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).
This commit is contained in:
Denis Vlasenko 2008-09-26 10:35:55 +00:00
parent f1980f67d3
commit ee5dce3365
6 changed files with 44 additions and 74 deletions

View File

@ -21,21 +21,17 @@
* POSIX Standard: 9.2.1 Group Database Access <grp.h> * POSIX Standard: 9.2.1 Group Database Access <grp.h>
*/ */
#ifndef _GRP_H #ifndef BB_GRP_H
#define _GRP_H 1 #define BB_GRP_H 1
#if __GNUC_PREREQ(4,1) #if __GNUC_PREREQ(4,1)
# pragma GCC visibility push(hidden) # pragma GCC visibility push(hidden)
#endif #endif
/* The group structure. */ /* This file is #included after #include <grp.h>
struct group { * We will use libc-defined structures, but will #define finction names
char *gr_name; /* Group name. */ * so that function calls are directed to bb_internal_XXX replacements
char *gr_passwd; /* Password. */ */
gid_t gr_gid; /* Group ID. */
char **gr_mem; /* Member list. */
};
#define setgrent bb_internal_setgrent #define setgrent bb_internal_setgrent
#define endgrent bb_internal_endgrent #define endgrent bb_internal_endgrent
@ -53,9 +49,7 @@ struct group {
/* All function names below should be remapped by #defines above /* All function names below should be remapped by #defines above
* in order to not collide with libc names. * in order to not collide with libc names. */
* In theory it isn't necessary, but I saw weird interactions at link time.
* Let's play safe */
/* Rewind the group-file stream. */ /* Rewind the group-file stream. */
@ -71,14 +65,14 @@ extern struct group *getgrent(void);
extern struct group *fgetgrent(FILE *__stream); extern struct group *fgetgrent(FILE *__stream);
/* Write the given entry onto the given stream. */ /* Write the given entry onto the given stream. */
extern int putgrent(__const struct group *__restrict __p, extern int putgrent(const struct group *__restrict __p,
FILE *__restrict __f); FILE *__restrict __f);
/* Search for an entry with a matching group ID. */ /* Search for an entry with a matching group ID. */
extern struct group *getgrgid(gid_t __gid); extern struct group *getgrgid(gid_t __gid);
/* Search for an entry with a matching group name. */ /* Search for an entry with a matching group name. */
extern struct group *getgrnam(__const char *__name); extern struct group *getgrnam(const char *__name);
/* Reentrant versions of some of the functions above. /* Reentrant versions of some of the functions above.
@ -98,7 +92,7 @@ extern int getgrgid_r(gid_t __gid, struct group *__restrict __resultbuf,
struct group **__restrict __result); struct group **__restrict __result);
/* Search for an entry with a matching group name. */ /* Search for an entry with a matching group name. */
extern int getgrnam_r(__const char *__restrict __name, extern int getgrnam_r(const char *__restrict __name,
struct group *__restrict __resultbuf, struct group *__restrict __resultbuf,
char *__restrict __buffer, size_t __buflen, char *__restrict __buffer, size_t __buflen,
struct group **__restrict __result); struct group **__restrict __result);
@ -113,13 +107,13 @@ extern int fgetgrent_r(FILE *__restrict __stream,
/* Store at most *NGROUPS members of the group set for USER into /* Store at most *NGROUPS members of the group set for USER into
*GROUPS. Also include GROUP. The actual number of groups found is *GROUPS. Also include GROUP. The actual number of groups found is
returned in *NGROUPS. Return -1 if the if *NGROUPS is too small. */ returned in *NGROUPS. Return -1 if the if *NGROUPS is too small. */
extern int getgrouplist(__const char *__user, gid_t __group, extern int getgrouplist(const char *__user, gid_t __group,
gid_t *__groups, int *__ngroups); gid_t *__groups, int *__ngroups);
/* Initialize the group set for the current user /* Initialize the group set for the current user
by reading the group database and using all groups by reading the group database and using all groups
of which USER is a member. Also include GROUP. */ of which USER is a member. Also include GROUP. */
extern int initgroups(__const char *__user, gid_t __group); extern int initgroups(const char *__user, gid_t __group);
#if __GNUC_PREREQ(4,1) #if __GNUC_PREREQ(4,1)
# pragma GCC visibility pop # pragma GCC visibility pop

View File

@ -69,21 +69,15 @@
#include <dmalloc.h> #include <dmalloc.h>
#endif #endif
#if !ENABLE_USE_BB_PWD_GRP #include <pwd.h>
# include <pwd.h> #include <grp.h>
# include <grp.h>
#endif
#if ENABLE_FEATURE_SHADOWPASSWDS #if ENABLE_FEATURE_SHADOWPASSWDS
# if !ENABLE_USE_BB_SHADOW # include <shadow.h>
# include <shadow.h>
# endif
#endif #endif
/* Some libc's forget to declare these, do it ourself */ /* Some libc's forget to declare these, do it ourself */
extern char **environ; extern char **environ;
/* Set the group set for the current user to GROUPS (N of them). */
int setgroups(size_t n, const gid_t *groups);
#if defined(__GLIBC__) && __GLIBC__ < 2 #if defined(__GLIBC__) && __GLIBC__ < 2
int vdprintf(int d, const char *format, va_list ap); int vdprintf(int d, const char *format, va_list ap);
#endif #endif

View File

@ -21,24 +21,17 @@
* POSIX Standard: 9.2.2 User Database Access <pwd.h> * POSIX Standard: 9.2.2 User Database Access <pwd.h>
*/ */
#ifndef _PWD_H #ifndef BB_PWD_H
#define _PWD_H 1 #define BB_PWD_H 1
#if __GNUC_PREREQ(4,1) #if __GNUC_PREREQ(4,1)
# pragma GCC visibility push(hidden) # pragma GCC visibility push(hidden)
#endif #endif
/* The passwd structure. */ /* This file is #included after #include <pwd.h>
struct passwd { * We will use libc-defined structures, but will #define finction names
char *pw_name; /* Username. */ * so that function calls are directed to bb_internal_XXX replacements
char *pw_passwd; /* Password. */ */
uid_t pw_uid; /* User ID. */
gid_t pw_gid; /* Group ID. */
char *pw_gecos; /* Real name. */
char *pw_dir; /* Home directory. */
char *pw_shell; /* Shell program. */
};
#define setpwent bb_internal_setpwent #define setpwent bb_internal_setpwent
#define endpwent bb_internal_endpwent #define endpwent bb_internal_endpwent
@ -51,13 +44,11 @@ struct passwd {
#define getpwuid_r bb_internal_getpwuid_r #define getpwuid_r bb_internal_getpwuid_r
#define getpwnam_r bb_internal_getpwnam_r #define getpwnam_r bb_internal_getpwnam_r
#define fgetpwent_r bb_internal_fgetpwent_r #define fgetpwent_r bb_internal_fgetpwent_r
#define getpw bb_internal_getpw //#define getpw bb_internal_getpw
/* All function names below should be remapped by #defines above /* All function names below should be remapped by #defines above
* in order to not collide with libc names. * in order to not collide with libc names. */
* In theory it isn't necessary, but I saw weird interactions at link time.
* Let's play safe */
/* Rewind the password-file stream. */ /* Rewind the password-file stream. */
@ -73,14 +64,14 @@ extern struct passwd *getpwent(void);
extern struct passwd *fgetpwent(FILE *__stream); extern struct passwd *fgetpwent(FILE *__stream);
/* Write the given entry onto the given stream. */ /* Write the given entry onto the given stream. */
extern int putpwent(__const struct passwd *__restrict __p, extern int putpwent(const struct passwd *__restrict __p,
FILE *__restrict __f); FILE *__restrict __f);
/* Search for an entry with a matching user ID. */ /* Search for an entry with a matching user ID. */
extern struct passwd *getpwuid(uid_t __uid); extern struct passwd *getpwuid(uid_t __uid);
/* Search for an entry with a matching username. */ /* Search for an entry with a matching username. */
extern struct passwd *getpwnam(__const char *__name); extern struct passwd *getpwnam(const char *__name);
/* Reentrant versions of some of the functions above. /* Reentrant versions of some of the functions above.
@ -99,7 +90,7 @@ extern int getpwuid_r(uid_t __uid,
char *__restrict __buffer, size_t __buflen, char *__restrict __buffer, size_t __buflen,
struct passwd **__restrict __result); struct passwd **__restrict __result);
extern int getpwnam_r(__const char *__restrict __name, extern int getpwnam_r(const char *__restrict __name,
struct passwd *__restrict __resultbuf, struct passwd *__restrict __resultbuf,
char *__restrict __buffer, size_t __buflen, char *__restrict __buffer, size_t __buflen,
struct passwd **__restrict __result); struct passwd **__restrict __result);
@ -114,7 +105,7 @@ extern int fgetpwent_r(FILE *__restrict __stream,
/* Re-construct the password-file line for the given uid /* Re-construct the password-file line for the given uid
in the given buffer. This knows the format that the caller in the given buffer. This knows the format that the caller
will expect, but this need not be the format of the password file. */ will expect, but this need not be the format of the password file. */
extern int getpw(uid_t __uid, char *__buffer); /* UNUSED extern int getpw(uid_t __uid, char *__buffer); */
#if __GNUC_PREREQ(4,1) #if __GNUC_PREREQ(4,1)
# pragma GCC visibility pop # pragma GCC visibility pop

View File

@ -4,8 +4,8 @@
* Licensed under the GPL-2 or later. * Licensed under the GPL-2 or later.
*/ */
#ifndef _BB_RTC_H_ #ifndef BB_RTC_H
#define _BB_RTC_H_ #define BB_RTC_H
#include "libbb.h" #include "libbb.h"

View File

@ -19,32 +19,23 @@
/* Declaration of types and functions for shadow password suite */ /* Declaration of types and functions for shadow password suite */
#ifndef _SHADOW_H #ifndef BB_SHADOW_H
#define _SHADOW_H 1 #define BB_SHADOW_H 1
#if __GNUC_PREREQ(4,1) #if __GNUC_PREREQ(4,1)
# pragma GCC visibility push(hidden) # pragma GCC visibility push(hidden)
#endif #endif
/* This file is #included after #include <shadow.h>
* We will use libc-defined structures, but will #define finction names
* so that function calls are directed to bb_internal_XXX replacements
*/
/* Paths to the user database files */ /* Paths to the user database files */
#ifndef _PATH_SHADOW #ifndef _PATH_SHADOW
#define _PATH_SHADOW "/etc/shadow" #define _PATH_SHADOW "/etc/shadow"
#endif #endif
/* Structure of the password file */
struct spwd {
char *sp_namp; /* Login name */
char *sp_pwdp; /* Encrypted password */
long sp_lstchg; /* Date of last change */
long sp_min; /* Minimum number of days between changes */
long sp_max; /* Maximum number of days between changes */
long sp_warn; /* Number of days to warn user to change the password */
long sp_inact; /* Number of days the account may be inactive */
long sp_expire; /* Number of days since 1970-01-01 until account expires */
unsigned long sp_flag; /* Reserved */
};
#define setspent bb_internal_setspent #define setspent bb_internal_setspent
#define endspent bb_internal_endspent #define endspent bb_internal_endspent
#define getspent bb_internal_getspent #define getspent bb_internal_getspent
@ -61,9 +52,7 @@ struct spwd {
/* All function names below should be remapped by #defines above /* All function names below should be remapped by #defines above
* in order to not collide with libc names. * in order to not collide with libc names. */
* In theory it isn't necessary, but I saw weird interactions at link time.
* Let's play safe */
/* Open database for reading */ /* Open database for reading */
@ -76,26 +65,26 @@ extern void endspent(void);
extern struct spwd *getspent(void); extern struct spwd *getspent(void);
/* Get shadow entry matching NAME */ /* Get shadow entry matching NAME */
extern struct spwd *getspnam(__const char *__name); extern struct spwd *getspnam(const char *__name);
/* Read shadow entry from STRING */ /* Read shadow entry from STRING */
extern struct spwd *sgetspent(__const char *__string); extern struct spwd *sgetspent(const char *__string);
/* Read next shadow entry from STREAM */ /* Read next shadow entry from STREAM */
extern struct spwd *fgetspent(FILE *__stream); extern struct spwd *fgetspent(FILE *__stream);
/* Write line containing shadow password entry to stream */ /* Write line containing shadow password entry to stream */
extern int putspent(__const struct spwd *__p, FILE *__stream); extern int putspent(const struct spwd *__p, FILE *__stream);
/* Reentrant versions of some of the functions above */ /* Reentrant versions of some of the functions above */
extern int getspent_r(struct spwd *__result_buf, char *__buffer, extern int getspent_r(struct spwd *__result_buf, char *__buffer,
size_t __buflen, struct spwd **__result); size_t __buflen, struct spwd **__result);
extern int getspnam_r(__const char *__name, struct spwd *__result_buf, extern int getspnam_r(const char *__name, struct spwd *__result_buf,
char *__buffer, size_t __buflen, char *__buffer, size_t __buflen,
struct spwd **__result); struct spwd **__result);
extern int sgetspent_r(__const char *__string, struct spwd *__result_buf, extern int sgetspent_r(const char *__string, struct spwd *__result_buf,
char *__buffer, size_t __buflen, char *__buffer, size_t __buflen,
struct spwd **__result); struct spwd **__result);

View File

@ -396,6 +396,7 @@ struct spwd *getspnam(const char *name)
} }
#endif #endif
#ifdef THIS_ONE_IS_UNUSED
/* This one doesn't use static buffers */ /* This one doesn't use static buffers */
int getpw(uid_t uid, char *buf) int getpw(uid_t uid, char *buf)
{ {
@ -419,6 +420,7 @@ int getpw(uid_t uid, char *buf)
return -1; return -1;
} }
#endif
/**********************************************************************/ /**********************************************************************/