]>
Commit | Line | Data |
---|---|---|
c1923c3b | 1 | --- cpio-2.6/src/copyin.c.chmodRaceC 2005-04-25 13:19:34.079310381 +0200 |
2 | +++ cpio-2.6/src/copyin.c 2005-04-25 14:09:32.514889697 +0200 | |
3 | @@ -389,19 +389,26 @@ | |
4 | continue; | |
5 | } | |
6 | ||
7 | - if (close (out_file_des) < 0) | |
8 | - error (0, errno, "%s", d->header.c_name); | |
9 | - | |
10 | + /* | |
11 | + * Avoid race condition. | |
12 | + * Set chown and chmod before closing the file desc. | |
13 | + * pvrabec@redhat.com | |
14 | + */ | |
15 | + | |
16 | /* File is now copied; set attributes. */ | |
17 | if (!no_chown_flag) | |
18 | - if ((chown (d->header.c_name, | |
19 | + if ((fchown (out_file_des, | |
20 | set_owner_flag ? set_owner : d->header.c_uid, | |
21 | set_group_flag ? set_group : d->header.c_gid) < 0) | |
22 | && errno != EPERM) | |
23 | error (0, errno, "%s", d->header.c_name); | |
24 | /* chown may have turned off some permissions we wanted. */ | |
25 | - if (chmod (d->header.c_name, (int) d->header.c_mode) < 0) | |
26 | + if (fchmod (out_file_des, (int) d->header.c_mode) < 0) | |
27 | + error (0, errno, "%s", d->header.c_name); | |
28 | + | |
29 | + if (close (out_file_des) < 0) | |
30 | error (0, errno, "%s", d->header.c_name); | |
31 | + | |
32 | if (retain_time_flag) | |
33 | { | |
34 | times.actime = times.modtime = d->header.c_mtime; | |
35 | @@ -557,6 +564,25 @@ | |
36 | write (out_file_des, "", 1); | |
37 | delayed_seek_count = 0; | |
38 | } | |
39 | + | |
40 | + /* | |
41 | + * Avoid race condition. | |
42 | + * Set chown and chmod before closing the file desc. | |
43 | + * pvrabec@redhat.com | |
44 | + */ | |
45 | + | |
46 | + /* File is now copied; set attributes. */ | |
47 | + if (!no_chown_flag) | |
48 | + if ((fchown (out_file_des, | |
49 | + set_owner_flag ? set_owner : file_hdr->c_uid, | |
50 | + set_group_flag ? set_group : file_hdr->c_gid) < 0) | |
51 | + && errno != EPERM) | |
52 | + error (0, errno, "%s", file_hdr->c_name); | |
53 | + | |
54 | + /* chown may have turned off some permissions we wanted. */ | |
55 | + if (fchmod (out_file_des, (int) file_hdr->c_mode) < 0) | |
56 | + error (0, errno, "%s", file_hdr->c_name); | |
57 | + | |
58 | if (close (out_file_des) < 0) | |
59 | error (0, errno, "%s", file_hdr->c_name); | |
60 | ||
61 | @@ -567,18 +593,6 @@ | |
62 | file_hdr->c_name, crc, file_hdr->c_chksum); | |
63 | } | |
64 | ||
65 | - /* File is now copied; set attributes. */ | |
66 | - if (!no_chown_flag) | |
67 | - if ((chown (file_hdr->c_name, | |
68 | - set_owner_flag ? set_owner : file_hdr->c_uid, | |
69 | - set_group_flag ? set_group : file_hdr->c_gid) < 0) | |
70 | - && errno != EPERM) | |
71 | - error (0, errno, "%s", file_hdr->c_name); | |
72 | - | |
73 | - /* chown may have turned off some permissions we wanted. */ | |
74 | - if (chmod (file_hdr->c_name, (int) file_hdr->c_mode) < 0) | |
75 | - error (0, errno, "%s", file_hdr->c_name); | |
76 | - | |
77 | if (retain_time_flag) | |
78 | { | |
79 | struct utimbuf times; /* For setting file times. */ | |
80 | @@ -589,7 +603,7 @@ | |
81 | if (utime (file_hdr->c_name, ×) < 0) | |
82 | error (0, errno, "%s", file_hdr->c_name); | |
83 | } | |
84 | - | |
85 | + | |
86 | tape_skip_padding (in_file_des, file_hdr->c_filesize); | |
87 | if (file_hdr->c_nlink > 1 | |
88 | && (archive_format == arf_newascii || archive_format == arf_crcascii) ) | |
89 | --- cpio-2.6/src/copypass.c.chmodRaceC 2004-09-06 14:09:04.000000000 +0200 | |
90 | +++ cpio-2.6/src/copypass.c 2005-04-25 14:09:38.135076926 +0200 | |
91 | @@ -181,19 +181,25 @@ | |
92 | } | |
93 | if (close (in_file_des) < 0) | |
94 | error (0, errno, "%s", input_name.ds_string); | |
95 | - if (close (out_file_des) < 0) | |
96 | - error (0, errno, "%s", output_name.ds_string); | |
97 | - | |
98 | + /* | |
99 | + * Avoid race condition. | |
100 | + * Set chown and chmod before closing the file desc. | |
101 | + * pvrabec@redhat.com | |
102 | + */ | |
103 | /* Set the attributes of the new file. */ | |
104 | if (!no_chown_flag) | |
105 | - if ((chown (output_name.ds_string, | |
106 | + if ((fchown (out_file_des, | |
107 | set_owner_flag ? set_owner : in_file_stat.st_uid, | |
108 | set_group_flag ? set_group : in_file_stat.st_gid) < 0) | |
109 | && errno != EPERM) | |
110 | error (0, errno, "%s", output_name.ds_string); | |
111 | /* chown may have turned off some permissions we wanted. */ | |
112 | - if (chmod (output_name.ds_string, in_file_stat.st_mode) < 0) | |
113 | + if (fchmod (out_file_des, in_file_stat.st_mode) < 0) | |
114 | + error (0, errno, "%s", output_name.ds_string); | |
115 | + | |
116 | + if (close (out_file_des) < 0) | |
117 | error (0, errno, "%s", output_name.ds_string); | |
118 | + | |
119 | if (reset_time_flag) | |
120 | { | |
121 | times.actime = in_file_stat.st_atime; |