opieinfo.c revision 78644
1/*
2opieinfo: Print a user's current OPIE sequence number and seed
3
4%%% portions-copyright-cmetz-96
5Portions of this software are Copyright 1996-1998 by Craig Metz, All Rights
6Reserved. The Inner Net License Version 2 applies to these portions of
7the software.
8You should have received a copy of the license with this software. If
9you didn't get a copy, you may request one from <license@inner.net>.
10
11Portions of this software are Copyright 1995 by Randall Atkinson and Dan
12McDonald, All Rights Reserved. All Rights under this copyright are assigned
13to the U.S. Naval Research Laboratory (NRL). The NRL Copyright Notice and
14License Agreement applies to this software.
15
16	History:
17
18	Modified by cmetz for OPIE 2.3. Removed unneeded debug message.
19	Modified by cmetz for OPIE 2.2. Use FUNCTION definition et al.
20               Fixed include order. Make everything static. Ifdef around
21               some headers.
22        Modified at NRL for OPIE 2.1. Substitute @@KEY_FILE@@. Re-write in
23	       C.
24        Modified at NRL for OPIE 2.01. Remove hard-coded paths for grep and
25               awk and let PATH take care of it. Substitute for Makefile
26               variables $(EXISTS) and $(KEY_FILE). Only compute $WHO if
27               there's a key file. Got rid of grep since awk can do the job
28               itself.
29	Modified at NRL for OPIE 2.0.
30	Written at Bellcore for the S/Key Version 1 software distribution
31		(keyinfo)
32
33$FreeBSD: head/contrib/opie/opieinfo.c 78644 2001-06-23 04:48:59Z ache $
34
35*/
36
37#include "opie_cfg.h"
38#include <stdio.h>
39#if HAVE_UNISTD_H
40#include <unistd.h>
41#endif /* HAVE_UNISTD_H */
42#include "opie.h"
43
44/* extern char *optarg; */
45extern int errno, optind;
46
47static char *getusername FUNCTION_NOARGS
48{
49  char *login;
50
51  login = getlogin();
52  if (login == NULL) {
53    fprintf(stderr, "Cannot find login name\n");
54    exit(1);
55  }
56  return login;
57}
58
59int main FUNCTION((argc, argv), int argc AND char *argv[])
60{
61  char *username;
62  struct opie opie;
63  int i;
64
65  while ((i = getopt(argc, argv, "hv")) != EOF) {
66    switch (i) {
67    case 'v':
68      opieversion();
69    case 'h':
70    default:
71      fprintf(stderr, "usage: %s [-h] [-v] [user_name]\n", argv[0]);
72      exit(0);
73    }
74  }
75
76  if (optind < argc) {
77    if (getuid() != 0) {
78      fprintf(stderr, "Only superuser may get another user's keys\n");
79      exit(1);
80    }
81    username = argv[optind];
82  } else
83    username = getusername();
84
85  if ((i = opielookup(&opie, username)) && (i != 2)) {
86    if (i < 0)
87      fprintf(stderr, "Error opening database! (errno = %d)\n", errno);
88    else
89      fprintf(stderr, "%s not found in database.\n", username);
90    exit(1);
91  }
92
93  printf("%d %s\n", opie.opie_n - 1, opie.opie_seed);
94
95  return 0;
96}
97