summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2011-01-02 14:43:18 +0100
committerVolker Lendecke <vl@samba.org>2011-01-07 13:28:06 +0100
commit126b1806b8e8fba98de94e217836680608621726 (patch)
treefbef2052fefff7f2c4450fedaaeea5dd48f89f59 /source3
parent0376d03e6db6713285bad9ad27c3b48e8c11b848 (diff)
downloadsamba-126b1806b8e8fba98de94e217836680608621726.tar.gz
samba-126b1806b8e8fba98de94e217836680608621726.tar.bz2
samba-126b1806b8e8fba98de94e217836680608621726.zip
s3: Factor out parse_getdc_response
Diffstat (limited to 'source3')
-rw-r--r--source3/libsmb/clidgram.c120
1 files changed, 65 insertions, 55 deletions
diff --git a/source3/libsmb/clidgram.c b/source3/libsmb/clidgram.c
index 734564dcbb..fe6269b9e1 100644
--- a/source3/libsmb/clidgram.c
+++ b/source3/libsmb/clidgram.c
@@ -216,19 +216,16 @@ bool send_getdc_request(struct messaging_context *msg_ctx,
return NT_STATUS_IS_OK(status);
}
-bool receive_getdc_response(TALLOC_CTX *mem_ctx,
- const struct sockaddr_storage *dc_ss,
- const char *domain_name,
- int dgm_id,
- uint32_t *nt_version,
- const char **dc_name,
- struct netlogon_samlogon_response **samlogon_response)
+static bool parse_getdc_response(
+ struct packet_struct *packet,
+ TALLOC_CTX *mem_ctx,
+ const char *domain_name,
+ uint32_t *nt_version,
+ const char **dc_name,
+ struct netlogon_samlogon_response **samlogon_response)
{
- struct packet_struct *packet = NULL;
- char *my_mailslot = NULL;
- struct in_addr dc_ip;
DATA_BLOB blob;
- struct netlogon_samlogon_response *r = NULL;
+ struct netlogon_samlogon_response *r;
union dgram_message_body p;
enum ndr_err_code ndr_err;
NTSTATUS status;
@@ -236,37 +233,16 @@ bool receive_getdc_response(TALLOC_CTX *mem_ctx,
const char *returned_dc = NULL;
const char *returned_domain = NULL;
- if (dc_ss->ss_family != AF_INET) {
- return false;
- }
-
- dc_ip = ((struct sockaddr_in *)dc_ss)->sin_addr;
-
- my_mailslot = mailslot_name(mem_ctx, dc_ip);
- if (!my_mailslot) {
- return false;
- }
-
- packet = receive_unexpected(DGRAM_PACKET, dgm_id, my_mailslot);
-
- if (packet == NULL) {
- DEBUG(5, ("Did not receive packet for %s\n", my_mailslot));
- return False;
- }
-
- DEBUG(5, ("Received packet for %s\n", my_mailslot));
-
blob = data_blob_const(packet->packet.dgram.data,
packet->packet.dgram.datasize);
-
if (blob.length < 4) {
- DEBUG(0,("invalid length: %d\n", (int)blob.length));
- goto fail;
+ DEBUG(1, ("invalid length: %d\n", (int)blob.length));
+ return false;
}
if (RIVAL(blob.data,0) != DGRAM_SMB) {
- DEBUG(0,("invalid packet\n"));
- goto fail;
+ DEBUG(1, ("invalid packet\n"));
+ return false;
}
blob.data += 4;
@@ -275,13 +251,13 @@ bool receive_getdc_response(TALLOC_CTX *mem_ctx,
ndr_err = ndr_pull_union_blob_all(&blob, mem_ctx, &p, DGRAM_SMB,
(ndr_pull_flags_fn_t)ndr_pull_dgram_smb_packet);
if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
- DEBUG(0,("failed to parse packet\n"));
- goto fail;
+ DEBUG(1, ("failed to parse packet\n"));
+ return false;
}
if (p.smb.smb_command != SMB_TRANSACTION) {
- DEBUG(0,("invalid smb_command: %d\n", p.smb.smb_command));
- goto fail;
+ DEBUG(1, ("invalid smb_command: %d\n", p.smb.smb_command));
+ return false;
}
if (DEBUGLEVEL >= 10) {
@@ -292,12 +268,13 @@ bool receive_getdc_response(TALLOC_CTX *mem_ctx,
r = TALLOC_ZERO_P(mem_ctx, struct netlogon_samlogon_response);
if (!r) {
- goto fail;
+ return false;
}
status = pull_netlogon_samlogon_response(&blob, mem_ctx, r);
if (!NT_STATUS_IS_OK(status)) {
- goto fail;
+ TALLOC_FREE(r);
+ return false;
}
map_netlogon_samlogon_response(r);
@@ -311,17 +288,19 @@ bool receive_getdc_response(TALLOC_CTX *mem_ctx,
if (!strequal(returned_domain, domain_name)) {
DEBUG(3, ("GetDC: Expected domain %s, got %s\n",
domain_name, returned_domain));
- goto fail;
+ TALLOC_FREE(r);
+ return false;
}
+ if (*returned_dc == '\\') returned_dc += 1;
+ if (*returned_dc == '\\') returned_dc += 1;
+
*dc_name = talloc_strdup(mem_ctx, returned_dc);
if (!*dc_name) {
- goto fail;
+ TALLOC_FREE(r);
+ return false;
}
- if (**dc_name == '\\') *dc_name += 1;
- if (**dc_name == '\\') *dc_name += 1;
-
if (samlogon_response) {
*samlogon_response = r;
} else {
@@ -331,15 +310,46 @@ bool receive_getdc_response(TALLOC_CTX *mem_ctx,
DEBUG(10, ("GetDC gave name %s for domain %s\n",
*dc_name, returned_domain));
- free_packet(packet);
- TALLOC_FREE(my_mailslot);
return True;
+}
-fail:
- TALLOC_FREE(my_mailslot);
- TALLOC_FREE(r);
- if (packet != NULL) {
- free_packet(packet);
+bool receive_getdc_response(TALLOC_CTX *mem_ctx,
+ const struct sockaddr_storage *dc_ss,
+ const char *domain_name,
+ int dgm_id,
+ uint32_t *nt_version,
+ const char **dc_name,
+ struct netlogon_samlogon_response **samlogon_response)
+{
+ struct packet_struct *packet = NULL;
+ char *my_mailslot = NULL;
+ struct in_addr dc_ip;
+ bool ret;
+
+
+ if (dc_ss->ss_family != AF_INET) {
+ return false;
+ }
+
+ dc_ip = ((struct sockaddr_in *)dc_ss)->sin_addr;
+
+ my_mailslot = mailslot_name(mem_ctx, dc_ip);
+ if (!my_mailslot) {
+ return false;
}
- return false;
+
+ packet = receive_unexpected(DGRAM_PACKET, dgm_id, my_mailslot);
+
+ if (packet == NULL) {
+ DEBUG(5, ("Did not receive packet for %s\n", my_mailslot));
+ return False;
+ }
+
+ DEBUG(5, ("Received packet for %s\n", my_mailslot));
+
+ ret = parse_getdc_response(packet, mem_ctx, domain_name, nt_version,
+ dc_name, samlogon_response);
+
+ free_packet(packet);
+ return ret;
}