jeanparpaillon / erlang-dbus

Erlang DBUS implementation (forked from unmaintained erlang-dbus)
Apache License 2.0
52 stars 22 forks source link

auth external: Resolve current user to cookie #39

Closed mpotra closed 2 years ago

mpotra commented 2 years ago

Currently, the connection to the unix socket fails when using External auth mech for any user that does not have the UID 1000 The reason is that the default cookie is set for UID 1000, and for example root user has UID 0 which fails the auth.

While there is the option to provide a different cookie via the external_cookie application env variable, this PR introduces the system_user value as a way of automatically attempting to determine the correct UID and set the hex-encoded cookie accordingly.

The steps are, somewhat similar to what session_sha1 mech does, but expanded:

This way, by simply setting application:set_env(dbus, external_cookie, system_user) from any application that relies on erlang-dbus, the UID is resolved automatically or fails gracefully to the default.

mpotra commented 2 years ago

lgtm, I am wondering why you using custom run_command function, but this is ok for me.

In case run_command is justified, might it be moved to another module for reuse ?

Ah, indeed, there was no other need for it, so I've removed it and placed the body within the calling function. Thanks for pointing it out to me