bug-hurd
[Top][All Lists]
Advanced

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

[PATCH 01/23] trans: fix the receiver lookup in password


From: Justus Winter
Subject: [PATCH 01/23] trans: fix the receiver lookup in password
Date: Fri, 29 Nov 2013 01:03:29 +0100

Use translation functions instead of doing the lookup manually.

* trans/Makefile (password-MIGSFLAGS): Add mutators.
* trans/password.c (S_password_check_user): Update accordingly.
(S_password_check_group): Likewise.
---
 trans/Makefile   |    6 +++++-
 trans/password.c |   30 ++++++++++++++++++------------
 2 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/trans/Makefile b/trans/Makefile
index 291df2f..c0386d0 100644
--- a/trans/Makefile
+++ b/trans/Makefile
@@ -1,6 +1,6 @@
 #
 #   Copyright (C) 1994, 1995, 1996, 1997, 1999, 2000, 2001, 2002, 2006, 2007,
-#   2008 Free Software Foundation, Inc.
+#   2008, 2013 Free Software Foundation, Inc.
 #
 #   This program is free software; you can redistribute it and/or
 #   modify it under the terms of the GNU General Public License as
@@ -32,6 +32,10 @@ OBJS = $(SRCS:.c=.o) fsysServer.o ifsockServer.o 
passwordServer.o \
 HURDLIBS = ports netfs trivfs iohelp fshelp pipe ihash shouldbeinlibc
 LDLIBS += -lpthread
 password-LDLIBS = $(LIBCRYPT)
+password-MIGSFLAGS=\
+    "-DIO_INTRAN=trivfs_protid_t trivfs_begin_using_protid (io_t)" \
+    "-DIO_DESTRUCTOR=trivfs_end_using_protid (trivfs_protid_t)" \
+    "-DPASSWORD_IMPORTS=import <hurd/trivfs.h>;"
 
 include ../Makeconf
 
diff --git a/trans/password.c b/trans/password.c
index 6f15a9e..344b78b 100644
--- a/trans/password.c
+++ b/trans/password.c
@@ -1,5 +1,5 @@
 /* Hurd standard password server.
-   Copyright (C) 1999 Free Software Foundation
+   Copyright (C) 1999, 2013 Free Software Foundation
    Written by Mark Kettenis.
 
    The GNU Hurd is free software; you can redistribute it and/or
@@ -135,10 +135,9 @@ trivfs_goaway (struct trivfs_control *fsys, int flags)
 
 /* Implement password_check_user as described in <hurd/password.defs>.  */
 kern_return_t
-S_password_check_user (io_t server, uid_t user, char *pw,
+S_password_check_user (struct trivfs_protid *cred, uid_t user, char *pw,
                       mach_port_t *port, mach_msg_type_name_t *port_type)
 {
-  struct trivfs_protid *cred;
   struct ugids ugids = UGIDS_INIT;
   auth_t auth;
   error_t err;
@@ -150,10 +149,16 @@ S_password_check_user (io_t server, uid_t user, char *pw,
       return strdup (pw);
     }
 
-  cred = ports_lookup_port (port_bucket, server, trivfs_protid_portclasses[0]);
   if (! cred)
     return EOPNOTSUPP;
 
+  if (cred->pi.bucket != port_bucket ||
+      cred->pi.class != trivfs_protid_portclasses[0])
+    {
+      ports_port_deref (cred);
+      return EOPNOTSUPP;
+    }
+
   /* Verify password.  */
   err = ugids_add_user (&ugids, user, 1);
   if (!err)
@@ -173,17 +178,14 @@ S_password_check_user (io_t server, uid_t user, char *pw,
     }
 
   ugids_fini (&ugids);
-
-  ports_port_deref (cred);
   return err;
 }
 
 /* Implement password_check_group as described in <hurd/password.defs>.  */
 kern_return_t
-S_password_check_group (io_t server, uid_t group, char *pw,
+S_password_check_group (struct trivfs_protid *cred, uid_t group, char *pw,
                        mach_port_t *port, mach_msg_type_name_t *port_type)
 {
-  struct trivfs_protid *cred;
   struct ugids ugids = UGIDS_INIT;
   auth_t auth;
   error_t err;
@@ -195,10 +197,16 @@ S_password_check_group (io_t server, uid_t group, char 
*pw,
       return strdup (pw);
     }
 
-  cred = ports_lookup_port (port_bucket, server, trivfs_protid_portclasses[0]);
   if (! cred)
     return EOPNOTSUPP;
-  
+
+  if (cred->pi.bucket != port_bucket ||
+      cred->pi.class != trivfs_protid_portclasses[0])
+    {
+      ports_port_deref (cred);
+      return EOPNOTSUPP;
+    }
+
   /* Verify password.  */
   err = ugids_add_gid (&ugids, group, 1);
   if (!err)
@@ -218,7 +226,5 @@ S_password_check_group (io_t server, uid_t group, char *pw,
     }
 
   ugids_fini (&ugids);
-
-  ports_port_deref (cred);
   return err;
 }
-- 
1.7.10.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]