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;
34 * Password Management Globals
36 char user[] = "username";
37 char old_pswd[] = "old_passwd";
38 char new_pswd[] = "new_passwd";
39 char new2_pswd[] = "new2_passwd";
40 char chg_passwd_flag[] = "chg_passwd_flag";
41 char add_user_flag[] = "add_user_flag";
42 char disable_user_flag[] = "disable_user_flag";
43 char enable_user_flag[] = "enable_user_flag";
45 /* we need these because we link to locking*.o */
46 void become_root(BOOL save_dir) {}
47 void unbecome_root(BOOL restore_dir) {}
48 /* We need this because we link to password.o */
49 BOOL change_oem_password(struct smb_passwd *smbpw, char *new_passwd, BOOL override) {return False;}
51 /****************************************************************************
52 ****************************************************************************/
53 static int enum_index(int value, struct enum_list *enumlist)
56 for (i=0;enumlist[i].name;i++)
57 if (value == enumlist[i].value) break;
61 static char *fix_backslash(char *str)
63 static char newstring[1024];
67 if (*str == '\\') {*p++ = '\\';*p++ = '\\';}
75 static char *stripspace(char *str)
77 static char newstring[1024];
81 if (*str != ' ') *p++ = *str;
88 static char *make_parm_name(char *label)
90 static char parmname[1024];
94 if (*label == ' ') *p++ = '_';
102 /****************************************************************************
103 include a lump of html in a page
104 ****************************************************************************/
105 static int include_html(char *fname)
107 FILE *f = fopen(fname,"r");
112 printf("ERROR: Can't open %s\n", fname);
117 ret = fread(buf, 1, sizeof(buf), f);
119 fwrite(buf, 1, ret, stdout);
126 /****************************************************************************
127 start the page with standard stuff
128 ****************************************************************************/
129 static void print_header(void)
131 if (!cgi_waspost()) {
132 printf("Expires: 0\r\n");
134 printf("Content-type: text/html\r\n\r\n");
136 if (!include_html("include/header.html")) {
137 printf("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n");
138 printf("<HTML>\n<HEAD>\n<TITLE>Samba Web Administration Tool</TITLE>\n</HEAD>\n<BODY background=\"/swat/images/background.jpg\">\n\n");
142 /****************************************************************************
144 ****************************************************************************/
145 static void print_footer(void)
147 if (!include_html("include/footer.html")) {
148 printf("\n</BODY>\n</HTML>\n");
152 /****************************************************************************
153 display one editable parameter in a form
154 ****************************************************************************/
155 static void show_parameter(int snum, struct parm_struct *parm)
158 void *ptr = parm->ptr;
160 if (parm->class == P_LOCAL && snum >= 0) {
161 ptr = lp_local_ptr(snum, ptr);
164 printf("<tr><td><A HREF=\"/swat/help/smb.conf.5.html#%s\">?</A> %s</td><td>",
165 stripspace(parm->label), parm->label);
167 switch (parm->type) {
169 printf("<input type=text size=2 name=\"parm_%s\" value=\"%c\">",
170 make_parm_name(parm->label), *(char *)ptr);
171 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.value=\'%c\'\">",
172 make_parm_name(parm->label),(char)(parm->def.cvalue));
177 printf("<input type=text size=40 name=\"parm_%s\" value=\"%s\">",
178 make_parm_name(parm->label), *(char **)ptr);
179 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.value=\'%s\'\">",
180 make_parm_name(parm->label),fix_backslash((char *)(parm->def.svalue)));
185 printf("<input type=text size=40 name=\"parm_%s\" value=\"%s\">",
186 make_parm_name(parm->label), (char *)ptr);
187 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.value=\'%s\'\">",
188 make_parm_name(parm->label),fix_backslash((char *)(parm->def.svalue)));
192 printf("<select name=\"parm_%s\">",make_parm_name(parm->label));
193 printf("<option %s>Yes", (*(BOOL *)ptr)?"selected":"");
194 printf("<option %s>No", (*(BOOL *)ptr)?"":"selected");
196 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.selectedIndex=\'%d\'\">",
197 make_parm_name(parm->label),(BOOL)(parm->def.bvalue)?0:1);
201 printf("<select name=\"parm_%s\">",make_parm_name(parm->label));
202 printf("<option %s>Yes", (*(BOOL *)ptr)?"":"selected");
203 printf("<option %s>No", (*(BOOL *)ptr)?"selected":"");
205 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.selectedIndex=\'%d\'\">",
206 make_parm_name(parm->label),(BOOL)(parm->def.bvalue)?1:0);
210 printf("<input type=text size=8 name=\"parm_%s\" value=%d>", make_parm_name(parm->label), *(int *)ptr);
211 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.value=\'%d\'\">",
212 make_parm_name(parm->label),(int)(parm->def.ivalue));
216 printf("<input type=text size=8 name=\"parm_%s\" value=0%o>", make_parm_name(parm->label), *(int *)ptr);
217 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.value=\'0%o\'\">",
218 make_parm_name(parm->label),(int)(parm->def.ivalue));
222 printf("<select name=\"parm_%s\">",make_parm_name(parm->label));
223 for (i=0;parm->enum_list[i].name;i++)
224 printf("<option %s>%s",(*(int *)ptr)==parm->enum_list[i].value?"selected":"",parm->enum_list[i].name);
226 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.selectedIndex=\'%d\'\">",
227 make_parm_name(parm->label),enum_index((int)(parm->def.ivalue),parm->enum_list));
232 printf("</td></tr>\n");
235 /****************************************************************************
236 display a set of parameters for a service
237 ****************************************************************************/
238 static void show_parameters(int snum, int allparameters, int advanced, int printers)
241 struct parm_struct *parm;
242 char *heading = NULL;
243 char *last_heading = NULL;
245 while ((parm = lp_next_parameter(snum, &i, allparameters))) {
246 if (snum < 0 && parm->class == P_LOCAL && !(parm->flags & FLAG_GLOBAL))
248 if (parm->class == P_SEPARATOR) {
249 heading = parm->label;
252 if (parm->flags & FLAG_HIDE) continue;
254 if (!printers && !(parm->flags & FLAG_BASIC)) {
255 void *ptr = parm->ptr;
257 switch (parm->type) {
259 if (*(char *)ptr == (char)(parm->def.cvalue)) continue;
264 if (!strcmp(*(char **)ptr,(char *)(parm->def.svalue))) continue;
269 if (!strcmp((char *)ptr,(char *)(parm->def.svalue))) continue;
274 if (*(BOOL *)ptr == (BOOL)(parm->def.bvalue)) continue;
279 if (*(int *)ptr == (int)(parm->def.ivalue)) continue;
284 if (*(int *)ptr == (int)(parm->def.ivalue)) continue;
290 if (printers && !(parm->flags & FLAG_PRINT)) continue;
292 if (heading && heading != last_heading) {
293 printf("<tr><td></td></tr><tr><td><b><u>%s</u></b></td></tr>\n", heading);
294 last_heading = heading;
296 show_parameter(snum, parm);
300 /****************************************************************************
302 ****************************************************************************/
303 static void write_config(FILE *f, BOOL show_defaults)
305 fprintf(f, "# Samba config file created using SWAT\n");
306 fprintf(f, "# from %s (%s)\n", cgi_remote_host(), cgi_remote_addr());
307 fprintf(f, "# Date: %s\n\n", timestring());
309 lp_dump(f, show_defaults);
312 /****************************************************************************
313 save and reoad the smb.conf config file
314 ****************************************************************************/
315 static int save_reload(void)
319 f = fopen(servicesf,"w");
321 printf("failed to open %s for writing\n", servicesf);
325 write_config(f, False);
330 if (!lp_load(servicesf,False,False,False)) {
331 printf("Can't reload %s\n", servicesf);
338 /****************************************************************************
340 ****************************************************************************/
341 static void commit_parameter(int snum, struct parm_struct *parm, char *v)
346 if (snum < 0 && parm->class == P_LOCAL) {
347 /* this handles the case where we are changing a local
348 variable globally. We need to change the parameter in
349 all shares where it is currently set to the default */
350 for (i=0;i<lp_numservices();i++) {
351 s = lp_servicename(i);
352 if (s && (*s) && lp_is_default(i, parm)) {
353 lp_do_parameter(i, parm->label, v);
358 lp_do_parameter(snum, parm->label, v);
361 /****************************************************************************
362 commit a set of parameters for a service
363 ****************************************************************************/
364 static void commit_parameters(int snum)
367 struct parm_struct *parm;
371 while ((parm = lp_next_parameter(snum, &i, 1))) {
372 slprintf(label, sizeof(label)-1, "parm_%s", make_parm_name(parm->label));
373 if ((v = cgi_variable(label))) {
374 if (parm->flags & FLAG_HIDE) continue;
375 commit_parameter(snum, parm, v);
380 /****************************************************************************
381 load the smb.conf file into loadparm.
382 ****************************************************************************/
383 static void load_config(void)
385 if (!lp_load(servicesf,False,True,False)) {
386 printf("<b>Can't load %s - using defaults</b><p>\n",
391 /****************************************************************************
392 spit out the html for a link with an image
393 ****************************************************************************/
394 static void image_link(char *name,char *hlink, char *src)
396 printf("<A HREF=\"%s/%s\"><img src=\"/swat/%s\" alt=\"%s\"></A>\n",
397 cgi_baseurl(), hlink, src, name);
400 /****************************************************************************
401 display the main navigation controls at the top of each page along
403 ****************************************************************************/
404 static void show_main_buttons(void)
406 image_link("Home", "", "images/home.gif");
408 /* Root gets full functionality */
409 if (am_root() == True) {
410 image_link("Globals", "globals", "images/globals.gif");
411 image_link("Shares", "shares", "images/shares.gif");
412 image_link("Printers", "printers", "images/printers.gif");
413 image_link("Status", "status", "images/status.gif");
414 image_link("View Config", "viewconfig","images/viewconfig.gif");
417 /* Everyone gets this functionality */
418 image_link("Password Management", "passwd", "images/passwd.gif");
423 /****************************************************************************
424 display a welcome page
425 ****************************************************************************/
426 static void welcome_page(void)
428 include_html("help/welcome.html");
431 /****************************************************************************
432 display the current smb.conf
433 ****************************************************************************/
434 static void viewconfig_page(void)
438 if (cgi_variable("full_view")) {
442 printf("<H2>Current Config</H2>\n");
443 printf("<form method=post>\n");
446 printf("<input type=submit name=\"normal_view\" value=\"Normal View\">\n");
448 printf("<input type=submit name=\"full_view\" value=\"Full View\">\n");
452 write_config(stdout, full_view);
457 /****************************************************************************
458 display a globals editing page
459 ****************************************************************************/
460 static void globals_page(void)
464 printf("<H2>Global Variables</H2>\n");
466 if (cgi_variable("Advanced") && !cgi_variable("Basic"))
469 if (cgi_variable("Commit")) {
470 commit_parameters(GLOBALS_SNUM);
474 printf("<FORM name=\"swatform\" method=post>\n");
476 printf("<input type=submit name=\"Commit\" value=\"Commit Changes\">\n");
477 printf("<input type=reset name=\"Reset Values\" value=\"Reset Values\">\n");
479 printf("<input type=submit name=\"Advanced\" value=\"Advanced View\">\n");
481 printf("<input type=submit name=\"Basic\" value=\"Basic View\">\n");
486 show_parameters(GLOBALS_SNUM, 1, advanced, 0);
487 printf("</table>\n");
490 printf("<input type=hidden name=\"Advanced\" value=1>\n");
496 /****************************************************************************
497 display a shares editing page
498 ****************************************************************************/
499 static void shares_page(void)
501 char *share = cgi_variable("share");
508 snum = lp_servicenumber(share);
510 printf("<H2>Share Parameters</H2>\n");
512 if (cgi_variable("Advanced") && !cgi_variable("Basic"))
515 if (cgi_variable("Commit") && snum >= 0) {
516 commit_parameters(snum);
520 if (cgi_variable("Delete") && snum >= 0) {
521 lp_remove_service(snum);
527 if (cgi_variable("createshare") && (share=cgi_variable("newshare"))) {
528 lp_copy_service(GLOBALS_SNUM, share);
530 snum = lp_servicenumber(share);
533 printf("<FORM name=\"swatform\" method=post>\n");
536 printf("<tr><td><input type=submit name=selectshare value=\"Choose Share\"></td>\n");
537 printf("<td><select name=share>\n");
539 printf("<option value=\" \"> \n");
540 for (i=0;i<lp_numservices();i++) {
541 s = lp_servicename(i);
542 if (s && (*s) && strcmp(s,"IPC$") && !lp_print_ok(i)) {
543 printf("<option %s value=\"%s\">%s\n",
544 (share && strcmp(share,s)==0)?"SELECTED":"",
548 printf("</select></td></tr><p>");
550 printf("<tr><td><input type=submit name=createshare value=\"Create Share\"></td>\n");
551 printf("<td><input type=text size=30 name=newshare></td></tr>\n");
556 printf("<input type=submit name=\"Commit\" value=\"Commit Changes\">\n");
557 printf("<input type=submit name=\"Delete\" value=\"Delete Share\">\n");
559 printf("<input type=submit name=\"Advanced\" value=\"Advanced View\">\n");
561 printf("<input type=submit name=\"Basic\" value=\"Basic View\">\n");
568 show_parameters(snum, 1, advanced, 0);
569 printf("</table>\n");
573 printf("<input type=hidden name=\"Advanced\" value=1>\n");
579 /****************************************************************************
580 ****************************************************************************/
581 static void sig_pipe ( int signo)
583 printf("<p> SIGPIPE caught\n");
586 /****************************************************************************
587 create 2 pipes and use them to feed the smbpasswd program
588 ****************************************************************************/
589 static BOOL talk_to_smbpasswd(char *old, char *new)
591 int i, n, fd1[2], fd2[2];
594 char line[MAX_STRINGLEN + 2]; /* one for newline, one for null */
596 if (signal(SIGPIPE, sig_pipe) == SIG_ERR) {
597 printf("<p> signal error");
600 if ((pipe(fd1) < 0) || (pipe(fd2) < 0)) {
601 printf("<p> pipe error");
604 if ((pid = fork()) < 0) {
605 printf("<p> fork error");
609 * Create this relationship with the pipes between the parent and
610 * the child as detailed below.
612 * parent -> fd1[1] -- fd1[0] -> child
613 * parent <- fd2[0] -- fd2[1] <- child
615 * fd1[0] is turned into child's stdin
616 * fd2[1] is turned into child's stdout
617 * fd2[1] is also turned into child's stderr
620 else if (pid > 0) { /* parent */
622 int to_child = fd1[1];
623 int from_child = fd2[0];
626 close(fd1[0]); /* parent doesn't need input side of pipe fd1 */
627 close(fd2[1]); /* parent doesn't need output side of pipe fd2 */
630 * smbpasswd doesn't require any input to disable or enable a user
632 if (!cgi_variable(disable_user_flag) && !cgi_variable(enable_user_flag)) {
634 * smbpasswd requires a regular old user to send their old password
636 if (am_root() == False) {
637 n = (strlen(old) <= (MAX_STRINGLEN)) ? strlen(old) : (MAX_STRINGLEN);
638 strncpy( line, old, n);
639 line[n] = '\n'; n++; /* add carriage return */
640 line[n] = 0; /* add null terminator, for debug */
641 if (write( to_child, line, n) != n) {
642 printf("<p> error on write to child");
647 * smbpasswd requires that the new password be sent to it twice
649 for( i=0; i<2; i++) {
650 n = (strlen(new) <= (MAX_STRINGLEN)) ? strlen(new) : (MAX_STRINGLEN);
651 strncpy( line, new, n);
652 line[n] = '\n'; n++; /* add carriage return */
653 line[n] = 0; /* add null terminator, for debug */
654 if (write( to_child, line, n) != n) {
655 printf("<p> error on write to child");
662 * Wait for smbpasswd to finish
664 if (sys_waitpid(pid, &wstat, 0) < 0) {
665 printf("<p> problem waiting");
669 * Read the answer from the add program
671 memset( line, '\0', sizeof(line));
672 if ((n = read( from_child, line, MAX_STRINGLEN)) < 0) {
673 printf("<p> error on read from child");
677 * Write the response from smbpasswd to user, if all is well
678 * line[] should be just a null terminated line. We could
679 * check for the null line and not print anything, but we
680 * really should be checking the exit code if we want to be
683 line[n] = 0; /* null terminate */
684 printf("<p> %s\n",line);
689 if (line[0] == '\0') {
690 rslt = True; /* All ok */
692 rslt = False; /* Something didn't work */
697 int from_parent = fd1[0];
698 int to_parent = fd2[1];
700 close(fd1[1]); /* child doesn't need output side of pipe fd1 */
701 close(fd2[0]); /* child doesn't need input side of pipe fd2 */
704 * Turn the from_parent pipe into the childs stdin
706 if (from_parent != STDIN_FILENO) {
707 if (dup2( from_parent, STDIN_FILENO) != STDIN_FILENO) {
708 printf("<p> dup2 error of stdin");
714 * Turn the to_parent pipe into the childs stdout
716 if (to_parent != STDOUT_FILENO) {
717 if (dup2( to_parent, STDOUT_FILENO) != STDOUT_FILENO) {
718 printf("<p> dup2 error of stdout");
723 * Make the childs stderr the to_parent pipe also
725 if (dup2( STDOUT_FILENO, STDERR_FILENO) != STDERR_FILENO) {
726 printf("<p> dup2 error of stdout");
730 /* Root can do more */
731 if (am_root() == True) {
732 if (cgi_variable(add_user_flag)) {
736 if (execl(SMB_PASSWD_PROGRAM, "smbpasswd", "-s", "-a", cgi_variable(user), (char *) 0) < 0) {
737 printf("<p> execl error of smbpasswd");
739 } else if (cgi_variable(disable_user_flag)) {
743 if (execl(SMB_PASSWD_PROGRAM, "smbpasswd", "-s", "-d", cgi_variable(user), (char *) 0) < 0) {
744 printf("<p> execl error of smbpasswd");
746 } else if (cgi_variable(enable_user_flag)) {
750 if (execl(SMB_PASSWD_PROGRAM, "smbpasswd", "-s", "-e", cgi_variable(user), (char *) 0) < 0) {
751 printf("<p> execl error of smbpasswd");
755 * Change a users password
757 if (execl(SMB_PASSWD_PROGRAM, "smbpasswd", "-s", cgi_variable(user), (char *) 0) < 0) {
758 printf("<p> execl error of smbpasswd");
763 * Ordinary users can change any users passwd if they know the old passwd
765 if (execl(SMB_PASSWD_PROGRAM, "smbpasswd", "-s", (char *) 0) < 0) {
766 printf("<p> execl error of smbpasswd");
773 /****************************************************************************
774 become the specified uid - permanently !
775 ****************************************************************************/
777 BOOL become_user_permanently(uid_t uid, gid_t gid)
780 if (geteuid() != 0) {
784 /* now completely lose our privilages. This is a fairly paranoid
785 way of doing it, but it does work on all systems that I know of */
787 #ifdef HAVE_SETRESUID
789 * Firstly ensure all our uids are set to root.
795 * Now ensure we change all our gids.
797 setresgid(gid,gid,gid);
800 * Now ensure all the uids are the user.
802 setresuid(uid,uid,uid);
805 * Firstly ensure all our uids are set to root.
811 * Now ensure we change all our gids.
817 * Now ensure all the uids are the user.
823 if (getuid() != uid || geteuid() != uid ||
824 getgid() != gid || getegid() != gid) {
825 /* We failed to lose our privilages. */
832 /****************************************************************************
833 do the stuff required to add or change a password
834 ****************************************************************************/
835 static void chg_passwd(void)
837 struct passwd *pass = NULL;
840 /* Make sure users name has been specified */
841 if (strlen(cgi_variable(user)) == 0) {
842 printf("<p> Must specify \"User Name\" \n");
847 * smbpasswd doesn't require anything but the users name to disable or enable the user,
848 * so if that's what we're doing, skip the rest of the checks
850 if (!cgi_variable(disable_user_flag) && !cgi_variable(enable_user_flag)) {
852 /* If current user is not root, make sure old password has been specified */
853 if ((am_root() == False) && (strlen( cgi_variable(old_pswd)) <= 0)) {
854 printf("<p> Must specify \"Old Password\" \n");
858 /* Make sure new passwords have been specified */
859 if ((strlen( cgi_variable(new_pswd )) <= 0) ||
860 (strlen( cgi_variable(new2_pswd)) <= 0)) {
861 printf("<p> Must specify \"New, and Re-typed Passwords\" \n");
865 /* Make sure new passwords was typed correctly twice */
866 if (strcmp(cgi_variable(new_pswd), cgi_variable(new2_pswd)) != 0) {
867 printf("<p> Re-typed password didn't match new password\n");
873 if (pass) printf("<p> User uid %d gid %d \n", pass->pw_uid, pass->pw_gid);
874 printf("<p> Processes uid %d, euid %d, gid %d, egid %d \n",getuid(),geteuid(),getgid(),getegid());
875 printf("<p> User Name %s \n", cgi_variable(user));
876 printf("<p> Old passwd %s \n", cgi_variable(old_pswd) ? cgi_variable(old_pswd):"");
877 printf("<p> New passwd %s \n", cgi_variable(new_pswd));
878 printf("<p> Re-typed New passwd %s \n", cgi_variable(new2_pswd));
879 printf("<p> flags '%s', '%s', '%s' \n",
880 (cgi_variable( chg_passwd_flag) ? cgi_variable( chg_passwd_flag) : ""),
881 (cgi_variable( add_user_flag) ? cgi_variable( add_user_flag) : ""),
882 (cgi_variable( disable_user_flag) ? cgi_variable( disable_user_flag) : ""));
883 (cgi_variable( enable_user_flag) ? cgi_variable( enable_user_flag) : ""));
884 #endif /* SWAT_DEBUG */
887 rslt = talk_to_smbpasswd( cgi_variable(old_pswd), cgi_variable(new_pswd));
888 if (am_root() == False) {
890 printf("<p> The passwd for '%s' has been changed. \n",cgi_variable(user));
892 printf("<p> The passwd for '%s' has NOT been changed. \n",cgi_variable(user));
899 /****************************************************************************
900 display a password editing page
901 ****************************************************************************/
902 static void passwd_page(void)
906 printf("<H2>Password Manager</H2>\n");
908 printf("<FORM name=\"swatform\" method=post>\n");
913 * After the first time through here be nice. If the user
914 * changed the User box text to another users name, remember it.
916 if ( cgi_variable(user) &&
917 (strcmp(cgi_variable(user), get_user_name()))) {
918 /* User is changing another accounts passwd */
919 new_name = cgi_variable(user);
921 /* User is changing there own passwd */
922 new_name = get_user_name();
925 printf("<p> User Name : <input type=text size=30 name=%s value=%s> \n", user, new_name);
926 if (am_root() == False) {
927 printf("<p> Old Password: <input type=password size=30 name=%s>\n",old_pswd);
929 printf("<p> New Password: <input type=password size=30 name=%s>\n",new_pswd);
930 printf("<p> Re-type New Password: <input type=password size=30 name=%s>\n",new2_pswd);
932 printf("</select></td></tr><p>");
934 printf("<input type=submit name=%s value=\"Change Password\">", chg_passwd_flag);
935 if (am_root() == True) {
936 printf("<input type=submit name=%s value=\"Add New User\">", add_user_flag);
937 printf("<input type=submit name=%s value=\"Disable User\">", disable_user_flag);
938 printf("<input type=submit name=%s value=\"Enable User\">", enable_user_flag);
943 * If we don't have user information then there's nothing to do. It's probably
944 * the first time through this code.
946 if (cgi_variable(user)) {
955 /****************************************************************************
956 display a printers editing page
957 ****************************************************************************/
958 static void printers_page(void)
960 char *share = cgi_variable("share");
967 snum = lp_servicenumber(share);
969 printf("<H2>Printer Parameters</H2>\n");
971 if (cgi_variable("Advanced") && !cgi_variable("Basic"))
974 if (cgi_variable("Commit") && snum >= 0) {
975 commit_parameters(snum);
979 if (cgi_variable("Delete") && snum >= 0) {
980 lp_remove_service(snum);
986 if (cgi_variable("createshare") && (share=cgi_variable("newshare"))) {
987 lp_copy_service(GLOBALS_SNUM, share);
988 snum = lp_servicenumber(share);
989 lp_do_parameter(snum, "print ok", "Yes");
991 snum = lp_servicenumber(share);
994 printf("<FORM name=\"swatform\" method=post>\n");
997 printf("<tr><td><input type=submit name=selectshare value=\"Choose Printer\"></td>\n");
998 printf("<td><select name=share>\n");
999 if (snum < 0 || !lp_print_ok(snum))
1000 printf("<option value=\" \"> \n");
1001 for (i=0;i<lp_numservices();i++) {
1002 s = lp_servicename(i);
1003 if (s && (*s) && strcmp(s,"IPC$") && lp_print_ok(i)) {
1004 printf("<option %s value=\"%s\">%s\n",
1005 (share && strcmp(share,s)==0)?"SELECTED":"",
1009 printf("</select></td></tr><p>");
1011 printf("<tr><td><input type=submit name=createshare value=\"Create Printer\"></td>\n");
1012 printf("<td><input type=text size=30 name=newshare></td></tr>\n");
1017 printf("<input type=submit name=\"Commit\" value=\"Commit Changes\">\n");
1018 printf("<input type=submit name=\"Delete\" value=\"Delete Printer\">\n");
1019 if (advanced == 0) {
1020 printf("<input type=submit name=\"Advanced\" value=\"Advanced View\">\n");
1022 printf("<input type=submit name=\"Basic\" value=\"Basic View\">\n");
1028 printf("<table>\n");
1029 show_parameters(snum, 1, advanced, 1);
1030 printf("</table>\n");
1034 printf("<input type=hidden name=\"Advanced\" value=1>\n");
1037 printf("</FORM>\n");
1040 /****************************************************************************
1042 ****************************************************************************/
1043 int main(int argc, char *argv[])
1045 extern char *optarg;
1050 int auth_required = 1;
1052 /* just in case it goes wild ... */
1055 dbf = fopen("/dev/null", "w");
1057 if (!dbf) dbf = stderr;
1059 while ((opt = getopt(argc, argv,"s:a")) != EOF) {
1062 pstrcpy(servicesf,optarg);
1070 cgi_setup(SWATDIR, auth_required);
1074 charset_initialise();
1076 /* if this binary is setuid then run completely as root */
1081 cgi_load_variables(NULL);
1083 show_main_buttons();
1085 page = cgi_pathinfo();
1087 /* Root gets full functionality */
1088 if (am_root() == True) {
1089 if (strcmp(page, "globals")==0) {
1091 } else if (strcmp(page,"shares")==0) {
1093 } else if (strcmp(page,"printers")==0) {
1095 } else if (strcmp(page,"status")==0) {
1097 } else if (strcmp(page,"viewconfig")==0) {
1099 } else if (strcmp(page,"passwd")==0) {
1105 /* Everyone gets this functionality */
1106 if (strcmp(page,"passwd")==0) {