Merge branch '2121_dir_symlink'
[kaloumi3.git] / lib / vfs / mc-vfs / samba / include / nameserv.h
blobc14c711baebcf3f4887fcacdb38fe036195db965
1 #ifndef _NAMESERV_H_
2 #define _NAMESERV_H_
3 /*
4 Unix SMB/Netbios implementation.
5 Version 1.9.
6 NBT netbios header - version 2
7 Copyright (C) Andrew Tridgell 1994-1998
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 #define PERMANENT_TTL 0
27 /* NTAS uses 2, NT uses 1, WfWg uses 0 */
28 #define MAINTAIN_LIST 2
29 #define ELECTION_VERSION 1
31 #define MAX_DGRAM_SIZE (576) /* tcp/ip datagram limit is 576 bytes */
32 #define MIN_DGRAM_SIZE 12
34 /*********************************************************
35 Types of reply packet.
36 **********************************************************/
38 enum netbios_reply_type_code { NMB_QUERY, NMB_STATUS, NMB_REG, NMB_REG_REFRESH,
39 NMB_REL, NMB_WAIT_ACK, NMB_MULTIHOMED_REG,
40 WINS_REG, WINS_QUERY };
42 /* From rfc1002, 4.2.1.2 */
43 /* Question types. */
44 #define QUESTION_TYPE_NB_QUERY 0x20
45 #define QUESTION_TYPE_NB_STATUS 0x21
47 /* Question class */
48 #define QUESTION_CLASS_IN 0x1
50 /* Opcode definitions */
51 #define NMB_NAME_QUERY_OPCODE 0x0
52 #define NMB_NAME_REG_OPCODE 0x05 /* see rfc1002.txt 4.2.2,3,5,6,7,8 */
53 #define NMB_NAME_RELEASE_OPCODE 0x06 /* see rfc1002.txt 4.2.9,10,11 */
54 #define NMB_WACK_OPCODE 0x07 /* see rfc1002.txt 4.2.16 */
55 /* Ambiguity in rfc1002 about which of these is correct. */
56 /* WinNT uses 8 by default but can be made to use 9. */
57 #define NMB_NAME_REFRESH_OPCODE_8 0x08 /* see rfc1002.txt 4.2.4 */
58 #define NMB_NAME_REFRESH_OPCODE_9 0x09 /* see rfc1002.txt 4.2.4 */
59 #define NMB_NAME_MULTIHOMED_REG_OPCODE 0x0F /* Invented by Microsoft. */
61 /* XXXX what about all the other types?? 0x1, 0x2, 0x3, 0x4, 0x8? */
63 /* Resource record types. rfc1002 4.2.1.3 */
64 #define RR_TYPE_A 0x1
65 #define RR_TYPE_NS 0x2
66 #define RR_TYPE_NULL 0xA
67 #define RR_TYPE_NB 0x20
68 #define RR_TYPE_NBSTAT 0x21
70 /* Resource record class. */
71 #define RR_CLASS_IN 0x1
73 /* NetBIOS flags */
74 #define NB_GROUP 0x80
75 #define NB_PERM 0x02
76 #define NB_ACTIVE 0x04
77 #define NB_CONFL 0x08
78 #define NB_DEREG 0x10
79 #define NB_BFLAG 0x00 /* Broadcast node type. */
80 #define NB_PFLAG 0x20 /* Point-to-point node type. */
81 #define NB_MFLAG 0x40 /* Mixed bcast & p-p node type. */
82 #define NB_HFLAG 0x60 /* Microsoft 'hybrid' node type. */
83 #define NB_NODETYPEMASK 0x60
84 /* Mask applied to outgoing NetBIOS flags. */
85 #define NB_FLGMSK 0xE0
87 /* NetBIOS flag identifier. */
88 #define NAME_GROUP(p) ((p)->data.nb_flags & NB_GROUP)
89 #define NAME_BFLAG(p) (((p)->data.nb_flags & NB_NODETYPEMASK) == NB_BFLAG)
90 #define NAME_PFLAG(p) (((p)->data.nb_flags & NB_NODETYPEMASK) == NB_PFLAG)
91 #define NAME_MFLAG(p) (((p)->data.nb_flags & NB_NODETYPEMASK) == NB_MFLAG)
92 #define NAME_HFLAG(p) (((p)->data.nb_flags & NB_NODETYPEMASK) == NB_HFLAG)
94 /* Samba name state for a name in a namelist. */
95 #define NAME_IS_ACTIVE(p) ((p)->data.nb_flags & NB_ACTIVE)
96 #define NAME_IN_CONFLICT(p) ((p)->data.nb_flags & NB_CONFL)
97 #define NAME_IS_DEREGISTERING(p) ((p)->data.nb_flags & NB_DEREG)
99 /* Error codes for NetBIOS requests. */
100 #define FMT_ERR 0x1 /* Packet format error. */
101 #define SRV_ERR 0x2 /* Internal server error. */
102 #define NAM_ERR 0x3 /* Name does not exist. */
103 #define IMP_ERR 0x4 /* Request not implemented. */
104 #define RFS_ERR 0x5 /* Request refused. */
105 #define ACT_ERR 0x6 /* Active error - name owned by another host. */
106 #define CFT_ERR 0x7 /* Name in conflict error. */
108 #define REFRESH_TIME (15*60)
109 #define NAME_POLL_REFRESH_TIME (5*60)
110 #define NAME_POLL_INTERVAL 15
112 /* Workgroup state identifiers. */
113 #define AM_POTENTIAL_MASTER_BROWSER(work) ((work)->mst_state == MST_POTENTIAL)
114 #define AM_LOCAL_MASTER_BROWSER(work) ((work)->mst_state == MST_BROWSER)
115 #define AM_DOMAIN_MASTER_BROWSER(work) ((work)->dom_state == DOMAIN_MST)
116 #define AM_DOMAIN_MEMBER(work) ((work)->log_state == LOGON_SRV)
118 /* Microsoft browser NetBIOS name. */
119 #define MSBROWSE "\001\002__MSBROWSE__\002"
121 /* Mail slots. */
122 #define BROWSE_MAILSLOT "\\MAILSLOT\\BROWSE"
123 #define NET_LOGON_MAILSLOT "\\MAILSLOT\\NET\\NETLOGON"
124 #define NT_LOGON_MAILSLOT "\\MAILSLOT\\NET\\NTLOGON"
125 #define LANMAN_MAILSLOT "\\MAILSLOT\\LANMAN"
127 /* Samba definitions for find_name_on_subnet(). */
128 #define FIND_ANY_NAME 0
129 #define FIND_SELF_NAME 1
132 * The different name types that can be in namelists.
134 * SELF_NAME should only be on the broadcast and unicast subnets.
135 * LMHOSTS_NAME should only be in the remote_broadcast_subnet.
136 * REGISTER_NAME, DNS_NAME, DNSFAIL_NAME should only be in the wins_server_subnet.
137 * WINS_PROXY_NAME should only be on the broadcast subnets.
138 * PERMANENT_NAME can be on all subnets except remote_broadcast_subnet.
142 enum name_source {LMHOSTS_NAME, REGISTER_NAME, SELF_NAME, DNS_NAME,
143 DNSFAIL_NAME, PERMANENT_NAME, WINS_PROXY_NAME};
144 enum node_type {B_NODE=0, P_NODE=1, M_NODE=2, NBDD_NODE=3};
145 enum packet_type {NMB_PACKET, DGRAM_PACKET};
147 enum master_state
149 MST_NONE,
150 MST_POTENTIAL,
151 MST_BACKUP,
152 MST_MSB,
153 MST_BROWSER,
154 MST_UNBECOMING_MASTER
157 enum domain_state
159 DOMAIN_NONE,
160 DOMAIN_WAIT,
161 DOMAIN_MST
164 enum logon_state
166 LOGON_NONE,
167 LOGON_WAIT,
168 LOGON_SRV
171 struct subnet_record;
173 struct nmb_data
175 uint16 nb_flags; /* Netbios flags. */
176 int num_ips; /* Number of ip entries. */
177 struct in_addr *ip; /* The ip list for this name. */
179 enum name_source source; /* Where the name came from. */
181 time_t death_time; /* The time the record must be removed (do not remove if 0). */
182 time_t refresh_time; /* The time the record should be refreshed. */
185 /* This is used to hold the list of servers in my domain, and is
186 contained within lists of domains. */
188 struct server_record
190 struct server_record *next;
191 struct server_record *prev;
193 struct subnet_record *subnet;
195 struct server_info_struct serv;
196 time_t death_time;
199 /* A workgroup structure. It contains a list of servers. */
200 struct work_record
202 struct work_record *next;
203 struct work_record *prev;
205 struct subnet_record *subnet;
207 struct server_record *serverlist;
209 /* Stage of development from non-local-master up to local-master browser. */
210 enum master_state mst_state;
212 /* Stage of development from non-domain-master to domain-master browser. */
213 enum domain_state dom_state;
215 /* Stage of development from non-logon-server to logon server. */
216 enum logon_state log_state;
218 /* Work group info. */
219 fstring work_group;
220 int token; /* Used when communicating with backup browsers. */
221 fstring local_master_browser_name; /* Current local master browser. */
223 /* Announce info. */
224 time_t lastannounce_time;
225 int announce_interval;
226 BOOL needannounce;
228 /* Timeout time for this workgroup. 0 means permanent. */
229 time_t death_time;
231 /* Election info */
232 BOOL RunningElection;
233 BOOL needelection;
234 int ElectionCount;
235 uint32 ElectionCriterion;
237 /* Domain master browser info. Used for efficient syncs. */
238 struct nmb_name dmb_name;
239 struct in_addr dmb_addr;
242 /* typedefs needed to define copy & free functions for userdata. */
243 struct userdata_struct;
245 typedef struct userdata_struct * (*userdata_copy_fn)(struct userdata_struct *);
246 typedef void (*userdata_free_fn)(struct userdata_struct *);
248 /* Structure to define any userdata passed around. */
250 struct userdata_struct {
251 userdata_copy_fn copy_fn;
252 userdata_free_fn free_fn;
253 unsigned int userdata_len;
254 char data[16]; /* 16 is to ensure alignment/padding on all systems */
257 struct response_record;
258 struct packet_struct;
259 struct res_rec;
261 /* typedef to define the function called when this response packet comes in. */
262 typedef void (*response_function)(struct subnet_record *, struct response_record *,
263 struct packet_struct *);
265 /* typedef to define the function called when this response record times out. */
266 typedef void (*timeout_response_function)(struct subnet_record *,
267 struct response_record *);
269 /* typedef to define the function called when the request that caused this
270 response record to be created is successful. */
271 typedef void (*success_function)(struct subnet_record *, struct userdata_struct *, ...);
273 /* typedef to define the function called when the request that caused this
274 response record to be created is unsuccessful. */
275 typedef void (*fail_function)(struct subnet_record *, struct response_record *, ...);
277 /* List of typedefs for success and fail functions of the different query
278 types. Used to catch any compile time prototype errors. */
280 typedef void (*register_name_success_function)( struct subnet_record *,
281 struct userdata_struct *,
282 struct nmb_name *,
283 uint16,
284 int,
285 struct in_addr);
286 typedef void (*register_name_fail_function)( struct subnet_record *,
287 struct response_record *,
288 struct nmb_name *);
290 typedef void (*release_name_success_function)( struct subnet_record *,
291 struct userdata_struct *,
292 struct nmb_name *,
293 struct in_addr);
294 typedef void (*release_name_fail_function)( struct subnet_record *,
295 struct response_record *,
296 struct nmb_name *);
298 typedef void (*refresh_name_success_function)( struct subnet_record *,
299 struct userdata_struct *,
300 struct nmb_name *,
301 uint16,
302 int,
303 struct in_addr);
304 typedef void (*refresh_name_fail_function)( struct subnet_record *,
305 struct response_record *,
306 struct nmb_name *);
308 typedef void (*query_name_success_function)( struct subnet_record *,
309 struct userdata_struct *,
310 struct nmb_name *,
311 struct in_addr,
312 struct res_rec *answers);
314 typedef void (*query_name_fail_function)( struct subnet_record *,
315 struct response_record *,
316 struct nmb_name *,
317 int);
319 typedef void (*node_status_success_function)( struct subnet_record *,
320 struct userdata_struct *,
321 struct res_rec *,
322 struct in_addr);
323 typedef void (*node_status_fail_function)( struct subnet_record *,
324 struct response_record *);
326 /* Initiated name queries are recorded in this list to track any responses. */
328 struct response_record
330 struct response_record *next;
331 struct response_record *prev;
333 uint16 response_id;
335 /* Callbacks for packets received or not. */
336 response_function resp_fn;
337 timeout_response_function timeout_fn;
339 /* Callbacks for the request succeeding or not. */
340 success_function success_fn;
341 fail_function fail_fn;
343 struct packet_struct *packet;
345 struct userdata_struct *userdata;
347 int num_msgs;
349 time_t repeat_time;
350 time_t repeat_interval;
351 int repeat_count;
353 /* Recursion protection. */
354 BOOL in_expiration_processing;
357 /* A subnet structure. It contains a list of workgroups and netbios names. */
360 B nodes will have their own, totally separate subnet record, with their
361 own netbios name set. These do NOT interact with other subnet records'
362 netbios names.
365 enum subnet_type {
366 NORMAL_SUBNET = 0, /* Subnet listed in interfaces list. */
367 UNICAST_SUBNET = 1, /* Subnet for unicast packets. */
368 REMOTE_BROADCAST_SUBNET = 2, /* Subnet for remote broadcasts. */
369 WINS_SERVER_SUBNET = 3 /* Only created if we are a WINS server. */
372 /* A resource record. */
373 struct res_rec {
374 struct nmb_name rr_name;
375 int rr_type;
376 int rr_class;
377 int ttl;
378 int rdlength;
379 char rdata[MAX_DGRAM_SIZE];
382 /* An nmb packet. */
383 struct nmb_packet
385 struct {
386 int name_trn_id;
387 int opcode;
388 BOOL response;
389 struct {
390 BOOL bcast;
391 BOOL recursion_available;
392 BOOL recursion_desired;
393 BOOL trunc;
394 BOOL authoritative;
395 } nm_flags;
396 int rcode;
397 int qdcount;
398 int ancount;
399 int nscount;
400 int arcount;
401 } header;
403 struct {
404 struct nmb_name question_name;
405 int question_type;
406 int question_class;
407 } question;
409 struct res_rec *answers;
410 struct res_rec *nsrecs;
411 struct res_rec *additional;
415 /* A datagram - this normally contains SMB data in the data[] array. */
417 struct dgram_packet {
418 struct {
419 int msg_type;
420 struct {
421 enum node_type node_type;
422 BOOL first;
423 BOOL more;
424 } flags;
425 int dgm_id;
426 struct in_addr source_ip;
427 int source_port;
428 int dgm_length;
429 int packet_offset;
430 } header;
431 struct nmb_name source_name;
432 struct nmb_name dest_name;
433 int datasize;
434 char data[MAX_DGRAM_SIZE];
437 /* Define a structure used to queue packets. This will be a linked
438 list of nmb packets. */
440 struct packet_struct
442 struct packet_struct *next;
443 struct packet_struct *prev;
444 BOOL locked;
445 struct in_addr ip;
446 int port;
447 int fd;
448 time_t timestamp;
449 enum packet_type packet_type;
450 union {
451 struct nmb_packet nmb;
452 struct dgram_packet dgram;
453 } packet;
456 /* NETLOGON opcodes */
458 #define QUERYFORPDC 7 /* Query for PDC. */
459 #define QUERYFORPDC_R 12 /* Response to Query for PDC. */
460 #define SAMLOGON 18
461 #define SAMLOGON_R 19
464 /* Ids for netbios packet types. */
466 #define ANN_HostAnnouncement 1
467 #define ANN_AnnouncementRequest 2
468 #define ANN_Election 8
469 #define ANN_GetBackupListReq 9
470 #define ANN_GetBackupListResp 10
471 #define ANN_BecomeBackup 11
472 #define ANN_DomainAnnouncement 12
473 #define ANN_MasterAnnouncement 13
474 #define ANN_ResetBrowserState 14
475 #define ANN_LocalMasterAnnouncement 15
478 /* Broadcast packet announcement intervals, in minutes. */
480 /* Attempt to add domain logon and domain master names. */
481 #define CHECK_TIME_ADD_DOM_NAMES 5
483 /* Search for master browsers of workgroups samba knows about,
484 except default. */
485 #define CHECK_TIME_MST_BROWSE 5
487 /* Request backup browser announcements from other servers. */
488 #define CHECK_TIME_ANNOUNCE_BACKUP 15
490 /* Request host announcements from other servers: min and max of interval. */
491 #define CHECK_TIME_MIN_HOST_ANNCE 3
492 #define CHECK_TIME_MAX_HOST_ANNCE 12
494 /* Announce as master to WINS server and any Primary Domain Controllers. */
495 #define CHECK_TIME_MST_ANNOUNCE 15
497 /* Time between syncs from domain master browser to local master browsers. */
498 #define CHECK_TIME_DMB_TO_LMB_SYNC 15
500 /* Do all remote announcements this often. */
501 #define REMOTE_ANNOUNCE_INTERVAL 180
503 /* what is the maximum period between name refreshes. Note that this only
504 affects non-permanent self names (in seconds) */
505 #define MAX_REFRESH_TIME (60*20)
507 /* Macro's to enumerate subnets either with or without
508 the UNICAST subnet. */
510 extern struct subnet_record *subnetlist;
511 extern struct subnet_record *unicast_subnet;
512 extern struct subnet_record *wins_server_subnet;
513 extern struct subnet_record *remote_broadcast_subnet;
515 #define FIRST_SUBNET subnetlist
516 #define NEXT_SUBNET_EXCLUDING_UNICAST(x) ((x)->next)
517 #define NEXT_SUBNET_INCLUDING_UNICAST(x) (get_next_subnet_maybe_unicast((x)))
519 /* To be removed. */
520 enum state_type { TEST };
521 #endif /* _NAMESERV_H_ */