r6321: added IDL and test suite for NBT dgram 'sam logon' request (sent by
[kai/samba.git] / source / libcli / dgram / libdgram.h
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 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 "librpc/gen_ndr/ndr_nbt.h"
24
25
26 /*
27   a nbt name request
28 */
29 struct nbt_dgram_request {
30         struct nbt_dgram_request *next, *prev;
31
32         /* where to send the request */
33         const char *dest_addr;
34         int dest_port;
35
36         /* the encoded request */
37         DATA_BLOB encoded;
38 };
39
40 /*
41   context structure for operations on dgram packets
42 */
43 struct nbt_dgram_socket {
44         struct socket_context *sock;
45         struct event_context *event_ctx;
46
47         /* the fd event */
48         struct fd_event *fde;
49
50         /* a queue of outgoing requests */
51         struct nbt_dgram_request *send_queue;
52
53         /* a list of mailslot handlers */
54         struct dgram_mailslot_handler *mailslot_handlers;
55
56         /* what to do with incoming request packets */
57         struct {
58                 void (*handler)(struct nbt_dgram_socket *, struct nbt_dgram_packet *, 
59                                 const char *, int );
60                 void *private;
61         } incoming;
62 };
63
64
65 /*
66   the mailslot code keeps a list of mailslot handlers. A mailslot
67   handler is a function that receives incoming packets for a specific
68   mailslot name. When a caller needs to send a mailslot and wants to
69   get a reply then it needs to register itself as listening for
70   incoming packets on the reply mailslot
71 */
72
73 typedef void (*dgram_mailslot_handler_t)(struct dgram_mailslot_handler *, 
74                                          struct nbt_dgram_packet *, 
75                                          const char *, int );
76
77 struct dgram_mailslot_handler {
78         struct dgram_mailslot_handler *next, *prev;
79
80         struct nbt_dgram_socket *dgmsock;
81         const char *mailslot_name;
82
83         dgram_mailslot_handler_t handler;
84         void *private;
85 };
86
87
88 /* prototypes */
89 NTSTATUS nbt_dgram_send(struct nbt_dgram_socket *dgmsock,
90                         struct nbt_dgram_packet *packet,
91                         const char *dest_addr,
92                         int dest_port);
93 NTSTATUS dgram_set_incoming_handler(struct nbt_dgram_socket *dgmsock,
94                                     void (*handler)(struct nbt_dgram_socket *, 
95                                                     struct nbt_dgram_packet *, 
96                                                     const char *, int ),
97                                     void *private);
98 struct nbt_dgram_socket *nbt_dgram_socket_init(TALLOC_CTX *mem_ctx, 
99                                                struct event_context *event_ctx);
100
101 const char *dgram_mailslot_name(struct nbt_dgram_packet *packet);
102 struct dgram_mailslot_handler *dgram_mailslot_find(struct nbt_dgram_socket *dgmsock,
103                                                    const char *mailslot_name);
104 struct dgram_mailslot_handler *dgram_mailslot_listen(struct nbt_dgram_socket *dgmsock,
105                                                      const char *mailslot_name,
106                                                      dgram_mailslot_handler_t handler,
107                                                      void *private);
108 struct dgram_mailslot_handler *dgram_mailslot_temp(struct nbt_dgram_socket *dgmsock,
109                                                    const char *mailslot_name,
110                                                    dgram_mailslot_handler_t handler,
111                                                    void *private);
112
113
114 NTSTATUS dgram_mailslot_send(struct nbt_dgram_socket *dgmsock,
115                              enum dgram_msg_type msg_type,
116                              const char *mailslot_name,
117                              struct nbt_name *dest_name,
118                              const char *dest_address,
119                              int dest_port,
120                              struct nbt_name *src_name,
121                              DATA_BLOB *request);
122
123 NTSTATUS dgram_mailslot_netlogon_send(struct nbt_dgram_socket *dgmsock,
124                                       struct nbt_name *dest_name,
125                                       const char *dest_address,
126                                       int dest_port,
127                                       struct nbt_name *src_name,
128                                       struct nbt_netlogon_packet *request);
129 NTSTATUS dgram_mailslot_netlogon_reply(struct nbt_dgram_socket *dgmsock,
130                                        struct nbt_dgram_packet *request,
131                                        const char *mailslot_name,
132                                        struct nbt_netlogon_packet *reply);
133 NTSTATUS dgram_mailslot_netlogon_parse(struct dgram_mailslot_handler *dgmslot,
134                                        TALLOC_CTX *mem_ctx,
135                                        struct nbt_dgram_packet *dgram,
136                                        struct nbt_netlogon_packet *netlogon);
137
138 NTSTATUS dgram_mailslot_ntlogon_send(struct nbt_dgram_socket *dgmsock,
139                                       struct nbt_name *dest_name,
140                                       const char *dest_address,
141                                       int dest_port,
142                                       struct nbt_name *src_name,
143                                       struct nbt_ntlogon_packet *request);
144 NTSTATUS dgram_mailslot_ntlogon_reply(struct nbt_dgram_socket *dgmsock,
145                                        struct nbt_dgram_packet *request,
146                                        const char *mailslot_name,
147                                        struct nbt_ntlogon_packet *reply);
148 NTSTATUS dgram_mailslot_ntlogon_parse(struct dgram_mailslot_handler *dgmslot,
149                                        TALLOC_CTX *mem_ctx,
150                                        struct nbt_dgram_packet *dgram,
151                                        struct nbt_ntlogon_packet *ntlogon);