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
  • coreutils/readlink.c

    diff -ru busybox-1.14.1/coreutils/readlink.c busybox-1.14.1-fixed/coreutils/readlink.c
    old new  
    66 *
    77 * Licensed under GPL v2 or later, see file LICENSE in this tarball for details.
    88 */
    9 
    109#include "libbb.h"
    1110
     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
    1234int readlink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
    1335int readlink_main(int argc UNUSED_PARAM, char **argv)
    1436{
     
    2042                unsigned opt;
    2143                /* We need exactly one non-option argument.  */
    2244                opt_complementary = "=1";
    23                 opt = getopt32(argv, "f");
     45                opt = getopt32(argv, "fnvsq");
    2446                fname = argv[optind];
    2547        )
    2648        SKIP_FEATURE_READLINK_FOLLOW(
     
    3052        )
    3153
    3254        /* compat: coreutils readlink reports errors silently via exit code */
    33         logmode = LOGMODE_NONE;
     55        if (!(opt & 4)) /* not -v */
     56                logmode = LOGMODE_NONE;
    3457
    35         if (opt) {
     58        if (opt & 1) { /* -f */
    3659                buf = realpath(fname, pathbuf);
    3760        } else {
    3861                buf = xmalloc_readlink_or_warn(fname);
     
    4063
    4164        if (!buf)
    4265                return EXIT_FAILURE;
    43         puts(buf);
     66        printf((opt & 2) ? "%s" : "%s\n", buf);
    4467
    4568        if (ENABLE_FEATURE_CLEAN_UP && !opt)
    4669                free(buf);
  • include/libbb.h

    diff -ru busybox-1.14.1/include/libbb.h busybox-1.14.1-fixed/include/libbb.h
    old new  
    10991099void print_signames(void) FAST_FUNC;
    11001100
    11011101char *bb_simplify_path(const char *path) FAST_FUNC;
     1102/* Returns ptr to NUL */
     1103char *bb_simplify_abs_path_inplace(char *path) FAST_FUNC;
    11021104
    11031105#define FAIL_DELAY 3
    11041106extern void bb_do_delay(int seconds) FAST_FUNC;
  • include/usage.h

    diff -ru busybox-1.14.1/include/usage.h busybox-1.14.1-fixed/include/usage.h
    old new  
    34043404       "files do not block on disk I/O"
    34053405
    34063406#define readlink_trivial_usage \
    3407         USE_FEATURE_READLINK_FOLLOW("[-f] ") "FILE"
     3407        USE_FEATURE_READLINK_FOLLOW("[-fnv] ") "FILE"
    34083408#define readlink_full_usage "\n\n" \
    34093409       "Display the value of a symlink" \
    34103410        USE_FEATURE_READLINK_FOLLOW( "\n" \
    34113411     "\nOptions:" \
    3412      "\n        -f      Canonicalize by following all symlinks") \
     3412     "\n        -f      Canonicalize by following all symlinks" \
     3413     "\n        -n      Don't add newline" \
     3414     "\n        -v      Verbose" \
     3415        ) \
    34133416
    34143417#define readprofile_trivial_usage \
    34153418       "[OPTIONS]..."
  • libbb/simplify_path.c

    diff -ru busybox-1.14.1/libbb/simplify_path.c busybox-1.14.1-fixed/libbb/simplify_path.c
    old new  
    66 *
    77 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
    88 */
    9 
    109#include "libbb.h"
    1110
    12 char* FAST_FUNC bb_simplify_path(const char *path)
     11char* FAST_FUNC bb_simplify_abs_path_inplace(char *start)
    1312{
    14         char *s, *start, *p;
     13        char *s, *p;
    1514
    16         if (path[0] == '/')
    17                 start = xstrdup(path);
    18         else {
    19                 s = xrealloc_getcwd_or_warn(NULL);
    20                 start = concat_path_file(s, path);
    21                 free(s);
    22         }
    2315        p = s = start;
    24 
    2516        do {
    2617                if (*p == '/') {
    2718                        if (*s == '/') {        /* skip duplicate (or initial) slash */
     
    4738        if ((p == start) || (*p != '/')) {      /* not a trailing slash */
    4839                ++p;                                    /* so keep last character */
    4940        }
    50         *p = 0;
     41        *p = '\0';
     42        return p;
     43}
     44
     45char* FAST_FUNC bb_simplify_path(const char *path)
     46{
     47        char *s, *p;
     48
     49        if (path[0] == '/')
     50                s = xstrdup(path);
     51        else {
     52                p = xrealloc_getcwd_or_warn(NULL);
     53                s = concat_path_file(p, path);
     54                free(p);
     55        }
    5156
    52         return start;
     57        bb_simplify_abs_path_inplace(s);
     58        return s;
    5359}
  • modutils/modprobe-small.c

    diff -ru busybox-1.14.1/modutils/modprobe-small.c busybox-1.14.1-fixed/modutils/modprobe-small.c
    old new  
    656656      [-b basedirectory] [forced_version]
    657657depmod [-n -e -v -q -r -u] [-F kernelsyms] module1.ko module2.ko ...
    658658If no arguments (except options) are given, "depmod -a" is assumed.
    659 depmod will output a dependancy list suitable for the modprobe utility.
     659depmod will output a dependency list suitable for the modprobe utility.
    660660Options:
    661661    -a, --all           Probe all modules
    662662    -A, --quick         Only does the work if there's a new module
  • modutils/modprobe.c

    diff -ru busybox-1.14.1/modutils/modprobe.c busybox-1.14.1-fixed/modutils/modprobe.c
    old new  
    88 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
    99 */
    1010
     11/* Note that unlike older versions of modules.dep/depmod (busybox and m-i-t),
     12 * we expect the full dependency list to be specified in modules.dep.  Older
     13 * versions would only export the direct dependency list.
     14 */
     15
    1116#include "libbb.h"
    1217#include "modutils.h"
    1318#include <sys/utsname.h>
    1419#include <fnmatch.h>
    1520
    16 //#define DBG(...) bb_error_msg(__VA_ARGS__)
     21//#define DBG(fmt, ...) bb_error_msg("%s: " fmt, __func__, ## __VA_ARGS__)
    1722#define DBG(...) ((void)0)
    1823
    1924#define MODULE_FLAG_LOADED              0x0001
     
    116121                return;
    117122        }
    118123
     124        DBG("queuing %s", name);
    119125        m->probed_name = name;
    120126        m->flags |= MODULE_FLAG_NEED_DEPS;
    121127        llist_add_to_end(&G.probes, m);
     
    205211
    206212static int do_modprobe(struct module_entry *m)
    207213{
    208         struct module_entry *m2;
     214        struct module_entry *m2 = m2; /* for compiler */
    209215        char *fn, *options;
    210         int rc = -1;
     216        int rc, first;
     217        llist_t *l;
    211218
    212219        if (!(m->flags & MODULE_FLAG_FOUND_IN_MODDEP)) {
    213220                DBG("skipping %s, not found in modules.dep", m->modname);
     
    218225        if (!(option_mask32 & MODPROBE_OPT_REMOVE))
    219226                m->deps = llist_rev(m->deps);
    220227
     228        for (l = m->deps; l != NULL; l = l->link)
     229                DBG("dep: %s", l->data);
     230
     231        first = 1;
    221232        rc = 0;
    222233        while (m->deps && rc == 0) {
    223234                fn = llist_pop(&m->deps);
    224235                m2 = get_or_add_modentry(fn);
    225236                if (option_mask32 & MODPROBE_OPT_REMOVE) {
    226                         if (bb_delete_module(m->modname, O_EXCL) != 0)
    227                                 rc = errno;
     237                        if (m2->flags & MODULE_FLAG_LOADED) {
     238                                if (bb_delete_module(m2->modname, O_EXCL) != 0) {
     239                                        if (first)
     240                                                rc = errno;
     241                                } else {
     242                                        m2->flags &= ~MODULE_FLAG_LOADED;
     243                                }
     244                        }
     245                        /* do not error out if *deps* fail to unload */
     246                        first = 0;
    228247                } else if (!(m2->flags & MODULE_FLAG_LOADED)) {
    229248                        options = m2->options;
    230249                        m2->options = NULL;
     
    242261                free(fn);
    243262        }
    244263
    245 //FIXME: what if rc < 0?
    246         if (rc > 0 && !(option_mask32 & INSMOD_OPT_SILENT)) {
     264        if (rc && !(option_mask32 & INSMOD_OPT_SILENT)) {
    247265                bb_error_msg("failed to %sload module %s: %s",
    248266                        (option_mask32 & MODPROBE_OPT_REMOVE) ? "un" : "",
    249                         m->probed_name ? m->probed_name : m->modname,
     267                        m2->probed_name ? m2->probed_name : m2->modname,
    250268                        moderror(rc)
    251269                );
    252270        }
     
    294312                        llist_add_to(&m->deps, xstrdup(tokens[0]));
    295313                        if (tokens[1])
    296314                                string_to_llist(tokens[1], &m->deps, " ");
    297                 }
     315                } else
     316                        DBG("skipping dep line");
    298317        }
    299318        config_close(p);
    300319}
     
    344363        if (opt & (MODPROBE_OPT_INSERT_ALL | MODPROBE_OPT_REMOVE)) {
    345364                /* Each argument is a module name */
    346365                do {
     366                        DBG("adding module %s", *argv);
    347367                        add_probe(*argv++);
    348368                } while (*argv);
    349369        } else {
    350370                /* First argument is module name, rest are parameters */
     371                DBG("probing just module %s", *argv);
    351372                add_probe(argv[0]);
    352373                G.cmdline_mopts = parse_cmdline_module_options(argv);
    353374        }
  • modutils/modutils.c

    diff -ru busybox-1.14.1/modutils/modutils.c busybox-1.14.1-fixed/modutils/modutils.c
    old new  
    5757        from = bb_get_last_path_component_nostrip(filename);
    5858        for (i = 0; i < (MODULE_NAME_LEN-1) && from[i] != '\0' && from[i] != '.'; i++)
    5959                modname[i] = (from[i] == '-') ? '_' : from[i];
    60         modname[i] = 0;
     60        modname[i] = '\0';
    6161
    6262        return modname;
    6363}
  • networking/ftpd.c

    diff -ru busybox-1.14.1/networking/ftpd.c busybox-1.14.1-fixed/networking/ftpd.c
    old new  
    13201320                                handle_appe();
    13211321                        else if (cmdval == const_STOU) /* "store unique" */
    13221322                                handle_stou();
     1323                        else
     1324                                goto bad_cmd;
    13231325                }
    13241326#endif
    13251327#if 0
     
    13401342                         * (doesn't necessarily mean "we must support them")
    13411343                         * foo 1.2.3: XXXX - comment
    13421344                         */
     1345#if ENABLE_FEATURE_FTP_WRITE
     1346 bad_cmd:
     1347#endif
    13431348                        cmdio_write_raw(STR(FTP_BADCMD)" Unknown command\r\n");
    13441349                }
    13451350        }
  • networking/httpd.c

    diff -ru busybox-1.14.1/networking/httpd.c busybox-1.14.1-fixed/networking/httpd.c
    old new  
    3232 *  foo=`httpd -d $foo`           # decode "Hello%20World" as "Hello World"
    3333 *  bar=`httpd -e "<Hello World>"`  # encode as "&#60Hello&#32World&#62"
    3434 * Note that url encoding for arguments is not the same as html encoding for
    35  * presentation.  -d decodes a url-encoded argument while -e encodes in html
     35 * presentation.  -d decodes an url-encoded argument while -e encodes in html
    3636 * for page display.
    3737 *
    3838 * httpd.conf has the following format:
     
    5454 * /adm:admin:setup  # Require user admin, pwd setup on urls starting with /adm/
    5555 * /adm:toor:PaSsWd  # or user toor, pwd PaSsWd on urls starting with /adm/
    5656 * .au:audio/basic   # additional mime type for audio.au files
    57  * *.php:/path/php   # running cgi.php scripts through an interpreter
     57 * *.php:/path/php   # run xxx.php through an interpreter
    5858 *
    5959 * A/D may be as a/d or allow/deny - only first char matters.
    6060 * Deny/Allow IP logic:
     
    9494 * server exits with an error.
    9595 *
    9696 */
     97 /* TODO: use TCP_CORK, parse_config() */
    9798
    9899#include "libbb.h"
    99100#if ENABLE_FEATURE_HTTPD_USE_SENDFILE
    100101# include <sys/sendfile.h>
    101102#endif
    102103
    103 //#define DEBUG 1
    104104#define DEBUG 0
    105105
    106106#define IOBUF_SIZE 8192    /* IO buffer */
     
    115115
    116116#define HEADER_READ_TIMEOUT 60
    117117
    118 static const char default_path_httpd_conf[] ALIGN1 = "/etc";
    119 static const char httpd_conf[] ALIGN1 = "httpd.conf";
     118static const char DEFAULT_PATH_HTTPD_CONF[] ALIGN1 = "/etc";
     119static const char HTTPD_CONF[] ALIGN1 = "httpd.conf";
    120120static const char HTTP_200[] ALIGN1 = "HTTP/1.0 200 OK\r\n";
    121121
    122122typedef struct has_next_ptr {
     
    242242        const char *bind_addr_or_port;
    243243
    244244        const char *g_query;
    245         const char *configFile;
     245        const char *opt_c_configFile;
    246246        const char *home_httpd;
    247247        const char *index_page;
    248248
     
    289289#define rmt_ip            (G.rmt_ip           )
    290290#define bind_addr_or_port (G.bind_addr_or_port)
    291291#define g_query           (G.g_query          )
    292 #define configFile        (G.configFile      )
     292#define opt_c_configFile  (G.opt_c_configFile )
    293293#define home_httpd        (G.home_httpd       )
    294294#define index_page        (G.index_page       )
    295295#define found_mime_type   (G.found_mime_type  )
     
    452452/*
    453453 * Parse configuration file into in-memory linked list.
    454454 *
    455  * The first non-white character is examined to determine if the config line
    456  * is one of the following:
    457  *    .ext:mime/type   # new mime type not compiled into httpd
    458  *    [adAD]:from      # ip address allow/deny, * for wildcard
    459  *    /path:user:pass  # username/password
    460  *    Ennn:error.html  # error page for status nnn
    461  *    P:/url:[http://]hostname[:port]/new/path # reverse proxy
    462  *
    463455 * Any previous IP rules are discarded.
    464456 * If the flag argument is not SUBDIR_PARSE then all /path and mime rules
    465457 * are also discarded.  That is, previous settings are retained if flag is
     
    469461 * path   Path where to look for httpd.conf (without filename).
    470462 * flag   Type of the parse request.
    471463 */
    472 /* flag */
    473 #define FIRST_PARSE          0
    474 #define SUBDIR_PARSE         1
    475 #define SIGNALED_PARSE       2
    476 #define FIND_FROM_HTTPD_ROOT 3
     464/* flag param: */
     465enum {
     466        FIRST_PARSE    = 0, /* path will be "/etc" */
     467        SIGNALED_PARSE = 1, /* path will be "/etc" */
     468        SUBDIR_PARSE   = 2, /* path will be derived from URL */
     469};
    477470static void parse_conf(const char *path, int flag)
    478471{
     472        /* internally used extra flag state */
     473        enum { TRY_CURDIR_PARSE = 3 };
     474
    479475        FILE *f;
    480 #if ENABLE_FEATURE_HTTPD_BASIC_AUTH
    481         Htaccess *prev;
    482 #endif
    483         Htaccess *cur;
    484         const char *filename = configFile;
     476        const char *filename;
    485477        char buf[160];
    486         char *p, *p0;
    487         char *after_colon;
    488         Htaccess_IP *pip;
    489478
    490479        /* discard old rules */
    491480        free_Htaccess_IP_list(&ip_a_d);
    492481        flg_deny_all = 0;
    493482        /* retain previous auth and mime config only for subdir parse */
    494483        if (flag != SUBDIR_PARSE) {
     484                free_Htaccess_list(&mime_a);
    495485#if ENABLE_FEATURE_HTTPD_BASIC_AUTH
    496486                free_Htaccess_list(&g_auth);
    497487#endif
    498                 free_Htaccess_list(&mime_a);
    499488#if ENABLE_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR
    500489                free_Htaccess_list(&script_i);
    501490#endif
    502491        }
    503492
     493        filename = opt_c_configFile;
    504494        if (flag == SUBDIR_PARSE || filename == NULL) {
    505                 filename = alloca(strlen(path) + sizeof(httpd_conf) + 2);
    506                 sprintf((char *)filename, "%s/%s", path, httpd_conf);
     495                filename = alloca(strlen(path) + sizeof(HTTPD_CONF) + 2);
     496                sprintf((char *)filename, "%s/%s", path, HTTPD_CONF);
    507497        }
    508498
    509499        while ((f = fopen_for_read(filename)) == NULL) {
    510                 if (flag == SUBDIR_PARSE || flag == FIND_FROM_HTTPD_ROOT) {
     500                if (flag >= SUBDIR_PARSE) { /* SUBDIR or TRY_CURDIR */
    511501                        /* config file not found, no changes to config */
    512502                        return;
    513503                }
    514                 if (configFile && flag == FIRST_PARSE) /* if -c option given */
    515                         bb_simple_perror_msg_and_die(filename);
    516                 flag = FIND_FROM_HTTPD_ROOT;
    517                 filename = httpd_conf;
     504                if (flag == FIRST_PARSE) {
     505                        /* -c CONFFILE given, but CONFFILE doesn't exist? */
     506                        if (opt_c_configFile)
     507                                bb_simple_perror_msg_and_die(opt_c_configFile);
     508                        /* else: no -c, thus we looked at /etc/httpd.conf,
     509                         * and it's not there. try ./httpd.conf: */
     510                }
     511                flag = TRY_CURDIR_PARSE;
     512                filename = HTTPD_CONF;
    518513        }
    519514
    520515#if ENABLE_FEATURE_HTTPD_BASIC_AUTH
    521         prev = g_auth;
    522 #endif
    523         /* This could stand some work */
    524         while ((p0 = fgets(buf, sizeof(buf), f)) != NULL) {
    525                 after_colon = NULL;
    526                 for (p = p0; *p0 != '\0' && *p0 != '#'; p0++) {
    527                         if (!isspace(*p0)) {
    528                                 *p++ = *p0;
    529                                 if (*p0 == ':' && after_colon == NULL)
    530                                         after_colon = p;
     516        /* in "/file:user:pass" lines, we prepend path in subdirs */
     517        if (flag != SUBDIR_PARSE)
     518                path = "";
     519#endif
     520        /* The lines can be:
     521         *
     522         * I:default_index_file
     523         * H:http_home
     524         * [AD]:IP[/mask]   # allow/deny, * for wildcard
     525         * Ennn:error.html  # error page for status nnn
     526         * P:/url:[http://]hostname[:port]/new/path # reverse proxy
     527         * .ext:mime/type   # mime type
     528         * *.php:/path/php  # run xxx.php through an interpreter
     529         * /file:user:pass  # username and password
     530         */
     531        while (fgets(buf, sizeof(buf), f) != NULL) {
     532                unsigned strlen_buf;
     533                unsigned char ch;
     534                char *after_colon;
     535
     536                { /* remove all whitespace, and # comments */
     537                        char *p, *p0;
     538
     539                        p0 = buf;
     540                        /* skip non-whitespace beginning. Often the whole line
     541                         * is non-whitespace. We want this case to work fast,
     542                         * without needless copying, therefore we don't merge
     543                         * this operation into next while loop. */
     544                        while ((ch = *p0) != '\0' && ch != '\n' && ch != '#'
     545                         && ch != ' ' && ch != '\t'
     546                        ) {
     547                                p0++;
     548                        }
     549                        p = p0;
     550                        /* if we enter this loop, we have some whitespace.
     551                         * discard it */
     552                        while (ch != '\0' && ch != '\n' && ch != '#') {
     553                                if (ch != ' ' && ch != '\t') {
     554                                        *p++ = ch;
     555                                }
     556                                ch = *++p0;
    531557                        }
     558                        *p = '\0';
     559                        strlen_buf = p - buf;
     560                        if (strlen_buf == 0)
     561                                continue; /* empty line */
    532562                }
    533                 *p = '\0';
    534563
    535                 /* test for empty or strange line */
    536                 if (after_colon == NULL || *after_colon == '\0')
     564                after_colon = strchr(buf, ':');
     565                /* strange line? */
     566                if (after_colon == NULL || *++after_colon == '\0')
     567                        goto config_error;
     568
     569                ch = (buf[0] & ~0x20); /* toupper if it's a letter */
     570
     571                if (ch == 'I') {
     572                        index_page = xstrdup(after_colon);
    537573                        continue;
    538                 p0 = buf;
    539                 if (*p0 == 'd' || *p0 == 'a')
    540                         *p0 -= 0x20; /* a/d -> A/D */
    541                 if (*after_colon == '*') {
    542                         if (*p0 == 'D') {
    543                                 /* memorize "deny all" */
    544                                 flg_deny_all = 1;
    545                         }
    546                         /* skip assumed "A:*", it is a default anyway */
     574                }
     575
     576                /* do not allow jumping around using H in subdir's configs */
     577                if (flag == FIRST_PARSE && ch == 'H') {
     578                        home_httpd = xstrdup(after_colon);
     579                        xchdir(home_httpd);
    547580                        continue;
    548581                }
    549582
    550                 if (*p0 == 'A' || *p0 == 'D') {
    551                         /* storing current config IP line */
    552                         pip = xzalloc(sizeof(Htaccess_IP));
    553                         if (scan_ip_mask(after_colon, &(pip->ip), &(pip->mask))) {
     583                if (ch == 'A' || ch == 'D') {
     584                        Htaccess_IP *pip;
     585
     586                        if (*after_colon == '*') {
     587                                if (ch == 'D') {
     588                                        /* memorize "deny all" */
     589                                        flg_deny_all = 1;
     590                                }
     591                                /* skip assumed "A:*", it is a default anyway */
     592                                continue;
     593                        }
     594                        /* store "allow/deny IP/mask" line */
     595                        pip = xzalloc(sizeof(*pip));
     596                        if (scan_ip_mask(after_colon, &pip->ip, &pip->mask)) {
    554597                                /* IP{/mask} syntax error detected, protect all */
    555                                 *p0 = 'D';
     598                                ch = 'D';
    556599                                pip->mask = 0;
    557600                        }
    558                         pip->allow_deny = *p0;
    559                         if (*p0 == 'D') {
     601                        pip->allow_deny = ch;
     602                        if (ch == 'D') {
    560603                                /* Deny:from_IP - prepend */
    561604                                pip->next = ip_a_d;
    562605                                ip_a_d = pip;
    563606                        } else {
    564                                 /* A:from_IP - append (thus D precedes A) */
     607                                /* A:from_IP - append (thus all D's precedes A's) */
    565608                                Htaccess_IP *prev_IP = ip_a_d;
    566609                                if (prev_IP == NULL) {
    567610                                        ip_a_d = pip;
     
    575618                }
    576619
    577620#if ENABLE_FEATURE_HTTPD_ERROR_PAGES
    578                 if (flag == FIRST_PARSE && *p0 == 'E') {
     621                if (flag == FIRST_PARSE && ch == 'E') {
    579622                        unsigned i;
    580                         int status = atoi(++p0); /* error status code */
     623                        int status = atoi(buf + 1); /* error status code */
     624
    581625                        if (status < HTTP_CONTINUE) {
    582                                 bb_error_msg("config error '%s' in '%s'", buf, filename);
    583                                 continue;
     626                                goto config_error;
    584627                        }
    585628                        /* then error page; find matching status */
    586629                        for (i = 0; i < ARRAY_SIZE(http_response_type); i++) {
     
    597640#endif
    598641
    599642#if ENABLE_FEATURE_HTTPD_PROXY
    600                 if (flag == FIRST_PARSE && *p0 == 'P') {
     643                if (flag == FIRST_PARSE && ch == 'P') {
    601644                        /* P:/url:[http://]hostname[:port]/new/path */
    602645                        char *url_from, *host_port, *url_to;
    603646                        Htaccess_Proxy *proxy_entry;
     
    605648                        url_from = after_colon;
    606649                        host_port = strchr(after_colon, ':');
    607650                        if (host_port == NULL) {
    608                                 bb_error_msg("config error '%s' in '%s'", buf, filename);
    609                                 continue;
     651                                goto config_error;
    610652                        }
    611653                        *host_port++ = '\0';
    612654                        if (strncmp(host_port, "http://", 7) == 0)
    613655                                host_port += 7;
    614656                        if (*host_port == '\0') {
    615                                 bb_error_msg("config error '%s' in '%s'", buf, filename);
    616                                 continue;
     657                                goto config_error;
    617658                        }
    618659                        url_to = strchr(host_port, '/');
    619660                        if (url_to == NULL) {
    620                                 bb_error_msg("config error '%s' in '%s'", buf, filename);
    621                                 continue;
     661                                goto config_error;
    622662                        }
    623663                        *url_to = '\0';
    624                         proxy_entry = xzalloc(sizeof(Htaccess_Proxy));
     664                        proxy_entry = xzalloc(sizeof(*proxy_entry));
    625665                        proxy_entry->url_from = xstrdup(url_from);
    626666                        proxy_entry->host_port = xstrdup(host_port);
    627667                        *url_to = '/';
     
    631671                        continue;
    632672                }
    633673#endif
     674                /* the rest of directives are non-alphabetic,
     675                 * must avoid using "toupper'ed" ch */
     676                ch = buf[0];
    634677
    635 #if ENABLE_FEATURE_HTTPD_BASIC_AUTH
    636                 if (*p0 == '/') {
    637                         /* make full path from httpd root / current_path / config_line_path */
    638                         const char *tp = (flag == SUBDIR_PARSE ? path : "");
    639                         p0 = xmalloc(strlen(tp) + (after_colon - buf) + 2 + strlen(after_colon));
    640                         after_colon[-1] = '\0';
    641                         sprintf(p0, "/%s%s", tp, buf);
    642 
    643                         /* looks like bb_simplify_path... */
    644                         tp = p = p0;
    645                         do {
    646                                 if (*p == '/') {
    647                                         if (*tp == '/') {    /* skip duplicate (or initial) slash */
    648                                                 continue;
    649                                         }
    650                                         if (*tp == '.') {
    651                                                 if (tp[1] == '/' || tp[1] == '\0') { /* remove extra '.' */
    652                                                         continue;
    653                                                 }
    654                                                 if ((tp[1] == '.') && (tp[2] == '/' || tp[2] == '\0')) {
    655                                                         ++tp;
    656                                                         if (p > p0) {
    657                                                                 while (*--p != '/') /* omit previous dir */
    658                                                                         continue;
    659                                                         }
    660                                                         continue;
    661                                                 }
    662                                         }
    663                                 }
    664                                 *++p = *tp;
    665                         } while (*++tp);
     678                if (ch == '.' /* ".ext:mime/type" */
     679#if ENABLE_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR
     680                 || (ch == '*' && buf[1] == '.') /* "*.php:/path/php" */
     681#endif
     682                ) {
     683                        char *p;
     684                        Htaccess *cur;
    666685
    667                         if ((p == p0) || (*p != '/')) { /* not a trailing slash */
    668                                 ++p;                    /* so keep last character */
     686                        cur = xzalloc(sizeof(*cur) /* includes space for NUL */ + strlen_buf);
     687                        strcpy(cur->before_colon, buf);
     688                        p = cur->before_colon + (after_colon - buf);
     689                        p[-1] = '\0';
     690                        cur->after_colon = p;
     691                        if (ch == '.') {
     692                                /* .mime line: prepend to mime_a list */
     693                                cur->next = mime_a;
     694                                mime_a = cur;
     695                        }
     696#if ENABLE_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR
     697                        else {
     698                                /* script interpreter line: prepend to script_i list */
     699                                cur->next = script_i;
     700                                script_i = cur;
    669701                        }
    670                         *p = ':';
    671                         strcpy(p + 1, after_colon);
    672                 }
    673702#endif
    674                 if (*p0 == 'I') {
    675                         index_page = xstrdup(after_colon);
    676                         continue;
    677                 }
    678 
    679                 /* Do not allow jumping around using H in subdir's configs */
    680                 if (flag == FIRST_PARSE && *p0 == 'H') {
    681                         home_httpd = xstrdup(after_colon);
    682                         xchdir(home_httpd);
    683703                        continue;
    684704                }
    685705
    686                 /* storing current config line */
    687                 cur = xzalloc(sizeof(Htaccess) + strlen(p0));
    688                 strcpy(cur->before_colon, p0);
    689 #if ENABLE_FEATURE_HTTPD_BASIC_AUTH
    690                 if (*p0 == '/') /* was malloced - see above */
    691                         free(p0);
    692 #endif
    693                 cur->after_colon = strchr(cur->before_colon, ':');
    694                 *cur->after_colon++ = '\0';
    695                 if (cur->before_colon[0] == '.') {
    696                         /* .mime line: prepend to mime_a list */
    697                         cur->next = mime_a;
    698                         mime_a = cur;
    699                         continue;
    700                 }
    701 #if ENABLE_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR
    702                 if (cur->before_colon[0] == '*' && cur->before_colon[1] == '.') {
    703                         /* script interpreter line: prepend to script_i list */
    704                         cur->next = script_i;
    705                         script_i = cur;
    706                         continue;
    707                 }
    708 #endif
    709706#if ENABLE_FEATURE_HTTPD_BASIC_AUTH
    710 //TODO: we do not test for leading "/"??
    711 //also, do we leak cur if BASIC_AUTH is off?
    712                 if (prev == NULL) {
    713                         /* first line */
    714                         g_auth = prev = cur;
    715                 } else {
    716                         /* sort path, if current length eq or bigger then move up */
    717                         Htaccess *prev_hti = g_auth;
    718                         size_t l = strlen(cur->before_colon);
    719                         Htaccess *hti;
    720 
    721                         for (hti = prev_hti; hti; hti = hti->next) {
    722                                 if (l >= strlen(hti->before_colon)) {
    723                                         /* insert before hti */
    724                                         cur->next = hti;
    725                                         if (prev_hti != hti) {
    726                                                 prev_hti->next = cur;
    727                                         } else {
    728                                                 /* insert as top */
    729                                                 g_auth = cur;
     707                if (ch == '/') { /* "/file:user:pass" */
     708                        char *p;
     709                        Htaccess *cur;
     710                        unsigned file_len;
     711
     712                        /* note: path is "" unless we are in SUBDIR parse,
     713                         * otherwise it does NOT start with "/" */
     714                        cur = xzalloc(sizeof(*cur) /* includes space for NUL */
     715                                + 1 + strlen(path)
     716                                + strlen_buf
     717                                );
     718                        /* form "/path/file" */
     719                        sprintf(cur->before_colon, "/%s%.*s",
     720                                path,
     721                                (int) (after_colon - buf - 1), /* includes "/", but not ":" */
     722                                buf);
     723                        /* canonicalize it */
     724                        p = bb_simplify_abs_path_inplace(cur->before_colon);
     725                        file_len = p - cur->before_colon;
     726                        /* add "user:pass" after NUL */
     727                        strcpy(++p, after_colon);
     728                        cur->after_colon = p;
     729
     730                        /* insert cur into g_auth */
     731                        /* g_auth is sorted by decreased filename length */
     732                        {
     733                                Htaccess *auth, **authp;
     734
     735                                authp = &g_auth;
     736                                while ((auth = *authp) != NULL) {
     737                                        if (file_len >= strlen(auth->before_colon)) {
     738                                                /* insert cur before auth */
     739                                                cur->next = auth;
     740                                                break;
    730741                                        }
    731                                         break;
     742                                        authp = &auth->next;
    732743                                }
    733                                 if (prev_hti != hti)
    734                                         prev_hti = prev_hti->next;
    735                         }
    736                         if (!hti) {       /* not inserted, add to bottom */
    737                                 prev->next = cur;
    738                                 prev = cur;
     744                                *authp = cur;
    739745                        }
     746                        continue;
    740747                }
    741748#endif /* BASIC_AUTH */
     749
     750                /* the line is not recognized */
     751 config_error:
     752                bb_error_msg("config error '%s' in '%s'", buf, filename);
    742753         } /* while (fgets) */
     754
    743755         fclose(f);
    744756}
    745757
     
    15271539                        send_headers_and_exit(HTTP_NOT_FOUND);
    15281540                log_and_exit();
    15291541        }
    1530 
    1531         if (DEBUG)
    1532                 bb_error_msg("sending file '%s' content-type: %s",
    1533                         url, found_mime_type);
    1534 
    15351542        /* If you want to know about EPIPE below
    15361543         * (happens if you abort downloads from local httpd): */
    15371544        signal(SIGPIPE, SIG_IGN);
     
    15591566                        }
    15601567                }
    15611568        }
     1569
     1570        if (DEBUG)
     1571                bb_error_msg("sending file '%s' content-type: %s",
     1572                        url, found_mime_type);
     1573
    15621574#if ENABLE_FEATURE_HTTPD_RANGES
    15631575        if (what == SEND_BODY)
    15641576                range_start = 0; /* err pages and ranges don't mix */
     
    20312043        /* We are done reading headers, disable peer timeout */
    20322044        alarm(0);
    20332045
    2034         if (strcmp(bb_basename(urlcopy), httpd_conf) == 0 || !ip_allowed) {
    2035                 /* protect listing [/path]/httpd_conf or IP deny */
     2046        if (strcmp(bb_basename(urlcopy), HTTPD_CONF) == 0 || !ip_allowed) {
     2047                /* protect listing [/path]/httpd.conf or IP deny */
    20362048                send_headers_and_exit(HTTP_FORBIDDEN);
    20372049        }
    20382050
     
    20742086                header_ptr += 2;
    20752087                write(proxy_fd, header_buf, header_ptr - header_buf);
    20762088                free(header_buf); /* on the order of 8k, free it */
    2077                 /* cgi_io_loop_and_exit needs to have two disctinct fds */
     2089                /* cgi_io_loop_and_exit needs to have two distinct fds */
    20782090                cgi_io_loop_and_exit(proxy_fd, dup(proxy_fd), length);
    20792091        }
    20802092#endif
     
    22452257
    22462258static void sighup_handler(int sig UNUSED_PARAM)
    22472259{
    2248         parse_conf(default_path_httpd_conf, SIGNALED_PARSE);
     2260        parse_conf(DEFAULT_PATH_HTTPD_CONF, SIGNALED_PARSE);
    22492261}
    22502262
    22512263enum {
     
    23042316                        USE_FEATURE_HTTPD_AUTH_MD5("m:")
    23052317                        USE_FEATURE_HTTPD_SETUID("u:")
    23062318                        "p:ifv",
    2307                         &configFile, &url_for_decode, &home_httpd
     2319                        &opt_c_configFile, &url_for_decode, &home_httpd
    23082320                        USE_FEATURE_HTTPD_ENCODE_URL_STR(, &url_for_encode)
    23092321                        USE_FEATURE_HTTPD_BASIC_AUTH(, &g_realm)
    23102322                        USE_FEATURE_HTTPD_AUTH_MD5(, &pass)
     
    23752387        }
    23762388#endif
    23772389
    2378         parse_conf(default_path_httpd_conf, FIRST_PARSE);
     2390        parse_conf(DEFAULT_PATH_HTTPD_CONF, FIRST_PARSE);
    23792391        if (!(opt & OPT_INETD))
    23802392                signal(SIGHUP, sighup_handler);
    23812393
  • networking/telnetd.c

    diff -ru busybox-1.14.1/networking/telnetd.c busybox-1.14.1-fixed/networking/telnetd.c
    old new  
    199199        return total + rc;
    200200}
    201201
     202/* Must match getopt32 string */
     203enum {
     204        OPT_WATCHCHILD = (1 << 2), /* -K */
     205        OPT_INETD      = (1 << 3) * ENABLE_FEATURE_TELNETD_STANDALONE, /* -i */
     206        OPT_PORT       = (1 << 4) * ENABLE_FEATURE_TELNETD_STANDALONE, /* -p */
     207        OPT_FOREGROUND = (1 << 6) * ENABLE_FEATURE_TELNETD_STANDALONE, /* -F */
     208};
     209
    202210static struct tsession *
    203211make_new_session(
    204                 USE_FEATURE_TELNETD_STANDALONE(int sock)
     212                USE_FEATURE_TELNETD_STANDALONE(int master_fd, int sock)
    205213                SKIP_FEATURE_TELNETD_STANDALONE(void)
    206214) {
    207215        const char *login_argv[2];
     
    288296        /* Restore default signal handling ASAP */
    289297        bb_signals((1 << SIGCHLD) + (1 << SIGPIPE), SIG_DFL);
    290298
     299#if ENABLE_FEATURE_TELNETD_STANDALONE
     300        if (!(option_mask32 & OPT_INETD)) {
     301                struct tsession *tp = sessions;
     302                while (tp) {
     303                        close(tp->ptyfd);
     304                        close(tp->sockfd_read);
     305                        /* sockfd_write == sockfd_read for standalone telnetd */
     306                        /*close(tp->sockfd_write);*/
     307                        tp = tp->next;
     308                }
     309        }
     310#endif
     311
    291312        /* Make new session and process group */
    292313        setsid();
    293314
     315        close(fd);
     316#if ENABLE_FEATURE_TELNETD_STANDALONE
     317        close(sock);
     318        if (master_fd >= 0)
     319                close(master_fd);
     320#endif
     321
    294322        /* Open the child's side of the tty. */
    295323        /* NB: setsid() disconnects from any previous ctty's. Therefore
    296324         * we must open child's side of the tty AFTER setsid! */
     
    329357        _exit(EXIT_FAILURE); /*bb_perror_msg_and_die("execv %s", loginpath);*/
    330358}
    331359
    332 /* Must match getopt32 string */
    333 enum {
    334         OPT_WATCHCHILD = (1 << 2), /* -K */
    335         OPT_INETD      = (1 << 3) * ENABLE_FEATURE_TELNETD_STANDALONE, /* -i */
    336         OPT_PORT       = (1 << 4) * ENABLE_FEATURE_TELNETD_STANDALONE, /* -p */
    337         OPT_FOREGROUND = (1 << 6) * ENABLE_FEATURE_TELNETD_STANDALONE, /* -F */
    338 };
    339 
    340360#if ENABLE_FEATURE_TELNETD_STANDALONE
    341361
    342362static void
     
    465485
    466486#if ENABLE_FEATURE_TELNETD_STANDALONE
    467487        if (IS_INETD) {
    468                 sessions = make_new_session(0);
     488                sessions = make_new_session(-1, 0);
    469489                if (!sessions) /* pty opening or vfork problem, exit */
    470490                        return 1; /* make_new_session prints error message */
    471491        } else {
     
    553573                if (fd < 0)
    554574                        goto again;
    555575                /* Create a new session and link it into our active list */
    556                 new_ts = make_new_session(fd);
     576                new_ts = make_new_session(master_fd, fd);
    557577                if (new_ts) {
    558578                        new_ts->next = sessions;
    559579                        sessions = new_ts;
  • busybox-1.14.

    diff -ru busybox-1.14.1/shell/ash.c busybox-1.14.1-fixed/shell/ash.c
    old new  
    1190911909                         */
    1191011910                        return fullname;
    1191111911                }
    11912                 stunalloc(fullname);
     11912                if (fullname != name)
     11913                        stunalloc(fullname);
    1191311914        }
    1191411915
    1191511916        /* not found in the PATH */
Note: See TracBrowser for help on using the repository browser.