added some QPATHINFO and QFILEINFO tests into smbtorture.
[Samba.git] / source / wsmbconf.c
blob8abdd6d3985a779ee0eed53f92d2747a0c6411e4
1 /*
2 Unix SMB/Netbios implementation.
3 Version 1.9.
4 html smb.conf editing - prototype only
5 Copyright (C) Andrew Tridgell 1997
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.
22 #ifdef SYSLOG
23 #undef SYSLOG
24 #endif
26 #include "includes.h"
27 #include "smb.h"
29 #define SDEFAULTS "Service defaults"
30 #define SGLOBAL "Global Parameters"
31 #define GLOBALS_SNUM -2
32 #define DEFAULTS_SNUM -1
34 static pstring servicesf = CONFIGFILE;
37 /* start the page with standard stuff */
38 static void print_header(void)
40 printf("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n");
41 printf("<HTML>\n<HEAD>\n<TITLE>smb.conf</TITLE>\n</HEAD>\n<BODY>\n\n");
45 /* finish off the page */
46 static void print_footer(void)
48 printf("\n</BODY>\n</HTML>\n");
51 /* display a servce, ready for editing */
52 static void show_service(int snum, int allparameters)
54 int i = 0;
55 pstring label, value;
56 char *sname;
58 if (snum == GLOBALS_SNUM)
59 sname = SGLOBAL;
60 else if (snum == DEFAULTS_SNUM)
61 sname = SDEFAULTS;
62 else sname = lp_servicename(snum);
64 printf("\n<p><table border=0>\n<tr>\n<td></td><td>\n\n");
65 printf("<form method=POST>\n");
66 printf("<H3>%s</H3>\n", sname);
67 printf("<input type=hidden name=service value=\"%s\">\n", sname);
68 printf("<input type=submit name=request value=Change>\n");
69 printf("<input type=submit name=request value=Rename>\n");
70 printf("<input type=submit name=request value=Copy>\n");
71 printf("<input type=submit name=request value=Remove>\n");
72 printf("<br><input name=newvalue><br>\n");
73 printf("<select name=parameter size=5>\n");
75 while (lp_next_parameter(snum, &i, label, value, allparameters)) {
76 printf("<option value=\"%s\">%s = %s\n",
77 label, label, value);
80 printf("</select>\n");
81 printf("</form>\n</td>\n</tr>\n</table>\n");
83 printf("<p>\n");
87 /* loop over all services, displaying them one after the other */
88 static void show_services(void)
90 int i;
91 int n;
92 int allparameters = cgi_boolean("allparameters", 0);
94 printf("<FORM METHOD=POST>\n");
95 printf("<p>Show all parameters?\n");
96 printf("<INPUT NAME=allparameters TYPE=checkbox VALUE=1 %s>\n",
97 allparameters?"CHECKED":"");
99 printf("<INPUT TYPE=submit NAME=reload VALUE=Reload>\n");
101 printf("</FORM>\n");
103 n = lp_numservices();
105 show_service(GLOBALS_SNUM, allparameters);
106 show_service(DEFAULTS_SNUM, allparameters);
108 for (i=0;i<n;i++)
109 if (VALID_SNUM(i))
110 show_service(i, allparameters);
114 /* load the smb.conf file into loadparm. */
115 static int load_config(void)
117 setuid(0);
118 if (!lp_load(servicesf,False)) {
119 printf("<b>Can't load %s - using defaults</b><p>\n",
120 servicesf);
122 return 1;
126 static int save_reload(void)
128 FILE *f;
130 f = fopen(servicesf,"w");
131 if (!f) {
132 printf("failed to open %s for writing\n", servicesf);
133 return 0;
136 fprintf(f, "# Samba config file created using wsmbconf\n");
138 lp_dump(f);
140 fclose(f);
142 lp_killunused(NULL);
144 if (!lp_load(servicesf,False)) {
145 printf("Can't reload %s\n", servicesf);
146 return 0;
149 return 1;
152 static void process_requests(void)
154 char *req = cgi_variable("request");
155 char *newvalue = cgi_variable("newvalue");
156 char *parameter = cgi_variable("parameter");
157 char *service = cgi_variable("service");
158 int snum=0;
160 if (!req) return;
162 if (service) {
163 /* work out what service it is */
164 if (strcmp(service,SGLOBAL) == 0) {
165 snum = GLOBALS_SNUM;
166 } else if (strcmp(service,SDEFAULTS) == 0) {
167 snum = DEFAULTS_SNUM;
168 } else {
169 snum = lp_servicenumber(service);
170 if (snum < 0) return;
174 if (!newvalue)
175 newvalue = "";
177 if (strcmp(req,"Change") == 0) {
178 /* change the value of a parameter */
179 if (!parameter || !service) return;
181 lp_do_parameter(snum, parameter, newvalue);
182 } else if (strcmp(req,"Rename") == 0) {
183 /* rename a service */
184 if (!newvalue || !service) return;
186 lp_rename_service(snum, newvalue);
187 } else if (strcmp(req,"Remove") == 0) {
188 /* remove a service */
189 if (!service) return;
191 lp_remove_service(snum);
192 } else if (strcmp(req,"Copy") == 0) {
193 /* copy a service */
194 if (!service || !newvalue) return;
196 lp_copy_service(snum, newvalue);
199 save_reload();
203 int main(int argc, char *argv[])
205 extern char *optarg;
206 extern int optind;
207 extern FILE *dbf;
208 int opt;
210 dbf = fopen("/dev/null", "w");
212 if (!dbf) dbf = stderr;
214 cgi_setup(WEB_ROOT);
217 while ((opt = getopt(argc, argv,"s:")) != EOF) {
218 switch (opt) {
219 case 's':
220 pstrcpy(servicesf,optarg);
221 break;
226 print_header();
228 charset_initialise();
230 if (load_config()) {
231 cgi_load_variables(NULL);
232 process_requests();
233 show_services();
235 print_footer();
236 return 0;