From: John Hodge Date: Tue, 19 Jan 2010 06:36:15 +0000 (+0800) Subject: Multi-user testing and bugfixing X-Git-Tag: rel0.06~319 X-Git-Url: https://git.ucc.asn.au/?p=tpg%2Facess2.git;a=commitdiff_plain;h=56b770130dc830c6a9dccb6c50e6442a8bdb0b6c Multi-user testing and bugfixing - Actually changes the UID now - Added stub normal user 'tpg', no password --- diff --git a/Kernel/Makefile.BuildNum b/Kernel/Makefile.BuildNum index 83ad29a9..52c5b788 100644 --- a/Kernel/Makefile.BuildNum +++ b/Kernel/Makefile.BuildNum @@ -1 +1 @@ -BUILD_NUM = 1370 +BUILD_NUM = 1375 diff --git a/Kernel/include/acess.h b/Kernel/include/acess.h index 24621b9d..a87aaec1 100644 --- a/Kernel/include/acess.h +++ b/Kernel/include/acess.h @@ -10,6 +10,12 @@ #include #include +#include "errno.h" + +// --- Types --- +typedef Uint tUID; +typedef Uint tGID; +typedef Sint64 tTimestamp; // --- Helper Macros --- /** @@ -358,8 +364,8 @@ extern int Proc_Spawn(char *Path); extern void Threads_Exit(); extern void Threads_Yield(); extern void Threads_Sleep(); -extern int Threads_GetUID(); -extern int Threads_GetGID(); +extern tUID Threads_GetUID(); +extern tGID Threads_GetGID(); extern int SpawnTask(tThreadFunction Function, void *Arg); extern Uint *Threads_GetCfgPtr(int Id); /** diff --git a/Kernel/syscalls.c b/Kernel/syscalls.c index ba9051a9..a555720f 100644 --- a/Kernel/syscalls.c +++ b/Kernel/syscalls.c @@ -28,8 +28,10 @@ extern Uint Binary_Load(char *file, Uint *entryPoint); extern int Threads_SetName(char *NewName); extern int Threads_GetPID(); extern int Threads_GetTID(); -extern int Threads_GetUID(); -extern int Threads_GetGID(); +extern tUID Threads_GetUID(); +extern int Threads_SetUID(Uint *errno, tUID ID); +extern tGID Threads_GetGID(); +extern int Threads_SetGID(Uint *errno, tGID ID); // === PROTOTYPES === int Syscall_ValidString(Uint Addr); @@ -40,7 +42,7 @@ extern int Threads_GetGID(); void SyscallHandler(tSyscallRegs *Regs) { Uint64 ret = 0; - Uint err = 0; + Uint err = -EOK; ENTER("iThread iNum", Threads_GetTID(), Regs->Num); if(Regs->Num < NUM_SYSCALLS) @@ -104,8 +106,8 @@ void SyscallHandler(tSyscallRegs *Regs) case SYS_GETGID: ret = Threads_GetGID(); break; // -- Set User/Group IDs - case SYS_SETUID: Log("Setting User ID to %i", Regs->Arg1); break; - case SYS_SETGID: Log("Setting Group ID to %i", Regs->Arg1); break; + case SYS_SETUID: ret = Threads_SetUID(&err, Regs->Arg1); break; + case SYS_SETGID: ret = Threads_SetGID(&err, Regs->Arg1); break; // -- Send Message case SYS_SENDMSG: diff --git a/Kernel/threads.c b/Kernel/threads.c index 90eb740e..890f32d7 100644 --- a/Kernel/threads.c +++ b/Kernel/threads.c @@ -41,8 +41,10 @@ void Threads_Wake(tThread *Thread); void Threads_AddActive(tThread *Thread); int Threads_GetPID(); int Threads_GetTID(); - int Threads_GetUID(); - int Threads_GetGID(); +tUID Threads_GetUID(); + int Threads_SetUID(Uint *Errno, tUID ID); +tGID Threads_GetGID(); + int Threads_SetGID(Uint *Errno, tUID ID); void Threads_Dump(); // === GLOBALS === @@ -616,14 +618,40 @@ int Threads_GetTID() { return Proc_GetCurThread()->TID; } -int Threads_GetUID() +tUID Threads_GetUID() { - return Proc_GetCurThread()->UID; + tThread *t = Proc_GetCurThread(); + int ret = t->UID; + Log("Threads_GetUID: TID %i, return %i", t->TID, ret); + return ret; +} +int Threads_SetUID(Uint *Errno, tUID ID) +{ + tThread *t = Proc_GetCurThread(); + if( t->UID != 0 ) { + *Errno = -EACCES; + return -1; + } + Log("Threads_SetUID - Setting User ID to %i", ID); + t->UID = ID; + return 0; } -int Threads_GetGID() + +tGID Threads_GetGID() { return Proc_GetCurThread()->GID; } +int Threads_SetGID(Uint *Errno, tGID ID) +{ + tThread *t = Proc_GetCurThread(); + if( t->UID != 0 ) { + *Errno = -EACCES; + return -1; + } + Log("Threads_SetGID - Setting Group ID to %i", ID); + t->GID = ID; + return 0; +} /** * \fn void Threads_Dump() diff --git a/Modules/IPStack/main.c b/Modules/IPStack/main.c index 76a18f0b..831000a4 100644 --- a/Modules/IPStack/main.c +++ b/Modules/IPStack/main.c @@ -3,7 +3,7 @@ * - Stack Initialisation */ #define DEBUG 0 -#define VERSION ((0<<8)|10) +#define VERSION VER3(0,10,0) #include "ipstack.h" #include "link.h" #include diff --git a/Usermode/Applications/Makefile.cfg b/Usermode/Applications/Makefile.cfg index 0418fb77..bc33f905 100644 --- a/Usermode/Applications/Makefile.cfg +++ b/Usermode/Applications/Makefile.cfg @@ -12,3 +12,4 @@ ASFLAGS = -felf CPPFLAGS = -I$(ACESSUSERDIR)/include/ CFLAGS = -fno-stack-protector $(CPPFLAGS) LDFLAGS = -T $(ACESSUSERDIR)/Libraries/acess.ld -L $(ACESSUSERDIR)/Libraries -I /Acess/Libs/ld-acess.so -lc +DIR = Bin diff --git a/Usermode/Applications/Makefile.tpl b/Usermode/Applications/Makefile.tpl index d3582703..d18e52e3 100644 --- a/Usermode/Applications/Makefile.tpl +++ b/Usermode/Applications/Makefile.tpl @@ -13,7 +13,7 @@ clean: @$(RM) $(OBJ) $(BIN) $(BIN).dsm Map.txt install: $(BIN) - $(xCP) $(BIN) $(DISTROOT)/Bin/ + $(xCP) $(BIN) $(DISTROOT)/$(DIR)/ $(BIN): $(OBJ) @echo --- $(LD) -o $@ diff --git a/Usermode/Applications/init_src/Makefile b/Usermode/Applications/init_src/Makefile index 23d7c276..f60ea49a 100644 --- a/Usermode/Applications/init_src/Makefile +++ b/Usermode/Applications/init_src/Makefile @@ -8,5 +8,6 @@ LDFLAGS += BIN = ../init OBJ = main.o +DIR = SBin -include ../Makefile.tpl diff --git a/Usermode/Applications/login_src/Makefile b/Usermode/Applications/login_src/Makefile index 239f6ff9..63909f64 100644 --- a/Usermode/Applications/login_src/Makefile +++ b/Usermode/Applications/login_src/Makefile @@ -6,5 +6,6 @@ DBTYPE = tpl OBJ = main.o database_$(DBTYPE).o BIN = ../login +DIR = SBin -include ../Makefile.tpl diff --git a/Usermode/Applications/login_src/database_tpl.c b/Usermode/Applications/login_src/database_tpl.c index de903d59..0f794694 100644 --- a/Usermode/Applications/login_src/database_tpl.c +++ b/Usermode/Applications/login_src/database_tpl.c @@ -22,9 +22,11 @@ tUserInfo gUserInfo; */ int ValidateUser(char *Username, char *Password) { + printf("Username: %s\n", Username); if(Username == NULL) return -1; if(Password == NULL) return -1; if(strcmp(Username, "root") == 0) return 0; + if(strcmp(Username, "tpg") == 0) return 1; return -1; } @@ -33,13 +35,22 @@ int ValidateUser(char *Username, char *Password) * \brief Gets a users information */ tUserInfo *GetUserInfo(int UID) -{ - if(UID != 0) return NULL; - - gUserInfo.UID = 0; - gUserInfo.GID = 0; +{ + gUserInfo.UID = UID; + gUserInfo.GID = UID; gUserInfo.Shell = "/Acess/Bin/CLIShell"; - gUserInfo.Home = "/Acess/Root"; + switch(UID) + { + case 0: + gUserInfo.Home = "/Acess/Root"; + break; + case 1: + gUserInfo.Home = "/Acess/Users/tpg"; + break; + default: + gUserInfo.Home = "/Acess/Users/Guest"; + break; + } return &gUserInfo; }