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";
44 /* we need these because we link to locking*.o */
45 void become_root(BOOL save_dir) {}
46 void unbecome_root(BOOL restore_dir) {}
47 /* We need this because we link to password.o */
48 BOOL change_oem_password(struct smb_passwd *smbpw, char *new_passwd, BOOL override) {return False;}
50 /****************************************************************************
51 ****************************************************************************/
52 static int enum_index(int value, struct enum_list *enumlist)
55 for (i=0;enumlist[i].name;i++)
56 if (value == enumlist[i].value) break;
60 static char *fix_backslash(char *str)
62 static char newstring[1024];
66 if (*str == '\\') {*p++ = '\\';*p++ = '\\';}
74 static char *stripspace(char *str)
76 static char newstring[1024];
80 if (*str != ' ') *p++ = *str;
87 static char *make_parm_name(char *label)
89 static char parmname[1024];
93 if (*label == ' ') *p++ = '_';
101 /****************************************************************************
102 include a lump of html in a page
103 ****************************************************************************/
104 static int include_html(char *fname)
106 FILE *f = fopen(fname,"r");
111 printf("ERROR: Can't open %s\n", fname);
116 ret = fread(buf, 1, sizeof(buf), f);
118 fwrite(buf, 1, ret, stdout);
125 /****************************************************************************
126 start the page with standard stuff
127 ****************************************************************************/
128 static void print_header(void)
130 if (!cgi_waspost()) {
131 printf("Expires: 0\r\n");
133 printf("Content-type: text/html\r\n\r\n");
135 if (!include_html("include/header.html")) {
136 printf("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n");
137 printf("<HTML>\n<HEAD>\n<TITLE>Samba Web Administration Tool</TITLE>\n</HEAD>\n<BODY background=\"/swat/images/background.jpg\">\n\n");
141 /****************************************************************************
143 ****************************************************************************/
144 static void print_footer(void)
146 if (!include_html("include/footer.html")) {
147 printf("\n</BODY>\n</HTML>\n");
151 /****************************************************************************
152 display one editable parameter in a form
153 ****************************************************************************/
154 static void show_parameter(int snum, struct parm_struct *parm)
157 void *ptr = parm->ptr;
159 if (parm->class == P_LOCAL && snum >= 0) {
160 ptr = lp_local_ptr(snum, ptr);
163 printf("<tr><td><A HREF=\"/swat/help/smb.conf.5.html#%s\">?</A> %s</td><td>",
164 stripspace(parm->label), parm->label);
166 switch (parm->type) {
168 printf("<input type=text size=2 name=\"parm_%s\" value=\"%c\">",
169 make_parm_name(parm->label), *(char *)ptr);
170 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.value=\'%c\'\">",
171 make_parm_name(parm->label),(char)(parm->def.cvalue));
176 printf("<input type=text size=40 name=\"parm_%s\" value=\"%s\">",
177 make_parm_name(parm->label), *(char **)ptr);
178 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.value=\'%s\'\">",
179 make_parm_name(parm->label),fix_backslash((char *)(parm->def.svalue)));
184 printf("<input type=text size=40 name=\"parm_%s\" value=\"%s\">",
185 make_parm_name(parm->label), (char *)ptr);
186 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.value=\'%s\'\">",
187 make_parm_name(parm->label),fix_backslash((char *)(parm->def.svalue)));
191 printf("<select name=\"parm_%s\">",make_parm_name(parm->label));
192 printf("<option %s>Yes", (*(BOOL *)ptr)?"selected":"");
193 printf("<option %s>No", (*(BOOL *)ptr)?"":"selected");
195 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.selectedIndex=\'%d\'\">",
196 make_parm_name(parm->label),(BOOL)(parm->def.bvalue)?0:1);
200 printf("<select name=\"parm_%s\">",make_parm_name(parm->label));
201 printf("<option %s>Yes", (*(BOOL *)ptr)?"":"selected");
202 printf("<option %s>No", (*(BOOL *)ptr)?"selected":"");
204 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.selectedIndex=\'%d\'\">",
205 make_parm_name(parm->label),(BOOL)(parm->def.bvalue)?1:0);
209 printf("<input type=text size=8 name=\"parm_%s\" value=%d>", make_parm_name(parm->label), *(int *)ptr);
210 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.value=\'%d\'\">",
211 make_parm_name(parm->label),(int)(parm->def.ivalue));
215 printf("<input type=text size=8 name=\"parm_%s\" value=0%o>", make_parm_name(parm->label), *(int *)ptr);
216 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.value=\'0%o\'\">",
217 make_parm_name(parm->label),(int)(parm->def.ivalue));
221 printf("<select name=\"parm_%s\">",make_parm_name(parm->label));
222 for (i=0;parm->enum_list[i].name;i++)
223 printf("<option %s>%s",(*(int *)ptr)==parm->enum_list[i].value?"selected":"",parm->enum_list[i].name);
225 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.selectedIndex=\'%d\'\">",
226 make_parm_name(parm->label),enum_index((int)(parm->def.ivalue),parm->enum_list));
231 printf("</td></tr>\n");
234 /****************************************************************************
235 display a set of parameters for a service
236 ****************************************************************************/
237 static void show_parameters(int snum, int allparameters, int advanced, int printers)
240 struct parm_struct *parm;
241 char *heading = NULL;
242 char *last_heading = NULL;
244 while ((parm = lp_next_parameter(snum, &i, allparameters))) {
245 if (snum < 0 && parm->class == P_LOCAL && !(parm->flags & FLAG_GLOBAL))
247 if (parm->class == P_SEPARATOR) {
248 heading = parm->label;
251 if (parm->flags & FLAG_HIDE) continue;
253 if (!printers && !(parm->flags & FLAG_BASIC)) {
254 void *ptr = parm->ptr;
256 switch (parm->type) {
258 if (*(char *)ptr == (char)(parm->def.cvalue)) continue;
263 if (!strcmp(*(char **)ptr,(char *)(parm->def.svalue))) continue;
268 if (!strcmp((char *)ptr,(char *)(parm->def.svalue))) continue;
273 if (*(BOOL *)ptr == (BOOL)(parm->def.bvalue)) continue;
278 if (*(int *)ptr == (int)(parm->def.ivalue)) continue;
283 if (*(int *)ptr == (int)(parm->def.ivalue)) continue;
289 if (printers && !(parm->flags & FLAG_PRINT)) continue;
291 if (heading && heading != last_heading) {
292 printf("<tr><td></td></tr><tr><td><b><u>%s</u></b></td></tr>\n", heading);
293 last_heading = heading;
295 show_parameter(snum, parm);
299 /****************************************************************************
301 ****************************************************************************/
302 static void write_config(FILE *f, BOOL show_defaults)
304 fprintf(f, "# Samba config file created using SWAT\n");
305 fprintf(f, "# from %s (%s)\n", cgi_remote_host(), cgi_remote_addr());
306 fprintf(f, "# Date: %s\n\n", timestring());
308 lp_dump(f, show_defaults);
311 /****************************************************************************
312 save and reoad the smb.conf config file
313 ****************************************************************************/
314 static int save_reload(void)
318 f = fopen(servicesf,"w");
320 printf("failed to open %s for writing\n", servicesf);
324 write_config(f, False);
329 if (!lp_load(servicesf,False,False,False)) {
330 printf("Can't reload %s\n", servicesf);
337 /****************************************************************************
339 ****************************************************************************/
340 static void commit_parameter(int snum, struct parm_struct *parm, char *v)
345 if (snum < 0 && parm->class == P_LOCAL) {
346 /* this handles the case where we are changing a local
347 variable globally. We need to change the parameter in
348 all shares where it is currently set to the default */
349 for (i=0;i<lp_numservices();i++) {
350 s = lp_servicename(i);
351 if (s && (*s) && lp_is_default(i, parm)) {
352 lp_do_parameter(i, parm->label, v);
357 lp_do_parameter(snum, parm->label, v);
360 /****************************************************************************
361 commit a set of parameters for a service
362 ****************************************************************************/
363 static void commit_parameters(int snum)
366 struct parm_struct *parm;
370 while ((parm = lp_next_parameter(snum, &i, 1))) {
371 slprintf(label, sizeof(label)-1, "parm_%s", make_parm_name(parm->label));
372 if ((v = cgi_variable(label))) {
373 if (parm->flags & FLAG_HIDE) continue;
374 commit_parameter(snum, parm, v);
379 /****************************************************************************
380 load the smb.conf file into loadparm.
381 ****************************************************************************/
382 static void load_config(void)
384 if (!lp_load(servicesf,False,True,False)) {
385 printf("<b>Can't load %s - using defaults</b><p>\n",
390 /****************************************************************************
391 spit out the html for a link with an image
392 ****************************************************************************/
393 static void image_link(char *name,char *hlink, char *src)
395 printf("<A HREF=\"%s/%s\"><img src=\"/swat/%s\" alt=\"%s\"></A>\n",
396 cgi_baseurl(), hlink, src, name);
399 /****************************************************************************
400 display the main navigation controls at the top of each page along
402 ****************************************************************************/
403 static void show_main_buttons(void)
405 image_link("Home", "", "images/home.gif");
407 /* Root gets full functionality */
408 if ( is_root() == True) {
409 image_link("Globals", "globals", "images/globals.gif");
410 image_link("Shares", "shares", "images/shares.gif");
411 image_link("Printers", "printers", "images/printers.gif");
412 image_link("Status", "status", "images/status.gif");
413 image_link("View Config", "viewconfig","images/viewconfig.gif");
416 /* Everyone gets this functionality */
417 image_link("Password Management", "passwd", "images/passwd.gif");
422 /****************************************************************************
423 display a welcome page
424 ****************************************************************************/
425 static void welcome_page(void)
427 include_html("help/welcome.html");
430 /****************************************************************************
431 display the current smb.conf
432 ****************************************************************************/
433 static void viewconfig_page(void)
437 if (cgi_variable("full_view")) {
441 printf("<H2>Current Config</H2>\n");
442 printf("<form method=post>\n");
445 printf("<input type=submit name=\"normal_view\" value=\"Normal View\">\n");
447 printf("<input type=submit name=\"full_view\" value=\"Full View\">\n");
451 write_config(stdout, full_view);
456 /****************************************************************************
457 display a globals editing page
458 ****************************************************************************/
459 static void globals_page(void)
463 printf("<H2>Global Variables</H2>\n");
465 if (cgi_variable("Advanced") && !cgi_variable("Basic"))
468 if (cgi_variable("Commit")) {
469 commit_parameters(GLOBALS_SNUM);
473 printf("<FORM name=\"swatform\" method=post>\n");
475 printf("<input type=submit name=\"Commit\" value=\"Commit Changes\">\n");
476 printf("<input type=reset name=\"Reset Values\" value=\"Reset Values\">\n");
478 printf("<input type=submit name=\"Advanced\" value=\"Advanced View\">\n");
480 printf("<input type=submit name=\"Basic\" value=\"Basic View\">\n");
485 show_parameters(GLOBALS_SNUM, 1, advanced, 0);
486 printf("</table>\n");
489 printf("<input type=hidden name=\"Advanced\" value=1>\n");
495 /****************************************************************************
496 display a shares editing page
497 ****************************************************************************/
498 static void shares_page(void)
500 char *share = cgi_variable("share");
507 snum = lp_servicenumber(share);
509 printf("<H2>Share Parameters</H2>\n");
511 if (cgi_variable("Advanced") && !cgi_variable("Basic"))
514 if (cgi_variable("Commit") && snum >= 0) {
515 commit_parameters(snum);
519 if (cgi_variable("Delete") && snum >= 0) {
520 lp_remove_service(snum);
526 if (cgi_variable("createshare") && (share=cgi_variable("newshare"))) {
527 lp_copy_service(GLOBALS_SNUM, share);
529 snum = lp_servicenumber(share);
532 printf("<FORM name=\"swatform\" method=post>\n");
535 printf("<tr><td><input type=submit name=selectshare value=\"Choose Share\"></td>\n");
536 printf("<td><select name=share>\n");
538 printf("<option value=\" \"> \n");
539 for (i=0;i<lp_numservices();i++) {
540 s = lp_servicename(i);
541 if (s && (*s) && strcmp(s,"IPC$") && !lp_print_ok(i)) {
542 printf("<option %s value=\"%s\">%s\n",
543 (share && strcmp(share,s)==0)?"SELECTED":"",
547 printf("</select></td></tr><p>");
549 printf("<tr><td><input type=submit name=createshare value=\"Create Share\"></td>\n");
550 printf("<td><input type=text size=30 name=newshare></td></tr>\n");
555 printf("<input type=submit name=\"Commit\" value=\"Commit Changes\">\n");
556 printf("<input type=submit name=\"Delete\" value=\"Delete Share\">\n");
558 printf("<input type=submit name=\"Advanced\" value=\"Advanced View\">\n");
560 printf("<input type=submit name=\"Basic\" value=\"Basic View\">\n");
567 show_parameters(snum, 1, advanced, 0);
568 printf("</table>\n");
572 printf("<input type=hidden name=\"Advanced\" value=1>\n");
578 /****************************************************************************
579 ****************************************************************************/
580 static void sig_pipe ( int signo)
582 printf("<p> SIGPIPE caught\n");
585 /****************************************************************************
586 create 2 pipes and use them to feed the smbpasswd program
587 ****************************************************************************/
588 static BOOL talk_to_smbpasswd(char *old, char *new)
590 int i, n, fd1[2], fd2[2];
593 char line[MAX_STRINGLEN + 2]; /* one for newline, one for null */
595 if (signal(SIGPIPE, sig_pipe) == SIG_ERR) {
596 printf("<p> signal error");
599 if ((pipe(fd1) < 0) || (pipe(fd2) < 0)) {
600 printf("<p> pipe error");
603 if ((pid = fork()) < 0) {
604 printf("<p> fork error");
608 * Create this relationship with the pipes between the parent and
609 * the child as detailed below.
611 * parent -> fd1[1] -- fd1[0] -> child
612 * parent <- fd2[0] -- fd2[1] <- child
614 * fd1[0] is turned into child's stdin
615 * fd2[1] is turned into child's stdout
616 * fd2[1] is also turned into child's stderr
619 else if (pid > 0) { /* parent */
621 int to_child = fd1[1];
622 int from_child = fd2[0];
625 close(fd1[0]); /* parent doesn't need input side of pipe fd1 */
626 close(fd2[1]); /* parent doesn't need output side of pipe fd2 */
629 * smbpasswd doesn't require any input to disable a user
631 if (cgi_variable(disable_user_flag)) {
633 * smbpasswd requires a regular old user to send their old password
635 if ( is_root() == False) {
636 n = (strlen(old) <= (MAX_STRINGLEN)) ? strlen(old) : (MAX_STRINGLEN);
637 strncpy( line, old, n);
638 line[n] = '\n'; n++; /* add carriage return */
639 line[n] = 0; /* add null terminator, for debug */
640 if (write( to_child, line, n) != n) {
641 printf("<p> error on write to child");
646 * smbpasswd requires that the new password be sent to it twice
648 for( i=0; i<2; i++) {
649 n = (strlen(new) <= (MAX_STRINGLEN)) ? strlen(new) : (MAX_STRINGLEN);
650 strncpy( line, new, n);
651 line[n] = '\n'; n++; /* add carriage return */
652 line[n] = 0; /* add null terminator, for debug */
653 if (write( to_child, line, n) != n) {
654 printf("<p> error on write to child");
661 * Wait for smbpasswd to finish
663 if (sys_waitpid(pid, &wstat, 0) < 0) {
664 printf("<p> problem waiting");
668 * Read the answer from the add program
670 memset( line, '\0', sizeof(line));
671 if ((n = read( from_child, line, MAX_STRINGLEN)) < 0) {
672 printf("<p> error on read from child");
676 * Write the response from smbpasswd to user, if all is well
677 * line[] should be just a null terminated line. We could
678 * check for the null line and not print anything, but we
679 * really should be checking the exit code if we want to be
682 line[n] = 0; /* null terminate */
683 printf("<p> %s\n",line);
688 if (line[0] == '\0') {
689 rslt = True; /* All ok */
691 rslt = False; /* Something didn't work */
696 int from_parent = fd1[0];
697 int to_parent = fd2[1];
699 close(fd1[1]); /* child doesn't need output side of pipe fd1 */
700 close(fd2[0]); /* child doesn't need input side of pipe fd2 */
703 * Turn the from_parent pipe into the childs stdin
705 if (from_parent != STDIN_FILENO) {
706 if (dup2( from_parent, STDIN_FILENO) != STDIN_FILENO) {
707 printf("<p> dup2 error of stdin");
713 * Turn the to_parent pipe into the childs stdout
715 if (to_parent != STDOUT_FILENO) {
716 if (dup2( to_parent, STDOUT_FILENO) != STDOUT_FILENO) {
717 printf("<p> dup2 error of stdout");
722 * Make the childs stderr the to_parent pipe also
724 if (dup2( STDOUT_FILENO, STDERR_FILENO) != STDERR_FILENO) {
725 printf("<p> dup2 error of stdout");
729 /* Root can do more */
730 if (is_root() == True) {
731 if (cgi_variable(add_user_flag)) {
735 if (execl(SMB_PASSWD_PROGRAM, "smbpasswd", "-s", "-a", cgi_variable(user), (char *) 0) < 0) {
736 printf("<p> execl error of smbpasswd");
738 } else if (cgi_variable(disable_user_flag)) {
742 if (execl(SMB_PASSWD_PROGRAM, "smbpasswd", "-s", "-d", cgi_variable(user), (char *) 0) < 0) {
743 printf("<p> execl error of smbpasswd");
747 * Change a users password
749 if (execl(SMB_PASSWD_PROGRAM, "smbpasswd", "-s", cgi_variable(user), (char *) 0) < 0) {
750 printf("<p> execl error of smbpasswd");
755 * Ordinary users can change any users passwd if they know the old passwd
757 if (execl(SMB_PASSWD_PROGRAM, "smbpasswd", "-s", (char *) 0) < 0) {
758 printf("<p> execl error of smbpasswd");
765 /****************************************************************************
766 become the specified uid
767 ****************************************************************************/
768 static BOOL become_uid(uid_t uid)
770 #ifdef HAVE_TRAPDOOR_UID
772 /* AIX3 has setuidx which is NOT a trapoor function (tridge) */
773 if (setuidx(ID_EFFECTIVE, uid) != 0) {
774 if (seteuid(uid) != 0) {
775 printf("<p> Can't set uid %d (setuidx)\n", (int)uid);
782 #ifdef HAVE_SETRESUID
783 if (setresuid(-1,uid,-1) != 0)
785 if ((seteuid(uid) != 0) && (setuid(uid) != 0))
788 printf("<p> Couldn't set uid %d currently set to (uid %d, euid %d)\n",
789 (int)uid,(int)getuid(), (int)geteuid());
790 if (uid > (uid_t)32000) {
791 printf("<p> Looks like your OS doesn't like high uid values - try using a different account\n");
797 if (((uid == (uid_t)-1) || ((sizeof(uid_t) == 2) && (uid == 65535))) &&
798 (geteuid() != uid)) {
799 printf("<p> Invalid uid -1. perhaps you have a account with uid 65535?\n");
806 /****************************************************************************
807 become the specified gid
808 ****************************************************************************/
809 static BOOL become_gid(gid_t gid)
811 #ifdef HAVE_SETRESUID
812 if (setresgid(-1,gid,-1) != 0)
814 if (setgid(gid) != 0)
817 printf("<p> Couldn't set gid %d currently set to (gid %d, egid %d)\n",
818 (int)gid,(int)getgid(),(int)getegid());
820 printf("<p> Looks like your OS doesn't like high gid values - try using a different account\n");
828 /****************************************************************************
829 become the specified uid and gid
830 ****************************************************************************/
831 static BOOL become_id(uid_t uid,gid_t gid)
833 return(become_gid(gid) && become_uid(uid));
836 /****************************************************************************
837 do the stuff required to add or change a password
838 ****************************************************************************/
839 static void chg_passwd(void)
842 struct passwd *pass = NULL;
845 /* Make sure users name has been specified */
846 if (strlen(cgi_variable(user)) == 0) {
847 printf("<p> Must specify \"User Name\" \n");
852 * smbpasswd doesn't require anything but the users name to disable the user,
853 * so if that's what we're doing, skip the rest of the checks
855 if (!cgi_variable(disable_user_flag)) {
857 /* If current user is not root, make sure old password has been specified */
858 if ((is_root() == False) && (strlen( cgi_variable(old_pswd)) <= 0)) {
859 printf("<p> Must specify \"Old Password\" \n");
863 /* Make sure new passwords have been specified */
864 if ((strlen( cgi_variable(new_pswd )) <= 0) ||
865 (strlen( cgi_variable(new2_pswd)) <= 0)) {
866 printf("<p> Must specify \"New, and Re-typed Passwords\" \n");
870 /* Make sure new passwords was typed correctly twice */
871 if (strcmp(cgi_variable(new_pswd), cgi_variable(new2_pswd)) != 0) {
872 printf("<p> Re-typed password didn't match new password\n");
877 /* Get the UID/GID of the user, and become that user */
878 if (is_root() == False) {
879 pass = Get_Pwnam(cgi_variable(user),True);
881 printf("<p> User uid unknown \n");
883 if (become_id(pass->pw_uid, pass->pw_gid) == False) {
884 printf("<p> uid/gid set failed \n");
891 if (pass) printf("<p> User uid %d gid %d \n", pass->pw_uid, pass->pw_gid);
892 printf("<p> Processes uid %d, euid %d, gid %d, egid %d \n",getuid(),geteuid(),getgid(),getegid());
893 printf("<p> User Name %s \n", cgi_variable(user));
894 printf("<p> Old passwd %s \n", cgi_variable(old_pswd) ? cgi_variable(old_pswd):"");
895 printf("<p> New passwd %s \n", cgi_variable(new_pswd));
896 printf("<p> Re-typed New passwd %s \n", cgi_variable(new2_pswd));
897 printf("<p> flags '%s', '%s', '%s' \n",
898 (cgi_variable( chg_passwd_flag) ? cgi_variable( chg_passwd_flag) : ""),
899 (cgi_variable( add_user_flag) ? cgi_variable( add_user_flag) : ""),
900 (cgi_variable( disable_user_flag) ? cgi_variable( disable_user_flag) : ""));
901 #endif /* SWAT_DEBUG */
904 rslt = talk_to_smbpasswd( cgi_variable(old_pswd), cgi_variable(new_pswd));
905 if (is_root() == False) {
907 printf("<p> The passwd for '%s' has been changed. \n",cgi_variable(user));
909 printf("<p> The passwd for '%s' has NOT been changed. \n",cgi_variable(user));
916 /****************************************************************************
917 display a password editing page
918 ****************************************************************************/
919 static void passwd_page(void)
924 printf("<H2>Password Manager</H2>\n");
926 printf("<FORM name=\"swatform\" method=post>\n");
931 * After the first time through here be nice. If the user
932 * changed the User box text to another users name, remember it.
934 if ( cgi_variable(user) &&
935 (strcmp(cgi_variable(user), get_user_name()))) {
936 /* User is changing another accounts passwd */
937 new_name = cgi_variable(user);
939 /* User is changing there own passwd */
940 new_name = get_user_name();
943 printf("<p> User Name : <input type=text size=30 name=%s value=%s> \n", user, new_name);
944 if (is_root() == False) {
945 printf("<p> Old Password: <input type=password size=30 name=%s>\n",old_pswd);
947 printf("<p> New Password: <input type=password size=30 name=%s>\n",new_pswd);
948 printf("<p> Re-type New Password: <input type=password size=30 name=%s>\n",new2_pswd);
950 printf("</select></td></tr><p>");
952 printf("<input type=submit name=%s value=\"Change Password\">", chg_passwd_flag);
953 if (is_root() == True) {
954 printf("<input type=submit name=%s value=\"Add New User\">", add_user_flag);
955 printf("<input type=submit name=%s value=\"Disable User\">", disable_user_flag);
960 * If we don't have user information then there's nothing to do. It's probably
961 * the first time through this code.
963 if (cgi_variable(user)) {
972 /****************************************************************************
973 display a printers editing page
974 ****************************************************************************/
975 static void printers_page(void)
977 char *share = cgi_variable("share");
984 snum = lp_servicenumber(share);
986 printf("<H2>Printer Parameters</H2>\n");
988 if (cgi_variable("Advanced") && !cgi_variable("Basic"))
991 if (cgi_variable("Commit") && snum >= 0) {
992 commit_parameters(snum);
996 if (cgi_variable("Delete") && snum >= 0) {
997 lp_remove_service(snum);
1003 if (cgi_variable("createshare") && (share=cgi_variable("newshare"))) {
1004 lp_copy_service(GLOBALS_SNUM, share);
1005 snum = lp_servicenumber(share);
1006 lp_do_parameter(snum, "print ok", "Yes");
1008 snum = lp_servicenumber(share);
1011 printf("<FORM name=\"swatform\" method=post>\n");
1013 printf("<table>\n");
1014 printf("<tr><td><input type=submit name=selectshare value=\"Choose Printer\"></td>\n");
1015 printf("<td><select name=share>\n");
1016 if (snum < 0 || !lp_print_ok(snum))
1017 printf("<option value=\" \"> \n");
1018 for (i=0;i<lp_numservices();i++) {
1019 s = lp_servicename(i);
1020 if (s && (*s) && strcmp(s,"IPC$") && lp_print_ok(i)) {
1021 printf("<option %s value=\"%s\">%s\n",
1022 (share && strcmp(share,s)==0)?"SELECTED":"",
1026 printf("</select></td></tr><p>");
1028 printf("<tr><td><input type=submit name=createshare value=\"Create Printer\"></td>\n");
1029 printf("<td><input type=text size=30 name=newshare></td></tr>\n");
1034 printf("<input type=submit name=\"Commit\" value=\"Commit Changes\">\n");
1035 printf("<input type=submit name=\"Delete\" value=\"Delete Printer\">\n");
1036 if (advanced == 0) {
1037 printf("<input type=submit name=\"Advanced\" value=\"Advanced View\">\n");
1039 printf("<input type=submit name=\"Basic\" value=\"Basic View\">\n");
1045 printf("<table>\n");
1046 show_parameters(snum, 1, advanced, 1);
1047 printf("</table>\n");
1051 printf("<input type=hidden name=\"Advanced\" value=1>\n");
1054 printf("</FORM>\n");
1057 /****************************************************************************
1059 ****************************************************************************/
1060 int main(int argc, char *argv[])
1062 extern char *optarg;
1067 int auth_required = 1;
1069 /* just in case it goes wild ... */
1072 dbf = fopen("/dev/null", "w");
1074 if (!dbf) dbf = stderr;
1076 while ((opt = getopt(argc, argv,"s:a")) != EOF) {
1079 pstrcpy(servicesf,optarg);
1087 cgi_setup(SWATDIR, auth_required);
1091 charset_initialise();
1093 /* if this binary is setuid then run completely as root */
1098 cgi_load_variables(NULL);
1100 show_main_buttons();
1102 page = cgi_pathinfo();
1104 /* Root gets full functionality */
1105 if ( is_root() == True) {
1106 if (strcmp(page, "globals")==0) {
1108 } else if (strcmp(page,"shares")==0) {
1110 } else if (strcmp(page,"printers")==0) {
1112 } else if (strcmp(page,"status")==0) {
1114 } else if (strcmp(page,"viewconfig")==0) {
1116 } else if (strcmp(page,"passwd")==0) {
1122 /* Everyone gets this functionality */
1123 if (strcmp(page,"passwd")==0) {