s3:smbldap Remove smbldap_get_dn
authorAndrew Bartlett <abartlet@samba.org>
Wed, 18 Mar 2009 04:29:02 +0000 (15:29 +1100)
committerGünther Deschner <gd@samba.org>
Mon, 6 Apr 2009 12:52:51 +0000 (14:52 +0200)
This removes one more caller to pull_utf8_allocate()

Signed-off-by: Günther Deschner <gd@samba.org>
source3/include/proto.h
source3/include/smbldap.h
source3/lib/smbldap.c
source3/passdb/pdb_ldap.c
source3/passdb/pdb_nds.c

index 0a2a8de4a93c64ded34e94877e39a2abd57accb0..c46e7a574c30c4f14ad105bc9eb7f9a82bee6fc3 100644 (file)
@@ -746,7 +746,6 @@ void smbldap_free_struct(struct smbldap_state **ldap_state) ;
 NTSTATUS smbldap_init(TALLOC_CTX *mem_ctx, struct event_context *event_ctx,
                      const char *location,
                      struct smbldap_state **smbldap_state);
-char *smbldap_get_dn(LDAP *ld, LDAPMessage *entry);
 bool smbldap_has_control(LDAP *ld, const char *control);
 bool smbldap_has_extension(LDAP *ld, const char *extension);
 bool smbldap_has_naming_context(LDAP *ld, const char *naming_context);
