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>
This commit is contained in:
parent
f3d58a29be
commit
526d85831e
@ -920,14 +920,13 @@ long xuname2uid(const char *name) FAST_FUNC;
|
|||||||
long xgroup2gid(const char *name) FAST_FUNC;
|
long xgroup2gid(const char *name) FAST_FUNC;
|
||||||
/* wrapper: allows string to contain numeric uid or gid */
|
/* wrapper: allows string to contain numeric uid or gid */
|
||||||
unsigned long get_ug_id(const char *s, long FAST_FUNC (*xname2id)(const char *)) FAST_FUNC;
|
unsigned long get_ug_id(const char *s, long FAST_FUNC (*xname2id)(const char *)) FAST_FUNC;
|
||||||
/* from chpst. Does not die, returns 0 on failure */
|
|
||||||
struct bb_uidgid_t {
|
struct bb_uidgid_t {
|
||||||
uid_t uid;
|
uid_t uid;
|
||||||
gid_t gid;
|
gid_t gid;
|
||||||
};
|
};
|
||||||
/* always sets uid and gid */
|
/* always sets uid and gid; returns 0 on failure */
|
||||||
int get_uidgid(struct bb_uidgid_t*, const char*, int numeric_ok) FAST_FUNC;
|
int get_uidgid(struct bb_uidgid_t*, const char*) FAST_FUNC;
|
||||||
/* always sets uid and gid, allows numeric; exits on failure */
|
/* always sets uid and gid; exits on failure */
|
||||||
void xget_uidgid(struct bb_uidgid_t*, const char*) FAST_FUNC;
|
void xget_uidgid(struct bb_uidgid_t*, const char*) FAST_FUNC;
|
||||||
/* chown-like handling of "user[:[group]" */
|
/* chown-like handling of "user[:[group]" */
|
||||||
void parse_chown_usergroup_or_die(struct bb_uidgid_t *u, char *user_group) FAST_FUNC;
|
void parse_chown_usergroup_or_die(struct bb_uidgid_t *u, char *user_group) FAST_FUNC;
|
||||||
|
@ -437,7 +437,7 @@ static void parse_config_file(void)
|
|||||||
goto pe_label;
|
goto pe_label;
|
||||||
}
|
}
|
||||||
*e = ':'; /* get_uidgid needs USER:GROUP syntax */
|
*e = ':'; /* get_uidgid needs USER:GROUP syntax */
|
||||||
if (get_uidgid(&sct->m_ugid, s, /*allow_numeric:*/ 1) == 0) {
|
if (get_uidgid(&sct->m_ugid, s) == 0) {
|
||||||
errmsg = "unknown user/group";
|
errmsg = "unknown user/group";
|
||||||
goto pe_label;
|
goto pe_label;
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#include "libbb.h"
|
#include "libbb.h"
|
||||||
|
|
||||||
/* Always sets uid and gid */
|
/* 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 passwd *pwd;
|
||||||
struct group *gr;
|
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' */
|
/* copies sz-1 bytes, stores terminating '\0' */
|
||||||
safe_strncpy(user, ug, sz);
|
safe_strncpy(user, ug, sz);
|
||||||
}
|
}
|
||||||
if (numeric_ok) {
|
n = bb_strtou(user, NULL, 10);
|
||||||
n = bb_strtou(user, NULL, 10);
|
if (!errno) {
|
||||||
if (!errno) {
|
u->uid = n;
|
||||||
u->uid = n;
|
pwd = getpwuid(n);
|
||||||
pwd = getpwuid(n);
|
/* If we have e.g. "500" string without user */
|
||||||
/* If we have e.g. "500" string without user */
|
/* with uid 500 in /etc/passwd, we set gid == uid */
|
||||||
/* with uid 500 in /etc/passwd, we set gid == uid */
|
u->gid = pwd ? pwd->pw_gid : n;
|
||||||
u->gid = pwd ? pwd->pw_gid : n;
|
goto skip;
|
||||||
goto skip;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/* Either it is not numeric, or caller disallows numeric username */
|
/* it is not numeric */
|
||||||
pwd = getpwnam(user);
|
pwd = getpwnam(user);
|
||||||
if (!pwd)
|
if (!pwd)
|
||||||
return 0;
|
return 0;
|
||||||
@ -63,12 +61,10 @@ int FAST_FUNC get_uidgid(struct bb_uidgid_t *u, const char *ug, int numeric_ok)
|
|||||||
|
|
||||||
skip:
|
skip:
|
||||||
if (group) {
|
if (group) {
|
||||||
if (numeric_ok) {
|
n = bb_strtou(group, NULL, 10);
|
||||||
n = bb_strtou(group, NULL, 10);
|
if (!errno) {
|
||||||
if (!errno) {
|
u->gid = n;
|
||||||
u->gid = n;
|
return 1;
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
gr = getgrnam(group);
|
gr = getgrnam(group);
|
||||||
if (!gr)
|
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)
|
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);
|
bb_error_msg_and_die("unknown user/group %s", ug);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,16 +115,16 @@ int main()
|
|||||||
{
|
{
|
||||||
unsigned u;
|
unsigned u;
|
||||||
struct bb_uidgid_t ug;
|
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);
|
printf("%u = %u:%u\n", u, ug.uid, ug.gid);
|
||||||
ug.uid = ug.gid = 1111;
|
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);
|
printf("%u = %u:%u\n", u, ug.uid, ug.gid);
|
||||||
ug.uid = ug.gid = 1111;
|
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);
|
printf("%u = %u:%u\n", u, ug.uid, ug.gid);
|
||||||
ug.uid = ug.gid = 1111;
|
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);
|
printf("%u = %u:%u\n", u, ug.uid, ug.gid);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -400,7 +400,7 @@ static void parse_next_rule(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* 2nd field: uid:gid - device ownership */
|
/* 2nd field: uid:gid - device ownership */
|
||||||
if (get_uidgid(&G.cur_rule.ugid, tokens[1], /*allow_numeric:*/ 1) == 0) {
|
if (get_uidgid(&G.cur_rule.ugid, tokens[1]) == 0) {
|
||||||
bb_error_msg("unknown user/group '%s' on line %d", tokens[1], G.parser->lineno);
|
bb_error_msg("unknown user/group '%s' on line %d", tokens[1], G.parser->lineno);
|
||||||
goto next_rule;
|
goto next_rule;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user