for(i=0; i<11; i++) {
tc = *maskp++;
- if (tc == '?' || tc == '*' || tc == '>') return 1;
+ if (tc == '?' || tc == '*' || tc == '>')
+ return 1;
}
return 0;
}
break;
}
}
-
+ lock_FinalizeMutex(&vcp->mx);
memset(vcp,0,sizeof(smb_vc_t));
free(vcp);
}
smb_HoldFIDNoLock(fidpIter);
lock_ReleaseWrite(&smb_rctLock);
- /* smb_CloseFID sets SMB_FID_DELETE */
- if (smb_CloseFID(vcp, fidpIter, NULL, 0) == 0)
- smb_ReleaseFID(fidpIter);
+ /* smb_CloseFID sets SMB_FID_DELETE on Success */
+ smb_CloseFID(vcp, fidpIter, NULL, 0);
+ smb_ReleaseFID(fidpIter);
lock_ObtainWrite(&smb_rctLock);
fidpNext = vcp->fidsp;
if (newFid) {
vcp->fidCounter = fid+1;
if (vcp->fidCounter == 0) {
- osi_Log1(smb_logp, "fidCounter wrapped around for vcp 0x%x",
- vcp);
+ osi_Log1(smb_logp, "fidCounter wrapped around for vcp 0x%x",
+ vcp);
vcp->fidCounter = 1;
}
}
smb_vc_t *vcp = NULL;
smb_ioctl_t *ioctlp;
- if (!fidp)
- return;
-
lock_ObtainWrite(&smb_rctLock);
osi_assert(fidp->refCount-- > 0);
+ lock_ObtainMutex(&fidp->mx);
if (fidp->refCount == 0 && (fidp->flags & SMB_FID_DELETE)) {
vcp = fidp->vcp;
fidp->vcp = NULL;
free(ioctlp);
}
+ lock_ReleaseMutex(&fidp->mx);
+ lock_FinalizeMutex(&fidp->mx);
free(fidp);
if (vcp)
smb_ReleaseVCNoLock(vcp);
+ } else {
+ lock_ReleaseMutex(&fidp->mx);
}
lock_ReleaseWrite(&smb_rctLock);
if (!rawBuf)
goto send1a;
+ lock_ObtainMutex(&fidp->mx);
if (fidp->flags & SMB_FID_IOCTL)
{
+ lock_ReleaseMutex(&fidp->mx);
#ifndef DJGPP
rc = smb_IoctlReadRaw(fidp, vcp, inp, outp);
#else
smb_ReleaseFID(fidp);
return rc;
}
-
+ lock_ReleaseMutex(&fidp->mx);
+
userp = smb_GetUser(vcp, inp);
#ifndef DJGPP
smb_CheckVCs();
}
- /* XXX GC the smb_username_t objects with refCount 0 and
- * neither SMB_USERNAMEFLAG_AFSLOGON nor (SMB_USERNAMEFLAG_LOGOFF
- * && smb_LogoffTokenTransfer &&
- * now > last_logoff_t + smb_LogoffTransferTimeout)
- */
+ /* GC smb_username_t objects that will no longer be used */
now = osi_Time();
lock_ObtainWrite(&smb_rctLock);
for ( unpp=&usernamesp; *unpp; ) {
smb_username_t *unp;
lock_ObtainMutex(&(*unpp)->mx);
- if ( (*unpp)->refCount > 0 )
+ if ( (*unpp)->refCount > 0 ||
+ ((*unpp)->flags & SMB_USERNAMEFLAG_AFSLOGON) ||
+ !((*unpp)->flags & SMB_USERNAMEFLAG_LOGOFF))
;
- else if ((*unpp)->flags & SMB_USERNAMEFLAG_AFSLOGON)
- ;
- else if (!(((*unpp)->flags & SMB_USERNAMEFLAG_LOGOFF) && smb_LogoffTokenTransfer))
- delete = 1;
- else if ((*unpp)->last_logoff_t + smb_LogoffTransferTimeout < now)
+ else if (!smb_LogoffTokenTransfer ||
+ ((*unpp)->last_logoff_t + smb_LogoffTransferTimeout < now))
delete = 1;
lock_ReleaseMutex(&(*unpp)->mx);
cm_HoldUser(userp);
fidp->userp = userp;
+ lock_ObtainMutex(&fidp->mx);
if ((share & 0xf) == 0)
fidp->flags |= SMB_FID_OPENREAD;
else if ((share & 0xf) == 1)
fidp->flags |= SMB_FID_OPENWRITE;
else
fidp->flags |= (SMB_FID_OPENREAD | SMB_FID_OPENWRITE);
+ lock_ReleaseMutex(&fidp->mx);
lock_ObtainMutex(&scp->mx);
smb_SetSMBParm(outp, 0, fidp->fid);
fid = smb_ChainFID(fid, inp);
fidp = smb_FindFID(vcp, fid, 0);
- if (!fidp || (fidp->flags & SMB_FID_IOCTL)) {
- if (fidp)
- smb_ReleaseFID(fidp);
+ if (!fidp)
+ return CM_ERROR_BADFD;
+
+ lock_ObtainMutex(&fidp->mx);
+ if (fidp->flags & SMB_FID_IOCTL) {
+ lock_ReleaseMutex(&fidp->mx);
+ smb_ReleaseFID(fidp);
return CM_ERROR_BADFD;
}
+ lock_ReleaseMutex(&fidp->mx);
userp = smb_GetUser(vcp, inp);
fidp, fidp->fid, vcp);
if (!userp) {
+ lock_ObtainMutex(&fidp->mx);
if (!fidp->userp && !(fidp->flags & SMB_FID_IOCTL)) {
+ lock_ReleaseMutex(&fidp->mx);
osi_Log0(smb_logp, " No user specified. Not closing fid.");
return CM_ERROR_BADFD;
}
userp = fidp->userp; /* no hold required since fidp is held
throughout the function */
+ lock_ReleaseMutex(&fidp->mx);
}
cm_InitReq(&req);
/* make sure we have a writable FD */
if (!(fidp->flags & SMB_FID_OPENWRITE)) {
+ lock_ReleaseMutex(&fidp->mx);
code = CM_ERROR_BADFDOP;
goto done;
}
done:
lock_ReleaseMutex(&scp->mx);
- lock_ReleaseMutex(&fidp->mx);
+
if (bufferp) {
lock_ReleaseMutex(&bufferp->mx);
buf_Release(bufferp);
fidp->NTopen_dscp, fidp->NTopen_pathp,
NULL, TRUE);
}
+ lock_ReleaseMutex(&fidp->mx);
if (code == 0 && doWriteBack) {
long code2;
fd = smb_ChainFID(fd, inp);
fidp = smb_FindFID(vcp, fd, 0);
- if (!fidp) {
+ if (!fidp)
return CM_ERROR_BADFD;
- }
+ lock_ObtainMutex(&fidp->mx);
if (fidp->flags & SMB_FID_IOCTL) {
+ lock_ReleaseMutex(&fidp->mx);
code = smb_IoctlWrite(fidp, vcp, inp, outp);
smb_ReleaseFID(fidp);
return code;
}
+ lock_ReleaseMutex(&fidp->mx);
userp = smb_GetUser(vcp, inp);
/* special case: 0 bytes transferred means truncate to this position */
* and don't set client mod time if we think that would go against the
* intention.
*/
+ lock_ObtainMutex(&fidp->mx);
if ((fidp->flags & SMB_FID_MTIMESETDONE) != SMB_FID_MTIMESETDONE) {
fidp->scp->mask |= CM_SCACHEMASK_CLIENTMODTIME;
fidp->scp->clientModTime = time(NULL);
}
+ lock_ReleaseMutex(&fidp->mx);
code = 0;
while ( code == 0 && count > 0 ) {
* and don't set client mod time if we think that would go against the
* intention.
*/
+ lock_ObtainMutex(&fidp->mx);
if ((fidp->flags & SMB_FID_LOOKSLIKECOPY) != SMB_FID_LOOKSLIKECOPY) {
fidp->scp->mask |= CM_SCACHEMASK_CLIENTMODTIME;
fidp->scp->clientModTime = time(NULL);
}
+ lock_ReleaseMutex(&fidp->mx);
code = 0;
while ( code == 0 && count > 0 ) {
fd = smb_ChainFID(fd, inp);
fidp = smb_FindFID(vcp, fd, 0);
- if (!fidp) {
+ if (!fidp)
return CM_ERROR_BADFD;
- }
+ lock_ObtainMutex(&fidp->mx);
if (fidp->flags & SMB_FID_IOCTL) {
+ lock_ReleaseMutex(&fidp->mx);
code = smb_IoctlRead(fidp, vcp, inp, outp);
smb_ReleaseFID(fidp);
return code;
}
+ lock_ReleaseMutex(&fidp->mx);
{
LARGE_INTEGER LOffset, LLength;
fidp = smb_FindFID(vcp, 0, SMB_FLAG_CREATE);
osi_assert(fidp);
+ cm_HoldUser(userp);
+
+ lock_ObtainMutex(&fidp->mx);
+ /* always create it open for read/write */
+ fidp->flags |= (SMB_FID_OPENREAD | SMB_FID_OPENWRITE);
+
/* save a pointer to the vnode */
fidp->scp = scp;
/* and the user */
- cm_HoldUser(userp);
fidp->userp = userp;
-
- /* always create it open for read/write */
- fidp->flags |= (SMB_FID_OPENREAD | SMB_FID_OPENWRITE);
+ lock_ReleaseMutex(&fidp->mx);
- smb_ReleaseFID(fidp);
-
smb_SetSMBParm(outp, 0, fidp->fid);
smb_SetSMBDataLength(outp, 0);
cm_Open(scp, 0, userp);
+ smb_ReleaseFID(fidp);
cm_ReleaseUser(userp);
/* leave scp held since we put it in fidp->scp */
return 0;
/* try to find the file descriptor */
fd = smb_ChainFID(fd, inp);
fidp = smb_FindFID(vcp, fd, 0);
- if (!fidp || (fidp->flags & SMB_FID_IOCTL)) {
+
+ if (!fidp)
+ return CM_ERROR_BADFD;
+
+ lock_ObtainMutex(&fidp->mx);
+ if (fidp->flags & SMB_FID_IOCTL) {
+ lock_ReleaseMutex(&fidp->mx);
+ smb_ReleaseFID(fidp);
return CM_ERROR_BADFD;
}
+ lock_ReleaseMutex(&fidp->mx);
userp = smb_GetUser(vcp, inp);
#endif /* !DJGPP */
}
+ lock_ObtainMutex(&vcp->mx);
strcpy(vcp->rname, rname);
vcp->flags |= flags;
+ lock_ReleaseMutex(&vcp->mx);
/* Allocate slot in session arrays */
/* Re-use dead session if possible, otherwise add one more */
vcp->flags |= SMB_VCFLAG_ALREADYDEAD;
lock_ReleaseMutex(&vcp->mx);
smb_CleanupDeadVC(vcp);
- smb_ReleaseVC(vcp);
} else {
/* assert that we do not exceed the maximum number of sessions or NCBs.
* we should probably want to wait for a session to be freed in case
thrd_SetEvent(SessionEvents[session]);
}
}
-
smb_ReleaseVC(vcp);
/* unlock */
fidp = smb_FindFID(vcp, 0, SMB_FLAG_CREATE);
osi_assert(fidp);
+ cm_HoldUser(userp);
+ lock_ObtainMutex(&fidp->mx);
/* save a pointer to the vnode */
fidp->scp = scp;
/* and the user */
- cm_HoldUser(userp);
fidp->userp = userp;
/* compute open mode */
- if (openMode != 1) fidp->flags |= SMB_FID_OPENREAD;
+ if (openMode != 1)
+ fidp->flags |= SMB_FID_OPENREAD;
if (openMode == 1 || openMode == 2)
fidp->flags |= SMB_FID_OPENWRITE;
+ lock_ReleaseMutex(&fidp->mx);
smb_ReleaseFID(fidp);
*((LARGE_INTEGER *)op) = scp->length; op += 8; /* alloc size */
*((LARGE_INTEGER *)op) = scp->length; op += 8; /* EOF */
*((u_long *)op) = scp->linkCount; op += 4;
+ lock_ObtainMutex(&fidp->mx);
*op++ = ((fidp->flags & SMB_FID_DELONCLOSE) ? 1 : 0);
+ lock_ReleaseMutex(&fidp->mx);
*op++ = (scp->fileType == CM_SCACHETYPE_DIRECTORY ? 1 : 0);
*op++ = 0;
*op++ = 0;
return 0;
}
+ lock_ObtainMutex(&fidp->mx);
if (infoLevel == SMB_QUERY_FILE_STANDARD_INFO && !(fidp->flags & SMB_FID_OPENDELETE)) {
- smb_SendTran2Error(vcp, p, op, CM_ERROR_NOACCESS);
+ lock_ReleaseMutex(&fidp->mx);
smb_ReleaseFID(fidp);
+ smb_SendTran2Error(vcp, p, op, CM_ERROR_NOACCESS);
return 0;
}
if ((infoLevel == SMB_QUERY_FILE_EA_INFO || infoLevel == SMB_QUERY_FILE_NAME_INFO)
&& !(fidp->flags & SMB_FID_OPENWRITE)) {
- smb_SendTran2Error(vcp, p, op, CM_ERROR_NOACCESS);
+ lock_ReleaseMutex(&fidp->mx);
smb_ReleaseFID(fidp);
+ smb_SendTran2Error(vcp, p, op, CM_ERROR_NOACCESS);
return 0;
}
+ lock_ReleaseMutex(&fidp->mx);
osi_Log1(smb_logp, "T2 SFileInfo type 0x%x", infoLevel);
lastMod.dwLowDateTime != -1 && lastMod.dwHighDateTime != -1) {
attr.mask |= CM_ATTRMASK_CLIENTMODTIME;
smb_UnixTimeFromLargeSearchTime(&attr.clientModTime, &lastMod);
+ lock_ObtainMutex(&fidp->mx);
fidp->flags |= SMB_FID_MTIMESETDONE;
+ lock_ReleaseMutex(&fidp->mx);
}
attribute = *((u_long *)(p->datap + 32));
if (*((char *)(p->datap))) {
code = cm_CheckNTDelete(fidp->NTopen_dscp, scp, userp,
&req);
- if (code == 0)
+ if (code == 0) {
+ lock_ObtainMutex(&fidp->mx);
fidp->flags |= SMB_FID_DELONCLOSE;
- }
+ lock_ReleaseMutex(&fidp->mx);
+ }
+ }
else {
code = 0;
+ lock_ObtainMutex(&fidp->mx);
fidp->flags &= ~SMB_FID_DELONCLOSE;
+ lock_ReleaseMutex(&fidp->mx);
}
}
fidp = smb_FindFID(vcp, 0, SMB_FLAG_CREATE);
osi_assert(fidp);
+ cm_HoldUser(userp);
+ lock_ObtainMutex(&fidp->mx);
/* save a pointer to the vnode */
fidp->scp = scp;
/* also the user */
- cm_HoldUser(userp);
fidp->userp = userp;
/* compute open mode */
if (openMode == 1 || openMode == 2)
fidp->flags |= SMB_FID_OPENWRITE;
+ lock_ReleaseMutex(&fidp->mx);
smb_ReleaseFID(fidp);
cm_Open(scp, 0, userp);
fid = smb_ChainFID(fid, inp);
fidp = smb_FindFID(vcp, fid, 0);
- if (!fidp || (fidp->flags & SMB_FID_IOCTL)) {
+ if (!fidp)
+ return CM_ERROR_BADFD;
+
+ lock_ObtainMutex(&fidp->mx);
+ if (fidp->flags & SMB_FID_IOCTL) {
osi_Log0(smb_logp, "smb_ReceiveV3Locking BadFD");
- if (fidp)
- smb_ReleaseFID(fidp);
+ lock_ReleaseMutex(&fidp->mx);
+ smb_ReleaseFID(fidp);
return CM_ERROR_BADFD;
}
+ lock_ReleaseMutex(&fidp->mx);
+
/* set inp->fid so that later read calls in same msg can find fid */
inp->fid = fid;
fid = smb_ChainFID(fid, inp);
fidp = smb_FindFID(vcp, fid, 0);
- if (!fidp || (fidp->flags & SMB_FID_IOCTL)) {
- if (fidp)
- smb_ReleaseFID(fidp);
+ if (!fidp)
+ return CM_ERROR_BADFD;
+
+ lock_ObtainMutex(&fidp->mx);
+ if (fidp->flags & SMB_FID_IOCTL) {
+ lock_ReleaseMutex(&fidp->mx);
+ smb_ReleaseFID(fidp);
return CM_ERROR_BADFD;
}
+ lock_ReleaseMutex(&fidp->mx);
userp = smb_GetUser(vcp, inp);
fid = smb_ChainFID(fid, inp);
fidp = smb_FindFID(vcp, fid, 0);
- if (!fidp || (fidp->flags & SMB_FID_IOCTL)) {
- if (fidp)
- smb_ReleaseFID(fidp);
+ if (!fidp)
+ return CM_ERROR_BADFD;
+
+ lock_ObtainMutex(&fidp->mx);
+ if (fidp->flags & SMB_FID_IOCTL) {
+ lock_ReleaseMutex(&fidp->mx);
+ smb_ReleaseFID(fidp);
return CM_ERROR_BADFD;
}
+ lock_ReleaseMutex(&fidp->mx);
userp = smb_GetUser(vcp, inp);
/* set inp->fid so that later read calls in same msg can find fid */
inp->fid = fd;
+ lock_ObtainMutex(&fidp->mx);
if (fidp->flags & SMB_FID_IOCTL) {
+ lock_ReleaseMutex(&fidp->mx);
code = smb_IoctlV3Read(fidp, vcp, inp, outp);
smb_ReleaseFID(fidp);
return code;
}
+ lock_ReleaseMutex(&fidp->mx);
userp = smb_GetUser(vcp, inp);
lock_ReleaseMutex(&scp->mx);
if (code) {
- fidp->flags = SMB_FID_DELETE;
+ /* shouldn't this be smb_CloseFID() fidp->flags = SMB_FID_DELETE; */
+ smb_CloseFID(vcp, fidp, NULL, 0);
smb_ReleaseFID(fidp);
cm_ReleaseSCache(scp);
}
}
+ lock_ObtainMutex(&fidp->mx);
/* save a pointer to the vnode */
fidp->scp = scp; /* Hold transfered to fidp->scp and no longer needed */
fidp->NTopen_pathp = strdup(lastNamep);
}
fidp->NTopen_wholepathp = realPathp;
+ lock_ReleaseMutex(&fidp->mx);
/* we don't need this any longer */
if (dscp) {
lock_ReleaseMutex(&scp->mx);
if (code) {
- fidp->flags = SMB_FID_DELETE;
+ /* Shouldn't this be smb_CloseFID()? fidp->flags = SMB_FID_DELETE; */
+ smb_CloseFID(vcp, fidp, NULL, 0);
smb_ReleaseFID(fidp);
cm_ReleaseSCache(scp);
}
}
+ lock_ObtainMutex(&fidp->mx);
/* save a pointer to the vnode */
fidp->scp = scp;
fidp->NTopen_pathp = strdup(lastNamep);
}
fidp->NTopen_wholepathp = realPathp;
+ lock_ReleaseMutex(&fidp->mx);
/* we don't need this any longer */
if (dscp)