]> git.samba.org - ira/wip.git/blob - source4/libcli/dgram/netlogon.c
r10997: r11980@SERNOX (orig r10037): metze | 2005-09-05 14:21:40 +0200
[ira/wip.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 "lib/events/events.h"
25 #include "dlinklist.h"
26 #include "libcli/nbt/libnbt.h"
27 #include "libcli/dgram/libdgram.h"
28 #include "lib/socket/socket.h"
29 #include "librpc/gen_ndr/ndr_nbt.h"
30
31 /* 
32    send a netlogon mailslot request 
33 */
34 NTSTATUS dgram_mailslot_netlogon_send(struct nbt_dgram_socket *dgmsock,
35                                       struct nbt_name *dest_name,
36                                       const struct nbt_peer_socket *dest,
37                                       struct nbt_name *src_name,
38                                       struct nbt_netlogon_packet *request)
39 {
40         NTSTATUS status;
41         DATA_BLOB blob;
42         TALLOC_CTX *tmp_ctx = talloc_new(dgmsock);
43
44         status = ndr_push_struct_blob(&blob, tmp_ctx, request, 
45                                       (ndr_push_flags_fn_t)ndr_push_nbt_netlogon_packet);
46         if (!NT_STATUS_IS_OK(status)) {
47                 talloc_free(tmp_ctx);
48                 return status;
49         }
50
51
52         status = dgram_mailslot_send(dgmsock, DGRAM_DIRECT_UNIQUE, 
53                                      NBT_MAILSLOT_NETLOGON,
54                                      dest_name, dest, 
55                                      src_name, &blob);
56         talloc_free(tmp_ctx);
57         return status;
58 }
59
60
61 /* 
62    send a netlogon mailslot reply
63 */
64 NTSTATUS dgram_mailslot_netlogon_reply(struct nbt_dgram_socket *dgmsock,
65                                        struct nbt_dgram_packet *request,
66                                        const char *mailslot_name,
67                                        struct nbt_netlogon_packet *reply)
68 {
69         NTSTATUS status;
70         DATA_BLOB blob;
71         TALLOC_CTX *tmp_ctx = talloc_new(dgmsock);
72         struct nbt_name myname;
73         struct nbt_peer_socket dest;
74
75         status = ndr_push_struct_blob(&blob, tmp_ctx, reply, 
76                                       (ndr_push_flags_fn_t)ndr_push_nbt_netlogon_packet);
77         if (!NT_STATUS_IS_OK(status)) {
78                 talloc_free(tmp_ctx);
79                 return status;
80         }
81
82         make_nbt_name_client(&myname, lp_netbios_name());
83
84         dest.port = request->src_port;
85         dest.addr = request->src_addr;
86         status = dgram_mailslot_send(dgmsock, DGRAM_DIRECT_UNIQUE, 
87                                      mailslot_name,
88                                      &request->data.msg.source_name,
89                                      &dest,
90                                      &myname, &blob);
91         talloc_free(tmp_ctx);
92         return status;
93 }
94
95
96 /*
97   parse a netlogon response. The packet must be a valid mailslot packet
98 */
99 NTSTATUS dgram_mailslot_netlogon_parse(struct dgram_mailslot_handler *dgmslot,
100                                        TALLOC_CTX *mem_ctx,
101                                        struct nbt_dgram_packet *dgram,
102                                        struct nbt_netlogon_packet *netlogon)
103 {
104         DATA_BLOB data = dgram_mailslot_data(dgram);
105         NTSTATUS status;
106
107         status = ndr_pull_struct_blob(&data, mem_ctx, netlogon, 
108                                       (ndr_pull_flags_fn_t)ndr_pull_nbt_netlogon_packet);
109         if (!NT_STATUS_IS_OK(status)) {
110                 DEBUG(0,("Failed to parse netlogon packet of length %d\n", 
111                          (int)data.length));
112                 if (DEBUGLVL(10)) {
113                         file_save("netlogon.dat", data.data, data.length);
114                 }
115         }
116         return status;
117 }