[BACK]Return to skeyinfo.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / skeyinfo

Annotation of src/usr.bin/skeyinfo/skeyinfo.c, Revision 1.14

1.14    ! millert     1: /*     $OpenBSD: skeyinfo.c,v 1.13 2003/06/10 22:20:51 deraadt Exp $   */
1.1       millert     2:
                      3: /*
1.10      millert     4:  * Copyright (c) 1997, 2001, 2002 Todd C. Miller <Todd.Miller@courtesan.com>
1.1       millert     5:  *
1.12      millert     6:  * Permission to use, copy, modify, and distribute this software for any
                      7:  * purpose with or without fee is hereby granted, provided that the above
                      8:  * copyright notice and this permission notice appear in all copies.
1.1       millert     9:  *
1.14    ! millert    10:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
        !            11:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
        !            12:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
        !            13:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
        !            14:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
        !            15:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
        !            16:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
        !            17:  *
        !            18:  * Sponsored in part by the Defense Advanced Research Projects
        !            19:  * Agency (DARPA) and Air Force Research Laboratory, Air Force
        !            20:  * Materiel Command, USAF, under agreement number F39502-99-1-0512.
1.1       millert    21:  */
                     22:
                     23: #include <err.h>
1.10      millert    24: #include <limits.h>
                     25: #include <paths.h>
1.1       millert    26: #include <pwd.h>
                     27: #include <stdio.h>
1.10      millert    28: #include <stdlib.h>
1.1       millert    29: #include <string.h>
                     30: #include <unistd.h>
                     31: #include <skey.h>
                     32:
                     33: extern char *__progname;
                     34:
1.9       millert    35: void usage(void);
1.1       millert    36:
                     37: int
1.9       millert    38: main(int argc, char **argv)
1.1       millert    39: {
                     40:        struct passwd *pw;
1.10      millert    41:        struct skey key;
                     42:        char *name = NULL;
                     43:        int error, ch, verbose = 0;
                     44:
                     45:        while ((ch = getopt(argc, argv, "v")) != -1)
1.1       millert    46:                switch(ch) {
                     47:                case 'v':
                     48:                        verbose = 1;
                     49:                        break;
                     50:                default:
                     51:                        usage();
                     52:        }
                     53:        argc -= optind;
                     54:        argv += optind;
                     55:
                     56:        if (argc == 1)
                     57:                name = argv[0];
                     58:        else if (argc > 1)
                     59:                usage();
                     60:
                     61:        if (name && getuid() != 0)
                     62:                errx(1, "only root may specify an alternate user");
                     63:
                     64:        if (name) {
                     65:                if ((pw = getpwnam(name)) == NULL)
                     66:                        errx(1, "no passwd entry for %s", name);
                     67:        } else {
                     68:                if ((pw = getpwuid(getuid())) == NULL)
                     69:                        errx(1, "no passwd entry for uid %u", getuid());
                     70:        }
                     71:
                     72:        if ((name = strdup(pw->pw_name)) == NULL)
                     73:                err(1, "cannot allocate memory");
1.11      mpech      74:        sevenbit(name);
1.1       millert    75:
1.10      millert    76:        error = skeylookup(&key, name);
                     77:        switch (error) {
                     78:                case 0:         /* Success! */
                     79:                        if (verbose)
                     80:                                (void)printf("otp-%s ", skey_get_algorithm());
                     81:                        (void)printf("%d %s\n", key.n - 1, key.seed);
                     82:                        break;
                     83:                case -1:        /* File error */
                     84:                        err(1, "cannot open %s/%s", _PATH_SKEYDIR, name);
                     85:                        break;
                     86:                case 1:         /* Unknown user */
                     87:                        errx(1, "%s is not listed in %s", name, _PATH_SKEYDIR);
                     88:                        break;
1.1       millert    89:        }
1.10      millert    90:        (void)fclose(key.keyfile);
1.1       millert    91:
1.10      millert    92:        exit(error ? 1 : 0);
1.1       millert    93: }
                     94:
                     95: void
1.13      deraadt    96: usage(void)
1.1       millert    97: {
1.10      millert    98:        (void)fprintf(stderr, "usage: %s [-v] [user]\n", __progname);
1.1       millert    99:        exit(1);
                    100: }