gzip: new GZIP_BIG_MEM option
[oweals/busybox.git] / libpwdgrp / pwd_grp.c
index 26e8ff469aa4aae700e9a087046a3ec3a6880f32..2eb9d9dd1d0890a4d9946aa5708d0c19ad6e1e71 100644 (file)
@@ -1,36 +1,25 @@
 /* vi: set sw=4 ts=4: */
-/*  Copyright (C) 2003     Manuel Novoa III
+/* Copyright (C) 2003     Manuel Novoa III
  *
- *  Licensed under GPL v2, or later.  See file LICENSE in this tarball.
+ * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  */
 
-/*  Nov 6, 2003  Initial version.
+/* Nov 6, 2003  Initial version.
  *
- *  NOTE: This implementation is quite strict about requiring all
+ * NOTE: This implementation is quite strict about requiring all
  *    field seperators.  It also does not allow leading whitespace
  *    except when processing the numeric fields.  glibc is more
  *    lenient.  See the various glibc difference comments below.
  *
- *  TODO:
+ * TODO:
  *    Move to dynamic allocation of (currently statically allocated)
  *      buffers; especially for the group-related functions since
  *      large group member lists will cause error returns.
- *
  */
 
 #include "libbb.h"
 #include <assert.h>
 
-#ifndef _PATH_SHADOW
-#define        _PATH_SHADOW    "/etc/shadow"
-#endif
-#ifndef _PATH_PASSWD
-#define        _PATH_PASSWD    "/etc/passwd"
-#endif
-#ifndef _PATH_GROUP
-#define        _PATH_GROUP     "/etc/group"
-#endif
-
 /**********************************************************************/
 /* Sizes for statically allocated buffers. */
 
@@ -164,6 +153,7 @@ int fgetgrent_r(FILE *__restrict stream, struct group *__restrict resultbuf,
 }
 
 #if ENABLE_USE_BB_SHADOW
+#ifdef UNUSED_FOR_NOW
 int fgetspent_r(FILE *__restrict stream, struct spwd *__restrict resultbuf,
                                char *__restrict buffer, size_t buflen,
                                struct spwd **__restrict result)
@@ -180,6 +170,7 @@ int fgetspent_r(FILE *__restrict stream, struct spwd *__restrict resultbuf,
        return rv;
 }
 #endif
+#endif
 
 /**********************************************************************/
 /* For the various fget??ent funcs, return NULL on failure and a
@@ -187,7 +178,7 @@ int fgetspent_r(FILE *__restrict stream, struct spwd *__restrict resultbuf,
  * TODO: audit & stop using these in bbox, they pull in static buffers */
 /**********************************************************************/
 
