/// <summary>
        /// Process record.
        /// </summary>
        protected override void ProcessRecord()
        {
            Sid sid;

            switch (ParameterSetName)
            {
            case "sddl":
                sid = new Sid(Sddl);
                break;

            case "name":
                sid = NtSecurity.LookupAccountName(Name);
                break;

            case "service":
                sid = NtSecurity.GetServiceSid(ServiceName);
                break;

            case "il":
                sid = NtSecurity.GetIntegritySid(IntegrityLevel);
                break;

            case "il_raw":
                sid = NtSecurity.GetIntegritySidRaw(IntegrityLevelRaw);
                break;

            case "package":
                sid = TokenUtils.DerivePackageSidFromName(PackageName);
                if (RestrictedPackageName != null)
                {
                    sid = TokenUtils.DeriveRestrictedPackageSidFromSid(sid, RestrictedPackageName);
                }
                break;

            case "known":
                sid = KnownSids.GetKnownSid(KnownSid);
                break;

            case "token":
                using (NtToken token = NtToken.OpenProcessToken())
                {
                    if (PrimaryGroup)
                    {
                        sid = token.PrimaryGroup;
                    }
                    else if (Owner)
                    {
                        sid = token.Owner;
                    }
                    else if (LogonGroup)
                    {
                        sid = token.LogonSid.Sid;
                    }
                    else if (AppContainer)
                    {
                        sid = token.AppContainerSid;
                    }
                    else if (Label)
                    {
                        sid = token.IntegrityLevelSid.Sid;
                    }
                    else
                    {
                        sid = token.User.Sid;
                    }
                }
                break;

            case "cap":
                sid = CapabilityGroup ? NtSecurity.GetCapabilityGroupSid(CapabilityName)
                                    : NtSecurity.GetCapabilitySid(CapabilityName);
                break;

            case "sid":
                sid = new Sid(SecurityAuthority, RelativeIdentifiers);
                break;

            case "logon":
                sid = NtSecurity.GetLogonSessionSid();
                break;

            default:
                throw new ArgumentException("No SID type specified");
            }

            if (ToSddl)
            {
                WriteObject(sid.ToString());
            }
            else if (ToName)
            {
                WriteObject(sid.Name);
            }
            else
            {
                WriteObject(sid);
            }
        }
コード例 #2
0
        /// <summary>
        /// Process record.
        /// </summary>
        protected override void ProcessRecord()
        {
            Sid sid;

            if (Sddl != null)
            {
                sid = new Sid(Sddl);
            }
            else if (Name != null)
            {
                sid = NtSecurity.LookupAccountName(Name);
            }
            else if (ServiceName != null)
            {
                sid = NtSecurity.GetServiceSid(ServiceName);
            }
            else if (IntegrityLevel.HasValue)
            {
                sid = NtSecurity.GetIntegritySid(IntegrityLevel.Value);
            }
            else if (IntegrityLevelRaw.HasValue)
            {
                sid = NtSecurity.GetIntegritySidRaw(IntegrityLevelRaw.Value);
            }
            else if (PackageName != null)
            {
                sid = TokenUtils.DerivePackageSidFromName(PackageName);
                if (RestrictedPackageName != null)
                {
                    sid = TokenUtils.DeriveRestrictedPackageSidFromSid(sid, RestrictedPackageName);
                }
            }
            else if (KnownSid.HasValue)
            {
                sid = KnownSids.GetKnownSid(KnownSid.Value);
            }
            else if (Token)
            {
                using (NtToken token = NtToken.OpenProcessToken())
                {
                    if (PrimaryGroup)
                    {
                        sid = token.PrimaryGroup;
                    }
                    else if (Owner)
                    {
                        sid = token.Owner;
                    }
                    else if (LogonGroup)
                    {
                        sid = token.LogonSid.Sid;
                    }
                    else if (AppContainer)
                    {
                        sid = token.AppContainerSid;
                    }
                    else if (Label)
                    {
                        sid = token.IntegrityLevelSid.Sid;
                    }
                    else
                    {
                        sid = token.User.Sid;
                    }
                }
            }
            else if (CapabilityName != null)
            {
                sid = CapabilityGroup ? NtSecurity.GetCapabilityGroupSid(CapabilityName)
                    : NtSecurity.GetCapabilitySid(CapabilityName);
            }
            else if (RelativeIdentifiers != null)
            {
                sid = new Sid(SecurityAuthority, RelativeIdentifiers);
            }
            else
            {
                throw new ArgumentException("No SID type specified");
            }

            WriteObject(sid);
        }