Module: sip-router
Branch: janakj/ldap
Commit: 6651dcc8ac76e515a49293c9fd0905f7e2e6b3c7
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=6651dcc…
Author: Gergely Kovacs <gergo(a)iptel.org>
Committer: Gergely Kovacs <gergo(a)iptel.org>
Date: Wed Aug 6 08:33:20 2008 +0000
Support for time-limited and size-limited search operations added
---
modules/db_ldap/ld_cfg.c | 27 +++++++++++++++++++++++++++
modules/db_ldap/ld_cfg.h | 6 ++++++
modules/db_ldap/ld_cmd.c | 11 ++++++++++-
modules/db_ldap/ld_cmd.h | 11 +++++++----
modules/db_ldap/ldap.cfg | 6 ++++++
5 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/modules/db_ldap/ld_cfg.c b/modules/db_ldap/ld_cfg.c
index ea3d564..996ce95 100644
--- a/modules/db_ldap/ld_cfg.c
+++ b/modules/db_ldap/ld_cfg.c
@@ -254,6 +254,8 @@ static cfg_option_t ldap_tab_options[] = {
{"field_map", .f = parse_field_map},
{"filter", .f = cfg_parse_str_opt, .flags = CFG_STR_PKGMEM},
{"base", .f = cfg_parse_str_opt, .flags = CFG_STR_PKGMEM},
+ {"timelimit", .f = cfg_parse_int_opt},
+ {"sizelimit", .f = cfg_parse_int_opt},
{0}
};
@@ -328,6 +330,8 @@ static int parse_section(void* param, cfg_parser_t* st, unsigned int
flags)
for(i = 0; scope_values[i].name; i++) {
scope_values[i].param = &cfg->scope;
}
+ ldap_tab_options[4].param = &cfg->timelimit;
+ ldap_tab_options[5].param = &cfg->sizelimit;
} else if (type == LDAP_CON_SECTION) {
if ((cinfo = pkg_malloc(sizeof(*cinfo))) == NULL) {
ERR("ldap:%s:%d: Out of memory\n", st->file, st->line);
@@ -442,6 +446,25 @@ struct ld_con_info* ld_find_conn_info(str* conn_id)
}
+int ld_cfg_validity_check(struct ld_cfg *cfg)
+{
+ struct ld_cfg *pcfg;
+
+ for (pcfg = cfg; pcfg; pcfg = pcfg->next) {
+ if (pcfg->sizelimit < 0 || pcfg->sizelimit > LD_MAXINT) {
+ ERR("ldap: invalid sizelimit (%d) specified\n", pcfg->sizelimit);
+ return -1;
+ }
+ if (pcfg->timelimit < 0 || pcfg->timelimit > LD_MAXINT) {
+ ERR("ldap: invalid timelimit (%d) specified\n", pcfg->timelimit);
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+
int ld_load_cfg(str* filename)
{
cfg_parser_t* parser;
@@ -464,5 +487,9 @@ int ld_load_cfg(str* filename)
return -1;
}
cfg_parser_close(parser);
+
+ if (ld_cfg_validity_check(cfg))
+ return -1;
+
return 0;
}
diff --git a/modules/db_ldap/ld_cfg.h b/modules/db_ldap/ld_cfg.h
index 43abca0..0acbf68 100644
--- a/modules/db_ldap/ld_cfg.h
+++ b/modules/db_ldap/ld_cfg.h
@@ -28,6 +28,10 @@
#include "ld_fld.h"
#include "../../str.h"
+#include <sys/time.h>
+
+/* RFC 2251: maxInt INTEGER ::= 2147483647 -- (2^^31 - 1) -- */
+#define LD_MAXINT (2147483647)
struct ld_cfg {
@@ -39,6 +43,8 @@ struct ld_cfg {
str* attr; /**< An array of LDAP attribute names, zero terminated */
enum ld_syntax* syntax; /**< An array of configured LDAP syntaxes */
int n; /**< Number of fields in the arrays */
+ int sizelimit; /**< retrieve at most sizelimit entries for a search */
+ int timelimit; /**< wait at most timelimit seconds for a search to complete */
struct ld_cfg* next; /**< The next table in the list */
};
diff --git a/modules/db_ldap/ld_cmd.c b/modules/db_ldap/ld_cmd.c
index 646313c..e628796 100644
--- a/modules/db_ldap/ld_cmd.c
+++ b/modules/db_ldap/ld_cmd.c
@@ -125,6 +125,12 @@ int ld_cmd(db_cmd_t* cmd)
lcmd->base = cfg->base.s;
lcmd->scope = cfg->scope;
+ lcmd->sizelimit = cfg->sizelimit;
+ if (cfg->timelimit) {
+ lcmd->timelimit.tv_sec = cfg->timelimit;
+ lcmd->timelimit.tv_usec = 0;
+ }
+
if (cfg->filter.s) {
lcmd->filter = cfg->filter;
}
@@ -174,7 +180,10 @@ int ld_cmd_exec(db_res_t* res, db_cmd_t* cmd)
}
ret = ldap_search_ext_s(lcon->con, lcmd->base, lcmd->scope, filter,
- lcmd->result, 0, NULL, NULL, NULL, 0, &msg);
+ lcmd->result, 0, NULL, NULL,
+ lcmd->timelimit.tv_sec ? &lcmd->timelimit : NULL,
+ lcmd->sizelimit,
+ &msg);
if (ret != LDAP_SUCCESS) {
ERR("ldap: Error in ldap_search: %s\n", ldap_err2string(ret));
diff --git a/modules/db_ldap/ld_cmd.h b/modules/db_ldap/ld_cmd.h
index 826f4c6..861da67 100644
--- a/modules/db_ldap/ld_cmd.h
+++ b/modules/db_ldap/ld_cmd.h
@@ -1,5 +1,5 @@
/*
- * $Id$
+ * $Id$
*
* LDAP Database Driver for SER
*
@@ -18,7 +18,7 @@
* details.
*
* You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
+ * with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
@@ -26,10 +26,10 @@
#define _LD_CMD_H
/** \addtogroup ldap
- * @{
+ * @{
*/
-/** \file
+/** \file
* Declaration of ld_cmd data structure that contains LDAP specific data
* stored in db_cmd structures and related functions.
*/
@@ -40,6 +40,7 @@
#include "../../str.h"
#include <stdarg.h>
+#include <sys/time.h>
/** Extension structure of db_cmd adding LDAP specific data.
@@ -52,6 +53,8 @@ struct ld_cmd {
int scope; /**< Scope of the search */
str filter; /**< To be added to the search filter */
char** result; /**< An array with result attribute names for ldap_search */
+ int sizelimit; /**< retrieve at most sizelimit entries for a search */
+ struct timeval timelimit; /**< wait at most timelimit seconds for a search to
complete */
};
diff --git a/modules/db_ldap/ldap.cfg b/modules/db_ldap/ldap.cfg
index d113bfb..b146ffb 100644
--- a/modules/db_ldap/ldap.cfg
+++ b/modules/db_ldap/ldap.cfg
@@ -63,6 +63,12 @@ field_map = auth_username : digestUsername
field_map = uid : serUID
field_map = flags : (BitString) serFlags
+# retrieve at most sizelimit entries for a search
+#sizelimit = 2147483647
+
+# wait at most timelimit seconds for a search to complete
+#timelimit = 120
+
#
# Domain table stores information about virtual domains
#