mirror of
https://github.com/javalsai/lidm.git
synced 2025-09-01 02:47:59 +02:00
lint: apply new style
This commit is contained in:
106
src/auth.c
106
src/auth.c
@@ -15,16 +15,18 @@
|
||||
#include "unistd.h"
|
||||
#include "util.h"
|
||||
|
||||
int pam_conversation(int num_msg, const struct pam_message **msg,
|
||||
struct pam_response **resp, void *appdata_ptr) {
|
||||
struct pam_response *reply =
|
||||
(struct pam_response *)malloc(sizeof(struct pam_response) * num_msg);
|
||||
int pam_conversation(int num_msg,
|
||||
const struct pam_message** msg,
|
||||
struct pam_response** resp,
|
||||
void* appdata_ptr) {
|
||||
struct pam_response* reply =
|
||||
(struct pam_response*)malloc(sizeof(struct pam_response) * num_msg);
|
||||
for (size_t i = 0; i < num_msg; i++) {
|
||||
reply[i].resp = NULL;
|
||||
reply[i].resp_retcode = 0;
|
||||
if (msg[i]->msg_style == PAM_PROMPT_ECHO_OFF ||
|
||||
msg[i]->msg_style == PAM_PROMPT_ECHO_ON) {
|
||||
char *input = (char *)appdata_ptr;
|
||||
char* input = (char*)appdata_ptr;
|
||||
reply[i].resp = strdup(input);
|
||||
}
|
||||
}
|
||||
@@ -32,18 +34,20 @@ int pam_conversation(int num_msg, const struct pam_message **msg,
|
||||
return PAM_SUCCESS;
|
||||
}
|
||||
|
||||
#define CHECK_PAM_RET(call) \
|
||||
ret = (call); \
|
||||
if (ret != PAM_SUCCESS) { \
|
||||
pam_end(pamh, ret); \
|
||||
return NULL; \
|
||||
#define CHECK_PAM_RET(call) \
|
||||
ret = (call); \
|
||||
if (ret != PAM_SUCCESS) { \
|
||||
pam_end(pamh, ret); \
|
||||
return NULL; \
|
||||
}
|
||||
|
||||
void clear_screen() { printf("\x1b[H\x1b[J"); }
|
||||
void clear_screen() {
|
||||
printf("\x1b[H\x1b[J");
|
||||
}
|
||||
|
||||
pam_handle_t *get_pamh(char *user, char *passwd) {
|
||||
pam_handle_t *pamh = NULL;
|
||||
struct pam_conv pamc = {pam_conversation, (void *)passwd};
|
||||
pam_handle_t* get_pamh(char* user, char* passwd) {
|
||||
pam_handle_t* pamh = NULL;
|
||||
struct pam_conv pamc = {pam_conversation, (void*)passwd};
|
||||
int ret;
|
||||
|
||||
CHECK_PAM_RET(pam_start("login", user, &pamc, &pamh))
|
||||
@@ -57,25 +61,22 @@ pam_handle_t *get_pamh(char *user, char *passwd) {
|
||||
}
|
||||
#undef CHECK_PAM_RET
|
||||
|
||||
void *shmalloc(size_t size) {
|
||||
void* shmalloc(size_t size) {
|
||||
return mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS,
|
||||
-1, 0);
|
||||
}
|
||||
|
||||
void sourceFileTry(char *file) {
|
||||
FILE *file2source = fopen(file, "r");
|
||||
if (file2source == NULL)
|
||||
return;
|
||||
void sourceFileTry(char* file) {
|
||||
FILE* file2source = fopen(file, "r");
|
||||
if (file2source == NULL) return;
|
||||
|
||||
char *line = NULL;
|
||||
char* line = NULL;
|
||||
size_t len = 0;
|
||||
ssize_t read;
|
||||
|
||||
while ((read = getline(&line, &len, file2source)) != -1) {
|
||||
if (read == 0 || (read > 0 && *line == '#'))
|
||||
continue;
|
||||
if (line[read - 1] == '\n')
|
||||
line[read - 1] = '\0';
|
||||
if (read == 0 || (read > 0 && *line == '#')) continue;
|
||||
if (line[read - 1] == '\n') line[read - 1] = '\0';
|
||||
|
||||
/* printf("Retrieved line of length %zu:\n", read); */
|
||||
/* printf("%s\n", line); */
|
||||
@@ -89,15 +90,15 @@ void sourceFileTry(char *file) {
|
||||
}
|
||||
}
|
||||
|
||||
if (line)
|
||||
free(line);
|
||||
if (line) free(line);
|
||||
fclose(file2source);
|
||||
}
|
||||
|
||||
void moarEnv(char *user, struct session session, struct passwd *pw,
|
||||
struct behavior *behavior) {
|
||||
if (chdir(pw->pw_dir) == -1)
|
||||
print_errno("can't chdir to user home");
|
||||
void moarEnv(char* user,
|
||||
struct session session,
|
||||
struct passwd* pw,
|
||||
struct behavior* behavior) {
|
||||
if (chdir(pw->pw_dir) == -1) print_errno("can't chdir to user home");
|
||||
|
||||
setenv("HOME", pw->pw_dir, true);
|
||||
setenv("USER", pw->pw_name, true);
|
||||
@@ -108,30 +109,26 @@ void moarEnv(char *user, struct session session, struct passwd *pw,
|
||||
|
||||
// PATH?
|
||||
|
||||
char *xdg_session_type;
|
||||
if (session.type == SHELL)
|
||||
xdg_session_type = "tty";
|
||||
if (session.type == XORG)
|
||||
xdg_session_type = "x11";
|
||||
if (session.type == WAYLAND)
|
||||
xdg_session_type = "wayland";
|
||||
char* xdg_session_type;
|
||||
if (session.type == SHELL) xdg_session_type = "tty";
|
||||
if (session.type == XORG) xdg_session_type = "x11";
|
||||
if (session.type == WAYLAND) xdg_session_type = "wayland";
|
||||
setenv("XDG_SESSION_TYPE", xdg_session_type, true);
|
||||
|
||||
printf("\n\n\n\n\x1b[1m");
|
||||
for (size_t i = 0; i < behavior->source.length; i++) {
|
||||
/* printf("DEBUG(source)!!!! %d %s\n", i, (char*)vec_get(&behavior->source,
|
||||
* i)); */
|
||||
sourceFileTry((char *)vec_get(&behavior->source, i));
|
||||
sourceFileTry((char*)vec_get(&behavior->source, i));
|
||||
}
|
||||
/* printf("\n"); */
|
||||
if (pw->pw_dir) {
|
||||
uint home_len = strlen(pw->pw_dir);
|
||||
for (size_t i = 0; i < behavior->user_source.length; i++) {
|
||||
char *file2sourcepath = (char *)vec_get(&behavior->user_source, i);
|
||||
char *newbuf =
|
||||
char* file2sourcepath = (char*)vec_get(&behavior->user_source, i);
|
||||
char* newbuf =
|
||||
malloc(home_len + strlen(file2sourcepath) + 2); // nullbyte and slash
|
||||
if (newbuf == NULL)
|
||||
continue; // can't bother
|
||||
if (newbuf == NULL) continue; // can't bother
|
||||
strcpy(newbuf, pw->pw_dir);
|
||||
newbuf[home_len] = '/'; // assume pw_dir doesn't start with '/' :P
|
||||
strcpy(&newbuf[home_len + 1], file2sourcepath);
|
||||
@@ -153,21 +150,24 @@ void moarEnv(char *user, struct session session, struct passwd *pw,
|
||||
/*setenv("XDG_SEAT", "seat0", true);*/
|
||||
}
|
||||
|
||||
bool launch(char *user, char *passwd, struct session session, void (*cb)(void),
|
||||
struct behavior *behavior) {
|
||||
struct passwd *pw = getpwnam(user);
|
||||
bool launch(char* user,
|
||||
char* passwd,
|
||||
struct session session,
|
||||
void (*cb)(void),
|
||||
struct behavior* behavior) {
|
||||
struct passwd* pw = getpwnam(user);
|
||||
if (pw == NULL) {
|
||||
print_err("could not get user info");
|
||||
return false;
|
||||
}
|
||||
|
||||
pam_handle_t *pamh = get_pamh(user, passwd);
|
||||
pam_handle_t* pamh = get_pamh(user, passwd);
|
||||
if (pamh == NULL) {
|
||||
print_err("error on pam authentication");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool *reach_session = shmalloc(sizeof(bool));
|
||||
bool* reach_session = shmalloc(sizeof(bool));
|
||||
if (reach_session == NULL) {
|
||||
perror("error allocating shared memory");
|
||||
return false;
|
||||
@@ -176,16 +176,15 @@ bool launch(char *user, char *passwd, struct session session, void (*cb)(void),
|
||||
|
||||
uint pid = fork();
|
||||
if (pid == 0) { // child
|
||||
char *TERM = NULL;
|
||||
char *_GETTERM = getenv("TERM");
|
||||
if (_GETTERM != NULL)
|
||||
strcln(&TERM, _GETTERM);
|
||||
char* TERM = NULL;
|
||||
char* _GETTERM = getenv("TERM");
|
||||
if (_GETTERM != NULL) strcln(&TERM, _GETTERM);
|
||||
if (clearenv() != 0) {
|
||||
print_errno("clearenv");
|
||||
_exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
char **envlist = pam_getenvlist(pamh);
|
||||
char** envlist = pam_getenvlist(pamh);
|
||||
if (envlist == NULL) {
|
||||
print_errno("pam_getenvlist");
|
||||
_exit(EXIT_FAILURE);
|
||||
@@ -222,8 +221,7 @@ bool launch(char *user, char *passwd, struct session session, void (*cb)(void),
|
||||
_exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (cb != NULL)
|
||||
cb();
|
||||
if (cb != NULL) cb();
|
||||
|
||||
*reach_session = true;
|
||||
|
||||
|
Reference in New Issue
Block a user