Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use XDG_RUNTIME_DIR for storing Xauthority #330

Merged
merged 2 commits into from
Jun 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 29 additions & 16 deletions src/login.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,31 @@ void remove_utmp_entry(struct utmp *entry) {
endutent();
}

void xauth(const char* display_name, const char* shell, const char* dir)
void xauth(const char* display_name, const char* shell, char* pwd)
{
const char* xauth_file = ".lyxauth";
char* xauth_dir = getenv("XDG_RUNTIME_DIR");
if ((xauth_dir == NULL) || (*xauth_dir == '\0'))
{
xauth_dir = getenv("XDG_CONFIG_DIR");
if ((xauth_dir == NULL) || (*xauth_dir == '\0'))
{
xauth_dir = pwd;
xauth_file = "lyxauth";
}
}
else
{
xauth_file = "lyxauth";
}

// trim trailing slashes
int i = strlen(xauth_dir) - 1;
while (xauth_dir[i] == '/') i--;
xauth_dir[i + 1] = '\0';

char xauthority[256];
snprintf(xauthority, 256, "%s/%s", dir, ".lyxauth");
snprintf(xauthority, 256, "%s/%s", xauth_dir, xauth_file);
setenv("XAUTHORITY", xauthority, 1);
setenv("DISPLAY", display_name, 1);

Expand Down Expand Up @@ -343,18 +364,10 @@ void xorg(
const char* vt,
const char* desktop_cmd)
{
// generate xauthority file
const char* xauth_dir = getenv("XDG_CONFIG_HOME");

if ((xauth_dir == NULL) || (*xauth_dir == '\0'))
{
xauth_dir = pwd->pw_dir;
}
UtkarshVerma marked this conversation as resolved.
Show resolved Hide resolved

char display_name[4];

snprintf(display_name, 3, ":%d", get_free_display());
xauth(display_name, pwd->pw_shell, xauth_dir);
xauth(display_name, pwd->pw_shell, pwd->pw_dir);

// start xorg
pid_t pid = fork();
Expand Down Expand Up @@ -531,7 +544,7 @@ void auth(
if (pwd->pw_shell[0] == '\0')
{
setusershell();

char* shell = getusershell();

if (shell != NULL)
Expand All @@ -552,7 +565,7 @@ void auth(

if (pid == 0)
{
// set user info
// set user info
ok = initgroups(pwd->pw_name, pwd->pw_gid);

if (ok != 0)
Expand Down Expand Up @@ -658,21 +671,21 @@ void auth(

// close pam session
ok = pam_do(pam_close_session, handle, 0, buf);

if (ok != PAM_SUCCESS)
{
return;
}

ok = pam_do(pam_setcred, handle, PAM_DELETE_CRED, buf);

if (ok != PAM_SUCCESS)
{
return;
}

ok = pam_end(handle, 0);

if (ok != PAM_SUCCESS)
{
pam_diagnose(ok, buf);
Expand Down