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