From: Tulio A M Mendes Date: Thu, 11 Jun 2026 02:58:29 +0000 (-0300) Subject: uid: add utmp syscalls and integrate with login X-Git-Url: https://projects.tadryanom.me/?a=commitdiff_plain;h=19a69035a4f55408775ae45e632eea0481342eca;p=AdrOS.git uid: add utmp syscalls and integrate with login Implement UID Infrastructure: integração utmp/wtmp (completed). Added syscalls for utmp management: - SYSCALL_UTMP_LOGIN (145): register login session - SYSCALL_UTMP_LOGOUT (146): register logout - SYSCALL_UTMP_DEAD (147): register process death Updated kernel syscall.c to handle utmp syscalls. Updated kernel include/syscall.h with new syscall numbers. Updated userspace include/syscall.h with new syscall numbers. Updated userspace include/utmp.h with utmp_login/logout/dead declarations. Updated userspace src/utmp.c with syscall wrappers. Updated login command to call utmp_login() with TTY name and hostname. Test: make test-battery PASS (157/157) --- diff --git a/include/syscall.h b/include/syscall.h index 69a2676e..bae5153d 100644 --- a/include/syscall.h +++ b/include/syscall.h @@ -186,6 +186,9 @@ enum { SYSCALL_MADVISE = 142, SYSCALL_EXECVEAT = 143, SYSCALL_REBOOT = 144, + SYSCALL_UTMP_LOGIN = 145, + SYSCALL_UTMP_LOGOUT = 146, + SYSCALL_UTMP_DEAD = 147, }; #endif diff --git a/src/kernel/syscall.c b/src/kernel/syscall.c index 7bdce471..6735f42f 100644 --- a/src/kernel/syscall.c +++ b/src/kernel/syscall.c @@ -41,6 +41,7 @@ #include "arch_syscall.h" #include "arch_process.h" #include "rtc.h" +#include "utmp.h" #include @@ -4447,6 +4448,32 @@ void syscall_handler(struct registers* regs) { return; } + if (syscall_no == SYSCALL_UTMP_LOGIN) { + /* utmp_login(pid, line, user, host) */ + uint32_t pid = sc_arg0(regs); + const char* line = (const char*)sc_arg1(regs); + const char* user = (const char*)sc_arg2(regs); + const char* host = (const char*)sc_arg3(regs); + sc_ret(regs) = (uint32_t)utmp_login(pid, line, user, host); + return; + } + + if (syscall_no == SYSCALL_UTMP_LOGOUT) { + /* utmp_logout(pid, line) */ + uint32_t pid = sc_arg0(regs); + const char* line = (const char*)sc_arg1(regs); + sc_ret(regs) = (uint32_t)utmp_logout(pid, line); + return; + } + + if (syscall_no == SYSCALL_UTMP_DEAD) { + /* utmp_dead(pid, exit_status) */ + uint32_t pid = sc_arg0(regs); + int exit_status = (int)sc_arg1(regs); + sc_ret(regs) = (uint32_t)utmp_dead(pid, exit_status); + return; + } + if (syscall_no == SYSCALL_MPROTECT) { uintptr_t addr = (uintptr_t)sc_arg0(regs); uint32_t len = sc_arg1(regs); diff --git a/user/cmds/login/login.c b/user/cmds/login/login.c index 851247ce..dffddceb 100644 --- a/user/cmds/login/login.c +++ b/user/cmds/login/login.c @@ -14,6 +14,8 @@ #include #include #include +#include +#include /* Simple login command */ int main(int argc, char** argv) { @@ -25,6 +27,19 @@ int main(int argc, char** argv) { while (1) { char username[64]; char password[64]; + char tty_name[32] = "ttyS0"; /* Default TTY */ + + /* Get TTY name from environment or default */ + char* tty = ttyname(STDIN_FILENO); + if (tty) { + /* Strip /dev/ prefix if present */ + if (strncmp(tty, "/dev/", 5) == 0) { + strncpy(tty_name, tty + 5, sizeof(tty_name) - 1); + } else { + strncpy(tty_name, tty, sizeof(tty_name) - 1); + } + tty_name[sizeof(tty_name) - 1] = '\0'; + } /* Prompt for username */ printf("login: "); @@ -93,6 +108,15 @@ int main(int argc, char** argv) { chdir(pw->pw_dir); } + /* Register login in utmp */ + struct utsname uts; + char hostname[64] = "localhost"; + if (uname(&uts) == 0) { + strncpy(hostname, uts.nodename, sizeof(hostname) - 1); + hostname[sizeof(hostname) - 1] = '\0'; + } + utmp_login(getpid(), tty_name, username, hostname); + /* Execute shell */ char* shell = pw->pw_shell; if (!shell || shell[0] == '\0') { diff --git a/user/ulibc/include/syscall.h b/user/ulibc/include/syscall.h index c0b27e8a..01b21499 100644 --- a/user/ulibc/include/syscall.h +++ b/user/ulibc/include/syscall.h @@ -156,6 +156,9 @@ enum { SYS_MADVISE = 142, SYS_EXECVEAT = 143, SYS_REBOOT = 144, + SYS_UTMP_LOGIN = 145, + SYS_UTMP_LOGOUT = 146, + SYS_UTMP_DEAD = 147, }; /* Raw syscall wrappers — up to 5 args via INT 0x80 */ diff --git a/user/ulibc/include/utmp.h b/user/ulibc/include/utmp.h index b36b9d93..7ae5db69 100644 --- a/user/ulibc/include/utmp.h +++ b/user/ulibc/include/utmp.h @@ -45,4 +45,9 @@ struct utmp* pututline(const struct utmp* ut); void endutent(void); void utmpname(const char* file); +/* Syscall wrappers for utmp management */ +int utmp_login(uint32_t pid, const char* line, const char* user, const char* host); +int utmp_logout(uint32_t pid, const char* line); +int utmp_dead(uint32_t pid, int exit_status); + #endif diff --git a/user/ulibc/src/utmp.c b/user/ulibc/src/utmp.c index adc56aaf..14761000 100644 --- a/user/ulibc/src/utmp.c +++ b/user/ulibc/src/utmp.c @@ -8,6 +8,8 @@ */ #include "utmp.h" +#include "syscall.h" +#include "errno.h" #include /* Stub implementation — AdrOS does not maintain utmp/wtmp records yet. @@ -46,3 +48,16 @@ void endutent(void) { void utmpname(const char* file) { (void)file; } + +/* Syscall wrappers for utmp management */ +int utmp_login(uint32_t pid, const char* line, const char* user, const char* host) { + return _syscall4(SYS_UTMP_LOGIN, (int)pid, (int)line, (int)user, (int)host); +} + +int utmp_logout(uint32_t pid, const char* line) { + return _syscall2(SYS_UTMP_LOGOUT, (int)pid, (int)line); +} + +int utmp_dead(uint32_t pid, int exit_status) { + return _syscall2(SYS_UTMP_DEAD, (int)pid, exit_status); +}