diff options
author | Simo Sorce <ssorce@redhat.com> | 2010-11-26 13:59:32 -0500 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2010-12-07 17:09:19 -0500 |
commit | 85abff7f43e8006de2c2fa35612884d377b9a036 (patch) | |
tree | 84e36f7e4d1eb807c4bc2d77b74cd755275d7973 /src/providers/ldap/sdap.c | |
parent | 1d9eec9e868fbc2d996f1030a43675be9a840133 (diff) | |
download | sssd-85abff7f43e8006de2c2fa35612884d377b9a036.tar.gz sssd-85abff7f43e8006de2c2fa35612884d377b9a036.tar.bz2 sssd-85abff7f43e8006de2c2fa35612884d377b9a036.zip |
ldap: Use USN entries if available.
Otherwise fallback to the default modifyTimestamp indicator
Diffstat (limited to 'src/providers/ldap/sdap.c')
-rw-r--r-- | src/providers/ldap/sdap.c | 58 |
1 files changed, 55 insertions, 3 deletions
diff --git a/src/providers/ldap/sdap.c b/src/providers/ldap/sdap.c index ffe625b3..1735ac52 100644 --- a/src/providers/ldap/sdap.c +++ b/src/providers/ldap/sdap.c @@ -22,6 +22,7 @@ #define LDAP_DEPRECATED 1 #include "util/util.h" #include "confdb/confdb.h" +#include "providers/ldap/ldap_common.h" #include "providers/ldap/sdap.h" /* =Retrieve-Options====================================================== */ @@ -540,6 +541,7 @@ int sdap_get_server_opts_from_rootdse(TALLOC_CTX *memctx, { NULL, NULL } }; const char *last_usn_name; const char *last_usn_value; + const char *entry_usn_name; int ret; int i; @@ -554,6 +556,7 @@ int sdap_get_server_opts_from_rootdse(TALLOC_CTX *memctx, } last_usn_name = opts->gen_map[SDAP_AT_LAST_USN].name; + entry_usn_name = opts->gen_map[SDAP_AT_ENTRY_USN].name; if (last_usn_name) { ret = sysdb_attrs_get_string(rootdse, last_usn_name, &last_usn_value); @@ -571,8 +574,6 @@ int sdap_get_server_opts_from_rootdse(TALLOC_CTX *memctx, DEBUG(1, ("Unkown error (%d) checking rootdse!\n", ret)); } } else { - const char *entry_usn_name; - entry_usn_name = opts->gen_map[SDAP_AT_ENTRY_USN].name; if (!entry_usn_name) { DEBUG(1, ("%s found in rootdse but %s is not set!\n", last_usn_name, @@ -601,13 +602,53 @@ int sdap_get_server_opts_from_rootdse(TALLOC_CTX *memctx, } if (!last_usn_name) { - DEBUG(5, ("No known USN scheme is supported by this server\n!")); + DEBUG(5, ("No known USN scheme is supported by this server!\n")); + if (!entry_usn_name) { + DEBUG(5, ("Will use modification timestamp as usn!\n")); + opts->gen_map[SDAP_AT_ENTRY_USN].name = + talloc_strdup(opts->gen_map, "modifyTimestamp"); + } + } + + if (!opts->user_map[SDAP_AT_USER_USN].name) { + opts->user_map[SDAP_AT_USER_USN].name = + talloc_strdup(opts->user_map, + opts->gen_map[SDAP_AT_ENTRY_USN].name); + } + if (!opts->group_map[SDAP_AT_GROUP_USN].name) { + opts->group_map[SDAP_AT_GROUP_USN].name = + talloc_strdup(opts->group_map, + opts->gen_map[SDAP_AT_ENTRY_USN].name); } *srv_opts = so; return EOK; } +void sdap_steal_server_opts(struct sdap_id_ctx *id_ctx, + struct sdap_server_opts **srv_opts) +{ + if (!id_ctx || !srv_opts || !*srv_opts) { + return; + } + + if (!id_ctx->srv_opts) { + id_ctx->srv_opts = talloc_move(id_ctx, srv_opts); + return; + } + + /* discard if same as previous so we do not reset max usn values + * unnecessarily */ + if (strcmp(id_ctx->srv_opts->server_id, (*srv_opts)->server_id) == 0) { + talloc_zfree(*srv_opts); + return; + } + + talloc_zfree(id_ctx->srv_opts); + id_ctx->srv_opts = talloc_move(id_ctx, srv_opts); +} + + int build_attrs_from_map(TALLOC_CTX *memctx, struct sdap_attr_map *map, size_t size, const char ***_attrs) @@ -636,6 +677,17 @@ int build_attrs_from_map(TALLOC_CTX *memctx, return EOK; } +int append_attrs_to_array(const char **attrs, size_t size, const char *attr) +{ + attrs = talloc_realloc(NULL, attrs, const char *, size + 2); + if (!attrs) return ENOMEM; + + attrs[size] = attr; + attrs[size + 1] = NULL; + + return EOK; +} + int sdap_control_create(struct sdap_handle *sh, const char *oid, int iscritical, struct berval *value, int dupval, LDAPControl **ctrlp) { |