49 #include "asterisk/channel.h"
61 #define RES_CONFIG_LDAP_CONF "res_ldap.conf"
62 #define RES_CONFIG_LDAP_DEFAULT_BASEDN "asterisk"
141 if (!strcasecmp(name, var->
name))
157 for (; *somestr; somestr++) {
176 ast_debug(2,
"LINE(%d) semicolon_count_var: %s\n", __LINE__, var_value->
value);
183 const char *attribute_name,
const char *attribute_value)
226 const char *attribute_name)
231 for (i = 0; i <
ARRAY_LEN(configs); i++) {
239 for (; attribute; attribute = attribute->
next) {
240 if (!strcasecmp(attribute_name, attribute->
name)) {
241 return attribute->
value;
246 return attribute_name;
252 const char *attribute_name)
257 for (i = 0; i <
ARRAY_LEN(configs); i++) {
265 for (; attribute; attribute = attribute->
next) {
266 if (strcasecmp(attribute_name, attribute->
value) == 0) {
267 return attribute->
name;
272 return attribute_name;
280 LDAPMessage *ldap_entry)
282 BerElement *ber = NULL;
285 int is_delimited = 0;
287 char *ldap_attribute_name;
288 struct berval *
value;
291 ldap_attribute_name = ldap_first_attribute(ldapConn, ldap_entry, &ber);
293 while (ldap_attribute_name) {
294 struct berval **
values = NULL;
296 int is_realmed_password_attribute = strcasecmp(attribute_name,
"md5secret") == 0;
298 values = ldap_get_values_len(ldapConn, ldap_entry, ldap_attribute_name);
303 for (v = values; *v; v++) {
305 valptr = value->bv_val;
306 ast_debug(2,
"LINE(%d) attribute_name: %s LDAP value: %s\n", __LINE__, attribute_name, valptr);
307 if (is_realmed_password_attribute) {
308 if (!strncasecmp(valptr,
"{md5}", 5)) {
319 if (valptr[i] ==
';') {
345 ldap_value_free_len(values);
347 ldap_memfree(ldap_attribute_name);
348 ldap_attribute_name = ldap_next_attribute(ldapConn, ldap_entry, ber);
362 LDAPMessage *ldap_result_msg,
unsigned int *entries_count_ptr)
368 LDAPMessage *ldap_entry = NULL;
369 BerElement *ber = NULL;
372 int is_delimited = 0;
373 char *delim_value = NULL;
374 int delim_tot_count = 0;
378 ldap_entry = ldap_first_entry(ldapConn, ldap_result_msg);
380 for (tot_count = 0; ldap_entry; tot_count++) {
383 ldap_entry = ldap_next_entry(ldapConn, ldap_entry);
387 if (entries_count_ptr) {
388 *entries_count_ptr = tot_count;
398 ldap_entry = ldap_first_entry(ldapConn, ldap_result_msg);
403 for (entry_index = 0; ldap_entry; ) {
412 char *ldap_attribute_name = ldap_first_attribute(ldapConn, ldap_entry, &ber);
413 struct berval *
value;
414 while (ldap_attribute_name) {
417 int is_realmed_password_attribute = strcasecmp(attribute_name,
"md5secret") == 0;
418 struct berval **
values = NULL;
420 values = ldap_get_values_len(ldapConn, ldap_entry, ldap_attribute_name);
425 for (v = values; *v; v++) {
427 valptr = value->bv_val;
428 if (is_realmed_password_attribute) {
429 if (strncasecmp(valptr,
"{md5}", 5) == 0) {
435 if (delim_value == NULL && !is_realmed_password_attribute
436 && (
static_table_config != table_config || strcmp(attribute_name,
"variable_value") == 0)) {
441 ast_debug(4,
"LINE(%d) is delimited %d times: %s\n", __LINE__, delim_tot_count, delim_value);
446 if (is_delimited != 0 && !is_realmed_password_attribute
447 && (
static_table_config != table_config || strcmp(attribute_name,
"variable_value") == 0) ) {
451 ast_debug(4,
"LINE(%d) DELIM pos: %d i: %d\n", __LINE__, pos, i);
452 if (delim_value[i] ==
';') {
453 delim_value[i] =
'\0';
455 ast_debug(2,
"LINE(%d) DELIM - attribute_name: %s value: %s pos: %d\n", __LINE__, attribute_name, &delim_value[pos], pos);
473 ast_debug(4,
"LINE(%d) DELIM pos: %d i: %d delim_count: %d\n", __LINE__, pos, i, delim_count);
475 ast_debug(4,
"LINE(%d) DELIM - attribute_name: %s value: %s pos: %d\n", __LINE__, attribute_name, &delim_value[pos], pos);
491 ast_debug(4,
"LINE(%d) DELIM pos: %d i: %d\n", __LINE__, pos, i);
498 ast_debug(2,
"LINE(%d) attribute_name: %s value: %s\n", __LINE__, attribute_name, valptr);
511 ldap_value_free_len(values);
513 ldap_memfree(ldap_attribute_name);
514 ldap_attribute_name = ldap_next_attribute(ldapConn, ldap_entry, ber);
521 if (tmpdebug && tmpdebug2) {
522 ast_debug(3,
"LINE(%d) Added to vars - %s = %s\n", __LINE__, tmpdebug->
value, tmpdebug2->
value);
525 vars[entry_index++] =
var;
533 ast_debug(3,
"LINE(%d) Added to vars - non static\n", __LINE__);
535 vars[entry_index++] =
var;
538 ldap_entry = ldap_next_entry(ldapConn, ldap_entry);
548 return (err == LDAP_SERVER_DOWN || err == LDAP_TIMEOUT || err == LDAP_CONNECT_ERROR);
564 LDAPMessage *ldap_result_msg = NULL;
567 ast_debug(2,
"ldap_loadentry dn=%s\n", dn);
570 result = ldap_search_ext_s(ldapConn, dn, LDAP_SCOPE_BASE,
571 "(objectclass=*)", NULL, 0, NULL, NULL, NULL, LDAP_NO_LIMIT, &ldap_result_msg);
576 usleep(500000L * tries);
578 ldap_unbind_ext_s(ldapConn, NULL, NULL);
588 if (result != LDAP_SUCCESS) {
589 ast_log(
LOG_WARNING,
"Failed to query directory. Error: %s.\n", ldap_err2string(result));
595 unsigned int *entries_count_ptr = NULL;
597 if ((num_entry = ldap_count_entries(ldapConn, ldap_result_msg)) > 0) {
598 ast_debug(3,
"num_entry: %d\n", num_entry);
605 ast_debug(2,
"Could not find any entry dn=%s.\n", dn);
608 ldap_msgfree(ldap_result_msg);
631 #define MAXRESULT 2048
632 char *ret_string = NULL;
638 ast_debug(2,
"substituted: string: '%s' => '%s' \n",
string, ret_string);
645 char *cbasedn = NULL;
649 if (*cbasedn ==
'"') {
652 int len = strlen(cbasedn);
653 if (cbasedn[len - 1] ==
'"')
654 cbasedn[len - 1] =
'\0';
665 ast_debug(2,
"basedn: '%s' => '%s' \n", basedn, cbasedn);
673 int search_len = strlen(search);
674 int by_len = strlen(by);
676 char *p = strstr(
string, search);
681 if (by_len == search_len) {
682 memcpy(p, by, by_len);
684 memmove(p + by_len, p + search_len, strlen(p + search_len) + 1);
685 memcpy(p, by, by_len);
687 p = strstr(p + by_len, search);
698 char *new_name = NULL;
699 char *new_value = NULL;
700 char *like_pos = strstr(name,
" LIKE");
702 ast_debug(2,
"name='%s' value='%s'\n", name, value);
708 new_name[
len] =
'\0';
728 const char *basedn,
const char *
table_name, va_list ap)
731 const char *newparam = NULL;
732 const char *newval = NULL;
738 LDAPMessage *ldap_result_msg = NULL;
753 newparam = va_arg(ap,
const char *);
754 newval = va_arg(ap,
const char *);
756 if (!newparam || !newval) {
758 " and 1 value to search on.\n");
797 while ((newparam = va_arg(ap,
const char *))) {
798 newval = va_arg(ap,
const char *);
805 result = ldap_search_ext_s(ldapConn, clean_basedn,
806 LDAP_SCOPE_SUBTREE,
ast_str_buffer(filter), NULL, 0, NULL, NULL, NULL, LDAP_NO_LIMIT,
813 ldap_unbind_ext_s(ldapConn, NULL, NULL);
823 if (result != LDAP_SUCCESS) {
824 ast_log(
LOG_WARNING,
"Failed to query directory. Error: %s.\n", ldap_err2string(result));
829 if (ldap_count_entries(ldapConn, ldap_result_msg) > 0) {
836 ldap_msgfree(ldap_result_msg);
845 if (strcasecmp(tmp->
name,
"accountBaseDN") == 0) {
852 int base_var_found = 0;
856 if (strcasecmp(test_var->
name, base_var->
name) == 0) {
860 test_var = test_var->
next;
863 if (base_var_found) {
864 base_var->
next = NULL;
869 base_var->
next = append_var;
871 base_var->
next = NULL;
873 append_var = base_var;
878 if (!tmp->
next && append_var) {
879 tmp->
next = append_var;
905 const char *basedn,
const char *
table_name, ...)
910 va_start(ap, table_name);
932 while (last_var->
next) {
933 last_var = last_var->
next;
958 const char *initfield = NULL;
959 const char *newparam, *newval;
964 newparam = va_arg(ap,
const char *);
965 newval = va_arg(ap,
const char *);
966 if (!newparam || !newval) {
967 ast_log(
LOG_WARNING,
"realtime retrieval requires at least 1 parameter and 1 value to search on.\n");
971 if ((op = strchr(initfield,
' '))) {
992 if (initfield && !strcmp(initfield, var->
name)) {
1049 const char *file,
struct ast_config *cfg,
struct ast_flags config_flags,
const char *sugg_incl,
const char *who_asked)
1051 unsigned int vars_count = 0;
1056 const char *last_category = NULL;
1057 int last_category_metric = 0;
1066 vars =
realtime_ldap_base(&vars_count, basedn, table_name,
"filename", file,
"commented",
"FALSE", NULL);
1077 if (!(categories =
ast_calloc(
sizeof(*categories), vars_count))) {
1081 for (vars_count = 0, p = vars; *p; p++) {
1096 (dn ? dn->
value :
"?"), file);
1097 }
else if (!cat_metric) {
1098 ast_log(
LOG_ERROR,
"No category metric in entry '%s'(category: %s) for file '%s'.\n",
1099 (dn ? dn->
value :
"?"), category->
value, file);
1100 }
else if (!var_metric) {
1101 ast_log(
LOG_ERROR,
"No variable metric in entry '%s'(category: %s) for file '%s'.\n",
1102 (dn ? dn->
value :
"?"), category->
value, file);
1103 }
else if (!var_name) {
1104 ast_log(
LOG_ERROR,
"No variable name in entry '%s' (category: %s metric: %s) for file '%s'.\n",
1106 cat_metric->
value, file);
1107 }
else if (!var_val) {
1108 ast_log(
LOG_ERROR,
"No variable value in entry '%s' (category: %s metric: %s variable: %s) for file '%s'.\n",
1112 categories[vars_count].
name = category->
value;
1113 categories[vars_count].
metric = atoi(cat_metric->
value);
1123 for (i = 0; i < vars_count; i++) {
1124 if (!strcmp(categories[i].variable_name,
"#include")) {
1132 if (!last_category || strcmp(last_category, categories[i].
name) ||
1133 last_category_metric != categories[i].metric) {
1139 last_category = categories[i].
name;
1140 last_category_metric = categories[i].
metric;
1144 if (!(new_v =
ast_variable_new(categories[i].variable_name, categories[i].variable_value, table_name))) {
1160 const char *lookup, va_list ap)
1163 LDAPMessage *ldap_entry = NULL;
1164 LDAPMod **ldap_mods;
1165 const char *newparam = NULL;
1166 const char *newval = NULL;
1168 int num_entries = 0;
1173 char *clean_basedn = NULL;
1177 LDAPMessage *ldap_result_msg = NULL;
1188 if (!attribute || !lookup) {
1201 if (!table_config) {
1223 newparam = va_arg(ap,
const char *);
1225 newval = va_arg(ap,
const char *);
1226 if (!newparam || !newval) {
1227 ast_log(
LOG_WARNING,
"LINE(%d): need at least one parameter to modify.\n", __LINE__);
1232 ldap_mods = ldap_memcalloc(
sizeof(LDAPMod *), mods_size);
1233 ldap_mods[0] = ldap_memcalloc(1,
sizeof(LDAPMod));
1235 ldap_mods[0]->mod_op = LDAP_MOD_REPLACE;
1236 ldap_mods[0]->mod_type = ldap_strdup(newparam);
1238 ldap_mods[0]->mod_values =
ast_calloc(
sizeof(
char *), 2);
1239 ldap_mods[0]->mod_values[0] = ldap_strdup(newval);
1241 while ((newparam = va_arg(ap,
const char *))) {
1243 newval = va_arg(ap,
const char *);
1246 for (i = 0; i < mods_size - 1; i++) {
1247 if (ldap_mods[i]&& !strcmp(ldap_mods[i]->mod_type, newparam)) {
1249 ldap_mods[i]->mod_values[0] = ldap_memrealloc(ldap_mods[i]->mod_values[0],
sizeof(
char) * (strlen(ldap_mods[i]->mod_values[0]) + strlen(newval) + 2));
1250 strcat(ldap_mods[i]->mod_values[0],
";");
1251 strcat(ldap_mods[i]->mod_values[0], newval);
1260 ldap_mods = ldap_memrealloc(ldap_mods,
sizeof(LDAPMod *) * mods_size);
1261 ldap_mods[mods_size - 1] = NULL;
1263 ldap_mods[mods_size - 2] = ldap_memcalloc(1,
sizeof(LDAPMod));
1265 ldap_mods[mods_size - 2]->mod_type = ldap_memcalloc(
sizeof(
char), strlen(newparam) + 1);
1266 strcpy(ldap_mods[mods_size - 2]->mod_type, newparam);
1268 if (strlen(newval) == 0) {
1269 ldap_mods[mods_size - 2]->mod_op = LDAP_MOD_DELETE;
1271 ldap_mods[mods_size - 2]->mod_op = LDAP_MOD_REPLACE;
1273 ldap_mods[mods_size - 2]->mod_values = ldap_memcalloc(
sizeof(
char *), 2);
1274 ldap_mods[mods_size - 2]->mod_values[0] = ldap_memcalloc(
sizeof(
char), strlen(newval) + 1);
1275 strcpy(ldap_mods[mods_size - 2]->mod_values[0], newval);
1283 result = ldap_search_ext_s(ldapConn, clean_basedn,
1284 LDAP_SCOPE_SUBTREE,
ast_str_buffer(filter), NULL, 0, NULL, NULL, NULL, LDAP_NO_LIMIT,
1290 usleep(500000L * tries);
1292 ldap_unbind_ext_s(ldapConn, NULL, NULL);
1301 if (result != LDAP_SUCCESS) {
1302 ast_log(
LOG_WARNING,
"Failed to query directory. Error: %s.\n", ldap_err2string(result));
1308 ldap_msgfree(ldap_result_msg);
1309 ldap_mods_free(ldap_mods, 0);
1313 if ((num_entries = ldap_count_entries(ldapConn, ldap_result_msg)) > 0) {
1314 ast_debug(3,
"LINE(%d) Modifying %s=%s hits: %d\n", __LINE__, attribute, lookup, num_entries);
1315 for (i = 0;
option_debug > 2 && i < mods_size - 1; i++) {
1316 if (ldap_mods[i]->mod_op != LDAP_MOD_DELETE) {
1317 ast_debug(3,
"LINE(%d) %s=%s \n", __LINE__, ldap_mods[i]->mod_type, ldap_mods[i]->mod_values[0]);
1319 ast_debug(3,
"LINE(%d) deleting %s \n", __LINE__, ldap_mods[i]->mod_type);
1322 ldap_entry = ldap_first_entry(ldapConn, ldap_result_msg);
1324 for (i = 0; ldap_entry; i++) {
1325 dn = ldap_get_dn(ldapConn, ldap_entry);
1326 if ((error = ldap_modify_ext_s(ldapConn, dn, ldap_mods, NULL, NULL)) != LDAP_SUCCESS) {
1328 attribute, lookup, dn, ldap_err2string(error));
1331 ldap_entry = ldap_next_entry(ldapConn, ldap_entry);
1338 ldap_msgfree(ldap_result_msg);
1339 ldap_mods_free(ldap_mods, 0);
1346 LDAPMessage *ldap_entry = NULL;
1347 LDAPMod **ldap_mods;
1348 const char *newparam = NULL;
1349 const char *newval = NULL;
1351 int num_entries = 0;
1356 char *clean_basedn = NULL;
1360 LDAPMessage *ldap_result_msg = NULL;
1381 if (!table_config) {
1401 while ((newparam = va_arg(ap,
const char *))) {
1402 newval = va_arg(ap,
const char *);
1410 newparam = va_arg(ap,
const char *);
1412 newval = va_arg(ap,
const char *);
1413 if (!newparam || !newval) {
1414 ast_log(
LOG_WARNING,
"LINE(%d): need at least one parameter to modify.\n", __LINE__);
1421 ldap_mods =
ast_calloc(
sizeof(LDAPMod *), mods_size);
1422 ldap_mods[0] =
ast_calloc(1,
sizeof(LDAPMod));
1424 ldap_mods[0]->mod_op = LDAP_MOD_REPLACE;
1425 ldap_mods[0]->mod_type =
ast_calloc(
sizeof(
char), strlen(newparam) + 1);
1426 strcpy(ldap_mods[0]->mod_type, newparam);
1428 ldap_mods[0]->mod_values =
ast_calloc(
sizeof(
char), 2);
1429 ldap_mods[0]->mod_values[0] =
ast_calloc(
sizeof(
char), strlen(newval) + 1);
1430 strcpy(ldap_mods[0]->mod_values[0], newval);
1432 while ((newparam = va_arg(ap,
const char *))) {
1434 newval = va_arg(ap,
const char *);
1437 for (i = 0; i < mods_size - 1; i++) {
1438 if (ldap_mods[i]&& !strcmp(ldap_mods[i]->mod_type, newparam)) {
1440 ldap_mods[i]->mod_values[0] =
ast_realloc(ldap_mods[i]->mod_values[0],
sizeof(
char) * (strlen(ldap_mods[i]->mod_values[0]) + strlen(newval) + 2));
1441 strcat(ldap_mods[i]->mod_values[0],
";");
1442 strcat(ldap_mods[i]->mod_values[0], newval);
1451 ldap_mods =
ast_realloc(ldap_mods,
sizeof(LDAPMod *) * mods_size);
1452 ldap_mods[mods_size - 1] = NULL;
1453 ldap_mods[mods_size - 2] =
ast_calloc(1,
sizeof(LDAPMod));
1455 ldap_mods[mods_size - 2]->mod_op = LDAP_MOD_REPLACE;
1457 ldap_mods[mods_size - 2]->mod_type =
ast_calloc(
sizeof(
char), strlen(newparam) + 1);
1458 strcpy(ldap_mods[mods_size - 2]->mod_type, newparam);
1460 ldap_mods[mods_size - 2]->mod_values =
ast_calloc(
sizeof(
char *), 2);
1461 ldap_mods[mods_size - 2]->mod_values[0] =
ast_calloc(
sizeof(
char), strlen(newval) + 1);
1462 strcpy(ldap_mods[mods_size - 2]->mod_values[0], newval);
1469 result = ldap_search_ext_s(ldapConn, clean_basedn,
1470 LDAP_SCOPE_SUBTREE,
ast_str_buffer(filter), NULL, 0, NULL, NULL, NULL, LDAP_NO_LIMIT,
1476 usleep(500000L * tries);
1478 ldap_unbind_ext_s(ldapConn, NULL, NULL);
1488 if (result != LDAP_SUCCESS) {
1489 ast_log(
LOG_WARNING,
"Failed to query directory. Error: %s.\n", ldap_err2string(result));
1495 ldap_msgfree(ldap_result_msg);
1496 ldap_mods_free(ldap_mods, 0);
1500 if ((num_entries = ldap_count_entries(ldapConn, ldap_result_msg)) > 0) {
1501 for (i = 0;
option_debug > 2 && i < mods_size - 1; i++) {
1502 ast_debug(3,
"LINE(%d) %s=%s \n", __LINE__, ldap_mods[i]->mod_type, ldap_mods[i]->mod_values[0]);
1505 ldap_entry = ldap_first_entry(ldapConn, ldap_result_msg);
1507 for (i = 0; ldap_entry; i++) {
1508 dn = ldap_get_dn(ldapConn, ldap_entry);
1509 if ((error = ldap_modify_ext_s(ldapConn, dn, ldap_mods, NULL, NULL)) != LDAP_SUCCESS) {
1510 ast_log(
LOG_ERROR,
"Couldn't modify dn:%s because %s", dn, ldap_err2string(error));
1513 ldap_entry = ldap_next_entry(ldapConn, ldap_entry);
1524 ldap_msgfree(ldap_result_msg);
1525 ldap_mods_free(ldap_mods, 0);
1548 ast_log(
LOG_WARNING,
"Couldn't establish connection to LDAP directory. Check debug.\n");
1552 ast_verb(1,
"LDAP RealTime driver loaded.\n");
1568 ldap_unbind_ext_s(ldapConn, NULL, NULL);
1573 ast_verb(1,
"LDAP RealTime driver unloaded.\n");
1587 ldap_unbind_ext_s(ldapConn, NULL, NULL);
1598 ast_log(
LOG_WARNING,
"Couldn't establish connection to your directory server. Check debug.\n");
1601 ast_verb(2,
"LDAP RealTime driver reloaded.\n");
1614 const char *s, *host;
1616 char *category_name = NULL;
1622 base_distinguished_name[0] =
'\0';
1632 ast_log(
LOG_NOTICE,
"No directory user found, anonymous binding as default.\n");
1651 if (!(s =
ast_variable_retrieve(config,
"_general",
"port")) || sscanf(s,
"%5d", &port) != 1 || port > 65535) {
1656 snprintf(url,
sizeof(url),
"ldap://%s:%d", host, port);
1667 ast_copy_string(base_distinguished_name, s,
sizeof(base_distinguished_name));
1671 }
else if (sscanf(s,
"%30d", &version) != 1 || version < 1 || version > 6) {
1679 int is_general = (strcasecmp(category_name,
"_general") == 0);
1680 int is_config = (strcasecmp(category_name,
"config") == 0);
1686 if (!table_config) {
1694 for (;
var; var = var->
next) {
1695 if (!strcasecmp(var->
name,
"additionalFilter")) {
1712 int bind_result = 0;
1716 ast_debug(2,
"Everything seems fine.\n");
1721 ast_log(
LOG_ERROR,
"Not enough parameters to connect to ldap directory\n");
1725 if (LDAP_SUCCESS != ldap_initialize(&ldapConn, url)) {
1726 ast_log(
LOG_ERROR,
"Failed to init ldap connection to '%s'. Check debug for more info.\n", url);
1730 if (LDAP_OPT_SUCCESS != ldap_set_option(ldapConn, LDAP_OPT_PROTOCOL_VERSION, &version)) {
1731 ast_log(
LOG_WARNING,
"Unable to set LDAP protocol version to %d, falling back to default.\n", version);
1735 ast_debug(2,
"bind to '%s' as user '%s'\n", url, user);
1736 cred.bv_val = (
char *) pass;
1737 cred.bv_len = strlen(pass);
1738 bind_result = ldap_sasl_bind_s(ldapConn, user, LDAP_SASL_SIMPLE, &cred, NULL, NULL, NULL);
1740 ast_debug(2,
"bind %s anonymously\n", url);
1743 bind_result = ldap_sasl_bind_s(ldapConn, NULL, LDAP_SASL_SIMPLE, &cred, NULL, NULL, NULL);
1745 if (bind_result == LDAP_SUCCESS) {
1746 ast_debug(2,
"Successfully connected to directory.\n");
1747 connect_time = time(NULL);
1751 ldap_unbind_ext_s(ldapConn, NULL, NULL);
1759 char status[256], credentials[100] =
"";
1764 e->
command =
"realtime show ldap status";
1766 "Usage: realtime show ldap status\n"
1767 " Shows connection information for the LDAP RealTime driver\n";
1777 snprintf(status,
sizeof(status),
"Connected to '%s', baseDN %s", url, base_distinguished_name);
1780 snprintf(credentials,
sizeof(credentials),
" with username %s", user);
1782 if (ctimesec > 31536000) {
1783 ast_cli(a->
fd,
"%s%s for %d years, %d days, %d hours, %d minutes, %d seconds.\n",
1784 status, credentials, ctimesec / 31536000,
1785 (ctimesec % 31536000) / 86400, (ctimesec % 86400) / 3600,
1786 (ctimesec % 3600) / 60, ctimesec % 60);
1787 }
else if (ctimesec > 86400) {
1788 ast_cli(a->
fd,
"%s%s for %d days, %d hours, %d minutes, %d seconds.\n",
1789 status, credentials, ctimesec / 86400, (ctimesec % 86400) / 3600,
1790 (ctimesec % 3600) / 60, ctimesec % 60);
1791 }
else if (ctimesec > 3600) {
1792 ast_cli(a->
fd,
"%s%s for %d hours, %d minutes, %d seconds.\n",
1793 status, credentials, ctimesec / 3600, (ctimesec % 3600) / 60,
1795 }
else if (ctimesec > 60) {
1796 ast_cli(a->
fd,
"%s%s for %d minutes, %d seconds.\n", status, credentials,
1797 ctimesec / 60, ctimesec % 60);
1799 ast_cli(a->
fd,
"%s%s for %d seconds.\n", status, credentials, ctimesec);
void pbx_substitute_variables_helper(struct ast_channel *c, const char *cp1, char *cp2, int count)
Main Channel structure associated with a channel.
static ast_mutex_t ldap_lock
#define AST_CLI_DEFINE(fn, txt,...)
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
const char * ast_variable_retrieve(const struct ast_config *config, const char *category, const char *variable)
Gets a variable.
static const char config[]
static void append_var_and_value_to_filter(struct ast_str **filter, struct ldap_table_config *table_config, const char *name, const char *value)
Append a name=value filter string. The filter string can grow.
String manipulation functions.
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
descriptor for a cli entry.
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category)
Goes through variables.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
static int semicolon_count_str(const char *somestr)
for the semicolon delimiter
#define RES_CONFIG_LDAP_CONF
Structure for variables, used for configurations and for channel variables.
static struct ast_variable * variable_named(struct ast_variable *var, const char *name)
Find variable by name.
Configuration File Parser.
static char * cleaned_basedn(struct ast_channel *channel, const char *basedn)
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
struct ast_str * ast_str_create(size_t init_len)
Create a malloc'ed dynamic length string.
#define ast_mutex_lock(a)
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
static char * realtime_ldap_status(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static struct ldap_table_config * table_config_new(const char *table_name)
Create a new table_config.
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
void ast_cli(int fd, const char *fmt,...)
static int is_ldap_connect_error(int err)
Check if we have a connection error.
static char base_distinguished_name[512]
const char * variable_value
#define ast_verb(level,...)
void ast_config_destroy(struct ast_config *config)
Destroys a config.
static struct ldap_table_config * base_table_config
static struct ldap_table_config * table_config_for_table_name(const char *table_name)
Find a table_config - Should be locked before using it.
Configuration engine structure, used to define realtime drivers.
struct ast_category * ast_category_new(const char *name, const char *in_file, int lineno)
Create a category structure.
#define CONFIG_STATUS_FILEMISSING
static int replace_string_in_string(char *string, const char *search, const char *by)
Replace <search> by <by> in string.
#define ast_debug(level,...)
Log a DEBUG message.
static int compare_categories(const void *a, const void *b)
Sorting alogrithm for qsort to find the order of the variables a and b.
static void table_configs_free(void)
Free table_config.
static struct ast_config_engine ldap_engine
#define ast_config_load(filename, flags)
Load a config file.
static const char * convert_attribute_name_to_ldap(struct ldap_table_config *table_config, const char *attribute_name)
Convert variable name to ldap attribute name - Should be locked before using it.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
char * ast_category_browse(struct ast_config *config, const char *prev)
Goes through categories.
static struct ast_variable * realtime_ldap(const char *basedn, const char *table_name, va_list ap)
See Asterisk doc.
struct ast_variable * delimiters
static time_t connect_time
A set of macros to manage forward-linked lists.
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Core PBX routines and definitions.
static const char * convert_attribute_name_from_ldap(struct ldap_table_config *table_config, const char *attribute_name)
Convert ldap attribute name to variable name.
static struct ast_variable ** realtime_ldap_base(unsigned int *entries_count_ptr, const char *basedn, const char *table_name,...)
same as realtime_ldap_base_ap but take variable arguments count list
#define ast_strdupa(s)
duplicate a string in memory from the stack
#define AST_LIST_HEAD_NOLOCK_STATIC(name, type)
Defines a structure to be used to hold a list of specified type, statically initialized.
static struct ast_cli_entry ldap_cli[]
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
void ast_variable_append(struct ast_category *category, struct ast_variable *variable)
static struct ast_variable ** realtime_ldap_result_to_vars(struct ldap_table_config *table_config, LDAPMessage *ldap_result_msg, unsigned int *entries_count_ptr)
Get variables from ldap entry attributes - Should be locked before using it.
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
struct ldap_table_config * next
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
int ast_config_engine_register(struct ast_config_engine *newconfig)
Register config engine.
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
#define AST_LIST_ENTRY(type)
Declare a forward link structure inside a list entry.
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
static struct ast_variable * realtime_ldap_entry_to_var(struct ldap_table_config *table_config, LDAPMessage *ldap_entry)
Get variables from ldap entry attributes.
struct ast_config * ast_config_new(void)
Create a new base configuration structure.
static int update_ldap(const char *basedn, const char *table_name, const char *attribute, const char *lookup, va_list ap)
static void ldap_table_config_add_attribute(struct ldap_table_config *table_config, const char *attribute_name, const char *attribute_value)
add attribute to table config - Should be locked before using it
static int semicolon_count_var(struct ast_variable *var)
static int update2_ldap(const char *basedn, const char *table_name, va_list ap)
structure to hold users read from users.conf
Structure used to handle boolean flags.
static struct ast_config * realtime_multi_ldap(const char *basedn, const char *table_name, va_list ap)
See Asterisk doc.
Support for logging to various files, console and syslog Configuration in file logger.conf.
static int unload_module(void)
const char * variable_name
static int parse_config(void)
parse the configuration file
Standard Command Line Interface.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
struct ast_variable * attributes
#define RES_CONFIG_LDAP_DEFAULT_BASEDN
int ast_cli_register_multiple(struct ast_cli_entry *e, int len)
Register multiple commands.
#define ast_realloc(a, b)
static struct ast_config * config_ldap(const char *basedn, const char *table_name, const char *file, struct ast_config *cfg, struct ast_flags config_flags, const char *sugg_incl, const char *who_asked)
See Asterisk doc.
static struct ast_variable * ldap_loadentry(struct ldap_table_config *table_config, const char *dn)
Get LDAP entry by dn and return attributes as variables - Should be locked before using it This is us...
Options provided by main asterisk program.
struct ldap_table_config::@326 entry
struct ast_variable * next
static struct ast_variable ** realtime_ldap_base_ap(unsigned int *entries_count_ptr, const char *basedn, const char *table_name, va_list ap)
LDAP base function.
void ast_category_append(struct ast_config *config, struct ast_category *cat)
#define CONFIG_STATUS_FILEINVALID
static int filter(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
static int load_module(void)
struct ast_config * ast_config_internal_load(const char *configfile, struct ast_config *cfg, struct ast_flags flags, const char *suggested_incl_file, const char *who_asked)
void ast_category_rename(struct ast_category *cat, const char *name)
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
static char * substituted(struct ast_channel *channel, const char *string)
#define AST_MUTEX_DEFINE_STATIC(mutex)
struct ast_variable * ast_variable_new(const char *name, const char *value, const char *filename)
Should be locked before using it.
static int ldap_reconnect(void)
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
int ast_config_engine_deregister(struct ast_config_engine *del)
Deregister config engine.
#define ast_mutex_unlock(a)
static struct ldap_table_config * static_table_config