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 "popt_common.h"
32 #include "web/swat_proto.h"
33 #include "printing/pcap.h"
35 static int demo_mode = False;
36 static int passwd_only = False;
37 static bool have_write_access = False;
38 static bool have_read_access = False;
39 static int iNumNonAutoPrintServices = 0;
42 * Password Management Globals
44 #define SWAT_USER "username"
45 #define OLD_PSWD "old_passwd"
46 #define NEW_PSWD "new_passwd"
47 #define NEW2_PSWD "new2_passwd"
48 #define CHG_S_PASSWD_FLAG "chg_s_passwd_flag"
49 #define CHG_R_PASSWD_FLAG "chg_r_passwd_flag"
50 #define ADD_USER_FLAG "add_user_flag"
51 #define DELETE_USER_FLAG "delete_user_flag"
52 #define DISABLE_USER_FLAG "disable_user_flag"
53 #define ENABLE_USER_FLAG "enable_user_flag"
54 #define RHOST "remote_host"
56 #define _(x) lang_msg_rotate(talloc_tos(),x)
58 /****************************************************************************
59 ****************************************************************************/
60 static int enum_index(int value, const struct enum_list *enumlist)
63 for (i=0;enumlist[i].name;i++)
64 if (value == enumlist[i].value) break;
68 static char *fix_backslash(const char *str)
70 static char newstring[1024];
74 if (*str == '\\') {*p++ = '\\';*p++ = '\\';}
82 static const char *fix_quotes(TALLOC_CTX *ctx, const char *str)
84 char *newstring = NULL;
87 int quote_len = strlen(""");
89 /* Count the number of quotes. */
94 newstring_len += quote_len;
100 newstring = TALLOC_ARRAY(ctx, char, newstring_len);
104 for (p = newstring; *str; str++) {
106 strncpy( p, """, quote_len);
116 static char *stripspaceupper(const char *str)
118 static char newstring[1024];
122 if (*str != ' ') *p++ = toupper_ascii(*str);
129 static char *make_parm_name(const char *label)
131 static char parmname[1024];
135 if (*label == ' ') *p++ = '_';
143 /****************************************************************************
144 include a lump of html in a page
145 ****************************************************************************/
146 static int include_html(const char *fname)
152 fd = web_open(fname, O_RDONLY, 0);
155 printf(_("ERROR: Can't open %s"), fname);
160 while ((ret = read(fd, buf, sizeof(buf))) > 0) {
161 if (write(1, buf, ret) == -1) {
170 /****************************************************************************
171 start the page with standard stuff
172 ****************************************************************************/
173 static void print_header(void)
175 if (!cgi_waspost()) {
176 printf("Expires: 0\r\n");
178 printf("Content-type: text/html\r\n\r\n");
180 if (!include_html("include/header.html")) {
181 printf("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n");
182 printf("<HTML>\n<HEAD>\n<TITLE>Samba Web Administration Tool</TITLE>\n</HEAD>\n<BODY background=\"/swat/images/background.jpg\">\n\n");
186 /* *******************************************************************
187 show parameter label with translated name in the following form
188 because showing original and translated label in one line looks
189 too long, and showing translated label only is unusable for
191 -------------------------------
192 HELP security [combo box][button]
194 -------------------------------
195 (capital words are translated by gettext.)
196 if no translation is available, then same form as original is
198 "i18n_translated_parm" class is used to change the color of the
199 translated parameter with CSS.
200 **************************************************************** */
201 static const char *get_parm_translated(TALLOC_CTX *ctx,
202 const char* pAnchor, const char* pHelp, const char* pLabel)
204 const char *pTranslated = _(pLabel);
206 if(strcmp(pLabel, pTranslated) != 0) {
207 output = talloc_asprintf(ctx,
208 "<A HREF=\"/swat/help/manpages/smb.conf.5.html#%s\" target=\"docs\"> %s</A> %s <br><span class=\"i18n_translated_parm\">%s</span>",
209 pAnchor, pHelp, pLabel, pTranslated);
212 output = talloc_asprintf(ctx,
213 "<A HREF=\"/swat/help/manpages/smb.conf.5.html#%s\" target=\"docs\"> %s</A> %s",
214 pAnchor, pHelp, pLabel);
217 /****************************************************************************
219 ****************************************************************************/
220 static void print_footer(void)
222 if (!include_html("include/footer.html")) {
223 printf("\n</BODY>\n</HTML>\n");
227 /****************************************************************************
228 display one editable parameter in a form
229 ****************************************************************************/
230 static void show_parameter(int snum, struct parm_struct *parm)
233 void *ptr = parm->ptr;
234 char *utf8_s1, *utf8_s2;
235 size_t converted_size;
236 TALLOC_CTX *ctx = talloc_stackframe();
238 if (parm->p_class == P_LOCAL && snum >= 0) {
239 ptr = lp_local_ptr_by_snum(snum, ptr);
242 printf("<tr><td>%s</td><td>", get_parm_translated(ctx,
243 stripspaceupper(parm->label), _("Help"), parm->label));
244 switch (parm->type) {
246 printf("<input type=text size=2 name=\"parm_%s\" value=\"%c\">",
247 make_parm_name(parm->label), *(char *)ptr);
248 printf("<input type=button value=\"%s\" onClick=\"swatform.parm_%s.value=\'%c\'\">",
249 _("Set Default"), make_parm_name(parm->label),(char)(parm->def.cvalue));
253 printf("<input type=text size=40 name=\"parm_%s\" value=\"",
254 make_parm_name(parm->label));
255 if ((char ***)ptr && *(char ***)ptr && **(char ***)ptr) {
256 char **list = *(char ***)ptr;
257 for (;*list;list++) {
258 /* enclose in HTML encoded quotes if the string contains a space */
259 if ( strchr_m(*list, ' ') ) {
260 push_utf8_talloc(talloc_tos(), &utf8_s1, *list, &converted_size);
261 push_utf8_talloc(talloc_tos(), &utf8_s2, ((*(list+1))?", ":""), &converted_size);
262 printf(""%s"%s", utf8_s1, utf8_s2);
264 push_utf8_talloc(talloc_tos(), &utf8_s1, *list, &converted_size);
265 push_utf8_talloc(talloc_tos(), &utf8_s2, ((*(list+1))?", ":""), &converted_size);
266 printf("%s%s", utf8_s1, utf8_s2);
268 TALLOC_FREE(utf8_s1);
269 TALLOC_FREE(utf8_s2);
273 printf("<input type=button value=\"%s\" onClick=\"swatform.parm_%s.value=\'",
274 _("Set Default"), make_parm_name(parm->label));
275 if (parm->def.lvalue) {
276 char **list = (char **)(parm->def.lvalue);
277 for (; *list; list++) {
278 /* enclose in HTML encoded quotes if the string contains a space */
279 if ( strchr_m(*list, ' ') )
280 printf(""%s"%s", *list, ((*(list+1))?", ":""));
282 printf("%s%s", *list, ((*(list+1))?", ":""));
290 push_utf8_talloc(talloc_tos(), &utf8_s1, *(char **)ptr, &converted_size);
291 printf("<input type=text size=40 name=\"parm_%s\" value=\"%s\">",
292 make_parm_name(parm->label), fix_quotes(ctx, utf8_s1));
293 TALLOC_FREE(utf8_s1);
294 printf("<input type=button value=\"%s\" onClick=\"swatform.parm_%s.value=\'%s\'\">",
295 _("Set Default"), make_parm_name(parm->label),fix_backslash((char *)(parm->def.svalue)));
299 printf("<select name=\"parm_%s\">",make_parm_name(parm->label));
300 printf("<option %s>Yes", (*(bool *)ptr)?"selected":"");
301 printf("<option %s>No", (*(bool *)ptr)?"":"selected");
303 printf("<input type=button value=\"%s\" onClick=\"swatform.parm_%s.selectedIndex=\'%d\'\">",
304 _("Set Default"), make_parm_name(parm->label),(bool)(parm->def.bvalue)?0:1);
308 printf("<select name=\"parm_%s\">",make_parm_name(parm->label));
309 printf("<option %s>Yes", (*(bool *)ptr)?"":"selected");
310 printf("<option %s>No", (*(bool *)ptr)?"selected":"");
312 printf("<input type=button value=\"%s\" onClick=\"swatform.parm_%s.selectedIndex=\'%d\'\">",
313 _("Set Default"), make_parm_name(parm->label),(bool)(parm->def.bvalue)?1:0);
317 printf("<input type=text size=8 name=\"parm_%s\" value=\"%d\">", make_parm_name(parm->label), *(int *)ptr);
318 printf("<input type=button value=\"%s\" onClick=\"swatform.parm_%s.value=\'%d\'\">",
319 _("Set Default"), make_parm_name(parm->label),(int)(parm->def.ivalue));
324 o = octal_string(*(int *)ptr);
325 printf("<input type=text size=8 name=\"parm_%s\" value=%s>",
326 make_parm_name(parm->label), o);
328 o = octal_string((int)(parm->def.ivalue));
329 printf("<input type=button value=\"%s\" "
330 "onClick=\"swatform.parm_%s.value=\'%s\'\">",
331 _("Set Default"), make_parm_name(parm->label), o);
337 printf("<select name=\"parm_%s\">",make_parm_name(parm->label));
338 for (i=0;parm->enum_list[i].name;i++) {
339 if (i == 0 || parm->enum_list[i].value != parm->enum_list[i-1].value) {
340 printf("<option %s>%s",(*(int *)ptr)==parm->enum_list[i].value?"selected":"",parm->enum_list[i].name);
344 printf("<input type=button value=\"%s\" onClick=\"swatform.parm_%s.selectedIndex=\'%d\'\">",
345 _("Set Default"), make_parm_name(parm->label),enum_index((int)(parm->def.ivalue),parm->enum_list));
350 printf("</td></tr>\n");
354 /****************************************************************************
355 display a set of parameters for a service
356 ****************************************************************************/
357 static void show_parameters(int snum, int allparameters, unsigned int parm_filter, int printers)
360 struct parm_struct *parm;
361 const char *heading = NULL;
362 const char *last_heading = NULL;
364 while ((parm = lp_next_parameter(snum, &i, allparameters))) {
365 if (snum < 0 && parm->p_class == P_LOCAL && !(parm->flags & FLAG_GLOBAL))
367 if (parm->p_class == P_SEPARATOR) {
368 heading = parm->label;
371 if (parm->flags & FLAG_HIDE) continue;
373 if (printers & !(parm->flags & FLAG_PRINT)) continue;
374 if (!printers & !(parm->flags & FLAG_SHARE)) continue;
377 if (!( parm_filter & FLAG_ADVANCED )) {
378 if (!(parm->flags & FLAG_BASIC)) {
379 void *ptr = parm->ptr;
381 if (parm->p_class == P_LOCAL && snum >= 0) {
382 ptr = lp_local_ptr_by_snum(snum, ptr);
385 switch (parm->type) {
387 if (*(char *)ptr == (char)(parm->def.cvalue)) continue;
391 if (!str_list_equal(*(const char ***)ptr,
392 (const char **)(parm->def.lvalue))) continue;
397 if (!strcmp(*(char **)ptr,(char *)(parm->def.svalue))) continue;
402 if (*(bool *)ptr == (bool)(parm->def.bvalue)) continue;
407 if (*(int *)ptr == (int)(parm->def.ivalue)) continue;
412 if (*(int *)ptr == (int)(parm->def.ivalue)) continue;
418 if (printers && !(parm->flags & FLAG_PRINT)) continue;
421 if ((parm_filter & FLAG_WIZARD) && !(parm->flags & FLAG_WIZARD)) continue;
423 if ((parm_filter & FLAG_ADVANCED) && !(parm->flags & FLAG_ADVANCED)) continue;
425 if (heading && heading != last_heading) {
426 printf("<tr><td></td></tr><tr><td><b><u>%s</u></b></td></tr>\n", _(heading));
427 last_heading = heading;
429 show_parameter(snum, parm);
433 /****************************************************************************
434 load the smb.conf file into loadparm.
435 ****************************************************************************/
436 static bool load_config(bool save_def)
438 return lp_load(get_dyn_CONFIGFILE(),False,save_def,False,True);
441 /****************************************************************************
443 ****************************************************************************/
444 static void write_config(FILE *f, bool show_defaults)
446 TALLOC_CTX *ctx = talloc_stackframe();
448 fprintf(f, "# Samba config file created using SWAT\n");
449 fprintf(f, "# from %s (%s)\n", cgi_remote_host(), cgi_remote_addr());
450 fprintf(f, "# Date: %s\n\n", current_timestring(ctx, False));
452 lp_dump(f, show_defaults, iNumNonAutoPrintServices);
457 /****************************************************************************
458 save and reload the smb.conf config file
459 ****************************************************************************/
460 static int save_reload(int snum)
465 f = sys_fopen(get_dyn_CONFIGFILE(),"w");
467 printf(_("failed to open %s for writing"), get_dyn_CONFIGFILE());
472 /* just in case they have used the buggy xinetd to create the file */
473 if (fstat(fileno(f), &st) == 0 &&
474 (st.st_mode & S_IWOTH)) {
475 #if defined HAVE_FCHMOD
476 fchmod(fileno(f), S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH);
478 chmod(get_dyn_CONFIGFILE(), S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH);
482 write_config(f, False);
484 lp_dump_one(f, False, snum);
487 lp_kill_all_services();
489 if (!load_config(False)) {
490 printf(_("Can't reload %s"), get_dyn_CONFIGFILE());
494 iNumNonAutoPrintServices = lp_numservices();
495 if (pcap_cache_loaded()) {
496 load_printers(server_event_context(),
497 server_messaging_context());
503 /****************************************************************************
505 ****************************************************************************/
506 static void commit_parameter(int snum, struct parm_struct *parm, const char *v)
511 if (snum < 0 && parm->p_class == P_LOCAL) {
512 /* this handles the case where we are changing a local
513 variable globally. We need to change the parameter in
514 all shares where it is currently set to the default */
515 for (i=0;i<lp_numservices();i++) {
516 s = lp_servicename(i);
517 if (s && (*s) && lp_is_default(i, parm)) {
518 lp_do_parameter(i, parm->label, v);
523 lp_do_parameter(snum, parm->label, v);
526 /****************************************************************************
527 commit a set of parameters for a service
528 ****************************************************************************/
529 static void commit_parameters(int snum)
532 struct parm_struct *parm;
536 while ((parm = lp_next_parameter(snum, &i, 1))) {
537 if (asprintf(&label, "parm_%s", make_parm_name(parm->label)) > 0) {
538 if ((v = cgi_variable(label)) != NULL) {
539 if (parm->flags & FLAG_HIDE)
541 commit_parameter(snum, parm, v);
548 /****************************************************************************
549 spit out the html for a link with an image
550 ****************************************************************************/
551 static void image_link(const char *name, const char *hlink, const char *src)
553 printf("<A HREF=\"%s/%s\"><img border=\"0\" src=\"/swat/%s\" alt=\"%s\"></A>\n",
554 cgi_baseurl(), hlink, src, name);
557 /****************************************************************************
558 display the main navigation controls at the top of each page along
560 ****************************************************************************/
561 static void show_main_buttons(void)
565 if ((p = cgi_user_name()) && strcmp(p, "root")) {
566 printf(_("Logged in as <b>%s</b>"), p);
570 image_link(_("Home"), "", "images/home.gif");
571 if (have_write_access) {
572 image_link(_("Globals"), "globals", "images/globals.gif");
573 image_link(_("Shares"), "shares", "images/shares.gif");
574 image_link(_("Printers"), "printers", "images/printers.gif");
575 image_link(_("Wizard"), "wizard", "images/wizard.gif");
577 /* root always gets all buttons, otherwise look for -P */
578 if ( have_write_access || (!passwd_only && have_read_access) ) {
579 image_link(_("Status"), "status", "images/status.gif");
580 image_link(_("View Config"), "viewconfig", "images/viewconfig.gif");
582 image_link(_("Password Management"), "passwd", "images/passwd.gif");
587 /****************************************************************************
588 * Handle Display/Edit Mode CGI
589 ****************************************************************************/
590 static void ViewModeBoxes(int mode)
592 printf("<p>%s: \n", _("Current View Is"));
593 printf("<input type=radio name=\"ViewMode\" value=0 %s>%s\n", ((mode == 0) ? "checked" : ""), _("Basic"));
594 printf("<input type=radio name=\"ViewMode\" value=1 %s>%s\n", ((mode == 1) ? "checked" : ""), _("Advanced"));
595 printf("<br>%s: \n", _("Change View To"));
596 printf("<input type=submit name=\"BasicMode\" value=\"%s\">\n", _("Basic"));
597 printf("<input type=submit name=\"AdvMode\" value=\"%s\">\n", _("Advanced"));
598 printf("</p><br>\n");
601 /****************************************************************************
602 display a welcome page
603 ****************************************************************************/
604 static void welcome_page(void)
606 if (file_exist("help/welcome.html")) {
607 include_html("help/welcome.html");
609 include_html("help/welcome-no-samba-doc.html");
613 /****************************************************************************
614 display the current smb.conf
615 ****************************************************************************/
616 static void viewconfig_page(void)
620 if (cgi_variable("full_view")) {
624 printf("<H2>%s</H2>\n", _("Current Config"));
625 printf("<form method=post>\n");
628 printf("<input type=submit name=\"normal_view\" value=\"%s\">\n", _("Normal View"));
630 printf("<input type=submit name=\"full_view\" value=\"%s\">\n", _("Full View"));
634 write_config(stdout, full_view);
639 /****************************************************************************
640 second screen of the wizard ... Fetch Configuration Parameters
641 ****************************************************************************/
642 static void wizard_params_page(void)
644 unsigned int parm_filter = FLAG_WIZARD;
646 /* Here we first set and commit all the parameters that were selected
647 in the previous screen. */
649 printf("<H2>%s</H2>\n", _("Wizard Parameter Edit Page"));
651 if (cgi_variable("Commit")) {
652 commit_parameters(GLOBAL_SECTION_SNUM);
656 printf("<form name=\"swatform\" method=post action=wizard_params>\n");
658 if (have_write_access) {
659 printf("<input type=submit name=\"Commit\" value=\"Commit Changes\">\n");
662 printf("<input type=reset name=\"Reset Values\" value=\"Reset\">\n");
666 show_parameters(GLOBAL_SECTION_SNUM, 1, parm_filter, 0);
667 printf("</table>\n");
671 /****************************************************************************
672 Utility to just rewrite the smb.conf file - effectively just cleans it up
673 ****************************************************************************/
674 static void rewritecfg_file(void)
676 commit_parameters(GLOBAL_SECTION_SNUM);
678 printf("<H2>%s</H2>\n", _("Note: smb.conf file has been read and rewritten"));
681 /****************************************************************************
682 wizard to create/modify the smb.conf file
683 ****************************************************************************/
684 static void wizard_page(void)
686 /* Set some variables to collect data from smb.conf */
693 if (cgi_variable("Rewrite")) {
694 (void) rewritecfg_file();
698 if (cgi_variable("GetWizardParams")){
699 (void) wizard_params_page();
703 if (cgi_variable("Commit")){
704 SerType = atoi(cgi_variable_nonull("ServerType"));
705 winstype = atoi(cgi_variable_nonull("WINSType"));
706 have_home = lp_servicenumber(HOMES_NAME);
707 HomeExpo = atoi(cgi_variable_nonull("HomeExpo"));
709 /* Plain text passwords are too badly broken - use encrypted passwords only */
710 lp_do_parameter( GLOBAL_SECTION_SNUM, "encrypt passwords", "Yes");
714 /* Stand-alone Server */
715 lp_do_parameter( GLOBAL_SECTION_SNUM, "security", "USER" );
716 lp_do_parameter( GLOBAL_SECTION_SNUM, "domain logons", "No" );
720 lp_do_parameter( GLOBAL_SECTION_SNUM, "security", "DOMAIN" );
721 lp_do_parameter( GLOBAL_SECTION_SNUM, "domain logons", "No" );
724 /* Domain Controller */
725 lp_do_parameter( GLOBAL_SECTION_SNUM, "security", "USER" );
726 lp_do_parameter( GLOBAL_SECTION_SNUM, "domain logons", "Yes" );
729 switch ( winstype ) {
731 lp_do_parameter( GLOBAL_SECTION_SNUM, "wins support", "No" );
732 lp_do_parameter( GLOBAL_SECTION_SNUM, "wins server", "" );
735 lp_do_parameter( GLOBAL_SECTION_SNUM, "wins support", "Yes" );
736 lp_do_parameter( GLOBAL_SECTION_SNUM, "wins server", "" );
739 lp_do_parameter( GLOBAL_SECTION_SNUM, "wins support", "No" );
740 lp_do_parameter( GLOBAL_SECTION_SNUM, "wins server", cgi_variable_nonull("WINSAddr"));
744 /* Have to create Homes share? */
745 if ((HomeExpo == 1) && (have_home == -1)) {
746 const char *unix_share = HOMES_NAME;
749 lp_copy_service(GLOBAL_SECTION_SNUM, unix_share);
750 have_home = lp_servicenumber(HOMES_NAME);
751 lp_do_parameter( have_home, "read only", "No");
752 lp_do_parameter( have_home, "valid users", "%S");
753 lp_do_parameter( have_home, "browseable", "No");
754 commit_parameters(have_home);
755 save_reload(have_home);
758 /* Need to Delete Homes share? */
759 if ((HomeExpo == 0) && (have_home != -1)) {
760 lp_remove_service(have_home);
764 commit_parameters(GLOBAL_SECTION_SNUM);
769 /* Now determine smb.conf WINS settings */
770 if (lp_wins_support())
772 if (lp_wins_server_list() && strlen(*lp_wins_server_list()))
775 /* Do we have a homes share? */
776 have_home = lp_servicenumber(HOMES_NAME);
778 if ((winstype == 2) && lp_wins_support())
781 role = lp_server_role();
784 printf("<H2>%s</H2>\n", _("Samba Configuration Wizard"));
785 printf("<form method=post action=wizard>\n");
787 if (have_write_access) {
788 printf("%s\n", _("The \"Rewrite smb.conf file\" button will clear the smb.conf file of all default values and of comments."));
789 printf("%s", _("The same will happen if you press the commit button."));
790 printf("<br><br>\n");
792 printf("<input type=submit name=\"Rewrite\" value=\"%s\"> ",_("Rewrite smb.conf file"));
793 printf("<input type=submit name=\"Commit\" value=\"%s\"> ",_("Commit"));
794 printf("<input type=submit name=\"GetWizardParams\" value=\"%s\">", _("Edit Parameter Values"));
795 printf("</center>\n");
799 printf("<center><table border=0>");
800 printf("<tr><td><b>%s: </b></td>\n", _("Server Type"));
801 printf("<td><input type=radio name=\"ServerType\" value=\"0\" %s> %s </td>", ((role == ROLE_STANDALONE) ? "checked" : ""), _("Stand Alone"));
802 printf("<td><input type=radio name=\"ServerType\" value=\"1\" %s> %s </td>", ((role == ROLE_DOMAIN_MEMBER) ? "checked" : ""), _("Domain Member"));
803 printf("<td><input type=radio name=\"ServerType\" value=\"2\" %s> %s </td>", ((role == ROLE_DOMAIN_PDC) ? "checked" : ""), _("Domain Controller"));
805 if (role == ROLE_DOMAIN_BDC) {
806 printf("<tr><td></td><td colspan=3><font color=\"#ff0000\">%s</font></td></tr>\n", _("Unusual Type in smb.conf - Please Select New Mode"));
808 printf("<tr><td><b>%s: </b></td>\n", _("Configure WINS As"));
809 printf("<td><input type=radio name=\"WINSType\" value=\"0\" %s> %s </td>", ((winstype == 0) ? "checked" : ""), _("Not Used"));
810 printf("<td><input type=radio name=\"WINSType\" value=\"1\" %s> %s </td>", ((winstype == 1) ? "checked" : ""), _("Server for client use"));
811 printf("<td><input type=radio name=\"WINSType\" value=\"2\" %s> %s </td>", ((winstype == 2) ? "checked" : ""), _("Client of another WINS server"));
813 printf("<tr><td></td><td></td><td></td><td>%s <input type=text size=\"16\" name=\"WINSAddr\" value=\"", _("Remote WINS Server"));
815 /* Print out the list of wins servers */
816 if(lp_wins_server_list()) {
818 const char **wins_servers = lp_wins_server_list();
819 for(i = 0; wins_servers[i]; i++) printf("%s ", wins_servers[i]);
822 printf("\"></td></tr>\n");
824 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"));
825 printf("<tr><td></td><td colspan=3><font color=\"#ff0000\">%s</font></td></tr>\n", _("Please Select desired WINS mode above."));
827 printf("<tr><td><b>%s: </b></td>\n", _("Expose Home Directories"));
828 printf("<td><input type=radio name=\"HomeExpo\" value=\"1\" %s> Yes</td>", (have_home == -1) ? "" : "checked ");
829 printf("<td><input type=radio name=\"HomeExpo\" value=\"0\" %s> No</td>", (have_home == -1 ) ? "checked" : "");
830 printf("<td></td></tr>\n");
832 /* Enable this when we are ready ....
833 * printf("<tr><td><b>%s: </b></td>\n", _("Is Print Server"));
834 * printf("<td><input type=radio name=\"PtrSvr\" value=\"1\" %s> Yes</td>");
835 * printf("<td><input type=radio name=\"PtrSvr\" value=\"0\" %s> No</td>");
836 * printf("<td></td></tr>\n");
839 printf("</table></center>");
842 printf("%s\n", _("The above configuration options will set multiple parameters and will generally assist with rapid Samba deployment."));
847 /****************************************************************************
848 display a globals editing page
849 ****************************************************************************/
850 static void globals_page(void)
852 unsigned int parm_filter = FLAG_BASIC;
855 printf("<H2>%s</H2>\n", _("Global Parameters"));
857 if (cgi_variable("Commit")) {
858 commit_parameters(GLOBAL_SECTION_SNUM);
862 if ( cgi_variable("ViewMode") )
863 mode = atoi(cgi_variable_nonull("ViewMode"));
864 if ( cgi_variable("BasicMode"))
866 if ( cgi_variable("AdvMode"))
869 printf("<form name=\"swatform\" method=post action=globals>\n");
871 ViewModeBoxes( mode );
874 parm_filter = FLAG_BASIC;
877 parm_filter = FLAG_ADVANCED;
881 if (have_write_access) {
882 printf("<input type=submit name=\"Commit\" value=\"%s\">\n",
883 _("Commit Changes"));
886 printf("<input type=reset name=\"Reset Values\" value=\"%s\">\n",
891 show_parameters(GLOBAL_SECTION_SNUM, 1, parm_filter, 0);
892 printf("</table>\n");
896 /****************************************************************************
897 display a shares editing page. share is in unix codepage,
898 ****************************************************************************/
899 static void shares_page(void)
901 const char *share = cgi_variable("share");
907 unsigned int parm_filter = FLAG_BASIC;
908 size_t converted_size;
911 snum = lp_servicenumber(share);
913 printf("<H2>%s</H2>\n", _("Share Parameters"));
915 if (cgi_variable("Commit") && snum >= 0) {
916 commit_parameters(snum);
918 snum = lp_servicenumber(share);
921 if (cgi_variable("Delete") && snum >= 0) {
922 lp_remove_service(snum);
928 if (cgi_variable("createshare") && (share=cgi_variable("newshare"))) {
929 snum = lp_servicenumber(share);
932 lp_copy_service(GLOBAL_SECTION_SNUM, share);
933 snum = lp_servicenumber(share);
935 snum = lp_servicenumber(share);
939 printf("<FORM name=\"swatform\" method=post>\n");
943 if ( cgi_variable("ViewMode") )
944 mode = atoi(cgi_variable_nonull("ViewMode"));
945 if ( cgi_variable("BasicMode"))
947 if ( cgi_variable("AdvMode"))
950 ViewModeBoxes( mode );
953 parm_filter = FLAG_BASIC;
956 parm_filter = FLAG_ADVANCED;
959 printf("<br><tr>\n");
960 printf("<td><input type=submit name=selectshare value=\"%s\"></td>\n", _("Choose Share"));
961 printf("<td><select name=share>\n");
963 printf("<option value=\" \"> \n");
964 for (i=0;i<lp_numservices();i++) {
965 s = lp_servicename(i);
966 if (s && (*s) && strcmp(s,"IPC$") && !lp_print_ok(i)) {
967 push_utf8_talloc(talloc_tos(), &utf8_s, s, &converted_size);
968 printf("<option %s value=\"%s\">%s\n",
969 (share && strcmp(share,s)==0)?"SELECTED":"",
974 printf("</select></td>\n");
975 if (have_write_access) {
976 printf("<td><input type=submit name=\"Delete\" value=\"%s\"></td>\n", _("Delete Share"));
981 if (have_write_access) {
983 printf("<td><input type=submit name=createshare value=\"%s\"></td>\n", _("Create Share"));
984 printf("<td><input type=text size=30 name=newshare></td></tr>\n");
990 if (have_write_access) {
991 printf("<input type=submit name=\"Commit\" value=\"%s\">\n", _("Commit Changes"));
994 printf("<input type=reset name=\"Reset Values\" value=\"%s\">\n", _("Reset Values"));
1000 show_parameters(snum, 1, parm_filter, 0);
1001 printf("</table>\n");
1004 printf("</FORM>\n");
1007 /*************************************************************
1008 change a password either locally or remotely
1009 *************************************************************/
1010 static bool change_password(const char *remote_machine, const char *user_name,
1011 const char *old_passwd, const char *new_passwd,
1015 char *err_str = NULL;
1016 char *msg_str = NULL;
1019 printf("%s\n<p>", _("password change in demo mode rejected"));
1023 if (remote_machine != NULL) {
1024 ret = remote_password_change(remote_machine, user_name,
1025 old_passwd, new_passwd, &err_str);
1026 if (err_str != NULL)
1027 printf("%s\n<p>", err_str);
1029 return NT_STATUS_IS_OK(ret);
1032 if(!initialize_password_db(True, NULL)) {
1033 printf("%s\n<p>", _("Can't setup password database vectors."));
1037 ret = local_password_change(user_name, local_flags, new_passwd,
1038 &err_str, &msg_str);
1041 printf("%s\n<p>", msg_str);
1043 printf("%s\n<p>", err_str);
1047 return NT_STATUS_IS_OK(ret);
1050 /****************************************************************************
1051 do the stuff required to add or change a password
1052 ****************************************************************************/
1053 static void chg_passwd(void)
1057 int local_flags = 0;
1059 /* Make sure users name has been specified */
1060 if (strlen(cgi_variable_nonull(SWAT_USER)) == 0) {
1061 printf("<p>%s\n", _(" Must specify \"User Name\" "));
1066 * smbpasswd doesn't require anything but the users name to delete, disable or enable the user,
1067 * so if that's what we're doing, skip the rest of the checks
1069 if (!cgi_variable(DISABLE_USER_FLAG) && !cgi_variable(ENABLE_USER_FLAG) && !cgi_variable(DELETE_USER_FLAG)) {
1072 * If current user is not root, make sure old password has been specified
1073 * If REMOTE change, even root must provide old password
1075 if (((!am_root()) && (strlen( cgi_variable_nonull(OLD_PSWD)) <= 0)) ||
1076 ((cgi_variable(CHG_R_PASSWD_FLAG)) && (strlen( cgi_variable_nonull(OLD_PSWD)) <= 0))) {
1077 printf("<p>%s\n", _(" Must specify \"Old Password\" "));
1081 /* If changing a users password on a remote hosts we have to know what host */
1082 if ((cgi_variable(CHG_R_PASSWD_FLAG)) && (strlen( cgi_variable_nonull(RHOST)) <= 0)) {
1083 printf("<p>%s\n", _(" Must specify \"Remote Machine\" "));
1087 /* Make sure new passwords have been specified */
1088 if ((strlen( cgi_variable_nonull(NEW_PSWD)) <= 0) ||
1089 (strlen( cgi_variable_nonull(NEW2_PSWD)) <= 0)) {
1090 printf("<p>%s\n", _(" Must specify \"New, and Re-typed Passwords\" "));
1094 /* Make sure new passwords was typed correctly twice */
1095 if (strcmp(cgi_variable_nonull(NEW_PSWD), cgi_variable_nonull(NEW2_PSWD)) != 0) {
1096 printf("<p>%s\n", _(" Re-typed password didn't match new password "));
1101 if (cgi_variable(CHG_R_PASSWD_FLAG)) {
1102 host = cgi_variable(RHOST);
1103 } else if (am_root()) {
1110 * Set up the local flags.
1113 local_flags |= (cgi_variable(ADD_USER_FLAG) ? LOCAL_ADD_USER : 0);
1114 local_flags |= (cgi_variable(ADD_USER_FLAG) ? LOCAL_SET_PASSWORD : 0);
1115 local_flags |= (cgi_variable(CHG_S_PASSWD_FLAG) ? LOCAL_SET_PASSWORD : 0);
1116 local_flags |= (cgi_variable(DELETE_USER_FLAG) ? LOCAL_DELETE_USER : 0);
1117 local_flags |= (cgi_variable(ENABLE_USER_FLAG) ? LOCAL_ENABLE_USER : 0);
1118 local_flags |= (cgi_variable(DISABLE_USER_FLAG) ? LOCAL_DISABLE_USER : 0);
1120 rslt = change_password(host,
1121 cgi_variable_nonull(SWAT_USER),
1122 cgi_variable_nonull(OLD_PSWD), cgi_variable_nonull(NEW_PSWD),
1125 if(cgi_variable(CHG_S_PASSWD_FLAG)) {
1128 printf(_(" The passwd for '%s' has been changed."), cgi_variable_nonull(SWAT_USER));
1131 printf(_(" The passwd for '%s' has NOT been changed."), cgi_variable_nonull(SWAT_USER));
1139 /****************************************************************************
1140 display a password editing page
1141 ****************************************************************************/
1142 static void passwd_page(void)
1144 const char *new_name = cgi_user_name();
1147 * After the first time through here be nice. If the user
1148 * changed the User box text to another users name, remember it.
1150 if (cgi_variable(SWAT_USER)) {
1151 new_name = cgi_variable_nonull(SWAT_USER);
1154 if (!new_name) new_name = "";
1156 printf("<H2>%s</H2>\n", _("Server Password Management"));
1158 printf("<FORM name=\"swatform\" method=post>\n");
1160 printf("<table>\n");
1163 * Create all the dialog boxes for data collection
1165 printf("<tr><td> %s : </td>\n", _("User Name"));
1166 printf("<td><input type=text size=30 name=%s value=%s></td></tr> \n", SWAT_USER, new_name);
1168 printf("<tr><td> %s : </td>\n", _("Old Password"));
1169 printf("<td><input type=password size=30 name=%s></td></tr> \n",OLD_PSWD);
1171 printf("<tr><td> %s : </td>\n", _("New Password"));
1172 printf("<td><input type=password size=30 name=%s></td></tr>\n",NEW_PSWD);
1173 printf("<tr><td> %s : </td>\n", _("Re-type New Password"));
1174 printf("<td><input type=password size=30 name=%s></td></tr>\n",NEW2_PSWD);
1175 printf("</table>\n");
1178 * Create all the control buttons for requesting action
1180 printf("<input type=submit name=%s value=\"%s\">\n",
1181 CHG_S_PASSWD_FLAG, _("Change Password"));
1182 if (demo_mode || am_root()) {
1183 printf("<input type=submit name=%s value=\"%s\">\n",
1184 ADD_USER_FLAG, _("Add New User"));
1185 printf("<input type=submit name=%s value=\"%s\">\n",
1186 DELETE_USER_FLAG, _("Delete User"));
1187 printf("<input type=submit name=%s value=\"%s\">\n",
1188 DISABLE_USER_FLAG, _("Disable User"));
1189 printf("<input type=submit name=%s value=\"%s\">\n",
1190 ENABLE_USER_FLAG, _("Enable User"));
1192 printf("<p></FORM>\n");
1195 * Do some work if change, add, disable or enable was
1196 * requested. It could be this is the first time through this
1197 * code, so there isn't anything to do. */
1198 if ((cgi_variable(CHG_S_PASSWD_FLAG)) || (cgi_variable(ADD_USER_FLAG)) || (cgi_variable(DELETE_USER_FLAG)) ||
1199 (cgi_variable(DISABLE_USER_FLAG)) || (cgi_variable(ENABLE_USER_FLAG))) {
1203 printf("<H2>%s</H2>\n", _("Client/Server Password Management"));
1205 printf("<FORM name=\"swatform\" method=post>\n");
1207 printf("<table>\n");
1210 * Create all the dialog boxes for data collection
1212 printf("<tr><td> %s : </td>\n", _("User Name"));
1213 printf("<td><input type=text size=30 name=%s value=%s></td></tr>\n",SWAT_USER, new_name);
1214 printf("<tr><td> %s : </td>\n", _("Old Password"));
1215 printf("<td><input type=password size=30 name=%s></td></tr>\n",OLD_PSWD);
1216 printf("<tr><td> %s : </td>\n", _("New Password"));
1217 printf("<td><input type=password size=30 name=%s></td></tr>\n",NEW_PSWD);
1218 printf("<tr><td> %s : </td>\n", _("Re-type New Password"));
1219 printf("<td><input type=password size=30 name=%s></td></tr>\n",NEW2_PSWD);
1220 printf("<tr><td> %s : </td>\n", _("Remote Machine"));
1221 printf("<td><input type=text size=30 name=%s></td></tr>\n",RHOST);
1226 * Create all the control buttons for requesting action
1228 printf("<input type=submit name=%s value=\"%s\">",
1229 CHG_R_PASSWD_FLAG, _("Change Password"));
1231 printf("<p></FORM>\n");
1234 * Do some work if a request has been made to change the
1235 * password somewhere other than the server. It could be this
1236 * is the first time through this code, so there isn't
1237 * anything to do. */
1238 if (cgi_variable(CHG_R_PASSWD_FLAG)) {
1244 /****************************************************************************
1245 display a printers editing page
1246 ****************************************************************************/
1247 static void printers_page(void)
1249 const char *share = cgi_variable("share");
1254 unsigned int parm_filter = FLAG_BASIC;
1257 snum = lp_servicenumber(share);
1259 printf("<H2>%s</H2>\n", _("Printer Parameters"));
1261 printf("<H3>%s</H3>\n", _("Important Note:"));
1262 printf("%s",_("Printer names marked with [*] in the Choose Printer drop-down box "));
1263 printf("%s",_("are autoloaded printers from "));
1264 printf("<A HREF=\"/swat/help/smb.conf.5.html#printcapname\" target=\"docs\">%s</A>\n", _("Printcap Name"));
1265 printf("%s\n", _("Attempting to delete these printers from SWAT will have no effect."));
1267 if (cgi_variable("Commit") && snum >= 0) {
1268 commit_parameters(snum);
1269 if (snum >= iNumNonAutoPrintServices)
1273 snum = lp_servicenumber(share);
1276 if (cgi_variable("Delete") && snum >= 0) {
1277 lp_remove_service(snum);
1283 if (cgi_variable("createshare") && (share=cgi_variable("newshare"))) {
1284 snum = lp_servicenumber(share);
1285 if (snum < 0 || snum >= iNumNonAutoPrintServices) {
1287 lp_copy_service(GLOBAL_SECTION_SNUM, share);
1288 snum = lp_servicenumber(share);
1289 lp_do_parameter(snum, "print ok", "Yes");
1291 snum = lp_servicenumber(share);
1295 printf("<FORM name=\"swatform\" method=post>\n");
1297 if ( cgi_variable("ViewMode") )
1298 mode = atoi(cgi_variable_nonull("ViewMode"));
1299 if ( cgi_variable("BasicMode"))
1301 if ( cgi_variable("AdvMode"))
1304 ViewModeBoxes( mode );
1307 parm_filter = FLAG_BASIC;
1310 parm_filter = FLAG_ADVANCED;
1313 printf("<table>\n");
1314 printf("<tr><td><input type=submit name=\"selectshare\" value=\"%s\"></td>\n", _("Choose Printer"));
1315 printf("<td><select name=\"share\">\n");
1316 if (snum < 0 || !lp_print_ok(snum))
1317 printf("<option value=\" \"> \n");
1318 for (i=0;i<lp_numservices();i++) {
1319 s = lp_servicename(i);
1320 if (s && (*s) && strcmp(s,"IPC$") && lp_print_ok(i)) {
1321 if (i >= iNumNonAutoPrintServices)
1322 printf("<option %s value=\"%s\">[*]%s\n",
1323 (share && strcmp(share,s)==0)?"SELECTED":"",
1326 printf("<option %s value=\"%s\">%s\n",
1327 (share && strcmp(share,s)==0)?"SELECTED":"",
1331 printf("</select></td>");
1332 if (have_write_access) {
1333 printf("<td><input type=submit name=\"Delete\" value=\"%s\"></td>\n", _("Delete Printer"));
1336 printf("</table>\n");
1338 if (have_write_access) {
1339 printf("<table>\n");
1340 printf("<tr><td><input type=submit name=\"createshare\" value=\"%s\"></td>\n", _("Create Printer"));
1341 printf("<td><input type=text size=30 name=\"newshare\"></td></tr>\n");
1347 if (have_write_access) {
1348 printf("<input type=submit name=\"Commit\" value=\"%s\">\n", _("Commit Changes"));
1350 printf("<input type=reset name=\"Reset Values\" value=\"%s\">\n", _("Reset Values"));
1355 printf("<table>\n");
1356 show_parameters(snum, 1, parm_filter, 1);
1357 printf("</table>\n");
1359 printf("</FORM>\n");
1363 when the _() translation macro is used there is no obvious place to free
1364 the resulting string and there is no easy way to give a static pointer.
1365 All we can do is rotate between some static buffers and hope a single d_printf()
1366 doesn't have more calls to _() than the number of buffers
1369 const char *lang_msg_rotate(TALLOC_CTX *ctx, const char *msgid)
1374 msgstr = lang_msg(msgid);
1379 ret = talloc_strdup(ctx, msgstr);
1381 lang_msg_free(msgstr);
1390 * main function for SWAT.
1392 int main(int argc, char *argv[])
1396 struct poptOption long_options[] = {
1398 { "disable-authentication", 'a', POPT_ARG_VAL, &demo_mode, True, "Disable authentication (demo mode)" },
1399 { "password-menu-only", 'P', POPT_ARG_VAL, &passwd_only, True, "Show only change password menu" },
1403 TALLOC_CTX *frame = talloc_stackframe();
1406 umask(S_IWGRP | S_IWOTH);
1408 #if defined(HAVE_SET_AUTH_PARAMETERS)
1409 set_auth_parameters(argc, argv);
1410 #endif /* HAVE_SET_AUTH_PARAMETERS */
1412 /* just in case it goes wild ... */
1417 /* we don't want any SIGPIPE messages */
1418 BlockSignals(True,SIGPIPE);
1420 debug_set_logfile("/dev/null");
1422 /* we don't want stderr screwing us up */
1424 open("/dev/null", O_WRONLY);
1425 setup_logging("swat", DEBUG_FILE);
1429 pc = poptGetContext("swat", argc, (const char **) argv, long_options, 0);
1431 /* Parse command line options */
1433 while(poptGetNextOpt(pc) != -1) { }
1435 poptFreeContext(pc);
1437 /* This should set a more apporiate log file */
1441 iNumNonAutoPrintServices = lp_numservices();
1442 if (pcap_cache_loaded()) {
1443 load_printers(server_event_context(),
1444 server_messaging_context());
1447 cgi_setup(get_dyn_SWATDIR(), !demo_mode);
1451 cgi_load_variables();
1453 if (!file_exist(get_dyn_CONFIGFILE())) {
1454 have_read_access = True;
1455 have_write_access = True;
1457 /* check if the authenticated user has write access - if not then
1458 don't show write options */
1459 have_write_access = (access(get_dyn_CONFIGFILE(),W_OK) == 0);
1461 /* if the user doesn't have read access to smb.conf then
1462 don't let them view it */
1463 have_read_access = (access(get_dyn_CONFIGFILE(),R_OK) == 0);
1466 show_main_buttons();
1468 page = cgi_pathinfo();
1470 /* Root gets full functionality */
1471 if (have_read_access && strcmp(page, "globals")==0) {
1473 } else if (have_read_access && strcmp(page,"shares")==0) {
1475 } else if (have_read_access && strcmp(page,"printers")==0) {
1477 } else if (have_read_access && strcmp(page,"status")==0) {
1479 } else if (have_read_access && strcmp(page,"viewconfig")==0) {
1481 } else if (strcmp(page,"passwd")==0) {
1483 } else if (have_read_access && strcmp(page,"wizard")==0) {
1485 } else if (have_read_access && strcmp(page,"wizard_params")==0) {
1486 wizard_params_page();
1487 } else if (have_read_access && strcmp(page,"rewritecfg")==0) {