/// <summary>
        /// Open an alias by SID.
        /// </summary>
        /// <param name="sid">The sid for the alias.</param>
        /// <param name="desired_access">The desired access for the alias object.</param>
        /// <param name="throw_on_error">True to throw on error.</param>
        /// <returns>The SAM alias object.</returns>
        public NtResult <SamAlias> OpenAlias(Sid sid, SamAliasAccessRights desired_access, bool throw_on_error)
        {
            if (sid.SubAuthorities.Count != DomainId.SubAuthorities.Count + 1 || !sid.StartsWith(DomainId))
            {
                return(NtStatus.STATUS_NO_SUCH_DOMAIN.CreateResultFromError <SamAlias>(throw_on_error));
            }

            return(OpenAlias(sid.SubAuthorities.Last(), null, desired_access, throw_on_error));
        }
        /// <summary>
        /// Open an alias by name.
        /// </summary>
        /// <param name="name">The name for the alias.</param>
        /// <param name="desired_access">The desired access for the alias object.</param>
        /// <param name="throw_on_error">True to throw on error.</param>
        /// <returns>The SAM alias object.</returns>
        public NtResult <SamAlias> OpenAlias(string name, SamAliasAccessRights desired_access, bool throw_on_error)
        {
            var sid_name = LookupName(name, throw_on_error);

            if (!sid_name.IsSuccess)
            {
                return(sid_name.Cast <SamAlias>());
            }

            var sid = Sid.Parse(sid_name.Result.Sddl, throw_on_error);

            if (!sid.IsSuccess)
            {
                return(sid.Cast <SamAlias>());
            }

            return(OpenAlias(sid.Result, desired_access, throw_on_error));
        }
Exemple #3
0
 internal static extern NtStatus SamOpenAlias(
     SafeSamHandle DomainHandle,
     SamAliasAccessRights DesiredAccess,
     uint AliasId,
     out SafeSamHandle AliasHandle
     );
 /// <summary>
 /// Enumerate and open accessible alias objects.
 /// </summary>
 /// <param name="desired_access">The desired access for the opened aliases.</param>
 /// <returns>The list of accessible aliases.</returns>
 public IReadOnlyList <SamAlias> OpenAccessibleAliases(SamAliasAccessRights desired_access)
 {
     return(OpenAccessibleAliases(desired_access, true).Result);
 }
 /// <summary>
 /// Enumerate and open accessible alias objects.
 /// </summary>
 /// <param name="desired_access">The desired access for the opened aliases.</param>
 /// <param name="throw_on_error">True to throw on error.</param>
 /// <returns>The list of accessible aliases.</returns>
 public NtResult <IReadOnlyList <SamAlias> > OpenAccessibleAliases(SamAliasAccessRights desired_access, bool throw_on_error)
 {
     return(EnumerateAliases(throw_on_error).Map <IReadOnlyList <SamAlias> >(e => e.Select(
                                                                                 s => OpenAlias(s.RelativeId, s.Name, desired_access, false).GetResultOrDefault()).Where(a => a != null).ToList().AsReadOnly()));
 }
 /// <summary>
 /// Open an alias by name.
 /// </summary>
 /// <param name="name">The name for the alias.</param>
 /// <param name="desired_access">The desired access for the alias object.</param>
 /// <returns>The SAM alias object.</returns>
 public SamAlias OpenAlias(string name, SamAliasAccessRights desired_access)
 {
     return(OpenAlias(name, desired_access, true).Result);
 }
 /// <summary>
 /// Open an alias by SID.
 /// </summary>
 /// <param name="sid">The sid for the alias.</param>
 /// <param name="desired_access">The desired access for the alias object.</param>
 /// <returns>The SAM alias object.</returns>
 public SamAlias OpenAlias(Sid sid, SamAliasAccessRights desired_access)
 {
     return(OpenAlias(sid, desired_access, true).Result);
 }
 /// <summary>
 /// Open an alias by relative ID.
 /// </summary>
 /// <param name="alias_id">The ID for the alias.</param>
 /// <param name="desired_access">The desired access for the alias object.</param>
 /// <returns>The SAM alias object.</returns>
 public SamAlias OpenAlias(uint alias_id, SamAliasAccessRights desired_access)
 {
     return(OpenAlias(alias_id, desired_access, true).Result);
 }
 /// <summary>
 /// Open an alias by relative ID.
 /// </summary>
 /// <param name="alias_id">The ID for the alias.</param>
 /// <param name="desired_access">The desired access for the alias object.</param>
 /// <param name="throw_on_error">True to throw on error.</param>
 /// <returns>The SAM alias object.</returns>
 public NtResult <SamAlias> OpenAlias(uint alias_id, SamAliasAccessRights desired_access, bool throw_on_error)
 {
     return(OpenAlias(alias_id, null, desired_access, throw_on_error));
 }
 private NtResult <SamAlias> OpenAlias(uint alias_id, string name, SamAliasAccessRights desired_access, bool throw_on_error)
 {
     return(SecurityNativeMethods.SamOpenAlias(Handle, desired_access, alias_id, out SafeSamHandle handle).CreateResult(throw_on_error,
                                                                                                                        () => CreateObject(handle, alias_id, name, (n, s) => new SamAlias(handle, desired_access, ServerName, n, s))));
 }
Exemple #11
0
 internal SamAlias(SafeSamHandle handle, SamAliasAccessRights granted_access, string server_name, string alias_name, Sid sid)
     : base(handle, granted_access, SamUtils.SAM_ALIAS_NT_TYPE_NAME, alias_name, server_name)
 {
     Sid  = sid;
     Name = alias_name;
 }