From: Jeffrey Altman Date: Sat, 3 Apr 2004 08:17:52 +0000 (+0000) Subject: reformatting-20040402 X-Git-Tag: openafs-devel-1_3_63~17 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=c38e32c7786e7a913cb431c81d5ffc9dc0a30cf1;p=packages%2Fo%2Fopenafs.git reformatting-20040402 Reformatting of the source code. Minor editorial changes to comments. --- diff --git a/src/WINNT/afsd/smb.c b/src/WINNT/afsd/smb.c index 32862cd04..9efb4bf76 100644 --- a/src/WINNT/afsd/smb.c +++ b/src/WINNT/afsd/smb.c @@ -123,7 +123,7 @@ typedef struct raw_write_cont { #ifndef DJGPP char *buf; #else - dos_ptr buf; + dos_ptr buf; #endif /* DJGPP */ int writeMode; long alreadyWritten; @@ -164,7 +164,7 @@ smb_waitingLock_t *smb_allWaitingLocks; /* forward decl */ void smb_DispatchPacket(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp, - NCB *ncbp, raw_write_cont_t *rwcp); + NCB *ncbp, raw_write_cont_t *rwcp); void smb_NetbiosInit(); #ifdef DJGPP #ifndef AFS_WIN95_ENV @@ -340,10 +340,10 @@ unsigned int smb_Attributes(cm_scache_t *scp) unsigned int attrs; if (scp->fileType == CM_SCACHETYPE_DIRECTORY - || scp->fileType == CM_SCACHETYPE_MOUNTPOINT) - attrs = SMB_ATTR_DIRECTORY; + || scp->fileType == CM_SCACHETYPE_MOUNTPOINT) + attrs = SMB_ATTR_DIRECTORY; else - attrs = 0; + attrs = 0; /* * We used to mark a file RO if it was in an RO volume, but that @@ -353,7 +353,7 @@ unsigned int smb_Attributes(cm_scache_t *scp) if ((scp->unixModeBits & 0222) == 0 || (scp->flags & CM_SCACHEFLAG_RO)) #endif if ((scp->unixModeBits & 0222) == 0) - attrs |= SMB_ATTR_READONLY; /* turn on read-only flag */ + attrs |= SMB_ATTR_READONLY; /* turn on read-only flag */ return attrs; } @@ -382,42 +382,42 @@ unsigned int smb_IsDotFile(char *lastComp) { static int ExtractBits(WORD bits, short start, short len) { - int end; - WORD num; + int end; + WORD num; - end = start + len; + end = start + len; - num = bits << (16 - end); - num = num >> ((16 - end) + start); - - return (int)num; + num = bits << (16 - end); + num = num >> ((16 - end) + start); + + return (int)num; } #ifndef DJGPP void ShowUnixTime(char *FuncName, long unixTime) { - FILETIME ft; - WORD wDate, wTime; + FILETIME ft; + WORD wDate, wTime; smb_LargeSearchTimeFromUnixTime(&ft, unixTime); - if (!FileTimeToDosDateTime(&ft, &wDate, &wTime)) - osi_Log1(afsd_logp, "Failed to convert filetime to dos datetime: %d", GetLastError()); - else { - int day, month, year, sec, min, hour; - char msg[256]; - - day = ExtractBits(wDate, 0, 5); - month = ExtractBits(wDate, 5, 4); - year = ExtractBits(wDate, 9, 7) + 1980; - - sec = ExtractBits(wTime, 0, 5); - min = ExtractBits(wTime, 5, 6); - hour = ExtractBits(wTime, 11, 5); - - sprintf(msg, "%s = %02d-%02d-%04d %02d:%02d:%02d", FuncName, month, day, year, hour, min, sec); - osi_Log1(afsd_logp, "%s", osi_LogSaveString(afsd_logp, msg)); - } + if (!FileTimeToDosDateTime(&ft, &wDate, &wTime)) + osi_Log1(afsd_logp, "Failed to convert filetime to dos datetime: %d", GetLastError()); + else { + int day, month, year, sec, min, hour; + char msg[256]; + + day = ExtractBits(wDate, 0, 5); + month = ExtractBits(wDate, 5, 4); + year = ExtractBits(wDate, 9, 7) + 1980; + + sec = ExtractBits(wTime, 0, 5); + min = ExtractBits(wTime, 5, 6); + hour = ExtractBits(wTime, 11, 5); + + sprintf(msg, "%s = %02d-%02d-%04d %02d:%02d:%02d", FuncName, month, day, year, hour, min, sec); + osi_Log1(afsd_logp, "%s", osi_LogSaveString(afsd_logp, msg)); + } } #endif /* DJGPP */ @@ -431,13 +431,13 @@ void GetTimeZoneInfo(BOOL *pDST, LONG *pDstBias, LONG *pBias) /* Get the time zone info. NT uses this to calc if we are in DST. */ GetTimeZoneInformation(&timeZoneInformation); - /* Return the daylight bias */ - *pDstBias = timeZoneInformation.DaylightBias; + /* Return the daylight bias */ + *pDstBias = timeZoneInformation.DaylightBias; - /* Return the bias */ - *pBias = timeZoneInformation.Bias; + /* Return the bias */ + *pBias = timeZoneInformation.Bias; - /* Now determine if DST is being observed */ + /* Now determine if DST is being observed */ /* Get the UTC (GMT) time */ GetSystemTime(&utc); @@ -468,51 +468,51 @@ void GetTimeZoneInfo(BOOL *pDST, LONG *pDstBias, LONG *pBias) /* Determine if we are observing daylight savings time */ void GetTimeZoneInfo(BOOL *pDST, LONG *pDstBias, LONG *pBias) { - struct timeb t; + struct timeb t; - ftime(&t); - *pDST = t.dstflag; - *pDstBias = -60; /* where can this be different? */ - *pBias = t.timezone; + ftime(&t); + *pDST = t.dstflag; + *pDstBias = -60; /* where can this be different? */ + *pBias = t.timezone; } #endif /* DJGPP */ void CompensateForSmbClientLastWriteTimeBugs(long *pLastWriteTime) { - BOOL dst; /* Will be TRUE if observing DST */ - LONG dstBias; /* Offset from local time if observing DST */ - LONG bias; /* Offset from GMT for local time */ - - /* - * This function will adjust the last write time to compensate - * for two bugs in the smb client: - * - * 1) During Daylight Savings Time, the LastWriteTime is ahead - * in time by the DaylightBias (ignoring the sign - the - * DaylightBias is always stored as a negative number). If - * the DaylightBias is -60, then the LastWriteTime will be - * ahead by 60 minutes. - * - * 2) If the local time zone is a positive offset from GMT, then - * the LastWriteTime will be the correct local time plus the - * Bias (ignoring the sign - a positive offset from GMT is - * always stored as a negative Bias). If the Bias is -120, - * then the LastWriteTime will be ahead by 120 minutes. - * - * These bugs can occur at the same time. - */ + BOOL dst; /* Will be TRUE if observing DST */ + LONG dstBias; /* Offset from local time if observing DST */ + LONG bias; /* Offset from GMT for local time */ - GetTimeZoneInfo(&dst, &dstBias, &bias); - - /* First adjust for DST */ - if (dst) - *pLastWriteTime -= (-dstBias * 60); /* Convert dstBias to seconds */ - - /* Now adjust for a positive offset from GMT (a negative bias). */ - if (bias < 0) - *pLastWriteTime -= (-bias * 60); /* Convert bias to seconds */ -} + /* + * This function will adjust the last write time to compensate + * for two bugs in the smb client: + * + * 1) During Daylight Savings Time, the LastWriteTime is ahead + * in time by the DaylightBias (ignoring the sign - the + * DaylightBias is always stored as a negative number). If + * the DaylightBias is -60, then the LastWriteTime will be + * ahead by 60 minutes. + * + * 2) If the local time zone is a positive offset from GMT, then + * the LastWriteTime will be the correct local time plus the + * Bias (ignoring the sign - a positive offset from GMT is + * always stored as a negative Bias). If the Bias is -120, + * then the LastWriteTime will be ahead by 120 minutes. + * + * These bugs can occur at the same time. + */ + + GetTimeZoneInfo(&dst, &dstBias, &bias); + + /* First adjust for DST */ + if (dst) + *pLastWriteTime -= (-dstBias * 60); /* Convert dstBias to seconds */ + + /* Now adjust for a positive offset from GMT (a negative bias). */ + if (bias < 0) + *pLastWriteTime -= (-bias * 60); /* Convert bias to seconds */ +} /* * Calculate the difference (in seconds) between local time and GMT. @@ -580,22 +580,22 @@ void smb_LargeSearchTimeFromUnixTime(FILETIME *largeTimep, long unixTime) #else /* DJGPP */ void smb_LargeSearchTimeFromUnixTime(FILETIME *largeTimep, long unixTime) { - /* unixTime: seconds since 1/1/1970 00:00:00 GMT */ - /* FILETIME: 100ns intervals since 1/1/1601 00:00:00 ??? */ - LARGE_INTEGER *ft = (LARGE_INTEGER *) largeTimep; - LARGE_INTEGER ut; - int leap_years = 89; /* leap years betw 1/1/1601 and 1/1/1970 */ - - /* set ft to number of 100ns intervals betw 1/1/1601 and 1/1/1970 GMT */ - *ft = ConvertLongToLargeInteger(((EPOCH_YEAR-1601) * 365 + leap_years) + /* unixTime: seconds since 1/1/1970 00:00:00 GMT */ + /* FILETIME: 100ns intervals since 1/1/1601 00:00:00 ??? */ + LARGE_INTEGER *ft = (LARGE_INTEGER *) largeTimep; + LARGE_INTEGER ut; + int leap_years = 89; /* leap years betw 1/1/1601 and 1/1/1970 */ + + /* set ft to number of 100ns intervals betw 1/1/1601 and 1/1/1970 GMT */ + *ft = ConvertLongToLargeInteger(((EPOCH_YEAR-1601) * 365 + leap_years) * 24 * 60); - *ft = LargeIntegerMultiplyByLong(*ft, 60); - *ft = LargeIntegerMultiplyByLong(*ft, 10000000); + *ft = LargeIntegerMultiplyByLong(*ft, 60); + *ft = LargeIntegerMultiplyByLong(*ft, 10000000); - /* add unix time */ - ut = ConvertLongToLargeInteger(unixTime); - ut = LargeIntegerMultiplyByLong(ut, 10000000); - *ft = LargeIntegerAdd(*ft, ut); + /* add unix time */ + ut = ConvertLongToLargeInteger(unixTime); + ut = LargeIntegerMultiplyByLong(ut, 10000000); + *ft = LargeIntegerAdd(*ft, ut); } #endif /* !DJGPP */ @@ -625,69 +625,68 @@ void smb_UnixTimeFromLargeSearchTime(long *unixTimep, FILETIME *largeTimep) #else /* DJGPP */ void smb_UnixTimeFromLargeSearchTime(long *unixTimep, FILETIME *largeTimep) { - /* unixTime: seconds since 1/1/1970 00:00:00 GMT */ - /* FILETIME: 100ns intervals since 1/1/1601 00:00:00 GMT? */ - LARGE_INTEGER *ft = (LARGE_INTEGER *) largeTimep; - LARGE_INTEGER a; - int leap_years = 89; - - /* set to number of 100ns intervals betw 1/1/1601 and 1/1/1970 */ - a = ConvertLongToLargeInteger(((EPOCH_YEAR-1601) * 365 + leap_years) * 24 * 60 -); - a = LargeIntegerMultiplyByLong(a, 60); - a = LargeIntegerMultiplyByLong(a, 10000000); - - /* subtract it from ft */ - a = LargeIntegerSubtract(*ft, a); - - /* divide down to seconds */ - *unixTimep = LargeIntegerDivideByLong(a, 10000000); + /* unixTime: seconds since 1/1/1970 00:00:00 GMT */ + /* FILETIME: 100ns intervals since 1/1/1601 00:00:00 GMT? */ + LARGE_INTEGER *ft = (LARGE_INTEGER *) largeTimep; + LARGE_INTEGER a; + int leap_years = 89; + + /* set to number of 100ns intervals betw 1/1/1601 and 1/1/1970 */ + a = ConvertLongToLargeInteger(((EPOCH_YEAR-1601) * 365 + leap_years) * 24 * 60); + a = LargeIntegerMultiplyByLong(a, 60); + a = LargeIntegerMultiplyByLong(a, 10000000); + + /* subtract it from ft */ + a = LargeIntegerSubtract(*ft, a); + + /* divide down to seconds */ + *unixTimep = LargeIntegerDivideByLong(a, 10000000); } #endif /* !DJGPP */ void smb_SearchTimeFromUnixTime(long *dosTimep, long unixTime) { struct tm *ltp; - int dosDate; - int dosTime; - struct tm localJunk; + int dosDate; + int dosTime; + struct tm localJunk; ltp = localtime((time_t*) &unixTime); /* if we fail, make up something */ - if (!ltp) { + if (!ltp) { ltp = &localJunk; - localJunk.tm_year = 89 - 20; - localJunk.tm_mon = 4; - localJunk.tm_mday = 12; - localJunk.tm_hour = 0; - localJunk.tm_min = 0; - localJunk.tm_sec = 0; - } + localJunk.tm_year = 89 - 20; + localJunk.tm_mon = 4; + localJunk.tm_mday = 12; + localJunk.tm_hour = 0; + localJunk.tm_min = 0; + localJunk.tm_sec = 0; + } dosDate = ((ltp->tm_year-80)<<9) | ((ltp->tm_mon+1) << 5) | (ltp->tm_mday); - dosTime = (ltp->tm_hour<<11) | (ltp->tm_min << 5) | (ltp->tm_sec / 2); - *dosTimep = (dosDate<<16) | dosTime; -} + dosTime = (ltp->tm_hour<<11) | (ltp->tm_min << 5) | (ltp->tm_sec / 2); + *dosTimep = (dosDate<<16) | dosTime; +} void smb_UnixTimeFromSearchTime(long *unixTimep, long searchTime) { unsigned short dosDate; - unsigned short dosTime; + unsigned short dosTime; struct tm localTm; - dosDate = searchTime & 0xffff; - dosTime = (searchTime >> 16) & 0xffff; + dosDate = searchTime & 0xffff; + dosTime = (searchTime >> 16) & 0xffff; - localTm.tm_year = 80 + ((dosDate>>9) & 0x3f); - localTm.tm_mon = ((dosDate >> 5) & 0xf) - 1; /* January is 0 in localTm */ - localTm.tm_mday = (dosDate) & 0x1f; - localTm.tm_hour = (dosTime>>11) & 0x1f; - localTm.tm_min = (dosTime >> 5) & 0x3f; - localTm.tm_sec = (dosTime & 0x1f) * 2; - localTm.tm_isdst = -1; /* compute whether DST in effect */ - - *unixTimep = mktime(&localTm); + localTm.tm_year = 80 + ((dosDate>>9) & 0x3f); + localTm.tm_mon = ((dosDate >> 5) & 0xf) - 1; /* January is 0 in localTm */ + localTm.tm_mday = (dosDate) & 0x1f; + localTm.tm_hour = (dosTime>>11) & 0x1f; + localTm.tm_min = (dosTime >> 5) & 0x3f; + localTm.tm_sec = (dosTime & 0x1f) * 2; + localTm.tm_isdst = -1; /* compute whether DST in effect */ + + *unixTimep = mktime(&localTm); } void smb_DosUTimeFromUnixTime(long *dosUTimep, long unixTime) @@ -700,7 +699,7 @@ void smb_UnixTimeFromDosUTime(long *unixTimep, long dosTime) #ifndef DJGPP *unixTimep = dosTime + smb_localZero; #else /* DJGPP */ - /* dosTime seems to be already adjusted for GMT */ + /* dosTime seems to be already adjusted for GMT */ *unixTimep = dosTime; #endif /* !DJGPP */ } @@ -713,36 +712,36 @@ smb_vc_t *smb_FindVC(unsigned short lsn, int flags, int lana) for(vcp = smb_allVCsp; vcp; vcp=vcp->nextp) { if (lsn == vcp->lsn && lana == vcp->lana) { vcp->refCount++; - break; + break; } - } - if (!vcp && (flags & SMB_FLAG_CREATE)) { + } + if (!vcp && (flags & SMB_FLAG_CREATE)) { vcp = malloc(sizeof(*vcp)); - memset(vcp, 0, sizeof(*vcp)); - vcp->refCount = 1; - vcp->tidCounter = 1; - vcp->fidCounter = 1; - vcp->uidCounter = 1; /* UID 0 is reserved for blank user */ - vcp->nextp = smb_allVCsp; - smb_allVCsp = vcp; - lock_InitializeMutex(&vcp->mx, "vc_t mutex"); - vcp->lsn = lsn; - vcp->lana = lana; - } - lock_ReleaseWrite(&smb_rctLock); - return vcp; + memset(vcp, 0, sizeof(*vcp)); + vcp->refCount = 1; + vcp->tidCounter = 1; + vcp->fidCounter = 1; + vcp->uidCounter = 1; /* UID 0 is reserved for blank user */ + vcp->nextp = smb_allVCsp; + smb_allVCsp = vcp; + lock_InitializeMutex(&vcp->mx, "vc_t mutex"); + vcp->lsn = lsn; + vcp->lana = lana; + } + lock_ReleaseWrite(&smb_rctLock); + return vcp; } int smb_IsStarMask(char *maskp) { int i; - char tc; + char tc; for(i=0; i<11; i++) { tc = *maskp++; - if (tc == '?' || tc == '*' || tc == '>') return 1; - } - return 0; + if (tc == '?' || tc == '*' || tc == '>') return 1; + } + return 0; } void smb_ReleaseVC(smb_vc_t *vcp) @@ -767,47 +766,47 @@ smb_tid_t *smb_FindTID(smb_vc_t *vcp, unsigned short tid, int flags) for(tidp = vcp->tidsp; tidp; tidp = tidp->nextp) { if (tid == tidp->tid) { tidp->refCount++; - break; - } - } - if (!tidp && (flags & SMB_FLAG_CREATE)) { + break; + } + } + if (!tidp && (flags & SMB_FLAG_CREATE)) { tidp = malloc(sizeof(*tidp)); - memset(tidp, 0, sizeof(*tidp)); - tidp->nextp = vcp->tidsp; - tidp->refCount = 1; - tidp->vcp = vcp; - vcp->tidsp = tidp; - lock_InitializeMutex(&tidp->mx, "tid_t mutex"); - tidp->tid = tid; - } - lock_ReleaseWrite(&smb_rctLock); - return tidp; -} + memset(tidp, 0, sizeof(*tidp)); + tidp->nextp = vcp->tidsp; + tidp->refCount = 1; + tidp->vcp = vcp; + vcp->tidsp = tidp; + lock_InitializeMutex(&tidp->mx, "tid_t mutex"); + tidp->tid = tid; + } + lock_ReleaseWrite(&smb_rctLock); + return tidp; +} void smb_ReleaseTID(smb_tid_t *tidp) { smb_tid_t *tp; - smb_tid_t **ltpp; - cm_user_t *userp; + smb_tid_t **ltpp; + cm_user_t *userp; userp = NULL; lock_ObtainWrite(&smb_rctLock); osi_assert(tidp->refCount-- > 0); - if (tidp->refCount == 0 && (tidp->flags & SMB_TIDFLAG_DELETE)) { + if (tidp->refCount == 0 && (tidp->flags & SMB_TIDFLAG_DELETE)) { ltpp = &tidp->vcp->tidsp; for(tp = *ltpp; tp; ltpp = &tp->nextp, tp = *ltpp) { if (tp == tidp) break; - } - osi_assert(tp != NULL); - *ltpp = tp->nextp; - lock_FinalizeMutex(&tidp->mx); - userp = tidp->userp; /* remember to drop ref later */ - } - lock_ReleaseWrite(&smb_rctLock); - if (userp) { - cm_ReleaseUser(userp); + } + osi_assert(tp != NULL); + *ltpp = tp->nextp; + lock_FinalizeMutex(&tidp->mx); + userp = tidp->userp; /* remember to drop ref later */ } -} + lock_ReleaseWrite(&smb_rctLock); + if (userp) { + cm_ReleaseUser(userp); + } +} smb_user_t *smb_FindUID(smb_vc_t *vcp, unsigned short uid, int flags) { @@ -820,21 +819,21 @@ smb_user_t *smb_FindUID(smb_vc_t *vcp, unsigned short uid, int flags) osi_LogEvent("AFS smb_FindUID (Find by UID)",NULL," VCP[%x] found-uid[%d] name[%s]",(int)vcp,uidp->userID,(uidp->unp) ? uidp->unp->name : ""); break; } - } - if (!uidp && (flags & SMB_FLAG_CREATE)) { + } + if (!uidp && (flags & SMB_FLAG_CREATE)) { uidp = malloc(sizeof(*uidp)); - memset(uidp, 0, sizeof(*uidp)); - uidp->nextp = vcp->usersp; - uidp->refCount = 1; - uidp->vcp = vcp; - vcp->usersp = uidp; - lock_InitializeMutex(&uidp->mx, "uid_t mutex"); - uidp->userID = uid; - osi_LogEvent("AFS smb_FindUID (Find by UID)",NULL,"VCP[%x] new-uid[%d] name[%s]",(int)vcp,uidp->userID,(uidp->unp ? uidp->unp->name : "")); - } - lock_ReleaseWrite(&smb_rctLock); - return uidp; -} + memset(uidp, 0, sizeof(*uidp)); + uidp->nextp = vcp->usersp; + uidp->refCount = 1; + uidp->vcp = vcp; + vcp->usersp = uidp; + lock_InitializeMutex(&uidp->mx, "uid_t mutex"); + uidp->userID = uid; + osi_LogEvent("AFS smb_FindUID (Find by UID)",NULL,"VCP[%x] new-uid[%d] name[%s]",(int)vcp,uidp->userID,(uidp->unp ? uidp->unp->name : "")); + } + lock_ReleaseWrite(&smb_rctLock); + return uidp; +} smb_username_t *smb_FindUserByName(char *usern, char *machine, int flags) { @@ -843,24 +842,24 @@ smb_username_t *smb_FindUserByName(char *usern, char *machine, int flags) lock_ObtainWrite(&smb_rctLock); for(unp = usernamesp; unp; unp = unp->nextp) { if (stricmp(unp->name, usern) == 0 && - stricmp(unp->machine, machine) == 0) { + stricmp(unp->machine, machine) == 0) { unp->refCount++; break; } } - if (!unp && (flags & SMB_FLAG_CREATE)) { - unp = malloc(sizeof(*unp)); - memset(unp, 0, sizeof(*unp)); - unp->refCount = 1; - unp->nextp = usernamesp; - unp->name = strdup(usern); - unp->machine = strdup(machine); - usernamesp = unp; - lock_InitializeMutex(&unp->mx, "username_t mutex"); - } + if (!unp && (flags & SMB_FLAG_CREATE)) { + unp = malloc(sizeof(*unp)); + memset(unp, 0, sizeof(*unp)); + unp->refCount = 1; + unp->nextp = usernamesp; + unp->name = strdup(usern); + unp->machine = strdup(machine); + usernamesp = unp; + lock_InitializeMutex(&unp->mx, "username_t mutex"); + } lock_ReleaseWrite(&smb_rctLock); return unp; -} +} smb_user_t *smb_FindUserByNameThisSession(smb_vc_t *vcp, char *usern) { @@ -868,44 +867,44 @@ smb_user_t *smb_FindUserByNameThisSession(smb_vc_t *vcp, char *usern) lock_ObtainWrite(&smb_rctLock); for(uidp = vcp->usersp; uidp; uidp = uidp->nextp) { - if (!uidp->unp) + if (!uidp->unp) continue; - if (stricmp(uidp->unp->name, usern) == 0) { + if (stricmp(uidp->unp->name, usern) == 0) { uidp->refCount++; osi_LogEvent("AFS smb_FindUserByNameThisSession",NULL,"VCP[%x] uid[%d] match-name[%s]",(int)vcp,uidp->userID,usern); break; - } else + } else continue; - } + } lock_ReleaseWrite(&smb_rctLock); return uidp; } void smb_ReleaseUID(smb_user_t *uidp) { smb_user_t *up; - smb_user_t **lupp; - cm_user_t *userp; + smb_user_t **lupp; + cm_user_t *userp; userp = NULL; lock_ObtainWrite(&smb_rctLock); osi_assert(uidp->refCount-- > 0); - if (uidp->refCount == 0 && (uidp->flags & SMB_USERFLAG_DELETE)) { + if (uidp->refCount == 0 && (uidp->flags & SMB_USERFLAG_DELETE)) { lupp = &uidp->vcp->usersp; for(up = *lupp; up; lupp = &up->nextp, up = *lupp) { if (up == uidp) break; - } - osi_assert(up != NULL); - *lupp = up->nextp; - lock_FinalizeMutex(&uidp->mx); - if (uidp->unp) - userp = uidp->unp->userp; /* remember to drop ref later */ - } + } + osi_assert(up != NULL); + *lupp = up->nextp; + lock_FinalizeMutex(&uidp->mx); + if (uidp->unp) + userp = uidp->unp->userp; /* remember to drop ref later */ + } lock_ReleaseWrite(&smb_rctLock); - if (userp) { + if (userp) { cm_ReleaseUserVCRef(userp); - cm_ReleaseUser(userp); - } -} + cm_ReleaseUser(userp); + } +} /* retrieve a held reference to a user structure corresponding to an incoming * request. @@ -914,22 +913,22 @@ void smb_ReleaseUID(smb_user_t *uidp) cm_user_t *smb_GetUser(smb_vc_t *vcp, smb_packet_t *inp) { smb_user_t *uidp; - cm_user_t *up; - smb_t *smbp; - + cm_user_t *up; + smb_t *smbp; + smbp = (smb_t *) inp; - uidp = smb_FindUID(vcp, smbp->uid, 0); - if ((!uidp) || (!uidp->unp)) - return NULL; + uidp = smb_FindUID(vcp, smbp->uid, 0); + if ((!uidp) || (!uidp->unp)) + return NULL; lock_ObtainMutex(&uidp->mx); - up = uidp->unp->userp; - cm_HoldUser(up); + up = uidp->unp->userp; + cm_HoldUser(up); lock_ReleaseMutex(&uidp->mx); - smb_ReleaseUID(uidp); + smb_ReleaseUID(uidp); - return up; + return up; } /* @@ -956,8 +955,10 @@ char *smb_GetTIDPath(smb_vc_t *vcp, unsigned short tid) */ int smb_ChainFID(int fid, smb_packet_t *inp) { - if (inp->fid == 0 || inp->inCount == 0) return fid; - else return inp->fid; + if (inp->fid == 0 || inp->inCount == 0) + return fid; + else + return inp->fid; } /* are we a priv'd user? What does this mean on NT? */ @@ -973,11 +974,11 @@ smb_fid_t *smb_FindFID(smb_vc_t *vcp, unsigned short fid, int flags) int newFid; /* figure out if we need to allocate a new file ID */ - if (fid == 0) { - newFid = 1; - fid = vcp->fidCounter; + if (fid == 0) { + newFid = 1; + fid = vcp->fidCounter; } - else newFid = 0; + else newFid = 0; lock_ObtainWrite(&smb_rctLock); retry: @@ -985,7 +986,8 @@ retry: if (fid == fidp->fid) { if (newFid) { fid++; - if (fid == 0) fid = 1; + if (fid == 0) + fid = 1; goto retry; } fidp->refCount++; @@ -1048,7 +1050,8 @@ void smb_ReleaseFID(smb_fid_t *fidp) lock_ReleaseWrite(&smb_rctLock); /* now release the scache structure */ - if (scp) cm_ReleaseSCache(scp); + if (scp) + cm_ReleaseSCache(scp); } /* @@ -1089,64 +1092,65 @@ char VNLCComputerName[] = "%LCCOMPUTERNAME%"; /* List available shares */ int smb_ListShares() { - char sbmtpath[256]; - char pathName[256]; - char shareBuf[4096]; - int num_shares=0; - char *this_share; - int len; - char *p; - int print_afs = 0; - int code; - - /*strcpy(shareNameList[num_shares], "all"); - strcpy(pathNameList[num_shares++], "/afs");*/ - fprintf(stderr, "The following shares are available:\n"); - fprintf(stderr, "Share Name (AFS Path)\n"); - fprintf(stderr, "---------------------\n"); - fprintf(stderr, "\\\\%s\\%-16s (%s)\n", smb_localNamep, "ALL", cm_mountRoot); + char sbmtpath[256]; + char pathName[256]; + char shareBuf[4096]; + int num_shares=0; + char *this_share; + int len; + char *p; + int print_afs = 0; + int code; + + /*strcpy(shareNameList[num_shares], "all"); + strcpy(pathNameList[num_shares++], "/afs");*/ + fprintf(stderr, "The following shares are available:\n"); + fprintf(stderr, "Share Name (AFS Path)\n"); + fprintf(stderr, "---------------------\n"); + fprintf(stderr, "\\\\%s\\%-16s (%s)\n", smb_localNamep, "ALL", cm_mountRoot); #ifndef DJGPP code = GetWindowsDirectory(sbmtpath, sizeof(sbmtpath)); - if (code == 0 || code > sizeof(sbmtpath)) return -1; + if (code == 0 || code > sizeof(sbmtpath)) return -1; #else - strcpy(sbmtpath, cm_confDir); + strcpy(sbmtpath, cm_confDir); #endif /* !DJGPP */ - strcat(sbmtpath, "/afsdsbmt.ini"); - len = GetPrivateProfileString("AFS Submounts", NULL, NULL, - shareBuf, sizeof(shareBuf), - sbmtpath); - if (len == 0) { - return num_shares; - } + strcat(sbmtpath, "/afsdsbmt.ini"); + len = GetPrivateProfileString("AFS Submounts", NULL, NULL, + shareBuf, sizeof(shareBuf), + sbmtpath); + if (len == 0) { + return num_shares; + } - this_share = shareBuf; - do - { - print_afs = 0; - /*strcpy(shareNameList[num_shares], this_share);*/ - len = GetPrivateProfileString("AFS Submounts", this_share, - NULL, - pathName, 256, - sbmtpath); - if (!len) return num_shares; - p = pathName; - if (strncmp(p, cm_mountRoot, strlen(cm_mountRoot)) != 0) + this_share = shareBuf; + do + { + print_afs = 0; + /*strcpy(shareNameList[num_shares], this_share);*/ + len = GetPrivateProfileString("AFS Submounts", this_share, + NULL, + pathName, 256, + sbmtpath); + if (!len) + return num_shares; + p = pathName; + if (strncmp(p, cm_mountRoot, strlen(cm_mountRoot)) != 0) print_afs = 1; - while (*p) { + while (*p) { if (*p == '\\') *p = '/'; /* change to / */ p++; - } + } - fprintf(stderr, "\\\\%s\\%-16s (%s%s)\n", - smb_localNamep, this_share, (print_afs ? cm_mountRoot : "\0"), - pathName); - num_shares++; - while (*this_share != 0) this_share++; /* find next NUL */ - this_share++; /* skip past the NUL */ - } while (*this_share != 0); /* stop at final NUL */ + fprintf(stderr, "\\\\%s\\%-16s (%s%s)\n", + smb_localNamep, this_share, (print_afs ? cm_mountRoot : "\0"), + pathName); + num_shares++; + while (*this_share != 0) this_share++; /* find next NUL */ + this_share++; /* skip past the NUL */ + } while (*this_share != 0); /* stop at final NUL */ - return num_shares; + return num_shares; } /* find a shareName in the table of submounts */ @@ -1176,7 +1180,7 @@ int smb_FindShare(smb_vc_t *vcp, smb_packet_t *inp, char *shareName, * world to do so. */ code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSConfigKeyName, - 0, KEY_QUERY_VALUE, &parmKey); + 0, KEY_QUERY_VALUE, &parmKey); if (code == ERROR_SUCCESS) { len = sizeof(allSubmount); code = RegQueryValueEx(parmKey, "AllSubmount", NULL, NULL, @@ -1267,8 +1271,9 @@ int smb_FindShare(smb_vc_t *vcp, smb_packet_t *inp, char *shareName, { if (cm_GetCell_Gen(shareName, temp, CM_FLAG_CREATE)) { - if (!stricmp(shareName, temp)) { /* no partial matches allowed */ - sprintf(pathName,"/%s/",shareName); + int len = min(strlen(shareName), strlen(temp)); + if (!_strnicmp(shareName, temp, len)) { /* partial matches allowed */ + sprintf(pathName,"/%s/",temp); *pathNamep = strdup(strlwr(pathName)); return 1; } @@ -1286,22 +1291,22 @@ smb_dirSearch_t *smb_FindDirSearchNL(long cookie) { smb_dirSearch_t *dsp; - for(dsp = smb_firstDirSearchp; dsp; dsp = (smb_dirSearch_t *) osi_QNext(&dsp->q)) { + for(dsp = smb_firstDirSearchp; dsp; dsp = (smb_dirSearch_t *) osi_QNext(&dsp->q)) { if (dsp->cookie == cookie) { if (dsp != smb_firstDirSearchp) { /* move to head of LRU queue, too, if we're not already there */ - if (smb_lastDirSearchp == (smb_dirSearch_t *) &dsp->q) - smb_lastDirSearchp = (smb_dirSearch_t *) - osi_QPrev(&dsp->q); + if (smb_lastDirSearchp == (smb_dirSearch_t *) &dsp->q) + smb_lastDirSearchp = (smb_dirSearch_t *) + osi_QPrev(&dsp->q); osi_QRemove((osi_queue_t **) &smb_firstDirSearchp, &dsp->q); - osi_QAdd((osi_queue_t **) &smb_firstDirSearchp, &dsp->q); - if (!smb_lastDirSearchp) - smb_lastDirSearchp = (smb_dirSearch_t *) &dsp->q; + osi_QAdd((osi_queue_t **) &smb_firstDirSearchp, &dsp->q); + if (!smb_lastDirSearchp) + smb_lastDirSearchp = (smb_dirSearch_t *) &dsp->q; } dsp->refCount++; - break; - } - } + break; + } + } return dsp; } @@ -1310,39 +1315,39 @@ void smb_DeleteDirSearch(smb_dirSearch_t *dsp) lock_ObtainWrite(&smb_globalLock); dsp->flags |= SMB_DIRSEARCH_DELETE; lock_ReleaseWrite(&smb_globalLock); - lock_ObtainMutex(&dsp->mx); + lock_ObtainMutex(&dsp->mx); if(dsp->scp != NULL) { - lock_ObtainMutex(&dsp->scp->mx); - if (dsp->flags & SMB_DIRSEARCH_BULKST) { - dsp->flags &= ~SMB_DIRSEARCH_BULKST; + lock_ObtainMutex(&dsp->scp->mx); + if (dsp->flags & SMB_DIRSEARCH_BULKST) { + dsp->flags &= ~SMB_DIRSEARCH_BULKST; dsp->scp->flags &= ~CM_SCACHEFLAG_BULKSTATTING; dsp->scp->bulkStatProgress = hones; - } - lock_ReleaseMutex(&dsp->scp->mx); - } - lock_ReleaseMutex(&dsp->mx); + } + lock_ReleaseMutex(&dsp->scp->mx); + } + lock_ReleaseMutex(&dsp->mx); } void smb_ReleaseDirSearch(smb_dirSearch_t *dsp) { cm_scache_t *scp; - scp = NULL; + scp = NULL; lock_ObtainWrite(&smb_globalLock); osi_assert(dsp->refCount-- > 0); - if (dsp->refCount == 0 && (dsp->flags & SMB_DIRSEARCH_DELETE)) { + 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); + smb_lastDirSearchp = (smb_dirSearch_t *) osi_QPrev(&smb_lastDirSearchp->q); osi_QRemove((osi_queue_t **) &smb_firstDirSearchp, &dsp->q); - lock_FinalizeMutex(&dsp->mx); - scp = dsp->scp; - free(dsp); - } + lock_FinalizeMutex(&dsp->mx); + scp = dsp->scp; + free(dsp); + } lock_ReleaseWrite(&smb_globalLock); - + /* do this now to avoid spurious locking hierarchy creation */ - if (scp) cm_ReleaseSCache(scp); + if (scp) cm_ReleaseSCache(scp); } /* find a dir search structure by cookie value, and return it held */ @@ -1353,7 +1358,7 @@ smb_dirSearch_t *smb_FindDirSearch(long cookie) lock_ObtainWrite(&smb_globalLock); dsp = smb_FindDirSearchNL(cookie); lock_ReleaseWrite(&smb_globalLock); - return dsp; + return dsp; } /* GC some dir search entries, in the address space expected by the specific protocol. @@ -1364,36 +1369,37 @@ void smb_GCDirSearches(int isV3) { smb_dirSearch_t *prevp; smb_dirSearch_t *tp; - smb_dirSearch_t *victimsp[SMB_DIRSEARCH_GCMAX]; - int victimCount; - int i; + smb_dirSearch_t *victimsp[SMB_DIRSEARCH_GCMAX]; + int victimCount; + int i; victimCount = 0; /* how many have we got so far */ for(tp = smb_lastDirSearchp; tp; tp=prevp) { - prevp = (smb_dirSearch_t *) osi_QPrev(&tp->q); /* we'll move tp from queue, so - * do this early. - */ + /* we'll move tp from queue, so + * do this early. + */ + prevp = (smb_dirSearch_t *) osi_QPrev(&tp->q); /* if no one is using this guy, and we're either in the new protocol, - * or we're in the old one and this is a small enough ID to be useful - * to the old protocol, GC this guy. - */ + * or we're in the old one and this is a small enough ID to be useful + * to the old protocol, GC this guy. + */ if (tp->refCount == 0 && (isV3 || tp->cookie <= 255)) { /* hold and delete */ tp->flags |= SMB_DIRSEARCH_DELETE; - victimsp[victimCount++] = tp; - tp->refCount++; - } + victimsp[victimCount++] = tp; + tp->refCount++; + } /* don't do more than this */ - if (victimCount >= SMB_DIRSEARCH_GCMAX) break; - } + if (victimCount >= SMB_DIRSEARCH_GCMAX) break; + } /* now release them */ - lock_ReleaseWrite(&smb_globalLock); - for(i = 0; i < victimCount; i++) { + lock_ReleaseWrite(&smb_globalLock); + for(i = 0; i < victimCount; i++) { smb_ReleaseDirSearch(victimsp[i]); - } - lock_ObtainWrite(&smb_globalLock); + } + lock_ObtainWrite(&smb_globalLock); } /* function for allocating a dir search entry. We need these to remember enough context @@ -1406,48 +1412,48 @@ smb_dirSearch_t *smb_NewDirSearch(int isV3) { smb_dirSearch_t *dsp; int counter; - int maxAllowed; + int maxAllowed; lock_ObtainWrite(&smb_globalLock); counter = 0; /* what's the biggest ID allowed in this version of the protocol */ - if (isV3) maxAllowed = 65535; - else maxAllowed = 255; + if (isV3) maxAllowed = 65535; + else maxAllowed = 255; while(1) { /* twice so we have enough tries to find guys we GC after one pass; - * 10 extra is just in case I mis-counted. - */ - if (++counter > 2*maxAllowed+10) osi_panic("afsd: dir search cookie leak", - __FILE__, __LINE__); - if (smb_dirSearchCounter > maxAllowed) { - smb_dirSearchCounter = 1; - smb_GCDirSearches(isV3); /* GC some (drops global lock) */ - } + * 10 extra is just in case I mis-counted. + */ + if (++counter > 2*maxAllowed+10) osi_panic("afsd: dir search cookie leak", + __FILE__, __LINE__); + if (smb_dirSearchCounter > maxAllowed) { + smb_dirSearchCounter = 1; + smb_GCDirSearches(isV3); /* GC some (drops global lock) */ + } dsp = smb_FindDirSearchNL(smb_dirSearchCounter); - if (dsp) { + if (dsp) { /* don't need to watch for refcount zero and deleted, since - * we haven't dropped the global lock. - */ + * we haven't dropped the global lock. + */ dsp->refCount--; - ++smb_dirSearchCounter; - continue; - } + ++smb_dirSearchCounter; + continue; + } - dsp = malloc(sizeof(*dsp)); - memset(dsp, 0, sizeof(*dsp)); - osi_QAdd((osi_queue_t **) &smb_firstDirSearchp, &dsp->q); - if (!smb_lastDirSearchp) smb_lastDirSearchp = (smb_dirSearch_t *) &dsp->q; - dsp->cookie = smb_dirSearchCounter; + dsp = malloc(sizeof(*dsp)); + memset(dsp, 0, sizeof(*dsp)); + osi_QAdd((osi_queue_t **) &smb_firstDirSearchp, &dsp->q); + if (!smb_lastDirSearchp) smb_lastDirSearchp = (smb_dirSearch_t *) &dsp->q; + dsp->cookie = smb_dirSearchCounter; ++smb_dirSearchCounter; - dsp->refCount = 1; - lock_InitializeMutex(&dsp->mx, "cm_dirSearch_t"); - dsp->lastTime = osi_Time(); - break; - } + dsp->refCount = 1; + lock_InitializeMutex(&dsp->mx, "cm_dirSearch_t"); + dsp->lastTime = osi_Time(); + break; + } lock_ReleaseWrite(&smb_globalLock); - return dsp; + return dsp; } static smb_packet_t *GetPacket(void) @@ -1622,18 +1628,18 @@ unsigned char *smb_GetSMBData(smb_packet_t *smbp, int *nbytesp) */ void smb_SetSMBDataLength(smb_packet_t *smbp, unsigned int dsize) { - unsigned char *afterParmsp; + unsigned char *afterParmsp; afterParmsp = smbp->wctp + ((*smbp->wctp)<<1) + 1; *afterParmsp++ = dsize & 0xff; - *afterParmsp = (dsize>>8) & 0xff; + *afterParmsp = (dsize>>8) & 0xff; } /* return the parm'th parameter in the smbp packet */ unsigned int smb_GetSMBParm(smb_packet_t *smbp, int parm) { - int parmCount; + int parmCount; unsigned char *parmDatap; parmCount = *smbp->wctp; @@ -1645,17 +1651,17 @@ unsigned int smb_GetSMBParm(smb_packet_t *smbp, int parm) char s[100]; h = RegisterEventSource(NULL, AFS_DAEMON_EVENT_NAME); sprintf(s, "Bad SMB param %d out of %d, ncb len %d", - parm, parmCount, smbp->ncb_length); + parm, parmCount, smbp->ncb_length); ptbuf[0] = s; ReportEvent(h, EVENTLOG_ERROR_TYPE, 0, 1006, NULL, - 1, smbp->ncb_length, ptbuf, smbp); + 1, smbp->ncb_length, ptbuf, smbp); DeregisterEventSource(h); #else /* DJGPP */ - char s[100]; + char s[100]; - sprintf(s, "Bad SMB param %d out of %d, ncb len %d", - parm, parmCount, smbp->ncb_length); - osi_Log0(afsd_logp, s); + sprintf(s, "Bad SMB param %d out of %d, ncb len %d", + parm, parmCount, smbp->ncb_length); + osi_Log0(afsd_logp, s); #endif /* !DJGPP */ osi_panic(s, __FILE__, __LINE__); } @@ -1667,7 +1673,7 @@ unsigned int smb_GetSMBParm(smb_packet_t *smbp, int parm) /* return the parm'th parameter in the smbp packet */ unsigned int smb_GetSMBOffsetParm(smb_packet_t *smbp, int parm, int offset) { - int parmCount; + int parmCount; unsigned char *parmDatap; parmCount = *smbp->wctp; @@ -1679,25 +1685,25 @@ unsigned int smb_GetSMBOffsetParm(smb_packet_t *smbp, int parm, int offset) char s[100]; h = RegisterEventSource(NULL, AFS_DAEMON_EVENT_NAME); sprintf(s, "Bad SMB param %d offset %d out of %d, ncb len %d", - parm, offset, parmCount, smbp->ncb_length); + parm, offset, parmCount, smbp->ncb_length); ptbuf[0] = s; ReportEvent(h, EVENTLOG_ERROR_TYPE, 0, 1006, NULL, - 1, smbp->ncb_length, ptbuf, smbp); + 1, smbp->ncb_length, ptbuf, smbp); DeregisterEventSource(h); #else /* DJGPP */ - char s[100]; + char s[100]; - sprintf(s, "Bad SMB param %d offset %d out of %d, " - "ncb len %d", - parm, offset, parmCount, smbp->ncb_length); - osi_Log0(afsd_logp, s); + sprintf(s, "Bad SMB param %d offset %d out of %d, " + "ncb len %d", + parm, offset, parmCount, smbp->ncb_length); + osi_Log0(afsd_logp, s); #endif /* !DJGPP */ osi_panic(s, __FILE__, __LINE__); } parmDatap = smbp->wctp + (2*parm) + 1 + offset; - return parmDatap[0] + (parmDatap[1] << 8); + return parmDatap[0] + (parmDatap[1] << 8); } void smb_SetSMBParm(smb_packet_t *smbp, int slot, unsigned int parmValue) @@ -1707,9 +1713,9 @@ void smb_SetSMBParm(smb_packet_t *smbp, int slot, unsigned int parmValue) /* make sure we have enough slots */ if (*smbp->wctp <= slot) *smbp->wctp = slot+1; - parmDatap = smbp->wctp + 2*slot + 1 + smbp->oddByte; - *parmDatap++ = parmValue & 0xff; - *parmDatap = (parmValue>>8) & 0xff; + parmDatap = smbp->wctp + 2*slot + 1 + smbp->oddByte; + *parmDatap++ = parmValue & 0xff; + *parmDatap = (parmValue>>8) & 0xff; } void smb_SetSMBParmLong(smb_packet_t *smbp, int slot, unsigned int parmValue) @@ -1760,80 +1766,84 @@ void smb_StripLastComponent(char *outPathp, char **lastComponentp, char *inPathp { char *lastSlashp; - lastSlashp = strrchr(inPathp, '\\'); + lastSlashp = strrchr(inPathp, '\\'); if (lastComponentp) *lastComponentp = lastSlashp; - if (lastSlashp) { + if (lastSlashp) { while (1) { - if (inPathp == lastSlashp) break; + if (inPathp == lastSlashp) + break; *outPathp++ = *inPathp++; - } - *outPathp++ = 0; - } + } + *outPathp++ = 0; + } else { *outPathp++ = 0; - } + } } unsigned char *smb_ParseASCIIBlock(unsigned char *inp, char **chainpp) { - if (*inp++ != 0x4) return NULL; - if (chainpp) { + if (*inp++ != 0x4) + return NULL; + if (chainpp) { *chainpp = inp + strlen(inp) + 1; /* skip over null-terminated string */ - } - return inp; + } + return inp; } unsigned char *smb_ParseVblBlock(unsigned char *inp, char **chainpp, int *lengthp) { int tlen; - if (*inp++ != 0x5) return NULL; - tlen = inp[0] + (inp[1]<<8); - inp += 2; /* skip length field */ + if (*inp++ != 0x5) + return NULL; + tlen = inp[0] + (inp[1]<<8); + inp += 2; /* skip length field */ - if (chainpp) { + if (chainpp) { *chainpp = inp + tlen; - } + } - if (lengthp) *lengthp = tlen; + if (lengthp) + *lengthp = tlen; - return inp; -} + return inp; +} /* format a packet as a response */ void smb_FormatResponsePacket(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *op) { smb_t *outp; - smb_t *inSmbp; + smb_t *inSmbp; - outp = (smb_t *) op; + outp = (smb_t *) op; - /* zero the basic structure through the smb_wct field, and zero the data - * size field, assuming that wct stays zero; otherwise, you have to - * explicitly set the data size field, too. - */ + /* zero the basic structure through the smb_wct field, and zero the data + * size field, assuming that wct stays zero; otherwise, you have to + * explicitly set the data size field, too. + */ inSmbp = (smb_t *) inp; memset(outp, 0, sizeof(smb_t)+2); - outp->id[0] = 0xff; - outp->id[1] = 'S'; - outp->id[2] = 'M'; - outp->id[3] = 'B'; + outp->id[0] = 0xff; + outp->id[1] = 'S'; + outp->id[2] = 'M'; + outp->id[3] = 'B'; if (inp) { outp->com = inSmbp->com; - outp->tid = inSmbp->tid; - outp->pid = inSmbp->pid; - outp->uid = inSmbp->uid; - outp->mid = inSmbp->mid; + outp->tid = inSmbp->tid; + outp->pid = inSmbp->pid; + outp->uid = inSmbp->uid; + outp->mid = inSmbp->mid; outp->res[0] = inSmbp->res[0]; outp->res[1] = inSmbp->res[1]; - op->inCom = inSmbp->com; + op->inCom = inSmbp->com; } - outp->reb = 0x80; /* SERVER_RESP */ + outp->reb = 0x80; /* SERVER_RESP */ outp->flg2 = 0x1; /* KNOWS_LONG_NAMES */ /* copy fields in generic packet area */ - op->wctp = &outp->wct; + op->wctp = &outp->wct; } /* send a (probably response) packet; vcp tells us to whom to send it. @@ -1842,45 +1852,45 @@ void smb_FormatResponsePacket(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *op void smb_SendPacket(smb_vc_t *vcp, smb_packet_t *inp) { NCB *ncbp; - int extra; - long code; - unsigned char *tp; + int extra; + long code; + unsigned char *tp; int localNCB = 0; #ifdef DJGPP - dos_ptr dos_ncb; + dos_ptr dos_ncb; #endif /* DJGPP */ - ncbp = inp->ncbp; + ncbp = inp->ncbp; if (ncbp == NULL) { ncbp = GetNCB(); localNCB = 1; } #ifdef DJGPP - dos_ncb = ((smb_ncb_t *)ncbp)->dos_ncb; + dos_ncb = ((smb_ncb_t *)ncbp)->dos_ncb; #endif /* DJGPP */ memset((char *)ncbp, 0, sizeof(NCB)); - extra = 2 * (*inp->wctp); /* space used by parms, in bytes */ + extra = 2 * (*inp->wctp); /* space used by parms, in bytes */ tp = inp->wctp + 1+ extra; /* points to count of data bytes */ - extra += tp[0] + (tp[1]<<8); - extra += ((unsigned int)inp->wctp - (unsigned int)inp->data); /* distance to last wct field */ - extra += 3; /* wct and length fields */ + extra += tp[0] + (tp[1]<<8); + extra += ((unsigned int)inp->wctp - (unsigned int)inp->data); /* distance to last wct field */ + extra += 3; /* wct and length fields */ - ncbp->ncb_length = extra; /* bytes to send */ - ncbp->ncb_lsn = (unsigned char) vcp->lsn; /* vc to use */ + ncbp->ncb_length = extra; /* bytes to send */ + ncbp->ncb_lsn = (unsigned char) vcp->lsn; /* vc to use */ ncbp->ncb_lana_num = vcp->lana; - ncbp->ncb_command = NCBSEND; /* op means send data */ + ncbp->ncb_command = NCBSEND; /* op means send data */ #ifndef DJGPP - ncbp->ncb_buffer = (char *) inp;/* packet */ - code = Netbios(ncbp); + ncbp->ncb_buffer = (char *) inp;/* packet */ + code = Netbios(ncbp); #else /* DJGPP */ - ncbp->ncb_buffer = inp->dos_pkt;/* packet */ - ((smb_ncb_t*)ncbp)->orig_pkt = inp; + ncbp->ncb_buffer = inp->dos_pkt;/* packet */ + ((smb_ncb_t*)ncbp)->orig_pkt = inp; - /* copy header information from virtual to DOS address space */ - dosmemput((char*)inp, SMB_PACKETSIZE, inp->dos_pkt); - code = Netbios(ncbp, dos_ncb); + /* copy header information from virtual to DOS address space */ + dosmemput((char*)inp, SMB_PACKETSIZE, inp->dos_pkt); + code = Netbios(ncbp, dos_ncb); #endif /* !DJGPP */ if (code != 0) @@ -1895,60 +1905,60 @@ void smb_MapNTError(long code, unsigned long *NTStatusp) unsigned long NTStatus; /* map CM_ERROR_* errors to NT 32-bit status codes */ - if (code == CM_ERROR_NOSUCHCELL) { + if (code == CM_ERROR_NOSUCHCELL) { NTStatus = 0xC000000FL; /* No such file */ - } - else if (code == CM_ERROR_NOSUCHVOLUME) { + } + else if (code == CM_ERROR_NOSUCHVOLUME) { NTStatus = 0xC000000FL; /* No such file */ - } - else if (code == CM_ERROR_TIMEDOUT) { - NTStatus = 0xC00000CFL; /* Sharing Paused */ - } - else if (code == CM_ERROR_RETRY) { + } + else if (code == CM_ERROR_TIMEDOUT) { + NTStatus = 0xC00000CFL; /* Sharing Paused */ + } + else if (code == CM_ERROR_RETRY) { NTStatus = 0xC000022DL; /* Retry */ - } - else if (code == CM_ERROR_NOACCESS) { + } + else if (code == CM_ERROR_NOACCESS) { NTStatus = 0xC0000022L; /* Access denied */ - } + } else if (code == CM_ERROR_READONLY) { NTStatus = 0xC00000A2L; /* Write protected */ - } - else if (code == CM_ERROR_NOSUCHFILE) { + } + else if (code == CM_ERROR_NOSUCHFILE) { NTStatus = 0xC000000FL; /* No such file */ - } + } else if (code == CM_ERROR_NOSUCHPATH) { NTStatus = 0xC000003AL; /* Object path not found */ - } - else if (code == CM_ERROR_TOOBIG) { + } + else if (code == CM_ERROR_TOOBIG) { NTStatus = 0xC000007BL; /* Invalid image format */ - } - else if (code == CM_ERROR_INVAL) { + } + else if (code == CM_ERROR_INVAL) { NTStatus = 0xC000000DL; /* Invalid parameter */ - } - else if (code == CM_ERROR_BADFD) { + } + else if (code == CM_ERROR_BADFD) { NTStatus = 0xC0000008L; /* Invalid handle */ - } - else if (code == CM_ERROR_BADFDOP) { + } + else if (code == CM_ERROR_BADFDOP) { NTStatus = 0xC0000022L; /* Access denied */ - } - else if (code == CM_ERROR_EXISTS) { + } + else if (code == CM_ERROR_EXISTS) { NTStatus = 0xC0000035L; /* Object name collision */ - } + } else if (code == CM_ERROR_NOTEMPTY) { NTStatus = 0xC0000101L; /* Directory not empty */ - } - else if (code == CM_ERROR_CROSSDEVLINK) { + } + else if (code == CM_ERROR_CROSSDEVLINK) { NTStatus = 0xC00000D4L; /* Not same device */ - } + } else if (code == CM_ERROR_NOTDIR) { NTStatus = 0xC0000103L; /* Not a directory */ - } - else if (code == CM_ERROR_ISDIR) { + } + else if (code == CM_ERROR_ISDIR) { NTStatus = 0xC00000BAL; /* File is a directory */ - } - else if (code == CM_ERROR_BADOP) { + } + else if (code == CM_ERROR_BADOP) { NTStatus = 0xC09820FFL; /* SMB no support */ - } + } else if (code == CM_ERROR_BADSHARENAME) { NTStatus = 0xC00000CCL; /* Bad network name */ } @@ -1989,11 +1999,11 @@ void smb_MapNTError(long code, unsigned long *NTStatusp) else if (code == CM_ERROR_BUFFERTOOSMALL) { NTStatus = 0xC0000023L; /* Buffer too small */ } - else { + else { NTStatus = 0xC0982001L; /* SMB non-specific error */ - } + } - *NTStatusp = NTStatus; + *NTStatusp = NTStatus; osi_Log2(afsd_logp, "SMB SEND code %x as NT %x", code, NTStatus); } @@ -2001,81 +2011,81 @@ void smb_MapCoreError(long code, smb_vc_t *vcp, unsigned short *scodep, unsigned char *classp) { unsigned char class; - unsigned short error; + unsigned short error; /* map CM_ERROR_* errors to SMB errors */ - if (code == CM_ERROR_NOSUCHCELL) { + if (code == CM_ERROR_NOSUCHCELL) { class = 1; - error = 3; /* bad path */ - } - else if (code == CM_ERROR_NOSUCHVOLUME) { + error = 3; /* bad path */ + } + else if (code == CM_ERROR_NOSUCHVOLUME) { class = 1; - error = 3; /* bad path */ - } - else if (code == CM_ERROR_TIMEDOUT) { + error = 3; /* bad path */ + } + else if (code == CM_ERROR_TIMEDOUT) { class = 2; - error = 81; /* server is paused */ - } - else if (code == CM_ERROR_RETRY) { + error = 81; /* server is paused */ + } + else if (code == CM_ERROR_RETRY) { class = 2; /* shouldn't happen */ - error = 1; - } - else if (code == CM_ERROR_NOACCESS) { + error = 1; + } + else if (code == CM_ERROR_NOACCESS) { class = 2; - error = 4; /* bad access */ - } + error = 4; /* bad access */ + } else if (code == CM_ERROR_READONLY) { class = 3; error = 19; /* read only */ } - else if (code == CM_ERROR_NOSUCHFILE) { + else if (code == CM_ERROR_NOSUCHFILE) { class = 1; - error = 2; /* ENOENT! */ - } + error = 2; /* ENOENT! */ + } else if (code == CM_ERROR_NOSUCHPATH) { class = 1; error = 3; /* Bad path */ } - else if (code == CM_ERROR_TOOBIG) { + else if (code == CM_ERROR_TOOBIG) { class = 1; error = 11; /* bad format */ - } - else if (code == CM_ERROR_INVAL) { + } + else if (code == CM_ERROR_INVAL) { class = 2; /* server non-specific error code */ - error = 1; - } - else if (code == CM_ERROR_BADFD) { + error = 1; + } + else if (code == CM_ERROR_BADFD) { class = 1; - error = 6; /* invalid file handle */ - } - else if (code == CM_ERROR_BADFDOP) { + error = 6; /* invalid file handle */ + } + else if (code == CM_ERROR_BADFDOP) { class = 1; /* invalid op on FD */ - error = 5; - } - else if (code == CM_ERROR_EXISTS) { + error = 5; + } + else if (code == CM_ERROR_EXISTS) { class = 1; - error = 80; /* file already exists */ - } + error = 80; /* file already exists */ + } else if (code == CM_ERROR_NOTEMPTY) { class = 1; error = 5; /* delete directory not empty */ } - else if (code == CM_ERROR_CROSSDEVLINK) { + else if (code == CM_ERROR_CROSSDEVLINK) { class = 1; - error = 17; /* EXDEV */ - } + error = 17; /* EXDEV */ + } else if (code == CM_ERROR_NOTDIR) { class = 1; /* bad path */ - error = 3; - } - else if (code == CM_ERROR_ISDIR) { + error = 3; + } + else if (code == CM_ERROR_ISDIR) { class = 1; /* access denied; DOS doesn't have a good match */ - error = 5; - } - else if (code == CM_ERROR_BADOP) { + error = 5; + } + else if (code == CM_ERROR_BADOP) { class = 2; - error = 65535; - } + error = 65535; + } else if (code == CM_ERROR_BADSHARENAME) { class = 2; error = 6; @@ -2136,18 +2146,18 @@ void smb_MapCoreError(long code, smb_vc_t *vcp, unsigned short *scodep, class = 1; error = 18; /* no files in search */ } - else if (code == CM_ERROR_RENAME_IDENTICAL) { - class = 1; - error = 183; /* Samba uses this */ - } - else { + else if (code == CM_ERROR_RENAME_IDENTICAL) { + class = 1; + error = 183; /* Samba uses this */ + } + else { class = 2; - error = 1; - } + error = 1; + } *scodep = error; - *classp = class; - osi_Log3(afsd_logp, "SMB SEND code %x as SMB %d: %d", code, class, error); + *classp = class; + osi_Log3(afsd_logp, "SMB SEND code %x as SMB %d: %d", code, class, error); } long smb_SendCoreBadOp(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp) @@ -2315,26 +2325,26 @@ long smb_ReceiveCoreUnlockRecord(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t long smb_ReceiveNegotiate(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp) { char *namep; - int coreProtoIndex; - int v3ProtoIndex; + int coreProtoIndex; + int v3ProtoIndex; int NTProtoIndex; - int protoIndex; /* index we're using */ - int namex; - int dbytes; + int protoIndex; /* index we're using */ + int namex; + int dbytes; int entryLength; - int tcounter; + int tcounter; char protocol_array[10][1024]; /* protocol signature of the client */ osi_Log1(afsd_logp, "SMB receive negotiate; %d + 1 ongoing ops", - ongoingOps - 1); + ongoingOps - 1); if (!isGateway) { if (active_vcp) { DWORD now = GetCurrentTime(); if (now - last_msg_time >= 30000 - && now - last_msg_time <= 90000) { + && now - last_msg_time <= 90000) { osi_Log1(afsd_logp, - "Setting dead_vcp %x", active_vcp); + "Setting dead_vcp %x", active_vcp); dead_vcp = active_vcp; dead_vcp->flags |= SMB_VCFLAG_ALREADYDEAD; } @@ -2343,26 +2353,26 @@ long smb_ReceiveNegotiate(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp) inp->flags |= SMB_PACKETFLAG_PROFILE_UPDATE_OK; - namep = smb_GetSMBData(inp, &dbytes); - namex = 0; + namep = smb_GetSMBData(inp, &dbytes); + namex = 0; tcounter = 0; coreProtoIndex = -1; /* not found */ - v3ProtoIndex = -1; + v3ProtoIndex = -1; NTProtoIndex = -1; - while(namex < dbytes) { + while(namex < dbytes) { osi_Log1(afsd_logp, "Protocol %s", - osi_LogSaveString(afsd_logp, namep+1)); + osi_LogSaveString(afsd_logp, namep+1)); strcpy(protocol_array[tcounter], namep+1); /* namep points at the first protocol, or really, a 0x02 - * byte preceding the null-terminated ASCII name. - */ - if (strcmp("PC NETWORK PROGRAM 1.0", namep+1) == 0) { - coreProtoIndex = tcounter; - } - else if (smb_useV3 && strcmp("LM1.2X002", namep+1) == 0) { + * byte preceding the null-terminated ASCII name. + */ + if (strcmp("PC NETWORK PROGRAM 1.0", namep+1) == 0) { + coreProtoIndex = tcounter; + } + else if (smb_useV3 && strcmp("LM1.2X002", namep+1) == 0) { v3ProtoIndex = tcounter; - } + } else if (smb_useV3 && strcmp("NT LM 0.12", namep+1) == 0) { NTProtoIndex = tcounter; } @@ -2375,7 +2385,7 @@ long smb_ReceiveNegotiate(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp) namex += entryLength; namep += entryLength; tcounter++; /* which proto entry we're looking at */ - } + } #ifndef NOMOREFILESFIX /* * NOTE: We can determine what OS (NT4.0, W2K, W9X, etc) @@ -2386,50 +2396,50 @@ long smb_ReceiveNegotiate(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp) * Proto signature is the same for Win XP. */ if (tcounter == 6) { - int i = 0; - smb_t *ip = (smb_t *) inp; - smb_t *op = (smb_t *) outp; - - if ((strcmp("PC NETWORK PROGRAM 1.0", protocol_array[0]) == 0) && - (strcmp("LANMAN1.0", protocol_array[1]) == 0) && - (strcmp("Windows for Workgroups 3.1a", protocol_array[2]) == 0) && - (strcmp("LM1.2X002", protocol_array[3]) == 0) && - (strcmp("LANMAN2.1", protocol_array[4]) == 0) && - (strcmp("NT LM 0.12", protocol_array[5]) == 0)) { - isWindows2000 = TRUE; - osi_Log0(afsd_logp, "Looks like a Windows 2000 client"); - /* - * HACK: for now - just negotiate a lower protocol till we - * figure out which flag/flag2 or some other field - * (capabilities maybe?) to set in order for this to work - * correctly with Windows 2000 clients (defect 11765) - */ - NTProtoIndex = -1; - /* Things to try (after looking at tcpdump output could be - * setting flags and flags2 to 0x98 and 0xc853 like this - * op->reb = 0x98; op->flg2 = 0xc853; - * osi_Log2(afsd_logp, "Flags:0x%x Flags2:0x%x", ip->reb, ip->flg2); - */ - } - } + int i = 0; + smb_t *ip = (smb_t *) inp; + smb_t *op = (smb_t *) outp; + + if ((strcmp("PC NETWORK PROGRAM 1.0", protocol_array[0]) == 0) && + (strcmp("LANMAN1.0", protocol_array[1]) == 0) && + (strcmp("Windows for Workgroups 3.1a", protocol_array[2]) == 0) && + (strcmp("LM1.2X002", protocol_array[3]) == 0) && + (strcmp("LANMAN2.1", protocol_array[4]) == 0) && + (strcmp("NT LM 0.12", protocol_array[5]) == 0)) { + isWindows2000 = TRUE; + osi_Log0(afsd_logp, "Looks like a Windows 2000 client"); + /* + * HACK: for now - just negotiate a lower protocol till we + * figure out which flag/flag2 or some other field + * (capabilities maybe?) to set in order for this to work + * correctly with Windows 2000 clients (defect 11765) + */ + NTProtoIndex = -1; + /* Things to try (after looking at tcpdump output could be + * setting flags and flags2 to 0x98 and 0xc853 like this + * op->reb = 0x98; op->flg2 = 0xc853; + * osi_Log2(afsd_logp, "Flags:0x%x Flags2:0x%x", ip->reb, ip->flg2); + */ + } + } #endif /* NOMOREFILESFIX */ - if (NTProtoIndex != -1) { + if (NTProtoIndex != -1) { protoIndex = NTProtoIndex; vcp->flags |= (SMB_VCFLAG_USENT | SMB_VCFLAG_USEV3); } else if (v3ProtoIndex != -1) { - protoIndex = v3ProtoIndex; - vcp->flags |= SMB_VCFLAG_USEV3; - } - else if (coreProtoIndex != -1) { - protoIndex = coreProtoIndex; - vcp->flags |= SMB_VCFLAG_USECORE; - } + protoIndex = v3ProtoIndex; + vcp->flags |= SMB_VCFLAG_USEV3; + } + else if (coreProtoIndex != -1) { + protoIndex = coreProtoIndex; + vcp->flags |= SMB_VCFLAG_USECORE; + } else protoIndex = -1; - if (protoIndex == -1) - return CM_ERROR_INVAL; + if (protoIndex == -1) + return CM_ERROR_INVAL; else if (NTProtoIndex != -1) { smb_SetSMBParm(outp, 0, protoIndex); smb_SetSMBParmByte(outp, 1, 0); /* share level security, no passwd encrypt */ @@ -2449,38 +2459,39 @@ long smb_ReceiveNegotiate(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp) else smb_SetSMBParmLong(outp, 9, 0x251); */ - smb_SetSMBParmLong(outp, 9, 0x251); /* Capabilities: * - * 32-bit error codes * - * and NT Find * - * and NT SMB's * - * and raw mode */ - smb_SetSMBParmLong(outp, 11, 0);/* XXX server time: do we need? */ - smb_SetSMBParmLong(outp, 13, 0);/* XXX server date: do we need? */ - smb_SetSMBParm(outp, 15, 0); /* XXX server tzone: do we need? */ + /* Capabilities: * + * 32-bit error codes * + * and NT Find * + * and NT SMB's * + * and raw mode */ + smb_SetSMBParmLong(outp, 9, 0x251); + smb_SetSMBParmLong(outp, 11, 0);/* XXX server time: do we need? */ + smb_SetSMBParmLong(outp, 13, 0);/* XXX server date: do we need? */ + smb_SetSMBParm(outp, 15, 0); /* XXX server tzone: do we need? */ smb_SetSMBParmByte(outp, 16, 0);/* Encryption key length */ - smb_SetSMBDataLength(outp, 0); /* perhaps should specify 8 bytes anyway */ + smb_SetSMBDataLength(outp, 0); /* perhaps should specify 8 bytes anyway */ } else if (v3ProtoIndex != -1) { - smb_SetSMBParm(outp, 0, protoIndex); - smb_SetSMBParm(outp, 1, 0); /* share level security, no passwd encrypt */ - smb_SetSMBParm(outp, 2, SMB_PACKETSIZE); - smb_SetSMBParm(outp, 3, smb_maxMpxRequests); /* max multiplexed requests */ - smb_SetSMBParm(outp, 4, smb_maxVCPerServer); /* max VCs per consumer/server connection */ - smb_SetSMBParm(outp, 5, 0); /* no support of block mode for read or write */ - smb_SetSMBParm(outp, 6, 1); /* next 2: session key */ - smb_SetSMBParm(outp, 7, 1); - smb_SetSMBParm(outp, 8, 0); /* XXX server time: do we need? */ - smb_SetSMBParm(outp, 9, 0); /* XXX server date: do we need? */ - smb_SetSMBParm(outp, 10, 0); /* XXX server tzone: do we need? */ - smb_SetSMBParm(outp, 11, 0); /* resvd */ - smb_SetSMBParm(outp, 12, 0); /* resvd */ - smb_SetSMBDataLength(outp, 0); /* perhaps should specify 8 bytes anyway */ - } + smb_SetSMBParm(outp, 0, protoIndex); + smb_SetSMBParm(outp, 1, 0); /* share level security, no passwd encrypt */ + smb_SetSMBParm(outp, 2, SMB_PACKETSIZE); + smb_SetSMBParm(outp, 3, smb_maxMpxRequests); /* max multiplexed requests */ + smb_SetSMBParm(outp, 4, smb_maxVCPerServer); /* max VCs per consumer/server connection */ + smb_SetSMBParm(outp, 5, 0); /* no support of block mode for read or write */ + smb_SetSMBParm(outp, 6, 1); /* next 2: session key */ + smb_SetSMBParm(outp, 7, 1); + smb_SetSMBParm(outp, 8, 0); /* XXX server time: do we need? */ + smb_SetSMBParm(outp, 9, 0); /* XXX server date: do we need? */ + smb_SetSMBParm(outp, 10, 0); /* XXX server tzone: do we need? */ + smb_SetSMBParm(outp, 11, 0); /* resvd */ + smb_SetSMBParm(outp, 12, 0); /* resvd */ + smb_SetSMBDataLength(outp, 0); /* perhaps should specify 8 bytes anyway */ + } else if (coreProtoIndex != -1) { - smb_SetSMBParm(outp, 0, protoIndex); - smb_SetSMBDataLength(outp, 0); - } - return 0; + smb_SetSMBParm(outp, 0, protoIndex); + smb_SetSMBDataLength(outp, 0); + } + return 0; } void smb_Daemon(void *parmp) @@ -2493,7 +2504,7 @@ void smb_Daemon(void *parmp) if ((count % 360) == 0) /* every hour */ smb_CalculateNowTZ(); /* XXX GC dir search entries */ - } + } } void smb_WaitingLocksDaemon() @@ -2523,7 +2534,7 @@ void smb_WaitingLocksDaemon() nwL = (smb_waitingLock_t *) osi_QNext(&wL->q); lock_ReleaseWrite(&smb_globalLock); code = cm_RetryLock((cm_file_lock_t *) wL->lockp, - wL->vcp->flags & SMB_VCFLAG_ALREADYDEAD); + wL->vcp->flags & SMB_VCFLAG_ALREADYDEAD); if (code == CM_ERROR_WOULDBLOCK) { /* no progress */ if (wL->timeRemaining != 0xffffffff @@ -2531,7 +2542,7 @@ void smb_WaitingLocksDaemon() goto endWait; continue; } -endWait: + endWait: vcp = wL->vcp; inp = wL->inp; outp = wL->outp; @@ -2568,42 +2579,42 @@ long smb_ReceiveCoreGetDiskAttributes(smb_vc_t *vcp, smb_packet_t *inp, smb_pack { osi_Log0(afsd_logp, "SMB receive get disk attributes"); - smb_SetSMBParm(outp, 0, 32000); - smb_SetSMBParm(outp, 1, 64); - smb_SetSMBParm(outp, 2, 1024); - smb_SetSMBParm(outp, 3, 30000); - smb_SetSMBParm(outp, 4, 0); - smb_SetSMBDataLength(outp, 0); + smb_SetSMBParm(outp, 0, 32000); + smb_SetSMBParm(outp, 1, 64); + smb_SetSMBParm(outp, 2, 1024); + smb_SetSMBParm(outp, 3, 30000); + smb_SetSMBParm(outp, 4, 0); + smb_SetSMBDataLength(outp, 0); return 0; } long smb_ReceiveCoreTreeConnect(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *rsp) { - smb_tid_t *tidp; - unsigned short newTid; - char shareName[256]; + smb_tid_t *tidp; + unsigned short newTid; + char shareName[256]; char *sharePath; int shareFound; - char *tp; - char *pathp; - char *passwordp; - cm_user_t *userp; - + char *tp; + char *pathp; + char *passwordp; + cm_user_t *userp; + osi_Log0(afsd_logp, "SMB receive tree connect"); /* parse input parameters */ tp = smb_GetSMBData(inp, NULL); pathp = smb_ParseASCIIBlock(tp, &tp); - passwordp = smb_ParseASCIIBlock(tp, &tp); + passwordp = smb_ParseASCIIBlock(tp, &tp); tp = strrchr(pathp, '\\'); - if (!tp) + if (!tp) return CM_ERROR_BADSMB; - strcpy(shareName, tp+1); + strcpy(shareName, tp+1); - userp = smb_GetUser(vcp, inp); + userp = smb_GetUser(vcp, inp); lock_ObtainMutex(&vcp->mx); - newTid = vcp->tidCounter++; + newTid = vcp->tidCounter++; lock_ReleaseMutex(&vcp->mx); tidp = smb_FindTID(vcp, newTid, SMB_FLAG_CREATE); @@ -2612,18 +2623,18 @@ long smb_ReceiveCoreTreeConnect(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t * smb_ReleaseTID(tidp); return CM_ERROR_BADSHARENAME; } - lock_ObtainMutex(&tidp->mx); - tidp->userp = userp; + lock_ObtainMutex(&tidp->mx); + tidp->userp = userp; tidp->pathname = sharePath; - lock_ReleaseMutex(&tidp->mx); - smb_ReleaseTID(tidp); + lock_ReleaseMutex(&tidp->mx); + smb_ReleaseTID(tidp); - smb_SetSMBParm(rsp, 0, SMB_PACKETSIZE); - smb_SetSMBParm(rsp, 1, newTid); - smb_SetSMBDataLength(rsp, 0); - - osi_Log1(afsd_logp, "SMB tree connect created ID %d", newTid); - return 0; + smb_SetSMBParm(rsp, 0, SMB_PACKETSIZE); + smb_SetSMBParm(rsp, 1, newTid); + smb_SetSMBDataLength(rsp, 0); + + osi_Log1(afsd_logp, "SMB tree connect created ID %d", newTid); + return 0; } unsigned char *smb_ParseDataBlock(unsigned char *inp, char **chainpp, int *lengthp) @@ -2631,16 +2642,16 @@ unsigned char *smb_ParseDataBlock(unsigned char *inp, char **chainpp, int *lengt int tlen; if (*inp++ != 0x1) return NULL; - tlen = inp[0] + (inp[1]<<8); - inp += 2; /* skip length field */ + tlen = inp[0] + (inp[1]<<8); + inp += 2; /* skip length field */ - if (chainpp) { + if (chainpp) { *chainpp = inp + tlen; - } + } - if (lengthp) *lengthp = tlen; + if (lengthp) *lengthp = tlen; - return inp; + return inp; } /* set maskp to the mask part of the incoming path. @@ -2651,10 +2662,10 @@ unsigned char *smb_ParseDataBlock(unsigned char *inp, char **chainpp, int *lengt int smb_Get8Dot3MaskFromPath(unsigned char *maskp, unsigned char *pathp) { char *tp; - char *up; - int i; - int tc; - int valid8Dot3; + char *up; + int i; + int tc; + int valid8Dot3; /* starts off valid */ valid8Dot3 = 1; @@ -2663,9 +2674,9 @@ int smb_Get8Dot3MaskFromPath(unsigned char *maskp, unsigned char *pathp) memset(maskp, ' ', 11); /* find last backslash, or use whole thing if there is none */ - tp = strrchr(pathp, '\\'); - if (!tp) tp = pathp; - else tp++; /* skip slash */ + tp = strrchr(pathp, '\\'); + if (!tp) tp = pathp; + else tp++; /* skip slash */ up = maskp; @@ -2684,14 +2695,18 @@ int smb_Get8Dot3MaskFromPath(unsigned char *maskp, unsigned char *pathp) up = maskp+8; /* ext goes here */ for(i=0;;i++) { tc = *tp++; - if (tc == 0) return valid8Dot3; + if (tc == 0) + return valid8Dot3; /* too many dots */ - if (tc == '.' || tc == '"') valid8Dot3 = 0; + if (tc == '.' || tc == '"') + valid8Dot3 = 0; /* copy extension if not too long */ - if (i < 3) *up++ = tc; - else valid8Dot3 = 0; + if (i < 3) + *up++ = tc; + else + valid8Dot3 = 0; } /* unreachable */ @@ -2700,33 +2715,37 @@ int smb_Get8Dot3MaskFromPath(unsigned char *maskp, unsigned char *pathp) int smb_Match8Dot3Mask(char *unixNamep, char *maskp) { char umask[11]; - int valid; - int i; - char tc1; - char tc2; - char *tp1; - char *tp2; - + int valid; + int i; + char tc1; + char tc2; + char *tp1; + char *tp2; + /* XXX redo this, calling smb_V3MatchMask with a converted mask */ - valid = smb_Get8Dot3MaskFromPath(umask, unixNamep); - if (!valid) return 0; + valid = smb_Get8Dot3MaskFromPath(umask, unixNamep); + if (!valid) + return 0; /* otherwise, we have a valid 8.3 name; see if we have a match, - * treating '?' as a wildcard in maskp (but not in the file name). - */ + * treating '?' as a wildcard in maskp (but not in the file name). + */ tp1 = umask; /* real name, in mask format */ - tp2 = maskp; /* mask, in mask format */ + tp2 = maskp; /* mask, in mask format */ for(i=0; i<11; i++) { tc1 = *tp1++; /* char from real name */ - tc2 = *tp2++; /* char from mask */ + tc2 = *tp2++; /* char from mask */ tc1 = (char) cm_foldUpper[(unsigned char)tc1]; tc2 = (char) cm_foldUpper[(unsigned char)tc2]; - if (tc1 == tc2) continue; - if (tc2 == '?' && tc1 != ' ') continue; - if (tc2 == '>') continue; + if (tc1 == tc2) + continue; + if (tc2 == '?' && tc1 != ' ') + continue; + if (tc2 == '>') + continue; return 0; - } + } /* we got a match */ return 1; @@ -2736,18 +2755,20 @@ char *smb_FindMask(char *pathp) { char *tp; - tp = strrchr(pathp, '\\'); /* find last slash */ + tp = strrchr(pathp, '\\'); /* find last slash */ - if (tp) return tp+1; /* skip the slash */ - else return pathp; /* no slash, return the entire path */ + if (tp) + return tp+1; /* skip the slash */ + else + return pathp; /* no slash, return the entire path */ } long smb_ReceiveCoreSearchVolume(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp) { unsigned char *pathp; - unsigned char *tp; - unsigned char mask[11]; - unsigned char *statBlockp; + unsigned char *tp; + unsigned char mask[11]; + unsigned char *statBlockp; unsigned char initStatBlock[21]; int statLen; @@ -2755,58 +2776,58 @@ long smb_ReceiveCoreSearchVolume(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t /* pull pathname and stat block out of request */ tp = smb_GetSMBData(inp, NULL); - pathp = smb_ParseASCIIBlock(tp, (char **) &tp); - osi_assert(pathp != NULL); - statBlockp = smb_ParseVblBlock(tp, (char **) &tp, &statLen); - osi_assert(statBlockp != NULL); + pathp = smb_ParseASCIIBlock(tp, (char **) &tp); + osi_assert(pathp != NULL); + statBlockp = smb_ParseVblBlock(tp, (char **) &tp, &statLen); + osi_assert(statBlockp != NULL); if (statLen == 0) { statBlockp = initStatBlock; statBlockp[0] = 8; } /* for returning to caller */ - smb_Get8Dot3MaskFromPath(mask, pathp); + smb_Get8Dot3MaskFromPath(mask, pathp); smb_SetSMBParm(outp, 0, 1); /* we're returning one entry */ - tp = smb_GetSMBData(outp, NULL); - *tp++ = 5; - *tp++ = 43; /* bytes in a dir entry */ - *tp++ = 0; /* high byte in counter */ - - /* now marshall the dir entry, starting with the search status */ - *tp++ = statBlockp[0]; /* Reserved */ - memcpy(tp, mask, 11); tp += 11; /* FileName */ + tp = smb_GetSMBData(outp, NULL); + *tp++ = 5; + *tp++ = 43; /* bytes in a dir entry */ + *tp++ = 0; /* high byte in counter */ + + /* now marshall the dir entry, starting with the search status */ + *tp++ = statBlockp[0]; /* Reserved */ + memcpy(tp, mask, 11); tp += 11; /* FileName */ /* now pass back server use info, with 1st byte non-zero */ - *tp++ = 1; - memset(tp, 0, 4); tp += 4; /* reserved for server use */ - - memcpy(tp, statBlockp+17, 4); tp += 4; /* reserved for consumer */ - - *tp++ = 0x8; /* attribute: volume */ + *tp++ = 1; + memset(tp, 0, 4); tp += 4; /* reserved for server use */ + + memcpy(tp, statBlockp+17, 4); tp += 4; /* reserved for consumer */ + + *tp++ = 0x8; /* attribute: volume */ /* copy out time */ - *tp++ = 0; - *tp++ = 0; - - /* copy out date */ - *tp++ = 18; - *tp++ = 178; - + *tp++ = 0; + *tp++ = 0; + + /* copy out date */ + *tp++ = 18; + *tp++ = 178; + /* 4 byte file size */ - *tp++ = 0; - *tp++ = 0; - *tp++ = 0; - *tp++ = 0; + *tp++ = 0; + *tp++ = 0; + *tp++ = 0; + *tp++ = 0; /* finally, null-terminated 8.3 pathname, which we set to AFS */ - memset(tp, ' ', 13); - strcpy(tp, "AFS"); - - /* set the length of the data part of the packet to 43 + 3, for the dir - * entry plus the 5 and the length fields. - */ - smb_SetSMBDataLength(outp, 46); + memset(tp, ' ', 13); + strcpy(tp, "AFS"); + + /* set the length of the data part of the packet to 43 + 3, for the dir + * entry plus the 5 and the length fields. + */ + smb_SetSMBDataLength(outp, 46); return 0; } @@ -2814,26 +2835,26 @@ long smb_ApplyDirListPatches(smb_dirListPatch_t **dirPatchespp, cm_user_t *userp, cm_req_t *reqp) { long code; - cm_scache_t *scp; - char *dptr; - long dosTime; - u_short shortTemp; - char attr; - smb_dirListPatch_t *patchp; - smb_dirListPatch_t *npatchp; - - for(patchp = *dirPatchespp; patchp; patchp = - (smb_dirListPatch_t *) osi_QNext(&patchp->q)) { + cm_scache_t *scp; + char *dptr; + long dosTime; + u_short shortTemp; + char attr; + smb_dirListPatch_t *patchp; + smb_dirListPatch_t *npatchp; + + for(patchp = *dirPatchespp; patchp; patchp = + (smb_dirListPatch_t *) osi_QNext(&patchp->q)) { code = cm_GetSCache(&patchp->fid, &scp, userp, reqp); - if (code) continue; - lock_ObtainMutex(&scp->mx); - code = cm_SyncOp(scp, NULL, userp, reqp, 0, - CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS); - if (code) { + if (code) continue; + lock_ObtainMutex(&scp->mx); + code = cm_SyncOp(scp, NULL, userp, reqp, 0, + CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS); + if (code) { lock_ReleaseMutex(&scp->mx); cm_ReleaseSCache(scp); continue; - } + } dptr = patchp->dptr; attr = smb_Attributes(scp); @@ -2843,109 +2864,109 @@ long smb_ApplyDirListPatches(smb_dirListPatch_t **dirPatchespp, *dptr++ = attr; /* get dos time */ - smb_SearchTimeFromUnixTime(&dosTime, scp->clientModTime); + smb_SearchTimeFromUnixTime(&dosTime, scp->clientModTime); - /* copy out time */ - shortTemp = dosTime & 0xffff; + /* copy out time */ + shortTemp = dosTime & 0xffff; *((u_short *)dptr) = shortTemp; - dptr += 2; + dptr += 2; /* and copy out date */ - shortTemp = (dosTime>>16) & 0xffff; + shortTemp = (dosTime>>16) & 0xffff; *((u_short *)dptr) = shortTemp; - dptr += 2; + dptr += 2; - /* copy out file length */ + /* copy out file length */ *((u_long *)dptr) = scp->length.LowPart; - dptr += 4; - lock_ReleaseMutex(&scp->mx); - cm_ReleaseSCache(scp); + dptr += 4; + lock_ReleaseMutex(&scp->mx); + cm_ReleaseSCache(scp); } - /* now free the patches */ - for(patchp = *dirPatchespp; patchp; patchp = npatchp) { + /* now free the patches */ + for(patchp = *dirPatchespp; patchp; patchp = npatchp) { npatchp = (smb_dirListPatch_t *) osi_QNext(&patchp->q); - free(patchp); - } + free(patchp); + } - /* and mark the list as empty */ - *dirPatchespp = NULL; + /* and mark the list as empty */ + *dirPatchespp = NULL; - return code; + return code; } long smb_ReceiveCoreSearchDir(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp) { int attribute; - long nextCookie; - char *tp; - long code; - char *pathp; - cm_dirEntry_t *dep; - int maxCount; - smb_dirListPatch_t *dirListPatchesp; - smb_dirListPatch_t *curPatchp; - int dataLength; - cm_buf_t *bufferp; - long temp; - osi_hyper_t dirLength; - osi_hyper_t bufferOffset; - osi_hyper_t curOffset; - osi_hyper_t thyper; - unsigned char *inCookiep; - smb_dirSearch_t *dsp; - cm_scache_t *scp; - long entryInDir; - long entryInBuffer; - unsigned long clientCookie; + long nextCookie; + char *tp; + long code; + char *pathp; + cm_dirEntry_t *dep; + int maxCount; + smb_dirListPatch_t *dirListPatchesp; + smb_dirListPatch_t *curPatchp; + int dataLength; + cm_buf_t *bufferp; + long temp; + osi_hyper_t dirLength; + osi_hyper_t bufferOffset; + osi_hyper_t curOffset; + osi_hyper_t thyper; + unsigned char *inCookiep; + smb_dirSearch_t *dsp; + cm_scache_t *scp; + long entryInDir; + long entryInBuffer; + unsigned long clientCookie; cm_pageHeader_t *pageHeaderp; - cm_user_t *userp = NULL; - int slotInPage; + cm_user_t *userp = NULL; + int slotInPage; char shortName[13]; char *actualName; char *shortNameEnd; - char mask[11]; - int returnedNames; - long nextEntryCookie; - int numDirChunks; /* # of 32 byte dir chunks in this entry */ - char resByte; /* reserved byte from the cookie */ - char *op; /* output data ptr */ - char *origOp; /* original value of op */ - cm_space_t *spacep; /* for pathname buffer */ - int starPattern; + char mask[11]; + int returnedNames; + long nextEntryCookie; + int numDirChunks; /* # of 32 byte dir chunks in this entry */ + char resByte; /* reserved byte from the cookie */ + char *op; /* output data ptr */ + char *origOp; /* original value of op */ + cm_space_t *spacep; /* for pathname buffer */ + int starPattern; int rootPath = 0; - int caseFold; + int caseFold; char *tidPathp; - cm_req_t req; - cm_fid_t fid; - int fileType; + cm_req_t req; + cm_fid_t fid; + int fileType; cm_InitReq(&req); - maxCount = smb_GetSMBParm(inp, 0); + maxCount = smb_GetSMBParm(inp, 0); - dirListPatchesp = NULL; + dirListPatchesp = NULL; - caseFold = CM_FLAG_CASEFOLD; + caseFold = CM_FLAG_CASEFOLD; tp = smb_GetSMBData(inp, NULL); - pathp = smb_ParseASCIIBlock(tp, &tp); - inCookiep = smb_ParseVblBlock(tp, &tp, &dataLength); - - /* bail out if request looks bad */ - if (!tp || !pathp) { - return CM_ERROR_BADSMB; - } + pathp = smb_ParseASCIIBlock(tp, &tp); + inCookiep = smb_ParseVblBlock(tp, &tp, &dataLength); + + /* bail out if request looks bad */ + if (!tp || !pathp) { + return CM_ERROR_BADSMB; + } /* We can handle long names */ if (vcp->flags & SMB_VCFLAG_USENT) ((smb_t *)outp)->flg2 |= 0x40; /* IS_LONG_NAME */ - + /* make sure we got a whole search status */ if (dataLength < 21) { - nextCookie = 0; /* start at the beginning of the dir */ - resByte = 0; - clientCookie = 0; + nextCookie = 0; /* start at the beginning of the dir */ + resByte = 0; + clientCookie = 0; attribute = smb_GetSMBParm(inp, 1); /* handle volume info in another function */ @@ -2953,7 +2974,7 @@ long smb_ReceiveCoreSearchDir(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *ou return smb_ReceiveCoreSearchVolume(vcp, inp, outp); osi_Log2(afsd_logp, "SMB receive search dir count %d [%s]", - maxCount, osi_LogSaveString(afsd_logp, pathp)); + maxCount, osi_LogSaveString(afsd_logp, pathp)); if (*pathp == 0) { /* null pathp, treat as root dir */ if (!(attribute & SMB_ATTR_DIRECTORY)) /* exclude dirs */ @@ -2961,42 +2982,42 @@ long smb_ReceiveCoreSearchDir(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *ou rootPath = 1; } - dsp = smb_NewDirSearch(0); + dsp = smb_NewDirSearch(0); dsp->attribute = attribute; - smb_Get8Dot3MaskFromPath(mask, pathp); + smb_Get8Dot3MaskFromPath(mask, pathp); memcpy(dsp->mask, mask, 11); /* track if this is likely to match a lot of entries */ - if (smb_IsStarMask(mask)) starPattern = 1; - else starPattern = 0; - } + if (smb_IsStarMask(mask)) starPattern = 1; + else starPattern = 0; + } else { /* pull the next cookie value out of the search status block */ - nextCookie = inCookiep[13] + (inCookiep[14]<<8) + (inCookiep[15]<<16) - + (inCookiep[16]<<24); + nextCookie = inCookiep[13] + (inCookiep[14]<<8) + (inCookiep[15]<<16) + + (inCookiep[16]<<24); dsp = smb_FindDirSearch(inCookiep[12]); if (!dsp) { /* can't find dir search status; fatal error */ return CM_ERROR_BADFD; - } + } attribute = dsp->attribute; resByte = inCookiep[0]; /* copy out client cookie, in host byte order. Don't bother - * interpreting it, since we're just passing it through, anyway. - */ + * interpreting it, since we're just passing it through, anyway. + */ memcpy(&clientCookie, &inCookiep[17], 4); memcpy(mask, dsp->mask, 11); /* assume we're doing a star match if it has continued for more * than one call. - */ - starPattern = 1; - } + */ + starPattern = 1; + } osi_Log3(afsd_logp, "SMB dir search cookie 0x%x, connection %d, attr 0x%x", - nextCookie, dsp->cookie, attribute); + nextCookie, dsp->cookie, attribute); userp = smb_GetUser(vcp, inp); @@ -3004,27 +3025,27 @@ long smb_ReceiveCoreSearchDir(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *ou lock_ObtainMutex(&dsp->mx); if (dsp->scp) { scp = dsp->scp; - cm_HoldSCache(scp); - code = 0; - } - else { + cm_HoldSCache(scp); + code = 0; + } + else { spacep = inp->spacep; - smb_StripLastComponent(spacep->data, NULL, pathp); - lock_ReleaseMutex(&dsp->mx); + smb_StripLastComponent(spacep->data, NULL, pathp); + lock_ReleaseMutex(&dsp->mx); tidPathp = smb_GetTIDPath(vcp, ((smb_t *)inp)->tid); - code = cm_NameI(cm_rootSCachep, spacep->data, - caseFold | CM_FLAG_FOLLOW, userp, tidPathp, &req, &scp); - lock_ObtainMutex(&dsp->mx); + code = cm_NameI(cm_rootSCachep, spacep->data, + caseFold | CM_FLAG_FOLLOW, userp, tidPathp, &req, &scp); + lock_ObtainMutex(&dsp->mx); if (code == 0) { if (dsp->scp != 0) cm_ReleaseSCache(dsp->scp); dsp->scp = 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. - * We held it once from the namei call, and so we do another hold - * now. - */ - cm_HoldSCache(scp); + * and one for our own processing. When we're done with this + * function, we'll drop the one for our own processing. + * We held it once from the namei call, and so we do another hold + * now. + */ + cm_HoldSCache(scp); lock_ObtainMutex(&scp->mx); if ((scp->flags & CM_SCACHEFLAG_BULKSTATTING) == 0 && LargeIntegerGreaterOrEqualToZero(scp->bulkStatProgress)) { @@ -3033,179 +3054,180 @@ long smb_ReceiveCoreSearchDir(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *ou } lock_ReleaseMutex(&scp->mx); } - } + } lock_ReleaseMutex(&dsp->mx); - if (code) { + if (code) { cm_ReleaseUser(userp); smb_DeleteDirSearch(dsp); smb_ReleaseDirSearch(dsp); - return code; - } + return code; + } /* reserves space for parameter; we'll adjust it again later to the - * real count of the # of entries we returned once we've actually - * assembled the directory listing. - */ + * real count of the # of entries we returned once we've actually + * assembled the directory listing. + */ smb_SetSMBParm(outp, 0, 0); - /* get the directory size */ + /* get the directory size */ lock_ObtainMutex(&scp->mx); - code = cm_SyncOp(scp, NULL, userp, &req, 0, - CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS); + code = cm_SyncOp(scp, NULL, userp, &req, 0, + CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS); if (code) { lock_ReleaseMutex(&scp->mx); - cm_ReleaseSCache(scp); - cm_ReleaseUser(userp); + cm_ReleaseSCache(scp); + cm_ReleaseUser(userp); smb_DeleteDirSearch(dsp); smb_ReleaseDirSearch(dsp); - return code; - } + return code; + } - dirLength = scp->length; - bufferp = NULL; - bufferOffset.LowPart = bufferOffset.HighPart = 0; - curOffset.HighPart = 0; - curOffset.LowPart = nextCookie; + dirLength = scp->length; + bufferp = NULL; + bufferOffset.LowPart = bufferOffset.HighPart = 0; + curOffset.HighPart = 0; + curOffset.LowPart = nextCookie; origOp = op = smb_GetSMBData(outp, NULL); - /* and write out the basic header */ - *op++ = 5; /* variable block */ - op += 2; /* skip vbl block length; we'll fill it in later */ - code = 0; - returnedNames = 0; - while (1) { + /* and write out the basic header */ + *op++ = 5; /* variable block */ + op += 2; /* skip vbl block length; we'll fill it in later */ + code = 0; + returnedNames = 0; + while (1) { /* make sure that curOffset.LowPart doesn't point to the first - * 32 bytes in the 2nd through last dir page, and that it doesn't - * point at the first 13 32-byte chunks in the first dir page, - * since those are dir and page headers, and don't contain useful - * information. - */ + * 32 bytes in the 2nd through last dir page, and that it doesn't + * point at the first 13 32-byte chunks in the first dir page, + * since those are dir and page headers, and don't contain useful + * information. + */ temp = curOffset.LowPart & (2048-1); - if (curOffset.HighPart == 0 && curOffset.LowPart < 2048) { + if (curOffset.HighPart == 0 && curOffset.LowPart < 2048) { /* we're in the first page */ - if (temp < 13*32) temp = 13*32; + if (temp < 13*32) temp = 13*32; } else { /* we're in a later dir page */ - if (temp < 32) temp = 32; - } + if (temp < 32) temp = 32; + } - /* make sure the low order 5 bits are zero */ - temp &= ~(32-1); - - /* now put temp bits back ito curOffset.LowPart */ - curOffset.LowPart &= ~(2048-1); - curOffset.LowPart |= temp; + /* make sure the low order 5 bits are zero */ + temp &= ~(32-1); + + /* now put temp bits back ito curOffset.LowPart */ + curOffset.LowPart &= ~(2048-1); + curOffset.LowPart |= temp; /* check if we've returned all the names that will fit in the - * response packet. - */ - if (returnedNames >= maxCount) break; - - /* check if we've passed the dir's EOF */ - if (LargeIntegerGreaterThanOrEqualTo(curOffset, dirLength)) break; + * response packet. + */ + if (returnedNames >= maxCount) + break; - /* see if we can use the bufferp we have now; compute in which page - * the current offset would be, and check whether that's the offset - * of the buffer we have. If not, get the buffer. + /* check if we've passed the dir's EOF */ + if (LargeIntegerGreaterThanOrEqualTo(curOffset, dirLength)) break; + + /* see if we can use the bufferp we have now; compute in which page + * the current offset would be, and check whether that's the offset + * of the buffer we have. If not, get the buffer. */ - thyper.HighPart = curOffset.HighPart; - thyper.LowPart = curOffset.LowPart & ~(buf_bufferSize-1); - if (!bufferp || !LargeIntegerEqualTo(thyper, bufferOffset)) { + thyper.HighPart = curOffset.HighPart; + thyper.LowPart = curOffset.LowPart & ~(buf_bufferSize-1); + if (!bufferp || !LargeIntegerEqualTo(thyper, bufferOffset)) { /* wrong buffer */ - if (bufferp) { - buf_Release(bufferp); - bufferp = NULL; - } + if (bufferp) { + buf_Release(bufferp); + bufferp = NULL; + } lock_ReleaseMutex(&scp->mx); lock_ObtainRead(&scp->bufCreateLock); - code = buf_Get(scp, &thyper, &bufferp); + code = buf_Get(scp, &thyper, &bufferp); lock_ReleaseRead(&scp->bufCreateLock); /* now, if we're doing a star match, do bulk fetching of all of - * the status info for files in the dir. - */ - if (starPattern) { + * the status info for files in the dir. + */ + if (starPattern) { smb_ApplyDirListPatches(&dirListPatchesp, userp, - &req); + &req); if ((dsp->flags & SMB_DIRSEARCH_BULKST) && LargeIntegerGreaterThanOrEqualTo(thyper, scp->bulkStatProgress)) { - /* Don't bulk stat if risking timeout */ - int now = GetCurrentTime(); - if (now - req.startTime > 5000) { - scp->bulkStatProgress = thyper; - scp->flags &= ~CM_SCACHEFLAG_BULKSTATTING; - dsp->flags &= ~SMB_DIRSEARCH_BULKST; - } else - cm_TryBulkStat(scp, &thyper, - userp, &req); + /* Don't bulk stat if risking timeout */ + int now = GetCurrentTime(); + if (now - req.startTime > 5000) { + scp->bulkStatProgress = thyper; + scp->flags &= ~CM_SCACHEFLAG_BULKSTATTING; + dsp->flags &= ~SMB_DIRSEARCH_BULKST; + } else + cm_TryBulkStat(scp, &thyper, userp, &req); } } - lock_ObtainMutex(&scp->mx); - if (code) break; - bufferOffset = thyper; + lock_ObtainMutex(&scp->mx); + if (code) + break; + bufferOffset = thyper; - /* now get the data in the cache */ - while (1) { + /* now get the data in the cache */ + while (1) { code = cm_SyncOp(scp, bufferp, userp, &req, - PRSFS_LOOKUP, - CM_SCACHESYNC_NEEDCALLBACK - | CM_SCACHESYNC_READ); + PRSFS_LOOKUP, + CM_SCACHESYNC_NEEDCALLBACK + | CM_SCACHESYNC_READ); if (code) break; - if (cm_HaveBuffer(scp, bufferp, 0)) break; - - /* otherwise, load the buffer and try again */ - code = cm_GetBuffer(scp, bufferp, NULL, userp, - &req); - if (code) break; - } - if (code) { + if (cm_HaveBuffer(scp, bufferp, 0)) break; + + /* otherwise, load the buffer and try again */ + code = cm_GetBuffer(scp, bufferp, NULL, userp, + &req); + if (code) break; + } + if (code) { buf_Release(bufferp); - bufferp = NULL; - break; + bufferp = NULL; + break; } - } /* if (wrong buffer) ... */ - - /* now we have the buffer containing the entry we're interested in; copy - * it out if it represents a non-deleted entry. - */ + } /* if (wrong buffer) ... */ + + /* now we have the buffer containing the entry we're interested in; copy + * it out if it represents a non-deleted entry. + */ entryInDir = curOffset.LowPart & (2048-1); - entryInBuffer = curOffset.LowPart & (buf_bufferSize - 1); + entryInBuffer = curOffset.LowPart & (buf_bufferSize - 1); /* page header will help tell us which entries are free. Page header - * can change more often than once per buffer, since AFS 3 dir page size - * may be less than (but not more than a buffer package buffer. - */ + * can change more often than once per buffer, since AFS 3 dir page size + * may be less than (but not more than a buffer package buffer. + */ temp = curOffset.LowPart & (buf_bufferSize - 1); /* only look intra-buffer */ - temp &= ~(2048 - 1); /* turn off intra-page bits */ + temp &= ~(2048 - 1); /* turn off intra-page bits */ pageHeaderp = (cm_pageHeader_t *) (bufferp->datap + temp); /* now determine which entry we're looking at in the page. If it is - * free (there's a free bitmap at the start of the dir), we should - * skip these 32 bytes. - */ - slotInPage = (entryInDir & 0x7e0) >> 5; - if (!(pageHeaderp->freeBitmap[slotInPage>>3] & (1 << (slotInPage & 0x7)))) { + * free (there's a free bitmap at the start of the dir), we should + * skip these 32 bytes. + */ + slotInPage = (entryInDir & 0x7e0) >> 5; + if (!(pageHeaderp->freeBitmap[slotInPage>>3] & (1 << (slotInPage & 0x7)))) { /* this entry is free */ - numDirChunks = 1; /* only skip this guy */ - goto nextEntry; - } + numDirChunks = 1; /* only skip this guy */ + goto nextEntry; + } tp = bufferp->datap + entryInBuffer; - dep = (cm_dirEntry_t *) tp; /* now points to AFS3 dir entry */ + dep = (cm_dirEntry_t *) tp; /* now points to AFS3 dir entry */ - /* while we're here, compute the next entry's location, too, + /* while we're here, compute the next entry's location, too, * since we'll need it when writing out the cookie into the dir * listing stream. - * - * XXXX Probably should do more sanity checking. - */ + * + * XXXX Probably should do more sanity checking. + */ numDirChunks = cm_NameEntries(dep->name, NULL); - /* compute the offset of the cookie representing the next entry */ - nextEntryCookie = curOffset.LowPart + (CM_DIR_CHUNKSIZE * numDirChunks); + /* compute the offset of the cookie representing the next entry */ + nextEntryCookie = curOffset.LowPart + (CM_DIR_CHUNKSIZE * numDirChunks); /* Compute 8.3 name if necessary */ actualName = dep->name; @@ -3214,43 +3236,43 @@ long smb_ReceiveCoreSearchDir(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *ou actualName = shortName; } - if (dep->fid.vnode != 0 && smb_Match8Dot3Mask(actualName, mask)) { - /* this is one of the entries to use: it is not deleted - * and it matches the star pattern we're looking for. - */ + if (dep->fid.vnode != 0 && smb_Match8Dot3Mask(actualName, mask)) { + /* this is one of the entries to use: it is not deleted + * and it matches the star pattern we're looking for. + */ - /* Eliminate entries that don't match requested - attributes */ - - /* no hidden files */ - if(smb_hideDotFiles && !(dsp->attribute & SMB_ATTR_HIDDEN) && smb_IsDotFile(actualName)) - goto nextEntry; - - if (!(dsp->attribute & SMB_ATTR_DIRECTORY)) /* no directories */ - { - /* We have already done the cm_TryBulkStat above */ - fid.cell = scp->fid.cell; - fid.volume = scp->fid.volume; - fid.vnode = ntohl(dep->fid.vnode); - fid.unique = ntohl(dep->fid.unique); - fileType = cm_FindFileType(&fid); - osi_Log2(afsd_logp, "smb_ReceiveCoreSearchDir: file %s " - "has filetype %d", dep->name, - fileType); - if (fileType == CM_SCACHETYPE_DIRECTORY) - goto nextEntry; - } + /* Eliminate entries that don't match requested + attributes */ + + /* no hidden files */ + if(smb_hideDotFiles && !(dsp->attribute & SMB_ATTR_HIDDEN) && smb_IsDotFile(actualName)) + goto nextEntry; + + if (!(dsp->attribute & SMB_ATTR_DIRECTORY)) /* no directories */ + { + /* We have already done the cm_TryBulkStat above */ + fid.cell = scp->fid.cell; + fid.volume = scp->fid.volume; + fid.vnode = ntohl(dep->fid.vnode); + fid.unique = ntohl(dep->fid.unique); + fileType = cm_FindFileType(&fid); + osi_Log2(afsd_logp, "smb_ReceiveCoreSearchDir: file %s " + "has filetype %d", dep->name, + fileType); + if (fileType == CM_SCACHETYPE_DIRECTORY) + goto nextEntry; + } *op++ = resByte; - memcpy(op, mask, 11); op += 11; - *op++ = (char) dsp->cookie; /* they say it must be non-zero */ - *op++ = nextEntryCookie & 0xff; - *op++ = (nextEntryCookie>>8) & 0xff; - *op++ = (nextEntryCookie>>16) & 0xff; - *op++ = (nextEntryCookie>>24) & 0xff; - memcpy(op, &clientCookie, 4); op += 4; - - /* now we emit the attribute. This is sort of tricky, + memcpy(op, mask, 11); op += 11; + *op++ = (char) dsp->cookie; /* they say it must be non-zero */ + *op++ = nextEntryCookie & 0xff; + *op++ = (nextEntryCookie>>8) & 0xff; + *op++ = (nextEntryCookie>>16) & 0xff; + *op++ = (nextEntryCookie>>24) & 0xff; + memcpy(op, &clientCookie, 4); op += 4; + + /* now we emit the attribute. This is sort of tricky, * since we need to really stat the file to find out * what type of entry we've got. Right now, we're * copying out data from a buffer, while holding the @@ -3262,36 +3284,36 @@ long smb_ReceiveCoreSearchDir(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *ou * record to make it easy to find this point later. * The replay will happen at a time when it is safe to * unlock the directory. - */ - curPatchp = malloc(sizeof(*curPatchp)); - osi_QAdd((osi_queue_t **) &dirListPatchesp, &curPatchp->q); - curPatchp->dptr = op; - curPatchp->fid.cell = scp->fid.cell; - curPatchp->fid.volume = scp->fid.volume; - curPatchp->fid.vnode = ntohl(dep->fid.vnode); - curPatchp->fid.unique = ntohl(dep->fid.unique); - - /* do hidden attribute here since name won't be around when applying - * dir list patches - */ + */ + curPatchp = malloc(sizeof(*curPatchp)); + osi_QAdd((osi_queue_t **) &dirListPatchesp, &curPatchp->q); + curPatchp->dptr = op; + curPatchp->fid.cell = scp->fid.cell; + curPatchp->fid.volume = scp->fid.volume; + curPatchp->fid.vnode = ntohl(dep->fid.vnode); + curPatchp->fid.unique = ntohl(dep->fid.unique); + + /* do hidden attribute here since name won't be around when applying + * dir list patches + */ - if ( smb_hideDotFiles && smb_IsDotFile(actualName) ) - curPatchp->flags = SMB_DIRLISTPATCH_DOTFILE; - else - curPatchp->flags = 0; + if ( smb_hideDotFiles && smb_IsDotFile(actualName) ) + curPatchp->flags = SMB_DIRLISTPATCH_DOTFILE; + else + curPatchp->flags = 0; + + op += 9; /* skip attr, time, date and size */ - op += 9; /* skip attr, time, date and size */ - /* zero out name area. The spec says to pad with * spaces, but Samba doesn't, and neither do we. */ memset(op, 0, 13); - /* finally, we get to copy out the name; we know that + /* finally, we get to copy out the name; we know that * it fits in 8.3 or the pattern wouldn't match, but it * never hurts to be sure. - */ - strncpy(op, actualName, 13); + */ + strncpy(op, actualName, 13); /* Uppercase if requested by client */ if ((((smb_t *)inp)->flg2 & 1) == 0) @@ -3299,25 +3321,25 @@ long smb_ReceiveCoreSearchDir(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *ou op += 13; - /* now, adjust the # of entries copied */ - returnedNames++; + /* now, adjust the # of entries copied */ + returnedNames++; } /* if we're including this name */ -nextEntry: - /* and adjust curOffset to be where the new cookie is */ + nextEntry: + /* and adjust curOffset to be where the new cookie is */ thyper.HighPart = 0; - thyper.LowPart = CM_DIR_CHUNKSIZE * numDirChunks; - curOffset = LargeIntegerAdd(thyper, curOffset); - } /* while copying data for dir listing */ + thyper.LowPart = CM_DIR_CHUNKSIZE * numDirChunks; + curOffset = LargeIntegerAdd(thyper, curOffset); + } /* while copying data for dir listing */ /* release the mutex */ lock_ReleaseMutex(&scp->mx); - if (bufferp) buf_Release(bufferp); + if (bufferp) buf_Release(bufferp); /* 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); + * will be empty, but better safe (and freeing everything) than sorry. + */ + smb_ApplyDirListPatches(&dirListPatchesp, userp, &req); /* special return code for unsuccessful search */ if (code == 0 && dataLength < 21 && returnedNames == 0) @@ -3334,26 +3356,26 @@ nextEntry: return code; } - /* finalize the output buffer */ - smb_SetSMBParm(outp, 0, returnedNames); + /* finalize the output buffer */ + smb_SetSMBParm(outp, 0, returnedNames); temp = (long) (op - origOp); - smb_SetSMBDataLength(outp, temp); + smb_SetSMBDataLength(outp, temp); /* the data area is a variable block, which has a 5 (already there) * followed by the length of the # of data bytes. We now know this to * be "temp," although that includes the 3 bytes of vbl block header. * Deduct for them and fill in the length field. - */ + */ temp -= 3; /* deduct vbl block info */ - osi_assert(temp == (43 * returnedNames)); - origOp[1] = temp & 0xff; - origOp[2] = (temp>>8) & 0xff; - if (returnedNames == 0) smb_DeleteDirSearch(dsp); - smb_ReleaseDirSearch(dsp); - cm_ReleaseSCache(scp); - cm_ReleaseUser(userp); - return code; -} + osi_assert(temp == (43 * returnedNames)); + origOp[1] = temp & 0xff; + origOp[2] = (temp>>8) & 0xff; + if (returnedNames == 0) smb_DeleteDirSearch(dsp); + smb_ReleaseDirSearch(dsp); + cm_ReleaseSCache(scp); + cm_ReleaseUser(userp); + return code; +} /* verify that this is a valid path to a directory. I don't know why they * don't use the get file attributes call. @@ -3361,76 +3383,76 @@ nextEntry: long smb_ReceiveCoreCheckPath(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp) { char *pathp; - long code; - cm_scache_t *rootScp; + long code; + cm_scache_t *rootScp; cm_scache_t *newScp; - cm_user_t *userp; - unsigned int attrs; - int caseFold; + cm_user_t *userp; + unsigned int attrs; + int caseFold; char *tidPathp; cm_req_t req; cm_InitReq(&req); - pathp = smb_GetSMBData(inp, NULL); - pathp = smb_ParseASCIIBlock(pathp, NULL); + pathp = smb_GetSMBData(inp, NULL); + pathp = smb_ParseASCIIBlock(pathp, NULL); osi_Log1(afsd_logp, "SMB receive check path %s", - osi_LogSaveString(afsd_logp, pathp)); - - if (!pathp) { + osi_LogSaveString(afsd_logp, pathp)); + + if (!pathp) { return CM_ERROR_BADFD; } - rootScp = cm_rootSCachep; + rootScp = cm_rootSCachep; userp = smb_GetUser(vcp, inp); - caseFold = CM_FLAG_CASEFOLD; + caseFold = CM_FLAG_CASEFOLD; tidPathp = smb_GetTIDPath(vcp, ((smb_t *)inp)->tid); - code = cm_NameI(rootScp, pathp, - caseFold | CM_FLAG_FOLLOW | CM_FLAG_CHECKPATH, - userp, tidPathp, &req, &newScp); + code = cm_NameI(rootScp, pathp, + caseFold | CM_FLAG_FOLLOW | CM_FLAG_CHECKPATH, + userp, tidPathp, &req, &newScp); - if (code) { + if (code) { cm_ReleaseUser(userp); - return code; - } + return code; + } /* now lock the vnode with a callback; returns with newScp locked */ lock_ObtainMutex(&newScp->mx); - code = cm_SyncOp(newScp, NULL, userp, &req, PRSFS_LOOKUP, - CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_NEEDCALLBACK); - if (code && code != CM_ERROR_NOACCESS) { + code = cm_SyncOp(newScp, NULL, userp, &req, PRSFS_LOOKUP, + CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_NEEDCALLBACK); + if (code && code != CM_ERROR_NOACCESS) { lock_ReleaseMutex(&newScp->mx); - cm_ReleaseSCache(newScp); - cm_ReleaseUser(userp); - return code; - } + cm_ReleaseSCache(newScp); + cm_ReleaseUser(userp); + return code; + } attrs = smb_Attributes(newScp); if (!(attrs & 0x10)) - code = CM_ERROR_NOTDIR; + code = CM_ERROR_NOTDIR; - lock_ReleaseMutex(&newScp->mx); - - cm_ReleaseSCache(newScp); - cm_ReleaseUser(userp); - return code; -} + lock_ReleaseMutex(&newScp->mx); + + cm_ReleaseSCache(newScp); + cm_ReleaseUser(userp); + return code; +} long smb_ReceiveCoreSetFileAttributes(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp) { char *pathp; - long code; - cm_scache_t *rootScp; - unsigned short attribute; - cm_attr_t attr; + long code; + cm_scache_t *rootScp; + unsigned short attribute; + cm_attr_t attr; cm_scache_t *newScp; - long dosTime; - cm_user_t *userp; - int caseFold; + long dosTime; + cm_user_t *userp; + int caseFold; char *tidPathp; cm_req_t req; @@ -3438,46 +3460,46 @@ long smb_ReceiveCoreSetFileAttributes(smb_vc_t *vcp, smb_packet_t *inp, smb_pack /* decode basic attributes we're passed */ attribute = smb_GetSMBParm(inp, 0); - dosTime = smb_GetSMBParm(inp, 1) | (smb_GetSMBParm(inp, 2) << 16); + dosTime = smb_GetSMBParm(inp, 1) | (smb_GetSMBParm(inp, 2) << 16); - pathp = smb_GetSMBData(inp, NULL); - pathp = smb_ParseASCIIBlock(pathp, NULL); + pathp = smb_GetSMBData(inp, NULL); + pathp = smb_ParseASCIIBlock(pathp, NULL); - if (!pathp) { + if (!pathp) { return CM_ERROR_BADSMB; } osi_Log2(afsd_logp, "SMB receive setfile attributes time %d, attr 0x%x", - dosTime, attribute); + dosTime, attribute); - rootScp = cm_rootSCachep; + rootScp = cm_rootSCachep; userp = smb_GetUser(vcp, inp); caseFold = CM_FLAG_CASEFOLD; tidPathp = smb_GetTIDPath(vcp, ((smb_t *)inp)->tid); - code = cm_NameI(rootScp, pathp, caseFold | CM_FLAG_FOLLOW, userp, - tidPathp, &req, &newScp); + code = cm_NameI(rootScp, pathp, caseFold | CM_FLAG_FOLLOW, userp, + tidPathp, &req, &newScp); - if (code) { - cm_ReleaseUser(userp); - return code; - } + if (code) { + cm_ReleaseUser(userp); + return code; + } /* now lock the vnode with a callback; returns with newScp locked; we * need the current status to determine what the new status is, in some * cases. - */ + */ lock_ObtainMutex(&newScp->mx); - code = cm_SyncOp(newScp, NULL, userp, &req, 0, - CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_NEEDCALLBACK); - if (code) { + code = cm_SyncOp(newScp, NULL, userp, &req, 0, + CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_NEEDCALLBACK); + if (code) { lock_ReleaseMutex(&newScp->mx); - cm_ReleaseSCache(newScp); - cm_ReleaseUser(userp); - return code; - } + cm_ReleaseSCache(newScp); + cm_ReleaseUser(userp); + return code; + } /* Check for RO volume */ if (newScp->flags & CM_SCACHEFLAG_RO) { @@ -3490,43 +3512,43 @@ long smb_ReceiveCoreSetFileAttributes(smb_vc_t *vcp, smb_packet_t *inp, smb_pack /* prepare for setattr call */ attr.mask = 0; if (dosTime != 0) { - attr.mask |= CM_ATTRMASK_CLIENTMODTIME; - smb_UnixTimeFromDosUTime(&attr.clientModTime, dosTime); + attr.mask |= CM_ATTRMASK_CLIENTMODTIME; + smb_UnixTimeFromDosUTime(&attr.clientModTime, dosTime); } if ((newScp->unixModeBits & 0222) && (attribute & 1) != 0) { /* we're told to make a writable file read-only */ - attr.unixModeBits = newScp->unixModeBits & ~0222; - attr.mask |= CM_ATTRMASK_UNIXMODEBITS; - } + attr.unixModeBits = newScp->unixModeBits & ~0222; + attr.mask |= CM_ATTRMASK_UNIXMODEBITS; + } else if ((newScp->unixModeBits & 0222) == 0 && (attribute & 1) == 0) { /* we're told to make a read-only file writable */ - attr.unixModeBits = newScp->unixModeBits | 0222; - attr.mask |= CM_ATTRMASK_UNIXMODEBITS; - } - lock_ReleaseMutex(&newScp->mx); + attr.unixModeBits = newScp->unixModeBits | 0222; + attr.mask |= CM_ATTRMASK_UNIXMODEBITS; + } + lock_ReleaseMutex(&newScp->mx); /* now call setattr */ if (attr.mask) - code = cm_SetAttr(newScp, &attr, userp, &req); + code = cm_SetAttr(newScp, &attr, userp, &req); else code = 0; - cm_ReleaseSCache(newScp); + cm_ReleaseSCache(newScp); cm_ReleaseUser(userp); - return code; + return code; } long smb_ReceiveCoreGetFileAttributes(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp) { char *pathp; - long code; - cm_scache_t *rootScp; + long code; + cm_scache_t *rootScp; cm_scache_t *newScp, *dscp; - long dosTime; - int attrs; - cm_user_t *userp; - int caseFold; + long dosTime; + int attrs; + cm_user_t *userp; + int caseFold; char *tidPathp; cm_space_t *spacep; char *lastComp; @@ -3534,10 +3556,10 @@ long smb_ReceiveCoreGetFileAttributes(smb_vc_t *vcp, smb_packet_t *inp, smb_pack cm_InitReq(&req); - pathp = smb_GetSMBData(inp, NULL); - pathp = smb_ParseASCIIBlock(pathp, NULL); + pathp = smb_GetSMBData(inp, NULL); + pathp = smb_ParseASCIIBlock(pathp, NULL); - if (!pathp) { + if (!pathp) { return CM_ERROR_BADSMB; } @@ -3545,14 +3567,14 @@ long smb_ReceiveCoreGetFileAttributes(smb_vc_t *vcp, smb_packet_t *inp, smb_pack pathp = "\\"; osi_Log1(afsd_logp, "SMB receive getfile attributes path %s", - osi_LogSaveString(afsd_logp, pathp)); + osi_LogSaveString(afsd_logp, pathp)); - rootScp = cm_rootSCachep; + rootScp = cm_rootSCachep; userp = smb_GetUser(vcp, inp); /* we shouldn't need this for V3 requests, but we seem to */ - caseFold = CM_FLAG_CASEFOLD; + caseFold = CM_FLAG_CASEFOLD; tidPathp = smb_GetTIDPath(vcp, ((smb_t *)inp)->tid); @@ -3569,13 +3591,16 @@ long smb_ReceiveCoreGetFileAttributes(smb_vc_t *vcp, smb_packet_t *inp, smb_pack * to explicitly ignore the requests for mount points that haven't * yet been evaluated and for directories that haven't yet been * fetched. + * + * We should modify this hack to provide a fake desktop.ini file + * http://msdn.microsoft.com/library/en-us/shellcc/platform/shell/programmersguide/shell_basics/shell_basics_extending/custom.asp */ spacep = inp->spacep; smb_StripLastComponent(spacep->data, &lastComp, pathp); if (lastComp && stricmp(lastComp, "\\desktop.ini") == 0) { code = cm_NameI(rootScp, spacep->data, - caseFold | CM_FLAG_DIRSEARCH | CM_FLAG_FOLLOW, - userp, tidPathp, &req, &dscp); + caseFold | CM_FLAG_DIRSEARCH | CM_FLAG_FOLLOW, + userp, tidPathp, &req, &dscp); if (code == 0) { if (dscp->fileType == CM_SCACHETYPE_MOUNTPOINT && !dscp->mountRootFidp) @@ -3595,75 +3620,75 @@ long smb_ReceiveCoreGetFileAttributes(smb_vc_t *vcp, smb_packet_t *inp, smb_pack } } - code = cm_NameI(rootScp, pathp, caseFold | CM_FLAG_FOLLOW, userp, - tidPathp, &req, &newScp); + code = cm_NameI(rootScp, pathp, caseFold | CM_FLAG_FOLLOW, userp, + tidPathp, &req, &newScp); - if (code) { - cm_ReleaseUser(userp); - return code; - } + if (code) { + cm_ReleaseUser(userp); + return code; + } /* now lock the vnode with a callback; returns with newScp locked */ lock_ObtainMutex(&newScp->mx); - code = cm_SyncOp(newScp, NULL, userp, &req, 0, - CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_NEEDCALLBACK); - if (code) { + code = cm_SyncOp(newScp, NULL, userp, &req, 0, + CM_SCACHESYNC_GETSTATUS | CM_SCACHESYNC_NEEDCALLBACK); + if (code) { lock_ReleaseMutex(&newScp->mx); - cm_ReleaseSCache(newScp); - cm_ReleaseUser(userp); - return code; - } + cm_ReleaseSCache(newScp); + cm_ReleaseUser(userp); + return code; + } #ifdef undef - /* use smb_Attributes instead. Also the fact that a file is in a readonly volume - doesn't mean it shojuld be marked as RO */ - + /* use smb_Attributes instead. Also the fact that a file is + * in a readonly volume doesn't mean it shojuld be marked as RO + */ if (newScp->fileType == CM_SCACHETYPE_DIRECTORY - || newScp->fileType == CM_SCACHETYPE_MOUNTPOINT) - attrs = SMB_ATTR_DIRECTORY; + || newScp->fileType == CM_SCACHETYPE_MOUNTPOINT) + attrs = SMB_ATTR_DIRECTORY; else - attrs = 0; + attrs = 0; if ((newScp->unixModeBits & 0222) == 0 || (newScp->flags & CM_SCACHEFLAG_RO)) - attrs |= SMB_ATTR_READONLY; /* turn on read-only flag */ + attrs |= SMB_ATTR_READONLY; /* turn on read-only flag */ #else attrs = smb_Attributes(newScp); #endif - smb_SetSMBParm(outp, 0, attrs); - - smb_DosUTimeFromUnixTime(&dosTime, newScp->clientModTime); - smb_SetSMBParm(outp, 1, dosTime & 0xffff); - smb_SetSMBParm(outp, 2, (dosTime>>16) & 0xffff); - smb_SetSMBParm(outp, 3, newScp->length.LowPart & 0xffff); - smb_SetSMBParm(outp, 4, (newScp->length.LowPart >> 16) & 0xffff); - smb_SetSMBParm(outp, 5, 0); - smb_SetSMBParm(outp, 6, 0); - smb_SetSMBParm(outp, 7, 0); - smb_SetSMBParm(outp, 8, 0); - smb_SetSMBParm(outp, 9, 0); - smb_SetSMBDataLength(outp, 0); - lock_ReleaseMutex(&newScp->mx); - - cm_ReleaseSCache(newScp); - cm_ReleaseUser(userp); + smb_SetSMBParm(outp, 0, attrs); + + smb_DosUTimeFromUnixTime(&dosTime, newScp->clientModTime); + smb_SetSMBParm(outp, 1, dosTime & 0xffff); + smb_SetSMBParm(outp, 2, (dosTime>>16) & 0xffff); + smb_SetSMBParm(outp, 3, newScp->length.LowPart & 0xffff); + smb_SetSMBParm(outp, 4, (newScp->length.LowPart >> 16) & 0xffff); + smb_SetSMBParm(outp, 5, 0); + smb_SetSMBParm(outp, 6, 0); + smb_SetSMBParm(outp, 7, 0); + smb_SetSMBParm(outp, 8, 0); + smb_SetSMBParm(outp, 9, 0); + smb_SetSMBDataLength(outp, 0); + lock_ReleaseMutex(&newScp->mx); + + cm_ReleaseSCache(newScp); + cm_ReleaseUser(userp); - return 0; -} + return 0; +} long smb_ReceiveCoreTreeDisconnect(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp) { - smb_tid_t *tidp; + smb_tid_t *tidp; osi_Log0(afsd_logp, "SMB receive tree disconnect"); /* find the tree and free it */ - tidp = smb_FindTID(vcp, ((smb_t *)inp)->tid, 0); - if (tidp) { + tidp = smb_FindTID(vcp, ((smb_t *)inp)->tid, 0); + if (tidp) { lock_ObtainMutex(&tidp->mx); tidp->flags |= SMB_TIDFLAG_DELETE; - lock_ReleaseMutex(&tidp->mx); + lock_ReleaseMutex(&tidp->mx); smb_ReleaseTID(tidp); - } + } return 0; } @@ -3804,18 +3829,18 @@ typedef struct smb_unlinkRock { int smb_UnlinkProc(cm_scache_t *dscp, cm_dirEntry_t *dep, void *vrockp, osi_hyper_t *offp) { long code; - smb_unlinkRock_t *rockp; - int caseFold; + smb_unlinkRock_t *rockp; + int caseFold; int match; char shortName[13]; char *matchName; - rockp = vrockp; + rockp = vrockp; if (rockp->vcp->flags & SMB_VCFLAG_USEV3) - caseFold = CM_FLAG_CASEFOLD; + caseFold = CM_FLAG_CASEFOLD; else - caseFold = CM_FLAG_CASEFOLD | CM_FLAG_8DOT3; + caseFold = CM_FLAG_CASEFOLD | CM_FLAG_8DOT3; matchName = dep->name; match = smb_V3MatchMask(matchName, rockp->maskp, caseFold); @@ -3828,48 +3853,48 @@ int smb_UnlinkProc(cm_scache_t *dscp, cm_dirEntry_t *dep, void *vrockp, osi_hype } if (match) { osi_Log1(smb_logp, "Unlinking %s", - osi_LogSaveString(smb_logp, matchName)); - code = cm_Unlink(dscp, dep->name, rockp->userp, rockp->reqp); + 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, - dscp, dep->name, NULL, TRUE); + FILE_NOTIFY_CHANGE_FILE_NAME, + dscp, dep->name, NULL, TRUE); if (code == 0) rockp->any = 1; } - else code = 0; + else code = 0; - return code; + return code; } long smb_ReceiveCoreUnlink(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp) { int attribute; - long code; - char *pathp; - char *tp; - cm_space_t *spacep; - cm_scache_t *dscp; - char *lastNamep; - smb_unlinkRock_t rock; - cm_user_t *userp; - osi_hyper_t thyper; - int caseFold; + long code; + char *pathp; + char *tp; + cm_space_t *spacep; + cm_scache_t *dscp; + char *lastNamep; + smb_unlinkRock_t rock; + cm_user_t *userp; + osi_hyper_t thyper; + int caseFold; char *tidPathp; - cm_req_t req; + cm_req_t req; cm_InitReq(&req); - attribute = smb_GetSMBParm(inp, 0); + attribute = smb_GetSMBParm(inp, 0); tp = smb_GetSMBData(inp, NULL); - pathp = smb_ParseASCIIBlock(tp, &tp); + pathp = smb_ParseASCIIBlock(tp, &tp); osi_Log1(smb_logp, "SMB receive unlink %s", - osi_LogSaveString(smb_logp, pathp)); + osi_LogSaveString(smb_logp, pathp)); spacep = inp->spacep; - smb_StripLastComponent(spacep->data, &lastNamep, pathp); + smb_StripLastComponent(spacep->data, &lastNamep, pathp); userp = smb_GetUser(vcp, inp); @@ -3877,64 +3902,65 @@ long smb_ReceiveCoreUnlink(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp) tidPathp = smb_GetTIDPath(vcp, ((smb_t *)inp)->tid); code = cm_NameI(cm_rootSCachep, spacep->data, caseFold, userp, tidPathp, - &req, &dscp); + &req, &dscp); - if (code) { - cm_ReleaseUser(userp); - return code; - } + if (code) { + cm_ReleaseUser(userp); + return code; + } - /* otherwise, scp points to the parent directory. - */ - if (!lastNamep) lastNamep = pathp; - else lastNamep++; + /* otherwise, scp points to the parent directory. */ + if (!lastNamep) + lastNamep = pathp; + else + lastNamep++; rock.any = 0; - rock.maskp = smb_FindMask(pathp); + rock.maskp = smb_FindMask(pathp); rock.hasTilde = ((strchr(rock.maskp, '~') != NULL) ? 1 : 0); thyper.LowPart = 0; - thyper.HighPart = 0; + thyper.HighPart = 0; rock.userp = userp; rock.reqp = &req; - rock.dscp = dscp; - rock.vcp = vcp; - code = cm_ApplyDir(dscp, smb_UnlinkProc, &rock, &thyper, userp, &req, NULL); + rock.dscp = dscp; + rock.vcp = vcp; + code = cm_ApplyDir(dscp, smb_UnlinkProc, &rock, &thyper, userp, &req, NULL); - cm_ReleaseUser(userp); + cm_ReleaseUser(userp); - cm_ReleaseSCache(dscp); + cm_ReleaseSCache(dscp); - if (code == 0 && !rock.any) + if (code == 0 && !rock.any) code = CM_ERROR_NOSUCHFILE; - return code; + return code; } typedef struct smb_renameRock { - cm_scache_t *odscp; /* old dir */ - cm_scache_t *ndscp; /* new dir */ - cm_user_t *userp; /* user */ + cm_scache_t *odscp; /* old dir */ + cm_scache_t *ndscp; /* new dir */ + cm_user_t *userp; /* user */ cm_req_t *reqp; /* request struct */ - smb_vc_t *vcp; /* virtual circuit */ + smb_vc_t *vcp; /* virtual circuit */ char *maskp; /* pointer to star pattern of old file name */ int hasTilde; /* star pattern might be shortname? */ - char *newNamep; /* ptr to the new file's name */ + char *newNamep; /* ptr to the new file's name */ } smb_renameRock_t; int smb_RenameProc(cm_scache_t *dscp, cm_dirEntry_t *dep, void *vrockp, osi_hyper_t *offp) { long code; - smb_renameRock_t *rockp; - int caseFold; + smb_renameRock_t *rockp; + int caseFold; int match; char shortName[13]; - rockp = vrockp; + rockp = vrockp; if (rockp->vcp->flags & SMB_VCFLAG_USEV3) - caseFold = CM_FLAG_CASEFOLD; + caseFold = CM_FLAG_CASEFOLD; else - caseFold = CM_FLAG_CASEFOLD | CM_FLAG_8DOT3; + caseFold = CM_FLAG_CASEFOLD | CM_FLAG_8DOT3; match = smb_V3MatchMask(dep->name, rockp->maskp, caseFold); if (!match @@ -3944,35 +3970,36 @@ int smb_RenameProc(cm_scache_t *dscp, cm_dirEntry_t *dep, void *vrockp, osi_hype match = smb_V3MatchMask(shortName, rockp->maskp, caseFold); } if (match) { - code = cm_Rename(rockp->odscp, dep->name, - rockp->ndscp, rockp->newNamep, rockp->userp, - rockp->reqp); + 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. - */ - if (code == 0) code = CM_ERROR_STOPNOW; + */ + if (code == 0) + code = CM_ERROR_STOPNOW; } - else code = 0; + else code = 0; - return code; + return code; } long smb_ReceiveCoreRename(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp) { - long code; - char *oldPathp; - char *newPathp; - char *tp; - cm_space_t *spacep; - smb_renameRock_t rock; - cm_scache_t *oldDscp; - cm_scache_t *newDscp; + long code; + char *oldPathp; + char *newPathp; + char *tp; + cm_space_t *spacep; + smb_renameRock_t rock; + cm_scache_t *oldDscp; + cm_scache_t *newDscp; cm_scache_t *tmpscp; - char *oldLastNamep; - char *newLastNamep; - osi_hyper_t thyper; - cm_user_t *userp; - int caseFold; + char *oldLastNamep; + char *newLastNamep; + osi_hyper_t thyper; + cm_user_t *userp; + int caseFold; char *tidPathp; DWORD filter; cm_req_t req; @@ -3980,78 +4007,83 @@ long smb_ReceiveCoreRename(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp) cm_InitReq(&req); tp = smb_GetSMBData(inp, NULL); - oldPathp = smb_ParseASCIIBlock(tp, &tp); - newPathp = smb_ParseASCIIBlock(tp, &tp); + oldPathp = smb_ParseASCIIBlock(tp, &tp); + newPathp = smb_ParseASCIIBlock(tp, &tp); osi_Log2(afsd_logp, "smb rename %s to %s", - osi_LogSaveString(afsd_logp, oldPathp), - osi_LogSaveString(afsd_logp, newPathp)); + osi_LogSaveString(afsd_logp, oldPathp), + osi_LogSaveString(afsd_logp, newPathp)); spacep = inp->spacep; - smb_StripLastComponent(spacep->data, &oldLastNamep, oldPathp); + smb_StripLastComponent(spacep->data, &oldLastNamep, oldPathp); userp = smb_GetUser(vcp, inp); -/* - * Changed to use CASEFOLD always. This enables us to rename Foo/baz when - * what actually exists is foo/baz. I don't know why the code used to be - * the way it was. 1/29/96 - * - * caseFold = ((vcp->flags & SMB_VCFLAG_USEV3) ? 0: CM_FLAG_CASEFOLD); - * - * Changed to use CM_FLAG_FOLLOW. 7/24/96 - * - * caseFold = CM_FLAG_CASEFOLD; - */ + /* + * Changed to use CASEFOLD always. This enables us to rename Foo/baz when + * what actually exists is foo/baz. I don't know why the code used to be + * the way it was. 1/29/96 + * + * caseFold = ((vcp->flags & SMB_VCFLAG_USEV3) ? 0: CM_FLAG_CASEFOLD); + * + * Changed to use CM_FLAG_FOLLOW. 7/24/96 + * + * caseFold = CM_FLAG_CASEFOLD; + */ caseFold = CM_FLAG_FOLLOW | CM_FLAG_CASEFOLD; tidPathp = smb_GetTIDPath(vcp, ((smb_t *)inp)->tid); code = cm_NameI(cm_rootSCachep, spacep->data, caseFold, - userp, tidPathp, &req, &oldDscp); + userp, tidPathp, &req, &oldDscp); - if (code) { - cm_ReleaseUser(userp); - return code; - } + if (code) { + cm_ReleaseUser(userp); + return code; + } smb_StripLastComponent(spacep->data, &newLastNamep, newPathp); code = cm_NameI(cm_rootSCachep, spacep->data, caseFold, - userp, tidPathp, &req, &newDscp); + userp, tidPathp, &req, &newDscp); - if (code) { + if (code) { cm_ReleaseSCache(oldDscp); - cm_ReleaseUser(userp); - return code; - } + cm_ReleaseUser(userp); + return code; + } - /* otherwise, oldDscp and newDscp point to the corresponding directories. - * next, get the component names, and lower case them. - */ + /* otherwise, oldDscp and newDscp point to the corresponding directories. + * next, get the component names, and lower case them. + */ - /* handle the old name first */ - if (!oldLastNamep) oldLastNamep = oldPathp; - else oldLastNamep++; + /* handle the old name first */ + if (!oldLastNamep) + oldLastNamep = oldPathp; + else + oldLastNamep++; /* and handle the new name, too */ - if (!newLastNamep) newLastNamep = newPathp; - else newLastNamep++; + if (!newLastNamep) + newLastNamep = newPathp; + else + newLastNamep++; /* do the vnode call */ - rock.odscp = oldDscp; - rock.ndscp = newDscp; - rock.userp = userp; + rock.odscp = oldDscp; + rock.ndscp = newDscp; + rock.userp = userp; rock.reqp = &req; - rock.vcp = vcp; - rock.maskp = oldLastNamep; + rock.vcp = vcp; + rock.maskp = oldLastNamep; rock.hasTilde = ((strchr(oldLastNamep, '~') != NULL) ? 1 : 0); - rock.newNamep = newLastNamep; + rock.newNamep = newLastNamep; /* 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) ) { cm_ReleaseSCache(tmpscp); return CM_ERROR_EXISTS; /* file exist, do not rename, also - fixes move*/ + * fixes move + */ } /* Now search the directory for the pattern, and do the appropriate rename when found */ @@ -4074,25 +4106,25 @@ long smb_ReceiveCoreRename(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp) if (oldDscp == newDscp) { if (oldDscp->flags & CM_SCACHEFLAG_ANYWATCH) smb_NotifyChange(FILE_ACTION_RENAMED_OLD_NAME, - filter, oldDscp, oldLastNamep, - newLastNamep, TRUE); + filter, oldDscp, oldLastNamep, + newLastNamep, TRUE); } else { if (oldDscp->flags & CM_SCACHEFLAG_ANYWATCH) smb_NotifyChange(FILE_ACTION_RENAMED_OLD_NAME, - filter, oldDscp, oldLastNamep, - NULL, TRUE); + filter, oldDscp, oldLastNamep, + NULL, TRUE); if (newDscp->flags & CM_SCACHEFLAG_ANYWATCH) smb_NotifyChange(FILE_ACTION_RENAMED_NEW_NAME, - filter, newDscp, newLastNamep, - NULL, TRUE); + filter, newDscp, newLastNamep, + NULL, TRUE); } cm_ReleaseUser(userp); - cm_ReleaseSCache(oldDscp); - cm_ReleaseSCache(newDscp); - - return code; + cm_ReleaseSCache(oldDscp); + cm_ReleaseSCache(newDscp); + + return code; } typedef struct smb_rmdirRock { @@ -4107,12 +4139,12 @@ typedef struct smb_rmdirRock { int smb_RmdirProc(cm_scache_t *dscp, cm_dirEntry_t *dep, void *vrockp, osi_hyper_t *offp) { long code; - smb_rmdirRock_t *rockp; + smb_rmdirRock_t *rockp; int match; char shortName[13]; char *matchName; - rockp = vrockp; + rockp = vrockp; matchName = dep->name; match = (cm_stricmp(matchName, rockp->maskp) == 0); @@ -4125,59 +4157,61 @@ int smb_RmdirProc(cm_scache_t *dscp, cm_dirEntry_t *dep, void *vrockp, osi_hyper } if (match) { osi_Log1(smb_logp, "Removing directory %s", - osi_LogSaveString(smb_logp, matchName)); - code = cm_RemoveDir(dscp, dep->name, rockp->userp, rockp->reqp); + 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, - dscp, dep->name, NULL, TRUE); + FILE_NOTIFY_CHANGE_DIR_NAME, + dscp, dep->name, NULL, TRUE); if (code == 0) rockp->any = 1; } - else code = 0; + else code = 0; - return code; + return code; } long smb_ReceiveCoreRemoveDir(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp) { - long code; - char *pathp; - char *tp; - cm_space_t *spacep; - cm_scache_t *dscp; - char *lastNamep; + long code; + char *pathp; + char *tp; + cm_space_t *spacep; + cm_scache_t *dscp; + char *lastNamep; smb_rmdirRock_t rock; - cm_user_t *userp; + cm_user_t *userp; osi_hyper_t thyper; - int caseFold; + int caseFold; char *tidPathp; - cm_req_t req; + cm_req_t req; cm_InitReq(&req); tp = smb_GetSMBData(inp, NULL); - pathp = smb_ParseASCIIBlock(tp, &tp); + pathp = smb_ParseASCIIBlock(tp, &tp); spacep = inp->spacep; - smb_StripLastComponent(spacep->data, &lastNamep, pathp); + smb_StripLastComponent(spacep->data, &lastNamep, pathp); userp = smb_GetUser(vcp, inp); - caseFold = CM_FLAG_CASEFOLD; + caseFold = CM_FLAG_CASEFOLD; tidPathp = smb_GetTIDPath(vcp, ((smb_t *)inp)->tid); code = cm_NameI(cm_rootSCachep, spacep->data, caseFold | CM_FLAG_FOLLOW, - userp, tidPathp, &req, &dscp); + userp, tidPathp, &req, &dscp); - if (code) { - cm_ReleaseUser(userp); - return code; - } + if (code) { + cm_ReleaseUser(userp); + return code; + } - /* otherwise, scp points to the parent directory. */ - if (!lastNamep) lastNamep = pathp; - else lastNamep++; + /* otherwise, scp points to the parent directory. */ + if (!lastNamep) + lastNamep = pathp; + else + lastNamep++; rock.any = 0; rock.maskp = lastNamep; @@ -4190,13 +4224,13 @@ long smb_ReceiveCoreRemoveDir(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *ou rock.dscp = dscp; code = cm_ApplyDir(dscp, smb_RmdirProc, &rock, &thyper, userp, &req, NULL); - cm_ReleaseUser(userp); + cm_ReleaseUser(userp); - cm_ReleaseSCache(dscp); + cm_ReleaseSCache(dscp); if (code == 0 && !rock.any) code = CM_ERROR_NOSUCHFILE; - return code; + return code; } long smb_ReceiveCoreFlush(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp) @@ -4226,7 +4260,8 @@ long smb_ReceiveCoreFlush(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp) lock_ObtainMutex(&fidp->mx); if (fidp->flags & SMB_FID_OPENWRITE) code = cm_FSync(fidp->scp, userp, &req); - else code = 0; + else + code = 0; lock_ReleaseMutex(&fidp->mx); smb_ReleaseFID(fidp); @@ -4416,7 +4451,7 @@ long smb_ReadData(smb_fid_t *fidp, osi_hyper_t *offsetp, long count, char *op, /* start by looking up the file's end */ code = cm_SyncOp(scp, NULL, userp, &req, 0, - CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS); + CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS); if (code) goto done; /* now we have the entry locked, look up the length */ @@ -4442,81 +4477,82 @@ long smb_ReadData(smb_fid_t *fidp, osi_hyper_t *offsetp, long count, char *op, *readp = count; - /* now, copy the data one buffer at a time, + /* now, copy the data one buffer at a time, * until we've filled the request packet */ - while (1) { + while (1) { /* if we've copied all the data requested, we're done */ - if (count <= 0) break; + if (count <= 0) break; - /* otherwise, load up a buffer of data */ - thyper.HighPart = offset.HighPart; - thyper.LowPart = offset.LowPart & ~(buf_bufferSize-1); - if (!bufferp || !LargeIntegerEqualTo(thyper, bufferOffset)) { + /* otherwise, load up a buffer of data */ + thyper.HighPart = offset.HighPart; + thyper.LowPart = offset.LowPart & ~(buf_bufferSize-1); + if (!bufferp || !LargeIntegerEqualTo(thyper, bufferOffset)) { /* wrong buffer */ - if (bufferp) { - buf_Release(bufferp); - bufferp = NULL; + if (bufferp) { + buf_Release(bufferp); + bufferp = NULL; } lock_ReleaseMutex(&scp->mx); lock_ObtainRead(&scp->bufCreateLock); - code = buf_Get(scp, &thyper, &bufferp); + code = buf_Get(scp, &thyper, &bufferp); lock_ReleaseRead(&scp->bufCreateLock); - lock_ObtainMutex(&scp->mx); - if (code) goto done; - bufferOffset = thyper; + lock_ObtainMutex(&scp->mx); + if (code) goto done; + bufferOffset = thyper; - /* now get the data in the cache */ - while (1) { + /* now get the data in the cache */ + while (1) { code = cm_SyncOp(scp, bufferp, userp, &req, 0, - CM_SCACHESYNC_NEEDCALLBACK - | CM_SCACHESYNC_READ); + CM_SCACHESYNC_NEEDCALLBACK + | CM_SCACHESYNC_READ); if (code) goto done; - if (cm_HaveBuffer(scp, bufferp, 0)) break; - - /* otherwise, load the buffer and try again */ - code = cm_GetBuffer(scp, bufferp, NULL, userp, &req); - if (code) break; - } - if (code) { + if (cm_HaveBuffer(scp, bufferp, 0)) break; + + /* otherwise, load the buffer and try again */ + code = cm_GetBuffer(scp, bufferp, NULL, userp, &req); + if (code) break; + } + if (code) { buf_Release(bufferp); - bufferp = NULL; + bufferp = NULL; goto done; } - } /* if (wrong buffer) ... */ + } /* if (wrong buffer) ... */ - /* now we have the right buffer loaded. Copy out the - * data from here to the user's buffer. - */ + /* now we have the right buffer loaded. Copy out the + * data from here to the user's buffer. + */ bufIndex = offset.LowPart & (buf_bufferSize - 1); /* and figure out how many bytes we want from this buffer */ - nbytes = buf_bufferSize - bufIndex; /* what remains in buffer */ - if (nbytes > count) nbytes = count; /* don't go past EOF */ + nbytes = buf_bufferSize - bufIndex; /* what remains in buffer */ + if (nbytes > count) nbytes = count; /* don't go past EOF */ - /* now copy the data */ + /* now copy the data */ #ifdef DJGPP - if (dosflag) - dosmemput(bufferp->datap + bufIndex, nbytes, (dos_ptr)op); - else + if (dosflag) + dosmemput(bufferp->datap + bufIndex, nbytes, (dos_ptr)op); + else #endif /* DJGPP */ - memcpy(op, bufferp->datap + bufIndex, nbytes); + memcpy(op, bufferp->datap + bufIndex, nbytes); /* adjust counters, pointers, etc. */ - op += nbytes; - count -= nbytes; - thyper.LowPart = nbytes; - thyper.HighPart = 0; - offset = LargeIntegerAdd(thyper, offset); - } /* while 1 */ - -done: + op += nbytes; + count -= nbytes; + thyper.LowPart = nbytes; + thyper.HighPart = 0; + offset = LargeIntegerAdd(thyper, offset); + } /* while 1 */ + + done: lock_ReleaseMutex(&scp->mx); lock_ReleaseMutex(&fidp->mx); - if (bufferp) buf_Release(bufferp); + if (bufferp) + buf_Release(bufferp); if (code == 0 && sequential) cm_ConsiderPrefetch(scp, &lastByte, userp, &req); @@ -4536,26 +4572,26 @@ long smb_WriteData(smb_fid_t *fidp, osi_hyper_t *offsetp, long count, char *op, #endif /* !DJGPP */ { osi_hyper_t offset; - long code; + long code; long written = 0; cm_scache_t *scp; - osi_hyper_t fileLength; /* file's length at start of write */ + 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 */ - cm_buf_t *bufferp; - osi_hyper_t thyper; /* hyper tmp variable */ - osi_hyper_t bufferOffset; - long 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 */ + cm_buf_t *bufferp; + osi_hyper_t thyper; /* hyper tmp variable */ + osi_hyper_t bufferOffset; + long 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 */ DWORD filter = 0; cm_req_t req; cm_InitReq(&req); - bufferp = NULL; - doWriteBack = 0; + bufferp = NULL; + doWriteBack = 0; offset = *offsetp; lock_ObtainMutex(&fidp->mx); @@ -4563,19 +4599,20 @@ long smb_WriteData(smb_fid_t *fidp, osi_hyper_t *offsetp, long count, char *op, lock_ObtainMutex(&scp->mx); /* start by looking up the file's end */ - code = cm_SyncOp(scp, NULL, userp, &req, 0, - CM_SCACHESYNC_NEEDCALLBACK - | CM_SCACHESYNC_SETSTATUS - | CM_SCACHESYNC_GETSTATUS); - if (code) goto done; + code = cm_SyncOp(scp, NULL, userp, &req, 0, + CM_SCACHESYNC_NEEDCALLBACK + | CM_SCACHESYNC_SETSTATUS + | CM_SCACHESYNC_GETSTATUS); + if (code) + goto done; /* make sure we have a writable FD */ - if (!(fidp->flags & SMB_FID_OPENWRITE)) { + if (!(fidp->flags & SMB_FID_OPENWRITE)) { code = CM_ERROR_BADFDOP; goto done; - } + } - /* now we have the entry locked, look up the length */ + /* now we have the entry locked, look up the length */ fileLength = scp->length; minLength = fileLength; if (LargeIntegerGreaterThan(minLength, scp->serverLength)) @@ -4583,87 +4620,86 @@ long smb_WriteData(smb_fid_t *fidp, osi_hyper_t *offsetp, long count, char *op, /* adjust file length if we extend past EOF */ thyper.LowPart = count; - thyper.HighPart = 0; + thyper.HighPart = 0; thyper = LargeIntegerAdd(offset, thyper); /* where write should end */ if (LargeIntegerGreaterThan(thyper, fileLength)) { /* we'd write past EOF, so extend the file */ scp->mask |= CM_SCACHEMASK_LENGTH; - scp->length = thyper; - filter |= - (FILE_NOTIFY_CHANGE_LAST_WRITE | FILE_NOTIFY_CHANGE_SIZE); - } else + scp->length = thyper; + filter |= (FILE_NOTIFY_CHANGE_LAST_WRITE | FILE_NOTIFY_CHANGE_SIZE); + } else filter |= FILE_NOTIFY_CHANGE_LAST_WRITE; - /* now, if the new position (thyper) and the old (offset) are in + /* now, if the new position (thyper) and the old (offset) are in * different storeback windows, remember to store back the previous * storeback window when we're done with the write. - */ + */ if ((thyper.LowPart & (-cm_chunkSize)) != - (offset.LowPart & (-cm_chunkSize))) { + (offset.LowPart & (-cm_chunkSize))) { /* they're different */ - doWriteBack = 1; - writeBackOffset.HighPart = offset.HighPart; - writeBackOffset.LowPart = offset.LowPart & (-cm_chunkSize); - } + doWriteBack = 1; + writeBackOffset.HighPart = offset.HighPart; + writeBackOffset.LowPart = offset.LowPart & (-cm_chunkSize); + } - *writtenp = count; + *writtenp = count; - /* now, copy the data one buffer at a time, until we've filled the + /* now, copy the data one buffer at a time, until we've filled the * request packet */ - while (1) { + while (1) { /* if we've copied all the data requested, we're done */ - if (count <= 0) break; + if (count <= 0) break; /* handle over quota or out of space */ - if (scp->flags & (CM_SCACHEFLAG_OVERQUOTA - | CM_SCACHEFLAG_OUTOFSPACE)) { + if (scp->flags & (CM_SCACHEFLAG_OVERQUOTA | CM_SCACHEFLAG_OUTOFSPACE)) { *writtenp = written; break; } - /* otherwise, load up a buffer of data */ - thyper.HighPart = offset.HighPart; - thyper.LowPart = offset.LowPart & ~(buf_bufferSize-1); - if (!bufferp || !LargeIntegerEqualTo(thyper, bufferOffset)) { + /* otherwise, load up a buffer of data */ + thyper.HighPart = offset.HighPart; + thyper.LowPart = offset.LowPart & ~(buf_bufferSize-1); + if (!bufferp || !LargeIntegerEqualTo(thyper, bufferOffset)) { /* wrong buffer */ - if (bufferp) { + if (bufferp) { lock_ReleaseMutex(&bufferp->mx); - buf_Release(bufferp); - bufferp = NULL; - } + buf_Release(bufferp); + bufferp = NULL; + } lock_ReleaseMutex(&scp->mx); lock_ObtainRead(&scp->bufCreateLock); - code = buf_Get(scp, &thyper, &bufferp); + code = buf_Get(scp, &thyper, &bufferp); lock_ReleaseRead(&scp->bufCreateLock); - lock_ObtainMutex(&bufferp->mx); - lock_ObtainMutex(&scp->mx); - if (code) goto done; + lock_ObtainMutex(&bufferp->mx); + lock_ObtainMutex(&scp->mx); + if (code) goto done; - bufferOffset = thyper; + bufferOffset = thyper; - /* now get the data in the cache */ - while (1) { + /* now get the data in the cache */ + while (1) { code = cm_SyncOp(scp, bufferp, userp, &req, 0, - CM_SCACHESYNC_NEEDCALLBACK - | CM_SCACHESYNC_WRITE - | CM_SCACHESYNC_BUFLOCKED); - if (code) goto done; + CM_SCACHESYNC_NEEDCALLBACK + | CM_SCACHESYNC_WRITE + | CM_SCACHESYNC_BUFLOCKED); + if (code) + goto done; /* If we're overwriting the entire buffer, or * if we're writing at or past EOF, mark the * buffer as current so we don't call * cm_GetBuffer. This skips the fetch from the * server in those cases where we're going to - * obliterate all the data in the buffer anyway, + * obliterate all the data in the buffer anyway, * or in those cases where there is no useful * data at the server to start with. - * - * Use minLength instead of scp->length, since + * + * Use minLength instead of scp->length, since * the latter has already been updated by this * call. - */ + */ if (LargeIntegerGreaterThanOrEqualTo( bufferp->offset, minLength) || LargeIntegerEqualTo(offset, bufferp->offset) @@ -4679,81 +4715,82 @@ long smb_WriteData(smb_fid_t *fidp, osi_hyper_t *offsetp, long count, char *op, bufferp->dataVersion = scp->dataVersion; } - if (cm_HaveBuffer(scp, bufferp, 1)) break; - - /* otherwise, load the buffer and try again */ - lock_ReleaseMutex(&bufferp->mx); - code = cm_GetBuffer(scp, bufferp, NULL, userp, - &req); - lock_ReleaseMutex(&scp->mx); - lock_ObtainMutex(&bufferp->mx); + if (cm_HaveBuffer(scp, bufferp, 1)) break; + + /* otherwise, load the buffer and try again */ + lock_ReleaseMutex(&bufferp->mx); + code = cm_GetBuffer(scp, bufferp, NULL, userp, + &req); + lock_ReleaseMutex(&scp->mx); + lock_ObtainMutex(&bufferp->mx); lock_ObtainMutex(&scp->mx); - if (code) break; - } - if (code) { + if (code) break; + } + if (code) { lock_ReleaseMutex(&bufferp->mx); buf_Release(bufferp); - bufferp = NULL; + bufferp = NULL; goto done; } - } /* if (wrong buffer) ... */ + } /* if (wrong buffer) ... */ - /* now we have the right buffer loaded. Copy out the - * data from here to the user's buffer. - */ + /* now we have the right buffer loaded. Copy out the + * data from here to the user's buffer. + */ bufIndex = offset.LowPart & (buf_bufferSize - 1); /* and figure out how many bytes we want from this buffer */ - nbytes = buf_bufferSize - bufIndex; /* what remains in buffer */ - if (nbytes > count) nbytes = count; /* don't go past end of request */ + nbytes = buf_bufferSize - bufIndex; /* what remains in buffer */ + if (nbytes > count) + nbytes = count; /* don't go past end of request */ - /* now copy the data */ + /* now copy the data */ #ifdef DJGPP - if (dosflag) - dosmemget((dos_ptr)op, nbytes, bufferp->datap + bufIndex); - else + if (dosflag) + dosmemget((dos_ptr)op, nbytes, bufferp->datap + bufIndex); + else #endif /* DJGPP */ - memcpy(bufferp->datap + bufIndex, op, nbytes); - buf_SetDirty(bufferp); + memcpy(bufferp->datap + bufIndex, op, nbytes); + buf_SetDirty(bufferp); /* and record the last writer */ if (bufferp->userp != userp) { - if (bufferp->userp) cm_ReleaseUser(bufferp->userp); - bufferp->userp = userp; - cm_HoldUser(userp); + if (bufferp->userp) cm_ReleaseUser(bufferp->userp); + bufferp->userp = userp; + cm_HoldUser(userp); } /* adjust counters, pointers, etc. */ - op += nbytes; - count -= nbytes; + op += nbytes; + count -= nbytes; written += nbytes; - thyper.LowPart = nbytes; - thyper.HighPart = 0; - offset = LargeIntegerAdd(thyper, offset); - } /* while 1 */ + thyper.LowPart = nbytes; + thyper.HighPart = 0; + offset = LargeIntegerAdd(thyper, offset); + } /* while 1 */ -done: + done: lock_ReleaseMutex(&scp->mx); lock_ReleaseMutex(&fidp->mx); - if (bufferp) { + if (bufferp) { lock_ReleaseMutex(&bufferp->mx); - buf_Release(bufferp); + buf_Release(bufferp); } if (code == 0 && filter != 0 && (fidp->flags & SMB_FID_NTOPEN) && (fidp->NTopen_dscp->flags & CM_SCACHEFLAG_ANYWATCH)) { smb_NotifyChange(FILE_ACTION_MODIFIED, filter, - fidp->NTopen_dscp, fidp->NTopen_pathp, - NULL, TRUE); + fidp->NTopen_dscp, fidp->NTopen_pathp, + NULL, TRUE); } - if (code == 0 && doWriteBack) { + if (code == 0 && doWriteBack) { lock_ObtainMutex(&scp->mx); cm_SyncOp(scp, NULL, userp, &req, 0, CM_SCACHESYNC_ASYNCSTORE); lock_ReleaseMutex(&scp->mx); - cm_QueueBKGRequest(scp, cm_BkgStore, writeBackOffset.LowPart, - writeBackOffset.HighPart, cm_chunkSize, 0, userp); - } + cm_QueueBKGRequest(scp, cm_BkgStore, writeBackOffset.LowPart, + writeBackOffset.HighPart, cm_chunkSize, 0, userp); + } return code; } @@ -4855,7 +4892,7 @@ void smb_CompleteWriteRaw(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp, #ifndef DJGPP char *rawBuf; #else /* DJGPP */ - dos_ptr rawBuf; + dos_ptr rawBuf; #endif /* !DJGPP */ long written = 0; long code; @@ -4864,14 +4901,14 @@ void smb_CompleteWriteRaw(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp, fidp = smb_FindFID(vcp, fd, 0); osi_Log2(afsd_logp, "Completing Raw Write offset %x count %x", - rwcp->offset.LowPart, rwcp->count); + rwcp->offset.LowPart, rwcp->count); userp = smb_GetUser(vcp, inp); #ifndef DJGPP rawBuf = rwcp->buf; code = smb_WriteData(fidp, &rwcp->offset, rwcp->count, rawBuf, userp, - &written); + &written); #else /* DJGPP */ rawBuf = (dos_ptr) rwcp->buf; code = smb_WriteData(fidp, &rwcp->offset, rwcp->count, @@ -4920,33 +4957,33 @@ long smb_ReceiveCoreWriteRawDummy(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t long smb_ReceiveCoreWriteRaw(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp, raw_write_cont_t *rwcp) { osi_hyper_t offset; - long count, written = 0; + long count, written = 0; long totalCount; - unsigned short fd; - smb_fid_t *fidp; - long code; - cm_user_t *userp; - char *op; + unsigned short fd; + smb_fid_t *fidp; + long code; + cm_user_t *userp; + char *op; unsigned short writeMode; #ifndef DJGPP char *rawBuf; #else /* DJGPP */ - dos_ptr rawBuf; + dos_ptr rawBuf; #endif /* !DJGPP */ - fd = smb_GetSMBParm(inp, 0); + fd = smb_GetSMBParm(inp, 0); totalCount = smb_GetSMBParm(inp, 1); - count = smb_GetSMBParm(inp, 10); - offset.HighPart = 0; /* too bad */ - offset.LowPart = smb_GetSMBParm(inp, 3) | (smb_GetSMBParm(inp, 4) << 16); + count = smb_GetSMBParm(inp, 10); + offset.HighPart = 0; /* too bad */ + offset.LowPart = smb_GetSMBParm(inp, 3) | (smb_GetSMBParm(inp, 4) << 16); writeMode = smb_GetSMBParm(inp, 7); op = (char *) inp->data; op += smb_GetSMBParm(inp, 11); - osi_Log4(afsd_logp, - "smb_ReceiveCoreWriteRaw fd %d, off 0x%x, size 0x%x, WriteMode 0x%x", - fd, offset.LowPart, count, writeMode); + osi_Log4(afsd_logp, + "smb_ReceiveCoreWriteRaw fd %d, off 0x%x, size 0x%x, WriteMode 0x%x", + fd, offset.LowPart, count, writeMode); fd = smb_ChainFID(fd, inp); fidp = smb_FindFID(vcp, fd, 0); @@ -5105,106 +5142,108 @@ long smb_ReceiveCoreRead(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp) long smb_ReceiveCoreMakeDir(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp) { char *pathp; - long code; + long code; cm_space_t *spacep; - char *tp; - cm_user_t *userp; - cm_scache_t *dscp; /* dir we're dealing with */ - cm_scache_t *scp; /* file we're creating */ - cm_attr_t setAttr; - int initialModeBits; - char *lastNamep; - int caseFold; + char *tp; + cm_user_t *userp; + cm_scache_t *dscp; /* dir we're dealing with */ + cm_scache_t *scp; /* file we're creating */ + cm_attr_t setAttr; + int initialModeBits; + char *lastNamep; + int caseFold; char *tidPathp; cm_req_t req; cm_InitReq(&req); - scp = NULL; + scp = NULL; /* compute initial mode bits based on read-only flag in attributes */ - initialModeBits = 0777; + initialModeBits = 0777; tp = smb_GetSMBData(inp, NULL); - pathp = smb_ParseASCIIBlock(tp, &tp); + pathp = smb_ParseASCIIBlock(tp, &tp); if (strcmp(pathp, "\\") == 0) return CM_ERROR_EXISTS; spacep = inp->spacep; - smb_StripLastComponent(spacep->data, &lastNamep, pathp); + smb_StripLastComponent(spacep->data, &lastNamep, pathp); userp = smb_GetUser(vcp, inp); - caseFold = CM_FLAG_CASEFOLD; + caseFold = CM_FLAG_CASEFOLD; tidPathp = smb_GetTIDPath(vcp, ((smb_t *)inp)->tid); code = cm_NameI(cm_rootSCachep, spacep->data, - caseFold | CM_FLAG_FOLLOW | CM_FLAG_CHECKPATH, - userp, tidPathp, &req, &dscp); + caseFold | CM_FLAG_FOLLOW | CM_FLAG_CHECKPATH, + userp, tidPat hp, &req, &dscp); - if (code) { - cm_ReleaseUser(userp); - return code; - } + if (code) { + cm_ReleaseUser(userp); + return code; + } - /* otherwise, scp points to the parent directory. Do a lookup, and + /* otherwise, scp points to the parent directory. Do a lookup, and * fail if we find it. Otherwise, we do the create. - */ - if (!lastNamep) lastNamep = pathp; - else lastNamep++; - code = cm_Lookup(dscp, lastNamep, caseFold, userp, &req, &scp); - if (scp) cm_ReleaseSCache(scp); - if (code != CM_ERROR_NOSUCHFILE) { - if (code == 0) code = CM_ERROR_EXISTS; + */ + if (!lastNamep) + lastNamep = pathp; + else + lastNamep++; + code = cm_Lookup(dscp, lastNamep, caseFold, userp, &req, &scp); + if (scp) cm_ReleaseSCache(scp); + if (code != CM_ERROR_NOSUCHFILE) { + if (code == 0) code = CM_ERROR_EXISTS; cm_ReleaseSCache(dscp); - cm_ReleaseUser(userp); - return code; - } + cm_ReleaseUser(userp); + return code; + } setAttr.mask = CM_ATTRMASK_CLIENTMODTIME; setAttr.clientModTime = time(NULL); code = cm_MakeDir(dscp, lastNamep, 0, &setAttr, userp, &req); if (code == 0 && (dscp->flags & CM_SCACHEFLAG_ANYWATCH)) smb_NotifyChange(FILE_ACTION_ADDED, - FILE_NOTIFY_CHANGE_DIR_NAME, - dscp, lastNamep, NULL, TRUE); + FILE_NOTIFY_CHANGE_DIR_NAME, + dscp, lastNamep, NULL, TRUE); /* we don't need this any longer */ cm_ReleaseSCache(dscp); - if (code) { + if (code) { /* something went wrong creating or truncating the file */ - cm_ReleaseUser(userp); - return code; - } + cm_ReleaseUser(userp); + return code; + } /* otherwise we succeeded */ - smb_SetSMBDataLength(outp, 0); - cm_ReleaseUser(userp); + smb_SetSMBDataLength(outp, 0); + cm_ReleaseUser(userp); - return 0; + return 0; } BOOL smb_IsLegalFilename(char *filename) { - /* - * Find the longest substring of filename that does not contain - * any of the chars in illegalChars. If that substring is less - * than the length of the whole string, then one or more of the - * illegal chars is in filename. - */ - if (strcspn(filename, illegalChars) < strlen(filename)) - return FALSE; + /* + * Find the longest substring of filename that does not contain + * any of the chars in illegalChars. If that substring is less + * than the length of the whole string, then one or more of the + * illegal chars is in filename. + */ + if (strcspn(filename, illegalChars) < strlen(filename)) + return FALSE; - return TRUE; + return TRUE; } long smb_ReceiveCoreCreate(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp) { char *pathp; - long code; + long code; cm_space_t *spacep; char *tp; int excl; @@ -5462,8 +5501,8 @@ void smb_DispatchPacket(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp, 1, ncbp->ncb_length, ptbuf, inp); DeregisterEventSource(h); #else /* DJGPP */ - osi_Log1(smb_logp, "SMB message too short, len %d", - ncbp->ncb_length); + osi_Log1(smb_logp, "SMB message too short, len %d", + ncbp->ncb_length); #endif /* !DJGPP */ return; @@ -5472,17 +5511,17 @@ void smb_DispatchPacket(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp, /* We are an ongoing op */ thrd_Increment(&ongoingOps); - /* set up response packet for receiving output */ + /* set up response packet for receiving output */ if (!(outp->flags & SMB_PACKETFLAG_SUSPENDED)) - smb_FormatResponsePacket(vcp, inp, outp); - outWctp = outp->wctp; + smb_FormatResponsePacket(vcp, inp, outp); + outWctp = outp->wctp; /* Remember session generation number and time */ oldGen = sessionGen; oldTime = GetCurrentTime(); while(inp->inCom != 0xff) { - dp = &smb_dispatchTable[inp->inCom]; + dp = &smb_dispatchTable[inp->inCom]; if (outp->flags & SMB_PACKETFLAG_SUSPENDED) { outp->flags &= ~SMB_PACKETFLAG_SUSPENDED; @@ -5490,48 +5529,48 @@ void smb_DispatchPacket(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp, goto resume; } - /* process each request in the packet; inCom, wctp and inCount - * are already set up. - */ + /* process each request in the packet; inCom, wctp and inCount + * are already set up. + */ osi_Log2(afsd_logp, "SMB received op 0x%x lsn %d", inp->inCom, - ncbp->ncb_lsn); + ncbp->ncb_lsn); /* now do the dispatch */ /* start by formatting the response record a little, as a default */ - if (dp->flags & SMB_DISPATCHFLAG_CHAINED) { + if (dp->flags & SMB_DISPATCHFLAG_CHAINED) { outWctp[0] = 2; - outWctp[1] = 0xff; /* no operation */ - outWctp[2] = 0; /* padding */ - outWctp[3] = 0; - outWctp[4] = 0; - } + outWctp[1] = 0xff; /* no operation */ + outWctp[2] = 0; /* padding */ + outWctp[3] = 0; + outWctp[4] = 0; + } else { /* not a chained request, this is a more reasonable default */ - outWctp[0] = 0; /* wct of zero */ - outWctp[1] = 0; /* and bcc (word) of zero */ - outWctp[2] = 0; - } + outWctp[0] = 0; /* wct of zero */ + outWctp[1] = 0; /* and bcc (word) of zero */ + outWctp[2] = 0; + } /* once set, stays set. Doesn't matter, since we never chain - * "no response" calls. - */ + * "no response" calls. + */ if (dp->flags & SMB_DISPATCHFLAG_NORESPONSE) - noSend = 1; + noSend = 1; - if (dp->procp) { + if (dp->procp) { /* we have a recognized operation */ if (inp->inCom == 0x1d) /* Raw Write */ code = smb_ReceiveCoreWriteRaw (vcp, inp, outp, - rwcp); + rwcp); else { osi_LogEvent("AFS Dispatch %s",(myCrt_Dispatch(inp->inCom)),"vcp[%x] lana[%d] lsn[%d]",(int)vcp,vcp->lana,vcp->lsn); osi_Log4(afsd_logp,"Dispatch %s vcp[%x] lana[%d] lsn[%d]",(myCrt_Dispatch(inp->inCom)),vcp,vcp->lana,vcp->lsn); code = (*(dp->procp)) (vcp, inp, outp); osi_LogEvent("AFS Dispatch return",NULL,"Code[%d]",(code==0)?0:code-CM_ERROR_BASE); osi_Log1(afsd_logp,"Dispatch return code[%d]",(code==0)?0:code-CM_ERROR_BASE); - } + } if (oldGen != sessionGen) { #ifndef DJGPP @@ -5541,18 +5580,18 @@ void smb_DispatchPacket(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp, newTime = GetCurrentTime(); h = RegisterEventSource(NULL, AFS_DAEMON_EVENT_NAME); sprintf(s, "Pkt straddled session startup, took %d ms, ncb length %d", - newTime - oldTime, ncbp->ncb_length); + newTime - oldTime, ncbp->ncb_length); ptbuf[0] = s; ReportEvent(h, EVENTLOG_WARNING_TYPE, 0, - 1005, NULL, 1, ncbp->ncb_length, ptbuf, smbp); + 1005, NULL, 1, ncbp->ncb_length, ptbuf, smbp); DeregisterEventSource(h); #else /* DJGPP */ osi_Log1(afsd_logp, "Pkt straddled session startup, " - "ncb length %d", ncbp->ncb_length); + "ncb length %d", ncbp->ncb_length); #endif /* !DJGPP */ } - } - else { + } + else { /* bad opcode, fail the request, after displaying it */ #ifdef NOTSERVICE smb_LogPacket(inp); @@ -5561,13 +5600,13 @@ void smb_DispatchPacket(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp, #ifndef DJGPP if (showErrors) { sprintf(tbuffer, "Received bad SMB req 0x%x", inp->inCom); - code = (*smb_MBfunc)(NULL, tbuffer, "Cancel: don't show again", - MB_OKCANCEL); - if (code == IDCANCEL) showErrors = 0; + code = (*smb_MBfunc)(NULL, tbuffer, "Cancel: don't show again", + MB_OKCANCEL); + if (code == IDCANCEL) showErrors = 0; } #endif /* DJGPP */ - code = CM_ERROR_BADOP; - } + code = CM_ERROR_BADOP; + } /* catastrophic failure: log as much as possible */ if (code == CM_ERROR_BADSMB) { @@ -5577,22 +5616,22 @@ void smb_DispatchPacket(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp, char s[100]; osi_Log1(smb_logp, - "Invalid SMB, ncb_length %d", - ncbp->ncb_length); + "Invalid SMB, ncb_length %d", + ncbp->ncb_length); h = RegisterEventSource(NULL, AFS_DAEMON_EVENT_NAME); sprintf(s, "Invalid SMB message, length %d", - ncbp->ncb_length); + ncbp->ncb_length); ptbuf[0] = s; ReportEvent(h, EVENTLOG_ERROR_TYPE, 0, 1002, NULL, - 1, ncbp->ncb_length, ptbuf, smbp); + 1, ncbp->ncb_length, ptbuf, smbp); DeregisterEventSource(h); #ifdef NOTSERVICE smb_LogPacket(inp); #endif /* NOTSERVICE */ #else /* DJGPP */ osi_Log1(afsd_logp, "Invalid SMB message, length %d", - ncbp->ncb_length); + ncbp->ncb_length); #endif /* !DJGPP */ code = CM_ERROR_INVAL; @@ -5603,10 +5642,10 @@ void smb_DispatchPacket(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp, return; } -resume: + resume: /* now, if we failed, turn the current response into an empty - * one, and fill in the response packet's error code. - */ + * one, and fill in the response packet's error code. + */ if (code) { if (vcp->flags & SMB_VCFLAG_STATUS32) { smb_MapNTError(code, &NTStatus); @@ -5629,7 +5668,7 @@ resume: break; } else { - smb_MapCoreError(code, vcp, &errCode, &errClass); + smb_MapCoreError(code, vcp, &errCode, &errClass); outWctp = outp->wctp; smbp = (smb_t *) &outp->data; if (code != CM_ERROR_PARTIALWRITE) { @@ -5642,49 +5681,50 @@ resume: } smbp->errLow = (unsigned char) (errCode & 0xff); smbp->errHigh = (unsigned char) ((errCode >> 8) & 0xff); - smbp->rcls = errClass; + smbp->rcls = errClass; break; } } /* error occurred */ - /* if we're here, we've finished one request. Look to see if + /* if we're here, we've finished one request. Look to see if * this is a chained opcode. If it is, setup things to process * the chained request, and setup the output buffer to hold the * chained response. Start by finding the next input record. - */ - if (!(dp->flags & SMB_DISPATCHFLAG_CHAINED)) - break; /* not a chained req */ - tp = inp->wctp; /* points to start of last request */ - if (tp[0] < 2) break; /* in a chained request, the first two - * parm fields are required, and are - * AndXCommand/AndXReserved and - * AndXOffset. */ - if (tp[1] == 0xff) break; /* no more chained opcodes */ - inp->inCom = tp[1]; - inp->wctp = inp->data + tp[3] + (tp[4] << 8); - inp->inCount++; - - /* and now append the next output request to the end of this - * last request. Begin by finding out where the last response + */ + if (!(dp->flags & SMB_DISPATCHFLAG_CHAINED)) + break; /* not a chained req */ + tp = inp->wctp; /* points to start of last request */ + /* in a chained request, the first two + * parm fields are required, and are + * AndXCommand/AndXReserved and + * AndXOffset. */ + if (tp[0] < 2) break; + if (tp[1] == 0xff) break; /* no more chained opcodes */ + inp->inCom = tp[1]; + inp->wctp = inp->data + tp[3] + (tp[4] << 8); + inp->inCount++; + + /* and now append the next output request to the end of this + * last request. Begin by finding out where the last response * ends, since that's where we'll put our new response. - */ - outWctp = outp->wctp; /* ptr to out parameters */ - osi_assert (outWctp[0] >= 2); /* need this for all chained requests */ - nparms = outWctp[0] << 1; - tp = outWctp + nparms + 1; /* now points to bcc field */ - nbytes = tp[0] + (tp[1] << 8); /* # of data bytes */ - tp += 2 /* for the count itself */ + nbytes; + */ + outWctp = outp->wctp; /* ptr to out parameters */ + osi_assert (outWctp[0] >= 2); /* need this for all chained requests */ + nparms = outWctp[0] << 1; + tp = outWctp + nparms + 1; /* now points to bcc field */ + nbytes = tp[0] + (tp[1] << 8); /* # of data bytes */ + tp += 2 /* for the count itself */ + nbytes; /* tp now points to the new output record; go back and patch the - * second parameter (off2) to point to the new record. - */ + * second parameter (off2) to point to the new record. + */ temp = (unsigned int)tp - ((unsigned int) outp->data); - outWctp[3] = (unsigned char) (temp & 0xff); - outWctp[4] = (unsigned char) ((temp >> 8) & 0xff); - outWctp[2] = 0; /* padding */ - outWctp[1] = inp->inCom; /* next opcode */ + outWctp[3] = (unsigned char) (temp & 0xff); + outWctp[4] = (unsigned char) ((temp >> 8) & 0xff); + outWctp[2] = 0; /* padding */ + outWctp[1] = inp->inCom; /* next opcode */ /* finally, setup for the next iteration */ - outp->wctp = tp; + outp->wctp = tp; outWctp = tp; } /* while loop over all requests in the packet */ @@ -5700,8 +5740,8 @@ resume: } } - /* now send the output packet, and return */ - if (!noSend) + /* now send the output packet, and return */ + if (!noSend) smb_SendPacket(vcp, outp); thrd_Decrement(&ongoingOps); @@ -5712,7 +5752,7 @@ resume: else if (active_vcp == vcp) active_vcp = NULL; - return; + return; } #ifndef DJGPP @@ -5755,7 +5795,7 @@ void smb_ClientWaiter(void *parmp) afsi_log("Error: smb_ClientWaiter WAIT_FAILED, errno %d\n", GetLastError()); } - idx = code - WAIT_OBJECT_0; + idx = code - WAIT_OBJECT_0; /* check idx range! */ if (idx < 0 || idx > (sizeof(NCBevents) / sizeof(NCBevents[0]))) @@ -5781,7 +5821,7 @@ void smb_ServerWaiter(void *parmp) int idx_session, idx_NCB; NCB *ncbp; #ifdef DJGPP - dos_ptr dos_ncb; + dos_ptr dos_ncb; #endif /* DJGPP */ while (1) { @@ -5824,7 +5864,7 @@ void smb_ServerWaiter(void *parmp) } /* Get an NCB */ -NCBretry: + NCBretry: code = thrd_WaitForMultipleObjects_Event(numNCBs, NCBavails, FALSE, INFINITE); if (code == WAIT_OBJECT_0) @@ -5869,7 +5909,7 @@ NCBretry: /* Fire it up */ ncbp = NCBs[idx_NCB]; #ifdef DJGPP - dos_ncb = ((smb_ncb_t *)ncbp)->dos_ncb; + dos_ncb = ((smb_ncb_t *)ncbp)->dos_ncb; #endif /* DJGPP */ ncbp->ncb_lsn = (unsigned char) LSNs[idx_session]; ncbp->ncb_command = NCBRECV | ASYNCH; @@ -5912,7 +5952,7 @@ void smb_Server(VOID *parmp) smb_vc_t *vcp; smb_t *smbp; #ifdef DJGPP - dos_ptr dos_ncb; + dos_ptr dos_ncb; #endif /* DJGPP */ outncbp = GetNCB(); @@ -6039,33 +6079,31 @@ void smb_Server(VOID *parmp) char *ptbuf[1]; char s[100]; - osi_Log1(smb_logp, - "dispatch smb recv failed, message incomplete, ncb_length %d", - ncbp->ncb_length); - h = RegisterEventSource(NULL, - AFS_DAEMON_EVENT_NAME); + osi_Log1(smb_logp, "dispatch smb recv failed, message incomplete, ncb_length %d", + ncbp->ncb_length); + h = RegisterEventSource(NULL, AFS_DAEMON_EVENT_NAME); sprintf(s, "SMB message incomplete, length %d", - ncbp->ncb_length); + ncbp->ncb_length); ptbuf[0] = s; ReportEvent(h, EVENTLOG_WARNING_TYPE, 0, - 1001, NULL, 1, - ncbp->ncb_length, ptbuf, - bufp); + 1001, NULL, 1, + ncbp->ncb_length, ptbuf, + bufp); DeregisterEventSource(h); #else /* DJGPP */ osi_Log1(smb_logp, - "dispatch smb recv failed, message incomplete, ncb_length %d", - ncbp->ncb_length); - osi_Log1(smb_logp, - "SMB message incomplete, " - "length %d", ncbp->ncb_length); + "dispatch smb recv failed, message incomplete, ncb_length %d", + ncbp->ncb_length); + osi_Log1(smb_logp, + "SMB message incomplete, " + "length %d", ncbp->ncb_length); #endif /* !DJGPP */ /* * We used to discard the packet. * Instead, try handling it normally. * - continue; + continue; */ break; } @@ -6148,12 +6186,12 @@ void smb_Server(VOID *parmp) bufp = (struct smb_packet *) ncbp->ncb_buffer; #ifdef DJGPP bufp = ((smb_ncb_t *) ncbp)->orig_pkt; - /* copy whole packet to virtual memory */ - /*fprintf(stderr, "smb_Server: copying dos packet at 0x%x, " - "bufp=0x%x\n", - bufp->dos_pkt / 16, bufp);*/ - fflush(stderr); - dosmemget(bufp->dos_pkt, ncbp->ncb_length, bufp->data); + /* copy whole packet to virtual memory */ + /*fprintf(stderr, "smb_Server: copying dos packet at 0x%x, " + "bufp=0x%x\n", + bufp->dos_pkt / 16, bufp);*/ + fflush(stderr); + dosmemget(bufp->dos_pkt, ncbp->ncb_length, bufp->data); #endif /* DJGPP */ smbp = (smb_t *)bufp->data; outbufp->flags = 0; @@ -6191,13 +6229,13 @@ void smb_Server(VOID *parmp) if (rwc.code == 0) smb_CompleteWriteRaw(vcp, bufp, outbufp, ncbp, &rwc); } else if (smbp->com == 0xa0) { - /* - * Serialize the handling for NT Transact - * (defect 11626) - */ - smb_DispatchPacket(vcp, bufp, outbufp, ncbp, NULL); + /* + * Serialize the handling for NT Transact + * (defect 11626) + */ + smb_DispatchPacket(vcp, bufp, outbufp, ncbp, NULL); thrd_SetEvent(SessionEvents[idx_session]); - } else { + } else { thrd_SetEvent(SessionEvents[idx_session]); /* TODO: what else needs to be serialized? */ smb_DispatchPacket(vcp, bufp, outbufp, ncbp, NULL); @@ -6300,7 +6338,7 @@ void smb_Listener(void *parmp) ncbp = GetNCB(); #ifdef DJGPP - dos_ncb = ((smb_ncb_t *)ncbp)->dos_ncb; + dos_ncb = ((smb_ncb_t *)ncbp)->dos_ncb; #endif /* DJGPP */ /* retrieve computer name */ @@ -6311,9 +6349,9 @@ void smb_Listener(void *parmp) memset(ncbp, 0, sizeof(NCB)); flags = 0; #ifdef DJGPP - /* terminate if shutdown flag is set */ - if (smbShutdownFlag == 1) - thrd_Exit(1); + /* terminate if shutdown flag is set */ + if (smbShutdownFlag == 1) + thrd_Exit(1); #endif /* DJGPP */ #ifndef NOEXPIRE @@ -6322,43 +6360,43 @@ void smb_Listener(void *parmp) unsigned long tod = time((void *) 0); if (tod > EXPIREDATE) { (*smb_MBfunc)(NULL, "AFS demo expiration", - "afsd listener", - MB_OK|MB_ICONSTOP|MB_SETFOREGROUND); + "afsd listener", + MB_OK|MB_ICONSTOP|MB_SETFOREGROUND); ExitThread(1); } } #endif /* !NOEXPIRE */ - ncbp->ncb_command = NCBLISTEN; - ncbp->ncb_rto = 0; /* No receive timeout */ - ncbp->ncb_sto = 0; /* No send timeout */ + ncbp->ncb_command = NCBLISTEN; + ncbp->ncb_rto = 0; /* No receive timeout */ + ncbp->ncb_sto = 0; /* No send timeout */ /* pad out with spaces instead of null termination */ len = strlen(smb_localNamep); - strncpy(ncbp->ncb_name, smb_localNamep, NCBNAMSZ); - for(i=len; incb_name[i] = ' '; + strncpy(ncbp->ncb_name, smb_localNamep, NCBNAMSZ); + for(i=len; incb_name[i] = ' '; - strcpy(ncbp->ncb_callname, "*"); - for(i=1; incb_callname[i] = ' '; + strcpy(ncbp->ncb_callname, "*"); + for(i=1; incb_callname[i] = ' '; ncbp->ncb_lana_num = lana; #ifndef DJGPP - code = Netbios(ncbp); + code = Netbios(ncbp); #else /* DJGPP */ - code = Netbios(ncbp, dos_ncb); + code = Netbios(ncbp, dos_ncb); - if (code != 0) - { - fprintf(stderr, "NCBLISTEN lana=%d failed with code %d\n", - ncbp->ncb_lana_num, code); - osi_Log2(0, "NCBLISTEN lana=%d failed with code %d", - ncbp->ncb_lana_num, code); - fprintf(stderr, "\nClient exiting due to network failure " - "(possibly due to power-saving mode)\n"); - fprintf(stderr, "Please restart client.\n"); - afs_exit(AFS_EXITCODE_NETWORK_FAILURE); - } + if (code != 0) + { + fprintf(stderr, "NCBLISTEN lana=%d failed with code %d\n", + ncbp->ncb_lana_num, code); + osi_Log2(0, "NCBLISTEN lana=%d failed with code %d", + ncbp->ncb_lana_num, code); + fprintf(stderr, "\nClient exiting due to network failure " + "(possibly due to power-saving mode)\n"); + fprintf(stderr, "Please restart client.\n"); + afs_exit(AFS_EXITCODE_NETWORK_FAILURE); + } #endif /* !DJGPP */ osi_assert(code == 0); @@ -6401,20 +6439,18 @@ void smb_Listener(void *parmp) char s[100]; h = RegisterEventSource(NULL, AFS_DAEMON_EVENT_NAME); - sprintf(s, "SMB session startup, %d ongoing ops", - ongoingOps); + sprintf(s, "SMB session startup, %d ongoing ops", ongoingOps); ptbuf[0] = s; ReportEvent(h, EVENTLOG_WARNING_TYPE, 0, 1004, NULL, - 1, 0, ptbuf, NULL); + 1, 0, ptbuf, NULL); DeregisterEventSource(h); #else /* DJGPP */ afsi_log("NCBLISTEN completed, call from %s",rname); osi_Log1(afsd_logp, "SMB session startup, %d ongoing ops", - ongoingOps); + ongoingOps); time(&now); - fprintf(stderr, "%s: New session %d starting from host " - "%s\n", - asctime(localtime(&now)), ncbp->ncb_lsn, rname); + fprintf(stderr, "%s: New session %d starting from host %s\n", + asctime(localtime(&now)), ncbp->ncb_lsn, rname); fflush(stderr); #endif /* !DJGPP */ } @@ -6493,14 +6529,14 @@ void smb_NetbiosInit() /*******************************************************************/ struct { - ADAPTER_STATUS status; - NAME_BUFFER NameBuff [30]; - } Adapter; + ADAPTER_STATUS status; + NAME_BUFFER NameBuff [30]; + } Adapter; int j; BOOL wla_found; - /* AFAIK, this is the default for the ms loopback adapter.*/ + /* AFAIK, this is the default for the ms loopback adapter.*/ unsigned char kWLA_MAC[6] = { 0x02, 0x00, 0x4c, 0x4f, 0x4f, 0x50 }; /*******************************************************************/ @@ -6550,54 +6586,6 @@ void smb_NetbiosInit() } else { sprintf(s, "Netbios NCBRESET lana %d succeeded", lana_list.lana[i]); afsi_log(s); - -#ifdef COMMENT - /* This code searches for the loopback adapter but - * we already did this during afsd_init - */ - memset( ncbp, 0, sizeof (*ncbp) ); - ncbp->ncb_command = NCBASTAT; - ncbp->ncb_lana_num = lana_list.lana[i]; - strcpy( ncbp->ncb_callname, "* " ); - ncbp->ncb_buffer = (char *) &Adapter; - ncbp->ncb_length = sizeof(Adapter); - code = Netbios( ncbp ); - - if ( code == 0 ) { - wla_found = TRUE; - for (j=0; wla_found && (j<6); j++) - wla_found = ( Adapter.status.adapter_address[j] == kWLA_MAC[j] ); - - if ( wla_found ) { - /* - * check to see if this is the Microsoft Loopback Adapter" - * if we are running on Windows XP or higher - * or if we only have the loopback adapter because it was - * selected during afsd_init - */ - if ( Version.dwPlatformId == VER_PLATFORM_WIN32_NT && - ( lana_list.length == 1 || - ( Version.dwMajorVersion > 5 || - Version.dwMajorVersion == 5 && - Version.dwMinorVersion >= 1 ) - ) - ) - { - sprintf(s, "Windows Loopback Adapter detected lana %d", lana_list.lana[i]); - afsi_log(s); - - /* select this lana; no need to continue */ - lana_list.length = 1; - lana_list.lana[0] = lana_list.lana[i]; - break; - } else { - sprintf(s, "Windows Loopback Adapter disabled lana %d", lana_list.lana[i]); - afsi_log(s); - lana_list.lana[i] = 255; /* invalid lana */ - } - } - } -#endif /* COMMENT */ } } #else @@ -6619,12 +6607,6 @@ void smb_NetbiosInit() len=lstrlen(smb_localNamep); memset(smb_sharename,' ',NCBNAMSZ); memcpy(smb_sharename,smb_localNamep,len); -#if 0 - /*ncbp->ncb_lana_num = smb_LANadapter;*/ - strcpy(ncbp->ncb_name, smb_localNamep); - len = strlen(smb_localNamep); - for(i=len; incb_name[i] = ' '; -#endif sprintf(s, "lana_list.length %d", lana_list.length); afsi_log(s); @@ -6719,9 +6701,9 @@ void smb_NetbiosInit() } void smb_Init(osi_log_t *logp, char *snamep, int useV3, int LANadapt, - int nThreads + int nThreads #ifndef DJGPP - , void *aMBfunc + , void *aMBfunc #endif ) @@ -6748,13 +6730,12 @@ void smb_Init(osi_log_t *logp, char *snamep, int useV3, int LANadapt, unsigned long tod = time((void *) 0); if (tod > EXPIREDATE) { #ifndef DJGPP - (*smb_MBfunc)(NULL, "AFS demo expiration", - "afsd", - MB_OK|MB_ICONSTOP|MB_SETFOREGROUND); + (*smb_MBfunc)(NULL, "AFS demo expiration", "afsd", + MB_OK|MB_ICONSTOP|MB_SETFOREGROUND); exit(1); #else /* DJGPP */ - fprintf(stderr, "AFS demo expiration\n"); - afs_exit(0); + fprintf(stderr, "AFS demo expiration\n"); + afs_exit(0); #endif /* !DJGPP */ } } @@ -6779,15 +6760,15 @@ void smb_Init(osi_log_t *logp, char *snamep, int useV3, int LANadapt, /* initialize the remote debugging log */ smb_logp = logp; - /* remember the name */ + /* remember the name */ len = 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_InitializeRWLock(&smb_globalLock, "smb global lock"); + lock_InitializeRWLock(&smb_rctLock, "smb refct and tree struct lock"); /* Raw I/O data structures */ lock_InitializeMutex(&smb_RawBufLock, "smb raw buffer lock"); @@ -6804,44 +6785,44 @@ void smb_Init(osi_log_t *logp, char *snamep, int useV3, int LANadapt, smb_RawBufs = rawBuf; } #else /* DJGPP */ + npar = 65536 >> 4; /* number of paragraphs */ + seg = __dpmi_allocate_dos_memory(npar, &smb_RawBufSel[0]); + if (seg == -1) { + afsi_log("Cannot allocate %d paragraphs of DOS memory", + npar); + osi_panic("",__FILE__,__LINE__); + } + else { + afsi_log("Allocated %d paragraphs of DOS mem at 0x%X", + npar, seg); + } + smb_RawBufs = (seg * 16) + 0; /* DOS physical address */ + + _farpokel(_dos_ds, smb_RawBufs, NULL); + for (i=0; i> 4; /* number of paragraphs */ - seg = __dpmi_allocate_dos_memory(npar, &smb_RawBufSel[0]); + seg = __dpmi_allocate_dos_memory(npar, &smb_RawBufSel[i+1]); if (seg == -1) { - afsi_log("Cannot allocate %d paragraphs of DOS memory", - npar); - osi_panic("",__FILE__,__LINE__); - } - else { - afsi_log("Allocated %d paragraphs of DOS mem at 0x%X", - npar, seg); - } - smb_RawBufs = (seg * 16) + 0; /* DOS physical address */ - - _farpokel(_dos_ds, smb_RawBufs, NULL); - for (i=0; i> 4; /* number of paragraphs */ - seg = __dpmi_allocate_dos_memory(npar, &smb_RawBufSel[i+1]); - if (seg == -1) { afsi_log("Cannot allocate %d paragraphs of DOS memory", - npar); + npar); osi_panic("",__FILE__,__LINE__); - } - else { + } + else { afsi_log("Allocated %d paragraphs of DOS mem at 0x%X", - npar, seg); - } - rawBuf = (seg * 16) + 0; /* DOS physical address */ - /*_farpokel(_dos_ds, smb_RawBufs, smb_RawBufs);*/ - _farpokel(_dos_ds, rawBuf, smb_RawBufs); - smb_RawBufs = rawBuf; + npar, seg); } + rawBuf = (seg * 16) + 0; /* DOS physical address */ + /*_farpokel(_dos_ds, smb_RawBufs, smb_RawBufs);*/ + _farpokel(_dos_ds, rawBuf, smb_RawBufs); + smb_RawBufs = rawBuf; + } #endif /* !DJGPP */ /* global free lists */ smb_ncbFreeListp = NULL; - smb_packetFreeListp = NULL; + smb_packetFreeListp = NULL; - smb_NetbiosInit(); + smb_NetbiosInit(); /* Initialize listener and server structures */ memset(dead_sessions, 0, sizeof(dead_sessions)); @@ -6905,25 +6886,25 @@ void smb_Init(osi_log_t *logp, char *snamep, int useV3, int LANadapt, smb_dispatchTable[0x2b].procp = smb_ReceiveCoreEcho; /* Set NORESPONSE because smb_ReceiveCoreEcho() does the responses itself */ smb_dispatchTable[0x2b].flags |= SMB_DISPATCHFLAG_NORESPONSE; - smb_dispatchTable[0x2d].procp = smb_ReceiveV3OpenX; - smb_dispatchTable[0x2d].flags |= SMB_DISPATCHFLAG_CHAINED; - smb_dispatchTable[0x2e].procp = smb_ReceiveV3ReadX; - smb_dispatchTable[0x2e].flags |= SMB_DISPATCHFLAG_CHAINED; + smb_dispatchTable[0x2d].procp = smb_ReceiveV3OpenX; + smb_dispatchTable[0x2d].flags |= SMB_DISPATCHFLAG_CHAINED; + smb_dispatchTable[0x2e].procp = smb_ReceiveV3ReadX; + smb_dispatchTable[0x2e].flags |= SMB_DISPATCHFLAG_CHAINED; smb_dispatchTable[0x32].procp = smb_ReceiveV3Tran2A; /* both are same */ - smb_dispatchTable[0x32].flags |= SMB_DISPATCHFLAG_NORESPONSE; - smb_dispatchTable[0x33].procp = smb_ReceiveV3Tran2A; - smb_dispatchTable[0x33].flags |= SMB_DISPATCHFLAG_NORESPONSE; - smb_dispatchTable[0x34].procp = smb_ReceiveV3FindClose; - smb_dispatchTable[0x35].procp = smb_ReceiveV3FindNotifyClose; + smb_dispatchTable[0x32].flags |= SMB_DISPATCHFLAG_NORESPONSE; + smb_dispatchTable[0x33].procp = smb_ReceiveV3Tran2A; + smb_dispatchTable[0x33].flags |= SMB_DISPATCHFLAG_NORESPONSE; + smb_dispatchTable[0x34].procp = smb_ReceiveV3FindClose; + smb_dispatchTable[0x35].procp = smb_ReceiveV3FindNotifyClose; smb_dispatchTable[0x70].procp = smb_ReceiveCoreTreeConnect; smb_dispatchTable[0x71].procp = smb_ReceiveCoreTreeDisconnect; smb_dispatchTable[0x72].procp = smb_ReceiveNegotiate; smb_dispatchTable[0x73].procp = smb_ReceiveV3SessionSetupX; - smb_dispatchTable[0x73].flags |= SMB_DISPATCHFLAG_CHAINED; - smb_dispatchTable[0x74].procp = smb_ReceiveV3UserLogoffX; - smb_dispatchTable[0x74].flags |= SMB_DISPATCHFLAG_CHAINED; - smb_dispatchTable[0x75].procp = smb_ReceiveV3TreeConnectX; - smb_dispatchTable[0x75].flags |= SMB_DISPATCHFLAG_CHAINED; + smb_dispatchTable[0x73].flags |= SMB_DISPATCHFLAG_CHAINED; + smb_dispatchTable[0x74].procp = smb_ReceiveV3UserLogoffX; + smb_dispatchTable[0x74].flags |= SMB_DISPATCHFLAG_CHAINED; + smb_dispatchTable[0x75].procp = smb_ReceiveV3TreeConnectX; + smb_dispatchTable[0x75].flags |= SMB_DISPATCHFLAG_CHAINED; smb_dispatchTable[0x80].procp = smb_ReceiveCoreGetDiskAttributes; smb_dispatchTable[0x81].procp = smb_ReceiveCoreSearchDir; smb_dispatchTable[0xA0].procp = smb_ReceiveNTTransact; @@ -6937,7 +6918,7 @@ void smb_Init(osi_log_t *logp, char *snamep, int useV3, int LANadapt, smb_dispatchTable[0xc3].procp = smb_SendCoreBadOp; for(i=0xd0; i<= 0xd7; i++) { smb_dispatchTable[i].procp = smb_SendCoreBadOp; - } + } /* setup tran 2 dispatch table */ smb_tran2DispatchTable[0].procp = smb_ReceiveTran2Open; @@ -6968,33 +6949,31 @@ void smb_Init(osi_log_t *logp, char *snamep, int useV3, int LANadapt, } #ifndef DJGPP - phandle = thrd_Create(NULL, 65536, (ThreadFunc) smb_ClientWaiter, - NULL, 0, &lpid, "smb_ClientWaiter"); + phandle = thrd_Create(NULL, 65536, (ThreadFunc) smb_ClientWaiter, + NULL, 0, &lpid, "smb_ClientWaiter"); osi_assert(phandle != NULL); thrd_CloseHandle(phandle); #endif /* !DJGPP */ - phandle = thrd_Create(NULL, 65536, (ThreadFunc) smb_ServerWaiter, - NULL, 0, &lpid, "smb_ServerWaiter"); + phandle = thrd_Create(NULL, 65536, (ThreadFunc) smb_ServerWaiter, + NULL, 0, &lpid, "smb_ServerWaiter"); osi_assert(phandle != NULL); thrd_CloseHandle(phandle); for (i=0; idos_ncb; + /* setup the NCB system */ + ncbp = GetNCB(); + dos_ncb = ((smb_ncb_t *)ncbp)->dos_ncb; - /* Block new sessions by setting shutdown flag */ - /*smbShutdownFlag = 1;*/ + /* Block new sessions by setting shutdown flag */ + /*smbShutdownFlag = 1;*/ - /* Hang up all sessions */ - for (i = 1; i < numSessions; i++) - { - if (dead_sessions[i]) + /* Hang up all sessions */ + for (i = 1; i < numSessions; i++) + { + if (dead_sessions[i]) continue; - /*fprintf(stderr, "NCBHANGUP session %d LSN %d\n", i, LSNs[i]);*/ - ncbp->ncb_command = NCBHANGUP; - ncbp->ncb_lana_num = lanas[i]; /*smb_LANadapter;*/ - ncbp->ncb_lsn = LSNs[i]; - code = Netbios(ncbp, dos_ncb); - /*fprintf(stderr, "returned from NCBHANGUP session %d LSN %d\n", i, LS - Ns[i]);*/ - if (code == 0) code = ncbp->ncb_retcode; - if (code != 0) { + /*fprintf(stderr, "NCBHANGUP session %d LSN %d\n", i, LSNs[i]);*/ + ncbp->ncb_command = NCBHANGUP; + ncbp->ncb_lana_num = lanas[i]; /*smb_LANadapter;*/ + ncbp->ncb_lsn = LSNs[i]; + code = Netbios(ncbp, dos_ncb); + /*fprintf(stderr, "returned from NCBHANGUP session %d LSN %d\n", i, LSNs[i]);*/ + if (code == 0) code = ncbp->ncb_retcode; + if (code != 0) { fprintf(stderr, "Session %d Netbios NCBHANGUP error code %d", i, code); - } + } } #if 1 - /* Delete Netbios name */ + /* Delete Netbios name */ for (i = 0; i < lana_list.length; i++) { if (lana_list.lana[i] == 255) continue; ncbp->ncb_command = NCBDELNAME; @@ -7063,19 +7041,19 @@ void smb_Shutdown(void) /* Get the UNC \\\ prefix. */ char *smb_GetSharename() { - char *name; + char *name; /* Make sure we have been properly initialized. */ if (smb_localNamep == NULL) return NULL; - /* Allocate space for \\\, plus the - * terminator. - */ - name = malloc(strlen(smb_localNamep) + strlen("ALL") + 4); - sprintf(name, "\\\\%s\\%s", smb_localNamep, "ALL"); - return name; -} + /* Allocate space for \\\, plus the + * terminator. + */ + name = malloc(strlen(smb_localNamep) + strlen("ALL") + 4); + sprintf(name, "\\\\%s\\%s", smb_localNamep, "ALL"); + return name; +} #ifdef NOTSERVICE @@ -7175,5 +7153,3 @@ int smb_DumpVCP(FILE *outputFile, char *cookie) lock_ReleaseRead(&smb_rctLock); return 0; } - - diff --git a/src/WINNT/afsd/smb3.c b/src/WINNT/afsd/smb3.c index 6dce16727..875977182 100644 --- a/src/WINNT/afsd/smb3.c +++ b/src/WINNT/afsd/smb3.c @@ -40,21 +40,21 @@ smb_tran2Packet_t *smb_tran2AssemblyQueuep; cm_user_t *smb_GetTran2User(smb_vc_t *vcp, smb_tran2Packet_t *inp) { smb_user_t *uidp; - cm_user_t *up = NULL; + cm_user_t *up = NULL; - uidp = smb_FindUID(vcp, inp->uid, 0); - if (!uidp) return NULL; + uidp = smb_FindUID(vcp, inp->uid, 0); + if (!uidp) return NULL; lock_ObtainMutex(&uidp->mx); - if (uidp->unp) { - up = uidp->unp->userp; - cm_HoldUser(up); - } + if (uidp->unp) { + up = uidp->unp->userp; + cm_HoldUser(up); + } lock_ReleaseMutex(&uidp->mx); - smb_ReleaseUID(uidp); - - return up; + smb_ReleaseUID(uidp); + + return up; } /* @@ -89,21 +89,22 @@ unsigned long smb_ExtAttributes(cm_scache_t *scp) int smb_V3IsStarMask(char *maskp) { - char tc; + char tc; while (tc = *maskp++) - if (tc == '?' || tc == '*') return 1; + if (tc == '?' || tc == '*') + return 1; return 0; } unsigned char *smb_ParseString(unsigned char *inp, char **chainpp) { - if (chainpp) { + if (chainpp) { /* skip over null-terminated string */ *chainpp = inp + strlen(inp) + 1; - } - return inp; -} + } + return inp; +} long smb_ReceiveV3SessionSetupX(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp) { @@ -160,7 +161,7 @@ long smb_ReceiveV3SessionSetupX(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t * /* Create a new UID and cm_user_t structure */ userp = unp->userp; if (!userp) - userp = cm_NewUser(); + userp = cm_NewUser(); lock_ObtainMutex(&vcp->mx); if (!vcp->uidCounter) vcp->uidCounter++; /* handle unlikely wraparounds */ @@ -212,9 +213,9 @@ long smb_ReceiveV3UserLogoffX(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *ou if (s1 == NULL) {s1 = s2; s2 = " ";} osi_Log4(afsd_logp, "SMB3 user logoffX uid %d name %s%s%s", - uidp->userID, - osi_LogSaveString(afsd_logp, - (uidp->unp) ? uidp->unp->name: " "), s1, s2); + uidp->userID, + osi_LogSaveString(afsd_logp, + (uidp->unp) ? uidp->unp->name: " "), s1, s2); lock_ObtainMutex(&uidp->mx); uidp->flags |= SMB_USERFLAG_DELETE; @@ -222,49 +223,49 @@ long smb_ReceiveV3UserLogoffX(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *ou * it doesn't get deleted right away * because the vcp points to it */ - lock_ReleaseMutex(&uidp->mx); - } - else + lock_ReleaseMutex(&uidp->mx); + } + else osi_Log0(afsd_logp, "SMB3 user logoffX"); - smb_SetSMBDataLength(outp, 0); - return 0; + smb_SetSMBDataLength(outp, 0); + return 0; } long smb_ReceiveV3TreeConnectX(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp) { - smb_tid_t *tidp; - unsigned short newTid; - char shareName[256]; + smb_tid_t *tidp; + unsigned short newTid; + char shareName[256]; char *sharePath; int shareFound; - char *tp; - char *pathp; - char *passwordp; + char *tp; + char *pathp; + char *passwordp; char *servicep; - cm_user_t *userp; + cm_user_t *userp; osi_Log0(afsd_logp, "SMB3 receive tree connect"); /* parse input parameters */ tp = smb_GetSMBData(inp, NULL); - passwordp = smb_ParseString(tp, &tp); + passwordp = smb_ParseString(tp, &tp); pathp = smb_ParseString(tp, &tp); servicep = smb_ParseString(tp, &tp); tp = strrchr(pathp, '\\'); - if (!tp) { - return CM_ERROR_BADSMB; - } - strcpy(shareName, tp+1); + if (!tp) { + return CM_ERROR_BADSMB; + } + strcpy(shareName, tp+1); if (strcmp(servicep, "IPC") == 0 || strcmp(shareName, "IPC$") == 0) return CM_ERROR_NOIPC; - userp = smb_GetUser(vcp, inp); + userp = smb_GetUser(vcp, inp); lock_ObtainMutex(&vcp->mx); - newTid = vcp->tidCounter++; + newTid = vcp->tidCounter++; lock_ReleaseMutex(&vcp->mx); tidp = smb_FindTID(vcp, newTid, SMB_FLAG_CREATE); @@ -273,11 +274,11 @@ long smb_ReceiveV3TreeConnectX(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *o smb_ReleaseTID(tidp); return CM_ERROR_BADSHARENAME; } - lock_ObtainMutex(&tidp->mx); - tidp->userp = userp; + lock_ObtainMutex(&tidp->mx); + tidp->userp = userp; tidp->pathname = sharePath; - lock_ReleaseMutex(&tidp->mx); - smb_ReleaseTID(tidp); + lock_ReleaseMutex(&tidp->mx); + smb_ReleaseTID(tidp); if (vcp->flags & SMB_VCFLAG_USENT) smb_SetSMBParm(outp, 2, 0); /* OptionalSupport bits */ @@ -285,27 +286,27 @@ long smb_ReceiveV3TreeConnectX(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *o ((smb_t *)outp)->tid = newTid; ((smb_t *)inp)->tid = newTid; tp = smb_GetSMBData(outp, NULL); - *tp++ = 'A'; - *tp++ = ':'; - *tp++ = 0; - smb_SetSMBDataLength(outp, 3); - - osi_Log1(afsd_logp, "SMB3 tree connect created ID %d", newTid); - return 0; + *tp++ = 'A'; + *tp++ = ':'; + *tp++ = 0; + smb_SetSMBDataLength(outp, 3); + + osi_Log1(afsd_logp, "SMB3 tree connect created ID %d", newTid); + return 0; } /* must be called with global tran lock held */ smb_tran2Packet_t *smb_FindTran2Packet(smb_vc_t *vcp, smb_packet_t *inp) { smb_tran2Packet_t *tp; - smb_t *smbp; + smb_t *smbp; - smbp = (smb_t *) inp->data; + smbp = (smb_t *) inp->data; for(tp = smb_tran2AssemblyQueuep; tp; tp = (smb_tran2Packet_t *) osi_QNext(&tp->q)) { if (tp->vcp == vcp && tp->mid == smbp->mid && tp->tid == smbp->tid) - return tp; - } - return NULL; + return tp; + } + return NULL; } smb_tran2Packet_t *smb_NewTran2Packet(smb_vc_t *vcp, smb_packet_t *inp, @@ -347,18 +348,18 @@ smb_tran2Packet_t *smb_GetTran2ResponsePacket(smb_vc_t *vcp, unsigned short dataAlign; tp = malloc(sizeof(*tp)); - memset(tp, 0, sizeof(*tp)); - tp->vcp = NULL; - tp->curData = tp->curParms = 0; - tp->totalData = totalData; - tp->totalParms = totalParms; + memset(tp, 0, sizeof(*tp)); + tp->vcp = NULL; + tp->curData = tp->curParms = 0; + tp->totalData = totalData; + tp->totalParms = totalParms; tp->oldTotalParms = totalParms; - tp->tid = inp->tid; - tp->mid = inp->mid; - tp->uid = inp->uid; - tp->pid = inp->pid; + tp->tid = inp->tid; + tp->mid = inp->mid; + tp->uid = inp->uid; + tp->pid = inp->pid; tp->res[0] = inp->res[0]; - tp->opcode = inp->opcode; + tp->opcode = inp->opcode; /* * We calculate where the parameters and data will start. @@ -375,7 +376,7 @@ smb_tran2Packet_t *smb_GetTran2ResponsePacket(smb_vc_t *vcp, dataOffset += dataAlign; tp->datap = outp->data + dataOffset; - return tp; + return tp; } /* free a tran2 packet; must be called with smb_globalLock held */ @@ -397,29 +398,29 @@ void smb_FreeTran2Packet(smb_tran2Packet_t *t2p) void smb_SendTran2Error(smb_vc_t *vcp, smb_tran2Packet_t *t2p, smb_packet_t *tp, long code) { - smb_t *smbp; - unsigned short errCode; - unsigned char errClass; + smb_t *smbp; + unsigned short errCode; + unsigned char errClass; unsigned long NTStatus; - if (vcp->flags & SMB_VCFLAG_STATUS32) + if (vcp->flags & SMB_VCFLAG_STATUS32) smb_MapNTError(code, &NTStatus); else smb_MapCoreError(code, vcp, &errCode, &errClass); - smb_FormatResponsePacket(vcp, NULL, tp); - smbp = (smb_t *) tp; - + smb_FormatResponsePacket(vcp, NULL, tp); + smbp = (smb_t *) tp; + /* We can handle long names */ if (vcp->flags & SMB_VCFLAG_USENT) smbp->flg2 |= 0x40; /* IS_LONG_NAME */ - /* now copy important fields from the tran 2 packet */ - smbp->com = 0x32; /* tran 2 response */ - smbp->tid = t2p->tid; - smbp->mid = t2p->mid; - smbp->pid = t2p->pid; - smbp->uid = t2p->uid; + /* now copy important fields from the tran 2 packet */ + smbp->com = 0x32; /* tran 2 response */ + smbp->tid = t2p->tid; + smbp->mid = t2p->mid; + smbp->pid = t2p->pid; + smbp->uid = t2p->uid; smbp->res[0] = t2p->res[0]; if (vcp->flags & SMB_VCFLAG_STATUS32) { smbp->rcls = (unsigned char) (NTStatus & 0xff); @@ -429,83 +430,83 @@ void smb_SendTran2Error(smb_vc_t *vcp, smb_tran2Packet_t *t2p, smbp->flg2 |= 0x4000; } else { - smbp->rcls = errClass; + smbp->rcls = errClass; smbp->errLow = (unsigned char) (errCode & 0xff); smbp->errHigh = (unsigned char) ((errCode >> 8) & 0xff); } - /* send packet */ - smb_SendPacket(vcp, tp); + /* send packet */ + smb_SendPacket(vcp, tp); } void smb_SendTran2Packet(smb_vc_t *vcp, smb_tran2Packet_t *t2p, smb_packet_t *tp) { - smb_t *smbp; - unsigned short parmOffset; + smb_t *smbp; + unsigned short parmOffset; unsigned short dataOffset; unsigned short totalLength; unsigned short dataAlign; - char *datap; + char *datap; - smb_FormatResponsePacket(vcp, NULL, tp); - smbp = (smb_t *) tp; + smb_FormatResponsePacket(vcp, NULL, tp); + smbp = (smb_t *) tp; /* We can handle long names */ if (vcp->flags & SMB_VCFLAG_USENT) smbp->flg2 |= 0x40; /* IS_LONG_NAME */ - - /* now copy important fields from the tran 2 packet */ - smbp->com = 0x32; /* tran 2 response */ - smbp->tid = t2p->tid; - smbp->mid = t2p->mid; - smbp->pid = t2p->pid; - smbp->uid = t2p->uid; + + /* now copy important fields from the tran 2 packet */ + smbp->com = 0x32; /* tran 2 response */ + smbp->tid = t2p->tid; + smbp->mid = t2p->mid; + smbp->pid = t2p->pid; + smbp->uid = t2p->uid; smbp->res[0] = t2p->res[0]; - totalLength = 1 + t2p->totalData + t2p->totalParms; + totalLength = 1 + t2p->totalData + t2p->totalParms; - /* now add the core parameters (tran2 info) to the packet */ - smb_SetSMBParm(tp, 0, t2p->totalParms); /* parm bytes */ - smb_SetSMBParm(tp, 1, t2p->totalData); /* data bytes */ - smb_SetSMBParm(tp, 2, 0); /* reserved */ - smb_SetSMBParm(tp, 3, t2p->totalParms); /* parm bytes in this packet */ + /* now add the core parameters (tran2 info) to the packet */ + smb_SetSMBParm(tp, 0, t2p->totalParms); /* parm bytes */ + smb_SetSMBParm(tp, 1, t2p->totalData); /* data bytes */ + smb_SetSMBParm(tp, 2, 0); /* reserved */ + smb_SetSMBParm(tp, 3, t2p->totalParms); /* parm bytes in this packet */ parmOffset = 10*2 + 35; /* parm offset in packet */ parmOffset++; /* round to even */ - smb_SetSMBParm(tp, 4, parmOffset); /* 11 parm words plus * - * hdr, bcc and wct */ - smb_SetSMBParm(tp, 5, 0); /* parm displacement */ - smb_SetSMBParm(tp, 6, t2p->totalData); /* data in this packet */ + smb_SetSMBParm(tp, 4, parmOffset); /* 11 parm words plus * + * hdr, bcc and wct */ + smb_SetSMBParm(tp, 5, 0); /* parm displacement */ + smb_SetSMBParm(tp, 6, t2p->totalData); /* data in this packet */ dataOffset = parmOffset + t2p->oldTotalParms; dataAlign = dataOffset & 2; /* quad-align */ dataOffset += dataAlign; - smb_SetSMBParm(tp, 7, dataOffset); /* offset of data */ - smb_SetSMBParm(tp, 8, 0); /* data displacement */ - smb_SetSMBParm(tp, 9, 0); /* low: setup word count * - * high: resvd */ - - datap = smb_GetSMBData(tp, NULL); + smb_SetSMBParm(tp, 7, dataOffset); /* offset of data */ + smb_SetSMBParm(tp, 8, 0); /* data displacement */ + smb_SetSMBParm(tp, 9, 0); /* low: setup word count * + * high: resvd */ + + datap = smb_GetSMBData(tp, NULL); *datap++ = 0; /* we rounded to even */ totalLength += dataAlign; - smb_SetSMBDataLength(tp, totalLength); + smb_SetSMBDataLength(tp, totalLength); - /* next, send the datagram */ - smb_SendPacket(vcp, tp); -} + /* next, send the datagram */ + smb_SendPacket(vcp, tp); +} long smb_ReceiveV3Tran2A(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp) { - smb_tran2Packet_t *asp; - int totalParms; - int totalData; - int parmDisp; - int dataDisp; - int parmOffset; - int dataOffset; - int parmCount; - int dataCount; - int firstPacket; - long code; + smb_tran2Packet_t *asp; + int totalParms; + int totalData; + int parmDisp; + int dataDisp; + int parmOffset; + int dataOffset; + int parmCount; + int dataCount; + int firstPacket; + long code; /* We sometimes see 0 word count. What to do? */ if (*inp->wctp == 0) { @@ -524,48 +525,48 @@ long smb_ReceiveV3Tran2A(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp) osi_Log0(afsd_logp, "TRANSACTION2 word count = 0"); #endif /* !DJGPP */ - smb_SetSMBDataLength(outp, 0); - smb_SendPacket(vcp, outp); + smb_SetSMBDataLength(outp, 0); + smb_SendPacket(vcp, outp); return 0; } - totalParms = smb_GetSMBParm(inp, 0); - totalData = smb_GetSMBParm(inp, 1); + totalParms = smb_GetSMBParm(inp, 0); + totalData = smb_GetSMBParm(inp, 1); - firstPacket = (inp->inCom == 0x32); + firstPacket = (inp->inCom == 0x32); /* find the packet we're reassembling */ lock_ObtainWrite(&smb_globalLock); - asp = smb_FindTran2Packet(vcp, inp); - if (!asp) { - asp = smb_NewTran2Packet(vcp, inp, totalParms, totalData); + asp = smb_FindTran2Packet(vcp, inp); + if (!asp) { + asp = smb_NewTran2Packet(vcp, inp, totalParms, totalData); } - lock_ReleaseWrite(&smb_globalLock); + lock_ReleaseWrite(&smb_globalLock); - /* now merge in this latest packet; start by looking up offsets */ + /* now merge in this latest packet; start by looking up offsets */ if (firstPacket) { parmDisp = dataDisp = 0; - parmOffset = smb_GetSMBParm(inp, 10); - dataOffset = smb_GetSMBParm(inp, 12); - parmCount = smb_GetSMBParm(inp, 9); - dataCount = smb_GetSMBParm(inp, 11); + parmOffset = smb_GetSMBParm(inp, 10); + dataOffset = smb_GetSMBParm(inp, 12); + parmCount = smb_GetSMBParm(inp, 9); + dataCount = smb_GetSMBParm(inp, 11); asp->maxReturnParms = smb_GetSMBParm(inp, 2); - asp->maxReturnData = smb_GetSMBParm(inp, 3); + asp->maxReturnData = smb_GetSMBParm(inp, 3); osi_Log3(afsd_logp, "SMB3 received T2 init packet total data %d, cur data %d, max return data %d", - totalData, dataCount, asp->maxReturnData); - } - else { - parmDisp = smb_GetSMBParm(inp, 4); - parmOffset = smb_GetSMBParm(inp, 3); - dataDisp = smb_GetSMBParm(inp, 7); - dataOffset = smb_GetSMBParm(inp, 6); - parmCount = smb_GetSMBParm(inp, 2); - dataCount = smb_GetSMBParm(inp, 5); - - osi_Log2(afsd_logp, "SMB3 received T2 aux packet parms %d, data %d", - parmCount, dataCount); - } + totalData, dataCount, asp->maxReturnData); + } + else { + parmDisp = smb_GetSMBParm(inp, 4); + parmOffset = smb_GetSMBParm(inp, 3); + dataDisp = smb_GetSMBParm(inp, 7); + dataOffset = smb_GetSMBParm(inp, 6); + parmCount = smb_GetSMBParm(inp, 2); + dataCount = smb_GetSMBParm(inp, 5); + + osi_Log2(afsd_logp, "SMB3 received T2 aux packet parms %d, data %d", + parmCount, dataCount); + } /* now copy the parms and data */ if ( parmCount != 0 ) @@ -576,50 +577,50 @@ long smb_ReceiveV3Tran2A(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp) memcpy(asp->datap + dataDisp, inp->data + dataOffset, dataCount); } - /* account for new bytes */ - asp->curData += dataCount; - asp->curParms += parmCount; - - /* finally, if we're done, remove the packet from the queue and dispatch it */ - if (asp->totalData <= asp->curData && asp->totalParms <= asp->curParms) { + /* account for new bytes */ + asp->curData += dataCount; + asp->curParms += parmCount; + + /* finally, if we're done, remove the packet from the queue and dispatch it */ + if (asp->totalData <= asp->curData && asp->totalParms <= asp->curParms) { /* we've received it all */ - lock_ObtainWrite(&smb_globalLock); + lock_ObtainWrite(&smb_globalLock); osi_QRemove((osi_queue_t **) &smb_tran2AssemblyQueuep, &asp->q); - lock_ReleaseWrite(&smb_globalLock); - - /* now dispatch it */ - if ( asp->opcode >= 0 && asp->opcode < 20 && smb_tran2DispatchTable[asp->opcode].procp) { - osi_LogEvent("AFS-Dispatch-2[%s]",myCrt_2Dispatch(asp->opcode),"vcp[%x] lana[%d] lsn[%d]",(int)vcp,vcp->lana,vcp->lsn); - osi_Log4(afsd_logp,"AFS Server - Dispatch-2 %s vcp[%x] lana[%d] lsn[%d]",myCrt_2Dispatch(asp->opcode),vcp,vcp->lana,vcp->lsn); - code = (*smb_tran2DispatchTable[asp->opcode].procp)(vcp, asp, outp); - } - else { - osi_LogEvent("AFS-Dispatch-2 [invalid]", NULL, "op[%x] vcp[%x] lana[%d] lsn[%d]", asp->opcode, vcp, vcp->lana, vcp->lsn); - osi_Log4(afsd_logp,"AFS Server - Dispatch-2 [INVALID] op[%x] vcp[%x] lana[%d] lsn[%d]", asp->opcode, vcp, vcp->lana, vcp->lsn); - code = CM_ERROR_BADOP; - } + lock_ReleaseWrite(&smb_globalLock); + + /* now dispatch it */ + if ( asp->opcode >= 0 && asp->opcode < 20 && smb_tran2DispatchTable[asp->opcode].procp) { + osi_LogEvent("AFS-Dispatch-2[%s]",myCrt_2Dispatch(asp->opcode),"vcp[%x] lana[%d] lsn[%d]",(int)vcp,vcp->lana,vcp->lsn); + osi_Log4(afsd_logp,"AFS Server - Dispatch-2 %s vcp[%x] lana[%d] lsn[%d]",myCrt_2Dispatch(asp->opcode),vcp,vcp->lana,vcp->lsn); + code = (*smb_tran2DispatchTable[asp->opcode].procp)(vcp, asp, outp); + } + else { + osi_LogEvent("AFS-Dispatch-2 [invalid]", NULL, "op[%x] vcp[%x] lana[%d] lsn[%d]", asp->opcode, vcp, vcp->lana, vcp->lsn); + osi_Log4(afsd_logp,"AFS Server - Dispatch-2 [INVALID] op[%x] vcp[%x] lana[%d] lsn[%d]", asp->opcode, vcp, vcp->lana, vcp->lsn); + code = CM_ERROR_BADOP; + } /* if an error is returned, we're supposed to send an error packet, - * otherwise the dispatched function already did the data sending. - * We give dispatched proc the responsibility since it knows how much - * space to allocate. - */ - if (code != 0) { - smb_SendTran2Error(vcp, asp, outp, code); - } + * otherwise the dispatched function already did the data sending. + * We give dispatched proc the responsibility since it knows how much + * space to allocate. + */ + if (code != 0) { + smb_SendTran2Error(vcp, asp, outp, code); + } /* free the input tran 2 packet */ lock_ObtainWrite(&smb_globalLock); - smb_FreeTran2Packet(asp); + smb_FreeTran2Packet(asp); lock_ReleaseWrite(&smb_globalLock); - } - else if (firstPacket) { + } + else if (firstPacket) { /* the first packet in a multi-packet request, we need to send an - * ack to get more data. - */ - smb_SetSMBDataLength(outp, 0); - smb_SendPacket(vcp, outp); - } + * ack to get more data. + */ + smb_SetSMBDataLength(outp, 0); + smb_SendPacket(vcp, outp); + } return 0; } @@ -923,18 +924,18 @@ long smb_ReceiveTran2Open(smb_vc_t *vcp, smb_tran2Packet_t *p, smb_packet_t *op) long smb_ReceiveTran2FindFirst(smb_vc_t *vcp, smb_tran2Packet_t *p, smb_packet_t *outp) { - return CM_ERROR_BADOP; + return CM_ERROR_BADOP; } long smb_ReceiveTran2FindNext(smb_vc_t *vcp, smb_tran2Packet_t *p, smb_packet_t *outp) { - return CM_ERROR_BADOP; + return CM_ERROR_BADOP; } long smb_ReceiveTran2QFSInfo(smb_vc_t *vcp, smb_tran2Packet_t *p, smb_packet_t *op) { smb_tran2Packet_t *outp; - smb_tran2QFSInfo_t qi; + smb_tran2QFSInfo_t qi; int responseSize; osi_hyper_t temp; static char FSname[6] = {'A', 0, 'F', 0, 'S', 0}; @@ -951,18 +952,18 @@ long smb_ReceiveTran2QFSInfo(smb_vc_t *vcp, smb_tran2Packet_t *p, smb_packet_t * default: return CM_ERROR_INVAL; } - outp = smb_GetTran2ResponsePacket(vcp, p, op, 0, responseSize); + outp = smb_GetTran2ResponsePacket(vcp, p, op, 0, responseSize); switch (p->parmsp[0]) { case 1: /* alloc info */ - qi.u.allocInfo.FSID = 0; - qi.u.allocInfo.sectorsPerAllocUnit = 1; - qi.u.allocInfo.totalAllocUnits = 0x7fffffff; - qi.u.allocInfo.availAllocUnits = 0x3fffffff; - qi.u.allocInfo.bytesPerSector = 1024; + qi.u.allocInfo.FSID = 0; + qi.u.allocInfo.sectorsPerAllocUnit = 1; + qi.u.allocInfo.totalAllocUnits = 0x7fffffff; + qi.u.allocInfo.availAllocUnits = 0x3fffffff; + qi.u.allocInfo.bytesPerSector = 1024; break; - case 2: + case 2: /* volume info */ qi.u.volumeInfo.vsn = 1234; qi.u.volumeInfo.vnCount = 4; @@ -1011,23 +1012,23 @@ long smb_ReceiveTran2QFSInfo(smb_vc_t *vcp, smb_tran2Packet_t *p, smb_packet_t * qi.u.FSattributeInfo.FSnameLength = 6; memcpy(qi.u.FSattributeInfo.FSname, FSname, 6); break; - } + } /* copy out return data, and set corresponding sizes */ outp->totalParms = 0; - outp->totalData = responseSize; - memcpy(outp->datap, &qi, responseSize); + outp->totalData = responseSize; + memcpy(outp->datap, &qi, responseSize); /* send and free the packets */ smb_SendTran2Packet(vcp, outp, op); - smb_FreeTran2Packet(outp); + smb_FreeTran2Packet(outp); - return 0; + return 0; } long smb_ReceiveTran2SetFSInfo(smb_vc_t *vcp, smb_tran2Packet_t *p, smb_packet_t *outp) { - return CM_ERROR_BADOP; + return CM_ERROR_BADOP; } struct smb_ShortNameRock { @@ -1072,7 +1073,7 @@ long cm_GetShortName(char *pathp, cm_user_t *userp, cm_req_t *reqp, smb_StripLastComponent(spacep->data, &lastNamep, pathp); code = cm_NameI(cm_rootSCachep, spacep->data, caseFold, userp, tidPathp, - reqp, &dscp); + reqp, &dscp); cm_FreeSpace(spacep); if (code) return code; @@ -1084,7 +1085,7 @@ long cm_GetShortName(char *pathp, cm_user_t *userp, cm_req_t *reqp, rock.vnode = vnode; rock.maskp = lastNamep; code = cm_ApplyDir(dscp, cm_GetShortNameProc, &rock, &thyper, userp, - reqp, NULL); + reqp, NULL); cm_ReleaseSCache(dscp); @@ -1100,19 +1101,19 @@ long cm_GetShortName(char *pathp, cm_user_t *userp, cm_req_t *reqp, long smb_ReceiveTran2QPathInfo(smb_vc_t *vcp, smb_tran2Packet_t *p, smb_packet_t *opx) { smb_tran2Packet_t *outp; - unsigned long dosTime; + unsigned long dosTime; FILETIME ft; - unsigned short infoLevel; - int nbytesRequired; - unsigned short attributes; + unsigned short infoLevel; + int nbytesRequired; + unsigned short attributes; unsigned long extAttributes; char shortName[13]; unsigned int len; - cm_user_t *userp; + cm_user_t *userp; cm_space_t *spacep; - cm_scache_t *scp, *dscp; - long code; - char *op; + cm_scache_t *scp, *dscp; + long code; + char *op; char *tidPathp; char *lastComp; cm_req_t req; @@ -1120,23 +1121,23 @@ long smb_ReceiveTran2QPathInfo(smb_vc_t *vcp, smb_tran2Packet_t *p, smb_packet_t cm_InitReq(&req); infoLevel = p->parmsp[0]; - if (infoLevel == 6) nbytesRequired = 0; - else if (infoLevel == 1) nbytesRequired = 22; - else if (infoLevel == 2) nbytesRequired = 26; + if (infoLevel == 6) nbytesRequired = 0; + else if (infoLevel == 1) nbytesRequired = 22; + else if (infoLevel == 2) nbytesRequired = 26; else if (infoLevel == 0x101) nbytesRequired = 40; else if (infoLevel == 0x102) nbytesRequired = 24; else if (infoLevel == 0x103) nbytesRequired = 4; else if (infoLevel == 0x108) nbytesRequired = 30; - else { + else { osi_Log2(afsd_logp, "Bad Tran2 op 0x%x infolevel 0x%x", - p->opcode, infoLevel); + p->opcode, infoLevel); smb_SendTran2Error(vcp, p, opx, CM_ERROR_INVAL); - return 0; - } + return 0; + } osi_Log2(afsd_logp, "T2 QPathInfo type 0x%x path %s", infoLevel, - osi_LogSaveString(afsd_logp, (char *)(&p->parmsp[3]))); + osi_LogSaveString(afsd_logp, (char *)(&p->parmsp[3]))); - outp = smb_GetTran2ResponsePacket(vcp, p, opx, 2, nbytesRequired); + outp = smb_GetTran2ResponsePacket(vcp, p, opx, 2, nbytesRequired); if (infoLevel > 0x100) outp->totalParms = 2; @@ -1144,22 +1145,22 @@ long smb_ReceiveTran2QPathInfo(smb_vc_t *vcp, smb_tran2Packet_t *p, smb_packet_t outp->totalParms = 0; outp->totalData = nbytesRequired; - /* now, if we're at infoLevel 6, we're only being asked to check - * the syntax, so we just OK things now. In particular, we're *not* - * being asked to verify anything about the state of any parent dirs. - */ + /* now, if we're at infoLevel 6, we're only being asked to check + * the syntax, so we just OK things now. In particular, we're *not* + * being asked to verify anything about the state of any parent dirs. + */ if (infoLevel == 6) { smb_SendTran2Packet(vcp, outp, opx); - smb_FreeTran2Packet(outp); + smb_FreeTran2Packet(outp); return 0; - } + } - userp = smb_GetTran2User(vcp, p); - if(!userp) { - osi_Log1(afsd_logp, "ReceiveTran2QPathInfo unable to resolve user [%d]", p->uid); - smb_FreeTran2Packet(outp); - return CM_ERROR_BADSMB; - } + userp = smb_GetTran2User(vcp, p); + if(!userp) { + osi_Log1(afsd_logp, "ReceiveTran2QPathInfo unable to resolve user [%d]", p->uid); + smb_FreeTran2Packet(outp); + return CM_ERROR_BADSMB; + } tidPathp = smb_GetTIDPath(vcp, p->tid); @@ -1215,30 +1216,30 @@ long smb_ReceiveTran2QPathInfo(smb_vc_t *vcp, smb_tran2Packet_t *p, smb_packet_t } /* now do namei and stat, and copy out the info */ - code = cm_NameI(cm_rootSCachep, (char *)(&p->parmsp[3]), - CM_FLAG_FOLLOW | CM_FLAG_CASEFOLD, userp, tidPathp, &req, &scp); + code = cm_NameI(cm_rootSCachep, (char *)(&p->parmsp[3]), + CM_FLAG_FOLLOW | CM_FLAG_CASEFOLD, userp, tidPathp, &req, &scp); if (code) { cm_ReleaseUser(userp); - smb_SendTran2Error(vcp, p, opx, code); - smb_FreeTran2Packet(outp); - return 0; - } + smb_SendTran2Error(vcp, p, opx, code); + smb_FreeTran2Packet(outp); + return 0; + } - lock_ObtainMutex(&scp->mx); + lock_ObtainMutex(&scp->mx); code = cm_SyncOp(scp, NULL, userp, &req, 0, - CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS); + CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS); if (code) goto done; - /* now we have the status in the cache entry, and everything is locked. + /* now we have the status in the cache entry, and everything is locked. * Marshall the output data. - */ + */ op = outp->datap; /* for info level 108, figure out short name */ if (infoLevel == 0x108) { code = cm_GetShortName((char *)(&p->parmsp[3]), userp, &req, - tidPathp, scp->fid.vnode, shortName, - (size_t *) &len); + tidPathp, scp->fid.vnode, shortName, + (size_t *) &len); if (code) { goto done; } @@ -1252,11 +1253,11 @@ long smb_ReceiveTran2QPathInfo(smb_vc_t *vcp, smb_tran2Packet_t *p, smb_packet_t } if (infoLevel == 1 || infoLevel == 2) { smb_SearchTimeFromUnixTime(&dosTime, scp->clientModTime); - *((u_long *)op) = dosTime; op += 4; /* creation time */ - *((u_long *)op) = dosTime; op += 4; /* access time */ - *((u_long *)op) = dosTime; op += 4; /* write time */ - *((u_long *)op) = scp->length.LowPart; op += 4; /* length */ - *((u_long *)op) = scp->length.LowPart; op += 4; /* alloc size */ + *((u_long *)op) = dosTime; op += 4; /* creation time */ + *((u_long *)op) = dosTime; op += 4; /* access time */ + *((u_long *)op) = dosTime; op += 4; /* write time */ + *((u_long *)op) = scp->length.LowPart; op += 4; /* length */ + *((u_long *)op) = scp->length.LowPart; op += 4; /* alloc size */ attributes = smb_Attributes(scp); *((u_short *)op) = attributes; op += 2; /* attributes */ } @@ -1290,20 +1291,22 @@ long smb_ReceiveTran2QPathInfo(smb_vc_t *vcp, smb_tran2Packet_t *p, smb_packet_t /* send and free the packets */ -done: + done: lock_ReleaseMutex(&scp->mx); - cm_ReleaseSCache(scp); - cm_ReleaseUser(userp); - if (code == 0) smb_SendTran2Packet(vcp, outp, opx); - else smb_SendTran2Error(vcp, p, opx, code); - smb_FreeTran2Packet(outp); + cm_ReleaseSCache(scp); + cm_ReleaseUser(userp); + if (code == 0) + smb_SendTran2Packet(vcp, outp, opx); + else + smb_SendTran2Error(vcp, p, opx, code); + smb_FreeTran2Packet(outp); - return 0; + return 0; } long smb_ReceiveTran2SetPathInfo(smb_vc_t *vcp, smb_tran2Packet_t *p, smb_packet_t *outp) { - return CM_ERROR_BADOP; + return CM_ERROR_BADOP; } long smb_ReceiveTran2QFileInfo(smb_vc_t *vcp, smb_tran2Packet_t *p, smb_packet_t *opx) @@ -1407,7 +1410,7 @@ long smb_ReceiveTran2QFileInfo(smb_vc_t *vcp, smb_tran2Packet_t *p, smb_packet_t } /* send and free the packets */ -done: + done: lock_ReleaseMutex(&scp->mx); cm_ReleaseUser(userp); smb_ReleaseFID(fidp); @@ -1553,7 +1556,7 @@ long smb_ReceiveTran2SetFileInfo(smb_vc_t *vcp, smb_tran2Packet_t *p, smb_packet fidp->flags &= ~SMB_FID_DELONCLOSE; } } -done: + done: cm_ReleaseUser(userp); smb_ReleaseFID(fidp); if (code == 0) smb_SendTran2Packet(vcp, outp, op); @@ -1565,27 +1568,27 @@ done: long smb_ReceiveTran2FSCTL(smb_vc_t *vcp, smb_tran2Packet_t *p, smb_packet_t *outp) { - return CM_ERROR_BADOP; + return CM_ERROR_BADOP; } long smb_ReceiveTran2IOCTL(smb_vc_t *vcp, smb_tran2Packet_t *p, smb_packet_t *outp) { - return CM_ERROR_BADOP; + return CM_ERROR_BADOP; } long smb_ReceiveTran2FindNotifyFirst(smb_vc_t *vcp, smb_tran2Packet_t *p, smb_packet_t *outp) { - return CM_ERROR_BADOP; + return CM_ERROR_BADOP; } long smb_ReceiveTran2FindNotifyNext(smb_vc_t *vcp, smb_tran2Packet_t *p, smb_packet_t *outp) { - return CM_ERROR_BADOP; + return CM_ERROR_BADOP; } long smb_ReceiveTran2MKDir(smb_vc_t *vcp, smb_tran2Packet_t *p, smb_packet_t *outp) { - return CM_ERROR_BADOP; + return CM_ERROR_BADOP; } long smb_ApplyV3DirListPatches(cm_scache_t *dscp, @@ -1593,47 +1596,46 @@ long smb_ApplyV3DirListPatches(cm_scache_t *dscp, cm_req_t *reqp) { long code; - cm_scache_t *scp; - cm_scache_t *targetScp; /* target if scp is a symlink */ - char *dptr; - long dosTime; + cm_scache_t *scp; + cm_scache_t *targetScp; /* target if scp is a symlink */ + char *dptr; + long dosTime; FILETIME ft; - int shortTemp; - unsigned short attr; + int shortTemp; + unsigned short attr; unsigned long lattr; - smb_dirListPatch_t *patchp; - smb_dirListPatch_t *npatchp; + smb_dirListPatch_t *patchp; + smb_dirListPatch_t *npatchp; - for(patchp = *dirPatchespp; patchp; patchp = - (smb_dirListPatch_t *) osi_QNext(&patchp->q)) { + for(patchp = *dirPatchespp; patchp; patchp = + (smb_dirListPatch_t *) osi_QNext(&patchp->q)) { code = cm_GetSCache(&patchp->fid, &scp, userp, reqp); - if (code) continue; - lock_ObtainMutex(&scp->mx); - code = cm_SyncOp(scp, NULL, userp, reqp, 0, - CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS); - if (code) { + if (code) continue; + lock_ObtainMutex(&scp->mx); + code = cm_SyncOp(scp, NULL, userp, reqp, 0, + CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS); + if (code) { lock_ReleaseMutex(&scp->mx); cm_ReleaseSCache(scp); continue; - } + } - /* now watch for a symlink */ - if (scp->fileType == CM_SCACHETYPE_SYMLINK) { + /* now watch for a symlink */ + if (scp->fileType == CM_SCACHETYPE_SYMLINK) { lock_ReleaseMutex(&scp->mx); - code = cm_EvaluateSymLink(dscp, scp, &targetScp, userp, - reqp); - if (code == 0) { + code = cm_EvaluateSymLink(dscp, scp, &targetScp, userp, reqp); + if (code == 0) { /* we have a more accurate file to use (the * target of the symbolic link). Otherwise, * we'll just use the symlink anyway. - */ + */ osi_Log2(afsd_logp, "symlink vp %x to vp %x", - scp, targetScp); + scp, targetScp); cm_ReleaseSCache(scp); - scp = targetScp; - } - lock_ObtainMutex(&scp->mx); - } + scp = targetScp; + } + lock_ObtainMutex(&scp->mx); + } dptr = patchp->dptr; @@ -1722,20 +1724,20 @@ long smb_ApplyV3DirListPatches(cm_scache_t *dscp, *dptr++ = (attr >> 8) & 0xff; } - lock_ReleaseMutex(&scp->mx); - cm_ReleaseSCache(scp); + lock_ReleaseMutex(&scp->mx); + cm_ReleaseSCache(scp); } - /* now free the patches */ - for(patchp = *dirPatchespp; patchp; patchp = npatchp) { + /* now free the patches */ + for(patchp = *dirPatchespp; patchp; patchp = npatchp) { npatchp = (smb_dirListPatch_t *) osi_QNext(&patchp->q); - free(patchp); + free(patchp); } - /* and mark the list as empty */ - *dirPatchespp = NULL; + /* and mark the list as empty */ + *dirPatchespp = NULL; - return code; + return code; } /* do a case-folding search of the star name mask with the name in namep. @@ -1744,7 +1746,7 @@ long smb_ApplyV3DirListPatches(cm_scache_t *dscp, int smb_V3MatchMask(char *namep, char *maskp, int flags) { unsigned char tcp1, tcp2; /* Pattern characters */ - unsigned char tcn1; /* Name characters */ + unsigned char tcn1; /* Name characters */ int sawDot = 0, sawStar = 0, req8dot3 = 0; char *starNamep, *starMaskp; static char nullCharp[] = {0}; @@ -1876,119 +1878,120 @@ int smb_V3MatchMask(char *namep, char *maskp, int flags) long smb_ReceiveTran2SearchDir(smb_vc_t *vcp, smb_tran2Packet_t *p, smb_packet_t *opx) { int attribute; - long nextCookie; - char *tp; - long code; - char *pathp; - cm_dirEntry_t *dep; - int maxCount; - smb_dirListPatch_t *dirListPatchesp; - smb_dirListPatch_t *curPatchp; - cm_buf_t *bufferp; - long temp; - long orbytes; /* # of bytes in this output record */ - long ohbytes; /* # of bytes, except file name */ - long onbytes; /* # of bytes in name, incl. term. null */ - osi_hyper_t dirLength; - osi_hyper_t bufferOffset; - osi_hyper_t curOffset; - osi_hyper_t thyper; - smb_dirSearch_t *dsp; - cm_scache_t *scp; - long entryInDir; - long entryInBuffer; + long nextCookie; + char *tp; + long code; + char *pathp; + cm_dirEntry_t *dep; + int maxCount; + smb_dirListPatch_t *dirListPatchesp; + smb_dirListPatch_t *curPatchp; + cm_buf_t *bufferp; + long temp; + long orbytes; /* # of bytes in this output record */ + long ohbytes; /* # of bytes, except file name */ + long onbytes; /* # of bytes in name, incl. term. null */ + osi_hyper_t dirLength; + osi_hyper_t bufferOffset; + osi_hyper_t curOffset; + osi_hyper_t thyper; + smb_dirSearch_t *dsp; + cm_scache_t *scp; + long entryInDir; + long entryInBuffer; cm_pageHeader_t *pageHeaderp; - cm_user_t *userp = NULL; - int slotInPage; - int returnedNames; - long nextEntryCookie; - int numDirChunks; /* # of 32 byte dir chunks in this entry */ - char *op; /* output data ptr */ + cm_user_t *userp = NULL; + int slotInPage; + int returnedNames; + long nextEntryCookie; + int numDirChunks; /* # of 32 byte dir chunks in this entry */ + char *op; /* output data ptr */ char *origOp; /* original value of op */ - cm_space_t *spacep; /* for pathname buffer */ - long maxReturnData; /* max # of return data */ - long maxReturnParms; /* max # of return parms */ - long bytesInBuffer; /* # data bytes in the output buffer */ - int starPattern; - char *maskp; /* mask part of path */ - int infoLevel; - int searchFlags; - int eos; - smb_tran2Packet_t *outp; /* response packet */ + cm_space_t *spacep; /* for pathname buffer */ + long maxReturnData; /* max # of return data */ + long maxReturnParms; /* max # of return parms */ + long bytesInBuffer; /* # data bytes in the output buffer */ + int starPattern; + char *maskp; /* mask part of path */ + int infoLevel; + int searchFlags; + int eos; + smb_tran2Packet_t *outp; /* response packet */ char *tidPathp; int align; char shortName[13]; /* 8.3 name if needed */ int NeedShortName; char *shortNameEnd; - int fileType; - cm_fid_t fid; - - cm_req_t req; + int fileType; + cm_fid_t fid; + + cm_req_t req; cm_InitReq(&req); eos = 0; if (p->opcode == 1) { /* find first; obtain basic parameters from request */ - attribute = p->parmsp[0]; - maxCount = p->parmsp[1]; - infoLevel = p->parmsp[3]; - searchFlags = p->parmsp[2]; - dsp = smb_NewDirSearch(1); - dsp->attribute = attribute; - pathp = ((char *) p->parmsp) + 12; /* points to path */ - nextCookie = 0; - maskp = strrchr(pathp, '\\'); - if (maskp == NULL) maskp = pathp; + attribute = p->parmsp[0]; + maxCount = p->parmsp[1]; + infoLevel = p->parmsp[3]; + searchFlags = p->parmsp[2]; + dsp = smb_NewDirSearch(1); + dsp->attribute = attribute; + pathp = ((char *) p->parmsp) + 12; /* points to path */ + nextCookie = 0; + maskp = strrchr(pathp, '\\'); + if (maskp == NULL) maskp = pathp; else maskp++; /* skip over backslash */ - strcpy(dsp->mask, maskp); /* and save mask */ + strcpy(dsp->mask, maskp); /* and save mask */ /* track if this is likely to match a lot of entries */ - starPattern = smb_V3IsStarMask(maskp); + starPattern = smb_V3IsStarMask(maskp); } - else { + else { osi_assert(p->opcode == 2); - /* find next; obtain basic parameters from request or open dir file */ - dsp = smb_FindDirSearch(p->parmsp[0]); - if (!dsp) return CM_ERROR_BADFD; - attribute = dsp->attribute; - maxCount = p->parmsp[1]; - infoLevel = p->parmsp[2]; - searchFlags = p->parmsp[5]; - pathp = NULL; - nextCookie = p->parmsp[3] | (p->parmsp[4] << 16); - maskp = dsp->mask; + /* find next; obtain basic parameters from request or open dir file */ + dsp = smb_FindDirSearch(p->parmsp[0]); + if (!dsp) return CM_ERROR_BADFD; + attribute = dsp->attribute; + maxCount = p->parmsp[1]; + infoLevel = p->parmsp[2]; + searchFlags = p->parmsp[5]; + pathp = NULL; + nextCookie = p->parmsp[3] | (p->parmsp[4] << 16); + maskp = dsp->mask; starPattern = 1; /* assume, since required a Find Next */ - } + } osi_Log4(afsd_logp, - "T2 search dir attr 0x%x, info level %d, max count %d, flags 0x%x", - attribute, infoLevel, maxCount, searchFlags); + "T2 search dir attr 0x%x, info level %d, max count %d, flags 0x%x", + attribute, infoLevel, maxCount, searchFlags); osi_Log2(afsd_logp, "...T2 search op %d, nextCookie 0x%x", - p->opcode, nextCookie); + p->opcode, nextCookie); if (infoLevel >= 0x101) searchFlags &= ~4; /* no resume keys */ - dirListPatchesp = NULL; + dirListPatchesp = NULL; maxReturnData = p->maxReturnData; - if (p->opcode == 1) /* find first */ - maxReturnParms = 10; /* bytes */ - else - maxReturnParms = 8; /* bytes */ + if (p->opcode == 1) /* find first */ + maxReturnParms = 10; /* bytes */ + else + maxReturnParms = 8; /* bytes */ #ifndef CM_CONFIG_MULTITRAN2RESPONSES - if (maxReturnData > 6000) maxReturnData = 6000; + if (maxReturnData > 6000) + maxReturnData = 6000; #endif /* CM_CONFIG_MULTITRAN2RESPONSES */ outp = smb_GetTran2ResponsePacket(vcp, p, opx, maxReturnParms, - maxReturnData); + maxReturnData); - osi_Log1(afsd_logp, "T2 receive search dir %s", - osi_LogSaveString(afsd_logp, pathp)); + osi_Log1(afsd_logp, "T2 receive search dir %s", + osi_LogSaveString(afsd_logp, pathp)); - /* bail out if request looks bad */ + /* bail out if request looks bad */ if (p->opcode == 1 && !pathp) { smb_ReleaseDirSearch(dsp); smb_FreeTran2Packet(outp); @@ -1996,7 +1999,7 @@ long smb_ReceiveTran2SearchDir(smb_vc_t *vcp, smb_tran2Packet_t *p, smb_packet_t } osi_Log2(afsd_logp, "T2 dir search cookie 0x%x, connection %d", - nextCookie, dsp->cookie); + nextCookie, dsp->cookie); userp = smb_GetTran2User(vcp, p); if (!userp) { @@ -2010,144 +2013,143 @@ long smb_ReceiveTran2SearchDir(smb_vc_t *vcp, smb_tran2Packet_t *p, smb_packet_t lock_ObtainMutex(&dsp->mx); if (dsp->scp) { scp = dsp->scp; - cm_HoldSCache(scp); - code = 0; - } - else { + cm_HoldSCache(scp); + code = 0; + } + else { spacep = cm_GetSpace(); - smb_StripLastComponent(spacep->data, NULL, pathp); - lock_ReleaseMutex(&dsp->mx); + smb_StripLastComponent(spacep->data, NULL, pathp); + lock_ReleaseMutex(&dsp->mx); tidPathp = smb_GetTIDPath(vcp, p->tid); - code = cm_NameI(cm_rootSCachep, spacep->data, - CM_FLAG_FOLLOW | CM_FLAG_CASEFOLD, - userp, tidPathp, &req, &scp); - cm_FreeSpace(spacep); + code = cm_NameI(cm_rootSCachep, spacep->data, + CM_FLAG_FOLLOW | CM_FLAG_CASEFOLD, + userp, tidPathp, &req, &scp); + cm_FreeSpace(spacep); - lock_ObtainMutex(&dsp->mx); + lock_ObtainMutex(&dsp->mx); if (code == 0) { - if (dsp->scp != 0) cm_ReleaseSCache(dsp->scp); + if (dsp->scp != 0) cm_ReleaseSCache(dsp->scp); dsp->scp = scp; /* we need one hold for the entry we just stored into, - * and one for our own processing. When we're done + * and one for our own processing. When we're done * with this function, we'll drop the one for our own * processing. We held it once from the namei call, * and so we do another hold now. - */ - cm_HoldSCache(scp); + */ + cm_HoldSCache(scp); lock_ObtainMutex(&scp->mx); if ((scp->flags & CM_SCACHEFLAG_BULKSTATTING) == 0 && LargeIntegerGreaterOrEqualToZero(scp->bulkStatProgress)) { - scp->flags |= CM_SCACHEFLAG_BULKSTATTING; + scp->flags |= CM_SCACHEFLAG_BULKSTATTING; dsp->flags |= SMB_DIRSEARCH_BULKST; } lock_ReleaseMutex(&scp->mx); - } } + } lock_ReleaseMutex(&dsp->mx); - if (code) { + if (code) { cm_ReleaseUser(userp); - smb_FreeTran2Packet(outp); + smb_FreeTran2Packet(outp); smb_DeleteDirSearch(dsp); smb_ReleaseDirSearch(dsp); - return code; + return code; } - /* get the directory size */ + /* get the directory size */ lock_ObtainMutex(&scp->mx); - code = cm_SyncOp(scp, NULL, userp, &req, 0, - CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS); + code = cm_SyncOp(scp, NULL, userp, &req, 0, + CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS); if (code) { lock_ReleaseMutex(&scp->mx); - cm_ReleaseSCache(scp); - cm_ReleaseUser(userp); - smb_FreeTran2Packet(outp); + cm_ReleaseSCache(scp); + cm_ReleaseUser(userp); + smb_FreeTran2Packet(outp); smb_DeleteDirSearch(dsp); smb_ReleaseDirSearch(dsp); - return code; - } - - dirLength = scp->length; - bufferp = NULL; - bufferOffset.LowPart = bufferOffset.HighPart = 0; - curOffset.HighPart = 0; - curOffset.LowPart = nextCookie; + return code; + } + + dirLength = scp->length; + bufferp = NULL; + bufferOffset.LowPart = bufferOffset.HighPart = 0; + curOffset.HighPart = 0; + curOffset.LowPart = nextCookie; origOp = outp->datap; - code = 0; - returnedNames = 0; - bytesInBuffer = 0; - while (1) { + code = 0; + returnedNames = 0; + bytesInBuffer = 0; + while (1) { op = origOp; if (searchFlags & 4) /* skip over resume key */ op += 4; /* make sure that curOffset.LowPart doesn't point to the first - * 32 bytes in the 2nd through last dir page, and that it doesn't - * point at the first 13 32-byte chunks in the first dir page, - * since those are dir and page headers, and don't contain useful - * information. - */ + * 32 bytes in the 2nd through last dir page, and that it doesn't + * point at the first 13 32-byte chunks in the first dir page, + * since those are dir and page headers, and don't contain useful + * information. + */ temp = curOffset.LowPart & (2048-1); - if (curOffset.HighPart == 0 && curOffset.LowPart < 2048) { + if (curOffset.HighPart == 0 && curOffset.LowPart < 2048) { /* we're in the first page */ - if (temp < 13*32) temp = 13*32; + if (temp < 13*32) temp = 13*32; } else { /* we're in a later dir page */ - if (temp < 32) temp = 32; - } + if (temp < 32) temp = 32; + } - /* make sure the low order 5 bits are zero */ - temp &= ~(32-1); + /* make sure the low order 5 bits are zero */ + temp &= ~(32-1); - /* now put temp bits back ito curOffset.LowPart */ - curOffset.LowPart &= ~(2048-1); - curOffset.LowPart |= temp; + /* now put temp bits back ito curOffset.LowPart */ + curOffset.LowPart &= ~(2048-1); + curOffset.LowPart |= temp; + + /* check if we've passed the dir's EOF */ + if (LargeIntegerGreaterThanOrEqualTo(curOffset, dirLength)) { + eos = 1; + break; + } - /* check if we've passed the dir's EOF */ - if (LargeIntegerGreaterThanOrEqualTo(curOffset, dirLength)) { - eos = 1; - break; - } + /* check if we've returned all the names that will fit in the + * response packet; we check return count as well as the number + * of bytes requested. We check the # of bytes after we find + * the dir entry, since we'll need to check its size. + */ + if (returnedNames >= maxCount) { + break; + } - /* check if we've returned all the names that will fit in the - * response packet; we check return count as well as the number - * of bytes requested. We check the # of bytes after we find - * the dir entry, since we'll need to check its size. - */ - if (returnedNames >= maxCount) { - break; - } - - /* see if we can use the bufferp we have now; compute in which - * page the current offset would be, and check whether that's - * the offset of the buffer we have. If not, get the buffer. - */ - thyper.HighPart = curOffset.HighPart; - thyper.LowPart = curOffset.LowPart & ~(buf_bufferSize-1); - if (!bufferp || !LargeIntegerEqualTo(thyper, bufferOffset)) { + /* see if we can use the bufferp we have now; compute in which + * page the current offset would be, and check whether that's + * the offset of the buffer we have. If not, get the buffer. + */ + thyper.HighPart = curOffset.HighPart; + thyper.LowPart = curOffset.LowPart & ~(buf_bufferSize-1); + if (!bufferp || !LargeIntegerEqualTo(thyper, bufferOffset)) { /* wrong buffer */ - if (bufferp) { - buf_Release(bufferp); - bufferp = NULL; - } + if (bufferp) { + buf_Release(bufferp); + bufferp = NULL; + } lock_ReleaseMutex(&scp->mx); lock_ObtainRead(&scp->bufCreateLock); - code = buf_Get(scp, &thyper, &bufferp); + code = buf_Get(scp, &thyper, &bufferp); lock_ReleaseRead(&scp->bufCreateLock); /* now, if we're doing a star match, do bulk fetching * of all of the status info for files in the dir. - */ - if (starPattern) { + */ + if (starPattern) { smb_ApplyV3DirListPatches(scp, &dirListPatchesp, - infoLevel, userp, - &req); + infoLevel, userp, + &req); if ((dsp->flags & SMB_DIRSEARCH_BULKST) - && LargeIntegerGreaterThanOrEqualTo( - thyper, scp->bulkStatProgress)) { + && LargeIntegerGreaterThanOrEqualTo(thyper, scp->bulkStatProgress)) { /* Don't bulk stat if risking timeout */ int now = GetCurrentTime(); if (now - req.startTime > 5000) { @@ -2155,79 +2157,77 @@ long smb_ReceiveTran2SearchDir(smb_vc_t *vcp, smb_tran2Packet_t *p, smb_packet_t scp->flags &= ~CM_SCACHEFLAG_BULKSTATTING; dsp->flags &= ~SMB_DIRSEARCH_BULKST; } else - cm_TryBulkStat(scp, &thyper, - userp, &req); + cm_TryBulkStat(scp, &thyper, userp, &req); } } - lock_ObtainMutex(&scp->mx); - if (code) break; - bufferOffset = thyper; + lock_ObtainMutex(&scp->mx); + if (code) break; + bufferOffset = thyper; - /* now get the data in the cache */ - while (1) { + /* now get the data in the cache */ + while (1) { code = cm_SyncOp(scp, bufferp, userp, &req, - PRSFS_LOOKUP, - CM_SCACHESYNC_NEEDCALLBACK - | CM_SCACHESYNC_READ); + PRSFS_LOOKUP, + CM_SCACHESYNC_NEEDCALLBACK + | CM_SCACHESYNC_READ); if (code) break; - if (cm_HaveBuffer(scp, bufferp, 0)) break; - - /* otherwise, load the buffer and try again */ - code = cm_GetBuffer(scp, bufferp, NULL, userp, - &req); - if (code) break; - } - if (code) { + if (cm_HaveBuffer(scp, bufferp, 0)) break; + + /* otherwise, load the buffer and try again */ + code = cm_GetBuffer(scp, bufferp, NULL, userp, + &req); + if (code) break; + } + if (code) { buf_Release(bufferp); - bufferp = NULL; - break; + bufferp = NULL; + break; } - } /* if (wrong buffer) ... */ + } /* if (wrong buffer) ... */ - /* now we have the buffer containing the entry we're interested - * in; copy it out if it represents a non-deleted entry. - */ + /* now we have the buffer containing the entry we're interested + * in; copy it out if it represents a non-deleted entry. + */ entryInDir = curOffset.LowPart & (2048-1); - entryInBuffer = curOffset.LowPart & (buf_bufferSize - 1); + entryInBuffer = curOffset.LowPart & (buf_bufferSize - 1); /* page header will help tell us which entries are free. Page * header can change more often than once per buffer, since * AFS 3 dir page size may be less than (but not more than) * a buffer package buffer. - */ + */ /* only look intra-buffer */ temp = curOffset.LowPart & (buf_bufferSize - 1); - temp &= ~(2048 - 1); /* turn off intra-page bits */ + temp &= ~(2048 - 1); /* turn off intra-page bits */ pageHeaderp = (cm_pageHeader_t *) (bufferp->datap + temp); /* now determine which entry we're looking at in the page. * If it is free (there's a free bitmap at the start of the * dir), we should skip these 32 bytes. - */ - slotInPage = (entryInDir & 0x7e0) >> 5; - if (!(pageHeaderp->freeBitmap[slotInPage>>3] - & (1 << (slotInPage & 0x7)))) { + */ + slotInPage = (entryInDir & 0x7e0) >> 5; + if (!(pageHeaderp->freeBitmap[slotInPage>>3] + & (1 << (slotInPage & 0x7)))) { /* this entry is free */ - numDirChunks = 1; /* only skip this guy */ - goto nextEntry; - } + numDirChunks = 1; /* only skip this guy */ + goto nextEntry; + } tp = bufferp->datap + entryInBuffer; - dep = (cm_dirEntry_t *) tp; /* now points to AFS3 dir entry */ + dep = (cm_dirEntry_t *) tp; /* now points to AFS3 dir entry */ - /* while we're here, compute the next entry's location, too, + /* while we're here, compute the next entry's location, too, * since we'll need it when writing out the cookie into the dir * listing stream. - * - * XXXX Probably should do more sanity checking. - */ + * + * XXXX Probably should do more sanity checking. + */ numDirChunks = cm_NameEntries(dep->name, &onbytes); - /* compute offset of cookie representing next entry */ - nextEntryCookie = curOffset.LowPart - + (CM_DIR_CHUNKSIZE * numDirChunks); + /* compute offset of cookie representing next entry */ + nextEntryCookie = curOffset.LowPart + (CM_DIR_CHUNKSIZE * numDirChunks); /* Need 8.3 name? */ NeedShortName = 0; @@ -2238,32 +2238,31 @@ long smb_ReceiveTran2SearchDir(smb_vc_t *vcp, smb_tran2Packet_t *p, smb_packet_t NeedShortName = 1; } - if (dep->fid.vnode != 0 - && (smb_V3MatchMask(dep->name, maskp, CM_FLAG_CASEFOLD) - || (NeedShortName - && smb_V3MatchMask(shortName, maskp, - CM_FLAG_CASEFOLD)))) { - - /* Eliminate entries that don't match requested - attributes */ - if (smb_hideDotFiles && !(dsp->attribute & SMB_ATTR_HIDDEN) && - smb_IsDotFile(dep->name)) - goto nextEntry; /* no hidden files */ + if (dep->fid.vnode != 0 + && (smb_V3MatchMask(dep->name, maskp, CM_FLAG_CASEFOLD) + || (NeedShortName + && smb_V3MatchMask(shortName, maskp, + CM_FLAG_CASEFOLD)))) { + + /* Eliminate entries that don't match requested attributes */ + if (smb_hideDotFiles && !(dsp->attribute & SMB_ATTR_HIDDEN) && + smb_IsDotFile(dep->name)) + goto nextEntry; /* no hidden files */ - if (!(dsp->attribute & SMB_ATTR_DIRECTORY)) /* no directories */ - { - /* We have already done the cm_TryBulkStat above */ - fid.cell = scp->fid.cell; - fid.volume = scp->fid.volume; - fid.vnode = ntohl(dep->fid.vnode); - fid.unique = ntohl(dep->fid.unique); - fileType = cm_FindFileType(&fid); - /*osi_Log2(afsd_logp, "smb_ReceiveTran2SearchDir: file %s " - "has filetype %d", dep->name, - fileType);*/ - if (fileType == CM_SCACHETYPE_DIRECTORY) - goto nextEntry; - } + if (!(dsp->attribute & SMB_ATTR_DIRECTORY)) /* no directories */ + { + /* We have already done the cm_TryBulkStat above */ + fid.cell = scp->fid.cell; + fid.volume = scp->fid.volume; + fid.vnode = ntohl(dep->fid.vnode); + fid.unique = ntohl(dep->fid.unique); + fileType = cm_FindFileType(&fid); + /*osi_Log2(afsd_logp, "smb_ReceiveTran2SearchDir: file %s " + "has filetype %d", dep->name, + fileType);*/ + if (fileType == CM_SCACHETYPE_DIRECTORY) + goto nextEntry; + } /* finally check if this name will fit */ @@ -2278,13 +2277,13 @@ long smb_ReceiveTran2SearchDir(smb_vc_t *vcp, smb_tran2Packet_t *p, smb_packet_t if (infoLevel == 0x104) ohbytes += 26; /* Short name & length */ - if (searchFlags & 4) { - ohbytes += 4; /* if resume key required */ - } + if (searchFlags & 4) { + ohbytes += 4; /* if resume key required */ + } - if (infoLevel != 1 - && infoLevel != 0x101 - && infoLevel != 0x103) + if (infoLevel != 1 + && infoLevel != 0x101 + && infoLevel != 0x103) ohbytes += 4; /* EASIZE */ /* add header to name & term. null */ @@ -2295,39 +2294,39 @@ long smb_ReceiveTran2SearchDir(smb_vc_t *vcp, smb_tran2Packet_t *p, smb_packet_t * even the aligned version (so we don't have to worry * about an * overflow when we pad things out below). * That's the reason for the alignment arithmetic below. - */ + */ if (infoLevel >= 0x101) align = (4 - (orbytes & 3)) & 3; else align = 0; if (orbytes + bytesInBuffer + align > maxReturnData) - break; + break; /* this is one of the entries to use: it is not deleted * and it matches the star pattern we're looking for. * Put out the name, preceded by its length. - */ + */ /* First zero everything else */ memset(origOp, 0, ohbytes); if (infoLevel <= 0x101) - *(origOp + ohbytes - 1) = (unsigned char) onbytes; + *(origOp + ohbytes - 1) = (unsigned char) onbytes; else if (infoLevel == 0x103) *((u_long *)(op + 8)) = onbytes; else *((u_long *)(op + 60)) = onbytes; - strcpy(origOp+ohbytes, dep->name); + strcpy(origOp+ohbytes, dep->name); /* Short name if requested and needed */ - if (infoLevel == 0x104) { + if (infoLevel == 0x104) { if (NeedShortName) { strcpy(op + 70, shortName); *(op + 68) = shortNameEnd - shortName; } } - /* now, adjust the # of entries copied */ - returnedNames++; + /* now, adjust the # of entries copied */ + returnedNames++; /* NextEntryOffset and FileIndex */ if (infoLevel >= 101) { @@ -2336,23 +2335,23 @@ long smb_ReceiveTran2SearchDir(smb_vc_t *vcp, smb_tran2Packet_t *p, smb_packet_t *((u_long *)(op+4)) = nextEntryCookie; } - /* now we emit the attribute. This is tricky, since - * we need to really stat the file to find out what + /* now we emit the attribute. This is tricky, since + * we need to really stat the file to find out what * type of entry we've got. Right now, we're copying * out data from * a buffer, while holding the scp * locked, so it isn't really convenient to stat * something now. We'll put in a place holder - * now, and make a second pass before returning this + * now, and make a second pass before returning this * to get the real attributes. So, we just skip the * data for now, and adjust it later. We allocate a * patch record to make it easy to find this point * later. The replay will happen at a time when it is * safe to unlock the directory. - */ + */ if (infoLevel != 0x103) { curPatchp = malloc(sizeof(*curPatchp)); - osi_QAdd((osi_queue_t **) &dirListPatchesp, - &curPatchp->q); + osi_QAdd((osi_queue_t **) &dirListPatchesp, + &curPatchp->q); curPatchp->dptr = op; if (infoLevel >= 0x101) curPatchp->dptr += 8; @@ -2368,9 +2367,9 @@ long smb_ReceiveTran2SearchDir(smb_vc_t *vcp, smb_tran2Packet_t *p, smb_packet_t curPatchp->fid.vnode = ntohl(dep->fid.vnode); curPatchp->fid.unique = ntohl(dep->fid.unique); - /* temp */ - curPatchp->dep = dep; - } + /* temp */ + curPatchp->dep = dep; + } if (searchFlags & 4) /* put out resume key */ @@ -2378,79 +2377,80 @@ long smb_ReceiveTran2SearchDir(smb_vc_t *vcp, smb_tran2Packet_t *p, smb_packet_t /* Adjust byte ptr and count */ origOp += orbytes; /* skip entire record */ - bytesInBuffer += orbytes; + bytesInBuffer += orbytes; /* and pad the record out */ - while (--align >= 0) { + while (--align >= 0) { *origOp++ = 0; - bytesInBuffer++; - } - + bytesInBuffer++; + } + } /* if we're including this name */ -nextEntry: - /* and adjust curOffset to be where the new cookie is */ + nextEntry: + /* and adjust curOffset to be where the new cookie is */ thyper.HighPart = 0; - thyper.LowPart = CM_DIR_CHUNKSIZE * numDirChunks; - curOffset = LargeIntegerAdd(thyper, curOffset); - } /* while copying data for dir listing */ + thyper.LowPart = CM_DIR_CHUNKSIZE * numDirChunks; + curOffset = LargeIntegerAdd(thyper, curOffset); + } /* while copying data for dir listing */ /* release the mutex */ lock_ReleaseMutex(&scp->mx); - if (bufferp) buf_Release(bufferp); + if (bufferp) buf_Release(bufferp); /* 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_ApplyV3DirListPatches(scp, &dirListPatchesp, infoLevel, userp, - &req); + */ + smb_ApplyV3DirListPatches(scp, &dirListPatchesp, infoLevel, userp, + &req); - /* now put out the final parameters */ + /* now put out the final parameters */ if (returnedNames == 0) eos = 1; - if (p->opcode == 1) { + if (p->opcode == 1) { /* find first */ - outp->parmsp[0] = (unsigned short) dsp->cookie; - outp->parmsp[1] = returnedNames; - outp->parmsp[2] = eos; - outp->parmsp[3] = 0; /* nothing wrong with EAS */ - outp->parmsp[4] = 0; /* don't need last name to continue - * search, cookie is enough. Normally, - * this is the offset of the file name - * of the last entry returned. - */ - outp->totalParms = 10; /* in bytes */ - } - else { - /* find next */ - outp->parmsp[0] = returnedNames; - outp->parmsp[1] = eos; - outp->parmsp[2] = 0; /* EAS error */ - outp->parmsp[3] = 0; /* last name, as above */ - outp->totalParms = 8; /* in bytes */ - } + outp->parmsp[0] = (unsigned short) dsp->cookie; + outp->parmsp[1] = returnedNames; + outp->parmsp[2] = eos; + outp->parmsp[3] = 0; /* nothing wrong with EAS */ + outp->parmsp[4] = 0; + /* don't need last name to continue + * search, cookie is enough. Normally, + * this is the offset of the file name + * of the last entry returned. + */ + outp->totalParms = 10; /* in bytes */ + } + else { + /* find next */ + outp->parmsp[0] = returnedNames; + outp->parmsp[1] = eos; + outp->parmsp[2] = 0; /* EAS error */ + outp->parmsp[3] = 0; /* last name, as above */ + outp->totalParms = 8; /* in bytes */ + } /* return # of bytes in the buffer */ - outp->totalData = bytesInBuffer; + outp->totalData = bytesInBuffer; osi_Log2(afsd_logp, "T2 search dir done, %d names, code %d", - returnedNames, code); + returnedNames, code); /* Return error code if unsuccessful on first request */ if (code == 0 && p->opcode == 1 && returnedNames == 0) code = CM_ERROR_NOSUCHFILE; /* if we're supposed to close the search after this request, or if - * we're supposed to close the search if we're done, and we're done, - * or if something went wrong, close the search. - */ - /* ((searchFlags & 1) || ((searchFlags & 2) && eos) */ - if ((searchFlags & 1) || (returnedNames == 0) || ((searchFlags & 2) && - eos) || code != 0) + * we're supposed to close the search if we're done, and we're done, + * or if something went wrong, close the search. + */ + /* ((searchFlags & 1) || ((searchFlags & 2) && eos) */ + if ((searchFlags & 1) || (returnedNames == 0) || + ((searchFlags & 2) && eos) || code != 0) smb_DeleteDirSearch(dsp); if (code) - smb_SendTran2Error(vcp, p, opx, code); + smb_SendTran2Error(vcp, p, opx, code); else { - smb_SendTran2Packet(vcp, outp, opx); + smb_SendTran2Packet(vcp, outp, opx); } smb_FreeTran2Packet(outp); smb_ReleaseDirSearch(dsp); @@ -2939,7 +2939,7 @@ long smb_ReceiveV3GetAttributes(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t * smb_SetSMBDataLength(outp, 0); code = 0; -done: + done: lock_ReleaseMutex(&scp->mx); cm_ReleaseUser(userp); smb_ReleaseFID(fidp);