- if (safe_mkdir(buf, 0700, pw->pw_uid, pw->pw_gid) < 0) {
- pam_syslog(handle, LOG_WARNING, "Failed to create runtime directory: %m");
- r = PAM_SYSTEM_ERR;
- goto finish;
- } else if ((r = pam_misc_setenv(handle, "XDG_RUNTIME_DIR", buf, 0)) != PAM_SUCCESS) {
- pam_syslog(handle, LOG_ERR, "Failed to set runtime dir.");
- goto finish;
- }
-
- free(buf);
- buf = NULL;
-
- if (create_session) {
- const char *id;
-
- /* Reuse or create XDG session ID */
- if (!(id = pam_getenv(handle, "XDG_SESSION_ID"))) {
- int mode;
-
- if (asprintf(&buf, "%llux", (unsigned long long) get_session_id(&mode)) < 0) {
- r = PAM_BUF_ERR;
- goto finish;
- }
-
- /* To avoid id clashes we add the session id
- * source to our session ids. Note that the
- * session id source might change during
- * runtime, because a filesystem became
- * writable or the system reconfigured. */
- buf[strlen(buf)-1] =
- mode != SESSION_ID_AUDIT ? (char) mode : 0;
-
- if ((r = pam_misc_setenv(handle, "XDG_SESSION_ID", buf, 0)) != PAM_SUCCESS) {
- pam_syslog(handle, LOG_ERR, "Failed to set session id.");
- goto finish;
- }
-
- if (!(id = pam_getenv(handle, "XDG_SESSION_ID"))) {
- pam_syslog(handle, LOG_ERR, "Failed to get session id.");
- r = PAM_SESSION_ERR;
- goto finish;
- }
- }
-
- r = asprintf(&buf, "/user/%s/%s", username, id);
- } else
- r = asprintf(&buf, "/user/%s/master", username);