mirror of
https://github.com/topjohnwu/ndk-busybox.git
synced 2025-02-12 15:08:23 +00:00
bb_parse_mode: do not do umask() needlessly.
This commit is contained in:
parent
f98d637ba4
commit
86724af484
@ -9,9 +9,6 @@
|
|||||||
|
|
||||||
/* http://www.opengroup.org/onlinepubs/007904975/utilities/chmod.html */
|
/* http://www.opengroup.org/onlinepubs/007904975/utilities/chmod.html */
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <assert.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include "libbb.h"
|
#include "libbb.h"
|
||||||
|
|
||||||
#define FILEMODEBITS (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO)
|
#define FILEMODEBITS (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO)
|
||||||
@ -24,7 +21,6 @@ int bb_parse_mode(const char *s, mode_t *current_mode)
|
|||||||
S_ISGID | S_IRWXG, /* g */
|
S_ISGID | S_IRWXG, /* g */
|
||||||
S_IRWXO /* o */
|
S_IRWXO /* o */
|
||||||
};
|
};
|
||||||
|
|
||||||
static const mode_t perm_mask[] = {
|
static const mode_t perm_mask[] = {
|
||||||
S_IRUSR | S_IRGRP | S_IROTH, /* r */
|
S_IRUSR | S_IRGRP | S_IROTH, /* r */
|
||||||
S_IWUSR | S_IWGRP | S_IWOTH, /* w */
|
S_IWUSR | S_IWGRP | S_IWOTH, /* w */
|
||||||
@ -33,25 +29,20 @@ int bb_parse_mode(const char *s, mode_t *current_mode)
|
|||||||
S_ISUID | S_ISGID, /* s */
|
S_ISUID | S_ISGID, /* s */
|
||||||
S_ISVTX /* t */
|
S_ISVTX /* t */
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char who_chars[] = "augo";
|
static const char who_chars[] = "augo";
|
||||||
static const char perm_chars[] = "rwxXst";
|
static const char perm_chars[] = "rwxXst";
|
||||||
|
|
||||||
const char *p;
|
const char *p;
|
||||||
|
|
||||||
mode_t wholist;
|
mode_t wholist;
|
||||||
mode_t permlist;
|
mode_t permlist;
|
||||||
mode_t mask;
|
|
||||||
mode_t new_mode;
|
mode_t new_mode;
|
||||||
char op;
|
char op;
|
||||||
|
|
||||||
assert(s);
|
|
||||||
|
|
||||||
if (((unsigned int)(*s - '0')) < 8) {
|
if (((unsigned int)(*s - '0')) < 8) {
|
||||||
unsigned long tmp;
|
unsigned long tmp;
|
||||||
char *e;
|
char *e;
|
||||||
|
|
||||||
tmp = strtol(s, &e, 8);
|
tmp = strtoul(s, &e, 8);
|
||||||
if (*e || (tmp > 07777U)) { /* Check range and trailing chars. */
|
if (*e || (tmp > 07777U)) { /* Check range and trailing chars. */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -59,16 +50,12 @@ int bb_parse_mode(const char *s, mode_t *current_mode)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
mask = umask(0);
|
|
||||||
umask(mask);
|
|
||||||
|
|
||||||
new_mode = *current_mode;
|
new_mode = *current_mode;
|
||||||
|
|
||||||
/* Note: We allow empty clauses, and hence empty modes.
|
/* Note: we allow empty clauses, and hence empty modes.
|
||||||
* We treat an empty mode as no change to perms. */
|
* We treat an empty mode as no change to perms. */
|
||||||
|
|
||||||
while (*s) { /* Process clauses. */
|
while (*s) { /* Process clauses. */
|
||||||
|
|
||||||
if (*s == ',') { /* We allow empty clauses. */
|
if (*s == ',') { /* We allow empty clauses. */
|
||||||
++s;
|
++s;
|
||||||
continue;
|
continue;
|
||||||
@ -76,7 +63,6 @@ int bb_parse_mode(const char *s, mode_t *current_mode)
|
|||||||
|
|
||||||
/* Get a wholist. */
|
/* Get a wholist. */
|
||||||
wholist = 0;
|
wholist = 0;
|
||||||
|
|
||||||
WHO_LIST:
|
WHO_LIST:
|
||||||
p = who_chars;
|
p = who_chars;
|
||||||
do {
|
do {
|
||||||
@ -95,7 +81,7 @@ int bb_parse_mode(const char *s, mode_t *current_mode)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* Since op is '=', clear all bits corresponding to the
|
/* Since op is '=', clear all bits corresponding to the
|
||||||
* wholist, of all file bits if wholist is empty. */
|
* wholist, or all file bits if wholist is empty. */
|
||||||
permlist = ~FILEMODEBITS;
|
permlist = ~FILEMODEBITS;
|
||||||
if (wholist) {
|
if (wholist) {
|
||||||
permlist = ~wholist;
|
permlist = ~wholist;
|
||||||
@ -124,7 +110,6 @@ int bb_parse_mode(const char *s, mode_t *current_mode)
|
|||||||
|
|
||||||
/* It was not a permcopy, so get a permlist. */
|
/* It was not a permcopy, so get a permlist. */
|
||||||
permlist = 0;
|
permlist = 0;
|
||||||
|
|
||||||
PERM_LIST:
|
PERM_LIST:
|
||||||
p = perm_chars;
|
p = perm_chars;
|
||||||
do {
|
do {
|
||||||
@ -140,15 +125,15 @@ int bb_parse_mode(const char *s, mode_t *current_mode)
|
|||||||
goto PERM_LIST;
|
goto PERM_LIST;
|
||||||
}
|
}
|
||||||
} while (*++p);
|
} while (*++p);
|
||||||
|
|
||||||
GOT_ACTION:
|
GOT_ACTION:
|
||||||
if (permlist) { /* The permlist was nonempty. */
|
if (permlist) { /* The permlist was nonempty. */
|
||||||
mode_t tmp = ~mask;
|
mode_t tmp = wholist;
|
||||||
if (wholist) {
|
if (!wholist) {
|
||||||
tmp = wholist;
|
mode_t u_mask = umask(0);
|
||||||
|
umask(u_mask);
|
||||||
|
tmp = ~u_mask;
|
||||||
}
|
}
|
||||||
permlist &= tmp;
|
permlist &= tmp;
|
||||||
|
|
||||||
if (op == '-') {
|
if (op == '-') {
|
||||||
new_mode &= ~permlist;
|
new_mode &= ~permlist;
|
||||||
} else {
|
} else {
|
||||||
@ -159,6 +144,5 @@ int bb_parse_mode(const char *s, mode_t *current_mode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
*current_mode = new_mode;
|
*current_mode = new_mode;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user