1 --- cpio-2.7/src/copyin.c.orig 2006-09-27 10:19:44.000000000 +0200
2 +++ cpio-2.7/src/copyin.c 2006-10-28 19:54:08.474959250 +0200
6 try_existing_file(struct cpio_file_stat* file_hdr, int in_file_des,
8 + int *existing_dir, mode_t *existing_mode)
10 struct stat file_stat;
13 we are trying to create, don't complain about
16 + *existing_mode = file_stat.st_mode;
19 else if (!unconditional_flag
24 - if (close (out_file_des) < 0)
25 - close_error (d->header.c_name);
27 - set_perms (&d->header);
28 + set_perms (&d->header, out_file_des);
33 write (out_file_des, "", 1);
34 delayed_seek_count = 0;
36 - if (close (out_file_des) < 0)
37 - close_error (file_hdr->c_name);
39 + set_perms (file_hdr, out_file_des);
41 if (archive_format == arf_crcascii)
44 file_hdr->c_name, crc, file_hdr->c_chksum);
47 - set_perms (file_hdr);
49 tape_skip_padding (in_file_des, file_hdr->c_filesize);
50 if (file_hdr->c_nlink > 1
51 && (archive_format == arf_newascii || archive_format == arf_crcascii) )
56 -copyin_directory(struct cpio_file_stat* file_hdr, int existing_dir)
57 +copyin_directory(struct cpio_file_stat* file_hdr, int existing_dir, mode_t existing_mode)
59 int res; /* Result of various function calls. */
65 - res = mkdir (file_hdr->c_name, file_hdr->c_mode);
66 + res = mkdir (file_hdr->c_name, file_hdr->c_mode & ~077);
71 + if (!no_chown_flag && (existing_mode & 077) != 0
72 + && chmod (file_hdr->c_name, existing_mode & 07700) < 0)
74 + error (0, errno, "%s: chmod", file_hdr->c_name);
80 if (res < 0 && create_dir_flag)
82 create_all_directories (file_hdr->c_name);
83 - res = mkdir (file_hdr->c_name, file_hdr->c_mode);
84 + res = mkdir (file_hdr->c_name, file_hdr->c_mode & ~077);
92 - set_perms (file_hdr);
93 + set_perms (file_hdr, -1);
101 - res = mknod (file_hdr->c_name, file_hdr->c_mode,
102 + res = mknod (file_hdr->c_name, file_hdr->c_mode & ~077,
103 makedev (file_hdr->c_rdev_maj, file_hdr->c_rdev_min));
104 if (res < 0 && create_dir_flag)
106 create_all_directories (file_hdr->c_name);
107 - res = mknod (file_hdr->c_name, file_hdr->c_mode,
108 + res = mknod (file_hdr->c_name, file_hdr->c_mode & ~077,
109 makedev (file_hdr->c_rdev_maj, file_hdr->c_rdev_min));
113 copyin_file (struct cpio_file_stat* file_hdr, int in_file_des)
116 + mode_t existing_mode;
118 if (!to_stdout_option
119 - && try_existing_file (file_hdr, in_file_des, &existing_dir) < 0)
120 + && try_existing_file (file_hdr, in_file_des, &existing_dir, &existing_mode) < 0)
123 /* Do the real copy or link. */
128 - copyin_directory(file_hdr, existing_dir);
129 + copyin_directory(file_hdr, existing_dir, existing_mode);
133 --- cpio-2.7/src/copypass.c.orig 2006-09-27 10:19:43.000000000 +0200
134 +++ cpio-2.7/src/copypass.c 2006-10-28 20:07:38.341572750 +0200
137 /* A wrapper around set_perms using another set of arguments */
139 -set_copypass_perms (const char *name, struct stat *st)
140 +set_copypass_perms (const char *name, struct stat *st, int file_des)
142 struct cpio_file_stat header;
143 header.c_name = name;
144 stat_to_cpio (&header, st);
145 - set_perms (&header);
146 + set_perms (&header, file_des);
149 /* Copy files listed on the standard input into directory `directory_name'.
152 if (close (in_file_des) < 0)
153 close_error (input_name.ds_string);
154 - if (close (out_file_des) < 0)
155 - close_error (output_name.ds_string);
157 - set_copypass_perms (input_name.ds_string, &in_file_stat);
158 + set_copypass_perms (output_name.ds_string, &in_file_stat, out_file_des);
162 @@ -232,15 +230,24 @@
166 - res = mkdir (output_name.ds_string, in_file_stat.st_mode);
167 + res = mkdir (output_name.ds_string, in_file_stat.st_mode & ~077);
173 + if (!no_chown_flag && (out_file_stat.st_mode & 077) != 0
174 + && chmod (output_name.ds_string, out_file_stat.st_mode & 07700) < 0)
176 + error (0, errno, "%s: chmod", output_name.ds_string);
182 if (res < 0 && create_dir_flag)
184 create_all_directories (output_name.ds_string);
185 - res = mkdir (output_name.ds_string, in_file_stat.st_mode);
186 + res = mkdir (output_name.ds_string, in_file_stat.st_mode & ~077);
194 - set_copypass_perms (output_name.ds_string, &in_file_stat);
195 + set_copypass_perms (output_name.ds_string, &in_file_stat, -1);
197 else if (S_ISCHR (in_file_stat.st_mode) ||
198 S_ISBLK (in_file_stat.st_mode) ||
199 @@ -283,12 +290,12 @@
203 - res = mknod (output_name.ds_string, in_file_stat.st_mode,
204 + res = mknod (output_name.ds_string, in_file_stat.st_mode & ~077,
205 in_file_stat.st_rdev);
206 if (res < 0 && create_dir_flag)
208 create_all_directories (output_name.ds_string);
209 - res = mknod (output_name.ds_string, in_file_stat.st_mode,
210 + res = mknod (output_name.ds_string, in_file_stat.st_mode & ~077,
211 in_file_stat.st_rdev);
215 mknod_error (output_name.ds_string);
218 - set_copypass_perms (output_name.ds_string, &in_file_stat);
219 + set_copypass_perms (output_name.ds_string, &in_file_stat, -1);
223 --- cpio-2.7/src/util.c.orig 2006-09-28 10:49:21.000000000 +0200
224 +++ cpio-2.7/src/util.c 2006-10-28 19:35:33.753293500 +0200
225 @@ -1251,18 +1251,30 @@
229 -set_perms (struct cpio_file_stat *header)
230 +set_perms (struct cpio_file_stat *header, int file_des)
234 uid_t uid = set_owner_flag ? set_owner : header->c_uid;
235 gid_t gid = set_group_flag ? set_group : header->c_gid;
236 + if (file_des == -1) {
237 if ((chown (header->c_name, uid, gid) < 0) && errno != EPERM)
238 chown_error_details (header->c_name, uid, gid);
240 + if ((fchown (file_des, uid, gid) < 0) && errno != EPERM)
241 + chown_error_details (header->c_name, uid, gid);
244 /* chown may have turned off some permissions we wanted. */
245 + if (file_des == -1) {
246 if (chmod (header->c_name, header->c_mode) < 0)
247 chmod_error_details (header->c_name, header->c_mode);
249 + if (fchmod (file_des, header->c_mode) < 0)
250 + chmod_error_details (header->c_name, header->c_mode);
251 + if (close (file_des) < 0)
252 + close_error (header->c_name);
255 if ((header->c_mode & CP_IFMT) && cdf_flag)
256 /* Once we "hide" the directory with the chmod(),
257 --- cpio-2.7/src/extern.h.orig 2006-09-27 10:19:44.000000000 +0200
258 +++ cpio-2.7/src/extern.h 2006-10-28 20:08:47.861917500 +0200
260 # define UMASKED_SYMLINK(name1,name2,mode) umasked_symlink(name1,name2,mode)
261 #endif /* SYMLINK_USES_UMASK */
263 -void set_perms (struct cpio_file_stat *header);
264 +void set_perms (struct cpio_file_stat *header, int file_des);
265 void set_file_times (const char *name, unsigned long atime, unsigned long mtime);
266 void stat_to_cpio (struct cpio_file_stat *hdr, struct stat *st);
267 void cpio_safer_name_suffix (char *name, bool link_target,