2 ** Copyright 1998 - 2006 Double Precision, Inc.
3 ** See COPYING for distribution information.
19 #if TIME_WITH_SYS_TIME
33 #include "libhmac/hmac.h"
48 #if NEED_CRYPT_PROTOTYPE
49 extern char *crypt(const char *, const char *);
53 extern char userdb_hex64
[];
56 extern void userdb_get_random(char *buf
, unsigned n
);
61 char *userdb_mkmd5pw(const char *);
66 ** Where possible, we turn off echo when entering the password.
67 ** We set up a signal handler to catch signals and restore the echo
72 static struct termios tios
;
75 static RETSIGTYPE
sighandler(int signum
)
77 if (write(1, "\n", 1) < 0)
78 ; /* ignore gcc warning */
79 tcsetattr(0, TCSANOW
, &tios
);
81 #if RETSIGTYPE != void
87 static void read_pw(char *buf
)
92 while ((c
=getchar()) != EOF
&& c
!= '\n')
95 if (c
== EOF
&& n
== 0) exit(1);
99 int main(int argc
, char **argv
)
106 struct hmac_hashinfo
*hmac
=0;
111 if (strcmp(argv
[n
], "-md5") == 0)
118 if (strncmp(argv
[n
], "-hmac-", 6) == 0)
122 for (i
=0; hmac_list
[i
] &&
123 strcmp(hmac_list
[i
]->hh_name
, argv
[n
]+6); i
++)
133 fprintf(stderr
, "%s: invalid argument.\n", argv
[0]);
137 /* Read the password */
141 if (tcgetattr(0, &tios
) == 0)
143 struct termios tios2
;
147 signal(SIGINT
, sighandler
);
148 signal(SIGHUP
, sighandler
);
150 tios2
.c_lflag
&= ~ECHO
;
151 tcsetattr(0, TCSANOW
, &tios2
);
155 if (write(2, "Password: ", 10) < 0)
156 ; /* ignore gcc warning */
158 if (write(2, "\nReenter password: ", 19) < 0)
159 ; /* ignore gcc warning */
161 if (strcmp(buf
, buf2
) == 0) break;
162 if (write(2, "\nPasswords don't match.\n\n", 25) < 0)
163 ; /* ignore gcc warning */
174 if (write(2, "\n", 1) < 0)
175 ; /* ignore gcc warning */
177 tcsetattr(0, TCSANOW
, &tios
);
178 signal(SIGINT
, SIG_DFL
);
179 signal(SIGHUP
, SIG_DFL
);
183 /* Set the password */
188 unsigned char *p
=malloc(hmac
->hh_L
*2);
197 hmac_hashkey(hmac
, buf
, strlen(buf
), p
, p
+hmac
->hh_L
);
198 for (i
=0; i
<hmac
->hh_L
*2; i
++)
199 printf("%02x", (int)p
[i
]);
215 printf("%s\n", userdb_mkmd5pw(buf
));
220 userdb_get_random(salt
, 2);
221 salt
[0]=userdb_hex64
[salt
[0] & 63];
222 salt
[1]=userdb_hex64
[salt
[0] & 63];
241 salt
[0]=userdb_hex64
[(unsigned)salt
[0]];
242 salt
[1]=userdb_hex64
[(unsigned)salt
[1]];
247 printf("%s\n", crypt(buf
, salt
));