/*
- Unix SMB/Netbios implementation.
- Version 1.9.
+ Unix SMB/CIFS implementation.
NBT netbios routines and daemon - version 2
Copyright (C) Andrew Tridgell 1994-1998
Copyright (C) Luke Kenneth Casson Leighton 1994-1998
*/
#include "includes.h"
-#include "smb.h"
extern int ClientNMB;
-extern int DEBUGLEVEL;
-
-extern fstring global_myworkgroup;
-extern char **my_netbios_names;
-
int updatecount = 0;
/*******************************************************************
work->serverlist = servrec->next;
ZERO_STRUCTP(servrec);
- free((char *)servrec);
+ SAFE_FREE(servrec);
}
Find a server in a server list.
**************************************************************************/
-struct server_record *find_server_in_workgroup(struct work_record *work, char *name)
+struct server_record *find_server_in_workgroup(struct work_record *work, const char *name)
{
struct server_record *ret;
work->serverlist = servrec->next;
ZERO_STRUCTP(servrec);
- free((char *)servrec);
+ SAFE_FREE(servrec);
work->subnet->work_changed = True;
}
****************************************************************************/
struct server_record *create_server_on_workgroup(struct work_record *work,
- char *name,int servertype,
- int ttl,char *comment)
+ const char *name,int servertype,
+ int ttl, const char *comment)
{
struct server_record *servrec;
return NULL;
}
- bzero((char *)servrec,sizeof(*servrec));
+ memset((char *)servrec,'\0',sizeof(*servrec));
servrec->subnet = work->subnet;
- StrnCpy(servrec->serv.name,name,sizeof(servrec->serv.name)-1);
- StrnCpy(servrec->serv.comment,comment,sizeof(servrec->serv.comment)-1);
+ fstrcpy(servrec->serv.name,name);
+ fstrcpy(servrec->serv.comment,comment);
strupper(servrec->serv.name);
servrec->serv.type = servertype;
{
struct subnet_record *ssub;
struct work_record *iwork;
- struct server_record *sserv;
/* Go through all the subnets we have already seen. */
for (ssub = FIRST_SUBNET; ssub != subrec; ssub = NEXT_SUBNET_INCLUDING_UNICAST(ssub))
{
for(iwork = ssub->workgrouplist; iwork; iwork = iwork->next)
{
- if((sserv = find_server_in_workgroup( iwork, servrec->serv.name)) != NULL)
+ if(find_server_in_workgroup( iwork, servrec->serv.name) != NULL)
{
/*
* We have already written out this server record, don't
/*******************************************************************
Decide if we should write out a workgroup record for this workgroup.
- We return zero if we should not. Don't write out global_myworkgroup (we've
+ We return zero if we should not. Don't write out lp_workgroup() (we've
already done it) and also don't write out a second workgroup record
on the unicast subnet that we've already written out on one of the
broadcast subnets.
{
struct subnet_record *ssub;
- if(strequal(global_myworkgroup, work->work_group))
+ if(strequal(lp_workgroup(), work->work_group))
return 0;
/* This is a workgroup we have seen on a broadcast subnet. All
Write out the browse.dat file.
******************************************************************/
+void write_browse_list_entry(XFILE *fp, const char *name, uint32 rec_type,
+ const char *local_master_browser_name, const char *description)
+{
+ fstring tmp;
+
+ slprintf(tmp,sizeof(tmp)-1, "\"%s\"", name);
+ x_fprintf(fp, "%-25s ", tmp);
+ x_fprintf(fp, "%08x ", rec_type);
+ slprintf(tmp, sizeof(tmp)-1, "\"%s\" ", local_master_browser_name);
+ x_fprintf(fp, "%-30s", tmp);
+ x_fprintf(fp, "\"%s\"\n", description);
+}
+
void write_browse_list(time_t t, BOOL force_write)
{
struct subnet_record *subrec;
struct server_record *servrec;
pstring fname,fnamenew;
uint32 stype;
- fstring tmp;
int i;
- FILE *fp;
+ XFILE *fp;
BOOL list_changed = force_write;
static time_t lasttime = 0;
return;
}
+ lasttime = t;
+
dump_workgroups(force_write);
for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec))
if(!list_changed)
return;
- lasttime = t;
updatecount++;
pstrcpy(fname,lp_lockdir());
pstrcpy(fnamenew,fname);
pstrcat(fnamenew,".");
- fp = fopen(fnamenew,"w");
+ fp = x_fopen(fnamenew,O_WRONLY|O_CREAT|O_TRUNC, 0644);
if (!fp)
{
* subnet.
*/
- if((work = find_workgroup_on_subnet(FIRST_SUBNET, global_myworkgroup)) == NULL)
+ if((work = find_workgroup_on_subnet(FIRST_SUBNET, lp_workgroup())) == NULL)
{
DEBUG(0,("write_browse_list: Fatal error - cannot find my workgroup %s\n",
- global_myworkgroup));
- fclose(fp);
+ lp_workgroup()));
+ x_fclose(fp);
return;
}
- slprintf(tmp,sizeof(tmp)-1, "\"%s\"", work->work_group);
- fprintf(fp, "%-25s ", tmp);
- fprintf(fp, "%08x ", SV_TYPE_DOMAIN_ENUM|SV_TYPE_NT|SV_TYPE_LOCAL_LIST_ONLY);
- slprintf(tmp, sizeof(tmp)-1, "\"%s\" ", work->local_master_browser_name);
- fprintf(fp, "%-30s", tmp);
- fprintf(fp, "\"%s\"\n", work->work_group);
+ write_browse_list_entry(fp, work->work_group,
+ SV_TYPE_DOMAIN_ENUM|SV_TYPE_NT|SV_TYPE_LOCAL_LIST_ONLY,
+ work->local_master_browser_name, work->work_group);
/*
* We need to do something special for our own names.
* once.
*/
- for (i=0; my_netbios_names[i]; i++)
+ for (i=0; my_netbios_names(i); i++)
{
stype = 0;
for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec))
{
- if((work = find_workgroup_on_subnet( subrec, global_myworkgroup )) == NULL)
+ if((work = find_workgroup_on_subnet( subrec, lp_workgroup() )) == NULL)
continue;
- if((servrec = find_server_in_workgroup( work, my_netbios_names[i])) == NULL)
+ if((servrec = find_server_in_workgroup( work, my_netbios_names(i))) == NULL)
continue;
stype |= servrec->serv.type;
}
/* Output server details, plus what workgroup they're in. */
- slprintf(tmp, sizeof(tmp)-1, "\"%s\"", my_netbios_names[i]);
- fprintf(fp, "%-25s ", tmp);
- fprintf(fp, "%08x ", stype);
- slprintf(tmp, sizeof(tmp)-1, "\"%s\" ", lp_serverstring());
- fprintf(fp, "%-30s", tmp);
- fprintf(fp, "\"%s\"\n", global_myworkgroup);
+ write_browse_list_entry(fp, my_netbios_names(i), stype,
+ string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH), lp_workgroup());
}
for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec))
if(wg_type)
{
- slprintf(tmp, sizeof(tmp)-1, "\"%s\"", work->work_group);
- fprintf(fp, "%-25s ", tmp);
-
- fprintf(fp, "%08x ", wg_type);
- slprintf(tmp, sizeof(tmp)-1, "\"%s\" ", work->local_master_browser_name);
- fprintf(fp, "%-30s", tmp);
- fprintf(fp, "\"%s\"\n", work->work_group);
+ write_browse_list_entry(fp, work->work_group, wg_type,
+ work->local_master_browser_name,
+ work->work_group);
}
/* Now write out any server records a workgroup may have. */
if(serv_type)
{
/* Output server details, plus what workgroup they're in. */
- slprintf(tmp, sizeof(tmp)-1, "\"%s\"", servrec->serv.name);
- fprintf(fp, "%-25s ", tmp);
- fprintf(fp, "%08x ", serv_type);
- slprintf(tmp, sizeof(tmp)-1, "\"%s\" ", servrec->serv.comment);
- fprintf(fp, "%-30s", tmp);
- fprintf(fp, "\"%s\"\n", work->work_group);
+ write_browse_list_entry(fp, servrec->serv.name, serv_type,
+ servrec->serv.comment, work->work_group);
}
}
}
}
- fclose(fp);
+ x_fclose(fp);
unlink(fname);
chmod(fnamenew,0644);
rename(fnamenew,fname);