2e6628523003e471cb5e5f0b9d67d7b4a7863979
* Copyright (c) 1988, 1993
* The Regents of the University of California. All rights reserved.
* %sccs.include.redist.c%
static char copyright
[] =
"@(#) Copyright (c) 1988, 1993\n\
The Regents of the University of California. All rights reserved.\n";
static char sccsid
[] = "@(#)chpass.c 8.2 (Berkeley) %G%";
#include <sys/resource.h>
char *progname
= "chpass";
void baduser
__P((void));
enum { NEWSH
, LOADENTRY
, EDITENTRY
} op
;
while ((ch
= getopt(argc
, argv
, "a:s:")) != EOF
)
if (op
== EDITENTRY
|| op
== NEWSH
)
if (!(pw
= getpwuid(uid
)))
errx(1, "unknown user: uid %u", uid
);
if (!(pw
= getpwnam(*argv
)))
errx(1, "unknown user: %s", *argv
);
if (uid
&& uid
!= pw
->pw_uid
)
/* protect p_shell -- it thinks NULL is /bin/sh */
if (p_shell(arg
, pw
, (ENTRY
*)NULL
))
pw_error((char *)NULL
, 0, 1);
* The temporary file/file descriptor usage is a little tricky here.
* 1: We start off with two fd's, one for the master password
* file (used to lock everything), and one for a temporary file.
* 2: Display() gets an fp for the temporary file, and copies the
* user's information into it. It then gives the temporary file
* to the user and closes the fp, closing the underlying fd.
* 3: The user edits the temporary file some number of times.
* 4: Verify() gets an fp for the temporary file, and verifies the
* contents. It can't use an fp derived from the step #2 fd,
* because the user's editor may have created a new instance of
* the file. Once the file is verified, its contents are stored
* in a password structure. The verify routine closes the fp,
* closing the underlying fd.
* 5: Delete the temporary file.
* 6: Get a new temporary file/fd. Pw_copy() gets an fp for it
* file and copies the master password file into it, replacing
* the user record with a new one. We can't use the first
* temporary file for this because it was owned by the user.
* Pw_copy() closes its fp, flushing the data and closing the
* underlying file descriptor. We can't close the master
* password fp, or we'd lose the lock.
* 7: Call pw_mkdb() (which renames the temporary file) and exit.
* The exit closes the master passwd fp/fd.
pw_error((char *)NULL
, 0, 1);
errx(1, "%s", strerror(EACCES
));
(void)fprintf(stderr
, "usage: chpass [-a list] [-s shell] [user]\n");