예제 #1
0
        static void Recurse(string path)
        {
            try
            {
                var fInfo = UnixFileInfo.GetFileSystemEntry(path);
                try
                {
                    fInfo.SetOwner(restrictedUser, restrictedGroup);
                    Console.WriteLine($"Changed ownership for '{fInfo.FullName}'");
                }
                catch (Exception any)
                {
                    Console.WriteLine($"Error: {any.Message}");
                }

                if (fInfo is UnixDirectoryInfo)
                {
                    var dInfo   = fInfo as UnixDirectoryInfo;
                    var content = dInfo.GetFileSystemEntries();
                    foreach (var currentEntry in content)
                    {
                        Recurse(currentEntry.FullName);
                    }
                }
            }
            catch (Exception any)
            {
                Console.WriteLine($"Error {any.GetType().Name}: {any.Message}");
            }
        }
        public void UpdatePermissionsOnUnixUsingMonoPosix()
        {
            var fileSystemEntry = UnixFileSystemInfo.GetFileSystemEntry("path");

            fileSystemEntry.FileAccessPermissions = FileAccessPermissions.UserRead;
            fileSystemEntry.FileAccessPermissions = FileAccessPermissions.UserWrite;
            fileSystemEntry.FileAccessPermissions = FileAccessPermissions.UserExecute;
            fileSystemEntry.FileAccessPermissions = FileAccessPermissions.UserReadWriteExecute;

            fileSystemEntry.FileAccessPermissions = FileAccessPermissions.GroupRead;
            fileSystemEntry.FileAccessPermissions = FileAccessPermissions.GroupWrite;
            fileSystemEntry.FileAccessPermissions = FileAccessPermissions.GroupExecute;
            fileSystemEntry.FileAccessPermissions = FileAccessPermissions.GroupReadWriteExecute;

            fileSystemEntry.FileAccessPermissions = FileAccessPermissions.UserRead | FileAccessPermissions.GroupRead;

            fileSystemEntry.FileAccessPermissions = FileAccessPermissions.AllPermissions;                                                               // Noncompliant (DefaultPermissions | OtherExecute | GroupExecute | UserExecute, // 0x000001FF)
            fileSystemEntry.FileAccessPermissions = FileAccessPermissions.DefaultPermissions;                                                           // Noncompliant (OtherWrite | OtherRead | GroupWrite | GroupRead | UserWrite | UserRead, // 0x000001B6)
            fileSystemEntry.FileAccessPermissions = FileAccessPermissions.OtherReadWriteExecute;                                                        // Noncompliant
            fileSystemEntry.FileAccessPermissions = FileAccessPermissions.OtherExecute;                                                                 // Noncompliant
            fileSystemEntry.FileAccessPermissions = FileAccessPermissions.OtherWrite;                                                                   // Noncompliant
            fileSystemEntry.FileAccessPermissions = FileAccessPermissions.OtherRead;                                                                    // Noncompliant {{Make sure this permission is safe.}}

            fileSystemEntry.FileAccessPermissions |= FileAccessPermissions.AllPermissions;                                                              // Noncompliant (DefaultPermissions | OtherExecute | GroupExecute | UserExecute, // 0x000001FF)
            fileSystemEntry.FileAccessPermissions |= FileAccessPermissions.DefaultPermissions;                                                          // Noncompliant (OtherWrite | OtherRead | GroupWrite | GroupRead | UserWrite | UserRead, // 0x000001B6)
            fileSystemEntry.FileAccessPermissions |= FileAccessPermissions.OtherReadWriteExecute;                                                       // Noncompliant
            fileSystemEntry.FileAccessPermissions |= FileAccessPermissions.OtherExecute;                                                                // Noncompliant
            fileSystemEntry.FileAccessPermissions |= FileAccessPermissions.OtherWrite;                                                                  // Noncompliant
            fileSystemEntry.FileAccessPermissions |= FileAccessPermissions.OtherRead;                                                                   // Noncompliant

            fileSystemEntry.FileAccessPermissions ^= FileAccessPermissions.AllPermissions;                                                              // Noncompliant - depending on the case this might add or remove permissions
            fileSystemEntry.FileAccessPermissions ^= FileAccessPermissions.DefaultPermissions;                                                          // Noncompliant
            fileSystemEntry.FileAccessPermissions ^= FileAccessPermissions.OtherReadWriteExecute;                                                       // Noncompliant
            fileSystemEntry.FileAccessPermissions ^= FileAccessPermissions.OtherExecute;                                                                // Noncompliant
            fileSystemEntry.FileAccessPermissions ^= FileAccessPermissions.OtherWrite;                                                                  // Noncompliant
            fileSystemEntry.FileAccessPermissions ^= FileAccessPermissions.OtherRead;                                                                   // Noncompliant

            fileSystemEntry.FileAccessPermissions = FileAccessPermissions.UserRead | FileAccessPermissions.GroupRead | FileAccessPermissions.OtherRead; // Noncompliant
//                                                                                                                                           ^^^^^^^^^
            UnixFileInfo.GetFileSystemEntry("path").FileAccessPermissions         = FileAccessPermissions.AllPermissions;                               // Noncompliant
            UnixSymbolicLinkInfo.GetFileSystemEntry("path").FileAccessPermissions = FileAccessPermissions.AllPermissions;                               // Noncompliant

            if (fileSystemEntry.FileAccessPermissions != FileAccessPermissions.OtherExecute)
            {
            }
            while (fileSystemEntry.FileAccessPermissions != FileAccessPermissions.OtherExecute)
            {
            }
            _ = fileSystemEntry.FileAccessPermissions == FileAccessPermissions.OtherWrite ? 1 : 2;

            fileSystemEntry.FileAccessPermissions = ~((FileAccessPermissions.OtherRead));
            fileSystemEntry.FileAccessPermissions = ~FileAccessPermissions.OtherRead;
        }
