#include "c.h"
-extern int xmkstemp(char **tmpname, char *dir);
+extern int xmkstemp(char **tmpname, const char *dir, const char *prefix);
-static inline FILE *xfmkstemp(char **tmpname, char *dir)
+static inline FILE *xfmkstemp(char **tmpname, const char *dir, const char *prefix)
{
int fd;
FILE *ret;
- fd = xmkstemp(tmpname, dir);
+ fd = xmkstemp(tmpname, dir, prefix);
if (fd == -1)
return NULL;
/* Create open temporary file in safe way. Please notice that the
* file permissions are -rw------- by default. */
-int xmkstemp(char **tmpname, char *dir)
+int xmkstemp(char **tmpname, const char *dir, const char *prefix)
{
char *localtmp;
- char *tmpenv;
+ const char *tmpenv;
mode_t old_mode;
int fd, rc;
/* Some use cases must be capable of being moved atomically
* with rename(2), which is the reason why dir is here. */
- if (dir != NULL)
- tmpenv = dir;
- else
- tmpenv = getenv("TMPDIR");
-
- if (tmpenv)
- rc = asprintf(&localtmp, "%s/%s.XXXXXX", tmpenv,
- program_invocation_short_name);
- else
- rc = asprintf(&localtmp, "%s/%s.XXXXXX", _PATH_TMP,
- program_invocation_short_name);
+ tmpenv = dir ? dir : getenv("TMPDIR");
+ if (!tmpenv)
+ tmpenv = _PATH_TMP;
+ rc = asprintf(&localtmp, "%s/%s.XXXXXX", tmpenv, prefix);
if (rc < 0)
return -1;
{
FILE *f;
char *tmpname;
- f = xfmkstemp(&tmpname, NULL);
+ f = xfmkstemp(&tmpname, NULL, "test");
unlink(tmpname);
free(tmpname);
fclose(f);
#else /* HAVE_LIBUSER */
/* write the new struct passwd to the passwd file. */
ctl->pw->pw_gecos = gecos;
- if (setpwnam(ctl->pw) < 0) {
+ if (setpwnam(ctl->pw, ".chfn") < 0) {
warn("setpwnam failed");
#endif
printf(_
errx(EXIT_FAILURE, _("Shell *NOT* changed. Try again later."));
#else
pw->pw_shell = info.shell;
- if (setpwnam(pw) < 0)
+ if (setpwnam(pw, ".chsh") < 0)
err(EXIT_FAILURE, _("setpwnam failed\n"
"Shell *NOT* changed. Try again later."));
#endif
* If the given username exists in the passwd file, the entry is
* replaced with the given entry.
*/
-int setpwnam(struct passwd *pwd)
+int setpwnam(struct passwd *pwd, const char *prefix)
{
FILE *fp = NULL, *pwf = NULL;
int save_errno;
int contlen, rc;
char *linebuf = NULL;
char *tmpname = NULL;
- char *atomic_dir = "/etc";
pw_init();
- if ((fp = xfmkstemp(&tmpname, atomic_dir)) == NULL)
+ if ((fp = xfmkstemp(&tmpname, "/etc", prefix)) == NULL)
return -1;
/* ptmp should be owned by root.root or root.wheel */
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*/
+#ifndef UTIL_LINUX_SETPWNAM_H
+#define UTIL_LINUX_SETPWNAM_H
#include "pathnames.h"
# define SGROUP_FILE "/tmp/gshadow"
#endif
-extern int setpwnam (struct passwd *pwd);
+extern int setpwnam (struct passwd *pwd, const char *prefix);
+
+#endif /* UTIL_LINUX_SETPWNAM_H */
{
FILE *fd;
char *tmpname = NULL;
- char *dir = "/etc";
- if ((fd = xfmkstemp(&tmpname, dir)) == NULL) {
+ if ((fd = xfmkstemp(&tmpname, "/etc", ".vipw")) == NULL) {
ulckpwdf();
err(EXIT_FAILURE, _("can't open temporary file"));
}