Print this page
3619 cp -p clobbers permissions/ownership following symbolic links

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/mv/mv.c
          +++ new/usr/src/cmd/mv/mv.c
↓ open down ↓ 12 lines elided ↑ open up ↑
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
       23 + * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
       24 + */
       25 +
       26 +/*
  23   27   * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  24   28   * Use is subject to license terms.
  25   29   */
  26   30  
  27   31  /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
  28   32  /*        All Rights Reserved   */
  29   33  
  30   34  /*
  31   35   * University Copyright- Copyright (c) 1982, 1986, 1988
  32   36   * The Regents of the University of California
↓ open down ↓ 1308 lines elided ↑ open up ↑
1341 1345   */
1342 1346  static int
1343 1347  chg_time(char *to, struct stat ss)
1344 1348  {
1345 1349          struct timespec times[2];
1346 1350          int rc;
1347 1351  
1348 1352          times[0] = ss.st_atim;
1349 1353          times[1] = ss.st_mtim;
1350 1354  
1351      -        rc = utimensat(AT_FDCWD, to, times, 0);
     1355 +        rc = utimensat(AT_FDCWD, to, times,
     1356 +            ISLNK(s1) ? AT_SYMLINK_NOFOLLOW : 0);
1352 1357  #ifdef XPG4
1353 1358          if ((pflg || mve) && rc != 0) {
1354 1359                  (void) fprintf(stderr,
1355 1360                      gettext("%s: cannot set times for %s: "), cmd, to);
1356 1361                  perror("");
1357 1362                  if (pflg)
1358 1363                          return (1);
1359 1364          }
1360 1365  #endif
1361 1366  
↓ open down ↓ 14 lines elided ↑ open up ↑
1376 1381   * Try to preserve permissions.
1377 1382   * If this is the XPG4 version and chmod() fails, print a diagnostic message
1378 1383   * and arrange for a non-zero exit status.
1379 1384   * If this is the Solaris version and chmod() fails, do not print a
1380 1385   * diagnostic message or exit with a non-zero value.
1381 1386   */
1382 1387  static int
1383 1388  chg_mode(char *target, uid_t uid, gid_t gid, mode_t mode)
1384 1389  {
1385 1390          int clearflg = 0; /* controls message printed upon chown() error */
     1391 +        struct stat st;
1386 1392  
     1393 +        /* Don't change mode if target is symlink */
     1394 +        if (lstat(target, &st) == 0 && ISLNK(st))
     1395 +                return (0);
     1396 +
1387 1397          if (chown(target, uid, gid) != 0) {
1388 1398  #ifdef XPG4
1389 1399                  if (mve) {
1390 1400                          (void) fprintf(stderr, gettext("%s: cannot change"
1391 1401                              " owner and group of %s: "), cmd, target);
1392 1402                          perror("");
1393 1403                  }
1394 1404  #endif
1395 1405                  if (mode & (S_ISUID | S_ISGID)) {
1396 1406                          /* try to clear S_ISUID and S_ISGID */
↓ open down ↓ 844 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX