1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

smbldap: Introduce "smbldap_get_ldap"

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@samba.org>
Reviewed-by: Alexander Bokovoy <ab@samba.org>
Reviewed-by: Ralph Böhme <slow@samba.org>
This commit is contained in:
Volker Lendecke 2017-04-19 13:29:31 +02:00
parent ebc80f4ac3
commit 46968fc60f
7 changed files with 343 additions and 211 deletions

View File

@ -68,6 +68,8 @@ NTSTATUS smbldap_init(TALLOC_CTX *mem_ctx,
const char *bind_secret,
struct smbldap_state **smbldap_state);
LDAP *smbldap_get_ldap(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,

View File

@ -35,6 +35,11 @@
#define SMBLDAP_IDLE_TIME 150 /* After 2.5 minutes disconnect */
LDAP *smbldap_get_ldap(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_ldap(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_ldap(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_ldap(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_ldap(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_ldap(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_ldap(ldap_state),
LDAP_OPT_DESC, &sd);
if (opt_rc == 0 && (getpeername(sd, (struct sockaddr *) &addr, &len)) < 0 )
reopen = True;
@ -1055,7 +1066,7 @@ 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_unbind(smbldap_get_ldap(ldap_state));
ldap_state->ldap_struct = NULL;
ldap_state->last_ping = (time_t)0;
} else {
@ -1063,7 +1074,7 @@ static int smbldap_open(struct smbldap_state *ldap_state)
}
}
if (ldap_state->ldap_struct != NULL) {
if (smbldap_get_ldap(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_ldap(ldap_state) != NULL) {
ldap_unbind(smbldap_get_ldap(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_ldap(ldap_state),
LDAP_OPT_ERROR_NUMBER, p_ld_errno);
ldap_get_option(ldap_state->ldap_struct,
ldap_get_option(smbldap_get_ldap(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_ldap(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_ldap(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_ldap(ldap_state), *res, NULL, NULL,
NULL, NULL, &rcontrols, 0);
if (rc != 0) {
DEBUG(3,("smbldap_search_paged: ldap_parse_result failed " \
@ -1449,7 +1461,8 @@ 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_ldap(ldap_state), utf8_dn,
attrs);
if (rc == LDAP_SUCCESS) {
break;
}
@ -1465,7 +1478,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_ldap(ldap_state));
ldap_state->ldap_struct = NULL;
}
@ -1499,7 +1512,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_ldap(ldap_state), utf8_dn, attrs);
if (rc == LDAP_SUCCESS) {
break;
}
@ -1515,7 +1528,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_ldap(ldap_state));
ldap_state->ldap_struct = NULL;
}
@ -1549,7 +1562,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_ldap(ldap_state), utf8_dn);
if (rc == LDAP_SUCCESS) {
break;
}
@ -1565,7 +1578,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_ldap(ldap_state));
ldap_state->ldap_struct = NULL;
}
@ -1595,7 +1608,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_ldap(ldap_state),
reqoid,
reqdata, serverctrls,
clientctrls, retoidp, retdatap);
if (rc == LDAP_SUCCESS) {
@ -1613,7 +1627,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_ldap(ldap_state));
ldap_state->ldap_struct = NULL;
}
@ -1641,7 +1655,7 @@ static void smbldap_idle_fn(struct tevent_context *tevent_ctx,
TALLOC_FREE(state->idle_event);
if (state->ldap_struct == NULL) {
if (smbldap_get_ldap(state) == NULL) {
DEBUG(10,("ldap connection not connected...\n"));
return;
}

File diff suppressed because it is too large Load Diff

View File

@ -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_ldap(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_ldap(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_ldap(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_ldap(ldap_state), *result);
if (count == 1) {
return NT_STATUS_OK;

View File

@ -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_ldap(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_ldap(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_ldap(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_ldap(ldap_state->smbldap_state), result);
dn = smbldap_talloc_dn(talloc_tos(),
smbldap_get_ldap(
ldap_state->smbldap_state),
entry);
if (!dn) {
return NT_STATUS_OBJECT_NAME_NOT_FOUND;
}

View File

@ -155,7 +155,8 @@ 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_ldap(ctx->smbldap_state),
result);
ldap_msgfree(result);
@ -273,23 +274,24 @@ 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_ldap(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_ldap(ctx->smbldap_state), result);
dn = smbldap_talloc_dn(mem_ctx,
ctx->smbldap_state->ldap_struct,
smbldap_get_ldap(ctx->smbldap_state),
entry);
if ( ! dn) {
goto done;
}
id_str = smbldap_talloc_single_attribute(
ctx->smbldap_state->ldap_struct,
smbldap_get_ldap(ctx->smbldap_state),
entry, type, mem_ctx);
if (id_str == NULL) {
DEBUG(0,("%s attribute not found\n", type));
@ -555,10 +557,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_ldap(ctx->smbldap_state),
entry, &mods, type, id_str);
smbldap_make_mod(ctx->smbldap_state->ldap_struct, entry, &mods,
smbldap_make_mod(smbldap_get_ldap(ctx->smbldap_state), entry, &mods,
get_attr_key2string(sidmap_attr_list, LDAP_ATTR_SID),
sid);
@ -579,7 +581,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_ldap(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 +714,8 @@ again:
goto done;
}
count = ldap_count_entries(ctx->smbldap_state->ldap_struct, result);
count = ldap_count_entries(smbldap_get_ldap(ctx->smbldap_state),
result);
if (count == 0) {
DEBUG(10, ("NO SIDs found\n"));
@ -726,11 +729,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_ldap(ctx->smbldap_state), result);
} else { /* following ones */
entry = ldap_next_entry(ctx->smbldap_state->ldap_struct,
entry);
entry = ldap_next_entry(
smbldap_get_ldap(ctx->smbldap_state), entry);
}
if ( ! entry) {
DEBUG(2, ("ERROR: Unable to fetch ldap entries "
@ -740,7 +743,7 @@ again:
/* first check if the SID is present */
sidstr = smbldap_talloc_single_attribute(
ctx->smbldap_state->ldap_struct,
smbldap_get_ldap(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 +756,12 @@ again:
*not the gid) */
type = ID_TYPE_UID;
tmp = smbldap_talloc_single_attribute(
ctx->smbldap_state->ldap_struct,
smbldap_get_ldap(ctx->smbldap_state),
entry, uidNumber, memctx);
if ( ! tmp) {
type = ID_TYPE_GID;
tmp = smbldap_talloc_single_attribute(
ctx->smbldap_state->ldap_struct,
smbldap_get_ldap(ctx->smbldap_state),
entry, gidNumber, memctx);
}
if ( ! tmp) { /* wow very strange entry, how did it match ? */
@ -926,7 +929,8 @@ again:
goto done;
}
count = ldap_count_entries(ctx->smbldap_state->ldap_struct, result);
count = ldap_count_entries(smbldap_get_ldap(ctx->smbldap_state),
result);
if (count == 0) {
DEBUG(10, ("NO SIDs found\n"));
@ -941,11 +945,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_ldap(ctx->smbldap_state), result);
} else { /* following ones */
entry = ldap_next_entry(ctx->smbldap_state->ldap_struct,
entry);
entry = ldap_next_entry(
smbldap_get_ldap(ctx->smbldap_state), entry);
}
if ( ! entry) {
DEBUG(2, ("ERROR: Unable to fetch ldap entries "
@ -955,7 +959,7 @@ again:
/* first check if the SID is present */
sidstr = smbldap_talloc_single_attribute(
ctx->smbldap_state->ldap_struct,
smbldap_get_ldap(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 +986,12 @@ again:
* not the gid) */
type = ID_TYPE_UID;
tmp = smbldap_talloc_single_attribute(
ctx->smbldap_state->ldap_struct,
smbldap_get_ldap(ctx->smbldap_state),
entry, uidNumber, memctx);
if ( ! tmp) {
type = ID_TYPE_GID;
tmp = smbldap_talloc_single_attribute(
ctx->smbldap_state->ldap_struct,
smbldap_get_ldap(ctx->smbldap_state),
entry, gidNumber, memctx);
}
if ( ! tmp) { /* no ids ?? */

View File

@ -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_ldap(ctx->smbldap_state);
if (ret == LDAP_SUCCESS) {
return NT_STATUS_OK;