1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * CDDL HEADER START
3*0Sstevel@tonic-gate *
4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*0Sstevel@tonic-gate * with the License.
8*0Sstevel@tonic-gate *
9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate * and limitations under the License.
13*0Sstevel@tonic-gate *
14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate *
20*0Sstevel@tonic-gate * CDDL HEADER END
21*0Sstevel@tonic-gate */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate * Copyright 2001-2003 Sun Microsystems, Inc. All rights reserved.
24*0Sstevel@tonic-gate * Use is subject to license terms.
25*0Sstevel@tonic-gate */
26*0Sstevel@tonic-gate
27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
28*0Sstevel@tonic-gate
29*0Sstevel@tonic-gate #include <stdio.h>
30*0Sstevel@tonic-gate #include <string.h>
31*0Sstevel@tonic-gate #include <stdlib.h>
32*0Sstevel@tonic-gate #include <ctype.h>
33*0Sstevel@tonic-gate #include <fcntl.h>
34*0Sstevel@tonic-gate #include <unistd.h>
35*0Sstevel@tonic-gate #include <locale.h>
36*0Sstevel@tonic-gate
37*0Sstevel@tonic-gate #include "ldap_parse.h"
38*0Sstevel@tonic-gate #include "nis_parse_ldap_conf.h"
39*0Sstevel@tonic-gate
40*0Sstevel@tonic-gate /* other attribute functions */
41*0Sstevel@tonic-gate static char *getIndex(const char **s_cur, const char *end_s);
42*0Sstevel@tonic-gate static bool_t get_ttls(const char *s, const char *s_end,
43*0Sstevel@tonic-gate __nis_table_mapping_t *t_mapping);
44*0Sstevel@tonic-gate static __nis_object_dn_t *parse_object_dn(const char *s, const char *end);
45*0Sstevel@tonic-gate static int parse_name_fields(const char *name_s, const char *name_s_end,
46*0Sstevel@tonic-gate __nis_table_mapping_t *t_mapping);
47*0Sstevel@tonic-gate static void get_mapping_rule(const char *s, int len,
48*0Sstevel@tonic-gate __nis_table_mapping_t *tbl, bool_t to_ldap);
49*0Sstevel@tonic-gate static bool_t get_deleteDisp(const char *s_begin, const char *s_end,
50*0Sstevel@tonic-gate __nis_object_dn_t *obj_dn);
51*0Sstevel@tonic-gate
52*0Sstevel@tonic-gate /* mapping rule functions */
53*0Sstevel@tonic-gate static const char *get_lhs(const char *s, const char *end_s,
54*0Sstevel@tonic-gate __nis_mapping_rlhs_t *lhs, __nis_mapping_item_type_t item_type);
55*0Sstevel@tonic-gate static const char *get_lhs_match(const char *s, const char *end_s,
56*0Sstevel@tonic-gate __nis_mapping_rlhs_t *lhs, __nis_mapping_item_type_t item_type);
57*0Sstevel@tonic-gate static const char *get_lhs_paren_item(const char *s, const char *end_s,
58*0Sstevel@tonic-gate __nis_mapping_rlhs_t *lhs, __nis_mapping_item_type_t item_type);
59*0Sstevel@tonic-gate static const char *get_rhs(const char *s, const char *end_s,
60*0Sstevel@tonic-gate __nis_mapping_rlhs_t *lhs, __nis_mapping_item_type_t item_type);
61*0Sstevel@tonic-gate static const char *get_mapping_item(const char *s, const char *end_s,
62*0Sstevel@tonic-gate __nis_mapping_item_t *item, __nis_mapping_item_type_t type);
63*0Sstevel@tonic-gate static const char *get_print_mapping_element(const char *s,
64*0Sstevel@tonic-gate const char *end_s, char *fmt_string, __nis_mapping_element_t *e,
65*0Sstevel@tonic-gate __nis_mapping_item_type_t item_type);
66*0Sstevel@tonic-gate static const char *get_subElement(const char *s, const char *end_s,
67*0Sstevel@tonic-gate __nis_mapping_sub_element_t *subelement,
68*0Sstevel@tonic-gate __nis_mapping_item_type_t type);
69*0Sstevel@tonic-gate static bool_t get_mapping_format(const char *fmt_string,
70*0Sstevel@tonic-gate __nis_mapping_format_t **fmt, int *nfmt, int *numItems,
71*0Sstevel@tonic-gate bool_t print_mapping);
72*0Sstevel@tonic-gate extern __yp_domain_context_t ypDomains;
73*0Sstevel@tonic-gate
74*0Sstevel@tonic-gate /*
75*0Sstevel@tonic-gate * FUNCTION: add_mapping_attribute
76*0Sstevel@tonic-gate *
77*0Sstevel@tonic-gate * Adds the attribute value to __nis_table_mapping_t
78*0Sstevel@tonic-gate * if the value is not yet set for the given database.
79*0Sstevel@tonic-gate *
80*0Sstevel@tonic-gate * RETURN VALUE: 0 on success, -1 on failure
81*0Sstevel@tonic-gate *
82*0Sstevel@tonic-gate * INPUT: attribute number and value
83*0Sstevel@tonic-gate */
84*0Sstevel@tonic-gate
85*0Sstevel@tonic-gate int
add_mapping_attribute(config_key attrib_num,const char * attrib_val,int attrib_len,__nis_table_mapping_t ** table_mapping)86*0Sstevel@tonic-gate add_mapping_attribute(
87*0Sstevel@tonic-gate config_key attrib_num,
88*0Sstevel@tonic-gate const char *attrib_val,
89*0Sstevel@tonic-gate int attrib_len,
90*0Sstevel@tonic-gate __nis_table_mapping_t **table_mapping)
91*0Sstevel@tonic-gate {
92*0Sstevel@tonic-gate const char *s;
93*0Sstevel@tonic-gate const char *attrib_end;
94*0Sstevel@tonic-gate const char *db_id_end;
95*0Sstevel@tonic-gate const char *begin_token;
96*0Sstevel@tonic-gate const char *end_token;
97*0Sstevel@tonic-gate char *index_string;
98*0Sstevel@tonic-gate __nis_object_dn_t *objectDN;
99*0Sstevel@tonic-gate __nis_table_mapping_t *t_mapping;
100*0Sstevel@tonic-gate __nis_table_mapping_t *t;
101*0Sstevel@tonic-gate
102*0Sstevel@tonic-gate bool_t new_mapping = FALSE;
103*0Sstevel@tonic-gate int nm;
104*0Sstevel@tonic-gate char *tmp_dbId;
105*0Sstevel@tonic-gate
106*0Sstevel@tonic-gate attrib_end = attrib_val + attrib_len;
107*0Sstevel@tonic-gate for (s = attrib_val; s < attrib_end; s++)
108*0Sstevel@tonic-gate if (*s == COLON_CHAR)
109*0Sstevel@tonic-gate break;
110*0Sstevel@tonic-gate
111*0Sstevel@tonic-gate if (s == attrib_end || *attrib_val == COLON_CHAR) {
112*0Sstevel@tonic-gate p_error = parse_unexpected_data_end_rule;
113*0Sstevel@tonic-gate return (-1);
114*0Sstevel@tonic-gate }
115*0Sstevel@tonic-gate
116*0Sstevel@tonic-gate db_id_end = s;
117*0Sstevel@tonic-gate while (s > attrib_val && is_whitespace(s[-1]))
118*0Sstevel@tonic-gate s--;
119*0Sstevel@tonic-gate
120*0Sstevel@tonic-gate if (s == attrib_val) {
121*0Sstevel@tonic-gate p_error = parse_unexpected_data_end_rule;
122*0Sstevel@tonic-gate return (-1);
123*0Sstevel@tonic-gate }
124*0Sstevel@tonic-gate
125*0Sstevel@tonic-gate if (yp2ldap) {
126*0Sstevel@tonic-gate tmp_dbId = s_strndup(attrib_val, s - attrib_val);
127*0Sstevel@tonic-gate if (tmp_dbId == NULL) {
128*0Sstevel@tonic-gate p_error = parse_no_mem_error;
129*0Sstevel@tonic-gate return (-1);
130*0Sstevel@tonic-gate }
131*0Sstevel@tonic-gate if (strchr(tmp_dbId, COMMA_CHAR)) {
132*0Sstevel@tonic-gate /* domain explicitly specified */
133*0Sstevel@tonic-gate nm = check_domain_specific_order(tmp_dbId,
134*0Sstevel@tonic-gate attrib_num, *table_mapping, &ypDomains);
135*0Sstevel@tonic-gate /*
136*0Sstevel@tonic-gate * No logging is needed here, as
137*0Sstevel@tonic-gate * check_domain_specific_order
138*0Sstevel@tonic-gate * will log any appropriate errors.
139*0Sstevel@tonic-gate */
140*0Sstevel@tonic-gate if (nm != 0) {
141*0Sstevel@tonic-gate free(tmp_dbId);
142*0Sstevel@tonic-gate return (-1);
143*0Sstevel@tonic-gate }
144*0Sstevel@tonic-gate }
145*0Sstevel@tonic-gate free(tmp_dbId);
146*0Sstevel@tonic-gate }
147*0Sstevel@tonic-gate
148*0Sstevel@tonic-gate if ((t_mapping = find_table_mapping(attrib_val,
149*0Sstevel@tonic-gate s - attrib_val, *table_mapping)) == NULL) {
150*0Sstevel@tonic-gate /* No mapping with this id, create one */
151*0Sstevel@tonic-gate t_mapping = (__nis_table_mapping_t *)
152*0Sstevel@tonic-gate s_calloc(1, sizeof (__nis_table_mapping_t));
153*0Sstevel@tonic-gate
154*0Sstevel@tonic-gate if (t_mapping == NULL) {
155*0Sstevel@tonic-gate p_error = parse_no_mem_error;
156*0Sstevel@tonic-gate return (-1);
157*0Sstevel@tonic-gate }
158*0Sstevel@tonic-gate (void) initialize_table_mapping(t_mapping);
159*0Sstevel@tonic-gate
160*0Sstevel@tonic-gate /* dbId is the label before the colon */
161*0Sstevel@tonic-gate t_mapping->dbId = s_strndup(attrib_val, s - attrib_val);
162*0Sstevel@tonic-gate if (t_mapping->dbId == NULL) {
163*0Sstevel@tonic-gate p_error = parse_no_mem_error;
164*0Sstevel@tonic-gate free(t_mapping);
165*0Sstevel@tonic-gate return (-1);
166*0Sstevel@tonic-gate }
167*0Sstevel@tonic-gate new_mapping = TRUE;
168*0Sstevel@tonic-gate } else {
169*0Sstevel@tonic-gate /* a table mapping already exists, use it */
170*0Sstevel@tonic-gate new_mapping = FALSE;
171*0Sstevel@tonic-gate }
172*0Sstevel@tonic-gate
173*0Sstevel@tonic-gate s = db_id_end + 1;
174*0Sstevel@tonic-gate while (s < attrib_end && is_whitespace(*s))
175*0Sstevel@tonic-gate s++;
176*0Sstevel@tonic-gate
177*0Sstevel@tonic-gate switch (attrib_num) {
178*0Sstevel@tonic-gate case key_yp_map_flags:
179*0Sstevel@tonic-gate if (t_mapping->usedns_flag != 0 ||
180*0Sstevel@tonic-gate t_mapping->securemap_flag != 0) {
181*0Sstevel@tonic-gate warn_duplicate_map(t_mapping->dbId,
182*0Sstevel@tonic-gate attrib_num);
183*0Sstevel@tonic-gate break;
184*0Sstevel@tonic-gate }
185*0Sstevel@tonic-gate while (is_whitespace(*s) && s < attrib_end)
186*0Sstevel@tonic-gate s++;
187*0Sstevel@tonic-gate while (s < attrib_end) {
188*0Sstevel@tonic-gate if (s < attrib_end && *s == 'b')
189*0Sstevel@tonic-gate t_mapping->usedns_flag = 1;
190*0Sstevel@tonic-gate if (s < attrib_end && *s == 's')
191*0Sstevel@tonic-gate t_mapping->securemap_flag = 1;
192*0Sstevel@tonic-gate s++;
193*0Sstevel@tonic-gate }
194*0Sstevel@tonic-gate break;
195*0Sstevel@tonic-gate case key_yp_comment_char:
196*0Sstevel@tonic-gate if (t_mapping->commentChar !=
197*0Sstevel@tonic-gate DEFAULT_COMMENT_CHAR) {
198*0Sstevel@tonic-gate warn_duplicate_map(t_mapping->dbId, attrib_num);
199*0Sstevel@tonic-gate break;
200*0Sstevel@tonic-gate }
201*0Sstevel@tonic-gate while (is_whitespace(*s) && s < attrib_end)
202*0Sstevel@tonic-gate s++;
203*0Sstevel@tonic-gate if (s < attrib_end && (s+1) < attrib_end &&
204*0Sstevel@tonic-gate (s+2) <= attrib_end) {
205*0Sstevel@tonic-gate while (is_whitespace(attrib_end[-1]))
206*0Sstevel@tonic-gate attrib_end--;
207*0Sstevel@tonic-gate while (*s != SINGLE_QUOTE_CHAR)
208*0Sstevel@tonic-gate s++;
209*0Sstevel@tonic-gate if (*s == SINGLE_QUOTE_CHAR &&
210*0Sstevel@tonic-gate *(s+2) == SINGLE_QUOTE_CHAR) {
211*0Sstevel@tonic-gate t_mapping->commentChar = *(s+1);
212*0Sstevel@tonic-gate } else if (*s == SINGLE_QUOTE_CHAR &&
213*0Sstevel@tonic-gate *(s+1) == SINGLE_QUOTE_CHAR) {
214*0Sstevel@tonic-gate t_mapping->commentChar = NULL;
215*0Sstevel@tonic-gate } else {
216*0Sstevel@tonic-gate /* anything else is an error */
217*0Sstevel@tonic-gate p_error = parse_bad_yp_comment_error;
218*0Sstevel@tonic-gate }
219*0Sstevel@tonic-gate break;
220*0Sstevel@tonic-gate } else {
221*0Sstevel@tonic-gate p_error = parse_bad_yp_comment_error;
222*0Sstevel@tonic-gate break;
223*0Sstevel@tonic-gate }
224*0Sstevel@tonic-gate case key_yp_repeated_field_separators:
225*0Sstevel@tonic-gate while (s < attrib_end && is_whitespace(*s))
226*0Sstevel@tonic-gate s++;
227*0Sstevel@tonic-gate if (s < attrib_end) {
228*0Sstevel@tonic-gate while (is_whitespace(attrib_end[-1]))
229*0Sstevel@tonic-gate attrib_end--;
230*0Sstevel@tonic-gate while (s < attrib_end &&
231*0Sstevel@tonic-gate *s != DOUBLE_QUOTE_CHAR)
232*0Sstevel@tonic-gate s++;
233*0Sstevel@tonic-gate s++;
234*0Sstevel@tonic-gate begin_token = s;
235*0Sstevel@tonic-gate while (s < attrib_end &&
236*0Sstevel@tonic-gate *s != DOUBLE_QUOTE_CHAR) {
237*0Sstevel@tonic-gate if (*s == ESCAPE_CHAR)
238*0Sstevel@tonic-gate s++;
239*0Sstevel@tonic-gate s++;
240*0Sstevel@tonic-gate }
241*0Sstevel@tonic-gate t_mapping->separatorStr =
242*0Sstevel@tonic-gate s_strndup(begin_token, s - begin_token);
243*0Sstevel@tonic-gate if (t_mapping->separatorStr == NULL)
244*0Sstevel@tonic-gate break;
245*0Sstevel@tonic-gate } else {
246*0Sstevel@tonic-gate p_error = parse_bad_field_separator_error;
247*0Sstevel@tonic-gate }
248*0Sstevel@tonic-gate break;
249*0Sstevel@tonic-gate case key_yp_name_fields:
250*0Sstevel@tonic-gate case key_yp_split_field:
251*0Sstevel@tonic-gate if (t_mapping->e || t_mapping->numSplits > 0) {
252*0Sstevel@tonic-gate warn_duplicate_map(t_mapping->dbId,
253*0Sstevel@tonic-gate attrib_num);
254*0Sstevel@tonic-gate break;
255*0Sstevel@tonic-gate }
256*0Sstevel@tonic-gate if (parse_name_fields(s, attrib_end, t_mapping)) {
257*0Sstevel@tonic-gate p_error = parse_bad_name_field;
258*0Sstevel@tonic-gate }
259*0Sstevel@tonic-gate break;
260*0Sstevel@tonic-gate case key_yp_db_id_map:
261*0Sstevel@tonic-gate case key_db_id_map:
262*0Sstevel@tonic-gate if (t_mapping->objName != NULL) {
263*0Sstevel@tonic-gate warn_duplicate_map(t_mapping->dbId, attrib_num);
264*0Sstevel@tonic-gate break;
265*0Sstevel@tonic-gate }
266*0Sstevel@tonic-gate
267*0Sstevel@tonic-gate if (s < attrib_end && *s == OPEN_BRACKET) {
268*0Sstevel@tonic-gate index_string = getIndex(&s, attrib_end);
269*0Sstevel@tonic-gate if (index_string == NULL)
270*0Sstevel@tonic-gate break;
271*0Sstevel@tonic-gate (void) parse_index(index_string,
272*0Sstevel@tonic-gate index_string + strlen(index_string),
273*0Sstevel@tonic-gate &t_mapping->index);
274*0Sstevel@tonic-gate free(index_string);
275*0Sstevel@tonic-gate if (p_error != no_parse_error)
276*0Sstevel@tonic-gate break;
277*0Sstevel@tonic-gate }
278*0Sstevel@tonic-gate while (is_whitespace(*s) && s < attrib_end)
279*0Sstevel@tonic-gate s++;
280*0Sstevel@tonic-gate if (s < attrib_end) {
281*0Sstevel@tonic-gate while (is_whitespace(attrib_end[-1]))
282*0Sstevel@tonic-gate attrib_end--;
283*0Sstevel@tonic-gate t_mapping->objName =
284*0Sstevel@tonic-gate s_strndup_esc(s, attrib_end - s);
285*0Sstevel@tonic-gate } else {
286*0Sstevel@tonic-gate if (yp2ldap) {
287*0Sstevel@tonic-gate p_error = parse_bad_map_error;
288*0Sstevel@tonic-gate } else {
289*0Sstevel@tonic-gate t_mapping->objName = s_strndup(s, 0);
290*0Sstevel@tonic-gate }
291*0Sstevel@tonic-gate }
292*0Sstevel@tonic-gate break;
293*0Sstevel@tonic-gate
294*0Sstevel@tonic-gate case key_yp_entry_ttl:
295*0Sstevel@tonic-gate case key_entry_ttl:
296*0Sstevel@tonic-gate if (t_mapping->initTtlLo != (time_t)NO_VALUE_SET) {
297*0Sstevel@tonic-gate warn_duplicate_map(t_mapping->dbId, attrib_num);
298*0Sstevel@tonic-gate break;
299*0Sstevel@tonic-gate }
300*0Sstevel@tonic-gate
301*0Sstevel@tonic-gate if (!get_ttls(s, attrib_end, t_mapping))
302*0Sstevel@tonic-gate p_error = parse_bad_ttl_format_error;
303*0Sstevel@tonic-gate break;
304*0Sstevel@tonic-gate
305*0Sstevel@tonic-gate case key_yp_ldap_object_dn:
306*0Sstevel@tonic-gate case key_ldap_object_dn:
307*0Sstevel@tonic-gate if (t_mapping->objectDN != NULL) {
308*0Sstevel@tonic-gate warn_duplicate_map(t_mapping->dbId, attrib_num);
309*0Sstevel@tonic-gate break;
310*0Sstevel@tonic-gate }
311*0Sstevel@tonic-gate objectDN = parse_object_dn(s, attrib_end);
312*0Sstevel@tonic-gate if (objectDN == NULL)
313*0Sstevel@tonic-gate break;
314*0Sstevel@tonic-gate t_mapping->objectDN = objectDN;
315*0Sstevel@tonic-gate t_mapping->seq_num = seq_num++;
316*0Sstevel@tonic-gate break;
317*0Sstevel@tonic-gate
318*0Sstevel@tonic-gate case key_nis_to_ldap_map:
319*0Sstevel@tonic-gate case key_nisplus_to_ldap_map:
320*0Sstevel@tonic-gate if (t_mapping->ruleToLDAP != 0) {
321*0Sstevel@tonic-gate warn_duplicate_map(t_mapping->dbId, attrib_num);
322*0Sstevel@tonic-gate break;
323*0Sstevel@tonic-gate }
324*0Sstevel@tonic-gate
325*0Sstevel@tonic-gate get_mapping_rule(s, attrib_end - s, t_mapping, TRUE);
326*0Sstevel@tonic-gate break;
327*0Sstevel@tonic-gate
328*0Sstevel@tonic-gate case key_ldap_to_nis_map:
329*0Sstevel@tonic-gate case key_ldap_to_nisplus_map:
330*0Sstevel@tonic-gate if (t_mapping->ruleFromLDAP != NULL) {
331*0Sstevel@tonic-gate warn_duplicate_map(t_mapping->dbId, attrib_num);
332*0Sstevel@tonic-gate break;
333*0Sstevel@tonic-gate }
334*0Sstevel@tonic-gate
335*0Sstevel@tonic-gate get_mapping_rule(s, attrib_end - s, t_mapping, FALSE);
336*0Sstevel@tonic-gate break;
337*0Sstevel@tonic-gate
338*0Sstevel@tonic-gate default:
339*0Sstevel@tonic-gate p_error = parse_internal_error;
340*0Sstevel@tonic-gate break;
341*0Sstevel@tonic-gate }
342*0Sstevel@tonic-gate if (p_error == no_parse_error) {
343*0Sstevel@tonic-gate if (new_mapping) {
344*0Sstevel@tonic-gate if (*table_mapping == NULL)
345*0Sstevel@tonic-gate *table_mapping = t_mapping;
346*0Sstevel@tonic-gate else {
347*0Sstevel@tonic-gate for (t = *table_mapping; t->next != NULL;
348*0Sstevel@tonic-gate t = t->next)
349*0Sstevel@tonic-gate ;
350*0Sstevel@tonic-gate t->next = t_mapping;
351*0Sstevel@tonic-gate }
352*0Sstevel@tonic-gate }
353*0Sstevel@tonic-gate } else {
354*0Sstevel@tonic-gate if (new_mapping)
355*0Sstevel@tonic-gate free_table_mapping(t_mapping);
356*0Sstevel@tonic-gate }
357*0Sstevel@tonic-gate return (p_error == no_parse_error ? 0 : -1);
358*0Sstevel@tonic-gate }
359*0Sstevel@tonic-gate
360*0Sstevel@tonic-gate /*
361*0Sstevel@tonic-gate * FUNCTION: add_ypdomains_attribute
362*0Sstevel@tonic-gate *
363*0Sstevel@tonic-gate * Adds the yp domains information to the __yp_domain_context_t
364*0Sstevel@tonic-gate * structure.
365*0Sstevel@tonic-gate *
366*0Sstevel@tonic-gate * RETURN: 0 on success, -1 on failure
367*0Sstevel@tonic-gate *
368*0Sstevel@tonic-gate * INPUT: attribute number and value
369*0Sstevel@tonic-gate */
370*0Sstevel@tonic-gate
371*0Sstevel@tonic-gate int
add_ypdomains_attribute(config_key attrib_num,const char * attrib_val,int attrib_len,__yp_domain_context_t * ypDomains)372*0Sstevel@tonic-gate add_ypdomains_attribute(
373*0Sstevel@tonic-gate config_key attrib_num,
374*0Sstevel@tonic-gate const char *attrib_val,
375*0Sstevel@tonic-gate int attrib_len,
376*0Sstevel@tonic-gate __yp_domain_context_t *ypDomains)
377*0Sstevel@tonic-gate {
378*0Sstevel@tonic-gate const char *s;
379*0Sstevel@tonic-gate const char *attrib_end;
380*0Sstevel@tonic-gate int numDomains = 0;
381*0Sstevel@tonic-gate int i;
382*0Sstevel@tonic-gate char *tmp_str;
383*0Sstevel@tonic-gate int ret = 0;
384*0Sstevel@tonic-gate
385*0Sstevel@tonic-gate attrib_end = attrib_val + attrib_len;
386*0Sstevel@tonic-gate for (s = attrib_val; s < attrib_end; s++) {
387*0Sstevel@tonic-gate if (*s == COLON_CHAR) {
388*0Sstevel@tonic-gate break;
389*0Sstevel@tonic-gate }
390*0Sstevel@tonic-gate }
391*0Sstevel@tonic-gate while (s > attrib_val && is_whitespace(s[-1]))
392*0Sstevel@tonic-gate s--;
393*0Sstevel@tonic-gate
394*0Sstevel@tonic-gate if (s == attrib_val) {
395*0Sstevel@tonic-gate p_error = parse_unexpected_data_end_rule;
396*0Sstevel@tonic-gate return (-1);
397*0Sstevel@tonic-gate }
398*0Sstevel@tonic-gate
399*0Sstevel@tonic-gate if (ypDomains == NULL) {
400*0Sstevel@tonic-gate /*
401*0Sstevel@tonic-gate * No point allocating. We cant return the resulting structure,
402*0Sstevel@tonic-gate * so just return failure. Should not ever happen because we
403*0Sstevel@tonic-gate * are always called with a pointer to the global ypDomains
404*0Sstevel@tonic-gate * structure.
405*0Sstevel@tonic-gate */
406*0Sstevel@tonic-gate return (-1);
407*0Sstevel@tonic-gate }
408*0Sstevel@tonic-gate
409*0Sstevel@tonic-gate switch (attrib_num) {
410*0Sstevel@tonic-gate case key_yp_domain_context:
411*0Sstevel@tonic-gate numDomains = ypDomains->numDomains;
412*0Sstevel@tonic-gate ypDomains->domainLabels =
413*0Sstevel@tonic-gate (char **)s_realloc(ypDomains->domainLabels,
414*0Sstevel@tonic-gate (numDomains + 1) *
415*0Sstevel@tonic-gate sizeof (ypDomains->domainLabels[0]));
416*0Sstevel@tonic-gate if (ypDomains->domainLabels == NULL) {
417*0Sstevel@tonic-gate p_error = parse_no_mem_error;
418*0Sstevel@tonic-gate free_yp_domain_context(ypDomains);
419*0Sstevel@tonic-gate break;
420*0Sstevel@tonic-gate }
421*0Sstevel@tonic-gate ypDomains->domainLabels[numDomains] =
422*0Sstevel@tonic-gate s_strndup(attrib_val, s - attrib_val);
423*0Sstevel@tonic-gate if (ypDomains->domainLabels[numDomains] == NULL) {
424*0Sstevel@tonic-gate p_error = parse_no_mem_error;
425*0Sstevel@tonic-gate free_yp_domain_context(ypDomains);
426*0Sstevel@tonic-gate break;
427*0Sstevel@tonic-gate }
428*0Sstevel@tonic-gate ypDomains->numDomains = numDomains + 1;
429*0Sstevel@tonic-gate while (s < attrib_end && is_whitespace(*s))
430*0Sstevel@tonic-gate s++;
431*0Sstevel@tonic-gate if (*s == COLON_CHAR)
432*0Sstevel@tonic-gate s++;
433*0Sstevel@tonic-gate while (s < attrib_end && is_whitespace(*s))
434*0Sstevel@tonic-gate s++;
435*0Sstevel@tonic-gate ypDomains->domains =
436*0Sstevel@tonic-gate (char **)s_realloc(ypDomains->domains,
437*0Sstevel@tonic-gate (numDomains + 1) *
438*0Sstevel@tonic-gate sizeof (ypDomains->domains[0]));
439*0Sstevel@tonic-gate if (ypDomains->domains == NULL) {
440*0Sstevel@tonic-gate p_error = parse_no_mem_error;
441*0Sstevel@tonic-gate free_yp_domain_context(ypDomains);
442*0Sstevel@tonic-gate break;
443*0Sstevel@tonic-gate }
444*0Sstevel@tonic-gate
445*0Sstevel@tonic-gate if (s < attrib_end) {
446*0Sstevel@tonic-gate while (is_whitespace(attrib_end[-1]))
447*0Sstevel@tonic-gate attrib_end--;
448*0Sstevel@tonic-gate ypDomains->domains[numDomains] =
449*0Sstevel@tonic-gate s_strndup_esc(s, attrib_end - s);
450*0Sstevel@tonic-gate if (ypDomains->domains[numDomains] == NULL) {
451*0Sstevel@tonic-gate p_error = parse_no_mem_error;
452*0Sstevel@tonic-gate free_yp_domain_context(ypDomains);
453*0Sstevel@tonic-gate break;
454*0Sstevel@tonic-gate }
455*0Sstevel@tonic-gate } else {
456*0Sstevel@tonic-gate p_error = parse_unexpected_yp_domain_end_error;
457*0Sstevel@tonic-gate free(ypDomains->domainLabels[numDomains]);
458*0Sstevel@tonic-gate ypDomains->domainLabels[numDomains] = NULL;
459*0Sstevel@tonic-gate ypDomains->numDomains--;
460*0Sstevel@tonic-gate free_yp_domain_context(ypDomains);
461*0Sstevel@tonic-gate }
462*0Sstevel@tonic-gate break;
463*0Sstevel@tonic-gate case key_yppasswdd_domains:
464*0Sstevel@tonic-gate ypDomains->yppasswddDomainLabels =
465*0Sstevel@tonic-gate (char **)s_realloc(
466*0Sstevel@tonic-gate ypDomains->yppasswddDomainLabels,
467*0Sstevel@tonic-gate (ypDomains->numYppasswdd + 1) *
468*0Sstevel@tonic-gate sizeof (ypDomains->yppasswddDomainLabels[0]));
469*0Sstevel@tonic-gate if (ypDomains->yppasswddDomainLabels == NULL) {
470*0Sstevel@tonic-gate p_error = parse_no_mem_error;
471*0Sstevel@tonic-gate break;
472*0Sstevel@tonic-gate }
473*0Sstevel@tonic-gate ypDomains->yppasswddDomainLabels
474*0Sstevel@tonic-gate [ypDomains->numYppasswdd] =
475*0Sstevel@tonic-gate s_strndup(attrib_val, s - attrib_val);
476*0Sstevel@tonic-gate if (ypDomains->yppasswddDomainLabels
477*0Sstevel@tonic-gate [ypDomains->numYppasswdd] == NULL) {
478*0Sstevel@tonic-gate p_error = parse_no_mem_error;
479*0Sstevel@tonic-gate }
480*0Sstevel@tonic-gate ypDomains->numYppasswdd++;
481*0Sstevel@tonic-gate break;
482*0Sstevel@tonic-gate }
483*0Sstevel@tonic-gate
484*0Sstevel@tonic-gate return (p_error == no_parse_error ? 0 : -1);
485*0Sstevel@tonic-gate }
486*0Sstevel@tonic-gate
487*0Sstevel@tonic-gate /*
488*0Sstevel@tonic-gate * FUNCTION: get_ttls
489*0Sstevel@tonic-gate *
490*0Sstevel@tonic-gate * Parse time to live attribute
491*0Sstevel@tonic-gate *
492*0Sstevel@tonic-gate * RETURN VALUE: TRUE on success, FALSE on failure
493*0Sstevel@tonic-gate *
494*0Sstevel@tonic-gate * INPUT: the attribute value
495*0Sstevel@tonic-gate */
496*0Sstevel@tonic-gate
497*0Sstevel@tonic-gate static bool_t
get_ttls(const char * s,const char * s_end,__nis_table_mapping_t * t_mapping)498*0Sstevel@tonic-gate get_ttls(
499*0Sstevel@tonic-gate const char *s,
500*0Sstevel@tonic-gate const char *s_end,
501*0Sstevel@tonic-gate __nis_table_mapping_t *t_mapping)
502*0Sstevel@tonic-gate {
503*0Sstevel@tonic-gate time_t initTtlHi = 0;
504*0Sstevel@tonic-gate time_t initTtlLo = 0;
505*0Sstevel@tonic-gate time_t ttl = 0;
506*0Sstevel@tonic-gate time_t digit;
507*0Sstevel@tonic-gate
508*0Sstevel@tonic-gate /*
509*0Sstevel@tonic-gate * attribute should be of the form
510*0Sstevel@tonic-gate * initialTTLlo ":" initialTTLhi ":" runningTTL
511*0Sstevel@tonic-gate */
512*0Sstevel@tonic-gate
513*0Sstevel@tonic-gate if (s == s_end) {
514*0Sstevel@tonic-gate p_error = parse_bad_ttl_format_error;
515*0Sstevel@tonic-gate return (FALSE);
516*0Sstevel@tonic-gate }
517*0Sstevel@tonic-gate
518*0Sstevel@tonic-gate if (isdigit(*s)) {
519*0Sstevel@tonic-gate while (s < s_end && isdigit(*s)) {
520*0Sstevel@tonic-gate digit = (*s++) - '0';
521*0Sstevel@tonic-gate if (WILL_OVERFLOW_TIME(initTtlLo, digit))
522*0Sstevel@tonic-gate initTtlLo = TIME_MAX;
523*0Sstevel@tonic-gate else
524*0Sstevel@tonic-gate initTtlLo = initTtlLo * 10 + digit;
525*0Sstevel@tonic-gate }
526*0Sstevel@tonic-gate } else {
527*0Sstevel@tonic-gate initTtlLo = ONE_HOUR;
528*0Sstevel@tonic-gate }
529*0Sstevel@tonic-gate
530*0Sstevel@tonic-gate while (s < s_end && is_whitespace(*s))
531*0Sstevel@tonic-gate s++;
532*0Sstevel@tonic-gate if (s + 1 >= s_end || *s++ != COLON_CHAR) {
533*0Sstevel@tonic-gate p_error = parse_bad_ttl_format_error;
534*0Sstevel@tonic-gate return (FALSE);
535*0Sstevel@tonic-gate }
536*0Sstevel@tonic-gate
537*0Sstevel@tonic-gate while (s < s_end && is_whitespace(*s))
538*0Sstevel@tonic-gate s++;
539*0Sstevel@tonic-gate if (isdigit(*s)) {
540*0Sstevel@tonic-gate while (s < s_end && isdigit(*s)) {
541*0Sstevel@tonic-gate digit = (*s++) - '0';
542*0Sstevel@tonic-gate if (WILL_OVERFLOW_TIME(initTtlHi, digit))
543*0Sstevel@tonic-gate initTtlHi = TIME_MAX;
544*0Sstevel@tonic-gate else
545*0Sstevel@tonic-gate initTtlHi = initTtlHi * 10 + digit;
546*0Sstevel@tonic-gate }
547*0Sstevel@tonic-gate } else {
548*0Sstevel@tonic-gate initTtlHi = initTtlLo;
549*0Sstevel@tonic-gate }
550*0Sstevel@tonic-gate
551*0Sstevel@tonic-gate while (s < s_end && is_whitespace(*s))
552*0Sstevel@tonic-gate s++;
553*0Sstevel@tonic-gate if (s >= s_end || *s++ != COLON_CHAR) {
554*0Sstevel@tonic-gate p_error = parse_bad_ttl_format_error;
555*0Sstevel@tonic-gate return (FALSE);
556*0Sstevel@tonic-gate }
557*0Sstevel@tonic-gate
558*0Sstevel@tonic-gate while (s < s_end && is_whitespace(*s))
559*0Sstevel@tonic-gate s++;
560*0Sstevel@tonic-gate if (isdigit(*s)) {
561*0Sstevel@tonic-gate while (s < s_end && isdigit(*s)) {
562*0Sstevel@tonic-gate digit = (*s++) - '0';
563*0Sstevel@tonic-gate if (WILL_OVERFLOW_TIME(ttl, digit))
564*0Sstevel@tonic-gate ttl = TIME_MAX;
565*0Sstevel@tonic-gate else
566*0Sstevel@tonic-gate ttl = ttl * 10 + digit;
567*0Sstevel@tonic-gate }
568*0Sstevel@tonic-gate } else {
569*0Sstevel@tonic-gate ttl = ONE_HOUR;
570*0Sstevel@tonic-gate }
571*0Sstevel@tonic-gate while (s < s_end && is_whitespace(*s))
572*0Sstevel@tonic-gate s++;
573*0Sstevel@tonic-gate if (s != s_end) {
574*0Sstevel@tonic-gate p_error = parse_bad_ttl_format_error;
575*0Sstevel@tonic-gate return (FALSE);
576*0Sstevel@tonic-gate }
577*0Sstevel@tonic-gate
578*0Sstevel@tonic-gate t_mapping->initTtlLo = initTtlLo;
579*0Sstevel@tonic-gate t_mapping->initTtlHi = initTtlHi;
580*0Sstevel@tonic-gate t_mapping->ttl = ttl;
581*0Sstevel@tonic-gate return (TRUE);
582*0Sstevel@tonic-gate }
583*0Sstevel@tonic-gate
584*0Sstevel@tonic-gate /*
585*0Sstevel@tonic-gate * FUNCTION: parse_name_fields
586*0Sstevel@tonic-gate *
587*0Sstevel@tonic-gate * Parse yp name fields
588*0Sstevel@tonic-gate *
589*0Sstevel@tonic-gate * RETURN VALUE: 0 on success, non-zero on failure
590*0Sstevel@tonic-gate *
591*0Sstevel@tonic-gate * INPUTS: attrib_value and attribute_end pointers.
592*0Sstevel@tonic-gate */
593*0Sstevel@tonic-gate
594*0Sstevel@tonic-gate static int
parse_name_fields(const char * name_s,const char * name_s_end,__nis_table_mapping_t * t_map)595*0Sstevel@tonic-gate parse_name_fields(const char *name_s,
596*0Sstevel@tonic-gate const char *name_s_end,
597*0Sstevel@tonic-gate __nis_table_mapping_t *t_map)
598*0Sstevel@tonic-gate {
599*0Sstevel@tonic-gate int i, n = 0;
600*0Sstevel@tonic-gate int nElements = 0;
601*0Sstevel@tonic-gate int numSplits = 0;
602*0Sstevel@tonic-gate int parse_next_line = 1;
603*0Sstevel@tonic-gate int itm_count = 0;
604*0Sstevel@tonic-gate const char *begin_fmt;
605*0Sstevel@tonic-gate const char *end_fmt;
606*0Sstevel@tonic-gate const char *begin_token;
607*0Sstevel@tonic-gate const char *end_token;
608*0Sstevel@tonic-gate char *fmt_string = NULL;
609*0Sstevel@tonic-gate __nis_mapping_format_t *base = NULL;
610*0Sstevel@tonic-gate __nis_mapping_item_t *item = NULL;
611*0Sstevel@tonic-gate __nis_mapping_element_t *elmnt = NULL;
612*0Sstevel@tonic-gate __nis_mapping_item_type_t item_type = mit_nisplus;
613*0Sstevel@tonic-gate token_type token;
614*0Sstevel@tonic-gate
615*0Sstevel@tonic-gate t_map->numColumns = 0;
616*0Sstevel@tonic-gate
617*0Sstevel@tonic-gate for (; parse_next_line > 0; parse_next_line--) {
618*0Sstevel@tonic-gate nElements = 0;
619*0Sstevel@tonic-gate item = NULL;
620*0Sstevel@tonic-gate base = NULL;
621*0Sstevel@tonic-gate while (name_s < name_s_end && *name_s != OPEN_PAREN_CHAR)
622*0Sstevel@tonic-gate name_s++;
623*0Sstevel@tonic-gate if (name_s == name_s_end) {
624*0Sstevel@tonic-gate p_error = parse_unexpected_data_end_rule;
625*0Sstevel@tonic-gate return (1);
626*0Sstevel@tonic-gate }
627*0Sstevel@tonic-gate while (name_s < name_s_end && *name_s != DOUBLE_QUOTE_CHAR)
628*0Sstevel@tonic-gate name_s++;
629*0Sstevel@tonic-gate if (name_s == name_s_end) {
630*0Sstevel@tonic-gate p_error = parse_unexpected_data_end_rule;
631*0Sstevel@tonic-gate return (1);
632*0Sstevel@tonic-gate }
633*0Sstevel@tonic-gate begin_fmt = ++name_s; /* start of format string */
634*0Sstevel@tonic-gate while (name_s < name_s_end && *name_s != DOUBLE_QUOTE_CHAR)
635*0Sstevel@tonic-gate name_s++;
636*0Sstevel@tonic-gate if (name_s == name_s_end) {
637*0Sstevel@tonic-gate p_error = parse_unexpected_data_end_rule;
638*0Sstevel@tonic-gate return (1);
639*0Sstevel@tonic-gate }
640*0Sstevel@tonic-gate end_fmt = name_s;
641*0Sstevel@tonic-gate fmt_string = s_strndup(begin_fmt, end_fmt - begin_fmt);
642*0Sstevel@tonic-gate if (fmt_string == NULL) {
643*0Sstevel@tonic-gate p_error = parse_no_mem_error;
644*0Sstevel@tonic-gate return (2);
645*0Sstevel@tonic-gate }
646*0Sstevel@tonic-gate if (!get_mapping_format(fmt_string, &base, &n, NULL, FALSE)) {
647*0Sstevel@tonic-gate p_error = parse_internal_error;
648*0Sstevel@tonic-gate free(fmt_string);
649*0Sstevel@tonic-gate fmt_string = NULL;
650*0Sstevel@tonic-gate return (3);
651*0Sstevel@tonic-gate }
652*0Sstevel@tonic-gate free(fmt_string);
653*0Sstevel@tonic-gate fmt_string = NULL;
654*0Sstevel@tonic-gate for (n = 0; base[n].type != mmt_end; n++) {
655*0Sstevel@tonic-gate if (base[n].type != mmt_item && base[n].type
656*0Sstevel@tonic-gate != mmt_berstring) {
657*0Sstevel@tonic-gate if (base[n].type == mmt_berstring_null)
658*0Sstevel@tonic-gate base[n].type = mmt_berstring;
659*0Sstevel@tonic-gate continue;
660*0Sstevel@tonic-gate }
661*0Sstevel@tonic-gate while (name_s < name_s_end && *name_s != COMMA_CHAR)
662*0Sstevel@tonic-gate name_s++;
663*0Sstevel@tonic-gate name_s++; /* now at comma char */
664*0Sstevel@tonic-gate while (name_s < name_s_end && is_whitespace(*name_s))
665*0Sstevel@tonic-gate name_s++;
666*0Sstevel@tonic-gate begin_token = name_s++;
667*0Sstevel@tonic-gate end_token = name_s_end;
668*0Sstevel@tonic-gate name_s = get_next_token(
669*0Sstevel@tonic-gate &begin_token, &end_token, &token);
670*0Sstevel@tonic-gate if (name_s == NULL) {
671*0Sstevel@tonic-gate p_error = parse_item_expected_error;
672*0Sstevel@tonic-gate return (4);
673*0Sstevel@tonic-gate }
674*0Sstevel@tonic-gate if (token != string_token) {
675*0Sstevel@tonic-gate p_error = parse_item_expected_error;
676*0Sstevel@tonic-gate return (5);
677*0Sstevel@tonic-gate }
678*0Sstevel@tonic-gate item = (__nis_mapping_item_t *)s_realloc(item,
679*0Sstevel@tonic-gate (nElements + 1) *
680*0Sstevel@tonic-gate sizeof (__nis_mapping_item_t));
681*0Sstevel@tonic-gate if (item == NULL) {
682*0Sstevel@tonic-gate p_error = parse_no_mem_error;
683*0Sstevel@tonic-gate return (2);
684*0Sstevel@tonic-gate }
685*0Sstevel@tonic-gate name_s = get_mapping_item(begin_token, name_s_end,
686*0Sstevel@tonic-gate &item[nElements], item_type);
687*0Sstevel@tonic-gate if (name_s == NULL) {
688*0Sstevel@tonic-gate p_error = parse_unmatched_escape;
689*0Sstevel@tonic-gate for (n = 0; n < (nElements + 1); n++)
690*0Sstevel@tonic-gate free_mapping_item(&item[n]);
691*0Sstevel@tonic-gate free_mapping_format(base);
692*0Sstevel@tonic-gate return (4);
693*0Sstevel@tonic-gate }
694*0Sstevel@tonic-gate nElements++;
695*0Sstevel@tonic-gate }
696*0Sstevel@tonic-gate if (p_error != no_parse_error) {
697*0Sstevel@tonic-gate for (n = 0; n < (nElements + 1); n++)
698*0Sstevel@tonic-gate free_mapping_item(&item[n]);
699*0Sstevel@tonic-gate free_mapping_format(base);
700*0Sstevel@tonic-gate return (6);
701*0Sstevel@tonic-gate }
702*0Sstevel@tonic-gate name_s = skip_token(name_s, name_s_end, close_paren_token);
703*0Sstevel@tonic-gate if (name_s == NULL) {
704*0Sstevel@tonic-gate p_error = parse_close_paren_expected_error;
705*0Sstevel@tonic-gate for (n = 0; n < (nElements + 1); n++)
706*0Sstevel@tonic-gate free_mapping_item(&item[n]);
707*0Sstevel@tonic-gate free_mapping_format(base);
708*0Sstevel@tonic-gate return (4);
709*0Sstevel@tonic-gate }
710*0Sstevel@tonic-gate while (name_s < name_s_end && is_whitespace(*name_s))
711*0Sstevel@tonic-gate name_s++;
712*0Sstevel@tonic-gate if (*name_s == COMMA_CHAR)
713*0Sstevel@tonic-gate parse_next_line++;
714*0Sstevel@tonic-gate
715*0Sstevel@tonic-gate if (nElements == 0) {
716*0Sstevel@tonic-gate p_error = parse_no_match_item;
717*0Sstevel@tonic-gate for (n = 0; n < (nElements + 1); n++)
718*0Sstevel@tonic-gate free_mapping_item(&item[n]);
719*0Sstevel@tonic-gate free_mapping_format(base);
720*0Sstevel@tonic-gate return (7);
721*0Sstevel@tonic-gate }
722*0Sstevel@tonic-gate elmnt = (__nis_mapping_element_t *)s_realloc(elmnt,
723*0Sstevel@tonic-gate (numSplits + 1) *
724*0Sstevel@tonic-gate sizeof (__nis_mapping_element_t));
725*0Sstevel@tonic-gate if (elmnt == NULL) {
726*0Sstevel@tonic-gate for (n = 0; n < (nElements + 1); n++)
727*0Sstevel@tonic-gate free_mapping_item(&item[n]);
728*0Sstevel@tonic-gate free_mapping_format(base);
729*0Sstevel@tonic-gate p_error = parse_no_mem_error;
730*0Sstevel@tonic-gate return (2);
731*0Sstevel@tonic-gate }
732*0Sstevel@tonic-gate elmnt[numSplits].type = me_match;
733*0Sstevel@tonic-gate elmnt[numSplits].element.match.numItems = nElements;
734*0Sstevel@tonic-gate elmnt[numSplits].element.match.item = item;
735*0Sstevel@tonic-gate elmnt[numSplits].element.match.fmt = base;
736*0Sstevel@tonic-gate item = NULL;
737*0Sstevel@tonic-gate base = NULL;
738*0Sstevel@tonic-gate
739*0Sstevel@tonic-gate t_map->e = elmnt;
740*0Sstevel@tonic-gate t_map->numSplits = numSplits;
741*0Sstevel@tonic-gate n = t_map->numColumns;
742*0Sstevel@tonic-gate
743*0Sstevel@tonic-gate for (i = n, itm_count = 0; i < n + nElements; i++) {
744*0Sstevel@tonic-gate if (t_map->e[numSplits].element.
745*0Sstevel@tonic-gate match.item[itm_count].name) {
746*0Sstevel@tonic-gate if (!add_column(t_map,
747*0Sstevel@tonic-gate t_map->e[numSplits].element.
748*0Sstevel@tonic-gate match.item[itm_count].name))
749*0Sstevel@tonic-gate return (1);
750*0Sstevel@tonic-gate itm_count++;
751*0Sstevel@tonic-gate } else {
752*0Sstevel@tonic-gate p_error = parse_internal_error;
753*0Sstevel@tonic-gate for (n = 0; n < (nElements + 1); n++)
754*0Sstevel@tonic-gate free_mapping_item(&item[n]);
755*0Sstevel@tonic-gate free_mapping_format(base);
756*0Sstevel@tonic-gate free_mapping_element(elmnt);
757*0Sstevel@tonic-gate return (1);
758*0Sstevel@tonic-gate }
759*0Sstevel@tonic-gate }
760*0Sstevel@tonic-gate numSplits++;
761*0Sstevel@tonic-gate }
762*0Sstevel@tonic-gate elmnt = NULL;
763*0Sstevel@tonic-gate
764*0Sstevel@tonic-gate if (item != NULL) {
765*0Sstevel@tonic-gate for (n = 0; n < t_map->numColumns; n++) {
766*0Sstevel@tonic-gate free_mapping_item(&item[n]);
767*0Sstevel@tonic-gate }
768*0Sstevel@tonic-gate free(item);
769*0Sstevel@tonic-gate }
770*0Sstevel@tonic-gate if (elmnt != NULL)
771*0Sstevel@tonic-gate free_mapping_element(elmnt);
772*0Sstevel@tonic-gate if (base != NULL)
773*0Sstevel@tonic-gate free_mapping_format(base);
774*0Sstevel@tonic-gate
775*0Sstevel@tonic-gate return (p_error == no_parse_error ? 0 : -1);
776*0Sstevel@tonic-gate }
777*0Sstevel@tonic-gate
778*0Sstevel@tonic-gate /*
779*0Sstevel@tonic-gate * FUNCTION: parse_object_dn
780*0Sstevel@tonic-gate *
781*0Sstevel@tonic-gate * Parse object dn attribute
782*0Sstevel@tonic-gate *
783*0Sstevel@tonic-gate * RETURN VALUE: __nis_object_dn_t on success
784*0Sstevel@tonic-gate * NULL on failure
785*0Sstevel@tonic-gate *
786*0Sstevel@tonic-gate * INPUT: the attribute value
787*0Sstevel@tonic-gate */
788*0Sstevel@tonic-gate
789*0Sstevel@tonic-gate static __nis_object_dn_t *
parse_object_dn(const char * s,const char * end)790*0Sstevel@tonic-gate parse_object_dn(const char *s, const char *end)
791*0Sstevel@tonic-gate {
792*0Sstevel@tonic-gate const char *s_begin;
793*0Sstevel@tonic-gate const char *s_end;
794*0Sstevel@tonic-gate object_dn_token token;
795*0Sstevel@tonic-gate parse_object_dn_state dn_state = dn_begin_parse;
796*0Sstevel@tonic-gate __nis_object_dn_t *obj_dn = NULL;
797*0Sstevel@tonic-gate __nis_object_dn_t *next = NULL;
798*0Sstevel@tonic-gate __nis_object_dn_t *last = NULL;
799*0Sstevel@tonic-gate
800*0Sstevel@tonic-gate /*
801*0Sstevel@tonic-gate * The attribute should be of form
802*0Sstevel@tonic-gate * objectDN *( ";" objectDN )
803*0Sstevel@tonic-gate * objectDN = readObjectSpec [":"[writeObjectSpec]]
804*0Sstevel@tonic-gate * readObjectSpec = [baseAndScope [filterAttrValList]]
805*0Sstevel@tonic-gate * writeObjectSpec = [baseAndScope [attrValList [":" deleteDisp]]]
806*0Sstevel@tonic-gate */
807*0Sstevel@tonic-gate
808*0Sstevel@tonic-gate while (s < end) {
809*0Sstevel@tonic-gate s_begin = s;
810*0Sstevel@tonic-gate s_end = end;
811*0Sstevel@tonic-gate s = get_next_object_dn_token(&s_begin, &s_end, &token);
812*0Sstevel@tonic-gate if (s == NULL)
813*0Sstevel@tonic-gate break;
814*0Sstevel@tonic-gate
815*0Sstevel@tonic-gate if (token == dn_no_token || token == dn_semi_token) {
816*0Sstevel@tonic-gate if (obj_dn == NULL)
817*0Sstevel@tonic-gate obj_dn = next;
818*0Sstevel@tonic-gate else
819*0Sstevel@tonic-gate last->next = next;
820*0Sstevel@tonic-gate last = next;
821*0Sstevel@tonic-gate next = NULL;
822*0Sstevel@tonic-gate if (token == dn_no_token)
823*0Sstevel@tonic-gate break;
824*0Sstevel@tonic-gate dn_state = dn_begin_parse;
825*0Sstevel@tonic-gate }
826*0Sstevel@tonic-gate if (next == NULL) {
827*0Sstevel@tonic-gate next = (__nis_object_dn_t *)
828*0Sstevel@tonic-gate s_calloc(1, sizeof (__nis_object_dn_t));
829*0Sstevel@tonic-gate if (next == NULL)
830*0Sstevel@tonic-gate break;
831*0Sstevel@tonic-gate next->read.scope = LDAP_SCOPE_ONELEVEL;
832*0Sstevel@tonic-gate next->write.scope = LDAP_SCOPE_UNKNOWN;
833*0Sstevel@tonic-gate next->delDisp = dd_always;
834*0Sstevel@tonic-gate }
835*0Sstevel@tonic-gate if (token == dn_semi_token)
836*0Sstevel@tonic-gate continue;
837*0Sstevel@tonic-gate
838*0Sstevel@tonic-gate switch (dn_state) {
839*0Sstevel@tonic-gate case dn_begin_parse:
840*0Sstevel@tonic-gate if (token == dn_ques_token)
841*0Sstevel@tonic-gate dn_state = dn_got_read_q_scope;
842*0Sstevel@tonic-gate else if (token == dn_colon_token) {
843*0Sstevel@tonic-gate dn_state = dn_got_write_colon;
844*0Sstevel@tonic-gate next->write.scope = LDAP_SCOPE_ONELEVEL;
845*0Sstevel@tonic-gate } else {
846*0Sstevel@tonic-gate if (!validate_dn(s_begin, s_end - s_begin))
847*0Sstevel@tonic-gate break;
848*0Sstevel@tonic-gate next->read.base =
849*0Sstevel@tonic-gate s_strndup_esc(s_begin, s_end - s_begin);
850*0Sstevel@tonic-gate dn_state = dn_got_read_dn;
851*0Sstevel@tonic-gate }
852*0Sstevel@tonic-gate break;
853*0Sstevel@tonic-gate case dn_got_read_dn:
854*0Sstevel@tonic-gate if (token == dn_ques_token)
855*0Sstevel@tonic-gate dn_state = dn_got_read_q_scope;
856*0Sstevel@tonic-gate else if (token == dn_colon_token) {
857*0Sstevel@tonic-gate dn_state = dn_got_write_colon;
858*0Sstevel@tonic-gate next->write.scope = LDAP_SCOPE_ONELEVEL;
859*0Sstevel@tonic-gate } else
860*0Sstevel@tonic-gate p_error = parse_object_dn_syntax_error;
861*0Sstevel@tonic-gate break;
862*0Sstevel@tonic-gate case dn_got_read_q_scope:
863*0Sstevel@tonic-gate if (token == dn_ques_token)
864*0Sstevel@tonic-gate dn_state = dn_got_read_q_filter;
865*0Sstevel@tonic-gate else if (token == dn_colon_token) {
866*0Sstevel@tonic-gate dn_state = dn_got_write_colon;
867*0Sstevel@tonic-gate next->write.scope = LDAP_SCOPE_ONELEVEL;
868*0Sstevel@tonic-gate } else if (token == dn_base_token) {
869*0Sstevel@tonic-gate next->read.scope = LDAP_SCOPE_BASE;
870*0Sstevel@tonic-gate dn_state = dn_got_read_scope;
871*0Sstevel@tonic-gate } else if (token == dn_one_token) {
872*0Sstevel@tonic-gate next->read.scope = LDAP_SCOPE_ONELEVEL;
873*0Sstevel@tonic-gate dn_state = dn_got_read_scope;
874*0Sstevel@tonic-gate } else if (token == dn_sub_token) {
875*0Sstevel@tonic-gate next->read.scope = LDAP_SCOPE_SUBTREE;
876*0Sstevel@tonic-gate dn_state = dn_got_read_scope;
877*0Sstevel@tonic-gate } else {
878*0Sstevel@tonic-gate p_error = parse_invalid_scope;
879*0Sstevel@tonic-gate }
880*0Sstevel@tonic-gate break;
881*0Sstevel@tonic-gate case dn_got_read_scope:
882*0Sstevel@tonic-gate if (token == dn_ques_token)
883*0Sstevel@tonic-gate dn_state = dn_got_read_q_filter;
884*0Sstevel@tonic-gate else if (token == dn_colon_token) {
885*0Sstevel@tonic-gate dn_state = dn_got_write_colon;
886*0Sstevel@tonic-gate next->write.scope = LDAP_SCOPE_ONELEVEL;
887*0Sstevel@tonic-gate } else
888*0Sstevel@tonic-gate p_error = parse_object_dn_syntax_error;
889*0Sstevel@tonic-gate break;
890*0Sstevel@tonic-gate case dn_got_read_q_filter:
891*0Sstevel@tonic-gate if (token == dn_ques_token) {
892*0Sstevel@tonic-gate p_error = parse_object_dn_syntax_error;
893*0Sstevel@tonic-gate } else if (token == dn_colon_token) {
894*0Sstevel@tonic-gate dn_state = dn_got_write_colon;
895*0Sstevel@tonic-gate next->write.scope = LDAP_SCOPE_ONELEVEL;
896*0Sstevel@tonic-gate } else {
897*0Sstevel@tonic-gate if (!validate_ldap_filter(s_begin, s_end))
898*0Sstevel@tonic-gate break;
899*0Sstevel@tonic-gate next->read.attrs =
900*0Sstevel@tonic-gate s_strndup_esc(s_begin, s_end - s_begin);
901*0Sstevel@tonic-gate dn_state = dn_got_read_filter;
902*0Sstevel@tonic-gate }
903*0Sstevel@tonic-gate break;
904*0Sstevel@tonic-gate case dn_got_read_filter:
905*0Sstevel@tonic-gate if (token == dn_ques_token) {
906*0Sstevel@tonic-gate p_error = parse_object_dn_syntax_error;
907*0Sstevel@tonic-gate } else if (token == dn_colon_token) {
908*0Sstevel@tonic-gate dn_state = dn_got_write_colon;
909*0Sstevel@tonic-gate next->write.scope = LDAP_SCOPE_ONELEVEL;
910*0Sstevel@tonic-gate } else
911*0Sstevel@tonic-gate p_error = parse_object_dn_syntax_error;
912*0Sstevel@tonic-gate break;
913*0Sstevel@tonic-gate case dn_got_write_colon:
914*0Sstevel@tonic-gate if (token == dn_ques_token)
915*0Sstevel@tonic-gate dn_state = dn_got_write_q_scope;
916*0Sstevel@tonic-gate else if (token == dn_colon_token) {
917*0Sstevel@tonic-gate dn_state = dn_got_delete_colon;
918*0Sstevel@tonic-gate } else {
919*0Sstevel@tonic-gate if (!validate_dn(s_begin, s_end - s_begin))
920*0Sstevel@tonic-gate break;
921*0Sstevel@tonic-gate next->write.base =
922*0Sstevel@tonic-gate s_strndup_esc(s_begin, s_end - s_begin);
923*0Sstevel@tonic-gate dn_state = dn_got_write_dn;
924*0Sstevel@tonic-gate }
925*0Sstevel@tonic-gate break;
926*0Sstevel@tonic-gate case dn_got_write_dn:
927*0Sstevel@tonic-gate if (token == dn_ques_token)
928*0Sstevel@tonic-gate dn_state = dn_got_write_q_scope;
929*0Sstevel@tonic-gate else if (token == dn_colon_token) {
930*0Sstevel@tonic-gate dn_state = dn_got_delete_colon;
931*0Sstevel@tonic-gate } else
932*0Sstevel@tonic-gate p_error = parse_object_dn_syntax_error;
933*0Sstevel@tonic-gate break;
934*0Sstevel@tonic-gate case dn_got_write_q_scope:
935*0Sstevel@tonic-gate if (token == dn_ques_token)
936*0Sstevel@tonic-gate dn_state = dn_got_write_q_filter;
937*0Sstevel@tonic-gate else if (token == dn_colon_token) {
938*0Sstevel@tonic-gate dn_state = dn_got_delete_colon;
939*0Sstevel@tonic-gate } else if (token == dn_base_token) {
940*0Sstevel@tonic-gate next->write.scope = LDAP_SCOPE_BASE;
941*0Sstevel@tonic-gate dn_state = dn_got_write_scope;
942*0Sstevel@tonic-gate } else if (token == dn_one_token) {
943*0Sstevel@tonic-gate next->write.scope = LDAP_SCOPE_ONELEVEL;
944*0Sstevel@tonic-gate dn_state = dn_got_write_scope;
945*0Sstevel@tonic-gate } else if (token == dn_sub_token) {
946*0Sstevel@tonic-gate next->write.scope = LDAP_SCOPE_SUBTREE;
947*0Sstevel@tonic-gate dn_state = dn_got_write_scope;
948*0Sstevel@tonic-gate } else {
949*0Sstevel@tonic-gate p_error = parse_invalid_scope;
950*0Sstevel@tonic-gate }
951*0Sstevel@tonic-gate break;
952*0Sstevel@tonic-gate case dn_got_write_scope:
953*0Sstevel@tonic-gate if (token == dn_ques_token)
954*0Sstevel@tonic-gate dn_state = dn_got_write_q_filter;
955*0Sstevel@tonic-gate else if (token == dn_colon_token) {
956*0Sstevel@tonic-gate dn_state = dn_got_delete_colon;
957*0Sstevel@tonic-gate } else
958*0Sstevel@tonic-gate p_error = parse_object_dn_syntax_error;
959*0Sstevel@tonic-gate break;
960*0Sstevel@tonic-gate case dn_got_write_q_filter:
961*0Sstevel@tonic-gate if (token == dn_ques_token) {
962*0Sstevel@tonic-gate p_error = parse_object_dn_syntax_error;
963*0Sstevel@tonic-gate } else if (token == dn_colon_token) {
964*0Sstevel@tonic-gate dn_state = dn_got_delete_colon;
965*0Sstevel@tonic-gate } else {
966*0Sstevel@tonic-gate if (!validate_ldap_filter(s_begin, s_end))
967*0Sstevel@tonic-gate break;
968*0Sstevel@tonic-gate next->write.attrs =
969*0Sstevel@tonic-gate s_strndup_esc(s_begin, s_end - s_begin);
970*0Sstevel@tonic-gate dn_state = dn_got_write_filter;
971*0Sstevel@tonic-gate }
972*0Sstevel@tonic-gate break;
973*0Sstevel@tonic-gate case dn_got_write_filter:
974*0Sstevel@tonic-gate if (token == dn_ques_token) {
975*0Sstevel@tonic-gate p_error = parse_object_dn_syntax_error;
976*0Sstevel@tonic-gate } else if (token == dn_colon_token) {
977*0Sstevel@tonic-gate dn_state = dn_got_delete_colon;
978*0Sstevel@tonic-gate
979*0Sstevel@tonic-gate } else
980*0Sstevel@tonic-gate p_error = parse_semi_expected_error;
981*0Sstevel@tonic-gate break;
982*0Sstevel@tonic-gate case dn_got_delete_colon:
983*0Sstevel@tonic-gate if (token == dn_ques_token) {
984*0Sstevel@tonic-gate p_error = parse_object_dn_syntax_error;
985*0Sstevel@tonic-gate } else if (token == dn_colon_token) {
986*0Sstevel@tonic-gate p_error = parse_object_dn_syntax_error;
987*0Sstevel@tonic-gate } else {
988*0Sstevel@tonic-gate if (!get_deleteDisp(s_begin, s_end, next))
989*0Sstevel@tonic-gate break;
990*0Sstevel@tonic-gate dn_state = dn_got_delete_dsp;
991*0Sstevel@tonic-gate }
992*0Sstevel@tonic-gate break;
993*0Sstevel@tonic-gate case dn_got_delete_dsp:
994*0Sstevel@tonic-gate p_error = parse_object_dn_syntax_error;
995*0Sstevel@tonic-gate break;
996*0Sstevel@tonic-gate }
997*0Sstevel@tonic-gate
998*0Sstevel@tonic-gate if (p_error != no_parse_error)
999*0Sstevel@tonic-gate break;
1000*0Sstevel@tonic-gate }
1001*0Sstevel@tonic-gate if (p_error != no_parse_error) {
1002*0Sstevel@tonic-gate if (obj_dn != NULL)
1003*0Sstevel@tonic-gate free_object_dn(obj_dn);
1004*0Sstevel@tonic-gate if (next != NULL)
1005*0Sstevel@tonic-gate free_object_dn(next);
1006*0Sstevel@tonic-gate obj_dn = NULL;
1007*0Sstevel@tonic-gate } else if (next != NULL) {
1008*0Sstevel@tonic-gate if (obj_dn == NULL)
1009*0Sstevel@tonic-gate obj_dn = next;
1010*0Sstevel@tonic-gate else
1011*0Sstevel@tonic-gate last->next = next;
1012*0Sstevel@tonic-gate } else if (obj_dn == NULL)
1013*0Sstevel@tonic-gate obj_dn = (__nis_object_dn_t *)
1014*0Sstevel@tonic-gate s_calloc(1, sizeof (__nis_object_dn_t));
1015*0Sstevel@tonic-gate
1016*0Sstevel@tonic-gate return (obj_dn);
1017*0Sstevel@tonic-gate }
1018*0Sstevel@tonic-gate
1019*0Sstevel@tonic-gate /*
1020*0Sstevel@tonic-gate * FUNCTION: get_mapping_rule
1021*0Sstevel@tonic-gate *
1022*0Sstevel@tonic-gate * Parse mapping rule attributes
1023*0Sstevel@tonic-gate *
1024*0Sstevel@tonic-gate * RETURN VALUE: None. Errors determined by p_error
1025*0Sstevel@tonic-gate *
1026*0Sstevel@tonic-gate * INPUT: the attribute value and mapping rule type
1027*0Sstevel@tonic-gate */
1028*0Sstevel@tonic-gate
1029*0Sstevel@tonic-gate static void
get_mapping_rule(const char * s,int len,__nis_table_mapping_t * tbl,bool_t to_ldap)1030*0Sstevel@tonic-gate get_mapping_rule(
1031*0Sstevel@tonic-gate const char *s,
1032*0Sstevel@tonic-gate int len,
1033*0Sstevel@tonic-gate __nis_table_mapping_t *tbl,
1034*0Sstevel@tonic-gate bool_t to_ldap)
1035*0Sstevel@tonic-gate {
1036*0Sstevel@tonic-gate const char *end_s = s + len;
1037*0Sstevel@tonic-gate const char *begin_token;
1038*0Sstevel@tonic-gate const char *end_token;
1039*0Sstevel@tonic-gate __nis_mapping_rule_t **rule = NULL;
1040*0Sstevel@tonic-gate __nis_mapping_rule_t *next = NULL;
1041*0Sstevel@tonic-gate /* __nis_mapping_rule_t **r; */
1042*0Sstevel@tonic-gate token_type t;
1043*0Sstevel@tonic-gate int nRules = 0;
1044*0Sstevel@tonic-gate const char *s1;
1045*0Sstevel@tonic-gate int i;
1046*0Sstevel@tonic-gate
1047*0Sstevel@tonic-gate /*
1048*0Sstevel@tonic-gate * The attribute value is of the form
1049*0Sstevel@tonic-gate * colattrspec *("," colattrspec)
1050*0Sstevel@tonic-gate * colattrspec = lhs "=" rhs
1051*0Sstevel@tonic-gate * lhs = lval | namespeclist
1052*0Sstevel@tonic-gate * rhs = rval | [namespec]
1053*0Sstevel@tonic-gate */
1054*0Sstevel@tonic-gate
1055*0Sstevel@tonic-gate for (;;) {
1056*0Sstevel@tonic-gate if ((next = (__nis_mapping_rule_t *)
1057*0Sstevel@tonic-gate s_calloc(1, sizeof (__nis_mapping_rule_t))) == NULL)
1058*0Sstevel@tonic-gate break;
1059*0Sstevel@tonic-gate
1060*0Sstevel@tonic-gate s = get_lhs(s, end_s, &next->lhs,
1061*0Sstevel@tonic-gate to_ldap ? mit_ldap : mit_nisplus);
1062*0Sstevel@tonic-gate if (s == NULL)
1063*0Sstevel@tonic-gate break;
1064*0Sstevel@tonic-gate
1065*0Sstevel@tonic-gate begin_token = s;
1066*0Sstevel@tonic-gate end_token = end_s;
1067*0Sstevel@tonic-gate s1 = get_next_token(&begin_token, &end_token, &t);
1068*0Sstevel@tonic-gate if (s1 == NULL)
1069*0Sstevel@tonic-gate break;
1070*0Sstevel@tonic-gate if (!(to_ldap && (t == comma_token || t == no_token))) {
1071*0Sstevel@tonic-gate s = get_rhs(s, end_s, &next->rhs,
1072*0Sstevel@tonic-gate to_ldap ? mit_nisplus : mit_ldap);
1073*0Sstevel@tonic-gate if (s == NULL)
1074*0Sstevel@tonic-gate break;
1075*0Sstevel@tonic-gate }
1076*0Sstevel@tonic-gate
1077*0Sstevel@tonic-gate if (next->lhs.numElements > 1 &&
1078*0Sstevel@tonic-gate (next->rhs.numElements != 1 ||
1079*0Sstevel@tonic-gate next->rhs.element[0].type != me_split)) {
1080*0Sstevel@tonic-gate p_error = parse_lhs_rhs_type_mismatch;
1081*0Sstevel@tonic-gate break;
1082*0Sstevel@tonic-gate }
1083*0Sstevel@tonic-gate if (rule == NULL) {
1084*0Sstevel@tonic-gate rule = (__nis_mapping_rule_t **)
1085*0Sstevel@tonic-gate malloc(sizeof (__nis_mapping_rule_t *));
1086*0Sstevel@tonic-gate if (rule == NULL)
1087*0Sstevel@tonic-gate break;
1088*0Sstevel@tonic-gate } else {
1089*0Sstevel@tonic-gate rule = (__nis_mapping_rule_t **)s_realloc(rule,
1090*0Sstevel@tonic-gate (nRules + 1) *
1091*0Sstevel@tonic-gate sizeof (__nis_mapping_rule_t *));
1092*0Sstevel@tonic-gate if (rule == NULL)
1093*0Sstevel@tonic-gate break;
1094*0Sstevel@tonic-gate }
1095*0Sstevel@tonic-gate
1096*0Sstevel@tonic-gate rule[nRules++] = next;
1097*0Sstevel@tonic-gate next = NULL;
1098*0Sstevel@tonic-gate
1099*0Sstevel@tonic-gate begin_token = s;
1100*0Sstevel@tonic-gate end_token = end_s;
1101*0Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t);
1102*0Sstevel@tonic-gate if (s == NULL)
1103*0Sstevel@tonic-gate break;
1104*0Sstevel@tonic-gate if (t == comma_token)
1105*0Sstevel@tonic-gate continue;
1106*0Sstevel@tonic-gate if (t != no_token) {
1107*0Sstevel@tonic-gate p_error = parse_unexpected_data_end_rule;
1108*0Sstevel@tonic-gate break;
1109*0Sstevel@tonic-gate }
1110*0Sstevel@tonic-gate if (to_ldap) {
1111*0Sstevel@tonic-gate tbl->numRulesToLDAP = nRules;
1112*0Sstevel@tonic-gate tbl->ruleToLDAP = rule;
1113*0Sstevel@tonic-gate } else {
1114*0Sstevel@tonic-gate tbl->numRulesFromLDAP = nRules;
1115*0Sstevel@tonic-gate tbl->ruleFromLDAP = rule;
1116*0Sstevel@tonic-gate }
1117*0Sstevel@tonic-gate return;
1118*0Sstevel@tonic-gate }
1119*0Sstevel@tonic-gate
1120*0Sstevel@tonic-gate if (rule) {
1121*0Sstevel@tonic-gate for (i = 0; i < nRules; i++)
1122*0Sstevel@tonic-gate free_mapping_rule(rule[i]);
1123*0Sstevel@tonic-gate free(rule);
1124*0Sstevel@tonic-gate }
1125*0Sstevel@tonic-gate if (next)
1126*0Sstevel@tonic-gate free_mapping_rule(next);
1127*0Sstevel@tonic-gate }
1128*0Sstevel@tonic-gate
1129*0Sstevel@tonic-gate /*
1130*0Sstevel@tonic-gate * FUNCTION: get_lhs
1131*0Sstevel@tonic-gate *
1132*0Sstevel@tonic-gate * Parse left hand side of mapping rule attribute
1133*0Sstevel@tonic-gate *
1134*0Sstevel@tonic-gate * RETURN VALUE: NULL if error
1135*0Sstevel@tonic-gate * position of beginning rhs
1136*0Sstevel@tonic-gate *
1137*0Sstevel@tonic-gate * INPUT: the attribute value and mapping rule type
1138*0Sstevel@tonic-gate */
1139*0Sstevel@tonic-gate
1140*0Sstevel@tonic-gate static const char *
get_lhs(const char * s,const char * end_s,__nis_mapping_rlhs_t * lhs,__nis_mapping_item_type_t item_type)1141*0Sstevel@tonic-gate get_lhs(const char *s,
1142*0Sstevel@tonic-gate const char *end_s,
1143*0Sstevel@tonic-gate __nis_mapping_rlhs_t *lhs,
1144*0Sstevel@tonic-gate __nis_mapping_item_type_t item_type)
1145*0Sstevel@tonic-gate {
1146*0Sstevel@tonic-gate token_type t;
1147*0Sstevel@tonic-gate const char *begin_token;
1148*0Sstevel@tonic-gate const char *end_token;
1149*0Sstevel@tonic-gate const char *sav_s;
1150*0Sstevel@tonic-gate __nis_mapping_element_t *e = NULL;
1151*0Sstevel@tonic-gate
1152*0Sstevel@tonic-gate /*
1153*0Sstevel@tonic-gate * lhs can be expressed as:
1154*0Sstevel@tonic-gate * item
1155*0Sstevel@tonic-gate * (item)
1156*0Sstevel@tonic-gate * (item list)
1157*0Sstevel@tonic-gate * (fmt, item list)
1158*0Sstevel@tonic-gate *
1159*0Sstevel@tonic-gate * lhs = lval | namespeclist
1160*0Sstevel@tonic-gate * lval = "(" formatspec "," namespec *("," namespec) ")"
1161*0Sstevel@tonic-gate * namespeclist = namespec | "(" namespec *("," namespec) ")"
1162*0Sstevel@tonic-gate */
1163*0Sstevel@tonic-gate
1164*0Sstevel@tonic-gate for (; p_error == no_parse_error; ) {
1165*0Sstevel@tonic-gate begin_token = s;
1166*0Sstevel@tonic-gate end_token = end_s;
1167*0Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t);
1168*0Sstevel@tonic-gate if (s == NULL)
1169*0Sstevel@tonic-gate break;
1170*0Sstevel@tonic-gate if (t == no_token) {
1171*0Sstevel@tonic-gate p_error = parse_unexpected_data_end_rule;
1172*0Sstevel@tonic-gate break;
1173*0Sstevel@tonic-gate }
1174*0Sstevel@tonic-gate
1175*0Sstevel@tonic-gate e = (__nis_mapping_element_t *)
1176*0Sstevel@tonic-gate s_calloc(1, sizeof (__nis_mapping_element_t));
1177*0Sstevel@tonic-gate if (e == NULL)
1178*0Sstevel@tonic-gate break;
1179*0Sstevel@tonic-gate
1180*0Sstevel@tonic-gate if (t == open_paren_token) {
1181*0Sstevel@tonic-gate free(e);
1182*0Sstevel@tonic-gate e = NULL;
1183*0Sstevel@tonic-gate
1184*0Sstevel@tonic-gate begin_token = s;
1185*0Sstevel@tonic-gate end_token = end_s;
1186*0Sstevel@tonic-gate sav_s = s;
1187*0Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t);
1188*0Sstevel@tonic-gate if (s == NULL)
1189*0Sstevel@tonic-gate break;
1190*0Sstevel@tonic-gate
1191*0Sstevel@tonic-gate if (t == quoted_string_token) {
1192*0Sstevel@tonic-gate s = get_lhs_match(sav_s, end_s, lhs, item_type);
1193*0Sstevel@tonic-gate if (s == NULL)
1194*0Sstevel@tonic-gate break;
1195*0Sstevel@tonic-gate } else if (t == string_token) {
1196*0Sstevel@tonic-gate s = get_lhs_paren_item(sav_s, end_s, lhs,
1197*0Sstevel@tonic-gate item_type);
1198*0Sstevel@tonic-gate if (s == NULL)
1199*0Sstevel@tonic-gate break;
1200*0Sstevel@tonic-gate } else {
1201*0Sstevel@tonic-gate p_error = parse_bad_lhs_format_error;
1202*0Sstevel@tonic-gate break;
1203*0Sstevel@tonic-gate }
1204*0Sstevel@tonic-gate } else if (t == string_token) {
1205*0Sstevel@tonic-gate s = get_mapping_item(begin_token, end_s,
1206*0Sstevel@tonic-gate &e->element.item, item_type);
1207*0Sstevel@tonic-gate if (s == NULL)
1208*0Sstevel@tonic-gate break;
1209*0Sstevel@tonic-gate e->type = me_item;
1210*0Sstevel@tonic-gate if (!add_element(e, lhs))
1211*0Sstevel@tonic-gate break;
1212*0Sstevel@tonic-gate e = NULL;
1213*0Sstevel@tonic-gate } else {
1214*0Sstevel@tonic-gate p_error = parse_bad_lhs_format_error;
1215*0Sstevel@tonic-gate break;
1216*0Sstevel@tonic-gate }
1217*0Sstevel@tonic-gate
1218*0Sstevel@tonic-gate s = skip_token(s, end_s, equal_token);
1219*0Sstevel@tonic-gate if (s == NULL)
1220*0Sstevel@tonic-gate break;
1221*0Sstevel@tonic-gate if (p_error == no_parse_error)
1222*0Sstevel@tonic-gate return (s);
1223*0Sstevel@tonic-gate }
1224*0Sstevel@tonic-gate if (e != NULL)
1225*0Sstevel@tonic-gate free_mapping_element(e);
1226*0Sstevel@tonic-gate
1227*0Sstevel@tonic-gate return (NULL);
1228*0Sstevel@tonic-gate }
1229*0Sstevel@tonic-gate
1230*0Sstevel@tonic-gate /*
1231*0Sstevel@tonic-gate * FUNCTION: get_lhs_match
1232*0Sstevel@tonic-gate *
1233*0Sstevel@tonic-gate * Parse left hand side of mapping rule attribute in case of
1234*0Sstevel@tonic-gate * matching rule
1235*0Sstevel@tonic-gate *
1236*0Sstevel@tonic-gate * RETURN VALUE: NULL if error
1237*0Sstevel@tonic-gate * position of beginning rhs
1238*0Sstevel@tonic-gate *
1239*0Sstevel@tonic-gate * INPUT: the attribute value and mapping rule type
1240*0Sstevel@tonic-gate */
1241*0Sstevel@tonic-gate
1242*0Sstevel@tonic-gate static const char *
get_lhs_match(const char * s,const char * end_s,__nis_mapping_rlhs_t * lhs,__nis_mapping_item_type_t item_type)1243*0Sstevel@tonic-gate get_lhs_match(
1244*0Sstevel@tonic-gate const char *s,
1245*0Sstevel@tonic-gate const char *end_s,
1246*0Sstevel@tonic-gate __nis_mapping_rlhs_t *lhs,
1247*0Sstevel@tonic-gate __nis_mapping_item_type_t item_type)
1248*0Sstevel@tonic-gate {
1249*0Sstevel@tonic-gate token_type t;
1250*0Sstevel@tonic-gate const char *begin_token;
1251*0Sstevel@tonic-gate const char *end_token;
1252*0Sstevel@tonic-gate int n = 0;
1253*0Sstevel@tonic-gate int nElements = 0;
1254*0Sstevel@tonic-gate char *fmt_string = NULL;
1255*0Sstevel@tonic-gate __nis_mapping_format_t *base = NULL;
1256*0Sstevel@tonic-gate __nis_mapping_item_t *item = NULL;
1257*0Sstevel@tonic-gate __nis_mapping_item_t *itm;
1258*0Sstevel@tonic-gate __nis_mapping_element_t *e;
1259*0Sstevel@tonic-gate
1260*0Sstevel@tonic-gate /*
1261*0Sstevel@tonic-gate * lval = "(" formatspec "," namespec *("," namespec) ")"
1262*0Sstevel@tonic-gate */
1263*0Sstevel@tonic-gate
1264*0Sstevel@tonic-gate for (; p_error == no_parse_error; ) {
1265*0Sstevel@tonic-gate begin_token = s;
1266*0Sstevel@tonic-gate end_token = end_s;
1267*0Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t);
1268*0Sstevel@tonic-gate if (s == NULL || t != quoted_string_token) {
1269*0Sstevel@tonic-gate p_error = parse_internal_error;
1270*0Sstevel@tonic-gate break;
1271*0Sstevel@tonic-gate }
1272*0Sstevel@tonic-gate
1273*0Sstevel@tonic-gate
1274*0Sstevel@tonic-gate fmt_string = s_strndup(begin_token, end_token - begin_token);
1275*0Sstevel@tonic-gate if (fmt_string == NULL)
1276*0Sstevel@tonic-gate break;
1277*0Sstevel@tonic-gate
1278*0Sstevel@tonic-gate if (!get_mapping_format(fmt_string, &base, &n, NULL, FALSE))
1279*0Sstevel@tonic-gate break;
1280*0Sstevel@tonic-gate
1281*0Sstevel@tonic-gate for (n = 0; base[n].type != mmt_end; n++) {
1282*0Sstevel@tonic-gate if (base[n].type != mmt_item &&
1283*0Sstevel@tonic-gate base[n].type != mmt_berstring) {
1284*0Sstevel@tonic-gate if (base[n].type == mmt_berstring_null)
1285*0Sstevel@tonic-gate base[n].type = mmt_berstring;
1286*0Sstevel@tonic-gate continue;
1287*0Sstevel@tonic-gate }
1288*0Sstevel@tonic-gate s = skip_token(s, end_s, comma_token);
1289*0Sstevel@tonic-gate if (s == NULL) {
1290*0Sstevel@tonic-gate p_error = parse_not_enough_extract_items;
1291*0Sstevel@tonic-gate break;
1292*0Sstevel@tonic-gate }
1293*0Sstevel@tonic-gate begin_token = s;
1294*0Sstevel@tonic-gate end_token = end_s;
1295*0Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t);
1296*0Sstevel@tonic-gate if (s == NULL)
1297*0Sstevel@tonic-gate break;
1298*0Sstevel@tonic-gate if (t != string_token) {
1299*0Sstevel@tonic-gate p_error = parse_item_expected_error;
1300*0Sstevel@tonic-gate break;
1301*0Sstevel@tonic-gate }
1302*0Sstevel@tonic-gate itm = (__nis_mapping_item_t *)
1303*0Sstevel@tonic-gate s_realloc(item, (nElements + 1) *
1304*0Sstevel@tonic-gate sizeof (__nis_mapping_item_t));
1305*0Sstevel@tonic-gate if (itm == NULL)
1306*0Sstevel@tonic-gate break;
1307*0Sstevel@tonic-gate item = itm;
1308*0Sstevel@tonic-gate
1309*0Sstevel@tonic-gate s = get_mapping_item(begin_token, end_s,
1310*0Sstevel@tonic-gate &item[nElements], item_type);
1311*0Sstevel@tonic-gate if (s == NULL)
1312*0Sstevel@tonic-gate break;
1313*0Sstevel@tonic-gate nElements++;
1314*0Sstevel@tonic-gate }
1315*0Sstevel@tonic-gate if (p_error != no_parse_error)
1316*0Sstevel@tonic-gate break;
1317*0Sstevel@tonic-gate
1318*0Sstevel@tonic-gate s = skip_token(s, end_s, close_paren_token);
1319*0Sstevel@tonic-gate if (s == NULL)
1320*0Sstevel@tonic-gate break;
1321*0Sstevel@tonic-gate free(fmt_string);
1322*0Sstevel@tonic-gate fmt_string = NULL;
1323*0Sstevel@tonic-gate
1324*0Sstevel@tonic-gate if (nElements == 0) {
1325*0Sstevel@tonic-gate p_error = parse_no_match_item;
1326*0Sstevel@tonic-gate break;
1327*0Sstevel@tonic-gate }
1328*0Sstevel@tonic-gate e = (__nis_mapping_element_t *)s_calloc(1,
1329*0Sstevel@tonic-gate sizeof (__nis_mapping_element_t));
1330*0Sstevel@tonic-gate if (e == NULL)
1331*0Sstevel@tonic-gate break;
1332*0Sstevel@tonic-gate e->type = me_match;
1333*0Sstevel@tonic-gate e->element.match.numItems = nElements;
1334*0Sstevel@tonic-gate e->element.match.item = item;
1335*0Sstevel@tonic-gate e->element.match.fmt = base;
1336*0Sstevel@tonic-gate lhs->numElements = 1;
1337*0Sstevel@tonic-gate lhs->element = e;
1338*0Sstevel@tonic-gate
1339*0Sstevel@tonic-gate if (p_error == no_parse_error)
1340*0Sstevel@tonic-gate return (s);
1341*0Sstevel@tonic-gate }
1342*0Sstevel@tonic-gate if (item == NULL) {
1343*0Sstevel@tonic-gate for (n = 0; n < nElements; n++)
1344*0Sstevel@tonic-gate free_mapping_item(&item[n]);
1345*0Sstevel@tonic-gate free(item);
1346*0Sstevel@tonic-gate }
1347*0Sstevel@tonic-gate if (fmt_string != NULL)
1348*0Sstevel@tonic-gate free(fmt_string);
1349*0Sstevel@tonic-gate if (base != NULL)
1350*0Sstevel@tonic-gate free_mapping_format(base);
1351*0Sstevel@tonic-gate
1352*0Sstevel@tonic-gate return (NULL);
1353*0Sstevel@tonic-gate }
1354*0Sstevel@tonic-gate
1355*0Sstevel@tonic-gate /*
1356*0Sstevel@tonic-gate * FUNCTION: get_lhs_paren_item
1357*0Sstevel@tonic-gate *
1358*0Sstevel@tonic-gate * Parse left hand side of mapping rule attribute in case of
1359*0Sstevel@tonic-gate * (item1, ..., item-n)
1360*0Sstevel@tonic-gate *
1361*0Sstevel@tonic-gate * RETURN VALUE: NULL if error
1362*0Sstevel@tonic-gate * position of beginning rhs
1363*0Sstevel@tonic-gate *
1364*0Sstevel@tonic-gate * INPUT: the attribute value and mapping rule type
1365*0Sstevel@tonic-gate */
1366*0Sstevel@tonic-gate
1367*0Sstevel@tonic-gate static const char *
get_lhs_paren_item(const char * s,const char * end_s,__nis_mapping_rlhs_t * lhs,__nis_mapping_item_type_t item_type)1368*0Sstevel@tonic-gate get_lhs_paren_item(
1369*0Sstevel@tonic-gate const char *s,
1370*0Sstevel@tonic-gate const char *end_s,
1371*0Sstevel@tonic-gate __nis_mapping_rlhs_t *lhs,
1372*0Sstevel@tonic-gate __nis_mapping_item_type_t item_type)
1373*0Sstevel@tonic-gate {
1374*0Sstevel@tonic-gate token_type t;
1375*0Sstevel@tonic-gate const char *begin_token;
1376*0Sstevel@tonic-gate const char *end_token;
1377*0Sstevel@tonic-gate __nis_mapping_element_t *e = NULL;
1378*0Sstevel@tonic-gate int n = 0;
1379*0Sstevel@tonic-gate int i;
1380*0Sstevel@tonic-gate
1381*0Sstevel@tonic-gate /*
1382*0Sstevel@tonic-gate * "(" namespec *("," namespec) ")"
1383*0Sstevel@tonic-gate */
1384*0Sstevel@tonic-gate
1385*0Sstevel@tonic-gate for (;;) {
1386*0Sstevel@tonic-gate e = (__nis_mapping_element_t *)s_realloc(e, (n + 1) *
1387*0Sstevel@tonic-gate sizeof (__nis_mapping_element_t));
1388*0Sstevel@tonic-gate if (e == NULL)
1389*0Sstevel@tonic-gate break;
1390*0Sstevel@tonic-gate
1391*0Sstevel@tonic-gate s = get_mapping_item(s, end_s, &e[n].element.item,
1392*0Sstevel@tonic-gate item_type);
1393*0Sstevel@tonic-gate if (s == NULL)
1394*0Sstevel@tonic-gate break;
1395*0Sstevel@tonic-gate e[n].type = me_item;
1396*0Sstevel@tonic-gate n++;
1397*0Sstevel@tonic-gate
1398*0Sstevel@tonic-gate begin_token = s;
1399*0Sstevel@tonic-gate end_token = end_s;
1400*0Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t);
1401*0Sstevel@tonic-gate if (s != NULL && t == close_paren_token) {
1402*0Sstevel@tonic-gate lhs->numElements = n;
1403*0Sstevel@tonic-gate if (n == 1)
1404*0Sstevel@tonic-gate e[0].element.item.repeat = TRUE;
1405*0Sstevel@tonic-gate lhs->element = e;
1406*0Sstevel@tonic-gate return (s);
1407*0Sstevel@tonic-gate }
1408*0Sstevel@tonic-gate if (s == NULL || t != comma_token) {
1409*0Sstevel@tonic-gate p_error = parse_comma_expected_error;
1410*0Sstevel@tonic-gate break;
1411*0Sstevel@tonic-gate }
1412*0Sstevel@tonic-gate }
1413*0Sstevel@tonic-gate for (i = 0; i < n; i++)
1414*0Sstevel@tonic-gate free_mapping_element(&e[i]);
1415*0Sstevel@tonic-gate if (e != NULL)
1416*0Sstevel@tonic-gate free(e);
1417*0Sstevel@tonic-gate return (NULL);
1418*0Sstevel@tonic-gate }
1419*0Sstevel@tonic-gate
1420*0Sstevel@tonic-gate /*
1421*0Sstevel@tonic-gate * FUNCTION: get_rhs
1422*0Sstevel@tonic-gate *
1423*0Sstevel@tonic-gate * Parse right hand side of mapping rule attribute
1424*0Sstevel@tonic-gate *
1425*0Sstevel@tonic-gate * RETURN VALUE: NULL if error
1426*0Sstevel@tonic-gate * position of beginning next mapping rule
1427*0Sstevel@tonic-gate *
1428*0Sstevel@tonic-gate * INPUT: the attribute value and mapping rule type
1429*0Sstevel@tonic-gate */
1430*0Sstevel@tonic-gate
1431*0Sstevel@tonic-gate static const char *
get_rhs(const char * s,const char * end_s,__nis_mapping_rlhs_t * rhs,__nis_mapping_item_type_t item_type)1432*0Sstevel@tonic-gate get_rhs(
1433*0Sstevel@tonic-gate const char *s,
1434*0Sstevel@tonic-gate const char *end_s,
1435*0Sstevel@tonic-gate __nis_mapping_rlhs_t *rhs,
1436*0Sstevel@tonic-gate __nis_mapping_item_type_t item_type)
1437*0Sstevel@tonic-gate {
1438*0Sstevel@tonic-gate /*
1439*0Sstevel@tonic-gate * This handles the following cases:
1440*0Sstevel@tonic-gate * name me_item
1441*0Sstevel@tonic-gate * (name) me_item
1442*0Sstevel@tonic-gate * (fmt, name-list) me_print
1443*0Sstevel@tonic-gate * (item, fmt) me_extract
1444*0Sstevel@tonic-gate */
1445*0Sstevel@tonic-gate
1446*0Sstevel@tonic-gate token_type t;
1447*0Sstevel@tonic-gate const char *begin_token;
1448*0Sstevel@tonic-gate const char *end_token;
1449*0Sstevel@tonic-gate char *str = NULL;
1450*0Sstevel@tonic-gate __nis_mapping_format_t *fmt = NULL;
1451*0Sstevel@tonic-gate __nis_mapping_element_t *e = NULL;
1452*0Sstevel@tonic-gate __nis_mapping_item_t item;
1453*0Sstevel@tonic-gate int n;
1454*0Sstevel@tonic-gate
1455*0Sstevel@tonic-gate (void) memset(&item, 0, sizeof (item));
1456*0Sstevel@tonic-gate
1457*0Sstevel@tonic-gate for (; p_error == no_parse_error; ) {
1458*0Sstevel@tonic-gate begin_token = s;
1459*0Sstevel@tonic-gate end_token = end_s;
1460*0Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t);
1461*0Sstevel@tonic-gate if (s == NULL)
1462*0Sstevel@tonic-gate break;
1463*0Sstevel@tonic-gate
1464*0Sstevel@tonic-gate e = (__nis_mapping_element_t *)
1465*0Sstevel@tonic-gate s_calloc(1, sizeof (__nis_mapping_element_t));
1466*0Sstevel@tonic-gate if (e == NULL)
1467*0Sstevel@tonic-gate break;
1468*0Sstevel@tonic-gate
1469*0Sstevel@tonic-gate if (t == string_token) {
1470*0Sstevel@tonic-gate s = get_mapping_item(begin_token, end_s,
1471*0Sstevel@tonic-gate &e->element.item, item_type);
1472*0Sstevel@tonic-gate } else if (t == open_paren_token) {
1473*0Sstevel@tonic-gate begin_token = s;
1474*0Sstevel@tonic-gate end_token = end_s;
1475*0Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t);
1476*0Sstevel@tonic-gate if (s == NULL)
1477*0Sstevel@tonic-gate break;
1478*0Sstevel@tonic-gate if (t == string_token) {
1479*0Sstevel@tonic-gate /* (item, fmt) - me_extract */
1480*0Sstevel@tonic-gate /* (item, "c") - me_split */
1481*0Sstevel@tonic-gate s = get_mapping_item(begin_token, end_s,
1482*0Sstevel@tonic-gate &item, item_type);
1483*0Sstevel@tonic-gate if (s == NULL)
1484*0Sstevel@tonic-gate break;
1485*0Sstevel@tonic-gate begin_token = s;
1486*0Sstevel@tonic-gate end_token = end_s;
1487*0Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token,
1488*0Sstevel@tonic-gate &t);
1489*0Sstevel@tonic-gate if (s == NULL)
1490*0Sstevel@tonic-gate break;
1491*0Sstevel@tonic-gate else if (t == close_paren_token) {
1492*0Sstevel@tonic-gate item.repeat = TRUE;
1493*0Sstevel@tonic-gate e->element.item = item;
1494*0Sstevel@tonic-gate e->type = me_item;
1495*0Sstevel@tonic-gate rhs->numElements = 1;
1496*0Sstevel@tonic-gate rhs->element = e;
1497*0Sstevel@tonic-gate return (s);
1498*0Sstevel@tonic-gate } else if (t != comma_token) {
1499*0Sstevel@tonic-gate p_error = parse_comma_expected_error;
1500*0Sstevel@tonic-gate break;
1501*0Sstevel@tonic-gate }
1502*0Sstevel@tonic-gate
1503*0Sstevel@tonic-gate begin_token = s;
1504*0Sstevel@tonic-gate end_token = end_s;
1505*0Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token,
1506*0Sstevel@tonic-gate &t);
1507*0Sstevel@tonic-gate if (s == NULL || t != quoted_string_token) {
1508*0Sstevel@tonic-gate p_error =
1509*0Sstevel@tonic-gate parse_format_string_expected_error;
1510*0Sstevel@tonic-gate break;
1511*0Sstevel@tonic-gate }
1512*0Sstevel@tonic-gate
1513*0Sstevel@tonic-gate if (end_token == begin_token + 1 ||
1514*0Sstevel@tonic-gate *begin_token == ESCAPE_CHAR &&
1515*0Sstevel@tonic-gate end_token == begin_token + 2) {
1516*0Sstevel@tonic-gate e->type = me_split;
1517*0Sstevel@tonic-gate e->element.split.item = item;
1518*0Sstevel@tonic-gate e->element.split.delim = *begin_token;
1519*0Sstevel@tonic-gate } else {
1520*0Sstevel@tonic-gate str = s_strndup(begin_token,
1521*0Sstevel@tonic-gate end_token - begin_token);
1522*0Sstevel@tonic-gate if (str == NULL)
1523*0Sstevel@tonic-gate break;
1524*0Sstevel@tonic-gate if (!get_mapping_format(str, &fmt,
1525*0Sstevel@tonic-gate NULL, &n, FALSE))
1526*0Sstevel@tonic-gate break;
1527*0Sstevel@tonic-gate free(str);
1528*0Sstevel@tonic-gate str = NULL;
1529*0Sstevel@tonic-gate if (n != 1) {
1530*0Sstevel@tonic-gate p_error =
1531*0Sstevel@tonic-gate parse_bad_extract_format_spec;
1532*0Sstevel@tonic-gate break;
1533*0Sstevel@tonic-gate }
1534*0Sstevel@tonic-gate e->type = me_extract;
1535*0Sstevel@tonic-gate e->element.extract.item = item;
1536*0Sstevel@tonic-gate e->element.extract.fmt = fmt;
1537*0Sstevel@tonic-gate }
1538*0Sstevel@tonic-gate s = skip_token(s, end_s, close_paren_token);
1539*0Sstevel@tonic-gate } else if (t == quoted_string_token) {
1540*0Sstevel@tonic-gate /* (fmt, name-list) - me_print */
1541*0Sstevel@tonic-gate str = s_strndup(begin_token,
1542*0Sstevel@tonic-gate end_token - begin_token);
1543*0Sstevel@tonic-gate if (str == NULL)
1544*0Sstevel@tonic-gate break;
1545*0Sstevel@tonic-gate
1546*0Sstevel@tonic-gate s = get_print_mapping_element(s, end_s,
1547*0Sstevel@tonic-gate str, e, item_type);
1548*0Sstevel@tonic-gate free(str);
1549*0Sstevel@tonic-gate str = NULL;
1550*0Sstevel@tonic-gate } else {
1551*0Sstevel@tonic-gate p_error = parse_start_rhs_unrecognized;
1552*0Sstevel@tonic-gate break;
1553*0Sstevel@tonic-gate }
1554*0Sstevel@tonic-gate } else {
1555*0Sstevel@tonic-gate p_error = parse_start_rhs_unrecognized;
1556*0Sstevel@tonic-gate break;
1557*0Sstevel@tonic-gate }
1558*0Sstevel@tonic-gate if (s == NULL)
1559*0Sstevel@tonic-gate break;
1560*0Sstevel@tonic-gate rhs->numElements = 1;
1561*0Sstevel@tonic-gate rhs->element = e;
1562*0Sstevel@tonic-gate if (p_error == no_parse_error)
1563*0Sstevel@tonic-gate return (s);
1564*0Sstevel@tonic-gate }
1565*0Sstevel@tonic-gate if (str)
1566*0Sstevel@tonic-gate free(str);
1567*0Sstevel@tonic-gate if (fmt != NULL)
1568*0Sstevel@tonic-gate free_mapping_format(fmt);
1569*0Sstevel@tonic-gate if (e != NULL)
1570*0Sstevel@tonic-gate free_mapping_element(e);
1571*0Sstevel@tonic-gate free_mapping_item(&item);
1572*0Sstevel@tonic-gate
1573*0Sstevel@tonic-gate return (NULL);
1574*0Sstevel@tonic-gate }
1575*0Sstevel@tonic-gate
1576*0Sstevel@tonic-gate /*
1577*0Sstevel@tonic-gate * FUNCTION: get_print_mapping_element
1578*0Sstevel@tonic-gate *
1579*0Sstevel@tonic-gate * Parse a print mapping rule attribute in case of the form
1580*0Sstevel@tonic-gate * (fmt, name-list)
1581*0Sstevel@tonic-gate *
1582*0Sstevel@tonic-gate * RETURN VALUE: NULL if error
1583*0Sstevel@tonic-gate * position of beginning next mapping rule
1584*0Sstevel@tonic-gate *
1585*0Sstevel@tonic-gate * INPUT: the attribute value and mapping rule type
1586*0Sstevel@tonic-gate */
1587*0Sstevel@tonic-gate
1588*0Sstevel@tonic-gate static const char *
get_print_mapping_element(const char * s,const char * end_s,char * fmt_string,__nis_mapping_element_t * e,__nis_mapping_item_type_t item_type)1589*0Sstevel@tonic-gate get_print_mapping_element(
1590*0Sstevel@tonic-gate const char *s,
1591*0Sstevel@tonic-gate const char *end_s,
1592*0Sstevel@tonic-gate char *fmt_string,
1593*0Sstevel@tonic-gate __nis_mapping_element_t *e,
1594*0Sstevel@tonic-gate __nis_mapping_item_type_t item_type)
1595*0Sstevel@tonic-gate {
1596*0Sstevel@tonic-gate token_type t;
1597*0Sstevel@tonic-gate const char *begin_token;
1598*0Sstevel@tonic-gate const char *end_token;
1599*0Sstevel@tonic-gate char elide;
1600*0Sstevel@tonic-gate bool_t doElide;
1601*0Sstevel@tonic-gate __nis_mapping_format_t *base = NULL;
1602*0Sstevel@tonic-gate __nis_mapping_sub_element_t *subElement = NULL;
1603*0Sstevel@tonic-gate int n = 0;
1604*0Sstevel@tonic-gate int nSub = 0;
1605*0Sstevel@tonic-gate int numSubElements;
1606*0Sstevel@tonic-gate
1607*0Sstevel@tonic-gate for (; p_error == no_parse_error; ) {
1608*0Sstevel@tonic-gate if (!get_mapping_format(fmt_string, &base, &n,
1609*0Sstevel@tonic-gate &numSubElements, TRUE))
1610*0Sstevel@tonic-gate break;
1611*0Sstevel@tonic-gate subElement = (__nis_mapping_sub_element_t *)
1612*0Sstevel@tonic-gate s_calloc(numSubElements,
1613*0Sstevel@tonic-gate sizeof (__nis_mapping_sub_element_t));
1614*0Sstevel@tonic-gate if (subElement == NULL)
1615*0Sstevel@tonic-gate break;
1616*0Sstevel@tonic-gate for (n = 0; base[n].type != mmt_end; n++) {
1617*0Sstevel@tonic-gate if (base[n].type != mmt_item &&
1618*0Sstevel@tonic-gate base[n].type != mmt_berstring) {
1619*0Sstevel@tonic-gate if (base[n].type == mmt_berstring_null)
1620*0Sstevel@tonic-gate base[n].type = mmt_berstring;
1621*0Sstevel@tonic-gate continue;
1622*0Sstevel@tonic-gate }
1623*0Sstevel@tonic-gate if (nSub < numSubElements) {
1624*0Sstevel@tonic-gate s = skip_token(s, end_s, comma_token);
1625*0Sstevel@tonic-gate if (s == NULL) {
1626*0Sstevel@tonic-gate p_error = parse_bad_print_format;
1627*0Sstevel@tonic-gate break;
1628*0Sstevel@tonic-gate }
1629*0Sstevel@tonic-gate }
1630*0Sstevel@tonic-gate
1631*0Sstevel@tonic-gate /* namelist may have parens around it */
1632*0Sstevel@tonic-gate s = get_subElement(s, end_s, &subElement[nSub],
1633*0Sstevel@tonic-gate item_type);
1634*0Sstevel@tonic-gate if (s == NULL)
1635*0Sstevel@tonic-gate break;
1636*0Sstevel@tonic-gate nSub++;
1637*0Sstevel@tonic-gate }
1638*0Sstevel@tonic-gate if (p_error != no_parse_error)
1639*0Sstevel@tonic-gate break;
1640*0Sstevel@tonic-gate
1641*0Sstevel@tonic-gate begin_token = s;
1642*0Sstevel@tonic-gate end_token = end_s;
1643*0Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t);
1644*0Sstevel@tonic-gate if (s == NULL || t == no_token) {
1645*0Sstevel@tonic-gate p_error = parse_unexpected_data_end_rule;
1646*0Sstevel@tonic-gate break;
1647*0Sstevel@tonic-gate } else if (t == close_paren_token) {
1648*0Sstevel@tonic-gate doElide = FALSE;
1649*0Sstevel@tonic-gate elide = '\0';
1650*0Sstevel@tonic-gate } else if (t == comma_token) {
1651*0Sstevel@tonic-gate begin_token = s;
1652*0Sstevel@tonic-gate end_token = end_s;
1653*0Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t);
1654*0Sstevel@tonic-gate if (s != NULL && t == quoted_string_token &&
1655*0Sstevel@tonic-gate (end_token == begin_token + 1 ||
1656*0Sstevel@tonic-gate *begin_token == ESCAPE_CHAR &&
1657*0Sstevel@tonic-gate end_token == begin_token + 2)) {
1658*0Sstevel@tonic-gate if (numSubElements != 1 ||
1659*0Sstevel@tonic-gate subElement->type == me_extract ||
1660*0Sstevel@tonic-gate subElement->type == me_split) {
1661*0Sstevel@tonic-gate p_error = parse_cannot_elide;
1662*0Sstevel@tonic-gate break;
1663*0Sstevel@tonic-gate }
1664*0Sstevel@tonic-gate if (subElement->type == me_item &&
1665*0Sstevel@tonic-gate !subElement->element.item.repeat) {
1666*0Sstevel@tonic-gate p_error = parse_cannot_elide;
1667*0Sstevel@tonic-gate break;
1668*0Sstevel@tonic-gate }
1669*0Sstevel@tonic-gate elide = *begin_token;
1670*0Sstevel@tonic-gate doElide = TRUE;
1671*0Sstevel@tonic-gate
1672*0Sstevel@tonic-gate } else {
1673*0Sstevel@tonic-gate p_error = parse_bad_elide_char;
1674*0Sstevel@tonic-gate break;
1675*0Sstevel@tonic-gate }
1676*0Sstevel@tonic-gate s = skip_token(s, end_s, close_paren_token);
1677*0Sstevel@tonic-gate if (s == NULL)
1678*0Sstevel@tonic-gate break;
1679*0Sstevel@tonic-gate }
1680*0Sstevel@tonic-gate
1681*0Sstevel@tonic-gate e->type = me_print;
1682*0Sstevel@tonic-gate e->element.print.fmt = base;
1683*0Sstevel@tonic-gate e->element.print.numSubElements = numSubElements;
1684*0Sstevel@tonic-gate e->element.print.subElement = subElement;
1685*0Sstevel@tonic-gate e->element.print.elide = elide;
1686*0Sstevel@tonic-gate e->element.print.doElide = doElide;
1687*0Sstevel@tonic-gate
1688*0Sstevel@tonic-gate if (p_error == no_parse_error)
1689*0Sstevel@tonic-gate return (s);
1690*0Sstevel@tonic-gate }
1691*0Sstevel@tonic-gate if (base)
1692*0Sstevel@tonic-gate free_mapping_format(base);
1693*0Sstevel@tonic-gate if (subElement != NULL) {
1694*0Sstevel@tonic-gate for (n = 0; n < numSubElements; n++)
1695*0Sstevel@tonic-gate free_mapping_sub_element(&subElement[n]);
1696*0Sstevel@tonic-gate free(subElement);
1697*0Sstevel@tonic-gate }
1698*0Sstevel@tonic-gate
1699*0Sstevel@tonic-gate return (NULL);
1700*0Sstevel@tonic-gate }
1701*0Sstevel@tonic-gate
1702*0Sstevel@tonic-gate /*
1703*0Sstevel@tonic-gate * FUNCTION: get_mapping_item
1704*0Sstevel@tonic-gate *
1705*0Sstevel@tonic-gate * Parse attribute string to get mapping item
1706*0Sstevel@tonic-gate *
1707*0Sstevel@tonic-gate * RETURN VALUE: NULL if error
1708*0Sstevel@tonic-gate * position of beginning next token after item
1709*0Sstevel@tonic-gate *
1710*0Sstevel@tonic-gate * INPUT: the attribute value and mapping rule type
1711*0Sstevel@tonic-gate */
1712*0Sstevel@tonic-gate
1713*0Sstevel@tonic-gate static const char *
get_mapping_item(const char * s,const char * end_s,__nis_mapping_item_t * item,__nis_mapping_item_type_t type)1714*0Sstevel@tonic-gate get_mapping_item(
1715*0Sstevel@tonic-gate const char *s,
1716*0Sstevel@tonic-gate const char *end_s,
1717*0Sstevel@tonic-gate __nis_mapping_item_t *item,
1718*0Sstevel@tonic-gate __nis_mapping_item_type_t type)
1719*0Sstevel@tonic-gate {
1720*0Sstevel@tonic-gate token_type t;
1721*0Sstevel@tonic-gate const char *begin_token;
1722*0Sstevel@tonic-gate const char *end_token;
1723*0Sstevel@tonic-gate char *name = NULL;
1724*0Sstevel@tonic-gate char *index_string;
1725*0Sstevel@tonic-gate const char *s_sav;
1726*0Sstevel@tonic-gate int len;
1727*0Sstevel@tonic-gate
1728*0Sstevel@tonic-gate (void) memset(item, 0, sizeof (*item));
1729*0Sstevel@tonic-gate
1730*0Sstevel@tonic-gate /*
1731*0Sstevel@tonic-gate * A namepec is defined as follows:
1732*0Sstevel@tonic-gate * namespec = ["ldap:"] attrspec [searchTriple] |
1733*0Sstevel@tonic-gate * ["nis+:"] colspec [objectspec]
1734*0Sstevel@tonic-gate *
1735*0Sstevel@tonic-gate * The form of the item is assumed to be as follows:
1736*0Sstevel@tonic-gate * ["ldap:"] attrspec [searchTriple]
1737*0Sstevel@tonic-gate * attrspec = attribute | "(" attribute ")"
1738*0Sstevel@tonic-gate * searchTriple = ":" [baseDN] ["?" [scope] ["?" [filter]]]
1739*0Sstevel@tonic-gate * baseDN = Base DN for search
1740*0Sstevel@tonic-gate * scope = "base" | "one" | "sub"
1741*0Sstevel@tonic-gate * filter = LDAP search filter
1742*0Sstevel@tonic-gate *
1743*0Sstevel@tonic-gate * The form of the objectspec is as follows:
1744*0Sstevel@tonic-gate * ["nis+:"] colspec [objectspec]
1745*0Sstevel@tonic-gate * objectspec = objectname | "[" indexlist "]" tablename
1746*0Sstevel@tonic-gate * objectname = The name of a NIS+ object
1747*0Sstevel@tonic-gate * tablename = The name of a NIS+ table
1748*0Sstevel@tonic-gate * indexlist = colspec ["," colspec]
1749*0Sstevel@tonic-gate * colspec = colname "=" colvalue
1750*0Sstevel@tonic-gate * colname = The name of a column in the table
1751*0Sstevel@tonic-gate * colvalue = colvaluestring | \" colvaluestring \"
1752*0Sstevel@tonic-gate */
1753*0Sstevel@tonic-gate
1754*0Sstevel@tonic-gate for (; p_error == no_parse_error; ) {
1755*0Sstevel@tonic-gate while (s < end_s && is_whitespace(*s))
1756*0Sstevel@tonic-gate s++;
1757*0Sstevel@tonic-gate len = end_s - s;
1758*0Sstevel@tonic-gate if (yp2ldap) {
1759*0Sstevel@tonic-gate if ((begin_token = skip_string("ldap:", s,
1760*0Sstevel@tonic-gate len)) != NULL) {
1761*0Sstevel@tonic-gate item->type = mit_ldap;
1762*0Sstevel@tonic-gate } else if ((begin_token = skip_string("yp:", s,
1763*0Sstevel@tonic-gate len)) != NULL) {
1764*0Sstevel@tonic-gate item->type = mit_nisplus;
1765*0Sstevel@tonic-gate } else {
1766*0Sstevel@tonic-gate item->type = type;
1767*0Sstevel@tonic-gate begin_token = s;
1768*0Sstevel@tonic-gate }
1769*0Sstevel@tonic-gate } else {
1770*0Sstevel@tonic-gate if ((begin_token = skip_string("ldap:", s,
1771*0Sstevel@tonic-gate len)) != NULL) {
1772*0Sstevel@tonic-gate item->type = mit_ldap;
1773*0Sstevel@tonic-gate } else if ((begin_token = skip_string("nis+:", s,
1774*0Sstevel@tonic-gate len)) != NULL) {
1775*0Sstevel@tonic-gate item->type = mit_nisplus;
1776*0Sstevel@tonic-gate } else if ((begin_token = skip_string("nisplus:", s,
1777*0Sstevel@tonic-gate len)) != NULL) {
1778*0Sstevel@tonic-gate item->type = mit_nisplus;
1779*0Sstevel@tonic-gate } else {
1780*0Sstevel@tonic-gate item->type = type;
1781*0Sstevel@tonic-gate begin_token = s;
1782*0Sstevel@tonic-gate }
1783*0Sstevel@tonic-gate }
1784*0Sstevel@tonic-gate
1785*0Sstevel@tonic-gate end_token = end_s;
1786*0Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t);
1787*0Sstevel@tonic-gate if (s == NULL || t != string_token) {
1788*0Sstevel@tonic-gate p_error = parse_bad_item_format;
1789*0Sstevel@tonic-gate break;
1790*0Sstevel@tonic-gate }
1791*0Sstevel@tonic-gate
1792*0Sstevel@tonic-gate item->name = s_strndup_esc(begin_token,
1793*0Sstevel@tonic-gate end_token - begin_token);
1794*0Sstevel@tonic-gate if (item->name == NULL)
1795*0Sstevel@tonic-gate break;
1796*0Sstevel@tonic-gate if (item->type == mit_ldap) {
1797*0Sstevel@tonic-gate item->searchSpec.triple.scope = LDAP_SCOPE_UNKNOWN;
1798*0Sstevel@tonic-gate begin_token = s;
1799*0Sstevel@tonic-gate end_token = end_s;
1800*0Sstevel@tonic-gate s_sav = s;
1801*0Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t);
1802*0Sstevel@tonic-gate if (s != NULL && t == colon_token) {
1803*0Sstevel@tonic-gate s = get_search_triple(s, end_s,
1804*0Sstevel@tonic-gate &item->searchSpec.triple);
1805*0Sstevel@tonic-gate if (s == NULL)
1806*0Sstevel@tonic-gate break;
1807*0Sstevel@tonic-gate } else
1808*0Sstevel@tonic-gate s = s_sav;
1809*0Sstevel@tonic-gate } else if (item->type == mit_nisplus) {
1810*0Sstevel@tonic-gate while (s < end_s && is_whitespace(*s))
1811*0Sstevel@tonic-gate s++;
1812*0Sstevel@tonic-gate
1813*0Sstevel@tonic-gate if (s < end_s && *s == OPEN_BRACKET) {
1814*0Sstevel@tonic-gate index_string = getIndex(&s, end_s);
1815*0Sstevel@tonic-gate if (index_string == NULL)
1816*0Sstevel@tonic-gate break;
1817*0Sstevel@tonic-gate (void) parse_index(index_string,
1818*0Sstevel@tonic-gate index_string + strlen(index_string),
1819*0Sstevel@tonic-gate &item->searchSpec.obj.index);
1820*0Sstevel@tonic-gate free(index_string);
1821*0Sstevel@tonic-gate if (p_error != no_parse_error)
1822*0Sstevel@tonic-gate break;
1823*0Sstevel@tonic-gate }
1824*0Sstevel@tonic-gate s_sav = s;
1825*0Sstevel@tonic-gate begin_token = s;
1826*0Sstevel@tonic-gate end_token = end_s;
1827*0Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t);
1828*0Sstevel@tonic-gate if (s != NULL && t == string_token) {
1829*0Sstevel@tonic-gate name = s_strndup_esc(begin_token,
1830*0Sstevel@tonic-gate end_token - begin_token);
1831*0Sstevel@tonic-gate if (name == NULL)
1832*0Sstevel@tonic-gate break;
1833*0Sstevel@tonic-gate item->searchSpec.obj.name = name;
1834*0Sstevel@tonic-gate } else
1835*0Sstevel@tonic-gate s = s_sav;
1836*0Sstevel@tonic-gate }
1837*0Sstevel@tonic-gate if (p_error == no_parse_error)
1838*0Sstevel@tonic-gate return (s);
1839*0Sstevel@tonic-gate }
1840*0Sstevel@tonic-gate free_mapping_item(item);
1841*0Sstevel@tonic-gate (void) memset(item, 0, sizeof (*item));
1842*0Sstevel@tonic-gate if (name == NULL)
1843*0Sstevel@tonic-gate free(name);
1844*0Sstevel@tonic-gate return (NULL);
1845*0Sstevel@tonic-gate }
1846*0Sstevel@tonic-gate
1847*0Sstevel@tonic-gate static const char *
get_print_sub_element(const char * s,const char * end_s,__nis_mapping_item_type_t type,__nis_mapping_sub_element_t * sub)1848*0Sstevel@tonic-gate get_print_sub_element(const char *s,
1849*0Sstevel@tonic-gate const char *end_s,
1850*0Sstevel@tonic-gate __nis_mapping_item_type_t type,
1851*0Sstevel@tonic-gate __nis_mapping_sub_element_t *sub)
1852*0Sstevel@tonic-gate {
1853*0Sstevel@tonic-gate
1854*0Sstevel@tonic-gate int k;
1855*0Sstevel@tonic-gate int n;
1856*0Sstevel@tonic-gate const char *begin_token;
1857*0Sstevel@tonic-gate const char *end_token;
1858*0Sstevel@tonic-gate token_type t;
1859*0Sstevel@tonic-gate __nis_mapping_format_t *base;
1860*0Sstevel@tonic-gate __nis_mapping_item_t *print_item;
1861*0Sstevel@tonic-gate
1862*0Sstevel@tonic-gate k = 0;
1863*0Sstevel@tonic-gate base = sub->element.print.fmt;
1864*0Sstevel@tonic-gate print_item = sub->element.print.item;
1865*0Sstevel@tonic-gate sub->element.print.doElide = FALSE;
1866*0Sstevel@tonic-gate sub->element.print.elide = '\0';
1867*0Sstevel@tonic-gate
1868*0Sstevel@tonic-gate for (n = 0; base[n].type != mmt_end; n++) {
1869*0Sstevel@tonic-gate if (base[n].type != mmt_item && base[n].type != mmt_berstring) {
1870*0Sstevel@tonic-gate if (base[n].type == mmt_berstring_null)
1871*0Sstevel@tonic-gate base[n].type = mmt_berstring;
1872*0Sstevel@tonic-gate continue;
1873*0Sstevel@tonic-gate }
1874*0Sstevel@tonic-gate s = skip_token(s, end_s, comma_token);
1875*0Sstevel@tonic-gate if (s == NULL) {
1876*0Sstevel@tonic-gate p_error = parse_bad_print_format;
1877*0Sstevel@tonic-gate break;
1878*0Sstevel@tonic-gate }
1879*0Sstevel@tonic-gate
1880*0Sstevel@tonic-gate begin_token = s;
1881*0Sstevel@tonic-gate end_token = end_s;
1882*0Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t);
1883*0Sstevel@tonic-gate if (s == NULL)
1884*0Sstevel@tonic-gate break;
1885*0Sstevel@tonic-gate /*
1886*0Sstevel@tonic-gate * Determine if of the form
1887*0Sstevel@tonic-gate * ("fmt", (item), "delim") or
1888*0Sstevel@tonic-gate * ("fmt", item1, item2, ..., item n)
1889*0Sstevel@tonic-gate */
1890*0Sstevel@tonic-gate if (t == open_paren_token) {
1891*0Sstevel@tonic-gate if (sub->element.print.numItems != 1) {
1892*0Sstevel@tonic-gate p_error = parse_invalid_print_arg;
1893*0Sstevel@tonic-gate break;
1894*0Sstevel@tonic-gate }
1895*0Sstevel@tonic-gate s = get_mapping_item(s, end_s, &print_item[k++], type);
1896*0Sstevel@tonic-gate s = skip_token(s, end_s, close_paren_token);
1897*0Sstevel@tonic-gate s = skip_token(s, end_s, comma_token);
1898*0Sstevel@tonic-gate if (s == NULL) {
1899*0Sstevel@tonic-gate p_error = parse_bad_print_format;
1900*0Sstevel@tonic-gate break;
1901*0Sstevel@tonic-gate }
1902*0Sstevel@tonic-gate begin_token = s;
1903*0Sstevel@tonic-gate end_token = end_s;
1904*0Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t);
1905*0Sstevel@tonic-gate if (s == NULL)
1906*0Sstevel@tonic-gate break;
1907*0Sstevel@tonic-gate if (t != quoted_string_token ||
1908*0Sstevel@tonic-gate begin_token + 1 != end_token) {
1909*0Sstevel@tonic-gate p_error = parse_bad_elide_char;
1910*0Sstevel@tonic-gate break;
1911*0Sstevel@tonic-gate }
1912*0Sstevel@tonic-gate sub->element.print.elide = *begin_token;
1913*0Sstevel@tonic-gate sub->element.print.doElide = TRUE;
1914*0Sstevel@tonic-gate print_item[0].repeat = TRUE;
1915*0Sstevel@tonic-gate break;
1916*0Sstevel@tonic-gate }
1917*0Sstevel@tonic-gate s = get_mapping_item(begin_token, end_s,
1918*0Sstevel@tonic-gate &print_item[k++], type);
1919*0Sstevel@tonic-gate if (s == NULL)
1920*0Sstevel@tonic-gate break;
1921*0Sstevel@tonic-gate
1922*0Sstevel@tonic-gate if (p_error != no_parse_error)
1923*0Sstevel@tonic-gate break;
1924*0Sstevel@tonic-gate }
1925*0Sstevel@tonic-gate
1926*0Sstevel@tonic-gate return (p_error == no_parse_error ? s : NULL);
1927*0Sstevel@tonic-gate }
1928*0Sstevel@tonic-gate
1929*0Sstevel@tonic-gate /*
1930*0Sstevel@tonic-gate * FUNCTION: get_subElement
1931*0Sstevel@tonic-gate *
1932*0Sstevel@tonic-gate * Parse attribute string to get sub element item
1933*0Sstevel@tonic-gate *
1934*0Sstevel@tonic-gate * RETURN VALUE: NULL if error
1935*0Sstevel@tonic-gate * position of beginning next token after item
1936*0Sstevel@tonic-gate *
1937*0Sstevel@tonic-gate * INPUT: the attribute value and mapping rule type
1938*0Sstevel@tonic-gate */
1939*0Sstevel@tonic-gate
1940*0Sstevel@tonic-gate static const char *
get_subElement(const char * s,const char * end_s,__nis_mapping_sub_element_t * subelement,__nis_mapping_item_type_t type)1941*0Sstevel@tonic-gate get_subElement(
1942*0Sstevel@tonic-gate const char *s,
1943*0Sstevel@tonic-gate const char *end_s,
1944*0Sstevel@tonic-gate __nis_mapping_sub_element_t *subelement,
1945*0Sstevel@tonic-gate __nis_mapping_item_type_t type)
1946*0Sstevel@tonic-gate {
1947*0Sstevel@tonic-gate token_type t;
1948*0Sstevel@tonic-gate const char *begin_token;
1949*0Sstevel@tonic-gate const char *end_token;
1950*0Sstevel@tonic-gate char *fmt_string;
1951*0Sstevel@tonic-gate __nis_mapping_item_t item;
1952*0Sstevel@tonic-gate __nis_mapping_element_type_t e_type;
1953*0Sstevel@tonic-gate __nis_mapping_item_t *print_item = NULL;
1954*0Sstevel@tonic-gate __nis_mapping_format_t *base = NULL;
1955*0Sstevel@tonic-gate int n = 0;
1956*0Sstevel@tonic-gate int numItems = 0;
1957*0Sstevel@tonic-gate unsigned char delim;
1958*0Sstevel@tonic-gate __nis_mapping_sub_element_t sub;
1959*0Sstevel@tonic-gate
1960*0Sstevel@tonic-gate /*
1961*0Sstevel@tonic-gate * What is the form of we are expecting here
1962*0Sstevel@tonic-gate * item me_item
1963*0Sstevel@tonic-gate * (item) me_item
1964*0Sstevel@tonic-gate * ("fmt", item1, item2, ..., item n) me_print
1965*0Sstevel@tonic-gate * ("fmt", (item), "elide") me_print
1966*0Sstevel@tonic-gate * (name, "delim") me_split
1967*0Sstevel@tonic-gate * (item, "fmt") me_extract
1968*0Sstevel@tonic-gate */
1969*0Sstevel@tonic-gate (void) memset(&item, 0, sizeof (item));
1970*0Sstevel@tonic-gate
1971*0Sstevel@tonic-gate for (; p_error == no_parse_error; ) {
1972*0Sstevel@tonic-gate begin_token = s;
1973*0Sstevel@tonic-gate end_token = end_s;
1974*0Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t);
1975*0Sstevel@tonic-gate if (s == NULL)
1976*0Sstevel@tonic-gate break;
1977*0Sstevel@tonic-gate if (t == string_token) { /* me_item */
1978*0Sstevel@tonic-gate s = get_mapping_item(begin_token, end_s,
1979*0Sstevel@tonic-gate &subelement->element.item, type);
1980*0Sstevel@tonic-gate if (s == NULL)
1981*0Sstevel@tonic-gate break;
1982*0Sstevel@tonic-gate subelement->type = me_item;
1983*0Sstevel@tonic-gate return (s);
1984*0Sstevel@tonic-gate } else if (t != open_paren_token) {
1985*0Sstevel@tonic-gate p_error = parse_item_expected_error;
1986*0Sstevel@tonic-gate break;
1987*0Sstevel@tonic-gate }
1988*0Sstevel@tonic-gate
1989*0Sstevel@tonic-gate begin_token = s;
1990*0Sstevel@tonic-gate end_token = end_s;
1991*0Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t);
1992*0Sstevel@tonic-gate if (s == NULL)
1993*0Sstevel@tonic-gate break;
1994*0Sstevel@tonic-gate
1995*0Sstevel@tonic-gate if (t != string_token && t != quoted_string_token) {
1996*0Sstevel@tonic-gate p_error = parse_item_expected_error;
1997*0Sstevel@tonic-gate break;
1998*0Sstevel@tonic-gate }
1999*0Sstevel@tonic-gate e_type = me_print;
2000*0Sstevel@tonic-gate if (t == string_token) {
2001*0Sstevel@tonic-gate /* me_item, me_extract or me_split */
2002*0Sstevel@tonic-gate s = get_mapping_item(begin_token, end_s, &item, type);
2003*0Sstevel@tonic-gate if (s == NULL)
2004*0Sstevel@tonic-gate break;
2005*0Sstevel@tonic-gate
2006*0Sstevel@tonic-gate begin_token = s;
2007*0Sstevel@tonic-gate end_token = end_s;
2008*0Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t);
2009*0Sstevel@tonic-gate if (s == NULL) {
2010*0Sstevel@tonic-gate p_error = parse_unexpected_data_end_rule;
2011*0Sstevel@tonic-gate break;
2012*0Sstevel@tonic-gate } else if (t == close_paren_token) {
2013*0Sstevel@tonic-gate subelement->type = me_item;
2014*0Sstevel@tonic-gate item.repeat = TRUE;
2015*0Sstevel@tonic-gate subelement->element.item = item;
2016*0Sstevel@tonic-gate if (yp2ldap) {
2017*0Sstevel@tonic-gate while (s < end_s && is_whitespace(*s))
2018*0Sstevel@tonic-gate s++;
2019*0Sstevel@tonic-gate if (s == end_s) {
2020*0Sstevel@tonic-gate p_error =
2021*0Sstevel@tonic-gate parse_unexpected_data_end_rule;
2022*0Sstevel@tonic-gate break;
2023*0Sstevel@tonic-gate }
2024*0Sstevel@tonic-gate if (*s == DASH_CHAR && s < end_s) {
2025*0Sstevel@tonic-gate s++;
2026*0Sstevel@tonic-gate while (s < end_s &&
2027*0Sstevel@tonic-gate is_whitespace(*s))
2028*0Sstevel@tonic-gate s++;
2029*0Sstevel@tonic-gate begin_token = s;
2030*0Sstevel@tonic-gate end_token = end_s;
2031*0Sstevel@tonic-gate
2032*0Sstevel@tonic-gate subelement->element.item.exItem
2033*0Sstevel@tonic-gate =
2034*0Sstevel@tonic-gate (__nis_mapping_item_t *)
2035*0Sstevel@tonic-gate s_malloc(sizeof (__nis_mapping_item_t));
2036*0Sstevel@tonic-gate if (!subelement->
2037*0Sstevel@tonic-gate element.item.exItem)
2038*0Sstevel@tonic-gate break;
2039*0Sstevel@tonic-gate s = get_mapping_item(s, end_s,
2040*0Sstevel@tonic-gate subelement->
2041*0Sstevel@tonic-gate element.item.exItem,
2042*0Sstevel@tonic-gate type);
2043*0Sstevel@tonic-gate if (s == NULL) {
2044*0Sstevel@tonic-gate p_error =
2045*0Sstevel@tonic-gate parse_internal_error;
2046*0Sstevel@tonic-gate free_mapping_item(
2047*0Sstevel@tonic-gate subelement->
2048*0Sstevel@tonic-gate element.item.exItem);
2049*0Sstevel@tonic-gate subelement->
2050*0Sstevel@tonic-gate element.item.exItem =
2051*0Sstevel@tonic-gate NULL;
2052*0Sstevel@tonic-gate break;
2053*0Sstevel@tonic-gate }
2054*0Sstevel@tonic-gate }
2055*0Sstevel@tonic-gate }
2056*0Sstevel@tonic-gate return (s);
2057*0Sstevel@tonic-gate } else if (t != comma_token) {
2058*0Sstevel@tonic-gate p_error = parse_comma_expected_error;
2059*0Sstevel@tonic-gate break;
2060*0Sstevel@tonic-gate }
2061*0Sstevel@tonic-gate
2062*0Sstevel@tonic-gate begin_token = s;
2063*0Sstevel@tonic-gate end_token = end_s;
2064*0Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t);
2065*0Sstevel@tonic-gate if (s == NULL || t != quoted_string_token) {
2066*0Sstevel@tonic-gate p_error = parse_format_string_expected_error;
2067*0Sstevel@tonic-gate break;
2068*0Sstevel@tonic-gate }
2069*0Sstevel@tonic-gate if (end_token == begin_token + 1 ||
2070*0Sstevel@tonic-gate *begin_token == ESCAPE_CHAR &&
2071*0Sstevel@tonic-gate end_token == begin_token + 2) {
2072*0Sstevel@tonic-gate /* me_split */
2073*0Sstevel@tonic-gate delim = (unsigned char)end_token[-1];
2074*0Sstevel@tonic-gate s = skip_token(s, end_s, close_paren_token);
2075*0Sstevel@tonic-gate if (s == NULL)
2076*0Sstevel@tonic-gate break;
2077*0Sstevel@tonic-gate subelement->element.split.item = item;
2078*0Sstevel@tonic-gate subelement->element.split.delim = delim;
2079*0Sstevel@tonic-gate subelement->type = me_split;
2080*0Sstevel@tonic-gate return (s);
2081*0Sstevel@tonic-gate }
2082*0Sstevel@tonic-gate e_type = me_extract;
2083*0Sstevel@tonic-gate }
2084*0Sstevel@tonic-gate fmt_string = s_strndup(begin_token, end_token - begin_token);
2085*0Sstevel@tonic-gate if (fmt_string == NULL)
2086*0Sstevel@tonic-gate break;
2087*0Sstevel@tonic-gate if (!get_mapping_format(fmt_string, &base, &n, &numItems,
2088*0Sstevel@tonic-gate e_type == me_print)) {
2089*0Sstevel@tonic-gate free(fmt_string);
2090*0Sstevel@tonic-gate break;
2091*0Sstevel@tonic-gate }
2092*0Sstevel@tonic-gate free(fmt_string);
2093*0Sstevel@tonic-gate
2094*0Sstevel@tonic-gate if (numItems != 1 && e_type == me_extract) {
2095*0Sstevel@tonic-gate p_error = numItems == 0 ?
2096*0Sstevel@tonic-gate parse_not_enough_extract_items :
2097*0Sstevel@tonic-gate parse_too_many_extract_items;
2098*0Sstevel@tonic-gate break;
2099*0Sstevel@tonic-gate } else if (numItems > 0 && e_type == me_print) {
2100*0Sstevel@tonic-gate print_item = (__nis_mapping_item_t *)s_calloc(numItems,
2101*0Sstevel@tonic-gate sizeof (__nis_mapping_item_t));
2102*0Sstevel@tonic-gate if (print_item == NULL)
2103*0Sstevel@tonic-gate break;
2104*0Sstevel@tonic-gate }
2105*0Sstevel@tonic-gate
2106*0Sstevel@tonic-gate if (e_type == me_print) {
2107*0Sstevel@tonic-gate sub.element.print.numItems = numItems;
2108*0Sstevel@tonic-gate sub.element.print.fmt = base;
2109*0Sstevel@tonic-gate sub.element.print.item = print_item;
2110*0Sstevel@tonic-gate s = get_print_sub_element(s, end_s, type, &sub);
2111*0Sstevel@tonic-gate if (s == NULL)
2112*0Sstevel@tonic-gate break;
2113*0Sstevel@tonic-gate }
2114*0Sstevel@tonic-gate s = skip_token(s, end_s, close_paren_token);
2115*0Sstevel@tonic-gate if (s == NULL)
2116*0Sstevel@tonic-gate break;
2117*0Sstevel@tonic-gate
2118*0Sstevel@tonic-gate subelement->type = e_type;
2119*0Sstevel@tonic-gate if (e_type == me_extract) {
2120*0Sstevel@tonic-gate subelement->element.extract.fmt = base;
2121*0Sstevel@tonic-gate subelement->element.extract.item = item;
2122*0Sstevel@tonic-gate } else {
2123*0Sstevel@tonic-gate subelement->type = me_print;
2124*0Sstevel@tonic-gate subelement->element.print.fmt = base;
2125*0Sstevel@tonic-gate subelement->element.print.numItems = numItems;
2126*0Sstevel@tonic-gate subelement->element.print.item = print_item;
2127*0Sstevel@tonic-gate subelement->element.print.doElide =
2128*0Sstevel@tonic-gate sub.element.print.doElide;
2129*0Sstevel@tonic-gate subelement->element.print.elide =
2130*0Sstevel@tonic-gate sub.element.print.elide;
2131*0Sstevel@tonic-gate }
2132*0Sstevel@tonic-gate if (p_error == no_parse_error)
2133*0Sstevel@tonic-gate return (s);
2134*0Sstevel@tonic-gate }
2135*0Sstevel@tonic-gate free_mapping_item(&item);
2136*0Sstevel@tonic-gate if (base != NULL)
2137*0Sstevel@tonic-gate free_mapping_format(base);
2138*0Sstevel@tonic-gate if (print_item) {
2139*0Sstevel@tonic-gate for (n = 0; n < numItems; n++)
2140*0Sstevel@tonic-gate free_mapping_item(&print_item[n]);
2141*0Sstevel@tonic-gate free(print_item);
2142*0Sstevel@tonic-gate }
2143*0Sstevel@tonic-gate
2144*0Sstevel@tonic-gate return (NULL);
2145*0Sstevel@tonic-gate }
2146*0Sstevel@tonic-gate
2147*0Sstevel@tonic-gate /*
2148*0Sstevel@tonic-gate * FUNCTION: skip_get_dn
2149*0Sstevel@tonic-gate *
2150*0Sstevel@tonic-gate * Get first token after dn
2151*0Sstevel@tonic-gate *
2152*0Sstevel@tonic-gate * RETURN VALUE: NULL if error (not valid dn)
2153*0Sstevel@tonic-gate * position of beginning next token after dn
2154*0Sstevel@tonic-gate *
2155*0Sstevel@tonic-gate * INPUT: the attribute value
2156*0Sstevel@tonic-gate */
2157*0Sstevel@tonic-gate
2158*0Sstevel@tonic-gate const char *
skip_get_dn(const char * dn,const char * end)2159*0Sstevel@tonic-gate skip_get_dn(const char *dn, const char *end)
2160*0Sstevel@tonic-gate {
2161*0Sstevel@tonic-gate size_t len = 0;
2162*0Sstevel@tonic-gate bool_t in_quote = FALSE;
2163*0Sstevel@tonic-gate bool_t goteq = FALSE;
2164*0Sstevel@tonic-gate bool_t gotch = FALSE;
2165*0Sstevel@tonic-gate bool_t done = FALSE;
2166*0Sstevel@tonic-gate bool_t last_comma = FALSE;
2167*0Sstevel@tonic-gate const char *last_dn = dn;
2168*0Sstevel@tonic-gate
2169*0Sstevel@tonic-gate while (!done) {
2170*0Sstevel@tonic-gate dn += len;
2171*0Sstevel@tonic-gate if (last_comma) {
2172*0Sstevel@tonic-gate last_dn = dn;
2173*0Sstevel@tonic-gate last_comma = FALSE;
2174*0Sstevel@tonic-gate }
2175*0Sstevel@tonic-gate if (dn >= end)
2176*0Sstevel@tonic-gate break;
2177*0Sstevel@tonic-gate len = 1;
2178*0Sstevel@tonic-gate switch (*dn) {
2179*0Sstevel@tonic-gate case ESCAPE_CHAR:
2180*0Sstevel@tonic-gate len = 2;
2181*0Sstevel@tonic-gate gotch = TRUE;
2182*0Sstevel@tonic-gate break;
2183*0Sstevel@tonic-gate case DOUBLE_QUOTE_CHAR:
2184*0Sstevel@tonic-gate in_quote = !in_quote;
2185*0Sstevel@tonic-gate break;
2186*0Sstevel@tonic-gate case QUESTION_MARK:
2187*0Sstevel@tonic-gate case CLOSE_PAREN_CHAR:
2188*0Sstevel@tonic-gate case COLON_CHAR:
2189*0Sstevel@tonic-gate done = !in_quote;
2190*0Sstevel@tonic-gate /* FALLTHRU */
2191*0Sstevel@tonic-gate case SEMI_COLON_CHAR:
2192*0Sstevel@tonic-gate case PLUS_SIGN:
2193*0Sstevel@tonic-gate case COMMA_CHAR:
2194*0Sstevel@tonic-gate if (!in_quote) {
2195*0Sstevel@tonic-gate if (!goteq || !gotch)
2196*0Sstevel@tonic-gate return (last_dn);
2197*0Sstevel@tonic-gate goteq = FALSE;
2198*0Sstevel@tonic-gate gotch = FALSE;
2199*0Sstevel@tonic-gate if (*dn != PLUS_SIGN)
2200*0Sstevel@tonic-gate last_dn = dn;
2201*0Sstevel@tonic-gate last_comma = *dn == COMMA_CHAR;
2202*0Sstevel@tonic-gate } else {
2203*0Sstevel@tonic-gate gotch = TRUE;
2204*0Sstevel@tonic-gate }
2205*0Sstevel@tonic-gate break;
2206*0Sstevel@tonic-gate case EQUAL_CHAR:
2207*0Sstevel@tonic-gate if (!in_quote) {
2208*0Sstevel@tonic-gate if (!gotch || goteq)
2209*0Sstevel@tonic-gate return (NULL);
2210*0Sstevel@tonic-gate goteq = TRUE;
2211*0Sstevel@tonic-gate gotch = FALSE;
2212*0Sstevel@tonic-gate } else {
2213*0Sstevel@tonic-gate gotch = TRUE;
2214*0Sstevel@tonic-gate }
2215*0Sstevel@tonic-gate break;
2216*0Sstevel@tonic-gate default:
2217*0Sstevel@tonic-gate if (!is_whitespace(*dn))
2218*0Sstevel@tonic-gate gotch = TRUE;
2219*0Sstevel@tonic-gate break;
2220*0Sstevel@tonic-gate }
2221*0Sstevel@tonic-gate }
2222*0Sstevel@tonic-gate
2223*0Sstevel@tonic-gate if (dn == end) {
2224*0Sstevel@tonic-gate if (!in_quote && goteq && gotch)
2225*0Sstevel@tonic-gate last_dn = dn;
2226*0Sstevel@tonic-gate }
2227*0Sstevel@tonic-gate
2228*0Sstevel@tonic-gate return (last_dn);
2229*0Sstevel@tonic-gate }
2230*0Sstevel@tonic-gate
2231*0Sstevel@tonic-gate /*
2232*0Sstevel@tonic-gate * FUNCTION: get_ldap_filter_element
2233*0Sstevel@tonic-gate *
2234*0Sstevel@tonic-gate * Get an ldap filter element for a given string
2235*0Sstevel@tonic-gate *
2236*0Sstevel@tonic-gate * RETURN VALUE: NULL if error
2237*0Sstevel@tonic-gate * __nis_mapping_element_t if success
2238*0Sstevel@tonic-gate *
2239*0Sstevel@tonic-gate * INPUT: the string to parse
2240*0Sstevel@tonic-gate */
2241*0Sstevel@tonic-gate
2242*0Sstevel@tonic-gate static __nis_mapping_element_t *
get_ldap_filter_element(const char * s,const char * end_s)2243*0Sstevel@tonic-gate get_ldap_filter_element(
2244*0Sstevel@tonic-gate const char *s,
2245*0Sstevel@tonic-gate const char *end_s
2246*0Sstevel@tonic-gate )
2247*0Sstevel@tonic-gate {
2248*0Sstevel@tonic-gate token_type t;
2249*0Sstevel@tonic-gate const char *begin_token;
2250*0Sstevel@tonic-gate const char *end_token;
2251*0Sstevel@tonic-gate char *format_str;
2252*0Sstevel@tonic-gate __nis_mapping_element_t *e = NULL;
2253*0Sstevel@tonic-gate
2254*0Sstevel@tonic-gate begin_token = s;
2255*0Sstevel@tonic-gate end_token = end_s;
2256*0Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t);
2257*0Sstevel@tonic-gate if (s == NULL || t != open_paren_token)
2258*0Sstevel@tonic-gate return (NULL);
2259*0Sstevel@tonic-gate
2260*0Sstevel@tonic-gate begin_token = s;
2261*0Sstevel@tonic-gate end_token = end_s;
2262*0Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t);
2263*0Sstevel@tonic-gate if (s == NULL || t != quoted_string_token)
2264*0Sstevel@tonic-gate return (NULL);
2265*0Sstevel@tonic-gate
2266*0Sstevel@tonic-gate format_str = s_strndup(begin_token, end_token - begin_token);
2267*0Sstevel@tonic-gate if (format_str == NULL)
2268*0Sstevel@tonic-gate return (NULL);
2269*0Sstevel@tonic-gate e = (__nis_mapping_element_t *)
2270*0Sstevel@tonic-gate s_calloc(1, sizeof (__nis_mapping_element_t));
2271*0Sstevel@tonic-gate if (e != NULL) {
2272*0Sstevel@tonic-gate (void) get_print_mapping_element(s, end_s,
2273*0Sstevel@tonic-gate format_str, e, mit_nisplus);
2274*0Sstevel@tonic-gate if (p_error != no_parse_error) {
2275*0Sstevel@tonic-gate free_mapping_element(e);
2276*0Sstevel@tonic-gate e = NULL;
2277*0Sstevel@tonic-gate }
2278*0Sstevel@tonic-gate }
2279*0Sstevel@tonic-gate free(format_str);
2280*0Sstevel@tonic-gate return (e);
2281*0Sstevel@tonic-gate }
2282*0Sstevel@tonic-gate
2283*0Sstevel@tonic-gate /*
2284*0Sstevel@tonic-gate * FUNCTION: get_search_triple
2285*0Sstevel@tonic-gate *
2286*0Sstevel@tonic-gate * Get the search triple or if NULL determine if valid
2287*0Sstevel@tonic-gate *
2288*0Sstevel@tonic-gate * RETURN VALUE: NULL if error
2289*0Sstevel@tonic-gate * position of beginning next token after
2290*0Sstevel@tonic-gate * search triple
2291*0Sstevel@tonic-gate *
2292*0Sstevel@tonic-gate * INPUT: the attribute value
2293*0Sstevel@tonic-gate */
2294*0Sstevel@tonic-gate
2295*0Sstevel@tonic-gate const char *
get_search_triple(const char * s,const char * end_s,__nis_search_triple_t * triple)2296*0Sstevel@tonic-gate get_search_triple(
2297*0Sstevel@tonic-gate const char *s,
2298*0Sstevel@tonic-gate const char *end_s,
2299*0Sstevel@tonic-gate __nis_search_triple_t *triple
2300*0Sstevel@tonic-gate )
2301*0Sstevel@tonic-gate {
2302*0Sstevel@tonic-gate const char *begin_token;
2303*0Sstevel@tonic-gate const char *end_token;
2304*0Sstevel@tonic-gate char *search_base = NULL;
2305*0Sstevel@tonic-gate int scope = LDAP_SCOPE_ONELEVEL;
2306*0Sstevel@tonic-gate char *filter = NULL;
2307*0Sstevel@tonic-gate const char *s1;
2308*0Sstevel@tonic-gate __nis_mapping_element_t
2309*0Sstevel@tonic-gate *element = NULL;
2310*0Sstevel@tonic-gate
2311*0Sstevel@tonic-gate /*
2312*0Sstevel@tonic-gate * The form of the searchTriple is assumed to be as follows:
2313*0Sstevel@tonic-gate * searchTriple = [baseDN] ["?" [scope] ["?" [filter]]]
2314*0Sstevel@tonic-gate * baseDN = Base DN for search
2315*0Sstevel@tonic-gate * scope = "base" | "one" | "sub"
2316*0Sstevel@tonic-gate * filter = LDAP search filter
2317*0Sstevel@tonic-gate */
2318*0Sstevel@tonic-gate for (; p_error == no_parse_error; ) {
2319*0Sstevel@tonic-gate while (s < end_s && is_whitespace(*s))
2320*0Sstevel@tonic-gate s++;
2321*0Sstevel@tonic-gate if (s == end_s)
2322*0Sstevel@tonic-gate break;
2323*0Sstevel@tonic-gate
2324*0Sstevel@tonic-gate if (!IS_TERMINAL_CHAR(*s)) {
2325*0Sstevel@tonic-gate begin_token = s;
2326*0Sstevel@tonic-gate s = skip_get_dn(begin_token, end_s);
2327*0Sstevel@tonic-gate if (s == NULL) {
2328*0Sstevel@tonic-gate p_error = parse_invalid_dn;
2329*0Sstevel@tonic-gate break;
2330*0Sstevel@tonic-gate }
2331*0Sstevel@tonic-gate if (triple != NULL) {
2332*0Sstevel@tonic-gate search_base = s_strndup(begin_token,
2333*0Sstevel@tonic-gate s - begin_token);
2334*0Sstevel@tonic-gate if (search_base == NULL)
2335*0Sstevel@tonic-gate break;
2336*0Sstevel@tonic-gate }
2337*0Sstevel@tonic-gate while (s < end_s && is_whitespace(*s))
2338*0Sstevel@tonic-gate s++;
2339*0Sstevel@tonic-gate if (s == end_s)
2340*0Sstevel@tonic-gate break;
2341*0Sstevel@tonic-gate }
2342*0Sstevel@tonic-gate
2343*0Sstevel@tonic-gate if (!IS_TERMINAL_CHAR(*s)) {
2344*0Sstevel@tonic-gate p_error = parse_bad_ldap_item_format;
2345*0Sstevel@tonic-gate break;
2346*0Sstevel@tonic-gate }
2347*0Sstevel@tonic-gate if (*s != QUESTION_MARK)
2348*0Sstevel@tonic-gate break;
2349*0Sstevel@tonic-gate
2350*0Sstevel@tonic-gate s++;
2351*0Sstevel@tonic-gate while (s < end_s && is_whitespace(*s))
2352*0Sstevel@tonic-gate s++;
2353*0Sstevel@tonic-gate if (s == end_s)
2354*0Sstevel@tonic-gate break;
2355*0Sstevel@tonic-gate
2356*0Sstevel@tonic-gate /* base, one, or sub, or empty value */
2357*0Sstevel@tonic-gate if (!IS_TERMINAL_CHAR(*s)) {
2358*0Sstevel@tonic-gate if ((s1 = skip_string("base", s, end_s - s)) != NULL) {
2359*0Sstevel@tonic-gate scope = LDAP_SCOPE_BASE;
2360*0Sstevel@tonic-gate } else if ((s1 = skip_string("one", s, end_s - s)) !=
2361*0Sstevel@tonic-gate NULL) {
2362*0Sstevel@tonic-gate scope = LDAP_SCOPE_ONELEVEL;
2363*0Sstevel@tonic-gate } else if ((s1 = skip_string("sub", s, end_s - s)) !=
2364*0Sstevel@tonic-gate NULL) {
2365*0Sstevel@tonic-gate scope = LDAP_SCOPE_SUBTREE;
2366*0Sstevel@tonic-gate } else if (s + 1 < end_s && *s != QUESTION_MARK) {
2367*0Sstevel@tonic-gate p_error = parse_invalid_scope;
2368*0Sstevel@tonic-gate break;
2369*0Sstevel@tonic-gate }
2370*0Sstevel@tonic-gate if (s1 != NULL)
2371*0Sstevel@tonic-gate s = s1;
2372*0Sstevel@tonic-gate while (s < end_s && is_whitespace(*s))
2373*0Sstevel@tonic-gate s++;
2374*0Sstevel@tonic-gate }
2375*0Sstevel@tonic-gate
2376*0Sstevel@tonic-gate if (s == end_s)
2377*0Sstevel@tonic-gate break;
2378*0Sstevel@tonic-gate if (*s != QUESTION_MARK)
2379*0Sstevel@tonic-gate break;
2380*0Sstevel@tonic-gate s++;
2381*0Sstevel@tonic-gate while (s < end_s && is_whitespace(*s))
2382*0Sstevel@tonic-gate s++;
2383*0Sstevel@tonic-gate if (s == end_s || IS_TERMINAL_CHAR(*s))
2384*0Sstevel@tonic-gate break;
2385*0Sstevel@tonic-gate
2386*0Sstevel@tonic-gate /* LDAP search filter */
2387*0Sstevel@tonic-gate if (*s == OPEN_PAREN_CHAR) {
2388*0Sstevel@tonic-gate begin_token = s;
2389*0Sstevel@tonic-gate end_token = end_s;
2390*0Sstevel@tonic-gate s = get_ldap_filter(&begin_token, &end_token);
2391*0Sstevel@tonic-gate if (s == NULL)
2392*0Sstevel@tonic-gate break;
2393*0Sstevel@tonic-gate s = end_token;
2394*0Sstevel@tonic-gate element = get_ldap_filter_element(begin_token, end_token);
2395*0Sstevel@tonic-gate if (element != NULL)
2396*0Sstevel@tonic-gate break;
2397*0Sstevel@tonic-gate } else {
2398*0Sstevel@tonic-gate begin_token = s;
2399*0Sstevel@tonic-gate end_token = end_s;
2400*0Sstevel@tonic-gate s = get_ava_list(&begin_token, &end_token, TRUE);
2401*0Sstevel@tonic-gate if (s == NULL)
2402*0Sstevel@tonic-gate break;
2403*0Sstevel@tonic-gate s = end_token;
2404*0Sstevel@tonic-gate }
2405*0Sstevel@tonic-gate if (triple != NULL)
2406*0Sstevel@tonic-gate filter = s_strndup(begin_token, s - begin_token);
2407*0Sstevel@tonic-gate if (p_error == no_parse_error)
2408*0Sstevel@tonic-gate break;
2409*0Sstevel@tonic-gate }
2410*0Sstevel@tonic-gate if (p_error == no_parse_error && triple != NULL) {
2411*0Sstevel@tonic-gate triple->base = search_base;
2412*0Sstevel@tonic-gate triple->scope = scope;
2413*0Sstevel@tonic-gate triple->attrs = filter;
2414*0Sstevel@tonic-gate triple->element = element;
2415*0Sstevel@tonic-gate element = NULL;
2416*0Sstevel@tonic-gate filter = NULL;
2417*0Sstevel@tonic-gate search_base = NULL;
2418*0Sstevel@tonic-gate }
2419*0Sstevel@tonic-gate
2420*0Sstevel@tonic-gate if (search_base != NULL)
2421*0Sstevel@tonic-gate free(search_base);
2422*0Sstevel@tonic-gate if (filter != NULL)
2423*0Sstevel@tonic-gate free(filter);
2424*0Sstevel@tonic-gate if (element != NULL) {
2425*0Sstevel@tonic-gate free_mapping_element(element);
2426*0Sstevel@tonic-gate free(element);
2427*0Sstevel@tonic-gate }
2428*0Sstevel@tonic-gate return (p_error == no_parse_error ? s : NULL);
2429*0Sstevel@tonic-gate }
2430*0Sstevel@tonic-gate
2431*0Sstevel@tonic-gate /*
2432*0Sstevel@tonic-gate * FUNCTION: get_mapping_format
2433*0Sstevel@tonic-gate *
2434*0Sstevel@tonic-gate * Get the __nis_mapping_format_t from the string
2435*0Sstevel@tonic-gate *
2436*0Sstevel@tonic-gate * RETURN VALUE: FALSE if error
2437*0Sstevel@tonic-gate * TRUE if __nis_mapping_format_t returned
2438*0Sstevel@tonic-gate *
2439*0Sstevel@tonic-gate * INPUT: the format string
2440*0Sstevel@tonic-gate */
2441*0Sstevel@tonic-gate
2442*0Sstevel@tonic-gate static bool_t
get_mapping_format(const char * fmt_string,__nis_mapping_format_t ** fmt,int * nfmt,int * numItems,bool_t print_mapping)2443*0Sstevel@tonic-gate get_mapping_format(
2444*0Sstevel@tonic-gate const char *fmt_string,
2445*0Sstevel@tonic-gate __nis_mapping_format_t **fmt,
2446*0Sstevel@tonic-gate int *nfmt,
2447*0Sstevel@tonic-gate int *numItems,
2448*0Sstevel@tonic-gate bool_t print_mapping)
2449*0Sstevel@tonic-gate {
2450*0Sstevel@tonic-gate const char *f = fmt_string;
2451*0Sstevel@tonic-gate const char *ef;
2452*0Sstevel@tonic-gate __nis_mapping_format_t *b;
2453*0Sstevel@tonic-gate __nis_mapping_format_t *base = NULL;
2454*0Sstevel@tonic-gate int n = 0;
2455*0Sstevel@tonic-gate int nItems = 0;
2456*0Sstevel@tonic-gate
2457*0Sstevel@tonic-gate f = fmt_string;
2458*0Sstevel@tonic-gate ef = f + strlen(f);
2459*0Sstevel@tonic-gate base = (__nis_mapping_format_t *)
2460*0Sstevel@tonic-gate s_calloc(1, sizeof (__nis_mapping_format_t));
2461*0Sstevel@tonic-gate
2462*0Sstevel@tonic-gate if (base == NULL)
2463*0Sstevel@tonic-gate return (FALSE);
2464*0Sstevel@tonic-gate base->type = mmt_begin;
2465*0Sstevel@tonic-gate n++;
2466*0Sstevel@tonic-gate
2467*0Sstevel@tonic-gate for (;;) {
2468*0Sstevel@tonic-gate b = (__nis_mapping_format_t *)s_realloc(
2469*0Sstevel@tonic-gate base, (n + 1) * sizeof (__nis_mapping_format_t));
2470*0Sstevel@tonic-gate
2471*0Sstevel@tonic-gate if (b == NULL)
2472*0Sstevel@tonic-gate break;
2473*0Sstevel@tonic-gate base = b;
2474*0Sstevel@tonic-gate base[n].type = mmt_end;
2475*0Sstevel@tonic-gate if (f == ef) {
2476*0Sstevel@tonic-gate if (nfmt)
2477*0Sstevel@tonic-gate *nfmt = n + 1;
2478*0Sstevel@tonic-gate *fmt = base;
2479*0Sstevel@tonic-gate if (numItems)
2480*0Sstevel@tonic-gate *numItems = nItems;
2481*0Sstevel@tonic-gate return (TRUE);
2482*0Sstevel@tonic-gate }
2483*0Sstevel@tonic-gate if (print_mapping)
2484*0Sstevel@tonic-gate f = get_next_print_format_item(f, ef, &base[n]);
2485*0Sstevel@tonic-gate else
2486*0Sstevel@tonic-gate f = get_next_extract_format_item(f, ef, &base[n]);
2487*0Sstevel@tonic-gate
2488*0Sstevel@tonic-gate
2489*0Sstevel@tonic-gate if (f == NULL)
2490*0Sstevel@tonic-gate break;
2491*0Sstevel@tonic-gate if (base[n].type == mmt_item ||
2492*0Sstevel@tonic-gate base[n].type == mmt_berstring)
2493*0Sstevel@tonic-gate nItems++;
2494*0Sstevel@tonic-gate n++;
2495*0Sstevel@tonic-gate }
2496*0Sstevel@tonic-gate if (base != NULL)
2497*0Sstevel@tonic-gate free_mapping_format(base);
2498*0Sstevel@tonic-gate return (FALSE);
2499*0Sstevel@tonic-gate }
2500*0Sstevel@tonic-gate
2501*0Sstevel@tonic-gate /*
2502*0Sstevel@tonic-gate * FUNCTION: getIndex
2503*0Sstevel@tonic-gate *
2504*0Sstevel@tonic-gate * Returns a string containing the index
2505*0Sstevel@tonic-gate *
2506*0Sstevel@tonic-gate * RETURN VALUE: NULL if error
2507*0Sstevel@tonic-gate * a string containing the index
2508*0Sstevel@tonic-gate *
2509*0Sstevel@tonic-gate * INPUT: attribute containing the index
2510*0Sstevel@tonic-gate */
2511*0Sstevel@tonic-gate
2512*0Sstevel@tonic-gate static char *
getIndex(const char ** s_cur,const char * s_end)2513*0Sstevel@tonic-gate getIndex(const char **s_cur, const char *s_end)
2514*0Sstevel@tonic-gate {
2515*0Sstevel@tonic-gate const char *s = *s_cur + 1;
2516*0Sstevel@tonic-gate const char *s1;
2517*0Sstevel@tonic-gate char *s_index;
2518*0Sstevel@tonic-gate char *s_index1;
2519*0Sstevel@tonic-gate char *s_index_end;
2520*0Sstevel@tonic-gate int n_brackets = 1;
2521*0Sstevel@tonic-gate bool_t in_quotes = FALSE;
2522*0Sstevel@tonic-gate char *index = NULL;
2523*0Sstevel@tonic-gate
2524*0Sstevel@tonic-gate while (s < s_end && is_whitespace(*s))
2525*0Sstevel@tonic-gate s++;
2526*0Sstevel@tonic-gate for (s1 = s; s1 < s_end; s1++) {
2527*0Sstevel@tonic-gate if (*s1 == ESCAPE_CHAR)
2528*0Sstevel@tonic-gate s1++;
2529*0Sstevel@tonic-gate else if (*s1 == DOUBLE_QUOTE_CHAR) {
2530*0Sstevel@tonic-gate in_quotes = !in_quotes;
2531*0Sstevel@tonic-gate } else if (in_quotes)
2532*0Sstevel@tonic-gate ;
2533*0Sstevel@tonic-gate else if (*s1 == CLOSE_BRACKET) {
2534*0Sstevel@tonic-gate if (--n_brackets == 0)
2535*0Sstevel@tonic-gate break;
2536*0Sstevel@tonic-gate } else if (*s1 == OPEN_BRACKET)
2537*0Sstevel@tonic-gate n_brackets++;
2538*0Sstevel@tonic-gate }
2539*0Sstevel@tonic-gate
2540*0Sstevel@tonic-gate if (n_brackets == 0) {
2541*0Sstevel@tonic-gate index = s_strndup(s, s1 - s);
2542*0Sstevel@tonic-gate if (index != NULL) {
2543*0Sstevel@tonic-gate s_index_end = index + (s1 - s);
2544*0Sstevel@tonic-gate s_index1 = index;
2545*0Sstevel@tonic-gate for (s_index = index; s_index < s_index_end;
2546*0Sstevel@tonic-gate s_index++) {
2547*0Sstevel@tonic-gate if (*s_index == ESCAPE_CHAR) {
2548*0Sstevel@tonic-gate *s_index1++ = *s_index++;
2549*0Sstevel@tonic-gate } else if (*s_index == DOUBLE_QUOTE_CHAR) {
2550*0Sstevel@tonic-gate in_quotes = !in_quotes;
2551*0Sstevel@tonic-gate } else if (!in_quotes &&
2552*0Sstevel@tonic-gate is_whitespace(*s_index)) {
2553*0Sstevel@tonic-gate continue;
2554*0Sstevel@tonic-gate }
2555*0Sstevel@tonic-gate *s_index1++ = *s_index;
2556*0Sstevel@tonic-gate }
2557*0Sstevel@tonic-gate *s_index1 = *s_index;
2558*0Sstevel@tonic-gate
2559*0Sstevel@tonic-gate s = s1 + 1;
2560*0Sstevel@tonic-gate
2561*0Sstevel@tonic-gate while (s < s_end && is_whitespace(*s))
2562*0Sstevel@tonic-gate s++;
2563*0Sstevel@tonic-gate *s_cur = s;
2564*0Sstevel@tonic-gate }
2565*0Sstevel@tonic-gate } else
2566*0Sstevel@tonic-gate p_error = parse_mismatched_brackets;
2567*0Sstevel@tonic-gate
2568*0Sstevel@tonic-gate return (index);
2569*0Sstevel@tonic-gate }
2570*0Sstevel@tonic-gate
2571*0Sstevel@tonic-gate /*
2572*0Sstevel@tonic-gate * FUNCTION: parse_index
2573*0Sstevel@tonic-gate *
2574*0Sstevel@tonic-gate * Parse attribute string to get __nis_index_t
2575*0Sstevel@tonic-gate *
2576*0Sstevel@tonic-gate * RETURN VALUE: FALSE if error
2577*0Sstevel@tonic-gate * TRUE if __nis_index_t returned
2578*0Sstevel@tonic-gate *
2579*0Sstevel@tonic-gate * INPUT: the attribute value to parse
2580*0Sstevel@tonic-gate */
2581*0Sstevel@tonic-gate
2582*0Sstevel@tonic-gate bool_t
parse_index(const char * s,const char * end_s,__nis_index_t * index)2583*0Sstevel@tonic-gate parse_index(const char *s, const char *end_s, __nis_index_t *index)
2584*0Sstevel@tonic-gate {
2585*0Sstevel@tonic-gate const char *begin_token;
2586*0Sstevel@tonic-gate const char *end_token;
2587*0Sstevel@tonic-gate char *name_str = NULL;
2588*0Sstevel@tonic-gate char **name;
2589*0Sstevel@tonic-gate char *fmt_string = NULL;
2590*0Sstevel@tonic-gate __nis_mapping_format_t *v = NULL;
2591*0Sstevel@tonic-gate __nis_mapping_format_t **value;
2592*0Sstevel@tonic-gate token_type t;
2593*0Sstevel@tonic-gate int n = 0;
2594*0Sstevel@tonic-gate
2595*0Sstevel@tonic-gate if (index != NULL)
2596*0Sstevel@tonic-gate (void) memset(index, 0, sizeof (*index));
2597*0Sstevel@tonic-gate
2598*0Sstevel@tonic-gate while (s < end_s) {
2599*0Sstevel@tonic-gate if (n > 0) {
2600*0Sstevel@tonic-gate s = skip_token(s, end_s, comma_token);
2601*0Sstevel@tonic-gate if (s == NULL) {
2602*0Sstevel@tonic-gate p_error = parse_bad_index_format;
2603*0Sstevel@tonic-gate break;
2604*0Sstevel@tonic-gate }
2605*0Sstevel@tonic-gate }
2606*0Sstevel@tonic-gate begin_token = s;
2607*0Sstevel@tonic-gate end_token = end_s;
2608*0Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t);
2609*0Sstevel@tonic-gate if (s == NULL)
2610*0Sstevel@tonic-gate break;
2611*0Sstevel@tonic-gate if (t != string_token) {
2612*0Sstevel@tonic-gate p_error = parse_bad_index_format;
2613*0Sstevel@tonic-gate break;
2614*0Sstevel@tonic-gate }
2615*0Sstevel@tonic-gate s = skip_token(s, end_s, equal_token);
2616*0Sstevel@tonic-gate if (s == NULL) {
2617*0Sstevel@tonic-gate p_error = parse_bad_index_format;
2618*0Sstevel@tonic-gate break;
2619*0Sstevel@tonic-gate }
2620*0Sstevel@tonic-gate if (index != NULL) {
2621*0Sstevel@tonic-gate name_str = s_strndup_esc(begin_token,
2622*0Sstevel@tonic-gate end_token - begin_token);
2623*0Sstevel@tonic-gate if (name_str == NULL)
2624*0Sstevel@tonic-gate break;
2625*0Sstevel@tonic-gate }
2626*0Sstevel@tonic-gate begin_token = s;
2627*0Sstevel@tonic-gate end_token = end_s;
2628*0Sstevel@tonic-gate s = get_next_token(&begin_token, &end_token, &t);
2629*0Sstevel@tonic-gate if (s == NULL)
2630*0Sstevel@tonic-gate break;
2631*0Sstevel@tonic-gate if (t != string_token && t != quoted_string_token) {
2632*0Sstevel@tonic-gate p_error = parse_bad_index_format;
2633*0Sstevel@tonic-gate break;
2634*0Sstevel@tonic-gate }
2635*0Sstevel@tonic-gate fmt_string = s_strndup(begin_token, end_token - begin_token);
2636*0Sstevel@tonic-gate if (fmt_string == NULL)
2637*0Sstevel@tonic-gate break;
2638*0Sstevel@tonic-gate if (!get_mapping_format(fmt_string, &v, NULL, NULL, FALSE))
2639*0Sstevel@tonic-gate break;
2640*0Sstevel@tonic-gate free(fmt_string);
2641*0Sstevel@tonic-gate fmt_string = NULL;
2642*0Sstevel@tonic-gate if (index != NULL) {
2643*0Sstevel@tonic-gate name = s_realloc(index->name,
2644*0Sstevel@tonic-gate (n + 1) * sizeof (char *));
2645*0Sstevel@tonic-gate if (name == NULL)
2646*0Sstevel@tonic-gate break;
2647*0Sstevel@tonic-gate value = s_realloc(index->value,
2648*0Sstevel@tonic-gate (n + 1) * sizeof (__nis_mapping_format_t *));
2649*0Sstevel@tonic-gate if (value == NULL)
2650*0Sstevel@tonic-gate break;
2651*0Sstevel@tonic-gate name[n] = name_str;
2652*0Sstevel@tonic-gate name_str = NULL;
2653*0Sstevel@tonic-gate value[n] = v;
2654*0Sstevel@tonic-gate v = NULL;
2655*0Sstevel@tonic-gate index->numIndexes = ++n;
2656*0Sstevel@tonic-gate index->name = name;
2657*0Sstevel@tonic-gate index->value = value;
2658*0Sstevel@tonic-gate } else if (v != NULL) {
2659*0Sstevel@tonic-gate free_mapping_format(v);
2660*0Sstevel@tonic-gate v = NULL;
2661*0Sstevel@tonic-gate }
2662*0Sstevel@tonic-gate }
2663*0Sstevel@tonic-gate if (p_error != no_parse_error) {
2664*0Sstevel@tonic-gate if (name_str != NULL)
2665*0Sstevel@tonic-gate free(name_str);
2666*0Sstevel@tonic-gate if (v != NULL)
2667*0Sstevel@tonic-gate free_mapping_format(v);
2668*0Sstevel@tonic-gate if (fmt_string != NULL)
2669*0Sstevel@tonic-gate free(fmt_string);
2670*0Sstevel@tonic-gate if (index != NULL)
2671*0Sstevel@tonic-gate free_index(index);
2672*0Sstevel@tonic-gate }
2673*0Sstevel@tonic-gate return (p_error != no_parse_error);
2674*0Sstevel@tonic-gate }
2675*0Sstevel@tonic-gate
2676*0Sstevel@tonic-gate /*
2677*0Sstevel@tonic-gate * FUNCTION: get_deleteDisp
2678*0Sstevel@tonic-gate *
2679*0Sstevel@tonic-gate * Parse deleteDisp. Sets p_error if an error occurred.
2680*0Sstevel@tonic-gate *
2681*0Sstevel@tonic-gate * RETURN VALUE: TRUE on success
2682*0Sstevel@tonic-gate * FAILURE on failure
2683*0Sstevel@tonic-gate *
2684*0Sstevel@tonic-gate * INPUT: begin and end of string and __nis_object_dn_t
2685*0Sstevel@tonic-gate */
2686*0Sstevel@tonic-gate
2687*0Sstevel@tonic-gate static bool_t
get_deleteDisp(const char * s_begin,const char * s_end,__nis_object_dn_t * obj_dn)2688*0Sstevel@tonic-gate get_deleteDisp(const char *s_begin, const char *s_end,
2689*0Sstevel@tonic-gate __nis_object_dn_t *obj_dn)
2690*0Sstevel@tonic-gate {
2691*0Sstevel@tonic-gate /*
2692*0Sstevel@tonic-gate * deleteDisp: "always" | perDbId | "never"
2693*0Sstevel@tonic-gate * perDbId: "dbid" "=" delDatabaseId
2694*0Sstevel@tonic-gate */
2695*0Sstevel@tonic-gate
2696*0Sstevel@tonic-gate if (same_string("always", s_begin, s_end - s_begin)) {
2697*0Sstevel@tonic-gate obj_dn->delDisp = dd_always;
2698*0Sstevel@tonic-gate } else if (same_string("never", s_begin, s_end - s_begin)) {
2699*0Sstevel@tonic-gate obj_dn->delDisp = dd_never;
2700*0Sstevel@tonic-gate } else if ((s_begin = skip_string("dbid", s_begin, s_end - s_begin))
2701*0Sstevel@tonic-gate != NULL) {
2702*0Sstevel@tonic-gate obj_dn->delDisp = dd_perDbId;
2703*0Sstevel@tonic-gate while (s_begin < s_end && is_whitespace(*s_begin))
2704*0Sstevel@tonic-gate s_begin++;
2705*0Sstevel@tonic-gate if (s_begin == s_end || *s_begin != EQUAL_CHAR) {
2706*0Sstevel@tonic-gate p_error = parse_object_dn_syntax_error;
2707*0Sstevel@tonic-gate } else {
2708*0Sstevel@tonic-gate s_begin++;
2709*0Sstevel@tonic-gate while (s_begin < s_end && is_whitespace(*s_begin))
2710*0Sstevel@tonic-gate s_begin++;
2711*0Sstevel@tonic-gate while (s_begin < s_end && is_whitespace(s_end[-1]))
2712*0Sstevel@tonic-gate s_end--;
2713*0Sstevel@tonic-gate if (s_begin == s_end) {
2714*0Sstevel@tonic-gate p_error = parse_object_dn_syntax_error;
2715*0Sstevel@tonic-gate } else {
2716*0Sstevel@tonic-gate obj_dn->dbIdName =
2717*0Sstevel@tonic-gate s_strndup(s_begin, s_end - s_begin);
2718*0Sstevel@tonic-gate }
2719*0Sstevel@tonic-gate }
2720*0Sstevel@tonic-gate } else {
2721*0Sstevel@tonic-gate p_error = parse_object_dn_syntax_error;
2722*0Sstevel@tonic-gate }
2723*0Sstevel@tonic-gate return (p_error == no_parse_error);
2724*0Sstevel@tonic-gate }
2725