Line data Source code
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 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 "lib/util/util_file.h"
24 : #include "libcli/dgram/libdgram.h"
25 : #include "lib/socket/socket.h"
26 : #include "libcli/resolve/resolve.h"
27 : #include "librpc/gen_ndr/ndr_nbt.h"
28 :
29 : /*
30 : send a netlogon mailslot request
31 : */
32 42 : NTSTATUS dgram_mailslot_netlogon_send(struct nbt_dgram_socket *dgmsock,
33 : struct nbt_name *dest_name,
34 : struct socket_address *dest,
35 : const char *mailslot,
36 : struct nbt_name *src_name,
37 : struct nbt_netlogon_packet *request)
38 : {
39 0 : NTSTATUS status;
40 0 : enum ndr_err_code ndr_err;
41 0 : DATA_BLOB blob;
42 42 : TALLOC_CTX *tmp_ctx = talloc_new(dgmsock);
43 :
44 42 : ndr_err = ndr_push_struct_blob(&blob, tmp_ctx, request,
45 : (ndr_push_flags_fn_t)ndr_push_nbt_netlogon_packet);
46 42 : if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
47 0 : talloc_free(tmp_ctx);
48 0 : return ndr_map_error2ntstatus(ndr_err);
49 : }
50 :
51 :
52 42 : status = dgram_mailslot_send(dgmsock, DGRAM_DIRECT_UNIQUE,
53 : mailslot,
54 : dest_name, dest,
55 : src_name, &blob);
56 42 : talloc_free(tmp_ctx);
57 42 : return status;
58 : }
59 :
60 :
61 : /*
62 : send a netlogon mailslot reply
63 : */
64 45 : NTSTATUS dgram_mailslot_netlogon_reply(struct nbt_dgram_socket *dgmsock,
65 : struct nbt_dgram_packet *request,
66 : const char *my_netbios_name,
67 : const char *mailslot_name,
68 : struct nbt_netlogon_response *reply)
69 : {
70 0 : NTSTATUS status;
71 0 : DATA_BLOB blob;
72 45 : TALLOC_CTX *tmp_ctx = talloc_new(dgmsock);
73 0 : struct nbt_name myname;
74 0 : struct socket_address *dest;
75 :
76 45 : status = push_nbt_netlogon_response(&blob, tmp_ctx, reply);
77 45 : if (!NT_STATUS_IS_OK(status)) {
78 0 : return status;
79 : }
80 :
81 45 : make_nbt_name_client(&myname, my_netbios_name);
82 :
83 45 : dest = socket_address_from_strings(tmp_ctx, dgmsock->sock->backend_name,
84 45 : request->src_addr, request->src_port);
85 45 : if (!dest) {
86 0 : talloc_free(tmp_ctx);
87 0 : return NT_STATUS_NO_MEMORY;
88 : }
89 :
90 45 : status = dgram_mailslot_send(dgmsock, DGRAM_DIRECT_UNIQUE,
91 : mailslot_name,
92 : &request->data.msg.source_name,
93 : dest,
94 : &myname, &blob);
95 45 : talloc_free(tmp_ctx);
96 45 : return status;
97 : }
98 :
99 :
100 : /*
101 : parse a netlogon request. The packet must be a valid mailslot packet
102 : */
103 45 : NTSTATUS dgram_mailslot_netlogon_parse_request(TALLOC_CTX *mem_ctx,
104 : struct nbt_dgram_packet *dgram,
105 : struct nbt_netlogon_packet *netlogon)
106 : {
107 45 : DATA_BLOB data = dgram_mailslot_data(dgram);
108 0 : enum ndr_err_code ndr_err;
109 :
110 45 : ndr_err = ndr_pull_struct_blob(&data, mem_ctx, netlogon,
111 : (ndr_pull_flags_fn_t)ndr_pull_nbt_netlogon_packet);
112 45 : if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
113 0 : NTSTATUS status = ndr_map_error2ntstatus(ndr_err);
114 0 : DEBUG(0,("Failed to parse netlogon packet of length %d: %s\n",
115 : (int)data.length, nt_errstr(status)));
116 0 : if (DEBUGLVL(10)) {
117 0 : (void)file_save("netlogon.dat", data.data, data.length);
118 : }
119 0 : return status;
120 : }
121 45 : return NT_STATUS_OK;
122 : }
123 :
124 : /*
125 : parse a netlogon response. The packet must be a valid mailslot packet
126 : */
127 42 : NTSTATUS dgram_mailslot_netlogon_parse_response(TALLOC_CTX *mem_ctx,
128 : struct nbt_dgram_packet *dgram,
129 : struct nbt_netlogon_response *netlogon)
130 : {
131 0 : NTSTATUS status;
132 42 : DATA_BLOB data = dgram_mailslot_data(dgram);
133 :
134 42 : status = pull_nbt_netlogon_response(&data, mem_ctx, netlogon);
135 42 : if (!NT_STATUS_IS_OK(status)) {
136 0 : return status;
137 : }
138 :
139 42 : return NT_STATUS_OK;
140 : }
141 :
|