Ignore:
Timestamp:
Nov 4, 2007, 3:16:40 AM (17 years ago)
Author:
Bruno Cornec
Message:

Update to busybox 1.7.2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.5/mindi-busybox/libbb/parse_mode.c

    r821 r1765  
    55 * Copyright (C) 2003  Manuel Novoa III  <mjn3@codepoet.org>
    66 *
    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.
    11  *
    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 GNU
    15  * General Public License for more details.
    16  *
    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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    20  *
     7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
    218 */
    229
    2310/* http://www.opengroup.org/onlinepubs/007904975/utilities/chmod.html */
    2411
    25 #include <stdlib.h>
    26 #include <assert.h>
    27 #include <sys/stat.h>
    2812#include "libbb.h"
    2913
    30 #define FILEMODEBITS    (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO)
     14/* This function is used from NOFORK applets. It must not allocate anything */
     15
     16#define FILEMODEBITS (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO)
    3117
    3218int bb_parse_mode(const char *s, mode_t *current_mode)
     
    3420    static const mode_t who_mask[] = {
    3521        S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO, /* a */
    36         S_ISUID | S_IRWXU,      /* u */
    37         S_ISGID | S_IRWXG,      /* g */
    38         S_IRWXO                 /* o */
     22        S_ISUID | S_IRWXU,           /* u */
     23        S_ISGID | S_IRWXG,           /* g */
     24        S_IRWXO                      /* o */
    3925    };
    40 
    4126    static const mode_t perm_mask[] = {
    4227        S_IRUSR | S_IRGRP | S_IROTH, /* r */
     
    4429        S_IXUSR | S_IXGRP | S_IXOTH, /* x */
    4530        S_IXUSR | S_IXGRP | S_IXOTH, /* X -- special -- see below */
    46         S_ISUID | S_ISGID,      /* s */
    47         S_ISVTX                 /* t */
     31        S_ISUID | S_ISGID,           /* s */
     32        S_ISVTX                      /* t */
    4833    };
    49 
    50     static const char who_chars[] = "augo";
    51     static const char perm_chars[] = "rwxXst";
     34    static const char who_chars[] ALIGN1 = "augo";
     35    static const char perm_chars[] ALIGN1 = "rwxXst";
    5236
    5337    const char *p;
    54 
    5538    mode_t wholist;
    5639    mode_t permlist;
    57     mode_t mask;
    5840    mode_t new_mode;
    5941    char op;
    60 
    61     assert(s);
    6242
    6343    if (((unsigned int)(*s - '0')) < 8) {
     
    6545        char *e;
    6646
    67         tmp = strtol(s, &e, 8);
     47        tmp = strtoul(s, &e, 8);
    6848        if (*e || (tmp > 07777U)) { /* Check range and trailing chars. */
    6949            return 0;
     
    7353    }
    7454
    75     mask = umask(0);
    76     umask(mask);
    77 
    7855    new_mode = *current_mode;
    7956
    80     /* Note: We allow empty clauses, and hence empty modes.
     57    /* Note: we allow empty clauses, and hence empty modes.
    8158     * We treat an empty mode as no change to perms. */
    8259
    8360    while (*s) {    /* Process clauses. */
    84 
    8561        if (*s == ',') {    /* We allow empty clauses. */
    8662            ++s;
     
    9066        /* Get a wholist. */
    9167        wholist = 0;
    92 
    93     WHO_LIST:
     68 WHO_LIST:
    9469        p = who_chars;
    9570        do {
     
    10984                }
    11085                /* Since op is '=', clear all bits corresponding to the
    111                  * wholist, of all file bits if wholist is empty. */
     86                 * wholist, or all file bits if wholist is empty. */
    11287                permlist = ~FILEMODEBITS;
    11388                if (wholist) {
     
    138113            /* It was not a permcopy, so get a permlist. */
    139114            permlist = 0;
    140 
    141         PERM_LIST:
     115 PERM_LIST:
    142116            p = perm_chars;
    143117            do {
    144118                if (*p == *s) {
    145119                    if ((*p != 'X')
    146                         || (new_mode & (S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH))
     120                     || (new_mode & (S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH))
    147121                    ) {
    148122                        permlist |= perm_mask[(int)(p-perm_chars)];
     
    154128                }
    155129            } while (*++p);
    156 
    157         GOT_ACTION:
     130 GOT_ACTION:
    158131            if (permlist) { /* The permlist was nonempty. */
    159                 mode_t tmp = ~mask;
    160                 if (wholist) {
    161                     tmp = wholist;
     132                mode_t tmp = wholist;
     133                if (!wholist) {
     134                    mode_t u_mask = umask(0);
     135                    umask(u_mask);
     136                    tmp = ~u_mask;
    162137                }
    163138                permlist &= tmp;
    164 
    165139                if (op == '-') {
    166140                    new_mode &= ~permlist;
     
    173147
    174148    *current_mode = new_mode;
    175 
    176149    return 1;
    177150}
Note: See TracChangeset for help on using the changeset viewer.