static NTSTATUS zfs_get_nt_acl_common(struct connection_struct *conn,
TALLOC_CTX *mem_ctx,
const struct smb_filename *smb_fname,
+ const ace_t *acebuf,
+ int naces,
struct SMB4ACL_T **ppacl,
struct zfsacl_config_data *config)
{
- int naces, i;
- ace_t *acebuf;
+ int i;
struct SMB4ACL_T *pacl;
SMB_STRUCT_STAT sbuf;
const SMB_STRUCT_STAT *psbuf = NULL;
}
is_dir = S_ISDIR(psbuf->st_ex_mode);
- /* read the number of file aces */
- if((naces = acl(smb_fname->base_name, ACE_GETACLCNT, 0, NULL)) == -1) {
- if(errno == ENOSYS) {
- DEBUG(9, ("acl(ACE_GETACLCNT, %s): Operation is not "
- "supported on the filesystem where the file "
- "reside\n", smb_fname->base_name));
- } else {
- DEBUG(9, ("acl(ACE_GETACLCNT, %s): %s ", smb_fname->base_name,
- strerror(errno)));
- }
- return map_nt_error_from_unix(errno);
- }
- /* allocate the field of ZFS aces */
mem_ctx = talloc_tos();
- acebuf = (ace_t *) talloc_size(mem_ctx, sizeof(ace_t)*naces);
- if(acebuf == NULL) {
- return NT_STATUS_NO_MEMORY;
- }
- /* read the aces into the field */
- if(acl(smb_fname->base_name, ACE_GETACL, naces, acebuf) < 0) {
- DEBUG(9, ("acl(ACE_GETACL, %s): %s ", smb_fname->base_name,
- strerror(errno)));
- return map_nt_error_from_unix(errno);
- }
+
/* create SMB4ACL data */
if((pacl = smb_create_smb4acl(mem_ctx)) == NULL) {
return NT_STATUS_NO_MEMORY;
static bool zfs_process_smbacl(vfs_handle_struct *handle, files_struct *fsp,
struct SMB4ACL_T *smbacl)
{
- int naces = smb_get_naces(smbacl), i;
+ int naces = smb_get_naces(smbacl), i, rv;
ace_t *acebuf;
struct SMB4ACE_T *smbace;
TALLOC_CTX *mem_ctx;
SMB_ASSERT(i == naces);
/* store acl */
- if(acl(fsp->fsp_name->base_name, ACE_SETACL, naces, acebuf)) {
+ if (fsp->fh->fd != -1) {
+ rv = facl(fsp->fh->fd, ACE_SETACL, naces, acebuf);
+ }
+ else {
+ rv = acl(fsp->fsp_name->base_name, ACE_SETACL, naces, acebuf);
+ }
+ if (rv != 0) {
if(errno == ENOSYS) {
DEBUG(9, ("acl(ACE_SETACL, %s): Operation is not "
"supported on the filesystem where the file "
DEBUG(9, ("acl(ACE_SETACL, %s): %s ", fsp_str_dbg(fsp),
strerror(errno)));
}
- return 0;
+ return false;
}
return True;
zfs_process_smbacl);
}
+static int get_zfsacl(TALLOC_CTX *mem_ctx,
+ const struct smb_filename *smb_fname,
+ ace_t **outbuf)
+{
+ int naces, rv;
+ ace_t *acebuf = NULL;
+
+ naces = acl(smb_fname->base_name, ACE_GETACLCNT, 0, NULL);
+ if (naces == -1) {
+ int dbg_level = 10;
+
+ if (errno == ENOSYS) {
+ dbg_level = 1;
+ }
+ DEBUG(dbg_level, ("acl(ACE_GETACLCNT, %s): %s ",
+ smb_fname->base_name, strerror(errno)));
+ return naces;
+ }
+ acebuf = talloc_size(mem_ctx, sizeof(ace_t)*naces);
+ if (acebuf == NULL) {
+ errno = ENOMEM;
+ return -1;
+ }
+
+ rv = acl(smb_fname->base_name, ACE_GETACL, naces, acebuf);
+ if (rv == -1) {
+ DBG_DEBUG("acl(ACE_GETACL, %s) failed: %s ",
+ smb_fname->base_name, strerror(errno));
+ return -1;
+ }
+
+ *outbuf = acebuf;
+ return naces;
+}
+
+static int fget_zfsacl(TALLOC_CTX *mem_ctx,
+ struct files_struct *fsp,
+ ace_t **outbuf)
+{
+ int naces, rv;
+ ace_t *acebuf = NULL;
+
+ if (fsp->fh->fd == -1) {
+ return get_zfsacl(mem_ctx, fsp->fsp_name, outbuf);
+ }
+
+ naces = facl(fsp->fh->fd, ACE_GETACLCNT, 0, NULL);
+ if (naces == -1) {
+ int dbg_level = 10;
+
+ if (errno == ENOSYS) {
+ dbg_level = 1;
+ }
+ DEBUG(dbg_level, ("facl(ACE_GETACLCNT, %s): %s ",
+ fsp_str_dbg(fsp), strerror(errno)));
+ return naces;
+ }
+
+ acebuf = talloc_size(mem_ctx, sizeof(ace_t)*naces);
+ if (acebuf == NULL) {
+ errno = ENOMEM;
+ return -1;
+ }
+
+ rv = facl(fsp->fh->fd, ACE_GETACL, naces, acebuf);
+ if (rv == -1) {
+ DBG_DEBUG("acl(ACE_GETACL, %s): %s ",
+ fsp_str_dbg(fsp), strerror(errno));
+ return -1;
+ }
+
+ *outbuf = acebuf;
+ return naces;
+}
+
static NTSTATUS zfsacl_fget_nt_acl(struct vfs_handle_struct *handle,
struct files_struct *fsp,
uint32_t security_info,
struct SMB4ACL_T *pacl;
NTSTATUS status;
struct zfsacl_config_data *config = NULL;
+ ace_t *acebuf = NULL;
+ int naces;
SMB_VFS_HANDLE_GET_DATA(handle, config,
struct zfsacl_config_data,
TALLOC_CTX *frame = talloc_stackframe();
- status = zfs_get_nt_acl_common(handle->conn, frame,
- fsp->fsp_name, &pacl, config);
- if (!NT_STATUS_IS_OK(status)) {
+ naces = fget_zfsacl(talloc_tos(), fsp, &acebuf);
+ if (naces == -1) {
+ status = map_nt_error_from_unix(errno);
TALLOC_FREE(frame);
if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {
return status;
return NT_STATUS_OK;
}
+ status = zfs_get_nt_acl_common(handle->conn,
+ frame,
+ fsp->fsp_name,
+ acebuf,
+ naces,
+ &pacl,
+ config);
+ if (!NT_STATUS_IS_OK(status)) {
+ TALLOC_FREE(frame);
+ return status;
+ }
+
status = smb_fget_nt_acl_nfs4(fsp, NULL, security_info, mem_ctx,
ppdesc, pacl);
TALLOC_FREE(frame);
NTSTATUS status;
struct zfsacl_config_data *config = NULL;
TALLOC_CTX *frame = NULL;
+ int naces;
+ ace_t *acebuf = NULL;
SMB_ASSERT(dirfsp == handle->conn->cwd_fsp);
frame = talloc_stackframe();
- status = zfs_get_nt_acl_common(handle->conn,
- frame,
- smb_fname,
- &pacl,
- config);
- if (!NT_STATUS_IS_OK(status)) {
+ naces = get_zfsacl(frame, smb_fname, &acebuf);
+ if (naces == -1) {
+ status = map_nt_error_from_unix(errno);
TALLOC_FREE(frame);
if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {
return status;
return NT_STATUS_OK;
}
+ status = zfs_get_nt_acl_common(handle->conn,
+ frame,
+ smb_fname,
+ acebuf,
+ naces,
+ &pacl,
+ config);
+ if (!NT_STATUS_IS_OK(status)) {
+ TALLOC_FREE(frame);
+ return status;
+ }
+
status = smb_get_nt_acl_nfs4(handle->conn,
smb_fname,
NULL,