X-Git-Url: https://git.saurik.com/apple/libinfo.git/blobdiff_plain/ccd4a120fd72e1cd2071458320f7a1914ef55421..9e8ccf68ea9492d257074b9d3023cf906c5dfeda:/util.subproj/rcmd.c diff --git a/util.subproj/rcmd.c b/util.subproj/rcmd.c index 29b256d..464250f 100644 --- a/util.subproj/rcmd.c +++ b/util.subproj/rcmd.c @@ -3,22 +3,21 @@ * * @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 - * 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, - * 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@ */ @@ -67,9 +66,7 @@ static char sccsid[] = "@(#)rcmd.c 8.3 (Berkeley) 3/26/94"; #include #include -#include #include -#include #include #include @@ -80,12 +77,15 @@ static char sccsid[] = "@(#)rcmd.c 8.3 (Berkeley) 3/26/94"; #include #include #include +#include #ifdef YP #include #include #include #endif -#include + +#include +#include /* 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; - int len = ai->ai_addrlen; + unsigned int len = ai->ai_addrlen; int nfds; if (s2 < 0) @@ -405,6 +405,9 @@ rresvport_af(alport, family) 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. * @@ -419,13 +422,14 @@ iruserok_sa(ra, rlen, superuser, ruser, luser) { register char *cp; struct stat sbuf; - struct passwd *pwd; + struct passwd p, *pwd; FILE *hostf; uid_t uid; - int first; + int first, status; char pbuf[MAXPATHLEN]; const struct sockaddr *raddr; struct sockaddr_storage ss; + char pwbuf[MAXPWBUF]; /* avoid alignment issue */ if (rlen > sizeof(ss)) @@ -445,8 +449,14 @@ again: } 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");