/// <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());
            }
        }
Beispiel #2
0
        /// <summary>
        /// Open an NT object with a specified type.
        /// </summary>
        /// <param name="typename">The name of the type to open (e.g. Event). If null the method will try and lookup the appropriate type.</param>
        /// <param name="path">The path to the object to open.</param>
        /// <param name="root">A root directory to open from.</param>
        /// <param name="access">Generic access rights to the object.</param>
        /// <returns>The opened object.</returns>
        /// <exception cref="NtException">Thrown if an error occurred opening the object.</exception>
        /// <exception cref="ArgumentException">Thrown if type of resource couldn't be found.</exception>
        public static NtObject OpenWithType(string typename, string path, NtObject root, GenericAccessRights access)
        {
            if (typename == null)
            {
                typename = NtDirectory.GetDirectoryEntryType(path, root);
                if (typename == null)
                {
                    throw new ArgumentException(String.Format("Can't find type for path {0}", path));
                }
            }

            switch (typename.ToLower())
            {
            case "device":
                return(NtFile.Open(path, root, (FileAccessRights)access, FileShareMode.None, FileOpenOptions.None));

            case "file":
                return(NtFile.Open(path, root, (FileAccessRights)access, FileShareMode.Read | FileShareMode.Write | FileShareMode.Delete, FileOpenOptions.None));

            case "event":
                return(NtEvent.Open(path, root, (EventAccessRights)access));

            case "directory":
                return(NtDirectory.Open(path, root, (DirectoryAccessRights)access));

            case "symboliclink":
                return(NtSymbolicLink.Open(path, root, (SymbolicLinkAccessRights)access));

            case "mutant":
                return(NtMutant.Open(path, root, (MutantAccessRights)access));

            case "semaphore":
                return(NtSemaphore.Open(path, root, (SemaphoreAccessRights)access));

            case "section":
                return(NtSection.Open(path, root, (SectionAccessRights)access));

            case "job":
                return(NtJob.Open(path, root, (JobAccessRights)access));

            case "key":
                return(NtKey.Open(path, root, (KeyAccessRights)access));

            default:
                throw new ArgumentException(String.Format("Can't open type {0}", typename));
            }
        }
Beispiel #3
0
 protected override sealed NtResult <NtDirectory> OpenInternal(ObjectAttributes obj_attributes,
                                                               DirectoryAccessRights desired_access, bool throw_on_error)
 {
     return(NtDirectory.Open(obj_attributes, desired_access, throw_on_error));
 }