summaryrefslogtreecommitdiff
path: root/libexec/ld.so
diff options
context:
space:
mode:
authorBrad Smith <brad@cvs.openbsd.org>2001-01-30 02:39:07 +0000
committerBrad Smith <brad@cvs.openbsd.org>2001-01-30 02:39:07 +0000
commitfb686cd5e32d59dfe386d830700e1f052cc312a8 (patch)
tree8c68bb2a50e6e56bd6fde68c608c8a79b18cada8 /libexec/ld.so
parente9ce1705de316c29218c00f11739ff5a746b30f7 (diff)
sync with a.out ldconfig, adds missing -U option. Reviewed by: drahn@
Diffstat (limited to 'libexec/ld.so')
-rw-r--r--libexec/ld.so/ldconfig/etc.c17
-rw-r--r--libexec/ld.so/ldconfig/ld.h16
-rw-r--r--libexec/ld.so/ldconfig/ldconfig.868
-rw-r--r--libexec/ld.so/ldconfig/ldconfig.c111
-rw-r--r--libexec/ld.so/ldconfig/shlib.c39
5 files changed, 154 insertions, 97 deletions
diff --git a/libexec/ld.so/ldconfig/etc.c b/libexec/ld.so/ldconfig/etc.c
index 4a14c0c6e43..863c7a29099 100644
--- a/libexec/ld.so/ldconfig/etc.c
+++ b/libexec/ld.so/ldconfig/etc.c
@@ -1,4 +1,4 @@
-/* * $OpenBSD: etc.c,v 1.1 2000/06/13 03:40:14 rahnds Exp $*/
+/* * $OpenBSD: etc.c,v 1.2 2001/01/30 02:39:04 brad Exp $*/
/*
*/
@@ -7,6 +7,21 @@
#include <string.h>
/*
+ * Like strdup but get fatal error if memory is exhausted.
+ */
+char *
+xstrdup(s)
+ char*s;
+{
+ char *result = strdup(s);
+
+ if (!result)
+ errx(1, "virtual memory exhausted");
+
+ return result;
+}
+
+/*
* Like malloc but get fatal error if memory is exhausted.
*/
void *
diff --git a/libexec/ld.so/ldconfig/ld.h b/libexec/ld.so/ldconfig/ld.h
index 6f62e0ab568..cb00ad572fa 100644
--- a/libexec/ld.so/ldconfig/ld.h
+++ b/libexec/ld.so/ldconfig/ld.h
@@ -1,11 +1,15 @@
-/* $OpenBSD: ld.h,v 1.2 2000/07/08 19:51:46 rahnds Exp $ */
+/* $OpenBSD: ld.h,v 1.3 2001/01/30 02:39:04 brad Exp $ */
/*
* Header file to make code compatible with ELF version
* ldconfig was taken from the a.out ld.
*/
#include <link.h>
-extern int n_search_dirs;
-extern char **search_dirs;
-char *xmalloc(int size);
-char *concat __P((const char *, const char *, const char *));
-#define PAGSIZ __LDPGSZ
+
+extern int n_search_dirs;
+extern char **search_dirs;
+char *xstrdup __P((char *));
+void *xmalloc __P((size_t));
+void *xrealloc __P((void *, size_t));
+char *concat __P((const char *, const char *, const char *));
+
+#define PAGSIZ __LDPGSZ
diff --git a/libexec/ld.so/ldconfig/ldconfig.8 b/libexec/ld.so/ldconfig/ldconfig.8
index d6feb6c4b74..62363480ade 100644
--- a/libexec/ld.so/ldconfig/ldconfig.8
+++ b/libexec/ld.so/ldconfig/ldconfig.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: ldconfig.8,v 1.4 2000/11/09 17:53:35 aaron Exp $
+.\" $OpenBSD: ldconfig.8,v 1.5 2001/01/30 02:39:05 brad Exp $
.\"
.\" Copyright (c) 1993,1995 Paul Kranenburg
.\" All rights reserved.
@@ -37,7 +37,7 @@
.Nd configure the shared library cache
.Sh SYNOPSIS
.Nm ldconfig
-.Op Fl Rmrsv
+.Op Fl RUmrsv
.Op Ar directory Ar ...
.Sh DESCRIPTION
.Nm
@@ -46,8 +46,7 @@ is used to prepare a set of
for use by the run-time linker
.Xr ld.so
to facilitate quick lookup of shared libraries available in multiple
-directories.
-It scans a set of built-in system directories and any
+directories. It scans a set of built-in system directories and any
.Ar directories
specified on the command line (in the given order) looking for shared
libraries and stores the results in the file
@@ -58,8 +57,8 @@ directory search operations
would have to perform to load the required shared libraries.
.Pp
The shared libraries so found will be automatically available for loading
-if needed by the program being prepared for execution.
-This obviates the need for storing search paths within the executable.
+if needed by the program being prepared for execution. This obviates the need
+for storing search paths within the executable.
.Pp
The
.Ev LD_LIBRARY_PATH
@@ -71,62 +70,63 @@ is a
.Sq \:
separated list of directory paths which are searched by
.Xr ld.so
-when it needs to load a shared library.
-It can be viewed as the run-time equivalent of the
-.Xr ld Ns 's
+when it needs to load a shared library. It can be viewed as the run-time
+equivalent of the
.Fl L
-switch.
+switch of
+.Xr ld.
.Pp
-.Nm
+.Nm Ldconfig
is typically run as part of the boot sequence.
.Pp
-The options are as follows:
-.Bl -tag -width Ds
+The following options are recognized by
+.Nm ldconfig:
+.Bl -tag -width indent
.It Fl R
-Rescan the previously configured directories.
-This opens the hints file
-and fetches the directory list from the header.
-Any additional pathnames on the command line are also processed.
+Rescan the previously configured directories. This opens the hints file
+and fetches the directory list from the header. Any additional pathnames
+on the command line are also processed.
+.It Fl U
+Unconfigure directories specified on the command line or remove inaccessible
+directories from search path if no directories specified. This option cannot
+be used with
+.Fl m .
.It Fl m
Merge the result of the scan of the directories given as arguments into
-the existing hints file.
-The default action is to build the hints file afresh.
+the existing hints file. The default action is to build the hints file
+afresh. This option cannot be used with
+.Fl U .
.It Fl r
-Lists the current contents of
+List the current contents of
.Xr ld.so.hints
-on the standard output.
-The hints file will not be modified.
+on the standard output. The hints file will not be modified.
.It Fl s
Do not scan the built-in system directory
.Pq Dq /usr/lib
for shared libraries.
.It Fl v
Switch on verbose mode.
-.El
-.Ss Security
+.Sh Security
Special care must be taken when loading shared libraries into the address
space of
.Ev set-user-Id
-programs.
-Whenever such a program is run,
+programs. Whenever such a program is run,
.Xr ld.so
will only load shared libraries from the
.Ev ld.so.hints
-file.
-In particular, the
+file. In particular, the
.Ev LD_LIBRARY_PATH
-is not used to search for libraries.
-Thus, the role of ldconfig is dual.
-In addition to building a set of hints for quick lookup, it also serves to
+is not used to search for libraries. Thus, the role of ldconfig is dual. In
+addition to building a set of hints for quick lookup, it also serves to
specify the trusted collection of directories from which shared objects can
-be safely loaded.
-It is presumed that the set of directories specified to
-.Nm
+be safely loaded. It is presumed that the set of directories specified to
+.Nm ldconfig
are under control of the system's administrator.
.Xr ld.so
further assists set-user-Id programs by erasing the
.Ev LD_LIBRARY_PATH
from the environment.
+
.Sh FILES
.Xr /var/run/ld.so.hints
.Sh SEE ALSO
diff --git a/libexec/ld.so/ldconfig/ldconfig.c b/libexec/ld.so/ldconfig/ldconfig.c
index 668a93549d1..b315505b75e 100644
--- a/libexec/ld.so/ldconfig/ldconfig.c
+++ b/libexec/ld.so/ldconfig/ldconfig.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ldconfig.c,v 1.1 2000/06/13 03:40:19 rahnds Exp $ */
+/* $OpenBSD: ldconfig.c,v 1.2 2001/01/30 02:39:06 brad Exp $ */
/*
* Copyright (c) 1993,1995 Paul Kranenburg
@@ -63,6 +63,7 @@ static int nostd;
static int justread;
static int merge;
static int rescan;
+static int unconfig;
struct shlib_list {
/* Internal list of shared libraries found */
@@ -92,11 +93,14 @@ char *argv[];
int i, c;
int rval = 0;
- while ((c = getopt(argc, argv, "Rmrsv")) != EOF) {
+ while ((c = getopt(argc, argv, "RUmrsv")) != EOF) {
switch (c) {
case 'R':
rescan = 1;
break;
+ case 'U':
+ rescan = unconfig = 1;
+ break;
case 'm':
merge = 1;
break;
@@ -110,12 +114,16 @@ char *argv[];
verbose = 1;
break;
default:
- errx(1, "Usage: %s [-mrsv] [dir ...]",
- __progname);
+ (void)fprintf(stderr,
+ "usage: %s [-RUmrsv] [dir ...]\n", __progname);
+ exit(1);
break;
}
}
+ if (unconfig && merge)
+ errx(1, "cannot use -U with -m");
+
dir_list = xmalloc(1);
*dir_list = '\0';
@@ -126,22 +134,35 @@ char *argv[];
listhints();
return 0;
}
- }
-
- if (!nostd && !merge)
- std_search_path();
- if (rescan)
add_search_path(dir_list);
+ dir_list = xrealloc(dir_list, 1);
+ *dir_list = '\0';
+ } else
+ if (!nostd)
+ std_search_path();
+
+ if (unconfig) {
+ if (optind < argc)
+ for (i = optind; i < argc; i++)
+ remove_search_dir(argv[i]);
+ else {
+ i = 0;
+ while (i < n_search_dirs) {
+ if (access(search_dirs[i], R_OK) < 0)
+ remove_search_dir(search_dirs[i]);
+ else
+ i++;
+ }
+ }
+ } else
+ for (i = optind; i < argc; i++)
+ add_search_dir(argv[i]);
- for (i = 0; i < n_search_dirs; i++)
- rval |= dodir(search_dirs[i], 1);
-
- for (i = optind; i < argc; i++) {
- /* Check for duplicates? */
- char *cp = concat(dir_list, *dir_list?":":"", argv[i]);
+ for (i = 0; i < n_search_dirs; i++) {
+ char *cp = concat(dir_list, *dir_list?":":"", search_dirs[i]);
free(dir_list);
dir_list = cp;
- rval |= dodir(argv[i], 0);
+ rval |= dodir(search_dirs[i], 0);
}
rval |= buildhints();
@@ -225,8 +246,7 @@ int dewey[], ndewey;
dir, file);
free(shp->name);
- if ((shp->name = strdup(name)) == NULL)
- errx(1, "virtual memory exhausted");
+ shp->name = xstrdup(name);
free(shp->path);
shp->path = concat(dir, "/", file);
bcopy(dewey, shp->dewey, sizeof(shp->dewey));
@@ -244,8 +264,7 @@ int dewey[], ndewey;
printf("Adding %s/%s\n", dir, file);
shp = (struct shlib_list *)xmalloc(sizeof *shp);
- if ((shp->name = strdup(name)) == NULL)
- errx(1, "virtual memory exhausted");
+ shp->name = xstrdup(name);
shp->path = concat(dir, "/", file);
bcopy(dewey, shp->dewey, MAXDEWEY);
shp->ndewey = ndewey;
@@ -462,37 +481,35 @@ readhints()
blist = (struct hints_bucket *)(addr + hdr->hh_hashtab);
strtab = (char *)(addr + hdr->hh_strtab);
- if (justread || !rescan) {
- for (i = 0; i < hdr->hh_nbucket; i++) {
- struct hints_bucket *bp = &blist[i];
+ dir_list = xstrdup(strtab + hdr->hh_dirlist);
- /* Sanity check */
- if (bp->hi_namex >= hdr->hh_strtab_sz) {
- warnx("Bad name index: %#x", bp->hi_namex);
- return -1;
- }
- if (bp->hi_pathx >= hdr->hh_strtab_sz) {
- warnx("Bad path index: %#x", bp->hi_pathx);
- return -1;
- }
+ if (rescan)
+ return (0);
- /* Allocate new list element */
- shp = (struct shlib_list *)xmalloc(sizeof *shp);
- if ((shp->name = strdup(strtab + bp->hi_namex)) == NULL)
- errx(1, "virtual memory exhausted");
- if ((shp->path = strdup(strtab + bp->hi_pathx)) == NULL)
- errx(1, "virtual memory exhausted");
- bcopy(bp->hi_dewey, shp->dewey, sizeof(shp->dewey));
- shp->ndewey = bp->hi_ndewey;
- shp->next = NULL;
-
- *shlib_tail = shp;
- shlib_tail = &shp->next;
+ for (i = 0; i < hdr->hh_nbucket; i++) {
+ struct hints_bucket *bp = &blist[i];
+
+ /* Sanity check */
+ if (bp->hi_namex >= hdr->hh_strtab_sz) {
+ warnx("Bad name index: %#x", bp->hi_namex);
+ return -1;
+ }
+ if (bp->hi_pathx >= hdr->hh_strtab_sz) {
+ warnx("Bad path index: %#x", bp->hi_pathx);
+ return -1;
}
- }
- if ((dir_list = strdup(strtab + hdr->hh_dirlist)) == NULL)
- errx(1, "virtual memory exhausted");
+ /* Allocate new list element */
+ shp = (struct shlib_list *)xmalloc(sizeof *shp);
+ shp->name = xstrdup(strtab + bp->hi_namex);
+ shp->path = xstrdup(strtab + bp->hi_pathx);
+ bcopy(bp->hi_dewey, shp->dewey, sizeof(shp->dewey));
+ shp->ndewey = bp->hi_ndewey;
+ shp->next = NULL;
+
+ *shlib_tail = shp;
+ shlib_tail = &shp->next;
+ }
return 0;
}
diff --git a/libexec/ld.so/ldconfig/shlib.c b/libexec/ld.so/ldconfig/shlib.c
index 925c6c7491f..8c306f2c11e 100644
--- a/libexec/ld.so/ldconfig/shlib.c
+++ b/libexec/ld.so/ldconfig/shlib.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: shlib.c,v 1.1 2000/06/13 03:40:21 rahnds Exp $ */
+/* $OpenBSD: shlib.c,v 1.2 2001/01/30 02:39:06 brad Exp $ */
/* $NetBSD: shlib.c,v 1.13 1998/04/04 01:00:29 fvdl Exp $ */
/*
@@ -77,26 +77,47 @@ void
add_search_dir(name)
char *name;
{
+ int i, len;
+
+ len = strlen(name);
+
+ while (len > 1 && name[len - 1] == '/')
+ --len;
+
+ for (i = 0; i < n_search_dirs; i++)
+ if (strlen(search_dirs[i]) == len &&
+ !strncmp(search_dirs[i], name, len))
+ return;
n_search_dirs++;
search_dirs = (char **)
xrealloc(search_dirs, n_search_dirs * sizeof search_dirs[0]);
- search_dirs[n_search_dirs - 1] = strdup(name);
+ search_dirs[n_search_dirs - 1] = xmalloc(++len);
+ (void)strlcpy(search_dirs[n_search_dirs - 1], name, len);
}
void
remove_search_dir(name)
char *name;
{
- int n;
+ int i, len;
- for (n = 0; n < n_search_dirs; n++) {
- if (strcmp(search_dirs[n], name))
+ len = strlen(name);
+
+ while (len > 1 && name[len - 1] == '/')
+ --len;
+
+ for (i = 0; i < n_search_dirs; i++) {
+ if (strlen(search_dirs[i]) != len ||
+ strncmp(search_dirs[i], name, len))
continue;
- free(search_dirs[n]);
- if (n < (n_search_dirs - 1))
- bcopy(&search_dirs[n+1], &search_dirs[n],
- (n_search_dirs - n - 1) * sizeof search_dirs[0]);
+ free(search_dirs[i]);
+ if (i < (n_search_dirs - 1))
+ bcopy(&search_dirs[i+1], &search_dirs[i],
+ (n_search_dirs - i - 1) * sizeof search_dirs[0]);
n_search_dirs--;
+ search_dirs = (char **)xrealloc(search_dirs,
+ n_search_dirs * sizeof search_dirs[0]);
+ break;
}
}