Пример #1
0
 protected override Errno OnAccessPath(string path, AccessModes mode)
 {
     if ((mode & AccessModes.W_OK) != 0)
     {
         return(Errno.EROFS);
     }
     try
     {
         Entry fsEntry = walker.SearchEntry(path.Substring(1));
         if (fsEntry == null)
         {
             return(Errno.ENOENT);
         }
         if (((mode & AccessModes.X_OK) != 0) && (fsEntry.Kind == EntryKind.ZipFileEntry))
         {
             return(Errno.EACCES);
         }
     }
     catch (DirectoryNotFoundException)
     {
         return(Errno.ENOTDIR);
     }
     catch (IOException)
     {
         return(Errno.EIO);
     }
     return(0);
 }
Пример #2
0
		public static Int32 FromAccessModes (AccessModes value)
		{
			Int32 rval;
			if (FromAccessModes (value, out rval) == -1)
				ThrowArgumentException (value);
			return rval;
		}
Пример #3
0
 public virtual Errno AccessPath(string path, AccessModes mask)
 {
     int r = Syscall.access (basedir+path, mask);
       if (r == -1)
     return Stdlib.GetLastError ();
       return 0;
 }
Пример #4
0
 public FieldAttribute(string FieldName, bool IsKey, AccessModes AccessMode, bool IsOptional)
 {
     this.FieldName = FieldName;
     this.IsKey = IsKey;
     this.AccessMode = AccessMode;
     this.IsOptional = IsOptional;
 }
Пример #5
0
 protected override Errno OnAccessPath(string path, AccessModes mask)
 {
     int r = Syscall.access (basedir+path, mask);
     if (r == -1)
         return Stdlib.GetLastError ();
     return 0;
 }
Пример #6
0
        /// <summary>
        /// Load the library using a number of options
        /// </summary>
        /// <param name="libraryName">The name of the library</param>
        /// <param name="isReadOnly">If <B>true</B>, loads the library in read-only mode.</param>
        /// <returns>A ShellLibrary Object</returns>
        public static ShellLibrary Load(string libraryName, bool isReadOnly)
        {
            CoreHelpers.ThrowIfNotWin7();

            IKnownFolder kf = KnownFolders.Libraries;
            string       librariesFolderPath = (kf != null) ? kf.Path : string.Empty;

            Guid   guid          = new Guid(ShellIIDGuid.IShellItem);
            string shellItemPath = System.IO.Path.Combine(librariesFolderPath, libraryName + FileExtension);
            int    hr            = ShellNativeMethods.SHCreateItemFromParsingName(shellItemPath, IntPtr.Zero, ref guid, out IShellItem nativeShellItem);

            if (!CoreErrorHelper.Succeeded(hr))
            {
                throw new ShellException(hr);
            }

            INativeShellLibrary nativeShellLibrary = (INativeShellLibrary) new ShellLibraryCoClass();
            AccessModes         flags = isReadOnly ?
                                        AccessModes.Read :
                                        AccessModes.ReadWrite;

            nativeShellLibrary.LoadLibraryFromItem(nativeShellItem, flags);

            ShellLibrary library = new ShellLibrary(nativeShellLibrary);

            try {
                library.nativeShellItem = (IShellItem2)nativeShellItem;
                library.Name            = libraryName;

                return(library);
            } catch {
                library.Dispose();
                throw;
            }
        }
Пример #7
0
        /// <summary>
        /// Load the library using a number of options
        /// </summary>
        /// <param name="libraryName">The name of the library.</param>
        /// <param name="folderPath">The path to the library.</param>
        /// <param name="isReadOnly">If <B>true</B>, opens the library in read-only mode.</param>
        /// <returns>A ShellLibrary Object</returns>
        public static ShellLibrary Load(string libraryName, string folderPath, bool isReadOnly)
        {
            CoreHelpers.ThrowIfNotWin7();

            // Create the shell item path
            string    shellItemPath = System.IO.Path.Combine(folderPath, libraryName + FileExtension);
            ShellFile item          = ShellFile.FromFilePath(shellItemPath);

            IShellItem          nativeShellItem    = item.NativeShellItem;
            INativeShellLibrary nativeShellLibrary = (INativeShellLibrary) new ShellLibraryCoClass();
            AccessModes         flags = isReadOnly ?
                                        AccessModes.Read :
                                        AccessModes.ReadWrite;

            nativeShellLibrary.LoadLibraryFromItem(nativeShellItem, flags);

            ShellLibrary library = new ShellLibrary(nativeShellLibrary);

            try {
                library.nativeShellItem = (IShellItem2)nativeShellItem;
                library.Name            = libraryName;

                return(library);
            } catch {
                library.Dispose();
                throw;
            }
        }
