[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tyndur-devel] [PATCH] libc: Fake-Implementierung von getpwd{nam, uid} und getgr{nam, gid}



+ libc: Implementierung der Funktionen getpwdnam und getpwduid aus pwd.h
+ libc: Implementierung der Funktionen getgrnam und getgrgid aus grp.h
---
 src/modules/include/grp.h   |   75 ++++++++++++++++++++++++++++++++++++++
 src/modules/include/pwd.h   |   79 ++++++++++++++++++++++++++++++++++++++++
 src/modules/lib/posix/grp.c |   84 +++++++++++++++++++++++++++++++++++++++++++
 src/modules/lib/posix/pwd.c |   84 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 322 insertions(+), 0 deletions(-)
 create mode 100644 src/modules/include/grp.h
 create mode 100644 src/modules/include/pwd.h
 create mode 100644 src/modules/lib/posix/grp.c
 create mode 100644 src/modules/lib/posix/pwd.c

diff --git a/src/modules/include/grp.h b/src/modules/include/grp.h
new file mode 100644
index 0000000..c0af924
--- /dev/null
+++ b/src/modules/include/grp.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2009 The tyndur Project. All rights reserved.
+ *
+ * This code is derived from software contributed to the tyndur Project
+ * by Antoine Kaufmann.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the tyndur Project
+ *     and its contributors.
+ * 4. Neither the name of the tyndur Project nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef _GRP_H_
+#define _GRP_H_
+
+#include <sys/types.h>
+#include <lost/config.h>
+
+/** Repraesentiert einen Eintrag in der Gruppendatenbank */
+struct group {
+    /** Gruppenname */
+    char*   gr_name;
+    /** Gruppen-ID */
+    gid_t   gr_gid;
+    /** Zeiger auf ein Nullterminiertes Array mit den Mitgliedern */
+    char**  gr_mem;
+};
+
+
+#ifndef CONFIG_LIBC_NO_STUBS
+
+/**
+ * Gruppendatebank-Eintrag anhand des Namens holen
+ *
+ * @param name Benutzername
+ *
+ * @return Pointer auf internen Speicher, der bei weiteren Aufrufen
+ *         ueberschrieben wird.
+ */
+struct group* getgrnam(const char* name);
+
+/**
+ * Gruppendatebank-Eintrag ahnand der GID holen
+ *
+ * @return Pointer auf internen Speicher, der bei weiteren Aufrufen
+ *         ueberschrieben wird.
+ */
+struct group* getgrgid(gid_t gid);
+
+#endif /* ndef CONFIG_LIBC_NO_STUBS */
+
+#endif /* ndef _GRP_H */
+
diff --git a/src/modules/include/pwd.h b/src/modules/include/pwd.h
new file mode 100644
index 0000000..3200de6
--- /dev/null
+++ b/src/modules/include/pwd.h
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2009 The tyndur Project. All rights reserved.
+ *
+ * This code is derived from software contributed to the tyndur Project
+ * by Antoine Kaufmann.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the tyndur Project
+ *     and its contributors.
+ * 4. Neither the name of the tyndur Project nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef _PWD_H_
+#define _PWD_H_
+
+#include <sys/types.h>
+#include <lost/config.h>
+
+/** Repraesentiert einen Eintrag in der Benutzerdatenbank */
+struct passwd {
+    /** Benutzername */
+    char*   pw_name;
+    /** Benutzer-ID */
+    uid_t   pw_uid;
+    /** Gruppen-ID */
+    gid_t   pw_gid;
+    /** Homeverzeichnis */
+    char*   pw_dir;
+    /** Login-Shell */
+    char*   pw_shell;
+};
+
+
+#ifndef CONFIG_LIBC_NO_STUBS
+
+/**
+ * Benutzerdatenbank-Eintrag anhand des Namens holen
+ *
+ * @param name Benutzername
+ *
+ * @return Pointer auf internen Speicher, der bei weiteren Aufrufen
+ *         ueberschrieben wird.
+ */
+struct passwd* getpwnam(const char* name);
+
+/**
+ * Benutzerdatenbank-Eintrag ahnand der UID holen
+ *
+ * @return Pointer auf internen Speicher, der bei weiteren Aufrufen
+ *         ueberschrieben wird.
+ */
+struct passwd* getpwuid(uid_t uid);
+
+#endif /* ndef CONFIG_LIBC_NO_STUBS */
+
+#endif /* ndef _PWD_H */
+
diff --git a/src/modules/lib/posix/grp.c b/src/modules/lib/posix/grp.c
new file mode 100644
index 0000000..7aa6529
--- /dev/null
+++ b/src/modules/lib/posix/grp.c
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2009 The tyndur Project. All rights reserved.
+ *
+ * This code is derived from software contributed to the tyndur Project
+ * by Antoine Kaufmann.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the tyndur Project
+ *     and its contributors.
+ * 4. Neither the name of the tyndur Project nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <string.h>
+#include <grp.h>
+#include <lost/config.h>
+
+
+#ifndef CONFIG_LIBC_NO_STUBS
+
+static struct group grpent;
+static char* grp_member[] = { "root", NULL };
+
+/**
+ * Gruppendatebank-Eintrag anhand des Namens holen
+ *
+ * @param name Benutzername
+ *
+ * @return Pointer auf internen Speicher, der bei weiteren Aufrufen
+ *         ueberschrieben wird.
+ */
+struct group* getgrnam(const char* name)
+{
+    // FIXME: Wir haben nur die Gruppe root
+    if (strcmp(name, "root")) {
+        return NULL;
+    }
+
+    return getgrgid(0);
+}
+
+/**
+ * Gruppendatebank-Eintrag ahnand der GID holen
+ *
+ * @return Pointer auf internen Speicher, der bei weiteren Aufrufen
+ *         ueberschrieben wird.
+ */
+struct group* getgrgid(gid_t gid)
+{
+    // FIXME: Wir haben nur die Gruppe root
+    if (gid != 0) {
+        return NULL;
+    }
+
+    grpent.gr_name  = "root";
+    grpent.gr_gid   = 0;
+    grpent.gr_mem   = grp_member;
+    return &grpent;
+}
+
+#endif /* ndef CONFIG_LIBC_NO_STUBS */
+
diff --git a/src/modules/lib/posix/pwd.c b/src/modules/lib/posix/pwd.c
new file mode 100644
index 0000000..b5313c5
--- /dev/null
+++ b/src/modules/lib/posix/pwd.c
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2009 The tyndur Project. All rights reserved.
+ *
+ * This code is derived from software contributed to the tyndur Project
+ * by Antoine Kaufmann.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the tyndur Project
+ *     and its contributors.
+ * 4. Neither the name of the tyndur Project nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <string.h>
+#include <pwd.h>
+#include <lost/config.h>
+
+
+#ifndef CONFIG_LIBC_NO_STUBS
+static struct passwd pwdent;
+
+/**
+ * Benutzerdatenbank-Eintrag anhand des Namens holen
+ *
+ * @param name Benutzername
+ *
+ * @return Pointer auf internen Speicher, der bei weiteren Aufrufen
+ *         ueberschrieben wird.
+ */
+struct passwd* getpwnam(const char* name)
+{
+    // FIXME: Wir haben nur den Bentuzer root
+    if (strcmp(name, "root")) {
+        return NULL;
+    }
+
+    return getpwuid(0);
+}
+
+/**
+ * Benutzerdatenbank-Eintrag ahnand der UID holen
+ *
+ * @return Pointer auf internen Speicher, der bei weiteren Aufrufen
+ *         ueberschrieben wird.
+ */
+struct passwd* getpwuid(uid_t uid)
+{
+    // FIXME: Wir haben nur den Bentuzer root
+    if (uid != 0) {
+        return NULL;
+    }
+
+    pwdent.pw_name  = "root";
+    pwdent.pw_uid   = 0;
+    pwdent.pw_gid   = 0;
+    pwdent.pw_dir   = "file:/";
+    pwdent.pw_shell = "file:/apps/sh";
+    return &pwdent;
+}
+
+#endif /* ndef CONFIG_LIBC_NO_STUBS */
+
-- 
1.6.0.6