/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
* Copyright (C) 1996
* David L. Nugent. All rights reserved.
*
"$FreeBSD$";
#endif /* not lint */
+#include <sys/wait.h>
+
+#include <err.h>
+#include <errno.h>
+#include <pwd.h>
+#include <libutil.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <pwd.h>
-#include <libutil.h>
-#include <errno.h>
-#include <err.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/param.h>
-#include <sys/wait.h>
#include "pwupd.h"
-static char pathpwd[] = _PATH_PWD;
-static char * pwpath = pathpwd;
-
-int
-setpwdir(const char * dir)
-{
- if (dir == NULL)
- return (-1);
- else
- pwpath = strdup(dir);
- if (pwpath == NULL)
- return (-1);
-
- return (0);
-}
-
char *
getpwpath(char const * file)
{
static char pathbuf[MAXPATHLEN];
- snprintf(pathbuf, sizeof pathbuf, "%s/%s", pwpath, file);
+ snprintf(pathbuf, sizeof pathbuf, "%s/%s", conf.etcpath, file);
return (pathbuf);
}
char *args[10];
args[i++] = _PATH_PWD_MKDB;
- args[i++] = "-C";
+ args[i++] = "-c";
- if (pwpath != pathpwd) {
+ if (strcmp(conf.etcpath, _PATH_PWD) != 0) {
args[i++] = "-d";
- args[i++] = pwpath;
+ args[i++] = conf.etcpath;
}
args[i++] = getpwpath(_MASTERPASSWD);
args[i] = NULL;
if (user != NULL)
old_pw = GETPWNAM(user);
- if (pw_init(pwpath, NULL))
+ if (pw_init(conf.etcpath, NULL))
err(1, "pw_init()");
if ((pfd = pw_lock()) == -1) {
pw_fini();
}
if (pw_copy(pfd, tfd, pw, old_pw) == -1) {
pw_fini();
+ close(tfd);
err(1, "pw_copy()");
}
+ fsync(tfd);
+ close(tfd);
/*
* in case of deletion of a user, the whole database
* needs to be regenerated
int
delpwent(struct passwd * pwd)
{
- char login[MAXLOGNAME];
-
- strlcpy(login, pwd->pw_name, MAXLOGNAME);
- return (pw_update(NULL, login));
+ return (pw_update(NULL, pwd->pw_name));
}