[PATCH] Allow stat call with capability in vfs_gpfs

Christof Schmitt cs at samba.org
Wed Oct 9 08:31:49 MDT 2013


Hi Abhidnya,

On Wed, Oct 09, 2013 at 10:14:36AM +0530, Abhidnya S Joshi wrote:
> Please find attached patch to handle stat call in vfs_gpfs using 
> capability. stat call will not succeed if READ_ATTR (nfsv4 perm) is not 
> allowed in GPFS but will succeed in NTFS. 

[...]
--- a/source3/modules/vfs_gpfs.c
+++ b/source3/modules/vfs_gpfs.c
@@ -1238,9 +1238,13 @@ static int vfs_gpfs_stat(struct vfs_handle_struct *handle,
 				return -1);
 
 	ret = SMB_VFS_NEXT_STAT(handle, smb_fname);
-	if (ret == -1) {
-		return -1;
+	if (ret == -1 && errno == EACCES) {
+		set_effective_capability(DAC_READ_CAPABILITY);
+		ret = SMB_VFS_NEXT_STAT(handle, smb_fname);
+		drop_effective_capability(DAC_READ_CAPABILITY);
 	}
+	if (ret == -1)
+		return -1;
 
 	if (!config->winattr) {
 		return 0;
@@ -1274,6 +1278,11 @@ static int vfs_gpfs_fstat(struct vfs_handle_struct *handle,
 				return -1);
 
 	ret = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
+	if (ret == -1 && errno == EACCES) {
+		set_effective_capability(DAC_READ_CAPABILITY);
+		ret = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
+		drop_effective_capability(DAC_READ_CAPABILITY);
+	}
 	if (ret == -1) {
 		return -1;
 	}
@@ -1307,6 +1316,11 @@ static int vfs_gpfs_lstat(struct vfs_handle_struct *handle,
 				return -1);
 
 	ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
+	if (ret == -1 && errno == EACCES) {
+		set_effective_capability(DAC_READ_CAPABILITY);
+		ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
+		drop_effective_capability(DAC_READ_CAPABILITY);
+	}
 	if (ret == -1) {
 		return -1;
 	}

Overall this looks good. Is there a reason for trying the stat calls
twice, first without setting the capability and if that fails again
while setting the capability? Always setting the capability for a stat
call would save some lines of code.

Regards,

Christof


More information about the samba-technical mailing list