예제 #3
0
        public void Can_download_osx_runtime()
        {
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                RuntimeManager.DownloadRuntimeToDirectory(QmlNetConfig.QtBuildVersion, RuntimeTarget.OSX64, _tempDirectory);
                File.ReadAllText(Path.Combine(_tempDirectory, "version.txt")).Should().Be($"{QmlNetConfig.QtBuildVersion}-osx-x64");

                var permissions = UnixFileInfo
                                  .GetFileSystemEntry(Path.Combine(_tempDirectory, "qt", "lib", "QtXml.framework", "Versions", "5", "QtXml"))
                                  .FileAccessPermissions;
                permissions.Should().Be(FileAccessPermissions.UserReadWriteExecute
                                        | FileAccessPermissions.GroupRead | FileAccessPermissions.GroupExecute
                                        | FileAccessPermissions.OtherRead | FileAccessPermissions.OtherExecute);

                // Make sure links are setup correctly.
                Directory.Exists(Path.Combine(_tempDirectory, "qt", "lib", "QtXml.framework", "Versions", "Current")).Should().BeTrue();
            }
        }
예제 #4
0
        /// <summary>
        /// Starts the updating process.
        /// </summary>
        /// <returns>TRUE if successful; If FALSE use Updater.LastError to get the error</returns>
        public static bool Update()
        {
            if (!IsAppImage)
            {
                logs.Add(new LogMessage(Logseverity.Error, "Updater.Update", "This app is not packaged in an AppImage"));
                return(false);
            }

            if (!ready)
            {
                logs.Add(new LogMessage(Logseverity.Error, "Updater.Update", "Updater is not ready yet"));
                return(false);
            }

            // First, create a backup
            logs.Add(new LogMessage(Logseverity.Info, "Updater.Update", "Creating backup"));
            try {
                File.Copy(AppImagePath, AppImagePath + "~", true);
            }
            catch (Exception ex) {
                // I'd be very suprised if this throws an exception
                logs.Add(new LogMessage(Logseverity.Error, "Updater.Update", $"An exception of type {ex.GetType()} was thrown, this is most likely an internal library error", ex));
                return(false);
            }

            // Mark as executable
            logs.Add(new LogMessage(Logseverity.Info, "Updater.Update", "Marking as executable"));
            try {
                var _file = UnixFileInfo.GetFileSystemEntry(downloadPath);
                // This will do for now...
                _file.FileAccessPermissions = FileAccessPermissions.UserReadWriteExecute;
            }
            catch (Exception ex) {
                logs.Add(new LogMessage(Logseverity.Error, "Updater.Update", $"An exception of type {ex.GetType()} was thrown, this is most likely an internal library error", ex));
                return(false);
            }

            // Then overwrite
            logs.Add(new LogMessage(Logseverity.Info, "Updater.Update", "Overwriting"));
            try {
                File.Delete(AppImagePath);
                File.Move(downloadPath, AppImagePath);
            }
            catch (Exception ex) {
                logs.Add(new LogMessage(Logseverity.Error, "Updater.Update", $"An exception of type {ex.GetType()} was thrown, this is most likely an internal library error", ex));
                return(false);
            }

            // Delete backups
            logs.Add(new LogMessage(Logseverity.Info, "Updater.Update", "Deleting backup"));
            try {
                File.Delete(AppImagePath + "~");
            }
            catch (Exception ex) {
                logs.Add(new LogMessage(Logseverity.Error, "Updater.Update", $"An exception of type {ex.GetType()} was thrown, this is most likely an internal library error", ex));
                return(false);
            }

            logs.Add(new LogMessage(Logseverity.Info, "Updater.Update", "Done, restarting the app is recommended"));

            return(true);
        }