Пример #8
0
        public static bool CheckPathAccessModes(FileAccessPermissions permissions, AccessModes request)
        {
            if (request.HasFlag(AccessModes.R_OK))
            {
                if (!(permissions.HasFlag(FileAccessPermissions.UserRead) || permissions.HasFlag(FileAccessPermissions.GroupRead) || permissions.HasFlag(FileAccessPermissions.OtherRead)))
                {
                    return(false);
                }
            }

            if (request.HasFlag(AccessModes.W_OK))
            {
                if (!(permissions.HasFlag(FileAccessPermissions.UserWrite) || permissions.HasFlag(FileAccessPermissions.GroupWrite) || permissions.HasFlag(FileAccessPermissions.OtherWrite)))
                {
                    return(false);
                }
            }

            // ReSharper disable once InvertIf
            if (request.HasFlag(AccessModes.X_OK))
            {
                if (!(permissions.HasFlag(FileAccessPermissions.UserExecute) || permissions.HasFlag(FileAccessPermissions.GroupExecute) || permissions.HasFlag(FileAccessPermissions.OtherExecute)))
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #9
0
        /// <summary>
        /// Creates a shell library in the Libraries Known Folder,
        /// using the given IKnownFolder
        /// </summary>
        /// <param name="sourceKnownFolder">KnownFolder from which to create the new Shell Library</param>
        /// <param name="isReadOnly">If <B>true</B> , opens the library in read-only mode.</param>
        private ShellLibrary(IKnownFolder sourceKnownFolder, bool isReadOnly)
            : this()
        {
            Debug.Assert(sourceKnownFolder != null);

            // Keep a reference locally
            knownFolder = sourceKnownFolder;

            nativeShellLibrary = (INativeShellLibrary) new ShellLibraryCoClass();

            AccessModes flags = isReadOnly ?
                                AccessModes.Read :
                                AccessModes.ReadWrite;

            // Get the IShellItem2
            base.nativeShellItem = ((ShellObject)sourceKnownFolder).NativeShellItem2;

            Guid guid = sourceKnownFolder.FolderId;

            // Load the library from the IShellItem2
            try {
                nativeShellLibrary.LoadLibraryFromKnownFolder(ref guid, flags);
            } catch (InvalidCastException) {
                throw new ArgumentException(LocalizedMessages.ShellLibraryInvalidLibrary, "sourceKnownFolder");
            } catch (NotImplementedException) {
                throw new ArgumentException(LocalizedMessages.ShellLibraryInvalidLibrary, "sourceKnownFolder");
            }
        }
Пример #10
0
        /// <summary>
        /// R_OK = read allowed
        /// W_OK = write allowed
        /// x_OK = exec allowed
        /// F_OK = exists
        /// </summary>
        /// <param name="path"></param>
        /// <param name="access"></param>
        /// <returns></returns>
        public Result CheckAccess(string path, AccessModes access)
        {
#if DEBUG
            var request = new CrazyFsRequest(CrazyFsRequestName.CheckAccess, new[]
            {
                new KeyValuePair <string, string>("path", path),
                new KeyValuePair <string, string>("access", access.ToString())
            }).Log();
#endif
            try
            {
                var result = FileSystem.Path.HasAccess(path, access)
                    ? new Result(ResultStatus.Success)
                    : new Result(ResultStatus.AccessDenied);
#if DEBUG
                request.Log(result);
#endif
                return(result);
            }
            catch (Exception ex)
            {
                var result = ex.GetResult();
#if DEBUG
                request.Log(result);
#endif
                return(result);
            }
        }
Пример #11
0
        /// <summary>
        ///
        /// </summary>
        protected void Unlock()
        {
            Animator.SetTrigger("Unlock");

            Open();

            AccessMode = AccessModes.Proximity;
        }
Пример #12
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="pathWrapper"></param>
 /// <param name="path"></param>
 /// <param name="modes"></param>
 /// <returns></returns>
 /// <exception cref="FileNotFoundException"></exception>
 public static bool HasAccess(this IPath pathWrapper, string path, AccessModes modes)
 {
     if (pathWrapper is not ILinuxPath obj)
     {
         throw new Exception("IPath is not the linux version");
     }
     return(obj.HasAccess(path, modes));
 }
Пример #13
0
        public virtual Errno AccessPath(string path, AccessModes mask)
        {
            int r = Syscall.access(basedir + path, mask);

            if (r == -1)
            {
                return(Stdlib.GetLastError());
            }
            return(0);
        }
Пример #14
0
        public static Int32 FromAccessModes(AccessModes value)
        {
            Int32 rval;

            if (FromAccessModes(value, out rval) == -1)
            {
                ThrowArgumentException(value);
            }
            return(rval);
        }
Пример #15
0
        protected override Errno OnAccessPath(string path, AccessModes mask)
        {
            int r = Syscall.access(basedir + path, mask);

            if (r == -1)
            {
                return(Stdlib.GetLastError());
            }
            return(0);
        }
Пример #16
0
 protected override Errno OnAccessPath(string path, AccessModes mask)
 {
     return 0;
     //			var realPath = GetRealPath(path);
     //			int r = Syscall.access(realPath, mask);
     //			if (r == -1)
     //			{
     //				return Stdlib.GetLastError();
     //			}
     //			return 0;
 }
Пример #17
0
        private Errno Access(string path, AccessModes mode)
        {
            Trace.WriteLine($"Access {path} {mode}");

            int r = Syscall.access(path, mode);

            if (r < 0)
            {
                return(GetLastError());
            }

            return(0);
        }
Пример #18
0
        private int _OnAccessPath(string path, int mode)
        {
            Errno errno;

            try
            {
                AccessModes _mode = NativeConvert.ToAccessModes(mode);
                errno = _filesystem.OnAccessPath(path, _mode);
            }
            catch (Exception e)
            {
                Trace.WriteLine(e.ToString());
                errno = Errno.EIO;
            }
            return(Interop.ConvertErrno(errno));
        }
Пример #19
0
        /// <summary>
        /// access() checks whether the calling process can access the file pathname. If pathname is a symbolic link, it is dereferenced.
        /// </summary>
        /// <param name="pathmame"></param>
        /// <param name="mode"></param>
        /// <returns>On success (all requested permissions granted), zero is returned. On error (at least one bit in mode asked for a permission that is denied, or some other error occurred), -1 is returned, and errno is set appropriately.</returns>
        public static bool Access(string pathmame, AccessModes mode)
        {
            int ret = access(pathmame, mode);

            if (ret == -1)
            {
                Errno err = errno;
                // return null;
                System.Console.Error.WriteLine("Error on syscall \"access\"");

                // https://github.com/mono/mono/blob/master/mcs/class/Mono.Posix/Mono.Unix.Native/Stdlib.cs
                // https://stackoverflow.com/questions/2485648/access-c-global-variable-errno-from-c-sharp
                // throw ACLManagerException(Glib::locale_to_utf8(strerror(errno)));
                throw new System.InvalidOperationException(GetErrorMessage(err));
            } // End if (ret == -1)

            return(ret == 0);
        } // End Function Access
Пример #20
0
        /// <summary>
        /// Load the library using a number of options
        /// </summary>
        /// <param name="nativeShellItem">IShellItem</param>
        /// <param name="isReadOnly">read-only flag</param>
        /// <returns>A ShellLibrary Object</returns>
        internal static ShellLibrary FromShellItem(IShellItem nativeShellItem, bool isReadOnly)
        {
            CoreHelpers.ThrowIfNotWin7();

            INativeShellLibrary nativeShellLibrary = (INativeShellLibrary) new ShellLibraryCoClass();

            AccessModes flags = isReadOnly ?
                                AccessModes.Read :
                                AccessModes.ReadWrite;

            nativeShellLibrary.LoadLibraryFromItem(nativeShellItem, flags);

            ShellLibrary library = new ShellLibrary(nativeShellLibrary);

            library.nativeShellItem = (IShellItem2)nativeShellItem;

            return(library);
        }
Пример #21
0
 public Result GetAccessToPath(string path, AccessModes mode)
 {
     return(GetFileSystemEntry(path)
            .Then(entry =>
     {
         var permissions = entry.FilePermissions;
         var fileUID = entry.UID;
         var fileGID = entry.GID;
         var userUID = Syscall.getuid();
         var userGID = Syscall.getgid();
         if (((AccessModes.R_OK & mode) != 0 && !permissions.CanUserRead(userUID, userGID, fileUID, fileGID)) ||
             ((AccessModes.W_OK & mode) != 0 && !permissions.CanUserWrite(userUID, userGID, fileUID, fileGID)) ||
             ((AccessModes.X_OK & mode) != 0 && !permissions.CanUserExecute(userUID, userGID, fileUID, fileGID)))
         {
             return Result.Fail(FileSystemError.AccessDenied);
         }
         return Result.Ok();
     }));
 }
Пример #22
0
        public Control(MetriLog log, string ipAddress)
        {
            this.log = log;

            try
            {
                sockControl   = new TcpClient(ipAddress, TCP_PORT_SOPAS);
                streamControl = sockControl.GetStream();
            }
            catch (Exception ex)
            {
                string msg = string.Format("Failed to connect to IP={0}, reasons={1}", ipAddress, ex.Message);
                log.Error(msg);
                throw new Exceptions.ConnectionFailedException(msg, ex);
            }

            _accessMode = GetAccessMode();
            InitStream();
        }
Пример #23
0
        public virtual bool HasAccess(string path, AccessModes modes)
        {
            if (FileSystem.File.Exists(path))
            {
                return(PermissionHelper.CheckPathAccessModes(
                           new UnixFileInfo(FileSystem.FileInfo.FromFileName(path).FullName).FileAccessPermissions, modes));
            }

            if (!FileSystem.Directory.Exists(path))
            {
                throw new FileNotFoundException();
            }

            return(PermissionHelper.CheckPathAccessModes(
                       new UnixDirectoryInfo(
                           FileSystem.DirectoryInfo.FromDirectoryName(path).FullName
                           ).FileAccessPermissions,
                       modes
                       ));
        }
        public override bool HasAccess(string path, AccessModes modes)
        {
            var path_enc = GetEncryptedPath(path, true);

            if (string.IsNullOrEmpty(path_enc))
            {
                return(false);
            }

            if (FileSystem.File.Exists(path))
            {
                return(PermissionHelper.CheckPathAccessModes(
                           new UnixFileInfo(path_enc.GetPath(_source)).FileAccessPermissions,
                           modes
                           ));
            }
            return(PermissionHelper.CheckPathAccessModes(
                       new UnixDirectoryInfo(path_enc.GetPath(_source)).FileAccessPermissions,
                       modes
                       ));
        }
Пример #25
0
        public bool HasPermission(FileSystemRights permissionFlag)
        {
            //
            // Windows

            if (Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                var fileInfo     = new FileInfo(FullPath);
                var fileSecurity = fileInfo.GetAccessControl();
                var usersSid     = new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null);
                var rules        = fileSecurity.GetAccessRules(true, true, usersSid.GetType()).OfType <FileSystemAccessRule>();

                return(rules.Where(r => r.FileSystemRights.HasFlag(permissionFlag)).Any());
            }

            //
            // Linux

            AccessModes accessMode = 0;

            if (permissionFlag.HasFlag(FileSystemRights.Read))
            {
                accessMode |= AccessModes.R_OK;
            }

            if (permissionFlag.HasFlag(FileSystemRights.Write))
            {
                accessMode |= AccessModes.W_OK;
            }

            if (permissionFlag.HasFlag(FileSystemRights.ExecuteFile))
            {
                accessMode |= AccessModes.X_OK;
            }

            var unixFileInfo = new Mono.Unix.UnixFileInfo(FullPath);

            return(unixFileInfo.CanAccess(accessMode));
        }
		private static int FromAccessModes (AccessModes value, out Int32 rval)
		{
			throw new System.NotImplementedException();
		}
Пример #27
0
 private static int ToAccessModes(Int32 value, out AccessModes rval)
 {
     throw new System.NotImplementedException();
 }
		private static int ToAccessModes (Int32 value, out AccessModes rval)
		{
			throw new System.NotImplementedException();
		}
Пример #29
0
 internal static extern int access(string path, AccessModes amode);
Пример #30
0
 private static int FromAccessModes(AccessModes value, out Int32 rval)
 {
     throw new System.NotImplementedException();
 }
Пример #31
0
 public FieldAttribute(string FieldName, AccessModes AccessMode, bool IsOptional)
     : this(FieldName, false, AccessMode, IsOptional) { }
Пример #32
0
		private static extern int FromAccessModes (AccessModes value, out Int32 rval);
Пример #33
0
        /// <summary>
        /// Sets the access mode on the device.
        /// </summary>
        internal void SetAccessMode(AccessModes newMode)
        {
            if (newMode == _accessMode)
            {
                log.DebugFormat("Skipping SetAccessMode: New access mode ({0}) is the same as the current one.", newMode);
                return;
            }

            if ((int)newMode < (int)_accessMode)
            {
                log.DebugFormat("Skipping SetAccessMode: New access mode ({0}) lower than the current one.", newMode);
                return;
            }

            byte[] dig;
            switch (newMode)
            {
            case AccessModes.Operator:
                dig = new byte[] { 59, 117, 101, 94 };
                break;

            case AccessModes.Maintenance:
                dig = new byte[] { 85, 119, 0, 230 };
                break;

            case AccessModes.AuthorizedClient:
                dig = new byte[] { 251, 53, 108, 222 };
                break;

            case AccessModes.Service:
                dig = new byte[] { 237, 120, 75, 170 };
                break;

            default:
                throw new NotImplementedException($"Changing to access level of {newMode} is not supported by MetriCam 2.");
            }

            byte[] commandAsBytes = Encoding.ASCII.GetBytes("sMN SetAccessMode ");
            Array.Resize(ref commandAsBytes, commandAsBytes.Length + 1 + dig.Length);
            int offsetOfMode = commandAsBytes.Length - dig.Length - 1;

            commandAsBytes[offsetOfMode] = (byte)newMode;
            for (int i = commandAsBytes.Length - dig.Length, j = 0; i < commandAsBytes.Length; i++, j++)
            {
                commandAsBytes[i] = dig[j];
            }
            SendCommand(commandAsBytes);

            bool success = ReceiveResponse(out byte[] payload, out byte checkSum);

            if (!success)
            {
                throw new InvalidOperationException($"Failed to set access mode to {newMode} (no response).");
            }

            byte cmdSuccess = payload[payload.Length - 1];

            if (0 == cmdSuccess)
            {
                throw new InvalidOperationException($"Failed to set access mode to {newMode} (not successful).");
            }

            _accessMode = newMode;
            log.DebugFormat("Access mode set to {0}", newMode);
        }
Пример #34
0
 public bool HasAccess(AccessModes mode)
 {
     return ((this.AccessMode & mode) == mode);
 }
Пример #35
0
 public void DeleteAccessModes(AccessModes accessModes)
 {
     _accessModesDal.Delete(accessModes);
 }
Пример #36
0
 public AccessModes UpdateAccessModes(AccessModes accessModes)
 {
     return(_accessModesDal.Update(accessModes));
 }
Пример #37
0
 public AccessModes AddAccessModes(AccessModes accessModes)
 {
     return(_accessModesDal.Add(accessModes));
 }
Пример #38
0
 protected override Errno OnAccessPath(string path, AccessModes mask)
 {
     return(WithLogging(
                () => fileSystemRepository.GetAccessToPath(path, mask),
                $"OnAccessPath({path}, {mask})"));
 }
Пример #39
0
 public virtual Errno OnAccessPath(string path, AccessModes mode)
 {
     return(Errno.ENOSYS);
 }
Пример #40
0
 public override Errno OnAccessPath(string path, AccessModes mode)
 {
     return(Access(GetTargetPath(path), mode));
 }
Пример #41
0
		public static bool TryFromAccessModes (AccessModes value, out Int32 rval)
		{
			return FromAccessModes (value, out rval) == 0;
		}
Пример #42
0
 public bool CanAccess(AccessModes mode)
 {
     return(Syscall.access(this.FullPath, mode) == 0);
 }
Пример #43
0
		private static extern int ToAccessModes (Int32 value, out AccessModes rval);
Пример #44
0
 public FieldAttribute(string FieldName, bool IsKey, AccessModes AccessMode)
     : this(FieldName, IsKey, AccessMode, false) { }
Пример #45
0
 public override Errno AccessPath(string path, AccessModes mask)
 {
     String readPath = _pathFactory.CreateVirtualPath4Read(new VirtualRawPath(path));
       return base.AccessPath(readPath, mask);
 }
Пример #46
0
 protected override Errno OnAccessPath(string path, AccessModes mode)
 {
     if ((mode & AccessModes.W_OK) != 0)
         return Errno.EROFS;
     try
     {
         Entry fsEntry = walker.SearchEntry(path.Substring(1));
         if (fsEntry == null)
             return Errno.ENOENT;
         if (((mode & AccessModes.X_OK) != 0) && (fsEntry.Kind == EntryKind.ZipFileEntry))
             return Errno.EACCES;
     }
     catch (DirectoryNotFoundException)
     {
         return Errno.ENOTDIR;
     }
     catch (IOException)
     {
         return Errno.EIO;
     }
     return 0;
 }
Пример #47
0
 public FieldAttribute(string FieldName, AccessModes AccessMode)
     : this(FieldName, false, AccessMode) { }
Пример #48
0
		public static bool TryToAccessModes (Int32 value, out AccessModes rval)
		{
			return ToAccessModes (value, out rval) == 0;
		}
Пример #49
0
        protected override Errno OnAccessPath(string path, AccessModes mask)
        {
            Logger.WriteLineIf(LogLevel.Verbose, _fslog_props, string.Format("OnAccessPath, path={0}, mask={1}", path, mask));

              return this._rfs.AccessPath(path, mask);
        }