32#if defined(HAVE_CRYPT_R) && !defined(__FreeBSD__)
43#define MAX_SALT_LEN 21
46 "abcdefghijklmnopqrstuvwxyz"
47 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
72static 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)
149char *
ast_crypt(
const char *key,
const char *salt)
154 crypted = crypt(key, salt);
169 return strcmp(expected, crypt(key, expected)) == 0;
174char *
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.
#define ast_strdup(str)
A wrapper for strdup()
static char gen_salt_char(void)
static int gen_salt(char *current_salt, size_t maxlen)
Generates a salt to try with crypt.
#define MAX_SALT_LEN
Max length of a salt string.
int ast_crypt_validate(const char *key, const char *expected)
Asterisk wrapper around crypt(3) for validating passwords.
char * ast_crypt(const char *key, const char *salt)
Asterisk wrapper around crypt(3).
char * ast_crypt_encrypt(const char *key)
Asterisk wrapper around crypt(3) for encrypting passwords.
#define SCOPED_MUTEX(varname, lock)
scoped lock specialization for mutexes
#define AST_MUTEX_DEFINE_STATIC(mutex)
static int force_inline attribute_pure ast_begins_with(const char *str, const char *prefix)
Checks whether a string begins with another.
#define ast_random_double()
Returns a random number between 0.0 and 1.0, inclusive.