This commit sets new users to see the DragonFly-tips fortunes instead
[dragonfly.git] / contrib / opie / opiegen.c
blobd48ee093289037264a9e5534bea1521bcb2540c0
1 /* opiegen.c: Sample OTP generator based on the opiegenerator()
2 library routine.
4 %%% portions-copyright-cmetz-96
5 Portions of this software are Copyright 1996-1999 by Craig Metz, All Rights
6 Reserved. The Inner Net License Version 2 applies to these portions of
7 the software.
8 You should have received a copy of the license with this software. If
9 you didn't get a copy, you may request one from <license@inner.net>.
11 History:
13 Modified by cmetz for OPIE 2.3. OPIE_PASS_MAX changed to
14 OPIE_SECRET_MAX. Send debug info to syslog.
15 Modified by cmetz for OPIE 2.2. Use FUNCTION definition et al.
16 Fixed include order.
17 Created at NRL for OPIE 2.2.
19 #include "opie_cfg.h"
20 #include <stdio.h>
21 #if DEBUG
22 #include <syslog.h>
23 #endif /* DEBUG */
24 #include "opie.h"
26 int main FUNCTION((argc, argv), int argc AND char *argv[])
28 char buffer[OPIE_CHALLENGE_MAX+1];
29 char secret[OPIE_SECRET_MAX+1];
30 char response[OPIE_RESPONSE_MAX+1];
31 int result;
33 if (opieinsecure()) {
34 fputs("Sorry, but you don't seem to be on a secure terminal.\n", stderr);
35 #if !DEBUG
36 exit(1);
37 #endif /* !DEBUG */
40 if (argc <= 1) {
41 fputs("Challenge: ", stderr);
42 if (!opiereadpass(buffer, sizeof(buffer)-1, 1))
43 fprintf(stderr, "Error reading challenge!");
44 } else {
45 char *ap, *ep, *c;
46 int i;
48 ep = buffer + sizeof(buffer) - 1;
49 for (i = 1, ap = buffer; (i < argc) && (ap < ep); i++) {
50 c = argv[i];
51 while ((*(ap++) = *(c++)) && (ap < ep));
52 *(ap - 1) = ' ';
54 *(ap - 1) = 0;
55 #if DEBUG
56 syslog(LOG_DEBUG, "opiegen: challenge is +%s+\n", buffer);
57 #endif /* DEBUG */
59 buffer[sizeof(buffer)-1] = 0;
61 fputs("Secret pass phrase: ", stderr);
62 if (!opiereadpass(secret, OPIE_SECRET_MAX, 0)) {
63 fputs("Error reading secret pass phrase!\n", stderr);
64 exit(1);
67 switch (result = opiegenerator(buffer, secret, response)) {
68 case -2:
69 fputs("Not a valid OTP secret pass phrase.\n", stderr);
70 break;
71 case -1:
72 fputs("Error processing challenge!\n", stderr);
73 break;
74 case 1:
75 fputs("Not a valid OTP challenge.\n", stderr);
76 break;
77 case 0:
78 fputs(response, stdout);
79 fputc('\n', stdout);
80 fflush(stdout);
81 memset(secret, 0, sizeof(secret));
82 exit(0);
83 default:
84 fprintf(stderr, "Unknown error %d!\n", result);
86 memset(secret, 0, sizeof(secret));
87 return 1;