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 "system/filesys.h"
32 #include "popt_common.h"
33 #include "web/swat_proto.h"
34 #include "printing/pcap.h"
35 #include "printing/load.h"
37 #include "intl/lang_tdb.h"
38 #include "lib/param/loadparm.h"
40 static int demo_mode
= False
;
41 static int passwd_only
= False
;
42 static bool have_write_access
= False
;
43 static bool have_read_access
= False
;
44 static int iNumNonAutoPrintServices
= 0;
47 * Password Management Globals
49 #define SWAT_USER "username"
50 #define OLD_PSWD "old_passwd"
51 #define NEW_PSWD "new_passwd"
52 #define NEW2_PSWD "new2_passwd"
53 #define CHG_S_PASSWD_FLAG "chg_s_passwd_flag"
54 #define CHG_R_PASSWD_FLAG "chg_r_passwd_flag"
55 #define ADD_USER_FLAG "add_user_flag"
56 #define DELETE_USER_FLAG "delete_user_flag"
57 #define DISABLE_USER_FLAG "disable_user_flag"
58 #define ENABLE_USER_FLAG "enable_user_flag"
59 #define RHOST "remote_host"
61 #define _(x) lang_msg_rotate(talloc_tos(),x)
63 /****************************************************************************
64 ****************************************************************************/
65 static int enum_index(int value
, const struct enum_list
*enumlist
)
68 for (i
=0;enumlist
[i
].name
;i
++)
69 if (value
== enumlist
[i
].value
) break;
73 static char *fix_backslash(const char *str
)
75 static char newstring
[1024];
79 if (*str
== '\\') {*p
++ = '\\';*p
++ = '\\';}
87 static const char *fix_quotes(TALLOC_CTX
*ctx
, char *str
)
89 char *newstring
= NULL
;
92 int quote_len
= strlen(""");
94 /* Count the number of quotes. */
99 newstring_len
+= quote_len
;
105 newstring
= talloc_array(ctx
, char, newstring_len
);
109 for (p
= newstring
; *str
; str
++) {
111 strncpy( p
, """, quote_len
);
121 static char *stripspaceupper(const char *str
)
123 static char newstring
[1024];
127 if (*str
!= ' ') *p
++ = toupper_m(*str
);
134 static char *make_parm_name(const char *label
)
136 static char parmname
[1024];
140 if (*label
== ' ') *p
++ = '_';
148 /****************************************************************************
149 include a lump of html in a page
150 ****************************************************************************/
151 static int include_html(const char *fname
)
157 fd
= web_open(fname
, O_RDONLY
, 0);
160 printf(_("ERROR: Can't open %s"), fname
);
165 while ((ret
= read(fd
, buf
, sizeof(buf
))) > 0) {
166 if (write(1, buf
, ret
) == -1) {
175 /****************************************************************************
176 start the page with standard stuff
177 ****************************************************************************/
178 static void print_header(void)
180 if (!cgi_waspost()) {
181 printf("Expires: 0\r\n");
183 printf("Content-type: text/html\r\n\r\n");
185 if (!include_html("include/header.html")) {
186 printf("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n");
187 printf("<HTML>\n<HEAD>\n<TITLE>Samba Web Administration Tool</TITLE>\n</HEAD>\n<BODY background=\"/swat/images/background.jpg\">\n\n");
191 /* *******************************************************************
192 show parameter label with translated name in the following form
193 because showing original and translated label in one line looks
194 too long, and showing translated label only is unusable for
196 -------------------------------
197 HELP security [combo box][button]
199 -------------------------------
200 (capital words are translated by gettext.)
201 if no translation is available, then same form as original is
203 "i18n_translated_parm" class is used to change the color of the
204 translated parameter with CSS.
205 **************************************************************** */
206 static const char *get_parm_translated(TALLOC_CTX
*ctx
,
207 const char* pAnchor
, const char* pHelp
, const char* pLabel
)
209 const char *pTranslated
= _(pLabel
);
211 if(strcmp(pLabel
, pTranslated
) != 0) {
212 output
= talloc_asprintf(ctx
,
213 "<A HREF=\"/swat/help/manpages/smb.conf.5.html#%s\" target=\"docs\"> %s</A> %s <br><span class=\"i18n_translated_parm\">%s</span>",
214 pAnchor
, pHelp
, pLabel
, pTranslated
);
217 output
= talloc_asprintf(ctx
,
218 "<A HREF=\"/swat/help/manpages/smb.conf.5.html#%s\" target=\"docs\"> %s</A> %s",
219 pAnchor
, pHelp
, pLabel
);
222 /****************************************************************************
224 ****************************************************************************/
225 static void print_footer(void)
227 if (!include_html("include/footer.html")) {
228 printf("\n</BODY>\n</HTML>\n");
232 /****************************************************************************
233 display one editable parameter in a form
234 ****************************************************************************/
235 static void show_parameter(int snum
, struct parm_struct
*parm
)
239 char *utf8_s1
, *utf8_s2
;
240 size_t converted_size
;
241 TALLOC_CTX
*ctx
= talloc_stackframe();
243 if (parm
->p_class
== P_LOCAL
&& snum
>= 0) {
244 ptr
= lp_local_ptr_by_snum(snum
, parm
);
246 ptr
= lp_parm_ptr(NULL
, parm
);
249 printf("<tr><td>%s</td><td>", get_parm_translated(ctx
,
250 stripspaceupper(parm
->label
), _("Help"), parm
->label
));
251 switch (parm
->type
) {
253 printf("<input type=text size=2 name=\"parm_%s\" value=\"%c\">",
254 make_parm_name(parm
->label
), *(char *)ptr
);
255 printf("<input type=button value=\"%s\" onClick=\"swatform.parm_%s.value=\'%c\'\">",
256 _("Set Default"), make_parm_name(parm
->label
),(char)(parm
->def
.cvalue
));
260 printf("<input type=text size=40 name=\"parm_%s\" value=\"",
261 make_parm_name(parm
->label
));
262 if ((char ***)ptr
&& *(char ***)ptr
&& **(char ***)ptr
) {
263 char **list
= *(char ***)ptr
;
264 for (;*list
;list
++) {
265 /* enclose in HTML encoded quotes if the string contains a space */
266 if ( strchr_m(*list
, ' ') ) {
267 push_utf8_talloc(talloc_tos(), &utf8_s1
, *list
, &converted_size
);
268 push_utf8_talloc(talloc_tos(), &utf8_s2
, ((*(list
+1))?", ":""), &converted_size
);
269 printf(""%s"%s", utf8_s1
, utf8_s2
);
271 push_utf8_talloc(talloc_tos(), &utf8_s1
, *list
, &converted_size
);
272 push_utf8_talloc(talloc_tos(), &utf8_s2
, ((*(list
+1))?", ":""), &converted_size
);
273 printf("%s%s", utf8_s1
, utf8_s2
);
275 TALLOC_FREE(utf8_s1
);
276 TALLOC_FREE(utf8_s2
);
280 printf("<input type=button value=\"%s\" onClick=\"swatform.parm_%s.value=\'",
281 _("Set Default"), make_parm_name(parm
->label
));
282 if (parm
->def
.lvalue
) {
283 char **list
= (char **)(parm
->def
.lvalue
);
284 for (; *list
; list
++) {
285 /* enclose in HTML encoded quotes if the string contains a space */
286 if ( strchr_m(*list
, ' ') )
287 printf(""%s"%s", *list
, ((*(list
+1))?", ":""));
289 printf("%s%s", *list
, ((*(list
+1))?", ":""));
297 push_utf8_talloc(talloc_tos(), &utf8_s1
, *(char **)ptr
, &converted_size
);
298 printf("<input type=text size=40 name=\"parm_%s\" value=\"%s\">",
299 make_parm_name(parm
->label
), fix_quotes(ctx
, utf8_s1
));
300 TALLOC_FREE(utf8_s1
);
301 printf("<input type=button value=\"%s\" onClick=\"swatform.parm_%s.value=\'%s\'\">",
302 _("Set Default"), make_parm_name(parm
->label
),fix_backslash((char *)(parm
->def
.svalue
)));
306 printf("<select name=\"parm_%s\">",make_parm_name(parm
->label
));
307 printf("<option %s>Yes", (*(bool *)ptr
)?"selected":"");
308 printf("<option %s>No", (*(bool *)ptr
)?"":"selected");
310 printf("<input type=button value=\"%s\" onClick=\"swatform.parm_%s.selectedIndex=\'%d\'\">",
311 _("Set Default"), make_parm_name(parm
->label
),(bool)(parm
->def
.bvalue
)?0:1);
315 printf("<select name=\"parm_%s\">",make_parm_name(parm
->label
));
316 printf("<option %s>Yes", (*(bool *)ptr
)?"":"selected");
317 printf("<option %s>No", (*(bool *)ptr
)?"selected":"");
319 printf("<input type=button value=\"%s\" onClick=\"swatform.parm_%s.selectedIndex=\'%d\'\">",
320 _("Set Default"), make_parm_name(parm
->label
),(bool)(parm
->def
.bvalue
)?1:0);
324 printf("<input type=text size=8 name=\"parm_%s\" value=\"%d\">", make_parm_name(parm
->label
), *(int *)ptr
);
325 printf("<input type=button value=\"%s\" onClick=\"swatform.parm_%s.value=\'%d\'\">",
326 _("Set Default"), make_parm_name(parm
->label
),(int)(parm
->def
.ivalue
));
331 o
= octal_string(*(int *)ptr
);
332 printf("<input type=text size=8 name=\"parm_%s\" value=%s>",
333 make_parm_name(parm
->label
), o
);
335 o
= octal_string((int)(parm
->def
.ivalue
));
336 printf("<input type=button value=\"%s\" "
337 "onClick=\"swatform.parm_%s.value=\'%s\'\">",
338 _("Set Default"), make_parm_name(parm
->label
), o
);
344 printf("<select name=\"parm_%s\">",make_parm_name(parm
->label
));
345 for (i
=0;parm
->enum_list
[i
].name
;i
++) {
346 if (i
== 0 || parm
->enum_list
[i
].value
!= parm
->enum_list
[i
-1].value
) {
347 printf("<option %s>%s",(*(int *)ptr
)==parm
->enum_list
[i
].value
?"selected":"",parm
->enum_list
[i
].name
);
351 printf("<input type=button value=\"%s\" onClick=\"swatform.parm_%s.selectedIndex=\'%d\'\">",
352 _("Set Default"), make_parm_name(parm
->label
),enum_index((int)(parm
->def
.ivalue
),parm
->enum_list
));
357 printf("</td></tr>\n");
361 /****************************************************************************
362 display a set of parameters for a service
363 ****************************************************************************/
364 static void show_parameters(int snum
, int allparameters
, unsigned int parm_filter
, int printers
)
367 struct parm_struct
*parm
;
368 const char *heading
= NULL
;
369 const char *last_heading
= NULL
;
371 while ((parm
= lp_next_parameter(snum
, &i
, allparameters
))) {
372 if (snum
< 0 && parm
->p_class
== P_LOCAL
&& !(parm
->flags
& FLAG_GLOBAL
))
374 if (parm
->p_class
== P_SEPARATOR
) {
375 heading
= parm
->label
;
378 if (parm
->flags
& FLAG_HIDE
) continue;
380 if (printers
& !(parm
->flags
& FLAG_PRINT
)) continue;
381 if (!printers
& !(parm
->flags
& FLAG_SHARE
)) continue;
384 if (!( parm_filter
& FLAG_ADVANCED
)) {
385 if (!(parm
->flags
& FLAG_BASIC
)) {
387 if (parm
->p_class
== P_LOCAL
&& snum
>= 0) {
388 ptr
= lp_local_ptr_by_snum(snum
, parm
);
390 ptr
= lp_parm_ptr(NULL
, parm
);
393 switch (parm
->type
) {
395 if (*(char *)ptr
== (char)(parm
->def
.cvalue
)) continue;
399 if (!str_list_equal(*(const char ***)ptr
,
400 (const char **)(parm
->def
.lvalue
))) continue;
405 if (!strcmp(*(char **)ptr
,(char *)(parm
->def
.svalue
))) continue;
410 if (*(bool *)ptr
== (bool)(parm
->def
.bvalue
)) continue;
415 if (*(int *)ptr
== (int)(parm
->def
.ivalue
)) continue;
420 if (*(int *)ptr
== (int)(parm
->def
.ivalue
)) continue;
426 if (printers
&& !(parm
->flags
& FLAG_PRINT
)) continue;
429 if ((parm_filter
& FLAG_WIZARD
) && !(parm
->flags
& FLAG_WIZARD
)) continue;
431 if ((parm_filter
& FLAG_ADVANCED
) && !(parm
->flags
& FLAG_ADVANCED
)) continue;
433 if (heading
&& heading
!= last_heading
) {
434 printf("<tr><td></td></tr><tr><td><b><u>%s</u></b></td></tr>\n", _(heading
));
435 last_heading
= heading
;
437 show_parameter(snum
, parm
);
441 /****************************************************************************
442 load the smb.conf file into loadparm.
443 ****************************************************************************/
444 static bool load_config(bool save_def
)
446 return lp_load(get_dyn_CONFIGFILE(),False
,save_def
,False
,True
);
449 /****************************************************************************
451 ****************************************************************************/
452 static void write_config(FILE *f
, bool show_defaults
)
454 TALLOC_CTX
*ctx
= talloc_stackframe();
456 fprintf(f
, "# Samba config file created using SWAT\n");
457 fprintf(f
, "# from %s (%s)\n", cgi_remote_host(), cgi_remote_addr());
458 fprintf(f
, "# Date: %s\n\n", current_timestring(ctx
, False
));
460 lp_dump(f
, show_defaults
, iNumNonAutoPrintServices
);
465 /****************************************************************************
466 save and reload the smb.conf config file
467 ****************************************************************************/
468 static int save_reload(int snum
)
473 f
= sys_fopen(get_dyn_CONFIGFILE(),"w");
475 printf(_("failed to open %s for writing"), get_dyn_CONFIGFILE());
480 /* just in case they have used the buggy xinetd to create the file */
481 if (fstat(fileno(f
), &st
) == 0 &&
482 (st
.st_mode
& S_IWOTH
)) {
483 #if defined HAVE_FCHMOD
484 fchmod(fileno(f
), S_IWUSR
| S_IRUSR
| S_IRGRP
| S_IROTH
);
486 chmod(get_dyn_CONFIGFILE(), S_IWUSR
| S_IRUSR
| S_IRGRP
| S_IROTH
);
490 write_config(f
, False
);
492 lp_dump_one(f
, False
, snum
);
495 lp_kill_all_services();
497 if (!load_config(False
)) {
498 printf(_("Can't reload %s"), get_dyn_CONFIGFILE());
502 iNumNonAutoPrintServices
= lp_numservices();
503 if (pcap_cache_loaded()) {
504 load_printers(server_event_context(),
505 server_messaging_context());
511 /****************************************************************************
513 ****************************************************************************/
514 static void commit_parameter(int snum
, struct parm_struct
*parm
, const char *v
)
519 if (snum
< 0 && parm
->p_class
== P_LOCAL
) {
520 /* this handles the case where we are changing a local
521 variable globally. We need to change the parameter in
522 all shares where it is currently set to the default */
523 for (i
=0;i
<lp_numservices();i
++) {
524 s
= lp_servicename(i
);
525 if (s
&& (*s
) && lp_is_default(i
, parm
)) {
526 lp_do_parameter(i
, parm
->label
, v
);
531 lp_do_parameter(snum
, parm
->label
, v
);
534 /****************************************************************************
535 commit a set of parameters for a service
536 ****************************************************************************/
537 static void commit_parameters(int snum
)
540 struct parm_struct
*parm
;
544 while ((parm
= lp_next_parameter(snum
, &i
, 1))) {
545 if (asprintf(&label
, "parm_%s", make_parm_name(parm
->label
)) > 0) {
546 if ((v
= cgi_variable(label
)) != NULL
) {
547 if (parm
->flags
& FLAG_HIDE
)
549 commit_parameter(snum
, parm
, v
);
556 /****************************************************************************
557 spit out the html for a link with an image
558 ****************************************************************************/
559 static void image_link(const char *name
, const char *hlink
, const char *src
)
561 printf("<A HREF=\"%s/%s\"><img border=\"0\" src=\"/swat/%s\" alt=\"%s\"></A>\n",
562 cgi_baseurl(), hlink
, src
, name
);
565 /****************************************************************************
566 display the main navigation controls at the top of each page along
568 ****************************************************************************/
569 static void show_main_buttons(void)
573 if ((p
= cgi_user_name()) && strcmp(p
, "root")) {
574 printf(_("Logged in as <b>%s</b>"), p
);
578 image_link(_("Home"), "", "images/home.gif");
579 if (have_write_access
) {
580 image_link(_("Globals"), "globals", "images/globals.gif");
581 image_link(_("Shares"), "shares", "images/shares.gif");
582 image_link(_("Printers"), "printers", "images/printers.gif");
583 image_link(_("Wizard"), "wizard", "images/wizard.gif");
585 /* root always gets all buttons, otherwise look for -P */
586 if ( have_write_access
|| (!passwd_only
&& have_read_access
) ) {
587 image_link(_("Status"), "status", "images/status.gif");
588 image_link(_("View Config"), "viewconfig", "images/viewconfig.gif");
590 image_link(_("Password Management"), "passwd", "images/passwd.gif");
595 /****************************************************************************
596 * Handle Display/Edit Mode CGI
597 ****************************************************************************/
598 static void ViewModeBoxes(int mode
)
600 printf("<p>%s: \n", _("Current View Is"));
601 printf("<input type=radio name=\"ViewMode\" value=0 %s>%s\n", ((mode
== 0) ? "checked" : ""), _("Basic"));
602 printf("<input type=radio name=\"ViewMode\" value=1 %s>%s\n", ((mode
== 1) ? "checked" : ""), _("Advanced"));
603 printf("<br>%s: \n", _("Change View To"));
604 printf("<input type=submit name=\"BasicMode\" value=\"%s\">\n", _("Basic"));
605 printf("<input type=submit name=\"AdvMode\" value=\"%s\">\n", _("Advanced"));
606 printf("</p><br>\n");
609 /****************************************************************************
610 display a welcome page
611 ****************************************************************************/
612 static void welcome_page(void)
614 if (file_exist("help/welcome.html")) {
615 include_html("help/welcome.html");
617 include_html("help/welcome-no-samba-doc.html");
621 /****************************************************************************
622 display the current smb.conf
623 ****************************************************************************/
624 static void viewconfig_page(void)
628 if (cgi_variable("full_view")) {
632 printf("<H2>%s</H2>\n", _("Current Config"));
633 printf("<form method=post>\n");
636 printf("<input type=submit name=\"normal_view\" value=\"%s\">\n", _("Normal View"));
638 printf("<input type=submit name=\"full_view\" value=\"%s\">\n", _("Full View"));
642 write_config(stdout
, full_view
);
647 /****************************************************************************
648 second screen of the wizard ... Fetch Configuration Parameters
649 ****************************************************************************/
650 static void wizard_params_page(void)
652 unsigned int parm_filter
= FLAG_WIZARD
;
654 /* Here we first set and commit all the parameters that were selected
655 in the previous screen. */
657 printf("<H2>%s</H2>\n", _("Wizard Parameter Edit Page"));
659 if (cgi_variable("Commit")) {
660 commit_parameters(GLOBAL_SECTION_SNUM
);
664 printf("<form name=\"swatform\" method=post action=wizard_params>\n");
666 if (have_write_access
) {
667 printf("<input type=submit name=\"Commit\" value=\"Commit Changes\">\n");
670 printf("<input type=reset name=\"Reset Values\" value=\"Reset\">\n");
674 show_parameters(GLOBAL_SECTION_SNUM
, 1, parm_filter
, 0);
675 printf("</table>\n");
679 /****************************************************************************
680 Utility to just rewrite the smb.conf file - effectively just cleans it up
681 ****************************************************************************/
682 static void rewritecfg_file(void)
684 commit_parameters(GLOBAL_SECTION_SNUM
);
686 printf("<H2>%s</H2>\n", _("Note: smb.conf file has been read and rewritten"));
689 /****************************************************************************
690 wizard to create/modify the smb.conf file
691 ****************************************************************************/
692 static void wizard_page(void)
694 /* Set some variables to collect data from smb.conf */
701 if (cgi_variable("Rewrite")) {
702 (void) rewritecfg_file();
706 if (cgi_variable("GetWizardParams")){
707 (void) wizard_params_page();
711 if (cgi_variable("Commit")){
712 SerType
= atoi(cgi_variable_nonull("ServerType"));
713 winstype
= atoi(cgi_variable_nonull("WINSType"));
714 have_home
= lp_servicenumber(HOMES_NAME
);
715 HomeExpo
= atoi(cgi_variable_nonull("HomeExpo"));
717 /* Plain text passwords are too badly broken - use encrypted passwords only */
718 lp_do_parameter( GLOBAL_SECTION_SNUM
, "encrypt passwords", "Yes");
722 /* Stand-alone Server */
723 lp_do_parameter( GLOBAL_SECTION_SNUM
, "security", "USER" );
724 lp_do_parameter( GLOBAL_SECTION_SNUM
, "domain logons", "No" );
728 lp_do_parameter( GLOBAL_SECTION_SNUM
, "security", "DOMAIN" );
729 lp_do_parameter( GLOBAL_SECTION_SNUM
, "domain logons", "No" );
732 /* Domain Controller */
733 lp_do_parameter( GLOBAL_SECTION_SNUM
, "security", "USER" );
734 lp_do_parameter( GLOBAL_SECTION_SNUM
, "domain logons", "Yes" );
737 switch ( winstype
) {
739 lp_do_parameter( GLOBAL_SECTION_SNUM
, "wins support", "No" );
740 lp_do_parameter( GLOBAL_SECTION_SNUM
, "wins server", "" );
743 lp_do_parameter( GLOBAL_SECTION_SNUM
, "wins support", "Yes" );
744 lp_do_parameter( GLOBAL_SECTION_SNUM
, "wins server", "" );
747 lp_do_parameter( GLOBAL_SECTION_SNUM
, "wins support", "No" );
748 lp_do_parameter( GLOBAL_SECTION_SNUM
, "wins server", cgi_variable_nonull("WINSAddr"));
752 /* Have to create Homes share? */
753 if ((HomeExpo
== 1) && (have_home
== -1)) {
754 const char *unix_share
= HOMES_NAME
;
757 lp_copy_service(GLOBAL_SECTION_SNUM
, unix_share
);
758 have_home
= lp_servicenumber(HOMES_NAME
);
759 lp_do_parameter( have_home
, "read only", "No");
760 lp_do_parameter( have_home
, "valid users", "%S");
761 lp_do_parameter( have_home
, "browseable", "No");
762 commit_parameters(have_home
);
763 save_reload(have_home
);
766 /* Need to Delete Homes share? */
767 if ((HomeExpo
== 0) && (have_home
!= -1)) {
768 lp_remove_service(have_home
);
772 commit_parameters(GLOBAL_SECTION_SNUM
);
777 /* Now determine smb.conf WINS settings */
778 if (lp_we_are_a_wins_server())
780 if (lp_wins_server_list() && strlen(*lp_wins_server_list()))
783 /* Do we have a homes share? */
784 have_home
= lp_servicenumber(HOMES_NAME
);
786 if ((winstype
== 2) && lp_we_are_a_wins_server())
789 role
= lp_server_role();
792 printf("<H2>%s</H2>\n", _("Samba Configuration Wizard"));
793 printf("<form method=post action=wizard>\n");
795 if (have_write_access
) {
796 printf("%s\n", _("The \"Rewrite smb.conf file\" button will clear the smb.conf file of all default values and of comments."));
797 printf("%s", _("The same will happen if you press the commit button."));
798 printf("<br><br>\n");
800 printf("<input type=submit name=\"Rewrite\" value=\"%s\"> ",_("Rewrite smb.conf file"));
801 printf("<input type=submit name=\"Commit\" value=\"%s\"> ",_("Commit"));
802 printf("<input type=submit name=\"GetWizardParams\" value=\"%s\">", _("Edit Parameter Values"));
803 printf("</center>\n");
807 printf("<center><table border=0>");
808 printf("<tr><td><b>%s: </b></td>\n", _("Server Type"));
809 printf("<td><input type=radio name=\"ServerType\" value=\"0\" %s> %s </td>", ((role
== ROLE_STANDALONE
) ? "checked" : ""), _("Stand Alone"));
810 printf("<td><input type=radio name=\"ServerType\" value=\"1\" %s> %s </td>", ((role
== ROLE_DOMAIN_MEMBER
) ? "checked" : ""), _("Domain Member"));
811 printf("<td><input type=radio name=\"ServerType\" value=\"2\" %s> %s </td>", ((role
== ROLE_DOMAIN_PDC
) ? "checked" : ""), _("Domain Controller"));
813 if (role
== ROLE_DOMAIN_BDC
) {
814 printf("<tr><td></td><td colspan=3><font color=\"#ff0000\">%s</font></td></tr>\n", _("Unusual Type in smb.conf - Please Select New Mode"));
816 printf("<tr><td><b>%s: </b></td>\n", _("Configure WINS As"));
817 printf("<td><input type=radio name=\"WINSType\" value=\"0\" %s> %s </td>", ((winstype
== 0) ? "checked" : ""), _("Not Used"));
818 printf("<td><input type=radio name=\"WINSType\" value=\"1\" %s> %s </td>", ((winstype
== 1) ? "checked" : ""), _("Server for client use"));
819 printf("<td><input type=radio name=\"WINSType\" value=\"2\" %s> %s </td>", ((winstype
== 2) ? "checked" : ""), _("Client of another WINS server"));
821 printf("<tr><td></td><td></td><td></td><td>%s <input type=text size=\"16\" name=\"WINSAddr\" value=\"", _("Remote WINS Server"));
823 /* Print out the list of wins servers */
824 if(lp_wins_server_list()) {
826 const char **wins_servers
= lp_wins_server_list();
827 for(i
= 0; wins_servers
[i
]; i
++) printf("%s ", wins_servers
[i
]);
830 printf("\"></td></tr>\n");
832 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"));
833 printf("<tr><td></td><td colspan=3><font color=\"#ff0000\">%s</font></td></tr>\n", _("Please Select desired WINS mode above."));
835 printf("<tr><td><b>%s: </b></td>\n", _("Expose Home Directories"));
836 printf("<td><input type=radio name=\"HomeExpo\" value=\"1\" %s> Yes</td>", (have_home
== -1) ? "" : "checked ");
837 printf("<td><input type=radio name=\"HomeExpo\" value=\"0\" %s> No</td>", (have_home
== -1 ) ? "checked" : "");
838 printf("<td></td></tr>\n");
840 /* Enable this when we are ready ....
841 * printf("<tr><td><b>%s: </b></td>\n", _("Is Print Server"));
842 * printf("<td><input type=radio name=\"PtrSvr\" value=\"1\" %s> Yes</td>");
843 * printf("<td><input type=radio name=\"PtrSvr\" value=\"0\" %s> No</td>");
844 * printf("<td></td></tr>\n");
847 printf("</table></center>");
850 printf("%s\n", _("The above configuration options will set multiple parameters and will generally assist with rapid Samba deployment."));
855 /****************************************************************************
856 display a globals editing page
857 ****************************************************************************/
858 static void globals_page(void)
860 unsigned int parm_filter
= FLAG_BASIC
;
863 printf("<H2>%s</H2>\n", _("Global Parameters"));
865 if (cgi_variable("Commit")) {
866 commit_parameters(GLOBAL_SECTION_SNUM
);
870 if ( cgi_variable("ViewMode") )
871 mode
= atoi(cgi_variable_nonull("ViewMode"));
872 if ( cgi_variable("BasicMode"))
874 if ( cgi_variable("AdvMode"))
877 printf("<form name=\"swatform\" method=post action=globals>\n");
879 ViewModeBoxes( mode
);
882 parm_filter
= FLAG_BASIC
;
885 parm_filter
= FLAG_ADVANCED
;
889 if (have_write_access
) {
890 printf("<input type=submit name=\"Commit\" value=\"%s\">\n",
891 _("Commit Changes"));
894 printf("<input type=reset name=\"Reset Values\" value=\"%s\">\n",
899 show_parameters(GLOBAL_SECTION_SNUM
, 1, parm_filter
, 0);
900 printf("</table>\n");
904 /****************************************************************************
905 display a shares editing page. share is in unix codepage,
906 ****************************************************************************/
907 static void shares_page(void)
909 const char *share
= cgi_variable("share");
915 unsigned int parm_filter
= FLAG_BASIC
;
916 size_t converted_size
;
919 snum
= lp_servicenumber(share
);
921 printf("<H2>%s</H2>\n", _("Share Parameters"));
923 if (cgi_variable("Commit") && snum
>= 0) {
924 commit_parameters(snum
);
926 snum
= lp_servicenumber(share
);
929 if (cgi_variable("Delete") && snum
>= 0) {
930 lp_remove_service(snum
);
936 if (cgi_variable("createshare") && (share
=cgi_variable("newshare"))) {
937 snum
= lp_servicenumber(share
);
940 lp_copy_service(GLOBAL_SECTION_SNUM
, share
);
941 snum
= lp_servicenumber(share
);
943 snum
= lp_servicenumber(share
);
947 printf("<FORM name=\"swatform\" method=post>\n");
951 if ( cgi_variable("ViewMode") )
952 mode
= atoi(cgi_variable_nonull("ViewMode"));
953 if ( cgi_variable("BasicMode"))
955 if ( cgi_variable("AdvMode"))
958 ViewModeBoxes( mode
);
961 parm_filter
= FLAG_BASIC
;
964 parm_filter
= FLAG_ADVANCED
;
967 printf("<br><tr>\n");
968 printf("<td><input type=submit name=selectshare value=\"%s\"></td>\n", _("Choose Share"));
969 printf("<td><select name=share>\n");
971 printf("<option value=\" \"> \n");
972 for (i
=0;i
<lp_numservices();i
++) {
973 s
= lp_servicename(i
);
974 if (s
&& (*s
) && strcmp(s
,"IPC$") && !lp_print_ok(i
)) {
975 push_utf8_talloc(talloc_tos(), &utf8_s
, s
, &converted_size
);
976 printf("<option %s value=\"%s\">%s\n",
977 (share
&& strcmp(share
,s
)==0)?"SELECTED":"",
982 printf("</select></td>\n");
983 if (have_write_access
) {
984 printf("<td><input type=submit name=\"Delete\" value=\"%s\"></td>\n", _("Delete Share"));
989 if (have_write_access
) {
991 printf("<td><input type=submit name=createshare value=\"%s\"></td>\n", _("Create Share"));
992 printf("<td><input type=text size=30 name=newshare></td></tr>\n");
998 if (have_write_access
) {
999 printf("<input type=submit name=\"Commit\" value=\"%s\">\n", _("Commit Changes"));
1002 printf("<input type=reset name=\"Reset Values\" value=\"%s\">\n", _("Reset Values"));
1007 printf("<table>\n");
1008 show_parameters(snum
, 1, parm_filter
, 0);
1009 printf("</table>\n");
1012 printf("</FORM>\n");
1015 /*************************************************************
1016 change a password either locally or remotely
1017 *************************************************************/
1018 static bool change_password(const char *remote_machine
, const char *user_name
,
1019 const char *old_passwd
, const char *new_passwd
,
1023 char *err_str
= NULL
;
1024 char *msg_str
= NULL
;
1027 printf("%s\n<p>", _("password change in demo mode rejected"));
1031 if (remote_machine
!= NULL
) {
1032 ret
= remote_password_change(remote_machine
, user_name
,
1033 old_passwd
, new_passwd
, &err_str
);
1034 if (err_str
!= NULL
)
1035 printf("%s\n<p>", err_str
);
1037 return NT_STATUS_IS_OK(ret
);
1040 if(!initialize_password_db(True
, NULL
)) {
1041 printf("%s\n<p>", _("Can't setup password database vectors."));
1045 ret
= local_password_change(user_name
, local_flags
, new_passwd
,
1046 &err_str
, &msg_str
);
1049 printf("%s\n<p>", msg_str
);
1051 printf("%s\n<p>", err_str
);
1055 return NT_STATUS_IS_OK(ret
);
1058 /****************************************************************************
1059 do the stuff required to add or change a password
1060 ****************************************************************************/
1061 static void chg_passwd(void)
1065 int local_flags
= 0;
1067 /* Make sure users name has been specified */
1068 if (strlen(cgi_variable_nonull(SWAT_USER
)) == 0) {
1069 printf("<p>%s\n", _(" Must specify \"User Name\" "));
1074 * smbpasswd doesn't require anything but the users name to delete, disable or enable the user,
1075 * so if that's what we're doing, skip the rest of the checks
1077 if (!cgi_variable(DISABLE_USER_FLAG
) && !cgi_variable(ENABLE_USER_FLAG
) && !cgi_variable(DELETE_USER_FLAG
)) {
1080 * If current user is not root, make sure old password has been specified
1081 * If REMOTE change, even root must provide old password
1083 if (((!am_root()) && (strlen( cgi_variable_nonull(OLD_PSWD
)) <= 0)) ||
1084 ((cgi_variable(CHG_R_PASSWD_FLAG
)) && (strlen( cgi_variable_nonull(OLD_PSWD
)) <= 0))) {
1085 printf("<p>%s\n", _(" Must specify \"Old Password\" "));
1089 /* If changing a users password on a remote hosts we have to know what host */
1090 if ((cgi_variable(CHG_R_PASSWD_FLAG
)) && (strlen( cgi_variable_nonull(RHOST
)) <= 0)) {
1091 printf("<p>%s\n", _(" Must specify \"Remote Machine\" "));
1095 /* Make sure new passwords have been specified */
1096 if ((strlen( cgi_variable_nonull(NEW_PSWD
)) <= 0) ||
1097 (strlen( cgi_variable_nonull(NEW2_PSWD
)) <= 0)) {
1098 printf("<p>%s\n", _(" Must specify \"New, and Re-typed Passwords\" "));
1102 /* Make sure new passwords was typed correctly twice */
1103 if (strcmp(cgi_variable_nonull(NEW_PSWD
), cgi_variable_nonull(NEW2_PSWD
)) != 0) {
1104 printf("<p>%s\n", _(" Re-typed password didn't match new password "));
1109 if (cgi_variable(CHG_R_PASSWD_FLAG
)) {
1110 host
= cgi_variable(RHOST
);
1111 } else if (am_root()) {
1118 * Set up the local flags.
1121 local_flags
|= (cgi_variable(ADD_USER_FLAG
) ? LOCAL_ADD_USER
: 0);
1122 local_flags
|= (cgi_variable(ADD_USER_FLAG
) ? LOCAL_SET_PASSWORD
: 0);
1123 local_flags
|= (cgi_variable(CHG_S_PASSWD_FLAG
) ? LOCAL_SET_PASSWORD
: 0);
1124 local_flags
|= (cgi_variable(DELETE_USER_FLAG
) ? LOCAL_DELETE_USER
: 0);
1125 local_flags
|= (cgi_variable(ENABLE_USER_FLAG
) ? LOCAL_ENABLE_USER
: 0);
1126 local_flags
|= (cgi_variable(DISABLE_USER_FLAG
) ? LOCAL_DISABLE_USER
: 0);
1128 rslt
= change_password(host
,
1129 cgi_variable_nonull(SWAT_USER
),
1130 cgi_variable_nonull(OLD_PSWD
), cgi_variable_nonull(NEW_PSWD
),
1133 if(cgi_variable(CHG_S_PASSWD_FLAG
)) {
1136 printf(_(" The passwd for '%s' has been changed."), cgi_variable_nonull(SWAT_USER
));
1139 printf(_(" The passwd for '%s' has NOT been changed."), cgi_variable_nonull(SWAT_USER
));
1147 /****************************************************************************
1148 display a password editing page
1149 ****************************************************************************/
1150 static void passwd_page(void)
1152 const char *new_name
= cgi_user_name();
1155 * After the first time through here be nice. If the user
1156 * changed the User box text to another users name, remember it.
1158 if (cgi_variable(SWAT_USER
)) {
1159 new_name
= cgi_variable_nonull(SWAT_USER
);
1162 if (!new_name
) new_name
= "";
1164 printf("<H2>%s</H2>\n", _("Server Password Management"));
1166 printf("<FORM name=\"swatform\" method=post>\n");
1168 printf("<table>\n");
1171 * Create all the dialog boxes for data collection
1173 printf("<tr><td> %s : </td>\n", _("User Name"));
1174 printf("<td><input type=text size=30 name=%s value=%s></td></tr> \n", SWAT_USER
, new_name
);
1176 printf("<tr><td> %s : </td>\n", _("Old Password"));
1177 printf("<td><input type=password size=30 name=%s></td></tr> \n",OLD_PSWD
);
1179 printf("<tr><td> %s : </td>\n", _("New Password"));
1180 printf("<td><input type=password size=30 name=%s></td></tr>\n",NEW_PSWD
);
1181 printf("<tr><td> %s : </td>\n", _("Re-type New Password"));
1182 printf("<td><input type=password size=30 name=%s></td></tr>\n",NEW2_PSWD
);
1183 printf("</table>\n");
1186 * Create all the control buttons for requesting action
1188 printf("<input type=submit name=%s value=\"%s\">\n",
1189 CHG_S_PASSWD_FLAG
, _("Change Password"));
1190 if (demo_mode
|| am_root()) {
1191 printf("<input type=submit name=%s value=\"%s\">\n",
1192 ADD_USER_FLAG
, _("Add New User"));
1193 printf("<input type=submit name=%s value=\"%s\">\n",
1194 DELETE_USER_FLAG
, _("Delete User"));
1195 printf("<input type=submit name=%s value=\"%s\">\n",
1196 DISABLE_USER_FLAG
, _("Disable User"));
1197 printf("<input type=submit name=%s value=\"%s\">\n",
1198 ENABLE_USER_FLAG
, _("Enable User"));
1200 printf("<p></FORM>\n");
1203 * Do some work if change, add, disable or enable was
1204 * requested. It could be this is the first time through this
1205 * code, so there isn't anything to do. */
1206 if ((cgi_variable(CHG_S_PASSWD_FLAG
)) || (cgi_variable(ADD_USER_FLAG
)) || (cgi_variable(DELETE_USER_FLAG
)) ||
1207 (cgi_variable(DISABLE_USER_FLAG
)) || (cgi_variable(ENABLE_USER_FLAG
))) {
1211 printf("<H2>%s</H2>\n", _("Client/Server Password Management"));
1213 printf("<FORM name=\"swatform\" method=post>\n");
1215 printf("<table>\n");
1218 * Create all the dialog boxes for data collection
1220 printf("<tr><td> %s : </td>\n", _("User Name"));
1221 printf("<td><input type=text size=30 name=%s value=%s></td></tr>\n",SWAT_USER
, new_name
);
1222 printf("<tr><td> %s : </td>\n", _("Old Password"));
1223 printf("<td><input type=password size=30 name=%s></td></tr>\n",OLD_PSWD
);
1224 printf("<tr><td> %s : </td>\n", _("New Password"));
1225 printf("<td><input type=password size=30 name=%s></td></tr>\n",NEW_PSWD
);
1226 printf("<tr><td> %s : </td>\n", _("Re-type New Password"));
1227 printf("<td><input type=password size=30 name=%s></td></tr>\n",NEW2_PSWD
);
1228 printf("<tr><td> %s : </td>\n", _("Remote Machine"));
1229 printf("<td><input type=text size=30 name=%s></td></tr>\n",RHOST
);
1234 * Create all the control buttons for requesting action
1236 printf("<input type=submit name=%s value=\"%s\">",
1237 CHG_R_PASSWD_FLAG
, _("Change Password"));
1239 printf("<p></FORM>\n");
1242 * Do some work if a request has been made to change the
1243 * password somewhere other than the server. It could be this
1244 * is the first time through this code, so there isn't
1245 * anything to do. */
1246 if (cgi_variable(CHG_R_PASSWD_FLAG
)) {
1252 /****************************************************************************
1253 display a printers editing page
1254 ****************************************************************************/
1255 static void printers_page(void)
1257 const char *share
= cgi_variable("share");
1262 unsigned int parm_filter
= FLAG_BASIC
;
1265 snum
= lp_servicenumber(share
);
1267 printf("<H2>%s</H2>\n", _("Printer Parameters"));
1269 printf("<H3>%s</H3>\n", _("Important Note:"));
1270 printf("%s",_("Printer names marked with [*] in the Choose Printer drop-down box "));
1271 printf("%s",_("are autoloaded printers from "));
1272 printf("<A HREF=\"/swat/help/smb.conf.5.html#printcapname\" target=\"docs\">%s</A>\n", _("Printcap Name"));
1273 printf("%s\n", _("Attempting to delete these printers from SWAT will have no effect."));
1275 if (cgi_variable("Commit") && snum
>= 0) {
1276 commit_parameters(snum
);
1277 if (snum
>= iNumNonAutoPrintServices
)
1281 snum
= lp_servicenumber(share
);
1284 if (cgi_variable("Delete") && snum
>= 0) {
1285 lp_remove_service(snum
);
1291 if (cgi_variable("createshare") && (share
=cgi_variable("newshare"))) {
1292 snum
= lp_servicenumber(share
);
1293 if (snum
< 0 || snum
>= iNumNonAutoPrintServices
) {
1295 lp_copy_service(GLOBAL_SECTION_SNUM
, share
);
1296 snum
= lp_servicenumber(share
);
1297 lp_do_parameter(snum
, "print ok", "Yes");
1299 snum
= lp_servicenumber(share
);
1303 printf("<FORM name=\"swatform\" method=post>\n");
1305 if ( cgi_variable("ViewMode") )
1306 mode
= atoi(cgi_variable_nonull("ViewMode"));
1307 if ( cgi_variable("BasicMode"))
1309 if ( cgi_variable("AdvMode"))
1312 ViewModeBoxes( mode
);
1315 parm_filter
= FLAG_BASIC
;
1318 parm_filter
= FLAG_ADVANCED
;
1321 printf("<table>\n");
1322 printf("<tr><td><input type=submit name=\"selectshare\" value=\"%s\"></td>\n", _("Choose Printer"));
1323 printf("<td><select name=\"share\">\n");
1324 if (snum
< 0 || !lp_print_ok(snum
))
1325 printf("<option value=\" \"> \n");
1326 for (i
=0;i
<lp_numservices();i
++) {
1327 s
= lp_servicename(i
);
1328 if (s
&& (*s
) && strcmp(s
,"IPC$") && lp_print_ok(i
)) {
1329 if (i
>= iNumNonAutoPrintServices
)
1330 printf("<option %s value=\"%s\">[*]%s\n",
1331 (share
&& strcmp(share
,s
)==0)?"SELECTED":"",
1334 printf("<option %s value=\"%s\">%s\n",
1335 (share
&& strcmp(share
,s
)==0)?"SELECTED":"",
1339 printf("</select></td>");
1340 if (have_write_access
) {
1341 printf("<td><input type=submit name=\"Delete\" value=\"%s\"></td>\n", _("Delete Printer"));
1344 printf("</table>\n");
1346 if (have_write_access
) {
1347 printf("<table>\n");
1348 printf("<tr><td><input type=submit name=\"createshare\" value=\"%s\"></td>\n", _("Create Printer"));
1349 printf("<td><input type=text size=30 name=\"newshare\"></td></tr>\n");
1355 if (have_write_access
) {
1356 printf("<input type=submit name=\"Commit\" value=\"%s\">\n", _("Commit Changes"));
1358 printf("<input type=reset name=\"Reset Values\" value=\"%s\">\n", _("Reset Values"));
1363 printf("<table>\n");
1364 show_parameters(snum
, 1, parm_filter
, 1);
1365 printf("</table>\n");
1367 printf("</FORM>\n");
1371 when the _() translation macro is used there is no obvious place to free
1372 the resulting string and there is no easy way to give a static pointer.
1373 All we can do is rotate between some static buffers and hope a single d_printf()
1374 doesn't have more calls to _() than the number of buffers
1377 const char *lang_msg_rotate(TALLOC_CTX
*ctx
, const char *msgid
)
1382 msgstr
= lang_msg(msgid
);
1387 ret
= talloc_strdup(ctx
, msgstr
);
1389 lang_msg_free(msgstr
);
1398 * main function for SWAT.
1400 int main(int argc
, char *argv
[])
1404 struct poptOption long_options
[] = {
1406 { "disable-authentication", 'a', POPT_ARG_VAL
, &demo_mode
, True
, "Disable authentication (demo mode)" },
1407 { "password-menu-only", 'P', POPT_ARG_VAL
, &passwd_only
, True
, "Show only change password menu" },
1411 TALLOC_CTX
*frame
= talloc_stackframe();
1414 umask(S_IWGRP
| S_IWOTH
);
1416 #if defined(HAVE_SET_AUTH_PARAMETERS)
1417 set_auth_parameters(argc
, argv
);
1418 #endif /* HAVE_SET_AUTH_PARAMETERS */
1420 /* just in case it goes wild ... */
1425 /* we don't want any SIGPIPE messages */
1426 BlockSignals(True
,SIGPIPE
);
1428 debug_set_logfile("/dev/null");
1430 /* we don't want stderr screwing us up */
1432 open("/dev/null", O_WRONLY
);
1433 setup_logging("swat", DEBUG_FILE
);
1437 pc
= poptGetContext("swat", argc
, (const char **) argv
, long_options
, 0);
1439 /* Parse command line options */
1441 while(poptGetNextOpt(pc
) != -1) { }
1443 poptFreeContext(pc
);
1445 /* This should set a more apporiate log file */
1449 iNumNonAutoPrintServices
= lp_numservices();
1450 if (pcap_cache_loaded()) {
1451 load_printers(server_event_context(),
1452 server_messaging_context());
1455 cgi_setup(get_dyn_SWATDIR(), !demo_mode
);
1459 cgi_load_variables();
1461 if (!file_exist(get_dyn_CONFIGFILE())) {
1462 have_read_access
= True
;
1463 have_write_access
= True
;
1465 /* check if the authenticated user has write access - if not then
1466 don't show write options */
1467 have_write_access
= (access(get_dyn_CONFIGFILE(),W_OK
) == 0);
1469 /* if the user doesn't have read access to smb.conf then
1470 don't let them view it */
1471 have_read_access
= (access(get_dyn_CONFIGFILE(),R_OK
) == 0);
1474 show_main_buttons();
1476 page
= cgi_pathinfo();
1478 /* Root gets full functionality */
1479 if (have_read_access
&& strcmp(page
, "globals")==0) {
1481 } else if (have_read_access
&& strcmp(page
,"shares")==0) {
1483 } else if (have_read_access
&& strcmp(page
,"printers")==0) {
1485 } else if (have_read_access
&& strcmp(page
,"status")==0) {
1487 } else if (have_read_access
&& strcmp(page
,"viewconfig")==0) {
1489 } else if (strcmp(page
,"passwd")==0) {
1491 } else if (have_read_access
&& strcmp(page
,"wizard")==0) {
1493 } else if (have_read_access
&& strcmp(page
,"wizard_params")==0) {
1494 wizard_params_page();
1495 } else if (have_read_access
&& strcmp(page
,"rewritecfg")==0) {