Changeset 1770 in MondoRescue for branches/stable/mindi-busybox/libbb/parse_mode.c
- Timestamp:
- Nov 6, 2007, 11:01:53 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mindi-busybox/libbb/parse_mode.c
r821 r1770 5 5 * Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org> 6 6 * 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. 21 8 */ 22 9 23 10 /* http://www.opengroup.org/onlinepubs/007904975/utilities/chmod.html */ 24 11 25 #include <stdlib.h>26 #include <assert.h>27 #include <sys/stat.h>28 12 #include "libbb.h" 29 13 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) 31 17 32 18 int bb_parse_mode(const char *s, mode_t *current_mode) … … 34 20 static const mode_t who_mask[] = { 35 21 S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO, /* a */ 36 S_ISUID | S_IRWXU, 37 S_ISGID | S_IRWXG, 38 S_IRWXO 22 S_ISUID | S_IRWXU, /* u */ 23 S_ISGID | S_IRWXG, /* g */ 24 S_IRWXO /* o */ 39 25 }; 40 41 26 static const mode_t perm_mask[] = { 42 27 S_IRUSR | S_IRGRP | S_IROTH, /* r */ … … 44 29 S_IXUSR | S_IXGRP | S_IXOTH, /* x */ 45 30 S_IXUSR | S_IXGRP | S_IXOTH, /* X -- special -- see below */ 46 S_ISUID | S_ISGID, 47 S_ISVTX 31 S_ISUID | S_ISGID, /* s */ 32 S_ISVTX /* t */ 48 33 }; 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"; 52 36 53 37 const char *p; 54 55 38 mode_t wholist; 56 39 mode_t permlist; 57 mode_t mask;58 40 mode_t new_mode; 59 41 char op; 60 61 assert(s);62 42 63 43 if (((unsigned int)(*s - '0')) < 8) { … … 65 45 char *e; 66 46 67 tmp = strto l(s, &e, 8);47 tmp = strtoul(s, &e, 8); 68 48 if (*e || (tmp > 07777U)) { /* Check range and trailing chars. */ 69 49 return 0; … … 73 53 } 74 54 75 mask = umask(0);76 umask(mask);77 78 55 new_mode = *current_mode; 79 56 80 /* Note: We allow empty clauses, and hence empty modes.57 /* Note: we allow empty clauses, and hence empty modes. 81 58 * We treat an empty mode as no change to perms. */ 82 59 83 60 while (*s) { /* Process clauses. */ 84 85 61 if (*s == ',') { /* We allow empty clauses. */ 86 62 ++s; … … 90 66 /* Get a wholist. */ 91 67 wholist = 0; 92 93 WHO_LIST: 68 WHO_LIST: 94 69 p = who_chars; 95 70 do { … … 109 84 } 110 85 /* Since op is '=', clear all bits corresponding to the 111 * wholist, o fall file bits if wholist is empty. */86 * wholist, or all file bits if wholist is empty. */ 112 87 permlist = ~FILEMODEBITS; 113 88 if (wholist) { … … 138 113 /* It was not a permcopy, so get a permlist. */ 139 114 permlist = 0; 140 141 PERM_LIST: 115 PERM_LIST: 142 116 p = perm_chars; 143 117 do { 144 118 if (*p == *s) { 145 119 if ((*p != 'X') 146 120 || (new_mode & (S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH)) 147 121 ) { 148 122 permlist |= perm_mask[(int)(p-perm_chars)]; … … 154 128 } 155 129 } while (*++p); 156 157 GOT_ACTION: 130 GOT_ACTION: 158 131 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; 162 137 } 163 138 permlist &= tmp; 164 165 139 if (op == '-') { 166 140 new_mode &= ~permlist; … … 173 147 174 148 *current_mode = new_mode; 175 176 149 return 1; 177 150 }
Note:
See TracChangeset
for help on using the changeset viewer.