summaryrefslogtreecommitdiff
path: root/Source/Kernel
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Kernel')
-rw-r--r--Source/Kernel/Core/kmain.wtf.cpp4
-rw-r--r--Source/Kernel/Makefile1
-rw-r--r--Source/Kernel/Ressources/Configuration/Groups2
-rw-r--r--Source/Kernel/Ressources/Configuration/Users4
-rw-r--r--Source/Kernel/TaskManager/Process.class.cpp11
-rw-r--r--Source/Kernel/TaskManager/Process.class.h9
-rw-r--r--Source/Kernel/UserManager/Group.class.h22
-rw-r--r--Source/Kernel/UserManager/User.class.h67
-rw-r--r--Source/Kernel/UserManager/Usr.ns.cpp95
-rw-r--r--Source/Kernel/UserManager/Usr.ns.h25
10 files changed, 238 insertions, 2 deletions
diff --git a/Source/Kernel/Core/kmain.wtf.cpp b/Source/Kernel/Core/kmain.wtf.cpp
index a8fb002..9ef55e9 100644
--- a/Source/Kernel/Core/kmain.wtf.cpp
+++ b/Source/Kernel/Core/kmain.wtf.cpp
@@ -17,6 +17,7 @@
#include <MemoryManager/PageAlloc.ns.h>
#include <MemoryManager/GDT.ns.h>
#include <TaskManager/Task.ns.h>
+#include <UserManager/Usr.ns.h>
#include <SyscallManager/IDT.ns.h>
#include <String.class.h>
#include <ByteArray.class.h>
@@ -164,6 +165,9 @@ void kmain(multiboot_info_t* mbd, u32int magic) {
FloppyController::detect();
Log::log(KL_STATUS, "kmain : Floppy drives detected");
+ Usr::load();
+ Log::log(KL_STATUS, "kmain : User list loaded");
+
asm volatile("sti");
Log::log(KL_STATUS, "kmain : Interrupts enabled.");
diff --git a/Source/Kernel/Makefile b/Source/Kernel/Makefile
index 55c5fb0..4a65c54 100644
--- a/Source/Kernel/Makefile
+++ b/Source/Kernel/Makefile
@@ -59,6 +59,7 @@ Objects = Core/loader.wtf.o \
VFS/File.class.o \
VFS/TextFile.class.o \
VFS/DirectoryNode.class.o \
+ UserManager/Usr.ns.o \
FileSystems/RamFS/RamFS.class.o \
SyscallManager/IDT.ns.o \
SyscallManager/Ressource.class.o \
diff --git a/Source/Kernel/Ressources/Configuration/Groups b/Source/Kernel/Ressources/Configuration/Groups
new file mode 100644
index 0000000..1a222ec
--- /dev/null
+++ b/Source/Kernel/Ressources/Configuration/Groups
@@ -0,0 +1,2 @@
+0:root
+1:users
diff --git a/Source/Kernel/Ressources/Configuration/Users b/Source/Kernel/Ressources/Configuration/Users
new file mode 100644
index 0000000..ea4367f
--- /dev/null
+++ b/Source/Kernel/Ressources/Configuration/Users
@@ -0,0 +1,4 @@
+# format is uid:username:maingroup:completename
+
+0:root:0:Chuck Norris
+1000:alexis211:1:
diff --git a/Source/Kernel/TaskManager/Process.class.cpp b/Source/Kernel/TaskManager/Process.class.cpp
index 5256b48..5b777ed 100644
--- a/Source/Kernel/TaskManager/Process.class.cpp
+++ b/Source/Kernel/TaskManager/Process.class.cpp
@@ -4,6 +4,7 @@
#include <VFS/File.class.h>
#include <Linker/Binary.proto.h>
#include <Process.iface.h>
+#include <UserManager/Usr.ns.h>
namespace Mem {
extern Heap kheap;
@@ -13,6 +14,9 @@ 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_GETCMDLINE, &Process::getCmdlineSC),
CALL0(0, 0)
};
@@ -27,6 +31,7 @@ Process::Process() : Ressource(PRIF_OBJTYPE, m_callTable) { //Private constructo
Process* Process::createKernel(String cmdline, VirtualTerminal *vt) {
Process* p = new Process();
p->m_pid = 0;
+ p->m_ppid = 0;
p->m_cmdline = cmdline;
p->m_retval = 0;
p->m_state = P_RUNNING;
@@ -68,6 +73,7 @@ Process* Process::run(String filename, FSNode* cwd, u32int uid) {
Process::Process(String cmdline, u32int uid) : Ressource(PRIF_OBJTYPE, m_callTable) {
m_pid = Task::nextPid();
+ m_ppid = Task::currProcess()->getPid();
m_cmdline = cmdline;
m_retval = 0;
m_state = P_STARTING;
@@ -170,6 +176,11 @@ u32int Process::allocPageSC(u32int pos) {
return 0;
}
+u32int Process::getCmdlineSC() {
+ if (Task::currProcess()->getUid() == m_uid or Usr::uid() == 0) return m_cmdline.serialize();
+ return (u32int) - 1;
+}
+
u32int Process::freePageSC(u32int pos) {
if (Task::currProcess() != this) return 1;
if ((pos & 0x00000FFF) != 0) pos = (pos & 0xFFFFF000) + 0x1000;
diff --git a/Source/Kernel/TaskManager/Process.class.h b/Source/Kernel/TaskManager/Process.class.h
index eda5fc6..d5fe454 100644
--- a/Source/Kernel/TaskManager/Process.class.h
+++ b/Source/Kernel/TaskManager/Process.class.h
@@ -34,7 +34,8 @@ class Process : public Ressource {
private:
Process(); //Creates an empty process, used by creatKernel()
- u32int m_pid;
+ u32int m_pid; //Process IDentifier
+ u32int m_ppid; //Parent PID
String m_cmdline;
s32int m_retval; //Can be either a standard return value or an E_* (see #defines above)
u8int m_state; //Is one of P_* defined above
@@ -50,7 +51,9 @@ class Process : public Ressource {
//System calls
static call_t m_callTable[];
u32int exitSC();
+ u32int getCmdlineSC();
u32int allocPageSC(u32int);
+ u32int freePageSC(u32int);
public:
static u32int scall(u8int, u32int, u32int, u32int, u32int);
@@ -71,13 +74,15 @@ class Process : public Ressource {
void unregisterFileDescriptor(File* fd);
PageDirectory* getPagedir();
+ u32int getUid() { return m_uid; }
+ u32int getPid() { return m_pid; }
+ u32int getPpid() { return m_ppid; }
VirtualTerminal* getInVT();
VirtualTerminal* getOutVT();
void setInVT(VirtualTerminal* vt);
void setOutVT(VirtualTerminal* vt);
u32int getState() { return m_state; }
- u32int freePageSC(u32int);
};
#endif
diff --git a/Source/Kernel/UserManager/Group.class.h b/Source/Kernel/UserManager/Group.class.h
new file mode 100644
index 0000000..e515058
--- /dev/null
+++ b/Source/Kernel/UserManager/Group.class.h
@@ -0,0 +1,22 @@
+#ifndef DEF_GROUP_CLASS_H
+#define DEF_GROUP_CLASS_H
+
+#include <UserManager/Usr.ns.h>
+
+class Group {
+ friend void Usr::load();
+
+ private:
+ Group(String name, u32int gid) : m_name(name), m_gid(gid) {}
+
+ String m_name;
+ u32int m_gid;
+
+ public:
+ void setName(String wat) { m_name = wat; Usr::save(); }
+
+ String getName() { return m_name; }
+ u32int getGid() { return m_gid; }
+};
+
+#endif
diff --git a/Source/Kernel/UserManager/User.class.h b/Source/Kernel/UserManager/User.class.h
new file mode 100644
index 0000000..1ad55f4
--- /dev/null
+++ b/Source/Kernel/UserManager/User.class.h
@@ -0,0 +1,67 @@
+#ifndef DEF_USER_CLASS_H
+#define DEF_USER_CLASS_H
+
+#include <UserManager/Group.class.h>
+#include <Vector.class.h>
+
+class User {
+ friend void Usr::load();
+
+ private:
+ String m_username, m_completeName;
+ u32int m_uid;
+ Group* m_group;
+ Vector<Group*> 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) {
+ Vector<String> eg = extragroups.split(",");
+ for (u32int i = 0; i < eg.size(); i++) {
+ Group* g = Usr::group(eg[i].toInt());
+ if (g != 0) m_extraGroups.push(g);
+ }
+ }
+
+ public:
+ String getUserName() { return m_username; }
+ String getCompleteName() { return m_completeName; }
+ u32int getUid() { return m_uid; }
+ Group* getGroup() { return m_group; }
+ bool isInGroup(u32int gid) {
+ for (u32int i = 0; i < m_extraGroups.size(); i++)
+ if (m_extraGroups[i]->getGid() == gid) return true;
+ return false;
+ }
+ bool isInGroup(String name) {
+ for (u32int i = 0; i < m_extraGroups.size(); i++)
+ if (m_extraGroups[i]->getName() == name) return true;
+ return false;
+ }
+ bool isInGroup(Group* g) {
+ for (u32int i = 0; i < m_extraGroups.size(); i++)
+ if (m_extraGroups[i] == g) return true;
+ return false;
+ }
+
+ String getGroups() {
+ String ret;
+ for (u32int i = 0; i < m_extraGroups.size(); i++) {
+ if (!ret.empty()) ret += ",";
+ ret += String::number(m_extraGroups[i]->getGid());
+ }
+ return ret;
+ }
+
+ void setUserName(String wat) { m_username = wat; Usr::save(); }
+ void setCompleteName(String wat) { m_completeName = wat; Usr::save(); }
+ void setGroup(Group* group) { m_group = group; Usr::save(); }
+ void addGroup(u32int gid) {
+ Group* g = Usr::group(gid);
+ if (g != 0 and !isInGroup(g)) {
+ m_extraGroups.push(g);
+ }
+ Usr::save();
+ }
+};
+
+#endif
diff --git a/Source/Kernel/UserManager/Usr.ns.cpp b/Source/Kernel/UserManager/Usr.ns.cpp
new file mode 100644
index 0000000..a551344
--- /dev/null
+++ b/Source/Kernel/UserManager/Usr.ns.cpp
@@ -0,0 +1,95 @@
+#include "Usr.ns.h"
+
+#include <UserManager/User.class.h>
+#include <SimpleList.class.h>
+#include <TaskManager/Task.ns.h>
+#include <VFS/TextFile.class.h>
+
+/*
+ * Syntax for Users and Groups configuration files : one entry per line
+ * syntax for Users : <uid>:<username>:<basegroup>:<extragroup>,<extragroup>:<completename>
+ * syntax for Groups : <gid>:<name>
+ */
+
+namespace Usr {
+
+SimpleList <User> *m_users = 0;
+SimpleList <Group> *m_groups = 0;
+
+void load() {
+ if (m_users != 0) delete m_users;
+ if (m_groups != 0) delete m_groups;
+ m_users = 0, m_groups = 0;
+
+ TextFile groups("/System/Configuration/Groups", FM_READ);
+ while (!groups.eof()) {
+ String s = groups.readLine();
+ Vector<String> data = s.split(":");
+ if (data.size() == 2 and !(s[0] == WChar("#"))) {
+ m_groups = m_groups->cons(Group(data[1], data[0].toInt()));
+ }
+ }
+
+ TextFile users("/System/Configuration/Users", FM_READ);
+ while (!users.eof()) {
+ String s = users.readLine();
+ Vector<String> 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()));
+ }
+ }
+}
+
+void save() {
+ TextFile groups("/System/Configuration/Groups", FM_TRUNCATE);
+ for (SimpleList<Group> *iter = m_groups; iter != 0; iter = iter->next()) {
+ groups.write(String::number(iter->v().getGid()) + ":" + iter->v().getName(), true);
+ }
+ TextFile users("/System/Configuration/Users", FM_TRUNCATE);
+ for (SimpleList<User> *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);
+ }
+}
+
+u32int uid() {
+ return Task::currProcess()->getUid();
+}
+
+User* user(u32int uid) {
+ for (SimpleList<User> *iter = m_users; iter != 0; iter = iter->next()) {
+ if (iter->v().getUid() == uid) return &iter->v();
+ }
+ return 0;
+}
+
+User* user(String username) {
+ for (SimpleList<User> *iter = m_users; iter != 0; iter = iter->next()) {
+ if (iter->v().getUserName() == username) return &iter->v();
+ }
+ return 0;
+}
+
+User* user() { return user(uid()); }
+
+Group* group(u32int gid) {
+ for (SimpleList<Group> *iter = m_groups; iter != 0; iter = iter->next()) {
+ if (iter->v().getGid() == gid) return &iter->v();
+ }
+ return 0;
+}
+
+Group* group(String name) {
+ for (SimpleList<Group> *iter = m_groups; iter != 0; iter = iter->next()) {
+ if (iter->v().getName() == name) return &iter->v();
+ }
+ return 0;
+}
+
+u32int uid(String username) {
+ User* x = user(username);
+ return (x != 0 ? x->getUid() : (u32int) - 1);
+}
+
+};
diff --git a/Source/Kernel/UserManager/Usr.ns.h b/Source/Kernel/UserManager/Usr.ns.h
new file mode 100644
index 0000000..36ee2cb
--- /dev/null
+++ b/Source/Kernel/UserManager/Usr.ns.h
@@ -0,0 +1,25 @@
+#ifndef DEF_USR_NS_H
+#define DEF_USR_NS_H
+
+#include <String.class.h>
+class Group;
+class User;
+
+namespace Usr {
+ void load(); //Loads users into memory, from /System/Configuration/{Users,Groups}
+ void save(); //Saves config from mem to filesystem
+
+ u32int uid(); //Returns current processes UID
+
+ User* user(u32int uid); //Returns user from UID
+ User* user(String username);
+ User* user();
+ Group* group(u32int gid);
+ Group* group(String name);
+
+ u32int uid(String username); //Returns UID of username
+};
+
+#endif
+
+#include <UserManager/User.class.h>