aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2015-10-19 04:27:17 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2015-10-19 04:27:17 +0200
commit526d85831e7480b9c7a3673d8dd356a438e6dd74 (patch)
tree0063fe2362ecaf3252ccf2a5042bf541546eedd6
parentf3d58a29be7cbf5c0bf94f1a12ac747f706b3d99 (diff)
downloadbusybox-w32-526d85831e7480b9c7a3673d8dd356a438e6dd74.tar.gz
busybox-w32-526d85831e7480b9c7a3673d8dd356a438e6dd74.tar.bz2
busybox-w32-526d85831e7480b9c7a3673d8dd356a438e6dd74.zip
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>
-rw-r--r--include/libbb.h7
-rw-r--r--libbb/appletlib.c2
-rw-r--r--libpwdgrp/uidgid_get.c42
-rw-r--r--util-linux/mdev.c2
4 files changed, 24 insertions, 29 deletions
diff --git a/include/libbb.h b/include/libbb.h
index f04f555c0..1a3f6d8ce 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -920,14 +920,13 @@ long xuname2uid(const char *name) FAST_FUNC;
920long xgroup2gid(const char *name) FAST_FUNC; 920long xgroup2gid(const char *name) FAST_FUNC;
921/* wrapper: allows string to contain numeric uid or gid */ 921/* wrapper: allows string to contain numeric uid or gid */
922unsigned long get_ug_id(const char *s, long FAST_FUNC (*xname2id)(const char *)) FAST_FUNC; 922unsigned long get_ug_id(const char *s, long FAST_FUNC (*xname2id)(const char *)) FAST_FUNC;
923/* from chpst. Does not die, returns 0 on failure */
924struct bb_uidgid_t { 923struct bb_uidgid_t {
925 uid_t uid; 924 uid_t uid;
926 gid_t gid; 925 gid_t gid;
927}; 926};
928/* always sets uid and gid */ 927/* always sets uid and gid; returns 0 on failure */
929int get_uidgid(struct bb_uidgid_t*, const char*, int numeric_ok) FAST_FUNC; 928int get_uidgid(struct bb_uidgid_t*, const char*) FAST_FUNC;
930/* always sets uid and gid, allows numeric; exits on failure */ 929/* always sets uid and gid; exits on failure */
931void xget_uidgid(struct bb_uidgid_t*, const char*) FAST_FUNC; 930void xget_uidgid(struct bb_uidgid_t*, const char*) FAST_FUNC;
932/* chown-like handling of "user[:[group]" */ 931/* chown-like handling of "user[:[group]" */
933void parse_chown_usergroup_or_die(struct bb_uidgid_t *u, char *user_group) FAST_FUNC; 932void parse_chown_usergroup_or_die(struct bb_uidgid_t *u, char *user_group) FAST_FUNC;
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index 24253cf27..0f83eda4b 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -437,7 +437,7 @@ static void parse_config_file(void)
437 goto pe_label; 437 goto pe_label;
438 } 438 }
439 *e = ':'; /* get_uidgid needs USER:GROUP syntax */ 439 *e = ':'; /* get_uidgid needs USER:GROUP syntax */
440 if (get_uidgid(&sct->m_ugid, s, /*allow_numeric:*/ 1) == 0) { 440 if (get_uidgid(&sct->m_ugid, s) == 0) {
441 errmsg = "unknown user/group"; 441 errmsg = "unknown user/group";
442 goto pe_label; 442 goto pe_label;
443 } 443 }
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.
28#include "libbb.h" 28#include "libbb.h"
29 29
30/* Always sets uid and gid */ 30/* Always sets uid and gid */
31int FAST_FUNC get_uidgid(struct bb_uidgid_t *u, const char *ug, int numeric_ok) 31int FAST_FUNC get_uidgid(struct bb_uidgid_t *u, const char *ug)
32{ 32{
33 struct passwd *pwd; 33 struct passwd *pwd;
34 struct group *gr; 34 struct group *gr;
@@ -43,18 +43,16 @@ int FAST_FUNC get_uidgid(struct bb_uidgid_t *u, const char *ug, int numeric_ok)
43 /* copies sz-1 bytes, stores terminating '\0' */ 43 /* copies sz-1 bytes, stores terminating '\0' */
44 safe_strncpy(user, ug, sz); 44 safe_strncpy(user, ug, sz);
45 } 45 }
46 if (numeric_ok) { 46 n = bb_strtou(user, NULL, 10);
47 n = bb_strtou(user, NULL, 10); 47 if (!errno) {
48 if (!errno) { 48 u->uid = n;
49 u->uid = n; 49 pwd = getpwuid(n);
50 pwd = getpwuid(n); 50 /* If we have e.g. "500" string without user */
51 /* If we have e.g. "500" string without user */ 51 /* with uid 500 in /etc/passwd, we set gid == uid */
52 /* with uid 500 in /etc/passwd, we set gid == uid */ 52 u->gid = pwd ? pwd->pw_gid : n;
53 u->gid = pwd ? pwd->pw_gid : n; 53 goto skip;
54 goto skip;
55 }
56 } 54 }
57 /* Either it is not numeric, or caller disallows numeric username */ 55 /* it is not numeric */
58 pwd = getpwnam(user); 56 pwd = getpwnam(user);
59 if (!pwd) 57 if (!pwd)
60 return 0; 58 return 0;
@@ -63,12 +61,10 @@ int FAST_FUNC get_uidgid(struct bb_uidgid_t *u, const char *ug, int numeric_ok)
63 61
64 skip: 62 skip:
65 if (group) { 63 if (group) {
66 if (numeric_ok) { 64 n = bb_strtou(group, NULL, 10);
67 n = bb_strtou(group, NULL, 10); 65 if (!errno) {
68 if (!errno) { 66 u->gid = n;
69 u->gid = n; 67 return 1;
70 return 1;
71 }
72 } 68 }
73 gr = getgrnam(group); 69 gr = getgrnam(group);
74 if (!gr) 70 if (!gr)
@@ -79,7 +75,7 @@ int FAST_FUNC get_uidgid(struct bb_uidgid_t *u, const char *ug, int numeric_ok)
79} 75}
80void FAST_FUNC xget_uidgid(struct bb_uidgid_t *u, const char *ug) 76void FAST_FUNC xget_uidgid(struct bb_uidgid_t *u, const char *ug)
81{ 77{
82 if (!get_uidgid(u, ug, 1)) 78 if (!get_uidgid(u, ug))
83 bb_error_msg_and_die("unknown user/group %s", ug); 79 bb_error_msg_and_die("unknown user/group %s", ug);
84} 80}
85 81
@@ -119,16 +115,16 @@ int main()
119{ 115{
120 unsigned u; 116 unsigned u;
121 struct bb_uidgid_t ug; 117 struct bb_uidgid_t ug;
122 u = get_uidgid(&ug, "apache", 0); 118 u = get_uidgid(&ug, "apache");
123 printf("%u = %u:%u\n", u, ug.uid, ug.gid); 119 printf("%u = %u:%u\n", u, ug.uid, ug.gid);
124 ug.uid = ug.gid = 1111; 120 ug.uid = ug.gid = 1111;
125 u = get_uidgid(&ug, "apache", 0); 121 u = get_uidgid(&ug, "apache");
126 printf("%u = %u:%u\n", u, ug.uid, ug.gid); 122 printf("%u = %u:%u\n", u, ug.uid, ug.gid);
127 ug.uid = ug.gid = 1111; 123 ug.uid = ug.gid = 1111;
128 u = get_uidgid(&ug, "apache:users", 0); 124 u = get_uidgid(&ug, "apache:users");
129 printf("%u = %u:%u\n", u, ug.uid, ug.gid); 125 printf("%u = %u:%u\n", u, ug.uid, ug.gid);
130 ug.uid = ug.gid = 1111; 126 ug.uid = ug.gid = 1111;
131 u = get_uidgid(&ug, "apache:users", 0); 127 u = get_uidgid(&ug, "apache:users");
132 printf("%u = %u:%u\n", u, ug.uid, ug.gid); 128 printf("%u = %u:%u\n", u, ug.uid, ug.gid);
133 return 0; 129 return 0;
134} 130}
diff --git a/util-linux/mdev.c b/util-linux/mdev.c
index 51781d597..37fa56827 100644
--- a/util-linux/mdev.c
+++ b/util-linux/mdev.c
@@ -400,7 +400,7 @@ static void parse_next_rule(void)
400 } 400 }
401 401
402 /* 2nd field: uid:gid - device ownership */ 402 /* 2nd field: uid:gid - device ownership */
403 if (get_uidgid(&G.cur_rule.ugid, tokens[1], /*allow_numeric:*/ 1) == 0) { 403 if (get_uidgid(&G.cur_rule.ugid, tokens[1]) == 0) {
404 bb_error_msg("unknown user/group '%s' on line %d", tokens[1], G.parser->lineno); 404 bb_error_msg("unknown user/group '%s' on line %d", tokens[1], G.parser->lineno);
405 goto next_rule; 405 goto next_rule;
406 } 406 }