int code;
afsi_file = INVALID_HANDLE_VALUE;
- code = GetWindowsDirectory(wd, sizeof(wd));
- if (code == 0) return;
+ if (getenv("TEMP"))
+ {
+ strcpy(wd, getenv("TEMP"));
+ }
+ else
+ {
+ code = GetWindowsDirectory(wd, sizeof(wd));
+ if (code == 0) return;
+ }
strcat(wd, "\\afsd_init.log");
GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, t, sizeof(t));
afsi_file = CreateFile(wd, GENERIC_WRITE, FILE_SHARE_READ, NULL,
void
afsi_log(char *pattern, ...)
{
- char s[100], t[100], u[100];
+ char s[100], t[100], d[100], u[100];
int zilch;
va_list ap;
va_start(ap, pattern);
vsprintf(s, pattern, ap);
if ( afsi_log_useTimestamp ) {
GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, t, sizeof(t));
- sprintf(u, "%s: %s\n", t, s);
+ GetDateFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, d, sizeof(d));
+ sprintf(u, "%s %s: %s\n", d, t, s);
if (afsi_file != INVALID_HANDLE_VALUE)
WriteFile(afsi_file, u, strlen(u), &zilch, NULL);
#ifdef NOTSERVICE
srand(ntohl(cm_HostAddr));
/* Look up configuration parameters in Registry */
-
code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSConfigKeyName,
0, KEY_QUERY_VALUE, &parmKey);
if (code != ERROR_SUCCESS) {
offset = 0;
- afsi_log("\n--# FV EIP----- RetAddr- FramePtr StackPtr Symbol\n" );
+ afsi_log("\n--# FV EIP----- RetAddr- FramePtr StackPtr Symbol" );
for ( frameNum = 0; ; ++ frameNum )
{
if ( s.AddrPC.Offset == 0 )
{
- afsi_log("(-nosymbols- PC == 0)\n" );
+ afsi_log("(-nosymbols- PC == 0)" );
}
else
{
{
if ( GetLastError() != ERROR_INVALID_ADDRESS )
{
- afsi_log("SymGetSymFromAddr(): errno = %lu\n",
+ afsi_log("SymGetSymFromAddr(): errno = %lu",
GetLastError());
}
}
if ( offset != 0 )
{
- afsi_log(" %+ld bytes\n", (long) offset);
+ afsi_log(" %+ld bytes", (long) offset);
}
}
{
if (GetLastError() != ERROR_INVALID_ADDRESS)
{
- afsi_log("Error: SymGetLineFromAddr(): errno = %lu\n",
+ afsi_log("Error: SymGetLineFromAddr(): errno = %lu",
GetLastError());
}
}
else
{
- afsi_log(" Line: %s(%lu) %+ld bytes\n", Line.FileName,
+ afsi_log(" Line: %s(%lu) %+ld bytes", Line.FileName,
Line.LineNumber, offset);
}
-
}
/* no return address means no deeper stackframe */
if (ep->ExceptionRecord->ExceptionCode == EXCEPTION_BREAKPOINT)
{
- afsi_log("EXCEPTION_BREAKPOINT - continue execition ...\n");
+ afsi_log("\nEXCEPTION_BREAKPOINT - continue execition ...\n");
#ifdef _DEBUG
if (allocRequestBrk)
unsigned int sessionGen = 0;
extern void afsi_log(char *pattern, ...);
+extern HANDLE afsi_file;
osi_hyper_t hzero = {0, 0};
osi_hyper_t hones = {0xFFFFFFFF, -1};
int smb_maxVCPerServer;
int smb_maxMpxRequests;
-#define NCBmax 100
+#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
+#define Sessionmax MAXIMUM_WAIT_OBJECTS
EVENT_HANDLE SessionEvents[Sessionmax];
unsigned short LSNs[Sessionmax];
int lanas[Sessionmax];
*(sizep) = strlen(cm_HostName)
#endif /* DJGPP */
+extern char AFSConfigKeyName[];
+
/*
* Demo expiration
*
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;
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 */
smb_user_t *uidp;
char temp[1024];
DWORD sizeTemp;
- char sbmtpath[256];
- char *p, *q;
+ 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 */
*/
void smb_ClientWaiter(void *parmp)
{
- DWORD code, idx;
+ DWORD code;
+ int idx;
while (1) {
code = thrd_WaitForMultipleObjects_Event(numNCBs, NCBevents,
FALSE, INFINITE);
if (code == WAIT_OBJECT_0)
continue;
- idx = 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 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]);
}
*/
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;
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:
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;
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;
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
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, lanas[idx_session]);
/* Should also release vcp. Also, would do
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 {
thrd_Sleep(1000);
thrd_SetEvent(SessionEvents[idx_session]);
EVENT_HANDLE retHandle;
int i;
+ osi_assert( idx < (sizeof(NCBs) / sizeof(NCBs[0])) );
+
NCBs[idx] = GetNCB();
NCBavails[idx] = thrd_CreateEvent(NULL, FALSE, TRUE, NULL);
#ifndef DJGPP
/* Log session startup */
#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);
+ 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
- if (reportSessionStartups) {
+ 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];
#endif /* !DJGPP */
}
- /* now ncbp->ncb_lsn is the connection ID */
- vcp = smb_FindVC(ncbp->ncb_lsn, SMB_FLAG_CREATE, ncbp->ncb_lana_num);
+ /* 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);
+ strcpy(vcp->rname, rname);
/* Allocate slot in session arrays */
/* Re-use dead session if possible, otherwise add one more */
/* 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;
}
/* Also add new session event */
SessionEvents[i] = thrd_CreateEvent(NULL, FALSE, TRUE, NULL);
numSessions++;
+ afsi_log("increasing numNCBs [ %d ] numSessions [ %d ]", numNCBs, numSessions);
thrd_SetEvent(SessionEvents[0]);
} else {
thrd_SetEvent(SessionEvents[i]);
if (code == 0) code = ncbp->ncb_retcode;
if (code == 0) {
- afsi_log("Netbios NCBADDNAME succeeded on lana %d", lana);
+ afsi_log("Netbios NCBADDNAME succeeded on lana %d\n", lana);
#ifdef DJGPP
/* we only use one LANA with djgpp */
lana_list.lana[0] = lana;
int totalParms, int totalData)
{
smb_tran2Packet_t *tp;
- smb_t *smbp;
+ smb_t *smbp;
- smbp = (smb_t *) inp->data;
+ smbp = (smb_t *) inp->data;
tp = malloc(sizeof(*tp));
- memset(tp, 0, sizeof(*tp));
- tp->vcp = vcp;
- smb_HoldVC(vcp);
- tp->curData = tp->curParms = 0;
- tp->totalData = totalData;
- tp->totalParms = totalParms;
- tp->tid = smbp->tid;
- tp->mid = smbp->mid;
- tp->uid = smbp->uid;
- tp->pid = smbp->pid;
+ memset(tp, 0, sizeof(*tp));
+ tp->vcp = vcp;
+ smb_HoldVC(vcp);
+ tp->curData = tp->curParms = 0;
+ tp->totalData = totalData;
+ tp->totalParms = totalParms;
+ tp->tid = smbp->tid;
+ tp->mid = smbp->mid;
+ tp->uid = smbp->uid;
+ tp->pid = smbp->pid;
tp->res[0] = smbp->res[0];
osi_QAdd((osi_queue_t **)&smb_tran2AssemblyQueuep, &tp->q);
- tp->opcode = smb_GetSMBParm(inp, 14);
+ tp->opcode = smb_GetSMBParm(inp, 14);
if (totalParms != 0)
- tp->parmsp = malloc(totalParms);
+ tp->parmsp = malloc(totalParms);
if (totalData != 0)
- tp->datap = malloc(totalData);
+ tp->datap = malloc(totalData);
tp->flags |= SMB_TRAN2PFLAG_ALLOC;
- return tp;
+ return tp;
}
smb_tran2Packet_t *smb_GetTran2ResponsePacket(smb_vc_t *vcp,
/* free a tran2 packet; must be called with smb_globalLock held */
void smb_FreeTran2Packet(smb_tran2Packet_t *t2p)
{
- if (t2p->vcp) smb_ReleaseVC(t2p->vcp);
+ if (t2p->vcp) smb_ReleaseVC(t2p->vcp);
if (t2p->flags & SMB_TRAN2PFLAG_ALLOC) {
if (t2p->parmsp)
free(t2p->parmsp);
if (t2p->datap)
free(t2p->datap);
}
- free(t2p);
+ free(t2p);
}
/* called with a VC, an input packet to respond to, and an error code.
fidp = smb_FindFID(vcp, fid, 0);
- osi_Log4(afsd_logp, "Request for NotifyChange filter 0x%x fid %d wtree %d file %s",
- filter, fid, watchtree, osi_LogSaveString(afsd_logp, fidp->NTopen_wholepathp));
+ if (fidp) {
+ osi_Log4(afsd_logp, "Request for NotifyChange filter 0x%x fid %d wtree %d file %s",
+ filter, fid, watchtree, osi_LogSaveString(afsd_logp, fidp->NTopen_wholepathp));
- scp = fidp->scp;
- lock_ObtainMutex(&scp->mx);
- if (watchtree)
- scp->flags |= CM_SCACHEFLAG_WATCHEDSUBTREE;
- else
- scp->flags |= CM_SCACHEFLAG_WATCHED;
- lock_ReleaseMutex(&scp->mx);
- smb_ReleaseFID(fidp);
+ scp = fidp->scp;
+ lock_ObtainMutex(&scp->mx);
+ if (watchtree)
+ scp->flags |= CM_SCACHEFLAG_WATCHEDSUBTREE;
+ else
+ scp->flags |= CM_SCACHEFLAG_WATCHED;
+ lock_ReleaseMutex(&scp->mx);
+ smb_ReleaseFID(fidp);
+ }
+ else
+ {
+ /* nothing - just a warning to main log file ... */
+ afsi_log("Warning: cannot find fidp vcp = 0x%X, fid = %d", vcp, fid);
+ }
outp->flags |= SMB_PACKETFLAG_NOSEND;