From d035d6ded0265c24cf58a7af154badc45950e522 Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Tue, 29 Jan 2008 00:21:52 +0000 Subject: [PATCH] DEVEL15-windows-lanahelper-20080128 LICENSE MIT The algorithms that were used to produce a Netbios name were broken. The name that was produced when the hostname was too long was in fact longer than the maximum permitted netbios name. Also, the "NetbiosName" value was not used as a suffix when the loopback adapter was not installed. The hardcoded string "AFS" was used instead. (cherry picked from commit 2542c5e07f52c89f25f290153f0b4669076ae654) --- src/WINNT/afsd/lanahelper.cpp | 26 ++++++++++++++++---------- src/WINNT/afsd/lanahelper.h | 2 +- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/WINNT/afsd/lanahelper.cpp b/src/WINNT/afsd/lanahelper.cpp index f99f11d29..36b53595d 100644 --- a/src/WINNT/afsd/lanahelper.cpp +++ b/src/WINNT/afsd/lanahelper.cpp @@ -572,8 +572,10 @@ extern "C" long lana_GetUncServerNameEx(char *buffer, lana_number_t * pLana, int rv = RegQueryValueEx(hkConfig, szNetbiosNameValue, NULL, NULL, (LPBYTE) ®NbName, &dummyLen); if(rv != ERROR_SUCCESS) strcpy(regNbName, "AFS"); - else - regNbName[15] = 0; + else { + /* Max Suffix Length is 6 */ + regNbName[6] = 0; + } RegCloseKey(hkConfig); } else { @@ -617,26 +619,30 @@ extern "C" long lana_GetUncServerNameEx(char *buffer, lana_number_t * pLana, int if(regNbName[0] && (regLana >=0 && lana_IsLoopback((lana_number_t) regLana,FALSE))) { - strncpy(nbName,regNbName,15); - nbName[16] = 0; + strncpy(nbName,regNbName,14); + nbName[14] = 0; strupr(nbName); } else { - char * dot; - if(flags & LANA_NETBIOS_NAME_SUFFIX) { - strcpy(nbName,"-AFS"); + _snprintf(nbName, MAX_NB_NAME_LENGTH, "-%s", regNbName); + nbName[14] = 0; } else { + char * dot; + dummyLen = sizeof(hostname); // assume we are not a cluster. rv = GetComputerName(hostname, &dummyLen); if(!SUCCEEDED(rv)) { // should not happen, but... return rv; } - strncpy(nbName, hostname, 11); - nbName[11] = 0; + strncpy(nbName, hostname, MAX_NB_NAME_LENGTH); + nbName[MAX_NB_NAME_LENGTH-1] = 0; + nbName[MAX_NB_NAME_LENGTH-strlen(regNbName)-2] = 0; if(dot = strchr(nbName,'.')) *dot = 0; - strcat(nbName,"-AFS"); + strncat(nbName, "-", MAX_NB_NAME_LENGTH); + strncat(nbName, regNbName, MAX_NB_NAME_LENGTH); + nbName[MAX_NB_NAME_LENGTH-1] = 0; } } diff --git a/src/WINNT/afsd/lanahelper.h b/src/WINNT/afsd/lanahelper.h index 608fe1631..e161532c7 100644 --- a/src/WINNT/afsd/lanahelper.h +++ b/src/WINNT/afsd/lanahelper.h @@ -42,7 +42,7 @@ extern "C" { }; #define LANA_INVALID 0xff -#define MAX_NB_NAME_LENGTH 17 +#define MAX_NB_NAME_LENGTH 16 #define LANA_NETBIOS_NAME_SUFFIX 1 #define LANA_NETBIOS_NAME_FULL 0 -- 2.39.5