glibc/sunrpc/pmap_rmt.c
Ulrich Drepper c4563d2d66 Update.
1999-04-28  Ulrich Drepper  <drepper@cygnus.com>

	* argp/argp-ba.c (argp_program_bug_address): Don't initialize with 0.
	* argp/argp-parse.c (_argp_hang): Likewise.
	* argp/argp-pv.c (argp_program_version): Likewise.
	* argp/argp-pvh.c (argp_program_version_hook): Likewise.
	* inet/ether_hton.c (ether_hton, startp): Likewise.
	* inet/ether_ntoh.c (ether_ntoh, startp): Likewise.
	* inet/getnetgrent_r.c (setup, startp): Likewise.
	* intl/loadmsgcat.c (_nl_msg_cat_cntr): Likewise.
	* intl/localealias.c (string_space, string_space_act, string_space_max,
	nmap, maxmap): Likewise.
	* libio/iopopen.c (proc_file_chain): Likewise.
	* libio/oldiopopen.c (old_proc_file_chain): Likewise.
	* locale/lc-collate.c (__collate_table, __collate_extra,
	__collate_element_hash, __collate_element_strings,
	__collate_element_values): Likewise.
	* malloc/mcheck.c (mcheck_used): Likewise.
	* malloc/mtrace.c (added_atexit_handler): Likewise.
	* malloc/set-freeres.c (already_called): Likewise.
	* misc/getpass.c (getpass) [buf, bufsize]: Likewise.
	* misc/syslog.c (LogStat, LogTag): Likewise.
	* nss/XXX-lookup.c (DATABASE_NAME_SYMBOL): Likewise.
	* nss/getXXbyYY_r.c (startp): Likewise.
	* posix/getopt.c (optarg, __getopt_initialized): Likewise.
	* posix/regex.c (init_syntax_once) [done]: Likewise.
	(debug): Likewise.
	* string/strfry.c (init): Likewise.
	* sunrpc/svc_run.c (svc_top): Likewise.
	* posix/euidaccess.c (have_ids): Likewise.
	* sysdeps/unix/sysv/linux/poll.c (must_emulate): Likewise.
	* sysdeps/unix/sysv/linux/ttyname.c (__ttyname, namelen): Likewise.
	* time/getdate.c (getdate_err): Likewise.
	* time/tzfile.c (transitions, type_idxs, types, zone_names, leaps):
	Likewise.
	* time/tzset.c (old_tz, is_initialized): Likewise.

	* inet/getnameinfo.c (nrl_domainname): Rewrite to allow initialization
	of static data with zero.
	* signal/allocrtsig.c (init): Likewise.

	* string/Makefile (routines): Add strchrnul.
	* string/Versions [GLIBC_2.1.1]: Add strchrnul.
	* string/string.c: Add strchrnul prototype.
	* include/string.h: Add __strchrnul prototype.
	* sysdeps/generic/strchrnul.c: New file.
	* sysdeps/i386/strchrnul.S: New file.
	* sysdeps/i386/bits/string.c: Add strchrnul optimization.
	* sysdeps/i386/i486/bits/string.c: Likewise.
	* argp/argp-help.c (argp_args_usage): Use __strchrnul.
	* inet/ether_line.c (ether_line): Likewise.
	* nscd/nscd_conf.c (nscd_parse_file): Likewise.
	* nss/nsswitch.c (nss_parse_file): Likewise.
	* posix/execvp.c (execvp): Likewise.
	* posix/fnmatch.c (internal_fnmatch): Likewise.
	* resolv/res_hconf.c (_res_hconv_init): Likewise.
	* resolv/res_init.c (res_init): Likewise.
	* stdlib/fmtmsg.c (init): Likewise.
	* stdlib/getsubopt.c (getsubopt): Likewise.

	* catgets/catgets.c (catopen): Only allocate one memory block.
	(catclose): Only one free call necessary.

	* catgets/open_catalog.c (__open_catalog): Simplify handling of
	file descriptor.

	* ctype/ctype-extn.c: Make __toascii_l and __isascii_l alias instead
	of real functions.  Simplify _tolower and _toupper.

	* grp/initgroups.c (compat_call): Remove unnecessary use of pointer
	variable.

	* iconv/gconv.h (struct gconv_info): Change data element from pointer
	to array of size 0.
	* iconv/gconv_open.c (__gconv_open): Allocate structures accordingly.
	* iconv/gconv_close.c (__gconv_close): Don't free data.

	* iconv/gconv_conf.c (add_alias): Avoid searching in tree twice to
	insert new alias.

	* iconv/gconv_db.c (add_derivation): More efficient copying.  Check
	for error while inserting in tree.

	* include/time.h: Pretty print.

	* inet/ruserpass.c: Rewrite use of toktab to avoid string pointers
	in table and lots of relocations.
	* posix/regex.c (regerror): Rewrite use of re_error_msgid to avoid
	string pointers in table and lots of relocations.

	* intl/finddomain.c: Remove definition of strchr macro.

	* io/ftw.c (nftw_arr, ftw_arr): Make const.

	* locale/loadlocale.c (_nl_load_locale): Optimize string copying.

	* locale/localeinfo.h (_nl_category_names): Change into an array with
	fixed width char string elements.
	* locale/setlocale.c (_nl_category_names): Likewise.
	(_nl_current): Make global.
	* locale/nl_langinfo.c (nldata): Removed.  Use _nl_current now.

	* malloc/Makefile (distribute): Add stackinfo.h.
	* sysdeps/generic/stackinfo.h: New file.
	* sysdeps/i386/stackinfo.h: New file.
	* posix/execl.c: Use stackinfo.h in optimizing alloca use.
	* posix/execle.c: Likewise.
	* posix/execlp.c: Likewise.

	* nis/nis_table.c (__create_ib_request): Always use realloc.

	* posix/execvp.c (execute): Rename to script_execute and keep only
	code to execute using shell.
	(execvp): Call execv directly and only fall back on script_execute.

	* resolv/inet_net_pton.c (inet_net_pton_ipv4): Remove digits define
	and always use xdigits instead.

	* resolv/res_init.c (res_init): Use rawmemchr instead of strchr
	where appropriate.

	* stdlib/fpioconst.h (__tens): New declaration.
	(struct mp_power): Remove array, add arrayoff element.
	* stdlib/fpioconst.c: Replace definitions of _ten_p* arrays by one
	__tens array and add in _fpioconst_pow10 offsets into __tens.
	* stdio-common/printf_fp.c: Rewrite to use new __tens array.
	* stdlib/strtod.c: Likewise.

	* stdlib/a64l.c (a64l_table): Avoid unnecessary elements.

	* stdlib/exit.c: Rewrite to use __exit_funcs being as sign for end
	of the list.
	* stdlib/atexit.c (__exit_funcs): Don't initialize.

	* stdlib/fmtmsg.c (keywords): Make name element fixed width array.

	* sunrpc/clnt_perr.c: Rewrite clnt_sperrno and auth_errmsg to use
	a single and an array with offsets.

	* sunrpc/des_soft.c (partab): Make it const.

	* sunrpc/key_call.c (trytimeout, tottimeout): Make const.
	(__key_encryptsession_pk_LOCAL): Don't initialize with 0.
	(__key_decryptsession_pk_LOCAL): Likewise.
	(__key_gendes_LOCAL): Likewise.
	(MESSENGER): Mark const.
	(key_call_private_main): Don't initialize with 0.
	(use_keyenvoy): Don't initialize with 0.
	(key_call): Rewrite to reverse logic of use_doors variable.

	* sunrpc/netname.c (OPSYS): Define as array, not pointer.
	(startp): Don't initialize with zero.

	* sunrpc/openchild.c (_openchild): Make first argument const.

	* sunrpc/pmap_rmt.c (timeout): Mark const.
	* sunrpc/xcrypt.c (hex): Likewise.

	* sysdeps/unix/sysv/linux/getcwd.c: Rewrite to allow omitting
	initialization of global variables.
	* sysdeps/unix/sysv/linux/getpt.c: Likewise.
	* sysdeps/unix/sysv/linux/if_index.c: Likewise.
	* termios/tcgetsid.c: Likewise.

	* sysdeps/unix/sysv/linux/i386/dl-procinfo.h (x86_cap_flags): Change
	fxsr to osfxsr.

	* time/tzfile.c (__tzfile_read): Rewrite to allocate only one memory
	block.  Add function to free memory if wanted.
	* time/tzset.c (tzset_internal): Pass extra argument to __tzfile_read.

	* wcsmbs/wcsmbsload.c (to_wc, to_mb): Correct initializers.

	* wcsmbs/wmemset.c: Little code optimization.
