diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-09-26 10:35:55 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-09-26 10:35:55 +0000 |
commit | ee5dce336597c76d674b570ed2c85041d50b6339 (patch) | |
tree | cd7ea0e60aff3fa129899319446dd3cce7b3ae39 | |
parent | f1980f67d3b005090a31b7465d219e8ca19c5736 (diff) | |
download | busybox-w32-ee5dce336597c76d674b570ed2c85041d50b6339.tar.gz busybox-w32-ee5dce336597c76d674b570ed2c85041d50b6339.tar.bz2 busybox-w32-ee5dce336597c76d674b570ed2c85041d50b6339.zip |
libpwdgrp: make it coexist with <pwd.h>, <grp.h> and <shadow.h>.
allows to get rid of hacks in libbb.h (extra declaration of setgroups -
now it comes from grp.h as intended).
-rw-r--r-- | include/grp_.h | 30 | ||||
-rw-r--r-- | include/libbb.h | 12 | ||||
-rw-r--r-- | include/pwd_.h | 33 | ||||
-rw-r--r-- | include/rtc_.h | 4 | ||||
-rw-r--r-- | include/shadow_.h | 37 | ||||
-rw-r--r-- | libpwdgrp/pwd_grp.c | 2 |
6 files changed, 44 insertions, 74 deletions
diff --git a/include/grp_.h b/include/grp_.h index 23c4dcc03..697a78606 100644 --- a/include/grp_.h +++ b/include/grp_.h | |||
@@ -21,21 +21,17 @@ | |||
21 | * POSIX Standard: 9.2.1 Group Database Access <grp.h> | 21 | * POSIX Standard: 9.2.1 Group Database Access <grp.h> |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #ifndef _GRP_H | 24 | #ifndef BB_GRP_H |
25 | #define _GRP_H 1 | 25 | #define BB_GRP_H 1 |
26 | 26 | ||
27 | #if __GNUC_PREREQ(4,1) | 27 | #if __GNUC_PREREQ(4,1) |
28 | # pragma GCC visibility push(hidden) | 28 | # pragma GCC visibility push(hidden) |
29 | #endif | 29 | #endif |
30 | 30 | ||
31 | /* The group structure. */ | 31 | /* This file is #included after #include <grp.h> |
32 | struct group { | 32 | * We will use libc-defined structures, but will #define finction names |
33 | char *gr_name; /* Group name. */ | 33 | * so that function calls are directed to bb_internal_XXX replacements |
34 | char *gr_passwd; /* Password. */ | 34 | */ |
35 | gid_t gr_gid; /* Group ID. */ | ||
36 | char **gr_mem; /* Member list. */ | ||
37 | }; | ||
38 | |||
39 | 35 | ||
40 | #define setgrent bb_internal_setgrent | 36 | #define setgrent bb_internal_setgrent |
41 | #define endgrent bb_internal_endgrent | 37 | #define endgrent bb_internal_endgrent |
@@ -53,9 +49,7 @@ struct group { | |||
53 | 49 | ||
54 | 50 | ||
55 | /* All function names below should be remapped by #defines above | 51 | /* All function names below should be remapped by #defines above |
56 | * in order to not collide with libc names. | 52 | * in order to not collide with libc names. */ |
57 | * In theory it isn't necessary, but I saw weird interactions at link time. | ||
58 | * Let's play safe */ | ||
59 | 53 | ||
60 | 54 | ||
61 | /* Rewind the group-file stream. */ | 55 | /* Rewind the group-file stream. */ |
@@ -71,14 +65,14 @@ extern struct group *getgrent(void); | |||
71 | extern struct group *fgetgrent(FILE *__stream); | 65 | extern struct group *fgetgrent(FILE *__stream); |
72 | 66 | ||
73 | /* Write the given entry onto the given stream. */ | 67 | /* Write the given entry onto the given stream. */ |
74 | extern int putgrent(__const struct group *__restrict __p, | 68 | extern int putgrent(const struct group *__restrict __p, |
75 | FILE *__restrict __f); | 69 | FILE *__restrict __f); |
76 | 70 | ||
77 | /* Search for an entry with a matching group ID. */ | 71 | /* Search for an entry with a matching group ID. */ |
78 | extern struct group *getgrgid(gid_t __gid); | 72 | extern struct group *getgrgid(gid_t __gid); |
79 | 73 | ||
80 | /* Search for an entry with a matching group name. */ | 74 | /* Search for an entry with a matching group name. */ |
81 | extern struct group *getgrnam(__const char *__name); | 75 | extern struct group *getgrnam(const char *__name); |
82 | 76 | ||
83 | /* Reentrant versions of some of the functions above. | 77 | /* Reentrant versions of some of the functions above. |
84 | 78 | ||
@@ -98,7 +92,7 @@ extern int getgrgid_r(gid_t __gid, struct group *__restrict __resultbuf, | |||
98 | struct group **__restrict __result); | 92 | struct group **__restrict __result); |
99 | 93 | ||
100 | /* Search for an entry with a matching group name. */ | 94 | /* Search for an entry with a matching group name. */ |
101 | extern int getgrnam_r(__const char *__restrict __name, | 95 | extern int getgrnam_r(const char *__restrict __name, |
102 | struct group *__restrict __resultbuf, | 96 | struct group *__restrict __resultbuf, |
103 | char *__restrict __buffer, size_t __buflen, | 97 | char *__restrict __buffer, size_t __buflen, |
104 | struct group **__restrict __result); | 98 | struct group **__restrict __result); |
@@ -113,13 +107,13 @@ extern int fgetgrent_r(FILE *__restrict __stream, | |||
113 | /* Store at most *NGROUPS members of the group set for USER into | 107 | /* Store at most *NGROUPS members of the group set for USER into |
114 | *GROUPS. Also include GROUP. The actual number of groups found is | 108 | *GROUPS. Also include GROUP. The actual number of groups found is |
115 | returned in *NGROUPS. Return -1 if the if *NGROUPS is too small. */ | 109 | returned in *NGROUPS. Return -1 if the if *NGROUPS is too small. */ |
116 | extern int getgrouplist(__const char *__user, gid_t __group, | 110 | extern int getgrouplist(const char *__user, gid_t __group, |
117 | gid_t *__groups, int *__ngroups); | 111 | gid_t *__groups, int *__ngroups); |
118 | 112 | ||
119 | /* Initialize the group set for the current user | 113 | /* Initialize the group set for the current user |
120 | by reading the group database and using all groups | 114 | by reading the group database and using all groups |
121 | of which USER is a member. Also include GROUP. */ | 115 | of which USER is a member. Also include GROUP. */ |
122 | extern int initgroups(__const char *__user, gid_t __group); | 116 | extern int initgroups(const char *__user, gid_t __group); |
123 | 117 | ||
124 | #if __GNUC_PREREQ(4,1) | 118 | #if __GNUC_PREREQ(4,1) |
125 | # pragma GCC visibility pop | 119 | # pragma GCC visibility pop |
diff --git a/include/libbb.h b/include/libbb.h index 951ff2f1a..5b92574dd 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -69,21 +69,15 @@ | |||
69 | #include <dmalloc.h> | 69 | #include <dmalloc.h> |
70 | #endif | 70 | #endif |
71 | 71 | ||
72 | #if !ENABLE_USE_BB_PWD_GRP | 72 | #include <pwd.h> |
73 | # include <pwd.h> | 73 | #include <grp.h> |
74 | # include <grp.h> | ||
75 | #endif | ||
76 | #if ENABLE_FEATURE_SHADOWPASSWDS | 74 | #if ENABLE_FEATURE_SHADOWPASSWDS |
77 | # if !ENABLE_USE_BB_SHADOW | 75 | # include <shadow.h> |
78 | # include <shadow.h> | ||
79 | # endif | ||
80 | #endif | 76 | #endif |
81 | 77 | ||
82 | /* Some libc's forget to declare these, do it ourself */ | 78 | /* Some libc's forget to declare these, do it ourself */ |
83 | 79 | ||
84 | extern char **environ; | 80 | extern char **environ; |
85 | /* Set the group set for the current user to GROUPS (N of them). */ | ||
86 | int setgroups(size_t n, const gid_t *groups); | ||
87 | #if defined(__GLIBC__) && __GLIBC__ < 2 | 81 | #if defined(__GLIBC__) && __GLIBC__ < 2 |
88 | int vdprintf(int d, const char *format, va_list ap); | 82 | int vdprintf(int d, const char *format, va_list ap); |
89 | #endif | 83 | #endif |
diff --git a/include/pwd_.h b/include/pwd_.h index 6199034d2..c36e4686c 100644 --- a/include/pwd_.h +++ b/include/pwd_.h | |||
@@ -21,24 +21,17 @@ | |||
21 | * POSIX Standard: 9.2.2 User Database Access <pwd.h> | 21 | * POSIX Standard: 9.2.2 User Database Access <pwd.h> |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #ifndef _PWD_H | 24 | #ifndef BB_PWD_H |
25 | #define _PWD_H 1 | 25 | #define BB_PWD_H 1 |
26 | 26 | ||
27 | #if __GNUC_PREREQ(4,1) | 27 | #if __GNUC_PREREQ(4,1) |
28 | # pragma GCC visibility push(hidden) | 28 | # pragma GCC visibility push(hidden) |
29 | #endif | 29 | #endif |
30 | 30 | ||
31 | /* The passwd structure. */ | 31 | /* This file is #included after #include <pwd.h> |
32 | struct passwd { | 32 | * We will use libc-defined structures, but will #define finction names |
33 | char *pw_name; /* Username. */ | 33 | * so that function calls are directed to bb_internal_XXX replacements |
34 | char *pw_passwd; /* Password. */ | 34 | */ |
35 | uid_t pw_uid; /* User ID. */ | ||
36 | gid_t pw_gid; /* Group ID. */ | ||
37 | char *pw_gecos; /* Real name. */ | ||
38 | char *pw_dir; /* Home directory. */ | ||
39 | char *pw_shell; /* Shell program. */ | ||
40 | }; | ||
41 | |||
42 | 35 | ||
43 | #define setpwent bb_internal_setpwent | 36 | #define setpwent bb_internal_setpwent |
44 | #define endpwent bb_internal_endpwent | 37 | #define endpwent bb_internal_endpwent |
@@ -51,13 +44,11 @@ struct passwd { | |||
51 | #define getpwuid_r bb_internal_getpwuid_r | 44 | #define getpwuid_r bb_internal_getpwuid_r |
52 | #define getpwnam_r bb_internal_getpwnam_r | 45 | #define getpwnam_r bb_internal_getpwnam_r |
53 | #define fgetpwent_r bb_internal_fgetpwent_r | 46 | #define fgetpwent_r bb_internal_fgetpwent_r |
54 | #define getpw bb_internal_getpw | 47 | //#define getpw bb_internal_getpw |
55 | 48 | ||
56 | 49 | ||
57 | /* All function names below should be remapped by #defines above | 50 | /* All function names below should be remapped by #defines above |
58 | * in order to not collide with libc names. | 51 | * in order to not collide with libc names. */ |
59 | * In theory it isn't necessary, but I saw weird interactions at link time. | ||
60 | * Let's play safe */ | ||
61 | 52 | ||
62 | 53 | ||
63 | /* Rewind the password-file stream. */ | 54 | /* Rewind the password-file stream. */ |
@@ -73,14 +64,14 @@ extern struct passwd *getpwent(void); | |||
73 | extern struct passwd *fgetpwent(FILE *__stream); | 64 | extern struct passwd *fgetpwent(FILE *__stream); |
74 | 65 | ||
75 | /* Write the given entry onto the given stream. */ | 66 | /* Write the given entry onto the given stream. */ |
76 | extern int putpwent(__const struct passwd *__restrict __p, | 67 | extern int putpwent(const struct passwd *__restrict __p, |
77 | FILE *__restrict __f); | 68 | FILE *__restrict __f); |
78 | 69 | ||
79 | /* Search for an entry with a matching user ID. */ | 70 | /* Search for an entry with a matching user ID. */ |
80 | extern struct passwd *getpwuid(uid_t __uid); | 71 | extern struct passwd *getpwuid(uid_t __uid); |
81 | 72 | ||
82 | /* Search for an entry with a matching username. */ | 73 | /* Search for an entry with a matching username. */ |
83 | extern struct passwd *getpwnam(__const char *__name); | 74 | extern struct passwd *getpwnam(const char *__name); |
84 | 75 | ||
85 | /* Reentrant versions of some of the functions above. | 76 | /* Reentrant versions of some of the functions above. |
86 | 77 | ||
@@ -99,7 +90,7 @@ extern int getpwuid_r(uid_t __uid, | |||
99 | char *__restrict __buffer, size_t __buflen, | 90 | char *__restrict __buffer, size_t __buflen, |
100 | struct passwd **__restrict __result); | 91 | struct passwd **__restrict __result); |
101 | 92 | ||
102 | extern int getpwnam_r(__const char *__restrict __name, | 93 | extern int getpwnam_r(const char *__restrict __name, |
103 | struct passwd *__restrict __resultbuf, | 94 | struct passwd *__restrict __resultbuf, |
104 | char *__restrict __buffer, size_t __buflen, | 95 | char *__restrict __buffer, size_t __buflen, |
105 | struct passwd **__restrict __result); | 96 | struct passwd **__restrict __result); |
@@ -114,7 +105,7 @@ extern int fgetpwent_r(FILE *__restrict __stream, | |||
114 | /* Re-construct the password-file line for the given uid | 105 | /* Re-construct the password-file line for the given uid |
115 | in the given buffer. This knows the format that the caller | 106 | in the given buffer. This knows the format that the caller |
116 | will expect, but this need not be the format of the password file. */ | 107 | will expect, but this need not be the format of the password file. */ |
117 | extern int getpw(uid_t __uid, char *__buffer); | 108 | /* UNUSED extern int getpw(uid_t __uid, char *__buffer); */ |
118 | 109 | ||
119 | #if __GNUC_PREREQ(4,1) | 110 | #if __GNUC_PREREQ(4,1) |
120 | # pragma GCC visibility pop | 111 | # pragma GCC visibility pop |
diff --git a/include/rtc_.h b/include/rtc_.h index 2e990581f..867edb3db 100644 --- a/include/rtc_.h +++ b/include/rtc_.h | |||
@@ -4,8 +4,8 @@ | |||
4 | * Licensed under the GPL-2 or later. | 4 | * Licensed under the GPL-2 or later. |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #ifndef _BB_RTC_H_ | 7 | #ifndef BB_RTC_H |
8 | #define _BB_RTC_H_ | 8 | #define BB_RTC_H |
9 | 9 | ||
10 | #include "libbb.h" | 10 | #include "libbb.h" |
11 | 11 | ||
diff --git a/include/shadow_.h b/include/shadow_.h index 5a8b71a47..73bed8400 100644 --- a/include/shadow_.h +++ b/include/shadow_.h | |||
@@ -19,32 +19,23 @@ | |||
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 | #ifndef _SHADOW_H | 22 | #ifndef BB_SHADOW_H |
23 | #define _SHADOW_H 1 | 23 | #define BB_SHADOW_H 1 |
24 | 24 | ||
25 | #if __GNUC_PREREQ(4,1) | 25 | #if __GNUC_PREREQ(4,1) |
26 | # pragma GCC visibility push(hidden) | 26 | # pragma GCC visibility push(hidden) |
27 | #endif | 27 | #endif |
28 | 28 | ||
29 | /* This file is #included after #include <shadow.h> | ||
30 | * We will use libc-defined structures, but will #define finction names | ||
31 | * so that function calls are directed to bb_internal_XXX replacements | ||
32 | */ | ||
33 | |||
29 | /* Paths to the user database files */ | 34 | /* Paths to the user database files */ |
30 | #ifndef _PATH_SHADOW | 35 | #ifndef _PATH_SHADOW |
31 | #define _PATH_SHADOW "/etc/shadow" | 36 | #define _PATH_SHADOW "/etc/shadow" |
32 | #endif | 37 | #endif |
33 | 38 | ||
34 | /* Structure of the password file */ | ||
35 | struct spwd { | ||
36 | char *sp_namp; /* Login name */ | ||
37 | char *sp_pwdp; /* Encrypted password */ | ||
38 | long sp_lstchg; /* Date of last change */ | ||
39 | long sp_min; /* Minimum number of days between changes */ | ||
40 | long sp_max; /* Maximum number of days between changes */ | ||
41 | long sp_warn; /* Number of days to warn user to change the password */ | ||
42 | long sp_inact; /* Number of days the account may be inactive */ | ||
43 | long sp_expire; /* Number of days since 1970-01-01 until account expires */ | ||
44 | unsigned long sp_flag; /* Reserved */ | ||
45 | }; | ||
46 | |||
47 | |||
48 | #define setspent bb_internal_setspent | 39 | #define setspent bb_internal_setspent |
49 | #define endspent bb_internal_endspent | 40 | #define endspent bb_internal_endspent |
50 | #define getspent bb_internal_getspent | 41 | #define getspent bb_internal_getspent |
@@ -61,9 +52,7 @@ struct spwd { | |||
61 | 52 | ||
62 | 53 | ||
63 | /* All function names below should be remapped by #defines above | 54 | /* All function names below should be remapped by #defines above |
64 | * in order to not collide with libc names. | 55 | * in order to not collide with libc names. */ |
65 | * In theory it isn't necessary, but I saw weird interactions at link time. | ||
66 | * Let's play safe */ | ||
67 | 56 | ||
68 | 57 | ||
69 | /* Open database for reading */ | 58 | /* Open database for reading */ |
@@ -76,26 +65,26 @@ extern void endspent(void); | |||
76 | extern struct spwd *getspent(void); | 65 | extern struct spwd *getspent(void); |
77 | 66 | ||
78 | /* Get shadow entry matching NAME */ | 67 | /* Get shadow entry matching NAME */ |
79 | extern struct spwd *getspnam(__const char *__name); | 68 | extern struct spwd *getspnam(const char *__name); |
80 | 69 | ||
81 | /* Read shadow entry from STRING */ | 70 | /* Read shadow entry from STRING */ |
82 | extern struct spwd *sgetspent(__const char *__string); | 71 | extern struct spwd *sgetspent(const char *__string); |
83 | 72 | ||
84 | /* Read next shadow entry from STREAM */ | 73 | /* Read next shadow entry from STREAM */ |
85 | extern struct spwd *fgetspent(FILE *__stream); | 74 | extern struct spwd *fgetspent(FILE *__stream); |
86 | 75 | ||
87 | /* Write line containing shadow password entry to stream */ | 76 | /* Write line containing shadow password entry to stream */ |
88 | extern int putspent(__const struct spwd *__p, FILE *__stream); | 77 | extern int putspent(const struct spwd *__p, FILE *__stream); |
89 | 78 | ||
90 | /* Reentrant versions of some of the functions above */ | 79 | /* Reentrant versions of some of the functions above */ |
91 | extern int getspent_r(struct spwd *__result_buf, char *__buffer, | 80 | extern int getspent_r(struct spwd *__result_buf, char *__buffer, |
92 | size_t __buflen, struct spwd **__result); | 81 | size_t __buflen, struct spwd **__result); |
93 | 82 | ||
94 | extern int getspnam_r(__const char *__name, struct spwd *__result_buf, | 83 | extern int getspnam_r(const char *__name, struct spwd *__result_buf, |
95 | char *__buffer, size_t __buflen, | 84 | char *__buffer, size_t __buflen, |
96 | struct spwd **__result); | 85 | struct spwd **__result); |
97 | 86 | ||
98 | extern int sgetspent_r(__const char *__string, struct spwd *__result_buf, | 87 | extern int sgetspent_r(const char *__string, struct spwd *__result_buf, |
99 | char *__buffer, size_t __buflen, | 88 | char *__buffer, size_t __buflen, |
100 | struct spwd **__result); | 89 | struct spwd **__result); |
101 | 90 | ||
diff --git a/libpwdgrp/pwd_grp.c b/libpwdgrp/pwd_grp.c index 98b8367ca..223cbde36 100644 --- a/libpwdgrp/pwd_grp.c +++ b/libpwdgrp/pwd_grp.c | |||
@@ -396,6 +396,7 @@ struct spwd *getspnam(const char *name) | |||
396 | } | 396 | } |
397 | #endif | 397 | #endif |
398 | 398 | ||
399 | #ifdef THIS_ONE_IS_UNUSED | ||
399 | /* This one doesn't use static buffers */ | 400 | /* This one doesn't use static buffers */ |
400 | int getpw(uid_t uid, char *buf) | 401 | int getpw(uid_t uid, char *buf) |
401 | { | 402 | { |
@@ -419,6 +420,7 @@ int getpw(uid_t uid, char *buf) | |||
419 | 420 | ||
420 | return -1; | 421 | return -1; |
421 | } | 422 | } |
423 | #endif | ||
422 | 424 | ||
423 | /**********************************************************************/ | 425 | /**********************************************************************/ |
424 | 426 | ||