32 #if defined(HAVE_CRYPT_R) && !defined(__FreeBSD__) 43 #define MAX_SALT_LEN 21 46 "abcdefghijklmnopqrstuvwxyz" 47 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 72 static int gen_salt(
char *current_salt,
size_t maxlen)
80 switch (current_salt[0]) {
83 *current_salt++ =
'$';
84 *current_salt++ =
'6';
85 *current_salt++ =
'$';
86 for (i = 0; i < 16; ++i) {
89 *current_salt++ =
'$';
90 *current_salt++ =
'\0';
93 switch (current_salt[1]) {
96 current_salt[1] =
'5';
100 current_salt[1] =
'1';
106 *current_salt++ =
'\0';
119 #if defined(HAVE_CRYPT_R) 123 struct crypt_data data = {};
124 const char *crypted = crypt_r(key, salt, &data);
138 struct crypt_data data = {};
139 return strcmp(expected, crypt_r(key, expected, &data)) == 0;
142 #elif defined(HAVE_CRYPT) 149 char *
ast_crypt(
const char *key,
const char *salt)
154 crypted = crypt(key, salt);
169 return strcmp(expected, crypt(key, expected)) == 0;
174 char *
ast_crypt(
const char *key,
const char *salt)
177 "crypt() support not available; cannot encrypt password\n");
184 "crypt() support not available; cannot validate password\n");
193 while (
gen_salt(salt,
sizeof(salt)) == 0) {
Asterisk main include file. File version handling, generic pbx functions.
static char gen_salt_char(void)
int ast_crypt_validate(const char *key, const char *expected)
Asterisk wrapper around crypt(3) for validating passwords.
static int gen_salt(char *current_salt, size_t maxlen)
Generates a salt to try with crypt.
#define ast_strdup(str)
A wrapper for strdup()
#define SCOPED_MUTEX(varname, lock)
scoped lock specialization for mutexes
#define MAX_SALT_LEN
Max length of a salt string.
char * ast_crypt_encrypt(const char *key)
Asterisk wrapper around crypt(3) for encrypting passwords.
char * ast_crypt(const char *key, const char *salt)
Asterisk wrapper around crypt(3).
static int force_inline attribute_pure ast_begins_with(const char *str, const char *prefix)
#define ast_random_double()
Returns a random number between 0.0 and 1.0, inclusive.
#define AST_MUTEX_DEFINE_STATIC(mutex)