chore: modularize PAM

also helps with sanitizing the code flow when spawning the child, more
code though
This commit is contained in:
2025-08-27 19:31:46 +02:00
parent ddc38ef27f
commit b56aa19671
7 changed files with 303 additions and 185 deletions

34
include/pam.h Normal file
View File

@@ -0,0 +1,34 @@
#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** envlist;
const char* errfn;
};
};
// Doesn't include `source`s
struct pamh_getenv_status pamh_get_complete_env(pam_handle_t* handle,
char* NNULLABLE user,
struct passwd* NNULLABLE pw,
enum session_type session_typ);
void free_envlist(char** NNULLABLE envlist);
pam_handle_t* NULLABLE get_pamh(char* NNULLABLE user, char* NNULLABLE passwd);
#endif /* PAM_H */