diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2015-10-19 04:27:17 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2015-10-19 04:27:17 +0200 |
commit | 526d85831e7480b9c7a3673d8dd356a438e6dd74 (patch) | |
tree | 0063fe2362ecaf3252ccf2a5042bf541546eedd6 /libpwdgrp | |
parent | f3d58a29be7cbf5c0bf94f1a12ac747f706b3d99 (diff) |
libbb: get_uidgid() always called with allow_numeric=1
function old new delta
xget_uidgid 30 25 -5
make_device 2188 2183 -5
main 797 792 -5
get_uidgid 240 225 -15
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libpwdgrp')
-rw-r--r-- | libpwdgrp/uidgid_get.c | 42 |
1 files changed, 19 insertions, 23 deletions
diff --git a/libpwdgrp/uidgid_get.c b/libpwdgrp/uidgid_get.c index 8388be0da..eeb65191f 100644 --- a/libpwdgrp/uidgid_get.c +++ b/libpwdgrp/uidgid_get.c @@ -28,7 +28,7 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "libbb.h" /* Always sets uid and gid */ -int FAST_FUNC get_uidgid(struct bb_uidgid_t *u, const char *ug, int numeric_ok) +int FAST_FUNC get_uidgid(struct bb_uidgid_t *u, const char *ug) { struct passwd *pwd; struct group *gr; @@ -43,18 +43,16 @@ int FAST_FUNC get_uidgid(struct bb_uidgid_t *u, const char *ug, int numeric_ok) /* copies sz-1 bytes, stores terminating '\0' */ safe_strncpy(user, ug, sz); } - if (numeric_ok) { - n = bb_strtou(user, NULL, 10); - if (!errno) { - u->uid = n; - pwd = getpwuid(n); - /* If we have e.g. "500" string without user */ - /* with uid 500 in /etc/passwd, we set gid == uid */ - u->gid = pwd ? pwd->pw_gid : n; - goto skip; - } + n = bb_strtou(user, NULL, 10); + if (!errno) { + u->uid = n; + pwd = getpwuid(n); + /* If we have e.g. "500" string without user */ + /* with uid 500 in /etc/passwd, we set gid == uid */ + u->gid = pwd ? pwd->pw_gid : n; + goto skip; } - /* Either it is not numeric, or caller disallows numeric username */ + /* it is not numeric */ pwd = getpwnam(user); if (!pwd) return 0; @@ -63,12 +61,10 @@ int FAST_FUNC get_uidgid(struct bb_uidgid_t *u, const char *ug, int numeric_ok) skip: if (group) { - if (numeric_ok) { - n = bb_strtou(group, NULL, 10); - if (!errno) { - u->gid = n; - return 1; - } + n = bb_strtou(group, NULL, 10); + if (!errno) { + u->gid = n; + return 1; } gr = getgrnam(group); if (!gr) @@ -79,7 +75,7 @@ int FAST_FUNC get_uidgid(struct bb_uidgid_t *u, const char *ug, int numeric_ok) } void FAST_FUNC xget_uidgid(struct bb_uidgid_t *u, const char *ug) { - if (!get_uidgid(u, ug, 1)) + if (!get_uidgid(u, ug)) bb_error_msg_and_die("unknown user/group %s", ug); } @@ -119,16 +115,16 @@ int main() { unsigned u; struct bb_uidgid_t ug; - u = get_uidgid(&ug, "apache", 0); + u = get_uidgid(&ug, "apache"); printf("%u = %u:%u\n", u, ug.uid, ug.gid); ug.uid = ug.gid = 1111; - u = get_uidgid(&ug, "apache", 0); + u = get_uidgid(&ug, "apache"); printf("%u = %u:%u\n", u, ug.uid, ug.gid); ug.uid = ug.gid = 1111; - u = get_uidgid(&ug, "apache:users", 0); + u = get_uidgid(&ug, "apache:users"); printf("%u = %u:%u\n", u, ug.uid, ug.gid); ug.uid = ug.gid = 1111; - u = get_uidgid(&ug, "apache:users", 0); + u = get_uidgid(&ug, "apache:users"); printf("%u = %u:%u\n", u, ug.uid, ug.gid); return 0; } |