From 7fa0fcafca76454effc65f8c3121a37cf0952ff9 Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Thu, 28 Dec 2006 21:33:30 +0000 Subject: fix build without shadow support --- coreutils/id.c | 21 +++---- include/libbb.h | 2 - include/shadow_.h | 87 ++++++++++++--------------- libpwdgrp/pwd_grp.c | 167 ++++++++++++++++++++++++++++----------------------- 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) #ifdef CONFIG_SELINUX if (is_selinux_enabled()) { - security_context_t mysid; - char context[80]; - int len = sizeof(context); + security_context_t mysid; + const char *context; - getcon(&mysid); - context[0] = '\0'; - if (mysid) { - len = strlen(mysid)+1; - safe_strncpy(context, mysid, len); - freecon(mysid); - } else { - safe_strncpy(context, "unknown", 8); - } + context = "unknown"; + getcon(&mysid); + if (mysid) { + context = alloca(strlen(mysid) + 1); + strcpy((char*)context, mysid); + freecon(mysid); + } printf(" context=%s", context); } #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 @@ #include "pwd_.h" #include "grp_.h" -#if ENABLE_FEATURE_SHADOWPASSWDS #include "shadow_.h" -#endif /* Try to pull in PATH_MAX */ #include 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 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -/* Declaration of types and functions for shadow password suite. */ +/* Declaration of types and functions for shadow password suite */ -#if !defined CONFIG_USE_BB_SHADOW +#if !ENABLE_USE_BB_SHADOW #include #else #ifndef _SHADOW_H #define _SHADOW_H 1 -#include - -/* Paths to the user database files. */ +/* Paths to the user database files */ #ifndef _PATH_SHADOW -#define _PATH_SHADOW "/etc/shadow" +#define _PATH_SHADOW "/etc/shadow" #endif -#define SHADOW _PATH_SHADOW - - -/* Structure of the password file. */ -struct spwd -{ - char *sp_namp; /* Login name. */ - char *sp_pwdp; /* Encrypted password. */ - long int sp_lstchg; /* Date of last change. */ - long int sp_min; /* Minimum number of days between changes. */ - long int sp_max; /* Maximum number of days between changes. */ - long int sp_warn; /* Number of days to warn user to change - the password. */ - long int sp_inact; /* Number of days the account may be - inactive. */ - long int sp_expire; /* Number of days since 1970-01-01 until - account expires. */ - unsigned long int sp_flag; /* Reserved. */ -}; +/* Structure of the password file */ +struct spwd { + char *sp_namp; /* Login name */ + char *sp_pwdp; /* Encrypted password */ + long int sp_lstchg; /* Date of last change */ + long int sp_min; /* Minimum number of days between changes */ + long int sp_max; /* Maximum number of days between changes */ + long int sp_warn; /* Number of days to warn user to change the password */ + long int sp_inact; /* Number of days the account may be inactive */ + long int sp_expire; /* Number of days since 1970-01-01 until account expires */ + unsigned long int sp_flag; /* Reserved */ +}; -/* Open database for reading. */ -extern void setspent (void); +/* Open database for reading */ +extern void setspent(void); -/* Close database. */ -extern void endspent (void); +/* Close database */ +extern void endspent(void); -/* Get next entry from database, perhaps after opening the file. */ -extern struct spwd *getspent (void); +/* Get next entry from database, perhaps after opening the file */ +extern struct spwd *getspent(void); -/* Get shadow entry matching NAME. */ -extern struct spwd *getspnam (__const char *__name); +/* Get shadow entry matching NAME */ +extern struct spwd *getspnam(__const char *__name); -/* Read shadow entry from STRING. */ -extern struct spwd *sgetspent (__const char *__string); +/* Read shadow entry from STRING */ +extern struct spwd *sgetspent(__const char *__string); -/* Read next shadow entry from STREAM. */ -extern struct spwd *fgetspent (FILE *__stream); +/* Read next shadow entry from STREAM */ +extern struct spwd *fgetspent(FILE *__stream); -/* Write line containing shadow password entry to stream. */ -extern int putspent (__const struct spwd *__p, FILE *__stream); +/* Write line containing shadow password entry to stream */ +extern int putspent(__const struct spwd *__p, FILE *__stream); -/* Reentrant versions of some of the functions above. */ -extern int getspent_r (struct spwd *__result_buf, char *__buffer, +/* Reentrant versions of some of the functions above */ +extern int getspent_r(struct spwd *__result_buf, char *__buffer, 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, 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, struct spwd **__result); -extern int fgetspent_r (FILE *__stream, struct spwd *__result_buf, +extern int fgetspent_r(FILE *__stream, struct spwd *__result_buf, char *__buffer, size_t __buflen, struct spwd **__result); -/* Protect password file against multi writers. */ -extern int lckpwdf (void); +/* Protect password file against multi writers */ +extern int lckpwdf(void); -/* Unlock password file. */ -extern int ulckpwdf (void); +/* Unlock password file */ +extern int ulckpwdf(void); #endif /* shadow.h */ #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 @@ #include "libbb.h" #include -#include -#include -#include -#include -#include -#include #include -#include #ifndef _PATH_SHADOW #define _PATH_SHADOW "/etc/shadow" @@ -50,13 +43,15 @@ /**********************************************************************/ /* Prototypes for internal functions. */ -extern int __parsepwent(void *pw, char *line); -extern int __parsegrent(void *gr, char *line); -extern int __parsespent(void *sp, char *line); - -extern int __pgsreader(int (*__parserfunc)(void *d, char *line), void *data, +static int __pgsreader(int (*parserfunc)(void *d, char *line), void *data, char *__restrict line_buff, size_t buflen, FILE *f); +static int __parsepwent(void *pw, char *line); +static int __parsegrent(void *gr, char *line); +#if ENABLE_USE_BB_SHADOW +static int __parsespent(void *sp, char *line); +#endif + /**********************************************************************/ /* For the various fget??ent_r funcs, return * @@ -81,7 +76,8 @@ int fgetpwent_r(FILE *__restrict stream, struct passwd *__restrict resultbuf, *result = NULL; - if (!(rv = __pgsreader(__parsepwent, resultbuf, buffer, buflen, stream))) { + rv = __pgsreader(__parsepwent, resultbuf, buffer, buflen, stream); + if (!rv) { *result = resultbuf; } @@ -96,13 +92,15 @@ int fgetgrent_r(FILE *__restrict stream, struct group *__restrict resultbuf, *result = NULL; - if (!(rv = __pgsreader(__parsegrent, resultbuf, buffer, buflen, stream))) { + rv = __pgsreader(__parsegrent, resultbuf, buffer, buflen, stream); + if (!rv) { *result = resultbuf; } return rv; } +#if ENABLE_USE_BB_SHADOW int fgetspent_r(FILE *__restrict stream, struct spwd *__restrict resultbuf, char *__restrict buffer, size_t buflen, struct spwd **__restrict result) @@ -111,12 +109,14 @@ int fgetspent_r(FILE *__restrict stream, struct spwd *__restrict resultbuf, *result = NULL; - if (!(rv = __pgsreader(__parsespent, resultbuf, buffer, buflen, stream))) { + rv = __pgsreader(__parsespent, resultbuf, buffer, buflen, stream); + if (!rv) { *result = resultbuf; } return rv; } +#endif /**********************************************************************/ /* For the various fget??ent funcs, return NULL on failure and a @@ -144,9 +144,7 @@ struct group *fgetgrent(FILE *stream) return result; } -extern int fgetspent_r(FILE *__restrict stream, struct spwd *__restrict resultbuf, - char *__restrict buffer, size_t buflen, - struct spwd **__restrict result); +#if ENABLE_USE_BB_SHADOW struct spwd *fgetspent(FILE *stream) { static char buffer[PWD_BUFFER_SIZE]; @@ -177,13 +175,15 @@ int sgetspent_r(const char *string, struct spwd *result_buf, strcpy(buffer, string); } - if (!(rv = __parsespent(result_buf, buffer))) { + rv = __parsespent(result_buf, buffer); + if (!rv) { *result = result_buf; } DONE: return rv; } +#endif /**********************************************************************/ @@ -191,43 +191,45 @@ int sgetspent_r(const char *string, struct spwd *result_buf, #error GETXXKEY_R_FUNC is already defined! #endif -#define GETXXKEY_R_FUNC getpwnam_R -#define GETXXKEY_R_PARSER __parsepwent -#define GETXXKEY_R_ENTTYPE struct passwd -#define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->pw_name, key)) -#define DO_GETXXKEY_R_KEYTYPE const char *__restrict +#define GETXXKEY_R_FUNC getpwnam_R +#define GETXXKEY_R_PARSER __parsepwent +#define GETXXKEY_R_ENTTYPE struct passwd +#define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->pw_name, key)) +#define DO_GETXXKEY_R_KEYTYPE const char *__restrict #define DO_GETXXKEY_R_PATHNAME _PATH_PASSWD #include "pwd_grp_internal.c" -#define GETXXKEY_R_FUNC getgrnam_R -#define GETXXKEY_R_PARSER __parsegrent -#define GETXXKEY_R_ENTTYPE struct group -#define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->gr_name, key)) -#define DO_GETXXKEY_R_KEYTYPE const char *__restrict +#define GETXXKEY_R_FUNC getgrnam_R +#define GETXXKEY_R_PARSER __parsegrent +#define GETXXKEY_R_ENTTYPE struct group +#define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->gr_name, key)) +#define DO_GETXXKEY_R_KEYTYPE const char *__restrict #define DO_GETXXKEY_R_PATHNAME _PATH_GROUP #include "pwd_grp_internal.c" -#define GETXXKEY_R_FUNC getspnam_R -#define GETXXKEY_R_PARSER __parsespent -#define GETXXKEY_R_ENTTYPE struct spwd -#define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->sp_namp, key)) -#define DO_GETXXKEY_R_KEYTYPE const char *__restrict +#if ENABLE_USE_BB_SHADOW +#define GETXXKEY_R_FUNC getspnam_R +#define GETXXKEY_R_PARSER __parsespent +#define GETXXKEY_R_ENTTYPE struct spwd +#define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->sp_namp, key)) +#define DO_GETXXKEY_R_KEYTYPE const char *__restrict #define DO_GETXXKEY_R_PATHNAME _PATH_SHADOW #include "pwd_grp_internal.c" +#endif -#define GETXXKEY_R_FUNC getpwuid_R -#define GETXXKEY_R_PARSER __parsepwent -#define GETXXKEY_R_ENTTYPE struct passwd -#define GETXXKEY_R_TEST(ENT) ((ENT)->pw_uid == key) -#define DO_GETXXKEY_R_KEYTYPE uid_t +#define GETXXKEY_R_FUNC getpwuid_R +#define GETXXKEY_R_PARSER __parsepwent +#define GETXXKEY_R_ENTTYPE struct passwd +#define GETXXKEY_R_TEST(ENT) ((ENT)->pw_uid == key) +#define DO_GETXXKEY_R_KEYTYPE uid_t #define DO_GETXXKEY_R_PATHNAME _PATH_PASSWD #include "pwd_grp_internal.c" -#define GETXXKEY_R_FUNC getgrgid_R -#define GETXXKEY_R_PARSER __parsegrent -#define GETXXKEY_R_ENTTYPE struct group -#define GETXXKEY_R_TEST(ENT) ((ENT)->gr_gid == key) -#define DO_GETXXKEY_R_KEYTYPE gid_t +#define GETXXKEY_R_FUNC getgrgid_R +#define GETXXKEY_R_PARSER __parsegrent +#define GETXXKEY_R_ENTTYPE struct group +#define GETXXKEY_R_TEST(ENT) ((ENT)->gr_gid == key) +#define DO_GETXXKEY_R_KEYTYPE gid_t #define DO_GETXXKEY_R_PATHNAME _PATH_GROUP #include "pwd_grp_internal.c" @@ -253,10 +255,10 @@ struct group *getgrgid(gid_t gid) return result; } +#if 0 //ENABLE_USE_BB_SHADOW /* This function is non-standard and is currently not built. It seems * to have been created as a reentrant version of the non-standard * functions getspuid. Why getspuid was added, I do not know. */ - int getspuid_r(uid_t uid, struct spwd *__restrict resultbuf, char *__restrict buffer, size_t buflen, struct spwd **__restrict result) @@ -267,7 +269,8 @@ int getspuid_r(uid_t uid, struct spwd *__restrict resultbuf, char pwd_buff[PWD_BUFFER_SIZE]; *result = NULL; - if (!(rv = getpwuid_r(uid, &password, pwd_buff, sizeof(pwd_buff), &pp))) { + rv = getpwuid_r(uid, &password, pwd_buff, sizeof(pwd_buff), &pp); + if (!rv) { rv = getspnam_r(password.pw_name, resultbuf, buffer, buflen, result); } @@ -276,7 +279,6 @@ int getspuid_r(uid_t uid, struct spwd *__restrict resultbuf, /* This function is non-standard and is currently not built. * Why it was added, I do not know. */ - struct spwd *getspuid(uid_t uid) { static char buffer[PWD_BUFFER_SIZE]; @@ -286,6 +288,7 @@ struct spwd *getspuid(uid_t uid) getspuid_r(uid, &resultbuf, buffer, sizeof(buffer), &result); return result; } +#endif struct passwd *getpwnam(const char *name) { @@ -307,6 +310,7 @@ struct group *getgrnam(const char *name) return result; } +#if ENABLE_USE_BB_SHADOW struct spwd *getspnam(const char *name) { static char buffer[PWD_BUFFER_SIZE]; @@ -316,6 +320,7 @@ struct spwd *getspnam(const char *name) getspnam_r(name, &resultbuf, buffer, sizeof(buffer), &result); return result; } +#endif int getpw(uid_t uid, char *buf) { @@ -382,14 +387,15 @@ int getpwent_r(struct passwd *__restrict resultbuf, *result = NULL; /* In case of error... */ if (!pwf) { - if (!(pwf = fopen(_PATH_PASSWD, "r"))) { + pwf = fopen(_PATH_PASSWD, "r"); + if (!pwf) { rv = errno; goto ERR; } } - if (!(rv = __pgsreader(__parsepwent, resultbuf, - buffer, buflen, pwf))) { + rv = __pgsreader(__parsepwent, resultbuf, buffer, buflen, pwf); + if (!rv) { *result = resultbuf; } @@ -428,14 +434,15 @@ int getgrent_r(struct group *__restrict resultbuf, *result = NULL; /* In case of error... */ if (!grf) { - if (!(grf = fopen(_PATH_GROUP, "r"))) { + grf = fopen(_PATH_GROUP, "r"); + if (!grf) { rv = errno; goto ERR; } } - if (!(rv = __pgsreader(__parsegrent, resultbuf, - buffer, buflen, grf))) { + rv = __pgsreader(__parsegrent, resultbuf, buffer, buflen, grf); + if (!rv) { *result = resultbuf; } @@ -444,6 +451,7 @@ int getgrent_r(struct group *__restrict resultbuf, return rv; } +#if ENABLE_USE_BB_SHADOW static FILE *spf /*= NULL*/; void setspent(void) { @@ -473,14 +481,15 @@ int getspent_r(struct spwd *resultbuf, char *buffer, *result = NULL; /* In case of error... */ if (!spf) { - if (!(spf = fopen(_PATH_SHADOW, "r"))) { + spf = fopen(_PATH_SHADOW, "r"); + if (!spf) { rv = errno; goto ERR; } } - if (!(rv = __pgsreader(__parsespent, resultbuf, - buffer, buflen, spf))) { + rv = __pgsreader(__parsespent, resultbuf, buffer, buflen, spf); + if (!rv) { *result = resultbuf; } @@ -488,6 +497,7 @@ int getspent_r(struct spwd *resultbuf, char *buffer, UNLOCK; return rv; } +#endif struct passwd *getpwent(void) { @@ -509,6 +519,7 @@ struct group *getgrent(void) return result; } +#if ENABLE_USE_BB_SHADOW struct spwd *getspent(void) { static char line_buff[PWD_BUFFER_SIZE]; @@ -528,6 +539,7 @@ struct spwd *sgetspent(const char *string) sgetspent_r(string, &spwd, line_buff, sizeof(line_buff), &result); return result; } +#endif int initgroups(const char *user, gid_t gid) { @@ -541,10 +553,10 @@ int initgroups(const char *user, gid_t gid) rv = -1; /* We alloc space for 8 gids at a time. */ - if (((group_list = (gid_t *) malloc(8*sizeof(gid_t *))) != NULL) - && ((grfile = fopen(_PATH_GROUP, "r")) != NULL) - ) { - + group_list = (gid_t *) malloc(8*sizeof(gid_t *)); + if (group_list + && ((grfile = fopen(_PATH_GROUP, "r")) != NULL) + ) { *group_list = gid; num_groups = 1; @@ -643,6 +655,7 @@ int putgrent(const struct group *__restrict p, FILE *__restrict f) return rv; } +#if ENABLE_USE_BB_SHADOW static const unsigned char _sp_off[] = { offsetof(struct spwd, sp_lstchg), /* 2 - not a char ptr */ offsetof(struct spwd, sp_min), /* 3 - not a char ptr */ @@ -663,13 +676,14 @@ int putspent(const struct spwd *p, FILE *stream) /* Unlike putpwent and putgrent, glibc does not check the args. */ if (fprintf(stream, "%s:%s:", p->sp_namp, (p->sp_pwdp ? p->sp_pwdp : "")) < 0 - ) { + ) { goto DO_UNLOCK; } for (i=0 ; i < sizeof(_sp_off) ; i++) { f = ld_format; - if ((x = *(const long int *)(((const char *) p) + _sp_off[i])) == -1) { + x = *(const long int *)(((const char *) p) + _sp_off[i]); + if (x == -1) { f += 3; } if (fprintf(stream, f, x) < 0) { @@ -688,6 +702,7 @@ int putspent(const struct spwd *p, FILE *stream) DO_UNLOCK: return rv; } +#endif /**********************************************************************/ /* Internal uClibc functions. */ @@ -703,7 +718,7 @@ static const unsigned char pw_off[] = { offsetof(struct passwd, pw_shell) /* 6 */ }; -int __parsepwent(void *data, char *line) +static int __parsepwent(void *data, char *line) { char *endptr; char *p; @@ -721,7 +736,8 @@ int __parsepwent(void *data, char *line) /* NOTE: glibc difference - glibc allows omission of * ':' seperators after the gid field if all remaining * entries are empty. We require all separators. */ - if (!(line = strchr(line, ':'))) { + line = strchr(line, ':'); + if (!line) { break; } } else { @@ -756,7 +772,7 @@ static const unsigned char gr_off[] = { offsetof(struct group, gr_gid) /* 2 - not a char ptr */ }; -int __parsegrent(void *data, char *line) +static int __parsegrent(void *data, char *line) { char *endptr; char *p; @@ -771,7 +787,8 @@ int __parsegrent(void *data, char *line) if (i < 2) { *((char **) p) = line; - if (!(line = strchr(line, ':'))) { + line = strchr(line, ':'); + if (!line) { break; } *line++ = 0; @@ -845,7 +862,7 @@ int __parsegrent(void *data, char *line) } /**********************************************************************/ - +#if ENABLE_USE_BB_SHADOW static const unsigned char sp_off[] = { offsetof(struct spwd, sp_namp), /* 0 */ offsetof(struct spwd, sp_pwdp), /* 1 */ @@ -858,7 +875,7 @@ static const unsigned char sp_off[] = { offsetof(struct spwd, sp_flag) /* 8 - not a char ptr */ }; -int __parsespent(void *data, char * line) +static int __parsespent(void *data, char * line) { char *endptr; char *p; @@ -869,7 +886,8 @@ int __parsespent(void *data, char * line) p = ((char *) ((struct spwd *) data)) + sp_off[i]; if (i < 2) { *((char **) p) = line; - if (!(line = strchr(line, ':'))) { + line = strchr(line, ':'); + if (!line) { break; } } else { @@ -900,6 +918,7 @@ int __parsespent(void *data, char * line) return EINVAL; } +#endif /**********************************************************************/ @@ -909,7 +928,7 @@ int __parsespent(void *data, char * line) * Returns 0 on success and ENOENT for end-of-file (glibc concession). */ -int __pgsreader(int (*__parserfunc)(void *d, char *line), void *data, +static int __pgsreader(int (*parserfunc)(void *d, char *line), void *data, char *__restrict line_buff, size_t buflen, FILE *f) { int line_len; @@ -917,7 +936,7 @@ int __pgsreader(int (*__parserfunc)(void *d, char *line), void *data, int rv = ERANGE; if (buflen < PWD_BUFFER_SIZE) { - errno=rv; + errno = rv; } else { skip = 0; do { @@ -947,14 +966,14 @@ int __pgsreader(int (*__parserfunc)(void *d, char *line), void *data, /* Skip empty lines, comment lines, and lines with leading * whitespace. */ if (*line_buff && (*line_buff != '#') && !isspace(*line_buff)) { - if (__parserfunc == __parsegrent) { /* Do evil group hack. */ + if (parserfunc == __parsegrent) { /* Do evil group hack. */ /* The group entry parsing function needs to know where * the end of the buffer is so that it can construct the * group member ptr table. */ ((struct group *) data)->gr_name = line_buff + buflen; } - if (!__parserfunc(data, line_buff)) { + if (!parserfunc(data, line_buff)) { rv = 0; break; } @@ -965,5 +984,3 @@ int __pgsreader(int (*__parserfunc)(void *d, char *line), void *data, return rv; } - -/**********************************************************************/ 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) char *timeout_arg; const char * const *p; struct passwd *pwd; - struct spwd *spwd; const char *shell; logmode = LOGMODE_BOTH; @@ -76,7 +75,7 @@ int sulogin_main(int argc, char **argv) } if (ENABLE_FEATURE_SHADOWPASSWDS) { - spwd = getspnam(pwd->pw_name); + struct spwd *spwd = getspnam(pwd->pw_name); if (!spwd) { goto auth_error; } -- cgit v1.2.3