summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--TODO2
-rw-r--r--include/canonicalize.h11
-rw-r--r--lib/canonicalize.c (renamed from mount/realpath.c)77
-rw-r--r--mount/Makefile.am21
-rw-r--r--mount/fsprobe.c1
-rw-r--r--mount/fsprobe_volumeid.c1
-rw-r--r--mount/fstab.c5
-rw-r--r--mount/lomount.c1
-rw-r--r--mount/mount.c1
-rw-r--r--mount/realpath.h14
-rw-r--r--mount/sundries.c48
-rw-r--r--mount/sundries.h5
-rw-r--r--mount/swapon.c1
-rw-r--r--mount/umount.c1
14 files changed, 103 insertions, 86 deletions
diff --git a/TODO b/TODO
index 42cbed417..65cc55aa5 100644
--- a/TODO
+++ b/TODO
@@ -12,6 +12,8 @@
Although mkswap has recently been -L option to create a label nothing appears to
have been change to swapon to display said labels. (rh#430386)
+ * use canonicalize_file_name() when exist in glibc (see lib/canonicalize.v)
+
* try improve compilation against others libc:
- klibc
- ???
diff --git a/include/canonicalize.h b/include/canonicalize.h
new file mode 100644
index 000000000..b8906d43d
--- /dev/null
+++ b/include/canonicalize.h
@@ -0,0 +1,11 @@
+#ifndef CANONICALIZE_H
+#define CANONICALIZE_H
+
+#include <limits.h>
+#ifndef PATH_MAX
+# define PATH_MAX 4096
+#endif
+
+extern char *canonicalize_path(const char *path);
+
+#endif /* CANONICALIZE_H */
diff --git a/mount/realpath.c b/lib/canonicalize.c
index 9b46951b5..b888fbb8e 100644
--- a/mount/realpath.c
+++ b/lib/canonicalize.c
@@ -1,5 +1,5 @@
/*
- * realpath.c -- canonicalize pathname by removing symlinks
+ * canonicalize.c -- canonicalize pathname by removing symlinks
* Copyright (C) 1993 Rick Sladkey <jrs@world.std.com>
*
* This program is free software; you can redistribute it and/or modify
@@ -11,67 +11,27 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library Public License for more details.
+ *
*/
-#define resolve_symlinks
-
/*
* This routine is part of libc. We include it nevertheless,
* since the libc version has some security flaws.
+ *
+ * TODO: use canonicalize_file_name() when exist in glibc
*/
#include <unistd.h>
#include <string.h>
#include <errno.h>
-#include "realpath.h"
-#include "sundries.h" /* for xstrdup */
+#include <stdlib.h>
+
+#include "canonicalize.h"
#ifndef MAXSYMLINKS
# define MAXSYMLINKS 256
#endif
-int
-is_pseudo_fs(const char *type)
-{
- if (type == NULL || *type == '/')
- return 0;
- if (streq(type, "none") ||
- streq(type, "proc") ||
- streq(type, "tmpfs") ||
- streq(type, "sysfs") ||
- streq(type, "devpts"))
- return 1;
- return 0;
-}
-
-/* Make a canonical pathname from PATH. Returns a freshly malloced string.
- It is up the *caller* to ensure that the PATH is sensible. i.e.
- canonicalize ("/dev/fd0/.") returns "/dev/fd0" even though ``/dev/fd0/.''
- is not a legal pathname for ``/dev/fd0''. Anything we cannot parse
- we return unmodified. */
-char *
-canonicalize_spec (const char *path)
-{
- if (path == NULL)
- return NULL;
- if (is_pseudo_fs(path))
- return xstrdup(path);
- return canonicalize(path);
-}
-
-char *
-canonicalize (const char *path) {
- char canonical[PATH_MAX+2];
-
- if (path == NULL)
- return NULL;
-
- if (myrealpath (path, canonical, PATH_MAX+1))
- return xstrdup(canonical);
-
- return xstrdup(path);
-}
-
-char *
+static char *
myrealpath(const char *path, char *resolved_path, int maxreslth) {
int readlinks = 0;
char *npath;
@@ -137,7 +97,6 @@ myrealpath(const char *path, char *resolved_path, int maxreslth) {
if (errno != EINVAL)
goto err;
} else {
-#ifdef resolve_symlinks /* Richard Gooch dislikes sl resolution */
int m;
char *newbuf;
@@ -153,12 +112,13 @@ myrealpath(const char *path, char *resolved_path, int maxreslth) {
/* Insert symlink contents into path. */
m = strlen(path);
- newbuf = xmalloc(m + n + 1);
+ newbuf = malloc(m + n + 1);
+ if (!newbuf)
+ goto err;
memcpy(newbuf, link_path, n);
memcpy(newbuf + n, path, m + 1);
free(buf);
path = buf = newbuf;
-#endif
}
*npath++ = '/';
}
@@ -175,3 +135,18 @@ myrealpath(const char *path, char *resolved_path, int maxreslth) {
free(buf);
return NULL;
}
+
+char *
+canonicalize_path(const char *path) {
+ char canonical[PATH_MAX+2];
+
+ if (path == NULL)
+ return NULL;
+
+ if (myrealpath (path, canonical, PATH_MAX+1))
+ return strdup(canonical);
+
+ return strdup(path);
+}
+
+
diff --git a/mount/Makefile.am b/mount/Makefile.am
index 3963fdaf6..90d956ebf 100644
--- a/mount/Makefile.am
+++ b/mount/Makefile.am
@@ -6,15 +6,15 @@ bin_PROGRAMS = mount umount
sbin_PROGRAMS = losetup swapon
dist_man_MANS = fstab.5 mount.8 swapoff.8 swapon.8 umount.8 losetup.8
-utils_common = sundries.c xmalloc.c realpath.c fsprobe.c
+utils_common = sundries.c xmalloc.c ../lib/canonicalize.c
headers_common = fstab.h mount_mntent.h mount_constants.h \
- lomount.h fsprobe.h realpath.h xmalloc.h \
+ lomount.h fsprobe.h xmalloc.h \
getusername.h loop.h sundries.h
mount_common = fstab.c mount_mntent.c getusername.c lomount.c \
$(utils_common) $(headers_common) ../lib/env.c ../lib/linux_version.c \
- ../lib/blkdev.c
+ ../lib/blkdev.c fsprobe.c
mount_SOURCES = mount.c $(mount_common) ../lib/setproctitle.c
mount_CFLAGS = $(SUID_CFLAGS) $(AM_CFLAGS)
@@ -25,10 +25,10 @@ umount_CFLAGS = $(SUID_CFLAGS) $(AM_CFLAGS)
umount_LDFLAGS = $(SUID_LDFLAGS) $(AM_LDFLAGS)
swapon_SOURCES = swapon.c swap_constants.h $(utils_common) \
- ../lib/linux_version.c ../lib/blkdev.c
+ ../lib/linux_version.c ../lib/blkdev.c fsprobe.c
-losetup_SOURCES = lomount.c sundries.c xmalloc.c realpath.c \
- loop.h lomount.h xmalloc.h sundries.h realpath.h
+losetup_SOURCES = lomount.c $(utils_common) \
+ loop.h lomount.h xmalloc.h sundries.h
losetup_CPPFLAGS = -DMAIN $(AM_CPPFLAGS)
mount_LDADD = $(LDADD_common)
@@ -61,7 +61,8 @@ losetup_static_CPPFLAGS = -DMAIN $(AM_CPPFLAGS)
endif
if HAVE_BLKID
-utils_common += fsprobe_blkid.c
+mount_common += fsprobe_blkid.c
+swapon_SOURCES += fsprobe_blkid.c
LDADD_common += $(BLKID_LIBS)
LDADD_common_static += $(BLKID_LIBS_STATIC)
endif
@@ -72,13 +73,15 @@ mount_static_LDADD += $(SELINUX_LIBS_STATIC)
endif
if HAVE_VOLUME_ID
-utils_common += fsprobe_volumeid.c
+mount_common += fsprobe_volumeid.c
+swapon_SOURCES += fsprobe_volumeid.c
LDADD_common += $(VOLUMEID_LIBS)
LDADD_common_static += $(VOLUMEID_LIBS_STATIC)
endif
noinst_PROGRAMS = mtab_lock_test
-mtab_lock_test_SOURCES = fstab.c sundries.c xmalloc.c $(headers_common)
+mtab_lock_test_SOURCES = fstab.c sundries.c xmalloc.c $(headers_common) \
+ ../lib/canonicalize.c
mtab_lock_test_CPPFLAGS = -DMAIN_TEST_MTABLOCK $(AM_CPPFLAGS)
install-exec-hook:
diff --git a/mount/fsprobe.c b/mount/fsprobe.c
index 07ffbd9ab..04e267f33 100644
--- a/mount/fsprobe.c
+++ b/mount/fsprobe.c
@@ -9,7 +9,6 @@
#include "fsprobe.h"
#include "sundries.h" /* for xstrdup */
#include "nls.h"
-#include "realpath.h"
/* list of already tested filesystems by fsprobe_procfsloop_mount() */
static struct tried {
diff --git a/mount/fsprobe_volumeid.c b/mount/fsprobe_volumeid.c
index b9b137b8a..a5c928230 100644
--- a/mount/fsprobe_volumeid.c
+++ b/mount/fsprobe_volumeid.c
@@ -12,7 +12,6 @@
#include "blkdev.h"
#include "fsprobe.h"
-#include "realpath.h"
#include "pathnames.h"
#include "sundries.h"
diff --git a/mount/fstab.c b/mount/fstab.c
index c60c5f4db..bcbc3a9db 100644
--- a/mount/fstab.c
+++ b/mount/fstab.c
@@ -19,7 +19,6 @@
#include "fsprobe.h"
#include "pathnames.h"
#include "nls.h"
-#include "realpath.h"
#define streq(s, t) (strcmp ((s), (t)) == 0)
@@ -924,10 +923,6 @@ mntFILE *my_setmntent (const char *file, char *mode) { return NULL; }
void my_endmntent (mntFILE *mfp) { }
int my_addmntent (mntFILE *mfp, struct my_mntent *mnt) { return 0; }
-char *canonicalize (const char *path) { return NULL; }
-char *canonicalize_spec (const char *path) { return NULL; }
-int is_pseudo_fs(const char *type) { return 0; };
-
int
main(int argc, char **argv)
{
diff --git a/mount/lomount.c b/mount/lomount.c
index 5675eac0a..ece0003e5 100644
--- a/mount/lomount.c
+++ b/mount/lomount.c
@@ -22,7 +22,6 @@
#include "nls.h"
#include "sundries.h"
#include "xmalloc.h"
-#include "realpath.h"
#include "pathnames.h"
#define SIZE(a) (sizeof(a)/sizeof(a[0]))
diff --git a/mount/mount.c b/mount/mount.c
index 23f27d676..e04dbdb51 100644
--- a/mount/mount.c
+++ b/mount/mount.c
@@ -40,7 +40,6 @@
#include "env.h"
#include "nls.h"
#include "blkdev.h"
-#include "realpath.h"
#define DO_PS_FIDDLING
diff --git a/mount/realpath.h b/mount/realpath.h
deleted file mode 100644
index 15450c1d7..000000000
--- a/mount/realpath.h
+++ /dev/null
@@ -1,14 +0,0 @@
-#ifndef REALPATH_H
-#define REALPATH_H
-
-#include <limits.h>
-#ifndef PATH_MAX
-# define PATH_MAX 4096
-#endif
-
-extern char *myrealpath(const char *path, char *resolved_path, int m);
-extern char *canonicalize (const char *path);
-extern char *canonicalize_spec (const char *path);
-extern int is_pseudo_fs(const char *type);
-
-#endif /* REALPATH_H */
diff --git a/mount/sundries.c b/mount/sundries.c
index fad8eaec6..bdaf11722 100644
--- a/mount/sundries.c
+++ b/mount/sundries.c
@@ -11,9 +11,11 @@
#include <stdio.h>
#include <string.h>
#include <mntent.h> /* for MNTTYPE_SWAP */
+
+#include "canonicalize.h"
+
#include "fstab.h"
#include "sundries.h"
-#include "realpath.h"
#include "xmalloc.h"
#include "nls.h"
@@ -276,3 +278,47 @@ parse_spec(const char *spec, char **name, char **value)
return 0;
}
+int
+is_pseudo_fs(const char *type)
+{
+ if (type == NULL || *type == '/')
+ return 0;
+ if (streq(type, "none") ||
+ streq(type, "proc") ||
+ streq(type, "tmpfs") ||
+ streq(type, "sysfs") ||
+ streq(type, "devpts"))
+ return 1;
+ return 0;
+}
+
+/* Make a canonical pathname from PATH. Returns a freshly malloced string.
+ It is up the *caller* to ensure that the PATH is sensible. i.e.
+ canonicalize ("/dev/fd0/.") returns "/dev/fd0" even though ``/dev/fd0/.''
+ is not a legal pathname for ``/dev/fd0''. Anything we cannot parse
+ we return unmodified. */
+char *
+canonicalize_spec (const char *path)
+{
+ char *res;
+
+ if (path == NULL)
+ return NULL;
+ if (is_pseudo_fs(path))
+ return xstrdup(path);
+
+ res = canonicalize_path(path);
+ if (!res)
+ die(EX_SYSERR, _("not enough memory"));
+ return res;
+}
+
+char *canonicalize (const char *path)
+{
+ char *res = canonicalize_path(path);
+
+ if (!res)
+ die(EX_SYSERR, _("not enough memory"));
+ return res;
+}
+
diff --git a/mount/sundries.h b/mount/sundries.h
index f64d15dbd..c85701287 100644
--- a/mount/sundries.h
+++ b/mount/sundries.h
@@ -37,6 +37,11 @@ char *xstrconcat4 (char *, const char *, const char *, const char *);
int parse_spec(const char *spec, char **name, char **value);
+int is_pseudo_fs(const char *type);
+
+char *canonicalize (const char *path);
+char *canonicalize_spec (const char *path);
+
/* exit status - bits below are ORed */
#define EX_USAGE 1 /* incorrect invocation or permission */
#define EX_SYSERR 2 /* out of memory, cannot fork, ... */
diff --git a/mount/swapon.c b/mount/swapon.c
index 0d5067e04..c50c32ae5 100644
--- a/mount/swapon.c
+++ b/mount/swapon.c
@@ -20,7 +20,6 @@
#include "swap_constants.h"
#include "nls.h"
#include "fsprobe.h"
-#include "realpath.h"
#include "pathnames.h"
#include "sundries.h"
#include "swapheader.h"
diff --git a/mount/umount.c b/mount/umount.c
index 738d05c31..9901a809e 100644
--- a/mount/umount.c
+++ b/mount/umount.c
@@ -19,7 +19,6 @@
#include "fstab.h"
#include "env.h"
#include "nls.h"
-#include "realpath.h"
#if defined(MNT_FORCE)
/* Interesting ... it seems libc knows about MNT_FORCE and presumably