17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
227c478bd9Sstevel@tonic-gate /*
23*a87701e9SGary Mills * Copyright 2015 Gary Mills
247c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
257c478bd9Sstevel@tonic-gate * Use is subject to license terms.
267c478bd9Sstevel@tonic-gate */
277c478bd9Sstevel@tonic-gate
287c478bd9Sstevel@tonic-gate #include <stdio.h>
297c478bd9Sstevel@tonic-gate #include <string.h>
307c478bd9Sstevel@tonic-gate #include <stdlib.h>
317c478bd9Sstevel@tonic-gate #include <ctype.h>
327c478bd9Sstevel@tonic-gate #include <fcntl.h>
337c478bd9Sstevel@tonic-gate #include <unistd.h>
347c478bd9Sstevel@tonic-gate #include <errno.h>
357c478bd9Sstevel@tonic-gate #include <locale.h>
367c478bd9Sstevel@tonic-gate #include <lber.h>
377c478bd9Sstevel@tonic-gate #include <ldap.h>
387c478bd9Sstevel@tonic-gate #include <syslog.h>
397c478bd9Sstevel@tonic-gate #include <dlfcn.h> /* for dynamic loading only */
407c478bd9Sstevel@tonic-gate
417c478bd9Sstevel@tonic-gate #include "ldap_parse.h"
427c478bd9Sstevel@tonic-gate #include "nis_parse_ldap_conf.h"
437c478bd9Sstevel@tonic-gate #include "nis_parse_ldap_err.h"
447c478bd9Sstevel@tonic-gate #include "ldap_util.h"
457c478bd9Sstevel@tonic-gate #include "ldap_util.h"
467c478bd9Sstevel@tonic-gate
477c478bd9Sstevel@tonic-gate void append_dot(char **str);
487c478bd9Sstevel@tonic-gate void append_comma(char **str);
497c478bd9Sstevel@tonic-gate bool_t make_full_dn(char **dn, const char *base);
507c478bd9Sstevel@tonic-gate bool_t make_fqdn(__nis_object_dn_t *dn, const char *base);
517c478bd9Sstevel@tonic-gate char *get_default_ldap_base(const char *domain);
527c478bd9Sstevel@tonic-gate bool_t add_domain(char **objName, const char *domain);
537c478bd9Sstevel@tonic-gate bool_t add_column(__nis_table_mapping_t *t, const char *col_name);
547c478bd9Sstevel@tonic-gate __nis_mapping_rule_t **dup_mapping_rules(
557c478bd9Sstevel@tonic-gate __nis_mapping_rule_t **rules, int n_rules);
567c478bd9Sstevel@tonic-gate __nis_mapping_rule_t *dup_mapping_rule(
577c478bd9Sstevel@tonic-gate __nis_mapping_rule_t *in);
587c478bd9Sstevel@tonic-gate void *s_malloc(size_t size);
597c478bd9Sstevel@tonic-gate __nis_mapping_format_t *dup_format_mapping(
607c478bd9Sstevel@tonic-gate __nis_mapping_format_t *in);
617c478bd9Sstevel@tonic-gate bool_t dup_mapping_element(__nis_mapping_element_t *in,
627c478bd9Sstevel@tonic-gate __nis_mapping_element_t *out);
63*a87701e9SGary Mills bool_t is_string_ok(char *, int);
647c478bd9Sstevel@tonic-gate
657c478bd9Sstevel@tonic-gate extern FILE *cons;
667c478bd9Sstevel@tonic-gate
677c478bd9Sstevel@tonic-gate /*
687c478bd9Sstevel@tonic-gate * FUNCTION: free_parse_structs
697c478bd9Sstevel@tonic-gate *
707c478bd9Sstevel@tonic-gate * Release the resources in parse results
717c478bd9Sstevel@tonic-gate *
727c478bd9Sstevel@tonic-gate */
737c478bd9Sstevel@tonic-gate
747c478bd9Sstevel@tonic-gate void
free_parse_structs()757c478bd9Sstevel@tonic-gate free_parse_structs()
767c478bd9Sstevel@tonic-gate {
777c478bd9Sstevel@tonic-gate __nis_table_mapping_t *t;
787c478bd9Sstevel@tonic-gate __nis_table_mapping_t *t1;
797c478bd9Sstevel@tonic-gate
807c478bd9Sstevel@tonic-gate free_proxy_info(&proxyInfo);
817c478bd9Sstevel@tonic-gate for (t = ldapTableMapping; t != NULL; t = t1) {
827c478bd9Sstevel@tonic-gate t1 = t->next;
837c478bd9Sstevel@tonic-gate free_table_mapping(t);
847c478bd9Sstevel@tonic-gate }
857c478bd9Sstevel@tonic-gate ldapTableMapping = NULL;
867c478bd9Sstevel@tonic-gate }
877c478bd9Sstevel@tonic-gate
887c478bd9Sstevel@tonic-gate /*
897c478bd9Sstevel@tonic-gate * FUNCTION: initialize_parse_structs
907c478bd9Sstevel@tonic-gate *
917c478bd9Sstevel@tonic-gate * Initialize fields to unset values
927c478bd9Sstevel@tonic-gate *
937c478bd9Sstevel@tonic-gate * INPUT: __nis_ldap_proxy_info, __nis_config_t
947c478bd9Sstevel@tonic-gate * and __nisdb_table_mapping_t structures
957c478bd9Sstevel@tonic-gate */
967c478bd9Sstevel@tonic-gate
977c478bd9Sstevel@tonic-gate void
initialize_parse_structs(__nis_ldap_proxy_info * proxy_info,__nis_config_t * config_info,__nisdb_table_mapping_t * table_info)987c478bd9Sstevel@tonic-gate initialize_parse_structs(
997c478bd9Sstevel@tonic-gate __nis_ldap_proxy_info *proxy_info,
1007c478bd9Sstevel@tonic-gate __nis_config_t *config_info,
1017c478bd9Sstevel@tonic-gate __nisdb_table_mapping_t *table_info)
1027c478bd9Sstevel@tonic-gate {
1037c478bd9Sstevel@tonic-gate proxy_info->default_servers = NULL;
1047c478bd9Sstevel@tonic-gate proxy_info->auth_method = (auth_method_t)NO_VALUE_SET;
1057c478bd9Sstevel@tonic-gate proxy_info->tls_method = (tls_method_t)NO_VALUE_SET;
1067c478bd9Sstevel@tonic-gate proxy_info->tls_cert_db = NULL;
1077c478bd9Sstevel@tonic-gate proxy_info->default_search_base = NULL;
1087c478bd9Sstevel@tonic-gate proxy_info->proxy_dn = NULL;
1097c478bd9Sstevel@tonic-gate proxy_info->proxy_passwd = NULL;
1107c478bd9Sstevel@tonic-gate proxy_info->default_nis_domain = NULL;
1117c478bd9Sstevel@tonic-gate proxy_info->bind_timeout.tv_sec = (time_t)NO_VALUE_SET;
1127c478bd9Sstevel@tonic-gate proxy_info->bind_timeout.tv_usec = 0;
1137c478bd9Sstevel@tonic-gate proxy_info->search_timeout.tv_sec = (time_t)NO_VALUE_SET;
1147c478bd9Sstevel@tonic-gate proxy_info->search_timeout.tv_usec = 0;
1157c478bd9Sstevel@tonic-gate proxy_info->modify_timeout.tv_sec = (time_t)NO_VALUE_SET;
1167c478bd9Sstevel@tonic-gate proxy_info->modify_timeout.tv_usec = 0;
1177c478bd9Sstevel@tonic-gate proxy_info->add_timeout.tv_sec = (time_t)NO_VALUE_SET;
1187c478bd9Sstevel@tonic-gate proxy_info->add_timeout.tv_usec = 0;
1197c478bd9Sstevel@tonic-gate proxy_info->delete_timeout.tv_sec = (time_t)NO_VALUE_SET;
1207c478bd9Sstevel@tonic-gate proxy_info->delete_timeout.tv_usec = 0;
1217c478bd9Sstevel@tonic-gate proxy_info->search_time_limit = (int)NO_VALUE_SET;
1227c478bd9Sstevel@tonic-gate proxy_info->search_size_limit = (int)NO_VALUE_SET;
1237c478bd9Sstevel@tonic-gate proxy_info->follow_referral = (follow_referral_t)NO_VALUE_SET;
1247c478bd9Sstevel@tonic-gate
1257c478bd9Sstevel@tonic-gate
1267c478bd9Sstevel@tonic-gate config_info->initialUpdate = (__nis_initial_update_t)NO_VALUE_SET;
1277c478bd9Sstevel@tonic-gate config_info->threadCreationError =
1287c478bd9Sstevel@tonic-gate (__nis_thread_creation_error_t)NO_VALUE_SET;
1297c478bd9Sstevel@tonic-gate config_info->threadCreationErrorTimeout.attempts = NO_VALUE_SET;
1307c478bd9Sstevel@tonic-gate config_info->threadCreationErrorTimeout.timeout = (time_t)NO_VALUE_SET;
1317c478bd9Sstevel@tonic-gate config_info->dumpError = (__nis_dump_error_t)NO_VALUE_SET;
1327c478bd9Sstevel@tonic-gate config_info->dumpErrorTimeout.attempts = NO_VALUE_SET;
1337c478bd9Sstevel@tonic-gate config_info->dumpErrorTimeout.timeout = (time_t)NO_VALUE_SET;
1347c478bd9Sstevel@tonic-gate config_info->resyncService = (__nis_resync_service_t)NO_VALUE_SET;
1357c478bd9Sstevel@tonic-gate config_info->updateBatching = (__nis_update_batching_t)NO_VALUE_SET;
1367c478bd9Sstevel@tonic-gate config_info->updateBatchingTimeout.timeout = (time_t)NO_VALUE_SET;
1377c478bd9Sstevel@tonic-gate config_info->numberOfServiceThreads = (int)NO_VALUE_SET;
1387c478bd9Sstevel@tonic-gate config_info->emulate_yp = (int)NO_VALUE_SET;
1397c478bd9Sstevel@tonic-gate config_info->maxRPCRecordSize = (int)NO_VALUE_SET;
1407c478bd9Sstevel@tonic-gate
1417c478bd9Sstevel@tonic-gate table_info->retrieveError = (__nis_retrieve_error_t)NO_VALUE_SET;
1427c478bd9Sstevel@tonic-gate table_info->retrieveErrorRetry.attempts = NO_VALUE_SET;
1437c478bd9Sstevel@tonic-gate table_info->retrieveErrorRetry.timeout = (time_t)NO_VALUE_SET;
1447c478bd9Sstevel@tonic-gate table_info->storeError = (__nis_store_error_t)NO_VALUE_SET;
1457c478bd9Sstevel@tonic-gate table_info->storeErrorRetry.attempts = NO_VALUE_SET;
1467c478bd9Sstevel@tonic-gate table_info->storeErrorRetry.timeout = (time_t)NO_VALUE_SET;
1477c478bd9Sstevel@tonic-gate table_info->refreshError = (__nis_refresh_error_t)NO_VALUE_SET;
1487c478bd9Sstevel@tonic-gate table_info->refreshErrorRetry.attempts = NO_VALUE_SET;
1497c478bd9Sstevel@tonic-gate table_info->refreshErrorRetry.timeout = (time_t)NO_VALUE_SET;
1507c478bd9Sstevel@tonic-gate table_info->matchFetch = (__nis_match_fetch_t)NO_VALUE_SET;
1517c478bd9Sstevel@tonic-gate }
1527c478bd9Sstevel@tonic-gate
1537c478bd9Sstevel@tonic-gate /*
1547c478bd9Sstevel@tonic-gate * FUNCTION: free_mapping_rule
1557c478bd9Sstevel@tonic-gate *
1567c478bd9Sstevel@tonic-gate * Frees __nis_mapping_rule_t
1577c478bd9Sstevel@tonic-gate *
1587c478bd9Sstevel@tonic-gate * INPUT: __nis_mapping_rule_t
1597c478bd9Sstevel@tonic-gate */
1607c478bd9Sstevel@tonic-gate
1617c478bd9Sstevel@tonic-gate void
free_mapping_rule(__nis_mapping_rule_t * rule)1627c478bd9Sstevel@tonic-gate free_mapping_rule(__nis_mapping_rule_t *rule)
1637c478bd9Sstevel@tonic-gate {
1647c478bd9Sstevel@tonic-gate int i;
1657c478bd9Sstevel@tonic-gate __nis_mapping_rlhs_t *r;
1667c478bd9Sstevel@tonic-gate
1677c478bd9Sstevel@tonic-gate if (rule != NULL) {
1687c478bd9Sstevel@tonic-gate r = &rule->lhs;
1697c478bd9Sstevel@tonic-gate for (i = 0; i < r->numElements; i++)
1707c478bd9Sstevel@tonic-gate free_mapping_element(&r->element[i]);
1717c478bd9Sstevel@tonic-gate if (r->element != NULL)
1727c478bd9Sstevel@tonic-gate free(r->element);
1737c478bd9Sstevel@tonic-gate
1747c478bd9Sstevel@tonic-gate r = &rule->rhs;
1757c478bd9Sstevel@tonic-gate for (i = 0; i < r->numElements; i++)
1767c478bd9Sstevel@tonic-gate free_mapping_element(&r->element[i]);
1777c478bd9Sstevel@tonic-gate if (r->element != NULL)
1787c478bd9Sstevel@tonic-gate free(r->element);
1797c478bd9Sstevel@tonic-gate
1807c478bd9Sstevel@tonic-gate free(rule);
1817c478bd9Sstevel@tonic-gate }
1827c478bd9Sstevel@tonic-gate }
1837c478bd9Sstevel@tonic-gate
1847c478bd9Sstevel@tonic-gate /*
1857c478bd9Sstevel@tonic-gate * FUNCTION: free_mapping_element
1867c478bd9Sstevel@tonic-gate *
1877c478bd9Sstevel@tonic-gate * Frees __nis_mapping_element_t
1887c478bd9Sstevel@tonic-gate *
1897c478bd9Sstevel@tonic-gate * INPUT: __nis_mapping_element_t
1907c478bd9Sstevel@tonic-gate */
1917c478bd9Sstevel@tonic-gate
1927c478bd9Sstevel@tonic-gate void
free_mapping_element(__nis_mapping_element_t * e)1937c478bd9Sstevel@tonic-gate free_mapping_element(__nis_mapping_element_t *e)
1947c478bd9Sstevel@tonic-gate {
1957c478bd9Sstevel@tonic-gate int i;
1967c478bd9Sstevel@tonic-gate
1977c478bd9Sstevel@tonic-gate if (e == NULL)
1987c478bd9Sstevel@tonic-gate return;
1997c478bd9Sstevel@tonic-gate
2007c478bd9Sstevel@tonic-gate switch (e->type) {
2017c478bd9Sstevel@tonic-gate case me_item:
2027c478bd9Sstevel@tonic-gate free_mapping_item(&e->element.item);
2037c478bd9Sstevel@tonic-gate break;
2047c478bd9Sstevel@tonic-gate case me_print:
2057c478bd9Sstevel@tonic-gate if (e->element.print.fmt != NULL)
2067c478bd9Sstevel@tonic-gate free_mapping_format(e->element.print.fmt);
2077c478bd9Sstevel@tonic-gate e->element.print.fmt = NULL;
2087c478bd9Sstevel@tonic-gate for (i = 0; i < e->element.print.numSubElements; i++)
2097c478bd9Sstevel@tonic-gate free_mapping_sub_element(
2107c478bd9Sstevel@tonic-gate &e->element.print.subElement[i]);
2117c478bd9Sstevel@tonic-gate e->element.print.numSubElements = 0;
2127c478bd9Sstevel@tonic-gate if (e->element.print.subElement != NULL)
2137c478bd9Sstevel@tonic-gate free(e->element.print.subElement);
2147c478bd9Sstevel@tonic-gate e->element.print.subElement = NULL;
2157c478bd9Sstevel@tonic-gate break;
2167c478bd9Sstevel@tonic-gate case me_split:
2177c478bd9Sstevel@tonic-gate free_mapping_item(&e->element.split.item);
2187c478bd9Sstevel@tonic-gate break;
2197c478bd9Sstevel@tonic-gate case me_match:
2207c478bd9Sstevel@tonic-gate if (e->element.match.fmt != NULL)
2217c478bd9Sstevel@tonic-gate free_mapping_format(e->element.match.fmt);
2227c478bd9Sstevel@tonic-gate e->element.match.fmt = NULL;
2237c478bd9Sstevel@tonic-gate for (i = 0; i < e->element.match.numItems; i++)
2247c478bd9Sstevel@tonic-gate free_mapping_item(&e->element.match.item[i]);
2257c478bd9Sstevel@tonic-gate e->element.match.numItems = 0;
2267c478bd9Sstevel@tonic-gate if (e->element.match.item != NULL)
2277c478bd9Sstevel@tonic-gate free(e->element.match.item);
2287c478bd9Sstevel@tonic-gate e->element.match.item = NULL;
2297c478bd9Sstevel@tonic-gate break;
2307c478bd9Sstevel@tonic-gate case me_extract:
2317c478bd9Sstevel@tonic-gate if (e->element.extract.fmt != NULL)
2327c478bd9Sstevel@tonic-gate free_mapping_format(e->element.extract.fmt);
2337c478bd9Sstevel@tonic-gate e->element.extract.fmt = NULL;
2347c478bd9Sstevel@tonic-gate free_mapping_item(&e->element.extract.item);
2357c478bd9Sstevel@tonic-gate break;
2367c478bd9Sstevel@tonic-gate }
2377c478bd9Sstevel@tonic-gate e = NULL;
2387c478bd9Sstevel@tonic-gate }
2397c478bd9Sstevel@tonic-gate
2407c478bd9Sstevel@tonic-gate /*
2417c478bd9Sstevel@tonic-gate * FUNCTION: free_table_mapping
2427c478bd9Sstevel@tonic-gate *
2437c478bd9Sstevel@tonic-gate * Frees __nis_table_mapping_t
2447c478bd9Sstevel@tonic-gate *
2457c478bd9Sstevel@tonic-gate * INPUT: __nis_table_mapping_t
2467c478bd9Sstevel@tonic-gate */
2477c478bd9Sstevel@tonic-gate
2487c478bd9Sstevel@tonic-gate /*
2497c478bd9Sstevel@tonic-gate * free_table_mapping does not remove the table mapping from
2507c478bd9Sstevel@tonic-gate * its hashed list
2517c478bd9Sstevel@tonic-gate */
2527c478bd9Sstevel@tonic-gate
2537c478bd9Sstevel@tonic-gate void
free_table_mapping(__nis_table_mapping_t * mapping)2547c478bd9Sstevel@tonic-gate free_table_mapping(__nis_table_mapping_t *mapping)
2557c478bd9Sstevel@tonic-gate {
2567c478bd9Sstevel@tonic-gate int i;
2577c478bd9Sstevel@tonic-gate
2587c478bd9Sstevel@tonic-gate if (mapping == NULL)
2597c478bd9Sstevel@tonic-gate return;
2607c478bd9Sstevel@tonic-gate
2617c478bd9Sstevel@tonic-gate if (mapping->dbId != NULL)
2627c478bd9Sstevel@tonic-gate free(mapping->dbId);
2637c478bd9Sstevel@tonic-gate mapping->dbId = NULL;
2647c478bd9Sstevel@tonic-gate
2657c478bd9Sstevel@tonic-gate if (mapping->objName != NULL)
2667c478bd9Sstevel@tonic-gate free(mapping->objName);
2677c478bd9Sstevel@tonic-gate mapping->objName = NULL;
2687c478bd9Sstevel@tonic-gate
2697c478bd9Sstevel@tonic-gate for (i = 0; i < mapping->index.numIndexes; i++) {
2707c478bd9Sstevel@tonic-gate free(mapping->index.name[i]);
2717c478bd9Sstevel@tonic-gate free_mapping_format(mapping->index.value[i]);
2727c478bd9Sstevel@tonic-gate }
2737c478bd9Sstevel@tonic-gate
2747c478bd9Sstevel@tonic-gate if (mapping->index.name != NULL)
2757c478bd9Sstevel@tonic-gate free(mapping->index.name);
2767c478bd9Sstevel@tonic-gate mapping->index.name = NULL;
2777c478bd9Sstevel@tonic-gate
2787c478bd9Sstevel@tonic-gate if (mapping->index.value != NULL)
2797c478bd9Sstevel@tonic-gate free(mapping->index.value);
2807c478bd9Sstevel@tonic-gate mapping->index.value = NULL;
2817c478bd9Sstevel@tonic-gate
2827c478bd9Sstevel@tonic-gate mapping->index.numIndexes = 0;
2837c478bd9Sstevel@tonic-gate
2847c478bd9Sstevel@tonic-gate if (mapping->column != NULL) {
2857c478bd9Sstevel@tonic-gate for (i = 0; i < mapping->numColumns; i++) {
2867c478bd9Sstevel@tonic-gate free(mapping->column[i]);
2877c478bd9Sstevel@tonic-gate }
2887c478bd9Sstevel@tonic-gate mapping->numColumns = 0;
2897c478bd9Sstevel@tonic-gate free(mapping->column);
2907c478bd9Sstevel@tonic-gate mapping->column = NULL;
2917c478bd9Sstevel@tonic-gate }
2927c478bd9Sstevel@tonic-gate
2937c478bd9Sstevel@tonic-gate if (mapping->commentChar != NULL)
2947c478bd9Sstevel@tonic-gate mapping->commentChar = NULL;
2957c478bd9Sstevel@tonic-gate
2967c478bd9Sstevel@tonic-gate if (mapping->objectDN != NULL)
2977c478bd9Sstevel@tonic-gate free_object_dn(mapping->objectDN);
2987c478bd9Sstevel@tonic-gate mapping->objectDN = NULL;
2997c478bd9Sstevel@tonic-gate
3007c478bd9Sstevel@tonic-gate if (mapping->separatorStr != NULL)
3017c478bd9Sstevel@tonic-gate mapping->separatorStr = NULL;
3027c478bd9Sstevel@tonic-gate
3037c478bd9Sstevel@tonic-gate for (i = 0; i < mapping->numRulesFromLDAP; i++) {
3047c478bd9Sstevel@tonic-gate if (mapping->ruleFromLDAP[i]) /* See Comment below */
3057c478bd9Sstevel@tonic-gate free_mapping_rule(mapping->ruleFromLDAP[i]);
3067c478bd9Sstevel@tonic-gate }
3077c478bd9Sstevel@tonic-gate mapping->numRulesFromLDAP = 0;
3087c478bd9Sstevel@tonic-gate
3097c478bd9Sstevel@tonic-gate if (mapping->ruleFromLDAP != NULL)
3107c478bd9Sstevel@tonic-gate free(mapping->ruleFromLDAP);
3117c478bd9Sstevel@tonic-gate mapping->ruleFromLDAP = NULL;
3127c478bd9Sstevel@tonic-gate
3137c478bd9Sstevel@tonic-gate for (i = 0; i < mapping->numRulesToLDAP; i++) {
3147c478bd9Sstevel@tonic-gate if (mapping->ruleToLDAP[i])
3157c478bd9Sstevel@tonic-gate /*
3167c478bd9Sstevel@tonic-gate * Normally mapping->ruleToLDAP[i] should
3177c478bd9Sstevel@tonic-gate * always be non-null if
3187c478bd9Sstevel@tonic-gate * mapping->numRulesToLDAP is > 0.
3197c478bd9Sstevel@tonic-gate * However it is possible to have data
3207c478bd9Sstevel@tonic-gate * corruption where numRulesToLDAP gets
3217c478bd9Sstevel@tonic-gate * some integer value even though no real
3227c478bd9Sstevel@tonic-gate * data is present in mapping->ruleToLDAP.
3237c478bd9Sstevel@tonic-gate */
3247c478bd9Sstevel@tonic-gate free_mapping_rule(mapping->ruleToLDAP[i]);
3257c478bd9Sstevel@tonic-gate }
3267c478bd9Sstevel@tonic-gate mapping->numRulesToLDAP = 0;
3277c478bd9Sstevel@tonic-gate
3287c478bd9Sstevel@tonic-gate if (mapping->ruleToLDAP != NULL)
3297c478bd9Sstevel@tonic-gate free(mapping->ruleToLDAP);
3307c478bd9Sstevel@tonic-gate mapping->ruleToLDAP = NULL;
3317c478bd9Sstevel@tonic-gate
3327c478bd9Sstevel@tonic-gate if (mapping->e != NULL) {
3337c478bd9Sstevel@tonic-gate /* Similar logic as in above comment applies. */
3347c478bd9Sstevel@tonic-gate for (i = 0; i <= mapping->numSplits; i++) {
3357c478bd9Sstevel@tonic-gate free_mapping_element(&mapping->e[i]);
3367c478bd9Sstevel@tonic-gate }
3377c478bd9Sstevel@tonic-gate free(mapping->e);
3387c478bd9Sstevel@tonic-gate }
3397c478bd9Sstevel@tonic-gate mapping->e = NULL;
3407c478bd9Sstevel@tonic-gate
3417c478bd9Sstevel@tonic-gate mapping->numSplits = 0;
3427c478bd9Sstevel@tonic-gate
3437c478bd9Sstevel@tonic-gate free(mapping);
3447c478bd9Sstevel@tonic-gate }
3457c478bd9Sstevel@tonic-gate
3467c478bd9Sstevel@tonic-gate /*
3477c478bd9Sstevel@tonic-gate * FUNCTION: free_config_info
3487c478bd9Sstevel@tonic-gate *
3497c478bd9Sstevel@tonic-gate * Frees __nis_config_info_t
3507c478bd9Sstevel@tonic-gate *
3517c478bd9Sstevel@tonic-gate * INPUT: __nis_config_info_t
3527c478bd9Sstevel@tonic-gate */
3537c478bd9Sstevel@tonic-gate
3547c478bd9Sstevel@tonic-gate void
free_config_info(__nis_config_info_t * config_info)3557c478bd9Sstevel@tonic-gate free_config_info(__nis_config_info_t *config_info)
3567c478bd9Sstevel@tonic-gate {
3577c478bd9Sstevel@tonic-gate if (config_info->config_dn != NULL)
3587c478bd9Sstevel@tonic-gate free(config_info->config_dn);
3597c478bd9Sstevel@tonic-gate config_info->config_dn = NULL;
3607c478bd9Sstevel@tonic-gate
3617c478bd9Sstevel@tonic-gate if (config_info->default_servers != NULL)
3627c478bd9Sstevel@tonic-gate free(config_info->default_servers);
3637c478bd9Sstevel@tonic-gate config_info->default_servers = NULL;
3647c478bd9Sstevel@tonic-gate
3657c478bd9Sstevel@tonic-gate if (config_info->proxy_dn != NULL)
3667c478bd9Sstevel@tonic-gate free(config_info->proxy_dn);
3677c478bd9Sstevel@tonic-gate config_info->proxy_dn = NULL;
3687c478bd9Sstevel@tonic-gate
3697c478bd9Sstevel@tonic-gate if (config_info->proxy_passwd != NULL)
3707c478bd9Sstevel@tonic-gate free(config_info->proxy_passwd);
3717c478bd9Sstevel@tonic-gate config_info->proxy_passwd = NULL;
3727c478bd9Sstevel@tonic-gate
3737c478bd9Sstevel@tonic-gate if (config_info->tls_cert_db != NULL)
3747c478bd9Sstevel@tonic-gate free(config_info->tls_cert_db);
3757c478bd9Sstevel@tonic-gate config_info->tls_cert_db = NULL;
3767c478bd9Sstevel@tonic-gate }
3777c478bd9Sstevel@tonic-gate
3787c478bd9Sstevel@tonic-gate /*
3797c478bd9Sstevel@tonic-gate * FUNCTION: free_proxy_info
3807c478bd9Sstevel@tonic-gate *
3817c478bd9Sstevel@tonic-gate * Frees __nis_ldap_proxy_info
3827c478bd9Sstevel@tonic-gate *
3837c478bd9Sstevel@tonic-gate * INPUT: __nis_ldap_proxy_info
3847c478bd9Sstevel@tonic-gate */
3857c478bd9Sstevel@tonic-gate
3867c478bd9Sstevel@tonic-gate void
free_proxy_info(__nis_ldap_proxy_info * proxy_info)3877c478bd9Sstevel@tonic-gate free_proxy_info(__nis_ldap_proxy_info *proxy_info)
3887c478bd9Sstevel@tonic-gate {
3897c478bd9Sstevel@tonic-gate if (proxy_info->tls_cert_db != NULL)
3907c478bd9Sstevel@tonic-gate free(proxy_info->tls_cert_db);
3917c478bd9Sstevel@tonic-gate proxy_info->tls_cert_db = NULL;
3927c478bd9Sstevel@tonic-gate
3937c478bd9Sstevel@tonic-gate if (proxy_info->default_servers != NULL)
3947c478bd9Sstevel@tonic-gate free(proxy_info->default_servers);
3957c478bd9Sstevel@tonic-gate proxy_info->default_servers = NULL;
3967c478bd9Sstevel@tonic-gate
3977c478bd9Sstevel@tonic-gate if (proxy_info->default_search_base != NULL)
3987c478bd9Sstevel@tonic-gate free(proxy_info->default_search_base);
3997c478bd9Sstevel@tonic-gate proxy_info->default_search_base = NULL;
4007c478bd9Sstevel@tonic-gate
4017c478bd9Sstevel@tonic-gate if (proxy_info->proxy_dn != NULL)
4027c478bd9Sstevel@tonic-gate free(proxy_info->proxy_dn);
4037c478bd9Sstevel@tonic-gate proxy_info->proxy_dn = NULL;
4047c478bd9Sstevel@tonic-gate
4057c478bd9Sstevel@tonic-gate if (proxy_info->proxy_passwd != NULL)
4067c478bd9Sstevel@tonic-gate free(proxy_info->proxy_passwd);
4077c478bd9Sstevel@tonic-gate proxy_info->proxy_passwd = NULL;
4087c478bd9Sstevel@tonic-gate
4097c478bd9Sstevel@tonic-gate if (proxy_info->default_nis_domain != NULL)
4107c478bd9Sstevel@tonic-gate free(proxy_info->default_nis_domain);
4117c478bd9Sstevel@tonic-gate proxy_info->default_nis_domain = NULL;
4127c478bd9Sstevel@tonic-gate }
4137c478bd9Sstevel@tonic-gate
4147c478bd9Sstevel@tonic-gate /*
4157c478bd9Sstevel@tonic-gate * FUNCTION: free_object_dn
4167c478bd9Sstevel@tonic-gate *
4177c478bd9Sstevel@tonic-gate * Frees __nis_object_dn_t
4187c478bd9Sstevel@tonic-gate *
4197c478bd9Sstevel@tonic-gate * INPUT: __nis_object_dn_t
4207c478bd9Sstevel@tonic-gate */
4217c478bd9Sstevel@tonic-gate
4227c478bd9Sstevel@tonic-gate void
free_object_dn(__nis_object_dn_t * obj_dn)4237c478bd9Sstevel@tonic-gate free_object_dn(__nis_object_dn_t *obj_dn)
4247c478bd9Sstevel@tonic-gate {
4257c478bd9Sstevel@tonic-gate __nis_object_dn_t *t;
4267c478bd9Sstevel@tonic-gate int i;
4277c478bd9Sstevel@tonic-gate
4287c478bd9Sstevel@tonic-gate while (obj_dn != NULL) {
4297c478bd9Sstevel@tonic-gate if (obj_dn->read.base != NULL)
4307c478bd9Sstevel@tonic-gate free(obj_dn->read.base);
4317c478bd9Sstevel@tonic-gate obj_dn->read.base = NULL;
4327c478bd9Sstevel@tonic-gate if (obj_dn->read.attrs != NULL)
4337c478bd9Sstevel@tonic-gate free(obj_dn->read.attrs);
4347c478bd9Sstevel@tonic-gate obj_dn->read.attrs = NULL;
4357c478bd9Sstevel@tonic-gate if (obj_dn->write.base != NULL)
4367c478bd9Sstevel@tonic-gate free(obj_dn->write.base);
4377c478bd9Sstevel@tonic-gate obj_dn->write.base = NULL;
4387c478bd9Sstevel@tonic-gate if (obj_dn->write.attrs != NULL)
4397c478bd9Sstevel@tonic-gate free(obj_dn->write.attrs);
4407c478bd9Sstevel@tonic-gate obj_dn->write.attrs = NULL;
4417c478bd9Sstevel@tonic-gate if (obj_dn->dbIdName != NULL)
4427c478bd9Sstevel@tonic-gate free(obj_dn->dbIdName);
4437c478bd9Sstevel@tonic-gate obj_dn->dbIdName = NULL;
4447c478bd9Sstevel@tonic-gate for (i = 0; i < obj_dn->numDbIds; i++)
4457c478bd9Sstevel@tonic-gate free_mapping_rule(obj_dn->dbId[i]);
4467c478bd9Sstevel@tonic-gate obj_dn->numDbIds = 0;
4477c478bd9Sstevel@tonic-gate
4487c478bd9Sstevel@tonic-gate if (obj_dn->dbId != NULL)
4497c478bd9Sstevel@tonic-gate free(obj_dn->dbId);
4507c478bd9Sstevel@tonic-gate obj_dn->dbId = NULL;
4517c478bd9Sstevel@tonic-gate
4527c478bd9Sstevel@tonic-gate t = obj_dn;
4537c478bd9Sstevel@tonic-gate obj_dn = obj_dn->next;
4547c478bd9Sstevel@tonic-gate free(t);
4557c478bd9Sstevel@tonic-gate }
4567c478bd9Sstevel@tonic-gate }
4577c478bd9Sstevel@tonic-gate
4587c478bd9Sstevel@tonic-gate /*
4597c478bd9Sstevel@tonic-gate * FUNCTION: free_index
4607c478bd9Sstevel@tonic-gate *
4617c478bd9Sstevel@tonic-gate * Frees __nis_index_t
4627c478bd9Sstevel@tonic-gate *
4637c478bd9Sstevel@tonic-gate * INPUT: __nis_index_t
4647c478bd9Sstevel@tonic-gate */
4657c478bd9Sstevel@tonic-gate
4667c478bd9Sstevel@tonic-gate void
free_index(__nis_index_t * index)4677c478bd9Sstevel@tonic-gate free_index(__nis_index_t *index)
4687c478bd9Sstevel@tonic-gate {
4697c478bd9Sstevel@tonic-gate int i;
4707c478bd9Sstevel@tonic-gate for (i = 0; i < index->numIndexes; i++) {
4717c478bd9Sstevel@tonic-gate free(index->name[i]);
4727c478bd9Sstevel@tonic-gate free_mapping_format(index->value[i]);
4737c478bd9Sstevel@tonic-gate }
4747c478bd9Sstevel@tonic-gate index->numIndexes = 0;
4757c478bd9Sstevel@tonic-gate if (index->name != NULL)
4767c478bd9Sstevel@tonic-gate free(index->name);
4777c478bd9Sstevel@tonic-gate index->name = NULL;
4787c478bd9Sstevel@tonic-gate if (index->value != NULL)
4797c478bd9Sstevel@tonic-gate free(index->value);
4807c478bd9Sstevel@tonic-gate index->value = NULL;
4817c478bd9Sstevel@tonic-gate }
4827c478bd9Sstevel@tonic-gate
4837c478bd9Sstevel@tonic-gate /*
4847c478bd9Sstevel@tonic-gate * FUNCTION: free_mapping_item
4857c478bd9Sstevel@tonic-gate *
4867c478bd9Sstevel@tonic-gate * Frees __nis_mapping_item_t
4877c478bd9Sstevel@tonic-gate *
4887c478bd9Sstevel@tonic-gate * INPUT: __nis_mapping_item_t
4897c478bd9Sstevel@tonic-gate */
4907c478bd9Sstevel@tonic-gate
4917c478bd9Sstevel@tonic-gate void
free_mapping_item(__nis_mapping_item_t * item)4927c478bd9Sstevel@tonic-gate free_mapping_item(__nis_mapping_item_t *item)
4937c478bd9Sstevel@tonic-gate {
4947c478bd9Sstevel@tonic-gate if (item == NULL)
4957c478bd9Sstevel@tonic-gate return;
4967c478bd9Sstevel@tonic-gate
4977c478bd9Sstevel@tonic-gate if (item->name != NULL)
4987c478bd9Sstevel@tonic-gate free(item->name);
4997c478bd9Sstevel@tonic-gate item->name = NULL;
5007c478bd9Sstevel@tonic-gate if (item->type == mit_nisplus) {
5017c478bd9Sstevel@tonic-gate free_index(&item->searchSpec.obj.index);
5027c478bd9Sstevel@tonic-gate if (item->searchSpec.obj.name != NULL)
5037c478bd9Sstevel@tonic-gate free(item->searchSpec.obj.name);
5047c478bd9Sstevel@tonic-gate item->searchSpec.obj.name = NULL;
5057c478bd9Sstevel@tonic-gate } else if (item->type == mit_ldap) {
5067c478bd9Sstevel@tonic-gate if (item->searchSpec.triple.base != NULL)
5077c478bd9Sstevel@tonic-gate free(item->searchSpec.triple.base);
5087c478bd9Sstevel@tonic-gate item->searchSpec.triple.base = NULL;
5097c478bd9Sstevel@tonic-gate if (item->searchSpec.triple.attrs != NULL)
5107c478bd9Sstevel@tonic-gate free(item->searchSpec.triple.attrs);
5117c478bd9Sstevel@tonic-gate item->searchSpec.triple.attrs = NULL;
5127c478bd9Sstevel@tonic-gate if (item->searchSpec.triple.element != NULL) {
5137c478bd9Sstevel@tonic-gate free_mapping_element(
5147c478bd9Sstevel@tonic-gate item->searchSpec.triple.element);
5157c478bd9Sstevel@tonic-gate free(item->searchSpec.triple.element);
5167c478bd9Sstevel@tonic-gate }
5177c478bd9Sstevel@tonic-gate item->searchSpec.triple.element = NULL;
5187c478bd9Sstevel@tonic-gate }
5197c478bd9Sstevel@tonic-gate if (item->exItem != NULL) {
5207c478bd9Sstevel@tonic-gate free_mapping_item(item->exItem);
5217c478bd9Sstevel@tonic-gate free(item->exItem);
5227c478bd9Sstevel@tonic-gate item->exItem = 0;
5237c478bd9Sstevel@tonic-gate }
5247c478bd9Sstevel@tonic-gate }
5257c478bd9Sstevel@tonic-gate
5267c478bd9Sstevel@tonic-gate /*
5277c478bd9Sstevel@tonic-gate * FUNCTION: free_mapping_format
5287c478bd9Sstevel@tonic-gate *
5297c478bd9Sstevel@tonic-gate * Frees __nis_mapping_format_t
5307c478bd9Sstevel@tonic-gate *
5317c478bd9Sstevel@tonic-gate * INPUT: __nis_mapping_format_t
5327c478bd9Sstevel@tonic-gate */
5337c478bd9Sstevel@tonic-gate
5347c478bd9Sstevel@tonic-gate void
free_mapping_format(__nis_mapping_format_t * fmt)5357c478bd9Sstevel@tonic-gate free_mapping_format(__nis_mapping_format_t *fmt)
5367c478bd9Sstevel@tonic-gate {
5377c478bd9Sstevel@tonic-gate __nis_mapping_format_t *f = fmt;
5387c478bd9Sstevel@tonic-gate
5397c478bd9Sstevel@tonic-gate while (fmt->type != mmt_end) {
5407c478bd9Sstevel@tonic-gate switch (fmt->type) {
5417c478bd9Sstevel@tonic-gate case mmt_item:
5427c478bd9Sstevel@tonic-gate break;
5437c478bd9Sstevel@tonic-gate case mmt_string:
5447c478bd9Sstevel@tonic-gate if (fmt->match.string != NULL)
5457c478bd9Sstevel@tonic-gate free(fmt->match.string);
5467c478bd9Sstevel@tonic-gate fmt->match.string = NULL;
5477c478bd9Sstevel@tonic-gate break;
5487c478bd9Sstevel@tonic-gate case mmt_single:
5497c478bd9Sstevel@tonic-gate if (fmt->match.single.lo != NULL)
5507c478bd9Sstevel@tonic-gate free(fmt->match.single.lo);
5517c478bd9Sstevel@tonic-gate fmt->match.single.lo = NULL;
5527c478bd9Sstevel@tonic-gate if (fmt->match.single.hi != NULL)
5537c478bd9Sstevel@tonic-gate free(fmt->match.single.hi);
5547c478bd9Sstevel@tonic-gate fmt->match.single.hi = NULL;
5557c478bd9Sstevel@tonic-gate break;
5567c478bd9Sstevel@tonic-gate case mmt_limit:
5577c478bd9Sstevel@tonic-gate break;
5587c478bd9Sstevel@tonic-gate case mmt_any:
5597c478bd9Sstevel@tonic-gate break;
5607c478bd9Sstevel@tonic-gate case mmt_berstring:
5617c478bd9Sstevel@tonic-gate case mmt_berstring_null:
5627c478bd9Sstevel@tonic-gate if (fmt->match.berString != NULL)
5637c478bd9Sstevel@tonic-gate free(fmt->match.berString);
5647c478bd9Sstevel@tonic-gate fmt->match.berString = NULL;
5657c478bd9Sstevel@tonic-gate break;
5667c478bd9Sstevel@tonic-gate case mmt_begin:
5677c478bd9Sstevel@tonic-gate break;
5687c478bd9Sstevel@tonic-gate case mmt_end:
5697c478bd9Sstevel@tonic-gate break;
5707c478bd9Sstevel@tonic-gate }
5717c478bd9Sstevel@tonic-gate fmt++;
5727c478bd9Sstevel@tonic-gate }
5737c478bd9Sstevel@tonic-gate free(f);
5747c478bd9Sstevel@tonic-gate }
5757c478bd9Sstevel@tonic-gate
5767c478bd9Sstevel@tonic-gate /*
5777c478bd9Sstevel@tonic-gate * FUNCTION: free_mapping_sub_element
5787c478bd9Sstevel@tonic-gate *
5797c478bd9Sstevel@tonic-gate * Frees __nis_mapping_sub_element_t
5807c478bd9Sstevel@tonic-gate *
5817c478bd9Sstevel@tonic-gate * INPUT: __nis_mapping_sub_element_t
5827c478bd9Sstevel@tonic-gate */
5837c478bd9Sstevel@tonic-gate
5847c478bd9Sstevel@tonic-gate void
free_mapping_sub_element(__nis_mapping_sub_element_t * sub)5857c478bd9Sstevel@tonic-gate free_mapping_sub_element(__nis_mapping_sub_element_t *sub)
5867c478bd9Sstevel@tonic-gate {
5877c478bd9Sstevel@tonic-gate int i;
5887c478bd9Sstevel@tonic-gate
5897c478bd9Sstevel@tonic-gate switch (sub->type) {
5907c478bd9Sstevel@tonic-gate case me_item:
5917c478bd9Sstevel@tonic-gate free_mapping_item(&sub->element.item);
5927c478bd9Sstevel@tonic-gate break;
5937c478bd9Sstevel@tonic-gate case me_print:
5947c478bd9Sstevel@tonic-gate if (sub->element.print.fmt != NULL)
5957c478bd9Sstevel@tonic-gate free_mapping_format(sub->element.print.fmt);
5967c478bd9Sstevel@tonic-gate sub->element.print.fmt = NULL;
5977c478bd9Sstevel@tonic-gate for (i = 0; i < sub->element.print.numItems; i++)
5987c478bd9Sstevel@tonic-gate free_mapping_item(&sub->element.print.item[i]);
5997c478bd9Sstevel@tonic-gate sub->element.print.numItems = 0;
6007c478bd9Sstevel@tonic-gate if (sub->element.print.item != NULL)
6017c478bd9Sstevel@tonic-gate free(sub->element.print.item);
6027c478bd9Sstevel@tonic-gate sub->element.print.item = NULL;
6037c478bd9Sstevel@tonic-gate break;
6047c478bd9Sstevel@tonic-gate case me_split:
6057c478bd9Sstevel@tonic-gate free_mapping_item(&sub->element.split.item);
6067c478bd9Sstevel@tonic-gate break;
6077c478bd9Sstevel@tonic-gate case me_extract:
6087c478bd9Sstevel@tonic-gate if (sub->element.extract.fmt != NULL)
6097c478bd9Sstevel@tonic-gate free_mapping_format(sub->element.extract.fmt);
6107c478bd9Sstevel@tonic-gate sub->element.extract.fmt = NULL;
6117c478bd9Sstevel@tonic-gate free_mapping_item(&sub->element.extract.item);
6127c478bd9Sstevel@tonic-gate break;
6137c478bd9Sstevel@tonic-gate }
6147c478bd9Sstevel@tonic-gate }
6157c478bd9Sstevel@tonic-gate
6167c478bd9Sstevel@tonic-gate /*
6177c478bd9Sstevel@tonic-gate * FUNCTION: read_line
6187c478bd9Sstevel@tonic-gate *
6197c478bd9Sstevel@tonic-gate * Gets next line in buffer - using '\' at end of line
6207c478bd9Sstevel@tonic-gate * to indicate continuation. Lines beginning with # are
6217c478bd9Sstevel@tonic-gate * ignored. start_line_num and start_line_num are
6227c478bd9Sstevel@tonic-gate * maintained to track the line number currently being
6237c478bd9Sstevel@tonic-gate * parsed.
6247c478bd9Sstevel@tonic-gate *
6257c478bd9Sstevel@tonic-gate * RETURN VALUE: The number of characters read. 0 for
6267c478bd9Sstevel@tonic-gate * eof, -1 for error
6277c478bd9Sstevel@tonic-gate *
6287c478bd9Sstevel@tonic-gate * INPUT: file descriptor, buffer, and buffer size
6297c478bd9Sstevel@tonic-gate */
6307c478bd9Sstevel@tonic-gate
6317c478bd9Sstevel@tonic-gate int
read_line(int fd,char * buffer,int buflen)6327c478bd9Sstevel@tonic-gate read_line(int fd, char *buffer, int buflen)
6337c478bd9Sstevel@tonic-gate {
6347c478bd9Sstevel@tonic-gate int linelen;
6357c478bd9Sstevel@tonic-gate int rc;
6367c478bd9Sstevel@tonic-gate char c;
6377c478bd9Sstevel@tonic-gate bool_t skip_line = FALSE;
6387c478bd9Sstevel@tonic-gate bool_t begin_line = TRUE;
6397c478bd9Sstevel@tonic-gate static bool_t prev_cr = FALSE;
6407c478bd9Sstevel@tonic-gate
6417c478bd9Sstevel@tonic-gate start_line_num = cur_line_num;
6427c478bd9Sstevel@tonic-gate (void) memset(buffer, 0, buflen);
6437c478bd9Sstevel@tonic-gate for (; p_error == no_parse_error; ) {
6447c478bd9Sstevel@tonic-gate linelen = 0;
6457c478bd9Sstevel@tonic-gate while (linelen < buflen) {
6467c478bd9Sstevel@tonic-gate rc = read(fd, &c, 1);
6477c478bd9Sstevel@tonic-gate if (1 == rc) {
6487c478bd9Sstevel@tonic-gate if (c == '\n' || c == '\r') {
6497c478bd9Sstevel@tonic-gate if (c == '\n') {
6507c478bd9Sstevel@tonic-gate if (prev_cr) {
6517c478bd9Sstevel@tonic-gate prev_cr = FALSE;
6527c478bd9Sstevel@tonic-gate continue;
6537c478bd9Sstevel@tonic-gate } else {
6547c478bd9Sstevel@tonic-gate if (linelen == 0)
6557c478bd9Sstevel@tonic-gate start_line_num =
6567c478bd9Sstevel@tonic-gate cur_line_num;
6577c478bd9Sstevel@tonic-gate else {
6587c478bd9Sstevel@tonic-gate if (
6597c478bd9Sstevel@tonic-gate is_string_ok(
6607c478bd9Sstevel@tonic-gate buffer,
6617c478bd9Sstevel@tonic-gate linelen)) {
6627c478bd9Sstevel@tonic-gate (void) memset(
6637c478bd9Sstevel@tonic-gate buffer, 0,
6647c478bd9Sstevel@tonic-gate linelen);
6657c478bd9Sstevel@tonic-gate linelen = 0;
6667c478bd9Sstevel@tonic-gate cur_line_num++;
6677c478bd9Sstevel@tonic-gate begin_line =
6687c478bd9Sstevel@tonic-gate TRUE;
6697c478bd9Sstevel@tonic-gate continue;
6707c478bd9Sstevel@tonic-gate }
6717c478bd9Sstevel@tonic-gate }
6727c478bd9Sstevel@tonic-gate cur_line_num++;
6737c478bd9Sstevel@tonic-gate }
6747c478bd9Sstevel@tonic-gate prev_cr = FALSE;
6757c478bd9Sstevel@tonic-gate } else {
6767c478bd9Sstevel@tonic-gate prev_cr = TRUE;
6777c478bd9Sstevel@tonic-gate if (linelen == 0)
6787c478bd9Sstevel@tonic-gate start_line_num =
6797c478bd9Sstevel@tonic-gate cur_line_num;
6807c478bd9Sstevel@tonic-gate cur_line_num++;
6817c478bd9Sstevel@tonic-gate }
6827c478bd9Sstevel@tonic-gate if (skip_line) {
6837c478bd9Sstevel@tonic-gate skip_line = FALSE;
6847c478bd9Sstevel@tonic-gate if (linelen == 0)
6857c478bd9Sstevel@tonic-gate start_line_num =
6867c478bd9Sstevel@tonic-gate cur_line_num;
6877c478bd9Sstevel@tonic-gate } else if (linelen > 0 &&
6887c478bd9Sstevel@tonic-gate buffer[linelen - 1]
6897c478bd9Sstevel@tonic-gate == ESCAPE_CHAR) {
6907c478bd9Sstevel@tonic-gate --linelen;
6917c478bd9Sstevel@tonic-gate } else if (linelen > 0) {
6927c478bd9Sstevel@tonic-gate buffer[linelen] = '\0';
6937c478bd9Sstevel@tonic-gate return (linelen);
6947c478bd9Sstevel@tonic-gate }
6957c478bd9Sstevel@tonic-gate begin_line = TRUE;
6967c478bd9Sstevel@tonic-gate } else {
6977c478bd9Sstevel@tonic-gate if (begin_line)
6987c478bd9Sstevel@tonic-gate skip_line = c == POUND_SIGN;
6997c478bd9Sstevel@tonic-gate begin_line = FALSE;
7007c478bd9Sstevel@tonic-gate if (!skip_line)
7017c478bd9Sstevel@tonic-gate buffer[linelen++] = c;
7027c478bd9Sstevel@tonic-gate }
7037c478bd9Sstevel@tonic-gate } else {
7047c478bd9Sstevel@tonic-gate if (linelen > 0 &&
7057c478bd9Sstevel@tonic-gate buffer[linelen - 1] == ESCAPE_CHAR) {
7067c478bd9Sstevel@tonic-gate /* continuation on last line */
7077c478bd9Sstevel@tonic-gate p_error = parse_bad_continuation_error;
7087c478bd9Sstevel@tonic-gate return (-1);
7097c478bd9Sstevel@tonic-gate } else {
7107c478bd9Sstevel@tonic-gate buffer[linelen] = '\0';
7117c478bd9Sstevel@tonic-gate return (linelen);
7127c478bd9Sstevel@tonic-gate }
7137c478bd9Sstevel@tonic-gate }
7147c478bd9Sstevel@tonic-gate }
7157c478bd9Sstevel@tonic-gate p_error = parse_line_too_long;
7167c478bd9Sstevel@tonic-gate }
7177c478bd9Sstevel@tonic-gate return (-1);
7187c478bd9Sstevel@tonic-gate }
7197c478bd9Sstevel@tonic-gate
7207c478bd9Sstevel@tonic-gate /*
7217c478bd9Sstevel@tonic-gate * FUNCTION: finish_parse
7227c478bd9Sstevel@tonic-gate *
7237c478bd9Sstevel@tonic-gate * Adds any elements not configured, fully qualifies
7247c478bd9Sstevel@tonic-gate * names
7257c478bd9Sstevel@tonic-gate *
7267c478bd9Sstevel@tonic-gate * RETURN VALUE: 0 on success, -1 on failure
7277c478bd9Sstevel@tonic-gate */
7287c478bd9Sstevel@tonic-gate
7297c478bd9Sstevel@tonic-gate int
finish_parse(__nis_ldap_proxy_info * proxy_info,__nis_table_mapping_t ** table_mapping)7307c478bd9Sstevel@tonic-gate finish_parse(
7317c478bd9Sstevel@tonic-gate __nis_ldap_proxy_info *proxy_info,
7327c478bd9Sstevel@tonic-gate __nis_table_mapping_t **table_mapping)
7337c478bd9Sstevel@tonic-gate {
7347c478bd9Sstevel@tonic-gate __nis_table_mapping_t *t;
7357c478bd9Sstevel@tonic-gate __nis_table_mapping_t *t1;
7367c478bd9Sstevel@tonic-gate __nis_table_mapping_t *t2;
7377c478bd9Sstevel@tonic-gate __nis_table_mapping_t *t_del = NULL;
7387c478bd9Sstevel@tonic-gate int i;
7397c478bd9Sstevel@tonic-gate int j;
7407c478bd9Sstevel@tonic-gate int k;
7417c478bd9Sstevel@tonic-gate __nis_object_dn_t *objectDN;
7427c478bd9Sstevel@tonic-gate __nis_mapping_rlhs_t *lhs;
7437c478bd9Sstevel@tonic-gate __nis_mapping_element_t *e;
7447c478bd9Sstevel@tonic-gate char *s;
7457c478bd9Sstevel@tonic-gate int errnum;
7467c478bd9Sstevel@tonic-gate
7477c478bd9Sstevel@tonic-gate /* set to default those values yet set */
7487c478bd9Sstevel@tonic-gate if (proxy_info->auth_method ==
7497c478bd9Sstevel@tonic-gate (auth_method_t)NO_VALUE_SET) {
7507c478bd9Sstevel@tonic-gate p_error = parse_no_proxy_auth_error;
7517c478bd9Sstevel@tonic-gate report_error(NULL, NULL);
7527c478bd9Sstevel@tonic-gate return (-1);
7537c478bd9Sstevel@tonic-gate }
7547c478bd9Sstevel@tonic-gate
7557c478bd9Sstevel@tonic-gate if (proxy_info->default_servers == NULL) {
7567c478bd9Sstevel@tonic-gate p_error = parse_no_ldap_server_error;
7577c478bd9Sstevel@tonic-gate report_error(NULL, NULL);
7587c478bd9Sstevel@tonic-gate return (-1);
7597c478bd9Sstevel@tonic-gate }
7607c478bd9Sstevel@tonic-gate
7617c478bd9Sstevel@tonic-gate if (proxy_info->tls_method == (tls_method_t)NO_VALUE_SET)
7627c478bd9Sstevel@tonic-gate proxy_info->tls_method = no_tls;
7637c478bd9Sstevel@tonic-gate else if (proxy_info->tls_method == ssl_tls &&
7647c478bd9Sstevel@tonic-gate (proxy_info->tls_cert_db == NULL ||
7657c478bd9Sstevel@tonic-gate *proxy_info->tls_cert_db == '\0')) {
7667c478bd9Sstevel@tonic-gate p_error = parse_no_cert_db;
7677c478bd9Sstevel@tonic-gate report_error(NULL, NULL);
7687c478bd9Sstevel@tonic-gate return (-1);
7697c478bd9Sstevel@tonic-gate }
7707c478bd9Sstevel@tonic-gate
7717c478bd9Sstevel@tonic-gate if (proxy_info->default_nis_domain == NULL)
7727c478bd9Sstevel@tonic-gate proxy_info->default_nis_domain =
7737c478bd9Sstevel@tonic-gate s_strdup(__nis_rpc_domain());
7747c478bd9Sstevel@tonic-gate else if (*proxy_info->default_nis_domain == '\0') {
7757c478bd9Sstevel@tonic-gate free(proxy_info->default_nis_domain);
7767c478bd9Sstevel@tonic-gate proxy_info->default_nis_domain =
7777c478bd9Sstevel@tonic-gate s_strdup(__nis_rpc_domain());
7787c478bd9Sstevel@tonic-gate }
7797c478bd9Sstevel@tonic-gate if (proxy_info->default_nis_domain != NULL)
7807c478bd9Sstevel@tonic-gate append_dot(&proxy_info->default_nis_domain);
7817c478bd9Sstevel@tonic-gate
7827c478bd9Sstevel@tonic-gate if (proxy_info->tls_method == ssl_tls) {
7837c478bd9Sstevel@tonic-gate if ((errnum = ldapssl_client_init(
7847c478bd9Sstevel@tonic-gate proxy_info->tls_cert_db, NULL)) < 0) {
7857c478bd9Sstevel@tonic-gate p_error = parse_ldapssl_client_init_error;
7867c478bd9Sstevel@tonic-gate report_error(ldapssl_err2string(errnum), NULL);
7877c478bd9Sstevel@tonic-gate return (-1);
7887c478bd9Sstevel@tonic-gate }
7897c478bd9Sstevel@tonic-gate }
7907c478bd9Sstevel@tonic-gate
7917c478bd9Sstevel@tonic-gate if (proxy_info->default_search_base == NULL)
7927c478bd9Sstevel@tonic-gate proxy_info->default_search_base =
7937c478bd9Sstevel@tonic-gate get_default_ldap_base(proxy_info->default_nis_domain);
7947c478bd9Sstevel@tonic-gate
7957c478bd9Sstevel@tonic-gate /* convert a relative dn to a fullly qualified dn */
7967c478bd9Sstevel@tonic-gate (void) make_full_dn(&proxy_info->proxy_dn,
7977c478bd9Sstevel@tonic-gate proxy_info->default_search_base);
7987c478bd9Sstevel@tonic-gate
7997c478bd9Sstevel@tonic-gate if (p_error != no_parse_error) {
8007c478bd9Sstevel@tonic-gate report_error(NULL, NULL);
8017c478bd9Sstevel@tonic-gate return (-1);
8027c478bd9Sstevel@tonic-gate }
8037c478bd9Sstevel@tonic-gate
8047c478bd9Sstevel@tonic-gate /*
8057c478bd9Sstevel@tonic-gate * Create a list of potential delete mappings
8067c478bd9Sstevel@tonic-gate * those have NULL objectDNs, but badly also rules
8077c478bd9Sstevel@tonic-gate * that are missing object dn's will be included.
8087c478bd9Sstevel@tonic-gate * We will use the ttl field to determine if the
8097c478bd9Sstevel@tonic-gate * delete rule is actually used
8107c478bd9Sstevel@tonic-gate */
8117c478bd9Sstevel@tonic-gate t2 = NULL;
8127c478bd9Sstevel@tonic-gate for (t = *table_mapping; t != NULL; t = t1) {
8137c478bd9Sstevel@tonic-gate t1 = t->next;
8147c478bd9Sstevel@tonic-gate if (t->objectDN == NULL) {
8157c478bd9Sstevel@tonic-gate if (t2 == NULL)
8167c478bd9Sstevel@tonic-gate *table_mapping = t1;
8177c478bd9Sstevel@tonic-gate else
8187c478bd9Sstevel@tonic-gate t2->next = t1;
8197c478bd9Sstevel@tonic-gate t->next = t_del;
8207c478bd9Sstevel@tonic-gate t_del = t;
8217c478bd9Sstevel@tonic-gate t->ttl = 0;
8227c478bd9Sstevel@tonic-gate } else
8237c478bd9Sstevel@tonic-gate t2 = t;
8247c478bd9Sstevel@tonic-gate }
8257c478bd9Sstevel@tonic-gate
8267c478bd9Sstevel@tonic-gate for (t = *table_mapping; t != NULL; t = t->next) {
8277c478bd9Sstevel@tonic-gate objectDN = t->objectDN;
8287c478bd9Sstevel@tonic-gate while (objectDN != NULL) {
8297c478bd9Sstevel@tonic-gate if (objectDN->dbIdName != NULL) {
8307c478bd9Sstevel@tonic-gate s = objectDN->dbIdName;
8317c478bd9Sstevel@tonic-gate t1 = find_table_mapping(s, strlen(s), t_del);
8327c478bd9Sstevel@tonic-gate if (t1 == NULL) {
8337c478bd9Sstevel@tonic-gate p_error = parse_no_db_del_mapping_rule;
8347c478bd9Sstevel@tonic-gate report_error2(objectDN->dbIdName, t->dbId);
8357c478bd9Sstevel@tonic-gate return (-1);
8367c478bd9Sstevel@tonic-gate } else if (t1->objName != NULL ||
8377c478bd9Sstevel@tonic-gate t1->numRulesToLDAP == 0 ||
8387c478bd9Sstevel@tonic-gate t1->numRulesFromLDAP != 0) {
8397c478bd9Sstevel@tonic-gate p_error = parse_invalid_db_del_mapping_rule;
8407c478bd9Sstevel@tonic-gate report_error(t1->dbId, NULL);
8417c478bd9Sstevel@tonic-gate return (-1);
8427c478bd9Sstevel@tonic-gate }
8437c478bd9Sstevel@tonic-gate objectDN->dbId =
8447c478bd9Sstevel@tonic-gate dup_mapping_rules(t1->ruleToLDAP,
8457c478bd9Sstevel@tonic-gate t1->numRulesToLDAP);
8467c478bd9Sstevel@tonic-gate if (objectDN->dbId == NULL) {
8477c478bd9Sstevel@tonic-gate break;
8487c478bd9Sstevel@tonic-gate }
8497c478bd9Sstevel@tonic-gate objectDN->numDbIds = t1->numRulesToLDAP;
8507c478bd9Sstevel@tonic-gate t1->ttl++;
8517c478bd9Sstevel@tonic-gate }
8527c478bd9Sstevel@tonic-gate objectDN = objectDN->next;
8537c478bd9Sstevel@tonic-gate }
8547c478bd9Sstevel@tonic-gate }
8557c478bd9Sstevel@tonic-gate
8567c478bd9Sstevel@tonic-gate for (t = t_del; t != NULL; t = t1) {
8577c478bd9Sstevel@tonic-gate t1 = t->next;
8587c478bd9Sstevel@tonic-gate if (t->ttl == 0) {
8597c478bd9Sstevel@tonic-gate p_error = parse_no_object_dn;
8607c478bd9Sstevel@tonic-gate report_error(t->dbId, NULL);
8617c478bd9Sstevel@tonic-gate }
8627c478bd9Sstevel@tonic-gate free_table_mapping(t);
8637c478bd9Sstevel@tonic-gate }
8647c478bd9Sstevel@tonic-gate
8657c478bd9Sstevel@tonic-gate if (p_error != no_parse_error)
8667c478bd9Sstevel@tonic-gate return (-1);
8677c478bd9Sstevel@tonic-gate
8687c478bd9Sstevel@tonic-gate /* set to default those table mapping values yet set */
8697c478bd9Sstevel@tonic-gate for (t = *table_mapping; t != NULL; t = t->next) {
8707c478bd9Sstevel@tonic-gate if (t->objName == 0) {
8717c478bd9Sstevel@tonic-gate p_error = parse_no_object_dn;
8727c478bd9Sstevel@tonic-gate report_error(t->dbId, NULL);
8737c478bd9Sstevel@tonic-gate return (-1);
8747c478bd9Sstevel@tonic-gate }
8757c478bd9Sstevel@tonic-gate if (!yp2ldap) {
8767c478bd9Sstevel@tonic-gate if (!add_domain(&t->objName,
8777c478bd9Sstevel@tonic-gate proxy_info->default_nis_domain)) {
8787c478bd9Sstevel@tonic-gate report_error(NULL, NULL);
8797c478bd9Sstevel@tonic-gate return (-1);
8807c478bd9Sstevel@tonic-gate }
8817c478bd9Sstevel@tonic-gate }
8827c478bd9Sstevel@tonic-gate if (t->initTtlHi == (time_t)NO_VALUE_SET)
8837c478bd9Sstevel@tonic-gate t->initTtlHi = DEFAULT_TTL_HIGH;
8847c478bd9Sstevel@tonic-gate if (t->initTtlLo == (time_t)NO_VALUE_SET)
8857c478bd9Sstevel@tonic-gate t->initTtlLo = DEFAULT_TTL_LOW;
8867c478bd9Sstevel@tonic-gate if (t->ttl == (time_t)NO_VALUE_SET)
8877c478bd9Sstevel@tonic-gate t->ttl = DEFAULT_TTL;
8887c478bd9Sstevel@tonic-gate objectDN = t->objectDN;
8897c478bd9Sstevel@tonic-gate
8907c478bd9Sstevel@tonic-gate /* fixup relative dn's */
8917c478bd9Sstevel@tonic-gate while (objectDN != NULL) {
8927c478bd9Sstevel@tonic-gate if (!yp2ldap) {
8937c478bd9Sstevel@tonic-gate if (!make_full_dn(&objectDN->read.base,
8947c478bd9Sstevel@tonic-gate proxy_info->default_search_base))
8957c478bd9Sstevel@tonic-gate break;
8967c478bd9Sstevel@tonic-gate }
8977c478bd9Sstevel@tonic-gate if (objectDN->write.scope != LDAP_SCOPE_UNKNOWN) {
8987c478bd9Sstevel@tonic-gate if (objectDN->write.base != NULL &&
8997c478bd9Sstevel@tonic-gate !make_full_dn(&objectDN->write.base,
9007c478bd9Sstevel@tonic-gate proxy_info->default_search_base))
9017c478bd9Sstevel@tonic-gate break;
9027c478bd9Sstevel@tonic-gate if (objectDN->write.base == NULL) {
9037c478bd9Sstevel@tonic-gate objectDN->write.base =
9047c478bd9Sstevel@tonic-gate s_strdup(objectDN->read.base);
9057c478bd9Sstevel@tonic-gate if (objectDN->write.base == NULL)
9067c478bd9Sstevel@tonic-gate break;
9077c478bd9Sstevel@tonic-gate }
9087c478bd9Sstevel@tonic-gate }
9097c478bd9Sstevel@tonic-gate objectDN = objectDN->next;
9107c478bd9Sstevel@tonic-gate }
9117c478bd9Sstevel@tonic-gate
9127c478bd9Sstevel@tonic-gate if (p_error != no_parse_error) {
9137c478bd9Sstevel@tonic-gate report_error(NULL, NULL);
9147c478bd9Sstevel@tonic-gate return (-1);
9157c478bd9Sstevel@tonic-gate }
9167c478bd9Sstevel@tonic-gate
9177c478bd9Sstevel@tonic-gate /* Check for ruleToLDAP with no rhs */
9187c478bd9Sstevel@tonic-gate for (i = 0; i < t->numRulesToLDAP; i++) {
9197c478bd9Sstevel@tonic-gate if (t->ruleToLDAP[i]->rhs.numElements == 0) {
9207c478bd9Sstevel@tonic-gate p_error = parse_unexpected_data_end_rule;
9217c478bd9Sstevel@tonic-gate report_error(t->dbId, NULL);
9227c478bd9Sstevel@tonic-gate return (-1);
9237c478bd9Sstevel@tonic-gate }
9247c478bd9Sstevel@tonic-gate }
9257c478bd9Sstevel@tonic-gate
9267c478bd9Sstevel@tonic-gate /* populate cols field */
9277c478bd9Sstevel@tonic-gate if (!yp2ldap) {
9287c478bd9Sstevel@tonic-gate for (i = 0; i < t->numRulesFromLDAP; i++) {
9297c478bd9Sstevel@tonic-gate lhs = &t->ruleFromLDAP[i]->lhs;
9307c478bd9Sstevel@tonic-gate for (j = 0; j < lhs->numElements; j++) {
9317c478bd9Sstevel@tonic-gate e = &lhs->element[j];
9327c478bd9Sstevel@tonic-gate switch (e->type) {
9337c478bd9Sstevel@tonic-gate case me_item:
9347c478bd9Sstevel@tonic-gate if (!add_column(t,
9357c478bd9Sstevel@tonic-gate e->element.item.name)) {
9367c478bd9Sstevel@tonic-gate report_error(
9377c478bd9Sstevel@tonic-gate NULL, NULL);
9387c478bd9Sstevel@tonic-gate return (-1);
9397c478bd9Sstevel@tonic-gate }
9407c478bd9Sstevel@tonic-gate break;
9417c478bd9Sstevel@tonic-gate case me_match:
9427c478bd9Sstevel@tonic-gate for (k = 0;
9437c478bd9Sstevel@tonic-gate k < e->element.match.numItems;
9447c478bd9Sstevel@tonic-gate k++)
9457c478bd9Sstevel@tonic-gate if (!add_column(t,
9467c478bd9Sstevel@tonic-gate e->element.match.item[k].name)) {
9477c478bd9Sstevel@tonic-gate report_error(
9487c478bd9Sstevel@tonic-gate NULL, NULL);
9497c478bd9Sstevel@tonic-gate return (-1);
9507c478bd9Sstevel@tonic-gate }
9517c478bd9Sstevel@tonic-gate break;
9527c478bd9Sstevel@tonic-gate }
9537c478bd9Sstevel@tonic-gate }
9547c478bd9Sstevel@tonic-gate }
9557c478bd9Sstevel@tonic-gate }
9567c478bd9Sstevel@tonic-gate }
9577c478bd9Sstevel@tonic-gate return (0);
9587c478bd9Sstevel@tonic-gate }
9597c478bd9Sstevel@tonic-gate
9607c478bd9Sstevel@tonic-gate /*
9617c478bd9Sstevel@tonic-gate * FUNCTION: set_default_values
9627c478bd9Sstevel@tonic-gate *
9637c478bd9Sstevel@tonic-gate * Sets unconfigured values to their default value
9647c478bd9Sstevel@tonic-gate */
9657c478bd9Sstevel@tonic-gate
9667c478bd9Sstevel@tonic-gate void
set_default_values(__nis_ldap_proxy_info * proxy_info,__nis_config_t * config_info,__nisdb_table_mapping_t * table_info)9677c478bd9Sstevel@tonic-gate set_default_values(__nis_ldap_proxy_info *proxy_info,
9687c478bd9Sstevel@tonic-gate __nis_config_t *config_info, __nisdb_table_mapping_t *table_info)
9697c478bd9Sstevel@tonic-gate {
9707c478bd9Sstevel@tonic-gate if (proxy_info->bind_timeout.tv_sec == (time_t)NO_VALUE_SET)
9717c478bd9Sstevel@tonic-gate proxy_info->bind_timeout.tv_sec = DEFAULT_BIND_TIMEOUT;
9727c478bd9Sstevel@tonic-gate if (proxy_info->search_timeout.tv_sec == (time_t)NO_VALUE_SET)
9737c478bd9Sstevel@tonic-gate proxy_info->search_timeout.tv_sec =
9747c478bd9Sstevel@tonic-gate (yp2ldap)?DEFAULT_YP_SEARCH_TIMEOUT:
9757c478bd9Sstevel@tonic-gate DEFAULT_SEARCH_TIMEOUT;
9767c478bd9Sstevel@tonic-gate if (proxy_info->modify_timeout.tv_sec == (time_t)NO_VALUE_SET)
9777c478bd9Sstevel@tonic-gate proxy_info->modify_timeout.tv_sec = DEFAULT_MODIFY_TIMEOUT;
9787c478bd9Sstevel@tonic-gate if (proxy_info->add_timeout.tv_sec == (time_t)NO_VALUE_SET)
9797c478bd9Sstevel@tonic-gate proxy_info->add_timeout.tv_sec = DEFAULT_ADD_TIMEOUT;
9807c478bd9Sstevel@tonic-gate if (proxy_info->delete_timeout.tv_sec == (time_t)NO_VALUE_SET)
9817c478bd9Sstevel@tonic-gate proxy_info->delete_timeout.tv_sec = DEFAULT_DELETE_TIMEOUT;
9827c478bd9Sstevel@tonic-gate
9837c478bd9Sstevel@tonic-gate if (proxy_info->search_time_limit == (int)NO_VALUE_SET)
9847c478bd9Sstevel@tonic-gate proxy_info->search_time_limit = DEFAULT_SEARCH_TIME_LIMIT;
9857c478bd9Sstevel@tonic-gate if (proxy_info->search_size_limit == (int)NO_VALUE_SET)
9867c478bd9Sstevel@tonic-gate proxy_info->search_size_limit = DEFAULT_SEARCH_SIZE_LIMIT;
9877c478bd9Sstevel@tonic-gate
9887c478bd9Sstevel@tonic-gate if (proxy_info->follow_referral == (follow_referral_t)NO_VALUE_SET)
9897c478bd9Sstevel@tonic-gate proxy_info->follow_referral = no_follow;
9907c478bd9Sstevel@tonic-gate
9917c478bd9Sstevel@tonic-gate switch (config_info->initialUpdate) {
9927c478bd9Sstevel@tonic-gate case (__nis_initial_update_t)NO_VALUE_SET:
9937c478bd9Sstevel@tonic-gate case (__nis_initial_update_t)INITIAL_UPDATE_NO_ACTION:
9947c478bd9Sstevel@tonic-gate case (__nis_initial_update_t)NO_INITIAL_UPDATE_NO_ACTION:
9957c478bd9Sstevel@tonic-gate config_info->initialUpdate = ini_none;
9967c478bd9Sstevel@tonic-gate break;
9977c478bd9Sstevel@tonic-gate case (__nis_initial_update_t)FROM_NO_INITIAL_UPDATE:
9987c478bd9Sstevel@tonic-gate config_info->initialUpdate = from_ldap;
9997c478bd9Sstevel@tonic-gate break;
10007c478bd9Sstevel@tonic-gate case (__nis_initial_update_t)TO_NO_INITIAL_UPDATE:
10017c478bd9Sstevel@tonic-gate config_info->initialUpdate = to_ldap;
10027c478bd9Sstevel@tonic-gate break;
10037c478bd9Sstevel@tonic-gate }
10047c478bd9Sstevel@tonic-gate if (config_info->threadCreationError ==
10057c478bd9Sstevel@tonic-gate (__nis_thread_creation_error_t)NO_VALUE_SET)
10067c478bd9Sstevel@tonic-gate config_info->threadCreationError = pass_error;
10077c478bd9Sstevel@tonic-gate if (config_info->threadCreationErrorTimeout.attempts == NO_VALUE_SET)
10087c478bd9Sstevel@tonic-gate config_info->threadCreationErrorTimeout.attempts =
10097c478bd9Sstevel@tonic-gate DEFAULT_THREAD_ERROR_ATTEMPTS;
10107c478bd9Sstevel@tonic-gate if (config_info->threadCreationErrorTimeout.timeout ==
10117c478bd9Sstevel@tonic-gate (time_t)NO_VALUE_SET)
10127c478bd9Sstevel@tonic-gate config_info->threadCreationErrorTimeout.timeout =
10137c478bd9Sstevel@tonic-gate DEFAULT_THREAD_ERROR_TIME_OUT;
10147c478bd9Sstevel@tonic-gate if (config_info->dumpError ==
10157c478bd9Sstevel@tonic-gate (__nis_dump_error_t)NO_VALUE_SET)
10167c478bd9Sstevel@tonic-gate config_info->dumpError = de_retry;
10177c478bd9Sstevel@tonic-gate if (config_info->dumpErrorTimeout.attempts == NO_VALUE_SET)
10187c478bd9Sstevel@tonic-gate config_info->dumpErrorTimeout.attempts =
10197c478bd9Sstevel@tonic-gate DEFAULT_DUMP_ERROR_ATTEMPTS;
10207c478bd9Sstevel@tonic-gate if (config_info->dumpErrorTimeout.timeout == (time_t)NO_VALUE_SET)
10217c478bd9Sstevel@tonic-gate config_info->dumpErrorTimeout.timeout =
10227c478bd9Sstevel@tonic-gate DEFAULT_DUMP_ERROR_TIME_OUT;
10237c478bd9Sstevel@tonic-gate if (config_info->resyncService ==
10247c478bd9Sstevel@tonic-gate (__nis_resync_service_t)NO_VALUE_SET)
10257c478bd9Sstevel@tonic-gate config_info->resyncService = from_copy;
10267c478bd9Sstevel@tonic-gate if (config_info->updateBatching ==
10277c478bd9Sstevel@tonic-gate (__nis_update_batching_t)NO_VALUE_SET)
10287c478bd9Sstevel@tonic-gate config_info->updateBatching = accumulate;
10297c478bd9Sstevel@tonic-gate if (config_info->updateBatchingTimeout.timeout == (time_t)NO_VALUE_SET)
10307c478bd9Sstevel@tonic-gate config_info->updateBatchingTimeout.timeout =
10317c478bd9Sstevel@tonic-gate DEFAULT_BATCHING_TIME_OUT;
10327c478bd9Sstevel@tonic-gate if (config_info->numberOfServiceThreads == (int)NO_VALUE_SET)
10337c478bd9Sstevel@tonic-gate config_info->numberOfServiceThreads =
10347c478bd9Sstevel@tonic-gate DEFAULT_NUMBER_OF_THREADS;
10357c478bd9Sstevel@tonic-gate if (config_info->emulate_yp == (int)NO_VALUE_SET)
10367c478bd9Sstevel@tonic-gate config_info->emulate_yp =
10377c478bd9Sstevel@tonic-gate DEFAULT_YP_EMULATION;
10387c478bd9Sstevel@tonic-gate if (config_info->maxRPCRecordSize == (int)NO_VALUE_SET)
10397c478bd9Sstevel@tonic-gate config_info->maxRPCRecordSize = RPC_MAXDATASIZE;
10407c478bd9Sstevel@tonic-gate
10417c478bd9Sstevel@tonic-gate if (table_info->retrieveError ==
10427c478bd9Sstevel@tonic-gate (__nis_retrieve_error_t)NO_VALUE_SET)
10437c478bd9Sstevel@tonic-gate table_info->retrieveError = use_cached;
10447c478bd9Sstevel@tonic-gate if (table_info->retrieveErrorRetry.attempts == NO_VALUE_SET)
10457c478bd9Sstevel@tonic-gate table_info->retrieveErrorRetry.attempts =
10467c478bd9Sstevel@tonic-gate DEFAULT_RETRIEVE_ERROR_ATTEMPTS;
10477c478bd9Sstevel@tonic-gate if (table_info->retrieveErrorRetry.timeout == (time_t)NO_VALUE_SET)
10487c478bd9Sstevel@tonic-gate table_info->retrieveErrorRetry.timeout =
10497c478bd9Sstevel@tonic-gate DEFAULT_RETRIEVE_ERROR_TIME_OUT;
10507c478bd9Sstevel@tonic-gate if (table_info->storeError ==
10517c478bd9Sstevel@tonic-gate (__nis_store_error_t)NO_VALUE_SET)
10527c478bd9Sstevel@tonic-gate table_info->storeError = sto_retry;
10537c478bd9Sstevel@tonic-gate if (table_info->storeErrorRetry.attempts == NO_VALUE_SET)
10547c478bd9Sstevel@tonic-gate table_info->storeErrorRetry.attempts =
10557c478bd9Sstevel@tonic-gate DEFAULT_STORE_ERROR_ATTEMPTS;
10567c478bd9Sstevel@tonic-gate if (table_info->storeErrorRetry.timeout == (time_t)NO_VALUE_SET)
10577c478bd9Sstevel@tonic-gate table_info->storeErrorRetry.timeout =
10587c478bd9Sstevel@tonic-gate DEFAULT_STORE_ERROR_TIME_OUT;
10597c478bd9Sstevel@tonic-gate if (table_info->refreshError ==
10607c478bd9Sstevel@tonic-gate (__nis_refresh_error_t)NO_VALUE_SET)
10617c478bd9Sstevel@tonic-gate table_info->refreshError = continue_using;
10627c478bd9Sstevel@tonic-gate if (table_info->refreshErrorRetry.attempts == NO_VALUE_SET)
10637c478bd9Sstevel@tonic-gate table_info->refreshErrorRetry.attempts =
10647c478bd9Sstevel@tonic-gate DEFAULT_REFRESH_ERROR_ATTEMPTS;
10657c478bd9Sstevel@tonic-gate if (table_info->refreshErrorRetry.timeout == (time_t)NO_VALUE_SET)
10667c478bd9Sstevel@tonic-gate table_info->refreshErrorRetry.timeout =
10677c478bd9Sstevel@tonic-gate DEFAULT_REFRESH_ERROR_TIME_OUT;
10687c478bd9Sstevel@tonic-gate if (table_info->matchFetch ==
10697c478bd9Sstevel@tonic-gate (__nis_match_fetch_t)NO_VALUE_SET)
10707c478bd9Sstevel@tonic-gate table_info->matchFetch = no_match_only;
10717c478bd9Sstevel@tonic-gate }
10727c478bd9Sstevel@tonic-gate
10737c478bd9Sstevel@tonic-gate __nis_table_mapping_t *
find_table_mapping(const char * s,int len,__nis_table_mapping_t * table_mapping)10747c478bd9Sstevel@tonic-gate find_table_mapping(const char *s, int len, __nis_table_mapping_t *table_mapping)
10757c478bd9Sstevel@tonic-gate {
10767c478bd9Sstevel@tonic-gate __nis_table_mapping_t *t;
10777c478bd9Sstevel@tonic-gate
10787c478bd9Sstevel@tonic-gate for (t = table_mapping; t != NULL; t = t->next)
10797c478bd9Sstevel@tonic-gate if (strlen(t->dbId) == len &&
10807c478bd9Sstevel@tonic-gate strncasecmp(t->dbId, s, len) == 0)
10817c478bd9Sstevel@tonic-gate break;
10827c478bd9Sstevel@tonic-gate return (t);
10837c478bd9Sstevel@tonic-gate }
10847c478bd9Sstevel@tonic-gate
10857c478bd9Sstevel@tonic-gate void
append_dot(char ** str)10867c478bd9Sstevel@tonic-gate append_dot(char **str)
10877c478bd9Sstevel@tonic-gate {
10887c478bd9Sstevel@tonic-gate char *s = *str;
10897c478bd9Sstevel@tonic-gate int len = strlen(s);
10907c478bd9Sstevel@tonic-gate
10917c478bd9Sstevel@tonic-gate if (len == 0 || s[len - 1] != PERIOD_CHAR) {
10927c478bd9Sstevel@tonic-gate s = s_realloc(s, len + 2);
10937c478bd9Sstevel@tonic-gate if (s != NULL) {
10947c478bd9Sstevel@tonic-gate s[len] = PERIOD_CHAR;
10957c478bd9Sstevel@tonic-gate s[len+1] = '\0';
10967c478bd9Sstevel@tonic-gate *str = s;
10977c478bd9Sstevel@tonic-gate }
10987c478bd9Sstevel@tonic-gate }
10997c478bd9Sstevel@tonic-gate }
11007c478bd9Sstevel@tonic-gate
11017c478bd9Sstevel@tonic-gate void
append_comma(char ** str)11027c478bd9Sstevel@tonic-gate append_comma(char **str)
11037c478bd9Sstevel@tonic-gate {
11047c478bd9Sstevel@tonic-gate
11057c478bd9Sstevel@tonic-gate char *s = *str;
11067c478bd9Sstevel@tonic-gate int len = strlen(s);
11077c478bd9Sstevel@tonic-gate
11087c478bd9Sstevel@tonic-gate if (len == 0 || s[len - 1] != COMMA_CHAR) {
11097c478bd9Sstevel@tonic-gate s = s_realloc(s, len + 2);
11107c478bd9Sstevel@tonic-gate if (s != NULL) {
11117c478bd9Sstevel@tonic-gate s[len] = COMMA_CHAR;
11127c478bd9Sstevel@tonic-gate s[len+1] = '\0';
11137c478bd9Sstevel@tonic-gate *str = s;
11147c478bd9Sstevel@tonic-gate }
11157c478bd9Sstevel@tonic-gate }
11167c478bd9Sstevel@tonic-gate }
11177c478bd9Sstevel@tonic-gate
11187c478bd9Sstevel@tonic-gate /*
11197c478bd9Sstevel@tonic-gate * FUNCTION: make_full_dn
11207c478bd9Sstevel@tonic-gate *
11217c478bd9Sstevel@tonic-gate * Appends the base dn if a relative ldap dn
11227c478bd9Sstevel@tonic-gate * (invoked only for LDAP write cycle)
11237c478bd9Sstevel@tonic-gate *
11247c478bd9Sstevel@tonic-gate * RETURN VALUE: FALSE if error
11257c478bd9Sstevel@tonic-gate * TRUE if __nis_index_t returned
11267c478bd9Sstevel@tonic-gate *
11277c478bd9Sstevel@tonic-gate * INPUT: the relative dn and ldap base
11287c478bd9Sstevel@tonic-gate */
11297c478bd9Sstevel@tonic-gate
11307c478bd9Sstevel@tonic-gate bool_t
make_full_dn(char ** dn,const char * base)11317c478bd9Sstevel@tonic-gate make_full_dn(char **dn, const char *base)
11327c478bd9Sstevel@tonic-gate {
11337c478bd9Sstevel@tonic-gate int len;
11347c478bd9Sstevel@tonic-gate int len1;
11357c478bd9Sstevel@tonic-gate
11367c478bd9Sstevel@tonic-gate if (*dn == NULL) {
11377c478bd9Sstevel@tonic-gate *dn = s_strdup(base);
11387c478bd9Sstevel@tonic-gate } else {
11397c478bd9Sstevel@tonic-gate len = strlen(*dn);
11407c478bd9Sstevel@tonic-gate if (len > 0 && (*dn)[len-1] == COMMA_CHAR) {
11417c478bd9Sstevel@tonic-gate len1 = strlen(base) + 1;
11427c478bd9Sstevel@tonic-gate *dn = s_realloc(*dn, len + len1);
11437c478bd9Sstevel@tonic-gate if (*dn != NULL)
11447c478bd9Sstevel@tonic-gate (void) strcpy(*dn + len, base);
11457c478bd9Sstevel@tonic-gate }
11467c478bd9Sstevel@tonic-gate }
11477c478bd9Sstevel@tonic-gate return (*dn != NULL);
11487c478bd9Sstevel@tonic-gate }
11497c478bd9Sstevel@tonic-gate
11507c478bd9Sstevel@tonic-gate /*
11517c478bd9Sstevel@tonic-gate * FUNCTION: make_fqdn
11527c478bd9Sstevel@tonic-gate *
11537c478bd9Sstevel@tonic-gate * Appends the base dn if a relative ldap dn
11547c478bd9Sstevel@tonic-gate * (invoked only for LDAP read cycle)
11557c478bd9Sstevel@tonic-gate *
11567c478bd9Sstevel@tonic-gate * RETURN VALUE: FALSE if error
11577c478bd9Sstevel@tonic-gate * TRUE if success
11587c478bd9Sstevel@tonic-gate *
11597c478bd9Sstevel@tonic-gate * INPUT: the relative dn and ldap base
11607c478bd9Sstevel@tonic-gate */
11617c478bd9Sstevel@tonic-gate bool_t
make_fqdn(__nis_object_dn_t * dn,const char * base)11627c478bd9Sstevel@tonic-gate make_fqdn(__nis_object_dn_t *dn, const char *base)
11637c478bd9Sstevel@tonic-gate {
11647c478bd9Sstevel@tonic-gate int len;
11657c478bd9Sstevel@tonic-gate int len1;
11667c478bd9Sstevel@tonic-gate
11677c478bd9Sstevel@tonic-gate if (dn == NULL) {
11687c478bd9Sstevel@tonic-gate return (FALSE);
11697c478bd9Sstevel@tonic-gate } else {
11707c478bd9Sstevel@tonic-gate while (dn != NULL && dn->read.base != NULL) {
11717c478bd9Sstevel@tonic-gate len = strlen(dn->read.base);
11727c478bd9Sstevel@tonic-gate if (len > 0 && (dn->read.base)[len-1] == COMMA_CHAR) {
11737c478bd9Sstevel@tonic-gate len1 = strlen(base) + 1;
11747c478bd9Sstevel@tonic-gate dn->read.base =
11757c478bd9Sstevel@tonic-gate s_realloc(dn->read.base, len + len1);
11767c478bd9Sstevel@tonic-gate if (dn->read.base != NULL)
11777c478bd9Sstevel@tonic-gate (void) strlcpy(dn->read.base + len,
11787c478bd9Sstevel@tonic-gate base, len1);
11797c478bd9Sstevel@tonic-gate else
11807c478bd9Sstevel@tonic-gate return (FALSE);
11817c478bd9Sstevel@tonic-gate }
11827c478bd9Sstevel@tonic-gate dn = dn->next;
11837c478bd9Sstevel@tonic-gate }
11847c478bd9Sstevel@tonic-gate }
11857c478bd9Sstevel@tonic-gate return (TRUE);
11867c478bd9Sstevel@tonic-gate }
11877c478bd9Sstevel@tonic-gate
11887c478bd9Sstevel@tonic-gate /*
11897c478bd9Sstevel@tonic-gate * FUNCTION: get_default_ldap_base
11907c478bd9Sstevel@tonic-gate *
11917c478bd9Sstevel@tonic-gate * Gets the default LDAP search base from the
11927c478bd9Sstevel@tonic-gate * nis+ default domain
11937c478bd9Sstevel@tonic-gate *
11947c478bd9Sstevel@tonic-gate * RETURN VALUE: NULL if error
11957c478bd9Sstevel@tonic-gate * the default base
11967c478bd9Sstevel@tonic-gate *
11977c478bd9Sstevel@tonic-gate * INPUT: the nis domain
11987c478bd9Sstevel@tonic-gate */
11997c478bd9Sstevel@tonic-gate
12007c478bd9Sstevel@tonic-gate char *
get_default_ldap_base(const char * domain)12017c478bd9Sstevel@tonic-gate get_default_ldap_base(const char *domain)
12027c478bd9Sstevel@tonic-gate {
12037c478bd9Sstevel@tonic-gate
12047c478bd9Sstevel@tonic-gate int len = strlen(domain);
12057c478bd9Sstevel@tonic-gate int i;
12067c478bd9Sstevel@tonic-gate int count = len + 4;
12077c478bd9Sstevel@tonic-gate char *base;
12087c478bd9Sstevel@tonic-gate
12097c478bd9Sstevel@tonic-gate for (i = 0; i < len - 1; i++)
12107c478bd9Sstevel@tonic-gate if (domain[i] == PERIOD_CHAR)
12117c478bd9Sstevel@tonic-gate count += 4;
12127c478bd9Sstevel@tonic-gate if ((base = malloc(count)) == NULL) {
12137c478bd9Sstevel@tonic-gate p_error = parse_no_mem_error;
12147c478bd9Sstevel@tonic-gate } else {
12157c478bd9Sstevel@tonic-gate (void) strcpy(base, "dc=");
12167c478bd9Sstevel@tonic-gate count = 3;
12177c478bd9Sstevel@tonic-gate for (i = 0; i < len - 1; i++) {
12187c478bd9Sstevel@tonic-gate if (domain[i] == PERIOD_CHAR) {
12197c478bd9Sstevel@tonic-gate (void) strcpy(base + count, ",dc=");
12207c478bd9Sstevel@tonic-gate count += 4;
12217c478bd9Sstevel@tonic-gate } else {
12227c478bd9Sstevel@tonic-gate base[count++] = domain[i];
12237c478bd9Sstevel@tonic-gate }
12247c478bd9Sstevel@tonic-gate }
12257c478bd9Sstevel@tonic-gate base[count] = '\0';
12267c478bd9Sstevel@tonic-gate }
12277c478bd9Sstevel@tonic-gate return (base);
12287c478bd9Sstevel@tonic-gate }
12297c478bd9Sstevel@tonic-gate
12307c478bd9Sstevel@tonic-gate /*
12317c478bd9Sstevel@tonic-gate * FUNCTION: add_domain
12327c478bd9Sstevel@tonic-gate *
12337c478bd9Sstevel@tonic-gate * Appends the base domain if a relative object name
12347c478bd9Sstevel@tonic-gate *
12357c478bd9Sstevel@tonic-gate * RETURN VALUE: FALSE if error
12367c478bd9Sstevel@tonic-gate * TRUE if OK
12377c478bd9Sstevel@tonic-gate *
12387c478bd9Sstevel@tonic-gate * INPUT: the relative object name and base domain
12397c478bd9Sstevel@tonic-gate * name
12407c478bd9Sstevel@tonic-gate */
12417c478bd9Sstevel@tonic-gate
12427c478bd9Sstevel@tonic-gate bool_t
add_domain(char ** objName,const char * domain)12437c478bd9Sstevel@tonic-gate add_domain(char **objName, const char *domain)
12447c478bd9Sstevel@tonic-gate {
12457c478bd9Sstevel@tonic-gate int len;
12467c478bd9Sstevel@tonic-gate int len1;
12477c478bd9Sstevel@tonic-gate bool_t trailing_dot;
12487c478bd9Sstevel@tonic-gate char *obj_name;
12497c478bd9Sstevel@tonic-gate
12507c478bd9Sstevel@tonic-gate if (domain == NULL || *objName == NULL) {
12517c478bd9Sstevel@tonic-gate p_error = parse_internal_error;
12527c478bd9Sstevel@tonic-gate return (FALSE);
12537c478bd9Sstevel@tonic-gate }
12547c478bd9Sstevel@tonic-gate len1 = strlen(domain);
12557c478bd9Sstevel@tonic-gate trailing_dot = (len1 > 0 && domain[len1 - 1] == PERIOD_CHAR) ?
12567c478bd9Sstevel@tonic-gate 0 : 1;
12577c478bd9Sstevel@tonic-gate len = strlen(*objName);
12587c478bd9Sstevel@tonic-gate if (len == 0 || (*objName)[len - 1] != PERIOD_CHAR) {
12597c478bd9Sstevel@tonic-gate obj_name = s_realloc(*objName,
12607c478bd9Sstevel@tonic-gate len + len1 + 2 + trailing_dot);
12617c478bd9Sstevel@tonic-gate if (obj_name != NULL) {
12627c478bd9Sstevel@tonic-gate obj_name[len++] = PERIOD_CHAR;
12637c478bd9Sstevel@tonic-gate (void) strcpy(obj_name + len, domain);
12647c478bd9Sstevel@tonic-gate if (trailing_dot != 0) {
12657c478bd9Sstevel@tonic-gate obj_name[len + len1] = PERIOD_CHAR;
12667c478bd9Sstevel@tonic-gate obj_name[len + len1 + 1] = '\0';
12677c478bd9Sstevel@tonic-gate }
12687c478bd9Sstevel@tonic-gate *objName = obj_name;
12697c478bd9Sstevel@tonic-gate }
12707c478bd9Sstevel@tonic-gate }
12717c478bd9Sstevel@tonic-gate
12727c478bd9Sstevel@tonic-gate return (*objName != NULL);
12737c478bd9Sstevel@tonic-gate }
12747c478bd9Sstevel@tonic-gate
12757c478bd9Sstevel@tonic-gate bool_t
dup_index(__nis_index_t * in,__nis_index_t * out)12767c478bd9Sstevel@tonic-gate dup_index(__nis_index_t *in, __nis_index_t *out)
12777c478bd9Sstevel@tonic-gate {
12787c478bd9Sstevel@tonic-gate int i;
12797c478bd9Sstevel@tonic-gate int j;
12807c478bd9Sstevel@tonic-gate
12817c478bd9Sstevel@tonic-gate out->name = (char **)s_calloc(in->numIndexes, sizeof (char *));
12827c478bd9Sstevel@tonic-gate if (out->name == NULL)
12837c478bd9Sstevel@tonic-gate return (FALSE);
12847c478bd9Sstevel@tonic-gate out->value = (__nis_mapping_format_t **)
12857c478bd9Sstevel@tonic-gate s_calloc(in->numIndexes, sizeof (__nis_mapping_format_t *));
12867c478bd9Sstevel@tonic-gate if (out->value == NULL) {
12877c478bd9Sstevel@tonic-gate free(out->name);
12887c478bd9Sstevel@tonic-gate out->name = NULL;
12897c478bd9Sstevel@tonic-gate return (FALSE);
12907c478bd9Sstevel@tonic-gate }
12917c478bd9Sstevel@tonic-gate
12927c478bd9Sstevel@tonic-gate for (i = 0; i < in->numIndexes; i++) {
12937c478bd9Sstevel@tonic-gate out->name[i] = s_strdup(in->name[i]);
12947c478bd9Sstevel@tonic-gate if (out->name[i] == NULL)
12957c478bd9Sstevel@tonic-gate break;
12967c478bd9Sstevel@tonic-gate out->value[i] = dup_format_mapping(in->value[i]);
12977c478bd9Sstevel@tonic-gate if (out->value[i] == NULL)
12987c478bd9Sstevel@tonic-gate break;
12997c478bd9Sstevel@tonic-gate }
13007c478bd9Sstevel@tonic-gate if (i < in->numIndexes) {
13017c478bd9Sstevel@tonic-gate for (j = 0; j <= i; j++) {
13027c478bd9Sstevel@tonic-gate if (out->name[j] != NULL)
13037c478bd9Sstevel@tonic-gate free(out->name[j]);
13047c478bd9Sstevel@tonic-gate if (out->value[j] != NULL)
13057c478bd9Sstevel@tonic-gate free_mapping_format(out->value[j]);
13067c478bd9Sstevel@tonic-gate }
13077c478bd9Sstevel@tonic-gate free(out->name);
13087c478bd9Sstevel@tonic-gate out->name = NULL;
13097c478bd9Sstevel@tonic-gate free(out->value);
13107c478bd9Sstevel@tonic-gate out->value = NULL;
13117c478bd9Sstevel@tonic-gate } else {
13127c478bd9Sstevel@tonic-gate out->numIndexes = in->numIndexes;
13137c478bd9Sstevel@tonic-gate }
13147c478bd9Sstevel@tonic-gate return (i == in->numIndexes);
13157c478bd9Sstevel@tonic-gate }
13167c478bd9Sstevel@tonic-gate
13177c478bd9Sstevel@tonic-gate bool_t
dup_mapping_item(__nis_mapping_item_t * in,__nis_mapping_item_t * out)13187c478bd9Sstevel@tonic-gate dup_mapping_item(__nis_mapping_item_t *in, __nis_mapping_item_t *out)
13197c478bd9Sstevel@tonic-gate {
13207c478bd9Sstevel@tonic-gate bool_t ret;
13217c478bd9Sstevel@tonic-gate
13227c478bd9Sstevel@tonic-gate if (in->type == mit_nisplus) {
13237c478bd9Sstevel@tonic-gate ret = dup_index(&in->searchSpec.obj.index,
13247c478bd9Sstevel@tonic-gate &out->searchSpec.obj.index);
13257c478bd9Sstevel@tonic-gate if (!ret)
13267c478bd9Sstevel@tonic-gate return (ret);
13277c478bd9Sstevel@tonic-gate if (in->searchSpec.obj.name != NULL) {
13287c478bd9Sstevel@tonic-gate out->searchSpec.obj.name =
13297c478bd9Sstevel@tonic-gate s_strdup(in->searchSpec.obj.name);
13307c478bd9Sstevel@tonic-gate if (out->searchSpec.obj.name == NULL)
13317c478bd9Sstevel@tonic-gate return (FALSE);
13327c478bd9Sstevel@tonic-gate } else
13337c478bd9Sstevel@tonic-gate out->searchSpec.obj.name = NULL;
13347c478bd9Sstevel@tonic-gate } else if (in->type == mit_ldap) {
13357c478bd9Sstevel@tonic-gate if (in->searchSpec.triple.base != NULL) {
13367c478bd9Sstevel@tonic-gate out->searchSpec.triple.base =
13377c478bd9Sstevel@tonic-gate s_strdup(in->searchSpec.triple.base);
13387c478bd9Sstevel@tonic-gate if (out->searchSpec.triple.base == NULL)
13397c478bd9Sstevel@tonic-gate return (FALSE);
13407c478bd9Sstevel@tonic-gate } else
13417c478bd9Sstevel@tonic-gate out->searchSpec.triple.base = NULL;
13427c478bd9Sstevel@tonic-gate out->searchSpec.triple.scope =
13437c478bd9Sstevel@tonic-gate in->searchSpec.triple.scope;
13447c478bd9Sstevel@tonic-gate if (in->searchSpec.triple.attrs != NULL) {
13457c478bd9Sstevel@tonic-gate out->searchSpec.triple.attrs =
13467c478bd9Sstevel@tonic-gate s_strdup(in->searchSpec.triple.attrs);
13477c478bd9Sstevel@tonic-gate if (out->searchSpec.triple.attrs == NULL)
13487c478bd9Sstevel@tonic-gate return (FALSE);
13497c478bd9Sstevel@tonic-gate } else
13507c478bd9Sstevel@tonic-gate out->searchSpec.triple.attrs = NULL;
13517c478bd9Sstevel@tonic-gate if (in->searchSpec.triple.element != NULL) {
13527c478bd9Sstevel@tonic-gate out->searchSpec.triple.element =
13537c478bd9Sstevel@tonic-gate (__nis_mapping_element_t *)
13547c478bd9Sstevel@tonic-gate s_calloc(1, sizeof (__nis_mapping_element_t));
13557c478bd9Sstevel@tonic-gate if (out->searchSpec.triple.element != NULL)
13567c478bd9Sstevel@tonic-gate dup_mapping_element(
13577c478bd9Sstevel@tonic-gate in->searchSpec.triple.element,
13587c478bd9Sstevel@tonic-gate out->searchSpec.triple.element);
13597c478bd9Sstevel@tonic-gate if (out->searchSpec.triple.element == NULL)
13607c478bd9Sstevel@tonic-gate return (FALSE);
13617c478bd9Sstevel@tonic-gate } else
13627c478bd9Sstevel@tonic-gate out->searchSpec.triple.element = NULL;
13637c478bd9Sstevel@tonic-gate }
13647c478bd9Sstevel@tonic-gate
13657c478bd9Sstevel@tonic-gate if (in->name != NULL) {
13667c478bd9Sstevel@tonic-gate out->name = s_strdup(in->name);
13677c478bd9Sstevel@tonic-gate if (out->name == NULL)
13687c478bd9Sstevel@tonic-gate return (FALSE);
13697c478bd9Sstevel@tonic-gate } else
13707c478bd9Sstevel@tonic-gate out->name = NULL;
13717c478bd9Sstevel@tonic-gate out->type = in->type;
13727c478bd9Sstevel@tonic-gate out->repeat = in->repeat;
13737c478bd9Sstevel@tonic-gate if (in->exItem) {
13747c478bd9Sstevel@tonic-gate out->exItem = (__nis_mapping_item_t *)s_malloc
13757c478bd9Sstevel@tonic-gate (sizeof (__nis_mapping_item_t));
13767c478bd9Sstevel@tonic-gate if (out->exItem == NULL)
13777c478bd9Sstevel@tonic-gate return (FALSE);
13787c478bd9Sstevel@tonic-gate else {
13797c478bd9Sstevel@tonic-gate (void) memset
13807c478bd9Sstevel@tonic-gate (out->exItem, 0, sizeof (out->exItem[0]));
13817c478bd9Sstevel@tonic-gate if (!dup_mapping_item
13827c478bd9Sstevel@tonic-gate (in->exItem, out->exItem))
13837c478bd9Sstevel@tonic-gate p_error = parse_internal_error;
13847c478bd9Sstevel@tonic-gate }
13857c478bd9Sstevel@tonic-gate } else
13867c478bd9Sstevel@tonic-gate out->exItem = NULL;
13877c478bd9Sstevel@tonic-gate
13887c478bd9Sstevel@tonic-gate return (p_error == no_parse_error);
13897c478bd9Sstevel@tonic-gate }
13907c478bd9Sstevel@tonic-gate
13917c478bd9Sstevel@tonic-gate __nis_mapping_format_t *
dup_format_mapping(__nis_mapping_format_t * in)13927c478bd9Sstevel@tonic-gate dup_format_mapping(__nis_mapping_format_t *in)
13937c478bd9Sstevel@tonic-gate {
13947c478bd9Sstevel@tonic-gate int i;
13957c478bd9Sstevel@tonic-gate __nis_mapping_format_t *out;
13967c478bd9Sstevel@tonic-gate bool_t got_end;
13977c478bd9Sstevel@tonic-gate
13987c478bd9Sstevel@tonic-gate i = 0;
13997c478bd9Sstevel@tonic-gate while (in[i].type != mmt_end)
14007c478bd9Sstevel@tonic-gate i++;
14017c478bd9Sstevel@tonic-gate out = (__nis_mapping_format_t *)s_calloc(
14027c478bd9Sstevel@tonic-gate i + 1, sizeof (__nis_mapping_format_t));
14037c478bd9Sstevel@tonic-gate if (out != NULL) {
14047c478bd9Sstevel@tonic-gate got_end = FALSE;
14057c478bd9Sstevel@tonic-gate for (i = 0; !got_end; i++) {
14067c478bd9Sstevel@tonic-gate switch (in[i].type) {
14077c478bd9Sstevel@tonic-gate case mmt_item:
14087c478bd9Sstevel@tonic-gate break;
14097c478bd9Sstevel@tonic-gate case mmt_string:
14107c478bd9Sstevel@tonic-gate out[i].match.string =
14117c478bd9Sstevel@tonic-gate s_strdup(in[i].match.string);
14127c478bd9Sstevel@tonic-gate break;
14137c478bd9Sstevel@tonic-gate case mmt_single:
14147c478bd9Sstevel@tonic-gate out[i].match.single.numRange =
14157c478bd9Sstevel@tonic-gate in[i].match.single.numRange;
14167c478bd9Sstevel@tonic-gate out[i].match.single.lo =
14177c478bd9Sstevel@tonic-gate s_malloc(in[i].match.single.numRange);
14187c478bd9Sstevel@tonic-gate if (out[i].match.single.lo == NULL)
14197c478bd9Sstevel@tonic-gate break;
14207c478bd9Sstevel@tonic-gate out[i].match.single.hi =
14217c478bd9Sstevel@tonic-gate s_malloc(in[i].match.single.numRange);
14227c478bd9Sstevel@tonic-gate if (out[i].match.single.hi == NULL)
14237c478bd9Sstevel@tonic-gate break;
14247c478bd9Sstevel@tonic-gate memcpy(out[i].match.single.lo,
14257c478bd9Sstevel@tonic-gate in[i].match.single.lo,
14267c478bd9Sstevel@tonic-gate in[i].match.single.numRange);
14277c478bd9Sstevel@tonic-gate memcpy(out[i].match.single.hi,
14287c478bd9Sstevel@tonic-gate in[i].match.single.hi,
14297c478bd9Sstevel@tonic-gate in[i].match.single.numRange);
14307c478bd9Sstevel@tonic-gate break;
14317c478bd9Sstevel@tonic-gate case mmt_limit:
14327c478bd9Sstevel@tonic-gate out[i].match.limit = in[i].match.limit;
14337c478bd9Sstevel@tonic-gate break;
14347c478bd9Sstevel@tonic-gate case mmt_any:
14357c478bd9Sstevel@tonic-gate break;
14367c478bd9Sstevel@tonic-gate case mmt_berstring:
14377c478bd9Sstevel@tonic-gate out[i].match.berString =
14387c478bd9Sstevel@tonic-gate s_strdup(in[i].match.berString);
14397c478bd9Sstevel@tonic-gate break;
14407c478bd9Sstevel@tonic-gate case mmt_begin:
14417c478bd9Sstevel@tonic-gate break;
14427c478bd9Sstevel@tonic-gate case mmt_end:
14437c478bd9Sstevel@tonic-gate got_end = TRUE;
14447c478bd9Sstevel@tonic-gate break;
14457c478bd9Sstevel@tonic-gate default:
14467c478bd9Sstevel@tonic-gate p_error = parse_internal_error;
14477c478bd9Sstevel@tonic-gate }
14487c478bd9Sstevel@tonic-gate if (p_error != no_parse_error)
14497c478bd9Sstevel@tonic-gate break;
14507c478bd9Sstevel@tonic-gate out[i].type = in[i].type;
14517c478bd9Sstevel@tonic-gate }
14527c478bd9Sstevel@tonic-gate if (p_error != no_parse_error) {
14537c478bd9Sstevel@tonic-gate free_mapping_format(out);
14547c478bd9Sstevel@tonic-gate out = NULL;
14557c478bd9Sstevel@tonic-gate }
14567c478bd9Sstevel@tonic-gate }
14577c478bd9Sstevel@tonic-gate
14587c478bd9Sstevel@tonic-gate return (out);
14597c478bd9Sstevel@tonic-gate }
14607c478bd9Sstevel@tonic-gate
14617c478bd9Sstevel@tonic-gate bool_t
dup_mapping_sub_element(__nis_mapping_sub_element_t * in,__nis_mapping_sub_element_t * out)14627c478bd9Sstevel@tonic-gate dup_mapping_sub_element(
14637c478bd9Sstevel@tonic-gate __nis_mapping_sub_element_t *in,
14647c478bd9Sstevel@tonic-gate __nis_mapping_sub_element_t *out)
14657c478bd9Sstevel@tonic-gate {
14667c478bd9Sstevel@tonic-gate bool_t ret = FALSE;
14677c478bd9Sstevel@tonic-gate int i;
14687c478bd9Sstevel@tonic-gate
14697c478bd9Sstevel@tonic-gate switch (in->type) {
14707c478bd9Sstevel@tonic-gate case me_item:
14717c478bd9Sstevel@tonic-gate ret = dup_mapping_item(&in->element.item,
14727c478bd9Sstevel@tonic-gate &out->element.item);
14737c478bd9Sstevel@tonic-gate break;
14747c478bd9Sstevel@tonic-gate case me_print:
14757c478bd9Sstevel@tonic-gate out->element.print.fmt =
14767c478bd9Sstevel@tonic-gate dup_format_mapping(in->element.print.fmt);
14777c478bd9Sstevel@tonic-gate if (out->element.print.fmt == NULL)
14787c478bd9Sstevel@tonic-gate break;
14797c478bd9Sstevel@tonic-gate out->element.print.numItems =
14807c478bd9Sstevel@tonic-gate in->element.print.numItems;
14817c478bd9Sstevel@tonic-gate out->element.print.item = (__nis_mapping_item_t *)
14827c478bd9Sstevel@tonic-gate s_calloc(in->element.print.numItems,
14837c478bd9Sstevel@tonic-gate sizeof (__nis_mapping_item_t));
14847c478bd9Sstevel@tonic-gate if (out->element.print.item == NULL)
14857c478bd9Sstevel@tonic-gate break;
14867c478bd9Sstevel@tonic-gate for (i = 0; i < in->element.print.numItems; i++)
14877c478bd9Sstevel@tonic-gate if (!dup_mapping_item(
14887c478bd9Sstevel@tonic-gate &in->element.print.item[i],
14897c478bd9Sstevel@tonic-gate &out->element.print.item[i]))
14907c478bd9Sstevel@tonic-gate break;
14917c478bd9Sstevel@tonic-gate if (i < in->element.print.numItems)
14927c478bd9Sstevel@tonic-gate break;
14937c478bd9Sstevel@tonic-gate ret = TRUE;
14947c478bd9Sstevel@tonic-gate out->element.print.doElide = in->element.print.doElide;
14957c478bd9Sstevel@tonic-gate out->element.print.elide = in->element.print.elide;
14967c478bd9Sstevel@tonic-gate break;
14977c478bd9Sstevel@tonic-gate case me_split:
14987c478bd9Sstevel@tonic-gate ret = dup_mapping_item(&in->element.split.item,
14997c478bd9Sstevel@tonic-gate &out->element.split.item);
15007c478bd9Sstevel@tonic-gate out->element.split.delim = in->element.split.delim;
15017c478bd9Sstevel@tonic-gate break;
15027c478bd9Sstevel@tonic-gate case me_extract:
15037c478bd9Sstevel@tonic-gate out->element.extract.fmt =
15047c478bd9Sstevel@tonic-gate dup_format_mapping(in->element.extract.fmt);
15057c478bd9Sstevel@tonic-gate if (out->element.extract.fmt == NULL)
15067c478bd9Sstevel@tonic-gate break;
15077c478bd9Sstevel@tonic-gate ret = dup_mapping_item(&in->element.extract.item,
15087c478bd9Sstevel@tonic-gate &out->element.extract.item);
15097c478bd9Sstevel@tonic-gate break;
15107c478bd9Sstevel@tonic-gate default:
15117c478bd9Sstevel@tonic-gate p_error = parse_internal_error;
15127c478bd9Sstevel@tonic-gate }
15137c478bd9Sstevel@tonic-gate out->type = in->type;
15147c478bd9Sstevel@tonic-gate
15157c478bd9Sstevel@tonic-gate return (ret);
15167c478bd9Sstevel@tonic-gate }
15177c478bd9Sstevel@tonic-gate
15187c478bd9Sstevel@tonic-gate bool_t
dup_mapping_element(__nis_mapping_element_t * in,__nis_mapping_element_t * out)15197c478bd9Sstevel@tonic-gate dup_mapping_element(
15207c478bd9Sstevel@tonic-gate __nis_mapping_element_t *in,
15217c478bd9Sstevel@tonic-gate __nis_mapping_element_t *out)
15227c478bd9Sstevel@tonic-gate {
15237c478bd9Sstevel@tonic-gate bool_t ret = FALSE;
15247c478bd9Sstevel@tonic-gate int i;
15257c478bd9Sstevel@tonic-gate
15267c478bd9Sstevel@tonic-gate if (in == NULL)
15277c478bd9Sstevel@tonic-gate return (ret);
15287c478bd9Sstevel@tonic-gate
15297c478bd9Sstevel@tonic-gate switch (in->type) {
15307c478bd9Sstevel@tonic-gate case me_item:
15317c478bd9Sstevel@tonic-gate ret = dup_mapping_item(&in->element.item,
15327c478bd9Sstevel@tonic-gate &out->element.item);
15337c478bd9Sstevel@tonic-gate break;
15347c478bd9Sstevel@tonic-gate case me_print:
15357c478bd9Sstevel@tonic-gate out->element.print.fmt =
15367c478bd9Sstevel@tonic-gate dup_format_mapping(in->element.print.fmt);
15377c478bd9Sstevel@tonic-gate if (out->element.print.fmt == NULL)
15387c478bd9Sstevel@tonic-gate break;
15397c478bd9Sstevel@tonic-gate out->element.print.numSubElements =
15407c478bd9Sstevel@tonic-gate in->element.print.numSubElements;
15417c478bd9Sstevel@tonic-gate out->element.print.subElement =
15427c478bd9Sstevel@tonic-gate (__nis_mapping_sub_element_t *)
15437c478bd9Sstevel@tonic-gate s_calloc(in->element.print.numSubElements,
15447c478bd9Sstevel@tonic-gate sizeof (__nis_mapping_sub_element_t));
15457c478bd9Sstevel@tonic-gate if (out->element.print.subElement == NULL)
15467c478bd9Sstevel@tonic-gate break;
15477c478bd9Sstevel@tonic-gate for (i = 0; i < in->element.print.numSubElements; i++)
15487c478bd9Sstevel@tonic-gate if (!dup_mapping_sub_element(
15497c478bd9Sstevel@tonic-gate &in->element.print.subElement[i],
15507c478bd9Sstevel@tonic-gate &out->element.print.subElement[i]))
15517c478bd9Sstevel@tonic-gate break;
15527c478bd9Sstevel@tonic-gate if (i < in->element.print.numSubElements)
15537c478bd9Sstevel@tonic-gate break;
15547c478bd9Sstevel@tonic-gate ret = TRUE;
15557c478bd9Sstevel@tonic-gate out->element.print.doElide = in->element.print.doElide;
15567c478bd9Sstevel@tonic-gate out->element.print.elide = in->element.print.elide;
15577c478bd9Sstevel@tonic-gate break;
15587c478bd9Sstevel@tonic-gate case me_split:
15597c478bd9Sstevel@tonic-gate ret = dup_mapping_item(&in->element.split.item,
15607c478bd9Sstevel@tonic-gate &out->element.split.item);
15617c478bd9Sstevel@tonic-gate out->element.split.delim = in->element.split.delim;
15627c478bd9Sstevel@tonic-gate break;
15637c478bd9Sstevel@tonic-gate case me_match:
15647c478bd9Sstevel@tonic-gate out->element.match.fmt =
15657c478bd9Sstevel@tonic-gate dup_format_mapping(in->element.match.fmt);
15667c478bd9Sstevel@tonic-gate if (out->element.match.fmt == NULL)
15677c478bd9Sstevel@tonic-gate break;
15687c478bd9Sstevel@tonic-gate out->element.match.numItems =
15697c478bd9Sstevel@tonic-gate in->element.match.numItems;
15707c478bd9Sstevel@tonic-gate out->element.match.item = (__nis_mapping_item_t *)
15717c478bd9Sstevel@tonic-gate s_calloc(in->element.match.numItems,
15727c478bd9Sstevel@tonic-gate sizeof (__nis_mapping_item_t));
15737c478bd9Sstevel@tonic-gate if (out->element.match.item == NULL)
15747c478bd9Sstevel@tonic-gate break;
15757c478bd9Sstevel@tonic-gate for (i = 0; i < in->element.match.numItems; i++)
15767c478bd9Sstevel@tonic-gate if (!dup_mapping_item(
15777c478bd9Sstevel@tonic-gate &in->element.match.item[i],
15787c478bd9Sstevel@tonic-gate &out->element.match.item[i]))
15797c478bd9Sstevel@tonic-gate break;
15807c478bd9Sstevel@tonic-gate if (i < in->element.match.numItems)
15817c478bd9Sstevel@tonic-gate break;
15827c478bd9Sstevel@tonic-gate ret = TRUE;
15837c478bd9Sstevel@tonic-gate break;
15847c478bd9Sstevel@tonic-gate case me_extract:
15857c478bd9Sstevel@tonic-gate out->element.extract.fmt =
15867c478bd9Sstevel@tonic-gate dup_format_mapping(in->element.extract.fmt);
15877c478bd9Sstevel@tonic-gate if (out->element.extract.fmt == NULL)
15887c478bd9Sstevel@tonic-gate break;
15897c478bd9Sstevel@tonic-gate ret = dup_mapping_item(&in->element.extract.item,
15907c478bd9Sstevel@tonic-gate &out->element.extract.item);
15917c478bd9Sstevel@tonic-gate break;
15927c478bd9Sstevel@tonic-gate default:
15937c478bd9Sstevel@tonic-gate p_error = parse_internal_error;
15947c478bd9Sstevel@tonic-gate }
15957c478bd9Sstevel@tonic-gate out->type = in->type;
15967c478bd9Sstevel@tonic-gate
15977c478bd9Sstevel@tonic-gate return (ret);
15987c478bd9Sstevel@tonic-gate }
15997c478bd9Sstevel@tonic-gate
16007c478bd9Sstevel@tonic-gate __nis_mapping_rule_t *
dup_mapping_rule(__nis_mapping_rule_t * in)16017c478bd9Sstevel@tonic-gate dup_mapping_rule(__nis_mapping_rule_t *in)
16027c478bd9Sstevel@tonic-gate {
16037c478bd9Sstevel@tonic-gate int i;
16047c478bd9Sstevel@tonic-gate __nis_mapping_rlhs_t *r_in;
16057c478bd9Sstevel@tonic-gate __nis_mapping_rlhs_t *r_out;
16067c478bd9Sstevel@tonic-gate __nis_mapping_rule_t *out;
16077c478bd9Sstevel@tonic-gate
16087c478bd9Sstevel@tonic-gate out = (__nis_mapping_rule_t *)
16097c478bd9Sstevel@tonic-gate s_calloc(1, sizeof (__nis_mapping_rule_t));
16107c478bd9Sstevel@tonic-gate if (out != NULL) {
16117c478bd9Sstevel@tonic-gate r_in = &in->lhs;
16127c478bd9Sstevel@tonic-gate r_out = &out->lhs;
16137c478bd9Sstevel@tonic-gate r_out->numElements = r_in->numElements;
16147c478bd9Sstevel@tonic-gate r_out->element = (__nis_mapping_element_t *)s_calloc
16157c478bd9Sstevel@tonic-gate (r_in->numElements, sizeof (__nis_mapping_element_t));
16167c478bd9Sstevel@tonic-gate if (r_out->element == NULL) {
16177c478bd9Sstevel@tonic-gate free_mapping_rule(out);
16187c478bd9Sstevel@tonic-gate return (NULL);
16197c478bd9Sstevel@tonic-gate }
16207c478bd9Sstevel@tonic-gate for (i = 0; i < r_in->numElements; i++) {
16217c478bd9Sstevel@tonic-gate if (!dup_mapping_element(&r_in->element[i],
16227c478bd9Sstevel@tonic-gate &r_out->element[i]))
16237c478bd9Sstevel@tonic-gate break;
16247c478bd9Sstevel@tonic-gate }
16257c478bd9Sstevel@tonic-gate if (i < r_in->numElements) {
16267c478bd9Sstevel@tonic-gate free_mapping_rule(out);
16277c478bd9Sstevel@tonic-gate return (NULL);
16287c478bd9Sstevel@tonic-gate }
16297c478bd9Sstevel@tonic-gate
16307c478bd9Sstevel@tonic-gate r_in = &in->rhs;
16317c478bd9Sstevel@tonic-gate r_out = &out->rhs;
16327c478bd9Sstevel@tonic-gate r_out->numElements = r_in->numElements;
16337c478bd9Sstevel@tonic-gate r_out->element = (__nis_mapping_element_t *)s_calloc
16347c478bd9Sstevel@tonic-gate (r_in->numElements, sizeof (__nis_mapping_element_t));
16357c478bd9Sstevel@tonic-gate if (r_out->element == NULL) {
16367c478bd9Sstevel@tonic-gate free_mapping_rule(out);
16377c478bd9Sstevel@tonic-gate return (NULL);
16387c478bd9Sstevel@tonic-gate }
16397c478bd9Sstevel@tonic-gate for (i = 0; i < r_in->numElements; i++) {
16407c478bd9Sstevel@tonic-gate if (!dup_mapping_element(&r_in->element[i],
16417c478bd9Sstevel@tonic-gate &r_out->element[i]))
16427c478bd9Sstevel@tonic-gate break;
16437c478bd9Sstevel@tonic-gate }
16447c478bd9Sstevel@tonic-gate if (i < r_in->numElements) {
16457c478bd9Sstevel@tonic-gate free_mapping_rule(out);
16467c478bd9Sstevel@tonic-gate return (NULL);
16477c478bd9Sstevel@tonic-gate }
16487c478bd9Sstevel@tonic-gate }
16497c478bd9Sstevel@tonic-gate return (out);
16507c478bd9Sstevel@tonic-gate }
16517c478bd9Sstevel@tonic-gate
16527c478bd9Sstevel@tonic-gate __nis_mapping_rule_t **
dup_mapping_rules(__nis_mapping_rule_t ** rules,int n_rules)16537c478bd9Sstevel@tonic-gate dup_mapping_rules(__nis_mapping_rule_t **rules, int n_rules)
16547c478bd9Sstevel@tonic-gate {
16557c478bd9Sstevel@tonic-gate int i, j;
16567c478bd9Sstevel@tonic-gate __nis_mapping_rule_t **r;
16577c478bd9Sstevel@tonic-gate
16587c478bd9Sstevel@tonic-gate r = (__nis_mapping_rule_t **)s_calloc(n_rules,
16597c478bd9Sstevel@tonic-gate sizeof (__nis_mapping_rule_t *));
16607c478bd9Sstevel@tonic-gate if (r != NULL) {
16617c478bd9Sstevel@tonic-gate for (i = 0; i < n_rules; i++) {
16627c478bd9Sstevel@tonic-gate r[i] = dup_mapping_rule(rules[i]);
16637c478bd9Sstevel@tonic-gate if (r[i] == NULL) {
16647c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++)
16657c478bd9Sstevel@tonic-gate free_mapping_rule(r[j]);
16667c478bd9Sstevel@tonic-gate free(r);
16677c478bd9Sstevel@tonic-gate r = NULL;
16687c478bd9Sstevel@tonic-gate break;
16697c478bd9Sstevel@tonic-gate }
16707c478bd9Sstevel@tonic-gate }
16717c478bd9Sstevel@tonic-gate }
16727c478bd9Sstevel@tonic-gate return (r);
16737c478bd9Sstevel@tonic-gate }
16747c478bd9Sstevel@tonic-gate
16757c478bd9Sstevel@tonic-gate /*
16767c478bd9Sstevel@tonic-gate * FUNCTION: add_column
16777c478bd9Sstevel@tonic-gate *
16787c478bd9Sstevel@tonic-gate * Adds a column name to the column list in __nis_table_mapping_t
16797c478bd9Sstevel@tonic-gate *
16807c478bd9Sstevel@tonic-gate * RETURN VALUE: FALSE if error
16817c478bd9Sstevel@tonic-gate * TRUE if __nis_index_t returned
16827c478bd9Sstevel@tonic-gate *
16837c478bd9Sstevel@tonic-gate * INPUT: the __nis_table_mapping_t and column name
16847c478bd9Sstevel@tonic-gate */
16857c478bd9Sstevel@tonic-gate
16867c478bd9Sstevel@tonic-gate bool_t
add_column(__nis_table_mapping_t * t,const char * col_name)16877c478bd9Sstevel@tonic-gate add_column(__nis_table_mapping_t *t, const char *col_name)
16887c478bd9Sstevel@tonic-gate {
16897c478bd9Sstevel@tonic-gate int i;
16907c478bd9Sstevel@tonic-gate char **cols = NULL;
16917c478bd9Sstevel@tonic-gate
16927c478bd9Sstevel@tonic-gate if (!yp2ldap) {
16937c478bd9Sstevel@tonic-gate for (i = 0; i < t->numColumns; i++) {
16947c478bd9Sstevel@tonic-gate if (strcasecmp(col_name, t->column[i]) == 0)
16957c478bd9Sstevel@tonic-gate return (TRUE);
16967c478bd9Sstevel@tonic-gate }
16977c478bd9Sstevel@tonic-gate }
16987c478bd9Sstevel@tonic-gate cols = (char **)s_realloc(t->column, (t->numColumns + 1) *
16997c478bd9Sstevel@tonic-gate sizeof (char *));
17007c478bd9Sstevel@tonic-gate if (cols == NULL)
17017c478bd9Sstevel@tonic-gate return (FALSE);
17027c478bd9Sstevel@tonic-gate t->column = cols;
17037c478bd9Sstevel@tonic-gate cols[t->numColumns] = s_strdup(col_name);
17047c478bd9Sstevel@tonic-gate if (cols[t->numColumns] == NULL)
17057c478bd9Sstevel@tonic-gate return (FALSE);
17067c478bd9Sstevel@tonic-gate t->numColumns++;
17077c478bd9Sstevel@tonic-gate return (TRUE);
17087c478bd9Sstevel@tonic-gate }
17097c478bd9Sstevel@tonic-gate
17107c478bd9Sstevel@tonic-gate /*
17117c478bd9Sstevel@tonic-gate * FUNCTION: add_element
17127c478bd9Sstevel@tonic-gate *
17137c478bd9Sstevel@tonic-gate * Adds a __nis_mapping_element_t to __nis_mapping_rlhs_t
17147c478bd9Sstevel@tonic-gate *
17157c478bd9Sstevel@tonic-gate * RETURN VALUE: FALSE if error
17167c478bd9Sstevel@tonic-gate * TRUE if __nis_index_t returned
17177c478bd9Sstevel@tonic-gate *
17187c478bd9Sstevel@tonic-gate * INPUT: the __nis_mapping_element_t and
17197c478bd9Sstevel@tonic-gate * __nis_mapping_rlhs_t
17207c478bd9Sstevel@tonic-gate */
17217c478bd9Sstevel@tonic-gate
17227c478bd9Sstevel@tonic-gate bool_t
add_element(__nis_mapping_element_t * e,__nis_mapping_rlhs_t * m)17237c478bd9Sstevel@tonic-gate add_element(
17247c478bd9Sstevel@tonic-gate __nis_mapping_element_t *e,
17257c478bd9Sstevel@tonic-gate __nis_mapping_rlhs_t *m)
17267c478bd9Sstevel@tonic-gate {
17277c478bd9Sstevel@tonic-gate __nis_mapping_element_t *e1;
17287c478bd9Sstevel@tonic-gate int i;
17297c478bd9Sstevel@tonic-gate int n = m->numElements;
17307c478bd9Sstevel@tonic-gate
17317c478bd9Sstevel@tonic-gate e1 = (__nis_mapping_element_t *)s_realloc(m->element,
17327c478bd9Sstevel@tonic-gate (n + 1) * sizeof (__nis_mapping_element_t));
17337c478bd9Sstevel@tonic-gate if (e1 == NULL) {
17347c478bd9Sstevel@tonic-gate e1 = m->element;
17357c478bd9Sstevel@tonic-gate for (i = 0; i < n; i++)
17367c478bd9Sstevel@tonic-gate free_mapping_element(e1++);
17377c478bd9Sstevel@tonic-gate if (m->element != NULL)
17387c478bd9Sstevel@tonic-gate free(m->element);
17397c478bd9Sstevel@tonic-gate m->element = NULL;
17407c478bd9Sstevel@tonic-gate m->numElements = 0;
17417c478bd9Sstevel@tonic-gate } else {
17427c478bd9Sstevel@tonic-gate e1[m->numElements++] = *e;
17437c478bd9Sstevel@tonic-gate free(e);
17447c478bd9Sstevel@tonic-gate m->element = (__nis_mapping_element_t *)e1;
17457c478bd9Sstevel@tonic-gate }
17467c478bd9Sstevel@tonic-gate return (e1 != NULL);
17477c478bd9Sstevel@tonic-gate }
17487c478bd9Sstevel@tonic-gate
17497c478bd9Sstevel@tonic-gate /*
17507c478bd9Sstevel@tonic-gate * FUNCTION: get_next_object_dn_token
17517c478bd9Sstevel@tonic-gate *
17527c478bd9Sstevel@tonic-gate * Get the next token in parsing object_dn
17537c478bd9Sstevel@tonic-gate *
17547c478bd9Sstevel@tonic-gate * RETURN VALUE: NULL if error
17557c478bd9Sstevel@tonic-gate * position of beginning next token after
17567c478bd9Sstevel@tonic-gate * token
17577c478bd9Sstevel@tonic-gate *
17587c478bd9Sstevel@tonic-gate * INPUT: the attribute value
17597c478bd9Sstevel@tonic-gate */
17607c478bd9Sstevel@tonic-gate
17617c478bd9Sstevel@tonic-gate const char *
get_next_object_dn_token(const char ** begin_ret,const char ** end_ret,object_dn_token * token)17627c478bd9Sstevel@tonic-gate get_next_object_dn_token(
17637c478bd9Sstevel@tonic-gate const char **begin_ret,
17647c478bd9Sstevel@tonic-gate const char **end_ret,
17657c478bd9Sstevel@tonic-gate object_dn_token *token)
17667c478bd9Sstevel@tonic-gate {
17677c478bd9Sstevel@tonic-gate object_dn_token t = dn_no_token;
17687c478bd9Sstevel@tonic-gate const char *s = *begin_ret;
17697c478bd9Sstevel@tonic-gate const char *begin;
17707c478bd9Sstevel@tonic-gate const char *end = *end_ret;
17717c478bd9Sstevel@tonic-gate const char *s1;
17727c478bd9Sstevel@tonic-gate bool_t in_quotes;
17737c478bd9Sstevel@tonic-gate
17747c478bd9Sstevel@tonic-gate while (s < end && is_whitespace(*s))
17757c478bd9Sstevel@tonic-gate s++;
17767c478bd9Sstevel@tonic-gate if (s >= end) {
17777c478bd9Sstevel@tonic-gate /* EMPTY */
17787c478bd9Sstevel@tonic-gate } else if (*s == SEMI_COLON_CHAR) {
17797c478bd9Sstevel@tonic-gate t = dn_semi_token;
17807c478bd9Sstevel@tonic-gate s++;
17817c478bd9Sstevel@tonic-gate } else if (*s == QUESTION_MARK) {
17827c478bd9Sstevel@tonic-gate t = dn_ques_token;
17837c478bd9Sstevel@tonic-gate s++;
17847c478bd9Sstevel@tonic-gate } else if (*s == COLON_CHAR) {
17857c478bd9Sstevel@tonic-gate t = dn_colon_token;
17867c478bd9Sstevel@tonic-gate s++;
17877c478bd9Sstevel@tonic-gate } else if (*s == OPEN_PAREN_CHAR) {
17887c478bd9Sstevel@tonic-gate begin = s;
17897c478bd9Sstevel@tonic-gate s = get_ldap_filter(&begin, &end);
17907c478bd9Sstevel@tonic-gate if (s != NULL) {
17917c478bd9Sstevel@tonic-gate t = dn_text_token;
17927c478bd9Sstevel@tonic-gate *begin_ret = begin;
17937c478bd9Sstevel@tonic-gate *end_ret = end;
17947c478bd9Sstevel@tonic-gate }
17957c478bd9Sstevel@tonic-gate } else {
17967c478bd9Sstevel@tonic-gate begin = s;
17977c478bd9Sstevel@tonic-gate in_quotes = FALSE;
17987c478bd9Sstevel@tonic-gate while (s < end) {
17997c478bd9Sstevel@tonic-gate if (*s == ESCAPE_CHAR) {
18007c478bd9Sstevel@tonic-gate if (s + 2 > end) {
18017c478bd9Sstevel@tonic-gate p_error = parse_unmatched_escape;
18027c478bd9Sstevel@tonic-gate s = NULL;
18037c478bd9Sstevel@tonic-gate break;
18047c478bd9Sstevel@tonic-gate }
18057c478bd9Sstevel@tonic-gate s++;
18067c478bd9Sstevel@tonic-gate } else if (*s == DOUBLE_QUOTE_CHAR) {
18077c478bd9Sstevel@tonic-gate in_quotes = ! in_quotes;
18087c478bd9Sstevel@tonic-gate } else if (in_quotes)
18097c478bd9Sstevel@tonic-gate ;
18107c478bd9Sstevel@tonic-gate else if (*s == SEMI_COLON_CHAR ||
18117c478bd9Sstevel@tonic-gate *s == QUESTION_MARK ||
18127c478bd9Sstevel@tonic-gate *s == COLON_CHAR)
18137c478bd9Sstevel@tonic-gate break;
18147c478bd9Sstevel@tonic-gate s++;
18157c478bd9Sstevel@tonic-gate }
18167c478bd9Sstevel@tonic-gate if (s != NULL) {
18177c478bd9Sstevel@tonic-gate s1 = s - 1;
18187c478bd9Sstevel@tonic-gate while (is_whitespace(*s1))
18197c478bd9Sstevel@tonic-gate s1--;
18207c478bd9Sstevel@tonic-gate s1++;
18217c478bd9Sstevel@tonic-gate if (same_string("base", begin, s1 - begin))
18227c478bd9Sstevel@tonic-gate t = dn_base_token;
18237c478bd9Sstevel@tonic-gate else if (same_string("one", begin, s1 - begin))
18247c478bd9Sstevel@tonic-gate t = dn_one_token;
18257c478bd9Sstevel@tonic-gate else if (same_string("sub", begin, s1 - begin))
18267c478bd9Sstevel@tonic-gate t = dn_sub_token;
18277c478bd9Sstevel@tonic-gate else
18287c478bd9Sstevel@tonic-gate t = dn_text_token;
18297c478bd9Sstevel@tonic-gate *begin_ret = begin;
18307c478bd9Sstevel@tonic-gate *end_ret = s1;
18317c478bd9Sstevel@tonic-gate }
18327c478bd9Sstevel@tonic-gate }
18337c478bd9Sstevel@tonic-gate *token = t;
18347c478bd9Sstevel@tonic-gate return (s);
18357c478bd9Sstevel@tonic-gate }
18367c478bd9Sstevel@tonic-gate
18377c478bd9Sstevel@tonic-gate /*
18387c478bd9Sstevel@tonic-gate * FUNCTION: get_next_token
18397c478bd9Sstevel@tonic-gate *
18407c478bd9Sstevel@tonic-gate * Get the next token in parsing mapping attribute
18417c478bd9Sstevel@tonic-gate *
18427c478bd9Sstevel@tonic-gate * RETURN VALUE: NULL if error
18437c478bd9Sstevel@tonic-gate * position of beginning next token after
18447c478bd9Sstevel@tonic-gate * token
18457c478bd9Sstevel@tonic-gate *
18467c478bd9Sstevel@tonic-gate * INPUT: the attribute value
18477c478bd9Sstevel@tonic-gate */
18487c478bd9Sstevel@tonic-gate
18497c478bd9Sstevel@tonic-gate const char *
get_next_token(const char ** begin_token,const char ** end_token,token_type * t)18507c478bd9Sstevel@tonic-gate get_next_token(const char **begin_token, const char **end_token, token_type *t)
18517c478bd9Sstevel@tonic-gate {
18527c478bd9Sstevel@tonic-gate const char *s = *begin_token;
18537c478bd9Sstevel@tonic-gate const char *end_s = *end_token;
18547c478bd9Sstevel@tonic-gate const char *s_begin;
18557c478bd9Sstevel@tonic-gate
18567c478bd9Sstevel@tonic-gate while (s < end_s && is_whitespace(*s))
18577c478bd9Sstevel@tonic-gate s++;
18587c478bd9Sstevel@tonic-gate if (s == end_s) {
18597c478bd9Sstevel@tonic-gate *t = no_token;
18607c478bd9Sstevel@tonic-gate return (s);
18617c478bd9Sstevel@tonic-gate }
18627c478bd9Sstevel@tonic-gate
18637c478bd9Sstevel@tonic-gate s_begin = s;
18647c478bd9Sstevel@tonic-gate
18657c478bd9Sstevel@tonic-gate if (*s == OPEN_PAREN_CHAR) {
18667c478bd9Sstevel@tonic-gate *begin_token = s;
18677c478bd9Sstevel@tonic-gate s++;
18687c478bd9Sstevel@tonic-gate *end_token = s;
18697c478bd9Sstevel@tonic-gate while (s < end_s && is_whitespace(*s))
18707c478bd9Sstevel@tonic-gate s++;
18717c478bd9Sstevel@tonic-gate *t = open_paren_token;
18727c478bd9Sstevel@tonic-gate } else if (*s == DOUBLE_QUOTE_CHAR) {
18737c478bd9Sstevel@tonic-gate s++;
18747c478bd9Sstevel@tonic-gate while (s < end_s) {
18757c478bd9Sstevel@tonic-gate if (*s == ESCAPE_CHAR)
18767c478bd9Sstevel@tonic-gate s += 2;
18777c478bd9Sstevel@tonic-gate else if (*s == DOUBLE_QUOTE_CHAR)
18787c478bd9Sstevel@tonic-gate break;
18797c478bd9Sstevel@tonic-gate else
18807c478bd9Sstevel@tonic-gate s++;
18817c478bd9Sstevel@tonic-gate }
18827c478bd9Sstevel@tonic-gate if (s >= end_s) {
18837c478bd9Sstevel@tonic-gate p_error = parse_unmatched_escape;
18847c478bd9Sstevel@tonic-gate return (NULL);
18857c478bd9Sstevel@tonic-gate }
18867c478bd9Sstevel@tonic-gate
18877c478bd9Sstevel@tonic-gate *t = quoted_string_token;
18887c478bd9Sstevel@tonic-gate *begin_token = s_begin + 1;
18897c478bd9Sstevel@tonic-gate *end_token = s++;
18907c478bd9Sstevel@tonic-gate } else if (*s == EQUAL_CHAR || *s == COMMA_CHAR ||
18917c478bd9Sstevel@tonic-gate *s == CLOSE_PAREN_CHAR || *s == COLON_CHAR) {
18927c478bd9Sstevel@tonic-gate if (*s == EQUAL_CHAR)
18937c478bd9Sstevel@tonic-gate *t = equal_token;
18947c478bd9Sstevel@tonic-gate else if (*s == COMMA_CHAR)
18957c478bd9Sstevel@tonic-gate *t = comma_token;
18967c478bd9Sstevel@tonic-gate else if (*s == CLOSE_PAREN_CHAR)
18977c478bd9Sstevel@tonic-gate *t = close_paren_token;
18987c478bd9Sstevel@tonic-gate else
18997c478bd9Sstevel@tonic-gate *t = colon_token;
19007c478bd9Sstevel@tonic-gate *begin_token = s;
19017c478bd9Sstevel@tonic-gate *end_token = ++s;
19027c478bd9Sstevel@tonic-gate } else {
19037c478bd9Sstevel@tonic-gate s_begin = s;
19047c478bd9Sstevel@tonic-gate while (s < end_s && !is_whitespace(*s)) {
19057c478bd9Sstevel@tonic-gate if (*s == ESCAPE_CHAR)
19067c478bd9Sstevel@tonic-gate s += 2;
19077c478bd9Sstevel@tonic-gate else if (*s == EQUAL_CHAR || *s == CLOSE_PAREN_CHAR ||
19087c478bd9Sstevel@tonic-gate *s == OPEN_PAREN_CHAR || *s == COMMA_CHAR ||
19097c478bd9Sstevel@tonic-gate *s == COLON_CHAR || *s == OPEN_BRACKET ||
19107c478bd9Sstevel@tonic-gate *s == CLOSE_BRACKET)
19117c478bd9Sstevel@tonic-gate break;
19127c478bd9Sstevel@tonic-gate else
19137c478bd9Sstevel@tonic-gate s++;
19147c478bd9Sstevel@tonic-gate }
19157c478bd9Sstevel@tonic-gate if (s > end_s) {
19167c478bd9Sstevel@tonic-gate p_error = parse_unmatched_escape;
19177c478bd9Sstevel@tonic-gate return (NULL);
19187c478bd9Sstevel@tonic-gate }
19197c478bd9Sstevel@tonic-gate *t = string_token;
19207c478bd9Sstevel@tonic-gate *end_token = s;
19217c478bd9Sstevel@tonic-gate *begin_token = s_begin;
19227c478bd9Sstevel@tonic-gate }
19237c478bd9Sstevel@tonic-gate if (s) {
19247c478bd9Sstevel@tonic-gate while (s < end_s && is_whitespace(*s))
19257c478bd9Sstevel@tonic-gate s++;
19267c478bd9Sstevel@tonic-gate }
19277c478bd9Sstevel@tonic-gate return (s);
19287c478bd9Sstevel@tonic-gate }
19297c478bd9Sstevel@tonic-gate
19307c478bd9Sstevel@tonic-gate /*
19317c478bd9Sstevel@tonic-gate * FUNCTION: skip_token
19327c478bd9Sstevel@tonic-gate *
19337c478bd9Sstevel@tonic-gate * Skip over the specified token - An error is set if
19347c478bd9Sstevel@tonic-gate * next token does not match expected token
19357c478bd9Sstevel@tonic-gate *
19367c478bd9Sstevel@tonic-gate * RETURN VALUE: NULL if error
19377c478bd9Sstevel@tonic-gate * position of beginning next token after
19387c478bd9Sstevel@tonic-gate * token
19397c478bd9Sstevel@tonic-gate *
19407c478bd9Sstevel@tonic-gate * INPUT: the attribute value
19417c478bd9Sstevel@tonic-gate */
19427c478bd9Sstevel@tonic-gate
19437c478bd9Sstevel@tonic-gate const char *
skip_token(const char * s,const char * end_s,token_type t)19447c478bd9Sstevel@tonic-gate skip_token(const char *s, const char *end_s, token_type t)
19457c478bd9Sstevel@tonic-gate {
19467c478bd9Sstevel@tonic-gate bool_t match;
19477c478bd9Sstevel@tonic-gate char c = 0;
19487c478bd9Sstevel@tonic-gate
19497c478bd9Sstevel@tonic-gate if (s == NULL)
19507c478bd9Sstevel@tonic-gate return (s);
19517c478bd9Sstevel@tonic-gate while (s < end_s && is_whitespace(*s))
19527c478bd9Sstevel@tonic-gate s++;
19537c478bd9Sstevel@tonic-gate c = (s == end_s) ? 0 : *s;
19547c478bd9Sstevel@tonic-gate switch (t) {
19557c478bd9Sstevel@tonic-gate case equal_token:
19567c478bd9Sstevel@tonic-gate match = c == EQUAL_CHAR;
19577c478bd9Sstevel@tonic-gate if (!match)
19587c478bd9Sstevel@tonic-gate p_error = parse_equal_expected_error;
19597c478bd9Sstevel@tonic-gate break;
19607c478bd9Sstevel@tonic-gate case comma_token:
19617c478bd9Sstevel@tonic-gate match = c == COMMA_CHAR;
19627c478bd9Sstevel@tonic-gate if (!match)
19637c478bd9Sstevel@tonic-gate p_error = parse_comma_expected_error;
19647c478bd9Sstevel@tonic-gate break;
19657c478bd9Sstevel@tonic-gate case close_paren_token:
19667c478bd9Sstevel@tonic-gate match = c == CLOSE_PAREN_CHAR;
19677c478bd9Sstevel@tonic-gate if (!match)
19687c478bd9Sstevel@tonic-gate p_error = parse_close_paren_expected_error;
19697c478bd9Sstevel@tonic-gate break;
19707c478bd9Sstevel@tonic-gate default:
19717c478bd9Sstevel@tonic-gate match = FALSE;
19727c478bd9Sstevel@tonic-gate break;
19737c478bd9Sstevel@tonic-gate }
19747c478bd9Sstevel@tonic-gate if (match) {
19757c478bd9Sstevel@tonic-gate s++;
19767c478bd9Sstevel@tonic-gate while (s < end_s && is_whitespace(*s))
19777c478bd9Sstevel@tonic-gate s++;
19787c478bd9Sstevel@tonic-gate } else {
19797c478bd9Sstevel@tonic-gate s = NULL;
19807c478bd9Sstevel@tonic-gate }
19817c478bd9Sstevel@tonic-gate return (s);
19827c478bd9Sstevel@tonic-gate }
19837c478bd9Sstevel@tonic-gate
19847c478bd9Sstevel@tonic-gate /*
19857c478bd9Sstevel@tonic-gate * FUNCTION: get_next_extract_format_item
19867c478bd9Sstevel@tonic-gate *
19877c478bd9Sstevel@tonic-gate * Get the next format token from the string. Note that
19887c478bd9Sstevel@tonic-gate * get_next_extract_format_item may change the input string.
19897c478bd9Sstevel@tonic-gate *
19907c478bd9Sstevel@tonic-gate * RETURN VALUE: NULL if error
19917c478bd9Sstevel@tonic-gate * position of beginning next token after
19927c478bd9Sstevel@tonic-gate * token
19937c478bd9Sstevel@tonic-gate *
19947c478bd9Sstevel@tonic-gate * INPUT: the format string
19957c478bd9Sstevel@tonic-gate */
19967c478bd9Sstevel@tonic-gate
19977c478bd9Sstevel@tonic-gate const char *
get_next_extract_format_item(const char * begin_fmt,const char * end_fmt,__nis_mapping_format_t * fmt)19987c478bd9Sstevel@tonic-gate get_next_extract_format_item(
19997c478bd9Sstevel@tonic-gate const char *begin_fmt,
20007c478bd9Sstevel@tonic-gate const char *end_fmt,
20017c478bd9Sstevel@tonic-gate __nis_mapping_format_t *fmt)
20027c478bd9Sstevel@tonic-gate {
20037c478bd9Sstevel@tonic-gate const char *s = begin_fmt;
20047c478bd9Sstevel@tonic-gate const char *s_end = end_fmt;
20057c478bd9Sstevel@tonic-gate bool_t escape;
20067c478bd9Sstevel@tonic-gate bool_t in_range;
20077c478bd9Sstevel@tonic-gate bool_t got_char;
20087c478bd9Sstevel@tonic-gate bool_t done;
20097c478bd9Sstevel@tonic-gate int numRange;
20107c478bd9Sstevel@tonic-gate char *lo = NULL;
20117c478bd9Sstevel@tonic-gate char *hi = NULL;
20127c478bd9Sstevel@tonic-gate bool_t skip_ber;
20137c478bd9Sstevel@tonic-gate
20147c478bd9Sstevel@tonic-gate for (; p_error == no_parse_error; ) {
20157c478bd9Sstevel@tonic-gate if (s >= s_end)
20167c478bd9Sstevel@tonic-gate break;
20177c478bd9Sstevel@tonic-gate
20187c478bd9Sstevel@tonic-gate if (*s == PERCENT_SIGN) {
20197c478bd9Sstevel@tonic-gate s++;
20207c478bd9Sstevel@tonic-gate /*
20217c478bd9Sstevel@tonic-gate * If the format is %s, it is interpreted
20227c478bd9Sstevel@tonic-gate * as a string.
20237c478bd9Sstevel@tonic-gate */
20247c478bd9Sstevel@tonic-gate if (s >= s_end) {
20257c478bd9Sstevel@tonic-gate p_error = parse_unsupported_format;
20267c478bd9Sstevel@tonic-gate break;
20277c478bd9Sstevel@tonic-gate }
20287c478bd9Sstevel@tonic-gate skip_ber = FALSE;
20297c478bd9Sstevel@tonic-gate switch (*s) {
20307c478bd9Sstevel@tonic-gate case 's':
20317c478bd9Sstevel@tonic-gate fmt->type = mmt_item;
20327c478bd9Sstevel@tonic-gate break;
20337c478bd9Sstevel@tonic-gate case 'n': /* null */
20347c478bd9Sstevel@tonic-gate case 'x': /* skip the next element */
20357c478bd9Sstevel@tonic-gate skip_ber = TRUE;
20367c478bd9Sstevel@tonic-gate /* FALLTHRU */
20377c478bd9Sstevel@tonic-gate case 'b': /* boolean */
20387c478bd9Sstevel@tonic-gate case 'e': /* enumerated */
20397c478bd9Sstevel@tonic-gate case 'i': /* int */
20407c478bd9Sstevel@tonic-gate case 'o': /* octet string */
20417c478bd9Sstevel@tonic-gate case 'B': /* bit string */
20427c478bd9Sstevel@tonic-gate fmt->match.berString = s_strndup(s, 1);
20437c478bd9Sstevel@tonic-gate fmt->type = skip_ber ?
20447c478bd9Sstevel@tonic-gate mmt_berstring_null :
20457c478bd9Sstevel@tonic-gate mmt_berstring;
20467c478bd9Sstevel@tonic-gate break;
20477c478bd9Sstevel@tonic-gate case 'a': /* octet string */
20487c478bd9Sstevel@tonic-gate if (yp2ldap) {
20497c478bd9Sstevel@tonic-gate fmt->match.berString =
20507c478bd9Sstevel@tonic-gate s_strndup(s, 1);
20517c478bd9Sstevel@tonic-gate fmt->type = skip_ber ?
20527c478bd9Sstevel@tonic-gate mmt_berstring_null :
20537c478bd9Sstevel@tonic-gate mmt_berstring;
20547c478bd9Sstevel@tonic-gate break;
20557c478bd9Sstevel@tonic-gate } /* else FALLTHRU */
20567c478bd9Sstevel@tonic-gate case '{': /* begin sequence */
20577c478bd9Sstevel@tonic-gate case '[': /* begin set */
20587c478bd9Sstevel@tonic-gate case '}': /* end sequence */
20597c478bd9Sstevel@tonic-gate case ']': /* end set */
20607c478bd9Sstevel@tonic-gate case 'l': /* length of next item */
20617c478bd9Sstevel@tonic-gate case 'O': /* octet string */
20627c478bd9Sstevel@tonic-gate case 't': /* tag of next item */
20637c478bd9Sstevel@tonic-gate case 'T': /* skip tag of next item */
20647c478bd9Sstevel@tonic-gate case 'v': /* seq of strings */
20657c478bd9Sstevel@tonic-gate case 'V': /* seq of strings + lengths */
20667c478bd9Sstevel@tonic-gate default:
20677c478bd9Sstevel@tonic-gate p_error = parse_bad_ber_format;
20687c478bd9Sstevel@tonic-gate break;
20697c478bd9Sstevel@tonic-gate }
20707c478bd9Sstevel@tonic-gate s++;
20717c478bd9Sstevel@tonic-gate } else if (*s == ASTERIX_CHAR) {
20727c478bd9Sstevel@tonic-gate fmt->type = mmt_any;
20737c478bd9Sstevel@tonic-gate s++;
20747c478bd9Sstevel@tonic-gate while (s < s_end && *s == ASTERIX_CHAR)
20757c478bd9Sstevel@tonic-gate s++;
20767c478bd9Sstevel@tonic-gate
20777c478bd9Sstevel@tonic-gate } else if (*s == OPEN_BRACKET) {
20787c478bd9Sstevel@tonic-gate escape = FALSE;
20797c478bd9Sstevel@tonic-gate in_range = FALSE;
20807c478bd9Sstevel@tonic-gate got_char = FALSE;
20817c478bd9Sstevel@tonic-gate numRange = 0;
20827c478bd9Sstevel@tonic-gate done = FALSE;
20837c478bd9Sstevel@tonic-gate s++;
20847c478bd9Sstevel@tonic-gate for (; s < s_end; s++) {
20857c478bd9Sstevel@tonic-gate if (escape) {
20867c478bd9Sstevel@tonic-gate escape = FALSE;
20877c478bd9Sstevel@tonic-gate } else if (*s == DASH_CHAR) {
20887c478bd9Sstevel@tonic-gate if (in_range || !got_char) {
20897c478bd9Sstevel@tonic-gate p_error = parse_unexpected_dash;
20907c478bd9Sstevel@tonic-gate break;
20917c478bd9Sstevel@tonic-gate }
20927c478bd9Sstevel@tonic-gate in_range = TRUE;
20937c478bd9Sstevel@tonic-gate got_char = FALSE;
20947c478bd9Sstevel@tonic-gate continue;
20957c478bd9Sstevel@tonic-gate } else if (*s == CLOSE_BRACKET) {
20967c478bd9Sstevel@tonic-gate if (in_range) {
20977c478bd9Sstevel@tonic-gate p_error = parse_unexpected_dash;
20987c478bd9Sstevel@tonic-gate }
20997c478bd9Sstevel@tonic-gate done = TRUE;
21007c478bd9Sstevel@tonic-gate break;
21017c478bd9Sstevel@tonic-gate } else if (*s == ESCAPE_CHAR) {
21027c478bd9Sstevel@tonic-gate escape = TRUE;
21037c478bd9Sstevel@tonic-gate continue;
21047c478bd9Sstevel@tonic-gate }
21057c478bd9Sstevel@tonic-gate if (in_range) {
21067c478bd9Sstevel@tonic-gate hi[numRange - 1] = *s;
21077c478bd9Sstevel@tonic-gate in_range = FALSE;
21087c478bd9Sstevel@tonic-gate } else {
21097c478bd9Sstevel@tonic-gate lo = s_realloc(lo, numRange + 1);
21107c478bd9Sstevel@tonic-gate hi = s_realloc(hi, numRange + 1);
21117c478bd9Sstevel@tonic-gate if (lo == NULL || hi == NULL)
21127c478bd9Sstevel@tonic-gate break;
21137c478bd9Sstevel@tonic-gate lo[numRange] = *s;
21147c478bd9Sstevel@tonic-gate hi[numRange] = *s;
21157c478bd9Sstevel@tonic-gate numRange++;
21167c478bd9Sstevel@tonic-gate got_char = TRUE;
21177c478bd9Sstevel@tonic-gate }
21187c478bd9Sstevel@tonic-gate }
21197c478bd9Sstevel@tonic-gate if (p_error != no_parse_error) {
21207c478bd9Sstevel@tonic-gate break;
21217c478bd9Sstevel@tonic-gate } else if (!done) {
21227c478bd9Sstevel@tonic-gate p_error = parse_mismatched_brackets;
21237c478bd9Sstevel@tonic-gate break;
21247c478bd9Sstevel@tonic-gate }
21257c478bd9Sstevel@tonic-gate s++;
21267c478bd9Sstevel@tonic-gate fmt->type = mmt_single;
21277c478bd9Sstevel@tonic-gate fmt->match.single.numRange = numRange;
21287c478bd9Sstevel@tonic-gate fmt->match.single.lo = (unsigned char *)lo;
21297c478bd9Sstevel@tonic-gate fmt->match.single.hi = (unsigned char *)hi;
21307c478bd9Sstevel@tonic-gate } else {
21317c478bd9Sstevel@tonic-gate /* go to next key symbol - copy escaped key symbols */
21327c478bd9Sstevel@tonic-gate escape = FALSE;
21337c478bd9Sstevel@tonic-gate done = FALSE;
21347c478bd9Sstevel@tonic-gate while (s < s_end) {
21357c478bd9Sstevel@tonic-gate if (escape)
21367c478bd9Sstevel@tonic-gate escape = FALSE;
21377c478bd9Sstevel@tonic-gate else {
21387c478bd9Sstevel@tonic-gate switch (*s) {
21397c478bd9Sstevel@tonic-gate case OPEN_BRACKET:
21407c478bd9Sstevel@tonic-gate case ASTERIX_CHAR:
21417c478bd9Sstevel@tonic-gate case PERCENT_SIGN:
21427c478bd9Sstevel@tonic-gate done = TRUE;
21437c478bd9Sstevel@tonic-gate break;
21447c478bd9Sstevel@tonic-gate case ESCAPE_CHAR:
21457c478bd9Sstevel@tonic-gate escape = !escape;
21467c478bd9Sstevel@tonic-gate break;
21477c478bd9Sstevel@tonic-gate default:
21487c478bd9Sstevel@tonic-gate break;
21497c478bd9Sstevel@tonic-gate }
21507c478bd9Sstevel@tonic-gate }
21517c478bd9Sstevel@tonic-gate if (done)
21527c478bd9Sstevel@tonic-gate break;
21537c478bd9Sstevel@tonic-gate s++;
21547c478bd9Sstevel@tonic-gate }
21557c478bd9Sstevel@tonic-gate if (escape) {
21567c478bd9Sstevel@tonic-gate p_error = parse_unmatched_escape;
21577c478bd9Sstevel@tonic-gate break;
21587c478bd9Sstevel@tonic-gate }
21597c478bd9Sstevel@tonic-gate fmt->type = mmt_string;
21607c478bd9Sstevel@tonic-gate fmt->match.string =
21617c478bd9Sstevel@tonic-gate s_strndup_esc(begin_fmt, s - begin_fmt);
21627c478bd9Sstevel@tonic-gate if (fmt->match.string == NULL)
21637c478bd9Sstevel@tonic-gate break;
21647c478bd9Sstevel@tonic-gate }
21657c478bd9Sstevel@tonic-gate
21667c478bd9Sstevel@tonic-gate if (p_error == no_parse_error)
21677c478bd9Sstevel@tonic-gate return (s);
21687c478bd9Sstevel@tonic-gate }
21697c478bd9Sstevel@tonic-gate if (lo != NULL)
21707c478bd9Sstevel@tonic-gate free(lo);
21717c478bd9Sstevel@tonic-gate if (hi != NULL)
21727c478bd9Sstevel@tonic-gate free(hi);
21737c478bd9Sstevel@tonic-gate return (NULL);
21747c478bd9Sstevel@tonic-gate }
21757c478bd9Sstevel@tonic-gate
21767c478bd9Sstevel@tonic-gate /*
21777c478bd9Sstevel@tonic-gate * FUNCTION: get_next_print_format_item
21787c478bd9Sstevel@tonic-gate *
21797c478bd9Sstevel@tonic-gate * Get the next format token from the string
21807c478bd9Sstevel@tonic-gate *
21817c478bd9Sstevel@tonic-gate * RETURN VALUE: NULL if error
21827c478bd9Sstevel@tonic-gate * position of beginning next token after
21837c478bd9Sstevel@tonic-gate * token
21847c478bd9Sstevel@tonic-gate *
21857c478bd9Sstevel@tonic-gate * INPUT: the format string
21867c478bd9Sstevel@tonic-gate */
21877c478bd9Sstevel@tonic-gate
21887c478bd9Sstevel@tonic-gate const char *
get_next_print_format_item(const char * begin_fmt,const char * end_fmt,__nis_mapping_format_t * fmt)21897c478bd9Sstevel@tonic-gate get_next_print_format_item(
21907c478bd9Sstevel@tonic-gate const char *begin_fmt,
21917c478bd9Sstevel@tonic-gate const char *end_fmt,
21927c478bd9Sstevel@tonic-gate __nis_mapping_format_t *fmt)
21937c478bd9Sstevel@tonic-gate {
21947c478bd9Sstevel@tonic-gate const char *s = begin_fmt;
21957c478bd9Sstevel@tonic-gate const char *s_end = end_fmt;
21967c478bd9Sstevel@tonic-gate bool_t skip_ber;
21977c478bd9Sstevel@tonic-gate
21987c478bd9Sstevel@tonic-gate for (; p_error == no_parse_error; ) {
21997c478bd9Sstevel@tonic-gate if (s >= s_end) {
22007c478bd9Sstevel@tonic-gate p_error = parse_internal_error;
22017c478bd9Sstevel@tonic-gate break;
22027c478bd9Sstevel@tonic-gate }
22037c478bd9Sstevel@tonic-gate
22047c478bd9Sstevel@tonic-gate if (*s == PERCENT_SIGN) {
22057c478bd9Sstevel@tonic-gate s++;
22067c478bd9Sstevel@tonic-gate if (s >= s_end) {
22077c478bd9Sstevel@tonic-gate p_error = parse_unsupported_format;
22087c478bd9Sstevel@tonic-gate break;
22097c478bd9Sstevel@tonic-gate }
22107c478bd9Sstevel@tonic-gate skip_ber = FALSE;
22117c478bd9Sstevel@tonic-gate /*
22127c478bd9Sstevel@tonic-gate * If the format is %s, it is interpretted
22137c478bd9Sstevel@tonic-gate * as a string.
22147c478bd9Sstevel@tonic-gate */
22157c478bd9Sstevel@tonic-gate switch (*s) {
22167c478bd9Sstevel@tonic-gate case 's':
22177c478bd9Sstevel@tonic-gate fmt->type = mmt_item;
22187c478bd9Sstevel@tonic-gate break;
22197c478bd9Sstevel@tonic-gate case 'n': /* null */
22207c478bd9Sstevel@tonic-gate case 'x': /* skip the next element */
22217c478bd9Sstevel@tonic-gate skip_ber = TRUE;
22227c478bd9Sstevel@tonic-gate /* FALLTHRU */
22237c478bd9Sstevel@tonic-gate case 'b': /* boolean */
22247c478bd9Sstevel@tonic-gate case 'e': /* enumerated */
22257c478bd9Sstevel@tonic-gate case 'i': /* int */
22267c478bd9Sstevel@tonic-gate case 'o': /* octet string */
22277c478bd9Sstevel@tonic-gate case 'B': /* bit string */
22287c478bd9Sstevel@tonic-gate fmt->match.berString = s_strndup(s, 1);
22297c478bd9Sstevel@tonic-gate fmt->type = skip_ber ?
22307c478bd9Sstevel@tonic-gate mmt_berstring_null :
22317c478bd9Sstevel@tonic-gate mmt_berstring;
22327c478bd9Sstevel@tonic-gate break;
22337c478bd9Sstevel@tonic-gate case '{': /* begin sequence */
22347c478bd9Sstevel@tonic-gate case '[': /* begin set */
22357c478bd9Sstevel@tonic-gate case '}': /* end sequence */
22367c478bd9Sstevel@tonic-gate case ']': /* end set */
22377c478bd9Sstevel@tonic-gate case 'a': /* octet string */
22387c478bd9Sstevel@tonic-gate case 'l': /* length of next item */
22397c478bd9Sstevel@tonic-gate case 'O': /* octet string */
22407c478bd9Sstevel@tonic-gate case 't': /* tag of next item */
22417c478bd9Sstevel@tonic-gate case 'T': /* skip tag of next item */
22427c478bd9Sstevel@tonic-gate case 'v': /* seq of strings */
22437c478bd9Sstevel@tonic-gate case 'V': /* seq of strings + lengths */
22447c478bd9Sstevel@tonic-gate default:
22457c478bd9Sstevel@tonic-gate p_error = parse_bad_ber_format;
22467c478bd9Sstevel@tonic-gate break;
22477c478bd9Sstevel@tonic-gate }
22487c478bd9Sstevel@tonic-gate s++;
22497c478bd9Sstevel@tonic-gate } else {
22507c478bd9Sstevel@tonic-gate while (s < s_end) {
22517c478bd9Sstevel@tonic-gate if (*s == PERCENT_SIGN)
22527c478bd9Sstevel@tonic-gate break;
22537c478bd9Sstevel@tonic-gate else if (*s == ESCAPE_CHAR)
22547c478bd9Sstevel@tonic-gate s++;
22557c478bd9Sstevel@tonic-gate s++;
22567c478bd9Sstevel@tonic-gate }
22577c478bd9Sstevel@tonic-gate if (s > s_end) {
22587c478bd9Sstevel@tonic-gate p_error = parse_unmatched_escape;
22597c478bd9Sstevel@tonic-gate break;
22607c478bd9Sstevel@tonic-gate }
22617c478bd9Sstevel@tonic-gate fmt->match.string =
22627c478bd9Sstevel@tonic-gate s_strndup_esc(begin_fmt, s - begin_fmt);
22637c478bd9Sstevel@tonic-gate if (fmt->match.string == NULL)
22647c478bd9Sstevel@tonic-gate break;
22657c478bd9Sstevel@tonic-gate fmt->type = mmt_string;
22667c478bd9Sstevel@tonic-gate }
22677c478bd9Sstevel@tonic-gate if (p_error == no_parse_error)
22687c478bd9Sstevel@tonic-gate return (s);
22697c478bd9Sstevel@tonic-gate }
22707c478bd9Sstevel@tonic-gate return (NULL);
22717c478bd9Sstevel@tonic-gate }
22727c478bd9Sstevel@tonic-gate
22737c478bd9Sstevel@tonic-gate /*
22747c478bd9Sstevel@tonic-gate * FUNCTION: get_ldap_filter
22757c478bd9Sstevel@tonic-gate *
22767c478bd9Sstevel@tonic-gate * Gets an LDAP filter - see RFC 2254. Note that this does not
22777c478bd9Sstevel@tonic-gate * determine if the ldap filter is valid. This only determines
22787c478bd9Sstevel@tonic-gate * that the parentheses are balanced.
22797c478bd9Sstevel@tonic-gate *
22807c478bd9Sstevel@tonic-gate * RETURN VALUE: NULL if error
22817c478bd9Sstevel@tonic-gate * position of beginning next token after
22827c478bd9Sstevel@tonic-gate * filter
22837c478bd9Sstevel@tonic-gate *
22847c478bd9Sstevel@tonic-gate * INPUT: the begin and end of string
22857c478bd9Sstevel@tonic-gate *
22867c478bd9Sstevel@tonic-gate * OUTPUT: the begin and end of LDAP filter
22877c478bd9Sstevel@tonic-gate *
22887c478bd9Sstevel@tonic-gate */
22897c478bd9Sstevel@tonic-gate
22907c478bd9Sstevel@tonic-gate const char *
get_ldap_filter(const char ** begin,const char ** end)22917c478bd9Sstevel@tonic-gate get_ldap_filter(const char **begin, const char **end)
22927c478bd9Sstevel@tonic-gate {
22937c478bd9Sstevel@tonic-gate const char *s = *begin;
22947c478bd9Sstevel@tonic-gate const char *s_begin;
22957c478bd9Sstevel@tonic-gate const char *s_end = *end;
22967c478bd9Sstevel@tonic-gate int nParen;
22977c478bd9Sstevel@tonic-gate
22987c478bd9Sstevel@tonic-gate for (; p_error == no_parse_error; ) {
22997c478bd9Sstevel@tonic-gate while (s < s_end && is_whitespace(*s))
23007c478bd9Sstevel@tonic-gate s++;
23017c478bd9Sstevel@tonic-gate if (s == s_end) {
23027c478bd9Sstevel@tonic-gate s = NULL;
23037c478bd9Sstevel@tonic-gate break;
23047c478bd9Sstevel@tonic-gate }
23057c478bd9Sstevel@tonic-gate
23067c478bd9Sstevel@tonic-gate s_begin = s;
23077c478bd9Sstevel@tonic-gate if (*s == OPEN_PAREN_CHAR) {
23087c478bd9Sstevel@tonic-gate nParen = 1;
23097c478bd9Sstevel@tonic-gate s++;
23107c478bd9Sstevel@tonic-gate while (s < s_end && nParen > 0) {
23117c478bd9Sstevel@tonic-gate if (*s == ESCAPE_CHAR)
23127c478bd9Sstevel@tonic-gate s++;
23137c478bd9Sstevel@tonic-gate else if (*s == OPEN_PAREN_CHAR)
23147c478bd9Sstevel@tonic-gate nParen++;
23157c478bd9Sstevel@tonic-gate else if (*s == CLOSE_PAREN_CHAR)
23167c478bd9Sstevel@tonic-gate nParen--;
23177c478bd9Sstevel@tonic-gate s++;
23187c478bd9Sstevel@tonic-gate }
23197c478bd9Sstevel@tonic-gate if (nParen == 0) {
23207c478bd9Sstevel@tonic-gate *begin = s_begin;
23217c478bd9Sstevel@tonic-gate *end = s;
23227c478bd9Sstevel@tonic-gate while (s < s_end && is_whitespace(*s))
23237c478bd9Sstevel@tonic-gate s++;
23247c478bd9Sstevel@tonic-gate } else
23257c478bd9Sstevel@tonic-gate s = NULL;
23267c478bd9Sstevel@tonic-gate } else
23277c478bd9Sstevel@tonic-gate s = NULL;
23287c478bd9Sstevel@tonic-gate if (p_error == no_parse_error)
23297c478bd9Sstevel@tonic-gate break;
23307c478bd9Sstevel@tonic-gate }
23317c478bd9Sstevel@tonic-gate if (s == NULL)
23327c478bd9Sstevel@tonic-gate p_error = parse_invalid_ldap_search_filter;
23337c478bd9Sstevel@tonic-gate
23347c478bd9Sstevel@tonic-gate return (s);
23357c478bd9Sstevel@tonic-gate }
23367c478bd9Sstevel@tonic-gate
23377c478bd9Sstevel@tonic-gate /*
23387c478bd9Sstevel@tonic-gate * FUNCTION: get_ava_list
23397c478bd9Sstevel@tonic-gate *
23407c478bd9Sstevel@tonic-gate * Gets an attribute value assertion list
23417c478bd9Sstevel@tonic-gate *
23427c478bd9Sstevel@tonic-gate * RETURN VALUE: NULL if error
23437c478bd9Sstevel@tonic-gate * position of beginning next token after
23447c478bd9Sstevel@tonic-gate * after attribute assertion
23457c478bd9Sstevel@tonic-gate *
23467c478bd9Sstevel@tonic-gate * INPUT: the begin and end of string
23477c478bd9Sstevel@tonic-gate * Indicator if ava list is part of a nisplus
23487c478bd9Sstevel@tonic-gate * item
23497c478bd9Sstevel@tonic-gate *
23507c478bd9Sstevel@tonic-gate * OUTPUT: the begin and end of LDAP filter
23517c478bd9Sstevel@tonic-gate *
23527c478bd9Sstevel@tonic-gate */
23537c478bd9Sstevel@tonic-gate
23547c478bd9Sstevel@tonic-gate const char *
get_ava_list(const char ** begin,const char ** end,bool_t end_nisplus)23557c478bd9Sstevel@tonic-gate get_ava_list(const char **begin, const char **end, bool_t end_nisplus)
23567c478bd9Sstevel@tonic-gate {
23577c478bd9Sstevel@tonic-gate const char *s = *begin;
23587c478bd9Sstevel@tonic-gate const char *s_begin;
23597c478bd9Sstevel@tonic-gate const char *s_end = *end;
23607c478bd9Sstevel@tonic-gate bool_t in_quote;
23617c478bd9Sstevel@tonic-gate bool_t got_equal;
23627c478bd9Sstevel@tonic-gate bool_t got_data;
23637c478bd9Sstevel@tonic-gate
23647c478bd9Sstevel@tonic-gate for (; p_error == no_parse_error; ) {
23657c478bd9Sstevel@tonic-gate while (s < s_end && is_whitespace(*s))
23667c478bd9Sstevel@tonic-gate s++;
23677c478bd9Sstevel@tonic-gate if (s == s_end) {
23687c478bd9Sstevel@tonic-gate s = NULL;
23697c478bd9Sstevel@tonic-gate break;
23707c478bd9Sstevel@tonic-gate }
23717c478bd9Sstevel@tonic-gate
23727c478bd9Sstevel@tonic-gate in_quote = FALSE;
23737c478bd9Sstevel@tonic-gate got_equal = FALSE;
23747c478bd9Sstevel@tonic-gate got_data = FALSE;
23757c478bd9Sstevel@tonic-gate s_begin = s;
23767c478bd9Sstevel@tonic-gate while (s < s_end) {
23777c478bd9Sstevel@tonic-gate if (*s == ESCAPE_CHAR) {
23787c478bd9Sstevel@tonic-gate s++;
23797c478bd9Sstevel@tonic-gate got_data = TRUE;
23807c478bd9Sstevel@tonic-gate } else if (*s == DOUBLE_QUOTE_CHAR) {
23817c478bd9Sstevel@tonic-gate in_quote = !in_quote;
23827c478bd9Sstevel@tonic-gate got_data = TRUE;
23837c478bd9Sstevel@tonic-gate } else if (in_quote)
23847c478bd9Sstevel@tonic-gate ;
23857c478bd9Sstevel@tonic-gate else if (*s == EQUAL_CHAR) {
23867c478bd9Sstevel@tonic-gate if (end_nisplus && got_data && got_equal)
23877c478bd9Sstevel@tonic-gate break;
23887c478bd9Sstevel@tonic-gate if (!got_data || got_equal) {
23897c478bd9Sstevel@tonic-gate got_equal = FALSE;
23907c478bd9Sstevel@tonic-gate break;
23917c478bd9Sstevel@tonic-gate }
23927c478bd9Sstevel@tonic-gate got_equal = TRUE;
23937c478bd9Sstevel@tonic-gate got_data = FALSE;
23947c478bd9Sstevel@tonic-gate } else if (*s == COMMA_CHAR) {
23957c478bd9Sstevel@tonic-gate if (!got_data || !got_equal)
23967c478bd9Sstevel@tonic-gate break;
23977c478bd9Sstevel@tonic-gate got_data = FALSE;
23987c478bd9Sstevel@tonic-gate got_equal = FALSE;
23997c478bd9Sstevel@tonic-gate } else if (is_whitespace(*s))
24007c478bd9Sstevel@tonic-gate ;
24017c478bd9Sstevel@tonic-gate else
24027c478bd9Sstevel@tonic-gate got_data = TRUE;
24037c478bd9Sstevel@tonic-gate s++;
24047c478bd9Sstevel@tonic-gate }
24057c478bd9Sstevel@tonic-gate if (!got_data || !got_equal || in_quote)
24067c478bd9Sstevel@tonic-gate s = NULL;
24077c478bd9Sstevel@tonic-gate else {
24087c478bd9Sstevel@tonic-gate *begin = s_begin;
24097c478bd9Sstevel@tonic-gate *end = s;
24107c478bd9Sstevel@tonic-gate while (s < s_end && is_whitespace(*s))
24117c478bd9Sstevel@tonic-gate s++;
24127c478bd9Sstevel@tonic-gate }
24137c478bd9Sstevel@tonic-gate if (p_error == no_parse_error)
24147c478bd9Sstevel@tonic-gate break;
24157c478bd9Sstevel@tonic-gate }
24167c478bd9Sstevel@tonic-gate if (s == NULL)
24177c478bd9Sstevel@tonic-gate p_error = parse_invalid_ldap_search_filter;
24187c478bd9Sstevel@tonic-gate
24197c478bd9Sstevel@tonic-gate return (s);
24207c478bd9Sstevel@tonic-gate }
24217c478bd9Sstevel@tonic-gate
24227c478bd9Sstevel@tonic-gate /* Utility functions */
24237c478bd9Sstevel@tonic-gate bool_t
validate_dn(const char * s,int len)24247c478bd9Sstevel@tonic-gate validate_dn(const char *s, int len)
24257c478bd9Sstevel@tonic-gate {
24267c478bd9Sstevel@tonic-gate const char *end = s + len;
24277c478bd9Sstevel@tonic-gate bool_t valid;
24287c478bd9Sstevel@tonic-gate
24297c478bd9Sstevel@tonic-gate valid = skip_get_dn(s, end) == end;
24307c478bd9Sstevel@tonic-gate
24317c478bd9Sstevel@tonic-gate if (!valid)
24327c478bd9Sstevel@tonic-gate p_error = parse_bad_dn;
24337c478bd9Sstevel@tonic-gate return (valid);
24347c478bd9Sstevel@tonic-gate }
24357c478bd9Sstevel@tonic-gate
24367c478bd9Sstevel@tonic-gate bool_t
validate_ldap_filter(const char * s,const char * end)24377c478bd9Sstevel@tonic-gate validate_ldap_filter(const char *s, const char *end)
24387c478bd9Sstevel@tonic-gate {
24397c478bd9Sstevel@tonic-gate const char *s_begin;
24407c478bd9Sstevel@tonic-gate const char *s_end;
24417c478bd9Sstevel@tonic-gate
24427c478bd9Sstevel@tonic-gate s_begin = s;
24437c478bd9Sstevel@tonic-gate s_end = end;
24447c478bd9Sstevel@tonic-gate
24457c478bd9Sstevel@tonic-gate if (*s == OPEN_PAREN_CHAR) {
24467c478bd9Sstevel@tonic-gate s = get_ldap_filter(&s_begin, &s_end);
24477c478bd9Sstevel@tonic-gate } else {
24487c478bd9Sstevel@tonic-gate /* Assume an attribute value list */
24497c478bd9Sstevel@tonic-gate s = get_ava_list(&s_begin, &s_end, FALSE);
24507c478bd9Sstevel@tonic-gate }
24517c478bd9Sstevel@tonic-gate if (s == NULL || s_end != end)
24527c478bd9Sstevel@tonic-gate p_error = parse_invalid_ldap_search_filter;
24537c478bd9Sstevel@tonic-gate
24547c478bd9Sstevel@tonic-gate return (p_error == no_parse_error);
24557c478bd9Sstevel@tonic-gate }
24567c478bd9Sstevel@tonic-gate
24577c478bd9Sstevel@tonic-gate char *
s_strndup(const char * s,int n)24587c478bd9Sstevel@tonic-gate s_strndup(const char *s, int n)
24597c478bd9Sstevel@tonic-gate {
24607c478bd9Sstevel@tonic-gate char *d = (char *)malloc(n + 1);
24617c478bd9Sstevel@tonic-gate
24627c478bd9Sstevel@tonic-gate if (d != NULL) {
24637c478bd9Sstevel@tonic-gate (void) memcpy(d, s, n);
24647c478bd9Sstevel@tonic-gate d[n] = '\0';
24657c478bd9Sstevel@tonic-gate } else {
24667c478bd9Sstevel@tonic-gate p_error = parse_no_mem_error;
24677c478bd9Sstevel@tonic-gate }
24687c478bd9Sstevel@tonic-gate
24697c478bd9Sstevel@tonic-gate return (d);
24707c478bd9Sstevel@tonic-gate }
24717c478bd9Sstevel@tonic-gate
24727c478bd9Sstevel@tonic-gate char *
s_strndup_esc(const char * s,int n)24737c478bd9Sstevel@tonic-gate s_strndup_esc(const char *s, int n)
24747c478bd9Sstevel@tonic-gate {
24757c478bd9Sstevel@tonic-gate char *d = (char *)malloc(n + 1);
24767c478bd9Sstevel@tonic-gate int i;
24777c478bd9Sstevel@tonic-gate int j;
24787c478bd9Sstevel@tonic-gate
24797c478bd9Sstevel@tonic-gate if (d != NULL) {
24807c478bd9Sstevel@tonic-gate for (i = 0, j = 0; i < n; i++) {
24817c478bd9Sstevel@tonic-gate if (s[i] == ESCAPE_CHAR)
24827c478bd9Sstevel@tonic-gate i++;
24837c478bd9Sstevel@tonic-gate d[j++] = s[i];
24847c478bd9Sstevel@tonic-gate }
24857c478bd9Sstevel@tonic-gate d[j] = '\0';
24867c478bd9Sstevel@tonic-gate } else {
24877c478bd9Sstevel@tonic-gate p_error = parse_no_mem_error;
24887c478bd9Sstevel@tonic-gate }
24897c478bd9Sstevel@tonic-gate
24907c478bd9Sstevel@tonic-gate return (d);
24917c478bd9Sstevel@tonic-gate }
24927c478bd9Sstevel@tonic-gate
24937c478bd9Sstevel@tonic-gate void *
s_calloc(size_t n,size_t size)24947c478bd9Sstevel@tonic-gate s_calloc(size_t n, size_t size)
24957c478bd9Sstevel@tonic-gate {
24967c478bd9Sstevel@tonic-gate void *d = (char *)calloc(n, size);
24977c478bd9Sstevel@tonic-gate
24987c478bd9Sstevel@tonic-gate if (d == NULL) {
24997c478bd9Sstevel@tonic-gate p_error = parse_no_mem_error;
25007c478bd9Sstevel@tonic-gate }
25017c478bd9Sstevel@tonic-gate
25027c478bd9Sstevel@tonic-gate return (d);
25037c478bd9Sstevel@tonic-gate }
25047c478bd9Sstevel@tonic-gate
25057c478bd9Sstevel@tonic-gate void *
s_malloc(size_t size)25067c478bd9Sstevel@tonic-gate s_malloc(size_t size)
25077c478bd9Sstevel@tonic-gate {
25087c478bd9Sstevel@tonic-gate void *d = malloc(size);
25097c478bd9Sstevel@tonic-gate if (d == NULL)
25107c478bd9Sstevel@tonic-gate p_error = parse_no_mem_error;
25117c478bd9Sstevel@tonic-gate return (d);
25127c478bd9Sstevel@tonic-gate }
25137c478bd9Sstevel@tonic-gate
25147c478bd9Sstevel@tonic-gate void *
s_realloc(void * s,size_t size)25157c478bd9Sstevel@tonic-gate s_realloc(void *s, size_t size)
25167c478bd9Sstevel@tonic-gate {
25177c478bd9Sstevel@tonic-gate s = realloc(s, size);
25187c478bd9Sstevel@tonic-gate if (s == NULL)
25197c478bd9Sstevel@tonic-gate p_error = parse_no_mem_error;
25207c478bd9Sstevel@tonic-gate return (s);
25217c478bd9Sstevel@tonic-gate }
25227c478bd9Sstevel@tonic-gate
25237c478bd9Sstevel@tonic-gate char *
s_strdup(const char * s)25247c478bd9Sstevel@tonic-gate s_strdup(const char *s)
25257c478bd9Sstevel@tonic-gate {
25267c478bd9Sstevel@tonic-gate return (s != NULL ? s_strndup(s, strlen(s)) : NULL);
25277c478bd9Sstevel@tonic-gate }
25287c478bd9Sstevel@tonic-gate
25297c478bd9Sstevel@tonic-gate bool_t
is_whitespace(int c)25307c478bd9Sstevel@tonic-gate is_whitespace(int c)
25317c478bd9Sstevel@tonic-gate {
25327c478bd9Sstevel@tonic-gate return (c == ' ' || c == '\t');
25337c478bd9Sstevel@tonic-gate }
25347c478bd9Sstevel@tonic-gate
25357c478bd9Sstevel@tonic-gate bool_t
is_string_ok(char * buffer,int buflen)25367c478bd9Sstevel@tonic-gate is_string_ok(char *buffer, int buflen)
25377c478bd9Sstevel@tonic-gate {
25387c478bd9Sstevel@tonic-gate int i;
25397c478bd9Sstevel@tonic-gate
25407c478bd9Sstevel@tonic-gate if (buffer == NULL)
25417c478bd9Sstevel@tonic-gate return (FALSE);
25427c478bd9Sstevel@tonic-gate
25437c478bd9Sstevel@tonic-gate for (i = 0; i < buflen; i++) {
25447c478bd9Sstevel@tonic-gate if (!is_whitespace(buffer[i])) {
25457c478bd9Sstevel@tonic-gate if (buffer[i] == POUND_SIGN)
25467c478bd9Sstevel@tonic-gate return (TRUE);
25477c478bd9Sstevel@tonic-gate else
25487c478bd9Sstevel@tonic-gate return (FALSE);
25497c478bd9Sstevel@tonic-gate }
25507c478bd9Sstevel@tonic-gate }
25517c478bd9Sstevel@tonic-gate return (TRUE);
25527c478bd9Sstevel@tonic-gate }
25537c478bd9Sstevel@tonic-gate
25547c478bd9Sstevel@tonic-gate /*
25557c478bd9Sstevel@tonic-gate * Returns true if the first string is contained at the beginning of the
25567c478bd9Sstevel@tonic-gate * second string. Otherwise returns false.
25577c478bd9Sstevel@tonic-gate */
25587c478bd9Sstevel@tonic-gate
25597c478bd9Sstevel@tonic-gate bool_t
contains_string(const char * s1,const char * s2)25607c478bd9Sstevel@tonic-gate contains_string(const char *s1, const char *s2)
25617c478bd9Sstevel@tonic-gate {
25627c478bd9Sstevel@tonic-gate return (strncasecmp(s1, s2, strlen(s1)) == 0);
25637c478bd9Sstevel@tonic-gate }
25647c478bd9Sstevel@tonic-gate
25657c478bd9Sstevel@tonic-gate /*
25667c478bd9Sstevel@tonic-gate * Returns the next character position in the second string, if the first
25677c478bd9Sstevel@tonic-gate * string is contained at the beginning of the second string. Otherwise
25687c478bd9Sstevel@tonic-gate * returns NULL.
25697c478bd9Sstevel@tonic-gate */
25707c478bd9Sstevel@tonic-gate
25717c478bd9Sstevel@tonic-gate const char *
skip_string(const char * s1,const char * s2,int len)25727c478bd9Sstevel@tonic-gate skip_string(const char *s1, const char *s2, int len)
25737c478bd9Sstevel@tonic-gate {
25747c478bd9Sstevel@tonic-gate int len1 = strlen(s1);
25757c478bd9Sstevel@tonic-gate
25767c478bd9Sstevel@tonic-gate if (len >= len1 && strncasecmp(s1, s2, strlen(s1)) == 0)
25777c478bd9Sstevel@tonic-gate return (s2 + len1);
25787c478bd9Sstevel@tonic-gate else
25797c478bd9Sstevel@tonic-gate return (NULL);
25807c478bd9Sstevel@tonic-gate }
25817c478bd9Sstevel@tonic-gate
25827c478bd9Sstevel@tonic-gate /*
25837c478bd9Sstevel@tonic-gate * The second string is not necessarily null terminated.
25847c478bd9Sstevel@tonic-gate * same_string returns true if the second string matches the first.
25857c478bd9Sstevel@tonic-gate * Otherwise returns false.
25867c478bd9Sstevel@tonic-gate */
25877c478bd9Sstevel@tonic-gate
25887c478bd9Sstevel@tonic-gate bool_t
same_string(const char * s1,const char * s2,int len)25897c478bd9Sstevel@tonic-gate same_string(const char *s1, const char *s2, int len)
25907c478bd9Sstevel@tonic-gate {
25917c478bd9Sstevel@tonic-gate int len1 = strlen(s1);
25927c478bd9Sstevel@tonic-gate
25937c478bd9Sstevel@tonic-gate return (len1 == len && strncasecmp(s1, s2, len1) == 0);
25947c478bd9Sstevel@tonic-gate }
25957c478bd9Sstevel@tonic-gate
25967c478bd9Sstevel@tonic-gate void
report_error(const char * str,const char * attr)25977c478bd9Sstevel@tonic-gate report_error(const char *str, const char *attr)
25987c478bd9Sstevel@tonic-gate {
25997c478bd9Sstevel@tonic-gate char fmt_buf[1024];
26007c478bd9Sstevel@tonic-gate int pos = 0;
26017c478bd9Sstevel@tonic-gate
26027c478bd9Sstevel@tonic-gate if (command_line_source != NULL) {
26037c478bd9Sstevel@tonic-gate snprintf(fmt_buf, sizeof (fmt_buf), "Error parsing %s: ",
26047c478bd9Sstevel@tonic-gate command_line_source);
26057c478bd9Sstevel@tonic-gate pos = strlen(fmt_buf);
26067c478bd9Sstevel@tonic-gate } else if (file_source != NULL) {
26077c478bd9Sstevel@tonic-gate snprintf(fmt_buf, sizeof (fmt_buf), "Error parsing file '%s': ",
26087c478bd9Sstevel@tonic-gate file_source);
26097c478bd9Sstevel@tonic-gate pos = strlen(fmt_buf);
26107c478bd9Sstevel@tonic-gate } else if (ldap_source != NULL) {
26117c478bd9Sstevel@tonic-gate snprintf(fmt_buf, sizeof (fmt_buf), "Error for LDAP dn '%s': ",
26127c478bd9Sstevel@tonic-gate ldap_source);
26137c478bd9Sstevel@tonic-gate pos = strlen(fmt_buf);
26147c478bd9Sstevel@tonic-gate }
26157c478bd9Sstevel@tonic-gate
26167c478bd9Sstevel@tonic-gate if (start_line_num != 0) {
26177c478bd9Sstevel@tonic-gate snprintf(fmt_buf + pos, sizeof (fmt_buf) - pos, "at line %d: ",
26187c478bd9Sstevel@tonic-gate start_line_num);
26197c478bd9Sstevel@tonic-gate pos += strlen(fmt_buf + pos);
26207c478bd9Sstevel@tonic-gate }
26217c478bd9Sstevel@tonic-gate
26227c478bd9Sstevel@tonic-gate if (attr != NULL) {
26237c478bd9Sstevel@tonic-gate snprintf(fmt_buf + pos, sizeof (fmt_buf) - pos,
26247c478bd9Sstevel@tonic-gate "for attribute %s: ", attr);
26257c478bd9Sstevel@tonic-gate pos += strlen(fmt_buf + pos);
26267c478bd9Sstevel@tonic-gate }
26277c478bd9Sstevel@tonic-gate
26287c478bd9Sstevel@tonic-gate if (cons != NULL) {
26297c478bd9Sstevel@tonic-gate snprintf(fmt_buf + pos, sizeof (fmt_buf) - pos, "%s\n",
26307c478bd9Sstevel@tonic-gate parse_error_msg[p_error]);
26317c478bd9Sstevel@tonic-gate fprintf(cons, fmt_buf, str == NULL ? "" : str);
26327c478bd9Sstevel@tonic-gate } else {
26337c478bd9Sstevel@tonic-gate snprintf(fmt_buf + pos, sizeof (fmt_buf) - pos, "%s",
26347c478bd9Sstevel@tonic-gate parse_error_msg[p_error]);
26357c478bd9Sstevel@tonic-gate syslog(LOG_ERR, fmt_buf, str == NULL ? "" : str);
26367c478bd9Sstevel@tonic-gate }
26377c478bd9Sstevel@tonic-gate }
26387c478bd9Sstevel@tonic-gate
26397c478bd9Sstevel@tonic-gate void
report_error2(const char * str1,const char * str2)26407c478bd9Sstevel@tonic-gate report_error2(
26417c478bd9Sstevel@tonic-gate const char *str1,
26427c478bd9Sstevel@tonic-gate const char *str2)
26437c478bd9Sstevel@tonic-gate {
26447c478bd9Sstevel@tonic-gate char fmt_buf[1024];
26457c478bd9Sstevel@tonic-gate
26467c478bd9Sstevel@tonic-gate if (cons != NULL) {
26477c478bd9Sstevel@tonic-gate snprintf(fmt_buf, sizeof (fmt_buf),
26487c478bd9Sstevel@tonic-gate "%s\n", parse_error_msg[p_error]);
26497c478bd9Sstevel@tonic-gate fprintf(cons, fmt_buf, str1, str2);
26507c478bd9Sstevel@tonic-gate } else {
26517c478bd9Sstevel@tonic-gate syslog(LOG_ERR, parse_error_msg[p_error], str1, str2);
26527c478bd9Sstevel@tonic-gate }
26537c478bd9Sstevel@tonic-gate }
26547c478bd9Sstevel@tonic-gate
26557c478bd9Sstevel@tonic-gate void
report_conn_error(conn_error e,const char * str1,const char * str2)26567c478bd9Sstevel@tonic-gate report_conn_error(
26577c478bd9Sstevel@tonic-gate conn_error e,
26587c478bd9Sstevel@tonic-gate const char *str1,
26597c478bd9Sstevel@tonic-gate const char *str2)
26607c478bd9Sstevel@tonic-gate {
26617c478bd9Sstevel@tonic-gate char fmt_buf[1024];
26627c478bd9Sstevel@tonic-gate
26637c478bd9Sstevel@tonic-gate if (cons != NULL) {
26647c478bd9Sstevel@tonic-gate snprintf(fmt_buf, sizeof (fmt_buf),
26657c478bd9Sstevel@tonic-gate "%s\n", conn_error_msg[e]);
26667c478bd9Sstevel@tonic-gate fprintf(cons, fmt_buf,
26677c478bd9Sstevel@tonic-gate str1 == NULL ? "" : str1,
26687c478bd9Sstevel@tonic-gate str2 == NULL ? "" : str2);
26697c478bd9Sstevel@tonic-gate } else {
26707c478bd9Sstevel@tonic-gate syslog(LOG_ERR,
26717c478bd9Sstevel@tonic-gate conn_error_msg[e],
26727c478bd9Sstevel@tonic-gate str1 == NULL ? "" : str1,
26737c478bd9Sstevel@tonic-gate str2 == NULL ? "" : str2);
26747c478bd9Sstevel@tonic-gate }
26757c478bd9Sstevel@tonic-gate }
26767c478bd9Sstevel@tonic-gate
26777c478bd9Sstevel@tonic-gate void
report_info(const char * str,const char * arg)26787c478bd9Sstevel@tonic-gate report_info(
26797c478bd9Sstevel@tonic-gate const char *str,
26807c478bd9Sstevel@tonic-gate const char *arg)
26817c478bd9Sstevel@tonic-gate {
26827c478bd9Sstevel@tonic-gate if (cons != NULL) {
26837c478bd9Sstevel@tonic-gate fputs(str, cons);
26847c478bd9Sstevel@tonic-gate if (arg != NULL)
26857c478bd9Sstevel@tonic-gate fputs(arg, cons);
26867c478bd9Sstevel@tonic-gate fputs("\n", cons);
26877c478bd9Sstevel@tonic-gate } else
26887c478bd9Sstevel@tonic-gate syslog(LOG_INFO, str, arg);
26897c478bd9Sstevel@tonic-gate }
2690