bug-cpio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-cpio] unable to squash perms while creating a cpio archive


From: Sergey Poznyakoff
Subject: Re: [Bug-cpio] unable to squash perms while creating a cpio archive
Date: Thu, 07 Jun 2007 10:38:24 +0300

Mike Frysinger <address@hidden> ha escrit:

> is there a reason the --owner option is not respected when creating
> archives ?

No, there is not.  

> i'd like to generate a cpio archive and squash all the ownership to a 
> specific uid/gid while doing so but it seems cpio ignores any such
> options in  create mode ...

Please try the enclosed patch.

Regards,
Sergey


Index: src/main.c
===================================================================
RCS file: /cvsroot/cpio/cpio/src/main.c,v
retrieving revision 1.23
diff -p -u -r1.23 main.c
--- src/main.c  18 Dec 2006 11:42:49 -0000      1.23
+++ src/main.c  7 Jun 2007 07:37:24 -0000
@@ -667,7 +667,6 @@ process_args (int argc, char *argv[])
       CHECK_USAGE(retain_time_flag, "--preserve-modification-time",
                  "--create");
       CHECK_USAGE(no_chown_flag, "--no-preserve-owner", "--create");
-      CHECK_USAGE(set_owner_flag||set_group_flag, "--owner", "--create");
       CHECK_USAGE(swap_bytes_flag, "--swap-bytes (--swap)", "--create");
       CHECK_USAGE(swap_halfwords_flag, "--swap-halfwords (--swap)",
                  "--create");
Index: src/util.c
===================================================================
RCS file: /cvsroot/cpio/cpio/src/util.c,v
retrieving revision 1.22
diff -p -u -r1.22 util.c
--- src/util.c  18 Dec 2006 09:49:06 -0000      1.22
+++ src/util.c  7 Jun 2007 07:37:25 -0000
@@ -1205,6 +1205,9 @@ sparse_write (int fildes, char *buf, uns
   return nbyte;
 }
 
+#define CPIO_UID(uid) (set_owner_flag ? set_owner : (uid))
+#define CPIO_GID(gid) (set_group_flag ? set_group : (gid));
+
 void
 stat_to_cpio (struct cpio_file_stat *hdr, struct stat *st)
 {
@@ -1244,8 +1247,8 @@ stat_to_cpio (struct cpio_file_stat *hdr
   else if (S_ISNWK (st->st_mode))
     hdr->c_mode |= CP_IFNWK;
 #endif
-  hdr->c_uid = st->st_uid;
-  hdr->c_gid = st->st_gid;
+  hdr->c_uid = CPIO_UID (st->st_uid);
+  hdr->c_gid = CPIO_GID (st->st_gid);
   hdr->c_nlink = st->st_nlink;
   hdr->c_rdev_maj = major (st->st_rdev);
   hdr->c_rdev_min = minor (st->st_rdev);
@@ -1260,8 +1263,8 @@ set_perms (struct cpio_file_stat *header
 {
   if (!no_chown_flag)
     {
-      uid_t uid = set_owner_flag ? set_owner : header->c_uid;
-      gid_t gid = set_group_flag ? set_group : header->c_gid; 
+      uid_t uid = CPIO_UID (header->c_uid);
+      gid_t gid = CPIO_GID (header->c_gid); 
       if ((chown (header->c_name, uid, gid) < 0) && errno != EPERM)
        chown_error_details (header->c_name, uid, gid);
     }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]