]> git.saurik.com Git - apple/libinfo.git/blobdiff - util.subproj/rcmd.c
Libinfo-477.40.5.tar.gz
[apple/libinfo.git] / util.subproj / rcmd.c
index 29b256d4489b374692b1e66946b7cdab337aeb6b..464250fcdaa36fedf2e8b129ce89602728a0d07a 100644 (file)
@@ -3,22 +3,21 @@
  *
  * @APPLE_LICENSE_HEADER_START@
  * 
  *
  * @APPLE_LICENSE_HEADER_START@
  * 
- * Copyright (c) 1999-2003 Apple Computer, Inc.  All Rights Reserved.
- * 
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * Portions Copyright (c) 1999 Apple Computer, Inc.  All Rights
+ * Reserved.  This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.1 (the "License").  You may not use this file
+ * except in compliance with the License.  Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
  * 
  * The Original Code and all software distributed under the License are
  * 
  * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT.  Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
  * 
  * @APPLE_LICENSE_HEADER_END@
  */
  * 
  * @APPLE_LICENSE_HEADER_END@
  */
@@ -67,9 +66,7 @@ static char sccsid[] = "@(#)rcmd.c    8.3 (Berkeley) 3/26/94";
 #include <sys/socket.h>
 #include <sys/stat.h>
 
 #include <sys/socket.h>
 #include <sys/stat.h>
 
-#include <netinet/in.h>
 #include <arpa/inet.h>
 #include <arpa/inet.h>
-#include <netinfo/ni_util.h>
 
 #include <signal.h>
 #include <fcntl.h>
 
 #include <signal.h>
 #include <fcntl.h>
@@ -80,12 +77,15 @@ static char sccsid[] = "@(#)rcmd.c  8.3 (Berkeley) 3/26/94";
 #include <stdio.h>
 #include <ctype.h>
 #include <string.h>
 #include <stdio.h>
 #include <ctype.h>
 #include <string.h>
+#include <time.h>
 #ifdef YP
 #include <rpc/rpc.h>
 #include <rpcsvc/yp_prot.h>
 #include <rpcsvc/ypclnt.h>
 #endif
 #ifdef YP
 #include <rpc/rpc.h>
 #include <rpcsvc/yp_prot.h>
 #include <rpcsvc/ypclnt.h>
 #endif
-#include <arpa/nameser8_compat.h>
+
+#include <arpa/nameser_compat.h>
+#include <nameser.h>
 
 /* wrapper for KAME-special getnameinfo() */
 #ifndef NI_WITHSCOPEID
 
 /* wrapper for KAME-special getnameinfo() */
 #ifndef NI_WITHSCOPEID
@@ -235,7 +235,7 @@ rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af)
        } else {
                char num[8];
                int s2 = rresvport_af(&lport, ai->ai_family), s3;
        } else {
                char num[8];
                int s2 = rresvport_af(&lport, ai->ai_family), s3;
-               int len = ai->ai_addrlen;
+               unsigned int len = ai->ai_addrlen;
                int nfds;
 
                if (s2 < 0)
                int nfds;
 
                if (s2 < 0)
@@ -405,6 +405,9 @@ rresvport_af(alport, family)
 int    __check_rhosts_file = 1;
 char   *__rcmd_errstr;
 
 int    __check_rhosts_file = 1;
 char   *__rcmd_errstr;
 
+/*  Guess at the size of a password buffer for getpwnam_r (see lookup.subproj/lu_group.c) */
+#define MAXPWBUF (MAXLOGNAME + 1 + _PASSWORD_LEN + 1 + MAXPATHLEN + 1 + MAXPATHLEN + 1 + 4098)
+
 /*
  * AF independent extension of iruserok.
  *
 /*
  * AF independent extension of iruserok.
  *
@@ -419,13 +422,14 @@ iruserok_sa(ra, rlen, superuser, ruser, luser)
 {
        register char *cp;
        struct stat sbuf;
 {
        register char *cp;
        struct stat sbuf;
-       struct passwd *pwd;
+       struct passwd p, *pwd;
        FILE *hostf;
        uid_t uid;
        FILE *hostf;
        uid_t uid;
-       int first;
+       int first, status;
        char pbuf[MAXPATHLEN];
        const struct sockaddr *raddr;
        struct sockaddr_storage ss;
        char pbuf[MAXPATHLEN];
        const struct sockaddr *raddr;
        struct sockaddr_storage ss;
+       char pwbuf[MAXPWBUF];
 
        /* avoid alignment issue */
        if (rlen > sizeof(ss)) 
 
        /* avoid alignment issue */
        if (rlen > sizeof(ss)) 
@@ -445,8 +449,14 @@ again:
        }
        if (first == 1 && (__check_rhosts_file || superuser)) {
                first = 0;
        }
        if (first == 1 && (__check_rhosts_file || superuser)) {
                first = 0;
-               if ((pwd = getpwnam(luser)) == NULL)
-                       return (-1);
+
+               memset(&p, 0, sizeof(struct passwd));
+               memset(pwbuf, 0, sizeof(pwbuf));
+               pwd = NULL;
+
+               status = getpwnam_r(luser, &p, pwbuf, MAXPWBUF, &pwd);
+               if (status != 0) return -1;
+
                (void)strcpy(pbuf, pwd->pw_dir);
                (void)strcat(pbuf, "/.rhosts");
 
                (void)strcpy(pbuf, pwd->pw_dir);
                (void)strcat(pbuf, "/.rhosts");