2 Unix SMB/CIFS implementation.
3 Samba Web Administration Tool
5 Copyright (C) Andrew Tridgell 1997-2002
6 Copyright (C) John H Terpstra 2002
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 * @defgroup swat SWAT - Samba Web Administration Tool
27 * @brief Samba Web Administration Tool.
31 #include "web/swat_proto.h"
33 static int demo_mode
= False
;
34 static int passwd_only
= False
;
35 static bool have_write_access
= False
;
36 static bool have_read_access
= False
;
37 static int iNumNonAutoPrintServices
= 0;
40 * Password Management Globals
42 #define SWAT_USER "username"
43 #define OLD_PSWD "old_passwd"
44 #define NEW_PSWD "new_passwd"
45 #define NEW2_PSWD "new2_passwd"
46 #define CHG_S_PASSWD_FLAG "chg_s_passwd_flag"
47 #define CHG_R_PASSWD_FLAG "chg_r_passwd_flag"
48 #define ADD_USER_FLAG "add_user_flag"
49 #define DELETE_USER_FLAG "delete_user_flag"
50 #define DISABLE_USER_FLAG "disable_user_flag"
51 #define ENABLE_USER_FLAG "enable_user_flag"
52 #define RHOST "remote_host"
54 #define _(x) lang_msg_rotate(talloc_tos(),x)
56 /****************************************************************************
57 ****************************************************************************/
58 static int enum_index(int value
, const struct enum_list
*enumlist
)
61 for (i
=0;enumlist
[i
].name
;i
++)
62 if (value
== enumlist
[i
].value
) break;
66 static char *fix_backslash(const char *str
)
68 static char newstring
[1024];
72 if (*str
== '\\') {*p
++ = '\\';*p
++ = '\\';}
80 static const char *fix_quotes(TALLOC_CTX
*ctx
, const char *str
)
82 char *newstring
= NULL
;
85 int quote_len
= strlen(""");
87 /* Count the number of quotes. */
91 newstring_len
+= quote_len
;
97 newstring
= TALLOC_ARRAY(ctx
, char, newstring_len
);
101 for (p
= newstring
; *str
; str
++) {
103 strncpy( p
, """, quote_len
);
114 static char *stripspaceupper(const char *str
)
116 static char newstring
[1024];
120 if (*str
!= ' ') *p
++ = toupper_ascii(*str
);
127 static char *make_parm_name(const char *label
)
129 static char parmname
[1024];
133 if (*label
== ' ') *p
++ = '_';
141 /****************************************************************************
142 include a lump of html in a page
143 ****************************************************************************/
144 static int include_html(const char *fname
)
150 fd
= web_open(fname
, O_RDONLY
, 0);
153 printf(_("ERROR: Can't open %s"), fname
);
158 while ((ret
= read(fd
, buf
, sizeof(buf
))) > 0) {
166 /****************************************************************************
167 start the page with standard stuff
168 ****************************************************************************/
169 static void print_header(void)
171 if (!cgi_waspost()) {
172 printf("Expires: 0\r\n");
174 printf("Content-type: text/html\r\n\r\n");
176 if (!include_html("include/header.html")) {
177 printf("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n");
178 printf("<HTML>\n<HEAD>\n<TITLE>Samba Web Administration Tool</TITLE>\n</HEAD>\n<BODY background=\"/swat/images/background.jpg\">\n\n");
182 /* *******************************************************************
183 show parameter label with translated name in the following form
184 because showing original and translated label in one line looks
185 too long, and showing translated label only is unusable for
187 -------------------------------
188 HELP security [combo box][button]
190 -------------------------------
191 (capital words are translated by gettext.)
192 if no translation is available, then same form as original is
194 "i18n_translated_parm" class is used to change the color of the
195 translated parameter with CSS.
196 **************************************************************** */
197 static const char *get_parm_translated(TALLOC_CTX
*ctx
,
198 const char* pAnchor
, const char* pHelp
, const char* pLabel
)
200 const char *pTranslated
= _(pLabel
);
202 if(strcmp(pLabel
, pTranslated
) != 0) {
203 output
= talloc_asprintf(ctx
,
204 "<A HREF=\"/swat/help/manpages/smb.conf.5.html#%s\" target=\"docs\"> %s</A> %s <br><span class=\"i18n_translated_parm\">%s</span>",
205 pAnchor
, pHelp
, pLabel
, pTranslated
);
208 output
= talloc_asprintf(ctx
,
209 "<A HREF=\"/swat/help/manpages/smb.conf.5.html#%s\" target=\"docs\"> %s</A> %s",
210 pAnchor
, pHelp
, pLabel
);
213 /****************************************************************************
215 ****************************************************************************/
216 static void print_footer(void)
218 if (!include_html("include/footer.html")) {
219 printf("\n</BODY>\n</HTML>\n");
223 /****************************************************************************
224 display one editable parameter in a form
225 ****************************************************************************/
226 static void show_parameter(int snum
, struct parm_struct
*parm
)
229 void *ptr
= parm
->ptr
;
230 char *utf8_s1
, *utf8_s2
;
231 TALLOC_CTX
*ctx
= talloc_stackframe();
233 if (parm
->p_class
== P_LOCAL
&& snum
>= 0) {
234 ptr
= lp_local_ptr(snum
, ptr
);
237 printf("<tr><td>%s</td><td>", get_parm_translated(ctx
,
238 stripspaceupper(parm
->label
), _("Help"), parm
->label
));
239 switch (parm
->type
) {
241 printf("<input type=text size=2 name=\"parm_%s\" value=\"%c\">",
242 make_parm_name(parm
->label
), *(char *)ptr
);
243 printf("<input type=button value=\"%s\" onClick=\"swatform.parm_%s.value=\'%c\'\">",
244 _("Set Default"), make_parm_name(parm
->label
),(char)(parm
->def
.cvalue
));
248 printf("<input type=text size=40 name=\"parm_%s\" value=\"",
249 make_parm_name(parm
->label
));
250 if ((char ***)ptr
&& *(char ***)ptr
&& **(char ***)ptr
) {
251 char **list
= *(char ***)ptr
;
252 for (;*list
;list
++) {
253 /* enclose in HTML encoded quotes if the string contains a space */
254 if ( strchr_m(*list
, ' ') ) {
255 push_utf8_allocate(&utf8_s1
, *list
);
256 push_utf8_allocate(&utf8_s2
, ((*(list
+1))?", ":""));
257 printf(""%s"%s", utf8_s1
, utf8_s2
);
259 push_utf8_allocate(&utf8_s1
, *list
);
260 push_utf8_allocate(&utf8_s2
, ((*(list
+1))?", ":""));
261 printf("%s%s", utf8_s1
, utf8_s2
);
268 printf("<input type=button value=\"%s\" onClick=\"swatform.parm_%s.value=\'",
269 _("Set Default"), make_parm_name(parm
->label
));
270 if (parm
->def
.lvalue
) {
271 char **list
= (char **)(parm
->def
.lvalue
);
272 for (; *list
; list
++) {
273 /* enclose in HTML encoded quotes if the string contains a space */
274 if ( strchr_m(*list
, ' ') )
275 printf(""%s"%s", *list
, ((*(list
+1))?", ":""));
277 printf("%s%s", *list
, ((*(list
+1))?", ":""));
285 push_utf8_allocate(&utf8_s1
, *(char **)ptr
);
286 printf("<input type=text size=40 name=\"parm_%s\" value=\"%s\">",
287 make_parm_name(parm
->label
), fix_quotes(ctx
, utf8_s1
));
289 printf("<input type=button value=\"%s\" onClick=\"swatform.parm_%s.value=\'%s\'\">",
290 _("Set Default"), make_parm_name(parm
->label
),fix_backslash((char *)(parm
->def
.svalue
)));
294 printf("<select name=\"parm_%s\">",make_parm_name(parm
->label
));
295 printf("<option %s>Yes", (*(bool *)ptr
)?"selected":"");
296 printf("<option %s>No", (*(bool *)ptr
)?"":"selected");
298 printf("<input type=button value=\"%s\" onClick=\"swatform.parm_%s.selectedIndex=\'%d\'\">",
299 _("Set Default"), make_parm_name(parm
->label
),(bool)(parm
->def
.bvalue
)?0:1);
303 printf("<select name=\"parm_%s\">",make_parm_name(parm
->label
));
304 printf("<option %s>Yes", (*(bool *)ptr
)?"":"selected");
305 printf("<option %s>No", (*(bool *)ptr
)?"selected":"");
307 printf("<input type=button value=\"%s\" onClick=\"swatform.parm_%s.selectedIndex=\'%d\'\">",
308 _("Set Default"), make_parm_name(parm
->label
),(bool)(parm
->def
.bvalue
)?1:0);
312 printf("<input type=text size=8 name=\"parm_%s\" value=\"%d\">", make_parm_name(parm
->label
), *(int *)ptr
);
313 printf("<input type=button value=\"%s\" onClick=\"swatform.parm_%s.value=\'%d\'\">",
314 _("Set Default"), make_parm_name(parm
->label
),(int)(parm
->def
.ivalue
));
319 o
= octal_string(*(int *)ptr
);
320 printf("<input type=text size=8 name=\"parm_%s\" value=%s>",
321 make_parm_name(parm
->label
), o
);
323 o
= octal_string((int)(parm
->def
.ivalue
));
324 printf("<input type=button value=\"%s\" "
325 "onClick=\"swatform.parm_%s.value=\'%s\'\">",
326 _("Set Default"), make_parm_name(parm
->label
), o
);
332 printf("<select name=\"parm_%s\">",make_parm_name(parm
->label
));
333 for (i
=0;parm
->enum_list
[i
].name
;i
++) {
334 if (i
== 0 || parm
->enum_list
[i
].value
!= parm
->enum_list
[i
-1].value
) {
335 printf("<option %s>%s",(*(int *)ptr
)==parm
->enum_list
[i
].value
?"selected":"",parm
->enum_list
[i
].name
);
339 printf("<input type=button value=\"%s\" onClick=\"swatform.parm_%s.selectedIndex=\'%d\'\">",
340 _("Set Default"), make_parm_name(parm
->label
),enum_index((int)(parm
->def
.ivalue
),parm
->enum_list
));
345 printf("</td></tr>\n");
349 /****************************************************************************
350 display a set of parameters for a service
351 ****************************************************************************/
352 static void show_parameters(int snum
, int allparameters
, unsigned int parm_filter
, int printers
)
355 struct parm_struct
*parm
;
356 const char *heading
= NULL
;
357 const char *last_heading
= NULL
;
359 while ((parm
= lp_next_parameter(snum
, &i
, allparameters
))) {
360 if (snum
< 0 && parm
->p_class
== P_LOCAL
&& !(parm
->flags
& FLAG_GLOBAL
))
362 if (parm
->p_class
== P_SEPARATOR
) {
363 heading
= parm
->label
;
366 if (parm
->flags
& FLAG_HIDE
) continue;
368 if (printers
& !(parm
->flags
& FLAG_PRINT
)) continue;
369 if (!printers
& !(parm
->flags
& FLAG_SHARE
)) continue;
372 if (!( parm_filter
& FLAG_ADVANCED
)) {
373 if (!(parm
->flags
& FLAG_BASIC
)) {
374 void *ptr
= parm
->ptr
;
376 if (parm
->p_class
== P_LOCAL
&& snum
>= 0) {
377 ptr
= lp_local_ptr(snum
, ptr
);
380 switch (parm
->type
) {
382 if (*(char *)ptr
== (char)(parm
->def
.cvalue
)) continue;
386 if (!str_list_compare(*(char ***)ptr
, (char **)(parm
->def
.lvalue
))) continue;
391 if (!strcmp(*(char **)ptr
,(char *)(parm
->def
.svalue
))) continue;
396 if (*(bool *)ptr
== (bool)(parm
->def
.bvalue
)) continue;
401 if (*(int *)ptr
== (int)(parm
->def
.ivalue
)) continue;
406 if (*(int *)ptr
== (int)(parm
->def
.ivalue
)) continue;
412 if (printers
&& !(parm
->flags
& FLAG_PRINT
)) continue;
415 if ((parm_filter
& FLAG_WIZARD
) && !(parm
->flags
& FLAG_WIZARD
)) continue;
417 if ((parm_filter
& FLAG_ADVANCED
) && !(parm
->flags
& FLAG_ADVANCED
)) continue;
419 if (heading
&& heading
!= last_heading
) {
420 printf("<tr><td></td></tr><tr><td><b><u>%s</u></b></td></tr>\n", _(heading
));
421 last_heading
= heading
;
423 show_parameter(snum
, parm
);
427 /****************************************************************************
428 load the smb.conf file into loadparm.
429 ****************************************************************************/
430 static bool load_config(bool save_def
)
432 lp_resetnumservices();
433 return lp_load(get_dyn_CONFIGFILE(),False
,save_def
,False
,True
);
436 /****************************************************************************
438 ****************************************************************************/
439 static void write_config(FILE *f
, bool show_defaults
)
441 fprintf(f
, "# Samba config file created using SWAT\n");
442 fprintf(f
, "# from %s (%s)\n", cgi_remote_host(), cgi_remote_addr());
443 fprintf(f
, "# Date: %s\n\n", current_timestring(False
));
445 lp_dump(f
, show_defaults
, iNumNonAutoPrintServices
);
448 /****************************************************************************
449 save and reload the smb.conf config file
450 ****************************************************************************/
451 static int save_reload(int snum
)
456 f
= sys_fopen(get_dyn_CONFIGFILE(),"w");
458 printf(_("failed to open %s for writing"), get_dyn_CONFIGFILE());
463 /* just in case they have used the buggy xinetd to create the file */
464 if (fstat(fileno(f
), &st
) == 0 &&
465 (st
.st_mode
& S_IWOTH
)) {
466 #if defined HAVE_FCHMOD
467 fchmod(fileno(f
), S_IWUSR
| S_IRUSR
| S_IRGRP
| S_IROTH
);
469 chmod(get_dyn_CONFIGFILE(), S_IWUSR
| S_IRUSR
| S_IRGRP
| S_IROTH
);
473 write_config(f
, False
);
475 lp_dump_one(f
, False
, snum
);
480 if (!load_config(False
)) {
481 printf(_("Can't reload %s"), get_dyn_CONFIGFILE());
485 iNumNonAutoPrintServices
= lp_numservices();
491 /****************************************************************************
493 ****************************************************************************/
494 static void commit_parameter(int snum
, struct parm_struct
*parm
, const char *v
)
499 if (snum
< 0 && parm
->p_class
== P_LOCAL
) {
500 /* this handles the case where we are changing a local
501 variable globally. We need to change the parameter in
502 all shares where it is currently set to the default */
503 for (i
=0;i
<lp_numservices();i
++) {
504 s
= lp_servicename(i
);
505 if (s
&& (*s
) && lp_is_default(i
, parm
)) {
506 lp_do_parameter(i
, parm
->label
, v
);
511 lp_do_parameter(snum
, parm
->label
, v
);
514 /****************************************************************************
515 commit a set of parameters for a service
516 ****************************************************************************/
517 static void commit_parameters(int snum
)
520 struct parm_struct
*parm
;
524 while ((parm
= lp_next_parameter(snum
, &i
, 1))) {
525 if (asprintf(&label
, "parm_%s", make_parm_name(parm
->label
)) > 0) {
526 if ((v
= cgi_variable(label
)) != NULL
) {
527 if (parm
->flags
& FLAG_HIDE
)
529 commit_parameter(snum
, parm
, v
);
536 /****************************************************************************
537 spit out the html for a link with an image
538 ****************************************************************************/
539 static void image_link(const char *name
, const char *hlink
, const char *src
)
541 printf("<A HREF=\"%s/%s\"><img border=\"0\" src=\"/swat/%s\" alt=\"%s\"></A>\n",
542 cgi_baseurl(), hlink
, src
, name
);
545 /****************************************************************************
546 display the main navigation controls at the top of each page along
548 ****************************************************************************/
549 static void show_main_buttons(void)
553 if ((p
= cgi_user_name()) && strcmp(p
, "root")) {
554 printf(_("Logged in as <b>%s</b>"), p
);
558 image_link(_("Home"), "", "images/home.gif");
559 if (have_write_access
) {
560 image_link(_("Globals"), "globals", "images/globals.gif");
561 image_link(_("Shares"), "shares", "images/shares.gif");
562 image_link(_("Printers"), "printers", "images/printers.gif");
563 image_link(_("Wizard"), "wizard", "images/wizard.gif");
565 /* root always gets all buttons, otherwise look for -P */
566 if ( have_write_access
|| (!passwd_only
&& have_read_access
) ) {
567 image_link(_("Status"), "status", "images/status.gif");
568 image_link(_("View Config"), "viewconfig", "images/viewconfig.gif");
570 image_link(_("Password Management"), "passwd", "images/passwd.gif");
575 /****************************************************************************
576 * Handle Display/Edit Mode CGI
577 ****************************************************************************/
578 static void ViewModeBoxes(int mode
)
580 printf("<p>%s: \n", _("Current View Is"));
581 printf("<input type=radio name=\"ViewMode\" value=0 %s>%s\n", ((mode
== 0) ? "checked" : ""), _("Basic"));
582 printf("<input type=radio name=\"ViewMode\" value=1 %s>%s\n", ((mode
== 1) ? "checked" : ""), _("Advanced"));
583 printf("<br>%s: \n", _("Change View To"));
584 printf("<input type=submit name=\"BasicMode\" value=\"%s\">\n", _("Basic"));
585 printf("<input type=submit name=\"AdvMode\" value=\"%s\">\n", _("Advanced"));
586 printf("</p><br>\n");
589 /****************************************************************************
590 display a welcome page
591 ****************************************************************************/
592 static void welcome_page(void)
594 if (file_exist("help/welcome.html", NULL
)) {
595 include_html("help/welcome.html");
597 include_html("help/welcome-no-samba-doc.html");
601 /****************************************************************************
602 display the current smb.conf
603 ****************************************************************************/
604 static void viewconfig_page(void)
608 if (cgi_variable("full_view")) {
612 printf("<H2>%s</H2>\n", _("Current Config"));
613 printf("<form method=post>\n");
616 printf("<input type=submit name=\"normal_view\" value=\"%s\">\n", _("Normal View"));
618 printf("<input type=submit name=\"full_view\" value=\"%s\">\n", _("Full View"));
622 write_config(stdout
, full_view
);
627 /****************************************************************************
628 second screen of the wizard ... Fetch Configuration Parameters
629 ****************************************************************************/
630 static void wizard_params_page(void)
632 unsigned int parm_filter
= FLAG_WIZARD
;
634 /* Here we first set and commit all the parameters that were selected
635 in the previous screen. */
637 printf("<H2>%s</H2>\n", _("Wizard Parameter Edit Page"));
639 if (cgi_variable("Commit")) {
640 commit_parameters(GLOBAL_SECTION_SNUM
);
644 printf("<form name=\"swatform\" method=post action=wizard_params>\n");
646 if (have_write_access
) {
647 printf("<input type=submit name=\"Commit\" value=\"Commit Changes\">\n");
650 printf("<input type=reset name=\"Reset Values\" value=\"Reset\">\n");
654 show_parameters(GLOBAL_SECTION_SNUM
, 1, parm_filter
, 0);
655 printf("</table>\n");
659 /****************************************************************************
660 Utility to just rewrite the smb.conf file - effectively just cleans it up
661 ****************************************************************************/
662 static void rewritecfg_file(void)
664 commit_parameters(GLOBAL_SECTION_SNUM
);
666 printf("<H2>%s</H2>\n", _("Note: smb.conf file has been read and rewritten"));
669 /****************************************************************************
670 wizard to create/modify the smb.conf file
671 ****************************************************************************/
672 static void wizard_page(void)
674 /* Set some variables to collect data from smb.conf */
681 if (cgi_variable("Rewrite")) {
682 (void) rewritecfg_file();
686 if (cgi_variable("GetWizardParams")){
687 (void) wizard_params_page();
691 if (cgi_variable("Commit")){
692 SerType
= atoi(cgi_variable_nonull("ServerType"));
693 winstype
= atoi(cgi_variable_nonull("WINSType"));
694 have_home
= lp_servicenumber(HOMES_NAME
);
695 HomeExpo
= atoi(cgi_variable_nonull("HomeExpo"));
697 /* Plain text passwords are too badly broken - use encrypted passwords only */
698 lp_do_parameter( GLOBAL_SECTION_SNUM
, "encrypt passwords", "Yes");
702 /* Stand-alone Server */
703 lp_do_parameter( GLOBAL_SECTION_SNUM
, "security", "USER" );
704 lp_do_parameter( GLOBAL_SECTION_SNUM
, "domain logons", "No" );
708 lp_do_parameter( GLOBAL_SECTION_SNUM
, "security", "DOMAIN" );
709 lp_do_parameter( GLOBAL_SECTION_SNUM
, "domain logons", "No" );
712 /* Domain Controller */
713 lp_do_parameter( GLOBAL_SECTION_SNUM
, "security", "USER" );
714 lp_do_parameter( GLOBAL_SECTION_SNUM
, "domain logons", "Yes" );
717 switch ( winstype
) {
719 lp_do_parameter( GLOBAL_SECTION_SNUM
, "wins support", "No" );
720 lp_do_parameter( GLOBAL_SECTION_SNUM
, "wins server", "" );
723 lp_do_parameter( GLOBAL_SECTION_SNUM
, "wins support", "Yes" );
724 lp_do_parameter( GLOBAL_SECTION_SNUM
, "wins server", "" );
727 lp_do_parameter( GLOBAL_SECTION_SNUM
, "wins support", "No" );
728 lp_do_parameter( GLOBAL_SECTION_SNUM
, "wins server", cgi_variable_nonull("WINSAddr"));
732 /* Have to create Homes share? */
733 if ((HomeExpo
== 1) && (have_home
== -1)) {
734 const char *unix_share
= HOMES_NAME
;
737 lp_copy_service(GLOBAL_SECTION_SNUM
, unix_share
);
738 iNumNonAutoPrintServices
= lp_numservices();
739 have_home
= lp_servicenumber(HOMES_NAME
);
740 lp_do_parameter( have_home
, "read only", "No");
741 lp_do_parameter( have_home
, "valid users", "%S");
742 lp_do_parameter( have_home
, "browseable", "No");
743 commit_parameters(have_home
);
746 /* Need to Delete Homes share? */
747 if ((HomeExpo
== 0) && (have_home
!= -1)) {
748 lp_remove_service(have_home
);
752 commit_parameters(GLOBAL_SECTION_SNUM
);
757 /* Now determine smb.conf WINS settings */
758 if (lp_wins_support())
760 if (lp_wins_server_list() && strlen(*lp_wins_server_list()))
763 /* Do we have a homes share? */
764 have_home
= lp_servicenumber(HOMES_NAME
);
766 if ((winstype
== 2) && lp_wins_support())
769 role
= lp_server_role();
772 printf("<H2>%s</H2>\n", _("Samba Configuration Wizard"));
773 printf("<form method=post action=wizard>\n");
775 if (have_write_access
) {
776 printf("%s\n", _("The \"Rewrite smb.conf file\" button will clear the smb.conf file of all default values and of comments."));
777 printf("%s", _("The same will happen if you press the commit button."));
778 printf("<br><br>\n");
780 printf("<input type=submit name=\"Rewrite\" value=\"%s\"> ",_("Rewrite smb.conf file"));
781 printf("<input type=submit name=\"Commit\" value=\"%s\"> ",_("Commit"));
782 printf("<input type=submit name=\"GetWizardParams\" value=\"%s\">", _("Edit Parameter Values"));
783 printf("</center>\n");
787 printf("<center><table border=0>");
788 printf("<tr><td><b>%s: </b></td>\n", _("Server Type"));
789 printf("<td><input type=radio name=\"ServerType\" value=\"0\" %s> %s </td>", ((role
== ROLE_STANDALONE
) ? "checked" : ""), _("Stand Alone"));
790 printf("<td><input type=radio name=\"ServerType\" value=\"1\" %s> %s </td>", ((role
== ROLE_DOMAIN_MEMBER
) ? "checked" : ""), _("Domain Member"));
791 printf("<td><input type=radio name=\"ServerType\" value=\"2\" %s> %s </td>", ((role
== ROLE_DOMAIN_PDC
) ? "checked" : ""), _("Domain Controller"));
793 if (role
== ROLE_DOMAIN_BDC
) {
794 printf("<tr><td></td><td colspan=3><font color=\"#ff0000\">%s</font></td></tr>\n", _("Unusual Type in smb.conf - Please Select New Mode"));
796 printf("<tr><td><b>%s: </b></td>\n", _("Configure WINS As"));
797 printf("<td><input type=radio name=\"WINSType\" value=\"0\" %s> %s </td>", ((winstype
== 0) ? "checked" : ""), _("Not Used"));
798 printf("<td><input type=radio name=\"WINSType\" value=\"1\" %s> %s </td>", ((winstype
== 1) ? "checked" : ""), _("Server for client use"));
799 printf("<td><input type=radio name=\"WINSType\" value=\"2\" %s> %s </td>", ((winstype
== 2) ? "checked" : ""), _("Client of another WINS server"));
801 printf("<tr><td></td><td></td><td></td><td>%s <input type=text size=\"16\" name=\"WINSAddr\" value=\"", _("Remote WINS Server"));
803 /* Print out the list of wins servers */
804 if(lp_wins_server_list()) {
806 const char **wins_servers
= lp_wins_server_list();
807 for(i
= 0; wins_servers
[i
]; i
++) printf("%s ", wins_servers
[i
]);
810 printf("\"></td></tr>\n");
812 printf("<tr><td></td><td colspan=3><font color=\"#ff0000\">%s</font></td></tr>\n", _("Error: WINS Server Mode and WINS Support both set in smb.conf"));
813 printf("<tr><td></td><td colspan=3><font color=\"#ff0000\">%s</font></td></tr>\n", _("Please Select desired WINS mode above."));
815 printf("<tr><td><b>%s: </b></td>\n", _("Expose Home Directories"));
816 printf("<td><input type=radio name=\"HomeExpo\" value=\"1\" %s> Yes</td>", (have_home
== -1) ? "" : "checked ");
817 printf("<td><input type=radio name=\"HomeExpo\" value=\"0\" %s> No</td>", (have_home
== -1 ) ? "checked" : "");
818 printf("<td></td></tr>\n");
820 /* Enable this when we are ready ....
821 * printf("<tr><td><b>%s: </b></td>\n", _("Is Print Server"));
822 * printf("<td><input type=radio name=\"PtrSvr\" value=\"1\" %s> Yes</td>");
823 * printf("<td><input type=radio name=\"PtrSvr\" value=\"0\" %s> No</td>");
824 * printf("<td></td></tr>\n");
827 printf("</table></center>");
830 printf("%s\n", _("The above configuration options will set multiple parameters and will generally assist with rapid Samba deployment."));
835 /****************************************************************************
836 display a globals editing page
837 ****************************************************************************/
838 static void globals_page(void)
840 unsigned int parm_filter
= FLAG_BASIC
;
843 printf("<H2>%s</H2>\n", _("Global Parameters"));
845 if (cgi_variable("Commit")) {
846 commit_parameters(GLOBAL_SECTION_SNUM
);
850 if ( cgi_variable("ViewMode") )
851 mode
= atoi(cgi_variable_nonull("ViewMode"));
852 if ( cgi_variable("BasicMode"))
854 if ( cgi_variable("AdvMode"))
857 printf("<form name=\"swatform\" method=post action=globals>\n");
859 ViewModeBoxes( mode
);
862 parm_filter
= FLAG_BASIC
;
865 parm_filter
= FLAG_ADVANCED
;
869 if (have_write_access
) {
870 printf("<input type=submit name=\"Commit\" value=\"%s\">\n",
871 _("Commit Changes"));
874 printf("<input type=reset name=\"Reset Values\" value=\"%s\">\n",
879 show_parameters(GLOBAL_SECTION_SNUM
, 1, parm_filter
, 0);
880 printf("</table>\n");
884 /****************************************************************************
885 display a shares editing page. share is in unix codepage,
886 ****************************************************************************/
887 static void shares_page(void)
889 const char *share
= cgi_variable("share");
895 unsigned int parm_filter
= FLAG_BASIC
;
898 snum
= lp_servicenumber(share
);
900 printf("<H2>%s</H2>\n", _("Share Parameters"));
902 if (cgi_variable("Commit") && snum
>= 0) {
903 commit_parameters(snum
);
907 if (cgi_variable("Delete") && snum
>= 0) {
908 lp_remove_service(snum
);
914 if (cgi_variable("createshare") && (share
=cgi_variable("newshare"))) {
916 lp_copy_service(GLOBAL_SECTION_SNUM
, share
);
917 iNumNonAutoPrintServices
= lp_numservices();
919 snum
= lp_servicenumber(share
);
922 printf("<FORM name=\"swatform\" method=post>\n");
926 if ( cgi_variable("ViewMode") )
927 mode
= atoi(cgi_variable_nonull("ViewMode"));
928 if ( cgi_variable("BasicMode"))
930 if ( cgi_variable("AdvMode"))
933 ViewModeBoxes( mode
);
936 parm_filter
= FLAG_BASIC
;
939 parm_filter
= FLAG_ADVANCED
;
942 printf("<br><tr>\n");
943 printf("<td><input type=submit name=selectshare value=\"%s\"></td>\n", _("Choose Share"));
944 printf("<td><select name=share>\n");
946 printf("<option value=\" \"> \n");
947 for (i
=0;i
<lp_numservices();i
++) {
948 s
= lp_servicename(i
);
949 if (s
&& (*s
) && strcmp(s
,"IPC$") && !lp_print_ok(i
)) {
950 push_utf8_allocate(&utf8_s
, s
);
951 printf("<option %s value=\"%s\">%s\n",
952 (share
&& strcmp(share
,s
)==0)?"SELECTED":"",
958 printf("</select></td>\n");
959 if (have_write_access
) {
960 printf("<td><input type=submit name=\"Delete\" value=\"%s\"></td>\n", _("Delete Share"));
965 if (have_write_access
) {
967 printf("<td><input type=submit name=createshare value=\"%s\"></td>\n", _("Create Share"));
968 printf("<td><input type=text size=30 name=newshare></td></tr>\n");
974 if (have_write_access
) {
975 printf("<input type=submit name=\"Commit\" value=\"%s\">\n", _("Commit Changes"));
978 printf("<input type=reset name=\"Reset Values\" value=\"%s\">\n", _("Reset Values"));
984 show_parameters(snum
, 1, parm_filter
, 0);
985 printf("</table>\n");
991 /*************************************************************
992 change a password either locally or remotely
993 *************************************************************/
994 static bool change_password(const char *remote_machine
, const char *user_name
,
995 const char *old_passwd
, const char *new_passwd
,
999 char *err_str
= NULL
;
1000 char *msg_str
= NULL
;
1003 printf("%s\n<p>", _("password change in demo mode rejected"));
1007 if (remote_machine
!= NULL
) {
1008 ret
= remote_password_change(remote_machine
, user_name
,
1009 old_passwd
, new_passwd
, &err_str
);
1010 if (err_str
!= NULL
)
1011 printf("%s\n<p>", err_str
);
1013 return NT_STATUS_IS_OK(ret
);
1016 if(!initialize_password_db(True
, NULL
)) {
1017 printf("%s\n<p>", _("Can't setup password database vectors."));
1021 ret
= local_password_change(user_name
, local_flags
, new_passwd
,
1022 &err_str
, &msg_str
);
1025 printf("%s\n<p>", msg_str
);
1027 printf("%s\n<p>", err_str
);
1031 return NT_STATUS_IS_OK(ret
);
1034 /****************************************************************************
1035 do the stuff required to add or change a password
1036 ****************************************************************************/
1037 static void chg_passwd(void)
1041 int local_flags
= 0;
1043 /* Make sure users name has been specified */
1044 if (strlen(cgi_variable_nonull(SWAT_USER
)) == 0) {
1045 printf("<p>%s\n", _(" Must specify \"User Name\" "));
1050 * smbpasswd doesn't require anything but the users name to delete, disable or enable the user,
1051 * so if that's what we're doing, skip the rest of the checks
1053 if (!cgi_variable(DISABLE_USER_FLAG
) && !cgi_variable(ENABLE_USER_FLAG
) && !cgi_variable(DELETE_USER_FLAG
)) {
1056 * If current user is not root, make sure old password has been specified
1057 * If REMOTE change, even root must provide old password
1059 if (((!am_root()) && (strlen( cgi_variable_nonull(OLD_PSWD
)) <= 0)) ||
1060 ((cgi_variable(CHG_R_PASSWD_FLAG
)) && (strlen( cgi_variable_nonull(OLD_PSWD
)) <= 0))) {
1061 printf("<p>%s\n", _(" Must specify \"Old Password\" "));
1065 /* If changing a users password on a remote hosts we have to know what host */
1066 if ((cgi_variable(CHG_R_PASSWD_FLAG
)) && (strlen( cgi_variable_nonull(RHOST
)) <= 0)) {
1067 printf("<p>%s\n", _(" Must specify \"Remote Machine\" "));
1071 /* Make sure new passwords have been specified */
1072 if ((strlen( cgi_variable_nonull(NEW_PSWD
)) <= 0) ||
1073 (strlen( cgi_variable_nonull(NEW2_PSWD
)) <= 0)) {
1074 printf("<p>%s\n", _(" Must specify \"New, and Re-typed Passwords\" "));
1078 /* Make sure new passwords was typed correctly twice */
1079 if (strcmp(cgi_variable_nonull(NEW_PSWD
), cgi_variable_nonull(NEW2_PSWD
)) != 0) {
1080 printf("<p>%s\n", _(" Re-typed password didn't match new password "));
1085 if (cgi_variable(CHG_R_PASSWD_FLAG
)) {
1086 host
= cgi_variable(RHOST
);
1087 } else if (am_root()) {
1094 * Set up the local flags.
1097 local_flags
|= (cgi_variable(ADD_USER_FLAG
) ? LOCAL_ADD_USER
: 0);
1098 local_flags
|= (cgi_variable(ADD_USER_FLAG
) ? LOCAL_SET_PASSWORD
: 0);
1099 local_flags
|= (cgi_variable(CHG_S_PASSWD_FLAG
) ? LOCAL_SET_PASSWORD
: 0);
1100 local_flags
|= (cgi_variable(DELETE_USER_FLAG
) ? LOCAL_DELETE_USER
: 0);
1101 local_flags
|= (cgi_variable(ENABLE_USER_FLAG
) ? LOCAL_ENABLE_USER
: 0);
1102 local_flags
|= (cgi_variable(DISABLE_USER_FLAG
) ? LOCAL_DISABLE_USER
: 0);
1105 rslt
= change_password(host
,
1106 cgi_variable_nonull(SWAT_USER
),
1107 cgi_variable_nonull(OLD_PSWD
), cgi_variable_nonull(NEW_PSWD
),
1110 if(cgi_variable(CHG_S_PASSWD_FLAG
)) {
1113 printf(_(" The passwd for '%s' has been changed."), cgi_variable_nonull(SWAT_USER
));
1116 printf(_(" The passwd for '%s' has NOT been changed."), cgi_variable_nonull(SWAT_USER
));
1124 /****************************************************************************
1125 display a password editing page
1126 ****************************************************************************/
1127 static void passwd_page(void)
1129 const char *new_name
= cgi_user_name();
1132 * After the first time through here be nice. If the user
1133 * changed the User box text to another users name, remember it.
1135 if (cgi_variable(SWAT_USER
)) {
1136 new_name
= cgi_variable_nonull(SWAT_USER
);
1139 if (!new_name
) new_name
= "";
1141 printf("<H2>%s</H2>\n", _("Server Password Management"));
1143 printf("<FORM name=\"swatform\" method=post>\n");
1145 printf("<table>\n");
1148 * Create all the dialog boxes for data collection
1150 printf("<tr><td> %s : </td>\n", _("User Name"));
1151 printf("<td><input type=text size=30 name=%s value=%s></td></tr> \n", SWAT_USER
, new_name
);
1153 printf("<tr><td> %s : </td>\n", _("Old Password"));
1154 printf("<td><input type=password size=30 name=%s></td></tr> \n",OLD_PSWD
);
1156 printf("<tr><td> %s : </td>\n", _("New Password"));
1157 printf("<td><input type=password size=30 name=%s></td></tr>\n",NEW_PSWD
);
1158 printf("<tr><td> %s : </td>\n", _("Re-type New Password"));
1159 printf("<td><input type=password size=30 name=%s></td></tr>\n",NEW2_PSWD
);
1160 printf("</table>\n");
1163 * Create all the control buttons for requesting action
1165 printf("<input type=submit name=%s value=\"%s\">\n",
1166 CHG_S_PASSWD_FLAG
, _("Change Password"));
1167 if (demo_mode
|| am_root()) {
1168 printf("<input type=submit name=%s value=\"%s\">\n",
1169 ADD_USER_FLAG
, _("Add New User"));
1170 printf("<input type=submit name=%s value=\"%s\">\n",
1171 DELETE_USER_FLAG
, _("Delete User"));
1172 printf("<input type=submit name=%s value=\"%s\">\n",
1173 DISABLE_USER_FLAG
, _("Disable User"));
1174 printf("<input type=submit name=%s value=\"%s\">\n",
1175 ENABLE_USER_FLAG
, _("Enable User"));
1177 printf("<p></FORM>\n");
1180 * Do some work if change, add, disable or enable was
1181 * requested. It could be this is the first time through this
1182 * code, so there isn't anything to do. */
1183 if ((cgi_variable(CHG_S_PASSWD_FLAG
)) || (cgi_variable(ADD_USER_FLAG
)) || (cgi_variable(DELETE_USER_FLAG
)) ||
1184 (cgi_variable(DISABLE_USER_FLAG
)) || (cgi_variable(ENABLE_USER_FLAG
))) {
1188 printf("<H2>%s</H2>\n", _("Client/Server Password Management"));
1190 printf("<FORM name=\"swatform\" method=post>\n");
1192 printf("<table>\n");
1195 * Create all the dialog boxes for data collection
1197 printf("<tr><td> %s : </td>\n", _("User Name"));
1198 printf("<td><input type=text size=30 name=%s value=%s></td></tr>\n",SWAT_USER
, new_name
);
1199 printf("<tr><td> %s : </td>\n", _("Old Password"));
1200 printf("<td><input type=password size=30 name=%s></td></tr>\n",OLD_PSWD
);
1201 printf("<tr><td> %s : </td>\n", _("New Password"));
1202 printf("<td><input type=password size=30 name=%s></td></tr>\n",NEW_PSWD
);
1203 printf("<tr><td> %s : </td>\n", _("Re-type New Password"));
1204 printf("<td><input type=password size=30 name=%s></td></tr>\n",NEW2_PSWD
);
1205 printf("<tr><td> %s : </td>\n", _("Remote Machine"));
1206 printf("<td><input type=text size=30 name=%s></td></tr>\n",RHOST
);
1211 * Create all the control buttons for requesting action
1213 printf("<input type=submit name=%s value=\"%s\">",
1214 CHG_R_PASSWD_FLAG
, _("Change Password"));
1216 printf("<p></FORM>\n");
1219 * Do some work if a request has been made to change the
1220 * password somewhere other than the server. It could be this
1221 * is the first time through this code, so there isn't
1222 * anything to do. */
1223 if (cgi_variable(CHG_R_PASSWD_FLAG
)) {
1229 /****************************************************************************
1230 display a printers editing page
1231 ****************************************************************************/
1232 static void printers_page(void)
1234 const char *share
= cgi_variable("share");
1239 unsigned int parm_filter
= FLAG_BASIC
;
1242 snum
= lp_servicenumber(share
);
1244 printf("<H2>%s</H2>\n", _("Printer Parameters"));
1246 printf("<H3>%s</H3>\n", _("Important Note:"));
1247 printf(_("Printer names marked with [*] in the Choose Printer drop-down box "));
1248 printf(_("are autoloaded printers from "));
1249 printf("<A HREF=\"/swat/help/smb.conf.5.html#printcapname\" target=\"docs\">%s</A>\n", _("Printcap Name"));
1250 printf("%s\n", _("Attempting to delete these printers from SWAT will have no effect."));
1252 if (cgi_variable("Commit") && snum
>= 0) {
1253 commit_parameters(snum
);
1254 if (snum
>= iNumNonAutoPrintServices
)
1260 if (cgi_variable("Delete") && snum
>= 0) {
1261 lp_remove_service(snum
);
1267 if (cgi_variable("createshare") && (share
=cgi_variable("newshare"))) {
1269 lp_copy_service(GLOBAL_SECTION_SNUM
, share
);
1270 iNumNonAutoPrintServices
= lp_numservices();
1271 snum
= lp_servicenumber(share
);
1272 lp_do_parameter(snum
, "print ok", "Yes");
1274 snum
= lp_servicenumber(share
);
1277 printf("<FORM name=\"swatform\" method=post>\n");
1279 if ( cgi_variable("ViewMode") )
1280 mode
= atoi(cgi_variable_nonull("ViewMode"));
1281 if ( cgi_variable("BasicMode"))
1283 if ( cgi_variable("AdvMode"))
1286 ViewModeBoxes( mode
);
1289 parm_filter
= FLAG_BASIC
;
1292 parm_filter
= FLAG_ADVANCED
;
1295 printf("<table>\n");
1296 printf("<tr><td><input type=submit name=\"selectshare\" value=\"%s\"></td>\n", _("Choose Printer"));
1297 printf("<td><select name=\"share\">\n");
1298 if (snum
< 0 || !lp_print_ok(snum
))
1299 printf("<option value=\" \"> \n");
1300 for (i
=0;i
<lp_numservices();i
++) {
1301 s
= lp_servicename(i
);
1302 if (s
&& (*s
) && strcmp(s
,"IPC$") && lp_print_ok(i
)) {
1303 if (i
>= iNumNonAutoPrintServices
)
1304 printf("<option %s value=\"%s\">[*]%s\n",
1305 (share
&& strcmp(share
,s
)==0)?"SELECTED":"",
1308 printf("<option %s value=\"%s\">%s\n",
1309 (share
&& strcmp(share
,s
)==0)?"SELECTED":"",
1313 printf("</select></td>");
1314 if (have_write_access
) {
1315 printf("<td><input type=submit name=\"Delete\" value=\"%s\"></td>\n", _("Delete Printer"));
1318 printf("</table>\n");
1320 if (have_write_access
) {
1321 printf("<table>\n");
1322 printf("<tr><td><input type=submit name=\"createshare\" value=\"%s\"></td>\n", _("Create Printer"));
1323 printf("<td><input type=text size=30 name=\"newshare\"></td></tr>\n");
1329 if (have_write_access
) {
1330 printf("<input type=submit name=\"Commit\" value=\"%s\">\n", _("Commit Changes"));
1332 printf("<input type=reset name=\"Reset Values\" value=\"%s\">\n", _("Reset Values"));
1337 printf("<table>\n");
1338 show_parameters(snum
, 1, parm_filter
, 1);
1339 printf("</table>\n");
1341 printf("</FORM>\n");
1345 when the _() translation macro is used there is no obvious place to free
1346 the resulting string and there is no easy way to give a static pointer.
1347 All we can do is rotate between some static buffers and hope a single d_printf()
1348 doesn't have more calls to _() than the number of buffers
1351 const char *lang_msg_rotate(TALLOC_CTX
*ctx
, const char *msgid
)
1356 msgstr
= lang_msg(msgid
);
1361 ret
= talloc_strdup(ctx
, msgstr
);
1363 lang_msg_free(msgstr
);
1372 * main function for SWAT.
1374 int main(int argc
, char *argv
[])
1378 struct poptOption long_options
[] = {
1380 { "disable-authentication", 'a', POPT_ARG_VAL
, &demo_mode
, True
, "Disable authentication (demo mode)" },
1381 { "password-menu-only", 'P', POPT_ARG_VAL
, &passwd_only
, True
, "Show only change password menu" },
1385 TALLOC_CTX
*frame
= talloc_stackframe();
1388 umask(S_IWGRP
| S_IWOTH
);
1390 #if defined(HAVE_SET_AUTH_PARAMETERS)
1391 set_auth_parameters(argc
, argv
);
1392 #endif /* HAVE_SET_AUTH_PARAMETERS */
1394 /* just in case it goes wild ... */
1399 /* we don't want any SIGPIPE messages */
1400 BlockSignals(True
,SIGPIPE
);
1402 dbf
= x_fopen("/dev/null", O_WRONLY
, 0);
1403 if (!dbf
) dbf
= x_stderr
;
1405 /* we don't want stderr screwing us up */
1407 open("/dev/null", O_WRONLY
);
1409 pc
= poptGetContext("swat", argc
, (const char **) argv
, long_options
, 0);
1411 /* Parse command line options */
1413 while(poptGetNextOpt(pc
) != -1) { }
1415 poptFreeContext(pc
);
1419 setup_logging(argv
[0],False
);
1422 iNumNonAutoPrintServices
= lp_numservices();
1425 cgi_setup(get_dyn_SWATDIR(), !demo_mode
);
1429 cgi_load_variables();
1431 if (!file_exist(get_dyn_CONFIGFILE(), NULL
)) {
1432 have_read_access
= True
;
1433 have_write_access
= True
;
1435 /* check if the authenticated user has write access - if not then
1436 don't show write options */
1437 have_write_access
= (access(get_dyn_CONFIGFILE(),W_OK
) == 0);
1439 /* if the user doesn't have read access to smb.conf then
1440 don't let them view it */
1441 have_read_access
= (access(get_dyn_CONFIGFILE(),R_OK
) == 0);
1444 show_main_buttons();
1446 page
= cgi_pathinfo();
1448 /* Root gets full functionality */
1449 if (have_read_access
&& strcmp(page
, "globals")==0) {
1451 } else if (have_read_access
&& strcmp(page
,"shares")==0) {
1453 } else if (have_read_access
&& strcmp(page
,"printers")==0) {
1455 } else if (have_read_access
&& strcmp(page
,"status")==0) {
1457 } else if (have_read_access
&& strcmp(page
,"viewconfig")==0) {
1459 } else if (strcmp(page
,"passwd")==0) {
1461 } else if (have_read_access
&& strcmp(page
,"wizard")==0) {
1463 } else if (have_read_access
&& strcmp(page
,"wizard_params")==0) {
1464 wizard_params_page();
1465 } else if (have_read_access
&& strcmp(page
,"rewritecfg")==0) {