diff options
Diffstat (limited to 'source3')
-rw-r--r-- | source3/lib/util_str.c | 16 | ||||
-rw-r--r-- | source3/rpcclient/rpcclient.c | 7 | ||||
-rw-r--r-- | source3/utils/ntlm_auth.c | 42 |
3 files changed, 34 insertions, 31 deletions
diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index 1401d6d853..1252c6756b 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -795,9 +795,14 @@ size_t strhex_to_str(char *p, size_t len, const char *strhex) return num_chars; } -DATA_BLOB strhex_to_data_blob(const char *strhex) +DATA_BLOB strhex_to_data_blob(TALLOC_CTX *mem_ctx, const char *strhex) { - DATA_BLOB ret_blob = data_blob(NULL, strlen(strhex)/2+1); + DATA_BLOB ret_blob; + + if (mem_ctx != NULL) + ret_blob = data_blob_talloc(mem_ctx, NULL, strlen(strhex)/2+1); + else + data_blob(NULL, strlen(strhex)/2+1); ret_blob.length = strhex_to_str((char*)ret_blob.data, strlen(strhex), @@ -810,16 +815,17 @@ DATA_BLOB strhex_to_data_blob(const char *strhex) * Routine to print a buffer as HEX digits, into an allocated string. */ -void hex_encode(const unsigned char *buff_in, size_t len, char **out_hex_buffer) +char *hex_encode(TALLOC_CTX *mem_ctx, const unsigned char *buff_in, size_t len) { int i; char *hex_buffer; - *out_hex_buffer = SMB_XMALLOC_ARRAY(char, (len*2)+1); - hex_buffer = *out_hex_buffer; + hex_buffer = TALLOC_ARRAY(mem_ctx, char, (len*2)+1); for (i = 0; i < len; i++) slprintf(&hex_buffer[i*2], 3, "%02X", buff_in[i]); + + return hex_buffer; } /** diff --git a/source3/rpcclient/rpcclient.c b/source3/rpcclient/rpcclient.c index 3112db19ad..34e81cafe6 100644 --- a/source3/rpcclient/rpcclient.c +++ b/source3/rpcclient/rpcclient.c @@ -384,11 +384,10 @@ static NTSTATUS setup_schannel(struct cli_state *cli, int pipe_auth_flags, ret = cli_nt_setup_netsec(cli, sec_channel_type, pipe_auth_flags, trust_password); if (NT_STATUS_IS_OK(ret)) { char *hex_session_key; - hex_encode(cli->pipes[cli->pipe_idx].auth_info.sess_key, - sizeof(cli->pipes[cli->pipe_idx].auth_info.sess_key), - &hex_session_key); + hex_session_key = hex_encode(NULL, cli->pipes[cli->pipe_idx].auth_info.sess_key, + sizeof(cli->pipes[cli->pipe_idx].auth_info.sess_key)); printf("Got Session key: %s\n", hex_session_key); - SAFE_FREE(hex_session_key); + talloc_free(hex_session_key); } return ret; } diff --git a/source3/utils/ntlm_auth.c b/source3/utils/ntlm_auth.c index 6d5737aad4..3fdd657a2d 100644 --- a/source3/utils/ntlm_auth.c +++ b/source3/utils/ntlm_auth.c @@ -1470,21 +1470,21 @@ static void manage_ntlm_server_1_request(enum stdio_helper_mode stdio_helper_mod if (ntlm_server_1_lm_session_key && (memcmp(zeros, lm_key, sizeof(lm_key)) != 0)) { - hex_encode((const unsigned char *)lm_key, - sizeof(lm_key), - &hex_lm_key); + hex_lm_key = hex_encode(NULL, + (const unsigned char *)lm_key, + sizeof(lm_key)); x_fprintf(x_stdout, "LANMAN-Session-Key: %s\n", hex_lm_key); - SAFE_FREE(hex_lm_key); + talloc_free(hex_lm_key); } if (ntlm_server_1_user_session_key && (memcmp(zeros, user_session_key, sizeof(user_session_key)) != 0)) { - hex_encode((const unsigned char *)user_session_key, - sizeof(user_session_key), - &hex_user_session_key); + hex_user_session_key = hex_encode(NULL, + (const unsigned char *)user_session_key, + sizeof(user_session_key)); x_fprintf(x_stdout, "User-Session-Key: %s\n", hex_user_session_key); - SAFE_FREE(hex_user_session_key); + talloc_free(hex_user_session_key); } } } @@ -1533,7 +1533,7 @@ static void manage_ntlm_server_1_request(enum stdio_helper_mode stdio_helper_mod } if (strequal(request, "LANMAN-Challenge")) { - challenge = strhex_to_data_blob(parameter); + challenge = strhex_to_data_blob(NULL, parameter); if (challenge.length != 8) { x_fprintf(x_stdout, "Error: hex decode of %s failed! (got %d bytes, expected 8)\n.\n", parameter, @@ -1541,7 +1541,7 @@ static void manage_ntlm_server_1_request(enum stdio_helper_mode stdio_helper_mod challenge = data_blob(NULL, 0); } } else if (strequal(request, "NT-Response")) { - nt_response = strhex_to_data_blob(parameter); + nt_response = strhex_to_data_blob(NULL, parameter); if (nt_response.length < 24) { x_fprintf(x_stdout, "Error: hex decode of %s failed! (only got %d bytes, needed at least 24)\n.\n", parameter, @@ -1549,7 +1549,7 @@ static void manage_ntlm_server_1_request(enum stdio_helper_mode stdio_helper_mod nt_response = data_blob(NULL, 0); } } else if (strequal(request, "LANMAN-Response")) { - lm_response = strhex_to_data_blob(parameter); + lm_response = strhex_to_data_blob(NULL, parameter); if (lm_response.length != 24) { x_fprintf(x_stdout, "Error: hex decode of %s failed! (got %d bytes, expected 24)\n.\n", parameter, @@ -1672,20 +1672,18 @@ static BOOL check_auth_crap(void) if (request_lm_key && (memcmp(zeros, lm_key, sizeof(lm_key)) != 0)) { - hex_encode((const unsigned char *)lm_key, - sizeof(lm_key), - &hex_lm_key); + hex_lm_key = hex_encode(NULL, (const unsigned char *)lm_key, + sizeof(lm_key)); x_fprintf(x_stdout, "LM_KEY: %s\n", hex_lm_key); - SAFE_FREE(hex_lm_key); + talloc_free(hex_lm_key); } if (request_user_session_key && (memcmp(zeros, user_session_key, sizeof(user_session_key)) != 0)) { - hex_encode((const unsigned char *)user_session_key, - sizeof(user_session_key), - &hex_user_session_key); + hex_user_session_key = hex_encode(NULL, (const unsigned char *)user_session_key, + sizeof(user_session_key)); x_fprintf(x_stdout, "NT_KEY: %s\n", hex_user_session_key); - SAFE_FREE(hex_user_session_key); + talloc_free(hex_user_session_key); } return True; @@ -1775,7 +1773,7 @@ enum { while((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case OPT_CHALLENGE: - opt_challenge = strhex_to_data_blob(hex_challenge); + opt_challenge = strhex_to_data_blob(NULL, hex_challenge); if (opt_challenge.length != 8) { x_fprintf(x_stderr, "hex decode of %s failed! (only got %d bytes)\n", hex_challenge, @@ -1784,7 +1782,7 @@ enum { } break; case OPT_LM: - opt_lm_response = strhex_to_data_blob(hex_lm_response); + opt_lm_response = strhex_to_data_blob(NULL, hex_lm_response); if (opt_lm_response.length != 24) { x_fprintf(x_stderr, "hex decode of %s failed! (only got %d bytes)\n", hex_lm_response, @@ -1794,7 +1792,7 @@ enum { break; case OPT_NT: - opt_nt_response = strhex_to_data_blob(hex_nt_response); + opt_nt_response = strhex_to_data_blob(NULL, hex_nt_response); if (opt_nt_response.length < 24) { x_fprintf(x_stderr, "hex decode of %s failed! (only got %d bytes)\n", hex_nt_response, |