public string GetSddlForm(AccessControlSections includeSections)
    {
      Contract.Requires(3 < this.BinaryLength);
      Contract.Ensures(System.Security.AccessControl.GenericSecurityDescriptor.Revision == 1);

      return default(string);
    }
コード例 #2
0
		public static RegistrySecurity GetAccessControl (this RegistryKey key, AccessControlSections includeSections)
		{
			if (key == null)
				throw new ArgumentNullException (nameof (key));

			return key.GetAccessControl (includeSections);
		}
コード例 #3
0
 public ObjectSecurity GetAccessControl(AccessControlSections includeSections)
 {
     using (this.provider.CurrentPSTransaction)
     {
         return this.txRegKey.GetAccessControl(includeSections);
     }
 }
コード例 #4
0
		public static FileSecurity GetAccessControl(this FileInfo fileInfo, AccessControlSections includeSections)
		{
			if (fileInfo == null)
				throw new ArgumentNullException (nameof (fileInfo));

			return fileInfo.GetAccessControl (includeSections);
		}
コード例 #5
0
		public static DirectorySecurity GetAccessControl(this DirectoryInfo directoryInfo, AccessControlSections includeSections)
		{
			if (directoryInfo == null)
				throw new ArgumentNullException (nameof (directoryInfo));

			return directoryInfo.GetAccessControl (includeSections);
		}
コード例 #6
0
		protected NativeObjectSecurity (bool isContainer,
						ResourceType resourceType,
						string name,
						AccessControlSections includeSections)
			: this (isContainer, resourceType, name, includeSections, null, null)
		{
		}
コード例 #7
0
ファイル: RegistrySecurity.cs プロジェクト: 40a/PowerShell
        /// <summary>
        /// Gets the security descriptor for the item specified by <paramref name="path"/>.
        /// </summary>
        /// 
        /// <param name="path">
        /// The path to the item.
        /// </param>
        ///
        /// <param name="sections">
        /// Specifies the parts of a security descriptor to retrieve.
        /// </param>
        /// 
        /// <returns>
        /// Nothing. An object that represents the security descriptor for the item
        /// specified by path is written to the WriteSecurityDescriptorObject method.
        /// </returns>
        public void GetSecurityDescriptor(string path,
                                          AccessControlSections sections)
        {
            ObjectSecurity sd = null;
            IRegistryWrapper key = null;

            // Validate input first.
            if (String.IsNullOrEmpty(path))
            {
                throw PSTraceSource.NewArgumentNullException("path");
            }

            if ((sections & ~AccessControlSections.All) != 0)
            {
                throw PSTraceSource.NewArgumentException("sections");
            }

            path = NormalizePath(path);

            key = GetRegkeyForPathWriteIfError(path, false);

            if (key != null)
            {
                try
                {
                    sd = key.GetAccessControl(sections);
                }
                catch (System.Security.SecurityException e)
                {
                    WriteError(new ErrorRecord(e, e.GetType().FullName, ErrorCategory.PermissionDenied, path));
                    return;
                }
                WriteSecurityDescriptorObject(sd, path);
            }
        }
コード例 #8
0
		protected NativeObjectSecurity (bool isContainer,
						ResourceType resourceType,
						SafeHandle handle,
						AccessControlSections includeSections)
			: this (isContainer, resourceType, handle, includeSections, null, null)
		{
		}
        private static CommonSecurityDescriptor CreateInternal(ResourceType resourceType, bool isContainer, string name, SafeHandle handle, AccessControlSections includeSections, bool createByName, ExceptionFromErrorCode exceptionFromErrorCode, object exceptionContext)
        {
            RawSecurityDescriptor descriptor;
            if (createByName && (name == null))
            {
                throw new ArgumentNullException("name");
            }
            if (!createByName && (handle == null))
            {
                throw new ArgumentNullException("handle");
            }
            int errorCode = System.Security.AccessControl.Win32.GetSecurityInfo(resourceType, name, handle, includeSections, out descriptor);
            if (errorCode == 0)
            {
                return new CommonSecurityDescriptor(isContainer, false, descriptor, true);
            }
            Exception exception = null;
            if (exceptionFromErrorCode != null)
            {
                exception = exceptionFromErrorCode(errorCode, name, handle, exceptionContext);
            }
            if (exception == null)
            {
                switch (errorCode)
                {
                    case 5:
                        exception = new UnauthorizedAccessException();
                        goto Label_0132;

                    case 0x51b:
                        exception = new InvalidOperationException(Environment.GetResourceString("AccessControl_InvalidOwner"));
                        goto Label_0132;

                    case 0x51c:
                        exception = new InvalidOperationException(Environment.GetResourceString("AccessControl_InvalidGroup"));
                        goto Label_0132;

                    case 0x57:
                        exception = new InvalidOperationException(Environment.GetResourceString("AccessControl_UnexpectedError", new object[] { errorCode }));
                        goto Label_0132;

                    case 0x7b:
                        exception = new ArgumentException(Environment.GetResourceString("Argument_InvalidName"), "name");
                        goto Label_0132;

                    case 2:
                        exception = (name == null) ? new FileNotFoundException() : new FileNotFoundException(name);
                        goto Label_0132;

                    case 0x546:
                        exception = new NotSupportedException(Environment.GetResourceString("AccessControl_NoAssociatedSecurity"));
                        goto Label_0132;
                }
                exception = new InvalidOperationException(Environment.GetResourceString("AccessControl_UnexpectedError", new object[] { errorCode }));
            }
        Label_0132:
            throw exception;
        }
