The branch, v3-5-test has been updated
       via  1da14b9 s3:smbldap: make smbldap_connect_system self contained
       via  6a3869d s3:smbldap: add a destructor to smbldap_state, just in case
       via  df03f6c s3:smbldap: let smbldap_free_struct do what it claims to
       via  70856a7 s3:smbldap: free the idle event scheduled in smbldap_open 
in smbldap_close
       via  3d78bea s3:smbldap: use smbldap_state as memory context for idle 
event
      from  1a8155d s3: explicitly pass domain_sid to wbint_LookupRids() (bug 
#7841)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-5-test


- Log -----------------------------------------------------------------
commit 1da14b93bc664948699f62cca2fc777c6f7523c9
Author: Gregor Beck <[email protected]>
Date:   Tue Jun 21 08:16:56 2011 +0200

    s3:smbldap: make smbldap_connect_system self contained
    
    The last 5 patches address bug #8253 (winbindd panics if verify_idpool() 
fails).

commit 6a3869da05b0d0e4d47db2502489de359d5e7e45
Author: Gregor Beck <[email protected]>
Date:   Tue Jun 21 08:06:28 2011 +0200

    s3:smbldap: add a destructor to smbldap_state, just in case

commit df03f6c2c98f65bf9656d27e1cc9dc72cd587e31
Author: Gregor Beck <[email protected]>
Date:   Tue Jun 21 08:02:53 2011 +0200

    s3:smbldap: let smbldap_free_struct do what it claims to

commit 70856a728a0be1c97e9e13382cd2d880450e07c4
Author: Gregor Beck <[email protected]>
Date:   Tue Jun 21 08:00:59 2011 +0200

    s3:smbldap: free the idle event scheduled in smbldap_open in smbldap_close

commit 3d78bea9ac27c3f6c98561e287add632a17ce747
Author: Gregor Beck <[email protected]>
Date:   Tue Jun 21 07:51:41 2011 +0200

    s3:smbldap: use smbldap_state as memory context for idle event
    
    ensure the event is canceled if the smbldap_state gets freed
    this fixes a panic of winbindd if verify_idpool fails

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

Summary of changes:
 source3/lib/smbldap.c |   34 +++++++++++++++++++++++-----------
 1 files changed, 23 insertions(+), 11 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/lib/smbldap.c b/source3/lib/smbldap.c
index 7aa36ba..c2ac343 100644
--- a/source3/lib/smbldap.c
+++ b/source3/lib/smbldap.c
@@ -1093,8 +1093,9 @@ static int rebindproc_connect (LDAP * ld, LDAP_CONST char 
*url, int request,
 /*******************************************************************
  connect to the ldap server under system privilege.
 ******************************************************************/
-static int smbldap_connect_system(struct smbldap_state *ldap_state, LDAP * 
ldap_struct)
+static int smbldap_connect_system(struct smbldap_state *ldap_state)
 {
+       LDAP *ldap_struct = ldap_state->ldap_struct;
        int rc;
        int version;
 
@@ -1105,7 +1106,8 @@ static int smbldap_connect_system(struct smbldap_state 
*ldap_state, LDAP * ldap_
                /* get the default dn and password only if they are not set 
already */
                if (!fetch_ldap_pw(&bind_dn, &bind_secret)) {
                        DEBUG(0, ("ldap_connect_system: Failed to retrieve 
password from secrets.tdb\n"));
-                       return LDAP_INVALID_CREDENTIALS;
+                       rc = LDAP_INVALID_CREDENTIALS;
+                       goto done;
                }
                smbldap_set_creds(ldap_state, false, bind_dn, bind_secret);
                SAFE_FREE(bind_dn);
@@ -1151,7 +1153,7 @@ static int smbldap_connect_system(struct smbldap_state 
*ldap_state, LDAP * ldap_
                               ld_error ? ld_error : "(unknown)"));
                SAFE_FREE(ld_error);
                ldap_state->num_failures++;
-               return rc;
+               goto done;
        }
 
        ldap_state->num_failures = 0;
@@ -1166,6 +1168,11 @@ static int smbldap_connect_system(struct smbldap_state 
*ldap_state, LDAP * ldap_
        DEBUG(3, ("ldap_connect_system: successful connection to the LDAP 
server\n"));
        DEBUGADD(10, ("ldap_connect_system: LDAP server %s support paged 
results\n", 
                ldap_state->paged_results ? "does" : "does not"));
+done:
+       if (rc != 0) {
+               ldap_unbind(ldap_struct);
+               ldap_state->ldap_struct = NULL;
+       }
        return rc;
 }
 
@@ -1220,9 +1227,7 @@ static int smbldap_open(struct smbldap_state *ldap_state)
                return rc;
        }
 
-       if ((rc = smbldap_connect_system(ldap_state, ldap_state->ldap_struct))) 
{
-               ldap_unbind(ldap_state->ldap_struct);
-               ldap_state->ldap_struct = NULL;
+       if ((rc = smbldap_connect_system(ldap_state))) {
                return rc;
        }
 
@@ -1234,7 +1239,7 @@ static int smbldap_open(struct smbldap_state *ldap_state)
 
        if (ldap_state->event_context != NULL) {
                ldap_state->idle_event = event_add_timed(
-                       ldap_state->event_context, NULL,
+                       ldap_state->event_context, ldap_state,
                        timeval_current_ofs(SMBLDAP_IDLE_TIME, 0),
                        smbldap_idle_fn, ldap_state);
        }
@@ -1259,6 +1264,8 @@ static NTSTATUS smbldap_close(struct smbldap_state 
*ldap_state)
 
        smbldap_delete_state(ldap_state);
 
+       TALLOC_FREE(ldap_state->idle_event);
+
        DEBUG(5,("The connection to the LDAP server was closed\n"));
        /* maybe free the results here --metze */
 
@@ -1745,7 +1752,7 @@ static void smbldap_idle_fn(struct event_context 
*event_ctx,
                DEBUG(10,("ldap connection not idle...\n"));
 
                state->idle_event = event_add_timed(
-                       event_ctx, NULL,
+                       event_ctx, state,
                        timeval_add(&now, SMBLDAP_IDLE_TIME, 0),
                        smbldap_idle_fn,
                        private_data);
@@ -1771,13 +1778,17 @@ void smbldap_free_struct(struct smbldap_state 
**ldap_state)
        SAFE_FREE((*ldap_state)->bind_dn);
        SAFE_FREE((*ldap_state)->bind_secret);
 
-       TALLOC_FREE((*ldap_state)->idle_event);
-
-       *ldap_state = NULL;
+       TALLOC_FREE(*ldap_state);
 
        /* No need to free any further, as it is talloc()ed */
 }
 
+static int smbldap_state_destructor(struct smbldap_state *state)
+{
+       smbldap_free_struct(&state);
+       return 0;
+}
+
 
 /**********************************************************************
  Intitalise the 'general' ldap structures, on which ldap operations may be 
conducted
@@ -1801,6 +1812,7 @@ NTSTATUS smbldap_init(TALLOC_CTX *mem_ctx, struct 
event_context *event_ctx,
 
        (*smbldap_state)->event_context = event_ctx;
 
+       talloc_set_destructor(*smbldap_state, smbldap_state_destructor);
        return NT_STATUS_OK;
 }
 


-- 
Samba Shared Repository

Reply via email to