getConnectionCredentials method

Future<DBusProcessCredentials> getConnectionCredentials(
  1. String name
)

Returns credentials for the process running the client that owns name.

Implementation

Future<DBusProcessCredentials> getConnectionCredentials(String name) async {
  var result = await callMethod(
      destination: 'org.freedesktop.DBus',
      path: DBusObjectPath('/org/freedesktop/DBus'),
      interface: 'org.freedesktop.DBus',
      name: 'GetConnectionCredentials',
      values: [DBusString(name)],
      replySignature: DBusSignature('a{sv}'));
  var credentials = result.returnValues[0].asStringVariantDict();
  int? unixUserId;
  List<int>? unixGroupIds;
  int? processId;
  String? windowsSid;
  List<int>? linuxSecurityLabel;
  var otherCredentials = <String, DBusValue>{};
  credentials.forEach((key, value) {
    switch (key) {
      case 'UnixUserID':
        if (value.signature != DBusSignature('u')) {
          throw 'org.freedesktop.DBus.GetConnectionCredentials returned invalid signature on UnixUserID: ${value.signature.value}';
        }
        unixUserId = value.asUint32();
        break;
      case 'UnixGroupIDs':
        if (value.signature != DBusSignature('au')) {
          throw 'org.freedesktop.DBus.GetConnectionCredentials returned invalid signature on UnixGroupIDs: ${value.signature.value}';
        }
        unixGroupIds = value.asUint32Array().toList();
        break;
      case 'ProcessID':
        if (value.signature != DBusSignature('u')) {
          throw 'org.freedesktop.DBus.GetConnectionCredentials returned invalid signature on ProcessID: ${value.signature.value}';
        }
        processId = value.asUint32();
        break;
      case 'WindowsSID':
        if (value.signature != DBusSignature('s')) {
          throw 'org.freedesktop.DBus.GetConnectionCredentials returned invalid signature on WindowsSID: ${value.signature.value}';
        }
        windowsSid = value.asString();
        break;
      case 'LinuxSecurityLabel':
        if (value.signature != DBusSignature('ay')) {
          throw 'org.freedesktop.DBus.GetConnectionCredentials returned invalid signature on LinuxSecurityLabel: ${value.signature.value}';
        }
        linuxSecurityLabel = value.asByteArray().toList();
        break;
      default:
        otherCredentials[key] = value;
        break;
    }
  });
  return DBusProcessCredentials(
      unixUserId: unixUserId,
      unixGroupIds: unixGroupIds,
      processId: processId,
      windowsSid: windowsSid,
      linuxSecurityLabel: linuxSecurityLabel,
      otherCredentials: otherCredentials);
}