source: clfs-embedded/patches/busybox-1.14.1-branch_update-1.patch@ b71d8ca

Last change on this file since b71d8ca was b71d8ca, checked in by Maarten Lankhorst <mlankhorst@…>, 15 years ago

update busybox

  • Property mode set to 100644
File size: 29.7 KB
RevLine 
[b71d8ca]1diff -ru busybox-1.14.1/coreutils/readlink.c busybox-1.14.1-fixed/coreutils/readlink.c
2--- busybox-1.14.1/coreutils/readlink.c 2009-05-27 18:00:23.000000000 +0200
3+++ busybox-1.14.1-fixed/coreutils/readlink.c 2009-09-04 13:03:37.741667825 +0200
4@@ -6,9 +6,31 @@
5 *
6 * Licensed under GPL v2 or later, see file LICENSE in this tarball for details.
7 */
8-
9 #include "libbb.h"
10
11+/*
12+ * # readlink --version
13+ * readlink (GNU coreutils) 6.10
14+ * # readlink --help
15+ * -f, --canonicalize
16+ * canonicalize by following every symlink in
17+ * every component of the given name recursively;
18+ * all but the last component must exist
19+ * -e, --canonicalize-existing
20+ * canonicalize by following every symlink in
21+ * every component of the given name recursively,
22+ * all components must exist
23+ * -m, --canonicalize-missing
24+ * canonicalize by following every symlink in
25+ * every component of the given name recursively,
26+ * without requirements on components existence
27+ * -n, --no-newline do not output the trailing newline
28+ * -q, --quiet, -s, --silent suppress most error messages
29+ * -v, --verbose report error messages
30+ *
31+ * bbox supports: -f -n -v (fully), -q -s (accepts but ignores)
32+ */
33+
34 int readlink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
35 int readlink_main(int argc UNUSED_PARAM, char **argv)
36 {
37@@ -20,7 +42,7 @@
38 unsigned opt;
39 /* We need exactly one non-option argument. */
40 opt_complementary = "=1";
41- opt = getopt32(argv, "f");
42+ opt = getopt32(argv, "fnvsq");
43 fname = argv[optind];
44 )
45 SKIP_FEATURE_READLINK_FOLLOW(
46@@ -30,9 +52,10 @@
47 )
48
49 /* compat: coreutils readlink reports errors silently via exit code */
50- logmode = LOGMODE_NONE;
51+ if (!(opt & 4)) /* not -v */
52+ logmode = LOGMODE_NONE;
53
54- if (opt) {
55+ if (opt & 1) { /* -f */
56 buf = realpath(fname, pathbuf);
57 } else {
58 buf = xmalloc_readlink_or_warn(fname);
59@@ -40,7 +63,7 @@
60
61 if (!buf)
62 return EXIT_FAILURE;
63- puts(buf);
64+ printf((opt & 2) ? "%s" : "%s\n", buf);
65
66 if (ENABLE_FEATURE_CLEAN_UP && !opt)
67 free(buf);
68diff -ru busybox-1.14.1/include/libbb.h busybox-1.14.1-fixed/include/libbb.h
69--- busybox-1.14.1/include/libbb.h 2009-05-27 18:01:37.000000000 +0200
70+++ busybox-1.14.1-fixed/include/libbb.h 2009-09-04 13:03:37.720987415 +0200
71@@ -1099,6 +1099,8 @@
72 void print_signames(void) FAST_FUNC;
73
74 char *bb_simplify_path(const char *path) FAST_FUNC;
75+/* Returns ptr to NUL */
76+char *bb_simplify_abs_path_inplace(char *path) FAST_FUNC;
77
78 #define FAIL_DELAY 3
79 extern void bb_do_delay(int seconds) FAST_FUNC;
80diff -ru busybox-1.14.1/include/usage.h busybox-1.14.1-fixed/include/usage.h
81--- busybox-1.14.1/include/usage.h 2009-05-27 18:00:23.000000000 +0200
82+++ busybox-1.14.1-fixed/include/usage.h 2009-09-04 13:03:37.741667825 +0200
83@@ -3404,12 +3404,15 @@
84 "files do not block on disk I/O"
85
86 #define readlink_trivial_usage \
87- USE_FEATURE_READLINK_FOLLOW("[-f] ") "FILE"
88+ USE_FEATURE_READLINK_FOLLOW("[-fnv] ") "FILE"
89 #define readlink_full_usage "\n\n" \
90 "Display the value of a symlink" \
91 USE_FEATURE_READLINK_FOLLOW( "\n" \
92 "\nOptions:" \
93- "\n -f Canonicalize by following all symlinks") \
94+ "\n -f Canonicalize by following all symlinks" \
95+ "\n -n Don't add newline" \
96+ "\n -v Verbose" \
97+ ) \
98
99 #define readprofile_trivial_usage \
100 "[OPTIONS]..."
101diff -ru busybox-1.14.1/libbb/simplify_path.c busybox-1.14.1-fixed/libbb/simplify_path.c
102--- busybox-1.14.1/libbb/simplify_path.c 2009-05-27 18:00:23.000000000 +0200
103+++ busybox-1.14.1-fixed/libbb/simplify_path.c 2009-09-04 13:03:37.725678136 +0200
104@@ -6,22 +6,13 @@
105 *
106 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
107 */
108-
109 #include "libbb.h"
110
111-char* FAST_FUNC bb_simplify_path(const char *path)
112+char* FAST_FUNC bb_simplify_abs_path_inplace(char *start)
113 {
114- char *s, *start, *p;
115+ char *s, *p;
116
117- if (path[0] == '/')
118- start = xstrdup(path);
119- else {
120- s = xrealloc_getcwd_or_warn(NULL);
121- start = concat_path_file(s, path);
122- free(s);
123- }
124 p = s = start;
125-
126 do {
127 if (*p == '/') {
128 if (*s == '/') { /* skip duplicate (or initial) slash */
129@@ -47,7 +38,22 @@
130 if ((p == start) || (*p != '/')) { /* not a trailing slash */
131 ++p; /* so keep last character */
132 }
133- *p = 0;
134+ *p = '\0';
135+ return p;
136+}
137+
138+char* FAST_FUNC bb_simplify_path(const char *path)
139+{
140+ char *s, *p;
141+
142+ if (path[0] == '/')
143+ s = xstrdup(path);
144+ else {
145+ p = xrealloc_getcwd_or_warn(NULL);
146+ s = concat_path_file(p, path);
147+ free(p);
148+ }
149
150- return start;
151+ bb_simplify_abs_path_inplace(s);
152+ return s;
153 }
154diff -ru busybox-1.14.1/modutils/modprobe-small.c busybox-1.14.1-fixed/modutils/modprobe-small.c
155--- busybox-1.14.1/modutils/modprobe-small.c 2009-05-27 18:00:23.000000000 +0200
156+++ busybox-1.14.1-fixed/modutils/modprobe-small.c 2009-09-04 13:03:37.733667718 +0200
157@@ -656,7 +656,7 @@
158 [-b basedirectory] [forced_version]
159 depmod [-n -e -v -q -r -u] [-F kernelsyms] module1.ko module2.ko ...
160 If no arguments (except options) are given, "depmod -a" is assumed.
161-depmod will output a dependancy list suitable for the modprobe utility.
162+depmod will output a dependency list suitable for the modprobe utility.
163 Options:
164 -a, --all Probe all modules
165 -A, --quick Only does the work if there's a new module
166diff -ru busybox-1.14.1/modutils/modprobe.c busybox-1.14.1-fixed/modutils/modprobe.c
167--- busybox-1.14.1/modutils/modprobe.c 2009-05-27 18:01:37.000000000 +0200
168+++ busybox-1.14.1-fixed/modutils/modprobe.c 2009-09-04 13:03:37.733667718 +0200
169@@ -8,12 +8,17 @@
170 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
171 */
172
173+/* Note that unlike older versions of modules.dep/depmod (busybox and m-i-t),
174+ * we expect the full dependency list to be specified in modules.dep. Older
175+ * versions would only export the direct dependency list.
176+ */
177+
178 #include "libbb.h"
179 #include "modutils.h"
180 #include <sys/utsname.h>
181 #include <fnmatch.h>
182
183-//#define DBG(...) bb_error_msg(__VA_ARGS__)
184+//#define DBG(fmt, ...) bb_error_msg("%s: " fmt, __func__, ## __VA_ARGS__)
185 #define DBG(...) ((void)0)
186
187 #define MODULE_FLAG_LOADED 0x0001
188@@ -116,6 +121,7 @@
189 return;
190 }
191
192+ DBG("queuing %s", name);
193 m->probed_name = name;
194 m->flags |= MODULE_FLAG_NEED_DEPS;
195 llist_add_to_end(&G.probes, m);
196@@ -205,9 +211,10 @@
197
198 static int do_modprobe(struct module_entry *m)
199 {
200- struct module_entry *m2;
201+ struct module_entry *m2 = m2; /* for compiler */
202 char *fn, *options;
203- int rc = -1;
204+ int rc, first;
205+ llist_t *l;
206
207 if (!(m->flags & MODULE_FLAG_FOUND_IN_MODDEP)) {
208 DBG("skipping %s, not found in modules.dep", m->modname);
209@@ -218,13 +225,25 @@
210 if (!(option_mask32 & MODPROBE_OPT_REMOVE))
211 m->deps = llist_rev(m->deps);
212
213+ for (l = m->deps; l != NULL; l = l->link)
214+ DBG("dep: %s", l->data);
215+
216+ first = 1;
217 rc = 0;
218 while (m->deps && rc == 0) {
219 fn = llist_pop(&m->deps);
220 m2 = get_or_add_modentry(fn);
221 if (option_mask32 & MODPROBE_OPT_REMOVE) {
222- if (bb_delete_module(m->modname, O_EXCL) != 0)
223- rc = errno;
224+ if (m2->flags & MODULE_FLAG_LOADED) {
225+ if (bb_delete_module(m2->modname, O_EXCL) != 0) {
226+ if (first)
227+ rc = errno;
228+ } else {
229+ m2->flags &= ~MODULE_FLAG_LOADED;
230+ }
231+ }
232+ /* do not error out if *deps* fail to unload */
233+ first = 0;
234 } else if (!(m2->flags & MODULE_FLAG_LOADED)) {
235 options = m2->options;
236 m2->options = NULL;
237@@ -242,11 +261,10 @@
238 free(fn);
239 }
240
241-//FIXME: what if rc < 0?
242- if (rc > 0 && !(option_mask32 & INSMOD_OPT_SILENT)) {
243+ if (rc && !(option_mask32 & INSMOD_OPT_SILENT)) {
244 bb_error_msg("failed to %sload module %s: %s",
245 (option_mask32 & MODPROBE_OPT_REMOVE) ? "un" : "",
246- m->probed_name ? m->probed_name : m->modname,
247+ m2->probed_name ? m2->probed_name : m2->modname,
248 moderror(rc)
249 );
250 }
251@@ -294,7 +312,8 @@
252 llist_add_to(&m->deps, xstrdup(tokens[0]));
253 if (tokens[1])
254 string_to_llist(tokens[1], &m->deps, " ");
255- }
256+ } else
257+ DBG("skipping dep line");
258 }
259 config_close(p);
260 }
261@@ -344,10 +363,12 @@
262 if (opt & (MODPROBE_OPT_INSERT_ALL | MODPROBE_OPT_REMOVE)) {
263 /* Each argument is a module name */
264 do {
265+ DBG("adding module %s", *argv);
266 add_probe(*argv++);
267 } while (*argv);
268 } else {
269 /* First argument is module name, rest are parameters */
270+ DBG("probing just module %s", *argv);
271 add_probe(argv[0]);
272 G.cmdline_mopts = parse_cmdline_module_options(argv);
273 }
274diff -ru busybox-1.14.1/modutils/modutils.c busybox-1.14.1-fixed/modutils/modutils.c
275--- busybox-1.14.1/modutils/modutils.c 2009-05-27 18:00:23.000000000 +0200
276+++ busybox-1.14.1-fixed/modutils/modutils.c 2009-09-04 13:03:37.733667718 +0200
277@@ -57,7 +57,7 @@
278 from = bb_get_last_path_component_nostrip(filename);
279 for (i = 0; i < (MODULE_NAME_LEN-1) && from[i] != '\0' && from[i] != '.'; i++)
280 modname[i] = (from[i] == '-') ? '_' : from[i];
281- modname[i] = 0;
282+ modname[i] = '\0';
283
284 return modname;
285 }
286diff -ru busybox-1.14.1/networking/ftpd.c busybox-1.14.1-fixed/networking/ftpd.c
287--- busybox-1.14.1/networking/ftpd.c 2009-05-27 18:00:23.000000000 +0200
288+++ busybox-1.14.1-fixed/networking/ftpd.c 2009-09-04 13:03:37.720987415 +0200
289@@ -1320,6 +1320,8 @@
290 handle_appe();
291 else if (cmdval == const_STOU) /* "store unique" */
292 handle_stou();
293+ else
294+ goto bad_cmd;
295 }
296 #endif
297 #if 0
298@@ -1340,6 +1342,9 @@
299 * (doesn't necessarily mean "we must support them")
300 * foo 1.2.3: XXXX - comment
301 */
302+#if ENABLE_FEATURE_FTP_WRITE
303+ bad_cmd:
304+#endif
305 cmdio_write_raw(STR(FTP_BADCMD)" Unknown command\r\n");
306 }
307 }
308diff -ru busybox-1.14.1/networking/httpd.c busybox-1.14.1-fixed/networking/httpd.c
309--- busybox-1.14.1/networking/httpd.c 2009-05-27 18:00:23.000000000 +0200
310+++ busybox-1.14.1-fixed/networking/httpd.c 2009-09-04 13:03:37.725678136 +0200
311@@ -32,7 +32,7 @@
312 * foo=`httpd -d $foo` # decode "Hello%20World" as "Hello World"
313 * bar=`httpd -e "<Hello World>"` # encode as "&#60Hello&#32World&#62"
314 * Note that url encoding for arguments is not the same as html encoding for
315- * presentation. -d decodes a url-encoded argument while -e encodes in html
316+ * presentation. -d decodes an url-encoded argument while -e encodes in html
317 * for page display.
318 *
319 * httpd.conf has the following format:
320@@ -54,7 +54,7 @@
321 * /adm:admin:setup # Require user admin, pwd setup on urls starting with /adm/
322 * /adm:toor:PaSsWd # or user toor, pwd PaSsWd on urls starting with /adm/
323 * .au:audio/basic # additional mime type for audio.au files
324- * *.php:/path/php # running cgi.php scripts through an interpreter
325+ * *.php:/path/php # run xxx.php through an interpreter
326 *
327 * A/D may be as a/d or allow/deny - only first char matters.
328 * Deny/Allow IP logic:
329@@ -94,13 +94,13 @@
330 * server exits with an error.
331 *
332 */
333+ /* TODO: use TCP_CORK, parse_config() */
334
335 #include "libbb.h"
336 #if ENABLE_FEATURE_HTTPD_USE_SENDFILE
337 # include <sys/sendfile.h>
338 #endif
339
340-//#define DEBUG 1
341 #define DEBUG 0
342
343 #define IOBUF_SIZE 8192 /* IO buffer */
344@@ -115,8 +115,8 @@
345
346 #define HEADER_READ_TIMEOUT 60
347
348-static const char default_path_httpd_conf[] ALIGN1 = "/etc";
349-static const char httpd_conf[] ALIGN1 = "httpd.conf";
350+static const char DEFAULT_PATH_HTTPD_CONF[] ALIGN1 = "/etc";
351+static const char HTTPD_CONF[] ALIGN1 = "httpd.conf";
352 static const char HTTP_200[] ALIGN1 = "HTTP/1.0 200 OK\r\n";
353
354 typedef struct has_next_ptr {
355@@ -242,7 +242,7 @@
356 const char *bind_addr_or_port;
357
358 const char *g_query;
359- const char *configFile;
360+ const char *opt_c_configFile;
361 const char *home_httpd;
362 const char *index_page;
363
364@@ -289,7 +289,7 @@
365 #define rmt_ip (G.rmt_ip )
366 #define bind_addr_or_port (G.bind_addr_or_port)
367 #define g_query (G.g_query )
368-#define configFile (G.configFile )
369+#define opt_c_configFile (G.opt_c_configFile )
370 #define home_httpd (G.home_httpd )
371 #define index_page (G.index_page )
372 #define found_mime_type (G.found_mime_type )
373@@ -452,14 +452,6 @@
374 /*
375 * Parse configuration file into in-memory linked list.
376 *
377- * The first non-white character is examined to determine if the config line
378- * is one of the following:
379- * .ext:mime/type # new mime type not compiled into httpd
380- * [adAD]:from # ip address allow/deny, * for wildcard
381- * /path:user:pass # username/password
382- * Ennn:error.html # error page for status nnn
383- * P:/url:[http://]hostname[:port]/new/path # reverse proxy
384- *
385 * Any previous IP rules are discarded.
386 * If the flag argument is not SUBDIR_PARSE then all /path and mime rules
387 * are also discarded. That is, previous settings are retained if flag is
388@@ -469,99 +461,150 @@
389 * path Path where to look for httpd.conf (without filename).
390 * flag Type of the parse request.
391 */
392-/* flag */
393-#define FIRST_PARSE 0
394-#define SUBDIR_PARSE 1
395-#define SIGNALED_PARSE 2
396-#define FIND_FROM_HTTPD_ROOT 3
397+/* flag param: */
398+enum {
399+ FIRST_PARSE = 0, /* path will be "/etc" */
400+ SIGNALED_PARSE = 1, /* path will be "/etc" */
401+ SUBDIR_PARSE = 2, /* path will be derived from URL */
402+};
403 static void parse_conf(const char *path, int flag)
404 {
405+ /* internally used extra flag state */
406+ enum { TRY_CURDIR_PARSE = 3 };
407+
408 FILE *f;
409-#if ENABLE_FEATURE_HTTPD_BASIC_AUTH
410- Htaccess *prev;
411-#endif
412- Htaccess *cur;
413- const char *filename = configFile;
414+ const char *filename;
415 char buf[160];
416- char *p, *p0;
417- char *after_colon;
418- Htaccess_IP *pip;
419
420 /* discard old rules */
421 free_Htaccess_IP_list(&ip_a_d);
422 flg_deny_all = 0;
423 /* retain previous auth and mime config only for subdir parse */
424 if (flag != SUBDIR_PARSE) {
425+ free_Htaccess_list(&mime_a);
426 #if ENABLE_FEATURE_HTTPD_BASIC_AUTH
427 free_Htaccess_list(&g_auth);
428 #endif
429- free_Htaccess_list(&mime_a);
430 #if ENABLE_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR
431 free_Htaccess_list(&script_i);
432 #endif
433 }
434
435+ filename = opt_c_configFile;
436 if (flag == SUBDIR_PARSE || filename == NULL) {
437- filename = alloca(strlen(path) + sizeof(httpd_conf) + 2);
438- sprintf((char *)filename, "%s/%s", path, httpd_conf);
439+ filename = alloca(strlen(path) + sizeof(HTTPD_CONF) + 2);
440+ sprintf((char *)filename, "%s/%s", path, HTTPD_CONF);
441 }
442
443 while ((f = fopen_for_read(filename)) == NULL) {
444- if (flag == SUBDIR_PARSE || flag == FIND_FROM_HTTPD_ROOT) {
445+ if (flag >= SUBDIR_PARSE) { /* SUBDIR or TRY_CURDIR */
446 /* config file not found, no changes to config */
447 return;
448 }
449- if (configFile && flag == FIRST_PARSE) /* if -c option given */
450- bb_simple_perror_msg_and_die(filename);
451- flag = FIND_FROM_HTTPD_ROOT;
452- filename = httpd_conf;
453+ if (flag == FIRST_PARSE) {
454+ /* -c CONFFILE given, but CONFFILE doesn't exist? */
455+ if (opt_c_configFile)
456+ bb_simple_perror_msg_and_die(opt_c_configFile);
457+ /* else: no -c, thus we looked at /etc/httpd.conf,
458+ * and it's not there. try ./httpd.conf: */
459+ }
460+ flag = TRY_CURDIR_PARSE;
461+ filename = HTTPD_CONF;
462 }
463
464 #if ENABLE_FEATURE_HTTPD_BASIC_AUTH
465- prev = g_auth;
466-#endif
467- /* This could stand some work */
468- while ((p0 = fgets(buf, sizeof(buf), f)) != NULL) {
469- after_colon = NULL;
470- for (p = p0; *p0 != '\0' && *p0 != '#'; p0++) {
471- if (!isspace(*p0)) {
472- *p++ = *p0;
473- if (*p0 == ':' && after_colon == NULL)
474- after_colon = p;
475+ /* in "/file:user:pass" lines, we prepend path in subdirs */
476+ if (flag != SUBDIR_PARSE)
477+ path = "";
478+#endif
479+ /* The lines can be:
480+ *
481+ * I:default_index_file
482+ * H:http_home
483+ * [AD]:IP[/mask] # allow/deny, * for wildcard
484+ * Ennn:error.html # error page for status nnn
485+ * P:/url:[http://]hostname[:port]/new/path # reverse proxy
486+ * .ext:mime/type # mime type
487+ * *.php:/path/php # run xxx.php through an interpreter
488+ * /file:user:pass # username and password
489+ */
490+ while (fgets(buf, sizeof(buf), f) != NULL) {
491+ unsigned strlen_buf;
492+ unsigned char ch;
493+ char *after_colon;
494+
495+ { /* remove all whitespace, and # comments */
496+ char *p, *p0;
497+
498+ p0 = buf;
499+ /* skip non-whitespace beginning. Often the whole line
500+ * is non-whitespace. We want this case to work fast,
501+ * without needless copying, therefore we don't merge
502+ * this operation into next while loop. */
503+ while ((ch = *p0) != '\0' && ch != '\n' && ch != '#'
504+ && ch != ' ' && ch != '\t'
505+ ) {
506+ p0++;
507+ }
508+ p = p0;
509+ /* if we enter this loop, we have some whitespace.
510+ * discard it */
511+ while (ch != '\0' && ch != '\n' && ch != '#') {
512+ if (ch != ' ' && ch != '\t') {
513+ *p++ = ch;
514+ }
515+ ch = *++p0;
516 }
517+ *p = '\0';
518+ strlen_buf = p - buf;
519+ if (strlen_buf == 0)
520+ continue; /* empty line */
521 }
522- *p = '\0';
523
524- /* test for empty or strange line */
525- if (after_colon == NULL || *after_colon == '\0')
526+ after_colon = strchr(buf, ':');
527+ /* strange line? */
528+ if (after_colon == NULL || *++after_colon == '\0')
529+ goto config_error;
530+
531+ ch = (buf[0] & ~0x20); /* toupper if it's a letter */
532+
533+ if (ch == 'I') {
534+ index_page = xstrdup(after_colon);
535 continue;
536- p0 = buf;
537- if (*p0 == 'd' || *p0 == 'a')
538- *p0 -= 0x20; /* a/d -> A/D */
539- if (*after_colon == '*') {
540- if (*p0 == 'D') {
541- /* memorize "deny all" */
542- flg_deny_all = 1;
543- }
544- /* skip assumed "A:*", it is a default anyway */
545+ }
546+
547+ /* do not allow jumping around using H in subdir's configs */
548+ if (flag == FIRST_PARSE && ch == 'H') {
549+ home_httpd = xstrdup(after_colon);
550+ xchdir(home_httpd);
551 continue;
552 }
553
554- if (*p0 == 'A' || *p0 == 'D') {
555- /* storing current config IP line */
556- pip = xzalloc(sizeof(Htaccess_IP));
557- if (scan_ip_mask(after_colon, &(pip->ip), &(pip->mask))) {
558+ if (ch == 'A' || ch == 'D') {
559+ Htaccess_IP *pip;
560+
561+ if (*after_colon == '*') {
562+ if (ch == 'D') {
563+ /* memorize "deny all" */
564+ flg_deny_all = 1;
565+ }
566+ /* skip assumed "A:*", it is a default anyway */
567+ continue;
568+ }
569+ /* store "allow/deny IP/mask" line */
570+ pip = xzalloc(sizeof(*pip));
571+ if (scan_ip_mask(after_colon, &pip->ip, &pip->mask)) {
572 /* IP{/mask} syntax error detected, protect all */
573- *p0 = 'D';
574+ ch = 'D';
575 pip->mask = 0;
576 }
577- pip->allow_deny = *p0;
578- if (*p0 == 'D') {
579+ pip->allow_deny = ch;
580+ if (ch == 'D') {
581 /* Deny:from_IP - prepend */
582 pip->next = ip_a_d;
583 ip_a_d = pip;
584 } else {
585- /* A:from_IP - append (thus D precedes A) */
586+ /* A:from_IP - append (thus all D's precedes A's) */
587 Htaccess_IP *prev_IP = ip_a_d;
588 if (prev_IP == NULL) {
589 ip_a_d = pip;
590@@ -575,12 +618,12 @@
591 }
592
593 #if ENABLE_FEATURE_HTTPD_ERROR_PAGES
594- if (flag == FIRST_PARSE && *p0 == 'E') {
595+ if (flag == FIRST_PARSE && ch == 'E') {
596 unsigned i;
597- int status = atoi(++p0); /* error status code */
598+ int status = atoi(buf + 1); /* error status code */
599+
600 if (status < HTTP_CONTINUE) {
601- bb_error_msg("config error '%s' in '%s'", buf, filename);
602- continue;
603+ goto config_error;
604 }
605 /* then error page; find matching status */
606 for (i = 0; i < ARRAY_SIZE(http_response_type); i++) {
607@@ -597,7 +640,7 @@
608 #endif
609
610 #if ENABLE_FEATURE_HTTPD_PROXY
611- if (flag == FIRST_PARSE && *p0 == 'P') {
612+ if (flag == FIRST_PARSE && ch == 'P') {
613 /* P:/url:[http://]hostname[:port]/new/path */
614 char *url_from, *host_port, *url_to;
615 Htaccess_Proxy *proxy_entry;
616@@ -605,23 +648,20 @@
617 url_from = after_colon;
618 host_port = strchr(after_colon, ':');
619 if (host_port == NULL) {
620- bb_error_msg("config error '%s' in '%s'", buf, filename);
621- continue;
622+ goto config_error;
623 }
624 *host_port++ = '\0';
625 if (strncmp(host_port, "http://", 7) == 0)
626 host_port += 7;
627 if (*host_port == '\0') {
628- bb_error_msg("config error '%s' in '%s'", buf, filename);
629- continue;
630+ goto config_error;
631 }
632 url_to = strchr(host_port, '/');
633 if (url_to == NULL) {
634- bb_error_msg("config error '%s' in '%s'", buf, filename);
635- continue;
636+ goto config_error;
637 }
638 *url_to = '\0';
639- proxy_entry = xzalloc(sizeof(Htaccess_Proxy));
640+ proxy_entry = xzalloc(sizeof(*proxy_entry));
641 proxy_entry->url_from = xstrdup(url_from);
642 proxy_entry->host_port = xstrdup(host_port);
643 *url_to = '/';
644@@ -631,115 +671,87 @@
645 continue;
646 }
647 #endif
648+ /* the rest of directives are non-alphabetic,
649+ * must avoid using "toupper'ed" ch */
650+ ch = buf[0];
651
652-#if ENABLE_FEATURE_HTTPD_BASIC_AUTH
653- if (*p0 == '/') {
654- /* make full path from httpd root / current_path / config_line_path */
655- const char *tp = (flag == SUBDIR_PARSE ? path : "");
656- p0 = xmalloc(strlen(tp) + (after_colon - buf) + 2 + strlen(after_colon));
657- after_colon[-1] = '\0';
658- sprintf(p0, "/%s%s", tp, buf);
659-
660- /* looks like bb_simplify_path... */
661- tp = p = p0;
662- do {
663- if (*p == '/') {
664- if (*tp == '/') { /* skip duplicate (or initial) slash */
665- continue;
666- }
667- if (*tp == '.') {
668- if (tp[1] == '/' || tp[1] == '\0') { /* remove extra '.' */
669- continue;
670- }
671- if ((tp[1] == '.') && (tp[2] == '/' || tp[2] == '\0')) {
672- ++tp;
673- if (p > p0) {
674- while (*--p != '/') /* omit previous dir */
675- continue;
676- }
677- continue;
678- }
679- }
680- }
681- *++p = *tp;
682- } while (*++tp);
683+ if (ch == '.' /* ".ext:mime/type" */
684+#if ENABLE_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR
685+ || (ch == '*' && buf[1] == '.') /* "*.php:/path/php" */
686+#endif
687+ ) {
688+ char *p;
689+ Htaccess *cur;
690
691- if ((p == p0) || (*p != '/')) { /* not a trailing slash */
692- ++p; /* so keep last character */
693+ cur = xzalloc(sizeof(*cur) /* includes space for NUL */ + strlen_buf);
694+ strcpy(cur->before_colon, buf);
695+ p = cur->before_colon + (after_colon - buf);
696+ p[-1] = '\0';
697+ cur->after_colon = p;
698+ if (ch == '.') {
699+ /* .mime line: prepend to mime_a list */
700+ cur->next = mime_a;
701+ mime_a = cur;
702+ }
703+#if ENABLE_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR
704+ else {
705+ /* script interpreter line: prepend to script_i list */
706+ cur->next = script_i;
707+ script_i = cur;
708 }
709- *p = ':';
710- strcpy(p + 1, after_colon);
711- }
712 #endif
713- if (*p0 == 'I') {
714- index_page = xstrdup(after_colon);
715- continue;
716- }
717-
718- /* Do not allow jumping around using H in subdir's configs */
719- if (flag == FIRST_PARSE && *p0 == 'H') {
720- home_httpd = xstrdup(after_colon);
721- xchdir(home_httpd);
722 continue;
723 }
724
725- /* storing current config line */
726- cur = xzalloc(sizeof(Htaccess) + strlen(p0));
727- strcpy(cur->before_colon, p0);
728-#if ENABLE_FEATURE_HTTPD_BASIC_AUTH
729- if (*p0 == '/') /* was malloced - see above */
730- free(p0);
731-#endif
732- cur->after_colon = strchr(cur->before_colon, ':');
733- *cur->after_colon++ = '\0';
734- if (cur->before_colon[0] == '.') {
735- /* .mime line: prepend to mime_a list */
736- cur->next = mime_a;
737- mime_a = cur;
738- continue;
739- }
740-#if ENABLE_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR
741- if (cur->before_colon[0] == '*' && cur->before_colon[1] == '.') {
742- /* script interpreter line: prepend to script_i list */
743- cur->next = script_i;
744- script_i = cur;
745- continue;
746- }
747-#endif
748 #if ENABLE_FEATURE_HTTPD_BASIC_AUTH
749-//TODO: we do not test for leading "/"??
750-//also, do we leak cur if BASIC_AUTH is off?
751- if (prev == NULL) {
752- /* first line */
753- g_auth = prev = cur;
754- } else {
755- /* sort path, if current length eq or bigger then move up */
756- Htaccess *prev_hti = g_auth;
757- size_t l = strlen(cur->before_colon);
758- Htaccess *hti;
759-
760- for (hti = prev_hti; hti; hti = hti->next) {
761- if (l >= strlen(hti->before_colon)) {
762- /* insert before hti */
763- cur->next = hti;
764- if (prev_hti != hti) {
765- prev_hti->next = cur;
766- } else {
767- /* insert as top */
768- g_auth = cur;
769+ if (ch == '/') { /* "/file:user:pass" */
770+ char *p;
771+ Htaccess *cur;
772+ unsigned file_len;
773+
774+ /* note: path is "" unless we are in SUBDIR parse,
775+ * otherwise it does NOT start with "/" */
776+ cur = xzalloc(sizeof(*cur) /* includes space for NUL */
777+ + 1 + strlen(path)
778+ + strlen_buf
779+ );
780+ /* form "/path/file" */
781+ sprintf(cur->before_colon, "/%s%.*s",
782+ path,
783+ (int) (after_colon - buf - 1), /* includes "/", but not ":" */
784+ buf);
785+ /* canonicalize it */
786+ p = bb_simplify_abs_path_inplace(cur->before_colon);
787+ file_len = p - cur->before_colon;
788+ /* add "user:pass" after NUL */
789+ strcpy(++p, after_colon);
790+ cur->after_colon = p;
791+
792+ /* insert cur into g_auth */
793+ /* g_auth is sorted by decreased filename length */
794+ {
795+ Htaccess *auth, **authp;
796+
797+ authp = &g_auth;
798+ while ((auth = *authp) != NULL) {
799+ if (file_len >= strlen(auth->before_colon)) {
800+ /* insert cur before auth */
801+ cur->next = auth;
802+ break;
803 }
804- break;
805+ authp = &auth->next;
806 }
807- if (prev_hti != hti)
808- prev_hti = prev_hti->next;
809- }
810- if (!hti) { /* not inserted, add to bottom */
811- prev->next = cur;
812- prev = cur;
813+ *authp = cur;
814 }
815+ continue;
816 }
817 #endif /* BASIC_AUTH */
818+
819+ /* the line is not recognized */
820+ config_error:
821+ bb_error_msg("config error '%s' in '%s'", buf, filename);
822 } /* while (fgets) */
823+
824 fclose(f);
825 }
826
827@@ -1527,11 +1539,6 @@
828 send_headers_and_exit(HTTP_NOT_FOUND);
829 log_and_exit();
830 }
831-
832- if (DEBUG)
833- bb_error_msg("sending file '%s' content-type: %s",
834- url, found_mime_type);
835-
836 /* If you want to know about EPIPE below
837 * (happens if you abort downloads from local httpd): */
838 signal(SIGPIPE, SIG_IGN);
839@@ -1559,6 +1566,11 @@
840 }
841 }
842 }
843+
844+ if (DEBUG)
845+ bb_error_msg("sending file '%s' content-type: %s",
846+ url, found_mime_type);
847+
848 #if ENABLE_FEATURE_HTTPD_RANGES
849 if (what == SEND_BODY)
850 range_start = 0; /* err pages and ranges don't mix */
851@@ -2031,8 +2043,8 @@
852 /* We are done reading headers, disable peer timeout */
853 alarm(0);
854
855- if (strcmp(bb_basename(urlcopy), httpd_conf) == 0 || !ip_allowed) {
856- /* protect listing [/path]/httpd_conf or IP deny */
857+ if (strcmp(bb_basename(urlcopy), HTTPD_CONF) == 0 || !ip_allowed) {
858+ /* protect listing [/path]/httpd.conf or IP deny */
859 send_headers_and_exit(HTTP_FORBIDDEN);
860 }
861
862@@ -2074,7 +2086,7 @@
863 header_ptr += 2;
864 write(proxy_fd, header_buf, header_ptr - header_buf);
865 free(header_buf); /* on the order of 8k, free it */
866- /* cgi_io_loop_and_exit needs to have two disctinct fds */
867+ /* cgi_io_loop_and_exit needs to have two distinct fds */
868 cgi_io_loop_and_exit(proxy_fd, dup(proxy_fd), length);
869 }
870 #endif
871@@ -2245,7 +2257,7 @@
872
873 static void sighup_handler(int sig UNUSED_PARAM)
874 {
875- parse_conf(default_path_httpd_conf, SIGNALED_PARSE);
876+ parse_conf(DEFAULT_PATH_HTTPD_CONF, SIGNALED_PARSE);
877 }
878
879 enum {
880@@ -2304,7 +2316,7 @@
881 USE_FEATURE_HTTPD_AUTH_MD5("m:")
882 USE_FEATURE_HTTPD_SETUID("u:")
883 "p:ifv",
884- &configFile, &url_for_decode, &home_httpd
885+ &opt_c_configFile, &url_for_decode, &home_httpd
886 USE_FEATURE_HTTPD_ENCODE_URL_STR(, &url_for_encode)
887 USE_FEATURE_HTTPD_BASIC_AUTH(, &g_realm)
888 USE_FEATURE_HTTPD_AUTH_MD5(, &pass)
889@@ -2375,7 +2387,7 @@
890 }
891 #endif
892
893- parse_conf(default_path_httpd_conf, FIRST_PARSE);
894+ parse_conf(DEFAULT_PATH_HTTPD_CONF, FIRST_PARSE);
895 if (!(opt & OPT_INETD))
896 signal(SIGHUP, sighup_handler);
897
898diff -ru busybox-1.14.1/networking/telnetd.c busybox-1.14.1-fixed/networking/telnetd.c
899--- busybox-1.14.1/networking/telnetd.c 2009-05-27 18:00:23.000000000 +0200
900+++ busybox-1.14.1-fixed/networking/telnetd.c 2009-09-04 13:03:37.745648372 +0200
901@@ -199,9 +199,17 @@
902 return total + rc;
903 }
904
905+/* Must match getopt32 string */
906+enum {
907+ OPT_WATCHCHILD = (1 << 2), /* -K */
908+ OPT_INETD = (1 << 3) * ENABLE_FEATURE_TELNETD_STANDALONE, /* -i */
909+ OPT_PORT = (1 << 4) * ENABLE_FEATURE_TELNETD_STANDALONE, /* -p */
910+ OPT_FOREGROUND = (1 << 6) * ENABLE_FEATURE_TELNETD_STANDALONE, /* -F */
911+};
912+
913 static struct tsession *
914 make_new_session(
915- USE_FEATURE_TELNETD_STANDALONE(int sock)
916+ USE_FEATURE_TELNETD_STANDALONE(int master_fd, int sock)
917 SKIP_FEATURE_TELNETD_STANDALONE(void)
918 ) {
919 const char *login_argv[2];
920@@ -288,9 +296,29 @@
921 /* Restore default signal handling ASAP */
922 bb_signals((1 << SIGCHLD) + (1 << SIGPIPE), SIG_DFL);
923
924+#if ENABLE_FEATURE_TELNETD_STANDALONE
925+ if (!(option_mask32 & OPT_INETD)) {
926+ struct tsession *tp = sessions;
927+ while (tp) {
928+ close(tp->ptyfd);
929+ close(tp->sockfd_read);
930+ /* sockfd_write == sockfd_read for standalone telnetd */
931+ /*close(tp->sockfd_write);*/
932+ tp = tp->next;
933+ }
934+ }
935+#endif
936+
937 /* Make new session and process group */
938 setsid();
939
940+ close(fd);
941+#if ENABLE_FEATURE_TELNETD_STANDALONE
942+ close(sock);
943+ if (master_fd >= 0)
944+ close(master_fd);
945+#endif
946+
947 /* Open the child's side of the tty. */
948 /* NB: setsid() disconnects from any previous ctty's. Therefore
949 * we must open child's side of the tty AFTER setsid! */
950@@ -329,14 +357,6 @@
951 _exit(EXIT_FAILURE); /*bb_perror_msg_and_die("execv %s", loginpath);*/
952 }
953
954-/* Must match getopt32 string */
955-enum {
956- OPT_WATCHCHILD = (1 << 2), /* -K */
957- OPT_INETD = (1 << 3) * ENABLE_FEATURE_TELNETD_STANDALONE, /* -i */
958- OPT_PORT = (1 << 4) * ENABLE_FEATURE_TELNETD_STANDALONE, /* -p */
959- OPT_FOREGROUND = (1 << 6) * ENABLE_FEATURE_TELNETD_STANDALONE, /* -F */
960-};
961-
962 #if ENABLE_FEATURE_TELNETD_STANDALONE
963
964 static void
965@@ -465,7 +485,7 @@
966
967 #if ENABLE_FEATURE_TELNETD_STANDALONE
968 if (IS_INETD) {
969- sessions = make_new_session(0);
970+ sessions = make_new_session(-1, 0);
971 if (!sessions) /* pty opening or vfork problem, exit */
972 return 1; /* make_new_session prints error message */
973 } else {
974@@ -553,7 +573,7 @@
975 if (fd < 0)
976 goto again;
977 /* Create a new session and link it into our active list */
978- new_ts = make_new_session(fd);
979+ new_ts = make_new_session(master_fd, fd);
980 if (new_ts) {
981 new_ts->next = sessions;
982 sessions = new_ts;
983diff -ru busybox-1.14.1/shell/ash.c busybox-1.14.1-fixed/shell/ash.c
984--- busybox-1.14.1/shell/ash.c 2009-05-27 18:00:23.000000000 +0200
985+++ busybox-1.14.1-fixed/shell/ash.c 2009-09-04 13:03:37.717444203 +0200
986@@ -11909,7 +11909,8 @@
987 */
988 return fullname;
989 }
990- stunalloc(fullname);
991+ if (fullname != name)
992+ stunalloc(fullname);
993 }
994
995 /* not found in the PATH */
Note: See TracBrowser for help on using the repository browser.