summaryrefslogtreecommitdiff
path: root/source3/lib/tldap.c
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2009-06-19 11:45:01 +0200
committerVolker Lendecke <vl@samba.org>2009-06-19 14:28:22 +0200
commit5cb6bf6f9d733cc085013174024785ab49a8bb51 (patch)
treed4be30f7eb7310f618db6324c42caea27bd8a251 /source3/lib/tldap.c
parent862ae382b80ef158317193ffbbbc9580a50e011c (diff)
downloadsamba-5cb6bf6f9d733cc085013174024785ab49a8bb51.tar.gz
samba-5cb6bf6f9d733cc085013174024785ab49a8bb51.tar.bz2
samba-5cb6bf6f9d733cc085013174024785ab49a8bb51.zip
Add tldap_context_[gs]etattr
This adds the ability to attach extended information to a tldap_context. This will become useful once we start to do automatic reconnects for example, a callback function might want attach a pointer to credentials so that it can rebind. The initial user of this will be a cached rootdse, so that things like the ability to do paged searches can be cached.
Diffstat (limited to 'source3/lib/tldap.c')
-rw-r--r--source3/lib/tldap.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/source3/lib/tldap.c b/source3/lib/tldap.c
index c70b8ca95d..10766fe34f 100644
--- a/source3/lib/tldap.c
+++ b/source3/lib/tldap.c
@@ -44,6 +44,11 @@ static bool tevent_req_is_ldap_error(struct tevent_req *req, int *perr)
return true;
}
+struct tldap_ctx_attribute {
+ char *name;
+ void *ptr;
+};
+
struct tldap_context {
int ld_version;
int ld_deref;
@@ -64,6 +69,8 @@ struct tldap_context {
void (*log_fn)(void *context, enum tldap_debug_level level,
const char *fmt, va_list ap);
void *log_private;
+
+ struct tldap_ctx_attribute *ctx_attrs;
};
struct tldap_message {
@@ -134,6 +141,77 @@ struct tldap_context *tldap_context_create(TALLOC_CTX *mem_ctx, int fd)
return ctx;
}
+static struct tldap_ctx_attribute *tldap_context_findattr(
+ struct tldap_context *ld, const char *name)
+{
+ int i, num_attrs;
+
+ num_attrs = talloc_array_length(ld->ctx_attrs);
+
+ for (i=0; i<num_attrs; i++) {
+ if (strcmp(ld->ctx_attrs[i].name, name) == 0) {
+ return &ld->ctx_attrs[i];
+ }
+ }
+ return NULL;
+}
+
+bool tldap_context_setattr(struct tldap_context *ld,
+ const char *name, const void *_pptr)
+{
+ struct tldap_ctx_attribute *tmp, *attr;
+ char *tmpname;
+ int num_attrs;
+ void **pptr = (void **)_pptr;
+
+ attr = tldap_context_findattr(ld, name);
+ if (attr != NULL) {
+ /*
+ * We don't actually delete attrs, we don't expect tons of
+ * attributes being shuffled around.
+ */
+ TALLOC_FREE(attr->ptr);
+ if (*pptr != NULL) {
+ attr->ptr = talloc_move(ld->ctx_attrs, pptr);
+ *pptr = NULL;
+ }
+ return true;
+ }
+
+ tmpname = talloc_strdup(ld, name);
+ if (tmpname == NULL) {
+ return false;
+ }
+
+ num_attrs = talloc_array_length(ld->ctx_attrs);
+
+ tmp = talloc_realloc(ld, ld->ctx_attrs, struct tldap_ctx_attribute,
+ num_attrs+1);
+ if (tmp == NULL) {
+ TALLOC_FREE(tmpname);
+ return false;
+ }
+ tmp[num_attrs].name = talloc_move(tmp, &tmpname);
+ if (*pptr != NULL) {
+ tmp[num_attrs].ptr = talloc_move(tmp, pptr);
+ } else {
+ tmp[num_attrs].ptr = NULL;
+ }
+ *pptr = NULL;
+ ld->ctx_attrs = tmp;
+ return true;
+}
+
+void *tldap_context_getattr(struct tldap_context *ld, const char *name)
+{
+ struct tldap_ctx_attribute *attr = tldap_context_findattr(ld, name);
+
+ if (attr == NULL) {
+ return NULL;
+ }
+ return attr->ptr;
+}
+
struct read_ldap_state {
uint8_t *buf;
bool done;