]> git.cameronkatri.com Git - pw-darwin.git/commitdiff
ANSIfy, WARNSify, CONSTify. Bit of style(9)-ify.
authorMark Murray <markm@FreeBSD.org>
Sat, 18 Oct 2003 10:04:16 +0000 (10:04 +0000)
committerMark Murray <markm@FreeBSD.org>
Sat, 18 Oct 2003 10:04:16 +0000 (10:04 +0000)
libutil/_secure_path.c
libutil/libutil.h
libutil/login_cap.c
libutil/login_cap.h
libutil/pw_util.c

index 550a092d00c22827229fa71be3a1d780a32f1304..0411080c4530204c5e7da77cc3378b191c18d3ce 100644 (file)
@@ -59,12 +59,12 @@ _secure_path(const char *path, uid_t uid, gid_t gid)
        msg = "%s: %s is not a regular file";
     else if (sb.st_mode & S_IWOTH)
        msg = "%s: %s is world writable";
        msg = "%s: %s is not a regular file";
     else if (sb.st_mode & S_IWOTH)
        msg = "%s: %s is world writable";
-    else if (uid != -1 && sb.st_uid != uid && sb.st_uid != 0) {
+    else if ((int)uid != -1 && sb.st_uid != uid && sb.st_uid != 0) {
        if (uid == 0)
                msg = "%s: %s is not owned by root";
        else
                msg = "%s: %s is not owned by uid %d";
        if (uid == 0)
                msg = "%s: %s is not owned by root";
        else
                msg = "%s: %s is not owned by uid %d";
-    } else if (gid != -1 && sb.st_gid != gid && (sb.st_mode & S_IWGRP))
+    } else if ((int)gid != -1 && sb.st_gid != gid && (sb.st_mode & S_IWGRP))
        msg = "%s: %s is group writeable by non-authorised groups";
     else
        r = 0;
        msg = "%s: %s is group writeable by non-authorised groups";
     else
        r = 0;
index b3ebc6a9acfeffa61cd7133e740c33e34407f95d..f2c266380dbb49a6f851d76a075122dc1bfb8417 100644 (file)
@@ -39,8 +39,6 @@
 #ifndef _LIBUTIL_H_
 #define        _LIBUTIL_H_
 
 #ifndef _LIBUTIL_H_
 #define        _LIBUTIL_H_
 
-#include <sys/cdefs.h>
-
 #define PROPERTY_MAX_NAME      64
 #define PROPERTY_MAX_VALUE     512
 
 #define PROPERTY_MAX_NAME      64
 #define PROPERTY_MAX_VALUE     512
 
@@ -87,13 +85,13 @@ char   *fparseln(FILE *, size_t *, size_t *, const char[3], int);
 #endif
 
 #ifdef _PWD_H_
 #endif
 
 #ifdef _PWD_H_
-int    pw_copy(int _ffd, int _tfd, struct passwd *_pw, struct passwd *_old_pw);
-struct passwd *pw_dup(struct passwd *_pw);
+int    pw_copy(int _ffd, int _tfd, const struct passwd *_pw, struct passwd *_old_pw);
+struct passwd *pw_dup(const struct passwd *_pw);
 int    pw_edit(int _notsetuid);
 int    pw_edit(int _notsetuid);
-int    pw_equal(struct passwd *_pw1, struct passwd *_pw2);
+int    pw_equal(const struct passwd *_pw1, const struct passwd *_pw2);
 void   pw_fini(void);
 int    pw_init(const char *_dir, const char *_master);
 void   pw_fini(void);
 int    pw_init(const char *_dir, const char *_master);
-char   *pw_make(struct passwd *_pw);
+char   *pw_make(const struct passwd *_pw);
 int    pw_mkdb(const char *_user);
 int    pw_lock(void);
 struct passwd *pw_scan(const char *_line, int _flags);
 int    pw_mkdb(const char *_user);
 int    pw_lock(void);
 struct passwd *pw_scan(const char *_line, int _flags);
