r6320: some minor netlogon datagram fixes - NT4 can now join a Samba4 domain without
[samba.git] / source / librpc / idl / nbt.idl
1 #include "idl_types.h"
2
3 /*
4    IDL structures for NBT operations
5
6    NBT is not traditionally encoded using IDL/NDR. This is a bit of an
7    experiment, and I may well switch us back to a more traditional
8    encoding if it doesn't work out
9 */
10
11 [ uuid("1-2-3-4"),
12   version(1.0),
13   depends(security)
14 ] interface nbt
15 {
16         const int NBT_NAME_SERVICE_PORT  = 137;
17         const int NBT_DGRAM_SERVICE_PORT = 138;
18
19         typedef [bitmap16bit] bitmap {
20                 NBT_RCODE                   = 0x000F,
21                 NBT_FLAG_BROADCAST          = 0x0010,
22                 NBT_FLAG_RECURSION_AVAIL    = 0x0080,
23                 NBT_FLAG_RECURSION_DESIRED  = 0x0100,
24                 NBT_FLAG_TRUNCATION         = 0x0200,
25                 NBT_FLAG_AUTHORITIVE        = 0x0400,
26                 NBT_OPCODE                  = 0x7800,
27                 NBT_FLAG_REPLY              = 0x8000
28         } nbt_operation;
29
30         /* the opcodes are in the operation field, masked with
31            NBT_OPCODE */
32         typedef enum {
33                 NBT_OPCODE_QUERY          =  (0x0<<11),
34                 NBT_OPCODE_REGISTER       =  (0x5<<11),
35                 NBT_OPCODE_RELEASE        =  (0x6<<11),
36                 NBT_OPCODE_WACK           =  (0x7<<11),
37                 NBT_OPCODE_REFRESH        =  (0x8<<11),
38                 NBT_OPCODE_REFRESH2       =  (0x9<<11),
39                 NBT_OPCODE_MULTI_HOME_REG =  (0xf<<11)
40         } nbt_opcode;
41
42         /* rcode values */
43         typedef enum {
44                 NBT_RCODE_OK  = 0x0,
45                 NBT_RCODE_FMT = 0x1,
46                 NBT_RCODE_SVR = 0x2,
47                 NBT_RCODE_NAM = 0x3,
48                 NBT_RCODE_IMP = 0x4,
49                 NBT_RCODE_RFS = 0x5,
50                 NBT_RCODE_ACT = 0x6,
51                 NBT_RCODE_CFT = 0x7
52         } nbt_rcode;
53
54         /* we support any 8bit name type, but by defining the common
55            ones here we get better debug displays */
56         typedef [enum8bit] enum {
57                 NBT_NAME_CLIENT   = 0x00,
58                 NBT_NAME_MS       = 0x01,
59                 NBT_NAME_USER     = 0x03,
60                 NBT_NAME_SERVER   = 0x20,
61                 NBT_NAME_PDC      = 0x1B,
62                 NBT_NAME_LOGON    = 0x1C,
63                 NBT_NAME_MASTER   = 0x1D,
64                 NBT_NAME_BROWSER  = 0x1E
65         } nbt_name_type;
66
67         /* the ndr parser for nbt_name is separately defined in
68            nbtname.c */
69         typedef [nopull,nopush] struct {
70                 string        name;
71                 string        scope;
72                 nbt_name_type type;
73         } nbt_name;
74
75         typedef [enum16bit] enum {
76                 NBT_QCLASS_IP = 0x01
77         } nbt_qclass;
78
79         typedef [enum16bit] enum {
80                 NBT_QTYPE_ADDRESS     = 0x0001,
81                 NBT_QTYPE_NAMESERVICE = 0x0002,
82                 NBT_QTYPE_NULL        = 0x000A,
83                 NBT_QTYPE_NETBIOS     = 0x0020,
84                 NBT_QTYPE_STATUS      = 0x0021
85         } nbt_qtype;
86
87         typedef struct {
88                 nbt_name   name;
89                 nbt_qtype  question_type;
90                 nbt_qclass question_class;
91         } nbt_name_question;
92
93         /* these are the possible values of the NBT_NM_OWNER_TYPE
94            field */
95         typedef enum {
96                 NBT_NODE_B = 0x0000,
97                 NBT_NODE_P = 0x2000,
98                 NBT_NODE_M = 0x4000,
99                 NBT_NODE_H = 0x6000
100         } nbt_node_type;
101
102         typedef [bitmap16bit] bitmap {
103                 NBT_NM_PERMANENT        = 0x0200,
104                 NBT_NM_ACTIVE           = 0x0400,
105                 NBT_NM_CONFLICT         = 0x0800,
106                 NBT_NM_DEREGISTER       = 0x1000,
107                 NBT_NM_OWNER_TYPE       = 0x6000,
108                 NBT_NM_GROUP            = 0x8000
109         } nb_flags;
110
111         typedef struct {
112                 nb_flags nb_flags;
113                 ipv4address ipaddr;
114         } nbt_rdata_address;
115
116         typedef struct {
117                 uint16 length;
118                 nbt_rdata_address addresses[length/6];
119         } nbt_rdata_netbios;
120
121         typedef struct {
122                 uint8 unit_id[6];
123                 uint8 jumpers;
124                 uint8 test_result;
125                 uint16 version_number;
126                 uint16 period_of_statistics;
127                 uint16 number_of_crcs;
128                 uint16 number_alignment_errors;
129                 uint16 number_of_collisions;
130                 uint16 number_send_aborts;
131                 uint32 number_good_sends;
132                 uint32 number_good_receives;
133                 uint16 number_retransmits;
134                 uint16 number_no_resource_conditions;
135                 uint16 number_free_command_blocks;
136                 uint16 total_number_command_blocks;
137                 uint16 max_total_number_command_blocks;
138                 uint16 number_pending_sessions;
139                 uint16 max_number_pending_sessions;
140                 uint16 max_total_sessions_possible;
141                 uint16 session_data_packet_size;
142         } nbt_statistics;
143
144         typedef struct {
145                 astring15 name;
146                 nbt_name_type type;
147                 nb_flags  nb_flags;
148         } nbt_status_name;
149
150         typedef struct {
151                 [value(r->num_names * 18 + 47)] uint16 length;
152                 uint8 num_names;
153                 nbt_status_name names[num_names];
154                 nbt_statistics  statistics;
155         } nbt_rdata_status;
156
157         typedef struct {
158                 uint16 length;
159                 uint8  data[length];
160         } nbt_rdata_data;
161
162         typedef [nodiscriminant] union {
163                 [case(NBT_QTYPE_NETBIOS)] nbt_rdata_netbios netbios;
164                 [case(NBT_QTYPE_STATUS)]  nbt_rdata_status status;
165                 [default]                 nbt_rdata_data   data;
166         } nbt_rdata;
167
168         typedef [flag(LIBNDR_PRINT_ARRAY_HEX)] struct {
169                 nbt_name   name;
170                 nbt_qtype  rr_type;
171                 nbt_qclass rr_class;
172                 uint32     ttl;
173                 [switch_is(rr_type)] nbt_rdata rdata;
174         } nbt_res_rec;
175
176         typedef [flag(NDR_NOALIGN|NDR_BIG_ENDIAN|NDR_PAHEX),public] struct {
177                 uint16            name_trn_id;
178                 nbt_operation     operation;
179                 uint16            qdcount;
180                 uint16            ancount;
181                 uint16            nscount;
182                 uint16            arcount;
183                 nbt_name_question questions[qdcount];
184                 nbt_res_rec       answers[ancount];
185                 nbt_res_rec       nsrecs[nscount];
186                 nbt_res_rec       additional[arcount];
187                 [flag(NDR_REMAINING)] DATA_BLOB padding;
188         } nbt_name_packet;
189
190
191         /*
192           NBT DGRAM packets (UDP/138)
193         */
194
195         typedef [enum8bit] enum {
196                 DGRAM_DIRECT_UNIQUE  = 0x10,
197                 DGRAM_DIRECT_GROUP   = 0x11,
198                 DGRAM_BCAST          = 0x12,
199                 DGRAM_ERROR          = 0x13,
200                 DGRAM_QUERY          = 0x14,
201                 DGRAM_QUERY_POSITIVE = 0x15,
202                 DGRAM_QUERY_NEGATIVE = 0x16
203         } dgram_msg_type;
204
205         typedef [bitmap8bit] bitmap {
206                 DGRAM_FLAG_MORE         = 0x01,
207                 DGRAM_FLAG_FIRST        = 0x02,
208                 DGRAM_FLAG_NODE_TYPE    = 0x0C
209         } dgram_flags;
210
211         typedef [enum8bit] enum {
212                 DGRAM_NODE_B    = 0x00,
213                 DGRAM_NODE_P    = 0x04,
214                 DGRAM_NODE_M    = 0x08,
215                 DGRAM_NODE_NBDD = 0x0C
216         } dgram_node_type;
217
218         /* a dgram_message is the main dgram body in general use */
219
220         /* the most common datagram type is a SMB_TRANSACTION
221            operation, where a SMB packet is used in the data section
222            of a dgram_message to hold a trans request, which in turn
223            holds a small command structure. It's a very strange beast
224            indeed. To make the code cleaner we define a basic SMB
225            packet in IDL here. This is not a general purpose SMB
226            packet, and won't be used in the core SMB client/server
227            code, but it does make working with these types of dgrams
228            easier */
229
230         const string NBT_MAILSLOT_NETLOGON = "\\MAILSLOT\\NET\\NETLOGON";
231         const string NBT_MAILSLOT_GETDC    = "\\MAILSLOT\\GETDC";
232         const string NBT_MAILSLOT_BROWSE   = "\\MAILSLOT\\BROWSE";
233
234         typedef [enum8bit] enum {
235                 SMB_TRANSACTION = 0x25
236         } smb_command;
237
238         typedef struct {
239                 [range(17,17),value(17)] uint8 wct;
240                 uint16                      total_param_count;
241                 uint16                      total_data_count;
242                 uint16                      max_param_count;
243                 uint16                      max_data_count;
244                 uint8                       max_setup_count;
245                 uint8                       pad;
246                 uint16                      trans_flags;
247                 uint32                      timeout;
248                 uint16                      reserved;
249                 uint16                      param_count;
250                 uint16                      param_offset;
251                 uint16                      data_count;
252                 uint16                      data_offset;
253                 [range(3,3),value(3)] uint8 setup_count;
254                 uint8                       pad2;
255                 uint16                      opcode;
256                 uint16                      priority;
257                 uint16                      class;
258                 [value(strlen(r->mailslot_name)+1+r->data.length)] 
259                       uint16                byte_count;
260                 astring                     mailslot_name;
261                 [flag(NDR_REMAINING)] DATA_BLOB data;
262         } smb_trans_body;
263
264         typedef [nodiscriminant] union {
265                 [case(SMB_TRANSACTION)] smb_trans_body trans;
266         } smb_body;
267
268
269         typedef [flag(NDR_NOALIGN|NDR_LITTLE_ENDIAN|NDR_PAHEX),public] struct {
270                 smb_command                smb_command;
271                 uint8                      err_class;
272                 uint8                      pad;
273                 uint16                     err_code;
274                 uint8                      flags;
275                 uint16                     flags2;
276                 uint16                     pid_high;
277                 uint8                      signature[8];
278                 uint16                     reserved;
279                 uint16                     tid;
280                 uint16                     pid;
281                 uint16                     vuid;
282                 uint16                     mid;
283                 [switch_is(smb_command)]   smb_body body;
284         } dgram_smb_packet;
285
286         typedef [v1_enum] enum {
287                 DGRAM_SMB = 0xff534d42 /* 0xffSMB */
288         } dgram_body_type;
289
290         typedef [nodiscriminant] union {
291                 [case(DGRAM_SMB)] dgram_smb_packet smb;
292         } dgram_message_body;
293
294         typedef struct {
295                 uint16          length;
296                 uint16          offset;
297                 nbt_name        source_name;
298                 nbt_name        dest_name;
299                 dgram_body_type dgram_body_type;
300                 [switch_is(dgram_body_type)] dgram_message_body body;
301         } dgram_message;
302
303         typedef [enum8bit] enum {
304                 DGRAM_ERROR_NAME_NOT_PRESENT = 0x82,
305                 DGRAM_ERROR_INVALID_SOURCE   = 0x83,
306                 DGRAM_ERROR_INVALID_DEST     = 0x84
307         } dgram_err_code;
308
309         typedef [nodiscriminant] union {
310                 [case(DGRAM_DIRECT_UNIQUE)]   dgram_message  msg;
311                 [case(DGRAM_DIRECT_GROUP)]    dgram_message  msg;
312                 [case(DGRAM_BCAST)]           dgram_message  msg;
313                 [case(DGRAM_ERROR)]           dgram_err_code error;
314                 [case(DGRAM_QUERY)]           nbt_name       dest_name;
315                 [case(DGRAM_QUERY_POSITIVE)]  nbt_name       dest_name;
316                 [case(DGRAM_QUERY_NEGATIVE)]  nbt_name       dest_name;
317         } dgram_data;
318
319         typedef [flag(NDR_NOALIGN|NDR_BIG_ENDIAN|NDR_PAHEX),public] struct {
320                 dgram_msg_type msg_type;
321                 dgram_flags    flags;
322                 uint16         dgram_id;
323                 ipv4address    source;
324                 uint16         src_port;
325                 [switch_is(msg_type)] dgram_data data;
326         } nbt_dgram_packet;
327
328
329         /* \MAILSLOT\NET\NETLOGON mailslot requests */
330         typedef enum {
331                 NETLOGON_QUERY_FOR_PDC     = 0x7,       
332                 NETLOGON_ANNOUNCE_UAS      = 0xa,
333                 NETLOGON_RESPONSE_FROM_PDC = 0xc
334         } nbt_netlogon_command;
335
336         /* query for pdc request */
337         typedef struct {
338                 astring              computer_name;
339                 astring              mailslot_name;
340                 [flag(NDR_ALIGN2)]   DATA_BLOB _pad;
341                 nstring              unicode_name;
342                 uint32               nt_version;
343                 uint16               lmnt_token;
344                 uint16               lm20_token;
345         } nbt_netlogon_query_for_pdc;
346
347         /* response from request */
348         typedef struct {
349                 astring pdc_name;
350                 [flag(NDR_ALIGN2)]   DATA_BLOB _pad;
351                 nstring              unicode_pdc_name;
352                 nstring              domain_name;
353                 uint32               nt_version;
354                 uint16               lmnt_token;
355                 uint16               lm20_token;
356         } nbt_netlogon_response_from_pdc;
357
358         /* announce change to UAS or SAM */
359         typedef struct {
360                 uint32           db_index;
361                 hyper            serial;
362                 NTTIME           timestamp;
363         } nbt_db_change;
364
365         /* used to announce SAM changes */
366         typedef struct {
367                 uint32           serial_lo;
368                 time_t           timestamp;
369                 uint32           pulse;
370                 uint32           random;
371                 astring          pdc_name;
372                 astring          domain;
373                 [flag(NDR_ALIGN2)] DATA_BLOB _pad;
374                 nstring          unicode_pdc_name;
375                 nstring          unicode_domain;
376                 uint32           db_count;
377                 nbt_db_change    dbchange[db_count];
378                 [value(ndr_size_dom_sid(&r->sid))] uint32 sid_size;
379                 uint16           unknown;
380                 dom_sid          sid;
381                 uint32           nt_version;
382                 uint16           lmnt_token;
383                 uint16           lm20_token;
384         } nbt_netlogon_announce_uas;
385
386         typedef [nodiscriminant] union {
387                 [case(NETLOGON_QUERY_FOR_PDC)] nbt_netlogon_query_for_pdc pdc;
388                 [case(NETLOGON_ANNOUNCE_UAS)] nbt_netlogon_announce_uas uas;
389                 [case(NETLOGON_RESPONSE_FROM_PDC)] nbt_netlogon_response_from_pdc response;
390         } nbt_netlogon_request;
391
392         typedef [flag(NDR_NOALIGN),public] struct {
393                 nbt_netlogon_command command;
394                 [switch_is(command)] nbt_netlogon_request req;
395         } nbt_netlogon_packet;
396 }