]> git.pld-linux.org Git - packages/coreutils.git/blob - coreutils-acl-0.8.25.patch
af8a77b55093c5a297c056b2449a21d56b7e0491
[packages/coreutils.git] / coreutils-acl-0.8.25.patch
1 diff -urN coreutils-4.5.10.org/configure.ac coreutils-4.5.10/configure.ac
2 --- coreutils-4.5.10.org/configure.ac   Mon Mar 24 16:29:50 2003
3 +++ coreutils-4.5.10/configure.ac       Mon Mar 24 16:31:35 2003
4 @@ -257,6 +257,8 @@
5  AM_GNU_GETTEXT([external], [need-ngettext])
6  AM_GNU_GETTEXT_VERSION(0.11.5)
7  
8 +ag_POSIX_ACL
9 +
10  # just in case we want PAM
11  AC_SUBST(LIB_PAM)
12  # with PAM su doesn't need libcrypt
13 diff -urN coreutils-4.5.10.org/lib/acl.c coreutils-4.5.10/lib/acl.c
14 --- coreutils-4.5.10.org/lib/acl.c      Mon Mar 24 16:29:46 2003
15 +++ coreutils-4.5.10/lib/acl.c  Mon Mar 24 16:30:58 2003
16 @@ -22,6 +22,13 @@
17  # include <config.h>
18  #endif
19  
20 +#if ENABLE_NLS
21 +# include <libintl.h>
22 +# define _(Text) gettext (Text)
23 +#else
24 +# define _(Text) Text
25 +#endif
26 +
27  #include <sys/stat.h>
28  #ifndef S_ISLNK
29  # define S_ISLNK(Mode) 0
30 @@ -33,6 +40,9 @@
31  #ifndef ENOSYS
32  # define ENOSYS (-1)
33  #endif
34 +#ifndef ENOTSUP
35 +# define ENOTSUP (-1)
36 +#endif
37  
38  #ifndef MIN_ACL_ENTRIES
39  # define MIN_ACL_ENTRIES 4
40 @@ -44,19 +54,201 @@
41  int
42  file_has_acl (char const *path, struct stat const *pathstat)
43  {
44 -  /* FIXME: This implementation should work on recent-enough versions
45 -     of HP-UX, Solaris, and Unixware, but it simply returns 0 with
46 -     POSIX 1003.1e (draft 17 -- abandoned), AIX, GNU/Linux, Irix, and
47 -     Tru64.  Please see Samba's source/lib/sysacls.c file for
48 -     fix-related ideas.  */
49 -
50  #if HAVE_ACL && defined GETACLCNT
51 +  /* This implementation should work on recent-enough versions of HP-UX,
52 +     Solaris, and Unixware.  */
53 +
54    if (! S_ISLNK (pathstat->st_mode))
55      {
56        int n = acl (path, GETACLCNT, 0, NULL);
57        return n < 0 ? (errno == ENOSYS ? 0 : -1) : (MIN_ACL_ENTRIES < n);
58      }
59 +#elif HAVE_ACL_EXTENDED_FILE
60 +
61 +  /* Linux specific.  */
62 +
63 +  if (! S_ISLNK (pathstat->st_mode))
64 +    {
65 +      int ret = acl_extended_file (path);
66 +      if (ret < 0)
67 +       return (errno == ENOSYS || errno == ENOTSUP) ? 0 : -1;
68 +      return ret;
69 +    }
70 +#else
71 +  /* FIXME: Add support for AIX, Irix, and Tru64, FreeBSD, etc.
72 +     Please see Samba's source/lib/sysacls.c file for fix-related ideas.  */
73 +#endif
74 +
75 +  return 0;
76 +}
77 +
78 +/* Copy the permissions from SRC_PATH to DST_PATH, including access control
79 +   lists on systems where this is supported. MODE is the file mode for
80 +   DST_PATH, including the file type.
81 +   Also sets special bits in MODE on DST_PATH.  */
82 +
83 +int
84 +copy_acl (char const *src_path, char const *dst_path, mode_t mode)
85 +{
86 +#if HAVE_ACL_GET_FILE && HAVE_ACL_SET_FILE && HAVE_ACL_FREE && \
87 +    HAVE_ACL_ENTRIES
88 +
89 +  /* Linux specific. Will work on all POSIX 1003.1e draft 17 (abandoned)
90 +     compliant systems if the acl_entries() function is implemented.  */
91 +
92 +  acl_t acl = acl_get_file (src_path, ACL_TYPE_ACCESS);
93 +  if (acl == NULL)
94 +    {
95 +      if (errno == ENOSYS || errno == ENOTSUP)
96 +       return set_acl (dst_path, mode);
97 +      else
98 +        {
99 +         error (0, errno, "%s", quote (src_path));
100 +         return -1;
101 +       }
102 +    }
103 +
104 +  if (acl_set_file (dst_path, ACL_TYPE_ACCESS, acl))
105 +    {
106 +      int saved_errno = errno;
107 +
108 +      if (errno == ENOSYS || errno == ENOTSUP)
109 +        {
110 +         int n = acl_entries (acl);
111 +
112 +         acl_free (acl);
113 +         if (n == 3)
114 +           {
115 +             if (chmod (dst_path, mode))
116 +               saved_errno = errno;
117 +             else
118 +               return 0;
119 +           }
120 +         else
121 +           chmod (dst_path, mode);
122 +       }
123 +      else
124 +       {
125 +         acl_free (acl);
126 +         chmod (dst_path, mode);
127 +       }
128 +      error (0, saved_errno, _("preserving permissions for %s"),
129 +            quote (dst_path));
130 +      return -1;
131 +    }
132 +  acl_free (acl);
133 +
134 +  if (mode & (S_ISUID | S_ISGID | S_ISVTX))
135 +    {
136 +      /* We did not call chmod so far, so the special bits have not yet
137 +         been set.  */
138 +
139 +      if (chmod (dst_path, mode))
140 +       {
141 +         error (0, errno, _("preserving permissions for %s"),
142 +                quote (dst_path));
143 +         return -1;
144 +       }
145 +    }
146 +
147 +  if (S_ISDIR (mode))
148 +    {
149 +      acl = acl_get_file (src_path, ACL_TYPE_DEFAULT);
150 +      if (acl == NULL)
151 +       {
152 +         error (0, errno, "%s", quote (src_path));
153 +         return -1;
154 +       }
155 +
156 +      if (acl_set_file (dst_path, ACL_TYPE_DEFAULT, acl))
157 +       {
158 +         error (0, errno, _("preserving permissions for %s"),
159 +                quote (dst_path));
160 +         acl_free(acl);
161 +         return -1;
162 +       }
163 +      else
164 +        acl_free(acl);
165 +    }
166 +  return 0;
167 +#else
168 +  int ret = chmod (dst_path, mode);
169 +  if (ret)
170 +    error (0, errno, _("preserving permissions for %s"), quote (dst_path));
171 +  return ret;
172  #endif
173 +}
174 +
175 +/* Set the permissions of PATH, overwriting access control lists, on systems
176 +   where this is supported. MODE is the file mode for PATH, including the
177 +   file type. Also sets special bits in MODE on PATH.  */
178  
179 +int
180 +set_acl (char const *path, mode_t mode)
181 +{
182 +#if HAVE_ACL_FROM_TEXT && HAVE_ACL_SET_FILE && HAVE_ACL_FREE && \
183 +       HAVE_ACL_DELETE_DEF_FILE
184 +  char acl_text[] = "u::---,g::---,o::---";
185 +  acl_t acl;
186 +
187 +  if (mode & S_IRUSR) acl_text[ 3] = 'r';
188 +  if (mode & S_IWUSR) acl_text[ 4] = 'w';
189 +  if (mode & S_IXUSR) acl_text[ 5] = 'x';
190 +  if (mode & S_IRGRP) acl_text[10] = 'r';
191 +  if (mode & S_IWGRP) acl_text[11] = 'w';
192 +  if (mode & S_IXGRP) acl_text[12] = 'x';
193 +  if (mode & S_IROTH) acl_text[17] = 'r';
194 +  if (mode & S_IWOTH) acl_text[18] = 'w';
195 +  if (mode & S_IXOTH) acl_text[19] = 'x';
196 +
197 +  acl = acl_from_text(acl_text);
198 +  if (!acl)
199 +    {
200 +      error (0, errno, "%s", quote (path));
201 +      return -1;
202 +    }
203 +
204 +  if (acl_set_file(path, ACL_TYPE_ACCESS, acl))
205 +    {
206 +      int saved_errno = errno;
207 +      acl_free (acl);
208 +
209 +      if (errno == ENOTSUP || errno == ENOSYS)
210 +       {
211 +         if (chmod (path, mode))
212 +           saved_errno = errno;
213 +         else
214 +           return 0;
215 +       }
216 +      error (0, saved_errno, _("setting permissions for %s"), quote (path));
217 +      return -1;
218 +    }
219 +  acl_free (acl);
220 +
221 +  if (mode & (S_ISUID | S_ISGID | S_ISVTX))
222 +    {
223 +      /* We did not call chmod so far, so the special bits have not yet
224 +         been set.  */
225 +
226 +      if (chmod (path, mode))
227 +       {
228 +         error (0, errno, _("preserving permissions for %s"),
229 +                quote (path));
230 +         return -1;
231 +       }
232 +    }
233 +
234 +  if (S_ISDIR (mode) && acl_delete_def_file (path))
235 +    {
236 +      error (0, errno, _("setting permissions for %s"), quote (path));
237 +      return -1;
238 +    }
239    return 0;
240 +#else
241 +  int ret = chmod (path, mode);
242 +  if (ret)
243 +    error (0, errno, _("setting permissions for %s"), quote (path));
244 +  return ret;
245 +#endif
246  }
247 +
248 diff -urN coreutils-4.5.10.org/lib/acl.h coreutils-4.5.10/lib/acl.h
249 --- coreutils-4.5.10.org/lib/acl.h      Mon Mar 24 16:29:46 2003
250 +++ coreutils-4.5.10/lib/acl.h  Mon Mar 24 16:30:58 2003
251 @@ -18,7 +18,7 @@
252  
253     Written by Paul Eggert.  */
254  
255 -#if HAVE_SYS_ACL_H && HAVE_ACL
256 +#if HAVE_SYS_ACL_H
257  # include <sys/acl.h>
258  #endif
259  #if ! defined GETACLCNT && defined ACL_CNT
260 @@ -26,3 +26,5 @@
261  #endif
262  
263  int file_has_acl (char const *, struct stat const *);
264 +int copy_acl (char const *, char const *, mode_t);
265 +int set_acl (char const *, mode_t);
266 diff -urN coreutils-4.5.10.org/m4/Makefile.am coreutils-4.5.10/m4/Makefile.am
267 --- coreutils-4.5.10.org/m4/Makefile.am Mon Mar 24 16:29:47 2003
268 +++ coreutils-4.5.10/m4/Makefile.am     Mon Mar 24 16:30:58 2003
269 @@ -62,6 +62,7 @@
270  onceonly.m4 \
271  open-max.m4 \
272  perl.m4 \
273 +posix_acl.m4 \
274  prereq.m4 \
275  progtest.m4 \
276  putenv.m4 \
277 diff -urN coreutils-4.5.10.org/m4/posix_acl.m4 coreutils-4.5.10/m4/posix_acl.m4
278 --- coreutils-4.5.10.org/m4/posix_acl.m4        Thu Jan  1 01:00:00 1970
279 +++ coreutils-4.5.10/m4/posix_acl.m4    Mon Mar 24 16:30:58 2003
280 @@ -0,0 +1,24 @@
281 +#serial 1
282 +
283 +dnl Written by Andreas Gruenbacher <a.gruenbacher@computer.org>.
284 +
285 +dnl Posix 1003.1e draft standard 17 (abandoned) and similar
286 +dnl access control list support
287 +AC_DEFUN([ag_POSIX_ACL],
288 +[
289 +  save_LIBS="$LIBS"
290 +  AC_CHECK_HEADERS(sys/acl.h)
291 +  AC_CHECK_LIB(acl, main)
292 +  AC_CHECK_FUNCS(acl_get_file acl_set_file acl_free acl_to_text \
293 +                 acl_from_text acl_delete_def_file)
294 +  # Linux specific extensions:
295 +  AC_CHECK_FUNCS(acl_entries acl_extended_file)
296 +  LIBS="$save_LIBS"
297 +
298 +  LIBACL=
299 +  if test $ac_cv_header_sys_acl_h = yes; then
300 +    AC_DEFINE(USE_ACL, 1, [Define if you want access control list support.])
301 +    LIBACL="-lacl"
302 +  fi
303 +  AC_SUBST(LIBACL)
304 +])
305 diff -urN coreutils-4.5.10.org/src/copy.c coreutils-4.5.10/src/copy.c
306 --- coreutils-4.5.10.org/src/copy.c     Mon Mar 24 16:29:46 2003
307 +++ coreutils-4.5.10/src/copy.c Mon Mar 24 16:30:58 2003
308 @@ -99,26 +99,6 @@
309  /* The invocation name of this program.  */
310  extern char *program_name;
311  
312 -/* Encapsulate selection of the file mode to be applied to
313 -   new non-directories.  */
314 -
315 -static mode_t
316 -get_dest_mode (const struct cp_options *option, mode_t mode)
317 -{
318 -  /* In some applications (e.g., install), use precisely the
319 -     specified mode.  */
320 -  if (option->set_mode)
321 -    return option->mode;
322 -
323 -  /* Honor the umask for `cp', but not for `mv' or `cp -p'.
324 -     In addition, `cp' without -p must clear the set-user-ID and set-group-ID
325 -     bits.  POSIX requires it do that when creating new files.  */
326 -  if (!option->move_mode && !option->preserve_mode)
327 -    mode &= (option->umask_kill & ~(S_ISUID | S_ISGID));
328 -
329 -  return mode;
330 -}
331 -
332  /* FIXME: describe */
333  /* FIXME: rewrite this to use a hash table so we avoid the quadratic
334     performance hit that's probably noticeable only on trees deeper
335 @@ -792,13 +772,13 @@
336    struct stat src_sb;
337    struct stat dst_sb;
338    mode_t src_mode;
339 -  mode_t src_type;
340 +  mode_t dst_mode;
341    char *earlier_file = NULL;
342    char *dst_backup = NULL;
343    int backup_succeeded = 0;
344    int delayed_fail;
345    int copied_as_regular = 0;
346 -  int ran_chown = 0;
347 +  int dst_mode_valid = 0;
348    int preserve_metadata;
349  
350    if (x->move_mode && rename_succeeded)
351 @@ -811,11 +791,9 @@
352        return 1;
353      }
354  
355 -  src_type = src_sb.st_mode;
356 -
357    src_mode = src_sb.st_mode;
358  
359 -  if (S_ISDIR (src_type) && !x->recursive)
360 +  if (S_ISDIR (src_mode) && !x->recursive)
361      {
362        error (0, 0, _("omitting directory %s"), quote (src_path));
363        return 1;
364 @@ -870,7 +848,7 @@
365  
366           if (!S_ISDIR (dst_sb.st_mode))
367             {
368 -             if (S_ISDIR (src_type))
369 +             if (S_ISDIR (src_mode))
370                 {
371                   error (0, 0,
372                      _("cannot overwrite non-directory %s with directory %s"),
373 @@ -896,7 +874,7 @@
374                 }
375             }
376  
377 -         if (!S_ISDIR (src_type))
378 +         if (!S_ISDIR (src_mode))
379             {
380               if (S_ISDIR (dst_sb.st_mode))
381                 {
382 @@ -924,7 +902,7 @@
383              This may be due to an interactive `negative' reply to the
384              prompt about the existing file.  It may also be due to the
385              use of the --reply=no option.  */
386 -         if (!S_ISDIR (src_type))
387 +         if (!S_ISDIR (src_mode))
388             {
389               /* cp and mv treat -i and -f differently.  */
390               if (x->move_mode)
391 @@ -1042,7 +1020,7 @@
392    /* If the source is a directory, we don't always create the destination
393       directory.  So --verbose should not announce anything until we're
394       sure we'll create a directory. */
395 -  if (x->verbose && !S_ISDIR (src_type))
396 +  if (x->verbose && !S_ISDIR (src_mode))
397      {
398        printf ("%s -> %s", quote_n (0, src_path), quote_n (1, dst_path));
399        if (backup_succeeded)
400 @@ -1077,7 +1055,7 @@
401            || (command_line_arg
402                && x->dereference == DEREF_COMMAND_LINE_ARGUMENTS)
403            || x->dereference == DEREF_ALWAYS))
404 -      || (x->recursive && S_ISDIR (src_type)))
405 +      || (x->recursive && S_ISDIR (src_mode)))
406      {
407        earlier_file = remember_copied (dst_path, src_sb.st_ino, src_sb.st_dev);
408      }
409 @@ -1090,7 +1068,7 @@
410        /* Avoid damaging the destination filesystem by refusing to preserve
411          hard-linked directories (which are found at least in Netapp snapshot
412          directories).  */
413 -      if (S_ISDIR (src_type))
414 +      if (S_ISDIR (src_mode))
415         {
416           /* If src_path and earlier_file refer to the same directory entry,
417              then warn about copying a directory into itself.  */
418 @@ -1142,7 +1120,7 @@
419      {
420        if (rename (src_path, dst_path) == 0)
421         {
422 -         if (x->verbose && S_ISDIR (src_type))
423 +         if (x->verbose && S_ISDIR (src_mode))
424             printf ("%s -> %s\n", quote_n (0, src_path), quote_n (1, dst_path));
425           if (rename_succeeded)
426             *rename_succeeded = 1;
427 @@ -1255,7 +1233,7 @@
428       In such cases, set this variable to zero.  */
429    preserve_metadata = 1;
430  
431 -  if (S_ISDIR (src_type))
432 +  if (S_ISDIR (src_mode))
433      {
434        struct dir_list *dir;
435  
436 @@ -1280,16 +1258,38 @@
437  
438        if (new_dst || !S_ISDIR (dst_sb.st_mode))
439         {
440 -         /* Create the new directory writable and searchable, so
441 -             we can create new entries in it.  */
442 -
443 -         if (mkdir (dst_path, (src_mode & x->umask_kill) | S_IRWXU))
444 +         if (mkdir (dst_path, src_mode))
445             {
446               error (0, errno, _("cannot create directory %s"),
447                      quote (dst_path));
448               goto un_backup;
449             }
450  
451 +         /* We need search and write permissions to the new directory
452 +            for adding the directory's contents. Check if these permissions
453 +            are already there.  */
454 +
455 +         if (lstat (dst_path, &dst_sb))
456 +           {
457 +             error (0, errno, _("cannot stat %s"), quote (dst_path));
458 +             delayed_fail = 1;
459 +           }
460 +         else if ((dst_sb.st_mode & S_IRWXU) != S_IRWXU)
461 +           {
462 +             /* Make the new directory writable and searchable. The original
463 +                permissions will be restored later.  */
464 +
465 +             dst_mode_valid = 1;
466 +             dst_mode = dst_sb.st_mode;
467 +
468 +             if (chmod (dst_path, dst_mode | S_IRWXU))
469 +               {
470 +                 error (0, errno, _("setting permissions for %s"),
471 +                        quote (dst_path));
472 +                 goto un_backup;
473 +               }
474 +           }
475 +
476           /* Insert the created directory's inode and device
477               numbers into the search structure, so that we can
478               avoid copying it again.  */
479 @@ -1365,10 +1365,10 @@
480           goto un_backup;
481         }
482      }
483 -  else if (S_ISREG (src_type)
484 -          || (x->copy_as_regular && !S_ISDIR (src_type)
485 +  else if (S_ISREG (src_mode)
486 +          || (x->copy_as_regular && !S_ISDIR (src_mode)
487  #ifdef S_ISLNK
488 -              && !S_ISLNK (src_type)
489 +              && !S_ISLNK (src_mode)
490  #endif
491                ))
492      {
493 @@ -1376,15 +1376,14 @@
494        /* POSIX says the permission bits of the source file must be
495          used as the 3rd argument in the open call, but that's not consistent
496          with historical practice.  */
497 -      if (copy_reg (src_path, dst_path, x,
498 -                   get_dest_mode (x, src_mode), &new_dst, &src_sb))
499 +      if (copy_reg (src_path, dst_path, x, src_mode, &new_dst, &src_sb))
500         goto un_backup;
501      }
502    else
503  #ifdef S_ISFIFO
504 -  if (S_ISFIFO (src_type))
505 +  if (S_ISFIFO (src_mode))
506      {
507 -      if (mkfifo (dst_path, get_dest_mode (x, src_mode)))
508 +      if (mkfifo (dst_path, src_mode))
509         {
510           error (0, errno, _("cannot create fifo %s"), quote (dst_path));
511           goto un_backup;
512 @@ -1392,13 +1391,13 @@
513      }
514    else
515  #endif
516 -    if (S_ISBLK (src_type) || S_ISCHR (src_type)
517 +    if (S_ISBLK (src_mode) || S_ISCHR (src_mode)
518  #ifdef S_ISSOCK
519 -       || S_ISSOCK (src_type)
520 +       || S_ISSOCK (src_mode)
521  #endif
522         )
523      {
524 -      if (mknod (dst_path, get_dest_mode (x, src_mode), src_sb.st_rdev))
525 +      if (mknod (dst_path, src_mode, src_sb.st_rdev))
526         {
527           error (0, errno, _("cannot create special file %s"),
528                  quote (dst_path));
529 @@ -1407,7 +1406,7 @@
530      }
531    else
532  #ifdef S_ISLNK
533 -  if (S_ISLNK (src_type))
534 +  if (S_ISLNK (src_mode))
535      {
536        char *src_link_val = xreadlink (src_path);
537        if (src_link_val == NULL)
538 @@ -1513,7 +1512,25 @@
539    if (x->preserve_ownership
540        && (new_dst || !SAME_OWNER_AND_GROUP (src_sb, dst_sb)))
541      {
542 -      ran_chown = 1;
543 +      /* The chown() system call may clear the SUID and SGID bits, so we
544 +         need to set them again later. (But we don't care if we will
545 +        overwrite the permissions of the destination file anyway.)  */
546 +        
547 +      if ((src_mode & (S_ISUID | S_ISGID))
548 +         && !x->preserve_mode && !x->move_mode && !x->set_mode)
549 +       {
550 +         if (lstat (dst_path, &dst_sb))
551 +           {
552 +             error (0, errno, _("cannot stat %s"), quote (dst_path));
553 +             delayed_fail = 1;
554 +           }
555 +         else
556 +           {
557 +             dst_mode_valid = 1;
558 +             dst_mode = dst_sb.st_mode;
559 +           }
560 +       }
561 +
562        if (DO_CHOWN (chown, dst_path, src_sb.st_uid, src_sb.st_gid))
563         {
564           error (0, errno, _("failed to preserve ownership for %s"),
565 @@ -1534,20 +1551,23 @@
566    }
567  #endif
568  
569 -  /* Permissions of newly-created regular files were set upon `open' in
570 -     copy_reg.  But don't return early if there were any special bits and
571 -     we had to run chown, because the chown must have reset those bits.  */
572 -  if ((new_dst && copied_as_regular)
573 -      && !(ran_chown && (src_mode & ~S_IRWXUGO)))
574 -    return delayed_fail;
575 -
576 -  if ((x->preserve_mode || new_dst)
577 -      && (x->copy_as_regular || S_ISREG (src_type) || S_ISDIR (src_type)))
578 +  if (x->preserve_mode || x->move_mode)
579      {
580 -      if (chmod (dst_path, get_dest_mode (x, src_mode)))
581 -       {
582 -         error (0, errno, _("setting permissions for %s"), quote (dst_path));
583 -         if (x->set_mode || x->require_preserve)
584 +      if (copy_acl (src_path, dst_path, src_mode) && x->require_preserve)
585 +       return 1;
586 +    }
587 +  else if (x->set_mode)
588 +    {
589 +      if (set_acl (dst_path, x->mode) && x->require_preserve)
590 +       return 1;
591 +    }
592 +  else if (dst_mode_valid)
593 +    {
594 +      if (chmod (dst_path, dst_mode))
595 +        {
596 +         error (0, errno, _("preserving permissions for %s"),
597 +                quote (dst_path));
598 +         if (x->require_preserve)
599             return 1;
600         }
601      }
602 diff -urN coreutils-4.5.10.org/src/copy.h coreutils-4.5.10/src/copy.h
603 --- coreutils-4.5.10.org/src/copy.h     Mon Mar 24 16:29:46 2003
604 +++ coreutils-4.5.10/src/copy.h Mon Mar 24 16:30:58 2003
605 @@ -139,9 +139,6 @@
606       Create destination directories as usual. */
607    int symbolic_link;
608  
609 -  /* The bits to preserve in created files' modes. */
610 -  mode_t umask_kill;
611 -
612    /* If nonzero, do not copy a nondirectory that has an existing destination
613       with the same or newer modification time. */
614    int update;
615 diff -urN coreutils-4.5.10.org/src/cp.c coreutils-4.5.10/src/cp.c
616 --- coreutils-4.5.10.org/src/cp.c       Mon Mar 24 16:29:46 2003
617 +++ coreutils-4.5.10/src/cp.c   Mon Mar 24 16:34:26 2003
618 @@ -61,7 +61,8 @@
619     need to be fixed after copying. */
620  struct dir_attr
621  {
622 -  int is_new_dir;
623 +  int mode_valid;
624 +  mode_t mode;
625    int slash_offset;
626    struct dir_attr *next;
627  };
628 @@ -342,9 +343,14 @@
629             }
630         }
631  
632 -      if (x->preserve_mode || p->is_new_dir)
633 +      if (x->preserve_mode)
634         {
635 -         if (chmod (dst_path, src_sb.st_mode & x->umask_kill))
636 +         if (copy_acl (src_path, dst_path, src_sb.st_mode))
637 +             return 1;
638 +       }
639 +      else if (p->mode_valid)
640 +        {
641 +         if (chmod (dst_path, p->mode))
642             {
643               error (0, errno, _("failed to preserve permissions for %s"),
644                      quote (dst_path));
645 @@ -362,8 +368,7 @@
646  
647     SRC_OFFSET is the index in CONST_DIRPATH (which is a destination
648     path) of the beginning of the source directory name.
649 -   Create any leading directories that don't already exist,
650 -   giving them permissions MODE.
651 +   Create any leading directories that don't already exist.
652     If VERBOSE_FMT_STRING is nonzero, use it as a printf format
653     string for printing a message after successfully making a directory.
654     The format should take two string arguments: the names of the
655 @@ -378,15 +383,16 @@
656  /* FIXME: find a way to synch this function with the one in lib/makepath.c. */
657  
658  static int
659 -make_path_private (const char *const_dirpath, int src_offset, int mode,
660 +make_path_private (const char *const_dirpath, int src_offset,
661                    const char *verbose_fmt_string, struct dir_attr **attr_list,
662 -                  int *new_dst, int (*xstat)())
663 +                  int *new_dst, const struct cp_options *x)
664  {
665    struct stat stats;
666    char *dirpath;               /* A copy of CONST_DIRPATH we can change. */
667    char *src;                   /* Source name in `dirpath'. */
668    char *dst_dirname;           /* Leading path of `dirpath'. */
669    size_t dirlen;               /* Length of leading path of `dirpath'. */
670 +  mode_t mode;
671  
672    dirpath = (char *) alloca (strlen (const_dirpath) + 1);
673    strcpy (dirpath, const_dirpath);
674 @@ -400,7 +406,7 @@
675  
676    *attr_list = NULL;
677  
678 -  if ((*xstat) (dst_dirname, &stats))
679 +  if ((*x->xstat) (dst_dirname, &stats))
680      {
681        /* Parent of CONST_DIRNAME does not exist.
682          Make all missing intermediate directories. */
683 @@ -420,15 +426,23 @@
684           *attr_list = new;
685  
686           *slash = '\0';
687 -         if ((*xstat) (dirpath, &stats))
688 +         if ((*x->xstat) (dirpath, &stats))
689             {
690               /* This element of the path does not exist.  We must set
691 -                *new_dst and new->is_new_dir inside this loop because,
692 +                *new_dst inside this loop because,
693                  for example, in the command `cp --parents ../a/../b/c e_dir',
694                  make_path_private creates only e_dir/../a if ./b already
695                  exists. */
696               *new_dst = 1;
697 -             new->is_new_dir = 1;
698 +
699 +             if ((*x->xstat) (src, &stats))
700 +               {
701 +                 error (0, errno, _("failed to get attributes of %s"),
702 +                        quote (src));
703 +                 return 1;
704 +               }
705 +             mode = stats.st_mode;
706 +
707               if (mkdir (dirpath, mode))
708                 {
709                   error (0, errno, _("cannot make directory %s"),
710 @@ -440,6 +454,46 @@
711                   if (verbose_fmt_string != NULL)
712                     printf (verbose_fmt_string, src, dirpath);
713                 }
714 +
715 +             /* We need search and write permissions to the new directory
716 +                for adding the directory's contents. Check if these
717 +                permissions are already there.  */
718 +
719 +             if (lstat (dirpath, &stats))
720 +               {
721 +                 error (0, errno, _("failed to get attributes of %s"),
722 +                        quote (dirpath));
723 +                 return 1;
724 +               }
725 +             else
726 +               {
727 +                 if (x->preserve_mode && mode != stats.st_mode)
728 +                   {
729 +                     new->mode = mode;
730 +                     new->mode_valid = 1;
731 +                   }
732 +                 else
733 +                   new->mode_valid = 0;
734 +
735 +                 if ((stats.st_mode & S_IRWXU) != S_IRWXU)
736 +                   {
737 +                     /* Make the new directory writable and searchable. The
738 +                        original permissions will be restored later.  */
739 +
740 +                     if (!new->mode_valid)
741 +                       {
742 +                         new->mode = stats.st_mode;
743 +                         new->mode_valid = 1;
744 +                       }
745 +
746 +                     if (chmod (dirpath, stats.st_mode | S_IRWXU))
747 +                       {
748 +                         error (0, errno, _("setting permissions for %s"),
749 +                                quote (dirpath));
750 +                         return 1;
751 +                       }
752 +                   }
753 +               }
754             }
755           else if (!S_ISDIR (stats.st_mode))
756             {
757 @@ -449,7 +503,7 @@
758             }
759           else
760             {
761 -             new->is_new_dir = 0;
762 +             new->mode_valid = 0;
763               *new_dst = 0;
764             }
765           *slash++ = '/';
766 @@ -600,11 +654,9 @@
767                  leading directories. */
768               parent_exists = !make_path_private (dst_path,
769                                                   arg_in_concat - dst_path,
770 -                                                 S_IRWXU,
771                                                   (x->verbose
772                                                    ? "%s -> %s\n" : NULL),
773 -                                                 &attr_list, &new_dst,
774 -                                                 x->xstat);
775 +                                                 &attr_list, &new_dst, x);
776             }
777           else
778             {
779 @@ -739,12 +791,6 @@
780    /* Not used.  */
781    x->stdin_tty = 0;
782  
783 -  /* Find out the current file creation mask, to knock the right bits
784 -     when using chmod.  The creation mask is set to be liberal, so
785 -     that created directories can be written, even if it would not
786 -     have been allowed with the mask this process was started with.  */
787 -  x->umask_kill = ~ umask (0);
788 -
789    x->update = 0;
790    x->verbose = 0;
791    x->dest_info = NULL;
792 @@ -1017,9 +1063,6 @@
793                                    version_control_string)
794                    : none);
795  
796 -  if (x.preserve_mode == 1)
797 -    x.umask_kill = ~ (mode_t) 0;
798 -
799    if (x.dereference == DEREF_UNDEFINED)
800      {
801        if (x.recursive)
802 diff -urN coreutils-4.5.10.org/src/install.c coreutils-4.5.10/src/install.c
803 --- coreutils-4.5.10.org/src/install.c  Mon Mar 24 16:29:46 2003
804 +++ coreutils-4.5.10/src/install.c      Mon Mar 24 16:30:58 2003
805 @@ -245,7 +245,6 @@
806    x->mode = S_IRUSR | S_IWUSR;
807    x->stdin_tty = 0;
808  
809 -  x->umask_kill = 0;
810    x->update = 0;
811    x->verbose = 0;
812    x->xstat = stat;
813 diff -urN coreutils-4.5.10.org/src/ls.c coreutils-4.5.10/src/ls.c
814 --- coreutils-4.5.10.org/src/ls.c       Mon Mar 24 16:29:46 2003
815 +++ coreutils-4.5.10/src/ls.c   Mon Mar 24 16:30:58 2003
816 @@ -223,13 +223,13 @@
817  
818      enum filetype filetype;
819  
820 -#if HAVE_ACL
821 +#if HAVE_ACL || USE_ACL
822      /* For long listings, true if the file has an access control list.  */
823      bool have_acl;
824  #endif
825    };
826  
827 -#if HAVE_ACL
828 +#if HAVE_ACL || USE_ACL
829  # define FILE_HAS_ACL(F) ((F)->have_acl)
830  #else
831  # define FILE_HAS_ACL(F) 0
832 @@ -2400,7 +2400,7 @@
833           return 0;
834         }
835  
836 -#if HAVE_ACL
837 +#if HAVE_ACL || USE_ACL
838        if (format == long_format)
839         {
840           int n = file_has_acl (path, &files[files_index].stat);
841 diff -urN coreutils-4.5.10.org/src/mv.c coreutils-4.5.10/src/mv.c
842 --- coreutils-4.5.10.org/src/mv.c       Mon Mar 24 16:29:46 2003
843 +++ coreutils-4.5.10/src/mv.c   Mon Mar 24 16:30:58 2003
844 @@ -137,12 +137,6 @@
845    x->mode = 0;
846    x->stdin_tty = isatty (STDIN_FILENO);
847  
848 -  /* Find out the current file creation mask, to knock the right bits
849 -     when using chmod.  The creation mask is set to be liberal, so
850 -     that created directories can be written, even if it would not
851 -     have been allowed with the mask this process was started with.  */
852 -  x->umask_kill = ~ umask (0);
853 -
854    x->update = 0;
855    x->verbose = 0;
856    x->xstat = lstat;
857 diff -urN coreutils-4.5.10.org/tests/misc/README coreutils-4.5.10/tests/misc/README
858 --- coreutils-4.5.10.org/tests/misc/README      Thu Jan  1 01:00:00 1970
859 +++ coreutils-4.5.10/tests/misc/README  Mon Mar 24 16:30:58 2003
860 @@ -0,0 +1,6 @@
861 +Use the run script to run any of the *.test scripts, e.g.,
862 +
863 +  run cp.test
864 +
865 +The cp.test script can be run as any user; the cp-root
866 +script requires root privileges.
867 diff -urN coreutils-4.5.10.org/tests/misc/acl coreutils-4.5.10/tests/misc/acl
868 --- coreutils-4.5.10.org/tests/misc/acl Thu Jan  1 01:00:00 1970
869 +++ coreutils-4.5.10/tests/misc/acl     Mon Mar 24 16:30:58 2003
870 @@ -0,0 +1,3 @@
871 +#!/bin/sh
872 +
873 +getfacl "$@" | sed -e 's/[     ]*#.*$//' -e '/^$/d'
874 diff -urN coreutils-4.5.10.org/tests/misc/cp-root.test coreutils-4.5.10/tests/misc/cp-root.test
875 --- coreutils-4.5.10.org/tests/misc/cp-root.test        Thu Jan  1 01:00:00 1970
876 +++ coreutils-4.5.10/tests/misc/cp-root.test    Mon Mar 24 16:30:58 2003
877 @@ -0,0 +1,26 @@
878 +! Tests the access control list extensions to cp.
879 +! This script must be run as root.
880 +!
881 +$ rm -rf test
882 +$ mkdir test
883 +$ cd test
884 +$ umask 022
885 +$ touch f
886 +$ chmod u+xs,g+xs f
887 +$ mode f
888 + -rwsr-sr-- f
889 +$ cp -p f g
890 +$ mode g
891 + -rwsr-sr-- g
892 +$ cp f h
893 +$ mode h
894 + -rwsr-sr-- h
895 +$ chown bin h
896 +$ cp h i
897 +$ mode i
898 + -rwsr-sr-- i
899 +!
900 +! cleanup
901 +!
902 +$cd ..
903 +$ rm -rf test
904 diff -urN coreutils-4.5.10.org/tests/misc/cp.test coreutils-4.5.10/tests/misc/cp.test
905 --- coreutils-4.5.10.org/tests/misc/cp.test     Thu Jan  1 01:00:00 1970
906 +++ coreutils-4.5.10/tests/misc/cp.test Mon Mar 24 16:30:58 2003
907 @@ -0,0 +1,86 @@
908 +! Tests the access control list extensions to cp (and also of ls).
909 +! Requires a system with POSIX access control lists and the
910 +! getfacl and setfacl utilities.
911 +!
912 +$ rm -rf test
913 +$ mkdir test
914 +$ cd test
915 +$ umask 022
916 +$ touch f
917 +$ mode . f
918 + drwxr-xr-x .
919 + -rw-r--r-- f
920 +$ setfacl -m u:@OWNER@:rw- f
921 +$ mode f
922 + -rw-rw-r--+ f
923 +$ acl f
924 + user::rw-
925 + user:@OWNER@:rw-
926 + group::r--
927 + mask::rw-
928 + other::r--
929 +!
930 +! cp and cp -p
931 +!
932 +$ cp f g
933 +$ cp -p f h
934 +$ mode g h
935 + -rw-r--r-- g
936 + -rw-rw-r--+ h
937 +$ acl h
938 + user::rw-
939 + user:@OWNER@:rw-
940 + group::r--
941 + mask::rw-
942 + other::r--
943 +$ mkdir d
944 +$ setfacl -d -m u::rwx,u:@OWNER@:r-x,g::---,m::r-x,o::--- d
945 +$ acl d
946 + user::rwx
947 + group::r-x
948 + other::r-x
949 + default:user::rwx
950 + default:user:@OWNER@:r-x
951 + default:group::---
952 + default:mask::r-x
953 + default:other::---
954 +$ touch d/i
955 +$ acl d/i
956 + user::rw-
957 + user:@OWNER@:r-x
958 + group::---
959 + mask::r--
960 + other::---
961 +$ cp f d/f
962 +$ acl d/f
963 + user::rw-
964 + user:@OWNER@:r-x
965 + group::---
966 + mask::r--
967 + other::---
968 +$ chmod go-rwx g
969 +$ cp g d/g
970 +$ acl d/g
971 + user::rw-
972 + user:@OWNER@:r-x
973 + group::---
974 + mask::---
975 + other::---
976 +$ cp -p h d/h
977 +$ acl h
978 + user::rw-
979 + user:@OWNER@:rw-
980 + group::r--
981 + mask::rw-
982 + other::r--
983 +$ touch j
984 +$ cp -p j d/j
985 +$ mode d/j
986 + -rw-r--r-- d/j
987 +$ 
988 +! mv
989 +!
990 +! cleanup
991 +!
992 +$cd ..
993 +$ rm -rf test
994 diff -urN coreutils-4.5.10.org/tests/misc/mode coreutils-4.5.10/tests/misc/mode
995 --- coreutils-4.5.10.org/tests/misc/mode        Thu Jan  1 01:00:00 1970
996 +++ coreutils-4.5.10/tests/misc/mode    Mon Mar 24 16:30:58 2003
997 @@ -0,0 +1,2 @@
998 +#!/bin/sh
999 +ls -dl $* | awk -- '!/^total/ { print $1, $8; }'
1000 diff -urN coreutils-4.5.10.org/tests/misc/run coreutils-4.5.10/tests/misc/run
1001 --- coreutils-4.5.10.org/tests/misc/run Thu Jan  1 01:00:00 1970
1002 +++ coreutils-4.5.10/tests/misc/run     Mon Mar 24 16:30:58 2003
1003 @@ -0,0 +1,164 @@
1004 +#!/usr/bin/perl
1005 +
1006 +use strict;
1007 +use FileHandle;
1008 +use POSIX qw(geteuid getegid isatty);
1009 +
1010 +my $pwd = `pwd`;
1011 +chomp $pwd;
1012 +$ENV{'PATH'} = $pwd . ":../../src:" . $ENV{'PATH'};
1013 +
1014 +my $owner = getpwuid(geteuid());
1015 +my $group = getgrgid(getegid());
1016 +
1017 +my ($OK, $FAILED) = ("ok", "failed");
1018 +if (isatty(fileno(STDOUT))) {
1019 +       $OK = "\033[32m" . $OK . "\033[m";
1020 +       $FAILED = "\033[31m\033[1m" . $FAILED . "\033[m";
1021 +}
1022 +
1023 +my ($prog, $in, $out) = ([], [], []);
1024 +my $line = 0;
1025 +my $prog_line;
1026 +my ($tests, $failed);
1027 +
1028 +for (;;) {
1029 +  my $script = <>; $line++;
1030 +  $script =~ s/\@OWNER\@/$owner/g;
1031 +  $script =~ s/\@GROUP\@/$group/g;
1032 +  next if (defined($script) && $script =~ /^!/);
1033 +  if (!defined($script) || $script =~ s/^\$ ?//) {
1034 +    if (@$prog) {
1035 +       #print "[$prog_line] \$ ", join(' ', @$prog), " -- ";
1036 +       my $p = [ @$prog ];
1037 +       print "[$prog_line] \$ ", join(' ',
1038 +             map { s/\s/\\$&/g; $_ } @$p), " -- ";
1039 +       my $result = exec_test($prog, $in);
1040 +       my $good = 1;
1041 +       my $nmax = (@$out > @$result) ? @$out : @$result;
1042 +       for (my $n=0; $n < $nmax; $n++) {
1043 +        if (!defined($out->[$n]) || !defined($result->[$n]) ||
1044 +            $out->[$n] ne $result->[$n]) {
1045 +                $good = 0;
1046 +                #chomp $out->[$n];
1047 +                #chomp $result->[$n];
1048 +                #print "$out->[$n] != $result->[$n]";
1049 +        }
1050 +       }
1051 +       $tests++;
1052 +       $failed++ unless $good;
1053 +       print $good ? $OK : $FAILED, "\n";
1054 +       if (!$good) {
1055 +         for (my $n=0; $n < $nmax; $n++) {
1056 +          my $l = defined($out->[$n]) ? $out->[$n] : "~";
1057 +          chomp $l;
1058 +          my $r = defined($result->[$n]) ? $result->[$n] : "~";
1059 +          chomp $r;
1060 +          print sprintf("%-37s | %-39s\n", $l, $r);
1061 +         }
1062 +       }
1063 +    }
1064 +    #$prog = [ split /\s+/, $script ] if $script;
1065 +    $prog = [ map { s/\\(.)/$1/g; $_ } split /(?<!\\)\s+/, $script ] if $script;
1066 +    $prog_line = $line;
1067 +    $in = [];
1068 +    $out = [];
1069 +  } elsif ($script =~ s/^> ?//) {
1070 +    push @$in, $script;
1071 +  } else {
1072 +    $script =~ s/^[ \t]*//;  # ignore leading whitespace
1073 +    push @$out, $script;
1074 +  }
1075 +  last unless defined($script);
1076 +}
1077 +my $status = sprintf("%d commands (%d passed, %d failed)",
1078 +       $tests, $tests-$failed, $failed);
1079 +if (isatty(fileno(STDOUT))) {
1080 +       if ($failed) {
1081 +               $status = "\033[31m\033[1m" . $status . "\033[m";
1082 +       } else {
1083 +               $status = "\033[32m" . $status . "\033[m";
1084 +       }
1085 +}
1086 +print $status, "\n";
1087 +
1088 +sub exec_test($$) {
1089 +  my ($prog, $in) = @_;
1090 +  local (*IN, *IN_DUP, *IN2, *OUT_DUP, *OUT, *OUT2);
1091 +
1092 +  if ($prog->[0] eq "umask") {
1093 +    umask oct $prog->[1];
1094 +    return [];
1095 +  } elsif ($prog->[0] eq "cd") {
1096 +    if (!chdir $prog->[1]) {
1097 +      return [ "chdir: $prog->[1]: $!\n" ];
1098 +    }
1099 +    return [];
1100 +  }
1101 +
1102 +  pipe *IN2, *OUT
1103 +    or die "Can't create pipe for reading: $!";
1104 +  open *IN_DUP, "<&STDIN"
1105 +    or *IN_DUP = undef;
1106 +  open *STDIN, "<&IN2"
1107 +    or die "Can't duplicate pipe for reading: $!";
1108 +  close *IN2;
1109 +
1110 +  open *OUT_DUP, ">&STDOUT"
1111 +    or die "Can't duplicate STDOUT: $!";
1112 +  pipe *IN, *OUT2
1113 +    or die "Can't create pipe for writing: $!";
1114 +  open *STDOUT, ">&OUT2"
1115 +    or die "Can't duplicate pipe for writing: $!";
1116 +  close *OUT2;
1117 +
1118 +  *STDOUT->autoflush();
1119 +  *OUT->autoflush();
1120 +
1121 +  if (fork()) {
1122 +    # Server
1123 +    if (*IN_DUP) {
1124 +      open *STDIN, "<&IN_DUP"
1125 +        or die "Can't duplicate STDIN: $!";
1126 +      close *IN_DUP
1127 +        or die "Can't close STDIN duplicate: $!";
1128 +    }
1129 +    open *STDOUT, ">&OUT_DUP"
1130 +      or die "Can't duplicate STDOUT: $!";
1131 +    close *OUT_DUP
1132 +      or die "Can't close STDOUT duplicate: $!";
1133 +
1134 +    foreach my $line (@$in) {
1135 +      #print "> $line";
1136 +      print OUT $line;
1137 +    }
1138 +    close *OUT
1139 +      or die "Can't close pipe for writing: $!";
1140 +
1141 +    my $result = [];
1142 +    while (<IN>) {
1143 +      #print "< $_";
1144 +      push @$result, $_;
1145 +    }
1146 +    return $result;
1147 +  } else {
1148 +    # Client
1149 +    close IN
1150 +      or die "Can't close read end for input pipe: $!";
1151 +    close OUT
1152 +      or die "Can't close write end for output pipe: $!";
1153 +    close OUT_DUP
1154 +      or die "Can't close STDOUT duplicate: $!";
1155 +    local *ERR_DUP;
1156 +    open ERR_DUP, ">&STDERR"
1157 +      or die "Can't duplicate STDERR: $!";
1158 +    open STDERR, ">&STDOUT"
1159 +      or die "Can't join STDOUT and STDERR: $!";
1160 +
1161 +    #print ERR_DUP "<", join(' ', @$prog), ">\n";
1162 +    exec @$prog;
1163 +    print ERR_DUP $prog->[0], ": $!\n";
1164 +    exit;
1165 +  }
1166 +}
1167 +
1168 --- coreutils-5.0/src/Makefile.am.orig  2003-12-28 23:21:11.000000000 +0100
1169 +++ coreutils-5.0/src/Makefile.am       2003-12-28 23:27:33.113542384 +0100
1170 @@ -34,10 +34,13 @@
1171  # replacement functions defined in libfetish.a.
1172  LDADD = ../lib/libfetish.a @LIBINTL@ ../lib/libfetish.a
1173  
1174 -dir_LDADD = $(LDADD) @LIB_CLOCK_GETTIME@
1175 -ls_LDADD = $(LDADD) @LIB_CLOCK_GETTIME@
1176 +dir_LDADD = $(LDADD) @LIB_CLOCK_GETTIME@ $(LIBACL)
1177 +ls_LDADD = $(LDADD) @LIB_CLOCK_GETTIME@ $(LIBACL)
1178  shred_LDADD = $(LDADD) @LIB_CLOCK_GETTIME@
1179 -vdir_LDADD = $(LDADD) @LIB_CLOCK_GETTIME@
1180 +vdir_LDADD = $(LDADD) @LIB_CLOCK_GETTIME@ $(LIBACL)
1181 +cp_LDADD = $(LDADD) $(LIBACL)
1182 +ginstall_LDADD = $(LDADD) $(LIBACL)
1183 +mv_LDADD = $(LDADD) $(LIBACL)
1184  
1185  ## If necessary, add -lm to resolve use of pow in lib/strtod.c.
1186  sort_LDADD = $(LDADD) @POW_LIB@
1187 --- coreutils-5.0/po/pl.po.orig 2003-12-28 23:21:11.000000000 +0100
1188 +++ coreutils-5.0/po/pl.po      2003-12-28 23:43:19.632649608 +0100
1189 @@ -1011,6 +1011,11 @@
1190  msgid "setting permissions for %s"
1191  msgstr "nie mo¿na ustawiæ uprawnieñ do %s"
1192  
1193 +#: src/copy.c:1568
1194 +#, c-format
1195 +msgid "preserving permissions for %s"
1196 +msgstr "nie mo¿na zachowaæ uprawnieñ do %s"
1197 +
1198  #: src/copy.c:1571 src/ln.c:326
1199  #, c-format
1200  msgid "cannot un-backup %s"
This page took 0.173263 seconds and 2 git commands to generate.