Woof.LinuxAdmin 5.0.3

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
Additional Details

Early development versions had limited API and low-level compatibility issues. As low-level issues are considered dangerous, you should use the latest package version that was well tested on several x64 and ARM64 devices and virtual machines.

There is a newer version of this package available.
See the version list below for details.
dotnet add package Woof.LinuxAdmin --version 5.0.3
NuGet\Install-Package Woof.LinuxAdmin -Version 5.0.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Woof.LinuxAdmin" Version="5.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Woof.LinuxAdmin --version 5.0.3
#r "nuget: Woof.LinuxAdmin, 5.0.3"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Woof.LinuxAdmin as a Cake Addin
#addin nuget:?package=Woof.LinuxAdmin&version=5.0.3

// Install Woof.LinuxAdmin as a Cake Tool
#tool nuget:?package=Woof.LinuxAdmin&version=5.0.3

Woof.LinuxAdmin

.NET extension created by CodeDog

Distributed under MIT License. (c)2021 by CodeDog, All rights reserved.


About

A set of Linux administration tools using system calls and shell. Made because .NET doesn't have Linux-specific functions, like Linux permission operations or a support for Linux users and groups.

There are other packages like Mono.Posix.NETStandard or TmdS.libc, but the first one focuses on completness, the other one is not easy to use.

This toolset is lightweight and super easy to use.

I aimed at making it compatible with many modern Linux systems, it might not work with a specific distro and / or hardware platform.

If the package doesn't work with your configuration - please kindly open a GitHub issue providing details about your platform and how to reproduce the problem.

Design

The core of the library is Linux native Syscall class. It contains the signatures for libc system calls. There is a minimalistic set of feature used, just to enable basic Linux file system operations.

Original naming convention is dropped for .NET naming and signatures style.

The managed functions sit in Linux static class.

There's also a FileSystem static class containing CopyDirectoryContent() helper.

For convenience, there is Shell class with Exec method to simplify executing shell commands and getting their output.

The functions mostly return bool values indicating that the operation was successful.

AddSystemUserAsync(), AddSystemGroupAsync() methods

The only asynchronous methods in Linux static class. They are asynchronous since they use shell to call useradd and groupadd.

Chmod(), ChmodR(), Chown(), ChownR()

Chmod changes permissions on a file system entry. You can provide permissions as follows:

  • octal string, like "664" (absolute read/write for user and group, read for others)
  • relative string, like "ug+rw,o-w", "+x" and so on,
  • binary - as uint Linux mode.

Conversions between string, uint and Permissions are made implicitly.

Special permission "X" also works, setting executable bit if the entry is a directory or has at least one executable bit set.

It is important, that the execute permissions cannot be set on unreadable entries. When the entry doesn't have a read permission for the specified target it's execute bit will not be set for that target.

Chown changes an owner of a file system entry. It works with string names only.

To change permissions and / or owner for all entries in a directory including the directory itself use ChmodR() and ChownR() methods.

Other tools

For the administration it's useful to check if the program has administrative privileges. To do so use Linux.IsRoot property.

Performance hint

To set absolute permissions use octal strings (or binary) to skip calling stat on each entry. Also, internal __xstat is a bit system specific so it might not work on all Linux systems.

Security

The package does not use unsafe code and no p/invoke implementation details are public. However, caution is advised when using Shell, because when running on root account it gives the application the full control over the target system.

Compatibility

The package is compatible with .NET 5.0 or newer. Tested on Ubuntu Ubuntu 20.04.3 LTS.

It's not guaranteed that __xstat and dependent Linux.Chmod() and Linux.ChmodR() functions will work on your distro. Test before use.

In case of a compatibility issue - create an issue on Github.


Disclaimer

Woof Toolkit is a work in progress in constant development, however it's carefully maintained with production code quality.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net5.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Woof.LinuxAdmin:

Package Downloads
Woof.ServiceInstaller The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

Registers and unregisters a project executable as either Windows Service or systemd deamon. Works both on Windows and Linux.

Woof.DataProtection.Linux The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

Provides data protection API for Linux.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
7.0.0 220 8/6/2023
6.2.0 652 2/20/2022
6.1.2 571 11/27/2021
6.1.1 1,742 11/26/2021
6.1.0 1,448 11/26/2021
6.0.3 592 11/15/2021
6.0.2 333 11/15/2021
6.0.1 727 11/9/2021
6.0.0 390 11/9/2021
5.2.1 481 11/8/2021
5.2.0 421 11/8/2021
5.1.1 688 11/5/2021
5.1.0 407 11/4/2021
5.0.5 470 11/1/2021
5.0.4 374 11/1/2021
5.0.3 536 10/31/2021
5.0.2 588 10/30/2021
5.0.1 472 10/30/2021
5.0.0 470 10/28/2021

ADD: Permissions.IsMatch(), better documentation.