Print this page
NEX-16159 Time spent sharing SMB filesystems could be reduced by optimizing smb_getdataset for default mount points
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Reviewed by: Matt Barden <matt.barden@nexenta.com>
NEX-3981 bad pointer free causes crash in fksmbd
Reviewed by: Gordon Ross <gordon.ross@nexenta.com>
Reviewed by: Kevin Crowe <kevin.crowe@nexenta.com>
Reviewed by: Alek Pinchuk <alek@nexenta.com>
NEX-1456 Cannot receive incremental stream for dataset shared via SMB: destination dataset has been modified. part 1
SMB-153 Quota tab for the Share does not work


   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   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 (c) 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright 2014 Nexenta Systems, Inc.  All rights reserved.
  25  */
  26 
  27 #include <stdio.h>
  28 #include <stdlib.h>
  29 #include <fcntl.h>
  30 #include <attr.h>
  31 #include <unistd.h>
  32 #include <libuutil.h>
  33 #include <libzfs.h>
  34 #include <assert.h>
  35 #include <stddef.h>
  36 #include <strings.h>
  37 #include <errno.h>
  38 #include <synch.h>
  39 #include <smbsrv/smb_xdr.h>
  40 #include <smbsrv/libmlsvc.h>
  41 #include <smbsrv/smb_idmap.h>
  42 #include <mlsvc.h>
  43 #include <sys/avl.h>
  44 


1066 
1067         if (smb_idmap_getsid(id, idtype, &sid) != IDMAP_SUCCESS)
1068                 return (-1);
1069 
1070         smb_sid_tostr(sid, sidstr);
1071         smb_sid_free(sid);
1072 
1073         return (0);
1074 }
1075 
1076 /*
1077  * smb_quota_zfs_init
1078  *
1079  * Initialize zfs library and dataset handles
1080  */
1081 static uint32_t
1082 smb_quota_zfs_init(const char *path, smb_quota_zfs_handle_t *zfs_hdl)
1083 {
1084         char dataset[MAXPATHLEN];
1085 
1086         if (smb_getdataset(path, dataset, MAXPATHLEN) != 0)
1087                 return (NT_STATUS_INVALID_PARAMETER);
1088 
1089         if ((zfs_hdl->z_lib = libzfs_init()) == NULL)
1090                 return (NT_STATUS_INTERNAL_ERROR);
1091 





1092         zfs_hdl->z_fs = zfs_open(zfs_hdl->z_lib, dataset, ZFS_TYPE_DATASET);
1093         if (zfs_hdl->z_fs == NULL) {
1094                 libzfs_fini(zfs_hdl->z_lib);
1095                 return (NT_STATUS_ACCESS_DENIED);
1096         }
1097 
1098         return (NT_STATUS_SUCCESS);
1099 }
1100 
1101 /*
1102  * smb_quota_zfs_fini
1103  *
1104  * Close zfs library and dataset handles
1105  */
1106 static void
1107 smb_quota_zfs_fini(smb_quota_zfs_handle_t *zfs_hdl)
1108 {
1109         zfs_close(zfs_hdl->z_fs);
1110         libzfs_fini(zfs_hdl->z_lib);
1111 }


1198         }
1199 
1200         afd = attropen(file, SMB_QUOTA_CNTRL_INDEX_XATTR, O_RDWR | O_CREAT,
1201             0640);
1202         if (afd == -1) {
1203                 (void) unlink(file);
1204                 if (qdir_created)
1205                         (void) remove(dir);
1206                 return;
1207         }
1208         (void) close(afd);
1209 
1210         if (acl_get(file, 0, &existing_aclp) == -1) {
1211                 (void) unlink(file);
1212                 if (qdir_created)
1213                         (void) remove(dir);
1214                 return;
1215         }
1216 
1217         acl_text = acl_totext(existing_aclp, ACL_COMPACT_FMT);
1218         acl_free(existing_aclp);
1219         if (acl_text == NULL) {

1220                 (void) unlink(file);
1221                 if (qdir_created)
1222                         (void) remove(dir);
1223                 return;
1224         }

