#include <stdio.h>
#include <stdlib.h>
#include <winsock2.h>
+#include <strsafe.h>
#include <osi.h>
#include "afsd.h"
cm_initparams_v1 cm_initParams;
+char *cm_sysName = 0;
+int cm_sysNameCount = 0;
+char *cm_sysNameList[MAXNUMSYSNAMES];
+
/*
* AFSD Initialization Log
*
afsi_file = INVALID_HANDLE_VALUE;
if (getenv("TEMP"))
{
- strcpy(wd, getenv("TEMP"));
+ StringCbCopyA(wd, sizeof(wd), getenv("TEMP"));
}
else
{
code = GetWindowsDirectory(wd, sizeof(wd));
if (code == 0) return;
}
- strcat(wd, "\\afsd_init.log");
+ StringCbCatA(wd, sizeof(wd), "\\afsd_init.log");
GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, t, sizeof(t));
afsi_file = CreateFile(wd, GENERIC_WRITE, FILE_SHARE_READ, NULL,
OPEN_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL);
SetFilePointer(afsi_file, 0, NULL, FILE_END);
GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, u, sizeof(u));
- strcat(t, ": Create log file\n");
- strcat(u, ": Created log file\n");
+ StringCbCatA(t, sizeof(t), ": Create log file\n");
+ StringCbCatA(u, sizeof(u), ": Created log file\n");
WriteFile(afsi_file, t, strlen(t), &zilch, NULL);
WriteFile(afsi_file, u, strlen(u), &zilch, NULL);
p = "PATH=";
void
afsi_log(char *pattern, ...)
{
- char s[100], t[100], d[100], u[300];
+ char s[256], t[100], d[100], u[512];
int zilch;
va_list ap;
va_start(ap, pattern);
- vsprintf(s, pattern, ap);
+ StringCbVPrintfA(s, sizeof(s), pattern, ap);
if ( afsi_log_useTimestamp ) {
GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, t, sizeof(t));
GetDateFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, d, sizeof(d));
- sprintf(u, "%s %s: %s\n", d, t, s);
+ StringCbPrintfA(u, sizeof(u), "%s %s: %s\n", d, t, s);
if (afsi_file != INVALID_HANDLE_VALUE)
WriteFile(afsi_file, u, strlen(u), &zilch, NULL);
#ifdef NOTSERVICE
return;
len = GetTempPath(sizeof(buf)-10, buf);
- strcpy(&buf[len], "/afsd.log");
+ StringCbCopyA(&buf[len], sizeof(buf)-len, "/afsd.log");
handle = CreateFile(buf, GENERIC_WRITE, FILE_SHARE_READ,
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (handle == INVALID_HANDLE_VALUE) {
long logChunkSize;
long stats;
long traceBufSize;
+ long maxcpus;
long ltt, ltto;
long rx_mtu, rx_nojumbo;
char rootCellName[256];
/*int freelanceEnabled;*/
WSADATA WSAjunk;
lana_number_t lanaNum;
+ int i;
WSAStartup(0x0101, &WSAjunk);
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_ALLOCATE_BUFFER,
NULL, code, 0, (LPTSTR)&msgBuf, 0, NULL);
- sprintf(buf,
+ StringCbPrintfA(buf, sizeof(buf),
"Failure in configuration while opening Registry: %s",
msgBuf);
osi_panic(buf, __FILE__, __LINE__);
}
+ dummyLen = sizeof(maxcpus);
+ code = RegQueryValueEx(parmKey, "MaxCPUs", NULL, NULL,
+ (BYTE *) &maxcpus, &dummyLen);
+ if (code == ERROR_SUCCESS) {
+ HANDLE hProcess;
+ DWORD_PTR processAffinityMask, systemAffinityMask;
+
+ hProcess = OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_SET_INFORMATION,
+ FALSE, GetCurrentProcessId());
+ if ( hProcess != NULL &&
+ GetProcessAffinityMask(hProcess, &processAffinityMask, &systemAffinityMask) )
+ {
+ int i, n, bits;
+ DWORD_PTR mask, newAffinityMask;
+
+#if defined(_WIN64)
+ bits = 64;
+#else
+ bits = 32;
+#endif
+ for ( i=0, n=0, mask=1, newAffinityMask=0; i<bits && n<maxcpus; i++ ) {
+ if ( processAffinityMask & mask ) {
+ newAffinityMask |= mask;
+ n++;
+ }
+ mask *= 2;
+ }
+
+ SetProcessAffinityMask(hProcess, newAffinityMask);
+ CloseHandle(hProcess);
+ afsi_log("CPU Restrictions set to %d cpu(s); %d cpu(s) available", maxcpus, n);
+ } else {
+ afsi_log("CPU Restrictions set to %d cpu(s); unable to access process information", maxcpus);
+ }
+ }
+
dummyLen = sizeof(traceBufSize);
code = RegQueryValueEx(parmKey, "TraceBufferSize", NULL, NULL,
(BYTE *) &traceBufSize, &dummyLen);
if (code == ERROR_SUCCESS)
afsi_log("Root volume %s", cm_rootVolumeName);
else {
- strcpy(cm_rootVolumeName, "root.afs");
+ StringCbCopyA(cm_rootVolumeName, sizeof(cm_rootVolumeName), "root.afs");
afsi_log("Default root volume name root.afs");
}
afsi_log("Mount root %s", cm_mountRoot);
cm_mountRootLen = strlen(cm_mountRoot);
} else {
- strcpy(cm_mountRoot, "/afs");
+ StringCbCopyA(cm_mountRoot, sizeof(cm_mountRoot), "/afs");
cm_mountRootLen = 4;
/* Don't log */
}
else {
GetWindowsDirectory(cm_CachePath, sizeof(cm_CachePath));
cm_CachePath[2] = 0; /* get drive letter only */
- strcat(cm_CachePath, "\\AFSCache");
+ StringCbCatA(cm_CachePath, sizeof(cm_CachePath), "\\AFSCache");
afsi_log("Default cache path %s", cm_CachePath);
}
/* Don't log */
}
- dummyLen = sizeof(cm_sysName);
+ for ( i=0; i < MAXNUMSYSNAMES; i++ ) {
+ cm_sysNameList[i] = osi_Alloc(MAXSYSNAME);
+ cm_sysNameList[i][0] = '\0';
+ }
+ cm_sysName = cm_sysNameList[0];
+
+ dummyLen = MAXSYSNAME;
code = RegQueryValueEx(parmKey, "SysName", NULL, NULL,
cm_sysName, &dummyLen);
if (code == ERROR_SUCCESS)
afsi_log("Sys name %s", cm_sysName);
else {
- strcat(cm_sysName, "i386_nt40");
+ StringCbCopyA(cm_sysName, MAXSYSNAME, "i386_nt40");
afsi_log("Default sys name %s", cm_sysName);
}
+ cm_sysNameCount = 1;
dummyLen = sizeof(cryptall);
code = RegQueryValueEx(parmKey, "SecurityLevel", NULL, NULL,
}
afsi_log("Maximum number of VCs per server is %d", smb_maxVCPerServer);
+ dummyLen = sizeof(smb_authType);
+ code = RegQueryValueEx(parmKey, "SMBAuthType", NULL, NULL,
+ (BYTE *) &smb_authType, &dummyLen);
+
+ if (code != ERROR_SUCCESS ||
+ (smb_authType != SMB_AUTH_EXTENDED && smb_authType != SMB_AUTH_NTLM && smb_authType != SMB_AUTH_NONE)) {
+ smb_authType = SMB_AUTH_EXTENDED; /* default is to use extended authentication */
+ }
+ afsi_log("SMB authentication type is %s", ((smb_authType == SMB_AUTH_NONE)?"NONE":((smb_authType == SMB_AUTH_EXTENDED)?"EXTENDED":"NTLM")));
+
dummyLen = sizeof(rx_nojumbo);
code = RegQueryValueEx(parmKey, "RxNoJumbo", NULL, NULL,
(BYTE *) &rx_nojumbo, &dummyLen);
afsi_log("Using >%s< as SMB server name", cm_NetbiosName);
} else {
/* something went horribly wrong. We can't proceed without a netbios name */
- sprintf(buf,"Netbios name could not be determined: %li", code);
+ StringCbPrintfA(buf,sizeof(buf),"Netbios name could not be determined: %li", code);
osi_panic(buf, __FILE__, __LINE__);
}
/* this should really be in an init daemon from here on down */
if (!cm_freelanceEnabled) {
+ osi_Log0(afsd_logp, "Loading Root Volume from cell");
code = cm_GetVolumeByName(cm_rootCellp, cm_rootVolumeName, cm_rootUserp,
&req, CM_FLAG_CREATE, &cm_rootVolumep);
afsi_log("cm_GetVolumeByName code %x root vol %x", code,