2 Unix SMB/Netbios implementation.
4 Samba Web Administration Tool
5 Copyright (C) Andrew Tridgell 1997-1998
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 #define GLOBALS_SNUM -1
31 static pstring servicesf = CONFIGFILE;
32 static BOOL demo_mode = False;
33 static BOOL have_write_access = False;
34 static BOOL have_read_access = False;
35 static int iNumNonAutoPrintServices = 0;
38 * Password Management Globals
40 #define SWAT_USER "username"
41 #define OLD_PSWD "old_passwd"
42 #define NEW_PSWD "new_passwd"
43 #define NEW2_PSWD "new2_passwd"
44 #define CHG_S_PASSWD_FLAG "chg_s_passwd_flag"
45 #define CHG_R_PASSWD_FLAG "chg_r_passwd_flag"
46 #define ADD_USER_FLAG "add_user_flag"
47 #define DELETE_USER_FLAG "delete_user_flag"
48 #define DISABLE_USER_FLAG "disable_user_flag"
49 #define ENABLE_USER_FLAG "enable_user_flag"
50 #define RHOST "remote_host"
52 /* we need these because we link to locking*.o */
53 void become_root(void) {}
54 void unbecome_root(void) {}
56 /****************************************************************************
57 ****************************************************************************/
58 static int enum_index(int value, struct enum_list *enumlist)
61 for (i=0;enumlist[i].name;i++)
62 if (value == enumlist[i].value) break;
66 static char *fix_backslash(char *str)
68 static char newstring[1024];
72 if (*str == '\\') {*p++ = '\\';*p++ = '\\';}
80 static char *stripspace(char *str)
82 static char newstring[1024];
86 if (*str != ' ') *p++ = *str;
93 static char *make_parm_name(char *label)
95 static char parmname[1024];
99 if (*label == ' ') *p++ = '_';
107 /****************************************************************************
108 include a lump of html in a page
109 ****************************************************************************/
110 static int include_html(char *fname)
112 FILE *f = sys_fopen(fname,"r");
117 printf("ERROR: Can't open %s\n", fname);
122 ret = fread(buf, 1, sizeof(buf), f);
124 fwrite(buf, 1, ret, stdout);
131 /****************************************************************************
132 start the page with standard stuff
133 ****************************************************************************/
134 static void print_header(void)
136 if (!cgi_waspost()) {
137 printf("Expires: 0\r\n");
139 printf("Content-type: text/html\r\n\r\n");
141 if (!include_html("include/header.html")) {
142 printf("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n");
143 printf("<HTML>\n<HEAD>\n<TITLE>Samba Web Administration Tool</TITLE>\n</HEAD>\n<BODY background=\"/swat/images/background.jpg\">\n\n");
147 /****************************************************************************
149 ****************************************************************************/
150 static void print_footer(void)
152 if (!include_html("include/footer.html")) {
153 printf("\n</BODY>\n</HTML>\n");
157 /****************************************************************************
158 display one editable parameter in a form
159 ****************************************************************************/
160 static void show_parameter(int snum, struct parm_struct *parm)
163 void *ptr = parm->ptr;
166 if (parm->class == P_LOCAL && snum >= 0) {
167 ptr = lp_local_ptr(snum, ptr);
170 str = stripspace(parm->label);
172 printf("<tr><td><A HREF=\"/swat/help/smb.conf.5.html#%s\" target=\"docs\">Help</A> %s</td><td>",
175 switch (parm->type) {
177 printf("<input type=text size=2 name=\"parm_%s\" value=\"%c\">",
178 make_parm_name(parm->label), *(char *)ptr);
179 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.value=\'%c\'\">",
180 make_parm_name(parm->label),(char)(parm->def.cvalue));
184 printf("<input type=text size=40 name=\"parm_%s\" value=\"",
185 make_parm_name(parm->label));
186 if ((char ***)ptr && *(char ***)ptr && **(char ***)ptr) {
187 char **list = *(char ***)ptr;
188 for (;*list;list++) {
189 printf("%s%s", *list, ((*(list+1))?" ":""));
193 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.value=\'",
194 make_parm_name(parm->label));
195 if (parm->def.lvalue) {
196 char **list = (char **)(parm->def.lvalue);
197 for (; *list; list++) {
198 printf("%s%s", *list, ((*(list+1))?" ":""));
206 printf("<input type=text size=40 name=\"parm_%s\" value=\"%s\">",
207 make_parm_name(parm->label), *(char **)ptr);
208 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.value=\'%s\'\">",
209 make_parm_name(parm->label),fix_backslash((char *)(parm->def.svalue)));
214 printf("<input type=text size=40 name=\"parm_%s\" value=\"%s\">",
215 make_parm_name(parm->label), (char *)ptr);
216 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.value=\'%s\'\">",
217 make_parm_name(parm->label),fix_backslash((char *)(parm->def.svalue)));
221 printf("<select name=\"parm_%s\">",make_parm_name(parm->label));
222 printf("<option %s>Yes", (*(BOOL *)ptr)?"selected":"");
223 printf("<option %s>No", (*(BOOL *)ptr)?"":"selected");
225 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.selectedIndex=\'%d\'\">",
226 make_parm_name(parm->label),(BOOL)(parm->def.bvalue)?0:1);
230 printf("<select name=\"parm_%s\">",make_parm_name(parm->label));
231 printf("<option %s>Yes", (*(BOOL *)ptr)?"":"selected");
232 printf("<option %s>No", (*(BOOL *)ptr)?"selected":"");
234 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.selectedIndex=\'%d\'\">",
235 make_parm_name(parm->label),(BOOL)(parm->def.bvalue)?1:0);
239 printf("<input type=text size=8 name=\"parm_%s\" value=%d>", make_parm_name(parm->label), *(int *)ptr);
240 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.value=\'%d\'\">",
241 make_parm_name(parm->label),(int)(parm->def.ivalue));
245 printf("<input type=text size=8 name=\"parm_%s\" value=%s>", make_parm_name(parm->label), octal_string(*(int *)ptr));
246 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.value=\'%s\'\">",
247 make_parm_name(parm->label),
248 octal_string((int)(parm->def.ivalue)));
252 printf("<select name=\"parm_%s\">",make_parm_name(parm->label));
253 for (i=0;parm->enum_list[i].name;i++) {
254 if (i == 0 || parm->enum_list[i].value != parm->enum_list[i-1].value) {
255 printf("<option %s>%s",(*(int *)ptr)==parm->enum_list[i].value?"selected":"",parm->enum_list[i].name);
259 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.selectedIndex=\'%d\'\">",
260 make_parm_name(parm->label),enum_index((int)(parm->def.ivalue),parm->enum_list));
265 printf("</td></tr>\n");
268 /****************************************************************************
269 display a set of parameters for a service
270 ****************************************************************************/
271 static void show_parameters(int snum, int allparameters, int advanced, int printers)
274 struct parm_struct *parm;
275 char *heading = NULL;
276 char *last_heading = NULL;
278 while ((parm = lp_next_parameter(snum, &i, allparameters))) {
279 if (snum < 0 && parm->class == P_LOCAL && !(parm->flags & FLAG_GLOBAL))
281 if (parm->class == P_SEPARATOR) {
282 heading = parm->label;
285 if (parm->flags & FLAG_HIDE) continue;
287 if (printers & !(parm->flags & FLAG_PRINT)) continue;
288 if (!printers & !(parm->flags & FLAG_SHARE)) continue;
291 if (!(parm->flags & FLAG_BASIC)) {
292 void *ptr = parm->ptr;
294 if (parm->class == P_LOCAL && snum >= 0) {
295 ptr = lp_local_ptr(snum, ptr);
298 switch (parm->type) {
300 if (*(char *)ptr == (char)(parm->def.cvalue)) continue;
304 if (!lp_list_compare(*(char ***)ptr, (char **)(parm->def.lvalue))) continue;
309 if (!strcmp(*(char **)ptr,(char *)(parm->def.svalue))) continue;
314 if (!strcmp((char *)ptr,(char *)(parm->def.svalue))) continue;
319 if (*(BOOL *)ptr == (BOOL)(parm->def.bvalue)) continue;
324 if (*(int *)ptr == (int)(parm->def.ivalue)) continue;
329 if (*(int *)ptr == (int)(parm->def.ivalue)) continue;
335 if (printers && !(parm->flags & FLAG_PRINT)) continue;
337 if (heading && heading != last_heading) {
338 printf("<tr><td></td></tr><tr><td><b><u>%s</u></b></td></tr>\n", heading);
339 last_heading = heading;
341 show_parameter(snum, parm);
345 /****************************************************************************
346 load the smb.conf file into loadparm.
347 ****************************************************************************/
348 static BOOL load_config(BOOL save_def)
350 lp_resetnumservices();
351 return lp_load(servicesf,False,save_def,False);
354 /****************************************************************************
356 ****************************************************************************/
357 static void write_config(FILE *f, BOOL show_defaults)
359 fprintf(f, "# Samba config file created using SWAT\n");
360 fprintf(f, "# from %s (%s)\n", cgi_remote_host(), cgi_remote_addr());
361 fprintf(f, "# Date: %s\n\n", timestring(False));
363 lp_dump(f, show_defaults, iNumNonAutoPrintServices);
366 /****************************************************************************
367 save and reoad the smb.conf config file
368 ****************************************************************************/
369 static int save_reload(int snum)
374 f = sys_fopen(servicesf,"w");
376 printf("failed to open %s for writing\n", servicesf);
380 /* just in case they have used the buggy xinetd to create the file */
381 if (fstat(fileno(f), &st) == 0 &&
382 (st.st_mode & S_IWOTH)) {
383 fchmod(fileno(f), S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH);
386 write_config(f, False);
388 lp_dump_one(f, False, snum);
393 if (!load_config(False)) {
394 printf("Can't reload %s\n", servicesf);
397 iNumNonAutoPrintServices = lp_numservices();
403 /****************************************************************************
405 ****************************************************************************/
406 static void commit_parameter(int snum, struct parm_struct *parm, char *v)
411 if (snum < 0 && parm->class == P_LOCAL) {
412 /* this handles the case where we are changing a local
413 variable globally. We need to change the parameter in
414 all shares where it is currently set to the default */
415 for (i=0;i<lp_numservices();i++) {
416 s = lp_servicename(i);
417 if (s && (*s) && lp_is_default(i, parm)) {
418 lp_do_parameter(i, parm->label, v);
423 lp_do_parameter(snum, parm->label, v);
426 /****************************************************************************
427 commit a set of parameters for a service
428 ****************************************************************************/
429 static void commit_parameters(int snum)
432 struct parm_struct *parm;
436 while ((parm = lp_next_parameter(snum, &i, 1))) {
437 slprintf(label, sizeof(label)-1, "parm_%s", make_parm_name(parm->label));
438 if ((v = cgi_variable(label))) {
439 if (parm->flags & FLAG_HIDE) continue;
440 commit_parameter(snum, parm, v);
445 /****************************************************************************
446 spit out the html for a link with an image
447 ****************************************************************************/
448 static void image_link(char *name,char *hlink, char *src)
450 printf("<A HREF=\"%s/%s\"><img border=\"0\" src=\"/swat/%s\" alt=\"%s\"></A>\n",
451 cgi_baseurl(), hlink, src, name);
454 /****************************************************************************
455 display the main navigation controls at the top of each page along
457 ****************************************************************************/
458 static void show_main_buttons(void)
462 if ((p = cgi_user_name()) && strcmp(p, "root")) {
463 printf("Logged in as <b>%s</b><p>\n", p);
466 image_link("Home", "", "images/home.gif");
467 if (have_write_access) {
468 image_link("Globals", "globals", "images/globals.gif");
469 image_link("Shares", "shares", "images/shares.gif");
470 image_link("Printers", "printers", "images/printers.gif");
472 if (have_read_access) {
473 image_link("Status", "status", "images/status.gif");
474 image_link("View Config", "viewconfig","images/viewconfig.gif");
476 image_link("Password Management", "passwd", "images/passwd.gif");
481 /****************************************************************************
482 display a welcome page
483 ****************************************************************************/
484 static void welcome_page(void)
486 include_html("help/welcome.html");
489 /****************************************************************************
490 display the current smb.conf
491 ****************************************************************************/
492 static void viewconfig_page(void)
496 if (cgi_variable("full_view")) {
500 printf("<H2>Current Config</H2>\n");
501 printf("<form method=post>\n");
504 printf("<input type=submit name=\"normal_view\" value=\"Normal View\">\n");
506 printf("<input type=submit name=\"full_view\" value=\"Full View\">\n");
510 write_config(stdout, full_view);
515 /****************************************************************************
516 display a globals editing page
517 ****************************************************************************/
518 static void globals_page(void)
522 printf("<H2>Global Variables</H2>\n");
524 if (cgi_variable("Advanced") && !cgi_variable("Basic"))
527 if (cgi_variable("Commit")) {
528 commit_parameters(GLOBALS_SNUM);
532 printf("<FORM name=\"swatform\" method=post>\n");
534 if (have_write_access) {
535 printf("<input type=submit name=\"Commit\" value=\"Commit Changes\">\n");
538 printf("<input type=reset name=\"Reset Values\" value=\"Reset Values\">\n");
540 printf("<input type=submit name=\"Advanced\" value=\"Advanced View\">\n");
542 printf("<input type=submit name=\"Basic\" value=\"Basic View\">\n");
547 show_parameters(GLOBALS_SNUM, 1, advanced, 0);
548 printf("</table>\n");
551 printf("<input type=hidden name=\"Advanced\" value=1>\n");
557 /****************************************************************************
558 display a shares editing page. share is in unix codepage, and must be in
559 dos codepage. FIXME !!! JRA.
560 ****************************************************************************/
561 static void shares_page(void)
563 char *share = cgi_variable("share");
570 snum = lp_servicenumber(share);
572 printf("<H2>Share Parameters</H2>\n");
574 if (cgi_variable("Advanced") && !cgi_variable("Basic"))
577 if (cgi_variable("Commit") && snum >= 0) {
578 commit_parameters(snum);
582 if (cgi_variable("Delete") && snum >= 0) {
583 lp_remove_service(snum);
589 if (cgi_variable("createshare") && (share=cgi_variable("newshare"))) {
591 lp_copy_service(GLOBALS_SNUM, share);
592 iNumNonAutoPrintServices = lp_numservices();
594 snum = lp_servicenumber(share);
597 printf("<FORM name=\"swatform\" method=post>\n");
601 printf("<td><input type=submit name=selectshare value=\"Choose Share\"></td>\n");
602 printf("<td><select name=share>\n");
604 printf("<option value=\" \"> \n");
605 for (i=0;i<lp_numservices();i++) {
606 s = lp_servicename(i);
607 if (s && (*s) && strcmp(s,"IPC$") && !lp_print_ok(i)) {
608 printf("<option %s value=\"%s\">%s\n",
609 (share && strcmp(share,s)==0)?"SELECTED":"",
613 printf("</select></td>\n");
614 if (have_write_access) {
615 printf("<td><input type=submit name=\"Delete\" value=\"Delete Share\"></td>\n");
620 if (have_write_access) {
622 printf("<td><input type=submit name=createshare value=\"Create Share\"></td>\n");
623 printf("<td><input type=text size=30 name=newshare></td></tr>\n");
629 if (have_write_access) {
630 printf("<input type=submit name=\"Commit\" value=\"Commit Changes\">\n");
633 printf("<input type=reset name=\"Reset Values\" value=\"Reset Values\">\n");
635 printf("<input type=submit name=\"Advanced\" value=\"Advanced View\">\n");
637 printf("<input type=submit name=\"Basic\" value=\"Basic View\">\n");
644 show_parameters(snum, 1, advanced, 0);
645 printf("</table>\n");
649 printf("<input type=hidden name=\"Advanced\" value=1>\n");
655 /*************************************************************
656 change a password either locally or remotely
657 *************************************************************/
658 static BOOL change_password(const char *remote_machine, char *user_name,
659 char *old_passwd, char *new_passwd,
667 printf("password change in demo mode rejected\n<p>");
671 if (remote_machine != NULL) {
672 ret = remote_password_change(remote_machine, user_name, old_passwd,
673 new_passwd, err_str, sizeof(err_str));
675 printf("%s\n<p>", err_str);
679 if(!initialize_password_db(True)) {
680 printf("Can't setup password database vectors.\n<p>");
684 ret = local_password_change(user_name, local_flags, new_passwd, err_str, sizeof(err_str),
685 msg_str, sizeof(msg_str));
688 printf("%s\n<p>", msg_str);
690 printf("%s\n<p>", err_str);
695 /****************************************************************************
696 do the stuff required to add or change a password
697 ****************************************************************************/
698 static void chg_passwd(void)
704 /* Make sure users name has been specified */
705 if (strlen(cgi_variable(SWAT_USER)) == 0) {
706 printf("<p> Must specify \"User Name\" \n");
711 * smbpasswd doesn't require anything but the users name to delete, disable or enable the user,
712 * so if that's what we're doing, skip the rest of the checks
714 if (!cgi_variable(DISABLE_USER_FLAG) && !cgi_variable(ENABLE_USER_FLAG) && !cgi_variable(DELETE_USER_FLAG)) {
717 * If current user is not root, make sure old password has been specified
718 * If REMOTE change, even root must provide old password
720 if (((!am_root()) && (strlen( cgi_variable(OLD_PSWD)) <= 0)) ||
721 ((cgi_variable(CHG_R_PASSWD_FLAG)) && (strlen( cgi_variable(OLD_PSWD)) <= 0))) {
722 printf("<p> Must specify \"Old Password\" \n");
726 /* If changing a users password on a remote hosts we have to know what host */
727 if ((cgi_variable(CHG_R_PASSWD_FLAG)) && (strlen( cgi_variable(RHOST)) <= 0)) {
728 printf("<p> Must specify \"Remote Machine\" \n");
732 /* Make sure new passwords have been specified */
733 if ((strlen( cgi_variable(NEW_PSWD)) <= 0) ||
734 (strlen( cgi_variable(NEW2_PSWD)) <= 0)) {
735 printf("<p> Must specify \"New, and Re-typed Passwords\" \n");
739 /* Make sure new passwords was typed correctly twice */
740 if (strcmp(cgi_variable(NEW_PSWD), cgi_variable(NEW2_PSWD)) != 0) {
741 printf("<p> Re-typed password didn't match new password\n");
746 if (cgi_variable(CHG_R_PASSWD_FLAG)) {
747 host = cgi_variable(RHOST);
748 } else if (am_root()) {
755 * Set up the local flags.
758 local_flags |= (cgi_variable(ADD_USER_FLAG) ? LOCAL_ADD_USER : 0);
759 local_flags |= (cgi_variable(DELETE_USER_FLAG) ? LOCAL_DELETE_USER : 0);
760 local_flags |= (cgi_variable(ENABLE_USER_FLAG) ? LOCAL_ENABLE_USER : 0);
761 local_flags |= (cgi_variable(DISABLE_USER_FLAG) ? LOCAL_DISABLE_USER : 0);
763 rslt = change_password(host,
764 cgi_variable(SWAT_USER),
765 cgi_variable(OLD_PSWD), cgi_variable(NEW_PSWD),
768 if(local_flags == 0) {
770 printf("<p> The passwd for '%s' has been changed. \n", cgi_variable(SWAT_USER));
772 printf("<p> The passwd for '%s' has NOT been changed. \n",cgi_variable(SWAT_USER));
779 /****************************************************************************
780 display a password editing page
781 ****************************************************************************/
782 static void passwd_page(void)
784 char *new_name = cgi_user_name();
787 * After the first time through here be nice. If the user
788 * changed the User box text to another users name, remember it.
790 if (cgi_variable(SWAT_USER)) {
791 new_name = cgi_variable(SWAT_USER);
794 if (!new_name) new_name = "";
796 printf("<H2>Server Password Management</H2>\n");
798 printf("<FORM name=\"swatform\" method=post>\n");
803 * Create all the dialog boxes for data collection
805 printf("<tr><td> User Name : </td>\n");
806 printf("<td><input type=text size=30 name=%s value=%s></td></tr> \n", SWAT_USER, new_name);
808 printf("<tr><td> Old Password : </td>\n");
809 printf("<td><input type=password size=30 name=%s></td></tr> \n",OLD_PSWD);
811 printf("<tr><td> New Password : </td>\n");
812 printf("<td><input type=password size=30 name=%s></td></tr>\n",NEW_PSWD);
813 printf("<tr><td> Re-type New Password : </td>\n");
814 printf("<td><input type=password size=30 name=%s></td></tr>\n",NEW2_PSWD);
815 printf("</table>\n");
818 * Create all the control buttons for requesting action
820 printf("<input type=submit name=%s value=\"Change Password\">\n",
822 if (demo_mode || am_root()) {
823 printf("<input type=submit name=%s value=\"Add New User\">\n",
825 printf("<input type=submit name=%s value=\"Delete User\">\n",
827 printf("<input type=submit name=%s value=\"Disable User\">\n",
829 printf("<input type=submit name=%s value=\"Enable User\">\n",
832 printf("<p></FORM>\n");
835 * Do some work if change, add, disable or enable was
836 * requested. It could be this is the first time through this
837 * code, so there isn't anything to do. */
838 if ((cgi_variable(CHG_S_PASSWD_FLAG)) || (cgi_variable(ADD_USER_FLAG)) || (cgi_variable(DELETE_USER_FLAG)) ||
839 (cgi_variable(DISABLE_USER_FLAG)) || (cgi_variable(ENABLE_USER_FLAG))) {
843 printf("<H2>Client/Server Password Management</H2>\n");
845 printf("<FORM name=\"swatform\" method=post>\n");
850 * Create all the dialog boxes for data collection
852 printf("<tr><td> User Name : </td>\n");
853 printf("<td><input type=text size=30 name=%s value=%s></td></tr>\n",SWAT_USER, new_name);
854 printf("<tr><td> Old Password : </td>\n");
855 printf("<td><input type=password size=30 name=%s></td></tr>\n",OLD_PSWD);
856 printf("<tr><td> New Password : </td>\n");
857 printf("<td><input type=password size=30 name=%s></td></tr>\n",NEW_PSWD);
858 printf("<tr><td> Re-type New Password : </td>\n");
859 printf("<td><input type=password size=30 name=%s></td></tr>\n",NEW2_PSWD);
860 printf("<tr><td> Remote Machine : </td>\n");
861 printf("<td><input type=text size=30 name=%s></td></tr>\n",RHOST);
866 * Create all the control buttons for requesting action
868 printf("<input type=submit name=%s value=\"Change Password\">",
871 printf("<p></FORM>\n");
874 * Do some work if a request has been made to change the
875 * password somewhere other than the server. It could be this
876 * is the first time through this code, so there isn't
878 if (cgi_variable(CHG_R_PASSWD_FLAG)) {
884 /****************************************************************************
885 display a printers editing page
886 ****************************************************************************/
887 static void printers_page(void)
889 char *share = cgi_variable("share");
896 snum = lp_servicenumber(share);
898 printf("<H2>Printer Parameters</H2>\n");
900 printf("<H3>Important Note:</H3>\n");
901 printf("Printer names marked with [*] in the Choose Printer drop-down box ");
902 printf("are autoloaded printers from ");
903 printf("<A HREF=\"/swat/help/smb.conf.5.html#PRINTCAPNAME\" target=\"docs\">Printcap Name</A>.\n");
904 printf("Attempting to delete these printers from SWAT will have no effect.\n");
906 if (cgi_variable("Advanced") && !cgi_variable("Basic"))
909 if (cgi_variable("Commit") && snum >= 0) {
910 commit_parameters(snum);
911 if (snum >= iNumNonAutoPrintServices)
917 if (cgi_variable("Delete") && snum >= 0) {
918 lp_remove_service(snum);
924 if (cgi_variable("createshare") && (share=cgi_variable("newshare"))) {
926 lp_copy_service(GLOBALS_SNUM, share);
927 iNumNonAutoPrintServices = lp_numservices();
928 snum = lp_servicenumber(share);
929 lp_do_parameter(snum, "print ok", "Yes");
931 snum = lp_servicenumber(share);
934 printf("<FORM name=\"swatform\" method=post>\n");
937 printf("<tr><td><input type=submit name=selectshare value=\"Choose Printer\"></td>\n");
938 printf("<td><select name=share>\n");
939 if (snum < 0 || !lp_print_ok(snum))
940 printf("<option value=\" \"> \n");
941 for (i=0;i<lp_numservices();i++) {
942 s = lp_servicename(i);
943 if (s && (*s) && strcmp(s,"IPC$") && lp_print_ok(i)) {
944 if (i >= iNumNonAutoPrintServices)
945 printf("<option %s value=\"%s\">[*]%s\n",
946 (share && strcmp(share,s)==0)?"SELECTED":"",
949 printf("<option %s value=\"%s\">%s\n",
950 (share && strcmp(share,s)==0)?"SELECTED":"",
954 printf("</select></td>");
955 if (have_write_access) {
956 printf("<td><input type=submit name=\"Delete\" value=\"Delete Printer\"></td>\n");
959 printf("</table>\n");
961 if (have_write_access) {
963 printf("<tr><td><input type=submit name=createshare value=\"Create Printer\"></td>\n");
964 printf("<td><input type=text size=30 name=newshare></td></tr>\n");
970 if (have_write_access) {
971 printf("<input type=submit name=\"Commit\" value=\"Commit Changes\">\n");
973 printf("<input type=reset name=\"Reset Values\" value=\"Reset Values\">\n");
975 printf("<input type=submit name=\"Advanced\" value=\"Advanced View\">\n");
977 printf("<input type=submit name=\"Basic\" value=\"Basic View\">\n");
984 show_parameters(snum, 1, advanced, 1);
985 printf("</table>\n");
989 printf("<input type=hidden name=\"Advanced\" value=1>\n");
995 /****************************************************************************
997 ****************************************************************************/
998 int main(int argc, char *argv[])
1000 extern char *optarg;
1007 umask(S_IWGRP | S_IWOTH);
1009 #if defined(HAVE_SET_AUTH_PARAMETERS)
1010 set_auth_parameters(argc, argv);
1011 #endif /* HAVE_SET_AUTH_PARAMETERS */
1013 /* just in case it goes wild ... */
1016 /* we don't want any SIGPIPE messages */
1017 BlockSignals(True,SIGPIPE);
1019 dbf = sys_fopen("/dev/null", "w");
1020 if (!dbf) dbf = stderr;
1022 /* we don't want stderr screwing us up */
1024 open("/dev/null", O_WRONLY);
1026 while ((opt = getopt(argc, argv,"s:a")) != EOF) {
1029 pstrcpy(servicesf,optarg);
1037 setup_logging(argv[0],False);
1039 iNumNonAutoPrintServices = lp_numservices();
1042 cgi_setup(SWATDIR, !demo_mode);
1046 cgi_load_variables(NULL);
1048 if (!file_exist(servicesf, NULL)) {
1049 have_read_access = True;
1050 have_write_access = True;
1052 /* check if the authenticated user has write access - if not then
1053 don't show write options */
1054 have_write_access = (access(servicesf,W_OK) == 0);
1056 /* if the user doesn't have read access to smb.conf then
1057 don't let them view it */
1058 have_read_access = (access(servicesf,R_OK) == 0);
1062 show_main_buttons();
1064 page = cgi_pathinfo();
1066 /* Root gets full functionality */
1067 if (have_read_access && strcmp(page, "globals")==0) {
1069 } else if (have_read_access && strcmp(page,"shares")==0) {
1071 } else if (have_read_access && strcmp(page,"printers")==0) {
1073 } else if (have_read_access && strcmp(page,"status")==0) {
1075 } else if (have_read_access && strcmp(page,"viewconfig")==0) {
1077 } else if (strcmp(page,"passwd")==0) {