superuser 4.1.3 copy "superuser: ^4.1.3" to clipboard
superuser: ^4.1.3 copied to clipboard

Detect, verify user who execute Dart CLI or Flutter program has superuser role and running with superuser permission with replicated UNIX identification commands.

Superuser detection for Dart CLI or Flutter desktop application #

Superuser is a special user, who granted as much as possible to access system files for maintenance purpose. Different systems has different names to refer superuser (e.g. root in various UNIX system and Administrator in Windows).

Although pub.dev has numerous of packages to detect superuser, they are designed for Flutter app for Android and some packages added iOS support already. Hence, these package may become bulky because of unnessary callbacks along with detection only.

Instead, superuser package offers superuser detection in Dart CLI or Flutter desktop and two replicated identification command from UNIX (whoami and group) for additional verification if necessary.

Limitations #

This package only tested using informations given on local machines only. Although it can run in domain joined machine since 4.0.0, only local scope can be extracted that any entities related with Activity Directory or LDAP are omitted.

For UNIX (or POSIX for more accuracely), Since /etc/sudoers only accessible via visudo only that it minimize chance of malfunction due to misconfiguration, but forbidden of read access makes impossible to programmically determine the executor is in corresponded group that it is granted to elevate. Therefore, except the program is invoked by root itself, condition of classifying user has admin right is determined by inspecting a group, which related to sudo commands in DEFAULT setting:

Group name Applied UNIX based platform (and distro)
sudo Linux in Debian-based (i.e. Debian, Ubuntu)
admin Darwin (macOS*)
wheel Default group for most UNIX platforms (i.e. FreeBSD, Fedora, OpenSUSE, etc...)

*: Although wheel group still exists because of inheritance of FreeBSD, most users created with admin right from macOS setting ONLY assigned admin group only.

If any non-default groups can invoke sudo due to modification of /etc/sudoers file, inspecting Superuser.groups is the most preferred workaround solution:

const Set<String> additionalSudoGpNames = <String>{
    "circle",
    "ring"
};

bool get isAdditionalAdminGroups =>
    additionalSudoGpNames.any(Superuser.groups.containsByString);

Implementations #

Production #

lld must be installed in the Linux already before build:

# Debian based
sudo apt install lld

# Fedora based
sudo dnf install lld

Testing or simulating with mock interface #

For testing, MockSuperuser must be binded already before performing widget test:

import 'package:flutter_test/flutter_test.dart';
import 'package:superuser/instance.dart';
import 'package:superuser/mock.dart';

void main() {
    setUpAll(() {
        // Bind mock instance here
        SuperuserInstance.bindInstance(
            MockSuperuser(whoAmI: "reonaw"),
        );
    });
    // Do any testes below
}

If using for debug simulation, mock interface must be binded before runApp:

import 'package:flutter/widgets.dart';
import 'package:superuser/instance.dart';
import 'package:superuser/mock.dart';

void main() {
    SuperuserInstance.bindInstance(
        MockSuperuser(
            whoAmI: "hiderik",
            isSuperuser: true,
            isActivated: true,
        ),
    );

    runApp(const YourApp());
}

To alter string detection staregy, it is possible to achieve by applying matchingFlag:

import 'package:flutter/widgets.dart';
import 'package:superuser/instance.dart';
import 'package:superuser/mock.dart';

void main() {
    // Either `yuunagit` or `YUUNAGIT` can be matched by using `OSString.<=` operation in `whoami`.
    SuperuserInstance.bindInstance(
        MockSuperuser(
            whoAmI: "yuunagit",
            matchingFlag: OSString.MATCH_CAPITAL,
        ),
    );

    runApp(const YourApp());
}

Value of matchingFlag has been mentioned in OSString's constructor method already.

Demo #

Demo application of superuser has been available in release page in Windows and Linux application.

These demo animations are for reference only, conditions and contents may be differ without notice.

Open without superuser right #

Open demo application oridinary

Open with superuser right #

Open demo application with superuser right

License #

BSD-3

4
likes
160
points
402
downloads

Documentation

API reference

Publisher

verified publisherrk0cc.xyz

Weekly Downloads

Detect, verify user who execute Dart CLI or Flutter program has superuser role and running with superuser permission with replicated UNIX identification commands.

Homepage
Repository (GitHub)
View/report issues

Topics

#superuser #root #admin #administrator #ffi

Funding

Consider supporting this project:

github.com

License

BSD-3-Clause (license)

Dependencies

meta, superuser_interfaces, superuser_plugin_unix, superuser_plugin_windows

More

Packages that depend on superuser