Print this page
10151 mv_xattrs() checks for a NULL array name


   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  * Copyright 2012 Milan Jurik. All rights reserved.

  26  */
  27 
  28 #include "libcmdutils.h"
  29 
  30 
  31 /*
  32  * Gets file descriptors of attribute directories for source and target
  33  * attribute files
  34  */
  35 int
  36 get_attrdirs(int indfd, int outdfd, char *attrfile, int *sfd, int *tfd)
  37 {
  38         int     pwdfd;
  39         int     fd1;
  40         int     fd2;
  41 
  42         pwdfd = open(".", O_RDONLY);
  43         if ((pwdfd != -1) && (fchdir(indfd) == 0)) {
  44                 if ((fd1 = attropen(attrfile, ".", O_RDONLY)) == -1) {
  45                         (void) fchdir(pwdfd);


 145                 }
 146                 if (fstat(tattrfd, &st2) < 0) {
 147                         etext = dgettext(TEXT_DOMAIN,
 148                             "could not stat attribute file");
 149                         goto error;
 150                 }
 151                 if (writefile(sattrfd, tattrfd, infile, outfile, dp->d_name,
 152                     dp->d_name, &st1, &st2) != 0) {
 153                         etext = dgettext(TEXT_DOMAIN,
 154                             "failed to copy extended attribute "
 155                             "from source to target");
 156                         goto error;
 157                 }
 158 
 159                 errno = 0;
 160                 if (sattr) {
 161                         /*
 162                          * Gets non default extended system attributes from
 163                          * source to copy to target.
 164                          */
 165                         if (dp->d_name != NULL)
 166                                 res = sysattr_list(cmd, sattrfd, dp->d_name);
 167 
 168                         if (res != NULL &&
 169                             get_attrdirs(indfd, outdfd, dp->d_name, &asfd,
 170                             &atfd) != 0) {
 171                                 etext = dgettext(TEXT_DOMAIN,
 172                                     "Failed to open attribute files");
 173                                 goto error;
 174                         }
 175                         /*
 176                          * Copy extended system attribute from source
 177                          * attribute file to target attribute file
 178                          */
 179                         if (res != NULL &&
 180                             (renameat(asfd, VIEW_READWRITE, atfd,
 181                             VIEW_READWRITE) != 0)) {
 182                                 if (errno == EPERM)
 183                                         etext = dgettext(TEXT_DOMAIN,
 184                                             "Permission denied -"
 185                                             "failed to move system attribute");




   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  * Copyright 2012 Milan Jurik. All rights reserved.
  26  * Copyright (c) 2018, Joyent, Inc.
  27  */
  28 
  29 #include "libcmdutils.h"
  30 
  31 
  32 /*
  33  * Gets file descriptors of attribute directories for source and target
  34  * attribute files
  35  */
  36 int
  37 get_attrdirs(int indfd, int outdfd, char *attrfile, int *sfd, int *tfd)
  38 {
  39         int     pwdfd;
  40         int     fd1;
  41         int     fd2;
  42 
  43         pwdfd = open(".", O_RDONLY);
  44         if ((pwdfd != -1) && (fchdir(indfd) == 0)) {
  45                 if ((fd1 = attropen(attrfile, ".", O_RDONLY)) == -1) {
  46                         (void) fchdir(pwdfd);


 146                 }
 147                 if (fstat(tattrfd, &st2) < 0) {
 148                         etext = dgettext(TEXT_DOMAIN,
 149                             "could not stat attribute file");
 150                         goto error;
 151                 }
 152                 if (writefile(sattrfd, tattrfd, infile, outfile, dp->d_name,
 153                     dp->d_name, &st1, &st2) != 0) {
 154                         etext = dgettext(TEXT_DOMAIN,
 155                             "failed to copy extended attribute "
 156                             "from source to target");
 157                         goto error;
 158                 }
 159 
 160                 errno = 0;
 161                 if (sattr) {
 162                         /*
 163                          * Gets non default extended system attributes from
 164                          * source to copy to target.
 165                          */

 166                         res = sysattr_list(cmd, sattrfd, dp->d_name);
 167 
 168                         if (res != NULL &&
 169                             get_attrdirs(indfd, outdfd, dp->d_name, &asfd,
 170                             &atfd) != 0) {
 171                                 etext = dgettext(TEXT_DOMAIN,
 172                                     "Failed to open attribute files");
 173                                 goto error;
 174                         }
 175                         /*
 176                          * Copy extended system attribute from source
 177                          * attribute file to target attribute file
 178                          */
 179                         if (res != NULL &&
 180                             (renameat(asfd, VIEW_READWRITE, atfd,
 181                             VIEW_READWRITE) != 0)) {
 182                                 if (errno == EPERM)
 183                                         etext = dgettext(TEXT_DOMAIN,
 184                                             "Permission denied -"
 185                                             "failed to move system attribute");