use NULL instead of 0
[kai/samba.git] / source3 / include / nameserv.h
index 9e4145213b7cf6abdbcc867dedb989314e917188..1aa1075543f2b73f719681ecbb707d11c68b0978 100644 (file)
@@ -2,7 +2,7 @@
    Unix SMB/Netbios implementation.
    Version 1.9.
    NBT netbios header - version 2
-   Copyright (C) Andrew Tridgell 1994-1995
+   Copyright (C) Andrew Tridgell 1994-1997
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -20,6 +20,8 @@
    
 */
 
+#define GET_TTL(ttl) ((ttl)?MIN(ttl,lp_max_ttl()):lp_max_ttl())
+
 /* NTAS uses 2, NT uses 1, WfWg uses 0 */
 #define MAINTAIN_LIST    2
 #define ELECTION_VERSION 1
 #define NMB_REG         0x05 /* see rfc1002.txt 4.2.2,3,5,6,7,8 */
 #define NMB_REG_REFRESH 0x09 /* see rfc1002.txt 4.2.4 */
 #define NMB_REL         0x06 /* see rfc1002.txt 4.2.9,10,11 */
-#define NMB_WAIT_ACK    0x07 /* see rfc1002.txt 4.2.17 */
+#define NMB_WAIT_ACK    0x07 /* see rfc1002.txt 4.2.16 */
 /* XXXX what about all the other types?? 0x1, 0x2, 0x3, 0x4, 0x8? */
 
+#define FIND_SELF  0x01
+#define FIND_WINS  0x02
+#define FIND_LOCAL 0x04
+
 /* NetBIOS flags */
 #define NB_GROUP  0x80
 #define NB_PERM   0x02
 #define NB_ACTIVE 0x04
 #define NB_CONFL  0x08
 #define NB_DEREG  0x10
-#define NB_BFLAG  0x00
-#define NB_PFLAG  0x20
-#define NB_MFLAG  0x40
-#define NB__FLAG  0x60
+#define NB_BFLAG  0x00 /* broadcast node type */
+#define NB_PFLAG  0x20 /* point-to-point node type */
+#define NB_MFLAG  0x40 /* mixed bcast & p-p node type */
+#define NB_HFLAG  0x60 /* microsoft 'hybrid' node type */
 #define NB_FLGMSK 0x60
 
 #define REFRESH_TIME (15*60)
 #define NAME_BFLAG(p)     (((p) & NB_FLGMSK) == NB_BFLAG)
 #define NAME_PFLAG(p)     (((p) & NB_FLGMSK) == NB_PFLAG)
 #define NAME_MFLAG(p)     (((p) & NB_FLGMSK) == NB_MFLAG)
-#define NAME__FLAG(p)     (((p) & NB_FLGMSK) == NB__FLAG)
+#define NAME_HFLAG(p)     (((p) & NB_FLGMSK) == NB_HFLAG)
 
 /* server type identifiers */
 #define AM_MASTER(work) (work->ServerType & SV_TYPE_MASTER_BROWSER)
 #define AM_BACKUP(work) (work->ServerType & SV_TYPE_BACKUP_BROWSER)
-#define AM_DOMCTL(work) (work->ServerType & SV_TYPE_DOMAIN_CTRL)
+#define AM_DOMMST(work) (work->ServerType & SV_TYPE_DOMAIN_MASTER)
+#define AM_DOMMEM(work) (work->ServerType & SV_TYPE_DOMAIN_MEMBER)
 
 /* microsoft browser NetBIOS name */
 #define MSBROWSE "\001\002__MSBROWSE__\002"
 enum name_source {STATUS_QUERY, LMHOSTS, REGISTER, SELF, DNS, DNSFAIL};
 enum node_type {B_NODE=0, P_NODE=1, M_NODE=2, NBDD_NODE=3};
 enum packet_type {NMB_PACKET, DGRAM_PACKET};
+
+enum master_state
+{
+   MST_POTENTIAL,
+   MST_BACK,
+   MST_MSB,
+   MST_BROWSER
+};
+
+enum domain_state
+{
+   DOMAIN_NONE,
+   DOMAIN_WAIT,
+   DOMAIN_MST
+};
+
+enum logon_state
+{
+   LOGON_NONE,
+   LOGON_WAIT,
+   LOGON_SRV
+};
+
 enum state_type
 {
-       NAME_STATUS_MASTER_CHECK,
-       NAME_STATUS_CHECK,
+       NAME_STATUS_DOM_SRV_CHK,
+       NAME_STATUS_SRV_CHK,
+       NAME_REGISTER_CHALLENGE,
        NAME_REGISTER,
        NAME_RELEASE,
        NAME_QUERY_CONFIRM,
-       NAME_QUERY_SYNC,
-       NAME_QUERY_MST_SRV_CHK,
+       NAME_QUERY_ANNOUNCE_HOST,
+       NAME_QUERY_SYNC_LOCAL,
+       NAME_QUERY_SYNC_REMOTE,
+       NAME_QUERY_DOM_SRV_CHK,
        NAME_QUERY_SRV_CHK,
        NAME_QUERY_FIND_MST,
-       NAME_QUERY_MST_CHK
+       NAME_QUERY_MST_CHK,
+       NAME_QUERY_DOMAIN
 };
 
 /* a netbios name structure */
