Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optionally pass auth client to dbus client #384

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/dbus.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export 'src/dbus_address.dart';
export 'src/dbus_auth_client.dart';
export 'src/dbus_client.dart';
export 'src/dbus_introspect.dart';
export 'src/dbus_method_call.dart';
Expand Down
9 changes: 7 additions & 2 deletions lib/src/dbus_auth_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class DBusAuthClient {
var _unixFdSupported = false;
DBusUUID? _uuid;
String? _errorMessage;
final String? _uid;

/// Stream of requests to send to the authentication server.
Stream<String> get requests => _requestsController.stream;
Expand All @@ -35,7 +36,9 @@ class DBusAuthClient {
String? get errorMessage => _errorMessage;

/// Creates a new authentication client.
DBusAuthClient({bool requestUnixFd = true}) : _requestUnixFd = requestUnixFd {
DBusAuthClient({bool requestUnixFd = true, String? uid})
: _requestUnixFd = requestUnixFd,
_uid = uid {
// On start, end an empty byte, as this is required if sending the credentials as a socket control message.
// We rely on the server using SO_PEERCRED to check out credentials.
// Then request the supported mechanisms.
Expand Down Expand Up @@ -126,7 +129,9 @@ class DBusAuthClient {
/// Start authentication using the EXTERNAL mechanism.
void _authenticateExternal() {
String authId;
if (Platform.isLinux) {
if (_uid != null) {
authId = _uid!;
} else if (Platform.isLinux) {
authId = getuid().toString();
} else if (Platform.isWindows) {
authId = getsid();
Expand Down
12 changes: 8 additions & 4 deletions lib/src/dbus_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class DBusClient {
RawSocket? _socket;
var _socketClosed = false;
final _readBuffer = DBusReadBuffer();
final _authClient = DBusAuthClient();
final DBusAuthClient _authClient;
var _authComplete = false;
Completer? _connectCompleter;
var _lastSerial = 0;
Expand Down Expand Up @@ -243,11 +243,15 @@ class DBusClient {

/// Creates a new DBus client to connect on [address].
/// If [messageBus] is false, then the server is not running a message bus and
/// no adresses or client to client communication is suported.
/// no addresses or client to client communication is supported.
/// If [authClient] is provided, it will be used instead of creating a new one.
DBusClient(DBusAddress address,
{this.introspectable = true, bool messageBus = true})
{this.introspectable = true,
bool messageBus = true,
DBusAuthClient? authClient})
: _address = address,
_messageBus = messageBus;
_messageBus = messageBus,
_authClient = authClient ?? DBusAuthClient();

/// Creates a new DBus client to communicate with the system bus.
factory DBusClient.system({bool introspectable = true}) {
Expand Down
Loading