dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / sgs / libcrle / common / audit.c
blobd5e94d7679f3beabf66d98c8e19937db2e20adda
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 /* LINTLIBRARY */
28 #include <link.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <unistd.h>
32 #include <strings.h>
33 #include <limits.h>
34 #include "rtld.h"
35 #include "_crle.h"
36 #include "msg.h"
39 * This file provides the LD_AUDIT interfaces for libcrle.so.1, which are
40 * called for one of two reasons:
42 * CRLE_AUD_DEPENDS
43 * under this mode, the dependencies of the application are
44 * gathered (similar to ldd(1)) and written back to the calling
45 * process.
47 * CRLE_AUD_DLDUMP
48 * under this mode, the LD_CONFIG file is read to determine which
49 * objects are to be dldump()'ed. The memory range occupied by
50 * the dumped images is written back to the calling process.
52 * Both of these interfaces are invoked via the crle(1) calling process. The
53 * following environment variables are used to communicate between the two:
55 * CRLE_FD the file descriptor on which to communicate to the calling
56 * process (used for CRLE_AUD_DEPENDS and CRLE_AUD_DUMP).
58 * CRLE_FLAGS this signals CRLE_AUD_DLDUMP mode, and indicates the required
59 * flags for the dldump(3x) calls.
62 static int auflag;
64 int pfd;
65 int dlflag = RTLD_CONFSET;
68 * Initial audit handshake, establish audit mode.
70 uint_t
71 /* ARGSUSED */
72 la_version(uint_t version)
74 char *str;
77 * Establish the file desciptor to communicate with the calling process,
78 * If there are any errors terminate the process.
80 if ((str = getenv(MSG_ORIG(MSG_ENV_AUD_FD))) == NULL)
81 exit(1);
82 pfd = atoi(str);
85 * Determine which audit mode is required based on the existance of
86 * CRLE_FLAGS.
88 if ((str = getenv(MSG_ORIG(MSG_ENV_AUD_FLAGS))) == NULL) {
89 auflag = CRLE_AUD_DEPENDS;
90 } else {
91 auflag = CRLE_AUD_DLDUMP;
92 dlflag |= atoi(str);
95 * Fill any memory holes before anything gets mapped.
97 if (filladdr() != 0)
98 exit(1);
102 * We need the audit interface containing la_objfilter().
104 return (LAV_VERSION3);
108 * Audit interface called for each dependency. If in CRLE_AUD_DEPENDS mode,
109 * return each dependency of the primary link-map to the caller.
111 uint_t
112 /* ARGSUSED2 */
113 la_objopen(Link_map * lmp, Lmid_t lmid, uintptr_t *cookie)
115 if (auflag == CRLE_AUD_DLDUMP)
116 return (0);
118 if ((lmid == LM_ID_BASE) &&
119 !(FLAGS(LINKMAP_TO_RTMAP(lmp)) & FLG_RT_ISMAIN)) {
120 char buffer[PATH_MAX];
122 (void) snprintf(buffer, PATH_MAX, MSG_ORIG(MSG_AUD_DEPEND),
123 lmp->l_name);
124 (void) write(pfd, buffer, strlen(buffer));
125 *cookie = (uintptr_t)lmp->l_name;
126 } else
127 *cookie = (uintptr_t)0;
129 return (0);
133 * Audit interface called for any filter/filtee pairs. If in CRLE_AUD_DEPENDS
134 * mode, return the filter/filtee association to the caller.
137 /* ARGSUSED2 */
138 la_objfilter(uintptr_t *fltrcook, const char *fltestr, uintptr_t *fltecook,
139 uint_t flags)
141 if (auflag == CRLE_AUD_DLDUMP)
142 return (0);
144 if (*fltrcook && *fltestr && *fltecook) {
145 char buffer[PATH_MAX];
147 (void) snprintf(buffer, PATH_MAX, MSG_ORIG(MSG_AUD_FILTER),
148 (char *)(*fltrcook), fltestr, (char *)(*fltecook));
149 (void) write(pfd, buffer, strlen(buffer));
151 return (1);
155 * Audit interface called before transfer of control to application. If in
156 * CRLE_AUD_DLDUMP mode read the configuration file and dldump() all necessary
157 * objects.
159 void
160 /* ARGSUSED */
161 la_preinit(uintptr_t *cookie)
163 if (auflag == CRLE_AUD_DLDUMP) {
164 if (dumpconfig() != 0)
165 exit(1);
167 exit(0);