8

The scenario is like this:

In a Linux based handheld device I have a C app which has dbus APIs ready to be called by 3rd party apps. The DBus APIs are called during booting time.

Is there any system API I can use to in my functions to print the caller's ID and save it to syslog?

Thanks in advance!

tao
  • 251
  • 3
  • 13

1 Answers1

4

/org/freedesktop/DBus object on the org.freedesktop.DBus bus has two methods belonging to the org.freedesktop.DBus interface (oh, well): GetConnectionUnixUser and GetConnectionUnixProcessID. Both accept a string—unique connection name which can be obtained by calling dbus_message_get_sender (or whatever method your high-level API wrapper offers).

rkhayrov
  • 10,040
  • 2
  • 35
  • 40
  • 3
    It’s worth pointing out that since this answer was written, the `org.freedesktop.DBus.GetConnectionCredentials` method has been added too, which should be used in preference to `GetConnectionUnixUser` and `GetConnectionUnixProcessID`. It means one method call instead of two, eliminates some race conditions, and gives you additional information about security labels. See the specification: https://dbus.freedesktop.org/doc/dbus-specification.html#bus-messages-get-connection-credentials – Philip Withnall Jun 22 '17 at 10:10
  • Credentials-object won't get peer unix user ID nor process ID in all cases as there are multiple types of authentication available. – Jari Turkia Jul 10 '22 at 09:55