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 * Copyright 1996 Sun Microsystems, Inc. All rights reserved. 23*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 24*7c478bd9Sstevel@tonic-gate */ 25*7c478bd9Sstevel@tonic-gate 26*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 27*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate /* 30*7c478bd9Sstevel@tonic-gate * Portions of this source code were derived from Berkeley 31*7c478bd9Sstevel@tonic-gate * under license from the Regents of the University of 32*7c478bd9Sstevel@tonic-gate * California. 33*7c478bd9Sstevel@tonic-gate */ 34*7c478bd9Sstevel@tonic-gate 35*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 36*7c478bd9Sstevel@tonic-gate 37*7c478bd9Sstevel@tonic-gate #include <stdio.h> 38*7c478bd9Sstevel@tonic-gate #include <string.h> 39*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 40*7c478bd9Sstevel@tonic-gate #include <sys/statvfs.h> 41*7c478bd9Sstevel@tonic-gate #include "ypsym.h" 42*7c478bd9Sstevel@tonic-gate /* this is 14 less the space for temps pids and .pag more or less */ 43*7c478bd9Sstevel@tonic-gate 44*7c478bd9Sstevel@tonic-gate #ifdef DEBUG 45*7c478bd9Sstevel@tonic-gate #define YPDBDIR "/var/ypnew" 46*7c478bd9Sstevel@tonic-gate #define ALIASLIST "/var/ypnew/aliases" 47*7c478bd9Sstevel@tonic-gate #else 48*7c478bd9Sstevel@tonic-gate #define YPDBDIR "/var/yp" 49*7c478bd9Sstevel@tonic-gate #define ALIASLIST "/var/yp/aliases" 50*7c478bd9Sstevel@tonic-gate #endif 51*7c478bd9Sstevel@tonic-gate #define issep(c) (c == ' ' || c == '\t') 52*7c478bd9Sstevel@tonic-gate 53*7c478bd9Sstevel@tonic-gate #ifdef SYSVCONFIG 54*7c478bd9Sstevel@tonic-gate #define isvar_sysv() (wasitsysv) 55*7c478bd9Sstevel@tonic-gate 56*7c478bd9Sstevel@tonic-gate static int wasitsysv = TRUE; 57*7c478bd9Sstevel@tonic-gate static int first_time = TRUE; 58*7c478bd9Sstevel@tonic-gate static listofnames *list = NULL; 59*7c478bd9Sstevel@tonic-gate #endif 60*7c478bd9Sstevel@tonic-gate 61*7c478bd9Sstevel@tonic-gate void sysv_exit(); 62*7c478bd9Sstevel@tonic-gate extern listofnames *names(); 63*7c478bd9Sstevel@tonic-gate extern void exit(); 64*7c478bd9Sstevel@tonic-gate extern void free_listofnames(); 65*7c478bd9Sstevel@tonic-gate 66*7c478bd9Sstevel@tonic-gate /* 67*7c478bd9Sstevel@tonic-gate * Setup alias file, check /var/yp filesystem type 68*7c478bd9Sstevel@tonic-gate * Note: The *never* checks for aliases under Solaris, so there is no need 69*7c478bd9Sstevel@tonic-gate * for this function. As of 1.1 beta 4, I will ifdef it out (cause 70*7c478bd9Sstevel@tonic-gate * you never know...). Should go away completely soon. 71*7c478bd9Sstevel@tonic-gate */ 72*7c478bd9Sstevel@tonic-gate 73*7c478bd9Sstevel@tonic-gate #ifdef SYSVCONFIG 74*7c478bd9Sstevel@tonic-gate void 75*7c478bd9Sstevel@tonic-gate sysvconfig(void) 76*7c478bd9Sstevel@tonic-gate { 77*7c478bd9Sstevel@tonic-gate struct statvfs statbuf; 78*7c478bd9Sstevel@tonic-gate 79*7c478bd9Sstevel@tonic-gate sigset(SIGCHLD, SIG_IGN); 80*7c478bd9Sstevel@tonic-gate /* 81*7c478bd9Sstevel@tonic-gate * if neccesary free previous list, then read in aliaslist 82*7c478bd9Sstevel@tonic-gate */ 83*7c478bd9Sstevel@tonic-gate 84*7c478bd9Sstevel@tonic-gate if (!first_time) 85*7c478bd9Sstevel@tonic-gate free_listofnames(list); 86*7c478bd9Sstevel@tonic-gate else 87*7c478bd9Sstevel@tonic-gate first_time = FALSE; 88*7c478bd9Sstevel@tonic-gate 89*7c478bd9Sstevel@tonic-gate list = names(ALIASLIST); 90*7c478bd9Sstevel@tonic-gate 91*7c478bd9Sstevel@tonic-gate /* 92*7c478bd9Sstevel@tonic-gate * Check if YP database directory is in a system v filesystem 93*7c478bd9Sstevel@tonic-gate */ 94*7c478bd9Sstevel@tonic-gate 95*7c478bd9Sstevel@tonic-gate if (statvfs(YPDBDIR, &statbuf) != 0) { 96*7c478bd9Sstevel@tonic-gate fprintf(stderr, "Cannot stat %s\n", YPDBDIR); 97*7c478bd9Sstevel@tonic-gate exit(-1); 98*7c478bd9Sstevel@tonic-gate } else { 99*7c478bd9Sstevel@tonic-gate /* if (strcmp(statbuf.f_basetype,"s5")) (doesn't work in k13) */ 100*7c478bd9Sstevel@tonic-gate if (statbuf.f_namemax == 14) 101*7c478bd9Sstevel@tonic-gate wasitsysv = TRUE; 102*7c478bd9Sstevel@tonic-gate else 103*7c478bd9Sstevel@tonic-gate wasitsysv = FALSE; 104*7c478bd9Sstevel@tonic-gate } 105*7c478bd9Sstevel@tonic-gate sigset(SIGCHLD, (void (*)())sysvconfig); 106*7c478bd9Sstevel@tonic-gate } 107*7c478bd9Sstevel@tonic-gate #endif 108*7c478bd9Sstevel@tonic-gate 109*7c478bd9Sstevel@tonic-gate /* 110*7c478bd9Sstevel@tonic-gate * Match key to alias 111*7c478bd9Sstevel@tonic-gate */ 112*7c478bd9Sstevel@tonic-gate int 113*7c478bd9Sstevel@tonic-gate yp_getalias(key, key_alias, maxlen) 114*7c478bd9Sstevel@tonic-gate char *key; 115*7c478bd9Sstevel@tonic-gate char *key_alias; 116*7c478bd9Sstevel@tonic-gate int maxlen; 117*7c478bd9Sstevel@tonic-gate { 118*7c478bd9Sstevel@tonic-gate listofnames *entry; 119*7c478bd9Sstevel@tonic-gate char *longname; 120*7c478bd9Sstevel@tonic-gate char *alias; 121*7c478bd9Sstevel@tonic-gate char name[256]; 122*7c478bd9Sstevel@tonic-gate 123*7c478bd9Sstevel@tonic-gate #ifndef SYSVCONFIG 124*7c478bd9Sstevel@tonic-gate strcpy(key_alias, key); 125*7c478bd9Sstevel@tonic-gate return (0); 126*7c478bd9Sstevel@tonic-gate #else 127*7c478bd9Sstevel@tonic-gate /* sysvconfig must be run before this routine */ 128*7c478bd9Sstevel@tonic-gate if (key == NULL || first_time) 129*7c478bd9Sstevel@tonic-gate return (-1); 130*7c478bd9Sstevel@tonic-gate 131*7c478bd9Sstevel@tonic-gate if (!isvar_sysv()) { 132*7c478bd9Sstevel@tonic-gate strcpy(key_alias, key); 133*7c478bd9Sstevel@tonic-gate return (0); 134*7c478bd9Sstevel@tonic-gate } 135*7c478bd9Sstevel@tonic-gate 136*7c478bd9Sstevel@tonic-gate for (entry = list, strcpy(name, entry->name); entry; 137*7c478bd9Sstevel@tonic-gate entry = entry->nextname, strcpy(name, entry->name)) { 138*7c478bd9Sstevel@tonic-gate 139*7c478bd9Sstevel@tonic-gate longname = strtok(name, " \t"); 140*7c478bd9Sstevel@tonic-gate alias = strtok(NULL, " \t\n"); 141*7c478bd9Sstevel@tonic-gate if (longname == NULL || alias == NULL) { 142*7c478bd9Sstevel@tonic-gate continue; 143*7c478bd9Sstevel@tonic-gate } 144*7c478bd9Sstevel@tonic-gate if (strcmp(longname, key) == 0) { 145*7c478bd9Sstevel@tonic-gate if ((int)strlen(alias) > (maxlen)) { 146*7c478bd9Sstevel@tonic-gate strncpy(key_alias, alias, (maxlen)); 147*7c478bd9Sstevel@tonic-gate key_alias[maxlen] = '\0'; 148*7c478bd9Sstevel@tonic-gate } else { 149*7c478bd9Sstevel@tonic-gate strcpy(key_alias, alias); 150*7c478bd9Sstevel@tonic-gate } 151*7c478bd9Sstevel@tonic-gate return (0); 152*7c478bd9Sstevel@tonic-gate } 153*7c478bd9Sstevel@tonic-gate } 154*7c478bd9Sstevel@tonic-gate /* alias not found */ 155*7c478bd9Sstevel@tonic-gate return (-1); 156*7c478bd9Sstevel@tonic-gate #endif 157*7c478bd9Sstevel@tonic-gate } 158*7c478bd9Sstevel@tonic-gate 159*7c478bd9Sstevel@tonic-gate /* 160*7c478bd9Sstevel@tonic-gate * Match alias to key 161*7c478bd9Sstevel@tonic-gate */ 162*7c478bd9Sstevel@tonic-gate int 163*7c478bd9Sstevel@tonic-gate yp_getkey(key_alias, key, maxlen) 164*7c478bd9Sstevel@tonic-gate char *key_alias; 165*7c478bd9Sstevel@tonic-gate char *key; 166*7c478bd9Sstevel@tonic-gate int maxlen; 167*7c478bd9Sstevel@tonic-gate { 168*7c478bd9Sstevel@tonic-gate listofnames *entry; 169*7c478bd9Sstevel@tonic-gate char *longname; 170*7c478bd9Sstevel@tonic-gate char *alias; 171*7c478bd9Sstevel@tonic-gate char name[256]; 172*7c478bd9Sstevel@tonic-gate 173*7c478bd9Sstevel@tonic-gate #ifndef SYSVCONFIG 174*7c478bd9Sstevel@tonic-gate strcpy(key, key_alias); 175*7c478bd9Sstevel@tonic-gate return (0); 176*7c478bd9Sstevel@tonic-gate #else 177*7c478bd9Sstevel@tonic-gate if (key_alias == NULL || first_time) { 178*7c478bd9Sstevel@tonic-gate return (-1); 179*7c478bd9Sstevel@tonic-gate } 180*7c478bd9Sstevel@tonic-gate 181*7c478bd9Sstevel@tonic-gate if (!isvar_sysv()) { 182*7c478bd9Sstevel@tonic-gate strcpy(key, key_alias); 183*7c478bd9Sstevel@tonic-gate return (0); 184*7c478bd9Sstevel@tonic-gate } 185*7c478bd9Sstevel@tonic-gate 186*7c478bd9Sstevel@tonic-gate for (entry = list, strcpy(name, entry->name); 187*7c478bd9Sstevel@tonic-gate entry; entry = entry->nextname, strcpy(name, entry->name)) { 188*7c478bd9Sstevel@tonic-gate 189*7c478bd9Sstevel@tonic-gate longname = strtok(name, " \t"); 190*7c478bd9Sstevel@tonic-gate alias = strtok(NULL, " \t\n"); 191*7c478bd9Sstevel@tonic-gate if (alias == NULL || longname == NULL) { 192*7c478bd9Sstevel@tonic-gate continue; 193*7c478bd9Sstevel@tonic-gate } 194*7c478bd9Sstevel@tonic-gate if ((strcmp(alias, key_alias) == 0) || 195*7c478bd9Sstevel@tonic-gate (strncmp(alias, key_alias, maxlen) == 0)) { 196*7c478bd9Sstevel@tonic-gate strcpy(key, longname); 197*7c478bd9Sstevel@tonic-gate return (0); 198*7c478bd9Sstevel@tonic-gate } 199*7c478bd9Sstevel@tonic-gate } 200*7c478bd9Sstevel@tonic-gate /* key not found */ 201*7c478bd9Sstevel@tonic-gate return (-1); 202*7c478bd9Sstevel@tonic-gate #endif 203*7c478bd9Sstevel@tonic-gate } 204