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]
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
28 #include <sys/types.h>
32 #include "config_msg.h"
34 #define FEATSZ CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \
35 MSG_CONF_EDLIBPATH_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
36 MSG_CONF_ESLIBPATH_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
37 MSG_CONF_ADLIBPATH_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
38 MSG_CONF_ASLIBPATH_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
39 MSG_CONF_DIRCFG_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
40 MSG_CONF_OBJALT_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
41 MSG_CONF_MEMRESV_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
42 MSG_CONF_ENVS_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
43 MSG_CONF_FLTR_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
44 CONV_INV_BUFSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE
47 * Ensure that Conv_config_feat_buf_t is large enough:
49 * FEATSZ is the real minimum size of the buffer required by conv_config_feat().
50 * However, Conv_config_feat_buf_t uses CONV_CONFIG_FEAT_BUFSIZE to set the
51 * buffer size. We do things this way because the definition of FEATSZ uses
52 * information that is not available in the environment of other programs
53 * that include the conv.h header file.
55 #if (CONV_CONFIG_FEAT_BUFSIZE != FEATSZ) && !defined(__lint)
56 #define REPORT_BUFSIZE FEATSZ
57 #include "report_bufsize.h"
58 #error "CONV_CONFIG_FEAT_BUFSIZE does not match FEATSZ"
62 * String conversion routine for configuration file information.
65 conv_config_feat(int features
, Conv_config_feat_buf_t
*config_feat_buf
)
67 static const Val_desc vda
[] = {
68 { CONF_EDLIBPATH
, MSG_CONF_EDLIBPATH
},
69 { CONF_ESLIBPATH
, MSG_CONF_ESLIBPATH
},
70 { CONF_ADLIBPATH
, MSG_CONF_ADLIBPATH
},
71 { CONF_ASLIBPATH
, MSG_CONF_ASLIBPATH
},
72 { CONF_DIRCFG
, MSG_CONF_DIRCFG
},
73 { CONF_OBJALT
, MSG_CONF_OBJALT
},
74 { CONF_MEMRESV
, MSG_CONF_MEMRESV
},
75 { CONF_ENVS
, MSG_CONF_ENVS
},
76 { CONF_FLTR
, MSG_CONF_FLTR
},
79 static CONV_EXPN_FIELD_ARG conv_arg
= {
80 NULL
, sizeof (config_feat_buf
->buf
) };
82 conv_arg
.buf
= config_feat_buf
->buf
;
83 conv_arg
.oflags
= conv_arg
.rflags
= features
;
84 (void) conv_expn_field(&conv_arg
, vda
, 0);
86 return ((const char *)config_feat_buf
->buf
);
89 #define FLAGSZ CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \
90 MSG_CONF_DIRENT_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
91 MSG_CONF_ALLENTS_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
92 MSG_CONF_NOEXIST_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
93 MSG_CONF_EXEC_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
94 MSG_CONF_ALTER_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
95 MSG_CONF_OPTIONAL_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
96 MSG_CONF_DUMP_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
97 MSG_CONF_REALPATH_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
98 MSG_CONF_NOALTER_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
99 MSG_CONF_GROUP_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
100 MSG_CONF_APP_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
101 MSG_CONF_CMDLINE_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
102 MSG_CONF_FILTER_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
103 MSG_CONF_FILTEE_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
104 CONV_INV_BUFSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE
107 * Ensure that Conv_config_obj_buf_t is large enough:
109 * FLAGSZ is the real minimum size of the buffer required by conv_config_obj().
110 * However, Conv_config_obj_buf_t uses CONV_CONFIG_OBJ_BUFSIZE to set the
111 * buffer size. We do things this way because the definition of FLAGSZ uses
112 * information that is not available in the environment of other programs
113 * that include the conv.h header file.
115 #if (CONV_CONFIG_OBJ_BUFSIZE != FLAGSZ) && !defined(__lint)
116 #define REPORT_BUFSIZE FLAGSZ
117 #include "report_bufsize.h"
118 #error "CONV_CONFIG_OBJ_BUFSIZE does not match FLAGSZ"
122 * String conversion routine for object flags.
125 conv_config_obj(ushort_t flags
, Conv_config_obj_buf_t
*config_obj_buf
)
127 static const Val_desc vda
[] = {
128 { RTC_OBJ_DIRENT
, MSG_CONF_DIRENT
},
129 { RTC_OBJ_ALLENTS
, MSG_CONF_ALLENTS
},
130 { RTC_OBJ_NOEXIST
, MSG_CONF_NOEXIST
},
131 { RTC_OBJ_EXEC
, MSG_CONF_EXEC
},
132 { RTC_OBJ_ALTER
, MSG_CONF_ALTER
},
133 { RTC_OBJ_DUMP
, MSG_CONF_DUMP
},
134 { RTC_OBJ_NOALTER
, MSG_CONF_NOALTER
},
135 { RTC_OBJ_REALPTH
, MSG_CONF_REALPATH
},
136 { RTC_OBJ_GROUP
, MSG_CONF_GROUP
},
137 { RTC_OBJ_APP
, MSG_CONF_APP
},
138 { RTC_OBJ_CMDLINE
, MSG_CONF_CMDLINE
},
139 { RTC_OBJ_FILTER
, MSG_CONF_FILTER
},
140 { RTC_OBJ_FILTEE
, MSG_CONF_FILTEE
},
143 static const char *leading_str_arr
[2];
144 static CONV_EXPN_FIELD_ARG conv_arg
= {
145 NULL
, sizeof (config_obj_buf
->buf
), leading_str_arr
};
147 const char **lstr
= leading_str_arr
;
149 if ((flags
== 0) || (flags
== RTC_OBJ_OPTINAL
))
150 return (MSG_ORIG(MSG_GBL_NULL
));
152 conv_arg
.buf
= config_obj_buf
->buf
;
153 conv_arg
.rflags
= flags
;
156 * Print an alternative-optional object simply as optional.
158 if ((flags
& (RTC_OBJ_ALTER
| RTC_OBJ_OPTINAL
)) ==
159 (RTC_OBJ_ALTER
| RTC_OBJ_OPTINAL
)) {
160 *lstr
++ = MSG_ORIG(MSG_CONF_OPTIONAL
);
161 conv_arg
.rflags
&= ~(RTC_OBJ_ALTER
| RTC_OBJ_OPTINAL
);
164 conv_arg
.oflags
= conv_arg
.rflags
&= ~RTC_OBJ_OPTINAL
;
166 (void) conv_expn_field(&conv_arg
, vda
, 0);
168 return ((const char *)config_obj_buf
->buf
);
172 * Determine whether and old pathname exists within a search path string,
173 * without a new pathname, i.e., does the search path string contain "/usr/lib"
174 * but not "/lib". If so, add the new pathname before the old pathname. For
177 * /local/lib:/opt/sfw/lib:/usr/lib
179 * /local/lib:/opt/sfw/lib:/lib:/usr/lib
182 conv_config_upm(const char *str
, const char *old
, const char *new,
185 const char *curstr
, *ptr
;
186 const char *curold
= 0, *curnew
= 0;
187 const char *ptrold
= old
, * ptrnew
= new;
188 int chkold
= 1, chknew
= 1;
190 for (curstr
= ptr
= str
; *ptr
; ptr
++) {
193 * We've come to the end of a token within the string.
195 if ((uintptr_t)ptr
- (uintptr_t)curstr
) {
197 * If the old or new string checking is still
198 * enabled, we've found a match.
205 curstr
= (char *)(ptr
+ 1);
208 * If an old or new string hasn't yet been matched,
209 * re-enable the checking for either.
223 * Determine if the current token matches the old or new string.
224 * If not, disable the checking for each string.
226 if (chkold
&& (*ptr
!= *ptrold
++))
228 if (chknew
&& (*ptr
!= *ptrnew
++))
233 * We've come to the end of the string, if the old or new string
234 * checking is still enabled, we've found a match.
236 if ((uintptr_t)ptr
- (uintptr_t)curstr
) {
244 * If an old string hasn't been found, or it has and a new string has
245 * been found, return the original string.
247 if ((curold
== 0) || curnew
)
254 * Allocate a new string, enlarged to accommodate the new string
255 * that will be inserted, and an associated separator.
257 if ((curstr
= malloc(newlen
+ 2 +
258 (uintptr_t)ptr
- (uintptr_t)str
)) == 0)
261 newstr
= (char *)curstr
;
262 for (len
= (uintptr_t)curold
- (uintptr_t)str
; len
; len
--)
263 *(newstr
++) = *(str
++); /* copy up to */
264 /* insertion point */
265 for (len
= newlen
; len
; len
--)
266 *(newstr
++) = *(new++); /* add new string and */
267 *(newstr
++) = ':'; /* separator */
268 for (len
= (uintptr_t)ptr
- (uintptr_t)str
; len
; len
--)
269 *(newstr
++) = *(str
++); /* add remaining */
270 *(newstr
++) = '\0'; /* string */