xref: /freebsd/include/rpcsvc/ypxfrd.x (revision 9524e274b5484ac8b43bacd90d4029183ccf6476)
12f83f6d8SBill Paul /*
22f83f6d8SBill Paul  * Copyright (c) 1995, 1996
32f83f6d8SBill Paul  *	Bill Paul <wpaul@ctr.columbia.edu>.  All rights reserved.
42f83f6d8SBill Paul  *
52f83f6d8SBill Paul  * Redistribution and use in source and binary forms, with or without
62f83f6d8SBill Paul  * modification, are permitted provided that the following conditions
72f83f6d8SBill Paul  * are met:
82f83f6d8SBill Paul  * 1. Redistributions of source code must retain the above copyright
92f83f6d8SBill Paul  *    notice, this list of conditions and the following disclaimer.
102f83f6d8SBill Paul  * 2. Redistributions in binary form must reproduce the above copyright
112f83f6d8SBill Paul  *    notice, this list of conditions and the following disclaimer in the
122f83f6d8SBill Paul  *    documentation and/or other materials provided with the distribution.
132f83f6d8SBill Paul  * 3. All advertising materials mentioning features or use of this software
142f83f6d8SBill Paul  *    must display the following acknowledgement:
152f83f6d8SBill Paul  *	This product includes software developed by Bill Paul.
162f83f6d8SBill Paul  * 4. Neither the name of the author nor the names of any co-contributors
172f83f6d8SBill Paul  *    may be used to endorse or promote products derived from this software
182f83f6d8SBill Paul  *    without specific prior written permission.
192f83f6d8SBill Paul  *
202f83f6d8SBill Paul  * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
212f83f6d8SBill Paul  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
222f83f6d8SBill Paul  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
232f83f6d8SBill Paul  * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR CONTRIBUTORS BE LIABLE
242f83f6d8SBill Paul  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
252f83f6d8SBill Paul  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
262f83f6d8SBill Paul  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
272f83f6d8SBill Paul  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
282f83f6d8SBill Paul  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
292f83f6d8SBill Paul  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
302f83f6d8SBill Paul  * SUCH DAMAGE.
312f83f6d8SBill Paul  */
322f83f6d8SBill Paul 
332f83f6d8SBill Paul /*
342f83f6d8SBill Paul  * This protocol definition file describes a file transfer
352f83f6d8SBill Paul  * system used to very quickly move NIS maps from one host to
362f83f6d8SBill Paul  * another. This is similar to what Sun does with their ypxfrd
372f83f6d8SBill Paul  * protocol, but it must be stressed that this protocol is _NOT_
382f83f6d8SBill Paul  * compatible with Sun's. There are a couple of reasons for this:
392f83f6d8SBill Paul  *
402f83f6d8SBill Paul  * 1) Sun's protocol is proprietary. The protocol definition is
412f83f6d8SBill Paul  *    not freely available in any of the SunRPC source distributions,
422f83f6d8SBill Paul  *    even though the NIS v2 protocol is.
432f83f6d8SBill Paul  *
442f83f6d8SBill Paul  * 2) The idea here is to transfer entire raw files rather than
452f83f6d8SBill Paul  *    sending just the records. Sun uses ndbm for its NIS map files,
462f83f6d8SBill Paul  *    while FreeBSD uses Berkeley DB. Both are hash databases, but the
472f83f6d8SBill Paul  *    formats are incompatible, making it impossible for them to
482f83f6d8SBill Paul  *    use each others' files. Even if FreeBSD adopted ndbm for its
492f83f6d8SBill Paul  *    database format, FreeBSD/i386 is a little-endian OS and
502f83f6d8SBill Paul  *    SunOS/SPARC is big-endian; ndbm is byte-order sensitive and
512f83f6d8SBill Paul  *    not very smart about it, which means an attempt to read a
522f83f6d8SBill Paul  *    database on a little-endian box that was created on a big-endian
532f83f6d8SBill Paul  *    box (or vice-versa) can cause the ndbm code to eat itself.
542f83f6d8SBill Paul  *    Luckily, Berkeley DB is able to deal with this situation in
552f83f6d8SBill Paul  *    a more graceful manner.
562f83f6d8SBill Paul  *
572f83f6d8SBill Paul  * While the protocol is incompatible, the idea is the same: we just open
582f83f6d8SBill Paul  * up a TCP pipe to the client and transfer the raw map database
592f83f6d8SBill Paul  * from the master server to the slave. This is many times faster than
602f83f6d8SBill Paul  * the standard yppush/ypxfr transfer method since it saves us from
612f83f6d8SBill Paul  * having to recreate the map databases via the DB library each time.
622f83f6d8SBill Paul  * For example: creating a passwd database with 30,000 entries with yp_mkdb
632f83f6d8SBill Paul  * can take a couple of minutes, but to just copy the file takes only a few
642f83f6d8SBill Paul  * seconds.
652f83f6d8SBill Paul  */
662f83f6d8SBill Paul 
672f83f6d8SBill Paul #ifndef RPC_HDR
681542dbb4SDavid E. O'Brien %#include <sys/cdefs.h>
692f83f6d8SBill Paul #endif
702f83f6d8SBill Paul 
712f83f6d8SBill Paul /* XXX cribbed from yp.x */
72*6b462d27SKonstantin Belousov const _YPMAXRECORD = 16777216;
732f83f6d8SBill Paul const _YPMAXDOMAIN = 64;
742f83f6d8SBill Paul const _YPMAXMAP = 64;
752f83f6d8SBill Paul const _YPMAXPEER = 64;
762f83f6d8SBill Paul 
77a2098feaSGabor Kovesdan /* Suggested default -- not necessarily the one used. */
782f83f6d8SBill Paul const YPXFRBLOCK = 32767;
792f83f6d8SBill Paul 
8074e4b87eSBill Paul /*
8174e4b87eSBill Paul  * Possible return codes from the remote server.
8274e4b87eSBill Paul  */
832f83f6d8SBill Paul enum xfrstat {
842f83f6d8SBill Paul 	XFR_REQUEST_OK	= 1,	/* Transfer request granted */
852f83f6d8SBill Paul 	XFR_DENIED	= 2,	/* Transfer request denied */
862f83f6d8SBill Paul 	XFR_NOFILE	= 3,	/* Requested map file doesn't exist */
872f83f6d8SBill Paul 	XFR_ACCESS	= 4,	/* File exists, but I couldn't access it */
882f83f6d8SBill Paul 	XFR_BADDB	= 5,	/* File is not a hash database */
892f83f6d8SBill Paul 	XFR_READ_OK	= 6,	/* Block read successfully */
902f83f6d8SBill Paul 	XFR_READ_ERR	= 7,	/* Read error during transfer */
9174e4b87eSBill Paul 	XFR_DONE	= 8,	/* Transfer completed */
9274e4b87eSBill Paul 	XFR_DB_ENDIAN_MISMATCH	= 9,	/* Database byte order mismatch */
9374e4b87eSBill Paul 	XFR_DB_TYPE_MISMATCH	= 10	/* Database type mismatch */
9474e4b87eSBill Paul };
9574e4b87eSBill Paul 
9674e4b87eSBill Paul /*
9774e4b87eSBill Paul  * Database type specifications. The client can use this to ask
9874e4b87eSBill Paul  * the server for a particular type of database or just take whatever
9974e4b87eSBill Paul  * the server has to offer.
10074e4b87eSBill Paul  */
10174e4b87eSBill Paul enum xfr_db_type {
10274e4b87eSBill Paul 	XFR_DB_ASCII		= 1,	/* Flat ASCII text */
10374e4b87eSBill Paul 	XFR_DB_BSD_HASH		= 2,	/* Berkeley DB, hash method */
10474e4b87eSBill Paul 	XFR_DB_BSD_BTREE	= 3,	/* Berkeley DB, btree method */
10574e4b87eSBill Paul 	XFR_DB_BSD_RECNO	= 4,	/* Berkeley DB, recno method */
10674e4b87eSBill Paul 	XFR_DB_BSD_MPOOL	= 5,	/* Berkeley DB, mpool method */
10774e4b87eSBill Paul 	XFR_DB_BSD_NDBM		= 6,	/* Berkeley DB, hash, ndbm compat */
10874e4b87eSBill Paul 	XFR_DB_GNU_GDBM		= 7,	/* GNU GDBM */
10974e4b87eSBill Paul 	XFR_DB_DBM		= 8,	/* Old, deprecated dbm format */
11074e4b87eSBill Paul 	XFR_DB_NDBM		= 9,	/* ndbm format (used by Sun's NISv2) */
11174e4b87eSBill Paul 	XFR_DB_OPAQUE		= 10,	/* Mystery format -- just pass along */
11274e4b87eSBill Paul 	XFR_DB_ANY		= 11,	/* I'll take any format you've got */
11374e4b87eSBill Paul 	XFR_DB_UNKNOWN		= 12	/* Unknown format */
11474e4b87eSBill Paul };
11574e4b87eSBill Paul 
11674e4b87eSBill Paul /*
11774e4b87eSBill Paul  * Machine byte order specification. This allows the client to check
11874e4b87eSBill Paul  * that it's copying a map database from a machine of similar byte sex.
11974e4b87eSBill Paul  * This is necessary for handling database libraries that are fatally
12074e4b87eSBill Paul  * byte order sensitive.
12174e4b87eSBill Paul  *
12274e4b87eSBill Paul  * The XFR_ENDIAN_ANY type is for use with the Berkeley DB database
12374e4b87eSBill Paul  * formats; Berkeley DB is smart enough to make up for byte order
12474e4b87eSBill Paul  * differences, so byte sex isn't important.
12574e4b87eSBill Paul  */
12674e4b87eSBill Paul enum xfr_byte_order {
12774e4b87eSBill Paul 	XFR_ENDIAN_BIG		= 1,	/* We want big endian */
12874e4b87eSBill Paul 	XFR_ENDIAN_LITTLE	= 2,	/* We want little endian */
12974e4b87eSBill Paul 	XFR_ENDIAN_ANY		= 3	/* We'll take whatever you got */
1302f83f6d8SBill Paul };
1312f83f6d8SBill Paul 
1322f83f6d8SBill Paul typedef string xfrdomain<_YPMAXDOMAIN>;
1332f83f6d8SBill Paul typedef string xfrmap<_YPMAXMAP>;
13474e4b87eSBill Paul typedef string xfrmap_filename<_YPMAXMAP>;	/* actual name of map file */
1352f83f6d8SBill Paul 
13674e4b87eSBill Paul /*
13774e4b87eSBill Paul  * Ask the remote ypxfrd for a map using this structure.
13874e4b87eSBill Paul  * Note: we supply both a map name and a map file name. These are not
13974e4b87eSBill Paul  * the same thing. In the case of ndbm, maps are stored in two files:
14074e4b87eSBill Paul  * map.bykey.pag and may.bykey.dir. We may also have to deal with
14174e4b87eSBill Paul  * file extensions (on the off chance that the remote server is supporting
14274e4b87eSBill Paul  * multiple DB formats). To handle this, we tell the remote server both
14374e4b87eSBill Paul  * what map we want and, in the case of ndbm, whether we want the .dir
14474e4b87eSBill Paul  * or the .pag part. This name should not be a fully qualified path:
14574e4b87eSBill Paul  * it's up to the remote server to decide which directories to look in.
14674e4b87eSBill Paul  */
1472f83f6d8SBill Paul struct ypxfr_mapname {
1482f83f6d8SBill Paul 	xfrmap xfrmap;
1492f83f6d8SBill Paul 	xfrdomain xfrdomain;
15074e4b87eSBill Paul 	xfrmap_filename xfrmap_filename;
15174e4b87eSBill Paul 	xfr_db_type xfr_db_type;
15274e4b87eSBill Paul 	xfr_byte_order xfr_byte_order;
1532f83f6d8SBill Paul };
1542f83f6d8SBill Paul 
1552f83f6d8SBill Paul /* Read response using this structure. */
1562f83f6d8SBill Paul union xfr switch (bool ok) {
1572f83f6d8SBill Paul case TRUE:
1582f83f6d8SBill Paul 	opaque xfrblock_buf<>;
1592f83f6d8SBill Paul case FALSE:
16074e4b87eSBill Paul 	xfrstat xfrstat;
1612f83f6d8SBill Paul };
1622f83f6d8SBill Paul 
1632f83f6d8SBill Paul program YPXFRD_FREEBSD_PROG {
1642f83f6d8SBill Paul 	version YPXFRD_FREEBSD_VERS {
1652f83f6d8SBill Paul 		union xfr
1662f83f6d8SBill Paul 		YPXFRD_GETMAP(ypxfr_mapname) = 1;
1672f83f6d8SBill Paul 	} = 1;
1682f83f6d8SBill Paul } = 600100069;	/* 100069 + 60000000 -- 100069 is the Sun ypxfrd prog number */
169