mirror of
https://github.com/javalsai/lidm.git
synced 2025-07-04 23:08:42 +02:00
Merge pull request #6 from rmntgx/save-last-selection
Save last selection
This commit is contained in:
commit
d5a708ec4a
@ -1,9 +1,13 @@
|
|||||||
#ifndef _LAUNCHSTATEH_
|
#ifndef LAUNCHSTATEH_
|
||||||
#define _LAUNCHSTATEH_
|
#define LAUNCHSTATEH_
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
struct LaunchState {
|
struct LaunchState {
|
||||||
int user_opt;
|
int user_opt;
|
||||||
int session_opt;
|
int session_opt;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LaunchState read_launch_state();
|
struct LaunchState read_launch_state();
|
||||||
|
@ -1,27 +1,32 @@
|
|||||||
// Small file to save last selection
|
// Small file for saving last selection
|
||||||
|
|
||||||
#define STATE_PATH "/var/lib/lidm/state"
|
#define STATE_DIR "/var/lib/lidm"
|
||||||
|
#define STATE_FILE "/var/lib/lidm/state"
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
#include "launch_state.h"
|
#include "launch_state.h"
|
||||||
|
|
||||||
struct LaunchState read_launch_state() {
|
struct LaunchState read_launch_state() {
|
||||||
struct LaunchState state;
|
struct LaunchState state;
|
||||||
state.user_opt = 1;
|
state.user_opt = 1;
|
||||||
state.session_opt = 1;
|
state.session_opt = 1;
|
||||||
FILE* f = fopen(STATE_PATH, "r");
|
FILE* state_fd = fopen(STATE_FILE, "r");
|
||||||
if(!f) return state;
|
if (state_fd == NULL) return state;
|
||||||
fscanf(f, "%i;%i", &state.user_opt, &state.session_opt);
|
if (fscanf(state_fd, "%i;%i", &state.user_opt, &state.session_opt) != 2) {
|
||||||
fclose(f);
|
state.user_opt = 1;
|
||||||
return state;
|
state.session_opt = 1;
|
||||||
|
}
|
||||||
|
(void)fclose(state_fd);
|
||||||
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool write_launch_state(struct LaunchState state) {
|
bool write_launch_state(struct LaunchState state) {
|
||||||
FILE* f = fopen(STATE_PATH, "w");
|
FILE* state_fd = fopen(STATE_FILE, "w");
|
||||||
if(!f) return false;
|
if (state_fd == NULL) {
|
||||||
fprintf(f, "%i;%i", state.user_opt, state.session_opt);
|
if (mkdir(STATE_DIR, 0755) == -1) return false;
|
||||||
fclose(f);
|
state_fd = fopen(STATE_FILE, "w");
|
||||||
return true;
|
if (state_fd == NULL) return false;
|
||||||
|
}
|
||||||
|
(void)fprintf(state_fd, "%i;%i", state.user_opt, state.session_opt);
|
||||||
|
(void)fclose(state_fd);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
16
src/ui.c
16
src/ui.c
@ -20,13 +20,13 @@
|
|||||||
#include "auth.h"
|
#include "auth.h"
|
||||||
#include "efield.h"
|
#include "efield.h"
|
||||||
#include "keys.h"
|
#include "keys.h"
|
||||||
|
#include "launch_state.h"
|
||||||
#include "ofield.h"
|
#include "ofield.h"
|
||||||
#include "sessions.h"
|
#include "sessions.h"
|
||||||
#include "ui.h"
|
#include "ui.h"
|
||||||
#include "ui_state.h"
|
#include "ui_state.h"
|
||||||
#include "users.h"
|
#include "users.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "launch_state.h"
|
|
||||||
|
|
||||||
const u_char INPUTS_N = 3;
|
const u_char INPUTS_N = 3;
|
||||||
|
|
||||||
@ -200,9 +200,11 @@ int load(struct Vector* users, struct Vector* sessions) {
|
|||||||
of_passwd = ofield_new(0);
|
of_passwd = ofield_new(0);
|
||||||
|
|
||||||
struct LaunchState initial_state = read_launch_state();
|
struct LaunchState initial_state = read_launch_state();
|
||||||
if(initial_state.user_opt > users->length || initial_state.session_opt > sessions->length + g_config->behavior.include_defshell) {
|
if (initial_state.user_opt > users->length ||
|
||||||
initial_state.user_opt = 1;
|
initial_state.session_opt >
|
||||||
initial_state.session_opt = 1;
|
sessions->length + g_config->behavior.include_defshell) {
|
||||||
|
initial_state.user_opt = 1;
|
||||||
|
initial_state.session_opt = 1;
|
||||||
}
|
}
|
||||||
of_user.current_opt = initial_state.user_opt;
|
of_user.current_opt = initial_state.user_opt;
|
||||||
of_session.current_opt = initial_state.session_opt;
|
of_session.current_opt = initial_state.session_opt;
|
||||||
@ -264,9 +266,9 @@ int load(struct Vector* users, struct Vector* sessions) {
|
|||||||
} else {
|
} else {
|
||||||
if (len == 1 && *seq == '\n') {
|
if (len == 1 && *seq == '\n') {
|
||||||
struct LaunchState ls;
|
struct LaunchState ls;
|
||||||
ls.user_opt = of_user.current_opt;
|
ls.user_opt = of_user.current_opt;
|
||||||
ls.session_opt = of_session.current_opt;
|
ls.session_opt = of_session.current_opt;
|
||||||
write_launch_state(ls);
|
write_launch_state(ls);
|
||||||
|
|
||||||
if (!launch(st_user().username, of_passwd.efield.content,
|
if (!launch(st_user().username, of_passwd.efield.content,
|
||||||
st_session(g_config->behavior.include_defshell),
|
st_session(g_config->behavior.include_defshell),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user