示例#1
0
        public static string GetOwner(PSObject instance)
        {
            string str;

            if (instance != null)
            {
                ObjectSecurity baseObject = instance.BaseObject as ObjectSecurity;
                if (baseObject != null)
                {
                    try
                    {
                        IdentityReference owner = baseObject.GetOwner(typeof(NTAccount));
                        str = owner.ToString();
                    }
                    catch (IdentityNotMappedException identityNotMappedException)
                    {
                        return(baseObject.GetSecurityDescriptorSddlForm(AccessControlSections.Owner));
                    }
                    return(str);
                }
                else
                {
                    throw PSTraceSource.NewArgumentNullException("instance");
                }
            }
            else
            {
                throw PSTraceSource.NewArgumentNullException("instance");
            }
        }
示例#2
0
        private static string GetOwnerName(ObjectSecurity systemSecurity)
        {
            var sid       = systemSecurity.GetOwner(typeof(SecurityIdentifier));
            var ntAccount = sid.Translate(typeof(NTAccount));
            var owner     = ntAccount.Value;

            return(owner);
        }
示例#3
0
 /// <summary>
 /// Check to ensure that the named pipe server we connected to is owned by the same
 /// user.
 /// </summary>
 /// <remarks>
 /// The type is embedded in assemblies that need to run cross platform.  While this particular
 /// code will never be hit when running on non-Windows platforms it does need to work when
 /// on Windows.  To facilitate that we use reflection to make the check here to enable it to
 /// compile into our cross plat assemblies.
 /// </remarks>
 private static bool CheckPipeConnectionOwnership(NamedPipeClientStream pipeStream)
 {
     try
     {
         var            currentIdentity    = WindowsIdentity.GetCurrent();
         var            currentOwner       = currentIdentity.Owner;
         ObjectSecurity remotePipeSecurity = GetPipeSecurity(pipeStream);
         var            remoteOwner        = remotePipeSecurity.GetOwner(typeof(SecurityIdentifier));
         return(currentOwner.Equals(remoteOwner));
     }
     catch (Exception ex)
     {
         Log("Exception checking pipe connection: {0}", ex.Message);
         return(false);
     }
 }
示例#4
0
        /// <summary>
        /// Remove all access of previous owner of type <see cref="SecurityIdentifier"/>
        /// </summary>
        /// <typeparam name="TIdentifier">The parameter can be of typeof <see cref="System.Security.Principal.NTAccount"/> or <see cref="System.Security.Principal.SecurityIdentifier"/> , <see cref=""/></typeparam>
        public static void PurgeAllAccess <TIdentifier>(this ObjectSecurity refId)
        {
            var oldOwner = refId.GetOwner(typeof(TIdentifier));

            refId.PurgeAccessRules(oldOwner);
        }