secur32.lib \
ole32.lib \
oleaut32.lib \
- psapi.lib wintrust.lib
+ psapi.lib \
+ wintrust.lib \
+ crypt32.lib
AFSD_EXELIBS =\
$(DESTDIR)\lib\libosi.lib \
#include "cm_buf.h"
#include "cm_freelance.h"
#include "smb_ioctl.h"
+#include "afsd_init.h"
#ifdef DJGPP
#include "afs/afsmsg95.h"
#endif
smb_DumpVCP(afsi_file, "a");
afsi_log("--- end dump ---");
+#ifdef DEBUG
DebugBreak();
+#endif
SetEvent(WaitToTerminate);
return retval;
}
+#define ENCODING (X509_ASN_ENCODING | PKCS_7_ASN_ENCODING)
+
+PCCERT_CONTEXT GetCertCtx(CHAR * filename)
+{
+ wchar_t wfilename[260];
+ BOOL fResult;
+ DWORD dwEncoding;
+ DWORD dwContentType;
+ DWORD dwFormatType;
+ DWORD dwSignerInfo;
+ HCERTSTORE hStore = NULL;
+ HCRYPTMSG hMsg = NULL;
+ PCMSG_SIGNER_INFO pSignerInfo = NULL;
+ PCCERT_CONTEXT pCertContext = NULL;
+ CERT_INFO CertInfo;
+
+ ZeroMemory(&CertInfo, sizeof(CertInfo));
+ mbstowcs(wfilename, filename, 260);
+
+ fResult = CryptQueryObject(CERT_QUERY_OBJECT_FILE,
+ wfilename,
+ CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED,
+ CERT_QUERY_FORMAT_FLAG_BINARY,
+ 0,
+ &dwEncoding,
+ &dwContentType,
+ &dwFormatType,
+ &hStore,
+ &hMsg,
+ NULL);
+
+ if (!fResult) {
+ afsi_log("CryptQueryObject failed for [%s] with error 0x%x",
+ filename,
+ GetLastError());
+ goto __exit;
+ }
+
+ fResult = CryptMsgGetParam(hMsg,
+ CMSG_SIGNER_INFO_PARAM,
+ 0,
+ NULL,
+ &dwSignerInfo);
+
+ if (!fResult) {
+ afsi_log("CryptMsgGetParam failed for [%s] with error 0x%x",
+ filename,
+ GetLastError());
+ goto __exit;
+ }
+
+ pSignerInfo = (PCMSG_SIGNER_INFO)LocalAlloc(LPTR, dwSignerInfo);
+
+ fResult = CryptMsgGetParam(hMsg,
+ CMSG_SIGNER_INFO_PARAM,
+ 0,
+ (PVOID)pSignerInfo,
+ &dwSignerInfo);
+
+ if (!fResult) {
+ afsi_log("CryptMsgGetParam failed for [%s] with error 0x%x",
+ filename,
+ GetLastError());
+ goto __exit;
+ }
+
+ CertInfo.Issuer = pSignerInfo->Issuer;
+ CertInfo.SerialNumber = pSignerInfo->SerialNumber;
+
+ pCertContext = CertFindCertificateInStore(hStore,
+ ENCODING,
+ 0,
+ CERT_FIND_SUBJECT_CERT,
+ (PVOID) &CertInfo,
+ NULL);
+
+ if (!pCertContext) {
+ afsi_log("CertFindCertificateInStore for file [%s] failed with 0x%x",
+ filename,
+ GetLastError());
+ goto __exit;
+ }
+
+ __exit:
+ if (pSignerInfo)
+ LocalFree(pSignerInfo);
+
+ /* if (pCertContext)
+ CertFreeCertificateContext(pCertContext);*/
+
+ if (hStore)
+ CertCloseStore(hStore,0);
+
+ if (hMsg)
+ CryptMsgClose(hMsg);
+
+ return pCertContext;
+}
+
BOOL VerifyTrust(CHAR * filename)
{
- WINTRUST_DATA fTrust;
- WINTRUST_FILE_INFO finfo;
- GUID trustAction = WINTRUST_ACTION_GENERIC_VERIFY_V2;
- GUID subject = WIN_TRUST_SUBJTYPE_RAW_FILEEX;
+ WIN_TRUST_ACTDATA_CONTEXT_WITH_SUBJECT fContextWSubject;
+ WIN_TRUST_SUBJECT_FILE fSubjectFile;
+ GUID trustAction = WIN_SPUB_ACTION_PUBLISHED_SOFTWARE;
+ GUID subject = WIN_TRUST_SUBJTYPE_PE_IMAGE;
wchar_t wfilename[260];
LONG ret;
mbstowcs(wfilename, filename, 260);
- finfo.cbStruct = sizeof(finfo);
- finfo.pcwszFilePath= wfilename;
- finfo.hFile = INVALID_HANDLE_VALUE;
- finfo.pgKnownSubject = &subject;
-
- fTrust.cbStruct = sizeof(fTrust);
- fTrust.pPolicyCallbackData = NULL;
- fTrust.pSIPClientData = NULL;
- fTrust.dwUIChoice = WTD_UI_NONE;
- fTrust.fdwRevocationChecks = WTD_REVOKE_NONE;
- fTrust.dwUnionChoice = WTD_CHOICE_FILE;
- fTrust.pFile = &finfo;
- fTrust.dwStateAction = WTD_STATEACTION_IGNORE;
- fTrust.hWVTStateData = NULL;
- fTrust.pwszURLReference = NULL;
- fTrust.dwProvFlags = WTD_SAFER_FLAG | WTD_REVOCATION_CHECK_NONE;
- fTrust.dwUIContext = WTD_UICONTEXT_EXECUTE;
-
- ret = WinVerifyTrust(INVALID_HANDLE_VALUE, &trustAction, &fTrust);
+ fSubjectFile.hFile = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
+ 0, NULL);
+ fSubjectFile.lpPath = wfilename;
+ fContextWSubject.hClientToken = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
+ FALSE, GetCurrentProcessId());
+ fContextWSubject.SubjectType = &subject;
+ fContextWSubject.Subject = &fSubjectFile;
+
+ ret = WinVerifyTrust(INVALID_HANDLE_VALUE, &trustAction, &fContextWSubject);
+
+ if ( fSubjectFile.hFile != INVALID_HANDLE_VALUE )
+ CloseHandle( fSubjectFile.hFile );
+ if ( fContextWSubject.hClientToken != INVALID_HANDLE_VALUE )
+ CloseHandle( fContextWSubject.hClientToken );
if (ret == ERROR_SUCCESS) {
return TRUE;
}
}
+void LogCertCtx(PCCERT_CONTEXT pCtx) {
+ DWORD dwData;
+ LPTSTR szName = NULL;
+
+ // Get Issuer name size.
+ if (!(dwData = CertGetNameString(pCtx,
+ CERT_NAME_SIMPLE_DISPLAY_TYPE,
+ CERT_NAME_ISSUER_FLAG,
+ NULL,
+ NULL,
+ 0))) {
+ afsi_log("CertGetNameString failed: 0x%x", GetLastError());
+ goto __exit;
+ }
+
+ // Allocate memory for Issuer name.
+ szName = (LPTSTR)LocalAlloc(LPTR, dwData * sizeof(TCHAR));
+
+ // Get Issuer name.
+ if (!(CertGetNameString(pCtx,
+ CERT_NAME_SIMPLE_DISPLAY_TYPE,
+ CERT_NAME_ISSUER_FLAG,
+ NULL,
+ szName,
+ dwData))) {
+ afsi_log("CertGetNameString failed: 0x%x", GetLastError());
+ goto __exit;
+ }
+
+ // print Issuer name.
+ afsi_log("Issuer Name: %s", szName);
+ LocalFree(szName);
+ szName = NULL;
+
+ // Get Subject name size.
+ if (!(dwData = CertGetNameString(pCtx,
+ CERT_NAME_SIMPLE_DISPLAY_TYPE,
+ 0,
+ NULL,
+ NULL,
+ 0))) {
+ afsi_log("CertGetNameString failed: 0x%x", GetLastError());
+ goto __exit;
+ }
+
+ // Allocate memory for subject name.
+ szName = (LPTSTR)LocalAlloc(LPTR, dwData * sizeof(TCHAR));
+
+ // Get subject name.
+ if (!(CertGetNameString(pCtx,
+ CERT_NAME_SIMPLE_DISPLAY_TYPE,
+ 0,
+ NULL,
+ szName,
+ dwData))) {
+ afsi_log("CertGetNameString failed: 0x%x", GetLastError());
+ goto __exit;
+ }
+
+ // Print Subject Name.
+ afsi_log("Subject Name: %s", szName);
+
+ __exit:
+
+ if (szName)
+ LocalFree(szName);
+}
+
BOOL AFSModulesVerify(void)
{
CHAR filename[1024];
DWORD cbNeeded;
unsigned int i;
BOOL success = TRUE;
+ PCCERT_CONTEXT pCtxService = NULL;
if (!GetModuleFileName(NULL, filename, sizeof(filename)))
return FALSE;
trustVerified = VerifyTrust(filename);
+ if (trustVerified) {
+ // get a certificate context for the signer of afsd_service.
+ pCtxService = GetCertCtx(filename);
+ if (pCtxService)
+ LogCertCtx(pCtxService);
+ }
+
// Get a list of all the modules in this process.
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
FALSE, GetCurrentProcessId());
afsi_log("Version mismatch: %s", szModName);
success = FALSE;
}
- if ( trustVerified && !VerifyTrust(szModName) ) {
- afsi_log("Signature Verification failed: %s", szModName);
- success = FALSE;
+ if ( trustVerified ) {
+ if ( !VerifyTrust(szModName) ) {
+ afsi_log("Signature Verification failed: %s", szModName);
+ success = FALSE;
+ }
+ else if (pCtxService) {
+ PCCERT_CONTEXT pCtx = GetCertCtx(szModName);
+
+ if (!pCtx || !CertCompareCertificate(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
+ pCtxService->pCertInfo,
+ pCtx->pCertInfo)) {
+ afsi_log("Certificate mismatch: %s", szModName);
+ if (pCtx)
+ LogCertCtx(pCtx);
+
+ success = FALSE;
+ }
+
+ if (pCtx)
+ CertFreeCertificateContext(pCtx);
+ }
}
}
}
}
}
+ if (pCtxService)
+ CertFreeCertificateContext(pCtxService);
+
CloseHandle(hProcess);
return success;
}
0, 0,
buf_nbuffers * buf_bufferSize);
if (data == NULL) {
+ afsi_log("Error mapping view of file: 0x%X", GetLastError());
if (hf != INVALID_HANDLE_VALUE)
CloseHandle(hf);
CloseHandle(hm);
extern osi_rwlock_t cm_callbackLock;
+extern void cm_CallbackNotifyChange(cm_scache_t *scp);
+
#endif /* _CM_CALLBACK_H_ENV__ */
void cm_GetConfigDir(char *dir)
{
- char wdir[256];
+ char wdir[256];
int tlen;
#ifdef AFS_WIN95_ENV
char *afsconf_path;
extern long cm_GetCellServDB(char *cellNamep);
+extern void cm_GetConfigDir(char *dir);
+
#endif /* __CM_CONFIG_INTERFACES_ONLY__ */
#endif /* __CONFIG_H_ENV_ */
/* called directly from ioctl */
/* called while not holding freelance lock */
-int cm_noteLocalMountPointChange() {
+int cm_noteLocalMountPointChange(void) {
lock_ObtainMutex(&cm_Freelance_Lock);
cm_fakeDirVersion++;
cm_localMountPointChangeFlag = 1;
#endif
if (!fp) {
-#if !defined(DJGPP);
+#if !defined(DJGPP)
RegCloseKey(hkFreelance);
#endif
rootCellName[0] = '.';
long cm_FreelanceAddSymlink(char *filename, char *destination, cm_fid_t *fidp)
{
- FILE *fp;
- char hfile[120];
char line[512];
char fullname[200];
- int n;
int alias = 0;
#if !defined(DJGPP)
HKEY hkFreelanceSymlinks = 0;
long cm_FreelanceRemoveSymlink(char *toremove)
{
- int i, n;
char* cp;
char line[512];
char shortname[200];
- char hfile[120], hfile2[120];
- FILE *fp1, *fp2;
int found=0;
#if !defined(DJGPP)
HKEY hkFreelanceSymlinks = 0;
extern int cm_getLocalMountPointChange();
extern int cm_reInitLocalMountPoints();
extern void cm_InitFreelance();
+extern int cm_noteLocalMountPointChange(void);
extern long cm_FreelanceRemoveMount(char *toremove);
extern long cm_FreelanceAddMount(char *filename, char *cellname, char *volume, int rw, cm_fid_t *fidp);
extern long cm_FreelanceRemoveSymlink(char *toremove);
extern void cm_DiscardSCache(cm_scache_t *scp);
+extern int cm_FindFileType(cm_fid_t *fidp);
+
#endif /* __CM_SCACHE_H_ENV__ */
* Time in Unix format of midnight, 1/1/1970 local time.
* When added to dosUTime, gives Unix (AFS) time.
*/
-long smb_localZero = 0;
+time_t smb_localZero = 0;
/* Time difference for converting to kludge-GMT */
int smb_NowTZ;
}
#endif /* !DJGPP */
-void smb_SearchTimeFromUnixTime(long *dosTimep, time_t unixTime)
+void smb_SearchTimeFromUnixTime(time_t *dosTimep, time_t unixTime)
{
struct tm *ltp;
int dosDate;
unsigned short dosTime;
struct tm localTm;
- dosDate = searchTime & 0xffff;
- dosTime = (searchTime >> 16) & 0xffff;
+ dosDate = (unsigned short) (searchTime & 0xffff);
+ dosTime = (unsigned short) ((searchTime >> 16) & 0xffff);
localTm.tm_year = 80 + ((dosDate>>9) & 0x3f);
localTm.tm_mon = ((dosDate >> 5) & 0xf) - 1; /* January is 0 in localTm */
thrd_Sleep(10000);
if ((count % 72) == 0) { /* every five minutes */
struct tm myTime;
- long old_localZero = smb_localZero;
+ time_t old_localZero = smb_localZero;
/* Initialize smb_localZero */
myTime.tm_isdst = -1; /* compute whether on DST or not */
smb_SearchTimeFromUnixTime(&dosTime, scp->clientModTime);
/* copy out time */
- shortTemp = dosTime & 0xffff;
+ shortTemp = (unsigned short) (dosTime & 0xffff);
*((u_short *)dptr) = shortTemp;
dptr += 2;
/* and copy out date */
- shortTemp = (dosTime>>16) & 0xffff;
+ shortTemp = (unsigned short) ((dosTime>>16) & 0xffff);
*((u_short *)dptr) = shortTemp;
dptr += 2;
smb_SetSMBParm(outp, 0, attrs);
smb_DosUTimeFromUnixTime(&dosTime, newScp->clientModTime);
- smb_SetSMBParm(outp, 1, dosTime & 0xffff);
- smb_SetSMBParm(outp, 2, (dosTime>>16) & 0xffff);
+ smb_SetSMBParm(outp, 1, (unsigned int)(dosTime & 0xffff));
+ smb_SetSMBParm(outp, 2, (unsigned int)((dosTime>>16) & 0xffff));
smb_SetSMBParm(outp, 3, newScp->length.LowPart & 0xffff);
smb_SetSMBParm(outp, 4, (newScp->length.LowPart >> 16) & 0xffff);
smb_SetSMBParm(outp, 5, 0);
smb_SetSMBParm(outp, 0, fidp->fid);
smb_SetSMBParm(outp, 1, smb_Attributes(scp));
smb_DosUTimeFromUnixTime(&dosTime, scp->clientModTime);
- smb_SetSMBParm(outp, 2, dosTime & 0xffff);
- smb_SetSMBParm(outp, 3, (dosTime >> 16) & 0xffff);
+ smb_SetSMBParm(outp, 2, (unsigned int)(dosTime & 0xffff));
+ smb_SetSMBParm(outp, 3, (unsigned int)((dosTime >> 16) & 0xffff));
smb_SetSMBParm(outp, 4, scp->length.LowPart & 0xffff);
smb_SetSMBParm(outp, 5, (scp->length.LowPart >> 16) & 0xffff);
/* pass the open mode back; XXXX add access checks */
writeBackOffset.HighPart, cm_chunkSize, 0, userp);
}
- osi_Log2(smb_logp, "smb_WriteData fid %d returns %d written %d",
+ osi_Log3(smb_logp, "smb_WriteData fid %d returns %d written %d",
fidp->fid, code, *writtenp);
return code;
}
while (1) {
code = thrd_WaitForMultipleObjects_Event(numNCBs, NCBevents,
FALSE, INFINITE);
- if (code == WAIT_OBJECT_0)
- continue;
+ if (code == WAIT_OBJECT_0) {
+ if (smbShutdownFlag == 1)
+ break;
+ else
+ continue;
+ }
/* error checking */
if (code >= WAIT_ABANDONED_0 && code < (WAIT_ABANDONED_0 + numNCBs))
/* Get a session */
code = thrd_WaitForMultipleObjects_Event(numSessions, SessionEvents,
FALSE, INFINITE);
- if (code == WAIT_OBJECT_0)
- continue;
+ if (code == WAIT_OBJECT_0) {
+ if ( smbShutdownFlag == 1 )
+ break;
+ else
+ continue;
+ }
if (code >= WAIT_ABANDONED_0 && code < (WAIT_ABANDONED_0 + numSessions))
{
NCBretry:
code = thrd_WaitForMultipleObjects_Event(numNCBs, NCBavails,
FALSE, INFINITE);
- if (code == WAIT_OBJECT_0)
- goto NCBretry;
+ if (code == WAIT_OBJECT_0) {
+ if ( smbShutdownFlag == 1 )
+ break;
+ else
+ goto NCBretry;
+ }
/* error checking */
if (code >= WAIT_ABANDONED_0 && code < (WAIT_ABANDONED_0 + numNCBs))
/* 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 = lanas[idx_session];
((smb_ncb_t*)ncbp)->orig_pkt = bufs[idx_NCB];
ncbp->ncb_event = NCBreturns[0][idx_NCB];
ncbp->ncb_length = SMB_PACKETSIZE;
+ dos_ncb = ((smb_ncb_t *)ncbp)->dos_ncb;
Netbios(ncbp, dos_ncb);
#endif /* !DJGPP */
}
while (1) {
code = thrd_WaitForMultipleObjects_Event(numNCBs, NCBreturns[myIdx],
FALSE, INFINITE);
+
+ /* terminate silently if shutdown flag is set */
if (code == WAIT_OBJECT_0) {
- continue;
+ if (smbShutdownFlag == 1)
+ break;
+ else
+ continue;
}
/* error checking */
* Either way, we can't do anything with this packet.
* Log, sleep and resume.
*/
- if(!vcp) {
+ if (!vcp) {
HANDLE h;
char buf[1000];
char *ptbuf[1];
ptbuf[0] = buf;
h = RegisterEventSource(NULL,AFS_DAEMON_EVENT_NAME);
- if(h) {
+ if (h) {
ReportEvent(h, EVENTLOG_ERROR_TYPE, 0, 1001, NULL,1,sizeof(*ncbp),ptbuf,(void*)ncbp);
DeregisterEventSource(h);
}
#ifndef DJGPP
code = Netbios(ncbp);
#else
- code = Netbios(ncbp, dos_ncb);
+ code = Netbios(ncbp, dos_ncb);
#endif
/*fprintf(stderr, "returned from NCBHANGUP session %d LSN %d\n", i, LSNs[i]);*/
if (code == 0) code = ncbp->ncb_retcode;
}
fflush(stderr);
}
+
+ /* Trigger the shutdown of all SMB threads */
+ for (i = 0; i < numSessions; i++)
+ thrd_SetEvent(NCBreturns[i][0]);
+
+ thrd_SetEvent(NCBevents[0]);
+ thrd_SetEvent(SessionEvents[0]);
+ thrd_SetEvent(NCBavails[0]);
+ thrd_Sleep(1000);
}
/* Get the UNC \\<servername>\<sharename> prefix. */
extern char *smb_GetSharename(void);
+extern DWORD smb_ServerExceptionFilter(void);
+
/* include other include files */
#include "smb3.h"
#include "smb_ioctl.h"