@@ -100,6 +134,14 @@ struct nmb_name {
   int name_type;
 };
 
+/* a netbios flags + ip address structure */
+/* this is used for multi-homed systems and for internet group names */
+struct nmb_ip
+{
+  struct in_addr ip; /* ip address of host that owns this name */
+  uint16 nb_flags;      /* netbios flags */
+};
+
 /* this is the structure used for the local netbios name list */
 struct name_record
 {
@@ -107,8 +149,8 @@ struct name_record
   struct name_record *prev;
 
   struct nmb_name name;    /* the netbios name */
-  struct in_addr ip;       /* ip address of host that owns this name */
-  int nb_flags;            /* netbios flags */
+  struct nmb_ip *ip_flgs;  /* the ip + flags */
+  int num_ips;             /* number of ip+flags entries */
 
   enum name_source source; /* where the name came from */
 
@@ -116,6 +158,8 @@ struct name_record
   time_t refresh_time; /* time record should be refreshed */
 };
 
+struct subnet_record;
+
 /* browse and backup server cache for synchronising browse list */
 struct browse_cache_record
 {
@@ -128,6 +172,8 @@ struct browse_cache_record
        struct in_addr ip;
        time_t sync_time;
        BOOL synced;
+       BOOL local;
+        struct subnet_record *subnet;
 };
 
 /* this is used to hold the list of servers in my domain, and is */
@@ -149,6 +195,15 @@ struct work_record
 
   struct server_record *serverlist;
 
+  /* stage of development from non-local-master up to local-master browser */
+  enum master_state mst_state;
+
+  /* stage of development from non-domain-master to domain master browser */
+  enum domain_state dom_state;
+
+  /* stage of development from non-logon-server to logon server */
+  enum logon_state log_state;
+
   /* work group info */
   fstring work_group;
   int     token;        /* used when communicating with backup browsers */
@@ -159,6 +214,7 @@ struct work_record
   int announce_interval;
   BOOL    needannounce;
 
+
   /* election info */
   BOOL    RunningElection;
   BOOL    needelection;
@@ -167,6 +223,8 @@ struct work_record
 };
 
 /* initiated name queries recorded in this list to track any responses... */
+/* sadly, we need to group everything together. i suppose that if this
+   gets unwieldy, then a union ought to be considered. oh for c++... */
 struct response_record
 {
   struct response_record *next;
@@ -181,9 +239,14 @@ struct response_record
   int nb_flags;
   time_t ttl;
 
+  int server_type;
+  fstring my_name;
+  fstring my_comment;
+
   BOOL bcast;
   BOOL recurse;
-  struct in_addr to_ip;
+  struct in_addr send_ip;
+  struct in_addr reply_to_ip;
 
   int num_msgs;
 
@@ -227,8 +290,6 @@ struct subnet_record
   struct in_addr bcast_ip;
   struct in_addr mask_ip;
   struct in_addr myip;
-
-  BOOL my_interface;
 };
 
 /* a resource record */
@@ -328,6 +389,9 @@ struct packet_struct
 
 /* broadcast packet announcement intervals, in minutes */
 
+/* attempt to add domain logon and domain master names */
+#define CHECK_TIME_ADD_DOM_NAMES 5 
+
 /* search for master browsers of workgroups samba knows about, 
    except default */
 #define CHECK_TIME_MST_BROWSE       5 
@@ -342,3 +406,23 @@ struct packet_struct
 /* announce as master to WINS server and any Primary Domain Controllers */
 #define CHECK_TIME_MST_ANNOUNCE    15
 
+/* do all remote announcements this often */
+#define REMOTE_ANNOUNCE_INTERVAL 180
+
+#define DFLT_SERVER_TYPE (SV_TYPE_WORKSTATION | SV_TYPE_SERVER | \
+                         SV_TYPE_TIME_SOURCE | SV_TYPE_SERVER_UNIX | \
+                         SV_TYPE_PRINTQ_SERVER | SV_TYPE_SERVER_NT | \
+                         SV_TYPE_NT )
+
+/* Macro's to enumerate subnets either with or without
+   the WINS subnet. */
+
+extern struct subnet_record *subnetlist;
+extern struct subnet_record *wins_subnet;
+
+#define FIRST_SUBNET subnetlist
+#define NEXT_SUBNET_EXCLUDING_WINS(x) ((x)->next)
+#define NEXT_SUBNET_INCLUDING_WINS(x) ( ((x) == wins_subnet) ? NULL : \
+                                        (((x)->next == NULL) ? wins_subnet : \
+                                         (x)->next))
+