1999-04-28 23:13:52 +00:00

411 lines
11 KiB
C

/* @(#)pmap_rmt.c 2.2 88/08/01 4.0 RPCSRC */
/*
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
* unrestricted use provided that this legend is included on all tape
* media and as a part of the software program in whole or part. Users
* may copy or modify Sun RPC without charge, but are not authorized
* to license or distribute it to anyone else except as part of a product or
* program developed by the user.
*
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
*
* Sun RPC is provided with no support and without any obligation on the
* part of Sun Microsystems, Inc. to assist in its use, correction,
* modification or enhancement.
*
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
* OR ANY PART THEREOF.
*
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Sun has been advised of the possibility of such damages.
*
* Sun Microsystems, Inc.
* 2550 Garcia Avenue
* Mountain View, California 94043
*/
#if !defined(lint) && defined(SCCSIDS)
static char sccsid[] = "@(#)pmap_rmt.c 1.21 87/08/27 Copyr 1984 Sun Micro";
#endif
/*
* pmap_rmt.c
* Client interface to pmap rpc service.
* remote call and broadcast service
*
* Copyright (C) 1984, Sun Microsystems, Inc.
*/
#include <unistd.h>
#include <string.h>
#include <rpc/rpc.h>
#include <rpc/pmap_prot.h>
#include <rpc/pmap_clnt.h>
#include <rpc/pmap_rmt.h>
#include <sys/poll.h>
#include <sys/socket.h>
#include <stdio.h>
#include <errno.h>
#undef _POSIX_SOURCE /* Ultrix <sys/param.h> needs --roland@gnu */
#include <sys/param.h> /* Ultrix needs before net/if --roland@gnu */
#include <net/if.h>
#include <sys/ioctl.h>
#include <arpa/inet.h>
#define MAX_BROADCAST_SIZE 1400
extern u_long _create_xid (void);
static const struct timeval timeout = {3, 0};
/*
* pmapper remote-call-service interface.
* This routine is used to call the pmapper remote call service
* which will look up a service program in the port maps, and then
* remotely call that routine with the given parameters. This allows
* programs to do a lookup and call in one step.
*/
enum clnt_stat
pmap_rmtcall (addr, prog, vers, proc, xdrargs, argsp, xdrres, resp, tout, port_ptr)
struct sockaddr_in *addr;
u_long prog, vers, proc;
xdrproc_t xdrargs, xdrres;
caddr_t argsp, resp;
struct timeval tout;
u_long *port_ptr;
{
int socket = -1;
CLIENT *client;
struct rmtcallargs a;
struct rmtcallres r;
enum clnt_stat stat;
addr->sin_port = htons (PMAPPORT);
client = clntudp_create (addr, PMAPPROG, PMAPVERS, timeout, &socket);
if (client != (CLIENT *) NULL)
{
a.prog = prog;
a.vers = vers;
a.proc = proc;
a.args_ptr = argsp;
a.xdr_args = xdrargs;
r.port_ptr = port_ptr;
r.results_ptr = resp;
r.xdr_results = xdrres;
stat = CLNT_CALL (client, PMAPPROC_CALLIT, (xdrproc_t)xdr_rmtcall_args,
(caddr_t)&a, (xdrproc_t)xdr_rmtcallres,
(caddr_t)&r, tout);
CLNT_DESTROY (client);
}
else
{
stat = RPC_FAILED;
}
/* (void)__close(socket); CLNT_DESTROY already closed it */
addr->sin_port = 0;
return stat;
}
/*
* XDR remote call arguments
* written for XDR_ENCODE direction only
*/
bool_t
xdr_rmtcall_args (XDR *xdrs, struct rmtcallargs *cap)
{
u_int lenposition, argposition, position;
if (xdr_u_long (xdrs, &(cap->prog)) &&
xdr_u_long (xdrs, &(cap->vers)) &&
xdr_u_long (xdrs, &(cap->proc)))
{
lenposition = XDR_GETPOS (xdrs);
if (!xdr_u_long (xdrs, &(cap->arglen)))
return FALSE;
argposition = XDR_GETPOS (xdrs);
if (!(*(cap->xdr_args)) (xdrs, cap->args_ptr))
return FALSE;
position = XDR_GETPOS (xdrs);
cap->arglen = (u_long) position - (u_long) argposition;
XDR_SETPOS (xdrs, lenposition);
if (!xdr_u_long (xdrs, &(cap->arglen)))
return FALSE;
XDR_SETPOS (xdrs, position);
return TRUE;
}
return FALSE;
}
/*
* XDR remote call results
* written for XDR_DECODE direction only
*/
bool_t
xdr_rmtcallres (xdrs, crp)
XDR *xdrs;
struct rmtcallres *crp;
{
caddr_t port_ptr;
port_ptr = (caddr_t) crp->port_ptr;
if (xdr_reference (xdrs, &port_ptr, sizeof (u_long), (xdrproc_t) xdr_u_long)
&& xdr_u_long (xdrs, &crp->resultslen))
{
crp->port_ptr = (u_long *) port_ptr;
return (*(crp->xdr_results)) (xdrs, crp->results_ptr);
}
return FALSE;
}
/*
* The following is kludged-up support for simple rpc broadcasts.
* Someday a large, complicated system will replace these trivial
* routines which only support udp/ip .
*/
static int
internal_function
getbroadcastnets (struct in_addr *addrs, int sock, char *buf)
/* int sock: any valid socket will do */
/* char *buf: why allocate more when we can use existing... */
{
struct ifconf ifc;
struct ifreq ifreq, *ifr;
struct sockaddr_in *sin;
int n, i;
ifc.ifc_len = UDPMSGSIZE;
ifc.ifc_buf = buf;
if (__ioctl (sock, SIOCGIFCONF, (char *) &ifc) < 0)
{
perror (_("broadcast: ioctl (get interface configuration)"));
return (0);
}
ifr = ifc.ifc_req;
for (i = 0, n = ifc.ifc_len / sizeof (struct ifreq); n > 0; n--, ifr++)
{
ifreq = *ifr;
if (__ioctl (sock, SIOCGIFFLAGS, (char *) &ifreq) < 0)
{
perror (_("broadcast: ioctl (get interface flags)"));
continue;
}
if ((ifreq.ifr_flags & IFF_BROADCAST) &&
(ifreq.ifr_flags & IFF_UP) &&
ifr->ifr_addr.sa_family == AF_INET)
{
sin = (struct sockaddr_in *) &ifr->ifr_addr;
#ifdef SIOCGIFBRDADDR /* 4.3BSD */
if (__ioctl (sock, SIOCGIFBRDADDR, (char *) &ifreq) < 0)
{
addrs[i++] = inet_makeaddr (inet_netof
/* Changed to pass struct instead of s_addr member
by roland@gnu. */
(sin->sin_addr), INADDR_ANY);
}
else
{
addrs[i++] = ((struct sockaddr_in *)
&ifreq.ifr_addr)->sin_addr;
}
#else /* 4.2 BSD */
addrs[i++] = inet_makeaddr (inet_netof
(sin->sin_addr.s_addr), INADDR_ANY);
#endif
}
}
return i;
}
enum clnt_stat
clnt_broadcast (prog, vers, proc, xargs, argsp, xresults, resultsp, eachresult)
u_long prog; /* program number */
u_long vers; /* version number */
u_long proc; /* procedure number */
xdrproc_t xargs; /* xdr routine for args */
caddr_t argsp; /* pointer to args */
xdrproc_t xresults; /* xdr routine for results */
caddr_t resultsp; /* pointer to results */
resultproc_t eachresult; /* call with each result obtained */
{
enum clnt_stat stat = RPC_FAILED;
AUTH *unix_auth = authunix_create_default ();
XDR xdr_stream;
XDR *xdrs = &xdr_stream;
struct timeval t;
int outlen, inlen, nets;
socklen_t fromlen;
int sock;
int on = 1;
struct pollfd fd;
int milliseconds;
int i;
bool_t done = FALSE;
u_long xid;
u_long port;
struct in_addr addrs[20];
struct sockaddr_in baddr, raddr; /* broadcast and response addresses */
struct rmtcallargs a;
struct rmtcallres r;
struct rpc_msg msg;
char outbuf[MAX_BROADCAST_SIZE], inbuf[UDPMSGSIZE];
/*
* initialization: create a socket, a broadcast address, and
* preserialize the arguments into a send buffer.
*/
if ((sock = __socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
{
perror (_("Cannot create socket for broadcast rpc"));
stat = RPC_CANTSEND;
goto done_broad;
}
#ifdef SO_BROADCAST
if (setsockopt (sock, SOL_SOCKET, SO_BROADCAST, &on, sizeof (on)) < 0)
{
perror (_("Cannot set socket option SO_BROADCAST"));
stat = RPC_CANTSEND;
goto done_broad;
}
#endif /* def SO_BROADCAST */
fd.fd = sock;
fd.events = POLLIN;
nets = getbroadcastnets (addrs, sock, inbuf);
__bzero ((char *) &baddr, sizeof (baddr));
baddr.sin_family = AF_INET;
baddr.sin_port = htons (PMAPPORT);
baddr.sin_addr.s_addr = htonl (INADDR_ANY);
/* baddr.sin_addr.S_un.S_addr = htonl(INADDR_ANY); */
msg.rm_xid = xid = _create_xid ();
t.tv_usec = 0;
msg.rm_direction = CALL;
msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
msg.rm_call.cb_prog = PMAPPROG;
msg.rm_call.cb_vers = PMAPVERS;
msg.rm_call.cb_proc = PMAPPROC_CALLIT;
msg.rm_call.cb_cred = unix_auth->ah_cred;
msg.rm_call.cb_verf = unix_auth->ah_verf;
a.prog = prog;
a.vers = vers;
a.proc = proc;
a.xdr_args = xargs;
a.args_ptr = argsp;
r.port_ptr = &port;
r.xdr_results = xresults;
r.results_ptr = resultsp;
xdrmem_create (xdrs, outbuf, MAX_BROADCAST_SIZE, XDR_ENCODE);
if ((!xdr_callmsg (xdrs, &msg)) || (!xdr_rmtcall_args (xdrs, &a)))
{
stat = RPC_CANTENCODEARGS;
goto done_broad;
}
outlen = (int) xdr_getpos (xdrs);
xdr_destroy (xdrs);
/*
* Basic loop: broadcast a packet and wait a while for response(s).
* The response timeout grows larger per iteration.
*/
for (t.tv_sec = 4; t.tv_sec <= 14; t.tv_sec += 2)
{
for (i = 0; i < nets; i++)
{
baddr.sin_addr = addrs[i];
if (sendto (sock, outbuf, outlen, 0,
(struct sockaddr *) &baddr,
sizeof (struct sockaddr)) != outlen)
{
perror (_("Cannot send broadcast packet"));
stat = RPC_CANTSEND;
goto done_broad;
}
}
if (eachresult == NULL)
{
stat = RPC_SUCCESS;
goto done_broad;
}
recv_again:
msg.acpted_rply.ar_verf = _null_auth;
msg.acpted_rply.ar_results.where = (caddr_t) & r;
msg.acpted_rply.ar_results.proc = (xdrproc_t) xdr_rmtcallres;
milliseconds = t.tv_sec * 1000 + t.tv_usec / 1000;
switch (__poll(&fd, 1, milliseconds))
{
case 0: /* timed out */
stat = RPC_TIMEDOUT;
continue;
case -1: /* some kind of error */
if (errno == EINTR)
goto recv_again;
perror (_("Broadcast poll problem"));
stat = RPC_CANTRECV;
goto done_broad;
} /* end of poll results switch */
try_again:
fromlen = sizeof (struct sockaddr);
inlen = recvfrom (sock, inbuf, UDPMSGSIZE, 0,
(struct sockaddr *) &raddr, &fromlen);
if (inlen < 0)
{
if (errno == EINTR)
goto try_again;
perror (_("Cannot receive reply to broadcast"));
stat = RPC_CANTRECV;
goto done_broad;
}
if ((size_t) inlen < sizeof (u_long))
goto recv_again;
/*
* see if reply transaction id matches sent id.
* If so, decode the results.
*/
xdrmem_create (xdrs, inbuf, (u_int) inlen, XDR_DECODE);
if (xdr_replymsg (xdrs, &msg))
{
if (((u_int32_t) msg.rm_xid == (u_int32_t) xid) &&
(msg.rm_reply.rp_stat == MSG_ACCEPTED) &&
(msg.acpted_rply.ar_stat == SUCCESS))
{
raddr.sin_port = htons ((u_short) port);
done = (*eachresult) (resultsp, &raddr);
}
/* otherwise, we just ignore the errors ... */
}
else
{
#ifdef notdef
/* some kind of deserialization problem ... */
if ((u_int32_t) msg.rm_xid == (u_int32_t) xid)
fprintf (stderr, "Broadcast deserialization problem");
/* otherwise, just random garbage */
#endif
}
xdrs->x_op = XDR_FREE;
msg.acpted_rply.ar_results.proc = (xdrproc_t)xdr_void;
(void) xdr_replymsg (xdrs, &msg);
(void) (*xresults) (xdrs, resultsp);
xdr_destroy (xdrs);
if (done)
{
stat = RPC_SUCCESS;
goto done_broad;
}
else
{
goto recv_again;
}
}
done_broad:
(void) __close (sock);
AUTH_DESTROY (unix_auth);
return stat;
}