Skip to content

Commit d60825a

Browse files
committed
Merge branch 'next'
2 parents a819b13 + 85ab72d commit d60825a

31 files changed

+860
-305
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.vscode/

superuser/CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
## 2.0.0
2+
3+
* Add user's joined group in local machine scope.
4+
5+
## 2.0.0-m.1
6+
7+
* `isSuperuser` can returns true without superuser permission activated.
8+
* Windows: Uses `NetUserGetLocalGroups` to find current user is a member of `Administrators`.
9+
* UNIX: Determine user joined default `sudo` command enabled groups (`admin` in macOS, `sudo` in Linux).
10+
* Expand UNIX's error code to unsigned 32-bits length with two 16-bits segmentes:
11+
* Lower 16-bits reuses origin error numbers from libraries.
12+
* Upper 16-bits denotes error categories that causing error thrown.
13+
114
## 1.0.2
215

316
* Add assertion to prevent using mock interface in release mode.

superuser/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ void main() {
4848

4949
Demo application of `superuser` has been available in [release page](https://github.com/rk0cc/superuser/releases) in Windows and Linux application.
5050

51+
These demo animations are for reference only, conditions and contents may be differ without notice.
52+
5153
### Open without superuser right
5254

5355
![Open demo application oridinary](https://github.com/user-attachments/assets/5b973019-c6d6-4466-9f60-01c86b06c1c8)

superuser/example/lib/main.dart

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,38 @@ class Context extends StatelessWidget {
5858

5959
@override
6060
Widget build(BuildContext context) {
61+
void onDisplayingGroups() async {
62+
await showDialog<void>(
63+
context: context,
64+
barrierDismissible: false,
65+
builder: (context) {
66+
List<String> gpList = Superuser.groups.toList(growable: false);
67+
68+
return AlertDialog(
69+
title: const Text("Groups"),
70+
content:
71+
Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
72+
Text("Total joined groups: ${gpList.length}"),
73+
SizedBox(
74+
width: 400,
75+
height: 275,
76+
child: ListView.builder(
77+
shrinkWrap: true,
78+
itemCount: gpList.length,
79+
itemBuilder: (context, index) =>
80+
ListTile(title: Text(gpList[index]))))
81+
]),
82+
actions: <TextButton>[
83+
TextButton(
84+
onPressed: () {
85+
Navigator.pop(context);
86+
},
87+
child: const Text("OK"))
88+
],
89+
);
90+
});
91+
}
92+
6193
return Scaffold(
6294
appBar: AppBar(title: const Text("Superuser")),
6395
drawer: Drawer(
@@ -121,7 +153,13 @@ class Context extends StatelessWidget {
121153
child: ListTile(
122154
title: const Text("Run as superuser", style: _titleStyle),
123155
trailing: Text(Superuser.isActivated ? "Yes" : "No",
124-
style: _valueStyle)))
156+
style: _valueStyle))),
157+
const Divider(),
158+
ListTile(
159+
title: const Text("Group"),
160+
trailing: ElevatedButton(
161+
onPressed: onDisplayingGroups,
162+
child: const Text("List all joined groups")))
125163
]));
126164
}
127165
}

superuser/example/pubspec.lock

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -211,31 +211,29 @@ packages:
211211
path: ".."
212212
relative: true
213213
source: path
214-
version: "1.0.1"
214+
version: "2.0.0"
215215
superuser_interfaces:
216216
dependency: transitive
217217
description:
218218
name: superuser_interfaces
219-
sha256: e7725726dfe90c535e8907149e255cc0647dc9dd7b08bb4286727e16c1915a35
219+
sha256: "483e04fc06f00035a94c77d35db6d44afe4b5022171c50bf58db3e267495a0b3"
220220
url: "https://pub.dev"
221221
source: hosted
222-
version: "2.0.0"
222+
version: "2.1.0"
223223
superuser_plugin_unix:
224224
dependency: transitive
225225
description:
226-
name: superuser_plugin_unix
227-
sha256: d0786e1fe844e22594108f12dd2ab8f99b84618376b421122b5a2c2853c34f13
228-
url: "https://pub.dev"
229-
source: hosted
230-
version: "1.0.0"
226+
path: "../../superuser_plugin_unix"
227+
relative: true
228+
source: path
229+
version: "2.0.0"
231230
superuser_plugin_windows:
232231
dependency: transitive
233232
description:
234-
name: superuser_plugin_windows
235-
sha256: "7531992b26f70cb0f3d1c76ba7e45c76968aa447039c6444e64deafce5e04e3f"
236-
url: "https://pub.dev"
237-
source: hosted
238-
version: "1.0.0"
233+
path: "../../superuser_plugin_windows"
234+
relative: true
235+
source: path
236+
version: "2.0.0"
239237
term_glyph:
240238
dependency: transitive
241239
description:

