The following commit has been merged in the master branch:
commit 4a256f2cd3f80203edc4ec6bb49ff7664a580dcd
Author: Sean Finney <[email protected]>
Date:   Mon Sep 28 23:34:29 2009 +0200

    libdpkg: Move copyfileperms to non-static file_copy_perms
    
    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
    opportunity 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.
    
    Signed-off-by: Guillem Jover <[email protected]>

diff --git a/lib/dpkg/Makefile.am b/lib/dpkg/Makefile.am
index 09cd900..4b31209 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/cleanup.c b/lib/dpkg/file.c
similarity index 58%
copy from lib/dpkg/cleanup.c
copy to lib/dpkg/file.c
index d7afe63..c69e34b 100644
--- a/lib/dpkg/cleanup.c
+++ b/lib/dpkg/file.c
@@ -1,8 +1,9 @@
 /*
  * libdpkg - Debian packaging suite library routines
- * cleanup.c - cleanup functions, used when we need to unwind
+ * file.c - file handling functions
  *
  * Copyright © 1995 Ian Jackson <[email protected]>
+ * Copyright © 2008 Guillem Jover <[email protected]>
  *
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as
@@ -22,42 +23,31 @@
 #include <config.h>
 #include <compat.h>
 
-#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
 #include <unistd.h>
-#include <dirent.h>
 
 #include <dpkg/dpkg.h>
+#include <dpkg/i18n.h>
+#include <dpkg/file.h>
 
 void
-cu_closepipe(int argc, void **argv)
+file_copy_perms(const char *src, const char *dst)
 {
-       int *p1 = (int *)argv[0];
+       struct stat stab;
 
-       close(p1[0]);
-       close(p1[1]);
-}
-
-void
-cu_closefile(int argc, void **argv)
-{
-       FILE *f = (FILE *)(argv[0]);
+       if (stat(src, &stab) == -1) {
+               if (errno == ENOENT)
+                       return;
+               ohshite(_("unable to stat source file '%.250s'"), src);
+       }
 
-       fclose(f);
-}
-
-void
-cu_closedir(int argc, void **argv)
-{
-       DIR *d = (DIR *)(argv[0]);
-
-       closedir(d);
-}
-
-void
-cu_closefd(int argc, void **argv)
-{
-       int ip = *(int *)argv[0];
+       if (chown(dst, stab.st_uid, stab.st_gid) == -1)
+               ohshite(_("unable to change ownership of target file '%.250s'"),
+                       dst);
 
-       close(ip);
+       if (chmod(dst, (stab.st_mode & 07777)) == -1)
+               ohshite(_("unable to set mode of target file '%.250s'"), dst);
 }
 
diff --git a/lib/dpkg/i18n.h b/lib/dpkg/file.h
similarity index 78%
copy from lib/dpkg/i18n.h
copy to lib/dpkg/file.h
index 8b9ab78..e4ecd10 100644
--- a/lib/dpkg/i18n.h
+++ b/lib/dpkg/file.h
@@ -1,6 +1,6 @@
 /*
  * libdpkg - Debian packaging suite library routines
- * i18n.h - i18n support
+ * file.h - file handling routines
  *
  * Copyright © 2008 Guillem Jover <[email protected]>
  *
@@ -19,18 +19,19 @@
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
-#ifndef DPKG_I18N_H
-#define DPKG_I18N_H
+#ifndef DPKG_FILE_H
+#define DPKG_FILE_H
 
 #include <dpkg/macros.h>
 
 DPKG_BEGIN_DECLS
 
-#include <gettext.h>
-
-#define _(str) gettext(str)
-#define N_(str) gettext_noop(str)
+/*
+ * Copy file ownership and permissions from one file to another.
+ */
+void file_copy_perms(const char *src, const char *dst);
 
 DPKG_END_DECLS
 
-#endif /* DPKG_I18N_H */
+#endif /* DPKG_FILE_H */
+
diff --git a/src/configure.c b/src/configure.c
index 5971dca..1043aed 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,
@@ -108,7 +108,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_copy_perms(cdr.buf, cdr2.buf);
        else if (errno != ENOENT)
                ohshite(_("unable to stat current installed conffile `%.250s'"),
                        cdr.buf);
@@ -465,30 +465,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

-- 
dpkg's main repository


-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to