示例#1
0
 /// <summary>
 /// Create and initialize a Silo,
 /// </summary>
 /// <param name="root_dir_flags">Flags for root directory.</param>
 /// <param name="throw_on_error">True to throw on error.</param>
 /// <returns>The Job object.</returns>
 public static NtResult <NtJob> CreateSilo(SiloObjectRootDirectoryControlFlags root_dir_flags, bool throw_on_error)
 {
     using (var job = Create(null, JobAccessRights.MaximumAllowed, throw_on_error))
     {
         if (!job.IsSuccess)
         {
             return(job);
         }
         return(job.Result.InitializeSilo(root_dir_flags, false).CreateResult(throw_on_error, () => job.Result.Duplicate()));
     }
 }
        /// <summary>
        /// Create and initialize a Server Silo,
        /// </summary>
        /// <param name="root_dir_flags">Flags for root directory.</param>
        /// <param name="throw_on_error">True to throw on error.</param>
        /// <param name="system_root">Path to the system root.</param>
        /// <param name="delete_event">Event to signal when silo deleted.</param>
        /// <param name="downlevel_container">True if a downlevel container.</param>
        /// <returns>The Job object.</returns>
        public static NtResult <NtJob> CreateServerSilo(SiloObjectRootDirectoryControlFlags root_dir_flags, string system_root, NtEvent delete_event, bool downlevel_container, bool throw_on_error)
        {
            using (var job = CreateSilo(root_dir_flags, throw_on_error))
            {
                if (!job.IsSuccess)
                {
                    return(job);
                }

                NtStatus status = job.Result.SetSiloSystemRoot(system_root, throw_on_error);
                if (!status.IsSuccess())
                {
                    return(status.CreateResultFromError <NtJob>(throw_on_error));
                }

                var silo_dir = job.Result.QuerySiloRootDirectory(throw_on_error);
                if (!silo_dir.IsSuccess)
                {
                    return(silo_dir.Cast <NtJob>());
                }

                string device_path = $@"{silo_dir.Result}\Device";

                using (var device_dir = NtDirectory.Open(@"\Device", null, DirectoryAccessRights.MaximumAllowed, throw_on_error))
                {
                    if (!device_dir.IsSuccess)
                    {
                        return(device_dir.Cast <NtJob>());
                    }
                    using (var obja = new ObjectAttributes(device_path, AttributeFlags.CaseInsensitive | AttributeFlags.Permanent | AttributeFlags.OpenIf))
                    {
                        using (var dir = NtDirectory.Create(obja, DirectoryAccessRights.MaximumAllowed, device_dir.Result, throw_on_error))
                        {
                            if (!dir.IsSuccess)
                            {
                                return(dir.Cast <NtJob>());
                            }
                        }
                    }
                }

                status = job.Result.InitializeServerSilo(delete_event, downlevel_container, throw_on_error);
                if (!status.IsSuccess())
                {
                    return(status.CreateResultFromError <NtJob>(throw_on_error));
                }
                return(job.Result.Duplicate().CreateResult());
            }
        }
        /// <summary>
        /// Initialize a Silo,
        /// </summary>
        /// <param name="root_dir_flags">Flags for root directory.</param>
        /// <param name="throw_on_error">True to throw on error.</param>
        /// <returns>The NT status code.</returns>
        public NtStatus InitializeSilo(SiloObjectRootDirectoryControlFlags root_dir_flags, bool throw_on_error)
        {
            NtStatus status = SetLimitFlags(JobObjectLimitFlags.Application, throw_on_error);

            if (!status.IsSuccess())
            {
                return(status);
            }
            status = CreateSilo(throw_on_error);
            if (!status.IsSuccess())
            {
                return(status);
            }
            status = AssignProcessPseudoHandle(throw_on_error);
            if (!status.IsSuccess())
            {
                return(status);
            }
            return(SetSiloObjectRootDirectory(root_dir_flags, throw_on_error));
        }
 /// <summary>
 /// Create the silo's root object directory.
 /// </summary>
 /// <param name="flags">The flags for the creation.</param>
 /// <returns>The NT status code.</returns>
 public void SetSiloObjectRootDirectory(SiloObjectRootDirectoryControlFlags flags)
 {
     SetSiloObjectRootDirectory(flags, true);
 }
 /// <summary>
 /// Initialize a Silo,
 /// </summary>
 /// <param name="root_dir_flags">Flags for root directory.</param>
 public void InitializeSilo(SiloObjectRootDirectoryControlFlags root_dir_flags)
 {
     InitializeSilo(root_dir_flags, true);
 }
 /// <summary>
 /// Create and initialize a Server Silo,
 /// </summary>
 /// <param name="root_dir_flags">Flags for root directory.</param>
 /// <param name="system_root">Path to the system root.</param>
 /// <param name="delete_event">Event to signal when silo deleted.</param>
 /// <param name="downlevel_container">True if a downlevel container.</param>
 /// <returns>The Job object.</returns>
 public static NtJob CreateServerSilo(SiloObjectRootDirectoryControlFlags root_dir_flags, string system_root, NtEvent delete_event, bool downlevel_container)
 {
     return(CreateServerSilo(root_dir_flags, system_root, delete_event, downlevel_container, true).Result);
 }
 /// <summary>
 /// Create an initialize a Silo,
 /// </summary>
 /// <param name="root_dir_flags">Flags for root directory.</param>
 /// <returns>The Job object.</returns>
 public static NtJob CreateSilo(SiloObjectRootDirectoryControlFlags root_dir_flags)
 {
     return(CreateSilo(root_dir_flags, true).Result);
 }