1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 28*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate /* 31*7c478bd9Sstevel@tonic-gate * Portions of this source code were derived from Berkeley 32*7c478bd9Sstevel@tonic-gate * under license from the Regents of the University of 33*7c478bd9Sstevel@tonic-gate * California. 34*7c478bd9Sstevel@tonic-gate */ 35*7c478bd9Sstevel@tonic-gate 36*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 37*7c478bd9Sstevel@tonic-gate 38*7c478bd9Sstevel@tonic-gate /* 39*7c478bd9Sstevel@tonic-gate * YP updater interface 40*7c478bd9Sstevel@tonic-gate */ 41*7c478bd9Sstevel@tonic-gate #include <stdio.h> 42*7c478bd9Sstevel@tonic-gate #include <rpc/rpc.h> 43*7c478bd9Sstevel@tonic-gate #include "yp_b.h" 44*7c478bd9Sstevel@tonic-gate #include <rpcsvc/ypclnt.h> 45*7c478bd9Sstevel@tonic-gate #include <rpcsvc/ypupd.h> 46*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 47*7c478bd9Sstevel@tonic-gate #include <rpc/trace.h> 48*7c478bd9Sstevel@tonic-gate #include <stdlib.h> 49*7c478bd9Sstevel@tonic-gate 50*7c478bd9Sstevel@tonic-gate #define WINDOW (60*60) 51*7c478bd9Sstevel@tonic-gate #define TOTAL_TIMEOUT 300 52*7c478bd9Sstevel@tonic-gate 53*7c478bd9Sstevel@tonic-gate #ifdef DEBUG 54*7c478bd9Sstevel@tonic-gate #define debugging 1 55*7c478bd9Sstevel@tonic-gate #define debug(msg) (void) fprintf(stderr, "%s\n", msg); 56*7c478bd9Sstevel@tonic-gate #else 57*7c478bd9Sstevel@tonic-gate #define debugging 0 58*7c478bd9Sstevel@tonic-gate #define debug(msg) 59*7c478bd9Sstevel@tonic-gate #endif 60*7c478bd9Sstevel@tonic-gate extern AUTH *authdes_seccreate(); 61*7c478bd9Sstevel@tonic-gate 62*7c478bd9Sstevel@tonic-gate int 63*7c478bd9Sstevel@tonic-gate yp_update(domain, map, op, key, keylen, data, datalen) 64*7c478bd9Sstevel@tonic-gate char *domain; 65*7c478bd9Sstevel@tonic-gate char *map; 66*7c478bd9Sstevel@tonic-gate unsigned op; 67*7c478bd9Sstevel@tonic-gate char *key; 68*7c478bd9Sstevel@tonic-gate int keylen; 69*7c478bd9Sstevel@tonic-gate char *data; 70*7c478bd9Sstevel@tonic-gate int datalen; 71*7c478bd9Sstevel@tonic-gate { 72*7c478bd9Sstevel@tonic-gate struct ypupdate_args args; 73*7c478bd9Sstevel@tonic-gate u_int rslt; 74*7c478bd9Sstevel@tonic-gate struct timeval total; 75*7c478bd9Sstevel@tonic-gate CLIENT *client; 76*7c478bd9Sstevel@tonic-gate char *ypmaster; 77*7c478bd9Sstevel@tonic-gate char ypmastername[MAXNETNAMELEN+1]; 78*7c478bd9Sstevel@tonic-gate enum clnt_stat stat; 79*7c478bd9Sstevel@tonic-gate u_int proc; 80*7c478bd9Sstevel@tonic-gate 81*7c478bd9Sstevel@tonic-gate trace3(TR_yp_update, 0, keylen, datalen); 82*7c478bd9Sstevel@tonic-gate switch (op) { 83*7c478bd9Sstevel@tonic-gate case YPOP_DELETE: 84*7c478bd9Sstevel@tonic-gate proc = YPU_DELETE; 85*7c478bd9Sstevel@tonic-gate break; 86*7c478bd9Sstevel@tonic-gate case YPOP_INSERT: 87*7c478bd9Sstevel@tonic-gate proc = YPU_INSERT; 88*7c478bd9Sstevel@tonic-gate break; 89*7c478bd9Sstevel@tonic-gate case YPOP_CHANGE: 90*7c478bd9Sstevel@tonic-gate proc = YPU_CHANGE; 91*7c478bd9Sstevel@tonic-gate break; 92*7c478bd9Sstevel@tonic-gate case YPOP_STORE: 93*7c478bd9Sstevel@tonic-gate proc = YPU_STORE; 94*7c478bd9Sstevel@tonic-gate break; 95*7c478bd9Sstevel@tonic-gate default: 96*7c478bd9Sstevel@tonic-gate trace1(TR_yp_update, 1); 97*7c478bd9Sstevel@tonic-gate return (YPERR_BADARGS); 98*7c478bd9Sstevel@tonic-gate } 99*7c478bd9Sstevel@tonic-gate if (yp_master(domain, map, &ypmaster) != 0) { 100*7c478bd9Sstevel@tonic-gate debug("no master found"); 101*7c478bd9Sstevel@tonic-gate trace1(TR_yp_update, 1); 102*7c478bd9Sstevel@tonic-gate return (YPERR_BADDB); 103*7c478bd9Sstevel@tonic-gate } 104*7c478bd9Sstevel@tonic-gate 105*7c478bd9Sstevel@tonic-gate client = clnt_create(ypmaster, YPU_PROG, YPU_VERS, "circuit_n"); 106*7c478bd9Sstevel@tonic-gate if (client == NULL) { 107*7c478bd9Sstevel@tonic-gate #ifdef DEBUG 108*7c478bd9Sstevel@tonic-gate /* CONSTCOND */ 109*7c478bd9Sstevel@tonic-gate if (debugging) { 110*7c478bd9Sstevel@tonic-gate clnt_pcreateerror("client create failed"); 111*7c478bd9Sstevel@tonic-gate } 112*7c478bd9Sstevel@tonic-gate #endif /* DEBUG */ 113*7c478bd9Sstevel@tonic-gate free(ypmaster); 114*7c478bd9Sstevel@tonic-gate trace1(TR_yp_update, 1); 115*7c478bd9Sstevel@tonic-gate return (YPERR_RPC); 116*7c478bd9Sstevel@tonic-gate } 117*7c478bd9Sstevel@tonic-gate 118*7c478bd9Sstevel@tonic-gate if (! host2netname(ypmastername, ypmaster, domain)) { 119*7c478bd9Sstevel@tonic-gate clnt_destroy(client); 120*7c478bd9Sstevel@tonic-gate free(ypmaster); 121*7c478bd9Sstevel@tonic-gate trace1(TR_yp_update, 1); 122*7c478bd9Sstevel@tonic-gate return (YPERR_BADARGS); 123*7c478bd9Sstevel@tonic-gate } 124*7c478bd9Sstevel@tonic-gate client->cl_auth = authdes_seccreate(ypmastername, WINDOW, 125*7c478bd9Sstevel@tonic-gate ypmaster, NULL); 126*7c478bd9Sstevel@tonic-gate free(ypmaster); 127*7c478bd9Sstevel@tonic-gate if (client->cl_auth == NULL) { 128*7c478bd9Sstevel@tonic-gate debug("auth create failed"); 129*7c478bd9Sstevel@tonic-gate clnt_destroy(client); 130*7c478bd9Sstevel@tonic-gate trace1(TR_yp_update, 1); 131*7c478bd9Sstevel@tonic-gate return (YPERR_RPC); 132*7c478bd9Sstevel@tonic-gate } 133*7c478bd9Sstevel@tonic-gate 134*7c478bd9Sstevel@tonic-gate args.mapname = map; 135*7c478bd9Sstevel@tonic-gate args.key.yp_buf_len = keylen; 136*7c478bd9Sstevel@tonic-gate args.key.yp_buf_val = key; 137*7c478bd9Sstevel@tonic-gate args.datum.yp_buf_len = datalen; 138*7c478bd9Sstevel@tonic-gate args.datum.yp_buf_val = data; 139*7c478bd9Sstevel@tonic-gate 140*7c478bd9Sstevel@tonic-gate total.tv_sec = TOTAL_TIMEOUT; 141*7c478bd9Sstevel@tonic-gate total.tv_usec = 0; 142*7c478bd9Sstevel@tonic-gate clnt_control(client, CLSET_TIMEOUT, (char *)&total); 143*7c478bd9Sstevel@tonic-gate stat = clnt_call(client, proc, 144*7c478bd9Sstevel@tonic-gate xdr_ypupdate_args, (char *)&args, 145*7c478bd9Sstevel@tonic-gate xdr_u_int, (char *)&rslt, total); 146*7c478bd9Sstevel@tonic-gate 147*7c478bd9Sstevel@tonic-gate if (stat != RPC_SUCCESS) { 148*7c478bd9Sstevel@tonic-gate #ifdef DEBUG 149*7c478bd9Sstevel@tonic-gate debug("ypupdate RPC call failed"); 150*7c478bd9Sstevel@tonic-gate /* CONSTCOND */ 151*7c478bd9Sstevel@tonic-gate if (debugging) 152*7c478bd9Sstevel@tonic-gate clnt_perror(client, "ypupdate call failed"); 153*7c478bd9Sstevel@tonic-gate #endif /* DEBUG */ 154*7c478bd9Sstevel@tonic-gate rslt = YPERR_RPC; 155*7c478bd9Sstevel@tonic-gate } 156*7c478bd9Sstevel@tonic-gate auth_destroy(client->cl_auth); 157*7c478bd9Sstevel@tonic-gate clnt_destroy(client); 158*7c478bd9Sstevel@tonic-gate trace1(TR_yp_update, 1); 159*7c478bd9Sstevel@tonic-gate return (rslt); 160*7c478bd9Sstevel@tonic-gate } 161