s3:smbldap: add a destructor to smbldap_state, just in case
[kai/samba.git] / source3 / lib / smbldap.c
index d7d06e9e081f05088074073ebb3959a59c2bca94..1fbefbf2d59934022a6021e27c226133cb5efe23 100644 (file)
@@ -239,7 +239,7 @@ ATTRIB_MAP_ENTRY sidmap_attr_list[] = {
                i++;
        i++;
 
-       names = TALLOC_ARRAY( mem_ctx, const char*, i );
+       names = talloc_array( mem_ctx, const char*, i );
        if ( !names ) {
                DEBUG(0,("get_attr_list: out of memory\n"));
                return NULL;
@@ -405,7 +405,7 @@ ATTRIB_MAP_ENTRY sidmap_attr_list[] = {
                        return NULL;
                }
 
-               if (StrCaseCmp(tmp, result) < 0) {
+               if (strcasecmp_m(tmp, result) < 0) {
                        TALLOC_FREE(result);
                        result = tmp;
                } else {
@@ -474,7 +474,7 @@ ATTRIB_MAP_ENTRY sidmap_attr_list[] = {
                return;
        }
 
-       handle = TALLOC_P(mem_ctx, LDAPMessage *);
+       handle = talloc(mem_ctx, LDAPMessage *);
        SMB_ASSERT(handle != NULL);
 
        *handle = result;
@@ -494,7 +494,7 @@ ATTRIB_MAP_ENTRY sidmap_attr_list[] = {
                return;
        }
 
-       handle = TALLOC_P(mem_ctx, LDAPMod **);
+       handle = talloc(mem_ctx, LDAPMod **);
        SMB_ASSERT(handle != NULL);
 
        *handle = mod;
@@ -654,7 +654,7 @@ static void smbldap_make_mod_internal(LDAP *ldap_struct, LDAPMessage *existing,
                        equal = (newblob && (data_blob_cmp(&oldblob, newblob) == 0));
                } else {
                        /* all of our string attributes are case insensitive */
-                       equal = (newval && (StrCaseCmp(oldval, newval) == 0));
+                       equal = (newval && (strcasecmp_m(oldval, newval) == 0));
                }
 
                if (equal) {
@@ -1307,7 +1307,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);
        }
@@ -1332,6 +1332,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 */
 
@@ -1820,7 +1822,7 @@ static void smbldap_idle_fn(struct event_context *event_ctx,
 
                /* this needs to be made monotonic clock aware inside tevent: */
                state->idle_event = event_add_timed(
-                       event_ctx, NULL,
+                       event_ctx, state,
                        timeval_add(&now_abs, SMBLDAP_IDLE_TIME, 0),
                        smbldap_idle_fn,
                        private_data);
@@ -1846,13 +1848,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
@@ -1862,7 +1868,7 @@ NTSTATUS smbldap_init(TALLOC_CTX *mem_ctx, struct event_context *event_ctx,
                      const char *location,
                      struct smbldap_state **smbldap_state)
 {
-       *smbldap_state = TALLOC_ZERO_P(mem_ctx, struct smbldap_state);
+       *smbldap_state = talloc_zero(mem_ctx, struct smbldap_state);
        if (!*smbldap_state) {
                DEBUG(0, ("talloc() failed for ldapsam private_data!\n"));
                return NT_STATUS_NO_MEMORY;
@@ -1876,6 +1882,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;
 }