1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <limits.h>
#include "sgs.h"
#include "rtc.h"
#include "conv.h"
#include "_crle.h"
#include "msg.h"
/*
* Display the command line required to regenerate the configuration file.
*
* Under normal mode the command is printed on one line to make it more
* available for grep(1) use. Under verbose mode the command is separated
* into each argument (a little more readable perhaps when the arguments are
* numerous of have long pathnames).
*
* Note that for version 1 configuration files we never used to generate any
* command-line information, and as the attempt to do so is only a best effort
* don't bother printing anything.
*/
static void
printcmd(Crle_desc *crle, Rtc_head * head, APlist *cmdline)
{
Aliste idx, lidx;
const char *fmto, *fmtb, *fmtm, *fmte;
char *cmd;
int output = 0;
if (crle->c_flags & CRLE_VERBOSE) {
fmto = MSG_INTL(MSG_DMP_CMD_ONE_V);
fmtb = MSG_INTL(MSG_DMP_CMD_BGN_V);
fmtm = MSG_INTL(MSG_DMP_CMD_MID_V);
fmte = MSG_INTL(MSG_DMP_CMD_END_V);
} else if (head->ch_version > RTC_VER_ONE) {
fmto = MSG_INTL(MSG_DMP_CMD_ONE);
fmtb = MSG_INTL(MSG_DMP_CMD_BGN);
fmtm = MSG_INTL(MSG_DMP_CMD_MID);
fmte = MSG_INTL(MSG_DMP_CMD_END);
} else {
(void) printf(MSG_ORIG(MSG_STR_NL));
return;
}
(void) printf(MSG_INTL(MSG_DMP_CMD_TITLE));
lidx = aplist_nitems(cmdline) - 1;
for (APLIST_TRAVERSE(cmdline, idx, cmd)) {
if (output++ == 0) {
if (idx < lidx)
(void) printf(fmtb, cmd);
else
(void) printf(fmto, cmd);
} else {
if (idx < lidx)
(void) printf(fmtm, cmd);
else
(void) printf(fmte, cmd);
}
}
}
/*
* Establish the argument required to generate the associated object.
*/
static const char *
getformat(Half flags)
{
if (flags & RTC_OBJ_ALTER) {
if (flags & RTC_OBJ_DUMP) {
if (flags & RTC_OBJ_GROUP)
return (MSG_ORIG(MSG_CMD_DUMPGRP));
else
return (MSG_ORIG(MSG_CMD_DUMPIND));
} else {
if (flags & RTC_OBJ_OPTINAL)
return (MSG_ORIG(MSG_CMD_OPTIONAL));
else
return (MSG_ORIG(MSG_CMD_ALTER));
}
} else {
if (flags & RTC_OBJ_GROUP)
return (MSG_ORIG(MSG_CMD_GRP));
else
return (MSG_ORIG(MSG_CMD_IND));
}
}
/*
* Fabricate a system default search path. If an update is requested, and
* new search paths are specified while no configuration file exists, or if a
* configuration file does exist but doesn't specify this particular search
* path, create any system defaults. The intent is to allow
* "crle -u -l/usr/local/lib" and have this append the search path to the
* system default, rather than have the user have to determine and specify
* this default themselves.
*/
static int
fablib(Crle_desc * crle, int flag)
{
const char *path;
char **list;
switch (flag) {
case CRLE_EDLIB:
#if M_CLASS == ELFCLASS64
path = MSG_ORIG(MSG_PTH_NEWDLP_64);
#else
path = MSG_ORIG(MSG_PTH_NEWDLP);
#endif
list = &crle->c_edlibpath;
break;
case CRLE_ESLIB:
#if M_CLASS == ELFCLASS64
path = MSG_ORIG(MSG_PTH_NEWTD_64);
#else
path = MSG_ORIG(MSG_PTH_NEWTD);
#endif
list = &crle->c_eslibpath;
break;
default:
return (1);
}
return (addlib(crle, list, path));
}
/*
* Establish the flags required to generate the associated object. Actually
* the flags are already part of the object being inspected from the present
* configuration file, but instead of using them all, which can cause some
* unsuspected propagation down the inspect() family, only use those flags that
* would have been contributed from crle()'s calls to inspect.
*/
static Half
getflags(Half flags)
{
flags &=
(RTC_OBJ_ALTER | RTC_OBJ_DUMP | RTC_OBJ_GROUP | RTC_OBJ_OPTINAL);
return (flags | RTC_OBJ_CMDLINE);
}
/*
* Dump a configuration files information. This routine is very close to the
* scanconfig() in libcrle.
*/
/*ARGSUSED2*/
static INSCFG_RET
scanconfig(Crle_desc * crle, Addr addr, int c_class)
{
Conv_inv_buf_t inv_buf1, inv_buf2, inv_buf3, inv_buf4;
Conv_dl_flag_buf_t dl_flag_buf;
Rtc_id *id;
Rtc_head *head;
Rtc_dir *dirtbl;
Rtc_file *filetbl;
Rtc_obj *objtbl, *obj;
Word *hash, *chain;
const char *strtbl;
int ndx, bkts;
APlist *cmdline = NULL;
boolean_t cmdset = B_FALSE;
char _cmd[PATH_MAX], *cmd;
char _objdir[PATH_MAX], *objdir = NULL;
/*
* If there is an Rtc_id present, the Rtc_head follows it.
* Otherwise, it is at the top.
*/
if (RTC_ID_TEST(addr)) {
id = (Rtc_id *) addr;
addr += sizeof (*id); /* Rtc_head follows */
} else {
id = NULL;
/*
* When updating an existing config file that is lacking
* the Rtc_id block, don't put one into the resulting file.
*/
crle->c_flags &= ~CRLE_ADDID;
}
head = (Rtc_head *) addr;
/*
* The rest of the configuration file can only be examined by
* a program of the same ELFCLASS, byte order, and hardware
* architecture as the one that created it.
*/
#ifdef _ELF64
/* 64-bit program with an existing 32-bit file? Abort. */
if (!(head->ch_cnflags & RTC_HDR_64)) {
(void) fprintf(stderr, MSG_INTL(MSG_ARG_CLASS),
crle->c_name, crle->c_confil);
return (INSCFG_RET_FAIL);
}
#else
/* 32-bit program with an existing 64-bit file? Restart. */
if (head->ch_cnflags & RTC_HDR_64)
return (INSCFG_RET_NEED64);
/*
* 32-bit program with an existing 32-bit file, but the
* user specified the -64 option? Abort
*/
if (c_class != ELFCLASS32) {
(void) fprintf(stderr, MSG_INTL(MSG_ARG_CLASS),
crle->c_name, crle->c_confil);
return (INSCFG_RET_FAIL);
}
#endif
/*
* Now that the ELFCLASS has been settled, ensure that the
* byte order and hardware match. Unlike ELFCLASS, where restarting
* the other version is an option, we cannot work around a mismatch
* of these attributes.
*/
if (id) { /* Rtc_id is present */
/*
* Was the file produced by compatible hardware?
* ELFCLASS doesn't matter here, because we can
* adjust for that, but byte order and machine type do.
*/
if ((id->id_data != M_DATA) || (id->id_machine != M_MACH)) {
(void) fprintf(stderr, MSG_INTL(MSG_ARG_WRONGARCH),
crle->c_name, crle->c_confil,
conv_ehdr_data(id->id_data, CONV_FMT_ALT_FILE,
&inv_buf1),
conv_ehdr_mach(id->id_machine, CONV_FMT_ALT_FILE,
&inv_buf2),
conv_ehdr_data(M_DATA, CONV_FMT_ALT_FILE,
&inv_buf3),
conv_ehdr_mach(M_MACH, CONV_FMT_ALT_FILE,
&inv_buf4));
return (INSCFG_RET_FAIL);
}
}
/* LINTED */
objtbl = (Rtc_obj *)(CAST_PTRINT(char *, head->ch_obj) + addr);
strtbl = (const char *)(CAST_PTRINT(char *, head->ch_str) + addr);
/*
* If the configuration file has a version higher than we
* recognise, we face two issues:
* (1) Updates are not possible because we have no
* way to recognise or propagate the new features.
* This has to be a fatal error.
* (2) Printing has the risk that we may have been
* handed something other than a real config file, as
* well as the fact that we can't display the information
* for the new features. So, we print a warning, but
* continue on to do the best we can with it.
*/
if (head->ch_version > RTC_VER_CURRENT) {
if (crle->c_flags & CRLE_UPDATE) {
(void) fprintf(stderr, MSG_INTL(MSG_ARG_UPDATEVER),
crle->c_name, crle->c_confil,
(int)head->ch_version, RTC_VER_CURRENT);
return (INSCFG_RET_FAIL);
} else {
(void) fprintf(stderr, MSG_INTL(MSG_ARG_PRINTVER),
crle->c_name, crle->c_confil,
(int)head->ch_version, RTC_VER_CURRENT);
}
}
/*
* If this is a version 1 configuration file we can't generate accurate
* update information, or the command-line used to create the file.
*/
if (head->ch_version == RTC_VER_ONE) {
(void) printf(MSG_INTL(MSG_ARG_UPDATE), crle->c_name,
crle->c_confil, (int)head->ch_version);
}
if (!(crle->c_flags & CRLE_UPDATE) && (head->ch_cnflags & RTC_HDR_64)) {
/*
* Construct the original command line argument.
*/
cmd = strdupa(MSG_ORIG(MSG_CMD_64));
if (aplist_append(&cmdline, cmd, AL_CNT_CRLE) == NULL)
return (INSCFG_RET_FAIL);
}
/*
* Start analyzing the configuration files header information.
*/
if ((crle->c_flags & CRLE_UPDATE) == 0) {
const char *fmt;
if (head->ch_dlflags)
fmt = conv_dl_flag(head->ch_dlflags, 0, &dl_flag_buf);
else
fmt = MSG_ORIG(MSG_STR_EMPTY);
(void) printf(MSG_INTL(MSG_DMP_HEAD), (int)head->ch_version,
crle->c_confil, fmt);
/*
* If the file has an id block, show the information
*/
if (id)
(void) printf(MSG_INTL(MSG_DMP_PLATFORM),
conv_ehdr_class(id->id_class, CONV_FMT_ALT_FILE,
&inv_buf1),
conv_ehdr_data(id->id_data, CONV_FMT_ALT_FILE,
&inv_buf2),
conv_ehdr_mach(id->id_machine, CONV_FMT_ALT_FILE,
&inv_buf3));
/*
* Construct the original command line argument.
*/
(void) snprintf(_cmd, PATH_MAX, MSG_ORIG(MSG_CMD_CONF),
crle->c_confil);
cmd = strdupa(_cmd);
if (aplist_append(&cmdline, cmd, AL_CNT_CRLE) == NULL)
return (INSCFG_RET_FAIL);
/*
* Construct any -f usage.
*/
if (head->ch_dlflags &&
(head->ch_dlflags != RTLD_REL_RELATIVE)) {
(void) snprintf(_cmd, PATH_MAX, MSG_ORIG(MSG_CMD_FLAGS),
conv_dl_flag(head->ch_dlflags, CONV_FMT_ALT_CRLE,
&dl_flag_buf));
cmd = strdupa(_cmd);
cmdset = B_TRUE;
if (aplist_append(&cmdline, cmd, AL_CNT_CRLE) == NULL)
return (INSCFG_RET_FAIL);
}
} else {
/*
* Establish any -f usage.
*/
if (head->ch_dlflags &&
(head->ch_dlflags != RTLD_REL_RELATIVE))
crle->c_dlflags = head->ch_dlflags;
}
/*
* Determine if this configuration file is only applicable to a specific
* application.
*/
if (head->ch_app) {
char *alter;
obj = (Rtc_obj *)(head->ch_app + addr);
/*
* Determine the output directory for the files
* alternative name.
*/
alter = (char *)(strtbl + obj->co_alter);
(void) strcpy(_objdir, alter);
alter = strrchr(_objdir, '/');
*alter = '\0';
crle->c_objdir = objdir = _objdir;
if (crle->c_flags & CRLE_UPDATE) {
if (inspect(crle, (strtbl + obj->co_name),
(RTC_OBJ_DUMP | RTC_OBJ_ALTER |
RTC_OBJ_GROUP | RTC_OBJ_CMDLINE)) != 0)
return (INSCFG_RET_FAIL);
} else {
(void) printf(MSG_INTL(MSG_DMP_APP),
(strtbl + obj->co_alter), (strtbl + obj->co_name));
/*
* Construct the original command line arguments.
*/
cmdset = B_TRUE;
(void) snprintf(_cmd, PATH_MAX,
MSG_ORIG(MSG_CMD_OUTPUT), crle->c_objdir);
cmd = strdupa(_cmd);
if (aplist_append(&cmdline, cmd, AL_CNT_CRLE) == NULL)
return (INSCFG_RET_FAIL);
(void) snprintf(_cmd, PATH_MAX,
MSG_ORIG(MSG_CMD_DUMPGRP), (strtbl + obj->co_name));
cmd = strdupa(_cmd);
if (aplist_append(&cmdline, cmd, AL_CNT_CRLE) == NULL)
return (INSCFG_RET_FAIL);
}
}
/*
* Analyze any alternative library path and trusted directory entries.
*/
if (head->ch_edlibpath) {
const char *str;
str = (const char *)(head->ch_edlibpath + addr);
if (crle->c_flags & CRLE_UPDATE) {
if ((head->ch_cnflags & RTC_HDR_UPM) == 0) {
if (head->ch_cnflags & RTC_HDR_64)
str = conv_config_upm(str,
MSG_ORIG(MSG_PTH_OLDDLP_64),
MSG_ORIG(MSG_PTH_UPDLP_64),
MSG_PTH_UPDLP_64_SIZE);
else
str = conv_config_upm(str,
MSG_ORIG(MSG_PTH_OLDDLP),
MSG_ORIG(MSG_PTH_UPDLP),
MSG_PTH_UPDLP_SIZE);
}
if (addlib(crle, &crle->c_edlibpath, str) != 0)
return (INSCFG_RET_FAIL);
} else {
(void) printf(MSG_INTL(MSG_DMP_DLIBPTH),
MSG_ORIG(MSG_STR_ELF), str);
(void) snprintf(_cmd, PATH_MAX,
MSG_ORIG(MSG_CMD_EDLIB), str);
cmd = strdupa(_cmd);
cmdset = B_TRUE;
if (aplist_append(&cmdline, cmd, AL_CNT_CRLE) == NULL)
return (INSCFG_RET_FAIL);
}
} else {
if (crle->c_flags & CRLE_UPDATE) {
if (crle->c_flags & CRLE_EDLIB) {
/*
* If we've been asked to update a configuration
* file, and no existing default ELF search
* path exists, but the user is going to add new
* entries, fabricate the system defaults so
* that the users get added to them.
*/
if (fablib(crle, CRLE_EDLIB) != 0)
return (INSCFG_RET_FAIL);
}
} else {
/*
* Indicate any system default.
*/
#if M_CLASS == ELFCLASS64
(void) printf(MSG_INTL(MSG_DEF_NEWDLP_64));
#else
(void) printf(MSG_INTL(MSG_DEF_NEWDLP));
#endif
}
}
if (head->ch_eslibpath) {
const char *str;
str = (const char *)(head->ch_eslibpath + addr);
if (crle->c_flags & CRLE_UPDATE) {
if ((head->ch_cnflags & RTC_HDR_UPM) == 0) {
if (head->ch_cnflags & RTC_HDR_64)
str = conv_config_upm(str,
MSG_ORIG(MSG_PTH_OLDTD_64),
MSG_ORIG(MSG_PTH_UPTD_64),
MSG_PTH_UPTD_64_SIZE);
else
str = conv_config_upm(str,
MSG_ORIG(MSG_PTH_OLDTD),
MSG_ORIG(MSG_PTH_UPTD),
MSG_PTH_UPTD_SIZE);
}
if (addlib(crle, &crle->c_eslibpath, str) != 0)
return (INSCFG_RET_FAIL);
} else {
(void) printf(MSG_INTL(MSG_DMP_TLIBPTH),
MSG_ORIG(MSG_STR_ELF), str);
(void) snprintf(_cmd, PATH_MAX,
MSG_ORIG(MSG_CMD_ESLIB), str);
cmd = strdupa(_cmd);
cmdset = B_TRUE;
if (aplist_append(&cmdline, cmd, AL_CNT_CRLE) == NULL)
return (INSCFG_RET_FAIL);
}
} else {
if (crle->c_flags & CRLE_UPDATE) {
if (crle->c_flags & CRLE_ESLIB) {
/*
* If we've been asked to update a configuration
* file, and no existing default ELF secure
* path exists, but the user is going to add new
* entries, fabricate the system defaults so
* that the users get added to them.
*/
if (fablib(crle, CRLE_ESLIB) != 0)
return (INSCFG_RET_FAIL);
}
} else {
/*
* Indicate any system default.
*/
#if M_CLASS == ELFCLASS64
(void) printf(MSG_INTL(MSG_DEF_NEWTD_64));
#else
(void) printf(MSG_INTL(MSG_DEF_NEWTD));
#endif
}
}
/*
* Display any environment variables.
*/
if ((head->ch_version >= RTC_VER_THREE) && head->ch_env) {
Rtc_env *envtbl;
if ((crle->c_flags & CRLE_UPDATE) == 0)
(void) printf(MSG_INTL(MSG_ENV_TITLE));
for (envtbl = (Rtc_env *)(head->ch_env + addr);
envtbl->env_str; envtbl++) {
const char *str;
str = (const char *)(envtbl->env_str + addr);
if (crle->c_flags & CRLE_UPDATE) {
if (addenv(crle, str,
(envtbl->env_flags | RTC_ENV_CONFIG)) == 0)
return (INSCFG_RET_FAIL);
} else {
const char *pfmt, *sfmt;
if (envtbl->env_flags & RTC_ENV_PERMANT) {
pfmt = MSG_INTL(MSG_ENV_PRM);
sfmt = MSG_ORIG(MSG_CMD_PRMENV);
} else {
pfmt = MSG_INTL(MSG_ENV_RPL);
sfmt = MSG_ORIG(MSG_CMD_RPLENV);
}
(void) printf(pfmt, str);
(void) snprintf(_cmd, PATH_MAX, sfmt, str);
cmd = strdupa(_cmd);
cmdset = B_TRUE;
if (aplist_append(&cmdline, cmd,
AL_CNT_CRLE) == NULL)
return (INSCFG_RET_FAIL);
}
}
}
/*
* Display any filter/filtee associations.
*/
if ((head->ch_version >= RTC_VER_FOUR) && head->ch_fltr) {
if ((crle->c_flags & CRLE_UPDATE) == 0) {
Rtc_fltr *fltrtbl;
Rtc_flte *fltetbl;
/* LINTED */
fltrtbl = (Rtc_fltr *)
(CAST_PTRINT(char *, head->ch_fltr) + addr);
/* LINTED */
fltetbl = (Rtc_flte *)
(CAST_PTRINT(char *, head->ch_flte) + addr);
(void) printf(MSG_INTL(MSG_FLT_TITLE));
while (fltrtbl->fr_filter) {
Rtc_flte *_fltetbl;
/*
* Print the filter and filtee string pair.
*/
(void) printf(MSG_INTL(MSG_FLT_FILTER),
(strtbl + fltrtbl->fr_filter),
(strtbl + fltrtbl->fr_string));
/*
* Print each filtee.
*/
/* LINTED */
for (_fltetbl = (Rtc_flte *)((char *)fltetbl +
fltrtbl->fr_filtee); _fltetbl->fe_filtee;
_fltetbl++) {
(void) printf(MSG_INTL(MSG_FLT_FILTEE),
(strtbl + _fltetbl->fe_filtee));
}
fltrtbl++;
}
}
}
/*
* Display any memory reservations required for any alternative
* objects.
*/
if (head->ch_resbgn && ((crle->c_flags & CRLE_UPDATE) == 0))
(void) printf(MSG_INTL(MSG_DMP_RESV),
(u_longlong_t)head->ch_resbgn,
(u_longlong_t)head->ch_resend,
(u_longlong_t)(head->ch_resend - head->ch_resbgn));
/*
* If there's no hash table there's nothing else to process.
*/
if (head->ch_hash == 0) {
if (((crle->c_flags & CRLE_UPDATE) == 0) && cmdset)
printcmd(crle, head, cmdline);
return (INSCFG_RET_OK);
}
/*
* Traverse the directory and filename arrays.
*/
for (dirtbl = (Rtc_dir *)(head->ch_dir + addr);
dirtbl->cd_obj; dirtbl++) {
struct stat status;
Rtc_obj *dobj;
const char *str;
dobj = (Rtc_obj *)(dirtbl->cd_obj + addr);
filetbl = (Rtc_file *)(dirtbl->cd_file + addr);
str = strtbl + dobj->co_name;
/*
* Simplify recreation by using any command-line directories.
* If we're dealing with a version 1 configuration file use
* every directory.
*/
if ((dobj->co_flags & RTC_OBJ_CMDLINE) ||
(head->ch_version == RTC_VER_ONE)) {
if (crle->c_flags & CRLE_UPDATE) {
if (inspect(crle, str,
getflags(dobj->co_flags)) != 0)
return (INSCFG_RET_FAIL);
if ((dobj->co_flags &
(RTC_OBJ_NOEXIST | RTC_OBJ_ALTER)) ==
RTC_OBJ_NOEXIST)
continue;
} else {
/* LINTED */
(void) snprintf(_cmd, PATH_MAX,
getformat(dobj->co_flags), str);
cmd = strdupa(_cmd);
cmdset = B_TRUE;
if (aplist_append(&cmdline, cmd,
AL_CNT_CRLE) == NULL)
return (INSCFG_RET_FAIL);
}
}
/*
* If this isn't an update print the directory name. If the
* directory has no entries (possible if the directory is a
* symlink to another directory, in which case we record the
* real path also), don't bother printing it unless we're in
* verbose mode.
*/
if ((crle->c_flags & CRLE_UPDATE) == 0) {
if ((dobj->co_flags &
(RTC_OBJ_NOEXIST | RTC_OBJ_ALTER)) ==
RTC_OBJ_NOEXIST) {
(void) printf(MSG_INTL(MSG_DMP_DIR_2), str);
continue;
} else if (filetbl->cf_obj ||
(crle->c_flags & CRLE_VERBOSE))
(void) printf(MSG_INTL(MSG_DMP_DIR_1), str);
}
/*
* Under verbose mode validate any real directory entry - the
* same test will be carried out by ld.so.1.
*/
if (((crle->c_flags & CRLE_UPDATE) == 0) &&
(crle->c_flags & CRLE_VERBOSE) &&
(dobj->co_flags & RTC_OBJ_REALPTH)) {
if (stat(str, &status) != 0) {
int err = errno;
(void) printf(MSG_INTL(MSG_DMP_STAT), str,
strerror(err));
} else if (status.st_mtime != dobj->co_info) {
(void) printf(MSG_INTL(MSG_DMP_DCMP), str);
}
}
for (; filetbl->cf_obj; filetbl++) {
Rtc_obj *fobj;
Half flags;
fobj = (Rtc_obj *)(filetbl->cf_obj + addr);
str = strtbl + fobj->co_name;
flags = fobj->co_flags;
/*
* Only update individual files that were originally
* specified on the command-line. Or, if this is a
* version 1 configuration file use every file that
* isn't part of an all-entries directory.
*/
if (((flags & RTC_OBJ_CMDLINE) &&
((fobj->co_flags & RTC_OBJ_APP) == 0)) ||
((head->ch_version == RTC_VER_ONE) &&
((dobj->co_flags & RTC_OBJ_ALLENTS) == 0))) {
char *alter = NULL, altdir[PATH_MAX];
/*
* Determine whether this file requires an
* alternative, and if so, and we haven't
* already an alternative in affect, create one.
*/
if (fobj->co_flags & RTC_OBJ_ALTER) {
alter = (char *)(strtbl +
fobj->co_alter);
(void) strcpy(altdir, alter);
alter = strrchr(altdir, '/');
*alter = '\0';
if ((objdir == NULL) ||
(strcmp(objdir, altdir) != 0)) {
(void) strcpy(_objdir, altdir);
crle->c_objdir = alter =
objdir = _objdir;
} else
alter = NULL;
}
if (crle->c_flags & CRLE_UPDATE) {
if (inspect(crle, str,
getflags(flags)) != 0)
return (INSCFG_RET_FAIL);
continue;
}
if (alter) {
(void) snprintf(_cmd, PATH_MAX,
MSG_ORIG(MSG_CMD_OUTPUT),
crle->c_objdir);
cmd = strdupa(_cmd);
cmdset = B_TRUE;
if (aplist_append(&cmdline, cmd,
AL_CNT_CRLE) == NULL)
return (INSCFG_RET_FAIL);
}
/* LINTED */
(void) snprintf(_cmd, PATH_MAX,
getformat(flags), str);
cmd = strdupa(_cmd);
cmdset = B_TRUE;
if (aplist_append(&cmdline, cmd,
AL_CNT_CRLE) == NULL)
return (INSCFG_RET_FAIL);
}
if (crle->c_flags & CRLE_UPDATE)
continue;
/*
* Although we record both full pathnames and their
* simple filenames (basename), only print the simple
* names unless we're under verbose mode.
*/
if ((strchr(str, '/') == 0) ||
(crle->c_flags & CRLE_VERBOSE)) {
if (fobj->co_flags & RTC_OBJ_ALTER)
(void) printf(MSG_INTL(MSG_DMP_FILE_2),
str, (strtbl + fobj->co_alter));
else
(void) printf(MSG_INTL(MSG_DMP_FILE_1),
str);
}
/*
* Under verbose mode validate any real file entry - the
* same test will be carried out by ld.so.1.
*/
if ((crle->c_flags & CRLE_VERBOSE) &&
(fobj->co_flags & RTC_OBJ_REALPTH)) {
if (stat(str, &status) != 0) {
int err = errno;
(void) printf(MSG_INTL(MSG_DMP_STAT),
str, strerror(err));
} else if (status.st_size != fobj->co_info) {
(void) printf(MSG_INTL(MSG_DMP_FCMP),
str);
}
}
}
}
if (((crle->c_flags & CRLE_UPDATE) == 0) && cmdset)
printcmd(crle, head, cmdline);
if ((crle->c_flags & CRLE_VERBOSE) == 0)
return (INSCFG_RET_OK);
/*
* If we've in verbose mode scan the hash list.
*/
/* LINTED */
hash = (Word *)(CAST_PTRINT(char *, head->ch_hash) + addr);
bkts = hash[0];
chain = &hash[2 + bkts];
hash += 2;
(void) printf(MSG_INTL(MSG_DMP_HASH));
/*
* Scan the hash buckets looking for valid entries.
*/
for (ndx = 0; ndx < bkts; ndx++, hash++) {
Conv_config_obj_buf_t config_obj_buf;
Rtc_obj *obj;
const char *str;
Word _ndx;
if (*hash == 0)
continue;
obj = objtbl + *hash;
str = strtbl + obj->co_name;
(void) printf(MSG_INTL(MSG_DMP_HASHENT_1), obj->co_id, ndx,
str, conv_config_obj(obj->co_flags, &config_obj_buf));
/*
* Determine whether there are other objects chained to this
* bucket.
*/
for (_ndx = chain[*hash]; _ndx; _ndx = chain[_ndx]) {
obj = objtbl + _ndx;
str = strtbl + obj->co_name;
(void) printf(MSG_INTL(MSG_DMP_HASHENT_2), obj->co_id,
str, conv_config_obj(obj->co_flags,
&config_obj_buf));
}
}
(void) printf(MSG_ORIG(MSG_STR_NL));
return (INSCFG_RET_OK);
}
INSCFG_RET
inspectconfig(Crle_desc * crle, int c_class)
{
INSCFG_RET error;
int fd;
Addr addr;
struct stat status;
const char *caller = crle->c_name, *file = crle->c_confil;
Conv_inv_buf_t inv_buf1, inv_buf2, inv_buf3;
/*
* Open the configuration file, determine its size and map it in.
*/
if ((fd = open(file, O_RDONLY, 0)) == -1) {
int err = errno;
if (err == ENOENT) {
#ifndef _ELF64
/* Must restart if user requested a 64-bit file */
if (c_class == ELFCLASS64)
return (INSCFG_RET_NEED64);
#endif
/*
* To allow an update (-u) from scratch, fabricate any
* default search and secure paths that the user
* intends to add to.
*/
if (crle->c_flags & CRLE_UPDATE) {
if (crle->c_flags & CRLE_EDLIB) {
if (fablib(crle, CRLE_EDLIB))
return (INSCFG_RET_FAIL);
}
if (crle->c_flags & CRLE_ESLIB) {
if (fablib(crle, CRLE_ESLIB))
return (INSCFG_RET_FAIL);
}
return (INSCFG_RET_OK);
} else if (crle->c_flags & CRLE_CONFDEF) {
const char *fmt1, *fmt2;
/*
* Otherwise if the user is inspecting a default
* configuration file that doesn't exist inform
* them and display the ELF defaults.
*/
(void) printf(MSG_INTL(MSG_DEF_NOCONF), file);
(void) printf(MSG_INTL(MSG_DMP_PLATFORM),
conv_ehdr_class(M_CLASS,
CONV_FMT_ALT_FILE, &inv_buf1),
conv_ehdr_data(M_DATA,
CONV_FMT_ALT_FILE, &inv_buf2),
conv_ehdr_mach(M_MACH,
CONV_FMT_ALT_FILE, &inv_buf3));
#if M_CLASS == ELFCLASS64
fmt1 = MSG_INTL(MSG_DEF_NEWDLP_64);
fmt2 = MSG_INTL(MSG_DEF_NEWTD_64);
#else
fmt1 = MSG_INTL(MSG_DEF_NEWDLP);
fmt2 = MSG_INTL(MSG_DEF_NEWTD);
#endif
(void) printf(fmt1);
(void) printf(fmt2);
return (INSCFG_RET_OK);
}
}
/*
* Otherwise there's an error condition in accessing the file.
*/
(void) fprintf(stderr, MSG_INTL(MSG_SYS_OPEN), caller, file,
strerror(err));
return (INSCFG_RET_FAIL);
}
(void) fstat(fd, &status);
if (status.st_size < sizeof (Rtc_head)) {
(void) close(fd);
(void) fprintf(stderr, MSG_INTL(MSG_COR_TRUNC), caller, file);
return (INSCFG_RET_FAIL);
}
if ((addr = (Addr)mmap(0, status.st_size, PROT_READ, MAP_SHARED,
fd, 0)) == (Addr)MAP_FAILED) {
int err = errno;
(void) fprintf(stderr, MSG_INTL(MSG_SYS_MMAP), caller, file,
strerror(err));
(void) close(fd);
return (INSCFG_RET_FAIL);
}
(void) close(fd);
/*
* Print the contents of the configuration file.
*/
error = scanconfig(crle, addr, c_class);
(void) munmap((void *)addr, status.st_size);
return (error);
}
|