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 33b9ae52e3SPaul Richards #include <sys/param.h> 34b9ae52e3SPaul Richards #include <sys/types.h> 35b9ae52e3SPaul Richards #include <sys/stat.h> 36b9ae52e3SPaul Richards #include <sys/mman.h> 37b9ae52e3SPaul Richards #include <a.out.h> 38b50d7faeSPhilippe Charnier #include <ctype.h> 39b50d7faeSPhilippe Charnier #include <dirent.h> 405e6220d9SDavid E. O'Brien #include <elf-hints.h> 41b50d7faeSPhilippe Charnier #include <err.h> 42b50d7faeSPhilippe Charnier #include <errno.h> 43b50d7faeSPhilippe Charnier #include <fcntl.h> 443f2c6f55SKonstantin Belousov #include <stdbool.h> 45699e1b82SRich Murphey #include <stdio.h> 46699e1b82SRich Murphey #include <stdlib.h> 47b9ae52e3SPaul Richards #include <string.h> 48699e1b82SRich Murphey #include <unistd.h> 49b9ae52e3SPaul Richards 50a565ca59SJohn Polstra #include "ldconfig.h" 51af911587SKonstantin Belousov #include "rtld_paths.h" 5280c71499SPeter Wemm 53*65f3be91SAlfonso Gregory static void usage(void) __dead2; 54b9ae52e3SPaul Richards 55b9ae52e3SPaul Richards int 5606eda379SXin LI main(int argc, char **argv) 57b9ae52e3SPaul Richards { 583f2c6f55SKonstantin Belousov const char *hints_file; 5950a40d09SEd Maste int c; 608b7cc20fSWarner Losh bool is_32, justread, merge, rescan, verbose; 613f2c6f55SKonstantin Belousov 628b7cc20fSWarner Losh is_32 = justread = merge = rescan = verbose = false; 63b9ae52e3SPaul Richards 64c905e45dSPeter Wemm while (argc > 1) { 65c905e45dSPeter Wemm if (strcmp(argv[1], "-aout") == 0) { 6650a40d09SEd Maste errx(1, "aout is not supported"); 67c905e45dSPeter Wemm } else if (strcmp(argv[1], "-elf") == 0) { 6866422f5bSPeter Wemm argc--; 6966422f5bSPeter Wemm argv++; 70c905e45dSPeter Wemm } else if (strcmp(argv[1], "-32") == 0) { 713f2c6f55SKonstantin Belousov is_32 = true; 72c905e45dSPeter Wemm argc--; 73c905e45dSPeter Wemm argv++; 74c905e45dSPeter Wemm } else { 75c905e45dSPeter Wemm break; 76c905e45dSPeter Wemm } 7766422f5bSPeter Wemm } 78cfa4d739SJohn Polstra 798b7cc20fSWarner Losh if (is_32) 8050a40d09SEd Maste hints_file = _PATH_ELF32_HINTS; 81c905e45dSPeter Wemm else 8250a40d09SEd Maste hints_file = _PATH_ELF_HINTS; 833ede04c7SKonstantin Belousov while((c = getopt(argc, argv, "Rf:imrsv")) != -1) { 84b9ae52e3SPaul Richards switch (c) { 85d4ba5766SPeter Wemm case 'R': 863f2c6f55SKonstantin Belousov rescan = true; 87d4ba5766SPeter Wemm break; 887c6da7dcSJohn Polstra case 'f': 897c6da7dcSJohn Polstra hints_file = optarg; 907c6da7dcSJohn Polstra break; 91643dcf40SJohn Polstra case 'i': 923f2c6f55SKonstantin Belousov insecure = true; 93643dcf40SJohn Polstra break; 94f606c848SSatoshi Asami case 'm': 953f2c6f55SKonstantin Belousov merge = true; 96b9ae52e3SPaul Richards break; 97b9ae52e3SPaul Richards case 'r': 983f2c6f55SKonstantin Belousov justread = true; 99b9ae52e3SPaul Richards break; 100f606c848SSatoshi Asami case 's': 101b828161dSKonstantin Belousov /* was nostd */ 102f606c848SSatoshi Asami break; 103f606c848SSatoshi Asami case 'v': 1043f2c6f55SKonstantin Belousov verbose = true; 105f606c848SSatoshi Asami break; 106b9ae52e3SPaul Richards default: 107b50d7faeSPhilippe Charnier usage(); 108b9ae52e3SPaul Richards break; 109b9ae52e3SPaul Richards } 110b9ae52e3SPaul Richards } 111b9ae52e3SPaul Richards 1123ede04c7SKonstantin Belousov if (justread) { 113a565ca59SJohn Polstra list_elf_hints(hints_file); 1143ede04c7SKonstantin Belousov } else { 1153ede04c7SKonstantin Belousov if (argc == optind) 1163ede04c7SKonstantin Belousov rescan = true; 117a565ca59SJohn Polstra update_elf_hints(hints_file, argc - optind, 118a565ca59SJohn Polstra argv + optind, merge || rescan); 1193ede04c7SKonstantin Belousov } 1203f2c6f55SKonstantin Belousov exit(0); 121a565ca59SJohn Polstra } 122a565ca59SJohn Polstra 123b50d7faeSPhilippe Charnier static void 124f709df34SEd Schouten usage(void) 125b50d7faeSPhilippe Charnier { 126b50d7faeSPhilippe Charnier fprintf(stderr, 127b828161dSKonstantin Belousov "usage: ldconfig [-32] [-elf] [-Rimrv] [-f hints_file] " 1283f2c6f55SKonstantin Belousov "[directory | file ...]\n"); 129b50d7faeSPhilippe Charnier exit(1); 130b50d7faeSPhilippe Charnier } 131