Annotation of 43BSDTahoe/etc/mkpasswd.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1980, 1983 Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * Redistribution and use in source and binary forms are permitted
                      6:  * provided that the above copyright notice and this paragraph are
                      7:  * duplicated in all such forms and that any documentation,
                      8:  * advertising materials, and other materials related to such
                      9:  * distribution and use acknowledge that the software was developed
                     10:  * by the University of California, Berkeley.  The name of the
                     11:  * University may not be used to endorse or promote products derived
                     12:  * from this software without specific prior written permission.
                     13:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
                     14:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
                     15:  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     16:  */
                     17: 
                     18: #ifndef lint
                     19: char copyright[] =
                     20: "@(#) Copyright (c) 1980, 1983 Regents of the University of California.\n\
                     21:  All rights reserved.\n";
                     22: #endif /* not lint */
                     23: 
                     24: #ifndef lint
                     25: static char sccsid[] = "@(#)mkpasswd.c 5.3 (Berkeley) 6/18/88";
                     26: #endif /* not lint */
                     27: 
                     28: #include <sys/file.h>
                     29: #include <stdio.h>
                     30: #include <pwd.h>
                     31: #include <ndbm.h>
                     32: 
                     33: main(argc, argv)
                     34:        int argc;
                     35:        char *argv[];
                     36: {
                     37:        DBM *dp;
                     38:        datum key, content;
                     39:        register char *cp, *tp;
                     40:        register struct passwd *pwd;
                     41:        int verbose = 0, entries = 0, maxlen = 0;
                     42:        char buf[BUFSIZ];
                     43: 
                     44:        if (argc > 1 && strcmp(argv[1], "-v") == 0) {
                     45:                verbose++;
                     46:                argv++, argc--;
                     47:        }
                     48:        if (argc != 2) {
                     49:                fprintf(stderr, "usage: mkpasswd [ -v ] file\n");
                     50:                exit(1);
                     51:        }
                     52:        if (access(argv[1], R_OK) < 0) {
                     53:                fprintf(stderr, "mkpasswd: ");
                     54:                perror(argv[1]);
                     55:                exit(1);
                     56:        }
                     57:        (void)umask(0);
                     58:        dp = dbm_open(argv[1], O_WRONLY|O_CREAT|O_EXCL, 0644);
                     59:        if (dp == NULL) {
                     60:                fprintf(stderr, "mkpasswd: ");
                     61:                perror(argv[1]);
                     62:                exit(1);
                     63:        }
                     64:        setpwfile(argv[1]);
                     65:        while (pwd = getpwent()) {
                     66:                cp = buf;
                     67: #define        COMPACT(e)      tp = pwd->e; while (*cp++ = *tp++);
                     68:                COMPACT(pw_name);
                     69:                COMPACT(pw_passwd);
                     70:                bcopy((char *)&pwd->pw_uid, cp, sizeof (int));
                     71:                cp += sizeof (int);
                     72:                bcopy((char *)&pwd->pw_gid, cp, sizeof (int));
                     73:                cp += sizeof (int);
                     74:                bcopy((char *)&pwd->pw_quota, cp, sizeof (int));
                     75:                cp += sizeof (int);
                     76:                COMPACT(pw_comment);
                     77:                COMPACT(pw_gecos);
                     78:                COMPACT(pw_dir);
                     79:                COMPACT(pw_shell);
                     80:                content.dptr = buf;
                     81:                content.dsize = cp - buf;
                     82:                if (verbose)
                     83:                        printf("store %s, uid %d\n", pwd->pw_name, pwd->pw_uid);
                     84:                key.dptr = pwd->pw_name;
                     85:                key.dsize = strlen(pwd->pw_name);
                     86:                if (dbm_store(dp, key, content, DBM_INSERT) < 0) {
                     87:                        fprintf(stderr, "mkpasswd: ");
                     88:                        perror("dbm_store failed");
                     89:                        exit(1);
                     90:                }
                     91:                key.dptr = (char *)&pwd->pw_uid;
                     92:                key.dsize = sizeof (int);
                     93:                if (dbm_store(dp, key, content, DBM_INSERT) < 0) {
                     94:                        fprintf(stderr, "mkpasswd: ");
                     95:                        perror("dbm_store failed");
                     96:                        exit(1);
                     97:                }
                     98:                entries++;
                     99:                if (cp - buf > maxlen)
                    100:                        maxlen = cp - buf;
                    101:        }
                    102:        dbm_close(dp);
                    103:        printf("%d password entries, maximum length %d\n", entries, maxlen);
                    104:        exit(0);
                    105: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.