00001 #ifndef _NAMESERV_H_
00002 #define _NAMESERV_H_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #define INFO_VERSION "INFO/version"
00025 #define INFO_COUNT "INFO/num_entries"
00026 #define INFO_ID_HIGH "INFO/id_high"
00027 #define INFO_ID_LOW "INFO/id_low"
00028 #define ENTRY_PREFIX "ENTRY/"
00029
00030 #define PERMANENT_TTL 0
00031
00032
00033 #define MAINTAIN_LIST 2
00034 #define ELECTION_VERSION 1
00035
00036 #define MAX_DGRAM_SIZE (576)
00037 #define MIN_DGRAM_SIZE 12
00038
00039
00040
00041
00042
00043 enum netbios_reply_type_code { NMB_QUERY, NMB_STATUS, NMB_REG, NMB_REG_REFRESH,
00044 NMB_REL, NMB_WAIT_ACK, NMB_MULTIHOMED_REG,
00045 WINS_REG, WINS_QUERY };
00046
00047
00048
00049 #define QUESTION_TYPE_NB_QUERY 0x20
00050 #define QUESTION_TYPE_NB_STATUS 0x21
00051
00052
00053 #define QUESTION_CLASS_IN 0x1
00054
00055
00056 #define NMB_NAME_QUERY_OPCODE 0x0
00057 #define NMB_NAME_REG_OPCODE 0x05
00058 #define NMB_NAME_RELEASE_OPCODE 0x06
00059 #define NMB_WACK_OPCODE 0x07
00060
00061
00062 #define NMB_NAME_REFRESH_OPCODE_8 0x08
00063 #define NMB_NAME_REFRESH_OPCODE_9 0x09
00064 #define NMB_NAME_MULTIHOMED_REG_OPCODE 0x0F
00065
00066
00067
00068
00069 #define RR_TYPE_A 0x1
00070 #define RR_TYPE_NS 0x2
00071 #define RR_TYPE_NULL 0xA
00072 #define RR_TYPE_NB 0x20
00073 #define RR_TYPE_NBSTAT 0x21
00074
00075
00076 #define RR_CLASS_IN 0x1
00077
00078
00079 #define NB_GROUP 0x80
00080 #define NB_PERM 0x02
00081 #define NB_ACTIVE 0x04
00082 #define NB_CONFL 0x08
00083 #define NB_DEREG 0x10
00084 #define NB_BFLAG 0x00
00085 #define NB_PFLAG 0x20
00086 #define NB_MFLAG 0x40
00087 #define NB_HFLAG 0x60
00088 #define NB_NODETYPEMASK 0x60
00089
00090 #define NB_FLGMSK 0xE0
00091
00092
00093 #define WINS_UNIQUE 0x00
00094 #define WINS_NGROUP 0x01
00095 #define WINS_SGROUP 0x02
00096 #define WINS_MHOMED 0x03
00097
00098 #define WINS_ACTIVE 0x00
00099 #define WINS_RELEASED 0x04
00100 #define WINS_TOMBSTONED 0x08
00101 #define WINS_DELETED 0x0C
00102
00103 #define WINS_STATE_MASK 0x0C
00104
00105 #define WINS_LOCAL 0x00
00106 #define WINS_REMOTE 0x10
00107
00108 #define WINS_BNODE 0x00
00109 #define WINS_PNODE 0x20
00110 #define WINS_MNODE 0x40
00111 #define WINS_HNODE 0x60
00112
00113 #define WINS_NONSTATIC 0x00
00114 #define WINS_STATIC 0x80
00115
00116 #define WINS_STATE_ACTIVE(p) (((p)->data.wins_flags & WINS_STATE_MASK) == WINS_ACTIVE)
00117
00118
00119
00120 #define NAME_GROUP(p) ((p)->data.nb_flags & NB_GROUP)
00121 #define NAME_BFLAG(p) (((p)->data.nb_flags & NB_NODETYPEMASK) == NB_BFLAG)
00122 #define NAME_PFLAG(p) (((p)->data.nb_flags & NB_NODETYPEMASK) == NB_PFLAG)
00123 #define NAME_MFLAG(p) (((p)->data.nb_flags & NB_NODETYPEMASK) == NB_MFLAG)
00124 #define NAME_HFLAG(p) (((p)->data.nb_flags & NB_NODETYPEMASK) == NB_HFLAG)
00125
00126
00127 #define NAME_IS_ACTIVE(p) ((p)->data.nb_flags & NB_ACTIVE)
00128 #define NAME_IN_CONFLICT(p) ((p)->data.nb_flags & NB_CONFL)
00129 #define NAME_IS_DEREGISTERING(p) ((p)->data.nb_flags & NB_DEREG)
00130
00131
00132 #define FMT_ERR 0x1
00133 #define SRV_ERR 0x2
00134 #define NAM_ERR 0x3
00135 #define IMP_ERR 0x4
00136 #define RFS_ERR 0x5
00137 #define ACT_ERR 0x6
00138 #define CFT_ERR 0x7
00139
00140 #define REFRESH_TIME (15*60)
00141 #define NAME_POLL_REFRESH_TIME (5*60)
00142 #define NAME_POLL_INTERVAL 15
00143
00144
00145 #define AM_POTENTIAL_MASTER_BROWSER(work) ((work)->mst_state == MST_POTENTIAL)
00146 #define AM_LOCAL_MASTER_BROWSER(work) ((work)->mst_state == MST_BROWSER)
00147 #define AM_DOMAIN_MASTER_BROWSER(work) ((work)->dom_state == DOMAIN_MST)
00148 #define AM_DOMAIN_MEMBER(work) ((work)->log_state == LOGON_SRV)
00149
00150
00151 #define MSBROWSE "\001\002__MSBROWSE__\002"
00152
00153
00154 #define BROWSE_MAILSLOT "\\MAILSLOT\\BROWSE"
00155 #define NET_LOGON_MAILSLOT "\\MAILSLOT\\NET\\NETLOGON"
00156 #define NT_LOGON_MAILSLOT "\\MAILSLOT\\NET\\NTLOGON"
00157 #define LANMAN_MAILSLOT "\\MAILSLOT\\LANMAN"
00158
00159
00160 #define FIND_ANY_NAME 0
00161 #define FIND_SELF_NAME 1
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174 enum name_source {LMHOSTS_NAME, REGISTER_NAME, SELF_NAME, DNS_NAME,
00175 DNSFAIL_NAME, PERMANENT_NAME, WINS_PROXY_NAME};
00176 enum node_type {B_NODE=0, P_NODE=1, M_NODE=2, NBDD_NODE=3};
00177 enum packet_type {NMB_PACKET, DGRAM_PACKET};
00178
00179 enum master_state {
00180 MST_NONE,
00181 MST_POTENTIAL,
00182 MST_BACKUP,
00183 MST_MSB,
00184 MST_BROWSER,
00185 MST_UNBECOMING_MASTER
00186 };
00187
00188 enum domain_state {
00189 DOMAIN_NONE,
00190 DOMAIN_WAIT,
00191 DOMAIN_MST
00192 };
00193
00194 enum logon_state {
00195 LOGON_NONE,
00196 LOGON_WAIT,
00197 LOGON_SRV
00198 };
00199
00200 struct subnet_record;
00201
00202 struct nmb_data {
00203 uint16 nb_flags;
00204 int num_ips;
00205 struct in_addr *ip;
00206
00207 enum name_source source;
00208
00209 time_t death_time;
00210 time_t refresh_time;
00211
00212 SMB_BIG_UINT id;
00213 struct in_addr wins_ip;
00214
00215 int wins_flags;
00216 };
00217
00218
00219 struct name_record {
00220 struct name_record *prev, *next;
00221 struct subnet_record *subnet;
00222 struct nmb_name name;
00223 struct nmb_data data;
00224 };
00225
00226
00227 struct browse_cache_record {
00228 struct browse_cache_record *prev, *next;
00229 unstring lmb_name;
00230 unstring work_group;
00231 struct in_addr ip;
00232 time_t sync_time;
00233 time_t death_time;
00234 };
00235
00236
00237
00238
00239 struct server_record {
00240 struct server_record *next;
00241 struct server_record *prev;
00242
00243 struct subnet_record *subnet;
00244
00245 struct server_info_struct serv;
00246 time_t death_time;
00247 };
00248
00249
00250 struct work_record {
00251 struct work_record *next;
00252 struct work_record *prev;
00253
00254 struct subnet_record *subnet;
00255
00256 struct server_record *serverlist;
00257
00258
00259 enum master_state mst_state;
00260
00261
00262 enum domain_state dom_state;
00263
00264
00265 enum logon_state log_state;
00266
00267
00268 unstring work_group;
00269 int token;
00270 unstring local_master_browser_name;
00271
00272
00273 time_t lastannounce_time;
00274 int announce_interval;
00275 BOOL needannounce;
00276
00277
00278 time_t death_time;
00279
00280
00281 BOOL RunningElection;
00282 BOOL needelection;
00283 int ElectionCount;
00284 uint32 ElectionCriterion;
00285
00286
00287 struct nmb_name dmb_name;
00288 struct in_addr dmb_addr;
00289 };
00290
00291
00292 struct userdata_struct;
00293
00294 typedef struct userdata_struct * (*userdata_copy_fn)(struct userdata_struct *);
00295 typedef void (*userdata_free_fn)(struct userdata_struct *);
00296
00297
00298
00299 struct userdata_struct {
00300 userdata_copy_fn copy_fn;
00301 userdata_free_fn free_fn;
00302 unsigned int userdata_len;
00303 char data[16];
00304 };
00305
00306 struct response_record;
00307 struct packet_struct;
00308 struct res_rec;
00309
00310
00311 typedef void (*response_function)(struct subnet_record *, struct response_record *,
00312 struct packet_struct *);
00313
00314
00315 typedef void (*timeout_response_function)(struct subnet_record *,
00316 struct response_record *);
00317
00318
00319
00320 typedef void (*success_function)(struct subnet_record *, struct userdata_struct *, ...);
00321
00322
00323
00324 typedef void (*fail_function)(struct subnet_record *, struct response_record *, ...);
00325
00326
00327
00328
00329 typedef void (*register_name_success_function)( struct subnet_record *,
00330 struct userdata_struct *,
00331 struct nmb_name *,
00332 uint16,
00333 int,
00334 struct in_addr);
00335 typedef void (*register_name_fail_function)( struct subnet_record *,
00336 struct response_record *,
00337 struct nmb_name *);
00338
00339 typedef void (*release_name_success_function)( struct subnet_record *,
00340 struct userdata_struct *,
00341 struct nmb_name *,
00342 struct in_addr);
00343 typedef void (*release_name_fail_function)( struct subnet_record *,
00344 struct response_record *,
00345 struct nmb_name *);
00346
00347 typedef void (*refresh_name_success_function)( struct subnet_record *,
00348 struct userdata_struct *,
00349 struct nmb_name *,
00350 uint16,
00351 int,
00352 struct in_addr);
00353 typedef void (*refresh_name_fail_function)( struct subnet_record *,
00354 struct response_record *,
00355 struct nmb_name *);
00356
00357 typedef void (*query_name_success_function)( struct subnet_record *,
00358 struct userdata_struct *,
00359 struct nmb_name *,
00360 struct in_addr,
00361 struct res_rec *answers);
00362
00363 typedef void (*query_name_fail_function)( struct subnet_record *,
00364 struct response_record *,
00365 struct nmb_name *,
00366 int);
00367
00368 typedef void (*node_status_success_function)( struct subnet_record *,
00369 struct userdata_struct *,
00370 struct res_rec *,
00371 struct in_addr);
00372 typedef void (*node_status_fail_function)( struct subnet_record *,
00373 struct response_record *);
00374
00375
00376
00377 struct response_record {
00378 struct response_record *next;
00379 struct response_record *prev;
00380
00381 uint16 response_id;
00382
00383
00384 response_function resp_fn;
00385 timeout_response_function timeout_fn;
00386
00387
00388 success_function success_fn;
00389 fail_function fail_fn;
00390
00391 struct packet_struct *packet;
00392
00393 struct userdata_struct *userdata;
00394
00395 int num_msgs;
00396
00397 time_t repeat_time;
00398 time_t repeat_interval;
00399 int repeat_count;
00400
00401
00402 BOOL in_expiration_processing;
00403 };
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413 enum subnet_type {
00414 NORMAL_SUBNET = 0,
00415 UNICAST_SUBNET = 1,
00416 REMOTE_BROADCAST_SUBNET = 2,
00417 WINS_SERVER_SUBNET = 3
00418 };
00419
00420 struct subnet_record {
00421 struct subnet_record *next;
00422 struct subnet_record *prev;
00423
00424 char *subnet_name;
00425 enum subnet_type type;
00426
00427 struct work_record *workgrouplist;
00428 struct name_record *namelist;
00429 struct response_record *responselist;
00430
00431 BOOL namelist_changed;
00432 BOOL work_changed;
00433
00434 struct in_addr bcast_ip;
00435 struct in_addr mask_ip;
00436 struct in_addr myip;
00437 int nmb_sock;
00438 int dgram_sock;
00439 };
00440
00441
00442 struct res_rec {
00443 struct nmb_name rr_name;
00444 int rr_type;
00445 int rr_class;
00446 int ttl;
00447 int rdlength;
00448 char rdata[MAX_DGRAM_SIZE];
00449 };
00450
00451
00452 #define NM_FLAGS_RS 0x80
00453 #define NM_FLAGS_AA 0x40
00454 #define NM_FLAGS_TC 0x20
00455 #define NM_FLAGS_RD 0x10
00456 #define NM_FLAGS_RA 0x08
00457 #define NM_FLAGS_B 0x01
00458
00459
00460 struct nmb_packet {
00461 struct {
00462 int name_trn_id;
00463 int opcode;
00464 BOOL response;
00465 struct {
00466 BOOL bcast;
00467 BOOL recursion_available;
00468 BOOL recursion_desired;
00469 BOOL trunc;
00470 BOOL authoritative;
00471 } nm_flags;
00472 int rcode;
00473 int qdcount;
00474 int ancount;
00475 int nscount;
00476 int arcount;
00477 } header;
00478
00479 struct {
00480 struct nmb_name question_name;
00481 int question_type;
00482 int question_class;
00483 } question;
00484
00485 struct res_rec *answers;
00486 struct res_rec *nsrecs;
00487 struct res_rec *additional;
00488 };
00489
00490
00491
00492 #define DGRAM_UNIQUE 0x10
00493 #define DGRAM_GROUP 0x11
00494 #define DGRAM_BROADCAST 0x12
00495 #define DGRAM_ERROR 0x13
00496 #define DGRAM_QUERY_REQUEST 0x14
00497 #define DGRAM_POSITIVE_QUERY_RESPONSE 0x15
00498 #define DGRAM_NEGATIVE_QUERT_RESPONSE 0x16
00499
00500
00501
00502 struct dgram_packet {
00503 struct {
00504 int msg_type;
00505 struct {
00506 enum node_type node_type;
00507 BOOL first;
00508 BOOL more;
00509 } flags;
00510 int dgm_id;
00511 struct in_addr source_ip;
00512 int source_port;
00513 int dgm_length;
00514 int packet_offset;
00515 } header;
00516 struct nmb_name source_name;
00517 struct nmb_name dest_name;
00518 int datasize;
00519 char data[MAX_DGRAM_SIZE];
00520 };
00521
00522
00523
00524
00525 struct packet_struct
00526 {
00527 struct packet_struct *next;
00528 struct packet_struct *prev;
00529 BOOL locked;
00530 struct in_addr ip;
00531 int port;
00532 int fd;
00533 time_t timestamp;
00534 enum packet_type packet_type;
00535 union {
00536 struct nmb_packet nmb;
00537 struct dgram_packet dgram;
00538 } packet;
00539 };
00540
00541
00542
00543 #define QUERYFORPDC 7
00544 #define SAM_UAS_CHANGE 10
00545 #define QUERYFORPDC_R 12
00546 #define SAMLOGON 18
00547 #define SAMLOGON_R 19
00548 #define SAMLOGON_UNK_R 21
00549 #define SAMLOGON_AD_UNK_R 23
00550 #define SAMLOGON_AD_R 25
00551
00552
00553
00554 #define ANN_HostAnnouncement 1
00555 #define ANN_AnnouncementRequest 2
00556 #define ANN_Election 8
00557 #define ANN_GetBackupListReq 9
00558 #define ANN_GetBackupListResp 10
00559 #define ANN_BecomeBackup 11
00560 #define ANN_DomainAnnouncement 12
00561 #define ANN_MasterAnnouncement 13
00562 #define ANN_ResetBrowserState 14
00563 #define ANN_LocalMasterAnnouncement 15
00564
00565
00566
00567
00568
00569 #define CHECK_TIME_ADD_DOM_NAMES 5
00570
00571
00572
00573 #define CHECK_TIME_MST_BROWSE 5
00574
00575
00576 #define CHECK_TIME_ANNOUNCE_BACKUP 15
00577
00578
00579 #define CHECK_TIME_MIN_HOST_ANNCE 3
00580 #define CHECK_TIME_MAX_HOST_ANNCE 12
00581
00582
00583 #define CHECK_TIME_MST_ANNOUNCE 15
00584
00585
00586 #define CHECK_TIME_DMB_TO_LMB_SYNC 15
00587
00588
00589 #define REMOTE_ANNOUNCE_INTERVAL 180
00590
00591
00592
00593 #define MAX_REFRESH_TIME (60*20)
00594
00595
00596 #define EXTINCTION_INTERVAL (4*24*60*60)
00597
00598
00599 #define EXTINCTION_TIMEOUT (24*60*60)
00600
00601
00602
00603
00604 extern struct subnet_record *subnetlist;
00605 extern struct subnet_record *unicast_subnet;
00606 extern struct subnet_record *wins_server_subnet;
00607 extern struct subnet_record *remote_broadcast_subnet;
00608
00609 #define FIRST_SUBNET subnetlist
00610 #define NEXT_SUBNET_EXCLUDING_UNICAST(x) ((x)->next)
00611 #define NEXT_SUBNET_INCLUDING_UNICAST(x) (get_next_subnet_maybe_unicast((x)))
00612
00613
00614 typedef struct _WINS_RECORD {
00615 char name[17];
00616 char type;
00617 int nb_flags;
00618 int wins_flags;
00619 SMB_BIG_UINT id;
00620 int num_ips;
00621 struct in_addr ip[25];
00622 struct in_addr wins_ip;
00623 } WINS_RECORD;
00624
00625
00626 enum state_type { TEST };
00627 #endif