11de7b4b8SPedro F. Giffuni /*- 21de7b4b8SPedro F. Giffuni * SPDX-License-Identifier: BSD-4-Clause 31de7b4b8SPedro F. Giffuni * 40f6b2cb3SPaul Traina * Copyright (c) 1993,1995 Paul Kranenburg 5b9ae52e3SPaul Richards * All rights reserved. 6b9ae52e3SPaul Richards * 7b9ae52e3SPaul Richards * Redistribution and use in source and binary forms, with or without 8b9ae52e3SPaul Richards * modification, are permitted provided that the following conditions 9b9ae52e3SPaul Richards * are met: 10b9ae52e3SPaul Richards * 1. Redistributions of source code must retain the above copyright 11b9ae52e3SPaul Richards * notice, this list of conditions and the following disclaimer. 12b9ae52e3SPaul Richards * 2. Redistributions in binary form must reproduce the above copyright 13b9ae52e3SPaul Richards * notice, this list of conditions and the following disclaimer in the 14b9ae52e3SPaul Richards * documentation and/or other materials provided with the distribution. 15b9ae52e3SPaul Richards * 3. All advertising materials mentioning features or use of this software 16b9ae52e3SPaul Richards * must display the following acknowledgement: 17b9ae52e3SPaul Richards * This product includes software developed by Paul Kranenburg. 18b9ae52e3SPaul Richards * 4. The name of the author may not be used to endorse or promote products 1909e3d49dSJordan K. Hubbard * derived from this software without specific prior written permission 20b9ae52e3SPaul Richards * 21b9ae52e3SPaul Richards * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22b9ae52e3SPaul Richards * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23b9ae52e3SPaul Richards * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24b9ae52e3SPaul Richards * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25b9ae52e3SPaul Richards * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26b9ae52e3SPaul Richards * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27b9ae52e3SPaul Richards * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28b9ae52e3SPaul Richards * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29b9ae52e3SPaul Richards * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30b9ae52e3SPaul Richards * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31b9ae52e3SPaul Richards */ 32b9ae52e3SPaul Richards 33b50d7faeSPhilippe Charnier #ifndef lint 34b50d7faeSPhilippe Charnier static const char rcsid[] = 357f3dea24SPeter Wemm "$FreeBSD$"; 36b50d7faeSPhilippe Charnier #endif /* not lint */ 37b50d7faeSPhilippe Charnier 38b9ae52e3SPaul Richards #include <sys/param.h> 39b9ae52e3SPaul Richards #include <sys/types.h> 40b9ae52e3SPaul Richards #include <sys/stat.h> 41b9ae52e3SPaul Richards #include <sys/mman.h> 42b9ae52e3SPaul Richards #include <a.out.h> 43b50d7faeSPhilippe Charnier #include <ctype.h> 44b50d7faeSPhilippe Charnier #include <dirent.h> 455e6220d9SDavid E. O'Brien #include <elf-hints.h> 46b50d7faeSPhilippe Charnier #include <err.h> 47b50d7faeSPhilippe Charnier #include <errno.h> 48b50d7faeSPhilippe Charnier #include <fcntl.h> 49699e1b82SRich Murphey #include <stdio.h> 50699e1b82SRich Murphey #include <stdlib.h> 51b9ae52e3SPaul Richards #include <string.h> 52699e1b82SRich Murphey #include <unistd.h> 53b9ae52e3SPaul Richards 54a565ca59SJohn Polstra #include "ldconfig.h" 5580c71499SPeter Wemm 567c6da7dcSJohn Polstra #if DEBUG 577c6da7dcSJohn Polstra /* test */ 58a565ca59SJohn Polstra #undef _PATH_ELF_HINTS 59a565ca59SJohn Polstra #define _PATH_ELF_HINTS "./ld-elf.so.hints" 607c6da7dcSJohn Polstra #endif 61b9ae52e3SPaul Richards 62c905e45dSPeter Wemm #define _PATH_LD32_HINTS "/var/run/ld32.so.hints" 63c905e45dSPeter Wemm #define _PATH_ELF32_HINTS "/var/run/ld-elf32.so.hints" 644153c211SWarner Losh #define _PATH_ELFSOFT_HINTS "/var/run/ld-elf-soft.so.hints" 65c905e45dSPeter Wemm 66b9ae52e3SPaul Richards #undef major 67b9ae52e3SPaul Richards #undef minor 68b9ae52e3SPaul Richards 69b9ae52e3SPaul Richards static int verbose; 70b9ae52e3SPaul Richards static int nostd; 71b9ae52e3SPaul Richards static int justread; 72f606c848SSatoshi Asami static int merge; 73d4ba5766SPeter Wemm static int rescan; 7406eda379SXin LI static const char *hints_file; 75b9ae52e3SPaul Richards 7685429990SWarner Losh static void usage(void); 77b9ae52e3SPaul Richards 78b9ae52e3SPaul Richards int 7906eda379SXin LI main(int argc, char **argv) 80b9ae52e3SPaul Richards { 81*50a40d09SEd Maste int c; 82c905e45dSPeter Wemm int is_32 = 0; 834153c211SWarner Losh int is_soft = 0; 84b9ae52e3SPaul Richards 85c905e45dSPeter Wemm while (argc > 1) { 86c905e45dSPeter Wemm if (strcmp(argv[1], "-aout") == 0) { 87*50a40d09SEd Maste errx(1, "aout is not supported"); 88c905e45dSPeter Wemm } else if (strcmp(argv[1], "-elf") == 0) { 8966422f5bSPeter Wemm argc--; 9066422f5bSPeter Wemm argv++; 91c905e45dSPeter Wemm } else if (strcmp(argv[1], "-32") == 0) { 92c905e45dSPeter Wemm is_32 = 1; 93c905e45dSPeter Wemm argc--; 94c905e45dSPeter Wemm argv++; 954153c211SWarner Losh } else if (strcmp(argv[1], "-soft") == 0) { 964153c211SWarner Losh is_soft = 1; 974153c211SWarner Losh argc--; 984153c211SWarner Losh argv++; 99c905e45dSPeter Wemm } else { 100c905e45dSPeter Wemm break; 101c905e45dSPeter Wemm } 10266422f5bSPeter Wemm } 103cfa4d739SJohn Polstra 1044153c211SWarner Losh if (is_soft) 1054153c211SWarner Losh hints_file = _PATH_ELFSOFT_HINTS; /* Never will have a.out softfloat */ 1064153c211SWarner Losh else if (is_32) 107*50a40d09SEd Maste hints_file = _PATH_ELF32_HINTS; 108c905e45dSPeter Wemm else 109*50a40d09SEd Maste hints_file = _PATH_ELF_HINTS; 11097333b9eSJohn Polstra if (argc == 1) 11197333b9eSJohn Polstra rescan = 1; 112643dcf40SJohn Polstra else while((c = getopt(argc, argv, "Rf:imrsv")) != -1) { 113b9ae52e3SPaul Richards switch (c) { 114d4ba5766SPeter Wemm case 'R': 115d4ba5766SPeter Wemm rescan = 1; 116d4ba5766SPeter Wemm break; 1177c6da7dcSJohn Polstra case 'f': 1187c6da7dcSJohn Polstra hints_file = optarg; 1197c6da7dcSJohn Polstra break; 120643dcf40SJohn Polstra case 'i': 121643dcf40SJohn Polstra insecure = 1; 122643dcf40SJohn Polstra break; 123f606c848SSatoshi Asami case 'm': 124f606c848SSatoshi Asami merge = 1; 125b9ae52e3SPaul Richards break; 126b9ae52e3SPaul Richards case 'r': 127b9ae52e3SPaul Richards justread = 1; 128b9ae52e3SPaul Richards break; 129f606c848SSatoshi Asami case 's': 130f606c848SSatoshi Asami nostd = 1; 131f606c848SSatoshi Asami break; 132f606c848SSatoshi Asami case 'v': 133f606c848SSatoshi Asami verbose = 1; 134f606c848SSatoshi Asami break; 135b9ae52e3SPaul Richards default: 136b50d7faeSPhilippe Charnier usage(); 137b9ae52e3SPaul Richards break; 138b9ae52e3SPaul Richards } 139b9ae52e3SPaul Richards } 140b9ae52e3SPaul Richards 141a565ca59SJohn Polstra if (justread) 142a565ca59SJohn Polstra list_elf_hints(hints_file); 143a565ca59SJohn Polstra else 144a565ca59SJohn Polstra update_elf_hints(hints_file, argc - optind, 145a565ca59SJohn Polstra argv + optind, merge || rescan); 146a565ca59SJohn Polstra return 0; 147a565ca59SJohn Polstra } 148a565ca59SJohn Polstra 149b50d7faeSPhilippe Charnier static void 150f709df34SEd Schouten usage(void) 151b50d7faeSPhilippe Charnier { 152b50d7faeSPhilippe Charnier fprintf(stderr, 153*50a40d09SEd Maste "usage: ldconfig [-32] [-elf] [-Rimrsv] [-f hints_file] [directory | file ...]\n"); 154b50d7faeSPhilippe Charnier exit(1); 155b50d7faeSPhilippe Charnier } 156