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 1990 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 4.3 BSD 32*7c478bd9Sstevel@tonic-gate * under license from the Regents of the University of California. 33*7c478bd9Sstevel@tonic-gate */ 34*7c478bd9Sstevel@tonic-gate 35*7c478bd9Sstevel@tonic-gate #ident "%Z%%M% %I% %E% SMI" 36*7c478bd9Sstevel@tonic-gate 37*7c478bd9Sstevel@tonic-gate #include <rpc/types.h> 38*7c478bd9Sstevel@tonic-gate #include "netconfig.h" 39*7c478bd9Sstevel@tonic-gate #include <stdio.h> 40*7c478bd9Sstevel@tonic-gate #include <synch.h> 41*7c478bd9Sstevel@tonic-gate #include <netdb.h> 42*7c478bd9Sstevel@tonic-gate 43*7c478bd9Sstevel@tonic-gate extern bool_t xdr_netconfig(XDR *, struct netconfig *); 44*7c478bd9Sstevel@tonic-gate 45*7c478bd9Sstevel@tonic-gate #define BINDING "/var/yp/binding" 46*7c478bd9Sstevel@tonic-gate #define YPSETLOCAL 3 47*7c478bd9Sstevel@tonic-gate 48*7c478bd9Sstevel@tonic-gate struct dom_binding { 49*7c478bd9Sstevel@tonic-gate struct dom_binding *dom_pnext; 50*7c478bd9Sstevel@tonic-gate char *dom_domain; 51*7c478bd9Sstevel@tonic-gate struct ypbind_binding *dom_binding; 52*7c478bd9Sstevel@tonic-gate CLIENT *dom_client; 53*7c478bd9Sstevel@tonic-gate int cache_bad; 54*7c478bd9Sstevel@tonic-gate int fd; /* fd in dom_client */ 55*7c478bd9Sstevel@tonic-gate dev_t rdev; /* device id of fd */ 56*7c478bd9Sstevel@tonic-gate int ref_count; /* number of threads using this structure */ 57*7c478bd9Sstevel@tonic-gate int need_free; /* if true, this structure needs to be freed */ 58*7c478bd9Sstevel@tonic-gate mutex_t server_name_lock; /* protects server name in dom_binding */ 59*7c478bd9Sstevel@tonic-gate }; 60*7c478bd9Sstevel@tonic-gate 61*7c478bd9Sstevel@tonic-gate /* Following structure is used only by ypbind */ 62*7c478bd9Sstevel@tonic-gate 63*7c478bd9Sstevel@tonic-gate struct domain { 64*7c478bd9Sstevel@tonic-gate struct domain *dom_pnext; 65*7c478bd9Sstevel@tonic-gate char *dom_name; 66*7c478bd9Sstevel@tonic-gate bool_t dom_boundp; 67*7c478bd9Sstevel@tonic-gate unsigned short dom_vers; /* only YPVERS */ 68*7c478bd9Sstevel@tonic-gate unsigned int dom_error; 69*7c478bd9Sstevel@tonic-gate CLIENT * ping_clnt; 70*7c478bd9Sstevel@tonic-gate struct ypbind_binding *dom_binding; 71*7c478bd9Sstevel@tonic-gate int dom_report_success; /* Controls msg to /dev/console*/ 72*7c478bd9Sstevel@tonic-gate int dom_broadcaster_pid; 73*7c478bd9Sstevel@tonic-gate int bindfile; /* File with binding info in it */ 74*7c478bd9Sstevel@tonic-gate int broadcaster_fd; 75*7c478bd9Sstevel@tonic-gate FILE *broadcaster_pipe; /* to get answer from locater */ 76*7c478bd9Sstevel@tonic-gate XDR broadcaster_xdr; /* xdr for pipe */ 77*7c478bd9Sstevel@tonic-gate struct timeval lastping; /* info to avoid a ping storm */ 78*7c478bd9Sstevel@tonic-gate }; 79*7c478bd9Sstevel@tonic-gate 80*7c478bd9Sstevel@tonic-gate enum ypbind_resptype { 81*7c478bd9Sstevel@tonic-gate YPBIND_SUCC_VAL = 1, 82*7c478bd9Sstevel@tonic-gate YPBIND_FAIL_VAL = 2 83*7c478bd9Sstevel@tonic-gate }; 84*7c478bd9Sstevel@tonic-gate typedef enum ypbind_resptype ypbind_resptype; 85*7c478bd9Sstevel@tonic-gate extern bool_t xdr_ypbind_resptype(XDR *, ypbind_resptype *); 86*7c478bd9Sstevel@tonic-gate #define YPBIND_ERR_ERR 1 /* Internal error */ 87*7c478bd9Sstevel@tonic-gate #define YPBIND_ERR_NOSERV 2 /* No bound server for passed domain */ 88*7c478bd9Sstevel@tonic-gate #define YPBIND_ERR_RESC 3 /* System resource allocation failure */ 89*7c478bd9Sstevel@tonic-gate #define YPBIND_ERR_NODOMAIN 4 /* Domain doesn't exist */ 90*7c478bd9Sstevel@tonic-gate 91*7c478bd9Sstevel@tonic-gate /* Following struct is used only by ypwhich and yppoll */ 92*7c478bd9Sstevel@tonic-gate 93*7c478bd9Sstevel@tonic-gate struct ypbind_domain { 94*7c478bd9Sstevel@tonic-gate char *ypbind_domainname; 95*7c478bd9Sstevel@tonic-gate rpcvers_t ypbind_vers; 96*7c478bd9Sstevel@tonic-gate }; 97*7c478bd9Sstevel@tonic-gate typedef struct ypbind_domain ypbind_domain; 98*7c478bd9Sstevel@tonic-gate bool_t xdr_ypbind_domain(XDR *, ypbind_domain *); 99*7c478bd9Sstevel@tonic-gate 100*7c478bd9Sstevel@tonic-gate /* 101*7c478bd9Sstevel@tonic-gate * This structure is used to store information about the server 102*7c478bd9Sstevel@tonic-gate * Returned by ypbind to the libnsl/yp clients to contact ypserv. 103*7c478bd9Sstevel@tonic-gate * Also used by ypxfr. 104*7c478bd9Sstevel@tonic-gate */ 105*7c478bd9Sstevel@tonic-gate 106*7c478bd9Sstevel@tonic-gate struct ypbind_binding { 107*7c478bd9Sstevel@tonic-gate struct netconfig *ypbind_nconf; 108*7c478bd9Sstevel@tonic-gate struct netbuf *ypbind_svcaddr; 109*7c478bd9Sstevel@tonic-gate char *ypbind_servername; 110*7c478bd9Sstevel@tonic-gate rpcvers_t ypbind_hi_vers; 111*7c478bd9Sstevel@tonic-gate rpcvers_t ypbind_lo_vers; 112*7c478bd9Sstevel@tonic-gate }; 113*7c478bd9Sstevel@tonic-gate typedef struct ypbind_binding ypbind_binding; 114*7c478bd9Sstevel@tonic-gate bool_t xdr_ypbind_binding(XDR *, ypbind_binding *); 115*7c478bd9Sstevel@tonic-gate 116*7c478bd9Sstevel@tonic-gate struct ypbind_resp { 117*7c478bd9Sstevel@tonic-gate ypbind_resptype ypbind_status; 118*7c478bd9Sstevel@tonic-gate union { 119*7c478bd9Sstevel@tonic-gate u_int ypbind_error; 120*7c478bd9Sstevel@tonic-gate struct ypbind_binding *ypbind_bindinfo; 121*7c478bd9Sstevel@tonic-gate } ypbind_resp_u; 122*7c478bd9Sstevel@tonic-gate }; 123*7c478bd9Sstevel@tonic-gate typedef struct ypbind_resp ypbind_resp; 124*7c478bd9Sstevel@tonic-gate bool_t xdr_ypbind_resp(XDR *, ypbind_resp *); 125*7c478bd9Sstevel@tonic-gate 126*7c478bd9Sstevel@tonic-gate struct ypbind_setdom { 127*7c478bd9Sstevel@tonic-gate char *ypsetdom_domain; 128*7c478bd9Sstevel@tonic-gate struct ypbind_binding *ypsetdom_bindinfo; 129*7c478bd9Sstevel@tonic-gate }; 130*7c478bd9Sstevel@tonic-gate typedef struct ypbind_setdom ypbind_setdom; 131*7c478bd9Sstevel@tonic-gate bool_t xdr_ypbind_setdom(XDR *, ypbind_setdom *); 132*7c478bd9Sstevel@tonic-gate 133*7c478bd9Sstevel@tonic-gate #define YPBINDPROG ((rpcprog_t)100007) 134*7c478bd9Sstevel@tonic-gate #define YPBINDVERS ((rpcvers_t)3) 135*7c478bd9Sstevel@tonic-gate #define YPBINDPROC_NULL ((rpcproc_t)0) 136*7c478bd9Sstevel@tonic-gate extern void *ypbindproc_null_3(); 137*7c478bd9Sstevel@tonic-gate #define YPBINDPROC_DOMAIN ((rpcproc_t)1) 138*7c478bd9Sstevel@tonic-gate extern ypbind_resp *ypbindproc_domain_3(); 139*7c478bd9Sstevel@tonic-gate #define YPBINDPROC_SETDOM ((rpcproc_t)2) 140*7c478bd9Sstevel@tonic-gate extern void *ypbindproc_setdom_3(); 141*7c478bd9Sstevel@tonic-gate 142*7c478bd9Sstevel@tonic-gate extern struct timeval _ypserv_timeout; 143*7c478bd9Sstevel@tonic-gate extern unsigned int _ypsleeptime; 144*7c478bd9Sstevel@tonic-gate 145*7c478bd9Sstevel@tonic-gate extern int __yp_dobind(char *, struct dom_binding **); 146*7c478bd9Sstevel@tonic-gate extern int __yp_dobind_rsvdport(char *, struct dom_binding **); 147*7c478bd9Sstevel@tonic-gate extern void free_dom_binding(struct dom_binding *); 148*7c478bd9Sstevel@tonic-gate extern CLIENT *__yp_clnt_create_rsvdport(const char *, rpcprog_t, 149*7c478bd9Sstevel@tonic-gate rpcvers_t, const char *, const uint_t, const uint_t); 150*7c478bd9Sstevel@tonic-gate extern void __yp_rel_binding(struct dom_binding *); 151*7c478bd9Sstevel@tonic-gate extern CLIENT *__clnt_create_loopback(rpcprog_t, rpcvers_t, int *); 152*7c478bd9Sstevel@tonic-gate 153*7c478bd9Sstevel@tonic-gate extern int _fcntl(int, int, ...); 154*7c478bd9Sstevel@tonic-gate extern uint_t _sleep(uint_t); 155