1 /*
2 * CDDL HEADER START
3 *
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.
7 *
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.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
24 */
25
26 #include <string.h>
27 #include <link.h>
28 #include "_conv.h"
29 #include "audit_msg.h"
30
31 #define BINDSZ CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \
32 MSG_LA_FLG_BINDTO_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
33 MSG_LA_FLG_BINDFROM_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
34 CONV_INV_BUFSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE
35
36 /*
37 * Ensure that Conv_la_bind_buf_t is large enough:
38 *
39 * BINDSZ is the real minimum size of the buffer required by conv_la_bind().
40 * However, Conv_la_bind_buf_t uses CONV_LA_BIND_BUFSIZE to set the
41 * buffer size. We do things this way because the definition of BINDSZ uses
42 * information that is not available in the environment of other programs
43 * that include the conv.h header file.
44 */
45 #if (CONV_LA_BIND_BUFSIZE != BINDSZ) && !defined(__lint)
46 #define REPORT_BUFSIZE BINDSZ
47 #include "report_bufsize.h"
48 #error "CONV_LA_BIND_BUFSIZE does not match BINDSZ"
49 #endif
50
51 /*
52 * String conversion routine for la_objopen() return flags.
53 */
54 const char *
conv_la_bind(uint_t bind,Conv_la_bind_buf_t * la_bind_buf)55 conv_la_bind(uint_t bind, Conv_la_bind_buf_t *la_bind_buf)
56 {
57 static const Val_desc vda[] = {
58 { LA_FLG_BINDTO, MSG_LA_FLG_BINDTO },
59 { LA_FLG_BINDFROM, MSG_LA_FLG_BINDFROM },
60 { 0, 0 }
61 };
62 static CONV_EXPN_FIELD_ARG conv_arg = {
63 NULL, sizeof (la_bind_buf->buf), NULL };
64
65 if (bind == 0)
66 return (MSG_ORIG(MSG_GBL_ZERO));
67
68 conv_arg.buf = la_bind_buf->buf;
69 conv_arg.oflags = conv_arg.rflags = bind;
70
71 (void) conv_expn_field(&conv_arg, vda, 0);
72
73 return ((const char *)la_bind_buf->buf);
74 }
75
76 #define SEARCHSZ CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \
77 MSG_LA_SER_ORIG_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
78 MSG_LA_SER_LIBPATH_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
79 MSG_LA_SER_RUNPATH_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
80 MSG_LA_SER_DEFAULT_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
81 MSG_LA_SER_CONFIG_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
82 MSG_LA_SER_SECURE_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
83 CONV_INV_BUFSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE
84
85 /*
86 * Ensure that Conv_la_search_buf_t is large enough:
87 *
88 * SEARCHSZ is the real minimum size of the buffer required by conv_la_search().
89 * However, Conv_la_search_buf_t uses CONV_LA_SEARCH_BUFSIZE to set the
90 * buffer size. We do things this way because the definition of SEARCHSZ uses
91 * information that is not available in the environment of other programs
92 * that include the conv.h header file.
93 */
94 #if (CONV_LA_SEARCH_BUFSIZE != SEARCHSZ) && !defined(__lint)
95 #define REPORT_BUFSIZE SEARCHSZ
96 #include "report_bufsize.h"
97 #error "CONV_LA_SEARCH_BUFSIZE does not match SEARCHSZ"
98 #endif
99
100 /*
101 * String conversion routine for la_objsearch() flags.
102 */
103 const char *
conv_la_search(uint_t search,Conv_la_search_buf_t * la_search_buf)104 conv_la_search(uint_t search, Conv_la_search_buf_t *la_search_buf)
105 {
106 static const Val_desc vda[] = {
107 { LA_SER_ORIG, MSG_LA_SER_ORIG },
108 { LA_SER_LIBPATH, MSG_LA_SER_LIBPATH },
109 { LA_SER_RUNPATH, MSG_LA_SER_RUNPATH },
110 { LA_SER_DEFAULT, MSG_LA_SER_DEFAULT },
111 { LA_SER_CONFIG, MSG_LA_SER_CONFIG },
112 { LA_SER_SECURE, MSG_LA_SER_SECURE },
113 { 0, 0 }
114 };
115 static CONV_EXPN_FIELD_ARG conv_arg = {
116 NULL, sizeof (la_search_buf->buf), NULL };
117
118 if (search == 0)
119 return (MSG_ORIG(MSG_GBL_NULL));
120
121 conv_arg.buf = la_search_buf->buf;
122 conv_arg.oflags = conv_arg.rflags = search;
123
124 (void) conv_expn_field(&conv_arg, vda, 0);
125
126 return ((const char *)la_search_buf->buf);
127 }
128
129 /*
130 * String conversion routine for la_objopen() return flags.
131 */
132
133 /*
134 * String conversion routine for la_activity() flags.
135 */
136 const char *
conv_la_activity(uint_t request,Conv_fmt_flags_t fmt_flags,Conv_inv_buf_t * inv_buf)137 conv_la_activity(uint_t request, Conv_fmt_flags_t fmt_flags,
138 Conv_inv_buf_t *inv_buf)
139 {
140 static const Msg requests[LA_ACT_MAX] = {
141 MSG_LA_ACT_CONSISTENT, /* MSG_ORIG(MSG_LA_ACT_CONSISTENT) */
142 MSG_LA_ACT_ADD, /* MSG_ORIG(MSG_LA_ACT_ADD) */
143 MSG_LA_ACT_DELETE /* MSG_ORIG(MSG_LA_ACT_DELETE) */
144 };
145 static const conv_ds_msg_t ds_requests = {
146 CONV_DS_MSG_INIT(LA_ACT_CONSISTENT, requests) };
147
148 static const conv_ds_t *ds[] = { CONV_DS_ADDR(ds_requests), NULL };
149
150 return (conv_map_ds(ELFOSABI_NONE, EM_NONE, request, ds, fmt_flags,
151 inv_buf));
152 }
153
154 #define SYMBSZ CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \
155 MSG_LA_SYMB_NOPLTENTER_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
156 MSG_LA_SYMB_NOPLTEXIT_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
157 MSG_LA_SYMB_STRUCTCALL_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
158 MSG_LA_SYMB_DLSYM_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
159 MSG_LA_SYMB_ALTVALUE_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
160 CONV_INV_BUFSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE
161
162 /*
163 * Ensure that Conv_la_symbind_buf_t is large enough:
164 *
165 * SYMBSZ is the real minimum size of the buffer required by conv_la_symbind().
166 * However, Conv_la_symbind_buf_t uses CONV_LA_SYMB_BUFSIZE to set the
167 * buffer size. We do things this way because the definition of SYMBSZ uses
168 * information that is not available in the environment of other programs
169 * that include the conv.h header file.
170 */
171 #if (CONV_LA_SYMBIND_BUFSIZE != SYMBSZ) && !defined(__lint)
172 #define REPORT_BUFSIZE SYMBSZ
173 #include "report_bufsize.h"
174 #error "CONV_LA_SYMBIND_BUFSIZE does not match SYMBSZ"
175 #endif
176
177 /*
178 * String conversion routine for la_symbind() flags.
179 */
180 const char *
conv_la_symbind(uint_t symbind,Conv_la_symbind_buf_t * la_symbind_buf)181 conv_la_symbind(uint_t symbind, Conv_la_symbind_buf_t *la_symbind_buf)
182 {
183 static const Val_desc vda[] = {
184 { LA_SYMB_NOPLTENTER, MSG_LA_SYMB_NOPLTENTER },
185 { LA_SYMB_NOPLTEXIT, MSG_LA_SYMB_NOPLTEXIT },
186 { LA_SYMB_STRUCTCALL, MSG_LA_SYMB_STRUCTCALL },
187 { LA_SYMB_DLSYM, MSG_LA_SYMB_DLSYM },
188 { LA_SYMB_ALTVALUE, MSG_LA_SYMB_ALTVALUE },
189 { 0, 0 }
190 };
191 static CONV_EXPN_FIELD_ARG conv_arg = {
192 NULL, sizeof (la_symbind_buf->buf), NULL };
193
194 if (symbind == 0)
195 return (MSG_ORIG(MSG_GBL_NULL));
196
197 conv_arg.buf = la_symbind_buf->buf;
198 conv_arg.oflags = conv_arg.rflags = symbind;
199
200 (void) conv_expn_field(&conv_arg, vda, 0);
201
202 return ((const char *)la_symbind_buf->buf);
203 }
204