1 | /* |
1 | /* |
2 | * crypto.C: Cryptographic module support. |
2 | * crypto.C: Cryptographic module support. |
3 | * Rights to this code are documented in doc/pod/license.pod. |
3 | * Rights to this code are documented in doc/pod/license.pod. |
4 | * |
4 | * |
5 | * Copyright © 2005-2007 Atheme Project (http://www.atheme.org) |
5 | * Copyright © 2005-2007 Atheme Project (http://www.atheme.org) |
6 | */ |
6 | */ |
7 | |
7 | |
8 | static char const rcsid[] = "$Id: crypto.C,v 1.3 2007/07/21 13:23:21 pippijn Exp $"; |
8 | static char const rcsid[] = "$Id: crypto.C,v 1.4 2007/08/28 17:08:12 pippijn Exp $"; |
9 | |
9 | |
10 | #include "atheme.h" |
10 | #include "atheme.h" |
|
|
11 | #include <ermyth/crypto.h> |
11 | |
12 | |
12 | static char saltbuf[BUFSIZE]; |
13 | static char saltbuf[BUFSIZE]; |
13 | bool crypto_module_loaded = false; |
14 | bool crypto::handler::loaded = false; |
14 | |
15 | |
15 | /* |
16 | /* |
16 | * crypt_string is just like crypt(3) under UNIX |
17 | * crypto::handler::crypt is just like crypt(3) under UNIX |
17 | * systems. Modules provide this function, otherwise |
18 | * systems. Modules provide this function, otherwise |
18 | * it returns the string unencrypted. |
19 | * it returns the string unencrypted. |
19 | */ |
20 | */ |
20 | char *(*crypt_string) (char *str, char *salt) = &generic_crypt_string; |
21 | namespace crypto |
|
|
22 | { |
|
|
23 | char const * |
|
|
24 | handler::crypt (char const * const str, char const * const salt) |
|
|
25 | { |
|
|
26 | return str; |
|
|
27 | } |
21 | |
28 | |
|
|
29 | /* |
|
|
30 | * crypt_verify_password is a frontend to crypt_string(). |
|
|
31 | */ |
|
|
32 | bool |
|
|
33 | verify_password (char const * const uinput, char const * const pass) |
|
|
34 | { |
|
|
35 | char const * const cstr = crypt (uinput, pass); |
|
|
36 | |
|
|
37 | if (!strcmp (cstr, pass)) |
|
|
38 | return true; |
|
|
39 | |
|
|
40 | return false; |
|
|
41 | } |
|
|
42 | |
22 | char * |
43 | char * |
23 | generic_crypt_string (char *str, char *salt) |
44 | gen_salt (void) |
24 | { |
45 | { |
25 | return str; |
46 | char *ht = gen_pw (6); |
26 | } |
47 | |
|
|
48 | strlcpy (saltbuf, "$1$", BUFSIZE); |
|
|
49 | strlcat (saltbuf, ht, BUFSIZE); |
|
|
50 | strlcat (saltbuf, "$", BUFSIZE); |
|
|
51 | |
|
|
52 | sfree (ht); |
27 | |
53 | |
28 | /* |
|
|
29 | * crypt_verify_password is a frontend to crypt_string(). |
|
|
30 | */ |
|
|
31 | bool |
|
|
32 | crypt_verify_password (char *uinput, char *pass) |
|
|
33 | { |
|
|
34 | char *cstr = crypt_string (uinput, pass); |
|
|
35 | |
|
|
36 | if (!strcmp (cstr, pass)) |
|
|
37 | return true; |
|
|
38 | |
|
|
39 | return false; |
|
|
40 | } |
|
|
41 | |
|
|
42 | char * |
|
|
43 | gen_salt (void) |
|
|
44 | { |
|
|
45 | char *ht = gen_pw (6); |
|
|
46 | |
|
|
47 | strlcpy (saltbuf, "$1$", BUFSIZE); |
|
|
48 | strlcat (saltbuf, ht, BUFSIZE); |
|
|
49 | strlcat (saltbuf, "$", BUFSIZE); |
|
|
50 | |
|
|
51 | free (ht); |
|
|
52 | |
|
|
53 | return saltbuf; |
54 | return saltbuf; |
54 | } |
55 | } |
55 | |
56 | } // namespace crypto |
56 | /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs |
|
|
57 | * vim:ts=8 |
|
|
58 | * vim:sw=8 |
|
|
59 | * vim:noexpandtab |
|
|
60 | */ |
|
|