From 326d6e8522f7aa73d80507575fbe283ab12dccfe Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Wed, 7 Mar 2007 18:14:05 +0000 Subject: [PATCH] DEVEL15-windows-plug-n-play-network-fix-20070307 Move the detection of which LAN adapter to use from smb_Init to smb_NetbiosInit so that it is executed after the service is resumed via a power management event. Otherwise, when the network comes back up the service attempts to bind to all LAN adapters instead of just the loopback or the configured one. (cherry picked from commit 5332348bdf68491670cc94ff1f9bc527876304fa) --- src/WINNT/afsd/afsd_init.c | 24 +--------------------- src/WINNT/afsd/smb.c | 42 ++++++++++++++++++++++++++++++-------- src/WINNT/afsd/smb.h | 2 +- 3 files changed, 35 insertions(+), 33 deletions(-) diff --git a/src/WINNT/afsd/afsd_init.c b/src/WINNT/afsd/afsd_init.c index 8a4e0b2a1..afbb2ca33 100644 --- a/src/WINNT/afsd/afsd_init.c +++ b/src/WINNT/afsd/afsd_init.c @@ -76,8 +76,6 @@ char cm_CachePath[MAX_PATH]; DWORD cm_CachePathLen; DWORD cm_ValidateCache = 1; -BOOL isGateway = FALSE; - BOOL reportSessionStartups = FALSE; cm_initparams_v1 cm_initParams; @@ -568,7 +566,6 @@ int afsd_InitCM(char **reasonP) long code; /*int freelanceEnabled;*/ WSADATA WSAjunk; - lana_number_t lanaNum; int i; char *p, *q; int cm_noIPAddr; /* number of client network interfaces */ @@ -1081,25 +1078,6 @@ int afsd_InitCM(char **reasonP) RegCloseKey (parmKey); - /* Call lanahelper to get Netbios name, lan adapter number and gateway flag */ - if (SUCCEEDED(code = lana_GetUncServerNameEx(cm_NetbiosName, &lanaNum, &isGateway, LANA_NETBIOS_NAME_FULL))) { - LANadapter = (lanaNum == LANA_INVALID)? -1: lanaNum; - - if (LANadapter != -1) - afsi_log("LAN adapter number %d", LANadapter); - else - afsi_log("LAN adapter number not determined"); - - if (isGateway) - afsi_log("Set for gateway service"); - - afsi_log("Using >%s< as SMB server name", cm_NetbiosName); - } else { - /* something went horribly wrong. We can't proceed without a netbios name */ - StringCbPrintfA(buf,sizeof(buf),"Netbios name could not be determined: %li", code); - osi_panic(buf, __FILE__, __LINE__); - } - cacheBlocks = ((afs_uint64)cacheSize * 1024) / CM_CONFIGDEFAULT_BLOCKSIZE; /* get network related info */ @@ -1325,7 +1303,7 @@ int afsd_InitSMB(char **reasonP, void *aMBfunc) /* Do this last so that we don't handle requests before init is done. * Here we initialize the SMB listener. */ - smb_Init(afsd_logp, cm_NetbiosName, smb_UseV3, LANadapter, numSvThreads, aMBfunc); + smb_Init(afsd_logp, smb_UseV3, numSvThreads, aMBfunc); afsi_log("smb_Init complete"); return 0; diff --git a/src/WINNT/afsd/smb.c b/src/WINNT/afsd/smb.c index 4fc8ea074..408d325f8 100644 --- a/src/WINNT/afsd/smb.c +++ b/src/WINNT/afsd/smb.c @@ -65,6 +65,8 @@ osi_mutex_t smb_ListenerLock; char smb_LANadapter; unsigned char smb_sharename[NCBNAMSZ+1] = {0}; +BOOL isGateway = FALSE; + /* for debugging */ long smb_maxObsConcurrentCalls=0; long smb_concurrentCalls=0; @@ -8592,6 +8594,7 @@ int smb_NetbiosInit(void) int delname_tried=0; int len; int lana_found = 0; + lana_number_t lanaNum; /* setup the NCB system */ ncbp = GetNCB(); @@ -8599,6 +8602,35 @@ int smb_NetbiosInit(void) dos_ncb = ((smb_ncb_t *)ncbp)->dos_ncb; #endif /* DJGPP */ + /* Call lanahelper to get Netbios name, lan adapter number and gateway flag */ + if (SUCCEEDED(code = lana_GetUncServerNameEx(cm_NetbiosName, &lanaNum, &isGateway, LANA_NETBIOS_NAME_FULL))) { + smb_LANadapter = (lanaNum == LANA_INVALID)? -1: lanaNum; + + if (smb_LANadapter != -1) + afsi_log("LAN adapter number %d", smb_LANadapter); + else + afsi_log("LAN adapter number not determined"); + + if (isGateway) + afsi_log("Set for gateway service"); + + afsi_log("Using >%s< as SMB server name", cm_NetbiosName); + } else { + /* something went horribly wrong. We can't proceed without a netbios name */ + char buf[128]; + StringCbPrintfA(buf,sizeof(buf),"Netbios name could not be determined: %li", code); + osi_panic(buf, __FILE__, __LINE__); + } + + /* remember the name */ + len = (int)strlen(cm_NetbiosName); + if (smb_localNamep) + free(smb_localNamep); + smb_localNamep = malloc(len+1); + strcpy(smb_localNamep, cm_NetbiosName); + afsi_log("smb_localNamep is >%s<", smb_localNamep); + + #ifndef DJGPP if (smb_LANadapter == -1) { ncbp->ncb_command = NCBENUM; @@ -8835,7 +8867,7 @@ void smb_StopListeners(void) Sleep(1000); /* give the listener threads a chance to exit */ } -void smb_Init(osi_log_t *logp, char *snamep, int useV3, int LANadapt, +void smb_Init(osi_log_t *logp, int useV3, int nThreads #ifndef DJGPP , void *aMBfunc @@ -8846,7 +8878,6 @@ void smb_Init(osi_log_t *logp, char *snamep, int useV3, int LANadapt, thread_t phandle; int lpid; INT_PTR i; - int len; struct tm myTime; #ifdef DJGPP int npar, seg, sel; @@ -8862,7 +8893,6 @@ void smb_Init(osi_log_t *logp, char *snamep, int useV3, int LANadapt, #endif /* DJGPP */ smb_useV3 = useV3; - smb_LANadapter = LANadapt; /* Initialize smb_localZero */ myTime.tm_isdst = -1; /* compute whether on DST or not */ @@ -8886,12 +8916,6 @@ void smb_Init(osi_log_t *logp, char *snamep, int useV3, int LANadapt, /* initialize the remote debugging log */ smb_logp = logp; - /* remember the name */ - len = (int)strlen(snamep); - smb_localNamep = malloc(len+1); - strcpy(smb_localNamep, snamep); - afsi_log("smb_localNamep is >%s<", smb_localNamep); - /* and the global lock */ lock_InitializeRWLock(&smb_globalLock, "smb global lock"); lock_InitializeRWLock(&smb_rctLock, "smb refct and tree struct lock"); diff --git a/src/WINNT/afsd/smb.h b/src/WINNT/afsd/smb.h index d86e129aa..ebb5e0974 100644 --- a/src/WINNT/afsd/smb.h +++ b/src/WINNT/afsd/smb.h @@ -523,7 +523,7 @@ typedef struct smb_dispatch { /* prototypes */ -extern void smb_Init(osi_log_t *logp, char *smbNamep, int useV3, int LANadapt, +extern void smb_Init(osi_log_t *logp, int useV3, int nThreads #ifndef DJGPP , void *aMBfunc -- 2.39.5