| 1 | /*
|
|---|
| 2 | Unix SMB/CIFS implementation.
|
|---|
| 3 |
|
|---|
| 4 | a raw async NBT DGRAM library
|
|---|
| 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 "../libcli/netlogon.h"
|
|---|
| 23 |
|
|---|
| 24 | /*
|
|---|
| 25 | a datagram name request
|
|---|
| 26 | */
|
|---|
| 27 | struct nbt_dgram_request {
|
|---|
| 28 | struct nbt_dgram_request *next, *prev;
|
|---|
| 29 |
|
|---|
| 30 | /* where to send the request */
|
|---|
| 31 | struct socket_address *dest;
|
|---|
| 32 |
|
|---|
| 33 | /* the encoded request */
|
|---|
| 34 | DATA_BLOB encoded;
|
|---|
| 35 | };
|
|---|
| 36 |
|
|---|
| 37 | /*
|
|---|
| 38 | context structure for operations on dgram packets
|
|---|
| 39 | */
|
|---|
| 40 | struct nbt_dgram_socket {
|
|---|
| 41 | struct socket_context *sock;
|
|---|
| 42 | struct tevent_context *event_ctx;
|
|---|
| 43 | struct smb_iconv_convenience *iconv_convenience;
|
|---|
| 44 |
|
|---|
| 45 | /* the fd event */
|
|---|
| 46 | struct tevent_fd *fde;
|
|---|
| 47 |
|
|---|
| 48 | /* a queue of outgoing requests */
|
|---|
| 49 | struct nbt_dgram_request *send_queue;
|
|---|
| 50 |
|
|---|
| 51 | /* a list of mailslot handlers */
|
|---|
| 52 | struct dgram_mailslot_handler *mailslot_handlers;
|
|---|
| 53 |
|
|---|
| 54 | /* what to do with incoming request packets */
|
|---|
| 55 | struct {
|
|---|
| 56 | void (*handler)(struct nbt_dgram_socket *, struct nbt_dgram_packet *,
|
|---|
| 57 | struct socket_address *src);
|
|---|
| 58 | void *private_data;
|
|---|
| 59 | } incoming;
|
|---|
| 60 | };
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 | /*
|
|---|
| 64 | the mailslot code keeps a list of mailslot handlers. A mailslot
|
|---|
| 65 | handler is a function that receives incoming packets for a specific
|
|---|
| 66 | mailslot name. When a caller needs to send a mailslot and wants to
|
|---|
| 67 | get a reply then it needs to register itself as listening for
|
|---|
| 68 | incoming packets on the reply mailslot
|
|---|
| 69 | */
|
|---|
| 70 |
|
|---|
| 71 | typedef void (*dgram_mailslot_handler_t)(struct dgram_mailslot_handler *,
|
|---|
| 72 | struct nbt_dgram_packet *,
|
|---|
| 73 | struct socket_address *src);
|
|---|
| 74 |
|
|---|
| 75 | struct dgram_mailslot_handler {
|
|---|
| 76 | struct dgram_mailslot_handler *next, *prev;
|
|---|
| 77 |
|
|---|
| 78 | struct nbt_dgram_socket *dgmsock;
|
|---|
| 79 | const char *mailslot_name;
|
|---|
| 80 |
|
|---|
| 81 | dgram_mailslot_handler_t handler;
|
|---|
| 82 | void *private_data;
|
|---|
| 83 | };
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 | /* prototypes */
|
|---|
| 87 | NTSTATUS nbt_dgram_send(struct nbt_dgram_socket *dgmsock,
|
|---|
| 88 | struct nbt_dgram_packet *packet,
|
|---|
| 89 | struct socket_address *dest);
|
|---|
| 90 | NTSTATUS dgram_set_incoming_handler(struct nbt_dgram_socket *dgmsock,
|
|---|
| 91 | void (*handler)(struct nbt_dgram_socket *,
|
|---|
| 92 | struct nbt_dgram_packet *,
|
|---|
| 93 | struct socket_address *),
|
|---|
| 94 | void *private_data);
|
|---|
| 95 | struct nbt_dgram_socket *nbt_dgram_socket_init(TALLOC_CTX *mem_ctx,
|
|---|
| 96 | struct tevent_context *event_ctx,
|
|---|
| 97 | struct smb_iconv_convenience *);
|
|---|
| 98 |
|
|---|
| 99 | const char *dgram_mailslot_name(struct nbt_dgram_packet *packet);
|
|---|
| 100 | struct dgram_mailslot_handler *dgram_mailslot_find(struct nbt_dgram_socket *dgmsock,
|
|---|
| 101 | const char *mailslot_name);
|
|---|
| 102 | struct dgram_mailslot_handler *dgram_mailslot_listen(struct nbt_dgram_socket *dgmsock,
|
|---|
| 103 | const char *mailslot_name,
|
|---|
| 104 | dgram_mailslot_handler_t handler,
|
|---|
| 105 | void *private_data);
|
|---|
| 106 | struct dgram_mailslot_handler *dgram_mailslot_temp(struct nbt_dgram_socket *dgmsock,
|
|---|
| 107 | const char *mailslot_name,
|
|---|
| 108 | dgram_mailslot_handler_t handler,
|
|---|
| 109 | void *private_data);
|
|---|
| 110 | DATA_BLOB dgram_mailslot_data(struct nbt_dgram_packet *dgram);
|
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 | NTSTATUS dgram_mailslot_send(struct nbt_dgram_socket *dgmsock,
|
|---|
| 114 | enum dgram_msg_type msg_type,
|
|---|
| 115 | const char *mailslot_name,
|
|---|
| 116 | struct nbt_name *dest_name,
|
|---|
| 117 | struct socket_address *dest,
|
|---|
| 118 | struct nbt_name *src_name,
|
|---|
| 119 | DATA_BLOB *request);
|
|---|
| 120 |
|
|---|
| 121 | NTSTATUS dgram_mailslot_netlogon_send(struct nbt_dgram_socket *dgmsock,
|
|---|
| 122 | struct nbt_name *dest_name,
|
|---|
| 123 | struct socket_address *dest,
|
|---|
| 124 | const char *mailslot_name,
|
|---|
| 125 | struct nbt_name *src_name,
|
|---|
| 126 | struct nbt_netlogon_packet *request);
|
|---|
| 127 | NTSTATUS dgram_mailslot_netlogon_reply(struct nbt_dgram_socket *dgmsock,
|
|---|
| 128 | struct nbt_dgram_packet *request,
|
|---|
| 129 | const char *my_netbios_name,
|
|---|
| 130 | const char *mailslot_name,
|
|---|
| 131 | struct nbt_netlogon_response *reply);
|
|---|
| 132 | NTSTATUS dgram_mailslot_netlogon_parse_request(struct dgram_mailslot_handler *dgmslot,
|
|---|
| 133 | TALLOC_CTX *mem_ctx,
|
|---|
| 134 | struct nbt_dgram_packet *dgram,
|
|---|
| 135 | struct nbt_netlogon_packet *netlogon);
|
|---|
| 136 |
|
|---|
| 137 | NTSTATUS dgram_mailslot_netlogon_parse_response(struct dgram_mailslot_handler *dgmslot,
|
|---|
| 138 | TALLOC_CTX *mem_ctx,
|
|---|
| 139 | struct nbt_dgram_packet *dgram,
|
|---|
| 140 | struct nbt_netlogon_response *netlogon);
|
|---|
| 141 |
|
|---|
| 142 | NTSTATUS dgram_mailslot_browse_send(struct nbt_dgram_socket *dgmsock,
|
|---|
| 143 | struct nbt_name *dest_name,
|
|---|
| 144 | struct socket_address *dest,
|
|---|
| 145 | struct nbt_name *src_name,
|
|---|
| 146 | struct nbt_browse_packet *request);
|
|---|
| 147 |
|
|---|
| 148 | NTSTATUS dgram_mailslot_browse_reply(struct nbt_dgram_socket *dgmsock,
|
|---|
| 149 | struct nbt_dgram_packet *request,
|
|---|
| 150 | const char *mailslot_name,
|
|---|
| 151 | const char *my_netbios_name,
|
|---|
| 152 | struct nbt_browse_packet *reply);
|
|---|
| 153 |
|
|---|
| 154 | NTSTATUS dgram_mailslot_browse_parse(struct dgram_mailslot_handler *dgmslot,
|
|---|
| 155 | TALLOC_CTX *mem_ctx,
|
|---|
| 156 | struct nbt_dgram_packet *dgram,
|
|---|
| 157 | struct nbt_browse_packet *pkt);
|
|---|