r12608: Remove some unused #include lines.
[abartlet/samba.git/.git] / source4 / libcli / dgram / netlogon.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    handling for netlogon dgram requests
5
6    Copyright (C) Andrew Tridgell 2005
7    
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 2 of the License, or
11    (at your option) any later version.
12    
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.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "includes.h"
24 #include "libcli/dgram/libdgram.h"
25
26 /* 
27    send a netlogon mailslot request 
28 */
29 NTSTATUS dgram_mailslot_netlogon_send(struct nbt_dgram_socket *dgmsock,
30                                       struct nbt_name *dest_name,
31                                       const struct nbt_peer_socket *dest,
32                                       struct nbt_name *src_name,
33                                       struct nbt_netlogon_packet *request)
34 {
35         NTSTATUS status;
36         DATA_BLOB blob;
37         TALLOC_CTX *tmp_ctx = talloc_new(dgmsock);
38
39         status = ndr_push_struct_blob(&blob, tmp_ctx, request, 
40                                       (ndr_push_flags_fn_t)ndr_push_nbt_netlogon_packet);
41         if (!NT_STATUS_IS_OK(status)) {
42                 talloc_free(tmp_ctx);
43                 return status;
44         }
45
46
47         status = dgram_mailslot_send(dgmsock, DGRAM_DIRECT_UNIQUE, 
48                                      NBT_MAILSLOT_NETLOGON,
49                                      dest_name, dest, 
50                                      src_name, &blob);
51         talloc_free(tmp_ctx);
52         return status;
53 }
54
55
56 /* 
57    send a netlogon mailslot reply
58 */
59 NTSTATUS dgram_mailslot_netlogon_reply(struct nbt_dgram_socket *dgmsock,
60                                        struct nbt_dgram_packet *request,
61                                        const char *mailslot_name,
62                                        struct nbt_netlogon_packet *reply)
63 {
64         NTSTATUS status;
65         DATA_BLOB blob;
66         TALLOC_CTX *tmp_ctx = talloc_new(dgmsock);
67         struct nbt_name myname;
68         struct nbt_peer_socket dest;
69
70         status = ndr_push_struct_blob(&blob, tmp_ctx, reply, 
71                                       (ndr_push_flags_fn_t)ndr_push_nbt_netlogon_packet);
72         if (!NT_STATUS_IS_OK(status)) {
73                 talloc_free(tmp_ctx);
74                 return status;
75         }
76
77         make_nbt_name_client(&myname, lp_netbios_name());
78
79         dest.port = request->src_port;
80         dest.addr = request->src_addr;
81         status = dgram_mailslot_send(dgmsock, DGRAM_DIRECT_UNIQUE, 
82                                      mailslot_name,
83                                      &request->data.msg.source_name,
84                                      &dest,
85                                      &myname, &blob);
86         talloc_free(tmp_ctx);
87         return status;
88 }
89
90
91 /*
92   parse a netlogon response. The packet must be a valid mailslot packet
93 */
94 NTSTATUS dgram_mailslot_netlogon_parse(struct dgram_mailslot_handler *dgmslot,
95                                        TALLOC_CTX *mem_ctx,
96                                        struct nbt_dgram_packet *dgram,
97                                        struct nbt_netlogon_packet *netlogon)
98 {
99         DATA_BLOB data = dgram_mailslot_data(dgram);
100         NTSTATUS status;
101
102         status = ndr_pull_struct_blob(&data, mem_ctx, netlogon, 
103                                       (ndr_pull_flags_fn_t)ndr_pull_nbt_netlogon_packet);
104         if (!NT_STATUS_IS_OK(status)) {
105                 DEBUG(0,("Failed to parse netlogon packet of length %d\n", 
106                          (int)data.length));
107                 if (DEBUGLVL(10)) {
108                         file_save("netlogon.dat", data.data, data.length);
109                 }
110         }
111         return status;
112 }