コード例 #10
0
ファイル: NativeObjectSecurity.cs プロジェクト: runefs/Marvin
		protected NativeObjectSecurity (bool isContainer,
						ResourceType resourceType,
						SafeHandle handle,
						AccessControlSections includeSections,
						ExceptionFromErrorCode exceptionFromErrorCode,
						object exceptionContext)
			: this (isContainer, resourceType, handle, includeSections)
		{
		}
コード例 #11
0
        public static RegistrySecurity GetAccessControl(this RegistryKey key, AccessControlSections includeSections)
        {
            if (key.Handle == null)
            {
                throw new ObjectDisposedException(key.Name, SR.ObjectDisposed_RegKeyClosed);
            }

            return new RegistrySecurity(key.Handle, key.Name, includeSections);
        }
コード例 #12
0
 internal FileSecurity(SafeFileHandle handle, string fullPath, AccessControlSections includeSections) : base(false, handle, includeSections, false)
 {
     if (fullPath != null)
     {
         new FileIOPermission(FileIOPermissionAccess.NoAccess, AccessControlActions.View, fullPath).Demand();
     }
     else
     {
         new FileIOPermission(PermissionState.Unrestricted).Demand();
     }
 }
コード例 #13
0
        private static bool TryGetFileSecurity(string path, AccessControlSections sectionsNeeded,
            out FileSystemSecurity security)
        {
            var exists = false;
            security = null;

            if (File.Exists(path))
            {
                exists = true;
                security = File.GetAccessControl(path, sectionsNeeded);
            }

            return exists;
        }
コード例 #14
0
        private bool TryGetDirectorySecurity(string path, AccessControlSections sectionsNeeded,
            out FileSystemSecurity security)
        {
            var exists = false;
            security = null;

            if (Directory.Exists(path))
            {
                exists = true;
                security = Directory.GetAccessControl(path, sectionsNeeded);
            }

            return exists;
        }
コード例 #15
0
        } // GetPermissionProviderInstance

        #endregion private methods

        #region GetSecurityDescriptor


        /// <summary>
        /// Gets the security descriptor from the specified item.
        /// </summary>
        /// 
        /// <param name="path">
        /// The path to the item to retrieve the security descriptor from.
        /// </param>
        /// 
        /// <param name="sections">
        /// Specifies the parts of a security descriptor to retrieve.
        /// </param>
        /// 
        /// <returns>
        /// The security descriptor for the item at the specified path.
        /// </returns>
        /// 
        internal Collection<PSObject> GetSecurityDescriptor(string path,
                                                             AccessControlSections sections)
        {
            if (path == null)
            {
                throw PSTraceSource.NewArgumentNullException("path");
            }

            CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext);

            GetSecurityDescriptor(path, sections, context);

            context.ThrowFirstErrorOrDoNothing();

            Collection<PSObject> contextResults = context.GetAccumulatedObjects() ?? new Collection<PSObject>();

            return contextResults;
        } // GetSecurityDescriptor
