summaryrefslogtreecommitdiffstats
path: root/pw
diff options
context:
space:
mode:
Diffstat (limited to 'pw')
-rw-r--r--pw/Makefile3
-rw-r--r--pw/Makefile.depend21
-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_lock.sh6
-rwxr-xr-xpw/tests/pw_modify.sh (renamed from pw/tests/pw_groupmod.sh)44
-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, 340 insertions, 647 deletions
diff --git a/pw/Makefile b/pw/Makefile
index 69953da..8c5acf9 100644
--- a/pw/Makefile
+++ b/pw/Makefile
@@ -8,7 +8,8 @@ SRCS= pw.c pw_conf.c pw_user.c pw_group.c pw_log.c pw_nis.c pw_vpw.c \
WARNS?= 2
-LIBADD= crypt util sbuf
+DPADD= ${LIBCRYPT} ${LIBUTIL}
+LDADD= -lcrypt -lutil
.include <src.opts.mk>
diff --git a/pw/Makefile.depend b/pw/Makefile.depend
new file mode 100644
index 0000000..8595bfc
--- /dev/null
+++ b/pw/Makefile.depend
@@ -0,0 +1,21 @@
+# Autogenerated - do NOT edit!
+
+DEP_RELDIR := ${_PARSEDIR:S,${SRCTOP}/,,}
+
+DIRDEPS = \
+ gnu/lib/csu \
+ gnu/lib/libgcc \
+ include \
+ include/xlocale \
+ lib/${CSU_DIR} \
+ lib/libc \
+ lib/libcompiler_rt \
+ lib/libcrypt \
+ lib/libutil \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
diff --git a/pw/fileupd.c b/pw/fileupd.c
index dc32712..7df4bb1 100644
--- a/pw/fileupd.c
+++ b/pw/fileupd.c
@@ -29,11 +29,32 @@ 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 74cc390..3f78e95 100644
--- a/pw/grupd.c
+++ b/pw/grupd.c
@@ -35,6 +35,10 @@ 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 99d3e8f..1289b3e 100644
--- a/pw/pw_conf.c
+++ b/pw/pw_conf.c
@@ -29,12 +29,9 @@ 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"
@@ -212,17 +209,20 @@ boolean_str(int val)
char *
newstr(char const * p)
{
- char *q;
+ char *q = NULL;
- if ((p = unquote(p)) == NULL)
- return (NULL);
+ if ((p = unquote(p)) != NULL) {
+ int l = strlen(p) + 1;
- if ((q = strdup(p)) == NULL)
- err(1, "strdup()");
-
- return (q);
+ if ((q = malloc(l)) != NULL)
+ memcpy(q, p, l);
+ }
+ return q;
}
+#define LNBUFSZ 1024
+
+
struct userconf *
read_userconfig(char const * file)
{
@@ -234,10 +234,8 @@ read_userconfig(char const * file)
buf = NULL;
linecap = 0;
- config.numgroups = 200;
- config.groups = calloc(config.numgroups, sizeof(char *));
- if (config.groups == NULL)
- err(1, "calloc()");
+ extendarray(&config.groups, &config.numgroups, 200);
+ memset(config.groups, 0, config.numgroups * sizeof(char *));
if (file == NULL)
file = _PATH_PW_CONF;
@@ -368,132 +366,138 @@ 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)
- return (0);
+ if ((fd = open(file, O_CREAT | O_RDWR | O_TRUNC | O_EXLOCK, 0644)) != -1) {
+ FILE *fp;
- 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 ((fp = fdopen(fd, "w")) == NULL)
+ close(fd);
+ else {
+ int i, j, k;
+ int len = LNBUFSZ;
+ char *buf = malloc(len);
- if (comments[i])
- fputs(comments[i], fp);
+ for (i = _UC_NONE; i < _UC_FIELDS; i++) {
+ int quote = 1;
+ char const *val = buf;
- 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));
+ *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 (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 debugging
- printf("WROTE: %s = %s\n", kwds[i], sbuf_data(buf));
+ printf("WROTE: %s = %s\n", kwds[i], val);
#endif
+ }
+ }
+ free(buf);
+ return fclose(fp) != EOF;
}
}
- sbuf_delete(buf);
- return (fclose(fp) != EOF);
+ return 0;
}
diff --git a/pw/pw_nis.c b/pw/pw_nis.c
index c786cc7..918fc30 100644
--- a/pw/pw_nis.c
+++ b/pw/pw_nis.c
@@ -29,6 +29,9 @@ 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 b058aab..483148a 100644
--- a/pw/pw_user.c
+++ b/pw/pw_user.c
@@ -40,6 +40,7 @@ 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>
@@ -184,7 +185,8 @@ 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) {
- snprintf(dbuf, MAXPATHLEN, "/usr%s", cnf->home);
+ strcpy(dbuf, "/usr");
+ strncat(dbuf, cnf->home, MAXPATHLEN-5);
if (mkdir(dbuf, _DEF_DIRMODE) != -1 || errno == EEXIST) {
chown(dbuf, 0, 0);
/*
@@ -362,9 +364,11 @@ 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);
- asprintf(&passtmp, "%s%s", locked_str, pwd->pw_passwd);
+ passtmp = malloc(strlen(pwd->pw_passwd) + sizeof(locked_str));
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) {
@@ -397,7 +401,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) {
- snprintf(file, sizeof(file), "crontab -u %s -r", pwd->pw_name);
+ sprintf(file, "crontab -u %s -r", pwd->pw_name);
system(file);
}
}
@@ -405,7 +409,7 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args)
* Save these for later, since contents of pwd may be
* invalidated by deletion
*/
- snprintf(file, sizeof(file), "%s/%s", _PATH_MAILDIR, pwd->pw_name);
+ sprintf(file, "%s/%s", _PATH_MAILDIR, pwd->pw_name);
strlcpy(home, pwd->pw_dir, sizeof(home));
gr = GETGRGID(pwd->pw_gid);
if (gr != NULL)
@@ -811,7 +815,7 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args)
*/
if (mode == M_ADD) {
if (!PWALTDIR()) {
- snprintf(line, sizeof(line), "%s/%s", _PATH_MAILDIR, pwd->pw_name);
+ sprintf(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);
@@ -955,7 +959,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) {
- snprintf(tmp, sizeof(tmp), "%u", prefer);
+ sprintf(tmp, "%lu", (unsigned long) prefer);
addarg(&grpargs, 'g', tmp);
}
if (getarg(args, 'N'))
@@ -1018,16 +1022,17 @@ 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);
-
- 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 arg->val;
+ else {
+ static char home[128];
- return (home);
+ if (cnf->home == NULL || *cnf->home == '\0')
+ errx(EX_CONFIG, "no base home directory set");
+ sprintf(home, "%s/%s", cnf->home, user);
+ return home;
+ }
}
static char *
@@ -1048,12 +1053,12 @@ shell_path(char const * path, char *shells[], char *sh)
static char shellpath[256];
if (sh != NULL) {
- snprintf(shellpath, sizeof(shellpath), "%s/%s", p, sh);
+ sprintf(shellpath, "%s/%s", p, sh);
if (access(shellpath, X_OK) == 0)
return shellpath;
} else
for (i = 0; i < _UC_MAXSHELLS && shells[i] != NULL; i++) {
- snprintf(shellpath, sizeof(shellpath), "%s/%s", p, shells[i]);
+ sprintf(shellpath, "%s/%s", p, shells[i]);
if (access(shellpath, X_OK) == 0)
return shellpath;
}
@@ -1303,7 +1308,7 @@ rmat(uid_t uid)
st.st_uid == uid) {
char tmp[MAXPATHLEN];
- snprintf(tmp, sizeof(tmp), "/usr/bin/atrm %s", e->d_name);
+ sprintf(tmp, "/usr/bin/atrm %s", e->d_name);
system(tmp);
}
}
diff --git a/pw/pwupd.c b/pw/pwupd.c
index 710e901..c2a9a53 100644
--- a/pw/pwupd.c
+++ b/pw/pwupd.c
@@ -33,6 +33,7 @@ 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>
@@ -51,13 +52,12 @@ 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,20 +66,23 @@ getpwpath(char const * file)
static char pathbuf[MAXPATHLEN];
snprintf(pathbuf, sizeof pathbuf, "%s/%s", pwpath, file);
-
- return (pathbuf);
+ return pathbuf;
}
static int
-pwdb_check(void)
+pwdb(char *arg,...)
{
int i = 0;
pid_t pid;
+ va_list ap;
char *args[10];
args[i++] = _PATH_PWD_MKDB;
- args[i++] = "-C";
-
+ va_start(ap, arg);
+ while (i < 6 && arg != NULL) {
+ args[i++] = arg;
+ arg = va_arg(ap, char *);
+ }
if (pwpath != pathpwd) {
args[i++] = "-d";
args[i++] = pwpath;
@@ -97,66 +100,65 @@ pwdb_check(void)
if (WEXITSTATUS(i))
i = EIO;
}
-
- return (i);
+ va_end(ap);
+ return i;
}
static int
pw_update(struct passwd * pwd, char const * user)
{
- 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) {
+ 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);
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);
- pw_fini();
-
- return (0);
+ 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
@@ -165,6 +167,5 @@ 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 d6e39ce..200ffee 100644
--- a/pw/pwupd.h
+++ b/pw/pwupd.h
@@ -112,7 +112,10 @@ 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 37d9c71..6bc9433 100644
--- a/pw/tests/Makefile
+++ b/pw/tests/Makefile
@@ -5,18 +5,10 @@ TESTSRC= ${.CURDIR}/../../../contrib/netbsd-tests/usr.sbin/useradd
TESTSDIR= ${TESTSBASE}/usr.sbin/pw
-ATF_TESTS_SH= pw_etcdir \
- pw_lock \
- pw_groupdel \
- pw_groupmod \
- pw_useradd \
- pw_userdel \
- pw_usermod \
- pw_usernext
+ATF_TESTS_SH= pw_delete pw_lock pw_modify pw_etcdir
-.for tp in ${ATF_TESTS_SH}
-TEST_METADATA.${tp}+= required_user="root"
-.endfor
+TEST_METADATA.pw_delete+= required_user="root"
+TEST_METADATA.pw_modify+= required_user="root"
FILES= group helper_functions.shin master.passwd
FILESDIR= ${TESTSDIR}
diff --git a/pw/tests/helper_functions.shin b/pw/tests/helper_functions.shin
index 3680dfe..f87b1e7 100755
--- a/pw/tests/helper_functions.shin
+++ b/pw/tests/helper_functions.shin
@@ -1,8 +1,5 @@
# $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
new file mode 100755
index 0000000..02a9ade
--- /dev/null
+++ b/pw/tests/pw_delete.sh
@@ -0,0 +1,47 @@
+# $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
deleted file mode 100755
index 75b063a..0000000
--- a/pw/tests/pw_groupdel.sh
+++ /dev/null
@@ -1,24 +0,0 @@
-# $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_lock.sh b/pw/tests/pw_lock.sh
index 9f14e24..070a6f9 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} useradd test || atf_fail "Creating test user"
- ${PW} lock test || atf_fail "Locking the user"
+ pw -V ${HOME} useradd test || atf_fail "Creating test user"
+ pw -V ${HOME} 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} unlock test || atf_fail "Locking the user"
+ pw -V ${HOME} 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_groupmod.sh b/pw/tests/pw_modify.sh
index ad7ad0a..b81f105 100755
--- a/pw/tests/pw_groupmod.sh
+++ b/pw/tests/pw_modify.sh
@@ -8,11 +8,11 @@
atf_test_case groupmod_user
groupmod_user_body() {
populate_etc_skel
- atf_check -s exit:0 ${PW} addgroup test
- atf_check -s exit:0 ${PW} groupmod test -m root
+ 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 -o match:"^test:\*:1001:root$" \
grep "^test:\*:.*:root$" $HOME/group
- atf_check -s exit:0 ${PW} groupmod test -d root
+ atf_check -s exit:0 pw -V ${HOME} 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} 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_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_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} 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_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_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} 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_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_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} groupadd testgroup
- atf_check -s exit:0 -x ${PW} groupmod testgroup -g 12345
+ atf_check -s exit:0 -x pw -V ${HOME} groupadd testgroup
+ atf_check -s exit:0 -x pw -V ${HOME} 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_useradd.sh b/pw/tests/pw_useradd.sh
deleted file mode 100755
index 48612ed..0000000
--- a/pw/tests/pw_useradd.sh
+++ /dev/null
@@ -1,188 +0,0 @@
-# $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
deleted file mode 100755
index 71a7033..0000000
--- a/pw/tests/pw_userdel.sh
+++ /dev/null
@@ -1,37 +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} 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
deleted file mode 100755
index 88bd316..0000000
--- a/pw/tests/pw_usermod.sh
+++ /dev/null
@@ -1,112 +0,0 @@
-# $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
deleted file mode 100755
index 89f938e..0000000
--- a/pw/tests/pw_usernext.sh
+++ /dev/null
@@ -1,45 +0,0 @@
-# $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
-}