-#if 0
+#ifdef UNUSED_SINCE_WE_AVOID_STATIC_BUFS
 struct passwd *fgetpwent(FILE *stream)
 {
        struct statics *S;
@@ -212,7 +203,7 @@ struct group *fgetgrent(FILE *stream)
 #endif
 
 #if ENABLE_USE_BB_SHADOW
-#if 0
+#ifdef UNUSED_SINCE_WE_AVOID_STATIC_BUFS
 struct spwd *fgetspent(FILE *stream)
 {
        struct statics *S;
@@ -225,6 +216,7 @@ struct spwd *fgetspent(FILE *stream)
 }
 #endif
 
+#ifdef UNUSED_FOR_NOW
 int sgetspent_r(const char *string, struct spwd *result_buf,
                                char *buffer, size_t buflen, struct spwd **result)
 {
@@ -254,6 +246,7 @@ int sgetspent_r(const char *string, struct spwd *result_buf,
        return rv;
 }
 #endif
+#endif /* ENABLE_USE_BB_SHADOW */
 
 /**********************************************************************/
 
@@ -399,35 +392,6 @@ struct spwd *getspnam(const char *name)
 }
 #endif
 
-#ifdef THIS_ONE_IS_UNUSED
-/* This one doesn't use static buffers */
-int getpw(uid_t uid, char *buf)
-{
-       struct passwd resultbuf;
-       struct passwd *result;
-       char buffer[PWD_BUFFER_SIZE];
-
-       if (!buf) {
-               errno = EINVAL;
-               return -1;
-       }
-
-       if (!getpwuid_r(uid, &resultbuf, buffer, sizeof(buffer), &result)) {
-               if (sprintf(buf, "%s:%s:%lu:%lu:%s:%s:%s\n",
-                                       resultbuf.pw_name, resultbuf.pw_passwd,
-                                       (unsigned long)(resultbuf.pw_uid),
-                                       (unsigned long)(resultbuf.pw_gid),
-                                       resultbuf.pw_gecos, resultbuf.pw_dir,
-                                       resultbuf.pw_shell) >= 0
-               ) {
-                       return 0;
-               }
-       }
-
-       return -1;
-}
-#endif
-
 /**********************************************************************/
 
 /* FIXME: we don't have such CONFIG_xx - ?! */
@@ -536,6 +500,7 @@ int getgrent_r(struct group *__restrict resultbuf,
        return rv;
 }
 
+#ifdef UNUSED_FOR_NOW
 #if ENABLE_USE_BB_SHADOW
 static FILE *spf /*= NULL*/;
 void setspent(void)
@@ -583,8 +548,9 @@ int getspent_r(struct spwd *resultbuf, char *buffer,
        return rv;
 }
 #endif
+#endif /* UNUSED_FOR_NOW */
 
-#if 0
+#ifdef UNUSED_SINCE_WE_AVOID_STATIC_BUFS
 struct passwd *getpwent(void)
 {
        static char line_buff[PWD_BUFFER_SIZE];
@@ -604,9 +570,8 @@ struct group *getgrent(void)
        getgrent_r(&gr, line_buff, sizeof(line_buff), &result);
        return result;
 }
-#endif
 
-#if 0 //ENABLE_USE_BB_SHADOW
+#if ENABLE_USE_BB_SHADOW
 struct spwd *getspent(void)
 {
        static char line_buff[PWD_BUFFER_SIZE];
@@ -627,6 +592,7 @@ struct spwd *sgetspent(const char *string)
        return result;
 }
 #endif
+#endif /* UNUSED_SINCE_WE_AVOID_STATIC_BUFS */
 
 static gid_t *getgrouplist_internal(int *ngroups_ptr, const char *user, gid_t gid)
 {
@@ -687,14 +653,18 @@ int getgrouplist(const char *user, gid_t gid, gid_t *groups, int *ngroups)
        return ngroups_old;
 }
 
+#ifdef UNUSED_SINCE_WE_AVOID_STATIC_BUFS
 int putpwent(const struct passwd *__restrict p, FILE *__restrict f)
 {
        int rv = -1;
 
+#if 0
+       /* glibc does this check */
        if (!p || !f) {
                errno = EINVAL;
                return rv;
        }
+#endif
 
        /* No extra thread locking is needed above what fprintf does. */
        if (fprintf(f, "%s:%s:%lu:%lu:%s:%s:%s\n",
@@ -713,10 +683,13 @@ int putgrent(const struct group *__restrict p, FILE *__restrict f)
 {
        int rv = -1;
 
-       if (!p || !f) {                         /* Sigh... glibc checks. */
+#if 0
+       /* glibc does this check */
+       if (!p || !f) {
                errno = EINVAL;
                return rv;
        }
+#endif
 
        if (fprintf(f, "%s:%s:%lu:",
                                p->gr_name, p->gr_passwd,
@@ -749,8 +722,10 @@ int putgrent(const struct group *__restrict p, FILE *__restrict f)
 
        return rv;
 }
+#endif
 
 #if ENABLE_USE_BB_SHADOW
+#ifdef UNUSED_FOR_NOW
 static const unsigned char put_sp_off[] ALIGN1 = {
        offsetof(struct spwd, sp_lstchg),       /* 2 - not a char ptr */
        offsetof(struct spwd, sp_min),          /* 3 - not a char ptr */
@@ -797,9 +772,10 @@ int putspent(const struct spwd *p, FILE *stream)
        return rv;
 }
 #endif
+#endif /* USE_BB_SHADOW */
 
 /**********************************************************************/
-/* Internal uClibc functions.                                         */
+/* Internal functions                                                 */
 /**********************************************************************/
 
 static const unsigned char pw_off[] ALIGN1 = {
@@ -906,9 +882,9 @@ static int FAST_FUNC bb__parsegrent(void *data, char *line)
 
                        if (p[1]) { /* We have a member list to process. */
                                /* Overwrite the last ':' with a ',' before counting.
-                                * This allows us to test for initial ',' and adds
-                                * one ',' so that the ',' count equals the member
-                                * count. */
+                                * This allows us to (1) test for initial ','
+                                * and (2) adds one ',' so that the number of commas
+                                * equals the member count. */
                                *p = ',';
                                do {
                                        /* NOTE: glibc difference - glibc allows and trims leading
@@ -1013,10 +989,10 @@ static int FAST_FUNC bb__parsespent(void *data, char *line)
 
 /**********************************************************************/
 
-/* Reads until if EOF, or until if finds a line which fits in the buffer
+/* Reads until EOF, or until it finds a line which fits in the buffer
  * and for which the parser function succeeds.
  *
- * Returns 0 on success and ENOENT for end-of-file (glibc concession).
+ * Returns 0 on success and ENOENT for end-of-file (glibc convention).
  */
 static int bb__pgsreader(
                int FAST_FUNC (*parserfunc)(void *d, char *line),