]> git.pld-linux.org Git - packages/cpio.git/blob - cpio-CAN_2005_111.patch
- second version from FC (temporary mask mode with 077 to avoid more chown races...
[packages/cpio.git] / cpio-CAN_2005_111.patch
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
3 @@ -186,7 +186,7 @@
4  \f
5  static int
6  try_existing_file(struct cpio_file_stat* file_hdr, int in_file_des,
7 -                 int *existing_dir)
8 +                 int *existing_dir, mode_t *existing_mode)
9  {
10    struct stat file_stat;
11  
12 @@ -200,6 +200,7 @@
13              we are trying to create, don't complain about
14              it.  */
15           *existing_dir = true;
16 +         *existing_mode = file_stat.st_mode;
17           return 0;
18         }
19        else if (!unconditional_flag
20 @@ -387,10 +388,7 @@
21           continue;
22         }
23  
24 -      if (close (out_file_des) < 0)
25 -       close_error (d->header.c_name);
26 -
27 -      set_perms (&d->header);
28 +      set_perms (&d->header, out_file_des);
29      }
30  }
31  \f
32 @@ -540,8 +538,8 @@
33        write (out_file_des, "", 1);
34        delayed_seek_count = 0;
35      }
36 -  if (close (out_file_des) < 0)
37 -    close_error (file_hdr->c_name);
38 +
39 +  set_perms (file_hdr, out_file_des);
40  
41    if (archive_format == arf_crcascii)
42      {
43 @@ -550,8 +548,6 @@
44                file_hdr->c_name, crc, file_hdr->c_chksum);
45      }
46  
47 -  set_perms (file_hdr);
48 -
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) )
52 @@ -565,7 +561,7 @@
53  }
54  \f
55  static void
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)
58  {
59    int res;                     /* Result of various function calls.  */
60  #ifdef HPUX_CDF
61 @@ -608,14 +604,23 @@
62           cdf_flag = 1;
63         }
64  #endif
65 -      res = mkdir (file_hdr->c_name, file_hdr->c_mode);
66 +      res = mkdir (file_hdr->c_name, file_hdr->c_mode & ~077);
67      }
68    else
69 -    res = 0;
70 +    {
71 +      if (!no_chown_flag && (existing_mode & 077) != 0
72 +         && chmod (file_hdr->c_name, existing_mode & 07700) < 0)
73 +       {
74 +         error (0, errno, "%s: chmod", file_hdr->c_name);
75 +         return;
76 +       }
77 +      res = 0;
78 +    }
79 +
80    if (res < 0 && create_dir_flag)
81      {
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);
85      }
86    if (res < 0)
87      {
88 @@ -643,7 +648,7 @@
89         }
90      }
91  
92 -  set_perms (file_hdr); 
93 +  set_perms (file_hdr, -1); 
94  }
95  \f
96  static void
97 @@ -690,12 +695,12 @@
98        return;
99      }
100    
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)
105      {
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));
110      }
111    if (res < 0)
112 @@ -769,9 +774,10 @@
113  copyin_file (struct cpio_file_stat* file_hdr, int in_file_des)
114  {
115    int existing_dir;
116 +  mode_t existing_mode;
117  
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)
121      return;
122  
123    /* Do the real copy or link.  */
124 @@ -782,7 +788,7 @@
125        break;
126  
127      case CP_IFDIR:
128 -      copyin_directory(file_hdr, existing_dir);
129 +      copyin_directory(file_hdr, existing_dir, existing_mode);
130        break;
131  
132      case CP_IFCHR:
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
135 @@ -34,12 +34,12 @@
136  
137  /* A wrapper around set_perms using another set of arguments */
138  static void
139 -set_copypass_perms (const char *name, struct stat *st)
140 +set_copypass_perms (const char *name, struct stat *st, int file_des)
141  {
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);
147  }
148  
149  /* Copy files listed on the standard input into directory `directory_name'.
150 @@ -194,10 +194,8 @@
151                 }
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);
156  
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);
159  
160               if (reset_time_flag)
161                  {
162 @@ -232,15 +230,24 @@
163                   cdf_flag = 1;
164                 }
165  #endif
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);
168  
169             }
170           else
171 -           res = 0;
172 +            {
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)
175 +                {
176 +                  error (0, errno, "%s: chmod", output_name.ds_string);
177 +                  continue;
178 +                }
179 +              res = 0;
180 +            }
181 +
182           if (res < 0 && create_dir_flag)
183             {
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);
187             }
188           if (res < 0)
189             {
190 @@ -257,7 +264,7 @@
191                   continue;
192                 }
193             }
194 -         set_copypass_perms (output_name.ds_string, &in_file_stat);
195 +         set_copypass_perms (output_name.ds_string, &in_file_stat, -1);
196         }
197        else if (S_ISCHR (in_file_stat.st_mode) ||
198                S_ISBLK (in_file_stat.st_mode) ||
199 @@ -283,12 +290,12 @@
200  
201           if (link_res < 0)
202             {
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)
207                 {
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);
212                 }
213               if (res < 0)
214 @@ -296,7 +303,7 @@
215                   mknod_error (output_name.ds_string);
216                   continue;
217                 }
218 -             set_copypass_perms (output_name.ds_string, &in_file_stat);
219 +             set_copypass_perms (output_name.ds_string, &in_file_stat, -1);
220             }
221         }
222  
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 @@
226  }
227  
228  void
229 -set_perms (struct cpio_file_stat *header)
230 +set_perms (struct cpio_file_stat *header, int file_des)
231  {
232    if (!no_chown_flag)
233      {
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);
239 +      } else {
240 +        if ((fchown (file_des, uid, gid) < 0) && errno != EPERM)
241 +          chown_error_details (header->c_name, uid, gid);
242 +      }
243      }
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);
248 +  } else {
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);
253 +  }
254  #ifdef HPUX_CDF
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
259 @@ -199,7 +199,7 @@
260  # define UMASKED_SYMLINK(name1,name2,mode)    umasked_symlink(name1,name2,mode)
261  #endif /* SYMLINK_USES_UMASK */
262  
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,
This page took 0.058693 seconds and 3 git commands to generate.