Make base64_encode_data_blob return a talloced string
authorVolker Lendecke <vl@sernet.de>
Sun, 28 Oct 2007 18:15:08 +0000 (19:15 +0100)
committerStefan Metzmacher <metze@samba.org>
Fri, 9 Nov 2007 14:12:30 +0000 (15:12 +0100)
source/lib/afs.c
source/lib/util_str.c
source/rpc_server/srv_samr_util.c
source/utils/net_rpc_samsync.c
source/utils/ntlm_auth.c

index e9a705902804ed9248ab5b9d74ac15a6b2737585..35f213fd080ba58dcdfe2e154990d72bfefe37ba 100644 (file)
@@ -53,7 +53,7 @@ static char *afs_encode_token(const char *cell, const DATA_BLOB ticket,
 
        base64_key = base64_encode_data_blob(key);
        if (base64_key == NULL) {
-               free(base64_ticket);
+               TALLOC_FREE(base64_ticket);
                return NULL;
        }
 
@@ -63,8 +63,8 @@ static char *afs_encode_token(const char *cell, const DATA_BLOB ticket,
 
        DEBUG(10, ("Got ticket string:\n%s\n", result));
 
-       free(base64_ticket);
-       free(base64_key);
+       TALLOC_FREE(base64_ticket);
+       TALLOC_FREE(base64_key);
 
        return result;
 }
index 6458ae3e05d0e6cf7a1f6fa0863b0cdbb527a663..f1078c6383a57fe738836d37c22454080fc03e60 100644 (file)
@@ -2528,7 +2528,8 @@ char *base64_encode_data_blob(DATA_BLOB data)
        out_cnt = 0;
        len = data.length;
        output_len = data.length * 2;
-       result = (char *)SMB_MALLOC(output_len); /* get us plenty of space */
+       result = TALLOC_ARRAY(talloc_tos(), char, output_len); /* get us plenty of space */
+       SMB_ASSERT(result != NULL);
 
        while (len-- && out_cnt < (data.length * 2) - 5) {
                int c = (unsigned char) *(data.data++);
index 7bac25e61173d1e521664482746a1d9bd6cba518..f7e20797a7ed5920aba27c711cd80fa92d3574a6 100644 (file)
@@ -58,7 +58,7 @@ void copy_id20_to_sam_passwd(struct samu *to, SAM_USER_INFO_20 *from)
                if (STRING_CHANGED_NC(old_string,new_string))
                        pdb_set_munged_dial(to   , new_string, PDB_CHANGED);
 
-               SAFE_FREE(new_string);
+               TALLOC_FREE(new_string);
        }
 }
 
@@ -201,7 +201,7 @@ void copy_id21_to_sam_passwd(struct samu *to, SAM_USER_INFO_21 *from)
                if (STRING_CHANGED_NC(old_string,newstr))
                        pdb_set_munged_dial(to   , newstr, PDB_CHANGED);
 