index a2cb8c5eea4ac0f58f2d87ea3acb0e0181b571f9..353e01aba6447adfbd227c5ee36eb3be05563134 100644 (file)
@@ -141,7 +141,6 @@ void smbldap_make_mod(LDAP *ldap_struct, LDAPMessage *existing,
 bool smbldap_get_single_attribute (LDAP * ldap_struct, LDAPMessage * entry,
                                   const char *attribute, char *value,
                                   int max_len);
-char *smbldap_get_dn(LDAP *ld, LDAPMessage *entry);
 int smbldap_modify(struct smbldap_state *ldap_state,
                    const char *dn,
                    LDAPMod *attrs[]);
@@ -214,7 +213,7 @@ char * smbldap_talloc_single_attribute(LDAP *ldap_struct, LDAPMessage *entry,
                                       TALLOC_CTX *mem_ctx);
 void talloc_autofree_ldapmsg(TALLOC_CTX *mem_ctx, LDAPMessage *result);
 void talloc_autofree_ldapmod(TALLOC_CTX *mem_ctx, LDAPMod **mod);
-const char *smbldap_talloc_dn(TALLOC_CTX *mem_ctx, LDAP *ld,
+char *smbldap_talloc_dn(TALLOC_CTX *mem_ctx, LDAP *ld,
                              LDAPMessage *entry);
 
 
index e24d35818c78944cd6f754f685868a037323ac37..1dfb02035d514bbfe3668c968d1124b88ae0a856 100644 (file)
@@ -1649,41 +1649,19 @@ NTSTATUS smbldap_init(TALLOC_CTX *mem_ctx, struct event_context *event_ctx,
        return NT_STATUS_OK;
 }
 
-/*******************************************************************
- Return a copy of the DN for a LDAPMessage. Convert from utf8 to CH_UNIX.
-********************************************************************/
-char *smbldap_get_dn(LDAP *ld, LDAPMessage *entry)
-{
-       char *utf8_dn, *unix_dn;
-       size_t converted_size;
-
-       utf8_dn = ldap_get_dn(ld, entry);
-       if (!utf8_dn) {
-               DEBUG (5, ("smbldap_get_dn: ldap_get_dn failed\n"));
-               return NULL;
-       }
-       if (!pull_utf8_allocate(&unix_dn, utf8_dn, &converted_size)) {
-               DEBUG (0, ("smbldap_get_dn: String conversion failure utf8 "
-                          "[%s]\n", utf8_dn));
-               return NULL;
-       }
-       ldap_memfree(utf8_dn);
-       return unix_dn;
-}
-
- const char *smbldap_talloc_dn(TALLOC_CTX *mem_ctx, LDAP *ld,
-                              LDAPMessage *entry)
+ char *smbldap_talloc_dn(TALLOC_CTX *mem_ctx, LDAP *ld,
+                        LDAPMessage *entry)
 {
        char *utf8_dn, *unix_dn;
        size_t converted_size;
 
        utf8_dn = ldap_get_dn(ld, entry);
        if (!utf8_dn) {
-               DEBUG (5, ("smbldap_get_dn: ldap_get_dn failed\n"));
+               DEBUG (5, ("smbldap_talloc_dn: ldap_get_dn failed\n"));
                return NULL;
        }
        if (!pull_utf8_talloc(mem_ctx, &unix_dn, utf8_dn, &converted_size)) {
-               DEBUG (0, ("smbldap_get_dn: String conversion failure utf8 "
+               DEBUG (0, ("smbldap_talloc_dn: String conversion failure utf8 "
                           "[%s]\n", utf8_dn));
                return NULL;
        }
index 77b19e3de950a616eb6cc6f63159ec1a8b63518f..b706721e77d83a8145e3384a7d7a5201bdd2da8f 100644 (file)
@@ -840,27 +840,27 @@ 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_get_dn(ldap_state->smbldap_state->ldap_struct, entry);
+               user_dn = smbldap_talloc_dn(ctx, ldap_state->smbldap_state->ldap_struct, entry);
                if (user_dn != NULL) {
-                       DEBUG(3, ("init_sam_from_ldap: smbldap_get_dn(%s) returned '%s'\n", username, user_dn));
+                       DEBUG(3, ("init_sam_from_ldap: smbldap_talloc_dn(ctx, %s) returned '%s'\n", username, user_dn));
 
                        pwd_len = sizeof(clear_text_pw);
                        if (pdb_nds_get_password(ldap_state->smbldap_state, user_dn, &pwd_len, clear_text_pw) == LDAP_SUCCESS) {
                                nt_lm_owf_gen(clear_text_pw, smbntpwd, smblmpwd);
                                if (!pdb_set_lanman_passwd(sampass, smblmpwd, PDB_SET)) {
-                                       SAFE_FREE(user_dn);
+                                       TALLOC_FREE(user_dn);
                                        return False;
                                }
                                ZERO_STRUCT(smblmpwd);
                                if (!pdb_set_nt_passwd(sampass, smbntpwd, PDB_SET)) {
-                                       SAFE_FREE(user_dn);
+                                       TALLOC_FREE(user_dn);
                                        return False;
                                }
                                ZERO_STRUCT(smbntpwd);
                                use_samba_attrs = False;
                        }
 
-                       SAFE_FREE(user_dn);
+                       TALLOC_FREE(user_dn);
 
                } else {
                        DEBUG(0, ("init_sam_from_ldap: failed to get user_dn for '%s'\n", username));
@@ -1908,7 +1908,7 @@ static NTSTATUS ldapsam_update_sam_account(struct pdb_methods *my_methods, struc
        }
 
        entry = ldap_first_entry(ldap_state->smbldap_state->ldap_struct, result);
-       dn = smbldap_get_dn(ldap_state->smbldap_state->ldap_struct, entry);
+       dn = smbldap_talloc_dn(NULL, ldap_state->smbldap_state->ldap_struct, entry);
        if (!dn) {
                return NT_STATUS_UNSUCCESSFUL;
        }
@@ -1918,7 +1918,7 @@ static NTSTATUS ldapsam_update_sam_account(struct pdb_methods *my_methods, struc
        if (!init_ldap_from_sam(ldap_state, entry, &mods, newpwd,
                                element_is_changed)) {
                DEBUG(0, ("ldapsam_update_sam_account: init_ldap_from_sam failed!\n"));
-               SAFE_FREE(dn);
+               TALLOC_FREE(dn);
                if (mods != NULL)
                        ldap_mods_free(mods,True);
                return NT_STATUS_UNSUCCESSFUL;
@@ -1928,7 +1928,7 @@ static NTSTATUS ldapsam_update_sam_account(struct pdb_methods *my_methods, struc
            && (mods == NULL)) {
                DEBUG(4,("ldapsam_update_sam_account: mods is empty: nothing to update for user: %s\n",
                         pdb_get_username(newpwd)));
-               SAFE_FREE(dn);
+               TALLOC_FREE(dn);
                return NT_STATUS_OK;
        }
        
@@ -1938,7 +1938,7 @@ static NTSTATUS ldapsam_update_sam_account(struct pdb_methods *my_methods, struc
                ldap_mods_free(mods,True);
        }
 
-       SAFE_FREE(dn);
+       TALLOC_FREE(dn);
 
        /*
         * We need to set the backend private data to NULL here. For example
@@ -2147,17 +2147,10 @@ static NTSTATUS ldapsam_add_sam_account(struct pdb_methods *my_methods, struct s
 
        /* Check if we need to update an existing entry */
        if (num_result == 1) {
-               char *tmp;
-
                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);
-               tmp = smbldap_get_dn(ldap_state->smbldap_state->ldap_struct, entry);
-               if (!tmp) {
-                       goto fn_exit;
-               }
-               dn = talloc_asprintf(ctx, "%s", tmp);
-               SAFE_FREE(tmp);
+               dn = smbldap_talloc_dn(ctx, ldap_state->smbldap_state->ldap_struct, entry);
                if (!dn) {
                        status = NT_STATUS_NO_MEMORY;
                        goto fn_exit;
@@ -2200,17 +2193,11 @@ static NTSTATUS ldapsam_add_sam_account(struct pdb_methods *my_methods, struct s
 
                /* Check if we need to update an existing entry */
                if (num_result == 1) {
-                       char *tmp;
 
                        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);
-                       tmp = smbldap_get_dn (ldap_state->smbldap_state->ldap_struct, entry);
-                       if (!tmp) {
-                               goto fn_exit;
-                       }
-                       dn = talloc_asprintf(ctx, "%s", tmp);
-                       SAFE_FREE(tmp);
+                       dn = smbldap_talloc_dn (ctx, ldap_state->smbldap_state->ldap_struct, entry);
                        if (!dn) {
                                status = NT_STATUS_NO_MEMORY;
                                goto fn_exit;
@@ -3525,7 +3512,7 @@ static NTSTATUS ldapsam_modify_aliasmem(struct pdb_methods *methods,
                return NT_STATUS_UNSUCCESSFUL;
        }
 
-       dn = smbldap_get_dn(ldap_state->smbldap_state->ldap_struct, entry);
+       dn = smbldap_talloc_dn(NULL, ldap_state->smbldap_state->ldap_struct, entry);
        if (!dn) {
                ldap_msgfree(result);
                return NT_STATUS_UNSUCCESSFUL;
@@ -3540,7 +3527,7 @@ static NTSTATUS ldapsam_modify_aliasmem(struct pdb_methods *methods,
 
        ldap_mods_free(mods, True);
        ldap_msgfree(result);
-       SAFE_FREE(dn);
+       TALLOC_FREE(dn);
 
        if (rc == LDAP_TYPE_OR_VALUE_EXISTS) {
                return NT_STATUS_MEMBER_IN_ALIAS;
@@ -6307,14 +6294,14 @@ NTSTATUS pdb_init_ldapsam(struct pdb_methods **pdb_method, const char *location)
                return NT_STATUS_UNSUCCESSFUL;
        }
 
-       dn = smbldap_get_dn(ldap_state->smbldap_state->ldap_struct, entry);
+       dn = smbldap_talloc_dn(talloc_tos(), ldap_state->smbldap_state->ldap_struct, entry);
        if (!dn) {
                ldap_msgfree(result);
                return NT_STATUS_UNSUCCESSFUL;
        }
 
        ldap_state->domain_dn = smb_xstrdup(dn);
-       ldap_memfree(dn);
+       TALLOC_FREE(dn);
 
        domain_sid_string = smbldap_talloc_single_attribute(
                    ldap_state->smbldap_state->ldap_struct,
index 1edd665d545e6d9a15f1dd3db4d25fa2c8288e7e..08665e46175a001635c390a7de98d00acc53eee5 100644 (file)
@@ -788,7 +788,7 @@ static NTSTATUS pdb_nds_update_login_attempts(struct pdb_methods *methods,
                }
 
                entry = ldap_first_entry(ldap_state->smbldap_state->ldap_struct, result);
-               dn = smbldap_get_dn(ldap_state->smbldap_state->ldap_struct, entry);
+               dn = smbldap_talloc_dn(NULL, ldap_state->smbldap_state->ldap_struct, entry);
                if (!dn) {
                        return NT_STATUS_OBJECT_NAME_NOT_FOUND;
                }
@@ -811,6 +811,7 @@ static NTSTATUS pdb_nds_update_login_attempts(struct pdb_methods *methods,
                        
                        rc = smb_ldap_setup_full_conn(&ld, ldap_state->location);
                        if (rc) {
+                               TALLOC_FREE(dn);
                                return NT_STATUS_INVALID_CONNECTION;
                        }
 
@@ -841,6 +842,7 @@ static NTSTATUS pdb_nds_update_login_attempts(struct pdb_methods *methods,
                                return nt_status;
                        }
                }
+               TALLOC_FREE(dn);
        }
        
        return NT_STATUS_OK;