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 <shadow.h>
#else
#ifndef _SHADOW_H
#define _SHADOW_H 1
-#include <stdio.h>
-
-/* 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
#include "libbb.h"
#include <features.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <string.h>
-#include <stddef.h>
-#include <errno.h>
#include <assert.h>
-#include <ctype.h>
#ifndef _PATH_SHADOW
#define _PATH_SHADOW "/etc/shadow"
/**********************************************************************/
/* 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
*
*result = NULL;
- if (!(rv = __pgsreader(__parsepwent, resultbuf, buffer, buflen, stream))) {
+ rv = __pgsreader(__parsepwent, resultbuf, buffer, buflen, stream);
+ if (!rv) {
*result = 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)
*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
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];
strcpy(buffer, string);
}
- if (!(rv = __parsespent(result_buf, buffer))) {
+ rv = __parsespent(result_buf, buffer);
+ if (!rv) {
*result = result_buf;
}
DONE:
return rv;
}
+#endif
/**********************************************************************/
#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"
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)
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);
}
/* 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];
getspuid_r(uid, &resultbuf, buffer, sizeof(buffer), &result);
return result;
}
+#endif
struct passwd *getpwnam(const char *name)
{
return result;
}
+#if ENABLE_USE_BB_SHADOW
struct spwd *getspnam(const char *name)
{
static char buffer[PWD_BUFFER_SIZE];
getspnam_r(name, &resultbuf, buffer, sizeof(buffer), &result);
return result;
}
+#endif
int getpw(uid_t uid, char *buf)
{
*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;
}
*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;
}
return rv;
}
+#if ENABLE_USE_BB_SHADOW
static FILE *spf /*= NULL*/;
void setspent(void)
{
*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;
}
UNLOCK;
return rv;
}
+#endif
struct passwd *getpwent(void)
{
return result;
}
+#if ENABLE_USE_BB_SHADOW
struct spwd *getspent(void)
{
static char line_buff[PWD_BUFFER_SIZE];
sgetspent_r(string, &spwd, line_buff, sizeof(line_buff), &result);
return result;
}
+#endif
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;
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 */
/* 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) {
DO_UNLOCK:
return rv;
}
+#endif
/**********************************************************************/
/* Internal uClibc functions. */
offsetof(struct passwd, pw_shell) /* 6 */
};
-int __parsepwent(void *data, char *line)
+static int __parsepwent(void *data, char *line)
{
char *endptr;
char *p;
/* 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 {
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;
if (i < 2) {
*((char **) p) = line;
- if (!(line = strchr(line, ':'))) {
+ line = strchr(line, ':');
+ if (!line) {
break;
}
*line++ = 0;
}
/**********************************************************************/
-
+#if ENABLE_USE_BB_SHADOW
static const unsigned char sp_off[] = {
offsetof(struct spwd, sp_namp), /* 0 */
offsetof(struct spwd, sp_pwdp), /* 1 */
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;
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 {
return EINVAL;
}
+#endif
/**********************************************************************/
* 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;
int rv = ERANGE;
if (buflen < PWD_BUFFER_SIZE) {
- errno=rv;
+ errno = rv;
} else {
skip = 0;
do {
/* 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;
}
return rv;
}
-
-/**********************************************************************/