/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* University Copyright- Copyright (c) 1982, 1986, 1988
* The Regents of the University of California
* All Rights Reserved
*
* University Acknowledgment- Portions of this document are derived from
* software developed by the University of California, Berkeley, and its
* contributors.
*/
#include <limits.h>
#include <stdio.h>
#include <ctype.h>
#include <pwd.h>
#include <signal.h>
#include <libintl.h>
#include <netdb.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <grp.h>
#include <alloca.h>
#include <priv_utils.h>
#ifdef SYSV
char *strchr();
#else
char *index();
#endif /* SYSV */
extern int usingypmap();
#ifdef NIS
static char *domain;
#endif
{
int rcmd_ret;
AF_INET);
return (rcmd_ret);
}
{
int rc;
char c;
int lport = 0;
#ifdef SYSV
#else
int oldmask;
#endif /* SYSV */
int selret;
char *addr;
return (-1);
}
} else {
}
if (rc != 0) {
return (-1);
}
#ifdef SYSV
/* ignore SIGPIPE */
/* block SIGURG */
#else
#endif /* SYSV */
for (;;) {
if (s < 0) {
/*
* See if we have any addresses of a different type
* to try.
*/
continue;
"socket: All ports in use\n"));
else
perror("rcmd: socket");
#ifdef SYSV
/* restore original SIGPIPE handler */
(struct sigaction *)0);
/* restore original signal mask */
(sigset_t *)0);
#else
#endif /* SYSV */
return (-1);
}
IN6_INADDR_TO_V4MAPPED(&((struct sockaddr_in *)
addrlen = sizeof (struct sockaddr_in6);
}
break;
(void) close(s);
if (errno == EADDRINUSE) {
lport = 0;
continue;
}
timo *= 2;
continue;
}
addr = (char *)&((struct sockaddr_in6 *)
else
addr = (char *)&((struct sockaddr_in *)
perror(0);
addr = (char *)&((struct sockaddr_in6 *)
else
addr = (char *)&((struct sockaddr_in *)
continue;
}
#ifdef SYSV
/* restore original SIGPIPE handler */
(struct sigaction *)0);
/* restore original signal mask */
#else
#endif /* SYSV */
return (-1);
}
lport = 0;
if (fd2p == 0) {
} else {
if (s2 < 0)
goto bad;
"write: setting up stderr"));
goto bad;
}
/*
* Something's wrong: we should get no
* data on this connection at this point,
* so we assume that the connection has
* gone away.
*/
goto bad;
}
/*
* We assume this is an incoming connect
* request and proceed normally.
*/
&len);
if (s3 < 0) {
perror("accept");
lport = 0;
goto bad;
}
else
break;
}
}
if (selret == -1) {
/*
* This should not happen, and we treat it as
* a fatal error.
*/
goto bad;
}
case AF_INET:
"socket: protocol failure in circuit "
"setup.\n"));
goto bad2;
}
break;
case AF_INET6:
"socket: protocol failure in circuit "
"setup.\n"));
goto bad2;
}
break;
default:
"socket: protocol failure in circuit setup.\n"));
goto bad2;
}
}
if (retval != 1) {
if (retval == 0) {
"Protocol error, %s closed connection\n"),
*ahost);
} else if (retval < 0) {
} else {
"Protocol error, %s sent %d bytes\n"),
}
goto bad2;
}
if (c != 0) {
if (c == '\n')
break;
}
goto bad2;
}
#ifdef SYSV
/* restore original SIGPIPE handler */
/* restore original signal mask */
#else
#endif /* SYSV */
return (s);
bad2:
if (lport)
bad:
(void) close(s);
#ifdef SYSV
/* restore original SIGPIPE handler */
/* restore original signal mask */
#else
#endif /* SYSV */
return (-1);
}
static int
{
int s;
int off = 0;
len = sizeof (struct sockaddr_in);
len = sizeof (struct sockaddr_in6);
} else {
return (-1);
}
if (s < 0)
return (-1);
/*
* Set SO_EXCLBIND to get a "unique" port, which is not bound
* to any other sockets.
*/
(void) close(s);
return (-1);
}
/* Try to bind() to the given port first. */
if (*alport != 0) {
} else {
}
/* To be safe, need to turn off SO_EXCLBIND. */
sizeof (off));
return (s);
}
if (errno != EADDRINUSE) {
(void) close(s);
return (-1);
}
}
/*
* If no port is given or the above bind() does not succeed, set
* TCP_ANONPRIVBIND option to ask the kernel to pick a port in the
* priviledged range for us.
*/
sizeof (on)) < 0) {
(void) close(s);
return (-1);
}
} else {
}
/*
* We need to tell the caller what the port is.
*/
(void) close(s);
return (-1);
}
case AF_INET6:
break;
case AF_INET:
break;
}
/*
* To be safe, always turn off these options when we are done.
*/
sizeof (off));
sizeof (off));
return (s);
}
(void) close(s);
return (-1);
}
int
{
(void) __priv_bracket(PRIV_ON);
(void) __priv_bracket(PRIV_OFF);
return (res);
}
int
{
} else {
return (-1);
}
}
int
{
}
int
{
const char *sp;
char *p;
int ngroups;
p = fhost;
while (*sp) {
if (*sp == '.') {
if (baselen == -1)
*p++ = *sp++;
} else {
}
}
*p = '\0';
/* check /etc/hosts.equiv */
if (!superuser) {
return (0);
}
}
}
/* check ~/.rhosts */
return (-1);
/*
* Read .rhosts as the local user to avoid NFS mapping the root uid
* to something that can't read .rhosts.
*/
return (-1);
return (-1);
}
return (-1);
}
return (0);
}
return (-1);
}
static int
{
char *user;
char *p;
#ifdef NIS
}
#endif /* NIS */
p = ahost;
/*
* We can get a line bigger than our buffer. If so we skip
* the offending line.
*/
;
continue;
}
while (*p != '\n' && *p != ' ' && *p != '\t' && *p != '\0') {
/*
* Both host and user ``names'' can be netgroups,
* and must have their case preserved. Case is
* preserved for user names because we break out
* of this loop when finding a field separator.
* To do so for host names, we must make a copy of
* the host name field.
*/
if (isupper(*p)) {
*p = tolower(*p);
}
p++;
}
if (*p == ' ' || *p == '\t') {
*p++ = '\0';
while (*p == ' ' || *p == '\t')
p++;
user = p;
while (*p != '\n' && *p != ' ' && *p != '\t' &&
*p != '\0')
p++;
} else
user = p;
*p = '\0';
hostmatch = 1;
#ifdef NIS
else
break;
} else {
break;
}
}
#endif /* NIS */
else if (ahost[0] == '-') {
break;
}
else
if (user[0]) {
usermatch = 1;
#ifdef NIS
if (hostmatch &&
break;
}
#endif /* NIS */
else if (user[0] == '-') {
break;
}
else
}
else
return (0);
}
return (-1);
}
static int
{
static char *ldomain;
static char *domainp;
static int nodomain;
char *cp;
if (ldomain == 0)
return (0);
}
if (len == -1)
return (0);
return (1);
return (0);
if (nodomain)
return (0);
if (!domainp) {
/*
* "domainp" points after the first dot in the host name
*/
nodomain = 1;
return (0);
}
nodomain = 1;
return (0);
}
domainp++;
while (*cp) {
cp++;
}
}
}