4 IDL structures for NBT operations
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
11 import
"misc.idl", "security.idl", "svcctl.idl";
13 helper
("libcli/nbt/libnbt.h")
17 const int NBT_NAME_SERVICE_PORT
= 137;
18 const int NBT_DGRAM_SERVICE_PORT
= 138;
20 typedef [bitmap16bit
] bitmap
{
22 NBT_FLAG_BROADCAST
= 0x0010,
23 NBT_FLAG_RECURSION_AVAIL
= 0x0080,
24 NBT_FLAG_RECURSION_DESIRED
= 0x0100,
25 NBT_FLAG_TRUNCATION
= 0x0200,
26 NBT_FLAG_AUTHORITIVE
= 0x0400,
28 NBT_FLAG_REPLY
= 0x8000
31 /* the opcodes are in the operation field, masked with
34 NBT_OPCODE_QUERY
= (0x0<<11),
35 NBT_OPCODE_REGISTER
= (0x5<<11),
36 NBT_OPCODE_RELEASE
= (0x6<<11),
37 NBT_OPCODE_WACK
= (0x7<<11),
38 NBT_OPCODE_REFRESH
= (0x8<<11),
39 NBT_OPCODE_REFRESH2
= (0x9<<11),
40 NBT_OPCODE_MULTI_HOME_REG
= (0xf<<11)
55 /* we support any 8bit name type, but by defining the common
56 ones here we get better debug displays */
57 typedef [enum8bit
] enum {
58 NBT_NAME_CLIENT
= 0x00,
61 NBT_NAME_SERVER
= 0x20,
63 NBT_NAME_LOGON
= 0x1C,
64 NBT_NAME_MASTER
= 0x1D,
65 NBT_NAME_BROWSER
= 0x1E
68 /* the ndr parser for nbt_name is separately defined in
69 nbtname.c (along with the parsers for nbt_string) */
70 typedef [public,nopull
,nopush
] struct {
76 typedef [enum16bit
] enum {
80 typedef [enum16bit
] enum {
81 NBT_QTYPE_ADDRESS
= 0x0001,
82 NBT_QTYPE_NAMESERVICE
= 0x0002,
83 NBT_QTYPE_NULL
= 0x000A,
84 NBT_QTYPE_NETBIOS
= 0x0020,
85 NBT_QTYPE_STATUS
= 0x0021
90 nbt_qtype question_type
;
91 nbt_qclass question_class
;
94 /* these are the possible values of the NBT_NM_OWNER_TYPE
103 typedef [bitmap16bit
] bitmap
{
104 NBT_NM_PERMANENT
= 0x0200,
105 NBT_NM_ACTIVE
= 0x0400,
106 NBT_NM_CONFLICT
= 0x0800,
107 NBT_NM_DEREGISTER
= 0x1000,
108 NBT_NM_OWNER_TYPE
= 0x6000,
109 NBT_NM_GROUP
= 0x8000
119 nbt_rdata_address addresses
[length
/6];
126 uint16 version_number
;
127 uint16 period_of_statistics
;
128 uint16 number_of_crcs
;
129 uint16 number_alignment_errors
;
130 uint16 number_of_collisions
;
131 uint16 number_send_aborts
;
132 uint32 number_good_sends
;
133 uint32 number_good_receives
;
134 uint16 number_retransmits
;
135 uint16 number_no_resource_conditions
;
136 uint16 number_free_command_blocks
;
137 uint16 total_number_command_blocks
;
138 uint16 max_total_number_command_blocks
;
139 uint16 number_pending_sessions
;
140 uint16 max_number_pending_sessions
;
141 uint16 max_total_sessions_possible
;
142 uint16 session_data_packet_size
;
146 [charset
(DOS
)] uint8 name
[15];
152 [value
(num_names
* 18 + 47)] uint16 length
;
154 nbt_status_name names
[num_names
];
155 nbt_statistics statistics
;
163 typedef [nodiscriminant
] union {
164 [case(NBT_QTYPE_NETBIOS
)] nbt_rdata_netbios netbios
;
165 [case(NBT_QTYPE_STATUS
)] nbt_rdata_status status
;
166 [default] nbt_rdata_data data
;
170 * this macro works arround the problem
171 * that we need to use nbt_rdata_data
172 * together with NBT_QTYPE_NETBIOS
175 #define NBT_RES_REC_LEVEL
(rr_type
, rdata
) (\
176 (((rr_type
) == NBT_QTYPE_NETBIOS
) && \
177 talloc_check_name
(ndr
, "struct ndr_push") && \
178 ((rdata
).data.length
== 2)) \
181 typedef [flag
(LIBNDR_PRINT_ARRAY_HEX
)] struct {
186 [switch_is(NBT_RES_REC_LEVEL
(rr_type
, rdata
))] nbt_rdata rdata
;
189 typedef [flag
(NDR_NOALIGN|NDR_BIG_ENDIAN|NDR_PAHEX
),public] struct {
191 nbt_operation operation
;
196 nbt_name_question questions
[qdcount
];
197 nbt_res_rec answers
[ancount
];
198 nbt_res_rec nsrecs
[nscount
];
199 nbt_res_rec additional
[arcount
];
200 [flag
(NDR_REMAINING
)] DATA_BLOB padding
;
205 NBT DGRAM packets (UDP/138)
208 typedef [enum8bit
] enum {
209 DGRAM_DIRECT_UNIQUE
= 0x10,
210 DGRAM_DIRECT_GROUP
= 0x11,
214 DGRAM_QUERY_POSITIVE
= 0x15,
215 DGRAM_QUERY_NEGATIVE
= 0x16
218 typedef [bitmap8bit
] bitmap
{
219 DGRAM_FLAG_MORE
= 0x01,
220 DGRAM_FLAG_FIRST
= 0x02,
221 DGRAM_FLAG_NODE_TYPE
= 0x0C
224 typedef [enum8bit
] enum {
228 DGRAM_NODE_NBDD
= 0x0C
231 /* a dgram_message is the main dgram body in general use */
233 /* the most common datagram type is a SMB_TRANSACTION
234 operation, where a SMB packet is used in the data section
235 of a dgram_message to hold a trans request, which in turn
236 holds a small command structure. It's a very strange beast
237 indeed. To make the code cleaner we define a basic SMB
238 packet in IDL here. This is not a general purpose SMB
239 packet, and won't be used in the core SMB client/server
240 code, but it does make working with these types of dgrams
243 const string NBT_MAILSLOT_NETLOGON
= "\\MAILSLOT\\NET\\NETLOGON";
244 const string NBT_MAILSLOT_NTLOGON
= "\\MAILSLOT\\NET\\NTLOGON";
245 const string NBT_MAILSLOT_GETDC
= "\\MAILSLOT\\NET\\GETDC";
246 const string NBT_MAILSLOT_BROWSE
= "\\MAILSLOT\\BROWSE";
248 typedef [enum8bit
] enum {
249 SMB_TRANSACTION
= 0x25
253 [range(17,17),value
(17)] uint8 wct
;
254 uint16 total_param_count
;
255 uint16 total_data_count
;
256 uint16 max_param_count
;
257 uint16 max_data_count
;
258 uint8 max_setup_count
;
267 [range(3,3),value
(3)] uint8 setup_count
;
272 [value
(strlen
(mailslot_name
)+1+data.length
)]
274 astring mailslot_name
;
275 [flag
(NDR_REMAINING
)] DATA_BLOB data
;
278 typedef [nodiscriminant
] union {
279 [case(SMB_TRANSACTION
)] smb_trans_body trans
;
283 typedef [flag
(NDR_NOALIGN|NDR_LITTLE_ENDIAN|NDR_PAHEX
),public] struct {
284 smb_command smb_command
;
297 [switch_is(smb_command
)] smb_body body
;
300 const uint32 DGRAM_SMB
= 0xff534d42; /* 0xffSMB */
302 typedef [nodiscriminant
] union {
303 [case(DGRAM_SMB
)] dgram_smb_packet smb
;
304 } dgram_message_body
;
309 nbt_name source_name
;
311 uint32 dgram_body_type
;
312 [switch_is(dgram_body_type
)] dgram_message_body body
;
315 typedef [enum8bit
] enum {
316 DGRAM_ERROR_NAME_NOT_PRESENT
= 0x82,
317 DGRAM_ERROR_INVALID_SOURCE
= 0x83,
318 DGRAM_ERROR_INVALID_DEST
= 0x84
321 typedef [nodiscriminant
] union {
322 [case(DGRAM_DIRECT_UNIQUE
)] dgram_message msg
;
323 [case(DGRAM_DIRECT_GROUP
)] dgram_message msg
;
324 [case(DGRAM_BCAST
)] dgram_message msg
;
325 [case(DGRAM_ERROR
)] dgram_err_code error
;
326 [case(DGRAM_QUERY
)] nbt_name dest_name
;
327 [case(DGRAM_QUERY_POSITIVE
)] nbt_name dest_name
;
328 [case(DGRAM_QUERY_NEGATIVE
)] nbt_name dest_name
;
331 typedef [flag
(NDR_NOALIGN|NDR_BIG_ENDIAN|NDR_PAHEX
),public] struct {
332 dgram_msg_type msg_type
;
335 ipv4address src_addr
;
337 [switch_is(msg_type
)] dgram_data data
;
341 /*******************************************/
342 /* \MAILSLOT\NET\NETLOGON mailslot requests */
344 NETLOGON_QUERY_FOR_PDC
= 0x7,
345 NETLOGON_ANNOUNCE_UAS
= 0xa,
346 NETLOGON_RESPONSE_FROM_PDC
= 0xc,
347 NETLOGON_QUERY_FOR_PDC2
= 0x12,
348 NETLOGON_RESPONSE_FROM_PDC2
= 0x17,
349 NETLOGON_RESPONSE_FROM_PDC_USER
= 0x19
350 } nbt_netlogon_command
;
352 /* query for pdc request */
354 astring computer_name
;
355 astring mailslot_name
;
356 [flag
(NDR_ALIGN2
)] DATA_BLOB _pad
;
357 nstring unicode_name
;
361 } nbt_netlogon_query_for_pdc
;
363 /* query for pdc request - new style */
365 uint16 request_count
;
366 nstring computer_name
;
368 astring mailslot_name
;
373 } nbt_netlogon_query_for_pdc2
;
375 /* response from pdc */
378 [flag
(NDR_ALIGN2
)] DATA_BLOB _pad
;
379 nstring unicode_pdc_name
;
384 } nbt_netlogon_response_from_pdc
;
386 typedef [bitmap32bit
] bitmap
{
387 NBT_SERVER_PDC
= 0x00000001,
388 NBT_SERVER_GC
= 0x00000004,
389 NBT_SERVER_LDAP
= 0x00000008,
390 NBT_SERVER_DS
= 0x00000010,
391 NBT_SERVER_KDC
= 0x00000020,
392 NBT_SERVER_TIMESERV
= 0x00000040,
393 NBT_SERVER_CLOSEST
= 0x00000080,
394 NBT_SERVER_WRITABLE
= 0x00000100,
395 NBT_SERVER_GOOD_TIMESERV
= 0x00000200
398 /* response from pdc - type2 */
400 [flag
(NDR_ALIGN4
)] DATA_BLOB _pad
;
401 nbt_server_type server_type
;
404 nbt_string dns_domain
;
405 nbt_string pdc_dns_name
;
408 nbt_string user_name
;
409 nbt_string server_site
;
410 nbt_string client_site
;
413 [flag
(NDR_BIG_ENDIAN
)]
419 } nbt_netlogon_response_from_pdc2
;
421 typedef enum netr_SamDatabaseID netr_SamDatabaseID
;
423 /* announce change to UAS or SAM */
425 netr_SamDatabaseID db_index
;
430 /* used to announce SAM changes */
438 [flag
(NDR_ALIGN2
)] DATA_BLOB _pad
;
439 nstring unicode_pdc_name
;
440 nstring unicode_domain
;
442 nbt_db_change dbchange
[db_count
];
443 [value
(ndr_size_dom_sid0
(&sid
, ndr
->flags
))] uint32 sid_size
;
444 [subcontext
(0),subcontext_size
(sid_size
)] dom_sid0 sid
;
448 } nbt_netlogon_announce_uas
;
450 typedef [nodiscriminant
] union {
451 [case(NETLOGON_QUERY_FOR_PDC
)] nbt_netlogon_query_for_pdc pdc
;
452 [case(NETLOGON_QUERY_FOR_PDC2
)] nbt_netlogon_query_for_pdc2 pdc2
;
453 [case(NETLOGON_ANNOUNCE_UAS
)] nbt_netlogon_announce_uas uas
;
454 [case(NETLOGON_RESPONSE_FROM_PDC
)] nbt_netlogon_response_from_pdc response
;
455 [case(NETLOGON_RESPONSE_FROM_PDC2
)] nbt_netlogon_response_from_pdc2 response2
;
456 [case(NETLOGON_RESPONSE_FROM_PDC_USER
)] nbt_netlogon_response_from_pdc2 response2
;
457 } nbt_netlogon_request
;
459 typedef [flag
(NDR_NOALIGN
),public] struct {
460 nbt_netlogon_command command
;
461 [switch_is(command
)] nbt_netlogon_request req
;
462 } nbt_netlogon_packet
;
464 /*******************************************/
465 /* CLDAP netlogon response */
467 /* note that these structures are very similar to, but not
468 quite identical to, the netlogon structures above */
475 [value
(1)] uint32 nt_version
;
478 } nbt_cldap_netlogon_1
;
488 nbt_string dns_domain
;
489 nbt_string pdc_dns_name
;
491 nbt_server_type server_type
;
492 [value
(3)] uint32 nt_version
;
495 } nbt_cldap_netlogon_3
;
499 nbt_server_type server_type
;
502 nbt_string dns_domain
;
503 nbt_string pdc_dns_name
;
506 nbt_string user_name
;
507 nbt_string server_site
;
508 nbt_string client_site
;
509 [value
(5)] uint32 nt_version
;
512 } nbt_cldap_netlogon_5
;
516 nbt_server_type server_type
;
519 nbt_string dns_domain
;
520 nbt_string pdc_dns_name
;
523 nbt_string user_name
;
524 nbt_string server_site
;
525 nbt_string client_site
;
528 [flag
(NDR_BIG_ENDIAN
)]
531 [value
(13)] uint32 nt_version
;
534 } nbt_cldap_netlogon_13
;
536 typedef [flag
(NDR_NOALIGN
),public,nodiscriminant
] union {
537 [case(0)] nbt_cldap_netlogon_1 logon1
;
538 [case(1)] nbt_cldap_netlogon_1 logon1
;
539 [case(2)] nbt_cldap_netlogon_3 logon3
;
540 [case(3)] nbt_cldap_netlogon_3 logon3
;
541 [case(4)] nbt_cldap_netlogon_5 logon5
;
542 [case(5)] nbt_cldap_netlogon_5 logon5
;
543 [case(6)] nbt_cldap_netlogon_5 logon5
;
544 [case(7)] nbt_cldap_netlogon_5 logon5
;
545 [default] nbt_cldap_netlogon_13 logon13
;
546 } nbt_cldap_netlogon
;
548 /*******************************************/
549 /* \MAILSLOT\NET\NTLOGON mailslot requests */
551 NTLOGON_SAM_LOGON
= 0x12,
552 NTLOGON_SAM_LOGON_REPLY
= 0x13,
553 NTLOGON_SAM_LOGON_REPLY15
= 0x15
554 } nbt_ntlogon_command
;
557 uint16 request_count
;
558 nstring computer_name
;
560 astring mailslot_name
;
562 [value
(ndr_size_dom_sid0
(&sid
, ndr
->flags
))] uint32 sid_size
;
563 [subcontext
(0),subcontext_size
(sid_size
)] dom_sid0 sid
;
567 } nbt_ntlogon_sam_logon
;
576 } nbt_ntlogon_sam_logon_reply
;
578 typedef [nodiscriminant
] union {
579 [case(NTLOGON_SAM_LOGON
)] nbt_ntlogon_sam_logon logon
;
580 [case(NTLOGON_SAM_LOGON_REPLY
)] nbt_ntlogon_sam_logon_reply reply
;
581 [case(NTLOGON_SAM_LOGON_REPLY15
)] nbt_ntlogon_sam_logon_reply reply
;
582 } nbt_ntlogon_request
;
584 typedef [flag
(NDR_NOALIGN
),public] struct {
585 nbt_ntlogon_command command
;
586 [switch_is(command
)] nbt_ntlogon_request req
;
587 } nbt_ntlogon_packet
;
589 /********************************************************/
590 /* \MAILSLOT\BROWSE mailslot requests */
591 /* for details see http://ubiqx.org/cifs/Browsing.html */
592 /********************************************************/
593 typedef bitmap svcctl_ServerType svcctl_ServerType
;
595 typedef [enum8bit
] enum {
596 HostAnnouncement
= 1,
597 AnnouncementRequest
= 2,
599 GetBackupListReq
= 9,
600 GetBackupListResp
= 10,
602 DomainAnnouncement
= 12,
603 MasterAnnouncement
= 13,
604 ResetBrowserState
= 14,
605 LocalMasterAnnouncement
= 15
611 [charset
(DOS
)] uint8 ServerName
[16];
614 svcctl_ServerType ServerType
;
619 } nbt_browse_host_announcement
;
623 astring ResponseName
;
624 } nbt_browse_announcement_request
;
629 uint32 UpTime
; /* In milliseconds */
630 uint32 Reserved
; /* Must be zero */
632 } nbt_browse_election_request
;
637 } nbt_browse_backup_list_request
;
642 nbt_name BackupServerList
[BackupCount
];/* TODO: this is wrong */
643 } nbt_browse_backup_list_response
;
647 } nbt_browse_become_backup
;
652 [charset
(DOS
)] uint8 ServerName
[16];
655 svcctl_ServerType ServerType
;
656 uint32 MysteriousField
;
658 } nbt_browse_domain_announcement
;
662 } nbt_browse_master_announcement
;
666 } nbt_browse_reset_state
;
671 [charset
(DOS
)] uint8 ServerName
[16];
674 svcctl_ServerType ServerType
;
679 } nbt_browse_local_master_announcement
;
681 typedef [nodiscriminant
] union {
682 [case(HostAnnouncement
)] nbt_browse_host_announcement host_annoucement
;
683 [case(AnnouncementRequest
)] nbt_browse_announcement_request announcement_request
;
684 [case(Election
)] nbt_browse_election_request election_request
;
685 [case(GetBackupListReq
)] nbt_browse_backup_list_request backup_list_request
;
686 [case(GetBackupListResp
)] nbt_browse_backup_list_response backup_list_response
;
687 [case(BecomeBackup
)] nbt_browse_become_backup become_backup
;
688 [case(DomainAnnouncement
)] nbt_browse_domain_announcement domain_announcement
;
689 [case(MasterAnnouncement
)] nbt_browse_master_announcement master_announcement
;
690 [case(ResetBrowserState
)] nbt_browse_reset_state reset_browser_state
;
691 [case(LocalMasterAnnouncement
)] nbt_browse_local_master_announcement local_master_announcement
;
692 } nbt_browse_payload
;
694 typedef [public,flag
(NDR_NOALIGN
)] struct {
695 nbt_browse_opcode opcode
;
696 [switch_is(opcode
)] nbt_browse_payload payload
;