mirror of
https://github.com/subhobhai943/SUB-OS.git
synced 2026-10-25 16:52:29 +00:00
feat(auth): Boot-time login prompt; fix(configure): arch selection via dialog
Login: - Add console_login() (security/auth.c): an interactive boot-time username / password gate rendered on the framebuffer console before any session starts. It blocks until valid credentials are entered, masks the password, scrubs it from the stack, and sets the current user. Default account is SUB / SUB, shown as a hint. Wired into the boot handoff in kernel/main.c ahead of both the GUI desktop and the emergency TTY shell. Configure: - scripts/kconfig/menuconfig.py: fix the architecture (and optimization) picker. The lxdialog front-end used --radiolist, where <Enter> confirms the ORIGINAL choice and only <Space> moves the dot -- so highlighting a new architecture and pressing <Enter> appeared to do nothing. Single-choice groups now use --menu (with --default-item), where <Enter> selects the highlighted row directly. Also stop the unconditional save-on-exit from overriding an explicit "No" at the exit confirmation. Verified: SUB/SUB logs in (injected via QEMU monitor) -> "Login successful" -> desktop starts; the desktop stays blocked until login. dialog --menu selection of aarch64 persists to .config/autoconf.h and retargets `make`. Clean build on x86_64/aarch64/armv8i. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01Fh5z6V7nGPbHvqVG5p4CXX
This commit is contained in:
1 parent
71ad6aca3d
commit
c982d6b538
5 files changed
+146
-44
No files matched your search
@@ -9,3 +9,7 @@ build/
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
.system_generated/
|
.system_generated/
|
||||||
.config
|
.config
|
||||||
|
|
||||||
|
# Python bytecode
|
||||||
|
__pycache__/
|
||||||
|
*.pyc
|
||||||
@@ -31,4 +31,9 @@ int auth_set_current_user(const char* username);
|
|||||||
size_t auth_get_user_count(void);
|
size_t auth_get_user_count(void);
|
||||||
const user_account_t* auth_get_user_by_index(size_t index);
|
const user_account_t* auth_get_user_by_index(size_t index);
|
||||||
|
|
||||||
|
/* Interactive boot-time login: prompts for a username and password on the
|
||||||
|
* console and blocks until a valid pair is entered, then sets the current
|
||||||
|
* user. Default account is SUB / SUB. */
|
||||||
|
void console_login(void);
|
||||||
|
|
||||||
#endif // _SECURITY_AUTH_H
|
#endif // _SECURITY_AUTH_H
|
||||||
+13
-8
@@ -275,20 +275,25 @@ static void subos_modular_core_boot(void) {
|
|||||||
bool emergency_text = init_has_param("nogui") || init_has_param("text") ||
|
bool emergency_text = init_has_param("nogui") || init_has_param("text") ||
|
||||||
init_has_param("emergency") || init_has_param("single");
|
init_has_param("emergency") || init_has_param("single");
|
||||||
|
|
||||||
|
// End the splash and return the screen to a text console so the login
|
||||||
|
// prompt is visible before any session (graphical or TTY) begins.
|
||||||
|
boot_logo_splash_end();
|
||||||
|
fbcon_enable(true);
|
||||||
|
|
||||||
|
// Gate the session behind an interactive login. This blocks until a valid
|
||||||
|
// username/password is entered; the default account is SUB / SUB.
|
||||||
|
console_login();
|
||||||
|
|
||||||
if (!emergency_text) {
|
if (!emergency_text) {
|
||||||
printk(KERN_INFO "INIT: Booting directly into SUB-OS Graphical Desktop Environment...\n");
|
printk(KERN_INFO "INIT: Starting SUB-OS Graphical Desktop Environment...\n");
|
||||||
boot_logo_splash_end();
|
|
||||||
gui_start_desktop();
|
gui_start_desktop();
|
||||||
printk(KERN_INFO "INIT: GUI session closed. Entering Emergency Kernel TTY Mode.\n");
|
printk(KERN_INFO "INIT: GUI session closed. Entering Kernel TTY Mode.\n");
|
||||||
|
// The desktop owned the framebuffer; return it to the text console.
|
||||||
|
fbcon_enable(true);
|
||||||
} else {
|
} else {
|
||||||
printk(KERN_INFO "INIT: Emergency text/kernel TTY mode requested via boot parameters.\n");
|
printk(KERN_INFO "INIT: Emergency text/kernel TTY mode requested via boot parameters.\n");
|
||||||
boot_logo_splash_end();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The screen returns to the console before handing over to userland, whether
|
|
||||||
// the GUI session just closed or a text boot was requested.
|
|
||||||
fbcon_enable(true);
|
|
||||||
|
|
||||||
// Hand control to userland: /sbin/init is a separate static ELF that runs
|
// Hand control to userland: /sbin/init is a separate static ELF that runs
|
||||||
// in ring 3 with its own page tables and talks back only through INT 0x80.
|
// in ring 3 with its own page tables and talks back only through INT 0x80.
|
||||||
exec_run_builtin_init();
|
exec_run_builtin_init();
|
||||||
|
|||||||
@@ -407,56 +407,68 @@ def run_dialog_gui():
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
items = submenu["items"]
|
items = submenu["items"]
|
||||||
item_opts = []
|
is_radio = any(i.get("type") == "radio" for i in items)
|
||||||
|
|
||||||
for item in items:
|
item_opts = []
|
||||||
itype = item.get("type")
|
if is_radio:
|
||||||
if itype == "bool":
|
# Single-choice group (architecture, optimization). Use a --menu,
|
||||||
|
# not a --radiolist: in a radiolist the arrow keys only move the
|
||||||
|
# highlight and <Space> is required to move the (*) dot, so a user
|
||||||
|
# who highlights another architecture and presses <Enter> confirms
|
||||||
|
# the ORIGINAL choice -- the selection appears to do nothing. With
|
||||||
|
# --menu, <Enter> selects the highlighted row directly.
|
||||||
|
default_item = None
|
||||||
|
for item in items:
|
||||||
|
item_opts.extend([item["id"], item["label"]])
|
||||||
|
group = item.get("group")
|
||||||
|
cur = cfg.get("CONFIG_ARCH") if group == "arch" else (
|
||||||
|
cfg.get("CONFIG_OPTIMIZATION") if group == "opt" else None)
|
||||||
|
if cur is not None and cur == item["val"]:
|
||||||
|
default_item = item["id"]
|
||||||
|
|
||||||
|
cmd = ["dialog", "--clear", "--backtitle", backtitle,
|
||||||
|
"--title", submenu["title"], "--help-button"]
|
||||||
|
if default_item:
|
||||||
|
cmd += ["--default-item", default_item]
|
||||||
|
cmd += ["--menu",
|
||||||
|
"Highlight a choice with the arrow keys and press <Enter> to select it.",
|
||||||
|
"20", "78", "10"] + item_opts
|
||||||
|
else:
|
||||||
|
for item in items:
|
||||||
status = "ON" if cfg.get(item["id"], False) else "OFF"
|
status = "ON" if cfg.get(item["id"], False) else "OFF"
|
||||||
item_opts.extend([item["id"], item["label"], status])
|
item_opts.extend([item["id"], item["label"], status])
|
||||||
elif itype == "radio":
|
|
||||||
group = item.get("group")
|
|
||||||
if group == "arch":
|
|
||||||
status = "ON" if cfg.get("CONFIG_ARCH") == item["val"] else "OFF"
|
|
||||||
elif group == "opt":
|
|
||||||
status = "ON" if cfg.get("CONFIG_OPTIMIZATION") == item["val"] else "OFF"
|
|
||||||
else:
|
|
||||||
status = "OFF"
|
|
||||||
item_opts.extend([item["id"], item["label"], status])
|
|
||||||
|
|
||||||
is_radiolist = any(i.get("type") == "radio" for i in items)
|
cmd = ["dialog", "--clear", "--backtitle", backtitle,
|
||||||
dialog_type = "--radiolist" if is_radiolist else "--checklist"
|
"--title", submenu["title"], "--help-button", "--help-status",
|
||||||
|
"--checklist",
|
||||||
cmd = [
|
"Use <Space> to toggle features [*], <Enter> to confirm, <Help> for info.",
|
||||||
"dialog",
|
"20", "78", "10"] + item_opts
|
||||||
"--clear",
|
|
||||||
"--backtitle", backtitle,
|
|
||||||
"--title", submenu["title"],
|
|
||||||
"--help-button",
|
|
||||||
"--help-status",
|
|
||||||
dialog_type,
|
|
||||||
"Use <Space> to toggle features [*], <Enter> to confirm, <Help> for info.",
|
|
||||||
"20", "78", "10"
|
|
||||||
] + item_opts
|
|
||||||
|
|
||||||
res = subprocess.run(cmd, stderr=subprocess.PIPE, text=True)
|
res = subprocess.run(cmd, stderr=subprocess.PIPE, text=True)
|
||||||
ret = res.returncode
|
ret = res.returncode
|
||||||
out = res.stderr.strip()
|
out = res.stderr.strip()
|
||||||
|
|
||||||
if ret == 0: # OK / Confirm
|
if ret == 0: # OK / Confirm
|
||||||
_apply_selection(cfg, items, [t.strip('"') for t in out.split()], is_radiolist)
|
if is_radio:
|
||||||
|
# --menu returns just the highlighted tag.
|
||||||
|
_apply_selection(cfg, items, [out.strip('"')], True)
|
||||||
|
else:
|
||||||
|
_apply_selection(cfg, items, [t.strip('"') for t in out.split()], False)
|
||||||
current_menu_id = "main"
|
current_menu_id = "main"
|
||||||
|
|
||||||
elif ret == 1 or ret == 255: # Cancel or Esc
|
elif ret == 1 or ret == 255: # Cancel or Esc
|
||||||
current_menu_id = "main"
|
current_menu_id = "main"
|
||||||
|
|
||||||
elif ret == 2: # Help button
|
elif ret == 2: # Help button
|
||||||
# With --help-status the payload is "HELP <focused-tag> <on-tags...>".
|
if is_radio:
|
||||||
# Re-apply the on-tags first so the toggles made before pressing
|
# --menu help payload is just "HELP <focused-tag>".
|
||||||
# <Help> survive the round trip, then show the focused item's help.
|
focus = _help_tag(out)
|
||||||
tokens = _help_tokens(out)
|
else:
|
||||||
focus = tokens[0] if tokens else None
|
# --help-status payload is "HELP <focused-tag> <on-tags...>";
|
||||||
_apply_selection(cfg, items, tokens[1:], is_radiolist)
|
# re-apply the on-tags so toggles made before <Help> survive.
|
||||||
|
tokens = _help_tokens(out)
|
||||||
|
focus = tokens[0] if tokens else None
|
||||||
|
_apply_selection(cfg, items, tokens[1:], False)
|
||||||
focused = next((i for i in items if i["id"] == focus), None)
|
focused = next((i for i in items if i["id"] == focus), None)
|
||||||
if focused:
|
if focused:
|
||||||
help_title = f"{focused['label']} - Help"
|
help_title = f"{focused['label']} - Help"
|
||||||
@@ -467,8 +479,10 @@ def run_dialog_gui():
|
|||||||
subprocess.run(["dialog", "--backtitle", backtitle, "--title", help_title,
|
subprocess.run(["dialog", "--backtitle", backtitle, "--title", help_title,
|
||||||
"--msgbox", help_text, "16", "72"])
|
"--msgbox", help_text, "16", "72"])
|
||||||
|
|
||||||
save_config(cfg)
|
# Saving is handled inside the loop: the <Save> button writes immediately,
|
||||||
print(f"*** Configuration written to {CONFIG_FILE} and {AUTOCONF_HEADER} ***")
|
# and <Exit> asks first and writes only on "Yes". Saving again here would
|
||||||
|
# override an explicit "No", so just report the resulting state.
|
||||||
|
print(f"*** Kernel configuration ready: {CONFIG_FILE} (ARCH={cfg.get('CONFIG_ARCH', 'x86_64')}) ***")
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
# Pure Python Curses GUI Renderer (Pixel-Perfect Linux lxdialog Replica)
|
# Pure Python Curses GUI Renderer (Pixel-Perfect Linux lxdialog Replica)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include <crypto/crypto.h>
|
#include <crypto/crypto.h>
|
||||||
#include <lib/string.h>
|
#include <lib/string.h>
|
||||||
#include <kernel/printk.h>
|
#include <kernel/printk.h>
|
||||||
|
#include <drivers/keyboard.h>
|
||||||
|
|
||||||
static user_account_t user_table[MAX_USERS];
|
static user_account_t user_table[MAX_USERS];
|
||||||
static size_t user_count = 0;
|
static size_t user_count = 0;
|
||||||
@@ -123,3 +124,76 @@ const user_account_t* auth_get_user_by_index(size_t index) {
|
|||||||
if (index >= MAX_USERS || !user_table[index].in_use) return NULL;
|
if (index >= MAX_USERS || !user_table[index].in_use) return NULL;
|
||||||
return &user_table[index];
|
return &user_table[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Read a line from the PS/2 keyboard into buf. When echo is false the typed
|
||||||
|
* characters are masked with '*' (password entry). Blocks until Enter. */
|
||||||
|
static void login_read_line(char* buf, size_t max, bool echo) {
|
||||||
|
size_t len = 0;
|
||||||
|
while (true) {
|
||||||
|
uint16_t key = keyboard_get_key();
|
||||||
|
if (key & KEY_SPECIAL_FLAG) {
|
||||||
|
continue; // ignore arrows / function keys at the login prompt
|
||||||
|
}
|
||||||
|
char c = (char)(key & 0xFF);
|
||||||
|
|
||||||
|
if (c == '\n' || c == '\r') {
|
||||||
|
printk("\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (c == '\b' || (unsigned char)c == 0x7F || c == 0x08) {
|
||||||
|
if (len > 0) {
|
||||||
|
len--;
|
||||||
|
printk("\b \b"); // erase the last glyph on screen
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ((unsigned char)c >= 32 && (unsigned char)c <= 126 && len < max - 1) {
|
||||||
|
buf[len++] = c;
|
||||||
|
if (echo) {
|
||||||
|
printk("%c", c);
|
||||||
|
} else {
|
||||||
|
printk("*");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
buf[len] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
void console_login(void) {
|
||||||
|
char username[32];
|
||||||
|
char password[64];
|
||||||
|
|
||||||
|
printk("\n" ANSI_BRIGHT_CYAN
|
||||||
|
"=================================================================\n"
|
||||||
|
" SUB-OS Secure Login -- authenticate to start your session\n"
|
||||||
|
"=================================================================\n"
|
||||||
|
ANSI_RESET);
|
||||||
|
printk(ANSI_YELLOW " Default credentials: username " ANSI_BRIGHT_GREEN "SUB"
|
||||||
|
ANSI_YELLOW ", password " ANSI_BRIGHT_GREEN "SUB" ANSI_RESET "\n\n");
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
printk(ANSI_BRIGHT_GREEN "sub-os " ANSI_RESET "login: ");
|
||||||
|
login_read_line(username, sizeof(username), true);
|
||||||
|
if (username[0] == '\0') {
|
||||||
|
continue; // empty username, re-prompt
|
||||||
|
}
|
||||||
|
|
||||||
|
printk("Password: ");
|
||||||
|
login_read_line(password, sizeof(password), false);
|
||||||
|
|
||||||
|
bool ok = auth_verify_password(username, password);
|
||||||
|
|
||||||
|
// Scrub the password from the stack regardless of the outcome.
|
||||||
|
memset(password, 0, sizeof(password));
|
||||||
|
|
||||||
|
if (ok) {
|
||||||
|
auth_set_current_user(username);
|
||||||
|
printk(ANSI_BRIGHT_GREEN
|
||||||
|
"\nLogin successful. Welcome to SUB-OS, %s!\n\n" ANSI_RESET,
|
||||||
|
username);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
printk(ANSI_BRIGHT_RED "\nLogin incorrect. Please try again.\n\n" ANSI_RESET);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user