Who called my DBus API in Linux system
Asked Answered
E

1

9

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!

Empson answered 4/5, 2011 at 14:43 Comment(0)
B
5

/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).

Buie answered 21/5, 2011 at 10:22 Comment(2)
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: dbus.freedesktop.org/doc/…Bromic
Credentials-object won't get peer unix user ID nor process ID in all cases as there are multiple types of authentication available.Glide

© 2022 - 2024 — McMap. All rights reserved.