aboutsummaryrefslogtreecommitdiffstats
path: root/security/pam-pgsql/files/patch-md5
blob: 177c2696cd2b753ea3fa3dcf979239fe65cd4eb9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
This patch replaces calls to mhash library with direct calls into -lmd,
greatly simplifying things...

--- pam_pgsql.c Wed Apr 18 16:47:57 2001
+++ pam_pgsql.c Wed Jan  9 14:46:01 2002
@@ -14,6 +14,7 @@
 #include <syslog.h>
 #include <ctype.h>
-#include <mhash.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <md5.h>
 #include <time.h>
 #include <libpq-fe.h>
-#include <crypt.h>
@@ -336,32 +336,7 @@
             s = strdup(crypt(pass, crypt_make_salt()));
             break;
-        case PW_MD5: {
-                char *buf;
-                int buf_size;
-                MHASH handle;
-                unsigned char *hash;
-
-                handle = mhash_init(MHASH_MD5);
-
-                if(handle == MHASH_FAILED) {
-                    SYSLOG("could not initialize mhash library!");
-                } else {
-                    int i; 
-
-                    mhash(handle, pass, strlen(pass));
-                    hash = mhash_end(handle);
-
-                    buf_size = (mhash_get_block_size(MHASH_MD5) * 2)+1;
-                    buf = (char *)malloc(buf_size);
-                    bzero(buf, buf_size);
-
-                    for(i = 0; i < mhash_get_block_size(MHASH_MD5); i++) {
-                        /* should be safe */
-                        sprintf(&buf[i * 2], "%.2x", hash[i]);
-                    }
-                    s = buf;
-                }
-            }
-            break;
+        case PW_MD5:
+       s = MD5Data(pass, strlen(pass), NULL);
+       break;
         case PW_CLEAR:
         default:
@@ -416,34 +391,15 @@
                 }
                 break;
-            case PW_MD5: {
-                char *buf;
-                int buf_size;
-                MHASH handle;
-                unsigned char *hash;
-
-                handle = mhash_init(MHASH_MD5);
-
-                if(handle == MHASH_FAILED) {
-                    SYSLOG("could not initialize mhash library!");
-                } else {
-                    int i; 
-
-                    mhash(handle, passwd, strlen(passwd));
-                    hash = mhash_end(handle);
-
-                    buf_size = (mhash_get_block_size(MHASH_MD5) * 2)+1;
-                    buf = (char *)malloc(buf_size);
-                    bzero(buf, buf_size);
-
-                    for(i = 0; i < mhash_get_block_size(MHASH_MD5); i++) {
-                        sprintf(&buf[i * 2], "%.2x", hash[i]);
-                    }
-
-                    if(strcmp(buf, stored_pw) == 0)
-                        rc = PAM_SUCCESS;
-                    free(buf);
-                }
-            }
-            break;
+            case PW_MD5:
+       if(strlen(stored_pw) != 32) {
+           SYSLOG("stored password has invalid length.");
+       } else {
+                    char *hash;
+           hash = MD5Data(passwd, strlen(passwd), NULL);
+                    if(strcmp(hash, stored_pw) == 0)
+           rc = PAM_SUCCESS;
+           free(hash);
+       }
+       break;
         }
     }