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

Merge dev into master (closes #182) #425

Merged
merged 15 commits into from
Aug 12, 2022
26 changes: 23 additions & 3 deletions src/inputs.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <ctype.h>

void handle_desktop(void* input_struct, struct tb_event* event)
{
Expand Down Expand Up @@ -76,6 +77,7 @@ void handle_text(void* input_struct, struct tb_event* event)
void input_desktop(struct desktop* target)
{
target->list = NULL;
target->list_simple = NULL;
target->cmd = NULL;
target->display_server = NULL;
target->cur = 0;
Expand Down Expand Up @@ -176,7 +178,8 @@ void input_desktop_add(
{
++(target->len);
target->list = realloc(target->list, target->len * (sizeof (char*)));
target->cmd = realloc(target->cmd, target->len * (sizeof (char*)));
target->list_simple = realloc(target->list_simple, target->len * (sizeof (char*)));
target->cmd = realloc(target->cmd, target->len * (sizeof (char*)));
target->display_server = realloc(
target->display_server,
target->len * (sizeof (enum display_server)));
Expand All @@ -190,8 +193,25 @@ void input_desktop_add(
return;
}

target->list[target->cur] = name;
target->cmd[target->cur] = cmd;
target->list[target->cur] = name;

int name_len = strlen(name);
char* name_simple = malloc(name_len);

memcpy(name_simple, name, name_len);

if (strstr(name_simple, " ") != NULL)
{
name_simple = strtok(name_simple, " ");
}

for (int i = 0; i < name_len; i++)
{
name_simple[i] = tolower(name_simple[i]);
}

target->list_simple[target->cur] = name_simple;
target->cmd[target->cur] = cmd;
target->display_server[target->cur] = display_server;
}

Expand Down
1 change: 1 addition & 0 deletions src/inputs.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ struct text
struct desktop
{
char** list;
char** list_simple;
char** cmd;
enum display_server* display_server;

Expand Down
19 changes: 9 additions & 10 deletions src/login.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,14 @@ void env_xdg_session(const enum display_server display_server)
}
}

void env_xdg(const char* tty_id)
void env_xdg(const char* tty_id, const char* desktop_name)
{
char user[15];
snprintf(user, 15, "/run/user/%d", getuid());
setenv("XDG_RUNTIME_DIR", user, 0);
setenv("XDG_SESSION_CLASS", "user", 0);
setenv("XDG_SESSION_ID", "1", 0);
setenv("XDG_SESSION_DESKTOP", desktop_name, 0);
setenv("XDG_SEAT", "seat0", 0);
setenv("XDG_VTNR", tty_id, 0);
}
Expand Down Expand Up @@ -475,16 +476,20 @@ void auth(
{
int ok;

char tty_id [3];
snprintf(tty_id, 3, "%d", config.tty);

// Add XDG environment variables
env_xdg_session(desktop->display_server[desktop->cur]);
env_xdg(tty_id, desktop->list_simple[desktop->cur]);

// open pam session
const char* creds[2] = {login->text, password->text};
struct pam_conv conv = {login_conv, creds};
struct pam_handle* handle;

ok = pam_start(config.service_name, NULL, &conv, &handle);

// Set XDG_SESSION_TYPE earlier to fix some bugs
env_xdg_session(desktop->display_server[desktop->cur]);

if (ok != PAM_SUCCESS)
{
pam_diagnose(ok, buf);
Expand Down Expand Up @@ -585,10 +590,7 @@ void auth(
}

// get a display
char tty_id [3];
char vt[5];

snprintf(tty_id, 3, "%d", config.tty);
snprintf(vt, 5, "vt%d", config.tty);

// set env
Expand All @@ -607,9 +609,6 @@ void auth(
putenv(env[i]);
}

// add xdg variables
env_xdg(tty_id);

// execute
int ok = chdir(pwd->pw_dir);

Expand Down