[PATCH] some cleanups for smbldap.c

Alexander Bokovoy ab at samba.org
Mon Jul 3 22:44:04 UTC 2017


On ti, 04 heinä 2017, Andrew Bartlett wrote:
> 
> The commit message refers to libsmbclient.  Is that a typo, or is this
> really exposed via libsmbclient somehow?
Thank you, Andrew, for better eyes!

A fixed patch is attached.


-- 
/ Alexander Bokovoy
-------------- next part --------------
>From 1ee0e360a76a1ad156d9098b700f0ff971847fe3 Mon Sep 17 00:00:00 2001
From: Alexander Bokovoy <ab at samba.org>
Date: Mon, 3 Jul 2017 11:58:50 +0300
Subject: [PATCH] smbldap: expose bind callback via API and increase smbldap
 ABI version

Until we fully migrate to use gensec in smbldap, we need to continue
exposing bind callback to allow FreeIPA to integrate with smbldap.

Since smbldap API is now lacking direct access to 'struct
smbldap_state' and new API functions were added to give access to
individual members of this structure, it makes sense to increase ABI
version too.

Signed-off-by: Alexander Bokovoy <ab at samba.org>
---
 source3/include/smbldap.h      |  7 +++++++
 source3/lib/ABI/smbldap-2.sigs | 32 ++++++++++++++++++++++++++++++++
 source3/lib/smbldap.c          | 16 ++++++++++------
 source3/wscript_build          |  2 +-
 4 files changed, 50 insertions(+), 7 deletions(-)
 create mode 100644 source3/lib/ABI/smbldap-2.sigs

diff --git a/source3/include/smbldap.h b/source3/include/smbldap.h
index 6af0806b748..878268aebd6 100644
--- a/source3/include/smbldap.h
+++ b/source3/include/smbldap.h
@@ -34,6 +34,9 @@
  */
 
 struct smbldap_state;
+typedef int (*smbldap_bind_callback_fn)(LDAP *ldap_struct,
+					struct smbldap_state *ldap_state,
+					void *data);
 
 /* The following definitions come from lib/smbldap.c  */
 
@@ -50,6 +53,10 @@ bool smbldap_get_paged_results(struct smbldap_state *state);
 void smbldap_set_paged_results(struct smbldap_state *state,
 			       bool paged_results);
 
