File: /usr/src/linux/net/khttpd/sysctl.c
1 /*
2
3 kHTTPd -- the next generation
4
5 Sysctl interface
6
7 */
8 /****************************************************************
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2, or (at your option)
12 * any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 ****************************************************************/
24
25
26 #include <linux/kernel.h>
27 #include <linux/errno.h>
28 #include <linux/slab.h>
29 #include <linux/net.h>
30 #include <linux/sched.h>
31 #include <linux/skbuff.h>
32 #include <linux/smp_lock.h>
33 #include <linux/sysctl.h>
34 #include <linux/un.h>
35 #include <linux/unistd.h>
36
37 #include <net/ip.h>
38 #include <net/sock.h>
39 #include <net/tcp.h>
40
41 #include <asm/atomic.h>
42 #include <asm/semaphore.h>
43 #include <asm/processor.h>
44 #include <asm/uaccess.h>
45
46 #include <linux/file.h>
47 #include "prototypes.h"
48
49
50
51 char sysctl_khttpd_docroot[200] = "/var/www";
52 int sysctl_khttpd_stop = 0;
53 int sysctl_khttpd_start = 0;
54 int sysctl_khttpd_unload = 0;
55 int sysctl_khttpd_clientport = 80;
56 int sysctl_khttpd_permreq = S_IROTH; /* "other" read-access is required by default*/
57 int sysctl_khttpd_permforbid = S_IFDIR | S_ISVTX | S_IXOTH | S_IXGRP | S_IXUSR;
58 /* forbidden is execute, directory and sticky*/
59 int sysctl_khttpd_logging = 0;
60 int sysctl_khttpd_serverport= 8080;
61
62 char sysctl_khttpd_dynamicstring[200];
63 int sysctl_khttpd_sloppymime= 0;
64 int sysctl_khttpd_threads = 2;
65 int sysctl_khttpd_maxconnect = 1000;
66
67
68 static struct ctl_table_header *khttpd_table_header;
69
70 static int sysctl_SecureString(ctl_table *table, int *name, int nlen,
71 void *oldval, size_t *oldlenp,
72 void *newval, size_t newlen, void **context);
73 static int proc_dosecurestring(ctl_table *table, int write, struct file *filp,
74 void *buffer, size_t *lenp);
75
76
77 static ctl_table khttpd_table[] = {
78 { NET_KHTTPD_DOCROOT,
79 "documentroot",
80 &sysctl_khttpd_docroot,
81 sizeof(sysctl_khttpd_docroot),
82 0644,
83 NULL,
84 proc_dostring,
85 &sysctl_string,
86 NULL,
87 NULL,
88 NULL
89 },
90 { NET_KHTTPD_STOP,
91 "stop",
92 &sysctl_khttpd_stop,
93 sizeof(int),
94 0644,
95 NULL,
96 proc_dointvec,
97 &sysctl_intvec,
98 NULL,
99 NULL,
100 NULL
101 },
102 { NET_KHTTPD_START,
103 "start",
104 &sysctl_khttpd_start,
105 sizeof(int),
106 0644,
107 NULL,
108 proc_dointvec,
109 &sysctl_intvec,
110 NULL,
111 NULL,
112 NULL
113 },
114 { NET_KHTTPD_UNLOAD,
115 "unload",
116 &sysctl_khttpd_unload,
117 sizeof(int),
118 0644,
119 NULL,
120 proc_dointvec,
121 &sysctl_intvec,
122 NULL,
123 NULL,
124 NULL
125 },
126 { NET_KHTTPD_THREADS,
127 "threads",
128 &sysctl_khttpd_threads,
129 sizeof(int),
130 0644,
131 NULL,
132 proc_dointvec,
133 &sysctl_intvec,
134 NULL,
135 NULL,
136 NULL
137 },
138 { NET_KHTTPD_MAXCONNECT,
139 "maxconnect",
140 &sysctl_khttpd_maxconnect,
141 sizeof(int),
142 0644,
143 NULL,
144 proc_dointvec,
145 &sysctl_intvec,
146 NULL,
147 NULL,
148 NULL
149 },
150 { NET_KHTTPD_SLOPPYMIME,
151 "sloppymime",
152 &sysctl_khttpd_sloppymime,
153 sizeof(int),
154 0644,
155 NULL,
156 proc_dointvec,
157 &sysctl_intvec,
158 NULL,
159 NULL,
160 NULL
161 },
162 { NET_KHTTPD_CLIENTPORT,
163 "clientport",
164 &sysctl_khttpd_clientport,
165 sizeof(int),
166 0644,
167 NULL,
168 proc_dointvec,
169 &sysctl_intvec,
170 NULL,
171 NULL,
172 NULL
173 },
174 { NET_KHTTPD_PERMREQ,
175 "perm_required",
176 &sysctl_khttpd_permreq,
177 sizeof(int),
178 0644,
179 NULL,
180 proc_dointvec,
181 &sysctl_intvec,
182 NULL,
183 NULL,
184 NULL
185 },
186 { NET_KHTTPD_PERMFORBID,
187 "perm_forbid",
188 &sysctl_khttpd_permforbid,
189 sizeof(int),
190 0644,
191 NULL,
192 proc_dointvec,
193 &sysctl_intvec,
194 NULL,
195 NULL,
196 NULL
197 },
198 { NET_KHTTPD_LOGGING,
199 "logging",
200 &sysctl_khttpd_logging,
201 sizeof(int),
202 0644,
203 NULL,
204 proc_dointvec,
205 &sysctl_intvec,
206 NULL,
207 NULL,
208 NULL
209 },
210 { NET_KHTTPD_SERVERPORT,
211 "serverport",
212 &sysctl_khttpd_serverport,
213 sizeof(int),
214 0644,
215 NULL,
216 proc_dointvec,
217 &sysctl_intvec,
218 NULL,
219 NULL,
220 NULL
221 },
222 { NET_KHTTPD_DYNAMICSTRING,
223 "dynamic",
224 &sysctl_khttpd_dynamicstring,
225 sizeof(sysctl_khttpd_dynamicstring),
226 0644,
227 NULL,
228 proc_dosecurestring,
229 &sysctl_SecureString,
230 NULL,
231 NULL,
232 NULL
233 },
234 {0,0,0,0,0,0,0,0,0,0,0} };
235
236
237 static ctl_table khttpd_dir_table[] = {
238 {NET_KHTTPD, "khttpd", NULL, 0, 0555, khttpd_table,0,0,0,0,0},
239 {0,0,0,0,0,0,0,0,0,0,0}
240 };
241
242 static ctl_table khttpd_root_table[] = {
243 {CTL_NET, "net", NULL, 0, 0555, khttpd_dir_table,0,0,0,0,0},
244 {0,0,0,0,0,0,0,0,0,0,0}
245 };
246
247
248 void StartSysctl(void)
249 {
250 khttpd_table_header = register_sysctl_table(khttpd_root_table,1);
251 }
252
253
254 void EndSysctl(void)
255 {
256 unregister_sysctl_table(khttpd_table_header);
257 }
258
259 static int proc_dosecurestring(ctl_table *table, int write, struct file *filp,
260 void *buffer, size_t *lenp)
261 {
262 size_t len;
263 char *p, c=0;
264 char String[256];
265
266 if ((table->data==0) || (table->maxlen==0) || (*lenp==0) ||
267 ((filp->f_pos!=0) && (write==0))) {
268 *lenp = 0;
269 return 0;
270 }
271
272 if (write!=0) {
273 len = 0;
274 p = buffer;
275 while (len < *lenp) {
276 if(get_user(c, p++))
277 return -EFAULT;
278 if (c == 0 || c == '\n')
279 break;
280 len++;
281 }
282 if (len >= table->maxlen)
283 len = table->maxlen-1;
284 if(copy_from_user(String, buffer,(unsigned long)len))
285 return -EFAULT;
286 ((char *) String)[len] = 0;
287 filp->f_pos += *lenp;
288 AddDynamicString(String);
289 } else {
290 GetSecureString(String);
291 len = strlen(String);
292 if (len > table->maxlen)
293 len = table->maxlen;
294 if (len > *lenp)
295 len = *lenp;
296 if (len!=0)
297 if(copy_to_user(buffer, String,(unsigned long)len))
298 return -EFAULT;
299 if (len < *lenp) {
300 if(put_user('\n', ((char *) buffer) + len))
301 return -EFAULT;
302 len++;
303 }
304 *lenp = len;
305 filp->f_pos += len;
306 }
307 return 0;
308 }
309
310 static int sysctl_SecureString (/*@unused@*/ctl_table *table,
311 /*@unused@*/int *name,
312 /*@unused@*/int nlen,
313 /*@unused@*/void *oldval,
314 /*@unused@*/size_t *oldlenp,
315 /*@unused@*/void *newval,
316 /*@unused@*/size_t newlen,
317 /*@unused@*/void **context)
318 {
319 return -ENOSYS;
320 }
321