X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/blobdiff_plain/0dc562ef320aea7c8ce63e8162868ee35079a93a..566238983e493a59134792aac791894850998146:/usr/src/old/mkpasswd/mkpasswd.c diff --git a/usr/src/old/mkpasswd/mkpasswd.c b/usr/src/old/mkpasswd/mkpasswd.c index c51332674d..5cc9e2f403 100644 --- a/usr/src/old/mkpasswd/mkpasswd.c +++ b/usr/src/old/mkpasswd/mkpasswd.c @@ -1,15 +1,32 @@ +/* + * Copyright (c) 1980, 1983 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms are permitted + * provided that this notice is preserved and that due credit is given + * to the University of California at Berkeley. The name of the University + * may not be used to endorse or promote products derived from this + * software without specific prior written permission. This software + * is provided ``as is'' without express or implied warranty. + */ + +#ifndef lint +char copyright[] = +"@(#) Copyright (c) 1980, 1983 Regents of the University of California.\n\ + All rights reserved.\n"; +#endif /* not lint */ + #ifndef lint -static char *sccsid = "@(#)mkpasswd.c 4.2 (Berkeley) 83/12/20"; -#endif +static char sccsid[] = "@(#)mkpasswd.c 5.2 (Berkeley) %G%"; +#endif /* not lint */ #include #include #include #include -char buf[BUFSIZ]; - main(argc, argv) + int argc; char *argv[]; { DBM *dp; @@ -17,6 +34,7 @@ main(argc, argv) register char *cp, *tp; register struct passwd *pwd; int verbose = 0, entries = 0, maxlen = 0; + char buf[BUFSIZ]; if (argc > 1 && strcmp(argv[1], "-v") == 0) { verbose++; @@ -26,42 +44,57 @@ main(argc, argv) fprintf(stderr, "usage: mkpasswd [ -v ] file\n"); exit(1); } - umask(0); - dp = ndbmopen(argv[1], O_WRONLY|O_CREAT|O_EXCL, 0644); + if (access(argv[1], R_OK) < 0) { + fprintf(stderr, "mkpasswd: "); + perror(argv[1]); + exit(1); + } + (void)umask(0); + dp = dbm_open(argv[1], O_WRONLY|O_CREAT|O_EXCL, 0644); if (dp == NULL) { - fprintf(stderr, "dbminit failed: "); + fprintf(stderr, "mkpasswd: "); perror(argv[1]); exit(1); } - dp->db_maxbno = 0; - setpwent(); + setpwfile(argv[1]); while (pwd = getpwent()) { cp = buf; -#define COMPACT(e) tp = pwd->pw_/**/e; while (*cp++ = *tp++); - COMPACT(name); - COMPACT(passwd); - *(int *)cp = pwd->pw_uid; cp += sizeof (int); - *(int *)cp = pwd->pw_gid; cp += sizeof (int); - *(int *)cp = pwd->pw_quota; cp += sizeof (int); - COMPACT(comment); - COMPACT(gecos); - COMPACT(dir); - COMPACT(shell); +#define COMPACT(e) tp = pwd->e; while (*cp++ = *tp++); + COMPACT(pw_name); + COMPACT(pw_passwd); + bcopy((char *)&pwd->pw_uid, cp, sizeof (int)); + cp += sizeof (int); + bcopy((char *)&pwd->pw_gid, cp, sizeof (int)); + cp += sizeof (int); + bcopy((char *)&pwd->pw_quota, cp, sizeof (int)); + cp += sizeof (int); + COMPACT(pw_comment); + COMPACT(pw_gecos); + COMPACT(pw_dir); + COMPACT(pw_shell); content.dptr = buf; content.dsize = cp - buf; if (verbose) printf("store %s, uid %d\n", pwd->pw_name, pwd->pw_uid); key.dptr = pwd->pw_name; key.dsize = strlen(pwd->pw_name); - dbmstore(dp, key, content, DB_INSERT); + if (dbm_store(dp, key, content, DBM_INSERT) < 0) { + fprintf(stderr, "mkpasswd: "); + perror("dbm_store failed"); + exit(1); + } key.dptr = (char *)&pwd->pw_uid; key.dsize = sizeof (int); - dbmstore(dp, key, content, DB_INSERT); + if (dbm_store(dp, key, content, DBM_INSERT) < 0) { + fprintf(stderr, "mkpasswd: "); + perror("dbm_store failed"); + exit(1); + } entries++; if (cp - buf > maxlen) maxlen = cp - buf; } - endpwent(); + dbm_close(dp); printf("%d password entries, maximum length %d\n", entries, maxlen); exit(0); }