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 DISABLE_USER_FLAG "disable_user_flag"
48 #define ENABLE_USER_FLAG "enable_user_flag"
49 #define RHOST "remote_host"
51 /* we need these because we link to locking*.o */
52 void become_root(BOOL save_dir
) {}
53 void unbecome_root(BOOL restore_dir
) {}
55 /****************************************************************************
56 ****************************************************************************/
57 static int enum_index(int value
, struct enum_list
*enumlist
)
60 for (i
=0;enumlist
[i
].name
;i
++)
61 if (value
== enumlist
[i
].value
) break;
65 static char *fix_backslash(char *str
)
67 static char newstring
[1024];
71 if (*str
== '\\') {*p
++ = '\\';*p
++ = '\\';}
79 static char *stripspace(char *str
)
81 static char newstring
[1024];
85 if (*str
!= ' ') *p
++ = *str
;
92 static char *make_parm_name(char *label
)
94 static char parmname
[1024];
98 if (*label
== ' ') *p
++ = '_';
106 /****************************************************************************
107 include a lump of html in a page
108 ****************************************************************************/
109 static int include_html(char *fname
)
111 FILE *f
= sys_fopen(fname
,"r");
116 printf("ERROR: Can't open %s\n", fname
);
121 ret
= fread(buf
, 1, sizeof(buf
), f
);
123 fwrite(buf
, 1, ret
, stdout
);
130 /****************************************************************************
131 start the page with standard stuff
132 ****************************************************************************/
133 static void print_header(void)
135 if (!cgi_waspost()) {
136 printf("Expires: 0\r\n");
138 printf("Content-type: text/html\r\n\r\n");
140 if (!include_html("include/header.html")) {
141 printf("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n");
142 printf("<HTML>\n<HEAD>\n<TITLE>Samba Web Administration Tool</TITLE>\n</HEAD>\n<BODY background=\"/swat/images/background.jpg\">\n\n");
146 /****************************************************************************
148 ****************************************************************************/
149 static void print_footer(void)
151 if (!include_html("include/footer.html")) {
152 printf("\n</BODY>\n</HTML>\n");
156 /****************************************************************************
157 display one editable parameter in a form
158 ****************************************************************************/
159 static void show_parameter(int snum
, struct parm_struct
*parm
)
162 void *ptr
= parm
->ptr
;
164 if (parm
->class == P_LOCAL
&& snum
>= 0) {
165 ptr
= lp_local_ptr(snum
, ptr
);
168 printf("<tr><td><A HREF=\"/swat/help/smb.conf.5.html#%s\" target=\"docs\">Help</A> %s</td><td>",
169 stripspace(parm
->label
), parm
->label
);
171 switch (parm
->type
) {
173 printf("<input type=text size=2 name=\"parm_%s\" value=\"%c\">",
174 make_parm_name(parm
->label
), *(char *)ptr
);
175 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.value=\'%c\'\">",
176 make_parm_name(parm
->label
),(char)(parm
->def
.cvalue
));
181 printf("<input type=text size=40 name=\"parm_%s\" value=\"%s\">",
182 make_parm_name(parm
->label
), *(char **)ptr
);
183 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.value=\'%s\'\">",
184 make_parm_name(parm
->label
),fix_backslash((char *)(parm
->def
.svalue
)));
189 printf("<input type=text size=40 name=\"parm_%s\" value=\"%s\">",
190 make_parm_name(parm
->label
), (char *)ptr
);
191 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.value=\'%s\'\">",
192 make_parm_name(parm
->label
),fix_backslash((char *)(parm
->def
.svalue
)));
196 printf("<select name=\"parm_%s\">",make_parm_name(parm
->label
));
197 printf("<option %s>Yes", (*(BOOL
*)ptr
)?"selected":"");
198 printf("<option %s>No", (*(BOOL
*)ptr
)?"":"selected");
200 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.selectedIndex=\'%d\'\">",
201 make_parm_name(parm
->label
),(BOOL
)(parm
->def
.bvalue
)?0:1);
205 printf("<select name=\"parm_%s\">",make_parm_name(parm
->label
));
206 printf("<option %s>Yes", (*(BOOL
*)ptr
)?"":"selected");
207 printf("<option %s>No", (*(BOOL
*)ptr
)?"selected":"");
209 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.selectedIndex=\'%d\'\">",
210 make_parm_name(parm
->label
),(BOOL
)(parm
->def
.bvalue
)?1:0);
214 printf("<input type=text size=8 name=\"parm_%s\" value=%d>", make_parm_name(parm
->label
), *(int *)ptr
);
215 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.value=\'%d\'\">",
216 make_parm_name(parm
->label
),(int)(parm
->def
.ivalue
));
220 printf("<input type=text size=8 name=\"parm_%s\" value=0%o>", make_parm_name(parm
->label
), *(int *)ptr
);
221 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.value=\'0%o\'\">",
222 make_parm_name(parm
->label
),(int)(parm
->def
.ivalue
));
226 printf("<select name=\"parm_%s\">",make_parm_name(parm
->label
));
227 for (i
=0;parm
->enum_list
[i
].name
;i
++)
228 printf("<option %s>%s",(*(int *)ptr
)==parm
->enum_list
[i
].value
?"selected":"",parm
->enum_list
[i
].name
);
230 printf("<input type=button value=\"Set Default\" onClick=\"swatform.parm_%s.selectedIndex=\'%d\'\">",
231 make_parm_name(parm
->label
),enum_index((int)(parm
->def
.ivalue
),parm
->enum_list
));
236 printf("</td></tr>\n");
239 /****************************************************************************
240 display a set of parameters for a service
241 ****************************************************************************/
242 static void show_parameters(int snum
, int allparameters
, int advanced
, int printers
)
245 struct parm_struct
*parm
;
246 char *heading
= NULL
;
247 char *last_heading
= NULL
;
249 while ((parm
= lp_next_parameter(snum
, &i
, allparameters
))) {
250 if (snum
< 0 && parm
->class == P_LOCAL
&& !(parm
->flags
& FLAG_GLOBAL
))
252 if (parm
->class == P_SEPARATOR
) {
253 heading
= parm
->label
;
256 if (parm
->flags
& FLAG_HIDE
) continue;
258 if (printers
& !(parm
->flags
& FLAG_PRINT
)) continue;
259 if (!printers
& !(parm
->flags
& FLAG_SHARE
)) continue;
262 if (!(parm
->flags
& FLAG_BASIC
)) {
263 void *ptr
= parm
->ptr
;
265 if (parm
->class == P_LOCAL
&& snum
>= 0) {
266 ptr
= lp_local_ptr(snum
, ptr
);
269 switch (parm
->type
) {
271 if (*(char *)ptr
== (char)(parm
->def
.cvalue
)) continue;
276 if (!strcmp(*(char **)ptr
,(char *)(parm
->def
.svalue
))) continue;
281 if (!strcmp((char *)ptr
,(char *)(parm
->def
.svalue
))) continue;
286 if (*(BOOL
*)ptr
== (BOOL
)(parm
->def
.bvalue
)) continue;
291 if (*(int *)ptr
== (int)(parm
->def
.ivalue
)) continue;
296 if (*(int *)ptr
== (int)(parm
->def
.ivalue
)) continue;
302 if (printers
&& !(parm
->flags
& FLAG_PRINT
)) continue;
304 if (heading
&& heading
!= last_heading
) {
305 printf("<tr><td></td></tr><tr><td><b><u>%s</u></b></td></tr>\n", heading
);
306 last_heading
= heading
;
308 show_parameter(snum
, parm
);
312 /****************************************************************************
313 load the smb.conf file into loadparm.
314 ****************************************************************************/
315 static BOOL
load_config(BOOL save_def
)
317 lp_resetnumservices();
318 return lp_load(servicesf
,False
,save_def
,False
);
321 /****************************************************************************
323 ****************************************************************************/
324 static void write_config(FILE *f
, BOOL show_defaults
)
326 fprintf(f
, "# Samba config file created using SWAT\n");
327 fprintf(f
, "# from %s (%s)\n", cgi_remote_host(), cgi_remote_addr());
328 fprintf(f
, "# Date: %s\n\n", timestring());
330 lp_dump(f
, show_defaults
, iNumNonAutoPrintServices
);
333 /****************************************************************************
334 save and reoad the smb.conf config file
335 ****************************************************************************/
336 static int save_reload(int snum
)
340 f
= sys_fopen(servicesf
,"w");
342 printf("failed to open %s for writing\n", servicesf
);
346 write_config(f
, False
);
348 lp_dump_one(f
, False
, snum
);
353 if (!load_config(False
)) {
354 printf("Can't reload %s\n", servicesf
);
357 iNumNonAutoPrintServices
= lp_numservices();
363 /****************************************************************************
365 ****************************************************************************/
366 static void commit_parameter(int snum
, struct parm_struct
*parm
, char *v
)
371 if (snum
< 0 && parm
->class == P_LOCAL
) {
372 /* this handles the case where we are changing a local
373 variable globally. We need to change the parameter in
374 all shares where it is currently set to the default */
375 for (i
=0;i
<lp_numservices();i
++) {
376 s
= lp_servicename(i
);
377 if (s
&& (*s
) && lp_is_default(i
, parm
)) {
378 lp_do_parameter(i
, parm
->label
, v
);
383 lp_do_parameter(snum
, parm
->label
, v
);
386 /****************************************************************************
387 commit a set of parameters for a service
388 ****************************************************************************/
389 static void commit_parameters(int snum
)
392 struct parm_struct
*parm
;
396 while ((parm
= lp_next_parameter(snum
, &i
, 1))) {
397 slprintf(label
, sizeof(label
)-1, "parm_%s", make_parm_name(parm
->label
));
398 if ((v
= cgi_variable(label
))) {
399 if (parm
->flags
& FLAG_HIDE
) continue;
400 commit_parameter(snum
, parm
, v
);
405 /****************************************************************************
406 spit out the html for a link with an image
407 ****************************************************************************/
408 static void image_link(char *name
,char *hlink
, char *src
)
410 printf("<A HREF=\"%s/%s\"><img src=\"/swat/%s\" alt=\"%s\"></A>\n",
411 cgi_baseurl(), hlink
, src
, name
);
414 /****************************************************************************
415 display the main navigation controls at the top of each page along
417 ****************************************************************************/
418 static void show_main_buttons(void)
420 image_link("Home", "", "images/home.gif");
421 if (have_read_access
) {
422 image_link("Globals", "globals", "images/globals.gif");
423 image_link("Shares", "shares", "images/shares.gif");
424 image_link("Printers", "printers", "images/printers.gif");
425 image_link("Status", "status", "images/status.gif");
426 image_link("View Config", "viewconfig","images/viewconfig.gif");
428 image_link("Password Management", "passwd", "images/passwd.gif");
433 /****************************************************************************
434 display a welcome page
435 ****************************************************************************/
436 static void welcome_page(void)
438 include_html("help/welcome.html");
441 /****************************************************************************
442 display the current smb.conf
443 ****************************************************************************/
444 static void viewconfig_page(void)
448 if (cgi_variable("full_view")) {
452 printf("<H2>Current Config</H2>\n");
453 printf("<form method=post>\n");
456 printf("<input type=submit name=\"normal_view\" value=\"Normal View\">\n");
458 printf("<input type=submit name=\"full_view\" value=\"Full View\">\n");
462 write_config(stdout
, full_view
);
467 /****************************************************************************
468 display a globals editing page
469 ****************************************************************************/
470 static void globals_page(void)
474 printf("<H2>Global Variables</H2>\n");
476 if (cgi_variable("Advanced") && !cgi_variable("Basic"))
479 if (cgi_variable("Commit")) {
480 commit_parameters(GLOBALS_SNUM
);
484 printf("<FORM name=\"swatform\" method=post>\n");
486 if (have_write_access
) {
487 printf("<input type=submit name=\"Commit\" value=\"Commit Changes\">\n");
490 printf("<input type=reset name=\"Reset Values\" value=\"Reset Values\">\n");
492 printf("<input type=submit name=\"Advanced\" value=\"Advanced View\">\n");
494 printf("<input type=submit name=\"Basic\" value=\"Basic View\">\n");
499 show_parameters(GLOBALS_SNUM
, 1, advanced
, 0);
500 printf("</table>\n");
503 printf("<input type=hidden name=\"Advanced\" value=1>\n");
509 /****************************************************************************
510 display a shares editing page
511 ****************************************************************************/
512 static void shares_page(void)
514 char *share
= cgi_variable("share");
521 snum
= lp_servicenumber(share
);
523 printf("<H2>Share Parameters</H2>\n");
525 if (cgi_variable("Advanced") && !cgi_variable("Basic"))
528 if (cgi_variable("Commit") && snum
>= 0) {
529 commit_parameters(snum
);
533 if (cgi_variable("Delete") && snum
>= 0) {
534 lp_remove_service(snum
);
540 if (cgi_variable("createshare") && (share
=cgi_variable("newshare"))) {
542 lp_copy_service(GLOBALS_SNUM
, share
);
543 iNumNonAutoPrintServices
= lp_numservices();
545 snum
= lp_servicenumber(share
);
548 printf("<FORM name=\"swatform\" method=post>\n");
552 printf("<td><input type=submit name=selectshare value=\"Choose Share\"></td>\n");
553 printf("<td><select name=share>\n");
555 printf("<option value=\" \"> \n");
556 for (i
=0;i
<lp_numservices();i
++) {
557 s
= lp_servicename(i
);
558 if (s
&& (*s
) && strcmp(s
,"IPC$") && !lp_print_ok(i
)) {
559 printf("<option %s value=\"%s\">%s\n",
560 (share
&& strcmp(share
,s
)==0)?"SELECTED":"",
564 printf("</select></td>\n");
565 if (have_write_access
) {
566 printf("<td><input type=submit name=\"Delete\" value=\"Delete Share\"></td>\n");
571 if (have_write_access
) {
573 printf("<td><input type=submit name=createshare value=\"Create Share\"></td>\n");
574 printf("<td><input type=text size=30 name=newshare></td></tr>\n");
580 if (have_write_access
) {
581 printf("<input type=submit name=\"Commit\" value=\"Commit Changes\">\n");
584 printf("<input type=reset name=\"Reset Values\" value=\"Reset Values\">\n");
586 printf("<input type=submit name=\"Advanced\" value=\"Advanced View\">\n");
588 printf("<input type=submit name=\"Basic\" value=\"Basic View\">\n");
595 show_parameters(snum
, 1, advanced
, 0);
596 printf("</table>\n");
600 printf("<input type=hidden name=\"Advanced\" value=1>\n");
606 /*************************************************************
607 change a password either locally or remotely
608 *************************************************************/
609 static BOOL
change_password(const char *remote_machine
, char *user_name
,
610 char *old_passwd
, char *new_passwd
,
611 BOOL add_user
, BOOL enable_user
, BOOL disable_user
)
618 printf("password change in demo mode rejected\n<p>");
622 if (remote_machine
!= NULL
) {
623 ret
= remote_password_change(remote_machine
, user_name
, old_passwd
,
624 new_passwd
, err_str
, sizeof(err_str
));
626 printf("%s\n<p>", err_str
);
630 if(!initialize_password_db()) {
631 printf("Can't setup password database vectors.\n<p>");
635 ret
= local_password_change(user_name
, False
, add_user
, enable_user
,
636 disable_user
, False
, new_passwd
, err_str
, sizeof(err_str
),
637 msg_str
, sizeof(msg_str
));
640 printf("%s\n<p>", msg_str
);
642 printf("%s\n<p>", err_str
);
647 /****************************************************************************
648 do the stuff required to add or change a password
649 ****************************************************************************/
650 static void chg_passwd(void)
655 /* Make sure users name has been specified */
656 if (strlen(cgi_variable(SWAT_USER
)) == 0) {
657 printf("<p> Must specify \"User Name\" \n");
662 * smbpasswd doesn't require anything but the users name to disable or enable the user,
663 * so if that's what we're doing, skip the rest of the checks
665 if (!cgi_variable(DISABLE_USER_FLAG
) && !cgi_variable(ENABLE_USER_FLAG
)) {
668 * If current user is not root, make sure old password has been specified
669 * If REMOTE change, even root must provide old password
671 if (((!am_root()) && (strlen( cgi_variable(OLD_PSWD
)) <= 0)) ||
672 ((cgi_variable(CHG_R_PASSWD_FLAG
)) && (strlen( cgi_variable(OLD_PSWD
)) <= 0))) {
673 printf("<p> Must specify \"Old Password\" \n");
677 /* If changing a users password on a remote hosts we have to know what host */
678 if ((cgi_variable(CHG_R_PASSWD_FLAG
)) && (strlen( cgi_variable(RHOST
)) <= 0)) {
679 printf("<p> Must specify \"Remote Machine\" \n");
683 /* Make sure new passwords have been specified */
684 if ((strlen( cgi_variable(NEW_PSWD
)) <= 0) ||
685 (strlen( cgi_variable(NEW2_PSWD
)) <= 0)) {
686 printf("<p> Must specify \"New, and Re-typed Passwords\" \n");
690 /* Make sure new passwords was typed correctly twice */
691 if (strcmp(cgi_variable(NEW_PSWD
), cgi_variable(NEW2_PSWD
)) != 0) {
692 printf("<p> Re-typed password didn't match new password\n");
697 if (cgi_variable(CHG_R_PASSWD_FLAG
)) {
698 host
= cgi_variable(RHOST
);
699 } else if (am_root()) {
704 rslt
= change_password(host
,
705 cgi_variable(SWAT_USER
),
706 cgi_variable(OLD_PSWD
), cgi_variable(NEW_PSWD
),
707 cgi_variable(ADD_USER_FLAG
)? True
: False
,
708 cgi_variable(ENABLE_USER_FLAG
)? True
: False
,
709 cgi_variable(DISABLE_USER_FLAG
)? True
: False
);
713 printf("<p> The passwd for '%s' has been changed. \n", cgi_variable(SWAT_USER
));
715 printf("<p> The passwd for '%s' has NOT been changed. \n",cgi_variable(SWAT_USER
));
721 /****************************************************************************
722 display a password editing page
723 ****************************************************************************/
724 static void passwd_page(void)
726 char *new_name
= cgi_user_name();
729 * After the first time through here be nice. If the user
730 * changed the User box text to another users name, remember it.
732 if (cgi_variable(SWAT_USER
)) {
733 new_name
= cgi_variable(SWAT_USER
);
736 if (!new_name
) new_name
= "";
738 printf("<H2>Server Password Management</H2>\n");
740 printf("<FORM name=\"swatform\" method=post>\n");
745 * Create all the dialog boxes for data collection
747 printf("<tr><td> User Name : </td>\n");
748 printf("<td><input type=text size=30 name=%s value=%s></td></tr> \n", SWAT_USER
, new_name
);
750 printf("<tr><td> Old Password : </td>\n");
751 printf("<td><input type=password size=30 name=%s></td></tr> \n",OLD_PSWD
);
753 printf("<tr><td> New Password : </td>\n");
754 printf("<td><input type=password size=30 name=%s></td></tr>\n",NEW_PSWD
);
755 printf("<tr><td> Re-type New Password : </td>\n");
756 printf("<td><input type=password size=30 name=%s></td></tr>\n",NEW2_PSWD
);
757 printf("</table>\n");
760 * Create all the control buttons for requesting action
762 printf("<input type=submit name=%s value=\"Change Password\">\n",
764 if (demo_mode
|| am_root()) {
765 printf("<input type=submit name=%s value=\"Add New User\">\n",
767 printf("<input type=submit name=%s value=\"Disable User\">\n",
769 printf("<input type=submit name=%s value=\"Enable User\">\n",
772 printf("<p></FORM>\n");
775 * Do some work if change, add, disable or enable was
776 * requested. It could be this is the first time through this
777 * code, so there isn't anything to do. */
778 if ((cgi_variable(CHG_S_PASSWD_FLAG
)) || (cgi_variable(ADD_USER_FLAG
)) ||
779 (cgi_variable(DISABLE_USER_FLAG
)) || (cgi_variable(ENABLE_USER_FLAG
))) {
783 printf("<H2>Client/Server Password Management</H2>\n");
785 printf("<FORM name=\"swatform\" method=post>\n");
790 * Create all the dialog boxes for data collection
792 printf("<tr><td> User Name : </td>\n");
793 printf("<td><input type=text size=30 name=%s value=%s></td></tr>\n",SWAT_USER
, new_name
);
794 printf("<tr><td> Old Password : </td>\n");
795 printf("<td><input type=password size=30 name=%s></td></tr>\n",OLD_PSWD
);
796 printf("<tr><td> New Password : </td>\n");
797 printf("<td><input type=password size=30 name=%s></td></tr>\n",NEW_PSWD
);
798 printf("<tr><td> Re-type New Password : </td>\n");
799 printf("<td><input type=password size=30 name=%s></td></tr>\n",NEW2_PSWD
);
800 printf("<tr><td> Remote Machine : </td>\n");
801 printf("<td><input type=password size=30 name=%s></td></tr>\n",RHOST
);
806 * Create all the control buttons for requesting action
808 printf("<input type=submit name=%s value=\"Change Password\">",
811 printf("<p></FORM>\n");
814 * Do some work if a request has been made to change the
815 * password somewhere other than the server. It could be this
816 * is the first time through this code, so there isn't
818 if (cgi_variable(CHG_R_PASSWD_FLAG
)) {
824 /****************************************************************************
825 display a printers editing page
826 ****************************************************************************/
827 static void printers_page(void)
829 char *share
= cgi_variable("share");
836 snum
= lp_servicenumber(share
);
838 printf("<H2>Printer Parameters</H2>\n");
840 printf("<H3>Important Note:</H3>\n");
841 printf("Printer names marked with [*] in the Choose Printer drop-down box ");
842 printf("are autoloaded printers from ");
843 printf("<A HREF=\"/swat/help/smb.conf.5.html#printcapname\" target=\"docs\">Printcap Name</A>.\n");
844 printf("Attempting to delete these printers from SWAT will have no effect.\n");
846 if (cgi_variable("Advanced") && !cgi_variable("Basic"))
849 if (cgi_variable("Commit") && snum
>= 0) {
850 commit_parameters(snum
);
851 if (snum
>= iNumNonAutoPrintServices
)
857 if (cgi_variable("Delete") && snum
>= 0) {
858 lp_remove_service(snum
);
864 if (cgi_variable("createshare") && (share
=cgi_variable("newshare"))) {
866 lp_copy_service(GLOBALS_SNUM
, share
);
867 iNumNonAutoPrintServices
= lp_numservices();
868 snum
= lp_servicenumber(share
);
869 lp_do_parameter(snum
, "print ok", "Yes");
871 snum
= lp_servicenumber(share
);
874 printf("<FORM name=\"swatform\" method=post>\n");
877 printf("<tr><td><input type=submit name=selectshare value=\"Choose Printer\"></td>\n");
878 printf("<td><select name=share>\n");
879 if (snum
< 0 || !lp_print_ok(snum
))
880 printf("<option value=\" \"> \n");
881 for (i
=0;i
<lp_numservices();i
++) {
882 s
= lp_servicename(i
);
883 if (s
&& (*s
) && strcmp(s
,"IPC$") && lp_print_ok(i
)) {
884 if (i
>= iNumNonAutoPrintServices
)
885 printf("<option %s value=\"%s\">[*]%s\n",
886 (share
&& strcmp(share
,s
)==0)?"SELECTED":"",
889 printf("<option %s value=\"%s\">%s\n",
890 (share
&& strcmp(share
,s
)==0)?"SELECTED":"",
894 printf("</select></td>");
895 if (have_write_access
) {
896 printf("<td><input type=submit name=\"Delete\" value=\"Delete Printer\"></td>\n");
899 printf("</table>\n");
901 if (have_write_access
) {
903 printf("<tr><td><input type=submit name=createshare value=\"Create Printer\"></td>\n");
904 printf("<td><input type=text size=30 name=newshare></td></tr>\n");
910 if (have_write_access
) {
911 printf("<input type=submit name=\"Commit\" value=\"Commit Changes\">\n");
913 printf("<input type=reset name=\"Reset Values\" value=\"Reset Values\">\n");
915 printf("<input type=submit name=\"Advanced\" value=\"Advanced View\">\n");
917 printf("<input type=submit name=\"Basic\" value=\"Basic View\">\n");
924 show_parameters(snum
, 1, advanced
, 1);
925 printf("</table>\n");
929 printf("<input type=hidden name=\"Advanced\" value=1>\n");
935 /****************************************************************************
937 ****************************************************************************/
938 int main(int argc
, char *argv
[])
946 #if defined(HAVE_SET_AUTH_PARAMETERS)
947 set_auth_parameters(argc
, argv
);
948 #endif /* HAVE_SET_AUTH_PARAMETERS */
950 /* just in case it goes wild ... */
953 dbf
= sys_fopen("/dev/null", "w");
955 if (!dbf
) dbf
= stderr
;
957 while ((opt
= getopt(argc
, argv
,"s:a")) != EOF
) {
960 pstrcpy(servicesf
,optarg
);
968 charset_initialise();
970 iNumNonAutoPrintServices
= lp_numservices();
973 cgi_setup(SWATDIR
, !demo_mode
);
977 cgi_load_variables(NULL
);
979 if (!file_exist(servicesf
, NULL
)) {
980 have_read_access
= True
;
981 have_write_access
= True
;
983 /* check if the authenticated user has write access - if not then
984 don't show write options */
985 have_write_access
= (access(servicesf
,W_OK
) == 0);
987 /* if the user doesn't have read access to smb.conf then
988 don't let them view it */
989 have_read_access
= (access(servicesf
,R_OK
) == 0);
996 page
= cgi_pathinfo();
998 /* Root gets full functionality */
999 if (have_read_access
&& strcmp(page
, "globals")==0) {
1001 } else if (have_read_access
&& strcmp(page
,"shares")==0) {
1003 } else if (have_read_access
&& strcmp(page
,"printers")==0) {
1005 } else if (have_read_access
&& strcmp(page
,"status")==0) {
1007 } else if (have_read_access
&& strcmp(page
,"viewconfig")==0) {
1009 } else if (strcmp(page
,"passwd")==0) {