r12608: Remove some unused #include lines.
[ira/wip.git] / source4 / libcli / dgram / ntlogon.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    handling for ntlogon 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 ntlogon mailslot request 
28 */
29 NTSTATUS dgram_mailslot_ntlogon_send(struct nbt_dgram_socket *dgmsock,
30                                      enum dgram_msg_type msg_type,
31                                      struct nbt_name *dest_name,
32                                      const struct nbt_peer_socket *dest,
33                                      struct nbt_name *src_name,
34                                      struct nbt_ntlogon_packet *request)
35 {
36         NTSTATUS status;
37         DATA_BLOB blob;
38         TALLOC_CTX *tmp_ctx = talloc_new(dgmsock);
39
40         status = ndr_push_struct_blob(&blob, tmp_ctx, request, 
41                                       (ndr_push_flags_fn_t)ndr_push_nbt_ntlogon_packet);
42         if (!NT_STATUS_IS_OK(status)) {
43                 talloc_free(tmp_ctx);
44                 return status;
45         }
46
47
48         status = dgram_mailslot_send(dgmsock, msg_type,
49                                      NBT_MAILSLOT_NTLOGON,
50                                      dest_name, dest, 
51                                      src_name, &blob);
52         talloc_free(tmp_ctx);
53         return status;
54 }
55
56
57 /* 
58    send a ntlogon mailslot reply
59 */
60 NTSTATUS dgram_mailslot_ntlogon_reply(struct nbt_dgram_socket *dgmsock,
61                                       struct nbt_dgram_packet *request,
62                                       const char *mailslot_name,
63                                       struct nbt_ntlogon_packet *reply)
64 {
65         NTSTATUS status;
66         DATA_BLOB blob;
67         TALLOC_CTX *tmp_ctx = talloc_new(dgmsock);
68         struct nbt_name myname;
69         struct nbt_peer_socket dest;
70
71         status = ndr_push_struct_blob(&blob, tmp_ctx, reply, 
72                                       (ndr_push_flags_fn_t)ndr_push_nbt_ntlogon_packet);
73         if (!NT_STATUS_IS_OK(status)) {
74                 talloc_free(tmp_ctx);
75                 return status;
76         }
77
78         make_nbt_name_client(&myname, lp_netbios_name());
79
80         dest.port = request->src_port;
81         dest.addr = request->src_addr;
82         status = dgram_mailslot_send(dgmsock, DGRAM_DIRECT_UNIQUE, 
83                                      mailslot_name,
84                                      &request->data.msg.source_name,
85                                      &dest,
86                                      &myname, &blob);
87         talloc_free(tmp_ctx);
88         return status;
89 }
90
91
92 /*
93   parse a ntlogon response. The packet must be a valid mailslot packet
94 */
95 NTSTATUS dgram_mailslot_ntlogon_parse(struct dgram_mailslot_handler *dgmslot,
96                                       TALLOC_CTX *mem_ctx,
97                                       struct nbt_dgram_packet *dgram,
98                                       struct nbt_ntlogon_packet *ntlogon)
99 {
100         DATA_BLOB data = dgram_mailslot_data(dgram);
101         NTSTATUS status;
102
103         status = ndr_pull_struct_blob(&data, mem_ctx, ntlogon, 
104                                       (ndr_pull_flags_fn_t)ndr_pull_nbt_ntlogon_packet);
105         if (!NT_STATUS_IS_OK(status)) {
106                 DEBUG(0,("Failed to parse ntlogon packet of length %d\n", 
107                          (int)data.length));
108                 if (DEBUGLVL(10)) {
109                         file_save("ntlogon.dat", data.data, data.length);
110                 }
111         }
112         return status;
113 }