mirror of https://github.com/fairyglade/ly.git
cosmetic changes + enter behavior (#126)
* remove trailing whitespace * always submit password on enter Moves the keypress logic for keypresses from if-else statements to switches, adds non-contextual behavior on pressing enter * wrap pam actions and handle errors at on spot * init all of text struct in input_text() This gets rid off valgrind warning on unitialized variables
This commit is contained in:
parent
95c0077416
commit
9486f05e59
|
@ -263,7 +263,7 @@ void config_defaults()
|
||||||
config.blank_box = true;
|
config.blank_box = true;
|
||||||
config.blank_password = false;
|
config.blank_password = false;
|
||||||
config.console_dev = strdup("/dev/console");
|
config.console_dev = strdup("/dev/console");
|
||||||
config.default_input = 2;
|
config.default_input = PASSWORD_INPUT;
|
||||||
config.fg = 9;
|
config.fg = 9;
|
||||||
config.hide_borders = false;
|
config.hide_borders = false;
|
||||||
config.input_len = 34;
|
config.input_len = 34;
|
||||||
|
|
|
@ -3,6 +3,12 @@
|
||||||
|
|
||||||
#include "ctypes.h"
|
#include "ctypes.h"
|
||||||
|
|
||||||
|
enum INPUTS {
|
||||||
|
SESSION_SWITCH,
|
||||||
|
LOGIN_INPUT,
|
||||||
|
PASSWORD_INPUT,
|
||||||
|
};
|
||||||
|
|
||||||
struct lang
|
struct lang
|
||||||
{
|
{
|
||||||
char* capslock;
|
char* capslock;
|
||||||
|
|
|
@ -115,6 +115,8 @@ void input_text(struct text* target, u64 len)
|
||||||
target->end = target->text;
|
target->end = target->text;
|
||||||
target->visible_start = target->text;
|
target->visible_start = target->text;
|
||||||
target->len = len;
|
target->len = len;
|
||||||
|
target->x = 0;
|
||||||
|
target->y = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void input_desktop_free(struct desktop* target)
|
void input_desktop_free(struct desktop* target)
|
||||||
|
|
44
src/login.c
44
src/login.c
|
@ -423,6 +423,24 @@ void shell(struct passwd* pwd)
|
||||||
reset_terminal(pwd);
|
reset_terminal(pwd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// pam_do performs the pam action specified in pam_action
|
||||||
|
// on pam_action fail, call diagnose and end pam session
|
||||||
|
int pam_do(
|
||||||
|
int (pam_action)(struct pam_handle *, int),
|
||||||
|
struct pam_handle *handle,
|
||||||
|
int flags,
|
||||||
|
struct term_buf *buf)
|
||||||
|
{
|
||||||
|
int status = pam_action(handle, flags);
|
||||||
|
|
||||||
|
if (status != PAM_SUCCESS) {
|
||||||
|
pam_diagnose(status, buf);
|
||||||
|
pam_end(handle, status);
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
void auth(
|
void auth(
|
||||||
struct desktop* desktop,
|
struct desktop* desktop,
|
||||||
struct text* login,
|
struct text* login,
|
||||||
|
@ -445,39 +463,31 @@ void auth(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ok = pam_authenticate(handle, 0);
|
ok = pam_do(pam_authenticate, handle, 0, buf);
|
||||||
|
|
||||||
if (ok != PAM_SUCCESS)
|
if (ok != PAM_SUCCESS)
|
||||||
{
|
{
|
||||||
pam_diagnose(ok, buf);
|
|
||||||
pam_end(handle, ok);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ok = pam_acct_mgmt(handle, 0);
|
ok = pam_do(pam_acct_mgmt, handle, 0, buf);
|
||||||
|
|
||||||
if (ok != PAM_SUCCESS)
|
if (ok != PAM_SUCCESS)
|
||||||
{
|
{
|
||||||
pam_diagnose(ok, buf);
|
|
||||||
pam_end(handle, ok);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ok = pam_setcred(handle, PAM_ESTABLISH_CRED);
|
ok = pam_do(pam_setcred, handle, PAM_ESTABLISH_CRED, buf);
|
||||||
|
|
||||||
if (ok != PAM_SUCCESS)
|
if (ok != PAM_SUCCESS)
|
||||||
{
|
{
|
||||||
pam_diagnose(ok, buf);
|
|
||||||
pam_end(handle, ok);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ok = pam_open_session(handle, 0);
|
ok = pam_do(pam_open_session, handle, 0, buf);
|
||||||
|
|
||||||
if (ok != PAM_SUCCESS)
|
if (ok != PAM_SUCCESS)
|
||||||
{
|
{
|
||||||
pam_diagnose(ok, buf);
|
|
||||||
pam_end(handle, ok);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -621,21 +631,17 @@ void auth(
|
||||||
desktop_load(desktop);
|
desktop_load(desktop);
|
||||||
|
|
||||||
// close pam session
|
// close pam session
|
||||||
ok = pam_close_session(handle, 0);
|
ok = pam_do(pam_close_session, handle, 0, buf);
|
||||||
|
|
||||||
if (ok != PAM_SUCCESS)
|
if (ok != PAM_SUCCESS)
|
||||||
{
|
{
|
||||||
pam_diagnose(ok, buf);
|
|
||||||
pam_end(handle, ok);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ok = pam_setcred(handle, PAM_DELETE_CRED);
|
ok = pam_do(pam_setcred, handle, PAM_DELETE_CRED, buf);
|
||||||
|
|
||||||
if (ok != PAM_SUCCESS)
|
if (ok != PAM_SUCCESS)
|
||||||
{
|
{
|
||||||
pam_diagnose(ok, buf);
|
|
||||||
pam_end(handle, ok);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -645,4 +651,4 @@ void auth(
|
||||||
{
|
{
|
||||||
pam_diagnose(ok, buf);
|
pam_diagnose(ok, buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
62
src/main.c
62
src/main.c
|
@ -47,7 +47,7 @@ void log_init(char** log)
|
||||||
log[DGN_NULL] = lang.err_null;
|
log[DGN_NULL] = lang.err_null;
|
||||||
log[DGN_ALLOC] = lang.err_alloc;
|
log[DGN_ALLOC] = lang.err_alloc;
|
||||||
log[DGN_BOUNDS] = lang.err_bounds;
|
log[DGN_BOUNDS] = lang.err_bounds;
|
||||||
log[DGN_DOMAIN] = lang.err_domain;
|
log[DGN_DOMAIN] = lang.err_domain;
|
||||||
log[DGN_MLOCK] = lang.err_mlock;
|
log[DGN_MLOCK] = lang.err_mlock;
|
||||||
log[DGN_XSESSIONS_DIR] = lang.err_xsessions_dir;
|
log[DGN_XSESSIONS_DIR] = lang.err_xsessions_dir;
|
||||||
log[DGN_XSESSIONS_OPEN] = lang.err_xsessions_open;
|
log[DGN_XSESSIONS_OPEN] = lang.err_xsessions_open;
|
||||||
|
@ -196,45 +196,43 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
if (event.type == TB_EVENT_KEY)
|
if (event.type == TB_EVENT_KEY)
|
||||||
{
|
{
|
||||||
if (event.key == TB_KEY_F1)
|
switch (event.key)
|
||||||
{
|
{
|
||||||
|
case TB_KEY_F1:
|
||||||
shutdown = true;
|
shutdown = true;
|
||||||
|
run = false;
|
||||||
break;
|
break;
|
||||||
}
|
case TB_KEY_F2:
|
||||||
else if (event.key == TB_KEY_F2)
|
|
||||||
{
|
|
||||||
reboot = true;
|
reboot = true;
|
||||||
|
run = false;
|
||||||
break;
|
break;
|
||||||
}
|
case TB_KEY_CTRL_C:
|
||||||
else if (event.key == TB_KEY_CTRL_C)
|
run = false;
|
||||||
{
|
|
||||||
break;
|
break;
|
||||||
}
|
case TB_KEY_ARROW_UP:
|
||||||
else if ((event.key == TB_KEY_ARROW_UP) && (active_input > 0))
|
if (active_input > 0)
|
||||||
{
|
{
|
||||||
--active_input;
|
--active_input;
|
||||||
update = true;
|
update = true;
|
||||||
}
|
}
|
||||||
else if (((event.key == TB_KEY_ARROW_DOWN)
|
break;
|
||||||
|| (event.key == TB_KEY_ENTER))
|
case TB_KEY_ARROW_DOWN:
|
||||||
&& (active_input < 2))
|
if (active_input < 2)
|
||||||
{
|
{
|
||||||
++active_input;
|
++active_input;
|
||||||
update = true;
|
update = true;
|
||||||
}
|
}
|
||||||
else if (event.key == TB_KEY_TAB)
|
break;
|
||||||
{
|
case TB_KEY_TAB:
|
||||||
++active_input;
|
++active_input;
|
||||||
|
|
||||||
if (active_input > 2)
|
if (active_input > 2)
|
||||||
{
|
{
|
||||||
active_input = 0;
|
active_input = PASSWORD_INPUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
update = true;
|
update = true;
|
||||||
}
|
break;
|
||||||
else if (event.key == TB_KEY_ENTER)
|
case TB_KEY_ENTER:
|
||||||
{
|
|
||||||
save(&desktop, &login);
|
save(&desktop, &login);
|
||||||
auth(&desktop, &login, &password, &buf);
|
auth(&desktop, &login, &password, &buf);
|
||||||
update = true;
|
update = true;
|
||||||
|
@ -242,6 +240,8 @@ int main(int argc, char** argv)
|
||||||
if (dgn_catch())
|
if (dgn_catch())
|
||||||
{
|
{
|
||||||
++auth_fails;
|
++auth_fails;
|
||||||
|
// move focus back to password input
|
||||||
|
active_input = PASSWORD_INPUT;
|
||||||
|
|
||||||
if (dgn_output_code() != DGN_PAM)
|
if (dgn_output_code() != DGN_PAM)
|
||||||
{
|
{
|
||||||
|
@ -256,13 +256,13 @@ int main(int argc, char** argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
load(&desktop, &login);
|
load(&desktop, &login);
|
||||||
}
|
break;
|
||||||
else
|
default:
|
||||||
{
|
|
||||||
(*input_handles[active_input])(
|
(*input_handles[active_input])(
|
||||||
input_structs[active_input],
|
input_structs[active_input],
|
||||||
&event);
|
&event);
|
||||||
update = true;
|
update = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue