]> git.cameronkatri.com Git - pw-darwin.git/blobdiff - pw/pw_user.c
Fix bugs spotted by gcc
[pw-darwin.git] / pw / pw_user.c
index 8ff4159108d886b7a7ae54c6ffe16167179c1528..b51a6cbbabf96e1e366d7037bdd498e690f1c8b1 100644 (file)
@@ -30,23 +30,28 @@ static const char rcsid[] =
   "$FreeBSD$";
 #endif /* not lint */
 
+#include <sys/param.h>
+#include <sys/resource.h>
+#include <sys/time.h>
+#include <sys/types.h>
+
 #include <ctype.h>
+#include <dirent.h>
 #include <err.h>
 #include <fcntl.h>
-#include <inttypes.h>
-#include <sys/param.h>
-#include <dirent.h>
-#include <paths.h>
-#include <termios.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/resource.h>
-#include <login_cap.h>
-#include <pwd.h>
 #include <grp.h>
+#include <pwd.h>
 #include <libutil.h>
+#include <login_cap.h>
+#include <paths.h>
+#include <string.h>
+#include <sysexits.h>
+#include <termios.h>
+#include <unistd.h>
+
 #include "pw.h"
 #include "bitmap.h"
+#include "psdate.h"
 
 #define LOGNAMESIZE (MAXLOGNAME-1)
 
@@ -618,7 +623,8 @@ rmat(uid_t uid)
                            st.st_uid == uid) {
                                char            tmp[MAXPATHLEN];
 
-                               snprintf(tmp, sizeof(tmp), "/usr/bin/atrm %s", e->d_name);
+                               snprintf(tmp, sizeof(tmp), "/usr/bin/atrm %s",
+                                   e->d_name);
                                system(tmp);
                        }
                }
@@ -671,7 +677,7 @@ pw_user_next(int argc, char **argv, char *name __unused)
                        cfg = optarg;
                        break;
                case 'q':
-                       quiet;
+                       quiet = true;
                        break;
                }
        }
@@ -694,7 +700,7 @@ pw_user_show(int argc, char **argv, char *arg1)
 {
        struct passwd *pwd = NULL;
        char *name = NULL;
-       uid_t id = -1;
+       intmax_t id = -1;
        int ch;
        bool all = false;
        bool pretty = false;
@@ -780,7 +786,7 @@ pw_user_del(int argc, char **argv, char *arg1)
        char home[MAXPATHLEN];
        const char *cfg = NULL;
        struct stat st;
-       uid_t id;
+       intmax_t id = -1;
        int ch, rc;
        bool nis = false;
        bool deletehome = false;
@@ -864,7 +870,8 @@ pw_user_del(int argc, char **argv, char *arg1)
                /* Remove crontabs */
                snprintf(file, sizeof(file), "/var/cron/tabs/%s", pwd->pw_name);
                if (access(file, F_OK) == 0) {
-                       snprintf(file, sizeof(file), "crontab -u %s -r", pwd->pw_name);
+                       snprintf(file, sizeof(file), "crontab -u %s -r",
+                           pwd->pw_name);
                        system(file);
                }
        }
@@ -1275,6 +1282,9 @@ pw_user_add(int argc, char **argv, char *arg1)
        if (name == NULL)
                errx(EX_DATAERR, "login name required");
 
+       if (GETPWNAM(name) != NULL)
+               errx(EX_DATAERR, "login name `%s' already exists", name);
+
        pwd = &fakeuser;
        pwd->pw_name = name;
        pwd->pw_class = cmdcnf->default_class ? cmdcnf->default_class : "";
@@ -1313,7 +1323,8 @@ pw_user_add(int argc, char **argv, char *arg1)
                printf("%s\n", cmdcnf->nispasswd);
                rc = addnispwent(cmdcnf->nispasswd, pwd);
                if (rc == -1)
-                       warnx("User '%s' already exists in NIS passwd", pwd->pw_name);
+                       warnx("User '%s' already exists in NIS passwd",
+                           pwd->pw_name);
                else if (rc != 0)
                        warn("NIS passwd update");
                /* NOTE: we treat NIS-only update errors as non-fatal */
@@ -1343,7 +1354,8 @@ pw_user_add(int argc, char **argv, char *arg1)
        grp = GETGRGID(pwd->pw_gid);
        pw_log(cnf, M_ADD, W_USER, "%s(%ju):%s(%ju):%s:%s:%s",
               pwd->pw_name, (uintmax_t)pwd->pw_uid,
-           grp ? grp->gr_name : "unknown", (uintmax_t)(grp ? grp->gr_gid : (uid_t)-1),
+           grp ? grp->gr_name : "unknown",
+              (uintmax_t)(grp ? grp->gr_gid : (uid_t)-1),
               pwd->pw_gecos, pwd->pw_dir, pwd->pw_shell);
 
        /*
@@ -1411,8 +1423,9 @@ pw_user_mod(int argc, char **argv, char *arg1)
        int ch, fd = -1;
        size_t i, j;
        bool quiet, createhome, pretty, dryrun, nis, edited, docreatehome;
+       bool precrypted;
        mode_t homemode = 0;
-       time_t expire_days, password_days, now, precrypted;
+       time_t expire_days, password_days, now;
 
        expire_days = password_days = -1;
        gecos = homedir = grname = name = newname = skel = shell =NULL;
@@ -1574,7 +1587,8 @@ pw_user_mod(int argc, char **argv, char *arg1)
                if (pwd->pw_uid != 0 && strcmp(pwd->pw_name, "root") == 0)
                        errx(EX_DATAERR, "can't change uid of `root' account");
                if (pwd->pw_uid == 0 && strcmp(pwd->pw_name, "root") != 0)
-                       warnx("WARNING: account `%s' will have a uid of 0 (superuser access!)", pwd->pw_name);
+                       warnx("WARNING: account `%s' will have a uid of 0 "
+                           "(superuser access!)", pwd->pw_name);
        }
 
        if (grname && pwd->pw_uid != 0) {