Mercurial > hg > nginx
comparison src/mysql/ngx_mysql.c @ 1574:6a60502db714
use ngx_sha1.h
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 16 Oct 2007 12:17:11 +0000 |
parents | 4d68c486fcb0 |
children | 2a92804f4109 |
comparison
equal
deleted
inserted
replaced
1573:8f911d6d0d70 | 1574:6a60502db714 |
---|---|
10 #include <ngx_config.h> | 10 #include <ngx_config.h> |
11 #include <ngx_core.h> | 11 #include <ngx_core.h> |
12 #include <ngx_event.h> | 12 #include <ngx_event.h> |
13 #include <ngx_event_connect.h> | 13 #include <ngx_event_connect.h> |
14 #include <ngx_mysql.h> | 14 #include <ngx_mysql.h> |
15 | 15 #include <ngx_sha1.h> |
16 #if (NGX_HAVE_OPENSSL_SHA1_H) | |
17 #include <openssl/sha.h> | |
18 #else | |
19 #include <sha.h> | |
20 #endif | |
21 | 16 |
22 | 17 |
23 #define NGX_MYSQL_LONG_PASSWORD 0x0001 | 18 #define NGX_MYSQL_LONG_PASSWORD 0x0001 |
24 #define NGX_MYSQL_CONNECT_WITH_DB 0x0008 | 19 #define NGX_MYSQL_CONNECT_WITH_DB 0x0008 |
25 #define NGX_MYSQL_PROTOCOL_41 0x0200 | 20 #define NGX_MYSQL_PROTOCOL_41 0x0200 |
140 ngx_mysql_t *m; | 135 ngx_mysql_t *m; |
141 ngx_connection_t *c; | 136 ngx_connection_t *c; |
142 ngx_mysql_greeting1_pkt_t *gr1; | 137 ngx_mysql_greeting1_pkt_t *gr1; |
143 ngx_mysql_greeting2_pkt_t *gr2; | 138 ngx_mysql_greeting2_pkt_t *gr2; |
144 ngx_mysql_auth_pkt_t *auth; | 139 ngx_mysql_auth_pkt_t *auth; |
145 SHA_CTX sha; | 140 ngx_sha1_t sha; |
146 u_char hash1[20], hash2[20]; | 141 u_char hash1[20], hash2[20]; |
147 | 142 |
148 c = rev->data; | 143 c = rev->data; |
149 m = c->data; | 144 m = c->data; |
150 | 145 |
239 | 234 |
240 if (m->passwd->len) { | 235 if (m->passwd->len) { |
241 | 236 |
242 *p++ = (u_char) 20; | 237 *p++ = (u_char) 20; |
243 | 238 |
244 SHA1_Init(&sha); | 239 ngx_sha1_init(&sha); |
245 SHA1_Update(&sha, m->passwd->data, m->passwd->len); | 240 ngx_sha1_update(&sha, m->passwd->data, m->passwd->len); |
246 SHA1_Final(hash1, &sha); | 241 ngx_sha1_final(hash1, &sha); |
247 | 242 |
248 SHA1_Init(&sha); | 243 ngx_sha1_init(&sha); |
249 SHA1_Update(&sha, hash1, 20); | 244 ngx_sha1_update(&sha, hash1, 20); |
250 SHA1_Final(hash2, &sha); | 245 ngx_sha1_final(hash2, &sha); |
251 | 246 |
252 SHA1_Init(&sha); | 247 ngx_sha1_init(&sha); |
253 SHA1_Update(&sha, gr2->salt1, 8); | 248 ngx_sha1_update(&sha, gr2->salt1, 8); |
254 SHA1_Update(&sha, gr2->salt2, 12); | 249 ngx_sha1_update(&sha, gr2->salt2, 12); |
255 SHA1_Update(&sha, hash2, 20); | 250 ngx_sha1_update(&sha, hash2, 20); |
256 SHA1_Final(hash2, &sha); | 251 ngx_sha1_final(hash2, &sha); |
257 | 252 |
258 for (i = 0; i < 20; i++) { | 253 for (i = 0; i < 20; i++) { |
259 *p++ = (u_char) (hash1[i] ^ hash2[i]); | 254 *p++ = (u_char) (hash1[i] ^ hash2[i]); |
260 } | 255 } |
261 | 256 |