summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon J. Gerraty <sjg@FreeBSD.org>2015-05-27 01:19:58 +0000
committerSimon J. Gerraty <sjg@FreeBSD.org>2015-05-27 01:19:58 +0000
commitd8b9e0faa3460c476b2e30e33f85d3c45d75832b (patch)
tree718a4865bc637195eba03ee314533bf4505046c9
parent07f6546979612511fa7f69bea50fe257e8ae562a (diff)
parent31af648934ea1701d783359919da4009225e7477 (diff)
downloadpw-darwin-d8b9e0faa3460c476b2e30e33f85d3c45d75832b.tar.gz
pw-darwin-d8b9e0faa3460c476b2e30e33f85d3c45d75832b.tar.zst
pw-darwin-d8b9e0faa3460c476b2e30e33f85d3c45d75832b.zip
Merge sync of head
-rw-r--r--pw/Makefile3
-rw-r--r--pw/Makefile.depend1
-rw-r--r--pw/fileupd.c21
-rw-r--r--pw/grupd.c4
-rw-r--r--pw/pw_conf.c266
-rw-r--r--pw/pw_nis.c3
-rw-r--r--pw/pw_user.c37
-rw-r--r--pw/pwupd.c109
-rw-r--r--pw/pwupd.h3
-rw-r--r--pw/tests/Makefile14
-rwxr-xr-xpw/tests/helper_functions.shin3
-rwxr-xr-xpw/tests/pw_delete.sh47
-rwxr-xr-xpw/tests/pw_groupdel.sh24
-rwxr-xr-xpw/tests/pw_groupmod.sh (renamed from pw/tests/pw_modify.sh)44
-rwxr-xr-xpw/tests/pw_lock.sh6
-rwxr-xr-xpw/tests/pw_useradd.sh188
-rwxr-xr-xpw/tests/pw_userdel.sh37
-rwxr-xr-xpw/tests/pw_usermod.sh112
-rwxr-xr-xpw/tests/pw_usernext.sh45
19 files changed, 648 insertions, 319 deletions
diff --git a/pw/Makefile b/pw/Makefile
index 8c5acf9..69953da 100644
--- a/pw/Makefile
+++ b/pw/Makefile
@@ -8,8 +8,7 @@ SRCS= pw.c pw_conf.c pw_user.c pw_group.c pw_log.c pw_nis.c pw_vpw.c \
WARNS?= 2
-DPADD= ${LIBCRYPT} ${LIBUTIL}
-LDADD= -lcrypt -lutil
+LIBADD= crypt util sbuf
.include <src.opts.mk>
diff --git a/pw/Makefile.depend b/pw/Makefile.depend
index 8595bfc..e9c6d4c 100644
--- a/pw/Makefile.depend
+++ b/pw/Makefile.depend
@@ -11,6 +11,7 @@ DIRDEPS = \
lib/libc \
lib/libcompiler_rt \
lib/libcrypt \
+ lib/libsbuf \
lib/libutil \
diff --git a/pw/fileupd.c b/pw/fileupd.c
index 7df4bb1..dc32712 100644
--- a/pw/fileupd.c
+++ b/pw/fileupd.c
@@ -29,32 +29,11 @@ static const char rcsid[] =
"$FreeBSD$";
#endif /* not lint */
-#include <stdio.h>
-#include <fcntl.h>
#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/param.h>
-#include <errno.h>
-#include <unistd.h>
#include "pwupd.h"
int
-extendline(char **buf, int * buflen, int needed)
-{
- if (needed > *buflen) {
- char *tmp = realloc(*buf, needed);
- if (tmp == NULL)
- return -1;
- *buf = tmp;
- *buflen = needed;
- }
- return *buflen;
-}
-
-int
extendarray(char ***buf, int * buflen, int needed)
{
if (needed > *buflen) {
diff --git a/pw/grupd.c b/pw/grupd.c
index 3f78e95..74cc390 100644
--- a/pw/grupd.c
+++ b/pw/grupd.c
@@ -35,10 +35,6 @@ static const char rcsid[] =
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
-#include <stdarg.h>
-#include <sys/types.h>
-#include <sys/stat.h>
#include <sys/param.h>
#include "pwupd.h"
diff --git a/pw/pw_conf.c b/pw/pw_conf.c
index 1289b3e..99d3e8f 100644
--- a/pw/pw_conf.c
+++ b/pw/pw_conf.c
@@ -29,9 +29,12 @@ static const char rcsid[] =
"$FreeBSD$";
#endif /* not lint */
+#include <sys/types.h>
+#include <sys/sbuf.h>
#include <string.h>
#include <ctype.h>
#include <fcntl.h>
+#include <err.h>
#include "pw.h"
@@ -209,19 +212,16 @@ boolean_str(int val)
char *
newstr(char const * p)
{
- char *q = NULL;
+ char *q;
- if ((p = unquote(p)) != NULL) {
- int l = strlen(p) + 1;
+ if ((p = unquote(p)) == NULL)
+ return (NULL);
- if ((q = malloc(l)) != NULL)
- memcpy(q, p, l);
- }
- return q;
-}
-
-#define LNBUFSZ 1024
+ if ((q = strdup(p)) == NULL)
+ err(1, "strdup()");
+ return (q);
+}
struct userconf *
read_userconfig(char const * file)
@@ -234,8 +234,10 @@ read_userconfig(char const * file)
buf = NULL;
linecap = 0;
- extendarray(&config.groups, &config.numgroups, 200);
- memset(config.groups, 0, config.numgroups * sizeof(char *));
+ config.numgroups = 200;
+ config.groups = calloc(config.numgroups, sizeof(char *));
+ if (config.groups == NULL)
+ err(1, "calloc()");
if (file == NULL)
file = _PATH_PW_CONF;
@@ -366,138 +368,132 @@ int
write_userconfig(char const * file)
{
int fd;
+ int i, j;
+ struct sbuf *buf;
+ FILE *fp;
if (file == NULL)
file = _PATH_PW_CONF;
- if ((fd = open(file, O_CREAT | O_RDWR | O_TRUNC | O_EXLOCK, 0644)) != -1) {
- FILE *fp;
+ if ((fd = open(file, O_CREAT|O_RDWR|O_TRUNC|O_EXLOCK, 0644)) == -1)
+ return (0);
- if ((fp = fdopen(fd, "w")) == NULL)
- close(fd);
- else {
- int i, j, k;
- int len = LNBUFSZ;
- char *buf = malloc(len);
-
- for (i = _UC_NONE; i < _UC_FIELDS; i++) {
- int quote = 1;
- char const *val = buf;
-
- *buf = '\0';
- switch (i) {
- case _UC_DEFAULTPWD:
- val = boolean_str(config.default_password);
- break;
- case _UC_REUSEUID:
- val = boolean_str(config.reuse_uids);
- break;
- case _UC_REUSEGID:
- val = boolean_str(config.reuse_gids);
- break;
- case _UC_NISPASSWD:
- val = config.nispasswd ? config.nispasswd : "";
- quote = 0;
- break;
- case _UC_DOTDIR:
- val = config.dotdir ? config.dotdir : boolean_str(0);
- break;
- case _UC_NEWMAIL:
- val = config.newmail ? config.newmail : boolean_str(0);
- break;
- case _UC_LOGFILE:
- val = config.logfile ? config.logfile : boolean_str(0);
- break;
- case _UC_HOMEROOT:
- val = config.home;
- break;
- case _UC_HOMEMODE:
- sprintf(buf, "%04o", config.homemode);
- quote = 0;
- break;
- case _UC_SHELLPATH:
- val = config.shelldir;
- break;
- case _UC_SHELLS:
- for (j = k = 0; j < _UC_MAXSHELLS && system_shells[j] != NULL; j++) {
- char lbuf[64];
- int l = snprintf(lbuf, sizeof lbuf, "%s\"%s\"", k ? "," : "", system_shells[j]);
- if (l < 0)
- l = 0;
- if (l + k + 1 < len || extendline(&buf, &len, len + LNBUFSZ) != -1) {
- strcpy(buf + k, lbuf);
- k += l;
- }
- }
- quote = 0;
- break;
- case _UC_DEFAULTSHELL:
- val = config.shell_default ? config.shell_default : bourne_shell;
- break;
- case _UC_DEFAULTGROUP:
- val = config.default_group ? config.default_group : "";
- break;
- case _UC_EXTRAGROUPS:
- extendarray(&config.groups, &config.numgroups, 200);
- for (j = k = 0; j < config.numgroups && config.groups[j] != NULL; j++) {
- char lbuf[64];
- int l = snprintf(lbuf, sizeof lbuf, "%s\"%s\"", k ? "," : "", config.groups[j]);
- if (l < 0)
- l = 0;
- if (l + k + 1 < len || extendline(&buf, &len, len + 1024) != -1) {
- strcpy(buf + k, lbuf);
- k += l;
- }
- }
- quote = 0;
- break;
- case _UC_DEFAULTCLASS:
- val = config.default_class ? config.default_class : "";
- break;
- case _UC_MINUID:
- sprintf(buf, "%lu", (unsigned long) config.min_uid);
- quote = 0;
- break;
- case _UC_MAXUID:
- sprintf(buf, "%lu", (unsigned long) config.max_uid);
- quote = 0;
- break;
- case _UC_MINGID:
- sprintf(buf, "%lu", (unsigned long) config.min_gid);
- quote = 0;
- break;
- case _UC_MAXGID:
- sprintf(buf, "%lu", (unsigned long) config.max_gid);
- quote = 0;
- break;
- case _UC_EXPIRE:
- sprintf(buf, "%d", config.expire_days);
- quote = 0;
- break;
- case _UC_PASSWORD:
- sprintf(buf, "%d", config.password_days);
- quote = 0;
- break;
- case _UC_NONE:
- break;
- }
+ if ((fp = fdopen(fd, "w")) == NULL) {
+ close(fd);
+ return (0);
+ }
+
+ buf = sbuf_new_auto();
+ for (i = _UC_NONE; i < _UC_FIELDS; i++) {
+ int quote = 1;
+
+ sbuf_clear(buf);
+ switch (i) {
+ case _UC_DEFAULTPWD:
+ sbuf_cat(buf, boolean_str(config.default_password));
+ break;
+ case _UC_REUSEUID:
+ sbuf_cat(buf, boolean_str(config.reuse_uids));
+ break;
+ case _UC_REUSEGID:
+ sbuf_cat(buf, boolean_str(config.reuse_gids));
+ break;
+ case _UC_NISPASSWD:
+ sbuf_cat(buf, config.nispasswd ? config.nispasswd :
+ "");
+ quote = 0;
+ break;
+ case _UC_DOTDIR:
+ sbuf_cat(buf, config.dotdir ? config.dotdir :
+ boolean_str(0));
+ break;
+ case _UC_NEWMAIL:
+ sbuf_cat(buf, config.newmail ? config.newmail :
+ boolean_str(0));
+ break;
+ case _UC_LOGFILE:
+ sbuf_cat(buf, config.logfile ? config.logfile :
+ boolean_str(0));
+ break;
+ case _UC_HOMEROOT:
+ sbuf_cat(buf, config.home);
+ break;
+ case _UC_HOMEMODE:
+ sbuf_printf(buf, "%04o", config.homemode);
+ quote = 0;
+ break;
+ case _UC_SHELLPATH:
+ sbuf_cat(buf, config.shelldir);
+ break;
+ case _UC_SHELLS:
+ for (j = 0; j < _UC_MAXSHELLS &&
+ system_shells[j] != NULL; j++)
+ sbuf_printf(buf, "%s\"%s\"", j ?
+ "," : "", system_shells[j]);
+ quote = 0;
+ break;
+ case _UC_DEFAULTSHELL:
+ sbuf_cat(buf, config.shell_default ?
+ config.shell_default : bourne_shell);
+ break;
+ case _UC_DEFAULTGROUP:
+ sbuf_cat(buf, config.default_group ?
+ config.default_group : "");
+ break;
+ case _UC_EXTRAGROUPS:
+ for (j = 0; j < config.numgroups &&
+ config.groups[j] != NULL; j++)
+ sbuf_printf(buf, "%s\"%s\"", j ?
+ "," : "", config.groups[j]);
+ quote = 0;
+ break;
+ case _UC_DEFAULTCLASS:
+ sbuf_cat(buf, config.default_class ?
+ config.default_class : "");
+ break;
+ case _UC_MINUID:
+ sbuf_printf(buf, "%lu", (unsigned long) config.min_uid);
+ quote = 0;
+ break;
+ case _UC_MAXUID:
+ sbuf_printf(buf, "%lu", (unsigned long) config.max_uid);
+ quote = 0;
+ break;
+ case _UC_MINGID:
+ sbuf_printf(buf, "%lu", (unsigned long) config.min_gid);
+ quote = 0;
+ break;
+ case _UC_MAXGID:
+ sbuf_printf(buf, "%lu", (unsigned long) config.max_gid);
+ quote = 0;
+ break;
+ case _UC_EXPIRE:
+ sbuf_printf(buf, "%d", config.expire_days);
+ quote = 0;
+ break;
+ case _UC_PASSWORD:
+ sbuf_printf(buf, "%d", config.password_days);
+ quote = 0;
+ break;
+ case _UC_NONE:
+ break;
+ }
+ sbuf_finish(buf);
- if (comments[i])
- fputs(comments[i], fp);
+ if (comments[i])
+ fputs(comments[i], fp);
- if (*kwds[i]) {
- if (quote)
- fprintf(fp, "%s = \"%s\"\n", kwds[i], val);
- else
- fprintf(fp, "%s = %s\n", kwds[i], val);
+ if (*kwds[i]) {
+ if (quote)
+ fprintf(fp, "%s = \"%s\"\n", kwds[i],
+ sbuf_data(buf));
+ else
+ fprintf(fp, "%s = %s\n", kwds[i], sbuf_data(buf));
#if debugging
- printf("WROTE: %s = %s\n", kwds[i], val);
+ printf("WROTE: %s = %s\n", kwds[i], sbuf_data(buf));
#endif
- }
- }
- free(buf);
- return fclose(fp) != EOF;
}
}
- return 0;
+ sbuf_delete(buf);
+ return (fclose(fp) != EOF);
}
diff --git a/pw/pw_nis.c b/pw/pw_nis.c
index 918fc30..c786cc7 100644
--- a/pw/pw_nis.c
+++ b/pw/pw_nis.c
@@ -29,9 +29,6 @@ static const char rcsid[] =
"$FreeBSD$";
#endif /* not lint */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
#include <sys/types.h>
#include <err.h>
#include <pwd.h>
diff --git a/pw/pw_user.c b/pw/pw_user.c
index 483148a..b058aab 100644
--- a/pw/pw_user.c
+++ b/pw/pw_user.c
@@ -40,7 +40,6 @@ static const char rcsid[] =
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
-#include <unistd.h>
#include <login_cap.h>
#include <pwd.h>
#include <grp.h>
@@ -185,8 +184,7 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args)
* But we create a symlink from cnf->home -> "/usr" -> cnf->home
*/
if (strchr(cnf->home+1, '/') == NULL) {
- strcpy(dbuf, "/usr");
- strncat(dbuf, cnf->home, MAXPATHLEN-5);
+ snprintf(dbuf, MAXPATHLEN, "/usr%s", cnf->home);
if (mkdir(dbuf, _DEF_DIRMODE) != -1 || errno == EEXIST) {
chown(dbuf, 0, 0);
/*
@@ -364,11 +362,9 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args)
if (mode == M_LOCK) {
if (strncmp(pwd->pw_passwd, locked_str, sizeof(locked_str)-1) == 0)
errx(EX_DATAERR, "user '%s' is already locked", pwd->pw_name);
- passtmp = malloc(strlen(pwd->pw_passwd) + sizeof(locked_str));
+ asprintf(&passtmp, "%s%s", locked_str, pwd->pw_passwd);
if (passtmp == NULL) /* disaster */
errx(EX_UNAVAILABLE, "out of memory");
- strcpy(passtmp, locked_str);
- strcat(passtmp, pwd->pw_passwd);
pwd->pw_passwd = passtmp;
edited = 1;
} else if (mode == M_UNLOCK) {
@@ -401,7 +397,7 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args)
*/
snprintf(file, sizeof(file), "/var/cron/tabs/%s", pwd->pw_name);
if (access(file, F_OK) == 0) {
- sprintf(file, "crontab -u %s -r", pwd->pw_name);
+ snprintf(file, sizeof(file), "crontab -u %s -r", pwd->pw_name);
system(file);
}
}
@@ -409,7 +405,7 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args)
* Save these for later, since contents of pwd may be
* invalidated by deletion
*/
- sprintf(file, "%s/%s", _PATH_MAILDIR, pwd->pw_name);
+ snprintf(file, sizeof(file), "%s/%s", _PATH_MAILDIR, pwd->pw_name);
strlcpy(home, pwd->pw_dir, sizeof(home));
gr = GETGRGID(pwd->pw_gid);
if (gr != NULL)
@@ -815,7 +811,7 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args)
*/
if (mode == M_ADD) {
if (!PWALTDIR()) {
- sprintf(line, "%s/%s", _PATH_MAILDIR, pwd->pw_name);
+ snprintf(line, sizeof(line), "%s/%s", _PATH_MAILDIR, pwd->pw_name);
close(open(line, O_RDWR | O_CREAT, 0600)); /* Preserve contents &
* mtime */
chown(line, pwd->pw_uid, pwd->pw_gid);
@@ -959,7 +955,7 @@ pw_gidpolicy(struct userconf * cnf, struct cargs * args, char *nam, gid_t prefer
* function will happily handle that case for us and exit.
*/
if (GETGRGID(prefer) == NULL) {
- sprintf(tmp, "%lu", (unsigned long) prefer);
+ snprintf(tmp, sizeof(tmp), "%u", prefer);
addarg(&grpargs, 'g', tmp);
}
if (getarg(args, 'N'))
@@ -1022,17 +1018,16 @@ static char *
pw_homepolicy(struct userconf * cnf, struct cargs * args, char const * user)
{
struct carg *arg = getarg(args, 'd');
+ static char home[128];
if (arg)
- return arg->val;
- else {
- static char home[128];
+ return (arg->val);
- if (cnf->home == NULL || *cnf->home == '\0')
- errx(EX_CONFIG, "no base home directory set");
- sprintf(home, "%s/%s", cnf->home, user);
- return home;
- }
+ if (cnf->home == NULL || *cnf->home == '\0')
+ errx(EX_CONFIG, "no base home directory set");
+ snprintf(home, sizeof(home), "%s/%s", cnf->home, user);
+
+ return (home);
}
static char *
@@ -1053,12 +1048,12 @@ shell_path(char const * path, char *shells[], char *sh)
static char shellpath[256];
if (sh != NULL) {
- sprintf(shellpath, "%s/%s", p, sh);
+ snprintf(shellpath, sizeof(shellpath), "%s/%s", p, sh);
if (access(shellpath, X_OK) == 0)
return shellpath;
} else
for (i = 0; i < _UC_MAXSHELLS && shells[i] != NULL; i++) {
- sprintf(shellpath, "%s/%s", p, shells[i]);
+ snprintf(shellpath, sizeof(shellpath), "%s/%s", p, shells[i]);
if (access(shellpath, X_OK) == 0)
return shellpath;
}
@@ -1308,7 +1303,7 @@ rmat(uid_t uid)
st.st_uid == uid) {
char tmp[MAXPATHLEN];
- sprintf(tmp, "/usr/bin/atrm %s", e->d_name);
+ snprintf(tmp, sizeof(tmp), "/usr/bin/atrm %s", e->d_name);
system(tmp);
}
}
diff --git a/pw/pwupd.c b/pw/pwupd.c
index c2a9a53..710e901 100644
--- a/pw/pwupd.c
+++ b/pw/pwupd.c
@@ -33,7 +33,6 @@ static const char rcsid[] =
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <stdarg.h>
#include <pwd.h>
#include <libutil.h>
#include <errno.h>
@@ -52,12 +51,13 @@ int
setpwdir(const char * dir)
{
if (dir == NULL)
- return -1;
+ return (-1);
else
pwpath = strdup(dir);
if (pwpath == NULL)
- return -1;
- return 0;
+ return (-1);
+
+ return (0);
}
char *
@@ -66,23 +66,20 @@ getpwpath(char const * file)
static char pathbuf[MAXPATHLEN];
snprintf(pathbuf, sizeof pathbuf, "%s/%s", pwpath, file);
- return pathbuf;
+
+ return (pathbuf);
}
static int
-pwdb(char *arg,...)
+pwdb_check(void)
{
int i = 0;
pid_t pid;
- va_list ap;
char *args[10];
args[i++] = _PATH_PWD_MKDB;
- va_start(ap, arg);
- while (i < 6 && arg != NULL) {
- args[i++] = arg;
- arg = va_arg(ap, char *);
- }
+ args[i++] = "-C";
+
if (pwpath != pathpwd) {
args[i++] = "-d";
args[i++] = pwpath;
@@ -100,65 +97,66 @@ pwdb(char *arg,...)
if (WEXITSTATUS(i))
i = EIO;
}
- va_end(ap);
- return i;
+
+ return (i);
}
static int
pw_update(struct passwd * pwd, char const * user)
{
- int rc = 0;
-
- rc = pwdb("-C", (char *)NULL); /* Check only */
- if (rc == 0) {
- int pfd, tfd;
- struct passwd *pw = NULL;
- struct passwd *old_pw = NULL;
-
- if (pwd != NULL)
- pw = pw_dup(pwd);
-
- if (user != NULL)
- old_pw = GETPWNAM(user);
-
- if (pw_init(pwpath, NULL))
- err(1, "pw_init()");
- if ((pfd = pw_lock()) == -1) {
- pw_fini();
- err(1, "pw_lock()");
- }
- if ((tfd = pw_tmp(-1)) == -1) {
- pw_fini();
- err(1, "pw_tmp()");
- }
- if (pw_copy(pfd, tfd, pw, old_pw) == -1) {
- pw_fini();
- err(1, "pw_copy()");
- }
- /*
- * in case of deletion of a user, the whole database
- * needs to be regenerated
- */
- if (pw_mkdb(pw != NULL ? pw->pw_name : NULL) == -1) {
- pw_fini();
- err(1, "pw_mkdb()");
- }
- free(pw);
+ struct passwd *pw = NULL;
+ struct passwd *old_pw = NULL;
+ int rc, pfd, tfd;
+
+ if ((rc = pwdb_check()) != 0)
+ return (rc);
+
+ if (pwd != NULL)
+ pw = pw_dup(pwd);
+
+ if (user != NULL)
+ old_pw = GETPWNAM(user);
+
+ if (pw_init(pwpath, NULL))
+ err(1, "pw_init()");
+ if ((pfd = pw_lock()) == -1) {
pw_fini();
+ err(1, "pw_lock()");
}
- return 0;
+ if ((tfd = pw_tmp(-1)) == -1) {
+ pw_fini();
+ err(1, "pw_tmp()");
+ }
+ if (pw_copy(pfd, tfd, pw, old_pw) == -1) {
+ pw_fini();
+ err(1, "pw_copy()");
+ }
+ /*
+ * in case of deletion of a user, the whole database
+ * needs to be regenerated
+ */
+ if (pw_mkdb(pw != NULL ? pw->pw_name : NULL) == -1) {
+ pw_fini();
+ err(1, "pw_mkdb()");
+ }
+ free(pw);
+ pw_fini();
+
+ return (0);
}
int
addpwent(struct passwd * pwd)
{
- return pw_update(pwd, NULL);
+
+ return (pw_update(pwd, NULL));
}
int
chgpwent(char const * login, struct passwd * pwd)
{
- return pw_update(pwd, login);
+
+ return (pw_update(pwd, login));
}
int
@@ -167,5 +165,6 @@ delpwent(struct passwd * pwd)
char login[MAXLOGNAME];
strlcpy(login, pwd->pw_name, MAXLOGNAME);
- return pw_update(NULL, login);
+
+ return (pw_update(NULL, login));
}
diff --git a/pw/pwupd.h b/pw/pwupd.h
index 200ffee..d6e39ce 100644
--- a/pw/pwupd.h
+++ b/pw/pwupd.h
@@ -112,10 +112,7 @@ void vendgrent(void);
void copymkdir(char const * dir, char const * skel, mode_t mode, uid_t uid, gid_t gid);
void rm_r(char const * dir, uid_t uid);
-int extendline(char **buf, int *buflen, int needed);
int extendarray(char ***buf, int *buflen, int needed);
__END_DECLS
-#define PWBUFSZ 1024
-
#endif /* !_PWUPD_H */
diff --git a/pw/tests/Makefile b/pw/tests/Makefile
index 6bc9433..37d9c71 100644
--- a/pw/tests/Makefile
+++ b/pw/tests/Makefile
@@ -5,10 +5,18 @@ TESTSRC= ${.CURDIR}/../../../contrib/netbsd-tests/usr.sbin/useradd
TESTSDIR= ${TESTSBASE}/usr.sbin/pw
-ATF_TESTS_SH= pw_delete pw_lock pw_modify pw_etcdir
+ATF_TESTS_SH= pw_etcdir \
+ pw_lock \
+ pw_groupdel \
+ pw_groupmod \
+ pw_useradd \
+ pw_userdel \
+ pw_usermod \
+ pw_usernext
-TEST_METADATA.pw_delete+= required_user="root"
-TEST_METADATA.pw_modify+= required_user="root"
+.for tp in ${ATF_TESTS_SH}
+TEST_METADATA.${tp}+= required_user="root"
+.endfor
FILES= group helper_functions.shin master.passwd
FILESDIR= ${TESTSDIR}
diff --git a/pw/tests/helper_functions.shin b/pw/tests/helper_functions.shin
index f87b1e7..3680dfe 100755
--- a/pw/tests/helper_functions.shin
+++ b/pw/tests/helper_functions.shin
@@ -1,5 +1,8 @@
# $FreeBSD$
+# The pw command
+PW="pw -V ${HOME}"
+
# Workdir to run tests in
TESTDIR=$(atf_get_srcdir)
diff --git a/pw/tests/pw_delete.sh b/pw/tests/pw_delete.sh
deleted file mode 100755
index 02a9ade..0000000
--- a/pw/tests/pw_delete.sh
+++ /dev/null
@@ -1,47 +0,0 @@
-# $FreeBSD$
-
-# Import helper functions
-. $(atf_get_srcdir)/helper_functions.shin
-
-# Test that a user can be deleted when another user is part of this
-# user's default group and does not go into an infinate loop.
-# PR: 191427
-atf_test_case rmuser_seperate_group cleanup
-rmuser_seperate_group_head() {
- atf_set "timeout" "30"
-}
-rmuser_seperate_group_body() {
- populate_etc_skel
- pw -V ${HOME} useradd test || atf_fail "Creating test user"
- pw -V ${HOME} groupmod test -M 'test,root' || \
- atf_fail "Modifying the group"
- pw -V ${HOME} userdel test || atf_fail "Delete the test user"
-}
-
-atf_test_case group_do_not_delete_wheel_if_group_unknown
-group_do_not_delete_wheel_if_group_unknown_head() {
- atf_set "descr" "Make sure we do not consider gid 0 an unknown group"
-}
-
-group_do_not_delete_wheel_if_group_unknown_body() {
- populate_etc_skel
- atf_check -s exit:0 -o inline:"wheel:*:0:root\n" -x pw -V ${HOME} groupshow wheel
- atf_check -e inline:"pw: -g expects a number\n" -s exit:64 -x pw -V ${HOME} groupdel -g I_do_not_exist
- atf_check -s exit:0 -o inline:"wheel:*:0:root\n" -x pw -V ${HOME} groupshow wheel
-}
-
-atf_test_case user_do_not_try_to_delete_root_if_user_unknown
-user_do_not_try_to_delete_root_if_user_unknown_head() {
- atf_set "descr" "Make sure not to try to remove root if deleting an unknown user"
-}
-
-user_do_not_try_to_delete_root_if_user_unknown_body() {
- populate_etc_skel
- atf_check -e inline:"pw: -u expects a number\n" -s exit:64 -x pw -V ${HOME} userdel -u plop
-}
-
-atf_init_test_cases() {
- atf_add_test_case rmuser_seperate_group
- atf_add_test_case group_do_not_delete_wheel_if_group_unknown
- atf_add_test_case user_do_not_try_to_delete_root_if_user_unknown
-}
diff --git a/pw/tests/pw_groupdel.sh b/pw/tests/pw_groupdel.sh
new file mode 100755
index 0000000..75b063a
--- /dev/null
+++ b/pw/tests/pw_groupdel.sh
@@ -0,0 +1,24 @@
+# $FreeBSD$
+
+# Import helper functions
+. $(atf_get_srcdir)/helper_functions.shin
+
+
+# Test to make sure we do not accidentially delete wheel when trying to delete
+# an unknown group
+atf_test_case group_do_not_delete_wheel_if_group_unknown
+group_do_not_delete_wheel_if_group_unknown_head() {
+ atf_set "descr" "Make sure we do not consider gid 0 an unknown group"
+}
+group_do_not_delete_wheel_if_group_unknown_body() {
+ populate_etc_skel
+ atf_check -s exit:0 -o inline:"wheel:*:0:root\n" -x ${PW} groupshow wheel
+ atf_check -e inline:"pw: -g expects a number\n" -s exit:64 -x \
+ ${PW} groupdel -g I_do_not_exist
+ atf_check -s exit:0 -o inline:"wheel:*:0:root\n" -x ${PW} groupshow wheel
+}
+
+
+atf_init_test_cases() {
+ atf_add_test_case group_do_not_delete_wheel_if_group_unknown
+}
diff --git a/pw/tests/pw_modify.sh b/pw/tests/pw_groupmod.sh
index b81f105..ad7ad0a 100755
--- a/pw/tests/pw_modify.sh
+++ b/pw/tests/pw_groupmod.sh
@@ -8,11 +8,11 @@
atf_test_case groupmod_user
groupmod_user_body() {
populate_etc_skel
- atf_check -s exit:0 pw -V ${HOME} addgroup test
- atf_check -s exit:0 pw -V ${HOME} groupmod test -m root
+ atf_check -s exit:0 ${PW} addgroup test
+ atf_check -s exit:0 ${PW} groupmod test -m root
atf_check -s exit:0 -o match:"^test:\*:1001:root$" \
grep "^test:\*:.*:root$" $HOME/group
- atf_check -s exit:0 pw -V ${HOME} groupmod test -d root
+ atf_check -s exit:0 ${PW} groupmod test -d root
atf_check -s exit:0 -o match:"^test:\*:1001:$" \
grep "^test:\*:.*:$" $HOME/group
}
@@ -22,9 +22,9 @@ groupmod_user_body() {
atf_test_case groupmod_invalid_user
groupmod_invalid_user_body() {
populate_etc_skel
- atf_check -s exit:0 pw -V ${HOME} addgroup test
- atf_check -s exit:67 -e match:"does not exist" pw -V ${HOME} groupmod test -m foo
- atf_check -s exit:0 pw -V ${HOME} groupmod test -d foo
+ atf_check -s exit:0 ${PW} addgroup test
+ atf_check -s exit:67 -e match:"does not exist" ${PW} groupmod test -m foo
+ atf_check -s exit:0 ${PW} groupmod test -d foo
}
atf_test_case groupmod_bug_193704
@@ -33,9 +33,9 @@ groupmod_bug_193704_head() {
}
groupmod_bug_193704_body() {
populate_etc_skel
- atf_check -s exit:0 -x pw -V ${HOME} groupadd test
- atf_check -s exit:0 -x pw -V ${HOME} groupmod test -l newgroupname
- atf_check -s exit:65 -e match:"^pw: unknown group" -x pw -V ${HOME} groupshow test
+ atf_check -s exit:0 -x ${PW} groupadd test
+ atf_check -s exit:0 -x ${PW} groupmod test -l newgroupname
+ atf_check -s exit:65 -e match:"^pw: unknown group" -x ${PW} groupshow test
}
atf_test_case usermod_bug_185666
@@ -45,17 +45,17 @@ usermod_bug_185666_head() {
usermod_bug_185666_body() {
populate_etc_skel
- atf_check -s exit:0 -x pw -V ${HOME} useradd testuser
- atf_check -s exit:0 -x pw -V ${HOME} groupadd testgroup
- atf_check -s exit:0 -x pw -V ${HOME} groupadd testgroup2
- atf_check -s exit:0 -x pw -V ${HOME} usermod testuser -G testgroup
- atf_check -o inline:"testuser:*:1001:\n" -x pw -V${HOME} groupshow testuser
- atf_check -o inline:"testgroup:*:1002:testuser\n" -x pw -V ${HOME} groupshow testgroup
- atf_check -o inline:"testgroup2:*:1003:\n" -x pw -V${HOME} groupshow testgroup2
- atf_check -s exit:0 -x pw -V ${HOME} usermod testuser -G testgroup2
- atf_check -o inline:"testuser:*:1001:\n" -x pw -V ${HOME} groupshow testuser
- atf_check -o inline:"testgroup:*:1002:\n" -x pw -V ${HOME} groupshow testgroup
- atf_check -o inline:"testgroup2:*:1003:testuser\n" -x pw -V ${HOME} groupshow testgroup2
+ atf_check -s exit:0 -x ${PW} useradd testuser
+ atf_check -s exit:0 -x ${PW} groupadd testgroup
+ atf_check -s exit:0 -x ${PW} groupadd testgroup2
+ atf_check -s exit:0 -x ${PW} usermod testuser -G testgroup
+ atf_check -o inline:"testuser:*:1001:\n" -x ${PW} groupshow testuser
+ atf_check -o inline:"testgroup:*:1002:testuser\n" -x ${PW} groupshow testgroup
+ atf_check -o inline:"testgroup2:*:1003:\n" -x ${PW} groupshow testgroup2
+ atf_check -s exit:0 -x ${PW} usermod testuser -G testgroup2
+ atf_check -o inline:"testuser:*:1001:\n" -x ${PW} groupshow testuser
+ atf_check -o inline:"testgroup:*:1002:\n" -x ${PW} groupshow testgroup
+ atf_check -o inline:"testgroup2:*:1003:testuser\n" -x ${PW} groupshow testgroup2
}
atf_test_case do_not_duplicate_group_on_gid_change
@@ -65,8 +65,8 @@ do_not_duplicate_group_on_gid_change_head() {
do_not_duplicate_group_on_gid_change_body() {
populate_etc_skel
- atf_check -s exit:0 -x pw -V ${HOME} groupadd testgroup
- atf_check -s exit:0 -x pw -V ${HOME} groupmod testgroup -g 12345
+ atf_check -s exit:0 -x ${PW} groupadd testgroup
+ atf_check -s exit:0 -x ${PW} groupmod testgroup -g 12345
# use grep to see if the entry has not be duplicated
atf_check -o inline:"testgroup:*:12345:\n" -s exit:0 -x grep "^testgroup" ${HOME}/group
}
diff --git a/pw/tests/pw_lock.sh b/pw/tests/pw_lock.sh
index 070a6f9..9f14e24 100755
--- a/pw/tests/pw_lock.sh
+++ b/pw/tests/pw_lock.sh
@@ -7,11 +7,11 @@
atf_test_case user_locking cleanup
user_locking_body() {
populate_etc_skel
- pw -V ${HOME} useradd test || atf_fail "Creating test user"
- pw -V ${HOME} lock test || atf_fail "Locking the user"
+ ${PW} useradd test || atf_fail "Creating test user"
+ ${PW} lock test || atf_fail "Locking the user"
atf_check -s exit:0 -o match:"^test:\*LOCKED\*\*:1001:" \
grep "^test:\*LOCKED\*\*:1001:" $HOME/master.passwd
- pw -V ${HOME} unlock test || atf_fail "Locking the user"
+ ${PW} unlock test || atf_fail "Locking the user"
atf_check -s exit:0 -o match:"^test:\*:1001:" \
grep "^test:\*:1001:" $HOME/master.passwd
}
diff --git a/pw/tests/pw_useradd.sh b/pw/tests/pw_useradd.sh
new file mode 100755
index 0000000..48612ed
--- /dev/null
+++ b/pw/tests/pw_useradd.sh
@@ -0,0 +1,188 @@
+# $FreeBSD$
+
+# Import helper functions
+. $(atf_get_srcdir)/helper_functions.shin
+
+# Test add user
+atf_test_case user_add
+user_add_body() {
+ populate_etc_skel
+
+ atf_check -s exit:0 ${PW} useradd test
+ atf_check -s exit:0 -o match:"^test:.*" \
+ grep "^test:.*" $HOME/master.passwd
+}
+
+# Test add user with option -N
+atf_test_case user_add_noupdate
+user_add_noupdate_body() {
+ populate_etc_skel
+
+ atf_check -s exit:0 -o match:"^test:.*" ${PW} useradd test -N
+ atf_check -s exit:1 -o empty grep "^test:.*" $HOME/master.passwd
+}
+
+# Test add user with comments
+atf_test_case user_add_comments
+user_add_comments_body() {
+ populate_etc_skel
+
+ atf_check -s exit:0 ${PW} useradd test -c "Test User,work,123,456"
+ atf_check -s exit:0 -o match:"^test:.*:Test User,work,123,456:" \
+ grep "^test:.*:Test User,work,123,456:" $HOME/master.passwd
+}
+
+# Test add user with comments and option -N
+atf_test_case user_add_comments_noupdate
+user_add_comments_noupdate_body() {
+ populate_etc_skel
+
+ atf_check -s exit:0 -o match:"^test:.*:Test User,work,123,456:" \
+ ${PW} useradd test -c "Test User,work,123,456" -N
+ atf_check -s exit:1 -o empty grep "^test:.*" $HOME/master.passwd
+}
+
+# Test add user with invalid comments
+atf_test_case user_add_comments_invalid
+user_add_comments_invalid_body() {
+ populate_etc_skel
+
+ atf_check -s exit:65 -e match:"invalid character" \
+ ${PW} useradd test -c "Test User,work,123:456,456"
+ atf_check -s exit:1 -o empty \
+ grep "^test:.*:Test User,work,123:456,456:" $HOME/master.passwd
+}
+
+# Test add user with invalid comments and option -N
+atf_test_case user_add_comments_invalid_noupdate
+user_add_comments_invalid_noupdate_body() {
+ populate_etc_skel
+
+ atf_check -s exit:65 -e match:"invalid character" \
+ ${PW} useradd test -c "Test User,work,123:456,456" -N
+ atf_check -s exit:1 -o empty grep "^test:.*" $HOME/master.passwd
+}
+
+# Test add user with alternate homedir
+atf_test_case user_add_homedir
+user_add_homedir_body() {
+ populate_etc_skel
+
+ atf_check -s exit:0 ${PW} useradd test -d /foo/bar
+ atf_check -s exit:0 -o match:"^test:\*:.*::0:0:User &:/foo/bar:.*" \
+ ${PW} usershow test
+}
+
+# Test add user with account expiration as an epoch date
+atf_test_case user_add_account_expiration_epoch
+user_add_account_expiration_epoch_body() {
+ populate_etc_skel
+
+ DATE=`date -j -v+1d "+%s"`
+ atf_check -s exit:0 ${PW} useradd test -e ${DATE}
+ atf_check -s exit:0 -o match:"^test:\*:.*::0:${DATE}:.*" \
+ ${PW} usershow test
+}
+
+# Test add user with account expiration as a DD-MM-YYYY date
+atf_test_case user_add_account_expiration_date_numeric
+user_add_account_expiration_date_numeric_body() {
+ populate_etc_skel
+
+ DATE=`date -j -v+1d "+%d-%m-%Y"`
+ EPOCH=`date -j -f "%d-%m-%Y %H:%M:%S" "${DATE} 00:00:00" "+%s"`
+ atf_check -s exit:0 ${PW} useradd test -e ${DATE}
+ atf_check -s exit:0 -o match:"^test:\*:.*::0:${EPOCH}:User &:.*" \
+ ${PW} usershow test
+}
+
+# Test add user with account expiration as a DD-MM-YYYY date
+atf_test_case user_add_account_expiration_date_month
+user_add_account_expiration_date_month_body() {
+ populate_etc_skel
+
+ DATE=`date -j -v+1d "+%d-%b-%Y"`
+ EPOCH=`date -j -f "%d-%b-%Y %H:%M:%S" "${DATE} 00:00:00" "+%s"`
+ atf_check -s exit:0 ${PW} useradd test -e ${DATE}
+ atf_check -s exit:0 -o match:"^test:\*:.*::0:${EPOCH}:User &:.*" \
+ ${PW} usershow test
+}
+
+# Test add user with account expiration as a relative date
+atf_test_case user_add_account_expiration_date_relative
+user_add_account_expiration_date_relative_body() {
+ populate_etc_skel
+
+ EPOCH=`date -j -v+13m "+%s"`
+ BUF=`expr $EPOCH + 5`
+ atf_check -s exit:0 ${PW} useradd test -e +13o
+ TIME=`${PW} usershow test | awk -F ':' '{print $7}'`
+ [ ! -z $TIME -a $TIME -ge $EPOCH -a $TIME -lt $BUF ] || \
+ atf_fail "Expiration time($TIME) was not within $EPOCH - $BUF seconds."
+}
+
+# Test add user with password expiration as an epoch date
+atf_test_case user_add_password_expiration_epoch
+user_add_password_expiration_epoch_body() {
+ populate_etc_skel
+
+ DATE=`date -j -v+1d "+%s"`
+ atf_check -s exit:0 ${PW} useradd test -p ${DATE}
+ atf_check -s exit:0 -o match:"^test:\*:.*::${DATE}:0:.*" \
+ ${PW} usershow test
+}
+
+# Test add user with password expiration as a DD-MM-YYYY date
+atf_test_case user_add_password_expiration_date_numeric
+user_add_password_expiration_date_numeric_body() {
+ populate_etc_skel
+
+ DATE=`date -j -v+1d "+%d-%m-%Y"`
+ EPOCH=`date -j -f "%d-%m-%Y %H:%M:%S" "${DATE} 00:00:00" "+%s"`
+ atf_check -s exit:0 ${PW} useradd test -p ${DATE}
+ atf_check -s exit:0 -o match:"^test:\*:.*::${EPOCH}:0:User &:.*" \
+ ${PW} usershow test
+}
+
+# Test add user with password expiration as a DD-MMM-YYYY date
+atf_test_case user_add_password_expiration_date_month
+user_add_password_expiration_date_month_body() {
+ populate_etc_skel
+
+ DATE=`date -j -v+1d "+%d-%b-%Y"`
+ EPOCH=`date -j -f "%d-%b-%Y %H:%M:%S" "${DATE} 00:00:00" "+%s"`
+ atf_check -s exit:0 ${PW} useradd test -p ${DATE}
+ atf_check -s exit:0 -o match:"^test:\*:.*::${EPOCH}:0:User &:.*" \
+ ${PW} usershow test
+}
+
+# Test add user with password expiration as a relative date
+atf_test_case user_add_password_expiration_date_relative
+user_add_password_expiration_date_relative_body() {
+ populate_etc_skel
+
+ EPOCH=`date -j -v+13m "+%s"`
+ BUF=`expr $EPOCH + 5`
+ atf_check -s exit:0 ${PW} useradd test -p +13o
+ TIME=`${PW} usershow test | awk -F ':' '{print $6}'`
+ [ ! -z $TIME -a $TIME -ge $EPOCH -a $TIME -lt $BUF ] || \
+ atf_fail "Expiration time($TIME) was not within $EPOCH - $BUF seconds."
+}
+
+atf_init_test_cases() {
+ atf_add_test_case user_add
+ atf_add_test_case user_add_noupdate
+ atf_add_test_case user_add_comments
+ atf_add_test_case user_add_comments_noupdate
+ atf_add_test_case user_add_comments_invalid
+ atf_add_test_case user_add_comments_invalid_noupdate
+ atf_add_test_case user_add_homedir
+ atf_add_test_case user_add_account_expiration_epoch
+ atf_add_test_case user_add_account_expiration_date_numeric
+ atf_add_test_case user_add_account_expiration_date_month
+ atf_add_test_case user_add_account_expiration_date_relative
+ atf_add_test_case user_add_password_expiration_epoch
+ atf_add_test_case user_add_password_expiration_date_numeric
+ atf_add_test_case user_add_password_expiration_date_month
+ atf_add_test_case user_add_password_expiration_date_relative
+}
diff --git a/pw/tests/pw_userdel.sh b/pw/tests/pw_userdel.sh
new file mode 100755
index 0000000..71a7033
--- /dev/null
+++ b/pw/tests/pw_userdel.sh
@@ -0,0 +1,37 @@
+# $FreeBSD$
+
+# Import helper functions
+. $(atf_get_srcdir)/helper_functions.shin
+
+
+# Test that a user can be deleted when another user is part of this
+# user's default group and does not go into an infinate loop.
+# PR: 191427
+atf_test_case rmuser_seperate_group cleanup
+rmuser_seperate_group_head() {
+ atf_set "timeout" "30"
+}
+rmuser_seperate_group_body() {
+ populate_etc_skel
+ ${PW} useradd test || atf_fail "Creating test user"
+ ${PW} groupmod test -M 'test,root' || \
+ atf_fail "Modifying the group"
+ ${PW} userdel test || atf_fail "Delete the test user"
+}
+
+
+atf_test_case user_do_not_try_to_delete_root_if_user_unknown
+user_do_not_try_to_delete_root_if_user_unknown_head() {
+ atf_set "descr" \
+ "Make sure not to try to remove root if deleting an unknown user"
+}
+user_do_not_try_to_delete_root_if_user_unknown_body() {
+ populate_etc_skel
+ atf_check -e inline:"pw: -u expects a number\n" -s exit:64 -x \
+ ${PW} userdel -u plop
+}
+
+atf_init_test_cases() {
+ atf_add_test_case rmuser_seperate_group
+ atf_add_test_case user_do_not_try_to_delete_root_if_user_unknown
+}
diff --git a/pw/tests/pw_usermod.sh b/pw/tests/pw_usermod.sh
new file mode 100755
index 0000000..88bd316
--- /dev/null
+++ b/pw/tests/pw_usermod.sh
@@ -0,0 +1,112 @@
+# $FreeBSD$
+
+# Import helper functions
+. $(atf_get_srcdir)/helper_functions.shin
+
+# Test modifying a user
+atf_test_case user_mod
+user_mod_body() {
+ populate_etc_skel
+
+ atf_check -s exit:67 -e match:"no such user" ${PW} usermod test
+ atf_check -s exit:0 ${PW} useradd test
+ atf_check -s exit:0 ${PW} usermod test
+ atf_check -s exit:0 -o match:"^test:.*" \
+ grep "^test:.*" $HOME/master.passwd
+}
+
+# Test modifying a user with option -N
+atf_test_case user_mod_noupdate
+user_mod_noupdate_body() {
+ populate_etc_skel
+
+ atf_check -s exit:67 -e match:"no such user" ${PW} usermod test -N
+ atf_check -s exit:0 ${PW} useradd test
+ atf_check -s exit:0 -o match:"^test:.*" ${PW} usermod test -N
+ atf_check -s exit:0 -o match:"^test:.*" \
+ grep "^test:.*" $HOME/master.passwd
+}
+
+# Test modifying a user with comments
+atf_test_case user_mod_comments
+user_mod_comments_body() {
+ populate_etc_skel
+
+ atf_check -s exit:0 ${PW} useradd test -c "Test User,home,123,456"
+ atf_check -s exit:0 ${PW} usermod test -c "Test User,work,123,456"
+ atf_check -s exit:0 -o match:"^test:.*:Test User,work,123,456:" \
+ grep "^test:.*:Test User,work,123,456:" $HOME/master.passwd
+}
+
+# Test modifying a user with comments with option -N
+atf_test_case user_mod_comments_noupdate
+user_mod_comments_noupdate_body() {
+ populate_etc_skel
+
+ atf_check -s exit:0 ${PW} useradd test -c "Test User,home,123,456"
+ atf_check -s exit:0 -o match:"^test:.*:Test User,work,123,456:" \
+ ${PW} usermod test -c "Test User,work,123,456" -N
+ atf_check -s exit:0 -o match:"^test:.*:Test User,home,123,456:" \
+ grep "^test:.*:Test User,home,123,456:" $HOME/master.passwd
+}
+
+# Test modifying a user with invalid comments
+atf_test_case user_mod_comments_invalid
+user_mod_comments_invalid_body() {
+ populate_etc_skel
+
+ atf_check -s exit:0 ${PW} useradd test
+ atf_check -s exit:65 -e match:"invalid character" \
+ ${PW} usermod test -c "Test User,work,123:456,456"
+ atf_check -s exit:1 -o empty \
+ grep "^test:.*:Test User,work,123:456,456:" $HOME/master.passwd
+ atf_check -s exit:0 -o match:"^test:\*" \
+ grep "^test:\*" $HOME/master.passwd
+}
+
+# Test modifying a user with invalid comments with option -N
+atf_test_case user_mod_comments_invalid_noupdate
+user_mod_comments_invalid_noupdate_body() {
+ populate_etc_skel
+
+ atf_check -s exit:0 ${PW} useradd test
+ atf_check -s exit:65 -e match:"invalid character" \
+ ${PW} usermod test -c "Test User,work,123:456,456" -N
+ atf_check -s exit:1 -o empty \
+ grep "^test:.*:Test User,work,123:456,456:" $HOME/master.passwd
+ atf_check -s exit:0 -o match:"^test:\*" \
+ grep "^test:\*" $HOME/master.passwd
+}
+
+# Test modifying a user name with -l
+atf_test_case user_mod_name
+user_mod_name_body() {
+ populate_etc_skel
+
+ atf_check -s exit:0 ${PW} useradd foo
+ atf_check -s exit:0 ${PW} usermod foo -l "bar"
+ atf_check -s exit:0 -o match:"^bar:.*" \
+ grep "^bar:.*" $HOME/master.passwd
+}
+
+# Test modifying a user name with -l with option -N
+atf_test_case user_mod_name_noupdate
+user_mod_name_noupdate_body() {
+ populate_etc_skel
+
+ atf_check -s exit:0 ${PW} useradd foo
+ atf_check -s exit:0 -o match:"^bar:.*" ${PW} usermod foo -l "bar" -N
+ atf_check -s exit:0 -o match:"^foo:.*" \
+ grep "^foo:.*" $HOME/master.passwd
+}
+
+atf_init_test_cases() {
+ atf_add_test_case user_mod
+ atf_add_test_case user_mod_noupdate
+ atf_add_test_case user_mod_comments
+ atf_add_test_case user_mod_comments_noupdate
+ atf_add_test_case user_mod_comments_invalid
+ atf_add_test_case user_mod_comments_invalid_noupdate
+ atf_add_test_case user_mod_name
+ atf_add_test_case user_mod_name_noupdate
+}
diff --git a/pw/tests/pw_usernext.sh b/pw/tests/pw_usernext.sh
new file mode 100755
index 0000000..89f938e
--- /dev/null
+++ b/pw/tests/pw_usernext.sh
@@ -0,0 +1,45 @@
+# $FreeBSD$
+
+# Import helper functions
+. $(atf_get_srcdir)/helper_functions.shin
+
+# Test usernext after adding a random number of new users.
+atf_test_case usernext
+usernext_body() {
+ populate_etc_skel
+
+ CURRENT=`${PW} usernext | sed -e 's/:.*//'`
+ RANDOM=`jot -r 1 1 150`
+ MAX=`expr ${CURRENT} + ${RANDOM}`
+ while [ "${CURRENT}" -lt "${MAX}" ]
+ do
+ atf_check -s exit:0 ${PW} useradd test${CURRENT}
+ CURRENT=`expr ${CURRENT} + 1`
+ done
+ atf_check -s exit:0 -o match:"${CURRENT}:${CURRENT}" \
+ ${PW} usernext
+}
+
+# Test usernext when multiple users are added to the same group so
+# that group id doesn't increment at the same pace as new users.
+atf_test_case usernext_assigned_group
+usernext_assigned_group_body() {
+ populate_etc_skel
+
+ CURRENT=`${PW} usernext | sed -e 's/:.*//'`
+ CURRENTGID=`${PW} groupnext`
+ RANDOM=`jot -r 1 1 150`
+ MAX=`expr ${CURRENT} + ${RANDOM}`
+ while [ "${CURRENT}" -lt "${MAX}" ]
+ do
+ atf_check -s exit:0 ${PW} useradd -n test${CURRENT} -g 0
+ CURRENT=`expr ${CURRENT} + 1`
+ done
+ atf_check -s exit:0 -o match:"${CURRENT}:${CURRENTGID}" \
+ ${PW} usernext
+}
+
+atf_init_test_cases() {
+ atf_add_test_case usernext
+ atf_add_test_case usernext_assigned_group
+}