summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorKai Blin <kai@samba.org>2008-01-19 02:12:35 +0100
committerKai Blin <kai@samba.org>2008-01-19 02:20:16 +0100
commit805caafd44cbc5fff49711b1a15fb64cc99f3ad3 (patch)
tree54c96bb7e84de810b3199b3a444ae27adef6d626 /source3
parentb97fbf58886427fbb7f3181694bf6f9648f5d0f4 (diff)
downloadsamba-805caafd44cbc5fff49711b1a15fb64cc99f3ad3.tar.gz
samba-805caafd44cbc5fff49711b1a15fb64cc99f3ad3.tar.bz2
samba-805caafd44cbc5fff49711b1a15fb64cc99f3ad3.zip
util_str: Don't return memory from talloc_tos(), use mem_ctx instead.
(This used to be commit ab0ee6e9a6a9eee317228f0c2bde254ad9a59b85)
Diffstat (limited to 'source3')
-rw-r--r--source3/lib/afs.c23
-rw-r--r--source3/lib/util_str.c6
-rw-r--r--source3/rpc_server/srv_samr_util.c12
-rw-r--r--source3/utils/net_rpc_samsync.c6
-rw-r--r--source3/utils/ntlm_auth.c25
5 files changed, 40 insertions, 32 deletions
diff --git a/source3/lib/afs.c b/source3/lib/afs.c
index a7d6f6c9f7..b3d590bf24 100644
--- a/source3/lib/afs.c
+++ b/source3/lib/afs.c
@@ -42,20 +42,23 @@ static char *afs_encode_token(const char *cell, const DATA_BLOB ticket,
const struct ClearToken *ct)
{
char *base64_ticket;
- char *result;
+ char *result = NULL;
DATA_BLOB key = data_blob(ct->HandShakeKey, 8);
char *base64_key;
+ TALLOC_CTX *mem_ctx;
+
+ mem_ctx = talloc_init("afs_encode_token");
+ if (mem_ctx == NULL)
+ goto done;
- base64_ticket = base64_encode_data_blob(ticket);
+ base64_ticket = base64_encode_data_blob(mem_ctx, ticket);
if (base64_ticket == NULL)
- return NULL;
+ goto done;
- base64_key = base64_encode_data_blob(key);
- if (base64_key == NULL) {
- TALLOC_FREE(base64_ticket);
- return NULL;
- }
+ base64_key = base64_encode_data_blob(mem_ctx, key);
+ if (base64_key == NULL)
+ goto done;
asprintf(&result, "%s\n%u\n%s\n%u\n%u\n%u\n%s\n", cell,
ct->AuthHandle, base64_key, ct->ViceId, ct->BeginTimestamp,
@@ -63,8 +66,8 @@ static char *afs_encode_token(const char *cell, const DATA_BLOB ticket,
DEBUG(10, ("Got ticket string:\n%s\n", result));
- TALLOC_FREE(base64_ticket);
- TALLOC_FREE(base64_key);
+done:
+ TALLOC_FREE(mem_ctx);
return result;
}
diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c
index 3e3268104c..bcb9197141 100644
--- a/source3/lib/util_str.c
+++ b/source3/lib/util_str.c
@@ -2415,13 +2415,13 @@ void base64_decode_inplace(char *s)
}
/**
- * Encode a base64 string into a malloc()ed string caller to free.
+ * Encode a base64 string into a talloc()ed string caller to free.
*
* From SQUID: adopted from http://ftp.sunet.se/pub2/gnu/vm/base64-encode.c
* with adjustments
**/
-char *base64_encode_data_blob(DATA_BLOB data)
+char *base64_encode_data_blob(TALLOC_CTX *mem_ctx, DATA_BLOB data)
{
int bits = 0;
int char_count = 0;
@@ -2434,7 +2434,7 @@ char *base64_encode_data_blob(DATA_BLOB data)
out_cnt = 0;
len = data.length;
output_len = data.length * 2;
- result = TALLOC_ARRAY(talloc_tos(), char, output_len); /* get us plenty of space */
+ result = TALLOC_ARRAY(mem_ctx, char, output_len); /* get us plenty of space */
SMB_ASSERT(result != NULL);
while (len-- && out_cnt < (data.length * 2) - 5) {
diff --git a/source3/rpc_server/srv_samr_util.c b/source3/rpc_server/srv_samr_util.c
index bde7936343..c8f732153c 100644
--- a/source3/rpc_server/srv_samr_util.c
+++ b/source3/rpc_server/srv_samr_util.c
@@ -44,16 +44,16 @@ void copy_id20_to_sam_passwd(struct samu *to, SAM_USER_INFO_20 *from)
char *new_string;
DATA_BLOB mung;
- if (from == NULL || to == NULL)
+ if (from == NULL || to == NULL)
return;
-
+
if (from->hdr_munged_dial.buffer) {
old_string = pdb_get_munged_dial(to);
mung.length = from->hdr_munged_dial.uni_str_len;
mung.data = (uint8 *) from->uni_munged_dial.buffer;
mung.free = NULL;
new_string = (mung.length == 0) ?
- NULL : base64_encode_data_blob(mung);
+ NULL : base64_encode_data_blob(talloc_tos(), mung);
DEBUG(10,("INFO_20 UNI_MUNGED_DIAL: %s -> %s\n",old_string, new_string));
if (STRING_CHANGED_NC(old_string,new_string))
pdb_set_munged_dial(to , new_string, PDB_CHANGED);
@@ -196,7 +196,7 @@ void copy_id21_to_sam_passwd(struct samu *to, SAM_USER_INFO_21 *from)
mung.data = (uint8 *) from->uni_munged_dial.buffer;
mung.free = NULL;
newstr = (mung.length == 0) ?
- NULL : base64_encode_data_blob(mung);
+ NULL : base64_encode_data_blob(talloc_tos(), mung);
DEBUG(10,("INFO_21 UNI_MUNGED_DIAL: %s -> %s\n",old_string, newstr));
if (STRING_CHANGED_NC(old_string,newstr))
pdb_set_munged_dial(to , newstr, PDB_CHANGED);
@@ -421,7 +421,7 @@ void copy_id23_to_sam_passwd(struct samu *to, SAM_USER_INFO_23 *from)
mung.data = (uint8 *) from->uni_munged_dial.buffer;
mung.free = NULL;
newstr = (mung.length == 0) ?
- NULL : base64_encode_data_blob(mung);
+ NULL : base64_encode_data_blob(talloc_tos(), mung);
DEBUG(10,("INFO_23 UNI_MUNGED_DIAL: %s -> %s\n",old_string, newstr));
if (STRING_CHANGED_NC(old_string, newstr))
pdb_set_munged_dial(to , newstr, PDB_CHANGED);
@@ -633,7 +633,7 @@ void copy_id25_to_sam_passwd(struct samu *to, SAM_USER_INFO_25 *from)
mung.data = (uint8 *) from->uni_munged_dial.buffer;
mung.free = NULL;
newstr = (mung.length == 0) ?
- NULL : base64_encode_data_blob(mung);
+ NULL : base64_encode_data_blob(talloc_tos(), mung);
DEBUG(10,("INFO_25 UNI_MUNGED_DIAL: %s -> %s\n",old_string, newstr));
if (STRING_CHANGED_NC(old_string,newstr))
pdb_set_munged_dial(to , newstr, PDB_CHANGED);
diff --git a/source3/utils/net_rpc_samsync.c b/source3/utils/net_rpc_samsync.c
index 779006884d..d0fcfe3aeb 100644
--- a/source3/utils/net_rpc_samsync.c
+++ b/source3/utils/net_rpc_samsync.c
@@ -365,7 +365,8 @@ static NTSTATUS sam_account_from_delta(struct samu *account, SAM_ACCOUNT_INFO *d
old_string = pdb_get_munged_dial(account);
mung.length = delta->hdr_parameters.uni_str_len;
mung.data = (uint8 *) delta->uni_parameters.buffer;
- newstr = (mung.length == 0) ? NULL : base64_encode_data_blob(mung);
+ newstr = (mung.length == 0) ? NULL :
+ base64_encode_data_blob(talloc_tos(), mung);
if (STRING_CHANGED_NC(old_string, newstr))
pdb_set_munged_dial(account, newstr, PDB_CHANGED);
@@ -1422,12 +1423,11 @@ static int fprintf_attr(FILE *add_fd, const char *attr_name,
base64_blob.data = (unsigned char *)value;
base64_blob.length = strlen(value);
- base64 = base64_encode_data_blob(base64_blob);
+ base64 = base64_encode_data_blob(value, base64_blob);
SMB_ASSERT(base64 != NULL);
res = fprintf(add_fd, "%s:: %s\n", attr_name, base64);
TALLOC_FREE(value);
- TALLOC_FREE(base64);
return res;
}
diff --git a/source3/utils/ntlm_auth.c b/source3/utils/ntlm_auth.c
index 6a702fc0cf..68bf24fec7 100644
--- a/source3/utils/ntlm_auth.c
+++ b/source3/utils/ntlm_auth.c
@@ -739,7 +739,8 @@ static void manage_squid_ntlmssp_request(enum stdio_helper_mode stdio_helper_mod
} else if (strncmp(buf, "GK", 2) == 0) {
DEBUG(10, ("Requested NTLMSSP session key\n"));
if(have_session_key) {
- char *key64 = base64_encode_data_blob(session_key);
+ char *key64 = base64_encode_data_blob(talloc_tos(),
+ session_key);
x_fprintf(x_stdout, "GK %s\n", key64?key64:"<NULL>");
TALLOC_FREE(key64);
} else {
@@ -768,7 +769,8 @@ static void manage_squid_ntlmssp_request(enum stdio_helper_mode stdio_helper_mod
nt_status = ntlmssp_update(ntlmssp_state, request, &reply);
if (NT_STATUS_EQUAL(nt_status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
- char *reply_base64 = base64_encode_data_blob(reply);
+ char *reply_base64 = base64_encode_data_blob(talloc_tos(),
+ reply);
x_fprintf(x_stdout, "TT %s\n", reply_base64);
TALLOC_FREE(reply_base64);
data_blob_free(&reply);
@@ -889,7 +891,8 @@ static void manage_client_ntlmssp_request(enum stdio_helper_mode stdio_helper_mo
DEBUG(10, ("Requested session key\n"));
if(have_session_key) {
- char *key64 = base64_encode_data_blob(session_key);
+ char *key64 = base64_encode_data_blob(talloc_tos(),
+ session_key);
x_fprintf(x_stdout, "GK %s\n", key64?key64:"<NULL>");
TALLOC_FREE(key64);
}
@@ -925,7 +928,8 @@ static void manage_client_ntlmssp_request(enum stdio_helper_mode stdio_helper_mo
}
if (NT_STATUS_EQUAL(nt_status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
- char *reply_base64 = base64_encode_data_blob(reply);
+ char *reply_base64 = base64_encode_data_blob(talloc_tos(),
+ reply);
if (first) {
x_fprintf(x_stdout, "YR %s\n", reply_base64);
} else {
@@ -939,7 +943,8 @@ static void manage_client_ntlmssp_request(enum stdio_helper_mode stdio_helper_mo
}
DEBUG(10, ("NTLMSSP challenge\n"));
} else if (NT_STATUS_IS_OK(nt_status)) {
- char *reply_base64 = base64_encode_data_blob(reply);
+ char *reply_base64 = base64_encode_data_blob(talloc_tos(),
+ reply);
x_fprintf(x_stdout, "AF %s\n", reply_base64);
TALLOC_FREE(reply_base64);
@@ -1039,7 +1044,7 @@ static void offer_gss_spnego_mechs(void) {
return;
}
- reply_base64 = base64_encode_data_blob(token);
+ reply_base64 = base64_encode_data_blob(talloc_tos(), token);
x_fprintf(x_stdout, "TT %s *\n", reply_base64);
TALLOC_FREE(reply_base64);
@@ -1276,7 +1281,7 @@ static void manage_gss_spnego_request(enum stdio_helper_mode stdio_helper_mode,
return;
}
- reply_base64 = base64_encode_data_blob(token);
+ reply_base64 = base64_encode_data_blob(talloc_tos(), token);
x_fprintf(x_stdout, "%s %s %s\n",
reply_code, reply_base64, reply_argument);
@@ -1343,7 +1348,7 @@ static bool manage_client_ntlmssp_init(SPNEGO_DATA spnego)
write_spnego_data(&to_server, &spnego);
data_blob_free(&spnego.negTokenInit.mechToken);
- to_server_base64 = base64_encode_data_blob(to_server);
+ to_server_base64 = base64_encode_data_blob(talloc_tos(), to_server);
data_blob_free(&to_server);
x_fprintf(x_stdout, "KK %s\n", to_server_base64);
TALLOC_FREE(to_server_base64);
@@ -1401,7 +1406,7 @@ static void manage_client_ntlmssp_targ(SPNEGO_DATA spnego)
write_spnego_data(&to_server, &spnego);
data_blob_free(&request);
- to_server_base64 = base64_encode_data_blob(to_server);
+ to_server_base64 = base64_encode_data_blob(talloc_tos(), to_server);
data_blob_free(&to_server);
x_fprintf(x_stdout, "KK %s\n", to_server_base64);
TALLOC_FREE(to_server_base64);
@@ -1490,7 +1495,7 @@ static bool manage_client_krb5_init(SPNEGO_DATA spnego)
return False;
}
- reply_base64 = base64_encode_data_blob(to_server);
+ reply_base64 = base64_encode_data_blob(talloc_tos(), to_server);
x_fprintf(x_stdout, "KK %s *\n", reply_base64);
TALLOC_FREE(reply_base64);