/// <summary>
        /// Loads the permission data from the given file or directory.
        /// </summary>
        /// <param name="nativeLibraryInterface">Object for native operations.</param>
        /// <param name="fullPath">Full path to the file or directory.</param>
        /// <param name="loadDefaultAcl">Specifies whether to load a directory's default ACL (1) or not (0). This must be 0 for files.</param>
        internal PosixPermissionInfo(INativeLibraryInterface nativeLibraryInterface, string fullPath, int loadDefaultAcl)
        {
            _nativeLibraryInterface = nativeLibraryInterface ?? throw new ArgumentNullException(nameof(nativeLibraryInterface));

            // Get permission data
            // TODO handle/document exceptions
            var acl = _nativeLibraryInterface.GetPermissionData(fullPath, loadDefaultAcl, out var dataContainer);

            // Initialize members
            OwnerId          = dataContainer.OwnerId;
            OwnerPermissions = dataContainer.OwnerPermissions;
            GroupId          = dataContainer.GroupId;
            GroupPermissions = dataContainer.GroupPermissions;
            OtherPermissions = dataContainer.OtherPermissions;

            // Parse ACL
            foreach (var entry in acl)
            {
                switch (entry.TagType)
                {
                case AccessControlListEntryTagTypes.User:
                {
                    // Add user to list
                    if (entry.TagQualifier != OwnerId)
                    {
                        _aclUserPermissions[entry.TagQualifier] = entry.Permissions;
                    }

                    break;
                }

                case AccessControlListEntryTagTypes.Group:
                {
                    // Add group to list
                    if (entry.TagQualifier != GroupId)
                    {
                        _aclGroupPermissions[entry.TagQualifier] = entry.Permissions;
                    }

                    break;
                }
                }
            }
        }
 /// <summary>
 /// Creates a new <see cref="PosixPermissionInfo"/> object from the given directory.
 /// </summary>
 /// <param name="nativeLibraryInterface">Object for native operations.</param>
 /// <param name="directory">The directory to load the permissions for.</param>
 /// <param name="loadDefaultAcl">Specifies whether the directory's own or default ACL should be loaded.</param>
 public PosixPermissionInfo(INativeLibraryInterface nativeLibraryInterface, DirectoryInfo directory, bool loadDefaultAcl)
     : this(nativeLibraryInterface, directory.FullName, loadDefaultAcl ? 0 : 1)
 {
 }
 /// <summary>
 /// Creates a new <see cref="PosixPermissionInfo"/> object from the given file.
 /// </summary>
 /// <param name="nativeLibraryInterface">Object for native operations.</param>
 /// <param name="file">The file to load the permissions for.</param>
 public PosixPermissionInfo(INativeLibraryInterface nativeLibraryInterface, FileInfo file)
     : this(nativeLibraryInterface, file.FullName, 0)
 {
 }
Пример #4
0
 /// <summary>
 /// Creates a new <see cref="PosixPermissionsProvider"/> object with the given injected objects.
 /// </summary>
 /// <param name="nativeLibraryInterface">Object for native operations.</param>
 public PosixPermissionsProvider(INativeLibraryInterface nativeLibraryInterface)
 {
     _nativeLibraryInterface = nativeLibraryInterface ?? throw new ArgumentNullException(nameof(nativeLibraryInterface));
 }