ypxfr_main.c (13376) | ypxfr_main.c (16132) |
---|---|
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 --- 15 unchanged lines hidden (view full) --- 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 * | 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 --- 15 unchanged lines hidden (view full) --- 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_main.c,v 1.15 1996/01/10 17:41:55 wpaul Exp $ | 32 * $Id: ypxfr_main.c,v 1.17 1996/06/03 03:11:39 wpaul Exp $ |
33 */ 34#include <stdio.h> 35#include <stdlib.h> 36#include <unistd.h> 37#include <string.h> 38#include <syslog.h> 39#include <errno.h> 40#include <sys/types.h> 41#include <sys/param.h> 42#include <sys/socket.h> 43#include <netinet/in.h> 44#include <arpa/inet.h> 45#include <rpc/rpc.h> 46#include <rpc/clnt.h> 47#include <rpcsvc/yp.h> 48struct dom_binding {}; 49#include <rpcsvc/ypclnt.h> | 33 */ 34#include <stdio.h> 35#include <stdlib.h> 36#include <unistd.h> 37#include <string.h> 38#include <syslog.h> 39#include <errno.h> 40#include <sys/types.h> 41#include <sys/param.h> 42#include <sys/socket.h> 43#include <netinet/in.h> 44#include <arpa/inet.h> 45#include <rpc/rpc.h> 46#include <rpc/clnt.h> 47#include <rpcsvc/yp.h> 48struct dom_binding {}; 49#include <rpcsvc/ypclnt.h> |
50#include <rpcsvc/ypxfrd.h> |
|
50#include "ypxfr_extern.h" 51 52#ifndef lint | 51#include "ypxfr_extern.h" 52 53#ifndef lint |
53static const char rcsid[] = "$Id: ypxfr_main.c,v 1.15 1996/01/10 17:41:55 wpaul Exp $"; | 54static const char rcsid[] = "$Id: ypxfr_main.c,v 1.17 1996/06/03 03:11:39 wpaul Exp $"; |
54#endif 55 56char *progname = "ypxfr"; 57char *yp_dir = _PATH_YP; 58int _rpcpmstart = 0; 59int ypxfr_use_yplib = 0; /* Assume the worst. */ 60int ypxfr_clear = 1; 61int ypxfr_prognum = 0; --- 19 unchanged lines hidden (view full) --- 81 } 82 83 if (_rpcpmstart) { 84 timeout.tv_sec = 20; 85 timeout.tv_usec = 0; 86 87 if ((clnt = clntudp_create(&ypxfr_callback_addr, ypxfr_prognum, 88 1, timeout, &sock)) == NULL) { | 55#endif 56 57char *progname = "ypxfr"; 58char *yp_dir = _PATH_YP; 59int _rpcpmstart = 0; 60int ypxfr_use_yplib = 0; /* Assume the worst. */ 61int ypxfr_clear = 1; 62int ypxfr_prognum = 0; --- 19 unchanged lines hidden (view full) --- 82 } 83 84 if (_rpcpmstart) { 85 timeout.tv_sec = 20; 86 timeout.tv_usec = 0; 87 88 if ((clnt = clntudp_create(&ypxfr_callback_addr, ypxfr_prognum, 89 1, timeout, &sock)) == NULL) { |
89 yp_error("%s", clnt_spcreateerror("failed to establish callback handle")); | 90 yp_error("%s", clnt_spcreateerror("failed to \ 91establish callback handle")); |
90 exit(1); 91 } 92 93 ypxfr_resp.status = retval; 94 95 if (yppushproc_xfrresp_1(&ypxfr_resp, clnt) == NULL) { 96 yp_error("%s", clnt_sperror(clnt, "callback failed")); 97 clnt_destroy(clnt); --- 33 unchanged lines hidden (view full) --- 131 if (status != YP_TRUE) 132 return (status); 133 134 dbkey.data = key; 135 dbkey.size = keylen; 136 dbval.data = val; 137 dbval.size = vallen; 138 | 92 exit(1); 93 } 94 95 ypxfr_resp.status = retval; 96 97 if (yppushproc_xfrresp_1(&ypxfr_resp, clnt) == NULL) { 98 yp_error("%s", clnt_sperror(clnt, "callback failed")); 99 clnt_destroy(clnt); --- 33 unchanged lines hidden (view full) --- 133 if (status != YP_TRUE) 134 return (status); 135 136 dbkey.data = key; 137 dbkey.size = keylen; 138 dbval.data = val; 139 dbval.size = vallen; 140 |
139 if (yp_put_record(dbp, &dbkey, &dbval) != YP_TRUE) | 141 if (yp_put_record(dbp, &dbkey, &dbval, 0) != YP_TRUE) |
140 return(yp_errno); 141 142 return (0); 143} 144 145main(argc,argv) 146 int argc; 147 char *argv[]; --- 221 unchanged lines hidden (view full) --- 369 370 } 371 372 /* Construct a temporary map file name */ 373 snprintf(tempmap, sizeof(tempmap), "%s.%d",ypxfr_mapname, getpid()); 374 snprintf(ypxfr_temp_map, sizeof(ypxfr_temp_map), "%s/%s/%s", yp_dir, 375 ypxfr_dest_domain, tempmap); 376 | 142 return(yp_errno); 143 144 return (0); 145} 146 147main(argc,argv) 148 int argc; 149 char *argv[]; --- 221 unchanged lines hidden (view full) --- 371 372 } 373 374 /* Construct a temporary map file name */ 375 snprintf(tempmap, sizeof(tempmap), "%s.%d",ypxfr_mapname, getpid()); 376 snprintf(ypxfr_temp_map, sizeof(ypxfr_temp_map), "%s/%s/%s", yp_dir, 377 ypxfr_dest_domain, tempmap); 378 |
379 if (getrpcport(ypxfr_master, YPXFRD_FREEBSD_PROG, 380 YPXFRD_FREEBSD_VERS, IPPROTO_TCP)) { 381 /* Try to send using ypxfrd. If it fails, use old method. */ 382 if (!ypxfrd_get_map(ypxfr_master, ypxfr_mapname, 383 ypxfr_source_domain, ypxfr_temp_map)) 384 goto leave; 385 } 386 |
|
377 /* Open the temporary map read/write. */ | 387 /* Open the temporary map read/write. */ |
378 if ((dbp = yp_open_db_rw(ypxfr_dest_domain, tempmap)) == NULL) { | 388 if ((dbp = yp_open_db_rw(ypxfr_dest_domain, tempmap, 0)) == NULL) { |
379 yp_error("failed to open temporary map file"); 380 ypxfr_exit(YPXFR_DBM,NULL); 381 } 382 383 /* 384 * Fill in the keys we already know, such as the order number, 385 * master name, input file name (we actually make up a bogus 386 * name for that) and output file name. 387 */ 388 snprintf(buf, sizeof(buf), "%d", ypxfr_order); 389 data.data = buf; 390 data.size = strlen(buf); 391 | 389 yp_error("failed to open temporary map file"); 390 ypxfr_exit(YPXFR_DBM,NULL); 391 } 392 393 /* 394 * Fill in the keys we already know, such as the order number, 395 * master name, input file name (we actually make up a bogus 396 * name for that) and output file name. 397 */ 398 snprintf(buf, sizeof(buf), "%d", ypxfr_order); 399 data.data = buf; 400 data.size = strlen(buf); 401 |
392 if (yp_put_record(dbp, &key, &data) != YP_TRUE) { | 402 if (yp_put_record(dbp, &key, &data, 0) != YP_TRUE) { |
393 yp_error("failed to write order number to database"); 394 ypxfr_exit(YPXFR_DBM,&ypxfr_temp_map); 395 } 396 397 key.data = "YP_MASTER_NAME"; 398 key.size = sizeof("YP_MASTER_NAME") - 1; 399 data.data = ypxfr_master; 400 data.size = strlen(ypxfr_master); 401 | 403 yp_error("failed to write order number to database"); 404 ypxfr_exit(YPXFR_DBM,&ypxfr_temp_map); 405 } 406 407 key.data = "YP_MASTER_NAME"; 408 key.size = sizeof("YP_MASTER_NAME") - 1; 409 data.data = ypxfr_master; 410 data.size = strlen(ypxfr_master); 411 |
402 if (yp_put_record(dbp, &key, &data) != YP_TRUE) { | 412 if (yp_put_record(dbp, &key, &data, 0) != YP_TRUE) { |
403 yp_error("failed to write master name to database"); 404 ypxfr_exit(YPXFR_DBM,&ypxfr_temp_map); 405 } 406 407 key.data = "YP_DOMAIN_NAME"; 408 key.size = sizeof("YP_DOMAIN_NAME") - 1; 409 data.data = ypxfr_dest_domain; 410 data.size = strlen(ypxfr_dest_domain); 411 | 413 yp_error("failed to write master name to database"); 414 ypxfr_exit(YPXFR_DBM,&ypxfr_temp_map); 415 } 416 417 key.data = "YP_DOMAIN_NAME"; 418 key.size = sizeof("YP_DOMAIN_NAME") - 1; 419 data.data = ypxfr_dest_domain; 420 data.size = strlen(ypxfr_dest_domain); 421 |
412 if (yp_put_record(dbp, &key, &data) != YP_TRUE) { | 422 if (yp_put_record(dbp, &key, &data, 0) != YP_TRUE) { |
413 yp_error("failed to write domain name to database"); 414 ypxfr_exit(YPXFR_DBM,&ypxfr_temp_map); 415 } 416 417 snprintf (buf, sizeof(buf), "%s:%s", ypxfr_source_host, ypxfr_mapname); 418 419 key.data = "YP_INPUT_NAME"; 420 key.size = sizeof("YP_INPUT_NAME") - 1; 421 data.data = &buf; 422 data.size = strlen(buf); 423 | 423 yp_error("failed to write domain name to database"); 424 ypxfr_exit(YPXFR_DBM,&ypxfr_temp_map); 425 } 426 427 snprintf (buf, sizeof(buf), "%s:%s", ypxfr_source_host, ypxfr_mapname); 428 429 key.data = "YP_INPUT_NAME"; 430 key.size = sizeof("YP_INPUT_NAME") - 1; 431 data.data = &buf; 432 data.size = strlen(buf); 433 |
424 if (yp_put_record(dbp, &key, &data) != YP_TRUE) { | 434 if (yp_put_record(dbp, &key, &data, 0) != YP_TRUE) { |
425 yp_error("failed to write input name to database"); 426 ypxfr_exit(YPXFR_DBM,&ypxfr_temp_map); 427 428 } 429 430 snprintf(buf, sizeof(buf), "%s/%s/%s", yp_dir, ypxfr_dest_domain, 431 ypxfr_mapname); 432 433 key.data = "YP_OUTPUT_NAME"; 434 key.size = sizeof("YP_OUTPUT_NAME") - 1; 435 data.data = &buf; 436 data.size = strlen(buf); 437 | 435 yp_error("failed to write input name to database"); 436 ypxfr_exit(YPXFR_DBM,&ypxfr_temp_map); 437 438 } 439 440 snprintf(buf, sizeof(buf), "%s/%s/%s", yp_dir, ypxfr_dest_domain, 441 ypxfr_mapname); 442 443 key.data = "YP_OUTPUT_NAME"; 444 key.size = sizeof("YP_OUTPUT_NAME") - 1; 445 data.data = &buf; 446 data.size = strlen(buf); 447 |
438 if (yp_put_record(dbp, &key, &data) != YP_TRUE) { | 448 if (yp_put_record(dbp, &key, &data, 0) != YP_TRUE) { |
439 yp_error("failed to write output name to database"); 440 ypxfr_exit(YPXFR_DBM,&ypxfr_temp_map); 441 } 442 443 /* Now suck over the contents of the map from the master. */ 444 445 if (ypxfr_get_map(ypxfr_mapname,ypxfr_source_domain, 446 ypxfr_source_host, ypxfr_foreach)){ 447 yp_error("failed to retrieve map from source host"); 448 ypxfr_exit(YPXFR_YPERR,&ypxfr_temp_map); 449 } 450 451 (void)(dbp->close)(dbp); 452 dbp = NULL; /* <- yes, it seems this is necessary. */ 453 | 449 yp_error("failed to write output name to database"); 450 ypxfr_exit(YPXFR_DBM,&ypxfr_temp_map); 451 } 452 453 /* Now suck over the contents of the map from the master. */ 454 455 if (ypxfr_get_map(ypxfr_mapname,ypxfr_source_domain, 456 ypxfr_source_host, ypxfr_foreach)){ 457 yp_error("failed to retrieve map from source host"); 458 ypxfr_exit(YPXFR_YPERR,&ypxfr_temp_map); 459 } 460 461 (void)(dbp->close)(dbp); 462 dbp = NULL; /* <- yes, it seems this is necessary. */ 463 |
464leave: 465 466 snprintf(buf, sizeof(buf), "%s/%s/%s", yp_dir, ypxfr_dest_domain, 467 ypxfr_mapname); 468 |
|
454 /* Peek at the order number again and check for skew. */ 455 if ((ypxfr_skew_check = ypxfr_get_order(ypxfr_source_domain, 456 ypxfr_mapname, 457 ypxfr_master, 0)) == 0) { 458 yp_error("failed to get order number of %s: %s", 459 ypxfr_mapname, yp_errno == YPXFR_SUCC ? 460 "map has order 0" : ypxfrerr_string(yp_errno)); 461 ypxfr_exit(YPXFR_YPERR,&ypxfr_temp_map); 462 } 463 464 if (ypxfr_order != ypxfr_skew_check) 465 ypxfr_exit(YPXFR_SKEW,&ypxfr_temp_map); 466 467 /* 468 * Send a YPPROC_CLEAR to the local ypserv. | 469 /* Peek at the order number again and check for skew. */ 470 if ((ypxfr_skew_check = ypxfr_get_order(ypxfr_source_domain, 471 ypxfr_mapname, 472 ypxfr_master, 0)) == 0) { 473 yp_error("failed to get order number of %s: %s", 474 ypxfr_mapname, yp_errno == YPXFR_SUCC ? 475 "map has order 0" : ypxfrerr_string(yp_errno)); 476 ypxfr_exit(YPXFR_YPERR,&ypxfr_temp_map); 477 } 478 479 if (ypxfr_order != ypxfr_skew_check) 480 ypxfr_exit(YPXFR_SKEW,&ypxfr_temp_map); 481 482 /* 483 * Send a YPPROC_CLEAR to the local ypserv. |
469 * The FreeBSD ypserv doesn't really need this, but we send it 470 * here anyway for the sake of consistency. | |
471 */ 472 if (ypxfr_clear) { 473 char in = 0; 474 char *out = NULL; 475 int stat; 476 if ((stat = callrpc("localhost",YPPROG,YPVERS,YPPROC_CLEAR, 477 xdr_void, (void *)&in, 478 xdr_void, (void *)out)) != RPC_SUCCESS) { --- 23 unchanged lines hidden --- | 484 */ 485 if (ypxfr_clear) { 486 char in = 0; 487 char *out = NULL; 488 int stat; 489 if ((stat = callrpc("localhost",YPPROG,YPVERS,YPPROC_CLEAR, 490 xdr_void, (void *)&in, 491 xdr_void, (void *)out)) != RPC_SUCCESS) { --- 23 unchanged lines hidden --- |