-               SAFE_FREE(newstr);
+               TALLOC_FREE(newstr);
        }
        
        if (from->fields_present & ACCT_RID) {
@@ -425,7 +425,7 @@ void copy_id23_to_sam_passwd(struct samu *to, SAM_USER_INFO_23 *from)
                if (STRING_CHANGED_NC(old_string, newstr))
                        pdb_set_munged_dial(to   , newstr, PDB_CHANGED);
 
-               SAFE_FREE(newstr);
+               TALLOC_FREE(newstr);
        }
        
        if (from->fields_present & ACCT_RID) {
@@ -637,7 +637,7 @@ void copy_id25_to_sam_passwd(struct samu *to, SAM_USER_INFO_25 *from)
                if (STRING_CHANGED_NC(old_string,newstr))
                        pdb_set_munged_dial(to   , newstr, PDB_CHANGED);
 
-               SAFE_FREE(newstr);
+               TALLOC_FREE(newstr);
        }
        
        if (from->fields_present & ACCT_RID) {
index 2b5eac6999d0fee4c30bfd3e28184900fb434dfc..3d88a974bfcca6a58cc689ecd52d3910a4d1adc7 100644 (file)
@@ -369,7 +369,7 @@ static NTSTATUS sam_account_from_delta(struct samu *account, SAM_ACCOUNT_INFO *d
 
                if (STRING_CHANGED_NC(old_string, newstr))
                        pdb_set_munged_dial(account, newstr, PDB_CHANGED);
-               SAFE_FREE(newstr);
+               TALLOC_FREE(newstr);
        }
 
        /* User and group sid */
@@ -1385,7 +1385,7 @@ static int fprintf_attr(FILE *add_fd, const char *attr_name,
 
        res = fprintf(add_fd, "%s:: %s\n", attr_name, base64);
        TALLOC_FREE(value);
-       SAFE_FREE(base64);
+       TALLOC_FREE(base64);
        return res;
 }
 
index b51827fd83587d12a964d058e67e2b43e6d1a0d6..0b50ced0b97ab01be5445559af0739bf280f310a 100644 (file)
@@ -738,7 +738,7 @@ static void manage_squid_ntlmssp_request(enum stdio_helper_mode stdio_helper_mod
                if(have_session_key) {
                        char *key64 = base64_encode_data_blob(session_key);
                        x_fprintf(x_stdout, "GK %s\n", key64?key64:"<NULL>");
-                       SAFE_FREE(key64);
+                       TALLOC_FREE(key64);
                } else {
                        x_fprintf(x_stdout, "BH\n");
                }
@@ -767,7 +767,7 @@ static void manage_squid_ntlmssp_request(enum stdio_helper_mode stdio_helper_mod
        if (NT_STATUS_EQUAL(nt_status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
                char *reply_base64 = base64_encode_data_blob(reply);
                x_fprintf(x_stdout, "TT %s\n", reply_base64);
-               SAFE_FREE(reply_base64);
+               TALLOC_FREE(reply_base64);
                data_blob_free(&reply);
                DEBUG(10, ("NTLMSSP challenge\n"));
        } else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_ACCESS_DENIED)) {
@@ -888,7 +888,7 @@ static void manage_client_ntlmssp_request(enum stdio_helper_mode stdio_helper_mo
                if(have_session_key) {
                        char *key64 = base64_encode_data_blob(session_key);
                        x_fprintf(x_stdout, "GK %s\n", key64?key64:"<NULL>");
-                       SAFE_FREE(key64);
+                       TALLOC_FREE(key64);
                }
                else {
                        x_fprintf(x_stdout, "BH\n");
@@ -928,7 +928,7 @@ static void manage_client_ntlmssp_request(enum stdio_helper_mode stdio_helper_mo
                } else { 
                        x_fprintf(x_stdout, "KK %s\n", reply_base64);
                }
-               SAFE_FREE(reply_base64);
+               TALLOC_FREE(reply_base64);
                if (first) {
                        initial_message = reply;
                } else {
@@ -938,7 +938,7 @@ static void manage_client_ntlmssp_request(enum stdio_helper_mode stdio_helper_mo
        } else if (NT_STATUS_IS_OK(nt_status)) {
                char *reply_base64 = base64_encode_data_blob(reply);
                x_fprintf(x_stdout, "AF %s\n", reply_base64);
-               SAFE_FREE(reply_base64);
+               TALLOC_FREE(reply_base64);
 
                if(have_session_key)
                        data_blob_free(&session_key);
@@ -1033,7 +1033,7 @@ static void offer_gss_spnego_mechs(void) {
        reply_base64 = base64_encode_data_blob(token);
        x_fprintf(x_stdout, "TT %s *\n", reply_base64);
 
-       SAFE_FREE(reply_base64);
+       TALLOC_FREE(reply_base64);
        data_blob_free(&token);
        DEBUG(10, ("sent SPNEGO negTokenInit\n"));
        return;
@@ -1264,7 +1264,7 @@ static void manage_gss_spnego_request(enum stdio_helper_mode stdio_helper_mode,
        x_fprintf(x_stdout, "%s %s %s\n",
                  reply_code, reply_base64, reply_argument);
 
-       SAFE_FREE(reply_base64);
+       TALLOC_FREE(reply_base64);
        data_blob_free(&token);
 
        return;
@@ -1329,7 +1329,7 @@ static bool manage_client_ntlmssp_init(SPNEGO_DATA spnego)
        to_server_base64 = base64_encode_data_blob(to_server);
        data_blob_free(&to_server);
        x_fprintf(x_stdout, "KK %s\n", to_server_base64);
-       SAFE_FREE(to_server_base64);
+       TALLOC_FREE(to_server_base64);
        return True;
 }
 
@@ -1387,7 +1387,7 @@ static void manage_client_ntlmssp_targ(SPNEGO_DATA spnego)
        to_server_base64 = base64_encode_data_blob(to_server);
        data_blob_free(&to_server);
        x_fprintf(x_stdout, "KK %s\n", to_server_base64);
-       SAFE_FREE(to_server_base64);
+       TALLOC_FREE(to_server_base64);
        return;
 }
 
@@ -1474,7 +1474,7 @@ static bool manage_client_krb5_init(SPNEGO_DATA spnego)
        reply_base64 = base64_encode_data_blob(to_server);
        x_fprintf(x_stdout, "KK %s *\n", reply_base64);
 
-       SAFE_FREE(reply_base64);
+       TALLOC_FREE(reply_base64);
        data_blob_free(&to_server);
        DEBUG(10, ("sent GSS-SPNEGO KERBEROS5 negTokenInit\n"));
        return True;