s3-selftest: Remove some unnecessary comma
[Samba/gebeck_regimport.git] / source4 / libcli / dgram / netlogon.c
blob0aa68642487bb33de8bb3be1eea9b65f22baaa46
1 /*
2 Unix SMB/CIFS implementation.
4 handling for netlogon dgram requests
6 Copyright (C) Andrew Tridgell 2005
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "includes.h"
23 #include "libcli/dgram/libdgram.h"
24 #include "lib/socket/socket.h"
25 #include "libcli/resolve/resolve.h"
26 #include "librpc/gen_ndr/ndr_nbt.h"
28 /*
29 send a netlogon mailslot request
31 NTSTATUS dgram_mailslot_netlogon_send(struct nbt_dgram_socket *dgmsock,
32 struct nbt_name *dest_name,
33 struct socket_address *dest,
34 const char *mailslot,
35 struct nbt_name *src_name,
36 struct nbt_netlogon_packet *request)
38 NTSTATUS status;
39 enum ndr_err_code ndr_err;
40 DATA_BLOB blob;
41 TALLOC_CTX *tmp_ctx = talloc_new(dgmsock);
43 ndr_err = ndr_push_struct_blob(&blob, tmp_ctx, request,
44 (ndr_push_flags_fn_t)ndr_push_nbt_netlogon_packet);
45 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
46 talloc_free(tmp_ctx);
47 return ndr_map_error2ntstatus(ndr_err);
51 status = dgram_mailslot_send(dgmsock, DGRAM_DIRECT_UNIQUE,
52 mailslot,
53 dest_name, dest,
54 src_name, &blob);
55 talloc_free(tmp_ctx);
56 return status;
60 /*
61 send a netlogon mailslot reply
63 NTSTATUS dgram_mailslot_netlogon_reply(struct nbt_dgram_socket *dgmsock,
64 struct nbt_dgram_packet *request,
65 const char *my_netbios_name,
66 const char *mailslot_name,
67 struct nbt_netlogon_response *reply)
69 NTSTATUS status;
70 DATA_BLOB blob;
71 TALLOC_CTX *tmp_ctx = talloc_new(dgmsock);
72 struct nbt_name myname;
73 struct socket_address *dest;
75 status = push_nbt_netlogon_response(&blob, tmp_ctx, reply);
76 if (!NT_STATUS_IS_OK(status)) {
77 return status;
80 make_nbt_name_client(&myname, my_netbios_name);
82 dest = socket_address_from_strings(tmp_ctx, dgmsock->sock->backend_name,
83 request->src_addr, request->src_port);
84 if (!dest) {
85 talloc_free(tmp_ctx);
86 return NT_STATUS_NO_MEMORY;
89 status = dgram_mailslot_send(dgmsock, DGRAM_DIRECT_UNIQUE,
90 mailslot_name,
91 &request->data.msg.source_name,
92 dest,
93 &myname, &blob);
94 talloc_free(tmp_ctx);
95 return status;
100 parse a netlogon response. The packet must be a valid mailslot packet
102 NTSTATUS dgram_mailslot_netlogon_parse_request(struct dgram_mailslot_handler *dgmslot,
103 TALLOC_CTX *mem_ctx,
104 struct nbt_dgram_packet *dgram,
105 struct nbt_netlogon_packet *netlogon)
107 DATA_BLOB data = dgram_mailslot_data(dgram);
108 enum ndr_err_code ndr_err;
110 ndr_err = ndr_pull_struct_blob(&data, mem_ctx, netlogon,
111 (ndr_pull_flags_fn_t)ndr_pull_nbt_netlogon_packet);
112 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
113 NTSTATUS status = ndr_map_error2ntstatus(ndr_err);
114 DEBUG(0,("Failed to parse netlogon packet of length %d: %s\n",
115 (int)data.length, nt_errstr(status)));
116 if (DEBUGLVL(10)) {
117 file_save("netlogon.dat", data.data, data.length);
119 return status;
121 return NT_STATUS_OK;
125 parse a netlogon response. The packet must be a valid mailslot packet
127 NTSTATUS dgram_mailslot_netlogon_parse_response(struct dgram_mailslot_handler *dgmslot,
128 TALLOC_CTX *mem_ctx,
129 struct nbt_dgram_packet *dgram,
130 struct nbt_netlogon_response *netlogon)
132 NTSTATUS status;
133 DATA_BLOB data = dgram_mailslot_data(dgram);
135 status = pull_nbt_netlogon_response(&data, mem_ctx, netlogon);
136 if (!NT_STATUS_IS_OK(status)) {
137 return status;
140 return NT_STATUS_OK;