PAM_XDG(8)

πŸ“¦
version 0.8.5 Β· 2 versions
, in nixos 26.05, nixpkgs unstable

✨ PAM_XDG(8) ✨

okay so bestie, you know how your XDG dirs are just... vibes and chaos if nobody sets them up? yeah. this module is the one that handles all of that. it's pam_xdg.so from the System Manager's Manual section 8, and honestly it's giving main character energy in your PAM stack. πŸ’…


🌸 NAME 🌸

pam_xdg.so β€” a PAM module that manages XDG Base Directories. that's it, that's the whole thing. it makes the dirs and sets the vars. obsessed. πŸŽ€


✨ SYNOPSIS ✨

pam_xdg.so [runtime] [notroot] [track_sessions [per_user_lock]]

no dashes, no equals signs, just vibes and bare words in the module line. note that per_user_lock only makes sense together with track_sessions β€” it's nested in there. iykyk. πŸ¦‹


πŸ’– DESCRIPTION πŸ’–

pam_xdg.so is a PAM module that manages creation of the XDG_RUNTIME_DIR directory, plus it injects environment variables denoting all the directories specified by the XDG Base Directory Specification 0.8 into user sessions. here's the spec link, copy it exactly bestie:

https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html

so like, when it's linked into the PAM session system, the runtime directory gets created once a user creates his or her first login session. 🫢

unless runtime was given, all XDG related environment variables will be created in all user sessions with their default or computed values β€” otherwise only XDG_RUNTIME_DIR. so runtime is the "just the runtime dir, thanks" mode. lowkey minimalist of it.

if notroot was given, the module will bypass itself for root account logins and perform no actions for root, except removing any possibly existing XDG environment variable. so root gets nothing set, and any leftover XDG vars get yeeted. respectfully. πŸ™ˆ

lastly, track_sessions will enable session tracking: once the last session ends, the user's XDG_RUNTIME_DIR will be recursively removed. 🧹 on high-load servers, then setting per_user_lock will reduce lock file lock contention. highkey useful if you've got a busy box, ngl.


πŸŽ€ how to actually install it (the config part) πŸŽ€

in order to make use of this module, place the following in the session part of the control file of desire under /etc/pam.d. on Linux it may be /etc/pam.d/common-session if that exists. on BSD's the files /etc/pam.d/system as well as /etc/pam.d/login, /etc/pam.d/sshd and /etc/pam.d/su may be desirable. adjusting paths as necessary, obviously, you know your system better than i do:

session optional pam_xdg.so notroot track_sessions

look at her. iconic line. put her where she belongs. ⭐


πŸ”₯ SEE ALSO πŸ”₯

go read those if you want the full lore. 🌈


πŸ‘‘ AUTHORS πŸ‘‘

Steffen Nurpmeso <steffen@sdaoden.eu>. that's the legend who wrote this. periodt. πŸ’œ


πŸ’€ CAVEATS πŸ’€

okay this part matters, so listen up.

on Unix systems, any "daemonized" program or script is reparented to the program running with PID 1, most likely leaving the PAM user session without PAM recognizing this. 😭

yet careless such code may hold or expect availability of resources of the session it just left β€” truly performing cleanup when sessions end seems thus unwise. like, if you rip the rug out from under something that's still standing on it, that's gonna be a bad time.

since so many PAM modules do support session tracking and cleanup, pam_xdg.so readded optional support for this. so like... it's back, but it's opt-in, and now you know why. πŸ¦‹

seriously though, if you're daemonizing stuff out of a session, think before you track_sessions. the module is doing what you asked, and what you asked might be spicy. πŸ”₯

and that's the whole page bestie!! πŸ’– this one's from the Debian packaging, dated Nov 27, 2024, and it's literally PAM_XDG(8) β€” go set your env vars, you gorgeous creature. πŸŽ€βœ¨πŸ«Ά

πŸ“¦ where this page comes from