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

pam_rhosts_auth.so fails if user .rhosts file NFS mounted



I'm using RedHat 4.0 with a bunch of updates, including pam-0.50-22, in
a networked environment with NIS & NFS used for access to users' home
directories.  (The NIS and NFS server is a SPARC running SunOS 4.1.3, if
that makes any difference.)  For security reasons, users' .rhosts files are
read/write for the owner only.  This unfortunately means that root can't
access these files remotely.

In the source code, specifically in pam_rhosts_auth.c, there was a comment
about this... 

    * Change effective uid while opening .rhosts.  If root and
    * reading an NFS mounted file system, can't read files that
    * are protected read/write owner only.

It's not clear whether this is a warning that the code breaks in that
situation, or whether the following geteuid()/seteuid() calls are an attempt
to fix things, however the code remains broken.  The problem is that simply
opening the file as the file's owner is not enough; if we're root as the NFS
reads are done, those will fail.  We have to run with the EUID set to the
file's owner until the file is closed, in order to avoid NFS errors.

The following patch file fixes the problem.  I've tested it with pam 0.50,
and it seems to work fine.  (The patch should also apply cleanly to versions
up to and including 0.54.)  I don't know if there are any repercussions to
running through the whole __ivaliduser() function with the EUID set to
something other than root, but it seems to be fine.  (The gethostbyname()
function is called indirectly from that code, but that should work fine for
non-root users in any case.)

------------------------------------------------------------------------------
--- Linux-PAM-0.50/modules/pam_rhosts/pam_rhosts_auth.c.bad	Mon Mar 24 10:56:03 1997
+++ Linux-PAM-0.50/modules/pam_rhosts/pam_rhosts_auth.c	Mon Mar 24 11:17:37 1997
@@ -274,15 +274,17 @@
      * Change effective uid while opening .rhosts.  If root and
      * reading an NFS mounted file system, can't read files that
      * are protected read/write owner only.
+     * ... fortunately, a fix is easy... (GED, Mar 24/97)
      */
 
     uid = geteuid();
     (void)seteuid(pwd->pw_uid);
     hostf = fopen(pbuf, "r");
-    (void)seteuid(uid);
 	
-    if (hostf == NULL)
+    if (hostf == NULL) {
+        (void)seteuid(uid);
 	return(1);
+    }
 
     /*
      * If not a regular file, or is owned by someone other than
@@ -306,11 +308,13 @@
     if (cp) {
 	opts->last_error = cp;
 	fclose(hostf);
+        (void)seteuid(uid);
 	return(1);
     }
 
     answer = __ivaliduser (opts, hostf, raddr, luser, ruser);
     (void) fclose(hostf);
+    (void)seteuid(uid);
     return (answer);
 }
 
------------------------------------------------------------------------------

-- 
Gilbert E. Detillieux		E-mail:	<gedetil@cs.umanitoba.ca>
Dept. of Computer Science	Web:	http://www.cs.umanitoba.ca/~gedetil/
University of Manitoba		Phone:	(204)474-8161
Winnipeg, MB, CANADA  R3T 2N2	Fax:	(204)269-9178
    "The earth is like a tiny grain of sand, only much, much heavier."



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