diff options
author | Eric Andersen <andersen@codepoet.org> | 2002-06-12 23:27:00 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2002-06-12 23:27:00 +0000 |
commit | c617db9065afa51100199d9ac4561feee4279291 (patch) | |
tree | e4a90725f73b9fb7ec9970ca495172181acfa873 | |
parent | fd6b9378be20243eaea7da1c2ddb3d68f123d28e (diff) |
Silence warnings, clean things up.
-Erik
-rw-r--r-- | libc/pwd_grp/__getgrent.c | 1 | ||||
-rw-r--r-- | libc/pwd_grp/__getpwent_r.c | 2 | ||||
-rw-r--r-- | libc/pwd_grp/__getspent_r.c | 2 | ||||
-rw-r--r-- | libc/pwd_grp/__sgetspent_r.c | 2 | ||||
-rw-r--r-- | libc/pwd_grp/config.h | 9 | ||||
-rw-r--r-- | libc/pwd_grp/fgetgrent.c | 1 | ||||
-rw-r--r-- | libc/pwd_grp/fgetpwent.c | 22 | ||||
-rw-r--r-- | libc/pwd_grp/fgetspent.c | 6 | ||||
-rw-r--r-- | libc/pwd_grp/getgrgid.c | 1 | ||||
-rw-r--r-- | libc/pwd_grp/getgrnam.c | 1 | ||||
-rw-r--r-- | libc/pwd_grp/getpw.c | 2 | ||||
-rw-r--r-- | libc/pwd_grp/getpwnam.c | 41 | ||||
-rw-r--r-- | libc/pwd_grp/getpwuid.c | 33 | ||||
-rw-r--r-- | libc/pwd_grp/getspnam.c | 44 | ||||
-rw-r--r-- | libc/pwd_grp/getspuid.c | 27 | ||||
-rw-r--r-- | libc/pwd_grp/grent.c | 1 | ||||
-rw-r--r-- | libc/pwd_grp/initgroups.c | 1 | ||||
-rw-r--r-- | libc/pwd_grp/lckpwdf.c | 223 | ||||
-rw-r--r-- | libc/pwd_grp/putpwent.c | 2 | ||||
-rw-r--r-- | libc/pwd_grp/putspent.c | 103 | ||||
-rw-r--r-- | libc/pwd_grp/pwent.c | 21 | ||||
-rw-r--r-- | libc/pwd_grp/sgetspent.c | 18 | ||||
-rw-r--r-- | libc/pwd_grp/spent.c | 36 |
23 files changed, 285 insertions, 314 deletions
diff --git a/libc/pwd_grp/__getgrent.c b/libc/pwd_grp/__getgrent.c index 2da45973f..911bdd66f 100644 --- a/libc/pwd_grp/__getgrent.c +++ b/libc/pwd_grp/__getgrent.c @@ -21,7 +21,6 @@ #include <unistd.h> #include <stdlib.h> #include <string.h> -#include <grp.h> #include "config.h" /* diff --git a/libc/pwd_grp/__getpwent_r.c b/libc/pwd_grp/__getpwent_r.c index aa2b990a4..db49ae255 100644 --- a/libc/pwd_grp/__getpwent_r.c +++ b/libc/pwd_grp/__getpwent_r.c @@ -24,7 +24,7 @@ #include <unistd.h> #include <string.h> #include <fcntl.h> -#include <pwd.h> +#include "config.h" /* This isn't as flash as my previous version -- it doesn't dynamically diff --git a/libc/pwd_grp/__getspent_r.c b/libc/pwd_grp/__getspent_r.c index 0500fa53c..2f87a1cc6 100644 --- a/libc/pwd_grp/__getspent_r.c +++ b/libc/pwd_grp/__getspent_r.c @@ -20,7 +20,7 @@ #include <unistd.h> #include <string.h> #include <fcntl.h> -#include <shadow.h> +#include "config.h" int __getspent_r(struct spwd * spwd, char * line_buff, size_t buflen, int spwd_fd) diff --git a/libc/pwd_grp/__sgetspent_r.c b/libc/pwd_grp/__sgetspent_r.c index f2cd73195..ec7c1c936 100644 --- a/libc/pwd_grp/__sgetspent_r.c +++ b/libc/pwd_grp/__sgetspent_r.c @@ -19,7 +19,7 @@ #include <stdlib.h> #include <unistd.h> #include <string.h> -#include <shadow.h> +#include "config.h" int __sgetspent_r(const char * string, struct spwd * spwd, char * line_buff, size_t buflen) diff --git a/libc/pwd_grp/config.h b/libc/pwd_grp/config.h index 5a5272999..2c3c6c3f0 100644 --- a/libc/pwd_grp/config.h +++ b/libc/pwd_grp/config.h @@ -24,12 +24,21 @@ #include <pwd.h> #include <grp.h> +#include <shadow.h> /* These are used internally to uClibc */ extern struct group * __getgrent __P ((int grp_fd)); extern int __getpwent_r(struct passwd * passwd, char * line_buff, size_t buflen, int pwd_fd); +extern int __getspent_r(struct spwd * spwd, char * line_buff, + size_t buflen, int spwd_fd); +extern int __sgetspent_r(const char * string, struct spwd * spwd, + char * line_buff, size_t buflen); + + +#define PWD_BUFFER_SIZE 256 + /* * Define GR_SCALE_DYNAMIC if you want grp to dynamically scale its read buffer diff --git a/libc/pwd_grp/fgetgrent.c b/libc/pwd_grp/fgetgrent.c index 7c08ea68e..327802b86 100644 --- a/libc/pwd_grp/fgetgrent.c +++ b/libc/pwd_grp/fgetgrent.c @@ -20,7 +20,6 @@ #include <stdio.h> #include <errno.h> -#include <grp.h> #include "config.h" struct group *fgetgrent(FILE * file) diff --git a/libc/pwd_grp/fgetpwent.c b/libc/pwd_grp/fgetpwent.c index ae43cdad8..e025cf6cc 100644 --- a/libc/pwd_grp/fgetpwent.c +++ b/libc/pwd_grp/fgetpwent.c @@ -20,28 +20,24 @@ #include <errno.h> #include <stdio.h> -#include <pwd.h> #include "config.h" -#define PWD_BUFFER_SIZE 256 - -/* file descriptor for the password file currently open */ -static char line_buff[PWD_BUFFER_SIZE]; -static struct passwd pwd; - int fgetpwent_r (FILE *file, struct passwd *password, char *buff, size_t buflen, struct passwd **crap) { - if (file == NULL) { - __set_errno(EINTR); - return -1; - } - return(__getpwent_r(password, buff, buflen, fileno(file))); + if (file == NULL) { + __set_errno(EINTR); + return -1; + } + return(__getpwent_r(password, buff, buflen, fileno(file))); } struct passwd *fgetpwent(FILE * file) { - if (fgetpwent_r(file, &pwd, line_buff, PWD_BUFFER_SIZE, NULL) != -1) { + static char line_buff[PWD_BUFFER_SIZE]; + static struct passwd pwd; + + if (fgetpwent_r(file, &pwd, line_buff, sizeof(line_buff), NULL) != -1) { return &pwd; } return NULL; diff --git a/libc/pwd_grp/fgetspent.c b/libc/pwd_grp/fgetspent.c index cf949065f..68053b39e 100644 --- a/libc/pwd_grp/fgetspent.c +++ b/libc/pwd_grp/fgetspent.c @@ -19,9 +19,7 @@ #include <errno.h> #include <stdio.h> -#include <shadow.h> - -#define PWD_BUFFER_SIZE 256 +#include "config.h" int fgetspent_r (FILE *file, struct spwd *spwd, char *buff, size_t buflen, struct spwd **crap) @@ -38,7 +36,7 @@ struct spwd *fgetspent(FILE * file) static char line_buff[PWD_BUFFER_SIZE]; static struct spwd spwd; - if (fgetspent_r(file, &spwd, line_buff, PWD_BUFFER_SIZE, NULL) != -1) { + if (fgetspent_r(file, &spwd, line_buff, sizeof(line_buff), NULL) != -1) { return &spwd; } return NULL; diff --git a/libc/pwd_grp/getgrgid.c b/libc/pwd_grp/getgrgid.c index f41e305ef..1eaed64c0 100644 --- a/libc/pwd_grp/getgrgid.c +++ b/libc/pwd_grp/getgrgid.c @@ -21,7 +21,6 @@ #include <sys/types.h> #include <unistd.h> #include <fcntl.h> -#include <grp.h> #include <paths.h> #include "config.h" diff --git a/libc/pwd_grp/getgrnam.c b/libc/pwd_grp/getgrnam.c index 77301797c..f33462498 100644 --- a/libc/pwd_grp/getgrnam.c +++ b/libc/pwd_grp/getgrnam.c @@ -22,7 +22,6 @@ #include <string.h> #include <errno.h> #include <fcntl.h> -#include <grp.h> #include <paths.h> #include "config.h" diff --git a/libc/pwd_grp/getpw.c b/libc/pwd_grp/getpw.c index 83f6fe973..4731bb961 100644 --- a/libc/pwd_grp/getpw.c +++ b/libc/pwd_grp/getpw.c @@ -21,7 +21,7 @@ #include <sys/types.h> #include <errno.h> #include <stdio.h> -#include <pwd.h> +#include "config.h" int getpw(uid_t uid, char *buf) { diff --git a/libc/pwd_grp/getpwnam.c b/libc/pwd_grp/getpwnam.c index 36f6f0942..b0674b15d 100644 --- a/libc/pwd_grp/getpwnam.c +++ b/libc/pwd_grp/getpwnam.c @@ -22,43 +22,38 @@ #include <string.h> #include <errno.h> #include <fcntl.h> -#include <pwd.h> #include <paths.h> #include "config.h" -#define PWD_BUFFER_SIZE 256 - -/* file descriptor for the password file currently open */ -static char line_buff[PWD_BUFFER_SIZE]; -static struct passwd pwd; - - int getpwnam_r (const char *name, struct passwd *password, char *buff, size_t buflen, struct passwd **crap) { - int passwd_fd; + int passwd_fd; - if (name == NULL) { - __set_errno(EINVAL); - return -1; - } + if (name == NULL) { + __set_errno(EINVAL); + return -1; + } - if ((passwd_fd = open(_PATH_PASSWD, O_RDONLY)) < 0) - return -1; + if ((passwd_fd = open(_PATH_PASSWD, O_RDONLY)) < 0) + return -1; - while (__getpwent_r(password, buff, buflen, passwd_fd) != -1) - if (!strcmp(password->pw_name, name)) { - close(passwd_fd); - return 0; - } + while (__getpwent_r(password, buff, buflen, passwd_fd) != -1) + if (!strcmp(password->pw_name, name)) { + close(passwd_fd); + return 0; + } - close(passwd_fd); - return -1; + close(passwd_fd); + return -1; } struct passwd *getpwnam(const char *name) { - if (getpwnam_r(name, &pwd, line_buff, PWD_BUFFER_SIZE, NULL) != -1) { + static char line_buff[PWD_BUFFER_SIZE]; + static struct passwd pwd; + + if (getpwnam_r(name, &pwd, line_buff, sizeof(line_buff), NULL) != -1) { return &pwd; } return NULL; diff --git a/libc/pwd_grp/getpwuid.c b/libc/pwd_grp/getpwuid.c index 4d6d60ee8..ff3637abe 100644 --- a/libc/pwd_grp/getpwuid.c +++ b/libc/pwd_grp/getpwuid.c @@ -21,37 +21,34 @@ #include <stdlib.h> #include <unistd.h> #include <fcntl.h> -#include <pwd.h> #include <paths.h> #include "config.h" -#define PWD_BUFFER_SIZE 256 - -/* file descriptor for the password file currently open */ -static char line_buff[PWD_BUFFER_SIZE]; -static struct passwd pwd; - int getpwuid_r (uid_t uid, struct passwd *password, char *buff, size_t buflen, struct passwd **crap) { - int passwd_fd; + int passwd_fd; - if ((passwd_fd = open(_PATH_PASSWD, O_RDONLY)) < 0) - return -1; + if ((passwd_fd = open(_PATH_PASSWD, O_RDONLY)) < 0) + return -1; - while (__getpwent_r(password, buff, buflen, passwd_fd) != -1) - if (password->pw_uid == uid) { - close(passwd_fd); - return 0; - } + while (__getpwent_r(password, buff, buflen, passwd_fd) != -1) + if (password->pw_uid == uid) { + close(passwd_fd); + return 0; + } - close(passwd_fd); - return -1; + close(passwd_fd); + return -1; } struct passwd *getpwuid(uid_t uid) { - if (getpwuid_r(uid, &pwd, line_buff, PWD_BUFFER_SIZE, NULL) != -1) { + /* file descriptor for the password file currently open */ + static char line_buff[PWD_BUFFER_SIZE]; + static struct passwd pwd; + + if (getpwuid_r(uid, &pwd, line_buff, sizeof(line_buff), NULL) != -1) { return &pwd; } return NULL; diff --git a/libc/pwd_grp/getspnam.c b/libc/pwd_grp/getspnam.c index 3865a0dc5..d8a29a8a2 100644 --- a/libc/pwd_grp/getspnam.c +++ b/libc/pwd_grp/getspnam.c @@ -21,41 +21,39 @@ #include <string.h> #include <errno.h> #include <fcntl.h> -#include <shadow.h> - -#define PWD_BUFFER_SIZE 256 +#include "config.h" int getspnam_r (const char *name, struct spwd *spwd, char *buff, size_t buflen, struct spwd **crap) { - int spwd_fd; + int spwd_fd; - if (name == NULL) { - __set_errno(EINVAL); - return -1; - } + if (name == NULL) { + __set_errno(EINVAL); + return -1; + } - if ((spwd_fd = open(_PATH_SHADOW, O_RDONLY)) < 0) - return -1; + if ((spwd_fd = open(_PATH_SHADOW, O_RDONLY)) < 0) + return -1; - while (__getspent_r(spwd, buff, buflen, spwd_fd) != -1) - if (!strcmp(spwd->sp_namp, name)) { - close(spwd_fd); - return 0; - } + while (__getspent_r(spwd, buff, buflen, spwd_fd) != -1) + if (!strcmp(spwd->sp_namp, name)) { + close(spwd_fd); + return 0; + } - close(spwd_fd); - return -1; + close(spwd_fd); + return -1; } struct spwd *getspnam(const char *name) { - static char line_buff[PWD_BUFFER_SIZE]; - static struct spwd spwd; + static char line_buff[PWD_BUFFER_SIZE]; + static struct spwd spwd; - if (getspnam_r(name, &spwd, line_buff, PWD_BUFFER_SIZE, NULL) != -1) { - return &spwd; - } - return NULL; + if (getspnam_r(name, &spwd, line_buff, sizeof(line_buff), NULL) != -1) { + return &spwd; + } + return NULL; } diff --git a/libc/pwd_grp/getspuid.c b/libc/pwd_grp/getspuid.c index 2f01cdca0..f06eb1ad0 100644 --- a/libc/pwd_grp/getspuid.c +++ b/libc/pwd_grp/getspuid.c @@ -20,31 +20,28 @@ #include <stdlib.h> #include <unistd.h> #include <fcntl.h> -#include <pwd.h> -#include <shadow.h> - -#define PWD_BUFFER_SIZE 256 +#include "config.h" int getspuid_r (uid_t uid, struct spwd *spwd, char *buff, size_t buflen, struct spwd **crap) { - char pwd_buff[PWD_BUFFER_SIZE]; - struct passwd password; + char pwd_buff[PWD_BUFFER_SIZE]; + struct passwd password; - if (getpwuid_r(uid, &password, pwd_buff, PWD_BUFFER_SIZE, NULL) < 0) - return -1; + if (getpwuid_r(uid, &password, pwd_buff, sizeof(pwd_buff), NULL) < 0) + return -1; - return getspnam_r(password.pw_name, spwd, buff, buflen, crap); + return getspnam_r(password.pw_name, spwd, buff, buflen, crap); } struct spwd *getspuid(uid_t uid) { - static char line_buff[PWD_BUFFER_SIZE]; - static struct spwd spwd; + static char line_buff[PWD_BUFFER_SIZE]; + static struct spwd spwd; - if (getspuid_r(uid, &spwd, line_buff, PWD_BUFFER_SIZE, NULL) != -1) { - return &spwd; - } - return NULL; + if (getspuid_r(uid, &spwd, line_buff, sizeof(line_buff), NULL) != -1) { + return &spwd; + } + return NULL; } diff --git a/libc/pwd_grp/grent.c b/libc/pwd_grp/grent.c index 973213f83..42db9f9b6 100644 --- a/libc/pwd_grp/grent.c +++ b/libc/pwd_grp/grent.c @@ -26,7 +26,6 @@ #include <unistd.h> #include <fcntl.h> -#include <grp.h> #include <paths.h> #include "config.h" diff --git a/libc/pwd_grp/initgroups.c b/libc/pwd_grp/initgroups.c index 87a6b569d..f3c0604f5 100644 --- a/libc/pwd_grp/initgroups.c +++ b/libc/pwd_grp/initgroups.c @@ -21,7 +21,6 @@ #include <unistd.h> #include <string.h> #include <fcntl.h> -#include <grp.h> #include <paths.h> #include "config.h" diff --git a/libc/pwd_grp/lckpwdf.c b/libc/pwd_grp/lckpwdf.c index 2f55ff65a..148d2c93a 100644 --- a/libc/pwd_grp/lckpwdf.c +++ b/libc/pwd_grp/lckpwdf.c @@ -19,7 +19,6 @@ Boston, MA 02111-1307, USA. */ #include <fcntl.h> -#include <shadow.h> #include <signal.h> #include <string.h> #include <unistd.h> @@ -37,127 +36,123 @@ static int lock_fd = -1; static void noop_handler __P ((int __sig)); -int -lckpwdf () +int lckpwdf (void) { - int flags; - sigset_t saved_set; /* Saved set of caught signals. */ - struct sigaction saved_act; /* Saved signal action. */ - sigset_t new_set; /* New set of caught signals. */ - struct sigaction new_act; /* New signal action. */ - struct flock fl; /* Information struct for locking. */ - int result; - - if (lock_fd != -1) - /* Still locked by own process. */ - return -1; - - lock_fd = open (_PATH_PASSWD, O_WRONLY); - if (lock_fd == -1) - /* Cannot create lock file. */ - return -1; - - /* Make sure file gets correctly closed when process finished. */ - flags = fcntl (lock_fd, F_GETFD, 0); - if (flags == -1) { - /* Cannot get file flags. */ - close(lock_fd); - lock_fd = -1; - return -1; - } - flags |= FD_CLOEXEC; /* Close on exit. */ - if (fcntl (lock_fd, F_SETFD, flags) < 0) { - /* Cannot set new flags. */ - close(lock_fd); - lock_fd = -1; - return -1; - } - - /* Now we have to get exclusive write access. Since multiple - process could try this we won't stop when it first fails. - Instead we set a timeout for the system call. Once the timer - expires it is likely that there are some problems which cannot be - resolved by waiting. - - It is important that we don't change the signal state. We must - restore the old signal behaviour. */ - memset (&new_act, '\0', sizeof (struct sigaction)); - new_act.sa_handler = noop_handler; - sigfillset (&new_act.sa_mask); - new_act.sa_flags = 0ul; - - /* Install new action handler for alarm and save old. */ - if (sigaction (SIGALRM, &new_act, &saved_act) < 0) { - /* Cannot install signal handler. */ - close(lock_fd); - lock_fd = -1; - return -1; - } - - /* Now make sure the alarm signal is not blocked. */ - sigemptyset (&new_set); - sigaddset (&new_set, SIGALRM); - if (sigprocmask (SIG_UNBLOCK, &new_set, &saved_set) < 0) { - sigaction (SIGALRM, &saved_act, NULL); - close(lock_fd); - lock_fd = -1; - return -1; - } - - /* Start timer. If we cannot get the lock in the specified time we - get a signal. */ - alarm (TIMEOUT); - - /* Try to get the lock. */ - memset (&fl, '\0', sizeof (struct flock)); - fl.l_type = F_WRLCK; - fl.l_whence = SEEK_SET; - result = fcntl (lock_fd, F_SETLKW, &fl); - - /* Clear alarm. */ - alarm (0); - - /* Restore old set of handled signals. We don't need to know - about the current one.*/ - sigprocmask (SIG_SETMASK, &saved_set, NULL); - - /* Restore old action handler for alarm. We don't need to know - about the current one. */ + int flags; + sigset_t saved_set; /* Saved set of caught signals. */ + struct sigaction saved_act; /* Saved signal action. */ + sigset_t new_set; /* New set of caught signals. */ + struct sigaction new_act; /* New signal action. */ + struct flock fl; /* Information struct for locking. */ + int result; + + if (lock_fd != -1) + /* Still locked by own process. */ + return -1; + + lock_fd = open (_PATH_PASSWD, O_WRONLY); + if (lock_fd == -1) + /* Cannot create lock file. */ + return -1; + + /* Make sure file gets correctly closed when process finished. */ + flags = fcntl (lock_fd, F_GETFD, 0); + if (flags == -1) { + /* Cannot get file flags. */ + close(lock_fd); + lock_fd = -1; + return -1; + } + flags |= FD_CLOEXEC; /* Close on exit. */ + if (fcntl (lock_fd, F_SETFD, flags) < 0) { + /* Cannot set new flags. */ + close(lock_fd); + lock_fd = -1; + return -1; + } + + /* Now we have to get exclusive write access. Since multiple + process could try this we won't stop when it first fails. + Instead we set a timeout for the system call. Once the timer + expires it is likely that there are some problems which cannot be + resolved by waiting. + + It is important that we don't change the signal state. We must + restore the old signal behaviour. */ + memset (&new_act, '\0', sizeof (struct sigaction)); + new_act.sa_handler = noop_handler; + sigfillset (&new_act.sa_mask); + new_act.sa_flags = 0ul; + + /* Install new action handler for alarm and save old. */ + if (sigaction (SIGALRM, &new_act, &saved_act) < 0) { + /* Cannot install signal handler. */ + close(lock_fd); + lock_fd = -1; + return -1; + } + + /* Now make sure the alarm signal is not blocked. */ + sigemptyset (&new_set); + sigaddset (&new_set, SIGALRM); + if (sigprocmask (SIG_UNBLOCK, &new_set, &saved_set) < 0) { sigaction (SIGALRM, &saved_act, NULL); - - if (result < 0) { - close(lock_fd); - lock_fd = -1; - return -1; - } - - return 0; + close(lock_fd); + lock_fd = -1; + return -1; + } + + /* Start timer. If we cannot get the lock in the specified time we + get a signal. */ + alarm (TIMEOUT); + + /* Try to get the lock. */ + memset (&fl, '\0', sizeof (struct flock)); + fl.l_type = F_WRLCK; + fl.l_whence = SEEK_SET; + result = fcntl (lock_fd, F_SETLKW, &fl); + + /* Clear alarm. */ + alarm (0); + + /* Restore old set of handled signals. We don't need to know + about the current one.*/ + sigprocmask (SIG_SETMASK, &saved_set, NULL); + + /* Restore old action handler for alarm. We don't need to know + about the current one. */ + sigaction (SIGALRM, &saved_act, NULL); + + if (result < 0) { + close(lock_fd); + lock_fd = -1; + return -1; + } + + return 0; } -int -ulckpwdf () +int ulckpwdf (void) { - int result; - - if (lock_fd == -1) { - /* There is no lock set. */ - result = -1; - } - else { - result = close (lock_fd); - - /* Mark descriptor as unused. */ - lock_fd = -1; - } - - return result; + int result; + + if (lock_fd == -1) { + /* There is no lock set. */ + result = -1; + } + else { + result = close (lock_fd); + + /* Mark descriptor as unused. */ + lock_fd = -1; + } + + return result; } -static void -noop_handler (sig) - int sig; +static void noop_handler (int sig) { - /* We simply return which makes the `fcntl' call return with an error. */ + /* We simply return which makes the `fcntl' call return with an error. */ } diff --git a/libc/pwd_grp/putpwent.c b/libc/pwd_grp/putpwent.c index 014cefa86..84028523b 100644 --- a/libc/pwd_grp/putpwent.c +++ b/libc/pwd_grp/putpwent.c @@ -20,7 +20,7 @@ #include <stdio.h> #include <errno.h> -#include <pwd.h> +#include "config.h" int putpwent(const struct passwd *passwd, FILE * f) { diff --git a/libc/pwd_grp/putspent.c b/libc/pwd_grp/putspent.c index a4626e1b4..89a69887c 100644 --- a/libc/pwd_grp/putspent.c +++ b/libc/pwd_grp/putspent.c @@ -17,63 +17,62 @@ Boston, MA 02111-1307, USA. */ #include <stdio.h> -#include <shadow.h> +#include "config.h" #define _S(x) x ? x : "" /* Write an entry to the given stream. This must know the format of the password file. */ -int -putspent (const struct spwd *p, FILE *stream) +int putspent (const struct spwd *p, FILE *stream) { - int errors = 0; - - if (fprintf (stream, "%s:%s:", p->sp_namp, _S (p->sp_pwdp)) < 0) - ++errors; - - if ((p->sp_lstchg != (long int) -1 - && fprintf (stream, "%ld:", p->sp_lstchg) < 0) - || (p->sp_lstchg == (long int) -1 - && putc (':', stream) == EOF)) - ++errors; - - if ((p->sp_min != (long int) -1 - && fprintf (stream, "%ld:", p->sp_min) < 0) - || (p->sp_min == (long int) -1 - && putc (':', stream) == EOF)) - ++errors; - - if ((p->sp_max != (long int) -1 - && fprintf (stream, "%ld:", p->sp_max) < 0) - || (p->sp_max == (long int) -1 - && putc (':', stream) == EOF)) - ++errors; - - if ((p->sp_warn != (long int) -1 - && fprintf (stream, "%ld:", p->sp_warn) < 0) - || (p->sp_warn == (long int) -1 - && putc (':', stream) == EOF)) - ++errors; - - if ((p->sp_inact != (long int) -1 - && fprintf (stream, "%ld:", p->sp_inact) < 0) - || (p->sp_inact == (long int) -1 - && putc (':', stream) == EOF)) - ++errors; - - if ((p->sp_expire != (long int) -1 - && fprintf (stream, "%ld:", p->sp_expire) < 0) - || (p->sp_expire == (long int) -1 - && putc (':', stream) == EOF)) - ++errors; - - if (p->sp_flag != ~0ul - && fprintf (stream, "%ld", p->sp_flag) < 0) - ++errors; - - if (putc ('\n', stream) == EOF) - ++errors; - - return errors ? -1 : 0; + int errors = 0; + + if (fprintf (stream, "%s:%s:", p->sp_namp, _S (p->sp_pwdp)) < 0) + ++errors; + + if ((p->sp_lstchg != (long int) -1 + && fprintf (stream, "%ld:", p->sp_lstchg) < 0) + || (p->sp_lstchg == (long int) -1 + && putc (':', stream) == EOF)) + ++errors; + + if ((p->sp_min != (long int) -1 + && fprintf (stream, "%ld:", p->sp_min) < 0) + || (p->sp_min == (long int) -1 + && putc (':', stream) == EOF)) + ++errors; + + if ((p->sp_max != (long int) -1 + && fprintf (stream, "%ld:", p->sp_max) < 0) + || (p->sp_max == (long int) -1 + && putc (':', stream) == EOF)) + ++errors; + + if ((p->sp_warn != (long int) -1 + && fprintf (stream, "%ld:", p->sp_warn) < 0) + || (p->sp_warn == (long int) -1 + && putc (':', stream) == EOF)) + ++errors; + + if ((p->sp_inact != (long int) -1 + && fprintf (stream, "%ld:", p->sp_inact) < 0) + || (p->sp_inact == (long int) -1 + && putc (':', stream) == EOF)) + ++errors; + + if ((p->sp_expire != (long int) -1 + && fprintf (stream, "%ld:", p->sp_expire) < 0) + || (p->sp_expire == (long int) -1 + && putc (':', stream) == EOF)) + ++errors; + + if (p->sp_flag != ~0ul + && fprintf (stream, "%ld", p->sp_flag) < 0) + ++errors; + + if (putc ('\n', stream) == EOF) + ++errors; + + return errors ? -1 : 0; } diff --git a/libc/pwd_grp/pwent.c b/libc/pwd_grp/pwent.c index 804bd8957..55fd249bc 100644 --- a/libc/pwd_grp/pwent.c +++ b/libc/pwd_grp/pwent.c @@ -21,7 +21,6 @@ #include <unistd.h> #include <stdlib.h> #include <errno.h> -#include <pwd.h> #include <fcntl.h> #include <paths.h> #include "config.h" @@ -32,26 +31,22 @@ * link them all in together. */ -#define PWD_BUFFER_SIZE 256 - /* file descriptor for the password file currently open */ static int pw_fd = -1; -static char line_buff[PWD_BUFFER_SIZE]; -static struct passwd pwd; void setpwent(void) { - if (pw_fd != -1) - close(pw_fd); + if (pw_fd != -1) + close(pw_fd); - pw_fd = open(_PATH_PASSWD, O_RDONLY); + pw_fd = open(_PATH_PASSWD, O_RDONLY); } void endpwent(void) { - if (pw_fd != -1) - close(pw_fd); - pw_fd = -1; + if (pw_fd != -1) + close(pw_fd); + pw_fd = -1; } int getpwent_r (struct passwd *password, char *buff, @@ -65,7 +60,9 @@ int getpwent_r (struct passwd *password, char *buff, struct passwd *getpwent(void) { - if (getpwent_r(&pwd, line_buff, PWD_BUFFER_SIZE, NULL) != -1) { + static char line_buff[PWD_BUFFER_SIZE]; + static struct passwd pwd; + if (getpwent_r(&pwd, line_buff, sizeof(line_buff), NULL) != -1) { return &pwd; } return NULL; diff --git a/libc/pwd_grp/sgetspent.c b/libc/pwd_grp/sgetspent.c index 6f80c87d6..83b1144ee 100644 --- a/libc/pwd_grp/sgetspent.c +++ b/libc/pwd_grp/sgetspent.c @@ -19,23 +19,21 @@ #include <errno.h> #include <stdio.h> -#include <shadow.h> - -#define PWD_BUFFER_SIZE 256 +#include "config.h" int sgetspent_r (const char *string, struct spwd *spwd, char *buff, size_t buflen, struct spwd **crap) { - return(__sgetspent_r(string, spwd, buff, buflen)); + return(__sgetspent_r(string, spwd, buff, buflen)); } struct spwd *sgetspent(const char *string) { - static char line_buff[PWD_BUFFER_SIZE]; - static struct spwd spwd; + static char line_buff[PWD_BUFFER_SIZE]; + static struct spwd spwd; - if (sgetspent_r(string, &spwd, line_buff, PWD_BUFFER_SIZE, NULL) != -1) { - return &spwd; - } - return NULL; + if (sgetspent_r(string, &spwd, line_buff, sizeof(line_buff), NULL) != -1) { + return &spwd; + } + return NULL; } diff --git a/libc/pwd_grp/spent.c b/libc/pwd_grp/spent.c index 196a952bd..c1305b15e 100644 --- a/libc/pwd_grp/spent.c +++ b/libc/pwd_grp/spent.c @@ -20,8 +20,8 @@ #include <unistd.h> #include <stdlib.h> #include <errno.h> -#include <shadow.h> #include <fcntl.h> +#include "config.h" /* * setspent(), endspent(), and getspent() are included in the same object @@ -29,43 +29,41 @@ * link them all in together. */ -#define PWD_BUFFER_SIZE 256 - /* file descriptor for the password file currently open */ static int spwd_fd = -1; void setspent(void) { - if (spwd_fd != -1) - close(spwd_fd); + if (spwd_fd != -1) + close(spwd_fd); - spwd_fd = open(_PATH_SHADOW, O_RDONLY); + spwd_fd = open(_PATH_SHADOW, O_RDONLY); } void endspent(void) { - if (spwd_fd != -1) - close(spwd_fd); - spwd_fd = -1; + if (spwd_fd != -1) + close(spwd_fd); + spwd_fd = -1; } int getspent_r (struct spwd *spwd, char *buff, size_t buflen, struct spwd **crap) { - if (spwd_fd != -1 && __getspent_r(spwd, buff, buflen, spwd_fd) != -1) { - return 0; - } - return -1; + if (spwd_fd != -1 && __getspent_r(spwd, buff, buflen, spwd_fd) != -1) { + return 0; + } + return -1; } struct spwd *getspent(void) { - static char line_buff[PWD_BUFFER_SIZE]; - static struct spwd spwd; + static char line_buff[PWD_BUFFER_SIZE]; + static struct spwd spwd; - if (getspent_r(&spwd, line_buff, PWD_BUFFER_SIZE, NULL) != -1) { - return &spwd; - } - return NULL; + if (getspent_r(&spwd, line_buff, sizeof(line_buff), NULL) != -1) { + return &spwd; + } + return NULL; } |