diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-12-28 05:44:47 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-12-28 05:44:47 +0000 |
commit | 9a44c4f91ce7e517d5325fd3743e6ad9d54ef3f0 (patch) | |
tree | 34292ef12cab59b118e91a6c58844ae25f1bee94 /libbb | |
parent | ba092336f00644c1233735bae4b81382309955d8 (diff) | |
download | busybox-w32-9a44c4f91ce7e517d5325fd3743e6ad9d54ef3f0.tar.gz busybox-w32-9a44c4f91ce7e517d5325fd3743e6ad9d54ef3f0.tar.bz2 busybox-w32-9a44c4f91ce7e517d5325fd3743e6ad9d54ef3f0.zip |
bb_xget[pw/gr]nam were horribly misnamed - fixed.
uidgid_get -> get_uidgid, add additional param
(numeric_ok). Make chown use it.
chown: fix "chown user: ...."
install: fix incorrect use of bb_xget[pw/gr]nam
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/bb_pwd.c | 127 |
1 files changed, 63 insertions, 64 deletions
diff --git a/libbb/bb_pwd.c b/libbb/bb_pwd.c index b5125b0f4..223a6b44c 100644 --- a/libbb/bb_pwd.c +++ b/libbb/bb_pwd.c | |||
@@ -7,31 +7,30 @@ | |||
7 | * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. | 7 | * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include <stdio.h> | ||
11 | #include <string.h> | ||
12 | #include <assert.h> | ||
13 | #include "libbb.h" | 10 | #include "libbb.h" |
14 | 11 | ||
15 | /* | 12 | #define assert(x) ((void)0) |
16 | * if bufsize is > 0 char *buffer cannot be set to NULL. | 13 | |
17 | * If idname is not NULL it is written on the static | 14 | /* |
18 | * allocated buffer (and a pointer to it is returned). | 15 | * if bufsize is > 0 char *buffer cannot be set to NULL. |
19 | * if idname is NULL, id as string is written to the static | 16 | * If idname is not NULL it is written on the static |
20 | * allocated buffer and NULL is returned. | 17 | * allocated buffer (and a pointer to it is returned). |
21 | * if bufsize is = 0 char *buffer can be set to NULL. | 18 | * if idname is NULL, id as string is written to the static |
22 | * If idname exists a pointer to it is returned, | 19 | * allocated buffer and NULL is returned. |
23 | * else NULL is returned. | 20 | * if bufsize is = 0 char *buffer can be set to NULL. |
24 | * if bufsize is < 0 char *buffer can be set to NULL. | 21 | * If idname exists a pointer to it is returned, |
25 | * If idname exists a pointer to it is returned, | 22 | * else NULL is returned. |
26 | * else an error message is printed and the program exits. | 23 | * if bufsize is < 0 char *buffer can be set to NULL. |
27 | */ | 24 | * If idname exists a pointer to it is returned, |
25 | * else an error message is printed and the program exits. | ||
26 | */ | ||
28 | 27 | ||
29 | /* internal function for bb_getpwuid and bb_getgrgid */ | 28 | /* internal function for bb_getpwuid and bb_getgrgid */ |
30 | static char * bb_getug(char *buffer, char *idname, long id, int bufsize, char prefix) | 29 | static char* bb_getug(char *buffer, char *idname, long id, int bufsize, char prefix) |
31 | { | 30 | { |
32 | if (bufsize > 0 ) { | 31 | if (bufsize > 0 ) { |
33 | assert(buffer!=NULL); | 32 | assert(buffer != NULL); |
34 | if(idname) { | 33 | if (idname) { |
35 | return safe_strncpy(buffer, idname, bufsize); | 34 | return safe_strncpy(buffer, idname, bufsize); |
36 | } | 35 | } |
37 | snprintf(buffer, bufsize, "%ld", id); | 36 | snprintf(buffer, bufsize, "%ld", id); |
@@ -41,75 +40,76 @@ static char * bb_getug(char *buffer, char *idname, long id, int bufsize, char pr | |||
41 | return idname; | 40 | return idname; |
42 | } | 41 | } |
43 | 42 | ||
44 | /* Hacked by Tito Ragusa (c) 2004 <farmatito@tiscali.it> to make it more | 43 | /* Hacked by Tito Ragusa (c) 2004 <farmatito@tiscali.it> to make it more |
45 | * flexible : | 44 | * flexible : |
46 | * | 45 | * |
47 | * if bufsize is > 0 char *group cannot be set to NULL. | 46 | * if bufsize is > 0 char *group cannot be set to NULL. |
48 | * On success groupname is written on static allocated buffer | 47 | * On success groupname is written on static allocated buffer |
49 | * group (and a pointer to it is returned). | 48 | * group (and a pointer to it is returned). |
50 | * On failure gid as string is written to static allocated | 49 | * On failure gid as string is written to static allocated |
51 | * buffer group and NULL is returned. | 50 | * buffer group and NULL is returned. |
52 | * if bufsize is = 0 char *group can be set to NULL. | 51 | * if bufsize is = 0 char *group can be set to NULL. |
53 | * On success groupname is returned. | 52 | * On success groupname is returned. |
54 | * On failure NULL is returned. | 53 | * On failure NULL is returned. |
55 | * if bufsize is < 0 char *group can be set to NULL. | 54 | * if bufsize is < 0 char *group can be set to NULL. |
56 | * On success groupname is returned. | 55 | * On success groupname is returned. |
57 | * On failure an error message is printed and | 56 | * On failure an error message is printed and |
58 | * the program exits. | 57 | * the program exits. |
59 | */ | 58 | */ |
60 | 59 | ||
61 | /* gets a groupname given a gid */ | 60 | /* gets a groupname given a gid */ |
62 | char * bb_getgrgid(char *group, long gid, int bufsize) | 61 | char* bb_getgrgid(char *group, long gid, int bufsize) |
63 | { | 62 | { |
64 | struct group *mygroup = getgrgid(gid); | 63 | struct group *mygroup = getgrgid(gid); |
65 | 64 | ||
66 | return bb_getug(group, (mygroup) ? | 65 | return bb_getug(group, |
67 | mygroup->gr_name : (char *)mygroup, gid, bufsize, 'g'); | 66 | mygroup ? mygroup->gr_name : (char *)mygroup, |
67 | gid, bufsize, 'g'); | ||
68 | } | 68 | } |
69 | 69 | ||
70 | /* returns a gid given a group name */ | 70 | /* returns a gid given a group name */ |
71 | long bb_xgetgrnam(const char *name) | 71 | long xgroup2gid(const char *name) |
72 | { | 72 | { |
73 | struct group *mygroup; | 73 | struct group *mygroup; |
74 | 74 | ||
75 | mygroup = getgrnam(name); | 75 | mygroup = getgrnam(name); |
76 | if (mygroup==NULL) | 76 | if (mygroup == NULL) |
77 | bb_error_msg_and_die("unknown group name: %s", name); | 77 | bb_error_msg_and_die("unknown group name: %s", name); |
78 | 78 | ||
79 | return mygroup->gr_gid; | 79 | return mygroup->gr_gid; |
80 | } | 80 | } |
81 | 81 | ||
82 | /* returns a uid given a username */ | 82 | /* returns a uid given a username */ |
83 | long bb_xgetpwnam(const char *name) | 83 | long xuname2uid(const char *name) |
84 | { | 84 | { |
85 | struct passwd *myuser; | 85 | struct passwd *myuser; |
86 | 86 | ||
87 | myuser = getpwnam(name); | 87 | myuser = getpwnam(name); |
88 | if (myuser==NULL) | 88 | if (myuser == NULL) |
89 | bb_error_msg_and_die("unknown user name: %s", name); | 89 | bb_error_msg_and_die("unknown user name: %s", name); |
90 | 90 | ||
91 | return myuser->pw_uid; | 91 | return myuser->pw_uid; |
92 | } | 92 | } |
93 | 93 | ||
94 | /* Hacked by Tito Ragusa (c) 2004 <farmatito@tiscali.it> to make it more | 94 | /* Hacked by Tito Ragusa (c) 2004 <farmatito@tiscali.it> to make it more |
95 | * flexible : | 95 | * flexible : |
96 | * | 96 | * |
97 | * if bufsize is > 0 char *name cannot be set to NULL. | 97 | * if bufsize is > 0 char *name cannot be set to NULL. |
98 | * On success username is written on the static allocated | 98 | * On success username is written on the static allocated |
99 | * buffer name (and a pointer to it is returned). | 99 | * buffer name (and a pointer to it is returned). |
100 | * On failure uid as string is written to the static | 100 | * On failure uid as string is written to the static |
101 | * allocated buffer name and NULL is returned. | 101 | * allocated buffer name and NULL is returned. |
102 | * if bufsize is = 0 char *name can be set to NULL. | 102 | * if bufsize is = 0 char *name can be set to NULL. |
103 | * On success username is returned. | 103 | * On success username is returned. |
104 | * On failure NULL is returned. | 104 | * On failure NULL is returned. |
105 | * if bufsize is < 0 char *name can be set to NULL | 105 | * if bufsize is < 0 char *name can be set to NULL |
106 | * On success username is returned. | 106 | * On success username is returned. |
107 | * On failure an error message is printed and | 107 | * On failure an error message is printed and |
108 | * the program exits. | 108 | * the program exits. |
109 | */ | 109 | */ |
110 | 110 | ||
111 | /* gets a username given a uid */ | 111 | /* gets a username given a uid */ |
112 | char * bb_getpwuid(char *name, long uid, int bufsize) | 112 | char* bb_getpwuid(char *name, long uid, int bufsize) |
113 | { | 113 | { |
114 | struct passwd *myuser = getpwuid(uid); | 114 | struct passwd *myuser = getpwuid(uid); |
115 | 115 | ||
@@ -118,13 +118,12 @@ char * bb_getpwuid(char *name, long uid, int bufsize) | |||
118 | } | 118 | } |
119 | 119 | ||
120 | unsigned long get_ug_id(const char *s, | 120 | unsigned long get_ug_id(const char *s, |
121 | long (*__bb_getxxnam)(const char *)) | 121 | long (*xname2id)(const char *)) |
122 | { | 122 | { |
123 | unsigned long r; | 123 | unsigned long r; |
124 | 124 | ||
125 | r = bb_strtoul(s, NULL, 10); | 125 | r = bb_strtoul(s, NULL, 10); |
126 | if (errno) | 126 | if (errno) |
127 | r = __bb_getxxnam(s); | 127 | return xname2id(s); |
128 | |||
129 | return r; | 128 | return r; |
130 | } | 129 | } |