17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate * 22*a506a34cSth160488 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 277c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate /* 307c478bd9Sstevel@tonic-gate * Portions of this source code were derived from Berkeley 317c478bd9Sstevel@tonic-gate * under license from the Regents of the University of 327c478bd9Sstevel@tonic-gate * California. 337c478bd9Sstevel@tonic-gate */ 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate /* 367c478bd9Sstevel@tonic-gate * This is a user command which gets a NIS data base from some running 377c478bd9Sstevel@tonic-gate * server, and gets it to the local site by using the normal NIS client 387c478bd9Sstevel@tonic-gate * enumeration functions. The map is copied to a temp name, then the real 397c478bd9Sstevel@tonic-gate * map is removed and the temp map is moved to the real name. ypxfr then 407c478bd9Sstevel@tonic-gate * sends a "YPPROC_CLEAR" message to the local server to insure that he will 417c478bd9Sstevel@tonic-gate * not hold a removed map open, so serving an obsolete version. 427c478bd9Sstevel@tonic-gate * 437c478bd9Sstevel@tonic-gate * ypxfr [ -h <host> ] [ -d <domainname> ] 447c478bd9Sstevel@tonic-gate * [ -s <domainname> ] [-f] [-c] [-C tid prot name] map 457c478bd9Sstevel@tonic-gate * 467c478bd9Sstevel@tonic-gate * If the host is ommitted, ypxfr will attempt to discover the master by 477c478bd9Sstevel@tonic-gate * using normal NIS services. If it can't get the record, it will use 487c478bd9Sstevel@tonic-gate * the address of the callback, if specified. If the host is specified 497c478bd9Sstevel@tonic-gate * as an internet address, no NIS services need to be locally available. 507c478bd9Sstevel@tonic-gate * 517c478bd9Sstevel@tonic-gate * If the domain is not specified, the default domain of the local machine 527c478bd9Sstevel@tonic-gate * is used. 537c478bd9Sstevel@tonic-gate * 547c478bd9Sstevel@tonic-gate * If the -f flag is used, the transfer will be done even if the master's 557c478bd9Sstevel@tonic-gate * copy is not newer than the local copy. 567c478bd9Sstevel@tonic-gate * 577c478bd9Sstevel@tonic-gate * The -c flag suppresses the YPPROC_CLEAR request to the local ypserv. It 587c478bd9Sstevel@tonic-gate * may be used if ypserv isn't currently running to suppress the error message. 597c478bd9Sstevel@tonic-gate * 607c478bd9Sstevel@tonic-gate * The -C flag is used to pass callback information to ypxfr when it is 617c478bd9Sstevel@tonic-gate * activated by ypserv. The callback information is used to send a 627c478bd9Sstevel@tonic-gate * yppushresp_xfr message with transaction id "tid" to a yppush process 637c478bd9Sstevel@tonic-gate * speaking a transient protocol number "prot". The yppush program is 647c478bd9Sstevel@tonic-gate * running on the host "name". 657c478bd9Sstevel@tonic-gate * 667c478bd9Sstevel@tonic-gate * The -s option is used to specify a source domain which may be 677c478bd9Sstevel@tonic-gate * different from the destination domain, for transfer of maps 687c478bd9Sstevel@tonic-gate * that are identical in different domains (e.g. services.byname) 697c478bd9Sstevel@tonic-gate * 707c478bd9Sstevel@tonic-gate */ 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate #include <ndbm.h> 737c478bd9Sstevel@tonic-gate #define DATUM 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate #include <stdio.h> 767c478bd9Sstevel@tonic-gate #include <errno.h> 777c478bd9Sstevel@tonic-gate #include <time.h> 787c478bd9Sstevel@tonic-gate #include <ctype.h> 797c478bd9Sstevel@tonic-gate #include <netdb.h> 807c478bd9Sstevel@tonic-gate #include <netconfig.h> 817c478bd9Sstevel@tonic-gate #include <netdir.h> 827c478bd9Sstevel@tonic-gate #include <rpc/rpc.h> 837c478bd9Sstevel@tonic-gate #include <sys/file.h> 847c478bd9Sstevel@tonic-gate #include <sys/stat.h> 857c478bd9Sstevel@tonic-gate #include <dirent.h> 867c478bd9Sstevel@tonic-gate #include <rpcsvc/ypclnt.h> 877c478bd9Sstevel@tonic-gate #include <rpcsvc/yp_prot.h> 887c478bd9Sstevel@tonic-gate #include <unistd.h> 897c478bd9Sstevel@tonic-gate #include <stdlib.h> 907c478bd9Sstevel@tonic-gate #include <rpcsvc/nis.h> 917c478bd9Sstevel@tonic-gate #include "ypdefs.h" 927c478bd9Sstevel@tonic-gate #include "yp_b.h" 937c478bd9Sstevel@tonic-gate #include "shim.h" 947c478bd9Sstevel@tonic-gate #include "yptol.h" 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate USE_YP_MASTER_NAME 977c478bd9Sstevel@tonic-gate USE_YP_SECURE 987c478bd9Sstevel@tonic-gate USE_YP_INTERDOMAIN 997c478bd9Sstevel@tonic-gate USE_YP_LAST_MODIFIED 1007c478bd9Sstevel@tonic-gate USE_YPDBPATH 1017c478bd9Sstevel@tonic-gate USE_DBM 1027c478bd9Sstevel@tonic-gate 1037c478bd9Sstevel@tonic-gate #define PARANOID 1 /* make sure maps have the right # entries */ 1047c478bd9Sstevel@tonic-gate 1057c478bd9Sstevel@tonic-gate #define CALLINTER_TRY 10 /* Seconds between callback tries */ 1067c478bd9Sstevel@tonic-gate #define CALLTIMEOUT CALLINTER_TRY*6 /* Total timeout for callback */ 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gate DBM *db; 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate /* ypxfr never uses N2L mode */ 1117c478bd9Sstevel@tonic-gate bool_t yptol_mode = FALSE; 1127c478bd9Sstevel@tonic-gate 1137c478bd9Sstevel@tonic-gate int debug = FALSE; 1147c478bd9Sstevel@tonic-gate int treepush = FALSE; 1157c478bd9Sstevel@tonic-gate #define TREEPUSH 1 1167c478bd9Sstevel@tonic-gate int defwrite = TRUE; 1177c478bd9Sstevel@tonic-gate 1187c478bd9Sstevel@tonic-gate char *domain = NULL; 1197c478bd9Sstevel@tonic-gate char *source = NULL; 1207c478bd9Sstevel@tonic-gate char *map = NULL; 1217c478bd9Sstevel@tonic-gate char *master = NULL; 1227c478bd9Sstevel@tonic-gate char *pushhost = NULL; 1237c478bd9Sstevel@tonic-gate /* 1247c478bd9Sstevel@tonic-gate * The name of the xfer peer as specified as a 1257c478bd9Sstevel@tonic-gate * -h option, -C name option or from querying the NIS 1267c478bd9Sstevel@tonic-gate */ 1277c478bd9Sstevel@tonic-gate struct dom_binding master_server; /* To talk to above */ 1287c478bd9Sstevel@tonic-gate unsigned int master_prog_vers; /* YPVERS (barfs at YPOLDVERS !) */ 1297c478bd9Sstevel@tonic-gate char *master_name = NULL; /* Map's master as contained in the map */ 1307c478bd9Sstevel@tonic-gate unsigned *master_version = NULL; /* Order number as contained in the map */ 1317c478bd9Sstevel@tonic-gate char *master_ascii_version; /* ASCII order number as contained in the map */ 1327c478bd9Sstevel@tonic-gate bool fake_master_version = FALSE; 1337c478bd9Sstevel@tonic-gate /* 1347c478bd9Sstevel@tonic-gate * TRUE only if there's no order number in 1357c478bd9Sstevel@tonic-gate * the map, and the user specified -f 1367c478bd9Sstevel@tonic-gate */ 1377c478bd9Sstevel@tonic-gate bool force = FALSE; /* TRUE iff user specified -f flag */ 1387c478bd9Sstevel@tonic-gate bool logging = FALSE; /* TRUE iff no tty, but log file exists */ 1397c478bd9Sstevel@tonic-gate bool check_count = FALSE; /* TRUE causes counts to be checked */ 1407c478bd9Sstevel@tonic-gate bool send_clear = TRUE; /* FALSE iff user specified -c flag */ 1417c478bd9Sstevel@tonic-gate bool callback = FALSE; 1427c478bd9Sstevel@tonic-gate /* 1437c478bd9Sstevel@tonic-gate * TRUE iff -C flag set. tid, proto and name 1447c478bd9Sstevel@tonic-gate * will be set to point to the command line args. 1457c478bd9Sstevel@tonic-gate */ 1467c478bd9Sstevel@tonic-gate bool secure_map = FALSE; /* TRUE if there is yp_secure in the map */ 1477c478bd9Sstevel@tonic-gate bool interdomain_map = FALSE; 1487c478bd9Sstevel@tonic-gate /* 1497c478bd9Sstevel@tonic-gate * TRUE if there is yp_interdomain in either 1507c478bd9Sstevel@tonic-gate * the local or the master version of the map 1517c478bd9Sstevel@tonic-gate */ 1527c478bd9Sstevel@tonic-gate int interdomain_sz = 0; /* Size of the interdomain value */ 1537c478bd9Sstevel@tonic-gate #define UDPINTER_TRY 10 /* Seconds between tries for udp */ 1547c478bd9Sstevel@tonic-gate #define UDPTIMEOUT UDPINTER_TRY*4 /* Total timeout for udp */ 1557c478bd9Sstevel@tonic-gate #define CALLINTER_TRY 10 /* Seconds between callback tries */ 1567c478bd9Sstevel@tonic-gate #define CALLTIMEOUT CALLINTER_TRY*6 /* Total timeout for callback */ 1577c478bd9Sstevel@tonic-gate struct timeval udp_timeout = { UDPTIMEOUT, 0}; 1587c478bd9Sstevel@tonic-gate struct timeval tcp_timeout = { 180, 0}; /* Timeout for map enumeration */ 1597c478bd9Sstevel@tonic-gate 1607c478bd9Sstevel@tonic-gate char *interdomain_value; /* place to store the interdomain value */ 1617c478bd9Sstevel@tonic-gate char *tid; 1627c478bd9Sstevel@tonic-gate char *proto; 1637c478bd9Sstevel@tonic-gate int entry_count; /* counts entries in the map */ 1647c478bd9Sstevel@tonic-gate char logfile[] = "/var/yp/ypxfr.log"; 1657c478bd9Sstevel@tonic-gate static char err_usage[] = 1667c478bd9Sstevel@tonic-gate "Usage:\n\ 1677c478bd9Sstevel@tonic-gate ypxfr [-f] [ -h host ] [ -d domainname ]\n\ 1687c478bd9Sstevel@tonic-gate [ -s domainname ] [-c] [-C tid prot servname ] map\n\n\ 1697c478bd9Sstevel@tonic-gate where\n\ 1707c478bd9Sstevel@tonic-gate -f forces transfer even if the master's copy is not newer.\n\ 1717c478bd9Sstevel@tonic-gate host is the server from where the map should be transfered\n\ 1727c478bd9Sstevel@tonic-gate -d domainname is specified if other than the default domain\n\ 1737c478bd9Sstevel@tonic-gate -s domainname is a source for the map that is same across domains\n\ 1747c478bd9Sstevel@tonic-gate -c inhibits sending a \"Clear map\" message to the local ypserv.\n\ 1757c478bd9Sstevel@tonic-gate -C is for use only by ypserv to pass callback information.\n"; 1767c478bd9Sstevel@tonic-gate char err_bad_args[] = 1777c478bd9Sstevel@tonic-gate "%s argument is bad.\n"; 1787c478bd9Sstevel@tonic-gate char err_cant_get_kname[] = 1797c478bd9Sstevel@tonic-gate "Can't get %s back from system call.\n"; 1807c478bd9Sstevel@tonic-gate char err_null_kname[] = 1817c478bd9Sstevel@tonic-gate "%s hasn't been set on this machine.\n"; 1827c478bd9Sstevel@tonic-gate char err_bad_hostname[] = "hostname"; 1837c478bd9Sstevel@tonic-gate char err_bad_mapname[] = "mapname"; 1847c478bd9Sstevel@tonic-gate char err_bad_domainname[] = "domainname"; 1857c478bd9Sstevel@tonic-gate char err_udp_failure[] = 1867c478bd9Sstevel@tonic-gate "Can't set up a udp connection to ypserv on host %s.\n"; 1877c478bd9Sstevel@tonic-gate char yptempname_prefix[] = "ypxfr_map."; 1887c478bd9Sstevel@tonic-gate char ypbkupname_prefix[] = "ypxfr_bkup."; 1897c478bd9Sstevel@tonic-gate 1907c478bd9Sstevel@tonic-gate void get_command_line_args(); 1917c478bd9Sstevel@tonic-gate bool bind_to_server(); 1927c478bd9Sstevel@tonic-gate bool ping_server(); 1937c478bd9Sstevel@tonic-gate bool get_private_recs(); 1947c478bd9Sstevel@tonic-gate bool get_order(); 1957c478bd9Sstevel@tonic-gate bool get_v1order(); 1967c478bd9Sstevel@tonic-gate bool get_v2order(); 1977c478bd9Sstevel@tonic-gate bool get_misc_recs(); 1987c478bd9Sstevel@tonic-gate bool get_master_name(); 1997c478bd9Sstevel@tonic-gate bool get_v1master_name(); 2007c478bd9Sstevel@tonic-gate bool get_v2master_name(); 2017c478bd9Sstevel@tonic-gate void find_map_master(); 2027c478bd9Sstevel@tonic-gate bool move_map(); 2037c478bd9Sstevel@tonic-gate unsigned get_local_version(); 2047c478bd9Sstevel@tonic-gate void mkfilename(); 2057c478bd9Sstevel@tonic-gate void mk_tmpname(); 2067c478bd9Sstevel@tonic-gate bool get_map(); 2077c478bd9Sstevel@tonic-gate bool add_private_entries(); 2087c478bd9Sstevel@tonic-gate bool new_mapfiles(); 2097c478bd9Sstevel@tonic-gate void del_mapfiles(); 2107c478bd9Sstevel@tonic-gate void set_output(); 2117c478bd9Sstevel@tonic-gate void logprintf(); 2127c478bd9Sstevel@tonic-gate bool send_ypclear(); 2137c478bd9Sstevel@tonic-gate void xfr_exit(); 2147c478bd9Sstevel@tonic-gate void send_callback(); 2157c478bd9Sstevel@tonic-gate int ypall_callback(); 2167c478bd9Sstevel@tonic-gate int map_yperr_to_pusherr(); 2177c478bd9Sstevel@tonic-gate extern CLIENT *__yp_clnt_create_rsvdport(); 2187c478bd9Sstevel@tonic-gate 2197c478bd9Sstevel@tonic-gate bool_t is_yptol_mode(); 2207c478bd9Sstevel@tonic-gate 2217c478bd9Sstevel@tonic-gate extern int errno; 2227c478bd9Sstevel@tonic-gate 2237c478bd9Sstevel@tonic-gate 2247c478bd9Sstevel@tonic-gate /* 2257c478bd9Sstevel@tonic-gate * This is the mainline for the ypxfr process. 2267c478bd9Sstevel@tonic-gate */ 2277c478bd9Sstevel@tonic-gate 228*a506a34cSth160488 int 2297c478bd9Sstevel@tonic-gate main(argc, argv) 2307c478bd9Sstevel@tonic-gate int argc; 2317c478bd9Sstevel@tonic-gate char **argv; 2327c478bd9Sstevel@tonic-gate 2337c478bd9Sstevel@tonic-gate { 2347c478bd9Sstevel@tonic-gate 2357c478bd9Sstevel@tonic-gate static char default_domain_name[YPMAXDOMAIN]; 2367c478bd9Sstevel@tonic-gate static unsigned big = 0xffffffff; 2377c478bd9Sstevel@tonic-gate int status; 2387c478bd9Sstevel@tonic-gate 2397c478bd9Sstevel@tonic-gate set_output(); 2407c478bd9Sstevel@tonic-gate 2417c478bd9Sstevel@tonic-gate /* 2427c478bd9Sstevel@tonic-gate * Inter-process lock synchronization structure. Since slave servers 2437c478bd9Sstevel@tonic-gate * get their maps from another NIS server rather than LDAP they can 2447c478bd9Sstevel@tonic-gate * never run in N2L mode. We thus do not have to init the update 2457c478bd9Sstevel@tonic-gate * locking mechanism. 2467c478bd9Sstevel@tonic-gate */ 2477c478bd9Sstevel@tonic-gate if (init_lock_map() == FALSE) { 2487c478bd9Sstevel@tonic-gate exit(1); 2497c478bd9Sstevel@tonic-gate } 2507c478bd9Sstevel@tonic-gate 2517c478bd9Sstevel@tonic-gate get_command_line_args(argc, argv); 2527c478bd9Sstevel@tonic-gate 2537c478bd9Sstevel@tonic-gate if (!domain) { 2547c478bd9Sstevel@tonic-gate 2557c478bd9Sstevel@tonic-gate if (!getdomainname(default_domain_name, YPMAXDOMAIN)) { 2567c478bd9Sstevel@tonic-gate domain = default_domain_name; 2577c478bd9Sstevel@tonic-gate } else { 2587c478bd9Sstevel@tonic-gate logprintf(err_cant_get_kname, 2597c478bd9Sstevel@tonic-gate err_bad_domainname); 2607c478bd9Sstevel@tonic-gate xfr_exit(YPPUSH_RSRC); 2617c478bd9Sstevel@tonic-gate } 2627c478bd9Sstevel@tonic-gate 2637c478bd9Sstevel@tonic-gate if (strlen(domain) == 0) { 2647c478bd9Sstevel@tonic-gate logprintf(err_null_kname, 2657c478bd9Sstevel@tonic-gate err_bad_domainname); 2667c478bd9Sstevel@tonic-gate xfr_exit(YPPUSH_RSRC); 2677c478bd9Sstevel@tonic-gate } 2687c478bd9Sstevel@tonic-gate } 2697c478bd9Sstevel@tonic-gate if (!source) 2707c478bd9Sstevel@tonic-gate source = domain; 2717c478bd9Sstevel@tonic-gate 2727c478bd9Sstevel@tonic-gate if (!master) { 2737c478bd9Sstevel@tonic-gate find_map_master(); 2747c478bd9Sstevel@tonic-gate } 2757c478bd9Sstevel@tonic-gate /* 2767c478bd9Sstevel@tonic-gate * if we were unable to get the master name, either from 2777c478bd9Sstevel@tonic-gate * the -h option or from -C "name" option or from NIS, 2787c478bd9Sstevel@tonic-gate * we are doomed ! 2797c478bd9Sstevel@tonic-gate */ 2807c478bd9Sstevel@tonic-gate if (!master) { 2817c478bd9Sstevel@tonic-gate xfr_exit(YPPUSH_MADDR); 2827c478bd9Sstevel@tonic-gate } 2837c478bd9Sstevel@tonic-gate 2847c478bd9Sstevel@tonic-gate if (!bind_to_server(master, &master_server, 2857c478bd9Sstevel@tonic-gate &master_prog_vers, &status)) { 2867c478bd9Sstevel@tonic-gate xfr_exit(status); 2877c478bd9Sstevel@tonic-gate } 2887c478bd9Sstevel@tonic-gate 2897c478bd9Sstevel@tonic-gate if (!get_private_recs(&status)) { 2907c478bd9Sstevel@tonic-gate xfr_exit(status); 2917c478bd9Sstevel@tonic-gate } 2927c478bd9Sstevel@tonic-gate 2937c478bd9Sstevel@tonic-gate if (!master_version) { 2947c478bd9Sstevel@tonic-gate 2957c478bd9Sstevel@tonic-gate if (force) { 2967c478bd9Sstevel@tonic-gate master_version = &big; 2977c478bd9Sstevel@tonic-gate fake_master_version = TRUE; 2987c478bd9Sstevel@tonic-gate } else { 2997c478bd9Sstevel@tonic-gate logprintf( 3007c478bd9Sstevel@tonic-gate "Can't get order number for map %s from server at %s: use the -f flag.\n", 3017c478bd9Sstevel@tonic-gate map, master); 3027c478bd9Sstevel@tonic-gate xfr_exit(YPPUSH_FORCE); 3037c478bd9Sstevel@tonic-gate } 3047c478bd9Sstevel@tonic-gate } 3057c478bd9Sstevel@tonic-gate 3067c478bd9Sstevel@tonic-gate if (!move_map(&status)) { 3077c478bd9Sstevel@tonic-gate xfr_exit(status); 3087c478bd9Sstevel@tonic-gate } 3097c478bd9Sstevel@tonic-gate 3107c478bd9Sstevel@tonic-gate if (send_clear && !send_ypclear(&status)) { 3117c478bd9Sstevel@tonic-gate xfr_exit(status); 3127c478bd9Sstevel@tonic-gate } 3137c478bd9Sstevel@tonic-gate 3147c478bd9Sstevel@tonic-gate if (logging) { 3157c478bd9Sstevel@tonic-gate logprintf("Transferred map %s from %s (%d entries).\n", 3167c478bd9Sstevel@tonic-gate map, master, entry_count); 3177c478bd9Sstevel@tonic-gate } 3187c478bd9Sstevel@tonic-gate 3197c478bd9Sstevel@tonic-gate xfr_exit(YPPUSH_SUCC); 320*a506a34cSth160488 return (0); 3217c478bd9Sstevel@tonic-gate /* NOTREACHED */ 3227c478bd9Sstevel@tonic-gate } 3237c478bd9Sstevel@tonic-gate 3247c478bd9Sstevel@tonic-gate /* 3257c478bd9Sstevel@tonic-gate * This decides whether we're being run interactively or not, and, if not, 3267c478bd9Sstevel@tonic-gate * whether we're supposed to be logging or not. If we are logging, it sets 3277c478bd9Sstevel@tonic-gate * up stderr to point to the log file, and sets the "logging" 3287c478bd9Sstevel@tonic-gate * variable. If there's no logging, the output goes in the bit bucket. 3297c478bd9Sstevel@tonic-gate * Logging output differs from interactive output in the presence of a 3307c478bd9Sstevel@tonic-gate * timestamp, present only in the log file. stderr is reset, too, because it 3317c478bd9Sstevel@tonic-gate * it's used by various library functions, including clnt_perror. 3327c478bd9Sstevel@tonic-gate */ 3337c478bd9Sstevel@tonic-gate void 3347c478bd9Sstevel@tonic-gate set_output() 3357c478bd9Sstevel@tonic-gate { 3367c478bd9Sstevel@tonic-gate if (!isatty(1)) { 3377c478bd9Sstevel@tonic-gate if (access(logfile, W_OK)) { 3387c478bd9Sstevel@tonic-gate (void) freopen("/dev/null", "w", stderr); 3397c478bd9Sstevel@tonic-gate } else { 3407c478bd9Sstevel@tonic-gate (void) freopen(logfile, "a", stderr); 3417c478bd9Sstevel@tonic-gate logging = TRUE; 3427c478bd9Sstevel@tonic-gate } 3437c478bd9Sstevel@tonic-gate } 3447c478bd9Sstevel@tonic-gate } 3457c478bd9Sstevel@tonic-gate /* 3467c478bd9Sstevel@tonic-gate * This constructs a logging record. 3477c478bd9Sstevel@tonic-gate */ 3487c478bd9Sstevel@tonic-gate void 3497c478bd9Sstevel@tonic-gate logprintf(arg1, arg2, arg3, arg4, arg5, arg6, arg7) 3507c478bd9Sstevel@tonic-gate /*VARARGS*/ 3517c478bd9Sstevel@tonic-gate { 3527c478bd9Sstevel@tonic-gate struct timeval t; 3537c478bd9Sstevel@tonic-gate 3547c478bd9Sstevel@tonic-gate fseek(stderr, 0, 2); 3557c478bd9Sstevel@tonic-gate if (logging) { 3567c478bd9Sstevel@tonic-gate (void) gettimeofday(&t, NULL); 3577c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "%19.19s: ", ctime(&t.tv_sec)); 3587c478bd9Sstevel@tonic-gate } 3597c478bd9Sstevel@tonic-gate (void) fprintf(stderr, (char *)arg1, arg2, arg3, arg4, arg5, 3607c478bd9Sstevel@tonic-gate arg6, arg7); 3617c478bd9Sstevel@tonic-gate fflush(stderr); 3627c478bd9Sstevel@tonic-gate } 3637c478bd9Sstevel@tonic-gate 3647c478bd9Sstevel@tonic-gate /* 3657c478bd9Sstevel@tonic-gate * This does the command line argument processing. 3667c478bd9Sstevel@tonic-gate */ 3677c478bd9Sstevel@tonic-gate void 3687c478bd9Sstevel@tonic-gate get_command_line_args(argc, argv) 3697c478bd9Sstevel@tonic-gate int argc; 3707c478bd9Sstevel@tonic-gate char **argv; 3717c478bd9Sstevel@tonic-gate 3727c478bd9Sstevel@tonic-gate { 3737c478bd9Sstevel@tonic-gate argv++; 3747c478bd9Sstevel@tonic-gate 3757c478bd9Sstevel@tonic-gate if (argc < 2) { 3767c478bd9Sstevel@tonic-gate logprintf(err_usage); 3777c478bd9Sstevel@tonic-gate xfr_exit(YPPUSH_BADARGS); 3787c478bd9Sstevel@tonic-gate } 3797c478bd9Sstevel@tonic-gate 3807c478bd9Sstevel@tonic-gate while (--argc) { 3817c478bd9Sstevel@tonic-gate 3827c478bd9Sstevel@tonic-gate if ((*argv)[0] == '-') { 3837c478bd9Sstevel@tonic-gate 3847c478bd9Sstevel@tonic-gate switch ((*argv)[1]) { 3857c478bd9Sstevel@tonic-gate 3867c478bd9Sstevel@tonic-gate case 'f': { 3877c478bd9Sstevel@tonic-gate force = TRUE; 3887c478bd9Sstevel@tonic-gate argv++; 3897c478bd9Sstevel@tonic-gate break; 3907c478bd9Sstevel@tonic-gate } 3917c478bd9Sstevel@tonic-gate 3927c478bd9Sstevel@tonic-gate case 'D': { 3937c478bd9Sstevel@tonic-gate debug = TRUE; 3947c478bd9Sstevel@tonic-gate argv++; 3957c478bd9Sstevel@tonic-gate break; 3967c478bd9Sstevel@tonic-gate } 3977c478bd9Sstevel@tonic-gate 3987c478bd9Sstevel@tonic-gate case 'T': { 3997c478bd9Sstevel@tonic-gate treepush = TRUE; 4007c478bd9Sstevel@tonic-gate argv++; 4017c478bd9Sstevel@tonic-gate break; 4027c478bd9Sstevel@tonic-gate } 4037c478bd9Sstevel@tonic-gate case 'P': { 4047c478bd9Sstevel@tonic-gate check_count = TRUE; 4057c478bd9Sstevel@tonic-gate argv++; 4067c478bd9Sstevel@tonic-gate break; 4077c478bd9Sstevel@tonic-gate } 4087c478bd9Sstevel@tonic-gate case 'W': { 4097c478bd9Sstevel@tonic-gate defwrite = FALSE; 4107c478bd9Sstevel@tonic-gate argv++; 4117c478bd9Sstevel@tonic-gate break; 4127c478bd9Sstevel@tonic-gate } 4137c478bd9Sstevel@tonic-gate case 'c': { 4147c478bd9Sstevel@tonic-gate send_clear = FALSE; 4157c478bd9Sstevel@tonic-gate argv++; 4167c478bd9Sstevel@tonic-gate break; 4177c478bd9Sstevel@tonic-gate } 4187c478bd9Sstevel@tonic-gate 4197c478bd9Sstevel@tonic-gate case 'h': { 4207c478bd9Sstevel@tonic-gate 4217c478bd9Sstevel@tonic-gate if (argc > 1) { 4227c478bd9Sstevel@tonic-gate argv++; 4237c478bd9Sstevel@tonic-gate argc--; 4247c478bd9Sstevel@tonic-gate master = *argv; 4257c478bd9Sstevel@tonic-gate argv++; 4267c478bd9Sstevel@tonic-gate 4277c478bd9Sstevel@tonic-gate if (strlen(master) > 256) { 4287c478bd9Sstevel@tonic-gate logprintf( 4297c478bd9Sstevel@tonic-gate err_bad_args, 4307c478bd9Sstevel@tonic-gate err_bad_hostname); 4317c478bd9Sstevel@tonic-gate xfr_exit(YPPUSH_BADARGS); 4327c478bd9Sstevel@tonic-gate } 4337c478bd9Sstevel@tonic-gate 4347c478bd9Sstevel@tonic-gate } else { 4357c478bd9Sstevel@tonic-gate logprintf(err_usage); 4367c478bd9Sstevel@tonic-gate xfr_exit(YPPUSH_BADARGS); 4377c478bd9Sstevel@tonic-gate } 4387c478bd9Sstevel@tonic-gate 4397c478bd9Sstevel@tonic-gate break; 4407c478bd9Sstevel@tonic-gate } 4417c478bd9Sstevel@tonic-gate 4427c478bd9Sstevel@tonic-gate case 'd': 4437c478bd9Sstevel@tonic-gate if (argc > 1) { 4447c478bd9Sstevel@tonic-gate argv++; 4457c478bd9Sstevel@tonic-gate argc--; 4467c478bd9Sstevel@tonic-gate domain = *argv; 4477c478bd9Sstevel@tonic-gate argv++; 4487c478bd9Sstevel@tonic-gate 4497c478bd9Sstevel@tonic-gate if (strlen(domain) > YPMAXDOMAIN) { 4507c478bd9Sstevel@tonic-gate logprintf( 4517c478bd9Sstevel@tonic-gate err_bad_args, 4527c478bd9Sstevel@tonic-gate err_bad_domainname); 4537c478bd9Sstevel@tonic-gate xfr_exit(YPPUSH_BADARGS); 4547c478bd9Sstevel@tonic-gate } 4557c478bd9Sstevel@tonic-gate 4567c478bd9Sstevel@tonic-gate } else { 4577c478bd9Sstevel@tonic-gate logprintf(err_usage); 4587c478bd9Sstevel@tonic-gate xfr_exit(YPPUSH_BADARGS); 4597c478bd9Sstevel@tonic-gate } 4607c478bd9Sstevel@tonic-gate break; 4617c478bd9Sstevel@tonic-gate 4627c478bd9Sstevel@tonic-gate case 's': 4637c478bd9Sstevel@tonic-gate if (argc > 1) { 4647c478bd9Sstevel@tonic-gate argv++; 4657c478bd9Sstevel@tonic-gate argc--; 4667c478bd9Sstevel@tonic-gate source = *argv; 4677c478bd9Sstevel@tonic-gate argv++; 4687c478bd9Sstevel@tonic-gate 4697c478bd9Sstevel@tonic-gate if (strlen(source) > YPMAXDOMAIN) { 4707c478bd9Sstevel@tonic-gate logprintf( 4717c478bd9Sstevel@tonic-gate err_bad_args, 4727c478bd9Sstevel@tonic-gate err_bad_domainname); 4737c478bd9Sstevel@tonic-gate xfr_exit(YPPUSH_BADARGS); 4747c478bd9Sstevel@tonic-gate } 4757c478bd9Sstevel@tonic-gate 4767c478bd9Sstevel@tonic-gate } else { 4777c478bd9Sstevel@tonic-gate logprintf(err_usage); 4787c478bd9Sstevel@tonic-gate xfr_exit(YPPUSH_BADARGS); 4797c478bd9Sstevel@tonic-gate } 4807c478bd9Sstevel@tonic-gate break; 4817c478bd9Sstevel@tonic-gate 4827c478bd9Sstevel@tonic-gate case 'C': 4837c478bd9Sstevel@tonic-gate if (argc > 3) { 4847c478bd9Sstevel@tonic-gate callback = TRUE; 4857c478bd9Sstevel@tonic-gate tid = *(++argv); 4867c478bd9Sstevel@tonic-gate proto = *(++argv); 4877c478bd9Sstevel@tonic-gate pushhost = *(++argv); 4887c478bd9Sstevel@tonic-gate if (strlen(pushhost) > 256) { 4897c478bd9Sstevel@tonic-gate logprintf(err_bad_args, err_bad_hostname); 4907c478bd9Sstevel@tonic-gate 4917c478bd9Sstevel@tonic-gate xfr_exit(YPPUSH_BADARGS); 4927c478bd9Sstevel@tonic-gate } 4937c478bd9Sstevel@tonic-gate argc -= 3; 4947c478bd9Sstevel@tonic-gate argv++; 4957c478bd9Sstevel@tonic-gate } else { 4967c478bd9Sstevel@tonic-gate logprintf(err_usage); 4977c478bd9Sstevel@tonic-gate xfr_exit(YPPUSH_BADARGS); 4987c478bd9Sstevel@tonic-gate } 4997c478bd9Sstevel@tonic-gate break; 5007c478bd9Sstevel@tonic-gate 5017c478bd9Sstevel@tonic-gate case 'b': { 5027c478bd9Sstevel@tonic-gate interdomain_map = TRUE; 5037c478bd9Sstevel@tonic-gate interdomain_value = ""; 5047c478bd9Sstevel@tonic-gate interdomain_sz = 0; 5057c478bd9Sstevel@tonic-gate argv++; 5067c478bd9Sstevel@tonic-gate break; 5077c478bd9Sstevel@tonic-gate } 5087c478bd9Sstevel@tonic-gate 5097c478bd9Sstevel@tonic-gate 5107c478bd9Sstevel@tonic-gate default: { 5117c478bd9Sstevel@tonic-gate logprintf(err_usage); 5127c478bd9Sstevel@tonic-gate xfr_exit(YPPUSH_BADARGS); 5137c478bd9Sstevel@tonic-gate } 5147c478bd9Sstevel@tonic-gate 5157c478bd9Sstevel@tonic-gate } 5167c478bd9Sstevel@tonic-gate 5177c478bd9Sstevel@tonic-gate } else { 5187c478bd9Sstevel@tonic-gate 5197c478bd9Sstevel@tonic-gate if (!map) { 5207c478bd9Sstevel@tonic-gate map = *argv; 5217c478bd9Sstevel@tonic-gate argv++; 5227c478bd9Sstevel@tonic-gate 5237c478bd9Sstevel@tonic-gate if (strlen(map) > YPMAXMAP) { 5247c478bd9Sstevel@tonic-gate logprintf(err_bad_args, 5257c478bd9Sstevel@tonic-gate err_bad_mapname); 5267c478bd9Sstevel@tonic-gate xfr_exit(YPPUSH_BADARGS); 5277c478bd9Sstevel@tonic-gate } 5287c478bd9Sstevel@tonic-gate 5297c478bd9Sstevel@tonic-gate } else { 5307c478bd9Sstevel@tonic-gate logprintf(err_usage); 5317c478bd9Sstevel@tonic-gate xfr_exit(YPPUSH_BADARGS); 5327c478bd9Sstevel@tonic-gate } 5337c478bd9Sstevel@tonic-gate } 5347c478bd9Sstevel@tonic-gate } 5357c478bd9Sstevel@tonic-gate 5367c478bd9Sstevel@tonic-gate if (!map) { 5377c478bd9Sstevel@tonic-gate logprintf(err_usage); 5387c478bd9Sstevel@tonic-gate xfr_exit(YPPUSH_BADARGS); 5397c478bd9Sstevel@tonic-gate } 5407c478bd9Sstevel@tonic-gate } 5417c478bd9Sstevel@tonic-gate 5427c478bd9Sstevel@tonic-gate /* 5437c478bd9Sstevel@tonic-gate * This tries to get the master name for the named map, from any 5447c478bd9Sstevel@tonic-gate * server's version, using the vanilla NIS client interface. If we get a 5457c478bd9Sstevel@tonic-gate * name back, the global "master" gets pointed to it. 5467c478bd9Sstevel@tonic-gate */ 5477c478bd9Sstevel@tonic-gate void 5487c478bd9Sstevel@tonic-gate find_map_master() 5497c478bd9Sstevel@tonic-gate { 5507c478bd9Sstevel@tonic-gate int err; 5517c478bd9Sstevel@tonic-gate 5527c478bd9Sstevel@tonic-gate if (err = __yp_master_rsvdport(source, map, &master)) { 5537c478bd9Sstevel@tonic-gate logprintf("Can't get master of %s. Reason: %s.\n", map, 5547c478bd9Sstevel@tonic-gate yperr_string(err)); 5557c478bd9Sstevel@tonic-gate } 5567c478bd9Sstevel@tonic-gate 5577c478bd9Sstevel@tonic-gate yp_unbind(source); 5587c478bd9Sstevel@tonic-gate } 5597c478bd9Sstevel@tonic-gate 5607c478bd9Sstevel@tonic-gate #ifdef TREEPUSH 561*a506a34cSth160488 int 5627c478bd9Sstevel@tonic-gate chk_treepush(name) 5637c478bd9Sstevel@tonic-gate char *name; 5647c478bd9Sstevel@tonic-gate { 5657c478bd9Sstevel@tonic-gate char inmap[256]; 5667c478bd9Sstevel@tonic-gate char inkey[256]; 5677c478bd9Sstevel@tonic-gate int inkeylen; 5687c478bd9Sstevel@tonic-gate char *outval; 5697c478bd9Sstevel@tonic-gate int outvallen; 5707c478bd9Sstevel@tonic-gate int err; 5717c478bd9Sstevel@tonic-gate outval = NULL; 5727c478bd9Sstevel@tonic-gate inkey[0] = 0; 5737c478bd9Sstevel@tonic-gate strcpy(inmap, "ypslaves."); 5747c478bd9Sstevel@tonic-gate strcat(inmap, name); 5757c478bd9Sstevel@tonic-gate gethostname(inkey, 256); 5767c478bd9Sstevel@tonic-gate inkeylen = strlen(inkey); 5777c478bd9Sstevel@tonic-gate 5787c478bd9Sstevel@tonic-gate err = yp_match(source, inmap, inkey, inkeylen, &outval, &outvallen); 5797c478bd9Sstevel@tonic-gate yp_unbind(source); 5807c478bd9Sstevel@tonic-gate return (err); 5817c478bd9Sstevel@tonic-gate } 5827c478bd9Sstevel@tonic-gate #endif 5837c478bd9Sstevel@tonic-gate 5847c478bd9Sstevel@tonic-gate /* 5857c478bd9Sstevel@tonic-gate * This sets up a udp connection to speak the correct program and version 5867c478bd9Sstevel@tonic-gate * to a NIS server. vers is set to YPVERS, doesn't give a damn about 5877c478bd9Sstevel@tonic-gate * YPOLDVERS. 5887c478bd9Sstevel@tonic-gate */ 5897c478bd9Sstevel@tonic-gate bool 5907c478bd9Sstevel@tonic-gate bind_to_server(host, pdomb, vers, status) 5917c478bd9Sstevel@tonic-gate char *host; 5927c478bd9Sstevel@tonic-gate struct dom_binding *pdomb; 5937c478bd9Sstevel@tonic-gate unsigned int *vers; 5947c478bd9Sstevel@tonic-gate int *status; 5957c478bd9Sstevel@tonic-gate { 5967c478bd9Sstevel@tonic-gate if (ping_server(host, pdomb, YPVERS, status)) { 5977c478bd9Sstevel@tonic-gate *vers = YPVERS; 5987c478bd9Sstevel@tonic-gate return (TRUE); 5997c478bd9Sstevel@tonic-gate } else 6007c478bd9Sstevel@tonic-gate return (FALSE); 6017c478bd9Sstevel@tonic-gate } 6027c478bd9Sstevel@tonic-gate 6037c478bd9Sstevel@tonic-gate /* 6047c478bd9Sstevel@tonic-gate * This sets up a UDP channel to a server which is assumed to speak an input 6057c478bd9Sstevel@tonic-gate * version of YPPROG. The channel is tested by pinging the server. In all 6067c478bd9Sstevel@tonic-gate * error cases except "Program Version Number Mismatch", the error is 6077c478bd9Sstevel@tonic-gate * reported, and in all error cases, the client handle is destroyed and the 6087c478bd9Sstevel@tonic-gate * socket associated with the channel is closed. 6097c478bd9Sstevel@tonic-gate */ 6107c478bd9Sstevel@tonic-gate bool 6117c478bd9Sstevel@tonic-gate ping_server(host, pdomb, vers, status) 6127c478bd9Sstevel@tonic-gate char *host; 6137c478bd9Sstevel@tonic-gate struct dom_binding *pdomb; 6147c478bd9Sstevel@tonic-gate unsigned int vers; 6157c478bd9Sstevel@tonic-gate int *status; 6167c478bd9Sstevel@tonic-gate { 6177c478bd9Sstevel@tonic-gate enum clnt_stat rpc_stat; 6187c478bd9Sstevel@tonic-gate 6197c478bd9Sstevel@tonic-gate if ((pdomb->dom_client = __yp_clnt_create_rsvdport(host, YPPROG, vers, 6207c478bd9Sstevel@tonic-gate 0, 0, 0)) != 0) { 6217c478bd9Sstevel@tonic-gate 6227c478bd9Sstevel@tonic-gate /* 6237c478bd9Sstevel@tonic-gate * if we are on a c2 system, we should only accept data 6247c478bd9Sstevel@tonic-gate * from a server which is on a reserved port. 6257c478bd9Sstevel@tonic-gate */ 6267c478bd9Sstevel@tonic-gate /* 6277c478bd9Sstevel@tonic-gate * NUKE this for 5.0DR. 6287c478bd9Sstevel@tonic-gate * 6297c478bd9Sstevel@tonic-gate * if (issecure() && 6307c478bd9Sstevel@tonic-gate * (pdomb->dom_server_addr.sin_family != AF_INET || 6317c478bd9Sstevel@tonic-gate * pdomb->dom_server_addr.sin_port >= IPPORT_RESERVED)) { 6327c478bd9Sstevel@tonic-gate * clnt_destroy(pdomb->dom_client); 6337c478bd9Sstevel@tonic-gate * close(pdomb->dom_socket); 6347c478bd9Sstevel@tonic-gate * (void) logprintf("bind_to_server: \ 6357c478bd9Sstevel@tonic-gate * server is not using a privileged port\n"); 6367c478bd9Sstevel@tonic-gate * *status = YPPUSH_YPERR; 6377c478bd9Sstevel@tonic-gate * return (FALSE); 6387c478bd9Sstevel@tonic-gate * } 6397c478bd9Sstevel@tonic-gate */ 6407c478bd9Sstevel@tonic-gate 6417c478bd9Sstevel@tonic-gate rpc_stat = clnt_call(pdomb->dom_client, YPBINDPROC_NULL, 6427c478bd9Sstevel@tonic-gate xdr_void, 0, xdr_void, 0, udp_timeout); 6437c478bd9Sstevel@tonic-gate 6447c478bd9Sstevel@tonic-gate if (rpc_stat == RPC_SUCCESS) { 6457c478bd9Sstevel@tonic-gate return (TRUE); 6467c478bd9Sstevel@tonic-gate } else { 6477c478bd9Sstevel@tonic-gate clnt_destroy(pdomb->dom_client); 6487c478bd9Sstevel@tonic-gate if (rpc_stat != RPC_PROGVERSMISMATCH) { 6497c478bd9Sstevel@tonic-gate (void) clnt_perror(pdomb->dom_client, 6507c478bd9Sstevel@tonic-gate "ypxfr: bind_to_server clnt_call error"); 6517c478bd9Sstevel@tonic-gate } 6527c478bd9Sstevel@tonic-gate 6537c478bd9Sstevel@tonic-gate *status = YPPUSH_RPC; 6547c478bd9Sstevel@tonic-gate return (FALSE); 6557c478bd9Sstevel@tonic-gate } 6567c478bd9Sstevel@tonic-gate } else { 6577c478bd9Sstevel@tonic-gate logprintf("bind_to_server __clnt_create_rsvd error"); 6587c478bd9Sstevel@tonic-gate (void) clnt_pcreateerror(""); 6597c478bd9Sstevel@tonic-gate fflush(stderr); 6607c478bd9Sstevel@tonic-gate *status = YPPUSH_RPC; 6617c478bd9Sstevel@tonic-gate return (FALSE); 6627c478bd9Sstevel@tonic-gate } 6637c478bd9Sstevel@tonic-gate } 6647c478bd9Sstevel@tonic-gate 6657c478bd9Sstevel@tonic-gate /* 6667c478bd9Sstevel@tonic-gate * This gets values for the YP_LAST_MODIFIED and YP_MASTER_NAME keys from the 6677c478bd9Sstevel@tonic-gate * master server's version of the map. Values are held in static variables 6687c478bd9Sstevel@tonic-gate * here. In the success cases, global pointer variables are set to point at 6697c478bd9Sstevel@tonic-gate * the local statics. 6707c478bd9Sstevel@tonic-gate */ 6717c478bd9Sstevel@tonic-gate bool 6727c478bd9Sstevel@tonic-gate get_private_recs(pushstat) 6737c478bd9Sstevel@tonic-gate int *pushstat; 6747c478bd9Sstevel@tonic-gate { 6757c478bd9Sstevel@tonic-gate static char anumber[20]; 6767c478bd9Sstevel@tonic-gate static unsigned number; 6777c478bd9Sstevel@tonic-gate static char name[YPMAXPEER + 1]; 6787c478bd9Sstevel@tonic-gate int status; 6797c478bd9Sstevel@tonic-gate 6807c478bd9Sstevel@tonic-gate status = 0; 6817c478bd9Sstevel@tonic-gate 6827c478bd9Sstevel@tonic-gate if (get_order(anumber, &number, &status)) { 6837c478bd9Sstevel@tonic-gate master_version = &number; 6847c478bd9Sstevel@tonic-gate master_ascii_version = anumber; 6857c478bd9Sstevel@tonic-gate if (debug) fprintf(stderr, 6867c478bd9Sstevel@tonic-gate "ypxfr: Master Version is %s\n", master_ascii_version); 6877c478bd9Sstevel@tonic-gate } else { 6887c478bd9Sstevel@tonic-gate 6897c478bd9Sstevel@tonic-gate if (status != 0) { 6907c478bd9Sstevel@tonic-gate *pushstat = status; 6917c478bd9Sstevel@tonic-gate if (debug) fprintf(stderr, 6927c478bd9Sstevel@tonic-gate "ypxfr: Couldn't get map's master version number, \ 6937c478bd9Sstevel@tonic-gate status was %d\n", status); 6947c478bd9Sstevel@tonic-gate return (FALSE); 6957c478bd9Sstevel@tonic-gate } 6967c478bd9Sstevel@tonic-gate } 6977c478bd9Sstevel@tonic-gate 6987c478bd9Sstevel@tonic-gate if (get_master_name(name, &status)) { 6997c478bd9Sstevel@tonic-gate master_name = name; 7007c478bd9Sstevel@tonic-gate if (debug) fprintf(stderr, 7017c478bd9Sstevel@tonic-gate "ypxfr: Maps master is '%s'\n", master_name); 7027c478bd9Sstevel@tonic-gate } else { 7037c478bd9Sstevel@tonic-gate 7047c478bd9Sstevel@tonic-gate if (status != 0) { 7057c478bd9Sstevel@tonic-gate *pushstat = status; 7067c478bd9Sstevel@tonic-gate if (debug) fprintf(stderr, 7077c478bd9Sstevel@tonic-gate "ypxfr: Couldn't get map's master name, status was %d\n", 7087c478bd9Sstevel@tonic-gate status); 7097c478bd9Sstevel@tonic-gate return (FALSE); 7107c478bd9Sstevel@tonic-gate } 7117c478bd9Sstevel@tonic-gate master_name = master; 7127c478bd9Sstevel@tonic-gate } 7137c478bd9Sstevel@tonic-gate 7147c478bd9Sstevel@tonic-gate if (debug) 7157c478bd9Sstevel@tonic-gate fprintf(stderr, 7167c478bd9Sstevel@tonic-gate "ypxfr: Getting private records from master.\n"); 7177c478bd9Sstevel@tonic-gate if (get_misc_recs(&status)) { 7187c478bd9Sstevel@tonic-gate if (debug) 7197c478bd9Sstevel@tonic-gate fprintf(stderr, 7207c478bd9Sstevel@tonic-gate "ypxfr: Masters map %s secure and %s an interdomain map.\n", 7217c478bd9Sstevel@tonic-gate (secure_map) ? "is" : "is not", 7227c478bd9Sstevel@tonic-gate (interdomain_map) ? "is" : "is not"); 7237c478bd9Sstevel@tonic-gate } else { 7247c478bd9Sstevel@tonic-gate if (status != 0) { 7257c478bd9Sstevel@tonic-gate *pushstat = status; 7267c478bd9Sstevel@tonic-gate if (debug) 7277c478bd9Sstevel@tonic-gate fprintf(stderr, 7287c478bd9Sstevel@tonic-gate "ypxfr: Couldn't get state of secure and interdomain flags in map.\n"); 7297c478bd9Sstevel@tonic-gate return (FALSE); 7307c478bd9Sstevel@tonic-gate } 7317c478bd9Sstevel@tonic-gate } 7327c478bd9Sstevel@tonic-gate 7337c478bd9Sstevel@tonic-gate return (TRUE); 7347c478bd9Sstevel@tonic-gate } 7357c478bd9Sstevel@tonic-gate 7367c478bd9Sstevel@tonic-gate /* 7377c478bd9Sstevel@tonic-gate * This gets the map's order number from the master server 7387c478bd9Sstevel@tonic-gate */ 7397c478bd9Sstevel@tonic-gate bool 7407c478bd9Sstevel@tonic-gate get_order(an, n, pushstat) 7417c478bd9Sstevel@tonic-gate char *an; 7427c478bd9Sstevel@tonic-gate unsigned *n; 7437c478bd9Sstevel@tonic-gate int *pushstat; 7447c478bd9Sstevel@tonic-gate { 7457c478bd9Sstevel@tonic-gate if (master_prog_vers == YPVERS) { 7467c478bd9Sstevel@tonic-gate return (get_v2order(an, n, pushstat)); 7477c478bd9Sstevel@tonic-gate } else 7487c478bd9Sstevel@tonic-gate return (FALSE); 7497c478bd9Sstevel@tonic-gate } 7507c478bd9Sstevel@tonic-gate 7517c478bd9Sstevel@tonic-gate bool 7527c478bd9Sstevel@tonic-gate get_v2order(an, n, pushstat) 7537c478bd9Sstevel@tonic-gate char *an; 7547c478bd9Sstevel@tonic-gate unsigned *n; 7557c478bd9Sstevel@tonic-gate int *pushstat; 7567c478bd9Sstevel@tonic-gate { 7577c478bd9Sstevel@tonic-gate struct ypreq_nokey req; 7587c478bd9Sstevel@tonic-gate struct ypresp_order resp; 7597c478bd9Sstevel@tonic-gate int retval; 7607c478bd9Sstevel@tonic-gate 7617c478bd9Sstevel@tonic-gate req.domain = source; 7627c478bd9Sstevel@tonic-gate req.map = map; 7637c478bd9Sstevel@tonic-gate 7647c478bd9Sstevel@tonic-gate /* 7657c478bd9Sstevel@tonic-gate * Get the map''s order number, null-terminate it and store it, 7667c478bd9Sstevel@tonic-gate * and convert it to binary and store it again. 7677c478bd9Sstevel@tonic-gate */ 7687c478bd9Sstevel@tonic-gate retval = FALSE; 7697c478bd9Sstevel@tonic-gate 7707c478bd9Sstevel@tonic-gate if ((enum clnt_stat) clnt_call(master_server.dom_client, 7717c478bd9Sstevel@tonic-gate YPPROC_ORDER, (xdrproc_t)xdr_ypreq_nokey, (char *)&req, 7727c478bd9Sstevel@tonic-gate (xdrproc_t)xdr_ypresp_order, (char *)&resp, 7737c478bd9Sstevel@tonic-gate udp_timeout) == RPC_SUCCESS) { 7747c478bd9Sstevel@tonic-gate 7757c478bd9Sstevel@tonic-gate if (resp.status == YP_TRUE) { 7767c478bd9Sstevel@tonic-gate sprintf(an, "%d", resp.ordernum); 7777c478bd9Sstevel@tonic-gate *n = resp.ordernum; 7787c478bd9Sstevel@tonic-gate retval = TRUE; 7797c478bd9Sstevel@tonic-gate } else if (resp.status != YP_BADDB) { 7807c478bd9Sstevel@tonic-gate *pushstat = ypprot_err(resp.status); 7817c478bd9Sstevel@tonic-gate 7827c478bd9Sstevel@tonic-gate if (!logging) { 7837c478bd9Sstevel@tonic-gate logprintf( 7847c478bd9Sstevel@tonic-gate "(info) Can't get order number from ypserv at %s. Reason: %s.\n", 7857c478bd9Sstevel@tonic-gate master, yperr_string( 7867c478bd9Sstevel@tonic-gate ypprot_err(resp.status))); 7877c478bd9Sstevel@tonic-gate } 7887c478bd9Sstevel@tonic-gate } 7897c478bd9Sstevel@tonic-gate 7907c478bd9Sstevel@tonic-gate CLNT_FREERES(master_server.dom_client, 7917c478bd9Sstevel@tonic-gate (xdrproc_t)xdr_ypresp_order, 7927c478bd9Sstevel@tonic-gate (char *)&resp); 7937c478bd9Sstevel@tonic-gate } else { 7947c478bd9Sstevel@tonic-gate *pushstat = YPPUSH_RPC; 7957c478bd9Sstevel@tonic-gate logprintf("ypxfr(get_v2order) RPC call to %s failed", master); 7967c478bd9Sstevel@tonic-gate clnt_perror(master_server.dom_client, ""); 7977c478bd9Sstevel@tonic-gate } 7987c478bd9Sstevel@tonic-gate 7997c478bd9Sstevel@tonic-gate return (retval); 8007c478bd9Sstevel@tonic-gate } 8017c478bd9Sstevel@tonic-gate 8027c478bd9Sstevel@tonic-gate /* 8037c478bd9Sstevel@tonic-gate * Pick up the state of the YP_SECURE and YP_INTERDOMAIN records from the 8047c478bd9Sstevel@tonic-gate * master. Only works on 4.0 V2 masters that will match a YP_ private key 8057c478bd9Sstevel@tonic-gate * when asked to explicitly. 8067c478bd9Sstevel@tonic-gate */ 8077c478bd9Sstevel@tonic-gate bool 8087c478bd9Sstevel@tonic-gate get_misc_recs(pushstat) 8097c478bd9Sstevel@tonic-gate int *pushstat; 8107c478bd9Sstevel@tonic-gate { 8117c478bd9Sstevel@tonic-gate struct ypreq_key req; 8127c478bd9Sstevel@tonic-gate struct ypresp_val resp; 8137c478bd9Sstevel@tonic-gate int retval; 8147c478bd9Sstevel@tonic-gate 8157c478bd9Sstevel@tonic-gate req.domain = source; 8167c478bd9Sstevel@tonic-gate req.map = map; 8177c478bd9Sstevel@tonic-gate req.keydat.dptr = yp_secure; 8187c478bd9Sstevel@tonic-gate req.keydat.dsize = yp_secure_sz; 8197c478bd9Sstevel@tonic-gate 8207c478bd9Sstevel@tonic-gate resp.valdat.dptr = NULL; 8217c478bd9Sstevel@tonic-gate resp.valdat.dsize = 0; 8227c478bd9Sstevel@tonic-gate 8237c478bd9Sstevel@tonic-gate /* 8247c478bd9Sstevel@tonic-gate * Get the value of the IS_SECURE key in the map. 8257c478bd9Sstevel@tonic-gate */ 8267c478bd9Sstevel@tonic-gate retval = FALSE; 8277c478bd9Sstevel@tonic-gate 8287c478bd9Sstevel@tonic-gate if (debug) 8297c478bd9Sstevel@tonic-gate fprintf(stderr, "ypxfr: Checking masters secure key.\n"); 8307c478bd9Sstevel@tonic-gate if ((enum clnt_stat) clnt_call(master_server.dom_client, 8317c478bd9Sstevel@tonic-gate YPPROC_MATCH, (xdrproc_t)xdr_ypreq_key, (char *)&req, 8327c478bd9Sstevel@tonic-gate (xdrproc_t)xdr_ypresp_val, (char *)&resp, 8337c478bd9Sstevel@tonic-gate udp_timeout) == RPC_SUCCESS) { 8347c478bd9Sstevel@tonic-gate if (resp.status == YP_TRUE) { 8357c478bd9Sstevel@tonic-gate if (debug) 8367c478bd9Sstevel@tonic-gate fprintf(stderr, "ypxfr: SECURE\n"); 8377c478bd9Sstevel@tonic-gate secure_map = TRUE; 8387c478bd9Sstevel@tonic-gate retval = TRUE; 8397c478bd9Sstevel@tonic-gate } else if ((resp.status != YP_NOKEY) && 8407c478bd9Sstevel@tonic-gate (resp.status != YP_VERS) && 8417c478bd9Sstevel@tonic-gate (resp.status != YP_NOMORE)) { 8427c478bd9Sstevel@tonic-gate *pushstat = ypprot_err(resp.status); 8437c478bd9Sstevel@tonic-gate 8447c478bd9Sstevel@tonic-gate if (!logging) { 8457c478bd9Sstevel@tonic-gate logprintf( 8467c478bd9Sstevel@tonic-gate "(info) Can't get secure flag from ypserv at %s. Reason: %s.\n", 8477c478bd9Sstevel@tonic-gate master, yperr_string( 8487c478bd9Sstevel@tonic-gate ypprot_err(resp.status))); 8497c478bd9Sstevel@tonic-gate } 8507c478bd9Sstevel@tonic-gate } 8517c478bd9Sstevel@tonic-gate 8527c478bd9Sstevel@tonic-gate CLNT_FREERES(master_server.dom_client, 8537c478bd9Sstevel@tonic-gate (xdrproc_t)xdr_ypresp_val, 8547c478bd9Sstevel@tonic-gate (char *)&resp); 8557c478bd9Sstevel@tonic-gate } else { 8567c478bd9Sstevel@tonic-gate *pushstat = YPPUSH_RPC; 8577c478bd9Sstevel@tonic-gate logprintf("ypxfr(get_misc_recs) RPC call to %s failed", master); 8587c478bd9Sstevel@tonic-gate clnt_perror(master_server.dom_client, ""); 8597c478bd9Sstevel@tonic-gate } 8607c478bd9Sstevel@tonic-gate 8617c478bd9Sstevel@tonic-gate if (debug) 8627c478bd9Sstevel@tonic-gate fprintf(stderr, "ypxfr: Checking masters INTERDOMAIN key.\n"); 8637c478bd9Sstevel@tonic-gate req.keydat.dptr = yp_interdomain; 8647c478bd9Sstevel@tonic-gate req.keydat.dsize = yp_interdomain_sz; 8657c478bd9Sstevel@tonic-gate 8667c478bd9Sstevel@tonic-gate resp.valdat.dptr = NULL; 8677c478bd9Sstevel@tonic-gate resp.valdat.dsize = 0; 8687c478bd9Sstevel@tonic-gate 8697c478bd9Sstevel@tonic-gate /* 8707c478bd9Sstevel@tonic-gate * Get the value of the INTERDOMAIN key in the map. 8717c478bd9Sstevel@tonic-gate */ 8727c478bd9Sstevel@tonic-gate 8737c478bd9Sstevel@tonic-gate if ((enum clnt_stat) clnt_call(master_server.dom_client, 8747c478bd9Sstevel@tonic-gate YPPROC_MATCH, (xdrproc_t)xdr_ypreq_key, (char *)&req, 8757c478bd9Sstevel@tonic-gate (xdrproc_t)xdr_ypresp_val, (char *)&resp, 8767c478bd9Sstevel@tonic-gate udp_timeout) == RPC_SUCCESS) { 8777c478bd9Sstevel@tonic-gate if (resp.status == YP_TRUE) { 8787c478bd9Sstevel@tonic-gate if (debug) 8797c478bd9Sstevel@tonic-gate fprintf(stderr, "ypxfr: INTERDOMAIN\n"); 8807c478bd9Sstevel@tonic-gate interdomain_map = TRUE; 8817c478bd9Sstevel@tonic-gate interdomain_value = (char *)malloc(resp.valdat.dsize+1); 8827c478bd9Sstevel@tonic-gate (void) memmove(interdomain_value, resp.valdat.dptr, 8837c478bd9Sstevel@tonic-gate resp.valdat.dsize); 8847c478bd9Sstevel@tonic-gate *(interdomain_value+resp.valdat.dsize) = '\0'; 8857c478bd9Sstevel@tonic-gate interdomain_sz = resp.valdat.dsize; 8867c478bd9Sstevel@tonic-gate retval = TRUE; 8877c478bd9Sstevel@tonic-gate } else if ((resp.status != YP_NOKEY) && 8887c478bd9Sstevel@tonic-gate (resp.status != YP_VERS) && 8897c478bd9Sstevel@tonic-gate (resp.status != YP_NOMORE)) { 8907c478bd9Sstevel@tonic-gate *pushstat = ypprot_err(resp.status); 8917c478bd9Sstevel@tonic-gate 8927c478bd9Sstevel@tonic-gate if (!logging) { 8937c478bd9Sstevel@tonic-gate logprintf( 8947c478bd9Sstevel@tonic-gate "(info) Can't get interdomain flag from ypserv at %s. Reason: %s.\n", 8957c478bd9Sstevel@tonic-gate master, yperr_string( 8967c478bd9Sstevel@tonic-gate ypprot_err(resp.status))); 8977c478bd9Sstevel@tonic-gate } 8987c478bd9Sstevel@tonic-gate } 8997c478bd9Sstevel@tonic-gate 9007c478bd9Sstevel@tonic-gate CLNT_FREERES(master_server.dom_client, 9017c478bd9Sstevel@tonic-gate (xdrproc_t)xdr_ypresp_val, 9027c478bd9Sstevel@tonic-gate (char *)&resp); 9037c478bd9Sstevel@tonic-gate } else { 9047c478bd9Sstevel@tonic-gate *pushstat = YPPUSH_RPC; 9057c478bd9Sstevel@tonic-gate logprintf("ypxfr(get_misc_recs) RPC call to %s failed", master); 9067c478bd9Sstevel@tonic-gate clnt_perror(master_server.dom_client, ""); 9077c478bd9Sstevel@tonic-gate } 9087c478bd9Sstevel@tonic-gate 9097c478bd9Sstevel@tonic-gate 9107c478bd9Sstevel@tonic-gate return (retval); 9117c478bd9Sstevel@tonic-gate } 9127c478bd9Sstevel@tonic-gate 9137c478bd9Sstevel@tonic-gate /* 9147c478bd9Sstevel@tonic-gate * This gets the map's master name from the master server 9157c478bd9Sstevel@tonic-gate */ 9167c478bd9Sstevel@tonic-gate bool 9177c478bd9Sstevel@tonic-gate get_master_name(name, pushstat) 9187c478bd9Sstevel@tonic-gate char *name; 9197c478bd9Sstevel@tonic-gate int *pushstat; 9207c478bd9Sstevel@tonic-gate { 9217c478bd9Sstevel@tonic-gate if (master_prog_vers == YPVERS) { 9227c478bd9Sstevel@tonic-gate return (get_v2master_name(name, pushstat)); 9237c478bd9Sstevel@tonic-gate } else 9247c478bd9Sstevel@tonic-gate return (FALSE); 9257c478bd9Sstevel@tonic-gate } 9267c478bd9Sstevel@tonic-gate 9277c478bd9Sstevel@tonic-gate bool 9287c478bd9Sstevel@tonic-gate get_v2master_name(name, pushstat) 9297c478bd9Sstevel@tonic-gate char *name; 9307c478bd9Sstevel@tonic-gate int *pushstat; 9317c478bd9Sstevel@tonic-gate { 9327c478bd9Sstevel@tonic-gate struct ypreq_nokey req; 9337c478bd9Sstevel@tonic-gate struct ypresp_master resp; 9347c478bd9Sstevel@tonic-gate int retval; 9357c478bd9Sstevel@tonic-gate 9367c478bd9Sstevel@tonic-gate req.domain = source; 9377c478bd9Sstevel@tonic-gate req.map = map; 9387c478bd9Sstevel@tonic-gate resp.master = NULL; 9397c478bd9Sstevel@tonic-gate retval = FALSE; 9407c478bd9Sstevel@tonic-gate 9417c478bd9Sstevel@tonic-gate if ((enum clnt_stat) clnt_call(master_server.dom_client, 9427c478bd9Sstevel@tonic-gate YPPROC_MASTER, (xdrproc_t)xdr_ypreq_nokey, (char *)&req, 9437c478bd9Sstevel@tonic-gate (xdrproc_t)xdr_ypresp_master, (char *)&resp, 9447c478bd9Sstevel@tonic-gate udp_timeout) == RPC_SUCCESS) { 9457c478bd9Sstevel@tonic-gate 9467c478bd9Sstevel@tonic-gate if (resp.status == YP_TRUE) { 9477c478bd9Sstevel@tonic-gate strcpy(name, resp.master); 9487c478bd9Sstevel@tonic-gate retval = TRUE; 9497c478bd9Sstevel@tonic-gate } else if (resp.status != YP_BADDB) { 9507c478bd9Sstevel@tonic-gate *pushstat = ypprot_err(resp.status); 9517c478bd9Sstevel@tonic-gate 9527c478bd9Sstevel@tonic-gate if (!logging) { 9537c478bd9Sstevel@tonic-gate logprintf( 9547c478bd9Sstevel@tonic-gate "(info) Can't get master name from ypserv at %s. Reason: %s.\n", 9557c478bd9Sstevel@tonic-gate master, yperr_string( 9567c478bd9Sstevel@tonic-gate ypprot_err(resp.status))); 9577c478bd9Sstevel@tonic-gate } 9587c478bd9Sstevel@tonic-gate } 9597c478bd9Sstevel@tonic-gate 9607c478bd9Sstevel@tonic-gate CLNT_FREERES(master_server.dom_client, 9617c478bd9Sstevel@tonic-gate (xdrproc_t)xdr_ypresp_master, 9627c478bd9Sstevel@tonic-gate (char *)&resp); 9637c478bd9Sstevel@tonic-gate } else { 9647c478bd9Sstevel@tonic-gate *pushstat = YPPUSH_RPC; 9657c478bd9Sstevel@tonic-gate logprintf( 9667c478bd9Sstevel@tonic-gate "ypxfr(get_v2master_name) RPC call to %s failed", master); 9677c478bd9Sstevel@tonic-gate clnt_perror(master_server.dom_client, ""); 9687c478bd9Sstevel@tonic-gate } 9697c478bd9Sstevel@tonic-gate 9707c478bd9Sstevel@tonic-gate return (retval); 9717c478bd9Sstevel@tonic-gate } 9727c478bd9Sstevel@tonic-gate 9737c478bd9Sstevel@tonic-gate /* 9747c478bd9Sstevel@tonic-gate * This does the work of transferring the map. 9757c478bd9Sstevel@tonic-gate */ 9767c478bd9Sstevel@tonic-gate bool 9777c478bd9Sstevel@tonic-gate move_map(pushstat) 9787c478bd9Sstevel@tonic-gate int *pushstat; 9797c478bd9Sstevel@tonic-gate { 9807c478bd9Sstevel@tonic-gate unsigned local_version; 9817c478bd9Sstevel@tonic-gate char map_name[MAXNAMLEN + 1]; 9827c478bd9Sstevel@tonic-gate char tmp_name[MAXNAMLEN + 1]; 9837c478bd9Sstevel@tonic-gate char bkup_name[MAXNAMLEN + 1]; 9847c478bd9Sstevel@tonic-gate char an[11]; 9857c478bd9Sstevel@tonic-gate unsigned n; 9867c478bd9Sstevel@tonic-gate datum key; 9877c478bd9Sstevel@tonic-gate datum val; 9887c478bd9Sstevel@tonic-gate int hgstatus; 9897c478bd9Sstevel@tonic-gate 9907c478bd9Sstevel@tonic-gate mkfilename(map_name); 9917c478bd9Sstevel@tonic-gate 9927c478bd9Sstevel@tonic-gate if (!force) { 9937c478bd9Sstevel@tonic-gate local_version = get_local_version(map_name); 9947c478bd9Sstevel@tonic-gate if (debug) fprintf(stderr, 9957c478bd9Sstevel@tonic-gate "ypxfr: Local version of map '%s' is %d\n", 9967c478bd9Sstevel@tonic-gate map_name, local_version); 9977c478bd9Sstevel@tonic-gate 9987c478bd9Sstevel@tonic-gate if (local_version >= *master_version) { 9997c478bd9Sstevel@tonic-gate logprintf( 10007c478bd9Sstevel@tonic-gate "Map %s at %s is not more recent than local.\n", 10017c478bd9Sstevel@tonic-gate map, master); 10027c478bd9Sstevel@tonic-gate *pushstat = YPPUSH_AGE; 10037c478bd9Sstevel@tonic-gate return (FALSE); 10047c478bd9Sstevel@tonic-gate } 10057c478bd9Sstevel@tonic-gate } 10067c478bd9Sstevel@tonic-gate 10077c478bd9Sstevel@tonic-gate mk_tmpname(yptempname_prefix, tmp_name); 10087c478bd9Sstevel@tonic-gate 10097c478bd9Sstevel@tonic-gate if (!new_mapfiles(tmp_name)) { 10107c478bd9Sstevel@tonic-gate logprintf( 10117c478bd9Sstevel@tonic-gate "Can't create temp map %s.\n", tmp_name); 10127c478bd9Sstevel@tonic-gate *pushstat = YPPUSH_FILE; 10137c478bd9Sstevel@tonic-gate return (FALSE); 10147c478bd9Sstevel@tonic-gate } 10157c478bd9Sstevel@tonic-gate 10167c478bd9Sstevel@tonic-gate if ((hgstatus = ypxfrd_getdbm(tmp_name, master, source, map)) < 0) 10177c478bd9Sstevel@tonic-gate { 10187c478bd9Sstevel@tonic-gate logprintf( 10197c478bd9Sstevel@tonic-gate "(info) %s %s %s ypxfrd getdbm failed (reason = %d) -- using ypxfr\n", 10207c478bd9Sstevel@tonic-gate master, domain, map, hgstatus); 10217c478bd9Sstevel@tonic-gate 10227c478bd9Sstevel@tonic-gate db = dbm_open(tmp_name, O_RDWR + O_CREAT + O_TRUNC, 0644); 10237c478bd9Sstevel@tonic-gate if (db == NULL) { 10247c478bd9Sstevel@tonic-gate logprintf( 10257c478bd9Sstevel@tonic-gate "Can't dbm init temp map %s.\n", tmp_name); 10267c478bd9Sstevel@tonic-gate del_mapfiles(tmp_name); 10277c478bd9Sstevel@tonic-gate *pushstat = YPPUSH_DBM; 10287c478bd9Sstevel@tonic-gate return (FALSE); 10297c478bd9Sstevel@tonic-gate } 10307c478bd9Sstevel@tonic-gate if (defwrite) dbm_setdefwrite(db); 10317c478bd9Sstevel@tonic-gate 10327c478bd9Sstevel@tonic-gate if (!get_map(tmp_name, pushstat)) { 10337c478bd9Sstevel@tonic-gate del_mapfiles(tmp_name); 10347c478bd9Sstevel@tonic-gate return (FALSE); 10357c478bd9Sstevel@tonic-gate } 10367c478bd9Sstevel@tonic-gate 10377c478bd9Sstevel@tonic-gate if (!add_private_entries(tmp_name)) { 10387c478bd9Sstevel@tonic-gate del_mapfiles(tmp_name); 10397c478bd9Sstevel@tonic-gate *pushstat = YPPUSH_DBM; 10407c478bd9Sstevel@tonic-gate return (FALSE); 10417c478bd9Sstevel@tonic-gate } 10427c478bd9Sstevel@tonic-gate 10437c478bd9Sstevel@tonic-gate /* 10447c478bd9Sstevel@tonic-gate * Decide whether the map just transferred is a secure map. 10457c478bd9Sstevel@tonic-gate * If we already know the local version was secure, we do not 10467c478bd9Sstevel@tonic-gate * need to check this version. 10477c478bd9Sstevel@tonic-gate */ 10487c478bd9Sstevel@tonic-gate if (!secure_map) { 10497c478bd9Sstevel@tonic-gate key.dptr = yp_secure; 10507c478bd9Sstevel@tonic-gate key.dsize = yp_secure_sz; 10517c478bd9Sstevel@tonic-gate val = dbm_fetch(db, key); 10527c478bd9Sstevel@tonic-gate if (val.dptr != NULL) { 10537c478bd9Sstevel@tonic-gate secure_map = TRUE; 10547c478bd9Sstevel@tonic-gate } 10557c478bd9Sstevel@tonic-gate } 10567c478bd9Sstevel@tonic-gate 10577c478bd9Sstevel@tonic-gate if (dbm_close_status(db) < 0) { 10587c478bd9Sstevel@tonic-gate logprintf( 10597c478bd9Sstevel@tonic-gate "Can't do dbm close operation on temp map %s.\n", 10607c478bd9Sstevel@tonic-gate tmp_name); 10617c478bd9Sstevel@tonic-gate del_mapfiles(tmp_name); 10627c478bd9Sstevel@tonic-gate *pushstat = YPPUSH_DBM; 10637c478bd9Sstevel@tonic-gate return (FALSE); 10647c478bd9Sstevel@tonic-gate } 10657c478bd9Sstevel@tonic-gate 10667c478bd9Sstevel@tonic-gate if (!get_order(an, &n, pushstat)) { 10677c478bd9Sstevel@tonic-gate return (FALSE); 10687c478bd9Sstevel@tonic-gate } 10697c478bd9Sstevel@tonic-gate if (n != *master_version) { 10707c478bd9Sstevel@tonic-gate logprintf( 10717c478bd9Sstevel@tonic-gate "Version skew at %s while transferring map %s.\n", 10727c478bd9Sstevel@tonic-gate master, map); 10737c478bd9Sstevel@tonic-gate del_mapfiles(tmp_name); 10747c478bd9Sstevel@tonic-gate *pushstat = YPPUSH_SKEW; 10757c478bd9Sstevel@tonic-gate return (FALSE); 10767c478bd9Sstevel@tonic-gate } 10777c478bd9Sstevel@tonic-gate 10787c478bd9Sstevel@tonic-gate if (check_count) 10797c478bd9Sstevel@tonic-gate if (!count_mismatch(tmp_name, entry_count)) { 10807c478bd9Sstevel@tonic-gate del_mapfiles(tmp_name); 10817c478bd9Sstevel@tonic-gate *pushstat = YPPUSH_DBM; 10827c478bd9Sstevel@tonic-gate return (FALSE); 10837c478bd9Sstevel@tonic-gate } 10847c478bd9Sstevel@tonic-gate } else { 10857c478bd9Sstevel@tonic-gate /* touch up the map */ 10867c478bd9Sstevel@tonic-gate db = dbm_open(tmp_name, 2, 0644); 10877c478bd9Sstevel@tonic-gate if (db == NULL) { 10887c478bd9Sstevel@tonic-gate logprintf( 10897c478bd9Sstevel@tonic-gate "Can't dbm init temp map %s.\n", tmp_name); 10907c478bd9Sstevel@tonic-gate del_mapfiles(tmp_name); 10917c478bd9Sstevel@tonic-gate *pushstat = YPPUSH_DBM; 10927c478bd9Sstevel@tonic-gate return (FALSE); 10937c478bd9Sstevel@tonic-gate } 10947c478bd9Sstevel@tonic-gate 10957c478bd9Sstevel@tonic-gate 10967c478bd9Sstevel@tonic-gate if (!add_private_entries(tmp_name)) { 10977c478bd9Sstevel@tonic-gate del_mapfiles(tmp_name); 10987c478bd9Sstevel@tonic-gate *pushstat = YPPUSH_DBM; 10997c478bd9Sstevel@tonic-gate return (FALSE); 11007c478bd9Sstevel@tonic-gate } 11017c478bd9Sstevel@tonic-gate 11027c478bd9Sstevel@tonic-gate /* 11037c478bd9Sstevel@tonic-gate * Decide whether the map just transferred is a secure map. 11047c478bd9Sstevel@tonic-gate * If we already know the local version was secure, we do not 11057c478bd9Sstevel@tonic-gate * need to check this version. 11067c478bd9Sstevel@tonic-gate */ 11077c478bd9Sstevel@tonic-gate if (!secure_map) { 11087c478bd9Sstevel@tonic-gate key.dptr = yp_secure; 11097c478bd9Sstevel@tonic-gate key.dsize = yp_secure_sz; 11107c478bd9Sstevel@tonic-gate val = dbm_fetch(db, key); 11117c478bd9Sstevel@tonic-gate if (val.dptr != NULL) { 11127c478bd9Sstevel@tonic-gate secure_map = TRUE; 11137c478bd9Sstevel@tonic-gate } 11147c478bd9Sstevel@tonic-gate } 11157c478bd9Sstevel@tonic-gate 11167c478bd9Sstevel@tonic-gate if (dbm_close_status(db) < 0) { 11177c478bd9Sstevel@tonic-gate logprintf( 11187c478bd9Sstevel@tonic-gate "Can't do dbm close operation on temp map %s.\n", 11197c478bd9Sstevel@tonic-gate tmp_name); 11207c478bd9Sstevel@tonic-gate del_mapfiles(tmp_name); 11217c478bd9Sstevel@tonic-gate *pushstat = YPPUSH_DBM; 11227c478bd9Sstevel@tonic-gate return (FALSE); 11237c478bd9Sstevel@tonic-gate } 11247c478bd9Sstevel@tonic-gate 11257c478bd9Sstevel@tonic-gate } 11267c478bd9Sstevel@tonic-gate 11277c478bd9Sstevel@tonic-gate if (lock_map(map_name) == 0) { 11287c478bd9Sstevel@tonic-gate del_mapfiles(tmp_name); 11297c478bd9Sstevel@tonic-gate logprintf("Lock error on %s\n", map_name); 11307c478bd9Sstevel@tonic-gate *pushstat = YPPUSH_FILE; 11317c478bd9Sstevel@tonic-gate return (FALSE); 11327c478bd9Sstevel@tonic-gate } 11337c478bd9Sstevel@tonic-gate if (!check_map_existence(map_name)) { 11347c478bd9Sstevel@tonic-gate 11357c478bd9Sstevel@tonic-gate if (!rename_map(tmp_name, map_name, secure_map)) { 11367c478bd9Sstevel@tonic-gate del_mapfiles(tmp_name); 11377c478bd9Sstevel@tonic-gate logprintf( 11387c478bd9Sstevel@tonic-gate "Rename error: couldn't mv %s to %s.\n", 11397c478bd9Sstevel@tonic-gate tmp_name, map_name); 11407c478bd9Sstevel@tonic-gate *pushstat = YPPUSH_FILE; 11417c478bd9Sstevel@tonic-gate unlock_map(map_name); 11427c478bd9Sstevel@tonic-gate return (FALSE); 11437c478bd9Sstevel@tonic-gate } 11447c478bd9Sstevel@tonic-gate 11457c478bd9Sstevel@tonic-gate } else { 11467c478bd9Sstevel@tonic-gate mk_tmpname(ypbkupname_prefix, bkup_name); 11477c478bd9Sstevel@tonic-gate 11487c478bd9Sstevel@tonic-gate if (!rename_map(map_name, bkup_name, secure_map)) { 11497c478bd9Sstevel@tonic-gate (void) rename_map(bkup_name, map_name, secure_map); 11507c478bd9Sstevel@tonic-gate logprintf( 11517c478bd9Sstevel@tonic-gate "Rename error: check that old %s is still intact.\n", 11527c478bd9Sstevel@tonic-gate map_name); 11537c478bd9Sstevel@tonic-gate del_mapfiles(tmp_name); 11547c478bd9Sstevel@tonic-gate *pushstat = YPPUSH_FILE; 11557c478bd9Sstevel@tonic-gate unlock_map(map_name); 11567c478bd9Sstevel@tonic-gate return (FALSE); 11577c478bd9Sstevel@tonic-gate } 11587c478bd9Sstevel@tonic-gate 11597c478bd9Sstevel@tonic-gate if (rename_map(tmp_name, map_name, secure_map)) { 11607c478bd9Sstevel@tonic-gate del_mapfiles(bkup_name); 11617c478bd9Sstevel@tonic-gate } else { 11627c478bd9Sstevel@tonic-gate del_mapfiles(tmp_name); 11637c478bd9Sstevel@tonic-gate (void) rename_map(bkup_name, map_name, secure_map); 11647c478bd9Sstevel@tonic-gate logprintf( 11657c478bd9Sstevel@tonic-gate "Rename error: check that old %s is still intact.\n", 11667c478bd9Sstevel@tonic-gate map_name); 11677c478bd9Sstevel@tonic-gate *pushstat = YPPUSH_FILE; 11687c478bd9Sstevel@tonic-gate unlock_map(map_name); 11697c478bd9Sstevel@tonic-gate return (FALSE); 11707c478bd9Sstevel@tonic-gate } 11717c478bd9Sstevel@tonic-gate } 11727c478bd9Sstevel@tonic-gate if (unlock_map(map_name) == 0) 11737c478bd9Sstevel@tonic-gate return (FALSE); 11747c478bd9Sstevel@tonic-gate 11757c478bd9Sstevel@tonic-gate return (TRUE); 11767c478bd9Sstevel@tonic-gate } 11777c478bd9Sstevel@tonic-gate 11787c478bd9Sstevel@tonic-gate /* 11797c478bd9Sstevel@tonic-gate * This tries to get the order number out of the local version of the map. 11807c478bd9Sstevel@tonic-gate * If the attempt fails for any version, the function will return "0" 11817c478bd9Sstevel@tonic-gate */ 11827c478bd9Sstevel@tonic-gate unsigned 11837c478bd9Sstevel@tonic-gate get_local_version(name) 11847c478bd9Sstevel@tonic-gate char *name; 11857c478bd9Sstevel@tonic-gate { 11867c478bd9Sstevel@tonic-gate datum key; 11877c478bd9Sstevel@tonic-gate datum val; 11887c478bd9Sstevel@tonic-gate char number[11]; 11897c478bd9Sstevel@tonic-gate DBM *db; 11907c478bd9Sstevel@tonic-gate 11917c478bd9Sstevel@tonic-gate if (!check_map_existence(name)) { 11927c478bd9Sstevel@tonic-gate return (0); 11937c478bd9Sstevel@tonic-gate } 11947c478bd9Sstevel@tonic-gate if (debug) fprintf(stderr, 11957c478bd9Sstevel@tonic-gate "ypxfr: Map does exist, checking version now.\n"); 11967c478bd9Sstevel@tonic-gate 11977c478bd9Sstevel@tonic-gate if ((db = dbm_open(name, 0, 0)) == 0) { 11987c478bd9Sstevel@tonic-gate return (0); 11997c478bd9Sstevel@tonic-gate } 12007c478bd9Sstevel@tonic-gate 12017c478bd9Sstevel@tonic-gate key.dptr = yp_last_modified; 12027c478bd9Sstevel@tonic-gate key.dsize = yp_last_modified_sz; 12037c478bd9Sstevel@tonic-gate val = dbm_fetch(db, key); 12047c478bd9Sstevel@tonic-gate if (!val.dptr) { /* Check to see if dptr is NULL */ 12057c478bd9Sstevel@tonic-gate return (0); 12067c478bd9Sstevel@tonic-gate } 12077c478bd9Sstevel@tonic-gate if (val.dsize == 0 || val.dsize > 10) { 12087c478bd9Sstevel@tonic-gate return (0); 12097c478bd9Sstevel@tonic-gate } 12107c478bd9Sstevel@tonic-gate /* Now save this value while we have it available */ 12117c478bd9Sstevel@tonic-gate (void) memmove(number, val.dptr, val.dsize); 12127c478bd9Sstevel@tonic-gate number[val.dsize] = '\0'; 12137c478bd9Sstevel@tonic-gate 12147c478bd9Sstevel@tonic-gate /* 12157c478bd9Sstevel@tonic-gate * Now check to see if it is 'secure'. If we haven't already 12167c478bd9Sstevel@tonic-gate * determined that it is secure in get_private_recs() then we check 12177c478bd9Sstevel@tonic-gate * the local map here. 12187c478bd9Sstevel@tonic-gate */ 12197c478bd9Sstevel@tonic-gate if (!secure_map) { 12207c478bd9Sstevel@tonic-gate key.dptr = yp_secure; 12217c478bd9Sstevel@tonic-gate key.dsize = yp_secure_sz; 12227c478bd9Sstevel@tonic-gate val = dbm_fetch(db, key); 12237c478bd9Sstevel@tonic-gate secure_map = (val.dptr != NULL); 12247c478bd9Sstevel@tonic-gate } 12257c478bd9Sstevel@tonic-gate 12267c478bd9Sstevel@tonic-gate /* 12277c478bd9Sstevel@tonic-gate * Now check to see if interdomain requests are made of the local 12287c478bd9Sstevel@tonic-gate * map. Keep the value around if they are. 12297c478bd9Sstevel@tonic-gate */ 12307c478bd9Sstevel@tonic-gate if (!interdomain_map) { 12317c478bd9Sstevel@tonic-gate key.dptr = yp_interdomain; 12327c478bd9Sstevel@tonic-gate key.dsize = yp_interdomain_sz; 12337c478bd9Sstevel@tonic-gate val = dbm_fetch(db, key); 12347c478bd9Sstevel@tonic-gate if (interdomain_map = (val.dptr != NULL)) { 12357c478bd9Sstevel@tonic-gate interdomain_value = (char *)malloc(val.dsize+1); 12367c478bd9Sstevel@tonic-gate (void) memmove(interdomain_value, val.dptr, val.dsize); 12377c478bd9Sstevel@tonic-gate *(interdomain_value+val.dsize) = '\0'; 12387c478bd9Sstevel@tonic-gate interdomain_sz = val.dsize; 12397c478bd9Sstevel@tonic-gate } 12407c478bd9Sstevel@tonic-gate } 12417c478bd9Sstevel@tonic-gate 12427c478bd9Sstevel@tonic-gate /* finish up */ 12437c478bd9Sstevel@tonic-gate (void) dbm_close_status(db); 12447c478bd9Sstevel@tonic-gate 12457c478bd9Sstevel@tonic-gate return ((unsigned)atoi(number)); 12467c478bd9Sstevel@tonic-gate } 12477c478bd9Sstevel@tonic-gate 12487c478bd9Sstevel@tonic-gate /* 12497c478bd9Sstevel@tonic-gate * This constructs a file name for a map, minus its dbm_dir 12507c478bd9Sstevel@tonic-gate * or dbm_pag extensions 12517c478bd9Sstevel@tonic-gate */ 12527c478bd9Sstevel@tonic-gate void 12537c478bd9Sstevel@tonic-gate mkfilename(ppath) 12547c478bd9Sstevel@tonic-gate char *ppath; 12557c478bd9Sstevel@tonic-gate { 12567c478bd9Sstevel@tonic-gate bool_t yptol_mode; 12577c478bd9Sstevel@tonic-gate int len; 12587c478bd9Sstevel@tonic-gate 12597c478bd9Sstevel@tonic-gate /* Work out if we are in yptol mode */ 12607c478bd9Sstevel@tonic-gate yptol_mode = is_yptol_mode(); 12617c478bd9Sstevel@tonic-gate 12627c478bd9Sstevel@tonic-gate len = strlen(domain) + strlen(map) + strlen(ypdbpath) + 3; 12637c478bd9Sstevel@tonic-gate if (yptol_mode) 12647c478bd9Sstevel@tonic-gate len += strlen(NTOL_PREFIX); 12657c478bd9Sstevel@tonic-gate 12667c478bd9Sstevel@tonic-gate if (len > (MAXNAMLEN + 1)) { 12677c478bd9Sstevel@tonic-gate logprintf("Map name string too long.\n"); 12687c478bd9Sstevel@tonic-gate } 12697c478bd9Sstevel@tonic-gate 12707c478bd9Sstevel@tonic-gate (void) strcpy(ppath, ypdbpath); 12717c478bd9Sstevel@tonic-gate (void) strcat(ppath, "/"); 12727c478bd9Sstevel@tonic-gate (void) strcat(ppath, domain); 12737c478bd9Sstevel@tonic-gate (void) strcat(ppath, "/"); 12747c478bd9Sstevel@tonic-gate if (yptol_mode) 12757c478bd9Sstevel@tonic-gate (void) strcat(ppath, NTOL_PREFIX); 12767c478bd9Sstevel@tonic-gate (void) strcat(ppath, map); 12777c478bd9Sstevel@tonic-gate } 12787c478bd9Sstevel@tonic-gate 12797c478bd9Sstevel@tonic-gate /* 12807c478bd9Sstevel@tonic-gate * This returns a temporary name for a map transfer minus its dbm_dir or 12817c478bd9Sstevel@tonic-gate * dbm_pag extensions. 12827c478bd9Sstevel@tonic-gate */ 12837c478bd9Sstevel@tonic-gate void 12847c478bd9Sstevel@tonic-gate mk_tmpname(prefix, xfr_name) 12857c478bd9Sstevel@tonic-gate char *prefix; 12867c478bd9Sstevel@tonic-gate char *xfr_name; 12877c478bd9Sstevel@tonic-gate { 12887c478bd9Sstevel@tonic-gate char xfr_anumber[10]; 12897c478bd9Sstevel@tonic-gate long xfr_number; 12907c478bd9Sstevel@tonic-gate 12917c478bd9Sstevel@tonic-gate if (!xfr_name) { 12927c478bd9Sstevel@tonic-gate return; 12937c478bd9Sstevel@tonic-gate } 12947c478bd9Sstevel@tonic-gate 12957c478bd9Sstevel@tonic-gate xfr_number = getpid(); 12967c478bd9Sstevel@tonic-gate (void) sprintf(xfr_anumber, "%d", xfr_number); 12977c478bd9Sstevel@tonic-gate 12987c478bd9Sstevel@tonic-gate (void) strcpy(xfr_name, ypdbpath); 12997c478bd9Sstevel@tonic-gate (void) strcat(xfr_name, "/"); 13007c478bd9Sstevel@tonic-gate (void) strcat(xfr_name, domain); 13017c478bd9Sstevel@tonic-gate (void) strcat(xfr_name, "/"); 13027c478bd9Sstevel@tonic-gate (void) strcat(xfr_name, prefix); 13037c478bd9Sstevel@tonic-gate (void) strcat(xfr_name, map); 13047c478bd9Sstevel@tonic-gate (void) strcat(xfr_name, "."); 13057c478bd9Sstevel@tonic-gate (void) strcat(xfr_name, xfr_anumber); 13067c478bd9Sstevel@tonic-gate } 13077c478bd9Sstevel@tonic-gate 13087c478bd9Sstevel@tonic-gate /* 13097c478bd9Sstevel@tonic-gate * This deletes the .pag and .dir files which implement a map. 13107c478bd9Sstevel@tonic-gate * 13117c478bd9Sstevel@tonic-gate * Note: No error checking is done here for a garbage input file name or for 13127c478bd9Sstevel@tonic-gate * failed unlink operations. 13137c478bd9Sstevel@tonic-gate */ 13147c478bd9Sstevel@tonic-gate void 13157c478bd9Sstevel@tonic-gate del_mapfiles(basename) 13167c478bd9Sstevel@tonic-gate char *basename; 13177c478bd9Sstevel@tonic-gate { 13187c478bd9Sstevel@tonic-gate char dbfilename[MAXNAMLEN + 1]; 13197c478bd9Sstevel@tonic-gate 13207c478bd9Sstevel@tonic-gate if (!basename) { 13217c478bd9Sstevel@tonic-gate return; 13227c478bd9Sstevel@tonic-gate } 13237c478bd9Sstevel@tonic-gate 13247c478bd9Sstevel@tonic-gate strcpy(dbfilename, basename); 13257c478bd9Sstevel@tonic-gate strcat(dbfilename, dbm_pag); 13267c478bd9Sstevel@tonic-gate unlink(dbfilename); 13277c478bd9Sstevel@tonic-gate strcpy(dbfilename, basename); 13287c478bd9Sstevel@tonic-gate strcat(dbfilename, dbm_dir); 13297c478bd9Sstevel@tonic-gate unlink(dbfilename); 13307c478bd9Sstevel@tonic-gate } 13317c478bd9Sstevel@tonic-gate 13327c478bd9Sstevel@tonic-gate /* 13337c478bd9Sstevel@tonic-gate * This creates <pname>.dir and <pname>.pag 13347c478bd9Sstevel@tonic-gate */ 13357c478bd9Sstevel@tonic-gate bool 13367c478bd9Sstevel@tonic-gate new_mapfiles(pname) 13377c478bd9Sstevel@tonic-gate char *pname; 13387c478bd9Sstevel@tonic-gate { 13397c478bd9Sstevel@tonic-gate char dbfile[MAXNAMLEN + 1]; 13407c478bd9Sstevel@tonic-gate int f; 13417c478bd9Sstevel@tonic-gate int len; 13427c478bd9Sstevel@tonic-gate 13437c478bd9Sstevel@tonic-gate if (!pname || ((len = strlen(pname)) == 0) || 13447c478bd9Sstevel@tonic-gate (len + 5) > (MAXNAMLEN + 1)) { 13457c478bd9Sstevel@tonic-gate return (FALSE); 13467c478bd9Sstevel@tonic-gate } 13477c478bd9Sstevel@tonic-gate 13487c478bd9Sstevel@tonic-gate errno = 0; 13497c478bd9Sstevel@tonic-gate (void) strcpy(dbfile, pname); 13507c478bd9Sstevel@tonic-gate (void) strcat(dbfile, dbm_dir); 13517c478bd9Sstevel@tonic-gate 13527c478bd9Sstevel@tonic-gate if ((f = open(dbfile, (O_WRONLY | O_CREAT | O_TRUNC), 0600)) >= 0) { 13537c478bd9Sstevel@tonic-gate (void) close(f); 13547c478bd9Sstevel@tonic-gate (void) strcpy(dbfile, pname); 13557c478bd9Sstevel@tonic-gate (void) strcat(dbfile, dbm_pag); 13567c478bd9Sstevel@tonic-gate 13577c478bd9Sstevel@tonic-gate if ((f = open(dbfile, (O_WRONLY | O_CREAT | O_TRUNC), 13587c478bd9Sstevel@tonic-gate 0600)) >= 0) { 13597c478bd9Sstevel@tonic-gate (void) close(f); 13607c478bd9Sstevel@tonic-gate return (TRUE); 13617c478bd9Sstevel@tonic-gate } else { 13627c478bd9Sstevel@tonic-gate return (FALSE); 13637c478bd9Sstevel@tonic-gate } 13647c478bd9Sstevel@tonic-gate 13657c478bd9Sstevel@tonic-gate } else { 13667c478bd9Sstevel@tonic-gate return (FALSE); 13677c478bd9Sstevel@tonic-gate } 13687c478bd9Sstevel@tonic-gate } 13697c478bd9Sstevel@tonic-gate 1370*a506a34cSth160488 int 13717c478bd9Sstevel@tonic-gate count_callback(status) 13727c478bd9Sstevel@tonic-gate int status; 13737c478bd9Sstevel@tonic-gate { 13747c478bd9Sstevel@tonic-gate if (status != YP_TRUE) { 13757c478bd9Sstevel@tonic-gate 13767c478bd9Sstevel@tonic-gate if (status != YP_NOMORE) { 13777c478bd9Sstevel@tonic-gate logprintf( 13787c478bd9Sstevel@tonic-gate "Error from ypserv on %s (ypall_callback) = %s.\n", 13797c478bd9Sstevel@tonic-gate master, yperr_string(ypprot_err(status))); 13807c478bd9Sstevel@tonic-gate } 13817c478bd9Sstevel@tonic-gate 13827c478bd9Sstevel@tonic-gate return (TRUE); 13837c478bd9Sstevel@tonic-gate } 13847c478bd9Sstevel@tonic-gate 13857c478bd9Sstevel@tonic-gate entry_count++; 13867c478bd9Sstevel@tonic-gate return (FALSE); 13877c478bd9Sstevel@tonic-gate } 13887c478bd9Sstevel@tonic-gate 13897c478bd9Sstevel@tonic-gate /* 13907c478bd9Sstevel@tonic-gate * This counts the entries in the dbm file after the transfer to 13917c478bd9Sstevel@tonic-gate * make sure that the dbm file was built correctly. 13927c478bd9Sstevel@tonic-gate * Returns TRUE if everything is OK, FALSE if they mismatch. 13937c478bd9Sstevel@tonic-gate */ 1394*a506a34cSth160488 int 13957c478bd9Sstevel@tonic-gate count_mismatch(pname, oldcount) 13967c478bd9Sstevel@tonic-gate char *pname; 13977c478bd9Sstevel@tonic-gate int oldcount; 13987c478bd9Sstevel@tonic-gate { 13997c478bd9Sstevel@tonic-gate datum key; 14007c478bd9Sstevel@tonic-gate DBM *db; 14017c478bd9Sstevel@tonic-gate #ifdef REALLY_PARANOID 14027c478bd9Sstevel@tonic-gate struct ypall_callback cbinfo; 14037c478bd9Sstevel@tonic-gate struct ypreq_nokey allreq; 14047c478bd9Sstevel@tonic-gate enum clnt_stat s; 14057c478bd9Sstevel@tonic-gate struct dom_binding domb; 14067c478bd9Sstevel@tonic-gate datum value; 14077c478bd9Sstevel@tonic-gate #endif /* REALLY_PARANOID */ 14087c478bd9Sstevel@tonic-gate 14097c478bd9Sstevel@tonic-gate entry_count = 0; 14107c478bd9Sstevel@tonic-gate db = dbm_open(pname, 0, 0); 14117c478bd9Sstevel@tonic-gate if (db) { 14127c478bd9Sstevel@tonic-gate for (key = dbm_firstkey(db); 14137c478bd9Sstevel@tonic-gate key.dptr != NULL; key = dbm_nextkey(db)) 14147c478bd9Sstevel@tonic-gate entry_count++; 14157c478bd9Sstevel@tonic-gate dbm_close_status(db); 14167c478bd9Sstevel@tonic-gate } 14177c478bd9Sstevel@tonic-gate 14187c478bd9Sstevel@tonic-gate if (oldcount != entry_count) { 14197c478bd9Sstevel@tonic-gate logprintf( 14207c478bd9Sstevel@tonic-gate "*** Count mismatch in dbm file %s: old=%d, new=%d ***\n", 14217c478bd9Sstevel@tonic-gate map, oldcount, entry_count); 14227c478bd9Sstevel@tonic-gate return (FALSE); 14237c478bd9Sstevel@tonic-gate } 14247c478bd9Sstevel@tonic-gate 14257c478bd9Sstevel@tonic-gate #ifdef REALLY_PARANOID 14267c478bd9Sstevel@tonic-gate 14277c478bd9Sstevel@tonic-gate if ((domb.dom_client = __yp_clnt_create_rsvdport(master, YPPROG, 14287c478bd9Sstevel@tonic-gate master_prog_vers, 14297c478bd9Sstevel@tonic-gate "tcp6", 0, 0)) == 0 && 14307c478bd9Sstevel@tonic-gate (domb.dom_client = __yp_clnt_create_rsvdport(master, YPPROG, 14317c478bd9Sstevel@tonic-gate master_prog_vers, 14327c478bd9Sstevel@tonic-gate "tcp", 0, 0)) == 0) { 14337c478bd9Sstevel@tonic-gate clnt_pcreateerror("ypxfr (mismatch) - TCP channel " 14347c478bd9Sstevel@tonic-gate "create failure"); 14357c478bd9Sstevel@tonic-gate return (FALSE); 14367c478bd9Sstevel@tonic-gate } 14377c478bd9Sstevel@tonic-gate 14387c478bd9Sstevel@tonic-gate if (master_prog_vers == YPVERS) { 14397c478bd9Sstevel@tonic-gate int tmpstat; 14407c478bd9Sstevel@tonic-gate 14417c478bd9Sstevel@tonic-gate allreq.domain = source; 14427c478bd9Sstevel@tonic-gate allreq.map = map; 14437c478bd9Sstevel@tonic-gate cbinfo.foreach = count_callback; 14447c478bd9Sstevel@tonic-gate tmpstat = 0; 14457c478bd9Sstevel@tonic-gate cbinfo.data = (char *)&tmpstat; 14467c478bd9Sstevel@tonic-gate 14477c478bd9Sstevel@tonic-gate entry_count = 0; 14487c478bd9Sstevel@tonic-gate s = clnt_call(domb.dom_client, YPPROC_ALL, xdr_ypreq_nokey, 14497c478bd9Sstevel@tonic-gate &allreq, xdr_ypall, &cbinfo, tcp_timeout); 14507c478bd9Sstevel@tonic-gate 14517c478bd9Sstevel@tonic-gate if (tmpstat == 0) { 14527c478bd9Sstevel@tonic-gate if (s == RPC_SUCCESS) { 14537c478bd9Sstevel@tonic-gate } else { 14547c478bd9Sstevel@tonic-gate clnt_perror(domb.dom_client, 14557c478bd9Sstevel@tonic-gate "ypxfr (get_map/all) - RPC clnt_call (TCP) failure"); 14567c478bd9Sstevel@tonic-gate return (FALSE); 14577c478bd9Sstevel@tonic-gate } 14587c478bd9Sstevel@tonic-gate 14597c478bd9Sstevel@tonic-gate } else { 14607c478bd9Sstevel@tonic-gate return (FALSE); 14617c478bd9Sstevel@tonic-gate } 14627c478bd9Sstevel@tonic-gate 14637c478bd9Sstevel@tonic-gate } else { 14647c478bd9Sstevel@tonic-gate logprintf("Wrong version number!\n"); 14657c478bd9Sstevel@tonic-gate return (FALSE); 14667c478bd9Sstevel@tonic-gate } 14677c478bd9Sstevel@tonic-gate clnt_destroy(domb.dom_client); 14687c478bd9Sstevel@tonic-gate close(domb.dom_socket); 14697c478bd9Sstevel@tonic-gate entry_count += 2; /* add in YP_entries */ 14707c478bd9Sstevel@tonic-gate if (oldcount != entry_count) { 14717c478bd9Sstevel@tonic-gate logprintf( 14727c478bd9Sstevel@tonic-gate "*** Count mismatch after enumerate %s: old=%d, new=%d ***\n", 14737c478bd9Sstevel@tonic-gate map, oldcount, entry_count); 14747c478bd9Sstevel@tonic-gate return (FALSE); 14757c478bd9Sstevel@tonic-gate } 14767c478bd9Sstevel@tonic-gate #endif /* REALLY_PARANOID */ 14777c478bd9Sstevel@tonic-gate 14787c478bd9Sstevel@tonic-gate return (TRUE); 14797c478bd9Sstevel@tonic-gate } 14807c478bd9Sstevel@tonic-gate 14817c478bd9Sstevel@tonic-gate /* 14827c478bd9Sstevel@tonic-gate * This sets up a TCP connection to the master server, and either gets 14837c478bd9Sstevel@tonic-gate * ypall_callback to do all the work of writing it to the local dbm file 14847c478bd9Sstevel@tonic-gate * (if the ypserv is current version), or does it itself for an old ypserv. 14857c478bd9Sstevel@tonic-gate */ 14867c478bd9Sstevel@tonic-gate bool 14877c478bd9Sstevel@tonic-gate get_map(pname, pushstat) 14887c478bd9Sstevel@tonic-gate char *pname; 14897c478bd9Sstevel@tonic-gate int *pushstat; 14907c478bd9Sstevel@tonic-gate { 14917c478bd9Sstevel@tonic-gate struct dom_binding domb; 14927c478bd9Sstevel@tonic-gate enum clnt_stat s; 14937c478bd9Sstevel@tonic-gate struct ypreq_nokey allreq; 14947c478bd9Sstevel@tonic-gate struct ypall_callback cbinfo; 14957c478bd9Sstevel@tonic-gate bool retval = FALSE; 14967c478bd9Sstevel@tonic-gate int tmpstat; 14977c478bd9Sstevel@tonic-gate int recvsiz = 24 * 1024; 14987c478bd9Sstevel@tonic-gate struct netconfig *nconf; 14997c478bd9Sstevel@tonic-gate int fd; 15007c478bd9Sstevel@tonic-gate struct netbuf *svcaddr; 15017c478bd9Sstevel@tonic-gate char *netid[] = { "tcp6", "tcp" }; 15027c478bd9Sstevel@tonic-gate int i, lastnetid = (sizeof (netid)/sizeof (netid[0])) - 1; 15037c478bd9Sstevel@tonic-gate 15047c478bd9Sstevel@tonic-gate svcaddr = (struct netbuf *)calloc(1, sizeof (struct netbuf)); 15057c478bd9Sstevel@tonic-gate if (! svcaddr) 15067c478bd9Sstevel@tonic-gate return (FALSE); 15077c478bd9Sstevel@tonic-gate svcaddr->maxlen = 32; 15087c478bd9Sstevel@tonic-gate svcaddr->len = 32; 15097c478bd9Sstevel@tonic-gate svcaddr->buf = (char *)malloc(32); 15107c478bd9Sstevel@tonic-gate if (! svcaddr->buf) { 15117c478bd9Sstevel@tonic-gate free(svcaddr); 15127c478bd9Sstevel@tonic-gate return (FALSE); 15137c478bd9Sstevel@tonic-gate } 15147c478bd9Sstevel@tonic-gate 15157c478bd9Sstevel@tonic-gate for (i = 0; i <= lastnetid; i++) { 15167c478bd9Sstevel@tonic-gate fd = RPC_ANYFD; 15177c478bd9Sstevel@tonic-gate if ((nconf = getnetconfigent(netid[i])) == NULL) { 15187c478bd9Sstevel@tonic-gate if (i != lastnetid) 15197c478bd9Sstevel@tonic-gate continue; 15207c478bd9Sstevel@tonic-gate logprintf("ypxfr: tcp transport not supported\n"); 15217c478bd9Sstevel@tonic-gate free(svcaddr->buf); 15227c478bd9Sstevel@tonic-gate free(svcaddr); 15237c478bd9Sstevel@tonic-gate return (FALSE); 15247c478bd9Sstevel@tonic-gate } 15257c478bd9Sstevel@tonic-gate if (rpcb_getaddr(YPPROG, master_prog_vers, nconf, svcaddr, 15267c478bd9Sstevel@tonic-gate master) == FALSE) { 15277c478bd9Sstevel@tonic-gate freenetconfigent(nconf); 15287c478bd9Sstevel@tonic-gate if (i != lastnetid) 15297c478bd9Sstevel@tonic-gate continue; 15307c478bd9Sstevel@tonic-gate logprintf("ypxfr: could not get %s address\n", master); 15317c478bd9Sstevel@tonic-gate free(svcaddr->buf); 15327c478bd9Sstevel@tonic-gate free(svcaddr); 15337c478bd9Sstevel@tonic-gate return (FALSE); 15347c478bd9Sstevel@tonic-gate } 15357c478bd9Sstevel@tonic-gate if ((domb.dom_client = __nis_clnt_create(fd, nconf, 0, svcaddr, 15367c478bd9Sstevel@tonic-gate 0, YPPROG, master_prog_vers, recvsiz, 0)) == 0) { 15377c478bd9Sstevel@tonic-gate freenetconfigent(nconf); 15387c478bd9Sstevel@tonic-gate if (i != lastnetid) 15397c478bd9Sstevel@tonic-gate continue; 15407c478bd9Sstevel@tonic-gate clnt_pcreateerror( 15417c478bd9Sstevel@tonic-gate "ypxfr (get_map) - TCP channel create failure"); 15427c478bd9Sstevel@tonic-gate *pushstat = YPPUSH_RPC; 15437c478bd9Sstevel@tonic-gate free(svcaddr->buf); 15447c478bd9Sstevel@tonic-gate free(svcaddr); 15457c478bd9Sstevel@tonic-gate return (FALSE); 15467c478bd9Sstevel@tonic-gate } 15477c478bd9Sstevel@tonic-gate break; 15487c478bd9Sstevel@tonic-gate } 15497c478bd9Sstevel@tonic-gate 15507c478bd9Sstevel@tonic-gate entry_count = 0; 15517c478bd9Sstevel@tonic-gate if (master_prog_vers == YPVERS) { 15527c478bd9Sstevel@tonic-gate allreq.domain = source; 15537c478bd9Sstevel@tonic-gate allreq.map = map; 15547c478bd9Sstevel@tonic-gate cbinfo.foreach = ypall_callback; 15557c478bd9Sstevel@tonic-gate tmpstat = 0; 15567c478bd9Sstevel@tonic-gate cbinfo.data = (char *)&tmpstat; 15577c478bd9Sstevel@tonic-gate 15587c478bd9Sstevel@tonic-gate s = clnt_call(domb.dom_client, YPPROC_ALL, 15597c478bd9Sstevel@tonic-gate (xdrproc_t)xdr_ypreq_nokey, 15607c478bd9Sstevel@tonic-gate (char *)&allreq, (xdrproc_t)xdr_ypall, (char *)&cbinfo, 15617c478bd9Sstevel@tonic-gate tcp_timeout); 15627c478bd9Sstevel@tonic-gate 15637c478bd9Sstevel@tonic-gate if (tmpstat == 0) { 15647c478bd9Sstevel@tonic-gate 15657c478bd9Sstevel@tonic-gate if (s == RPC_SUCCESS) { 15667c478bd9Sstevel@tonic-gate retval = TRUE; 15677c478bd9Sstevel@tonic-gate } else { 15687c478bd9Sstevel@tonic-gate clnt_perror(domb.dom_client, 15697c478bd9Sstevel@tonic-gate "ypxfr (get_map/all) - RPC clnt_call (TCP) failure"); 15707c478bd9Sstevel@tonic-gate *pushstat = YPPUSH_RPC; 15717c478bd9Sstevel@tonic-gate } 15727c478bd9Sstevel@tonic-gate 15737c478bd9Sstevel@tonic-gate } else { 15747c478bd9Sstevel@tonic-gate *pushstat = tmpstat; 15757c478bd9Sstevel@tonic-gate } 15767c478bd9Sstevel@tonic-gate 15777c478bd9Sstevel@tonic-gate } else 15787c478bd9Sstevel@tonic-gate retval = FALSE; /* barf again at YPOLDVERS */ 15797c478bd9Sstevel@tonic-gate cleanup: 15807c478bd9Sstevel@tonic-gate clnt_destroy(domb.dom_client); 15817c478bd9Sstevel@tonic-gate return (retval); 15827c478bd9Sstevel@tonic-gate } 15837c478bd9Sstevel@tonic-gate 15847c478bd9Sstevel@tonic-gate /* 15857c478bd9Sstevel@tonic-gate * This sticks each key-value pair into the current map. It returns FALSE as 15867c478bd9Sstevel@tonic-gate * long as it wants to keep getting called back, and TRUE on error conditions 15877c478bd9Sstevel@tonic-gate * and "No more k-v pairs". 15887c478bd9Sstevel@tonic-gate */ 15897c478bd9Sstevel@tonic-gate int 15907c478bd9Sstevel@tonic-gate ypall_callback(status, key, kl, val, vl, pushstat) 15917c478bd9Sstevel@tonic-gate int status; 15927c478bd9Sstevel@tonic-gate char *key; 15937c478bd9Sstevel@tonic-gate int kl; 15947c478bd9Sstevel@tonic-gate char *val; 15957c478bd9Sstevel@tonic-gate int vl; 15967c478bd9Sstevel@tonic-gate int *pushstat; 15977c478bd9Sstevel@tonic-gate { 15987c478bd9Sstevel@tonic-gate datum keydat; 15997c478bd9Sstevel@tonic-gate datum valdat; 16007c478bd9Sstevel@tonic-gate datum test; 16017c478bd9Sstevel@tonic-gate 16027c478bd9Sstevel@tonic-gate if (status != YP_TRUE) { 16037c478bd9Sstevel@tonic-gate 16047c478bd9Sstevel@tonic-gate if (status != YP_NOMORE) { 16057c478bd9Sstevel@tonic-gate logprintf( 16067c478bd9Sstevel@tonic-gate "Error from ypserv on %s (ypall_callback) = %s.\n", 16077c478bd9Sstevel@tonic-gate master, yperr_string(ypprot_err(status))); 16087c478bd9Sstevel@tonic-gate *pushstat = map_yperr_to_pusherr(status); 16097c478bd9Sstevel@tonic-gate } 16107c478bd9Sstevel@tonic-gate 16117c478bd9Sstevel@tonic-gate return (TRUE); 16127c478bd9Sstevel@tonic-gate } 16137c478bd9Sstevel@tonic-gate 16147c478bd9Sstevel@tonic-gate keydat.dptr = key; 16157c478bd9Sstevel@tonic-gate keydat.dsize = kl; 16167c478bd9Sstevel@tonic-gate valdat.dptr = val; 16177c478bd9Sstevel@tonic-gate valdat.dsize = vl; 16187c478bd9Sstevel@tonic-gate entry_count++; 16197c478bd9Sstevel@tonic-gate /* way too many fetches */ 16207c478bd9Sstevel@tonic-gate 16217c478bd9Sstevel@tonic-gate #ifdef PARANOID 16227c478bd9Sstevel@tonic-gate test = dbm_fetch(db, keydat); 16237c478bd9Sstevel@tonic-gate if (test.dptr != NULL) { 16247c478bd9Sstevel@tonic-gate logprintf("Duplicate key %s in map %s\n", key, map); 16257c478bd9Sstevel@tonic-gate *pushstat = YPPUSH_DBM; 16267c478bd9Sstevel@tonic-gate return (TRUE); 16277c478bd9Sstevel@tonic-gate } 16287c478bd9Sstevel@tonic-gate #endif /* PARANOID */ 16297c478bd9Sstevel@tonic-gate if (dbm_store(db, keydat, valdat, 0) < 0) { 16307c478bd9Sstevel@tonic-gate logprintf( 16317c478bd9Sstevel@tonic-gate "Can't do dbm store into temp map %s.\n", map); 16327c478bd9Sstevel@tonic-gate *pushstat = YPPUSH_DBM; 16337c478bd9Sstevel@tonic-gate return (TRUE); 16347c478bd9Sstevel@tonic-gate } 16357c478bd9Sstevel@tonic-gate #ifdef PARANOID 16367c478bd9Sstevel@tonic-gate test = dbm_fetch(db, keydat); 16377c478bd9Sstevel@tonic-gate if (test.dptr == NULL) { 16387c478bd9Sstevel@tonic-gate logprintf("Key %s was not inserted into dbm file %s\n", 16397c478bd9Sstevel@tonic-gate key, map); 16407c478bd9Sstevel@tonic-gate *pushstat = YPPUSH_DBM; 16417c478bd9Sstevel@tonic-gate return (TRUE); 16427c478bd9Sstevel@tonic-gate } 16437c478bd9Sstevel@tonic-gate #endif /* PARANOID */ 16447c478bd9Sstevel@tonic-gate 16457c478bd9Sstevel@tonic-gate if (dbm_error(db)) { 16467c478bd9Sstevel@tonic-gate logprintf("Key %s dbm_error raised in file %s\n", 16477c478bd9Sstevel@tonic-gate key, map); 16487c478bd9Sstevel@tonic-gate *pushstat = YPPUSH_DBM; 16497c478bd9Sstevel@tonic-gate return (TRUE); 16507c478bd9Sstevel@tonic-gate } 16517c478bd9Sstevel@tonic-gate return (FALSE); 16527c478bd9Sstevel@tonic-gate } 16537c478bd9Sstevel@tonic-gate 16547c478bd9Sstevel@tonic-gate /* 16557c478bd9Sstevel@tonic-gate * This maps a YP_xxxx error code into a YPPUSH_xxxx error code 16567c478bd9Sstevel@tonic-gate */ 16577c478bd9Sstevel@tonic-gate int 16587c478bd9Sstevel@tonic-gate map_yperr_to_pusherr(yperr) 16597c478bd9Sstevel@tonic-gate int yperr; 16607c478bd9Sstevel@tonic-gate { 16617c478bd9Sstevel@tonic-gate int reason; 16627c478bd9Sstevel@tonic-gate 16637c478bd9Sstevel@tonic-gate switch (yperr) { 16647c478bd9Sstevel@tonic-gate 16657c478bd9Sstevel@tonic-gate case YP_NOMORE: 16667c478bd9Sstevel@tonic-gate reason = YPPUSH_SUCC; 16677c478bd9Sstevel@tonic-gate break; 16687c478bd9Sstevel@tonic-gate 16697c478bd9Sstevel@tonic-gate case YP_NOMAP: 16707c478bd9Sstevel@tonic-gate reason = YPPUSH_NOMAP; 16717c478bd9Sstevel@tonic-gate break; 16727c478bd9Sstevel@tonic-gate 16737c478bd9Sstevel@tonic-gate case YP_NODOM: 16747c478bd9Sstevel@tonic-gate reason = YPPUSH_NODOM; 16757c478bd9Sstevel@tonic-gate break; 16767c478bd9Sstevel@tonic-gate 16777c478bd9Sstevel@tonic-gate case YP_NOKEY: 16787c478bd9Sstevel@tonic-gate reason = YPPUSH_YPERR; 16797c478bd9Sstevel@tonic-gate break; 16807c478bd9Sstevel@tonic-gate 16817c478bd9Sstevel@tonic-gate case YP_BADARGS: 16827c478bd9Sstevel@tonic-gate reason = YPPUSH_BADARGS; 16837c478bd9Sstevel@tonic-gate break; 16847c478bd9Sstevel@tonic-gate 16857c478bd9Sstevel@tonic-gate case YP_BADDB: 16867c478bd9Sstevel@tonic-gate reason = YPPUSH_YPERR; 16877c478bd9Sstevel@tonic-gate break; 16887c478bd9Sstevel@tonic-gate 16897c478bd9Sstevel@tonic-gate default: 16907c478bd9Sstevel@tonic-gate reason = YPPUSH_XFRERR; 16917c478bd9Sstevel@tonic-gate break; 16927c478bd9Sstevel@tonic-gate } 16937c478bd9Sstevel@tonic-gate 16947c478bd9Sstevel@tonic-gate return (reason); 16957c478bd9Sstevel@tonic-gate } 16967c478bd9Sstevel@tonic-gate 16977c478bd9Sstevel@tonic-gate /* 16987c478bd9Sstevel@tonic-gate * This writes the last-modified and master entries into the new dbm file 16997c478bd9Sstevel@tonic-gate */ 17007c478bd9Sstevel@tonic-gate bool 17017c478bd9Sstevel@tonic-gate add_private_entries(pname) 17027c478bd9Sstevel@tonic-gate char *pname; 17037c478bd9Sstevel@tonic-gate { 17047c478bd9Sstevel@tonic-gate datum key; 17057c478bd9Sstevel@tonic-gate datum val; 17067c478bd9Sstevel@tonic-gate 17077c478bd9Sstevel@tonic-gate if (!fake_master_version) { 17087c478bd9Sstevel@tonic-gate key.dptr = yp_last_modified; 17097c478bd9Sstevel@tonic-gate key.dsize = yp_last_modified_sz; 17107c478bd9Sstevel@tonic-gate val.dptr = master_ascii_version; 17117c478bd9Sstevel@tonic-gate val.dsize = strlen(master_ascii_version); 17127c478bd9Sstevel@tonic-gate 17137c478bd9Sstevel@tonic-gate if (dbm_store(db, key, val, 1) < 0) { 17147c478bd9Sstevel@tonic-gate logprintf( 17157c478bd9Sstevel@tonic-gate "Can't do dbm store into temp map %s.\n", 17167c478bd9Sstevel@tonic-gate pname); 17177c478bd9Sstevel@tonic-gate return (FALSE); 17187c478bd9Sstevel@tonic-gate } 17197c478bd9Sstevel@tonic-gate entry_count++; 17207c478bd9Sstevel@tonic-gate } 17217c478bd9Sstevel@tonic-gate 17227c478bd9Sstevel@tonic-gate if (master_name) { 17237c478bd9Sstevel@tonic-gate key.dptr = yp_master_name; 17247c478bd9Sstevel@tonic-gate key.dsize = yp_master_name_sz; 17257c478bd9Sstevel@tonic-gate val.dptr = master_name; 17267c478bd9Sstevel@tonic-gate val.dsize = strlen(master_name); 17277c478bd9Sstevel@tonic-gate if (dbm_store(db, key, val, 1) < 0) { 17287c478bd9Sstevel@tonic-gate logprintf( 17297c478bd9Sstevel@tonic-gate "Can't do dbm store into temp map %s.\n", 17307c478bd9Sstevel@tonic-gate pname); 17317c478bd9Sstevel@tonic-gate return (FALSE); 17327c478bd9Sstevel@tonic-gate } 17337c478bd9Sstevel@tonic-gate entry_count++; 17347c478bd9Sstevel@tonic-gate } 17357c478bd9Sstevel@tonic-gate 17367c478bd9Sstevel@tonic-gate if (interdomain_map) { 17377c478bd9Sstevel@tonic-gate key.dptr = yp_interdomain; 17387c478bd9Sstevel@tonic-gate key.dsize = yp_interdomain_sz; 17397c478bd9Sstevel@tonic-gate val.dptr = interdomain_value; 17407c478bd9Sstevel@tonic-gate val.dsize = interdomain_sz; 17417c478bd9Sstevel@tonic-gate if (dbm_store(db, key, val, 1) < 0) { 17427c478bd9Sstevel@tonic-gate logprintf( 17437c478bd9Sstevel@tonic-gate "Can't do dbm store into temp map %s.\n", 17447c478bd9Sstevel@tonic-gate pname); 17457c478bd9Sstevel@tonic-gate return (FALSE); 17467c478bd9Sstevel@tonic-gate } 17477c478bd9Sstevel@tonic-gate entry_count++; 17487c478bd9Sstevel@tonic-gate } 17497c478bd9Sstevel@tonic-gate 17507c478bd9Sstevel@tonic-gate if (secure_map) { 17517c478bd9Sstevel@tonic-gate key.dptr = yp_secure; 17527c478bd9Sstevel@tonic-gate key.dsize = yp_secure_sz; 17537c478bd9Sstevel@tonic-gate val.dptr = yp_secure; 17547c478bd9Sstevel@tonic-gate val.dsize = yp_secure_sz; 17557c478bd9Sstevel@tonic-gate if (dbm_store(db, key, val, 1) < 0) { 17567c478bd9Sstevel@tonic-gate logprintf( 17577c478bd9Sstevel@tonic-gate "Can't do dbm store into temp map %s.\n", 17587c478bd9Sstevel@tonic-gate pname); 17597c478bd9Sstevel@tonic-gate return (FALSE); 17607c478bd9Sstevel@tonic-gate } 17617c478bd9Sstevel@tonic-gate entry_count++; 17627c478bd9Sstevel@tonic-gate } 17637c478bd9Sstevel@tonic-gate 17647c478bd9Sstevel@tonic-gate return (TRUE); 17657c478bd9Sstevel@tonic-gate } 17667c478bd9Sstevel@tonic-gate 17677c478bd9Sstevel@tonic-gate 17687c478bd9Sstevel@tonic-gate /* 17697c478bd9Sstevel@tonic-gate * This sends a YPPROC_CLEAR message to the local ypserv process. 17707c478bd9Sstevel@tonic-gate */ 17717c478bd9Sstevel@tonic-gate bool 17727c478bd9Sstevel@tonic-gate send_ypclear(pushstat) 17737c478bd9Sstevel@tonic-gate int *pushstat; 17747c478bd9Sstevel@tonic-gate { 17757c478bd9Sstevel@tonic-gate struct dom_binding domb; 17767c478bd9Sstevel@tonic-gate char local_host_name[256]; 17777c478bd9Sstevel@tonic-gate unsigned int progvers; 17787c478bd9Sstevel@tonic-gate int status; 17797c478bd9Sstevel@tonic-gate 17807c478bd9Sstevel@tonic-gate if (gethostname(local_host_name, 256)) { 17817c478bd9Sstevel@tonic-gate logprintf("Can't get local machine name.\n"); 17827c478bd9Sstevel@tonic-gate *pushstat = YPPUSH_RSRC; 17837c478bd9Sstevel@tonic-gate return (FALSE); 17847c478bd9Sstevel@tonic-gate } 17857c478bd9Sstevel@tonic-gate 17867c478bd9Sstevel@tonic-gate if (!bind_to_server(local_host_name, &domb, 17877c478bd9Sstevel@tonic-gate &progvers, &status)) { 17887c478bd9Sstevel@tonic-gate *pushstat = YPPUSH_CLEAR; 17897c478bd9Sstevel@tonic-gate return (FALSE); 17907c478bd9Sstevel@tonic-gate } 17917c478bd9Sstevel@tonic-gate 17927c478bd9Sstevel@tonic-gate if ((enum clnt_stat) clnt_call(domb.dom_client, 17937c478bd9Sstevel@tonic-gate YPPROC_CLEAR, xdr_void, 0, xdr_void, 0, 17947c478bd9Sstevel@tonic-gate udp_timeout) != RPC_SUCCESS) { 17957c478bd9Sstevel@tonic-gate logprintf( 17967c478bd9Sstevel@tonic-gate "Can't send ypclear message to ypserv on the local machine.\n"); 17977c478bd9Sstevel@tonic-gate xfr_exit(YPPUSH_CLEAR); 17987c478bd9Sstevel@tonic-gate } 17997c478bd9Sstevel@tonic-gate 18007c478bd9Sstevel@tonic-gate return (TRUE); 18017c478bd9Sstevel@tonic-gate } 18027c478bd9Sstevel@tonic-gate 18037c478bd9Sstevel@tonic-gate /* 18047c478bd9Sstevel@tonic-gate * This decides if send_callback has to get called, and does the process exit. 18057c478bd9Sstevel@tonic-gate */ 18067c478bd9Sstevel@tonic-gate void 18077c478bd9Sstevel@tonic-gate xfr_exit(status) 18087c478bd9Sstevel@tonic-gate int status; 18097c478bd9Sstevel@tonic-gate { 18107c478bd9Sstevel@tonic-gate if (callback) { 18117c478bd9Sstevel@tonic-gate send_callback(&status); 18127c478bd9Sstevel@tonic-gate } 18137c478bd9Sstevel@tonic-gate 18147c478bd9Sstevel@tonic-gate if (status == YPPUSH_SUCC) { 18157c478bd9Sstevel@tonic-gate #ifdef TREEPUSH 18167c478bd9Sstevel@tonic-gate if (treepush) { 18177c478bd9Sstevel@tonic-gate if (debug) 18187c478bd9Sstevel@tonic-gate execlp("./yppush", "yppush", "-T", map, 0); 18197c478bd9Sstevel@tonic-gate execlp("/usr/etc/yp/yppush", "yppush", "-T", map, 0); 18207c478bd9Sstevel@tonic-gate perror("yppush"); 18217c478bd9Sstevel@tonic-gate } 18227c478bd9Sstevel@tonic-gate #endif 18237c478bd9Sstevel@tonic-gate exit(0); 18247c478bd9Sstevel@tonic-gate } else { 18257c478bd9Sstevel@tonic-gate exit(1); 18267c478bd9Sstevel@tonic-gate } 18277c478bd9Sstevel@tonic-gate } 18287c478bd9Sstevel@tonic-gate 18297c478bd9Sstevel@tonic-gate /* 18307c478bd9Sstevel@tonic-gate * This sets up a UDP connection to the yppush process which contacted our 18317c478bd9Sstevel@tonic-gate * parent ypserv, and sends him a status on the requested transfer. 18327c478bd9Sstevel@tonic-gate */ 18337c478bd9Sstevel@tonic-gate void 18347c478bd9Sstevel@tonic-gate send_callback(status) 18357c478bd9Sstevel@tonic-gate int *status; 18367c478bd9Sstevel@tonic-gate { 18377c478bd9Sstevel@tonic-gate struct yppushresp_xfr resp; 18387c478bd9Sstevel@tonic-gate struct dom_binding domb; 18397c478bd9Sstevel@tonic-gate 18407c478bd9Sstevel@tonic-gate resp.transid = (unsigned long) atoi(tid); 18417c478bd9Sstevel@tonic-gate resp.status = (unsigned long) *status; 18427c478bd9Sstevel@tonic-gate 18437c478bd9Sstevel@tonic-gate udp_timeout.tv_sec = CALLTIMEOUT; 18447c478bd9Sstevel@tonic-gate 18457c478bd9Sstevel@tonic-gate if ((domb.dom_client = __yp_clnt_create_rsvdport(pushhost, 18467c478bd9Sstevel@tonic-gate (ulong_t)atoi(proto), 18477c478bd9Sstevel@tonic-gate YPPUSHVERS, 18487c478bd9Sstevel@tonic-gate 0, 0, 0)) == NULL) { 18497c478bd9Sstevel@tonic-gate *status = YPPUSH_RPC; 18507c478bd9Sstevel@tonic-gate return; 18517c478bd9Sstevel@tonic-gate } 18527c478bd9Sstevel@tonic-gate 18537c478bd9Sstevel@tonic-gate if ((enum clnt_stat) clnt_call(domb.dom_client, 18547c478bd9Sstevel@tonic-gate YPPUSHPROC_XFRRESP, (xdrproc_t)xdr_yppushresp_xfr, 18557c478bd9Sstevel@tonic-gate (char *)&resp, xdr_void, 0, 18567c478bd9Sstevel@tonic-gate udp_timeout) != RPC_SUCCESS) { 18577c478bd9Sstevel@tonic-gate *status = YPPUSH_RPC; 18587c478bd9Sstevel@tonic-gate return; 18597c478bd9Sstevel@tonic-gate } 18607c478bd9Sstevel@tonic-gate } 18617c478bd9Sstevel@tonic-gate 18627c478bd9Sstevel@tonic-gate /* 18637c478bd9Sstevel@tonic-gate * FUNCTION: is_yptol_mode(); 18647c478bd9Sstevel@tonic-gate * 18657c478bd9Sstevel@tonic-gate * DESCRIPTION: Determines if we should run in N2L or traditional mode based 18667c478bd9Sstevel@tonic-gate * on the presence of the N2L mapping file. 18677c478bd9Sstevel@tonic-gate * 18687c478bd9Sstevel@tonic-gate * This is a copy of a function from libnisdb. If more than this 18697c478bd9Sstevel@tonic-gate * one function become required it may be worth linking the 18707c478bd9Sstevel@tonic-gate * entire lib. 18717c478bd9Sstevel@tonic-gate * 18727c478bd9Sstevel@tonic-gate * INPUTS: Nothing 18737c478bd9Sstevel@tonic-gate * 18747c478bd9Sstevel@tonic-gate * OUTPUTS: TRUE = Run in N2L mode 18757c478bd9Sstevel@tonic-gate * FALSE = Run in traditional mode. 18767c478bd9Sstevel@tonic-gate */ 18777c478bd9Sstevel@tonic-gate bool_t 18787c478bd9Sstevel@tonic-gate is_yptol_mode() 18797c478bd9Sstevel@tonic-gate { 18807c478bd9Sstevel@tonic-gate struct stat filestat; 18817c478bd9Sstevel@tonic-gate 18827c478bd9Sstevel@tonic-gate if (stat(NTOL_MAP_FILE, &filestat) != -1) 18837c478bd9Sstevel@tonic-gate return (TRUE); 18847c478bd9Sstevel@tonic-gate 18857c478bd9Sstevel@tonic-gate return (FALSE); 18867c478bd9Sstevel@tonic-gate } 1887