#include <afs/stds.h>
#include <windows.h>
+#pragma warning(push)
+#pragma warning(disable: 4005)
#include <ntstatus.h>
+#pragma warning(pop)
#include <stddef.h>
#include <stdlib.h>
#include <malloc.h>
osi_rwlock_t smb_globalLock;
osi_rwlock_t smb_rctLock;
osi_mutex_t smb_ListenerLock;
+osi_mutex_t smb_StartedLock;
-char smb_LANadapter;
+unsigned char smb_LANadapter = LANA_INVALID;
unsigned char smb_sharename[NCBNAMSZ+1] = {0};
+int smb_LanAdapterChangeDetected = 0;
+
+BOOL isGateway = FALSE;
/* for debugging */
long smb_maxObsConcurrentCalls=0;
EVENT_HANDLE **NCBreturns;
EVENT_HANDLE **NCBShutdown;
EVENT_HANDLE *smb_ServerShutdown;
+EVENT_HANDLE ListenerShutdown[256];
DWORD NCBsessions[NCB_MAX];
NCB *NCBs[NCB_MAX];
struct smb_packet *bufs[NCB_MAX];
int lanas[SESSION_MAX];
BOOL dead_sessions[SESSION_MAX];
LANA_ENUM lana_list;
-
/* for raw I/O */
osi_mutex_t smb_RawBufLock;
char *smb_RawBufs;
/* forward decl */
void smb_DispatchPacket(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp,
NCB *ncbp, raw_write_cont_t *rwcp);
-int smb_NetbiosInit(void);
+int smb_NetbiosInit(int);
#ifdef LOG_PACKET
void smb_LogPacket(smb_packet_t *packet);
{
time_t diff_t = unixTime - smb_localZero;
#if defined(DEBUG) && !defined(_USE_32BIT_TIME_T)
- osi_assert(diff_t < _UI32_MAX);
+ osi_assertx(diff_t < _UI32_MAX, "time_t > _UI32_MAX");
#endif
*dosUTimep = (afs_uint32)diff_t;
}
*/
NTSTATUS nts = STATUS_UNSUCCESSFUL, ntsEx = STATUS_UNSUCCESSFUL;
MSV1_0_LM20_CHALLENGE_REQUEST lsaReq;
- PMSV1_0_LM20_CHALLENGE_RESPONSE lsaResp;
+ PMSV1_0_LM20_CHALLENGE_RESPONSE lsaResp = NULL;
ULONG lsaRespSize = 0;
lsaReq.MessageType = MsV1_0Lm20ChallengeRequest;
&lsaResp,
&lsaRespSize,
&ntsEx);
- if (nts != STATUS_SUCCESS)
+ if (nts != STATUS_SUCCESS || ntsEx != STATUS_SUCCESS) {
osi_Log4(smb_logp,"MsV1_0Lm20ChallengeRequest failure: nts 0x%x ntsEx 0x%x respSize is %u needs %u",
nts, ntsEx, sizeof(lsaReq), lsaRespSize);
- osi_assert(nts == STATUS_SUCCESS); /* this had better work! */
+ afsi_log("MsV1_0Lm20ChallengeRequest failure: nts 0x%x ntsEx 0x%x respSize %u",
+ nts, ntsEx, lsaRespSize);
+ }
+ osi_assertx(nts == STATUS_SUCCESS, "LsaCallAuthenticationPackage failed"); /* this had better work! */
- memcpy(vcp->encKey, lsaResp->ChallengeToClient, MSV1_0_CHALLENGE_LENGTH);
- LsaFreeReturnBuffer(lsaResp);
+ if (ntsEx == STATUS_SUCCESS) {
+ memcpy(vcp->encKey, lsaResp->ChallengeToClient, MSV1_0_CHALLENGE_LENGTH);
+ LsaFreeReturnBuffer(lsaResp);
+ } else {
+ /*
+ * This will cause the subsequent authentication to fail but
+ * that is better than us dereferencing a NULL pointer and
+ * crashing.
+ */
+ memset(vcp->encKey, 0, MSV1_0_CHALLENGE_LENGTH);
+ }
}
else
memset(vcp->encKey, 0, MSV1_0_CHALLENGE_LENGTH);
userp = NULL;
lock_ObtainWrite(&smb_rctLock);
- osi_assert(tidp->refCount-- > 0);
+ osi_assertx(tidp->refCount-- > 0, "smb_tid_t refCount 0");
if (tidp->refCount == 0 && (tidp->delete)) {
ltpp = &tidp->vcp->tidsp;
for(tp = *ltpp; tp; ltpp = &tp->nextp, tp = *ltpp) {
if (tp == tidp)
break;
}
- osi_assert(tp != NULL);
+ osi_assertx(tp != NULL, "null smb_tid_t");
*ltpp = tp->nextp;
lock_FinalizeMutex(&tidp->mx);
userp = tidp->userp; /* remember to drop ref later */
time_t now = osi_Time();
lock_ObtainWrite(&smb_rctLock);
- osi_assert(unp->refCount-- > 0);
+ osi_assertx(unp->refCount-- > 0, "smb_username_t refCount 0");
if (unp->refCount == 0 && !(unp->flags & SMB_USERNAMEFLAG_AFSLOGON) &&
(unp->flags & SMB_USERNAMEFLAG_LOGOFF)) {
lupp = &usernamesp;
if (up == unp)
break;
}
- osi_assert(up != NULL);
+ osi_assertx(up != NULL, "null smb_username_t");
*lupp = up->nextp;
up->nextp = NULL; /* do not remove this */
lock_FinalizeMutex(&unp->mx);
smb_username_t *unp = NULL;
lock_ObtainWrite(&smb_rctLock);
- osi_assert(uidp->refCount-- > 0);
+ osi_assertx(uidp->refCount-- > 0, "smb_user_t refCount 0");
if (uidp->refCount == 0) {
lupp = &uidp->vcp->usersp;
for(up = *lupp; up; lupp = &up->nextp, up = *lupp) {
if (up == uidp)
break;
}
- osi_assert(up != NULL);
+ osi_assertx(up != NULL, "null smb_user_t");
*lupp = up->nextp;
lock_FinalizeMutex(&uidp->mx);
unp = uidp->unp;
lock_ObtainMutex(&fidp->mx);
lock_ObtainWrite(&smb_rctLock);
- osi_assert(fidp->refCount-- > 0);
+ osi_assertx(fidp->refCount-- > 0, "smb_fid_t refCount 0");
if (fidp->refCount == 0 && (fidp->delete)) {
vcp = fidp->vcp;
fidp->vcp = NULL;
lock_ObtainMutex(&scp->mx);
scp->flags &= ~CM_SCACHEFLAG_SMB_FID;
lock_ReleaseMutex(&scp->mx);
- osi_Log2(afsd_logp,"smb_ReleaseFID fidp 0x%p scp 0x%p", fidp, scp);
+ osi_Log2(smb_logp,"smb_ReleaseFID fidp 0x%p scp 0x%p", fidp, scp);
fidp->scp = NULL;
}
userp = fidp->userp;
}
if (_stricmp(shareName, "IPC$") == 0 ||
+ _stricmp(shareName, "srvsvc") == 0 ||
+ _stricmp(shareName, "wkssvc") == 0 ||
_stricmp(shareName, SMB_IOCTL_FILENAME_NOSLASH) == 0 ||
_stricmp(shareName, "DESKTOP.INI") == 0
) {
return 0;
}
+ /* Check for volume references
+ *
+ * They look like <cell>{%,#}<volume>
+ */
+ if (strchr(shareName, '%') != NULL ||
+ strchr(shareName, '#') != NULL) {
+ char pathstr[CELL_MAXNAMELEN + VL_MAXNAMELEN + 1 + CM_PREFIX_VOL_CCH];
+ /* make room for '/@vol:' + mountchar + NULL terminator*/
+
+ osi_Log1(smb_logp, "smb_FindShare found volume reference [%s]",
+ osi_LogSaveString(smb_logp, shareName));
+
+ snprintf(pathstr, sizeof(pathstr)/sizeof(char),
+ "/" CM_PREFIX_VOL "%s", shareName);
+ pathstr[sizeof(pathstr)/sizeof(char) - 1] = '\0';
+ len = strlen(pathstr) + 1;
+
+ *pathNamep = malloc(len);
+ if (*pathNamep) {
+ strcpy(*pathNamep, pathstr);
+ strlwr(*pathNamep);
+ osi_Log1(smb_logp, " returning pathname [%s]",
+ osi_LogSaveString(smb_logp, *pathNamep));
+
+ return 1;
+ } else {
+ return 0;
+ }
+ }
+
code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_OPENAFS_SUBKEY "\\Submounts",
0, KEY_QUERY_VALUE, &parmKey);
if (code == ERROR_SUCCESS) {
{
lock_ObtainWrite(&smb_globalLock);
lock_ObtainMutex(&dsp->mx);
- osi_Log3(afsd_logp,"smb_DeleteDirSearch cookie %d dsp 0x%p scp 0x%p",
+ osi_Log3(smb_logp,"smb_DeleteDirSearch cookie %d dsp 0x%p scp 0x%p",
dsp->cookie, dsp, dsp->scp);
dsp->flags |= SMB_DIRSEARCH_DELETE;
if (dsp->scp != NULL) {
cm_scache_t *scp = NULL;
lock_ObtainMutex(&dsp->mx);
- osi_assert(dsp->refCount-- > 0);
+ osi_assertx(dsp->refCount-- > 0, "cm_scache_t refCount 0");
if (dsp->refCount == 0 && (dsp->flags & SMB_DIRSEARCH_DELETE)) {
if (&dsp->q == (osi_queue_t *) smb_lastDirSearchp)
smb_lastDirSearchp = (smb_dirSearch_t *) osi_QPrev(&smb_lastDirSearchp->q);
lock_ReleaseMutex(&dsp->mx);
lock_FinalizeMutex(&dsp->mx);
scp = dsp->scp;
- osi_Log3(afsd_logp,"smb_ReleaseDirSearch cookie %d dsp 0x%p scp 0x%p",
+ osi_Log3(smb_logp,"smb_ReleaseDirSearch cookie %d dsp 0x%p scp 0x%p",
dsp->cookie, dsp, scp);
free(dsp);
} else {
counter = 0;
/* what's the biggest ID allowed in this version of the protocol */
+ /* TODO: do we really want a non v3 dir search request to wrap
+ smb_dirSearchCounter? */
maxAllowed = isV3 ? 65535 : 255;
if (smb_dirSearchCounter > maxAllowed)
smb_dirSearchCounter = 1;
if (!smb_lastDirSearchp)
smb_lastDirSearchp = (smb_dirSearch_t *) &dsp->q;
- osi_Log2(afsd_logp,"smb_NewDirSearch cookie %d dsp 0x%p",
+ osi_Log2(smb_logp,"smb_NewDirSearch cookie %d dsp 0x%p",
dsp->cookie, dsp);
break;
}
tbp->spacep = NULL;
}
- osi_assert(tbp->magic == SMB_PACKETMAGIC);
+ osi_assertx(tbp->magic == SMB_PACKETMAGIC, "invalid smb_packet_t magic");
return tbp;
}
tbp->magic = SMB_NCBMAGIC;
}
- osi_assert(tbp->magic == SMB_NCBMAGIC);
+ osi_assertx(tbp->magic == SMB_NCBMAGIC, "invalid smb_packet_t magic");
memset(&tbp->ncb, 0, sizeof(NCB));
ncbp = &tbp->ncb;
void smb_FreePacket(smb_packet_t *tbp)
{
smb_vc_t * vcp = NULL;
- osi_assert(tbp->magic == SMB_PACKETMAGIC);
+ osi_assertx(tbp->magic == SMB_PACKETMAGIC, "invalid smb_packet_t magic");
lock_ObtainWrite(&smb_globalLock);
tbp->nextp = smb_packetFreeListp;
smb_ncb_t *tbp;
tbp = (smb_ncb_t *) bufferp;
- osi_assert(tbp->magic == SMB_NCBMAGIC);
+ osi_assertx(tbp->magic == SMB_NCBMAGIC, "invalid smb_packet_t magic");
lock_ObtainWrite(&smb_globalLock);
tbp->nextp = smb_ncbFreeListp;
outp->res[1] = inSmbp->res[1];
op->inCom = inSmbp->com;
}
- outp->reb = SMB_FLAGS_SERVER_TO_CLIENT | SMB_FLAGS_CANONICAL_PATHNAMES;
+ outp->reb = SMB_FLAGS_SERVER_TO_CLIENT;
+#ifdef SEND_CANONICAL_PATHNAMES
+ outp->reb |= SMB_FLAGS_CANONICAL_PATHNAMES;
+#endif
outp->flg2 = SMB_FLAGS2_KNOWS_LONG_NAMES;
/* copy fields in generic packet area */
else if (code == CM_ERROR_READONLY) {
NTStatus = 0xC00000A2L; /* Write protected */
}
- else if (code == CM_ERROR_NOSUCHFILE) {
+ else if (code == CM_ERROR_NOSUCHFILE ||
+ code == CM_ERROR_BPLUS_NOMATCH) {
NTStatus = 0xC000000FL; /* No such file */
}
else if (code == CM_ERROR_NOSUCHPATH) {
NTStatus = 0xC09820FBL; /* SMB use standard */
}
else if (code == CM_ERROR_QUOTA) {
-#ifdef COMMENT
NTStatus = 0xC0000044L; /* Quota exceeded */
-#else
- NTStatus = 0xC000007FL; /* Disk full */
-#endif
}
else if (code == CM_ERROR_SPACE) {
NTStatus = 0xC000007FL; /* Disk full */
else if (code == CM_ERROR_PATH_NOT_COVERED) {
NTStatus = 0xC0000257L; /* Path Not Covered */
}
-#ifdef COMMENT
else if (code == CM_ERROR_ALLBUSY) {
- NTStatus = 0xC00000BFL; /* Network Busy */
+ NTStatus = 0xC000022DL; /* Retry */
}
else if (code == CM_ERROR_ALLOFFLINE || code == CM_ERROR_ALLDOWN) {
- NTStatus = 0xC0000350L; /* Remote Host Down */
- }
-#else
- /* we do not want to be telling the SMB/CIFS client that
- * the AFS Client Service is busy or down.
- */
- else if (code == CM_ERROR_ALLBUSY ||
- code == CM_ERROR_ALLOFFLINE ||
- code == CM_ERROR_ALLDOWN) {
NTStatus = 0xC00000BEL; /* Bad Network Path */
- }
-#endif
- else if (code == RXKADUNKNOWNKEY) {
- NTStatus = 0xC0000322L; /* Bad Kerberos key */
- } else {
+ }
+ else if (code >= ERROR_TABLE_BASE_RXK && code < ERROR_TABLE_BASE_RXK + 256) {
+ NTStatus = 0xC0000322L; /* No Kerberos key */
+ }
+ else if (code == CM_ERROR_BAD_LEVEL) {
+ NTStatus = 0xC0000148L; /* Invalid Level */
+ }
+ else if (code == CM_ERROR_RANGE_NOT_LOCKED) {
+ NTStatus = 0xC000007EL; /* Range Not Locked */
+ }
+ else {
NTStatus = 0xC0982001L; /* SMB non-specific error */
}
class = 3;
error = 19; /* read only */
}
- else if (code == CM_ERROR_NOSUCHFILE) {
+ else if (code == CM_ERROR_NOSUCHFILE ||
+ code == CM_ERROR_BPLUS_NOMATCH) {
class = 1;
error = 2; /* ENOENT! */
}
if (!fidp)
goto send1;
+ if (fidp->scp && (fidp->scp->flags & CM_SCACHEFLAG_DELETED)) {
+ smb_CloseFID(vcp, fidp, NULL, 0);
+ code = CM_ERROR_NOSUCHFILE;
+ goto send1a;
+ }
+
+
pid = ((smb_t *) inp)->pid;
{
LARGE_INTEGER LOffset, LLength;
if (wl->state == SMB_WAITINGLOCKSTATE_DONE)
continue;
- osi_assert(wl->state != SMB_WAITINGLOCKSTATE_ERROR);
+ osi_assertx(wl->state != SMB_WAITINGLOCKSTATE_ERROR, "!SMB_WAITINGLOCKSTATE_ERROR");
/* wl->state is either _DONE or _WAITING. _ERROR
would no longer be on the queue. */
wlRequest);
scp = wlRequest->scp;
- osi_Log2(afsd_logp,"smb_WaitingLocksDaemon wlRequest 0x%p scp 0x%p", wlRequest, scp);
+ osi_Log2(smb_logp,"smb_WaitingLocksDaemon wlRequest 0x%p scp 0x%p", wlRequest, scp);
cm_InitReq(&req);
smb_tid_t *tidp;
smb_user_t *uidp;
unsigned short newTid;
- char shareName[256];
+ char shareName[AFSPATHMAX];
char *sharePath;
int shareFound;
char *tp;
/* mask starts out all blanks */
memset(maskp, ' ', 11);
+ maskp[11] = '\0';
/* find last backslash, or use whole thing if there is none */
tp = strrchr(pathp, '\\');
- if (!tp) tp = pathp;
- else tp++; /* skip slash */
+ if (!tp)
+ tp = pathp;
+ else
+ tp++; /* skip slash */
up = maskp;
/* names starting with a dot are illegal */
- if (*tp == '.') valid8Dot3 = 0;
+ if (*tp == '.')
+ valid8Dot3 = 0;
for(i=0;; i++) {
tc = *tp++;
- if (tc == 0) return valid8Dot3;
- if (tc == '.' || tc == '"') break;
- if (i < 8) *up++ = tc;
- else valid8Dot3 = 0;
+ if (tc == 0)
+ return valid8Dot3;
+ if (tc == '.' || tc == '"')
+ break;
+ if (i < 8)
+ *up++ = tc;
+ else
+ valid8Dot3 = 0;
}
/* if we get here, tp point after the dot */
{
unsigned char *pathp;
unsigned char *tp;
- unsigned char mask[11];
+ unsigned char mask[12];
unsigned char *statBlockp;
unsigned char initStatBlock[21];
int statLen;
/* pull pathname and stat block out of request */
tp = smb_GetSMBData(inp, NULL);
pathp = smb_ParseASCIIBlock(tp, (char **) &tp);
- osi_assert(pathp != NULL);
+ osi_assertx(pathp != NULL, "null path");
if (smb_StoreAnsiFilenames)
OemToChar(pathp,pathp);
statBlockp = smb_ParseVblBlock(tp, (char **) &tp, &statLen);
- osi_assert(statBlockp != NULL);
+ osi_assertx(statBlockp != NULL, "null statBlock");
if (statLen == 0) {
statBlockp = initStatBlock;
statBlockp[0] = 8;
return 0;
}
-long smb_ApplyDirListPatches(smb_dirListPatch_t **dirPatchespp,
- cm_user_t *userp, cm_req_t *reqp)
+static long
+smb_ApplyDirListPatches(smb_dirListPatch_t **dirPatchespp,
+ char * tidPathp, char * relPathp,
+ cm_user_t *userp, cm_req_t *reqp)
{
long code = 0;
cm_scache_t *scp;
char attr;
smb_dirListPatch_t *patchp;
smb_dirListPatch_t *npatchp;
+ char path[AFSPATHMAX];
for (patchp = *dirPatchespp; patchp; patchp =
(smb_dirListPatch_t *) osi_QNext(&patchp->q)) {
dptr = patchp->dptr;
+ snprintf(path, AFSPATHMAX, "%s\\%s", relPathp ? relPathp : "", patchp->dep->name);
+ reqp->relPathp = path;
+ reqp->tidPathp = tidPathp;
+
code = cm_GetSCache(&patchp->fid, &scp, userp, reqp);
+ reqp->relPathp = reqp->tidPathp = NULL;
+
if (code) {
if( patchp->flags & SMB_DIRLISTPATCH_DOTFILE )
*dptr++ = SMB_ATTR_HIDDEN;
char *tp;
long code = 0;
char *pathp;
- cm_dirEntry_t *dep;
+ cm_dirEntry_t *dep = 0;
int maxCount;
smb_dirListPatch_t *dirListPatchesp;
smb_dirListPatch_t *curPatchp;
char shortName[13];
char *actualName;
char *shortNameEnd;
- char mask[11];
+ char mask[12];
int returnedNames;
long nextEntryCookie;
int numDirChunks; /* # of 32 byte dir chunks in this entry */
int starPattern;
int rootPath = 0;
int caseFold;
- char *tidPathp;
+ char *tidPathp = 0;
cm_req_t req;
cm_fid_t fid;
int fileType;
dsp = smb_NewDirSearch(0);
dsp->attribute = attribute;
smb_Get8Dot3MaskFromPath(mask, pathp);
- memcpy(dsp->mask, mask, 11);
+ memcpy(dsp->mask, mask, 12);
/* track if this is likely to match a lot of entries */
if (smb_IsStarMask(mask))
*/
memcpy(&clientCookie, &inCookiep[17], 4);
- memcpy(mask, dsp->mask, 11);
+ memcpy(mask, dsp->mask, 12);
/* assume we're doing a star match if it has continued for more
* than one call.
lock_ObtainMutex(&dsp->mx);
if (dsp->scp) {
scp = dsp->scp;
- osi_Log2(afsd_logp,"smb_ReceiveCoreSearchDir (1) dsp 0x%p scp 0x%p", dsp, scp);
+ osi_Log2(smb_logp,"smb_ReceiveCoreSearchDir (1) dsp 0x%p scp 0x%p", dsp, scp);
cm_HoldSCache(scp);
code = 0;
} else {
smb_ReleaseDirSearch(dsp);
return CM_ERROR_NOFILES;
}
+ strcpy(dsp->tidPath, tidPathp ? tidPathp : "/");
+ strcpy(dsp->relPath, spacep->data);
+
code = cm_NameI(cm_data.rootSCachep, spacep->data,
caseFold | CM_FLAG_FOLLOW, userp, tidPathp, &req, &scp);
if (code == 0) {
#ifdef DFS_SUPPORT
if (scp->fileType == CM_SCACHETYPE_DFSLINK) {
+ int pnc = cm_VolStatus_Notify_DFS_Mapping(scp, tidPathp, spacep->data);
cm_ReleaseSCache(scp);
lock_ReleaseMutex(&dsp->mx);
cm_ReleaseUser(userp);
smb_DeleteDirSearch(dsp);
smb_ReleaseDirSearch(dsp);
- if ( WANTS_DFS_PATHNAMES(inp) )
+ if ( WANTS_DFS_PATHNAMES(inp) || pnc )
return CM_ERROR_PATH_NOT_COVERED;
else
return CM_ERROR_BADSHARENAME;
#endif /* DFS_SUPPORT */
dsp->scp = scp;
- osi_Log2(afsd_logp,"smb_ReceiveCoreSearchDir (2) dsp 0x%p scp 0x%p", dsp, scp);
+ osi_Log2(smb_logp,"smb_ReceiveCoreSearchDir (2) dsp 0x%p scp 0x%p", dsp, scp);
/* we need one hold for the entry we just stored into,
* and one for our own processing. When we're done with this
* function, we'll drop the one for our own processing.
* the status info for files in the dir.
*/
if (starPattern) {
- smb_ApplyDirListPatches(&dirListPatchesp, userp, &req);
+ smb_ApplyDirListPatches(&dirListPatchesp, dsp->tidPath, dsp->relPath, userp, &req);
lock_ObtainMutex(&scp->mx);
if ((dsp->flags & SMB_DIRSEARCH_BULKST) &&
LargeIntegerGreaterThanOrEqualTo(thyper,
scp->bulkStatProgress)) {
/* Don't bulk stat if risking timeout */
int now = GetTickCount();
- if (now - req.startTime > RDRtimeout) {
+ if (now - req.startTime > RDRtimeout * 1000) {
scp->bulkStatProgress = thyper;
scp->flags &= ~CM_SCACHEFLAG_BULKSTATTING;
dsp->flags &= ~SMB_DIRSEARCH_BULKST;
"has filetype %d", osi_LogSaveString(smb_logp, dep->name),
fileType);
if (fileType == CM_SCACHETYPE_DIRECTORY ||
+ fileType == CM_SCACHETYPE_MOUNTPOINT ||
fileType == CM_SCACHETYPE_DFSLINK ||
fileType == CM_SCACHETYPE_INVALID)
osi_Log0(smb_logp, "SMB search dir skipping directory or bad link");
/* apply and free last set of patches; if not doing a star match, this
* will be empty, but better safe (and freeing everything) than sorry.
*/
- smb_ApplyDirListPatches(&dirListPatchesp, userp, &req);
+ smb_ApplyDirListPatches(&dirListPatchesp, dsp->tidPath, dsp->relPath, userp, &req);
/* special return code for unsuccessful search */
if (code == 0 && dataLength < 21 && returnedNames == 0)
* Deduct for them and fill in the length field.
*/
temp -= 3; /* deduct vbl block info */
- osi_assert(temp == (43 * returnedNames));
+ osi_assertx(temp == (43 * returnedNames), "unexpected data length");
origOp[1] = (char)(temp & 0xff);
origOp[2] = (char)((temp>>8) & 0xff);
if (returnedNames == 0)
#ifdef DFS_SUPPORT
if (newScp->fileType == CM_SCACHETYPE_DFSLINK) {
+ int pnc = cm_VolStatus_Notify_DFS_Mapping(newScp, tidPathp, pathp);
cm_ReleaseSCache(newScp);
cm_ReleaseUser(userp);
- if ( WANTS_DFS_PATHNAMES(inp) )
+ if ( WANTS_DFS_PATHNAMES(inp) || pnc )
return CM_ERROR_PATH_NOT_COVERED;
else
return CM_ERROR_BADSHARENAME;
#ifdef DFS_SUPPORT
if (newScp->fileType == CM_SCACHETYPE_DFSLINK) {
+ int pnc = cm_VolStatus_Notify_DFS_Mapping(newScp, tidPathp, pathp);
cm_ReleaseSCache(newScp);
cm_ReleaseUser(userp);
- if ( WANTS_DFS_PATHNAMES(inp) )
+ if ( WANTS_DFS_PATHNAMES(inp) || pnc )
return CM_ERROR_PATH_NOT_COVERED;
else
return CM_ERROR_BADSHARENAME;
if (code == 0) {
#ifdef DFS_SUPPORT
if (dscp->fileType == CM_SCACHETYPE_DFSLINK) {
- if ( WANTS_DFS_PATHNAMES(inp) )
+ int pnc = cm_VolStatus_Notify_DFS_Mapping(dscp, tidPathp, spacep->data);
+ if ( WANTS_DFS_PATHNAMES(inp) || pnc )
return CM_ERROR_PATH_NOT_COVERED;
else
return CM_ERROR_BADSHARENAME;
#ifdef DFS_SUPPORT
if (newScp->fileType == CM_SCACHETYPE_DFSLINK) {
+ int pnc = cm_VolStatus_Notify_DFS_Mapping(newScp, tidPathp, pathp);
cm_ReleaseSCache(newScp);
cm_ReleaseUser(userp);
- if ( WANTS_DFS_PATHNAMES(inp) )
+ if ( WANTS_DFS_PATHNAMES(inp) || pnc )
return CM_ERROR_PATH_NOT_COVERED;
else
return CM_ERROR_BADSHARENAME;
#ifdef DFS_SUPPORT
if (scp->fileType == CM_SCACHETYPE_DFSLINK) {
+ int pnc = cm_VolStatus_Notify_DFS_Mapping(scp, tidPathp, pathp);
cm_ReleaseSCache(scp);
cm_ReleaseUser(userp);
- if ( WANTS_DFS_PATHNAMES(inp) )
+ if ( WANTS_DFS_PATHNAMES(inp) || pnc )
return CM_ERROR_PATH_NOT_COVERED;
else
return CM_ERROR_BADSHARENAME;
}
fidp = smb_FindFID(vcp, 0, SMB_FLAG_CREATE);
- osi_assert(fidp);
+ osi_assertx(fidp, "null smb_fid_t");
/* save a pointer to the vnode */
fidp->scp = scp;
- osi_Log2(afsd_logp,"smb_ReceiveCoreOpen fidp 0x%p scp 0x%p", fidp, scp);
+ osi_Log2(smb_logp,"smb_ReceiveCoreOpen fidp 0x%p scp 0x%p", fidp, scp);
lock_ObtainMutex(&scp->mx);
scp->flags |= CM_SCACHEFLAG_SMB_FID;
lock_ReleaseMutex(&scp->mx);
lock_ObtainMutex(&fidp->mx);
if ((share & 0xf) == 0)
- fidp->flags |= SMB_FID_OPENREAD;
+ fidp->flags |= SMB_FID_OPENREAD_LISTDIR;
else if ((share & 0xf) == 1)
fidp->flags |= SMB_FID_OPENWRITE;
else
- fidp->flags |= (SMB_FID_OPENREAD | SMB_FID_OPENWRITE);
+ fidp->flags |= (SMB_FID_OPENREAD_LISTDIR | SMB_FID_OPENWRITE);
lock_ReleaseMutex(&fidp->mx);
lock_ObtainMutex(&scp->mx);
char *maskp; /* pointer to the star pattern */
int flags;
int any;
+ cm_dirEntryList_t * matches;
} smb_unlinkRock_t;
int smb_UnlinkProc(cm_scache_t *dscp, cm_dirEntry_t *dep, void *vrockp, osi_hyper_t *offp)
match = smb_V3MatchMask(matchName, rockp->maskp, caseFold | CM_FLAG_CASEFOLD);
}
if (match) {
- osi_Log1(smb_logp, "Unlinking %s",
+ osi_Log1(smb_logp, "Found match %s",
osi_LogSaveString(smb_logp, matchName));
- code = cm_Unlink(dscp, dep->name, rockp->userp, rockp->reqp);
- if (code == 0 && (dscp->flags & CM_SCACHEFLAG_ANYWATCH))
- smb_NotifyChange(FILE_ACTION_REMOVED,
- FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_CREATION,
- dscp, dep->name, NULL, TRUE);
- if (code == 0) {
- rockp->any = 1;
- /* If we made a case sensitive exact match, we might as well quit now. */
- if (!(rockp->flags & SMB_MASKFLAG_CASEFOLD) && !strcmp(matchName, rockp->maskp))
- code = CM_ERROR_STOPNOW;
- }
+ cm_DirEntryListAdd(dep->name, &rockp->matches);
+
+ rockp->any = 1;
+
+ /* If we made a case sensitive exact match, we might as well quit now. */
+ if (!(rockp->flags & SMB_MASKFLAG_CASEFOLD) && !strcmp(matchName, rockp->maskp))
+ code = CM_ERROR_STOPNOW;
+ else
+ code = 0;
}
else code = 0;
#ifdef DFS_SUPPORT
if (dscp->fileType == CM_SCACHETYPE_DFSLINK) {
+ int pnc = cm_VolStatus_Notify_DFS_Mapping(dscp, tidPathp,spacep->data);
cm_ReleaseSCache(dscp);
cm_ReleaseUser(userp);
- if ( WANTS_DFS_PATHNAMES(inp) )
+ if ( WANTS_DFS_PATHNAMES(inp) || pnc )
return CM_ERROR_PATH_NOT_COVERED;
else
return CM_ERROR_BADSHARENAME;
rock.reqp = &req;
rock.dscp = dscp;
rock.vcp = vcp;
+ rock.matches = NULL;
/* Now, if we aren't dealing with a wildcard match, we first try an exact
* match. If that fails, we do a case insensitve match.
if (code == CM_ERROR_STOPNOW)
code = 0;
+ if (code == 0 && rock.matches) {
+ cm_dirEntryList_t * entry;
+
+ for (entry = rock.matches; code == 0 && entry; entry = entry->nextp) {
+
+ osi_Log1(smb_logp, "Unlinking %s",
+ osi_LogSaveString(smb_logp, entry->name));
+ code = cm_Unlink(dscp, entry->name, userp, &req);
+
+ if (code == 0 && (dscp->flags & CM_SCACHEFLAG_ANYWATCH))
+ smb_NotifyChange(FILE_ACTION_REMOVED,
+ FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_CREATION,
+ dscp, entry->name, NULL, TRUE);
+ }
+ }
+
+ cm_DirEntryListFree(&rock.matches);
+
cm_ReleaseUser(userp);
cm_ReleaseSCache(dscp);
char *maskp; /* pointer to star pattern of old file name */
int flags; /* tilde, casefold, etc */
char *newNamep; /* ptr to the new file's name */
+ char oldName[MAX_PATH];
int any;
} smb_renameRock_t;
cm_Gen8Dot3Name(dep, shortName, NULL);
match = smb_V3MatchMask(shortName, rockp->maskp, caseFold);
}
+
if (match) {
rockp->any = 1;
-
- code = cm_Rename(rockp->odscp, dep->name,
- rockp->ndscp, rockp->newNamep, rockp->userp,
- rockp->reqp);
- /* if the call worked, stop doing the search now, since we
- * really only want to rename one file.
- */
- osi_Log1(smb_logp, "cm_Rename returns %ld", code);
- if (code == 0)
+ strncpy(rockp->oldName, dep->name, sizeof(rockp->oldName)/sizeof(char) - 1);
+ rockp->oldName[sizeof(rockp->oldName)/sizeof(char) - 1] = '\0';
code = CM_ERROR_STOPNOW;
- }
- else
+ } else {
code = 0;
+ }
return code;
}
#ifdef DFS_SUPPORT
if (oldDscp->fileType == CM_SCACHETYPE_DFSLINK) {
+ int pnc = cm_VolStatus_Notify_DFS_Mapping(oldDscp, tidPathp, spacep->data);
cm_ReleaseSCache(oldDscp);
cm_ReleaseUser(userp);
- if ( WANTS_DFS_PATHNAMES(inp) )
+ if ( WANTS_DFS_PATHNAMES(inp) || pnc )
return CM_ERROR_PATH_NOT_COVERED;
else
return CM_ERROR_BADSHARENAME;
#ifdef DFS_SUPPORT
if (newDscp->fileType == CM_SCACHETYPE_DFSLINK) {
+ int pnc = cm_VolStatus_Notify_DFS_Mapping(newDscp, tidPathp, spacep->data);
cm_ReleaseSCache(oldDscp);
cm_ReleaseSCache(newDscp);
cm_ReleaseUser(userp);
- if ( WANTS_DFS_PATHNAMES(inp) )
+ if ( WANTS_DFS_PATHNAMES(inp) || pnc )
return CM_ERROR_PATH_NOT_COVERED;
else
return CM_ERROR_BADSHARENAME;
rock.maskp = oldLastNamep;
rock.flags = ((strchr(oldLastNamep, '~') != NULL) ? SMB_MASKFLAG_TILDE : 0);
rock.newNamep = newLastNamep;
+ rock.oldName[0] = '\0';
rock.any = 0;
/* Check if the file already exists; if so return error */
code = cm_Lookup(newDscp,newLastNamep,CM_FLAG_CHECKPATH,userp,&req,&tmpscp);
- if ((code != CM_ERROR_NOSUCHFILE) && (code != CM_ERROR_NOSUCHPATH) && (code != CM_ERROR_NOSUCHVOLUME) ) {
+ if ((code != CM_ERROR_NOSUCHFILE) && (code != CM_ERROR_BPLUS_NOMATCH) &&
+ (code != CM_ERROR_NOSUCHPATH) && (code != CM_ERROR_NOSUCHVOLUME) )
+ {
osi_Log2(smb_logp, " lookup returns %ld for [%s]", code,
- osi_LogSaveString(afsd_logp, newLastNamep));
+ osi_LogSaveString(smb_logp, newLastNamep));
/* Check if the old and the new names differ only in case. If so return
* success, else return CM_ERROR_EXISTS
}
osi_Log1(smb_logp, "smb_RenameProc returns %ld", code);
- if (code == CM_ERROR_STOPNOW)
- code = 0;
- else if (code == 0)
+ if (code == CM_ERROR_STOPNOW && rock.oldName[0] != '\0') {
+ code = cm_Rename(rock.odscp, rock.oldName,
+ rock.ndscp, rock.newNamep, rock.userp,
+ rock.reqp);
+ /* if the call worked, stop doing the search now, since we
+ * really only want to rename one file.
+ */
+ osi_Log1(smb_logp, "cm_Rename returns %ld", code);
+ } else if (code == 0) {
code = CM_ERROR_NOSUCHFILE;
+ }
/* Handle Change Notification */
/*
* Being lazy, not distinguishing between files and dirs in this
* filter, since we'd have to do a lookup.
*/
- filter = FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_DIR_NAME;
- if (oldDscp == newDscp) {
- if (oldDscp->flags & CM_SCACHEFLAG_ANYWATCH)
- smb_NotifyChange(FILE_ACTION_RENAMED_OLD_NAME,
- filter, oldDscp, oldLastNamep,
- newLastNamep, TRUE);
- } else {
- if (oldDscp->flags & CM_SCACHEFLAG_ANYWATCH)
- smb_NotifyChange(FILE_ACTION_RENAMED_OLD_NAME,
- filter, oldDscp, oldLastNamep,
- NULL, TRUE);
- if (newDscp->flags & CM_SCACHEFLAG_ANYWATCH)
- smb_NotifyChange(FILE_ACTION_RENAMED_NEW_NAME,
- filter, newDscp, newLastNamep,
- NULL, TRUE);
+ if (code == 0) {
+ filter = FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_DIR_NAME;
+ if (oldDscp == newDscp) {
+ if (oldDscp->flags & CM_SCACHEFLAG_ANYWATCH)
+ smb_NotifyChange(FILE_ACTION_RENAMED_OLD_NAME,
+ filter, oldDscp, oldLastNamep,
+ newLastNamep, TRUE);
+ } else {
+ if (oldDscp->flags & CM_SCACHEFLAG_ANYWATCH)
+ smb_NotifyChange(FILE_ACTION_RENAMED_OLD_NAME,
+ filter, oldDscp, oldLastNamep,
+ NULL, TRUE);
+ if (newDscp->flags & CM_SCACHEFLAG_ANYWATCH)
+ smb_NotifyChange(FILE_ACTION_RENAMED_NEW_NAME,
+ filter, newDscp, newLastNamep,
+ NULL, TRUE);
+ }
}
if (tmpscp != NULL)
#ifdef DFS_SUPPORT
if (oldDscp->fileType == CM_SCACHETYPE_DFSLINK) {
+ int pnc = cm_VolStatus_Notify_DFS_Mapping(oldDscp, tidPathp, spacep->data);
cm_ReleaseSCache(oldDscp);
cm_ReleaseUser(userp);
- if ( WANTS_DFS_PATHNAMES(inp) )
+ if ( WANTS_DFS_PATHNAMES(inp) || pnc )
return CM_ERROR_PATH_NOT_COVERED;
else
return CM_ERROR_BADSHARENAME;
#ifdef DFS_SUPPORT
if (newDscp->fileType == CM_SCACHETYPE_DFSLINK) {
+ int pnc = cm_VolStatus_Notify_DFS_Mapping(newDscp, tidPathp, spacep->data);
cm_ReleaseSCache(newDscp);
cm_ReleaseSCache(oldDscp);
cm_ReleaseUser(userp);
- if ( WANTS_DFS_PATHNAMES(inp) )
+ if ( WANTS_DFS_PATHNAMES(inp) || pnc )
return CM_ERROR_PATH_NOT_COVERED;
else
return CM_ERROR_BADSHARENAME;
/* Check if the file already exists; if so return error */
code = cm_Lookup(newDscp,newLastNamep,CM_FLAG_CHECKPATH,userp,&req,&tmpscp);
- if ((code != CM_ERROR_NOSUCHFILE) && (code != CM_ERROR_NOSUCHPATH) && (code != CM_ERROR_NOSUCHVOLUME) ) {
+ if ((code != CM_ERROR_NOSUCHFILE) && (code != CM_ERROR_BPLUS_NOMATCH) &&
+ (code != CM_ERROR_NOSUCHPATH) && (code != CM_ERROR_NOSUCHVOLUME) )
+ {
osi_Log2(smb_logp, " lookup returns %ld for [%s]", code,
- osi_LogSaveString(afsd_logp, newLastNamep));
+ osi_LogSaveString(smb_logp, newLastNamep));
/* if the existing link is to the same file, then we return success */
if (!code) {
char *maskp; /* pointer to the star pattern */
int flags;
int any;
+ cm_dirEntryList_t * matches;
} smb_rmdirRock_t;
int smb_RmdirProc(cm_scache_t *dscp, cm_dirEntry_t *dep, void *vrockp, osi_hyper_t *offp)
matchName = shortName;
match = (cm_stricmp(matchName, rockp->maskp) == 0);
}
+
if (match) {
- osi_Log1(smb_logp, "Removing directory %s",
- osi_LogSaveString(smb_logp, matchName));
- code = cm_RemoveDir(dscp, dep->name, rockp->userp, rockp->reqp);
- if (code == 0 && (dscp->flags & CM_SCACHEFLAG_ANYWATCH))
- smb_NotifyChange(FILE_ACTION_REMOVED,
- FILE_NOTIFY_CHANGE_DIR_NAME | FILE_NOTIFY_CHANGE_CREATION,
- dscp, dep->name, NULL, TRUE);
- if (code == 0)
rockp->any = 1;
+ cm_DirEntryListAdd(dep->name, &rockp->matches);
}
- else code = 0;
- return code;
+ return 0;
}
long smb_ReceiveCoreRemoveDir(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp)
#ifdef DFS_SUPPORT
if (dscp->fileType == CM_SCACHETYPE_DFSLINK) {
+ int pnc = cm_VolStatus_Notify_DFS_Mapping(dscp, tidPathp, spacep->data);
cm_ReleaseSCache(dscp);
cm_ReleaseUser(userp);
- if ( WANTS_DFS_PATHNAMES(inp) )
+ if ( WANTS_DFS_PATHNAMES(inp) || pnc )
return CM_ERROR_PATH_NOT_COVERED;
else
return CM_ERROR_BADSHARENAME;
rock.userp = userp;
rock.reqp = &req;
rock.dscp = dscp;
+ rock.matches = NULL;
/* First do a case sensitive match, and if that fails, do a case insensitive match */
code = cm_ApplyDir(dscp, smb_RmdirProc, &rock, &thyper, userp, &req, NULL);
code = cm_ApplyDir(dscp, smb_RmdirProc, &rock, &thyper, userp, &req, NULL);
}
+ if (code == 0 && rock.matches) {
+ cm_dirEntryList_t * entry;
+
+ for (entry = rock.matches; code == 0 && entry; entry = entry->nextp) {
+ osi_Log1(smb_logp, "Removing directory %s",
+ osi_LogSaveString(smb_logp, entry->name));
+
+ code = cm_RemoveDir(dscp, entry->name, userp, &req);
+
+ if (code == 0 && (dscp->flags & CM_SCACHEFLAG_ANYWATCH))
+ smb_NotifyChange(FILE_ACTION_REMOVED,
+ FILE_NOTIFY_CHANGE_DIR_NAME | FILE_NOTIFY_CHANGE_CREATION,
+ dscp, entry->name, NULL, TRUE);
+ }
+ }
+
+ cm_DirEntryListFree(&rock.matches);
+
cm_ReleaseUser(userp);
cm_ReleaseSCache(dscp);
if (!fidp)
return CM_ERROR_BADFD;
+ if (fidp->scp && (fidp->scp->flags & CM_SCACHEFLAG_DELETED)) {
+ smb_CloseFID(vcp, fidp, NULL, 0);
+ smb_ReleaseFID(fidp);
+ return CM_ERROR_NOSUCHFILE;
+ }
+
lock_ObtainMutex(&fidp->mx);
if (fidp->flags & SMB_FID_IOCTL) {
lock_ReleaseMutex(&fidp->mx);
cm_scache_t *dscp = NULL;
char *pathp = NULL;
cm_scache_t * scp = NULL;
+ cm_scache_t *delscp = NULL;
int deleted = 0;
int nullcreator = 0;
char *fullPathp;
lock_ReleaseMutex(&fidp->mx);
- smb_FullName(dscp, scp, pathp, &fullPathp, userp, &req);
- if (scp->fileType == CM_SCACHETYPE_DIRECTORY) {
+
+ code = cm_Lookup(dscp, pathp, CM_FLAG_NOMOUNTCHASE, userp, &req, &delscp);
+ if (code) {
+ cm_HoldSCache(scp);
+ delscp = scp;
+ }
+ smb_FullName(dscp, delscp, pathp, &fullPathp, userp, &req);
+ if (delscp->fileType == CM_SCACHETYPE_DIRECTORY) {
code = cm_RemoveDir(dscp, fullPathp, userp, &req);
if (code == 0) {
deleted = 1;
fidp->NTopen_pathp = NULL;
fidp->flags &= ~SMB_FID_NTOPEN;
} else {
- osi_assert(fidp->NTopen_dscp == NULL);
- osi_assert(fidp->NTopen_pathp == NULL);
+ osi_assertx(fidp->NTopen_dscp == NULL, "null NTopen_dsc");
+ osi_assertx(fidp->NTopen_pathp == NULL, "null NTopen_path");
}
if (fidp->NTopen_wholepathp) {
if (dscp)
cm_ReleaseSCache(dscp);
- if (scp) {
- if (deleted || nullcreator) {
- lock_ObtainMutex(&scp->mx);
- if (nullcreator && scp->creator == userp)
- scp->creator = NULL;
+ if (delscp) {
+ if (deleted) {
+ lock_ObtainMutex(&delscp->mx);
if (deleted)
- scp->flags |= CM_SCACHEFLAG_DELETED;
- lock_ReleaseMutex(&scp->mx);
+ delscp->flags |= CM_SCACHEFLAG_DELETED;
+ lock_ReleaseMutex(&delscp->mx);
}
+ cm_ReleaseSCache(delscp);
+ }
+
+ if (scp) {
lock_ObtainMutex(&scp->mx);
+ if (nullcreator && scp->creator == userp)
+ scp->creator = NULL;
scp->flags &= ~CM_SCACHEFLAG_SMB_FID;
lock_ReleaseMutex(&scp->mx);
cm_ReleaseSCache(scp);
cm_scache_t *scp;
osi_hyper_t fileLength; /* file's length at start of write */
osi_hyper_t minLength; /* don't read past this */
- long nbytes; /* # of bytes to transfer this iteration */
+ afs_uint32 nbytes; /* # of bytes to transfer this iteration */
cm_buf_t *bufferp;
osi_hyper_t thyper; /* hyper tmp variable */
osi_hyper_t bufferOffset;
- long bufIndex; /* index in buffer where our data is */
+ afs_uint32 bufIndex; /* index in buffer where our data is */
int doWriteBack;
osi_hyper_t writeBackOffset;/* offset of region to write back when
* I/O is done */
/* now copy the data */
memcpy(bufferp->datap + bufIndex, op, nbytes);
- buf_SetDirty(bufferp);
+ buf_SetDirty(bufferp, bufIndex, nbytes);
/* and record the last writer */
if (bufferp->userp != userp) {
return CM_ERROR_BADFD;
}
+ if (fidp->scp && (fidp->scp->flags & CM_SCACHEFLAG_DELETED)) {
+ smb_CloseFID(vcp, fidp, NULL, 0);
+ smb_ReleaseFID(fidp);
+ return CM_ERROR_NOSUCHFILE;
+ }
+
lock_ObtainMutex(&fidp->mx);
if (fidp->flags & SMB_FID_IOCTL) {
lock_ReleaseMutex(&fidp->mx);
offset = LargeIntegerAdd(offset,
ConvertLongToLargeInteger(written));
- count -= written;
+ count -= (unsigned short)written;
total_written += written;
written = 0;
}
fd = smb_GetSMBParm(inp, 0);
fidp = smb_FindFID(vcp, fd, 0);
+ if (fidp->scp && (fidp->scp->flags & CM_SCACHEFLAG_DELETED)) {
+ smb_CloseFID(vcp, fidp, NULL, 0);
+ smb_ReleaseFID(fidp);
+ return;
+ }
+
osi_Log3(smb_logp, "Completing Raw Write offset 0x%x:%08x count %x",
rwcp->offset.HighPart, rwcp->offset.LowPart, rwcp->count);
return CM_ERROR_BADFD;
}
+ if (fidp->scp && (fidp->scp->flags & CM_SCACHEFLAG_DELETED)) {
+ smb_CloseFID(vcp, fidp, NULL, 0);
+ smb_ReleaseFID(fidp);
+ return CM_ERROR_NOSUCHFILE;
+ }
+
{
unsigned pid;
cm_key_t key;
if (!fidp)
return CM_ERROR_BADFD;
+ if (fidp->scp && (fidp->scp->flags & CM_SCACHEFLAG_DELETED)) {
+ smb_CloseFID(vcp, fidp, NULL, 0);
+ smb_ReleaseFID(fidp);
+ return CM_ERROR_NOSUCHFILE;
+ }
+
lock_ObtainMutex(&fidp->mx);
if (fidp->flags & SMB_FID_IOCTL) {
lock_ReleaseMutex(&fidp->mx);
#ifdef DFS_SUPPORT
if (dscp->fileType == CM_SCACHETYPE_DFSLINK) {
+ int pnc = cm_VolStatus_Notify_DFS_Mapping(dscp, tidPathp, spacep->data);
cm_ReleaseSCache(dscp);
cm_ReleaseUser(userp);
- if ( WANTS_DFS_PATHNAMES(inp) )
+ if ( WANTS_DFS_PATHNAMES(inp) || pnc )
return CM_ERROR_PATH_NOT_COVERED;
else
return CM_ERROR_BADSHARENAME;
lastNamep++;
code = cm_Lookup(dscp, lastNamep, 0, userp, &req, &scp);
if (scp) cm_ReleaseSCache(scp);
- if (code != CM_ERROR_NOSUCHFILE) {
+ if (code != CM_ERROR_NOSUCHFILE && code != CM_ERROR_BPLUS_NOMATCH) {
if (code == 0) code = CM_ERROR_EXISTS;
cm_ReleaseSCache(dscp);
cm_ReleaseUser(userp);
#ifdef DFS_SUPPORT
if (dscp->fileType == CM_SCACHETYPE_DFSLINK) {
+ int pnc = cm_VolStatus_Notify_DFS_Mapping(dscp, tidPathp, spacep->data);
cm_ReleaseSCache(dscp);
cm_ReleaseUser(userp);
- if ( WANTS_DFS_PATHNAMES(inp) )
+ if ( WANTS_DFS_PATHNAMES(inp) || pnc )
return CM_ERROR_PATH_NOT_COVERED;
else
return CM_ERROR_BADSHARENAME;
#endif
code = cm_Lookup(dscp, lastNamep, 0, userp, &req, &scp);
- if (code && code != CM_ERROR_NOSUCHFILE) {
+ if (code && code != CM_ERROR_NOSUCHFILE && code != CM_ERROR_BPLUS_NOMATCH) {
cm_ReleaseSCache(dscp);
cm_ReleaseUser(userp);
return code;
/* now all we have to do is open the file itself */
fidp = smb_FindFID(vcp, 0, SMB_FLAG_CREATE);
- osi_assert(fidp);
+ osi_assertx(fidp, "null smb_fid_t");
cm_HoldUser(userp);
lock_ObtainMutex(&fidp->mx);
/* always create it open for read/write */
- fidp->flags |= (SMB_FID_OPENREAD | SMB_FID_OPENWRITE);
+ fidp->flags |= (SMB_FID_OPENREAD_LISTDIR | SMB_FID_OPENWRITE);
/* remember that the file was newly created */
if (created)
fidp->flags |= SMB_FID_CREATED;
- osi_Log2(afsd_logp,"smb_ReceiveCoreCreate fidp 0x%p scp 0x%p", fidp, scp);
+ osi_Log2(smb_logp,"smb_ReceiveCoreCreate fidp 0x%p scp 0x%p", fidp, scp);
/* save a pointer to the vnode */
fidp->scp = scp;
/* try to find the file descriptor */
fd = smb_ChainFID(fd, inp);
fidp = smb_FindFID(vcp, fd, 0);
-
if (!fidp)
return CM_ERROR_BADFD;
+ if (fidp->scp && (fidp->scp->flags & CM_SCACHEFLAG_DELETED)) {
+ smb_CloseFID(vcp, fidp, NULL, 0);
+ smb_ReleaseFID(fidp);
+ return CM_ERROR_NOSUCHFILE;
+ }
+
lock_ObtainMutex(&fidp->mx);
if (fidp->flags & SMB_FID_IOCTL) {
lock_ReleaseMutex(&fidp->mx);
{
/* this is fatal - log as much as possible */
osi_Log1(smb_logp, "Fatal: NCBevents idx [ %d ] out of range.\n", idx);
- osi_assert(0);
+ osi_assertx(0, "invalid index");
}
thrd_ResetEvent(NCBevents[idx]);
{
/* this is fatal - log as much as possible */
osi_Log1(smb_logp, "Fatal: session idx [ %d ] out of range.\n", idx_session);
- osi_assert(0);
+ osi_assertx(0, "invalid index");
}
/* Get an NCB */
{
/* this is fatal - log as much as possible */
osi_Log1(smb_logp, "Fatal: idx_NCB [ %d ] out of range.\n", idx_NCB);
- osi_assert(0);
+ osi_assertx(0, "invalid index");
}
/* Link them together */
{
/* this is fatal - log as much as possible */
osi_Log1(smb_logp, "Fatal: idx_NCB %d out of range.\n", idx_NCB);
- osi_assert(0);
+ osi_assertx(0, "invalid index");
}
ncbp = NCBs[idx_NCB];
int i;
char eventName[MAX_PATH];
- osi_assert( idx < (sizeof(NCBs) / sizeof(NCBs[0])) );
+ osi_assertx( idx < (sizeof(NCBs) / sizeof(NCBs[0])), "invalid index" );
NCBs[idx] = GetNCB();
sprintf(eventName,"NCBavails[%d]", idx);
char cname[MAX_COMPUTERNAME_LENGTH+1];
int cnamelen = MAX_COMPUTERNAME_LENGTH+1;
INT_PTR lana = (INT_PTR) parmp;
+ char eventName[MAX_PATH];
+
+ sprintf(eventName,"smb_Listener_lana_%d", (char)lana);
+ ListenerShutdown[lana] = thrd_CreateEvent(NULL, FALSE, FALSE, eventName);
+ if ( GetLastError() == ERROR_ALREADY_EXISTS )
+ thrd_ResetEvent(ListenerShutdown[lana]);
ncbp = GetNCB();
code = Netbios(ncbp);
- if (code == NRC_BRIDGE) {
- int lanaRemaining = 0;
+ if (code == NRC_NAMERR) {
+ /* An smb shutdown or Vista resume must have taken place */
+ osi_Log2(smb_logp,
+ "NCBLISTEN lana=%d failed with NRC_NAMERR.",
+ ncbp->ncb_lana_num, code);
- if (smb_ListenerState == SMB_LISTENER_STOPPED || smbShutdownFlag == 1) {
- ExitThread(1);
+ if (lock_TryMutex(&smb_StartedLock)) {
+ lana_list.lana[i] = LANA_INVALID;
+ lock_ReleaseMutex(&smb_StartedLock);
}
+ break;
+ } else if (code == NRC_BRIDGE || code != 0) {
+ int lanaRemaining = 0;
- osi_Log2(smb_logp,
- "NCBLISTEN lana=%d failed with NRC_BRIDGE. Listener thread exiting.",
- ncbp->ncb_lana_num, code);
+ while (!lock_TryMutex(&smb_StartedLock)) {
+ if (smb_ListenerState == SMB_LISTENER_STOPPED || smbShutdownFlag == 1)
+ goto exit_thread;
+ Sleep(50);
+ }
+
+ osi_Log2(smb_logp,
+ "NCBLISTEN lana=%d failed with %s. Listener thread exiting.",
+ ncbp->ncb_lana_num, ncb_error_string(code));
for (i = 0; i < lana_list.length; i++) {
- if (lana_list.lana[i] == ncbp->ncb_lana_num) {
- smb_StopListener(ncbp, lana_list.lana[i]);
- lana_list.lana[i] = 255;
+ if (lana_list.lana[i] == lana) {
+ smb_StopListener(ncbp, lana_list.lana[i], FALSE);
+ lana_list.lana[i] = LANA_INVALID;
}
- if (lana_list.lana[i] != 255)
+ if (lana_list.lana[i] != LANA_INVALID)
lanaRemaining++;
}
if (lanaRemaining == 0) {
+ cm_VolStatus_Network_Stopped(cm_NetbiosName
+#ifdef _WIN64
+ ,cm_NetbiosName
+#endif
+ );
smb_ListenerState = SMB_LISTENER_STOPPED;
- smb_LANadapter = -1;
+ smb_LANadapter = LANA_INVALID;
lana_list.length = 0;
}
- FreeNCB(ncbp);
- return;
- } else if (code != 0) {
- char tbuffer[256];
+ lock_ReleaseMutex(&smb_StartedLock);
+ break;
+ }
+#if 0
+ else if (code != 0) {
+ char tbuffer[AFSPATHMAX];
/* terminate silently if shutdown flag is set */
- if (smb_ListenerState == SMB_LISTENER_STOPPED || smbShutdownFlag == 1) {
- ExitThread(1);
+ while (!lock_TryMutex(&smb_StartedLock)) {
+ if (smb_ListenerState == SMB_LISTENER_STOPPED || smbShutdownFlag == 1)
+ goto exit_thread;
+ Sleep(50);
}
- osi_Log2(smb_logp,
- "NCBLISTEN lana=%d failed with code %d",
- ncbp->ncb_lana_num, code);
+ osi_Log3(smb_logp,
+ "NCBLISTEN lana=%d failed with code %d [%s]",
+ ncbp->ncb_lana_num, code, ncb_error_string(code));
osi_Log0(smb_logp,
"Client exiting due to network failure. Please restart client.\n");
sprintf(tbuffer,
"Client exiting due to network failure. Please restart client.\n"
- "NCBLISTEN lana=%d failed with code %d",
- ncbp->ncb_lana_num, code);
+ "NCBLISTEN lana=%d failed with code %d [%s]",
+ ncbp->ncb_lana_num, code, ncb_error_string(code));
if (showErrors)
code = (*smb_MBfunc)(NULL, tbuffer, "AFS Client Service: Fatal Error",
MB_OK|MB_SERVICE_NOTIFICATION);
osi_panic(tbuffer, __FILE__, __LINE__);
+
+ lock_ReleaseMutex(&smb_StartedLock);
+ break;
}
+#endif /* 0 */
/* check for remote conns */
/* first get remote name and insert null terminator */
* we should probably want to wait for a session to be freed in case
* we run out.
*/
- osi_assert(session < SESSION_MAX - 1);
- osi_assert(numNCBs < NCB_MAX - 1); /* if we pass this test we can allocate one more */
+ osi_assertx(session < SESSION_MAX - 1, "invalid session");
+ osi_assertx(numNCBs < NCB_MAX - 1, "invalid numNCBs"); /* if we pass this test we can allocate one more */
lock_ObtainMutex(&vcp->mx);
vcp->session = session;
lock_ReleaseMutex(&smb_ListenerLock);
} /* dispatch while loop */
+exit_thread:
FreeNCB(ncbp);
+ thrd_SetEvent(ListenerShutdown[lana]);
+ return;
+}
+
+static void
+smb_LanAdapterChangeThread(void *param)
+{
+ /*
+ * Give the IPAddrDaemon thread a chance
+ * to block before we trigger.
+ */
+ Sleep(30000);
+ smb_LanAdapterChange(0);
+}
+
+void smb_SetLanAdapterChangeDetected(void)
+{
+ int lpid;
+ thread_t phandle;
+
+ lock_ObtainMutex(&smb_StartedLock);
+
+ if (!powerStateSuspended) {
+ phandle = thrd_Create(NULL, 65536, (ThreadFunc) smb_LanAdapterChangeThread,
+ NULL, 0, &lpid, "smb_LanAdapterChange");
+ osi_assertx(phandle != NULL, "smb_LanAdapterChangeThread thread creation failure");
+ thrd_CloseHandle(phandle);
+ }
+
+ smb_LanAdapterChangeDetected = 1;
+ lock_ReleaseMutex(&smb_StartedLock);
+}
+
+void smb_LanAdapterChange(int locked) {
+ lana_number_t lanaNum;
+ BOOL bGateway;
+ char NetbiosName[MAX_NB_NAME_LENGTH] = "";
+ int change = 0;
+ LANA_ENUM temp_list;
+ long code;
+ int i;
+
+
+ afsi_log("smb_LanAdapterChange");
+
+ if (!locked)
+ lock_ObtainMutex(&smb_StartedLock);
+
+ smb_LanAdapterChangeDetected = 0;
+
+ if (!powerStateSuspended &&
+ SUCCEEDED(lana_GetUncServerNameEx(NetbiosName, &lanaNum, &bGateway,
+ LANA_NETBIOS_NAME_FULL)) &&
+ lanaNum != LANA_INVALID && smb_LANadapter != lanaNum) {
+ if ( isGateway != bGateway ||
+ strcmp(cm_NetbiosName, NetbiosName) ) {
+ change = 1;
+ } else {
+ NCB *ncbp = GetNCB();
+ ncbp->ncb_command = NCBENUM;
+ ncbp->ncb_buffer = (PUCHAR)&temp_list;
+ ncbp->ncb_length = sizeof(temp_list);
+ code = Netbios(ncbp);
+ if (code == 0) {
+ if (temp_list.length != lana_list.length)
+ change = 1;
+ else {
+ for (i=0; i<lana_list.length; i++) {
+ if ( temp_list.lana[i] != lana_list.lana[i] ) {
+ change = 1;
+ break;
+ }
+ }
+ }
+ }
+ FreeNCB(ncbp);
+ }
+ }
+
+ if (change) {
+ afsi_log("Lan Adapter Change detected");
+ smb_StopListeners(1);
+ smb_RestartListeners(1);
+ }
+ if (!locked)
+ lock_ReleaseMutex(&smb_StartedLock);
}
/* initialize Netbios */
-int smb_NetbiosInit(void)
+int smb_NetbiosInit(int locked)
{
NCB *ncbp;
int i, lana, code, l;
int delname_tried=0;
int len;
int lana_found = 0;
+ lana_number_t lanaNum;
+
+ if (!locked)
+ lock_ObtainMutex(&smb_StartedLock);
+
+ if (smb_ListenerState != SMB_LISTENER_UNINITIALIZED &&
+ smb_ListenerState != SMB_LISTENER_STOPPED) {
+ if (!locked)
+ lock_ReleaseMutex(&smb_StartedLock);
+ return 0;
+ }
/* setup the NCB system */
ncbp = GetNCB();
- if (smb_LANadapter == -1) {
+ /* 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 != LANA_INVALID)
+ 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);
+
+
+ if (smb_LANadapter == LANA_INVALID) {
ncbp->ncb_command = NCBENUM;
ncbp->ncb_buffer = (PUCHAR)&lana_list;
ncbp->ncb_length = sizeof(lana_list);
code = ncbp->ncb_retcode;
if (code != 0) {
afsi_log("Netbios NCBRESET lana %d error code %d", lana_list.lana[i], code);
- lana_list.lana[i] = 255; /* invalid lana */
+ lana_list.lana[i] = LANA_INVALID; /* invalid lana */
} else {
afsi_log("Netbios NCBRESET lana %d succeeded", lana_list.lana[i]);
}
else {
afsi_log("Netbios NCBADDNAME lana %d error code %d", lana, code);
if (code == NRC_BRIDGE) { /* invalid LANA num */
- lana_list.lana[l] = 255;
+ lana_list.lana[l] = LANA_INVALID;
continue;
}
else if (code == NRC_DUPNAME) {
afsi_log("Netbios NCBDELNAME lana %d error code %d\n", lana, code);
}
if (code != 0 || delname_tried) {
- lana_list.lana[l] = 255;
+ lana_list.lana[l] = LANA_INVALID;
}
else if (code == 0) {
if (!delname_tried) {
}
else {
afsi_log("Netbios NCBADDNAME lana %d error code %d", lana, code);
- lana_list.lana[l] = 255; /* invalid lana */
+ lana_list.lana[l] = LANA_INVALID; /* invalid lana */
}
}
if (code == 0) {
+ smb_LANadapter = lana;
lana_found = 1; /* at least one worked */
}
}
- osi_assert(lana_list.length >= 0);
+ osi_assertx(lana_list.length >= 0, "empty lana list");
if (!lana_found) {
afsi_log("No valid LANA numbers found!");
lana_list.length = 0;
- smb_LANadapter = -1;
+ smb_LANadapter = LANA_INVALID;
smb_ListenerState = SMB_LISTENER_STOPPED;
+ cm_VolStatus_Network_Stopped(cm_NetbiosName
+#ifdef _WIN64
+ ,cm_NetbiosName
+#endif
+ );
}
/* we're done with the NCB now */
FreeNCB(ncbp);
+ afsi_log("smb_NetbiosInit smb_LANadapter=%d",smb_LANadapter);
+ if (lana_list.length > 0)
+ osi_assert(smb_LANadapter != LANA_INVALID);
+
+ if (!locked)
+ lock_ReleaseMutex(&smb_StartedLock);
+
return (lana_list.length > 0 ? 1 : 0);
}
-void smb_StartListeners()
+void smb_StartListeners(int locked)
{
int i;
int lpid;
thread_t phandle;
- if (smb_ListenerState == SMB_LISTENER_STARTED)
+ if (!locked)
+ lock_ObtainMutex(&smb_StartedLock);
+
+ if (smb_ListenerState == SMB_LISTENER_STARTED) {
+ if (!locked)
+ lock_ReleaseMutex(&smb_StartedLock);
return;
-
+ }
+
+ afsi_log("smb_StartListeners");
smb_ListenerState = SMB_LISTENER_STARTED;
+ cm_VolStatus_Network_Started(cm_NetbiosName
+#ifdef _WIN64
+ , cm_NetbiosName
+#endif
+ );
for (i = 0; i < lana_list.length; i++) {
- if (lana_list.lana[i] == 255)
+ if (lana_list.lana[i] == LANA_INVALID)
continue;
phandle = thrd_Create(NULL, 65536, (ThreadFunc) smb_Listener,
(void*)lana_list.lana[i], 0, &lpid, "smb_Listener");
- osi_assert(phandle != NULL);
+ osi_assertx(phandle != NULL, "smb_Listener thread creation failure");
thrd_CloseHandle(phandle);
}
+ if (!locked)
+ lock_ReleaseMutex(&smb_StartedLock);
}
-void smb_RestartListeners()
+void smb_RestartListeners(int locked)
{
- if (!powerStateSuspended && smb_ListenerState == SMB_LISTENER_STOPPED) {
- if (smb_NetbiosInit())
- smb_StartListeners();
+ if (!locked)
+ lock_ObtainMutex(&smb_StartedLock);
+
+ if (powerStateSuspended)
+ afsi_log("smb_RestartListeners called while suspended");
+
+ if (!powerStateSuspended && smb_ListenerState != SMB_LISTENER_UNINITIALIZED) {
+ if (smb_ListenerState == SMB_LISTENER_STOPPED) {
+ if (smb_NetbiosInit(1))
+ smb_StartListeners(1);
+ } else if (smb_LanAdapterChangeDetected) {
+ smb_LanAdapterChange(1);
+ }
}
+ if (!locked)
+ lock_ReleaseMutex(&smb_StartedLock);
}
-void smb_StopListener(NCB *ncbp, int lana)
+void smb_StopListener(NCB *ncbp, int lana, int wait)
{
long code;
} else {
afsi_log("Netbios NCBRESET lana %d succeeded", lana);
}
+
+ if (wait)
+ thrd_WaitForSingleObject_Event(ListenerShutdown[lana], INFINITE);
}
-void smb_StopListeners(void)
+void smb_StopListeners(int locked)
{
NCB *ncbp;
int lana, l;
- if (smb_ListenerState == SMB_LISTENER_STOPPED)
+ if (!locked)
+ lock_ObtainMutex(&smb_StartedLock);
+
+ if (smb_ListenerState == SMB_LISTENER_STOPPED) {
+ if (!locked)
+ lock_ReleaseMutex(&smb_StartedLock);
return;
+ }
+ afsi_log("smb_StopListeners");
smb_ListenerState = SMB_LISTENER_STOPPED;
+ cm_VolStatus_Network_Stopped(cm_NetbiosName
+#ifdef _WIN64
+ , cm_NetbiosName
+#endif
+ );
ncbp = GetNCB();
for (l = 0; l < lana_list.length; l++) {
lana = lana_list.lana[l];
- if (lana != 255) {
- smb_StopListener(ncbp, lana);
+ if (lana != LANA_INVALID) {
+ smb_StopListener(ncbp, lana, TRUE);
/* mark the adapter invalid */
- lana_list.lana[l] = 255; /* invalid lana */
+ lana_list.lana[l] = LANA_INVALID; /* invalid lana */
}
}
/* force a re-evaluation of the network adapters */
lana_list.length = 0;
- smb_LANadapter = -1;
+ smb_LANadapter = LANA_INVALID;
FreeNCB(ncbp);
- Sleep(1000); /* give the listener threads a chance to exit */
+ if (!locked)
+ lock_ReleaseMutex(&smb_StartedLock);
}
-void smb_Init(osi_log_t *logp, char *snamep, int useV3, int LANadapt,
+void smb_Init(osi_log_t *logp, int useV3,
int nThreads
, void *aMBfunc
)
thread_t phandle;
int lpid;
INT_PTR i;
- int len;
struct tm myTime;
EVENT_HANDLE retHandle;
char eventName[MAX_PATH];
+ int startListeners = 0;
smb_TlsRequestSlot = TlsAlloc();
smb_MBfunc = aMBfunc;
smb_useV3 = useV3;
- smb_LANadapter = LANadapt;
/* Initialize smb_localZero */
myTime.tm_isdst = -1; /* compute whether on DST or not */
/* 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");
lock_InitializeMutex(&smb_RawBufLock, "smb raw buffer lock");
lock_InitializeMutex(&smb_ListenerLock, "smb listener lock");
+ lock_InitializeMutex(&smb_StartedLock, "smb started lock");
/* 4 Raw I/O buffers */
smb_RawBufs = calloc(65536,1);
smb_ncbFreeListp = NULL;
smb_packetFreeListp = NULL;
- smb_NetbiosInit();
+ lock_ObtainMutex(&smb_StartedLock);
+ startListeners = smb_NetbiosInit(1);
/* Initialize listener and server structures */
numVCs = 0;
);
if (nts != STATUS_SUCCESS && ntsEx != STATUS_SUCCESS) {
- char message[256];
+ char message[AFSPATHMAX];
sprintf(message,"MsV1_0SetProcessOption failure: nts 0x%x ntsEx 0x%x",
nts, ntsEx);
OutputDebugString(message);
}
/* Start listeners, waiters, servers, and daemons */
-
- smb_StartListeners();
+ if (startListeners)
+ smb_StartListeners(1);
phandle = thrd_Create(NULL, 65536, (ThreadFunc) smb_ClientWaiter,
NULL, 0, &lpid, "smb_ClientWaiter");
- osi_assert(phandle != NULL);
+ osi_assertx(phandle != NULL, "smb_ClientWaiter thread creation failure");
thrd_CloseHandle(phandle);
phandle = thrd_Create(NULL, 65536, (ThreadFunc) smb_ServerWaiter,
NULL, 0, &lpid, "smb_ServerWaiter");
- osi_assert(phandle != NULL);
+ osi_assertx(phandle != NULL, "smb_ServerWaiter thread creation failure");
thrd_CloseHandle(phandle);
for (i=0; i<smb_NumServerThreads; i++) {
phandle = thrd_Create(NULL, 65536, (ThreadFunc) smb_Server,
(void *) i, 0, &lpid, "smb_Server");
- osi_assert(phandle != NULL);
+ osi_assertx(phandle != NULL, "smb_Server thread creation failure");
thrd_CloseHandle(phandle);
}
phandle = thrd_Create(NULL, 65536, (ThreadFunc) smb_Daemon,
NULL, 0, &lpid, "smb_Daemon");
- osi_assert(phandle != NULL);
+ osi_assertx(phandle != NULL, "smb_Daemon thread creation failure");
thrd_CloseHandle(phandle);
phandle = thrd_Create(NULL, 65536, (ThreadFunc) smb_WaitingLocksDaemon,
NULL, 0, &lpid, "smb_WaitingLocksDaemon");
- osi_assert(phandle != NULL);
+ osi_assertx(phandle != NULL, "smb_WaitingLocksDaemon thread creation failure");
thrd_CloseHandle(phandle);
+ lock_ReleaseMutex(&smb_StartedLock);
return;
}
/* Delete Netbios name */
memset((char *)ncbp, 0, sizeof(NCB));
for (i = 0; i < lana_list.length; i++) {
- if (lana_list.lana[i] == 255) continue;
+ if (lana_list.lana[i] == LANA_INVALID) continue;
ncbp->ncb_command = NCBDELNAME;
ncbp->ncb_lana_num = lana_list.lana[i];
memcpy(ncbp->ncb_name,smb_sharename,NCBNAMSZ);
lock_ObtainMutex(&scp->mx);
scp->flags &= ~CM_SCACHEFLAG_SMB_FID;
lock_ReleaseMutex(&scp->mx);
- osi_Log2(afsd_logp,"smb_Shutdown fidp 0x%p scp 0x%p", fidp, scp);
+ osi_Log2(smb_logp,"smb_Shutdown fidp 0x%p scp 0x%p", fidp, scp);
cm_ReleaseSCache(scp);
}
lock_ReleaseMutex(&fidp->mx);
if (lock)
lock_ObtainRead(&smb_rctLock);
- sprintf(output, "begin dumping smb_vc_t\n");
+ sprintf(output, "begin dumping smb_vc_t\r\n");
WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
for (vcp = smb_allVCsp; vcp; vcp=vcp->nextp)
{
smb_fid_t *fidp;
- sprintf(output, "%s vcp=0x%p, refCount=%d, flags=%d, vcID=%d, lsn=%d, uidCounter=%d, tidCounter=%d, fidCounter=%d\n",
- cookie, vcp, vcp->refCount, vcp->flags, vcp->vcID, vcp->lsn, vcp->uidCounter, vcp->tidCounter, vcp->fidCounter);
- WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
-
- sprintf(output, "begin dumping smb_fid_t\n");
- WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
-
- for (fidp = vcp->fidsp; fidp; fidp = (smb_fid_t *) osi_QNext(&fidp->q))
- {
- sprintf(output, "%s -- smb_fidp=0x%p, refCount=%d, fid=%d, vcp=0x%p, scp=0x%p, ioctlp=0x%p, NTopen_pathp=%s, NTopen_wholepathp=%s\n",
- cookie, fidp, fidp->refCount, fidp->fid, fidp->vcp, fidp->scp, fidp->ioctlp,
- fidp->NTopen_pathp ? fidp->NTopen_pathp : "NULL",
- fidp->NTopen_wholepathp ? fidp->NTopen_wholepathp : "NULL");
- WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
- }
-
- sprintf(output, "done dumping smb_fid_t\n");
- WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
- }
-
- sprintf(output, "done dumping smb_vc_t\n");
- WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
-
- sprintf(output, "begin dumping DEAD smb_vc_t\n");
- WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
-
- for (vcp = smb_deadVCsp; vcp; vcp=vcp->nextp)
- {
- smb_fid_t *fidp;
-
- sprintf(output, "%s vcp=0x%p, refCount=%d, flags=%d, vcID=%d, lsn=%d, uidCounter=%d, tidCounter=%d, fidCounter=%d\n",
+ sprintf(output, "%s vcp=0x%p, refCount=%d, flags=%d, vcID=%d, lsn=%d, uidCounter=%d, tidCounter=%d, fidCounter=%d\r\n",
cookie, vcp, vcp->refCount, vcp->flags, vcp->vcID, vcp->lsn, vcp->uidCounter, vcp->tidCounter, vcp->fidCounter);
WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
- sprintf(output, "begin dumping smb_fid_t\n");
+ sprintf(output, "begin dumping smb_fid_t\r\n");
WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
for (fidp = vcp->fidsp; fidp; fidp = (smb_fid_t *) osi_QNext(&fidp->q))
{
- sprintf(output, "%s -- smb_fidp=0x%p, refCount=%d, fid=%d, vcp=0x%p, scp=0x%p, ioctlp=0x%p, NTopen_pathp=%s, NTopen_wholepathp=%s\n",
+ sprintf(output, "%s -- smb_fidp=0x%p, refCount=%d, fid=%d, vcp=0x%p, scp=0x%p, ioctlp=0x%p, NTopen_pathp=%s, NTopen_wholepathp=%s\r\n",
cookie, fidp, fidp->refCount, fidp->fid, fidp->vcp, fidp->scp, fidp->ioctlp,
fidp->NTopen_pathp ? fidp->NTopen_pathp : "NULL",
fidp->NTopen_wholepathp ? fidp->NTopen_wholepathp : "NULL");
WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
}
- sprintf(output, "done dumping smb_fid_t\n");
+ sprintf(output, "done dumping smb_fid_t\r\n");
WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
}
- sprintf(output, "done dumping DEAD smb_vc_t\n");
+ sprintf(output, "done dumping smb_vc_t\r\n");
WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
- sprintf(output, "begin dumping DEAD smb_vc_t\n");
+ sprintf(output, "begin dumping DEAD smb_vc_t\r\n");
WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
for (vcp = smb_deadVCsp; vcp; vcp=vcp->nextp)
{
smb_fid_t *fidp;
- sprintf(output, "%s vcp=0x%p, refCount=%d, flags=%d, vcID=%d, lsn=%d, uidCounter=%d, tidCounter=%d, fidCounter=%d\n",
+ sprintf(output, "%s vcp=0x%p, refCount=%d, flags=%d, vcID=%d, lsn=%d, uidCounter=%d, tidCounter=%d, fidCounter=%d\r\n",
cookie, vcp, vcp->refCount, vcp->flags, vcp->vcID, vcp->lsn, vcp->uidCounter, vcp->tidCounter, vcp->fidCounter);
WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
- sprintf(output, "begin dumping smb_fid_t\n");
+ sprintf(output, "begin dumping smb_fid_t\r\n");
WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
for (fidp = vcp->fidsp; fidp; fidp = (smb_fid_t *) osi_QNext(&fidp->q))
{
- sprintf(output, "%s -- smb_fidp=0x%p, refCount=%d, fid=%d, vcp=0x%p, scp=0x%p, ioctlp=0x%p, NTopen_pathp=%s, NTopen_wholepathp=%s\n",
+ sprintf(output, "%s -- smb_fidp=0x%p, refCount=%d, fid=%d, vcp=0x%p, scp=0x%p, ioctlp=0x%p, NTopen_pathp=%s, NTopen_wholepathp=%s\r\n",
cookie, fidp, fidp->refCount, fidp->fid, fidp->vcp, fidp->scp, fidp->ioctlp,
fidp->NTopen_pathp ? fidp->NTopen_pathp : "NULL",
fidp->NTopen_wholepathp ? fidp->NTopen_wholepathp : "NULL");
WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
}
- sprintf(output, "done dumping smb_fid_t\n");
+ sprintf(output, "done dumping smb_fid_t\r\n");
WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
}
- sprintf(output, "done dumping DEAD smb_vc_t\n");
+ sprintf(output, "done dumping DEAD smb_vc_t\r\n");
WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
if (lock)
lock_ReleaseRead(&smb_rctLock);
return 0;
}
+
+long smb_IsNetworkStarted(void)
+{
+ long rc;
+ lock_ObtainWrite(&smb_globalLock);
+ rc = (smb_ListenerState == SMB_LISTENER_STARTED && smbShutdownFlag == 0);
+ lock_ReleaseWrite(&smb_globalLock);
+ return rc;
+}