internal LogStream(string path, int bufferSize, LogRetentionOption retention, long maxFileSize, int maxNumOfFiles) { string fullPath = Path.GetFullPath(path); this._fileName = fullPath; if (fullPath.StartsWith(@"\\.\", StringComparison.Ordinal)) { throw new NotSupportedException(System.SR.GetString("NotSupported_IONonFileDevices")); } Microsoft.Win32.UnsafeNativeMethods.SECURITY_ATTRIBUTES secAttrs = GetSecAttrs(FileShare.Read); int num = 0x100000; this._canWrite = true; this._pathSav = fullPath; this._fAccessSav = 0x40000000; this._shareSav = FileShare.Read; this._secAttrsSav = secAttrs; this._secAccessSav = FileIOPermissionAccess.Write; this._modeSav = (retention != LogRetentionOption.SingleFileUnboundedSize) ? FileMode.Create : FileMode.OpenOrCreate; this._flagsAndAttributesSav = num; this._seekToEndSav = retention == LogRetentionOption.SingleFileUnboundedSize; base.bufferSize = bufferSize; this._retention = retention; this._maxFileSize = maxFileSize; this._maxNumberOfFiles = maxNumOfFiles; this._Init(fullPath, this._fAccessSav, this._shareSav, this._secAttrsSav, this._secAccessSav, this._modeSav, this._flagsAndAttributesSav, this._seekToEndSav); }
internal LogStream(String path, int bufferSize, LogRetentionOption retention, long maxFileSize, int maxNumOfFiles) { Debug.Assert(!String.IsNullOrEmpty(path)); // Get absolute path - Security needs this to prevent something // like trying to create a file in c:\tmp with the name // "..\WinNT\System32\ntoskrnl.exe". Store it for user convenience. //String filePath = Path.GetFullPathInternal(path); String filePath = Path.GetFullPath(path); _fileName = filePath; // Prevent access to your disk drives as raw block devices. if (filePath.StartsWith("\\\\.\\", StringComparison.Ordinal)) { throw new NotSupportedException(SR.GetString(SR.NotSupported_IONonFileDevices)); } UnsafeNativeMethods.SECURITY_ATTRIBUTES secAttrs = GetSecAttrs(FileShare.Read); // For mitigating local elevation of privilege attack through named pipes // make sure we always call CreateFile with SECURITY_ANONYMOUS so that the // named pipe server can't impersonate a high privileged client security context int flagsAndAttributes = (int)FileOptions.None | (UnsafeNativeMethods.SECURITY_SQOS_PRESENT | UnsafeNativeMethods.SECURITY_ANONYMOUS); // Only write is enabled //_canRead = false; //_canSeek = false; _canWrite = true; _pathSav = filePath; _fAccessSav = UnsafeNativeMethods.GENERIC_WRITE; _shareSav = FileShare.Read; _secAttrsSav = secAttrs; _secAccessSav = FileIOPermissionAccess.Write; _modeSav = (retention != LogRetentionOption.SingleFileUnboundedSize)? FileMode.Create : FileMode.OpenOrCreate; _flagsAndAttributesSav = flagsAndAttributes; _seekToEndSav = (retention != LogRetentionOption.SingleFileUnboundedSize)? false : true; this.bufferSize = bufferSize; _retention = retention; _maxFileSize = maxFileSize; _maxNumberOfFiles = maxNumOfFiles; _Init(filePath, _fAccessSav, _shareSav, _secAttrsSav, _secAccessSav, _modeSav, _flagsAndAttributesSav, _seekToEndSav); }
internal LogStream(String path, int bufferSize, LogRetentionOption retention, long maxFileSize, int maxNumOfFiles) { Debug.Assert(!String.IsNullOrEmpty(path)); // Get absolute path - Security needs this to prevent something // like trying to create a file in c:\tmp with the name // "..\WinNT\System32\ntoskrnl.exe". Store it for user convenience. //String filePath = Path.GetFullPathInternal(path); String filePath = Path.GetFullPath(path); _fileName = filePath; // Prevent access to your disk drives as raw block devices. if (filePath.StartsWith("\\\\.\\", StringComparison.Ordinal)) throw new NotSupportedException(SR.GetString(SR.NotSupported_IONonFileDevices)); UnsafeNativeMethods.SECURITY_ATTRIBUTES secAttrs = GetSecAttrs(FileShare.Read); // For mitigating local elevation of privilege attack through named pipes // make sure we always call CreateFile with SECURITY_ANONYMOUS so that the // named pipe server can't impersonate a high privileged client security context int flagsAndAttributes = (int)FileOptions.None | (UnsafeNativeMethods.SECURITY_SQOS_PRESENT | UnsafeNativeMethods.SECURITY_ANONYMOUS); // Only write is enabled //_canRead = false; //_canSeek = false; _canWrite = true; _pathSav = filePath; _fAccessSav = UnsafeNativeMethods.GENERIC_WRITE; _shareSav = FileShare.Read; _secAttrsSav = secAttrs; _secAccessSav = FileIOPermissionAccess.Write; _modeSav = (retention != LogRetentionOption.SingleFileUnboundedSize)? FileMode.Create : FileMode.OpenOrCreate; _flagsAndAttributesSav = flagsAndAttributes; _seekToEndSav = (retention != LogRetentionOption.SingleFileUnboundedSize)? false : true; this.bufferSize = bufferSize; _retention = retention; _maxFileSize = maxFileSize; _maxNumberOfFiles = maxNumOfFiles; _Init(filePath, _fAccessSav, _shareSav, _secAttrsSav, _secAccessSav, _modeSav, _flagsAndAttributesSav, _seekToEndSav); }