return vcp;
}
-int smb_IsStarMask(clientchar_t *maskp)
+static int smb_Is8Dot3StarMask(clientchar_t *maskp)
{
int i;
clientchar_t tc;
return 0;
}
+static int smb_IsStarMask(clientchar_t *maskp)
+{
+ int i;
+ clientchar_t tc;
+
+ while (*maskp) {
+ tc = *maskp++;
+ if (tc == _C('?') || tc == _C('*') || tc == _C('>'))
+ return 1;
+ }
+ return 0;
+}
+
#ifdef DEBUG_SMB_REFCOUNT
void smb_ReleaseVCInternalDbg(smb_vc_t *vcp, char * file, long line)
#define smb_ReleaseVCInternal(a) smb_ReleaseVCInternalDbg(a, file, line)
matchType = SMB_FINDSHARE_EXACT_MATCH;
else
matchType = SMB_FINDSHARE_PARTIAL_MATCH;
- if(vrock->match) free(vrock->match);
+ if(vrock->match)
+ free(vrock->match);
vrock->match = cm_FsStringToClientStringAlloc(dep->name, -1, NULL);
vrock->matchType = matchType;
char **chainpp, int flags)
{
size_t cb;
+ afs_uint32 type = *inp++;
- if (*inp++ != 0x4)
- return NULL;
+ /*
+ * The first byte specifies the type of the input string.
+ * CIFS TR 1.0 3.2.10. This function only parses null terminated
+ * strings.
+ */
+ switch (type) {
+ /* Length Counted */
+ case 0x1: /* Data Block */
+ case 0x5: /* Variable Block */
+ cb = *inp++ << 16 | *inp++;
+ break;
+
+ /* Null-terminated string */
+ case 0x4: /* ASCII */
+ case 0x3: /* Pathname */
+ case 0x2: /* Dialect */
+ cb = sizeof(pktp->data) - (inp - pktp->data);
+ if (inp < pktp->data || inp >= pktp->data + sizeof(pktp->data)) {
+#ifdef DEBUG_UNICODE
+ DebugBreak();
+#endif
+ cb = sizeof(pktp->data);
+ }
+ break;
+
+ default:
+ return NULL; /* invalid input */
+ }
#ifdef SMB_UNICODE
- if (!WANTS_UNICODE(pktp))
+ if (type == 0x2 /* Dialect */ || !WANTS_UNICODE(pktp))
flags |= SMB_STRF_FORCEASCII;
#endif
- cb = sizeof(pktp->data) - (inp - pktp->data);
- if (inp < pktp->data || inp >= pktp->data + sizeof(pktp->data)) {
-#ifdef DEBUG_UNICODE
- DebugBreak();
-#endif
- cb = sizeof(pktp->data);
- }
return smb_ParseStringBuf(pktp->data, &pktp->stringsp, inp, &cb, chainpp, flags);
}
/* map CM_ERROR_* errors to NT 32-bit status codes */
/* NT Status codes are listed in ntstatus.h not winerror.h */
- if (code == CM_ERROR_NOSUCHCELL) {
+ if (code == 0) {
+ NTStatus = 0;
+ }
+ else if (code == CM_ERROR_NOSUCHCELL) {
NTStatus = 0xC000000FL; /* No such file */
}
else if (code == CM_ERROR_NOSUCHVOLUME) {
NTStatus = 0xC0000033L; /* Object name invalid */
}
else if (code == CM_ERROR_WOULDBLOCK) {
- NTStatus = 0xC0000055L; /* Lock not granted */
+ NTStatus = 0xC00000D8L; /* Can't wait */
}
else if (code == CM_ERROR_SHARING_VIOLATION) {
NTStatus = 0xC0000043L; /* Sharing violation */
}
else if (code == CM_ERROR_LOCK_NOT_GRANTED) {
NTStatus = 0xC0000055L; /* Lock Not Granted */
+ } else if (code == ENOMEM) {
+ NTStatus = 0xC0000017L; /* Out of Memory */
} else {
NTStatus = 0xC0982001L; /* SMB non-specific error */
}
char *tbp;
tbp = smb_GetSMBData(inp, NULL);
pathp = smb_ParseASCIIBlock(inp, tbp, &tbp, SMB_STRF_ANSIPATH);
+ if (!pathp)
+ return CM_ERROR_BADSMB;
}
tp = cm_ClientStrRChr(pathp, '\\');
if (!tp)
tidp = smb_FindTID(vcp, newTid, SMB_FLAG_CREATE);
uidp = smb_FindUID(vcp, ((smb_t *)inp)->uid, 0);
+ if (!uidp)
+ return CM_ERROR_BADSMB;
userp = smb_GetUserFromUID(uidp);
shareFound = smb_FindShare(vcp, uidp, shareName, &sharePath);
- if (uidp)
- smb_ReleaseUID(uidp);
+ smb_ReleaseUID(uidp);
if (!shareFound) {
smb_ReleaseTID(tidp, FALSE);
return CM_ERROR_BADSHARENAME;
tp = smb_GetSMBData(inp, NULL);
pathp = smb_ParseASCIIBlock(inp, tp, &tp,
SMB_STRF_ANSIPATH|SMB_STRF_FORCEASCII);
- osi_assertx(pathp != NULL, "null path");
+ if (!pathp)
+ return CM_ERROR_BADSMB;
statBlockp = smb_ParseVblBlock(tp, &tp, &statLen);
osi_assertx(statBlockp != NULL, "null statBlock");
if (statLen == 0) {
tp = smb_GetSMBData(inp, NULL);
pathp = smb_ParseASCIIBlock(inp, tp, &tp,
SMB_STRF_ANSIPATH|SMB_STRF_FORCEASCII);
- inCookiep = smb_ParseVblBlock(tp, &tp, &dataLength);
+ if (!pathp)
+ return CM_ERROR_BADSMB;
- /* bail out if request looks bad */
- if (!tp || !pathp) {
+ inCookiep = smb_ParseVblBlock(tp, &tp, &dataLength);
+ if (!tp)
return CM_ERROR_BADSMB;
- }
/* We can handle long names */
if (vcp->flags & SMB_VCFLAG_USENT)
memcpy(dsp->mask, mask, 12);
/* track if this is likely to match a lot of entries */
- if (smb_IsStarMask(mask))
+ if (smb_Is8Dot3StarMask(mask))
starPattern = 1;
else
starPattern = 0;
/* Compute 8.3 name if necessary */
actualName = cm_FsStringToClientStringAlloc(dep->name, -1, NULL);
if (dep->fid.vnode != 0 && !cm_Is8Dot3(actualName)) {
- free(actualName);
+ if (actualName)
+ free(actualName);
cm_Gen8Dot3NameInt(dep->name, &dep->fid, shortName, &shortNameEnd);
actualName = shortName;
free_actualName = 0;
pdata = smb_GetSMBData(inp, NULL);
pathp = smb_ParseASCIIBlock(inp, pdata, NULL, SMB_STRF_ANSIPATH);
if (!pathp)
- return CM_ERROR_BADFD;
+ return CM_ERROR_BADSMB;
osi_Log1(smb_logp, "SMB receive check path %S",
osi_LogSaveClientString(smb_logp, pathp));
datap = smb_GetSMBData(inp, NULL);
pathp = smb_ParseASCIIBlock(inp, datap, NULL, SMB_STRF_ANSIPATH);
+ if (!pathp)
+ return CM_ERROR_BADSMB;
osi_Log1(smb_logp, "SMB receive open file [%S]", osi_LogSaveClientString(smb_logp, pathp));
tp = smb_GetSMBData(inp, NULL);
pathp = smb_ParseASCIIBlock(inp, tp, &tp, SMB_STRF_ANSIPATH);
+ if (!pathp)
+ return CM_ERROR_BADSMB;
osi_Log1(smb_logp, "SMB receive unlink %S",
osi_LogSaveClientString(smb_logp, pathp));
osi_Log0(smb_logp, "Can't rename. Target already exists");
code = CM_ERROR_EXISTS;
}
-
- if (tmpscp != NULL)
- cm_ReleaseSCache(tmpscp);
-
goto done;
}
tp = smb_GetSMBData(inp, NULL);
oldPathp = smb_ParseASCIIBlock(inp, tp, &tp, SMB_STRF_ANSIPATH);
+ if (!oldPathp)
+ return CM_ERROR_BADSMB;
newPathp = smb_ParseASCIIBlock(inp, tp, &tp, SMB_STRF_ANSIPATH);
+ if (!newPathp)
+ return CM_ERROR_BADSMB;
osi_Log2(smb_logp, "smb rename [%S] to [%S]",
osi_LogSaveClientString(smb_logp, oldPathp),
tp = smb_GetSMBData(inp, NULL);
pathp = smb_ParseASCIIBlock(inp, tp, &tp, SMB_STRF_ANSIPATH);
+ if (!pathp)
+ return CM_ERROR_BADSMB;
spacep = inp->spacep;
smb_StripLastComponent(spacep->wdata, &lastNamep, pathp);
tp = smb_GetSMBData(inp, NULL);
pathp = smb_ParseASCIIBlock(inp, tp, &tp, SMB_STRF_ANSIPATH);
-
- if (cm_ClientStrCmp(pathp, _C("\\")) == 0)
- return CM_ERROR_EXISTS;
+ if (!pathp)
+ return CM_ERROR_BADSMB;
spacep = inp->spacep;
smb_StripLastComponent(spacep->wdata, &lastNamep, pathp);
+ if (cm_ClientStrCmp(pathp, _C("\\")) == 0)
+ return CM_ERROR_EXISTS;
+
userp = smb_GetUserFromVCP(vcp, inp);
caseFold = CM_FLAG_CASEFOLD;
tp = smb_GetSMBData(inp, NULL);
pathp = smb_ParseASCIIBlock(inp, tp, &tp, SMB_STRF_ANSIPATH);
+ if (!pathp)
+ return CM_ERROR_BADSMB;
if (!cm_IsValidClientString(pathp)) {
#ifdef DEBUG
if (smbp->com == 0x1d) {
/* Special handling for Write Raw */
raw_write_cont_t rwc;
- EVENT_HANDLE rwevent;
- char eventName[MAX_PATH];
smb_DispatchPacket(vcp, bufp, outbufp, ncbp, &rwc);
if (rwc.code == 0) {
- rwevent = thrd_CreateEvent(NULL, FALSE, FALSE, TEXT("smb_Server() rwevent"));
+ EVENT_HANDLE rwevent;
+ char eventName[MAX_PATH];
+
+ snprintf(eventName, MAX_PATH, "smb_Server() rwevent %d", myIdx);
+ rwevent = thrd_CreateEvent(NULL, FALSE, FALSE, eventName);
if ( GetLastError() == ERROR_ALREADY_EXISTS )
osi_Log1(smb_logp, "Event Object Already Exists: %s", osi_LogSaveString(smb_logp, eventName));
+
ncbp->ncb_command = NCBRECV | ASYNCH;
ncbp->ncb_lsn = (unsigned char) vcp->lsn;
ncbp->ncb_lana_num = vcp->lana;