v13i078: Sun RPC, release 3.9, Part01/15
Rich Salz
rsalz at bbn.com
Wed Mar 2 10:02:18 AEST 1988
Submitted-by: Stephen X. Nahm <sxn at Sun.COM>
Posting-number: Volume 13, Issue 78
Archive-name: rpc3.9/part01
RPCSRC 3.9 11/30/87
This distribution contains Sun Microsystem's implementation of the
RPC and XDR protocols and is compatible with 4.2BSD and 4.3BSD. Also
included is complete documentation, utilities, RPC service
specification files, and demonstration services in the format used by
the RPC protocol compiler (rpcgen).
If you wish to report bugs found in this release, send mail to:
Portable NFS
Sun Microsystems, Inc
MS 12-33
2550 Garcia Avenue
Mountain View, CA 94043
or send Email to nfsnet at sun.com (the Internet) or sun!nfsnet (Usenet).
WHAT'S NEW IN THIS RELEASE
The previous release was RPCSRC 3.2. As with all previous releases,
this release is based directly on files from Sun Microsystem's
implementation.
New Documentation
1) New manual pages are provided for the XDR and RPC library
routines.
2) Revised versions are provided of the "RPC Programmer's Manual,"
the "XDR Protocol Specification," and the "RPC Protocol
Specification."
3) Three new manuals are provided: "RPCGEN Programmer's Manual,"
"XDR Technical Notes," and the "NFS Protocol Specification."
New Demonstration Services
4) The demo directory contains two services used as examples in the
"RPCGEN Programmer's Manual": msg and dir.
5) A "sort service" is also provided in RPCL format (.x). This
service is identical to the "toy" service in RPCSRC 3.2, however
it is now built with RPCGEN.
New Functionality
6) rpcgen has been extensively improved. It now provides client
stubs in addition to server stubs. New conventions are used for
naming procedures to make it easier to convert a non-RPC service
into an RPC-based service. The RPC Language (RPCL) has been
changed slightly (particularly with the specification of variable
length arrays). Constants can be defined, and rpcgen now uses
the C Pre-Processor. See the "RPCGEN Programmer's manual" for
details.
7) rpcinfo can now send broadcast calls to services.
Service Definitions
8) Service definition files (in RPCGEN format) are now included
for certain RPC services. THESE SERVICE DEFINITIONS ARE FOR
INFORMATION ONLY. No guarantee is made of their accuracy or
suitability for any particular purpose.
9) The Remote Status (rstat) service is supplied. This service is
used by perfmeter on Sun workstations to display the server's
load average, cpu utilization and other information. This service
is compatible with 4.2BSD and 4.3BSD only. No client is supplied.
(see rpcsvc/rstat.x)
The package may be purchased from Sun for $100. Order RPC-3.9-X-X-5
for 1/4" tape, or RPC-3.9-X-X-6 for 1/2" tape.
-----
Steve Nahm <sxn at Sun.COM>
for the Portable NFS Team
#! /bin/sh
# This is a shell archive. To extract, remove the header and type "sh filename"
#
echo x - DISCLAIMER
cat > DISCLAIMER <<'Funky_Stuff'
/*
* 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
*/
Funky_Stuff
len=`wc -c < DISCLAIMER`
if [ $len != 1269 ] ; then
echo error: DISCLAIMER was $len bytes long, should have been 1269
fi
echo x - README
cat > README <<'Funky_Stuff'
RPCSRC 3.9 11/30/87
This distribution contains Sun Microsystem's implementation of the
RPC and XDR protocols and is compatible with 4.2BSD and 4.3BSD. Also
included is complete documentation, utilities, RPC service
specification files, and demonstration services in the format used by
the RPC protocol compiler (rpcgen). See WHAT'S NEW below for
details.
If you wish to report bugs found in this release, send mail to:
Portable NFS
Sun Microsystems, Inc
MS 12-33
2550 Garcia Avenue
Mountain View, CA 94043
or send Email to nfsnet at sun.com (the Internet) or sun!nfsnet (Usenet).
ROADMAP
The directory hierarchy is as follows:
demo/ Various demonstration services
demo/dir Remote directory lister
demo/msg Remote console message delivery service
demo/sort Remote sort service
doc/ Documentation for RPC, XDR and NFS in "-ms" format.
etc/ Utilities (rpcinfo and portmap). portmap must be
started by root before any other RPC network services are
used. SEE BELOW FOR BUGFIX TO 4.3BSD COMPILER.
man/ Manual pages for RPC library, rpcgen, and utilities.
rpc/ The RPC and XDR library (formerly rpclib). SEE BELOW
FOR BUGFIX TO 4.2BSD COMPILER.
rpcgen/ The RPC Language compiler (for .x files)
rpcsvc/ Service definition files for various services and the
server procedures for the Remote Status service.
BUILD INSTRUCTIONS
Makefiles can be found in all directories except for man. The
Makefile in the top directory will cause these others to be invoked
(except for in the doc directory), in turn building the entire
release.
After making any compiler fixes that are needed (see below), at
the top directory, type:
make install
For all installations, the Makefile macro DESTDIR is prepended to the
installation path. It is defined to be null in the Makefiles, so
installations are relative to root. (You will probably need root
privileges for installing the files under the default path.) To
install the files under some other tree (e.g., /usr/local), use the
command:
make install DESTDIR=/usr/local
This will place the include files in /usr/local/usr/include, the RPC
library in /usr/local/usr/lib, rpcgen in /usr/local/usr/bin, and the
utilities in /usr/local/etc. You'll have to edit the Makefiles or
install the files by hand if you want to do anything other than this
kind of relocation of the installation tree.
The RPC library will be built and installed first. By default it is
installed in /usr/lib as "librpclib.a". The directory
/usr/include/rpc will also be created, and several header files will
be installed there. ALL RPC SERVICES INCLUDE THESE HEADER FILES.
The programs in etc link in routines from librpclib.a. If you change
where it is installed, be sure to edit etc's Makefile to reflect this.
These programs are installed in /etc. PORTMAP MUST BE RUNNING ON
YOUR SYSTEM BEFORE YOU START ANY OTHER RPC SERVICE.
rpcgen is installed in /usr/bin. This program is required to build
the demonstration services in demo.
The rpcsvc directory will install its files in the directory
/usr/include/rpcsvc. The Remote Status service (rstat) will be
compiled and installed in /etc. If you wish to make this service
available, you should either start this service when needed or have
it started at boot time by invoking it in your /etc/rc.local script.
(Be sure that portmap is started first!) Sun has modified its
version of inetd to automatically start RPC services. (Use "make
LIB=" when building rstat on a Sun Workstation.)
The documentation is not built during the "make install" command.
Typing "make" in the doc directory will cause all of the manuals to
be formatted using nroff into a single file. We have had a report
that certain "troff" equivalents have trouble processing the full
manual. If you have trouble, try building the manuals individually
(see the Makefile).
The demonstration services in the demo directory are not built by the
top-level "make install" command. To build these, cd to the demo
directory and enter "make". The three services will be built.
RPCGEN MUST BE INSTALLED in a path that make can find. To run the
services, start the portmap program as root and invoke the service
(you probably will want to put it in the background). rpcinfo can be
used to check that the service succeeded in getting registered with
portmap, and to ping the service (see rpcinfo's man page). You can
then use the corresponding client program to exercise the service.
To build these services on a Sun workstation, you must prevent the
Makefile from trying to link the RPC library (as these routines are
already a part of Sun's libc). Use: "make LIB=".
BUGFIX FOR 4.3BSD COMPILER
The use of a 'void *' declaration for one of the arguments in
the reply_proc() procedure in etc/rpcinfo.c will trigger a bug
in the 4.3BSD compiler. The bug is fixed by the following change to
the compiler file mip/manifest.h:
*** manifest.h.r1.1 Thu Apr 30 13:52:25 1987
--- manifest.h.r1.2 Mon Nov 23 18:58:17 1987
***************
*** 21,27 ****
/*
* Bogus type values
*/
! #define TNULL PTR /* pointer to UNDEF */
#define TVOID FTN /* function returning UNDEF (for void) */
/*
--- 21,27 ----
/*
* Bogus type values
*/
! #define TNULL INCREF(MOETY) /* pointer to MOETY -- impossible type */
#define TVOID FTN /* function returning UNDEF (for void) */
/*
If you cannot fix your compiler, change the declartion in reply_proc()
from 'void *' to 'char *'.
BUGFIX FOR 4.2BSD COMPILER
Unpatched 4.2BSD compilers complain about valid C. You can make old
compilers happy by changing some voids to ints. However, the fix to
the 4.2 VAX compiler is as follows (to mip/trees.c):
*** trees.c.r1.1 Mon May 11 13:47:58 1987
--- trees.c.r1.2 Wed Jul 2 18:28:52 1986
***************
*** 1247,1253 ****
if(o==CAST && mt1==0)return(TYPL+TYMATCH);
if( mt12 & MDBI ) return( TYPL+LVAL+TYMATCH );
else if( (mt1&MENU)||(mt2&MENU) ) return( LVAL+NCVT+TYPL+PTMATCH+PUN );
! else if( mt12 == 0 ) break;
else if( mt1 & MPTR ) return( LVAL+PTMATCH+PUN );
else if( mt12 & MPTI ) return( TYPL+LVAL+TYMATCH+PUN );
break;
--- 1261,1269 ----
if(o==CAST && mt1==0)return(TYPL+TYMATCH);
if( mt12 & MDBI ) return( TYPL+LVAL+TYMATCH );
else if( (mt1&MENU)||(mt2&MENU) ) return( LVAL+NCVT+TYPL+PTMATCH+PUN );
! /* if right is TVOID and looks like a CALL, is not ok */
! else if (mt2 == 0 && (p->in.right->in.op == CALL || p->in.right->in.op == UNARY CALL))
! break;
else if( mt1 & MPTR ) return( LVAL+PTMATCH+PUN );
else if( mt12 & MPTI ) return( TYPL+LVAL+TYMATCH+PUN );
break;
WHAT'S NEW IN THIS RELEASE
The previous release was RPCSRC 3.2. As with all previous releases,
this release is based directly on files from Sun Microsystem's
implementation.
New Documentation
1) New manual pages are provided for the XDR and RPC library
routines.
2) Revised versions are provided of the "RPC Programmer's Manual,"
the "XDR Protocol Specification," and the "RPC Protocol
Specification."
3) Three new manuals are provided: "RPCGEN Programmer's Manual,"
"XDR Technical Notes," and the "NFS Protocol Specification."
New Demonstration Services
4) The demo directory contains two services used as examples in the
"RPCGEN Programmer's Manual": msg and dir.
5) A "sort service" is also provided in RPCL format (.x). This
service is identical to the "toy" service in RPCSRC 3.2, however
it is now built with RPCGEN.
New Functionality
6) rpcgen has been extensively improved. It now provides client
stubs in addition to server stubs. New conventions are used for
naming procedures to make it easier to convert a non-RPC service
into an RPC-based service. The RPC Language (RPCL) has been
changed slightly (particularly with the specification of variable
length arrays). Constants can be defined, and rpcgen now uses
the C Pre-Processor. See the "RPCGEN Programmer's manual" for
details.
7) rpcinfo can now send broadcast calls to services.
Service Definitions
8) Service definition files (in RPCGEN format) are now included
for certain RPC services. THESE SERVICE DEFINITIONS ARE FOR
INFORMATION ONLY. No guarantee is made of their accuracy or
suitability for any particular purpose.
9) The Remote Status (rstat) service is supplied. This service is
used by perfmeter on Sun workstations to display the server's
load average, cpu utilization and other information. This service
is compatible with 4.2BSD and 4.3BSD only. No client is supplied.
(see rpcsvc/rstat.x)
Funky_Stuff
len=`wc -c < README`
if [ $len != 8752 ] ; then
echo error: README was $len bytes long, should have been 8752
fi
echo x - Makefile
cat > Makefile <<'Funky_Stuff'
#
# @(#)Makefile 1.6 87/11/30 3.9 RPCSRC
#
# Build and install everything.
#
# These directories are presumed to exist in DESTDIR:
# /usr/lib /usr/bin /usr/include
#
DESTDIR=
CFLAGS=-O
MAKE=make
SUBDIR= rpcgen etc rpcsvc
all install: rpclib ${SUBDIR}
rpclib: FRC
@echo "Building and installing RPC library"
cd rpc; $(MAKE) ${MFLAGS} all DESTDIR=${DESTDIR}; \
$(MAKE) ${MFLAGS} install DESTDIR=${DESTDIR}
${SUBDIR}: FRC
@echo "Building and installing files from: $@"
cd $@; $(MAKE) ${MFLAGS} DESTDIR=${DESTDIR} CFLAGS=${CFLAGS};\
$(MAKE) ${MFLAGS} install DESTDIR=${DESTDIR}
FRC:
Funky_Stuff
len=`wc -c < Makefile`
if [ $len != 610 ] ; then
echo error: Makefile was $len bytes long, should have been 610
fi
echo x - rpc
echo creating directory rpc
mkdir rpc
cd rpc
echo x - Makefile
cat > Makefile <<'Funky_Stuff'
#
# @(#)Makefile 1.4 87/11/13 3.9 RPCSRC
#
#
# Copyright (c) 1987 by Sun Microsystems, Inc.
#
DESTDIR=
CPPFLAGS = -I..
CFLAGS = -I..
SRCS = auth_none.c auth_unix.c authunix_prot.c bindresvport.c \
clnt_generic.c clnt_perror.c clnt_raw.c clnt_simple.c clnt_tcp.c \
clnt_udp.c rpc_dtablesize.c get_myaddress.c getrpcent.c getrpcport.c \
pmap_clnt.c pmap_getmaps.c pmap_getport.c pmap_prot.c \
pmap_prot2.c pmap_rmt.c rpc_prot.c rpc_commondata.c rpc_callmsg.c \
svc.c svc_auth.c svc_auth_unix.c svc_raw.c svc_run.c svc_simple.c \
svc_tcp.c svc_udp.c xdr.c xdr_array.c xdr_float.c xdr_mem.c \
xdr_rec.c xdr_reference.c xdr_stdio.c
OBJS = auth_none.o auth_unix.o authunix_prot.o bindresvport.o \
clnt_generic.o clnt_perror.o clnt_raw.o clnt_simple.o clnt_tcp.o \
clnt_udp.o rpc_dtablesize.o get_myaddress.o getrpcent.o getrpcport.o \
pmap_clnt.o pmap_getmaps.o pmap_getport.o pmap_prot.o \
pmap_prot2.o pmap_rmt.o rpc_prot.o rpc_commondata.o rpc_callmsg.o \
svc.o svc_auth.o svc_auth_unix.o svc_raw.o svc_run.o svc_simple.o \
svc_tcp.o svc_udp.o xdr.o xdr_array.o xdr_float.o xdr_mem.o \
xdr_rec.o xdr_reference.o xdr_stdio.o
HDRS = auth.h auth_unix.h clnt.h netdb.h pmap_clnt.h \
pmap_prot.h pmap_rmt.h rpc.h rpc_msg.h svc.h svc_auth.h types.h xdr.h
all rpclib: librpclib.a
librpclib.a: ${OBJS}
@echo "building librpclib.a"
@ar cru librpclib.a ${OBJS}
install: $(HDRS) librpclib.a
@echo "Creating RPC header directory"
-mkdir ${DESTDIR}/usr/include/rpc && \
chown bin ${DESTDIR}/usr/include/rpc && \
chmod 755 ${DESTDIR}/usr/include/rpc
@echo "Installing RPC header files"
-set -x;for i in $(HDRS) ; do \
(install -c -m 644 $$i ${DESTDIR}/usr/include/rpc) done
@echo "Installing RPC library"
install -c -m 644 librpclib.a ${DESTDIR}/usr/lib
ranlib ${DESTDIR}/usr/lib/librpclib.a
tags: $(SRCS) $(HDRS)
ctags -tw $(SRCS) $(HDRS)
ref: tags
sed 's, /.*,,' tags | \
awk ' { printf("%-26s%-16s%s\n", $$1, $$2, $$3) }' > ref
lint: $(SRCS) $(HDRS)
$(LINT.c) $(SRCS)
clean: rm -f *.o rpclib.a
.SUFFIXES: .x .x~
.x.c:
rpcgen -c $< | \
sed 's/^#include \"$*\.h\"/#include <rpc\/$*\.h>/' > $@
.x.h:
rpcgen -h $< > $@
depend: $(SRCS) $(HDRS)
@${CC} ${CFLAGS} -M ${SRCS} > makedep
@echo '/^# DO NOT DELETE THIS LINE/+1,$$d' >eddep
@echo '$$r makedep' >>eddep
@echo 'w' >>eddep
@cp Makefile makefile.bak
@ed - Makefile < eddep
@rm eddep makedep makefile.bak
depend.42BSD depend.42bsd:
cp /dev/null x.c
for i in $(SRCS) ; do \
(/bin/grep '^#[ ]*include' x.c $$i | sed \
-e '/\.\.\/h/d' \
-e '/\.\.\/ufs/d' \
-e 's,<\(.*\)>,"/usr/include/\1",' \
-e 's/:[^"]*"\([^"]*\)".*/: \1/' \
-e 's/\.c/\.o/' >>makedep); done
echo '/^# DO NOT DELETE THIS LINE/+2,$$d' >eddep
echo '$$r makedep' >>eddep
echo 'w' >>eddep
cp Makefile Makefile.bak
ed - Makefile < eddep
rm eddep makedep x.c
echo '# DEPENDENCIES MUST END AT END OF FILE' >> Makefile
echo '# IF YOU PUT STUFF HERE IT WILL GO AWAY' >> Makefile
echo '# see make depend above' >> Makefile
# DO NOT DELETE THIS LINE
Funky_Stuff
len=`wc -c < Makefile`
if [ $len != 3145 ] ; then
echo error: Makefile was $len bytes long, should have been 3145
fi
echo x - auth.h
cat > auth.h <<'Funky_Stuff'
/* @(#)auth.h 1.2 87/11/23 3.9 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
*/
/* @(#)auth.h 1.16 87/10/01 SMI */
/*
* auth.h, Authentication interface.
*
* Copyright (C) 1984, Sun Microsystems, Inc.
*
* The data structures are completely opaque to the client. The client
* is required to pass a AUTH * to routines that create rpc
* "sessions".
*/
#define MAX_AUTH_BYTES 400
#define MAXNETNAMELEN 255 /* maximum length of network user's name */
/*
* Status returned from authentication check
*/
enum auth_stat {
AUTH_OK=0,
/*
* failed at remote end
*/
AUTH_BADCRED=1, /* bogus credentials (seal broken) */
AUTH_REJECTEDCRED=2, /* client should begin new session */
AUTH_BADVERF=3, /* bogus verifier (seal broken) */
AUTH_REJECTEDVERF=4, /* verifier expired or was replayed */
AUTH_TOOWEAK=5, /* rejected due to security reasons */
/*
* failed locally
*/
AUTH_INVALIDRESP=6, /* bogus response verifier */
AUTH_FAILED=7 /* some unknown reason */
};
#if (mc68000 || sparc || vax || i386)
typedef u_long u_int32; /* 32-bit unsigned integers */
#endif
/*
* Authentication info. Opaque to client.
*/
struct opaque_auth {
enum_t oa_flavor; /* flavor of auth */
caddr_t oa_base; /* address of more auth stuff */
u_int oa_length; /* not to exceed MAX_AUTH_BYTES */
};
/*
* Auth handle, interface to client side authenticators.
*/
typedef struct {
struct opaque_auth ah_cred;
struct opaque_auth ah_verf;
struct auth_ops {
void (*ah_nextverf)();
int (*ah_marshal)(); /* nextverf & serialize */
int (*ah_validate)(); /* validate varifier */
int (*ah_refresh)(); /* refresh credentials */
void (*ah_destroy)(); /* destroy this structure */
} *ah_ops;
caddr_t ah_private;
} AUTH;
/*
* Authentication ops.
* The ops and the auth handle provide the interface to the authenticators.
*
* AUTH *auth;
* XDR *xdrs;
* struct opaque_auth verf;
*/
#define AUTH_NEXTVERF(auth) \
((*((auth)->ah_ops->ah_nextverf))(auth))
#define auth_nextverf(auth) \
((*((auth)->ah_ops->ah_nextverf))(auth))
#define AUTH_MARSHALL(auth, xdrs) \
((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
#define auth_marshall(auth, xdrs) \
((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
#define AUTH_VALIDATE(auth, verfp) \
((*((auth)->ah_ops->ah_validate))((auth), verfp))
#define auth_validate(auth, verfp) \
((*((auth)->ah_ops->ah_validate))((auth), verfp))
#define AUTH_REFRESH(auth) \
((*((auth)->ah_ops->ah_refresh))(auth))
#define auth_refresh(auth) \
((*((auth)->ah_ops->ah_refresh))(auth))
#define AUTH_DESTROY(auth) \
((*((auth)->ah_ops->ah_destroy))(auth))
#define auth_destroy(auth) \
((*((auth)->ah_ops->ah_destroy))(auth))
extern struct opaque_auth _null_auth;
/*
* These are the various implementations of client side authenticators.
*/
/*
* Unix style authentication
* AUTH *authunix_create(machname, uid, gid, len, aup_gids)
* char *machname;
* int uid;
* int gid;
* int len;
* int *aup_gids;
*/
extern AUTH *authunix_create();
extern AUTH *authunix_create_default(); /* takes no parameters */
extern AUTH *authnone_create(); /* takes no parameters */
#define AUTH_NONE 0 /* no authentication */
#define AUTH_NULL 0 /* backward compatibility */
#define AUTH_UNIX 1 /* unix style (uid, gids) */
#define AUTH_SHORT 2 /* short hand unix style */
#define AUTH_DES 3 /* des style (encrypted timestamps) */
Funky_Stuff
len=`wc -c < auth.h`
if [ $len != 4637 ] ; then
echo error: auth.h was $len bytes long, should have been 4637
fi
echo x - auth_none.c
cat > auth_none.c <<'Funky_Stuff'
/* @(#)auth_none.c 1.1 87/11/04 3.9 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[] = "@(#)auth_none.c 1.19 87/08/11 Copyr 1984 Sun Micro";
#endif
/*
* auth_none.c
* Creates a client authentication handle for passing "null"
* credentials and verifiers to remote systems.
*
* Copyright (C) 1984, Sun Microsystems, Inc.
*/
#include <rpc/types.h>
#include <rpc/xdr.h>
#include <rpc/auth.h>
#define MAX_MARSHEL_SIZE 20
/*
* Authenticator operations routines
*/
static void authnone_verf();
static void authnone_destroy();
static bool_t authnone_marshal();
static bool_t authnone_validate();
static bool_t authnone_refresh();
static struct auth_ops ops = {
authnone_verf,
authnone_marshal,
authnone_validate,
authnone_refresh,
authnone_destroy
};
static struct authnone_private {
AUTH no_client;
char marshalled_client[MAX_MARSHEL_SIZE];
u_int mcnt;
} *authnone_private;
AUTH *
authnone_create()
{
register struct authnone_private *ap = authnone_private;
XDR xdr_stream;
register XDR *xdrs;
if (ap == 0) {
ap = (struct authnone_private *)calloc(1, sizeof (*ap));
if (ap == 0)
return (0);
authnone_private = ap;
}
if (!ap->mcnt) {
ap->no_client.ah_cred = ap->no_client.ah_verf = _null_auth;
ap->no_client.ah_ops = &ops;
xdrs = &xdr_stream;
xdrmem_create(xdrs, ap->marshalled_client, (u_int)MAX_MARSHEL_SIZE,
XDR_ENCODE);
(void)xdr_opaque_auth(xdrs, &ap->no_client.ah_cred);
(void)xdr_opaque_auth(xdrs, &ap->no_client.ah_verf);
ap->mcnt = XDR_GETPOS(xdrs);
XDR_DESTROY(xdrs);
}
return (&ap->no_client);
}
/*ARGSUSED*/
static bool_t
authnone_marshal(client, xdrs)
AUTH *client;
XDR *xdrs;
{
register struct authnone_private *ap = authnone_private;
if (ap == 0)
return (0);
return ((*xdrs->x_ops->x_putbytes)(xdrs,
ap->marshalled_client, ap->mcnt));
}
static void
authnone_verf()
{
}
static bool_t
authnone_validate()
{
return (TRUE);
}
static bool_t
authnone_refresh()
{
return (FALSE);
}
static void
authnone_destroy()
{
}
Funky_Stuff
len=`wc -c < auth_none.c`
if [ $len != 3296 ] ; then
echo error: auth_none.c was $len bytes long, should have been 3296
fi
echo x - auth_unix.c
cat > auth_unix.c <<'Funky_Stuff'
/* @(#)auth_unix.c 1.1 87/11/04 3.9 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[] = "@(#)auth_unix.c 1.19 87/08/11 Copyr 1984 Sun Micro";
#endif
/*
* auth_unix.c, Implements UNIX style authentication parameters.
*
* Copyright (C) 1984, Sun Microsystems, Inc.
*
* The system is very weak. The client uses no encryption for it's
* credentials and only sends null verifiers. The server sends backs
* null verifiers or optionally a verifier that suggests a new short hand
* for the credentials.
*
*/
#include <stdio.h>
#include <sys/time.h>
#include <rpc/types.h>
#include <rpc/xdr.h>
#include <rpc/auth.h>
#include <rpc/auth_unix.h>
/*
* Unix authenticator operations vector
*/
static void authunix_nextverf();
static bool_t authunix_marshal();
static bool_t authunix_validate();
static bool_t authunix_refresh();
static void authunix_destroy();
static struct auth_ops auth_unix_ops = {
authunix_nextverf,
authunix_marshal,
authunix_validate,
authunix_refresh,
authunix_destroy
};
/*
* This struct is pointed to by the ah_private field of an auth_handle.
*/
struct audata {
struct opaque_auth au_origcred; /* original credentials */
struct opaque_auth au_shcred; /* short hand cred */
u_long au_shfaults; /* short hand cache faults */
char au_marshed[MAX_AUTH_BYTES];
u_int au_mpos; /* xdr pos at end of marshed */
};
#define AUTH_PRIVATE(auth) ((struct audata *)auth->ah_private)
static bool_t marshal_new_auth();
/*
* Create a unix style authenticator.
* Returns an auth handle with the given stuff in it.
*/
AUTH *
authunix_create(machname, uid, gid, len, aup_gids)
char *machname;
int uid;
int gid;
register int len;
int *aup_gids;
{
struct authunix_parms aup;
char mymem[MAX_AUTH_BYTES];
struct timeval now;
XDR xdrs;
register AUTH *auth;
register struct audata *au;
/*
* Allocate and set up auth handle
*/
auth = (AUTH *)mem_alloc(sizeof(*auth));
#ifndef KERNEL
if (auth == NULL) {
(void)fprintf(stderr, "authunix_create: out of memory\n");
return (NULL);
}
#endif
au = (struct audata *)mem_alloc(sizeof(*au));
#ifndef KERNEL
if (au == NULL) {
(void)fprintf(stderr, "authunix_create: out of memory\n");
return (NULL);
}
#endif
auth->ah_ops = &auth_unix_ops;
auth->ah_private = (caddr_t)au;
auth->ah_verf = au->au_shcred = _null_auth;
au->au_shfaults = 0;
/*
* fill in param struct from the given params
*/
(void)gettimeofday(&now, (struct timezone *)0);
aup.aup_time = now.tv_sec;
aup.aup_machname = machname;
aup.aup_uid = uid;
aup.aup_gid = gid;
aup.aup_len = (u_int)len;
aup.aup_gids = aup_gids;
/*
* Serialize the parameters into origcred
*/
xdrmem_create(&xdrs, mymem, MAX_AUTH_BYTES, XDR_ENCODE);
if (! xdr_authunix_parms(&xdrs, &aup))
abort();
au->au_origcred.oa_length = len = XDR_GETPOS(&xdrs);
au->au_origcred.oa_flavor = AUTH_UNIX;
#ifdef KERNEL
au->au_origcred.oa_base = mem_alloc((u_int) len);
#else
if ((au->au_origcred.oa_base = mem_alloc((u_int) len)) == NULL) {
(void)fprintf(stderr, "authunix_create: out of memory\n");
return (NULL);
}
#endif
bcopy(mymem, au->au_origcred.oa_base, (u_int)len);
/*
* set auth handle to reflect new cred.
*/
auth->ah_cred = au->au_origcred;
marshal_new_auth(auth);
return (auth);
}
/*
* Returns an auth handle with parameters determined by doing lots of
* syscalls.
*/
AUTH *
authunix_create_default()
{
register int len;
char machname[MAX_MACHINE_NAME + 1];
register int uid;
register int gid;
int gids[NGRPS];
if (gethostname(machname, MAX_MACHINE_NAME) == -1)
abort();
machname[MAX_MACHINE_NAME] = 0;
uid = geteuid();
gid = getegid();
if ((len = getgroups(NGRPS, gids)) < 0)
abort();
return (authunix_create(machname, uid, gid, len, gids));
}
/*
* authunix operations
*/
static void
authunix_nextverf(auth)
AUTH *auth;
{
/* no action necessary */
}
static bool_t
authunix_marshal(auth, xdrs)
AUTH *auth;
XDR *xdrs;
{
register struct audata *au = AUTH_PRIVATE(auth);
return (XDR_PUTBYTES(xdrs, au->au_marshed, au->au_mpos));
}
static bool_t
authunix_validate(auth, verf)
register AUTH *auth;
struct opaque_auth verf;
{
register struct audata *au;
XDR xdrs;
if (verf.oa_flavor == AUTH_SHORT) {
au = AUTH_PRIVATE(auth);
xdrmem_create(&xdrs, verf.oa_base, verf.oa_length, XDR_DECODE);
if (au->au_shcred.oa_base != NULL) {
mem_free(au->au_shcred.oa_base,
au->au_shcred.oa_length);
au->au_shcred.oa_base = NULL;
}
if (xdr_opaque_auth(&xdrs, &au->au_shcred)) {
auth->ah_cred = au->au_shcred;
} else {
xdrs.x_op = XDR_FREE;
(void)xdr_opaque_auth(&xdrs, &au->au_shcred);
au->au_shcred.oa_base = NULL;
auth->ah_cred = au->au_origcred;
}
marshal_new_auth(auth);
}
return (TRUE);
}
static bool_t
authunix_refresh(auth)
register AUTH *auth;
{
register struct audata *au = AUTH_PRIVATE(auth);
struct authunix_parms aup;
struct timeval now;
XDR xdrs;
register int stat;
if (auth->ah_cred.oa_base == au->au_origcred.oa_base) {
/* there is no hope. Punt */
return (FALSE);
}
au->au_shfaults ++;
/* first deserialize the creds back into a struct authunix_parms */
aup.aup_machname = NULL;
aup.aup_gids = (int *)NULL;
xdrmem_create(&xdrs, au->au_origcred.oa_base,
au->au_origcred.oa_length, XDR_DECODE);
stat = xdr_authunix_parms(&xdrs, &aup);
if (! stat)
goto done;
/* update the time and serialize in place */
(void)gettimeofday(&now, (struct timezone *)0);
aup.aup_time = now.tv_sec;
xdrs.x_op = XDR_ENCODE;
XDR_SETPOS(&xdrs, 0);
stat = xdr_authunix_parms(&xdrs, &aup);
if (! stat)
goto done;
auth->ah_cred = au->au_origcred;
marshal_new_auth(auth);
done:
/* free the struct authunix_parms created by deserializing */
xdrs.x_op = XDR_FREE;
(void)xdr_authunix_parms(&xdrs, &aup);
XDR_DESTROY(&xdrs);
return (stat);
}
static void
authunix_destroy(auth)
register AUTH *auth;
{
register struct audata *au = AUTH_PRIVATE(auth);
mem_free(au->au_origcred.oa_base, au->au_origcred.oa_length);
if (au->au_shcred.oa_base != NULL)
mem_free(au->au_shcred.oa_base, au->au_shcred.oa_length);
mem_free(auth->ah_private, sizeof(struct audata));
if (auth->ah_verf.oa_base != NULL)
mem_free(auth->ah_verf.oa_base, auth->ah_verf.oa_length);
mem_free((caddr_t)auth, sizeof(*auth));
}
/*
* Marshals (pre-serializes) an auth struct.
* sets private data, au_marshed and au_mpos
*/
static bool_t
marshal_new_auth(auth)
register AUTH *auth;
{
XDR xdr_stream;
register XDR *xdrs = &xdr_stream;
register struct audata *au = AUTH_PRIVATE(auth);
xdrmem_create(xdrs, au->au_marshed, MAX_AUTH_BYTES, XDR_ENCODE);
if ((! xdr_opaque_auth(xdrs, &(auth->ah_cred))) ||
(! xdr_opaque_auth(xdrs, &(auth->ah_verf)))) {
perror("auth_none.c - Fatal marshalling problem");
} else {
au->au_mpos = XDR_GETPOS(xdrs);
}
XDR_DESTROY(xdrs);
}
Funky_Stuff
len=`wc -c < auth_unix.c`
if [ $len != 8130 ] ; then
echo error: auth_unix.c was $len bytes long, should have been 8130
fi
echo x - auth_unix.h
cat > auth_unix.h <<'Funky_Stuff'
/* @(#)auth_unix.h 1.1 87/11/04 3.9 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
*/
/* @(#)auth_unix.h 1.5 86/07/16 SMI */
/*
* auth_unix.h, Protocol for UNIX style authentication parameters for RPC
*
* Copyright (C) 1984, Sun Microsystems, Inc.
*/
/*
* The system is very weak. The client uses no encryption for it
* credentials and only sends null verifiers. The server sends backs
* null verifiers or optionally a verifier that suggests a new short hand
* for the credentials.
*/
/* The machine name is part of a credential; it may not exceed 255 bytes */
#define MAX_MACHINE_NAME 255
/* gids compose part of a credential; there may not be more than 10 of them */
#define NGRPS 8
/*
* Unix style credentials.
*/
struct authunix_parms {
u_long aup_time;
char *aup_machname;
int aup_uid;
int aup_gid;
u_int aup_len;
int *aup_gids;
};
extern bool_t xdr_authunix_parms();
/*
* If a response verifier has flavor AUTH_SHORT,
* then the body of the response verifier encapsulates the following structure;
* again it is serialized in the obvious fashion.
*/
struct short_hand_verf {
struct opaque_auth new_cred;
};
Funky_Stuff
len=`wc -c < auth_unix.h`
if [ $len != 2389 ] ; then
echo error: auth_unix.h was $len bytes long, should have been 2389
fi
echo x - authunix_prot.c
cat > authunix_prot.c <<'Funky_Stuff'
/* @(#)authunix_prot.c 1.1 87/11/04 3.9 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[] = "@(#)authunix_prot.c 1.15 87/08/11 Copyr 1984 Sun Micro";
#endif
/*
* authunix_prot.c
* XDR for UNIX style authentication parameters for RPC
*
* Copyright (C) 1984, Sun Microsystems, Inc.
*/
#include <rpc/types.h>
#include <rpc/xdr.h>
#include <rpc/auth.h>
#include <rpc/auth_unix.h>
/*
* XDR for unix authentication parameters.
*/
bool_t
xdr_authunix_parms(xdrs, p)
register XDR *xdrs;
register struct authunix_parms *p;
{
if (xdr_u_long(xdrs, &(p->aup_time))
&& xdr_string(xdrs, &(p->aup_machname), MAX_MACHINE_NAME)
&& xdr_int(xdrs, &(p->aup_uid))
&& xdr_int(xdrs, &(p->aup_gid))
&& xdr_array(xdrs, (caddr_t *)&(p->aup_gids),
&(p->aup_len), NGRPS, sizeof(int), xdr_int) ) {
return (TRUE);
}
return (FALSE);
}
Funky_Stuff
len=`wc -c < authunix_prot.c`
if [ $len != 2139 ] ; then
echo error: authunix_prot.c was $len bytes long, should have been 2139
fi
echo x - bindresvport.c
cat > bindresvport.c <<'Funky_Stuff'
/* @(#)bindresvport.c 1.1 87/11/04 3.9 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[] = "@(#)bindresvport.c 1.6 87/09/23 SMI";
#endif
/*
* Copyright (c) 1987 by Sun Microsystems, Inc.
*/
#include <sys/types.h>
#include <sys/errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
/*
* Bind a socket to a privileged IP port
*/
bindresvport(sd, sin)
int sd;
struct sockaddr_in *sin;
{
int res;
static short port;
struct sockaddr_in myaddr;
extern int errno;
int i;
#define STARTPORT 600
#define ENDPORT (IPPORT_RESERVED - 1)
#define NPORTS (ENDPORT - STARTPORT + 1)
if (sin == (struct sockaddr_in *)0) {
sin = &myaddr;
bzero(sin, sizeof (*sin));
sin->sin_family = AF_INET;
} else if (sin->sin_family != AF_INET) {
errno = EPFNOSUPPORT;
return (-1);
}
if (port == 0) {
port = (getpid() % NPORTS) + STARTPORT;
}
for (i = 0; i < NPORTS; i++) {
sin->sin_port = htons(port++);
if (port > ENDPORT) {
port = STARTPORT;
}
res = bind(sd, sin, sizeof(struct sockaddr_in));
if (res == 0) {
return (0);
}
if ((res < 0) && (errno == EACCES)) {
return (-1);
}
}
return (-1);
}
Funky_Stuff
len=`wc -c < bindresvport.c`
if [ $len != 2416 ] ; then
echo error: bindresvport.c was $len bytes long, should have been 2416
fi
echo x - clnt.h
cat > clnt.h <<'Funky_Stuff'
/* @(#)clnt.h 1.1 87/11/04 3.9 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
*/
/* @(#)clnt.h 1.30 87/07/14 SMI */
/*
* clnt.h - Client side remote procedure call interface.
*
* Copyright (C) 1984, Sun Microsystems, Inc.
*/
#ifndef _CLNT_
#define _CLNT_
/*
* Rpc calls return an enum clnt_stat. This should be looked at more,
* since each implementation is required to live with this (implementation
* independent) list of errors.
*/
enum clnt_stat {
RPC_SUCCESS=0, /* call succeeded */
/*
* local errors
*/
RPC_CANTENCODEARGS=1, /* can't encode arguments */
RPC_CANTDECODERES=2, /* can't decode results */
RPC_CANTSEND=3, /* failure in sending call */
RPC_CANTRECV=4, /* failure in receiving result */
RPC_TIMEDOUT=5, /* call timed out */
/*
* remote errors
*/
RPC_VERSMISMATCH=6, /* rpc versions not compatible */
RPC_AUTHERROR=7, /* authentication error */
RPC_PROGUNAVAIL=8, /* program not available */
RPC_PROGVERSMISMATCH=9, /* program version mismatched */
RPC_PROCUNAVAIL=10, /* procedure unavailable */
RPC_CANTDECODEARGS=11, /* decode arguments error */
RPC_SYSTEMERROR=12, /* generic "other problem" */
/*
* callrpc & clnt_create errors
*/
RPC_UNKNOWNHOST=13, /* unknown host name */
RPC_UNKNOWNPROTO=17, /* unkown protocol */
/*
* _ create errors
*/
RPC_PMAPFAILURE=14, /* the pmapper failed in its call */
RPC_PROGNOTREGISTERED=15, /* remote program is not registered */
/*
* unspecified error
*/
RPC_FAILED=16
};
/*
* Error info.
*/
struct rpc_err {
enum clnt_stat re_status;
union {
int RE_errno; /* realated system error */
enum auth_stat RE_why; /* why the auth error occurred */
struct {
u_long low; /* lowest verion supported */
u_long high; /* highest verion supported */
} RE_vers;
struct { /* maybe meaningful if RPC_FAILED */
long s1;
long s2;
} RE_lb; /* life boot & debugging only */
} ru;
#define re_errno ru.RE_errno
#define re_why ru.RE_why
#define re_vers ru.RE_vers
#define re_lb ru.RE_lb
};
/*
* Client rpc handle.
* Created by individual implementations, see e.g. rpc_udp.c.
* Client is responsible for initializing auth, see e.g. auth_none.c.
*/
typedef struct {
AUTH *cl_auth; /* authenticator */
struct clnt_ops {
enum clnt_stat (*cl_call)(); /* call remote procedure */
void (*cl_abort)(); /* abort a call */
void (*cl_geterr)(); /* get specific error code */
bool_t (*cl_freeres)(); /* frees results */
void (*cl_destroy)();/* destroy this structure */
bool_t (*cl_control)();/* the ioctl() of rpc */
} *cl_ops;
caddr_t cl_private; /* private stuff */
} CLIENT;
/*
* client side rpc interface ops
*
* Parameter types are:
*
*/
/*
* enum clnt_stat
* CLNT_CALL(rh, proc, xargs, argsp, xres, resp, timeout)
* CLIENT *rh;
* u_long proc;
* xdrproc_t xargs;
* caddr_t argsp;
* xdrproc_t xres;
* caddr_t resp;
* struct timeval timeout;
*/
#define CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs) \
((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs))
#define clnt_call(rh, proc, xargs, argsp, xres, resp, secs) \
((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs))
/*
* void
* CLNT_ABORT(rh);
* CLIENT *rh;
*/
#define CLNT_ABORT(rh) ((*(rh)->cl_ops->cl_abort)(rh))
#define clnt_abort(rh) ((*(rh)->cl_ops->cl_abort)(rh))
/*
* struct rpc_err
* CLNT_GETERR(rh);
* CLIENT *rh;
*/
#define CLNT_GETERR(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp))
#define clnt_geterr(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp))
/*
* bool_t
* CLNT_FREERES(rh, xres, resp);
* CLIENT *rh;
* xdrproc_t xres;
* caddr_t resp;
*/
#define CLNT_FREERES(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
#define clnt_freeres(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
/*
* bool_t
* CLNT_CONTROL(cl, request, info)
* CLIENT *cl;
* u_int request;
* char *info;
*/
#define CLNT_CONTROL(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
#define clnt_control(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
/*
* control operations that apply to both udp and tcp transports
*/
#define CLSET_TIMEOUT 1 /* set timeout (timeval) */
#define CLGET_TIMEOUT 2 /* get timeout (timeval) */
#define CLGET_SERVER_ADDR 3 /* get server's address (sockaddr) */
/*
* udp only control operations
*/
#define CLSET_RETRY_TIMEOUT 4 /* set retry timeout (timeval) */
#define CLGET_RETRY_TIMEOUT 5 /* get retry timeout (timeval) */
/*
* void
* CLNT_DESTROY(rh);
* CLIENT *rh;
*/
#define CLNT_DESTROY(rh) ((*(rh)->cl_ops->cl_destroy)(rh))
#define clnt_destroy(rh) ((*(rh)->cl_ops->cl_destroy)(rh))
/*
* RPCTEST is a test program which is accessable on every rpc
* transport/port. It is used for testing, performance evaluation,
* and network administration.
*/
#define RPCTEST_PROGRAM ((u_long)1)
#define RPCTEST_VERSION ((u_long)1)
#define RPCTEST_NULL_PROC ((u_long)2)
#define RPCTEST_NULL_BATCH_PROC ((u_long)3)
/*
* By convention, procedure 0 takes null arguments and returns them
*/
#define NULLPROC ((u_long)0)
/*
* Below are the client handle creation routines for the various
* implementations of client side rpc. They can return NULL if a
* creation failure occurs.
*/
/*
* Memory based rpc (for speed check and testing)
* CLIENT *
* clntraw_create(prog, vers)
* u_long prog;
* u_long vers;
*/
extern CLIENT *clntraw_create();
/*
* Generic client creation routine. Supported protocols are "udp" and "tcp"
*/
extern CLIENT *
clnt_create(/*host, prog, vers, prot*/); /*
char *host; -- hostname
u_long prog; -- program number
u_long vers; -- version number
char *prot; -- protocol
*/
/*
* TCP based rpc
* CLIENT *
* clnttcp_create(raddr, prog, vers, sockp, sendsz, recvsz)
* struct sockaddr_in *raddr;
* u_long prog;
* u_long version;
* register int *sockp;
* u_int sendsz;
* u_int recvsz;
*/
extern CLIENT *clnttcp_create();
/*
* UDP based rpc.
* CLIENT *
* clntudp_create(raddr, program, version, wait, sockp)
* struct sockaddr_in *raddr;
* u_long program;
* u_long version;
* struct timeval wait;
* int *sockp;
*
* Same as above, but you specify max packet sizes.
* CLIENT *
* clntudp_bufcreate(raddr, program, version, wait, sockp, sendsz, recvsz)
* struct sockaddr_in *raddr;
* u_long program;
* u_long version;
* struct timeval wait;
* int *sockp;
* u_int sendsz;
* u_int recvsz;
*/
extern CLIENT *clntudp_create();
extern CLIENT *clntudp_bufcreate();
/*
* Print why creation failed
*/
void clnt_pcreateerror(/* char *msg */); /* stderr */
char *clnt_spcreateerror(/* char *msg */); /* string */
/*
* Like clnt_perror(), but is more verbose in its output
*/
void clnt_perrno(/* enum clnt_stat num */); /* stderr */
/*
* Print an English error message, given the client error code
*/
void clnt_perror(/* CLIENT *clnt, char *msg */); /* stderr */
char *clnt_sperror(/* CLIENT *clnt, char *msg */); /* string */
/*
* If a creation fails, the following allows the user to figure out why.
*/
struct rpc_createerr {
enum clnt_stat cf_stat;
struct rpc_err cf_error; /* useful when cf_stat == RPC_PMAPFAILURE */
};
extern struct rpc_createerr rpc_createerr;
/*
* Copy error message to buffer.
*/
char *clnt_sperrno(/* enum clnt_stat num */); /* string */
#define UDPMSGSIZE 8800 /* rpc imposed limit on udp msg size */
#define RPCSMALLMSGSIZE 400 /* a more reasonable packet size */
#endif /*!_CLNT_*/
Funky_Stuff
len=`wc -c < clnt.h`
if [ $len != 8731 ] ; then
echo error: clnt.h was $len bytes long, should have been 8731
fi
echo x - clnt_generic.c
cat > clnt_generic.c <<'Funky_Stuff'
/* @(#)clnt_generic.c 1.1 87/11/04 3.9 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[] = "@(#)clnt_generic.c 1.4 87/08/11 (C) 1987 SMI";
#endif
/*
* Copyright (C) 1987, Sun Microsystems, Inc.
*/
#include <rpc/rpc.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/errno.h>
#include <netdb.h>
/*
* Generic client creation: takes (hostname, program-number, protocol) and
* returns client handle. Default options are set, which the user can
* change using the rpc equivalent of ioctl()'s.
*/
CLIENT *
clnt_create(hostname, prog, vers, proto)
char *hostname;
unsigned prog;
unsigned vers;
char *proto;
{
struct hostent *h;
struct protoent *p;
struct sockaddr_in sin;
int sock;
struct timeval tv;
CLIENT *client;
h = gethostbyname(hostname);
if (h == NULL) {
rpc_createerr.cf_stat = RPC_UNKNOWNHOST;
return (NULL);
}
if (h->h_addrtype != AF_INET) {
/*
* Only support INET for now
*/
rpc_createerr.cf_stat = RPC_SYSTEMERROR;
rpc_createerr.cf_error.re_errno = EAFNOSUPPORT;
return (NULL);
}
sin.sin_family = h->h_addrtype;
sin.sin_port = 0;
bzero(sin.sin_zero, sizeof(sin.sin_zero));
bcopy(h->h_addr, (char*)&sin.sin_addr, h->h_length);
p = getprotobyname(proto);
if (p == NULL) {
rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
rpc_createerr.cf_error.re_errno = EPFNOSUPPORT;
return (NULL);
}
sock = RPC_ANYSOCK;
switch (p->p_proto) {
case IPPROTO_UDP:
tv.tv_sec = 5;
tv.tv_usec = 0;
client = clntudp_create(&sin, prog, vers, tv, &sock);
if (client == NULL) {
return (NULL);
}
tv.tv_sec = 25;
clnt_control(client, CLSET_TIMEOUT, &tv);
break;
case IPPROTO_TCP:
client = clnttcp_create(&sin, prog, vers, &sock, 0, 0);
if (client == NULL) {
return (NULL);
}
tv.tv_sec = 25;
tv.tv_usec = 0;
clnt_control(client, CLSET_TIMEOUT, &tv);
break;
default:
rpc_createerr.cf_stat = RPC_SYSTEMERROR;
rpc_createerr.cf_error.re_errno = EPFNOSUPPORT;
return (NULL);
}
return (client);
}
Funky_Stuff
len=`wc -c < clnt_generic.c`
if [ $len != 3268 ] ; then
echo error: clnt_generic.c was $len bytes long, should have been 3268
fi
echo x - clnt_perror.c
cat > clnt_perror.c <<'Funky_Stuff'
/* @(#)clnt_perror.c 1.1 87/11/04 3.9 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[] = "@(#)clnt_perror.c 1.15 87/10/07 Copyr 1984 Sun Micro";
#endif
/*
* clnt_perror.c
*
* Copyright (C) 1984, Sun Microsystems, Inc.
*
*/
#include <stdio.h>
#include <rpc/types.h>
#include <rpc/auth.h>
#include <rpc/clnt.h>
extern char *sys_errlist[];
extern char *sprintf();
static char *auth_errmsg();
extern char *strcpy();
static char *buf;
static char *
_buf()
{
if (buf == 0)
buf = (char *)malloc(256);
return (buf);
}
/*
* Print reply error info
*/
char *
clnt_sperror(rpch, s)
CLIENT *rpch;
char *s;
{
struct rpc_err e;
void clnt_perrno();
char *err;
char *str = _buf();
char *strstart = str;
if (str == 0)
return (0);
CLNT_GETERR(rpch, &e);
(void) sprintf(str, "%s: ", s);
str += strlen(str);
(void) strcpy(str, clnt_sperrno(e.re_status));
str += strlen(str);
switch (e.re_status) {
case RPC_SUCCESS:
case RPC_CANTENCODEARGS:
case RPC_CANTDECODERES:
case RPC_TIMEDOUT:
case RPC_PROGUNAVAIL:
case RPC_PROCUNAVAIL:
case RPC_CANTDECODEARGS:
case RPC_SYSTEMERROR:
case RPC_UNKNOWNHOST:
case RPC_UNKNOWNPROTO:
case RPC_PMAPFAILURE:
case RPC_PROGNOTREGISTERED:
case RPC_FAILED:
break;
case RPC_CANTSEND:
case RPC_CANTRECV:
(void) sprintf(str, "; errno = %s",
sys_errlist[e.re_errno]);
str += strlen(str);
break;
case RPC_VERSMISMATCH:
(void) sprintf(str,
"; low version = %lu, high version = %lu",
e.re_vers.low, e.re_vers.high);
str += strlen(str);
break;
case RPC_AUTHERROR:
err = auth_errmsg(e.re_why);
(void) sprintf(str,"; why = ");
str += strlen(str);
if (err != NULL) {
(void) sprintf(str, "%s",err);
} else {
(void) sprintf(str,
"(unknown authentication error - %d)",
(int) e.re_why);
}
str += strlen(str);
break;
case RPC_PROGVERSMISMATCH:
(void) sprintf(str,
"; low version = %lu, high version = %lu",
e.re_vers.low, e.re_vers.high);
str += strlen(str);
break;
default: /* unknown */
(void) sprintf(str,
"; s1 = %lu, s2 = %lu",
e.re_lb.s1, e.re_lb.s2);
str += strlen(str);
break;
}
(void) sprintf(str, "\n");
return(strstart) ;
}
void
clnt_perror(rpch, s)
CLIENT *rpch;
char *s;
{
(void) fprintf(stderr,"%s",clnt_sperror(rpch,s));
}
struct rpc_errtab {
enum clnt_stat status;
char *message;
};
static struct rpc_errtab rpc_errlist[] = {
{ RPC_SUCCESS,
"RPC: Success" },
{ RPC_CANTENCODEARGS,
"RPC: Can't encode arguments" },
{ RPC_CANTDECODERES,
"RPC: Can't decode result" },
{ RPC_CANTSEND,
"RPC: Unable to send" },
{ RPC_CANTRECV,
"RPC: Unable to receive" },
{ RPC_TIMEDOUT,
"RPC: Timed out" },
{ RPC_VERSMISMATCH,
"RPC: Incompatible versions of RPC" },
{ RPC_AUTHERROR,
"RPC: Authentication error" },
{ RPC_PROGUNAVAIL,
"RPC: Program unavailable" },
{ RPC_PROGVERSMISMATCH,
"RPC: Program/version mismatch" },
{ RPC_PROCUNAVAIL,
"RPC: Procedure unavailable" },
{ RPC_CANTDECODEARGS,
"RPC: Server can't decode arguments" },
{ RPC_SYSTEMERROR,
"RPC: Remote system error" },
{ RPC_UNKNOWNHOST,
"RPC: Unknown host" },
{ RPC_UNKNOWNPROTO,
"RPC: Unknown protocol" },
{ RPC_PMAPFAILURE,
"RPC: Port mapper failure" },
{ RPC_PROGNOTREGISTERED,
"RPC: Program not registered"},
{ RPC_FAILED,
"RPC: Failed (unspecified error)"}
};
/*
* This interface for use by clntrpc
*/
char *
clnt_sperrno(stat)
enum clnt_stat stat;
{
int i;
for (i = 0; i < sizeof(rpc_errlist)/sizeof(struct rpc_errtab); i++) {
if (rpc_errlist[i].status == stat) {
return (rpc_errlist[i].message);
}
}
return ("RPC: (unknown error code)");
}
void
clnt_perrno(num)
enum clnt_stat num;
{
(void) fprintf(stderr,"%s",clnt_sperrno(num));
}
char *
clnt_spcreateerror(s)
char *s;
{
extern int sys_nerr;
extern char *sys_errlist[];
char *str = _buf();
if (str == 0)
return(0);
(void) sprintf(str, "%s: ", s);
(void) strcat(str, clnt_sperrno(rpc_createerr.cf_stat));
switch (rpc_createerr.cf_stat) {
case RPC_PMAPFAILURE:
(void) strcat(str, " - ");
(void) strcat(str,
clnt_sperrno(rpc_createerr.cf_error.re_status));
break;
case RPC_SYSTEMERROR:
(void) strcat(str, " - ");
if (rpc_createerr.cf_error.re_errno > 0
&& rpc_createerr.cf_error.re_errno < sys_nerr)
(void) strcat(str,
sys_errlist[rpc_createerr.cf_error.re_errno]);
else
(void) sprintf(&str[strlen(str)], "Error %d",
rpc_createerr.cf_error.re_errno);
break;
}
(void) strcat(str, "\n");
return (str);
}
void
clnt_pcreateerror(s)
char *s;
{
(void) fprintf(stderr,"%s",clnt_spcreateerror(s));
}
struct auth_errtab {
enum auth_stat status;
char *message;
};
static struct auth_errtab auth_errlist[] = {
{ AUTH_OK,
"Authentication OK" },
{ AUTH_BADCRED,
"Invalid client credential" },
{ AUTH_REJECTEDCRED,
"Server rejected credential" },
{ AUTH_BADVERF,
"Invalid client verifier" },
{ AUTH_REJECTEDVERF,
"Server rejected verifier" },
{ AUTH_TOOWEAK,
"Client credential too weak" },
{ AUTH_INVALIDRESP,
"Invalid server verifier" },
{ AUTH_FAILED,
"Failed (unspecified error)" },
};
static char *
auth_errmsg(stat)
enum auth_stat stat;
{
int i;
for (i = 0; i < sizeof(auth_errlist)/sizeof(struct auth_errtab); i++) {
if (auth_errlist[i].status == stat) {
return(auth_errlist[i].message);
}
}
return(NULL);
}
Funky_Stuff
len=`wc -c < clnt_perror.c`
if [ $len != 6675 ] ; then
echo error: clnt_perror.c was $len bytes long, should have been 6675
fi
cd ..
echo more files to follow
exit
--
For comp.sources.unix stuff, mail to rsalz at uunet.uu.net.
More information about the Comp.sources.unix
mailing list