mirror of
https://github.com/javalsai/lidm.git
synced 2026-02-27 03:50:44 +01:00
feat: support Xorg & better auth logic (#80)
Co-authored-by: grialion <48643945+grialion@users.noreply.github.com>
This commit is contained in:
@@ -6,7 +6,8 @@
|
||||
#include "config.h"
|
||||
#include "sessions.h"
|
||||
|
||||
bool launch(char* user, char* passwd, struct session session, void (*cb)(void),
|
||||
struct config* config);
|
||||
bool launch(char* NNULLABLE user, char* NNULLABLE passwd,
|
||||
struct session session, void (*NULLABLE cb)(void),
|
||||
struct config* NNULLABLE config);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "macros.h"
|
||||
#include "util.h"
|
||||
|
||||
enum introspection_type {
|
||||
enum IntrospectionType {
|
||||
STRING,
|
||||
BOOL,
|
||||
NUMBER,
|
||||
@@ -26,7 +26,7 @@ static const char* NNULLABLE const INTROS_TYS_NAMES[] = {
|
||||
struct introspection_item {
|
||||
char* NNULLABLE name;
|
||||
size_t offset;
|
||||
enum introspection_type typ;
|
||||
enum IntrospectionType typ;
|
||||
};
|
||||
|
||||
#define INTROS_ITEM(key, table, ty) \
|
||||
@@ -90,10 +90,10 @@ BUILD(colors, COLORS, TABLE_COLORS);
|
||||
BUILD(chars, CHARS, TABLE_CHARS);
|
||||
|
||||
#define TABLE_FUNCTIONS(F, name) \
|
||||
F(enum keys, poweroff, KEY, F1, name) \
|
||||
F(enum keys, reboot, KEY, F2, name) \
|
||||
F(enum keys, fido, KEY, NONE, name) \
|
||||
F(enum keys, refresh, KEY, F5, name)
|
||||
F(enum Keys, poweroff, KEY, F1, name) \
|
||||
F(enum Keys, reboot, KEY, F2, name) \
|
||||
F(enum Keys, fido, KEY, NONE, name) \
|
||||
F(enum Keys, refresh, KEY, F5, name)
|
||||
|
||||
BUILD(functions, FUNCTIONS, TABLE_FUNCTIONS);
|
||||
|
||||
@@ -152,15 +152,15 @@ struct introspection_table {
|
||||
|
||||
static const struct introspection_table CONFIG_INSTROSPECTION[] = {
|
||||
{"colors", offsetof(struct config, colors), INTROS_TABLE_COLORS,
|
||||
sizeof(INTROS_TABLE_COLORS) / sizeof(INTROS_TABLE_COLORS[0])},
|
||||
LEN(INTROS_TABLE_COLORS)},
|
||||
{"chars", offsetof(struct config, chars), INTROS_TABLE_CHARS,
|
||||
sizeof(INTROS_TABLE_CHARS) / sizeof(INTROS_TABLE_CHARS[0])},
|
||||
LEN(INTROS_TABLE_CHARS)},
|
||||
{"functions", offsetof(struct config, functions), INTROS_TABLE_FUNCTIONS,
|
||||
sizeof(INTROS_TABLE_FUNCTIONS) / sizeof(INTROS_TABLE_FUNCTIONS[0])},
|
||||
LEN(INTROS_TABLE_FUNCTIONS)},
|
||||
{"strings", offsetof(struct config, strings), INTROS_TABLE_STRINGS,
|
||||
sizeof(INTROS_TABLE_STRINGS) / sizeof(INTROS_TABLE_STRINGS[0])},
|
||||
LEN(INTROS_TABLE_STRINGS)},
|
||||
{"behavior", offsetof(struct config, behavior), INTROS_TABLE_BEHAVIOR,
|
||||
sizeof(INTROS_TABLE_BEHAVIOR) / sizeof(INTROS_TABLE_BEHAVIOR[0])},
|
||||
LEN(INTROS_TABLE_BEHAVIOR)},
|
||||
};
|
||||
|
||||
//// FUNCTIONS
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
#ifndef DESKTOP_EXEC_H_
|
||||
#define DESKTOP_EXEC_H_
|
||||
// TODO: rewrite properly
|
||||
// NOLINTBEGIN(clang-diagnostic-nullability-completeness)
|
||||
|
||||
#ifndef DESKTOP_EXEC_H_
|
||||
#define DESKTOP_EXEC_H_
|
||||
|
||||
#include "macros.h"
|
||||
|
||||
char* NULLABLE search_path(const char* NNULLABLE for_binary);
|
||||
int execvpe_desktop(char** args, char* NNULLABLE* NNULLABLE envlist);
|
||||
int parse_exec_string(const char* exec_s, int* arg_count, char*** args);
|
||||
void free_parsed_args(int arg_count, char** args);
|
||||
|
||||
#endif
|
||||
// NOLINTEND(clang-diagnostic-nullability-completeness)
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
enum keys {
|
||||
enum Keys {
|
||||
ESC,
|
||||
F1,
|
||||
F2,
|
||||
@@ -68,7 +68,7 @@ static const char* const KEY_NAMES[] = {
|
||||
};
|
||||
|
||||
struct key_mapping {
|
||||
enum keys key;
|
||||
enum Keys key;
|
||||
const char* sequences[3];
|
||||
};
|
||||
|
||||
|
||||
@@ -7,25 +7,25 @@
|
||||
#endif
|
||||
|
||||
// Do we just replace the compiler with clang??
|
||||
#if defined(__clang__)
|
||||
#ifdef __clang__
|
||||
#define NULLABLE _Nullable
|
||||
#else
|
||||
#define NULLABLE
|
||||
#endif
|
||||
|
||||
#if defined(__clang__)
|
||||
#ifdef __clang__
|
||||
#define NNULLABLE _Nonnull
|
||||
#else
|
||||
#define NNULLABLE
|
||||
#endif
|
||||
|
||||
#if defined(__clang__)
|
||||
#ifdef __clang__
|
||||
#define UNULLABLE _Null_unspecified
|
||||
#else
|
||||
#define UNULLABLE
|
||||
#endif
|
||||
|
||||
#if defined(__clang__)
|
||||
#ifdef __clang__
|
||||
#define COMPILER_VERSION __VERSION__
|
||||
#elif defined(__GNUC__)
|
||||
#define xstr(s) str(s)
|
||||
@@ -36,5 +36,6 @@
|
||||
#endif
|
||||
|
||||
#define LEN(X) (sizeof(X) / sizeof((X)[0]))
|
||||
#define UNUSED(x) ((void)(x))
|
||||
|
||||
#endif
|
||||
|
||||
33
include/pam.h
Normal file
33
include/pam.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#ifndef PAM_H
|
||||
#define PAM_H
|
||||
|
||||
#include <pwd.h>
|
||||
#include <security/_pam_types.h>
|
||||
#include <security/pam_appl.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "macros.h"
|
||||
#include "sessions.h"
|
||||
|
||||
#define PAMH_ERR_NOERR 0
|
||||
#define PAMH_ERR_ALLOC 1
|
||||
#define PAMH_ERR_ERRNO 2
|
||||
#define PAMH_ERR_NOERRNO 3
|
||||
|
||||
struct pamh_getenv_status {
|
||||
char error_flag;
|
||||
union {
|
||||
char* NULLABLE* NNULLABLE envlist;
|
||||
const char* NNULLABLE errfn;
|
||||
};
|
||||
};
|
||||
|
||||
// Doesn't include `source`s
|
||||
struct pamh_getenv_status pamh_get_complete_env(pam_handle_t* NNULLABLE handle,
|
||||
struct passwd* NNULLABLE pw,
|
||||
enum SessionType session_typ);
|
||||
|
||||
void free_envlist(char* NULLABLE* NNULLABLE envlist);
|
||||
pam_handle_t* NULLABLE get_pamh(char* NNULLABLE user, char* NNULLABLE passwd);
|
||||
|
||||
#endif /* PAM_H */
|
||||
@@ -2,21 +2,71 @@
|
||||
#define SESSIONSH_
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "desktop_exec.h"
|
||||
#include "macros.h"
|
||||
#include "util.h"
|
||||
|
||||
enum session_type {
|
||||
enum SessionType {
|
||||
XORG,
|
||||
WAYLAND,
|
||||
SHELL,
|
||||
};
|
||||
|
||||
enum ExecType {
|
||||
EXEC_SHELL,
|
||||
EXEC_DESKTOP,
|
||||
};
|
||||
|
||||
struct desktop_exec {
|
||||
char* NULLABLE* NNULLABLE args;
|
||||
int arg_count;
|
||||
};
|
||||
|
||||
struct session_exec {
|
||||
enum ExecType typ;
|
||||
union {
|
||||
char* NNULLABLE shell;
|
||||
struct desktop_exec desktop;
|
||||
};
|
||||
};
|
||||
|
||||
static inline struct session_exec session_exec_shell(char* NNULLABLE shell) {
|
||||
return (struct session_exec){
|
||||
.typ = EXEC_SHELL,
|
||||
.shell = shell,
|
||||
};
|
||||
}
|
||||
|
||||
static inline struct session_exec session_exec_desktop(
|
||||
int arg_count, char* NULLABLE* NNULLABLE args) {
|
||||
return (struct session_exec){
|
||||
.typ = EXEC_DESKTOP,
|
||||
.desktop =
|
||||
{
|
||||
.args = args,
|
||||
.arg_count = arg_count,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
static inline int session_exec_exec(struct session_exec* NNULLABLE exec,
|
||||
char* NULLABLE* NNULLABLE envlist) {
|
||||
switch (exec->typ) {
|
||||
case EXEC_SHELL:
|
||||
return execle(exec->shell, exec->shell, NULL, envlist);
|
||||
case EXEC_DESKTOP:
|
||||
return execvpe_desktop(exec->desktop.args, envlist);
|
||||
default:
|
||||
__builtin_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
struct session {
|
||||
char* NNULLABLE name;
|
||||
char* NNULLABLE exec;
|
||||
char* NULLABLE tryexec;
|
||||
enum session_type type;
|
||||
struct session_exec exec;
|
||||
enum SessionType type;
|
||||
};
|
||||
|
||||
struct Vector get_avaliable_sessions();
|
||||
|
||||
8
include/signal_handler.h
Normal file
8
include/signal_handler.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef SIGNALHANDLERH_
|
||||
#define SIGNALHANDLERH_
|
||||
|
||||
// handle SIGTERM by sending SIGTERM to all children, resulting
|
||||
// in a graceful graphical shutdown
|
||||
void setup_sigterm();
|
||||
|
||||
#endif /* SIGNALHANDLERH_ */
|
||||
@@ -39,7 +39,7 @@
|
||||
#define VALUES_SEPR 3
|
||||
#define VALUE_MAXLEN (BOX_WIDTH - VALUES_COL + 1 - BOX_HMARGIN - 2)
|
||||
|
||||
enum input { SESSION, USER, PASSWD };
|
||||
enum Input { SESSION, USER, PASSWD };
|
||||
extern const u_char INPUTS_N;
|
||||
|
||||
void setup(struct config* config);
|
||||
@@ -49,7 +49,7 @@ void print_errno(const char* /*descr*/);
|
||||
void print_pam_msg(const char* msg, int msg_style);
|
||||
void clear_pam_msg(void);
|
||||
|
||||
void ui_update_field(enum input focused_input);
|
||||
void ui_update_field(enum Input focused_input);
|
||||
void ui_update_ffield();
|
||||
void ui_update_ofield(struct opts_field* self);
|
||||
void ui_update_cursor_focus();
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "macros.h"
|
||||
#include "ui.h"
|
||||
|
||||
extern enum input focused_input;
|
||||
extern enum Input focused_input;
|
||||
|
||||
extern struct opts_field of_session;
|
||||
extern struct opts_field of_user;
|
||||
@@ -15,7 +15,7 @@ extern struct opts_field of_passwd;
|
||||
extern struct Vector* UNULLABLE gusers;
|
||||
extern struct Vector* UNULLABLE gsessions;
|
||||
|
||||
struct opts_field* NNULLABLE get_opts_field(enum input from);
|
||||
struct opts_field* NNULLABLE get_opts_field(enum Input from);
|
||||
struct opts_field* NNULLABLE get_opts_ffield();
|
||||
|
||||
struct user st_user();
|
||||
|
||||
@@ -10,12 +10,18 @@
|
||||
|
||||
#include "keys.h"
|
||||
|
||||
int find_keyname(enum keys* at, const char* name);
|
||||
enum keys find_ansi(const char* seq);
|
||||
int find_keyname(enum Keys* at, const char* name);
|
||||
struct option_keys {
|
||||
bool is_some;
|
||||
enum Keys key;
|
||||
};
|
||||
struct option_keys find_ansi(const char* seq);
|
||||
void read_press(u_char* length, char* out);
|
||||
// non blocking, waits up to tv or interrupt, returns true if actually read
|
||||
bool read_press_nb(u_char* length, char* out, struct timeval* tv);
|
||||
|
||||
// UTF8
|
||||
//
|
||||
bool utf8_iscont(char byte);
|
||||
size_t utf8len(const char* str);
|
||||
size_t utf8len_until(const char* str, const char* until);
|
||||
@@ -24,12 +30,16 @@ const char* utf8back(const char* str);
|
||||
const char* utf8seek(const char* str);
|
||||
const char* utf8seekn(const char* str, size_t n);
|
||||
|
||||
// Vector
|
||||
//
|
||||
struct Vector {
|
||||
uint32_t length;
|
||||
uint32_t capacity;
|
||||
void** pages;
|
||||
};
|
||||
|
||||
struct Vector vec_from_raw(void** raw);
|
||||
void** vec_as_raw(struct Vector self);
|
||||
extern const struct Vector VEC_NEW;
|
||||
int vec_resize(struct Vector* self, size_t size);
|
||||
int vec_reserve(struct Vector* self, size_t size);
|
||||
|
||||
Reference in New Issue
Block a user