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 #pragma ident "%Z%%M% %I% %E% SMI" 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate #include <stdio.h> 30*7c478bd9Sstevel@tonic-gate #include <string.h> 31*7c478bd9Sstevel@tonic-gate #include <stdlib.h> 32*7c478bd9Sstevel@tonic-gate #include <ctype.h> 33*7c478bd9Sstevel@tonic-gate #include <fcntl.h> 34*7c478bd9Sstevel@tonic-gate #include <unistd.h> 35*7c478bd9Sstevel@tonic-gate #include <errno.h> 36*7c478bd9Sstevel@tonic-gate #include <locale.h> 37*7c478bd9Sstevel@tonic-gate #include <lber.h> 38*7c478bd9Sstevel@tonic-gate #include <ldap.h> 39*7c478bd9Sstevel@tonic-gate #include <syslog.h> 40*7c478bd9Sstevel@tonic-gate #include <dlfcn.h> /* for dynamic loading only */ 41*7c478bd9Sstevel@tonic-gate 42*7c478bd9Sstevel@tonic-gate #include "ldap_parse.h" 43*7c478bd9Sstevel@tonic-gate #include "nis_parse_ldap_conf.h" 44*7c478bd9Sstevel@tonic-gate #include "nis_parse_ldap_err.h" 45*7c478bd9Sstevel@tonic-gate #include "ldap_util.h" 46*7c478bd9Sstevel@tonic-gate #include "ldap_util.h" 47*7c478bd9Sstevel@tonic-gate 48*7c478bd9Sstevel@tonic-gate void append_dot(char **str); 49*7c478bd9Sstevel@tonic-gate void append_comma(char **str); 50*7c478bd9Sstevel@tonic-gate bool_t make_full_dn(char **dn, const char *base); 51*7c478bd9Sstevel@tonic-gate bool_t make_fqdn(__nis_object_dn_t *dn, const char *base); 52*7c478bd9Sstevel@tonic-gate char *get_default_ldap_base(const char *domain); 53*7c478bd9Sstevel@tonic-gate bool_t add_domain(char **objName, const char *domain); 54*7c478bd9Sstevel@tonic-gate bool_t add_column(__nis_table_mapping_t *t, const char *col_name); 55*7c478bd9Sstevel@tonic-gate __nis_mapping_rule_t **dup_mapping_rules( 56*7c478bd9Sstevel@tonic-gate __nis_mapping_rule_t **rules, int n_rules); 57*7c478bd9Sstevel@tonic-gate __nis_mapping_rule_t *dup_mapping_rule( 58*7c478bd9Sstevel@tonic-gate __nis_mapping_rule_t *in); 59*7c478bd9Sstevel@tonic-gate void *s_malloc(size_t size); 60*7c478bd9Sstevel@tonic-gate __nis_mapping_format_t *dup_format_mapping( 61*7c478bd9Sstevel@tonic-gate __nis_mapping_format_t *in); 62*7c478bd9Sstevel@tonic-gate bool_t dup_mapping_element(__nis_mapping_element_t *in, 63*7c478bd9Sstevel@tonic-gate __nis_mapping_element_t *out); 64*7c478bd9Sstevel@tonic-gate 65*7c478bd9Sstevel@tonic-gate extern FILE *cons; 66*7c478bd9Sstevel@tonic-gate 67*7c478bd9Sstevel@tonic-gate /* 68*7c478bd9Sstevel@tonic-gate * FUNCTION: free_parse_structs 69*7c478bd9Sstevel@tonic-gate * 70*7c478bd9Sstevel@tonic-gate * Release the resources in parse results 71*7c478bd9Sstevel@tonic-gate * 72*7c478bd9Sstevel@tonic-gate */ 73*7c478bd9Sstevel@tonic-gate 74*7c478bd9Sstevel@tonic-gate void 75*7c478bd9Sstevel@tonic-gate free_parse_structs() 76*7c478bd9Sstevel@tonic-gate { 77*7c478bd9Sstevel@tonic-gate __nis_table_mapping_t *t; 78*7c478bd9Sstevel@tonic-gate __nis_table_mapping_t *t1; 79*7c478bd9Sstevel@tonic-gate 80*7c478bd9Sstevel@tonic-gate free_proxy_info(&proxyInfo); 81*7c478bd9Sstevel@tonic-gate for (t = ldapTableMapping; t != NULL; t = t1) { 82*7c478bd9Sstevel@tonic-gate t1 = t->next; 83*7c478bd9Sstevel@tonic-gate free_table_mapping(t); 84*7c478bd9Sstevel@tonic-gate } 85*7c478bd9Sstevel@tonic-gate ldapTableMapping = NULL; 86*7c478bd9Sstevel@tonic-gate } 87*7c478bd9Sstevel@tonic-gate 88*7c478bd9Sstevel@tonic-gate /* 89*7c478bd9Sstevel@tonic-gate * FUNCTION: initialize_parse_structs 90*7c478bd9Sstevel@tonic-gate * 91*7c478bd9Sstevel@tonic-gate * Initialize fields to unset values 92*7c478bd9Sstevel@tonic-gate * 93*7c478bd9Sstevel@tonic-gate * INPUT: __nis_ldap_proxy_info, __nis_config_t 94*7c478bd9Sstevel@tonic-gate * and __nisdb_table_mapping_t structures 95*7c478bd9Sstevel@tonic-gate */ 96*7c478bd9Sstevel@tonic-gate 97*7c478bd9Sstevel@tonic-gate void 98*7c478bd9Sstevel@tonic-gate initialize_parse_structs( 99*7c478bd9Sstevel@tonic-gate __nis_ldap_proxy_info *proxy_info, 100*7c478bd9Sstevel@tonic-gate __nis_config_t *config_info, 101*7c478bd9Sstevel@tonic-gate __nisdb_table_mapping_t *table_info) 102*7c478bd9Sstevel@tonic-gate { 103*7c478bd9Sstevel@tonic-gate proxy_info->default_servers = NULL; 104*7c478bd9Sstevel@tonic-gate proxy_info->auth_method = (auth_method_t)NO_VALUE_SET; 105*7c478bd9Sstevel@tonic-gate proxy_info->tls_method = (tls_method_t)NO_VALUE_SET; 106*7c478bd9Sstevel@tonic-gate proxy_info->tls_cert_db = NULL; 107*7c478bd9Sstevel@tonic-gate proxy_info->default_search_base = NULL; 108*7c478bd9Sstevel@tonic-gate proxy_info->proxy_dn = NULL; 109*7c478bd9Sstevel@tonic-gate proxy_info->proxy_passwd = NULL; 110*7c478bd9Sstevel@tonic-gate proxy_info->default_nis_domain = NULL; 111*7c478bd9Sstevel@tonic-gate proxy_info->bind_timeout.tv_sec = (time_t)NO_VALUE_SET; 112*7c478bd9Sstevel@tonic-gate proxy_info->bind_timeout.tv_usec = 0; 113*7c478bd9Sstevel@tonic-gate proxy_info->search_timeout.tv_sec = (time_t)NO_VALUE_SET; 114*7c478bd9Sstevel@tonic-gate proxy_info->search_timeout.tv_usec = 0; 115*7c478bd9Sstevel@tonic-gate proxy_info->modify_timeout.tv_sec = (time_t)NO_VALUE_SET; 116*7c478bd9Sstevel@tonic-gate proxy_info->modify_timeout.tv_usec = 0; 117*7c478bd9Sstevel@tonic-gate proxy_info->add_timeout.tv_sec = (time_t)NO_VALUE_SET; 118*7c478bd9Sstevel@tonic-gate proxy_info->add_timeout.tv_usec = 0; 119*7c478bd9Sstevel@tonic-gate proxy_info->delete_timeout.tv_sec = (time_t)NO_VALUE_SET; 120*7c478bd9Sstevel@tonic-gate proxy_info->delete_timeout.tv_usec = 0; 121*7c478bd9Sstevel@tonic-gate proxy_info->search_time_limit = (int)NO_VALUE_SET; 122*7c478bd9Sstevel@tonic-gate proxy_info->search_size_limit = (int)NO_VALUE_SET; 123*7c478bd9Sstevel@tonic-gate proxy_info->follow_referral = (follow_referral_t)NO_VALUE_SET; 124*7c478bd9Sstevel@tonic-gate 125*7c478bd9Sstevel@tonic-gate 126*7c478bd9Sstevel@tonic-gate config_info->initialUpdate = (__nis_initial_update_t)NO_VALUE_SET; 127*7c478bd9Sstevel@tonic-gate config_info->threadCreationError = 128*7c478bd9Sstevel@tonic-gate (__nis_thread_creation_error_t)NO_VALUE_SET; 129*7c478bd9Sstevel@tonic-gate config_info->threadCreationErrorTimeout.attempts = NO_VALUE_SET; 130*7c478bd9Sstevel@tonic-gate config_info->threadCreationErrorTimeout.timeout = (time_t)NO_VALUE_SET; 131*7c478bd9Sstevel@tonic-gate config_info->dumpError = (__nis_dump_error_t)NO_VALUE_SET; 132*7c478bd9Sstevel@tonic-gate config_info->dumpErrorTimeout.attempts = NO_VALUE_SET; 133*7c478bd9Sstevel@tonic-gate config_info->dumpErrorTimeout.timeout = (time_t)NO_VALUE_SET; 134*7c478bd9Sstevel@tonic-gate config_info->resyncService = (__nis_resync_service_t)NO_VALUE_SET; 135*7c478bd9Sstevel@tonic-gate config_info->updateBatching = (__nis_update_batching_t)NO_VALUE_SET; 136*7c478bd9Sstevel@tonic-gate config_info->updateBatchingTimeout.timeout = (time_t)NO_VALUE_SET; 137*7c478bd9Sstevel@tonic-gate config_info->numberOfServiceThreads = (int)NO_VALUE_SET; 138*7c478bd9Sstevel@tonic-gate config_info->emulate_yp = (int)NO_VALUE_SET; 139*7c478bd9Sstevel@tonic-gate config_info->maxRPCRecordSize = (int)NO_VALUE_SET; 140*7c478bd9Sstevel@tonic-gate 141*7c478bd9Sstevel@tonic-gate table_info->retrieveError = (__nis_retrieve_error_t)NO_VALUE_SET; 142*7c478bd9Sstevel@tonic-gate table_info->retrieveErrorRetry.attempts = NO_VALUE_SET; 143*7c478bd9Sstevel@tonic-gate table_info->retrieveErrorRetry.timeout = (time_t)NO_VALUE_SET; 144*7c478bd9Sstevel@tonic-gate table_info->storeError = (__nis_store_error_t)NO_VALUE_SET; 145*7c478bd9Sstevel@tonic-gate table_info->storeErrorRetry.attempts = NO_VALUE_SET; 146*7c478bd9Sstevel@tonic-gate table_info->storeErrorRetry.timeout = (time_t)NO_VALUE_SET; 147*7c478bd9Sstevel@tonic-gate table_info->refreshError = (__nis_refresh_error_t)NO_VALUE_SET; 148*7c478bd9Sstevel@tonic-gate table_info->refreshErrorRetry.attempts = NO_VALUE_SET; 149*7c478bd9Sstevel@tonic-gate table_info->refreshErrorRetry.timeout = (time_t)NO_VALUE_SET; 150*7c478bd9Sstevel@tonic-gate table_info->matchFetch = (__nis_match_fetch_t)NO_VALUE_SET; 151*7c478bd9Sstevel@tonic-gate } 152*7c478bd9Sstevel@tonic-gate 153*7c478bd9Sstevel@tonic-gate /* 154*7c478bd9Sstevel@tonic-gate * FUNCTION: free_mapping_rule 155*7c478bd9Sstevel@tonic-gate * 156*7c478bd9Sstevel@tonic-gate * Frees __nis_mapping_rule_t 157*7c478bd9Sstevel@tonic-gate * 158*7c478bd9Sstevel@tonic-gate * INPUT: __nis_mapping_rule_t 159*7c478bd9Sstevel@tonic-gate */ 160*7c478bd9Sstevel@tonic-gate 161*7c478bd9Sstevel@tonic-gate void 162*7c478bd9Sstevel@tonic-gate free_mapping_rule(__nis_mapping_rule_t *rule) 163*7c478bd9Sstevel@tonic-gate { 164*7c478bd9Sstevel@tonic-gate int i; 165*7c478bd9Sstevel@tonic-gate __nis_mapping_rlhs_t *r; 166*7c478bd9Sstevel@tonic-gate 167*7c478bd9Sstevel@tonic-gate if (rule != NULL) { 168*7c478bd9Sstevel@tonic-gate r = &rule->lhs; 169*7c478bd9Sstevel@tonic-gate for (i = 0; i < r->numElements; i++) 170*7c478bd9Sstevel@tonic-gate free_mapping_element(&r->element[i]); 171*7c478bd9Sstevel@tonic-gate if (r->element != NULL) 172*7c478bd9Sstevel@tonic-gate free(r->element); 173*7c478bd9Sstevel@tonic-gate 174*7c478bd9Sstevel@tonic-gate r = &rule->rhs; 175*7c478bd9Sstevel@tonic-gate for (i = 0; i < r->numElements; i++) 176*7c478bd9Sstevel@tonic-gate free_mapping_element(&r->element[i]); 177*7c478bd9Sstevel@tonic-gate if (r->element != NULL) 178*7c478bd9Sstevel@tonic-gate free(r->element); 179*7c478bd9Sstevel@tonic-gate 180*7c478bd9Sstevel@tonic-gate free(rule); 181*7c478bd9Sstevel@tonic-gate } 182*7c478bd9Sstevel@tonic-gate } 183*7c478bd9Sstevel@tonic-gate 184*7c478bd9Sstevel@tonic-gate /* 185*7c478bd9Sstevel@tonic-gate * FUNCTION: free_mapping_element 186*7c478bd9Sstevel@tonic-gate * 187*7c478bd9Sstevel@tonic-gate * Frees __nis_mapping_element_t 188*7c478bd9Sstevel@tonic-gate * 189*7c478bd9Sstevel@tonic-gate * INPUT: __nis_mapping_element_t 190*7c478bd9Sstevel@tonic-gate */ 191*7c478bd9Sstevel@tonic-gate 192*7c478bd9Sstevel@tonic-gate void 193*7c478bd9Sstevel@tonic-gate free_mapping_element(__nis_mapping_element_t *e) 194*7c478bd9Sstevel@tonic-gate { 195*7c478bd9Sstevel@tonic-gate int i; 196*7c478bd9Sstevel@tonic-gate 197*7c478bd9Sstevel@tonic-gate if (e == NULL) 198*7c478bd9Sstevel@tonic-gate return; 199*7c478bd9Sstevel@tonic-gate 200*7c478bd9Sstevel@tonic-gate switch (e->type) { 201*7c478bd9Sstevel@tonic-gate case me_item: 202*7c478bd9Sstevel@tonic-gate free_mapping_item(&e->element.item); 203*7c478bd9Sstevel@tonic-gate break; 204*7c478bd9Sstevel@tonic-gate case me_print: 205*7c478bd9Sstevel@tonic-gate if (e->element.print.fmt != NULL) 206*7c478bd9Sstevel@tonic-gate free_mapping_format(e->element.print.fmt); 207*7c478bd9Sstevel@tonic-gate e->element.print.fmt = NULL; 208*7c478bd9Sstevel@tonic-gate for (i = 0; i < e->element.print.numSubElements; i++) 209*7c478bd9Sstevel@tonic-gate free_mapping_sub_element( 210*7c478bd9Sstevel@tonic-gate &e->element.print.subElement[i]); 211*7c478bd9Sstevel@tonic-gate e->element.print.numSubElements = 0; 212*7c478bd9Sstevel@tonic-gate if (e->element.print.subElement != NULL) 213*7c478bd9Sstevel@tonic-gate free(e->element.print.subElement); 214*7c478bd9Sstevel@tonic-gate e->element.print.subElement = NULL; 215*7c478bd9Sstevel@tonic-gate break; 216*7c478bd9Sstevel@tonic-gate case me_split: 217*7c478bd9Sstevel@tonic-gate free_mapping_item(&e->element.split.item); 218*7c478bd9Sstevel@tonic-gate break; 219*7c478bd9Sstevel@tonic-gate case me_match: 220*7c478bd9Sstevel@tonic-gate if (e->element.match.fmt != NULL) 221*7c478bd9Sstevel@tonic-gate free_mapping_format(e->element.match.fmt); 222*7c478bd9Sstevel@tonic-gate e->element.match.fmt = NULL; 223*7c478bd9Sstevel@tonic-gate for (i = 0; i < e->element.match.numItems; i++) 224*7c478bd9Sstevel@tonic-gate free_mapping_item(&e->element.match.item[i]); 225*7c478bd9Sstevel@tonic-gate e->element.match.numItems = 0; 226*7c478bd9Sstevel@tonic-gate if (e->element.match.item != NULL) 227*7c478bd9Sstevel@tonic-gate free(e->element.match.item); 228*7c478bd9Sstevel@tonic-gate e->element.match.item = NULL; 229*7c478bd9Sstevel@tonic-gate break; 230*7c478bd9Sstevel@tonic-gate case me_extract: 231*7c478bd9Sstevel@tonic-gate if (e->element.extract.fmt != NULL) 232*7c478bd9Sstevel@tonic-gate free_mapping_format(e->element.extract.fmt); 233*7c478bd9Sstevel@tonic-gate e->element.extract.fmt = NULL; 234*7c478bd9Sstevel@tonic-gate free_mapping_item(&e->element.extract.item); 235*7c478bd9Sstevel@tonic-gate break; 236*7c478bd9Sstevel@tonic-gate } 237*7c478bd9Sstevel@tonic-gate e = NULL; 238*7c478bd9Sstevel@tonic-gate } 239*7c478bd9Sstevel@tonic-gate 240*7c478bd9Sstevel@tonic-gate /* 241*7c478bd9Sstevel@tonic-gate * FUNCTION: free_table_mapping 242*7c478bd9Sstevel@tonic-gate * 243*7c478bd9Sstevel@tonic-gate * Frees __nis_table_mapping_t 244*7c478bd9Sstevel@tonic-gate * 245*7c478bd9Sstevel@tonic-gate * INPUT: __nis_table_mapping_t 246*7c478bd9Sstevel@tonic-gate */ 247*7c478bd9Sstevel@tonic-gate 248*7c478bd9Sstevel@tonic-gate /* 249*7c478bd9Sstevel@tonic-gate * free_table_mapping does not remove the table mapping from 250*7c478bd9Sstevel@tonic-gate * its hashed list 251*7c478bd9Sstevel@tonic-gate */ 252*7c478bd9Sstevel@tonic-gate 253*7c478bd9Sstevel@tonic-gate void 254*7c478bd9Sstevel@tonic-gate free_table_mapping(__nis_table_mapping_t *mapping) 255*7c478bd9Sstevel@tonic-gate { 256*7c478bd9Sstevel@tonic-gate int i; 257*7c478bd9Sstevel@tonic-gate 258*7c478bd9Sstevel@tonic-gate if (mapping == NULL) 259*7c478bd9Sstevel@tonic-gate return; 260*7c478bd9Sstevel@tonic-gate 261*7c478bd9Sstevel@tonic-gate if (mapping->dbId != NULL) 262*7c478bd9Sstevel@tonic-gate free(mapping->dbId); 263*7c478bd9Sstevel@tonic-gate mapping->dbId = NULL; 264*7c478bd9Sstevel@tonic-gate 265*7c478bd9Sstevel@tonic-gate if (mapping->objName != NULL) 266*7c478bd9Sstevel@tonic-gate free(mapping->objName); 267*7c478bd9Sstevel@tonic-gate mapping->objName = NULL; 268*7c478bd9Sstevel@tonic-gate 269*7c478bd9Sstevel@tonic-gate for (i = 0; i < mapping->index.numIndexes; i++) { 270*7c478bd9Sstevel@tonic-gate free(mapping->index.name[i]); 271*7c478bd9Sstevel@tonic-gate free_mapping_format(mapping->index.value[i]); 272*7c478bd9Sstevel@tonic-gate } 273*7c478bd9Sstevel@tonic-gate 274*7c478bd9Sstevel@tonic-gate if (mapping->index.name != NULL) 275*7c478bd9Sstevel@tonic-gate free(mapping->index.name); 276*7c478bd9Sstevel@tonic-gate mapping->index.name = NULL; 277*7c478bd9Sstevel@tonic-gate 278*7c478bd9Sstevel@tonic-gate if (mapping->index.value != NULL) 279*7c478bd9Sstevel@tonic-gate free(mapping->index.value); 280*7c478bd9Sstevel@tonic-gate mapping->index.value = NULL; 281*7c478bd9Sstevel@tonic-gate 282*7c478bd9Sstevel@tonic-gate mapping->index.numIndexes = 0; 283*7c478bd9Sstevel@tonic-gate 284*7c478bd9Sstevel@tonic-gate if (mapping->column != NULL) { 285*7c478bd9Sstevel@tonic-gate for (i = 0; i < mapping->numColumns; i++) { 286*7c478bd9Sstevel@tonic-gate free(mapping->column[i]); 287*7c478bd9Sstevel@tonic-gate } 288*7c478bd9Sstevel@tonic-gate mapping->numColumns = 0; 289*7c478bd9Sstevel@tonic-gate free(mapping->column); 290*7c478bd9Sstevel@tonic-gate mapping->column = NULL; 291*7c478bd9Sstevel@tonic-gate } 292*7c478bd9Sstevel@tonic-gate 293*7c478bd9Sstevel@tonic-gate if (mapping->commentChar != NULL) 294*7c478bd9Sstevel@tonic-gate mapping->commentChar = NULL; 295*7c478bd9Sstevel@tonic-gate 296*7c478bd9Sstevel@tonic-gate if (mapping->objectDN != NULL) 297*7c478bd9Sstevel@tonic-gate free_object_dn(mapping->objectDN); 298*7c478bd9Sstevel@tonic-gate mapping->objectDN = NULL; 299*7c478bd9Sstevel@tonic-gate 300*7c478bd9Sstevel@tonic-gate if (mapping->separatorStr != NULL) 301*7c478bd9Sstevel@tonic-gate mapping->separatorStr = NULL; 302*7c478bd9Sstevel@tonic-gate 303*7c478bd9Sstevel@tonic-gate for (i = 0; i < mapping->numRulesFromLDAP; i++) { 304*7c478bd9Sstevel@tonic-gate if (mapping->ruleFromLDAP[i]) /* See Comment below */ 305*7c478bd9Sstevel@tonic-gate free_mapping_rule(mapping->ruleFromLDAP[i]); 306*7c478bd9Sstevel@tonic-gate } 307*7c478bd9Sstevel@tonic-gate mapping->numRulesFromLDAP = 0; 308*7c478bd9Sstevel@tonic-gate 309*7c478bd9Sstevel@tonic-gate if (mapping->ruleFromLDAP != NULL) 310*7c478bd9Sstevel@tonic-gate free(mapping->ruleFromLDAP); 311*7c478bd9Sstevel@tonic-gate mapping->ruleFromLDAP = NULL; 312*7c478bd9Sstevel@tonic-gate 313*7c478bd9Sstevel@tonic-gate for (i = 0; i < mapping->numRulesToLDAP; i++) { 314*7c478bd9Sstevel@tonic-gate if (mapping->ruleToLDAP[i]) 315*7c478bd9Sstevel@tonic-gate /* 316*7c478bd9Sstevel@tonic-gate * Normally mapping->ruleToLDAP[i] should 317*7c478bd9Sstevel@tonic-gate * always be non-null if 318*7c478bd9Sstevel@tonic-gate * mapping->numRulesToLDAP is > 0. 319*7c478bd9Sstevel@tonic-gate * However it is possible to have data 320*7c478bd9Sstevel@tonic-gate * corruption where numRulesToLDAP gets 321*7c478bd9Sstevel@tonic-gate * some integer value even though no real 322*7c478bd9Sstevel@tonic-gate * data is present in mapping->ruleToLDAP. 323*7c478bd9Sstevel@tonic-gate */ 324*7c478bd9Sstevel@tonic-gate free_mapping_rule(mapping->ruleToLDAP[i]); 325*7c478bd9Sstevel@tonic-gate } 326*7c478bd9Sstevel@tonic-gate mapping->numRulesToLDAP = 0; 327*7c478bd9Sstevel@tonic-gate 328*7c478bd9Sstevel@tonic-gate if (mapping->ruleToLDAP != NULL) 329*7c478bd9Sstevel@tonic-gate free(mapping->ruleToLDAP); 330*7c478bd9Sstevel@tonic-gate mapping->ruleToLDAP = NULL; 331*7c478bd9Sstevel@tonic-gate 332*7c478bd9Sstevel@tonic-gate if (mapping->e != NULL) { 333*7c478bd9Sstevel@tonic-gate /* Similar logic as in above comment applies. */ 334*7c478bd9Sstevel@tonic-gate for (i = 0; i <= mapping->numSplits; i++) { 335*7c478bd9Sstevel@tonic-gate free_mapping_element(&mapping->e[i]); 336*7c478bd9Sstevel@tonic-gate } 337*7c478bd9Sstevel@tonic-gate free(mapping->e); 338*7c478bd9Sstevel@tonic-gate } 339*7c478bd9Sstevel@tonic-gate mapping->e = NULL; 340*7c478bd9Sstevel@tonic-gate 341*7c478bd9Sstevel@tonic-gate mapping->numSplits = 0; 342*7c478bd9Sstevel@tonic-gate 343*7c478bd9Sstevel@tonic-gate free(mapping); 344*7c478bd9Sstevel@tonic-gate } 345*7c478bd9Sstevel@tonic-gate 346*7c478bd9Sstevel@tonic-gate /* 347*7c478bd9Sstevel@tonic-gate * FUNCTION: free_config_info 348*7c478bd9Sstevel@tonic-gate * 349*7c478bd9Sstevel@tonic-gate * Frees __nis_config_info_t 350*7c478bd9Sstevel@tonic-gate * 351*7c478bd9Sstevel@tonic-gate * INPUT: __nis_config_info_t 352*7c478bd9Sstevel@tonic-gate */ 353*7c478bd9Sstevel@tonic-gate 354*7c478bd9Sstevel@tonic-gate void 355*7c478bd9Sstevel@tonic-gate free_config_info(__nis_config_info_t *config_info) 356*7c478bd9Sstevel@tonic-gate { 357*7c478bd9Sstevel@tonic-gate if (config_info->config_dn != NULL) 358*7c478bd9Sstevel@tonic-gate free(config_info->config_dn); 359*7c478bd9Sstevel@tonic-gate config_info->config_dn = NULL; 360*7c478bd9Sstevel@tonic-gate 361*7c478bd9Sstevel@tonic-gate if (config_info->default_servers != NULL) 362*7c478bd9Sstevel@tonic-gate free(config_info->default_servers); 363*7c478bd9Sstevel@tonic-gate config_info->default_servers = NULL; 364*7c478bd9Sstevel@tonic-gate 365*7c478bd9Sstevel@tonic-gate if (config_info->proxy_dn != NULL) 366*7c478bd9Sstevel@tonic-gate free(config_info->proxy_dn); 367*7c478bd9Sstevel@tonic-gate config_info->proxy_dn = NULL; 368*7c478bd9Sstevel@tonic-gate 369*7c478bd9Sstevel@tonic-gate if (config_info->proxy_passwd != NULL) 370*7c478bd9Sstevel@tonic-gate free(config_info->proxy_passwd); 371*7c478bd9Sstevel@tonic-gate config_info->proxy_passwd = NULL; 372*7c478bd9Sstevel@tonic-gate 373*7c478bd9Sstevel@tonic-gate if (config_info->tls_cert_db != NULL) 374*7c478bd9Sstevel@tonic-gate free(config_info->tls_cert_db); 375*7c478bd9Sstevel@tonic-gate config_info->tls_cert_db = NULL; 376*7c478bd9Sstevel@tonic-gate } 377*7c478bd9Sstevel@tonic-gate 378*7c478bd9Sstevel@tonic-gate /* 379*7c478bd9Sstevel@tonic-gate * FUNCTION: free_proxy_info 380*7c478bd9Sstevel@tonic-gate * 381*7c478bd9Sstevel@tonic-gate * Frees __nis_ldap_proxy_info 382*7c478bd9Sstevel@tonic-gate * 383*7c478bd9Sstevel@tonic-gate * INPUT: __nis_ldap_proxy_info 384*7c478bd9Sstevel@tonic-gate */ 385*7c478bd9Sstevel@tonic-gate 386*7c478bd9Sstevel@tonic-gate void 387*7c478bd9Sstevel@tonic-gate free_proxy_info(__nis_ldap_proxy_info *proxy_info) 388*7c478bd9Sstevel@tonic-gate { 389*7c478bd9Sstevel@tonic-gate if (proxy_info->tls_cert_db != NULL) 390*7c478bd9Sstevel@tonic-gate free(proxy_info->tls_cert_db); 391*7c478bd9Sstevel@tonic-gate proxy_info->tls_cert_db = NULL; 392*7c478bd9Sstevel@tonic-gate 393*7c478bd9Sstevel@tonic-gate if (proxy_info->default_servers != NULL) 394*7c478bd9Sstevel@tonic-gate free(proxy_info->default_servers); 395*7c478bd9Sstevel@tonic-gate proxy_info->default_servers = NULL; 396*7c478bd9Sstevel@tonic-gate 397*7c478bd9Sstevel@tonic-gate if (proxy_info->default_search_base != NULL) 398*7c478bd9Sstevel@tonic-gate free(proxy_info->default_search_base); 399*7c478bd9Sstevel@tonic-gate proxy_info->default_search_base = NULL; 400*7c478bd9Sstevel@tonic-gate 401*7c478bd9Sstevel@tonic-gate if (proxy_info->proxy_dn != NULL) 402*7c478bd9Sstevel@tonic-gate free(proxy_info->proxy_dn); 403*7c478bd9Sstevel@tonic-gate proxy_info->proxy_dn = NULL; 404*7c478bd9Sstevel@tonic-gate 405*7c478bd9Sstevel@tonic-gate if (proxy_info->proxy_passwd != NULL) 406*7c478bd9Sstevel@tonic-gate free(proxy_info->proxy_passwd); 407*7c478bd9Sstevel@tonic-gate proxy_info->proxy_passwd = NULL; 408*7c478bd9Sstevel@tonic-gate 409*7c478bd9Sstevel@tonic-gate if (proxy_info->default_nis_domain != NULL) 410*7c478bd9Sstevel@tonic-gate free(proxy_info->default_nis_domain); 411*7c478bd9Sstevel@tonic-gate proxy_info->default_nis_domain = NULL; 412*7c478bd9Sstevel@tonic-gate } 413*7c478bd9Sstevel@tonic-gate 414*7c478bd9Sstevel@tonic-gate /* 415*7c478bd9Sstevel@tonic-gate * FUNCTION: free_object_dn 416*7c478bd9Sstevel@tonic-gate * 417*7c478bd9Sstevel@tonic-gate * Frees __nis_object_dn_t 418*7c478bd9Sstevel@tonic-gate * 419*7c478bd9Sstevel@tonic-gate * INPUT: __nis_object_dn_t 420*7c478bd9Sstevel@tonic-gate */ 421*7c478bd9Sstevel@tonic-gate 422*7c478bd9Sstevel@tonic-gate void 423*7c478bd9Sstevel@tonic-gate free_object_dn(__nis_object_dn_t *obj_dn) 424*7c478bd9Sstevel@tonic-gate { 425*7c478bd9Sstevel@tonic-gate __nis_object_dn_t *t; 426*7c478bd9Sstevel@tonic-gate int i; 427*7c478bd9Sstevel@tonic-gate 428*7c478bd9Sstevel@tonic-gate while (obj_dn != NULL) { 429*7c478bd9Sstevel@tonic-gate if (obj_dn->read.base != NULL) 430*7c478bd9Sstevel@tonic-gate free(obj_dn->read.base); 431*7c478bd9Sstevel@tonic-gate obj_dn->read.base = NULL; 432*7c478bd9Sstevel@tonic-gate if (obj_dn->read.attrs != NULL) 433*7c478bd9Sstevel@tonic-gate free(obj_dn->read.attrs); 434*7c478bd9Sstevel@tonic-gate obj_dn->read.attrs = NULL; 435*7c478bd9Sstevel@tonic-gate if (obj_dn->write.base != NULL) 436*7c478bd9Sstevel@tonic-gate free(obj_dn->write.base); 437*7c478bd9Sstevel@tonic-gate obj_dn->write.base = NULL; 438*7c478bd9Sstevel@tonic-gate if (obj_dn->write.attrs != NULL) 439*7c478bd9Sstevel@tonic-gate free(obj_dn->write.attrs); 440*7c478bd9Sstevel@tonic-gate obj_dn->write.attrs = NULL; 441*7c478bd9Sstevel@tonic-gate if (obj_dn->dbIdName != NULL) 442*7c478bd9Sstevel@tonic-gate free(obj_dn->dbIdName); 443*7c478bd9Sstevel@tonic-gate obj_dn->dbIdName = NULL; 444*7c478bd9Sstevel@tonic-gate for (i = 0; i < obj_dn->numDbIds; i++) 445*7c478bd9Sstevel@tonic-gate free_mapping_rule(obj_dn->dbId[i]); 446*7c478bd9Sstevel@tonic-gate obj_dn->numDbIds = 0; 447*7c478bd9Sstevel@tonic-gate 448*7c478bd9Sstevel@tonic-gate if (obj_dn->dbId != NULL) 449*7c478bd9Sstevel@tonic-gate free(obj_dn->dbId); 450*7c478bd9Sstevel@tonic-gate obj_dn->dbId = NULL; 451*7c478bd9Sstevel@tonic-gate 452*7c478bd9Sstevel@tonic-gate t = obj_dn; 453*7c478bd9Sstevel@tonic-gate obj_dn = obj_dn->next; 454*7c478bd9Sstevel@tonic-gate free(t); 455*7c478bd9Sstevel@tonic-gate } 456*7c478bd9Sstevel@tonic-gate } 457*7c478bd9Sstevel@tonic-gate 458*7c478bd9Sstevel@tonic-gate /* 459*7c478bd9Sstevel@tonic-gate * FUNCTION: free_index 460*7c478bd9Sstevel@tonic-gate * 461*7c478bd9Sstevel@tonic-gate * Frees __nis_index_t 462*7c478bd9Sstevel@tonic-gate * 463*7c478bd9Sstevel@tonic-gate * INPUT: __nis_index_t 464*7c478bd9Sstevel@tonic-gate */ 465*7c478bd9Sstevel@tonic-gate 466*7c478bd9Sstevel@tonic-gate void 467*7c478bd9Sstevel@tonic-gate free_index(__nis_index_t *index) 468*7c478bd9Sstevel@tonic-gate { 469*7c478bd9Sstevel@tonic-gate int i; 470*7c478bd9Sstevel@tonic-gate for (i = 0; i < index->numIndexes; i++) { 471*7c478bd9Sstevel@tonic-gate free(index->name[i]); 472*7c478bd9Sstevel@tonic-gate free_mapping_format(index->value[i]); 473*7c478bd9Sstevel@tonic-gate } 474*7c478bd9Sstevel@tonic-gate index->numIndexes = 0; 475*7c478bd9Sstevel@tonic-gate if (index->name != NULL) 476*7c478bd9Sstevel@tonic-gate free(index->name); 477*7c478bd9Sstevel@tonic-gate index->name = NULL; 478*7c478bd9Sstevel@tonic-gate if (index->value != NULL) 479*7c478bd9Sstevel@tonic-gate free(index->value); 480*7c478bd9Sstevel@tonic-gate index->value = NULL; 481*7c478bd9Sstevel@tonic-gate } 482*7c478bd9Sstevel@tonic-gate 483*7c478bd9Sstevel@tonic-gate /* 484*7c478bd9Sstevel@tonic-gate * FUNCTION: free_mapping_item 485*7c478bd9Sstevel@tonic-gate * 486*7c478bd9Sstevel@tonic-gate * Frees __nis_mapping_item_t 487*7c478bd9Sstevel@tonic-gate * 488*7c478bd9Sstevel@tonic-gate * INPUT: __nis_mapping_item_t 489*7c478bd9Sstevel@tonic-gate */ 490*7c478bd9Sstevel@tonic-gate 491*7c478bd9Sstevel@tonic-gate void 492*7c478bd9Sstevel@tonic-gate free_mapping_item(__nis_mapping_item_t *item) 493*7c478bd9Sstevel@tonic-gate { 494*7c478bd9Sstevel@tonic-gate if (item == NULL) 495*7c478bd9Sstevel@tonic-gate return; 496*7c478bd9Sstevel@tonic-gate 497*7c478bd9Sstevel@tonic-gate if (item->name != NULL) 498*7c478bd9Sstevel@tonic-gate free(item->name); 499*7c478bd9Sstevel@tonic-gate item->name = NULL; 500*7c478bd9Sstevel@tonic-gate if (item->type == mit_nisplus) { 501*7c478bd9Sstevel@tonic-gate free_index(&item->searchSpec.obj.index); 502*7c478bd9Sstevel@tonic-gate if (item->searchSpec.obj.name != NULL) 503*7c478bd9Sstevel@tonic-gate free(item->searchSpec.obj.name); 504*7c478bd9Sstevel@tonic-gate item->searchSpec.obj.name = NULL; 505*7c478bd9Sstevel@tonic-gate } else if (item->type == mit_ldap) { 506*7c478bd9Sstevel@tonic-gate if (item->searchSpec.triple.base != NULL) 507*7c478bd9Sstevel@tonic-gate free(item->searchSpec.triple.base); 508*7c478bd9Sstevel@tonic-gate item->searchSpec.triple.base = NULL; 509*7c478bd9Sstevel@tonic-gate if (item->searchSpec.triple.attrs != NULL) 510*7c478bd9Sstevel@tonic-gate free(item->searchSpec.triple.attrs); 511*7c478bd9Sstevel@tonic-gate item->searchSpec.triple.attrs = NULL; 512*7c478bd9Sstevel@tonic-gate if (item->searchSpec.triple.element != NULL) { 513*7c478bd9Sstevel@tonic-gate free_mapping_element( 514*7c478bd9Sstevel@tonic-gate item->searchSpec.triple.element); 515*7c478bd9Sstevel@tonic-gate free(item->searchSpec.triple.element); 516*7c478bd9Sstevel@tonic-gate } 517*7c478bd9Sstevel@tonic-gate item->searchSpec.triple.element = NULL; 518*7c478bd9Sstevel@tonic-gate } 519*7c478bd9Sstevel@tonic-gate if (item->exItem != NULL) { 520*7c478bd9Sstevel@tonic-gate free_mapping_item(item->exItem); 521*7c478bd9Sstevel@tonic-gate free(item->exItem); 522*7c478bd9Sstevel@tonic-gate item->exItem = 0; 523*7c478bd9Sstevel@tonic-gate } 524*7c478bd9Sstevel@tonic-gate } 525*7c478bd9Sstevel@tonic-gate 526*7c478bd9Sstevel@tonic-gate /* 527*7c478bd9Sstevel@tonic-gate * FUNCTION: free_mapping_format 528*7c478bd9Sstevel@tonic-gate * 529*7c478bd9Sstevel@tonic-gate * Frees __nis_mapping_format_t 530*7c478bd9Sstevel@tonic-gate * 531*7c478bd9Sstevel@tonic-gate * INPUT: __nis_mapping_format_t 532*7c478bd9Sstevel@tonic-gate */ 533*7c478bd9Sstevel@tonic-gate 534*7c478bd9Sstevel@tonic-gate void 535*7c478bd9Sstevel@tonic-gate free_mapping_format(__nis_mapping_format_t *fmt) 536*7c478bd9Sstevel@tonic-gate { 537*7c478bd9Sstevel@tonic-gate __nis_mapping_format_t *f = fmt; 538*7c478bd9Sstevel@tonic-gate 539*7c478bd9Sstevel@tonic-gate while (fmt->type != mmt_end) { 540*7c478bd9Sstevel@tonic-gate switch (fmt->type) { 541*7c478bd9Sstevel@tonic-gate case mmt_item: 542*7c478bd9Sstevel@tonic-gate break; 543*7c478bd9Sstevel@tonic-gate case mmt_string: 544*7c478bd9Sstevel@tonic-gate if (fmt->match.string != NULL) 545*7c478bd9Sstevel@tonic-gate free(fmt->match.string); 546*7c478bd9Sstevel@tonic-gate fmt->match.string = NULL; 547*7c478bd9Sstevel@tonic-gate break; 548*7c478bd9Sstevel@tonic-gate case mmt_single: 549*7c478bd9Sstevel@tonic-gate if (fmt->match.single.lo != NULL) 550*7c478bd9Sstevel@tonic-gate free(fmt->match.single.lo); 551*7c478bd9Sstevel@tonic-gate fmt->match.single.lo = NULL; 552*7c478bd9Sstevel@tonic-gate if (fmt->match.single.hi != NULL) 553*7c478bd9Sstevel@tonic-gate free(fmt->match.single.hi); 554*7c478bd9Sstevel@tonic-gate fmt->match.single.hi = NULL; 555*7c478bd9Sstevel@tonic-gate break; 556*7c478bd9Sstevel@tonic-gate case mmt_limit: 557*7c478bd9Sstevel@tonic-gate break; 558*7c478bd9Sstevel@tonic-gate case mmt_any: 559*7c478bd9Sstevel@tonic-gate break; 560*7c478bd9Sstevel@tonic-gate case mmt_berstring: 561*7c478bd9Sstevel@tonic-gate case mmt_berstring_null: 562*7c478bd9Sstevel@tonic-gate if (fmt->match.berString != NULL) 563*7c478bd9Sstevel@tonic-gate free(fmt->match.berString); 564*7c478bd9Sstevel@tonic-gate fmt->match.berString = NULL; 565*7c478bd9Sstevel@tonic-gate break; 566*7c478bd9Sstevel@tonic-gate case mmt_begin: 567*7c478bd9Sstevel@tonic-gate break; 568*7c478bd9Sstevel@tonic-gate case mmt_end: 569*7c478bd9Sstevel@tonic-gate break; 570*7c478bd9Sstevel@tonic-gate } 571*7c478bd9Sstevel@tonic-gate fmt++; 572*7c478bd9Sstevel@tonic-gate } 573*7c478bd9Sstevel@tonic-gate free(f); 574*7c478bd9Sstevel@tonic-gate } 575*7c478bd9Sstevel@tonic-gate 576*7c478bd9Sstevel@tonic-gate /* 577*7c478bd9Sstevel@tonic-gate * FUNCTION: free_mapping_sub_element 578*7c478bd9Sstevel@tonic-gate * 579*7c478bd9Sstevel@tonic-gate * Frees __nis_mapping_sub_element_t 580*7c478bd9Sstevel@tonic-gate * 581*7c478bd9Sstevel@tonic-gate * INPUT: __nis_mapping_sub_element_t 582*7c478bd9Sstevel@tonic-gate */ 583*7c478bd9Sstevel@tonic-gate 584*7c478bd9Sstevel@tonic-gate void 585*7c478bd9Sstevel@tonic-gate free_mapping_sub_element(__nis_mapping_sub_element_t *sub) 586*7c478bd9Sstevel@tonic-gate { 587*7c478bd9Sstevel@tonic-gate int i; 588*7c478bd9Sstevel@tonic-gate 589*7c478bd9Sstevel@tonic-gate switch (sub->type) { 590*7c478bd9Sstevel@tonic-gate case me_item: 591*7c478bd9Sstevel@tonic-gate free_mapping_item(&sub->element.item); 592*7c478bd9Sstevel@tonic-gate break; 593*7c478bd9Sstevel@tonic-gate case me_print: 594*7c478bd9Sstevel@tonic-gate if (sub->element.print.fmt != NULL) 595*7c478bd9Sstevel@tonic-gate free_mapping_format(sub->element.print.fmt); 596*7c478bd9Sstevel@tonic-gate sub->element.print.fmt = NULL; 597*7c478bd9Sstevel@tonic-gate for (i = 0; i < sub->element.print.numItems; i++) 598*7c478bd9Sstevel@tonic-gate free_mapping_item(&sub->element.print.item[i]); 599*7c478bd9Sstevel@tonic-gate sub->element.print.numItems = 0; 600*7c478bd9Sstevel@tonic-gate if (sub->element.print.item != NULL) 601*7c478bd9Sstevel@tonic-gate free(sub->element.print.item); 602*7c478bd9Sstevel@tonic-gate sub->element.print.item = NULL; 603*7c478bd9Sstevel@tonic-gate break; 604*7c478bd9Sstevel@tonic-gate case me_split: 605*7c478bd9Sstevel@tonic-gate free_mapping_item(&sub->element.split.item); 606*7c478bd9Sstevel@tonic-gate break; 607*7c478bd9Sstevel@tonic-gate case me_extract: 608*7c478bd9Sstevel@tonic-gate if (sub->element.extract.fmt != NULL) 609*7c478bd9Sstevel@tonic-gate free_mapping_format(sub->element.extract.fmt); 610*7c478bd9Sstevel@tonic-gate sub->element.extract.fmt = NULL; 611*7c478bd9Sstevel@tonic-gate free_mapping_item(&sub->element.extract.item); 612*7c478bd9Sstevel@tonic-gate break; 613*7c478bd9Sstevel@tonic-gate } 614*7c478bd9Sstevel@tonic-gate } 615*7c478bd9Sstevel@tonic-gate 616*7c478bd9Sstevel@tonic-gate /* 617*7c478bd9Sstevel@tonic-gate * FUNCTION: read_line 618*7c478bd9Sstevel@tonic-gate * 619*7c478bd9Sstevel@tonic-gate * Gets next line in buffer - using '\' at end of line 620*7c478bd9Sstevel@tonic-gate * to indicate continuation. Lines beginning with # are 621*7c478bd9Sstevel@tonic-gate * ignored. start_line_num and start_line_num are 622*7c478bd9Sstevel@tonic-gate * maintained to track the line number currently being 623*7c478bd9Sstevel@tonic-gate * parsed. 624*7c478bd9Sstevel@tonic-gate * 625*7c478bd9Sstevel@tonic-gate * RETURN VALUE: The number of characters read. 0 for 626*7c478bd9Sstevel@tonic-gate * eof, -1 for error 627*7c478bd9Sstevel@tonic-gate * 628*7c478bd9Sstevel@tonic-gate * INPUT: file descriptor, buffer, and buffer size 629*7c478bd9Sstevel@tonic-gate */ 630*7c478bd9Sstevel@tonic-gate 631*7c478bd9Sstevel@tonic-gate int 632*7c478bd9Sstevel@tonic-gate read_line(int fd, char *buffer, int buflen) 633*7c478bd9Sstevel@tonic-gate { 634*7c478bd9Sstevel@tonic-gate int linelen; 635*7c478bd9Sstevel@tonic-gate int rc; 636*7c478bd9Sstevel@tonic-gate char c; 637*7c478bd9Sstevel@tonic-gate bool_t skip_line = FALSE; 638*7c478bd9Sstevel@tonic-gate bool_t begin_line = TRUE; 639*7c478bd9Sstevel@tonic-gate static bool_t prev_cr = FALSE; 640*7c478bd9Sstevel@tonic-gate 641*7c478bd9Sstevel@tonic-gate start_line_num = cur_line_num; 642*7c478bd9Sstevel@tonic-gate (void) memset(buffer, 0, buflen); 643*7c478bd9Sstevel@tonic-gate for (; p_error == no_parse_error; ) { 644*7c478bd9Sstevel@tonic-gate linelen = 0; 645*7c478bd9Sstevel@tonic-gate while (linelen < buflen) { 646*7c478bd9Sstevel@tonic-gate rc = read(fd, &c, 1); 647*7c478bd9Sstevel@tonic-gate if (1 == rc) { 648*7c478bd9Sstevel@tonic-gate if (c == '\n' || c == '\r') { 649*7c478bd9Sstevel@tonic-gate if (c == '\n') { 650*7c478bd9Sstevel@tonic-gate if (prev_cr) { 651*7c478bd9Sstevel@tonic-gate prev_cr = FALSE; 652*7c478bd9Sstevel@tonic-gate continue; 653*7c478bd9Sstevel@tonic-gate } else { 654*7c478bd9Sstevel@tonic-gate if (linelen == 0) 655*7c478bd9Sstevel@tonic-gate start_line_num = 656*7c478bd9Sstevel@tonic-gate cur_line_num; 657*7c478bd9Sstevel@tonic-gate else { 658*7c478bd9Sstevel@tonic-gate if ( 659*7c478bd9Sstevel@tonic-gate is_string_ok( 660*7c478bd9Sstevel@tonic-gate buffer, 661*7c478bd9Sstevel@tonic-gate linelen)) { 662*7c478bd9Sstevel@tonic-gate (void) memset( 663*7c478bd9Sstevel@tonic-gate buffer, 0, 664*7c478bd9Sstevel@tonic-gate linelen); 665*7c478bd9Sstevel@tonic-gate linelen = 0; 666*7c478bd9Sstevel@tonic-gate cur_line_num++; 667*7c478bd9Sstevel@tonic-gate begin_line = 668*7c478bd9Sstevel@tonic-gate TRUE; 669*7c478bd9Sstevel@tonic-gate continue; 670*7c478bd9Sstevel@tonic-gate } 671*7c478bd9Sstevel@tonic-gate } 672*7c478bd9Sstevel@tonic-gate cur_line_num++; 673*7c478bd9Sstevel@tonic-gate } 674*7c478bd9Sstevel@tonic-gate prev_cr = FALSE; 675*7c478bd9Sstevel@tonic-gate } else { 676*7c478bd9Sstevel@tonic-gate prev_cr = TRUE; 677*7c478bd9Sstevel@tonic-gate if (linelen == 0) 678*7c478bd9Sstevel@tonic-gate start_line_num = 679*7c478bd9Sstevel@tonic-gate cur_line_num; 680*7c478bd9Sstevel@tonic-gate cur_line_num++; 681*7c478bd9Sstevel@tonic-gate } 682*7c478bd9Sstevel@tonic-gate if (skip_line) { 683*7c478bd9Sstevel@tonic-gate skip_line = FALSE; 684*7c478bd9Sstevel@tonic-gate if (linelen == 0) 685*7c478bd9Sstevel@tonic-gate start_line_num = 686*7c478bd9Sstevel@tonic-gate cur_line_num; 687*7c478bd9Sstevel@tonic-gate } else if (linelen > 0 && 688*7c478bd9Sstevel@tonic-gate buffer[linelen - 1] 689*7c478bd9Sstevel@tonic-gate == ESCAPE_CHAR) { 690*7c478bd9Sstevel@tonic-gate --linelen; 691*7c478bd9Sstevel@tonic-gate } else if (linelen > 0) { 692*7c478bd9Sstevel@tonic-gate buffer[linelen] = '\0'; 693*7c478bd9Sstevel@tonic-gate return (linelen); 694*7c478bd9Sstevel@tonic-gate } 695*7c478bd9Sstevel@tonic-gate begin_line = TRUE; 696*7c478bd9Sstevel@tonic-gate } else { 697*7c478bd9Sstevel@tonic-gate if (begin_line) 698*7c478bd9Sstevel@tonic-gate skip_line = c == POUND_SIGN; 699*7c478bd9Sstevel@tonic-gate begin_line = FALSE; 700*7c478bd9Sstevel@tonic-gate if (!skip_line) 701*7c478bd9Sstevel@tonic-gate buffer[linelen++] = c; 702*7c478bd9Sstevel@tonic-gate } 703*7c478bd9Sstevel@tonic-gate } else { 704*7c478bd9Sstevel@tonic-gate if (linelen > 0 && 705*7c478bd9Sstevel@tonic-gate buffer[linelen - 1] == ESCAPE_CHAR) { 706*7c478bd9Sstevel@tonic-gate /* continuation on last line */ 707*7c478bd9Sstevel@tonic-gate p_error = parse_bad_continuation_error; 708*7c478bd9Sstevel@tonic-gate return (-1); 709*7c478bd9Sstevel@tonic-gate } else { 710*7c478bd9Sstevel@tonic-gate buffer[linelen] = '\0'; 711*7c478bd9Sstevel@tonic-gate return (linelen); 712*7c478bd9Sstevel@tonic-gate } 713*7c478bd9Sstevel@tonic-gate } 714*7c478bd9Sstevel@tonic-gate } 715*7c478bd9Sstevel@tonic-gate p_error = parse_line_too_long; 716*7c478bd9Sstevel@tonic-gate } 717*7c478bd9Sstevel@tonic-gate return (-1); 718*7c478bd9Sstevel@tonic-gate } 719*7c478bd9Sstevel@tonic-gate 720*7c478bd9Sstevel@tonic-gate /* 721*7c478bd9Sstevel@tonic-gate * FUNCTION: finish_parse 722*7c478bd9Sstevel@tonic-gate * 723*7c478bd9Sstevel@tonic-gate * Adds any elements not configured, fully qualifies 724*7c478bd9Sstevel@tonic-gate * names 725*7c478bd9Sstevel@tonic-gate * 726*7c478bd9Sstevel@tonic-gate * RETURN VALUE: 0 on success, -1 on failure 727*7c478bd9Sstevel@tonic-gate */ 728*7c478bd9Sstevel@tonic-gate 729*7c478bd9Sstevel@tonic-gate int 730*7c478bd9Sstevel@tonic-gate finish_parse( 731*7c478bd9Sstevel@tonic-gate __nis_ldap_proxy_info *proxy_info, 732*7c478bd9Sstevel@tonic-gate __nis_table_mapping_t **table_mapping) 733*7c478bd9Sstevel@tonic-gate { 734*7c478bd9Sstevel@tonic-gate __nis_table_mapping_t *t; 735*7c478bd9Sstevel@tonic-gate __nis_table_mapping_t *t1; 736*7c478bd9Sstevel@tonic-gate __nis_table_mapping_t *t2; 737*7c478bd9Sstevel@tonic-gate __nis_table_mapping_t *t_del = NULL; 738*7c478bd9Sstevel@tonic-gate int i; 739*7c478bd9Sstevel@tonic-gate int j; 740*7c478bd9Sstevel@tonic-gate int k; 741*7c478bd9Sstevel@tonic-gate __nis_object_dn_t *objectDN; 742*7c478bd9Sstevel@tonic-gate __nis_mapping_rlhs_t *lhs; 743*7c478bd9Sstevel@tonic-gate __nis_mapping_element_t *e; 744*7c478bd9Sstevel@tonic-gate char *s; 745*7c478bd9Sstevel@tonic-gate int errnum; 746*7c478bd9Sstevel@tonic-gate 747*7c478bd9Sstevel@tonic-gate /* set to default those values yet set */ 748*7c478bd9Sstevel@tonic-gate if (proxy_info->auth_method == 749*7c478bd9Sstevel@tonic-gate (auth_method_t)NO_VALUE_SET) { 750*7c478bd9Sstevel@tonic-gate p_error = parse_no_proxy_auth_error; 751*7c478bd9Sstevel@tonic-gate report_error(NULL, NULL); 752*7c478bd9Sstevel@tonic-gate return (-1); 753*7c478bd9Sstevel@tonic-gate } 754*7c478bd9Sstevel@tonic-gate 755*7c478bd9Sstevel@tonic-gate if (proxy_info->default_servers == NULL) { 756*7c478bd9Sstevel@tonic-gate p_error = parse_no_ldap_server_error; 757*7c478bd9Sstevel@tonic-gate report_error(NULL, NULL); 758*7c478bd9Sstevel@tonic-gate return (-1); 759*7c478bd9Sstevel@tonic-gate } 760*7c478bd9Sstevel@tonic-gate 761*7c478bd9Sstevel@tonic-gate if (proxy_info->tls_method == (tls_method_t)NO_VALUE_SET) 762*7c478bd9Sstevel@tonic-gate proxy_info->tls_method = no_tls; 763*7c478bd9Sstevel@tonic-gate else if (proxy_info->tls_method == ssl_tls && 764*7c478bd9Sstevel@tonic-gate (proxy_info->tls_cert_db == NULL || 765*7c478bd9Sstevel@tonic-gate *proxy_info->tls_cert_db == '\0')) { 766*7c478bd9Sstevel@tonic-gate p_error = parse_no_cert_db; 767*7c478bd9Sstevel@tonic-gate report_error(NULL, NULL); 768*7c478bd9Sstevel@tonic-gate return (-1); 769*7c478bd9Sstevel@tonic-gate } 770*7c478bd9Sstevel@tonic-gate 771*7c478bd9Sstevel@tonic-gate if (proxy_info->default_nis_domain == NULL) 772*7c478bd9Sstevel@tonic-gate proxy_info->default_nis_domain = 773*7c478bd9Sstevel@tonic-gate s_strdup(__nis_rpc_domain()); 774*7c478bd9Sstevel@tonic-gate else if (*proxy_info->default_nis_domain == '\0') { 775*7c478bd9Sstevel@tonic-gate free(proxy_info->default_nis_domain); 776*7c478bd9Sstevel@tonic-gate proxy_info->default_nis_domain = 777*7c478bd9Sstevel@tonic-gate s_strdup(__nis_rpc_domain()); 778*7c478bd9Sstevel@tonic-gate } 779*7c478bd9Sstevel@tonic-gate if (proxy_info->default_nis_domain != NULL) 780*7c478bd9Sstevel@tonic-gate append_dot(&proxy_info->default_nis_domain); 781*7c478bd9Sstevel@tonic-gate 782*7c478bd9Sstevel@tonic-gate if (proxy_info->tls_method == ssl_tls) { 783*7c478bd9Sstevel@tonic-gate if ((errnum = ldapssl_client_init( 784*7c478bd9Sstevel@tonic-gate proxy_info->tls_cert_db, NULL)) < 0) { 785*7c478bd9Sstevel@tonic-gate p_error = parse_ldapssl_client_init_error; 786*7c478bd9Sstevel@tonic-gate report_error(ldapssl_err2string(errnum), NULL); 787*7c478bd9Sstevel@tonic-gate return (-1); 788*7c478bd9Sstevel@tonic-gate } 789*7c478bd9Sstevel@tonic-gate } 790*7c478bd9Sstevel@tonic-gate 791*7c478bd9Sstevel@tonic-gate if (proxy_info->default_search_base == NULL) 792*7c478bd9Sstevel@tonic-gate proxy_info->default_search_base = 793*7c478bd9Sstevel@tonic-gate get_default_ldap_base(proxy_info->default_nis_domain); 794*7c478bd9Sstevel@tonic-gate 795*7c478bd9Sstevel@tonic-gate /* convert a relative dn to a fullly qualified dn */ 796*7c478bd9Sstevel@tonic-gate (void) make_full_dn(&proxy_info->proxy_dn, 797*7c478bd9Sstevel@tonic-gate proxy_info->default_search_base); 798*7c478bd9Sstevel@tonic-gate 799*7c478bd9Sstevel@tonic-gate if (p_error != no_parse_error) { 800*7c478bd9Sstevel@tonic-gate report_error(NULL, NULL); 801*7c478bd9Sstevel@tonic-gate return (-1); 802*7c478bd9Sstevel@tonic-gate } 803*7c478bd9Sstevel@tonic-gate 804*7c478bd9Sstevel@tonic-gate /* 805*7c478bd9Sstevel@tonic-gate * Create a list of potential delete mappings 806*7c478bd9Sstevel@tonic-gate * those have NULL objectDNs, but badly also rules 807*7c478bd9Sstevel@tonic-gate * that are missing object dn's will be included. 808*7c478bd9Sstevel@tonic-gate * We will use the ttl field to determine if the 809*7c478bd9Sstevel@tonic-gate * delete rule is actually used 810*7c478bd9Sstevel@tonic-gate */ 811*7c478bd9Sstevel@tonic-gate t2 = NULL; 812*7c478bd9Sstevel@tonic-gate for (t = *table_mapping; t != NULL; t = t1) { 813*7c478bd9Sstevel@tonic-gate t1 = t->next; 814*7c478bd9Sstevel@tonic-gate if (t->objectDN == NULL) { 815*7c478bd9Sstevel@tonic-gate if (t2 == NULL) 816*7c478bd9Sstevel@tonic-gate *table_mapping = t1; 817*7c478bd9Sstevel@tonic-gate else 818*7c478bd9Sstevel@tonic-gate t2->next = t1; 819*7c478bd9Sstevel@tonic-gate t->next = t_del; 820*7c478bd9Sstevel@tonic-gate t_del = t; 821*7c478bd9Sstevel@tonic-gate t->ttl = 0; 822*7c478bd9Sstevel@tonic-gate } else 823*7c478bd9Sstevel@tonic-gate t2 = t; 824*7c478bd9Sstevel@tonic-gate } 825*7c478bd9Sstevel@tonic-gate 826*7c478bd9Sstevel@tonic-gate for (t = *table_mapping; t != NULL; t = t->next) { 827*7c478bd9Sstevel@tonic-gate objectDN = t->objectDN; 828*7c478bd9Sstevel@tonic-gate while (objectDN != NULL) { 829*7c478bd9Sstevel@tonic-gate if (objectDN->dbIdName != NULL) { 830*7c478bd9Sstevel@tonic-gate s = objectDN->dbIdName; 831*7c478bd9Sstevel@tonic-gate t1 = find_table_mapping(s, strlen(s), t_del); 832*7c478bd9Sstevel@tonic-gate if (t1 == NULL) { 833*7c478bd9Sstevel@tonic-gate p_error = parse_no_db_del_mapping_rule; 834*7c478bd9Sstevel@tonic-gate report_error2(objectDN->dbIdName, t->dbId); 835*7c478bd9Sstevel@tonic-gate return (-1); 836*7c478bd9Sstevel@tonic-gate } else if (t1->objName != NULL || 837*7c478bd9Sstevel@tonic-gate t1->numRulesToLDAP == 0 || 838*7c478bd9Sstevel@tonic-gate t1->numRulesFromLDAP != 0) { 839*7c478bd9Sstevel@tonic-gate p_error = parse_invalid_db_del_mapping_rule; 840*7c478bd9Sstevel@tonic-gate report_error(t1->dbId, NULL); 841*7c478bd9Sstevel@tonic-gate return (-1); 842*7c478bd9Sstevel@tonic-gate } 843*7c478bd9Sstevel@tonic-gate objectDN->dbId = 844*7c478bd9Sstevel@tonic-gate dup_mapping_rules(t1->ruleToLDAP, 845*7c478bd9Sstevel@tonic-gate t1->numRulesToLDAP); 846*7c478bd9Sstevel@tonic-gate if (objectDN->dbId == NULL) { 847*7c478bd9Sstevel@tonic-gate break; 848*7c478bd9Sstevel@tonic-gate } 849*7c478bd9Sstevel@tonic-gate objectDN->numDbIds = t1->numRulesToLDAP; 850*7c478bd9Sstevel@tonic-gate t1->ttl++; 851*7c478bd9Sstevel@tonic-gate } 852*7c478bd9Sstevel@tonic-gate objectDN = objectDN->next; 853*7c478bd9Sstevel@tonic-gate } 854*7c478bd9Sstevel@tonic-gate } 855*7c478bd9Sstevel@tonic-gate 856*7c478bd9Sstevel@tonic-gate for (t = t_del; t != NULL; t = t1) { 857*7c478bd9Sstevel@tonic-gate t1 = t->next; 858*7c478bd9Sstevel@tonic-gate if (t->ttl == 0) { 859*7c478bd9Sstevel@tonic-gate p_error = parse_no_object_dn; 860*7c478bd9Sstevel@tonic-gate report_error(t->dbId, NULL); 861*7c478bd9Sstevel@tonic-gate } 862*7c478bd9Sstevel@tonic-gate free_table_mapping(t); 863*7c478bd9Sstevel@tonic-gate } 864*7c478bd9Sstevel@tonic-gate 865*7c478bd9Sstevel@tonic-gate if (p_error != no_parse_error) 866*7c478bd9Sstevel@tonic-gate return (-1); 867*7c478bd9Sstevel@tonic-gate 868*7c478bd9Sstevel@tonic-gate /* set to default those table mapping values yet set */ 869*7c478bd9Sstevel@tonic-gate for (t = *table_mapping; t != NULL; t = t->next) { 870*7c478bd9Sstevel@tonic-gate if (t->objName == 0) { 871*7c478bd9Sstevel@tonic-gate p_error = parse_no_object_dn; 872*7c478bd9Sstevel@tonic-gate report_error(t->dbId, NULL); 873*7c478bd9Sstevel@tonic-gate return (-1); 874*7c478bd9Sstevel@tonic-gate } 875*7c478bd9Sstevel@tonic-gate if (!yp2ldap) { 876*7c478bd9Sstevel@tonic-gate if (!add_domain(&t->objName, 877*7c478bd9Sstevel@tonic-gate proxy_info->default_nis_domain)) { 878*7c478bd9Sstevel@tonic-gate report_error(NULL, NULL); 879*7c478bd9Sstevel@tonic-gate return (-1); 880*7c478bd9Sstevel@tonic-gate } 881*7c478bd9Sstevel@tonic-gate } 882*7c478bd9Sstevel@tonic-gate if (t->initTtlHi == (time_t)NO_VALUE_SET) 883*7c478bd9Sstevel@tonic-gate t->initTtlHi = DEFAULT_TTL_HIGH; 884*7c478bd9Sstevel@tonic-gate if (t->initTtlLo == (time_t)NO_VALUE_SET) 885*7c478bd9Sstevel@tonic-gate t->initTtlLo = DEFAULT_TTL_LOW; 886*7c478bd9Sstevel@tonic-gate if (t->ttl == (time_t)NO_VALUE_SET) 887*7c478bd9Sstevel@tonic-gate t->ttl = DEFAULT_TTL; 888*7c478bd9Sstevel@tonic-gate objectDN = t->objectDN; 889*7c478bd9Sstevel@tonic-gate 890*7c478bd9Sstevel@tonic-gate /* fixup relative dn's */ 891*7c478bd9Sstevel@tonic-gate while (objectDN != NULL) { 892*7c478bd9Sstevel@tonic-gate if (!yp2ldap) { 893*7c478bd9Sstevel@tonic-gate if (!make_full_dn(&objectDN->read.base, 894*7c478bd9Sstevel@tonic-gate proxy_info->default_search_base)) 895*7c478bd9Sstevel@tonic-gate break; 896*7c478bd9Sstevel@tonic-gate } 897*7c478bd9Sstevel@tonic-gate if (objectDN->write.scope != LDAP_SCOPE_UNKNOWN) { 898*7c478bd9Sstevel@tonic-gate if (objectDN->write.base != NULL && 899*7c478bd9Sstevel@tonic-gate !make_full_dn(&objectDN->write.base, 900*7c478bd9Sstevel@tonic-gate proxy_info->default_search_base)) 901*7c478bd9Sstevel@tonic-gate break; 902*7c478bd9Sstevel@tonic-gate if (objectDN->write.base == NULL) { 903*7c478bd9Sstevel@tonic-gate objectDN->write.base = 904*7c478bd9Sstevel@tonic-gate s_strdup(objectDN->read.base); 905*7c478bd9Sstevel@tonic-gate if (objectDN->write.base == NULL) 906*7c478bd9Sstevel@tonic-gate break; 907*7c478bd9Sstevel@tonic-gate } 908*7c478bd9Sstevel@tonic-gate } 909*7c478bd9Sstevel@tonic-gate objectDN = objectDN->next; 910*7c478bd9Sstevel@tonic-gate } 911*7c478bd9Sstevel@tonic-gate 912*7c478bd9Sstevel@tonic-gate if (p_error != no_parse_error) { 913*7c478bd9Sstevel@tonic-gate report_error(NULL, NULL); 914*7c478bd9Sstevel@tonic-gate return (-1); 915*7c478bd9Sstevel@tonic-gate } 916*7c478bd9Sstevel@tonic-gate 917*7c478bd9Sstevel@tonic-gate /* Check for ruleToLDAP with no rhs */ 918*7c478bd9Sstevel@tonic-gate for (i = 0; i < t->numRulesToLDAP; i++) { 919*7c478bd9Sstevel@tonic-gate if (t->ruleToLDAP[i]->rhs.numElements == 0) { 920*7c478bd9Sstevel@tonic-gate p_error = parse_unexpected_data_end_rule; 921*7c478bd9Sstevel@tonic-gate report_error(t->dbId, NULL); 922*7c478bd9Sstevel@tonic-gate return (-1); 923*7c478bd9Sstevel@tonic-gate } 924*7c478bd9Sstevel@tonic-gate } 925*7c478bd9Sstevel@tonic-gate 926*7c478bd9Sstevel@tonic-gate /* populate cols field */ 927*7c478bd9Sstevel@tonic-gate if (!yp2ldap) { 928*7c478bd9Sstevel@tonic-gate for (i = 0; i < t->numRulesFromLDAP; i++) { 929*7c478bd9Sstevel@tonic-gate lhs = &t->ruleFromLDAP[i]->lhs; 930*7c478bd9Sstevel@tonic-gate for (j = 0; j < lhs->numElements; j++) { 931*7c478bd9Sstevel@tonic-gate e = &lhs->element[j]; 932*7c478bd9Sstevel@tonic-gate switch (e->type) { 933*7c478bd9Sstevel@tonic-gate case me_item: 934*7c478bd9Sstevel@tonic-gate if (!add_column(t, 935*7c478bd9Sstevel@tonic-gate e->element.item.name)) { 936*7c478bd9Sstevel@tonic-gate report_error( 937*7c478bd9Sstevel@tonic-gate NULL, NULL); 938*7c478bd9Sstevel@tonic-gate return (-1); 939*7c478bd9Sstevel@tonic-gate } 940*7c478bd9Sstevel@tonic-gate break; 941*7c478bd9Sstevel@tonic-gate case me_match: 942*7c478bd9Sstevel@tonic-gate for (k = 0; 943*7c478bd9Sstevel@tonic-gate k < e->element.match.numItems; 944*7c478bd9Sstevel@tonic-gate k++) 945*7c478bd9Sstevel@tonic-gate if (!add_column(t, 946*7c478bd9Sstevel@tonic-gate e->element.match.item[k].name)) { 947*7c478bd9Sstevel@tonic-gate report_error( 948*7c478bd9Sstevel@tonic-gate NULL, NULL); 949*7c478bd9Sstevel@tonic-gate return (-1); 950*7c478bd9Sstevel@tonic-gate } 951*7c478bd9Sstevel@tonic-gate break; 952*7c478bd9Sstevel@tonic-gate } 953*7c478bd9Sstevel@tonic-gate } 954*7c478bd9Sstevel@tonic-gate } 955*7c478bd9Sstevel@tonic-gate } 956*7c478bd9Sstevel@tonic-gate } 957*7c478bd9Sstevel@tonic-gate return (0); 958*7c478bd9Sstevel@tonic-gate } 959*7c478bd9Sstevel@tonic-gate 960*7c478bd9Sstevel@tonic-gate /* 961*7c478bd9Sstevel@tonic-gate * FUNCTION: set_default_values 962*7c478bd9Sstevel@tonic-gate * 963*7c478bd9Sstevel@tonic-gate * Sets unconfigured values to their default value 964*7c478bd9Sstevel@tonic-gate */ 965*7c478bd9Sstevel@tonic-gate 966*7c478bd9Sstevel@tonic-gate void 967*7c478bd9Sstevel@tonic-gate set_default_values(__nis_ldap_proxy_info *proxy_info, 968*7c478bd9Sstevel@tonic-gate __nis_config_t *config_info, __nisdb_table_mapping_t *table_info) 969*7c478bd9Sstevel@tonic-gate { 970*7c478bd9Sstevel@tonic-gate if (proxy_info->bind_timeout.tv_sec == (time_t)NO_VALUE_SET) 971*7c478bd9Sstevel@tonic-gate proxy_info->bind_timeout.tv_sec = DEFAULT_BIND_TIMEOUT; 972*7c478bd9Sstevel@tonic-gate if (proxy_info->search_timeout.tv_sec == (time_t)NO_VALUE_SET) 973*7c478bd9Sstevel@tonic-gate proxy_info->search_timeout.tv_sec = 974*7c478bd9Sstevel@tonic-gate (yp2ldap)?DEFAULT_YP_SEARCH_TIMEOUT: 975*7c478bd9Sstevel@tonic-gate DEFAULT_SEARCH_TIMEOUT; 976*7c478bd9Sstevel@tonic-gate if (proxy_info->modify_timeout.tv_sec == (time_t)NO_VALUE_SET) 977*7c478bd9Sstevel@tonic-gate proxy_info->modify_timeout.tv_sec = DEFAULT_MODIFY_TIMEOUT; 978*7c478bd9Sstevel@tonic-gate if (proxy_info->add_timeout.tv_sec == (time_t)NO_VALUE_SET) 979*7c478bd9Sstevel@tonic-gate proxy_info->add_timeout.tv_sec = DEFAULT_ADD_TIMEOUT; 980*7c478bd9Sstevel@tonic-gate if (proxy_info->delete_timeout.tv_sec == (time_t)NO_VALUE_SET) 981*7c478bd9Sstevel@tonic-gate proxy_info->delete_timeout.tv_sec = DEFAULT_DELETE_TIMEOUT; 982*7c478bd9Sstevel@tonic-gate 983*7c478bd9Sstevel@tonic-gate if (proxy_info->search_time_limit == (int)NO_VALUE_SET) 984*7c478bd9Sstevel@tonic-gate proxy_info->search_time_limit = DEFAULT_SEARCH_TIME_LIMIT; 985*7c478bd9Sstevel@tonic-gate if (proxy_info->search_size_limit == (int)NO_VALUE_SET) 986*7c478bd9Sstevel@tonic-gate proxy_info->search_size_limit = DEFAULT_SEARCH_SIZE_LIMIT; 987*7c478bd9Sstevel@tonic-gate 988*7c478bd9Sstevel@tonic-gate if (proxy_info->follow_referral == (follow_referral_t)NO_VALUE_SET) 989*7c478bd9Sstevel@tonic-gate proxy_info->follow_referral = no_follow; 990*7c478bd9Sstevel@tonic-gate 991*7c478bd9Sstevel@tonic-gate switch (config_info->initialUpdate) { 992*7c478bd9Sstevel@tonic-gate case (__nis_initial_update_t)NO_VALUE_SET: 993*7c478bd9Sstevel@tonic-gate case (__nis_initial_update_t)INITIAL_UPDATE_NO_ACTION: 994*7c478bd9Sstevel@tonic-gate case (__nis_initial_update_t)NO_INITIAL_UPDATE_NO_ACTION: 995*7c478bd9Sstevel@tonic-gate config_info->initialUpdate = ini_none; 996*7c478bd9Sstevel@tonic-gate break; 997*7c478bd9Sstevel@tonic-gate case (__nis_initial_update_t)FROM_NO_INITIAL_UPDATE: 998*7c478bd9Sstevel@tonic-gate config_info->initialUpdate = from_ldap; 999*7c478bd9Sstevel@tonic-gate break; 1000*7c478bd9Sstevel@tonic-gate case (__nis_initial_update_t)TO_NO_INITIAL_UPDATE: 1001*7c478bd9Sstevel@tonic-gate config_info->initialUpdate = to_ldap; 1002*7c478bd9Sstevel@tonic-gate break; 1003*7c478bd9Sstevel@tonic-gate } 1004*7c478bd9Sstevel@tonic-gate if (config_info->threadCreationError == 1005*7c478bd9Sstevel@tonic-gate (__nis_thread_creation_error_t)NO_VALUE_SET) 1006*7c478bd9Sstevel@tonic-gate config_info->threadCreationError = pass_error; 1007*7c478bd9Sstevel@tonic-gate if (config_info->threadCreationErrorTimeout.attempts == NO_VALUE_SET) 1008*7c478bd9Sstevel@tonic-gate config_info->threadCreationErrorTimeout.attempts = 1009*7c478bd9Sstevel@tonic-gate DEFAULT_THREAD_ERROR_ATTEMPTS; 1010*7c478bd9Sstevel@tonic-gate if (config_info->threadCreationErrorTimeout.timeout == 1011*7c478bd9Sstevel@tonic-gate (time_t)NO_VALUE_SET) 1012*7c478bd9Sstevel@tonic-gate config_info->threadCreationErrorTimeout.timeout = 1013*7c478bd9Sstevel@tonic-gate DEFAULT_THREAD_ERROR_TIME_OUT; 1014*7c478bd9Sstevel@tonic-gate if (config_info->dumpError == 1015*7c478bd9Sstevel@tonic-gate (__nis_dump_error_t)NO_VALUE_SET) 1016*7c478bd9Sstevel@tonic-gate config_info->dumpError = de_retry; 1017*7c478bd9Sstevel@tonic-gate if (config_info->dumpErrorTimeout.attempts == NO_VALUE_SET) 1018*7c478bd9Sstevel@tonic-gate config_info->dumpErrorTimeout.attempts = 1019*7c478bd9Sstevel@tonic-gate DEFAULT_DUMP_ERROR_ATTEMPTS; 1020*7c478bd9Sstevel@tonic-gate if (config_info->dumpErrorTimeout.timeout == (time_t)NO_VALUE_SET) 1021*7c478bd9Sstevel@tonic-gate config_info->dumpErrorTimeout.timeout = 1022*7c478bd9Sstevel@tonic-gate DEFAULT_DUMP_ERROR_TIME_OUT; 1023*7c478bd9Sstevel@tonic-gate if (config_info->resyncService == 1024*7c478bd9Sstevel@tonic-gate (__nis_resync_service_t)NO_VALUE_SET) 1025*7c478bd9Sstevel@tonic-gate config_info->resyncService = from_copy; 1026*7c478bd9Sstevel@tonic-gate if (config_info->updateBatching == 1027*7c478bd9Sstevel@tonic-gate (__nis_update_batching_t)NO_VALUE_SET) 1028*7c478bd9Sstevel@tonic-gate config_info->updateBatching = accumulate; 1029*7c478bd9Sstevel@tonic-gate if (config_info->updateBatchingTimeout.timeout == (time_t)NO_VALUE_SET) 1030*7c478bd9Sstevel@tonic-gate config_info->updateBatchingTimeout.timeout = 1031*7c478bd9Sstevel@tonic-gate DEFAULT_BATCHING_TIME_OUT; 1032*7c478bd9Sstevel@tonic-gate if (config_info->numberOfServiceThreads == (int)NO_VALUE_SET) 1033*7c478bd9Sstevel@tonic-gate config_info->numberOfServiceThreads = 1034*7c478bd9Sstevel@tonic-gate DEFAULT_NUMBER_OF_THREADS; 1035*7c478bd9Sstevel@tonic-gate if (config_info->emulate_yp == (int)NO_VALUE_SET) 1036*7c478bd9Sstevel@tonic-gate config_info->emulate_yp = 1037*7c478bd9Sstevel@tonic-gate DEFAULT_YP_EMULATION; 1038*7c478bd9Sstevel@tonic-gate if (config_info->maxRPCRecordSize == (int)NO_VALUE_SET) 1039*7c478bd9Sstevel@tonic-gate config_info->maxRPCRecordSize = RPC_MAXDATASIZE; 1040*7c478bd9Sstevel@tonic-gate 1041*7c478bd9Sstevel@tonic-gate if (table_info->retrieveError == 1042*7c478bd9Sstevel@tonic-gate (__nis_retrieve_error_t)NO_VALUE_SET) 1043*7c478bd9Sstevel@tonic-gate table_info->retrieveError = use_cached; 1044*7c478bd9Sstevel@tonic-gate if (table_info->retrieveErrorRetry.attempts == NO_VALUE_SET) 1045*7c478bd9Sstevel@tonic-gate table_info->retrieveErrorRetry.attempts = 1046*7c478bd9Sstevel@tonic-gate DEFAULT_RETRIEVE_ERROR_ATTEMPTS; 1047*7c478bd9Sstevel@tonic-gate if (table_info->retrieveErrorRetry.timeout == (time_t)NO_VALUE_SET) 1048*7c478bd9Sstevel@tonic-gate table_info->retrieveErrorRetry.timeout = 1049*7c478bd9Sstevel@tonic-gate DEFAULT_RETRIEVE_ERROR_TIME_OUT; 1050*7c478bd9Sstevel@tonic-gate if (table_info->storeError == 1051*7c478bd9Sstevel@tonic-gate (__nis_store_error_t)NO_VALUE_SET) 1052*7c478bd9Sstevel@tonic-gate table_info->storeError = sto_retry; 1053*7c478bd9Sstevel@tonic-gate if (table_info->storeErrorRetry.attempts == NO_VALUE_SET) 1054*7c478bd9Sstevel@tonic-gate table_info->storeErrorRetry.attempts = 1055*7c478bd9Sstevel@tonic-gate DEFAULT_STORE_ERROR_ATTEMPTS; 1056*7c478bd9Sstevel@tonic-gate if (table_info->storeErrorRetry.timeout == (time_t)NO_VALUE_SET) 1057*7c478bd9Sstevel@tonic-gate table_info->storeErrorRetry.timeout = 1058*7c478bd9Sstevel@tonic-gate DEFAULT_STORE_ERROR_TIME_OUT; 1059*7c478bd9Sstevel@tonic-gate if (table_info->refreshError == 1060*7c478bd9Sstevel@tonic-gate (__nis_refresh_error_t)NO_VALUE_SET) 1061*7c478bd9Sstevel@tonic-gate table_info->refreshError = continue_using; 1062*7c478bd9Sstevel@tonic-gate if (table_info->refreshErrorRetry.attempts == NO_VALUE_SET) 1063*7c478bd9Sstevel@tonic-gate table_info->refreshErrorRetry.attempts = 1064*7c478bd9Sstevel@tonic-gate DEFAULT_REFRESH_ERROR_ATTEMPTS; 1065*7c478bd9Sstevel@tonic-gate if (table_info->refreshErrorRetry.timeout == (time_t)NO_VALUE_SET) 1066*7c478bd9Sstevel@tonic-gate table_info->refreshErrorRetry.timeout = 1067*7c478bd9Sstevel@tonic-gate DEFAULT_REFRESH_ERROR_TIME_OUT; 1068*7c478bd9Sstevel@tonic-gate if (table_info->matchFetch == 1069*7c478bd9Sstevel@tonic-gate (__nis_match_fetch_t)NO_VALUE_SET) 1070*7c478bd9Sstevel@tonic-gate table_info->matchFetch = no_match_only; 1071*7c478bd9Sstevel@tonic-gate } 1072*7c478bd9Sstevel@tonic-gate 1073*7c478bd9Sstevel@tonic-gate __nis_table_mapping_t * 1074*7c478bd9Sstevel@tonic-gate find_table_mapping(const char *s, int len, __nis_table_mapping_t *table_mapping) 1075*7c478bd9Sstevel@tonic-gate { 1076*7c478bd9Sstevel@tonic-gate __nis_table_mapping_t *t; 1077*7c478bd9Sstevel@tonic-gate 1078*7c478bd9Sstevel@tonic-gate for (t = table_mapping; t != NULL; t = t->next) 1079*7c478bd9Sstevel@tonic-gate if (strlen(t->dbId) == len && 1080*7c478bd9Sstevel@tonic-gate strncasecmp(t->dbId, s, len) == 0) 1081*7c478bd9Sstevel@tonic-gate break; 1082*7c478bd9Sstevel@tonic-gate return (t); 1083*7c478bd9Sstevel@tonic-gate } 1084*7c478bd9Sstevel@tonic-gate 1085*7c478bd9Sstevel@tonic-gate void 1086*7c478bd9Sstevel@tonic-gate append_dot(char **str) 1087*7c478bd9Sstevel@tonic-gate { 1088*7c478bd9Sstevel@tonic-gate char *s = *str; 1089*7c478bd9Sstevel@tonic-gate int len = strlen(s); 1090*7c478bd9Sstevel@tonic-gate 1091*7c478bd9Sstevel@tonic-gate if (len == 0 || s[len - 1] != PERIOD_CHAR) { 1092*7c478bd9Sstevel@tonic-gate s = s_realloc(s, len + 2); 1093*7c478bd9Sstevel@tonic-gate if (s != NULL) { 1094*7c478bd9Sstevel@tonic-gate s[len] = PERIOD_CHAR; 1095*7c478bd9Sstevel@tonic-gate s[len+1] = '\0'; 1096*7c478bd9Sstevel@tonic-gate *str = s; 1097*7c478bd9Sstevel@tonic-gate } 1098*7c478bd9Sstevel@tonic-gate } 1099*7c478bd9Sstevel@tonic-gate } 1100*7c478bd9Sstevel@tonic-gate 1101*7c478bd9Sstevel@tonic-gate void 1102*7c478bd9Sstevel@tonic-gate append_comma(char **str) 1103*7c478bd9Sstevel@tonic-gate { 1104*7c478bd9Sstevel@tonic-gate 1105*7c478bd9Sstevel@tonic-gate char *s = *str; 1106*7c478bd9Sstevel@tonic-gate int len = strlen(s); 1107*7c478bd9Sstevel@tonic-gate 1108*7c478bd9Sstevel@tonic-gate if (len == 0 || s[len - 1] != COMMA_CHAR) { 1109*7c478bd9Sstevel@tonic-gate s = s_realloc(s, len + 2); 1110*7c478bd9Sstevel@tonic-gate if (s != NULL) { 1111*7c478bd9Sstevel@tonic-gate s[len] = COMMA_CHAR; 1112*7c478bd9Sstevel@tonic-gate s[len+1] = '\0'; 1113*7c478bd9Sstevel@tonic-gate *str = s; 1114*7c478bd9Sstevel@tonic-gate } 1115*7c478bd9Sstevel@tonic-gate } 1116*7c478bd9Sstevel@tonic-gate } 1117*7c478bd9Sstevel@tonic-gate 1118*7c478bd9Sstevel@tonic-gate /* 1119*7c478bd9Sstevel@tonic-gate * FUNCTION: make_full_dn 1120*7c478bd9Sstevel@tonic-gate * 1121*7c478bd9Sstevel@tonic-gate * Appends the base dn if a relative ldap dn 1122*7c478bd9Sstevel@tonic-gate * (invoked only for LDAP write cycle) 1123*7c478bd9Sstevel@tonic-gate * 1124*7c478bd9Sstevel@tonic-gate * RETURN VALUE: FALSE if error 1125*7c478bd9Sstevel@tonic-gate * TRUE if __nis_index_t returned 1126*7c478bd9Sstevel@tonic-gate * 1127*7c478bd9Sstevel@tonic-gate * INPUT: the relative dn and ldap base 1128*7c478bd9Sstevel@tonic-gate */ 1129*7c478bd9Sstevel@tonic-gate 1130*7c478bd9Sstevel@tonic-gate bool_t 1131*7c478bd9Sstevel@tonic-gate make_full_dn(char **dn, const char *base) 1132*7c478bd9Sstevel@tonic-gate { 1133*7c478bd9Sstevel@tonic-gate int len; 1134*7c478bd9Sstevel@tonic-gate int len1; 1135*7c478bd9Sstevel@tonic-gate 1136*7c478bd9Sstevel@tonic-gate if (*dn == NULL) { 1137*7c478bd9Sstevel@tonic-gate *dn = s_strdup(base); 1138*7c478bd9Sstevel@tonic-gate } else { 1139*7c478bd9Sstevel@tonic-gate len = strlen(*dn); 1140*7c478bd9Sstevel@tonic-gate if (len > 0 && (*dn)[len-1] == COMMA_CHAR) { 1141*7c478bd9Sstevel@tonic-gate len1 = strlen(base) + 1; 1142*7c478bd9Sstevel@tonic-gate *dn = s_realloc(*dn, len + len1); 1143*7c478bd9Sstevel@tonic-gate if (*dn != NULL) 1144*7c478bd9Sstevel@tonic-gate (void) strcpy(*dn + len, base); 1145*7c478bd9Sstevel@tonic-gate } 1146*7c478bd9Sstevel@tonic-gate } 1147*7c478bd9Sstevel@tonic-gate return (*dn != NULL); 1148*7c478bd9Sstevel@tonic-gate } 1149*7c478bd9Sstevel@tonic-gate 1150*7c478bd9Sstevel@tonic-gate /* 1151*7c478bd9Sstevel@tonic-gate * FUNCTION: make_fqdn 1152*7c478bd9Sstevel@tonic-gate * 1153*7c478bd9Sstevel@tonic-gate * Appends the base dn if a relative ldap dn 1154*7c478bd9Sstevel@tonic-gate * (invoked only for LDAP read cycle) 1155*7c478bd9Sstevel@tonic-gate * 1156*7c478bd9Sstevel@tonic-gate * RETURN VALUE: FALSE if error 1157*7c478bd9Sstevel@tonic-gate * TRUE if success 1158*7c478bd9Sstevel@tonic-gate * 1159*7c478bd9Sstevel@tonic-gate * INPUT: the relative dn and ldap base 1160*7c478bd9Sstevel@tonic-gate */ 1161*7c478bd9Sstevel@tonic-gate bool_t 1162*7c478bd9Sstevel@tonic-gate make_fqdn(__nis_object_dn_t *dn, const char *base) 1163*7c478bd9Sstevel@tonic-gate { 1164*7c478bd9Sstevel@tonic-gate int len; 1165*7c478bd9Sstevel@tonic-gate int len1; 1166*7c478bd9Sstevel@tonic-gate 1167*7c478bd9Sstevel@tonic-gate if (dn == NULL) { 1168*7c478bd9Sstevel@tonic-gate return (FALSE); 1169*7c478bd9Sstevel@tonic-gate } else { 1170*7c478bd9Sstevel@tonic-gate while (dn != NULL && dn->read.base != NULL) { 1171*7c478bd9Sstevel@tonic-gate len = strlen(dn->read.base); 1172*7c478bd9Sstevel@tonic-gate if (len > 0 && (dn->read.base)[len-1] == COMMA_CHAR) { 1173*7c478bd9Sstevel@tonic-gate len1 = strlen(base) + 1; 1174*7c478bd9Sstevel@tonic-gate dn->read.base = 1175*7c478bd9Sstevel@tonic-gate s_realloc(dn->read.base, len + len1); 1176*7c478bd9Sstevel@tonic-gate if (dn->read.base != NULL) 1177*7c478bd9Sstevel@tonic-gate (void) strlcpy(dn->read.base + len, 1178*7c478bd9Sstevel@tonic-gate base, len1); 1179*7c478bd9Sstevel@tonic-gate else 1180*7c478bd9Sstevel@tonic-gate return (FALSE); 1181*7c478bd9Sstevel@tonic-gate } 1182*7c478bd9Sstevel@tonic-gate dn = dn->next; 1183*7c478bd9Sstevel@tonic-gate } 1184*7c478bd9Sstevel@tonic-gate } 1185*7c478bd9Sstevel@tonic-gate return (TRUE); 1186*7c478bd9Sstevel@tonic-gate } 1187*7c478bd9Sstevel@tonic-gate 1188*7c478bd9Sstevel@tonic-gate /* 1189*7c478bd9Sstevel@tonic-gate * FUNCTION: get_default_ldap_base 1190*7c478bd9Sstevel@tonic-gate * 1191*7c478bd9Sstevel@tonic-gate * Gets the default LDAP search base from the 1192*7c478bd9Sstevel@tonic-gate * nis+ default domain 1193*7c478bd9Sstevel@tonic-gate * 1194*7c478bd9Sstevel@tonic-gate * RETURN VALUE: NULL if error 1195*7c478bd9Sstevel@tonic-gate * the default base 1196*7c478bd9Sstevel@tonic-gate * 1197*7c478bd9Sstevel@tonic-gate * INPUT: the nis domain 1198*7c478bd9Sstevel@tonic-gate */ 1199*7c478bd9Sstevel@tonic-gate 1200*7c478bd9Sstevel@tonic-gate char * 1201*7c478bd9Sstevel@tonic-gate get_default_ldap_base(const char *domain) 1202*7c478bd9Sstevel@tonic-gate { 1203*7c478bd9Sstevel@tonic-gate 1204*7c478bd9Sstevel@tonic-gate int len = strlen(domain); 1205*7c478bd9Sstevel@tonic-gate int i; 1206*7c478bd9Sstevel@tonic-gate int count = len + 4; 1207*7c478bd9Sstevel@tonic-gate char *base; 1208*7c478bd9Sstevel@tonic-gate 1209*7c478bd9Sstevel@tonic-gate for (i = 0; i < len - 1; i++) 1210*7c478bd9Sstevel@tonic-gate if (domain[i] == PERIOD_CHAR) 1211*7c478bd9Sstevel@tonic-gate count += 4; 1212*7c478bd9Sstevel@tonic-gate if ((base = malloc(count)) == NULL) { 1213*7c478bd9Sstevel@tonic-gate p_error = parse_no_mem_error; 1214*7c478bd9Sstevel@tonic-gate } else { 1215*7c478bd9Sstevel@tonic-gate (void) strcpy(base, "dc="); 1216*7c478bd9Sstevel@tonic-gate count = 3; 1217*7c478bd9Sstevel@tonic-gate for (i = 0; i < len - 1; i++) { 1218*7c478bd9Sstevel@tonic-gate if (domain[i] == PERIOD_CHAR) { 1219*7c478bd9Sstevel@tonic-gate (void) strcpy(base + count, ",dc="); 1220*7c478bd9Sstevel@tonic-gate count += 4; 1221*7c478bd9Sstevel@tonic-gate } else { 1222*7c478bd9Sstevel@tonic-gate base[count++] = domain[i]; 1223*7c478bd9Sstevel@tonic-gate } 1224*7c478bd9Sstevel@tonic-gate } 1225*7c478bd9Sstevel@tonic-gate base[count] = '\0'; 1226*7c478bd9Sstevel@tonic-gate } 1227*7c478bd9Sstevel@tonic-gate return (base); 1228*7c478bd9Sstevel@tonic-gate } 1229*7c478bd9Sstevel@tonic-gate 1230*7c478bd9Sstevel@tonic-gate /* 1231*7c478bd9Sstevel@tonic-gate * FUNCTION: add_domain 1232*7c478bd9Sstevel@tonic-gate * 1233*7c478bd9Sstevel@tonic-gate * Appends the base domain if a relative object name 1234*7c478bd9Sstevel@tonic-gate * 1235*7c478bd9Sstevel@tonic-gate * RETURN VALUE: FALSE if error 1236*7c478bd9Sstevel@tonic-gate * TRUE if OK 1237*7c478bd9Sstevel@tonic-gate * 1238*7c478bd9Sstevel@tonic-gate * INPUT: the relative object name and base domain 1239*7c478bd9Sstevel@tonic-gate * name 1240*7c478bd9Sstevel@tonic-gate */ 1241*7c478bd9Sstevel@tonic-gate 1242*7c478bd9Sstevel@tonic-gate bool_t 1243*7c478bd9Sstevel@tonic-gate add_domain(char **objName, const char *domain) 1244*7c478bd9Sstevel@tonic-gate { 1245*7c478bd9Sstevel@tonic-gate int len; 1246*7c478bd9Sstevel@tonic-gate int len1; 1247*7c478bd9Sstevel@tonic-gate bool_t trailing_dot; 1248*7c478bd9Sstevel@tonic-gate char *obj_name; 1249*7c478bd9Sstevel@tonic-gate 1250*7c478bd9Sstevel@tonic-gate if (domain == NULL || *objName == NULL) { 1251*7c478bd9Sstevel@tonic-gate p_error = parse_internal_error; 1252*7c478bd9Sstevel@tonic-gate return (FALSE); 1253*7c478bd9Sstevel@tonic-gate } 1254*7c478bd9Sstevel@tonic-gate len1 = strlen(domain); 1255*7c478bd9Sstevel@tonic-gate trailing_dot = (len1 > 0 && domain[len1 - 1] == PERIOD_CHAR) ? 1256*7c478bd9Sstevel@tonic-gate 0 : 1; 1257*7c478bd9Sstevel@tonic-gate len = strlen(*objName); 1258*7c478bd9Sstevel@tonic-gate if (len == 0 || (*objName)[len - 1] != PERIOD_CHAR) { 1259*7c478bd9Sstevel@tonic-gate obj_name = s_realloc(*objName, 1260*7c478bd9Sstevel@tonic-gate len + len1 + 2 + trailing_dot); 1261*7c478bd9Sstevel@tonic-gate if (obj_name != NULL) { 1262*7c478bd9Sstevel@tonic-gate obj_name[len++] = PERIOD_CHAR; 1263*7c478bd9Sstevel@tonic-gate (void) strcpy(obj_name + len, domain); 1264*7c478bd9Sstevel@tonic-gate if (trailing_dot != 0) { 1265*7c478bd9Sstevel@tonic-gate obj_name[len + len1] = PERIOD_CHAR; 1266*7c478bd9Sstevel@tonic-gate obj_name[len + len1 + 1] = '\0'; 1267*7c478bd9Sstevel@tonic-gate } 1268*7c478bd9Sstevel@tonic-gate *objName = obj_name; 1269*7c478bd9Sstevel@tonic-gate } 1270*7c478bd9Sstevel@tonic-gate } 1271*7c478bd9Sstevel@tonic-gate 1272*7c478bd9Sstevel@tonic-gate return (*objName != NULL); 1273*7c478bd9Sstevel@tonic-gate } 1274*7c478bd9Sstevel@tonic-gate 1275*7c478bd9Sstevel@tonic-gate bool_t 1276*7c478bd9Sstevel@tonic-gate dup_index(__nis_index_t *in, __nis_index_t *out) 1277*7c478bd9Sstevel@tonic-gate { 1278*7c478bd9Sstevel@tonic-gate int i; 1279*7c478bd9Sstevel@tonic-gate int j; 1280*7c478bd9Sstevel@tonic-gate 1281*7c478bd9Sstevel@tonic-gate out->name = (char **)s_calloc(in->numIndexes, sizeof (char *)); 1282*7c478bd9Sstevel@tonic-gate if (out->name == NULL) 1283*7c478bd9Sstevel@tonic-gate return (FALSE); 1284*7c478bd9Sstevel@tonic-gate out->value = (__nis_mapping_format_t **) 1285*7c478bd9Sstevel@tonic-gate s_calloc(in->numIndexes, sizeof (__nis_mapping_format_t *)); 1286*7c478bd9Sstevel@tonic-gate if (out->value == NULL) { 1287*7c478bd9Sstevel@tonic-gate free(out->name); 1288*7c478bd9Sstevel@tonic-gate out->name = NULL; 1289*7c478bd9Sstevel@tonic-gate return (FALSE); 1290*7c478bd9Sstevel@tonic-gate } 1291*7c478bd9Sstevel@tonic-gate 1292*7c478bd9Sstevel@tonic-gate for (i = 0; i < in->numIndexes; i++) { 1293*7c478bd9Sstevel@tonic-gate out->name[i] = s_strdup(in->name[i]); 1294*7c478bd9Sstevel@tonic-gate if (out->name[i] == NULL) 1295*7c478bd9Sstevel@tonic-gate break; 1296*7c478bd9Sstevel@tonic-gate out->value[i] = dup_format_mapping(in->value[i]); 1297*7c478bd9Sstevel@tonic-gate if (out->value[i] == NULL) 1298*7c478bd9Sstevel@tonic-gate break; 1299*7c478bd9Sstevel@tonic-gate } 1300*7c478bd9Sstevel@tonic-gate if (i < in->numIndexes) { 1301*7c478bd9Sstevel@tonic-gate for (j = 0; j <= i; j++) { 1302*7c478bd9Sstevel@tonic-gate if (out->name[j] != NULL) 1303*7c478bd9Sstevel@tonic-gate free(out->name[j]); 1304*7c478bd9Sstevel@tonic-gate if (out->value[j] != NULL) 1305*7c478bd9Sstevel@tonic-gate free_mapping_format(out->value[j]); 1306*7c478bd9Sstevel@tonic-gate } 1307*7c478bd9Sstevel@tonic-gate free(out->name); 1308*7c478bd9Sstevel@tonic-gate out->name = NULL; 1309*7c478bd9Sstevel@tonic-gate free(out->value); 1310*7c478bd9Sstevel@tonic-gate out->value = NULL; 1311*7c478bd9Sstevel@tonic-gate } else { 1312*7c478bd9Sstevel@tonic-gate out->numIndexes = in->numIndexes; 1313*7c478bd9Sstevel@tonic-gate } 1314*7c478bd9Sstevel@tonic-gate return (i == in->numIndexes); 1315*7c478bd9Sstevel@tonic-gate } 1316*7c478bd9Sstevel@tonic-gate 1317*7c478bd9Sstevel@tonic-gate bool_t 1318*7c478bd9Sstevel@tonic-gate dup_mapping_item(__nis_mapping_item_t *in, __nis_mapping_item_t *out) 1319*7c478bd9Sstevel@tonic-gate { 1320*7c478bd9Sstevel@tonic-gate bool_t ret; 1321*7c478bd9Sstevel@tonic-gate 1322*7c478bd9Sstevel@tonic-gate if (in->type == mit_nisplus) { 1323*7c478bd9Sstevel@tonic-gate ret = dup_index(&in->searchSpec.obj.index, 1324*7c478bd9Sstevel@tonic-gate &out->searchSpec.obj.index); 1325*7c478bd9Sstevel@tonic-gate if (!ret) 1326*7c478bd9Sstevel@tonic-gate return (ret); 1327*7c478bd9Sstevel@tonic-gate if (in->searchSpec.obj.name != NULL) { 1328*7c478bd9Sstevel@tonic-gate out->searchSpec.obj.name = 1329*7c478bd9Sstevel@tonic-gate s_strdup(in->searchSpec.obj.name); 1330*7c478bd9Sstevel@tonic-gate if (out->searchSpec.obj.name == NULL) 1331*7c478bd9Sstevel@tonic-gate return (FALSE); 1332*7c478bd9Sstevel@tonic-gate } else 1333*7c478bd9Sstevel@tonic-gate out->searchSpec.obj.name = NULL; 1334*7c478bd9Sstevel@tonic-gate } else if (in->type == mit_ldap) { 1335*7c478bd9Sstevel@tonic-gate if (in->searchSpec.triple.base != NULL) { 1336*7c478bd9Sstevel@tonic-gate out->searchSpec.triple.base = 1337*7c478bd9Sstevel@tonic-gate s_strdup(in->searchSpec.triple.base); 1338*7c478bd9Sstevel@tonic-gate if (out->searchSpec.triple.base == NULL) 1339*7c478bd9Sstevel@tonic-gate return (FALSE); 1340*7c478bd9Sstevel@tonic-gate } else 1341*7c478bd9Sstevel@tonic-gate out->searchSpec.triple.base = NULL; 1342*7c478bd9Sstevel@tonic-gate out->searchSpec.triple.scope = 1343*7c478bd9Sstevel@tonic-gate in->searchSpec.triple.scope; 1344*7c478bd9Sstevel@tonic-gate if (in->searchSpec.triple.attrs != NULL) { 1345*7c478bd9Sstevel@tonic-gate out->searchSpec.triple.attrs = 1346*7c478bd9Sstevel@tonic-gate s_strdup(in->searchSpec.triple.attrs); 1347*7c478bd9Sstevel@tonic-gate if (out->searchSpec.triple.attrs == NULL) 1348*7c478bd9Sstevel@tonic-gate return (FALSE); 1349*7c478bd9Sstevel@tonic-gate } else 1350*7c478bd9Sstevel@tonic-gate out->searchSpec.triple.attrs = NULL; 1351*7c478bd9Sstevel@tonic-gate if (in->searchSpec.triple.element != NULL) { 1352*7c478bd9Sstevel@tonic-gate out->searchSpec.triple.element = 1353*7c478bd9Sstevel@tonic-gate (__nis_mapping_element_t *) 1354*7c478bd9Sstevel@tonic-gate s_calloc(1, sizeof (__nis_mapping_element_t)); 1355*7c478bd9Sstevel@tonic-gate if (out->searchSpec.triple.element != NULL) 1356*7c478bd9Sstevel@tonic-gate dup_mapping_element( 1357*7c478bd9Sstevel@tonic-gate in->searchSpec.triple.element, 1358*7c478bd9Sstevel@tonic-gate out->searchSpec.triple.element); 1359*7c478bd9Sstevel@tonic-gate if (out->searchSpec.triple.element == NULL) 1360*7c478bd9Sstevel@tonic-gate return (FALSE); 1361*7c478bd9Sstevel@tonic-gate } else 1362*7c478bd9Sstevel@tonic-gate out->searchSpec.triple.element = NULL; 1363*7c478bd9Sstevel@tonic-gate } 1364*7c478bd9Sstevel@tonic-gate 1365*7c478bd9Sstevel@tonic-gate if (in->name != NULL) { 1366*7c478bd9Sstevel@tonic-gate out->name = s_strdup(in->name); 1367*7c478bd9Sstevel@tonic-gate if (out->name == NULL) 1368*7c478bd9Sstevel@tonic-gate return (FALSE); 1369*7c478bd9Sstevel@tonic-gate } else 1370*7c478bd9Sstevel@tonic-gate out->name = NULL; 1371*7c478bd9Sstevel@tonic-gate out->type = in->type; 1372*7c478bd9Sstevel@tonic-gate out->repeat = in->repeat; 1373*7c478bd9Sstevel@tonic-gate if (in->exItem) { 1374*7c478bd9Sstevel@tonic-gate out->exItem = (__nis_mapping_item_t *)s_malloc 1375*7c478bd9Sstevel@tonic-gate (sizeof (__nis_mapping_item_t)); 1376*7c478bd9Sstevel@tonic-gate if (out->exItem == NULL) 1377*7c478bd9Sstevel@tonic-gate return (FALSE); 1378*7c478bd9Sstevel@tonic-gate else { 1379*7c478bd9Sstevel@tonic-gate (void) memset 1380*7c478bd9Sstevel@tonic-gate (out->exItem, 0, sizeof (out->exItem[0])); 1381*7c478bd9Sstevel@tonic-gate if (!dup_mapping_item 1382*7c478bd9Sstevel@tonic-gate (in->exItem, out->exItem)) 1383*7c478bd9Sstevel@tonic-gate p_error = parse_internal_error; 1384*7c478bd9Sstevel@tonic-gate } 1385*7c478bd9Sstevel@tonic-gate } else 1386*7c478bd9Sstevel@tonic-gate out->exItem = NULL; 1387*7c478bd9Sstevel@tonic-gate 1388*7c478bd9Sstevel@tonic-gate return (p_error == no_parse_error); 1389*7c478bd9Sstevel@tonic-gate } 1390*7c478bd9Sstevel@tonic-gate 1391*7c478bd9Sstevel@tonic-gate __nis_mapping_format_t * 1392*7c478bd9Sstevel@tonic-gate dup_format_mapping(__nis_mapping_format_t *in) 1393*7c478bd9Sstevel@tonic-gate { 1394*7c478bd9Sstevel@tonic-gate int i; 1395*7c478bd9Sstevel@tonic-gate __nis_mapping_format_t *out; 1396*7c478bd9Sstevel@tonic-gate bool_t got_end; 1397*7c478bd9Sstevel@tonic-gate 1398*7c478bd9Sstevel@tonic-gate i = 0; 1399*7c478bd9Sstevel@tonic-gate while (in[i].type != mmt_end) 1400*7c478bd9Sstevel@tonic-gate i++; 1401*7c478bd9Sstevel@tonic-gate out = (__nis_mapping_format_t *)s_calloc( 1402*7c478bd9Sstevel@tonic-gate i + 1, sizeof (__nis_mapping_format_t)); 1403*7c478bd9Sstevel@tonic-gate if (out != NULL) { 1404*7c478bd9Sstevel@tonic-gate got_end = FALSE; 1405*7c478bd9Sstevel@tonic-gate for (i = 0; !got_end; i++) { 1406*7c478bd9Sstevel@tonic-gate switch (in[i].type) { 1407*7c478bd9Sstevel@tonic-gate case mmt_item: 1408*7c478bd9Sstevel@tonic-gate break; 1409*7c478bd9Sstevel@tonic-gate case mmt_string: 1410*7c478bd9Sstevel@tonic-gate out[i].match.string = 1411*7c478bd9Sstevel@tonic-gate s_strdup(in[i].match.string); 1412*7c478bd9Sstevel@tonic-gate break; 1413*7c478bd9Sstevel@tonic-gate case mmt_single: 1414*7c478bd9Sstevel@tonic-gate out[i].match.single.numRange = 1415*7c478bd9Sstevel@tonic-gate in[i].match.single.numRange; 1416*7c478bd9Sstevel@tonic-gate out[i].match.single.lo = 1417*7c478bd9Sstevel@tonic-gate s_malloc(in[i].match.single.numRange); 1418*7c478bd9Sstevel@tonic-gate if (out[i].match.single.lo == NULL) 1419*7c478bd9Sstevel@tonic-gate break; 1420*7c478bd9Sstevel@tonic-gate out[i].match.single.hi = 1421*7c478bd9Sstevel@tonic-gate s_malloc(in[i].match.single.numRange); 1422*7c478bd9Sstevel@tonic-gate if (out[i].match.single.hi == NULL) 1423*7c478bd9Sstevel@tonic-gate break; 1424*7c478bd9Sstevel@tonic-gate memcpy(out[i].match.single.lo, 1425*7c478bd9Sstevel@tonic-gate in[i].match.single.lo, 1426*7c478bd9Sstevel@tonic-gate in[i].match.single.numRange); 1427*7c478bd9Sstevel@tonic-gate memcpy(out[i].match.single.hi, 1428*7c478bd9Sstevel@tonic-gate in[i].match.single.hi, 1429*7c478bd9Sstevel@tonic-gate in[i].match.single.numRange); 1430*7c478bd9Sstevel@tonic-gate break; 1431*7c478bd9Sstevel@tonic-gate case mmt_limit: 1432*7c478bd9Sstevel@tonic-gate out[i].match.limit = in[i].match.limit; 1433*7c478bd9Sstevel@tonic-gate break; 1434*7c478bd9Sstevel@tonic-gate case mmt_any: 1435*7c478bd9Sstevel@tonic-gate break; 1436*7c478bd9Sstevel@tonic-gate case mmt_berstring: 1437*7c478bd9Sstevel@tonic-gate out[i].match.berString = 1438*7c478bd9Sstevel@tonic-gate s_strdup(in[i].match.berString); 1439*7c478bd9Sstevel@tonic-gate break; 1440*7c478bd9Sstevel@tonic-gate case mmt_begin: 1441*7c478bd9Sstevel@tonic-gate break; 1442*7c478bd9Sstevel@tonic-gate case mmt_end: 1443*7c478bd9Sstevel@tonic-gate got_end = TRUE; 1444*7c478bd9Sstevel@tonic-gate break; 1445*7c478bd9Sstevel@tonic-gate default: 1446*7c478bd9Sstevel@tonic-gate p_error = parse_internal_error; 1447*7c478bd9Sstevel@tonic-gate } 1448*7c478bd9Sstevel@tonic-gate if (p_error != no_parse_error) 1449*7c478bd9Sstevel@tonic-gate break; 1450*7c478bd9Sstevel@tonic-gate out[i].type = in[i].type; 1451*7c478bd9Sstevel@tonic-gate } 1452*7c478bd9Sstevel@tonic-gate if (p_error != no_parse_error) { 1453*7c478bd9Sstevel@tonic-gate free_mapping_format(out); 1454*7c478bd9Sstevel@tonic-gate out = NULL; 1455*7c478bd9Sstevel@tonic-gate } 1456*7c478bd9Sstevel@tonic-gate } 1457*7c478bd9Sstevel@tonic-gate 1458*7c478bd9Sstevel@tonic-gate return (out); 1459*7c478bd9Sstevel@tonic-gate } 1460*7c478bd9Sstevel@tonic-gate 1461*7c478bd9Sstevel@tonic-gate bool_t 1462*7c478bd9Sstevel@tonic-gate dup_mapping_sub_element( 1463*7c478bd9Sstevel@tonic-gate __nis_mapping_sub_element_t *in, 1464*7c478bd9Sstevel@tonic-gate __nis_mapping_sub_element_t *out) 1465*7c478bd9Sstevel@tonic-gate { 1466*7c478bd9Sstevel@tonic-gate bool_t ret = FALSE; 1467*7c478bd9Sstevel@tonic-gate int i; 1468*7c478bd9Sstevel@tonic-gate 1469*7c478bd9Sstevel@tonic-gate switch (in->type) { 1470*7c478bd9Sstevel@tonic-gate case me_item: 1471*7c478bd9Sstevel@tonic-gate ret = dup_mapping_item(&in->element.item, 1472*7c478bd9Sstevel@tonic-gate &out->element.item); 1473*7c478bd9Sstevel@tonic-gate break; 1474*7c478bd9Sstevel@tonic-gate case me_print: 1475*7c478bd9Sstevel@tonic-gate out->element.print.fmt = 1476*7c478bd9Sstevel@tonic-gate dup_format_mapping(in->element.print.fmt); 1477*7c478bd9Sstevel@tonic-gate if (out->element.print.fmt == NULL) 1478*7c478bd9Sstevel@tonic-gate break; 1479*7c478bd9Sstevel@tonic-gate out->element.print.numItems = 1480*7c478bd9Sstevel@tonic-gate in->element.print.numItems; 1481*7c478bd9Sstevel@tonic-gate out->element.print.item = (__nis_mapping_item_t *) 1482*7c478bd9Sstevel@tonic-gate s_calloc(in->element.print.numItems, 1483*7c478bd9Sstevel@tonic-gate sizeof (__nis_mapping_item_t)); 1484*7c478bd9Sstevel@tonic-gate if (out->element.print.item == NULL) 1485*7c478bd9Sstevel@tonic-gate break; 1486*7c478bd9Sstevel@tonic-gate for (i = 0; i < in->element.print.numItems; i++) 1487*7c478bd9Sstevel@tonic-gate if (!dup_mapping_item( 1488*7c478bd9Sstevel@tonic-gate &in->element.print.item[i], 1489*7c478bd9Sstevel@tonic-gate &out->element.print.item[i])) 1490*7c478bd9Sstevel@tonic-gate break; 1491*7c478bd9Sstevel@tonic-gate if (i < in->element.print.numItems) 1492*7c478bd9Sstevel@tonic-gate break; 1493*7c478bd9Sstevel@tonic-gate ret = TRUE; 1494*7c478bd9Sstevel@tonic-gate out->element.print.doElide = in->element.print.doElide; 1495*7c478bd9Sstevel@tonic-gate out->element.print.elide = in->element.print.elide; 1496*7c478bd9Sstevel@tonic-gate break; 1497*7c478bd9Sstevel@tonic-gate case me_split: 1498*7c478bd9Sstevel@tonic-gate ret = dup_mapping_item(&in->element.split.item, 1499*7c478bd9Sstevel@tonic-gate &out->element.split.item); 1500*7c478bd9Sstevel@tonic-gate out->element.split.delim = in->element.split.delim; 1501*7c478bd9Sstevel@tonic-gate break; 1502*7c478bd9Sstevel@tonic-gate case me_extract: 1503*7c478bd9Sstevel@tonic-gate out->element.extract.fmt = 1504*7c478bd9Sstevel@tonic-gate dup_format_mapping(in->element.extract.fmt); 1505*7c478bd9Sstevel@tonic-gate if (out->element.extract.fmt == NULL) 1506*7c478bd9Sstevel@tonic-gate break; 1507*7c478bd9Sstevel@tonic-gate ret = dup_mapping_item(&in->element.extract.item, 1508*7c478bd9Sstevel@tonic-gate &out->element.extract.item); 1509*7c478bd9Sstevel@tonic-gate break; 1510*7c478bd9Sstevel@tonic-gate default: 1511*7c478bd9Sstevel@tonic-gate p_error = parse_internal_error; 1512*7c478bd9Sstevel@tonic-gate } 1513*7c478bd9Sstevel@tonic-gate out->type = in->type; 1514*7c478bd9Sstevel@tonic-gate 1515*7c478bd9Sstevel@tonic-gate return (ret); 1516*7c478bd9Sstevel@tonic-gate } 1517*7c478bd9Sstevel@tonic-gate 1518*7c478bd9Sstevel@tonic-gate bool_t 1519*7c478bd9Sstevel@tonic-gate dup_mapping_element( 1520*7c478bd9Sstevel@tonic-gate __nis_mapping_element_t *in, 1521*7c478bd9Sstevel@tonic-gate __nis_mapping_element_t *out) 1522*7c478bd9Sstevel@tonic-gate { 1523*7c478bd9Sstevel@tonic-gate bool_t ret = FALSE; 1524*7c478bd9Sstevel@tonic-gate int i; 1525*7c478bd9Sstevel@tonic-gate 1526*7c478bd9Sstevel@tonic-gate if (in == NULL) 1527*7c478bd9Sstevel@tonic-gate return (ret); 1528*7c478bd9Sstevel@tonic-gate 1529*7c478bd9Sstevel@tonic-gate switch (in->type) { 1530*7c478bd9Sstevel@tonic-gate case me_item: 1531*7c478bd9Sstevel@tonic-gate ret = dup_mapping_item(&in->element.item, 1532*7c478bd9Sstevel@tonic-gate &out->element.item); 1533*7c478bd9Sstevel@tonic-gate break; 1534*7c478bd9Sstevel@tonic-gate case me_print: 1535*7c478bd9Sstevel@tonic-gate out->element.print.fmt = 1536*7c478bd9Sstevel@tonic-gate dup_format_mapping(in->element.print.fmt); 1537*7c478bd9Sstevel@tonic-gate if (out->element.print.fmt == NULL) 1538*7c478bd9Sstevel@tonic-gate break; 1539*7c478bd9Sstevel@tonic-gate out->element.print.numSubElements = 1540*7c478bd9Sstevel@tonic-gate in->element.print.numSubElements; 1541*7c478bd9Sstevel@tonic-gate out->element.print.subElement = 1542*7c478bd9Sstevel@tonic-gate (__nis_mapping_sub_element_t *) 1543*7c478bd9Sstevel@tonic-gate s_calloc(in->element.print.numSubElements, 1544*7c478bd9Sstevel@tonic-gate sizeof (__nis_mapping_sub_element_t)); 1545*7c478bd9Sstevel@tonic-gate if (out->element.print.subElement == NULL) 1546*7c478bd9Sstevel@tonic-gate break; 1547*7c478bd9Sstevel@tonic-gate for (i = 0; i < in->element.print.numSubElements; i++) 1548*7c478bd9Sstevel@tonic-gate if (!dup_mapping_sub_element( 1549*7c478bd9Sstevel@tonic-gate &in->element.print.subElement[i], 1550*7c478bd9Sstevel@tonic-gate &out->element.print.subElement[i])) 1551*7c478bd9Sstevel@tonic-gate break; 1552*7c478bd9Sstevel@tonic-gate if (i < in->element.print.numSubElements) 1553*7c478bd9Sstevel@tonic-gate break; 1554*7c478bd9Sstevel@tonic-gate ret = TRUE; 1555*7c478bd9Sstevel@tonic-gate out->element.print.doElide = in->element.print.doElide; 1556*7c478bd9Sstevel@tonic-gate out->element.print.elide = in->element.print.elide; 1557*7c478bd9Sstevel@tonic-gate break; 1558*7c478bd9Sstevel@tonic-gate case me_split: 1559*7c478bd9Sstevel@tonic-gate ret = dup_mapping_item(&in->element.split.item, 1560*7c478bd9Sstevel@tonic-gate &out->element.split.item); 1561*7c478bd9Sstevel@tonic-gate out->element.split.delim = in->element.split.delim; 1562*7c478bd9Sstevel@tonic-gate break; 1563*7c478bd9Sstevel@tonic-gate case me_match: 1564*7c478bd9Sstevel@tonic-gate out->element.match.fmt = 1565*7c478bd9Sstevel@tonic-gate dup_format_mapping(in->element.match.fmt); 1566*7c478bd9Sstevel@tonic-gate if (out->element.match.fmt == NULL) 1567*7c478bd9Sstevel@tonic-gate break; 1568*7c478bd9Sstevel@tonic-gate out->element.match.numItems = 1569*7c478bd9Sstevel@tonic-gate in->element.match.numItems; 1570*7c478bd9Sstevel@tonic-gate out->element.match.item = (__nis_mapping_item_t *) 1571*7c478bd9Sstevel@tonic-gate s_calloc(in->element.match.numItems, 1572*7c478bd9Sstevel@tonic-gate sizeof (__nis_mapping_item_t)); 1573*7c478bd9Sstevel@tonic-gate if (out->element.match.item == NULL) 1574*7c478bd9Sstevel@tonic-gate break; 1575*7c478bd9Sstevel@tonic-gate for (i = 0; i < in->element.match.numItems; i++) 1576*7c478bd9Sstevel@tonic-gate if (!dup_mapping_item( 1577*7c478bd9Sstevel@tonic-gate &in->element.match.item[i], 1578*7c478bd9Sstevel@tonic-gate &out->element.match.item[i])) 1579*7c478bd9Sstevel@tonic-gate break; 1580*7c478bd9Sstevel@tonic-gate if (i < in->element.match.numItems) 1581*7c478bd9Sstevel@tonic-gate break; 1582*7c478bd9Sstevel@tonic-gate ret = TRUE; 1583*7c478bd9Sstevel@tonic-gate break; 1584*7c478bd9Sstevel@tonic-gate case me_extract: 1585*7c478bd9Sstevel@tonic-gate out->element.extract.fmt = 1586*7c478bd9Sstevel@tonic-gate dup_format_mapping(in->element.extract.fmt); 1587*7c478bd9Sstevel@tonic-gate if (out->element.extract.fmt == NULL) 1588*7c478bd9Sstevel@tonic-gate break; 1589*7c478bd9Sstevel@tonic-gate ret = dup_mapping_item(&in->element.extract.item, 1590*7c478bd9Sstevel@tonic-gate &out->element.extract.item); 1591*7c478bd9Sstevel@tonic-gate break; 1592*7c478bd9Sstevel@tonic-gate default: 1593*7c478bd9Sstevel@tonic-gate p_error = parse_internal_error; 1594*7c478bd9Sstevel@tonic-gate } 1595*7c478bd9Sstevel@tonic-gate out->type = in->type; 1596*7c478bd9Sstevel@tonic-gate 1597*7c478bd9Sstevel@tonic-gate return (ret); 1598*7c478bd9Sstevel@tonic-gate } 1599*7c478bd9Sstevel@tonic-gate 1600*7c478bd9Sstevel@tonic-gate __nis_mapping_rule_t * 1601*7c478bd9Sstevel@tonic-gate dup_mapping_rule(__nis_mapping_rule_t *in) 1602*7c478bd9Sstevel@tonic-gate { 1603*7c478bd9Sstevel@tonic-gate int i; 1604*7c478bd9Sstevel@tonic-gate __nis_mapping_rlhs_t *r_in; 1605*7c478bd9Sstevel@tonic-gate __nis_mapping_rlhs_t *r_out; 1606*7c478bd9Sstevel@tonic-gate __nis_mapping_rule_t *out; 1607*7c478bd9Sstevel@tonic-gate 1608*7c478bd9Sstevel@tonic-gate out = (__nis_mapping_rule_t *) 1609*7c478bd9Sstevel@tonic-gate s_calloc(1, sizeof (__nis_mapping_rule_t)); 1610*7c478bd9Sstevel@tonic-gate if (out != NULL) { 1611*7c478bd9Sstevel@tonic-gate r_in = &in->lhs; 1612*7c478bd9Sstevel@tonic-gate r_out = &out->lhs; 1613*7c478bd9Sstevel@tonic-gate r_out->numElements = r_in->numElements; 1614*7c478bd9Sstevel@tonic-gate r_out->element = (__nis_mapping_element_t *)s_calloc 1615*7c478bd9Sstevel@tonic-gate (r_in->numElements, sizeof (__nis_mapping_element_t)); 1616*7c478bd9Sstevel@tonic-gate if (r_out->element == NULL) { 1617*7c478bd9Sstevel@tonic-gate free_mapping_rule(out); 1618*7c478bd9Sstevel@tonic-gate return (NULL); 1619*7c478bd9Sstevel@tonic-gate } 1620*7c478bd9Sstevel@tonic-gate for (i = 0; i < r_in->numElements; i++) { 1621*7c478bd9Sstevel@tonic-gate if (!dup_mapping_element(&r_in->element[i], 1622*7c478bd9Sstevel@tonic-gate &r_out->element[i])) 1623*7c478bd9Sstevel@tonic-gate break; 1624*7c478bd9Sstevel@tonic-gate } 1625*7c478bd9Sstevel@tonic-gate if (i < r_in->numElements) { 1626*7c478bd9Sstevel@tonic-gate free_mapping_rule(out); 1627*7c478bd9Sstevel@tonic-gate return (NULL); 1628*7c478bd9Sstevel@tonic-gate } 1629*7c478bd9Sstevel@tonic-gate 1630*7c478bd9Sstevel@tonic-gate r_in = &in->rhs; 1631*7c478bd9Sstevel@tonic-gate r_out = &out->rhs; 1632*7c478bd9Sstevel@tonic-gate r_out->numElements = r_in->numElements; 1633*7c478bd9Sstevel@tonic-gate r_out->element = (__nis_mapping_element_t *)s_calloc 1634*7c478bd9Sstevel@tonic-gate (r_in->numElements, sizeof (__nis_mapping_element_t)); 1635*7c478bd9Sstevel@tonic-gate if (r_out->element == NULL) { 1636*7c478bd9Sstevel@tonic-gate free_mapping_rule(out); 1637*7c478bd9Sstevel@tonic-gate return (NULL); 1638*7c478bd9Sstevel@tonic-gate } 1639*7c478bd9Sstevel@tonic-gate for (i = 0; i < r_in->numElements; i++) { 1640*7c478bd9Sstevel@tonic-gate if (!dup_mapping_element(&r_in->element[i], 1641*7c478bd9Sstevel@tonic-gate &r_out->element[i])) 1642*7c478bd9Sstevel@tonic-gate break; 1643*7c478bd9Sstevel@tonic-gate } 1644*7c478bd9Sstevel@tonic-gate if (i < r_in->numElements) { 1645*7c478bd9Sstevel@tonic-gate free_mapping_rule(out); 1646*7c478bd9Sstevel@tonic-gate return (NULL); 1647*7c478bd9Sstevel@tonic-gate } 1648*7c478bd9Sstevel@tonic-gate } 1649*7c478bd9Sstevel@tonic-gate return (out); 1650*7c478bd9Sstevel@tonic-gate } 1651*7c478bd9Sstevel@tonic-gate 1652*7c478bd9Sstevel@tonic-gate __nis_mapping_rule_t ** 1653*7c478bd9Sstevel@tonic-gate dup_mapping_rules(__nis_mapping_rule_t **rules, int n_rules) 1654*7c478bd9Sstevel@tonic-gate { 1655*7c478bd9Sstevel@tonic-gate int i, j; 1656*7c478bd9Sstevel@tonic-gate __nis_mapping_rule_t **r; 1657*7c478bd9Sstevel@tonic-gate 1658*7c478bd9Sstevel@tonic-gate r = (__nis_mapping_rule_t **)s_calloc(n_rules, 1659*7c478bd9Sstevel@tonic-gate sizeof (__nis_mapping_rule_t *)); 1660*7c478bd9Sstevel@tonic-gate if (r != NULL) { 1661*7c478bd9Sstevel@tonic-gate for (i = 0; i < n_rules; i++) { 1662*7c478bd9Sstevel@tonic-gate r[i] = dup_mapping_rule(rules[i]); 1663*7c478bd9Sstevel@tonic-gate if (r[i] == NULL) { 1664*7c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) 1665*7c478bd9Sstevel@tonic-gate free_mapping_rule(r[j]); 1666*7c478bd9Sstevel@tonic-gate free(r); 1667*7c478bd9Sstevel@tonic-gate r = NULL; 1668*7c478bd9Sstevel@tonic-gate break; 1669*7c478bd9Sstevel@tonic-gate } 1670*7c478bd9Sstevel@tonic-gate } 1671*7c478bd9Sstevel@tonic-gate } 1672*7c478bd9Sstevel@tonic-gate return (r); 1673*7c478bd9Sstevel@tonic-gate } 1674*7c478bd9Sstevel@tonic-gate 1675*7c478bd9Sstevel@tonic-gate /* 1676*7c478bd9Sstevel@tonic-gate * FUNCTION: add_column 1677*7c478bd9Sstevel@tonic-gate * 1678*7c478bd9Sstevel@tonic-gate * Adds a column name to the column list in __nis_table_mapping_t 1679*7c478bd9Sstevel@tonic-gate * 1680*7c478bd9Sstevel@tonic-gate * RETURN VALUE: FALSE if error 1681*7c478bd9Sstevel@tonic-gate * TRUE if __nis_index_t returned 1682*7c478bd9Sstevel@tonic-gate * 1683*7c478bd9Sstevel@tonic-gate * INPUT: the __nis_table_mapping_t and column name 1684*7c478bd9Sstevel@tonic-gate */ 1685*7c478bd9Sstevel@tonic-gate 1686*7c478bd9Sstevel@tonic-gate bool_t 1687*7c478bd9Sstevel@tonic-gate add_column(__nis_table_mapping_t *t, const char *col_name) 1688*7c478bd9Sstevel@tonic-gate { 1689*7c478bd9Sstevel@tonic-gate int i; 1690*7c478bd9Sstevel@tonic-gate char **cols = NULL; 1691*7c478bd9Sstevel@tonic-gate 1692*7c478bd9Sstevel@tonic-gate if (!yp2ldap) { 1693*7c478bd9Sstevel@tonic-gate for (i = 0; i < t->numColumns; i++) { 1694*7c478bd9Sstevel@tonic-gate if (strcasecmp(col_name, t->column[i]) == 0) 1695*7c478bd9Sstevel@tonic-gate return (TRUE); 1696*7c478bd9Sstevel@tonic-gate } 1697*7c478bd9Sstevel@tonic-gate } 1698*7c478bd9Sstevel@tonic-gate cols = (char **)s_realloc(t->column, (t->numColumns + 1) * 1699*7c478bd9Sstevel@tonic-gate sizeof (char *)); 1700*7c478bd9Sstevel@tonic-gate if (cols == NULL) 1701*7c478bd9Sstevel@tonic-gate return (FALSE); 1702*7c478bd9Sstevel@tonic-gate t->column = cols; 1703*7c478bd9Sstevel@tonic-gate cols[t->numColumns] = s_strdup(col_name); 1704*7c478bd9Sstevel@tonic-gate if (cols[t->numColumns] == NULL) 1705*7c478bd9Sstevel@tonic-gate return (FALSE); 1706*7c478bd9Sstevel@tonic-gate t->numColumns++; 1707*7c478bd9Sstevel@tonic-gate return (TRUE); 1708*7c478bd9Sstevel@tonic-gate } 1709*7c478bd9Sstevel@tonic-gate 1710*7c478bd9Sstevel@tonic-gate /* 1711*7c478bd9Sstevel@tonic-gate * FUNCTION: add_element 1712*7c478bd9Sstevel@tonic-gate * 1713*7c478bd9Sstevel@tonic-gate * Adds a __nis_mapping_element_t to __nis_mapping_rlhs_t 1714*7c478bd9Sstevel@tonic-gate * 1715*7c478bd9Sstevel@tonic-gate * RETURN VALUE: FALSE if error 1716*7c478bd9Sstevel@tonic-gate * TRUE if __nis_index_t returned 1717*7c478bd9Sstevel@tonic-gate * 1718*7c478bd9Sstevel@tonic-gate * INPUT: the __nis_mapping_element_t and 1719*7c478bd9Sstevel@tonic-gate * __nis_mapping_rlhs_t 1720*7c478bd9Sstevel@tonic-gate */ 1721*7c478bd9Sstevel@tonic-gate 1722*7c478bd9Sstevel@tonic-gate bool_t 1723*7c478bd9Sstevel@tonic-gate add_element( 1724*7c478bd9Sstevel@tonic-gate __nis_mapping_element_t *e, 1725*7c478bd9Sstevel@tonic-gate __nis_mapping_rlhs_t *m) 1726*7c478bd9Sstevel@tonic-gate { 1727*7c478bd9Sstevel@tonic-gate __nis_mapping_element_t *e1; 1728*7c478bd9Sstevel@tonic-gate int i; 1729*7c478bd9Sstevel@tonic-gate int n = m->numElements; 1730*7c478bd9Sstevel@tonic-gate 1731*7c478bd9Sstevel@tonic-gate e1 = (__nis_mapping_element_t *)s_realloc(m->element, 1732*7c478bd9Sstevel@tonic-gate (n + 1) * sizeof (__nis_mapping_element_t)); 1733*7c478bd9Sstevel@tonic-gate if (e1 == NULL) { 1734*7c478bd9Sstevel@tonic-gate e1 = m->element; 1735*7c478bd9Sstevel@tonic-gate for (i = 0; i < n; i++) 1736*7c478bd9Sstevel@tonic-gate free_mapping_element(e1++); 1737*7c478bd9Sstevel@tonic-gate if (m->element != NULL) 1738*7c478bd9Sstevel@tonic-gate free(m->element); 1739*7c478bd9Sstevel@tonic-gate m->element = NULL; 1740*7c478bd9Sstevel@tonic-gate m->numElements = 0; 1741*7c478bd9Sstevel@tonic-gate } else { 1742*7c478bd9Sstevel@tonic-gate e1[m->numElements++] = *e; 1743*7c478bd9Sstevel@tonic-gate free(e); 1744*7c478bd9Sstevel@tonic-gate m->element = (__nis_mapping_element_t *)e1; 1745*7c478bd9Sstevel@tonic-gate } 1746*7c478bd9Sstevel@tonic-gate return (e1 != NULL); 1747*7c478bd9Sstevel@tonic-gate } 1748*7c478bd9Sstevel@tonic-gate 1749*7c478bd9Sstevel@tonic-gate /* 1750*7c478bd9Sstevel@tonic-gate * FUNCTION: get_next_object_dn_token 1751*7c478bd9Sstevel@tonic-gate * 1752*7c478bd9Sstevel@tonic-gate * Get the next token in parsing object_dn 1753*7c478bd9Sstevel@tonic-gate * 1754*7c478bd9Sstevel@tonic-gate * RETURN VALUE: NULL if error 1755*7c478bd9Sstevel@tonic-gate * position of beginning next token after 1756*7c478bd9Sstevel@tonic-gate * token 1757*7c478bd9Sstevel@tonic-gate * 1758*7c478bd9Sstevel@tonic-gate * INPUT: the attribute value 1759*7c478bd9Sstevel@tonic-gate */ 1760*7c478bd9Sstevel@tonic-gate 1761*7c478bd9Sstevel@tonic-gate const char * 1762*7c478bd9Sstevel@tonic-gate get_next_object_dn_token( 1763*7c478bd9Sstevel@tonic-gate const char **begin_ret, 1764*7c478bd9Sstevel@tonic-gate const char **end_ret, 1765*7c478bd9Sstevel@tonic-gate object_dn_token *token) 1766*7c478bd9Sstevel@tonic-gate { 1767*7c478bd9Sstevel@tonic-gate object_dn_token t = dn_no_token; 1768*7c478bd9Sstevel@tonic-gate const char *s = *begin_ret; 1769*7c478bd9Sstevel@tonic-gate const char *begin; 1770*7c478bd9Sstevel@tonic-gate const char *end = *end_ret; 1771*7c478bd9Sstevel@tonic-gate const char *s1; 1772*7c478bd9Sstevel@tonic-gate bool_t in_quotes; 1773*7c478bd9Sstevel@tonic-gate 1774*7c478bd9Sstevel@tonic-gate while (s < end && is_whitespace(*s)) 1775*7c478bd9Sstevel@tonic-gate s++; 1776*7c478bd9Sstevel@tonic-gate if (s >= end) { 1777*7c478bd9Sstevel@tonic-gate /* EMPTY */ 1778*7c478bd9Sstevel@tonic-gate } else if (*s == SEMI_COLON_CHAR) { 1779*7c478bd9Sstevel@tonic-gate t = dn_semi_token; 1780*7c478bd9Sstevel@tonic-gate s++; 1781*7c478bd9Sstevel@tonic-gate } else if (*s == QUESTION_MARK) { 1782*7c478bd9Sstevel@tonic-gate t = dn_ques_token; 1783*7c478bd9Sstevel@tonic-gate s++; 1784*7c478bd9Sstevel@tonic-gate } else if (*s == COLON_CHAR) { 1785*7c478bd9Sstevel@tonic-gate t = dn_colon_token; 1786*7c478bd9Sstevel@tonic-gate s++; 1787*7c478bd9Sstevel@tonic-gate } else if (*s == OPEN_PAREN_CHAR) { 1788*7c478bd9Sstevel@tonic-gate begin = s; 1789*7c478bd9Sstevel@tonic-gate s = get_ldap_filter(&begin, &end); 1790*7c478bd9Sstevel@tonic-gate if (s != NULL) { 1791*7c478bd9Sstevel@tonic-gate t = dn_text_token; 1792*7c478bd9Sstevel@tonic-gate *begin_ret = begin; 1793*7c478bd9Sstevel@tonic-gate *end_ret = end; 1794*7c478bd9Sstevel@tonic-gate } 1795*7c478bd9Sstevel@tonic-gate } else { 1796*7c478bd9Sstevel@tonic-gate begin = s; 1797*7c478bd9Sstevel@tonic-gate in_quotes = FALSE; 1798*7c478bd9Sstevel@tonic-gate while (s < end) { 1799*7c478bd9Sstevel@tonic-gate if (*s == ESCAPE_CHAR) { 1800*7c478bd9Sstevel@tonic-gate if (s + 2 > end) { 1801*7c478bd9Sstevel@tonic-gate p_error = parse_unmatched_escape; 1802*7c478bd9Sstevel@tonic-gate s = NULL; 1803*7c478bd9Sstevel@tonic-gate break; 1804*7c478bd9Sstevel@tonic-gate } 1805*7c478bd9Sstevel@tonic-gate s++; 1806*7c478bd9Sstevel@tonic-gate } else if (*s == DOUBLE_QUOTE_CHAR) { 1807*7c478bd9Sstevel@tonic-gate in_quotes = ! in_quotes; 1808*7c478bd9Sstevel@tonic-gate } else if (in_quotes) 1809*7c478bd9Sstevel@tonic-gate ; 1810*7c478bd9Sstevel@tonic-gate else if (*s == SEMI_COLON_CHAR || 1811*7c478bd9Sstevel@tonic-gate *s == QUESTION_MARK || 1812*7c478bd9Sstevel@tonic-gate *s == COLON_CHAR) 1813*7c478bd9Sstevel@tonic-gate break; 1814*7c478bd9Sstevel@tonic-gate s++; 1815*7c478bd9Sstevel@tonic-gate } 1816*7c478bd9Sstevel@tonic-gate if (s != NULL) { 1817*7c478bd9Sstevel@tonic-gate s1 = s - 1; 1818*7c478bd9Sstevel@tonic-gate while (is_whitespace(*s1)) 1819*7c478bd9Sstevel@tonic-gate s1--; 1820*7c478bd9Sstevel@tonic-gate s1++; 1821*7c478bd9Sstevel@tonic-gate if (same_string("base", begin, s1 - begin)) 1822*7c478bd9Sstevel@tonic-gate t = dn_base_token; 1823*7c478bd9Sstevel@tonic-gate else if (same_string("one", begin, s1 - begin)) 1824*7c478bd9Sstevel@tonic-gate t = dn_one_token; 1825*7c478bd9Sstevel@tonic-gate else if (same_string("sub", begin, s1 - begin)) 1826*7c478bd9Sstevel@tonic-gate t = dn_sub_token; 1827*7c478bd9Sstevel@tonic-gate else 1828*7c478bd9Sstevel@tonic-gate t = dn_text_token; 1829*7c478bd9Sstevel@tonic-gate *begin_ret = begin; 1830*7c478bd9Sstevel@tonic-gate *end_ret = s1; 1831*7c478bd9Sstevel@tonic-gate } 1832*7c478bd9Sstevel@tonic-gate } 1833*7c478bd9Sstevel@tonic-gate *token = t; 1834*7c478bd9Sstevel@tonic-gate return (s); 1835*7c478bd9Sstevel@tonic-gate } 1836*7c478bd9Sstevel@tonic-gate 1837*7c478bd9Sstevel@tonic-gate /* 1838*7c478bd9Sstevel@tonic-gate * FUNCTION: get_next_token 1839*7c478bd9Sstevel@tonic-gate * 1840*7c478bd9Sstevel@tonic-gate * Get the next token in parsing mapping attribute 1841*7c478bd9Sstevel@tonic-gate * 1842*7c478bd9Sstevel@tonic-gate * RETURN VALUE: NULL if error 1843*7c478bd9Sstevel@tonic-gate * position of beginning next token after 1844*7c478bd9Sstevel@tonic-gate * token 1845*7c478bd9Sstevel@tonic-gate * 1846*7c478bd9Sstevel@tonic-gate * INPUT: the attribute value 1847*7c478bd9Sstevel@tonic-gate */ 1848*7c478bd9Sstevel@tonic-gate 1849*7c478bd9Sstevel@tonic-gate const char * 1850*7c478bd9Sstevel@tonic-gate get_next_token(const char **begin_token, const char **end_token, token_type *t) 1851*7c478bd9Sstevel@tonic-gate { 1852*7c478bd9Sstevel@tonic-gate const char *s = *begin_token; 1853*7c478bd9Sstevel@tonic-gate const char *end_s = *end_token; 1854*7c478bd9Sstevel@tonic-gate const char *s_begin; 1855*7c478bd9Sstevel@tonic-gate 1856*7c478bd9Sstevel@tonic-gate while (s < end_s && is_whitespace(*s)) 1857*7c478bd9Sstevel@tonic-gate s++; 1858*7c478bd9Sstevel@tonic-gate if (s == end_s) { 1859*7c478bd9Sstevel@tonic-gate *t = no_token; 1860*7c478bd9Sstevel@tonic-gate return (s); 1861*7c478bd9Sstevel@tonic-gate } 1862*7c478bd9Sstevel@tonic-gate 1863*7c478bd9Sstevel@tonic-gate s_begin = s; 1864*7c478bd9Sstevel@tonic-gate 1865*7c478bd9Sstevel@tonic-gate if (*s == OPEN_PAREN_CHAR) { 1866*7c478bd9Sstevel@tonic-gate *begin_token = s; 1867*7c478bd9Sstevel@tonic-gate s++; 1868*7c478bd9Sstevel@tonic-gate *end_token = s; 1869*7c478bd9Sstevel@tonic-gate while (s < end_s && is_whitespace(*s)) 1870*7c478bd9Sstevel@tonic-gate s++; 1871*7c478bd9Sstevel@tonic-gate *t = open_paren_token; 1872*7c478bd9Sstevel@tonic-gate } else if (*s == DOUBLE_QUOTE_CHAR) { 1873*7c478bd9Sstevel@tonic-gate s++; 1874*7c478bd9Sstevel@tonic-gate while (s < end_s) { 1875*7c478bd9Sstevel@tonic-gate if (*s == ESCAPE_CHAR) 1876*7c478bd9Sstevel@tonic-gate s += 2; 1877*7c478bd9Sstevel@tonic-gate else if (*s == DOUBLE_QUOTE_CHAR) 1878*7c478bd9Sstevel@tonic-gate break; 1879*7c478bd9Sstevel@tonic-gate else 1880*7c478bd9Sstevel@tonic-gate s++; 1881*7c478bd9Sstevel@tonic-gate } 1882*7c478bd9Sstevel@tonic-gate if (s >= end_s) { 1883*7c478bd9Sstevel@tonic-gate p_error = parse_unmatched_escape; 1884*7c478bd9Sstevel@tonic-gate return (NULL); 1885*7c478bd9Sstevel@tonic-gate } 1886*7c478bd9Sstevel@tonic-gate 1887*7c478bd9Sstevel@tonic-gate *t = quoted_string_token; 1888*7c478bd9Sstevel@tonic-gate *begin_token = s_begin + 1; 1889*7c478bd9Sstevel@tonic-gate *end_token = s++; 1890*7c478bd9Sstevel@tonic-gate } else if (*s == EQUAL_CHAR || *s == COMMA_CHAR || 1891*7c478bd9Sstevel@tonic-gate *s == CLOSE_PAREN_CHAR || *s == COLON_CHAR) { 1892*7c478bd9Sstevel@tonic-gate if (*s == EQUAL_CHAR) 1893*7c478bd9Sstevel@tonic-gate *t = equal_token; 1894*7c478bd9Sstevel@tonic-gate else if (*s == COMMA_CHAR) 1895*7c478bd9Sstevel@tonic-gate *t = comma_token; 1896*7c478bd9Sstevel@tonic-gate else if (*s == CLOSE_PAREN_CHAR) 1897*7c478bd9Sstevel@tonic-gate *t = close_paren_token; 1898*7c478bd9Sstevel@tonic-gate else 1899*7c478bd9Sstevel@tonic-gate *t = colon_token; 1900*7c478bd9Sstevel@tonic-gate *begin_token = s; 1901*7c478bd9Sstevel@tonic-gate *end_token = ++s; 1902*7c478bd9Sstevel@tonic-gate } else { 1903*7c478bd9Sstevel@tonic-gate s_begin = s; 1904*7c478bd9Sstevel@tonic-gate while (s < end_s && !is_whitespace(*s)) { 1905*7c478bd9Sstevel@tonic-gate if (*s == ESCAPE_CHAR) 1906*7c478bd9Sstevel@tonic-gate s += 2; 1907*7c478bd9Sstevel@tonic-gate else if (*s == EQUAL_CHAR || *s == CLOSE_PAREN_CHAR || 1908*7c478bd9Sstevel@tonic-gate *s == OPEN_PAREN_CHAR || *s == COMMA_CHAR || 1909*7c478bd9Sstevel@tonic-gate *s == COLON_CHAR || *s == OPEN_BRACKET || 1910*7c478bd9Sstevel@tonic-gate *s == CLOSE_BRACKET) 1911*7c478bd9Sstevel@tonic-gate break; 1912*7c478bd9Sstevel@tonic-gate else 1913*7c478bd9Sstevel@tonic-gate s++; 1914*7c478bd9Sstevel@tonic-gate } 1915*7c478bd9Sstevel@tonic-gate if (s > end_s) { 1916*7c478bd9Sstevel@tonic-gate p_error = parse_unmatched_escape; 1917*7c478bd9Sstevel@tonic-gate return (NULL); 1918*7c478bd9Sstevel@tonic-gate } 1919*7c478bd9Sstevel@tonic-gate *t = string_token; 1920*7c478bd9Sstevel@tonic-gate *end_token = s; 1921*7c478bd9Sstevel@tonic-gate *begin_token = s_begin; 1922*7c478bd9Sstevel@tonic-gate } 1923*7c478bd9Sstevel@tonic-gate if (s) { 1924*7c478bd9Sstevel@tonic-gate while (s < end_s && is_whitespace(*s)) 1925*7c478bd9Sstevel@tonic-gate s++; 1926*7c478bd9Sstevel@tonic-gate } 1927*7c478bd9Sstevel@tonic-gate return (s); 1928*7c478bd9Sstevel@tonic-gate } 1929*7c478bd9Sstevel@tonic-gate 1930*7c478bd9Sstevel@tonic-gate /* 1931*7c478bd9Sstevel@tonic-gate * FUNCTION: skip_token 1932*7c478bd9Sstevel@tonic-gate * 1933*7c478bd9Sstevel@tonic-gate * Skip over the specified token - An error is set if 1934*7c478bd9Sstevel@tonic-gate * next token does not match expected token 1935*7c478bd9Sstevel@tonic-gate * 1936*7c478bd9Sstevel@tonic-gate * RETURN VALUE: NULL if error 1937*7c478bd9Sstevel@tonic-gate * position of beginning next token after 1938*7c478bd9Sstevel@tonic-gate * token 1939*7c478bd9Sstevel@tonic-gate * 1940*7c478bd9Sstevel@tonic-gate * INPUT: the attribute value 1941*7c478bd9Sstevel@tonic-gate */ 1942*7c478bd9Sstevel@tonic-gate 1943*7c478bd9Sstevel@tonic-gate const char * 1944*7c478bd9Sstevel@tonic-gate skip_token(const char *s, const char *end_s, token_type t) 1945*7c478bd9Sstevel@tonic-gate { 1946*7c478bd9Sstevel@tonic-gate bool_t match; 1947*7c478bd9Sstevel@tonic-gate char c = 0; 1948*7c478bd9Sstevel@tonic-gate 1949*7c478bd9Sstevel@tonic-gate if (s == NULL) 1950*7c478bd9Sstevel@tonic-gate return (s); 1951*7c478bd9Sstevel@tonic-gate while (s < end_s && is_whitespace(*s)) 1952*7c478bd9Sstevel@tonic-gate s++; 1953*7c478bd9Sstevel@tonic-gate c = (s == end_s) ? 0 : *s; 1954*7c478bd9Sstevel@tonic-gate switch (t) { 1955*7c478bd9Sstevel@tonic-gate case equal_token: 1956*7c478bd9Sstevel@tonic-gate match = c == EQUAL_CHAR; 1957*7c478bd9Sstevel@tonic-gate if (!match) 1958*7c478bd9Sstevel@tonic-gate p_error = parse_equal_expected_error; 1959*7c478bd9Sstevel@tonic-gate break; 1960*7c478bd9Sstevel@tonic-gate case comma_token: 1961*7c478bd9Sstevel@tonic-gate match = c == COMMA_CHAR; 1962*7c478bd9Sstevel@tonic-gate if (!match) 1963*7c478bd9Sstevel@tonic-gate p_error = parse_comma_expected_error; 1964*7c478bd9Sstevel@tonic-gate break; 1965*7c478bd9Sstevel@tonic-gate case close_paren_token: 1966*7c478bd9Sstevel@tonic-gate match = c == CLOSE_PAREN_CHAR; 1967*7c478bd9Sstevel@tonic-gate if (!match) 1968*7c478bd9Sstevel@tonic-gate p_error = parse_close_paren_expected_error; 1969*7c478bd9Sstevel@tonic-gate break; 1970*7c478bd9Sstevel@tonic-gate default: 1971*7c478bd9Sstevel@tonic-gate match = FALSE; 1972*7c478bd9Sstevel@tonic-gate break; 1973*7c478bd9Sstevel@tonic-gate } 1974*7c478bd9Sstevel@tonic-gate if (match) { 1975*7c478bd9Sstevel@tonic-gate s++; 1976*7c478bd9Sstevel@tonic-gate while (s < end_s && is_whitespace(*s)) 1977*7c478bd9Sstevel@tonic-gate s++; 1978*7c478bd9Sstevel@tonic-gate } else { 1979*7c478bd9Sstevel@tonic-gate s = NULL; 1980*7c478bd9Sstevel@tonic-gate } 1981*7c478bd9Sstevel@tonic-gate return (s); 1982*7c478bd9Sstevel@tonic-gate } 1983*7c478bd9Sstevel@tonic-gate 1984*7c478bd9Sstevel@tonic-gate /* 1985*7c478bd9Sstevel@tonic-gate * FUNCTION: get_next_extract_format_item 1986*7c478bd9Sstevel@tonic-gate * 1987*7c478bd9Sstevel@tonic-gate * Get the next format token from the string. Note that 1988*7c478bd9Sstevel@tonic-gate * get_next_extract_format_item may change the input string. 1989*7c478bd9Sstevel@tonic-gate * 1990*7c478bd9Sstevel@tonic-gate * RETURN VALUE: NULL if error 1991*7c478bd9Sstevel@tonic-gate * position of beginning next token after 1992*7c478bd9Sstevel@tonic-gate * token 1993*7c478bd9Sstevel@tonic-gate * 1994*7c478bd9Sstevel@tonic-gate * INPUT: the format string 1995*7c478bd9Sstevel@tonic-gate */ 1996*7c478bd9Sstevel@tonic-gate 1997*7c478bd9Sstevel@tonic-gate const char * 1998*7c478bd9Sstevel@tonic-gate get_next_extract_format_item( 1999*7c478bd9Sstevel@tonic-gate const char *begin_fmt, 2000*7c478bd9Sstevel@tonic-gate const char *end_fmt, 2001*7c478bd9Sstevel@tonic-gate __nis_mapping_format_t *fmt) 2002*7c478bd9Sstevel@tonic-gate { 2003*7c478bd9Sstevel@tonic-gate const char *s = begin_fmt; 2004*7c478bd9Sstevel@tonic-gate const char *s_end = end_fmt; 2005*7c478bd9Sstevel@tonic-gate bool_t escape; 2006*7c478bd9Sstevel@tonic-gate bool_t in_range; 2007*7c478bd9Sstevel@tonic-gate bool_t got_char; 2008*7c478bd9Sstevel@tonic-gate bool_t done; 2009*7c478bd9Sstevel@tonic-gate int numRange; 2010*7c478bd9Sstevel@tonic-gate char *lo = NULL; 2011*7c478bd9Sstevel@tonic-gate char *hi = NULL; 2012*7c478bd9Sstevel@tonic-gate bool_t skip_ber; 2013*7c478bd9Sstevel@tonic-gate 2014*7c478bd9Sstevel@tonic-gate for (; p_error == no_parse_error; ) { 2015*7c478bd9Sstevel@tonic-gate if (s >= s_end) 2016*7c478bd9Sstevel@tonic-gate break; 2017*7c478bd9Sstevel@tonic-gate 2018*7c478bd9Sstevel@tonic-gate if (*s == PERCENT_SIGN) { 2019*7c478bd9Sstevel@tonic-gate s++; 2020*7c478bd9Sstevel@tonic-gate /* 2021*7c478bd9Sstevel@tonic-gate * If the format is %s, it is interpreted 2022*7c478bd9Sstevel@tonic-gate * as a string. 2023*7c478bd9Sstevel@tonic-gate */ 2024*7c478bd9Sstevel@tonic-gate if (s >= s_end) { 2025*7c478bd9Sstevel@tonic-gate p_error = parse_unsupported_format; 2026*7c478bd9Sstevel@tonic-gate break; 2027*7c478bd9Sstevel@tonic-gate } 2028*7c478bd9Sstevel@tonic-gate skip_ber = FALSE; 2029*7c478bd9Sstevel@tonic-gate switch (*s) { 2030*7c478bd9Sstevel@tonic-gate case 's': 2031*7c478bd9Sstevel@tonic-gate fmt->type = mmt_item; 2032*7c478bd9Sstevel@tonic-gate break; 2033*7c478bd9Sstevel@tonic-gate case 'n': /* null */ 2034*7c478bd9Sstevel@tonic-gate case 'x': /* skip the next element */ 2035*7c478bd9Sstevel@tonic-gate skip_ber = TRUE; 2036*7c478bd9Sstevel@tonic-gate /* FALLTHRU */ 2037*7c478bd9Sstevel@tonic-gate case 'b': /* boolean */ 2038*7c478bd9Sstevel@tonic-gate case 'e': /* enumerated */ 2039*7c478bd9Sstevel@tonic-gate case 'i': /* int */ 2040*7c478bd9Sstevel@tonic-gate case 'o': /* octet string */ 2041*7c478bd9Sstevel@tonic-gate case 'B': /* bit string */ 2042*7c478bd9Sstevel@tonic-gate fmt->match.berString = s_strndup(s, 1); 2043*7c478bd9Sstevel@tonic-gate fmt->type = skip_ber ? 2044*7c478bd9Sstevel@tonic-gate mmt_berstring_null : 2045*7c478bd9Sstevel@tonic-gate mmt_berstring; 2046*7c478bd9Sstevel@tonic-gate break; 2047*7c478bd9Sstevel@tonic-gate case 'a': /* octet string */ 2048*7c478bd9Sstevel@tonic-gate if (yp2ldap) { 2049*7c478bd9Sstevel@tonic-gate fmt->match.berString = 2050*7c478bd9Sstevel@tonic-gate s_strndup(s, 1); 2051*7c478bd9Sstevel@tonic-gate fmt->type = skip_ber ? 2052*7c478bd9Sstevel@tonic-gate mmt_berstring_null : 2053*7c478bd9Sstevel@tonic-gate mmt_berstring; 2054*7c478bd9Sstevel@tonic-gate break; 2055*7c478bd9Sstevel@tonic-gate } /* else FALLTHRU */ 2056*7c478bd9Sstevel@tonic-gate case '{': /* begin sequence */ 2057*7c478bd9Sstevel@tonic-gate case '[': /* begin set */ 2058*7c478bd9Sstevel@tonic-gate case '}': /* end sequence */ 2059*7c478bd9Sstevel@tonic-gate case ']': /* end set */ 2060*7c478bd9Sstevel@tonic-gate case 'l': /* length of next item */ 2061*7c478bd9Sstevel@tonic-gate case 'O': /* octet string */ 2062*7c478bd9Sstevel@tonic-gate case 't': /* tag of next item */ 2063*7c478bd9Sstevel@tonic-gate case 'T': /* skip tag of next item */ 2064*7c478bd9Sstevel@tonic-gate case 'v': /* seq of strings */ 2065*7c478bd9Sstevel@tonic-gate case 'V': /* seq of strings + lengths */ 2066*7c478bd9Sstevel@tonic-gate default: 2067*7c478bd9Sstevel@tonic-gate p_error = parse_bad_ber_format; 2068*7c478bd9Sstevel@tonic-gate break; 2069*7c478bd9Sstevel@tonic-gate } 2070*7c478bd9Sstevel@tonic-gate s++; 2071*7c478bd9Sstevel@tonic-gate } else if (*s == ASTERIX_CHAR) { 2072*7c478bd9Sstevel@tonic-gate fmt->type = mmt_any; 2073*7c478bd9Sstevel@tonic-gate s++; 2074*7c478bd9Sstevel@tonic-gate while (s < s_end && *s == ASTERIX_CHAR) 2075*7c478bd9Sstevel@tonic-gate s++; 2076*7c478bd9Sstevel@tonic-gate 2077*7c478bd9Sstevel@tonic-gate } else if (*s == OPEN_BRACKET) { 2078*7c478bd9Sstevel@tonic-gate escape = FALSE; 2079*7c478bd9Sstevel@tonic-gate in_range = FALSE; 2080*7c478bd9Sstevel@tonic-gate got_char = FALSE; 2081*7c478bd9Sstevel@tonic-gate numRange = 0; 2082*7c478bd9Sstevel@tonic-gate done = FALSE; 2083*7c478bd9Sstevel@tonic-gate s++; 2084*7c478bd9Sstevel@tonic-gate for (; s < s_end; s++) { 2085*7c478bd9Sstevel@tonic-gate if (escape) { 2086*7c478bd9Sstevel@tonic-gate escape = FALSE; 2087*7c478bd9Sstevel@tonic-gate } else if (*s == DASH_CHAR) { 2088*7c478bd9Sstevel@tonic-gate if (in_range || !got_char) { 2089*7c478bd9Sstevel@tonic-gate p_error = parse_unexpected_dash; 2090*7c478bd9Sstevel@tonic-gate break; 2091*7c478bd9Sstevel@tonic-gate } 2092*7c478bd9Sstevel@tonic-gate in_range = TRUE; 2093*7c478bd9Sstevel@tonic-gate got_char = FALSE; 2094*7c478bd9Sstevel@tonic-gate continue; 2095*7c478bd9Sstevel@tonic-gate } else if (*s == CLOSE_BRACKET) { 2096*7c478bd9Sstevel@tonic-gate if (in_range) { 2097*7c478bd9Sstevel@tonic-gate p_error = parse_unexpected_dash; 2098*7c478bd9Sstevel@tonic-gate } 2099*7c478bd9Sstevel@tonic-gate done = TRUE; 2100*7c478bd9Sstevel@tonic-gate break; 2101*7c478bd9Sstevel@tonic-gate } else if (*s == ESCAPE_CHAR) { 2102*7c478bd9Sstevel@tonic-gate escape = TRUE; 2103*7c478bd9Sstevel@tonic-gate continue; 2104*7c478bd9Sstevel@tonic-gate } 2105*7c478bd9Sstevel@tonic-gate if (in_range) { 2106*7c478bd9Sstevel@tonic-gate hi[numRange - 1] = *s; 2107*7c478bd9Sstevel@tonic-gate in_range = FALSE; 2108*7c478bd9Sstevel@tonic-gate } else { 2109*7c478bd9Sstevel@tonic-gate lo = s_realloc(lo, numRange + 1); 2110*7c478bd9Sstevel@tonic-gate hi = s_realloc(hi, numRange + 1); 2111*7c478bd9Sstevel@tonic-gate if (lo == NULL || hi == NULL) 2112*7c478bd9Sstevel@tonic-gate break; 2113*7c478bd9Sstevel@tonic-gate lo[numRange] = *s; 2114*7c478bd9Sstevel@tonic-gate hi[numRange] = *s; 2115*7c478bd9Sstevel@tonic-gate numRange++; 2116*7c478bd9Sstevel@tonic-gate got_char = TRUE; 2117*7c478bd9Sstevel@tonic-gate } 2118*7c478bd9Sstevel@tonic-gate } 2119*7c478bd9Sstevel@tonic-gate if (p_error != no_parse_error) { 2120*7c478bd9Sstevel@tonic-gate break; 2121*7c478bd9Sstevel@tonic-gate } else if (!done) { 2122*7c478bd9Sstevel@tonic-gate p_error = parse_mismatched_brackets; 2123*7c478bd9Sstevel@tonic-gate break; 2124*7c478bd9Sstevel@tonic-gate } 2125*7c478bd9Sstevel@tonic-gate s++; 2126*7c478bd9Sstevel@tonic-gate fmt->type = mmt_single; 2127*7c478bd9Sstevel@tonic-gate fmt->match.single.numRange = numRange; 2128*7c478bd9Sstevel@tonic-gate fmt->match.single.lo = (unsigned char *)lo; 2129*7c478bd9Sstevel@tonic-gate fmt->match.single.hi = (unsigned char *)hi; 2130*7c478bd9Sstevel@tonic-gate } else { 2131*7c478bd9Sstevel@tonic-gate /* go to next key symbol - copy escaped key symbols */ 2132*7c478bd9Sstevel@tonic-gate escape = FALSE; 2133*7c478bd9Sstevel@tonic-gate done = FALSE; 2134*7c478bd9Sstevel@tonic-gate while (s < s_end) { 2135*7c478bd9Sstevel@tonic-gate if (escape) 2136*7c478bd9Sstevel@tonic-gate escape = FALSE; 2137*7c478bd9Sstevel@tonic-gate else { 2138*7c478bd9Sstevel@tonic-gate switch (*s) { 2139*7c478bd9Sstevel@tonic-gate case OPEN_BRACKET: 2140*7c478bd9Sstevel@tonic-gate case ASTERIX_CHAR: 2141*7c478bd9Sstevel@tonic-gate case PERCENT_SIGN: 2142*7c478bd9Sstevel@tonic-gate done = TRUE; 2143*7c478bd9Sstevel@tonic-gate break; 2144*7c478bd9Sstevel@tonic-gate case ESCAPE_CHAR: 2145*7c478bd9Sstevel@tonic-gate escape = !escape; 2146*7c478bd9Sstevel@tonic-gate break; 2147*7c478bd9Sstevel@tonic-gate default: 2148*7c478bd9Sstevel@tonic-gate break; 2149*7c478bd9Sstevel@tonic-gate } 2150*7c478bd9Sstevel@tonic-gate } 2151*7c478bd9Sstevel@tonic-gate if (done) 2152*7c478bd9Sstevel@tonic-gate break; 2153*7c478bd9Sstevel@tonic-gate s++; 2154*7c478bd9Sstevel@tonic-gate } 2155*7c478bd9Sstevel@tonic-gate if (escape) { 2156*7c478bd9Sstevel@tonic-gate p_error = parse_unmatched_escape; 2157*7c478bd9Sstevel@tonic-gate break; 2158*7c478bd9Sstevel@tonic-gate } 2159*7c478bd9Sstevel@tonic-gate fmt->type = mmt_string; 2160*7c478bd9Sstevel@tonic-gate fmt->match.string = 2161*7c478bd9Sstevel@tonic-gate s_strndup_esc(begin_fmt, s - begin_fmt); 2162*7c478bd9Sstevel@tonic-gate if (fmt->match.string == NULL) 2163*7c478bd9Sstevel@tonic-gate break; 2164*7c478bd9Sstevel@tonic-gate } 2165*7c478bd9Sstevel@tonic-gate 2166*7c478bd9Sstevel@tonic-gate if (p_error == no_parse_error) 2167*7c478bd9Sstevel@tonic-gate return (s); 2168*7c478bd9Sstevel@tonic-gate } 2169*7c478bd9Sstevel@tonic-gate if (lo != NULL) 2170*7c478bd9Sstevel@tonic-gate free(lo); 2171*7c478bd9Sstevel@tonic-gate if (hi != NULL) 2172*7c478bd9Sstevel@tonic-gate free(hi); 2173*7c478bd9Sstevel@tonic-gate return (NULL); 2174*7c478bd9Sstevel@tonic-gate } 2175*7c478bd9Sstevel@tonic-gate 2176*7c478bd9Sstevel@tonic-gate /* 2177*7c478bd9Sstevel@tonic-gate * FUNCTION: get_next_print_format_item 2178*7c478bd9Sstevel@tonic-gate * 2179*7c478bd9Sstevel@tonic-gate * Get the next format token from the string 2180*7c478bd9Sstevel@tonic-gate * 2181*7c478bd9Sstevel@tonic-gate * RETURN VALUE: NULL if error 2182*7c478bd9Sstevel@tonic-gate * position of beginning next token after 2183*7c478bd9Sstevel@tonic-gate * token 2184*7c478bd9Sstevel@tonic-gate * 2185*7c478bd9Sstevel@tonic-gate * INPUT: the format string 2186*7c478bd9Sstevel@tonic-gate */ 2187*7c478bd9Sstevel@tonic-gate 2188*7c478bd9Sstevel@tonic-gate const char * 2189*7c478bd9Sstevel@tonic-gate get_next_print_format_item( 2190*7c478bd9Sstevel@tonic-gate const char *begin_fmt, 2191*7c478bd9Sstevel@tonic-gate const char *end_fmt, 2192*7c478bd9Sstevel@tonic-gate __nis_mapping_format_t *fmt) 2193*7c478bd9Sstevel@tonic-gate { 2194*7c478bd9Sstevel@tonic-gate const char *s = begin_fmt; 2195*7c478bd9Sstevel@tonic-gate const char *s_end = end_fmt; 2196*7c478bd9Sstevel@tonic-gate bool_t skip_ber; 2197*7c478bd9Sstevel@tonic-gate 2198*7c478bd9Sstevel@tonic-gate for (; p_error == no_parse_error; ) { 2199*7c478bd9Sstevel@tonic-gate if (s >= s_end) { 2200*7c478bd9Sstevel@tonic-gate p_error = parse_internal_error; 2201*7c478bd9Sstevel@tonic-gate break; 2202*7c478bd9Sstevel@tonic-gate } 2203*7c478bd9Sstevel@tonic-gate 2204*7c478bd9Sstevel@tonic-gate if (*s == PERCENT_SIGN) { 2205*7c478bd9Sstevel@tonic-gate s++; 2206*7c478bd9Sstevel@tonic-gate if (s >= s_end) { 2207*7c478bd9Sstevel@tonic-gate p_error = parse_unsupported_format; 2208*7c478bd9Sstevel@tonic-gate break; 2209*7c478bd9Sstevel@tonic-gate } 2210*7c478bd9Sstevel@tonic-gate skip_ber = FALSE; 2211*7c478bd9Sstevel@tonic-gate /* 2212*7c478bd9Sstevel@tonic-gate * If the format is %s, it is interpretted 2213*7c478bd9Sstevel@tonic-gate * as a string. 2214*7c478bd9Sstevel@tonic-gate */ 2215*7c478bd9Sstevel@tonic-gate switch (*s) { 2216*7c478bd9Sstevel@tonic-gate case 's': 2217*7c478bd9Sstevel@tonic-gate fmt->type = mmt_item; 2218*7c478bd9Sstevel@tonic-gate break; 2219*7c478bd9Sstevel@tonic-gate case 'n': /* null */ 2220*7c478bd9Sstevel@tonic-gate case 'x': /* skip the next element */ 2221*7c478bd9Sstevel@tonic-gate skip_ber = TRUE; 2222*7c478bd9Sstevel@tonic-gate /* FALLTHRU */ 2223*7c478bd9Sstevel@tonic-gate case 'b': /* boolean */ 2224*7c478bd9Sstevel@tonic-gate case 'e': /* enumerated */ 2225*7c478bd9Sstevel@tonic-gate case 'i': /* int */ 2226*7c478bd9Sstevel@tonic-gate case 'o': /* octet string */ 2227*7c478bd9Sstevel@tonic-gate case 'B': /* bit string */ 2228*7c478bd9Sstevel@tonic-gate fmt->match.berString = s_strndup(s, 1); 2229*7c478bd9Sstevel@tonic-gate fmt->type = skip_ber ? 2230*7c478bd9Sstevel@tonic-gate mmt_berstring_null : 2231*7c478bd9Sstevel@tonic-gate mmt_berstring; 2232*7c478bd9Sstevel@tonic-gate break; 2233*7c478bd9Sstevel@tonic-gate case '{': /* begin sequence */ 2234*7c478bd9Sstevel@tonic-gate case '[': /* begin set */ 2235*7c478bd9Sstevel@tonic-gate case '}': /* end sequence */ 2236*7c478bd9Sstevel@tonic-gate case ']': /* end set */ 2237*7c478bd9Sstevel@tonic-gate case 'a': /* octet string */ 2238*7c478bd9Sstevel@tonic-gate case 'l': /* length of next item */ 2239*7c478bd9Sstevel@tonic-gate case 'O': /* octet string */ 2240*7c478bd9Sstevel@tonic-gate case 't': /* tag of next item */ 2241*7c478bd9Sstevel@tonic-gate case 'T': /* skip tag of next item */ 2242*7c478bd9Sstevel@tonic-gate case 'v': /* seq of strings */ 2243*7c478bd9Sstevel@tonic-gate case 'V': /* seq of strings + lengths */ 2244*7c478bd9Sstevel@tonic-gate default: 2245*7c478bd9Sstevel@tonic-gate p_error = parse_bad_ber_format; 2246*7c478bd9Sstevel@tonic-gate break; 2247*7c478bd9Sstevel@tonic-gate } 2248*7c478bd9Sstevel@tonic-gate s++; 2249*7c478bd9Sstevel@tonic-gate } else { 2250*7c478bd9Sstevel@tonic-gate while (s < s_end) { 2251*7c478bd9Sstevel@tonic-gate if (*s == PERCENT_SIGN) 2252*7c478bd9Sstevel@tonic-gate break; 2253*7c478bd9Sstevel@tonic-gate else if (*s == ESCAPE_CHAR) 2254*7c478bd9Sstevel@tonic-gate s++; 2255*7c478bd9Sstevel@tonic-gate s++; 2256*7c478bd9Sstevel@tonic-gate } 2257*7c478bd9Sstevel@tonic-gate if (s > s_end) { 2258*7c478bd9Sstevel@tonic-gate p_error = parse_unmatched_escape; 2259*7c478bd9Sstevel@tonic-gate break; 2260*7c478bd9Sstevel@tonic-gate } 2261*7c478bd9Sstevel@tonic-gate fmt->match.string = 2262*7c478bd9Sstevel@tonic-gate s_strndup_esc(begin_fmt, s - begin_fmt); 2263*7c478bd9Sstevel@tonic-gate if (fmt->match.string == NULL) 2264*7c478bd9Sstevel@tonic-gate break; 2265*7c478bd9Sstevel@tonic-gate fmt->type = mmt_string; 2266*7c478bd9Sstevel@tonic-gate } 2267*7c478bd9Sstevel@tonic-gate if (p_error == no_parse_error) 2268*7c478bd9Sstevel@tonic-gate return (s); 2269*7c478bd9Sstevel@tonic-gate } 2270*7c478bd9Sstevel@tonic-gate return (NULL); 2271*7c478bd9Sstevel@tonic-gate } 2272*7c478bd9Sstevel@tonic-gate 2273*7c478bd9Sstevel@tonic-gate /* 2274*7c478bd9Sstevel@tonic-gate * FUNCTION: get_ldap_filter 2275*7c478bd9Sstevel@tonic-gate * 2276*7c478bd9Sstevel@tonic-gate * Gets an LDAP filter - see RFC 2254. Note that this does not 2277*7c478bd9Sstevel@tonic-gate * determine if the ldap filter is valid. This only determines 2278*7c478bd9Sstevel@tonic-gate * that the parentheses are balanced. 2279*7c478bd9Sstevel@tonic-gate * 2280*7c478bd9Sstevel@tonic-gate * RETURN VALUE: NULL if error 2281*7c478bd9Sstevel@tonic-gate * position of beginning next token after 2282*7c478bd9Sstevel@tonic-gate * filter 2283*7c478bd9Sstevel@tonic-gate * 2284*7c478bd9Sstevel@tonic-gate * INPUT: the begin and end of string 2285*7c478bd9Sstevel@tonic-gate * 2286*7c478bd9Sstevel@tonic-gate * OUTPUT: the begin and end of LDAP filter 2287*7c478bd9Sstevel@tonic-gate * 2288*7c478bd9Sstevel@tonic-gate */ 2289*7c478bd9Sstevel@tonic-gate 2290*7c478bd9Sstevel@tonic-gate const char * 2291*7c478bd9Sstevel@tonic-gate get_ldap_filter(const char **begin, const char **end) 2292*7c478bd9Sstevel@tonic-gate { 2293*7c478bd9Sstevel@tonic-gate const char *s = *begin; 2294*7c478bd9Sstevel@tonic-gate const char *s_begin; 2295*7c478bd9Sstevel@tonic-gate const char *s_end = *end; 2296*7c478bd9Sstevel@tonic-gate int nParen; 2297*7c478bd9Sstevel@tonic-gate 2298*7c478bd9Sstevel@tonic-gate for (; p_error == no_parse_error; ) { 2299*7c478bd9Sstevel@tonic-gate while (s < s_end && is_whitespace(*s)) 2300*7c478bd9Sstevel@tonic-gate s++; 2301*7c478bd9Sstevel@tonic-gate if (s == s_end) { 2302*7c478bd9Sstevel@tonic-gate s = NULL; 2303*7c478bd9Sstevel@tonic-gate break; 2304*7c478bd9Sstevel@tonic-gate } 2305*7c478bd9Sstevel@tonic-gate 2306*7c478bd9Sstevel@tonic-gate s_begin = s; 2307*7c478bd9Sstevel@tonic-gate if (*s == OPEN_PAREN_CHAR) { 2308*7c478bd9Sstevel@tonic-gate nParen = 1; 2309*7c478bd9Sstevel@tonic-gate s++; 2310*7c478bd9Sstevel@tonic-gate while (s < s_end && nParen > 0) { 2311*7c478bd9Sstevel@tonic-gate if (*s == ESCAPE_CHAR) 2312*7c478bd9Sstevel@tonic-gate s++; 2313*7c478bd9Sstevel@tonic-gate else if (*s == OPEN_PAREN_CHAR) 2314*7c478bd9Sstevel@tonic-gate nParen++; 2315*7c478bd9Sstevel@tonic-gate else if (*s == CLOSE_PAREN_CHAR) 2316*7c478bd9Sstevel@tonic-gate nParen--; 2317*7c478bd9Sstevel@tonic-gate s++; 2318*7c478bd9Sstevel@tonic-gate } 2319*7c478bd9Sstevel@tonic-gate if (nParen == 0) { 2320*7c478bd9Sstevel@tonic-gate *begin = s_begin; 2321*7c478bd9Sstevel@tonic-gate *end = s; 2322*7c478bd9Sstevel@tonic-gate while (s < s_end && is_whitespace(*s)) 2323*7c478bd9Sstevel@tonic-gate s++; 2324*7c478bd9Sstevel@tonic-gate } else 2325*7c478bd9Sstevel@tonic-gate s = NULL; 2326*7c478bd9Sstevel@tonic-gate } else 2327*7c478bd9Sstevel@tonic-gate s = NULL; 2328*7c478bd9Sstevel@tonic-gate if (p_error == no_parse_error) 2329*7c478bd9Sstevel@tonic-gate break; 2330*7c478bd9Sstevel@tonic-gate } 2331*7c478bd9Sstevel@tonic-gate if (s == NULL) 2332*7c478bd9Sstevel@tonic-gate p_error = parse_invalid_ldap_search_filter; 2333*7c478bd9Sstevel@tonic-gate 2334*7c478bd9Sstevel@tonic-gate return (s); 2335*7c478bd9Sstevel@tonic-gate } 2336*7c478bd9Sstevel@tonic-gate 2337*7c478bd9Sstevel@tonic-gate /* 2338*7c478bd9Sstevel@tonic-gate * FUNCTION: get_ava_list 2339*7c478bd9Sstevel@tonic-gate * 2340*7c478bd9Sstevel@tonic-gate * Gets an attribute value assertion list 2341*7c478bd9Sstevel@tonic-gate * 2342*7c478bd9Sstevel@tonic-gate * RETURN VALUE: NULL if error 2343*7c478bd9Sstevel@tonic-gate * position of beginning next token after 2344*7c478bd9Sstevel@tonic-gate * after attribute assertion 2345*7c478bd9Sstevel@tonic-gate * 2346*7c478bd9Sstevel@tonic-gate * INPUT: the begin and end of string 2347*7c478bd9Sstevel@tonic-gate * Indicator if ava list is part of a nisplus 2348*7c478bd9Sstevel@tonic-gate * item 2349*7c478bd9Sstevel@tonic-gate * 2350*7c478bd9Sstevel@tonic-gate * OUTPUT: the begin and end of LDAP filter 2351*7c478bd9Sstevel@tonic-gate * 2352*7c478bd9Sstevel@tonic-gate */ 2353*7c478bd9Sstevel@tonic-gate 2354*7c478bd9Sstevel@tonic-gate const char * 2355*7c478bd9Sstevel@tonic-gate get_ava_list(const char **begin, const char **end, bool_t end_nisplus) 2356*7c478bd9Sstevel@tonic-gate { 2357*7c478bd9Sstevel@tonic-gate const char *s = *begin; 2358*7c478bd9Sstevel@tonic-gate const char *s_begin; 2359*7c478bd9Sstevel@tonic-gate const char *s_end = *end; 2360*7c478bd9Sstevel@tonic-gate bool_t in_quote; 2361*7c478bd9Sstevel@tonic-gate bool_t got_equal; 2362*7c478bd9Sstevel@tonic-gate bool_t got_data; 2363*7c478bd9Sstevel@tonic-gate 2364*7c478bd9Sstevel@tonic-gate for (; p_error == no_parse_error; ) { 2365*7c478bd9Sstevel@tonic-gate while (s < s_end && is_whitespace(*s)) 2366*7c478bd9Sstevel@tonic-gate s++; 2367*7c478bd9Sstevel@tonic-gate if (s == s_end) { 2368*7c478bd9Sstevel@tonic-gate s = NULL; 2369*7c478bd9Sstevel@tonic-gate break; 2370*7c478bd9Sstevel@tonic-gate } 2371*7c478bd9Sstevel@tonic-gate 2372*7c478bd9Sstevel@tonic-gate in_quote = FALSE; 2373*7c478bd9Sstevel@tonic-gate got_equal = FALSE; 2374*7c478bd9Sstevel@tonic-gate got_data = FALSE; 2375*7c478bd9Sstevel@tonic-gate s_begin = s; 2376*7c478bd9Sstevel@tonic-gate while (s < s_end) { 2377*7c478bd9Sstevel@tonic-gate if (*s == ESCAPE_CHAR) { 2378*7c478bd9Sstevel@tonic-gate s++; 2379*7c478bd9Sstevel@tonic-gate got_data = TRUE; 2380*7c478bd9Sstevel@tonic-gate } else if (*s == DOUBLE_QUOTE_CHAR) { 2381*7c478bd9Sstevel@tonic-gate in_quote = !in_quote; 2382*7c478bd9Sstevel@tonic-gate got_data = TRUE; 2383*7c478bd9Sstevel@tonic-gate } else if (in_quote) 2384*7c478bd9Sstevel@tonic-gate ; 2385*7c478bd9Sstevel@tonic-gate else if (*s == EQUAL_CHAR) { 2386*7c478bd9Sstevel@tonic-gate if (end_nisplus && got_data && got_equal) 2387*7c478bd9Sstevel@tonic-gate break; 2388*7c478bd9Sstevel@tonic-gate if (!got_data || got_equal) { 2389*7c478bd9Sstevel@tonic-gate got_equal = FALSE; 2390*7c478bd9Sstevel@tonic-gate break; 2391*7c478bd9Sstevel@tonic-gate } 2392*7c478bd9Sstevel@tonic-gate got_equal = TRUE; 2393*7c478bd9Sstevel@tonic-gate got_data = FALSE; 2394*7c478bd9Sstevel@tonic-gate } else if (*s == COMMA_CHAR) { 2395*7c478bd9Sstevel@tonic-gate if (!got_data || !got_equal) 2396*7c478bd9Sstevel@tonic-gate break; 2397*7c478bd9Sstevel@tonic-gate got_data = FALSE; 2398*7c478bd9Sstevel@tonic-gate got_equal = FALSE; 2399*7c478bd9Sstevel@tonic-gate } else if (is_whitespace(*s)) 2400*7c478bd9Sstevel@tonic-gate ; 2401*7c478bd9Sstevel@tonic-gate else 2402*7c478bd9Sstevel@tonic-gate got_data = TRUE; 2403*7c478bd9Sstevel@tonic-gate s++; 2404*7c478bd9Sstevel@tonic-gate } 2405*7c478bd9Sstevel@tonic-gate if (!got_data || !got_equal || in_quote) 2406*7c478bd9Sstevel@tonic-gate s = NULL; 2407*7c478bd9Sstevel@tonic-gate else { 2408*7c478bd9Sstevel@tonic-gate *begin = s_begin; 2409*7c478bd9Sstevel@tonic-gate *end = s; 2410*7c478bd9Sstevel@tonic-gate while (s < s_end && is_whitespace(*s)) 2411*7c478bd9Sstevel@tonic-gate s++; 2412*7c478bd9Sstevel@tonic-gate } 2413*7c478bd9Sstevel@tonic-gate if (p_error == no_parse_error) 2414*7c478bd9Sstevel@tonic-gate break; 2415*7c478bd9Sstevel@tonic-gate } 2416*7c478bd9Sstevel@tonic-gate if (s == NULL) 2417*7c478bd9Sstevel@tonic-gate p_error = parse_invalid_ldap_search_filter; 2418*7c478bd9Sstevel@tonic-gate 2419*7c478bd9Sstevel@tonic-gate return (s); 2420*7c478bd9Sstevel@tonic-gate } 2421*7c478bd9Sstevel@tonic-gate 2422*7c478bd9Sstevel@tonic-gate /* Utility functions */ 2423*7c478bd9Sstevel@tonic-gate bool_t 2424*7c478bd9Sstevel@tonic-gate validate_dn(const char *s, int len) 2425*7c478bd9Sstevel@tonic-gate { 2426*7c478bd9Sstevel@tonic-gate const char *end = s + len; 2427*7c478bd9Sstevel@tonic-gate bool_t valid; 2428*7c478bd9Sstevel@tonic-gate 2429*7c478bd9Sstevel@tonic-gate valid = skip_get_dn(s, end) == end; 2430*7c478bd9Sstevel@tonic-gate 2431*7c478bd9Sstevel@tonic-gate if (!valid) 2432*7c478bd9Sstevel@tonic-gate p_error = parse_bad_dn; 2433*7c478bd9Sstevel@tonic-gate return (valid); 2434*7c478bd9Sstevel@tonic-gate } 2435*7c478bd9Sstevel@tonic-gate 2436*7c478bd9Sstevel@tonic-gate bool_t 2437*7c478bd9Sstevel@tonic-gate validate_ldap_filter(const char *s, const char *end) 2438*7c478bd9Sstevel@tonic-gate { 2439*7c478bd9Sstevel@tonic-gate const char *s_begin; 2440*7c478bd9Sstevel@tonic-gate const char *s_end; 2441*7c478bd9Sstevel@tonic-gate 2442*7c478bd9Sstevel@tonic-gate s_begin = s; 2443*7c478bd9Sstevel@tonic-gate s_end = end; 2444*7c478bd9Sstevel@tonic-gate 2445*7c478bd9Sstevel@tonic-gate if (*s == OPEN_PAREN_CHAR) { 2446*7c478bd9Sstevel@tonic-gate s = get_ldap_filter(&s_begin, &s_end); 2447*7c478bd9Sstevel@tonic-gate } else { 2448*7c478bd9Sstevel@tonic-gate /* Assume an attribute value list */ 2449*7c478bd9Sstevel@tonic-gate s = get_ava_list(&s_begin, &s_end, FALSE); 2450*7c478bd9Sstevel@tonic-gate } 2451*7c478bd9Sstevel@tonic-gate if (s == NULL || s_end != end) 2452*7c478bd9Sstevel@tonic-gate p_error = parse_invalid_ldap_search_filter; 2453*7c478bd9Sstevel@tonic-gate 2454*7c478bd9Sstevel@tonic-gate return (p_error == no_parse_error); 2455*7c478bd9Sstevel@tonic-gate } 2456*7c478bd9Sstevel@tonic-gate 2457*7c478bd9Sstevel@tonic-gate char * 2458*7c478bd9Sstevel@tonic-gate s_strndup(const char *s, int n) 2459*7c478bd9Sstevel@tonic-gate { 2460*7c478bd9Sstevel@tonic-gate char *d = (char *)malloc(n + 1); 2461*7c478bd9Sstevel@tonic-gate 2462*7c478bd9Sstevel@tonic-gate if (d != NULL) { 2463*7c478bd9Sstevel@tonic-gate (void) memcpy(d, s, n); 2464*7c478bd9Sstevel@tonic-gate d[n] = '\0'; 2465*7c478bd9Sstevel@tonic-gate } else { 2466*7c478bd9Sstevel@tonic-gate p_error = parse_no_mem_error; 2467*7c478bd9Sstevel@tonic-gate } 2468*7c478bd9Sstevel@tonic-gate 2469*7c478bd9Sstevel@tonic-gate return (d); 2470*7c478bd9Sstevel@tonic-gate } 2471*7c478bd9Sstevel@tonic-gate 2472*7c478bd9Sstevel@tonic-gate char * 2473*7c478bd9Sstevel@tonic-gate s_strndup_esc(const char *s, int n) 2474*7c478bd9Sstevel@tonic-gate { 2475*7c478bd9Sstevel@tonic-gate char *d = (char *)malloc(n + 1); 2476*7c478bd9Sstevel@tonic-gate int i; 2477*7c478bd9Sstevel@tonic-gate int j; 2478*7c478bd9Sstevel@tonic-gate 2479*7c478bd9Sstevel@tonic-gate if (d != NULL) { 2480*7c478bd9Sstevel@tonic-gate for (i = 0, j = 0; i < n; i++) { 2481*7c478bd9Sstevel@tonic-gate if (s[i] == ESCAPE_CHAR) 2482*7c478bd9Sstevel@tonic-gate i++; 2483*7c478bd9Sstevel@tonic-gate d[j++] = s[i]; 2484*7c478bd9Sstevel@tonic-gate } 2485*7c478bd9Sstevel@tonic-gate d[j] = '\0'; 2486*7c478bd9Sstevel@tonic-gate } else { 2487*7c478bd9Sstevel@tonic-gate p_error = parse_no_mem_error; 2488*7c478bd9Sstevel@tonic-gate } 2489*7c478bd9Sstevel@tonic-gate 2490*7c478bd9Sstevel@tonic-gate return (d); 2491*7c478bd9Sstevel@tonic-gate } 2492*7c478bd9Sstevel@tonic-gate 2493*7c478bd9Sstevel@tonic-gate void * 2494*7c478bd9Sstevel@tonic-gate s_calloc(size_t n, size_t size) 2495*7c478bd9Sstevel@tonic-gate { 2496*7c478bd9Sstevel@tonic-gate void *d = (char *)calloc(n, size); 2497*7c478bd9Sstevel@tonic-gate 2498*7c478bd9Sstevel@tonic-gate if (d == NULL) { 2499*7c478bd9Sstevel@tonic-gate p_error = parse_no_mem_error; 2500*7c478bd9Sstevel@tonic-gate } 2501*7c478bd9Sstevel@tonic-gate 2502*7c478bd9Sstevel@tonic-gate return (d); 2503*7c478bd9Sstevel@tonic-gate } 2504*7c478bd9Sstevel@tonic-gate 2505*7c478bd9Sstevel@tonic-gate void * 2506*7c478bd9Sstevel@tonic-gate s_malloc(size_t size) 2507*7c478bd9Sstevel@tonic-gate { 2508*7c478bd9Sstevel@tonic-gate void *d = malloc(size); 2509*7c478bd9Sstevel@tonic-gate if (d == NULL) 2510*7c478bd9Sstevel@tonic-gate p_error = parse_no_mem_error; 2511*7c478bd9Sstevel@tonic-gate return (d); 2512*7c478bd9Sstevel@tonic-gate } 2513*7c478bd9Sstevel@tonic-gate 2514*7c478bd9Sstevel@tonic-gate void * 2515*7c478bd9Sstevel@tonic-gate s_realloc(void *s, size_t size) 2516*7c478bd9Sstevel@tonic-gate { 2517*7c478bd9Sstevel@tonic-gate s = realloc(s, size); 2518*7c478bd9Sstevel@tonic-gate if (s == NULL) 2519*7c478bd9Sstevel@tonic-gate p_error = parse_no_mem_error; 2520*7c478bd9Sstevel@tonic-gate return (s); 2521*7c478bd9Sstevel@tonic-gate } 2522*7c478bd9Sstevel@tonic-gate 2523*7c478bd9Sstevel@tonic-gate char * 2524*7c478bd9Sstevel@tonic-gate s_strdup(const char *s) 2525*7c478bd9Sstevel@tonic-gate { 2526*7c478bd9Sstevel@tonic-gate return (s != NULL ? s_strndup(s, strlen(s)) : NULL); 2527*7c478bd9Sstevel@tonic-gate } 2528*7c478bd9Sstevel@tonic-gate 2529*7c478bd9Sstevel@tonic-gate bool_t 2530*7c478bd9Sstevel@tonic-gate is_whitespace(int c) 2531*7c478bd9Sstevel@tonic-gate { 2532*7c478bd9Sstevel@tonic-gate return (c == ' ' || c == '\t'); 2533*7c478bd9Sstevel@tonic-gate } 2534*7c478bd9Sstevel@tonic-gate 2535*7c478bd9Sstevel@tonic-gate bool_t 2536*7c478bd9Sstevel@tonic-gate is_string_ok(char *buffer, int buflen) 2537*7c478bd9Sstevel@tonic-gate { 2538*7c478bd9Sstevel@tonic-gate int i; 2539*7c478bd9Sstevel@tonic-gate 2540*7c478bd9Sstevel@tonic-gate if (buffer == NULL) 2541*7c478bd9Sstevel@tonic-gate return (FALSE); 2542*7c478bd9Sstevel@tonic-gate 2543*7c478bd9Sstevel@tonic-gate for (i = 0; i < buflen; i++) { 2544*7c478bd9Sstevel@tonic-gate if (!is_whitespace(buffer[i])) { 2545*7c478bd9Sstevel@tonic-gate if (buffer[i] == POUND_SIGN) 2546*7c478bd9Sstevel@tonic-gate return (TRUE); 2547*7c478bd9Sstevel@tonic-gate else 2548*7c478bd9Sstevel@tonic-gate return (FALSE); 2549*7c478bd9Sstevel@tonic-gate } 2550*7c478bd9Sstevel@tonic-gate } 2551*7c478bd9Sstevel@tonic-gate return (TRUE); 2552*7c478bd9Sstevel@tonic-gate } 2553*7c478bd9Sstevel@tonic-gate 2554*7c478bd9Sstevel@tonic-gate /* 2555*7c478bd9Sstevel@tonic-gate * Returns true if the first string is contained at the beginning of the 2556*7c478bd9Sstevel@tonic-gate * second string. Otherwise returns false. 2557*7c478bd9Sstevel@tonic-gate */ 2558*7c478bd9Sstevel@tonic-gate 2559*7c478bd9Sstevel@tonic-gate bool_t 2560*7c478bd9Sstevel@tonic-gate contains_string(const char *s1, const char *s2) 2561*7c478bd9Sstevel@tonic-gate { 2562*7c478bd9Sstevel@tonic-gate return (strncasecmp(s1, s2, strlen(s1)) == 0); 2563*7c478bd9Sstevel@tonic-gate } 2564*7c478bd9Sstevel@tonic-gate 2565*7c478bd9Sstevel@tonic-gate /* 2566*7c478bd9Sstevel@tonic-gate * Returns the next character position in the second string, if the first 2567*7c478bd9Sstevel@tonic-gate * string is contained at the beginning of the second string. Otherwise 2568*7c478bd9Sstevel@tonic-gate * returns NULL. 2569*7c478bd9Sstevel@tonic-gate */ 2570*7c478bd9Sstevel@tonic-gate 2571*7c478bd9Sstevel@tonic-gate const char * 2572*7c478bd9Sstevel@tonic-gate skip_string(const char *s1, const char *s2, int len) 2573*7c478bd9Sstevel@tonic-gate { 2574*7c478bd9Sstevel@tonic-gate int len1 = strlen(s1); 2575*7c478bd9Sstevel@tonic-gate 2576*7c478bd9Sstevel@tonic-gate if (len >= len1 && strncasecmp(s1, s2, strlen(s1)) == 0) 2577*7c478bd9Sstevel@tonic-gate return (s2 + len1); 2578*7c478bd9Sstevel@tonic-gate else 2579*7c478bd9Sstevel@tonic-gate return (NULL); 2580*7c478bd9Sstevel@tonic-gate } 2581*7c478bd9Sstevel@tonic-gate 2582*7c478bd9Sstevel@tonic-gate /* 2583*7c478bd9Sstevel@tonic-gate * The second string is not necessarily null terminated. 2584*7c478bd9Sstevel@tonic-gate * same_string returns true if the second string matches the first. 2585*7c478bd9Sstevel@tonic-gate * Otherwise returns false. 2586*7c478bd9Sstevel@tonic-gate */ 2587*7c478bd9Sstevel@tonic-gate 2588*7c478bd9Sstevel@tonic-gate bool_t 2589*7c478bd9Sstevel@tonic-gate same_string(const char *s1, const char *s2, int len) 2590*7c478bd9Sstevel@tonic-gate { 2591*7c478bd9Sstevel@tonic-gate int len1 = strlen(s1); 2592*7c478bd9Sstevel@tonic-gate 2593*7c478bd9Sstevel@tonic-gate return (len1 == len && strncasecmp(s1, s2, len1) == 0); 2594*7c478bd9Sstevel@tonic-gate } 2595*7c478bd9Sstevel@tonic-gate 2596*7c478bd9Sstevel@tonic-gate void 2597*7c478bd9Sstevel@tonic-gate report_error(const char *str, const char *attr) 2598*7c478bd9Sstevel@tonic-gate { 2599*7c478bd9Sstevel@tonic-gate char fmt_buf[1024]; 2600*7c478bd9Sstevel@tonic-gate int pos = 0; 2601*7c478bd9Sstevel@tonic-gate 2602*7c478bd9Sstevel@tonic-gate if (command_line_source != NULL) { 2603*7c478bd9Sstevel@tonic-gate snprintf(fmt_buf, sizeof (fmt_buf), "Error parsing %s: ", 2604*7c478bd9Sstevel@tonic-gate command_line_source); 2605*7c478bd9Sstevel@tonic-gate pos = strlen(fmt_buf); 2606*7c478bd9Sstevel@tonic-gate } else if (file_source != NULL) { 2607*7c478bd9Sstevel@tonic-gate snprintf(fmt_buf, sizeof (fmt_buf), "Error parsing file '%s': ", 2608*7c478bd9Sstevel@tonic-gate file_source); 2609*7c478bd9Sstevel@tonic-gate pos = strlen(fmt_buf); 2610*7c478bd9Sstevel@tonic-gate } else if (ldap_source != NULL) { 2611*7c478bd9Sstevel@tonic-gate snprintf(fmt_buf, sizeof (fmt_buf), "Error for LDAP dn '%s': ", 2612*7c478bd9Sstevel@tonic-gate ldap_source); 2613*7c478bd9Sstevel@tonic-gate pos = strlen(fmt_buf); 2614*7c478bd9Sstevel@tonic-gate } 2615*7c478bd9Sstevel@tonic-gate 2616*7c478bd9Sstevel@tonic-gate if (start_line_num != 0) { 2617*7c478bd9Sstevel@tonic-gate snprintf(fmt_buf + pos, sizeof (fmt_buf) - pos, "at line %d: ", 2618*7c478bd9Sstevel@tonic-gate start_line_num); 2619*7c478bd9Sstevel@tonic-gate pos += strlen(fmt_buf + pos); 2620*7c478bd9Sstevel@tonic-gate } 2621*7c478bd9Sstevel@tonic-gate 2622*7c478bd9Sstevel@tonic-gate if (attr != NULL) { 2623*7c478bd9Sstevel@tonic-gate snprintf(fmt_buf + pos, sizeof (fmt_buf) - pos, 2624*7c478bd9Sstevel@tonic-gate "for attribute %s: ", attr); 2625*7c478bd9Sstevel@tonic-gate pos += strlen(fmt_buf + pos); 2626*7c478bd9Sstevel@tonic-gate } 2627*7c478bd9Sstevel@tonic-gate 2628*7c478bd9Sstevel@tonic-gate if (cons != NULL) { 2629*7c478bd9Sstevel@tonic-gate snprintf(fmt_buf + pos, sizeof (fmt_buf) - pos, "%s\n", 2630*7c478bd9Sstevel@tonic-gate parse_error_msg[p_error]); 2631*7c478bd9Sstevel@tonic-gate fprintf(cons, fmt_buf, str == NULL ? "" : str); 2632*7c478bd9Sstevel@tonic-gate } else { 2633*7c478bd9Sstevel@tonic-gate snprintf(fmt_buf + pos, sizeof (fmt_buf) - pos, "%s", 2634*7c478bd9Sstevel@tonic-gate parse_error_msg[p_error]); 2635*7c478bd9Sstevel@tonic-gate syslog(LOG_ERR, fmt_buf, str == NULL ? "" : str); 2636*7c478bd9Sstevel@tonic-gate } 2637*7c478bd9Sstevel@tonic-gate } 2638*7c478bd9Sstevel@tonic-gate 2639*7c478bd9Sstevel@tonic-gate void 2640*7c478bd9Sstevel@tonic-gate report_error2( 2641*7c478bd9Sstevel@tonic-gate const char *str1, 2642*7c478bd9Sstevel@tonic-gate const char *str2) 2643*7c478bd9Sstevel@tonic-gate { 2644*7c478bd9Sstevel@tonic-gate char fmt_buf[1024]; 2645*7c478bd9Sstevel@tonic-gate 2646*7c478bd9Sstevel@tonic-gate if (cons != NULL) { 2647*7c478bd9Sstevel@tonic-gate snprintf(fmt_buf, sizeof (fmt_buf), 2648*7c478bd9Sstevel@tonic-gate "%s\n", parse_error_msg[p_error]); 2649*7c478bd9Sstevel@tonic-gate fprintf(cons, fmt_buf, str1, str2); 2650*7c478bd9Sstevel@tonic-gate } else { 2651*7c478bd9Sstevel@tonic-gate syslog(LOG_ERR, parse_error_msg[p_error], str1, str2); 2652*7c478bd9Sstevel@tonic-gate } 2653*7c478bd9Sstevel@tonic-gate } 2654*7c478bd9Sstevel@tonic-gate 2655*7c478bd9Sstevel@tonic-gate void 2656*7c478bd9Sstevel@tonic-gate report_conn_error( 2657*7c478bd9Sstevel@tonic-gate conn_error e, 2658*7c478bd9Sstevel@tonic-gate const char *str1, 2659*7c478bd9Sstevel@tonic-gate const char *str2) 2660*7c478bd9Sstevel@tonic-gate { 2661*7c478bd9Sstevel@tonic-gate char fmt_buf[1024]; 2662*7c478bd9Sstevel@tonic-gate 2663*7c478bd9Sstevel@tonic-gate if (cons != NULL) { 2664*7c478bd9Sstevel@tonic-gate snprintf(fmt_buf, sizeof (fmt_buf), 2665*7c478bd9Sstevel@tonic-gate "%s\n", conn_error_msg[e]); 2666*7c478bd9Sstevel@tonic-gate fprintf(cons, fmt_buf, 2667*7c478bd9Sstevel@tonic-gate str1 == NULL ? "" : str1, 2668*7c478bd9Sstevel@tonic-gate str2 == NULL ? "" : str2); 2669*7c478bd9Sstevel@tonic-gate } else { 2670*7c478bd9Sstevel@tonic-gate syslog(LOG_ERR, 2671*7c478bd9Sstevel@tonic-gate conn_error_msg[e], 2672*7c478bd9Sstevel@tonic-gate str1 == NULL ? "" : str1, 2673*7c478bd9Sstevel@tonic-gate str2 == NULL ? "" : str2); 2674*7c478bd9Sstevel@tonic-gate } 2675*7c478bd9Sstevel@tonic-gate } 2676*7c478bd9Sstevel@tonic-gate 2677*7c478bd9Sstevel@tonic-gate void 2678*7c478bd9Sstevel@tonic-gate report_info( 2679*7c478bd9Sstevel@tonic-gate const char *str, 2680*7c478bd9Sstevel@tonic-gate const char *arg) 2681*7c478bd9Sstevel@tonic-gate { 2682*7c478bd9Sstevel@tonic-gate if (cons != NULL) { 2683*7c478bd9Sstevel@tonic-gate fputs(str, cons); 2684*7c478bd9Sstevel@tonic-gate if (arg != NULL) 2685*7c478bd9Sstevel@tonic-gate fputs(arg, cons); 2686*7c478bd9Sstevel@tonic-gate fputs("\n", cons); 2687*7c478bd9Sstevel@tonic-gate } else 2688*7c478bd9Sstevel@tonic-gate syslog(LOG_INFO, str, arg); 2689*7c478bd9Sstevel@tonic-gate } 2690