4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
31 #include "nscd_config.h"
33 #include "nscd_switch.h"
36 * Configuration data for the nscd switch functions.
38 nscd_cfg_global_switch_t nscd_switch_cfg_g
;
39 nscd_cfg_switch_t
*nscd_switch_cfg
;
42 * statistics of the nscd switch functions.
44 nscd_cfg_stat_global_switch_t nscd_switch_stats_g
;
45 nscd_cfg_stat_switch_t
*nscd_switch_stats
;
48 * cookie is set up by the verify function for passing to
52 struct __nsw_switchconfig_v1
*cfg
;
57 _nscd_alloc_switch_cfg()
59 nscd_switch_cfg
= calloc(NSCD_NUM_DB
, sizeof (nscd_cfg_switch_t
));
60 if (nscd_switch_cfg
== NULL
)
61 return (NSCD_NO_MEMORY
);
63 return (NSCD_SUCCESS
);
67 _nscd_alloc_switch_stats()
70 nscd_switch_stats
= calloc(NSCD_NUM_DB
,
71 sizeof (nscd_cfg_stat_switch_t
));
72 if (nscd_switch_stats
== NULL
)
73 return (NSCD_NO_MEMORY
);
75 return (NSCD_SUCCESS
);
80 _nscd_cfg_switch_notify(
82 struct nscd_cfg_param_desc
*pdesc
,
84 nscd_cfg_flag_t dflag
,
85 nscd_cfg_error_t
**errorp
,
91 nsw_cfg_cookie_t
*ck
= (nsw_cfg_cookie_t
*)cookie
;
93 if (_nscd_cfg_flag_is_set(dflag
, NSCD_CFG_DFLAG_INIT
) ||
94 _nscd_cfg_flag_is_set(dflag
, NSCD_CFG_DFLAG_GROUP
)) {
96 * group data is received, copy in the
99 if (_nscd_cfg_flag_is_set(pdesc
->pflag
,
100 NSCD_CFG_PFLAG_GLOBAL
)) {
101 nscd_switch_cfg_g
= *(nscd_cfg_global_switch_t
*)data
;
103 nscd_switch_cfg
[nswdb
->index
] =
104 *(nscd_cfg_switch_t
*)data
;
109 * individual paramater is received: copy in the
110 * parameter value except for nsw-config-string.
112 if (_nscd_cfg_flag_is_set(pdesc
->pflag
,
113 NSCD_CFG_PFLAG_GLOBAL
)) {
114 dp
= (char *)&nscd_switch_cfg_g
+ pdesc
->p_offset
;
115 (void) memcpy(dp
, data
, pdesc
->p_size
);
117 dp
= (char *)&nscd_switch_cfg
[nswdb
->index
] +
119 if (pdesc
->p_offset
!=
120 offsetof(nscd_cfg_switch_t
, nsw_config_string
))
121 (void) memcpy(dp
, data
, pdesc
->p_size
);
126 * cookie contains data for the switch policy config
128 if (cookie
!= NULL
) {
129 rc
= _nscd_create_sw_struct(nswdb
->index
, -1, nswdb
->name
,
130 ck
->cfgstr
, ck
->cfg
, NULL
);
131 if (rc
!= NSCD_SUCCESS
) {
132 (void) __nsw_freeconfig_v1(ck
->cfg
);
139 if (_nscd_cfg_flag_is_not_set(dflag
, NSCD_CFG_DFLAG_STATIC_DATA
))
142 return (NSCD_SUCCESS
);
147 _nscd_cfg_switch_verify(
149 struct nscd_cfg_param_desc
*pdesc
,
150 nscd_cfg_id_t
*nswdb
,
151 nscd_cfg_flag_t dflag
,
152 nscd_cfg_error_t
**errorp
,
155 char *me
= "_nscd_cfg_switch_verify";
156 nscd_cfg_switch_t
*cfg
;
159 struct __nsw_switchconfig_v1
*switchcfg
= NULL
;
160 enum __nsw_parse_err err
;
161 nsw_cfg_cookie_t
*ck
;
162 char buf
[MAX_NSSWITCH_CONFIG_STRING_SZ
];
163 char msg
[NSCD_CFG_MAX_ERR_MSG_LEN
];
166 * global config data has nothing special to verify
168 if (_nscd_cfg_flag_is_set(pdesc
->pflag
, NSCD_CFG_PFLAG_GLOBAL
))
169 return (NSCD_SUCCESS
);
174 * switch policy string is the one to parse and verify
177 if (_nscd_cfg_flag_is_set(dflag
, NSCD_CFG_DFLAG_INIT
) ||
178 _nscd_cfg_flag_is_set(dflag
, NSCD_CFG_DFLAG_GROUP
)) {
180 /* get it from the group data */
181 cfg
= (nscd_cfg_switch_t
*)data
;
182 nswcfgstr
= cfg
->nsw_config_string
;
184 /* not group, and not the switch policy string, return */
185 if (pdesc
->p_offset
!= offsetof(nscd_cfg_switch_t
,
187 return (NSCD_SUCCESS
);
189 /* the data itself is the string */
190 nswcfgstr
= (char *)data
;
194 * convert the string into struct __nsw_switchconfig_v1
196 size
= MAX_NSSWITCH_CONFIG_STRING_SZ
;
197 if (strlcpy(buf
, nswcfgstr
, size
) >= size
) {
199 (void) snprintf(msg
, sizeof (msg
),
200 gettext("switch policy string too long (\"%s : %s\" > %d)"),
201 nswdb
->name
, nswcfgstr
, size
);
203 _NSCD_LOG(NSCD_LOG_CONFIG
, NSCD_LOG_LEVEL_ERROR
)
207 *errorp
= _nscd_cfg_make_error(
208 NSCD_CFG_SYNTAX_ERROR
, msg
);
210 return (NSCD_CFG_SYNTAX_ERROR
);
212 switchcfg
= _nsw_getoneconfig_v1(nswdb
->name
, buf
, &err
);
213 if (switchcfg
== NULL
) {
215 (void) snprintf(msg
, sizeof (msg
),
216 gettext("syntax error: switch policy string (%s : %s) rc = %d"),
217 nswdb
->name
, nswcfgstr
, err
);
219 _NSCD_LOG(NSCD_LOG_CONFIG
, NSCD_LOG_LEVEL_ERROR
)
223 *errorp
= _nscd_cfg_make_error(
224 NSCD_CFG_SYNTAX_ERROR
, msg
);
226 return (NSCD_CFG_SYNTAX_ERROR
);
229 /* save the __nsw_switchconfig_v1 for the notify function */
230 ck
= calloc(1, sizeof (nsw_cfg_cookie_t
));
232 (void) __nsw_freeconfig_v1(switchcfg
);
233 return (NSCD_CFG_SYNTAX_ERROR
);
236 ck
->cfgstr
= nswcfgstr
;
239 return (NSCD_SUCCESS
);
244 _nscd_cfg_switch_get_stat(
246 struct nscd_cfg_stat_desc
*sdesc
,
247 nscd_cfg_id_t
*nswdb
,
248 nscd_cfg_flag_t
*dflag
,
249 void (**free_stat
)(void *stat
),
250 nscd_cfg_error_t
**errorp
)
253 if (_nscd_cfg_flag_is_set(sdesc
->sflag
, NSCD_CFG_SFLAG_GLOBAL
)) {
254 *stat
= &NSCD_SW_STATS_G
;
256 *stat
= &NSCD_SW_STATS(nswdb
->index
);
258 /* indicate the statistics are static, i.e., do not free */
259 *dflag
= _nscd_cfg_flag_set(*dflag
, NSCD_CFG_DFLAG_STATIC_DATA
);
261 return (NSCD_SUCCESS
);