summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 6267f10)
raw | patch | inline | side by side (parent: 6267f10)
author | Ton Voon <tonvoon@users.sourceforge.net> | |
Tue, 11 Jul 2006 12:38:09 +0000 (12:38 +0000) | ||
committer | Ton Voon <tonvoon@users.sourceforge.net> | |
Tue, 11 Jul 2006 12:38:09 +0000 (12:38 +0000) |
on Tru64 (Ciro Iriarte - 1520331)
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1446 f882894a-f735-0410-b71e-b25c423dba1c
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1446 f882894a-f735-0410-b71e-b25c423dba1c
12 files changed:
lib/creat-safer.c | [new file with mode: 0644] | patch | blob |
lib/dup-safer.c | [new file with mode: 0644] | patch | blob |
lib/fcntl--.h | [new file with mode: 0644] | patch | blob |
lib/fcntl-safer.h | [new file with mode: 0644] | patch | blob |
lib/fd-safer.c | [new file with mode: 0644] | patch | blob |
lib/open-safer.c | [new file with mode: 0644] | patch | blob |
lib/pipe-safer.c | [new file with mode: 0644] | patch | blob |
lib/unistd--.h | [new file with mode: 0644] | patch | blob |
lib/unistd-safer.h | [new file with mode: 0644] | patch | blob |
m4/fcntl-safer.m4 | [new file with mode: 0644] | patch | blob |
m4/np_coreutils.m4 | patch | blob | history | |
m4/unistd-safer.m4 | [new file with mode: 0644] | patch | blob |
diff --git a/lib/creat-safer.c b/lib/creat-safer.c
--- /dev/null
+++ b/lib/creat-safer.c
@@ -0,0 +1,33 @@
+/* Invoke creat, but avoid some glitches.
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ 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. */
+
+/* Written by Jim Meyering. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "fcntl-safer.h"
+
+#include <fcntl.h>
+#include "unistd-safer.h"
+
+int
+creat_safer (char const *file, mode_t mode)
+{
+ return fd_safer (creat (file, mode));
+}
diff --git a/lib/dup-safer.c b/lib/dup-safer.c
--- /dev/null
+++ b/lib/dup-safer.c
@@ -0,0 +1,46 @@
+/* Invoke dup, but avoid some glitches.
+ Copyright (C) 2001, 2004, 2005 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ 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. */
+
+/* Written by Paul Eggert. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "unistd-safer.h"
+
+#include <fcntl.h>
+
+#include <unistd.h>
+#ifndef STDERR_FILENO
+# define STDERR_FILENO 2
+#endif
+
+/* Like dup, but do not return STDIN_FILENO, STDOUT_FILENO, or
+ STDERR_FILENO. */
+
+int
+dup_safer (int fd)
+{
+#ifdef F_DUPFD
+ return fcntl (fd, F_DUPFD, STDERR_FILENO + 1);
+#else
+ /* fd_safer calls us back, but eventually the recursion unwinds and
+ does the right thing. */
+ return fd_safer (dup (fd));
+#endif
+}
diff --git a/lib/fcntl--.h b/lib/fcntl--.h
--- /dev/null
+++ b/lib/fcntl--.h
@@ -0,0 +1,28 @@
+/* Like fcntl.h, but redefine some names to avoid glitches.
+
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ 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. */
+
+/* Written by Paul Eggert. */
+
+#include <fcntl.h>
+#include "fcntl-safer.h"
+
+#undef open
+#define open open_safer
+
+#undef creat
+#define creat creat_safer
diff --git a/lib/fcntl-safer.h b/lib/fcntl-safer.h
--- /dev/null
+++ b/lib/fcntl-safer.h
@@ -0,0 +1,24 @@
+/* Invoke fcntl-like functions, but avoid some glitches.
+
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ 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. */
+
+/* Written by Paul Eggert. */
+
+#include <sys/types.h>
+
+int open_safer (char const *, int, ...);
+int creat_safer (char const *, mode_t);
diff --git a/lib/fd-safer.c b/lib/fd-safer.c
--- /dev/null
+++ b/lib/fd-safer.c
@@ -0,0 +1,59 @@
+/* Return a safer copy of a file descriptor.
+
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ 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. */
+
+/* Written by Paul Eggert. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "unistd-safer.h"
+
+#include <errno.h>
+
+#include <unistd.h>
+#ifndef STDIN_FILENO
+# define STDIN_FILENO 0
+#endif
+#ifndef STDERR_FILENO
+# define STDERR_FILENO 2
+#endif
+
+/* Return FD, unless FD would be a copy of standard input, output, or
+ error; in that case, return a duplicate of FD, closing FD. On
+ failure to duplicate, close FD, set errno, and return -1. Preserve
+ errno if FD is negative, so that the caller can always inspect
+ errno when the returned value is negative.
+
+ This function is usefully wrapped around functions that return file
+ descriptors, e.g., fd_safer (open ("file", O_RDONLY)). */
+
+int
+fd_safer (int fd)
+{
+ if (STDIN_FILENO <= fd && fd <= STDERR_FILENO)
+ {
+ int f = dup_safer (fd);
+ int e = errno;
+ close (fd);
+ errno = e;
+ fd = f;
+ }
+
+ return fd;
+}
diff --git a/lib/open-safer.c b/lib/open-safer.c
--- /dev/null
+++ b/lib/open-safer.c
@@ -0,0 +1,51 @@
+/* Invoke open, but avoid some glitches.
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ 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. */
+
+/* Written by Paul Eggert. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "fcntl-safer.h"
+
+#include <fcntl.h>
+#include <stdarg.h>
+#include "unistd-safer.h"
+
+int
+open_safer (char const *file, int flags, ...)
+{
+ mode_t mode = 0;
+
+ if (flags & O_CREAT)
+ {
+ va_list ap;
+ va_start (ap, flags);
+
+ /* Assume mode_t promotes to int if and only if it is smaller.
+ This assumption isn't guaranteed by the C standard, but we
+ don't know of any real-world counterexamples. */
+ mode = (sizeof (mode_t) < sizeof (int)
+ ? va_arg (ap, int)
+ : va_arg (ap, mode_t));
+
+ va_end (ap);
+ }
+
+ return fd_safer (open (file, flags, mode));
+}
diff --git a/lib/pipe-safer.c b/lib/pipe-safer.c
--- /dev/null
+++ b/lib/pipe-safer.c
@@ -0,0 +1,50 @@
+/* Invoke pipe, but avoid some glitches.
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ 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. */
+
+/* Written by Jim Meyering. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "unistd-safer.h"
+
+#include <unistd.h>
+
+/* Like pipe, but ensure that neither of the file descriptors is
+ STDIN_FILENO, STDOUT_FILENO, or STDERR_FILENO. */
+
+int
+pipe_safer (int fd[2])
+{
+ int fail = pipe (fd);
+ if (fail)
+ return fail;
+
+ {
+ int i;
+ for (i = 0; i < 2; i++)
+ {
+ int f = fd_safer (fd[i]);
+ if (f < 0)
+ return -1;
+ fd[i] = f;
+ }
+ }
+
+ return 0;
+}
diff --git a/lib/unistd--.h b/lib/unistd--.h
--- /dev/null
+++ b/lib/unistd--.h
@@ -0,0 +1,28 @@
+/* Like unistd.h, but redefine some names to avoid glitches.
+
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ 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. */
+
+/* Written by Paul Eggert. */
+
+#include <unistd.h>
+#include "unistd-safer.h"
+
+#undef dup
+#define dup dup_safer
+
+#undef pipe
+#define pipe pipe_safer
diff --git a/lib/unistd-safer.h b/lib/unistd-safer.h
--- /dev/null
+++ b/lib/unistd-safer.h
@@ -0,0 +1,23 @@
+/* Invoke unistd-like functions, but avoid some glitches.
+
+ Copyright (C) 2001, 2003, 2005 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ 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. */
+
+/* Written by Paul Eggert. */
+
+int dup_safer (int);
+int fd_safer (int);
+int pipe_safer (int[2]);
diff --git a/m4/fcntl-safer.m4 b/m4/fcntl-safer.m4
--- /dev/null
+++ b/m4/fcntl-safer.m4
@@ -0,0 +1,12 @@
+#serial 2
+dnl Copyright (C) 2005 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FCNTL_SAFER],
+[
+ AC_LIBSOURCES([creat-safer.c, fcntl-safer.h, open-safer.c, fcntl--.h])
+ AC_LIBOBJ([open-safer])
+ AC_LIBOBJ([creat-safer])
+])
diff --git a/m4/np_coreutils.m4 b/m4/np_coreutils.m4
index 23d55e4468e4bb88ac51eccec320f1eced35ac3d..5360bbd07ef1ac6f636496e0c7e584fad1ce46f2 100644 (file)
--- a/m4/np_coreutils.m4
+++ b/m4/np_coreutils.m4
AC_REQUIRE([AM_STDBOOL_H])
AC_REQUIRE([gl_C_STRTOLD])
AC_REQUIRE([gl_EXITFAIL])
+ AC_REQUIRE([gl_FCNTL_SAFER])
AC_REQUIRE([gl_FSUSAGE])
AC_REQUIRE([gl_FUNC_ALLOCA])
AC_REQUIRE([gl_GETOPT])
AC_REQUIRE([gl_MOUNTLIST])
AC_REQUIRE([gl_REGEX])
+ AC_REQUIRE([gl_UNISTD_SAFER])
AC_REQUIRE([gl_XALLOC])
AC_REQUIRE([gl_FUNC_GLIBC_UNLOCKED_IO])
diff --git a/m4/unistd-safer.m4 b/m4/unistd-safer.m4
--- /dev/null
+++ b/m4/unistd-safer.m4
@@ -0,0 +1,13 @@
+#serial 7
+dnl Copyright (C) 2002, 2005 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_UNISTD_SAFER],
+[
+ AC_LIBSOURCES([dup-safer.c, fd-safer.c, pipe-safer.c, unistd-safer.h, unistd--.h])
+ AC_LIBOBJ([dup-safer])
+ AC_LIBOBJ([fd-safer])
+ AC_LIBOBJ([pipe-safer])
+])