From ec6a6922d074da4b64976282333e308deb39aeec Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Sun, 8 Nov 2009 12:58:27 +0100 Subject: Introduced PaperWork : our init/login manager. Login with user=root;pass=admin or user=alexis211;pass=iamgod --- Source/Kernel/Core/kmain.wtf.cpp | 16 +++ Source/Kernel/Makefile | 1 + Source/Kernel/Ressources/Configuration/Users | 4 +- Source/Kernel/TaskManager/Process-sc.class.cpp | 143 +++++++++++++++++++++ Source/Kernel/TaskManager/Process.class.cpp | 113 ---------------- Source/Kernel/TaskManager/Process.class.h | 2 + Source/Kernel/UserManager/User.class.h | 9 +- Source/Kernel/UserManager/Usr.ns.cpp | 15 ++- .../Kernel/VTManager/VirtualTerminal-sc.proto.cpp | 25 +++- Source/Kernel/VTManager/VirtualTerminal.proto.cpp | 19 --- Source/Kernel/VTManager/VirtualTerminal.proto.h | 2 +- 11 files changed, 204 insertions(+), 145 deletions(-) create mode 100644 Source/Kernel/TaskManager/Process-sc.class.cpp (limited to 'Source/Kernel') diff --git a/Source/Kernel/Core/kmain.wtf.cpp b/Source/Kernel/Core/kmain.wtf.cpp index 76d8971..62f96d5 100644 --- a/Source/Kernel/Core/kmain.wtf.cpp +++ b/Source/Kernel/Core/kmain.wtf.cpp @@ -171,6 +171,7 @@ void kmain(multiboot_info_t* mbd, u32int magic) { asm volatile("sti"); Log::log(KL_STATUS, "kmain : Interrupts enabled."); + /* new KernelShell(cwd); //No need to save that in a var, it is automatically destroyed anyways Log::log(KL_STATUS, "kmain : Kernel shell launched"); //kvt->unmap(); @@ -181,6 +182,21 @@ void kmain(multiboot_info_t* mbd, u32int magic) { Log::log(KL_STATUS, "kmain : All kernel shells finished. Halting."); Sys::halt(); + */ + + Process* p = Process::run("/System/Applications/PaperWork.app", 0); + if (p == 0) { + PANIC("Could not launch PaperWork !"); + } else { + VirtualTerminal* vt = new ScrollableVT(15, 76, 200, SHELL_FGCOLOR, SHELL_BGCOLOR); + Kbd::setFocus(vt); + ((ScrollableVT*)vt)->map(9); + p->setInVT(vt); + p->setOutVT(vt); + p->start(); + while (p->getState() != P_FINISHED) Task::currThread()->sleep(100); + PANIC("PaperWork finished."); + } PANIC("END OF KMAIN"); } diff --git a/Source/Kernel/Makefile b/Source/Kernel/Makefile index 301d64c..b7a8bd3 100644 --- a/Source/Kernel/Makefile +++ b/Source/Kernel/Makefile @@ -26,6 +26,7 @@ Objects = Core/loader.wtf.o \ DeviceManager/Time.ns.o \ DeviceManager/Kbd.ns.o \ TaskManager/Process.class.o \ + TaskManager/Process-sc.class.o \ TaskManager/Thread.class.o \ TaskManager/Task.ns.o \ TaskManager/Task.wtf.o \ diff --git a/Source/Kernel/Ressources/Configuration/Users b/Source/Kernel/Ressources/Configuration/Users index cc98bf5..490bc6b 100644 --- a/Source/Kernel/Ressources/Configuration/Users +++ b/Source/Kernel/Ressources/Configuration/Users @@ -1,4 +1,4 @@ # format is uid:username:maingroup:completename -0:melon:0::The Melon Operating System -1000:alexis211:1:: +0:melon:0::The Melon Operating System:admin +1000:alexis211:1::The Creator:iamgod diff --git a/Source/Kernel/TaskManager/Process-sc.class.cpp b/Source/Kernel/TaskManager/Process-sc.class.cpp new file mode 100644 index 0000000..5a94c81 --- /dev/null +++ b/Source/Kernel/TaskManager/Process-sc.class.cpp @@ -0,0 +1,143 @@ +#include "Process.class.h" +#include +#include +#include +#include +#include + +#define ISPARENT Task::currProcess()->getPid() == m_ppid + +call_t Process::m_callTable[] = { + CALL0(PRIF_EXIT, &Process::exitSC), + CALL1(PRIF_ALLOCPAGE, &Process::allocPageSC), + CALL1(PRIF_FREEPAGE, &Process::freePageSC), + CALL0(PRIF_GETPID, &Process::getPid), + CALL0(PRIF_GETPPID, &Process::getPpid), + CALL0(PRIF_ARGC, &Process::argcSC), + CALL1(PRIF_ARGV, &Process::argvSC), + CALL0(PRIF_START, &Process::startSC), + CALL1(PRIF_AUTODELETE, &Process::autoDeleteSC), + CALL1(PRIF_PUSHARG, &Process::pushArgSC), + CALL1(PRIF_SETOUTVT, &Process::setOutVTSC), + CALL1(PRIF_SETINVT, &Process::setInVTSC), + CALL2(PRIF_AUTHPW, &Process::authPWSC), + CALL1(PRIF_AUTHNOPW, &Process::authNoPWSC), + CALL0(0, 0) +}; + +u32int Process::scall(u8int wat, u32int a, u32int b, u32int c, u32int d) { + if (wat == PRIF_SGETCPR) return Task::currProcess()->resId(); + if (wat == PRIF_SRUN) { + String* e = (String*)a; + Process* p = Process::run(*e, Usr::uid()); + if (p != 0) return p->resId(); + } + if (wat == PRIF_SWAIT) { + Process* p = Res::get(a, PRIF_OBJTYPE); + if (Task::currProcess()->getPid() != p->m_ppid) return 0; + while (p->m_state != P_FINISHED and !p->m_autodelete) Task::currThread()->sleep(20); + if (p->m_autodelete) return E_AUTODELETE; + s32int ret = p->m_retval; + delete p; + return ret; + } + return (u32int) - 1; +} + +u32int Process::exitSC() { + if (Task::currProcess() != this) return 1; + Task::currentThreadExits(E_EXIT); + return 0; +} + +u32int Process::allocPageSC(u32int pos) { + if (Task::currProcess() != this) return 1; + if ((pos & 0x00000FFF) != 0) pos = (pos & 0xFFFFF000) + 0x1000; + if (pos >= 0xC0000000) return 1; + m_pagedir->allocFrame(pos, true, true); + return 0; +} + +u32int Process::argcSC() { + if (Usr::uid() == m_uid or ISROOT or ISPARENT) { + return (m_arguments.size()); + } + return (u32int) - 1; +} + +u32int Process::argvSC(u32int idx) { + if (idx >= m_arguments.size()) return (u32int) - 1; + if (Usr::uid() == m_uid or ISROOT or ISPARENT) { + return m_arguments[idx].serialize(); + } + return (u32int) - 1; +} + +u32int Process::freePageSC(u32int pos) { + if (Task::currProcess() != this) return 1; + if ((pos & 0x00000FFF) != 0) pos = (pos & 0xFFFFF000) + 0x1000; + if (pos >= 0xC0000000) return 1; + m_pagedir->freeFrame(pos); + return 0; +} + +u32int Process::startSC() { + if (Task::currProcess()->getPid() == m_ppid) { + start(); + return 1; + } + return 0; +} + +u32int Process::autoDeleteSC(u32int d) { + if (Task::currProcess()->getPid() != m_ppid) return 2; + m_autodelete = (d != 0); + return (m_autodelete ? 1 : 0); +} + +u32int Process::pushArgSC(u32int arg) { + String* a = (String*)arg; + m_arguments.push(*a); + return 0; +} + +u32int Process::setInVTSC(u32int vtid) { + if (Task::currProcess()->getPid() != m_ppid) return 0; + VirtualTerminal* vt = Res::get(vtid, VTIF_OBJTYPE); + if (vt != 0) setInVT(vt); + return 1; +} + +u32int Process::setOutVTSC(u32int vtid) { + if (Task::currProcess()->getPid() != m_ppid) return 0; + VirtualTerminal* vt = Res::get(vtid, VTIF_OBJTYPE); + if (vt != 0) setOutVT(vt); + return 1; +} + +u32int Process::authPWSC(u32int user, u32int pw) { + if (Task::currProcess() != this) return 0; + String* u = (String*)user; + String* p = (String*)pw; + User* usr = Usr::user(*u); + if (usr == 0) return 0; + if (usr->vrfyPassword(*p)) { + m_uid = usr->getUid(); + return 1; + } + return 0; +} + +u32int Process::authNoPWSC(u32int user) { + if (Task::currProcess() != this) return 0; + if (!ISROOT) return 0; + String* u = (String*)user; + User* usr = Usr::user(*u); + if (usr == 0) return 0; + m_uid = usr->getUid(); + return 1; +} + +bool Process::accessible() { + return (m_uid == Usr::uid()); +} diff --git a/Source/Kernel/TaskManager/Process.class.cpp b/Source/Kernel/TaskManager/Process.class.cpp index eec28d8..bca5f1c 100644 --- a/Source/Kernel/TaskManager/Process.class.cpp +++ b/Source/Kernel/TaskManager/Process.class.cpp @@ -8,47 +8,10 @@ #include #include -#define ISPARENT Task::currProcess()->getPid() == m_ppid - namespace Mem { extern Heap kheap; } -call_t Process::m_callTable[] = { - CALL0(PRIF_EXIT, &Process::exitSC), - CALL1(PRIF_ALLOCPAGE, &Process::allocPageSC), - CALL1(PRIF_FREEPAGE, &Process::freePageSC), - CALL0(PRIF_GETPID, &Process::getPid), - CALL0(PRIF_GETPPID, &Process::getPpid), - CALL0(PRIF_ARGC, &Process::argcSC), - CALL1(PRIF_ARGV, &Process::argvSC), - CALL0(PRIF_START, &Process::startSC), - CALL1(PRIF_AUTODELETE, &Process::autoDeleteSC), - CALL1(PRIF_PUSHARG, &Process::pushArgSC), - CALL1(PRIF_SETOUTVT, &Process::setOutVTSC), - CALL1(PRIF_SETINVT, &Process::setInVTSC), - CALL0(0, 0) -}; - -u32int Process::scall(u8int wat, u32int a, u32int b, u32int c, u32int d) { - if (wat == PRIF_SGETCPR) return Task::currProcess()->resId(); - if (wat == PRIF_SRUN) { - String* e = (String*)a; - Process* p = Process::run(*e, Usr::uid()); - if (p != 0) return p->resId(); - } - if (wat == PRIF_SWAIT) { - Process* p = Res::get(a, PRIF_OBJTYPE); - if (Task::currProcess()->getPid() != p->m_ppid) return 0; - while (p->m_state != P_FINISHED and !p->m_autodelete) Task::currThread()->sleep(20); - if (p->m_autodelete) return E_AUTODELETE; - s32int ret = p->m_retval; - delete p; - return ret; - } - return (u32int) - 1; -} - Process::Process() : Ressource(PRIF_OBJTYPE, m_callTable) { //Private constructor, does nothing } @@ -196,79 +159,3 @@ void Process::setInVT(VirtualTerminal* vt) { void Process::setOutVT(VirtualTerminal* vt) { m_outVT = vt; } - -u32int Process::exitSC() { - if (Task::currProcess() != this) return 1; - Task::currentThreadExits(E_EXIT); - return 0; -} - -u32int Process::allocPageSC(u32int pos) { - if (Task::currProcess() != this) return 1; - if ((pos & 0x00000FFF) != 0) pos = (pos & 0xFFFFF000) + 0x1000; - if (pos >= 0xC0000000) return 1; - m_pagedir->allocFrame(pos, true, true); - return 0; -} - -u32int Process::argcSC() { - if (Usr::uid() == m_uid or ISROOT or ISPARENT) { - return (m_arguments.size()); - } - return (u32int) - 1; -} - -u32int Process::argvSC(u32int idx) { - if (idx >= m_arguments.size()) return (u32int) - 1; - if (Usr::uid() == m_uid or ISROOT or ISPARENT) { - return m_arguments[idx].serialize(); - } - return (u32int) - 1; -} - -u32int Process::freePageSC(u32int pos) { - if (Task::currProcess() != this) return 1; - if ((pos & 0x00000FFF) != 0) pos = (pos & 0xFFFFF000) + 0x1000; - if (pos >= 0xC0000000) return 1; - m_pagedir->freeFrame(pos); - return 0; -} - -u32int Process::startSC() { - if (Task::currProcess()->getPid() == m_ppid) { - start(); - return 1; - } - return 0; -} - -u32int Process::autoDeleteSC(u32int d) { - if (Task::currProcess()->getPid() != m_ppid) return 2; - m_autodelete = (d != 0); - return (m_autodelete ? 1 : 0); -} - -u32int Process::pushArgSC(u32int arg) { - String* a = (String*)arg; - m_arguments.push(*a); - return 0; -} - -u32int Process::setInVTSC(u32int vtid) { - if (Task::currProcess()->getPid() != m_ppid) return 0; - VirtualTerminal* vt = Res::get(vtid, VTIF_OBJTYPE); - if (vt != 0) setInVT(vt); - return 1; -} - -u32int Process::setOutVTSC(u32int vtid) { - if (Task::currProcess()->getPid() != m_ppid) return 0; - VirtualTerminal* vt = Res::get(vtid, VTIF_OBJTYPE); - if (vt != 0) setOutVT(vt); - return 1; -} - - -bool Process::accessible() { - return (m_uid == Usr::uid()); -} diff --git a/Source/Kernel/TaskManager/Process.class.h b/Source/Kernel/TaskManager/Process.class.h index 11da57b..053a640 100644 --- a/Source/Kernel/TaskManager/Process.class.h +++ b/Source/Kernel/TaskManager/Process.class.h @@ -64,6 +64,8 @@ class Process : public Ressource { u32int pushArgSC(u32int); u32int setOutVTSC(u32int); u32int setInVTSC(u32int); + u32int authPWSC(u32int, u32int); + u32int authNoPWSC(u32int); bool accessible(); public: diff --git a/Source/Kernel/UserManager/User.class.h b/Source/Kernel/UserManager/User.class.h index ae02281..9d13ef1 100644 --- a/Source/Kernel/UserManager/User.class.h +++ b/Source/Kernel/UserManager/User.class.h @@ -8,13 +8,13 @@ class User { friend void Usr::load(); private: - String m_username, m_completeName; + String m_username, m_completeName, m_password; u32int m_uid; Group* m_group; Vector m_extraGroups; - User(String username, String completeName, Group* group, String extragroups, u32int uid) - : m_username(username), m_completeName(completeName), m_uid(uid), m_group(group) { + User(String username, String completeName, String password, Group* group, String extragroups, u32int uid) + : m_username(username), m_completeName(completeName), m_password(password), m_uid(uid), m_group(group) { Vector eg = extragroups.split(","); for (u32int i = 0; i < eg.size(); i++) { Group* g = Usr::group(eg[i].toInt()); @@ -25,6 +25,7 @@ class User { public: String getUserName() { return m_username; } String getCompleteName() { return m_completeName; } + String getPassword() { return m_password; } u32int getUid() { return m_uid; } Group* getGroup() { return m_group; } bool isInGroup(u32int gid) { @@ -45,6 +46,7 @@ class User { if (m_extraGroups[i] == g) return true; return false; } + bool vrfyPassword(String pw) { return pw == m_password; } String getGroups() { String ret; @@ -57,6 +59,7 @@ class User { void setUserName(String wat) { m_username = wat; Usr::save(); } void setCompleteName(String wat) { m_completeName = wat; Usr::save(); } + void setPassword(String wat) { m_password = wat; Usr::save(); } void setGroup(Group* group) { m_group = group; Usr::save(); } void addGroup(u32int gid) { Group* g = Usr::group(gid); diff --git a/Source/Kernel/UserManager/Usr.ns.cpp b/Source/Kernel/UserManager/Usr.ns.cpp index db371ae..ecf9bae 100644 --- a/Source/Kernel/UserManager/Usr.ns.cpp +++ b/Source/Kernel/UserManager/Usr.ns.cpp @@ -5,10 +5,11 @@ #include #include #include +#include /* * Syntax for Users and Groups configuration files : one entry per line - * syntax for Users : :::,: + * syntax for Users : :::,:: * syntax for Groups : : */ @@ -22,6 +23,8 @@ void load() { if (m_groups != 0) delete m_groups; m_users = 0, m_groups = 0; + if (VFS::find("/System/Configuration/Groups")) VFS::find("/System/Configuration/Groups")->setPermissions(0600); + if (VFS::find("/System/Configuration/Users")) VFS::find("/System/Configuration/Users")->setPermissions(0600); TextFile groups("/System/Configuration/Groups", FM_READ); while (!groups.eof()) { String s = groups.readLine(); @@ -38,13 +41,14 @@ void load() { TextFile users("/System/Configuration/Users", FM_READ); while (!users.eof()) { String s = users.readLine(); + if (s == "" or s[0] == WChar("#")) continue; Vector data = s.split(":"); - if (data.size() == 5 and !(s[0] == WChar("#"))) { - m_users = m_users->cons(User(data[1], data[4], group(data[2].toInt()), data[3], data[0].toInt())); + if (data.size() == 6) { + m_users = m_users->cons(User(data[1], data[4], data[5], group(data[2].toInt()), data[3], data[0].toInt())); } } if (m_users == 0) { - m_users = m_users->cons(User("melon", "MelOS", group(0), "", 0)); + m_users = m_users->cons(User("melon", "MelOS", "", group(0), "", 0)); Log::log(KL_WARNING, "Usr.ns : users file invalid, had to add default users."); } } @@ -58,7 +62,8 @@ void save() { for (SimpleList *iter = m_users; iter != 0; iter = iter->next()) { users.write(String::number(iter->v().getUid()) + ":" + iter->v().getUserName() + ":" + String::number(iter->v().getGroup()->getGid()) + ":" - + iter->v().getGroups() + ":" + iter->v().getCompleteName(), true); + + iter->v().getGroups() + ":" + iter->v().getCompleteName() + ":" + + iter->v().getPassword(), true); } } diff --git a/Source/Kernel/VTManager/VirtualTerminal-sc.proto.cpp b/Source/Kernel/VTManager/VirtualTerminal-sc.proto.cpp index 0a4e14b..5506c74 100644 --- a/Source/Kernel/VTManager/VirtualTerminal-sc.proto.cpp +++ b/Source/Kernel/VTManager/VirtualTerminal-sc.proto.cpp @@ -1,4 +1,25 @@ #include "VirtualTerminal.proto.h" +#include +#include + +call_t VirtualTerminal::m_callTable[] = { + CALL1(VTIF_WRITEHEX, &VirtualTerminal::writeHexSC), + CALL2(VTIF_WRITEDEC, &VirtualTerminal::writeDecSC), + CALL1(VTIF_WRITE, &VirtualTerminal::writeSC), + CALL1(VTIF_PUT, &VirtualTerminal::putSC), + CALL1(VTIF_READLINE, &VirtualTerminal::readLineSC), + CALL1(VTIF_SETCOLOR, &VirtualTerminal::setColorSC), + CALL1(VTIF_SETCSRLINE, &VirtualTerminal::setCursorLineSC), + CALL1(VTIF_SETCSRCOL, &VirtualTerminal::setCursorColSC), + CALL0(VTIF_ISBOXED, &VirtualTerminal::isBoxedSC), + CALL0(0, 0) +}; + +u32int VirtualTerminal::scall(u8int wat, u32int a, u32int b, u32int c, u32int d) { + if (wat == VTIF_SGETPRINVT) return Task::currProcess()->getInVT()->resId(); + if (wat == VTIF_SGETPROUTVT) return Task::currProcess()->getOutVT()->resId(); + return (u32int) - 1; +} u32int VirtualTerminal::writeHexSC(u32int number) { writeHex(number); @@ -22,8 +43,8 @@ u32int VirtualTerminal::putSC(u32int code) { return 0; } -u32int VirtualTerminal::readLineSC() { - return readLine().serialize(); +u32int VirtualTerminal::readLineSC(u32int show) { + return readLine(show != 0).serialize(); } u32int VirtualTerminal::setColorSC(u32int x) { diff --git a/Source/Kernel/VTManager/VirtualTerminal.proto.cpp b/Source/Kernel/VTManager/VirtualTerminal.proto.cpp index 2587369..0079707 100644 --- a/Source/Kernel/VTManager/VirtualTerminal.proto.cpp +++ b/Source/Kernel/VTManager/VirtualTerminal.proto.cpp @@ -5,25 +5,6 @@ #include -call_t VirtualTerminal::m_callTable[] = { - CALL1(VTIF_WRITEHEX, &VirtualTerminal::writeHexSC), - CALL2(VTIF_WRITEDEC, &VirtualTerminal::writeDecSC), - CALL1(VTIF_WRITE, &VirtualTerminal::writeSC), - CALL1(VTIF_PUT, &VirtualTerminal::putSC), - CALL0(VTIF_READLINE, &VirtualTerminal::readLineSC), - CALL1(VTIF_SETCOLOR, &VirtualTerminal::setColorSC), - CALL1(VTIF_SETCSRLINE, &VirtualTerminal::setCursorLineSC), - CALL1(VTIF_SETCSRCOL, &VirtualTerminal::setCursorColSC), - CALL0(VTIF_ISBOXED, &VirtualTerminal::isBoxedSC), - CALL0(0, 0) -}; - -u32int VirtualTerminal::scall(u8int wat, u32int a, u32int b, u32int c, u32int d) { - if (wat == VTIF_SGETPRINVT) return Task::currProcess()->getInVT()->resId(); - if (wat == VTIF_SGETPROUTVT) return Task::currProcess()->getOutVT()->resId(); - return (u32int) - 1; -} - VirtualTerminal::VirtualTerminal() : Ressource(VTIF_OBJTYPE, m_callTable), m_kbdMutex(false), m_kbdbuffMutex(false), m_kbdbuff() { } diff --git a/Source/Kernel/VTManager/VirtualTerminal.proto.h b/Source/Kernel/VTManager/VirtualTerminal.proto.h index 90fa88e..9c138ec 100644 --- a/Source/Kernel/VTManager/VirtualTerminal.proto.h +++ b/Source/Kernel/VTManager/VirtualTerminal.proto.h @@ -25,7 +25,7 @@ class VirtualTerminal : public Ressource { u32int writeDecSC(u32int, u32int); u32int writeSC(u32int); u32int putSC(u32int); - u32int readLineSC(); + u32int readLineSC(u32int); u32int setColorSC(u32int); u32int setCursorLineSC(u32int); u32int setCursorColSC(u32int); -- cgit v1.2.3