+void smbldap_set_bind_callback(struct smbldap_state *state,
+			       smbldap_bind_callback_fn callback,
+			       void *callback_data);
+
 void smbldap_set_mod (LDAPMod *** modlist, int modop, const char *attribute, const char *value);
 void smbldap_set_mod_blob(LDAPMod *** modlist, int modop, const char *attribute, const DATA_BLOB *newblob);
 void smbldap_make_mod(LDAP *ldap_struct, LDAPMessage *existing,
diff --git a/source3/lib/ABI/smbldap-2.sigs b/source3/lib/ABI/smbldap-2.sigs
new file mode 100644
index 00000000000..8abefec15b6
--- /dev/null
+++ b/source3/lib/ABI/smbldap-2.sigs
@@ -0,0 +1,32 @@
+smbldap_add: int (struct smbldap_state *, const char *, LDAPMod **)
+smbldap_delete: int (struct smbldap_state *, const char *)
+smbldap_extended_operation: int (struct smbldap_state *, const char *, struct berval *, LDAPControl **, LDAPControl **, char **, struct berval **)
+smbldap_free_struct: void (struct smbldap_state **)
+smbldap_get_ldap: LDAP *(struct smbldap_state *)
+smbldap_get_paged_results: bool (struct smbldap_state *)
+smbldap_get_single_attribute: bool (LDAP *, LDAPMessage *, const char *, char *, int)
+smbldap_has_control: bool (LDAP *, const char *)
+smbldap_has_extension: bool (LDAP *, const char *)
+smbldap_has_naming_context: bool (LDAP *, const char *)
+smbldap_init: NTSTATUS (TALLOC_CTX *, struct tevent_context *, const char *, bool, const char *, const char *, struct smbldap_state **)
+smbldap_make_mod: void (LDAP *, LDAPMessage *, LDAPMod ***, const char *, const char *)
+smbldap_make_mod_blob: void (LDAP *, LDAPMessage *, LDAPMod ***, const char *, const DATA_BLOB *)
+smbldap_modify: int (struct smbldap_state *, const char *, LDAPMod **)
+smbldap_pull_sid: bool (LDAP *, LDAPMessage *, const char *, struct dom_sid *)
+smbldap_search: int (struct smbldap_state *, const char *, int, const char *, const char **, int, LDAPMessage **)
+smbldap_search_paged: int (struct smbldap_state *, const char *, int, const char *, const char **, int, int, LDAPMessage **, void **)
+smbldap_search_suffix: int (struct smbldap_state *, const char *, const char **, LDAPMessage **)
+smbldap_set_bind_callback: void (struct smbldap_state *, smbldap_bind_callback_fn, void *)
+smbldap_set_creds: bool (struct smbldap_state *, bool, const char *, const char *)
+smbldap_set_mod: void (LDAPMod ***, int, const char *, const char *)
+smbldap_set_mod_blob: void (LDAPMod ***, int, const char *, const DATA_BLOB *)
+smbldap_set_paged_results: void (struct smbldap_state *, bool)
+smbldap_setup_full_conn: int (LDAP **, const char *)
+smbldap_start_tls: int (LDAP *, int)
+smbldap_talloc_autofree_ldapmod: void (TALLOC_CTX *, LDAPMod **)
+smbldap_talloc_autofree_ldapmsg: void (TALLOC_CTX *, LDAPMessage *)
+smbldap_talloc_dn: char *(TALLOC_CTX *, LDAP *, LDAPMessage *)
+smbldap_talloc_first_attribute: char *(LDAP *, LDAPMessage *, const char *, TALLOC_CTX *)
+smbldap_talloc_single_attribute: char *(LDAP *, LDAPMessage *, const char *, TALLOC_CTX *)
+smbldap_talloc_single_blob: bool (TALLOC_CTX *, LDAP *, LDAPMessage *, const char *, DATA_BLOB *)
+smbldap_talloc_smallest_attribute: char *(LDAP *, LDAPMessage *, const char *, TALLOC_CTX *)
diff --git a/source3/lib/smbldap.c b/source3/lib/smbldap.c
index 3e7cdd4dc58..71166f649be 100644
--- a/source3/lib/smbldap.c
+++ b/source3/lib/smbldap.c
@@ -46,8 +46,7 @@ struct smbldap_state {
 	bool anonymous;
 	char *bind_dn;
 	char *bind_secret;
-	int (*bind_callback)(LDAP *ldap_struct,
-			     struct smbldap_state *ldap_state, void *data);
+	smbldap_bind_callback_fn bind_callback;
 	void *bind_callback_data;
 
 	bool paged_results;
@@ -77,6 +76,13 @@ void smbldap_set_paged_results(struct smbldap_state *state,
 	state->paged_results = paged_results;
 }
 
+void smbldap_set_bind_callback(struct smbldap_state *state,
+			       smbldap_bind_callback_fn callback,
+			       void *callback_data)
+{
+	state->bind_callback = callback;
+	state->bind_callback_data = callback_data;
+}
 /*******************************************************************
  Search an attribute and return the first value found.
 ******************************************************************/
@@ -1726,8 +1732,7 @@ void smbldap_free_struct(struct smbldap_state **ldap_state)
 
 	SAFE_FREE((*ldap_state)->bind_dn);
 	SAFE_FREE((*ldap_state)->bind_secret);
-	(*ldap_state)->bind_callback = NULL;
-	(*ldap_state)->bind_callback_data = NULL;
+	smbldap_set_bind_callback(*ldap_state, NULL, NULL);
 
 	TALLOC_FREE(*ldap_state);
 
@@ -1907,8 +1912,7 @@ bool smbldap_set_creds(struct smbldap_state *ldap_state, bool anon, const char *
 	/* free any previously set credential */
 
 	SAFE_FREE(ldap_state->bind_dn);
-	ldap_state->bind_callback = NULL;
-	ldap_state->bind_callback_data = NULL;
+	smbldap_set_bind_callback(ldap_state, NULL, NULL);
 
 	if (ldap_state->bind_secret) {
 		/* make sure secrets are zeroed out of memory */
diff --git a/source3/wscript_build b/source3/wscript_build
index 2cc74e0f4ec..a030b8ad177 100644
--- a/source3/wscript_build
+++ b/source3/wscript_build
@@ -523,7 +523,7 @@ bld.SAMBA3_LIBRARY('smbldap',
                     abi_directory='lib/ABI',
                     abi_match='smbldap_*',
                     pc_files=[],
-                    vnum='1',
+                    vnum='2',
                     public_headers='include/smbldap.h include/smb_ldap.h')
 
 bld.SAMBA3_LIBRARY('ads',
-- 
2.13.0



More information about the samba-technical mailing list