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
41*0Sstevel@tonic-gate #include "ldap_parse.h"
42*0Sstevel@tonic-gate #include "nis_parse_ldap_conf.h"
43*0Sstevel@tonic-gate
44*0Sstevel@tonic-gate extern FILE *cons;
45*0Sstevel@tonic-gate
46*0Sstevel@tonic-gate static bool_t get_timeval_t(const char *s, int len, struct timeval *t,
47*0Sstevel@tonic-gate time_t default_val);
48*0Sstevel@tonic-gate static bool_t get_limit(const char *s, int len, int *limit, int default_val);
49*0Sstevel@tonic-gate static bool_t get_time_t(const char *s, time_t *t, time_t default_val);
50*0Sstevel@tonic-gate static bool_t get_uint_val(const char *attrib_val, int *val, int default_val);
51*0Sstevel@tonic-gate static bool_t get_int_val(const char *attrib_val, int *val, int default_val);
52*0Sstevel@tonic-gate static void warn_duplicate_val(config_key attrib_num);
53*0Sstevel@tonic-gate
54*0Sstevel@tonic-gate static struct {
55*0Sstevel@tonic-gate const char *key_name;
56*0Sstevel@tonic-gate config_key key_id;
57*0Sstevel@tonic-gate } keyword_lookup[] = {
58*0Sstevel@tonic-gate {CONFIG_DN, key_config_dn},
59*0Sstevel@tonic-gate {YP_CONFIG_DN, key_yp_config_dn},
60*0Sstevel@tonic-gate {CONFIG_SERVER_LIST, key_config_server_list},
61*0Sstevel@tonic-gate {YP_CONFIG_SERVER_LIST, key_yp_config_server_list},
62*0Sstevel@tonic-gate {CONFIG_AUTH_METHOD, key_config_auth_method},
63*0Sstevel@tonic-gate {YP_CONFIG_AUTH_METHOD, key_yp_config_auth_method},
64*0Sstevel@tonic-gate {CONFIG_TLS_OPTION, key_config_tls_option},
65*0Sstevel@tonic-gate {YP_CONFIG_TLS_OPTION, key_yp_config_tls_option},
66*0Sstevel@tonic-gate {CONFIG_TLS_CERT_DB, key_config_tls_certificate_db},
67*0Sstevel@tonic-gate {YP_CONFIG_TLS_CERT_DB, key_yp_config_tls_certificate_db},
68*0Sstevel@tonic-gate {CONFIG_PROXY_USER, key_config_proxy_user},
69*0Sstevel@tonic-gate {YP_CONFIG_PROXY_USER, key_yp_config_proxy_user},
70*0Sstevel@tonic-gate {CONFIG_PROXY_PASSWD, key_config_proxy_passwd},
71*0Sstevel@tonic-gate {YP_CONFIG_PROXY_PASSWD, key_yp_config_proxy_passwd},
72*0Sstevel@tonic-gate {PREFERRED_SERVERS, key_preferred_servers},
73*0Sstevel@tonic-gate {AUTH_METHOD, key_auth_method},
74*0Sstevel@tonic-gate {TLS_OPTION, key_tls_option},
75*0Sstevel@tonic-gate {YP_TLS_OPTION, key_yp_tls_option},
76*0Sstevel@tonic-gate {TLS_CERT_DB, key_tls_certificate_db},
77*0Sstevel@tonic-gate {YP_TLS_CERT_DB, key_yp_tls_certificate_db},
78*0Sstevel@tonic-gate {SEARCH_BASE, key_search_base},
79*0Sstevel@tonic-gate {PROXY_USER, key_proxy_user},
80*0Sstevel@tonic-gate {YP_PROXY_USER, key_yp_proxy_user},
81*0Sstevel@tonic-gate {PROXY_PASSWD, key_proxy_passwd},
82*0Sstevel@tonic-gate {YP_PROXY_PASSWD, key_yp_proxy_passwd},
83*0Sstevel@tonic-gate {LDAP_BASE_DOMAIN, key_ldap_base_domain},
84*0Sstevel@tonic-gate {YP_LDAP_BASE_DOMAIN, key_yp_ldap_base_domain},
85*0Sstevel@tonic-gate {BIND_TIMEOUT, key_bind_timeout},
86*0Sstevel@tonic-gate {YP_BIND_TIMEOUT, key_yp_bind_timeout},
87*0Sstevel@tonic-gate {SEARCH_TIMEOUT, key_search_timeout},
88*0Sstevel@tonic-gate {YP_SEARCH_TIMEOUT, key_yp_search_timeout},
89*0Sstevel@tonic-gate {MODIFY_TIMEOUT, key_modify_timeout},
90*0Sstevel@tonic-gate {YP_MODIFY_TIMEOUT, key_yp_modify_timeout},
91*0Sstevel@tonic-gate {ADD_TIMEOUT, key_add_timeout},
92*0Sstevel@tonic-gate {YP_ADD_TIMEOUT, key_yp_add_timeout},
93*0Sstevel@tonic-gate
94*0Sstevel@tonic-gate {DELETE_TIMEOUT, key_delete_timeout},
95*0Sstevel@tonic-gate {YP_DELETE_TIMEOUT, key_yp_delete_timeout},
96*0Sstevel@tonic-gate {SEARCH_TIME_LIMIT, key_search_time_limit},
97*0Sstevel@tonic-gate {YP_SEARCH_TIME_LIMIT, key_yp_search_time_limit},
98*0Sstevel@tonic-gate {SEARCH_SIZE_LIMIT, key_search_size_limit},
99*0Sstevel@tonic-gate {YP_SEARCH_SIZE_LIMIT, key_yp_search_size_limit},
100*0Sstevel@tonic-gate {FOLLOW_REFERRAL, key_follow_referral},
101*0Sstevel@tonic-gate {YP_FOLLOW_REFERRAL, key_yp_follow_referral},
102*0Sstevel@tonic-gate {INITIAL_UPDATE_ACTION, key_initial_update_action},
103*0Sstevel@tonic-gate {INITIAL_UPDATE_ONLY, key_initial_update_only},
104*0Sstevel@tonic-gate {RETRIEVE_ERROR_ACTION, key_retrieve_error_action},
105*0Sstevel@tonic-gate {YP_RETRIEVE_ERROR_ACTION, key_yp_retrieve_error_action},
106*0Sstevel@tonic-gate {RETREIVE_ERROR_ATTEMPTS,
107*0Sstevel@tonic-gate key_retrieve_error_attempts},
108*0Sstevel@tonic-gate {YP_RETREIVE_ERROR_ATTEMPTS,
109*0Sstevel@tonic-gate key_yp_retrieve_error_attempts},
110*0Sstevel@tonic-gate {RETREIVE_ERROR_TIMEOUT,
111*0Sstevel@tonic-gate key_retreive_error_timeout},
112*0Sstevel@tonic-gate {YP_RETREIVE_ERROR_TIMEOUT,
113*0Sstevel@tonic-gate key_yp_retreive_error_timeout},
114*0Sstevel@tonic-gate {STORE_ERROR_ACTION, key_store_error_action},
115*0Sstevel@tonic-gate {YP_STORE_ERROR_ACTION, key_yp_store_error_action},
116*0Sstevel@tonic-gate {STORE_ERROR_ATTEMPTS, key_store_error_attempts},
117*0Sstevel@tonic-gate {YP_STORE_ERROR_ATTEMPTS, key_yp_store_error_attempts},
118*0Sstevel@tonic-gate {STORE_ERROR_TIMEOUT, key_store_error_timeout},
119*0Sstevel@tonic-gate {YP_STORE_ERROR_TIMEOUT, key_yp_store_error_timeout},
120*0Sstevel@tonic-gate
121*0Sstevel@tonic-gate {REFRESH_ERROR_ACTION, key_refresh_error_action},
122*0Sstevel@tonic-gate
123*0Sstevel@tonic-gate {REFRESH_ERROR_ATTEMPTS,
124*0Sstevel@tonic-gate key_refresh_error_attempts},
125*0Sstevel@tonic-gate {REFRESH_ERROR_TIMEOUT, key_refresh_error_timeout},
126*0Sstevel@tonic-gate {THREAD_CREATE_ERROR_ACTION,
127*0Sstevel@tonic-gate key_thread_create_error_action},
128*0Sstevel@tonic-gate {THREAD_CREATE_ERROR_ATTEMPTS,
129*0Sstevel@tonic-gate key_thread_create_error_attempts},
130*0Sstevel@tonic-gate {THREAD_CREATE_ERROR_TIMEOUT,
131*0Sstevel@tonic-gate key_thread_create_error_timeout},
132*0Sstevel@tonic-gate {DUMP_ERROR_ACTION, key_dump_error_action},
133*0Sstevel@tonic-gate {DUMP_ERROR_ATTEMPTS, key_dump_error_attempts},
134*0Sstevel@tonic-gate {DUMP_ERROR_TIMEOUT, key_dump_error_timeout},
135*0Sstevel@tonic-gate {RESYNC, key_resync},
136*0Sstevel@tonic-gate {UPDATE_BATCHING, key_update_batching},
137*0Sstevel@tonic-gate {UPDATE_BATCHING_TIMEOUT,
138*0Sstevel@tonic-gate key_update_batching_timeout},
139*0Sstevel@tonic-gate {MATCH_FETCH, key_match_fetch},
140*0Sstevel@tonic-gate {YP_MATCH_FETCH, key_yp_match_fetch},
141*0Sstevel@tonic-gate {NUMBER_THEADS, key_number_threads},
142*0Sstevel@tonic-gate {YP_EMULATION, key_yp_emulation},
143*0Sstevel@tonic-gate {MAX_RPC_RECSIZE, key_max_rpc_recsize},
144*0Sstevel@tonic-gate {YP_DOMAIN_CONTEXT, key_yp_domain_context},
145*0Sstevel@tonic-gate {YPPASSWDD_DOMAINS, key_yppasswdd_domains},
146*0Sstevel@tonic-gate {DB_ID_MAP, key_db_id_map},
147*0Sstevel@tonic-gate {YP_DB_ID_MAP, key_yp_db_id_map},
148*0Sstevel@tonic-gate {YP_COMMENT_CHAR, key_yp_comment_char},
149*0Sstevel@tonic-gate {YP_MAP_FLAGS, key_yp_map_flags},
150*0Sstevel@tonic-gate {ENTRY_TTL, key_entry_ttl},
151*0Sstevel@tonic-gate {YP_ENTRY_TTL, key_yp_entry_ttl},
152*0Sstevel@tonic-gate {YP_NAME_FIELDS, key_yp_name_fields},
153*0Sstevel@tonic-gate {YP_SPLIT_FIELD, key_yp_split_field},
154*0Sstevel@tonic-gate {YP_REPEATED_FIELD_SEPARATORS, key_yp_repeated_field_separators},
155*0Sstevel@tonic-gate {LDAP_OBJECT_DN, key_ldap_object_dn},
156*0Sstevel@tonic-gate {YP_LDAP_OBJECT_DN, key_yp_ldap_object_dn},
157*0Sstevel@tonic-gate {LDAP_TO_NISPLUS_MAP, key_ldap_to_nisplus_map},
158*0Sstevel@tonic-gate {LDAP_TO_NIS_MAP, key_ldap_to_nis_map},
159*0Sstevel@tonic-gate {NISPLUS_TO_LDAP_MAP, key_nisplus_to_ldap_map},
160*0Sstevel@tonic-gate {NIS_TO_LDAP_MAP, key_nis_to_ldap_map}
161*0Sstevel@tonic-gate };
162*0Sstevel@tonic-gate
163*0Sstevel@tonic-gate /*
164*0Sstevel@tonic-gate * FUNCTION: add_config_attribute
165*0Sstevel@tonic-gate *
166*0Sstevel@tonic-gate * Adds the attribute value to __nis_config_info_t
167*0Sstevel@tonic-gate * if the value is not yet set.
168*0Sstevel@tonic-gate *
169*0Sstevel@tonic-gate * RETURN VALUE: 0 on success, -1 on failure
170*0Sstevel@tonic-gate *
171*0Sstevel@tonic-gate * INPUT: attribute number and value (assumed to be non-NULL)
172*0Sstevel@tonic-gate */
173*0Sstevel@tonic-gate
174*0Sstevel@tonic-gate int
add_config_attribute(config_key attrib_num,const char * attrib_val,int attrib_len,__nis_config_info_t * config_info)175*0Sstevel@tonic-gate add_config_attribute(
176*0Sstevel@tonic-gate config_key attrib_num,
177*0Sstevel@tonic-gate const char *attrib_val,
178*0Sstevel@tonic-gate int attrib_len,
179*0Sstevel@tonic-gate __nis_config_info_t *config_info)
180*0Sstevel@tonic-gate {
181*0Sstevel@tonic-gate switch (attrib_num) {
182*0Sstevel@tonic-gate case key_yp_config_dn:
183*0Sstevel@tonic-gate case key_config_dn:
184*0Sstevel@tonic-gate if (config_info->config_dn == NULL) {
185*0Sstevel@tonic-gate if (!validate_dn(attrib_val, attrib_len))
186*0Sstevel@tonic-gate break;
187*0Sstevel@tonic-gate config_info->config_dn =
188*0Sstevel@tonic-gate s_strndup(attrib_val, attrib_len);
189*0Sstevel@tonic-gate } else {
190*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
191*0Sstevel@tonic-gate }
192*0Sstevel@tonic-gate break;
193*0Sstevel@tonic-gate case key_yp_config_server_list:
194*0Sstevel@tonic-gate case key_config_server_list:
195*0Sstevel@tonic-gate if (config_info->default_servers == NULL) {
196*0Sstevel@tonic-gate config_info->default_servers =
197*0Sstevel@tonic-gate s_strndup(attrib_val, attrib_len);
198*0Sstevel@tonic-gate } else {
199*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
200*0Sstevel@tonic-gate }
201*0Sstevel@tonic-gate break;
202*0Sstevel@tonic-gate case key_yp_config_auth_method:
203*0Sstevel@tonic-gate case key_config_auth_method:
204*0Sstevel@tonic-gate if (config_info->auth_method ==
205*0Sstevel@tonic-gate (auth_method_t)NO_VALUE_SET) {
206*0Sstevel@tonic-gate if (same_string("none", attrib_val,
207*0Sstevel@tonic-gate attrib_len))
208*0Sstevel@tonic-gate config_info->auth_method = none;
209*0Sstevel@tonic-gate else if (same_string("simple", attrib_val,
210*0Sstevel@tonic-gate attrib_len))
211*0Sstevel@tonic-gate config_info->auth_method = simple;
212*0Sstevel@tonic-gate else if (same_string("sasl/cram-md5",
213*0Sstevel@tonic-gate attrib_val, attrib_len))
214*0Sstevel@tonic-gate config_info->auth_method = cram_md5;
215*0Sstevel@tonic-gate else if (same_string("sasl/digest-md5",
216*0Sstevel@tonic-gate attrib_val, attrib_len))
217*0Sstevel@tonic-gate config_info->auth_method = digest_md5;
218*0Sstevel@tonic-gate else
219*0Sstevel@tonic-gate p_error = parse_bad_auth_method_error;
220*0Sstevel@tonic-gate } else {
221*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
222*0Sstevel@tonic-gate }
223*0Sstevel@tonic-gate break;
224*0Sstevel@tonic-gate case key_yp_config_tls_option:
225*0Sstevel@tonic-gate case key_config_tls_option:
226*0Sstevel@tonic-gate if (config_info->tls_method ==
227*0Sstevel@tonic-gate (tls_method_t)NO_VALUE_SET) {
228*0Sstevel@tonic-gate if (same_string("none", attrib_val,
229*0Sstevel@tonic-gate attrib_len))
230*0Sstevel@tonic-gate config_info->tls_method = no_tls;
231*0Sstevel@tonic-gate else if (same_string("ssl", attrib_val,
232*0Sstevel@tonic-gate attrib_len))
233*0Sstevel@tonic-gate config_info->tls_method = ssl_tls;
234*0Sstevel@tonic-gate else
235*0Sstevel@tonic-gate p_error = parse_bad_tls_option_error;
236*0Sstevel@tonic-gate } else {
237*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
238*0Sstevel@tonic-gate }
239*0Sstevel@tonic-gate break;
240*0Sstevel@tonic-gate case key_yp_config_tls_certificate_db:
241*0Sstevel@tonic-gate case key_config_tls_certificate_db:
242*0Sstevel@tonic-gate if (config_info->tls_cert_db == NULL) {
243*0Sstevel@tonic-gate config_info->tls_cert_db =
244*0Sstevel@tonic-gate s_strndup(attrib_val, attrib_len);
245*0Sstevel@tonic-gate } else {
246*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
247*0Sstevel@tonic-gate }
248*0Sstevel@tonic-gate break;
249*0Sstevel@tonic-gate case key_yp_config_proxy_user:
250*0Sstevel@tonic-gate case key_config_proxy_user:
251*0Sstevel@tonic-gate if (config_info->proxy_dn == NULL) {
252*0Sstevel@tonic-gate config_info->proxy_dn =
253*0Sstevel@tonic-gate s_strndup(attrib_val, attrib_len);
254*0Sstevel@tonic-gate } else {
255*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
256*0Sstevel@tonic-gate }
257*0Sstevel@tonic-gate break;
258*0Sstevel@tonic-gate case key_yp_config_proxy_passwd:
259*0Sstevel@tonic-gate case key_config_proxy_passwd:
260*0Sstevel@tonic-gate if (config_info->proxy_passwd == NULL) {
261*0Sstevel@tonic-gate config_info->proxy_passwd =
262*0Sstevel@tonic-gate s_strndup_esc(attrib_val, attrib_len);
263*0Sstevel@tonic-gate } else {
264*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
265*0Sstevel@tonic-gate }
266*0Sstevel@tonic-gate break;
267*0Sstevel@tonic-gate default:
268*0Sstevel@tonic-gate p_error = parse_internal_error;
269*0Sstevel@tonic-gate break;
270*0Sstevel@tonic-gate }
271*0Sstevel@tonic-gate return (p_error == no_parse_error ? 0 : -1);
272*0Sstevel@tonic-gate }
273*0Sstevel@tonic-gate
274*0Sstevel@tonic-gate /*
275*0Sstevel@tonic-gate * FUNCTION: add_bind_attribute
276*0Sstevel@tonic-gate *
277*0Sstevel@tonic-gate * Adds the attribute value to __nis_ldap_proxy_info
278*0Sstevel@tonic-gate * if the value is not yet set.
279*0Sstevel@tonic-gate *
280*0Sstevel@tonic-gate * RETURN VALUE: 0 on success, -1 on failure
281*0Sstevel@tonic-gate *
282*0Sstevel@tonic-gate * INPUT: attribute number and value (assumed to be non-NULL)
283*0Sstevel@tonic-gate */
284*0Sstevel@tonic-gate
285*0Sstevel@tonic-gate int
add_bind_attribute(config_key attrib_num,const char * attrib_val,int attrib_len,__nis_ldap_proxy_info * proxy_info)286*0Sstevel@tonic-gate add_bind_attribute(
287*0Sstevel@tonic-gate config_key attrib_num,
288*0Sstevel@tonic-gate const char *attrib_val,
289*0Sstevel@tonic-gate int attrib_len,
290*0Sstevel@tonic-gate __nis_ldap_proxy_info *proxy_info)
291*0Sstevel@tonic-gate {
292*0Sstevel@tonic-gate struct timeval t;
293*0Sstevel@tonic-gate int limit;
294*0Sstevel@tonic-gate
295*0Sstevel@tonic-gate switch (attrib_num) {
296*0Sstevel@tonic-gate case key_yp_preferred_servers:
297*0Sstevel@tonic-gate case key_preferred_servers:
298*0Sstevel@tonic-gate if (proxy_info->default_servers == NULL) {
299*0Sstevel@tonic-gate proxy_info->default_servers =
300*0Sstevel@tonic-gate s_strndup(attrib_val, attrib_len);
301*0Sstevel@tonic-gate } else {
302*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
303*0Sstevel@tonic-gate }
304*0Sstevel@tonic-gate break;
305*0Sstevel@tonic-gate case key_yp_auth_method:
306*0Sstevel@tonic-gate case key_auth_method:
307*0Sstevel@tonic-gate if (proxy_info->auth_method ==
308*0Sstevel@tonic-gate (auth_method_t)NO_VALUE_SET) {
309*0Sstevel@tonic-gate if (same_string("none", attrib_val,
310*0Sstevel@tonic-gate attrib_len))
311*0Sstevel@tonic-gate proxy_info->auth_method = none;
312*0Sstevel@tonic-gate else if (same_string("simple", attrib_val,
313*0Sstevel@tonic-gate attrib_len))
314*0Sstevel@tonic-gate proxy_info->auth_method = simple;
315*0Sstevel@tonic-gate else if (same_string("sasl/cram-md5",
316*0Sstevel@tonic-gate attrib_val, attrib_len))
317*0Sstevel@tonic-gate proxy_info->auth_method = cram_md5;
318*0Sstevel@tonic-gate else if (same_string("sasl/digest-md5",
319*0Sstevel@tonic-gate attrib_val, attrib_len))
320*0Sstevel@tonic-gate proxy_info->auth_method = digest_md5;
321*0Sstevel@tonic-gate else
322*0Sstevel@tonic-gate p_error = parse_bad_auth_method_error;
323*0Sstevel@tonic-gate } else {
324*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
325*0Sstevel@tonic-gate }
326*0Sstevel@tonic-gate break;
327*0Sstevel@tonic-gate case key_yp_tls_option:
328*0Sstevel@tonic-gate case key_tls_option:
329*0Sstevel@tonic-gate if (proxy_info->tls_method ==
330*0Sstevel@tonic-gate (tls_method_t)NO_VALUE_SET) {
331*0Sstevel@tonic-gate if (same_string("none", attrib_val,
332*0Sstevel@tonic-gate attrib_len))
333*0Sstevel@tonic-gate proxy_info->tls_method = no_tls;
334*0Sstevel@tonic-gate else if (same_string("ssl", attrib_val,
335*0Sstevel@tonic-gate attrib_len))
336*0Sstevel@tonic-gate proxy_info->tls_method = ssl_tls;
337*0Sstevel@tonic-gate else
338*0Sstevel@tonic-gate p_error = parse_bad_tls_option_error;
339*0Sstevel@tonic-gate } else {
340*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
341*0Sstevel@tonic-gate }
342*0Sstevel@tonic-gate break;
343*0Sstevel@tonic-gate case key_yp_tls_certificate_db:
344*0Sstevel@tonic-gate case key_tls_certificate_db:
345*0Sstevel@tonic-gate if (proxy_info->tls_cert_db == NULL) {
346*0Sstevel@tonic-gate proxy_info->tls_cert_db =
347*0Sstevel@tonic-gate s_strndup(attrib_val, attrib_len);
348*0Sstevel@tonic-gate } else {
349*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
350*0Sstevel@tonic-gate }
351*0Sstevel@tonic-gate break;
352*0Sstevel@tonic-gate case key_yp_search_base:
353*0Sstevel@tonic-gate case key_search_base:
354*0Sstevel@tonic-gate if (proxy_info->default_search_base == NULL) {
355*0Sstevel@tonic-gate if (!validate_dn(attrib_val, attrib_len))
356*0Sstevel@tonic-gate break;
357*0Sstevel@tonic-gate proxy_info->default_search_base =
358*0Sstevel@tonic-gate s_strndup(attrib_val, attrib_len);
359*0Sstevel@tonic-gate } else {
360*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
361*0Sstevel@tonic-gate }
362*0Sstevel@tonic-gate break;
363*0Sstevel@tonic-gate case key_yp_proxy_user:
364*0Sstevel@tonic-gate case key_proxy_user:
365*0Sstevel@tonic-gate if (proxy_info->proxy_dn == NULL) {
366*0Sstevel@tonic-gate proxy_info->proxy_dn =
367*0Sstevel@tonic-gate s_strndup(attrib_val, attrib_len);
368*0Sstevel@tonic-gate } else {
369*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
370*0Sstevel@tonic-gate }
371*0Sstevel@tonic-gate break;
372*0Sstevel@tonic-gate case key_yp_proxy_passwd:
373*0Sstevel@tonic-gate case key_proxy_passwd:
374*0Sstevel@tonic-gate if (proxy_info->proxy_passwd == NULL) {
375*0Sstevel@tonic-gate proxy_info->proxy_passwd =
376*0Sstevel@tonic-gate s_strndup_esc(attrib_val, attrib_len);
377*0Sstevel@tonic-gate } else {
378*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
379*0Sstevel@tonic-gate }
380*0Sstevel@tonic-gate break;
381*0Sstevel@tonic-gate case key_yp_ldap_base_domain:
382*0Sstevel@tonic-gate case key_ldap_base_domain:
383*0Sstevel@tonic-gate if (proxy_info->default_nis_domain == NULL) {
384*0Sstevel@tonic-gate proxy_info->default_nis_domain =
385*0Sstevel@tonic-gate s_strndup_esc(attrib_val, attrib_len);
386*0Sstevel@tonic-gate } else {
387*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
388*0Sstevel@tonic-gate }
389*0Sstevel@tonic-gate break;
390*0Sstevel@tonic-gate case key_yp_bind_timeout:
391*0Sstevel@tonic-gate case key_bind_timeout:
392*0Sstevel@tonic-gate if (proxy_info->bind_timeout.tv_sec ==
393*0Sstevel@tonic-gate (time_t)NO_VALUE_SET) {
394*0Sstevel@tonic-gate if (!get_timeval_t(attrib_val, attrib_len, &t,
395*0Sstevel@tonic-gate DEFAULT_BIND_TIMEOUT))
396*0Sstevel@tonic-gate break;
397*0Sstevel@tonic-gate proxy_info->bind_timeout = t;
398*0Sstevel@tonic-gate } else {
399*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
400*0Sstevel@tonic-gate }
401*0Sstevel@tonic-gate break;
402*0Sstevel@tonic-gate case key_yp_search_timeout:
403*0Sstevel@tonic-gate if (proxy_info->search_timeout.tv_sec ==
404*0Sstevel@tonic-gate (time_t)NO_VALUE_SET) {
405*0Sstevel@tonic-gate if (!get_timeval_t(attrib_val, attrib_len, &t,
406*0Sstevel@tonic-gate DEFAULT_YP_SEARCH_TIMEOUT))
407*0Sstevel@tonic-gate break;
408*0Sstevel@tonic-gate proxy_info->search_timeout = t;
409*0Sstevel@tonic-gate } else {
410*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
411*0Sstevel@tonic-gate }
412*0Sstevel@tonic-gate break;
413*0Sstevel@tonic-gate
414*0Sstevel@tonic-gate case key_search_timeout:
415*0Sstevel@tonic-gate if (proxy_info->search_timeout.tv_sec ==
416*0Sstevel@tonic-gate (time_t)NO_VALUE_SET) {
417*0Sstevel@tonic-gate if (!get_timeval_t(attrib_val, attrib_len, &t,
418*0Sstevel@tonic-gate DEFAULT_SEARCH_TIMEOUT))
419*0Sstevel@tonic-gate break;
420*0Sstevel@tonic-gate proxy_info->search_timeout = t;
421*0Sstevel@tonic-gate } else {
422*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
423*0Sstevel@tonic-gate }
424*0Sstevel@tonic-gate break;
425*0Sstevel@tonic-gate case key_yp_modify_timeout:
426*0Sstevel@tonic-gate case key_modify_timeout:
427*0Sstevel@tonic-gate if (proxy_info->modify_timeout.tv_sec ==
428*0Sstevel@tonic-gate (time_t)NO_VALUE_SET) {
429*0Sstevel@tonic-gate if (!get_timeval_t(attrib_val, attrib_len, &t,
430*0Sstevel@tonic-gate DEFAULT_MODIFY_TIMEOUT))
431*0Sstevel@tonic-gate break;
432*0Sstevel@tonic-gate proxy_info->modify_timeout = t;
433*0Sstevel@tonic-gate } else {
434*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
435*0Sstevel@tonic-gate }
436*0Sstevel@tonic-gate break;
437*0Sstevel@tonic-gate case key_yp_add_timeout:
438*0Sstevel@tonic-gate case key_add_timeout:
439*0Sstevel@tonic-gate if (proxy_info->add_timeout.tv_sec ==
440*0Sstevel@tonic-gate (time_t)NO_VALUE_SET) {
441*0Sstevel@tonic-gate if (!get_timeval_t(attrib_val, attrib_len, &t,
442*0Sstevel@tonic-gate DEFAULT_ADD_TIMEOUT))
443*0Sstevel@tonic-gate break;
444*0Sstevel@tonic-gate proxy_info->add_timeout = t;
445*0Sstevel@tonic-gate } else {
446*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
447*0Sstevel@tonic-gate }
448*0Sstevel@tonic-gate break;
449*0Sstevel@tonic-gate case key_yp_delete_timeout:
450*0Sstevel@tonic-gate case key_delete_timeout:
451*0Sstevel@tonic-gate if (proxy_info->delete_timeout.tv_sec ==
452*0Sstevel@tonic-gate (time_t)NO_VALUE_SET) {
453*0Sstevel@tonic-gate if (!get_timeval_t(attrib_val, attrib_len, &t,
454*0Sstevel@tonic-gate DEFAULT_DELETE_TIMEOUT))
455*0Sstevel@tonic-gate break;
456*0Sstevel@tonic-gate proxy_info->delete_timeout = t;
457*0Sstevel@tonic-gate } else {
458*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
459*0Sstevel@tonic-gate }
460*0Sstevel@tonic-gate break;
461*0Sstevel@tonic-gate case key_yp_search_time_limit:
462*0Sstevel@tonic-gate case key_search_time_limit:
463*0Sstevel@tonic-gate if (proxy_info->search_time_limit ==
464*0Sstevel@tonic-gate (int)NO_VALUE_SET) {
465*0Sstevel@tonic-gate if (!get_limit(attrib_val, attrib_len, &limit,
466*0Sstevel@tonic-gate DEFAULT_SEARCH_TIME_LIMIT))
467*0Sstevel@tonic-gate break;
468*0Sstevel@tonic-gate proxy_info->search_time_limit = limit;
469*0Sstevel@tonic-gate } else {
470*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
471*0Sstevel@tonic-gate }
472*0Sstevel@tonic-gate break;
473*0Sstevel@tonic-gate case key_yp_search_size_limit:
474*0Sstevel@tonic-gate case key_search_size_limit:
475*0Sstevel@tonic-gate if (proxy_info->search_size_limit ==
476*0Sstevel@tonic-gate (int)NO_VALUE_SET) {
477*0Sstevel@tonic-gate if (!get_limit(attrib_val, attrib_len, &limit,
478*0Sstevel@tonic-gate DEFAULT_SEARCH_SIZE_LIMIT))
479*0Sstevel@tonic-gate break;
480*0Sstevel@tonic-gate proxy_info->search_size_limit = limit;
481*0Sstevel@tonic-gate } else {
482*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
483*0Sstevel@tonic-gate }
484*0Sstevel@tonic-gate break;
485*0Sstevel@tonic-gate case key_yp_follow_referral:
486*0Sstevel@tonic-gate case key_follow_referral:
487*0Sstevel@tonic-gate if (proxy_info->follow_referral ==
488*0Sstevel@tonic-gate (follow_referral_t)NO_VALUE_SET) {
489*0Sstevel@tonic-gate if (same_string("yes", attrib_val, attrib_len))
490*0Sstevel@tonic-gate proxy_info->follow_referral = follow;
491*0Sstevel@tonic-gate else if (same_string("no", attrib_val, attrib_len))
492*0Sstevel@tonic-gate proxy_info->follow_referral = no_follow;
493*0Sstevel@tonic-gate else
494*0Sstevel@tonic-gate p_error = parse_yes_or_no_expected_error;
495*0Sstevel@tonic-gate } else {
496*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
497*0Sstevel@tonic-gate }
498*0Sstevel@tonic-gate break;
499*0Sstevel@tonic-gate default:
500*0Sstevel@tonic-gate p_error = parse_internal_error;
501*0Sstevel@tonic-gate break;
502*0Sstevel@tonic-gate }
503*0Sstevel@tonic-gate return (p_error == no_parse_error ? 0 : -1);
504*0Sstevel@tonic-gate }
505*0Sstevel@tonic-gate
506*0Sstevel@tonic-gate /*
507*0Sstevel@tonic-gate * FUNCTION: add_operation_attribute
508*0Sstevel@tonic-gate *
509*0Sstevel@tonic-gate * Adds the attribute value to __nis_config_t and
510*0Sstevel@tonic-gate * __nisdb_table_mapping_t if the value is not yet set.
511*0Sstevel@tonic-gate *
512*0Sstevel@tonic-gate * RETURN VALUE: 0 on success, -1 on failure
513*0Sstevel@tonic-gate *
514*0Sstevel@tonic-gate * INPUT: attribute number and value (assumed to be non-NULL)
515*0Sstevel@tonic-gate */
516*0Sstevel@tonic-gate
517*0Sstevel@tonic-gate int
add_operation_attribute(config_key attrib_num,const char * attrib_val,int attrib_len,__nis_config_t * config_info,__nisdb_table_mapping_t * table_info)518*0Sstevel@tonic-gate add_operation_attribute(
519*0Sstevel@tonic-gate config_key attrib_num,
520*0Sstevel@tonic-gate const char *attrib_val,
521*0Sstevel@tonic-gate int attrib_len,
522*0Sstevel@tonic-gate __nis_config_t *config_info,
523*0Sstevel@tonic-gate __nisdb_table_mapping_t *table_info)
524*0Sstevel@tonic-gate {
525*0Sstevel@tonic-gate char buf[1024];
526*0Sstevel@tonic-gate int i;
527*0Sstevel@tonic-gate int len;
528*0Sstevel@tonic-gate time_t timeout;
529*0Sstevel@tonic-gate bool_t last_digit = FALSE;
530*0Sstevel@tonic-gate
531*0Sstevel@tonic-gate for (i = 0, len = 0; i < attrib_len; i++) {
532*0Sstevel@tonic-gate if (!last_digit &&
533*0Sstevel@tonic-gate is_whitespace(attrib_val[i]))
534*0Sstevel@tonic-gate continue;
535*0Sstevel@tonic-gate buf[len++] = attrib_val[i];
536*0Sstevel@tonic-gate if (len >= sizeof (buf)) {
537*0Sstevel@tonic-gate p_error = parse_line_too_long;
538*0Sstevel@tonic-gate return (-1);
539*0Sstevel@tonic-gate }
540*0Sstevel@tonic-gate last_digit = isdigit(attrib_val[i]);
541*0Sstevel@tonic-gate }
542*0Sstevel@tonic-gate buf[len] = '\0';
543*0Sstevel@tonic-gate
544*0Sstevel@tonic-gate switch (attrib_num) {
545*0Sstevel@tonic-gate case key_initial_update_action:
546*0Sstevel@tonic-gate if (config_info->initialUpdate ==
547*0Sstevel@tonic-gate (__nis_initial_update_t)NO_VALUE_SET) {
548*0Sstevel@tonic-gate if (strcasecmp("none", buf) == 0)
549*0Sstevel@tonic-gate config_info->initialUpdate = ini_none;
550*0Sstevel@tonic-gate else if (strcasecmp("from_ldap", buf) == 0)
551*0Sstevel@tonic-gate config_info->initialUpdate =
552*0Sstevel@tonic-gate (__nis_initial_update_t)FROM_NO_INITIAL_UPDATE;
553*0Sstevel@tonic-gate else if (strcasecmp("to_ldap", buf) == 0)
554*0Sstevel@tonic-gate config_info->initialUpdate =
555*0Sstevel@tonic-gate (__nis_initial_update_t)TO_NO_INITIAL_UPDATE;
556*0Sstevel@tonic-gate else
557*0Sstevel@tonic-gate p_error = parse_initial_update_action_error;
558*0Sstevel@tonic-gate } else if (config_info->initialUpdate ==
559*0Sstevel@tonic-gate (__nis_initial_update_t)INITIAL_UPDATE_NO_ACTION) {
560*0Sstevel@tonic-gate if (strcasecmp("none", buf) == 0)
561*0Sstevel@tonic-gate config_info->initialUpdate = ini_none;
562*0Sstevel@tonic-gate else if (strcasecmp("from_ldap", buf) == 0)
563*0Sstevel@tonic-gate config_info->initialUpdate = from_ldap_update_only;
564*0Sstevel@tonic-gate else if (strcasecmp("to_ldap", buf) == 0)
565*0Sstevel@tonic-gate config_info->initialUpdate = to_ldap_update_only;
566*0Sstevel@tonic-gate else
567*0Sstevel@tonic-gate p_error = parse_initial_update_action_error;
568*0Sstevel@tonic-gate } else if (config_info->initialUpdate ==
569*0Sstevel@tonic-gate (__nis_initial_update_t)NO_INITIAL_UPDATE_NO_ACTION) {
570*0Sstevel@tonic-gate if (strcasecmp("none", buf) == 0)
571*0Sstevel@tonic-gate config_info->initialUpdate = ini_none;
572*0Sstevel@tonic-gate else if (strcasecmp("from_ldap", buf) == 0)
573*0Sstevel@tonic-gate config_info->initialUpdate = from_ldap;
574*0Sstevel@tonic-gate else if (strcasecmp("to_ldap", buf) == 0)
575*0Sstevel@tonic-gate config_info->initialUpdate = to_ldap;
576*0Sstevel@tonic-gate else
577*0Sstevel@tonic-gate p_error = parse_initial_update_action_error;
578*0Sstevel@tonic-gate } else {
579*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
580*0Sstevel@tonic-gate }
581*0Sstevel@tonic-gate break;
582*0Sstevel@tonic-gate case key_initial_update_only:
583*0Sstevel@tonic-gate if (config_info->initialUpdate ==
584*0Sstevel@tonic-gate (__nis_initial_update_t)NO_VALUE_SET) {
585*0Sstevel@tonic-gate if (strcasecmp("yes", buf) == 0)
586*0Sstevel@tonic-gate config_info->initialUpdate =
587*0Sstevel@tonic-gate (__nis_initial_update_t)
588*0Sstevel@tonic-gate INITIAL_UPDATE_NO_ACTION;
589*0Sstevel@tonic-gate else if (strcasecmp("no", buf) == 0)
590*0Sstevel@tonic-gate config_info->initialUpdate =
591*0Sstevel@tonic-gate (__nis_initial_update_t)
592*0Sstevel@tonic-gate NO_INITIAL_UPDATE_NO_ACTION;
593*0Sstevel@tonic-gate else
594*0Sstevel@tonic-gate p_error = parse_initial_update_only_error;
595*0Sstevel@tonic-gate } else if (config_info->initialUpdate ==
596*0Sstevel@tonic-gate (__nis_initial_update_t)FROM_NO_INITIAL_UPDATE) {
597*0Sstevel@tonic-gate if (strcasecmp("yes", buf) == 0)
598*0Sstevel@tonic-gate config_info->initialUpdate = from_ldap_update_only;
599*0Sstevel@tonic-gate else if (strcasecmp("no", buf) == 0)
600*0Sstevel@tonic-gate config_info->initialUpdate = from_ldap;
601*0Sstevel@tonic-gate else
602*0Sstevel@tonic-gate p_error = parse_initial_update_only_error;
603*0Sstevel@tonic-gate } else if (config_info->initialUpdate ==
604*0Sstevel@tonic-gate (__nis_initial_update_t)TO_NO_INITIAL_UPDATE) {
605*0Sstevel@tonic-gate if (strcasecmp("yes", buf) == 0)
606*0Sstevel@tonic-gate config_info->initialUpdate = to_ldap_update_only;
607*0Sstevel@tonic-gate else if (strcasecmp("no", buf) == 0)
608*0Sstevel@tonic-gate config_info->initialUpdate = to_ldap;
609*0Sstevel@tonic-gate else
610*0Sstevel@tonic-gate p_error = parse_initial_update_only_error;
611*0Sstevel@tonic-gate } else if (config_info->initialUpdate != ini_none) {
612*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
613*0Sstevel@tonic-gate }
614*0Sstevel@tonic-gate break;
615*0Sstevel@tonic-gate case key_thread_create_error_action:
616*0Sstevel@tonic-gate if (config_info->threadCreationError ==
617*0Sstevel@tonic-gate (__nis_thread_creation_error_t)NO_VALUE_SET) {
618*0Sstevel@tonic-gate if (strcasecmp("pass_error", buf) == 0)
619*0Sstevel@tonic-gate config_info->threadCreationError = pass_error;
620*0Sstevel@tonic-gate else if (strcasecmp("retry", buf) == 0)
621*0Sstevel@tonic-gate config_info->threadCreationError = cre_retry;
622*0Sstevel@tonic-gate else
623*0Sstevel@tonic-gate p_error = parse_thread_create_error_action_error;
624*0Sstevel@tonic-gate } else {
625*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
626*0Sstevel@tonic-gate }
627*0Sstevel@tonic-gate break;
628*0Sstevel@tonic-gate case key_thread_create_error_attempts:
629*0Sstevel@tonic-gate if (config_info->threadCreationErrorTimeout.attempts ==
630*0Sstevel@tonic-gate NO_VALUE_SET) {
631*0Sstevel@tonic-gate if (get_int_val(buf, &i, DEFAULT_THREAD_ERROR_ATTEMPTS))
632*0Sstevel@tonic-gate config_info->threadCreationErrorTimeout.attempts = i;
633*0Sstevel@tonic-gate } else {
634*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
635*0Sstevel@tonic-gate }
636*0Sstevel@tonic-gate break;
637*0Sstevel@tonic-gate case key_thread_create_error_timeout:
638*0Sstevel@tonic-gate if (config_info->threadCreationErrorTimeout.timeout ==
639*0Sstevel@tonic-gate (time_t)NO_VALUE_SET) {
640*0Sstevel@tonic-gate if (get_time_t(buf, &timeout,
641*0Sstevel@tonic-gate DEFAULT_THREAD_ERROR_TIME_OUT))
642*0Sstevel@tonic-gate config_info->threadCreationErrorTimeout.timeout =
643*0Sstevel@tonic-gate timeout;
644*0Sstevel@tonic-gate } else {
645*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
646*0Sstevel@tonic-gate }
647*0Sstevel@tonic-gate break;
648*0Sstevel@tonic-gate case key_dump_error_action:
649*0Sstevel@tonic-gate if (config_info->dumpError ==
650*0Sstevel@tonic-gate (__nis_dump_error_t)NO_VALUE_SET) {
651*0Sstevel@tonic-gate if (strcasecmp("rollback", buf) == 0)
652*0Sstevel@tonic-gate config_info->dumpError = rollback;
653*0Sstevel@tonic-gate else if (strcasecmp("retry", buf) == 0)
654*0Sstevel@tonic-gate config_info->dumpError = de_retry;
655*0Sstevel@tonic-gate else
656*0Sstevel@tonic-gate p_error = parse_dump_error_action_error;
657*0Sstevel@tonic-gate } else {
658*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
659*0Sstevel@tonic-gate }
660*0Sstevel@tonic-gate break;
661*0Sstevel@tonic-gate case key_dump_error_attempts:
662*0Sstevel@tonic-gate if (config_info->dumpErrorTimeout.attempts == NO_VALUE_SET) {
663*0Sstevel@tonic-gate if (get_int_val(buf, &i, DEFAULT_DUMP_ERROR_ATTEMPTS))
664*0Sstevel@tonic-gate config_info->dumpErrorTimeout.attempts = i;
665*0Sstevel@tonic-gate } else {
666*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
667*0Sstevel@tonic-gate }
668*0Sstevel@tonic-gate break;
669*0Sstevel@tonic-gate case key_dump_error_timeout:
670*0Sstevel@tonic-gate if (config_info->dumpErrorTimeout.timeout ==
671*0Sstevel@tonic-gate (time_t)NO_VALUE_SET) {
672*0Sstevel@tonic-gate if (get_time_t(buf, &timeout,
673*0Sstevel@tonic-gate DEFAULT_DUMP_ERROR_TIME_OUT))
674*0Sstevel@tonic-gate config_info->dumpErrorTimeout.timeout = timeout;
675*0Sstevel@tonic-gate } else {
676*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
677*0Sstevel@tonic-gate }
678*0Sstevel@tonic-gate break;
679*0Sstevel@tonic-gate case key_resync:
680*0Sstevel@tonic-gate if (config_info->resyncService ==
681*0Sstevel@tonic-gate (__nis_resync_service_t)NO_VALUE_SET) {
682*0Sstevel@tonic-gate if (strcasecmp("directory_locked", buf) == 0)
683*0Sstevel@tonic-gate config_info->resyncService = directory_locked;
684*0Sstevel@tonic-gate else if (strcasecmp("from_copy", buf) == 0)
685*0Sstevel@tonic-gate config_info->resyncService = from_copy;
686*0Sstevel@tonic-gate else if (strcasecmp("from_live", buf) == 0)
687*0Sstevel@tonic-gate config_info->resyncService = from_live;
688*0Sstevel@tonic-gate else
689*0Sstevel@tonic-gate p_error = parse_resync_error;
690*0Sstevel@tonic-gate } else {
691*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
692*0Sstevel@tonic-gate }
693*0Sstevel@tonic-gate break;
694*0Sstevel@tonic-gate case key_update_batching:
695*0Sstevel@tonic-gate if (config_info->updateBatching ==
696*0Sstevel@tonic-gate (__nis_update_batching_t)NO_VALUE_SET) {
697*0Sstevel@tonic-gate if (strcasecmp("none", buf) == 0)
698*0Sstevel@tonic-gate config_info->updateBatching = upd_none;
699*0Sstevel@tonic-gate else if (strcasecmp("accumulate", buf) == 0) {
700*0Sstevel@tonic-gate config_info->updateBatching = accumulate;
701*0Sstevel@tonic-gate } else if (strcasecmp("bounded_accumulate", buf) == 0) {
702*0Sstevel@tonic-gate config_info->updateBatching = bounded_accumulate;
703*0Sstevel@tonic-gate } else
704*0Sstevel@tonic-gate p_error = parse_update_batching_error;
705*0Sstevel@tonic-gate } else {
706*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
707*0Sstevel@tonic-gate }
708*0Sstevel@tonic-gate break;
709*0Sstevel@tonic-gate case key_update_batching_timeout:
710*0Sstevel@tonic-gate if (config_info->updateBatchingTimeout.timeout ==
711*0Sstevel@tonic-gate (time_t)NO_VALUE_SET) {
712*0Sstevel@tonic-gate if (get_time_t(buf, &timeout, DEFAULT_BATCHING_TIME_OUT))
713*0Sstevel@tonic-gate config_info->updateBatchingTimeout.timeout = timeout;
714*0Sstevel@tonic-gate } else {
715*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
716*0Sstevel@tonic-gate }
717*0Sstevel@tonic-gate break;
718*0Sstevel@tonic-gate case key_number_threads:
719*0Sstevel@tonic-gate if (config_info->numberOfServiceThreads ==
720*0Sstevel@tonic-gate (int)NO_VALUE_SET) {
721*0Sstevel@tonic-gate if (get_uint_val(buf, &i, DEFAULT_NUMBER_OF_THREADS))
722*0Sstevel@tonic-gate config_info->numberOfServiceThreads = i;
723*0Sstevel@tonic-gate } else {
724*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
725*0Sstevel@tonic-gate }
726*0Sstevel@tonic-gate break;
727*0Sstevel@tonic-gate case key_yp_emulation:
728*0Sstevel@tonic-gate if (config_info->emulate_yp ==
729*0Sstevel@tonic-gate (int)NO_VALUE_SET) {
730*0Sstevel@tonic-gate if (strcasecmp("yes", buf) == 0)
731*0Sstevel@tonic-gate config_info->emulate_yp = TRUE;
732*0Sstevel@tonic-gate } else {
733*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
734*0Sstevel@tonic-gate }
735*0Sstevel@tonic-gate break;
736*0Sstevel@tonic-gate case key_yp_retrieve_error_action:
737*0Sstevel@tonic-gate if (table_info->retrieveError ==
738*0Sstevel@tonic-gate (__nis_retrieve_error_t)NO_VALUE_SET) {
739*0Sstevel@tonic-gate if (strcasecmp("use_cached", buf) == 0)
740*0Sstevel@tonic-gate table_info->retrieveError = use_cached;
741*0Sstevel@tonic-gate else if (strcasecmp("fail", buf) == 0)
742*0Sstevel@tonic-gate table_info->retrieveError = fail;
743*0Sstevel@tonic-gate else
744*0Sstevel@tonic-gate p_error = parse_yp_retrieve_error_action_error;
745*0Sstevel@tonic-gate } else {
746*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
747*0Sstevel@tonic-gate }
748*0Sstevel@tonic-gate break;
749*0Sstevel@tonic-gate case key_retrieve_error_action:
750*0Sstevel@tonic-gate if (table_info->retrieveError ==
751*0Sstevel@tonic-gate (__nis_retrieve_error_t)NO_VALUE_SET) {
752*0Sstevel@tonic-gate if (strcasecmp("use_cached", buf) == 0)
753*0Sstevel@tonic-gate table_info->retrieveError = use_cached;
754*0Sstevel@tonic-gate else if (strcasecmp("try_again", buf) == 0)
755*0Sstevel@tonic-gate table_info->retrieveError = try_again;
756*0Sstevel@tonic-gate else if (strcasecmp("unavail", buf) == 0)
757*0Sstevel@tonic-gate table_info->retrieveError = ret_unavail;
758*0Sstevel@tonic-gate else if (strcasecmp("no_such_name", buf) == 0)
759*0Sstevel@tonic-gate table_info->retrieveError = no_such_name;
760*0Sstevel@tonic-gate else if (strcasecmp("retry", buf) == 0)
761*0Sstevel@tonic-gate table_info->retrieveError = ret_retry;
762*0Sstevel@tonic-gate else
763*0Sstevel@tonic-gate p_error = parse_retrieve_error_action_error;
764*0Sstevel@tonic-gate } else {
765*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
766*0Sstevel@tonic-gate }
767*0Sstevel@tonic-gate break;
768*0Sstevel@tonic-gate case key_yp_retrieve_error_attempts:
769*0Sstevel@tonic-gate case key_retrieve_error_attempts:
770*0Sstevel@tonic-gate if (table_info->retrieveErrorRetry.attempts == NO_VALUE_SET) {
771*0Sstevel@tonic-gate if (get_int_val(buf, &i, DEFAULT_RETRIEVE_ERROR_ATTEMPTS))
772*0Sstevel@tonic-gate table_info->retrieveErrorRetry.attempts = i;
773*0Sstevel@tonic-gate } else {
774*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
775*0Sstevel@tonic-gate }
776*0Sstevel@tonic-gate break;
777*0Sstevel@tonic-gate case key_yp_retreive_error_timeout:
778*0Sstevel@tonic-gate case key_retreive_error_timeout:
779*0Sstevel@tonic-gate if (table_info->retrieveErrorRetry.timeout ==
780*0Sstevel@tonic-gate (time_t)NO_VALUE_SET) {
781*0Sstevel@tonic-gate if (get_time_t(buf, &timeout,
782*0Sstevel@tonic-gate DEFAULT_RETRIEVE_ERROR_TIME_OUT))
783*0Sstevel@tonic-gate table_info->retrieveErrorRetry.timeout = timeout;
784*0Sstevel@tonic-gate } else {
785*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
786*0Sstevel@tonic-gate }
787*0Sstevel@tonic-gate break;
788*0Sstevel@tonic-gate case key_yp_store_error_action:
789*0Sstevel@tonic-gate if (table_info->storeError ==
790*0Sstevel@tonic-gate (__nis_store_error_t)NO_VALUE_SET) {
791*0Sstevel@tonic-gate if (strcasecmp("retry", buf) == 0)
792*0Sstevel@tonic-gate table_info->storeError = sto_retry;
793*0Sstevel@tonic-gate else if (strcasecmp("fail", buf) == 0)
794*0Sstevel@tonic-gate table_info->storeError = sto_fail;
795*0Sstevel@tonic-gate else
796*0Sstevel@tonic-gate p_error = parse_yp_store_error_action_error;
797*0Sstevel@tonic-gate } else {
798*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
799*0Sstevel@tonic-gate }
800*0Sstevel@tonic-gate break;
801*0Sstevel@tonic-gate case key_store_error_action:
802*0Sstevel@tonic-gate if (table_info->storeError ==
803*0Sstevel@tonic-gate (__nis_store_error_t)NO_VALUE_SET) {
804*0Sstevel@tonic-gate if (strcasecmp("system_error", buf) == 0)
805*0Sstevel@tonic-gate table_info->storeError = system_error;
806*0Sstevel@tonic-gate else if (strcasecmp("unavail", buf) == 0)
807*0Sstevel@tonic-gate table_info->storeError = sto_unavail;
808*0Sstevel@tonic-gate else if (strcasecmp("retry", buf) == 0)
809*0Sstevel@tonic-gate table_info->storeError = sto_retry;
810*0Sstevel@tonic-gate else
811*0Sstevel@tonic-gate p_error = parse_store_error_action_error;
812*0Sstevel@tonic-gate } else {
813*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
814*0Sstevel@tonic-gate }
815*0Sstevel@tonic-gate break;
816*0Sstevel@tonic-gate case key_yp_store_error_attempts:
817*0Sstevel@tonic-gate case key_store_error_attempts:
818*0Sstevel@tonic-gate if (table_info->storeErrorRetry.attempts == NO_VALUE_SET) {
819*0Sstevel@tonic-gate if (get_int_val(buf, &i,
820*0Sstevel@tonic-gate DEFAULT_STORE_ERROR_ATTEMPTS))
821*0Sstevel@tonic-gate table_info->storeErrorRetry.attempts = i;
822*0Sstevel@tonic-gate } else {
823*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
824*0Sstevel@tonic-gate }
825*0Sstevel@tonic-gate break;
826*0Sstevel@tonic-gate case key_yp_store_error_timeout:
827*0Sstevel@tonic-gate case key_store_error_timeout:
828*0Sstevel@tonic-gate if (table_info->storeErrorRetry.timeout ==
829*0Sstevel@tonic-gate (time_t)NO_VALUE_SET) {
830*0Sstevel@tonic-gate if (get_time_t(buf, &timeout,
831*0Sstevel@tonic-gate DEFAULT_STORE_ERROR_TIME_OUT))
832*0Sstevel@tonic-gate table_info->storeErrorRetry.timeout = timeout;
833*0Sstevel@tonic-gate } else {
834*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
835*0Sstevel@tonic-gate }
836*0Sstevel@tonic-gate break;
837*0Sstevel@tonic-gate case key_refresh_error_action:
838*0Sstevel@tonic-gate if (table_info->refreshError ==
839*0Sstevel@tonic-gate (__nis_refresh_error_t)NO_VALUE_SET) {
840*0Sstevel@tonic-gate if (strcasecmp("continue_using", buf) == 0)
841*0Sstevel@tonic-gate table_info->refreshError = continue_using;
842*0Sstevel@tonic-gate else if (strcasecmp("cache_expired", buf) == 0)
843*0Sstevel@tonic-gate table_info->refreshError = cache_expired;
844*0Sstevel@tonic-gate else if (strcasecmp("tryagain", buf) == 0)
845*0Sstevel@tonic-gate table_info->refreshError = tryagain;
846*0Sstevel@tonic-gate else if (strcasecmp("retry", buf) == 0)
847*0Sstevel@tonic-gate table_info->refreshError = ref_retry;
848*0Sstevel@tonic-gate else if (strcasecmp("continue_using,retry", buf) == 0 ||
849*0Sstevel@tonic-gate strcasecmp("retry,continue_using", buf) == 0)
850*0Sstevel@tonic-gate table_info->refreshError = continue_using_retry;
851*0Sstevel@tonic-gate else
852*0Sstevel@tonic-gate p_error = parse_refresh_error_action_error;
853*0Sstevel@tonic-gate } else {
854*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
855*0Sstevel@tonic-gate }
856*0Sstevel@tonic-gate break;
857*0Sstevel@tonic-gate case key_refresh_error_attempts:
858*0Sstevel@tonic-gate if (table_info->refreshErrorRetry.attempts == NO_VALUE_SET) {
859*0Sstevel@tonic-gate if (get_int_val(buf, &i, DEFAULT_REFRESH_ERROR_ATTEMPTS))
860*0Sstevel@tonic-gate table_info->refreshErrorRetry.attempts = i;
861*0Sstevel@tonic-gate } else {
862*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
863*0Sstevel@tonic-gate }
864*0Sstevel@tonic-gate break;
865*0Sstevel@tonic-gate case key_refresh_error_timeout:
866*0Sstevel@tonic-gate if (table_info->refreshErrorRetry.timeout ==
867*0Sstevel@tonic-gate (time_t)NO_VALUE_SET) {
868*0Sstevel@tonic-gate if (get_time_t(buf, &timeout,
869*0Sstevel@tonic-gate DEFAULT_REFRESH_ERROR_TIME_OUT))
870*0Sstevel@tonic-gate table_info->refreshErrorRetry.timeout = timeout;
871*0Sstevel@tonic-gate } else {
872*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
873*0Sstevel@tonic-gate }
874*0Sstevel@tonic-gate break;
875*0Sstevel@tonic-gate case key_yp_match_fetch:
876*0Sstevel@tonic-gate case key_match_fetch:
877*0Sstevel@tonic-gate if (table_info->matchFetch ==
878*0Sstevel@tonic-gate (__nis_match_fetch_t)NO_VALUE_SET) {
879*0Sstevel@tonic-gate if (strcasecmp("no_match_only", buf) == 0)
880*0Sstevel@tonic-gate table_info->matchFetch = no_match_only;
881*0Sstevel@tonic-gate else if (strcasecmp("always", buf) == 0)
882*0Sstevel@tonic-gate table_info->matchFetch = mat_always;
883*0Sstevel@tonic-gate else if (strcasecmp("never", buf) == 0)
884*0Sstevel@tonic-gate table_info->matchFetch = mat_never;
885*0Sstevel@tonic-gate else
886*0Sstevel@tonic-gate p_error = parse_match_fetch_error;
887*0Sstevel@tonic-gate } else {
888*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
889*0Sstevel@tonic-gate }
890*0Sstevel@tonic-gate break;
891*0Sstevel@tonic-gate case key_max_rpc_recsize:
892*0Sstevel@tonic-gate if (config_info->maxRPCRecordSize ==
893*0Sstevel@tonic-gate (int)NO_VALUE_SET) {
894*0Sstevel@tonic-gate if (get_uint_val(buf, &i, RPC_MAXDATASIZE))
895*0Sstevel@tonic-gate config_info->maxRPCRecordSize = i;
896*0Sstevel@tonic-gate } else {
897*0Sstevel@tonic-gate warn_duplicate_val(attrib_num);
898*0Sstevel@tonic-gate }
899*0Sstevel@tonic-gate break;
900*0Sstevel@tonic-gate default:
901*0Sstevel@tonic-gate p_error = parse_internal_error;
902*0Sstevel@tonic-gate break;
903*0Sstevel@tonic-gate }
904*0Sstevel@tonic-gate
905*0Sstevel@tonic-gate return (p_error == no_parse_error ? 0 : -1);
906*0Sstevel@tonic-gate }
907*0Sstevel@tonic-gate
908*0Sstevel@tonic-gate /*
909*0Sstevel@tonic-gate * FUNCTION: get_attrib_num
910*0Sstevel@tonic-gate *
911*0Sstevel@tonic-gate * Get the attribute number for the corresponding keyword.
912*0Sstevel@tonic-gate *
913*0Sstevel@tonic-gate * RETURN VALUE: attribute number on success,
914*0Sstevel@tonic-gate * key_bad on failure
915*0Sstevel@tonic-gate *
916*0Sstevel@tonic-gate * INPUT: the attribute name string (assumed to be non-NULL)
917*0Sstevel@tonic-gate */
918*0Sstevel@tonic-gate
919*0Sstevel@tonic-gate config_key
get_attrib_num(const char * s,int n)920*0Sstevel@tonic-gate get_attrib_num(const char *s, int n)
921*0Sstevel@tonic-gate {
922*0Sstevel@tonic-gate int k;
923*0Sstevel@tonic-gate int i;
924*0Sstevel@tonic-gate config_key attrib_num = key_bad;
925*0Sstevel@tonic-gate
926*0Sstevel@tonic-gate k = n < sizeof (_key_val) ? n : sizeof (_key_val) - 1;
927*0Sstevel@tonic-gate (void) memcpy(_key_val, s, k);
928*0Sstevel@tonic-gate _key_val[k] = '\0';
929*0Sstevel@tonic-gate
930*0Sstevel@tonic-gate for (i = 0; i < sizeof (keyword_lookup) /
931*0Sstevel@tonic-gate sizeof (keyword_lookup[0]); i++) {
932*0Sstevel@tonic-gate if (strncasecmp(s, keyword_lookup[i].key_name, n) == 0 &&
933*0Sstevel@tonic-gate strlen(keyword_lookup[i].key_name) == n) {
934*0Sstevel@tonic-gate attrib_num = keyword_lookup[i].key_id;
935*0Sstevel@tonic-gate break;
936*0Sstevel@tonic-gate }
937*0Sstevel@tonic-gate }
938*0Sstevel@tonic-gate
939*0Sstevel@tonic-gate if (attrib_num == key_bad) {
940*0Sstevel@tonic-gate p_error = parse_bad_key;
941*0Sstevel@tonic-gate }
942*0Sstevel@tonic-gate
943*0Sstevel@tonic-gate return (attrib_num);
944*0Sstevel@tonic-gate }
945*0Sstevel@tonic-gate
946*0Sstevel@tonic-gate /*
947*0Sstevel@tonic-gate * FUNCTION: get_timeval_t
948*0Sstevel@tonic-gate *
949*0Sstevel@tonic-gate * Extract time from string
950*0Sstevel@tonic-gate *
951*0Sstevel@tonic-gate * RETURN VALUE: TRUE if parsed
952*0Sstevel@tonic-gate * FALSE otherwise
953*0Sstevel@tonic-gate *
954*0Sstevel@tonic-gate * INPUT: the attribute value string (assumed to be non-NULL)
955*0Sstevel@tonic-gate */
956*0Sstevel@tonic-gate
957*0Sstevel@tonic-gate static bool_t
get_timeval_t(const char * s,int len,struct timeval * t,time_t default_val)958*0Sstevel@tonic-gate get_timeval_t(
959*0Sstevel@tonic-gate const char *s,
960*0Sstevel@tonic-gate int len,
961*0Sstevel@tonic-gate struct timeval *t,
962*0Sstevel@tonic-gate time_t default_val)
963*0Sstevel@tonic-gate {
964*0Sstevel@tonic-gate time_t tv_sec = 0;
965*0Sstevel@tonic-gate time_t tv_usec = 0;
966*0Sstevel@tonic-gate time_t digit;
967*0Sstevel@tonic-gate time_t mult = 100000;
968*0Sstevel@tonic-gate bool_t got_digit = FALSE;
969*0Sstevel@tonic-gate bool_t got_period = FALSE;
970*0Sstevel@tonic-gate const char *s_end = s + len;
971*0Sstevel@tonic-gate
972*0Sstevel@tonic-gate while (s < s_end && is_whitespace(*s))
973*0Sstevel@tonic-gate s++;
974*0Sstevel@tonic-gate
975*0Sstevel@tonic-gate while (s < s_end && isdigit(*s)) {
976*0Sstevel@tonic-gate digit = (*s++) - '0';
977*0Sstevel@tonic-gate got_digit = TRUE;
978*0Sstevel@tonic-gate if (WILL_OVERFLOW_TIME(tv_sec, digit))
979*0Sstevel@tonic-gate tv_sec = TIME_MAX;
980*0Sstevel@tonic-gate else
981*0Sstevel@tonic-gate tv_sec = tv_sec * 10 + digit;
982*0Sstevel@tonic-gate }
983*0Sstevel@tonic-gate while (s < s_end && is_whitespace(*s))
984*0Sstevel@tonic-gate s++;
985*0Sstevel@tonic-gate
986*0Sstevel@tonic-gate if (s < s_end && *s == PERIOD_CHAR) {
987*0Sstevel@tonic-gate s++;
988*0Sstevel@tonic-gate got_period = TRUE;
989*0Sstevel@tonic-gate while (s < s_end && isdigit(*s)) {
990*0Sstevel@tonic-gate got_digit = TRUE;
991*0Sstevel@tonic-gate digit = (*s++) - '0';
992*0Sstevel@tonic-gate tv_usec += digit * mult;
993*0Sstevel@tonic-gate mult /= 10;
994*0Sstevel@tonic-gate }
995*0Sstevel@tonic-gate while (s < s_end && is_whitespace(*s))
996*0Sstevel@tonic-gate s++;
997*0Sstevel@tonic-gate }
998*0Sstevel@tonic-gate if (s == s_end) {
999*0Sstevel@tonic-gate if (!got_digit) {
1000*0Sstevel@tonic-gate if (got_period) {
1001*0Sstevel@tonic-gate p_error = parse_bad_time_error;
1002*0Sstevel@tonic-gate return (FALSE);
1003*0Sstevel@tonic-gate }
1004*0Sstevel@tonic-gate tv_sec = default_val;
1005*0Sstevel@tonic-gate }
1006*0Sstevel@tonic-gate t->tv_sec = tv_sec;
1007*0Sstevel@tonic-gate t->tv_usec = tv_usec;
1008*0Sstevel@tonic-gate } else
1009*0Sstevel@tonic-gate p_error = parse_bad_time_error;
1010*0Sstevel@tonic-gate
1011*0Sstevel@tonic-gate return (s == s_end);
1012*0Sstevel@tonic-gate }
1013*0Sstevel@tonic-gate
1014*0Sstevel@tonic-gate /*
1015*0Sstevel@tonic-gate * FUNCTION: get_limit
1016*0Sstevel@tonic-gate *
1017*0Sstevel@tonic-gate * Extract limit from string
1018*0Sstevel@tonic-gate *
1019*0Sstevel@tonic-gate * RETURN VALUE: TRUE if parsed
1020*0Sstevel@tonic-gate * FALSE otherwise
1021*0Sstevel@tonic-gate *
1022*0Sstevel@tonic-gate * INPUT: the attribute value string (assumed to be non-NULL)
1023*0Sstevel@tonic-gate */
1024*0Sstevel@tonic-gate
1025*0Sstevel@tonic-gate
1026*0Sstevel@tonic-gate static bool_t
get_limit(const char * s,int len,int * limit,int default_val)1027*0Sstevel@tonic-gate get_limit(
1028*0Sstevel@tonic-gate const char *s,
1029*0Sstevel@tonic-gate int len,
1030*0Sstevel@tonic-gate int *limit,
1031*0Sstevel@tonic-gate int default_val)
1032*0Sstevel@tonic-gate {
1033*0Sstevel@tonic-gate bool_t got_digit = FALSE;
1034*0Sstevel@tonic-gate int l = 0;
1035*0Sstevel@tonic-gate time_t digit;
1036*0Sstevel@tonic-gate const char *s_end = s + len;
1037*0Sstevel@tonic-gate
1038*0Sstevel@tonic-gate while (s < s_end && is_whitespace(*s))
1039*0Sstevel@tonic-gate s++;
1040*0Sstevel@tonic-gate
1041*0Sstevel@tonic-gate while (s < s_end && isdigit(*s)) {
1042*0Sstevel@tonic-gate got_digit = TRUE;
1043*0Sstevel@tonic-gate digit = (*s++) - '0';
1044*0Sstevel@tonic-gate if (WILL_OVERFLOW_LIMIT(l, digit))
1045*0Sstevel@tonic-gate l = LIMIT_MAX;
1046*0Sstevel@tonic-gate else
1047*0Sstevel@tonic-gate l = l * 10 + digit;
1048*0Sstevel@tonic-gate }
1049*0Sstevel@tonic-gate while (s < s_end && is_whitespace(*s))
1050*0Sstevel@tonic-gate s++;
1051*0Sstevel@tonic-gate if (s == s_end) {
1052*0Sstevel@tonic-gate if (!got_digit)
1053*0Sstevel@tonic-gate l = default_val;
1054*0Sstevel@tonic-gate *limit = l;
1055*0Sstevel@tonic-gate } else
1056*0Sstevel@tonic-gate p_error = parse_bad_uint_error;
1057*0Sstevel@tonic-gate
1058*0Sstevel@tonic-gate return (s == s_end);
1059*0Sstevel@tonic-gate }
1060*0Sstevel@tonic-gate
1061*0Sstevel@tonic-gate /*
1062*0Sstevel@tonic-gate * FUNCTION: get_time_t
1063*0Sstevel@tonic-gate *
1064*0Sstevel@tonic-gate * Parse a buffer containing a time_t string
1065*0Sstevel@tonic-gate *
1066*0Sstevel@tonic-gate * RETURN VALUE: TRUE on success, FALSE on failure
1067*0Sstevel@tonic-gate *
1068*0Sstevel@tonic-gate * INPUT: the attribute value string (assumed to be non-NULL)
1069*0Sstevel@tonic-gate */
1070*0Sstevel@tonic-gate
1071*0Sstevel@tonic-gate static bool_t
get_time_t(const char * s,time_t * t,time_t default_val)1072*0Sstevel@tonic-gate get_time_t(const char *s, time_t *t, time_t default_val)
1073*0Sstevel@tonic-gate {
1074*0Sstevel@tonic-gate bool_t got_digit = FALSE;
1075*0Sstevel@tonic-gate time_t timeout = 0;
1076*0Sstevel@tonic-gate
1077*0Sstevel@tonic-gate for (; is_whitespace(*s); s++)
1078*0Sstevel@tonic-gate ;
1079*0Sstevel@tonic-gate while (isdigit(*s)) {
1080*0Sstevel@tonic-gate got_digit = TRUE;
1081*0Sstevel@tonic-gate if (WILL_OVERFLOW_TIME(timeout, *s))
1082*0Sstevel@tonic-gate timeout = TIME_MAX;
1083*0Sstevel@tonic-gate else
1084*0Sstevel@tonic-gate timeout = timeout * 10 + *s - '0';
1085*0Sstevel@tonic-gate s++;
1086*0Sstevel@tonic-gate }
1087*0Sstevel@tonic-gate for (; is_whitespace(*s); s++)
1088*0Sstevel@tonic-gate ;
1089*0Sstevel@tonic-gate if (*s != '\0') {
1090*0Sstevel@tonic-gate p_error = parse_bad_int_error;
1091*0Sstevel@tonic-gate return (FALSE);
1092*0Sstevel@tonic-gate }
1093*0Sstevel@tonic-gate if (!got_digit)
1094*0Sstevel@tonic-gate timeout = default_val;
1095*0Sstevel@tonic-gate
1096*0Sstevel@tonic-gate *t = timeout;
1097*0Sstevel@tonic-gate return (TRUE);
1098*0Sstevel@tonic-gate }
1099*0Sstevel@tonic-gate
1100*0Sstevel@tonic-gate /*
1101*0Sstevel@tonic-gate * FUNCTION: get_uint_val
1102*0Sstevel@tonic-gate *
1103*0Sstevel@tonic-gate * Parse a buffer containing a non-negative integer
1104*0Sstevel@tonic-gate *
1105*0Sstevel@tonic-gate * RETURN VALUE: TRUE on success, FALSE on failure
1106*0Sstevel@tonic-gate *
1107*0Sstevel@tonic-gate * INPUT: the attribute value string (assumed to be non-NULL)
1108*0Sstevel@tonic-gate */
1109*0Sstevel@tonic-gate
1110*0Sstevel@tonic-gate static bool_t
get_uint_val(const char * s,int * val,int default_val)1111*0Sstevel@tonic-gate get_uint_val(const char *s, int *val, int default_val)
1112*0Sstevel@tonic-gate {
1113*0Sstevel@tonic-gate bool_t got_digit = FALSE;
1114*0Sstevel@tonic-gate int v = 0;
1115*0Sstevel@tonic-gate
1116*0Sstevel@tonic-gate for (; is_whitespace(*s); s++)
1117*0Sstevel@tonic-gate ;
1118*0Sstevel@tonic-gate while (isdigit(*s)) {
1119*0Sstevel@tonic-gate got_digit = TRUE;
1120*0Sstevel@tonic-gate if (WILL_OVERFLOW_INT(v, *s))
1121*0Sstevel@tonic-gate v = INT_MAX;
1122*0Sstevel@tonic-gate else
1123*0Sstevel@tonic-gate v = v * 10 + *s - '0';
1124*0Sstevel@tonic-gate s++;
1125*0Sstevel@tonic-gate }
1126*0Sstevel@tonic-gate for (; is_whitespace(*s); s++)
1127*0Sstevel@tonic-gate ;
1128*0Sstevel@tonic-gate if (*s != '\0') {
1129*0Sstevel@tonic-gate p_error = parse_bad_int_error;
1130*0Sstevel@tonic-gate return (FALSE);
1131*0Sstevel@tonic-gate }
1132*0Sstevel@tonic-gate
1133*0Sstevel@tonic-gate if (!got_digit)
1134*0Sstevel@tonic-gate v = default_val;
1135*0Sstevel@tonic-gate
1136*0Sstevel@tonic-gate *val = v;
1137*0Sstevel@tonic-gate return (TRUE);
1138*0Sstevel@tonic-gate }
1139*0Sstevel@tonic-gate
1140*0Sstevel@tonic-gate /*
1141*0Sstevel@tonic-gate * FUNCTION: get_int_val
1142*0Sstevel@tonic-gate *
1143*0Sstevel@tonic-gate * Parse a buffer containing a non-negative integer
1144*0Sstevel@tonic-gate *
1145*0Sstevel@tonic-gate * RETURN VALUE: TRUE on success, FALSE on failure
1146*0Sstevel@tonic-gate *
1147*0Sstevel@tonic-gate * INPUT: the attribute value string (assumed to be non-NULL)
1148*0Sstevel@tonic-gate */
1149*0Sstevel@tonic-gate
1150*0Sstevel@tonic-gate static bool_t
get_int_val(const char * s,int * val,int default_val)1151*0Sstevel@tonic-gate get_int_val(const char *s, int *val, int default_val)
1152*0Sstevel@tonic-gate {
1153*0Sstevel@tonic-gate bool_t got_digit = FALSE;
1154*0Sstevel@tonic-gate int v = 0;
1155*0Sstevel@tonic-gate bool_t is_neg = FALSE;
1156*0Sstevel@tonic-gate
1157*0Sstevel@tonic-gate for (; is_whitespace(*s); s++)
1158*0Sstevel@tonic-gate ;
1159*0Sstevel@tonic-gate if (*s == '-') {
1160*0Sstevel@tonic-gate is_neg = TRUE;
1161*0Sstevel@tonic-gate s++;
1162*0Sstevel@tonic-gate }
1163*0Sstevel@tonic-gate while (isdigit(*s)) {
1164*0Sstevel@tonic-gate got_digit = TRUE;
1165*0Sstevel@tonic-gate if (WILL_OVERFLOW_INT(v, *s))
1166*0Sstevel@tonic-gate v = INT_MAX;
1167*0Sstevel@tonic-gate else
1168*0Sstevel@tonic-gate v = v * 10 + *s - '0';
1169*0Sstevel@tonic-gate s++;
1170*0Sstevel@tonic-gate }
1171*0Sstevel@tonic-gate for (; is_whitespace(*s); s++)
1172*0Sstevel@tonic-gate ;
1173*0Sstevel@tonic-gate if (*s != '\0') {
1174*0Sstevel@tonic-gate p_error = parse_bad_int_error;
1175*0Sstevel@tonic-gate return (FALSE);
1176*0Sstevel@tonic-gate }
1177*0Sstevel@tonic-gate
1178*0Sstevel@tonic-gate if (!got_digit) {
1179*0Sstevel@tonic-gate if (is_neg) {
1180*0Sstevel@tonic-gate p_error = parse_bad_int_error;
1181*0Sstevel@tonic-gate return (FALSE);
1182*0Sstevel@tonic-gate }
1183*0Sstevel@tonic-gate v = default_val;
1184*0Sstevel@tonic-gate }
1185*0Sstevel@tonic-gate if (is_neg)
1186*0Sstevel@tonic-gate v = -v;
1187*0Sstevel@tonic-gate *val = v;
1188*0Sstevel@tonic-gate return (TRUE);
1189*0Sstevel@tonic-gate }
1190*0Sstevel@tonic-gate
1191*0Sstevel@tonic-gate static void
warn_duplicate_val(config_key attrib_num)1192*0Sstevel@tonic-gate warn_duplicate_val(
1193*0Sstevel@tonic-gate config_key attrib_num)
1194*0Sstevel@tonic-gate {
1195*0Sstevel@tonic-gate const char *key_name = "Unknown";
1196*0Sstevel@tonic-gate int i;
1197*0Sstevel@tonic-gate
1198*0Sstevel@tonic-gate if (warn_file == NULL || is_cmd_line_option(attrib_num))
1199*0Sstevel@tonic-gate return;
1200*0Sstevel@tonic-gate
1201*0Sstevel@tonic-gate for (i = 0; i < sizeof (keyword_lookup) /
1202*0Sstevel@tonic-gate sizeof (keyword_lookup[0]); i++) {
1203*0Sstevel@tonic-gate if (attrib_num == keyword_lookup[i].key_id) {
1204*0Sstevel@tonic-gate key_name = keyword_lookup[i].key_name;
1205*0Sstevel@tonic-gate break;
1206*0Sstevel@tonic-gate }
1207*0Sstevel@tonic-gate }
1208*0Sstevel@tonic-gate if (cons != NULL) {
1209*0Sstevel@tonic-gate fprintf(cons,
1210*0Sstevel@tonic-gate "Warning: Duplicate value for %s in %s at line:%d\n",
1211*0Sstevel@tonic-gate key_name, warn_file, start_line_num);
1212*0Sstevel@tonic-gate } else {
1213*0Sstevel@tonic-gate syslog(LOG_INFO,
1214*0Sstevel@tonic-gate "Duplicate value for %s in %s at line:%d",
1215*0Sstevel@tonic-gate key_name, warn_file, start_line_num);
1216*0Sstevel@tonic-gate }
1217*0Sstevel@tonic-gate }
1218*0Sstevel@tonic-gate
1219*0Sstevel@tonic-gate void
warn_duplicate_map(const char * db_id,config_key attrib_num)1220*0Sstevel@tonic-gate warn_duplicate_map(
1221*0Sstevel@tonic-gate const char *db_id,
1222*0Sstevel@tonic-gate config_key attrib_num)
1223*0Sstevel@tonic-gate {
1224*0Sstevel@tonic-gate const char *key_name = "Unknown";
1225*0Sstevel@tonic-gate int i;
1226*0Sstevel@tonic-gate
1227*0Sstevel@tonic-gate if (warn_file == NULL)
1228*0Sstevel@tonic-gate return;
1229*0Sstevel@tonic-gate
1230*0Sstevel@tonic-gate for (i = 0; i < sizeof (keyword_lookup) /
1231*0Sstevel@tonic-gate sizeof (keyword_lookup[0]); i++) {
1232*0Sstevel@tonic-gate if (attrib_num == keyword_lookup[i].key_id) {
1233*0Sstevel@tonic-gate key_name = keyword_lookup[i].key_name;
1234*0Sstevel@tonic-gate break;
1235*0Sstevel@tonic-gate }
1236*0Sstevel@tonic-gate }
1237*0Sstevel@tonic-gate if (cons != NULL) {
1238*0Sstevel@tonic-gate fprintf(cons,
1239*0Sstevel@tonic-gate "Warning: Duplicate value for %s:%s in %s at line:%d\n",
1240*0Sstevel@tonic-gate key_name, db_id, warn_file, start_line_num);
1241*0Sstevel@tonic-gate } else {
1242*0Sstevel@tonic-gate syslog(LOG_INFO,
1243*0Sstevel@tonic-gate "Duplicate value for %s:%s in %s at line:%d",
1244*0Sstevel@tonic-gate key_name, db_id, warn_file, start_line_num);
1245*0Sstevel@tonic-gate }
1246*0Sstevel@tonic-gate }
1247