[SCM] Samba Shared Repository - branch master updated

Jeremy Allison jra at samba.org
Wed Jan 27 02:36:03 UTC 2016


The branch, master has been updated
       via  465c3d9 smbd quotas: avoid stat of foreign file systems
       via  c6ed45f s3-lib: introduce sys_realpath()
      from  f0c43ce dbwrap_file: fix use of read_data()

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 465c3d9a4e1a30e334922149f3ed1057f09fe169
Author: Uri Simchoni <uri at samba.org>
Date:   Mon Jan 18 23:34:48 2016 +0200

    smbd quotas: avoid stat of foreign file systems
    
    When determining the block device of our file system, avoid
    stat'ing paths which are definitely not the mount point of
    our file system. This is done to avoid stalling smbd due to
    unresponsive network file systems (e.g. NFS) which are not
    related to the SMB shares.
    
    See discussion in samba-technical for vfs_fileid:
    https://lists.samba.org/archive/samba-technical/2016-January/111553.html
    
    Signed-off-by: Uri Simchoni <uri at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    
    Autobuild-User(master): Jeremy Allison <jra at samba.org>
    Autobuild-Date(master): Wed Jan 27 03:35:48 CET 2016 on sn-devel-144

commit c6ed45fe710924f847f46d505ceabfec21e7cf38
Author: Uri Simchoni <uri at samba.org>
Date:   Mon Jan 18 23:34:06 2016 +0200

    s3-lib: introduce sys_realpath()
    
    Add sys_realpath() function that captures the OS variations
    on realpath().
    
    Signed-off-by: Uri Simchoni <uri at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 source3/include/proto.h       |  1 +
 source3/lib/sysquotas.c       | 71 +++++++++++++++++++++++++++++++++++++------
 source3/lib/system.c          | 25 +++++++++++++++
 source3/modules/vfs_default.c | 15 +--------
 4 files changed, 88 insertions(+), 24 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/include/proto.h b/source3/include/proto.h
