diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-12-28 21:33:30 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-12-28 21:33:30 +0000 |
commit | 7fa0fcafca76454effc65f8c3121a37cf0952ff9 (patch) | |
tree | 7342a1d3a0320d586b7e18cdadb8cab580e32e79 | |
parent | 9a44c4f91ce7e517d5325fd3743e6ad9d54ef3f0 (diff) | |
download | busybox-w32-7fa0fcafca76454effc65f8c3121a37cf0952ff9.tar.gz busybox-w32-7fa0fcafca76454effc65f8c3121a37cf0952ff9.tar.bz2 busybox-w32-7fa0fcafca76454effc65f8c3121a37cf0952ff9.zip |
fix build without shadow support
-rw-r--r-- | coreutils/id.c | 21 | ||||
-rw-r--r-- | include/libbb.h | 2 | ||||
-rw-r--r-- | include/shadow_.h | 87 | ||||
-rw-r--r-- | libpwdgrp/pwd_grp.c | 167 | ||||
-rw-r--r-- | loginutils/sulogin.c | 3 |
5 files changed, 141 insertions, 139 deletions
diff --git a/coreutils/id.c b/coreutils/id.c index 35f945dba..36007ae55 100644 --- a/coreutils/id.c +++ b/coreutils/id.c | |||
@@ -89,19 +89,16 @@ int id_main(int argc, char **argv) | |||
89 | 89 | ||
90 | #ifdef CONFIG_SELINUX | 90 | #ifdef CONFIG_SELINUX |
91 | if (is_selinux_enabled()) { | 91 | if (is_selinux_enabled()) { |
92 | security_context_t mysid; | 92 | security_context_t mysid; |
93 | char context[80]; | 93 | const char *context; |
94 | int len = sizeof(context); | ||
95 | 94 | ||
96 | getcon(&mysid); | 95 | context = "unknown"; |
97 | context[0] = '\0'; | 96 | getcon(&mysid); |
98 | if (mysid) { | 97 | if (mysid) { |
99 | len = strlen(mysid)+1; | 98 | context = alloca(strlen(mysid) + 1); |
100 | safe_strncpy(context, mysid, len); | 99 | strcpy((char*)context, mysid); |
101 | freecon(mysid); | 100 | freecon(mysid); |
102 | } else { | 101 | } |
103 | safe_strncpy(context, "unknown", 8); | ||
104 | } | ||
105 | printf(" context=%s", context); | 102 | printf(" context=%s", context); |
106 | } | 103 | } |
107 | #endif | 104 | #endif |
diff --git a/include/libbb.h b/include/libbb.h index ece1c9d91..6948695e9 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -51,9 +51,7 @@ | |||
51 | 51 | ||
52 | #include "pwd_.h" | 52 | #include "pwd_.h" |
53 | #include "grp_.h" | 53 | #include "grp_.h" |
54 | #if ENABLE_FEATURE_SHADOWPASSWDS | ||
55 | #include "shadow_.h" | 54 | #include "shadow_.h" |
56 | #endif | ||
57 | 55 | ||
58 | /* Try to pull in PATH_MAX */ | 56 | /* Try to pull in PATH_MAX */ |
59 | #include <limits.h> | 57 | #include <limits.h> |
diff --git a/include/shadow_.h b/include/shadow_.h index 177ee5f93..634dfb466 100644 --- a/include/shadow_.h +++ b/include/shadow_.h | |||
@@ -17,83 +17,74 @@ | |||
17 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | 17 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
18 | 02111-1307 USA. */ | 18 | 02111-1307 USA. */ |
19 | 19 | ||
20 | /* Declaration of types and functions for shadow password suite. */ | 20 | /* Declaration of types and functions for shadow password suite */ |
21 | 21 | ||
22 | #if !defined CONFIG_USE_BB_SHADOW | 22 | #if !ENABLE_USE_BB_SHADOW |
23 | #include <shadow.h> | 23 | #include <shadow.h> |
24 | #else | 24 | #else |
25 | 25 | ||
26 | #ifndef _SHADOW_H | 26 | #ifndef _SHADOW_H |
27 | #define _SHADOW_H 1 | 27 | #define _SHADOW_H 1 |
28 | 28 | ||
29 | #include <stdio.h> | 29 | /* Paths to the user database files */ |
30 | |||
31 | /* Paths to the user database files. */ | ||
32 | #ifndef _PATH_SHADOW | 30 | #ifndef _PATH_SHADOW |
33 | #define _PATH_SHADOW "/etc/shadow" | 31 | #define _PATH_SHADOW "/etc/shadow" |
34 | #endif | 32 | #endif |
35 | #define SHADOW _PATH_SHADOW | ||
36 | |||
37 | |||
38 | /* Structure of the password file. */ | ||
39 | struct spwd | ||
40 | { | ||
41 | char *sp_namp; /* Login name. */ | ||
42 | char *sp_pwdp; /* Encrypted password. */ | ||
43 | long int sp_lstchg; /* Date of last change. */ | ||
44 | long int sp_min; /* Minimum number of days between changes. */ | ||
45 | long int sp_max; /* Maximum number of days between changes. */ | ||
46 | long int sp_warn; /* Number of days to warn user to change | ||
47 | the password. */ | ||
48 | long int sp_inact; /* Number of days the account may be | ||
49 | inactive. */ | ||
50 | long int sp_expire; /* Number of days since 1970-01-01 until | ||
51 | account expires. */ | ||
52 | unsigned long int sp_flag; /* Reserved. */ | ||
53 | }; | ||
54 | 33 | ||
34 | /* Structure of the password file */ | ||
35 | struct spwd { | ||
36 | char *sp_namp; /* Login name */ | ||
37 | char *sp_pwdp; /* Encrypted password */ | ||
38 | long int sp_lstchg; /* Date of last change */ | ||
39 | long int sp_min; /* Minimum number of days between changes */ | ||
40 | long int sp_max; /* Maximum number of days between changes */ | ||
41 | long int sp_warn; /* Number of days to warn user to change the password */ | ||
42 | long int sp_inact; /* Number of days the account may be inactive */ | ||
43 | long int sp_expire; /* Number of days since 1970-01-01 until account expires */ | ||
44 | unsigned long int sp_flag; /* Reserved */ | ||
45 | }; | ||
55 | 46 | ||
56 | /* Open database for reading. */ | 47 | /* Open database for reading */ |
57 | extern void setspent (void); | 48 | extern void setspent(void); |
58 | 49 | ||
59 | /* Close database. */ | 50 | /* Close database */ |
60 | extern void endspent (void); | 51 | extern void endspent(void); |
61 | 52 | ||
62 | /* Get next entry from database, perhaps after opening the file. */ | 53 | /* Get next entry from database, perhaps after opening the file */ |
63 | extern struct spwd *getspent (void); | 54 | extern struct spwd *getspent(void); |
64 | 55 | ||
65 | /* Get shadow entry matching NAME. */ | 56 | /* Get shadow entry matching NAME */ |
66 | extern struct spwd *getspnam (__const char *__name); | 57 | extern struct spwd *getspnam(__const char *__name); |
67 | 58 | ||
68 | /* Read shadow entry from STRING. */ | 59 | /* Read shadow entry from STRING */ |
69 | extern struct spwd *sgetspent (__const char *__string); | 60 | extern struct spwd *sgetspent(__const char *__string); |
70 | 61 | ||
71 | /* Read next shadow entry from STREAM. */ | 62 | /* Read next shadow entry from STREAM */ |
72 | extern struct spwd *fgetspent (FILE *__stream); | 63 | extern struct spwd *fgetspent(FILE *__stream); |
73 | 64 | ||
74 | /* Write line containing shadow password entry to stream. */ | 65 | /* Write line containing shadow password entry to stream */ |
75 | extern int putspent (__const struct spwd *__p, FILE *__stream); | 66 | extern int putspent(__const struct spwd *__p, FILE *__stream); |
76 | 67 | ||
77 | /* Reentrant versions of some of the functions above. */ | 68 | /* Reentrant versions of some of the functions above */ |
78 | extern int getspent_r (struct spwd *__result_buf, char *__buffer, | 69 | extern int getspent_r(struct spwd *__result_buf, char *__buffer, |
79 | size_t __buflen, struct spwd **__result); | 70 | size_t __buflen, struct spwd **__result); |
80 | 71 | ||
81 | extern int getspnam_r (__const char *__name, struct spwd *__result_buf, | 72 | extern int getspnam_r(__const char *__name, struct spwd *__result_buf, |
82 | char *__buffer, size_t __buflen, | 73 | char *__buffer, size_t __buflen, |
83 | struct spwd **__result); | 74 | struct spwd **__result); |
84 | 75 | ||
85 | extern int sgetspent_r (__const char *__string, struct spwd *__result_buf, | 76 | extern int sgetspent_r(__const char *__string, struct spwd *__result_buf, |
86 | char *__buffer, size_t __buflen, | 77 | char *__buffer, size_t __buflen, |
87 | struct spwd **__result); | 78 | struct spwd **__result); |
88 | 79 | ||
89 | extern int fgetspent_r (FILE *__stream, struct spwd *__result_buf, | 80 | extern int fgetspent_r(FILE *__stream, struct spwd *__result_buf, |
90 | char *__buffer, size_t __buflen, | 81 | char *__buffer, size_t __buflen, |
91 | struct spwd **__result); | 82 | struct spwd **__result); |
92 | /* Protect password file against multi writers. */ | 83 | /* Protect password file against multi writers */ |
93 | extern int lckpwdf (void); | 84 | extern int lckpwdf(void); |
94 | 85 | ||
95 | /* Unlock password file. */ | 86 | /* Unlock password file */ |
96 | extern int ulckpwdf (void); | 87 | extern int ulckpwdf(void); |
97 | 88 | ||
98 | #endif /* shadow.h */ | 89 | #endif /* shadow.h */ |
99 | #endif | 90 | #endif |
diff --git a/libpwdgrp/pwd_grp.c b/libpwdgrp/pwd_grp.c index ac65d4c5b..fcf6eaffe 100644 --- a/libpwdgrp/pwd_grp.c +++ b/libpwdgrp/pwd_grp.c | |||
@@ -20,14 +20,7 @@ | |||
20 | 20 | ||
21 | #include "libbb.h" | 21 | #include "libbb.h" |
22 | #include <features.h> | 22 | #include <features.h> |
23 | #include <stdio.h> | ||
24 | #include <stdlib.h> | ||
25 | #include <stdint.h> | ||
26 | #include <string.h> | ||
27 | #include <stddef.h> | ||
28 | #include <errno.h> | ||
29 | #include <assert.h> | 23 | #include <assert.h> |
30 | #include <ctype.h> | ||
31 | 24 | ||
32 | #ifndef _PATH_SHADOW | 25 | #ifndef _PATH_SHADOW |
33 | #define _PATH_SHADOW "/etc/shadow" | 26 | #define _PATH_SHADOW "/etc/shadow" |
@@ -50,13 +43,15 @@ | |||
50 | /**********************************************************************/ | 43 | /**********************************************************************/ |
51 | /* Prototypes for internal functions. */ | 44 | /* Prototypes for internal functions. */ |
52 | 45 | ||
53 | extern int __parsepwent(void *pw, char *line); | 46 | static int __pgsreader(int (*parserfunc)(void *d, char *line), void *data, |
54 | extern int __parsegrent(void *gr, char *line); | ||
55 | extern int __parsespent(void *sp, char *line); | ||
56 | |||
57 | extern int __pgsreader(int (*__parserfunc)(void *d, char *line), void *data, | ||
58 | char *__restrict line_buff, size_t buflen, FILE *f); | 47 | char *__restrict line_buff, size_t buflen, FILE *f); |
59 | 48 | ||
49 | static int __parsepwent(void *pw, char *line); | ||
50 | static int __parsegrent(void *gr, char *line); | ||
51 | #if ENABLE_USE_BB_SHADOW | ||
52 | static int __parsespent(void *sp, char *line); | ||
53 | #endif | ||
54 | |||
60 | /**********************************************************************/ | 55 | /**********************************************************************/ |
61 | /* For the various fget??ent_r funcs, return | 56 | /* For the various fget??ent_r funcs, return |
62 | * | 57 | * |
@@ -81,7 +76,8 @@ int fgetpwent_r(FILE *__restrict stream, struct passwd *__restrict resultbuf, | |||
81 | 76 | ||
82 | *result = NULL; | 77 | *result = NULL; |
83 | 78 | ||
84 | if (!(rv = __pgsreader(__parsepwent, resultbuf, buffer, buflen, stream))) { | 79 | rv = __pgsreader(__parsepwent, resultbuf, buffer, buflen, stream); |
80 | if (!rv) { | ||
85 | *result = resultbuf; | 81 | *result = resultbuf; |
86 | } | 82 | } |
87 | 83 | ||
@@ -96,13 +92,15 @@ int fgetgrent_r(FILE *__restrict stream, struct group *__restrict resultbuf, | |||
96 | 92 | ||
97 | *result = NULL; | 93 | *result = NULL; |
98 | 94 | ||
99 | if (!(rv = __pgsreader(__parsegrent, resultbuf, buffer, buflen, stream))) { | 95 | rv = __pgsreader(__parsegrent, resultbuf, buffer, buflen, stream); |
96 | if (!rv) { | ||
100 | *result = resultbuf; | 97 | *result = resultbuf; |
101 | } | 98 | } |
102 | 99 | ||
103 | return rv; | 100 | return rv; |
104 | } | 101 | } |
105 | 102 | ||
103 | #if ENABLE_USE_BB_SHADOW | ||
106 | int fgetspent_r(FILE *__restrict stream, struct spwd *__restrict resultbuf, | 104 | int fgetspent_r(FILE *__restrict stream, struct spwd *__restrict resultbuf, |
107 | char *__restrict buffer, size_t buflen, | 105 | char *__restrict buffer, size_t buflen, |
108 | struct spwd **__restrict result) | 106 | struct spwd **__restrict result) |
@@ -111,12 +109,14 @@ int fgetspent_r(FILE *__restrict stream, struct spwd *__restrict resultbuf, | |||
111 | 109 | ||
112 | *result = NULL; | 110 | *result = NULL; |
113 | 111 | ||
114 | if (!(rv = __pgsreader(__parsespent, resultbuf, buffer, buflen, stream))) { | 112 | rv = __pgsreader(__parsespent, resultbuf, buffer, buflen, stream); |
113 | if (!rv) { | ||
115 | *result = resultbuf; | 114 | *result = resultbuf; |
116 | } | 115 | } |
117 | 116 | ||
118 | return rv; | 117 | return rv; |
119 | } | 118 | } |
119 | #endif | ||
120 | 120 | ||
121 | /**********************************************************************/ | 121 | /**********************************************************************/ |
122 | /* For the various fget??ent funcs, return NULL on failure and a | 122 | /* For the various fget??ent funcs, return NULL on failure and a |
@@ -144,9 +144,7 @@ struct group *fgetgrent(FILE *stream) | |||
144 | return result; | 144 | return result; |
145 | } | 145 | } |
146 | 146 | ||
147 | extern int fgetspent_r(FILE *__restrict stream, struct spwd *__restrict resultbuf, | 147 | #if ENABLE_USE_BB_SHADOW |
148 | char *__restrict buffer, size_t buflen, | ||
149 | struct spwd **__restrict result); | ||
150 | struct spwd *fgetspent(FILE *stream) | 148 | struct spwd *fgetspent(FILE *stream) |
151 | { | 149 | { |
152 | static char buffer[PWD_BUFFER_SIZE]; | 150 | static char buffer[PWD_BUFFER_SIZE]; |
@@ -177,13 +175,15 @@ int sgetspent_r(const char *string, struct spwd *result_buf, | |||
177 | strcpy(buffer, string); | 175 | strcpy(buffer, string); |
178 | } | 176 | } |
179 | 177 | ||
180 | if (!(rv = __parsespent(result_buf, buffer))) { | 178 | rv = __parsespent(result_buf, buffer); |
179 | if (!rv) { | ||
181 | *result = result_buf; | 180 | *result = result_buf; |
182 | } | 181 | } |
183 | 182 | ||
184 | DONE: | 183 | DONE: |
185 | return rv; | 184 | return rv; |
186 | } | 185 | } |
186 | #endif | ||
187 | 187 | ||
188 | /**********************************************************************/ | 188 | /**********************************************************************/ |
189 | 189 | ||
@@ -191,43 +191,45 @@ int sgetspent_r(const char *string, struct spwd *result_buf, | |||
191 | #error GETXXKEY_R_FUNC is already defined! | 191 | #error GETXXKEY_R_FUNC is already defined! |
192 | #endif | 192 | #endif |
193 | 193 | ||
194 | #define GETXXKEY_R_FUNC getpwnam_R | 194 | #define GETXXKEY_R_FUNC getpwnam_R |
195 | #define GETXXKEY_R_PARSER __parsepwent | 195 | #define GETXXKEY_R_PARSER __parsepwent |
196 | #define GETXXKEY_R_ENTTYPE struct passwd | 196 | #define GETXXKEY_R_ENTTYPE struct passwd |
197 | #define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->pw_name, key)) | 197 | #define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->pw_name, key)) |
198 | #define DO_GETXXKEY_R_KEYTYPE const char *__restrict | 198 | #define DO_GETXXKEY_R_KEYTYPE const char *__restrict |
199 | #define DO_GETXXKEY_R_PATHNAME _PATH_PASSWD | 199 | #define DO_GETXXKEY_R_PATHNAME _PATH_PASSWD |
200 | #include "pwd_grp_internal.c" | 200 | #include "pwd_grp_internal.c" |
201 | 201 | ||
202 | #define GETXXKEY_R_FUNC getgrnam_R | 202 | #define GETXXKEY_R_FUNC getgrnam_R |
203 | #define GETXXKEY_R_PARSER __parsegrent | 203 | #define GETXXKEY_R_PARSER __parsegrent |
204 | #define GETXXKEY_R_ENTTYPE struct group | 204 | #define GETXXKEY_R_ENTTYPE struct group |
205 | #define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->gr_name, key)) | 205 | #define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->gr_name, key)) |
206 | #define DO_GETXXKEY_R_KEYTYPE const char *__restrict | 206 | #define DO_GETXXKEY_R_KEYTYPE const char *__restrict |
207 | #define DO_GETXXKEY_R_PATHNAME _PATH_GROUP | 207 | #define DO_GETXXKEY_R_PATHNAME _PATH_GROUP |
208 | #include "pwd_grp_internal.c" | 208 | #include "pwd_grp_internal.c" |
209 | 209 | ||
210 | #define GETXXKEY_R_FUNC getspnam_R | 210 | #if ENABLE_USE_BB_SHADOW |
211 | #define GETXXKEY_R_PARSER __parsespent | 211 | #define GETXXKEY_R_FUNC getspnam_R |
212 | #define GETXXKEY_R_ENTTYPE struct spwd | 212 | #define GETXXKEY_R_PARSER __parsespent |
213 | #define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->sp_namp, key)) | 213 | #define GETXXKEY_R_ENTTYPE struct spwd |
214 | #define DO_GETXXKEY_R_KEYTYPE const char *__restrict | 214 | #define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->sp_namp, key)) |
215 | #define DO_GETXXKEY_R_KEYTYPE const char *__restrict | ||
215 | #define DO_GETXXKEY_R_PATHNAME _PATH_SHADOW | 216 | #define DO_GETXXKEY_R_PATHNAME _PATH_SHADOW |
216 | #include "pwd_grp_internal.c" | 217 | #include "pwd_grp_internal.c" |
218 | #endif | ||
217 | 219 | ||
218 | #define GETXXKEY_R_FUNC getpwuid_R | 220 | #define GETXXKEY_R_FUNC getpwuid_R |
219 | #define GETXXKEY_R_PARSER __parsepwent | 221 | #define GETXXKEY_R_PARSER __parsepwent |
220 | #define GETXXKEY_R_ENTTYPE struct passwd | 222 | #define GETXXKEY_R_ENTTYPE struct passwd |
221 | #define GETXXKEY_R_TEST(ENT) ((ENT)->pw_uid == key) | 223 | #define GETXXKEY_R_TEST(ENT) ((ENT)->pw_uid == key) |
222 | #define DO_GETXXKEY_R_KEYTYPE uid_t | 224 | #define DO_GETXXKEY_R_KEYTYPE uid_t |
223 | #define DO_GETXXKEY_R_PATHNAME _PATH_PASSWD | 225 | #define DO_GETXXKEY_R_PATHNAME _PATH_PASSWD |
224 | #include "pwd_grp_internal.c" | 226 | #include "pwd_grp_internal.c" |
225 | 227 | ||
226 | #define GETXXKEY_R_FUNC getgrgid_R | 228 | #define GETXXKEY_R_FUNC getgrgid_R |
227 | #define GETXXKEY_R_PARSER __parsegrent | 229 | #define GETXXKEY_R_PARSER __parsegrent |
228 | #define GETXXKEY_R_ENTTYPE struct group | 230 | #define GETXXKEY_R_ENTTYPE struct group |
229 | #define GETXXKEY_R_TEST(ENT) ((ENT)->gr_gid == key) | 231 | #define GETXXKEY_R_TEST(ENT) ((ENT)->gr_gid == key) |
230 | #define DO_GETXXKEY_R_KEYTYPE gid_t | 232 | #define DO_GETXXKEY_R_KEYTYPE gid_t |
231 | #define DO_GETXXKEY_R_PATHNAME _PATH_GROUP | 233 | #define DO_GETXXKEY_R_PATHNAME _PATH_GROUP |
232 | #include "pwd_grp_internal.c" | 234 | #include "pwd_grp_internal.c" |
233 | 235 | ||
@@ -253,10 +255,10 @@ struct group *getgrgid(gid_t gid) | |||
253 | return result; | 255 | return result; |
254 | } | 256 | } |
255 | 257 | ||
258 | #if 0 //ENABLE_USE_BB_SHADOW | ||
256 | /* This function is non-standard and is currently not built. It seems | 259 | /* This function is non-standard and is currently not built. It seems |
257 | * to have been created as a reentrant version of the non-standard | 260 | * to have been created as a reentrant version of the non-standard |
258 | * functions getspuid. Why getspuid was added, I do not know. */ | 261 | * functions getspuid. Why getspuid was added, I do not know. */ |
259 | |||
260 | int getspuid_r(uid_t uid, struct spwd *__restrict resultbuf, | 262 | int getspuid_r(uid_t uid, struct spwd *__restrict resultbuf, |
261 | char *__restrict buffer, size_t buflen, | 263 | char *__restrict buffer, size_t buflen, |
262 | struct spwd **__restrict result) | 264 | struct spwd **__restrict result) |
@@ -267,7 +269,8 @@ int getspuid_r(uid_t uid, struct spwd *__restrict resultbuf, | |||
267 | char pwd_buff[PWD_BUFFER_SIZE]; | 269 | char pwd_buff[PWD_BUFFER_SIZE]; |
268 | 270 | ||
269 | *result = NULL; | 271 | *result = NULL; |
270 | if (!(rv = getpwuid_r(uid, &password, pwd_buff, sizeof(pwd_buff), &pp))) { | 272 | rv = getpwuid_r(uid, &password, pwd_buff, sizeof(pwd_buff), &pp); |
273 | if (!rv) { | ||
271 | rv = getspnam_r(password.pw_name, resultbuf, buffer, buflen, result); | 274 | rv = getspnam_r(password.pw_name, resultbuf, buffer, buflen, result); |
272 | } | 275 | } |
273 | 276 | ||
@@ -276,7 +279,6 @@ int getspuid_r(uid_t uid, struct spwd *__restrict resultbuf, | |||
276 | 279 | ||
277 | /* This function is non-standard and is currently not built. | 280 | /* This function is non-standard and is currently not built. |
278 | * Why it was added, I do not know. */ | 281 | * Why it was added, I do not know. */ |
279 | |||
280 | struct spwd *getspuid(uid_t uid) | 282 | struct spwd *getspuid(uid_t uid) |
281 | { | 283 | { |
282 | static char buffer[PWD_BUFFER_SIZE]; | 284 | static char buffer[PWD_BUFFER_SIZE]; |
@@ -286,6 +288,7 @@ struct spwd *getspuid(uid_t uid) | |||
286 | getspuid_r(uid, &resultbuf, buffer, sizeof(buffer), &result); | 288 | getspuid_r(uid, &resultbuf, buffer, sizeof(buffer), &result); |
287 | return result; | 289 | return result; |
288 | } | 290 | } |
291 | #endif | ||
289 | 292 | ||
290 | struct passwd *getpwnam(const char *name) | 293 | struct passwd *getpwnam(const char *name) |
291 | { | 294 | { |
@@ -307,6 +310,7 @@ struct group *getgrnam(const char *name) | |||
307 | return result; | 310 | return result; |
308 | } | 311 | } |
309 | 312 | ||
313 | #if ENABLE_USE_BB_SHADOW | ||
310 | struct spwd *getspnam(const char *name) | 314 | struct spwd *getspnam(const char *name) |
311 | { | 315 | { |
312 | static char buffer[PWD_BUFFER_SIZE]; | 316 | static char buffer[PWD_BUFFER_SIZE]; |
@@ -316,6 +320,7 @@ struct spwd *getspnam(const char *name) | |||
316 | getspnam_r(name, &resultbuf, buffer, sizeof(buffer), &result); | 320 | getspnam_r(name, &resultbuf, buffer, sizeof(buffer), &result); |
317 | return result; | 321 | return result; |
318 | } | 322 | } |
323 | #endif | ||
319 | 324 | ||
320 | int getpw(uid_t uid, char *buf) | 325 | int getpw(uid_t uid, char *buf) |
321 | { | 326 | { |
@@ -382,14 +387,15 @@ int getpwent_r(struct passwd *__restrict resultbuf, | |||
382 | *result = NULL; /* In case of error... */ | 387 | *result = NULL; /* In case of error... */ |
383 | 388 | ||
384 | if (!pwf) { | 389 | if (!pwf) { |
385 | if (!(pwf = fopen(_PATH_PASSWD, "r"))) { | 390 | pwf = fopen(_PATH_PASSWD, "r"); |
391 | if (!pwf) { | ||
386 | rv = errno; | 392 | rv = errno; |
387 | goto ERR; | 393 | goto ERR; |
388 | } | 394 | } |
389 | } | 395 | } |
390 | 396 | ||
391 | if (!(rv = __pgsreader(__parsepwent, resultbuf, | 397 | rv = __pgsreader(__parsepwent, resultbuf, buffer, buflen, pwf); |
392 | buffer, buflen, pwf))) { | 398 | if (!rv) { |
393 | *result = resultbuf; | 399 | *result = resultbuf; |
394 | } | 400 | } |
395 | 401 | ||
@@ -428,14 +434,15 @@ int getgrent_r(struct group *__restrict resultbuf, | |||
428 | *result = NULL; /* In case of error... */ | 434 | *result = NULL; /* In case of error... */ |
429 | 435 | ||
430 | if (!grf) { | 436 | if (!grf) { |
431 | if (!(grf = fopen(_PATH_GROUP, "r"))) { | 437 | grf = fopen(_PATH_GROUP, "r"); |
438 | if (!grf) { | ||
432 | rv = errno; | 439 | rv = errno; |
433 | goto ERR; | 440 | goto ERR; |
434 | } | 441 | } |
435 | } | 442 | } |
436 | 443 | ||
437 | if (!(rv = __pgsreader(__parsegrent, resultbuf, | 444 | rv = __pgsreader(__parsegrent, resultbuf, buffer, buflen, grf); |
438 | buffer, buflen, grf))) { | 445 | if (!rv) { |
439 | *result = resultbuf; | 446 | *result = resultbuf; |
440 | } | 447 | } |
441 | 448 | ||
@@ -444,6 +451,7 @@ int getgrent_r(struct group *__restrict resultbuf, | |||
444 | return rv; | 451 | return rv; |
445 | } | 452 | } |
446 | 453 | ||
454 | #if ENABLE_USE_BB_SHADOW | ||
447 | static FILE *spf /*= NULL*/; | 455 | static FILE *spf /*= NULL*/; |
448 | void setspent(void) | 456 | void setspent(void) |
449 | { | 457 | { |
@@ -473,14 +481,15 @@ int getspent_r(struct spwd *resultbuf, char *buffer, | |||
473 | *result = NULL; /* In case of error... */ | 481 | *result = NULL; /* In case of error... */ |
474 | 482 | ||
475 | if (!spf) { | 483 | if (!spf) { |
476 | if (!(spf = fopen(_PATH_SHADOW, "r"))) { | 484 | spf = fopen(_PATH_SHADOW, "r"); |
485 | if (!spf) { | ||
477 | rv = errno; | 486 | rv = errno; |
478 | goto ERR; | 487 | goto ERR; |
479 | } | 488 | } |
480 | } | 489 | } |
481 | 490 | ||
482 | if (!(rv = __pgsreader(__parsespent, resultbuf, | 491 | rv = __pgsreader(__parsespent, resultbuf, buffer, buflen, spf); |
483 | buffer, buflen, spf))) { | 492 | if (!rv) { |
484 | *result = resultbuf; | 493 | *result = resultbuf; |
485 | } | 494 | } |
486 | 495 | ||
@@ -488,6 +497,7 @@ int getspent_r(struct spwd *resultbuf, char *buffer, | |||
488 | UNLOCK; | 497 | UNLOCK; |
489 | return rv; | 498 | return rv; |
490 | } | 499 | } |
500 | #endif | ||
491 | 501 | ||
492 | struct passwd *getpwent(void) | 502 | struct passwd *getpwent(void) |
493 | { | 503 | { |
@@ -509,6 +519,7 @@ struct group *getgrent(void) | |||
509 | return result; | 519 | return result; |
510 | } | 520 | } |
511 | 521 | ||
522 | #if ENABLE_USE_BB_SHADOW | ||
512 | struct spwd *getspent(void) | 523 | struct spwd *getspent(void) |
513 | { | 524 | { |
514 | static char line_buff[PWD_BUFFER_SIZE]; | 525 | static char line_buff[PWD_BUFFER_SIZE]; |
@@ -528,6 +539,7 @@ struct spwd *sgetspent(const char *string) | |||
528 | sgetspent_r(string, &spwd, line_buff, sizeof(line_buff), &result); | 539 | sgetspent_r(string, &spwd, line_buff, sizeof(line_buff), &result); |
529 | return result; | 540 | return result; |
530 | } | 541 | } |
542 | #endif | ||
531 | 543 | ||
532 | int initgroups(const char *user, gid_t gid) | 544 | int initgroups(const char *user, gid_t gid) |
533 | { | 545 | { |
@@ -541,10 +553,10 @@ int initgroups(const char *user, gid_t gid) | |||
541 | rv = -1; | 553 | rv = -1; |
542 | 554 | ||
543 | /* We alloc space for 8 gids at a time. */ | 555 | /* We alloc space for 8 gids at a time. */ |
544 | if (((group_list = (gid_t *) malloc(8*sizeof(gid_t *))) != NULL) | 556 | group_list = (gid_t *) malloc(8*sizeof(gid_t *)); |
545 | && ((grfile = fopen(_PATH_GROUP, "r")) != NULL) | 557 | if (group_list |
546 | ) { | 558 | && ((grfile = fopen(_PATH_GROUP, "r")) != NULL) |
547 | 559 | ) { | |
548 | *group_list = gid; | 560 | *group_list = gid; |
549 | num_groups = 1; | 561 | num_groups = 1; |
550 | 562 | ||
@@ -643,6 +655,7 @@ int putgrent(const struct group *__restrict p, FILE *__restrict f) | |||
643 | return rv; | 655 | return rv; |
644 | } | 656 | } |
645 | 657 | ||
658 | #if ENABLE_USE_BB_SHADOW | ||
646 | static const unsigned char _sp_off[] = { | 659 | static const unsigned char _sp_off[] = { |
647 | offsetof(struct spwd, sp_lstchg), /* 2 - not a char ptr */ | 660 | offsetof(struct spwd, sp_lstchg), /* 2 - not a char ptr */ |
648 | offsetof(struct spwd, sp_min), /* 3 - not a char ptr */ | 661 | offsetof(struct spwd, sp_min), /* 3 - not a char ptr */ |
@@ -663,13 +676,14 @@ int putspent(const struct spwd *p, FILE *stream) | |||
663 | /* Unlike putpwent and putgrent, glibc does not check the args. */ | 676 | /* Unlike putpwent and putgrent, glibc does not check the args. */ |
664 | if (fprintf(stream, "%s:%s:", p->sp_namp, | 677 | if (fprintf(stream, "%s:%s:", p->sp_namp, |
665 | (p->sp_pwdp ? p->sp_pwdp : "")) < 0 | 678 | (p->sp_pwdp ? p->sp_pwdp : "")) < 0 |
666 | ) { | 679 | ) { |
667 | goto DO_UNLOCK; | 680 | goto DO_UNLOCK; |
668 | } | 681 | } |
669 | 682 | ||
670 | for (i=0 ; i < sizeof(_sp_off) ; i++) { | 683 | for (i=0 ; i < sizeof(_sp_off) ; i++) { |
671 | f = ld_format; | 684 | f = ld_format; |
672 | if ((x = *(const long int *)(((const char *) p) + _sp_off[i])) == -1) { | 685 | x = *(const long int *)(((const char *) p) + _sp_off[i]); |
686 | if (x == -1) { | ||
673 | f += 3; | 687 | f += 3; |
674 | } | 688 | } |
675 | if (fprintf(stream, f, x) < 0) { | 689 | if (fprintf(stream, f, x) < 0) { |
@@ -688,6 +702,7 @@ int putspent(const struct spwd *p, FILE *stream) | |||
688 | DO_UNLOCK: | 702 | DO_UNLOCK: |
689 | return rv; | 703 | return rv; |
690 | } | 704 | } |
705 | #endif | ||
691 | 706 | ||
692 | /**********************************************************************/ | 707 | /**********************************************************************/ |
693 | /* Internal uClibc functions. */ | 708 | /* Internal uClibc functions. */ |
@@ -703,7 +718,7 @@ static const unsigned char pw_off[] = { | |||
703 | offsetof(struct passwd, pw_shell) /* 6 */ | 718 | offsetof(struct passwd, pw_shell) /* 6 */ |
704 | }; | 719 | }; |
705 | 720 | ||
706 | int __parsepwent(void *data, char *line) | 721 | static int __parsepwent(void *data, char *line) |
707 | { | 722 | { |
708 | char *endptr; | 723 | char *endptr; |
709 | char *p; | 724 | char *p; |
@@ -721,7 +736,8 @@ int __parsepwent(void *data, char *line) | |||
721 | /* NOTE: glibc difference - glibc allows omission of | 736 | /* NOTE: glibc difference - glibc allows omission of |
722 | * ':' seperators after the gid field if all remaining | 737 | * ':' seperators after the gid field if all remaining |
723 | * entries are empty. We require all separators. */ | 738 | * entries are empty. We require all separators. */ |
724 | if (!(line = strchr(line, ':'))) { | 739 | line = strchr(line, ':'); |
740 | if (!line) { | ||
725 | break; | 741 | break; |
726 | } | 742 | } |
727 | } else { | 743 | } else { |
@@ -756,7 +772,7 @@ static const unsigned char gr_off[] = { | |||
756 | offsetof(struct group, gr_gid) /* 2 - not a char ptr */ | 772 | offsetof(struct group, gr_gid) /* 2 - not a char ptr */ |
757 | }; | 773 | }; |
758 | 774 | ||
759 | int __parsegrent(void *data, char *line) | 775 | static int __parsegrent(void *data, char *line) |
760 | { | 776 | { |
761 | char *endptr; | 777 | char *endptr; |
762 | char *p; | 778 | char *p; |
@@ -771,7 +787,8 @@ int __parsegrent(void *data, char *line) | |||
771 | 787 | ||
772 | if (i < 2) { | 788 | if (i < 2) { |
773 | *((char **) p) = line; | 789 | *((char **) p) = line; |
774 | if (!(line = strchr(line, ':'))) { | 790 | line = strchr(line, ':'); |
791 | if (!line) { | ||
775 | break; | 792 | break; |
776 | } | 793 | } |
777 | *line++ = 0; | 794 | *line++ = 0; |
@@ -845,7 +862,7 @@ int __parsegrent(void *data, char *line) | |||
845 | } | 862 | } |
846 | 863 | ||
847 | /**********************************************************************/ | 864 | /**********************************************************************/ |
848 | 865 | #if ENABLE_USE_BB_SHADOW | |
849 | static const unsigned char sp_off[] = { | 866 | static const unsigned char sp_off[] = { |
850 | offsetof(struct spwd, sp_namp), /* 0 */ | 867 | offsetof(struct spwd, sp_namp), /* 0 */ |
851 | offsetof(struct spwd, sp_pwdp), /* 1 */ | 868 | offsetof(struct spwd, sp_pwdp), /* 1 */ |
@@ -858,7 +875,7 @@ static const unsigned char sp_off[] = { | |||
858 | offsetof(struct spwd, sp_flag) /* 8 - not a char ptr */ | 875 | offsetof(struct spwd, sp_flag) /* 8 - not a char ptr */ |
859 | }; | 876 | }; |
860 | 877 | ||
861 | int __parsespent(void *data, char * line) | 878 | static int __parsespent(void *data, char * line) |
862 | { | 879 | { |
863 | char *endptr; | 880 | char *endptr; |
864 | char *p; | 881 | char *p; |
@@ -869,7 +886,8 @@ int __parsespent(void *data, char * line) | |||
869 | p = ((char *) ((struct spwd *) data)) + sp_off[i]; | 886 | p = ((char *) ((struct spwd *) data)) + sp_off[i]; |
870 | if (i < 2) { | 887 | if (i < 2) { |
871 | *((char **) p) = line; | 888 | *((char **) p) = line; |
872 | if (!(line = strchr(line, ':'))) { | 889 | line = strchr(line, ':'); |
890 | if (!line) { | ||
873 | break; | 891 | break; |
874 | } | 892 | } |
875 | } else { | 893 | } else { |
@@ -900,6 +918,7 @@ int __parsespent(void *data, char * line) | |||
900 | 918 | ||
901 | return EINVAL; | 919 | return EINVAL; |
902 | } | 920 | } |
921 | #endif | ||
903 | 922 | ||
904 | /**********************************************************************/ | 923 | /**********************************************************************/ |
905 | 924 | ||
@@ -909,7 +928,7 @@ int __parsespent(void *data, char * line) | |||
909 | * Returns 0 on success and ENOENT for end-of-file (glibc concession). | 928 | * Returns 0 on success and ENOENT for end-of-file (glibc concession). |
910 | */ | 929 | */ |
911 | 930 | ||
912 | int __pgsreader(int (*__parserfunc)(void *d, char *line), void *data, | 931 | static int __pgsreader(int (*parserfunc)(void *d, char *line), void *data, |
913 | char *__restrict line_buff, size_t buflen, FILE *f) | 932 | char *__restrict line_buff, size_t buflen, FILE *f) |
914 | { | 933 | { |
915 | int line_len; | 934 | int line_len; |
@@ -917,7 +936,7 @@ int __pgsreader(int (*__parserfunc)(void *d, char *line), void *data, | |||
917 | int rv = ERANGE; | 936 | int rv = ERANGE; |
918 | 937 | ||
919 | if (buflen < PWD_BUFFER_SIZE) { | 938 | if (buflen < PWD_BUFFER_SIZE) { |
920 | errno=rv; | 939 | errno = rv; |
921 | } else { | 940 | } else { |
922 | skip = 0; | 941 | skip = 0; |
923 | do { | 942 | do { |
@@ -947,14 +966,14 @@ int __pgsreader(int (*__parserfunc)(void *d, char *line), void *data, | |||
947 | /* Skip empty lines, comment lines, and lines with leading | 966 | /* Skip empty lines, comment lines, and lines with leading |
948 | * whitespace. */ | 967 | * whitespace. */ |
949 | if (*line_buff && (*line_buff != '#') && !isspace(*line_buff)) { | 968 | if (*line_buff && (*line_buff != '#') && !isspace(*line_buff)) { |
950 | if (__parserfunc == __parsegrent) { /* Do evil group hack. */ | 969 | if (parserfunc == __parsegrent) { /* Do evil group hack. */ |
951 | /* The group entry parsing function needs to know where | 970 | /* The group entry parsing function needs to know where |
952 | * the end of the buffer is so that it can construct the | 971 | * the end of the buffer is so that it can construct the |
953 | * group member ptr table. */ | 972 | * group member ptr table. */ |
954 | ((struct group *) data)->gr_name = line_buff + buflen; | 973 | ((struct group *) data)->gr_name = line_buff + buflen; |
955 | } | 974 | } |
956 | 975 | ||
957 | if (!__parserfunc(data, line_buff)) { | 976 | if (!parserfunc(data, line_buff)) { |
958 | rv = 0; | 977 | rv = 0; |
959 | break; | 978 | break; |
960 | } | 979 | } |
@@ -965,5 +984,3 @@ int __pgsreader(int (*__parserfunc)(void *d, char *line), void *data, | |||
965 | 984 | ||
966 | return rv; | 985 | return rv; |
967 | } | 986 | } |
968 | |||
969 | /**********************************************************************/ | ||
diff --git a/loginutils/sulogin.c b/loginutils/sulogin.c index c07264e7b..30f9d9350 100644 --- a/loginutils/sulogin.c +++ b/loginutils/sulogin.c | |||
@@ -41,7 +41,6 @@ int sulogin_main(int argc, char **argv) | |||
41 | char *timeout_arg; | 41 | char *timeout_arg; |
42 | const char * const *p; | 42 | const char * const *p; |
43 | struct passwd *pwd; | 43 | struct passwd *pwd; |
44 | struct spwd *spwd; | ||
45 | const char *shell; | 44 | const char *shell; |
46 | 45 | ||
47 | logmode = LOGMODE_BOTH; | 46 | logmode = LOGMODE_BOTH; |
@@ -76,7 +75,7 @@ int sulogin_main(int argc, char **argv) | |||
76 | } | 75 | } |
77 | 76 | ||
78 | if (ENABLE_FEATURE_SHADOWPASSWDS) { | 77 | if (ENABLE_FEATURE_SHADOWPASSWDS) { |
79 | spwd = getspnam(pwd->pw_name); | 78 | struct spwd *spwd = getspnam(pwd->pw_name); |
80 | if (!spwd) { | 79 | if (!spwd) { |
81 | goto auth_error; | 80 | goto auth_error; |
82 | } | 81 | } |