Ejemplo n.º 1
0
        /// <summary>
        /// Delete LSA private data.
        /// </summary>
        /// <param name="system_name">The system containing the LSA instance.</param>
        /// <param name="keyname">The name of the key.</param>
        /// <param name="throw_on_error">True to throw on error.</param>
        /// <returns>The NT status code.</returns>
        public static NtStatus LsaDeletePrivateData(string system_name, string keyname, bool throw_on_error)
        {
            using (var policy = LsaPolicy.Open(system_name, LsaPolicyAccessRights.MaximumAllowed, throw_on_error))
            {
                if (!policy.IsSuccess)
                {
                    return(policy.Status);
                }

                return(policy.Result.StorePrivateData(keyname, null, throw_on_error));
            }
        }
Ejemplo n.º 2
0
        public static NtResult <SidName> LookupInternetName(Sid sid, bool throw_on_error)
        {
            using (var policy = LsaPolicy.Open(LsaPolicyAccessRights.LookupNames, throw_on_error))
            {
                if (!policy.IsSuccess)
                {
                    return(policy.Cast <SidName>());
                }

                return(policy.Result.LookupSids2(new Sid[] { sid }, LsaLookupOptionFlags.PreferInternetNames, throw_on_error).Map(e => e.First()));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Retrieve LSA private data.
        /// </summary>
        /// <param name="system_name">The system containing the LSA instance.</param>
        /// <param name="keyname">The name of the key.</param>
        /// <param name="throw_on_error">True to throw on error.</param>
        /// <returns>The private data as bytes.</returns>
        public static NtResult <byte[]> LsaRetrievePrivateData(string system_name, string keyname, bool throw_on_error)
        {
            if (keyname is null)
            {
                throw new ArgumentNullException(nameof(keyname));
            }

            using (var policy = LsaPolicy.Open(system_name, Policy.LsaPolicyAccessRights.GetPrivateInformation, throw_on_error))
            {
                if (!policy.IsSuccess)
                {
                    return(policy.Cast <byte[]>());
                }
                return(policy.Result.RetrievePrivateData(keyname, throw_on_error));
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Store LSA private data.
        /// </summary>
        /// <param name="system_name">The system containing the LSA instance.</param>
        /// <param name="keyname">The name of the key.</param>
        /// <param name="data">The data to store.</param>
        /// <param name="throw_on_error">True to throw on error.</param>
        /// <returns>The NT status code.</returns>
        public static NtStatus LsaStorePrivateData(string system_name, string keyname, byte[] data, bool throw_on_error)
        {
            if (data is null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            using (var policy = LsaPolicy.Open(system_name, LsaPolicyAccessRights.CreateSecret, throw_on_error))
            {
                if (!policy.IsSuccess)
                {
                    return(policy.Status);
                }

                return(policy.Result.StorePrivateData(keyname, data, throw_on_error));
            }
        }