diff --git a/lib/src/dbus_auth_client.dart b/lib/src/dbus_auth_client.dart index a6c3f06..75f6ed1 100644 --- a/lib/src/dbus_auth_client.dart +++ b/lib/src/dbus_auth_client.dart @@ -1,9 +1,10 @@ import 'dart:async'; import 'dart:io'; +import 'package:posix/posix.dart'; + import 'dbus_uuid.dart'; -import 'getsid.dart'; -import 'getuid.dart'; +import 'getsid.dart' as getsid; /// A client for D-Bus authentication. class DBusAuthClient { @@ -129,7 +130,7 @@ class DBusAuthClient { if (Platform.isLinux) { authId = getuid().toString(); } else if (Platform.isWindows) { - authId = getsid(); + authId = getsid.getsid(); } else { throw 'Authentication not supported on ${Platform.operatingSystem}'; } diff --git a/lib/src/dbus_client.dart b/lib/src/dbus_client.dart index fe3ca35..4092699 100644 --- a/lib/src/dbus_client.dart +++ b/lib/src/dbus_client.dart @@ -2,6 +2,8 @@ import 'dart:async'; import 'dart:convert'; import 'dart:io'; +import 'package:posix/posix.dart'; + import 'dbus_address.dart'; import 'dbus_auth_client.dart'; import 'dbus_bus_name.dart'; @@ -22,7 +24,6 @@ import 'dbus_read_buffer.dart'; import 'dbus_signal.dart'; import 'dbus_value.dart'; import 'dbus_write_buffer.dart'; -import 'getuid.dart'; /// Reply received when calling [DBusClient.requestName]. enum DBusRequestNameReply { primaryOwner, inQueue, exists, alreadyOwner } diff --git a/lib/src/dbus_server.dart b/lib/src/dbus_server.dart index db3ce6b..77e8d91 100644 --- a/lib/src/dbus_server.dart +++ b/lib/src/dbus_server.dart @@ -3,6 +3,8 @@ import 'dart:convert'; import 'dart:io'; import 'dart:math'; +import 'package:posix/posix.dart'; + import 'dbus_address.dart'; import 'dbus_auth_server.dart'; import 'dbus_bus_name.dart'; @@ -20,7 +22,6 @@ import 'dbus_read_buffer.dart'; import 'dbus_uuid.dart'; import 'dbus_value.dart'; import 'dbus_write_buffer.dart'; -import 'getuid.dart'; /// Results of starting a service. enum DBusServerStartServiceResult { success, alreadyRunning, notFound } diff --git a/lib/src/getuid.dart b/lib/src/getuid.dart deleted file mode 100644 index 6911ed4..0000000 --- a/lib/src/getuid.dart +++ /dev/null @@ -1,2 +0,0 @@ -// Conditionally import the FFI version, so this doesn't break web builds. -export 'getuid_stub.dart' if (dart.library.ffi) 'getuid_linux.dart'; diff --git a/lib/src/getuid_linux.dart b/lib/src/getuid_linux.dart deleted file mode 100644 index de6a516..0000000 --- a/lib/src/getuid_linux.dart +++ /dev/null @@ -1,16 +0,0 @@ -import 'dart:ffi'; -import 'dart:io'; - -typedef _GetuidC = Int32 Function(); -typedef _GetuidDart = int Function(); - -/// Gets the user ID of the current user. -int getuid() { - if (!Platform.isLinux) { - throw 'Unable to determine UID on this system'; - } - - final dylib = DynamicLibrary.open('libc.so.6'); - final getuidP = dylib.lookupFunction<_GetuidC, _GetuidDart>('getuid'); - return getuidP(); -} diff --git a/lib/src/getuid_stub.dart b/lib/src/getuid_stub.dart deleted file mode 100644 index ebfe08b..0000000 --- a/lib/src/getuid_stub.dart +++ /dev/null @@ -1,4 +0,0 @@ -/// Gets the user ID of the current user. -int getuid() { - throw 'Unable to determine UID on this system'; -} diff --git a/pubspec.yaml b/pubspec.yaml index 48c9a82..2d29bdf 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -18,6 +18,7 @@ dependencies: args: ^2.0.0 ffi: ^2.0.0 meta: ^1.3.0 + posix: ^5.0.0 xml: ^6.1.0 dev_dependencies: diff --git a/test/dbus_test.dart b/test/dbus_test.dart index 6079e2e..84078be 100644 --- a/test/dbus_test.dart +++ b/test/dbus_test.dart @@ -9,7 +9,7 @@ import 'package:dbus/src/dbus_match_rule.dart'; import 'package:dbus/src/dbus_member_name.dart'; import 'package:dbus/src/dbus_message.dart'; import 'package:dbus/src/dbus_uuid.dart'; -import 'package:dbus/src/getuid.dart'; +import 'package:posix/posix.dart'; import 'package:test/test.dart'; // Test server that exposes an activatable service.