Nuke unused macro and comment
[dragonfly.git] / usr.bin / key / skey.c
bloba3a7c00662fbd36af4bf637275c07967d396a7a3
1 /* Stand-alone program for computing responses to S/Key challenges.
2 * Takes the iteration count and seed as command line args, prompts
3 * for the user's key, and produces both word and hex format responses.
5 * Usage example:
6 * >skey 88 ka9q2
7 * Enter password:
8 * OMEN US HORN OMIT BACK AHOY
9 * C848 666B 6435 0A93
10 * >
12 * $FreeBSD: src/usr.bin/key/skey.c,v 1.6.6.1 2001/03/04 08:35:48 kris Exp $
13 * $DragonFly: src/usr.bin/key/skey.c,v 1.3 2003/10/04 20:36:46 hmp Exp $
16 #include <err.h>
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <unistd.h>
22 #ifdef __MSDOS__
23 #include <dos.h>
24 #else /* Assume BSD Unix */
25 #include <fcntl.h>
26 #endif
28 #include <skey.h>
30 static void usage(void);
32 int
33 main(int argc, char **argv)
35 int n,cnt,i;
36 char passwd[256] /* ,passwd2[256] */;
37 char key[8];
38 char *seed;
39 char buf[33];
40 char *slash;
42 cnt = 1;
43 while((i = getopt(argc,argv,"n:")) != -1){
44 switch(i){
45 case 'n':
46 cnt = atoi(optarg);
47 break;
50 /* could be in the form <number>/<seed> */
51 if(argc <= optind + 1){
52 /*look for / in it */
53 if(argc <= optind)
54 usage();
56 slash = strchr(argv[optind], '/');
57 if(slash == NULL)
58 usage();
59 *slash++ = '\0';
60 seed = slash;
62 if((n = atoi(argv[optind])) < 0){
63 warnx("%s not positive",argv[optind]);
64 usage();
67 else {
69 if((n = atoi(argv[optind])) < 0){
70 warnx("%s not positive",argv[optind]);
71 usage();
73 seed = argv[++optind];
75 fprintf(stderr,"Reminder - Do not use this program while logged in via telnet or rlogin.\n");
77 /* Get user's secret password */
78 for(;;){
79 fprintf(stderr,"Enter secret password: ");
80 readpass(passwd,sizeof(passwd));
81 break;
82 /************
83 fprintf(stderr,"Again secret password: ");
84 readpass(passwd2,sizeof(passwd));
85 if(strcmp(passwd,passwd2) == 0) break;
86 fprintf(stderr, "Sorry no match\n");
87 **************/
91 /* Crunch seed and password into starting key */
92 if(keycrunch(key,seed,passwd) != 0)
93 errx(1, "key crunch failed");
94 if(cnt == 1){
95 while(n-- != 0)
96 f(key);
97 printf("%s\n",btoe(buf,key));
98 #ifdef HEXIN
99 printf("%s\n",put8(buf,key));
100 #endif
101 } else {
102 for(i=0;i<=n-cnt;i++)
103 f(key);
104 for(;i<=n;i++){
105 #ifdef HEXIN
106 printf("%d: %-29s %s\n",i,btoe(buf,key),put8(buf,key));
107 #else
108 printf("%d: %-29s\n",i,btoe(buf,key));
109 #endif
110 f(key);
113 return 0;
116 static void
117 usage(void)
119 fprintf(stderr,"usage: key [-n count] <sequence #>[/] <key>\n");
120 exit(1);