index e18aaf4..09e9915 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -264,6 +264,7 @@ int sys_setxattr (const char *path, const char *name, const void *value, size_t
 int sys_fsetxattr (int filedes, const char *name, const void *value, size_t size, int flags);
 uint32_t unix_dev_major(SMB_DEV_T dev);
 uint32_t unix_dev_minor(SMB_DEV_T dev);
+char *sys_realpath(const char *path);
 #if 0
 int sys_get_number_of_cores(void);
 #endif
diff --git a/source3/lib/sysquotas.c b/source3/lib/sysquotas.c
index 2ef1d1b..bacc4b2 100644
--- a/source3/lib/sysquotas.c
+++ b/source3/lib/sysquotas.c
@@ -40,35 +40,84 @@
 
 #endif /* NO_QUOTACTL_USED */
 
-#ifdef HAVE_MNTENT
+#if defined(HAVE_MNTENT) && defined(HAVE_REALPATH)
 static int sys_path_to_bdev(const char *path, char **mntpath, char **bdev, char **fs)
 {
 	int ret = -1;
 	SMB_STRUCT_STAT S;
 	FILE *fp;
-	struct mntent *mnt;
+	struct mntent *mnt = NULL;
 	SMB_DEV_T devno;
+	char *stat_mntpath = NULL;
+	char *p;
 
 	/* find the block device file */
-
-	if (!path||!mntpath||!bdev||!fs)
-		smb_panic("sys_path_to_bdev: called with NULL pointer");
-
 	(*mntpath) = NULL;
 	(*bdev) = NULL;
 	(*fs) = NULL;
-	
-	if ( sys_stat(path, &S, false) == -1 )
-		return (-1);
+
+	if (sys_stat(path, &S, false) != 0) {
+		return -1;
+	}
 
 	devno = S.st_ex_dev ;
 
+	stat_mntpath = sys_realpath(path);
+	if (stat_mntpath == NULL) {
+		DBG_WARNING("realpath(%s) failed - %s\n", path,
+			    strerror(errno));
+		goto out;
+	}
+
+	if (sys_stat(stat_mntpath, &S, false) != 0) {
+		DBG_WARNING("cannot stat real path %s - %s\n", stat_mntpath,
+			    strerror(errno));
+		goto out;
+	}
+
+	if (S.st_ex_dev != devno) {
+		DBG_WARNING("device on real path has changed\n");
+		goto out;
+	}
+
+	while (true) {
+		p = strrchr(stat_mntpath, '/');
+		if (p == NULL) {
+			DBG_ERR("realpath for %s does not begin with a '/'\n",
+				path);
+			goto out;
+		}
+
+		if (p == stat_mntpath) {
+			++p;
+		}
+
+		*p = 0;
+		if (sys_stat(stat_mntpath, &S, false) != 0) {
+			DBG_WARNING("cannot stat real path component %s - %s\n",
+				    stat_mntpath, strerror(errno));
+			goto out;
+		}
+		if (S.st_ex_dev != devno) {
+			*p = '/';
+			break;
+		}
+
+		if (p <= stat_mntpath + 1) {
+			break;
+		}
+	}
+
 	fp = setmntent(MOUNTED,"r");
 	if (fp == NULL) {
-		return -1;
+		goto out;
 	}
   
 	while ((mnt = getmntent(fp))) {
+		if (!strequal(mnt->mnt_dir, stat_mntpath)) {
+			continue;
+		}
+
 		if ( sys_stat(mnt->mnt_dir, &S, false) == -1 )
 			continue ;
 
@@ -91,6 +140,8 @@ static int sys_path_to_bdev(const char *path, char **mntpath, char **bdev, char
 
 	endmntent(fp) ;
 
+out:
+	SAFE_FREE(stat_mntpath);
 	return ret;
 }
 /* #endif HAVE_MNTENT */
diff --git a/source3/lib/system.c b/source3/lib/system.c
index e54b946..0351e37 100644
--- a/source3/lib/system.c
+++ b/source3/lib/system.c
@@ -1236,6 +1236,31 @@ uint32_t unix_dev_minor(SMB_DEV_T dev)
 #endif
 }
 
+/**************************************************************************
+ Wrapper for realpath.
+****************************************************************************/
+
+char *sys_realpath(const char *path)
+{
+	char *result;
+
+#ifdef REALPATH_TAKES_NULL
+	result = realpath(path, NULL);
+#else
+	result = SMB_MALLOC_ARRAY(char, PATH_MAX + 1);
+	if (result) {
+		char *resolved_path = realpath(path, result);
+		if (!resolved_path) {
+			SAFE_FREE(result);
+		} else {
+			/* SMB_ASSERT(result == resolved_path) ? */
+			result = resolved_path;
+		}
+	}
+#endif
+	return result;
+}
+
 #if 0
 /*******************************************************************
  Return the number of CPUs.
diff --git a/source3/modules/vfs_default.c b/source3/modules/vfs_default.c
index 2eb9a17..762624b 100644
--- a/source3/modules/vfs_default.c
+++ b/source3/modules/vfs_default.c
@@ -2145,20 +2145,7 @@ static char *vfswrap_realpath(vfs_handle_struct *handle, const char *path)
 	char *result;
 
 	START_PROFILE(syscall_realpath);
-#ifdef REALPATH_TAKES_NULL
-	result = realpath(path, NULL);
-#else
-	result = SMB_MALLOC_ARRAY(char, PATH_MAX+1);
-	if (result) {
-		char *resolved_path = realpath(path, result);
-		if (!resolved_path) {
-			SAFE_FREE(result);
-		} else {
-			/* SMB_ASSERT(result == resolved_path) ? */
-			result = resolved_path;
-		}
-	}
-#endif
+	result = sys_realpath(path);
 	END_PROFILE(syscall_realpath);
 	return result;
 }


-- 
Samba Shared Repository



More information about the samba-cvs mailing list