3 kHTTPd -- the next generation
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)
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.
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.
23 ****************************************************************/
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>
35 #include <linux/unistd.h>
41 #include <asm/atomic.h>
42 #include <asm/semaphore.h>
43 #include <asm/processor.h>
44 #include <asm/uaccess.h>
46 #include <linux/file.h>
47 #include "prototypes.h"
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;
62 char sysctl_khttpd_dynamicstring[200];
63 int sysctl_khttpd_sloppymime= 0;
64 int sysctl_khttpd_threads = 2;
65 int sysctl_khttpd_maxconnect = 1000;
67 atomic_t khttpd_stopCount;
69 static struct ctl_table_header *khttpd_table_header;
71 static int sysctl_SecureString(ctl_table *table, int *name, int nlen,
72 void *oldval, size_t *oldlenp,
73 void *newval, size_t newlen, void **context);
74 static int proc_dosecurestring(ctl_table *table, int write, struct file *filp,
75 void *buffer, size_t *lenp);
76 static int khttpd_stop_wrap_proc_dointvec(ctl_table *table, int write, struct file *filp,
77 void *buffer, size_t *lenp);
80 static ctl_table khttpd_table[] = {
83 &sysctl_khttpd_docroot,
84 sizeof(sysctl_khttpd_docroot),
99 khttpd_stop_wrap_proc_dointvec,
107 &sysctl_khttpd_start,
119 &sysctl_khttpd_unload,
129 { NET_KHTTPD_THREADS,
131 &sysctl_khttpd_threads,
141 { NET_KHTTPD_MAXCONNECT,
143 &sysctl_khttpd_maxconnect,
153 { NET_KHTTPD_SLOPPYMIME,
155 &sysctl_khttpd_sloppymime,
165 { NET_KHTTPD_CLIENTPORT,
167 &sysctl_khttpd_clientport,
177 { NET_KHTTPD_PERMREQ,
179 &sysctl_khttpd_permreq,
189 { NET_KHTTPD_PERMFORBID,
191 &sysctl_khttpd_permforbid,
201 { NET_KHTTPD_LOGGING,
203 &sysctl_khttpd_logging,
213 { NET_KHTTPD_SERVERPORT,
215 &sysctl_khttpd_serverport,
225 { NET_KHTTPD_DYNAMICSTRING,
227 &sysctl_khttpd_dynamicstring,
228 sizeof(sysctl_khttpd_dynamicstring),
232 &sysctl_SecureString,
237 {0,0,0,0,0,0,0,0,0,0,0} };
240 static ctl_table khttpd_dir_table[] = {
241 {NET_KHTTPD, "khttpd", NULL, 0, 0555, khttpd_table,0,0,0,0,0},
242 {0,0,0,0,0,0,0,0,0,0,0}
245 static ctl_table khttpd_root_table[] = {
246 {CTL_NET, "net", NULL, 0, 0555, khttpd_dir_table,0,0,0,0,0},
247 {0,0,0,0,0,0,0,0,0,0,0}
251 void StartSysctl(void)
253 khttpd_table_header = register_sysctl_table(khttpd_root_table,1);
259 unregister_sysctl_table(khttpd_table_header);
262 static int proc_dosecurestring(ctl_table *table, int write, struct file *filp,
263 void *buffer, size_t *lenp)
269 if ((table->data==0) || (table->maxlen==0) || (*lenp==0) ||
270 ((filp->f_pos!=0) && (write==0))) {
278 while (len < *lenp) {
281 if (c == 0 || c == '\n')
285 if (len >= table->maxlen)
286 len = table->maxlen-1;
287 if(copy_from_user(String, buffer,(unsigned long)len))
289 ((char *) String)[len] = 0;
290 filp->f_pos += *lenp;
291 AddDynamicString(String);
293 GetSecureString(String);
294 len = strlen(String);
295 if (len > table->maxlen)
300 if(copy_to_user(buffer, String,(unsigned long)len))
303 if(put_user('\n', ((char *) buffer) + len))
313 /* A wrapper around proc_dointvec that computes
314 * khttpd_stopCount = # of times sysctl_khttpd_stop has gone true
315 * Sensing sysctl_khttpd_stop in other threads is racy;
316 * sensing khttpd_stopCount in other threads is not.
318 static int khttpd_stop_wrap_proc_dointvec(ctl_table *table, int write, struct file *filp,
319 void *buffer, size_t *lenp)
322 int oldstop = sysctl_khttpd_stop;
323 rv = proc_dointvec(table, write, filp, buffer, lenp);
324 if (sysctl_khttpd_stop && !oldstop)
325 atomic_inc(&khttpd_stopCount);
331 static int sysctl_SecureString (/*@unused@*/ctl_table *table,
332 /*@unused@*/int *name,
333 /*@unused@*/int nlen,
334 /*@unused@*/void *oldval,
335 /*@unused@*/size_t *oldlenp,
336 /*@unused@*/void *newval,
337 /*@unused@*/size_t newlen,
338 /*@unused@*/void **context)