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

[Minios-devel] [UNIKRAFT PATCH 1/1] lib/ukunistd: Imlement getpwnam, getpwuid and getpwent


  • To: "minios-devel@xxxxxxxxxxxxx" <minios-devel@xxxxxxxxxxxxx>
  • From: Vlad-Andrei BĂDOIU (78692) <vlad_andrei.badoiu@xxxxxxxxxxxxxxx>
  • Date: Tue, 27 Aug 2019 16:36:33 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=stud.acs.upb.ro; dmarc=pass action=none header.from=stud.acs.upb.ro; dkim=pass header.d=stud.acs.upb.ro; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=IOwxU3BO7wUbpKwne4zHTOVVXloE91QZhY87PhwKrbk=; b=a/f2P5bHF3iuWX/YE53ocn1iB3pY1Y8u10YOOZijKtvbyEi5K1e5TfFuBYb+MnYWB4Uh6OMBDRN+7KZbT3A6PAgdDtFIHjHPwwOA4PJkN7f8tpUbQ14Cxz78bKA42C6DvUT9TBcrPZ+Ct6vSDtEd1ZvjCVU7C59vrhOyeKcdJmHKm5abRGj0qFz/jbC30rAHHzK+suWXdvHs4ZaJ0L3fb4bkhRoLcmDUZUq0BvTGcaKmL519BQNtHuLgjRzYm1JJwkHMmoXUCsHV18TqDUF3y1HkuYm68iB3Q5vcTxNKmlHdRNLTclgS0AuGr9ebFs7dKYmURkb8gQyfVF45B3ZFOQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XCzKUOa40iIo3Xb+3oq4A6cMa54dLQlHSs7tAaHLg9jETxSG2BQ80raXhnzJWaZ0tTf4fb/XYZT/SJnp1evHb55FE5U27nfC+OLQlGOEK4TAq10R5VaGAa+FUv4d56zDkoEumNeszkff8CFNzWF1OWpk7+xcuAdQ+xlNfU2XGyp9y/Wu1EBPFmRo5H8DxPV8+K1fKFnxkcHzaf4kc6UuqMrfGv80NQFmt9lllXPbASV+2LxVRYp1uAvjTyugDbein81UX/VSEWewt2/hW4xN4lj4Ow2fQ6Cmlo72COsm/CX5CjrAEmuaZ+xnfz7E6A9Hel9nm7rcRRYJWr4uGmnu+w==
  • Authentication-results: spf=none (sender IP is ) smtp.mailfrom=vlad_andrei.badoiu@xxxxxxxxxxxxxxx;
  • Cc: Vlad-Andrei BĂDOIU (78692) <vlad_andrei.badoiu@xxxxxxxxxxxxxxx>, "costin.lupu@xxxxxxxxx" <costin.lupu@xxxxxxxxx>
  • Delivery-date: Tue, 27 Aug 2019 16:36:39 +0000
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>
  • Thread-index: AQHVXPWVQCIFu20Wqki1uk74AF/6zA==
  • Thread-topic: [UNIKRAFT PATCH 1/1] lib/ukunistd: Imlement getpwnam, getpwuid and getpwent

Our implementation uses a list for the password database. Since we have no shell
available on Unikraft, the pw_shell field is set to NULL.

Signed-off-by: Vlad-Andrei Badoiu <vlad_andrei.badoiu@xxxxxxxxxxxxxxx>
---
 lib/ukunistd/user.c | 77 ++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 66 insertions(+), 11 deletions(-)

diff --git a/lib/ukunistd/user.c b/lib/ukunistd/user.c
index 8fe991e4..9d39aed8 100644
--- a/lib/ukunistd/user.c
+++ b/lib/ukunistd/user.c
@@ -35,8 +35,39 @@
 
 #include <unistd.h>
 #include <pwd.h>
+#include <string.h>
 #include <sys/types.h>
 #include <uk/essentials.h>
+#include <uk/list.h>
+
+static struct passwd_entry {
+       struct passwd *passwd;
+
+       UK_SLIST_ENTRY(struct passwd_entry) entries;
+} *iter;
+
+UK_SLIST_HEAD(uk_entry_list, struct passwd_entry);
+
+static struct uk_entry_list passwds;
+
+void __constructor init_ukunistd()
+{
+       static struct passwd_entry p1;
+       static struct passwd passwd = {
+               .pw_name = "root",
+               .pw_passwd = "password",
+               .pw_uid = 0,
+               .pw_gid = 0,
+               .pw_gecos = "root",
+               .pw_dir = "/",
+               .pw_shell = NULL,
+       };
+
+       p1.passwd = &passwd;
+
+       UK_SLIST_INIT(&passwds);
+       UK_SLIST_INSERT_HEAD(&passwds, &p1, entries);
+}
 
 uid_t getuid(void)
 {
@@ -78,14 +109,37 @@ char *getlogin(void)
        return 0;
 }
 
-struct passwd *getpwnam(const char *name __unused)
+void setpwent(void)
+{
+       iter = UK_SLIST_FIRST(&passwds);
+}
+
+void endpwent(void)
+{
+}
+
+struct passwd *getpwnam(const char *name)
 {
-       return NULL;
+       struct passwd *pwd;
+
+       setpwent();
+       while ((pwd = getpwent()) && strcmp(pwd->pw_name, name))
+               ;
+       endpwent();
+
+       return pwd;
 }
 
-struct passwd *getpwuid(uid_t uid __unused)
+struct passwd *getpwuid(uid_t uid)
 {
-       return NULL;
+       struct passwd *pwd;
+
+       setpwent();
+       while ((pwd = getpwent()) && pwd->pw_uid != uid)
+               ;
+       endpwent();
+
+       return pwd;
 }
 
 int getpwnam_r(const char *name __unused, struct passwd *pwd __unused,
@@ -104,15 +158,16 @@ int getpwuid_r(uid_t uid __unused, struct passwd *pwd 
__unused,
 
 struct passwd *getpwent(void)
 {
-       return NULL;
-}
+       struct passwd *pwd;
+       
+       if (iter == NULL)
+               return NULL;
 
-void setpwent(void)
-{
-}
+       pwd = iter->passwd;
 
-void endpwent(void)
-{
+       iter = UK_SLIST_NEXT(iter, entries);
+
+       return pwd;
 }
 
 gid_t getgid(void)
-- 
2.20.1


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.