The following commit has been merged in the master branch:
commit ceb07b08dad4d5eead630064f45c7e7ded00a341
Author: Guillem Jover <[email protected]>
Date: Thu Sep 16 19:52:41 2010 +0200
Refactor file_stat code
Create a new file_stat struct, and use it instead of the
filestatoverride one.
diff --git a/lib/dpkg/file.h b/lib/dpkg/file.h
index ce16c04..f9360d7 100644
--- a/lib/dpkg/file.h
+++ b/lib/dpkg/file.h
@@ -2,7 +2,7 @@
* libdpkg - Debian packaging suite library routines
* file.h - file handling routines
*
- * Copyright © 2008 Guillem Jover <[email protected]>
+ * Copyright © 2008-2010 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 published by
@@ -21,12 +21,21 @@
#ifndef LIBDPKG_FILE_H
#define LIBDPKG_FILE_H
+#include <sys/types.h>
+
#include <stdbool.h>
#include <dpkg/macros.h>
DPKG_BEGIN_DECLS
+struct file_stat {
+ uid_t uid;
+ gid_t gid;
+ mode_t mode;
+ time_t mtime;
+};
+
/*
* Copy file ownership and permissions from one file to another.
*/
diff --git a/lib/dpkg/tarfn.c b/lib/dpkg/tarfn.c
index c5b598d..dd22e20 100644
--- a/lib/dpkg/tarfn.c
+++ b/lib/dpkg/tarfn.c
@@ -180,10 +180,10 @@ DecodeTarHeader(char *block, struct tar_entry *d)
else
d->name = StoC(h->Name, sizeof(h->Name));
d->linkname = StoC(h->LinkName, sizeof(h->LinkName));
- d->mode = get_unix_mode(h);
+ d->stat.mode = get_unix_mode(h);
d->size = (size_t)OtoL(h->Size, sizeof(h->Size));
- d->mtime = (time_t)OtoL(h->ModificationTime,
- sizeof(h->ModificationTime));
+ d->stat.mtime = (time_t)OtoL(h->ModificationTime,
+ sizeof(h->ModificationTime));
d->dev = ((OtoL(h->MajorDevice,
sizeof(h->MajorDevice)) & 0xff) << 8) |
(OtoL(h->MinorDevice, sizeof(h->MinorDevice)) & 0xff);
@@ -191,16 +191,16 @@ DecodeTarHeader(char *block, struct tar_entry *d)
if (*h->UserName)
passwd = getpwnam(h->UserName);
if (passwd)
- d->uid = passwd->pw_uid;
+ d->stat.uid = passwd->pw_uid;
else
- d->uid = (uid_t)OtoL(h->UserID, sizeof(h->UserID));
+ d->stat.uid = (uid_t)OtoL(h->UserID, sizeof(h->UserID));
if (*h->GroupName)
group = getgrnam(h->GroupName);
if (group)
- d->gid = group->gr_gid;
+ d->stat.gid = group->gr_gid;
else
- d->gid = (gid_t)OtoL(h->GroupID, sizeof(h->GroupID));
+ d->stat.gid = (gid_t)OtoL(h->GroupID, sizeof(h->GroupID));
checksum = OtoL(h->Checksum, sizeof(h->Checksum));
diff --git a/lib/dpkg/tarfn.h b/lib/dpkg/tarfn.h
index 0401cb0..2e6a3b4 100644
--- a/lib/dpkg/tarfn.h
+++ b/lib/dpkg/tarfn.h
@@ -3,6 +3,7 @@
* tarfn.h - tar archive extraction functions
*
* Copyright © 1995 Bruce Perens
+ * Copyright © 2009-2010 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 published by
@@ -26,6 +27,8 @@
#include <unistd.h>
#include <stdlib.h>
+#include <dpkg/file.h>
+
#define TARBLKSZ 512
enum tar_format {
@@ -54,11 +57,9 @@ struct tar_entry {
char *name; /* File name */
char *linkname; /* Name for symbolic and hard links */
size_t size; /* Size of file */
- time_t mtime; /* Last-modified time */
- mode_t mode; /* Unix mode, including device bits. */
- uid_t uid; /* Numeric UID */
- gid_t gid; /* Numeric GID */
dev_t dev; /* Special device for mknod() */
+
+ struct file_stat stat;
};
typedef int (*tar_read_func)(void *ctx, char *buffer, int length);
diff --git a/src/archives.c b/src/archives.c
index fdfad13..5103a94 100644
--- a/src/archives.c
+++ b/src/archives.c
@@ -4,6 +4,7 @@
*
* Copyright © 1994,1995 Ian Jackson <[email protected]>
* Copyright © 2000 Wichert Akkerman <[email protected]>
+ * Copyright © 2007-2010 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 published by
@@ -46,6 +47,7 @@
#include <dpkg/buffer.h>
#include <dpkg/subproc.h>
#include <dpkg/command.h>
+#include <dpkg/file.h>
#include <dpkg/tarfn.h>
#include <dpkg/myopt.h>
#include <dpkg/triglib.h>
@@ -231,26 +233,23 @@ does_replace(struct pkginfo *newpigp, struct
pkginfoperfile *newpifp,
}
static void
-newtarobject_utime(const char *path, struct tar_entry *ti)
+newtarobject_utime(const char *path, struct file_stat *st)
{
struct utimbuf utb;
utb.actime= currenttime;
- utb.modtime = ti->mtime;
+ utb.modtime = st->mtime;
if (utime(path,&utb))
- ohshite(_("error setting timestamps of `%.255s'"), ti->name);
+ ohshite(_("error setting timestamps of `%.255s'"), path);
}
static void
-newtarobject_allmodes(const char *path, struct tar_entry *ti,
- struct filestatoverride *statoverride)
+newtarobject_allmodes(const char *path, struct file_stat *st)
{
- if (chown(path,
- statoverride ? statoverride->uid : ti->uid,
- statoverride ? statoverride->gid : ti->gid))
- ohshite(_("error setting ownership of `%.255s'"), ti->name);
- if (chmod(path,(statoverride ? statoverride->mode : ti->mode) & ~S_IFMT))
- ohshite(_("error setting permissions of `%.255s'"), ti->name);
- newtarobject_utime(path,ti);
+ if (chown(path, st->uid, st->gid))
+ ohshite(_("error setting ownership of `%.255s'"), path);
+ if (chmod(path, st->mode & ~S_IFMT))
+ ohshite(_("error setting permissions of `%.255s'"), path);
+ newtarobject_utime(path, st);
}
static void
@@ -419,9 +418,9 @@ tarobject(void *ctx, struct tar_entry *ti)
ssize_t r;
struct stat stab, stabtmp;
char databuf[TARBLKSZ];
+ struct file_stat *st;
struct fileinlist *nifd, **oldnifd;
struct pkginfo *divpkg, *otherpkg;
- mode_t am;
ensureobstackinit();
@@ -436,7 +435,8 @@ tarobject(void *ctx, struct tar_entry *ti)
debug(dbg_eachfile,
"tarobject ti->name='%s' mode=%lo owner=%u.%u type=%d(%c)"
" ti->linkname='%s' namenode='%s' flags=%o instead='%s'",
- ti->name, (long)ti->mode, (unsigned)ti->uid, (unsigned)ti->gid,
+ ti->name, (long)ti->stat.mode,
+ (unsigned)ti->stat.uid, (unsigned)ti->stat.gid,
ti->type,
ti->type >= '0' && ti->type <= '6' ? "-hlcbdp"[ti->type - '0'] : '?',
ti->linkname,
@@ -461,6 +461,11 @@ tarobject(void *ctx, struct tar_entry *ti)
}
}
+ if (nifd->namenode->statoverride)
+ st = nifd->namenode->statoverride;
+ else
+ st = &ti->stat;
+
usenode = namenodetouse(nifd->namenode, tc->pkg);
usename = usenode->name + 1; /* Skip the leading '/'. */
@@ -695,15 +700,9 @@ tarobject(void *ctx, struct tar_entry *ti)
nifd->namenode->statoverride->uid,
nifd->namenode->statoverride->gid,
nifd->namenode->statoverride->mode);
- if (fchown(fd,
- nifd->namenode->statoverride ?
- nifd->namenode->statoverride->uid : ti->uid,
- nifd->namenode->statoverride ?
- nifd->namenode->statoverride->gid : ti->gid))
+ if (fchown(fd, st->uid, st->gid))
ohshite(_("error setting ownership of `%.255s'"), ti->name);
- am = (nifd->namenode->statoverride ?
- nifd->namenode->statoverride->mode : ti->mode) & ~S_IFMT;
- if (fchmod(fd,am))
+ if (fchmod(fd, st->mode & ~S_IFMT))
ohshite(_("error setting permissions of `%.255s'"), ti->name);
/* Postpone the fsync, to try to avoid massive I/O degradation. */
@@ -712,25 +711,25 @@ tarobject(void *ctx, struct tar_entry *ti)
pop_cleanup(ehflag_normaltidy); /* fd= open(fnamenewvb.buf) */
if (close(fd))
ohshite(_("error closing/writing `%.255s'"), ti->name);
- newtarobject_utime(fnamenewvb.buf,ti);
+ newtarobject_utime(fnamenewvb.buf, st);
break;
case tar_filetype_fifo:
if (mkfifo(fnamenewvb.buf,0))
ohshite(_("error creating pipe `%.255s'"), ti->name);
debug(dbg_eachfiledetail, "tarobject fifo");
- newtarobject_allmodes(fnamenewvb.buf,ti, nifd->namenode->statoverride);
+ newtarobject_allmodes(fnamenewvb.buf, st);
break;
case tar_filetype_chardev:
if (mknod(fnamenewvb.buf, S_IFCHR, ti->dev))
ohshite(_("error creating device `%.255s'"), ti->name);
debug(dbg_eachfiledetail, "tarobject chardev");
- newtarobject_allmodes(fnamenewvb.buf,ti, nifd->namenode->statoverride);
+ newtarobject_allmodes(fnamenewvb.buf, st);
break;
case tar_filetype_blockdev:
if (mknod(fnamenewvb.buf, S_IFBLK, ti->dev))
ohshite(_("error creating device `%.255s'"), ti->name);
debug(dbg_eachfiledetail, "tarobject blockdev");
- newtarobject_allmodes(fnamenewvb.buf,ti, nifd->namenode->statoverride);
+ newtarobject_allmodes(fnamenewvb.buf, st);
break;
case tar_filetype_hardlink:
varbufreset(&hardlinkfn);
@@ -743,18 +742,14 @@ tarobject(void *ctx, struct tar_entry *ti)
if (link(hardlinkfn.buf,fnamenewvb.buf))
ohshite(_("error creating hard link `%.255s'"), ti->name);
debug(dbg_eachfiledetail, "tarobject hardlink");
- newtarobject_allmodes(fnamenewvb.buf,ti, nifd->namenode->statoverride);
+ newtarobject_allmodes(fnamenewvb.buf, st);
break;
case tar_filetype_symlink:
/* We've already cheched for an existing directory. */
if (symlink(ti->linkname, fnamenewvb.buf))
ohshite(_("error creating symbolic link `%.255s'"), ti->name);
debug(dbg_eachfiledetail, "tarobject symlink creating");
- if (lchown(fnamenewvb.buf,
- nifd->namenode->statoverride ?
- nifd->namenode->statoverride->uid : ti->uid,
- nifd->namenode->statoverride ?
- nifd->namenode->statoverride->gid : ti->gid))
+ if (lchown(fnamenewvb.buf, st->uid, st->gid))
ohshite(_("error setting ownership of symlink `%.255s'"), ti->name);
break;
case tar_filetype_dir:
@@ -762,13 +757,13 @@ tarobject(void *ctx, struct tar_entry *ti)
if (mkdir(fnamenewvb.buf,0))
ohshite(_("error creating directory `%.255s'"), ti->name);
debug(dbg_eachfiledetail, "tarobject directory creating");
- newtarobject_allmodes(fnamenewvb.buf,ti,nifd->namenode->statoverride);
+ newtarobject_allmodes(fnamenewvb.buf, st);
break;
default:
internerr("unknown tar type '%d', but already checked", ti->type);
}
- set_selinux_path_context(fnamevb.buf, fnamenewvb.buf, ti->mode);
+ set_selinux_path_context(fnamevb.buf, fnamenewvb.buf, st->mode);
/* CLEANUP: Now we have extracted the new object in .dpkg-new (or,
* if the file already exists as a directory and we were trying to extract
diff --git a/src/filesdb.h b/src/filesdb.h
index 7d2645c..44a2c85 100644
--- a/src/filesdb.h
+++ b/src/filesdb.h
@@ -3,6 +3,7 @@
* filesdb.h - management of database of files installed on system
*
* Copyright © 1995 Ian Jackson <[email protected]>
+ * Copyright © 2008-2010 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 published by
@@ -21,6 +22,8 @@
#ifndef FILESDB_H
#define FILESDB_H
+#include <dpkg/file.h>
+
/*
* Data structure here is as follows:
*
@@ -57,7 +60,14 @@ struct filenamenode {
const char *name;
struct filepackages *packages;
struct diversion *divert;
- struct filestatoverride *statoverride;
+
+ /* We allow the administrator to override the owner, group and mode of
+ * a file. If such an override is present we use that instead of the
+ * stat information stored in the archive.
+ *
+ * This functionality used to be in the suidmanager package. */
+ struct file_stat *statoverride;
+
/* Fields from here on are used by archives.c &c, and cleared by
* filesdbinit.
*/
@@ -83,18 +93,6 @@ struct fileinlist {
struct filenamenode *namenode;
};
-struct filestatoverride {
- /* We allow the administrator to override the owner, group and mode of
- * a file. If such an override is present we use that instead of the
- * stat information stored in the archive.
- *
- * This functionality used to be in the suidmanager package.
- */
- uid_t uid;
- gid_t gid;
- mode_t mode;
-};
-
struct diversion {
/* When we deal with an `overridden' file, every package except
* the overriding one is considered to contain the other file
diff --git a/src/statcmd.c b/src/statcmd.c
index 42aad13..337e351 100644
--- a/src/statcmd.c
+++ b/src/statcmd.c
@@ -2,7 +2,7 @@
* dpkg-statoverride - override ownership and mode of files
*
* Copyright © 2000, 2001 Wichert Akkerman <[email protected]>
- * Copyright © 2006-2009 Guillem Jover <[email protected]>
+ * Copyright © 2006-2010 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 published by
@@ -128,10 +128,10 @@ path_cleanup(const char *path)
return new_path;
}
-static struct filestatoverride *
+static struct file_stat *
statdb_node_new(const char *user, const char *group, const char *mode)
{
- struct filestatoverride *filestat;
+ struct file_stat *filestat;
filestat = nfmalloc(sizeof(*filestat));
@@ -142,7 +142,7 @@ statdb_node_new(const char *user, const char *group, const
char *mode)
return filestat;
}
-static struct filestatoverride **
+static struct file_stat **
statdb_node_find(const char *filename)
{
struct filenamenode *file;
@@ -167,7 +167,7 @@ statdb_node_remove(const char *filename)
}
static void
-statdb_node_apply(const char *filename, struct filestatoverride *filestat)
+statdb_node_apply(const char *filename, struct file_stat *filestat)
{
if (chown(filename, filestat->uid, filestat->gid) < 0)
ohshite(_("error setting ownership of `%.255s'"), filename);
@@ -178,7 +178,7 @@ statdb_node_apply(const char *filename, struct
filestatoverride *filestat)
static void
statdb_node_print(FILE *out, struct filenamenode *file)
{
- struct filestatoverride *filestat = file->statoverride;
+ struct file_stat *filestat = file->statoverride;
struct passwd *pw;
struct group *gr;
@@ -260,7 +260,7 @@ statoverride_add(const char *const *argv)
const char *mode = argv[2];
const char *path = argv[3];
char *filename;
- struct filestatoverride **filestat;
+ struct file_stat **filestat;
if (!user || !group || !mode || !path || argv[4])
badusage(_("--add needs four arguments"));
diff --git a/src/statdb.c b/src/statdb.c
index 6ff02ae..adeaef0 100644
--- a/src/statdb.c
+++ b/src/statdb.c
@@ -4,6 +4,7 @@
*
* Copyright © 1995 Ian Jackson <[email protected]>
* Copyright © 2000, 2001 Wichert Akkerman <[email protected]>
+ * Copyright © 2008-2010 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 published by
@@ -112,7 +113,7 @@ ensure_statoverrides(void)
struct stat stab1, stab2;
FILE *file;
char *loaded_list, *loaded_list_end, *thisline, *nextline, *ptr;
- struct filestatoverride *fso;
+ struct file_stat *fso;
struct filenamenode *fnn;
varbufreset(&vb);
@@ -164,7 +165,7 @@ ensure_statoverrides(void)
thisline = loaded_list;
while (thisline < loaded_list_end) {
- fso = nfmalloc(sizeof(struct filestatoverride));
+ fso = nfmalloc(sizeof(struct file_stat));
if (!(ptr = memchr(thisline, '\n', loaded_list_end - thisline)))
ohshit(_("statoverride file is missing final newline"));
--
dpkg's main repository
--
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]