Print this page
10133 smatch fixes for usr/src/cmd/fs.d


   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 2010 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 /*




  28  * This is the smbfs/chacl command.
  29  * (just for testing - not installed)
  30  *
  31  * Works like chmod(1), but only supporting A=... forms.
  32  * i.e. chacl A=everyone@:full_set:fd:allow /mnt/foo
  33  *
  34  * Some more test cases:
  35  *      /usr/lib/fs/smbfs/chacl -v
  36  *      A=user:2147483649:rwxpdDaARWcCos::allow,
  37  *      user:2147483653:raRcs::allow,
  38  *      everyone@:raRcs::allow
  39  */
  40 
  41 #include <sys/types.h>
  42 #include <sys/errno.h>
  43 #include <sys/stat.h>
  44 #include <sys/acl.h>
  45 #include <sys/acl_impl.h>
  46 
  47 #include <fcntl.h>


 121         /*
 122          * Ask libsec to parse the ACL arg.
 123          */
 124         if (strncmp(acl_arg, "A=", 2) != 0)
 125                 usage();
 126         error = acl_parse(acl_arg + 2, &acl);
 127         if (error) {
 128                 fprintf(stderr, "%s: can not parse ACL: %s\n",
 129                     progname, acl_arg);
 130                 exit(1);
 131         }
 132         if (acl->acl_type != ACE_T) {
 133                 fprintf(stderr, "%s: ACL not ACE_T type: %s\n",
 134                     progname, acl_arg);
 135                 exit(1);
 136         }
 137 
 138         /*
 139          * Which parts of the SD are being modified?
 140          */
 141         selector = 0;
 142         if (acl)
 143                 selector |= DACL_SECURITY_INFORMATION;
 144         if (uid != (uid_t)-1)
 145                 selector |= OWNER_SECURITY_INFORMATION;
 146         if (gid != (gid_t)-1)
 147                 selector |= GROUP_SECURITY_INFORMATION;
 148 
 149         if (optind == argc)
 150                 usage();
 151         for (; optind < argc; optind++)
 152                 chacl(argv[optind], selector, uid, gid, acl);
 153 
 154 done:
 155         acl_free(acl);
 156         return (0);
 157 }
 158 
 159 void
 160 chacl(char *file, uint32_t selector, uid_t uid, gid_t gid, acl_t *acl)
 161 {
 162         struct stat st;
 163         struct i_ntsd *sd = NULL;




   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 2010 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 /*
  28  * Copyright (c) 2018, Joyent, Inc.
  29  */
  30 
  31 /*
  32  * This is the smbfs/chacl command.
  33  * (just for testing - not installed)
  34  *
  35  * Works like chmod(1), but only supporting A=... forms.
  36  * i.e. chacl A=everyone@:full_set:fd:allow /mnt/foo
  37  *
  38  * Some more test cases:
  39  *      /usr/lib/fs/smbfs/chacl -v
  40  *      A=user:2147483649:rwxpdDaARWcCos::allow,
  41  *      user:2147483653:raRcs::allow,
  42  *      everyone@:raRcs::allow
  43  */
  44 
  45 #include <sys/types.h>
  46 #include <sys/errno.h>
  47 #include <sys/stat.h>
  48 #include <sys/acl.h>
  49 #include <sys/acl_impl.h>
  50 
  51 #include <fcntl.h>


 125         /*
 126          * Ask libsec to parse the ACL arg.
 127          */
 128         if (strncmp(acl_arg, "A=", 2) != 0)
 129                 usage();
 130         error = acl_parse(acl_arg + 2, &acl);
 131         if (error) {
 132                 fprintf(stderr, "%s: can not parse ACL: %s\n",
 133                     progname, acl_arg);
 134                 exit(1);
 135         }
 136         if (acl->acl_type != ACE_T) {
 137                 fprintf(stderr, "%s: ACL not ACE_T type: %s\n",
 138                     progname, acl_arg);
 139                 exit(1);
 140         }
 141 
 142         /*
 143          * Which parts of the SD are being modified?
 144          */
 145         selector = DACL_SECURITY_INFORMATION;
 146 

 147         if (uid != (uid_t)-1)
 148                 selector |= OWNER_SECURITY_INFORMATION;
 149         if (gid != (gid_t)-1)
 150                 selector |= GROUP_SECURITY_INFORMATION;
 151 
 152         if (optind == argc)
 153                 usage();
 154         for (; optind < argc; optind++)
 155                 chacl(argv[optind], selector, uid, gid, acl);
 156 
 157 done:
 158         acl_free(acl);
 159         return (0);
 160 }
 161 
 162 void
 163 chacl(char *file, uint32_t selector, uid_t uid, gid_t gid, acl_t *acl)
 164 {
 165         struct stat st;
 166         struct i_ntsd *sd = NULL;