* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
* %sccs.include.redist.c%
static char sccsid
[] = "@(#)pw_util.c 8.2 (Berkeley) %G%";
* This file is used by all the "password" programs; vipw(8), chpass(1),
#include <sys/resource.h>
/* Unlimited resource limits. */
rlim
.rlim_cur
= rlim
.rlim_max
= RLIM_INFINITY
;
(void)setrlimit(RLIMIT_CPU
, &rlim
);
(void)setrlimit(RLIMIT_FSIZE
, &rlim
);
(void)setrlimit(RLIMIT_STACK
, &rlim
);
(void)setrlimit(RLIMIT_DATA
, &rlim
);
(void)setrlimit(RLIMIT_RSS
, &rlim
);
/* Don't drop core (not really necessary, but GP's). */
rlim
.rlim_cur
= rlim
.rlim_max
= 0;
(void)setrlimit(RLIMIT_CORE
, &rlim
);
(void)signal(SIGALRM
, SIG_IGN
);
(void)signal(SIGHUP
, SIG_IGN
);
(void)signal(SIGINT
, SIG_IGN
);
(void)signal(SIGPIPE
, SIG_IGN
);
(void)signal(SIGQUIT
, SIG_IGN
);
(void)signal(SIGTERM
, SIG_IGN
);
(void)signal(SIGTSTP
, SIG_IGN
);
(void)signal(SIGTTOU
, SIG_IGN
);
/* Create with exact permissions. */
* If the master password file doesn't exist, the system is hosed.
* Might as well try to build one. Set the close-on-exec bit so
* that users can't get at the encrypted passwords while editing.
* Open should allow flock'ing the file; see 4.4BSD. XXX
lockfd
= open(_PATH_MASTERPASSWD
, O_RDONLY
, 0);
if (lockfd
< 0 || fcntl(lockfd
, F_SETFD
, 1) == -1)
err(1, "%s", _PATH_MASTERPASSWD
);
if (flock(lockfd
, LOCK_EX
|LOCK_NB
))
errx(1, "the password db file is busy");
static char path
[MAXPATHLEN
] = _PATH_MASTERPASSWD
;
if (p
= strrchr(path
, '/'))
if ((fd
= mkstemp(path
)) == -1)
warnx("rebuilding the database...");
execl(_PATH_PWD_MKDB
, "pwd_mkdb", "-p", tempname
, NULL
);
pw_error(_PATH_PWD_MKDB
, 1, 1);
pid
= waitpid(pid
, &pstat
, 0);
if (pid
== -1 || !WIFEXITED(pstat
) || WEXITSTATUS(pstat
) != 0)
if (!(editor
= getenv("EDITOR")))
if (p
= strrchr(editor
, '/'))
execlp(editor
, p
, tempname
, NULL
);
pid
= waitpid(pid
, (int *)&pstat
, 0);
if (pid
== -1 || !WIFEXITED(pstat
) || WEXITSTATUS(pstat
) != 0)
(void)printf("re-edit the password file? [y]: ");
if (c
!= EOF
&& c
!= '\n')
while (getchar() != '\n');
pw_error(name
, err
, eval
)
warnx("%s: unchanged", _PATH_MASTERPASSWD
);