[PATCH 2/6] move copyfileperms to non-static file_copyfileperms
this functionality is also needed by the conffile handling code to ensure
that the merge output is stored in a file with the same permissions as
the original conffile, preventing the accidental oppurtunity for
unintended information disclosure.
therefore the function is moved into a new library module (file.{c,h}),
and given an appropriate prefix. note that some of the translatable error
messages have been modified as they would otherwise be misleading.
---
lib/dpkg/Makefile.am | 1 +
lib/dpkg/file.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++
lib/dpkg/file.h | 35 +++++++++++++++++++++++++++++
src/configure.c | 28 +----------------------
4 files changed, 97 insertions(+), 26 deletions(-)
create mode 100644 lib/dpkg/file.c
create mode 100644 lib/dpkg/file.h
diff --git a/lib/dpkg/Makefile.am b/lib/dpkg/Makefile.am
index d45bcd4..245f2c6 100644
--- a/lib/dpkg/Makefile.am
+++ b/lib/dpkg/Makefile.am
@@ -26,6 +26,7 @@ libdpkg_a_SOURCES = \
dbmodify.c \
dump.c \
ehandle.c \
+ file.c file.h \
fields.c \
i18n.h \
lock.c \
diff --git a/lib/dpkg/file.c b/lib/dpkg/file.c
new file mode 100644
index 0000000..0408844
--- /dev/null
+++ b/lib/dpkg/file.c
@@ -0,0 +1,59 @@
+/*
+ * libdpkg - Debian packaging suite library routines
+ * file.c - file handling functions
+ *
+ * Copyright © 1995 Ian Jackson <ian@chiark.greenend.org.uk>
+ * Copyright © 2008 Guillem Jover <guillem@debian.org>
+ *
+ * This 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 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 dpkg; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <config.h>
+#include <compat.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include <dpkg/file.h>
+#include <dpkg/dpkg.h>
+#include <dpkg/i18n.h>
+
+/*
+ * Copy file ownership and permissions from one file to another.
+ */
+void
+file_copyfileperm(const char *source, const char *target)
+{
+ struct stat stab;
+
+ if (stat(source, &stab) == -1) {
+ if (errno == ENOENT)
+ return;
+ ohshite(_("unable to stat installed file `%.250s'"), source);
+ }
+
+ if (chown(target, stab.st_uid, stab.st_gid) == -1)
+ ohshite(_("unable to change ownership of target file`%.250s'"),
+ target);
+
+ if (chmod(target, (stab.st_mode & 07777)) == -1)
+ ohshite(_("unable to set mode of target file`%.250s'"), target);
+}
+
+/*
+ * vim: noet ts=8
+ */
diff --git a/lib/dpkg/file.h b/lib/dpkg/file.h
new file mode 100644
index 0000000..cb95647
--- /dev/null
+++ b/lib/dpkg/file.h
@@ -0,0 +1,35 @@
+/*
+ * libdpkg - Debian packaging suite library routines
+ * file.h - file handling routines
+ *
+ * Copyright © 2008 Guillem Jover <guillem@debian.org>
+ *
+ * This 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 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 dpkg; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef DPKG_FILE_H
+#define DPKG_FILE_H
+
+#include <dpkg/macros.h>
+
+DPKG_BEGIN_DECLS
+
+/* set permissions on target to equal those of source */
+void file_copyfileperm(const char *source, const char *target);
+
+DPKG_END_DECLS
+
+#endif /* DPKG_FILE_H */
+
diff --git a/src/configure.c b/src/configure.c
index f691046..17bf941 100644
--- a/src/configure.c
+++ b/src/configure.c
@@ -47,6 +47,7 @@
#include <dpkg/dpkg.h>
#include <dpkg/dpkg-db.h>
#include <dpkg/buffer.h>
+#include <dpkg/file.h>
#include "filesdb.h"
#include "main.h"
@@ -58,7 +59,6 @@ static int conffoptcells[2][2] = {
};
static void md5hash(struct pkginfo *pkg, char *hashbuf, const char *fn);
-static void copyfileperm(const char *source, const char *target);
static void showdiff(const char *old, const char *new);
static void suspend(void);
static enum conffopt promptconfaction(const char *cfgfile,
@@ -107,7 +107,7 @@ deferred_configure_conffile(struct pkginfo *pkg, struct conffile *conff)
/* Copy the permissions from the installed version to the new
* distributed version. */
if (!stat(cdr.buf, &stab))
- copyfileperm(cdr.buf, cdr2.buf);
+ file_copyfileperm(cdr.buf, cdr2.buf);
else if (errno != ENOENT)
ohshite(_("unable to stat current installed conffile `%.250s'"),
cdr.buf);
@@ -471,30 +471,6 @@ md5hash(struct pkginfo *pkg, char *hashbuf, const char *fn)
}
/*
- * Copy file ownership and permissions from one file to another.
- */
-static void
-copyfileperm(const char *source, const char *target)
-{
- struct stat stab;
-
- if (stat(source, &stab) == -1) {
- if (errno == ENOENT)
- return;
- ohshite(_("unable to stat current installed conffile `%.250s'"),
- source);
- }
-
- if (chown(target, stab.st_uid, stab.st_gid) == -1)
- ohshite(_("unable to change ownership of new dist conffile `%.250s'"),
- target);
-
- if (chmod(target, (stab.st_mode & 07777)) == -1)
- ohshite(_("unable to set mode of new dist conffile `%.250s'"),
- target);
-}
-
-/*
* Show a diff between two files.
*/
static void
--
1.6.4.3
Reply to: