home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume13 / rpc3.9 / part01 next >
Encoding:
Internet Message Format  |  1988-02-27  |  59.7 KB

  1. Subject:  v13i078:  Sun RPC, release 3.9, Part01/15
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: Stephen X. Nahm <sxn@Sun.COM>
  7. Posting-number: Volume 13, Issue 78
  8. Archive-name: rpc3.9/part01
  9.  
  10. RPCSRC 3.9 11/30/87
  11.  
  12. This distribution contains Sun Microsystem's implementation of the
  13. RPC and XDR protocols and is compatible with 4.2BSD and 4.3BSD.  Also
  14. included is complete documentation, utilities, RPC service
  15. specification files, and demonstration services in the format used by
  16. the RPC protocol compiler (rpcgen).  
  17.  
  18. If you wish to report bugs found in this release, send mail to:
  19.  
  20. Portable NFS
  21. Sun Microsystems, Inc
  22. MS 12-33
  23. 2550 Garcia Avenue
  24. Mountain View, CA  94043
  25.  
  26. or send Email to nfsnet@sun.com (the Internet) or sun!nfsnet (Usenet).
  27.  
  28. WHAT'S NEW IN THIS RELEASE
  29.  
  30. The previous release was RPCSRC 3.2.  As with all previous releases,
  31. this release is based directly on files from Sun Microsystem's
  32. implementation.
  33.  
  34. New Documentation
  35.  
  36. 1)  New manual pages are provided for the XDR and RPC library
  37.     routines.
  38. 2)  Revised versions are provided of the "RPC Programmer's Manual,"
  39.     the "XDR Protocol Specification," and the "RPC Protocol
  40.     Specification."
  41. 3)  Three new manuals are provided: "RPCGEN Programmer's Manual,"
  42.     "XDR Technical Notes," and the "NFS Protocol Specification."
  43.  
  44. New Demonstration Services
  45.  
  46. 4)  The demo directory contains two services used as examples in the
  47.     "RPCGEN Programmer's Manual": msg and dir.
  48. 5)  A "sort service" is also provided in RPCL format (.x). This
  49.     service is identical to the "toy" service in RPCSRC 3.2, however
  50.     it is now built with RPCGEN.
  51.  
  52. New Functionality
  53.  
  54. 6)  rpcgen has been extensively improved.  It now provides client
  55.     stubs in addition to server stubs.  New conventions are used for
  56.     naming procedures to make it easier to convert a non-RPC service
  57.     into an RPC-based service.  The RPC Language (RPCL) has been
  58.     changed slightly (particularly with the specification of variable
  59.     length arrays).  Constants can be defined, and rpcgen now uses
  60.     the C Pre-Processor.  See the "RPCGEN Programmer's manual" for
  61.     details.
  62. 7)  rpcinfo can now send broadcast calls to services.
  63.  
  64. Service Definitions
  65.  
  66. 8)  Service definition files (in RPCGEN format) are now included
  67.     for certain RPC services.  THESE SERVICE DEFINITIONS ARE FOR
  68.     INFORMATION ONLY.  No guarantee is made of their accuracy or
  69.     suitability for any particular purpose.
  70. 9)  The Remote Status (rstat) service is supplied.  This service is
  71.     used by perfmeter on Sun workstations to display the server's
  72.     load average, cpu utilization and other information.  This service
  73.     is compatible with 4.2BSD and 4.3BSD only.  No client is supplied.
  74.     (see rpcsvc/rstat.x)
  75.  
  76. The package may be purchased from Sun for $100.  Order RPC-3.9-X-X-5
  77. for 1/4" tape, or RPC-3.9-X-X-6 for 1/2" tape.
  78. -----
  79. Steve Nahm <sxn@Sun.COM>
  80. for the Portable NFS Team
  81.  
  82. #! /bin/sh
  83. # This is a shell archive. To extract, remove the header and type "sh filename"
  84. #
  85. echo x - DISCLAIMER
  86. cat > DISCLAIMER <<'Funky_Stuff'
  87. /*
  88.  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  89.  * unrestricted use provided that this legend is included on all tape
  90.  * media and as a part of the software program in whole or part.  Users
  91.  * may copy or modify Sun RPC without charge, but are not authorized
  92.  * to license or distribute it to anyone else except as part of a product or
  93.  * program developed by the user.
  94.  * 
  95.  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  96.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  97.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  98.  * 
  99.  * Sun RPC is provided with no support and without any obligation on the
  100.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  101.  * modification or enhancement.
  102.  * 
  103.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  104.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  105.  * OR ANY PART THEREOF.
  106.  * 
  107.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  108.  * or profits or other special, indirect and consequential damages, even if
  109.  * Sun has been advised of the possibility of such damages.
  110.  * 
  111.  * Sun Microsystems, Inc.
  112.  * 2550 Garcia Avenue
  113.  * Mountain View, California  94043
  114.  */
  115. Funky_Stuff
  116. len=`wc -c < DISCLAIMER`
  117. if [ $len !=     1269 ] ; then
  118.   echo error: DISCLAIMER was $len bytes long, should have been     1269
  119. fi
  120. echo x - README
  121. cat > README <<'Funky_Stuff'
  122. RPCSRC 3.9 11/30/87
  123.  
  124. This distribution contains Sun Microsystem's implementation of the
  125. RPC and XDR protocols and is compatible with 4.2BSD and 4.3BSD.  Also
  126. included is complete documentation, utilities, RPC service
  127. specification files, and demonstration services in the format used by
  128. the RPC protocol compiler (rpcgen).  See WHAT'S NEW below for
  129. details.
  130.  
  131. If you wish to report bugs found in this release, send mail to:
  132.  
  133. Portable NFS
  134. Sun Microsystems, Inc
  135. MS 12-33
  136. 2550 Garcia Avenue
  137. Mountain View, CA  94043
  138.  
  139. or send Email to nfsnet@sun.com (the Internet) or sun!nfsnet (Usenet).
  140.  
  141. ROADMAP
  142.  
  143. The directory hierarchy is as follows:
  144.  
  145.     demo/       Various demonstration services
  146.     demo/dir        Remote directory lister
  147.     demo/msg        Remote console message delivery service
  148.     demo/sort       Remote sort service
  149.  
  150.     doc/        Documentation for RPC, XDR and NFS in "-ms" format.
  151.  
  152.     etc/        Utilities (rpcinfo and portmap).  portmap must be
  153.                 started by root before any other RPC network services are
  154.                 used.  SEE BELOW FOR BUGFIX TO 4.3BSD COMPILER.
  155.  
  156.     man/        Manual pages for RPC library, rpcgen, and utilities.
  157.  
  158.     rpc/        The RPC and XDR library (formerly rpclib).  SEE BELOW
  159.                 FOR BUGFIX TO 4.2BSD COMPILER.
  160.  
  161.     rpcgen/     The RPC Language compiler (for .x files)
  162.  
  163.     rpcsvc/     Service definition files for various services and the
  164.                 server procedures for the Remote Status service.
  165.  
  166. BUILD INSTRUCTIONS
  167.  
  168. Makefiles can be found in all directories except for man.  The
  169. Makefile in the top directory will cause these others to be invoked
  170. (except for in the doc directory), in turn building the entire
  171. release.
  172.  
  173. After making any compiler fixes that are needed (see below), at
  174. the top directory, type:
  175.  
  176.     make install
  177.  
  178. For all installations, the Makefile macro DESTDIR is prepended to the
  179. installation path.  It is defined to be null in the Makefiles, so
  180. installations are relative to root.  (You will probably need root
  181. privileges for installing the files under the default path.)  To
  182. install the files under some other tree (e.g., /usr/local), use the
  183. command:
  184.  
  185.     make install DESTDIR=/usr/local
  186.  
  187. This will place the include files in /usr/local/usr/include, the RPC
  188. library in /usr/local/usr/lib, rpcgen in /usr/local/usr/bin, and the
  189. utilities in /usr/local/etc.  You'll have to edit the Makefiles or
  190. install the files by hand if you want to do anything other than this
  191. kind of relocation of the installation tree.
  192.  
  193. The RPC library will be built and installed first.  By default it is
  194. installed in /usr/lib as "librpclib.a".  The directory
  195. /usr/include/rpc will also be created, and several header files will
  196. be installed there.  ALL RPC SERVICES INCLUDE THESE HEADER FILES.
  197.  
  198. The programs in etc link in routines from librpclib.a.  If you change
  199. where it is installed, be sure to edit etc's Makefile to reflect this.
  200. These programs are installed in /etc.  PORTMAP MUST BE RUNNING ON
  201. YOUR SYSTEM BEFORE YOU START ANY OTHER RPC SERVICE.
  202.  
  203. rpcgen is installed in /usr/bin.  This program is required to build
  204. the demonstration services in demo.
  205.  
  206. The rpcsvc directory will install its files in the directory
  207. /usr/include/rpcsvc.  The Remote Status service (rstat) will be
  208. compiled and installed in /etc.  If you wish to make this service
  209. available, you should either start this service when needed or have
  210. it started at boot time by invoking it in your /etc/rc.local script.
  211. (Be sure that portmap is started first!)  Sun has modified its
  212. version of inetd to automatically start RPC services.  (Use "make
  213. LIB=" when building rstat on a Sun Workstation.)
  214.  
  215. The documentation is not built during the "make install" command.
  216. Typing "make" in the doc directory will cause all of the manuals to
  217. be formatted using nroff into a single file.  We have had a report
  218. that certain "troff" equivalents have trouble processing the full
  219. manual.  If you have trouble, try building the manuals individually
  220. (see the Makefile).
  221.  
  222. The demonstration services in the demo directory are not built by the
  223. top-level "make install" command.  To build these, cd to the demo
  224. directory and enter "make".  The three services will be built.
  225. RPCGEN MUST BE INSTALLED in a path that make can find.  To run the
  226. services, start the portmap program as root and invoke the service
  227. (you probably will want to put it in the background).  rpcinfo can be
  228. used to check that the service succeeded in getting registered with
  229. portmap, and to ping the service (see rpcinfo's man page).  You can
  230. then use the corresponding client program to exercise the service.
  231. To build these services on a Sun workstation, you must prevent the
  232. Makefile from trying to link the RPC library (as these routines are
  233. already a part of Sun's libc).  Use: "make LIB=".
  234.  
  235. BUGFIX FOR 4.3BSD COMPILER
  236.  
  237. The use of a 'void *' declaration for one of the arguments in
  238. the reply_proc() procedure in etc/rpcinfo.c will trigger a bug
  239. in the 4.3BSD compiler.  The bug is fixed by the following change to
  240. the compiler file mip/manifest.h:
  241.  
  242. *** manifest.h.r1.1    Thu Apr 30 13:52:25 1987
  243. --- manifest.h.r1.2    Mon Nov 23 18:58:17 1987
  244. ***************
  245. *** 21,27 ****
  246.   /*
  247.    * Bogus type values
  248.    */
  249. ! #define TNULL    PTR        /* pointer to UNDEF */
  250.   #define TVOID    FTN        /* function returning UNDEF (for void) */
  251.   
  252.   /*
  253. --- 21,27 ----
  254.   /*
  255.    * Bogus type values
  256.    */
  257. ! #define TNULL    INCREF(MOETY)    /* pointer to MOETY -- impossible type */
  258.   #define TVOID    FTN        /* function returning UNDEF (for void) */
  259.   
  260.   /*
  261.  
  262. If you cannot fix your compiler, change the declartion in reply_proc()
  263. from 'void *' to 'char *'.
  264.  
  265. BUGFIX FOR 4.2BSD COMPILER
  266.  
  267. Unpatched 4.2BSD compilers complain about valid C.  You can make old
  268. compilers happy by changing some voids to ints.  However, the fix to
  269. the 4.2 VAX compiler is as follows (to mip/trees.c):
  270.  
  271. *** trees.c.r1.1    Mon May 11 13:47:58 1987
  272. --- trees.c.r1.2    Wed Jul  2 18:28:52 1986
  273. ***************
  274. *** 1247,1253 ****
  275.           if(o==CAST && mt1==0)return(TYPL+TYMATCH);
  276.           if( mt12 & MDBI ) return( TYPL+LVAL+TYMATCH );
  277.           else if( (mt1&MENU)||(mt2&MENU) ) return( LVAL+NCVT+TYPL+PTMATCH+PUN );
  278. !         else if( mt12 == 0 ) break;
  279.           else if( mt1 & MPTR ) return( LVAL+PTMATCH+PUN );
  280.           else if( mt12 & MPTI ) return( TYPL+LVAL+TYMATCH+PUN );
  281.           break;
  282. --- 1261,1269 ----
  283.           if(o==CAST && mt1==0)return(TYPL+TYMATCH);
  284.           if( mt12 & MDBI ) return( TYPL+LVAL+TYMATCH );
  285.           else if( (mt1&MENU)||(mt2&MENU) ) return( LVAL+NCVT+TYPL+PTMATCH+PUN );
  286. !         /* if right is TVOID and looks like a CALL, is not ok */
  287. !         else if (mt2 == 0 && (p->in.right->in.op == CALL || p->in.right->in.op == UNARY CALL))
  288. !             break;
  289.           else if( mt1 & MPTR ) return( LVAL+PTMATCH+PUN );
  290.           else if( mt12 & MPTI ) return( TYPL+LVAL+TYMATCH+PUN );
  291.           break;
  292.  
  293. WHAT'S NEW IN THIS RELEASE
  294.  
  295. The previous release was RPCSRC 3.2.  As with all previous releases,
  296. this release is based directly on files from Sun Microsystem's
  297. implementation.
  298.  
  299. New Documentation
  300.  
  301. 1)  New manual pages are provided for the XDR and RPC library
  302.     routines.
  303. 2)  Revised versions are provided of the "RPC Programmer's Manual,"
  304.     the "XDR Protocol Specification," and the "RPC Protocol
  305.     Specification."
  306. 3)  Three new manuals are provided: "RPCGEN Programmer's Manual,"
  307.     "XDR Technical Notes," and the "NFS Protocol Specification."
  308.  
  309. New Demonstration Services
  310.  
  311. 4)  The demo directory contains two services used as examples in the
  312.     "RPCGEN Programmer's Manual": msg and dir.
  313. 5)  A "sort service" is also provided in RPCL format (.x). This
  314.     service is identical to the "toy" service in RPCSRC 3.2, however
  315.     it is now built with RPCGEN.
  316.  
  317. New Functionality
  318.  
  319. 6)  rpcgen has been extensively improved.  It now provides client
  320.     stubs in addition to server stubs.  New conventions are used for
  321.     naming procedures to make it easier to convert a non-RPC service
  322.     into an RPC-based service.  The RPC Language (RPCL) has been
  323.     changed slightly (particularly with the specification of variable
  324.     length arrays).  Constants can be defined, and rpcgen now uses
  325.     the C Pre-Processor.  See the "RPCGEN Programmer's manual" for
  326.     details.
  327. 7)  rpcinfo can now send broadcast calls to services.
  328.  
  329. Service Definitions
  330.  
  331. 8)  Service definition files (in RPCGEN format) are now included
  332.     for certain RPC services.  THESE SERVICE DEFINITIONS ARE FOR
  333.     INFORMATION ONLY.  No guarantee is made of their accuracy or
  334.     suitability for any particular purpose.
  335. 9)  The Remote Status (rstat) service is supplied.  This service is
  336.     used by perfmeter on Sun workstations to display the server's
  337.     load average, cpu utilization and other information.  This service
  338.     is compatible with 4.2BSD and 4.3BSD only.  No client is supplied.
  339.     (see rpcsvc/rstat.x)
  340. Funky_Stuff
  341. len=`wc -c < README`
  342. if [ $len !=     8752 ] ; then
  343.   echo error: README was $len bytes long, should have been     8752
  344. fi
  345. echo x - Makefile
  346. cat > Makefile <<'Funky_Stuff'
  347. #
  348. # @(#)Makefile    1.6 87/11/30 3.9 RPCSRC
  349. #
  350. #   Build and install everything.
  351. #
  352. # These directories are presumed to exist in DESTDIR:
  353. #    /usr/lib /usr/bin /usr/include
  354. #
  355. DESTDIR=
  356. CFLAGS=-O
  357. MAKE=make
  358.  
  359. SUBDIR= rpcgen etc rpcsvc
  360.  
  361. all install:    rpclib ${SUBDIR}
  362.  
  363. rpclib:    FRC
  364.     @echo "Building and installing RPC library"
  365.     cd rpc; $(MAKE) ${MFLAGS} all DESTDIR=${DESTDIR}; \
  366.         $(MAKE) ${MFLAGS} install DESTDIR=${DESTDIR}
  367.  
  368. ${SUBDIR}:    FRC
  369.     @echo "Building and installing files from: $@"
  370.     cd $@; $(MAKE) ${MFLAGS} DESTDIR=${DESTDIR} CFLAGS=${CFLAGS};\
  371.         $(MAKE) ${MFLAGS} install DESTDIR=${DESTDIR}
  372.  
  373. FRC:
  374.  
  375. Funky_Stuff
  376. len=`wc -c < Makefile`
  377. if [ $len !=      610 ] ; then
  378.   echo error: Makefile was $len bytes long, should have been      610
  379. fi
  380. echo x - rpc
  381. echo creating directory rpc
  382. mkdir rpc
  383. cd rpc
  384. echo x - Makefile
  385. cat > Makefile <<'Funky_Stuff'
  386. #
  387. # @(#)Makefile    1.4 87/11/13 3.9 RPCSRC
  388. #
  389. #
  390. # Copyright (c) 1987 by Sun Microsystems, Inc.
  391. #
  392. DESTDIR=
  393.  
  394. CPPFLAGS = -I..
  395. CFLAGS = -I..
  396.  
  397. SRCS = auth_none.c auth_unix.c  authunix_prot.c bindresvport.c \
  398.     clnt_generic.c clnt_perror.c clnt_raw.c clnt_simple.c clnt_tcp.c \
  399.     clnt_udp.c rpc_dtablesize.c get_myaddress.c getrpcent.c getrpcport.c \
  400.     pmap_clnt.c pmap_getmaps.c pmap_getport.c pmap_prot.c \
  401.     pmap_prot2.c pmap_rmt.c rpc_prot.c rpc_commondata.c rpc_callmsg.c \
  402.     svc.c svc_auth.c svc_auth_unix.c svc_raw.c svc_run.c svc_simple.c \
  403.     svc_tcp.c svc_udp.c xdr.c xdr_array.c xdr_float.c xdr_mem.c \
  404.     xdr_rec.c xdr_reference.c xdr_stdio.c
  405.  
  406. OBJS = auth_none.o auth_unix.o  authunix_prot.o bindresvport.o \
  407.     clnt_generic.o clnt_perror.o clnt_raw.o clnt_simple.o clnt_tcp.o \
  408.     clnt_udp.o rpc_dtablesize.o get_myaddress.o getrpcent.o getrpcport.o \
  409.     pmap_clnt.o pmap_getmaps.o pmap_getport.o pmap_prot.o \
  410.     pmap_prot2.o pmap_rmt.o rpc_prot.o rpc_commondata.o rpc_callmsg.o \
  411.     svc.o svc_auth.o svc_auth_unix.o svc_raw.o svc_run.o svc_simple.o \
  412.     svc_tcp.o svc_udp.o xdr.o xdr_array.o xdr_float.o xdr_mem.o \
  413.     xdr_rec.o xdr_reference.o xdr_stdio.o
  414.  
  415. HDRS = auth.h auth_unix.h clnt.h netdb.h pmap_clnt.h \
  416.     pmap_prot.h pmap_rmt.h rpc.h rpc_msg.h svc.h svc_auth.h types.h xdr.h
  417.  
  418. all rpclib:    librpclib.a
  419.  
  420. librpclib.a: ${OBJS}
  421.     @echo "building librpclib.a"
  422.     @ar cru librpclib.a ${OBJS}
  423.  
  424. install: $(HDRS) librpclib.a
  425.     @echo "Creating RPC header directory"
  426.     -mkdir ${DESTDIR}/usr/include/rpc && \
  427.         chown bin ${DESTDIR}/usr/include/rpc && \
  428.         chmod 755 ${DESTDIR}/usr/include/rpc
  429.     @echo "Installing RPC header files"
  430.     -set -x;for i in $(HDRS) ; do \
  431.         (install -c -m 644 $$i ${DESTDIR}/usr/include/rpc) done
  432.     @echo "Installing RPC library"
  433.     install -c -m 644 librpclib.a ${DESTDIR}/usr/lib
  434.     ranlib ${DESTDIR}/usr/lib/librpclib.a
  435.  
  436. tags: $(SRCS) $(HDRS)
  437.     ctags -tw $(SRCS) $(HDRS)
  438.  
  439. ref: tags
  440.     sed 's,    /.*,,' tags | \
  441.     awk ' { printf("%-26s%-16s%s\n", $$1, $$2, $$3) }' > ref
  442.  
  443. lint: $(SRCS) $(HDRS)
  444.     $(LINT.c) $(SRCS)
  445.  
  446. clean: rm -f *.o rpclib.a
  447.  
  448. .SUFFIXES: .x .x~
  449.  
  450. .x.c:
  451.     rpcgen -c $< | \
  452.     sed 's/^#include \"$*\.h\"/#include <rpc\/$*\.h>/' > $@
  453.  
  454. .x.h:
  455.     rpcgen -h $< > $@
  456.  
  457. depend: $(SRCS) $(HDRS)
  458.     @${CC} ${CFLAGS} -M ${SRCS} > makedep
  459.     @echo '/^# DO NOT DELETE THIS LINE/+1,$$d' >eddep
  460.     @echo '$$r makedep' >>eddep
  461.     @echo 'w' >>eddep
  462.     @cp Makefile makefile.bak
  463.     @ed - Makefile < eddep
  464.     @rm eddep makedep makefile.bak
  465.  
  466. depend.42BSD depend.42bsd:
  467.     cp /dev/null x.c
  468.     for i in $(SRCS) ; do \
  469.               (/bin/grep '^#[         ]*include' x.c $$i | sed \
  470.                       -e '/\.\.\/h/d' \
  471.                       -e '/\.\.\/ufs/d' \
  472.                       -e 's,<\(.*\)>,"/usr/include/\1",' \
  473.                       -e 's/:[^"]*"\([^"]*\)".*/: \1/' \
  474.                       -e 's/\.c/\.o/' >>makedep); done
  475.     echo '/^# DO NOT DELETE THIS LINE/+2,$$d' >eddep
  476.     echo '$$r makedep' >>eddep
  477.     echo 'w' >>eddep
  478.     cp Makefile Makefile.bak
  479.     ed - Makefile < eddep
  480.     rm eddep makedep x.c
  481.     echo '# DEPENDENCIES MUST END AT END OF FILE' >> Makefile
  482.     echo '# IF YOU PUT STUFF HERE IT WILL GO AWAY' >> Makefile
  483.     echo '# see make depend above' >> Makefile
  484.  
  485. # DO NOT DELETE THIS LINE
  486.  
  487.  
  488. Funky_Stuff
  489. len=`wc -c < Makefile`
  490. if [ $len !=     3145 ] ; then
  491.   echo error: Makefile was $len bytes long, should have been     3145
  492. fi
  493. echo x - auth.h
  494. cat > auth.h <<'Funky_Stuff'
  495. /* @(#)auth.h    1.2 87/11/23 3.9 RPCSRC */
  496. /*
  497.  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  498.  * unrestricted use provided that this legend is included on all tape
  499.  * media and as a part of the software program in whole or part.  Users
  500.  * may copy or modify Sun RPC without charge, but are not authorized
  501.  * to license or distribute it to anyone else except as part of a product or
  502.  * program developed by the user.
  503.  * 
  504.  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  505.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  506.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  507.  * 
  508.  * Sun RPC is provided with no support and without any obligation on the
  509.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  510.  * modification or enhancement.
  511.  * 
  512.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  513.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  514.  * OR ANY PART THEREOF.
  515.  * 
  516.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  517.  * or profits or other special, indirect and consequential damages, even if
  518.  * Sun has been advised of the possibility of such damages.
  519.  * 
  520.  * Sun Microsystems, Inc.
  521.  * 2550 Garcia Avenue
  522.  * Mountain View, California  94043
  523.  */
  524. /*      @(#)auth.h 1.16 87/10/01 SMI      */
  525.  
  526. /*
  527.  * auth.h, Authentication interface.
  528.  *
  529.  * Copyright (C) 1984, Sun Microsystems, Inc.
  530.  *
  531.  * The data structures are completely opaque to the client.  The client
  532.  * is required to pass a AUTH * to routines that create rpc
  533.  * "sessions".
  534.  */
  535.  
  536.  
  537. #define MAX_AUTH_BYTES    400
  538. #define MAXNETNAMELEN    255    /* maximum length of network user's name */
  539.  
  540. /*
  541.  * Status returned from authentication check
  542.  */
  543. enum auth_stat {
  544.     AUTH_OK=0,
  545.     /*
  546.      * failed at remote end
  547.      */
  548.     AUTH_BADCRED=1,            /* bogus credentials (seal broken) */
  549.     AUTH_REJECTEDCRED=2,        /* client should begin new session */
  550.     AUTH_BADVERF=3,            /* bogus verifier (seal broken) */
  551.     AUTH_REJECTEDVERF=4,        /* verifier expired or was replayed */
  552.     AUTH_TOOWEAK=5,            /* rejected due to security reasons */
  553.     /*
  554.      * failed locally
  555.     */
  556.     AUTH_INVALIDRESP=6,        /* bogus response verifier */
  557.     AUTH_FAILED=7            /* some unknown reason */
  558. };
  559.  
  560. #if (mc68000 || sparc || vax || i386)
  561. typedef u_long u_int32;    /* 32-bit unsigned integers */
  562. #endif
  563.  
  564. /*
  565.  * Authentication info.  Opaque to client.
  566.  */
  567. struct opaque_auth {
  568.     enum_t    oa_flavor;        /* flavor of auth */
  569.     caddr_t    oa_base;        /* address of more auth stuff */
  570.     u_int    oa_length;        /* not to exceed MAX_AUTH_BYTES */
  571. };
  572.  
  573.  
  574. /*
  575.  * Auth handle, interface to client side authenticators.
  576.  */
  577. typedef struct {
  578.     struct    opaque_auth    ah_cred;
  579.     struct    opaque_auth    ah_verf;
  580.     struct auth_ops {
  581.         void    (*ah_nextverf)();
  582.         int    (*ah_marshal)();    /* nextverf & serialize */
  583.         int    (*ah_validate)();    /* validate varifier */
  584.         int    (*ah_refresh)();    /* refresh credentials */
  585.         void    (*ah_destroy)();    /* destroy this structure */
  586.     } *ah_ops;
  587.     caddr_t ah_private;
  588. } AUTH;
  589.  
  590.  
  591. /*
  592.  * Authentication ops.
  593.  * The ops and the auth handle provide the interface to the authenticators.
  594.  *
  595.  * AUTH    *auth;
  596.  * XDR    *xdrs;
  597.  * struct opaque_auth verf;
  598.  */
  599. #define AUTH_NEXTVERF(auth)        \
  600.         ((*((auth)->ah_ops->ah_nextverf))(auth))
  601. #define auth_nextverf(auth)        \
  602.         ((*((auth)->ah_ops->ah_nextverf))(auth))
  603.  
  604. #define AUTH_MARSHALL(auth, xdrs)    \
  605.         ((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
  606. #define auth_marshall(auth, xdrs)    \
  607.         ((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
  608.  
  609. #define AUTH_VALIDATE(auth, verfp)    \
  610.         ((*((auth)->ah_ops->ah_validate))((auth), verfp))
  611. #define auth_validate(auth, verfp)    \
  612.         ((*((auth)->ah_ops->ah_validate))((auth), verfp))
  613.  
  614. #define AUTH_REFRESH(auth)        \
  615.         ((*((auth)->ah_ops->ah_refresh))(auth))
  616. #define auth_refresh(auth)        \
  617.         ((*((auth)->ah_ops->ah_refresh))(auth))
  618.  
  619. #define AUTH_DESTROY(auth)        \
  620.         ((*((auth)->ah_ops->ah_destroy))(auth))
  621. #define auth_destroy(auth)        \
  622.         ((*((auth)->ah_ops->ah_destroy))(auth))
  623.  
  624.  
  625. extern struct opaque_auth _null_auth;
  626.  
  627.  
  628. /*
  629.  * These are the various implementations of client side authenticators.
  630.  */
  631.  
  632. /*
  633.  * Unix style authentication
  634.  * AUTH *authunix_create(machname, uid, gid, len, aup_gids)
  635.  *    char *machname;
  636.  *    int uid;
  637.  *    int gid;
  638.  *    int len;
  639.  *    int *aup_gids;
  640.  */
  641. extern AUTH *authunix_create();
  642. extern AUTH *authunix_create_default();    /* takes no parameters */
  643. extern AUTH *authnone_create();        /* takes no parameters */
  644.  
  645. #define AUTH_NONE    0        /* no authentication */
  646. #define    AUTH_NULL    0        /* backward compatibility */
  647. #define    AUTH_UNIX    1        /* unix style (uid, gids) */
  648. #define    AUTH_SHORT    2        /* short hand unix style */
  649. #define AUTH_DES    3        /* des style (encrypted timestamps) */
  650. Funky_Stuff
  651. len=`wc -c < auth.h`
  652. if [ $len !=     4637 ] ; then
  653.   echo error: auth.h was $len bytes long, should have been     4637
  654. fi
  655. echo x - auth_none.c
  656. cat > auth_none.c <<'Funky_Stuff'
  657. /* @(#)auth_none.c    1.1 87/11/04 3.9 RPCSRC */
  658. /*
  659.  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  660.  * unrestricted use provided that this legend is included on all tape
  661.  * media and as a part of the software program in whole or part.  Users
  662.  * may copy or modify Sun RPC without charge, but are not authorized
  663.  * to license or distribute it to anyone else except as part of a product or
  664.  * program developed by the user.
  665.  * 
  666.  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  667.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  668.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  669.  * 
  670.  * Sun RPC is provided with no support and without any obligation on the
  671.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  672.  * modification or enhancement.
  673.  * 
  674.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  675.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  676.  * OR ANY PART THEREOF.
  677.  * 
  678.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  679.  * or profits or other special, indirect and consequential damages, even if
  680.  * Sun has been advised of the possibility of such damages.
  681.  * 
  682.  * Sun Microsystems, Inc.
  683.  * 2550 Garcia Avenue
  684.  * Mountain View, California  94043
  685.  */
  686. #if !defined(lint) && defined(SCCSIDS)
  687. static char sccsid[] = "@(#)auth_none.c 1.19 87/08/11 Copyr 1984 Sun Micro";
  688. #endif
  689.  
  690. /*
  691.  * auth_none.c
  692.  * Creates a client authentication handle for passing "null" 
  693.  * credentials and verifiers to remote systems. 
  694.  * 
  695.  * Copyright (C) 1984, Sun Microsystems, Inc. 
  696.  */
  697.  
  698. #include <rpc/types.h>
  699. #include <rpc/xdr.h>
  700. #include <rpc/auth.h>
  701. #define MAX_MARSHEL_SIZE 20
  702.  
  703. /*
  704.  * Authenticator operations routines
  705.  */
  706. static void    authnone_verf();
  707. static void    authnone_destroy();
  708. static bool_t    authnone_marshal();
  709. static bool_t    authnone_validate();
  710. static bool_t    authnone_refresh();
  711.  
  712. static struct auth_ops ops = {
  713.     authnone_verf,
  714.     authnone_marshal,
  715.     authnone_validate,
  716.     authnone_refresh,
  717.     authnone_destroy
  718. };
  719.  
  720. static struct authnone_private {
  721.     AUTH    no_client;
  722.     char    marshalled_client[MAX_MARSHEL_SIZE];
  723.     u_int    mcnt;
  724. } *authnone_private;
  725.  
  726. AUTH *
  727. authnone_create()
  728. {
  729.     register struct authnone_private *ap = authnone_private;
  730.     XDR xdr_stream;
  731.     register XDR *xdrs;
  732.  
  733.     if (ap == 0) {
  734.         ap = (struct authnone_private *)calloc(1, sizeof (*ap));
  735.         if (ap == 0)
  736.             return (0);
  737.         authnone_private = ap;
  738.     }
  739.     if (!ap->mcnt) {
  740.         ap->no_client.ah_cred = ap->no_client.ah_verf = _null_auth;
  741.         ap->no_client.ah_ops = &ops;
  742.         xdrs = &xdr_stream;
  743.         xdrmem_create(xdrs, ap->marshalled_client, (u_int)MAX_MARSHEL_SIZE,
  744.             XDR_ENCODE);
  745.         (void)xdr_opaque_auth(xdrs, &ap->no_client.ah_cred);
  746.         (void)xdr_opaque_auth(xdrs, &ap->no_client.ah_verf);
  747.         ap->mcnt = XDR_GETPOS(xdrs);
  748.         XDR_DESTROY(xdrs);
  749.     }
  750.     return (&ap->no_client);
  751. }
  752.  
  753. /*ARGSUSED*/
  754. static bool_t
  755. authnone_marshal(client, xdrs)
  756.     AUTH *client;
  757.     XDR *xdrs;
  758. {
  759.     register struct authnone_private *ap = authnone_private;
  760.  
  761.     if (ap == 0)
  762.         return (0);
  763.     return ((*xdrs->x_ops->x_putbytes)(xdrs,
  764.         ap->marshalled_client, ap->mcnt));
  765. }
  766.  
  767. static void 
  768. authnone_verf()
  769. {
  770. }
  771.  
  772. static bool_t
  773. authnone_validate()
  774. {
  775.  
  776.     return (TRUE);
  777. }
  778.  
  779. static bool_t
  780. authnone_refresh()
  781. {
  782.  
  783.     return (FALSE);
  784. }
  785.  
  786. static void
  787. authnone_destroy()
  788. {
  789. }
  790. Funky_Stuff
  791. len=`wc -c < auth_none.c`
  792. if [ $len !=     3296 ] ; then
  793.   echo error: auth_none.c was $len bytes long, should have been     3296
  794. fi
  795. echo x - auth_unix.c
  796. cat > auth_unix.c <<'Funky_Stuff'
  797. /* @(#)auth_unix.c    1.1 87/11/04 3.9 RPCSRC */
  798. /*
  799.  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  800.  * unrestricted use provided that this legend is included on all tape
  801.  * media and as a part of the software program in whole or part.  Users
  802.  * may copy or modify Sun RPC without charge, but are not authorized
  803.  * to license or distribute it to anyone else except as part of a product or
  804.  * program developed by the user.
  805.  * 
  806.  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  807.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  808.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  809.  * 
  810.  * Sun RPC is provided with no support and without any obligation on the
  811.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  812.  * modification or enhancement.
  813.  * 
  814.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  815.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  816.  * OR ANY PART THEREOF.
  817.  * 
  818.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  819.  * or profits or other special, indirect and consequential damages, even if
  820.  * Sun has been advised of the possibility of such damages.
  821.  * 
  822.  * Sun Microsystems, Inc.
  823.  * 2550 Garcia Avenue
  824.  * Mountain View, California  94043
  825.  */
  826. #if !defined(lint) && defined(SCCSIDS)
  827. static char sccsid[] = "@(#)auth_unix.c 1.19 87/08/11 Copyr 1984 Sun Micro";
  828. #endif
  829.  
  830. /*
  831.  * auth_unix.c, Implements UNIX style authentication parameters. 
  832.  *  
  833.  * Copyright (C) 1984, Sun Microsystems, Inc. 
  834.  *
  835.  * The system is very weak.  The client uses no encryption for it's
  836.  * credentials and only sends null verifiers.  The server sends backs
  837.  * null verifiers or optionally a verifier that suggests a new short hand
  838.  * for the credentials.
  839.  *
  840.  */
  841.  
  842. #include <stdio.h>
  843. #include <sys/time.h>
  844.  
  845. #include <rpc/types.h>
  846. #include <rpc/xdr.h>
  847. #include <rpc/auth.h>
  848. #include <rpc/auth_unix.h>
  849.  
  850. /*
  851.  * Unix authenticator operations vector
  852.  */
  853. static void    authunix_nextverf();
  854. static bool_t    authunix_marshal();
  855. static bool_t    authunix_validate();
  856. static bool_t    authunix_refresh();
  857. static void    authunix_destroy();
  858.  
  859. static struct auth_ops auth_unix_ops = {
  860.     authunix_nextverf,
  861.     authunix_marshal,
  862.     authunix_validate,
  863.     authunix_refresh,
  864.     authunix_destroy
  865. };
  866.  
  867. /*
  868.  * This struct is pointed to by the ah_private field of an auth_handle.
  869.  */
  870. struct audata {
  871.     struct opaque_auth    au_origcred;    /* original credentials */
  872.     struct opaque_auth    au_shcred;    /* short hand cred */
  873.     u_long            au_shfaults;    /* short hand cache faults */
  874.     char            au_marshed[MAX_AUTH_BYTES];
  875.     u_int            au_mpos;    /* xdr pos at end of marshed */
  876. };
  877. #define    AUTH_PRIVATE(auth)    ((struct audata *)auth->ah_private)
  878.  
  879. static bool_t marshal_new_auth();
  880.  
  881.  
  882. /*
  883.  * Create a unix style authenticator.
  884.  * Returns an auth handle with the given stuff in it.
  885.  */
  886. AUTH *
  887. authunix_create(machname, uid, gid, len, aup_gids)
  888.     char *machname;
  889.     int uid;
  890.     int gid;
  891.     register int len;
  892.     int *aup_gids;
  893. {
  894.     struct authunix_parms aup;
  895.     char mymem[MAX_AUTH_BYTES];
  896.     struct timeval now;
  897.     XDR xdrs;
  898.     register AUTH *auth;
  899.     register struct audata *au;
  900.  
  901.     /*
  902.      * Allocate and set up auth handle
  903.      */
  904.     auth = (AUTH *)mem_alloc(sizeof(*auth));
  905. #ifndef KERNEL
  906.     if (auth == NULL) {
  907.         (void)fprintf(stderr, "authunix_create: out of memory\n");
  908.         return (NULL);
  909.     }
  910. #endif
  911.     au = (struct audata *)mem_alloc(sizeof(*au));
  912. #ifndef KERNEL
  913.     if (au == NULL) {
  914.         (void)fprintf(stderr, "authunix_create: out of memory\n");
  915.         return (NULL);
  916.     }
  917. #endif
  918.     auth->ah_ops = &auth_unix_ops;
  919.     auth->ah_private = (caddr_t)au;
  920.     auth->ah_verf = au->au_shcred = _null_auth;
  921.     au->au_shfaults = 0;
  922.  
  923.     /*
  924.      * fill in param struct from the given params
  925.      */
  926.     (void)gettimeofday(&now,  (struct timezone *)0);
  927.     aup.aup_time = now.tv_sec;
  928.     aup.aup_machname = machname;
  929.     aup.aup_uid = uid;
  930.     aup.aup_gid = gid;
  931.     aup.aup_len = (u_int)len;
  932.     aup.aup_gids = aup_gids;
  933.  
  934.     /*
  935.      * Serialize the parameters into origcred
  936.      */
  937.     xdrmem_create(&xdrs, mymem, MAX_AUTH_BYTES, XDR_ENCODE);
  938.     if (! xdr_authunix_parms(&xdrs, &aup)) 
  939.         abort();
  940.     au->au_origcred.oa_length = len = XDR_GETPOS(&xdrs);
  941.     au->au_origcred.oa_flavor = AUTH_UNIX;
  942. #ifdef KERNEL
  943.     au->au_origcred.oa_base = mem_alloc((u_int) len);
  944. #else
  945.     if ((au->au_origcred.oa_base = mem_alloc((u_int) len)) == NULL) {
  946.         (void)fprintf(stderr, "authunix_create: out of memory\n");
  947.         return (NULL);
  948.     }
  949. #endif
  950.     bcopy(mymem, au->au_origcred.oa_base, (u_int)len);
  951.  
  952.     /*
  953.      * set auth handle to reflect new cred.
  954.      */
  955.     auth->ah_cred = au->au_origcred;
  956.     marshal_new_auth(auth);
  957.     return (auth);
  958. }
  959.  
  960. /*
  961.  * Returns an auth handle with parameters determined by doing lots of
  962.  * syscalls.
  963.  */
  964. AUTH *
  965. authunix_create_default()
  966. {
  967.     register int len;
  968.     char machname[MAX_MACHINE_NAME + 1];
  969.     register int uid;
  970.     register int gid;
  971.     int gids[NGRPS];
  972.  
  973.     if (gethostname(machname, MAX_MACHINE_NAME) == -1)
  974.         abort();
  975.     machname[MAX_MACHINE_NAME] = 0;
  976.     uid = geteuid();
  977.     gid = getegid();
  978.     if ((len = getgroups(NGRPS, gids)) < 0)
  979.         abort();
  980.     return (authunix_create(machname, uid, gid, len, gids));
  981. }
  982.  
  983. /*
  984.  * authunix operations
  985.  */
  986.  
  987. static void
  988. authunix_nextverf(auth)
  989.     AUTH *auth;
  990. {
  991.     /* no action necessary */
  992. }
  993.  
  994. static bool_t
  995. authunix_marshal(auth, xdrs)
  996.     AUTH *auth;
  997.     XDR *xdrs;
  998. {
  999.     register struct audata *au = AUTH_PRIVATE(auth);
  1000.  
  1001.     return (XDR_PUTBYTES(xdrs, au->au_marshed, au->au_mpos));
  1002. }
  1003.  
  1004. static bool_t
  1005. authunix_validate(auth, verf)
  1006.     register AUTH *auth;
  1007.     struct opaque_auth verf;
  1008. {
  1009.     register struct audata *au;
  1010.     XDR xdrs;
  1011.  
  1012.     if (verf.oa_flavor == AUTH_SHORT) {
  1013.         au = AUTH_PRIVATE(auth);
  1014.         xdrmem_create(&xdrs, verf.oa_base, verf.oa_length, XDR_DECODE);
  1015.  
  1016.         if (au->au_shcred.oa_base != NULL) {
  1017.             mem_free(au->au_shcred.oa_base,
  1018.                 au->au_shcred.oa_length);
  1019.             au->au_shcred.oa_base = NULL;
  1020.         }
  1021.         if (xdr_opaque_auth(&xdrs, &au->au_shcred)) {
  1022.             auth->ah_cred = au->au_shcred;
  1023.         } else {
  1024.             xdrs.x_op = XDR_FREE;
  1025.             (void)xdr_opaque_auth(&xdrs, &au->au_shcred);
  1026.             au->au_shcred.oa_base = NULL;
  1027.             auth->ah_cred = au->au_origcred;
  1028.         }
  1029.         marshal_new_auth(auth);
  1030.     }
  1031.     return (TRUE);
  1032. }
  1033.  
  1034. static bool_t
  1035. authunix_refresh(auth)
  1036.     register AUTH *auth;
  1037. {
  1038.     register struct audata *au = AUTH_PRIVATE(auth);
  1039.     struct authunix_parms aup;
  1040.     struct timeval now;
  1041.     XDR xdrs;
  1042.     register int stat;
  1043.  
  1044.     if (auth->ah_cred.oa_base == au->au_origcred.oa_base) {
  1045.         /* there is no hope.  Punt */
  1046.         return (FALSE);
  1047.     }
  1048.     au->au_shfaults ++;
  1049.  
  1050.     /* first deserialize the creds back into a struct authunix_parms */
  1051.     aup.aup_machname = NULL;
  1052.     aup.aup_gids = (int *)NULL;
  1053.     xdrmem_create(&xdrs, au->au_origcred.oa_base,
  1054.         au->au_origcred.oa_length, XDR_DECODE);
  1055.     stat = xdr_authunix_parms(&xdrs, &aup);
  1056.     if (! stat) 
  1057.         goto done;
  1058.  
  1059.     /* update the time and serialize in place */
  1060.     (void)gettimeofday(&now, (struct timezone *)0);
  1061.     aup.aup_time = now.tv_sec;
  1062.     xdrs.x_op = XDR_ENCODE;
  1063.     XDR_SETPOS(&xdrs, 0);
  1064.     stat = xdr_authunix_parms(&xdrs, &aup);
  1065.     if (! stat)
  1066.         goto done;
  1067.     auth->ah_cred = au->au_origcred;
  1068.     marshal_new_auth(auth);
  1069. done:
  1070.     /* free the struct authunix_parms created by deserializing */
  1071.     xdrs.x_op = XDR_FREE;
  1072.     (void)xdr_authunix_parms(&xdrs, &aup);
  1073.     XDR_DESTROY(&xdrs);
  1074.     return (stat);
  1075. }
  1076.  
  1077. static void
  1078. authunix_destroy(auth)
  1079.     register AUTH *auth;
  1080. {
  1081.     register struct audata *au = AUTH_PRIVATE(auth);
  1082.  
  1083.     mem_free(au->au_origcred.oa_base, au->au_origcred.oa_length);
  1084.  
  1085.     if (au->au_shcred.oa_base != NULL)
  1086.         mem_free(au->au_shcred.oa_base, au->au_shcred.oa_length);
  1087.  
  1088.     mem_free(auth->ah_private, sizeof(struct audata));
  1089.  
  1090.     if (auth->ah_verf.oa_base != NULL)
  1091.         mem_free(auth->ah_verf.oa_base, auth->ah_verf.oa_length);
  1092.  
  1093.     mem_free((caddr_t)auth, sizeof(*auth));
  1094. }
  1095.  
  1096. /*
  1097.  * Marshals (pre-serializes) an auth struct.
  1098.  * sets private data, au_marshed and au_mpos
  1099.  */
  1100. static bool_t
  1101. marshal_new_auth(auth)
  1102.     register AUTH *auth;
  1103. {
  1104.     XDR        xdr_stream;
  1105.     register XDR    *xdrs = &xdr_stream;
  1106.     register struct audata *au = AUTH_PRIVATE(auth);
  1107.  
  1108.     xdrmem_create(xdrs, au->au_marshed, MAX_AUTH_BYTES, XDR_ENCODE);
  1109.     if ((! xdr_opaque_auth(xdrs, &(auth->ah_cred))) ||
  1110.         (! xdr_opaque_auth(xdrs, &(auth->ah_verf)))) {
  1111.         perror("auth_none.c - Fatal marshalling problem");
  1112.     } else {
  1113.         au->au_mpos = XDR_GETPOS(xdrs);
  1114.     }
  1115.     XDR_DESTROY(xdrs);
  1116. }
  1117. Funky_Stuff
  1118. len=`wc -c < auth_unix.c`
  1119. if [ $len !=     8130 ] ; then
  1120.   echo error: auth_unix.c was $len bytes long, should have been     8130
  1121. fi
  1122. echo x - auth_unix.h
  1123. cat > auth_unix.h <<'Funky_Stuff'
  1124. /* @(#)auth_unix.h    1.1 87/11/04 3.9 RPCSRC */
  1125. /*
  1126.  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  1127.  * unrestricted use provided that this legend is included on all tape
  1128.  * media and as a part of the software program in whole or part.  Users
  1129.  * may copy or modify Sun RPC without charge, but are not authorized
  1130.  * to license or distribute it to anyone else except as part of a product or
  1131.  * program developed by the user.
  1132.  * 
  1133.  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  1134.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  1135.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  1136.  * 
  1137.  * Sun RPC is provided with no support and without any obligation on the
  1138.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  1139.  * modification or enhancement.
  1140.  * 
  1141.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  1142.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  1143.  * OR ANY PART THEREOF.
  1144.  * 
  1145.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  1146.  * or profits or other special, indirect and consequential damages, even if
  1147.  * Sun has been advised of the possibility of such damages.
  1148.  * 
  1149.  * Sun Microsystems, Inc.
  1150.  * 2550 Garcia Avenue
  1151.  * Mountain View, California  94043
  1152.  */
  1153. /*      @(#)auth_unix.h 1.5 86/07/16 SMI      */
  1154.  
  1155. /*
  1156.  * auth_unix.h, Protocol for UNIX style authentication parameters for RPC
  1157.  *
  1158.  * Copyright (C) 1984, Sun Microsystems, Inc.
  1159.  */
  1160.  
  1161. /*
  1162.  * The system is very weak.  The client uses no encryption for  it
  1163.  * credentials and only sends null verifiers.  The server sends backs
  1164.  * null verifiers or optionally a verifier that suggests a new short hand
  1165.  * for the credentials.
  1166.  */
  1167.  
  1168. /* The machine name is part of a credential; it may not exceed 255 bytes */
  1169. #define MAX_MACHINE_NAME 255
  1170.  
  1171. /* gids compose part of a credential; there may not be more than 10 of them */
  1172. #define NGRPS 8
  1173.  
  1174. /*
  1175.  * Unix style credentials.
  1176.  */
  1177. struct authunix_parms {
  1178.     u_long     aup_time;
  1179.     char    *aup_machname;
  1180.     int     aup_uid;
  1181.     int     aup_gid;
  1182.     u_int     aup_len;
  1183.     int    *aup_gids;
  1184. };
  1185.  
  1186. extern bool_t xdr_authunix_parms();
  1187.  
  1188. /* 
  1189.  * If a response verifier has flavor AUTH_SHORT, 
  1190.  * then the body of the response verifier encapsulates the following structure;
  1191.  * again it is serialized in the obvious fashion.
  1192.  */
  1193. struct short_hand_verf {
  1194.     struct opaque_auth new_cred;
  1195. };
  1196. Funky_Stuff
  1197. len=`wc -c < auth_unix.h`
  1198. if [ $len !=     2389 ] ; then
  1199.   echo error: auth_unix.h was $len bytes long, should have been     2389
  1200. fi
  1201. echo x - authunix_prot.c
  1202. cat > authunix_prot.c <<'Funky_Stuff'
  1203. /* @(#)authunix_prot.c    1.1 87/11/04 3.9 RPCSRC */
  1204. /*
  1205.  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  1206.  * unrestricted use provided that this legend is included on all tape
  1207.  * media and as a part of the software program in whole or part.  Users
  1208.  * may copy or modify Sun RPC without charge, but are not authorized
  1209.  * to license or distribute it to anyone else except as part of a product or
  1210.  * program developed by the user.
  1211.  * 
  1212.  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  1213.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  1214.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  1215.  * 
  1216.  * Sun RPC is provided with no support and without any obligation on the
  1217.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  1218.  * modification or enhancement.
  1219.  * 
  1220.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  1221.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  1222.  * OR ANY PART THEREOF.
  1223.  * 
  1224.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  1225.  * or profits or other special, indirect and consequential damages, even if
  1226.  * Sun has been advised of the possibility of such damages.
  1227.  * 
  1228.  * Sun Microsystems, Inc.
  1229.  * 2550 Garcia Avenue
  1230.  * Mountain View, California  94043
  1231.  */
  1232. #if !defined(lint) && defined(SCCSIDS)
  1233. static char sccsid[] = "@(#)authunix_prot.c 1.15 87/08/11 Copyr 1984 Sun Micro";
  1234. #endif
  1235.  
  1236. /*
  1237.  * authunix_prot.c
  1238.  * XDR for UNIX style authentication parameters for RPC
  1239.  *
  1240.  * Copyright (C) 1984, Sun Microsystems, Inc.
  1241.  */
  1242.  
  1243.  
  1244. #include <rpc/types.h>
  1245. #include <rpc/xdr.h>
  1246. #include <rpc/auth.h>
  1247. #include <rpc/auth_unix.h>
  1248.  
  1249. /*
  1250.  * XDR for unix authentication parameters.
  1251.  */
  1252. bool_t
  1253. xdr_authunix_parms(xdrs, p)
  1254.     register XDR *xdrs;
  1255.     register struct authunix_parms *p;
  1256. {
  1257.  
  1258.     if (xdr_u_long(xdrs, &(p->aup_time))
  1259.         && xdr_string(xdrs, &(p->aup_machname), MAX_MACHINE_NAME)
  1260.         && xdr_int(xdrs, &(p->aup_uid))
  1261.         && xdr_int(xdrs, &(p->aup_gid))
  1262.         && xdr_array(xdrs, (caddr_t *)&(p->aup_gids),
  1263.             &(p->aup_len), NGRPS, sizeof(int), xdr_int) ) {
  1264.         return (TRUE);
  1265.     }
  1266.     return (FALSE);
  1267. }
  1268.  
  1269. Funky_Stuff
  1270. len=`wc -c < authunix_prot.c`
  1271. if [ $len !=     2139 ] ; then
  1272.   echo error: authunix_prot.c was $len bytes long, should have been     2139
  1273. fi
  1274. echo x - bindresvport.c
  1275. cat > bindresvport.c <<'Funky_Stuff'
  1276. /* @(#)bindresvport.c    1.1 87/11/04 3.9 RPCSRC */
  1277. /*
  1278.  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  1279.  * unrestricted use provided that this legend is included on all tape
  1280.  * media and as a part of the software program in whole or part.  Users
  1281.  * may copy or modify Sun RPC without charge, but are not authorized
  1282.  * to license or distribute it to anyone else except as part of a product or
  1283.  * program developed by the user.
  1284.  * 
  1285.  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  1286.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  1287.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  1288.  * 
  1289.  * Sun RPC is provided with no support and without any obligation on the
  1290.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  1291.  * modification or enhancement.
  1292.  * 
  1293.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  1294.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  1295.  * OR ANY PART THEREOF.
  1296.  * 
  1297.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  1298.  * or profits or other special, indirect and consequential damages, even if
  1299.  * Sun has been advised of the possibility of such damages.
  1300.  * 
  1301.  * Sun Microsystems, Inc.
  1302.  * 2550 Garcia Avenue
  1303.  * Mountain View, California  94043
  1304.  */
  1305. #if !defined(lint) && defined(SCCSIDS)
  1306. static  char sccsid[] = "@(#)bindresvport.c 1.6 87/09/23 SMI";
  1307. #endif
  1308.  
  1309. /*
  1310.  * Copyright (c) 1987 by Sun Microsystems, Inc.
  1311.  */
  1312.  
  1313. #include <sys/types.h>
  1314. #include <sys/errno.h>
  1315. #include <sys/socket.h>
  1316. #include <netinet/in.h>
  1317.  
  1318. /*
  1319.  * Bind a socket to a privileged IP port
  1320.  */
  1321. bindresvport(sd, sin)
  1322.     int sd;
  1323.     struct sockaddr_in *sin;
  1324. {
  1325.     int res;
  1326.     static short port;
  1327.     struct sockaddr_in myaddr;
  1328.     extern int errno;
  1329.     int i;
  1330.  
  1331. #define STARTPORT 600
  1332. #define ENDPORT (IPPORT_RESERVED - 1)
  1333. #define NPORTS    (ENDPORT - STARTPORT + 1)
  1334.  
  1335.     if (sin == (struct sockaddr_in *)0) {
  1336.         sin = &myaddr;
  1337.         bzero(sin, sizeof (*sin));
  1338.         sin->sin_family = AF_INET;
  1339.     } else if (sin->sin_family != AF_INET) {
  1340.         errno = EPFNOSUPPORT;
  1341.         return (-1);
  1342.     }
  1343.     if (port == 0) {
  1344.         port = (getpid() % NPORTS) + STARTPORT;
  1345.     }
  1346.     for (i = 0; i < NPORTS; i++) {
  1347.         sin->sin_port = htons(port++);
  1348.         if (port > ENDPORT) {
  1349.             port = STARTPORT;
  1350.         }
  1351.         res = bind(sd, sin, sizeof(struct sockaddr_in));
  1352.         if (res == 0) {
  1353.             return (0);
  1354.         }
  1355.         if ((res < 0) && (errno == EACCES)) {
  1356.             return (-1);
  1357.         }
  1358.     }
  1359.     return (-1);
  1360. }
  1361. Funky_Stuff
  1362. len=`wc -c < bindresvport.c`
  1363. if [ $len !=     2416 ] ; then
  1364.   echo error: bindresvport.c was $len bytes long, should have been     2416
  1365. fi
  1366. echo x - clnt.h
  1367. cat > clnt.h <<'Funky_Stuff'
  1368. /* @(#)clnt.h    1.1 87/11/04 3.9 RPCSRC */
  1369. /*
  1370.  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  1371.  * unrestricted use provided that this legend is included on all tape
  1372.  * media and as a part of the software program in whole or part.  Users
  1373.  * may copy or modify Sun RPC without charge, but are not authorized
  1374.  * to license or distribute it to anyone else except as part of a product or
  1375.  * program developed by the user.
  1376.  * 
  1377.  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  1378.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  1379.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  1380.  * 
  1381.  * Sun RPC is provided with no support and without any obligation on the
  1382.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  1383.  * modification or enhancement.
  1384.  * 
  1385.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  1386.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  1387.  * OR ANY PART THEREOF.
  1388.  * 
  1389.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  1390.  * or profits or other special, indirect and consequential damages, even if
  1391.  * Sun has been advised of the possibility of such damages.
  1392.  * 
  1393.  * Sun Microsystems, Inc.
  1394.  * 2550 Garcia Avenue
  1395.  * Mountain View, California  94043
  1396.  */
  1397. /*    @(#)clnt.h 1.30 87/07/14 SMI      */
  1398.  
  1399. /*
  1400.  * clnt.h - Client side remote procedure call interface.
  1401.  *
  1402.  * Copyright (C) 1984, Sun Microsystems, Inc.
  1403.  */
  1404.  
  1405. #ifndef _CLNT_
  1406. #define _CLNT_
  1407.  
  1408. /*
  1409.  * Rpc calls return an enum clnt_stat.  This should be looked at more,
  1410.  * since each implementation is required to live with this (implementation
  1411.  * independent) list of errors.
  1412.  */
  1413. enum clnt_stat {
  1414.     RPC_SUCCESS=0,            /* call succeeded */
  1415.     /*
  1416.      * local errors
  1417.      */
  1418.     RPC_CANTENCODEARGS=1,        /* can't encode arguments */
  1419.     RPC_CANTDECODERES=2,        /* can't decode results */
  1420.     RPC_CANTSEND=3,            /* failure in sending call */
  1421.     RPC_CANTRECV=4,            /* failure in receiving result */
  1422.     RPC_TIMEDOUT=5,            /* call timed out */
  1423.     /*
  1424.      * remote errors
  1425.      */
  1426.     RPC_VERSMISMATCH=6,        /* rpc versions not compatible */
  1427.     RPC_AUTHERROR=7,        /* authentication error */
  1428.     RPC_PROGUNAVAIL=8,        /* program not available */
  1429.     RPC_PROGVERSMISMATCH=9,        /* program version mismatched */
  1430.     RPC_PROCUNAVAIL=10,        /* procedure unavailable */
  1431.     RPC_CANTDECODEARGS=11,        /* decode arguments error */
  1432.     RPC_SYSTEMERROR=12,        /* generic "other problem" */
  1433.  
  1434.     /*
  1435.      * callrpc & clnt_create errors
  1436.      */
  1437.     RPC_UNKNOWNHOST=13,        /* unknown host name */
  1438.     RPC_UNKNOWNPROTO=17,        /* unkown protocol */
  1439.  
  1440.     /*
  1441.      * _ create errors
  1442.      */
  1443.     RPC_PMAPFAILURE=14,        /* the pmapper failed in its call */
  1444.     RPC_PROGNOTREGISTERED=15,    /* remote program is not registered */
  1445.     /*
  1446.      * unspecified error
  1447.      */
  1448.     RPC_FAILED=16
  1449. };
  1450.  
  1451.  
  1452. /*
  1453.  * Error info.
  1454.  */
  1455. struct rpc_err {
  1456.     enum clnt_stat re_status;
  1457.     union {
  1458.         int RE_errno;        /* realated system error */
  1459.         enum auth_stat RE_why;    /* why the auth error occurred */
  1460.         struct {
  1461.             u_long low;    /* lowest verion supported */
  1462.             u_long high;    /* highest verion supported */
  1463.         } RE_vers;
  1464.         struct {        /* maybe meaningful if RPC_FAILED */
  1465.             long s1;
  1466.             long s2;
  1467.         } RE_lb;        /* life boot & debugging only */
  1468.     } ru;
  1469. #define    re_errno    ru.RE_errno
  1470. #define    re_why        ru.RE_why
  1471. #define    re_vers        ru.RE_vers
  1472. #define    re_lb        ru.RE_lb
  1473. };
  1474.  
  1475.  
  1476. /*
  1477.  * Client rpc handle.
  1478.  * Created by individual implementations, see e.g. rpc_udp.c.
  1479.  * Client is responsible for initializing auth, see e.g. auth_none.c.
  1480.  */
  1481. typedef struct {
  1482.     AUTH    *cl_auth;            /* authenticator */
  1483.     struct clnt_ops {
  1484.         enum clnt_stat    (*cl_call)();    /* call remote procedure */
  1485.         void        (*cl_abort)();    /* abort a call */
  1486.         void        (*cl_geterr)();    /* get specific error code */
  1487.         bool_t        (*cl_freeres)(); /* frees results */
  1488.         void        (*cl_destroy)();/* destroy this structure */
  1489.         bool_t          (*cl_control)();/* the ioctl() of rpc */
  1490.     } *cl_ops;
  1491.     caddr_t            cl_private;    /* private stuff */
  1492. } CLIENT;
  1493.  
  1494.  
  1495. /*
  1496.  * client side rpc interface ops
  1497.  *
  1498.  * Parameter types are:
  1499.  *
  1500.  */
  1501.  
  1502. /*
  1503.  * enum clnt_stat
  1504.  * CLNT_CALL(rh, proc, xargs, argsp, xres, resp, timeout)
  1505.  *     CLIENT *rh;
  1506.  *    u_long proc;
  1507.  *    xdrproc_t xargs;
  1508.  *    caddr_t argsp;
  1509.  *    xdrproc_t xres;
  1510.  *    caddr_t resp;
  1511.  *    struct timeval timeout;
  1512.  */
  1513. #define    CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs)    \
  1514.     ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs))
  1515. #define    clnt_call(rh, proc, xargs, argsp, xres, resp, secs)    \
  1516.     ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs))
  1517.  
  1518. /*
  1519.  * void
  1520.  * CLNT_ABORT(rh);
  1521.  *     CLIENT *rh;
  1522.  */
  1523. #define    CLNT_ABORT(rh)    ((*(rh)->cl_ops->cl_abort)(rh))
  1524. #define    clnt_abort(rh)    ((*(rh)->cl_ops->cl_abort)(rh))
  1525.  
  1526. /*
  1527.  * struct rpc_err
  1528.  * CLNT_GETERR(rh);
  1529.  *     CLIENT *rh;
  1530.  */
  1531. #define    CLNT_GETERR(rh,errp)    ((*(rh)->cl_ops->cl_geterr)(rh, errp))
  1532. #define    clnt_geterr(rh,errp)    ((*(rh)->cl_ops->cl_geterr)(rh, errp))
  1533.  
  1534.  
  1535. /*
  1536.  * bool_t
  1537.  * CLNT_FREERES(rh, xres, resp);
  1538.  *     CLIENT *rh;
  1539.  *    xdrproc_t xres;
  1540.  *    caddr_t resp;
  1541.  */
  1542. #define    CLNT_FREERES(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
  1543. #define    clnt_freeres(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
  1544.  
  1545. /*
  1546.  * bool_t
  1547.  * CLNT_CONTROL(cl, request, info)
  1548.  *      CLIENT *cl;
  1549.  *      u_int request;
  1550.  *      char *info;
  1551.  */
  1552. #define    CLNT_CONTROL(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
  1553. #define    clnt_control(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
  1554.  
  1555. /*
  1556.  * control operations that apply to both udp and tcp transports
  1557.  */
  1558. #define CLSET_TIMEOUT       1   /* set timeout (timeval) */
  1559. #define CLGET_TIMEOUT       2   /* get timeout (timeval) */
  1560. #define CLGET_SERVER_ADDR   3   /* get server's address (sockaddr) */
  1561. /*
  1562.  * udp only control operations
  1563.  */
  1564. #define CLSET_RETRY_TIMEOUT 4   /* set retry timeout (timeval) */
  1565. #define CLGET_RETRY_TIMEOUT 5   /* get retry timeout (timeval) */
  1566.  
  1567. /*
  1568.  * void
  1569.  * CLNT_DESTROY(rh);
  1570.  *     CLIENT *rh;
  1571.  */
  1572. #define    CLNT_DESTROY(rh)    ((*(rh)->cl_ops->cl_destroy)(rh))
  1573. #define    clnt_destroy(rh)    ((*(rh)->cl_ops->cl_destroy)(rh))
  1574.  
  1575.  
  1576. /*
  1577.  * RPCTEST is a test program which is accessable on every rpc
  1578.  * transport/port.  It is used for testing, performance evaluation,
  1579.  * and network administration.
  1580.  */
  1581.  
  1582. #define RPCTEST_PROGRAM        ((u_long)1)
  1583. #define RPCTEST_VERSION        ((u_long)1)
  1584. #define RPCTEST_NULL_PROC    ((u_long)2)
  1585. #define RPCTEST_NULL_BATCH_PROC    ((u_long)3)
  1586.  
  1587. /*
  1588.  * By convention, procedure 0 takes null arguments and returns them
  1589.  */
  1590.  
  1591. #define NULLPROC ((u_long)0)
  1592.  
  1593. /*
  1594.  * Below are the client handle creation routines for the various
  1595.  * implementations of client side rpc.  They can return NULL if a 
  1596.  * creation failure occurs.
  1597.  */
  1598.  
  1599. /*
  1600.  * Memory based rpc (for speed check and testing)
  1601.  * CLIENT *
  1602.  * clntraw_create(prog, vers)
  1603.  *    u_long prog;
  1604.  *    u_long vers;
  1605.  */
  1606. extern CLIENT *clntraw_create();
  1607.  
  1608.  
  1609. /*
  1610.  * Generic client creation routine. Supported protocols are "udp" and "tcp"
  1611.  */
  1612. extern CLIENT *
  1613. clnt_create(/*host, prog, vers, prot*/); /*
  1614.     char *host;     -- hostname
  1615.     u_long prog;    -- program number
  1616.     u_long vers;    -- version number
  1617.     char *prot;    -- protocol
  1618. */
  1619.  
  1620.     
  1621.     
  1622.  
  1623. /*
  1624.  * TCP based rpc
  1625.  * CLIENT *
  1626.  * clnttcp_create(raddr, prog, vers, sockp, sendsz, recvsz)
  1627.  *    struct sockaddr_in *raddr;
  1628.  *    u_long prog;
  1629.  *    u_long version;
  1630.  *    register int *sockp;
  1631.  *    u_int sendsz;
  1632.  *    u_int recvsz;
  1633.  */
  1634. extern CLIENT *clnttcp_create();
  1635.  
  1636. /*
  1637.  * UDP based rpc.
  1638.  * CLIENT *
  1639.  * clntudp_create(raddr, program, version, wait, sockp)
  1640.  *    struct sockaddr_in *raddr;
  1641.  *    u_long program;
  1642.  *    u_long version;
  1643.  *    struct timeval wait;
  1644.  *    int *sockp;
  1645.  *
  1646.  * Same as above, but you specify max packet sizes.
  1647.  * CLIENT *
  1648.  * clntudp_bufcreate(raddr, program, version, wait, sockp, sendsz, recvsz)
  1649.  *    struct sockaddr_in *raddr;
  1650.  *    u_long program;
  1651.  *    u_long version;
  1652.  *    struct timeval wait;
  1653.  *    int *sockp;
  1654.  *    u_int sendsz;
  1655.  *    u_int recvsz;
  1656.  */
  1657. extern CLIENT *clntudp_create();
  1658. extern CLIENT *clntudp_bufcreate();
  1659.  
  1660. /*
  1661.  * Print why creation failed
  1662.  */
  1663. void clnt_pcreateerror(/* char *msg */);    /* stderr */
  1664. char *clnt_spcreateerror(/* char *msg */);    /* string */
  1665.  
  1666. /*
  1667.  * Like clnt_perror(), but is more verbose in its output
  1668.  */ 
  1669. void clnt_perrno(/* enum clnt_stat num */);    /* stderr */
  1670.  
  1671. /*
  1672.  * Print an English error message, given the client error code
  1673.  */
  1674. void clnt_perror(/* CLIENT *clnt, char *msg */);     /* stderr */
  1675. char *clnt_sperror(/* CLIENT *clnt, char *msg */);    /* string */
  1676.  
  1677. /* 
  1678.  * If a creation fails, the following allows the user to figure out why.
  1679.  */
  1680. struct rpc_createerr {
  1681.     enum clnt_stat cf_stat;
  1682.     struct rpc_err cf_error; /* useful when cf_stat == RPC_PMAPFAILURE */
  1683. };
  1684.  
  1685. extern struct rpc_createerr rpc_createerr;
  1686.  
  1687.  
  1688.  
  1689. /*
  1690.  * Copy error message to buffer.
  1691.  */
  1692. char *clnt_sperrno(/* enum clnt_stat num */);    /* string */
  1693.  
  1694.  
  1695.  
  1696. #define UDPMSGSIZE    8800    /* rpc imposed limit on udp msg size */
  1697. #define RPCSMALLMSGSIZE    400    /* a more reasonable packet size */
  1698.  
  1699. #endif /*!_CLNT_*/
  1700. Funky_Stuff
  1701. len=`wc -c < clnt.h`
  1702. if [ $len !=     8731 ] ; then
  1703.   echo error: clnt.h was $len bytes long, should have been     8731
  1704. fi
  1705. echo x - clnt_generic.c
  1706. cat > clnt_generic.c <<'Funky_Stuff'
  1707. /* @(#)clnt_generic.c    1.1 87/11/04 3.9 RPCSRC */
  1708. /*
  1709.  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  1710.  * unrestricted use provided that this legend is included on all tape
  1711.  * media and as a part of the software program in whole or part.  Users
  1712.  * may copy or modify Sun RPC without charge, but are not authorized
  1713.  * to license or distribute it to anyone else except as part of a product or
  1714.  * program developed by the user.
  1715.  * 
  1716.  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  1717.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  1718.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  1719.  * 
  1720.  * Sun RPC is provided with no support and without any obligation on the
  1721.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  1722.  * modification or enhancement.
  1723.  * 
  1724.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  1725.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  1726.  * OR ANY PART THEREOF.
  1727.  * 
  1728.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  1729.  * or profits or other special, indirect and consequential damages, even if
  1730.  * Sun has been advised of the possibility of such damages.
  1731.  * 
  1732.  * Sun Microsystems, Inc.
  1733.  * 2550 Garcia Avenue
  1734.  * Mountain View, California  94043
  1735.  */
  1736. #if !defined(lint) && defined(SCCSIDS)
  1737. static char sccsid[] = "@(#)clnt_generic.c 1.4 87/08/11 (C) 1987 SMI";
  1738. #endif
  1739. /*
  1740.  * Copyright (C) 1987, Sun Microsystems, Inc.
  1741.  */
  1742. #include <rpc/rpc.h>
  1743. #include <sys/socket.h>
  1744. #include <sys/time.h>
  1745. #include <sys/errno.h>
  1746. #include <netdb.h>
  1747.  
  1748. /*
  1749.  * Generic client creation: takes (hostname, program-number, protocol) and
  1750.  * returns client handle. Default options are set, which the user can 
  1751.  * change using the rpc equivalent of ioctl()'s.
  1752.  */
  1753. CLIENT *
  1754. clnt_create(hostname, prog, vers, proto)
  1755.     char *hostname;
  1756.     unsigned prog;
  1757.     unsigned vers;
  1758.     char *proto;
  1759. {
  1760.     struct hostent *h;
  1761.     struct protoent *p;
  1762.     struct sockaddr_in sin;
  1763.     int sock;
  1764.     struct timeval tv;
  1765.     CLIENT *client;
  1766.  
  1767.     h = gethostbyname(hostname);
  1768.     if (h == NULL) {
  1769.         rpc_createerr.cf_stat = RPC_UNKNOWNHOST;
  1770.         return (NULL);
  1771.     }
  1772.     if (h->h_addrtype != AF_INET) {
  1773.         /*
  1774.          * Only support INET for now
  1775.          */
  1776.         rpc_createerr.cf_stat = RPC_SYSTEMERROR;
  1777.         rpc_createerr.cf_error.re_errno = EAFNOSUPPORT; 
  1778.         return (NULL);
  1779.     }
  1780.     sin.sin_family = h->h_addrtype;
  1781.     sin.sin_port = 0;
  1782.     bzero(sin.sin_zero, sizeof(sin.sin_zero));
  1783.     bcopy(h->h_addr, (char*)&sin.sin_addr, h->h_length);
  1784.     p = getprotobyname(proto);
  1785.     if (p == NULL) {
  1786.         rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
  1787.         rpc_createerr.cf_error.re_errno = EPFNOSUPPORT; 
  1788.         return (NULL);
  1789.     }
  1790.     sock = RPC_ANYSOCK;
  1791.     switch (p->p_proto) {
  1792.     case IPPROTO_UDP:
  1793.         tv.tv_sec = 5;
  1794.         tv.tv_usec = 0;
  1795.         client = clntudp_create(&sin, prog, vers, tv, &sock);
  1796.         if (client == NULL) {
  1797.             return (NULL);
  1798.         }
  1799.         tv.tv_sec = 25;
  1800.         clnt_control(client, CLSET_TIMEOUT, &tv);
  1801.         break;
  1802.     case IPPROTO_TCP:
  1803.         client = clnttcp_create(&sin, prog, vers, &sock, 0, 0);
  1804.         if (client == NULL) {
  1805.             return (NULL);
  1806.         }
  1807.         tv.tv_sec = 25;
  1808.         tv.tv_usec = 0;
  1809.         clnt_control(client, CLSET_TIMEOUT, &tv);
  1810.         break;
  1811.     default:
  1812.         rpc_createerr.cf_stat = RPC_SYSTEMERROR;
  1813.         rpc_createerr.cf_error.re_errno = EPFNOSUPPORT; 
  1814.         return (NULL);
  1815.     }
  1816.     return (client);
  1817. }
  1818. Funky_Stuff
  1819. len=`wc -c < clnt_generic.c`
  1820. if [ $len !=     3268 ] ; then
  1821.   echo error: clnt_generic.c was $len bytes long, should have been     3268
  1822. fi
  1823. echo x - clnt_perror.c
  1824. cat > clnt_perror.c <<'Funky_Stuff'
  1825. /* @(#)clnt_perror.c    1.1 87/11/04 3.9 RPCSRC */
  1826. /*
  1827.  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  1828.  * unrestricted use provided that this legend is included on all tape
  1829.  * media and as a part of the software program in whole or part.  Users
  1830.  * may copy or modify Sun RPC without charge, but are not authorized
  1831.  * to license or distribute it to anyone else except as part of a product or
  1832.  * program developed by the user.
  1833.  * 
  1834.  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  1835.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  1836.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  1837.  * 
  1838.  * Sun RPC is provided with no support and without any obligation on the
  1839.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  1840.  * modification or enhancement.
  1841.  * 
  1842.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  1843.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  1844.  * OR ANY PART THEREOF.
  1845.  * 
  1846.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  1847.  * or profits or other special, indirect and consequential damages, even if
  1848.  * Sun has been advised of the possibility of such damages.
  1849.  * 
  1850.  * Sun Microsystems, Inc.
  1851.  * 2550 Garcia Avenue
  1852.  * Mountain View, California  94043
  1853.  */
  1854. #if !defined(lint) && defined(SCCSIDS)
  1855. static char sccsid[] = "@(#)clnt_perror.c 1.15 87/10/07 Copyr 1984 Sun Micro";
  1856. #endif
  1857.  
  1858. /*
  1859.  * clnt_perror.c
  1860.  *
  1861.  * Copyright (C) 1984, Sun Microsystems, Inc.
  1862.  *
  1863.  */
  1864. #include <stdio.h>
  1865.  
  1866. #include <rpc/types.h>
  1867. #include <rpc/auth.h>
  1868. #include <rpc/clnt.h>
  1869.  
  1870. extern char *sys_errlist[];
  1871. extern char *sprintf();
  1872. static char *auth_errmsg();
  1873.  
  1874. extern char *strcpy();
  1875.  
  1876. static char *buf;
  1877.  
  1878. static char *
  1879. _buf()
  1880. {
  1881.  
  1882.     if (buf == 0)
  1883.         buf = (char *)malloc(256);
  1884.     return (buf);
  1885. }
  1886.  
  1887. /*
  1888.  * Print reply error info
  1889.  */
  1890. char *
  1891. clnt_sperror(rpch, s)
  1892.     CLIENT *rpch;
  1893.     char *s;
  1894. {
  1895.     struct rpc_err e;
  1896.     void clnt_perrno();
  1897.     char *err;
  1898.     char *str = _buf();
  1899.     char *strstart = str;
  1900.  
  1901.     if (str == 0)
  1902.         return (0);
  1903.     CLNT_GETERR(rpch, &e);
  1904.  
  1905.     (void) sprintf(str, "%s: ", s);  
  1906.     str += strlen(str);
  1907.  
  1908.     (void) strcpy(str, clnt_sperrno(e.re_status));  
  1909.     str += strlen(str);
  1910.  
  1911.     switch (e.re_status) {
  1912.     case RPC_SUCCESS:
  1913.     case RPC_CANTENCODEARGS:
  1914.     case RPC_CANTDECODERES:
  1915.     case RPC_TIMEDOUT:     
  1916.     case RPC_PROGUNAVAIL:
  1917.     case RPC_PROCUNAVAIL:
  1918.     case RPC_CANTDECODEARGS:
  1919.     case RPC_SYSTEMERROR:
  1920.     case RPC_UNKNOWNHOST:
  1921.     case RPC_UNKNOWNPROTO:
  1922.     case RPC_PMAPFAILURE:
  1923.     case RPC_PROGNOTREGISTERED:
  1924.     case RPC_FAILED:
  1925.         break;
  1926.  
  1927.     case RPC_CANTSEND:
  1928.     case RPC_CANTRECV:
  1929.         (void) sprintf(str, "; errno = %s",
  1930.             sys_errlist[e.re_errno]); 
  1931.         str += strlen(str);
  1932.         break;
  1933.  
  1934.     case RPC_VERSMISMATCH:
  1935.         (void) sprintf(str,
  1936.             "; low version = %lu, high version = %lu", 
  1937.             e.re_vers.low, e.re_vers.high);
  1938.         str += strlen(str);
  1939.         break;
  1940.  
  1941.     case RPC_AUTHERROR:
  1942.         err = auth_errmsg(e.re_why);
  1943.         (void) sprintf(str,"; why = ");
  1944.         str += strlen(str);
  1945.         if (err != NULL) {
  1946.             (void) sprintf(str, "%s",err);
  1947.         } else {
  1948.             (void) sprintf(str,
  1949.                 "(unknown authentication error - %d)",
  1950.                 (int) e.re_why);
  1951.         }
  1952.         str += strlen(str);
  1953.         break;
  1954.  
  1955.     case RPC_PROGVERSMISMATCH:
  1956.         (void) sprintf(str, 
  1957.             "; low version = %lu, high version = %lu", 
  1958.             e.re_vers.low, e.re_vers.high);
  1959.         str += strlen(str);
  1960.         break;
  1961.  
  1962.     default:    /* unknown */
  1963.         (void) sprintf(str, 
  1964.             "; s1 = %lu, s2 = %lu", 
  1965.             e.re_lb.s1, e.re_lb.s2);
  1966.         str += strlen(str);
  1967.         break;
  1968.     }
  1969.     (void) sprintf(str, "\n");
  1970.     return(strstart) ;
  1971. }
  1972.  
  1973. void
  1974. clnt_perror(rpch, s)
  1975.     CLIENT *rpch;
  1976.     char *s;
  1977. {
  1978.     (void) fprintf(stderr,"%s",clnt_sperror(rpch,s));
  1979. }
  1980.  
  1981.  
  1982. struct rpc_errtab {
  1983.     enum clnt_stat status;
  1984.     char *message;
  1985. };
  1986.  
  1987. static struct rpc_errtab  rpc_errlist[] = {
  1988.     { RPC_SUCCESS, 
  1989.         "RPC: Success" }, 
  1990.     { RPC_CANTENCODEARGS, 
  1991.         "RPC: Can't encode arguments" },
  1992.     { RPC_CANTDECODERES, 
  1993.         "RPC: Can't decode result" },
  1994.     { RPC_CANTSEND, 
  1995.         "RPC: Unable to send" },
  1996.     { RPC_CANTRECV, 
  1997.         "RPC: Unable to receive" },
  1998.     { RPC_TIMEDOUT, 
  1999.         "RPC: Timed out" },
  2000.     { RPC_VERSMISMATCH, 
  2001.         "RPC: Incompatible versions of RPC" },
  2002.     { RPC_AUTHERROR, 
  2003.         "RPC: Authentication error" },
  2004.     { RPC_PROGUNAVAIL, 
  2005.         "RPC: Program unavailable" },
  2006.     { RPC_PROGVERSMISMATCH, 
  2007.         "RPC: Program/version mismatch" },
  2008.     { RPC_PROCUNAVAIL, 
  2009.         "RPC: Procedure unavailable" },
  2010.     { RPC_CANTDECODEARGS, 
  2011.         "RPC: Server can't decode arguments" },
  2012.     { RPC_SYSTEMERROR, 
  2013.         "RPC: Remote system error" },
  2014.     { RPC_UNKNOWNHOST, 
  2015.         "RPC: Unknown host" },
  2016.     { RPC_UNKNOWNPROTO,
  2017.         "RPC: Unknown protocol" },
  2018.     { RPC_PMAPFAILURE, 
  2019.         "RPC: Port mapper failure" },
  2020.     { RPC_PROGNOTREGISTERED, 
  2021.         "RPC: Program not registered"},
  2022.     { RPC_FAILED, 
  2023.         "RPC: Failed (unspecified error)"}
  2024. };
  2025.  
  2026.  
  2027. /*
  2028.  * This interface for use by clntrpc
  2029.  */
  2030. char *
  2031. clnt_sperrno(stat)
  2032.     enum clnt_stat stat;
  2033. {
  2034.     int i;
  2035.  
  2036.     for (i = 0; i < sizeof(rpc_errlist)/sizeof(struct rpc_errtab); i++) {
  2037.         if (rpc_errlist[i].status == stat) {
  2038.             return (rpc_errlist[i].message);
  2039.         }
  2040.     }
  2041.     return ("RPC: (unknown error code)");
  2042. }
  2043.  
  2044. void
  2045. clnt_perrno(num)
  2046.     enum clnt_stat num;
  2047. {
  2048.     (void) fprintf(stderr,"%s",clnt_sperrno(num));
  2049. }
  2050.  
  2051.  
  2052. char *
  2053. clnt_spcreateerror(s)
  2054.     char *s;
  2055. {
  2056.     extern int sys_nerr;
  2057.     extern char *sys_errlist[];
  2058.     char *str = _buf();
  2059.  
  2060.     if (str == 0)
  2061.         return(0);
  2062.     (void) sprintf(str, "%s: ", s);
  2063.     (void) strcat(str, clnt_sperrno(rpc_createerr.cf_stat));
  2064.     switch (rpc_createerr.cf_stat) {
  2065.     case RPC_PMAPFAILURE:
  2066.         (void) strcat(str, " - ");
  2067.         (void) strcat(str,
  2068.             clnt_sperrno(rpc_createerr.cf_error.re_status));
  2069.         break;
  2070.  
  2071.     case RPC_SYSTEMERROR:
  2072.         (void) strcat(str, " - ");
  2073.         if (rpc_createerr.cf_error.re_errno > 0
  2074.             && rpc_createerr.cf_error.re_errno < sys_nerr)
  2075.             (void) strcat(str,
  2076.                 sys_errlist[rpc_createerr.cf_error.re_errno]);
  2077.         else
  2078.             (void) sprintf(&str[strlen(str)], "Error %d",
  2079.                 rpc_createerr.cf_error.re_errno);
  2080.         break;
  2081.     }
  2082.     (void) strcat(str, "\n");
  2083.     return (str);
  2084. }
  2085.  
  2086. void
  2087. clnt_pcreateerror(s)
  2088.     char *s;
  2089. {
  2090.     (void) fprintf(stderr,"%s",clnt_spcreateerror(s));
  2091. }
  2092.  
  2093. struct auth_errtab {
  2094.     enum auth_stat status;    
  2095.     char *message;
  2096. };
  2097.  
  2098. static struct auth_errtab auth_errlist[] = {
  2099.     { AUTH_OK,
  2100.         "Authentication OK" },
  2101.     { AUTH_BADCRED,
  2102.         "Invalid client credential" },
  2103.     { AUTH_REJECTEDCRED,
  2104.         "Server rejected credential" },
  2105.     { AUTH_BADVERF,
  2106.         "Invalid client verifier" },
  2107.     { AUTH_REJECTEDVERF,
  2108.         "Server rejected verifier" },
  2109.     { AUTH_TOOWEAK,
  2110.         "Client credential too weak" },
  2111.     { AUTH_INVALIDRESP,
  2112.         "Invalid server verifier" },
  2113.     { AUTH_FAILED,
  2114.         "Failed (unspecified error)" },
  2115. };
  2116.  
  2117. static char *
  2118. auth_errmsg(stat)
  2119.     enum auth_stat stat;
  2120. {
  2121.     int i;
  2122.  
  2123.     for (i = 0; i < sizeof(auth_errlist)/sizeof(struct auth_errtab); i++) {
  2124.         if (auth_errlist[i].status == stat) {
  2125.             return(auth_errlist[i].message);
  2126.         }
  2127.     }
  2128.     return(NULL);
  2129. }
  2130. Funky_Stuff
  2131. len=`wc -c < clnt_perror.c`
  2132. if [ $len !=     6675 ] ; then
  2133.   echo error: clnt_perror.c was $len bytes long, should have been     6675
  2134. fi
  2135. cd ..
  2136. echo more files to follow
  2137. exit
  2138.