check_bound.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 2002 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 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.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Checks to see whether the program is still bound to the
* claimed address and returns the univeral merged address
*
*/
#include <stdio.h>
#include <netconfig.h>
#include <netdir.h>
#include <stdlib.h>
#include "rpcbind.h"
#include <string.h>
/* the following just to get my address */
#include <errno.h>
struct fdlist {
int fd;
int check_binding;
};
static char *nullstring = "";
/*
* Returns 1 if the given address is bound for the given addr & transport
* For all error cases, we assume that the address is bound
* Returns 0 for success.
*/
static bool_t
char *uaddr; /* the universal address */
{
int fd;
int ans;
return (TRUE);
if (!na)
return (TRUE); /* punt, should never happen */
return (TRUE);
}
return (TRUE);
}
/* Bad fd. Purge this fd */
}
}
/*
* Keep open one more file descriptor for this transport, which
* will be used to determine whether the given service is up
* or not by trying to bind to the registered address.
* We are ignoring errors here. It trashes taddr and baddr;
* but that perhaps should not matter.
*
* We check for the following conditions:
* 1. Is it possible for t_bind to fail in the case where
* we bind to an already bound address and have any
* other error number besides TNOADDR.
* 2. If a address is specified in bind addr, can I bind to
* the same address.
* 3. If NULL is specified in bind addr, can I bind to the
* address to which the fd finally got bound.
*/
int
{
int fd;
return (-1);
return (-1);
}
} else {
}
/*
* Note that we haven't dequeued this entry nor have we freed
* the netconfig structure.
*/
if (debugging) {
"%s: add_bndlist cannot open connection: %s",
}
return (-1);
}
/* Set the qlen only for cots transports */
case T_COTS:
case T_COTS_ORD:
break;
case T_CLTS:
break;
default:
goto error;
}
return (0); /* All is fine */
}
/* Perhaps condition #1 */
if (debugging) {
}
goto not_bound;
}
/* Condition #2 */
#ifdef BIND_DEBUG
#endif
goto not_bound;
}
/* Condition #3 */
/* Set the qlen only for cots transports */
case T_COTS:
case T_COTS_ORD:
break;
case T_CLTS:
break;
default:
goto error;
}
if (debugging) {
}
goto error;
}
/* Now fdl->fd is bound to a transport chosen address */
if (debugging) {
"%s: add_bndlist cannot open connection: %s",
}
goto error;
}
/*
* This transport is schizo. Previously it handled a
* request to bind to an already bound transport by
* returning a different bind address, and now it's
* returning a TNOADDR for essentially the same
* request. The spec may allow this behavior, so
* we'll just assume we can't do bind checking with
* this transport.
*/
goto not_bound;
}
if (debugging) {
}
goto error;
}
case T_COTS:
case T_COTS_ORD:
#ifdef BIND_DEBUG
#endif
goto not_bound;
}
break;
case T_CLTS:
#ifdef BIND_DEBUG
#endif
goto not_bound;
default:
goto error;
}
}
return (0);
return (1);
return (-1);
}
char *netid;
char *uaddr;
{
break;
return (TRUE);
}
/* Return pointer to port string in the universal address */
while (*--PORT != '.'); }
/*
* Returns NULL if there was some system error.
* Returns "" if the address was not bound, i.e the server crashed.
* Returns the merged address otherwise.
*/
char *
char *netid;
char *uaddr;
char *saddr;
{
struct nd_mergearg ma;
int stat;
break;
return (NULL);
/* that server died */
return (nullstring);
/*
* If saddr is not NULL, the remote client may have included the
* address by which it contacted us. Use that for the "client" uaddr,
* otherwise use the info from the SVCXPRT.
*/
} else {
/* retrieve the client's address */
return (NULL);
}
}
#ifdef ND_DEBUG
} else {
}
#endif
/* Not an INET adaress? */
#ifdef ND_DEBUG
" ND_MERGEADDR interface\n");
#endif
}
/* Inet address, but no xp_ltaddr */
#ifdef ND_DEBUG
" ND_MERGEADDR interface\n");
#endif
} else {
/*
* (xprt)->xp_ltaddr contains portmap's port address.
* Overwrite this with actual application's port address
* before returning to the caller.
*/
*s_uport = '\0';
/* Get the port info from uaddr */
return (NULL);
}
/* Copy IP address into the Universal address holder */
/* Append port info to the Universal address holder */
stat = 0;
#ifdef ND_DEBUG
" used for contacting us\n");
#endif
}
}
if (stat) {
return (NULL);
}
#ifdef ND_DEBUG
#endif
}
/*
* Returns a netconf structure from its internal list. This
* structure should not be freed.
*/
struct netconfig *
char *netid;
{
break;
return (NULL);
}
#ifdef BIND_DEBUG
int a;
char *msg;
caddr_t b, c, d;
{
char buf[1024];
}
#endif