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 2001-2003 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 <locale.h> 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate #include "ldap_parse.h" 377c478bd9Sstevel@tonic-gate #include "nis_parse_ldap_conf.h" 38*a87701e9SGary Mills #include "nis_parse_ldap_yp_util.h" 39*a87701e9SGary Mills #include "nis_parse_ldap_util.h" 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate /* other attribute functions */ 427c478bd9Sstevel@tonic-gate static char *getIndex(const char **s_cur, const char *end_s); 437c478bd9Sstevel@tonic-gate static bool_t get_ttls(const char *s, const char *s_end, 447c478bd9Sstevel@tonic-gate __nis_table_mapping_t *t_mapping); 457c478bd9Sstevel@tonic-gate static __nis_object_dn_t *parse_object_dn(const char *s, const char *end); 467c478bd9Sstevel@tonic-gate static int parse_name_fields(const char *name_s, const char *name_s_end, 477c478bd9Sstevel@tonic-gate __nis_table_mapping_t *t_mapping); 487c478bd9Sstevel@tonic-gate static void get_mapping_rule(const char *s, int len, 497c478bd9Sstevel@tonic-gate __nis_table_mapping_t *tbl, bool_t to_ldap); 507c478bd9Sstevel@tonic-gate static bool_t get_deleteDisp(const char *s_begin, const char *s_end, 517c478bd9Sstevel@tonic-gate __nis_object_dn_t *obj_dn); 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate /* mapping rule functions */ 547c478bd9Sstevel@tonic-gate static const char *get_lhs(const char *s, const char *end_s, 557c478bd9Sstevel@tonic-gate __nis_mapping_rlhs_t *lhs, __nis_mapping_item_type_t item_type); 567c478bd9Sstevel@tonic-gate static const char *get_lhs_match(const char *s, const char *end_s, 577c478bd9Sstevel@tonic-gate __nis_mapping_rlhs_t *lhs, __nis_mapping_item_type_t item_type); 587c478bd9Sstevel@tonic-gate static const char *get_lhs_paren_item(const char *s, const char *end_s, 597c478bd9Sstevel@tonic-gate __nis_mapping_rlhs_t *lhs, __nis_mapping_item_type_t item_type); 607c478bd9Sstevel@tonic-gate static const char *get_rhs(const char *s, const char *end_s, 617c478bd9Sstevel@tonic-gate __nis_mapping_rlhs_t *lhs, __nis_mapping_item_type_t item_type); 627c478bd9Sstevel@tonic-gate static const char *get_mapping_item(const char *s, const char *end_s, 637c478bd9Sstevel@tonic-gate __nis_mapping_item_t *item, __nis_mapping_item_type_t type); 647c478bd9Sstevel@tonic-gate static const char *get_print_mapping_element(const char *s, 657c478bd9Sstevel@tonic-gate const char *end_s, char *fmt_string, __nis_mapping_element_t *e, 667c478bd9Sstevel@tonic-gate __nis_mapping_item_type_t item_type); 677c478bd9Sstevel@tonic-gate static const char *get_subElement(const char *s, const char *end_s, 687c478bd9Sstevel@tonic-gate __nis_mapping_sub_element_t *subelement, 697c478bd9Sstevel@tonic-gate __nis_mapping_item_type_t type); 707c478bd9Sstevel@tonic-gate static bool_t get_mapping_format(const char *fmt_string, 717c478bd9Sstevel@tonic-gate __nis_mapping_format_t **fmt, int *nfmt, int *numItems, 727c478bd9Sstevel@tonic-gate bool_t print_mapping); 737c478bd9Sstevel@tonic-gate extern __yp_domain_context_t ypDomains; 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate /* 767c478bd9Sstevel@tonic-gate * FUNCTION: add_mapping_attribute 777c478bd9Sstevel@tonic-gate * 787c478bd9Sstevel@tonic-gate * Adds the attribute value to __nis_table_mapping_t 797c478bd9Sstevel@tonic-gate * if the value is not yet set for the given database. 807c478bd9Sstevel@tonic-gate * 817c478bd9Sstevel@tonic-gate * RETURN VALUE: 0 on success, -1 on failure 827c478bd9Sstevel@tonic-gate * 837c478bd9Sstevel@tonic-gate * INPUT: attribute number and value 847c478bd9Sstevel@tonic-gate */ 857c478bd9Sstevel@tonic-gate 867c478bd9Sstevel@tonic-gate int 877c478bd9Sstevel@tonic-gate add_mapping_attribute( 887c478bd9Sstevel@tonic-gate config_key attrib_num, 897c478bd9Sstevel@tonic-gate const char *attrib_val, 907c478bd9Sstevel@tonic-gate int attrib_len, 917c478bd9Sstevel@tonic-gate __nis_table_mapping_t **table_mapping) 927c478bd9Sstevel@tonic-gate { 937c478bd9Sstevel@tonic-gate const char *s; 947c478bd9Sstevel@tonic-gate const char *attrib_end; 957c478bd9Sstevel@tonic-gate const char *db_id_end; 967c478bd9Sstevel@tonic-gate const char *begin_token; 977c478bd9Sstevel@tonic-gate char *index_string; 987c478bd9Sstevel@tonic-gate __nis_object_dn_t *objectDN; 997c478bd9Sstevel@tonic-gate __nis_table_mapping_t *t_mapping; 1007c478bd9Sstevel@tonic-gate __nis_table_mapping_t *t; 1017c478bd9Sstevel@tonic-gate 1027c478bd9Sstevel@tonic-gate bool_t new_mapping = FALSE; 1037c478bd9Sstevel@tonic-gate int nm; 1047c478bd9Sstevel@tonic-gate char *tmp_dbId; 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate attrib_end = attrib_val + attrib_len; 1077c478bd9Sstevel@tonic-gate for (s = attrib_val; s < attrib_end; s++) 1087c478bd9Sstevel@tonic-gate if (*s == COLON_CHAR) 1097c478bd9Sstevel@tonic-gate break; 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate if (s == attrib_end || *attrib_val == COLON_CHAR) { 1127c478bd9Sstevel@tonic-gate p_error = parse_unexpected_data_end_rule; 1137c478bd9Sstevel@tonic-gate return (-1); 1147c478bd9Sstevel@tonic-gate } 1157c478bd9Sstevel@tonic-gate 1167c478bd9Sstevel@tonic-gate db_id_end = s; 1177c478bd9Sstevel@tonic-gate while (s > attrib_val && is_whitespace(s[-1])) 1187c478bd9Sstevel@tonic-gate s--; 1197c478bd9Sstevel@tonic-gate 1207c478bd9Sstevel@tonic-gate if (s == attrib_val) { 1217c478bd9Sstevel@tonic-gate p_error = parse_unexpected_data_end_rule; 1227c478bd9Sstevel@tonic-gate return (-1); 1237c478bd9Sstevel@tonic-gate } 1247c478bd9Sstevel@tonic-gate 1257c478bd9Sstevel@tonic-gate if (yp2ldap) { 1267c478bd9Sstevel@tonic-gate tmp_dbId = s_strndup(attrib_val, s - attrib_val); 1277c478bd9Sstevel@tonic-gate if (tmp_dbId == NULL) { 1287c478bd9Sstevel@tonic-gate p_error = parse_no_mem_error; 1297c478bd9Sstevel@tonic-gate return (-1); 1307c478bd9Sstevel@tonic-gate } 1317c478bd9Sstevel@tonic-gate if (strchr(tmp_dbId, COMMA_CHAR)) { 1327c478bd9Sstevel@tonic-gate /* domain explicitly specified */ 1337c478bd9Sstevel@tonic-gate nm = check_domain_specific_order(tmp_dbId, 1347c478bd9Sstevel@tonic-gate attrib_num, *table_mapping, &ypDomains); 1357c478bd9Sstevel@tonic-gate /* 1367c478bd9Sstevel@tonic-gate * No logging is needed here, as 1377c478bd9Sstevel@tonic-gate * check_domain_specific_order 1387c478bd9Sstevel@tonic-gate * will log any appropriate errors. 1397c478bd9Sstevel@tonic-gate */ 1407c478bd9Sstevel@tonic-gate if (nm != 0) { 1417c478bd9Sstevel@tonic-gate free(tmp_dbId); 1427c478bd9Sstevel@tonic-gate return (-1); 1437c478bd9Sstevel@tonic-gate } 1447c478bd9Sstevel@tonic-gate } 1457c478bd9Sstevel@tonic-gate free(tmp_dbId); 1467c478bd9Sstevel@tonic-gate } 1477c478bd9Sstevel@tonic-gate 1487c478bd9Sstevel@tonic-gate if ((t_mapping = find_table_mapping(attrib_val, 1497c478bd9Sstevel@tonic-gate s - attrib_val, *table_mapping)) == NULL) { 1507c478bd9Sstevel@tonic-gate /* No mapping with this id, create one */ 1517c478bd9Sstevel@tonic-gate t_mapping = (__nis_table_mapping_t *) 1527c478bd9Sstevel@tonic-gate s_calloc(1, sizeof (__nis_table_mapping_t)); 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate if (t_mapping == NULL) { 1557c478bd9Sstevel@tonic-gate p_error = parse_no_mem_error; 1567c478bd9Sstevel@tonic-gate return (-1); 1577c478bd9Sstevel@tonic-gate } 1587c478bd9Sstevel@tonic-gate (void) initialize_table_mapping(t_mapping); 1597c478bd9Sstevel@tonic-gate 1607c478bd9Sstevel@tonic-gate /* dbId is the label before the colon */ 1617c478bd9Sstevel@tonic-gate t_mapping->dbId = s_strndup(attrib_val, s - attrib_val); 1627c478bd9Sstevel@tonic-gate if (t_mapping->dbId == NULL) { 1637c478bd9Sstevel@tonic-gate p_error = parse_no_mem_error; 1647c478bd9Sstevel@tonic-gate free(t_mapping); 1657c478bd9Sstevel@tonic-gate return (-1); 1667c478bd9Sstevel@tonic-gate } 1677c478bd9Sstevel@tonic-gate new_mapping = TRUE; 1687c478bd9Sstevel@tonic-gate } else { 1697c478bd9Sstevel@tonic-gate /* a table mapping already exists, use it */ 1707c478bd9Sstevel@tonic-gate new_mapping = FALSE; 1717c478bd9Sstevel@tonic-gate } 1727c478bd9Sstevel@tonic-gate 1737c478bd9Sstevel@tonic-gate s = db_id_end + 1; 1747c478bd9Sstevel@tonic-gate while (s < attrib_end && is_whitespace(*s)) 1757c478bd9Sstevel@tonic-gate s++; 1767c478bd9Sstevel@tonic-gate 1777c478bd9Sstevel@tonic-gate switch (attrib_num) { 1787c478bd9Sstevel@tonic-gate case key_yp_map_flags: 1797c478bd9Sstevel@tonic-gate if (t_mapping->usedns_flag != 0 || 1807c478bd9Sstevel@tonic-gate t_mapping->securemap_flag != 0) { 1817c478bd9Sstevel@tonic-gate warn_duplicate_map(t_mapping->dbId, 1827c478bd9Sstevel@tonic-gate attrib_num); 1837c478bd9Sstevel@tonic-gate break; 1847c478bd9Sstevel@tonic-gate } 1857c478bd9Sstevel@tonic-gate while (is_whitespace(*s) && s < attrib_end) 1867c478bd9Sstevel@tonic-gate s++; 1877c478bd9Sstevel@tonic-gate while (s < attrib_end) { 1887c478bd9Sstevel@tonic-gate if (s < attrib_end && *s == 'b') 1897c478bd9Sstevel@tonic-gate t_mapping->usedns_flag = 1; 1907c478bd9Sstevel@tonic-gate if (s < attrib_end && *s == 's') 1917c478bd9Sstevel@tonic-gate t_mapping->securemap_flag = 1; 1927c478bd9Sstevel@tonic-gate s++; 1937c478bd9Sstevel@tonic-gate } 1947c478bd9Sstevel@tonic-gate break; 1957c478bd9Sstevel@tonic-gate case key_yp_comment_char: 1967c478bd9Sstevel@tonic-gate if (t_mapping->commentChar != 1977c478bd9Sstevel@tonic-gate DEFAULT_COMMENT_CHAR) { 1987c478bd9Sstevel@tonic-gate warn_duplicate_map(t_mapping->dbId, attrib_num); 1997c478bd9Sstevel@tonic-gate break; 2007c478bd9Sstevel@tonic-gate } 2017c478bd9Sstevel@tonic-gate while (is_whitespace(*s) && s < attrib_end) 2027c478bd9Sstevel@tonic-gate s++; 2037c478bd9Sstevel@tonic-gate if (s < attrib_end && (s+1) < attrib_end && 2047c478bd9Sstevel@tonic-gate (s+2) <= attrib_end) { 2057c478bd9Sstevel@tonic-gate while (is_whitespace(attrib_end[-1])) 2067c478bd9Sstevel@tonic-gate attrib_end--; 2077c478bd9Sstevel@tonic-gate while (*s != SINGLE_QUOTE_CHAR) 2087c478bd9Sstevel@tonic-gate s++; 2097c478bd9Sstevel@tonic-gate if (*s == SINGLE_QUOTE_CHAR && 2107c478bd9Sstevel@tonic-gate *(s+2) == SINGLE_QUOTE_CHAR) { 2117c478bd9Sstevel@tonic-gate t_mapping->commentChar = *(s+1); 2127c478bd9Sstevel@tonic-gate } else if (*s == SINGLE_QUOTE_CHAR && 2137c478bd9Sstevel@tonic-gate *(s+1) == SINGLE_QUOTE_CHAR) { 2147c478bd9Sstevel@tonic-gate t_mapping->commentChar = NULL; 2157c478bd9Sstevel@tonic-gate } else { 2167c478bd9Sstevel@tonic-gate /* anything else is an error */ 2177c478bd9Sstevel@tonic-gate p_error = parse_bad_yp_comment_error; 2187c478bd9Sstevel@tonic-gate } 2197c478bd9Sstevel@tonic-gate break; 2207c478bd9Sstevel@tonic-gate } else { 2217c478bd9Sstevel@tonic-gate p_error = parse_bad_yp_comment_error; 2227c478bd9Sstevel@tonic-gate break; 2237c478bd9Sstevel@tonic-gate } 2247c478bd9Sstevel@tonic-gate case key_yp_repeated_field_separators: 2257c478bd9Sstevel@tonic-gate while (s < attrib_end && is_whitespace(*s)) 2267c478bd9Sstevel@tonic-gate s++; 2277c478bd9Sstevel@tonic-gate if (s < attrib_end) { 2287c478bd9Sstevel@tonic-gate while (is_whitespace(attrib_end[-1])) 2297c478bd9Sstevel@tonic-gate attrib_end--; 2307c478bd9Sstevel@tonic-gate while (s < attrib_end && 2317c478bd9Sstevel@tonic-gate *s != DOUBLE_QUOTE_CHAR) 2327c478bd9Sstevel@tonic-gate s++; 2337c478bd9Sstevel@tonic-gate s++; 2347c478bd9Sstevel@tonic-gate begin_token = s; 2357c478bd9Sstevel@tonic-gate while (s < attrib_end && 2367c478bd9Sstevel@tonic-gate *s != DOUBLE_QUOTE_CHAR) { 2377c478bd9Sstevel@tonic-gate if (*s == ESCAPE_CHAR) 2387c478bd9Sstevel@tonic-gate s++; 2397c478bd9Sstevel@tonic-gate s++; 2407c478bd9Sstevel@tonic-gate } 2417c478bd9Sstevel@tonic-gate t_mapping->separatorStr = 2427c478bd9Sstevel@tonic-gate s_strndup(begin_token, s - begin_token); 2437c478bd9Sstevel@tonic-gate if (t_mapping->separatorStr == NULL) 2447c478bd9Sstevel@tonic-gate break; 2457c478bd9Sstevel@tonic-gate } else { 2467c478bd9Sstevel@tonic-gate p_error = parse_bad_field_separator_error; 2477c478bd9Sstevel@tonic-gate } 2487c478bd9Sstevel@tonic-gate break; 2497c478bd9Sstevel@tonic-gate case key_yp_name_fields: 2507c478bd9Sstevel@tonic-gate case key_yp_split_field: 2517c478bd9Sstevel@tonic-gate if (t_mapping->e || t_mapping->numSplits > 0) { 2527c478bd9Sstevel@tonic-gate warn_duplicate_map(t_mapping->dbId, 2537c478bd9Sstevel@tonic-gate attrib_num); 2547c478bd9Sstevel@tonic-gate break; 2557c478bd9Sstevel@tonic-gate } 2567c478bd9Sstevel@tonic-gate if (parse_name_fields(s, attrib_end, t_mapping)) { 2577c478bd9Sstevel@tonic-gate p_error = parse_bad_name_field; 2587c478bd9Sstevel@tonic-gate } 2597c478bd9Sstevel@tonic-gate break; 2607c478bd9Sstevel@tonic-gate case key_yp_db_id_map: 2617c478bd9Sstevel@tonic-gate case key_db_id_map: 2627c478bd9Sstevel@tonic-gate if (t_mapping->objName != NULL) { 2637c478bd9Sstevel@tonic-gate warn_duplicate_map(t_mapping->dbId, attrib_num); 2647c478bd9Sstevel@tonic-gate break; 2657c478bd9Sstevel@tonic-gate } 2667c478bd9Sstevel@tonic-gate 2677c478bd9Sstevel@tonic-gate if (s < attrib_end && *s == OPEN_BRACKET) { 2687c478bd9Sstevel@tonic-gate index_string = getIndex(&s, attrib_end); 2697c478bd9Sstevel@tonic-gate if (index_string == NULL) 2707c478bd9Sstevel@tonic-gate break; 2717c478bd9Sstevel@tonic-gate (void) parse_index(index_string, 2727c478bd9Sstevel@tonic-gate index_string + strlen(index_string), 2737c478bd9Sstevel@tonic-gate &t_mapping->index); 2747c478bd9Sstevel@tonic-gate free(index_string); 2757c478bd9Sstevel@tonic-gate if (p_error != no_parse_error) 2767c478bd9Sstevel@tonic-gate break; 2777c478bd9Sstevel@tonic-gate } 2787c478bd9Sstevel@tonic-gate while (is_whitespace(*s) && s < attrib_end) 2797c478bd9Sstevel@tonic-gate s++; 2807c478bd9Sstevel@tonic-gate if (s < attrib_end) { 2817c478bd9Sstevel@tonic-gate while (is_whitespace(attrib_end[-1])) 2827c478bd9Sstevel@tonic-gate attrib_end--; 2837c478bd9Sstevel@tonic-gate t_mapping->objName = 2847c478bd9Sstevel@tonic-gate s_strndup_esc(s, attrib_end - s); 2857c478bd9Sstevel@tonic-gate } else { 2867c478bd9Sstevel@tonic-gate if (yp2ldap) { 2877c478bd9Sstevel@tonic-gate p_error = parse_bad_map_error; 2887c478bd9Sstevel@tonic-gate } else { 2897c478bd9Sstevel@tonic-gate t_mapping->objName = s_strndup(s, 0); 2907c478bd9Sstevel@tonic-gate } 2917c478bd9Sstevel@tonic-gate } 2927c478bd9Sstevel@tonic-gate break; 2937c478bd9Sstevel@tonic-gate 2947c478bd9Sstevel@tonic-gate case key_yp_entry_ttl: 2957c478bd9Sstevel@tonic-gate case key_entry_ttl: 2967c478bd9Sstevel@tonic-gate if (t_mapping->initTtlLo != (time_t)NO_VALUE_SET) { 2977c478bd9Sstevel@tonic-gate warn_duplicate_map(t_mapping->dbId, attrib_num); 2987c478bd9Sstevel@tonic-gate break; 2997c478bd9Sstevel@tonic-gate } 3007c478bd9Sstevel@tonic-gate 3017c478bd9Sstevel@tonic-gate if (!get_ttls(s, attrib_end, t_mapping)) 3027c478bd9Sstevel@tonic-gate p_error = parse_bad_ttl_format_error; 3037c478bd9Sstevel@tonic-gate break; 3047c478bd9Sstevel@tonic-gate 3057c478bd9Sstevel@tonic-gate case key_yp_ldap_object_dn: 3067c478bd9Sstevel@tonic-gate case key_ldap_object_dn: 3077c478bd9Sstevel@tonic-gate if (t_mapping->objectDN != NULL) { 3087c478bd9Sstevel@tonic-gate warn_duplicate_map(t_mapping->dbId, attrib_num); 3097c478bd9Sstevel@tonic-gate break; 3107c478bd9Sstevel@tonic-gate } 3117c478bd9Sstevel@tonic-gate objectDN = parse_object_dn(s, attrib_end); 3127c478bd9Sstevel@tonic-gate if (objectDN == NULL) 3137c478bd9Sstevel@tonic-gate break; 3147c478bd9Sstevel@tonic-gate t_mapping->objectDN = objectDN; 3157c478bd9Sstevel@tonic-gate t_mapping->seq_num = seq_num++; 3167c478bd9Sstevel@tonic-gate break; 3177c478bd9Sstevel@tonic-gate 3187c478bd9Sstevel@tonic-gate case key_nis_to_ldap_map: 3197c478bd9Sstevel@tonic-gate case key_nisplus_to_ldap_map: 3207c478bd9Sstevel@tonic-gate if (t_mapping->ruleToLDAP != 0) { 3217c478bd9Sstevel@tonic-gate warn_duplicate_map(t_mapping->dbId, attrib_num); 3227c478bd9Sstevel@tonic-gate break; 3237c478bd9Sstevel@tonic-gate } 3247c478bd9Sstevel@tonic-gate 3257c478bd9Sstevel@tonic-gate get_mapping_rule(s, attrib_end - s, t_mapping, TRUE); 3267c478bd9Sstevel@tonic-gate break; 3277c478bd9Sstevel@tonic-gate 3287c478bd9Sstevel@tonic-gate case key_ldap_to_nis_map: 3297c478bd9Sstevel@tonic-gate case key_ldap_to_nisplus_map: 3307c478bd9Sstevel@tonic-gate if (t_mapping->ruleFromLDAP != NULL) { 3317c478bd9Sstevel@tonic-gate warn_duplicate_map(t_mapping->dbId, attrib_num); 3327c478bd9Sstevel@tonic-gate break; 3337c478bd9Sstevel@tonic-gate } 3347c478bd9Sstevel@tonic-gate 3357c478bd9Sstevel@tonic-gate get_mapping_rule(s, attrib_end - s, t_mapping, FALSE); 3367c478bd9Sstevel@tonic-gate break; 3377c478bd9Sstevel@tonic-gate 3387c478bd9Sstevel@tonic-gate default: 3397c478bd9Sstevel@tonic-gate p_error = parse_internal_error; 3407c478bd9Sstevel@tonic-gate break; 3417c478bd9Sstevel@tonic-gate } 3427c478bd9Sstevel@tonic-gate if (p_error == no_parse_error) { 3437c478bd9Sstevel@tonic-gate if (new_mapping) { 3447c478bd9Sstevel@tonic-gate if (*table_mapping == NULL) 3457c478bd9Sstevel@tonic-gate *table_mapping = t_mapping; 3467c478bd9Sstevel@tonic-gate else { 3477c478bd9Sstevel@tonic-gate for (t = *table_mapping; t->next != NULL; 3487c478bd9Sstevel@tonic-gate t = t->next) 3497c478bd9Sstevel@tonic-gate ; 3507c478bd9Sstevel@tonic-gate t->next = t_mapping; 3517c478bd9Sstevel@tonic-gate } 3527c478bd9Sstevel@tonic-gate } 3537c478bd9Sstevel@tonic-gate } else { 3547c478bd9Sstevel@tonic-gate if (new_mapping) 3557c478bd9Sstevel@tonic-gate free_table_mapping(t_mapping); 3567c478bd9Sstevel@tonic-gate } 3577c478bd9Sstevel@tonic-gate return (p_error == no_parse_error ? 0 : -1); 3587c478bd9Sstevel@tonic-gate } 3597c478bd9Sstevel@tonic-gate 3607c478bd9Sstevel@tonic-gate /* 3617c478bd9Sstevel@tonic-gate * FUNCTION: add_ypdomains_attribute 3627c478bd9Sstevel@tonic-gate * 3637c478bd9Sstevel@tonic-gate * Adds the yp domains information to the __yp_domain_context_t 3647c478bd9Sstevel@tonic-gate * structure. 3657c478bd9Sstevel@tonic-gate * 3667c478bd9Sstevel@tonic-gate * RETURN: 0 on success, -1 on failure 3677c478bd9Sstevel@tonic-gate * 3687c478bd9Sstevel@tonic-gate * INPUT: attribute number and value 3697c478bd9Sstevel@tonic-gate */ 3707c478bd9Sstevel@tonic-gate 3717c478bd9Sstevel@tonic-gate int 3727c478bd9Sstevel@tonic-gate add_ypdomains_attribute( 3737c478bd9Sstevel@tonic-gate config_key attrib_num, 3747c478bd9Sstevel@tonic-gate const char *attrib_val, 3757c478bd9Sstevel@tonic-gate int attrib_len, 3767c478bd9Sstevel@tonic-gate __yp_domain_context_t *ypDomains) 3777c478bd9Sstevel@tonic-gate { 3787c478bd9Sstevel@tonic-gate const char *s; 3797c478bd9Sstevel@tonic-gate const char *attrib_end; 3807c478bd9Sstevel@tonic-gate int numDomains = 0; 3817c478bd9Sstevel@tonic-gate 3827c478bd9Sstevel@tonic-gate attrib_end = attrib_val + attrib_len; 3837c478bd9Sstevel@tonic-gate for (s = attrib_val; s < attrib_end; s++) { 3847c478bd9Sstevel@tonic-gate if (*s == COLON_CHAR) { 3857c478bd9Sstevel@tonic-gate break; 3867c478bd9Sstevel@tonic-gate } 3877c478bd9Sstevel@tonic-gate } 3887c478bd9Sstevel@tonic-gate while (s > attrib_val && is_whitespace(s[-1])) 3897c478bd9Sstevel@tonic-gate s--; 3907c478bd9Sstevel@tonic-gate 3917c478bd9Sstevel@tonic-gate if (s == attrib_val) { 3927c478bd9Sstevel@tonic-gate p_error = parse_unexpected_data_end_rule; 3937c478bd9Sstevel@tonic-gate return (-1); 3947c478bd9Sstevel@tonic-gate } 3957c478bd9Sstevel@tonic-gate 3967c478bd9Sstevel@tonic-gate if (ypDomains == NULL) { 3977c478bd9Sstevel@tonic-gate /* 3987c478bd9Sstevel@tonic-gate * No point allocating. We cant return the resulting structure, 3997c478bd9Sstevel@tonic-gate * so just return failure. Should not ever happen because we 4007c478bd9Sstevel@tonic-gate * are always called with a pointer to the global ypDomains 4017c478bd9Sstevel@tonic-gate * structure. 4027c478bd9Sstevel@tonic-gate */ 4037c478bd9Sstevel@tonic-gate return (-1); 4047c478bd9Sstevel@tonic-gate } 4057c478bd9Sstevel@tonic-gate 4067c478bd9Sstevel@tonic-gate switch (attrib_num) { 4077c478bd9Sstevel@tonic-gate case key_yp_domain_context: 4087c478bd9Sstevel@tonic-gate numDomains = ypDomains->numDomains; 4097c478bd9Sstevel@tonic-gate ypDomains->domainLabels = 4107c478bd9Sstevel@tonic-gate (char **)s_realloc(ypDomains->domainLabels, 4117c478bd9Sstevel@tonic-gate (numDomains + 1) * 4127c478bd9Sstevel@tonic-gate sizeof (ypDomains->domainLabels[0])); 4137c478bd9Sstevel@tonic-gate if (ypDomains->domainLabels == NULL) { 4147c478bd9Sstevel@tonic-gate p_error = parse_no_mem_error; 4157c478bd9Sstevel@tonic-gate free_yp_domain_context(ypDomains); 4167c478bd9Sstevel@tonic-gate break; 4177c478bd9Sstevel@tonic-gate } 4187c478bd9Sstevel@tonic-gate ypDomains->domainLabels[numDomains] = 4197c478bd9Sstevel@tonic-gate s_strndup(attrib_val, s - attrib_val); 4207c478bd9Sstevel@tonic-gate if (ypDomains->domainLabels[numDomains] == NULL) { 4217c478bd9Sstevel@tonic-gate p_error = parse_no_mem_error; 4227c478bd9Sstevel@tonic-gate free_yp_domain_context(ypDomains); 4237c478bd9Sstevel@tonic-gate break; 4247c478bd9Sstevel@tonic-gate } 4257c478bd9Sstevel@tonic-gate ypDomains->numDomains = numDomains + 1; 4267c478bd9Sstevel@tonic-gate while (s < attrib_end && is_whitespace(*s)) 4277c478bd9Sstevel@tonic-gate s++; 4287c478bd9Sstevel@tonic-gate if (*s == COLON_CHAR) 4297c478bd9Sstevel@tonic-gate s++; 4307c478bd9Sstevel@tonic-gate while (s < attrib_end && is_whitespace(*s)) 4317c478bd9Sstevel@tonic-gate s++; 4327c478bd9Sstevel@tonic-gate ypDomains->domains = 4337c478bd9Sstevel@tonic-gate (char **)s_realloc(ypDomains->domains, 4347c478bd9Sstevel@tonic-gate (numDomains + 1) * 4357c478bd9Sstevel@tonic-gate sizeof (ypDomains->domains[0])); 4367c478bd9Sstevel@tonic-gate if (ypDomains->domains == NULL) { 4377c478bd9Sstevel@tonic-gate p_error = parse_no_mem_error; 4387c478bd9Sstevel@tonic-gate free_yp_domain_context(ypDomains); 4397c478bd9Sstevel@tonic-gate break; 4407c478bd9Sstevel@tonic-gate } 4417c478bd9Sstevel@tonic-gate 4427c478bd9Sstevel@tonic-gate if (s < attrib_end) { 4437c478bd9Sstevel@tonic-gate while (is_whitespace(attrib_end[-1])) 4447c478bd9Sstevel@tonic-gate attrib_end--; 4457c478bd9Sstevel@tonic-gate ypDomains->domains[numDomains] = 4467c478bd9Sstevel@tonic-gate s_strndup_esc(s, attrib_end - s); 4477c478bd9Sstevel@tonic-gate if (ypDomains->domains[numDomains] == NULL) { 4487c478bd9Sstevel@tonic-gate p_error = parse_no_mem_error; 4497c478bd9Sstevel@tonic-gate free_yp_domain_context(ypDomains); 4507c478bd9Sstevel@tonic-gate break; 4517c478bd9Sstevel@tonic-gate } 4527c478bd9Sstevel@tonic-gate } else { 4537c478bd9Sstevel@tonic-gate p_error = parse_unexpected_yp_domain_end_error; 4547c478bd9Sstevel@tonic-gate free(ypDomains->domainLabels[numDomains]); 4557c478bd9Sstevel@tonic-gate ypDomains->domainLabels[numDomains] = NULL; 4567c478bd9Sstevel@tonic-gate ypDomains->numDomains--; 4577c478bd9Sstevel@tonic-gate free_yp_domain_context(ypDomains); 4587c478bd9Sstevel@tonic-gate } 4597c478bd9Sstevel@tonic-gate break; 4607c478bd9Sstevel@tonic-gate case key_yppasswdd_domains: 4617c478bd9Sstevel@tonic-gate ypDomains->yppasswddDomainLabels = 4627c478bd9Sstevel@tonic-gate (char **)s_realloc( 4637c478bd9Sstevel@tonic-gate ypDomains->yppasswddDomainLabels, 4647c478bd9Sstevel@tonic-gate (ypDomains->numYppasswdd + 1) * 4657c478bd9Sstevel@tonic-gate sizeof (ypDomains->yppasswddDomainLabels[0])); 4667c478bd9Sstevel@tonic-gate if (ypDomains->yppasswddDomainLabels == NULL) { 4677c478bd9Sstevel@tonic-gate p_error = parse_no_mem_error; 4687c478bd9Sstevel@tonic-gate break; 4697c478bd9Sstevel@tonic-gate } 4707c478bd9Sstevel@tonic-gate ypDomains->yppasswddDomainLabels 4717c478bd9Sstevel@tonic-gate [ypDomains->numYppasswdd] = 4727c478bd9Sstevel@tonic-gate s_strndup(attrib_val, s - attrib_val); 4737c478bd9Sstevel@tonic-gate if (ypDomains->yppasswddDomainLabels 4747c478bd9Sstevel@tonic-gate [ypDomains->numYppasswdd] == NULL) { 4757c478bd9Sstevel@tonic-gate p_error = parse_no_mem_error; 4767c478bd9Sstevel@tonic-gate } 4777c478bd9Sstevel@tonic-gate ypDomains->numYppasswdd++; 4787c478bd9Sstevel@tonic-gate break; 4797c478bd9Sstevel@tonic-gate } 4807c478bd9Sstevel@tonic-gate 4817c478bd9Sstevel@tonic-gate return (p_error == no_parse_error ? 0 : -1); 4827c478bd9Sstevel@tonic-gate } 4837c478bd9Sstevel@tonic-gate 4847c478bd9Sstevel@tonic-gate /* 4857c478bd9Sstevel@tonic-gate * FUNCTION: get_ttls 4867c478bd9Sstevel@tonic-gate * 4877c478bd9Sstevel@tonic-gate * Parse time to live attribute 4887c478bd9Sstevel@tonic-gate * 4897c478bd9Sstevel@tonic-gate * RETURN VALUE: TRUE on success, FALSE on failure 4907c478bd9Sstevel@tonic-gate * 4917c478bd9Sstevel@tonic-gate * INPUT: the attribute value 4927c478bd9Sstevel@tonic-gate */ 4937c478bd9Sstevel@tonic-gate 4947c478bd9Sstevel@tonic-gate static bool_t 4957c478bd9Sstevel@tonic-gate get_ttls( 4967c478bd9Sstevel@tonic-gate const char *s, 4977c478bd9Sstevel@tonic-gate const char *s_end, 4987c478bd9Sstevel@tonic-gate __nis_table_mapping_t *t_mapping) 4997c478bd9Sstevel@tonic-gate { 5007c478bd9Sstevel@tonic-gate time_t initTtlHi = 0; 5017c478bd9Sstevel@tonic-gate time_t initTtlLo = 0; 5027c478bd9Sstevel@tonic-gate time_t ttl = 0; 5037c478bd9Sstevel@tonic-gate time_t digit; 5047c478bd9Sstevel@tonic-gate 5057c478bd9Sstevel@tonic-gate /* 5067c478bd9Sstevel@tonic-gate * attribute should be of the form 5077c478bd9Sstevel@tonic-gate * initialTTLlo ":" initialTTLhi ":" runningTTL 5087c478bd9Sstevel@tonic-gate */ 5097c478bd9Sstevel@tonic-gate 5107c478bd9Sstevel@tonic-gate if (s == s_end) { 5117c478bd9Sstevel@tonic-gate p_error = parse_bad_ttl_format_error; 5127c478bd9Sstevel@tonic-gate return (FALSE); 5137c478bd9Sstevel@tonic-gate } 5147c478bd9Sstevel@tonic-gate 5157c478bd9Sstevel@tonic-gate if (isdigit(*s)) { 5167c478bd9Sstevel@tonic-gate while (s < s_end && isdigit(*s)) { 5177c478bd9Sstevel@tonic-gate digit = (*s++) - '0'; 5187c478bd9Sstevel@tonic-gate if (WILL_OVERFLOW_TIME(initTtlLo, digit)) 5197c478bd9Sstevel@tonic-gate initTtlLo = TIME_MAX; 5207c478bd9Sstevel@tonic-gate else 5217c478bd9Sstevel@tonic-gate initTtlLo = initTtlLo * 10 + digit; 5227c478bd9Sstevel@tonic-gate } 5237c478bd9Sstevel@tonic-gate } else { 5247c478bd9Sstevel@tonic-gate initTtlLo = ONE_HOUR; 5257c478bd9Sstevel@tonic-gate } 5267c478bd9Sstevel@tonic-gate 5277c478bd9Sstevel@tonic-gate while (s < s_end && is_whitespace(*s)) 5287c478bd9Sstevel@tonic-gate s++; 5297c478bd9Sstevel@tonic-gate if (s + 1 >= s_end || *s++ != COLON_CHAR) { 5307c478bd9Sstevel@tonic-gate p_error = parse_bad_ttl_format_error; 5317c478bd9Sstevel@tonic-gate return (FALSE); 5327c478bd9Sstevel@tonic-gate } 5337c478bd9Sstevel@tonic-gate 5347c478bd9Sstevel@tonic-gate while (s < s_end && is_whitespace(*s)) 5357c478bd9Sstevel@tonic-gate s++; 5367c478bd9Sstevel@tonic-gate if (isdigit(*s)) { 5377c478bd9Sstevel@tonic-gate while (s < s_end && isdigit(*s)) { 5387c478bd9Sstevel@tonic-gate digit = (*s++) - '0'; 5397c478bd9Sstevel@tonic-gate if (WILL_OVERFLOW_TIME(initTtlHi, digit)) 5407c478bd9Sstevel@tonic-gate initTtlHi = TIME_MAX; 5417c478bd9Sstevel@tonic-gate else 5427c478bd9Sstevel@tonic-gate initTtlHi = initTtlHi * 10 + digit; 5437c478bd9Sstevel@tonic-gate } 5447c478bd9Sstevel@tonic-gate } else { 5457c478bd9Sstevel@tonic-gate initTtlHi = initTtlLo; 5467c478bd9Sstevel@tonic-gate } 5477c478bd9Sstevel@tonic-gate 5487c478bd9Sstevel@tonic-gate while (s < s_end && is_whitespace(*s)) 5497c478bd9Sstevel@tonic-gate s++; 5507c478bd9Sstevel@tonic-gate if (s >= s_end || *s++ != COLON_CHAR) { 5517c478bd9Sstevel@tonic-gate p_error = parse_bad_ttl_format_error; 5527c478bd9Sstevel@tonic-gate return (FALSE); 5537c478bd9Sstevel@tonic-gate } 5547c478bd9Sstevel@tonic-gate 5557c478bd9Sstevel@tonic-gate while (s < s_end && is_whitespace(*s)) 5567c478bd9Sstevel@tonic-gate s++; 5577c478bd9Sstevel@tonic-gate if (isdigit(*s)) { 5587c478bd9Sstevel@tonic-gate while (s < s_end && isdigit(*s)) { 5597c478bd9Sstevel@tonic-gate digit = (*s++) - '0'; 5607c478bd9Sstevel@tonic-gate if (WILL_OVERFLOW_TIME(ttl, digit)) 5617c478bd9Sstevel@tonic-gate ttl = TIME_MAX; 5627c478bd9Sstevel@tonic-gate else 5637c478bd9Sstevel@tonic-gate ttl = ttl * 10 + digit; 5647c478bd9Sstevel@tonic-gate } 5657c478bd9Sstevel@tonic-gate } else { 5667c478bd9Sstevel@tonic-gate ttl = ONE_HOUR; 5677c478bd9Sstevel@tonic-gate } 5687c478bd9Sstevel@tonic-gate while (s < s_end && is_whitespace(*s)) 5697c478bd9Sstevel@tonic-gate s++; 5707c478bd9Sstevel@tonic-gate if (s != s_end) { 5717c478bd9Sstevel@tonic-gate p_error = parse_bad_ttl_format_error; 5727c478bd9Sstevel@tonic-gate return (FALSE); 5737c478bd9Sstevel@tonic-gate } 5747c478bd9Sstevel@tonic-gate 5757c478bd9Sstevel@tonic-gate t_mapping->initTtlLo = initTtlLo; 5767c478bd9Sstevel@tonic-gate t_mapping->initTtlHi = initTtlHi; 5777c478bd9Sstevel@tonic-gate t_mapping->ttl = ttl; 5787c478bd9Sstevel@tonic-gate return (TRUE); 5797c478bd9Sstevel@tonic-gate } 5807c478bd9Sstevel@tonic-gate 5817c478bd9Sstevel@tonic-gate /* 5827c478bd9Sstevel@tonic-gate * FUNCTION: parse_name_fields 5837c478bd9Sstevel@tonic-gate * 5847c478bd9Sstevel@tonic-gate * Parse yp name fields 5857c478bd9Sstevel@tonic-gate * 5867c478bd9Sstevel@tonic-gate * RETURN VALUE: 0 on success, non-zero on failure 5877c478bd9Sstevel@tonic-gate * 5887c478bd9Sstevel@tonic-gate * INPUTS: attrib_value and attribute_end pointers. 5897c478bd9Sstevel@tonic-gate */ 5907c478bd9Sstevel@tonic-gate 5917c478bd9Sstevel@tonic-gate static int 5927c478bd9Sstevel@tonic-gate parse_name_fields(const char *name_s, 5937c478bd9Sstevel@tonic-gate const char *name_s_end, 5947c478bd9Sstevel@tonic-gate __nis_table_mapping_t *t_map) 5957c478bd9Sstevel@tonic-gate { 5967c478bd9Sstevel@tonic-gate int i, n = 0; 5977c478bd9Sstevel@tonic-gate int nElements = 0; 5987c478bd9Sstevel@tonic-gate int numSplits = 0; 5997c478bd9Sstevel@tonic-gate int parse_next_line = 1; 6007c478bd9Sstevel@tonic-gate int itm_count = 0; 6017c478bd9Sstevel@tonic-gate const char *begin_fmt; 6027c478bd9Sstevel@tonic-gate const char *end_fmt; 6037c478bd9Sstevel@tonic-gate const char *begin_token; 6047c478bd9Sstevel@tonic-gate const char *end_token; 6057c478bd9Sstevel@tonic-gate char *fmt_string = NULL; 6067c478bd9Sstevel@tonic-gate __nis_mapping_format_t *base = NULL; 6077c478bd9Sstevel@tonic-gate __nis_mapping_item_t *item = NULL; 6087c478bd9Sstevel@tonic-gate __nis_mapping_element_t *elmnt = NULL; 6097c478bd9Sstevel@tonic-gate __nis_mapping_item_type_t item_type = mit_nisplus; 6107c478bd9Sstevel@tonic-gate token_type token; 6117c478bd9Sstevel@tonic-gate 6127c478bd9Sstevel@tonic-gate t_map->numColumns = 0; 6137c478bd9Sstevel@tonic-gate 6147c478bd9Sstevel@tonic-gate for (; parse_next_line > 0; parse_next_line--) { 6157c478bd9Sstevel@tonic-gate nElements = 0; 6167c478bd9Sstevel@tonic-gate item = NULL; 6177c478bd9Sstevel@tonic-gate base = NULL; 6187c478bd9Sstevel@tonic-gate while (name_s < name_s_end && *name_s != OPEN_PAREN_CHAR) 6197c478bd9Sstevel@tonic-gate name_s++; 6207c478bd9Sstevel@tonic-gate if (name_s == name_s_end) { 6217c478bd9Sstevel@tonic-gate p_error = parse_unexpected_data_end_rule; 6227c478bd9Sstevel@tonic-gate return (1); 6237c478bd9Sstevel@tonic-gate } 6247c478bd9Sstevel@tonic-gate while (name_s < name_s_end && *name_s != DOUBLE_QUOTE_CHAR) 6257c478bd9Sstevel@tonic-gate name_s++; 6267c478bd9Sstevel@tonic-gate if (name_s == name_s_end) { 6277c478bd9Sstevel@tonic-gate p_error = parse_unexpected_data_end_rule; 6287c478bd9Sstevel@tonic-gate return (1); 6297c478bd9Sstevel@tonic-gate } 6307c478bd9Sstevel@tonic-gate begin_fmt = ++name_s; /* start of format string */ 6317c478bd9Sstevel@tonic-gate while (name_s < name_s_end && *name_s != DOUBLE_QUOTE_CHAR) 6327c478bd9Sstevel@tonic-gate name_s++; 6337c478bd9Sstevel@tonic-gate if (name_s == name_s_end) { 6347c478bd9Sstevel@tonic-gate p_error = parse_unexpected_data_end_rule; 6357c478bd9Sstevel@tonic-gate return (1); 6367c478bd9Sstevel@tonic-gate } 6377c478bd9Sstevel@tonic-gate end_fmt = name_s; 6387c478bd9Sstevel@tonic-gate fmt_string = s_strndup(begin_fmt, end_fmt - begin_fmt); 6397c478bd9Sstevel@tonic-gate if (fmt_string == NULL) { 6407c478bd9Sstevel@tonic-gate p_error = parse_no_mem_error; 6417c478bd9Sstevel@tonic-gate return (2); 6427c478bd9Sstevel@tonic-gate } 6437c478bd9Sstevel@tonic-gate if (!get_mapping_format(fmt_string, &base, &n, NULL, FALSE)) { 6447c478bd9Sstevel@tonic-gate p_error = parse_internal_error; 6457c478bd9Sstevel@tonic-gate free(fmt_string); 6467c478bd9Sstevel@tonic-gate fmt_string = NULL; 6477c478bd9Sstevel@tonic-gate return (3); 6487c478bd9Sstevel@tonic-gate } 6497c478bd9Sstevel@tonic-gate free(fmt_string); 6507c478bd9Sstevel@tonic-gate fmt_string = NULL; 6517c478bd9Sstevel@tonic-gate for (n = 0; base[n].type != mmt_end; n++) { 6527c478bd9Sstevel@tonic-gate if (base[n].type != mmt_item && base[n].type 6537c478bd9Sstevel@tonic-gate != mmt_berstring) { 6547c478bd9Sstevel@tonic-gate if (base[n].type == mmt_berstring_null) 6557c478bd9Sstevel@tonic-gate base[n].type = mmt_berstring; 6567c478bd9Sstevel@tonic-gate continue; 6577c478bd9Sstevel@tonic-gate } 6587c478bd9Sstevel@tonic-gate while (name_s < name_s_end && *name_s != COMMA_CHAR) 6597c478bd9Sstevel@tonic-gate name_s++; 6607c478bd9Sstevel@tonic-gate name_s++; /* now at comma char */ 6617c478bd9Sstevel@tonic-gate while (name_s < name_s_end && is_whitespace(*name_s)) 6627c478bd9Sstevel@tonic-gate name_s++; 6637c478bd9Sstevel@tonic-gate begin_token = name_s++; 6647c478bd9Sstevel@tonic-gate end_token = name_s_end; 6657c478bd9Sstevel@tonic-gate name_s = get_next_token( 6667c478bd9Sstevel@tonic-gate &begin_token, &end_token, &token); 6677c478bd9Sstevel@tonic-gate if (name_s == NULL) { 6687c478bd9Sstevel@tonic-gate p_error = parse_item_expected_error; 6697c478bd9Sstevel@tonic-gate return (4); 6707c478bd9Sstevel@tonic-gate } 6717c478bd9Sstevel@tonic-gate if (token != string_token) { 6727c478bd9Sstevel@tonic-gate p_error = parse_item_expected_error; 6737c478bd9Sstevel@tonic-gate return (5); 6747c478bd9Sstevel@tonic-gate } 6757c478bd9Sstevel@tonic-gate item = (__nis_mapping_item_t *)s_realloc(item, 6767c478bd9Sstevel@tonic-gate (nElements + 1) * 6777c478bd9Sstevel@tonic-gate sizeof (__nis_mapping_item_t)); 6787c478bd9Sstevel@tonic-gate if (item == NULL) { 6797c478bd9Sstevel@tonic-gate p_error = parse_no_mem_error; 6807c478bd9Sstevel@tonic-gate return (2); 6817c478bd9Sstevel@tonic-gate } 6827c478bd9Sstevel@tonic-gate name_s = get_mapping_item(begin_token, name_s_end, 6837c478bd9Sstevel@tonic-gate &item[nElements], item_type); 6847c478bd9Sstevel@tonic-gate if (name_s == NULL) { 6857c478bd9Sstevel@tonic-gate p_error = parse_unmatched_escape; 6867c478bd9Sstevel@tonic-gate for (n = 0; n < (nElements + 1); n++) 6877c478bd9Sstevel@tonic-gate free_mapping_item(&item[n]); 6887c478bd9Sstevel@tonic-gate free_mapping_format(base); 6897c478bd9Sstevel@tonic-gate return (4); 6907c478bd9Sstevel@tonic-gate } 6917c478bd9Sstevel@tonic-gate nElements++; 6927c478bd9Sstevel@tonic-gate } 6937c478bd9Sstevel@tonic-gate if (p_error != no_parse_error) { 6947c478bd9Sstevel@tonic-gate for (n = 0; n < (nElements + 1); n++) 6957c478bd9Sstevel@tonic-gate free_mapping_item(&item[n]); 6967c478bd9Sstevel@tonic-gate free_mapping_format(base); 6977c478bd9Sstevel@tonic-gate return (6); 6987c478bd9Sstevel@tonic-gate } 6997c478bd9Sstevel@tonic-gate name_s = skip_token(name_s, name_s_end, close_paren_token); 7007c478bd9Sstevel@tonic-gate if (name_s == NULL) { 7017c478bd9Sstevel@tonic-gate p_error = parse_close_paren_expected_error; 7027c478bd9Sstevel@tonic-gate for (n = 0; n < (nElements + 1); n++) 7037c478bd9Sstevel@tonic-gate free_mapping_item(&item[n]); 7047c478bd9Sstevel@tonic-gate free_mapping_format(base); 7057c478bd9Sstevel@tonic-gate return (4); 7067c478bd9Sstevel@tonic-gate } 7077c478bd9Sstevel@tonic-gate while (name_s < name_s_end && is_whitespace(*name_s)) 7087c478bd9Sstevel@tonic-gate name_s++; 7097c478bd9Sstevel@tonic-gate if (*name_s == COMMA_CHAR) 7107c478bd9Sstevel@tonic-gate parse_next_line++; 7117c478bd9Sstevel@tonic-gate 7127c478bd9Sstevel@tonic-gate if (nElements == 0) { 7137c478bd9Sstevel@tonic-gate p_error = parse_no_match_item; 7147c478bd9Sstevel@tonic-gate for (n = 0; n < (nElements + 1); n++) 7157c478bd9Sstevel@tonic-gate free_mapping_item(&item[n]); 7167c478bd9Sstevel@tonic-gate free_mapping_format(base); 7177c478bd9Sstevel@tonic-gate return (7); 7187c478bd9Sstevel@tonic-gate } 7197c478bd9Sstevel@tonic-gate elmnt = (__nis_mapping_element_t *)s_realloc(elmnt, 7207c478bd9Sstevel@tonic-gate (numSplits + 1) * 7217c478bd9Sstevel@tonic-gate sizeof (__nis_mapping_element_t)); 7227c478bd9Sstevel@tonic-gate if (elmnt == NULL) { 7237c478bd9Sstevel@tonic-gate for (n = 0; n < (nElements + 1); n++) 7247c478bd9Sstevel@tonic-gate free_mapping_item(&item[n]); 7257c478bd9Sstevel@tonic-gate free_mapping_format(base); 7267c478bd9Sstevel@tonic-gate p_error = parse_no_mem_error; 7277c478bd9Sstevel@tonic-gate return (2); 7287c478bd9Sstevel@tonic-gate } 7297c478bd9Sstevel@tonic-gate elmnt[numSplits].type = me_match; 7307c478bd9Sstevel@tonic-gate elmnt[numSplits].element.match.numItems = nElements; 7317c478bd9Sstevel@tonic-gate elmnt[numSplits].element.match.item = item; 7327c478bd9Sstevel@tonic-gate elmnt[numSplits].element.match.fmt = base; 7337c478bd9Sstevel@tonic-gate item = NULL; 7347c478bd9Sstevel@tonic-gate base = NULL; 7357c478bd9Sstevel@tonic-gate 7367c478bd9Sstevel@tonic-gate t_map->e = elmnt; 7377c478bd9Sstevel@tonic-gate t_map->numSplits = numSplits; 7387c478bd9Sstevel@tonic-gate n = t_map->numColumns; 7397c478bd9Sstevel@tonic-gate 7407c478bd9Sstevel@tonic-gate for (i = n, itm_count = 0; i < n + nElements; i++) { 7417c478bd9Sstevel@tonic-gate if (t_map->e[numSplits].element. 7427c478bd9Sstevel@tonic-gate match.item[itm_count].name) { 7437c478bd9Sstevel@tonic-gate if (!add_column(t_map, 7447c478bd9Sstevel@tonic-gate t_map->e[numSplits].element. 7457c478bd9Sstevel@tonic-gate match.item[itm_count].name)) 7467c478bd9Sstevel@tonic-gate return (1); 7477c478bd9Sstevel@tonic-gate itm_count++; 7487c478bd9Sstevel@tonic-gate } else { 7497c478bd9Sstevel@tonic-gate p_error = parse_internal_error; 7507c478bd9Sstevel@tonic-gate for (n = 0; n < (nElements + 1); n++) 7517c478bd9Sstevel@tonic-gate free_mapping_item(&item[n]); 7527c478bd9Sstevel@tonic-gate free_mapping_format(base); 7537c478bd9Sstevel@tonic-gate free_mapping_element(elmnt); 7547c478bd9Sstevel@tonic-gate return (1); 7557c478bd9Sstevel@tonic-gate } 7567c478bd9Sstevel@tonic-gate } 7577c478bd9Sstevel@tonic-gate numSplits++; 7587c478bd9Sstevel@tonic-gate } 7597c478bd9Sstevel@tonic-gate elmnt = NULL; 7607c478bd9Sstevel@tonic-gate 7617c478bd9Sstevel@tonic-gate if (item != NULL) { 7627c478bd9Sstevel@tonic-gate for (n = 0; n < t_map->numColumns; n++) { 7637c478bd9Sstevel@tonic-gate free_mapping_item(&item[n]); 7647c478bd9Sstevel@tonic-gate } 7657c478bd9Sstevel@tonic-gate free(item); 7667c478bd9Sstevel@tonic-gate } 7677c478bd9Sstevel@tonic-gate if (elmnt != NULL) 7687c478bd9Sstevel@tonic-gate free_mapping_element(elmnt); 7697c478bd9Sstevel@tonic-gate if (base != NULL) 7707c478bd9Sstevel@tonic-gate free_mapping_format(base); 7717c478bd9Sstevel@tonic-gate 7727c478bd9Sstevel@tonic-gate return (p_error == no_parse_error ? 0 : -1); 7737c478bd9Sstevel@tonic-gate } 7747c478bd9Sstevel@tonic-gate 7757c478bd9Sstevel@tonic-gate /* 7767c478bd9Sstevel@tonic-gate * FUNCTION: parse_object_dn 7777c478bd9Sstevel@tonic-gate * 7787c478bd9Sstevel@tonic-gate * Parse object dn attribute 7797c478bd9Sstevel@tonic-gate * 7807c478bd9Sstevel@tonic-gate * RETURN VALUE: __nis_object_dn_t on success 7817c478bd9Sstevel@tonic-gate * NULL on failure 7827c478bd9Sstevel@tonic-gate * 7837c478bd9Sstevel@tonic-gate * INPUT: the attribute value 7847c478bd9Sstevel@tonic-gate */ 7857c478bd9Sstevel@tonic-gate 7867c478bd9Sstevel@tonic-gate static __nis_object_dn_t * 7877c478bd9Sstevel@tonic-gate parse_object_dn(const char *s, const char *end) 7887c478bd9Sstevel@tonic-gate { 7897c478bd9Sstevel@tonic-gate const char *s_begin; 7907c478bd9Sstevel@tonic-gate const char *s_end; 7917c478bd9Sstevel@tonic-gate object_dn_token token; 7927c478bd9Sstevel@tonic-gate parse_object_dn_state dn_state = dn_begin_parse; 7937c478bd9Sstevel@tonic-gate __nis_object_dn_t *obj_dn = NULL; 7947c478bd9Sstevel@tonic-gate __nis_object_dn_t *next = NULL; 7957c478bd9Sstevel@tonic-gate __nis_object_dn_t *last = NULL; 7967c478bd9Sstevel@tonic-gate 7977c478bd9Sstevel@tonic-gate /* 7987c478bd9Sstevel@tonic-gate * The attribute should be of form 7997c478bd9Sstevel@tonic-gate * objectDN *( ";" objectDN ) 8007c478bd9Sstevel@tonic-gate * objectDN = readObjectSpec [":"[writeObjectSpec]] 8017c478bd9Sstevel@tonic-gate * readObjectSpec = [baseAndScope [filterAttrValList]] 8027c478bd9Sstevel@tonic-gate * writeObjectSpec = [baseAndScope [attrValList [":" deleteDisp]]] 8037c478bd9Sstevel@tonic-gate */ 8047c478bd9Sstevel@tonic-gate 8057c478bd9Sstevel@tonic-gate while (s < end) { 8067c478bd9Sstevel@tonic-gate s_begin = s; 8077c478bd9Sstevel@tonic-gate s_end = end; 8087c478bd9Sstevel@tonic-gate s = get_next_object_dn_token(&s_begin, &s_end, &token); 8097c478bd9Sstevel@tonic-gate if (s == NULL) 8107c478bd9Sstevel@tonic-gate break; 8117c478bd9Sstevel@tonic-gate 8127c478bd9Sstevel@tonic-gate if (token == dn_no_token || token == dn_semi_token) { 8137c478bd9Sstevel@tonic-gate if (obj_dn == NULL) 8147c478bd9Sstevel@tonic-gate obj_dn = next; 8157c478bd9Sstevel@tonic-gate else 8167c478bd9Sstevel@tonic-gate last->next = next; 8177c478bd9Sstevel@tonic-gate last = next; 8187c478bd9Sstevel@tonic-gate next = NULL; 8197c478bd9Sstevel@tonic-gate if (token == dn_no_token) 8207c478bd9Sstevel@tonic-gate break; 8217c478bd9Sstevel@tonic-gate dn_state = dn_begin_parse; 8227c478bd9Sstevel@tonic-gate } 8237c478bd9Sstevel@tonic-gate if (next == NULL) { 8247c478bd9Sstevel@tonic-gate next = (__nis_object_dn_t *) 8257c478bd9Sstevel@tonic-gate s_calloc(1, sizeof (__nis_object_dn_t)); 8267c478bd9Sstevel@tonic-gate if (next == NULL) 8277c478bd9Sstevel@tonic-gate break; 8287c478bd9Sstevel@tonic-gate next->read.scope = LDAP_SCOPE_ONELEVEL; 8297c478bd9Sstevel@tonic-gate next->write.scope = LDAP_SCOPE_UNKNOWN; 8307c478bd9Sstevel@tonic-gate next->delDisp = dd_always; 8317c478bd9Sstevel@tonic-gate } 8327c478bd9Sstevel@tonic-gate if (token == dn_semi_token) 8337c478bd9Sstevel@tonic-gate continue; 8347c478bd9Sstevel@tonic-gate 8357c478bd9Sstevel@tonic-gate switch (dn_state) { 8367c478bd9Sstevel@tonic-gate case dn_begin_parse: 8377c478bd9Sstevel@tonic-gate if (token == dn_ques_token) 8387c478bd9Sstevel@tonic-gate dn_state = dn_got_read_q_scope; 8397c478bd9Sstevel@tonic-gate else if (token == dn_colon_token) { 8407c478bd9Sstevel@tonic-gate dn_state = dn_got_write_colon; 8417c478bd9Sstevel@tonic-gate next->write.scope = LDAP_SCOPE_ONELEVEL; 8427c478bd9Sstevel@tonic-gate } else { 8437c478bd9Sstevel@tonic-gate if (!validate_dn(s_begin, s_end - s_begin)) 8447c478bd9Sstevel@tonic-gate break; 8457c478bd9Sstevel@tonic-gate next->read.base = 8467c478bd9Sstevel@tonic-gate s_strndup_esc(s_begin, s_end - s_begin); 8477c478bd9Sstevel@tonic-gate dn_state = dn_got_read_dn; 8487c478bd9Sstevel@tonic-gate } 8497c478bd9Sstevel@tonic-gate break; 8507c478bd9Sstevel@tonic-gate case dn_got_read_dn: 8517c478bd9Sstevel@tonic-gate if (token == dn_ques_token) 8527c478bd9Sstevel@tonic-gate dn_state = dn_got_read_q_scope; 8537c478bd9Sstevel@tonic-gate else if (token == dn_colon_token) { 8547c478bd9Sstevel@tonic-gate dn_state = dn_got_write_colon; 8557c478bd9Sstevel@tonic-gate next->write.scope = LDAP_SCOPE_ONELEVEL; 8567c478bd9Sstevel@tonic-gate } else 8577c478bd9Sstevel@tonic-gate p_error = parse_object_dn_syntax_error; 8587c478bd9Sstevel@tonic-gate break; 8597c478bd9Sstevel@tonic-gate case dn_got_read_q_scope: 8607c478bd9Sstevel@tonic-gate if (token == dn_ques_token) 8617c478bd9Sstevel@tonic-gate dn_state = dn_got_read_q_filter; 8627c478bd9Sstevel@tonic-gate else if (token == dn_colon_token) { 8637c478bd9Sstevel@tonic-gate dn_state = dn_got_write_colon; 8647c478bd9Sstevel@tonic-gate next->write.scope = LDAP_SCOPE_ONELEVEL; 8657c478bd9Sstevel@tonic-gate } else if (token == dn_base_token) { 8667c478bd9Sstevel@tonic-gate next->read.scope = LDAP_SCOPE_BASE; 8677c478bd9Sstevel@tonic-gate dn_state = dn_got_read_scope; 8687c478bd9Sstevel@tonic-gate } else if (token == dn_one_token) { 8697c478bd9Sstevel@tonic-gate next->read.scope = LDAP_SCOPE_ONELEVEL; 8707c478bd9Sstevel@tonic-gate dn_state = dn_got_read_scope; 8717c478bd9Sstevel@tonic-gate } else if (token == dn_sub_token) { 8727c478bd9Sstevel@tonic-gate next->read.scope = LDAP_SCOPE_SUBTREE; 8737c478bd9Sstevel@tonic-gate dn_state = dn_got_read_scope; 8747c478bd9Sstevel@tonic-gate } else { 8757c478bd9Sstevel@tonic-gate p_error = parse_invalid_scope; 8767c478bd9Sstevel@tonic-gate } 8777c478bd9Sstevel@tonic-gate break; 8787c478bd9Sstevel@tonic-gate case dn_got_read_scope: 8797c478bd9Sstevel@tonic-gate if (token == dn_ques_token) 8807c478bd9Sstevel@tonic-gate dn_state = dn_got_read_q_filter; 8817c478bd9Sstevel@tonic-gate else if (token == dn_colon_token) { 8827c478bd9Sstevel@tonic-gate dn_state = dn_got_write_colon; 8837c478bd9Sstevel@tonic-gate next->write.scope = LDAP_SCOPE_ONELEVEL; 8847c478bd9Sstevel@tonic-gate } else 8857c478bd9Sstevel@tonic-gate p_error = parse_object_dn_syntax_error; 8867c478bd9Sstevel@tonic-gate break; 8877c478bd9Sstevel@tonic-gate case dn_got_read_q_filter: 8887c478bd9Sstevel@tonic-gate if (token == dn_ques_token) { 8897c478bd9Sstevel@tonic-gate p_error = parse_object_dn_syntax_error; 8907c478bd9Sstevel@tonic-gate } else if (token == dn_colon_token) { 8917c478bd9Sstevel@tonic-gate dn_state = dn_got_write_colon; 8927c478bd9Sstevel@tonic-gate next->write.scope = LDAP_SCOPE_ONELEVEL; 8937c478bd9Sstevel@tonic-gate } else { 8947c478bd9Sstevel@tonic-gate if (!validate_ldap_filter(s_begin, s_end)) 8957c478bd9Sstevel@tonic-gate break; 8967c478bd9Sstevel@tonic-gate next->read.attrs = 8977c478bd9Sstevel@tonic-gate s_strndup_esc(s_begin, s_end - s_begin); 8987c478bd9Sstevel@tonic-gate dn_state = dn_got_read_filter; 8997c478bd9Sstevel@tonic-gate } 9007c478bd9Sstevel@tonic-gate break; 9017c478bd9Sstevel@tonic-gate case dn_got_read_filter: 9027c478bd9Sstevel@tonic-gate if (token == dn_ques_token) { 9037c478bd9Sstevel@tonic-gate p_error = parse_object_dn_syntax_error; 9047c478bd9Sstevel@tonic-gate } else if (token == dn_colon_token) { 9057c478bd9Sstevel@tonic-gate dn_state = dn_got_write_colon; 9067c478bd9Sstevel@tonic-gate next->write.scope = LDAP_SCOPE_ONELEVEL; 9077c478bd9Sstevel@tonic-gate } else 9087c478bd9Sstevel@tonic-gate p_error = parse_object_dn_syntax_error; 9097c478bd9Sstevel@tonic-gate break; 9107c478bd9Sstevel@tonic-gate case dn_got_write_colon: 9117c478bd9Sstevel@tonic-gate if (token == dn_ques_token) 9127c478bd9Sstevel@tonic-gate dn_state = dn_got_write_q_scope; 9137c478bd9Sstevel@tonic-gate else if (token == dn_colon_token) { 9147c478bd9Sstevel@tonic-gate dn_state = dn_got_delete_colon; 9157c478bd9Sstevel@tonic-gate } else { 9167c478bd9Sstevel@tonic-gate if (!validate_dn(s_begin, s_end - s_begin)) 9177c478bd9Sstevel@tonic-gate break; 9187c478bd9Sstevel@tonic-gate next->write.base = 9197c478bd9Sstevel@tonic-gate s_strndup_esc(s_begin, s_end - s_begin); 9207c478bd9Sstevel@tonic-gate dn_state = dn_got_write_dn; 9217c478bd9Sstevel@tonic-gate } 9227c478bd9Sstevel@tonic-gate break; 9237c478bd9Sstevel@tonic-gate case dn_got_write_dn: 9247c478bd9Sstevel@tonic-gate if (token == dn_ques_token) 9257c478bd9Sstevel@tonic-gate dn_state = dn_got_write_q_scope; 9267c478bd9Sstevel@tonic-gate else if (token == dn_colon_token) { 9277c478bd9Sstevel@tonic-gate dn_state = dn_got_delete_colon; 9287c478bd9Sstevel@tonic-gate } else 9297c478bd9Sstevel@tonic-gate p_error = parse_object_dn_syntax_error; 9307c478bd9Sstevel@tonic-gate break; 9317c478bd9Sstevel@tonic-gate case dn_got_write_q_scope: 9327c478bd9Sstevel@tonic-gate if (token == dn_ques_token) 9337c478bd9Sstevel@tonic-gate dn_state = dn_got_write_q_filter; 9347c478bd9Sstevel@tonic-gate else if (token == dn_colon_token) { 9357c478bd9Sstevel@tonic-gate dn_state = dn_got_delete_colon; 9367c478bd9Sstevel@tonic-gate } else if (token == dn_base_token) { 9377c478bd9Sstevel@tonic-gate next->write.scope = LDAP_SCOPE_BASE; 9387c478bd9Sstevel@tonic-gate dn_state = dn_got_write_scope; 9397c478bd9Sstevel@tonic-gate } else if (token == dn_one_token) { 9407c478bd9Sstevel@tonic-gate next->write.scope = LDAP_SCOPE_ONELEVEL; 9417c478bd9Sstevel@tonic-gate dn_state = dn_got_write_scope; 9427c478bd9Sstevel@tonic-gate } else if (token == dn_sub_token) { 9437c478bd9Sstevel@tonic-gate next->write.scope = LDAP_SCOPE_SUBTREE; 9447c478bd9Sstevel@tonic-gate dn_state = dn_got_write_scope; 9457c478bd9Sstevel@tonic-gate } else { 9467c478bd9Sstevel@tonic-gate p_error = parse_invalid_scope; 9477c478bd9Sstevel@tonic-gate } 9487c478bd9Sstevel@tonic-gate break; 9497c478bd9Sstevel@tonic-gate case dn_got_write_scope: 9507c478bd9Sstevel@tonic-gate if (token == dn_ques_token) 9517c478bd9Sstevel@tonic-gate dn_state = dn_got_write_q_filter; 9527c478bd9Sstevel@tonic-gate else if (token == dn_colon_token) { 9537c478bd9Sstevel@tonic-gate dn_state = dn_got_delete_colon; 9547c478bd9Sstevel@tonic-gate } else 9557c478bd9Sstevel@tonic-gate p_error = parse_object_dn_syntax_error; 9567c478bd9Sstevel@tonic-gate break; 9577c478bd9Sstevel@tonic-gate case dn_got_write_q_filter: 9587c478bd9Sstevel@tonic-gate if (token == dn_ques_token) { 9597c478bd9Sstevel@tonic-gate p_error = parse_object_dn_syntax_error; 9607c478bd9Sstevel@tonic-gate } else if (token == dn_colon_token) { 9617c478bd9Sstevel@tonic-gate dn_state = dn_got_delete_colon; 9627c478bd9Sstevel@tonic-gate } else { 9637c478bd9Sstevel@tonic-gate if (!validate_ldap_filter(s_begin, s_end)) 9647c478bd9Sstevel@tonic-gate break; 9657c478bd9Sstevel@tonic-gate next->write.attrs = 9667c478bd9Sstevel@tonic-gate s_strndup_esc(s_begin, s_end - s_begin); 9677c478bd9Sstevel@tonic-gate dn_state = dn_got_write_filter; 9687c478bd9Sstevel@tonic-gate } 9697c478bd9Sstevel@tonic-gate break; 9707c478bd9Sstevel@tonic-gate case dn_got_write_filter: 9717c478bd9Sstevel@tonic-gate if (token == dn_ques_token) { 9727c478bd9Sstevel@tonic-gate p_error = parse_object_dn_syntax_error; 9737c478bd9Sstevel@tonic-gate } else if (token == dn_colon_token) { 9747c478bd9Sstevel@tonic-gate dn_state = dn_got_delete_colon; 9757c478bd9Sstevel@tonic-gate 9767c478bd9Sstevel@tonic-gate } else 9777c478bd9Sstevel@tonic-gate p_error = parse_semi_expected_error; 9787c478bd9Sstevel@tonic-gate break; 9797c478bd9Sstevel@tonic-gate case dn_got_delete_colon: 9807c478bd9Sstevel@tonic-gate if (token == dn_ques_token) { 9817c478bd9Sstevel@tonic-gate p_error = parse_object_dn_syntax_error; 9827c478bd9Sstevel@tonic-gate } else if (token == dn_colon_token) { 9837c478bd9Sstevel@tonic-gate p_error = parse_object_dn_syntax_error; 9847c478bd9Sstevel@tonic-gate } else { 9857c478bd9Sstevel@tonic-gate if (!get_deleteDisp(s_begin, s_end, next)) 9867c478bd9Sstevel@tonic-gate break; 9877c478bd9Sstevel@tonic-gate dn_state = dn_got_delete_dsp; 9887c478bd9Sstevel@tonic-gate } 9897c478bd9Sstevel@tonic-gate break; 9907c478bd9Sstevel@tonic-gate case dn_got_delete_dsp: 9917c478bd9Sstevel@tonic-gate p_error = parse_object_dn_syntax_error; 9927c478bd9Sstevel@tonic-gate break; 9937c478bd9Sstevel@tonic-gate } 9947c478bd9Sstevel@tonic-gate 9957c478bd9Sstevel@tonic-gate if (p_error != no_parse_error) 9967c478bd9Sstevel@tonic-gate break; 9977c478bd9Sstevel@tonic-gate } 9987c478bd9Sstevel@tonic-gate if (p_error != no_parse_error) { 9997c478bd9Sstevel@tonic-gate if (obj_dn != NULL) 10007c478bd9Sstevel@tonic-gate free_object_dn(obj_dn); 10017c478bd9Sstevel@tonic-gate if (next != NULL) 10027c478bd9Sstevel@tonic-gate free_object_dn(next); 10037c478bd9Sstevel@tonic-gate obj_dn = NULL; 10047c478bd9Sstevel@tonic-gate } else if (next != NULL) { 10057c478bd9Sstevel@tonic-gate if (obj_dn == NULL) 10067c478bd9Sstevel@tonic-gate obj_dn = next; 10077c478bd9Sstevel@tonic-gate else 10087c478bd9Sstevel@tonic-gate last->next = next; 10097c478bd9Sstevel@tonic-gate } else if (obj_dn == NULL) 10107c478bd9Sstevel@tonic-gate obj_dn = (__nis_object_dn_t *) 10117c478bd9Sstevel@tonic-gate s_calloc(1, sizeof (__nis_object_dn_t)); 10127c478bd9Sstevel@tonic-gate 10137c478bd9Sstevel@tonic-gate return (obj_dn); 10147c478bd9Sstevel@tonic-gate } 10157c478bd9Sstevel@tonic-gate 10167c478bd9Sstevel@tonic-gate /* 10177c478bd9Sstevel@tonic-gate * FUNCTION: get_mapping_rule 10187c478bd9Sstevel@tonic-gate * 10197c478bd9Sstevel@tonic-gate * Parse mapping rule attributes 10207c478bd9Sstevel@tonic-gate * 10217c478bd9Sstevel@tonic-gate * RETURN VALUE: None. Errors determined by p_error 10227c478bd9Sstevel@tonic-gate * 10237c478bd9Sstevel@tonic-gate * INPUT: the attribute value and mapping rule type 10247c478bd9Sstevel@tonic-gate */ 10257c478bd9Sstevel@tonic-gate 10267c478bd9Sstevel@tonic-gate static void 10277c478bd9Sstevel@tonic-gate get_mapping_rule( 10287c478bd9Sstevel@tonic-gate const char *s, 10297c478bd9Sstevel@tonic-gate int len, 10307c478bd9Sstevel@tonic-gate __nis_table_mapping_t *tbl, 10317c478bd9Sstevel@tonic-gate bool_t to_ldap) 10327c478bd9Sstevel@tonic-gate { 10337c478bd9Sstevel@tonic-gate const char *end_s = s + len; 10347c478bd9Sstevel@tonic-gate const char *begin_token; 10357c478bd9Sstevel@tonic-gate const char *end_token; 10367c478bd9Sstevel@tonic-gate __nis_mapping_rule_t **rule = NULL; 10377c478bd9Sstevel@tonic-gate __nis_mapping_rule_t *next = NULL; 10387c478bd9Sstevel@tonic-gate /* __nis_mapping_rule_t **r; */ 10397c478bd9Sstevel@tonic-gate token_type t; 10407c478bd9Sstevel@tonic-gate int nRules = 0; 10417c478bd9Sstevel@tonic-gate const char *s1; 10427c478bd9Sstevel@tonic-gate int i; 10437c478bd9Sstevel@tonic-gate 10447c478bd9Sstevel@tonic-gate /* 10457c478bd9Sstevel@tonic-gate * The attribute value is of the form 10467c478bd9Sstevel@tonic-gate * colattrspec *("," colattrspec) 10477c478bd9Sstevel@tonic-gate * colattrspec = lhs "=" rhs 10487c478bd9Sstevel@tonic-gate * lhs = lval | namespeclist 10497c478bd9Sstevel@tonic-gate * rhs = rval | [namespec] 10507c478bd9Sstevel@tonic-gate */ 10517c478bd9Sstevel@tonic-gate 10527c478bd9Sstevel@tonic-gate for (;;) { 10537c478bd9Sstevel@tonic-gate if ((next = (__nis_mapping_rule_t *) 10547c478bd9Sstevel@tonic-gate s_calloc(1, sizeof (__nis_mapping_rule_t))) == NULL) 10557c478bd9Sstevel@tonic-gate break; 10567c478bd9Sstevel@tonic-gate 10577c478bd9Sstevel@tonic-gate s = get_lhs(s, end_s, &next->lhs, 10587c478bd9Sstevel@tonic-gate to_ldap ? mit_ldap : mit_nisplus); 10597c478bd9Sstevel@tonic-gate if (s == NULL) 10607c478bd9Sstevel@tonic-gate break; 10617c478bd9Sstevel@tonic-gate 10627c478bd9Sstevel@tonic-gate begin_token = s; 10637c478bd9Sstevel@tonic-gate end_token = end_s; 10647c478bd9Sstevel@tonic-gate s1 = get_next_token(&begin_token, &end_token, &t); 10657c478bd9Sstevel@tonic-gate if (s1 == NULL) 10667c478bd9Sstevel@tonic-gate break; 10677c478bd9Sstevel@tonic-gate if (!(to_ldap && (t == comma_token || t == no_token))) { 10687c478bd9Sstevel@tonic-gate s = get_rhs(s, end_s, &next->rhs, 10697c478bd9Sstevel@tonic-gate to_ldap ? mit_nisplus : mit_ldap); 10707c478bd9Sstevel@tonic-gate if (s == NULL) 10717c478bd9Sstevel@tonic-gate break; 10727c478bd9Sstevel@tonic-gate } 10737c478bd9Sstevel@tonic-gate 10747c478bd9Sstevel@tonic-gate if (next->lhs.numElements > 1 && 10757c478bd9Sstevel@tonic-gate (next->rhs.numElements != 1 || 10767c478bd9Sstevel@tonic-gate next->rhs.element[0].type != me_split)) { 10777c478bd9Sstevel@tonic-gate p_error = parse_lhs_rhs_type_mismatch; 10787c478bd9Sstevel@tonic-gate break; 10797c478bd9Sstevel@tonic-gate } 10807c478bd9Sstevel@tonic-gate if (rule == NULL) { 10817c478bd9Sstevel@tonic-gate rule = (__nis_mapping_rule_t **) 10827c478bd9Sstevel@tonic-gate malloc(sizeof (__nis_mapping_rule_t *)); 10837c478bd9Sstevel@tonic-gate if (rule == NULL) 10847c478bd9Sstevel@tonic-gate break; 10857c478bd9Sstevel@tonic-gate } else { 10867c478bd9Sstevel@tonic-gate rule = (__nis_mapping_rule_t **)s_realloc(rule, 10877c478bd9Sstevel@tonic-gate (nRules + 1) * 10887c478bd9Sstevel@tonic-gate sizeof (__nis_mapping_rule_t *)); 10897c478bd9Sstevel@tonic-gate if (rule == NULL) 10907c478bd9Sstevel@tonic-gate break; 10917c478bd9Sstevel@tonic-gate } 10927c478bd9Sstevel@tonic-gate 10937c478bd9Sstevel@tonic-gate rule[nRules++] = next; 10947c478bd9Sstevel@tonic-gate next = NULL; 10957c478bd9Sstevel@tonic-gate 10967c478bd9Sstevel@tonic-gate begin_token = s; 10977c478bd9Sstevel@tonic-gate end_token = end_s; 10987c478bd9Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t); 10997c478bd9Sstevel@tonic-gate if (s == NULL) 11007c478bd9Sstevel@tonic-gate break; 11017c478bd9Sstevel@tonic-gate if (t == comma_token) 11027c478bd9Sstevel@tonic-gate continue; 11037c478bd9Sstevel@tonic-gate if (t != no_token) { 11047c478bd9Sstevel@tonic-gate p_error = parse_unexpected_data_end_rule; 11057c478bd9Sstevel@tonic-gate break; 11067c478bd9Sstevel@tonic-gate } 11077c478bd9Sstevel@tonic-gate if (to_ldap) { 11087c478bd9Sstevel@tonic-gate tbl->numRulesToLDAP = nRules; 11097c478bd9Sstevel@tonic-gate tbl->ruleToLDAP = rule; 11107c478bd9Sstevel@tonic-gate } else { 11117c478bd9Sstevel@tonic-gate tbl->numRulesFromLDAP = nRules; 11127c478bd9Sstevel@tonic-gate tbl->ruleFromLDAP = rule; 11137c478bd9Sstevel@tonic-gate } 11147c478bd9Sstevel@tonic-gate return; 11157c478bd9Sstevel@tonic-gate } 11167c478bd9Sstevel@tonic-gate 11177c478bd9Sstevel@tonic-gate if (rule) { 11187c478bd9Sstevel@tonic-gate for (i = 0; i < nRules; i++) 11197c478bd9Sstevel@tonic-gate free_mapping_rule(rule[i]); 11207c478bd9Sstevel@tonic-gate free(rule); 11217c478bd9Sstevel@tonic-gate } 11227c478bd9Sstevel@tonic-gate if (next) 11237c478bd9Sstevel@tonic-gate free_mapping_rule(next); 11247c478bd9Sstevel@tonic-gate } 11257c478bd9Sstevel@tonic-gate 11267c478bd9Sstevel@tonic-gate /* 11277c478bd9Sstevel@tonic-gate * FUNCTION: get_lhs 11287c478bd9Sstevel@tonic-gate * 11297c478bd9Sstevel@tonic-gate * Parse left hand side of mapping rule attribute 11307c478bd9Sstevel@tonic-gate * 11317c478bd9Sstevel@tonic-gate * RETURN VALUE: NULL if error 11327c478bd9Sstevel@tonic-gate * position of beginning rhs 11337c478bd9Sstevel@tonic-gate * 11347c478bd9Sstevel@tonic-gate * INPUT: the attribute value and mapping rule type 11357c478bd9Sstevel@tonic-gate */ 11367c478bd9Sstevel@tonic-gate 11377c478bd9Sstevel@tonic-gate static const char * 11387c478bd9Sstevel@tonic-gate get_lhs(const char *s, 11397c478bd9Sstevel@tonic-gate const char *end_s, 11407c478bd9Sstevel@tonic-gate __nis_mapping_rlhs_t *lhs, 11417c478bd9Sstevel@tonic-gate __nis_mapping_item_type_t item_type) 11427c478bd9Sstevel@tonic-gate { 11437c478bd9Sstevel@tonic-gate token_type t; 11447c478bd9Sstevel@tonic-gate const char *begin_token; 11457c478bd9Sstevel@tonic-gate const char *end_token; 11467c478bd9Sstevel@tonic-gate const char *sav_s; 11477c478bd9Sstevel@tonic-gate __nis_mapping_element_t *e = NULL; 11487c478bd9Sstevel@tonic-gate 11497c478bd9Sstevel@tonic-gate /* 11507c478bd9Sstevel@tonic-gate * lhs can be expressed as: 11517c478bd9Sstevel@tonic-gate * item 11527c478bd9Sstevel@tonic-gate * (item) 11537c478bd9Sstevel@tonic-gate * (item list) 11547c478bd9Sstevel@tonic-gate * (fmt, item list) 11557c478bd9Sstevel@tonic-gate * 11567c478bd9Sstevel@tonic-gate * lhs = lval | namespeclist 11577c478bd9Sstevel@tonic-gate * lval = "(" formatspec "," namespec *("," namespec) ")" 11587c478bd9Sstevel@tonic-gate * namespeclist = namespec | "(" namespec *("," namespec) ")" 11597c478bd9Sstevel@tonic-gate */ 11607c478bd9Sstevel@tonic-gate 11617c478bd9Sstevel@tonic-gate for (; p_error == no_parse_error; ) { 11627c478bd9Sstevel@tonic-gate begin_token = s; 11637c478bd9Sstevel@tonic-gate end_token = end_s; 11647c478bd9Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t); 11657c478bd9Sstevel@tonic-gate if (s == NULL) 11667c478bd9Sstevel@tonic-gate break; 11677c478bd9Sstevel@tonic-gate if (t == no_token) { 11687c478bd9Sstevel@tonic-gate p_error = parse_unexpected_data_end_rule; 11697c478bd9Sstevel@tonic-gate break; 11707c478bd9Sstevel@tonic-gate } 11717c478bd9Sstevel@tonic-gate 11727c478bd9Sstevel@tonic-gate e = (__nis_mapping_element_t *) 11737c478bd9Sstevel@tonic-gate s_calloc(1, sizeof (__nis_mapping_element_t)); 11747c478bd9Sstevel@tonic-gate if (e == NULL) 11757c478bd9Sstevel@tonic-gate break; 11767c478bd9Sstevel@tonic-gate 11777c478bd9Sstevel@tonic-gate if (t == open_paren_token) { 11787c478bd9Sstevel@tonic-gate free(e); 11797c478bd9Sstevel@tonic-gate e = NULL; 11807c478bd9Sstevel@tonic-gate 11817c478bd9Sstevel@tonic-gate begin_token = s; 11827c478bd9Sstevel@tonic-gate end_token = end_s; 11837c478bd9Sstevel@tonic-gate sav_s = s; 11847c478bd9Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t); 11857c478bd9Sstevel@tonic-gate if (s == NULL) 11867c478bd9Sstevel@tonic-gate break; 11877c478bd9Sstevel@tonic-gate 11887c478bd9Sstevel@tonic-gate if (t == quoted_string_token) { 11897c478bd9Sstevel@tonic-gate s = get_lhs_match(sav_s, end_s, lhs, item_type); 11907c478bd9Sstevel@tonic-gate if (s == NULL) 11917c478bd9Sstevel@tonic-gate break; 11927c478bd9Sstevel@tonic-gate } else if (t == string_token) { 11937c478bd9Sstevel@tonic-gate s = get_lhs_paren_item(sav_s, end_s, lhs, 11947c478bd9Sstevel@tonic-gate item_type); 11957c478bd9Sstevel@tonic-gate if (s == NULL) 11967c478bd9Sstevel@tonic-gate break; 11977c478bd9Sstevel@tonic-gate } else { 11987c478bd9Sstevel@tonic-gate p_error = parse_bad_lhs_format_error; 11997c478bd9Sstevel@tonic-gate break; 12007c478bd9Sstevel@tonic-gate } 12017c478bd9Sstevel@tonic-gate } else if (t == string_token) { 12027c478bd9Sstevel@tonic-gate s = get_mapping_item(begin_token, end_s, 12037c478bd9Sstevel@tonic-gate &e->element.item, item_type); 12047c478bd9Sstevel@tonic-gate if (s == NULL) 12057c478bd9Sstevel@tonic-gate break; 12067c478bd9Sstevel@tonic-gate e->type = me_item; 12077c478bd9Sstevel@tonic-gate if (!add_element(e, lhs)) 12087c478bd9Sstevel@tonic-gate break; 12097c478bd9Sstevel@tonic-gate e = NULL; 12107c478bd9Sstevel@tonic-gate } else { 12117c478bd9Sstevel@tonic-gate p_error = parse_bad_lhs_format_error; 12127c478bd9Sstevel@tonic-gate break; 12137c478bd9Sstevel@tonic-gate } 12147c478bd9Sstevel@tonic-gate 12157c478bd9Sstevel@tonic-gate s = skip_token(s, end_s, equal_token); 12167c478bd9Sstevel@tonic-gate if (s == NULL) 12177c478bd9Sstevel@tonic-gate break; 12187c478bd9Sstevel@tonic-gate if (p_error == no_parse_error) 12197c478bd9Sstevel@tonic-gate return (s); 12207c478bd9Sstevel@tonic-gate } 12217c478bd9Sstevel@tonic-gate if (e != NULL) 12227c478bd9Sstevel@tonic-gate free_mapping_element(e); 12237c478bd9Sstevel@tonic-gate 12247c478bd9Sstevel@tonic-gate return (NULL); 12257c478bd9Sstevel@tonic-gate } 12267c478bd9Sstevel@tonic-gate 12277c478bd9Sstevel@tonic-gate /* 12287c478bd9Sstevel@tonic-gate * FUNCTION: get_lhs_match 12297c478bd9Sstevel@tonic-gate * 12307c478bd9Sstevel@tonic-gate * Parse left hand side of mapping rule attribute in case of 12317c478bd9Sstevel@tonic-gate * matching rule 12327c478bd9Sstevel@tonic-gate * 12337c478bd9Sstevel@tonic-gate * RETURN VALUE: NULL if error 12347c478bd9Sstevel@tonic-gate * position of beginning rhs 12357c478bd9Sstevel@tonic-gate * 12367c478bd9Sstevel@tonic-gate * INPUT: the attribute value and mapping rule type 12377c478bd9Sstevel@tonic-gate */ 12387c478bd9Sstevel@tonic-gate 12397c478bd9Sstevel@tonic-gate static const char * 12407c478bd9Sstevel@tonic-gate get_lhs_match( 12417c478bd9Sstevel@tonic-gate const char *s, 12427c478bd9Sstevel@tonic-gate const char *end_s, 12437c478bd9Sstevel@tonic-gate __nis_mapping_rlhs_t *lhs, 12447c478bd9Sstevel@tonic-gate __nis_mapping_item_type_t item_type) 12457c478bd9Sstevel@tonic-gate { 12467c478bd9Sstevel@tonic-gate token_type t; 12477c478bd9Sstevel@tonic-gate const char *begin_token; 12487c478bd9Sstevel@tonic-gate const char *end_token; 12497c478bd9Sstevel@tonic-gate int n = 0; 12507c478bd9Sstevel@tonic-gate int nElements = 0; 12517c478bd9Sstevel@tonic-gate char *fmt_string = NULL; 12527c478bd9Sstevel@tonic-gate __nis_mapping_format_t *base = NULL; 12537c478bd9Sstevel@tonic-gate __nis_mapping_item_t *item = NULL; 12547c478bd9Sstevel@tonic-gate __nis_mapping_item_t *itm; 12557c478bd9Sstevel@tonic-gate __nis_mapping_element_t *e; 12567c478bd9Sstevel@tonic-gate 12577c478bd9Sstevel@tonic-gate /* 12587c478bd9Sstevel@tonic-gate * lval = "(" formatspec "," namespec *("," namespec) ")" 12597c478bd9Sstevel@tonic-gate */ 12607c478bd9Sstevel@tonic-gate 12617c478bd9Sstevel@tonic-gate for (; p_error == no_parse_error; ) { 12627c478bd9Sstevel@tonic-gate begin_token = s; 12637c478bd9Sstevel@tonic-gate end_token = end_s; 12647c478bd9Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t); 12657c478bd9Sstevel@tonic-gate if (s == NULL || t != quoted_string_token) { 12667c478bd9Sstevel@tonic-gate p_error = parse_internal_error; 12677c478bd9Sstevel@tonic-gate break; 12687c478bd9Sstevel@tonic-gate } 12697c478bd9Sstevel@tonic-gate 12707c478bd9Sstevel@tonic-gate 12717c478bd9Sstevel@tonic-gate fmt_string = s_strndup(begin_token, end_token - begin_token); 12727c478bd9Sstevel@tonic-gate if (fmt_string == NULL) 12737c478bd9Sstevel@tonic-gate break; 12747c478bd9Sstevel@tonic-gate 12757c478bd9Sstevel@tonic-gate if (!get_mapping_format(fmt_string, &base, &n, NULL, FALSE)) 12767c478bd9Sstevel@tonic-gate break; 12777c478bd9Sstevel@tonic-gate 12787c478bd9Sstevel@tonic-gate for (n = 0; base[n].type != mmt_end; n++) { 12797c478bd9Sstevel@tonic-gate if (base[n].type != mmt_item && 12807c478bd9Sstevel@tonic-gate base[n].type != mmt_berstring) { 12817c478bd9Sstevel@tonic-gate if (base[n].type == mmt_berstring_null) 12827c478bd9Sstevel@tonic-gate base[n].type = mmt_berstring; 12837c478bd9Sstevel@tonic-gate continue; 12847c478bd9Sstevel@tonic-gate } 12857c478bd9Sstevel@tonic-gate s = skip_token(s, end_s, comma_token); 12867c478bd9Sstevel@tonic-gate if (s == NULL) { 12877c478bd9Sstevel@tonic-gate p_error = parse_not_enough_extract_items; 12887c478bd9Sstevel@tonic-gate break; 12897c478bd9Sstevel@tonic-gate } 12907c478bd9Sstevel@tonic-gate begin_token = s; 12917c478bd9Sstevel@tonic-gate end_token = end_s; 12927c478bd9Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t); 12937c478bd9Sstevel@tonic-gate if (s == NULL) 12947c478bd9Sstevel@tonic-gate break; 12957c478bd9Sstevel@tonic-gate if (t != string_token) { 12967c478bd9Sstevel@tonic-gate p_error = parse_item_expected_error; 12977c478bd9Sstevel@tonic-gate break; 12987c478bd9Sstevel@tonic-gate } 12997c478bd9Sstevel@tonic-gate itm = (__nis_mapping_item_t *) 13007c478bd9Sstevel@tonic-gate s_realloc(item, (nElements + 1) * 13017c478bd9Sstevel@tonic-gate sizeof (__nis_mapping_item_t)); 13027c478bd9Sstevel@tonic-gate if (itm == NULL) 13037c478bd9Sstevel@tonic-gate break; 13047c478bd9Sstevel@tonic-gate item = itm; 13057c478bd9Sstevel@tonic-gate 13067c478bd9Sstevel@tonic-gate s = get_mapping_item(begin_token, end_s, 13077c478bd9Sstevel@tonic-gate &item[nElements], item_type); 13087c478bd9Sstevel@tonic-gate if (s == NULL) 13097c478bd9Sstevel@tonic-gate break; 13107c478bd9Sstevel@tonic-gate nElements++; 13117c478bd9Sstevel@tonic-gate } 13127c478bd9Sstevel@tonic-gate if (p_error != no_parse_error) 13137c478bd9Sstevel@tonic-gate break; 13147c478bd9Sstevel@tonic-gate 13157c478bd9Sstevel@tonic-gate s = skip_token(s, end_s, close_paren_token); 13167c478bd9Sstevel@tonic-gate if (s == NULL) 13177c478bd9Sstevel@tonic-gate break; 13187c478bd9Sstevel@tonic-gate free(fmt_string); 13197c478bd9Sstevel@tonic-gate fmt_string = NULL; 13207c478bd9Sstevel@tonic-gate 13217c478bd9Sstevel@tonic-gate if (nElements == 0) { 13227c478bd9Sstevel@tonic-gate p_error = parse_no_match_item; 13237c478bd9Sstevel@tonic-gate break; 13247c478bd9Sstevel@tonic-gate } 13257c478bd9Sstevel@tonic-gate e = (__nis_mapping_element_t *)s_calloc(1, 13267c478bd9Sstevel@tonic-gate sizeof (__nis_mapping_element_t)); 13277c478bd9Sstevel@tonic-gate if (e == NULL) 13287c478bd9Sstevel@tonic-gate break; 13297c478bd9Sstevel@tonic-gate e->type = me_match; 13307c478bd9Sstevel@tonic-gate e->element.match.numItems = nElements; 13317c478bd9Sstevel@tonic-gate e->element.match.item = item; 13327c478bd9Sstevel@tonic-gate e->element.match.fmt = base; 13337c478bd9Sstevel@tonic-gate lhs->numElements = 1; 13347c478bd9Sstevel@tonic-gate lhs->element = e; 13357c478bd9Sstevel@tonic-gate 13367c478bd9Sstevel@tonic-gate if (p_error == no_parse_error) 13377c478bd9Sstevel@tonic-gate return (s); 13387c478bd9Sstevel@tonic-gate } 13397c478bd9Sstevel@tonic-gate if (item == NULL) { 13407c478bd9Sstevel@tonic-gate for (n = 0; n < nElements; n++) 13417c478bd9Sstevel@tonic-gate free_mapping_item(&item[n]); 13427c478bd9Sstevel@tonic-gate free(item); 13437c478bd9Sstevel@tonic-gate } 13447c478bd9Sstevel@tonic-gate if (fmt_string != NULL) 13457c478bd9Sstevel@tonic-gate free(fmt_string); 13467c478bd9Sstevel@tonic-gate if (base != NULL) 13477c478bd9Sstevel@tonic-gate free_mapping_format(base); 13487c478bd9Sstevel@tonic-gate 13497c478bd9Sstevel@tonic-gate return (NULL); 13507c478bd9Sstevel@tonic-gate } 13517c478bd9Sstevel@tonic-gate 13527c478bd9Sstevel@tonic-gate /* 13537c478bd9Sstevel@tonic-gate * FUNCTION: get_lhs_paren_item 13547c478bd9Sstevel@tonic-gate * 13557c478bd9Sstevel@tonic-gate * Parse left hand side of mapping rule attribute in case of 13567c478bd9Sstevel@tonic-gate * (item1, ..., item-n) 13577c478bd9Sstevel@tonic-gate * 13587c478bd9Sstevel@tonic-gate * RETURN VALUE: NULL if error 13597c478bd9Sstevel@tonic-gate * position of beginning rhs 13607c478bd9Sstevel@tonic-gate * 13617c478bd9Sstevel@tonic-gate * INPUT: the attribute value and mapping rule type 13627c478bd9Sstevel@tonic-gate */ 13637c478bd9Sstevel@tonic-gate 13647c478bd9Sstevel@tonic-gate static const char * 13657c478bd9Sstevel@tonic-gate get_lhs_paren_item( 13667c478bd9Sstevel@tonic-gate const char *s, 13677c478bd9Sstevel@tonic-gate const char *end_s, 13687c478bd9Sstevel@tonic-gate __nis_mapping_rlhs_t *lhs, 13697c478bd9Sstevel@tonic-gate __nis_mapping_item_type_t item_type) 13707c478bd9Sstevel@tonic-gate { 13717c478bd9Sstevel@tonic-gate token_type t; 13727c478bd9Sstevel@tonic-gate const char *begin_token; 13737c478bd9Sstevel@tonic-gate const char *end_token; 13747c478bd9Sstevel@tonic-gate __nis_mapping_element_t *e = NULL; 13757c478bd9Sstevel@tonic-gate int n = 0; 13767c478bd9Sstevel@tonic-gate int i; 13777c478bd9Sstevel@tonic-gate 13787c478bd9Sstevel@tonic-gate /* 13797c478bd9Sstevel@tonic-gate * "(" namespec *("," namespec) ")" 13807c478bd9Sstevel@tonic-gate */ 13817c478bd9Sstevel@tonic-gate 13827c478bd9Sstevel@tonic-gate for (;;) { 13837c478bd9Sstevel@tonic-gate e = (__nis_mapping_element_t *)s_realloc(e, (n + 1) * 13847c478bd9Sstevel@tonic-gate sizeof (__nis_mapping_element_t)); 13857c478bd9Sstevel@tonic-gate if (e == NULL) 13867c478bd9Sstevel@tonic-gate break; 13877c478bd9Sstevel@tonic-gate 13887c478bd9Sstevel@tonic-gate s = get_mapping_item(s, end_s, &e[n].element.item, 13897c478bd9Sstevel@tonic-gate item_type); 13907c478bd9Sstevel@tonic-gate if (s == NULL) 13917c478bd9Sstevel@tonic-gate break; 13927c478bd9Sstevel@tonic-gate e[n].type = me_item; 13937c478bd9Sstevel@tonic-gate n++; 13947c478bd9Sstevel@tonic-gate 13957c478bd9Sstevel@tonic-gate begin_token = s; 13967c478bd9Sstevel@tonic-gate end_token = end_s; 13977c478bd9Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t); 13987c478bd9Sstevel@tonic-gate if (s != NULL && t == close_paren_token) { 13997c478bd9Sstevel@tonic-gate lhs->numElements = n; 14007c478bd9Sstevel@tonic-gate if (n == 1) 14017c478bd9Sstevel@tonic-gate e[0].element.item.repeat = TRUE; 14027c478bd9Sstevel@tonic-gate lhs->element = e; 14037c478bd9Sstevel@tonic-gate return (s); 14047c478bd9Sstevel@tonic-gate } 14057c478bd9Sstevel@tonic-gate if (s == NULL || t != comma_token) { 14067c478bd9Sstevel@tonic-gate p_error = parse_comma_expected_error; 14077c478bd9Sstevel@tonic-gate break; 14087c478bd9Sstevel@tonic-gate } 14097c478bd9Sstevel@tonic-gate } 14107c478bd9Sstevel@tonic-gate for (i = 0; i < n; i++) 14117c478bd9Sstevel@tonic-gate free_mapping_element(&e[i]); 14127c478bd9Sstevel@tonic-gate if (e != NULL) 14137c478bd9Sstevel@tonic-gate free(e); 14147c478bd9Sstevel@tonic-gate return (NULL); 14157c478bd9Sstevel@tonic-gate } 14167c478bd9Sstevel@tonic-gate 14177c478bd9Sstevel@tonic-gate /* 14187c478bd9Sstevel@tonic-gate * FUNCTION: get_rhs 14197c478bd9Sstevel@tonic-gate * 14207c478bd9Sstevel@tonic-gate * Parse right hand side of mapping rule attribute 14217c478bd9Sstevel@tonic-gate * 14227c478bd9Sstevel@tonic-gate * RETURN VALUE: NULL if error 14237c478bd9Sstevel@tonic-gate * position of beginning next mapping rule 14247c478bd9Sstevel@tonic-gate * 14257c478bd9Sstevel@tonic-gate * INPUT: the attribute value and mapping rule type 14267c478bd9Sstevel@tonic-gate */ 14277c478bd9Sstevel@tonic-gate 14287c478bd9Sstevel@tonic-gate static const char * 14297c478bd9Sstevel@tonic-gate get_rhs( 14307c478bd9Sstevel@tonic-gate const char *s, 14317c478bd9Sstevel@tonic-gate const char *end_s, 14327c478bd9Sstevel@tonic-gate __nis_mapping_rlhs_t *rhs, 14337c478bd9Sstevel@tonic-gate __nis_mapping_item_type_t item_type) 14347c478bd9Sstevel@tonic-gate { 14357c478bd9Sstevel@tonic-gate /* 14367c478bd9Sstevel@tonic-gate * This handles the following cases: 14377c478bd9Sstevel@tonic-gate * name me_item 14387c478bd9Sstevel@tonic-gate * (name) me_item 14397c478bd9Sstevel@tonic-gate * (fmt, name-list) me_print 14407c478bd9Sstevel@tonic-gate * (item, fmt) me_extract 14417c478bd9Sstevel@tonic-gate */ 14427c478bd9Sstevel@tonic-gate 14437c478bd9Sstevel@tonic-gate token_type t; 14447c478bd9Sstevel@tonic-gate const char *begin_token; 14457c478bd9Sstevel@tonic-gate const char *end_token; 14467c478bd9Sstevel@tonic-gate char *str = NULL; 14477c478bd9Sstevel@tonic-gate __nis_mapping_format_t *fmt = NULL; 14487c478bd9Sstevel@tonic-gate __nis_mapping_element_t *e = NULL; 14497c478bd9Sstevel@tonic-gate __nis_mapping_item_t item; 14507c478bd9Sstevel@tonic-gate int n; 14517c478bd9Sstevel@tonic-gate 14527c478bd9Sstevel@tonic-gate (void) memset(&item, 0, sizeof (item)); 14537c478bd9Sstevel@tonic-gate 14547c478bd9Sstevel@tonic-gate for (; p_error == no_parse_error; ) { 14557c478bd9Sstevel@tonic-gate begin_token = s; 14567c478bd9Sstevel@tonic-gate end_token = end_s; 14577c478bd9Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t); 14587c478bd9Sstevel@tonic-gate if (s == NULL) 14597c478bd9Sstevel@tonic-gate break; 14607c478bd9Sstevel@tonic-gate 14617c478bd9Sstevel@tonic-gate e = (__nis_mapping_element_t *) 14627c478bd9Sstevel@tonic-gate s_calloc(1, sizeof (__nis_mapping_element_t)); 14637c478bd9Sstevel@tonic-gate if (e == NULL) 14647c478bd9Sstevel@tonic-gate break; 14657c478bd9Sstevel@tonic-gate 14667c478bd9Sstevel@tonic-gate if (t == string_token) { 14677c478bd9Sstevel@tonic-gate s = get_mapping_item(begin_token, end_s, 14687c478bd9Sstevel@tonic-gate &e->element.item, item_type); 14697c478bd9Sstevel@tonic-gate } else if (t == open_paren_token) { 14707c478bd9Sstevel@tonic-gate begin_token = s; 14717c478bd9Sstevel@tonic-gate end_token = end_s; 14727c478bd9Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t); 14737c478bd9Sstevel@tonic-gate if (s == NULL) 14747c478bd9Sstevel@tonic-gate break; 14757c478bd9Sstevel@tonic-gate if (t == string_token) { 14767c478bd9Sstevel@tonic-gate /* (item, fmt) - me_extract */ 14777c478bd9Sstevel@tonic-gate /* (item, "c") - me_split */ 14787c478bd9Sstevel@tonic-gate s = get_mapping_item(begin_token, end_s, 14797c478bd9Sstevel@tonic-gate &item, item_type); 14807c478bd9Sstevel@tonic-gate if (s == NULL) 14817c478bd9Sstevel@tonic-gate break; 14827c478bd9Sstevel@tonic-gate begin_token = s; 14837c478bd9Sstevel@tonic-gate end_token = end_s; 14847c478bd9Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, 14857c478bd9Sstevel@tonic-gate &t); 14867c478bd9Sstevel@tonic-gate if (s == NULL) 14877c478bd9Sstevel@tonic-gate break; 14887c478bd9Sstevel@tonic-gate else if (t == close_paren_token) { 14897c478bd9Sstevel@tonic-gate item.repeat = TRUE; 14907c478bd9Sstevel@tonic-gate e->element.item = item; 14917c478bd9Sstevel@tonic-gate e->type = me_item; 14927c478bd9Sstevel@tonic-gate rhs->numElements = 1; 14937c478bd9Sstevel@tonic-gate rhs->element = e; 14947c478bd9Sstevel@tonic-gate return (s); 14957c478bd9Sstevel@tonic-gate } else if (t != comma_token) { 14967c478bd9Sstevel@tonic-gate p_error = parse_comma_expected_error; 14977c478bd9Sstevel@tonic-gate break; 14987c478bd9Sstevel@tonic-gate } 14997c478bd9Sstevel@tonic-gate 15007c478bd9Sstevel@tonic-gate begin_token = s; 15017c478bd9Sstevel@tonic-gate end_token = end_s; 15027c478bd9Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, 15037c478bd9Sstevel@tonic-gate &t); 15047c478bd9Sstevel@tonic-gate if (s == NULL || t != quoted_string_token) { 15057c478bd9Sstevel@tonic-gate p_error = 15067c478bd9Sstevel@tonic-gate parse_format_string_expected_error; 15077c478bd9Sstevel@tonic-gate break; 15087c478bd9Sstevel@tonic-gate } 15097c478bd9Sstevel@tonic-gate 15107c478bd9Sstevel@tonic-gate if (end_token == begin_token + 1 || 1511*a87701e9SGary Mills (*begin_token == ESCAPE_CHAR && 1512*a87701e9SGary Mills end_token == begin_token + 2)) { 15137c478bd9Sstevel@tonic-gate e->type = me_split; 15147c478bd9Sstevel@tonic-gate e->element.split.item = item; 15157c478bd9Sstevel@tonic-gate e->element.split.delim = *begin_token; 15167c478bd9Sstevel@tonic-gate } else { 15177c478bd9Sstevel@tonic-gate str = s_strndup(begin_token, 15187c478bd9Sstevel@tonic-gate end_token - begin_token); 15197c478bd9Sstevel@tonic-gate if (str == NULL) 15207c478bd9Sstevel@tonic-gate break; 15217c478bd9Sstevel@tonic-gate if (!get_mapping_format(str, &fmt, 15227c478bd9Sstevel@tonic-gate NULL, &n, FALSE)) 15237c478bd9Sstevel@tonic-gate break; 15247c478bd9Sstevel@tonic-gate free(str); 15257c478bd9Sstevel@tonic-gate str = NULL; 15267c478bd9Sstevel@tonic-gate if (n != 1) { 15277c478bd9Sstevel@tonic-gate p_error = 15287c478bd9Sstevel@tonic-gate parse_bad_extract_format_spec; 15297c478bd9Sstevel@tonic-gate break; 15307c478bd9Sstevel@tonic-gate } 15317c478bd9Sstevel@tonic-gate e->type = me_extract; 15327c478bd9Sstevel@tonic-gate e->element.extract.item = item; 15337c478bd9Sstevel@tonic-gate e->element.extract.fmt = fmt; 15347c478bd9Sstevel@tonic-gate } 15357c478bd9Sstevel@tonic-gate s = skip_token(s, end_s, close_paren_token); 15367c478bd9Sstevel@tonic-gate } else if (t == quoted_string_token) { 15377c478bd9Sstevel@tonic-gate /* (fmt, name-list) - me_print */ 15387c478bd9Sstevel@tonic-gate str = s_strndup(begin_token, 15397c478bd9Sstevel@tonic-gate end_token - begin_token); 15407c478bd9Sstevel@tonic-gate if (str == NULL) 15417c478bd9Sstevel@tonic-gate break; 15427c478bd9Sstevel@tonic-gate 15437c478bd9Sstevel@tonic-gate s = get_print_mapping_element(s, end_s, 15447c478bd9Sstevel@tonic-gate str, e, item_type); 15457c478bd9Sstevel@tonic-gate free(str); 15467c478bd9Sstevel@tonic-gate str = NULL; 15477c478bd9Sstevel@tonic-gate } else { 15487c478bd9Sstevel@tonic-gate p_error = parse_start_rhs_unrecognized; 15497c478bd9Sstevel@tonic-gate break; 15507c478bd9Sstevel@tonic-gate } 15517c478bd9Sstevel@tonic-gate } else { 15527c478bd9Sstevel@tonic-gate p_error = parse_start_rhs_unrecognized; 15537c478bd9Sstevel@tonic-gate break; 15547c478bd9Sstevel@tonic-gate } 15557c478bd9Sstevel@tonic-gate if (s == NULL) 15567c478bd9Sstevel@tonic-gate break; 15577c478bd9Sstevel@tonic-gate rhs->numElements = 1; 15587c478bd9Sstevel@tonic-gate rhs->element = e; 15597c478bd9Sstevel@tonic-gate if (p_error == no_parse_error) 15607c478bd9Sstevel@tonic-gate return (s); 15617c478bd9Sstevel@tonic-gate } 15627c478bd9Sstevel@tonic-gate if (str) 15637c478bd9Sstevel@tonic-gate free(str); 15647c478bd9Sstevel@tonic-gate if (fmt != NULL) 15657c478bd9Sstevel@tonic-gate free_mapping_format(fmt); 15667c478bd9Sstevel@tonic-gate if (e != NULL) 15677c478bd9Sstevel@tonic-gate free_mapping_element(e); 15687c478bd9Sstevel@tonic-gate free_mapping_item(&item); 15697c478bd9Sstevel@tonic-gate 15707c478bd9Sstevel@tonic-gate return (NULL); 15717c478bd9Sstevel@tonic-gate } 15727c478bd9Sstevel@tonic-gate 15737c478bd9Sstevel@tonic-gate /* 15747c478bd9Sstevel@tonic-gate * FUNCTION: get_print_mapping_element 15757c478bd9Sstevel@tonic-gate * 15767c478bd9Sstevel@tonic-gate * Parse a print mapping rule attribute in case of the form 15777c478bd9Sstevel@tonic-gate * (fmt, name-list) 15787c478bd9Sstevel@tonic-gate * 15797c478bd9Sstevel@tonic-gate * RETURN VALUE: NULL if error 15807c478bd9Sstevel@tonic-gate * position of beginning next mapping rule 15817c478bd9Sstevel@tonic-gate * 15827c478bd9Sstevel@tonic-gate * INPUT: the attribute value and mapping rule type 15837c478bd9Sstevel@tonic-gate */ 15847c478bd9Sstevel@tonic-gate 15857c478bd9Sstevel@tonic-gate static const char * 15867c478bd9Sstevel@tonic-gate get_print_mapping_element( 15877c478bd9Sstevel@tonic-gate const char *s, 15887c478bd9Sstevel@tonic-gate const char *end_s, 15897c478bd9Sstevel@tonic-gate char *fmt_string, 15907c478bd9Sstevel@tonic-gate __nis_mapping_element_t *e, 15917c478bd9Sstevel@tonic-gate __nis_mapping_item_type_t item_type) 15927c478bd9Sstevel@tonic-gate { 15937c478bd9Sstevel@tonic-gate token_type t; 15947c478bd9Sstevel@tonic-gate const char *begin_token; 15957c478bd9Sstevel@tonic-gate const char *end_token; 15967c478bd9Sstevel@tonic-gate char elide; 15977c478bd9Sstevel@tonic-gate bool_t doElide; 15987c478bd9Sstevel@tonic-gate __nis_mapping_format_t *base = NULL; 15997c478bd9Sstevel@tonic-gate __nis_mapping_sub_element_t *subElement = NULL; 16007c478bd9Sstevel@tonic-gate int n = 0; 16017c478bd9Sstevel@tonic-gate int nSub = 0; 16027c478bd9Sstevel@tonic-gate int numSubElements; 16037c478bd9Sstevel@tonic-gate 16047c478bd9Sstevel@tonic-gate for (; p_error == no_parse_error; ) { 16057c478bd9Sstevel@tonic-gate if (!get_mapping_format(fmt_string, &base, &n, 16067c478bd9Sstevel@tonic-gate &numSubElements, TRUE)) 16077c478bd9Sstevel@tonic-gate break; 16087c478bd9Sstevel@tonic-gate subElement = (__nis_mapping_sub_element_t *) 16097c478bd9Sstevel@tonic-gate s_calloc(numSubElements, 16107c478bd9Sstevel@tonic-gate sizeof (__nis_mapping_sub_element_t)); 16117c478bd9Sstevel@tonic-gate if (subElement == NULL) 16127c478bd9Sstevel@tonic-gate break; 16137c478bd9Sstevel@tonic-gate for (n = 0; base[n].type != mmt_end; n++) { 16147c478bd9Sstevel@tonic-gate if (base[n].type != mmt_item && 16157c478bd9Sstevel@tonic-gate base[n].type != mmt_berstring) { 16167c478bd9Sstevel@tonic-gate if (base[n].type == mmt_berstring_null) 16177c478bd9Sstevel@tonic-gate base[n].type = mmt_berstring; 16187c478bd9Sstevel@tonic-gate continue; 16197c478bd9Sstevel@tonic-gate } 16207c478bd9Sstevel@tonic-gate if (nSub < numSubElements) { 16217c478bd9Sstevel@tonic-gate s = skip_token(s, end_s, comma_token); 16227c478bd9Sstevel@tonic-gate if (s == NULL) { 16237c478bd9Sstevel@tonic-gate p_error = parse_bad_print_format; 16247c478bd9Sstevel@tonic-gate break; 16257c478bd9Sstevel@tonic-gate } 16267c478bd9Sstevel@tonic-gate } 16277c478bd9Sstevel@tonic-gate 16287c478bd9Sstevel@tonic-gate /* namelist may have parens around it */ 16297c478bd9Sstevel@tonic-gate s = get_subElement(s, end_s, &subElement[nSub], 16307c478bd9Sstevel@tonic-gate item_type); 16317c478bd9Sstevel@tonic-gate if (s == NULL) 16327c478bd9Sstevel@tonic-gate break; 16337c478bd9Sstevel@tonic-gate nSub++; 16347c478bd9Sstevel@tonic-gate } 16357c478bd9Sstevel@tonic-gate if (p_error != no_parse_error) 16367c478bd9Sstevel@tonic-gate break; 16377c478bd9Sstevel@tonic-gate 16387c478bd9Sstevel@tonic-gate begin_token = s; 16397c478bd9Sstevel@tonic-gate end_token = end_s; 16407c478bd9Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t); 16417c478bd9Sstevel@tonic-gate if (s == NULL || t == no_token) { 16427c478bd9Sstevel@tonic-gate p_error = parse_unexpected_data_end_rule; 16437c478bd9Sstevel@tonic-gate break; 16447c478bd9Sstevel@tonic-gate } else if (t == close_paren_token) { 16457c478bd9Sstevel@tonic-gate doElide = FALSE; 16467c478bd9Sstevel@tonic-gate elide = '\0'; 16477c478bd9Sstevel@tonic-gate } else if (t == comma_token) { 16487c478bd9Sstevel@tonic-gate begin_token = s; 16497c478bd9Sstevel@tonic-gate end_token = end_s; 16507c478bd9Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t); 16517c478bd9Sstevel@tonic-gate if (s != NULL && t == quoted_string_token && 16527c478bd9Sstevel@tonic-gate (end_token == begin_token + 1 || 1653*a87701e9SGary Mills (*begin_token == ESCAPE_CHAR && 1654*a87701e9SGary Mills end_token == begin_token + 2))) { 16557c478bd9Sstevel@tonic-gate if (numSubElements != 1 || 16567c478bd9Sstevel@tonic-gate subElement->type == me_extract || 16577c478bd9Sstevel@tonic-gate subElement->type == me_split) { 16587c478bd9Sstevel@tonic-gate p_error = parse_cannot_elide; 16597c478bd9Sstevel@tonic-gate break; 16607c478bd9Sstevel@tonic-gate } 16617c478bd9Sstevel@tonic-gate if (subElement->type == me_item && 16627c478bd9Sstevel@tonic-gate !subElement->element.item.repeat) { 16637c478bd9Sstevel@tonic-gate p_error = parse_cannot_elide; 16647c478bd9Sstevel@tonic-gate break; 16657c478bd9Sstevel@tonic-gate } 16667c478bd9Sstevel@tonic-gate elide = *begin_token; 16677c478bd9Sstevel@tonic-gate doElide = TRUE; 16687c478bd9Sstevel@tonic-gate 16697c478bd9Sstevel@tonic-gate } else { 16707c478bd9Sstevel@tonic-gate p_error = parse_bad_elide_char; 16717c478bd9Sstevel@tonic-gate break; 16727c478bd9Sstevel@tonic-gate } 16737c478bd9Sstevel@tonic-gate s = skip_token(s, end_s, close_paren_token); 16747c478bd9Sstevel@tonic-gate if (s == NULL) 16757c478bd9Sstevel@tonic-gate break; 16767c478bd9Sstevel@tonic-gate } 16777c478bd9Sstevel@tonic-gate 16787c478bd9Sstevel@tonic-gate e->type = me_print; 16797c478bd9Sstevel@tonic-gate e->element.print.fmt = base; 16807c478bd9Sstevel@tonic-gate e->element.print.numSubElements = numSubElements; 16817c478bd9Sstevel@tonic-gate e->element.print.subElement = subElement; 16827c478bd9Sstevel@tonic-gate e->element.print.elide = elide; 16837c478bd9Sstevel@tonic-gate e->element.print.doElide = doElide; 16847c478bd9Sstevel@tonic-gate 16857c478bd9Sstevel@tonic-gate if (p_error == no_parse_error) 16867c478bd9Sstevel@tonic-gate return (s); 16877c478bd9Sstevel@tonic-gate } 16887c478bd9Sstevel@tonic-gate if (base) 16897c478bd9Sstevel@tonic-gate free_mapping_format(base); 16907c478bd9Sstevel@tonic-gate if (subElement != NULL) { 16917c478bd9Sstevel@tonic-gate for (n = 0; n < numSubElements; n++) 16927c478bd9Sstevel@tonic-gate free_mapping_sub_element(&subElement[n]); 16937c478bd9Sstevel@tonic-gate free(subElement); 16947c478bd9Sstevel@tonic-gate } 16957c478bd9Sstevel@tonic-gate 16967c478bd9Sstevel@tonic-gate return (NULL); 16977c478bd9Sstevel@tonic-gate } 16987c478bd9Sstevel@tonic-gate 16997c478bd9Sstevel@tonic-gate /* 17007c478bd9Sstevel@tonic-gate * FUNCTION: get_mapping_item 17017c478bd9Sstevel@tonic-gate * 17027c478bd9Sstevel@tonic-gate * Parse attribute string to get mapping item 17037c478bd9Sstevel@tonic-gate * 17047c478bd9Sstevel@tonic-gate * RETURN VALUE: NULL if error 17057c478bd9Sstevel@tonic-gate * position of beginning next token after item 17067c478bd9Sstevel@tonic-gate * 17077c478bd9Sstevel@tonic-gate * INPUT: the attribute value and mapping rule type 17087c478bd9Sstevel@tonic-gate */ 17097c478bd9Sstevel@tonic-gate 17107c478bd9Sstevel@tonic-gate static const char * 17117c478bd9Sstevel@tonic-gate get_mapping_item( 17127c478bd9Sstevel@tonic-gate const char *s, 17137c478bd9Sstevel@tonic-gate const char *end_s, 17147c478bd9Sstevel@tonic-gate __nis_mapping_item_t *item, 17157c478bd9Sstevel@tonic-gate __nis_mapping_item_type_t type) 17167c478bd9Sstevel@tonic-gate { 17177c478bd9Sstevel@tonic-gate token_type t; 17187c478bd9Sstevel@tonic-gate const char *begin_token; 17197c478bd9Sstevel@tonic-gate const char *end_token; 17207c478bd9Sstevel@tonic-gate char *name = NULL; 17217c478bd9Sstevel@tonic-gate char *index_string; 17227c478bd9Sstevel@tonic-gate const char *s_sav; 17237c478bd9Sstevel@tonic-gate int len; 17247c478bd9Sstevel@tonic-gate 17257c478bd9Sstevel@tonic-gate (void) memset(item, 0, sizeof (*item)); 17267c478bd9Sstevel@tonic-gate 17277c478bd9Sstevel@tonic-gate /* 17287c478bd9Sstevel@tonic-gate * A namepec is defined as follows: 17297c478bd9Sstevel@tonic-gate * namespec = ["ldap:"] attrspec [searchTriple] | 17307c478bd9Sstevel@tonic-gate * ["nis+:"] colspec [objectspec] 17317c478bd9Sstevel@tonic-gate * 17327c478bd9Sstevel@tonic-gate * The form of the item is assumed to be as follows: 17337c478bd9Sstevel@tonic-gate * ["ldap:"] attrspec [searchTriple] 17347c478bd9Sstevel@tonic-gate * attrspec = attribute | "(" attribute ")" 17357c478bd9Sstevel@tonic-gate * searchTriple = ":" [baseDN] ["?" [scope] ["?" [filter]]] 17367c478bd9Sstevel@tonic-gate * baseDN = Base DN for search 17377c478bd9Sstevel@tonic-gate * scope = "base" | "one" | "sub" 17387c478bd9Sstevel@tonic-gate * filter = LDAP search filter 17397c478bd9Sstevel@tonic-gate * 17407c478bd9Sstevel@tonic-gate * The form of the objectspec is as follows: 17417c478bd9Sstevel@tonic-gate * ["nis+:"] colspec [objectspec] 17427c478bd9Sstevel@tonic-gate * objectspec = objectname | "[" indexlist "]" tablename 17437c478bd9Sstevel@tonic-gate * objectname = The name of a NIS+ object 17447c478bd9Sstevel@tonic-gate * tablename = The name of a NIS+ table 17457c478bd9Sstevel@tonic-gate * indexlist = colspec ["," colspec] 17467c478bd9Sstevel@tonic-gate * colspec = colname "=" colvalue 17477c478bd9Sstevel@tonic-gate * colname = The name of a column in the table 17487c478bd9Sstevel@tonic-gate * colvalue = colvaluestring | \" colvaluestring \" 17497c478bd9Sstevel@tonic-gate */ 17507c478bd9Sstevel@tonic-gate 17517c478bd9Sstevel@tonic-gate for (; p_error == no_parse_error; ) { 17527c478bd9Sstevel@tonic-gate while (s < end_s && is_whitespace(*s)) 17537c478bd9Sstevel@tonic-gate s++; 17547c478bd9Sstevel@tonic-gate len = end_s - s; 17557c478bd9Sstevel@tonic-gate if (yp2ldap) { 17567c478bd9Sstevel@tonic-gate if ((begin_token = skip_string("ldap:", s, 17577c478bd9Sstevel@tonic-gate len)) != NULL) { 17587c478bd9Sstevel@tonic-gate item->type = mit_ldap; 17597c478bd9Sstevel@tonic-gate } else if ((begin_token = skip_string("yp:", s, 17607c478bd9Sstevel@tonic-gate len)) != NULL) { 17617c478bd9Sstevel@tonic-gate item->type = mit_nisplus; 17627c478bd9Sstevel@tonic-gate } else { 17637c478bd9Sstevel@tonic-gate item->type = type; 17647c478bd9Sstevel@tonic-gate begin_token = s; 17657c478bd9Sstevel@tonic-gate } 17667c478bd9Sstevel@tonic-gate } else { 17677c478bd9Sstevel@tonic-gate if ((begin_token = skip_string("ldap:", s, 17687c478bd9Sstevel@tonic-gate len)) != NULL) { 17697c478bd9Sstevel@tonic-gate item->type = mit_ldap; 17707c478bd9Sstevel@tonic-gate } else if ((begin_token = skip_string("nis+:", s, 17717c478bd9Sstevel@tonic-gate len)) != NULL) { 17727c478bd9Sstevel@tonic-gate item->type = mit_nisplus; 17737c478bd9Sstevel@tonic-gate } else if ((begin_token = skip_string("nisplus:", s, 17747c478bd9Sstevel@tonic-gate len)) != NULL) { 17757c478bd9Sstevel@tonic-gate item->type = mit_nisplus; 17767c478bd9Sstevel@tonic-gate } else { 17777c478bd9Sstevel@tonic-gate item->type = type; 17787c478bd9Sstevel@tonic-gate begin_token = s; 17797c478bd9Sstevel@tonic-gate } 17807c478bd9Sstevel@tonic-gate } 17817c478bd9Sstevel@tonic-gate 17827c478bd9Sstevel@tonic-gate end_token = end_s; 17837c478bd9Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t); 17847c478bd9Sstevel@tonic-gate if (s == NULL || t != string_token) { 17857c478bd9Sstevel@tonic-gate p_error = parse_bad_item_format; 17867c478bd9Sstevel@tonic-gate break; 17877c478bd9Sstevel@tonic-gate } 17887c478bd9Sstevel@tonic-gate 17897c478bd9Sstevel@tonic-gate item->name = s_strndup_esc(begin_token, 17907c478bd9Sstevel@tonic-gate end_token - begin_token); 17917c478bd9Sstevel@tonic-gate if (item->name == NULL) 17927c478bd9Sstevel@tonic-gate break; 17937c478bd9Sstevel@tonic-gate if (item->type == mit_ldap) { 17947c478bd9Sstevel@tonic-gate item->searchSpec.triple.scope = LDAP_SCOPE_UNKNOWN; 17957c478bd9Sstevel@tonic-gate begin_token = s; 17967c478bd9Sstevel@tonic-gate end_token = end_s; 17977c478bd9Sstevel@tonic-gate s_sav = s; 17987c478bd9Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t); 17997c478bd9Sstevel@tonic-gate if (s != NULL && t == colon_token) { 18007c478bd9Sstevel@tonic-gate s = get_search_triple(s, end_s, 18017c478bd9Sstevel@tonic-gate &item->searchSpec.triple); 18027c478bd9Sstevel@tonic-gate if (s == NULL) 18037c478bd9Sstevel@tonic-gate break; 18047c478bd9Sstevel@tonic-gate } else 18057c478bd9Sstevel@tonic-gate s = s_sav; 18067c478bd9Sstevel@tonic-gate } else if (item->type == mit_nisplus) { 18077c478bd9Sstevel@tonic-gate while (s < end_s && is_whitespace(*s)) 18087c478bd9Sstevel@tonic-gate s++; 18097c478bd9Sstevel@tonic-gate 18107c478bd9Sstevel@tonic-gate if (s < end_s && *s == OPEN_BRACKET) { 18117c478bd9Sstevel@tonic-gate index_string = getIndex(&s, end_s); 18127c478bd9Sstevel@tonic-gate if (index_string == NULL) 18137c478bd9Sstevel@tonic-gate break; 18147c478bd9Sstevel@tonic-gate (void) parse_index(index_string, 18157c478bd9Sstevel@tonic-gate index_string + strlen(index_string), 18167c478bd9Sstevel@tonic-gate &item->searchSpec.obj.index); 18177c478bd9Sstevel@tonic-gate free(index_string); 18187c478bd9Sstevel@tonic-gate if (p_error != no_parse_error) 18197c478bd9Sstevel@tonic-gate break; 18207c478bd9Sstevel@tonic-gate } 18217c478bd9Sstevel@tonic-gate s_sav = s; 18227c478bd9Sstevel@tonic-gate begin_token = s; 18237c478bd9Sstevel@tonic-gate end_token = end_s; 18247c478bd9Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t); 18257c478bd9Sstevel@tonic-gate if (s != NULL && t == string_token) { 18267c478bd9Sstevel@tonic-gate name = s_strndup_esc(begin_token, 18277c478bd9Sstevel@tonic-gate end_token - begin_token); 18287c478bd9Sstevel@tonic-gate if (name == NULL) 18297c478bd9Sstevel@tonic-gate break; 18307c478bd9Sstevel@tonic-gate item->searchSpec.obj.name = name; 18317c478bd9Sstevel@tonic-gate } else 18327c478bd9Sstevel@tonic-gate s = s_sav; 18337c478bd9Sstevel@tonic-gate } 18347c478bd9Sstevel@tonic-gate if (p_error == no_parse_error) 18357c478bd9Sstevel@tonic-gate return (s); 18367c478bd9Sstevel@tonic-gate } 18377c478bd9Sstevel@tonic-gate free_mapping_item(item); 18387c478bd9Sstevel@tonic-gate (void) memset(item, 0, sizeof (*item)); 18397c478bd9Sstevel@tonic-gate if (name == NULL) 18407c478bd9Sstevel@tonic-gate free(name); 18417c478bd9Sstevel@tonic-gate return (NULL); 18427c478bd9Sstevel@tonic-gate } 18437c478bd9Sstevel@tonic-gate 18447c478bd9Sstevel@tonic-gate static const char * 18457c478bd9Sstevel@tonic-gate get_print_sub_element(const char *s, 18467c478bd9Sstevel@tonic-gate const char *end_s, 18477c478bd9Sstevel@tonic-gate __nis_mapping_item_type_t type, 18487c478bd9Sstevel@tonic-gate __nis_mapping_sub_element_t *sub) 18497c478bd9Sstevel@tonic-gate { 18507c478bd9Sstevel@tonic-gate 18517c478bd9Sstevel@tonic-gate int k; 18527c478bd9Sstevel@tonic-gate int n; 18537c478bd9Sstevel@tonic-gate const char *begin_token; 18547c478bd9Sstevel@tonic-gate const char *end_token; 18557c478bd9Sstevel@tonic-gate token_type t; 18567c478bd9Sstevel@tonic-gate __nis_mapping_format_t *base; 18577c478bd9Sstevel@tonic-gate __nis_mapping_item_t *print_item; 18587c478bd9Sstevel@tonic-gate 18597c478bd9Sstevel@tonic-gate k = 0; 18607c478bd9Sstevel@tonic-gate base = sub->element.print.fmt; 18617c478bd9Sstevel@tonic-gate print_item = sub->element.print.item; 18627c478bd9Sstevel@tonic-gate sub->element.print.doElide = FALSE; 18637c478bd9Sstevel@tonic-gate sub->element.print.elide = '\0'; 18647c478bd9Sstevel@tonic-gate 18657c478bd9Sstevel@tonic-gate for (n = 0; base[n].type != mmt_end; n++) { 18667c478bd9Sstevel@tonic-gate if (base[n].type != mmt_item && base[n].type != mmt_berstring) { 18677c478bd9Sstevel@tonic-gate if (base[n].type == mmt_berstring_null) 18687c478bd9Sstevel@tonic-gate base[n].type = mmt_berstring; 18697c478bd9Sstevel@tonic-gate continue; 18707c478bd9Sstevel@tonic-gate } 18717c478bd9Sstevel@tonic-gate s = skip_token(s, end_s, comma_token); 18727c478bd9Sstevel@tonic-gate if (s == NULL) { 18737c478bd9Sstevel@tonic-gate p_error = parse_bad_print_format; 18747c478bd9Sstevel@tonic-gate break; 18757c478bd9Sstevel@tonic-gate } 18767c478bd9Sstevel@tonic-gate 18777c478bd9Sstevel@tonic-gate begin_token = s; 18787c478bd9Sstevel@tonic-gate end_token = end_s; 18797c478bd9Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t); 18807c478bd9Sstevel@tonic-gate if (s == NULL) 18817c478bd9Sstevel@tonic-gate break; 18827c478bd9Sstevel@tonic-gate /* 18837c478bd9Sstevel@tonic-gate * Determine if of the form 18847c478bd9Sstevel@tonic-gate * ("fmt", (item), "delim") or 18857c478bd9Sstevel@tonic-gate * ("fmt", item1, item2, ..., item n) 18867c478bd9Sstevel@tonic-gate */ 18877c478bd9Sstevel@tonic-gate if (t == open_paren_token) { 18887c478bd9Sstevel@tonic-gate if (sub->element.print.numItems != 1) { 18897c478bd9Sstevel@tonic-gate p_error = parse_invalid_print_arg; 18907c478bd9Sstevel@tonic-gate break; 18917c478bd9Sstevel@tonic-gate } 18927c478bd9Sstevel@tonic-gate s = get_mapping_item(s, end_s, &print_item[k++], type); 18937c478bd9Sstevel@tonic-gate s = skip_token(s, end_s, close_paren_token); 18947c478bd9Sstevel@tonic-gate s = skip_token(s, end_s, comma_token); 18957c478bd9Sstevel@tonic-gate if (s == NULL) { 18967c478bd9Sstevel@tonic-gate p_error = parse_bad_print_format; 18977c478bd9Sstevel@tonic-gate break; 18987c478bd9Sstevel@tonic-gate } 18997c478bd9Sstevel@tonic-gate begin_token = s; 19007c478bd9Sstevel@tonic-gate end_token = end_s; 19017c478bd9Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t); 19027c478bd9Sstevel@tonic-gate if (s == NULL) 19037c478bd9Sstevel@tonic-gate break; 19047c478bd9Sstevel@tonic-gate if (t != quoted_string_token || 19057c478bd9Sstevel@tonic-gate begin_token + 1 != end_token) { 19067c478bd9Sstevel@tonic-gate p_error = parse_bad_elide_char; 19077c478bd9Sstevel@tonic-gate break; 19087c478bd9Sstevel@tonic-gate } 19097c478bd9Sstevel@tonic-gate sub->element.print.elide = *begin_token; 19107c478bd9Sstevel@tonic-gate sub->element.print.doElide = TRUE; 19117c478bd9Sstevel@tonic-gate print_item[0].repeat = TRUE; 19127c478bd9Sstevel@tonic-gate break; 19137c478bd9Sstevel@tonic-gate } 19147c478bd9Sstevel@tonic-gate s = get_mapping_item(begin_token, end_s, 19157c478bd9Sstevel@tonic-gate &print_item[k++], type); 19167c478bd9Sstevel@tonic-gate if (s == NULL) 19177c478bd9Sstevel@tonic-gate break; 19187c478bd9Sstevel@tonic-gate 19197c478bd9Sstevel@tonic-gate if (p_error != no_parse_error) 19207c478bd9Sstevel@tonic-gate break; 19217c478bd9Sstevel@tonic-gate } 19227c478bd9Sstevel@tonic-gate 19237c478bd9Sstevel@tonic-gate return (p_error == no_parse_error ? s : NULL); 19247c478bd9Sstevel@tonic-gate } 19257c478bd9Sstevel@tonic-gate 19267c478bd9Sstevel@tonic-gate /* 19277c478bd9Sstevel@tonic-gate * FUNCTION: get_subElement 19287c478bd9Sstevel@tonic-gate * 19297c478bd9Sstevel@tonic-gate * Parse attribute string to get sub element item 19307c478bd9Sstevel@tonic-gate * 19317c478bd9Sstevel@tonic-gate * RETURN VALUE: NULL if error 19327c478bd9Sstevel@tonic-gate * position of beginning next token after item 19337c478bd9Sstevel@tonic-gate * 19347c478bd9Sstevel@tonic-gate * INPUT: the attribute value and mapping rule type 19357c478bd9Sstevel@tonic-gate */ 19367c478bd9Sstevel@tonic-gate 19377c478bd9Sstevel@tonic-gate static const char * 19387c478bd9Sstevel@tonic-gate get_subElement( 19397c478bd9Sstevel@tonic-gate const char *s, 19407c478bd9Sstevel@tonic-gate const char *end_s, 19417c478bd9Sstevel@tonic-gate __nis_mapping_sub_element_t *subelement, 19427c478bd9Sstevel@tonic-gate __nis_mapping_item_type_t type) 19437c478bd9Sstevel@tonic-gate { 19447c478bd9Sstevel@tonic-gate token_type t; 19457c478bd9Sstevel@tonic-gate const char *begin_token; 19467c478bd9Sstevel@tonic-gate const char *end_token; 19477c478bd9Sstevel@tonic-gate char *fmt_string; 19487c478bd9Sstevel@tonic-gate __nis_mapping_item_t item; 19497c478bd9Sstevel@tonic-gate __nis_mapping_element_type_t e_type; 19507c478bd9Sstevel@tonic-gate __nis_mapping_item_t *print_item = NULL; 19517c478bd9Sstevel@tonic-gate __nis_mapping_format_t *base = NULL; 19527c478bd9Sstevel@tonic-gate int n = 0; 19537c478bd9Sstevel@tonic-gate int numItems = 0; 19547c478bd9Sstevel@tonic-gate unsigned char delim; 19557c478bd9Sstevel@tonic-gate __nis_mapping_sub_element_t sub; 19567c478bd9Sstevel@tonic-gate 19577c478bd9Sstevel@tonic-gate /* 19587c478bd9Sstevel@tonic-gate * What is the form of we are expecting here 19597c478bd9Sstevel@tonic-gate * item me_item 19607c478bd9Sstevel@tonic-gate * (item) me_item 19617c478bd9Sstevel@tonic-gate * ("fmt", item1, item2, ..., item n) me_print 19627c478bd9Sstevel@tonic-gate * ("fmt", (item), "elide") me_print 19637c478bd9Sstevel@tonic-gate * (name, "delim") me_split 19647c478bd9Sstevel@tonic-gate * (item, "fmt") me_extract 19657c478bd9Sstevel@tonic-gate */ 19667c478bd9Sstevel@tonic-gate (void) memset(&item, 0, sizeof (item)); 19677c478bd9Sstevel@tonic-gate 19687c478bd9Sstevel@tonic-gate for (; p_error == no_parse_error; ) { 19697c478bd9Sstevel@tonic-gate begin_token = s; 19707c478bd9Sstevel@tonic-gate end_token = end_s; 19717c478bd9Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t); 19727c478bd9Sstevel@tonic-gate if (s == NULL) 19737c478bd9Sstevel@tonic-gate break; 19747c478bd9Sstevel@tonic-gate if (t == string_token) { /* me_item */ 19757c478bd9Sstevel@tonic-gate s = get_mapping_item(begin_token, end_s, 19767c478bd9Sstevel@tonic-gate &subelement->element.item, type); 19777c478bd9Sstevel@tonic-gate if (s == NULL) 19787c478bd9Sstevel@tonic-gate break; 19797c478bd9Sstevel@tonic-gate subelement->type = me_item; 19807c478bd9Sstevel@tonic-gate return (s); 19817c478bd9Sstevel@tonic-gate } else if (t != open_paren_token) { 19827c478bd9Sstevel@tonic-gate p_error = parse_item_expected_error; 19837c478bd9Sstevel@tonic-gate break; 19847c478bd9Sstevel@tonic-gate } 19857c478bd9Sstevel@tonic-gate 19867c478bd9Sstevel@tonic-gate begin_token = s; 19877c478bd9Sstevel@tonic-gate end_token = end_s; 19887c478bd9Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t); 19897c478bd9Sstevel@tonic-gate if (s == NULL) 19907c478bd9Sstevel@tonic-gate break; 19917c478bd9Sstevel@tonic-gate 19927c478bd9Sstevel@tonic-gate if (t != string_token && t != quoted_string_token) { 19937c478bd9Sstevel@tonic-gate p_error = parse_item_expected_error; 19947c478bd9Sstevel@tonic-gate break; 19957c478bd9Sstevel@tonic-gate } 19967c478bd9Sstevel@tonic-gate e_type = me_print; 19977c478bd9Sstevel@tonic-gate if (t == string_token) { 19987c478bd9Sstevel@tonic-gate /* me_item, me_extract or me_split */ 19997c478bd9Sstevel@tonic-gate s = get_mapping_item(begin_token, end_s, &item, type); 20007c478bd9Sstevel@tonic-gate if (s == NULL) 20017c478bd9Sstevel@tonic-gate break; 20027c478bd9Sstevel@tonic-gate 20037c478bd9Sstevel@tonic-gate begin_token = s; 20047c478bd9Sstevel@tonic-gate end_token = end_s; 20057c478bd9Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t); 20067c478bd9Sstevel@tonic-gate if (s == NULL) { 20077c478bd9Sstevel@tonic-gate p_error = parse_unexpected_data_end_rule; 20087c478bd9Sstevel@tonic-gate break; 20097c478bd9Sstevel@tonic-gate } else if (t == close_paren_token) { 20107c478bd9Sstevel@tonic-gate subelement->type = me_item; 20117c478bd9Sstevel@tonic-gate item.repeat = TRUE; 20127c478bd9Sstevel@tonic-gate subelement->element.item = item; 20137c478bd9Sstevel@tonic-gate if (yp2ldap) { 20147c478bd9Sstevel@tonic-gate while (s < end_s && is_whitespace(*s)) 20157c478bd9Sstevel@tonic-gate s++; 20167c478bd9Sstevel@tonic-gate if (s == end_s) { 20177c478bd9Sstevel@tonic-gate p_error = 20187c478bd9Sstevel@tonic-gate parse_unexpected_data_end_rule; 20197c478bd9Sstevel@tonic-gate break; 20207c478bd9Sstevel@tonic-gate } 20217c478bd9Sstevel@tonic-gate if (*s == DASH_CHAR && s < end_s) { 20227c478bd9Sstevel@tonic-gate s++; 20237c478bd9Sstevel@tonic-gate while (s < end_s && 20247c478bd9Sstevel@tonic-gate is_whitespace(*s)) 20257c478bd9Sstevel@tonic-gate s++; 20267c478bd9Sstevel@tonic-gate begin_token = s; 20277c478bd9Sstevel@tonic-gate end_token = end_s; 20287c478bd9Sstevel@tonic-gate 20297c478bd9Sstevel@tonic-gate subelement->element.item.exItem 20307c478bd9Sstevel@tonic-gate = 20317c478bd9Sstevel@tonic-gate (__nis_mapping_item_t *) 20327c478bd9Sstevel@tonic-gate s_malloc(sizeof (__nis_mapping_item_t)); 20337c478bd9Sstevel@tonic-gate if (!subelement-> 20347c478bd9Sstevel@tonic-gate element.item.exItem) 20357c478bd9Sstevel@tonic-gate break; 20367c478bd9Sstevel@tonic-gate s = get_mapping_item(s, end_s, 20377c478bd9Sstevel@tonic-gate subelement-> 20387c478bd9Sstevel@tonic-gate element.item.exItem, 20397c478bd9Sstevel@tonic-gate type); 20407c478bd9Sstevel@tonic-gate if (s == NULL) { 20417c478bd9Sstevel@tonic-gate p_error = 20427c478bd9Sstevel@tonic-gate parse_internal_error; 20437c478bd9Sstevel@tonic-gate free_mapping_item( 20447c478bd9Sstevel@tonic-gate subelement-> 20457c478bd9Sstevel@tonic-gate element.item.exItem); 20467c478bd9Sstevel@tonic-gate subelement-> 20477c478bd9Sstevel@tonic-gate element.item.exItem = 20487c478bd9Sstevel@tonic-gate NULL; 20497c478bd9Sstevel@tonic-gate break; 20507c478bd9Sstevel@tonic-gate } 20517c478bd9Sstevel@tonic-gate } 20527c478bd9Sstevel@tonic-gate } 20537c478bd9Sstevel@tonic-gate return (s); 20547c478bd9Sstevel@tonic-gate } else if (t != comma_token) { 20557c478bd9Sstevel@tonic-gate p_error = parse_comma_expected_error; 20567c478bd9Sstevel@tonic-gate break; 20577c478bd9Sstevel@tonic-gate } 20587c478bd9Sstevel@tonic-gate 20597c478bd9Sstevel@tonic-gate begin_token = s; 20607c478bd9Sstevel@tonic-gate end_token = end_s; 20617c478bd9Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t); 20627c478bd9Sstevel@tonic-gate if (s == NULL || t != quoted_string_token) { 20637c478bd9Sstevel@tonic-gate p_error = parse_format_string_expected_error; 20647c478bd9Sstevel@tonic-gate break; 20657c478bd9Sstevel@tonic-gate } 20667c478bd9Sstevel@tonic-gate if (end_token == begin_token + 1 || 2067*a87701e9SGary Mills (*begin_token == ESCAPE_CHAR && 2068*a87701e9SGary Mills end_token == begin_token + 2)) { 20697c478bd9Sstevel@tonic-gate /* me_split */ 20707c478bd9Sstevel@tonic-gate delim = (unsigned char)end_token[-1]; 20717c478bd9Sstevel@tonic-gate s = skip_token(s, end_s, close_paren_token); 20727c478bd9Sstevel@tonic-gate if (s == NULL) 20737c478bd9Sstevel@tonic-gate break; 20747c478bd9Sstevel@tonic-gate subelement->element.split.item = item; 20757c478bd9Sstevel@tonic-gate subelement->element.split.delim = delim; 20767c478bd9Sstevel@tonic-gate subelement->type = me_split; 20777c478bd9Sstevel@tonic-gate return (s); 20787c478bd9Sstevel@tonic-gate } 20797c478bd9Sstevel@tonic-gate e_type = me_extract; 20807c478bd9Sstevel@tonic-gate } 20817c478bd9Sstevel@tonic-gate fmt_string = s_strndup(begin_token, end_token - begin_token); 20827c478bd9Sstevel@tonic-gate if (fmt_string == NULL) 20837c478bd9Sstevel@tonic-gate break; 20847c478bd9Sstevel@tonic-gate if (!get_mapping_format(fmt_string, &base, &n, &numItems, 20857c478bd9Sstevel@tonic-gate e_type == me_print)) { 20867c478bd9Sstevel@tonic-gate free(fmt_string); 20877c478bd9Sstevel@tonic-gate break; 20887c478bd9Sstevel@tonic-gate } 20897c478bd9Sstevel@tonic-gate free(fmt_string); 20907c478bd9Sstevel@tonic-gate 20917c478bd9Sstevel@tonic-gate if (numItems != 1 && e_type == me_extract) { 20927c478bd9Sstevel@tonic-gate p_error = numItems == 0 ? 20937c478bd9Sstevel@tonic-gate parse_not_enough_extract_items : 20947c478bd9Sstevel@tonic-gate parse_too_many_extract_items; 20957c478bd9Sstevel@tonic-gate break; 20967c478bd9Sstevel@tonic-gate } else if (numItems > 0 && e_type == me_print) { 20977c478bd9Sstevel@tonic-gate print_item = (__nis_mapping_item_t *)s_calloc(numItems, 20987c478bd9Sstevel@tonic-gate sizeof (__nis_mapping_item_t)); 20997c478bd9Sstevel@tonic-gate if (print_item == NULL) 21007c478bd9Sstevel@tonic-gate break; 21017c478bd9Sstevel@tonic-gate } 21027c478bd9Sstevel@tonic-gate 21037c478bd9Sstevel@tonic-gate if (e_type == me_print) { 21047c478bd9Sstevel@tonic-gate sub.element.print.numItems = numItems; 21057c478bd9Sstevel@tonic-gate sub.element.print.fmt = base; 21067c478bd9Sstevel@tonic-gate sub.element.print.item = print_item; 21077c478bd9Sstevel@tonic-gate s = get_print_sub_element(s, end_s, type, &sub); 21087c478bd9Sstevel@tonic-gate if (s == NULL) 21097c478bd9Sstevel@tonic-gate break; 21107c478bd9Sstevel@tonic-gate } 21117c478bd9Sstevel@tonic-gate s = skip_token(s, end_s, close_paren_token); 21127c478bd9Sstevel@tonic-gate if (s == NULL) 21137c478bd9Sstevel@tonic-gate break; 21147c478bd9Sstevel@tonic-gate 21157c478bd9Sstevel@tonic-gate subelement->type = e_type; 21167c478bd9Sstevel@tonic-gate if (e_type == me_extract) { 21177c478bd9Sstevel@tonic-gate subelement->element.extract.fmt = base; 21187c478bd9Sstevel@tonic-gate subelement->element.extract.item = item; 21197c478bd9Sstevel@tonic-gate } else { 21207c478bd9Sstevel@tonic-gate subelement->type = me_print; 21217c478bd9Sstevel@tonic-gate subelement->element.print.fmt = base; 21227c478bd9Sstevel@tonic-gate subelement->element.print.numItems = numItems; 21237c478bd9Sstevel@tonic-gate subelement->element.print.item = print_item; 21247c478bd9Sstevel@tonic-gate subelement->element.print.doElide = 21257c478bd9Sstevel@tonic-gate sub.element.print.doElide; 21267c478bd9Sstevel@tonic-gate subelement->element.print.elide = 21277c478bd9Sstevel@tonic-gate sub.element.print.elide; 21287c478bd9Sstevel@tonic-gate } 21297c478bd9Sstevel@tonic-gate if (p_error == no_parse_error) 21307c478bd9Sstevel@tonic-gate return (s); 21317c478bd9Sstevel@tonic-gate } 21327c478bd9Sstevel@tonic-gate free_mapping_item(&item); 21337c478bd9Sstevel@tonic-gate if (base != NULL) 21347c478bd9Sstevel@tonic-gate free_mapping_format(base); 21357c478bd9Sstevel@tonic-gate if (print_item) { 21367c478bd9Sstevel@tonic-gate for (n = 0; n < numItems; n++) 21377c478bd9Sstevel@tonic-gate free_mapping_item(&print_item[n]); 21387c478bd9Sstevel@tonic-gate free(print_item); 21397c478bd9Sstevel@tonic-gate } 21407c478bd9Sstevel@tonic-gate 21417c478bd9Sstevel@tonic-gate return (NULL); 21427c478bd9Sstevel@tonic-gate } 21437c478bd9Sstevel@tonic-gate 21447c478bd9Sstevel@tonic-gate /* 21457c478bd9Sstevel@tonic-gate * FUNCTION: skip_get_dn 21467c478bd9Sstevel@tonic-gate * 21477c478bd9Sstevel@tonic-gate * Get first token after dn 21487c478bd9Sstevel@tonic-gate * 21497c478bd9Sstevel@tonic-gate * RETURN VALUE: NULL if error (not valid dn) 21507c478bd9Sstevel@tonic-gate * position of beginning next token after dn 21517c478bd9Sstevel@tonic-gate * 21527c478bd9Sstevel@tonic-gate * INPUT: the attribute value 21537c478bd9Sstevel@tonic-gate */ 21547c478bd9Sstevel@tonic-gate 21557c478bd9Sstevel@tonic-gate const char * 21567c478bd9Sstevel@tonic-gate skip_get_dn(const char *dn, const char *end) 21577c478bd9Sstevel@tonic-gate { 21587c478bd9Sstevel@tonic-gate size_t len = 0; 21597c478bd9Sstevel@tonic-gate bool_t in_quote = FALSE; 21607c478bd9Sstevel@tonic-gate bool_t goteq = FALSE; 21617c478bd9Sstevel@tonic-gate bool_t gotch = FALSE; 21627c478bd9Sstevel@tonic-gate bool_t done = FALSE; 21637c478bd9Sstevel@tonic-gate bool_t last_comma = FALSE; 21647c478bd9Sstevel@tonic-gate const char *last_dn = dn; 21657c478bd9Sstevel@tonic-gate 21667c478bd9Sstevel@tonic-gate while (!done) { 21677c478bd9Sstevel@tonic-gate dn += len; 21687c478bd9Sstevel@tonic-gate if (last_comma) { 21697c478bd9Sstevel@tonic-gate last_dn = dn; 21707c478bd9Sstevel@tonic-gate last_comma = FALSE; 21717c478bd9Sstevel@tonic-gate } 21727c478bd9Sstevel@tonic-gate if (dn >= end) 21737c478bd9Sstevel@tonic-gate break; 21747c478bd9Sstevel@tonic-gate len = 1; 21757c478bd9Sstevel@tonic-gate switch (*dn) { 21767c478bd9Sstevel@tonic-gate case ESCAPE_CHAR: 21777c478bd9Sstevel@tonic-gate len = 2; 21787c478bd9Sstevel@tonic-gate gotch = TRUE; 21797c478bd9Sstevel@tonic-gate break; 21807c478bd9Sstevel@tonic-gate case DOUBLE_QUOTE_CHAR: 21817c478bd9Sstevel@tonic-gate in_quote = !in_quote; 21827c478bd9Sstevel@tonic-gate break; 21837c478bd9Sstevel@tonic-gate case QUESTION_MARK: 21847c478bd9Sstevel@tonic-gate case CLOSE_PAREN_CHAR: 21857c478bd9Sstevel@tonic-gate case COLON_CHAR: 21867c478bd9Sstevel@tonic-gate done = !in_quote; 21877c478bd9Sstevel@tonic-gate /* FALLTHRU */ 21887c478bd9Sstevel@tonic-gate case SEMI_COLON_CHAR: 21897c478bd9Sstevel@tonic-gate case PLUS_SIGN: 21907c478bd9Sstevel@tonic-gate case COMMA_CHAR: 21917c478bd9Sstevel@tonic-gate if (!in_quote) { 21927c478bd9Sstevel@tonic-gate if (!goteq || !gotch) 21937c478bd9Sstevel@tonic-gate return (last_dn); 21947c478bd9Sstevel@tonic-gate goteq = FALSE; 21957c478bd9Sstevel@tonic-gate gotch = FALSE; 21967c478bd9Sstevel@tonic-gate if (*dn != PLUS_SIGN) 21977c478bd9Sstevel@tonic-gate last_dn = dn; 21987c478bd9Sstevel@tonic-gate last_comma = *dn == COMMA_CHAR; 21997c478bd9Sstevel@tonic-gate } else { 22007c478bd9Sstevel@tonic-gate gotch = TRUE; 22017c478bd9Sstevel@tonic-gate } 22027c478bd9Sstevel@tonic-gate break; 22037c478bd9Sstevel@tonic-gate case EQUAL_CHAR: 22047c478bd9Sstevel@tonic-gate if (!in_quote) { 22057c478bd9Sstevel@tonic-gate if (!gotch || goteq) 22067c478bd9Sstevel@tonic-gate return (NULL); 22077c478bd9Sstevel@tonic-gate goteq = TRUE; 22087c478bd9Sstevel@tonic-gate gotch = FALSE; 22097c478bd9Sstevel@tonic-gate } else { 22107c478bd9Sstevel@tonic-gate gotch = TRUE; 22117c478bd9Sstevel@tonic-gate } 22127c478bd9Sstevel@tonic-gate break; 22137c478bd9Sstevel@tonic-gate default: 22147c478bd9Sstevel@tonic-gate if (!is_whitespace(*dn)) 22157c478bd9Sstevel@tonic-gate gotch = TRUE; 22167c478bd9Sstevel@tonic-gate break; 22177c478bd9Sstevel@tonic-gate } 22187c478bd9Sstevel@tonic-gate } 22197c478bd9Sstevel@tonic-gate 22207c478bd9Sstevel@tonic-gate if (dn == end) { 22217c478bd9Sstevel@tonic-gate if (!in_quote && goteq && gotch) 22227c478bd9Sstevel@tonic-gate last_dn = dn; 22237c478bd9Sstevel@tonic-gate } 22247c478bd9Sstevel@tonic-gate 22257c478bd9Sstevel@tonic-gate return (last_dn); 22267c478bd9Sstevel@tonic-gate } 22277c478bd9Sstevel@tonic-gate 22287c478bd9Sstevel@tonic-gate /* 22297c478bd9Sstevel@tonic-gate * FUNCTION: get_ldap_filter_element 22307c478bd9Sstevel@tonic-gate * 22317c478bd9Sstevel@tonic-gate * Get an ldap filter element for a given string 22327c478bd9Sstevel@tonic-gate * 22337c478bd9Sstevel@tonic-gate * RETURN VALUE: NULL if error 22347c478bd9Sstevel@tonic-gate * __nis_mapping_element_t if success 22357c478bd9Sstevel@tonic-gate * 22367c478bd9Sstevel@tonic-gate * INPUT: the string to parse 22377c478bd9Sstevel@tonic-gate */ 22387c478bd9Sstevel@tonic-gate 22397c478bd9Sstevel@tonic-gate static __nis_mapping_element_t * 22407c478bd9Sstevel@tonic-gate get_ldap_filter_element( 22417c478bd9Sstevel@tonic-gate const char *s, 22427c478bd9Sstevel@tonic-gate const char *end_s 22437c478bd9Sstevel@tonic-gate ) 22447c478bd9Sstevel@tonic-gate { 22457c478bd9Sstevel@tonic-gate token_type t; 22467c478bd9Sstevel@tonic-gate const char *begin_token; 22477c478bd9Sstevel@tonic-gate const char *end_token; 22487c478bd9Sstevel@tonic-gate char *format_str; 22497c478bd9Sstevel@tonic-gate __nis_mapping_element_t *e = NULL; 22507c478bd9Sstevel@tonic-gate 22517c478bd9Sstevel@tonic-gate begin_token = s; 22527c478bd9Sstevel@tonic-gate end_token = end_s; 22537c478bd9Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t); 22547c478bd9Sstevel@tonic-gate if (s == NULL || t != open_paren_token) 22557c478bd9Sstevel@tonic-gate return (NULL); 22567c478bd9Sstevel@tonic-gate 22577c478bd9Sstevel@tonic-gate begin_token = s; 22587c478bd9Sstevel@tonic-gate end_token = end_s; 22597c478bd9Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t); 22607c478bd9Sstevel@tonic-gate if (s == NULL || t != quoted_string_token) 22617c478bd9Sstevel@tonic-gate return (NULL); 22627c478bd9Sstevel@tonic-gate 22637c478bd9Sstevel@tonic-gate format_str = s_strndup(begin_token, end_token - begin_token); 22647c478bd9Sstevel@tonic-gate if (format_str == NULL) 22657c478bd9Sstevel@tonic-gate return (NULL); 22667c478bd9Sstevel@tonic-gate e = (__nis_mapping_element_t *) 22677c478bd9Sstevel@tonic-gate s_calloc(1, sizeof (__nis_mapping_element_t)); 22687c478bd9Sstevel@tonic-gate if (e != NULL) { 22697c478bd9Sstevel@tonic-gate (void) get_print_mapping_element(s, end_s, 22707c478bd9Sstevel@tonic-gate format_str, e, mit_nisplus); 22717c478bd9Sstevel@tonic-gate if (p_error != no_parse_error) { 22727c478bd9Sstevel@tonic-gate free_mapping_element(e); 22737c478bd9Sstevel@tonic-gate e = NULL; 22747c478bd9Sstevel@tonic-gate } 22757c478bd9Sstevel@tonic-gate } 22767c478bd9Sstevel@tonic-gate free(format_str); 22777c478bd9Sstevel@tonic-gate return (e); 22787c478bd9Sstevel@tonic-gate } 22797c478bd9Sstevel@tonic-gate 22807c478bd9Sstevel@tonic-gate /* 22817c478bd9Sstevel@tonic-gate * FUNCTION: get_search_triple 22827c478bd9Sstevel@tonic-gate * 22837c478bd9Sstevel@tonic-gate * Get the search triple or if NULL determine if valid 22847c478bd9Sstevel@tonic-gate * 22857c478bd9Sstevel@tonic-gate * RETURN VALUE: NULL if error 22867c478bd9Sstevel@tonic-gate * position of beginning next token after 22877c478bd9Sstevel@tonic-gate * search triple 22887c478bd9Sstevel@tonic-gate * 22897c478bd9Sstevel@tonic-gate * INPUT: the attribute value 22907c478bd9Sstevel@tonic-gate */ 22917c478bd9Sstevel@tonic-gate 22927c478bd9Sstevel@tonic-gate const char * 22937c478bd9Sstevel@tonic-gate get_search_triple( 22947c478bd9Sstevel@tonic-gate const char *s, 22957c478bd9Sstevel@tonic-gate const char *end_s, 22967c478bd9Sstevel@tonic-gate __nis_search_triple_t *triple 22977c478bd9Sstevel@tonic-gate ) 22987c478bd9Sstevel@tonic-gate { 22997c478bd9Sstevel@tonic-gate const char *begin_token; 23007c478bd9Sstevel@tonic-gate const char *end_token; 23017c478bd9Sstevel@tonic-gate char *search_base = NULL; 23027c478bd9Sstevel@tonic-gate int scope = LDAP_SCOPE_ONELEVEL; 23037c478bd9Sstevel@tonic-gate char *filter = NULL; 23047c478bd9Sstevel@tonic-gate const char *s1; 23057c478bd9Sstevel@tonic-gate __nis_mapping_element_t 23067c478bd9Sstevel@tonic-gate *element = NULL; 23077c478bd9Sstevel@tonic-gate 23087c478bd9Sstevel@tonic-gate /* 23097c478bd9Sstevel@tonic-gate * The form of the searchTriple is assumed to be as follows: 23107c478bd9Sstevel@tonic-gate * searchTriple = [baseDN] ["?" [scope] ["?" [filter]]] 23117c478bd9Sstevel@tonic-gate * baseDN = Base DN for search 23127c478bd9Sstevel@tonic-gate * scope = "base" | "one" | "sub" 23137c478bd9Sstevel@tonic-gate * filter = LDAP search filter 23147c478bd9Sstevel@tonic-gate */ 23157c478bd9Sstevel@tonic-gate for (; p_error == no_parse_error; ) { 23167c478bd9Sstevel@tonic-gate while (s < end_s && is_whitespace(*s)) 23177c478bd9Sstevel@tonic-gate s++; 23187c478bd9Sstevel@tonic-gate if (s == end_s) 23197c478bd9Sstevel@tonic-gate break; 23207c478bd9Sstevel@tonic-gate 23217c478bd9Sstevel@tonic-gate if (!IS_TERMINAL_CHAR(*s)) { 23227c478bd9Sstevel@tonic-gate begin_token = s; 23237c478bd9Sstevel@tonic-gate s = skip_get_dn(begin_token, end_s); 23247c478bd9Sstevel@tonic-gate if (s == NULL) { 23257c478bd9Sstevel@tonic-gate p_error = parse_invalid_dn; 23267c478bd9Sstevel@tonic-gate break; 23277c478bd9Sstevel@tonic-gate } 23287c478bd9Sstevel@tonic-gate if (triple != NULL) { 23297c478bd9Sstevel@tonic-gate search_base = s_strndup(begin_token, 23307c478bd9Sstevel@tonic-gate s - begin_token); 23317c478bd9Sstevel@tonic-gate if (search_base == NULL) 23327c478bd9Sstevel@tonic-gate break; 23337c478bd9Sstevel@tonic-gate } 23347c478bd9Sstevel@tonic-gate while (s < end_s && is_whitespace(*s)) 23357c478bd9Sstevel@tonic-gate s++; 23367c478bd9Sstevel@tonic-gate if (s == end_s) 23377c478bd9Sstevel@tonic-gate break; 23387c478bd9Sstevel@tonic-gate } 23397c478bd9Sstevel@tonic-gate 23407c478bd9Sstevel@tonic-gate if (!IS_TERMINAL_CHAR(*s)) { 23417c478bd9Sstevel@tonic-gate p_error = parse_bad_ldap_item_format; 23427c478bd9Sstevel@tonic-gate break; 23437c478bd9Sstevel@tonic-gate } 23447c478bd9Sstevel@tonic-gate if (*s != QUESTION_MARK) 23457c478bd9Sstevel@tonic-gate break; 23467c478bd9Sstevel@tonic-gate 23477c478bd9Sstevel@tonic-gate s++; 23487c478bd9Sstevel@tonic-gate while (s < end_s && is_whitespace(*s)) 23497c478bd9Sstevel@tonic-gate s++; 23507c478bd9Sstevel@tonic-gate if (s == end_s) 23517c478bd9Sstevel@tonic-gate break; 23527c478bd9Sstevel@tonic-gate 23537c478bd9Sstevel@tonic-gate /* base, one, or sub, or empty value */ 23547c478bd9Sstevel@tonic-gate if (!IS_TERMINAL_CHAR(*s)) { 23557c478bd9Sstevel@tonic-gate if ((s1 = skip_string("base", s, end_s - s)) != NULL) { 23567c478bd9Sstevel@tonic-gate scope = LDAP_SCOPE_BASE; 23577c478bd9Sstevel@tonic-gate } else if ((s1 = skip_string("one", s, end_s - s)) != 23587c478bd9Sstevel@tonic-gate NULL) { 23597c478bd9Sstevel@tonic-gate scope = LDAP_SCOPE_ONELEVEL; 23607c478bd9Sstevel@tonic-gate } else if ((s1 = skip_string("sub", s, end_s - s)) != 23617c478bd9Sstevel@tonic-gate NULL) { 23627c478bd9Sstevel@tonic-gate scope = LDAP_SCOPE_SUBTREE; 23637c478bd9Sstevel@tonic-gate } else if (s + 1 < end_s && *s != QUESTION_MARK) { 23647c478bd9Sstevel@tonic-gate p_error = parse_invalid_scope; 23657c478bd9Sstevel@tonic-gate break; 23667c478bd9Sstevel@tonic-gate } 23677c478bd9Sstevel@tonic-gate if (s1 != NULL) 23687c478bd9Sstevel@tonic-gate s = s1; 23697c478bd9Sstevel@tonic-gate while (s < end_s && is_whitespace(*s)) 23707c478bd9Sstevel@tonic-gate s++; 23717c478bd9Sstevel@tonic-gate } 23727c478bd9Sstevel@tonic-gate 23737c478bd9Sstevel@tonic-gate if (s == end_s) 23747c478bd9Sstevel@tonic-gate break; 23757c478bd9Sstevel@tonic-gate if (*s != QUESTION_MARK) 23767c478bd9Sstevel@tonic-gate break; 23777c478bd9Sstevel@tonic-gate s++; 23787c478bd9Sstevel@tonic-gate while (s < end_s && is_whitespace(*s)) 23797c478bd9Sstevel@tonic-gate s++; 23807c478bd9Sstevel@tonic-gate if (s == end_s || IS_TERMINAL_CHAR(*s)) 23817c478bd9Sstevel@tonic-gate break; 23827c478bd9Sstevel@tonic-gate 23837c478bd9Sstevel@tonic-gate /* LDAP search filter */ 23847c478bd9Sstevel@tonic-gate if (*s == OPEN_PAREN_CHAR) { 23857c478bd9Sstevel@tonic-gate begin_token = s; 23867c478bd9Sstevel@tonic-gate end_token = end_s; 23877c478bd9Sstevel@tonic-gate s = get_ldap_filter(&begin_token, &end_token); 23887c478bd9Sstevel@tonic-gate if (s == NULL) 23897c478bd9Sstevel@tonic-gate break; 23907c478bd9Sstevel@tonic-gate s = end_token; 23917c478bd9Sstevel@tonic-gate element = get_ldap_filter_element(begin_token, end_token); 23927c478bd9Sstevel@tonic-gate if (element != NULL) 23937c478bd9Sstevel@tonic-gate break; 23947c478bd9Sstevel@tonic-gate } else { 23957c478bd9Sstevel@tonic-gate begin_token = s; 23967c478bd9Sstevel@tonic-gate end_token = end_s; 23977c478bd9Sstevel@tonic-gate s = get_ava_list(&begin_token, &end_token, TRUE); 23987c478bd9Sstevel@tonic-gate if (s == NULL) 23997c478bd9Sstevel@tonic-gate break; 24007c478bd9Sstevel@tonic-gate s = end_token; 24017c478bd9Sstevel@tonic-gate } 24027c478bd9Sstevel@tonic-gate if (triple != NULL) 24037c478bd9Sstevel@tonic-gate filter = s_strndup(begin_token, s - begin_token); 24047c478bd9Sstevel@tonic-gate if (p_error == no_parse_error) 24057c478bd9Sstevel@tonic-gate break; 24067c478bd9Sstevel@tonic-gate } 24077c478bd9Sstevel@tonic-gate if (p_error == no_parse_error && triple != NULL) { 24087c478bd9Sstevel@tonic-gate triple->base = search_base; 24097c478bd9Sstevel@tonic-gate triple->scope = scope; 24107c478bd9Sstevel@tonic-gate triple->attrs = filter; 24117c478bd9Sstevel@tonic-gate triple->element = element; 24127c478bd9Sstevel@tonic-gate element = NULL; 24137c478bd9Sstevel@tonic-gate filter = NULL; 24147c478bd9Sstevel@tonic-gate search_base = NULL; 24157c478bd9Sstevel@tonic-gate } 24167c478bd9Sstevel@tonic-gate 24177c478bd9Sstevel@tonic-gate if (search_base != NULL) 24187c478bd9Sstevel@tonic-gate free(search_base); 24197c478bd9Sstevel@tonic-gate if (filter != NULL) 24207c478bd9Sstevel@tonic-gate free(filter); 24217c478bd9Sstevel@tonic-gate if (element != NULL) { 24227c478bd9Sstevel@tonic-gate free_mapping_element(element); 24237c478bd9Sstevel@tonic-gate free(element); 24247c478bd9Sstevel@tonic-gate } 24257c478bd9Sstevel@tonic-gate return (p_error == no_parse_error ? s : NULL); 24267c478bd9Sstevel@tonic-gate } 24277c478bd9Sstevel@tonic-gate 24287c478bd9Sstevel@tonic-gate /* 24297c478bd9Sstevel@tonic-gate * FUNCTION: get_mapping_format 24307c478bd9Sstevel@tonic-gate * 24317c478bd9Sstevel@tonic-gate * Get the __nis_mapping_format_t from the string 24327c478bd9Sstevel@tonic-gate * 24337c478bd9Sstevel@tonic-gate * RETURN VALUE: FALSE if error 24347c478bd9Sstevel@tonic-gate * TRUE if __nis_mapping_format_t returned 24357c478bd9Sstevel@tonic-gate * 24367c478bd9Sstevel@tonic-gate * INPUT: the format string 24377c478bd9Sstevel@tonic-gate */ 24387c478bd9Sstevel@tonic-gate 24397c478bd9Sstevel@tonic-gate static bool_t 24407c478bd9Sstevel@tonic-gate get_mapping_format( 24417c478bd9Sstevel@tonic-gate const char *fmt_string, 24427c478bd9Sstevel@tonic-gate __nis_mapping_format_t **fmt, 24437c478bd9Sstevel@tonic-gate int *nfmt, 24447c478bd9Sstevel@tonic-gate int *numItems, 24457c478bd9Sstevel@tonic-gate bool_t print_mapping) 24467c478bd9Sstevel@tonic-gate { 24477c478bd9Sstevel@tonic-gate const char *f = fmt_string; 24487c478bd9Sstevel@tonic-gate const char *ef; 24497c478bd9Sstevel@tonic-gate __nis_mapping_format_t *b; 24507c478bd9Sstevel@tonic-gate __nis_mapping_format_t *base = NULL; 24517c478bd9Sstevel@tonic-gate int n = 0; 24527c478bd9Sstevel@tonic-gate int nItems = 0; 24537c478bd9Sstevel@tonic-gate 24547c478bd9Sstevel@tonic-gate f = fmt_string; 24557c478bd9Sstevel@tonic-gate ef = f + strlen(f); 24567c478bd9Sstevel@tonic-gate base = (__nis_mapping_format_t *) 24577c478bd9Sstevel@tonic-gate s_calloc(1, sizeof (__nis_mapping_format_t)); 24587c478bd9Sstevel@tonic-gate 24597c478bd9Sstevel@tonic-gate if (base == NULL) 24607c478bd9Sstevel@tonic-gate return (FALSE); 24617c478bd9Sstevel@tonic-gate base->type = mmt_begin; 24627c478bd9Sstevel@tonic-gate n++; 24637c478bd9Sstevel@tonic-gate 24647c478bd9Sstevel@tonic-gate for (;;) { 24657c478bd9Sstevel@tonic-gate b = (__nis_mapping_format_t *)s_realloc( 24667c478bd9Sstevel@tonic-gate base, (n + 1) * sizeof (__nis_mapping_format_t)); 24677c478bd9Sstevel@tonic-gate 24687c478bd9Sstevel@tonic-gate if (b == NULL) 24697c478bd9Sstevel@tonic-gate break; 24707c478bd9Sstevel@tonic-gate base = b; 24717c478bd9Sstevel@tonic-gate base[n].type = mmt_end; 24727c478bd9Sstevel@tonic-gate if (f == ef) { 24737c478bd9Sstevel@tonic-gate if (nfmt) 24747c478bd9Sstevel@tonic-gate *nfmt = n + 1; 24757c478bd9Sstevel@tonic-gate *fmt = base; 24767c478bd9Sstevel@tonic-gate if (numItems) 24777c478bd9Sstevel@tonic-gate *numItems = nItems; 24787c478bd9Sstevel@tonic-gate return (TRUE); 24797c478bd9Sstevel@tonic-gate } 24807c478bd9Sstevel@tonic-gate if (print_mapping) 24817c478bd9Sstevel@tonic-gate f = get_next_print_format_item(f, ef, &base[n]); 24827c478bd9Sstevel@tonic-gate else 24837c478bd9Sstevel@tonic-gate f = get_next_extract_format_item(f, ef, &base[n]); 24847c478bd9Sstevel@tonic-gate 24857c478bd9Sstevel@tonic-gate 24867c478bd9Sstevel@tonic-gate if (f == NULL) 24877c478bd9Sstevel@tonic-gate break; 24887c478bd9Sstevel@tonic-gate if (base[n].type == mmt_item || 24897c478bd9Sstevel@tonic-gate base[n].type == mmt_berstring) 24907c478bd9Sstevel@tonic-gate nItems++; 24917c478bd9Sstevel@tonic-gate n++; 24927c478bd9Sstevel@tonic-gate } 24937c478bd9Sstevel@tonic-gate if (base != NULL) 24947c478bd9Sstevel@tonic-gate free_mapping_format(base); 24957c478bd9Sstevel@tonic-gate return (FALSE); 24967c478bd9Sstevel@tonic-gate } 24977c478bd9Sstevel@tonic-gate 24987c478bd9Sstevel@tonic-gate /* 24997c478bd9Sstevel@tonic-gate * FUNCTION: getIndex 25007c478bd9Sstevel@tonic-gate * 25017c478bd9Sstevel@tonic-gate * Returns a string containing the index 25027c478bd9Sstevel@tonic-gate * 25037c478bd9Sstevel@tonic-gate * RETURN VALUE: NULL if error 25047c478bd9Sstevel@tonic-gate * a string containing the index 25057c478bd9Sstevel@tonic-gate * 25067c478bd9Sstevel@tonic-gate * INPUT: attribute containing the index 25077c478bd9Sstevel@tonic-gate */ 25087c478bd9Sstevel@tonic-gate 25097c478bd9Sstevel@tonic-gate static char * 25107c478bd9Sstevel@tonic-gate getIndex(const char **s_cur, const char *s_end) 25117c478bd9Sstevel@tonic-gate { 25127c478bd9Sstevel@tonic-gate const char *s = *s_cur + 1; 25137c478bd9Sstevel@tonic-gate const char *s1; 25147c478bd9Sstevel@tonic-gate char *s_index; 25157c478bd9Sstevel@tonic-gate char *s_index1; 25167c478bd9Sstevel@tonic-gate char *s_index_end; 25177c478bd9Sstevel@tonic-gate int n_brackets = 1; 25187c478bd9Sstevel@tonic-gate bool_t in_quotes = FALSE; 25197c478bd9Sstevel@tonic-gate char *index = NULL; 25207c478bd9Sstevel@tonic-gate 25217c478bd9Sstevel@tonic-gate while (s < s_end && is_whitespace(*s)) 25227c478bd9Sstevel@tonic-gate s++; 25237c478bd9Sstevel@tonic-gate for (s1 = s; s1 < s_end; s1++) { 25247c478bd9Sstevel@tonic-gate if (*s1 == ESCAPE_CHAR) 25257c478bd9Sstevel@tonic-gate s1++; 25267c478bd9Sstevel@tonic-gate else if (*s1 == DOUBLE_QUOTE_CHAR) { 25277c478bd9Sstevel@tonic-gate in_quotes = !in_quotes; 25287c478bd9Sstevel@tonic-gate } else if (in_quotes) 25297c478bd9Sstevel@tonic-gate ; 25307c478bd9Sstevel@tonic-gate else if (*s1 == CLOSE_BRACKET) { 25317c478bd9Sstevel@tonic-gate if (--n_brackets == 0) 25327c478bd9Sstevel@tonic-gate break; 25337c478bd9Sstevel@tonic-gate } else if (*s1 == OPEN_BRACKET) 25347c478bd9Sstevel@tonic-gate n_brackets++; 25357c478bd9Sstevel@tonic-gate } 25367c478bd9Sstevel@tonic-gate 25377c478bd9Sstevel@tonic-gate if (n_brackets == 0) { 25387c478bd9Sstevel@tonic-gate index = s_strndup(s, s1 - s); 25397c478bd9Sstevel@tonic-gate if (index != NULL) { 25407c478bd9Sstevel@tonic-gate s_index_end = index + (s1 - s); 25417c478bd9Sstevel@tonic-gate s_index1 = index; 25427c478bd9Sstevel@tonic-gate for (s_index = index; s_index < s_index_end; 25437c478bd9Sstevel@tonic-gate s_index++) { 25447c478bd9Sstevel@tonic-gate if (*s_index == ESCAPE_CHAR) { 25457c478bd9Sstevel@tonic-gate *s_index1++ = *s_index++; 25467c478bd9Sstevel@tonic-gate } else if (*s_index == DOUBLE_QUOTE_CHAR) { 25477c478bd9Sstevel@tonic-gate in_quotes = !in_quotes; 25487c478bd9Sstevel@tonic-gate } else if (!in_quotes && 25497c478bd9Sstevel@tonic-gate is_whitespace(*s_index)) { 25507c478bd9Sstevel@tonic-gate continue; 25517c478bd9Sstevel@tonic-gate } 25527c478bd9Sstevel@tonic-gate *s_index1++ = *s_index; 25537c478bd9Sstevel@tonic-gate } 25547c478bd9Sstevel@tonic-gate *s_index1 = *s_index; 25557c478bd9Sstevel@tonic-gate 25567c478bd9Sstevel@tonic-gate s = s1 + 1; 25577c478bd9Sstevel@tonic-gate 25587c478bd9Sstevel@tonic-gate while (s < s_end && is_whitespace(*s)) 25597c478bd9Sstevel@tonic-gate s++; 25607c478bd9Sstevel@tonic-gate *s_cur = s; 25617c478bd9Sstevel@tonic-gate } 25627c478bd9Sstevel@tonic-gate } else 25637c478bd9Sstevel@tonic-gate p_error = parse_mismatched_brackets; 25647c478bd9Sstevel@tonic-gate 25657c478bd9Sstevel@tonic-gate return (index); 25667c478bd9Sstevel@tonic-gate } 25677c478bd9Sstevel@tonic-gate 25687c478bd9Sstevel@tonic-gate /* 25697c478bd9Sstevel@tonic-gate * FUNCTION: parse_index 25707c478bd9Sstevel@tonic-gate * 25717c478bd9Sstevel@tonic-gate * Parse attribute string to get __nis_index_t 25727c478bd9Sstevel@tonic-gate * 25737c478bd9Sstevel@tonic-gate * RETURN VALUE: FALSE if error 25747c478bd9Sstevel@tonic-gate * TRUE if __nis_index_t returned 25757c478bd9Sstevel@tonic-gate * 25767c478bd9Sstevel@tonic-gate * INPUT: the attribute value to parse 25777c478bd9Sstevel@tonic-gate */ 25787c478bd9Sstevel@tonic-gate 25797c478bd9Sstevel@tonic-gate bool_t 25807c478bd9Sstevel@tonic-gate parse_index(const char *s, const char *end_s, __nis_index_t *index) 25817c478bd9Sstevel@tonic-gate { 25827c478bd9Sstevel@tonic-gate const char *begin_token; 25837c478bd9Sstevel@tonic-gate const char *end_token; 25847c478bd9Sstevel@tonic-gate char *name_str = NULL; 25857c478bd9Sstevel@tonic-gate char **name; 25867c478bd9Sstevel@tonic-gate char *fmt_string = NULL; 25877c478bd9Sstevel@tonic-gate __nis_mapping_format_t *v = NULL; 25887c478bd9Sstevel@tonic-gate __nis_mapping_format_t **value; 25897c478bd9Sstevel@tonic-gate token_type t; 25907c478bd9Sstevel@tonic-gate int n = 0; 25917c478bd9Sstevel@tonic-gate 25927c478bd9Sstevel@tonic-gate if (index != NULL) 25937c478bd9Sstevel@tonic-gate (void) memset(index, 0, sizeof (*index)); 25947c478bd9Sstevel@tonic-gate 25957c478bd9Sstevel@tonic-gate while (s < end_s) { 25967c478bd9Sstevel@tonic-gate if (n > 0) { 25977c478bd9Sstevel@tonic-gate s = skip_token(s, end_s, comma_token); 25987c478bd9Sstevel@tonic-gate if (s == NULL) { 25997c478bd9Sstevel@tonic-gate p_error = parse_bad_index_format; 26007c478bd9Sstevel@tonic-gate break; 26017c478bd9Sstevel@tonic-gate } 26027c478bd9Sstevel@tonic-gate } 26037c478bd9Sstevel@tonic-gate begin_token = s; 26047c478bd9Sstevel@tonic-gate end_token = end_s; 26057c478bd9Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t); 26067c478bd9Sstevel@tonic-gate if (s == NULL) 26077c478bd9Sstevel@tonic-gate break; 26087c478bd9Sstevel@tonic-gate if (t != string_token) { 26097c478bd9Sstevel@tonic-gate p_error = parse_bad_index_format; 26107c478bd9Sstevel@tonic-gate break; 26117c478bd9Sstevel@tonic-gate } 26127c478bd9Sstevel@tonic-gate s = skip_token(s, end_s, equal_token); 26137c478bd9Sstevel@tonic-gate if (s == NULL) { 26147c478bd9Sstevel@tonic-gate p_error = parse_bad_index_format; 26157c478bd9Sstevel@tonic-gate break; 26167c478bd9Sstevel@tonic-gate } 26177c478bd9Sstevel@tonic-gate if (index != NULL) { 26187c478bd9Sstevel@tonic-gate name_str = s_strndup_esc(begin_token, 26197c478bd9Sstevel@tonic-gate end_token - begin_token); 26207c478bd9Sstevel@tonic-gate if (name_str == NULL) 26217c478bd9Sstevel@tonic-gate break; 26227c478bd9Sstevel@tonic-gate } 26237c478bd9Sstevel@tonic-gate begin_token = s; 26247c478bd9Sstevel@tonic-gate end_token = end_s; 26257c478bd9Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t); 26267c478bd9Sstevel@tonic-gate if (s == NULL) 26277c478bd9Sstevel@tonic-gate break; 26287c478bd9Sstevel@tonic-gate if (t != string_token && t != quoted_string_token) { 26297c478bd9Sstevel@tonic-gate p_error = parse_bad_index_format; 26307c478bd9Sstevel@tonic-gate break; 26317c478bd9Sstevel@tonic-gate } 26327c478bd9Sstevel@tonic-gate fmt_string = s_strndup(begin_token, end_token - begin_token); 26337c478bd9Sstevel@tonic-gate if (fmt_string == NULL) 26347c478bd9Sstevel@tonic-gate break; 26357c478bd9Sstevel@tonic-gate if (!get_mapping_format(fmt_string, &v, NULL, NULL, FALSE)) 26367c478bd9Sstevel@tonic-gate break; 26377c478bd9Sstevel@tonic-gate free(fmt_string); 26387c478bd9Sstevel@tonic-gate fmt_string = NULL; 26397c478bd9Sstevel@tonic-gate if (index != NULL) { 26407c478bd9Sstevel@tonic-gate name = s_realloc(index->name, 26417c478bd9Sstevel@tonic-gate (n + 1) * sizeof (char *)); 26427c478bd9Sstevel@tonic-gate if (name == NULL) 26437c478bd9Sstevel@tonic-gate break; 26447c478bd9Sstevel@tonic-gate value = s_realloc(index->value, 26457c478bd9Sstevel@tonic-gate (n + 1) * sizeof (__nis_mapping_format_t *)); 26467c478bd9Sstevel@tonic-gate if (value == NULL) 26477c478bd9Sstevel@tonic-gate break; 26487c478bd9Sstevel@tonic-gate name[n] = name_str; 26497c478bd9Sstevel@tonic-gate name_str = NULL; 26507c478bd9Sstevel@tonic-gate value[n] = v; 26517c478bd9Sstevel@tonic-gate v = NULL; 26527c478bd9Sstevel@tonic-gate index->numIndexes = ++n; 26537c478bd9Sstevel@tonic-gate index->name = name; 26547c478bd9Sstevel@tonic-gate index->value = value; 26557c478bd9Sstevel@tonic-gate } else if (v != NULL) { 26567c478bd9Sstevel@tonic-gate free_mapping_format(v); 26577c478bd9Sstevel@tonic-gate v = NULL; 26587c478bd9Sstevel@tonic-gate } 26597c478bd9Sstevel@tonic-gate } 26607c478bd9Sstevel@tonic-gate if (p_error != no_parse_error) { 26617c478bd9Sstevel@tonic-gate if (name_str != NULL) 26627c478bd9Sstevel@tonic-gate free(name_str); 26637c478bd9Sstevel@tonic-gate if (v != NULL) 26647c478bd9Sstevel@tonic-gate free_mapping_format(v); 26657c478bd9Sstevel@tonic-gate if (fmt_string != NULL) 26667c478bd9Sstevel@tonic-gate free(fmt_string); 26677c478bd9Sstevel@tonic-gate if (index != NULL) 26687c478bd9Sstevel@tonic-gate free_index(index); 26697c478bd9Sstevel@tonic-gate } 26707c478bd9Sstevel@tonic-gate return (p_error != no_parse_error); 26717c478bd9Sstevel@tonic-gate } 26727c478bd9Sstevel@tonic-gate 26737c478bd9Sstevel@tonic-gate /* 26747c478bd9Sstevel@tonic-gate * FUNCTION: get_deleteDisp 26757c478bd9Sstevel@tonic-gate * 26767c478bd9Sstevel@tonic-gate * Parse deleteDisp. Sets p_error if an error occurred. 26777c478bd9Sstevel@tonic-gate * 26787c478bd9Sstevel@tonic-gate * RETURN VALUE: TRUE on success 26797c478bd9Sstevel@tonic-gate * FAILURE on failure 26807c478bd9Sstevel@tonic-gate * 26817c478bd9Sstevel@tonic-gate * INPUT: begin and end of string and __nis_object_dn_t 26827c478bd9Sstevel@tonic-gate */ 26837c478bd9Sstevel@tonic-gate 26847c478bd9Sstevel@tonic-gate static bool_t 26857c478bd9Sstevel@tonic-gate get_deleteDisp(const char *s_begin, const char *s_end, 26867c478bd9Sstevel@tonic-gate __nis_object_dn_t *obj_dn) 26877c478bd9Sstevel@tonic-gate { 26887c478bd9Sstevel@tonic-gate /* 26897c478bd9Sstevel@tonic-gate * deleteDisp: "always" | perDbId | "never" 26907c478bd9Sstevel@tonic-gate * perDbId: "dbid" "=" delDatabaseId 26917c478bd9Sstevel@tonic-gate */ 26927c478bd9Sstevel@tonic-gate 26937c478bd9Sstevel@tonic-gate if (same_string("always", s_begin, s_end - s_begin)) { 26947c478bd9Sstevel@tonic-gate obj_dn->delDisp = dd_always; 26957c478bd9Sstevel@tonic-gate } else if (same_string("never", s_begin, s_end - s_begin)) { 26967c478bd9Sstevel@tonic-gate obj_dn->delDisp = dd_never; 26977c478bd9Sstevel@tonic-gate } else if ((s_begin = skip_string("dbid", s_begin, s_end - s_begin)) 26987c478bd9Sstevel@tonic-gate != NULL) { 26997c478bd9Sstevel@tonic-gate obj_dn->delDisp = dd_perDbId; 27007c478bd9Sstevel@tonic-gate while (s_begin < s_end && is_whitespace(*s_begin)) 27017c478bd9Sstevel@tonic-gate s_begin++; 27027c478bd9Sstevel@tonic-gate if (s_begin == s_end || *s_begin != EQUAL_CHAR) { 27037c478bd9Sstevel@tonic-gate p_error = parse_object_dn_syntax_error; 27047c478bd9Sstevel@tonic-gate } else { 27057c478bd9Sstevel@tonic-gate s_begin++; 27067c478bd9Sstevel@tonic-gate while (s_begin < s_end && is_whitespace(*s_begin)) 27077c478bd9Sstevel@tonic-gate s_begin++; 27087c478bd9Sstevel@tonic-gate while (s_begin < s_end && is_whitespace(s_end[-1])) 27097c478bd9Sstevel@tonic-gate s_end--; 27107c478bd9Sstevel@tonic-gate if (s_begin == s_end) { 27117c478bd9Sstevel@tonic-gate p_error = parse_object_dn_syntax_error; 27127c478bd9Sstevel@tonic-gate } else { 27137c478bd9Sstevel@tonic-gate obj_dn->dbIdName = 27147c478bd9Sstevel@tonic-gate s_strndup(s_begin, s_end - s_begin); 27157c478bd9Sstevel@tonic-gate } 27167c478bd9Sstevel@tonic-gate } 27177c478bd9Sstevel@tonic-gate } else { 27187c478bd9Sstevel@tonic-gate p_error = parse_object_dn_syntax_error; 27197c478bd9Sstevel@tonic-gate } 27207c478bd9Sstevel@tonic-gate return (p_error == no_parse_error); 27217c478bd9Sstevel@tonic-gate } 2722