diff options
Diffstat (limited to 'source3')
-rw-r--r-- | source3/groupdb/mapping_ldb.c | 48 | ||||
-rw-r--r-- | source3/lib/ldb/common/ldb.c | 6 | ||||
-rw-r--r-- | source3/lib/ldb/examples/ldbreader.c | 3 | ||||
-rw-r--r-- | source3/lib/ldb/include/ldb.h | 12 | ||||
-rw-r--r-- | source3/lib/ldb/modules/ldb_map.c | 2 | ||||
-rw-r--r-- | source3/lib/ldb/nssldb/ldb-grp.c | 36 | ||||
-rw-r--r-- | source3/lib/ldb/nssldb/ldb-pwd.c | 27 | ||||
-rw-r--r-- | source3/lib/ldb/tools/ad2oLschema.c | 6 | ||||
-rw-r--r-- | source3/lib/ldb/tools/ldbedit.c | 2 | ||||
-rw-r--r-- | source3/lib/ldb/tools/ldbtest.c | 8 |
10 files changed, 28 insertions, 122 deletions
diff --git a/source3/groupdb/mapping_ldb.c b/source3/groupdb/mapping_ldb.c index 5c43af531f..af99b86c45 100644 --- a/source3/groupdb/mapping_ldb.c +++ b/source3/groupdb/mapping_ldb.c @@ -243,24 +243,16 @@ failed: static bool get_group_map_from_gid(gid_t gid, GROUP_MAP *map) { int ret; - char *expr; struct ldb_result *res=NULL; - expr = talloc_asprintf(ldb, "(&(gidNumber=%u)(objectClass=groupMap))", - (unsigned)gid); - if (expr == NULL) goto failed; - - ret = ldb_search(ldb, ldb, &res, NULL, LDB_SCOPE_SUBTREE, NULL, expr); - talloc_steal(expr, res); + ret = ldb_search(ldb, ldb, &res, NULL, LDB_SCOPE_SUBTREE, NULL, "(&(gidNumber=%u)(objectClass=groupMap))", (unsigned)gid); if (ret != LDB_SUCCESS || res->count != 1) goto failed; if (!msg_to_group_map(res->msgs[0], map)) goto failed; - talloc_free(expr); return True; failed: - talloc_free(expr); return False; } @@ -270,23 +262,16 @@ failed: static bool get_group_map_from_ntname(const char *name, GROUP_MAP *map) { int ret; - char *expr; struct ldb_result *res=NULL; - expr = talloc_asprintf(ldb, "(&(ntName=%s)(objectClass=groupMap))", name); - if (expr == NULL) goto failed; - - ret = ldb_search(ldb, ldb, &res, NULL, LDB_SCOPE_SUBTREE, NULL, expr); - talloc_steal(expr, res); + ret = ldb_search(ldb, ldb, &res, NULL, LDB_SCOPE_SUBTREE, NULL, "(&(ntName=%s)(objectClass=groupMap))", name); if (ret != LDB_SUCCESS || res->count != 1) goto failed; if (!msg_to_group_map(res->msgs[0], map)) goto failed; - talloc_free(expr); return True; failed: - talloc_free(expr); return False; } @@ -317,7 +302,6 @@ static bool enum_group_mapping(const DOM_SID *domsid, enum lsa_SidType sid_name_ size_t *p_num_entries, bool unix_only) { int i, ret; - char *expr; fstring name; struct ldb_result *res = NULL; struct ldb_dn *basedn=NULL; @@ -326,14 +310,6 @@ static bool enum_group_mapping(const DOM_SID *domsid, enum lsa_SidType sid_name_ tmp_ctx = talloc_new(ldb); if (tmp_ctx == NULL) goto failed; - if (sid_name_use == SID_NAME_UNKNOWN) { - expr = talloc_asprintf(tmp_ctx, "(&(objectClass=groupMap))"); - } else { - expr = talloc_asprintf(tmp_ctx, "(&(sidNameUse=%u)(objectClass=groupMap))", - sid_name_use); - } - if (expr == NULL) goto failed; - /* we do a subtree search on the domain */ if (domsid != NULL) { sid_to_fstring(name, domsid); @@ -341,7 +317,15 @@ static bool enum_group_mapping(const DOM_SID *domsid, enum lsa_SidType sid_name_ if (basedn == NULL) goto failed; } - ret = ldb_search(ldb, ldb, &res, basedn, LDB_SCOPE_SUBTREE, NULL, expr); + if (sid_name_use == SID_NAME_UNKNOWN) { + ret = ldb_search(ldb, ldb, &res, basedn, LDB_SCOPE_SUBTREE, NULL, + "(&(objectClass=groupMap))"); + } else { + ret = ldb_search(ldb, ldb, &res, basedn, LDB_SCOPE_SUBTREE, NULL, + "(&(sidNameUse=%u)(objectClass=groupMap))", + sid_name_use); + } + talloc_steal(tmp_ctx, res); if (ret != LDB_SUCCESS) goto failed; @@ -380,7 +364,6 @@ static NTSTATUS one_alias_membership(const DOM_SID *member, NULL }; DOM_SID alias; - char *expr; int ret, i; struct ldb_result *res=NULL; fstring string_sid; @@ -390,12 +373,7 @@ static NTSTATUS one_alias_membership(const DOM_SID *member, return NT_STATUS_INVALID_PARAMETER; } - expr = talloc_asprintf(ldb, "(&(member=%s)(objectClass=groupMap))", - string_sid); - if (expr == NULL) goto failed; - - ret = ldb_search(ldb, ldb, &res, NULL, LDB_SCOPE_SUBTREE, attrs, expr); - talloc_steal(expr, res); + ret = ldb_search(ldb, ldb, &res, NULL, LDB_SCOPE_SUBTREE, attrs, "(&(member=%s)(objectClass=groupMap))", string_sid); if (ret != LDB_SUCCESS) { goto failed; } @@ -414,11 +392,9 @@ static NTSTATUS one_alias_membership(const DOM_SID *member, } } - talloc_free(expr); return NT_STATUS_OK; failed: - talloc_free(expr); return status; } 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); } |