Back to home page

Nginx displayed by LXR

Source navigation ]
Diff markup ]
Identifier search ]
general search ]
 
 
Version: nginx-1.15.12 ]​[ nginx-1.16.0 ]​

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 
0025     value = crypt_r((char *) key, (char *) salt, &cd);
0026 
0027     if (value) {
0028         len = ngx_strlen(value) + 1;
0029 
0030         *encrypted = ngx_pnalloc(pool, len);
0031         if (*encrypted == NULL) {
0032             return NGX_ERROR;
0033         }
0034 
0035         ngx_memcpy(*encrypted, value, len);
0036         return NGX_OK;
0037     }
0038 
0039     ngx_log_error(NGX_LOG_CRIT, pool->log, ngx_errno, "crypt_r() failed");
0040 
0041     return NGX_ERROR;
0042 }
0043 
0044 #else
0045 
0046 ngx_int_t
0047 ngx_libc_crypt(ngx_pool_t *pool, u_char *key, u_char *salt, u_char **encrypted)
0048 {
0049     char       *value;
0050     size_t      len;
0051     ngx_err_t   err;
0052 
0053     value = crypt((char *) key, (char *) salt);
0054 
0055     if (value) {
0056         len = ngx_strlen(value) + 1;
0057 
0058         *encrypted = ngx_pnalloc(pool, len);
0059         if (*encrypted == NULL) {
0060             return NGX_ERROR;
0061         }
0062 
0063         ngx_memcpy(*encrypted, value, len);
0064         return NGX_OK;
0065     }
0066 
0067     err = ngx_errno;
0068 
0069     ngx_log_error(NGX_LOG_CRIT, pool->log, err, "crypt() failed");
0070 
0071     return NGX_ERROR;
0072 }
0073 
0074 #endif
0075 
0076 #endif /* NGX_CRYPT */