1225 
1226         aclp = NULL;
1227         if (strcmp(acl_text, SMB_QUOTA_CNTRL_PERM) != 0) {
1228                 if (acl_fromtext(SMB_QUOTA_CNTRL_PERM, &aclp) != 0) {
1229                         free(acl_text);
1230                         (void) unlink(file);
1231                         if (qdir_created)
1232                                 (void) remove(dir);
1233                         return;
1234                 }
1235                 if (acl_set(file, aclp) == -1) {
1236                         free(acl_text);
1237                         (void) unlink(file);
1238                         if (qdir_created)
1239                                 (void) remove(dir);
1240                         acl_free(aclp);
1241                         return;
1242                 }
1243                 acl_free(aclp);
1244         }


   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   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 (c) 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright 2018 Nexenta Systems, Inc.  All rights reserved.
  25  */
  26 
  27 #include <stdio.h>
  28 #include <stdlib.h>
  29 #include <fcntl.h>
  30 #include <attr.h>
  31 #include <unistd.h>
  32 #include <libuutil.h>
  33 #include <libzfs.h>
  34 #include <assert.h>
  35 #include <stddef.h>
  36 #include <strings.h>
  37 #include <errno.h>
  38 #include <synch.h>
  39 #include <smbsrv/smb_xdr.h>
  40 #include <smbsrv/libmlsvc.h>
  41 #include <smbsrv/smb_idmap.h>
  42 #include <mlsvc.h>
  43 #include <sys/avl.h>
  44 


1066 
1067         if (smb_idmap_getsid(id, idtype, &sid) != IDMAP_SUCCESS)
1068                 return (-1);
1069 
1070         smb_sid_tostr(sid, sidstr);
1071         smb_sid_free(sid);
1072 
1073         return (0);
1074 }
1075 
1076 /*
1077  * smb_quota_zfs_init
1078  *
1079  * Initialize zfs library and dataset handles
1080  */
1081 static uint32_t
1082 smb_quota_zfs_init(const char *path, smb_quota_zfs_handle_t *zfs_hdl)
1083 {
1084         char dataset[MAXPATHLEN];
1085 



1086         if ((zfs_hdl->z_lib = libzfs_init()) == NULL)
1087                 return (NT_STATUS_INTERNAL_ERROR);
1088 
1089         if (smb_getdataset(zfs_hdl->z_lib, path, dataset, MAXPATHLEN) != 0) {
1090                 libzfs_fini(zfs_hdl->z_lib);
1091                 return (NT_STATUS_INVALID_PARAMETER);
1092         }
1093 
1094         zfs_hdl->z_fs = zfs_open(zfs_hdl->z_lib, dataset, ZFS_TYPE_DATASET);
1095         if (zfs_hdl->z_fs == NULL) {
1096                 libzfs_fini(zfs_hdl->z_lib);
1097                 return (NT_STATUS_ACCESS_DENIED);
1098         }
1099 
1100         return (NT_STATUS_SUCCESS);
1101 }
1102 
1103 /*
1104  * smb_quota_zfs_fini
1105  *
1106  * Close zfs library and dataset handles
1107  */
1108 static void
1109 smb_quota_zfs_fini(smb_quota_zfs_handle_t *zfs_hdl)
1110 {
1111         zfs_close(zfs_hdl->z_fs);
1112         libzfs_fini(zfs_hdl->z_lib);
1113 }


1200         }
1201 
1202         afd = attropen(file, SMB_QUOTA_CNTRL_INDEX_XATTR, O_RDWR | O_CREAT,
1203             0640);
1204         if (afd == -1) {
1205                 (void) unlink(file);
1206                 if (qdir_created)
1207                         (void) remove(dir);
1208                 return;
1209         }
1210         (void) close(afd);
1211 
1212         if (acl_get(file, 0, &existing_aclp) == -1) {
1213                 (void) unlink(file);
1214                 if (qdir_created)
1215                         (void) remove(dir);
1216                 return;
1217         }
1218 
1219         acl_text = acl_totext(existing_aclp, ACL_COMPACT_FMT);

1220         if (acl_text == NULL) {
1221                 acl_free(existing_aclp);
1222                 (void) unlink(file);
1223                 if (qdir_created)
1224                         (void) remove(dir);
1225                 return;
1226         }
1227         acl_free(existing_aclp);
1228 
1229         aclp = NULL;
1230         if (strcmp(acl_text, SMB_QUOTA_CNTRL_PERM) != 0) {
1231                 if (acl_fromtext(SMB_QUOTA_CNTRL_PERM, &aclp) != 0) {
1232                         free(acl_text);
1233                         (void) unlink(file);
1234                         if (qdir_created)
1235                                 (void) remove(dir);
1236                         return;
1237                 }
1238                 if (acl_set(file, aclp) == -1) {
1239                         free(acl_text);
1240                         (void) unlink(file);
1241                         if (qdir_created)
1242                                 (void) remove(dir);
1243                         acl_free(aclp);
1244                         return;
1245                 }
1246                 acl_free(aclp);
1247         }