freebsd_amp_hwpstate/libexec/ypxfr/ypxfr_misc.c

241 lines
6.2 KiB
C
Raw Normal View History

/*
* 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.
*
* $Id: ypxfr_misc.c,v 1.6 1995/12/24 04:39:55 wpaul Exp $
*/
#include <rpc/rpc.h>
#include <rpcsvc/yp.h>
struct dom_binding {};
#include <rpcsvc/ypclnt.h>
#include "ypxfr_extern.h"
#ifndef lint
static const char rcsid[] = "$Id: ypxfr_misc.c,v 1.6 1995/12/24 04:39:55 wpaul Exp $";
#endif
char *ypxfrerr_string(code)
ypxfrstat code;
{
switch(code) {
case YPXFR_SUCC:
return ("Map successfully transfered");
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).
*/
char *ypxfr_get_master(domain,map,source,yplib)
char *domain;
char *map;
char *source;
const int yplib;
{
if (yplib) {
int res;
char *master;
if ((res = yp_master(domain, map, &master))) {
switch (res) {
case YPERR_DOMAIN:
yp_errno = YPXFR_NODOM;
break;
case YPERR_MAP:
yp_errno = YPXFR_NOMAP;
break;
case YPERR_YPERR:
default:
yp_errno = YPXFR_YPERR;
break;
}
return(NULL);
} else
return(master);
} 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"));
yp_errno = YPXFR_RPC;
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);
yp_errno = YPXFR_RPC;
return(NULL);
}
clnt_destroy(clnt);
if (resp->stat != YP_TRUE) {
switch (resp->stat) {
case YP_NODOM:
yp_errno = YPXFR_NODOM;
break;
case YP_NOMAP:
yp_errno = YPXFR_NOMAP;
break;
case YP_YPERR:
default:
yp_errno = YPXFR_YPERR;
break;
}
return(NULL);
}
return(resp->peer);
}
}
unsigned long ypxfr_get_order(domain, map, source, yplib)
char *domain;
char *map;
char *source;
const int yplib;
{
if (yplib) {
unsigned long order;
int res;
if ((res = yp_order(domain, map, (int *)&order))) {
switch (res) {
case (YPERR_DOMAIN):
yp_errno = YPXFR_NODOM;
break;
case (YPERR_MAP):
yp_errno = YPXFR_NOMAP;
break;
case (YPERR_YPERR):
default:
yp_errno = YPXFR_YPERR;
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"));
yp_errno = YPXFR_RPC;
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);
yp_errno = YPXFR_RPC;
return(0);
}
clnt_destroy(clnt);
if (resp->stat != YP_TRUE) {
switch (resp->stat) {
case (YP_NODOM):
yp_errno = YPXFR_NODOM;
break;
case (YP_NOMAP):
yp_errno = YPXFR_NOMAP;
break;
case (YP_YPERR):
default:
yp_errno = YPXFR_YPERR;
break;
}
return(0);
}
return(resp->ordernum);
}
}