Mercurial > hg > nginx-vendor-0-6
comparison src/os/unix/ngx_user.c @ 52:0d75d65c642f NGINX_0_1_26
nginx 0.1.26
*) Change: the invalid client header lines are now ignored and logged
at the info level.
*) Change: the server name is also logged in error log.
*) Feature: the ngx_http_auth_basic_module module and the auth_basic
and auth_basic_user_file directives.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Tue, 22 Mar 2005 00:00:00 +0300 |
parents | |
children | bcb5fce0b038 |
comparison
equal
deleted
inserted
replaced
51:43f383e47efc | 52:0d75d65c642f |
---|---|
1 | |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4 */ | |
5 | |
6 | |
7 #include <ngx_config.h> | |
8 #include <ngx_core.h> | |
9 | |
10 | |
11 /* | |
12 * Solaris has thread-safe crypt() | |
13 * Linux has crypt_r(); "struct crypt_data" is more than 128K | |
14 * FreeBSD needs the mutex to protect crypt() | |
15 * | |
16 * TODO: | |
17 * ngx_crypt_init() to init mutex | |
18 */ | |
19 | |
20 | |
21 #if (NGX_LINUX) | |
22 | |
23 ngx_int_t | |
24 ngx_crypt(ngx_pool_t *pool, u_char *key, u_char *salt, u_char **encrypted) | |
25 { | |
26 char *value; | |
27 size_t len; | |
28 struct crypt_data cd; | |
29 | |
30 value = crypt_r((char *) key, (char *) salt, &cd); | |
31 | |
32 if (value) { | |
33 len = ngx_strlen(value); | |
34 | |
35 *encrypted = ngx_palloc(pool, len); | |
36 if (*encrypted) { | |
37 ngx_memcpy(*encrypted, value, len + 1); | |
38 return NGX_OK; | |
39 } | |
40 } | |
41 | |
42 return NGX_ERROR; | |
43 } | |
44 | |
45 #else | |
46 | |
47 ngx_int_t | |
48 ngx_crypt(ngx_pool_t *pool, u_char *key, u_char *salt, u_char **encrypted) | |
49 { | |
50 char *value; | |
51 size_t len; | |
52 ngx_int_t rc; | |
53 | |
54 #if (NGX_THREADS && NGX_NONREENTRANT_CRYPT) | |
55 | |
56 /* crypt() is a time consuming funtion, so we only try to lock */ | |
57 | |
58 if (ngx_mutex_trylock(ngx_crypt_mutex) != NGX_OK) { | |
59 return NGX_AGAIN; | |
60 } | |
61 | |
62 #endif | |
63 | |
64 rc = NGX_ERROR; | |
65 | |
66 value = crypt((char *) key, (char *) salt); | |
67 | |
68 if (value) { | |
69 len = ngx_strlen(value); | |
70 | |
71 *encrypted = ngx_palloc(pool, len); | |
72 if (*encrypted) { | |
73 ngx_memcpy(*encrypted, value, len + 1); | |
74 rc = NGX_OK; | |
75 } | |
76 } | |
77 | |
78 #if (NGX_THREADS && NGX_NONREENTRANT_CRYPT) | |
79 ngx_mutex_unlock(ngx_crypt_mutex); | |
80 #endif | |
81 | |
82 return rc; | |
83 } | |
84 | |
85 #endif |