Asterisk - The Open Source Telephony Project
21.4.1
|
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. | |
struct ast_module * | AST_MODULE_SELF_SYM (void) |
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 int | config_can_be_inherited (const char *key) |
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 Realtime Documentation. 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. More... | |
static struct ast_str * | create_lookup_filter (struct ldap_table_config *config, const struct ast_variable *fields) |
static int | is_ldap_connect_error (int err) |
Check if we have a connection error. | |
static int | ldap_entry_has_attribute (LDAPMessage *entry, const char *lookup) |
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. More... | |
static LDAPMod * | ldap_mod_append (LDAPMod *src, const char *new_value) |
static LDAPMod * | ldap_mod_create (const char *attribute, const char *new_value) |
static LDAPMod * | ldap_mod_duplicate (const LDAPMod *src) |
static LDAPMod * | ldap_mod_find (LDAPMod **modifications, const char *lookup) |
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 More... | |
static int | load_module (void) |
Load the module. More... | |
static LDAPMod ** | massage_mods_for_entry (LDAPMessage *entry, LDAPMod **mods) |
static int | parse_config (void) |
parse the configuration file More... | |
static struct ast_variable * | realtime_arguments_to_fields (va_list ap) |
static struct ast_variable * | realtime_ldap (const char *basedn, const char *table_name, const struct ast_variable *fields) |
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 | |
static struct ast_variable ** | realtime_ldap_base_ap (unsigned int *entries_count_ptr, const char *basedn, const char *table_name, const struct ast_variable *fields) |
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) |
Realtime Status. More... | |
static struct ast_config * | realtime_multi_ldap (const char *basedn, const char *table_name, const struct ast_variable *fields) |
See Asterisk doc. More... | |
static int | reload (void) |
Reload Module. | |
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) |
Count semicolons in string. More... | |
static int | semicolon_count_var (struct ast_variable *var) |
Count semicolons in variables. More... | |
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. More... | |
static struct ldap_table_config * | table_config_new (const char *table_name) |
Create a new table_config. | |
static void | table_configs_free (void) |
Free table_config. More... | |
static int | unload_module (void) |
Unload Module. More... | |
static int | update2_ldap (const char *basedn, const char *table_name, const struct ast_variable *lookup_fields, const struct ast_variable *update_fields) |
static int | update_ldap (const char *basedn, const char *table_name, const char *attribute, const char *lookup, const struct ast_variable *fields) |
static struct ast_variable * | variable_named (struct ast_variable *var, const char *name) |
Find variable by name. | |
static size_t | variables_count (const struct ast_variable *vars) |
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 = "da6642af068ee5e6490c5b1d2cc1d238" , .support_level = AST_MODULE_SUPPORT_EXTENDED, .load = load_module, .unload = unload_module, .reload = reload, .load_pri = AST_MODPRI_REALTIME_DRIVER, .requires = "extconfig", } |
Module Information. More... | |
static const 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, 0} } |
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)
OpenLDAP http://www.openldap.org
Definition in file res_config_ldap.c.
|
static |
Definition at line 685 of file res_config_ldap.c.
References ast_debug, and substituted().
Referenced by realtime_ldap_base_ap().
|
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 1099 of file res_config_ldap.c.
References category_and_metric::var_metric.
Referenced by config_ldap().
|
static |
See Asterisk Realtime Documentation.
This is for Static Realtime
load the configuration stuff for the .conf files called on a reload
Definition at line 1128 of file res_config_ldap.c.
References ast_calloc, ast_category_append(), ast_category_new_dynamic, ast_debug, compare_categories(), realtime_ldap_base(), ast_variable::value, category_and_metric::var_metric, and variable_named().
|
static |
Convert ldap attribute name to variable name.
Definition at line 280 of file res_config_ldap.c.
References ldap_table_config::attributes, 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.
Definition at line 252 of file res_config_ldap.c.
References ldap_table_config::attributes, ast_variable::name, ast_variable::next, and ast_variable::value.
Referenced by append_var_and_value_to_filter().
|
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 594 of file res_config_ldap.c.
References ast_debug, ast_variables_destroy(), is_ldap_connect_error(), ldap_reconnect(), and realtime_ldap_result_to_vars().
Referenced by realtime_ldap_base_ap().
|
static |
Definition at line 1912 of file res_config_ldap.c.
References ast_debug.
Referenced by ldap_loadentry(), load_module(), realtime_ldap_base_ap(), and reload().
|
static |
add attribute to table config
Should be locked before using it
Definition at line 204 of file res_config_ldap.c.
References ldap_table_config::attributes, ast_variable::next, and ldap_table_config::table_name.
Referenced by parse_config().
|
static |
Load the module.
Module loading including tests for configuration or dependencies. This function can return AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_DECLINE, or AST_MODULE_LOAD_SUCCESS. If a dependency or environment variable fails tests return AST_MODULE_LOAD_FAILURE. If the module can not load the configuration file or other non-critical problem return AST_MODULE_LOAD_DECLINE. On success return AST_MODULE_LOAD_SUCCESS.
Definition at line 1717 of file res_config_ldap.c.
References ast_cli_register_multiple, ast_config_engine_register(), ldap_reconnect(), and parse_config().
|
static |
parse the configuration file
< using the [config] context for Static RealTime
Definition at line 1810 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_strdup, ldap_table_config_add_attribute(), ast_variable::name, ast_variable::next, table_config_for_table_name(), table_config_new(), table_configs_free(), and ast_variable::value.
Referenced by load_module(), and reload().
|
static |
See Asterisk doc.
For Realtime Dynamic(i.e., switch, queues, and directory)
Definition at line 1005 of file res_config_ldap.c.
References ast_variable::next, and realtime_ldap_base_ap().
|
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) |
fields | contains list of pairs name/value |
Definition at line 812 of file res_config_ldap.c.
References ast_debug, ast_str_buffer(), ast_variables_destroy(), cleaned_basedn(), is_ldap_connect_error(), ldap_loadentry(), ldap_reconnect(), ast_variable::name, ast_variable::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 308 of file res_config_ldap.c.
References ast_debug, convert_attribute_name_from_ldap(), ast_variable::next, and ldap_table_config::table_name.
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.
First find the total count
For each static realtime variable we may create several entries in the vars array if it's delimited
Definition at line 394 of file res_config_ldap.c.
References ast_calloc, ast_debug, ast_strdup, ast_variables_destroy(), convert_attribute_name_from_ldap(), ast_variable::next, realtime_ldap_entry_to_var(), semicolon_count_str(), semicolon_count_var(), ldap_table_config::table_name, ast_variable::value, and variable_named().
Referenced by ldap_loadentry(), and realtime_ldap_base_ap().
|
static |
Realtime Status.
Definition at line 1962 of file res_config_ldap.c.
References ast_cli_print_timestr_fromseconds(), ast_str_append(), ast_str_buffer(), ast_str_create, ast_cli_entry::command, and ast_cli_entry::usage.
|
static |
See Asterisk doc.
this function will be called for the switch statement 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 1040 of file res_config_ldap.c.
References ast_category_append(), ast_category_new_anonymous, ast_config_new(), ast_strdupa, ast_variable::name, ast_variable::next, realtime_ldap_base_ap(), and ast_variable::value.
|
static |
Replace <search> by <by> in string.
Definition at line 714 of file res_config_ldap.c.
Referenced by append_var_and_value_to_filter().
|
static |
Count semicolons in string.
somestr | - pointer to a string |
Definition at line 169 of file res_config_ldap.c.
Referenced by realtime_ldap_result_to_vars(), and semicolon_count_var().
|
static |
Count semicolons in variables.
takes a linked list of ast_variable variables, finds the one with the name variable_value and returns the number of semicolons in the value for that ast_variable
Definition at line 187 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 670 of file res_config_ldap.c.
References ast_calloc, and ast_debug.
Referenced by cleaned_basedn(), and handle_eval_function().
|
static |
Find a table_config.
Should be locked before using it
Definition at line 139 of file res_config_ldap.c.
References AST_LIST_TRAVERSE, and ldap_table_config::table_name.
Referenced by parse_config(), and realtime_ldap_base_ap().
|
static |
Free table_config.
Definition at line 227 of file res_config_ldap.c.
References ldap_table_config::additional_filter, AST_LIST_REMOVE_HEAD, ast_variables_destroy(), ldap_table_config::attributes, and ldap_table_config::table_name.
Referenced by parse_config(), and unload_module().
|
static |
Unload Module.
Definition at line 1742 of file res_config_ldap.c.
References ast_cli_unregister_multiple(), ast_config_engine_deregister(), and table_configs_free().
|
static |
Module Information.
Definition at line 2007 of file res_config_ldap.c.
|
static |
Definition at line 110 of file res_config_ldap.c.