superuser/example/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: superuser_demo
22
description: "Flutter superuser package demo application"
33
publish_to: 'none'
4-
version: 1.0.0
4+
version: 2.0.0
55
environment:
66
sdk: '>=3.4.0 <4.0.0'
77
dependencies:
@@ -15,6 +15,6 @@ dependencies:
1515
dev_dependencies:
1616
flutter_test:
1717
sdk: flutter
18-
flutter_lints: ^4.0.0
18+
flutter_lints: ^4.0.0
1919
flutter:
2020
uses-material-design: true

superuser/lib/src/instance.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:superuser_plugin_unix/superuser_plugin_unix.dart';
77
import 'package:superuser_plugin_windows/superuser_plugin_windows.dart';
88

99
import 'exception.dart';
10+
import 'utils.dart';
1011

1112
SuperuserInterface? _instance;
1213

@@ -45,17 +46,16 @@ abstract final class SuperuserInstance {
4546
/// the provided interface should not be closed. Otherwise,
4647
/// it throws [ArgumentError].
4748
///
48-
/// In [kReleaseMode] or non widget testing process, [suInterface] will not
49-
/// accept [MockSuperuser] and throw [IllegalInstanceError] instead. Therefore,
50-
/// ensure all dummy data are removed already.
49+
/// [suInterface] can only accept [MockSuperuser] if [kDebugMode]
50+
/// or it performs widget testing. Using mock interface in
51+
/// [kReleaseMode] or [kProfileMode] causes [IllegalInstanceError]
52+
/// throw.
5153
static void bindInstance(SuperuserInterface? suInterface) {
5254
if (!Platform.isWindows && !Platform.isMacOS && !Platform.isLinux) {
5355
throw UnsupportedError("Unknown platform");
5456
}
5557

56-
if (kReleaseMode &&
57-
!Platform.environment.containsKey("FLUTTER_TEST") &&
58-
suInterface is MockSuperuser) {
58+
if (!kUnderDevelop && suInterface is MockSuperuser) {
5959
throw IllegalInstanceError(
6060
"Mock instance cannot be used in release mode.");
6161
}

superuser/lib/src/utils.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import 'dart:io';
2+
3+
import 'package:flutter/foundation.dart';
4+
import 'package:meta/meta.dart';
5+
6+
@internal
7+
bool get kUnderDevelop =>
8+
kDebugMode || Platform.environment.containsKey("FLUTTER_TEST");

superuser/lib/superuser.dart

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,33 @@ abstract final class Superuser {
2727
const Superuser._();
2828

2929
/// Determine this program is executed by a user, who is superuser exactly or
30-
/// one of members in superuser group.
30+
/// one of members in superuser group that it is possible to toggle [isActivated]
31+
/// (it can be executed with restricted permission that making [isActivated] retains
32+
/// false).
33+
///
34+
/// For UNIX platform, it returns true if user who execute this program is `root`
35+
/// or a member of built-in group that can uses `sudo` command. (`admin` for macOS
36+
/// or `sudo` for majority of Linux systems).
37+
///
38+
/// In Windows, it returns true if current user is a member of `Administrators`
39+
/// group in local machine. This detection does not consider Active Directory
40+
/// users.
3141
static bool get isSuperuser => instance.isSuperuser;
3242

33-
/// Determine this program is running with superuser role.
43+
/// Determine this program is running with superuser role that it can
44+
/// access and modify protected location programmatically.
3445
///
35-
/// If this getter called in UNIX platforms (macOS or Linux),
36-
/// it is an alias getter of [isSuperuser] since `root` is one and only
37-
/// user can be represented as superuser.
46+
/// UNIX platforms (macOS and Linux) only consider executor is `root`,
47+
/// whatever how this program called.
3848
///
3949
/// For Windows platform, it consider this process has been elevated
40-
/// or not.
50+
/// or not, which should be positive if and only if user granted UAC
51+
/// prompt.
4152
static bool get isActivated => instance.isActivated;
4253

4354
/// Obtain username who call current program.
4455
static String get whoAmI => instance.whoAmI;
56+
57+
/// Obtain user's associated groups in local system.
58+
static Iterable<String> get groups => instance.groups;
4559
}

superuser/pubspec.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: superuser
22
description: Detect, verify user who execute Flutter program has superuser role and running with superuser permission.
3-
version: 1.0.2
3+
version: 2.0.0
44
homepage: https://github.com/rk0cc/superuser
55
repository: https://github.com/rk0cc/superuser/tree/main/superuser
66
funding:
@@ -18,9 +18,9 @@ dependencies:
1818
flutter:
1919
sdk: flutter
2020
meta: ^1.12.0
21-
superuser_interfaces: ^2.0.0
22-
superuser_plugin_unix: ^1.0.0
23-
superuser_plugin_windows: ^1.0.0
21+
superuser_interfaces: ^2.1.0
22+
superuser_plugin_unix: ^2.0.0
23+
superuser_plugin_windows: ^2.0.0
2424
dev_dependencies:
2525
flutter_lints: ^4.0.0
2626
platforms:

0 commit comments

Comments
 (0)