summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2009-01-21 16:15:53 +0100
committerJelmer Vernooij <jelmer@samba.org>2009-01-21 16:15:53 +0100
commitf3ecb701335b1129947127d4c45eef970b66875c (patch)
tree4e670492610ad24817f6717bf1a9762df22cd7f5 /source3/lib
parent47951fc5d0085e124666b7667715bba98076820e (diff)
downloadsamba-f3ecb701335b1129947127d4c45eef970b66875c.tar.gz
samba-f3ecb701335b1129947127d4c45eef970b66875c.tar.bz2
samba-f3ecb701335b1129947127d4c45eef970b66875c.zip
Replace ldb_search() with ldb_search_exp_fmt(), like in Samba 4.
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/ldb/common/ldb.c6
-rw-r--r--source3/lib/ldb/examples/ldbreader.c3
-rw-r--r--source3/lib/ldb/include/ldb.h12
-rw-r--r--source3/lib/ldb/modules/ldb_map.c2
-rw-r--r--source3/lib/ldb/nssldb/ldb-grp.c36
-rw-r--r--source3/lib/ldb/nssldb/ldb-pwd.c27
-rw-r--r--source3/lib/ldb/tools/ad2oLschema.c6
-rw-r--r--source3/lib/ldb/tools/ldbedit.c2
-rw-r--r--source3/lib/ldb/tools/ldbtest.c8
9 files changed, 16 insertions, 86 deletions
diff --git a/source3/lib/ldb/common/ldb.c b/source3/lib/ldb/common/ldb.c
index 495047f3a1..6e28528dbf 100644
--- a/source3/lib/ldb/common/ldb.c
+++ b/source3/lib/ldb/common/ldb.c
@@ -745,7 +745,7 @@ int ldb_build_rename_req(struct ldb_request **ret_req,
note that ldb_search() will automatically replace a NULL 'base' value with the
defaultNamingContext from the rootDSE if available.
*/
-int ldb_search(struct ldb_context *ldb, TALLOC_CTX *mem_ctx,
+static int _ldb_search(struct ldb_context *ldb, TALLOC_CTX *mem_ctx,
struct ldb_result **_res,
const struct ldb_dn *base,
enum ldb_scope scope,
@@ -799,7 +799,7 @@ done:
takes a memory context where results are allocated
*/
-int ldb_search_exp_fmt(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, struct ldb_result **result,
+int ldb_search(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, struct ldb_result **result,
struct ldb_dn *base, enum ldb_scope scope, const char * const *attrs,
const char *exp_fmt, ...)
{
@@ -819,7 +819,7 @@ int ldb_search_exp_fmt(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, struct ldb_
return LDB_ERR_OPERATIONS_ERROR;
}
- ret = ldb_search(ldb, ldb, &res, base, scope, attrs, expression);
+ ret = _ldb_search(ldb, ldb, &res, base, scope, attrs, expression);
if (ret == LDB_SUCCESS) {
talloc_steal(mem_ctx, res);
diff --git a/source3/lib/ldb/examples/ldbreader.c b/source3/lib/ldb/examples/ldbreader.c
index 9ab21ee25f..35ea03b20e 100644
--- a/source3/lib/ldb/examples/ldbreader.c
+++ b/source3/lib/ldb/examples/ldbreader.c
@@ -56,7 +56,6 @@ static int vprintf_fn(void *private_data, const char *fmt, ...)
int main(int argc, const char **argv)
{
struct ldb_context *ldb;
- const char *expression = "(dn=*)";
struct ldb_result *resultMsg;
int i;
@@ -89,7 +88,7 @@ int main(int argc, const char **argv)
confusing to start with. See RFC2254.
*/
if (LDB_SUCCESS != ldb_search(ldb, ldb, &resultMsg, NULL, LDB_SCOPE_DEFAULT,
- NULL, expression) ) {
+ NULL, "(dn=*)") ) {
printf("Problem in search\n");
exit(-1);
}
diff --git a/source3/lib/ldb/include/ldb.h b/source3/lib/ldb/include/ldb.h
index d98536c480..113652a1a7 100644
--- a/source3/lib/ldb/include/ldb.h
+++ b/source3/lib/ldb/include/ldb.h
@@ -988,18 +988,6 @@ int ldb_build_rename_req(struct ldb_request **ret_req,
\note use talloc_free() to free the ldb_result returned
*/
int ldb_search(struct ldb_context *ldb, TALLOC_CTX *mem_ctx,
- struct ldb_result **_res,
- const struct ldb_dn *base,
- enum ldb_scope scope,
- const char * const *attrs,
- const char *expression);
-
-/*
- * a useful search function where you can easily define the expression and
- * that takes a memory context where results are allocated
-*/
-
-int ldb_search_exp_fmt(struct ldb_context *ldb, TALLOC_CTX *mem_ctx,
struct ldb_result **result, struct ldb_dn *base,
enum ldb_scope scope, const char * const *attrs,
const char *exp_fmt, ...);
diff --git a/source3/lib/ldb/modules/ldb_map.c b/source3/lib/ldb/modules/ldb_map.c
index 54e1758c1e..bda6cdcda5 100644
--- a/source3/lib/ldb/modules/ldb_map.c
+++ b/source3/lib/ldb/modules/ldb_map.c
@@ -1199,7 +1199,7 @@ static int map_init_dns(struct ldb_module *module, struct ldb_map_context *data,
return LDB_ERR_OPERATIONS_ERROR;
}
- ret = ldb_search(module->ldb, dn, LDB_SCOPE_BASE, NULL, attrs, &res);
+ ret = ldb_search(module->ldb, module->ldb, &res, dn, LDB_SCOPE_BASE, attrs, NULL);
talloc_free(dn);
if (ret != LDB_SUCCESS) {
return ret;
diff --git a/source3/lib/ldb/nssldb/ldb-grp.c b/source3/lib/ldb/nssldb/ldb-grp.c
index 842a668d2f..82598e1e95 100644
--- a/source3/lib/ldb/nssldb/ldb-grp.c
+++ b/source3/lib/ldb/nssldb/ldb-grp.c
@@ -151,7 +151,6 @@ NSS_STATUS _nss_ldb_getgrent_r(struct group *result_buf, char *buffer, size_t bu
NSS_STATUS _nss_ldb_getgrnam_r(const char *name, struct group *result_buf, char *buffer, size_t buflen, int *errnop)
{
int ret;
- char *filter;
TALLOC_CTX *ctx;
struct ldb_result *gr_res;
struct ldb_result *mem_res;
@@ -167,21 +166,12 @@ NSS_STATUS _nss_ldb_getgrnam_r(const char *name, struct group *result_buf, char
return NSS_STATUS_UNAVAIL;
}
- /* build the filter for this uid */
- filter = talloc_asprintf(ctx, _LDB_NSS_GRNAM_FILTER, name);
- if (filter == NULL) {
- /* this is a fatal error */
- *errnop = errno = ENOMEM;
- ret = NSS_STATUS_UNAVAIL;
- goto done;
- }
-
/* search the entry */
ret = ldb_search(_ldb_nss_ctx->ldb, _ldb_nss_ctx->ldb, &gr_res,
_ldb_nss_ctx->base,
LDB_SCOPE_SUBTREE,
_ldb_nss_gr_attrs,
- filter);
+ _LDB_NSS_GRNAM_FILTER, name);
if (ret != LDB_SUCCESS) {
/* this is a fatal error */
*errnop = errno = ENOENT;
@@ -242,7 +232,6 @@ done:
NSS_STATUS _nss_ldb_getgrgid_r(gid_t gid, struct group *result_buf, char *buffer, size_t buflen, int *errnop)
{
int ret;
- char *filter;
TALLOC_CTX *ctx;
struct ldb_result *gr_res;
struct ldb_result *mem_res;
@@ -263,21 +252,12 @@ NSS_STATUS _nss_ldb_getgrgid_r(gid_t gid, struct group *result_buf, char *buffer
return NSS_STATUS_UNAVAIL;
}
- /* build the filter for this uid */
- filter = talloc_asprintf(ctx, _LDB_NSS_GRGID_FILTER, gid);
- if (filter == NULL) {
- /* this is a fatal error */
- *errnop = errno = ENOMEM;
- ret = NSS_STATUS_UNAVAIL;
- goto done;
- }
-
/* search the entry */
ret = ldb_search(_ldb_nss_ctx->ldb, _ldb_nss_ctx->ldb, &gr_res,
_ldb_nss_ctx->base,
LDB_SCOPE_SUBTREE,
_ldb_nss_gr_attrs,
- filter);
+ _LDB_NSS_GRGID_FILTER, gid);
if (ret != LDB_SUCCESS) {
/* this is a fatal error */
*errnop = errno = ENOENT;
@@ -338,7 +318,6 @@ done:
NSS_STATUS _nss_ldb_initgroups_dyn(const char *user, gid_t group, long int *start, long int *size, gid_t **groups, long int limit, int *errnop)
{
int ret;
- char *filter;
const char * attrs[] = { "uidNumber", "gidNumber", NULL };
struct ldb_result *uid_res;
struct ldb_result *mem_res;
@@ -354,21 +333,12 @@ NSS_STATUS _nss_ldb_initgroups_dyn(const char *user, gid_t group, long int *star
return NSS_STATUS_UNAVAIL;
}
- /* build the filter for this name */
- filter = talloc_asprintf(mem_res, _LDB_NSS_PWNAM_FILTER, user);
- if (filter == NULL) {
- /* this is a fatal error */
- *errnop = errno = ENOENT;
- ret = NSS_STATUS_UNAVAIL;
- goto done;
- }
-
/* search the entry */
ret = ldb_search(_ldb_nss_ctx->ldb, _ldb_nss_ctx->ldb, &uid_res,
_ldb_nss_ctx->base,
LDB_SCOPE_SUBTREE,
attrs,
- filter);
+ _LDB_NSS_PWNAM_FILTER, user);
if (ret != LDB_SUCCESS) {
/* this is a fatal error */
*errnop = errno = ENOENT;
diff --git a/source3/lib/ldb/nssldb/ldb-pwd.c b/source3/lib/ldb/nssldb/ldb-pwd.c
index 0af7af9981..2e7ec456b3 100644
--- a/source3/lib/ldb/nssldb/ldb-pwd.c
+++ b/source3/lib/ldb/nssldb/ldb-pwd.c
@@ -113,7 +113,6 @@ NSS_STATUS _nss_ldb_getpwent_r(struct passwd *result_buf,
NSS_STATUS _nss_ldb_getpwuid_r(uid_t uid, struct passwd *result_buf, char *buffer, size_t buflen, int *errnop)
{
int ret;
- char *filter;
struct ldb_result *res;
if (uid == 0) { /* we don't serve root uid by policy */
@@ -126,22 +125,12 @@ NSS_STATUS _nss_ldb_getpwuid_r(uid_t uid, struct passwd *result_buf, char *buffe
return ret;
}
- /* build the filter for this uid */
- filter = talloc_asprintf(_ldb_nss_ctx, _LDB_NSS_PWUID_FILTER, uid);
- if (filter == NULL) {
- /* this is a fatal error */
- *errnop = errno = ENOMEM;
- ret = NSS_STATUS_UNAVAIL;
- goto done;
- }
-
/* search the entry */
ret = ldb_search(_ldb_nss_ctx->ldb, _ldb_nss_ctx->ldb, &res,
_ldb_nss_ctx->base,
LDB_SCOPE_SUBTREE,
_ldb_nss_pw_attrs,
- filter
- );
+ _LDB_NSS_PWUID_FILTER, uid);
if (ret != LDB_SUCCESS) {
/* this is a fatal error */
*errnop = errno = ENOENT;
@@ -171,7 +160,6 @@ NSS_STATUS _nss_ldb_getpwuid_r(uid_t uid, struct passwd *result_buf, char *buffe
res->msgs[0]);
done:
- talloc_free(filter);
talloc_free(res);
return ret;
}
@@ -179,7 +167,6 @@ done:
NSS_STATUS _nss_ldb_getpwnam_r(const char *name, struct passwd *result_buf, char *buffer, size_t buflen, int *errnop)
{
int ret;
- char *filter;
struct ldb_result *res;
ret = _ldb_nss_init();
@@ -187,21 +174,12 @@ NSS_STATUS _nss_ldb_getpwnam_r(const char *name, struct passwd *result_buf, char
return ret;
}
- /* build the filter for this name */
- filter = talloc_asprintf(_ldb_nss_ctx, _LDB_NSS_PWNAM_FILTER, name);
- if (filter == NULL) {
- /* this is a fatal error */
- *errnop = errno = ENOENT;
- ret = NSS_STATUS_UNAVAIL;
- goto done;
- }
-
/* search the entry */
ret = ldb_search(_ldb_nss_ctx->ldb, _ldb_nss_ctx->ldb, &res,
_ldb_nss_ctx->base,
LDB_SCOPE_SUBTREE,
_ldb_nss_pw_attrs,
- filter);
+ _LDB_NSS_PWNAM_FILTER, name);
if (ret != LDB_SUCCESS) {
/* this is a fatal error */
*errnop = errno = ENOENT;
@@ -231,7 +209,6 @@ NSS_STATUS _nss_ldb_getpwnam_r(const char *name, struct passwd *result_buf, char
res->msgs[0]);
done:
- talloc_free(filter);
talloc_free(res);
return ret;
}
diff --git a/source3/lib/ldb/tools/ad2oLschema.c b/source3/lib/ldb/tools/ad2oLschema.c
index 55406b29be..0f05448a9e 100644
--- a/source3/lib/ldb/tools/ad2oLschema.c
+++ b/source3/lib/ldb/tools/ad2oLschema.c
@@ -118,12 +118,10 @@ static int fetch_oc_recursive(struct ldb_context *ldb, struct ldb_dn *schemadn,
struct ldb_result *res;
const char *name = ldb_msg_find_attr_as_string(search_from->msgs[i],
"lDAPDisplayname", NULL);
- char *filter = talloc_asprintf(mem_ctx, "(&(&(objectClass=classSchema)(subClassOf=%s))(!(lDAPDisplayName=%s)))",
- name, name);
ret = ldb_search(ldb, ldb, &res, schemadn, LDB_SCOPE_SUBTREE,
- oc_attrs, filter);
- talloc_free(filter);
+ oc_attrs, "(&(&(objectClass=classSchema)(subClassOf=%s))(!(lDAPDisplayName=%s)))",
+ name, name);
if (ret != LDB_SUCCESS) {
printf("Search failed: %s\n", ldb_errstring(ldb));
return ret;
diff --git a/source3/lib/ldb/tools/ldbedit.c b/source3/lib/ldb/tools/ldbedit.c
index dff7270e5d..a33e6ae704 100644
--- a/source3/lib/ldb/tools/ldbedit.c
+++ b/source3/lib/ldb/tools/ldbedit.c
@@ -306,7 +306,7 @@ int main(int argc, const char **argv)
}
}
- ret = ldb_search(ldb, ldb, &result, basedn, options->scope, attrs, expression);
+ ret = ldb_search(ldb, ldb, &result, basedn, options->scope, attrs, "%s", expression);
if (ret != LDB_SUCCESS) {
printf("search failed - %s\n", ldb_errstring(ldb));
exit(1);
diff --git a/source3/lib/ldb/tools/ldbtest.c b/source3/lib/ldb/tools/ldbtest.c
index 637eb5a7ff..5e8ef1b21c 100644
--- a/source3/lib/ldb/tools/ldbtest.c
+++ b/source3/lib/ldb/tools/ldbtest.c
@@ -220,20 +220,18 @@ static void search_uid(struct ldb_context *ldb, struct ldb_dn *basedn, int nreco
for (i=0;i<nsearches;i++) {
int uid = (i * 700 + 17) % (nrecords * 2);
- char *expr;
struct ldb_result *res = NULL;
int ret;
- expr = talloc_asprintf(ldb, "(uid=TEST%d)", uid);
- ret = ldb_search(ldb, ldb, &res, basedn, LDB_SCOPE_SUBTREE, NULL, expr);
+ ret = ldb_search(ldb, ldb, &res, basedn, LDB_SCOPE_SUBTREE, NULL, "(uid=TEST%d)", uid);
if (ret != LDB_SUCCESS || (uid < nrecords && res->count != 1)) {
- printf("Failed to find %s - %s\n", expr, ldb_errstring(ldb));
+ printf("Failed to find TEST%d - %s\n", uid, ldb_errstring(ldb));
exit(1);
}
if (uid >= nrecords && res->count > 0) {
- printf("Found %s !? - %d\n", expr, ret);
+ printf("Found TEST%d !? - %d\n", uid, ret);
exit(1);
}