-/*
- * Copyright (C) 1998, 1989 Transarc Corporation - All rights reserved
- *
- * (C) COPYRIGHT IBM CORPORATION 1987, 1988
- * LICENSED MATERIALS - PROPERTY OF IBM
- *
- *
+/*
+ * Copyright 2000, International Business Machines Corporation and others.
+ * All Rights Reserved.
+ *
+ * This software has been released under the terms of the IBM Public
+ * License. For details, see the LICENSE file in the top-level source
+ * directory or online at http://www.openafs.org/dl/license10.html
*/
+//#define NOSERVICE 1
+
+#define NOMOREFILESFIX 1
+
#include <afs/param.h>
#include <afs/stds.h>
+#ifndef DJGPP
#include <windows.h>
+#else
+#include <sys/timeb.h>
+#include <tzfile.h>
+#endif /* !DJGPP */
#include <stddef.h>
#include <stdlib.h>
#include <malloc.h>
#include "afsd.h"
#include "smb.h"
+#include "lanahelper.h"
/* These characters are illegal in Windows filenames */
static char *illegalChars = "\\/:*?\"<>|";
smb_vc_t *dead_vcp = NULL;
smb_vc_t *active_vcp = NULL;
+/* TODO; logout mechanism needs to be thread-safe */
char *loggedOutName = NULL;
smb_user_t *loggedOutUserp = NULL;
unsigned long loggedOutTime;
int loggedOut = 0;
+#ifdef DJGPP
+int smbShutdownFlag = 0;
+#endif /* DJGPP */
int smb_LogoffTokenTransfer;
unsigned long smb_LogoffTransferTimeout;
unsigned int sessionGen = 0;
-void afsi_log();
+extern void afsi_log(char *pattern, ...);
+extern HANDLE afsi_file;
osi_hyper_t hzero = {0, 0};
osi_hyper_t hones = {0xFFFFFFFF, -1};
-osi_log_t *smb_logp;
+osi_log_t * smb_logp;
osi_rwlock_t smb_globalLock;
osi_rwlock_t smb_rctLock;
-
-unsigned char smb_LANadapter;
+osi_mutex_t smb_ListenerLock;
+
+char smb_LANadapter;
+unsigned char smb_sharename[NCBNAMSZ+1] = {0};
/* for debugging */
long smb_maxObsConcurrentCalls=0;
int numNCBs, numSessions;
-#define NCBmax 100
-HANDLE NCBavails[NCBmax], NCBevents[NCBmax];
-HANDLE **NCBreturns;
+int smb_maxVCPerServer;
+int smb_maxMpxRequests;
+
+#define NCBmax MAXIMUM_WAIT_OBJECTS
+EVENT_HANDLE NCBavails[NCBmax], NCBevents[NCBmax];
+EVENT_HANDLE **NCBreturns;
DWORD NCBsessions[NCBmax];
NCB *NCBs[NCBmax];
struct smb_packet *bufs[NCBmax];
-#define Sessionmax 100
-HANDLE SessionEvents[Sessionmax];
+#define Sessionmax MAXIMUM_WAIT_OBJECTS
+EVENT_HANDLE SessionEvents[Sessionmax];
unsigned short LSNs[Sessionmax];
+int lanas[Sessionmax];
BOOL dead_sessions[Sessionmax];
+LANA_ENUM lana_list;
/* for raw I/O */
osi_mutex_t smb_RawBufLock;
+#ifdef DJGPP
+#define SMB_RAW_BUFS 4
+dos_ptr smb_RawBufs;
+int smb_RawBufSel[SMB_RAW_BUFS];
+#else
char *smb_RawBufs;
+#endif /* DJGPP */
#define RAWTIMEOUT INFINITE
long code;
osi_hyper_t offset;
long count;
+#ifndef DJGPP
char *buf;
+#else
+ dos_ptr buf;
+#endif /* DJGPP */
int writeMode;
long alreadyWritten;
} raw_write_cont_t;
smb_dirSearch_t *smb_firstDirSearchp;
smb_dirSearch_t *smb_lastDirSearchp;
+/* hide dot files? */
+int smb_hideDotFiles;
+
/* global state about V3 protocols */
int smb_useV3; /* try to negotiate V3 */
+#ifndef DJGPP
/* MessageBox or something like it */
int (WINAPI *smb_MBfunc)(HWND, LPCTSTR, LPCTSTR, UINT) = NULL;
+#endif /* DJGPP */
/* GMT time info:
* Time in Unix format of midnight, 1/1/1970 local time.
/* Time difference for converting to kludge-GMT */
int smb_NowTZ;
-char *smb_localNamep;
+char *smb_localNamep = NULL;
smb_vc_t *smb_allVCsp;
+smb_username_t *usernamesp = NULL;
+
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);
+void smb_NetbiosInit();
+#ifdef DJGPP
+#ifndef AFS_WIN95_ENV
+DWORD smb_ServerExceptionFilter(void);
+#endif
+
+extern char cm_HostName[];
+extern char cm_confDir[];
+#endif
+
+#ifdef DJGPP
+#define LPTSTR char *
+#define GetComputerName(str, sizep) \
+ strcpy((str), cm_HostName); \
+ *(sizep) = strlen(cm_HostName)
+#endif /* DJGPP */
+
+extern char AFSConfigKeyName[];
/*
* Demo expiration
#define EXPIREDATE 834000000 /* Wed Jun 5 1996 */
+char * myCrt_Dispatch(int i)
+{
+ switch (i)
+ {
+ default:
+ return "unknown SMB op";
+ case 0x00:
+ return "(00)ReceiveCoreMakeDir";
+ case 0x01:
+ return "(01)ReceiveCoreRemoveDir";
+ case 0x02:
+ return "(02)ReceiveCoreOpen";
+ case 0x03:
+ return "(03)ReceiveCoreCreate";
+ case 0x04:
+ return "(04)ReceiveCoreClose";
+ case 0x05:
+ return "(05)ReceiveCoreFlush";
+ case 0x06:
+ return "(06)ReceiveCoreUnlink";
+ case 0x07:
+ return "(07)ReceiveCoreRename";
+ case 0x08:
+ return "(08)ReceiveCoreGetFileAttributes";
+ case 0x09:
+ return "(09)ReceiveCoreSetFileAttributes";
+ case 0x0a:
+ return "(0a)ReceiveCoreRead";
+ case 0x0b:
+ return "(0b)ReceiveCoreWrite";
+ case 0x0c:
+ return "(0c)ReceiveCoreLockRecord";
+ case 0x0d:
+ return "(0d)ReceiveCoreUnlockRecord";
+ case 0x0e:
+ return "(0e)SendCoreBadOp";
+ case 0x0f:
+ return "(0f)ReceiveCoreCreate";
+ case 0x10:
+ return "(10)ReceiveCoreCheckPath";
+ case 0x11:
+ return "(11)SendCoreBadOp";
+ case 0x12:
+ return "(12)ReceiveCoreSeek";
+ case 0x1a:
+ return "(1a)ReceiveCoreReadRaw";
+ case 0x1d:
+ return "(1d)ReceiveCoreWriteRawDummy";
+ case 0x22:
+ return "(22)ReceiveV3SetAttributes";
+ case 0x23:
+ return "(23)ReceiveV3GetAttributes";
+ case 0x24:
+ return "(24)ReceiveV3LockingX";
+ case 0x29:
+ return "(29)SendCoreBadOp";
+ case 0x2b:
+ return "(2b)ReceiveCoreEcho";
+ case 0x2d:
+ return "(2d)ReceiveV3OpenX";
+ case 0x2e:
+ return "(2e)ReceiveV3ReadX";
+ case 0x32:
+ return "(32)ReceiveV3Tran2A";
+ case 0x33:
+ return "(33)ReceiveV3Tran2A";
+ case 0x34:
+ return "(34)ReceiveV3FindClose";
+ case 0x35:
+ return "(35)ReceiveV3FindNotifyClose";
+ case 0x70:
+ return "(70)ReceiveCoreTreeConnect";
+ case 0x71:
+ return "(71)ReceiveCoreTreeDisconnect";
+ case 0x72:
+ return "(72)ReceiveNegotiate";
+ case 0x73:
+ return "(73)ReceiveV3SessionSetupX";
+ case 0x74:
+ return "(74)ReceiveV3UserLogoffX";
+ case 0x75:
+ return "(75)ReceiveV3TreeConnectX";
+ case 0x80:
+ return "(80)ReceiveCoreGetDiskAttributes";
+ case 0x81:
+ return "(81)ReceiveCoreSearchDir";
+ case 0xA0:
+ return "(A0)ReceiveNTTransact";
+ case 0xA2:
+ return "(A2)ReceiveNTCreateX";
+ case 0xA4:
+ return "(A4)ReceiveNTCancel";
+ case 0xc0:
+ return "(c0)SendCoreBadOp";
+ case 0xc1:
+ return "(c1)SendCoreBadOp";
+ case 0xc2:
+ return "(c2)SendCoreBadOp";
+ case 0xc3:
+ return "(c3)SendCoreBadOp";
+ }
+}
+char * myCrt_2Dispatch(int i)
+{
+ switch (i)
+ {
+ default:
+ return "unknown SMB op-2";
+ case 0:
+ return "S(00)CreateFile";
+ case 1:
+ return "S(01)FindFirst";
+ case 2:
+ return "S(02)FindNext"; /* FindNext */
+ case 3:
+ return "S(03)QueryFileSystem_ReceiveTran2QFSInfo";
+ case 4:
+ return "S(04)??";
+ case 5:
+ return "S(05)QueryFileInfo_ReceiveTran2QPathInfo";
+ case 6:
+ return "S(06)SetFileInfo_ReceiveTran2SetPathInfo";
+ case 7:
+ return "S(07)SetInfoHandle_ReceiveTran2QFileInfo";
+ case 8:
+ return "S(08)??_ReceiveTran2SetFileInfo";
+ case 9:
+ return "S(09)??_ReceiveTran2FSCTL";
+ case 10:
+ return "S(0a)_ReceiveTran2IOCTL";
+ case 11:
+ return "S(0b)_ReceiveTran2FindNotifyFirst";
+ case 12:
+ return "S(0c)_ReceiveTran2FindNotifyNext";
+ case 13:
+ return "S(0d)CreateDirectory_ReceiveTran2MKDir";
+ }
+}
/* scache must be locked */
unsigned int smb_Attributes(cm_scache_t *scp)
if (scp->fileType == CM_SCACHETYPE_DIRECTORY
|| scp->fileType == CM_SCACHETYPE_MOUNTPOINT)
- attrs = 0x10;
+ attrs = SMB_ATTR_DIRECTORY;
else
attrs = 0;
if ((scp->unixModeBits & 0222) == 0 || (scp->flags & CM_SCACHEFLAG_RO))
#endif
if ((scp->unixModeBits & 0222) == 0)
- attrs |= 1; /* turn on read-only flag */
+ attrs |= SMB_ATTR_READONLY; /* turn on read-only flag */
return attrs;
}
+/* Check if the named file/dir is a dotfile/dotdir */
+/* String pointed to by lastComp can have leading slashes, but otherwise should have
+ no other patch components */
+unsigned int smb_IsDotFile(char *lastComp) {
+ char *s;
+ if(lastComp) {
+ /* skip over slashes */
+ for(s=lastComp;*s && (*s == '\\' || *s == '/'); s++);
+ }
+ else
+ return 0;
+
+ /* nulls, curdir and parent dir doesn't count */
+ if(!*s) return 0;
+ if(*s == '.') {
+ if(!*(s + 1)) return 0;
+ if(*(s+1) == '.' && !*(s + 2)) return 0;
+ return 1;
+ }
+ return 0;
+}
+
static int ExtractBits(WORD bits, short start, short len)
{
int end;
return (int)num;
}
+#ifndef DJGPP
void ShowUnixTime(char *FuncName, long unixTime)
{
FILETIME ft;
osi_Log1(afsd_logp, "%s", osi_LogSaveString(afsd_logp, msg));
}
}
+#endif /* DJGPP */
+#ifndef DJGPP
/* Determine if we are observing daylight savings time */
void GetTimeZoneInfo(BOOL *pDST, LONG *pDstBias, LONG *pBias)
{
*/
*pDST = localDST.wHour != local.wHour;
}
+#else
+/* Determine if we are observing daylight savings time */
+void GetTimeZoneInfo(BOOL *pDST, LONG *pDstBias, LONG *pBias)
+{
+ struct timeb t;
+
+ ftime(&t);
+ *pDST = t.dstflag;
+ *pDstBias = -60; /* where can this be different? */
+ *pBias = t.timezone;
+}
+#endif /* DJGPP */
+
void CompensateForSmbClientLastWriteTimeBugs(long *pLastWriteTime)
{
smb_NowTZ = seconds;
}
+
+#ifndef DJGPP
void smb_LargeSearchTimeFromUnixTime(FILETIME *largeTimep, long unixTime)
{
struct tm *ltp;
SystemTimeToFileTime(&stm, largeTimep);
}
+#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)
+ * 24 * 60);
+ *ft = LargeIntegerMultiplyByLong(*ft, 60);
+ *ft = LargeIntegerMultiplyByLong(*ft, 10000000);
+
+ /* add unix time */
+ ut = ConvertLongToLargeInteger(unixTime);
+ ut = LargeIntegerMultiplyByLong(ut, 10000000);
+ *ft = LargeIntegerAdd(*ft, ut);
+}
+#endif /* !DJGPP */
+#ifndef DJGPP
void smb_UnixTimeFromLargeSearchTime(long *unixTimep, FILETIME *largeTimep)
{
SYSTEMTIME stm;
*unixTimep = mktime(<);
_timezone = save_timezone;
}
+#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);
+}
+#endif /* !DJGPP */
void smb_SearchTimeFromUnixTime(long *dosTimep, long unixTime)
{
int dosTime;
struct tm localJunk;
- ltp = localtime(&unixTime);
+ ltp = localtime((time_t*) &unixTime);
/* if we fail, make up something */
if (!ltp) {
void smb_UnixTimeFromDosUTime(long *unixTimep, long dosTime)
{
+#ifndef DJGPP
*unixTimep = dosTime + smb_localZero;
+#else /* DJGPP */
+ /* dosTime seems to be already adjusted for GMT */
+ *unixTimep = dosTime;
+#endif /* !DJGPP */
}
-smb_vc_t *smb_FindVC(unsigned short lsn, int flags)
+smb_vc_t *smb_FindVC(unsigned short lsn, int flags, int lana)
{
smb_vc_t *vcp;
lock_ObtainWrite(&smb_rctLock);
for(vcp = smb_allVCsp; vcp; vcp=vcp->nextp) {
- if (lsn == vcp->lsn) {
+ if (lsn == vcp->lsn && lana == vcp->lana) {
vcp->refCount++;
break;
}
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;
smb_user_t *smb_FindUID(smb_vc_t *vcp, unsigned short uid, int flags)
{
- smb_user_t *uidp;
+ smb_user_t *uidp = NULL;
lock_ObtainWrite(&smb_rctLock);
for(uidp = vcp->usersp; uidp; uidp = uidp->nextp) {
if (uid == uidp->userID) {
uidp->refCount++;
- break;
+ 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)) {
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)
+{
+ smb_username_t *unp= NULL;
+
+ lock_ObtainWrite(&smb_rctLock);
+ for(unp = usernamesp; unp; unp = unp->nextp) {
+ if (stricmp(unp->name, usern) == 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");
+ }
+ lock_ReleaseWrite(&smb_rctLock);
+ return unp;
+}
+
+smb_user_t *smb_FindUserByNameThisSession(smb_vc_t *vcp, char *usern)
+{
+ smb_user_t *uidp= NULL;
+
+ lock_ObtainWrite(&smb_rctLock);
+ for(uidp = vcp->usersp; uidp; uidp = uidp->nextp) {
+ if (!uidp->unp)
+ continue;
+ 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
+ continue;
+ }
+ lock_ReleaseWrite(&smb_rctLock);
+ return uidp;
+}
void smb_ReleaseUID(smb_user_t *uidp)
{
smb_user_t *up;
osi_assert(up != NULL);
*lupp = up->nextp;
lock_FinalizeMutex(&uidp->mx);
- userp = uidp->userp; /* remember to drop ref later */
+ if (uidp->unp)
+ userp = uidp->unp->userp; /* remember to drop ref later */
}
lock_ReleaseWrite(&smb_rctLock);
if (userp) {
smbp = (smb_t *) inp;
uidp = smb_FindUID(vcp, smbp->uid, 0);
- if (!uidp) return NULL;
+ if ((!uidp) || (!uidp->unp))
+ return NULL;
lock_ObtainMutex(&uidp->mx);
- up = uidp->userp;
+ up = uidp->unp->userp;
cm_HoldUser(up);
lock_ReleaseMutex(&uidp->mx);
char *tpath;
tidp = smb_FindTID(vcp, tid, 0);
+ if (!tidp)
+ return NULL;
tpath = tidp->pathname;
smb_ReleaseTID(tidp);
return tpath;
if (fid == fidp->fid) {
if (newFid) {
fid++;
- if (fid == 0) fid = 1;
- goto retry;
- }
+ if (fid == 0) fid = 1;
+ goto retry;
+ }
fidp->refCount++;
- break;
+ break;
}
- }
- if (!fidp && (flags & SMB_FLAG_CREATE)) {
+ }
+ if (!fidp && (flags & SMB_FLAG_CREATE)) {
+ char eventName[MAX_PATH];
+ sprintf(eventName,"fid_t event fid=%d", fid);
fidp = malloc(sizeof(*fidp));
- memset(fidp, 0, sizeof(*fidp));
+ memset(fidp, 0, sizeof(*fidp));
osi_QAdd((osi_queue_t **)&vcp->fidsp, &fidp->q);
- fidp->refCount = 1;
- fidp->vcp = vcp;
- lock_InitializeMutex(&fidp->mx, "fid_t mutex");
- fidp->fid = fid;
+ fidp->refCount = 1;
+ fidp->vcp = vcp;
+ lock_InitializeMutex(&fidp->mx, "fid_t mutex");
+ fidp->fid = fid;
fidp->curr_chunk = fidp->prev_chunk = -2;
- fidp->raw_write_event = CreateEvent(NULL, FALSE, TRUE, NULL);
- if (newFid) {
+ fidp->raw_write_event = thrd_CreateEvent(NULL, FALSE, TRUE, eventName);
+ if ( GetLastError() == ERROR_ALREADY_EXISTS )
+ afsi_log("Event Object Already Exists: %s", eventName);
+ if (newFid) {
vcp->fidCounter = fid+1;
- if (vcp->fidCounter == 0) vcp->fidCounter = 1;
- }
+ if (vcp->fidCounter == 0) vcp->fidCounter = 1;
}
- lock_ReleaseWrite(&smb_rctLock);
- return fidp;
+ }
+ lock_ReleaseWrite(&smb_rctLock);
+ return fidp;
}
void smb_ReleaseFID(smb_fid_t *fidp)
{
cm_scache_t *scp;
- smb_vc_t *vcp;
- smb_ioctl_t *ioctlp;
+ smb_vc_t *vcp;
+ smb_ioctl_t *ioctlp;
+
+ if (!fidp)
+ return NULL;
scp = NULL;
lock_ObtainWrite(&smb_rctLock);
osi_assert(fidp->refCount-- > 0);
- if (fidp->refCount == 0 && (fidp->flags & SMB_FID_DELETE)) {
+ if (fidp->refCount == 0 && (fidp->flags & SMB_FID_DELETE)) {
vcp = fidp->vcp;
if (!(fidp->flags & SMB_FID_IOCTL))
scp = fidp->scp;
osi_QRemove((osi_queue_t **) &vcp->fidsp, &fidp->q);
- CloseHandle(fidp->raw_write_event);
+ thrd_CloseHandle(fidp->raw_write_event);
/* and see if there is ioctl stuff to free */
- ioctlp = fidp->ioctlp;
- if (ioctlp) {
+ ioctlp = fidp->ioctlp;
+ if (ioctlp) {
if (ioctlp->prefix) cm_FreeSpace(ioctlp->prefix);
if (ioctlp->inAllocp) free(ioctlp->inAllocp);
if (ioctlp->outAllocp) free(ioctlp->outAllocp);
free(ioctlp);
- }
-
- free(fidp);
}
+
+ free(fidp);
+ }
lock_ReleaseWrite(&smb_rctLock);
/* now release the scache structure */
char VNComputerName[] = "%COMPUTERNAME%";
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);
+
+#ifndef DJGPP
+ code = GetWindowsDirectory(sbmtpath, sizeof(sbmtpath));
+ if (code == 0 || code > sizeof(sbmtpath)) return -1;
+#else
+ 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;
+ }
+
+ 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, 4) != 0)
+ print_afs = 1;
+ 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 */
+
+ return num_shares;
+}
+
/* find a shareName in the table of submounts */
int smb_FindShare(smb_vc_t *vcp, smb_packet_t *inp, char *shareName,
char **pathNamep)
smb_user_t *uidp;
char temp[1024];
DWORD sizeTemp;
+ char sbmtpath[256];
+ char *p, *q;
+ HKEY parmKey;
+ DWORD code;
+ DWORD allSubmount = 1;
if (strcmp(shareName, "IPC$") == 0) {
*pathNamep = NULL;
return 0;
}
- if (_stricmp(shareName, "all") == 0) {
+ /* if allSubmounts == 0, only return the //mountRoot/all share
+ * if in fact it has been been created in the subMounts table.
+ * This is to allow sites that want to restrict access to the
+ * world to do so.
+ */
+ code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSConfigKeyName,
+ 0, KEY_QUERY_VALUE, &parmKey);
+ if (code == ERROR_SUCCESS) {
+ len = sizeof(allSubmount);
+ code = RegQueryValueEx(parmKey, "AllSubmount", NULL, NULL,
+ (BYTE *) &allSubmount, &len);
+ if (code != ERROR_SUCCESS) {
+ allSubmount = 1;
+ }
+ RegCloseKey (parmKey);
+ }
+
+ if (allSubmount && _stricmp(shareName, "all") == 0) {
*pathNamep = NULL;
return 1;
}
+ /* In case, the all share is disabled we need to still be able
+ * to handle ioctl requests
+ */
+ if (_stricmp(shareName, "ioctl$") == 0) {
+ *pathNamep = "/.__ioctl__";
+ return 1;
+ }
+
+#ifndef DJGPP
+ strcpy(sbmtpath, "afsdsbmt.ini");
+#else /* DJGPP */
+ strcpy(sbmtpath, cm_confDir);
+ strcat(sbmtpath, "/afsdsbmt.ini");
+#endif /* !DJGPP */
len = GetPrivateProfileString("AFS Submounts", shareName, "",
- pathName, sizeof(pathName), "afsdsbmt.ini");
+ pathName, sizeof(pathName), sbmtpath);
if (len == 0 || len == sizeof(pathName) - 1) {
*pathNamep = NULL;
return 0;
}
+
+ /* We can accept either unix or PC style AFS pathnames. Convert
+ Unix-style to PC style here for internal use. */
+ p = pathName;
+ if (strncmp(p, cm_mountRoot, 4) == 0)
+ p += strlen(cm_mountRoot); /* skip mount path */
+ q = p;
+ while (*q) {
+ if (*q == '/') *q = '\\'; /* change to \ */
+ q++;
+ }
while (1)
{
- if (var = smb_stristr(pathName, VNUserName)) {
+ if (var = smb_stristr(p, VNUserName)) {
uidp = smb_FindUID(vcp, ((smb_t *)inp)->uid, 0);
- smb_subst(pathName, var, sizeof(VNUserName),
- uidp->name);
- smb_ReleaseUID(uidp);
+ if (uidp && uidp->unp)
+ smb_subst(p, var, sizeof(VNUserName),
+ uidp->unp->name);
+ else
+ smb_subst(p, var, sizeof(VNUserName),
+ " ");
+ if (uidp)
+ smb_ReleaseUID(uidp);
}
- else if (var = smb_stristr(pathName, VNLCUserName)) {
+ else if (var = smb_stristr(p, VNLCUserName)) {
uidp = smb_FindUID(vcp, ((smb_t *)inp)->uid, 0);
- strcpy(temp, uidp->name);
+ if (uidp && uidp->unp)
+ strcpy(temp, uidp->unp->name);
+ else strcpy(temp, " ");
_strlwr(temp);
- smb_subst(pathName, var, sizeof(VNLCUserName), temp);
- smb_ReleaseUID(uidp);
+ smb_subst(p, var, sizeof(VNLCUserName), temp);
+ if (uidp)
+ smb_ReleaseUID(uidp);
}
- else if (var = smb_stristr(pathName, VNComputerName)) {
+ else if (var = smb_stristr(p, VNComputerName)) {
sizeTemp = sizeof(temp);
GetComputerName((LPTSTR)temp, &sizeTemp);
- smb_subst(pathName, var, sizeof(VNComputerName),
+ smb_subst(p, var, sizeof(VNComputerName),
temp);
}
- else if (var = smb_stristr(pathName, VNLCComputerName)) {
+ else if (var = smb_stristr(p, VNLCComputerName)) {
sizeTemp = sizeof(temp);
GetComputerName((LPTSTR)temp, &sizeTemp);
_strlwr(temp);
- smb_subst(pathName, var, sizeof(VNLCComputerName),
+ smb_subst(p, var, sizeof(VNLCComputerName),
temp);
}
else break;
}
- *pathNamep = strdup(pathName);
+ *pathNamep = strdup(p);
return 1;
}
static smb_packet_t *GetPacket(void)
{
smb_packet_t *tbp;
+#ifdef DJGPP
+ unsigned int npar, seg, tb_sel;
+#endif
+
lock_ObtainWrite(&smb_globalLock);
tbp = smb_packetFreeListp;
- if (tbp) smb_packetFreeListp = tbp->nextp;
+ if (tbp)
+ smb_packetFreeListp = tbp->nextp;
lock_ReleaseWrite(&smb_globalLock);
- if (!tbp) {
- tbp = GlobalAlloc(GMEM_FIXED, 65540);
- tbp->magic = SMB_PACKETMAGIC;
+ if (!tbp) {
+#ifndef DJGPP
+ tbp = calloc(65540,1);
+#else /* DJGPP */
+ tbp = malloc(sizeof(smb_packet_t));
+#endif /* !DJGPP */
+ tbp->magic = SMB_PACKETMAGIC;
tbp->ncbp = NULL;
tbp->vcp = NULL;
tbp->resumeCode = 0;
tbp->oddByte = 0;
tbp->ncb_length = 0;
tbp->flags = 0;
+ tbp->spacep = NULL;
+
+#ifdef DJGPP
+ npar = SMB_PACKETSIZE >> 4; /* number of paragraphs */
+ {
+ signed int retval =
+ __dpmi_allocate_dos_memory(npar, &tb_sel); /* DOS segment */
+ if (retval == -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, retval);
+ seg = retval;
+ }
+ }
+ tbp->dos_pkt = (seg * 16) + 0; /* DOS physical address */
+ tbp->dos_pkt_sel = tb_sel;
+#endif /* DJGPP */
}
-
- osi_assert(tbp->magic == SMB_PACKETMAGIC);
+ osi_assert(tbp->magic == SMB_PACKETMAGIC);
- return tbp;
+ return tbp;
}
smb_packet_t *smb_CopyPacket(smb_packet_t *pkt)
smb_packet_t *tbp;
tbp = GetPacket();
memcpy(tbp, pkt, sizeof(smb_packet_t));
- tbp->wctp = tbp->data + (pkt->wctp - pkt->data);
+ tbp->wctp = tbp->data + ((unsigned int)pkt->wctp - (unsigned int)pkt->data);
return tbp;
}
static NCB *GetNCB(void)
{
smb_ncb_t *tbp;
+ NCB *ncbp;
+#ifdef DJGPP
+ unsigned int npar, seg, tb_sel;
+#endif /* DJGPP */
+
lock_ObtainWrite(&smb_globalLock);
tbp = smb_ncbFreeListp;
- if (tbp) smb_ncbFreeListp = tbp->nextp;
+ if (tbp)
+ smb_ncbFreeListp = tbp->nextp;
lock_ReleaseWrite(&smb_globalLock);
- if (!tbp) {
- tbp = GlobalAlloc(GMEM_FIXED, sizeof(*tbp));
- tbp->magic = SMB_NCBMAGIC;
+ if (!tbp) {
+#ifndef DJGPP
+ tbp = calloc(sizeof(*tbp),1);
+#else /* DJGPP */
+ tbp = malloc(sizeof(*tbp));
+ npar = (sizeof(NCB)+15) >> 4; /* number of paragraphs */
+ {
+ signed int retval =
+ __dpmi_allocate_dos_memory(npar, &tb_sel); /* DOS segment */
+ if (retval == -1) {
+ afsi_log("Cannot allocate %d paragraphs of DOS mem in GetNCB",
+ npar);
+ osi_panic("",__FILE__,__LINE__);
+ } else {
+ afsi_log("Allocated %d paragraphs of DOS mem at 0x%X in GetNCB",
+ npar, retval);
+ seg = retval;
+ }
+ }
+ tbp->dos_ncb = (seg * 16) + 0; /* DOS physical address */
+ tbp->dos_ncb_sel = tb_sel;
+#endif /* !DJGPP */
+ tbp->magic = SMB_NCBMAGIC;
}
- osi_assert(tbp->magic == SMB_NCBMAGIC);
+ osi_assert(tbp->magic == SMB_NCBMAGIC);
memset(&tbp->ncb, 0, sizeof(NCB));
- return &tbp->ncb;
+ ncbp = &tbp->ncb;
+#ifdef DJGPP
+ dos_memset(tbp->dos_ncb, 0, sizeof(NCB));
+#endif /* DJGPP */
+ return ncbp;
}
void smb_FreePacket(smb_packet_t *tbp)
{
- osi_assert(tbp->magic == SMB_PACKETMAGIC);
+ osi_assert(tbp->magic == SMB_PACKETMAGIC);
- lock_ObtainWrite(&smb_globalLock);
+ lock_ObtainWrite(&smb_globalLock);
tbp->nextp = smb_packetFreeListp;
smb_packetFreeListp = tbp;
tbp->magic = SMB_PACKETMAGIC;
tbp->oddByte = 0;
tbp->ncb_length = 0;
tbp->flags = 0;
- lock_ReleaseWrite(&smb_globalLock);
+ lock_ReleaseWrite(&smb_globalLock);
}
static void FreeNCB(NCB *bufferp)
{
smb_ncb_t *tbp;
- tbp = (smb_ncb_t *) bufferp;
- osi_assert(tbp->magic == SMB_NCBMAGIC);
+ tbp = (smb_ncb_t *) bufferp;
+ osi_assert(tbp->magic == SMB_NCBMAGIC);
- lock_ObtainWrite(&smb_globalLock);
+ lock_ObtainWrite(&smb_globalLock);
tbp->nextp = smb_ncbFreeListp;
smb_ncbFreeListp = tbp;
- lock_ReleaseWrite(&smb_globalLock);
+ lock_ReleaseWrite(&smb_globalLock);
}
/* get a ptr to the data part of a packet, and its count */
unsigned char *smb_GetSMBData(smb_packet_t *smbp, int *nbytesp)
{
- int parmBytes;
- int dataBytes;
- unsigned char *afterParmsp;
+ int parmBytes;
+ int dataBytes;
+ unsigned char *afterParmsp;
- parmBytes = *smbp->wctp << 1;
+ parmBytes = *smbp->wctp << 1;
afterParmsp = smbp->wctp + parmBytes + 1;
- dataBytes = afterParmsp[0] + (afterParmsp[1]<<8);
- if (nbytesp) *nbytesp = dataBytes;
+ dataBytes = afterParmsp[0] + (afterParmsp[1]<<8);
+ if (nbytesp) *nbytesp = dataBytes;
/* don't forget to skip the data byte count, since it follows
- * the parameters; that's where the "2" comes from below.
- */
- return (unsigned char *) (afterParmsp + 2);
+ * the parameters; that's where the "2" comes from below.
+ */
+ return (unsigned char *) (afterParmsp + 2);
}
/* must set all the returned parameters before playing around with the
parmCount = *smbp->wctp;
if (parm >= parmCount) {
- HANDLE h;
+#ifndef DJGPP
+ HANDLE h;
char *ptbuf[1];
char s[100];
h = RegisterEventSource(NULL, AFS_DAEMON_EVENT_NAME);
ReportEvent(h, EVENTLOG_ERROR_TYPE, 0, 1006, NULL,
1, smbp->ncb_length, ptbuf, smbp);
DeregisterEventSource(h);
+#else /* DJGPP */
+ 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);
+#endif /* !DJGPP */
osi_panic(s, __FILE__, __LINE__);
}
parmDatap = smbp->wctp + (2*parm) + 1;
parmCount = *smbp->wctp;
if (parm * 2 + offset >= parmCount * 2) {
+#ifndef DJGPP
HANDLE h;
char *ptbuf[1];
char s[100];
ReportEvent(h, EVENTLOG_ERROR_TYPE, 0, 1006, NULL,
1, smbp->ncb_length, ptbuf, smbp);
DeregisterEventSource(h);
+#else /* DJGPP */
+ 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);
+#endif /* !DJGPP */
+
osi_panic(s, __FILE__, __LINE__);
}
parmDatap = smbp->wctp + (2*parm) + 1 + offset;
long code;
unsigned char *tp;
int localNCB = 0;
+#ifdef DJGPP
+ dos_ptr dos_ncb;
+#endif /* DJGPP */
ncbp = inp->ncbp;
if (ncbp == NULL) {
ncbp = GetNCB();
localNCB = 1;
}
+#ifdef DJGPP
+ 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 */
tp = inp->wctp + 1+ extra; /* points to count of data bytes */
extra += tp[0] + (tp[1]<<8);
- extra += (inp->wctp - inp->data); /* distance to last wct field */
+ 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_lana_num = smb_LANadapter;
+ ncbp->ncb_lana_num = vcp->lana;
ncbp->ncb_command = NCBSEND; /* op means send data */
+#ifndef DJGPP
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;
+
+ /* 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)
osi_Log1(afsd_logp, "SendPacket failure code %d", code);
NTStatus = 0xC000000FL; /* No such file */
}
else if (code == CM_ERROR_TIMEDOUT) {
- NTStatus = 0xC00000CFL; /* Paused */
+ NTStatus = 0xC00000CFL; /* Sharing Paused */
}
else if (code == CM_ERROR_RETRY) {
NTStatus = 0xC000022DL; /* Retry */
NTStatus = 0xC00000CCL; /* Bad network name */
}
else if (code == CM_ERROR_NOIPC) {
- NTStatus = 0xC00000CCL; /* Bad network name */
+#ifdef COMMENT
+ NTStatus = 0xC0000022L; /* Access Denied */
+#else
+ NTStatus = 0xC000013DL; /* Remote Resources */
+#endif
}
else if (code == CM_ERROR_CLOCKSKEW) {
NTStatus = 0xC0000133L; /* Time difference at DC */
error = 6;
}
else if (code == CM_ERROR_NOIPC) {
- class = 1;
- error = 66;
+ class = 2;
+ error = 4; /* bad access */
}
else if (code == CM_ERROR_CLOCKSKEW) {
class = 1; /* invalid function */
class = 1;
error = 18; /* no files in search */
}
+ else if (code == CM_ERROR_RENAME_IDENTICAL) {
+ class = 1;
+ error = 183; /* Samba uses this */
+ }
else {
class = 2;
error = 1;
smb_fid_t *fidp;
long code;
cm_user_t *userp = NULL;
- char *rawBuf;
- NCB *ncbp;
+ NCB *ncbp;
+ int rc;
+#ifndef DJGPP
+ char *rawBuf = NULL;
+#else
+ dos_ptr rawBuf = NULL;
+ dos_ptr dos_ncb;
+#endif /* DJGPP */
rawBuf = NULL;
finalCount = 0;
if (!fidp)
goto send1;
- if (fidp->flags & SMB_FID_IOCTL)
- return smb_IoctlReadRaw(fidp, vcp, inp, outp);
-
- userp = smb_GetUser(vcp, inp);
-
lock_ObtainMutex(&smb_RawBufLock);
if (smb_RawBufs) {
/* Get a raw buf, from head of list */
rawBuf = smb_RawBufs;
+#ifndef DJGPP
smb_RawBufs = *(char **)smb_RawBufs;
+#else /* DJGPP */
+ smb_RawBufs = _farpeekl(_dos_ds, smb_RawBufs);
+#endif /* !DJGPP */
}
lock_ReleaseMutex(&smb_RawBufLock);
if (!rawBuf)
- goto send;
+ goto send1a;
+ if (fidp->flags & SMB_FID_IOCTL)
+ {
+#ifndef DJGPP
+ rc = smb_IoctlReadRaw(fidp, vcp, inp, outp);
+#else
+ rc = smb_IoctlReadRaw(fidp, vcp, inp, outp, rawBuf);
+#endif
+ if (rawBuf) {
+ /* Give back raw buffer */
+ lock_ObtainMutex(&smb_RawBufLock);
+#ifndef DJGPP
+ *((char **) rawBuf) = smb_RawBufs;
+#else /* DJGPP */
+ _farpokel(_dos_ds, rawBuf, smb_RawBufs);
+#endif /* !DJGPP */
+
+ smb_RawBufs = rawBuf;
+ lock_ReleaseMutex(&smb_RawBufLock);
+ }
+ return rc;
+ }
+
+ userp = smb_GetUser(vcp, inp);
+
+#ifndef DJGPP
code = smb_ReadData(fidp, &offset, count, rawBuf, userp, &finalCount);
+#else /* DJGPP */
+ /* have to give ReadData flag so it will treat buffer as DOS mem. */
+ code = smb_ReadData(fidp, &offset, count, (unsigned char *)rawBuf,
+ userp, &finalCount, TRUE /* rawFlag */);
+#endif /* !DJGPP */
+
if (code != 0)
goto send;
send:
+ cm_ReleaseUser(userp);
+send1a:
smb_ReleaseFID(fidp);
- cm_ReleaseUser(userp);
send1:
ncbp = outp->ncbp;
+#ifdef DJGPP
+ dos_ncb = ((smb_ncb_t *)ncbp)->dos_ncb;
+#endif /* DJGPP */
memset((char *)ncbp, 0, sizeof(NCB));
ncbp->ncb_length = (unsigned short) finalCount;
ncbp->ncb_lsn = (unsigned char) vcp->lsn;
- ncbp->ncb_lana_num = smb_LANadapter;
+ ncbp->ncb_lana_num = vcp->lana;
ncbp->ncb_command = NCBSEND;
ncbp->ncb_buffer = rawBuf;
+#ifndef DJGPP
code = Netbios(ncbp);
+#else /* DJGPP */
+ code = Netbios(ncbp, dos_ncb);
+#endif /* !DJGPP */
if (code != 0)
osi_Log1(afsd_logp, "ReadRaw send failure code %d", code);
if (rawBuf) {
/* Give back raw buffer */
lock_ObtainMutex(&smb_RawBufLock);
+#ifndef DJGPP
*((char **) rawBuf) = smb_RawBufs;
+#else /* DJGPP */
+ _farpokel(_dos_ds, rawBuf, smb_RawBufs);
+#endif /* !DJGPP */
+
smb_RawBufs = rawBuf;
lock_ReleaseMutex(&smb_RawBufLock);
}
int NTProtoIndex;
int protoIndex; /* index we're using */
int namex;
- long dbytes;
+ int dbytes;
int entryLength;
int tcounter;
char protocol_array[10][1024]; /* protocol signature of the client */
/* compute size of protocol entry */
entryLength = strlen(namep+1);
- entryLength += 2; /* 0x02 bytes and null termination */
+ entryLength += 2; /* 0x02 bytes and null termination */
- /* advance over this protocol entry */
+ /* advance over this protocol entry */
namex += entryLength;
- namep += entryLength;
- tcounter++; /* which proto entry we're looking at */
+ namep += entryLength;
+ tcounter++; /* which proto entry we're looking at */
}
+#ifndef NOMOREFILESFIX
/*
* NOTE: We can determine what OS (NT4.0, W2K, W9X, etc)
* the client is running by reading the protocol signature.
* ie. the order in which it sends us the protocol list.
*
* Special handling for Windows 2000 clients (defect 11765 )
+ * <asanka:11Jun03> Proto signature is the same for Win XP. </>
*/
if (tcounter == 6) {
int i = 0;
*/
}
}
+#endif /* NOMOREFILESFIX */
if (NTProtoIndex != -1) {
protoIndex = NTProtoIndex;
return CM_ERROR_INVAL;
else if (NTProtoIndex != -1) {
smb_SetSMBParm(outp, 0, protoIndex);
- smb_SetSMBParmByte(outp, 1, 0); /* share level security, no passwd encrypt */
- smb_SetSMBParm(outp, 1, 8); /* max multiplexed requests */
- smb_SetSMBParm(outp, 2, 100); /* max VCs per consumer/server connection */
- smb_SetSMBParmLong(outp, 3, SMB_PACKETSIZE); /* xmit buffer size */
+ smb_SetSMBParmByte(outp, 1, 0); /* share level security, no passwd encrypt */
+ smb_SetSMBParm(outp, 1, smb_maxMpxRequests); /* max multiplexed requests */
+ smb_SetSMBParm(outp, 2, smb_maxVCPerServer); /* max VCs per consumer/server connection */
+ smb_SetSMBParmLong(outp, 3, SMB_PACKETSIZE); /* xmit buffer size */
smb_SetSMBParmLong(outp, 5, 65536); /* raw buffer size */
- smb_SetSMBParm(outp, 7, 1); /* next 2: session key */
- smb_SetSMBParm(outp, 8, 1);
+ smb_SetSMBParm(outp, 7, 1); /* next 2: session key */
+ smb_SetSMBParm(outp, 8, 1);
/*
* Tried changing the capabilities to support for W2K - defect 117695
* Maybe something else needs to be changed here?
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, 8); /* max multiplexed requests */
- smb_SetSMBParm(outp, 4, 100); /* max VCs per consumer/server connection */
+ 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);
while(1) {
count++;
- Sleep(10000);
+ thrd_Sleep(10000);
if ((count % 360) == 0) /* every hour */
smb_CalculateNowTZ();
/* XXX GC dir search entries */
nwL = smb_allWaitingLocks;
if (nwL == NULL) {
osi_SleepW((long)&smb_allWaitingLocks, &smb_globalLock);
- Sleep(1000);
+ thrd_Sleep(1000);
continue;
}
else first = 1;
FreeNCB(ncbp);
free(wL);
} while (nwL);
- Sleep(1000);
+ thrd_Sleep(1000);
}
}
/* names starting with a dot are illegal */
if (*tp == '.') valid8Dot3 = 0;
- for(i=0;; i++) {
+ for(i=0;; i++) {
tc = *tp++;
- if (tc == 0) return valid8Dot3;
- if (tc == '.' || tc == '"') break;
- if (i < 8) *up++ = tc;
- else valid8Dot3 = 0;
- }
-
- /* if we get here, tp point after the dot */
- up = maskp+8; /* ext goes here */
- for(i=0;;i++) {
- tc = *tp++;
- if (tc == 0) return valid8Dot3;
-
- /* too many dots */
- if (tc == '.' || tc == '"') valid8Dot3 = 0;
-
- /* copy extension if not too long */
- if (i < 3) *up++ = tc;
- else valid8Dot3 = 0;
- }
+ if (tc == 0) return valid8Dot3;
+ if (tc == '.' || tc == '"') break;
+ if (i < 8) *up++ = tc;
+ else valid8Dot3 = 0;
+ }
+
+ /* if we get here, tp point after the dot */
+ up = maskp+8; /* ext goes here */
+ for(i=0;;i++) {
+ tc = *tp++;
+ if (tc == 0) return valid8Dot3;
+
+ /* too many dots */
+ if (tc == '.' || tc == '"') valid8Dot3 = 0;
+
+ /* copy extension if not too long */
+ if (i < 3) *up++ = tc;
+ else valid8Dot3 = 0;
+ }
+
+ /* unreachable */
}
int smb_Match8Dot3Mask(char *unixNamep, char *maskp)
/* pull pathname and stat block out of request */
tp = smb_GetSMBData(inp, NULL);
- pathp = smb_ParseASCIIBlock(tp, &tp);
+ pathp = smb_ParseASCIIBlock(tp, (char **) &tp);
osi_assert(pathp != NULL);
- statBlockp = smb_ParseVblBlock(tp, &tp, &statLen);
+ statBlockp = smb_ParseVblBlock(tp, (char **) &tp, &statLen);
osi_assert(statBlockp != NULL);
if (statLen == 0) {
statBlockp = initStatBlock;
attr = smb_Attributes(scp);
*dptr++ = attr;
+ /* check hidden attribute (the flag is only ON when dot file hiding is on ) */
+ if( patchp->flags & SMB_DIRLISTPATCH_DOTFILE )
+ attr |= SMB_ATTR_HIDDEN;
+
/* get dos time */
smb_SearchTimeFromUnixTime(&dosTime, scp->clientModTime);
int maxCount;
smb_dirListPatch_t *dirListPatchesp;
smb_dirListPatch_t *curPatchp;
- long dataLength;
+ int dataLength;
cm_buf_t *bufferp;
long temp;
osi_hyper_t dirLength;
int caseFold;
char *tidPathp;
cm_req_t req;
+ cm_fid_t fid;
+ int fileType;
cm_InitReq(&req);
if (attribute & 0x8)
return smb_ReceiveCoreSearchVolume(vcp, inp, outp);
- osi_Log2(afsd_logp, "SMB receive search dir count %d |%s|",
+ osi_Log2(afsd_logp, "SMB receive search dir count %d [%s]",
maxCount, osi_LogSaveString(afsd_logp, pathp));
if (*pathp == 0) { /* null pathp, treat as root dir */
- if (!(attribute & 0x10)) /* exclude dirs */
+ if (!(attribute & SMB_ATTR_DIRECTORY)) /* exclude dirs */
return CM_ERROR_NOFILES;
rootPath = 1;
}
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;
+ }
+
*op++ = resByte;
memcpy(op, mask, 11); op += 11;
*op++ = (char) dsp->cookie; /* they say it must be non-zero */
* 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);
- op += 9; /* skip attr, time, date and size */
+ 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;
+
+ 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.
*/
spacep = inp->spacep;
smb_StripLastComponent(spacep->data, &lastComp, pathp);
- if (strcmp(lastComp, "\\desktop.ini") == 0) {
+ if (lastComp && stricmp(lastComp, "\\desktop.ini") == 0) {
code = cm_NameI(rootScp, spacep->data,
caseFold | CM_FLAG_DIRSEARCH | CM_FLAG_FOLLOW,
userp, tidPathp, &req, &dscp);
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 */
+
if (newScp->fileType == CM_SCACHETYPE_DIRECTORY
|| newScp->fileType == CM_SCACHETYPE_MOUNTPOINT)
- attrs = 0x10;
+ attrs = SMB_ATTR_DIRECTORY;
else
attrs = 0;
if ((newScp->unixModeBits & 0222) == 0 || (newScp->flags & CM_SCACHEFLAG_RO))
- attrs |= 1; /* 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);
cm_InitReq(&req);
- osi_Log0(afsd_logp, "SMB receive open");
-
- 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 open file [%s]", osi_LogSaveString(afsd_logp, pathp));
+
+#ifdef DEBUG_VERBOSE
+ {
+ char *hexpath;
+
+ hexpath = osi_HexifyString( pathp );
+ DEBUG_EVENT2("AFS", "CoreOpen H[%s] A[%s]", hexpath, pathp);
+ free(hexpath);
+ }
+#endif
+
share = smb_GetSMBParm(inp, 0);
attribute = smb_GetSMBParm(inp, 1);
int any;
} smb_unlinkRock_t;
-long smb_UnlinkProc(cm_scache_t *dscp, cm_dirEntry_t *dep, void *vrockp, osi_hyper_t *offp)
+int smb_UnlinkProc(cm_scache_t *dscp, cm_dirEntry_t *dep, void *vrockp, osi_hyper_t *offp)
{
long code;
smb_unlinkRock_t *rockp;
char *newNamep; /* ptr to the new file's name */
} smb_renameRock_t;
-long smb_RenameProc(cm_scache_t *dscp, cm_dirEntry_t *dep, void *vrockp, osi_hyper_t *offp)
+int smb_RenameProc(cm_scache_t *dscp, cm_dirEntry_t *dep, void *vrockp, osi_hyper_t *offp)
{
long code;
smb_renameRock_t *rockp;
smb_renameRock_t rock;
cm_scache_t *oldDscp;
cm_scache_t *newDscp;
+ cm_scache_t *tmpscp;
char *oldLastNamep;
char *newLastNamep;
osi_hyper_t thyper;
rock.hasTilde = ((strchr(oldLastNamep, '~') != NULL) ? 1 : 0);
rock.newNamep = newLastNamep;
- /* now search the dir for the pattern, and do the appropriate rename when
- * found.
- */
+ /* 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*/
+ }
+
+ /* Now search the directory for the pattern, and do the appropriate rename when found */
thyper.LowPart = 0; /* search dir from here */
- thyper.HighPart = 0;
- code = cm_ApplyDir(oldDscp, smb_RenameProc, &rock, &thyper, userp, &req, NULL);
+ thyper.HighPart = 0;
+
+ code = cm_ApplyDir(oldDscp, smb_RenameProc, &rock, &thyper, userp, &req, NULL);
- if (code == CM_ERROR_STOPNOW)
+ if (code == CM_ERROR_STOPNOW)
code = 0;
else if (code == 0)
code = CM_ERROR_NOSUCHFILE;
int any;
} smb_rmdirRock_t;
-long smb_RmdirProc(cm_scache_t *dscp, cm_dirEntry_t *dep, void *vrockp, osi_hyper_t *offp)
+int smb_RmdirProc(cm_scache_t *dscp, cm_dirEntry_t *dep, void *vrockp, osi_hyper_t *offp)
{
long code;
smb_rmdirRock_t *rockp;
char *fullName;
};
-long smb_FullNameProc(cm_scache_t *scp, cm_dirEntry_t *dep, void *rockp,
+int smb_FullNameProc(cm_scache_t *scp, cm_dirEntry_t *dep, void *rockp,
osi_hyper_t *offp)
{
char shortName[13];
/* Don't jump the gun on an async raw write */
while (fidp->raw_writers) {
lock_ReleaseMutex(&fidp->mx);
- WaitForSingleObject(fidp->raw_write_event, RAWTIMEOUT);
+ thrd_WaitForSingleObject_Event(fidp->raw_write_event, RAWTIMEOUT);
lock_ObtainMutex(&fidp->mx);
}
/*
* smb_ReadData -- common code for Read, Read And X, and Raw Read
*/
+#ifndef DJGPP
long smb_ReadData(smb_fid_t *fidp, osi_hyper_t *offsetp, long count, char *op,
cm_user_t *userp, long *readp)
+#else /* DJGPP */
+long smb_ReadData(smb_fid_t *fidp, osi_hyper_t *offsetp, long count, char *op,
+ cm_user_t *userp, long *readp, int dosflag)
+#endif /* !DJGPP */
{
osi_hyper_t offset;
long code;
if (nbytes > count) nbytes = count; /* don't go past EOF */
/* now copy the data */
+#ifdef DJGPP
+ if (dosflag)
+ dosmemput(bufferp->datap + bufIndex, nbytes, (dos_ptr)op);
+ else
+#endif /* DJGPP */
memcpy(op, bufferp->datap + bufIndex, nbytes);
/* adjust counters, pointers, etc. */
/*
* smb_WriteData -- common code for Write and Raw Write
*/
+#ifndef DJGPP
long smb_WriteData(smb_fid_t *fidp, osi_hyper_t *offsetp, long count, char *op,
cm_user_t *userp, long *writtenp)
+#else /* DJGPP */
+long smb_WriteData(smb_fid_t *fidp, osi_hyper_t *offsetp, long count, char *op,
+ cm_user_t *userp, long *writtenp, int dosflag)
+#endif /* !DJGPP */
{
osi_hyper_t offset;
long code;
if (nbytes > count) nbytes = count; /* don't go past end of request */
/* now copy the data */
+#ifdef DJGPP
+ if (dosflag)
+ dosmemget((dos_ptr)op, nbytes, bufferp->datap + bufIndex);
+ else
+#endif /* DJGPP */
memcpy(bufferp->datap + bufIndex, op, nbytes);
buf_SetDirty(bufferp);
cm_user_t *userp;
cm_attr_t truncAttr; /* attribute struct used for truncating file */
char *op;
- long inDataBlockCount;
+ int inDataBlockCount;
fd = smb_GetSMBParm(inp, 0);
count = smb_GetSMBParm(inp, 1);
fidp->scp->clientModTime = time(NULL);
}
+#ifndef DJGPP
code = smb_WriteData(fidp, &offset, count, op, userp, &written);
+#else /* DJGPP */
+ code = smb_WriteData(fidp, &offset, count, op, userp, &written, FALSE);
+#endif /* !DJGPP */
if (code == 0 && written < count)
code = CM_ERROR_PARTIALWRITE;
unsigned short fd;
smb_fid_t *fidp;
cm_user_t *userp;
+#ifndef DJGPP
char *rawBuf;
- int written = 0;
+#else /* DJGPP */
+ dos_ptr rawBuf;
+#endif /* !DJGPP */
+ long written = 0;
long code;
fd = smb_GetSMBParm(inp, 0);
userp = smb_GetUser(vcp, inp);
+#ifndef DJGPP
rawBuf = rwcp->buf;
-
code = smb_WriteData(fidp, &rwcp->offset, rwcp->count, rawBuf, userp,
&written);
+#else /* DJGPP */
+ rawBuf = (dos_ptr) rwcp->buf;
+ code = smb_WriteData(fidp, &rwcp->offset, rwcp->count,
+ (unsigned char *) rawBuf, userp,
+ &written, TRUE);
+#endif /* !DJGPP */
if (rwcp->writeMode & 0x1) { /* synchronous */
smb_t *op;
lock_ObtainMutex(&fidp->mx);
fidp->raw_writers--;
if (fidp->raw_writers == 0)
- SetEvent(fidp->raw_write_event);
+ thrd_SetEvent(fidp->raw_write_event);
lock_ReleaseMutex(&fidp->mx);
}
/* Give back raw buffer */
lock_ObtainMutex(&smb_RawBufLock);
+#ifndef DJGPP
*((char **)rawBuf) = smb_RawBufs;
+#else /* DJGPP */
+ _farpokel(_dos_ds, rawBuf, smb_RawBufs);
+#endif /* !DJGPP */
smb_RawBufs = rawBuf;
lock_ReleaseMutex(&smb_RawBufLock);
cm_user_t *userp;
char *op;
unsigned short writeMode;
+#ifndef DJGPP
char *rawBuf;
+#else /* DJGPP */
+ dos_ptr rawBuf;
+#endif /* !DJGPP */
fd = smb_GetSMBParm(inp, 0);
totalCount = smb_GetSMBParm(inp, 1);
fidp->scp->clientModTime = time(NULL);
}
+#ifndef DJGPP
code = smb_WriteData(fidp, &offset, count, op, userp, &written);
+#else /* DJGPP */
+ code = smb_WriteData(fidp, &offset, count, op, userp, &written, FALSE);
+#endif /* !DJGPP */
if (code == 0 && written < count)
code = CM_ERROR_PARTIALWRITE;
if (smb_RawBufs) {
/* Get a raw buf, from head of list */
rawBuf = smb_RawBufs;
+#ifndef DJGPP
smb_RawBufs = *(char **)smb_RawBufs;
+#else /* DJGPP */
+ smb_RawBufs = _farpeekl(_dos_ds, smb_RawBufs);
+#endif /* !DJGPP */
}
else
code = CM_ERROR_USESTD;
if (code == 0 && (writeMode & 1) == 0) {
lock_ObtainMutex(&fidp->mx);
fidp->raw_writers++;
- ResetEvent(fidp->raw_write_event);
+ thrd_ResetEvent(fidp->raw_write_event);
lock_ReleaseMutex(&fidp->mx);
}
*op++ = (unsigned char) (count & 0xff);
*op++ = (unsigned char) ((count >> 8) & 0xff);
+#ifndef DJGPP
code = smb_ReadData(fidp, &offset, count, op, userp, &finalCount);
+#else /* DJGPP */
+ code = smb_ReadData(fidp, &offset, count, op, userp, &finalCount, FALSE);
+#endif /* !DJGPP */
/* fix some things up */
smb_SetSMBParm(outp, 0, finalCount);
if (!smb_IsLegalFilename(lastNamep))
return CM_ERROR_BADNTFILENAME;
- code = cm_Lookup(dscp, lastNamep, caseFold, userp, &req, &scp);
+ osi_Log1(afsd_logp, "SMB receive create [%s]", osi_LogSaveString( afsd_logp, pathp ));
+#ifdef DEBUG_VERBOSE
+ {
+ char *hexp;
+ hexp = osi_HexifyString( lastNamep );
+ DEBUG_EVENT2("AFS", "CoreCreate H[%s] A[%s]", hexp, lastNamep );
+ free(hexp);
+ }
+#endif
+
+code = cm_Lookup(dscp, lastNamep, caseFold, userp, &req, &scp);
if (code && code != CM_ERROR_NOSUCHFILE) {
cm_ReleaseSCache(dscp);
cm_ReleaseUser(userp);
void smb_DispatchPacket(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp,
NCB *ncbp, raw_write_cont_t *rwcp)
{
- static showErrors = 1;
- smb_dispatch_t *dp;
- smb_t *smbp;
- unsigned long code;
- unsigned char *outWctp;
- int nparms; /* # of bytes of parameters */
- char tbuffer[200];
- int nbytes; /* bytes of data, excluding count */
- int temp;
- unsigned char *tp;
- unsigned short errCode;
+ static showErrors = 0;
+ smb_dispatch_t *dp;
+ smb_t *smbp;
+ unsigned long code;
+ unsigned char *outWctp;
+ int nparms; /* # of bytes of parameters */
+ char tbuffer[200];
+ int nbytes; /* bytes of data, excluding count */
+ int temp;
+ unsigned char *tp;
+ unsigned short errCode;
unsigned long NTStatus;
- int noSend;
- unsigned char errClass;
+ int noSend;
+ unsigned char errClass;
unsigned int oldGen;
DWORD oldTime, newTime;
/* Sanity check */
if (ncbp->ncb_length < offsetof(struct smb, vdata)) {
/* log it and discard it */
+#ifndef DJGPP
HANDLE h;
char *ptbuf[1];
char s[100];
ReportEvent(h, EVENTLOG_WARNING_TYPE, 0, 1007, NULL,
1, ncbp->ncb_length, ptbuf, inp);
DeregisterEventSource(h);
+#else /* DJGPP */
+ osi_Log1(smb_logp, "SMB message too short, len %d",
+ ncbp->ncb_length);
+#endif /* !DJGPP */
+
return;
}
/* We are an ongoing op */
- InterlockedIncrement(&ongoingOps);
+ thrd_Increment(&ongoingOps);
/* set up response packet for receiving output */
if (!(outp->flags & SMB_PACKETFLAG_SUSPENDED))
/* Raw Write */
code = smb_ReceiveCoreWriteRaw (vcp, inp, outp,
rwcp);
- else
- code = (*(dp->procp)) (vcp, inp, outp);
+ 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
HANDLE h;
char *ptbuf[1];
char s[100];
ReportEvent(h, EVENTLOG_WARNING_TYPE, 0,
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);
+#endif /* !DJGPP */
}
}
else {
/* bad opcode, fail the request, after displaying it */
+#ifdef NOTSERVICE
+ smb_LogPacket(inp);
+#endif /* NOTSERVICE */
+
+#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;
}
+#endif /* DJGPP */
code = CM_ERROR_BADOP;
}
/* catastrophic failure: log as much as possible */
if (code == CM_ERROR_BADSMB) {
+#ifndef DJGPP
HANDLE h;
char *ptbuf[1];
char s[100];
ReportEvent(h, EVENTLOG_ERROR_TYPE, 0, 1002, NULL,
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);
+#endif /* !DJGPP */
code = CM_ERROR_INVAL;
}
if (outp->flags & SMB_PACKETFLAG_NOSEND) {
- InterlockedDecrement(&ongoingOps);
+ thrd_Decrement(&ongoingOps);
return;
}
/* tp now points to the new output record; go back and patch the
* second parameter (off2) to point to the new record.
*/
- temp = tp - ((char *) outp->data);
+ 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 */
/* now send the output packet, and return */
if (!noSend)
smb_SendPacket(vcp, outp);
- InterlockedDecrement(&ongoingOps);
+ thrd_Decrement(&ongoingOps);
if (!(vcp->flags & SMB_VCFLAG_ALREADYDEAD)) {
active_vcp = vcp;
return;
}
+#ifndef DJGPP
/* Wait for Netbios() calls to return, and make the results available to server
* threads. Note that server threads can't wait on the NCBevents array
* themselves, because NCB events are manual-reset, and the servers would race
*/
void smb_ClientWaiter(void *parmp)
{
- DWORD code, idx;
+ DWORD code;
+ int idx;
while (1) {
- code = WaitForMultipleObjects(numNCBs, NCBevents,
+ code = thrd_WaitForMultipleObjects_Event(numNCBs, NCBevents,
FALSE, INFINITE);
if (code == WAIT_OBJECT_0)
continue;
- idx = code - WAIT_OBJECT_0;
- ResetEvent(NCBevents[idx]);
- SetEvent(NCBreturns[0][idx]);
+ /* error checking */
+ if (code >= WAIT_ABANDONED_0 && code < (WAIT_ABANDONED_0 + numNCBs))
+ {
+ int abandonIdx = code - WAIT_ABANDONED_0;
+ afsi_log("Error: smb_ClientWaiter event %d abandoned, errno %d\n", abandonIdx, GetLastError());
+ }
+
+ if (code == WAIT_IO_COMPLETION)
+ {
+ afsi_log("Error: smb_ClientWaiter WAIT_IO_COMPLETION\n");
+ continue;
+ }
+
+ if (code == WAIT_TIMEOUT)
+ {
+ afsi_log("Error: smb_ClientWaiter WAIT_TIMEOUT, errno %d\n", GetLastError());
+ }
+
+ if (code == WAIT_FAILED)
+ {
+ afsi_log("Error: smb_ClientWaiter WAIT_FAILED, errno %d\n", GetLastError());
+ }
+
+ idx = code - WAIT_OBJECT_0;
+
+ /* check idx range! */
+ if (idx < 0 || idx > (sizeof(NCBevents) / sizeof(NCBevents[0])))
+ {
+ /* this is fatal - log as much as possible */
+ afsi_log("Fatal: NCBevents idx [ %d ] out of range.\n", idx);
+ osi_assert(0);
+ }
+
+ thrd_ResetEvent(NCBevents[idx]);
+ thrd_SetEvent(NCBreturns[0][idx]);
}
}
+#endif /* !DJGPP */
/*
* Try to have one NCBRECV request waiting for every live session. Not more
*/
void smb_ServerWaiter(void *parmp)
{
- DWORD code, idx_session, idx_NCB;
+ DWORD code;
+ int idx_session, idx_NCB;
NCB *ncbp;
+#ifdef DJGPP
+ dos_ptr dos_ncb;
+#endif /* DJGPP */
while (1) {
/* Get a session */
- code = WaitForMultipleObjects(numSessions, SessionEvents,
- FALSE, INFINITE);
+ code = thrd_WaitForMultipleObjects_Event(numSessions, SessionEvents,
+ FALSE, INFINITE);
if (code == WAIT_OBJECT_0)
continue;
- idx_session = code - WAIT_OBJECT_0;
+
+ if (code >= WAIT_ABANDONED_0 && code < (WAIT_ABANDONED_0 + numSessions))
+ {
+ int abandonIdx = code - WAIT_ABANDONED_0;
+ afsi_log("Error: smb_ServerWaiter (SessionEvents) event %d abandoned, errno %d\n", abandonIdx, GetLastError());
+ }
+
+ if (code == WAIT_IO_COMPLETION)
+ {
+ afsi_log("Error: smb_ServerWaiter (SessionEvents) WAIT_IO_COMPLETION\n");
+ continue;
+ }
+
+ if (code == WAIT_TIMEOUT)
+ {
+ afsi_log("Error: smb_ServerWaiter (SessionEvents) WAIT_TIMEOUT, errno %d\n", GetLastError());
+ }
+
+ if (code == WAIT_FAILED)
+ {
+ afsi_log("Error: smb_ServerWaiter (SessionEvents) WAIT_FAILED, errno %d\n", GetLastError());
+ }
+
+ idx_session = code - WAIT_OBJECT_0;
+
+ /* check idx range! */
+ if (idx_session < 0 || idx_session > (sizeof(SessionEvents) / sizeof(SessionEvents[0])))
+ {
+ /* this is fatal - log as much as possible */
+ afsi_log("Fatal: session idx [ %d ] out of range.\n", idx_session);
+ osi_assert(0);
+ }
/* Get an NCB */
NCBretry:
- code = WaitForMultipleObjects(numNCBs, NCBavails,
- FALSE, INFINITE);
+ code = thrd_WaitForMultipleObjects_Event(numNCBs, NCBavails,
+ FALSE, INFINITE);
if (code == WAIT_OBJECT_0)
goto NCBretry;
- idx_NCB = code - WAIT_OBJECT_0;
+
+ /* error checking */
+ if (code >= WAIT_ABANDONED_0 && code < (WAIT_ABANDONED_0 + numNCBs))
+ {
+ int abandonIdx = code - WAIT_ABANDONED_0;
+ afsi_log("Error: smb_ClientWaiter (NCBavails) event %d abandoned, errno %d\n", abandonIdx, GetLastError());
+ }
+
+ if (code == WAIT_IO_COMPLETION)
+ {
+ afsi_log("Error: smb_ClientWaiter (NCBavails) WAIT_IO_COMPLETION\n");
+ continue;
+ }
+
+ if (code == WAIT_TIMEOUT)
+ {
+ afsi_log("Error: smb_ClientWaiter (NCBavails) WAIT_TIMEOUT, errno %d\n", GetLastError());
+ }
+
+ if (code == WAIT_FAILED)
+ {
+ afsi_log("Error: smb_ClientWaiter (NCBavails) WAIT_FAILED, errno %d\n", GetLastError());
+ }
+
+ idx_NCB = code - WAIT_OBJECT_0;
+
+ /* check idx range! */
+ if (idx_NCB < 0 || idx_NCB > (sizeof(NCBsessions) / sizeof(NCBsessions[0])))
+ {
+ /* this is fatal - log as much as possible */
+ afsi_log("Fatal: idx_NCB [ %d ] out of range.\n", idx_NCB);
+ osi_assert(0);
+ }
/* Link them together */
NCBsessions[idx_NCB] = idx_session;
/* Fire it up */
ncbp = NCBs[idx_NCB];
+#ifdef DJGPP
+ dos_ncb = ((smb_ncb_t *)ncbp)->dos_ncb;
+#endif /* DJGPP */
ncbp->ncb_lsn = (unsigned char) LSNs[idx_session];
ncbp->ncb_command = NCBRECV | ASYNCH;
- ncbp->ncb_lana_num = smb_LANadapter;
+ ncbp->ncb_lana_num = lanas[idx_session];
+#ifndef DJGPP
ncbp->ncb_buffer = (unsigned char *) bufs[idx_NCB];
- ncbp->ncb_length = SMB_PACKETSIZE;
ncbp->ncb_event = NCBevents[idx_NCB];
+ ncbp->ncb_length = SMB_PACKETSIZE;
Netbios(ncbp);
+#else /* DJGPP */
+ ncbp->ncb_buffer = bufs[idx_NCB]->dos_pkt;
+ ((smb_ncb_t*)ncbp)->orig_pkt = bufs[idx_NCB];
+ ncbp->ncb_event = NCBreturns[0][idx_NCB];
+ ncbp->ncb_length = SMB_PACKETSIZE;
+ Netbios(ncbp, dos_ncb);
+#endif /* !DJGPP */
}
}
int myIdx = (int) parmp;
NCB *ncbp;
NCB *outncbp;
- smb_packet_t *bufp;
+ smb_packet_t *bufp;
smb_packet_t *outbufp;
- DWORD code, rcode, idx_NCB, idx_session;
+ DWORD code, rcode;
+ int idx_NCB, idx_session;
UCHAR rc;
smb_vc_t *vcp;
smb_t *smbp;
+#ifdef DJGPP
+ dos_ptr dos_ncb;
+#endif /* DJGPP */
outncbp = GetNCB();
outbufp = GetPacket();
(*smb_MBfunc)(NULL, "AFS demo expiration",
"afsd dispatcher",
MB_OK|MB_ICONSTOP|MB_SETFOREGROUND);
- ExitThread(1);
+ trhd_Exit(1);
}
}
#endif /* !NOEXPIRE */
- code = WaitForMultipleObjects(numNCBs, NCBreturns[myIdx],
- FALSE, INFINITE);
- if (code == WAIT_OBJECT_0)
+ code = thrd_WaitForMultipleObjects_Event(numNCBs, NCBreturns[myIdx],
+ FALSE, INFINITE);
+ if (code == WAIT_OBJECT_0) {
continue;
- idx_NCB = code - WAIT_OBJECT_0;
+ }
+
+ /* error checking */
+ if (code >= WAIT_ABANDONED_0 && code < (WAIT_ABANDONED_0 + numNCBs))
+ {
+ int abandonIdx = code - WAIT_ABANDONED_0;
+ afsi_log("Error: smb_Server ( NCBreturns[%d] ) event %d abandoned, errno %d\n", myIdx, abandonIdx, GetLastError());
+ }
+
+ if (code == WAIT_IO_COMPLETION)
+ {
+ afsi_log("Error: smb_Server ( NCBreturns[%d] ) WAIT_IO_COMPLETION\n", myIdx);
+ continue;
+ }
+
+ if (code == WAIT_TIMEOUT)
+ {
+ afsi_log("Error: smb_Server ( NCBreturns[%d] ) WAIT_TIMEOUT, errno %d\n", myIdx, GetLastError());
+ }
+
+ if (code == WAIT_FAILED)
+ {
+ afsi_log("Error: smb_Server ( NCBreturns[%d] ) WAIT_FAILED, errno %d\n", myIdx, GetLastError());
+ }
+
+ idx_NCB = code - WAIT_OBJECT_0;
+
+ /* check idx range! */
+ if (idx_NCB < 0 || idx_NCB > (sizeof(NCBs) / sizeof(NCBs[0])))
+ {
+ /* this is fatal - log as much as possible */
+ afsi_log("Fatal: idx_NCB [ %d ] out of range.\n", idx_NCB);
+ osi_assert(0);
+ }
ncbp = NCBs[idx_NCB];
+#ifdef DJGPP
+ dos_ncb = ((smb_ncb_t *)ncbp)->dos_ncb;
+#endif /* DJGPP */
idx_session = NCBsessions[idx_NCB];
rc = ncbp->ncb_retcode;
case NRC_PENDING:
/* Can this happen? Or is it just my
- * UNIX paranoia? */
+ * UNIX paranoia?
+ */
continue;
case NRC_SCLOSED:
case NRC_SNUMOUT:
/* Client closed session */
+ if (reportSessionStartups)
+ {
+ afsi_log("session [ %d ] closed", idx_session);
+ }
dead_sessions[idx_session] = TRUE;
- vcp = smb_FindVC(ncbp->ncb_lsn, 0);
+ vcp = smb_FindVC(ncbp->ncb_lsn, 0, lanas[idx_session]);
/* Should also release vcp. Also, would do
- * sanity check that all TID's are gone. */
- if (dead_vcp)
- osi_Log1(afsd_logp,
- "dead_vcp already set, %x",
- dead_vcp);
- if (!dead_vcp
- && !(vcp->flags & SMB_VCFLAG_ALREADYDEAD)) {
- osi_Log2(afsd_logp,
- "setting dead_vcp %x, user struct %x",
- vcp, vcp->usersp);
- dead_vcp = vcp;
- vcp->flags |= SMB_VCFLAG_ALREADYDEAD;
- }
- if (vcp->justLoggedOut) {
- loggedOut = 1;
- loggedOutTime = vcp->logoffTime;
- loggedOutName =
- strdup(vcp->justLoggedOut->name);
- loggedOutUserp = vcp->justLoggedOut;
- lock_ObtainWrite(&smb_rctLock);
- loggedOutUserp->refCount++;
- lock_ReleaseWrite(&smb_rctLock);
- }
+ * sanity check that all TID's are gone.
+ *
+ * TODO: check if we could use LSNs[idx_session] instead,
+ * also cleanup after dead vcp
+ */
+ if (vcp) {
+ if (dead_vcp)
+ osi_Log1(afsd_logp,
+ "dead_vcp already set, %x",
+ dead_vcp);
+ if (!dead_vcp && !(vcp->flags & SMB_VCFLAG_ALREADYDEAD)) {
+ osi_Log2(afsd_logp,
+ "setting dead_vcp %x, user struct %x",
+ vcp, vcp->usersp);
+ dead_vcp = vcp;
+ vcp->flags |= SMB_VCFLAG_ALREADYDEAD;
+ }
+ if (vcp->justLoggedOut) {
+ loggedOut = 1;
+ loggedOutTime = vcp->logoffTime;
+ loggedOutName =
+ strdup(vcp->justLoggedOut->unp->name);
+ loggedOutUserp = vcp->justLoggedOut;
+ lock_ObtainWrite(&smb_rctLock);
+ loggedOutUserp->refCount++;
+ lock_ReleaseWrite(&smb_rctLock);
+ }
+ }
goto doneWithNCB;
case NRC_INCOMP:
/* Treat as transient error */
{
- HANDLE h;
+#ifndef DJGPP
+ EVENT_HANDLE h;
char *ptbuf[1];
char s[100];
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);
+#endif /* !DJGPP */
+
/*
* We used to discard the packet.
* Instead, try handling it normally.
default:
/* A weird error code. Log it, sleep, and
* continue. */
- if (vcp->errorCount++ > 3)
+ if (vcp->errorCount++ > 3) {
+ afsi_log("session [ %d ] closed, vcp->errorCount = %d", idx_session, vcp->errorCount);
dead_sessions[idx_session] = TRUE;
+ }
else {
- Sleep(1000);
- SetEvent(SessionEvents[idx_session]);
+ thrd_Sleep(1000);
+ thrd_SetEvent(SessionEvents[idx_session]);
}
continue;
}
if (smb_concurrentCalls > smb_maxObsConcurrentCalls)
smb_maxObsConcurrentCalls = smb_concurrentCalls;
- vcp = smb_FindVC(ncbp->ncb_lsn, 0);
+ vcp = smb_FindVC(ncbp->ncb_lsn, 0, ncbp->ncb_lana_num);
+ /*
+ * If at this point vcp is NULL (implies that packet was invalid)
+ * then we are in big trouble. This means either :
+ * a) we have the wrong NCB.
+ * b) Netbios screwed up the call.
+ * Obviously this implies that
+ * ( LSNs[idx_session] != ncbp->ncb_lsn ||
+ * lanas[idx_session] != ncbp->ncb_lana_num )
+ * Either way, we can't do anything with this packet.
+ * Log, sleep and resume.
+ */
+ if(!vcp) {
+ HANDLE h;
+ char buf[1000];
+ char *ptbuf[1];
+
+ sprintf(buf,
+ "Bad vcp!! : "
+ "LSNs[idx_session]=[%d],"
+ "lanas[idx_session]=[%d],"
+ "ncbp->ncb_lsn=[%d],"
+ "ncbp->ncb_lana_num=[%d]",
+ LSNs[idx_session],
+ lanas[idx_session],
+ ncbp->ncb_lsn,
+ ncbp->ncb_lana_num);
+
+ ptbuf[0] = buf;
+
+ h = RegisterEventSource(NULL,AFS_DAEMON_EVENT_NAME);
+ if(h) {
+ ReportEvent(h, EVENTLOG_ERROR_TYPE, 0, 1001, NULL,1,sizeof(*ncbp),ptbuf,(void*)ncbp);
+ DeregisterEventSource(h);
+ }
+
+ /* Also log in the trace log. */
+ osi_Log4(afsd_logp, "Server: BAD VCP!"
+ "LSNs[idx_session]=[%d],"
+ "lanas[idx_session]=[%d],"
+ "ncbp->ncb_lsn=[%d],"
+ "ncbp->ncb_lana_num=[%d]",
+ LSNs[idx_session],
+ lanas[idx_session],
+ ncbp->ncb_lsn,
+ ncbp->ncb_lana_num);
+
+ /* thrd_Sleep(1000); Don't bother sleeping */
+ thrd_SetEvent(SessionEvents[idx_session]);
+ smb_concurrentCalls--;
+ continue;
+ }
+
+
vcp->errorCount = 0;
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);
+#endif /* DJGPP */
smbp = (smb_t *)bufp->data;
outbufp->flags = 0;
+#if !defined(DJGPP) && !defined(AFS_WIN32_ENV)
+ __try
+ {
+#endif
if (smbp->com == 0x1d) {
/* Special handling for Write Raw */
raw_write_cont_t rwc;
- HANDLE rwevent;
- smb_DispatchPacket(vcp, bufp, outbufp, ncbp, &rwc);
+ EVENT_HANDLE rwevent;
+ char eventName[MAX_PATH];
+
+ smb_DispatchPacket(vcp, bufp, outbufp, ncbp, &rwc);
if (rwc.code == 0) {
- rwevent = CreateEvent(NULL, FALSE, FALSE, NULL);
+ rwevent = thrd_CreateEvent(NULL, FALSE, FALSE, TEXT("smb_Server() rwevent"));
+ if ( GetLastError() == ERROR_ALREADY_EXISTS )
+ afsi_log("Event Object Already Exists: %s", eventName);
ncbp->ncb_command = NCBRECV | ASYNCH;
ncbp->ncb_lsn = (unsigned char) vcp->lsn;
- ncbp->ncb_lana_num = smb_LANadapter;
+ ncbp->ncb_lana_num = vcp->lana;
ncbp->ncb_buffer = rwc.buf;
ncbp->ncb_length = 65535;
ncbp->ncb_event = rwevent;
+#ifndef DJGPP
Netbios(ncbp);
- rcode = WaitForSingleObject(rwevent,
- RAWTIMEOUT);
- CloseHandle(rwevent);
+#else
+ Netbios(ncbp, dos_ncb);
+#endif /* !DJGPP */
+ rcode = thrd_WaitForSingleObject_Event(rwevent, RAWTIMEOUT);
+ thrd_CloseHandle(rwevent);
}
- SetEvent(SessionEvents[idx_session]);
+ thrd_SetEvent(SessionEvents[idx_session]);
if (rwc.code == 0)
- smb_CompleteWriteRaw(vcp, bufp, outbufp, ncbp,
- &rwc);
+ 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);
- SetEvent(SessionEvents[idx_session]);
+ thrd_SetEvent(SessionEvents[idx_session]);
} else {
- SetEvent(SessionEvents[idx_session]);
+ thrd_SetEvent(SessionEvents[idx_session]);
+ /* TODO: what else needs to be serialized? */
smb_DispatchPacket(vcp, bufp, outbufp, ncbp, NULL);
}
+#if !defined(DJGPP) && !defined(AFS_WIN95_ENV)
+ }
+ __except( smb_ServerExceptionFilter() ) {
+ }
+#endif
smb_concurrentCalls--;
doneWithNCB:
- SetEvent(NCBavails[idx_NCB]);
+ thrd_SetEvent(NCBavails[idx_NCB]);
}
}
/*
+ * Exception filter for the server threads. If an exception occurs in the
+ * dispatch routines, which is where exceptions are most common, then do a
+ * force trace and give control to upstream exception handlers. Useful for
+ * debugging.
+ */
+#if !defined(DJGPP) && !defined(AFS_WIN95_ENV)
+DWORD smb_ServerExceptionFilter(void) {
+ /* While this is not the best time to do a trace, if it succeeds, then
+ * we have a trace (assuming tracing was enabled). Otherwise, this should
+ * throw a second exception.
+ */
+ HANDLE h;
+ char *ptbuf[1];
+
+ ptbuf[0] = "Unhandled exception forcing trace";
+
+ h = RegisterEventSource(NULL,AFS_DAEMON_EVENT_NAME);
+ if(h) {
+ ReportEvent(h, EVENTLOG_ERROR_TYPE, 0, 1001, NULL,1,0,ptbuf,NULL);
+ DeregisterEventSource(h);
+ }
+
+ afsd_ForceTrace(TRUE);
+ return EXCEPTION_CONTINUE_SEARCH;
+}
+#endif
+
+/*
* Create a new NCB and associated events, packet buffer, and "space" buffer.
* If the number of server threads is M, and the number of live sessions is
* N, then the number of NCB's in use at any time either waiting for, or
void InitNCBslot(int idx)
{
struct smb_packet *bufp;
- HANDLE retHandle;
+ EVENT_HANDLE retHandle;
int i;
+ char eventName[MAX_PATH];
+
+ osi_assert( idx < (sizeof(NCBs) / sizeof(NCBs[0])) );
NCBs[idx] = GetNCB();
- NCBavails[idx] = CreateEvent(NULL, FALSE, TRUE, NULL);
- NCBevents[idx] = CreateEvent(NULL, TRUE, FALSE, NULL);
- retHandle = CreateEvent(NULL, FALSE, FALSE, NULL);
+ sprintf(eventName,"NCBavails[%d]", idx);
+ NCBavails[idx] = thrd_CreateEvent(NULL, FALSE, TRUE, eventName);
+ if ( GetLastError() == ERROR_ALREADY_EXISTS )
+ afsi_log("Event Object Already Exists: %s", eventName);
+#ifndef DJGPP
+ sprintf(eventName,"NCBevents[%d]", idx);
+ NCBevents[idx] = thrd_CreateEvent(NULL, TRUE, FALSE, eventName);
+ if ( GetLastError() == ERROR_ALREADY_EXISTS )
+ afsi_log("Event Object Already Exists: %s", eventName);
+#endif /* !DJGPP */
+ sprintf(eventName,"NCBReturns[0<=i<smb_NumServerThreads][%d]", idx);
+ retHandle = thrd_CreateEvent(NULL, FALSE, FALSE, eventName);
+ if ( GetLastError() == ERROR_ALREADY_EXISTS )
+ afsi_log("Event Object Already Exists: %s", eventName);
for (i=0; i<smb_NumServerThreads; i++)
NCBreturns[i][idx] = retHandle;
bufp = GetPacket();
void smb_Listener(void *parmp)
{
NCB *ncbp;
- long code;
- long len;
+ long code;
+ long len;
long i, j;
- smb_vc_t *vcp;
+ smb_vc_t *vcp;
int flags = 0;
char rname[NCBNAMSZ+1];
char cname[MAX_COMPUTERNAME_LENGTH+1];
int cnamelen = MAX_COMPUTERNAME_LENGTH+1;
+#ifdef DJGPP
+ dos_ptr dos_ncb;
+ time_t now;
+#endif /* DJGPP */
+ int lana = (int) parmp;
ncbp = GetNCB();
+#ifdef DJGPP
+ dos_ncb = ((smb_ncb_t *)ncbp)->dos_ncb;
+#endif /* DJGPP */
+
+ /* retrieve computer name */
+ GetComputerName(cname, &cnamelen);
+ _strupr(cname);
while (1) {
+ memset(ncbp, 0, sizeof(NCB));
+ flags = 0;
+#ifdef DJGPP
+ /* terminate if shutdown flag is set */
+ if (smbShutdownFlag == 1)
+ thrd_Exit(1);
+#endif /* DJGPP */
+
#ifndef NOEXPIRE
/* check for demo expiration */
{
strcpy(ncbp->ncb_callname, "*");
for(i=1; i<NCBNAMSZ; i++) ncbp->ncb_callname[i] = ' ';
- ncbp->ncb_lana_num = smb_LANadapter;
+ ncbp->ncb_lana_num = lana;
+#ifndef DJGPP
code = Netbios(ncbp);
+#else /* DJGPP */
+ 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);
+ }
+#endif /* !DJGPP */
+
osi_assert(code == 0);
/* check for remote conns */
break;
}
}
- /* get local name and compare */
- GetComputerName(cname, &cnamelen);
- _strupr(cname);
+
+ /* compare with local name */
if (!isGateway)
if (strncmp(rname, cname, NCBNAMSZ) != 0)
flags |= SMB_VCFLAG_REMOTECONN;
osi_Log1(afsd_logp, "New session lsn %d", ncbp->ncb_lsn);
+ /* lock */
+ lock_ObtainMutex(&smb_ListenerLock);
/* New generation */
sessionGen++;
/* Log session startup */
- if (reportSessionStartups) {
+#ifdef NOTSERVICE
+ fprintf(stderr, "New session(ncb_lsn,ncb_lana_num) %d,%d starting from host "
+ "%s\n",
+ ncbp->ncb_lsn,ncbp->ncb_lana_num, rname);
+#endif
+ afsi_log("New session(ncb_lsn,ncb_lana_num) (%d,%d) starting from host %s, %d ongoing ops",
+ ncbp->ncb_lsn,ncbp->ncb_lana_num, rname, ongoingOps);
+
+ if (reportSessionStartups) {
+#ifndef DJGPP
HANDLE h;
char *ptbuf[1];
char s[100];
ReportEvent(h, EVENTLOG_WARNING_TYPE, 0, 1004, 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);
+ time(&now);
+ fprintf(stderr, "%s: New session %d starting from host "
+ "%s\n",
+ asctime(localtime(&now)), ncbp->ncb_lsn, rname);
+ fflush(stderr);
+#endif /* !DJGPP */
}
- /* now ncbp->ncb_lsn is the connection ID */
- vcp = smb_FindVC(ncbp->ncb_lsn, SMB_FLAG_CREATE);
+ /* now ncbp->ncb_lsn is the connection ID */
+ vcp = smb_FindVC(ncbp->ncb_lsn, SMB_FLAG_CREATE, ncbp->ncb_lana_num);
vcp->flags |= flags;
+ strcpy(vcp->rname, rname);
/* Allocate slot in session arrays */
/* Re-use dead session if possible, otherwise add one more */
- for (i = 0; i < numSessions; i++) {
+ /* But don't look at session[0], it is reserved */
+ for (i = 1; i < numSessions; i++) {
if (dead_sessions[i]) {
+ afsi_log("connecting to dead session [ %d ]", i);
dead_sessions[i] = FALSE;
break;
}
}
+
+ /* assert that we do not exceed the maximum number of sessions or NCBs.
+ * we should probably want to wait for a session to be freed in case
+ * we run out.
+ */
+
+ osi_assert(i < Sessionmax && numNCBs < NCBmax - 1);
+
LSNs[i] = ncbp->ncb_lsn;
+ lanas[i] = ncbp->ncb_lana_num;
+
if (i == numSessions) {
/* Add new NCB for new session */
+ char eventName[MAX_PATH];
+
+ osi_Log1(afsd_logp, "smb_Listener creating new session %d", i);
+
InitNCBslot(numNCBs);
numNCBs++;
- SetEvent(NCBavails[0]);
- SetEvent(NCBevents[0]);
+ thrd_SetEvent(NCBavails[0]);
+ thrd_SetEvent(NCBevents[0]);
for (j = 0; j < smb_NumServerThreads; j++)
- SetEvent(NCBreturns[j][0]);
+ thrd_SetEvent(NCBreturns[j][0]);
/* Also add new session event */
- SessionEvents[i] = CreateEvent(NULL, FALSE, TRUE, NULL);
+ sprintf(eventName, "SessionEvents[%d]", i);
+ SessionEvents[i] = thrd_CreateEvent(NULL, FALSE, TRUE, eventName);
+ if ( GetLastError() == ERROR_ALREADY_EXISTS )
+ afsi_log("Event Object Already Exists: %s", eventName);
numSessions++;
- SetEvent(SessionEvents[0]);
+ afsi_log("increasing numNCBs [ %d ] numSessions [ %d ]", numNCBs, numSessions);
+ thrd_SetEvent(SessionEvents[0]);
} else {
- SetEvent(SessionEvents[i]);
+ thrd_SetEvent(SessionEvents[i]);
}
+ /* unlock */
+ lock_ReleaseMutex(&smb_ListenerLock);
} /* dispatch while loop */
}
+/* initialize Netbios */
+void smb_NetbiosInit()
+{
+ NCB *ncbp;
+#ifdef DJGPP
+ dos_ptr dos_ncb;
+#endif /* DJGPP */
+ int i, lana, code, l;
+ char s[100];
+ int delname_tried=0;
+ int len;
+ int lana_found = 0;
+ OSVERSIONINFO Version;
+
+ /*******************************************************************/
+ /* ms loopback adapter scan */
+ /*******************************************************************/
+ struct
+ {
+ ADAPTER_STATUS status;
+ NAME_BUFFER NameBuff [30];
+ } Adapter;
+
+ int j;
+ BOOL wla_found;
+
+ /* AFAIK, this is the default for the ms loopback adapter.*/
+ unsigned char kWLA_MAC[6] = { 0x02, 0x00, 0x4c, 0x4f, 0x4f, 0x50 };
+ /*******************************************************************/
+
+ /* Get the version of Windows */
+ memset(&Version, 0x00, sizeof(Version));
+ Version.dwOSVersionInfoSize = sizeof(Version);
+ GetVersionEx(&Version);
+
+ /* setup the NCB system */
+ ncbp = GetNCB();
+#ifdef DJGPP
+ dos_ncb = ((smb_ncb_t *)ncbp)->dos_ncb;
+#endif /* DJGPP */
+
+#ifndef DJGPP
+ if (smb_LANadapter == -1) {
+ ncbp->ncb_command = NCBENUM;
+ ncbp->ncb_buffer = (PUCHAR)&lana_list;
+ ncbp->ncb_length = sizeof(lana_list);
+ code = Netbios(ncbp);
+ if (code != 0) {
+ sprintf(s, "Netbios NCBENUM error code %d", code);
+ afsi_log(s);
+ osi_panic(s, __FILE__, __LINE__);
+ }
+ }
+ else {
+ lana_list.length = 1;
+ lana_list.lana[0] = smb_LANadapter;
+ }
+
+ for (i = 0; i < lana_list.length; i++) {
+ /* reset the adaptor: in Win32, this is required for every process, and
+ * acts as an init call, not as a real hardware reset.
+ */
+ ncbp->ncb_command = NCBRESET;
+ ncbp->ncb_callname[0] = 100;
+ ncbp->ncb_callname[2] = 100;
+ ncbp->ncb_lana_num = lana_list.lana[i];
+ code = Netbios(ncbp);
+ if (code == 0)
+ code = ncbp->ncb_retcode;
+ if (code != 0) {
+ sprintf(s, "Netbios NCBRESET lana %d error code %d", lana_list.lana[i], code);
+ afsi_log(s);
+ lana_list.lana[i] = 255; /* invalid lana */
+ } else {
+ sprintf(s, "Netbios NCBRESET lana %d succeeded", lana_list.lana[i]);
+ afsi_log(s);
+ 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
+ */
+ if ( Version.dwPlatformId == VER_PLATFORM_WIN32_NT &&
+ ( 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 */
+ }
+ }
+ }
+ }
+ }
+#else
+ /* for DJGPP, there is no NCBENUM and NCBRESET is a real reset. so
+ we will just fake the LANA list */
+ if (smb_LANadapter == -1) {
+ for (i = 0; i < 8; i++)
+ lana_list.lana[i] = i;
+ lana_list.length = 8;
+ }
+ else {
+ lana_list.length = 1;
+ lana_list.lana[0] = smb_LANadapter;
+ }
+#endif /* !DJGPP */
+
+ /* and declare our name so we can receive connections */
+ memset(ncbp, 0, sizeof(*ncbp));
+ 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; i<NCBNAMSZ; i++) ncbp->ncb_name[i] = ' ';
+#endif
+ sprintf(s, "lana_list.length %d", lana_list.length);
+ afsi_log(s);
+
+ /* Keep the name so we can unregister it later */
+ for (l = 0; l < lana_list.length; l++) {
+ lana = lana_list.lana[l];
+
+ ncbp->ncb_command = NCBADDNAME;
+ ncbp->ncb_lana_num = lana;
+ memcpy(ncbp->ncb_name,smb_sharename,NCBNAMSZ);
+#ifndef DJGPP
+ code = Netbios(ncbp);
+#else /* DJGPP */
+ code = Netbios(ncbp, dos_ncb);
+#endif /* !DJGPP */
+
+ afsi_log("Netbios NCBADDNAME lana=%d code=%d retcode=%d complete=%d",
+ lana, code, ncbp->ncb_retcode,ncbp->ncb_cmd_cplt);
+ {
+ char name[NCBNAMSZ+1];
+ name[NCBNAMSZ]=0;
+ memcpy(name,ncbp->ncb_name,NCBNAMSZ);
+ afsi_log("Netbios NCBADDNAME added new name >%s<",name);
+ }
+
+ if (code == 0) code = ncbp->ncb_retcode;
+ if (code == 0) {
+ afsi_log("Netbios NCBADDNAME succeeded on lana %d\n", lana);
+#ifdef DJGPP
+ /* we only use one LANA with djgpp */
+ lana_list.lana[0] = lana;
+ lana_list.length = 1;
+#endif
+ }
+ else {
+ sprintf(s, "Netbios NCBADDNAME lana %d error code %d", lana, code);
+ afsi_log(s);
+ if (code == NRC_BRIDGE) { /* invalid LANA num */
+ lana_list.lana[l] = 255;
+ continue;
+ }
+ else if (code == NRC_DUPNAME) {
+ afsi_log("Name already exists; try to delete it");
+ memset(ncbp, 0, sizeof(*ncbp));
+ ncbp->ncb_command = NCBDELNAME;
+ memcpy(ncbp->ncb_name,smb_sharename,NCBNAMSZ);
+ ncbp->ncb_lana_num = lana;
+#ifndef DJGPP
+ code = Netbios(ncbp);
+#else
+ code = Netbios(ncbp, dos_ncb);
+#endif /* DJGPP */
+ if (code == 0) code = ncbp->ncb_retcode;
+ else {
+ sprintf(s, "Netbios NCBDELNAME lana %d error code %d\n", lana, code);
+ afsi_log(s);
+ }
+ if (code != 0 || delname_tried) {
+ lana_list.lana[l] = 255;
+ }
+ else if (code == 0) {
+ if (!delname_tried) {
+ lana--;
+ delname_tried = 1;
+ continue;
+ }
+ }
+ }
+ else {
+ sprintf(s, "Netbios NCBADDNAME lana %d error code %d", lana, code);
+ afsi_log(s);
+ lana_list.lana[l] = 255; /* invalid lana */
+ osi_panic(s, __FILE__, __LINE__);
+ }
+ }
+ if (code == 0) {
+ lana_found = 1; /* at least one worked */
+#ifdef DJGPP
+ break;
+#endif
+ }
+ }
+
+ osi_assert(lana_list.length >= 0);
+ if (!lana_found) {
+ sprintf(s, "No valid LANA numbers found!");
+ osi_panic(s, __FILE__, __LINE__);
+ }
+
+ /* we're done with the NCB now */
+ FreeNCB(ncbp);
+}
+
void smb_Init(osi_log_t *logp, char *snamep, int useV3, int LANadapt,
- int nThreads, void *aMBfunc)
+ int nThreads
+#ifndef DJGPP
+ , void *aMBfunc
+#endif
+ )
+
{
- HANDLE phandle;
- long lpid;
- int i;
- long code;
- int len;
- NCB *ncbp;
+ thread_t phandle;
+ int lpid;
+ int i;
+ int len;
struct tm myTime;
- char s[100];
-
+#ifdef DJGPP
+ int npar, seg, sel;
+ dos_ptr rawBuf;
+#endif /* DJGPP */
+ EVENT_HANDLE retHandle;
+ char eventName[MAX_PATH];
+
+#ifndef DJGPP
smb_MBfunc = aMBfunc;
+#endif /* DJGPP */
#ifndef NOEXPIRE
/* check for demo expiration */
{
unsigned long tod = time((void *) 0);
if (tod > EXPIREDATE) {
+#ifndef DJGPP
(*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);
+#endif /* !DJGPP */
}
}
#endif /* !NOEXPIRE */
/* remember the name */
len = strlen(snamep);
- smb_localNamep = malloc(len+1);
- strcpy(smb_localNamep, 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");
/* Raw I/O data structures */
lock_InitializeMutex(&smb_RawBufLock, "smb raw buffer lock");
+ lock_InitializeMutex(&smb_ListenerLock, "smb listener lock");
+
/* 4 Raw I/O buffers */
- smb_RawBufs = GlobalAlloc(GMEM_FIXED, 65536);
+#ifndef DJGPP
+ smb_RawBufs = calloc(65536,1);
*((char **)smb_RawBufs) = NULL;
for (i=0; i<3; i++) {
- char *rawBuf = GlobalAlloc(GMEM_FIXED, 65536);
+ char *rawBuf = calloc(65536,1);
*((char **)rawBuf) = smb_RawBufs;
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<SMB_RAW_BUFS-1; i++) {
+ npar = 65536 >> 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);
+ osi_panic("",__FILE__,__LINE__);
+ }
+ 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;
+ }
+#endif /* !DJGPP */
/* global free lists */
smb_ncbFreeListp = NULL;
smb_packetFreeListp = NULL;
- /* setup the NCB system */
- ncbp = GetNCB();
-
- /* reset the adaptor: in Win32, this is required for every process, and
- * acts as an init call, not as a real hardware reset.
- */
- ncbp->ncb_command = NCBRESET;
- ncbp->ncb_callname[0] = 100;
- ncbp->ncb_callname[2] = 100;
- ncbp->ncb_lana_num = smb_LANadapter;
- code = Netbios(ncbp);
- if (code == 0) code = ncbp->ncb_retcode;
- if (code != 0) {
- sprintf(s, "Netbios NCBRESET error code %d", code);
- afsi_log(s);
- osi_panic(s, __FILE__, __LINE__);
- }
-
- /* and declare our name so we can receive connections */
- memset(ncbp, 0, sizeof(*ncbp));
- ncbp->ncb_lana_num = smb_LANadapter;
- ncbp->ncb_command = NCBADDNAME;
- strncpy(ncbp->ncb_name, snamep, len);
- for(i=len; i<NCBNAMSZ; i++) ncbp->ncb_name[i] = ' ';
- code = Netbios(ncbp);
- if (code == 0) {
- code = ncbp->ncb_retcode;
- }
- if (code != 0) {
- afsi_log("Netbios NCBADDNAME error code %d", code);
- }
-
- /* we're done with the NCB now */
- FreeNCB(ncbp);
+ smb_NetbiosInit();
/* Initialize listener and server structures */
memset(dead_sessions, 0, sizeof(dead_sessions));
- SessionEvents[0] = CreateEvent(NULL, FALSE, FALSE, NULL);
+ sprintf(eventName, "SessionEvents[0]");
+ SessionEvents[0] = thrd_CreateEvent(NULL, FALSE, FALSE, eventName);
+ if ( GetLastError() == ERROR_ALREADY_EXISTS )
+ afsi_log("Event Object Already Exists: %s", eventName);
numSessions = 1;
smb_NumServerThreads = nThreads;
- NCBavails[0] = CreateEvent(NULL, FALSE, FALSE, NULL);
- NCBevents[0] = CreateEvent(NULL, FALSE, FALSE, NULL);
- NCBreturns = malloc(nThreads * sizeof(HANDLE *));
- for (i = 0; i < nThreads; i++) {
- NCBreturns[i] = malloc(NCBmax * sizeof(HANDLE));
- NCBreturns[i][0] = CreateEvent(NULL, FALSE, FALSE, NULL);
+ sprintf(eventName, "NCBavails[0]");
+ NCBavails[0] = thrd_CreateEvent(NULL, FALSE, FALSE, eventName);
+ if ( GetLastError() == ERROR_ALREADY_EXISTS )
+ afsi_log("Event Object Already Exists: %s", eventName);
+ sprintf(eventName, "NCBevents[0]");
+ NCBevents[0] = thrd_CreateEvent(NULL, FALSE, FALSE, eventName);
+ if ( GetLastError() == ERROR_ALREADY_EXISTS )
+ afsi_log("Event Object Already Exists: %s", eventName);
+ NCBreturns = malloc(nThreads * sizeof(EVENT_HANDLE *));
+ sprintf(eventName, "NCBreturns[0<=i<smb_NumServerThreads][0]");
+ retHandle = thrd_CreateEvent(NULL, FALSE, FALSE, eventName);
+ if ( GetLastError() == ERROR_ALREADY_EXISTS )
+ afsi_log("Event Object Already Exists: %s", eventName);
+ for (i = 0; i < smb_NumServerThreads; i++) {
+ NCBreturns[i] = malloc(NCBmax * sizeof(EVENT_HANDLE));
+ NCBreturns[i][0] = retHandle;
}
for (i = 1; i <= nThreads; i++)
InitNCBslot(i);
smb_dispatchTable[0x0b].procp = smb_ReceiveCoreWrite;
smb_dispatchTable[0x0c].procp = smb_ReceiveCoreLockRecord;
smb_dispatchTable[0x0d].procp = smb_ReceiveCoreUnlockRecord;
- smb_dispatchTable[0x0e].procp = smb_SendCoreBadOp;
+ smb_dispatchTable[0x0e].procp = smb_SendCoreBadOp; /* create temporary */
smb_dispatchTable[0x0f].procp = smb_ReceiveCoreCreate;
smb_dispatchTable[0x10].procp = smb_ReceiveCoreCheckPath;
smb_dispatchTable[0x11].procp = smb_SendCoreBadOp; /* process exit */
/* Start listeners, waiters, servers, and daemons */
- phandle = CreateThread(NULL, 65536, (LPTHREAD_START_ROUTINE) smb_Listener,
- NULL, 0, &lpid);
- osi_assert(phandle != NULL);
- CloseHandle(phandle);
+ for (i = 0; i < lana_list.length; i++) {
+ if (lana_list.lana[i] == 255) continue;
+ phandle = thrd_Create(NULL, 65536, (ThreadFunc) smb_Listener,
+ (void*)lana_list.lana[i], 0, &lpid, "smb_Listener");
+ osi_assert(phandle != NULL);
+ thrd_CloseHandle(phandle);
+ }
- phandle = CreateThread(NULL, 65536, (LPTHREAD_START_ROUTINE) smb_ClientWaiter,
- NULL, 0, &lpid);
+#ifndef DJGPP
+ phandle = thrd_Create(NULL, 65536, (ThreadFunc) smb_ClientWaiter,
+ NULL, 0, &lpid, "smb_ClientWaiter");
osi_assert(phandle != NULL);
- CloseHandle(phandle);
+ thrd_CloseHandle(phandle);
+#endif /* !DJGPP */
- phandle = CreateThread(NULL, 65536, (LPTHREAD_START_ROUTINE) smb_ServerWaiter,
- NULL, 0, &lpid);
+ phandle = thrd_Create(NULL, 65536, (ThreadFunc) smb_ServerWaiter,
+ NULL, 0, &lpid, "smb_ServerWaiter");
osi_assert(phandle != NULL);
- CloseHandle(phandle);
+ thrd_CloseHandle(phandle);
for (i=0; i<nThreads; i++) {
- phandle = CreateThread(NULL, 65536,
- (LPTHREAD_START_ROUTINE) smb_Server,
- (void *) i, 0, &lpid);
+ phandle = thrd_Create(NULL, 65536,
+ (ThreadFunc) smb_Server,
+ (void *) i, 0, &lpid, "smb_Server");
osi_assert(phandle != NULL);
- CloseHandle(phandle);
+ thrd_CloseHandle(phandle);
}
- phandle = CreateThread(NULL, 65536, (LPTHREAD_START_ROUTINE) smb_Daemon,
- NULL, 0, &lpid);
+ phandle = thrd_Create(NULL, 65536, (ThreadFunc) smb_Daemon,
+ NULL, 0, &lpid, "smb_Daemon");
osi_assert(phandle != NULL);
- CloseHandle(phandle);
+ thrd_CloseHandle(phandle);
- phandle = CreateThread(NULL, 65536,
- (LPTHREAD_START_ROUTINE) smb_WaitingLocksDaemon,
- NULL, 0, &lpid);
+ phandle = thrd_Create(NULL, 65536,
+ (ThreadFunc) smb_WaitingLocksDaemon,
+ NULL, 0, &lpid, "smb_WaitingLocksDaemon");
osi_assert(phandle != NULL);
- CloseHandle(phandle);
+ thrd_CloseHandle(phandle);
+
+#ifdef DJGPP
+ smb_ListShares();
+#endif
return;
}
+
+#ifdef DJGPP
+void smb_Shutdown(void)
+{
+ NCB *ncbp;
+ dos_ptr dos_ncb;
+ long code;
+ int i;
+
+ /*fprintf(stderr, "Entering smb_Shutdown\n");*/
+
+ /* setup the NCB system */
+ ncbp = GetNCB();
+ dos_ncb = ((smb_ncb_t *)ncbp)->dos_ncb;
+
+ /* Block new sessions by setting shutdown flag */
+ /*smbShutdownFlag = 1;*/
+
+ /* 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, "Session %d Netbios NCBHANGUP error code %d", i, code);
+ }
+ }
+
+#if 1
+ /* Delete Netbios name */
+ for (i = 0; i < lana_list.length; i++) {
+ if (lana_list.lana[i] == 255) continue;
+ ncbp->ncb_command = NCBDELNAME;
+ ncbp->ncb_lana_num = lana_list.lana[i];
+ memcpy(ncbp->ncb_name,smb_sharename,NCBNAMSZ);
+ code = Netbios(ncbp, dos_ncb);
+ if (code == 0) code = ncbp->ncb_retcode;
+ if (code != 0) {
+ fprintf(stderr, "Netbios NCBDELNAME lana %d error code %d",
+ ncbp->ncb_lana_num, code);
+ }
+ fflush(stderr);
+ }
+#endif
+}
+#endif /* DJGPP */
+
+/* Get the UNC \\<servername>\<sharename> prefix. */
+char *smb_GetSharename()
+{
+ char *name;
+
+ /* Make sure we have been properly initialized. */
+ if (smb_localNamep == NULL)
+ return NULL;
+
+ /* Allocate space for \\<servername>\<sharename>, plus the
+ * terminator.
+ */
+ name = malloc(strlen(smb_localNamep) + strlen("ALL") + 4);
+ sprintf(name, "\\\\%s\\%s", smb_localNamep, "ALL");
+ return name;
+}
+
+#ifdef NOTSERVICE
+
+void smb_LogPacket(smb_packet_t *packet)
+{
+ BYTE *vp, *cp;
+ unsigned length, paramlen, datalen, i, j;
+ char buf[81];
+ char hex[]={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
+
+ if(!packet) return;
+
+ osi_Log0(afsd_logp, "*** SMB packet dump ***");
+
+ vp = (BYTE *) packet->data;
+
+ datalen = *((WORD*)(vp + (paramlen = ((unsigned)*(vp+20)) << 1)));
+ length = paramlen + 2 + datalen;
+
+
+ for(i=0;i < length; i+=16)
+ {
+ memset( buf, ' ', 80 );
+ buf[80] = 0;
+
+ itoa( i, buf, 16 );
+
+ buf[strlen(buf)] = ' ';
+
+ cp = (BYTE*) buf + 7;
+
+ for(j=0;j < 16 && (i+j)<length; j++)
+ {
+ *(cp++) = hex[vp[i+j] >> 4];
+ *(cp++) = hex[vp[i+j] & 0xf];
+ *(cp++) = ' ';
+
+ if(j==7)
+ {
+ *(cp++) = '-';
+ *(cp++) = ' ';
+ }
+ }
+
+ for(j=0;j < 16 && (i+j)<length;j++)
+ {
+ *(cp++) = ( 32 <= vp[i+j] && 128 > vp[i+j] )? vp[i+j]:'.';
+ if(j==7)
+ {
+ *(cp++) = ' ';
+ *(cp++) = '-';
+ *(cp++) = ' ';
+ }
+ }
+
+ *cp = 0;
+
+ osi_Log0( afsd_logp, buf );
+ }
+
+ osi_Log0(afsd_logp, "*** End SMB packet dump ***");
+
+}
+
+#endif /* NOTSERVICE */
+
+int smb_DumpVCP(FILE *outputFile, char *cookie)
+{
+ int zilch;
+ char output[1024];
+
+ smb_vc_t *vcp;
+
+ lock_ObtainRead(&smb_rctLock);
+
+ for(vcp = smb_allVCsp; vcp; vcp=vcp->nextp)
+ {
+ smb_fid_t *fidp;
+
+ sprintf(output, "%s vcp=0x%08X, refCount=%d, flags=%d, vcID=%d, lsn=%d, uidCounter=%d, tidCounter=%d, fidCounter=%d\n",
+ cookie, vcp, vcp->refCount, vcp->flags, vcp->vcID, vcp->lsn, vcp->uidCounter, vcp->tidCounter, vcp->fidCounter);
+ WriteFile(outputFile, output, strlen(output), &zilch, NULL);
+
+ for(fidp = vcp->fidsp; fidp; fidp = (smb_fid_t *) osi_QNext(&fidp->q))
+ {
+ sprintf(output, "%s -- fidp=0x%08X, refCount=%d, fid=%d, vcp=0x%08X, scp=0x%08X, ioctlp=0x%08X, NTopen_pathp=%s, NTopen_wholepathp=%s\n",
+ cookie, fidp, fidp->refCount, fidp->fid, fidp->vcp, fidp->scp, fidp->ioctlp,
+ fidp->NTopen_pathp ? fidp->NTopen_pathp : "NULL",
+ fidp->NTopen_wholepathp ? fidp->NTopen_wholepathp : "NULL");
+ WriteFile(outputFile, output, strlen(output), &zilch, NULL);
+ }
+
+ sprintf(output, "done dumping fidsp\n");
+ WriteFile(outputFile, output, strlen(output), &zilch, NULL);
+ }
+
+ lock_ReleaseRead(&smb_rctLock);
+ return 0;
+}
+
+