[PATCH] some cleanups for smbldap.c
vl at samba.org
vl at samba.org
Wed Apr 19 14:20:36 UTC 2017
Hi!
The main focus is to make "struct smbldap_state" private to smbldap.c
for better encapsulation.
Review appreciated!
Thanks, Volker
-------------- next part --------------
From 9e4c9b4b35e25d6240c04cbd83ce3013944687cc Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 18 Apr 2017 20:49:12 +0200
Subject: [PATCH 1/6] smbldap: Fix a typo
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/include/smbldap.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/source3/include/smbldap.h b/source3/include/smbldap.h
index b287d62..0310049 100644
--- a/source3/include/smbldap.h
+++ b/source3/include/smbldap.h
@@ -37,7 +37,7 @@ struct smbldap_state {
LDAP *ldap_struct;
pid_t pid;
time_t last_ping; /* monotonic */
- /* retrive-once info */
+ /* retrieve-once info */
const char *uri;
/* credentials */
--
2.1.4
From 142d7a130fbd5398a234cba3d158b2c62764e9b5 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 19 Apr 2017 13:29:31 +0200
Subject: [PATCH 2/6] smbldap: Introduce "smbldap_get_ld"
This is a pretty big boiler-plate change. I've renamed the struct member
temporarily to find all accessors. Not sure where this leads in the end, but
the goal is to make struct smbldap_struct private to smbldap.c
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/include/smbldap.h | 2 +
source3/lib/smbldap.c | 63 ++++---
source3/passdb/pdb_ldap.c | 399 ++++++++++++++++++++++++---------------
source3/passdb/pdb_ldap_util.c | 9 +-
source3/passdb/pdb_nds.c | 16 +-
source3/winbindd/idmap_ldap.c | 48 ++---
source3/winbindd/idmap_rfc2307.c | 2 +-
7 files changed, 330 insertions(+), 209 deletions(-)
diff --git a/source3/include/smbldap.h b/source3/include/smbldap.h
index 0310049..c2ff62e 100644
--- a/source3/include/smbldap.h
+++ b/source3/include/smbldap.h
@@ -68,6 +68,8 @@ NTSTATUS smbldap_init(TALLOC_CTX *mem_ctx,
const char *bind_secret,
struct smbldap_state **smbldap_state);
+LDAP *smbldap_get_ld(struct smbldap_state *state);
+
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/smbldap.c b/source3/lib/smbldap.c
index 2ef112f..0a8679f 100644
--- a/source3/lib/smbldap.c
+++ b/source3/lib/smbldap.c
@@ -35,6 +35,11 @@
#define SMBLDAP_IDLE_TIME 150 /* After 2.5 minutes disconnect */
+LDAP *smbldap_get_ld(struct smbldap_state *state)
+{
+ return state->ldap_struct;
+}
+
/*******************************************************************
Search an attribute and return the first value found.
@@ -943,7 +948,7 @@ static int rebindproc_connect (LDAP * ld, LDAP_CONST char *url, int request,
******************************************************************/
static int smbldap_connect_system(struct smbldap_state *ldap_state)
{
- LDAP *ldap_struct = ldap_state->ldap_struct;
+ LDAP *ldap_struct = smbldap_get_ld(ldap_state);
int rc;
int version;
@@ -988,7 +993,8 @@ static int smbldap_connect_system(struct smbldap_state *ldap_state)
if (rc != LDAP_SUCCESS) {
char *ld_error = NULL;
- ldap_get_option(ldap_state->ldap_struct, LDAP_OPT_ERROR_STRING,
+ ldap_get_option(smbldap_get_ld(ldap_state),
+ LDAP_OPT_ERROR_STRING,
&ld_error);
DEBUG(ldap_state->num_failures ? 2 : 0,
("failed to bind to server %s with dn=\"%s\" Error: %s\n\t%s\n",
@@ -1004,9 +1010,11 @@ static int smbldap_connect_system(struct smbldap_state *ldap_state)
ldap_state->num_failures = 0;
ldap_state->paged_results = False;
- ldap_get_option(ldap_state->ldap_struct, LDAP_OPT_PROTOCOL_VERSION, &version);
+ ldap_get_option(smbldap_get_ld(ldap_state), LDAP_OPT_PROTOCOL_VERSION,
+ &version);
- if (smbldap_has_control(ldap_state->ldap_struct, ADS_PAGE_CTL_OID) && version == 3) {
+ if (smbldap_has_control(smbldap_get_ld(ldap_state), ADS_PAGE_CTL_OID)
+ && version == 3) {
ldap_state->paged_results = True;
}
@@ -1035,7 +1043,9 @@ static int smbldap_open(struct smbldap_state *ldap_state)
bool reopen = False;
SMB_ASSERT(ldap_state);
- if ((ldap_state->ldap_struct != NULL) && ((ldap_state->last_ping + SMBLDAP_DONT_PING_TIME) < time_mono(NULL))) {
+ if ((smbldap_get_ld(ldap_state) != NULL) &&
+ ((ldap_state->last_ping + SMBLDAP_DONT_PING_TIME) <
+ time_mono(NULL))) {
#ifdef HAVE_UNIXSOCKET
struct sockaddr_un addr;
@@ -1045,7 +1055,8 @@ static int smbldap_open(struct smbldap_state *ldap_state)
socklen_t len = sizeof(addr);
int sd;
- opt_rc = ldap_get_option(ldap_state->ldap_struct, LDAP_OPT_DESC, &sd);
+ opt_rc = ldap_get_option(smbldap_get_ld(ldap_state),
+ LDAP_OPT_DESC, &sd);
if (opt_rc == 0 && (getpeername(sd, (struct sockaddr *) &addr, &len)) < 0 )
reopen = True;
@@ -1055,15 +1066,15 @@ static int smbldap_open(struct smbldap_state *ldap_state)
#endif
if (reopen) {
/* the other end has died. reopen. */
- ldap_unbind(ldap_state->ldap_struct);
- ldap_state->ldap_struct = NULL;
+ ldap_unbind(smbldap_get_ld(ldap_state));
+ ldap_state->ldap_struct = NULL;
ldap_state->last_ping = (time_t)0;
} else {
ldap_state->last_ping = time_mono(NULL);
}
}
- if (ldap_state->ldap_struct != NULL) {
+ if (smbldap_get_ld(ldap_state) != NULL) {
DEBUG(11,("smbldap_open: already connected to the LDAP server\n"));
return LDAP_SUCCESS;
}
@@ -1102,8 +1113,8 @@ static NTSTATUS smbldap_close(struct smbldap_state *ldap_state)
if (!ldap_state)
return NT_STATUS_INVALID_PARAMETER;
- if (ldap_state->ldap_struct != NULL) {
- ldap_unbind(ldap_state->ldap_struct);
+ if (smbldap_get_ld(ldap_state) != NULL) {
+ ldap_unbind(smbldap_get_ld(ldap_state));
ldap_state->ldap_struct = NULL;
}
@@ -1172,10 +1183,10 @@ static void setup_ldap_local_alarm(struct smbldap_state *ldap_state, time_t abso
static void get_ldap_errs(struct smbldap_state *ldap_state, char **pp_ld_error, int *p_ld_errno)
{
- ldap_get_option(ldap_state->ldap_struct,
+ ldap_get_option(smbldap_get_ld(ldap_state),
LDAP_OPT_ERROR_NUMBER, p_ld_errno);
- ldap_get_option(ldap_state->ldap_struct,
+ ldap_get_option(smbldap_get_ld(ldap_state),
LDAP_OPT_ERROR_STRING, pp_ld_error);
}
@@ -1295,7 +1306,8 @@ static int smbldap_search_ext(struct smbldap_state *ldap_state,
break;
}
- rc = ldap_search_ext_s(ldap_state->ldap_struct, base, scope,
+ rc = ldap_search_ext_s(smbldap_get_ld(ldap_state),
+ base, scope,
utf8_filter,
discard_const_p(char *, attrs),
attrsonly, sctrls, cctrls, timeout_ptr,
@@ -1315,7 +1327,7 @@ static int smbldap_search_ext(struct smbldap_state *ldap_state,
if (ld_errno != LDAP_SERVER_DOWN) {
break;
}
- ldap_unbind(ldap_state->ldap_struct);
+ ldap_unbind(smbldap_get_ld(ldap_state));
ldap_state->ldap_struct = NULL;
}
@@ -1390,7 +1402,7 @@ int smbldap_search_paged(struct smbldap_state *ldap_state,
DEBUG(3,("smbldap_search_paged: search was successful\n"));
- rc = ldap_parse_result(ldap_state->ldap_struct, *res, NULL, NULL,
+ rc = ldap_parse_result(smbldap_get_ld(ldap_state), *res, NULL, NULL,
NULL, NULL, &rcontrols, 0);
if (rc != 0) {
DEBUG(3,("smbldap_search_paged: ldap_parse_result failed " \
@@ -1449,7 +1461,7 @@ int smbldap_modify(struct smbldap_state *ldap_state, const char *dn, LDAPMod *at
break;
}
- rc = ldap_modify_s(ldap_state->ldap_struct, utf8_dn, attrs);
+ rc = ldap_modify_s(smbldap_get_ld(ldap_state), utf8_dn, attrs);
if (rc == LDAP_SUCCESS) {
break;
}
@@ -1465,7 +1477,7 @@ int smbldap_modify(struct smbldap_state *ldap_state, const char *dn, LDAPMod *at
if (ld_errno != LDAP_SERVER_DOWN) {
break;
}
- ldap_unbind(ldap_state->ldap_struct);
+ ldap_unbind(smbldap_get_ld(ldap_state));
ldap_state->ldap_struct = NULL;
}
@@ -1499,7 +1511,7 @@ int smbldap_add(struct smbldap_state *ldap_state, const char *dn, LDAPMod *attrs
break;
}
- rc = ldap_add_s(ldap_state->ldap_struct, utf8_dn, attrs);
+ rc = ldap_add_s(smbldap_get_ld(ldap_state), utf8_dn, attrs);
if (rc == LDAP_SUCCESS) {
break;
}
@@ -1515,7 +1527,7 @@ int smbldap_add(struct smbldap_state *ldap_state, const char *dn, LDAPMod *attrs
if (ld_errno != LDAP_SERVER_DOWN) {
break;
}
- ldap_unbind(ldap_state->ldap_struct);
+ ldap_unbind(smbldap_get_ld(ldap_state));
ldap_state->ldap_struct = NULL;
}
@@ -1549,7 +1561,7 @@ int smbldap_delete(struct smbldap_state *ldap_state, const char *dn)
break;
}
- rc = ldap_delete_s(ldap_state->ldap_struct, utf8_dn);
+ rc = ldap_delete_s(smbldap_get_ld(ldap_state), utf8_dn);
if (rc == LDAP_SUCCESS) {
break;
}
@@ -1565,7 +1577,7 @@ int smbldap_delete(struct smbldap_state *ldap_state, const char *dn)
if (ld_errno != LDAP_SERVER_DOWN) {
break;
}
- ldap_unbind(ldap_state->ldap_struct);
+ ldap_unbind(smbldap_get_ld(ldap_state));
ldap_state->ldap_struct = NULL;
}
@@ -1595,7 +1607,8 @@ int smbldap_extended_operation(struct smbldap_state *ldap_state,
break;
}
- rc = ldap_extended_operation_s(ldap_state->ldap_struct, reqoid,
+ rc = ldap_extended_operation_s(smbldap_get_ld(ldap_state),
+ reqoid,
reqdata, serverctrls,
clientctrls, retoidp, retdatap);
if (rc == LDAP_SUCCESS) {
@@ -1613,7 +1626,7 @@ int smbldap_extended_operation(struct smbldap_state *ldap_state,
if (ld_errno != LDAP_SERVER_DOWN) {
break;
}
- ldap_unbind(ldap_state->ldap_struct);
+ ldap_unbind(smbldap_get_ld(ldap_state));
ldap_state->ldap_struct = NULL;
}
@@ -1641,7 +1654,7 @@ static void smbldap_idle_fn(struct tevent_context *tevent_ctx,
TALLOC_FREE(state->idle_event);
- if (state->ldap_struct == NULL) {
+ if (smbldap_get_ld(state) == NULL) {
DEBUG(10,("ldap connection not connected...\n"));
return;
}
diff --git a/source3/passdb/pdb_ldap.c b/source3/passdb/pdb_ldap.c
index b5c6cbf..f9180ab 100644
--- a/source3/passdb/pdb_ldap.c
+++ b/source3/passdb/pdb_ldap.c
@@ -74,7 +74,7 @@
LDAP *priv2ld(struct ldapsam_privates *priv)
{
- return priv->smbldap_state->ldap_struct;
+ return smbldap_get_ld(priv->smbldap_state);
}
/**********************************************************************
@@ -191,7 +191,9 @@ static NTSTATUS ldapsam_get_seq_num(struct pdb_methods *my_methods, time_t *seq_
return ntstatus;
}
- if (!smbldap_has_naming_context(ldap_state->smbldap_state->ldap_struct, lp_ldap_suffix(talloc_tos()))) {
+ if (!smbldap_has_naming_context(
+ smbldap_get_ld(ldap_state->smbldap_state),
+ lp_ldap_suffix(talloc_tos()))) {
DEBUG(3,("ldapsam_get_seq_num: DIT not configured to hold %s "
"as top-level namingContext\n", lp_ldap_suffix(talloc_tos())));
return ntstatus;
@@ -243,19 +245,22 @@ static NTSTATUS ldapsam_get_seq_num(struct pdb_methods *my_methods, time_t *seq_
goto done;
}
- num_result = ldap_count_entries(ldap_state->smbldap_state->ldap_struct, msg);
+ num_result = ldap_count_entries(
+ smbldap_get_ld(ldap_state->smbldap_state), msg);
if (num_result != 1) {
DEBUG(3,("ldapsam_get_seq_num: Expected one entry, got %d\n", num_result));
goto done;
}
- entry = ldap_first_entry(ldap_state->smbldap_state->ldap_struct, msg);
+ entry = ldap_first_entry(
+ smbldap_get_ld(ldap_state->smbldap_state), msg);
if (entry == NULL) {
DEBUG(3,("ldapsam_get_seq_num: Could not retrieve entry\n"));
goto done;
}
- values = ldap_get_values(ldap_state->smbldap_state->ldap_struct, entry, attrs[0]);
+ values = ldap_get_values(
+ smbldap_get_ld(ldap_state->smbldap_state), entry, attrs[0]);
if (values == NULL) {
DEBUG(3,("ldapsam_get_seq_num: no values\n"));
goto done;
@@ -435,8 +440,10 @@ static time_t ldapsam_get_entry_timestamp( struct ldapsam_privates *ldap_state,
char *temp;
struct tm tm;
- temp = smbldap_talloc_single_attribute(ldap_state->smbldap_state->ldap_struct, entry,
- get_userattr_key2string(ldap_state->schema_ver,LDAP_ATTR_MOD_TIMESTAMP),
+ temp = smbldap_talloc_single_attribute(
+ smbldap_get_ld(ldap_state->smbldap_state), entry,
+ get_userattr_key2string(ldap_state->schema_ver,
+ LDAP_ATTR_MOD_TIMESTAMP),
talloc_tos());
if (!temp) {
return (time_t) 0;
@@ -541,7 +548,7 @@ static bool init_sam_from_ldap(struct ldapsam_privates *ldap_state,
if ( ldap_state->schema_ver == SCHEMAVER_SAMBASAMACCOUNT ) {
if ((temp = smbldap_talloc_single_attribute(
- ldap_state->smbldap_state->ldap_struct,
+ smbldap_get_ld(ldap_state->smbldap_state),
entry,
get_userattr_key2string(ldap_state->schema_ver,
LDAP_ATTR_USER_SID),
@@ -550,7 +557,7 @@ static bool init_sam_from_ldap(struct ldapsam_privates *ldap_state,
}
} else {
if ((temp = smbldap_talloc_single_attribute(
- ldap_state->smbldap_state->ldap_struct,
+ smbldap_get_ld(ldap_state->smbldap_state),
entry,
get_userattr_key2string(ldap_state->schema_ver,
LDAP_ATTR_USER_RID),
@@ -571,7 +578,7 @@ static bool init_sam_from_ldap(struct ldapsam_privates *ldap_state,
}
temp = smbldap_talloc_single_attribute(
- ldap_state->smbldap_state->ldap_struct,
+ smbldap_get_ld(ldap_state->smbldap_state),
entry,
get_userattr_key2string(ldap_state->schema_ver,
LDAP_ATTR_PWD_LAST_SET),
@@ -583,7 +590,7 @@ static bool init_sam_from_ldap(struct ldapsam_privates *ldap_state,
}
temp = smbldap_talloc_single_attribute(
- ldap_state->smbldap_state->ldap_struct,
+ smbldap_get_ld(ldap_state->smbldap_state),
entry,
get_userattr_key2string(ldap_state->schema_ver,
LDAP_ATTR_LOGON_TIME),
@@ -594,7 +601,7 @@ static bool init_sam_from_ldap(struct ldapsam_privates *ldap_state,
}
temp = smbldap_talloc_single_attribute(
- ldap_state->smbldap_state->ldap_struct,
+ smbldap_get_ld(ldap_state->smbldap_state),
entry,
get_userattr_key2string(ldap_state->schema_ver,
LDAP_ATTR_LOGOFF_TIME),
@@ -605,7 +612,7 @@ static bool init_sam_from_ldap(struct ldapsam_privates *ldap_state,
}
temp = smbldap_talloc_single_attribute(
- ldap_state->smbldap_state->ldap_struct,
+ smbldap_get_ld(ldap_state->smbldap_state),
entry,
get_userattr_key2string(ldap_state->schema_ver,
LDAP_ATTR_KICKOFF_TIME),
@@ -616,7 +623,7 @@ static bool init_sam_from_ldap(struct ldapsam_privates *ldap_state,
}
temp = smbldap_talloc_single_attribute(
- ldap_state->smbldap_state->ldap_struct,
+ smbldap_get_ld(ldap_state->smbldap_state),
entry,
get_userattr_key2string(ldap_state->schema_ver,
LDAP_ATTR_PWD_CAN_CHANGE),
@@ -634,7 +641,7 @@ static bool init_sam_from_ldap(struct ldapsam_privates *ldap_state,
*/
fullname = smbldap_talloc_single_attribute(
- ldap_state->smbldap_state->ldap_struct,
+ smbldap_get_ld(ldap_state->smbldap_state),
entry,
get_userattr_key2string(ldap_state->schema_ver,
LDAP_ATTR_DISPLAY_NAME),
@@ -643,7 +650,7 @@ static bool init_sam_from_ldap(struct ldapsam_privates *ldap_state,
pdb_set_fullname(sampass, fullname, PDB_SET);
} else {
fullname = smbldap_talloc_single_attribute(
- ldap_state->smbldap_state->ldap_struct,
+ smbldap_get_ld(ldap_state->smbldap_state),
entry,
get_userattr_key2string(ldap_state->schema_ver,
LDAP_ATTR_CN),
@@ -654,7 +661,7 @@ static bool init_sam_from_ldap(struct ldapsam_privates *ldap_state,
}
dir_drive = smbldap_talloc_single_attribute(
- ldap_state->smbldap_state->ldap_struct,
+ smbldap_get_ld(ldap_state->smbldap_state),
entry,
get_userattr_key2string(ldap_state->schema_ver,
LDAP_ATTR_HOME_DRIVE),
@@ -666,7 +673,7 @@ static bool init_sam_from_ldap(struct ldapsam_privates *ldap_state,
}
homedir = smbldap_talloc_single_attribute(
- ldap_state->smbldap_state->ldap_struct,
+ smbldap_get_ld(ldap_state->smbldap_state),
entry,
get_userattr_key2string(ldap_state->schema_ver,
LDAP_ATTR_HOME_PATH),
@@ -690,7 +697,7 @@ static bool init_sam_from_ldap(struct ldapsam_privates *ldap_state,
}
logon_script = smbldap_talloc_single_attribute(
- ldap_state->smbldap_state->ldap_struct,
+ smbldap_get_ld(ldap_state->smbldap_state),
entry,
get_userattr_key2string(ldap_state->schema_ver,
LDAP_ATTR_LOGON_SCRIPT),
@@ -714,7 +721,7 @@ static bool init_sam_from_ldap(struct ldapsam_privates *ldap_state,
}
profile_path = smbldap_talloc_single_attribute(
- ldap_state->smbldap_state->ldap_struct,
+ smbldap_get_ld(ldap_state->smbldap_state),
entry,
get_userattr_key2string(ldap_state->schema_ver,
LDAP_ATTR_PROFILE_PATH),
@@ -738,7 +745,7 @@ static bool init_sam_from_ldap(struct ldapsam_privates *ldap_state,
}
acct_desc = smbldap_talloc_single_attribute(
- ldap_state->smbldap_state->ldap_struct,
+ smbldap_get_ld(ldap_state->smbldap_state),
entry,
get_userattr_key2string(ldap_state->schema_ver,
LDAP_ATTR_DESC),
@@ -748,7 +755,7 @@ static bool init_sam_from_ldap(struct ldapsam_privates *ldap_state,
}
workstations = smbldap_talloc_single_attribute(
- ldap_state->smbldap_state->ldap_struct,
+ smbldap_get_ld(ldap_state->smbldap_state),
entry,
get_userattr_key2string(ldap_state->schema_ver,
LDAP_ATTR_USER_WKS),
@@ -758,7 +765,7 @@ static bool init_sam_from_ldap(struct ldapsam_privates *ldap_state,
}
munged_dial = smbldap_talloc_single_attribute(
- ldap_state->smbldap_state->ldap_struct,
+ smbldap_get_ld(ldap_state->smbldap_state),
entry,
get_userattr_key2string(ldap_state->schema_ver,
LDAP_ATTR_MUNGED_DIAL),
@@ -780,7 +787,8 @@ static bool init_sam_from_ldap(struct ldapsam_privates *ldap_state,
/* Make call to Novell eDirectory ldap extension to get clear text password.
NOTE: This will only work if we have an SSL connection to eDirectory. */
- user_dn = smbldap_talloc_dn(ctx, ldap_state->smbldap_state->ldap_struct, entry);
+ user_dn = smbldap_talloc_dn(
+ ctx, smbldap_get_ld(ldap_state->smbldap_state), entry);
if (user_dn != NULL) {
DEBUG(3, ("init_sam_from_ldap: smbldap_talloc_dn(ctx, %s) returned '%s'\n", username, user_dn));
@@ -809,7 +817,7 @@ static bool init_sam_from_ldap(struct ldapsam_privates *ldap_state,
if (use_samba_attrs) {
temp = smbldap_talloc_single_attribute(
- ldap_state->smbldap_state->ldap_struct,
+ smbldap_get_ld(ldap_state->smbldap_state),
entry,
get_userattr_key2string(ldap_state->schema_ver,
LDAP_ATTR_LMPW),
@@ -824,7 +832,7 @@ static bool init_sam_from_ldap(struct ldapsam_privates *ldap_state,
}
temp = smbldap_talloc_single_attribute(
- ldap_state->smbldap_state->ldap_struct,
+ smbldap_get_ld(ldap_state->smbldap_state),
entry,
get_userattr_key2string(ldap_state->schema_ver,
LDAP_ATTR_NTPW),
@@ -862,7 +870,7 @@ static bool init_sam_from_ldap(struct ldapsam_privates *ldap_state,
}
if (smbldap_get_single_attribute(
- ldap_state->smbldap_state->ldap_struct,
+ smbldap_get_ld(ldap_state->smbldap_state),
entry,
get_userattr_key2string(ldap_state->schema_ver,
LDAP_ATTR_PWD_HISTORY),
@@ -896,7 +904,7 @@ static bool init_sam_from_ldap(struct ldapsam_privates *ldap_state,
}
temp = smbldap_talloc_single_attribute(
- ldap_state->smbldap_state->ldap_struct,
+ smbldap_get_ld(ldap_state->smbldap_state),
entry,
get_userattr_key2string(ldap_state->schema_ver,
LDAP_ATTR_ACB_INFO),
@@ -917,7 +925,7 @@ static bool init_sam_from_ldap(struct ldapsam_privates *ldap_state,
pdb_set_logon_divs(sampass, logon_divs, PDB_SET);
temp = smbldap_talloc_single_attribute(
- ldap_state->smbldap_state->ldap_struct,
+ smbldap_get_ld(ldap_state->smbldap_state),
entry,
get_userattr_key2string(ldap_state->schema_ver,
LDAP_ATTR_BAD_PASSWORD_COUNT),
@@ -929,7 +937,7 @@ static bool init_sam_from_ldap(struct ldapsam_privates *ldap_state,
}
temp = smbldap_talloc_single_attribute(
- ldap_state->smbldap_state->ldap_struct,
+ smbldap_get_ld(ldap_state->smbldap_state),
entry,
get_userattr_key2string(ldap_state->schema_ver,
LDAP_ATTR_BAD_PASSWORD_TIME),
@@ -941,7 +949,7 @@ static bool init_sam_from_ldap(struct ldapsam_privates *ldap_state,
temp = smbldap_talloc_single_attribute(
- ldap_state->smbldap_state->ldap_struct,
+ smbldap_get_ld(ldap_state->smbldap_state),
entry,
get_userattr_key2string(ldap_state->schema_ver,
LDAP_ATTR_LOGON_COUNT),
@@ -954,7 +962,7 @@ static bool init_sam_from_ldap(struct ldapsam_privates *ldap_state,
/* pdb_set_unknown_6(sampass, unknown6, PDB_SET); */
temp = smbldap_talloc_single_attribute(
- ldap_state->smbldap_state->ldap_struct,
+ smbldap_get_ld(ldap_state->smbldap_state),
entry,
get_userattr_key2string(ldap_state->schema_ver,
LDAP_ATTR_LOGON_HOURS),
@@ -1124,13 +1132,18 @@ static bool init_ldap_from_sam (struct ldapsam_privates *ldap_state,
* do this on a per-mod basis
*/
if (need_update(sampass, PDB_USERNAME)) {
- smbldap_make_mod(ldap_state->smbldap_state->ldap_struct, existing, mods,
- "uid", pdb_get_username(sampass));
+ smbldap_make_mod(smbldap_get_ld(ldap_state->smbldap_state),
+ existing, mods,
+ "uid", pdb_get_username(sampass));
if (ldap_state->is_nds_ldap) {
- smbldap_make_mod(ldap_state->smbldap_state->ldap_struct, existing, mods,
- "cn", pdb_get_username(sampass));
- smbldap_make_mod(ldap_state->smbldap_state->ldap_struct, existing, mods,
- "sn", pdb_get_username(sampass));
+ smbldap_make_mod(
+ smbldap_get_ld(ldap_state->smbldap_state),
+ existing, mods,
+ "cn", pdb_get_username(sampass));
+ smbldap_make_mod(
+ smbldap_get_ld(ldap_state->smbldap_state),
+ existing, mods,
+ "sn", pdb_get_username(sampass));
}
}
@@ -1143,7 +1156,10 @@ static bool init_ldap_from_sam (struct ldapsam_privates *ldap_state,
switch ( ldap_state->schema_ver ) {
case SCHEMAVER_SAMBASAMACCOUNT:
- smbldap_make_mod(ldap_state->smbldap_state->ldap_struct, existing, mods,
+ smbldap_make_mod(
+ smbldap_get_ld(
+ ldap_state->smbldap_state),
+ existing, mods,
get_userattr_key2string(ldap_state->schema_ver, LDAP_ATTR_USER_SID),
sid_to_fstring(sid_string, user_sid));
break;
@@ -1163,7 +1179,10 @@ static bool init_ldap_from_sam (struct ldapsam_privates *ldap_state,
switch ( ldap_state->schema_ver ) {
case SCHEMAVER_SAMBASAMACCOUNT:
- smbldap_make_mod(ldap_state->smbldap_state->ldap_struct, existing, mods,
+ smbldap_make_mod(
+ smbldap_get_ld(
+ ldap_state->smbldap_state),
+ existing, mods,
get_userattr_key2string(ldap_state->schema_ver,
LDAP_ATTR_PRIMARY_GROUP_SID), sid_to_fstring(sid_string, group_sid));
break;
@@ -1184,42 +1203,50 @@ static bool init_ldap_from_sam (struct ldapsam_privates *ldap_state,
*/
if (need_update(sampass, PDB_FULLNAME))
- smbldap_make_mod(ldap_state->smbldap_state->ldap_struct, existing, mods,
+ smbldap_make_mod(smbldap_get_ld(ldap_state->smbldap_state),
+ existing, mods,
get_userattr_key2string(ldap_state->schema_ver, LDAP_ATTR_DISPLAY_NAME),
pdb_get_fullname(sampass));
if (need_update(sampass, PDB_ACCTDESC))
- smbldap_make_mod(ldap_state->smbldap_state->ldap_struct, existing, mods,
+ smbldap_make_mod(smbldap_get_ld(ldap_state->smbldap_state),
+ existing, mods,
get_userattr_key2string(ldap_state->schema_ver, LDAP_ATTR_DESC),
pdb_get_acct_desc(sampass));
if (need_update(sampass, PDB_WORKSTATIONS))
- smbldap_make_mod(ldap_state->smbldap_state->ldap_struct, existing, mods,
+ smbldap_make_mod(smbldap_get_ld(ldap_state->smbldap_state),
+ existing, mods,
get_userattr_key2string(ldap_state->schema_ver, LDAP_ATTR_USER_WKS),
pdb_get_workstations(sampass));
if (need_update(sampass, PDB_MUNGEDDIAL))
- smbldap_make_mod(ldap_state->smbldap_state->ldap_struct, existing, mods,
+ smbldap_make_mod(smbldap_get_ld(ldap_state->smbldap_state),
+ existing, mods,
get_userattr_key2string(ldap_state->schema_ver, LDAP_ATTR_MUNGED_DIAL),
pdb_get_munged_dial(sampass));
if (need_update(sampass, PDB_SMBHOME))
- smbldap_make_mod(ldap_state->smbldap_state->ldap_struct, existing, mods,
+ smbldap_make_mod(smbldap_get_ld(ldap_state->smbldap_state),
+ existing, mods,
get_userattr_key2string(ldap_state->schema_ver, LDAP_ATTR_HOME_PATH),
pdb_get_homedir(sampass));
if (need_update(sampass, PDB_DRIVE))
- smbldap_make_mod(ldap_state->smbldap_state->ldap_struct, existing, mods,
+ smbldap_make_mod(smbldap_get_ld(ldap_state->smbldap_state),
+ existing, mods,
get_userattr_key2string(ldap_state->schema_ver, LDAP_ATTR_HOME_DRIVE),
pdb_get_dir_drive(sampass));
if (need_update(sampass, PDB_LOGONSCRIPT))
- smbldap_make_mod(ldap_state->smbldap_state->ldap_struct, existing, mods,
+ smbldap_make_mod(smbldap_get_ld(ldap_state->smbldap_state),
+ existing, mods,
get_userattr_key2string(ldap_state->schema_ver, LDAP_ATTR_LOGON_SCRIPT),
pdb_get_logon_script(sampass));
if (need_update(sampass, PDB_PROFILE))
- smbldap_make_mod(ldap_state->smbldap_state->ldap_struct, existing, mods,
+ smbldap_make_mod(smbldap_get_ld(ldap_state->smbldap_state),
+ existing, mods,
get_userattr_key2string(ldap_state->schema_ver, LDAP_ATTR_PROFILE_PATH),
pdb_get_profile_path(sampass));
@@ -1227,7 +1254,8 @@ static bool init_ldap_from_sam (struct ldapsam_privates *ldap_state,
return false;
}
if (need_update(sampass, PDB_LOGONTIME))
- smbldap_make_mod(ldap_state->smbldap_state->ldap_struct, existing, mods,
+ smbldap_make_mod(smbldap_get_ld(ldap_state->smbldap_state),
+ existing, mods,
get_userattr_key2string(ldap_state->schema_ver, LDAP_ATTR_LOGON_TIME), temp);
SAFE_FREE(temp);
@@ -1235,7 +1263,8 @@ static bool init_ldap_from_sam (struct ldapsam_privates *ldap_state,
return false;
}
if (need_update(sampass, PDB_LOGOFFTIME))
- smbldap_make_mod(ldap_state->smbldap_state->ldap_struct, existing, mods,
+ smbldap_make_mod(smbldap_get_ld(ldap_state->smbldap_state),
+ existing, mods,
get_userattr_key2string(ldap_state->schema_ver, LDAP_ATTR_LOGOFF_TIME), temp);
SAFE_FREE(temp);
@@ -1243,7 +1272,8 @@ static bool init_ldap_from_sam (struct ldapsam_privates *ldap_state,
return false;
}
if (need_update(sampass, PDB_KICKOFFTIME))
- smbldap_make_mod(ldap_state->smbldap_state->ldap_struct, existing, mods,
+ smbldap_make_mod(smbldap_get_ld(ldap_state->smbldap_state),
+ existing, mods,
get_userattr_key2string(ldap_state->schema_ver, LDAP_ATTR_KICKOFF_TIME), temp);
SAFE_FREE(temp);
@@ -1251,7 +1281,8 @@ static bool init_ldap_from_sam (struct ldapsam_privates *ldap_state,
return false;
}
if (need_update(sampass, PDB_CANCHANGETIME))
- smbldap_make_mod(ldap_state->smbldap_state->ldap_struct, existing, mods,
+ smbldap_make_mod(smbldap_get_ld(ldap_state->smbldap_state),
+ existing, mods,
get_userattr_key2string(ldap_state->schema_ver, LDAP_ATTR_PWD_CAN_CHANGE), temp);
SAFE_FREE(temp);
@@ -1264,11 +1295,17 @@ static bool init_ldap_from_sam (struct ldapsam_privates *ldap_state,
char pwstr[34];
pdb_sethexpwd(pwstr, lm_pw,
pdb_get_acct_ctrl(sampass));
- smbldap_make_mod(ldap_state->smbldap_state->ldap_struct, existing, mods,
+ smbldap_make_mod(
+ smbldap_get_ld(
+ ldap_state->smbldap_state),
+ existing, mods,
get_userattr_key2string(ldap_state->schema_ver, LDAP_ATTR_LMPW),
pwstr);
} else {
- smbldap_make_mod(ldap_state->smbldap_state->ldap_struct, existing, mods,
+ smbldap_make_mod(
+ smbldap_get_ld(
+ ldap_state->smbldap_state),
+ existing, mods,
get_userattr_key2string(ldap_state->schema_ver, LDAP_ATTR_LMPW),
NULL);
}
@@ -1279,11 +1316,17 @@ static bool init_ldap_from_sam (struct ldapsam_privates *ldap_state,
char pwstr[34];
pdb_sethexpwd(pwstr, nt_pw,
pdb_get_acct_ctrl(sampass));
- smbldap_make_mod(ldap_state->smbldap_state->ldap_struct, existing, mods,
+ smbldap_make_mod(
+ smbldap_get_ld(
+ ldap_state->smbldap_state),
+ existing, mods,
get_userattr_key2string(ldap_state->schema_ver, LDAP_ATTR_NTPW),
pwstr);
} else {
- smbldap_make_mod(ldap_state->smbldap_state->ldap_struct, existing, mods,
+ smbldap_make_mod(
+ smbldap_get_ld(
+ ldap_state->smbldap_state),
+ existing, mods,
get_userattr_key2string(ldap_state->schema_ver, LDAP_ATTR_NTPW),
NULL);
}
@@ -1319,7 +1362,9 @@ static bool init_ldap_from_sam (struct ldapsam_privates *ldap_state,
}
}
}
- smbldap_make_mod(ldap_state->smbldap_state->ldap_struct, existing, mods,
+ smbldap_make_mod(
+ smbldap_get_ld(ldap_state->smbldap_state),
+ existing, mods,
get_userattr_key2string(ldap_state->schema_ver, LDAP_ATTR_PWD_HISTORY),
pwstr);
SAFE_FREE(pwstr);
@@ -1330,7 +1375,9 @@ static bool init_ldap_from_sam (struct ldapsam_privates *ldap_state,
(long int)pdb_get_pass_last_set_time(sampass)) < 0) {
return false;
}
- smbldap_make_mod(ldap_state->smbldap_state->ldap_struct, existing, mods,
+ smbldap_make_mod(
+ smbldap_get_ld(ldap_state->smbldap_state),
+ existing, mods,
get_userattr_key2string(ldap_state->schema_ver, LDAP_ATTR_PWD_LAST_SET),
temp);
SAFE_FREE(temp);
@@ -1342,7 +1389,8 @@ static bool init_ldap_from_sam (struct ldapsam_privates *ldap_state,
if (hours) {
char hourstr[44];
pdb_sethexhours(hourstr, hours);
- smbldap_make_mod(ldap_state->smbldap_state->ldap_struct,
+ smbldap_make_mod(
+ smbldap_get_ld(ldap_state->smbldap_state),
existing,
mods,
get_userattr_key2string(ldap_state->schema_ver,
@@ -1352,7 +1400,9 @@ static bool init_ldap_from_sam (struct ldapsam_privates *ldap_state,
}
if (need_update(sampass, PDB_ACCTCTRL))
- smbldap_make_mod(ldap_state->smbldap_state->ldap_struct, existing, mods,
+ smbldap_make_mod(
+ smbldap_get_ld(ldap_state->smbldap_state),
+ existing, mods,
get_userattr_key2string(ldap_state->schema_ver, LDAP_ATTR_ACB_INFO),
pdb_encode_acct_ctrl (pdb_get_acct_ctrl(sampass), NEW_PW_FORMAT_SPACE_PADDED_LEN));
@@ -1381,7 +1431,7 @@ static bool init_ldap_from_sam (struct ldapsam_privates *ldap_state,
return false;
}
smbldap_make_mod(
- ldap_state->smbldap_state->ldap_struct,
+ smbldap_get_ld(ldap_state->smbldap_state),
existing, mods,
get_userattr_key2string(
ldap_state->schema_ver,
@@ -1393,7 +1443,7 @@ static bool init_ldap_from_sam (struct ldapsam_privates *ldap_state,
return false;
}
smbldap_make_mod(
- ldap_state->smbldap_state->ldap_struct,
+ smbldap_get_ld(ldap_state->smbldap_state),
existing, mods,
get_userattr_key2string(
ldap_state->schema_ver,
@@ -1489,7 +1539,8 @@ static NTSTATUS ldapsam_getsampwnam(struct pdb_methods *my_methods, struct samu
if ( rc != LDAP_SUCCESS )
return NT_STATUS_NO_SUCH_USER;
- count = ldap_count_entries(ldap_state->smbldap_state->ldap_struct, result);
+ count = ldap_count_entries(smbldap_get_ld(ldap_state->smbldap_state),
+ result);
if (count < 1) {
DEBUG(4, ("ldapsam_getsampwnam: Unable to locate user [%s] count=%d\n", sname, count));
@@ -1501,7 +1552,8 @@ static NTSTATUS ldapsam_getsampwnam(struct pdb_methods *my_methods, struct samu
return NT_STATUS_NO_SUCH_USER;
}
- entry = ldap_first_entry(ldap_state->smbldap_state->ldap_struct, result);
+ entry = ldap_first_entry(smbldap_get_ld(ldap_state->smbldap_state),
+ result);
if (entry) {
if (!init_sam_from_ldap(ldap_state, user, entry)) {
DEBUG(1,("ldapsam_getsampwnam: init_sam_from_ldap failed for user '%s'!\n", sname));
@@ -1571,7 +1623,8 @@ static NTSTATUS ldapsam_getsampwsid(struct pdb_methods *my_methods, struct samu
if (rc != LDAP_SUCCESS)
return NT_STATUS_NO_SUCH_USER;
- count = ldap_count_entries(ldap_state->smbldap_state->ldap_struct, result);
+ count = ldap_count_entries(smbldap_get_ld(ldap_state->smbldap_state),
+ result);
if (count < 1) {
DEBUG(4, ("ldapsam_getsampwsid: Unable to locate SID [%s] "
@@ -1586,7 +1639,8 @@ static NTSTATUS ldapsam_getsampwsid(struct pdb_methods *my_methods, struct samu
return NT_STATUS_NO_SUCH_USER;
}
- entry = ldap_first_entry(ldap_state->smbldap_state->ldap_struct, result);
+ entry = ldap_first_entry(smbldap_get_ld(ldap_state->smbldap_state),
+ result);
if (!entry) {
ldap_msgfree(result);
return NT_STATUS_NO_SUCH_USER;
@@ -1636,7 +1690,8 @@ static NTSTATUS ldapsam_modify_entry(struct pdb_methods *my_methods,
if (!ldap_state->is_nds_ldap) {
- if (!smbldap_has_extension(ldap_state->smbldap_state->ldap_struct,
+ if (!smbldap_has_extension(
+ smbldap_get_ld(ldap_state->smbldap_state),
LDAP_EXOP_MODIFY_PASSWD)) {
DEBUG(2, ("ldap password change requested, but LDAP "
"server does not support it -- ignoring\n"));
@@ -1723,7 +1778,9 @@ static NTSTATUS ldapsam_modify_entry(struct pdb_methods *my_methods,
return NT_STATUS_OK;
}
- ldap_get_option(ldap_state->smbldap_state->ldap_struct, LDAP_OPT_ERROR_STRING,
+ ldap_get_option(
+ smbldap_get_ld(ldap_state->smbldap_state),
+ LDAP_OPT_ERROR_STRING,
&ld_error);
DEBUG(0,("ldapsam_modify_entry: LDAP Password could not be changed for user %s: %s\n\t%s\n",
pdb_get_username(newpwd), ldap_err2string(rc), ld_error?ld_error:"unknown"));
@@ -1875,13 +1932,17 @@ static NTSTATUS ldapsam_update_sam_account(struct pdb_methods *my_methods, struc
smbldap_talloc_autofree_ldapmsg(newpwd, result);
}
- if (ldap_count_entries(ldap_state->smbldap_state->ldap_struct, result) == 0) {
+ if (ldap_count_entries(smbldap_get_ld(ldap_state->smbldap_state),
+ result) == 0) {
DEBUG(0, ("ldapsam_update_sam_account: No user to modify!\n"));
return NT_STATUS_UNSUCCESSFUL;
}
- entry = ldap_first_entry(ldap_state->smbldap_state->ldap_struct, result);
- dn = smbldap_talloc_dn(talloc_tos(), ldap_state->smbldap_state->ldap_struct, entry);
+ entry = ldap_first_entry(smbldap_get_ld(ldap_state->smbldap_state),
+ result);
+ dn = smbldap_talloc_dn(talloc_tos(),
+ smbldap_get_ld(ldap_state->smbldap_state),
+ entry);
if (!dn) {
return NT_STATUS_UNSUCCESSFUL;
}
@@ -2071,7 +2132,8 @@ static NTSTATUS ldapsam_add_sam_account(struct pdb_methods *my_methods, struct s
goto fn_exit;
}
- if (ldap_count_entries(ldap_state->smbldap_state->ldap_struct, result) != 0) {
+ if (ldap_count_entries(smbldap_get_ld(ldap_state->smbldap_state),
+ result) != 0) {
DEBUG(0,("ldapsam_add_sam_account: User '%s' already in the base, with samba attributes\n",
username));
goto fn_exit;
@@ -2083,7 +2145,9 @@ static NTSTATUS ldapsam_add_sam_account(struct pdb_methods *my_methods, struct s
rc = ldapsam_get_ldap_user_by_sid(ldap_state,
sid, &result);
if (rc == LDAP_SUCCESS) {
- if (ldap_count_entries(ldap_state->smbldap_state->ldap_struct, result) != 0) {
+ if (ldap_count_entries(
+ smbldap_get_ld(ldap_state->smbldap_state),
+ result) != 0) {
DEBUG(0,("ldapsam_add_sam_account: SID '%s' "
"already in the base, with samba "
"attributes\n", sid_string_dbg(sid)));
@@ -2116,7 +2180,8 @@ static NTSTATUS ldapsam_add_sam_account(struct pdb_methods *my_methods, struct s
goto fn_exit;
}
- num_result = ldap_count_entries(ldap_state->smbldap_state->ldap_struct, result);
+ num_result = ldap_count_entries(
+ smbldap_get_ld(ldap_state->smbldap_state), result);
if (num_result > 1) {
DEBUG (0, ("ldapsam_add_sam_account: More than one user with that uid exists: bailing out!\n"));
@@ -2127,8 +2192,10 @@ static NTSTATUS ldapsam_add_sam_account(struct pdb_methods *my_methods, struct s
if (num_result == 1) {
DEBUG(3,("ldapsam_add_sam_account: User exists without samba attributes: adding them\n"));
ldap_op = LDAP_MOD_REPLACE;
- entry = ldap_first_entry (ldap_state->smbldap_state->ldap_struct, result);
- dn = smbldap_talloc_dn(ctx, ldap_state->smbldap_state->ldap_struct, entry);
+ entry = ldap_first_entry(
+ smbldap_get_ld(ldap_state->smbldap_state), result);
+ dn = smbldap_talloc_dn(
+ ctx, smbldap_get_ld(ldap_state->smbldap_state), entry);
if (!dn) {
status = NT_STATUS_NO_MEMORY;
goto fn_exit;
@@ -2162,7 +2229,8 @@ static NTSTATUS ldapsam_add_sam_account(struct pdb_methods *my_methods, struct s
goto fn_exit;
}
- num_result = ldap_count_entries(ldap_state->smbldap_state->ldap_struct, result);
+ num_result = ldap_count_entries(
+ smbldap_get_ld(ldap_state->smbldap_state), result);
if (num_result > 1) {
DEBUG (0, ("ldapsam_add_sam_account: More than one user with specified Sid exists: bailing out!\n"));
@@ -2174,8 +2242,12 @@ static NTSTATUS ldapsam_add_sam_account(struct pdb_methods *my_methods, struct s
DEBUG(3,("ldapsam_add_sam_account: User exists without samba attributes: adding them\n"));
ldap_op = LDAP_MOD_REPLACE;
- entry = ldap_first_entry (ldap_state->smbldap_state->ldap_struct, result);
- dn = smbldap_talloc_dn (ctx, ldap_state->smbldap_state->ldap_struct, entry);
+ entry = ldap_first_entry (
+ smbldap_get_ld(ldap_state->smbldap_state),
+ result);
+ dn = smbldap_talloc_dn (
+ ctx, smbldap_get_ld(ldap_state->smbldap_state),
+ entry);
if (!dn) {
status = NT_STATUS_NO_MEMORY;
goto fn_exit;
@@ -2288,14 +2360,14 @@ static bool init_group_from_ldap(struct ldapsam_privates *ldap_state,
TALLOC_CTX *ctx = talloc_init("init_group_from_ldap");
if (ldap_state == NULL || map == NULL || entry == NULL ||
- ldap_state->smbldap_state->ldap_struct == NULL) {
+ smbldap_get_ld(ldap_state->smbldap_state) == NULL) {
DEBUG(0, ("init_group_from_ldap: NULL parameters found!\n"));
TALLOC_FREE(ctx);
return false;
}
temp = smbldap_talloc_single_attribute(
- ldap_state->smbldap_state->ldap_struct,
+ smbldap_get_ld(ldap_state->smbldap_state),
entry,
get_attr_key2string(groupmap_attr_list,
LDAP_ATTR_GIDNUMBER),
@@ -2312,7 +2384,7 @@ static bool init_group_from_ldap(struct ldapsam_privates *ldap_state,
TALLOC_FREE(temp);
temp = smbldap_talloc_single_attribute(
- ldap_state->smbldap_state->ldap_struct,
+ smbldap_get_ld(ldap_state->smbldap_state),
entry,
get_attr_key2string(groupmap_attr_list,
LDAP_ATTR_GROUP_SID),
@@ -2332,7 +2404,7 @@ static bool init_group_from_ldap(struct ldapsam_privates *ldap_state,
TALLOC_FREE(temp);
temp = smbldap_talloc_single_attribute(
- ldap_state->smbldap_state->ldap_struct,
+ smbldap_get_ld(ldap_state->smbldap_state),
entry,
get_attr_key2string(groupmap_attr_list,
LDAP_ATTR_GROUP_TYPE),
@@ -2354,14 +2426,14 @@ static bool init_group_from_ldap(struct ldapsam_privates *ldap_state,
TALLOC_FREE(temp);
temp = smbldap_talloc_single_attribute(
- ldap_state->smbldap_state->ldap_struct,
+ smbldap_get_ld(ldap_state->smbldap_state),
entry,
get_attr_key2string(groupmap_attr_list,
LDAP_ATTR_DISPLAY_NAME),
ctx);
if (!temp) {
temp = smbldap_talloc_single_attribute(
- ldap_state->smbldap_state->ldap_struct,
+ smbldap_get_ld(ldap_state->smbldap_state),
entry,
get_attr_key2string(groupmap_attr_list,
LDAP_ATTR_CN),
@@ -2381,7 +2453,7 @@ for gidNumber(%lu)\n",(unsigned long)map->gid));
TALLOC_FREE(temp);
temp = smbldap_talloc_single_attribute(
- ldap_state->smbldap_state->ldap_struct,
+ smbldap_get_ld(ldap_state->smbldap_state),
entry,
get_attr_key2string(groupmap_attr_list,
LDAP_ATTR_DESC),
@@ -2612,7 +2684,7 @@ static NTSTATUS ldapsam_enum_group_members(struct pdb_methods *methods,
smbldap_talloc_autofree_ldapmsg(mem_ctx, result);
- count = ldap_count_entries(conn->ldap_struct, result);
+ count = ldap_count_entries(smbldap_get_ld(conn), result);
if (count > 1) {
DEBUG(1, ("Found more than one groupmap entry for %s\n",
@@ -2626,7 +2698,7 @@ static NTSTATUS ldapsam_enum_group_members(struct pdb_methods *methods,
goto done;
}
- entry = ldap_first_entry(conn->ldap_struct, result);
+ entry = ldap_first_entry(smbldap_get_ld(conn), result);
if (entry == NULL)
goto done;
@@ -2637,7 +2709,7 @@ static NTSTATUS ldapsam_enum_group_members(struct pdb_methods *methods,
goto done;
}
- values = ldap_get_values(conn->ldap_struct, entry, "memberUid");
+ values = ldap_get_values(smbldap_get_ld(conn), entry, "memberUid");
if ((values != NULL) && (values[0] != NULL)) {
@@ -2678,22 +2750,22 @@ static NTSTATUS ldapsam_enum_group_members(struct pdb_methods *methods,
if (rc != LDAP_SUCCESS)
goto done;
- count = ldap_count_entries(conn->ldap_struct, result);
+ count = ldap_count_entries(smbldap_get_ld(conn), result);
DEBUG(10,("ldapsam_enum_group_members: found %d accounts\n", count));
smbldap_talloc_autofree_ldapmsg(mem_ctx, result);
- for (entry = ldap_first_entry(conn->ldap_struct, result);
+ for (entry = ldap_first_entry(smbldap_get_ld(conn), result);
entry != NULL;
- entry = ldap_next_entry(conn->ldap_struct, entry))
+ entry = ldap_next_entry(smbldap_get_ld(conn), entry))
{
char *sidstr;
struct dom_sid sid;
uint32_t rid;
- sidstr = smbldap_talloc_single_attribute(conn->ldap_struct,
- entry, "sambaSID",
- mem_ctx);
+ sidstr = smbldap_talloc_single_attribute(
+ smbldap_get_ld(conn), entry, "sambaSID",
+ mem_ctx);
if (!sidstr) {
DEBUG(0, ("Severe DB error, %s can't miss the sambaSID"
"attribute\n", LDAP_OBJ_SAMBASAMACCOUNT));
@@ -2736,13 +2808,13 @@ static NTSTATUS ldapsam_enum_group_members(struct pdb_methods *methods,
smbldap_talloc_autofree_ldapmsg(mem_ctx, result);
- for (entry = ldap_first_entry(conn->ldap_struct, result);
+ for (entry = ldap_first_entry(smbldap_get_ld(conn), result);
entry != NULL;
- entry = ldap_next_entry(conn->ldap_struct, entry))
+ entry = ldap_next_entry(smbldap_get_ld(conn), entry))
{
uint32_t rid;
- if (!ldapsam_extract_rid_from_entry(conn->ldap_struct,
+ if (!ldapsam_extract_rid_from_entry(smbldap_get_ld(conn),
entry,
get_global_sam_sid(),
&rid)) {
@@ -2884,16 +2956,16 @@ static NTSTATUS ldapsam_enum_group_memberships(struct pdb_methods *methods,
goto done;
}
- for (entry = ldap_first_entry(conn->ldap_struct, result);
+ for (entry = ldap_first_entry(smbldap_get_ld(conn), result);
entry != NULL;
- entry = ldap_next_entry(conn->ldap_struct, entry))
+ entry = ldap_next_entry(smbldap_get_ld(conn), entry))
{
fstring str;
struct dom_sid sid;
gid_t gid;
char *end;
- if (!smbldap_get_single_attribute(conn->ldap_struct,
+ if (!smbldap_get_single_attribute(smbldap_get_ld(conn),
entry, "sambaSID",
str, sizeof(str)-1))
continue;
@@ -2901,7 +2973,7 @@ static NTSTATUS ldapsam_enum_group_memberships(struct pdb_methods *methods,
if (!string_to_sid(&sid, str))
goto done;
- if (!smbldap_get_single_attribute(conn->ldap_struct,
+ if (!smbldap_get_single_attribute(smbldap_get_ld(conn),
entry, "gidNumber",
str, sizeof(str)-1))
continue;
@@ -2970,12 +3042,17 @@ static NTSTATUS ldapsam_map_posixgroup(TALLOC_CTX *mem_ctx,
smbldap_talloc_autofree_ldapmsg(mem_ctx, msg);
if ((rc != LDAP_SUCCESS) ||
- (ldap_count_entries(ldap_state->smbldap_state->ldap_struct, msg) != 1) ||
- ((entry = ldap_first_entry(ldap_state->smbldap_state->ldap_struct, msg)) == NULL)) {
+ (ldap_count_entries(smbldap_get_ld(ldap_state->smbldap_state),
+ msg) != 1) ||
+ ((entry = ldap_first_entry(
+ smbldap_get_ld(ldap_state->smbldap_state),
+ msg)) == NULL)) {
return NT_STATUS_NO_SUCH_GROUP;
}
- dn = smbldap_talloc_dn(mem_ctx, ldap_state->smbldap_state->ldap_struct, entry);
+ dn = smbldap_talloc_dn(mem_ctx,
+ smbldap_get_ld(ldap_state->smbldap_state),
+ entry);
if (dn == NULL) {
return NT_STATUS_NO_MEMORY;
}
@@ -2983,13 +3060,17 @@ static NTSTATUS ldapsam_map_posixgroup(TALLOC_CTX *mem_ctx,
mods = NULL;
smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass",
LDAP_OBJ_GROUPMAP);
- smbldap_make_mod(ldap_state->smbldap_state->ldap_struct, entry, &mods, "sambaSid",
+ smbldap_make_mod(smbldap_get_ld(ldap_state->smbldap_state), entry,
+ &mods, "sambaSid",
sid_string_talloc(mem_ctx, &map->sid));
- smbldap_make_mod(ldap_state->smbldap_state->ldap_struct, entry, &mods, "sambaGroupType",
+ smbldap_make_mod(smbldap_get_ld(ldap_state->smbldap_state), entry,
+ &mods, "sambaGroupType",
talloc_asprintf(mem_ctx, "%d", map->sid_name_use));
- smbldap_make_mod(ldap_state->smbldap_state->ldap_struct, entry, &mods, "displayName",
+ smbldap_make_mod(smbldap_get_ld(ldap_state->smbldap_state), entry,
+ &mods, "displayName",
map->nt_name);
- smbldap_make_mod(ldap_state->smbldap_state->ldap_struct, entry, &mods, "description",
+ smbldap_make_mod(smbldap_get_ld(ldap_state->smbldap_state), entry,
+ &mods, "description",
map->comment);
smbldap_talloc_autofree_ldapmod(mem_ctx, mods);
@@ -3038,7 +3119,8 @@ static NTSTATUS ldapsam_add_group_mapping_entry(struct pdb_methods *methods,
smbldap_talloc_autofree_ldapmsg(mem_ctx, msg);
if ((rc == LDAP_SUCCESS) &&
- (ldap_count_entries(ldap_state->smbldap_state->ldap_struct, msg) > 0)) {
+ (ldap_count_entries(smbldap_get_ld(ldap_state->smbldap_state),
+ msg) > 0)) {
DEBUG(3, ("SID %s already present in LDAP, refusing to add "
"group mapping entry\n", sid_string_dbg(&map->sid)));
@@ -3105,20 +3187,26 @@ static NTSTATUS ldapsam_add_group_mapping_entry(struct pdb_methods *methods,
mods = NULL;
- smbldap_make_mod(ldap_state->smbldap_state->ldap_struct, NULL, &mods, "objectClass",
- LDAP_OBJ_SID_ENTRY);
- smbldap_make_mod(ldap_state->smbldap_state->ldap_struct, NULL, &mods, "objectClass",
- LDAP_OBJ_GROUPMAP);
- smbldap_make_mod(ldap_state->smbldap_state->ldap_struct, NULL, &mods, "sambaSid",
+ smbldap_make_mod(smbldap_get_ld(ldap_state->smbldap_state), NULL,
+ &mods, "objectClass", LDAP_OBJ_SID_ENTRY);
+ smbldap_make_mod(smbldap_get_ld(ldap_state->smbldap_state), NULL,
+ &mods, "objectClass", LDAP_OBJ_GROUPMAP);
+ smbldap_make_mod(smbldap_get_ld(ldap_state->smbldap_state), NULL,
+ &mods, "sambaSid",
sid_string_talloc(mem_ctx, &map->sid));
- smbldap_make_mod(ldap_state->smbldap_state->ldap_struct, NULL, &mods, "sambaGroupType",
+ smbldap_make_mod(smbldap_get_ld(ldap_state->smbldap_state), NULL,
+ &mods, "sambaGroupType",
talloc_asprintf(mem_ctx, "%d", map->sid_name_use));
- smbldap_make_mod(ldap_state->smbldap_state->ldap_struct, NULL, &mods, "displayName",
+ smbldap_make_mod(smbldap_get_ld(ldap_state->smbldap_state), NULL,
+ &mods, "displayName",
map->nt_name);
- smbldap_make_mod(ldap_state->smbldap_state->ldap_struct, NULL, &mods, "description",
+ smbldap_make_mod(smbldap_get_ld(ldap_state->smbldap_state), NULL,
+ &mods, "description",
map->comment);
- smbldap_make_mod(ldap_state->smbldap_state->ldap_struct, NULL, &mods, "gidNumber",
- talloc_asprintf(mem_ctx, "%u", (unsigned int)map->gid));
+ smbldap_make_mod(smbldap_get_ld(ldap_state->smbldap_state), NULL,
+ &mods, "gidNumber",
+ talloc_asprintf(mem_ctx, "%u",
+ (unsigned int)map->gid));
smbldap_talloc_autofree_ldapmod(mem_ctx, mods);
rc = smbldap_add(ldap_state->smbldap_state, dn, mods);
@@ -3176,13 +3264,17 @@ static NTSTATUS ldapsam_update_group_mapping_entry(struct pdb_methods *methods,
smbldap_talloc_autofree_ldapmsg(mem_ctx, msg);
if ((rc != LDAP_SUCCESS) ||
- (ldap_count_entries(ldap_state->smbldap_state->ldap_struct, msg) != 1) ||
- ((entry = ldap_first_entry(ldap_state->smbldap_state->ldap_struct, msg)) == NULL)) {
+ (ldap_count_entries(smbldap_get_ld(ldap_state->smbldap_state),
+ msg) != 1) ||
+ ((entry = ldap_first_entry(
+ smbldap_get_ld(ldap_state->smbldap_state),
+ msg)) == NULL)) {
result = NT_STATUS_NO_SUCH_GROUP;
goto done;
}
- dn = smbldap_talloc_dn(mem_ctx, ldap_state->smbldap_state->ldap_struct, entry);
+ dn = smbldap_talloc_dn(
+ mem_ctx, smbldap_get_ld(ldap_state->smbldap_state), entry);
if (dn == NULL) {
result = NT_STATUS_NO_MEMORY;
@@ -3190,10 +3282,10 @@ static NTSTATUS ldapsam_update_group_mapping_entry(struct pdb_methods *methods,
}
mods = NULL;
- smbldap_make_mod(ldap_state->smbldap_state->ldap_struct, entry, &mods, "displayName",
- map->nt_name);
- smbldap_make_mod(ldap_state->smbldap_state->ldap_struct, entry, &mods, "description",
- map->comment);
+ smbldap_make_mod(smbldap_get_ld(ldap_state->smbldap_state), entry,
+ &mods, "displayName", map->nt_name);
+ smbldap_make_mod(smbldap_get_ld(ldap_state->smbldap_state), entry,
+ &mods, "description", map->comment);
smbldap_talloc_autofree_ldapmod(mem_ctx, mods);
if (mods == NULL) {
@@ -3337,11 +3429,11 @@ static NTSTATUS ldapsam_setsamgrent(struct pdb_methods *my_methods,
TALLOC_FREE(filter);
DEBUG(2, ("ldapsam_setsamgrent: %d entries in the base!\n",
- ldap_count_entries(ldap_state->smbldap_state->ldap_struct,
+ ldap_count_entries(smbldap_get_ld(ldap_state->smbldap_state),
ldap_state->result)));
ldap_state->entry =
- ldap_first_entry(ldap_state->smbldap_state->ldap_struct,
+ ldap_first_entry(smbldap_get_ld(ldap_state->smbldap_state),
ldap_state->result);
ldap_state->index = 0;
@@ -3375,9 +3467,9 @@ static NTSTATUS ldapsam_getsamgrent(struct pdb_methods *my_methods,
bret = init_group_from_ldap(ldap_state, map,
ldap_state->entry);
- ldap_state->entry =
- ldap_next_entry(ldap_state->smbldap_state->ldap_struct,
- ldap_state->entry);
+ ldap_state->entry = ldap_next_entry(
+ smbldap_get_ld(ldap_state->smbldap_state),
+ ldap_state->entry);
}
return NT_STATUS_OK;
@@ -3494,7 +3586,7 @@ static NTSTATUS ldapsam_modify_aliasmem(struct pdb_methods *methods,
return NT_STATUS_NO_SUCH_ALIAS;
}
- count = ldap_count_entries(ldap_state->smbldap_state->ldap_struct,
+ count = ldap_count_entries(smbldap_get_ld(ldap_state->smbldap_state),
result);
if (count < 1) {
@@ -3514,7 +3606,7 @@ static NTSTATUS ldapsam_modify_aliasmem(struct pdb_methods *methods,
SAFE_FREE(filter);
- entry = ldap_first_entry(ldap_state->smbldap_state->ldap_struct,
+ entry = ldap_first_entry(smbldap_get_ld(ldap_state->smbldap_state),
result);
if (!entry) {
@@ -3522,7 +3614,9 @@ static NTSTATUS ldapsam_modify_aliasmem(struct pdb_methods *methods,
return NT_STATUS_UNSUCCESSFUL;
}
- dn = smbldap_talloc_dn(talloc_tos(), ldap_state->smbldap_state->ldap_struct, entry);
+ dn = smbldap_talloc_dn(talloc_tos(),
+ smbldap_get_ld(ldap_state->smbldap_state),
+ entry);
if (!dn) {
ldap_msgfree(result);
return NT_STATUS_UNSUCCESSFUL;
@@ -3617,7 +3711,7 @@ static NTSTATUS ldapsam_enum_aliasmem(struct pdb_methods *methods,
return NT_STATUS_NO_SUCH_ALIAS;
}
- count = ldap_count_entries(ldap_state->smbldap_state->ldap_struct,
+ count = ldap_count_entries(smbldap_get_ld(ldap_state->smbldap_state),
result);
if (count < 1) {
@@ -3637,7 +3731,7 @@ static NTSTATUS ldapsam_enum_aliasmem(struct pdb_methods *methods,
SAFE_FREE(filter);
- entry = ldap_first_entry(ldap_state->smbldap_state->ldap_struct,
+ entry = ldap_first_entry(smbldap_get_ld(ldap_state->smbldap_state),
result);
if (!entry) {
@@ -3645,7 +3739,7 @@ static NTSTATUS ldapsam_enum_aliasmem(struct pdb_methods *methods,
return NT_STATUS_UNSUCCESSFUL;
}
- values = ldap_get_values(ldap_state->smbldap_state->ldap_struct,
+ values = ldap_get_values(smbldap_get_ld(ldap_state->smbldap_state),
entry,
get_attr_key2string(groupmap_attr_list,
LDAP_ATTR_SID_LIST));
@@ -3756,7 +3850,7 @@ static NTSTATUS ldapsam_alias_memberships(struct pdb_methods *methods,
smbldap_talloc_autofree_ldapmsg(filter, result);
}
- ldap_struct = ldap_state->smbldap_state->ldap_struct;
+ ldap_struct = smbldap_get_ld(ldap_state->smbldap_state);
for (entry = ldap_first_entry(ldap_struct, result);
entry != NULL;
@@ -4069,7 +4163,7 @@ static NTSTATUS ldapsam_lookup_rids(struct pdb_methods *methods,
if (rc != LDAP_SUCCESS)
goto done;
- ld = ldap_state->smbldap_state->ldap_struct;
+ ld = smbldap_get_ld(ldap_state->smbldap_state);
num_mapped = 0;
for (entry = ldap_first_entry(ld, msg);
@@ -4139,7 +4233,7 @@ static NTSTATUS ldapsam_lookup_rids(struct pdb_methods *methods,
/* ldap_struct might have changed due to a reconnect */
- ld = ldap_state->smbldap_state->ldap_struct;
+ ld = smbldap_get_ld(ldap_state->smbldap_state);
/* For consistency checks, we already checked we're only domain or builtin */
@@ -4327,7 +4421,7 @@ static bool ldapsam_search_firstpage(struct pdb_search *search)
state->connection->paged_results = False;
}
- ld = state->connection->ldap_struct;
+ ld = smbldap_get_ld(state->connection);
if ( ld == NULL) {
DEBUG(5, ("Don't have an LDAP connection right after a "
"search\n"));
@@ -4358,7 +4452,8 @@ static bool ldapsam_search_nextpage(struct pdb_search *search)
if ((rc != LDAP_SUCCESS) || (state->entries == NULL))
return False;
- state->current_entry = ldap_first_entry(state->connection->ldap_struct, state->entries);
+ state->current_entry = ldap_first_entry(
+ smbldap_get_ld(state->connection), state->entries);
if (state->current_entry == NULL) {
ldap_msgfree(state->entries);
@@ -4389,17 +4484,19 @@ static bool ldapsam_search_next_entry(struct pdb_search *search,
}
result = state->ldap2displayentry(state, search,
- state->connection->ldap_struct,
+ smbldap_get_ld(state->connection),
state->current_entry, entry);
if (!result) {
char *dn;
- dn = ldap_get_dn(state->connection->ldap_struct, state->current_entry);
+ dn = ldap_get_dn(smbldap_get_ld(state->connection),
+ state->current_entry);
DEBUG(5, ("Skipping entry %s\n", dn != NULL ? dn : "<NULL>"));
if (dn != NULL) ldap_memfree(dn);
}
- state->current_entry = ldap_next_entry(state->connection->ldap_struct, state->current_entry);
+ state->current_entry = ldap_next_entry(
+ smbldap_get_ld(state->connection), state->current_entry);
if (state->current_entry == NULL) {
ldap_msgfree(state->entries);
@@ -6543,7 +6640,7 @@ NTSTATUS pdb_ldapsam_init_common(struct pdb_methods **pdb_method,
/* Given that the above might fail, everything below this must be
* optional */
- entry = ldap_first_entry(ldap_state->smbldap_state->ldap_struct,
+ entry = ldap_first_entry(smbldap_get_ld(ldap_state->smbldap_state),
result);
if (!entry) {
DEBUG(0, ("pdb_init_ldapsam: Could not get domain info "
@@ -6552,7 +6649,9 @@ NTSTATUS pdb_ldapsam_init_common(struct pdb_methods **pdb_method,
return NT_STATUS_UNSUCCESSFUL;
}
- dn = smbldap_talloc_dn(talloc_tos(), ldap_state->smbldap_state->ldap_struct, entry);
+ dn = smbldap_talloc_dn(talloc_tos(),
+ smbldap_get_ld(ldap_state->smbldap_state),
+ entry);
if (!dn) {
ldap_msgfree(result);
return NT_STATUS_UNSUCCESSFUL;
@@ -6562,7 +6661,7 @@ NTSTATUS pdb_ldapsam_init_common(struct pdb_methods **pdb_method,
TALLOC_FREE(dn);
domain_sid_string = smbldap_talloc_single_attribute(
- ldap_state->smbldap_state->ldap_struct,
+ smbldap_get_ld(ldap_state->smbldap_state),
entry,
get_userattr_key2string(ldap_state->schema_ver,
LDAP_ATTR_USER_SID),
@@ -6598,7 +6697,7 @@ NTSTATUS pdb_ldapsam_init_common(struct pdb_methods **pdb_method,
}
alg_rid_base_string = smbldap_talloc_single_attribute(
- ldap_state->smbldap_state->ldap_struct,
+ smbldap_get_ld(ldap_state->smbldap_state),
entry,
get_attr_key2string( dominfo_attr_list,
LDAP_ATTR_ALGORITHMIC_RID_BASE ),
diff --git a/source3/passdb/pdb_ldap_util.c b/source3/passdb/pdb_ldap_util.c
index 64ad53f..2860d91 100644
--- a/source3/passdb/pdb_ldap_util.c
+++ b/source3/passdb/pdb_ldap_util.c
@@ -90,7 +90,8 @@ static NTSTATUS add_new_domain_account_policies(struct smbldap_state *ldap_state
if (rc!=LDAP_SUCCESS) {
char *ld_error = NULL;
- ldap_get_option(ldap_state->ldap_struct, LDAP_OPT_ERROR_STRING, &ld_error);
+ ldap_get_option(smbldap_get_ld(ldap_state),
+ LDAP_OPT_ERROR_STRING, &ld_error);
DEBUG(1,("add_new_domain_account_policies: failed to add account policies to dn= %s with: %s\n\t%s\n",
dn, ldap_err2string(rc),
ld_error ? ld_error : "unknown"));
@@ -153,7 +154,7 @@ static NTSTATUS add_new_domain_info(struct smbldap_state *ldap_state,
return NT_STATUS_UNSUCCESSFUL;
}
- num_result = ldap_count_entries(ldap_state->ldap_struct, result);
+ num_result = ldap_count_entries(smbldap_get_ld(ldap_state), result);
if (num_result > 1) {
DEBUG (0, ("add_new_domain_info: More than domain with that name exists: bailing "
@@ -229,7 +230,7 @@ static NTSTATUS add_new_domain_info(struct smbldap_state *ldap_state,
if (rc!=LDAP_SUCCESS) {
char *ld_error = NULL;
- ldap_get_option(ldap_state->ldap_struct,
+ ldap_get_option(smbldap_get_ld(ldap_state),
LDAP_OPT_ERROR_STRING, &ld_error);
DEBUG(1,("add_new_domain_info: failed to add domain dn= %s with: %s\n\t%s\n",
dn, ldap_err2string(rc),
@@ -291,7 +292,7 @@ NTSTATUS smbldap_search_domain_info(struct smbldap_state *ldap_state,
SAFE_FREE(filter);
- count = ldap_count_entries(ldap_state->ldap_struct, *result);
+ count = ldap_count_entries(smbldap_get_ld(ldap_state), *result);
if (count == 1) {
return NT_STATUS_OK;
diff --git a/source3/passdb/pdb_nds.c b/source3/passdb/pdb_nds.c
index d7c16da..9844a44 100644
--- a/source3/passdb/pdb_nds.c
+++ b/source3/passdb/pdb_nds.c
@@ -667,7 +667,7 @@ int pdb_nds_get_password(
size_t *pwd_len,
char *pwd )
{
- LDAP *ld = ldap_state->ldap_struct;
+ LDAP *ld = smbldap_get_ld(ldap_state);
int rc = -1;
rc = nmasldap_get_password(ld, object_dn, pwd_len, (unsigned char *)pwd);
@@ -707,7 +707,7 @@ int pdb_nds_set_password(
char *object_dn,
const char *pwd )
{
- LDAP *ld = ldap_state->ldap_struct;
+ LDAP *ld = smbldap_get_ld(ldap_state);
int rc = -1;
LDAPMod **tmpmods = NULL;
@@ -784,13 +784,19 @@ static NTSTATUS pdb_nds_update_login_attempts(struct pdb_methods *methods,
smbldap_talloc_autofree_ldapmsg(sam_acct, result);
}
- if (ldap_count_entries(ldap_state->smbldap_state->ldap_struct, result) == 0) {
+ if (ldap_count_entries(
+ smbldap_get_ld(ldap_state->smbldap_state),
+ result) == 0) {
DEBUG(0, ("pdb_nds_update_login_attempts: No user to modify!\n"));
return NT_STATUS_OBJECT_NAME_NOT_FOUND;
}
- entry = ldap_first_entry(ldap_state->smbldap_state->ldap_struct, result);
- dn = smbldap_talloc_dn(talloc_tos(), ldap_state->smbldap_state->ldap_struct, entry);
+ entry = ldap_first_entry(
+ smbldap_get_ld(ldap_state->smbldap_state), result);
+ dn = smbldap_talloc_dn(talloc_tos(),
+ smbldap_get_ld(
+ ldap_state->smbldap_state),
+ entry);
if (!dn) {
return NT_STATUS_OBJECT_NAME_NOT_FOUND;
}
diff --git a/source3/winbindd/idmap_ldap.c b/source3/winbindd/idmap_ldap.c
index 7545061..025c9ce 100644
--- a/source3/winbindd/idmap_ldap.c
+++ b/source3/winbindd/idmap_ldap.c
@@ -155,7 +155,7 @@ static NTSTATUS verify_idpool(struct idmap_domain *dom)
return NT_STATUS_UNSUCCESSFUL;
}
- count = ldap_count_entries(ctx->smbldap_state->ldap_struct, result);
+ count = ldap_count_entries(smbldap_get_ld(ctx->smbldap_state), result);
ldap_msgfree(result);
@@ -273,23 +273,23 @@ static NTSTATUS idmap_ldap_allocate_id_internal(struct idmap_domain *dom,
smbldap_talloc_autofree_ldapmsg(mem_ctx, result);
- count = ldap_count_entries(ctx->smbldap_state->ldap_struct, result);
+ count = ldap_count_entries(smbldap_get_ld(ctx->smbldap_state), result);
if (count != 1) {
DEBUG(0,("Single %s object not found\n", LDAP_OBJ_IDPOOL));
goto done;
}
- entry = ldap_first_entry(ctx->smbldap_state->ldap_struct, result);
+ entry = ldap_first_entry(smbldap_get_ld(ctx->smbldap_state), result);
dn = smbldap_talloc_dn(mem_ctx,
- ctx->smbldap_state->ldap_struct,
+ smbldap_get_ld(ctx->smbldap_state),
entry);
if ( ! dn) {
goto done;
}
id_str = smbldap_talloc_single_attribute(
- ctx->smbldap_state->ldap_struct,
+ smbldap_get_ld(ctx->smbldap_state),
entry, type, mem_ctx);
if (id_str == NULL) {
DEBUG(0,("%s attribute not found\n", type));
@@ -555,10 +555,10 @@ static NTSTATUS idmap_ldap_set_mapping(struct idmap_domain *dom,
smbldap_set_mod(&mods, LDAP_MOD_ADD,
"objectClass", LDAP_OBJ_IDMAP_ENTRY);
- smbldap_make_mod(ctx->smbldap_state->ldap_struct,
+ smbldap_make_mod(smbldap_get_ld(ctx->smbldap_state),
entry, &mods, type, id_str);
- smbldap_make_mod(ctx->smbldap_state->ldap_struct, entry, &mods,
+ smbldap_make_mod(smbldap_get_ld(ctx->smbldap_state), entry, &mods,
get_attr_key2string(sidmap_attr_list, LDAP_ATTR_SID),
sid);
@@ -579,7 +579,7 @@ static NTSTATUS idmap_ldap_set_mapping(struct idmap_domain *dom,
if (rc != LDAP_SUCCESS) {
char *ld_error = NULL;
- ldap_get_option(ctx->smbldap_state->ldap_struct,
+ ldap_get_option(smbldap_get_ld(ctx->smbldap_state),
LDAP_OPT_ERROR_STRING, &ld_error);
DEBUG(0,("ldap_set_mapping_internals: Failed to add %s to %lu "
"mapping [%s]\n", sid,
@@ -712,7 +712,7 @@ again:
goto done;
}
- count = ldap_count_entries(ctx->smbldap_state->ldap_struct, result);
+ count = ldap_count_entries(smbldap_get_ld(ctx->smbldap_state), result);
if (count == 0) {
DEBUG(10, ("NO SIDs found\n"));
@@ -726,11 +726,11 @@ again:
uint32_t id;
if (i == 0) { /* first entry */
- entry = ldap_first_entry(ctx->smbldap_state->ldap_struct,
- result);
+ entry = ldap_first_entry(
+ smbldap_get_ld(ctx->smbldap_state), result);
} else { /* following ones */
- entry = ldap_next_entry(ctx->smbldap_state->ldap_struct,
- entry);
+ entry = ldap_next_entry(
+ smbldap_get_ld(ctx->smbldap_state), entry);
}
if ( ! entry) {
DEBUG(2, ("ERROR: Unable to fetch ldap entries "
@@ -740,7 +740,7 @@ again:
/* first check if the SID is present */
sidstr = smbldap_talloc_single_attribute(
- ctx->smbldap_state->ldap_struct,
+ smbldap_get_ld(ctx->smbldap_state),
entry, LDAP_ATTRIBUTE_SID, memctx);
if ( ! sidstr) { /* no sid, skip entry */
DEBUG(2, ("WARNING SID not found on entry\n"));
@@ -753,12 +753,12 @@ again:
*not the gid) */
type = ID_TYPE_UID;
tmp = smbldap_talloc_single_attribute(
- ctx->smbldap_state->ldap_struct,
+ smbldap_get_ld(ctx->smbldap_state),
entry, uidNumber, memctx);
if ( ! tmp) {
type = ID_TYPE_GID;
tmp = smbldap_talloc_single_attribute(
- ctx->smbldap_state->ldap_struct,
+ smbldap_get_ld(ctx->smbldap_state),
entry, gidNumber, memctx);
}
if ( ! tmp) { /* wow very strange entry, how did it match ? */
@@ -926,7 +926,7 @@ again:
goto done;
}
- count = ldap_count_entries(ctx->smbldap_state->ldap_struct, result);
+ count = ldap_count_entries(smbldap_get_ld(ctx->smbldap_state), result);
if (count == 0) {
DEBUG(10, ("NO SIDs found\n"));
@@ -941,11 +941,11 @@ again:
uint32_t id;
if (i == 0) { /* first entry */
- entry = ldap_first_entry(ctx->smbldap_state->ldap_struct,
- result);
+ entry = ldap_first_entry(
+ smbldap_get_ld(ctx->smbldap_state), result);
} else { /* following ones */
- entry = ldap_next_entry(ctx->smbldap_state->ldap_struct,
- entry);
+ entry = ldap_next_entry(
+ smbldap_get_ld(ctx->smbldap_state), entry);
}
if ( ! entry) {
DEBUG(2, ("ERROR: Unable to fetch ldap entries "
@@ -955,7 +955,7 @@ again:
/* first check if the SID is present */
sidstr = smbldap_talloc_single_attribute(
- ctx->smbldap_state->ldap_struct,
+ smbldap_get_ld(ctx->smbldap_state),
entry, LDAP_ATTRIBUTE_SID, memctx);
if ( ! sidstr) { /* no sid ??, skip entry */
DEBUG(2, ("WARNING SID not found on entry\n"));
@@ -982,12 +982,12 @@ again:
* not the gid) */
type = ID_TYPE_UID;
tmp = smbldap_talloc_single_attribute(
- ctx->smbldap_state->ldap_struct,
+ smbldap_get_ld(ctx->smbldap_state),
entry, uidNumber, memctx);
if ( ! tmp) {
type = ID_TYPE_GID;
tmp = smbldap_talloc_single_attribute(
- ctx->smbldap_state->ldap_struct,
+ smbldap_get_ld(ctx->smbldap_state),
entry, gidNumber, memctx);
}
if ( ! tmp) { /* no ids ?? */
diff --git a/source3/winbindd/idmap_rfc2307.c b/source3/winbindd/idmap_rfc2307.c
index 8ee84f7..25c1914 100644
--- a/source3/winbindd/idmap_rfc2307.c
+++ b/source3/winbindd/idmap_rfc2307.c
@@ -142,7 +142,7 @@ static NTSTATUS idmap_rfc2307_ldap_search(struct idmap_rfc2307_context *ctx,
ret = smbldap_search(ctx->smbldap_state, bind_path, LDAP_SCOPE_SUBTREE,
expr, attrs, 0, result);
- ctx->ldap = ctx->smbldap_state->ldap_struct;
+ ctx->ldap = smbldap_get_ld(ctx->smbldap_state);
if (ret == LDAP_SUCCESS) {
return NT_STATUS_OK;
--
2.1.4
From 8050edb631464c3368581b620fb50a015dab06a0 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 19 Apr 2017 13:39:25 +0200
Subject: [PATCH 3/6] smbldap: Introduce "smbldap_get_paged_results"
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/include/smbldap.h | 1 +
source3/lib/smbldap.c | 4 ++++
source3/passdb/pdb_ldap.c | 7 ++++---
3 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/source3/include/smbldap.h b/source3/include/smbldap.h
index c2ff62e..8967348 100644
--- a/source3/include/smbldap.h
+++ b/source3/include/smbldap.h
@@ -69,6 +69,7 @@ NTSTATUS smbldap_init(TALLOC_CTX *mem_ctx,
struct smbldap_state **smbldap_state);
LDAP *smbldap_get_ld(struct smbldap_state *state);
+bool smbldap_get_paged_results(struct smbldap_state *state);
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);
diff --git a/source3/lib/smbldap.c b/source3/lib/smbldap.c
index 0a8679f..0ee0782 100644
--- a/source3/lib/smbldap.c
+++ b/source3/lib/smbldap.c
@@ -40,6 +40,10 @@ LDAP *smbldap_get_ld(struct smbldap_state *state)
return state->ldap_struct;
}
+bool smbldap_get_paged_results(struct smbldap_state *state)
+{
+ return state->paged_results;
+}
/*******************************************************************
Search an attribute and return the first value found.
diff --git a/source3/passdb/pdb_ldap.c b/source3/passdb/pdb_ldap.c
index f9180ab..091f8cb 100644
--- a/source3/passdb/pdb_ldap.c
+++ b/source3/passdb/pdb_ldap.c
@@ -4393,7 +4393,7 @@ static bool ldapsam_search_firstpage(struct pdb_search *search)
state->entries = NULL;
- if (state->connection->paged_results) {
+ if (smbldap_get_paged_results(state->connection)) {
rc = smbldap_search_paged(state->connection, state->base,
state->scope, state->filter,
state->attrs, state->attrsonly,
@@ -4438,7 +4438,7 @@ static bool ldapsam_search_nextpage(struct pdb_search *search)
(struct ldap_search_state *)search->private_data;
int rc;
- if (!state->connection->paged_results) {
+ if (!smbldap_get_paged_results(state->connection)) {
/* There is no next page when there are no paged results */
return False;
}
@@ -4523,8 +4523,9 @@ static void ldapsam_search_end(struct pdb_search *search)
state->entries = NULL;
state->current_entry = NULL;
- if (!state->connection->paged_results)
+ if (!smbldap_get_paged_results(state->connection)) {
return;
+ }
/* Tell the LDAP server we're not interested in the rest anymore. */
--
2.1.4
From de3f23538e7b5a09ec255a3d5d4900f87f23645d Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 19 Apr 2017 13:39:25 +0200
Subject: [PATCH 4/6] smbldap: Introduce "smbldap_get_paged_results"
This should be hidden inside smbldap.c, but this is a quick way to
get smbldap_state private to smbldap.c
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/include/smbldap.h | 2 ++
source3/lib/smbldap.c | 6 ++++++
source3/passdb/pdb_ldap.c | 2 +-
3 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/source3/include/smbldap.h b/source3/include/smbldap.h
index 8967348..68a6830 100644
--- a/source3/include/smbldap.h
+++ b/source3/include/smbldap.h
@@ -70,6 +70,8 @@ NTSTATUS smbldap_init(TALLOC_CTX *mem_ctx,
LDAP *smbldap_get_ld(struct smbldap_state *state);
bool smbldap_get_paged_results(struct smbldap_state *state);
+void smbldap_set_paged_results(struct smbldap_state *state,
+ bool paged_results);
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);
diff --git a/source3/lib/smbldap.c b/source3/lib/smbldap.c
index 0ee0782..03f24c9 100644
--- a/source3/lib/smbldap.c
+++ b/source3/lib/smbldap.c
@@ -45,6 +45,12 @@ bool smbldap_get_paged_results(struct smbldap_state *state)
return state->paged_results;
}
+void smbldap_set_paged_results(struct smbldap_state *state,
+ bool paged_results)
+{
+ state->paged_results = paged_results;
+}
+
/*******************************************************************
Search an attribute and return the first value found.
******************************************************************/
diff --git a/source3/passdb/pdb_ldap.c b/source3/passdb/pdb_ldap.c
index 091f8cb..a49abe9 100644
--- a/source3/passdb/pdb_ldap.c
+++ b/source3/passdb/pdb_ldap.c
@@ -4418,7 +4418,7 @@ static bool ldapsam_search_firstpage(struct pdb_search *search)
/* Ok, the server was lying. It told us it could do paged
* searches when it could not. */
- state->connection->paged_results = False;
+ smbldap_set_paged_results(state->connection, false);
}
ld = smbldap_get_ld(state->connection);
--
2.1.4
From 06fbe1edc368ab65b10aed22f6657f7f9a3ad0cd Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 19 Apr 2017 13:43:39 +0200
Subject: [PATCH 5/6] smbldap: Privatize struct smbldap_state
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/include/smbldap.h | 25 +------------------------
source3/lib/smbldap.c | 26 ++++++++++++++++++++++++++
2 files changed, 27 insertions(+), 24 deletions(-)
diff --git a/source3/include/smbldap.h b/source3/include/smbldap.h
index 68a6830..abfa990 100644
--- a/source3/include/smbldap.h
+++ b/source3/include/smbldap.h
@@ -33,30 +33,7 @@
*
*/
-struct smbldap_state {
- LDAP *ldap_struct;
- pid_t pid;
- time_t last_ping; /* monotonic */
- /* retrieve-once info */
- const char *uri;
-
- /* credentials */
- bool anonymous;
- char *bind_dn;
- char *bind_secret;
- int (*bind_callback)(LDAP *ldap_struct, struct smbldap_state *ldap_state, void *data);
- void *bind_callback_data;
-
- bool paged_results;
-
- unsigned int num_failures;
-
- time_t last_use; /* monotonic */
- struct tevent_context *tevent_context;
- struct tevent_timer *idle_event;
-
- struct timeval last_rebind; /* monotonic */
-};
+struct smbldap_state;
/* The following definitions come from lib/smbldap.c */
diff --git a/source3/lib/smbldap.c b/source3/lib/smbldap.c
index 03f24c9..b7f34ce 100644
--- a/source3/lib/smbldap.c
+++ b/source3/lib/smbldap.c
@@ -35,6 +35,32 @@
#define SMBLDAP_IDLE_TIME 150 /* After 2.5 minutes disconnect */
+struct smbldap_state {
+ LDAP *ldap_struct;
+ pid_t pid;
+ time_t last_ping; /* monotonic */
+ /* retrieve-once info */
+ const char *uri;
+
+ /* credentials */
+ bool anonymous;
+ char *bind_dn;
+ char *bind_secret;
+ int (*bind_callback)(LDAP *ldap_struct,
+ struct smbldap_state *ldap_state, void *data);
+ void *bind_callback_data;
+
+ bool paged_results;
+
+ unsigned int num_failures;
+
+ time_t last_use; /* monotonic */
+ struct tevent_context *tevent_context;
+ struct tevent_timer *idle_event;
+
+ struct timeval last_rebind; /* monotonic */
+};
+
LDAP *smbldap_get_ld(struct smbldap_state *state)
{
return state->ldap_struct;
--
2.1.4
From 162df3b5f34aa6661f52c89278890523840df81f Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 19 Apr 2017 14:54:11 +0200
Subject: [PATCH 6/6] smbldap: Bump version number
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/lib/ABI/smbldap-1.sigs | 31 +++++++++++++++++++++++++++++++
source3/wscript_build | 2 +-
2 files changed, 32 insertions(+), 1 deletion(-)
create mode 100644 source3/lib/ABI/smbldap-1.sigs
diff --git a/source3/lib/ABI/smbldap-1.sigs b/source3/lib/ABI/smbldap-1.sigs
new file mode 100644
index 0000000..6e08972
--- /dev/null
+++ b/source3/lib/ABI/smbldap-1.sigs
@@ -0,0 +1,31 @@
+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_ld: 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_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/wscript_build b/source3/wscript_build
index 145f89b..d5bb62a 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='0',
+ vnum='1',
public_headers='include/smbldap.h include/smb_ldap.h')
bld.SAMBA3_LIBRARY('ads',
--
2.1.4
More information about the samba-technical
mailing list