17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
55aefb655Srie * Common Development and Distribution License (the "License").
65aefb655Srie * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
215aefb655Srie
227c478bd9Sstevel@tonic-gate /*
2323a1cceaSRoger A. Faulkner * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate #include <sys/types.h>
277c478bd9Sstevel@tonic-gate #include <sys/stat.h>
287c478bd9Sstevel@tonic-gate #include <sys/mman.h>
297c478bd9Sstevel@tonic-gate #include <fcntl.h>
307c478bd9Sstevel@tonic-gate #include <stdio.h>
317c478bd9Sstevel@tonic-gate #include <string.h>
327c478bd9Sstevel@tonic-gate #include <unistd.h>
337c478bd9Sstevel@tonic-gate #include <errno.h>
347c478bd9Sstevel@tonic-gate #include <limits.h>
357c478bd9Sstevel@tonic-gate #include "sgs.h"
367c478bd9Sstevel@tonic-gate #include "rtc.h"
377c478bd9Sstevel@tonic-gate #include "conv.h"
387c478bd9Sstevel@tonic-gate #include "_crle.h"
397c478bd9Sstevel@tonic-gate #include "msg.h"
407c478bd9Sstevel@tonic-gate
417c478bd9Sstevel@tonic-gate
427c478bd9Sstevel@tonic-gate /*
437c478bd9Sstevel@tonic-gate * Display the command line required to regenerate the configuration file.
447c478bd9Sstevel@tonic-gate *
457c478bd9Sstevel@tonic-gate * Under normal mode the command is printed on one line to make it more
467c478bd9Sstevel@tonic-gate * available for grep(1) use. Under verbose mode the command is separated
477c478bd9Sstevel@tonic-gate * into each argument (a little more readable perhaps when the arguments are
487c478bd9Sstevel@tonic-gate * numerous of have long pathnames).
497c478bd9Sstevel@tonic-gate *
507c478bd9Sstevel@tonic-gate * Note that for version 1 configuration files we never used to generate any
517c478bd9Sstevel@tonic-gate * command-line information, and as the attempt to do so is only a best effort
527c478bd9Sstevel@tonic-gate * don't bother printing anything.
537c478bd9Sstevel@tonic-gate */
547c478bd9Sstevel@tonic-gate static void
printcmd(Crle_desc * crle,Rtc_head * head,APlist * cmdline)5557ef7aa9SRod Evans printcmd(Crle_desc *crle, Rtc_head * head, APlist *cmdline)
567c478bd9Sstevel@tonic-gate {
5757ef7aa9SRod Evans Aliste idx, lidx;
587c478bd9Sstevel@tonic-gate const char *fmto, *fmtb, *fmtm, *fmte;
597c478bd9Sstevel@tonic-gate char *cmd;
607c478bd9Sstevel@tonic-gate int output = 0;
617c478bd9Sstevel@tonic-gate
627c478bd9Sstevel@tonic-gate if (crle->c_flags & CRLE_VERBOSE) {
637c478bd9Sstevel@tonic-gate fmto = MSG_INTL(MSG_DMP_CMD_ONE_V);
647c478bd9Sstevel@tonic-gate fmtb = MSG_INTL(MSG_DMP_CMD_BGN_V);
657c478bd9Sstevel@tonic-gate fmtm = MSG_INTL(MSG_DMP_CMD_MID_V);
667c478bd9Sstevel@tonic-gate fmte = MSG_INTL(MSG_DMP_CMD_END_V);
677c478bd9Sstevel@tonic-gate
687c478bd9Sstevel@tonic-gate } else if (head->ch_version > RTC_VER_ONE) {
697c478bd9Sstevel@tonic-gate fmto = MSG_INTL(MSG_DMP_CMD_ONE);
707c478bd9Sstevel@tonic-gate fmtb = MSG_INTL(MSG_DMP_CMD_BGN);
717c478bd9Sstevel@tonic-gate fmtm = MSG_INTL(MSG_DMP_CMD_MID);
727c478bd9Sstevel@tonic-gate fmte = MSG_INTL(MSG_DMP_CMD_END);
737c478bd9Sstevel@tonic-gate
747c478bd9Sstevel@tonic-gate } else {
757c478bd9Sstevel@tonic-gate (void) printf(MSG_ORIG(MSG_STR_NL));
767c478bd9Sstevel@tonic-gate return;
777c478bd9Sstevel@tonic-gate }
787c478bd9Sstevel@tonic-gate
797c478bd9Sstevel@tonic-gate (void) printf(MSG_INTL(MSG_DMP_CMD_TITLE));
8057ef7aa9SRod Evans
8157ef7aa9SRod Evans lidx = aplist_nitems(cmdline) - 1;
8257ef7aa9SRod Evans for (APLIST_TRAVERSE(cmdline, idx, cmd)) {
837c478bd9Sstevel@tonic-gate if (output++ == 0) {
8457ef7aa9SRod Evans if (idx < lidx)
857c478bd9Sstevel@tonic-gate (void) printf(fmtb, cmd);
867c478bd9Sstevel@tonic-gate else
877c478bd9Sstevel@tonic-gate (void) printf(fmto, cmd);
887c478bd9Sstevel@tonic-gate } else {
8957ef7aa9SRod Evans if (idx < lidx)
907c478bd9Sstevel@tonic-gate (void) printf(fmtm, cmd);
917c478bd9Sstevel@tonic-gate else
927c478bd9Sstevel@tonic-gate (void) printf(fmte, cmd);
937c478bd9Sstevel@tonic-gate }
947c478bd9Sstevel@tonic-gate }
957c478bd9Sstevel@tonic-gate }
967c478bd9Sstevel@tonic-gate
977c478bd9Sstevel@tonic-gate /*
987c478bd9Sstevel@tonic-gate * Establish the argument required to generate the associated object.
997c478bd9Sstevel@tonic-gate */
1007c478bd9Sstevel@tonic-gate static const char *
getformat(Half flags)1017c478bd9Sstevel@tonic-gate getformat(Half flags)
1027c478bd9Sstevel@tonic-gate {
1037c478bd9Sstevel@tonic-gate if (flags & RTC_OBJ_ALTER) {
1047c478bd9Sstevel@tonic-gate if (flags & RTC_OBJ_DUMP) {
1057c478bd9Sstevel@tonic-gate if (flags & RTC_OBJ_GROUP)
1067c478bd9Sstevel@tonic-gate return (MSG_ORIG(MSG_CMD_DUMPGRP));
1077c478bd9Sstevel@tonic-gate else
1087c478bd9Sstevel@tonic-gate return (MSG_ORIG(MSG_CMD_DUMPIND));
1097c478bd9Sstevel@tonic-gate } else {
1107c478bd9Sstevel@tonic-gate if (flags & RTC_OBJ_OPTINAL)
1117c478bd9Sstevel@tonic-gate return (MSG_ORIG(MSG_CMD_OPTIONAL));
1127c478bd9Sstevel@tonic-gate else
1137c478bd9Sstevel@tonic-gate return (MSG_ORIG(MSG_CMD_ALTER));
1147c478bd9Sstevel@tonic-gate }
1157c478bd9Sstevel@tonic-gate } else {
1167c478bd9Sstevel@tonic-gate if (flags & RTC_OBJ_GROUP)
1177c478bd9Sstevel@tonic-gate return (MSG_ORIG(MSG_CMD_GRP));
1187c478bd9Sstevel@tonic-gate else
1197c478bd9Sstevel@tonic-gate return (MSG_ORIG(MSG_CMD_IND));
1207c478bd9Sstevel@tonic-gate }
1217c478bd9Sstevel@tonic-gate }
1227c478bd9Sstevel@tonic-gate
1237c478bd9Sstevel@tonic-gate /*
1247c478bd9Sstevel@tonic-gate * Fabricate a system default search path. If an update is requested, and
1257c478bd9Sstevel@tonic-gate * new search paths are specified while no configuration file exists, or if a
1267c478bd9Sstevel@tonic-gate * configuration file does exist but doesn't specify this particular search
1277c478bd9Sstevel@tonic-gate * path, create any system defaults. The intent is to allow
1287c478bd9Sstevel@tonic-gate * "crle -u -l/usr/local/lib" and have this append the search path to the
1297c478bd9Sstevel@tonic-gate * system default, rather than have the user have to determine and specify
1307c478bd9Sstevel@tonic-gate * this default themselves.
1317c478bd9Sstevel@tonic-gate */
1327c478bd9Sstevel@tonic-gate static int
fablib(Crle_desc * crle,int flag)1337c478bd9Sstevel@tonic-gate fablib(Crle_desc * crle, int flag)
1347c478bd9Sstevel@tonic-gate {
1357c478bd9Sstevel@tonic-gate const char *path;
1367c478bd9Sstevel@tonic-gate char **list;
1377c478bd9Sstevel@tonic-gate
1387c478bd9Sstevel@tonic-gate switch (flag) {
1397c478bd9Sstevel@tonic-gate case CRLE_EDLIB:
140c13de8f6Sab #if M_CLASS == ELFCLASS64
141c13de8f6Sab path = MSG_ORIG(MSG_PTH_NEWDLP_64);
1427c478bd9Sstevel@tonic-gate #else
143c13de8f6Sab path = MSG_ORIG(MSG_PTH_NEWDLP);
1447c478bd9Sstevel@tonic-gate #endif
1457c478bd9Sstevel@tonic-gate list = &crle->c_edlibpath;
1467c478bd9Sstevel@tonic-gate break;
1477c478bd9Sstevel@tonic-gate
1487c478bd9Sstevel@tonic-gate case CRLE_ESLIB:
149c13de8f6Sab #if M_CLASS == ELFCLASS64
150c13de8f6Sab path = MSG_ORIG(MSG_PTH_NEWTD_64);
1517c478bd9Sstevel@tonic-gate #else
152c13de8f6Sab path = MSG_ORIG(MSG_PTH_NEWTD);
1537c478bd9Sstevel@tonic-gate #endif
1547c478bd9Sstevel@tonic-gate list = &crle->c_eslibpath;
1557c478bd9Sstevel@tonic-gate break;
1567c478bd9Sstevel@tonic-gate
1577c478bd9Sstevel@tonic-gate default:
1587c478bd9Sstevel@tonic-gate return (1);
1597c478bd9Sstevel@tonic-gate }
1607c478bd9Sstevel@tonic-gate
1617c478bd9Sstevel@tonic-gate return (addlib(crle, list, path));
1627c478bd9Sstevel@tonic-gate }
1637c478bd9Sstevel@tonic-gate
1647c478bd9Sstevel@tonic-gate /*
1657c478bd9Sstevel@tonic-gate * Establish the flags required to generate the associated object. Actually
1667c478bd9Sstevel@tonic-gate * the flags are already part of the object being inspected from the present
1677c478bd9Sstevel@tonic-gate * configuration file, but instead of using them all, which can cause some
1687c478bd9Sstevel@tonic-gate * unsuspected propagation down the inspect() family, only use those flags that
1697c478bd9Sstevel@tonic-gate * would have been contributed from crle()'s calls to inspect.
1707c478bd9Sstevel@tonic-gate */
1717c478bd9Sstevel@tonic-gate static Half
getflags(Half flags)1727c478bd9Sstevel@tonic-gate getflags(Half flags)
1737c478bd9Sstevel@tonic-gate {
1747c478bd9Sstevel@tonic-gate flags &=
1757c478bd9Sstevel@tonic-gate (RTC_OBJ_ALTER | RTC_OBJ_DUMP | RTC_OBJ_GROUP | RTC_OBJ_OPTINAL);
1767c478bd9Sstevel@tonic-gate return (flags | RTC_OBJ_CMDLINE);
1777c478bd9Sstevel@tonic-gate }
1787c478bd9Sstevel@tonic-gate
1797c478bd9Sstevel@tonic-gate /*
1807c478bd9Sstevel@tonic-gate * Dump a configuration files information. This routine is very close to the
1817c478bd9Sstevel@tonic-gate * scanconfig() in libcrle.
1827c478bd9Sstevel@tonic-gate */
183587032cfSab /*ARGSUSED2*/
184c13de8f6Sab static INSCFG_RET
scanconfig(Crle_desc * crle,Addr addr,int c_class)185587032cfSab scanconfig(Crle_desc * crle, Addr addr, int c_class)
1867c478bd9Sstevel@tonic-gate {
187d5fa36a7SToomas Soome Conv_inv_buf_t inv_buf1, inv_buf2, inv_buf3, inv_buf4;
188de777a60Sab Conv_dl_flag_buf_t dl_flag_buf;
189c13de8f6Sab Rtc_id *id;
190c13de8f6Sab Rtc_head *head;
1917c478bd9Sstevel@tonic-gate Rtc_dir *dirtbl;
1927c478bd9Sstevel@tonic-gate Rtc_file *filetbl;
19357ef7aa9SRod Evans Rtc_obj *objtbl, *obj;
19457ef7aa9SRod Evans Word *hash, *chain;
1957c478bd9Sstevel@tonic-gate const char *strtbl;
1967c478bd9Sstevel@tonic-gate int ndx, bkts;
19757ef7aa9SRod Evans APlist *cmdline = NULL;
198*fec04708SRichard Lowe boolean_t cmdset = B_FALSE;
19957ef7aa9SRod Evans char _cmd[PATH_MAX], *cmd;
20057ef7aa9SRod Evans char _objdir[PATH_MAX], *objdir = NULL;
201c13de8f6Sab
202c13de8f6Sab /*
203c13de8f6Sab * If there is an Rtc_id present, the Rtc_head follows it.
204c13de8f6Sab * Otherwise, it is at the top.
205c13de8f6Sab */
206c13de8f6Sab if (RTC_ID_TEST(addr)) {
207c13de8f6Sab id = (Rtc_id *) addr;
208c13de8f6Sab addr += sizeof (*id); /* Rtc_head follows */
209c13de8f6Sab } else {
210c13de8f6Sab id = NULL;
211c13de8f6Sab /*
212c13de8f6Sab * When updating an existing config file that is lacking
213c13de8f6Sab * the Rtc_id block, don't put one into the resulting file.
214c13de8f6Sab */
215c13de8f6Sab crle->c_flags &= ~CRLE_ADDID;
216c13de8f6Sab }
217c13de8f6Sab head = (Rtc_head *) addr;
218c13de8f6Sab
219c13de8f6Sab
220c13de8f6Sab /*
221c13de8f6Sab * The rest of the configuration file can only be examined by
222c13de8f6Sab * a program of the same ELFCLASS, byte order, and hardware
223c13de8f6Sab * architecture as the one that created it.
224c13de8f6Sab */
225c13de8f6Sab #ifdef _ELF64
226c13de8f6Sab /* 64-bit program with an existing 32-bit file? Abort. */
227c13de8f6Sab if (!(head->ch_cnflags & RTC_HDR_64)) {
228c13de8f6Sab (void) fprintf(stderr, MSG_INTL(MSG_ARG_CLASS),
229de777a60Sab crle->c_name, crle->c_confil);
230c13de8f6Sab return (INSCFG_RET_FAIL);
231c13de8f6Sab }
232c13de8f6Sab #else
233c13de8f6Sab /* 32-bit program with an existing 64-bit file? Restart. */
234c13de8f6Sab if (head->ch_cnflags & RTC_HDR_64)
235c13de8f6Sab return (INSCFG_RET_NEED64);
236587032cfSab
237587032cfSab /*
238587032cfSab * 32-bit program with an existing 32-bit file, but the
239587032cfSab * user specified the -64 option? Abort
240587032cfSab */
241587032cfSab if (c_class != ELFCLASS32) {
242587032cfSab (void) fprintf(stderr, MSG_INTL(MSG_ARG_CLASS),
243de777a60Sab crle->c_name, crle->c_confil);
244587032cfSab return (INSCFG_RET_FAIL);
245587032cfSab }
246c13de8f6Sab #endif
247c13de8f6Sab /*
248c13de8f6Sab * Now that the ELFCLASS has been settled, ensure that the
249c13de8f6Sab * byte order and hardware match. Unlike ELFCLASS, where restarting
250c13de8f6Sab * the other version is an option, we cannot work around a mismatch
251c13de8f6Sab * of these attributes.
252c13de8f6Sab */
253c13de8f6Sab if (id) { /* Rtc_id is present */
254c13de8f6Sab /*
255c13de8f6Sab * Was the file produced by compatible hardware?
256c13de8f6Sab * ELFCLASS doesn't matter here, because we can
257c13de8f6Sab * adjust for that, but byte order and machine type do.
258c13de8f6Sab */
259c13de8f6Sab if ((id->id_data != M_DATA) || (id->id_machine != M_MACH)) {
260c13de8f6Sab (void) fprintf(stderr, MSG_INTL(MSG_ARG_WRONGARCH),
261c13de8f6Sab crle->c_name, crle->c_confil,
262d29b2c44Sab conv_ehdr_data(id->id_data, CONV_FMT_ALT_FILE,
263de777a60Sab &inv_buf1),
264d29b2c44Sab conv_ehdr_mach(id->id_machine, CONV_FMT_ALT_FILE,
265de777a60Sab &inv_buf2),
266d29b2c44Sab conv_ehdr_data(M_DATA, CONV_FMT_ALT_FILE,
267d29b2c44Sab &inv_buf3),
268d29b2c44Sab conv_ehdr_mach(M_MACH, CONV_FMT_ALT_FILE,
269de777a60Sab &inv_buf4));
270c13de8f6Sab return (INSCFG_RET_FAIL);
271c13de8f6Sab }
272c13de8f6Sab }
273c13de8f6Sab
274c13de8f6Sab
2757c478bd9Sstevel@tonic-gate /* LINTED */
276c13de8f6Sab objtbl = (Rtc_obj *)(CAST_PTRINT(char *, head->ch_obj) + addr);
277c13de8f6Sab strtbl = (const char *)(CAST_PTRINT(char *, head->ch_str) + addr);
278c13de8f6Sab
279c13de8f6Sab /*
280c13de8f6Sab * If the configuration file has a version higher than we
281c13de8f6Sab * recognise, we face two issues:
282c13de8f6Sab * (1) Updates are not possible because we have no
283c13de8f6Sab * way to recognise or propagate the new features.
284c13de8f6Sab * This has to be a fatal error.
285c13de8f6Sab * (2) Printing has the risk that we may have been
286c13de8f6Sab * handed something other than a real config file, as
287c13de8f6Sab * well as the fact that we can't display the information
288c13de8f6Sab * for the new features. So, we print a warning, but
289c13de8f6Sab * continue on to do the best we can with it.
290c13de8f6Sab */
291c13de8f6Sab if (head->ch_version > RTC_VER_CURRENT) {
292c13de8f6Sab if (crle->c_flags & CRLE_UPDATE) {
293c13de8f6Sab (void) fprintf(stderr, MSG_INTL(MSG_ARG_UPDATEVER),
294de777a60Sab crle->c_name, crle->c_confil,
295de777a60Sab (int)head->ch_version, RTC_VER_CURRENT);
296c13de8f6Sab return (INSCFG_RET_FAIL);
297c13de8f6Sab } else {
298c13de8f6Sab (void) fprintf(stderr, MSG_INTL(MSG_ARG_PRINTVER),
299de777a60Sab crle->c_name, crle->c_confil,
300de777a60Sab (int)head->ch_version, RTC_VER_CURRENT);
301c13de8f6Sab }
302c13de8f6Sab }
3037c478bd9Sstevel@tonic-gate
3047c478bd9Sstevel@tonic-gate /*
3057c478bd9Sstevel@tonic-gate * If this is a version 1 configuration file we can't generate accurate
3067c478bd9Sstevel@tonic-gate * update information, or the command-line used to create the file.
3077c478bd9Sstevel@tonic-gate */
3087c478bd9Sstevel@tonic-gate if (head->ch_version == RTC_VER_ONE) {
3097c478bd9Sstevel@tonic-gate (void) printf(MSG_INTL(MSG_ARG_UPDATE), crle->c_name,
310587032cfSab crle->c_confil, (int)head->ch_version);
3117c478bd9Sstevel@tonic-gate }
3127c478bd9Sstevel@tonic-gate
313c13de8f6Sab
314c13de8f6Sab if (!(crle->c_flags & CRLE_UPDATE) && (head->ch_cnflags & RTC_HDR_64)) {
315c13de8f6Sab /*
316c13de8f6Sab * Construct the original command line argument.
317c13de8f6Sab */
31823a1cceaSRoger A. Faulkner cmd = strdupa(MSG_ORIG(MSG_CMD_64));
31957ef7aa9SRod Evans if (aplist_append(&cmdline, cmd, AL_CNT_CRLE) == NULL)
320c13de8f6Sab return (INSCFG_RET_FAIL);
3217c478bd9Sstevel@tonic-gate }
3227c478bd9Sstevel@tonic-gate
323c13de8f6Sab
3247c478bd9Sstevel@tonic-gate /*
3257c478bd9Sstevel@tonic-gate * Start analyzing the configuration files header information.
3267c478bd9Sstevel@tonic-gate */
3277c478bd9Sstevel@tonic-gate if ((crle->c_flags & CRLE_UPDATE) == 0) {
3287c478bd9Sstevel@tonic-gate const char *fmt;
3297c478bd9Sstevel@tonic-gate
3307c478bd9Sstevel@tonic-gate if (head->ch_dlflags)
331de777a60Sab fmt = conv_dl_flag(head->ch_dlflags, 0, &dl_flag_buf);
3327c478bd9Sstevel@tonic-gate else
3337c478bd9Sstevel@tonic-gate fmt = MSG_ORIG(MSG_STR_EMPTY);
3347c478bd9Sstevel@tonic-gate
335587032cfSab (void) printf(MSG_INTL(MSG_DMP_HEAD), (int)head->ch_version,
3367c478bd9Sstevel@tonic-gate crle->c_confil, fmt);
3377c478bd9Sstevel@tonic-gate
338c13de8f6Sab /*
339c13de8f6Sab * If the file has an id block, show the information
340c13de8f6Sab */
341c13de8f6Sab if (id)
342de777a60Sab (void) printf(MSG_INTL(MSG_DMP_PLATFORM),
343d29b2c44Sab conv_ehdr_class(id->id_class, CONV_FMT_ALT_FILE,
344de777a60Sab &inv_buf1),
345d29b2c44Sab conv_ehdr_data(id->id_data, CONV_FMT_ALT_FILE,
346de777a60Sab &inv_buf2),
347d29b2c44Sab conv_ehdr_mach(id->id_machine, CONV_FMT_ALT_FILE,
348de777a60Sab &inv_buf3));
349c13de8f6Sab
3507c478bd9Sstevel@tonic-gate /*
3517c478bd9Sstevel@tonic-gate * Construct the original command line argument.
3527c478bd9Sstevel@tonic-gate */
3537c478bd9Sstevel@tonic-gate (void) snprintf(_cmd, PATH_MAX, MSG_ORIG(MSG_CMD_CONF),
3547c478bd9Sstevel@tonic-gate crle->c_confil);
35523a1cceaSRoger A. Faulkner cmd = strdupa(_cmd);
35657ef7aa9SRod Evans if (aplist_append(&cmdline, cmd, AL_CNT_CRLE) == NULL)
357c13de8f6Sab return (INSCFG_RET_FAIL);
3587c478bd9Sstevel@tonic-gate
3597c478bd9Sstevel@tonic-gate /*
3607c478bd9Sstevel@tonic-gate * Construct any -f usage.
3617c478bd9Sstevel@tonic-gate */
3627c478bd9Sstevel@tonic-gate if (head->ch_dlflags &&
3637c478bd9Sstevel@tonic-gate (head->ch_dlflags != RTLD_REL_RELATIVE)) {
3647c478bd9Sstevel@tonic-gate (void) snprintf(_cmd, PATH_MAX, MSG_ORIG(MSG_CMD_FLAGS),
365d29b2c44Sab conv_dl_flag(head->ch_dlflags, CONV_FMT_ALT_CRLE,
366de777a60Sab &dl_flag_buf));
36723a1cceaSRoger A. Faulkner cmd = strdupa(_cmd);
368*fec04708SRichard Lowe cmdset = B_TRUE;
36957ef7aa9SRod Evans if (aplist_append(&cmdline, cmd, AL_CNT_CRLE) == NULL)
370c13de8f6Sab return (INSCFG_RET_FAIL);
3717c478bd9Sstevel@tonic-gate }
3727c478bd9Sstevel@tonic-gate } else {
3737c478bd9Sstevel@tonic-gate /*
3747c478bd9Sstevel@tonic-gate * Establish any -f usage.
3757c478bd9Sstevel@tonic-gate */
3767c478bd9Sstevel@tonic-gate if (head->ch_dlflags &&
3777c478bd9Sstevel@tonic-gate (head->ch_dlflags != RTLD_REL_RELATIVE))
3787c478bd9Sstevel@tonic-gate crle->c_dlflags = head->ch_dlflags;
3797c478bd9Sstevel@tonic-gate }
3807c478bd9Sstevel@tonic-gate
3817c478bd9Sstevel@tonic-gate
3827c478bd9Sstevel@tonic-gate /*
3837c478bd9Sstevel@tonic-gate * Determine if this configuration file is only applicable to a specific
3847c478bd9Sstevel@tonic-gate * application.
3857c478bd9Sstevel@tonic-gate */
3867c478bd9Sstevel@tonic-gate if (head->ch_app) {
3877c478bd9Sstevel@tonic-gate char *alter;
3887c478bd9Sstevel@tonic-gate
3897c478bd9Sstevel@tonic-gate obj = (Rtc_obj *)(head->ch_app + addr);
3907c478bd9Sstevel@tonic-gate
3917c478bd9Sstevel@tonic-gate /*
3927c478bd9Sstevel@tonic-gate * Determine the output directory for the files
3937c478bd9Sstevel@tonic-gate * alternative name.
3947c478bd9Sstevel@tonic-gate */
3957c478bd9Sstevel@tonic-gate alter = (char *)(strtbl + obj->co_alter);
3967c478bd9Sstevel@tonic-gate (void) strcpy(_objdir, alter);
3977c478bd9Sstevel@tonic-gate alter = strrchr(_objdir, '/');
3987c478bd9Sstevel@tonic-gate *alter = '\0';
3997c478bd9Sstevel@tonic-gate
4007c478bd9Sstevel@tonic-gate crle->c_objdir = objdir = _objdir;
4017c478bd9Sstevel@tonic-gate
4027c478bd9Sstevel@tonic-gate if (crle->c_flags & CRLE_UPDATE) {
4037c478bd9Sstevel@tonic-gate if (inspect(crle, (strtbl + obj->co_name),
4047c478bd9Sstevel@tonic-gate (RTC_OBJ_DUMP | RTC_OBJ_ALTER |
4057c478bd9Sstevel@tonic-gate RTC_OBJ_GROUP | RTC_OBJ_CMDLINE)) != 0)
406c13de8f6Sab return (INSCFG_RET_FAIL);
4077c478bd9Sstevel@tonic-gate } else {
4087c478bd9Sstevel@tonic-gate (void) printf(MSG_INTL(MSG_DMP_APP),
4097c478bd9Sstevel@tonic-gate (strtbl + obj->co_alter), (strtbl + obj->co_name));
4107c478bd9Sstevel@tonic-gate
4117c478bd9Sstevel@tonic-gate /*
4127c478bd9Sstevel@tonic-gate * Construct the original command line arguments.
4137c478bd9Sstevel@tonic-gate */
414*fec04708SRichard Lowe cmdset = B_TRUE;
4157c478bd9Sstevel@tonic-gate (void) snprintf(_cmd, PATH_MAX,
4167c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_CMD_OUTPUT), crle->c_objdir);
41723a1cceaSRoger A. Faulkner cmd = strdupa(_cmd);
41857ef7aa9SRod Evans if (aplist_append(&cmdline, cmd, AL_CNT_CRLE) == NULL)
419c13de8f6Sab return (INSCFG_RET_FAIL);
4207c478bd9Sstevel@tonic-gate
4217c478bd9Sstevel@tonic-gate (void) snprintf(_cmd, PATH_MAX,
4227c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_CMD_DUMPGRP), (strtbl + obj->co_name));
42323a1cceaSRoger A. Faulkner cmd = strdupa(_cmd);
42457ef7aa9SRod Evans if (aplist_append(&cmdline, cmd, AL_CNT_CRLE) == NULL)
425c13de8f6Sab return (INSCFG_RET_FAIL);
4267c478bd9Sstevel@tonic-gate }
4277c478bd9Sstevel@tonic-gate }
4287c478bd9Sstevel@tonic-gate
4297c478bd9Sstevel@tonic-gate /*
4307c478bd9Sstevel@tonic-gate * Analyze any alternative library path and trusted directory entries.
4317c478bd9Sstevel@tonic-gate */
4327c478bd9Sstevel@tonic-gate if (head->ch_edlibpath) {
4337c478bd9Sstevel@tonic-gate const char *str;
4347c478bd9Sstevel@tonic-gate
4357c478bd9Sstevel@tonic-gate str = (const char *)(head->ch_edlibpath + addr);
4367c478bd9Sstevel@tonic-gate
4377c478bd9Sstevel@tonic-gate if (crle->c_flags & CRLE_UPDATE) {
4387c478bd9Sstevel@tonic-gate
4397c478bd9Sstevel@tonic-gate if ((head->ch_cnflags & RTC_HDR_UPM) == 0) {
4407c478bd9Sstevel@tonic-gate if (head->ch_cnflags & RTC_HDR_64)
4415aefb655Srie str = conv_config_upm(str,
4427c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_PTH_OLDDLP_64),
4437c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_PTH_UPDLP_64),
4447c478bd9Sstevel@tonic-gate MSG_PTH_UPDLP_64_SIZE);
4457c478bd9Sstevel@tonic-gate else
4465aefb655Srie str = conv_config_upm(str,
4477c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_PTH_OLDDLP),
4487c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_PTH_UPDLP),
4497c478bd9Sstevel@tonic-gate MSG_PTH_UPDLP_SIZE);
4507c478bd9Sstevel@tonic-gate }
4517c478bd9Sstevel@tonic-gate if (addlib(crle, &crle->c_edlibpath, str) != 0)
452c13de8f6Sab return (INSCFG_RET_FAIL);
4537c478bd9Sstevel@tonic-gate } else {
4547c478bd9Sstevel@tonic-gate (void) printf(MSG_INTL(MSG_DMP_DLIBPTH),
4557c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_STR_ELF), str);
4567c478bd9Sstevel@tonic-gate
4577c478bd9Sstevel@tonic-gate (void) snprintf(_cmd, PATH_MAX,
4587c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_CMD_EDLIB), str);
45923a1cceaSRoger A. Faulkner cmd = strdupa(_cmd);
460*fec04708SRichard Lowe cmdset = B_TRUE;
46157ef7aa9SRod Evans if (aplist_append(&cmdline, cmd, AL_CNT_CRLE) == NULL)
462c13de8f6Sab return (INSCFG_RET_FAIL);
4637c478bd9Sstevel@tonic-gate }
4647c478bd9Sstevel@tonic-gate } else {
4657c478bd9Sstevel@tonic-gate if (crle->c_flags & CRLE_UPDATE) {
4667c478bd9Sstevel@tonic-gate if (crle->c_flags & CRLE_EDLIB) {
4677c478bd9Sstevel@tonic-gate /*
4687c478bd9Sstevel@tonic-gate * If we've been asked to update a configuration
4697c478bd9Sstevel@tonic-gate * file, and no existing default ELF search
4707c478bd9Sstevel@tonic-gate * path exists, but the user is going to add new
4717c478bd9Sstevel@tonic-gate * entries, fabricate the system defaults so
4727c478bd9Sstevel@tonic-gate * that the users get added to them.
4737c478bd9Sstevel@tonic-gate */
4747c478bd9Sstevel@tonic-gate if (fablib(crle, CRLE_EDLIB) != 0)
475c13de8f6Sab return (INSCFG_RET_FAIL);
4767c478bd9Sstevel@tonic-gate }
4777c478bd9Sstevel@tonic-gate } else {
4787c478bd9Sstevel@tonic-gate /*
4797c478bd9Sstevel@tonic-gate * Indicate any system default.
4807c478bd9Sstevel@tonic-gate */
481c13de8f6Sab #if M_CLASS == ELFCLASS64
482c13de8f6Sab (void) printf(MSG_INTL(MSG_DEF_NEWDLP_64));
4837c478bd9Sstevel@tonic-gate #else
484c13de8f6Sab (void) printf(MSG_INTL(MSG_DEF_NEWDLP));
4857c478bd9Sstevel@tonic-gate #endif
4867c478bd9Sstevel@tonic-gate }
4877c478bd9Sstevel@tonic-gate }
4887c478bd9Sstevel@tonic-gate
4897c478bd9Sstevel@tonic-gate if (head->ch_eslibpath) {
4907c478bd9Sstevel@tonic-gate const char *str;
4917c478bd9Sstevel@tonic-gate
4927c478bd9Sstevel@tonic-gate str = (const char *)(head->ch_eslibpath + addr);
4937c478bd9Sstevel@tonic-gate
4947c478bd9Sstevel@tonic-gate if (crle->c_flags & CRLE_UPDATE) {
4957c478bd9Sstevel@tonic-gate
4967c478bd9Sstevel@tonic-gate if ((head->ch_cnflags & RTC_HDR_UPM) == 0) {
4977c478bd9Sstevel@tonic-gate if (head->ch_cnflags & RTC_HDR_64)
4985aefb655Srie str = conv_config_upm(str,
4997c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_PTH_OLDTD_64),
5007c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_PTH_UPTD_64),
5017c478bd9Sstevel@tonic-gate MSG_PTH_UPTD_64_SIZE);
5027c478bd9Sstevel@tonic-gate else
5035aefb655Srie str = conv_config_upm(str,
5047c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_PTH_OLDTD),
5057c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_PTH_UPTD),
5067c478bd9Sstevel@tonic-gate MSG_PTH_UPTD_SIZE);
5077c478bd9Sstevel@tonic-gate }
5087c478bd9Sstevel@tonic-gate if (addlib(crle, &crle->c_eslibpath, str) != 0)
509c13de8f6Sab return (INSCFG_RET_FAIL);
5107c478bd9Sstevel@tonic-gate } else {
5117c478bd9Sstevel@tonic-gate (void) printf(MSG_INTL(MSG_DMP_TLIBPTH),
5127c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_STR_ELF), str);
5137c478bd9Sstevel@tonic-gate
5147c478bd9Sstevel@tonic-gate (void) snprintf(_cmd, PATH_MAX,
5157c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_CMD_ESLIB), str);
51623a1cceaSRoger A. Faulkner cmd = strdupa(_cmd);
517*fec04708SRichard Lowe cmdset = B_TRUE;
51857ef7aa9SRod Evans if (aplist_append(&cmdline, cmd, AL_CNT_CRLE) == NULL)
519c13de8f6Sab return (INSCFG_RET_FAIL);
5207c478bd9Sstevel@tonic-gate }
5217c478bd9Sstevel@tonic-gate } else {
5227c478bd9Sstevel@tonic-gate if (crle->c_flags & CRLE_UPDATE) {
5237c478bd9Sstevel@tonic-gate if (crle->c_flags & CRLE_ESLIB) {
5247c478bd9Sstevel@tonic-gate /*
5257c478bd9Sstevel@tonic-gate * If we've been asked to update a configuration
5267c478bd9Sstevel@tonic-gate * file, and no existing default ELF secure
5277c478bd9Sstevel@tonic-gate * path exists, but the user is going to add new
5287c478bd9Sstevel@tonic-gate * entries, fabricate the system defaults so
5297c478bd9Sstevel@tonic-gate * that the users get added to them.
5307c478bd9Sstevel@tonic-gate */
5317c478bd9Sstevel@tonic-gate if (fablib(crle, CRLE_ESLIB) != 0)
532c13de8f6Sab return (INSCFG_RET_FAIL);
5337c478bd9Sstevel@tonic-gate }
5347c478bd9Sstevel@tonic-gate } else {
5357c478bd9Sstevel@tonic-gate /*
5367c478bd9Sstevel@tonic-gate * Indicate any system default.
5377c478bd9Sstevel@tonic-gate */
538c13de8f6Sab #if M_CLASS == ELFCLASS64
539c13de8f6Sab (void) printf(MSG_INTL(MSG_DEF_NEWTD_64));
5407c478bd9Sstevel@tonic-gate #else
541c13de8f6Sab (void) printf(MSG_INTL(MSG_DEF_NEWTD));
5427c478bd9Sstevel@tonic-gate #endif
5437c478bd9Sstevel@tonic-gate }
5447c478bd9Sstevel@tonic-gate }
5457c478bd9Sstevel@tonic-gate
5467c478bd9Sstevel@tonic-gate /*
5477c478bd9Sstevel@tonic-gate * Display any environment variables.
5487c478bd9Sstevel@tonic-gate */
5497c478bd9Sstevel@tonic-gate if ((head->ch_version >= RTC_VER_THREE) && head->ch_env) {
55057ef7aa9SRod Evans Rtc_env *envtbl;
5517c478bd9Sstevel@tonic-gate
5527c478bd9Sstevel@tonic-gate if ((crle->c_flags & CRLE_UPDATE) == 0)
5537c478bd9Sstevel@tonic-gate (void) printf(MSG_INTL(MSG_ENV_TITLE));
5547c478bd9Sstevel@tonic-gate
5557c478bd9Sstevel@tonic-gate for (envtbl = (Rtc_env *)(head->ch_env + addr);
5567c478bd9Sstevel@tonic-gate envtbl->env_str; envtbl++) {
5577c478bd9Sstevel@tonic-gate const char *str;
5587c478bd9Sstevel@tonic-gate
5597c478bd9Sstevel@tonic-gate str = (const char *)(envtbl->env_str + addr);
5607c478bd9Sstevel@tonic-gate
5617c478bd9Sstevel@tonic-gate if (crle->c_flags & CRLE_UPDATE) {
5627c478bd9Sstevel@tonic-gate if (addenv(crle, str,
5637c478bd9Sstevel@tonic-gate (envtbl->env_flags | RTC_ENV_CONFIG)) == 0)
564c13de8f6Sab return (INSCFG_RET_FAIL);
5657c478bd9Sstevel@tonic-gate } else {
5667c478bd9Sstevel@tonic-gate const char *pfmt, *sfmt;
5677c478bd9Sstevel@tonic-gate
5687c478bd9Sstevel@tonic-gate if (envtbl->env_flags & RTC_ENV_PERMANT) {
5697c478bd9Sstevel@tonic-gate pfmt = MSG_INTL(MSG_ENV_PRM);
5707c478bd9Sstevel@tonic-gate sfmt = MSG_ORIG(MSG_CMD_PRMENV);
5717c478bd9Sstevel@tonic-gate } else {
5727c478bd9Sstevel@tonic-gate pfmt = MSG_INTL(MSG_ENV_RPL);
5737c478bd9Sstevel@tonic-gate sfmt = MSG_ORIG(MSG_CMD_RPLENV);
5747c478bd9Sstevel@tonic-gate }
5757c478bd9Sstevel@tonic-gate (void) printf(pfmt, str);
5767c478bd9Sstevel@tonic-gate (void) snprintf(_cmd, PATH_MAX, sfmt, str);
57723a1cceaSRoger A. Faulkner cmd = strdupa(_cmd);
578*fec04708SRichard Lowe cmdset = B_TRUE;
57957ef7aa9SRod Evans if (aplist_append(&cmdline, cmd,
58057ef7aa9SRod Evans AL_CNT_CRLE) == NULL)
581c13de8f6Sab return (INSCFG_RET_FAIL);
5827c478bd9Sstevel@tonic-gate }
5837c478bd9Sstevel@tonic-gate }
5847c478bd9Sstevel@tonic-gate }
5857c478bd9Sstevel@tonic-gate
5867c478bd9Sstevel@tonic-gate /*
5877c478bd9Sstevel@tonic-gate * Display any filter/filtee associations.
5887c478bd9Sstevel@tonic-gate */
5897c478bd9Sstevel@tonic-gate if ((head->ch_version >= RTC_VER_FOUR) && head->ch_fltr) {
5907c478bd9Sstevel@tonic-gate if ((crle->c_flags & CRLE_UPDATE) == 0) {
59157ef7aa9SRod Evans Rtc_fltr *fltrtbl;
59257ef7aa9SRod Evans Rtc_flte *fltetbl;
5937c478bd9Sstevel@tonic-gate
5947c478bd9Sstevel@tonic-gate /* LINTED */
595c13de8f6Sab fltrtbl = (Rtc_fltr *)
596de777a60Sab (CAST_PTRINT(char *, head->ch_fltr) + addr);
5977c478bd9Sstevel@tonic-gate /* LINTED */
598c13de8f6Sab fltetbl = (Rtc_flte *)
599de777a60Sab (CAST_PTRINT(char *, head->ch_flte) + addr);
6007c478bd9Sstevel@tonic-gate
6017c478bd9Sstevel@tonic-gate (void) printf(MSG_INTL(MSG_FLT_TITLE));
6027c478bd9Sstevel@tonic-gate
6037c478bd9Sstevel@tonic-gate while (fltrtbl->fr_filter) {
6047c478bd9Sstevel@tonic-gate Rtc_flte *_fltetbl;
6057c478bd9Sstevel@tonic-gate
6067c478bd9Sstevel@tonic-gate /*
6077c478bd9Sstevel@tonic-gate * Print the filter and filtee string pair.
6087c478bd9Sstevel@tonic-gate */
6097c478bd9Sstevel@tonic-gate (void) printf(MSG_INTL(MSG_FLT_FILTER),
6107c478bd9Sstevel@tonic-gate (strtbl + fltrtbl->fr_filter),
6117c478bd9Sstevel@tonic-gate (strtbl + fltrtbl->fr_string));
6127c478bd9Sstevel@tonic-gate
6137c478bd9Sstevel@tonic-gate /*
6147c478bd9Sstevel@tonic-gate * Print each filtee.
6157c478bd9Sstevel@tonic-gate */
6167c478bd9Sstevel@tonic-gate /* LINTED */
6177c478bd9Sstevel@tonic-gate for (_fltetbl = (Rtc_flte *)((char *)fltetbl +
6187c478bd9Sstevel@tonic-gate fltrtbl->fr_filtee); _fltetbl->fe_filtee;
6197c478bd9Sstevel@tonic-gate _fltetbl++) {
6207c478bd9Sstevel@tonic-gate (void) printf(MSG_INTL(MSG_FLT_FILTEE),
6217c478bd9Sstevel@tonic-gate (strtbl + _fltetbl->fe_filtee));
6227c478bd9Sstevel@tonic-gate }
6237c478bd9Sstevel@tonic-gate fltrtbl++;
6247c478bd9Sstevel@tonic-gate }
6257c478bd9Sstevel@tonic-gate }
6267c478bd9Sstevel@tonic-gate }
6277c478bd9Sstevel@tonic-gate
6287c478bd9Sstevel@tonic-gate /*
6297c478bd9Sstevel@tonic-gate * Display any memory reservations required for any alternative
6307c478bd9Sstevel@tonic-gate * objects.
6317c478bd9Sstevel@tonic-gate */
6327c478bd9Sstevel@tonic-gate if (head->ch_resbgn && ((crle->c_flags & CRLE_UPDATE) == 0))
633587032cfSab (void) printf(MSG_INTL(MSG_DMP_RESV),
634de777a60Sab (u_longlong_t)head->ch_resbgn,
635de777a60Sab (u_longlong_t)head->ch_resend,
636de777a60Sab (u_longlong_t)(head->ch_resend - head->ch_resbgn));
6377c478bd9Sstevel@tonic-gate
6387c478bd9Sstevel@tonic-gate /*
6397c478bd9Sstevel@tonic-gate * If there's no hash table there's nothing else to process.
6407c478bd9Sstevel@tonic-gate */
6417c478bd9Sstevel@tonic-gate if (head->ch_hash == 0) {
642*fec04708SRichard Lowe if (((crle->c_flags & CRLE_UPDATE) == 0) && cmdset)
64357ef7aa9SRod Evans printcmd(crle, head, cmdline);
644c13de8f6Sab return (INSCFG_RET_OK);
6457c478bd9Sstevel@tonic-gate }
6467c478bd9Sstevel@tonic-gate
6477c478bd9Sstevel@tonic-gate /*
6487c478bd9Sstevel@tonic-gate * Traverse the directory and filename arrays.
6497c478bd9Sstevel@tonic-gate */
6507c478bd9Sstevel@tonic-gate for (dirtbl = (Rtc_dir *)(head->ch_dir + addr);
6517c478bd9Sstevel@tonic-gate dirtbl->cd_obj; dirtbl++) {
6527c478bd9Sstevel@tonic-gate struct stat status;
6537c478bd9Sstevel@tonic-gate Rtc_obj *dobj;
6547c478bd9Sstevel@tonic-gate const char *str;
6557c478bd9Sstevel@tonic-gate
6567c478bd9Sstevel@tonic-gate dobj = (Rtc_obj *)(dirtbl->cd_obj + addr);
6577c478bd9Sstevel@tonic-gate filetbl = (Rtc_file *)(dirtbl->cd_file + addr);
6587c478bd9Sstevel@tonic-gate str = strtbl + dobj->co_name;
6597c478bd9Sstevel@tonic-gate
6607c478bd9Sstevel@tonic-gate /*
6617c478bd9Sstevel@tonic-gate * Simplify recreation by using any command-line directories.
6627c478bd9Sstevel@tonic-gate * If we're dealing with a version 1 configuration file use
6637c478bd9Sstevel@tonic-gate * every directory.
6647c478bd9Sstevel@tonic-gate */
6657c478bd9Sstevel@tonic-gate if ((dobj->co_flags & RTC_OBJ_CMDLINE) ||
6667c478bd9Sstevel@tonic-gate (head->ch_version == RTC_VER_ONE)) {
6677c478bd9Sstevel@tonic-gate if (crle->c_flags & CRLE_UPDATE) {
6687c478bd9Sstevel@tonic-gate if (inspect(crle, str,
6697c478bd9Sstevel@tonic-gate getflags(dobj->co_flags)) != 0)
670c13de8f6Sab return (INSCFG_RET_FAIL);
6717c478bd9Sstevel@tonic-gate if ((dobj->co_flags &
6727c478bd9Sstevel@tonic-gate (RTC_OBJ_NOEXIST | RTC_OBJ_ALTER)) ==
6737c478bd9Sstevel@tonic-gate RTC_OBJ_NOEXIST)
6747c478bd9Sstevel@tonic-gate continue;
6757c478bd9Sstevel@tonic-gate } else {
6767c478bd9Sstevel@tonic-gate /* LINTED */
6777c478bd9Sstevel@tonic-gate (void) snprintf(_cmd, PATH_MAX,
6787c478bd9Sstevel@tonic-gate getformat(dobj->co_flags), str);
67923a1cceaSRoger A. Faulkner cmd = strdupa(_cmd);
680*fec04708SRichard Lowe cmdset = B_TRUE;
68157ef7aa9SRod Evans if (aplist_append(&cmdline, cmd,
68257ef7aa9SRod Evans AL_CNT_CRLE) == NULL)
683c13de8f6Sab return (INSCFG_RET_FAIL);
6847c478bd9Sstevel@tonic-gate }
6857c478bd9Sstevel@tonic-gate }
6867c478bd9Sstevel@tonic-gate
6877c478bd9Sstevel@tonic-gate /*
6887c478bd9Sstevel@tonic-gate * If this isn't an update print the directory name. If the
6897c478bd9Sstevel@tonic-gate * directory has no entries (possible if the directory is a
6907c478bd9Sstevel@tonic-gate * symlink to another directory, in which case we record the
6917c478bd9Sstevel@tonic-gate * real path also), don't bother printing it unless we're in
6927c478bd9Sstevel@tonic-gate * verbose mode.
6937c478bd9Sstevel@tonic-gate */
6947c478bd9Sstevel@tonic-gate if ((crle->c_flags & CRLE_UPDATE) == 0) {
6957c478bd9Sstevel@tonic-gate if ((dobj->co_flags &
6967c478bd9Sstevel@tonic-gate (RTC_OBJ_NOEXIST | RTC_OBJ_ALTER)) ==
6977c478bd9Sstevel@tonic-gate RTC_OBJ_NOEXIST) {
6987c478bd9Sstevel@tonic-gate (void) printf(MSG_INTL(MSG_DMP_DIR_2), str);
6997c478bd9Sstevel@tonic-gate continue;
7007c478bd9Sstevel@tonic-gate } else if (filetbl->cf_obj ||
7017c478bd9Sstevel@tonic-gate (crle->c_flags & CRLE_VERBOSE))
7027c478bd9Sstevel@tonic-gate (void) printf(MSG_INTL(MSG_DMP_DIR_1), str);
7037c478bd9Sstevel@tonic-gate }
7047c478bd9Sstevel@tonic-gate
7057c478bd9Sstevel@tonic-gate /*
7067c478bd9Sstevel@tonic-gate * Under verbose mode validate any real directory entry - the
7077c478bd9Sstevel@tonic-gate * same test will be carried out by ld.so.1.
7087c478bd9Sstevel@tonic-gate */
7097c478bd9Sstevel@tonic-gate if (((crle->c_flags & CRLE_UPDATE) == 0) &&
7107c478bd9Sstevel@tonic-gate (crle->c_flags & CRLE_VERBOSE) &&
7117c478bd9Sstevel@tonic-gate (dobj->co_flags & RTC_OBJ_REALPTH)) {
7127c478bd9Sstevel@tonic-gate if (stat(str, &status) != 0) {
7137c478bd9Sstevel@tonic-gate int err = errno;
7147c478bd9Sstevel@tonic-gate (void) printf(MSG_INTL(MSG_DMP_STAT), str,
7157c478bd9Sstevel@tonic-gate strerror(err));
7167c478bd9Sstevel@tonic-gate } else if (status.st_mtime != dobj->co_info) {
7177c478bd9Sstevel@tonic-gate (void) printf(MSG_INTL(MSG_DMP_DCMP), str);
7187c478bd9Sstevel@tonic-gate }
7197c478bd9Sstevel@tonic-gate }
7207c478bd9Sstevel@tonic-gate
7217c478bd9Sstevel@tonic-gate for (; filetbl->cf_obj; filetbl++) {
72257ef7aa9SRod Evans Rtc_obj *fobj;
72357ef7aa9SRod Evans Half flags;
7247c478bd9Sstevel@tonic-gate
7257c478bd9Sstevel@tonic-gate fobj = (Rtc_obj *)(filetbl->cf_obj + addr);
7267c478bd9Sstevel@tonic-gate str = strtbl + fobj->co_name;
7277c478bd9Sstevel@tonic-gate flags = fobj->co_flags;
7287c478bd9Sstevel@tonic-gate
7297c478bd9Sstevel@tonic-gate /*
7307c478bd9Sstevel@tonic-gate * Only update individual files that were originally
7317c478bd9Sstevel@tonic-gate * specified on the command-line. Or, if this is a
7327c478bd9Sstevel@tonic-gate * version 1 configuration file use every file that
7337c478bd9Sstevel@tonic-gate * isn't part of an all-entries directory.
7347c478bd9Sstevel@tonic-gate */
7357c478bd9Sstevel@tonic-gate if (((flags & RTC_OBJ_CMDLINE) &&
7367c478bd9Sstevel@tonic-gate ((fobj->co_flags & RTC_OBJ_APP) == 0)) ||
7377c478bd9Sstevel@tonic-gate ((head->ch_version == RTC_VER_ONE) &&
7387c478bd9Sstevel@tonic-gate ((dobj->co_flags & RTC_OBJ_ALLENTS) == 0))) {
73957ef7aa9SRod Evans char *alter = NULL, altdir[PATH_MAX];
7407c478bd9Sstevel@tonic-gate
7417c478bd9Sstevel@tonic-gate /*
7427c478bd9Sstevel@tonic-gate * Determine whether this file requires an
7437c478bd9Sstevel@tonic-gate * alternative, and if so, and we haven't
7447c478bd9Sstevel@tonic-gate * already an alternative in affect, create one.
7457c478bd9Sstevel@tonic-gate */
7467c478bd9Sstevel@tonic-gate if (fobj->co_flags & RTC_OBJ_ALTER) {
7477c478bd9Sstevel@tonic-gate alter = (char *)(strtbl +
7487c478bd9Sstevel@tonic-gate fobj->co_alter);
7497c478bd9Sstevel@tonic-gate (void) strcpy(altdir, alter);
7507c478bd9Sstevel@tonic-gate alter = strrchr(altdir, '/');
7517c478bd9Sstevel@tonic-gate *alter = '\0';
7527c478bd9Sstevel@tonic-gate
75357ef7aa9SRod Evans if ((objdir == NULL) ||
7547c478bd9Sstevel@tonic-gate (strcmp(objdir, altdir) != 0)) {
7557c478bd9Sstevel@tonic-gate (void) strcpy(_objdir, altdir);
7567c478bd9Sstevel@tonic-gate crle->c_objdir = alter =
7577c478bd9Sstevel@tonic-gate objdir = _objdir;
7587c478bd9Sstevel@tonic-gate } else
75957ef7aa9SRod Evans alter = NULL;
7607c478bd9Sstevel@tonic-gate }
7617c478bd9Sstevel@tonic-gate
7627c478bd9Sstevel@tonic-gate if (crle->c_flags & CRLE_UPDATE) {
7637c478bd9Sstevel@tonic-gate if (inspect(crle, str,
7647c478bd9Sstevel@tonic-gate getflags(flags)) != 0)
765c13de8f6Sab return (INSCFG_RET_FAIL);
7667c478bd9Sstevel@tonic-gate continue;
7677c478bd9Sstevel@tonic-gate }
7687c478bd9Sstevel@tonic-gate
7697c478bd9Sstevel@tonic-gate if (alter) {
7707c478bd9Sstevel@tonic-gate (void) snprintf(_cmd, PATH_MAX,
7717c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_CMD_OUTPUT),
7727c478bd9Sstevel@tonic-gate crle->c_objdir);
77323a1cceaSRoger A. Faulkner cmd = strdupa(_cmd);
774*fec04708SRichard Lowe cmdset = B_TRUE;
77557ef7aa9SRod Evans if (aplist_append(&cmdline, cmd,
77657ef7aa9SRod Evans AL_CNT_CRLE) == NULL)
777c13de8f6Sab return (INSCFG_RET_FAIL);
7787c478bd9Sstevel@tonic-gate }
7797c478bd9Sstevel@tonic-gate
7807c478bd9Sstevel@tonic-gate /* LINTED */
7817c478bd9Sstevel@tonic-gate (void) snprintf(_cmd, PATH_MAX,
7827c478bd9Sstevel@tonic-gate getformat(flags), str);
78323a1cceaSRoger A. Faulkner cmd = strdupa(_cmd);
784*fec04708SRichard Lowe cmdset = B_TRUE;
78557ef7aa9SRod Evans if (aplist_append(&cmdline, cmd,
78657ef7aa9SRod Evans AL_CNT_CRLE) == NULL)
787c13de8f6Sab return (INSCFG_RET_FAIL);
7887c478bd9Sstevel@tonic-gate }
7897c478bd9Sstevel@tonic-gate
7907c478bd9Sstevel@tonic-gate if (crle->c_flags & CRLE_UPDATE)
7917c478bd9Sstevel@tonic-gate continue;
7927c478bd9Sstevel@tonic-gate
7937c478bd9Sstevel@tonic-gate /*
7947c478bd9Sstevel@tonic-gate * Although we record both full pathnames and their
7957c478bd9Sstevel@tonic-gate * simple filenames (basename), only print the simple
7967c478bd9Sstevel@tonic-gate * names unless we're under verbose mode.
7977c478bd9Sstevel@tonic-gate */
7987c478bd9Sstevel@tonic-gate if ((strchr(str, '/') == 0) ||
7997c478bd9Sstevel@tonic-gate (crle->c_flags & CRLE_VERBOSE)) {
8007c478bd9Sstevel@tonic-gate if (fobj->co_flags & RTC_OBJ_ALTER)
8017c478bd9Sstevel@tonic-gate (void) printf(MSG_INTL(MSG_DMP_FILE_2),
8027c478bd9Sstevel@tonic-gate str, (strtbl + fobj->co_alter));
8037c478bd9Sstevel@tonic-gate else
8047c478bd9Sstevel@tonic-gate (void) printf(MSG_INTL(MSG_DMP_FILE_1),
8057c478bd9Sstevel@tonic-gate str);
8067c478bd9Sstevel@tonic-gate }
8077c478bd9Sstevel@tonic-gate
8087c478bd9Sstevel@tonic-gate /*
8097c478bd9Sstevel@tonic-gate * Under verbose mode validate any real file entry - the
8107c478bd9Sstevel@tonic-gate * same test will be carried out by ld.so.1.
8117c478bd9Sstevel@tonic-gate */
8127c478bd9Sstevel@tonic-gate if ((crle->c_flags & CRLE_VERBOSE) &&
8137c478bd9Sstevel@tonic-gate (fobj->co_flags & RTC_OBJ_REALPTH)) {
8147c478bd9Sstevel@tonic-gate if (stat(str, &status) != 0) {
8157c478bd9Sstevel@tonic-gate int err = errno;
8167c478bd9Sstevel@tonic-gate (void) printf(MSG_INTL(MSG_DMP_STAT),
8177c478bd9Sstevel@tonic-gate str, strerror(err));
8187c478bd9Sstevel@tonic-gate } else if (status.st_size != fobj->co_info) {
8197c478bd9Sstevel@tonic-gate (void) printf(MSG_INTL(MSG_DMP_FCMP),
8207c478bd9Sstevel@tonic-gate str);
8217c478bd9Sstevel@tonic-gate }
8227c478bd9Sstevel@tonic-gate }
8237c478bd9Sstevel@tonic-gate }
8247c478bd9Sstevel@tonic-gate }
8257c478bd9Sstevel@tonic-gate
826*fec04708SRichard Lowe if (((crle->c_flags & CRLE_UPDATE) == 0) && cmdset)
82757ef7aa9SRod Evans printcmd(crle, head, cmdline);
8287c478bd9Sstevel@tonic-gate
8297c478bd9Sstevel@tonic-gate if ((crle->c_flags & CRLE_VERBOSE) == 0)
830c13de8f6Sab return (INSCFG_RET_OK);
8317c478bd9Sstevel@tonic-gate
8327c478bd9Sstevel@tonic-gate /*
8337c478bd9Sstevel@tonic-gate * If we've in verbose mode scan the hash list.
8347c478bd9Sstevel@tonic-gate */
8357c478bd9Sstevel@tonic-gate /* LINTED */
836c13de8f6Sab hash = (Word *)(CAST_PTRINT(char *, head->ch_hash) + addr);
8377c478bd9Sstevel@tonic-gate bkts = hash[0];
8387c478bd9Sstevel@tonic-gate chain = &hash[2 + bkts];
8397c478bd9Sstevel@tonic-gate hash += 2;
8407c478bd9Sstevel@tonic-gate
8417c478bd9Sstevel@tonic-gate (void) printf(MSG_INTL(MSG_DMP_HASH));
8427c478bd9Sstevel@tonic-gate
8437c478bd9Sstevel@tonic-gate /*
8447c478bd9Sstevel@tonic-gate * Scan the hash buckets looking for valid entries.
8457c478bd9Sstevel@tonic-gate */
8467c478bd9Sstevel@tonic-gate for (ndx = 0; ndx < bkts; ndx++, hash++) {
847de777a60Sab Conv_config_obj_buf_t config_obj_buf;
848de777a60Sab Rtc_obj *obj;
849de777a60Sab const char *str;
850de777a60Sab Word _ndx;
8517c478bd9Sstevel@tonic-gate
852d5fa36a7SToomas Soome if (*hash == 0)
8537c478bd9Sstevel@tonic-gate continue;
8547c478bd9Sstevel@tonic-gate
8557c478bd9Sstevel@tonic-gate obj = objtbl + *hash;
8567c478bd9Sstevel@tonic-gate str = strtbl + obj->co_name;
8577c478bd9Sstevel@tonic-gate
8587c478bd9Sstevel@tonic-gate (void) printf(MSG_INTL(MSG_DMP_HASHENT_1), obj->co_id, ndx,
859de777a60Sab str, conv_config_obj(obj->co_flags, &config_obj_buf));
8607c478bd9Sstevel@tonic-gate
8617c478bd9Sstevel@tonic-gate /*
8627c478bd9Sstevel@tonic-gate * Determine whether there are other objects chained to this
8637c478bd9Sstevel@tonic-gate * bucket.
8647c478bd9Sstevel@tonic-gate */
8657c478bd9Sstevel@tonic-gate for (_ndx = chain[*hash]; _ndx; _ndx = chain[_ndx]) {
8667c478bd9Sstevel@tonic-gate obj = objtbl + _ndx;
8677c478bd9Sstevel@tonic-gate str = strtbl + obj->co_name;
8687c478bd9Sstevel@tonic-gate
8697c478bd9Sstevel@tonic-gate (void) printf(MSG_INTL(MSG_DMP_HASHENT_2), obj->co_id,
870de777a60Sab str, conv_config_obj(obj->co_flags,
871de777a60Sab &config_obj_buf));
8727c478bd9Sstevel@tonic-gate }
8737c478bd9Sstevel@tonic-gate }
8747c478bd9Sstevel@tonic-gate (void) printf(MSG_ORIG(MSG_STR_NL));
8757c478bd9Sstevel@tonic-gate
876c13de8f6Sab return (INSCFG_RET_OK);
8777c478bd9Sstevel@tonic-gate }
8787c478bd9Sstevel@tonic-gate
8797c478bd9Sstevel@tonic-gate
880c13de8f6Sab INSCFG_RET
inspectconfig(Crle_desc * crle,int c_class)881587032cfSab inspectconfig(Crle_desc * crle, int c_class)
8827c478bd9Sstevel@tonic-gate {
883c13de8f6Sab INSCFG_RET error;
884c13de8f6Sab int fd;
8857c478bd9Sstevel@tonic-gate Addr addr;
8867c478bd9Sstevel@tonic-gate struct stat status;
8877c478bd9Sstevel@tonic-gate const char *caller = crle->c_name, *file = crle->c_confil;
888de777a60Sab Conv_inv_buf_t inv_buf1, inv_buf2, inv_buf3;
8897c478bd9Sstevel@tonic-gate
8907c478bd9Sstevel@tonic-gate /*
8917c478bd9Sstevel@tonic-gate * Open the configuration file, determine its size and map it in.
8927c478bd9Sstevel@tonic-gate */
8937c478bd9Sstevel@tonic-gate if ((fd = open(file, O_RDONLY, 0)) == -1) {
8947c478bd9Sstevel@tonic-gate int err = errno;
8957c478bd9Sstevel@tonic-gate
896587032cfSab if (err == ENOENT) {
897587032cfSab #ifndef _ELF64
898587032cfSab /* Must restart if user requested a 64-bit file */
899587032cfSab if (c_class == ELFCLASS64)
900587032cfSab return (INSCFG_RET_NEED64);
901587032cfSab #endif
902587032cfSab
9037c478bd9Sstevel@tonic-gate /*
9047c478bd9Sstevel@tonic-gate * To allow an update (-u) from scratch, fabricate any
9057c478bd9Sstevel@tonic-gate * default search and secure paths that the user
9067c478bd9Sstevel@tonic-gate * intends to add to.
9077c478bd9Sstevel@tonic-gate */
9087c478bd9Sstevel@tonic-gate if (crle->c_flags & CRLE_UPDATE) {
9097c478bd9Sstevel@tonic-gate if (crle->c_flags & CRLE_EDLIB) {
9107c478bd9Sstevel@tonic-gate if (fablib(crle, CRLE_EDLIB))
911587032cfSab return (INSCFG_RET_FAIL);
9127c478bd9Sstevel@tonic-gate }
9137c478bd9Sstevel@tonic-gate if (crle->c_flags & CRLE_ESLIB) {
9147c478bd9Sstevel@tonic-gate if (fablib(crle, CRLE_ESLIB))
915587032cfSab return (INSCFG_RET_FAIL);
9167c478bd9Sstevel@tonic-gate }
917587032cfSab return (INSCFG_RET_OK);
9187c478bd9Sstevel@tonic-gate
9197c478bd9Sstevel@tonic-gate } else if (crle->c_flags & CRLE_CONFDEF) {
9207c478bd9Sstevel@tonic-gate const char *fmt1, *fmt2;
9217c478bd9Sstevel@tonic-gate
9227c478bd9Sstevel@tonic-gate /*
9237c478bd9Sstevel@tonic-gate * Otherwise if the user is inspecting a default
9247c478bd9Sstevel@tonic-gate * configuration file that doesn't exist inform
9257c478bd9Sstevel@tonic-gate * them and display the ELF defaults.
9267c478bd9Sstevel@tonic-gate */
9277c478bd9Sstevel@tonic-gate (void) printf(MSG_INTL(MSG_DEF_NOCONF), file);
928587032cfSab (void) printf(MSG_INTL(MSG_DMP_PLATFORM),
929de777a60Sab conv_ehdr_class(M_CLASS,
930d29b2c44Sab CONV_FMT_ALT_FILE, &inv_buf1),
931de777a60Sab conv_ehdr_data(M_DATA,
932d29b2c44Sab CONV_FMT_ALT_FILE, &inv_buf2),
933de777a60Sab conv_ehdr_mach(M_MACH,
934d29b2c44Sab CONV_FMT_ALT_FILE, &inv_buf3));
935587032cfSab
9367c478bd9Sstevel@tonic-gate
937c13de8f6Sab #if M_CLASS == ELFCLASS64
938*fec04708SRichard Lowe fmt1 = MSG_INTL(MSG_DEF_NEWDLP_64);
939*fec04708SRichard Lowe fmt2 = MSG_INTL(MSG_DEF_NEWTD_64);
9407c478bd9Sstevel@tonic-gate #else
941*fec04708SRichard Lowe fmt1 = MSG_INTL(MSG_DEF_NEWDLP);
942*fec04708SRichard Lowe fmt2 = MSG_INTL(MSG_DEF_NEWTD);
9437c478bd9Sstevel@tonic-gate #endif
9447c478bd9Sstevel@tonic-gate (void) printf(fmt1);
9457c478bd9Sstevel@tonic-gate (void) printf(fmt2);
9467c478bd9Sstevel@tonic-gate
947587032cfSab return (INSCFG_RET_OK);
9487c478bd9Sstevel@tonic-gate }
9497c478bd9Sstevel@tonic-gate }
9507c478bd9Sstevel@tonic-gate
9517c478bd9Sstevel@tonic-gate /*
9527c478bd9Sstevel@tonic-gate * Otherwise there's an error condition in accessing the file.
9537c478bd9Sstevel@tonic-gate */
9547c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_SYS_OPEN), caller, file,
9557c478bd9Sstevel@tonic-gate strerror(err));
9567c478bd9Sstevel@tonic-gate
957587032cfSab return (INSCFG_RET_FAIL);
9587c478bd9Sstevel@tonic-gate }
9597c478bd9Sstevel@tonic-gate
9607c478bd9Sstevel@tonic-gate (void) fstat(fd, &status);
9617c478bd9Sstevel@tonic-gate if (status.st_size < sizeof (Rtc_head)) {
9627c478bd9Sstevel@tonic-gate (void) close(fd);
9637c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_COR_TRUNC), caller, file);
964587032cfSab return (INSCFG_RET_FAIL);
9657c478bd9Sstevel@tonic-gate }
9667c478bd9Sstevel@tonic-gate if ((addr = (Addr)mmap(0, status.st_size, PROT_READ, MAP_SHARED,
9677c478bd9Sstevel@tonic-gate fd, 0)) == (Addr)MAP_FAILED) {
9687c478bd9Sstevel@tonic-gate int err = errno;
9697c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_SYS_MMAP), caller, file,
9707c478bd9Sstevel@tonic-gate strerror(err));
9717c478bd9Sstevel@tonic-gate (void) close(fd);
972587032cfSab return (INSCFG_RET_FAIL);
9737c478bd9Sstevel@tonic-gate }
9747c478bd9Sstevel@tonic-gate (void) close(fd);
9757c478bd9Sstevel@tonic-gate
9767c478bd9Sstevel@tonic-gate /*
9777c478bd9Sstevel@tonic-gate * Print the contents of the configuration file.
9787c478bd9Sstevel@tonic-gate */
979587032cfSab error = scanconfig(crle, addr, c_class);
9807c478bd9Sstevel@tonic-gate
9817c478bd9Sstevel@tonic-gate (void) munmap((void *)addr, status.st_size);
9827c478bd9Sstevel@tonic-gate return (error);
9837c478bd9Sstevel@tonic-gate }
984