/*The following definitions come from charset.c */
-void charset_initialise(void);
+void charset_initialise();
void codepage_initialise(int client_codepage);
void add_char_string(char *s);
/*The following definitions come from clitar.c */
+int strslashcmp(char *s1, char *s2);
int padit(char *buf, int bufsize, int padsize);
void cmd_block(void);
void cmd_tarmode(void);
BOOL dptr_zero(char *buf);
void *dptr_fetch(char *buf,int *num);
void *dptr_fetch_lanman2(char *params,int dptr_num);
-BOOL dir_check_ftype(int cnum, int mode,struct stat *st,int dirtype);
+BOOL dir_check_ftype(int cnum,int mode,struct stat *st,int dirtype);
BOOL get_dir_entry(int cnum,char *mask,int dirtype,char *fname,int *size,int *mode,time_t *date,BOOL check_descend);
void *OpenDir(int cnum, char *name, BOOL use_veto);
void CloseDir(void *p);
/*The following definitions come from nameserv.c */
-void remove_name_entry(struct subnet_record *d, char *name,int type, BOOL direct);
-void add_my_name_entry(struct subnet_record *d,char *name,int type,int nb_flags, BOOL direct);
+void remove_name_entry(struct subnet_record *d, char *name,int type);
+void add_my_name_entry(struct subnet_record *d,char *name,int type,int nb_flags);
+void add_domain_logon_names(void);
+void add_domain_master_bcast(void);
+void add_domain_master_wins(void);
void add_domain_names(time_t t);
void add_my_names(void);
void remove_my_names();
BOOL yield_connection(int cnum,char *name,int max_connections);
BOOL claim_connection(int cnum,char *name,int max_connections,BOOL Clear);
void exit_server(char *reason);
-void standard_sub(int cnum,char *s);
+void standard_sub(int cnum,char *string);
char *smb_fn_name(int type);
int chain_reply(char *inbuf,char *outbuf,int size,int bufsize);
int construct_reply(char *inbuf,char *outbuf,int size,int bufsize);
BOOL smb_shm_get_usage(int *bytes_free,
int *bytes_used,
int *bytes_overhead);
-smb_shm_offset_t smb_shm_alloc(int size);
-smb_shm_offset_t smb_shm_addr2offset(void *addr);
-smb_shm_offset_t smb_shm_get_userdef_off(void);
/*The following definitions come from smbencrypt.c */
int count_chars(char *s,char c);
void make_dir_struct(char *buf,char *mask,char *fname,unsigned int size,int mode,time_t date);
void close_low_fds(void);
-int set_blocking(int fd, int set);
+int set_blocking(int fd, BOOL set);
int write_socket(int fd,char *buf,int len);
int read_udp_socket(int fd,char *buf,int len);
int read_with_timeout(int fd,char *buf,int mincnt,int maxcnt,long time_out);
void reset_globals_after_fork();
char *client_name(void);
char *client_addr(void);
-void standard_sub_basic(char *s);
+void standard_sub_basic(char *string);
BOOL same_net(struct in_addr ip1,struct in_addr ip2,struct in_addr mask);
int PutUniCode(char *dst,char *src);
struct hostent *Get_Hostbyname(char *name);
0,lp_serverstring(),True);
/* add special browser name */
- add_my_name_entry(d,MSBROWSE,0x01,nb_type|NB_ACTIVE|NB_GROUP,False);
+ add_my_name_entry(d,MSBROWSE,0x01,nb_type|NB_ACTIVE|NB_GROUP);
/* DON'T do anything else after calling add_my_name_entry() */
break;
0,myname,True);
/* add master name */
- add_my_name_entry(d,work->work_group,0x1d,nb_type|NB_ACTIVE,False);
+ add_my_name_entry(d,work->work_group,0x1d,nb_type|NB_ACTIVE);
/* DON'T do anything else after calling add_my_name_entry() */
break;
******************************************************************/
void become_domain_master(struct subnet_record *d, struct work_record *work)
{
- /* domain type must be limited to domain enum + server type. it must
- not have SV_TYPE_SERVER or anything else with SERVER in it, else
- clients get confused and start thinking this entry is a server
- not a workgroup
- */
+ /* domain type must be limited to domain enum + server type. it must
+ not have SV_TYPE_SERVER or anything else with SERVER in it, else
+ clients get confused and start thinking this entry is a server
+ not a workgroup
+ */
- if (!work || !d) return;
-
- if (!lp_domain_master())
- {
- DEBUG(0,("Samba not configured as a domain master browser.\n"));
- return;
- }
+ if (!work || !d) return;
- DEBUG(2,("Becoming domain master for %s %s (currently at stage %d)\n",
+ if (!lp_domain_master())
+ {
+ DEBUG(0,("Samba not configured as a domain master browser.\n"));
+ return;
+ }
+
+ DEBUG(2,("Becoming domain master for %s %s (currently at stage %d)\n",
work->work_group,inet_ntoa(d->bcast_ip),work->dom_state));
-
- switch (work->dom_state)
- {
- case DOMAIN_NONE: /* while we were nothing but a server... */
- {
- DEBUG(3,("become_domain_master: go to first stage: register <1b> name\n"));
- work->dom_state = DOMAIN_WAIT;
-
- /* Registering the DOMAIN<1b> name is very tricky. We need to
- do this on all our subnets, but don't want to bradcast it
- on locally connected subnets (WinNT doesn't do this). Also,
- previous versions of Samba screw up royally when we do this.
- We need to register it immediatly on our local subnet, but
- also actually check with the WINS server if it exists. If the name
- has already been claimed by someone else in the WINS server
- then we need to back out all our local registrations and
- fail. Thus we only directly enter the name on local subnets,
- on the WINS subnet we actually check...
- */
- /* XXXX the 0x1b is domain master browser name */
- if(d == wins_subnet)
- add_my_name_entry(d, work->work_group,0x1b,nb_type|NB_ACTIVE,False);
- else
- add_my_name_entry(d, work->work_group,0x1b,nb_type|NB_ACTIVE,True);
- /* DON'T do anything else after calling add_my_name_entry() */
- break;
- }
+ switch (work->dom_state)
+ {
+ case DOMAIN_NONE: /* while we were nothing but a server... */
+ {
+ DEBUG(3,("become_domain_master: go to first stage: register <1b> name\n"));
+ work->dom_state = DOMAIN_WAIT;
+
+ /* Registering the DOMAIN<1b> name is very tricky. We need to
+ do this on all our subnets, but don't want to bradcast it
+ on locally connected subnets (WinNT doesn't do this). Also,
+ previous versions of Samba screw up royally when we do this.
+ We need to register it immediatly on our local subnet, but
+ also actually check with the WINS server if it exists. If the name
+ has already been claimed by someone else in the WINS server
+ then we need to back out all our local registrations and
+ fail. Thus we only directly enter the name on local subnets,
+ on the WINS subnet we actually check...
+ */
+ /* XXXX the 0x1b is domain master browser name */
+ add_my_name_entry(d, work->work_group,0x1b,nb_type|NB_ACTIVE);
+
+ /* DON'T do anything else after calling add_my_name_entry() */
+ break;
+ }
- case DOMAIN_WAIT:
- {
- work->dom_state = DOMAIN_MST; /* ... become domain master */
- DEBUG(3,("become_domain_master: first stage - register as domain member\n"));
-
- /* update our server status */
- work->ServerType |= SV_TYPE_NT|SV_TYPE_DOMAIN_MASTER;
- add_server_entry(d,work,myname,work->ServerType|SV_TYPE_LOCAL_LIST_ONLY,
- 0, lp_serverstring(),True);
+ case DOMAIN_WAIT:
+ {
+ work->dom_state = DOMAIN_MST; /* ... become domain master */
+ DEBUG(3,("become_domain_master: first stage - register as domain member\n"));
- DEBUG(0,("Samba is now a domain master browser for workgroup %s on subnet %s\n",
- work->work_group, inet_ntoa(d->bcast_ip)));
+ /* update our server status */
+ work->ServerType |= SV_TYPE_NT|SV_TYPE_DOMAIN_MASTER;
+ add_server_entry(d,work,myname,work->ServerType|SV_TYPE_LOCAL_LIST_ONLY,
+ 0, lp_serverstring(),True);
- break;
- }
+ DEBUG(0,("Samba is now a domain master browser for workgroup %s on subnet %s\n",
+ work->work_group, inet_ntoa(d->bcast_ip)));
- case DOMAIN_MST:
- {
- /* don't have to do anything: just report success */
- DEBUG(3,("domain second stage: there isn't one!\n"));
- break;
- }
- }
+ if (d == wins_subnet)
+ {
+ /* ok! we successfully registered by unicast with the
+ WINS server. we now expect to become the domain
+ master on the local subnets. if this fails, it's
+ probably a 1.9.16p2 to 1.9.16p11 server's fault
+ */
+ add_domain_master_bcast();
+ }
+ break;
+ }
+
+ case DOMAIN_MST:
+ {
+ /* don't have to do anything: just report success */
+ DEBUG(3,("domain second stage: there isn't one!\n"));
+ break;
+ }
+ }
}
work->log_state = LOGON_WAIT;
/* XXXX the 0x1c is apparently something to do with domain logons */
- add_my_name_entry(d, myworkgroup,0x1c,nb_type|NB_ACTIVE|NB_GROUP,False);
+ add_my_name_entry(d, myworkgroup,0x1c,nb_type|NB_ACTIVE|NB_GROUP);
/* DON'T do anything else after calling add_my_name_entry() */
break;
/* announce ourselves as no longer active as a master browser. */
announce_server(d, work, work->work_group, myname, 0, 0);
- remove_name_entry(d,MSBROWSE ,0x01,False);
- remove_name_entry(d,work->work_group,0x1d,False);
+ remove_name_entry(d,MSBROWSE ,0x01);
+ remove_name_entry(d,work->work_group,0x1d);
}
}
announce_server(d, work, work->work_group, myname, 0, 0);
/* Remove the name entry without any NetBIOS traffic as that's
how it was registered. */
- remove_name_entry(d,work->work_group,0x1b,True);
+ remove_name_entry(d,work->work_group,0x1b);
}
}
}
/* announce ourselves as no longer active as a master browser. */
announce_server(d, work, work->work_group, myname, 0, 0);
- remove_name_entry(d,work->work_group,0x1c,False);
+ remove_name_entry(d,work->work_group,0x1c);
}
}
note: the name will _always_ be removed
XXXX at present, the name is removed _even_ if a WINS server says keep it.
- If direct is True then the name being removed must have been a direct name
- add. This is done for special names such as DOMAIN<1b>. Just delete it
- without any network release traffic.
-
****************************************************************************/
-void remove_name_entry(struct subnet_record *d, char *name,int type, BOOL direct)
+void remove_name_entry(struct subnet_record *d, char *name,int type)
{
/* XXXX BUG: if samba is offering WINS support, it should still broadcast
a de-registration packet to the local subnet before removing the
if (ip_equal(d->bcast_ip, wins_ip))
{
- if (!lp_wins_support() && !direct)
+ if (!lp_wins_support())
{
/* not a WINS server: we have to release them on the network */
queue_netbios_pkt_wins(ClientNMB,NMB_REL,NAME_RELEASE,
}
else
{
- if(!direct)
/* local interface: release them on the network */
queue_netbios_packet(d,ClientNMB,NMB_REL,NAME_RELEASE,
name, type, 0, 0,0,NULL,NULL,
/****************************************************************************
add an entry to the name list
- If the direct BOOL is set then no network traffic is done for the add - it
- is just blasted into the subnet entry with a zero TTL - it will not
- expire and has not been legitimately claimed. This is *only* done if
- we are a WINS server or for a special name such as DOMAIN<1b>.
big note: our name will _always_ be added (if there are no objections).
it's just a matter of when this will be done (e.g after a time-out).
****************************************************************************/
-void add_my_name_entry(struct subnet_record *d,char *name,int type,int nb_flags, BOOL direct)
+void add_my_name_entry(struct subnet_record *d,char *name,int type,int nb_flags)
{
BOOL re_reg = False;
struct nmb_name n;
if (ip_equal(d->bcast_ip, wins_ip))
{
- if (lp_wins_support() || direct)
+ if (lp_wins_support())
{
/* we are a WINS server. */
if(lp_wins_support())
+ {
DEBUG(4,("add_my_name_entry: samba as WINS server adding: "));
- else
- DEBUG(4,("add_my_name_entry: direct name entry : adding: "));
+ }
/* this will call add_netbios_entry() */
name_register_work(d, name, type, nb_flags,0, ipzero, False);
}
else
{
- if(direct)
- {
- /* Just enter the name to be the ip address of the subnet
- via name_register_work to ensure all side effects are done.
- */
- DEBUG(4,("add_my_name_entry: direct name entry : adding: "));
- /* this will call add_netbios_entry() */
- name_register_work(d, name, type, nb_flags,0, d->myip, False);
- }
- else
- {
- /* broadcast the packet, but it comes from ipzero */
- queue_netbios_packet(d,ClientNMB,
+ /* broadcast the packet, but it comes from ipzero */
+ queue_netbios_packet(d,ClientNMB,
re_reg ? NMB_REG_REFRESH : NMB_REG, NAME_REGISTER,
name, type, nb_flags, GET_TTL(0),0,NULL,NULL,
True, False, d->bcast_ip, ipzero);
- }
}
}
+/****************************************************************************
+ add the internet group <1c> domain logon names by wins unicast and broadcast.
+ ****************************************************************************/
+void add_domain_logon_names(void)
+{
+ struct subnet_record *d;
+
+ if (!lp_domain_logons()) return;
+
+ for (d = FIRST_SUBNET; d; d = NEXT_SUBNET_INCLUDING_WINS(d))
+ {
+ struct work_record *work = find_workgroupstruct(d, myworkgroup, True);
+
+ if (work && work->log_state == LOGON_NONE)
+ {
+ struct nmb_name n;
+ make_nmb_name(&n,myworkgroup,0x1c,scope);
+
+ if (!find_name(d->namelist, &n, FIND_SELF))
+ {
+ /* logon servers are group names. don't expect failure */
+
+ DEBUG(0,("%s attempting to become logon server for %s %s\n",
+ timestring(), myworkgroup, inet_ntoa(d->bcast_ip)));
+
+ become_logon_server(d, work);
+ }
+ }
+ }
+}
+
+
+/****************************************************************************
+ add the <1b> domain master names by broadcast.
+ ****************************************************************************/
+void add_domain_master_bcast(void)
+{
+ struct subnet_record *d;
+
+ if (!lp_domain_master()) return;
+
+ for (d = FIRST_SUBNET; d; d = NEXT_SUBNET_EXCLUDING_WINS(d))
+ {
+ struct work_record *work = find_workgroupstruct(d, myworkgroup, True);
+
+ if (work && work->dom_state == DOMAIN_NONE)
+ {
+ struct nmb_name n;
+ make_nmb_name(&n,myworkgroup,0x1b,scope);
+
+ if (!find_name(d->namelist, &n, FIND_SELF))
+ {
+ DEBUG(0,("%s add_domain_names: attempting to become domain \
+master browser on workgroup %s %s\n",
+ timestring(), myworkgroup, inet_ntoa(d->bcast_ip)));
+
+ /* send out a query to establish whether there's a
+ domain controller on the local subnet. if not,
+ we can become a domain controller. it's only
+ polite that we check, before claiming the
+ NetBIOS name 0x1b.
+ */
+
+ DEBUG(0,("add_domain_names:querying subnet %s \
+for domain master on workgroup %s\n",
+ inet_ntoa(d->bcast_ip), myworkgroup));
+
+ queue_netbios_packet(d,ClientNMB,NMB_QUERY,
+ NAME_QUERY_DOMAIN,
+ myworkgroup, 0x1b,
+ 0, 0,0,NULL,NULL,
+ True, False,
+ d->bcast_ip, d->bcast_ip);
+ }
+ }
+ }
+}
+
+
+/****************************************************************************
+ add the <1b> domain master name by wins unicast.
+ ****************************************************************************/
+void add_domain_master_wins(void)
+{
+ struct work_record *work;
+
+ if (!lp_domain_master() || wins_subnet == NULL) return;
+
+ work = find_workgroupstruct(wins_subnet, myworkgroup, True);
+
+ if (work && work->dom_state == DOMAIN_NONE)
+ {
+ struct nmb_name n;
+ make_nmb_name(&n,myworkgroup,0x1b,scope);
+
+ if (!find_name(wins_subnet->namelist, &n, FIND_SELF))
+ {
+ DEBUG(0,("%s add_domain_names: attempting to become domain \
+master browser on workgroup %s %s\n",
+ timestring(), myworkgroup, inet_ntoa(wins_subnet->bcast_ip)));
+
+ if (lp_wins_support())
+ {
+ /* use the wins server's capabilities (indirectly). if
+ someone has already registered the domain<1b>
+ name with the WINS server, then the WINS
+ server's job is to _check_ that the owner still
+ wants it, before giving it away.
+ */
+
+ DEBUG(1,("%s initiate become domain master for %s\n",
+ timestring(), myworkgroup));
+
+ become_domain_master(wins_subnet, work);
+ }
+ else
+ {
+ /* send out a query to establish whether there's a
+ domain controller on the WINS subnet. if not,
+ we can become a domain controller. it's only
+ polite that we check, before claiming the
+ NetBIOS name 0x1b.
+ */
+
+ DEBUG(0,("add_domain_names:querying WINS \
+for domain master on workgroup %s\n", myworkgroup));
+
+ queue_netbios_pkt_wins(ClientNMB,NMB_QUERY,
+ NAME_QUERY_DOMAIN,
+ myworkgroup, 0x1b,
+ 0, 0,0,NULL,NULL,
+ False, True, ipzero, ipzero);
+ }
+ }
+ }
+}
+
+
/****************************************************************************
add the domain logon server and domain master browser names
**************************************************************************/
void add_domain_names(time_t t)
{
- static time_t lastrun = 0;
- struct subnet_record *d;
- struct work_record *work;
- struct nmb_name n;
+ static time_t lastrun = 0;
- if (lastrun != 0 && t < lastrun + CHECK_TIME_ADD_DOM_NAMES * 60) return;
- lastrun = t;
+ if (lastrun != 0 && t < lastrun + CHECK_TIME_ADD_DOM_NAMES * 60) return;
+ lastrun = t;
- for (d = FIRST_SUBNET; d; d = NEXT_SUBNET_INCLUDING_WINS(d))
- {
- work = find_workgroupstruct(d, myworkgroup, False);
- if (lp_domain_logons() && work && work->log_state == LOGON_NONE)
- {
- make_nmb_name(&n,myworkgroup,0x1c,scope);
- if (!find_name(d->namelist, &n, FIND_SELF))
- {
- /* logon servers are group names - we don't expect this to fail. */
- DEBUG(0,("%s attempting to become logon server for %s %s\n",
- timestring(), myworkgroup, inet_ntoa(d->bcast_ip)));
- become_logon_server(d, work);
- }
- }
- }
+ /* do the "internet group" - <1c> names */
+ add_domain_logon_names();
- for (d = FIRST_SUBNET; d; d = NEXT_SUBNET_INCLUDING_WINS(d))
- {
- work = find_workgroupstruct(d, myworkgroup, True);
+ /* do the domain master names */
+ if (wins_subnet != NULL)
+ {
+ /* if the registration of the <1b> name is successful, then
+ add_domain_master_bcast() will be called. this will
+ result in domain logon services being gracefully provided,
+ as opposed to the aggressive nature of 1.9.16p2 to 1.9.16p11.
- if (lp_domain_master() && work && work->dom_state == DOMAIN_NONE)
- {
- make_nmb_name(&n,myworkgroup,0x1b,scope);
- if (!find_name(d->namelist, &n, FIND_SELF))
- {
- DEBUG(0,("%s add_domain_names: attempting to become domain master \
-browser on workgroup %s %s\n",
- timestring(), myworkgroup, inet_ntoa(d->bcast_ip)));
-
- if(d == wins_subnet)
- {
- if (lp_wins_support())
- {
- /* use the wins server's capabilities (indirectly). if
- someone has already registered the domain<1b> name with
- the WINS server, then the WINS server's job is to _check_
- that the owner still wants it, before giving it away.
- */
-
- DEBUG(1,("%s initiating becoming domain master for %s\n",
- timestring(), myworkgroup));
- become_domain_master(d, work);
- }
- else
- {
- /* send out a query to establish whether there's a
- domain controller on the WINS subnet. if not,
- we can become a domain controller.
- it's only polite that we check, before claiming the
- NetBIOS name 0x1b.
- */
-
- DEBUG(0,("add_domain_names:querying WINS for domain master \
-on workgroup %s\n", myworkgroup));
-
- queue_netbios_pkt_wins(ClientNMB,NMB_QUERY,NAME_QUERY_DOMAIN,
- myworkgroup, 0x1b,
- 0, 0,0,NULL,NULL,
- False, True, ipzero, ipzero);
- }
- }
- else
- {
- DEBUG(0,("add_domain_names:querying subnet %s for domain master \
-on workgroup %s\n", inet_ntoa(d->bcast_ip), myworkgroup));
- queue_netbios_packet(d,ClientNMB,NMB_QUERY,NAME_QUERY_DOMAIN,
- myworkgroup, 0x1b,
- 0, 0,0,NULL,NULL,
- True, False,
- d->bcast_ip, d->bcast_ip);
- }
- }
- }
- }
-}
+ which, due to a bug in namelogon.c from 1.9.16p2 to 1.9.16p11
+ cannot _provide_ domain master / domain logon services!!!
+ */
+ add_domain_master_wins();
+ }
+ else
+ {
+ add_domain_master_bcast();
+ }
+}
/****************************************************************************
add the magic samba names, useful for finding samba servers
{
BOOL wins = (lp_wins_support() && (d == wins_subnet));
- add_my_name_entry(d, myname,0x20,nb_type|NB_ACTIVE,False);
- add_my_name_entry(d, myname,0x03,nb_type|NB_ACTIVE,False);
- add_my_name_entry(d, myname,0x00,nb_type|NB_ACTIVE,False);
+ add_my_name_entry(d, myname,0x20,nb_type|NB_ACTIVE);
+ add_my_name_entry(d, myname,0x03,nb_type|NB_ACTIVE);
+ add_my_name_entry(d, myname,0x00,nb_type|NB_ACTIVE);
/* these names are added permanently (ttl of zero) and will NOT be
refreshed with the WINS server */
/* get all SELF names removed from the WINS server's database */
/* XXXX note: problem occurs if this removes the wrong one! */
- remove_name_entry(d,n->name.name, n->name.name_type,False);
+ remove_name_entry(d,n->name.name, n->name.name_type);
}
}
}
n->death_time != 0)
{
add_my_name_entry(d,n->name.name,n->name.name_type,
- n->ip_flgs[0].nb_flags,False);
+ n->ip_flgs[0].nb_flags);
/* they get a new lease on life :-) */
n->death_time += GET_TTL(0);
n->refresh_time += GET_TTL(0);