~ubuntu-branches/ubuntu/trusty/nginx/trusty-proposed

« back to all changes in this revision

Viewing changes to src/os/unix/ngx_user.c

  • Committer: Package Import Robot
  • Author(s): Kartik Mistry
  • Date: 2013-04-25 12:51:45 UTC
  • mfrom: (1.3.28)
  • mto: (1.3.29) (15.1.2 experimental)
  • mto: This revision was merged to the branch mainline in revision 64.
  • Revision ID: package-import@ubuntu.com-20130425125145-ugl0wor6bq0u5eae
Tags: upstream-1.4.0
ImportĀ upstreamĀ versionĀ 1.4.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
 
2
2
/*
3
3
 * Copyright (C) Igor Sysoev
 
4
 * Copyright (C) Nginx, Inc.
4
5
 */
5
6
 
6
7
 
23
24
#if (NGX_HAVE_GNU_CRYPT_R)
24
25
 
25
26
ngx_int_t
26
 
ngx_crypt(ngx_pool_t *pool, u_char *key, u_char *salt, u_char **encrypted)
 
27
ngx_libc_crypt(ngx_pool_t *pool, u_char *key, u_char *salt, u_char **encrypted)
27
28
{
28
29
    char               *value;
29
30
    size_t              len;
30
 
    ngx_err_t           err;
31
31
    struct crypt_data   cd;
32
32
 
33
 
    ngx_set_errno(0);
34
 
 
35
33
    cd.initialized = 0;
36
34
    /* work around the glibc bug */
37
35
    cd.current_salt[0] = ~salt[0];
38
36
 
39
37
    value = crypt_r((char *) key, (char *) salt, &cd);
40
38
 
41
 
    err = ngx_errno;
42
 
 
43
 
    if (err == 0) {
44
 
        len = ngx_strlen(value);
45
 
 
46
 
        *encrypted = ngx_palloc(pool, len);
47
 
        if (*encrypted) {
48
 
            ngx_memcpy(*encrypted, value, len + 1);
49
 
            return NGX_OK;
 
39
    if (value) {
 
40
        len = ngx_strlen(value) + 1;
 
41
 
 
42
        *encrypted = ngx_pnalloc(pool, len);
 
43
        if (*encrypted == NULL) {
 
44
            return NGX_ERROR;
50
45
        }
 
46
 
 
47
        ngx_memcpy(*encrypted, value, len);
 
48
        return NGX_OK;
51
49
    }
52
50
 
53
 
    ngx_log_error(NGX_LOG_CRIT, pool->log, err, "crypt_r() failed");
 
51
    ngx_log_error(NGX_LOG_CRIT, pool->log, ngx_errno, "crypt_r() failed");
54
52
 
55
53
    return NGX_ERROR;
56
54
}
58
56
#else
59
57
 
60
58
ngx_int_t
61
 
ngx_crypt(ngx_pool_t *pool, u_char *key, u_char *salt, u_char **encrypted)
 
59
ngx_libc_crypt(ngx_pool_t *pool, u_char *key, u_char *salt, u_char **encrypted)
62
60
{
63
61
    char       *value;
64
62
    size_t      len;
66
64
 
67
65
#if (NGX_THREADS && NGX_NONREENTRANT_CRYPT)
68
66
 
69
 
    /* crypt() is a time consuming funtion, so we only try to lock */
 
67
    /* crypt() is a time consuming function, so we only try to lock */
70
68
 
71
69
    if (ngx_mutex_trylock(ngx_crypt_mutex) != NGX_OK) {
72
70
        return NGX_AGAIN;
74
72
 
75
73
#endif
76
74
 
77
 
    ngx_set_errno(0);
78
 
 
79
75
    value = crypt((char *) key, (char *) salt);
80
76
 
81
77
    if (value) {
82
 
        len = ngx_strlen(value);
 
78
        len = ngx_strlen(value) + 1;
83
79
 
84
 
        *encrypted = ngx_palloc(pool, len);
85
 
        if (*encrypted) {
86
 
            ngx_memcpy(*encrypted, value, len + 1);
 
80
        *encrypted = ngx_pnalloc(pool, len);
 
81
        if (*encrypted == NULL) {
 
82
#if (NGX_THREADS && NGX_NONREENTRANT_CRYPT)
 
83
            ngx_mutex_unlock(ngx_crypt_mutex);
 
84
#endif
 
85
            return NGX_ERROR;
87
86
        }
88
87
 
 
88
        ngx_memcpy(*encrypted, value, len);
89
89
#if (NGX_THREADS && NGX_NONREENTRANT_CRYPT)
90
90
        ngx_mutex_unlock(ngx_crypt_mutex);
91
91
#endif