ypxfr_misc.c revision 13007
1/* 2 * Copyright (c) 1995 3 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. All advertising materials mentioning features or use of this software 14 * must display the following acknowledgement: 15 * This product includes software developed by Bill Paul. 16 * 4. Neither the name of the author nor the names of any co-contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * 32 * $Id: ypxfr_misc.c,v 1.6 1995/12/24 04:39:55 wpaul Exp $ 33 */ 34#include <rpc/rpc.h> 35#include <rpcsvc/yp.h> 36struct dom_binding {}; 37#include <rpcsvc/ypclnt.h> 38#include "ypxfr_extern.h" 39 40#ifndef lint 41static const char rcsid[] = "$Id: ypxfr_misc.c,v 1.6 1995/12/24 04:39:55 wpaul Exp $"; 42#endif 43 44char *ypxfrerr_string(code) 45 ypxfrstat code; 46{ 47 switch(code) { 48 case YPXFR_SUCC: 49 return ("Map successfully transfered"); 50 break; 51 case YPXFR_AGE: 52 return ("Master's version not newer"); 53 break; 54 case YPXFR_NOMAP: 55 return ("No such map in server's domain"); 56 break; 57 case YPXFR_NODOM: 58 return ("Domain not supported by server"); 59 break; 60 case YPXFR_RSRC: 61 return ("Local resource allocation failure"); 62 break; 63 case YPXFR_RPC: 64 return ("RPC failure talking to server"); 65 break; 66 case YPXFR_MADDR: 67 return ("Could not get master server address"); 68 break; 69 case YPXFR_YPERR: 70 return ("NIS server/map database error"); 71 break; 72 case YPXFR_BADARGS: 73 return ("Request arguments bad"); 74 break; 75 case YPXFR_DBM: 76 return ("Local database operation failed"); 77 break; 78 case YPXFR_FILE: 79 return ("Local file I/O operation failed"); 80 break; 81 case YPXFR_SKEW: 82 return ("Map version skew during transfer"); 83 break; 84 case YPXFR_CLEAR: 85 return ("Couldn't send \"clear\" request to local ypserv"); 86 break; 87 case YPXFR_FORCE: 88 return ("No local order number in map -- use -f flag"); 89 break; 90 case YPXFR_XFRERR: 91 return ("General ypxfr error"); 92 break; 93 case YPXFR_REFUSED: 94 return ("Transfer request refused by ypserv"); 95 break; 96 default: 97 return ("Unknown error code"); 98 break; 99 } 100} 101 102/* 103 * These are wrappers for the usual yp_master() and yp_order() functions. 104 * They can use either local yplib functions (the real yp_master() and 105 * yp_order()) or do direct RPCs to a specified server. The latter is 106 * necessary if ypxfr is run on a machine that isn't configured as an 107 * NIS client (this can happen very easily: a given machine need not be 108 * an NIS client in order to be an NIS server). 109 */ 110 111char *ypxfr_get_master(domain,map,source,yplib) 112 char *domain; 113 char *map; 114 char *source; 115 const int yplib; 116{ 117 if (yplib) { 118 int res; 119 char *master; 120 if ((res = yp_master(domain, map, &master))) { 121 switch (res) { 122 case YPERR_DOMAIN: 123 yp_errno = YPXFR_NODOM; 124 break; 125 case YPERR_MAP: 126 yp_errno = YPXFR_NOMAP; 127 break; 128 case YPERR_YPERR: 129 default: 130 yp_errno = YPXFR_YPERR; 131 break; 132 } 133 return(NULL); 134 } else 135 return(master); 136 } else { 137 CLIENT *clnt; 138 ypresp_master *resp; 139 ypreq_nokey req; 140 141 if ((clnt = clnt_create(source,YPPROG,YPVERS,"udp")) == NULL) { 142 yp_error("%s",clnt_spcreateerror("failed to \ 143create udp handle to ypserv")); 144 yp_errno = YPXFR_RPC; 145 return(NULL); 146 } 147 148 req.map = map; 149 req.domain = domain; 150 if ((resp = ypproc_master_2(&req, clnt)) == NULL) { 151 yp_error("%s",clnt_sperror(clnt,"YPPROC_MASTER \ 152failed")); 153 clnt_destroy(clnt); 154 yp_errno = YPXFR_RPC; 155 return(NULL); 156 } 157 clnt_destroy(clnt); 158 if (resp->stat != YP_TRUE) { 159 switch (resp->stat) { 160 case YP_NODOM: 161 yp_errno = YPXFR_NODOM; 162 break; 163 case YP_NOMAP: 164 yp_errno = YPXFR_NOMAP; 165 break; 166 case YP_YPERR: 167 default: 168 yp_errno = YPXFR_YPERR; 169 break; 170 } 171 return(NULL); 172 } 173 return(resp->peer); 174 } 175} 176 177unsigned long ypxfr_get_order(domain, map, source, yplib) 178 char *domain; 179 char *map; 180 char *source; 181 const int yplib; 182{ 183 if (yplib) { 184 unsigned long order; 185 int res; 186 if ((res = yp_order(domain, map, (int *)&order))) { 187 switch (res) { 188 case (YPERR_DOMAIN): 189 yp_errno = YPXFR_NODOM; 190 break; 191 case (YPERR_MAP): 192 yp_errno = YPXFR_NOMAP; 193 break; 194 case (YPERR_YPERR): 195 default: 196 yp_errno = YPXFR_YPERR; 197 break; 198 } 199 return(0); 200 } else 201 return(order); 202 } else { 203 CLIENT *clnt; 204 ypresp_order *resp; 205 ypreq_nokey req; 206 207 if ((clnt = clnt_create(source,YPPROG,YPVERS,"udp")) == NULL) { 208 yp_error("%s",clnt_spcreateerror("couldn't create \ 209udp handle to ypserv")); 210 yp_errno = YPXFR_RPC; 211 return(0); 212 } 213 req.map = map; 214 req.domain = domain; 215 if ((resp = ypproc_order_2(&req, clnt)) == NULL) { 216 yp_error("%s", clnt_sperror(clnt, "YPPROC_ORDER \ 217failed")); 218 clnt_destroy(clnt); 219 yp_errno = YPXFR_RPC; 220 return(0); 221 } 222 clnt_destroy(clnt); 223 if (resp->stat != YP_TRUE) { 224 switch (resp->stat) { 225 case (YP_NODOM): 226 yp_errno = YPXFR_NODOM; 227 break; 228 case (YP_NOMAP): 229 yp_errno = YPXFR_NOMAP; 230 break; 231 case (YP_YPERR): 232 default: 233 yp_errno = YPXFR_YPERR; 234 break; 235 } 236 return(0); 237 } 238 return(resp->ordernum); 239 } 240} 241