diff options
author | Miloslav Trmac <mitr@volny.cz> | 2006-05-08 23:54:06 +0000 |
---|---|---|
committer | Miloslav Trmac <mitr@volny.cz> | 2006-05-08 23:54:06 +0000 |
commit | 3bd074fd404b4863d811d0a50e9ef484523c6b57 (patch) | |
tree | 9c4ca48303377ab77a8a00d10561ba1e8afbab28 /src | |
parent | 0414be84b33e98510feb1d0e281b089ba16b349d (diff) | |
download | initscripts-3bd074fd404b4863d811d0a50e9ef484523c6b57.tar initscripts-3bd074fd404b4863d811d0a50e9ef484523c6b57.tar.gz initscripts-3bd074fd404b4863d811d0a50e9ef484523c6b57.tar.bz2 initscripts-3bd074fd404b4863d811d0a50e9ef484523c6b57.tar.xz initscripts-3bd074fd404b4863d811d0a50e9ef484523c6b57.zip |
Fix handling of mount points with white space (#186713):
- src/fstab-decode.c, src/fstab-decode.8: New files.
- src/Makefile: Build and install fstab-decode.
- initscripts.spec: Add fstab-decode to %files
- rc.d/init.d/functions (fstab_decode_str): New function.
(__umount_loop, __umount_loopback_loop): Factor out from copy&pasted copies.
(action): Fix command quoting.
- rc.d/rc.sysinit: Correctly quote and decode mount points.
- rc.d/init.d/halt: Use __umount_* and fstab-decode.
(action): Rename from runcmd. Fix command quoting.
- rc.d/init.d/netfs: Use __umount_*.
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile | 4 | ||||
-rw-r--r-- | src/fstab-decode.8 | 45 | ||||
-rw-r--r-- | src/fstab-decode.c | 86 |
3 files changed, 134 insertions, 1 deletions
diff --git a/src/Makefile b/src/Makefile index 78276fad..84d6d439 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,7 +1,7 @@ CFLAGS+=$(RPM_OPT_FLAGS) -Wall -D_GNU_SOURCE PROGS=usernetctl doexec netreport testd usleep ipcalc initlog \ - getkey ppp-watch consoletype genhostid rename_device + fstab-decode getkey ppp-watch consoletype genhostid rename_device PPPWATCH_OBJS=ppp-watch.o shvar.o INITLOG_OBJS=initlog.o process.o USLEEP_OBJS=usleep.o @@ -20,6 +20,7 @@ install: install -m 4755 usernetctl $(ROOT)/usr/sbin/usernetctl install -m 2755 netreport $(ROOT)/sbin/netreport install -m 755 ipcalc $(ROOT)/bin/ipcalc + install -m 755 fstab-decode $(ROOT)/sbin/fstab-decode install -m 755 genhostid $(ROOT)/sbin/genhostid install -m 755 initlog $(ROOT)/sbin/initlog install -m 755 getkey $(ROOT)/sbin/getkey @@ -32,6 +33,7 @@ install: install -m 644 getkey.1 $(ROOT)$(mandir)/man1 install -m 644 netreport.1 $(ROOT)$(mandir)/man1 install -m 644 usleep.1 $(ROOT)$(mandir)/man1 + install -m 644 fstab-decode.8 $(ROOT)$(mandir)/man8 install -m 644 usernetctl.8 $(ROOT)$(mandir)/man8 install -m 644 ppp-watch.8 $(ROOT)$(mandir)/man8 install -m 644 ipcalc.1 $(ROOT)$(mandir)/man1 diff --git a/src/fstab-decode.8 b/src/fstab-decode.8 new file mode 100644 index 00000000..216dee86 --- /dev/null +++ b/src/fstab-decode.8 @@ -0,0 +1,45 @@ +.\" A man page for fstab-decode(8). +.\" +.\" Copyright (C) 2006 Red Hat, Inc. All rights reserved. +.\" +.\" This copyrighted material is made available to anyone wishing to use, +.\" modify, copy, or redistribute it subject to the terms and conditions of the +.\" GNU General Public License v.2. +.\" +.\" This program is distributed in the hope that it will be useful, but WITHOUT +.\" ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +.\" FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +.\" more details. +.\" +.\" You should have received a copy of the GNU General Public License along +.\" with this program; if not, write to the Free Software Foundation, Inc., +.\" 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +.\" +.\" Author: Miloslav Trmac <mitr@redhat.com> +.TH fstab-decode 8 "May 2006" + +.SH NAME +fstab-decode \- run a command with fstab-encoded arguments + +.SH SYNOPSIS +\fB fstab-decode\fR \fICOMMAND\fR [\fIARGUMENT\fR]... + +.SH DESCRIPTION +.B fstab-decode +decodes escapes in the specified \FIARGUMENT\fRs +and uses them to run \fICOMMAND\fR. +The argument escaping uses the same rules as path escaping in +\fB/etc/fstab\fR, +.B /etc/mtab +and \fB/proc/mtab\fR. + +.SH EXIT STATUS +.B fstab-decode +exits with status 127 if +.I COMMAND +can't be run. +Otherwise it exits with the status returned by \fICOMMAND\fR. + +.SH EXAMPLES + +.B fstab-decode umount $(awk '$3 == "vfat" { print $2 }' /etc/fstab) diff --git a/src/fstab-decode.c b/src/fstab-decode.c new file mode 100644 index 00000000..4a162dfe --- /dev/null +++ b/src/fstab-decode.c @@ -0,0 +1,86 @@ +/* fstab-decode(8). + +Copyright (c) 2006 Red Hat, Inc. All rights reserved. + +This copyrighted material is made available to anyone wishing to use, modify, +copy, or redistribute it subject to the terms and conditions of the GNU General +Public License v.2. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 51 Franklin +Street, Fifth Floor, Boston, MA 02110-1301, USA. + +Author: Miloslav Trmac <mitr@redhat.com> */ + +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +/* Decode the fstab-encoded string in place. */ +static void +decode(char *s) +{ + const char *src; + char *dest; + + src = s; + dest = s; + while (*src != '\0') { + if (*src != '\\') + *dest = *src++; + else { + static const struct repl { + char orig[4]; + size_t len; + char new; + } repls[] = { +#define R(X, Y) { X, sizeof(X) - 1, Y } + R("\\", '\\'), + R("011", '\t'), + R("012", '\n'), + R("040", ' '), + R("134", '\\') +#undef R + }; + + size_t i; + + for (i = 0; i < sizeof (repls) / sizeof (repls[0]); + i++) { + if (memcmp(src + 1, repls[i].orig, + repls[i].len) == 0) { + *dest = repls[i].new; + src += 1 + repls[i].len; + goto found; + } + } + *dest = *src++; + found: + ; + } + dest++; + } + *dest = '\0'; +} + +int +main (int argc, char *argv[]) +{ + size_t i; + + if (argc < 2) { + fprintf(stderr, "Usage: fstab-decode command [arguments]\n"); + return EXIT_FAILURE; + } + for (i = 2; i < (size_t)argc; i++) + decode(argv[i]); + execvp(argv[1], argv + 1); + fprintf(stderr, "fstab-decode: %s: %s\n", argv[1], strerror(errno)); + return 127; +} |