ldap plugin for portable configuration engine (ARA) More...
#include "asterisk.h"
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdio.h>
#include <ldap.h>
#include "asterisk/channel.h"
#include "asterisk/logger.h"
#include "asterisk/config.h"
#include "asterisk/module.h"
#include "asterisk/lock.h"
#include "asterisk/options.h"
#include "asterisk/cli.h"
#include "asterisk/utils.h"
#include "asterisk/strings.h"
#include "asterisk/pbx.h"
#include "asterisk/linkedlists.h"
Go to the source code of this file.
Data Structures | |
struct | category_and_metric |
struct | ldap_table_config |
Table configuration. More... | |
struct | table_configs |
Should be locked before using it. More... | |
Macros | |
#define | MAXRESULT 2048 |
#define | RES_CONFIG_LDAP_CONF "res_ldap.conf" |
#define | RES_CONFIG_LDAP_DEFAULT_BASEDN "asterisk" |
Functions | |
static void | __reg_module (void) |
static void | __unreg_module (void) |
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. More... | |
static char * | cleaned_basedn (struct ast_channel *channel, const char *basedn) |
static int | compare_categories (const void *a, const void *b) |
Sorting alogrithm for qsort to find the order of the variables a and b. More... | |
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. More... | |
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. More... | |
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. More... | |
static int | is_ldap_connect_error (int err) |
Check if we have a connection error. More... | |
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 used for setting the default values of an object(i.e., with accountBaseDN) More... | |
static int | ldap_reconnect (void) |
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 More... | |
static int | load_module (void) |
static int | parse_config (void) |
parse the configuration file More... | |
static struct ast_variable * | realtime_ldap (const char *basedn, const char *table_name, va_list ap) |
See Asterisk doc. More... | |
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 More... | |
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. More... | |
static struct ast_variable * | realtime_ldap_entry_to_var (struct ldap_table_config *table_config, LDAPMessage *ldap_entry) |
Get variables from ldap entry attributes. More... | |
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. More... | |
static char * | realtime_ldap_status (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static struct ast_config * | realtime_multi_ldap (const char *basedn, const char *table_name, va_list ap) |
See Asterisk doc. More... | |
static int | reload (void) |
static int | replace_string_in_string (char *string, const char *search, const char *by) |
Replace <search> by <by> in string. More... | |
static int | semicolon_count_str (const char *somestr) |
for the semicolon delimiter More... | |
static int | semicolon_count_var (struct ast_variable *var) |
static char * | substituted (struct ast_channel *channel, const char *string) |
static struct ldap_table_config * | table_config_for_table_name (const char *table_name) |
Find a table_config - Should be locked before using it. More... | |
static struct ldap_table_config * | table_config_new (const char *table_name) |
Create a new table_config. More... | |
static void | table_configs_free (void) |
Free table_config. More... | |
static int | unload_module (void) |
static int | update2_ldap (const char *basedn, const char *table_name, va_list ap) |
static int | update_ldap (const char *basedn, const char *table_name, const char *attribute, const char *lookup, va_list ap) |
static struct ast_variable * | variable_named (struct ast_variable *var, const char *name) |
Find variable by name. More... | |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "LDAP realtime interface" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .reload = reload, .load_pri = AST_MODPRI_REALTIME_DRIVER, } |
static struct ast_module_info * | ast_module_info = &__mod_info |
static char | base_distinguished_name [512] |
static struct ldap_table_config * | base_table_config |
static time_t | connect_time |
static struct ast_cli_entry | ldap_cli [] |
static struct ast_config_engine | ldap_engine |
static ast_mutex_t | ldap_lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, 1 } |
static LDAP * | ldapConn |
static char | pass [512] |
static struct ldap_table_config * | static_table_config |
static struct table_configs | table_configs = { .first = NULL, .last = NULL, } |
static char | url [512] |
static char | user [512] |
static int | version |
ldap plugin for portable configuration engine (ARA)
Definition in file res_config_ldap.c.
#define MAXRESULT 2048 |
Referenced by substituted().
#define RES_CONFIG_LDAP_CONF "res_ldap.conf" |
Definition at line 61 of file res_config_ldap.c.
Referenced by config_ldap(), and parse_config().
#define RES_CONFIG_LDAP_DEFAULT_BASEDN "asterisk" |
Definition at line 62 of file res_config_ldap.c.
Referenced by parse_config().
|
static |
Definition at line 1810 of file res_config_ldap.c.
|
static |
Definition at line 1810 of file res_config_ldap.c.
|
static |
Append a name=value filter string. The filter string can grow.
Definition at line 694 of file res_config_ldap.c.
References ast_debug, ast_str_append(), ast_strdupa, convert_attribute_name_to_ldap(), len(), name, and replace_string_in_string().
Referenced by realtime_ldap_base_ap(), update2_ldap(), and update_ldap().
|
static |
Definition at line 643 of file res_config_ldap.c.
References ast_debug, ast_strlen_zero(), len(), and substituted().
Referenced by realtime_ldap_base_ap(), update2_ldap(), and update_ldap().
|
static |
Sorting alogrithm for qsort to find the order of the variables a and b.
a | pointer to category_and_metric struct |
b | pointer to category_and_metric struct |
-1 | for if b is greater |
0 | zero for equal |
1 | if a is greater |
Definition at line 1019 of file res_config_ldap.c.
References category_and_metric::metric, category_and_metric::name, and category_and_metric::var_metric.
Referenced by config_ldap().
|
static |
See Asterisk doc.
This is for Static Realtime (again: I think...)
load the configuration stuff for the .conf files called on a reload
Definition at line 1048 of file res_config_ldap.c.
References ast_calloc, ast_category_append(), ast_category_new(), ast_config_internal_load(), ast_debug, ast_free, ast_log(), ast_strlen_zero(), ast_variable_append(), ast_variable_new(), compare_categories(), LOG_ERROR, LOG_WARNING, category_and_metric::metric, name, category_and_metric::name, realtime_ldap_base(), RES_CONFIG_LDAP_CONF, ast_variable::value, category_and_metric::var_metric, category_and_metric::variable_name, variable_named(), and category_and_metric::variable_value.
|
static |
Convert ldap attribute name to variable name.
Definition at line 251 of file res_config_ldap.c.
References ARRAY_LEN, ldap_table_config::attributes, base_table_config, ast_variable::name, ast_variable::next, and ast_variable::value.
Referenced by realtime_ldap_entry_to_var(), and realtime_ldap_result_to_vars().
|
static |
Convert variable name to ldap attribute name - Should be locked before using it.
Definition at line 225 of file res_config_ldap.c.
References ARRAY_LEN, ldap_table_config::attributes, base_table_config, ast_variable::name, ast_variable::next, and ast_variable::value.
Referenced by append_var_and_value_to_filter(), update2_ldap(), and update_ldap().
|
static |
Check if we have a connection error.
Definition at line 546 of file res_config_ldap.c.
Referenced by ldap_loadentry(), realtime_ldap_base_ap(), update2_ldap(), and update_ldap().
|
static |
Get LDAP entry by dn and return attributes as variables - Should be locked before using it This is used for setting the default values of an object(i.e., with accountBaseDN)
< not using this
Definition at line 554 of file res_config_ldap.c.
References ast_debug, ast_log(), ast_mutex_unlock, ast_realloc, ast_variables_destroy(), is_ldap_connect_error(), ldap_lock, ldap_reconnect(), LOG_ERROR, LOG_NOTICE, LOG_WARNING, realtime_ldap_result_to_vars(), and var.
Referenced by realtime_ldap_base_ap().
|
static |
Definition at line 1710 of file res_config_ldap.c.
References ast_debug, ast_log(), ast_strlen_zero(), LOG_ERROR, and LOG_WARNING.
Referenced by ldap_loadentry(), load_module(), realtime_ldap_base_ap(), reload(), update2_ldap(), and update_ldap().
|
static |
add attribute to table config - Should be locked before using it
Definition at line 182 of file res_config_ldap.c.
References ast_strlen_zero(), ast_variable_new(), ldap_table_config::attributes, ast_variable::next, ldap_table_config::table_name, and var.
Referenced by parse_config().
|
static |
Definition at line 1538 of file res_config_ldap.c.
References ARRAY_LEN, ast_cli_register_multiple(), ast_config_engine_register(), ast_log(), ast_mutex_lock, ast_mutex_unlock, ast_verb, ldap_cli, ldap_engine, ldap_lock, ldap_reconnect(), LOG_ERROR, LOG_WARNING, and parse_config().
|
static |
parse the configuration file
< using the [config] context for Static RealTime
Definition at line 1610 of file res_config_ldap.c.
References ldap_table_config::additional_filter, ast_category_browse(), ast_config_destroy(), ast_config_load, ast_copy_string(), AST_LIST_INSERT_HEAD, ast_log(), ast_strdup, ast_strlen_zero(), ast_variable_browse(), ast_variable_retrieve(), base_table_config, config, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEMISSING, ldap_table_config::entry, ldap_table_config_add_attribute(), LOG_ERROR, LOG_NOTICE, LOG_WARNING, ast_variable::name, ast_variable::next, RES_CONFIG_LDAP_CONF, RES_CONFIG_LDAP_DEFAULT_BASEDN, static_table_config, table_config_for_table_name(), table_config_new(), table_configs_free(), ast_variable::value, and var.
Referenced by load_module(), and reload().
|
static |
See Asterisk doc.
For Realtime Dynamic(i.e., switch, queues, and directory) – I think
Definition at line 921 of file res_config_ldap.c.
References free, ast_variable::next, realtime_ldap_base_ap(), and var.
|
static |
same as realtime_ldap_base_ap but take variable arguments count list
Definition at line 904 of file res_config_ldap.c.
References realtime_ldap_base_ap().
Referenced by config_ldap().
|
static |
LDAP base function.
entries_count_ptr | is a pointer to found entries count (can be NULL) |
basedn | is the base DN |
table_name | is the table_name (used dor attribute convertion and additional filter) |
ap | contains null terminated list of pairs name/value |
Definition at line 727 of file res_config_ldap.c.
References ldap_table_config::additional_filter, append_var_and_value_to_filter(), ast_debug, ast_free, ast_log(), ast_mutex_lock, ast_mutex_unlock, ast_str_append(), ast_str_buffer(), ast_str_create(), ast_variables_destroy(), base_table_config, cleaned_basedn(), filter(), is_ldap_connect_error(), ldap_loadentry(), ldap_lock, ldap_reconnect(), LOG_DEBUG, LOG_ERROR, LOG_WARNING, ast_variable::name, ast_variable::next, ldap_table_config::next, realtime_ldap_result_to_vars(), table_config_for_table_name(), and ast_variable::value.
Referenced by realtime_ldap(), realtime_ldap_base(), and realtime_multi_ldap().
|
static |
Get variables from ldap entry attributes.
Definition at line 279 of file res_config_ldap.c.
References ast_debug, ast_strlen_zero(), ast_variable_new(), convert_attribute_name_from_ldap(), ast_variable::next, ldap_table_config::table_name, value, and var.
Referenced by realtime_ldap_result_to_vars().
|
static |
Get variables from ldap entry attributes - Should be locked before using it.
The results are freed outside this function so is the vars array.
Definition at line 361 of file res_config_ldap.c.
References ast_calloc, ast_debug, ast_strdup, ast_strlen_zero(), ast_variable_new(), ast_variables_destroy(), convert_attribute_name_from_ldap(), free, ast_variable::next, option_debug, realtime_ldap_entry_to_var(), semicolon_count_str(), semicolon_count_var(), static_table_config, ldap_table_config::table_name, value, ast_variable::value, var, and variable_named().
Referenced by ldap_loadentry(), and realtime_ldap_base_ap().
|
static |
Definition at line 1757 of file res_config_ldap.c.
References ast_cli(), ast_strlen_zero(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, connect_time, ast_cli_args::fd, status, and ast_cli_entry::usage.
|
static |
See Asterisk doc.
this function will be called for the switch statment if no match is found with the realtime_ldap function(i.e. it is a failover); however, the ast_load_realtime wil match on wildcharacters also depending on what the mode is set to this is an area of asterisk that could do with a lot of modification I think this function returns Realtime dynamic objects
Definition at line 954 of file res_config_ldap.c.
References ast_category_append(), ast_category_new(), ast_category_rename(), ast_config_new(), ast_log(), ast_strdupa, ast_variable_append(), free, LOG_ERROR, LOG_WARNING, ast_variable::name, ast_variable::next, ldap_table_config::next, realtime_ldap_base_ap(), ast_variable::value, and var.
|
static |
Definition at line 1581 of file res_config_ldap.c.
References ast_log(), ast_mutex_lock, ast_mutex_unlock, ast_verb, ldap_lock, ldap_reconnect(), LOG_NOTICE, LOG_WARNING, and parse_config().
|
static |
Replace <search> by <by> in string.
Definition at line 671 of file res_config_ldap.c.
Referenced by append_var_and_value_to_filter().
|
static |
for the semicolon delimiter
somestr | - pointer to a string |
Definition at line 153 of file res_config_ldap.c.
Referenced by realtime_ldap_result_to_vars(), and semicolon_count_var().
|
static |
Definition at line 168 of file res_config_ldap.c.
References ast_debug, semicolon_count_str(), ast_variable::value, and variable_named().
Referenced by realtime_ldap_result_to_vars().
|
static |
Definition at line 629 of file res_config_ldap.c.
References ast_calloc, ast_debug, ast_strlen_zero(), MAXRESULT, and pbx_substitute_variables_helper().
Referenced by cleaned_basedn().
|
static |
Find a table_config - Should be locked before using it.
Definition at line 125 of file res_config_ldap.c.
References AST_LIST_TRAVERSE, ldap_table_config::entry, and ldap_table_config::table_name.
Referenced by parse_config(), realtime_ldap_base_ap(), update2_ldap(), and update_ldap().
|
static |
Create a new table_config.
Definition at line 106 of file res_config_ldap.c.
References ast_calloc, ast_strdup, free, and ldap_table_config::table_name.
Referenced by parse_config().
|
static |
Free table_config.
Definition at line 203 of file res_config_ldap.c.
References ldap_table_config::additional_filter, ast_free, AST_LIST_REMOVE_HEAD, ast_variables_destroy(), ldap_table_config::attributes, base_table_config, ldap_table_config::entry, free, static_table_config, and ldap_table_config::table_name.
Referenced by parse_config(), and unload_module().
|
static |
Definition at line 1560 of file res_config_ldap.c.
References ARRAY_LEN, ast_cli_unregister_multiple(), ast_config_engine_deregister(), ast_mutex_lock, ast_mutex_unlock, ast_verb, ldap_cli, ldap_engine, ldap_lock, and table_configs_free().
|
static |
Definition at line 1343 of file res_config_ldap.c.
References ldap_table_config::additional_filter, append_var_and_value_to_filter(), ast_calloc, ast_debug, ast_free, ast_log(), ast_mutex_lock, ast_mutex_unlock, ast_realloc, ast_str_append(), ast_str_buffer(), ast_str_create(), base_table_config, cleaned_basedn(), convert_attribute_name_to_ldap(), filter(), is_ldap_connect_error(), ldap_lock, ldap_reconnect(), LOG_ERROR, LOG_WARNING, option_debug, and table_config_for_table_name().
|
static |
Definition at line 1159 of file res_config_ldap.c.
References ldap_table_config::additional_filter, append_var_and_value_to_filter(), ast_calloc, ast_debug, ast_free, ast_log(), ast_mutex_lock, ast_mutex_unlock, ast_str_append(), ast_str_buffer(), ast_str_create(), base_table_config, cleaned_basedn(), convert_attribute_name_to_ldap(), filter(), free, is_ldap_connect_error(), ldap_lock, ldap_reconnect(), LOG_ERROR, LOG_WARNING, option_debug, and table_config_for_table_name().
|
static |
Find variable by name.
Definition at line 138 of file res_config_ldap.c.
References ast_variable::name, ast_variable::next, and var.
Referenced by config_ldap(), realtime_ldap_result_to_vars(), and semicolon_count_var().
|
static |
Definition at line 1810 of file res_config_ldap.c.
|
static |
Definition at line 1810 of file res_config_ldap.c.
|
static |
Definition at line 70 of file res_config_ldap.c.
|
static |
Definition at line 98 of file res_config_ldap.c.
Referenced by convert_attribute_name_from_ldap(), convert_attribute_name_to_ldap(), parse_config(), realtime_ldap_base_ap(), table_configs_free(), update2_ldap(), and update_ldap().
|
static |
Definition at line 72 of file res_config_ldap.c.
Referenced by realtime_ldap_status().
|
static |
Definition at line 101 of file res_config_ldap.c.
Referenced by load_module(), and unload_module().
|
static |
Definition at line 1529 of file res_config_ldap.c.
Referenced by load_module(), and unload_module().
|
static |
Definition at line 64 of file res_config_ldap.c.
Referenced by ldap_loadentry(), load_module(), realtime_ldap_base_ap(), reload(), unload_module(), update2_ldap(), and update_ldap().
|
static |
Definition at line 66 of file res_config_ldap.c.
|
static |
Definition at line 69 of file res_config_ldap.c.
Referenced by __ast_dsp_call_progress(), AST_TEST_DEFINE(), build_transactions(), gtalk_create_candidates(), jingle_create_candidates(), and login_exec().
|
static |
Definition at line 99 of file res_config_ldap.c.
Referenced by parse_config(), realtime_ldap_result_to_vars(), and table_configs_free().
|
static |
|
static |
Definition at line 67 of file res_config_ldap.c.
Referenced by acf_curl_helper(), caldav_load_calendar(), dial_exec_full(), ewscal_load_calendar(), exchangecal_load_calendar(), ical_load_calendar(), queue_exec(), reqprep(), respprep(), sendurl_exec(), and sip_sendhtml().
|
static |
Definition at line 68 of file res_config_ldap.c.
Referenced by action_meetmelist(), AST_TEST_DEFINE(), authenticate_request(), authenticate_verify(), build_route(), build_setup(), build_user(), check_access(), complete_sip_user(), conf_queue_dtmf(), find_user(), get_manager_by_name_locked(), iax2_destroy_helper(), manager_shutdown(), meetme_show_cmd(), meetmemute(), parse_setup(), process_message(), prune_users(), realtime_user(), set_config(), sip_show_user(), sip_show_users(), user_ref(), users_data_provider_get(), vm_users_data_provider_get(), and vmauthenticate().
|
static |
Definition at line 71 of file res_config_ldap.c.