windows-lanahelper-20080128
authorJeffrey Altman <jaltman@secure-endpoints.com>
Tue, 29 Jan 2008 00:20:33 +0000 (00:20 +0000)
committerJeffrey Altman <jaltman@secure-endpoints.com>
Tue, 29 Jan 2008 00:20:33 +0000 (00:20 +0000)
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.

src/WINNT/afsd/lanahelper.cpp
src/WINNT/afsd/lanahelper.h

index f99f11d..36b5359 100644 (file)
@@ -572,8 +572,10 @@ extern "C" long lana_GetUncServerNameEx(char *buffer, lana_number_t * pLana, int
        rv = RegQueryValueEx(hkConfig, szNetbiosNameValue, NULL, NULL, (LPBYTE) &regNbName, &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;
        }
     }
 
index 608fe16..e161532 100644 (file)
@@ -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