summaryrefslogtreecommitdiff
path: root/pam/gkr-pam-client.c
diff options
context:
space:
mode:
authorJacob Keller <jacob.keller@gmail.com>2018-10-05 00:47:27 -0700
committerJacob Keller <jacob.keller@gmail.com>2018-10-05 00:47:27 -0700
commitb22d058a055ec3e0f31ae16417f16b42baadb42f (patch)
treed34fa9f9daad7964d60822d55f40dcbbd4a4d36c /pam/gkr-pam-client.c
parentaace7a266a37a7e9a915060189e48b9ebd2552f2 (diff)
downloadgnome-keyring-b22d058a055ec3e0f31ae16417f16b42baadb42f.tar.gz
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 2ca51a0aef5b ("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>
Diffstat (limited to 'pam/gkr-pam-client.c')
-rw-r--r--pam/gkr-pam-client.c17
1 files changed, 3 insertions, 14 deletions
diff --git a/pam/gkr-pam-client.c b/pam/gkr-pam-client.c
index 71766c1d..ebb7f798 100644
--- a/pam/gkr-pam-client.c
+++ b/pam/gkr-pam-client.c
@@ -148,27 +148,16 @@ lookup_daemon (struct passwd *pwd,
struct sockaddr_un *addr)
{
struct stat st;
- const char *suffix;
- if (control == NULL) {
- control = getenv ("XDG_RUNTIME_DIR");
- if (control == NULL)
- return GKD_CONTROL_RESULT_NO_DAEMON;
- suffix = "/keyring/control";
- } else {
- suffix = "/control";
- }
-
- if (strlen (control) + strlen (suffix) + 1 > sizeof (addr->sun_path)) {
- syslog (GKR_LOG_ERR, "gkr-pam: address is too long for unix socket path: %s/%s",
- control, suffix);
+ if (strlen (control) + 1 > sizeof (addr->sun_path)) {
+ syslog (GKR_LOG_ERR, "gkr-pam: address is too long for unix socket path: %s",
+ control);
return GKD_CONTROL_RESULT_FAILED;
}
memset (addr, 0, sizeof (*addr));
addr->sun_family = AF_UNIX;
strcpy (addr->sun_path, control);
- strcat (addr->sun_path, suffix);
/* A bunch of checks to make sure nothing funny is going on */
if (lstat (addr->sun_path, &st) < 0) {