fix: use getuser() syscall for determining username rather than session.toml hack
This commit is contained in:
@@ -509,7 +509,7 @@ static bool try_login(LoginState* ls) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Write session so any app can query the current user
|
||||
// Persist login session state for the active desktop session.
|
||||
montauk::user::set_session(ls->username);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include <montauk/syscall.h>
|
||||
#include <montauk/string.h>
|
||||
#include <montauk/heap.h>
|
||||
#include <montauk/config.h>
|
||||
|
||||
// ==== ANSI color codes ====
|
||||
|
||||
@@ -81,8 +80,11 @@ extern "C" void _start() {
|
||||
Montauk::SysInfo sysinfo;
|
||||
montauk::get_info(&sysinfo);
|
||||
|
||||
auto doc = montauk::config::load("session");
|
||||
const char* username = doc.get_string("session.username", "user");
|
||||
const char* username = "user";
|
||||
char username_buf[32] = {};
|
||||
if (montauk::getuser(username_buf, sizeof(username_buf)) > 0 && username_buf[0]) {
|
||||
username = username_buf;
|
||||
}
|
||||
|
||||
uint64_t ms = montauk::get_milliseconds();
|
||||
uint64_t total_secs = ms / 1000;
|
||||
@@ -260,8 +262,6 @@ extern "C" void _start() {
|
||||
p = app(p, RST);
|
||||
}
|
||||
|
||||
doc.destroy();
|
||||
|
||||
// ==== Print output ====
|
||||
|
||||
montauk::putchar('\n');
|
||||
|
||||
@@ -1500,20 +1500,14 @@ extern "C" void _start() {
|
||||
music_visualizer::reset(g.visualizer);
|
||||
|
||||
// Parse arguments: accept a directory path or a file path
|
||||
// Helper: set dir_path to current user's home via session config
|
||||
// Helper: set dir_path to current user's home directory
|
||||
auto set_user_home = [&]() {
|
||||
auto doc = montauk::config::load("session");
|
||||
const char* name = doc.get_string("session.username", "");
|
||||
if (name[0]) {
|
||||
int p = 0;
|
||||
const char* pfx = "0:/users/";
|
||||
while (*pfx && p < (int)sizeof(g.dir_path) - 1) g.dir_path[p++] = *pfx++;
|
||||
while (*name && p < (int)sizeof(g.dir_path) - 1) g.dir_path[p++] = *name++;
|
||||
g.dir_path[p] = '\0';
|
||||
char username[32] = {};
|
||||
if (montauk::getuser(username, sizeof(username)) > 0 && username[0]) {
|
||||
snprintf(g.dir_path, sizeof(g.dir_path), "0:/users/%s", username);
|
||||
} else {
|
||||
memcpy(g.dir_path, "0:/home", 8);
|
||||
}
|
||||
doc.destroy();
|
||||
};
|
||||
|
||||
char arg_file[128] = {};
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include <montauk/syscall.h>
|
||||
#include <montauk/string.h>
|
||||
#include <montauk/heap.h>
|
||||
#include <montauk/config.h>
|
||||
|
||||
extern "C" {
|
||||
#include <string.h>
|
||||
@@ -114,17 +113,10 @@ extern "C" void _start() {
|
||||
|
||||
// Build output path: 0:/users/<username>/Pictures/screenshot_YYYYMMDD_HHMMSS.jpg
|
||||
char username[32] = {};
|
||||
{
|
||||
auto doc = montauk::config::load("session");
|
||||
const char* name = doc.get_string("session.username", "");
|
||||
if (name[0] == '\0') {
|
||||
doc.destroy();
|
||||
montauk::mfree(jpeg.data);
|
||||
montauk::print("screenshot: no user session\n");
|
||||
montauk::exit(1);
|
||||
}
|
||||
montauk::strncpy(username, name, sizeof(username) - 1);
|
||||
doc.destroy();
|
||||
if (montauk::getuser(username, sizeof(username)) <= 0 || username[0] == '\0') {
|
||||
montauk::mfree(jpeg.data);
|
||||
montauk::print("screenshot: no user session\n");
|
||||
montauk::exit(1);
|
||||
}
|
||||
|
||||
char home[128];
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include <montauk/syscall.h>
|
||||
#include <montauk/string.h>
|
||||
#include <montauk/heap.h>
|
||||
#include <montauk/config.h>
|
||||
#include <gui/gui.hpp>
|
||||
#include <gui/standalone.hpp>
|
||||
#include <gui/truetype.hpp>
|
||||
@@ -1255,19 +1254,17 @@ static bool handle_key(const Montauk::KeyEvent& key, bool& quit) {
|
||||
}
|
||||
|
||||
static void set_default_dir() {
|
||||
auto doc = montauk::config::load("session");
|
||||
const char* name = doc.get_string("session.username", "");
|
||||
if (name[0]) {
|
||||
snprintf(g.dir_path, sizeof(g.dir_path), "0:/users/%s/Videos", name);
|
||||
char username[32] = {};
|
||||
if (montauk::getuser(username, sizeof(username)) > 0 && username[0]) {
|
||||
snprintf(g.dir_path, sizeof(g.dir_path), "0:/users/%s/Videos", username);
|
||||
const char* probe[1];
|
||||
int ok = montauk::readdir(g.dir_path, probe, 1);
|
||||
if (ok < 0) {
|
||||
snprintf(g.dir_path, sizeof(g.dir_path), "0:/users/%s", name);
|
||||
snprintf(g.dir_path, sizeof(g.dir_path), "0:/users/%s", username);
|
||||
}
|
||||
} else {
|
||||
montauk::strncpy(g.dir_path, "0:/home", (int)sizeof(g.dir_path));
|
||||
}
|
||||
doc.destroy();
|
||||
}
|
||||
|
||||
static void parse_args(char* auto_file, int auto_file_cap) {
|
||||
|
||||
Reference in New Issue
Block a user