2
Unix SMB/CIFS implementation.
3
Samba Web Administration Tool
5
Copyright (C) Andrew Tridgell 1997-2002
6
Copyright (C) John H Terpstra 2002
8
This program is free software; you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation; either version 2 of the License, or
11
(at your option) any later version.
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU General Public License for more details.
18
You should have received a copy of the GNU General Public License
19
along with this program; if not, write to the Free Software
20
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24
* @defgroup swat SWAT - Samba Web Administration Tool
28
* @brief Samba Web Administration Tool.
32
#include "web/swat_proto.h"
34
static BOOL demo_mode = False;
35
static BOOL passwd_only = False;
36
static BOOL have_write_access = False;
37
static BOOL have_read_access = False;
38
static int iNumNonAutoPrintServices = 0;
41
* Password Management Globals
43
#define SWAT_USER "username"
44
#define OLD_PSWD "old_passwd"
45
#define NEW_PSWD "new_passwd"
46
#define NEW2_PSWD "new2_passwd"
47
#define CHG_S_PASSWD_FLAG "chg_s_passwd_flag"
48
#define CHG_R_PASSWD_FLAG "chg_r_passwd_flag"
49
#define ADD_USER_FLAG "add_user_flag"
50
#define DELETE_USER_FLAG "delete_user_flag"
51
#define DISABLE_USER_FLAG "disable_user_flag"
52
#define ENABLE_USER_FLAG "enable_user_flag"
53
#define RHOST "remote_host"
56
/****************************************************************************
57
****************************************************************************/
58
static int enum_index(int value, const struct enum_list *enumlist)
61
for (i=0;enumlist[i].name;i++)
62
if (value == enumlist[i].value) break;
66
static char *fix_backslash(const char *str)
68
static char newstring[1024];
72
if (*str == '\\') {*p++ = '\\';*p++ = '\\';}
80
static char *fix_quotes(const char *str)
82
static pstring newstring;
84
size_t newstring_len = sizeof(newstring);
85
int quote_len = strlen(""");
88
if ( *str == '\"' && (newstring_len - PTR_DIFF(p, newstring) - 1) > quote_len ) {
89
strncpy( p, """, quote_len);
100
static char *stripspaceupper(const char *str)
102
static char newstring[1024];
106
if (*str != ' ') *p++ = toupper_ascii(*str);
113
static char *make_parm_name(const char *label)
115
static char parmname[1024];
119
if (*label == ' ') *p++ = '_';
127
/****************************************************************************
128
include a lump of html in a page
129
****************************************************************************/
130
static int include_html(const char *fname)
136
fd = web_open(fname, O_RDONLY, 0);
139
printf(_("ERROR: Can't open %s"), fname);
144
while ((ret = read(fd, buf, sizeof(buf))) > 0) {
152
/****************************************************************************
153
start the page with standard stuff
154
****************************************************************************/
155
static void print_header(void)
157
if (!cgi_waspost()) {
158
printf("Expires: 0\r\n");
160
printf("Content-type: text/html\r\n\r\n");
162
if (!include_html("include/header.html")) {
163
printf("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n");
164
printf("<HTML>\n<HEAD>\n<TITLE>Samba Web Administration Tool</TITLE>\n</HEAD>\n<BODY background=\"/swat/images/background.jpg\">\n\n");
168
/* *******************************************************************
169
show parameter label with translated name in the following form
170
because showing original and translated label in one line looks
171
too long, and showing translated label only is unusable for
173
-------------------------------
174
HELP security [combo box][button]
176
-------------------------------
177
(capital words are translated by gettext.)
178
if no translation is available, then same form as original is
180
"i18n_translated_parm" class is used to change the color of the
181
translated parameter with CSS.
182
**************************************************************** */
183
static const char* get_parm_translated(
184
const char* pAnchor, const char* pHelp, const char* pLabel)
186
const char* pTranslated = _(pLabel);
187
static pstring output;
188
if(strcmp(pLabel, pTranslated) != 0)
191
"<A HREF=\"/swat/help/manpages/smb.conf.5.html#%s\" target=\"docs\"> %s</A> %s <br><span class=\"i18n_translated_parm\">%s</span>",
192
pAnchor, pHelp, pLabel, pTranslated);
196
"<A HREF=\"/swat/help/manpages/smb.conf.5.html#%s\" target=\"docs\"> %s</A> %s",
197
pAnchor, pHelp, pLabel);
200
/****************************************************************************
202
****************************************************************************/
203
static void print_footer(void)
205
if (!include_html("include/footer.html")) {
206
printf("\n</BODY>\n</HTML>\n");
210
/****************************************************************************
211
display one editable parameter in a form
212
****************************************************************************/
213
static void show_parameter(int snum, struct parm_struct *parm)
216
void *ptr = parm->ptr;
217
char *utf8_s1, *utf8_s2;
219
if (parm->p_class == P_LOCAL && snum >= 0) {
220
ptr = lp_local_ptr(snum, ptr);
223
printf("<tr><td>%s</td><td>", get_parm_translated(stripspaceupper(parm->label), _("Help"), parm->label));
224
switch (parm->type) {
226
printf("<input type=text size=2 name=\"parm_%s\" value=\"%c\">",
227
make_parm_name(parm->label), *(char *)ptr);
228
printf("<input type=button value=\"%s\" onClick=\"swatform.parm_%s.value=\'%c\'\">",
229
_("Set Default"), make_parm_name(parm->label),(char)(parm->def.cvalue));
233
printf("<input type=text size=40 name=\"parm_%s\" value=\"",
234
make_parm_name(parm->label));
235
if ((char ***)ptr && *(char ***)ptr && **(char ***)ptr) {
236
char **list = *(char ***)ptr;
237
for (;*list;list++) {
238
/* enclose in HTML encoded quotes if the string contains a space */
239
if ( strchr_m(*list, ' ') ) {
240
push_utf8_allocate(&utf8_s1, *list);
241
push_utf8_allocate(&utf8_s2, ((*(list+1))?", ":""));
242
printf(""%s"%s", utf8_s1, utf8_s2);
244
push_utf8_allocate(&utf8_s1, *list);
245
push_utf8_allocate(&utf8_s2, ((*(list+1))?", ":""));
246
printf("%s%s", utf8_s1, utf8_s2);
253
printf("<input type=button value=\"%s\" onClick=\"swatform.parm_%s.value=\'",
254
_("Set Default"), make_parm_name(parm->label));
255
if (parm->def.lvalue) {
256
char **list = (char **)(parm->def.lvalue);
257
for (; *list; list++) {
258
/* enclose in HTML encoded quotes if the string contains a space */
259
if ( strchr_m(*list, ' ') )
260
printf(""%s"%s", *list, ((*(list+1))?", ":""));
262
printf("%s%s", *list, ((*(list+1))?", ":""));
270
push_utf8_allocate(&utf8_s1, *(char **)ptr);
271
printf("<input type=text size=40 name=\"parm_%s\" value=\"%s\">",
272
make_parm_name(parm->label), fix_quotes(utf8_s1));
274
printf("<input type=button value=\"%s\" onClick=\"swatform.parm_%s.value=\'%s\'\">",
275
_("Set Default"), make_parm_name(parm->label),fix_backslash((char *)(parm->def.svalue)));
280
push_utf8_allocate(&utf8_s1, (char *)ptr);
281
printf("<input type=text size=40 name=\"parm_%s\" value=\"%s\">",
282
make_parm_name(parm->label), fix_quotes(utf8_s1));
284
printf("<input type=button value=\"%s\" onClick=\"swatform.parm_%s.value=\'%s\'\">",
285
_("Set Default"), make_parm_name(parm->label),fix_backslash((char *)(parm->def.svalue)));
289
printf("<select name=\"parm_%s\">",make_parm_name(parm->label));
290
printf("<option %s>Yes", (*(BOOL *)ptr)?"selected":"");
291
printf("<option %s>No", (*(BOOL *)ptr)?"":"selected");
293
printf("<input type=button value=\"%s\" onClick=\"swatform.parm_%s.selectedIndex=\'%d\'\">",
294
_("Set Default"), make_parm_name(parm->label),(BOOL)(parm->def.bvalue)?0:1);
298
printf("<select name=\"parm_%s\">",make_parm_name(parm->label));
299
printf("<option %s>Yes", (*(BOOL *)ptr)?"":"selected");
300
printf("<option %s>No", (*(BOOL *)ptr)?"selected":"");
302
printf("<input type=button value=\"%s\" onClick=\"swatform.parm_%s.selectedIndex=\'%d\'\">",
303
_("Set Default"), make_parm_name(parm->label),(BOOL)(parm->def.bvalue)?1:0);
307
printf("<input type=text size=8 name=\"parm_%s\" value=\"%d\">", make_parm_name(parm->label), *(int *)ptr);
308
printf("<input type=button value=\"%s\" onClick=\"swatform.parm_%s.value=\'%d\'\">",
309
_("Set Default"), make_parm_name(parm->label),(int)(parm->def.ivalue));
313
printf("<input type=text size=8 name=\"parm_%s\" value=%s>", make_parm_name(parm->label), octal_string(*(int *)ptr));
314
printf("<input type=button value=\"%s\" onClick=\"swatform.parm_%s.value=\'%s\'\">",
315
_("Set Default"), make_parm_name(parm->label),
316
octal_string((int)(parm->def.ivalue)));
320
printf("<select name=\"parm_%s\">",make_parm_name(parm->label));
321
for (i=0;parm->enum_list[i].name;i++) {
322
if (i == 0 || parm->enum_list[i].value != parm->enum_list[i-1].value) {
323
printf("<option %s>%s",(*(int *)ptr)==parm->enum_list[i].value?"selected":"",parm->enum_list[i].name);
327
printf("<input type=button value=\"%s\" onClick=\"swatform.parm_%s.selectedIndex=\'%d\'\">",
328
_("Set Default"), make_parm_name(parm->label),enum_index((int)(parm->def.ivalue),parm->enum_list));
333
printf("</td></tr>\n");
336
/****************************************************************************
337
display a set of parameters for a service
338
****************************************************************************/
339
static void show_parameters(int snum, int allparameters, unsigned int parm_filter, int printers)
342
struct parm_struct *parm;
343
const char *heading = NULL;
344
const char *last_heading = NULL;
346
while ((parm = lp_next_parameter(snum, &i, allparameters))) {
347
if (snum < 0 && parm->p_class == P_LOCAL && !(parm->flags & FLAG_GLOBAL))
349
if (parm->p_class == P_SEPARATOR) {
350
heading = parm->label;
353
if (parm->flags & FLAG_HIDE) continue;
355
if (printers & !(parm->flags & FLAG_PRINT)) continue;
356
if (!printers & !(parm->flags & FLAG_SHARE)) continue;
359
if (!( parm_filter & FLAG_ADVANCED )) {
360
if (!(parm->flags & FLAG_BASIC)) {
361
void *ptr = parm->ptr;
363
if (parm->p_class == P_LOCAL && snum >= 0) {
364
ptr = lp_local_ptr(snum, ptr);
367
switch (parm->type) {
369
if (*(char *)ptr == (char)(parm->def.cvalue)) continue;
373
if (!str_list_compare(*(char ***)ptr, (char **)(parm->def.lvalue))) continue;
378
if (!strcmp(*(char **)ptr,(char *)(parm->def.svalue))) continue;
383
if (!strcmp((char *)ptr,(char *)(parm->def.svalue))) continue;
388
if (*(BOOL *)ptr == (BOOL)(parm->def.bvalue)) continue;
393
if (*(int *)ptr == (int)(parm->def.ivalue)) continue;
398
if (*(int *)ptr == (int)(parm->def.ivalue)) continue;
404
if (printers && !(parm->flags & FLAG_PRINT)) continue;
407
if ((parm_filter & FLAG_WIZARD) && !(parm->flags & FLAG_WIZARD)) continue;
409
if ((parm_filter & FLAG_ADVANCED) && !(parm->flags & FLAG_ADVANCED)) continue;
411
if (heading && heading != last_heading) {
412
printf("<tr><td></td></tr><tr><td><b><u>%s</u></b></td></tr>\n", _(heading));
413
last_heading = heading;
415
show_parameter(snum, parm);
419
/****************************************************************************
420
load the smb.conf file into loadparm.
421
****************************************************************************/
422
static BOOL load_config(BOOL save_def)
424
lp_resetnumservices();
425
return lp_load(dyn_CONFIGFILE,False,save_def,False,True);
428
/****************************************************************************
430
****************************************************************************/
431
static void write_config(FILE *f, BOOL show_defaults)
433
fprintf(f, "# Samba config file created using SWAT\n");
434
fprintf(f, "# from %s (%s)\n", cgi_remote_host(), cgi_remote_addr());
435
fprintf(f, "# Date: %s\n\n", current_timestring(False));
437
lp_dump(f, show_defaults, iNumNonAutoPrintServices);
440
/****************************************************************************
441
save and reload the smb.conf config file
442
****************************************************************************/
443
static int save_reload(int snum)
448
f = sys_fopen(dyn_CONFIGFILE,"w");
450
printf(_("failed to open %s for writing"), dyn_CONFIGFILE);
455
/* just in case they have used the buggy xinetd to create the file */
456
if (fstat(fileno(f), &st) == 0 &&
457
(st.st_mode & S_IWOTH)) {
458
#if defined HAVE_FCHMOD
459
fchmod(fileno(f), S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH);
461
chmod(dyn_CONFIGFILE, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH);
465
write_config(f, False);
467
lp_dump_one(f, False, snum);
472
if (!load_config(False)) {
473
printf(_("Can't reload %s"), dyn_CONFIGFILE);
477
iNumNonAutoPrintServices = lp_numservices();
483
/****************************************************************************
485
****************************************************************************/
486
static void commit_parameter(int snum, struct parm_struct *parm, const char *v)
491
if (snum < 0 && parm->p_class == P_LOCAL) {
492
/* this handles the case where we are changing a local
493
variable globally. We need to change the parameter in
494
all shares where it is currently set to the default */
495
for (i=0;i<lp_numservices();i++) {
496
s = lp_servicename(i);
497
if (s && (*s) && lp_is_default(i, parm)) {
498
lp_do_parameter(i, parm->label, v);
503
lp_do_parameter(snum, parm->label, v);
506
/****************************************************************************
507
commit a set of parameters for a service
508
****************************************************************************/
509
static void commit_parameters(int snum)
512
struct parm_struct *parm;
516
while ((parm = lp_next_parameter(snum, &i, 1))) {
517
slprintf(label, sizeof(label)-1, "parm_%s", make_parm_name(parm->label));
518
if ((v = cgi_variable(label)) != NULL) {
519
if (parm->flags & FLAG_HIDE) continue;
520
commit_parameter(snum, parm, v);
525
/****************************************************************************
526
spit out the html for a link with an image
527
****************************************************************************/
528
static void image_link(const char *name, const char *hlink, const char *src)
530
printf("<A HREF=\"%s/%s\"><img border=\"0\" src=\"/swat/%s\" alt=\"%s\"></A>\n",
531
cgi_baseurl(), hlink, src, name);
534
/****************************************************************************
535
display the main navigation controls at the top of each page along
537
****************************************************************************/
538
static void show_main_buttons(void)
542
if ((p = cgi_user_name()) && strcmp(p, "root")) {
543
printf(_("Logged in as <b>%s</b>"), p);
547
image_link(_("Home"), "", "images/home.gif");
548
if (have_write_access) {
549
image_link(_("Globals"), "globals", "images/globals.gif");
550
image_link(_("Shares"), "shares", "images/shares.gif");
551
image_link(_("Printers"), "printers", "images/printers.gif");
552
image_link(_("Wizard"), "wizard", "images/wizard.gif");
554
/* root always gets all buttons, otherwise look for -P */
555
if ( have_write_access || (!passwd_only && have_read_access) ) {
556
image_link(_("Status"), "status", "images/status.gif");
557
image_link(_("View Config"), "viewconfig", "images/viewconfig.gif");
559
image_link(_("Password Management"), "passwd", "images/passwd.gif");
564
/****************************************************************************
565
* Handle Display/Edit Mode CGI
566
****************************************************************************/
567
static void ViewModeBoxes(int mode)
569
printf("<p>%s: \n", _("Current View Is"));
570
printf("<input type=radio name=\"ViewMode\" value=0 %s>%s\n", ((mode == 0) ? "checked" : ""), _("Basic"));
571
printf("<input type=radio name=\"ViewMode\" value=1 %s>%s\n", ((mode == 1) ? "checked" : ""), _("Advanced"));
572
printf("<br>%s: \n", _("Change View To"));
573
printf("<input type=submit name=\"BasicMode\" value=\"%s\">\n", _("Basic"));
574
printf("<input type=submit name=\"AdvMode\" value=\"%s\">\n", _("Advanced"));
575
printf("</p><br>\n");
578
/****************************************************************************
579
display a welcome page
580
****************************************************************************/
581
static void welcome_page(void)
583
if (file_exist("help/welcome.html", NULL)) {
584
include_html("help/welcome.html");
586
include_html("help/welcome-no-samba-doc.html");
590
/****************************************************************************
591
display the current smb.conf
592
****************************************************************************/
593
static void viewconfig_page(void)
597
if (cgi_variable("full_view")) {
601
printf("<H2>%s</H2>\n", _("Current Config"));
602
printf("<form method=post>\n");
605
printf("<input type=submit name=\"normal_view\" value=\"%s\">\n", _("Normal View"));
607
printf("<input type=submit name=\"full_view\" value=\"%s\">\n", _("Full View"));
611
write_config(stdout, full_view);
616
/****************************************************************************
617
second screen of the wizard ... Fetch Configuration Parameters
618
****************************************************************************/
619
static void wizard_params_page(void)
621
unsigned int parm_filter = FLAG_WIZARD;
623
/* Here we first set and commit all the parameters that were selected
624
in the previous screen. */
626
printf("<H2>%s</H2>\n", _("Wizard Parameter Edit Page"));
628
if (cgi_variable("Commit")) {
629
commit_parameters(GLOBAL_SECTION_SNUM);
633
printf("<form name=\"swatform\" method=post action=wizard_params>\n");
635
if (have_write_access) {
636
printf("<input type=submit name=\"Commit\" value=\"Commit Changes\">\n");
639
printf("<input type=reset name=\"Reset Values\" value=\"Reset\">\n");
643
show_parameters(GLOBAL_SECTION_SNUM, 1, parm_filter, 0);
644
printf("</table>\n");
648
/****************************************************************************
649
Utility to just rewrite the smb.conf file - effectively just cleans it up
650
****************************************************************************/
651
static void rewritecfg_file(void)
653
commit_parameters(GLOBAL_SECTION_SNUM);
655
printf("<H2>%s</H2>\n", _("Note: smb.conf file has been read and rewritten"));
658
/****************************************************************************
659
wizard to create/modify the smb.conf file
660
****************************************************************************/
661
static void wizard_page(void)
663
/* Set some variables to collect data from smb.conf */
670
if (cgi_variable("Rewrite")) {
671
(void) rewritecfg_file();
675
if (cgi_variable("GetWizardParams")){
676
(void) wizard_params_page();
680
if (cgi_variable("Commit")){
681
SerType = atoi(cgi_variable_nonull("ServerType"));
682
winstype = atoi(cgi_variable_nonull("WINSType"));
683
have_home = lp_servicenumber(HOMES_NAME);
684
HomeExpo = atoi(cgi_variable_nonull("HomeExpo"));
686
/* Plain text passwords are too badly broken - use encrypted passwords only */
687
lp_do_parameter( GLOBAL_SECTION_SNUM, "encrypt passwords", "Yes");
691
/* Stand-alone Server */
692
lp_do_parameter( GLOBAL_SECTION_SNUM, "security", "USER" );
693
lp_do_parameter( GLOBAL_SECTION_SNUM, "domain logons", "No" );
697
lp_do_parameter( GLOBAL_SECTION_SNUM, "security", "DOMAIN" );
698
lp_do_parameter( GLOBAL_SECTION_SNUM, "domain logons", "No" );
701
/* Domain Controller */
702
lp_do_parameter( GLOBAL_SECTION_SNUM, "security", "USER" );
703
lp_do_parameter( GLOBAL_SECTION_SNUM, "domain logons", "Yes" );
706
switch ( winstype ) {
708
lp_do_parameter( GLOBAL_SECTION_SNUM, "wins support", "No" );
709
lp_do_parameter( GLOBAL_SECTION_SNUM, "wins server", "" );
712
lp_do_parameter( GLOBAL_SECTION_SNUM, "wins support", "Yes" );
713
lp_do_parameter( GLOBAL_SECTION_SNUM, "wins server", "" );
716
lp_do_parameter( GLOBAL_SECTION_SNUM, "wins support", "No" );
717
lp_do_parameter( GLOBAL_SECTION_SNUM, "wins server", cgi_variable_nonull("WINSAddr"));
721
/* Have to create Homes share? */
722
if ((HomeExpo == 1) && (have_home == -1)) {
725
pstrcpy(unix_share,HOMES_NAME);
727
lp_copy_service(GLOBAL_SECTION_SNUM, unix_share);
728
iNumNonAutoPrintServices = lp_numservices();
729
have_home = lp_servicenumber(HOMES_NAME);
730
lp_do_parameter( have_home, "read only", "No");
731
lp_do_parameter( have_home, "valid users", "%S");
732
lp_do_parameter( have_home, "browseable", "No");
733
commit_parameters(have_home);
736
/* Need to Delete Homes share? */
737
if ((HomeExpo == 0) && (have_home != -1)) {
738
lp_remove_service(have_home);
742
commit_parameters(GLOBAL_SECTION_SNUM);
747
/* Now determine smb.conf WINS settings */
748
if (lp_wins_support())
750
if (lp_wins_server_list() && strlen(*lp_wins_server_list()))
754
/* Do we have a homes share? */
755
have_home = lp_servicenumber(HOMES_NAME);
757
if ((winstype == 2) && lp_wins_support())
760
role = lp_server_role();
763
printf("<H2>%s</H2>\n", _("Samba Configuration Wizard"));
764
printf("<form method=post action=wizard>\n");
766
if (have_write_access) {
767
printf("%s\n", _("The \"Rewrite smb.conf file\" button will clear the smb.conf file of all default values and of comments."));
768
printf("%s", _("The same will happen if you press the commit button."));
769
printf("<br><br>\n");
771
printf("<input type=submit name=\"Rewrite\" value=\"%s\"> ",_("Rewrite smb.conf file"));
772
printf("<input type=submit name=\"Commit\" value=\"%s\"> ",_("Commit"));
773
printf("<input type=submit name=\"GetWizardParams\" value=\"%s\">", _("Edit Parameter Values"));
774
printf("</center>\n");
778
printf("<center><table border=0>");
779
printf("<tr><td><b>%s: </b></td>\n", _("Server Type"));
780
printf("<td><input type=radio name=\"ServerType\" value=\"0\" %s> %s </td>", ((role == ROLE_STANDALONE) ? "checked" : ""), _("Stand Alone"));
781
printf("<td><input type=radio name=\"ServerType\" value=\"1\" %s> %s </td>", ((role == ROLE_DOMAIN_MEMBER) ? "checked" : ""), _("Domain Member"));
782
printf("<td><input type=radio name=\"ServerType\" value=\"2\" %s> %s </td>", ((role == ROLE_DOMAIN_PDC) ? "checked" : ""), _("Domain Controller"));
784
if (role == ROLE_DOMAIN_BDC) {
785
printf("<tr><td></td><td colspan=3><font color=\"#ff0000\">%s</font></td></tr>\n", _("Unusual Type in smb.conf - Please Select New Mode"));
787
printf("<tr><td><b>%s: </b></td>\n", _("Configure WINS As"));
788
printf("<td><input type=radio name=\"WINSType\" value=\"0\" %s> %s </td>", ((winstype == 0) ? "checked" : ""), _("Not Used"));
789
printf("<td><input type=radio name=\"WINSType\" value=\"1\" %s> %s </td>", ((winstype == 1) ? "checked" : ""), _("Server for client use"));
790
printf("<td><input type=radio name=\"WINSType\" value=\"2\" %s> %s </td>", ((winstype == 2) ? "checked" : ""), _("Client of another WINS server"));
792
printf("<tr><td></td><td></td><td></td><td>%s <input type=text size=\"16\" name=\"WINSAddr\" value=\"", _("Remote WINS Server"));
794
/* Print out the list of wins servers */
795
if(lp_wins_server_list()) {
797
const char **wins_servers = lp_wins_server_list();
798
for(i = 0; wins_servers[i]; i++) printf("%s ", wins_servers[i]);
801
printf("\"></td></tr>\n");
803
printf("<tr><td></td><td colspan=3><font color=\"#ff0000\">%s</font></td></tr>\n", _("Error: WINS Server Mode and WINS Support both set in smb.conf"));
804
printf("<tr><td></td><td colspan=3><font color=\"#ff0000\">%s</font></td></tr>\n", _("Please Select desired WINS mode above."));
806
printf("<tr><td><b>%s: </b></td>\n", _("Expose Home Directories"));
807
printf("<td><input type=radio name=\"HomeExpo\" value=\"1\" %s> Yes</td>", (have_home == -1) ? "" : "checked ");
808
printf("<td><input type=radio name=\"HomeExpo\" value=\"0\" %s> No</td>", (have_home == -1 ) ? "checked" : "");
809
printf("<td></td></tr>\n");
811
/* Enable this when we are ready ....
812
* printf("<tr><td><b>%s: </b></td>\n", _("Is Print Server"));
813
* printf("<td><input type=radio name=\"PtrSvr\" value=\"1\" %s> Yes</td>");
814
* printf("<td><input type=radio name=\"PtrSvr\" value=\"0\" %s> No</td>");
815
* printf("<td></td></tr>\n");
818
printf("</table></center>");
821
printf("%s\n", _("The above configuration options will set multiple parameters and will generally assist with rapid Samba deployment."));
826
/****************************************************************************
827
display a globals editing page
828
****************************************************************************/
829
static void globals_page(void)
831
unsigned int parm_filter = FLAG_BASIC;
834
printf("<H2>%s</H2>\n", _("Global Parameters"));
836
if (cgi_variable("Commit")) {
837
commit_parameters(GLOBAL_SECTION_SNUM);
841
if ( cgi_variable("ViewMode") )
842
mode = atoi(cgi_variable_nonull("ViewMode"));
843
if ( cgi_variable("BasicMode"))
845
if ( cgi_variable("AdvMode"))
848
printf("<form name=\"swatform\" method=post action=globals>\n");
850
ViewModeBoxes( mode );
853
parm_filter = FLAG_BASIC;
856
parm_filter = FLAG_ADVANCED;
860
if (have_write_access) {
861
printf("<input type=submit name=\"Commit\" value=\"%s\">\n",
862
_("Commit Changes"));
865
printf("<input type=reset name=\"Reset Values\" value=\"%s\">\n",
870
show_parameters(GLOBAL_SECTION_SNUM, 1, parm_filter, 0);
871
printf("</table>\n");
875
/****************************************************************************
876
display a shares editing page. share is in unix codepage,
877
****************************************************************************/
878
static void shares_page(void)
880
const char *share = cgi_variable("share");
886
unsigned int parm_filter = FLAG_BASIC;
889
snum = lp_servicenumber(share);
891
printf("<H2>%s</H2>\n", _("Share Parameters"));
893
if (cgi_variable("Commit") && snum >= 0) {
894
commit_parameters(snum);
898
if (cgi_variable("Delete") && snum >= 0) {
899
lp_remove_service(snum);
905
if (cgi_variable("createshare") && (share=cgi_variable("newshare"))) {
907
lp_copy_service(GLOBAL_SECTION_SNUM, share);
908
iNumNonAutoPrintServices = lp_numservices();
910
snum = lp_servicenumber(share);
913
printf("<FORM name=\"swatform\" method=post>\n");
917
if ( cgi_variable("ViewMode") )
918
mode = atoi(cgi_variable_nonull("ViewMode"));
919
if ( cgi_variable("BasicMode"))
921
if ( cgi_variable("AdvMode"))
924
ViewModeBoxes( mode );
927
parm_filter = FLAG_BASIC;
930
parm_filter = FLAG_ADVANCED;
933
printf("<br><tr>\n");
934
printf("<td><input type=submit name=selectshare value=\"%s\"></td>\n", _("Choose Share"));
935
printf("<td><select name=share>\n");
937
printf("<option value=\" \"> \n");
938
for (i=0;i<lp_numservices();i++) {
939
s = lp_servicename(i);
940
if (s && (*s) && strcmp(s,"IPC$") && !lp_print_ok(i)) {
941
push_utf8_allocate(&utf8_s, s);
942
printf("<option %s value=\"%s\">%s\n",
943
(share && strcmp(share,s)==0)?"SELECTED":"",
949
printf("</select></td>\n");
950
if (have_write_access) {
951
printf("<td><input type=submit name=\"Delete\" value=\"%s\"></td>\n", _("Delete Share"));
956
if (have_write_access) {
958
printf("<td><input type=submit name=createshare value=\"%s\"></td>\n", _("Create Share"));
959
printf("<td><input type=text size=30 name=newshare></td></tr>\n");
965
if (have_write_access) {
966
printf("<input type=submit name=\"Commit\" value=\"%s\">\n", _("Commit Changes"));
969
printf("<input type=reset name=\"Reset Values\" value=\"%s\">\n", _("Reset Values"));
975
show_parameters(snum, 1, parm_filter, 0);
976
printf("</table>\n");
982
/*************************************************************
983
change a password either locally or remotely
984
*************************************************************/
985
static BOOL change_password(const char *remote_machine, const char *user_name,
986
const char *old_passwd, const char *new_passwd,
994
printf("%s\n<p>", _("password change in demo mode rejected"));
998
if (remote_machine != NULL) {
999
ret = remote_password_change(remote_machine, user_name, old_passwd,
1000
new_passwd, err_str, sizeof(err_str));
1002
printf("%s\n<p>", err_str);
1003
return NT_STATUS_IS_OK(ret);
1006
if(!initialize_password_db(True)) {
1007
printf("%s\n<p>", _("Can't setup password database vectors."));
1011
ret = local_password_change(user_name, local_flags, new_passwd, err_str, sizeof(err_str),
1012
msg_str, sizeof(msg_str));
1015
printf("%s\n<p>", msg_str);
1017
printf("%s\n<p>", err_str);
1019
return NT_STATUS_IS_OK(ret);
1022
/****************************************************************************
1023
do the stuff required to add or change a password
1024
****************************************************************************/
1025
static void chg_passwd(void)
1029
int local_flags = 0;
1031
/* Make sure users name has been specified */
1032
if (strlen(cgi_variable_nonull(SWAT_USER)) == 0) {
1033
printf("<p>%s\n", _(" Must specify \"User Name\" "));
1038
* smbpasswd doesn't require anything but the users name to delete, disable or enable the user,
1039
* so if that's what we're doing, skip the rest of the checks
1041
if (!cgi_variable(DISABLE_USER_FLAG) && !cgi_variable(ENABLE_USER_FLAG) && !cgi_variable(DELETE_USER_FLAG)) {
1044
* If current user is not root, make sure old password has been specified
1045
* If REMOTE change, even root must provide old password
1047
if (((!am_root()) && (strlen( cgi_variable_nonull(OLD_PSWD)) <= 0)) ||
1048
((cgi_variable(CHG_R_PASSWD_FLAG)) && (strlen( cgi_variable_nonull(OLD_PSWD)) <= 0))) {
1049
printf("<p>%s\n", _(" Must specify \"Old Password\" "));
1053
/* If changing a users password on a remote hosts we have to know what host */
1054
if ((cgi_variable(CHG_R_PASSWD_FLAG)) && (strlen( cgi_variable_nonull(RHOST)) <= 0)) {
1055
printf("<p>%s\n", _(" Must specify \"Remote Machine\" "));
1059
/* Make sure new passwords have been specified */
1060
if ((strlen( cgi_variable_nonull(NEW_PSWD)) <= 0) ||
1061
(strlen( cgi_variable_nonull(NEW2_PSWD)) <= 0)) {
1062
printf("<p>%s\n", _(" Must specify \"New, and Re-typed Passwords\" "));
1066
/* Make sure new passwords was typed correctly twice */
1067
if (strcmp(cgi_variable_nonull(NEW_PSWD), cgi_variable_nonull(NEW2_PSWD)) != 0) {
1068
printf("<p>%s\n", _(" Re-typed password didn't match new password "));
1073
if (cgi_variable(CHG_R_PASSWD_FLAG)) {
1074
host = cgi_variable(RHOST);
1075
} else if (am_root()) {
1082
* Set up the local flags.
1085
local_flags |= (cgi_variable(ADD_USER_FLAG) ? LOCAL_ADD_USER : 0);
1086
local_flags |= (cgi_variable(ADD_USER_FLAG) ? LOCAL_SET_PASSWORD : 0);
1087
local_flags |= (cgi_variable(CHG_S_PASSWD_FLAG) ? LOCAL_SET_PASSWORD : 0);
1088
local_flags |= (cgi_variable(DELETE_USER_FLAG) ? LOCAL_DELETE_USER : 0);
1089
local_flags |= (cgi_variable(ENABLE_USER_FLAG) ? LOCAL_ENABLE_USER : 0);
1090
local_flags |= (cgi_variable(DISABLE_USER_FLAG) ? LOCAL_DISABLE_USER : 0);
1093
rslt = change_password(host,
1094
cgi_variable_nonull(SWAT_USER),
1095
cgi_variable_nonull(OLD_PSWD), cgi_variable_nonull(NEW_PSWD),
1098
if(cgi_variable(CHG_S_PASSWD_FLAG)) {
1101
printf(_(" The passwd for '%s' has been changed."), cgi_variable_nonull(SWAT_USER));
1104
printf(_(" The passwd for '%s' has NOT been changed."), cgi_variable_nonull(SWAT_USER));
1112
/****************************************************************************
1113
display a password editing page
1114
****************************************************************************/
1115
static void passwd_page(void)
1117
const char *new_name = cgi_user_name();
1120
* After the first time through here be nice. If the user
1121
* changed the User box text to another users name, remember it.
1123
if (cgi_variable(SWAT_USER)) {
1124
new_name = cgi_variable_nonull(SWAT_USER);
1127
if (!new_name) new_name = "";
1129
printf("<H2>%s</H2>\n", _("Server Password Management"));
1131
printf("<FORM name=\"swatform\" method=post>\n");
1133
printf("<table>\n");
1136
* Create all the dialog boxes for data collection
1138
printf("<tr><td> %s : </td>\n", _("User Name"));
1139
printf("<td><input type=text size=30 name=%s value=%s></td></tr> \n", SWAT_USER, new_name);
1141
printf("<tr><td> %s : </td>\n", _("Old Password"));
1142
printf("<td><input type=password size=30 name=%s></td></tr> \n",OLD_PSWD);
1144
printf("<tr><td> %s : </td>\n", _("New Password"));
1145
printf("<td><input type=password size=30 name=%s></td></tr>\n",NEW_PSWD);
1146
printf("<tr><td> %s : </td>\n", _("Re-type New Password"));
1147
printf("<td><input type=password size=30 name=%s></td></tr>\n",NEW2_PSWD);
1148
printf("</table>\n");
1151
* Create all the control buttons for requesting action
1153
printf("<input type=submit name=%s value=\"%s\">\n",
1154
CHG_S_PASSWD_FLAG, _("Change Password"));
1155
if (demo_mode || am_root()) {
1156
printf("<input type=submit name=%s value=\"%s\">\n",
1157
ADD_USER_FLAG, _("Add New User"));
1158
printf("<input type=submit name=%s value=\"%s\">\n",
1159
DELETE_USER_FLAG, _("Delete User"));
1160
printf("<input type=submit name=%s value=\"%s\">\n",
1161
DISABLE_USER_FLAG, _("Disable User"));
1162
printf("<input type=submit name=%s value=\"%s\">\n",
1163
ENABLE_USER_FLAG, _("Enable User"));
1165
printf("<p></FORM>\n");
1168
* Do some work if change, add, disable or enable was
1169
* requested. It could be this is the first time through this
1170
* code, so there isn't anything to do. */
1171
if ((cgi_variable(CHG_S_PASSWD_FLAG)) || (cgi_variable(ADD_USER_FLAG)) || (cgi_variable(DELETE_USER_FLAG)) ||
1172
(cgi_variable(DISABLE_USER_FLAG)) || (cgi_variable(ENABLE_USER_FLAG))) {
1176
printf("<H2>%s</H2>\n", _("Client/Server Password Management"));
1178
printf("<FORM name=\"swatform\" method=post>\n");
1180
printf("<table>\n");
1183
* Create all the dialog boxes for data collection
1185
printf("<tr><td> %s : </td>\n", _("User Name"));
1186
printf("<td><input type=text size=30 name=%s value=%s></td></tr>\n",SWAT_USER, new_name);
1187
printf("<tr><td> %s : </td>\n", _("Old Password"));
1188
printf("<td><input type=password size=30 name=%s></td></tr>\n",OLD_PSWD);
1189
printf("<tr><td> %s : </td>\n", _("New Password"));
1190
printf("<td><input type=password size=30 name=%s></td></tr>\n",NEW_PSWD);
1191
printf("<tr><td> %s : </td>\n", _("Re-type New Password"));
1192
printf("<td><input type=password size=30 name=%s></td></tr>\n",NEW2_PSWD);
1193
printf("<tr><td> %s : </td>\n", _("Remote Machine"));
1194
printf("<td><input type=text size=30 name=%s></td></tr>\n",RHOST);
1199
* Create all the control buttons for requesting action
1201
printf("<input type=submit name=%s value=\"%s\">",
1202
CHG_R_PASSWD_FLAG, _("Change Password"));
1204
printf("<p></FORM>\n");
1207
* Do some work if a request has been made to change the
1208
* password somewhere other than the server. It could be this
1209
* is the first time through this code, so there isn't
1210
* anything to do. */
1211
if (cgi_variable(CHG_R_PASSWD_FLAG)) {
1217
/****************************************************************************
1218
display a printers editing page
1219
****************************************************************************/
1220
static void printers_page(void)
1222
const char *share = cgi_variable("share");
1227
unsigned int parm_filter = FLAG_BASIC;
1230
snum = lp_servicenumber(share);
1232
printf("<H2>%s</H2>\n", _("Printer Parameters"));
1234
printf("<H3>%s</H3>\n", _("Important Note:"));
1235
printf(_("Printer names marked with [*] in the Choose Printer drop-down box "));
1236
printf(_("are autoloaded printers from "));
1237
printf("<A HREF=\"/swat/help/smb.conf.5.html#printcapname\" target=\"docs\">%s</A>\n", _("Printcap Name"));
1238
printf("%s\n", _("Attempting to delete these printers from SWAT will have no effect."));
1240
if (cgi_variable("Commit") && snum >= 0) {
1241
commit_parameters(snum);
1242
if (snum >= iNumNonAutoPrintServices)
1248
if (cgi_variable("Delete") && snum >= 0) {
1249
lp_remove_service(snum);
1255
if (cgi_variable("createshare") && (share=cgi_variable("newshare"))) {
1257
lp_copy_service(GLOBAL_SECTION_SNUM, share);
1258
iNumNonAutoPrintServices = lp_numservices();
1259
snum = lp_servicenumber(share);
1260
lp_do_parameter(snum, "print ok", "Yes");
1262
snum = lp_servicenumber(share);
1265
printf("<FORM name=\"swatform\" method=post>\n");
1267
if ( cgi_variable("ViewMode") )
1268
mode = atoi(cgi_variable_nonull("ViewMode"));
1269
if ( cgi_variable("BasicMode"))
1271
if ( cgi_variable("AdvMode"))
1274
ViewModeBoxes( mode );
1277
parm_filter = FLAG_BASIC;
1280
parm_filter = FLAG_ADVANCED;
1283
printf("<table>\n");
1284
printf("<tr><td><input type=submit name=\"selectshare\" value=\"%s\"></td>\n", _("Choose Printer"));
1285
printf("<td><select name=\"share\">\n");
1286
if (snum < 0 || !lp_print_ok(snum))
1287
printf("<option value=\" \"> \n");
1288
for (i=0;i<lp_numservices();i++) {
1289
s = lp_servicename(i);
1290
if (s && (*s) && strcmp(s,"IPC$") && lp_print_ok(i)) {
1291
if (i >= iNumNonAutoPrintServices)
1292
printf("<option %s value=\"%s\">[*]%s\n",
1293
(share && strcmp(share,s)==0)?"SELECTED":"",
1296
printf("<option %s value=\"%s\">%s\n",
1297
(share && strcmp(share,s)==0)?"SELECTED":"",
1301
printf("</select></td>");
1302
if (have_write_access) {
1303
printf("<td><input type=submit name=\"Delete\" value=\"%s\"></td>\n", _("Delete Printer"));
1306
printf("</table>\n");
1308
if (have_write_access) {
1309
printf("<table>\n");
1310
printf("<tr><td><input type=submit name=\"createshare\" value=\"%s\"></td>\n", _("Create Printer"));
1311
printf("<td><input type=text size=30 name=\"newshare\"></td></tr>\n");
1317
if (have_write_access) {
1318
printf("<input type=submit name=\"Commit\" value=\"%s\">\n", _("Commit Changes"));
1320
printf("<input type=reset name=\"Reset Values\" value=\"%s\">\n", _("Reset Values"));
1325
printf("<table>\n");
1326
show_parameters(snum, 1, parm_filter, 1);
1327
printf("</table>\n");
1329
printf("</FORM>\n");
1334
* main function for SWAT.
1336
int main(int argc, char *argv[])
1340
struct poptOption long_options[] = {
1342
{ "disable-authentication", 'a', POPT_ARG_VAL, &demo_mode, True, "Disable authentication (demo mode)" },
1343
{ "password-menu-only", 'P', POPT_ARG_VAL, &passwd_only, True, "Show only change password menu" },
1349
umask(S_IWGRP | S_IWOTH);
1351
#if defined(HAVE_SET_AUTH_PARAMETERS)
1352
set_auth_parameters(argc, argv);
1353
#endif /* HAVE_SET_AUTH_PARAMETERS */
1355
/* just in case it goes wild ... */
1360
/* we don't want any SIGPIPE messages */
1361
BlockSignals(True,SIGPIPE);
1363
dbf = x_fopen("/dev/null", O_WRONLY, 0);
1364
if (!dbf) dbf = x_stderr;
1366
/* we don't want stderr screwing us up */
1368
open("/dev/null", O_WRONLY);
1370
pc = poptGetContext("swat", argc, (const char **) argv, long_options, 0);
1372
/* Parse command line options */
1374
while(poptGetNextOpt(pc) != -1) { }
1376
poptFreeContext(pc);
1380
setup_logging(argv[0],False);
1383
iNumNonAutoPrintServices = lp_numservices();
1386
cgi_setup(dyn_SWATDIR, !demo_mode);
1390
cgi_load_variables();
1392
if (!file_exist(dyn_CONFIGFILE, NULL)) {
1393
have_read_access = True;
1394
have_write_access = True;
1396
/* check if the authenticated user has write access - if not then
1397
don't show write options */
1398
have_write_access = (access(dyn_CONFIGFILE,W_OK) == 0);
1400
/* if the user doesn't have read access to smb.conf then
1401
don't let them view it */
1402
have_read_access = (access(dyn_CONFIGFILE,R_OK) == 0);
1405
show_main_buttons();
1407
page = cgi_pathinfo();
1409
/* Root gets full functionality */
1410
if (have_read_access && strcmp(page, "globals")==0) {
1412
} else if (have_read_access && strcmp(page,"shares")==0) {
1414
} else if (have_read_access && strcmp(page,"printers")==0) {
1416
} else if (have_read_access && strcmp(page,"status")==0) {
1418
} else if (have_read_access && strcmp(page,"viewconfig")==0) {
1420
} else if (strcmp(page,"passwd")==0) {
1422
} else if (have_read_access && strcmp(page,"wizard")==0) {
1424
} else if (have_read_access && strcmp(page,"wizard_params")==0) {
1425
wizard_params_page();
1426
} else if (have_read_access && strcmp(page,"rewritecfg")==0) {