r25026: Move param/param.h out of includes.h
[tprouty/samba.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 3 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, see <http://www.gnu.org/licenses/>.
20 */
21
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"
27 #include "param/param.h"
28
29 /* 
30    send a ntlogon mailslot request 
31 */
32 NTSTATUS dgram_mailslot_ntlogon_send(struct nbt_dgram_socket *dgmsock,
33                                      enum dgram_msg_type msg_type,
34                                      struct nbt_name *dest_name,
35                                      struct socket_address *dest,
36                                      struct nbt_name *src_name,
37                                      struct nbt_ntlogon_packet *request)
38 {
39         NTSTATUS status;
40         DATA_BLOB blob;
41         TALLOC_CTX *tmp_ctx = talloc_new(dgmsock);
42
43         status = ndr_push_struct_blob(&blob, tmp_ctx, request, 
44                                       (ndr_push_flags_fn_t)ndr_push_nbt_ntlogon_packet);
45         if (!NT_STATUS_IS_OK(status)) {
46                 talloc_free(tmp_ctx);
47                 return status;
48         }
49
50
51         status = dgram_mailslot_send(dgmsock, msg_type,
52                                      NBT_MAILSLOT_NTLOGON,
53                                      dest_name, dest, 
54                                      src_name, &blob);
55         talloc_free(tmp_ctx);
56         return status;
57 }
58
59
60 /* 
61    send a ntlogon mailslot reply
62 */
63 NTSTATUS dgram_mailslot_ntlogon_reply(struct nbt_dgram_socket *dgmsock,
64                                       struct nbt_dgram_packet *request,
65                                       const char *mailslot_name,
66                                       struct nbt_ntlogon_packet *reply)
67 {
68         NTSTATUS status;
69         DATA_BLOB blob;
70         TALLOC_CTX *tmp_ctx = talloc_new(dgmsock);
71         struct nbt_name myname;
72         struct socket_address *dest;
73
74         status = ndr_push_struct_blob(&blob, tmp_ctx, reply, 
75                                       (ndr_push_flags_fn_t)ndr_push_nbt_ntlogon_packet);
76         if (!NT_STATUS_IS_OK(status)) {
77                 talloc_free(tmp_ctx);
78                 return status;
79         }
80
81         make_nbt_name_client(&myname, lp_netbios_name());
82
83         dest = socket_address_from_strings(tmp_ctx, 
84                                            dgmsock->sock->backend_name, 
85                                            request->src_addr, request->src_port);
86         if (!dest) {
87                 talloc_free(tmp_ctx);
88                 return NT_STATUS_NO_MEMORY;
89         }
90
91         status = dgram_mailslot_send(dgmsock, DGRAM_DIRECT_UNIQUE, 
92                                      mailslot_name,
93                                      &request->data.msg.source_name,
94                                      dest,
95                                      &myname, &blob);
96         talloc_free(tmp_ctx);
97         return status;
98 }
99
100
101 /*
102   parse a ntlogon response. The packet must be a valid mailslot packet
103 */
104 NTSTATUS dgram_mailslot_ntlogon_parse(struct dgram_mailslot_handler *dgmslot,
105                                       TALLOC_CTX *mem_ctx,
106                                       struct nbt_dgram_packet *dgram,
107                                       struct nbt_ntlogon_packet *ntlogon)
108 {
109         DATA_BLOB data = dgram_mailslot_data(dgram);
110         NTSTATUS status;
111
112         status = ndr_pull_struct_blob(&data, mem_ctx, ntlogon, 
113                                       (ndr_pull_flags_fn_t)ndr_pull_nbt_ntlogon_packet);
114         if (!NT_STATUS_IS_OK(status)) {
115                 DEBUG(0,("Failed to parse ntlogon packet of length %d\n", 
116                          (int)data.length));
117                 if (DEBUGLVL(10)) {
118                         file_save("ntlogon.dat", data.data, data.length);
119                 }
120         }
121         return status;
122 }