summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2003-08-28 18:12:59 +0000
committerJeremy Allison <jra@samba.org>2003-08-28 18:12:59 +0000
commit6872f392f1a8cd667aecc8df0b15da66f58c9407 (patch)
tree64adecb7953a5031dbe0fa6a90e840f0c13aac1e /source3
parent76bcb93c66395f6d3e7bd960489094fcafa9fa89 (diff)
downloadsamba-6872f392f1a8cd667aecc8df0b15da66f58c9407.tar.gz
samba-6872f392f1a8cd667aecc8df0b15da66f58c9407.tar.bz2
samba-6872f392f1a8cd667aecc8df0b15da66f58c9407.zip
Fixed off-by-one bugs in workgroup name comparisons. Complain when a
workgroup name is >15 characters. Jeremy. (This used to be commit 35a0b3c035d50474eda97b015676885722737a95)
Diffstat (limited to 'source3')
-rw-r--r--source3/nmbd/nmbd_elections.c8
-rw-r--r--source3/nmbd/nmbd_serverlistdb.c2
-rw-r--r--source3/nmbd/nmbd_workgroupdb.c15
3 files changed, 16 insertions, 9 deletions
diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c
index e341f6f7fb..fabc0eddca 100644
--- a/source3/nmbd/nmbd_elections.c
+++ b/source3/nmbd/nmbd_elections.c
@@ -97,7 +97,7 @@ static void check_for_master_browser_fail( struct subnet_record *subrec,
return;
}
- if (strnequal(work->work_group, lp_workgroup(), sizeof(nstring))) {
+ if (strnequal(work->work_group, lp_workgroup(), sizeof(nstring)-1)) {
if (lp_local_master()) {
/* We have discovered that there is no local master
@@ -145,7 +145,7 @@ void check_master_browser_exists(time_t t)
struct work_record *work;
for (work = subrec->workgrouplist; work; work = work->next) {
- if (strnequal(work->work_group, workgroup_name, sizeof(nstring)) && !AM_LOCAL_MASTER_BROWSER(work)) {
+ if (strnequal(work->work_group, workgroup_name, sizeof(nstring)-1) && !AM_LOCAL_MASTER_BROWSER(work)) {
/* Do a name query for the local master browser on this net. */
query_name( subrec, work->work_group, 0x1d,
check_for_master_browser_success,
@@ -284,7 +284,7 @@ void process_election(struct subnet_record *subrec, struct packet_struct *p, cha
goto done;
}
- if (!strnequal(work->work_group, lp_workgroup(), sizeof(nstring))) {
+ if (!strnequal(work->work_group, lp_workgroup(), sizeof(nstring)-1)) {
DEBUG(3,("process_election: ignoring election request for workgroup %s on subnet %s as this \
is not my workgroup.\n", work->work_group, subrec->subnet_name ));
goto done;
@@ -381,7 +381,7 @@ void nmbd_message_election(int msg_type, pid_t src, void *buf, size_t len)
for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) {
struct work_record *work;
for (work = subrec->workgrouplist; work; work = work->next) {
- if (strnequal(work->work_group, lp_workgroup(), sizeof(nstring))) {
+ if (strnequal(work->work_group, lp_workgroup(), sizeof(nstring)-1)) {
work->needelection = True;
work->ElectionCount=0;
work->mst_state = lp_local_master() ? MST_POTENTIAL : MST_NONE;
diff --git a/source3/nmbd/nmbd_serverlistdb.c b/source3/nmbd/nmbd_serverlistdb.c
index ecde45cfb9..a5008f803b 100644
--- a/source3/nmbd/nmbd_serverlistdb.c
+++ b/source3/nmbd/nmbd_serverlistdb.c
@@ -251,7 +251,7 @@ static uint32 write_this_workgroup_name( struct subnet_record *subrec,
{
struct subnet_record *ssub;
- if(strnequal(lp_workgroup(), work->work_group, sizeof(nstring)))
+ if(strnequal(lp_workgroup(), work->work_group, sizeof(nstring)-1))
return 0;
/* This is a workgroup we have seen on a broadcast subnet. All
diff --git a/source3/nmbd/nmbd_workgroupdb.c b/source3/nmbd/nmbd_workgroupdb.c
index c957b517cf..b9fab4b278 100644
--- a/source3/nmbd/nmbd_workgroupdb.c
+++ b/source3/nmbd/nmbd_workgroupdb.c
@@ -56,7 +56,14 @@ static struct work_record *create_workgroup(const char *name, int ttl)
}
memset((char *)work, '\0', sizeof(*work));
- nstrcpy(work->work_group,name);
+ if (strlen(name)+1 > sizeof(nstring)) {
+ memcpy(work->work_group,name,sizeof(nstring)-1);
+ work->work_group[sizeof(nstring)-1] = '\0';
+ DEBUG(0,("create_workgroup: workgroup name %s is too long. Truncating to %s\n",
+ name, work->work_group ));
+ } else {
+ nstrcpy(work->work_group,name);
+ }
work->serverlist = NULL;
work->RunningElection = False;
@@ -76,7 +83,7 @@ static struct work_record *create_workgroup(const char *name, int ttl)
for (subrec = FIRST_SUBNET; subrec && (t == -1); subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) {
struct work_record *w;
for (w = subrec->workgrouplist; w && t == -1; w = w->next) {
- if (strnequal(w->work_group, work->work_group, sizeof(nstring)))
+ if (strnequal(w->work_group, work->work_group, sizeof(nstring)-1))
t = w->token;
}
}
@@ -150,7 +157,7 @@ struct work_record *find_workgroup_on_subnet(struct subnet_record *subrec,
name, subrec->subnet_name));
for (ret = subrec->workgrouplist; ret; ret = ret->next) {
- if (strnequal(ret->work_group,name,sizeof(nstring))) {
+ if (strnequal(ret->work_group,name,sizeof(nstring)-1)) {
DEBUGADD(4, ("found.\n"));
return(ret);
}
@@ -211,7 +218,7 @@ void initiate_myworkgroup_startup(struct subnet_record *subrec, struct work_reco
{
int i;
- if(!strnequal(lp_workgroup(), work->work_group,sizeof(nstring)))
+ if(!strnequal(lp_workgroup(), work->work_group,sizeof(nstring)-1))
return;
/* If this is a broadcast subnet then start elections on it if we are so configured. */