本文整理汇总了C#中System.IO.Pipes.PipeSecurity.SetOwner方法的典型用法代码示例。如果您正苦于以下问题:C# PipeSecurity.SetOwner方法的具体用法?C# PipeSecurity.SetOwner怎么用?C# PipeSecurity.SetOwner使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.Pipes.PipeSecurity
的用法示例。
在下文中一共展示了PipeSecurity.SetOwner方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateServerStream
static NamedPipeServerStream CreateServerStream()
{
var user = WindowsIdentity.GetCurrent().User;
var security = new PipeSecurity();
security.AddAccessRule( new PipeAccessRule( user, PipeAccessRights.FullControl, AccessControlType.Allow ) );
security.SetOwner( user );
security.SetGroup( user );
IncrementServers();
try
{
return new NamedPipeServerStream(
ProtocolConstants.PipeName,
PipeDirection.InOut,
20,
PipeTransmissionMode.Byte,
PipeOptions.Asynchronous,
CommandLineLength,
CommandLineLength,
security );
}
catch ( Exception )
{
DecrementServers();
throw;
}
}
示例2: InternalConstruct
/// <summary>
/// Instantiates an endpoint to act as a client
/// </summary>
/// <param name="pipeName">The name of the pipe to which we should connect.</param>
internal void InternalConstruct(string pipeName)
{
ErrorUtilities.VerifyThrowArgumentLength(pipeName, "pipeName");
_debugCommunications = (Environment.GetEnvironmentVariable("MSBUILDDEBUGCOMM") == "1");
_status = LinkStatus.Inactive;
_asyncDataMonitor = new object();
_sharedReadBuffer = InterningBinaryReader.CreateSharedBuffer();
SecurityIdentifier identifier = WindowsIdentity.GetCurrent().Owner;
PipeSecurity security = new PipeSecurity();
// Restrict access to just this account. We set the owner specifically here, and on the
// pipe client side they will check the owner against this one - they must have identical
// SIDs or the client will reject this server. This is used to avoid attacks where a
// hacked server creates a less restricted pipe in an attempt to lure us into using it and
// then sending build requests to the real pipe client (which is the MSBuild Build Manager.)
PipeAccessRule rule = new PipeAccessRule(identifier, PipeAccessRights.ReadWrite, AccessControlType.Allow);
security.AddAccessRule(rule);
security.SetOwner(identifier);
_pipeServer = new NamedPipeServerStream
(
pipeName,
PipeDirection.InOut,
1, // Only allow one connection at a time.
PipeTransmissionMode.Byte,
PipeOptions.Asynchronous | PipeOptions.WriteThrough,
PipeBufferSize, // Default input buffer
PipeBufferSize, // Default output buffer
security,
HandleInheritability.None
);
}
示例3: DispatchConnection
/// <summary>
/// Checks to see if memory is available, and if it is creates a new
/// Connection object, awaits the completion of the connection, then
/// runs <see cref="ConnectionCompleted"/> for cleanup.
/// </summary>
private async Task DispatchConnection(NamedPipeServerStream pipeStream)
{
try
{
// There is always a race between timeout and connections because
// there is no way to cancel listening on the pipe without
// closing the pipe. We immediately increment the connection
// semaphore while processing connections in order to narrow
// the race window as much as possible.
Interlocked.Increment(ref this.activeConnectionCount);
if (Environment.Is64BitProcess || MemoryHelper.IsMemoryAvailable())
{
CompilerServerLogger.Log("Memory available - accepting connection");
Connection connection = new Connection(pipeStream, handler);
await connection.ServeConnection().ConfigureAwait(false);
// The connection should be finished
ConnectionCompleted(connection);
}
else
{
CompilerServerLogger.Log("Memory tight - rejecting connection.");
// As long as we haven't written a response, the client has not
// committed to this server instance and can look elsewhere.
pipeStream.Close();
// We didn't create a connection -- decrement the semaphore
Interlocked.Decrement(ref this.activeConnectionCount);
// Start a terminate server timer if there are no active
// connections
StartTimeoutTimerIfNecessary();
}
}
catch (Exception e) if (CompilerFatalError.Report(e))
{
throw ExceptionUtilities.Unreachable;
}
}
/// <summary>
/// Create an instance of the pipe. This might be the first instance, or a subsequent instance.
/// There always needs to be an instance of the pipe created to listen for a new client connection.
/// </summary>
/// <returns>The pipe instance, or NULL if the pipe couldn't be created..</returns>
private NamedPipeServerStream ConstructPipe()
{
// Add the process ID onto the pipe name so each process gets a unique pipe name.
// The client must user this algorithm too to connect.
string pipeName = basePipeName + Process.GetCurrentProcess().Id.ToString();
try
{
CompilerServerLogger.Log("Constructing pipe '{0}'.", pipeName);
SecurityIdentifier identifier = WindowsIdentity.GetCurrent().Owner;
PipeSecurity security = new PipeSecurity();
// Restrict access to just this account.
PipeAccessRule rule = new PipeAccessRule(identifier, PipeAccessRights.ReadWrite | PipeAccessRights.CreateNewInstance, AccessControlType.Allow);
security.AddAccessRule(rule);
security.SetOwner(identifier);
NamedPipeServerStream pipeStream = new NamedPipeServerStream(
pipeName,
PipeDirection.InOut,
NamedPipeServerStream.MaxAllowedServerInstances, // Maximum connections.
PipeTransmissionMode.Byte,
PipeOptions.Asynchronous | PipeOptions.WriteThrough,
PipeBufferSize, // Default input buffer
PipeBufferSize, // Default output buffer
security,
HandleInheritability.None);
CompilerServerLogger.Log("Successfully constructed pipe '{0}'.", pipeName);
return pipeStream;
}
catch (Exception e)
{
// Windows may not create the pipe for a number of reasons.
CompilerServerLogger.LogException(e, string.Format("Construction of pipe '{0}' failed", pipeName));
return null;
}
}
示例4: ConstructPipe
/// <summary>
/// Create an instance of the pipe. This might be the first instance, or a subsequent instance.
/// There always needs to be an instance of the pipe created to listen for a new client connection.
/// </summary>
/// <returns>The pipe instance or throws an exception.</returns>
private NamedPipeServerStream ConstructPipe(string pipeName)
{
CompilerServerLogger.Log("Constructing pipe '{0}'.", pipeName);
SecurityIdentifier identifier = WindowsIdentity.GetCurrent().Owner;
PipeSecurity security = new PipeSecurity();
// Restrict access to just this account.
PipeAccessRule rule = new PipeAccessRule(identifier, PipeAccessRights.ReadWrite | PipeAccessRights.CreateNewInstance, AccessControlType.Allow);
security.AddAccessRule(rule);
security.SetOwner(identifier);
NamedPipeServerStream pipeStream = new NamedPipeServerStream(
pipeName,
PipeDirection.InOut,
NamedPipeServerStream.MaxAllowedServerInstances, // Maximum connections.
PipeTransmissionMode.Byte,
PipeOptions.Asynchronous | PipeOptions.WriteThrough,
PipeBufferSize, // Default input buffer
PipeBufferSize, // Default output buffer
security,
HandleInheritability.None);
CompilerServerLogger.Log("Successfully constructed pipe '{0}'.", pipeName);
return pipeStream;
}