コード例 #16
0
        /// <summary>
        /// Internal wrapper for the GetSecurityDescriptor protected method. This method will
        /// only be called if the provider implements the ISecurityDescriptorCmdletProvider interface.
        /// </summary>
        /// 
        /// <param name="path">
        /// The path to the item to retrieve the security descriptor from.
        /// </param>
        /// 
        /// <param name="sections">
        /// Specifies the parts of a security descriptor to retrieve.
        /// </param>
        /// 
        /// <param name="context">
        /// The context under which this method is being called.
        /// </param>
        /// 
        /// <returns>
        /// Nothing. An instance of an object that represents the security descriptor
        /// for the item specified by the path should be written to the context.
        /// </returns>
        /// 
        internal void GetSecurityDescriptor(
            string path,
            AccessControlSections sections,
            CmdletProviderContext context)
        {
            Context = context;

            ISecurityDescriptorCmdletProvider permissionProvider = this as ISecurityDescriptorCmdletProvider;

            //
            // if this is not supported, the fn will throw
            //
            CheckIfSecurityDescriptorInterfaceIsSupported(permissionProvider);

            // Call interface method

            permissionProvider.GetSecurityDescriptor(path, sections);
        } // GetSecurityDescriptor
コード例 #17
0
ファイル: FileSystemSecurity.cs プロジェクト: 40a/PowerShell
        /// <summary>
        /// Gets the SecurityDescriptor at the specified path, including only the specified
        /// AccessControlSections.
        /// </summary>
        ///
        /// <param name="path">
        /// The path of the item to retrieve. It may be a drive or provider-qualified path and may include.
        /// glob characters.
        /// </param>
        /// 
        /// <param name="sections">
        /// The sections of the security descriptor to include.
        /// </param>
        /// 
        /// <returns>
        /// Nothing. An object that represents the security descriptor for the item
        /// specified by path is written to the context's pipeline.
        /// </returns>
        /// 
        /// <exception cref="System.ArgumentException">
        ///     path is null or empty.
        ///     path doesn't exist
        ///     sections is not valid.
        /// </exception>
        public void GetSecurityDescriptor(string path,
                                          AccessControlSections sections)
        {
            ObjectSecurity sd = null;
            path = NormalizePath(path);

            if (String.IsNullOrEmpty(path))
            {
                throw PSTraceSource.NewArgumentNullException("path");
            }

            if ((sections & ~AccessControlSections.All) != 0)
            {
                throw PSTraceSource.NewArgumentException("sections");
            }

            var currentPrivilegeState = new PlatformInvokes.TOKEN_PRIVILEGE();
            try
            {
                PlatformInvokes.EnableTokenPrivilege("SeBackupPrivilege", ref currentPrivilegeState);

                if (Directory.Exists(path))
                {
                    sd = new DirectorySecurity(path, sections);
                }
                else
                {
                    sd = new FileSecurity(path, sections);
                }
            }
            catch (System.Security.SecurityException e)
            {
                WriteError(new ErrorRecord(e, e.GetType().FullName, ErrorCategory.PermissionDenied, path));
            }
            finally
            {
                PlatformInvokes.RestoreTokenPrivilege("SeBackupPrivilege", ref currentPrivilegeState);
            }

            WriteSecurityDescriptorObject(sd, path);
        }
コード例 #18
0
 protected virtual void Persist(string name, AccessControlSections includeSections);
コード例 #19
0
 protected virtual void Persist(SafeHandle handle, AccessControlSections includeSections);
コード例 #20
0
 protected virtual void Persist(bool enableOwnershipPrivilege, string name, AccessControlSections includeSections);
コード例 #21
0
 public string GetSecurityDescriptorSddlForm(AccessControlSections includeSections);
コード例 #22
0
 protected void Persist(string name, AccessControlSections includeSections, object exceptionContext);
コード例 #23
0
 protected sealed override void Persist(string name, AccessControlSections includeSections);
コード例 #24
0
 protected sealed override void Persist(SafeHandle handle, AccessControlSections includeSections);
コード例 #25
0
 protected NativeObjectSecurity(bool isContainer, ResourceType resourceType, string name, AccessControlSections includeSections, NativeObjectSecurity.ExceptionFromErrorCode exceptionFromErrorCode, object exceptionContext);
コード例 #26
0
 protected NativeObjectSecurity(bool isContainer, ResourceType resourceType, string name, AccessControlSections includeSections);
コード例 #27
0
 protected NativeObjectSecurity(bool isContainer, ResourceType resourceType, SafeHandle handle, AccessControlSections includeSections);
コード例 #28
0
 public void SetSecurityDescriptorBinaryForm(byte[] binaryForm, AccessControlSections includeSections);
コード例 #29
0
 public void SetSecurityDescriptorSddlForm(string sddlForm, AccessControlSections includeSections);
コード例 #30
0
 protected void Persist(SafeHandle handle, AccessControlSections includeSections, object exceptionContext);