pam: lookup XDG_RUNTIME_DIR using get_any_env

The pam_gnome_keyring.so PAM module needs to find the daemon control
file, which is stored in $XDG_RUNTIME_DIR/keyring/control.
Unfortunately when commit 2ca51a0a ("daemon: Stop exporting the
$GNOME_KEYRING_CONTROL env variable", 2014-03-06) switched to using
XDG_RUNTIME_DIR preferentially over GNOME_KEYRING_CONTROL, it was looked
up using getenv().

Unfortunately XDG_RUNTIME_DIR isn't always set in the environment, but
may need to be looked up from pam_getenv. Indeed, the function
get_any_env already exists for this purpose.

Because of the incorrect environment lookup, lookup_daemon will
incorrectly report that the gnome-keyring-daemon is not running, even
though it is. This results in starting the daemon multiple times, and
potentially failing to shut it down, or start it correctly when changing
the password.

To fix this, move the code for determining the control file path from
gkr-pam-client.c into gkr-pam-module.c This will using get_any_env(),
and avoids the need for passing the pam_handle_t variable into
gkr-pam-client.c

It does mean that the control variable must be allocated with space,
since we need to combine the environment value with a different suffix
depending on if we use GNOME_KEYRING_CONTROL or XDG_RUNTIME_DIR.

Add a function get_control_file, so that the logic for determining the
control file path remains in one location.

Signed-off-by: Jacob Keller <jacob.keller@gmail.com>
6 jobs for jk-fix-reading-xdg-runtime-dir in 18 minutes and 51 seconds (queued for 88 minutes and 30 seconds)
Status Job ID Name Coverage
  Build
passed #117043
fedora:asan

00:04:22

passed #117045
fedora:coverage

00:04:27

71.4%
passed #117044
fedora:ubsan

00:04:13

passed #117042
fedora:Werror

00:05:22

 
  Deploy
passed #117046
pages

00:00:24

passed pages:deploy

00:00:00