Back to home page

Nginx displayed by LXR

Source navigation ]
Diff markup ]
Identifier search ]
general search ]
 
 
Version: nginx-1.13.12 ]​[ nginx-1.12.2 ]​

0001 
0002 /*
0003  * Copyright (C) Igor Sysoev
0004  * Copyright (C) Nginx, Inc.
0005  */
0006 
0007 
0008 #include <ngx_config.h>
0009 #include <ngx_core.h>
0010 
0011 
0012 #if (NGX_CRYPT)
0013 
0014 #if (NGX_HAVE_GNU_CRYPT_R)
0015 
0016 ngx_int_t
0017 ngx_libc_crypt(ngx_pool_t *pool, u_char *key, u_char *salt, u_char **encrypted)
0018 {
0019     char               *value;
0020     size_t              len;
0021     struct crypt_data   cd;
0022 
0023     cd.initialized = 0;
0024 #ifdef __GLIBC__
0025     /* work around the glibc bug */
0026     cd.current_salt[0] = ~salt[0];
0027 #endif
0028 
0029     value = crypt_r((char *) key, (char *) salt, &cd);
0030 
0031     if (value) {
0032         len = ngx_strlen(value) + 1;
0033 
0034         *encrypted = ngx_pnalloc(pool, len);
0035         if (*encrypted == NULL) {
0036             return NGX_ERROR;
0037         }
0038 
0039         ngx_memcpy(*encrypted, value, len);
0040         return NGX_OK;
0041     }
0042 
0043     ngx_log_error(NGX_LOG_CRIT, pool->log, ngx_errno, "crypt_r() failed");
0044 
0045     return NGX_ERROR;
0046 }
0047 
0048 #else
0049 
0050 ngx_int_t
0051 ngx_libc_crypt(ngx_pool_t *pool, u_char *key, u_char *salt, u_char **encrypted)
0052 {
0053     char       *value;
0054     size_t      len;
0055     ngx_err_t   err;
0056 
0057     value = crypt((char *) key, (char *) salt);
0058 
0059     if (value) {
0060         len = ngx_strlen(value) + 1;
0061 
0062         *encrypted = ngx_pnalloc(pool, len);
0063         if (*encrypted == NULL) {
0064             return NGX_ERROR;
0065         }
0066 
0067         ngx_memcpy(*encrypted, value, len);
0068         return NGX_OK;
0069     }
0070 
0071     err = ngx_errno;
0072 
0073     ngx_log_error(NGX_LOG_CRIT, pool->log, err, "crypt() failed");
0074 
0075     return NGX_ERROR;
0076 }
0077 
0078 #endif
0079 
0080 #endif /* NGX_CRYPT */