comparison src/os/unix/ngx_user.c @ 503:b1648294f693 release-0.1.26

nginx-0.1.26-RELEASE import *) 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 <igor@sysoev.ru>
date Tue, 22 Mar 2005 16:02:46 +0000
parents
children 9b8c906f6e63
comparison
equal deleted inserted replaced
502:2017b79d7db5 503:b1648294f693
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_CRYPT)
22
23 #if (NGX_LINUX)
24
25 ngx_int_t
26 ngx_crypt(ngx_pool_t *pool, u_char *key, u_char *salt, u_char **encrypted)
27 {
28 char *value;
29 size_t len;
30 struct crypt_data cd;
31
32 value = crypt_r((char *) key, (char *) salt, &cd);
33
34 if (value) {
35 len = ngx_strlen(value);
36
37 *encrypted = ngx_palloc(pool, len);
38 if (*encrypted) {
39 ngx_memcpy(*encrypted, value, len + 1);
40 return NGX_OK;
41 }
42 }
43
44 return NGX_ERROR;
45 }
46
47 #else
48
49 ngx_int_t
50 ngx_crypt(ngx_pool_t *pool, u_char *key, u_char *salt, u_char **encrypted)
51 {
52 char *value;
53 size_t len;
54 ngx_int_t rc;
55
56 #if (NGX_THREADS && NGX_NONREENTRANT_CRYPT)
57
58 /* crypt() is a time consuming funtion, so we only try to lock */
59
60 if (ngx_mutex_trylock(ngx_crypt_mutex) != NGX_OK) {
61 return NGX_AGAIN;
62 }
63
64 #endif
65
66 rc = NGX_ERROR;
67
68 value = crypt((char *) key, (char *) salt);
69
70 if (value) {
71 len = ngx_strlen(value);
72
73 *encrypted = ngx_palloc(pool, len);
74 if (*encrypted) {
75 ngx_memcpy(*encrypted, value, len + 1);
76 rc = NGX_OK;
77 }
78 }
79
80 #if (NGX_THREADS && NGX_NONREENTRANT_CRYPT)
81 ngx_mutex_unlock(ngx_crypt_mutex);
82 #endif
83
84 return rc;
85 }
86
87 #endif
88
89 #endif /* NGX_CRYPT */