]> granicus.if.org Git - linux-pam/blob - modules/pam_pwdb/pam_unix_md.-c
d9b2c51b205a2a7cc0cdc87315c92eca7797e347
[linux-pam] / modules / pam_pwdb / pam_unix_md.-c
1 /*
2  * This function is a front-end for the message digest algorithms used
3  * to compute the user's encrypted passwords. No reversible encryption
4  * is used here and I intend to keep it that way.
5  *
6  * While there are many sources of encryption outside the United
7  * States, it *may* be illegal to re-export reversible encryption
8  * computer code. Until such time as it is legal to export encryption
9  * software freely from the US, please do not send me any. (AGM)
10  */
11
12 /* this should have been defined in a header file.. Why wasn't it? AGM */
13 extern char *crypt(const char *key, const char *salt);
14
15 #include "md5.h"
16 #include "bigcrypt.-c"
17
18 struct cfns {
19     const char *salt;
20     int len;
21     char * (* mdfn)(const char *key, const char *salt);
22 };
23
24 /* array of non-standard digest algorithms available */
25
26 #define N_MDS 1
27 const static struct cfns cfn_list[N_MDS] = {
28     { "$1$", 3, Goodcrypt_md5 },
29 };
30
31 static char *_pam_md(const char *key, const char *salt)
32 {
33     char *x,*e=NULL;
34     int i;
35
36     D(("called with key='%s', salt='%s'", key, salt));
37
38     /* check for non-standard salts */
39
40     for (i=0; i<N_MDS; ++i) {
41         if ( !strncmp(cfn_list[i].salt, salt, cfn_list[i].len) ) {
42             e = cfn_list[i].mdfn(key, salt);
43             break;
44         }
45     }
46
47     if ( i >= N_MDS ) {
48         e = bigcrypt(key, salt);      /* (defaults to standard algorithm) */
49     }
50
51     x = x_strdup(e);                        /* put e in malloc()ed memory */
52     _pam_overwrite(e);                                        /* clean up */
53     return x;                           /* this must be deleted elsewhere */
54 }
55
56 #ifndef PWDB_NO_MD_COMPAT
57 static char *_pam_md_compat(const char *key, const char *salt)
58 {
59     char *x,*e=NULL;
60
61     D(("called with key='%s', salt='%s'", key, salt));
62
63     if ( !strncmp("$1$", salt, 3) ) {
64         e = Brokencrypt_md5(key, salt);
65         x = x_strdup(e);                    /* put e in malloc()ed memory */
66         _pam_overwrite(e);                                    /* clean up */
67     } else {
68         x = x_strdup("*");
69     }
70
71     return x;                           /* this must be deleted elsewhere */
72 }
73 #endif /* PWDB_NO_MD_COMPAT */