aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/openrc-pam/openrc-pam.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/openrc-pam/openrc-pam.c b/src/openrc-pam/openrc-pam.c
index d4b39da8..2803ae94 100644
--- a/src/openrc-pam/openrc-pam.c
+++ b/src/openrc-pam/openrc-pam.c
@@ -15,7 +15,7 @@
#include "queue.h"
static int
-inc_dec_lockfile(pam_handle_t *pamh, int val)
+inc_dec_lockfile(const char *runtimedir, int val)
{
char *lockfile_path = NULL;
FILE *lockfile = NULL;
@@ -24,7 +24,7 @@ inc_dec_lockfile(pam_handle_t *pamh, int val)
elog(LOG_INFO, "locking lockfile");
- xasprintf(&lockfile_path, "%s/openrc/%s", pam_getenv(pamh, "XDG_RUNTIME_DIR"), "lock");
+ xasprintf(&lockfile_path, "%s/%s", runtimedir, "lock");
lockfile = fopen(lockfile_path, "r+");
if (!lockfile) {
lockfile = fopen(lockfile_path, "w+");
@@ -168,12 +168,15 @@ exec_user_cmd(struct passwd *pw, char *cmd, char **envlist)
static char *create_rc_runtime_dir(struct passwd *pw) {
char *path = NULL;
- if (mkdir("/run/openrc/user", 0755) != 0 && errno != EEXIST)
+ if (mkdir("/run/openrc/user", 0755) != 0 && errno != EEXIST) {
+ elog(LOG_ERR, "Failed to mkdir %s: %s", path, strerror(errno));
return NULL;
+ }
xasprintf(&path, "/run/openrc/user/%d/", pw->pw_uid);
if (mkdir(path, 0700) != 0 && errno != EEXIST) {
+ elog(LOG_ERR, "Failed to mkdir %s: %s", path, strerror(errno));
free(path);
return NULL;
}
@@ -200,6 +203,7 @@ static bool exec_openrc(pam_handle_t *pamh, const char *runlevel, bool lock) {
const char *username;
struct passwd *pw = NULL;
char *openrc_runtime_dir;
+ const char *xdg_runtime_dir;
char *openrc_runtime_dir_env;
char **envlist;
char **env;
@@ -211,7 +215,8 @@ static bool exec_openrc(pam_handle_t *pamh, const char *runlevel, bool lock) {
return false;
/* avoid setting RC_RUNTIME_DIR if XDG_RUNTIME_DIR is already set by the user's stack */
- if (pam_getenv(pamh, "XDG_RUNTIME_DIR") == NULL) {
+ if ((xdg_runtime_dir = pam_getenv(pamh, "XDG_RUNTIME_DIR"))) {
+ elog(LOG_INFO, "Setting up RC_RUNTIME_DIR");
openrc_runtime_dir = create_rc_runtime_dir(pw);
if (!openrc_runtime_dir) {
return false;
@@ -219,10 +224,11 @@ static bool exec_openrc(pam_handle_t *pamh, const char *runlevel, bool lock) {
xasprintf(&openrc_runtime_dir_env, "RC_RUNTIME_DIR=%s", openrc_runtime_dir);
pam_putenv(pamh, openrc_runtime_dir_env);
- elog(LOG_INFO, "exporting: %s", openrc_runtime_dir_env);
+ elog(LOG_INFO, "Exporting: %s", openrc_runtime_dir_env);
free(openrc_runtime_dir_env);
} else {
- xasprintf(&openrc_runtime_dir, "%s/%s", pam_getenv(pamh, "XDG_RUNTIME_DIR"), "openrc");
+ elog(LOG_INFO, "Using XDG_RUNTIME_DIR");
+ xasprintf(&openrc_runtime_dir, "%s/%s", xdg_runtime_dir, "openrc");
if (mkdir(openrc_runtime_dir, 0700) != 0 && errno != EEXIST) {
free(openrc_runtime_dir);
return false;
@@ -230,6 +236,7 @@ static bool exec_openrc(pam_handle_t *pamh, const char *runlevel, bool lock) {
}
if (chown(openrc_runtime_dir, pw->pw_uid, pw->pw_gid) != 0) {
+ elog(LOG_ERR, "failed to chown %s", openrc_runtime_dir);
rmdir(openrc_runtime_dir);
free(openrc_runtime_dir);
return false;
@@ -241,7 +248,7 @@ static bool exec_openrc(pam_handle_t *pamh, const char *runlevel, bool lock) {
/* if we are locking, reduce the count by 1,
* because we don't want to count ourselves */
- lockval = inc_dec_lockfile(pamh, lock ? 1 : -1) - lock == true ? 1 : 0;
+ lockval = inc_dec_lockfile(openrc_runtime_dir, lock ? 1 : -1) - lock == true ? 1 : 0;
if (lockval == 0) {
elog(LOG_INFO, "Executing %s for user %s", cmd, username);