index b7193031dbd82e6e3c603ada5665af46fbd329be..8347b5100dcce4a44d5f27a4af86fa0b0c541227 100644 (file)
@@ -59,10 +59,10 @@ static int lc_object_count = 0;
 static size_t internal_stringsz = 0;
 static char * internal_string = NULL;
 static size_t internal_arraysz = 0;
 static size_t internal_stringsz = 0;
 static char * internal_string = NULL;
 static size_t internal_arraysz = 0;
-static char ** internal_array = NULL;
+static const char ** internal_array = NULL;
 
 static char *
 
 static char *
-allocstr(char *str)
+allocstr(const char *str)
 {
     char    *p;
 
 {
     char    *p;
 
@@ -77,10 +77,10 @@ allocstr(char *str)
 }
 
 
 }
 
 
-static char **
+static const char **
 allocarray(size_t sz)
 {
 allocarray(size_t sz)
 {
-    char    **p;
+    static const char    **p;
 
     if (sz <= internal_arraysz)
        p = internal_array;
 
     if (sz <= internal_arraysz)
        p = internal_array;
@@ -100,12 +100,12 @@ allocarray(size_t sz)
  * Free using freearraystr()
  */
 
  * Free using freearraystr()
  */
 
-static char **
-arrayize(char *str, const char *chars, int *size)
+static const char **
+arrayize(const char *str, const char *chars, int *size)
 {
     int            i;
 {
     int            i;
-    char    *ptr;
-    char    **res = NULL;
+    const char *ptr;
+    const char **res = NULL;
 
     /* count the sub-strings */
     for (i = 0, ptr = str; *ptr; i++) {
 
     /* count the sub-strings */
     for (i = 0, ptr = str; *ptr; i++) {
@@ -191,7 +191,7 @@ login_getclassbyname(char const *name, const struct passwd *pwd)
        const char  *dir;
        char        userpath[MAXPATHLEN];
 
        const char  *dir;
        char        userpath[MAXPATHLEN];
 
-       static char *login_dbarray[] = { NULL, NULL, NULL };
+       static const char *login_dbarray[] = { NULL, NULL, NULL };
 
        me = (name != NULL && strcmp(name, LOGIN_MECLASS) == 0);
        dir = (!me || pwd == NULL) ? NULL : pwd->pw_dir;
 
        me = (name != NULL && strcmp(name, LOGIN_MECLASS) == 0);
        dir = (!me || pwd == NULL) ? NULL : pwd->pw_dir;
@@ -224,7 +224,7 @@ login_getclassbyname(char const *name, const struct passwd *pwd)
        if (name == NULL || *name == '\0')
            name = LOGIN_DEFCLASS;
 
        if (name == NULL || *name == '\0')
            name = LOGIN_DEFCLASS;
 
-       switch (cgetent(&lc->lc_cap, login_dbarray, (char*)name)) {
+       switch (cgetent(&lc->lc_cap, login_dbarray, name)) {
        case -1:                /* Failed, entry does not exist */
            if (me)
                break;  /* Don't retry default on 'me' */
        case -1:                /* Failed, entry does not exist */
            if (me)
                break;  /* Don't retry default on 'me' */
@@ -242,7 +242,7 @@ login_getclassbyname(char const *name, const struct passwd *pwd)
            /* fall-back to default class */
            name = LOGIN_DEFCLASS;
            msg = "%s: no default/fallback class '%s'";
            /* fall-back to default class */
            name = LOGIN_DEFCLASS;
            msg = "%s: no default/fallback class '%s'";
-           if (cgetent(&lc->lc_cap, login_dbarray, (char*)name) != 0 && r >= 0)
+           if (cgetent(&lc->lc_cap, login_dbarray, name) != 0 && r >= 0)
                break;
            /* FALLTHROUGH - just return system defaults */
        case 0:         /* success! */
                break;
            /* FALLTHROUGH - just return system defaults */
        case 0:         /* success! */
@@ -352,7 +352,7 @@ login_getcapstr(login_cap_t *lc, const char *cap, const char *def, const char *e
     if (lc == NULL || cap == NULL || lc->lc_cap == NULL || *cap == '\0')
        return def;
 
     if (lc == NULL || cap == NULL || lc->lc_cap == NULL || *cap == '\0')
        return def;
 
-    if ((ret = cgetstr(lc->lc_cap, (char *)cap, &res)) == -1)
+    if ((ret = cgetstr(lc->lc_cap, cap, &res)) == -1)
        return def;
     return (ret >= 0) ? res : error;
 }
        return def;
     return (ret >= 0) ? res : error;
 }
@@ -365,14 +365,14 @@ login_getcapstr(login_cap_t *lc, const char *cap, const char *def, const char *e
  * strings.
  */
 
  * strings.
  */
 
-char **
+const char **
 login_getcaplist(login_cap_t *lc, const char *cap, const char *chars)
 {
 login_getcaplist(login_cap_t *lc, const char *cap, const char *chars)
 {
-    char    *lstring;
+    const char *lstring;
 
     if (chars == NULL)
        chars = ", \t";
 
     if (chars == NULL)
        chars = ", \t";
-    if ((lstring = (char *)login_getcapstr(lc, cap, NULL, NULL)) != NULL)
+    if ((lstring = login_getcapstr(lc, cap, NULL, NULL)) != NULL)
        return arrayize(lstring, chars, NULL);
     return NULL;
 }
        return arrayize(lstring, chars, NULL);
     return NULL;
 }
@@ -390,18 +390,18 @@ const char *
 login_getpath(login_cap_t *lc, const char *cap, const char *error)
 {
     const char *str;
 login_getpath(login_cap_t *lc, const char *cap, const char *error)
 {
     const char *str;
+    char *ptr;
+    int count;
 
 
-    if ((str = login_getcapstr(lc, cap, NULL, NULL)) == NULL)
-       str = error;
-    else {
-       char *ptr = (char *)str;
-
-       while (*ptr) {
-           int count = strcspn(ptr, ", \t");
-           ptr += count;
-           if (*ptr)
-               *ptr++ = ':';
-       }
+    str = login_getcapstr(lc, cap, NULL, NULL);
+    if (str == NULL)
+       return error;
+    ptr = __DECONST(char *, str); /* XXXX Yes, very dodgy */
+    while (*ptr) {
+       count = strcspn(ptr, ", \t");
+       ptr += count;
+       if (*ptr)
+           *ptr++ = ':';
     }
     return str;
 }
     }
     return str;
 }
@@ -535,7 +535,7 @@ login_getcaptime(login_cap_t *lc, const char *cap, rlim_t def, rlim_t error)
      * If there's an error, return <error>.
      */
 
      * If there's an error, return <error>.
      */
 
-    if ((r = cgetstr(lc->lc_cap, (char *)cap, &res)) == -1)
+    if ((r = cgetstr(lc->lc_cap, cap, &res)) == -1)
        return def;
     else if (r < 0) {
        errno = ERANGE;
        return def;
     else if (r < 0) {
        errno = ERANGE;
@@ -622,10 +622,10 @@ login_getcapnum(login_cap_t *lc, const char *cap, rlim_t def, rlim_t error)
     /*
      * For BSDI compatibility, try for the tag=<val> first
      */
     /*
      * For BSDI compatibility, try for the tag=<val> first
      */
-    if ((r = cgetstr(lc->lc_cap, (char *)cap, &res)) == -1) {
+    if ((r = cgetstr(lc->lc_cap, cap, &res)) == -1) {
        long    lval;
        /* string capability not present, so try for tag#<val> as numeric */
        long    lval;
        /* string capability not present, so try for tag#<val> as numeric */
-       if ((r = cgetnum(lc->lc_cap, (char *)cap, &lval)) == -1)
+       if ((r = cgetnum(lc->lc_cap, cap, &lval)) == -1)
            return def; /* Not there, so return default */
        else if (r >= 0)
            return (rlim_t)lval;
            return def; /* Not there, so return default */
        else if (r >= 0)
            return (rlim_t)lval;
@@ -671,7 +671,7 @@ login_getcapsize(login_cap_t *lc, const char *cap, rlim_t def, rlim_t error)
     if (lc == NULL || lc->lc_cap == NULL)
        return def;
 
     if (lc == NULL || lc->lc_cap == NULL)
        return def;
 
-    if ((r = cgetstr(lc->lc_cap, (char *)cap, &res)) == -1)
+    if ((r = cgetstr(lc->lc_cap, cap, &res)) == -1)
        return def;
     else if (r < 0) {
        errno = ERANGE;
        return def;
     else if (r < 0) {
        errno = ERANGE;
@@ -739,7 +739,7 @@ login_getcapbool(login_cap_t *lc, const char *cap, int def)
 {
     if (lc == NULL || lc->lc_cap == NULL)
        return def;
 {
     if (lc == NULL || lc->lc_cap == NULL)
        return def;
-    return (cgetcap(lc->lc_cap, (char *)cap, ':') != NULL);
+    return (cgetcap(lc->lc_cap, cap, ':') != NULL);
 }
 
 
 }
 
 
@@ -767,14 +767,14 @@ const char *
 login_getstyle(login_cap_t *lc, const char *style, const char *auth)
 {
     int            i;
 login_getstyle(login_cap_t *lc, const char *style, const char *auth)
 {
     int            i;
-    char    **authtypes = NULL;
+    const char **authtypes = NULL;
     char    *auths= NULL;
     char    realauth[64];
 
     char    *auths= NULL;
     char    realauth[64];
 
-    static char *defauthtypes[] = { LOGIN_DEFSTYLE, NULL };
+    static const char *defauthtypes[] = { LOGIN_DEFSTYLE, NULL };
 
     if (auth != NULL && *auth != '\0') {
 
     if (auth != NULL && *auth != '\0') {
-       if (snprintf(realauth, sizeof realauth, "auth-%s", auth) < sizeof realauth)
+       if (snprintf(realauth, sizeof realauth, "auth-%s", auth) < (int)sizeof(realauth))
            authtypes = login_getcaplist(lc, realauth, NULL);
     }
 
            authtypes = login_getcaplist(lc, realauth, NULL);
     }
 
index f6c6431ecd30a92734b16d1f7f2af12564c7581f..a7cb4c67e8f0a1847c4b3843ce1df520c508575e 100644 (file)
@@ -104,7 +104,7 @@ login_cap_t *login_getpwclass(const struct passwd *);
 login_cap_t *login_getuserclass(const struct passwd *);
 
 const char *login_getcapstr(login_cap_t*, const char *, const char *, const char *);
 login_cap_t *login_getuserclass(const struct passwd *);
 
 const char *login_getcapstr(login_cap_t*, const char *, const char *, const char *);
-char **login_getcaplist(login_cap_t *, const char *, const char *);
+const char **login_getcaplist(login_cap_t *, const char *, const char *);
 const char *login_getstyle(login_cap_t *, const char *, const char *);
 rlim_t login_getcaptime(login_cap_t *, const char *, rlim_t, rlim_t);
 rlim_t login_getcapnum(login_cap_t *, const char *, rlim_t, rlim_t);
 const char *login_getstyle(login_cap_t *, const char *, const char *);
 rlim_t login_getcaptime(login_cap_t *, const char *, rlim_t, rlim_t);
 rlim_t login_getcapnum(login_cap_t *, const char *, rlim_t, rlim_t);
@@ -147,8 +147,8 @@ int in_ltms(const login_time_t *, struct tm *, time_t *);
 
 /* helper functions */
 
 
 /* helper functions */
 
-int login_strinlist(char **, char const *, int);
-int login_str2inlist(char **, const char *, const char *, int);
+int login_strinlist(const char **, char const *, int);
+int login_str2inlist(const char **, const char *, const char *, int);
 login_time_t * login_timelist(login_cap_t *, char const *, int *, login_time_t **);
 int login_ttyok(login_cap_t *, const char *, const char *, const char *);
 int login_hostok(login_cap_t *, const char *, const char *, const char *, const char *);
 login_time_t * login_timelist(login_cap_t *, char const *, int *, login_time_t **);
 int login_ttyok(login_cap_t *, const char *, const char *, const char *);
 int login_hostok(login_cap_t *, const char *, const char *, const char *, const char *);
index 114bf7265b1c8cfd4518f76d1debdd0b4d651087..708583d05877c92edbe5239ce81e231bb4262dd8 100644 (file)
@@ -80,6 +80,7 @@ static char passwd_dir[PATH_MAX];
 static char tempname[PATH_MAX];
 static int initialized;
 
 static char tempname[PATH_MAX];
 static int initialized;
 
+#if 0
 void
 pw_cont(int sig)
 {
 void
 pw_cont(int sig)
 {
@@ -87,6 +88,7 @@ pw_cont(int sig)
        if (editpid != -1)
                kill(editpid, sig);
 }
        if (editpid != -1)
                kill(editpid, sig);
 }
+#endif
 
 /*
  * Initialize statics and set limits, signals & umask to try to avoid
 
 /*
  * Initialize statics and set limits, signals & umask to try to avoid
@@ -102,7 +104,7 @@ pw_init(const char *dir, const char *master)
        if (dir == NULL) {
                strcpy(passwd_dir, _PATH_ETC);
        } else {
        if (dir == NULL) {
                strcpy(passwd_dir, _PATH_ETC);
        } else {
-               if (strlen(dir) >= sizeof passwd_dir) {
+               if (strlen(dir) >= sizeof(passwd_dir)) {
                        errno = ENAMETOOLONG;
                        return (-1);
                }
                        errno = ENAMETOOLONG;
                        return (-1);
                }
@@ -112,13 +114,13 @@ pw_init(const char *dir, const char *master)
        if (master == NULL) {
                if (dir == NULL) {
                        strcpy(masterpasswd, _PATH_MASTERPASSWD);
        if (master == NULL) {
                if (dir == NULL) {
                        strcpy(masterpasswd, _PATH_MASTERPASSWD);
-               } else if (snprintf(masterpasswd, sizeof masterpasswd, "%s/%s",
-                   passwd_dir, _MASTERPASSWD) > sizeof masterpasswd) {
+               } else if (snprintf(masterpasswd, sizeof(masterpasswd), "%s/%s",
+                   passwd_dir, _MASTERPASSWD) > (int)sizeof(masterpasswd)) {
                        errno = ENAMETOOLONG;
                        return (-1);
                }
        } else {
                        errno = ENAMETOOLONG;
                        return (-1);
                }
        } else {
-               if (strlen(master) >= sizeof masterpasswd) {
+               if (strlen(master) >= sizeof(masterpasswd)) {
                        errno = ENAMETOOLONG;
                        return (-1);
                }
                        errno = ENAMETOOLONG;
                        return (-1);
                }
@@ -216,7 +218,7 @@ int
 pw_tmp(int mfd)
 {
        char buf[8192];
 pw_tmp(int mfd)
 {
        char buf[8192];
-       ssize_t nr, nw;
+       ssize_t nr;
        const char *p;
        int tfd;
 
        const char *p;
        int tfd;
 
@@ -226,16 +228,16 @@ pw_tmp(int mfd)
                ++p;
        else
                p = masterpasswd;
                ++p;
        else
                p = masterpasswd;
-       if (snprintf(tempname, sizeof tempname, "%.*spw.XXXXXX",
-               (int)(p - masterpasswd), masterpasswd) >= sizeof tempname) {
+       if (snprintf(tempname, sizeof(tempname), "%.*spw.XXXXXX",
+               (int)(p - masterpasswd), masterpasswd) >= (int)sizeof(tempname)) {
                errno = ENAMETOOLONG;
                return (-1);
        }
        if ((tfd = mkstemp(tempname)) == -1)
                return (-1);
        if (mfd != -1) {
                errno = ENAMETOOLONG;
                return (-1);
        }
        if ((tfd = mkstemp(tempname)) == -1)
                return (-1);
        if (mfd != -1) {
-               while ((nr = read(mfd, buf, sizeof buf)) > 0)
-                       if ((nw = write(tfd, buf, nr)) != nr)
+               while ((nr = read(mfd, buf, sizeof(buf))) > 0)
+                       if (write(tfd, buf, (size_t)nr) != nr)
                                break;
                if (nr != 0) {
                        unlink(tempname);
                                break;
                if (nr != 0) {
                        unlink(tempname);
@@ -269,6 +271,7 @@ pw_mkdb(const char *user)
                        execl(_PATH_PWD_MKDB, "pwd_mkdb", "-p",
                            "-d", passwd_dir, "-u", user, tempname, NULL);
                _exit(1);
                        execl(_PATH_PWD_MKDB, "pwd_mkdb", "-p",
                            "-d", passwd_dir, "-u", user, tempname, NULL);
                _exit(1);
+               /* NOTREACHED */
        default:
                /* parent */
                break;
        default:
                /* parent */
                break;
@@ -381,7 +384,7 @@ pw_fini(void)
  * Compares two struct pwds.
  */
 int
  * Compares two struct pwds.
  */
 int
-pw_equal(struct passwd *pw1, struct passwd *pw2)
+pw_equal(const struct passwd *pw1, const struct passwd *pw2)
 {
        return (strcmp(pw1->pw_name, pw2->pw_name) == 0 &&
            pw1->pw_uid == pw2->pw_uid &&
 {
        return (strcmp(pw1->pw_name, pw2->pw_name) == 0 &&
            pw1->pw_uid == pw2->pw_uid &&
@@ -398,7 +401,7 @@ pw_equal(struct passwd *pw1, struct passwd *pw2)
  * Make a passwd line out of a struct passwd.
  */
 char *
  * Make a passwd line out of a struct passwd.
  */
 char *
-pw_make(struct passwd *pw)
+pw_make(const struct passwd *pw)
 {
        char *line;
 
 {
        char *line;
 
@@ -414,12 +417,12 @@ pw_make(struct passwd *pw)
  * a single record on the way.
  */
 int
  * a single record on the way.
  */
 int
-pw_copy(int ffd, int tfd, struct passwd *pw, struct passwd *old_pw)
+pw_copy(int ffd, int tfd, const struct passwd *pw, struct passwd *old_pw)
 {
        char buf[8192], *end, *line, *p, *q, *r, t;
        struct passwd *fpw;
 {
        char buf[8192], *end, *line, *p, *q, *r, t;
        struct passwd *fpw;
-       ssize_t len;
-       int eof;
+       size_t len;
+       int eof, readlen;
 
        if ((line = pw_make(pw)) == NULL)
                return (-1);
 
        if ((line = pw_make(pw)) == NULL)
                return (-1);
@@ -437,7 +440,7 @@ pw_copy(int ffd, int tfd, struct passwd *pw, struct passwd *old_pw)
                if (q >= end) {
                        if (eof)
                                break;
                if (q >= end) {
                        if (eof)
                                break;
-                       if (q - p >= sizeof buf) {
+                       if ((size_t)(q - p) >= sizeof(buf)) {
                                warnx("passwd line too long");
                                errno = EINVAL; /* hack */
                                goto err;
                                warnx("passwd line too long");
                                errno = EINVAL; /* hack */
                                goto err;
@@ -448,14 +451,16 @@ pw_copy(int ffd, int tfd, struct passwd *pw, struct passwd *old_pw)
                        } else {
                                p = q = end = buf;
                        }
                        } else {
                                p = q = end = buf;
                        }
-                       len = read(ffd, end, sizeof buf - (end - buf));
-                       if (len == -1)
+                       readlen = read(ffd, end, sizeof(buf) - (end - buf));
+                       if (readlen == -1)
                                goto err;
                                goto err;
+                       else
+                               len = (size_t)readlen;
                        if (len == 0 && p == buf)
                                break;
                        end += len;
                        len = end - buf;
                        if (len == 0 && p == buf)
                                break;
                        end += len;
                        len = end - buf;
-                       if (len < sizeof buf) {
+                       if (len < (ssize_t)sizeof(buf)) {
                                eof = 1;
                                if (len > 0 && buf[len - 1] != '\n')
                                        ++len, *end++ = '\n';
                                eof = 1;
                                if (len > 0 && buf[len - 1] != '\n')
                                        ++len, *end++ = '\n';
@@ -497,7 +502,7 @@ pw_copy(int ffd, int tfd, struct passwd *pw, struct passwd *old_pw)
 
                /* it is, replace it */
                len = strlen(line);
 
                /* it is, replace it */
                len = strlen(line);
-               if (write(tfd, line, len) != len)
+               if (write(tfd, line, len) != (int)len)
                        goto err;
 
                /* we're done, just copy the rest over */
                        goto err;
 
                /* we're done, just copy the rest over */
@@ -505,10 +510,12 @@ pw_copy(int ffd, int tfd, struct passwd *pw, struct passwd *old_pw)
                        if (write(tfd, q, end - q) != end - q)
                                goto err;
                        q = buf;
                        if (write(tfd, q, end - q) != end - q)
                                goto err;
                        q = buf;
-                       len = read(ffd, buf, sizeof buf);
-                       if (len == 0)
+                       readlen = read(ffd, buf, sizeof(buf));
+                       if (readlen == 0)
                                break;
                                break;
-                       if (len == -1)
+                       else
+                               len = (size_t)readlen;
+                       if (readlen == -1)
                                goto err;
                        end = buf + len;
                }
                                goto err;
                        end = buf + len;
                }
@@ -517,7 +524,7 @@ pw_copy(int ffd, int tfd, struct passwd *pw, struct passwd *old_pw)
 
        /* if we got here, we have a new entry */
        len = strlen(line);
 
        /* if we got here, we have a new entry */
        len = strlen(line);
-       if (write(tfd, line, len) != len ||
+       if ((size_t)write(tfd, line, len) != len ||
            write(tfd, "\n", 1) != 1)
                goto err;
  done:
            write(tfd, "\n", 1) != 1)
                goto err;
  done:
@@ -542,22 +549,22 @@ pw_tempname(void)
  * Duplicate a struct passwd.
  */
 struct passwd *
  * Duplicate a struct passwd.
  */
 struct passwd *
-pw_dup(struct passwd *pw)
+pw_dup(const struct passwd *pw)
 {
        struct passwd *npw;
 {
        struct passwd *npw;
-       size_t len;
+       ssize_t len;
 
 
-       len = sizeof *npw +
+       len = sizeof(*npw) +
            (pw->pw_name ? strlen(pw->pw_name) + 1 : 0) +
            (pw->pw_passwd ? strlen(pw->pw_passwd) + 1 : 0) +
            (pw->pw_class ? strlen(pw->pw_class) + 1 : 0) +
            (pw->pw_gecos ? strlen(pw->pw_gecos) + 1 : 0) +
            (pw->pw_dir ? strlen(pw->pw_dir) + 1 : 0) +
            (pw->pw_shell ? strlen(pw->pw_shell) + 1 : 0);
            (pw->pw_name ? strlen(pw->pw_name) + 1 : 0) +
            (pw->pw_passwd ? strlen(pw->pw_passwd) + 1 : 0) +
            (pw->pw_class ? strlen(pw->pw_class) + 1 : 0) +
            (pw->pw_gecos ? strlen(pw->pw_gecos) + 1 : 0) +
            (pw->pw_dir ? strlen(pw->pw_dir) + 1 : 0) +
            (pw->pw_shell ? strlen(pw->pw_shell) + 1 : 0);
-       if ((npw = malloc(len)) == NULL)
+       if ((npw = malloc((size_t)len)) == NULL)
                return (NULL);
                return (NULL);
-       memcpy(npw, pw, sizeof *npw);
-       len = sizeof *npw;
+       memcpy(npw, pw, sizeof(*npw));
+       len = sizeof(*npw);
        if (pw->pw_name) {
                npw->pw_name = ((char *)npw) + len;
                len += sprintf(npw->pw_name, "%s", pw->pw_name) + 1;
        if (pw->pw_name) {
                npw->pw_name = ((char *)npw) + len;
                len += sprintf(npw->pw_name, "%s", pw->pw_name) + 1;