1995-12-25 03:07:13 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1995
|
|
|
|
* Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Bill Paul.
|
|
|
|
* 4. Neither the name of the author nor the names of any co-contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
1997-12-08 07:49:56 +00:00
|
|
|
|
2003-05-04 00:59:13 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
1997-12-08 07:49:56 +00:00
|
|
|
|
1996-10-25 16:13:09 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
1996-02-04 05:18:44 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/param.h>
|
1995-12-25 03:07:13 +00:00
|
|
|
#include <rpc/rpc.h>
|
|
|
|
#include <rpcsvc/yp.h>
|
|
|
|
#include <rpcsvc/ypclnt.h>
|
|
|
|
#include "ypxfr_extern.h"
|
|
|
|
|
2002-04-06 19:08:02 +00:00
|
|
|
const char *
|
2002-02-06 15:26:07 +00:00
|
|
|
ypxfrerr_string(ypxfrstat code)
|
1995-12-25 03:07:13 +00:00
|
|
|
{
|
2002-02-06 13:30:31 +00:00
|
|
|
switch (code) {
|
1995-12-25 03:07:13 +00:00
|
|
|
case YPXFR_SUCC:
|
2000-06-02 21:22:09 +00:00
|
|
|
return ("Map successfully transferred");
|
1995-12-25 03:07:13 +00:00
|
|
|
break;
|
|
|
|
case YPXFR_AGE:
|
|
|
|
return ("Master's version not newer");
|
|
|
|
break;
|
|
|
|
case YPXFR_NOMAP:
|
|
|
|
return ("No such map in server's domain");
|
|
|
|
break;
|
|
|
|
case YPXFR_NODOM:
|
|
|
|
return ("Domain not supported by server");
|
|
|
|
break;
|
|
|
|
case YPXFR_RSRC:
|
|
|
|
return ("Local resource allocation failure");
|
|
|
|
break;
|
|
|
|
case YPXFR_RPC:
|
|
|
|
return ("RPC failure talking to server");
|
|
|
|
break;
|
|
|
|
case YPXFR_MADDR:
|
|
|
|
return ("Could not get master server address");
|
|
|
|
break;
|
|
|
|
case YPXFR_YPERR:
|
|
|
|
return ("NIS server/map database error");
|
|
|
|
break;
|
|
|
|
case YPXFR_BADARGS:
|
|
|
|
return ("Request arguments bad");
|
|
|
|
break;
|
|
|
|
case YPXFR_DBM:
|
|
|
|
return ("Local database operation failed");
|
|
|
|
break;
|
|
|
|
case YPXFR_FILE:
|
|
|
|
return ("Local file I/O operation failed");
|
|
|
|
break;
|
|
|
|
case YPXFR_SKEW:
|
|
|
|
return ("Map version skew during transfer");
|
|
|
|
break;
|
|
|
|
case YPXFR_CLEAR:
|
|
|
|
return ("Couldn't send \"clear\" request to local ypserv");
|
|
|
|
break;
|
|
|
|
case YPXFR_FORCE:
|
|
|
|
return ("No local order number in map -- use -f flag");
|
|
|
|
break;
|
|
|
|
case YPXFR_XFRERR:
|
|
|
|
return ("General ypxfr error");
|
|
|
|
break;
|
|
|
|
case YPXFR_REFUSED:
|
|
|
|
return ("Transfer request refused by ypserv");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return ("Unknown error code");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These are wrappers for the usual yp_master() and yp_order() functions.
|
|
|
|
* They can use either local yplib functions (the real yp_master() and
|
|
|
|
* yp_order()) or do direct RPCs to a specified server. The latter is
|
|
|
|
* necessary if ypxfr is run on a machine that isn't configured as an
|
|
|
|
* NIS client (this can happen very easily: a given machine need not be
|
|
|
|
* an NIS client in order to be an NIS server).
|
|
|
|
*/
|
|
|
|
|
1996-02-04 05:18:44 +00:00
|
|
|
/*
|
|
|
|
* Careful: yp_master() returns a pointer to a dynamically allocated
|
|
|
|
* buffer. Calling ypproc_master_2() ourselves also returns a pointer
|
|
|
|
* to dynamically allocated memory, though this time it's memory
|
|
|
|
* allocated by the XDR routines. We have to rememver to free() or
|
|
|
|
* xdr_free() the memory as required to avoid leaking memory.
|
|
|
|
*/
|
2002-02-06 15:26:07 +00:00
|
|
|
char *
|
|
|
|
ypxfr_get_master(char *domain, char *map, char *source, const int yplib)
|
1995-12-25 03:07:13 +00:00
|
|
|
{
|
1996-02-04 05:18:44 +00:00
|
|
|
static char mastername[MAXPATHLEN + 2];
|
|
|
|
|
|
|
|
bzero((char *)&mastername, sizeof(mastername));
|
|
|
|
|
1995-12-25 03:07:13 +00:00
|
|
|
if (yplib) {
|
|
|
|
int res;
|
|
|
|
char *master;
|
|
|
|
if ((res = yp_master(domain, map, &master))) {
|
|
|
|
switch (res) {
|
|
|
|
case YPERR_DOMAIN:
|
2011-12-16 22:05:10 +00:00
|
|
|
yp_errno = (enum ypstat)YPXFR_NODOM;
|
1995-12-25 03:07:13 +00:00
|
|
|
break;
|
|
|
|
case YPERR_MAP:
|
2011-12-16 22:05:10 +00:00
|
|
|
yp_errno = (enum ypstat)YPXFR_NOMAP;
|
1995-12-25 03:07:13 +00:00
|
|
|
break;
|
|
|
|
case YPERR_YPERR:
|
|
|
|
default:
|
2011-12-16 22:05:10 +00:00
|
|
|
yp_errno = (enum ypstat)YPXFR_YPERR;
|
1995-12-25 03:07:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return(NULL);
|
1996-02-04 05:18:44 +00:00
|
|
|
} else {
|
|
|
|
snprintf(mastername, sizeof(mastername), "%s", master);
|
|
|
|
free(master);
|
|
|
|
return((char *)&mastername);
|
|
|
|
}
|
1995-12-25 03:07:13 +00:00
|
|
|
} else {
|
|
|
|
CLIENT *clnt;
|
|
|
|
ypresp_master *resp;
|
|
|
|
ypreq_nokey req;
|
|
|
|
|
|
|
|
if ((clnt = clnt_create(source,YPPROG,YPVERS,"udp")) == NULL) {
|
|
|
|
yp_error("%s",clnt_spcreateerror("failed to \
|
|
|
|
create udp handle to ypserv"));
|
2011-12-16 22:05:10 +00:00
|
|
|
yp_errno = (enum ypstat)YPXFR_RPC;
|
1995-12-25 03:07:13 +00:00
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
req.map = map;
|
|
|
|
req.domain = domain;
|
|
|
|
if ((resp = ypproc_master_2(&req, clnt)) == NULL) {
|
|
|
|
yp_error("%s",clnt_sperror(clnt,"YPPROC_MASTER \
|
|
|
|
failed"));
|
|
|
|
clnt_destroy(clnt);
|
2011-12-16 22:05:10 +00:00
|
|
|
yp_errno = (enum ypstat)YPXFR_RPC;
|
1995-12-25 03:07:13 +00:00
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
clnt_destroy(clnt);
|
|
|
|
if (resp->stat != YP_TRUE) {
|
|
|
|
switch (resp->stat) {
|
|
|
|
case YP_NODOM:
|
2011-12-16 22:05:10 +00:00
|
|
|
yp_errno = (enum ypstat)YPXFR_NODOM;
|
1995-12-25 03:07:13 +00:00
|
|
|
break;
|
|
|
|
case YP_NOMAP:
|
2011-12-16 22:05:10 +00:00
|
|
|
yp_errno = (enum ypstat)YPXFR_NOMAP;
|
1995-12-25 03:07:13 +00:00
|
|
|
break;
|
|
|
|
case YP_YPERR:
|
|
|
|
default:
|
2011-12-16 22:05:10 +00:00
|
|
|
yp_errno = (enum ypstat)YPXFR_YPERR;
|
1995-12-25 03:07:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return(NULL);
|
|
|
|
}
|
1996-02-04 05:18:44 +00:00
|
|
|
snprintf(mastername, sizeof(mastername), "%s", resp->peer);
|
1996-06-05 05:42:52 +00:00
|
|
|
/* xdr_free(xdr_ypresp_master, (char *)&resp); */
|
1996-02-04 05:18:44 +00:00
|
|
|
return((char *)&mastername);
|
1995-12-25 03:07:13 +00:00
|
|
|
}
|
|
|
|
}
|
2002-02-06 13:30:31 +00:00
|
|
|
|
2002-02-06 15:26:07 +00:00
|
|
|
unsigned long
|
|
|
|
ypxfr_get_order(char *domain, char *map, char *source, const int yplib)
|
1995-12-25 03:07:13 +00:00
|
|
|
{
|
|
|
|
if (yplib) {
|
2004-02-16 10:03:44 +00:00
|
|
|
unsigned int order;
|
1995-12-25 03:07:13 +00:00
|
|
|
int res;
|
2004-02-16 10:03:44 +00:00
|
|
|
if ((res = yp_order(domain, map, &order))) {
|
1995-12-25 03:07:13 +00:00
|
|
|
switch (res) {
|
1996-02-04 05:18:44 +00:00
|
|
|
case YPERR_DOMAIN:
|
2011-12-16 22:05:10 +00:00
|
|
|
yp_errno = (enum ypstat)YPXFR_NODOM;
|
1995-12-25 03:07:13 +00:00
|
|
|
break;
|
1996-02-04 05:18:44 +00:00
|
|
|
case YPERR_MAP:
|
2011-12-16 22:05:10 +00:00
|
|
|
yp_errno = (enum ypstat)YPXFR_NOMAP;
|
1995-12-25 03:07:13 +00:00
|
|
|
break;
|
1996-02-04 05:18:44 +00:00
|
|
|
case YPERR_YPERR:
|
1995-12-25 03:07:13 +00:00
|
|
|
default:
|
2011-12-16 22:05:10 +00:00
|
|
|
yp_errno = (enum ypstat)YPXFR_YPERR;
|
1995-12-25 03:07:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
} else
|
|
|
|
return(order);
|
|
|
|
} else {
|
|
|
|
CLIENT *clnt;
|
|
|
|
ypresp_order *resp;
|
|
|
|
ypreq_nokey req;
|
|
|
|
|
|
|
|
if ((clnt = clnt_create(source,YPPROG,YPVERS,"udp")) == NULL) {
|
|
|
|
yp_error("%s",clnt_spcreateerror("couldn't create \
|
|
|
|
udp handle to ypserv"));
|
2011-12-16 22:05:10 +00:00
|
|
|
yp_errno = (enum ypstat)YPXFR_RPC;
|
1995-12-25 03:07:13 +00:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
req.map = map;
|
|
|
|
req.domain = domain;
|
|
|
|
if ((resp = ypproc_order_2(&req, clnt)) == NULL) {
|
|
|
|
yp_error("%s", clnt_sperror(clnt, "YPPROC_ORDER \
|
|
|
|
failed"));
|
|
|
|
clnt_destroy(clnt);
|
2011-12-16 22:05:10 +00:00
|
|
|
yp_errno = (enum ypstat)YPXFR_RPC;
|
1995-12-25 03:07:13 +00:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
clnt_destroy(clnt);
|
|
|
|
if (resp->stat != YP_TRUE) {
|
|
|
|
switch (resp->stat) {
|
1996-02-04 05:18:44 +00:00
|
|
|
case YP_NODOM:
|
2011-12-16 22:05:10 +00:00
|
|
|
yp_errno = (enum ypstat)YPXFR_NODOM;
|
1995-12-25 03:07:13 +00:00
|
|
|
break;
|
1996-02-04 05:18:44 +00:00
|
|
|
case YP_NOMAP:
|
2011-12-16 22:05:10 +00:00
|
|
|
yp_errno = (enum ypstat)YPXFR_NOMAP;
|
1995-12-25 03:07:13 +00:00
|
|
|
break;
|
1996-02-04 05:18:44 +00:00
|
|
|
case YP_YPERR:
|
1995-12-25 03:07:13 +00:00
|
|
|
default:
|
2011-12-16 22:05:10 +00:00
|
|
|
yp_errno = (enum ypstat)YPXFR_YPERR;
|
1995-12-25 03:07:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
return(resp->ordernum);
|
|
|
|
}
|
|
|
|
}
|
1996-10-25 16:13:09 +00:00
|
|
|
|
2002-02-06 15:26:07 +00:00
|
|
|
int
|
|
|
|
ypxfr_match(char *server, char *domain, char *map, char *key,
|
|
|
|
unsigned long keylen)
|
1996-10-25 16:13:09 +00:00
|
|
|
{
|
|
|
|
ypreq_key ypkey;
|
|
|
|
ypresp_val *ypval;
|
|
|
|
CLIENT *clnt;
|
|
|
|
static char buf[YPMAXRECORD + 2];
|
|
|
|
|
2002-04-28 15:18:50 +00:00
|
|
|
bzero(buf, sizeof(buf));
|
1996-10-25 16:13:09 +00:00
|
|
|
|
|
|
|
if ((clnt = clnt_create(server, YPPROG,YPVERS,"udp")) == NULL) {
|
|
|
|
yp_error("failed to create UDP handle: %s",
|
|
|
|
clnt_spcreateerror(server));
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
ypkey.domain = domain;
|
|
|
|
ypkey.map = map;
|
|
|
|
ypkey.key.keydat_len = keylen;
|
|
|
|
ypkey.key.keydat_val = key;
|
|
|
|
|
|
|
|
if ((ypval = ypproc_match_2(&ypkey, clnt)) == NULL) {
|
|
|
|
clnt_destroy(clnt);
|
|
|
|
yp_error("%s: %s", server,
|
|
|
|
clnt_sperror(clnt,"YPPROC_MATCH failed"));
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
clnt_destroy(clnt);
|
|
|
|
|
|
|
|
if (ypval->stat != YP_TRUE) {
|
2002-04-28 15:18:50 +00:00
|
|
|
xdr_free((xdrproc_t)xdr_ypresp_val, ypval);
|
1996-10-25 16:13:09 +00:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2002-04-28 15:18:50 +00:00
|
|
|
xdr_free((xdrproc_t)xdr_ypresp_val, ypval);
|
1996-10-25 16:13:09 +00:00
|
|
|
|
|
|
|
return(1);
|
|
|
|
}
|