da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Copyright (c) 1983
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * The Regents of the University of California. All rights reserved.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Redistribution and use in source and binary forms, with or without
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * modification, are permitted provided that the following conditions
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * are met:
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * 1. Redistributions of source code must retain the above copyright
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * notice, this list of conditions and the following disclaimer.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * 2. Redistributions in binary form must reproduce the above copyright
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * notice, this list of conditions and the following disclaimer in the
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * documentation and/or other materials provided with the distribution.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * 3. Neither the name of the University nor the names of its contributors
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * may be used to endorse or promote products derived from this software
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * without specific prior written permission.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * SUCH DAMAGE.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic char sccsid[] = "@(#)rcmd.c 5.17 (Berkeley) 6/27/88";
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif /* LIBC_SCCS and not lint */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern void setnetgrent(const char *);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern void endnetgrent(void);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern int getnetgrent(char **, char **, char **);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic int _checknetgrouphost(const char *, const char *, int);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic int _checknetgroupuser(const char *, const char *);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define extern __EXPORT__
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (s < 0)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return (-1);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (;;) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (bind(s, (struct sockaddr *)&sin, sizeof (sin)) >= 0)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return (s);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return (-1);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return (-1);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern int rcmd(char **ahost, unsigned short rport, const char *locuser, const char *remuser, const char *cmd, int *fd2p)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (hp == 0) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return (-1);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (;;) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (s < 0) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "All ports in use"));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "rcmd: socket"));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinreturn (-1);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin bcopy(hp->h_addr_list[0], (caddr_t)&sin.sin_addr, hp->h_length);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (connect(s, (struct sockaddr *)&sin, sizeof (sin)) >= 0)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "connect to address"),
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "Trying %s...\n"),
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return (-1);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (fd2p == 0) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "write: setting up stderr"));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (s3 < 0) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "accept"));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "socket: protocol failure in circuit setup."));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "socket: protocol failure in circuit setup.\n");
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (c != 0) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (c == '\n')
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return (s);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return (-1);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern int ruserok(const char *rhost, int superuser, const char *ruser, const char *luser)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register char *p;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin while (*sp) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *p++ = *sp++;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *p = '\0';
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin hostf = superuser ? (FILE *)0 : fopen(_PATH_HEQUIV, "r");
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!_validuser(hostf, fhost, luser, ruser, baselen)) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return(0);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return(-1);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return(-1);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return(-1);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return (-1);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin_validuser(FILE *hostf, const char *rhost, const char *luser,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register char *p;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /* We need to get rid of all comments. */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (p) *p = '\0';
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin while (*p != '\n' && *p != ' ' && *p != '\t' && *p != '\0') {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *p++ = '\0';
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin while (*p != '\n' && *p != ' ' && *p != '\t' && *p != '\0')
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *p = '\0';
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /* Adding new authentication -Nilendu */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /* enable all host for + entry */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /* enable all user for + entry */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /* disable all host for - entry */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /* disable all user for - entry */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /* disable host from -hostname entry */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return -1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /* disable host from -@netgroup entry for host */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if ('-' == ahost[0] && '@' == ahost[1] && '\0' != ahost[2]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return -1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /* disable user from -user entry */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return -1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /* disable user from -@netgroup entry for user */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin && user[2] != '\0' && _checknetgroupuser(ruser, &user[2]))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return -1;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /* enable host from +@netgroup entry for host */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if ('+' == ahost[0] && '@' == ahost[1] && '\0' != ahost[2])
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin hostvalid = _checknetgrouphost(rhost, &ahost[2], baselen);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /* enable user from +@netgroup entry for user */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin hostvalid = hostvalid ? 1 : _checkhost(rhost, ahost, baselen);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin uservalid = uservalid ? 1 : !stricmp(ruser,*user ? user : luser);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif /* YP */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return (-1);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin_checkhost(const char *rhost, const char *lhost, int len)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return(0);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return(1);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return(0);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return(0);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return(0);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return(0);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin_checknetgrouphost(const char *rhost, const char *netgr, int baselen)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin while (1 == (status = getnetgrent(&host, &user, &domain))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin ; /* find valid host entry */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin_checknetgroupuser(const char *ruser, const char *netgr)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin while (1 == (status = getnetgrent(&host, &user, &domain))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin ; /* find valid user entry */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif /* YP */