The branch, master has been updated
       via  325a58a6532e2a9bc7b8e21d55c9b1ccfb879bf9 (commit)
       via  344dbced50dda7ad788b2e1908896ae926ae471a (commit)
       via  c594d21fdaea3fcee11afddc4f0d3e8c065db815 (commit)
       via  ae5e1d984109d0b0d8356416d74b51c4f5311d2a (commit)
      from  8e22e38c9c4a08f9f49f3f8f29dab8d6a948948e (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 325a58a6532e2a9bc7b8e21d55c9b1ccfb879bf9
Author: Volker Lendecke <[email protected]>
Date:   Sun Jun 28 15:30:08 2009 +0200

    Make pdb_ads survive a restart of Samba4
    
    The search function retries once, the modifying call that hits a dead smbd
    returns an error. The next try will reconnect. This was simple to implement 
and
    provides a good compromise against Samba4 idling our connection. Most of the
    modifying calls are quickly after a search (like OpenUser) anyway.

commit 344dbced50dda7ad788b2e1908896ae926ae471a
Author: Volker Lendecke <[email protected]>
Date:   Sun Jun 28 15:29:38 2009 +0200

    If the connection is down, don't try another write.

commit c594d21fdaea3fcee11afddc4f0d3e8c065db815
Author: Volker Lendecke <[email protected]>
Date:   Sun Jun 28 14:41:11 2009 +0200

    Add tldap_search_va

commit ae5e1d984109d0b0d8356416d74b51c4f5311d2a
Author: Volker Lendecke <[email protected]>
Date:   Sun Jun 28 13:03:14 2009 +0200

    tldap_msg_received: Properly free the asn1_struct in case of an error

-----------------------------------------------------------------------

Summary of changes:
 source3/include/tldap.h      |    1 +
 source3/include/tldap_util.h |    4 +
 source3/lib/tldap.c          |   18 +++
 source3/lib/tldap_util.c     |   28 +++-
 source3/passdb/pdb_ads.c     |  331 ++++++++++++++++++++++++++++--------------
 5 files changed, 268 insertions(+), 114 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/include/tldap.h b/source3/include/tldap.h
index 1d920f8..cd50298 100644
--- a/source3/include/tldap.h
+++ b/source3/include/tldap.h
@@ -48,6 +48,7 @@ struct tldap_mod {
 bool tevent_req_is_ldap_error(struct tevent_req *req, int *perr);
 
 struct tldap_context *tldap_context_create(TALLOC_CTX *mem_ctx, int fd);
+bool tldap_connection_ok(struct tldap_context *ld);
 bool tldap_context_setattr(struct tldap_context *ld,
                           const char *name, const void *pptr);
 void *tldap_context_getattr(struct tldap_context *ld, const char *name);
diff --git a/source3/include/tldap_util.h b/source3/include/tldap_util.h
index 9b0393e..f257afc 100644
--- a/source3/include/tldap_util.h
+++ b/source3/include/tldap_util.h
@@ -45,6 +45,10 @@ bool tldap_make_mod_fmt(struct tldap_message *existing, 
TALLOC_CTX *mem_ctx,
 
 const char *tldap_errstr(TALLOC_CTX *mem_ctx, struct tldap_context *ld,
                         int rc);
+int tldap_search_va(struct tldap_context *ld, const char *base, int scope,
+                   const char *attrs[], int num_attrs, int attrsonly,
+                   TALLOC_CTX *mem_ctx, struct tldap_message ***res,
+                   const char *fmt, va_list ap);
 int tldap_search_fmt(struct tldap_context *ld, const char *base, int scope,
                     const char *attrs[], int num_attrs, int attrsonly,
                     TALLOC_CTX *mem_ctx, struct tldap_message ***res,
diff --git a/source3/lib/tldap.c b/source3/lib/tldap.c
index aba8a25..451bc18 100644
--- a/source3/lib/tldap.c
+++ b/source3/lib/tldap.c
@@ -55,6 +55,7 @@ struct tldap_context {
        int ld_sizelimit;
        int ld_timelimit;
        struct tstream_context *conn;
+       bool server_down;
        int msgid;
        struct tevent_queue *outgoing;
        struct tevent_req **pending;
@@ -153,6 +154,14 @@ struct tldap_context *tldap_context_create(TALLOC_CTX 
*mem_ctx, int fd)
        return ctx;
 }
 
+bool tldap_connection_ok(struct tldap_context *ld)
+{
+       if (ld == NULL) {
+               return false;
+       }
+       return !ld->server_down;
+}
+
 static struct tldap_ctx_attribute *tldap_context_findattr(
        struct tldap_context *ld, const char *name)
 {
@@ -395,6 +404,11 @@ static struct tevent_req *tldap_msg_send(TALLOC_CTX 
*mem_ctx,
        state->ev = ev;
        state->id = id;
 
+       if (state->ld->server_down) {
+               tevent_req_error(req, TLDAP_SERVER_DOWN);
+               return tevent_req_post(req, ev);
+       }
+
        tldap_push_controls(data, sctrls, num_sctrls);
 
        asn1_pop_tag(data);
@@ -507,12 +521,15 @@ static void tldap_msg_sent(struct tevent_req *subreq)
 {
        struct tevent_req *req = tevent_req_callback_data(
                subreq, struct tevent_req);
+       struct tldap_msg_state *state = tevent_req_data(
+               req, struct tldap_msg_state);
        ssize_t nwritten;
        int err;
 
        nwritten = tstream_writev_queue_recv(subreq, &err);
        TALLOC_FREE(subreq);
        if (nwritten == -1) {
+               state->ld->server_down = true;
                tevent_req_error(req, TLDAP_SERVER_DOWN);
                return;
        }
@@ -585,6 +602,7 @@ static void tldap_msg_received(struct tevent_req *subreq)
                /* Dump unexpected reply */
                tldap_debug(ld, TLDAP_DEBUG_WARNING, "tldap_msg_received: "
                            "No request pending for msg %d\n", id);
+               TALLOC_FREE(data);
                TALLOC_FREE(inbuf);
                goto done;
        }
diff --git a/source3/lib/tldap_util.c b/source3/lib/tldap_util.c
index f4fffb5..f3a8c71 100644
--- a/source3/lib/tldap_util.c
+++ b/source3/lib/tldap_util.c
@@ -325,22 +325,19 @@ const char *tldap_errstr(TALLOC_CTX *mem_ctx, struct 
tldap_context *ld, int rc)
        return res;
 }
 
-int tldap_search_fmt(struct tldap_context *ld, const char *base, int scope,
-                    const char *attrs[], int num_attrs, int attrsonly,
-                    TALLOC_CTX *mem_ctx, struct tldap_message ***res,
-                    const char *fmt, ...)
+int tldap_search_va(struct tldap_context *ld, const char *base, int scope,
+                   const char *attrs[], int num_attrs, int attrsonly,
+                   TALLOC_CTX *mem_ctx, struct tldap_message ***res,
+                   const char *fmt, va_list ap)
 {
-       va_list ap;
        char *filter;
        int ret;
 
-       va_start(ap, fmt);
        filter = talloc_vasprintf(talloc_tos(), fmt, ap);
-       va_end(ap);
-
        if (filter == NULL) {
                return TLDAP_NO_MEMORY;
        }
+
        ret = tldap_search(ld, base, scope, filter,
                           attrs, num_attrs, attrsonly,
                           NULL /*sctrls*/, 0, NULL /*cctrls*/, 0,
@@ -350,6 +347,21 @@ int tldap_search_fmt(struct tldap_context *ld, const char 
*base, int scope,
        return ret;
 }
 
+int tldap_search_fmt(struct tldap_context *ld, const char *base, int scope,
+                    const char *attrs[], int num_attrs, int attrsonly,
+                    TALLOC_CTX *mem_ctx, struct tldap_message ***res,
+                    const char *fmt, ...)
+{
+       va_list ap;
+       int ret;
+
+       va_start(ap, fmt);
+       ret = tldap_search_va(ld, base, scope, attrs, num_attrs, attrsonly,
+                             mem_ctx, res, fmt, ap);
+       va_end(ap);
+       return ret;
+}
+
 bool tldap_pull_uint64(struct tldap_message *msg, const char *attr,
                       uint64_t *presult)
 {
diff --git a/source3/passdb/pdb_ads.c b/source3/passdb/pdb_ads.c
index f4ab299..cdde30d 100644
--- a/source3/passdb/pdb_ads.c
+++ b/source3/passdb/pdb_ads.c
@@ -20,6 +20,7 @@
 #include "includes.h"
 
 struct pdb_ads_state {
+       struct sockaddr_un socket_address;
        struct tldap_context *ld;
        struct dom_sid domainsid;
        char *domaindn;
@@ -32,11 +33,17 @@ static NTSTATUS pdb_ads_getsampwsid(struct pdb_methods *m,
                                    const DOM_SID *sid);
 static bool pdb_ads_gid_to_sid(struct pdb_methods *m, gid_t gid,
                               DOM_SID *sid);
-static bool pdb_ads_dnblob2sid(struct tldap_context *ld, DATA_BLOB *dnblob,
+static bool pdb_ads_dnblob2sid(struct pdb_ads_state *state, DATA_BLOB *dnblob,
                               struct dom_sid *psid);
 static NTSTATUS pdb_ads_sid2dn(struct pdb_ads_state *state,
                               const struct dom_sid *sid,
                               TALLOC_CTX *mem_ctx, char **pdn);
+static struct tldap_context *pdb_ads_ld(struct pdb_ads_state *state);
+static int pdb_ads_search_fmt(struct pdb_ads_state *state, const char *base,
+                             int scope, const char *attrs[], int num_attrs,
+                             int attrsonly,
+                             TALLOC_CTX *mem_ctx, struct tldap_message ***res,
+                             const char *fmt, ...);
 
 static bool pdb_ads_pull_time(struct tldap_message *msg, const char *attr,
                              time_t *ptime)
@@ -317,9 +324,9 @@ static NTSTATUS pdb_ads_getsampwfilter(struct pdb_methods 
*m,
        struct tldap_message **users;
        int rc, count;
 
-       rc = tldap_search_fmt(state->ld, state->domaindn, TLDAP_SCOPE_SUB,
-                             attrs, ARRAY_SIZE(attrs), 0, talloc_tos(),
-                             &users, "%s", filter);
+       rc = pdb_ads_search_fmt(state, state->domaindn, TLDAP_SCOPE_SUB,
+                               attrs, ARRAY_SIZE(attrs), 0, talloc_tos(),
+                               &users, "%s", filter);
        if (rc != TLDAP_SUCCESS) {
                DEBUG(10, ("ldap_search failed %s\n",
                           tldap_errstr(debug_ctx(), state->ld, rc)));
@@ -377,6 +384,7 @@ static NTSTATUS pdb_ads_create_user(struct pdb_methods *m,
 {
        struct pdb_ads_state *state = talloc_get_type_abort(
                m->private_data, struct pdb_ads_state);
+       struct tldap_context *ld;
        const char *attrs[1] = { "objectSid" };
        struct tldap_mod *mods = NULL;
        int num_mods = 0;
@@ -392,6 +400,11 @@ static NTSTATUS pdb_ads_create_user(struct pdb_methods *m,
                return NT_STATUS_NO_MEMORY;
        }
 
+       ld = pdb_ads_ld(state);
+       if (ld == NULL) {
+               return NT_STATUS_LDAP(TLDAP_SERVER_DOWN);
+       }
+
        /* TODO: Create machines etc */
 
        ok = true;
@@ -404,18 +417,20 @@ static NTSTATUS pdb_ads_create_user(struct pdb_methods *m,
                return NT_STATUS_NO_MEMORY;
        }
 
-       rc = tldap_add(state->ld, dn, num_mods, mods, NULL, 0, NULL, 0);
+
+       rc = tldap_add(ld, dn, num_mods, mods, NULL, 0, NULL, 0);
        if (rc != TLDAP_SUCCESS) {
                DEBUG(10, ("ldap_add failed %s\n",
-                          tldap_errstr(debug_ctx(), state->ld, rc)));
+                          tldap_errstr(debug_ctx(), ld, rc)));
                TALLOC_FREE(dn);
                return NT_STATUS_LDAP(rc);
        }
 
-       rc = tldap_search_fmt(state->ld, state->domaindn, TLDAP_SCOPE_SUB,
-                             attrs, ARRAY_SIZE(attrs), 0, talloc_tos(), &user,
-                            "(&(objectclass=user)(samaccountname=%s))",
-                            name);
+       rc = pdb_ads_search_fmt(state, state->domaindn, TLDAP_SCOPE_SUB,
+                               attrs, ARRAY_SIZE(attrs), 0, talloc_tos(),
+                               &user,
+                               "(&(objectclass=user)(samaccountname=%s))",
+                               name);
        if (rc != TLDAP_SUCCESS) {
                DEBUG(10, ("Could not find just created user %s: %s\n",
                           name, tldap_errstr(debug_ctx(), state->ld, rc)));
@@ -449,20 +464,26 @@ static NTSTATUS pdb_ads_delete_user(struct pdb_methods *m,
        struct pdb_ads_state *state = talloc_get_type_abort(
                m->private_data, struct pdb_ads_state);
        NTSTATUS status;
+       struct tldap_context *ld;
        char *dn;
        int rc;
 
+       ld = pdb_ads_ld(state);
+       if (ld == NULL) {
+               return NT_STATUS_LDAP(TLDAP_SERVER_DOWN);
+       }
+
        status = pdb_ads_sid2dn(state, pdb_get_user_sid(sam), talloc_tos(),
                                &dn);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
        }
 
-       rc = tldap_delete(state->ld, dn, NULL, 0, NULL, 0);
+       rc = tldap_delete(ld, dn, NULL, 0, NULL, 0);
        TALLOC_FREE(dn);
        if (rc != TLDAP_SUCCESS) {
                DEBUG(10, ("ldap_delete for %s failed: %s\n", dn,
-                          tldap_errstr(debug_ctx(), state->ld, rc)));
+                          tldap_errstr(debug_ctx(), ld, rc)));
                return NT_STATUS_LDAP(rc);
        }
        return NT_STATUS_OK;
@@ -480,9 +501,15 @@ static NTSTATUS pdb_ads_update_sam_account(struct 
pdb_methods *m,
        struct pdb_ads_state *state = talloc_get_type_abort(
                m->private_data, struct pdb_ads_state);
        struct pdb_ads_samu_private *priv = pdb_ads_get_samu_private(m, sam);
+       struct tldap_context *ld;
        struct tldap_mod *mods = NULL;
        int rc, num_mods = 0;
 
+       ld = pdb_ads_ld(state);
+       if (ld == NULL) {
+               return NT_STATUS_LDAP(TLDAP_SERVER_DOWN);
+       }
+
        if (!pdb_ads_init_ads_from_sam(state, priv->ldapmsg, talloc_tos(),
                                       &num_mods, &mods, sam)) {
                return NT_STATUS_NO_MEMORY;
@@ -493,16 +520,15 @@ static NTSTATUS pdb_ads_update_sam_account(struct 
pdb_methods *m,
                return NT_STATUS_OK;
        }
 
-       rc = tldap_modify(state->ld, priv->dn, num_mods, mods, NULL, 0,
+       rc = tldap_modify(ld, priv->dn, num_mods, mods, NULL, 0,
                          NULL, 0);
+       TALLOC_FREE(mods);
        if (rc != TLDAP_SUCCESS) {
                DEBUG(10, ("ldap_modify for %s failed: %s\n", priv->dn,
-                          tldap_errstr(debug_ctx(), state->ld, rc)));
+                          tldap_errstr(debug_ctx(), ld, rc)));
                return NT_STATUS_LDAP(rc);
        }
 
-       TALLOC_FREE(mods);
-
        return NT_STATUS_OK;
 }
 
@@ -538,9 +564,9 @@ static NTSTATUS pdb_ads_getgrfilter(struct pdb_methods *m, 
GROUP_MAP *map,
        uint32_t grouptype;
        int rc;
 
-       rc = tldap_search_fmt(state->ld, state->domaindn, TLDAP_SCOPE_SUB,
-                             attrs, ARRAY_SIZE(attrs), 0, talloc_tos(),
-                             &group, "%s", filter);
+       rc = pdb_ads_search_fmt(state, state->domaindn, TLDAP_SCOPE_SUB,
+                               attrs, ARRAY_SIZE(attrs), 0, talloc_tos(),
+                               &group, "%s", filter);
        if (rc != TLDAP_SUCCESS) {
                DEBUG(10, ("ldap_search failed %s\n",
                           tldap_errstr(debug_ctx(), state->ld, rc)));
@@ -644,6 +670,7 @@ static NTSTATUS pdb_ads_create_dom_group(struct pdb_methods 
*m,
        TALLOC_CTX *frame = talloc_stackframe();
        struct pdb_ads_state *state = talloc_get_type_abort(
                m->private_data, struct pdb_ads_state);
+       struct tldap_context *ld;
        const char *attrs[1] = { "objectSid" };
        int num_mods = 0;
        struct tldap_mod *mods = NULL;
@@ -653,6 +680,11 @@ static NTSTATUS pdb_ads_create_dom_group(struct 
pdb_methods *m,
        int rc;
        bool ok = true;
 
+       ld = pdb_ads_ld(state);
+       if (ld == NULL) {
+               return NT_STATUS_LDAP(TLDAP_SERVER_DOWN);
+       }
+
        dn = talloc_asprintf(talloc_tos(), "cn=%s,cn=users,%s", name,
                             state->domaindn);
        if (dn == NULL) {
@@ -674,7 +706,7 @@ static NTSTATUS pdb_ads_create_dom_group(struct pdb_methods 
*m,
                return NT_STATUS_NO_MEMORY;
        }
 
-       rc = tldap_add(state->ld, dn, num_mods, mods, NULL, 0, NULL, 0);
+       rc = tldap_add(ld, dn, num_mods, mods, NULL, 0, NULL, 0);
        if (rc != TLDAP_SUCCESS) {
                DEBUG(10, ("ldap_add failed %s\n",
                           tldap_errstr(debug_ctx(), state->ld, rc)));
@@ -682,8 +714,8 @@ static NTSTATUS pdb_ads_create_dom_group(struct pdb_methods 
*m,
                return NT_STATUS_LDAP(rc);
        }
 
-       rc = tldap_search_fmt(
-               state->ld, state->domaindn, TLDAP_SCOPE_SUB,
+       rc = pdb_ads_search_fmt(
+               state, state->domaindn, TLDAP_SCOPE_SUB,
                attrs, ARRAY_SIZE(attrs), 0, talloc_tos(), &alias,
                "(&(objectclass=group)(samaccountname=%s))", name);
        if (rc != TLDAP_SUCCESS) {
@@ -717,6 +749,7 @@ static NTSTATUS pdb_ads_delete_dom_group(struct pdb_methods 
*m,
 {
        struct pdb_ads_state *state = talloc_get_type_abort(
                m->private_data, struct pdb_ads_state);
+       struct tldap_context *ld;
        struct dom_sid sid;
        char *sidstr;
        struct tldap_message **msg;
@@ -728,10 +761,10 @@ static NTSTATUS pdb_ads_delete_dom_group(struct 
pdb_methods *m,
        sidstr = sid_binstring(talloc_tos(), &sid);
        NT_STATUS_HAVE_NO_MEMORY(sidstr);
 
-       rc = tldap_search_fmt(state->ld, state->domaindn, TLDAP_SCOPE_SUB,
-                             NULL, 0, 0, talloc_tos(), &msg,
-                             ("(&(objectSid=%s)(objectClass=group))"),
-                             sidstr);
+       rc = pdb_ads_search_fmt(state, state->domaindn, TLDAP_SCOPE_SUB,
+                               NULL, 0, 0, talloc_tos(), &msg,
+                               ("(&(objectSid=%s)(objectClass=group))"),
+                               sidstr);
        TALLOC_FREE(sidstr);
        if (rc != TLDAP_SUCCESS) {
                DEBUG(10, ("ldap_search failed %s\n",
@@ -749,18 +782,24 @@ static NTSTATUS pdb_ads_delete_dom_group(struct 
pdb_methods *m,
        }
 
        if (!tldap_entry_dn(msg[0], &dn)) {
+               TALLOC_FREE(msg);
                return NT_STATUS_INTERNAL_DB_CORRUPTION;
        }
 
-       rc = tldap_delete(state->ld, dn, NULL, 0, NULL, 0);
+       ld = pdb_ads_ld(state);
+       if (ld == NULL) {
+               TALLOC_FREE(msg);
+               return NT_STATUS_LDAP(TLDAP_SERVER_DOWN);
+       }
+
+       rc = tldap_delete(ld, dn, NULL, 0, NULL, 0);
+       TALLOC_FREE(msg);
        if (rc != TLDAP_SUCCESS) {
                DEBUG(10, ("ldap_delete failed: %s\n",
                           tldap_errstr(debug_ctx(), state->ld, rc)));
-               TALLOC_FREE(dn);
                return NT_STATUS_LDAP(rc);
        }
 
-       TALLOC_FREE(msg);
        return NT_STATUS_OK;
 }
 
@@ -810,9 +849,9 @@ static NTSTATUS pdb_ads_enum_group_members(struct 
pdb_methods *m,
        sidstr = sid_binstring(talloc_tos(), group);
        NT_STATUS_HAVE_NO_MEMORY(sidstr);
 
-       rc = tldap_search_fmt(state->ld, state->domaindn, TLDAP_SCOPE_SUB,
-                             attrs, ARRAY_SIZE(attrs), 0, talloc_tos(), &msg,
-                             "(objectsid=%s)", sidstr);
+       rc = pdb_ads_search_fmt(state, state->domaindn, TLDAP_SCOPE_SUB,
+                               attrs, ARRAY_SIZE(attrs), 0, talloc_tos(),
+                               &msg, "(objectsid=%s)", sidstr);
        TALLOC_FREE(sidstr);
        if (rc != TLDAP_SUCCESS) {
                DEBUG(10, ("ldap_search failed %s\n",
@@ -841,7 +880,7 @@ static NTSTATUS pdb_ads_enum_group_members(struct 
pdb_methods *m,
 
        for (i=0; i<num_members; i++) {
                struct dom_sid sid;
-               if (!pdb_ads_dnblob2sid(state->ld, &blobs[i], &sid)
+               if (!pdb_ads_dnblob2sid(state, &blobs[i], &sid)
                    || !sid_peek_rid(&sid, &members[i])) {
                        TALLOC_FREE(members);
                        return NT_STATUS_INTERNAL_DB_CORRUPTION;
@@ -871,8 +910,8 @@ static NTSTATUS pdb_ads_enum_group_memberships(struct 
pdb_methods *m,
        struct dom_sid *group_sids;
        gid_t *gids;
 
-       rc = tldap_search_fmt(
-               state->ld, state->domaindn, TLDAP_SCOPE_SUB,
+       rc = pdb_ads_search_fmt(
+               state, state->domaindn, TLDAP_SCOPE_SUB,
                attrs, ARRAY_SIZE(attrs), 0, talloc_tos(), &groups,
                "(&(member=%s)(grouptype=%d)(objectclass=group))",
                priv->dn, GTYPE_SECURITY_GLOBAL_GROUP);
@@ -929,12 +968,18 @@ static NTSTATUS pdb_ads_mod_groupmem(struct pdb_methods 
*m,
        struct pdb_ads_state *state = talloc_get_type_abort(
                m->private_data, struct pdb_ads_state);
        TALLOC_CTX *frame = talloc_stackframe();
+       struct tldap_context *ld;
        struct dom_sid groupsid, membersid;
        char *groupdn, *memberdn;
        struct tldap_mod *mods;
        int rc;
        NTSTATUS status;
 
+       ld = pdb_ads_ld(state);
+       if (ld == NULL) {
+               return NT_STATUS_LDAP(TLDAP_SERVER_DOWN);
+       }
+
        sid_compose(&groupsid, &state->domainsid, grouprid);
        sid_compose(&membersid, &state->domainsid, memberrid);
 
@@ -957,7 +1002,7 @@ static NTSTATUS pdb_ads_mod_groupmem(struct pdb_methods *m,
                return NT_STATUS_NO_MEMORY;
        }
 
-       rc = tldap_modify(state->ld, groupdn, 1, mods, NULL, 0, NULL, 0);
+       rc = tldap_modify(ld, groupdn, 1, mods, NULL, 0, NULL, 0);
        TALLOC_FREE(frame);
        if (rc != TLDAP_SUCCESS) {
                DEBUG(10, ("ldap_modify failed: %s\n",
@@ -996,6 +1041,7 @@ static NTSTATUS pdb_ads_create_alias(struct pdb_methods *m,
        TALLOC_CTX *frame = talloc_stackframe();
        struct pdb_ads_state *state = talloc_get_type_abort(
                m->private_data, struct pdb_ads_state);
+       struct tldap_context *ld;
        const char *attrs[1] = { "objectSid" };
        int num_mods = 0;
        struct tldap_mod *mods = NULL;
@@ -1005,6 +1051,11 @@ static NTSTATUS pdb_ads_create_alias(struct pdb_methods 
*m,
        int rc;
        bool ok = true;
 
+       ld = pdb_ads_ld(state);
+       if (ld == NULL) {
+               return NT_STATUS_LDAP(TLDAP_SERVER_DOWN);
+       }
+
        dn = talloc_asprintf(talloc_tos(), "cn=%s,cn=users,%s", name,
                             state->domaindn);
        if (dn == NULL) {
@@ -1026,7 +1077,7 @@ static NTSTATUS pdb_ads_create_alias(struct pdb_methods 
*m,
                return NT_STATUS_NO_MEMORY;
        }
 
-       rc = tldap_add(state->ld, dn, num_mods, mods, NULL, 0, NULL, 0);
+       rc = tldap_add(ld, dn, num_mods, mods, NULL, 0, NULL, 0);
        if (rc != TLDAP_SUCCESS) {
                DEBUG(10, ("ldap_add failed %s\n",
                           tldap_errstr(debug_ctx(), state->ld, rc)));
@@ -1034,8 +1085,8 @@ static NTSTATUS pdb_ads_create_alias(struct pdb_methods 
*m,
                return NT_STATUS_LDAP(rc);
        }
 
-       rc = tldap_search_fmt(
-               state->ld, state->domaindn, TLDAP_SCOPE_SUB,


-- 
Samba Shared Repository

Reply via email to