vcp->lana = lana;
vcp->secCtx = NULL;
- if (smb_authType == SMB_AUTH_NTLM || smb_authType == SMB_AUTH_EXTENDED) {
+ if (smb_authType == SMB_AUTH_NTLM) {
/* We must obtain a challenge for extended auth
* in case the client negotiates smb v3
*/
p = pathName;
cchlen = lengthof(pathName);
- /* within this code block, we maintain, cchlen = writeable
+ /* within this code block, we maintain, cchlen = writable
buffer length of p */
if (cm_ClientStrCmpN(p, cm_mountRootC, cm_mountRootCLen) == 0) {
smb_FreeNCB(ncbp);
}
-void smb_MapNTError(long code, unsigned long *NTStatusp)
+void smb_MapNTError(long code, unsigned long *NTStatusp, afs_uint32 redir)
{
unsigned long NTStatus;
NTStatus = 0xC0000034L; /* Name not found */
}
else if (code == CM_ERROR_TIMEDOUT) {
+ if (redir)
+ NTStatus = 0xC0020052L; /* RPC_NT_COMM_FAILURE */
+ else {
#ifdef COMMENT
- NTStatus = 0xC00000CFL; /* Sharing Paused */
-
- /* Do not send Timeout to the SMB redirector.
- * It causes the redirector to drop the connection */
- NTStatus = 0x00000102L; /* Timeout */
- /* do not send Retry to the SMB redirector.
- * It believes the error comes from the transport
- * layer not from the SMB server. */
- NTStatus = 0xC000022DL; /* Retry */
+ NTStatus = 0xC00000CFL; /* Sharing Paused */
+
+ /* Do not send Timeout to the SMB redirector.
+ * It causes the redirector to drop the connection */
+ NTStatus = 0x00000102L; /* Timeout */
+ /* do not send Retry to the SMB redirector.
+ * It believes the error comes from the transport
+ * layer not from the SMB server. */
+ NTStatus = 0xC000022DL; /* Retry */
#else
- NTStatus = 0xC00000B5L; /* I/O Timeout */
+ NTStatus = 0xC00000B5L; /* I/O Timeout */
#endif
+ }
}
else if (code == CM_ERROR_RETRY) {
+ if (redir)
+ NTStatus = 0xC000022DL; /* Retry */
+ else {
#ifdef COMMENT
- NTStatus = 0xC000022DL; /* Retry */
+ NTStatus = 0xC000022DL; /* Retry */
#else
- NTStatus = 0xC00000B5L; /* I/O Timeout */
+ NTStatus = 0xC00000B5L; /* I/O Timeout */
#endif
+ }
}
else if (code == CM_ERROR_NOACCESS) {
NTStatus = 0xC0000022L; /* Access denied */
else if (code == CM_ERROR_RPC_MOREDATA) {
NTStatus = 0x80000005L; /* Buffer overflow */
}
- else {
+ else {
+ char foo[256];
+ sprintf(foo, "No mapping for 0x%X using 0xC0982001\r\n", code);
+ OutputDebugString(foo);
NTStatus = 0xC0982001L; /* SMB non-specific error */
}
* the same value for all sessions. We should generate a random value
* and store it into the vcp
*/
- smb_SetSMBParm(outp, 7, 1); /* next 2: session key */
- smb_SetSMBParm(outp, 8, 1);
+ smb_SetSMBParmLong(outp, 7, 0x1a2b3c4d); /* session key */
/*
* Tried changing the capabilities to support for W2K - defect 117695
* Maybe something else needs to be changed here?
datap + MSV1_0_CHALLENGE_LENGTH,
(int)(sizeof(outp->data)/sizeof(char) - (datap - outp->data)));
} else if ( smb_authType == SMB_AUTH_EXTENDED ) {
- void * secBlob;
- int secBlobLength;
+ void * secBlob = NULL;
+ int secBlobLength = 0;
smb_SetSMBParmByte(outp, 16, 0); /* Encryption key length */
- smb_NegotiateExtendedSecurity(&secBlob, &secBlobLength);
+ /*
+ * The SMB specification permits the server to save a round trip
+ * in the GSS negotiation by sending an initial security blob.
+ * Unfortunately, doing so trips a bug in Windows 7 and Server 2008 R2
+ * whereby the SMB 1.x redirector drops the blob on the floor after
+ * the first connection to the server and simply attempts to reuse
+ * the previous authentication context. This bug can be avoided by
+ * the server sending no security blob in the SMB_COM_NEGOTIATE
+ * response. This forces the client to send an initial GSS init_sec_context
+ * blob under all circumstances which works around the bug in Microsoft's
+ * code.
+ *
+ * Do not call smb_NegotiateExtendedSecurity(&secBlob, &secBlobLength);
+ */
smb_SetSMBDataLength(outp, secBlobLength + sizeof(smb_ServerGUID));
-
datap = smb_GetSMBData(outp, NULL);
+
memcpy(datap, &smb_ServerGUID, sizeof(smb_ServerGUID));
+ datap += sizeof(smb_ServerGUID);
if (secBlob) {
- datap += sizeof(smb_ServerGUID);
memcpy(datap, secBlob, secBlobLength);
free(secBlob);
+ datap += sizeof(secBlobLength);
}
} else {
- smb_SetSMBParmByte(outp, 16, 0); /* Encryption key length */
- smb_SetSMBDataLength(outp, 0); /* Perhaps we should specify 8 bytes anyway */
+ smb_SetSMBParmByte(outp, 16, 0);/* Challenge length */
+ smb_SetSMBDataLength(outp, smb_ServerDomainNameLength);
+ datap = smb_GetSMBData(outp, NULL);
+ /* the faux domain name */
+ cm_ClientStringToUtf8(smb_ServerDomainName, -1,
+ datap,
+ (int)(sizeof(outp->data)/sizeof(char) - (datap - outp->data)));
}
}
else if (v3ProtoIndex != -1) {
afs_uint32 rights;
afs_int32 mustFake = 0;
+ lock_ObtainWrite(&dscp->rw);
code = cm_FindACLCache(dscp, userp, &rights);
if (code == -1) {
- lock_ObtainWrite(&dscp->rw);
code = cm_SyncOp(dscp, NULL, userp, reqp, PRSFS_READ,
CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
- lock_ReleaseWrite(&dscp->rw);
if (code == CM_ERROR_NOACCESS) {
mustFake = 1;
code = 0;
}
}
+ lock_ReleaseWrite(&dscp->rw);
if (code)
goto cleanup;
reqp->relPathp = path;
reqp->tidPathp = tidPathp;
- code = cm_GetSCache(&patchp->fid, &scp, userp, reqp);
+ code = cm_GetSCache(&patchp->fid, &dscp->fid, &scp, userp, reqp);
reqp->relPathp = reqp->tidPathp = NULL;
if (code) {
if (dscp->fileType == CM_SCACHETYPE_MOUNTPOINT && !dscp->mountRootFid.volume)
code = CM_ERROR_NOSUCHFILE;
else if (dscp->fileType == CM_SCACHETYPE_DIRECTORY) {
- cm_buf_t *bp = buf_Find(dscp, &hzero);
+ cm_buf_t *bp = buf_Find(&dscp->fid, &hzero);
if (bp) {
buf_Release(bp);
bp = NULL;
lock_ReleaseMutex(&fidp->mx);
- /* CM_UNLOCK_BY_FID doesn't look at the process ID. We pass
- * in zero. */
+ /*
+ * CM_UNLOCK_FLAG_BY_FID doesn't look at the process ID.
+ * We pass in zero.
+ */
key = cm_GenerateKey(vcp->vcID, 0, fidp->fid);
lock_ObtainWrite(&scp->rw);
goto post_syncopdone;
}
- cm_UnlockByKey(scp, key, CM_UNLOCK_BY_FID, userp, &req);
+ cm_UnlockByKey(scp, key, CM_UNLOCK_FLAG_BY_FID, userp, &req);
cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_LOCK);
/* now copy the data */
memcpy(bufferp->datap + bufIndex, op, nbytes);
- buf_SetDirty(bufferp, bufIndex, nbytes, userp);
+ buf_SetDirty(bufferp, &req, bufIndex, nbytes, userp);
/* adjust counters, pointers, etc. */
op += nbytes;
lock_ReleaseWrite(&scp->rw);
cm_QueueBKGRequest(scp, cm_BkgStore, writeBackOffset.LowPart,
writeBackOffset.HighPart,
- smb_AsyncStoreSize, 0, userp);
+ smb_AsyncStoreSize, 0, userp, &req);
/* cm_SyncOpDone is called at the completion of cm_BkgStore */
}
} else {
*/
if (code) {
if (vcp->flags & SMB_VCFLAG_STATUS32) {
- smb_MapNTError(code, &NTStatus);
+ smb_MapNTError(code, &NTStatus, FALSE);
outWctp = outp->wctp;
smbp = (smb_t *) &outp->data;
if (code != CM_ERROR_PARTIALWRITE
if (vcp->flags & SMB_VCFLAG_STATUS32) {
unsigned long NTStatus;
- smb_MapNTError(code, &NTStatus);
+ smb_MapNTError(code, &NTStatus, FALSE);
outWctp = outp->wctp;
smbp = (smb_t *) &outp->data;
*outWctp++ = 0;
return;
}
-static void
-configureBackConnectionHostNames(void)
+void
+smb_configureBackConnectionHostNames(int bEnable)
{
/* On Windows XP SP2, Windows 2003 SP1, and all future Windows operating systems
* there is a restriction on the use of SMB authentication on loopback connections.
DWORD dwSize, dwAllocSize;
DWORD dwValue;
PBYTE pHostNames = NULL, pName = NULL;
+ PBYTE pOrigNames = NULL, pOrig = NULL;
BOOL bNameFound = FALSE;
+ DWORD dwLoopbackCheckDisabled;
+ DWORD dwszBackConnectionHostNames;
+ size_t nbsize = strlen(cm_NetbiosName) + 2;
+ size_t len;
static BOOL bLoopbackCheckDisabled = FALSE;
- /* BackConnectionHostNames and DisableLoopbackCheck */
+ /* DisableLoopbackCheck */
+ if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE,
+ "SYSTEM\\CurrentControlSet\\Control\\Lsa",
+ 0,
+ KEY_READ|KEY_WRITE,
+ &hkLsa) == ERROR_SUCCESS )
+ {
+ dwSize = sizeof(DWORD);
+ if ( RegQueryValueEx( hkLsa, "DisableLoopbackCheck", 0, &dwType, (LPBYTE)&dwLoopbackCheckDisabled, &dwSize) != ERROR_SUCCESS)
+ {
+ dwLoopbackCheckDisabled = 0;
+ }
+ } else {
+ hkLsa = INVALID_HANDLE_VALUE;
+ }
+
+ /* BackConnectionHostNames */
if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE,
"SYSTEM\\CurrentControlSet\\Control\\Lsa\\MSV1_0",
0,
dwAllocSize += 1 /* in case the source string is not nul terminated */
+ (DWORD)strlen(cm_NetbiosName) + 2;
pHostNames = malloc(dwAllocSize);
- dwSize = dwAllocSize;
+ dwszBackConnectionHostNames = dwAllocSize;
if (RegQueryValueEx( hkMSV10, "BackConnectionHostNames", 0, &dwType,
- pHostNames, &dwSize) == ERROR_SUCCESS)
+ pHostNames, &dwszBackConnectionHostNames) == ERROR_SUCCESS)
{
for (pName = pHostNames;
- (pName - pHostNames < (int) dwSize) && *pName ;
+ (pName - pHostNames < (int) dwszBackConnectionHostNames) && *pName ;
pName += strlen(pName) + 1)
{
if ( !stricmp(pName, cm_NetbiosName) ) {
}
}
- if ( !bNameFound ) {
- size_t size = strlen(cm_NetbiosName) + 2;
- if ( !pHostNames ) {
- pHostNames = malloc(size);
- pName = pHostNames;
- }
- StringCbCopyA(pName, size, cm_NetbiosName);
- pName += size - 1;
- *pName = '\0'; /* add a second nul terminator */
+ if ( bEnable ) {
+ if ( !bNameFound ) {
+ size_t size = strlen(cm_NetbiosName) + 2;
+ if ( !pHostNames ) {
+ pHostNames = malloc(size);
+ pName = pHostNames;
+ }
+ StringCbCopyA(pName, size, cm_NetbiosName);
+ pName += size - 1;
+ *pName = '\0'; /* add a second nul terminator */
- dwType = REG_MULTI_SZ;
- dwSize = (DWORD)(pName - pHostNames + 1);
- RegSetValueEx( hkMSV10, "BackConnectionHostNames", 0, dwType, pHostNames, dwSize);
+ dwType = REG_MULTI_SZ;
+ dwSize = (DWORD)(pName - pHostNames + 1);
+ RegSetValueEx( hkMSV10, "BackConnectionHostNames", 0, dwType, pHostNames, dwSize);
- if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE,
- "SYSTEM\\CurrentControlSet\\Control\\Lsa",
- 0,
- KEY_READ|KEY_WRITE,
- &hkLsa) == ERROR_SUCCESS )
- {
- dwSize = sizeof(DWORD);
- if ( RegQueryValueEx( hkLsa, "DisableLoopbackCheck", 0, &dwType, (LPBYTE)&dwValue, &dwSize) != ERROR_SUCCESS ||
- dwValue == 0 ) {
+ if ( hkLsa != INVALID_HANDLE_VALUE && !dwLoopbackCheckDisabled)
+ {
dwType = REG_DWORD;
dwSize = sizeof(DWORD);
- dwValue = 1;
- RegSetValueEx( hkLsa, "DisableLoopbackCheck", 0, dwType, (LPBYTE)&dwValue, dwSize);
+ dwLoopbackCheckDisabled = 1;
+ RegSetValueEx( hkLsa, "DisableLoopbackCheck", 0, dwType, (LPBYTE)&dwLoopbackCheckDisabled, dwSize);
if (RegCreateKeyEx( HKEY_LOCAL_MACHINE,
AFSREG_CLT_OPENAFS_SUBKEY,
bLoopbackCheckDisabled = TRUE;
RegCloseKey(hkClient);
}
- RegCloseKey(hkLsa);
}
+ } else if (!bLoopbackCheckDisabled && hkLsa != INVALID_HANDLE_VALUE) {
+ if (RegCreateKeyEx( HKEY_LOCAL_MACHINE,
+ AFSREG_CLT_OPENAFS_SUBKEY,
+ 0,
+ NULL,
+ REG_OPTION_NON_VOLATILE,
+ KEY_READ|KEY_WRITE,
+ NULL,
+ &hkClient,
+ NULL) == ERROR_SUCCESS) {
+
+ dwSize = sizeof(DWORD);
+ if ( RegQueryValueEx( hkClient, "RemoveDisableLoopbackCheck", 0, &dwType, (LPBYTE)&dwValue, &dwSize) == ERROR_SUCCESS &&
+ dwValue == 1 ) {
+ RegDeleteValue(hkLsa, "DisableLoopbackCheck");
+ }
+ }
+ RegDeleteValue(hkClient, "RemoveDisableLoopbackCheck");
+ RegCloseKey(hkClient);
}
- } else if (!bLoopbackCheckDisabled) {
- if (RegCreateKeyEx( HKEY_LOCAL_MACHINE,
- AFSREG_CLT_OPENAFS_SUBKEY,
- 0,
- NULL,
- REG_OPTION_NON_VOLATILE,
- KEY_READ|KEY_WRITE,
- NULL,
- &hkClient,
- NULL) == ERROR_SUCCESS) {
-
- dwSize = sizeof(DWORD);
- if ( RegQueryValueEx( hkClient, "RemoveDisableLoopbackCheck", 0, &dwType, (LPBYTE)&dwValue, &dwSize) == ERROR_SUCCESS &&
- dwValue == 1 ) {
- if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE,
- "SYSTEM\\CurrentControlSet\\Control\\Lsa",
- 0,
- KEY_READ|KEY_WRITE,
- &hkLsa) == ERROR_SUCCESS )
- {
+ } else {
+ /*
+ * Disable SMB. Start by removing the DisableLoopbackCheck value if present.
+ */
+ if (hkLsa != INVALID_HANDLE_VALUE) {
+ if (RegCreateKeyEx( HKEY_LOCAL_MACHINE,
+ AFSREG_CLT_OPENAFS_SUBKEY,
+ 0,
+ NULL,
+ REG_OPTION_NON_VOLATILE,
+ KEY_READ|KEY_WRITE,
+ NULL,
+ &hkClient,
+ NULL) == ERROR_SUCCESS) {
+
+ dwSize = sizeof(DWORD);
+ if ( RegQueryValueEx( hkClient, "RemoveDisableLoopbackCheck", 0, &dwType, (LPBYTE)&dwValue, &dwSize) == ERROR_SUCCESS &&
+ dwValue == 1 ) {
RegDeleteValue(hkLsa, "DisableLoopbackCheck");
- RegCloseKey(hkLsa);
}
}
RegDeleteValue(hkClient, "RemoveDisableLoopbackCheck");
RegCloseKey(hkClient);
}
+
+ /* Then remove our NetbiosName from the BackConnectionHostNames list */
+ if ( bNameFound ) {
+ /*
+ * we found our name so if the size of the value is smaller
+ * or equal to the length of our name alone, we are done.
+ */
+ if ( dwszBackConnectionHostNames <= nbsize ) {
+ RegDeleteValue( hkMSV10, "BackConnectionHostNames");
+ } else {
+ pOrigNames = pHostNames;
+ pHostNames = malloc(dwAllocSize);
+
+ pOrig = pOrigNames;
+ pName = pHostNames;
+ while (pOrig - pOrigNames < dwszBackConnectionHostNames) {
+ len = strlen(pOrig);
+ if ( stricmp(pOrig, cm_NetbiosName)) {
+ /* not our name */
+ StringCbCopyA(pName, dwAllocSize - (pName - pHostNames), pOrig);
+ pName += len + 1;
+ }
+ pOrig += len + 1;
+ }
+ *pName = '\0'; /* add a second nul terminator */
+ pName++;
+
+ dwType = REG_MULTI_SZ;
+ dwSize = (DWORD)(pName - pHostNames + 1);
+ RegSetValueEx( hkMSV10, "BackConnectionHostNames", 0, dwType, pHostNames, dwSize);
+ }
+ }
}
if (pHostNames) {
pHostNames = NULL;
}
+ if (pOrigNames) {
+ free(pOrigNames);
+ pOrigNames = NULL;
+ }
+
RegCloseKey(hkMSV10);
}
+
+ if ( hkLsa != INVALID_HANDLE_VALUE ) {
+ RegCloseKey(hkLsa);
+ }
}
-static void
-configureExtendedSMBSessionTimeouts(void)
+void
+smb_configureExtendedSMBSessionTimeouts(int bEnable)
{
/*
* In a Hot Fix to Windows 2003 SP2, the smb redirector was given the following
* new functionality:
*
- * [HKLM\SYSTEM\CurrentControlSet\Services\LanManWorkstation\Parameters]
+ * [HKLM\SYSTEM\CurrentControlSet\Services\LanmanWorkstation\Parameters]
* "ReconnectableServers" REG_MULTI_SZ
* "ExtendedSessTimeout" REG_DWORD (seconds)
* "ServersWithExtendedSessTimeout" REG_MULTI_SZ
* These values can be used to prevent the smb redirector from timing out
* smb connection to the afs smb server prematurely.
*/
- HKEY hkLanMan;
+ HKEY hkLanman;
DWORD dwType;
DWORD dwSize, dwAllocSize;
DWORD dwValue;
- PBYTE pHostNames = NULL, pName = NULL;
+ PBYTE pHostNames = NULL, pOrigNames = NULL, pName = NULL, pOrig = NULL;
BOOL bNameFound = FALSE;
+ DWORD dwszReconnectableServers;
+ DWORD dwszServersWithExtendedSessTimeout;
+ size_t nbsize = strlen(cm_NetbiosName) + 2;
+ size_t len;
if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE,
- "SYSTEM\\CurrentControlSet\\Services\\LanManWorkstation\\Parameters",
+ "SYSTEM\\CurrentControlSet\\Services\\LanmanWorkstation\\Parameters",
0,
KEY_READ|KEY_WRITE,
- &hkLanMan) == ERROR_SUCCESS )
+ &hkLanman) == ERROR_SUCCESS )
{
- if ((RegQueryValueEx( hkLanMan, "ReconnectableServers", 0,
+ if ((RegQueryValueEx( hkLanman, "ReconnectableServers", 0,
&dwType, NULL, &dwAllocSize) == ERROR_SUCCESS) &&
(dwType == REG_MULTI_SZ))
{
dwAllocSize += 1 /* in case the source string is not nul terminated */
+ (DWORD)strlen(cm_NetbiosName) + 2;
pHostNames = malloc(dwAllocSize);
- dwSize = dwAllocSize;
- if (RegQueryValueEx( hkLanMan, "ReconnectableServers", 0, &dwType,
- pHostNames, &dwSize) == ERROR_SUCCESS)
+ dwszReconnectableServers = dwAllocSize;
+ if (RegQueryValueEx( hkLanman, "ReconnectableServers", 0, &dwType,
+ pHostNames, &dwszReconnectableServers) == ERROR_SUCCESS)
{
for (pName = pHostNames;
- (pName - pHostNames < (int) dwSize) && *pName ;
+ (pName - pHostNames < (int) dwszReconnectableServers) && *pName ;
pName += strlen(pName) + 1)
{
if ( !stricmp(pName, cm_NetbiosName) ) {
}
}
- if ( !bNameFound ) {
- size_t size = strlen(cm_NetbiosName) + 2;
+ /*
+ * If our name was not found and we are enabling SMB,
+ * add our name to the current value.
+ */
+ if ( bEnable && !bNameFound ) {
if ( !pHostNames ) {
- pHostNames = malloc(size);
+ pHostNames = malloc(nbsize);
pName = pHostNames;
}
- StringCbCopyA(pName, size, cm_NetbiosName);
- pName += size - 1;
+ StringCbCopyA(pName, nbsize, cm_NetbiosName);
+ pName += nbsize - 1;
*pName = '\0'; /* add a second nul terminator */
dwType = REG_MULTI_SZ;
dwSize = (DWORD)(pName - pHostNames + 1);
- RegSetValueEx( hkLanMan, "ReconnectableServers", 0, dwType, pHostNames, dwSize);
+ RegSetValueEx( hkLanman, "ReconnectableServers", 0, dwType, pHostNames, dwSize);
+ }
+
+ /*
+ * If our name was found and we are disabling SMB,
+ * remove our name from the list and update the value.
+ * If our name is the only entry, remove the value.
+ */
+ if ( !bEnable && bNameFound ) {
+ /*
+ * we found our name so if the size of the value is smaller
+ * or equal to the length of our name alone, we are done.
+ */
+ if ( dwszReconnectableServers <= nbsize ) {
+ RegDeleteValue( hkLanman, "ReconnectableServers");
+ } else {
+ pOrigNames = pHostNames;
+ pHostNames = malloc(dwAllocSize);
+
+ pOrig = pOrigNames;
+ pName = pHostNames;
+ while (pOrig - pOrigNames <dwszReconnectableServers ) {
+ len = strlen(pOrig);
+ if ( stricmp(pOrig, cm_NetbiosName)) {
+ /* not our name */
+ StringCbCopyA(pName, dwAllocSize - (pName - pHostNames), pOrig);
+ pName += len + 1;
+ }
+ pOrig += len + 1;
+ }
+ *pName = '\0'; /* add a second nul terminator */
+ pName++;
+
+ dwType = REG_MULTI_SZ;
+ dwSize = (DWORD)(pName - pHostNames + 1);
+ RegSetValueEx( hkLanman, "ReconnectableServers", 0, dwType, pHostNames, dwSize);
+ }
}
if (pHostNames) {
pHostNames = NULL;
}
- if ((RegQueryValueEx( hkLanMan, "ServersWithExtendedSessTimeout", 0,
+ if (pOrigNames) {
+ free(pOrigNames);
+ pOrigNames = NULL;
+ }
+
+ if ((RegQueryValueEx( hkLanman, "ServersWithExtendedSessTimeout", 0,
&dwType, NULL, &dwAllocSize) == ERROR_SUCCESS) &&
(dwType == REG_MULTI_SZ))
{
dwAllocSize += 1 /* in case the source string is not nul terminated */
+ (DWORD)strlen(cm_NetbiosName) + 2;
pHostNames = malloc(dwAllocSize);
- dwSize = dwAllocSize;
- if (RegQueryValueEx( hkLanMan, "ServersWithExtendedSessTimeout", 0, &dwType,
- pHostNames, &dwSize) == ERROR_SUCCESS)
+ dwszServersWithExtendedSessTimeout = dwAllocSize;
+ if (RegQueryValueEx( hkLanman, "ServersWithExtendedSessTimeout", 0, &dwType,
+ pHostNames, &dwszServersWithExtendedSessTimeout) == ERROR_SUCCESS)
{
for (pName = pHostNames;
- (pName - pHostNames < (int) dwSize) && *pName ;
+ (pName - pHostNames < (int) dwszServersWithExtendedSessTimeout) && *pName ;
pName += strlen(pName) + 1)
{
if ( !stricmp(pName, cm_NetbiosName) ) {
}
}
- if ( !bNameFound ) {
+ /*
+ * If our name was not found and we are enabling SMB,
+ * add our name to the current value.
+ */
+ if ( bEnable && !bNameFound ) {
size_t size = strlen(cm_NetbiosName) + 2;
if ( !pHostNames ) {
pHostNames = malloc(size);
dwType = REG_MULTI_SZ;
dwSize = (DWORD)(pName - pHostNames + 1);
- RegSetValueEx( hkLanMan, "ServersWithExtendedSessTimeout", 0, dwType, pHostNames, dwSize);
+ RegSetValueEx( hkLanman, "ServersWithExtendedSessTimeout", 0, dwType, pHostNames, dwSize);
+ }
+
+ /*
+ * If our name was found and we are disabling SMB,
+ * remove our name from the list and update the value.
+ * If our name is the only entry, remove the value.
+ */
+ if ( !bEnable && bNameFound ) {
+ /*
+ * we found our name so if the size of the value is smaller
+ * or equal to the length of our name alone, we are done.
+ */
+ if ( dwszServersWithExtendedSessTimeout <= nbsize ) {
+ RegDeleteValue( hkLanman, "ServersWithExtendedSessTimeout");
+ } else {
+ pOrigNames = pHostNames;
+ pHostNames = malloc(dwAllocSize);
+
+ pOrig = pOrigNames;
+ pName = pHostNames;
+ while (pOrig - pOrigNames < dwszServersWithExtendedSessTimeout) {
+ len = strlen(pOrig);
+ if ( stricmp(pOrig, cm_NetbiosName)) {
+ /* not our name */
+ StringCbCopyA(pName, dwAllocSize - (pName - pHostNames), pOrig);
+ pName += len + 1;
+ }
+ pOrig += len + 1;
+ }
+ *pName = '\0'; /* add a second nul terminator */
+ pName++;
+
+ dwType = REG_MULTI_SZ;
+ dwSize = (DWORD)(pName - pHostNames + 1);
+ RegSetValueEx( hkLanman, "ServersWithExtendedSessTimeout", 0, dwType, pHostNames, dwSize);
+ }
}
if (pHostNames) {
pHostNames = NULL;
}
- if ((RegQueryValueEx( hkLanMan, "ExtendedSessTimeout", 0,
- &dwType, (LPBYTE)&dwValue, &dwAllocSize) != ERROR_SUCCESS) ||
- (dwType != REG_DWORD))
- {
- dwType = REG_DWORD;
- dwSize = sizeof(dwValue);
- dwValue = 300; /* 5 minutes */
- RegSetValueEx( hkLanMan, "ExtendedSessTimeout", 0, dwType, (const BYTE *)&dwValue, dwSize);
+ if (pOrigNames) {
+ free(pOrigNames);
+ pOrigNames = NULL;
+ }
+
+ if ( bEnable ) {
+ if ((RegQueryValueEx( hkLanman, "ExtendedSessTimeout", 0,
+ &dwType, (LPBYTE)&dwValue, &dwAllocSize) != ERROR_SUCCESS) ||
+ (dwType != REG_DWORD))
+ {
+ dwType = REG_DWORD;
+ dwSize = sizeof(dwValue);
+ dwValue = 300; /* 5 minutes */
+ RegSetValueEx( hkLanman, "ExtendedSessTimeout", 0, dwType, (const BYTE *)&dwValue, dwSize);
+ }
}
- RegCloseKey(hkLanMan);
+ RegCloseKey(hkLanman);
}
}
int lana_found = 0;
lana_number_t lanaNum;
+ if (!smb_Enabled)
+ return 0;
+
if (!locked)
lock_ObtainMutex(&smb_StartedLock);
int lpid;
thread_t phandle;
+ if (!smb_Enabled)
+ return;
+
if (!locked)
lock_ObtainMutex(&smb_StartedLock);
afsi_log("smb_StartListeners");
/* Ensure the AFS Netbios Name is registered to allow loopback access */
- configureBackConnectionHostNames();
+ smb_configureBackConnectionHostNames(TRUE);
/* Configure Extended SMB Session Timeouts */
if (msftSMBRedirectorSupportsExtendedTimeouts()) {
afsi_log("Microsoft SMB Redirector supports Extended Timeouts");
- configureExtendedSMBSessionTimeouts();
+ smb_configureExtendedSMBSessionTimeouts(TRUE);
}
smb_ListenerState = SMB_LISTENER_STARTED;
void smb_RestartListeners(int locked)
{
+ if (!smb_Enabled)
+ return;
+
if (!locked)
lock_ObtainMutex(&smb_StartedLock);
NCB *ncbp;
int lana, l;
+ if (!smb_Enabled)
+ return;
+
if (!locked)
lock_ObtainMutex(&smb_StartedLock);
char eventName[MAX_PATH];
int startListeners = 0;
+ if (!smb_Enabled)
+ return;
+
smb_MBfunc = aMBfunc;
smb_useV3 = useV3;
afs_uint32 i;
smb_vc_t *vcp;
+ if (!smb_Enabled)
+ return;
+
/*fprintf(stderr, "Entering smb_Shutdown\n");*/
/* setup the NCB system */
WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
+ if (!smb_Enabled)
+ goto done;
+
sprintf(output, "begin dumping smb_waitingLockRequest_t\r\n");
WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
-
for ( wlrp = smb_allWaitingLocks; wlrp; wlrp = (smb_waitingLockRequest_t *) osi_QNext(&wlrp->q)) {
smb_waitingLock_t *lockp;
sprintf(output, "done dumping DEAD smb_vc_t\r\n");
WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
+ done:
if (lock)
lock_ReleaseRead(&smb_rctLock);
return 0;
long smb_IsNetworkStarted(void)
{
long rc;
+
+ if (!smb_Enabled)
+ return 0;
+
lock_ObtainWrite(&smb_globalLock);
rc = (smb_ListenerState == SMB_LISTENER_STARTED && smbShutdownFlag == 0);
lock_ReleaseWrite(&smb_globalLock);