Diff between e265df74043faeaac9747583e785c257053f0c91 and 6c4b6ba514c7911bdbfa02bfadbe09799fd3cdaf

Changed Files

File Additions Deletions Status
obexd/plugins/filesystem.c +16 -0 modified
obexd/plugins/ftp.c +8 -51 modified

Full Patch

diff --git a/obexd/plugins/filesystem.c b/obexd/plugins/filesystem.c
index c88d965..75c1c30 100644
--- a/obexd/plugins/filesystem.c
+++ b/obexd/plugins/filesystem.c
@@ -126,8 +126,11 @@ static gchar *file_stat_line(gchar *filename, struct stat *fstat,
 static gpointer filesystem_open(const char *name, int oflag, mode_t mode,
 		gpointer context, size_t *size, int *err)
 {
+	struct obex_session *os = context;
 	struct stat stats;
 	struct statvfs buf;
+	const char *root_folder, *folder;
+	gboolean root;
 	int fd = open(name, oflag, mode);
 
 	if (fd < 0) {
@@ -142,6 +145,19 @@ static gpointer filesystem_open(const char *name, int oflag, mode_t mode,
 		goto failed;
 	}
 
+	root_folder = obex_get_root_folder(os);
+	folder = g_path_get_dirname(name);
+	root = g_strcmp0(folder, root_folder);
+
+	if (!root || obex_get_symlinks(os)) {
+		if (S_ISLNK(stats.st_mode)) {
+			if (err)
+				*err = -EPERM;
+			goto failed;
+		}
+
+	}
+
 	if (oflag == O_RDONLY) {
 		if (size)
 			*size = stats.st_size;
diff --git a/obexd/plugins/ftp.c b/obexd/plugins/ftp.c
index e9cb96a..899d463 100644
--- a/obexd/plugins/ftp.c
+++ b/obexd/plugins/ftp.c
@@ -162,10 +162,10 @@ static gint get_by_type(struct ftp_session *ftp, const gchar *type)
 	const char *capability = obex_get_capability_path(os);
 
 	if (type == NULL)
-		return -ENOENT;
+		return obex_stream_start(os, ftp->folder, os);
 
 	if (g_str_equal(type, CAP_TYPE))
-		return obex_stream_start(os, capability, NULL);
+		return obex_stream_start(os, capability, os);
 
 	if (g_str_equal(type, LST_TYPE))
 		return obex_stream_start(os, ftp->folder, os);
@@ -173,31 +173,6 @@ static gint get_by_type(struct ftp_session *ftp, const gchar *type)
 	return -ENOENT;
 }
 
-static gint ftp_prepare_get(struct ftp_session *ftp, gchar *file)
-{
-	struct obex_session *os = ftp->os;
-	const char *root_folder = obex_get_root_folder(os);
-	gboolean root;
-
-	root = g_str_equal(root_folder, ftp->folder);
-
-	if (!root || !obex_get_symlinks(os)) {
-		struct stat dstat;
-		gint err;
-
-		if (lstat(file, &dstat) < 0) {
-			err = -errno;
-			debug("lstat: %s(%d)", strerror(errno), errno);
-			return err;
-		}
-
-		if (S_ISLNK(dstat.st_mode))
-			return -EPERM;
-	}
-
-	return obex_stream_start(os, file, NULL);
-}
-
 static gpointer ftp_connect(struct obex_session *os, int *err)
 {
 	struct ftp_session *ftp;
@@ -222,34 +197,16 @@ static int ftp_get(struct obex_session *os, obex_object_t *obj,
 {
 	struct ftp_session *ftp = user_data;
 	const char *type = obex_get_type(os);
-	const char *name = obex_get_name(os);
-	gint err;
-	gchar *path;
-
-	if (ftp->folder == NULL) {
-		err = -ENOENT;
-		goto fail;
-	}
-
-	err = get_by_type(ftp, type);
-	if (err < 0) {
-		if (!name)
-			goto fail;
-
-		path = g_build_filename(ftp->folder, name, NULL);
+	int ret;
 
-		err = ftp_prepare_get(ftp, path);
+	if (ftp->folder == NULL)
+		return -ENOENT;
 
-		g_free(path);
-
-		if (err < 0)
-			goto fail;
-	}
+	ret = get_by_type(ftp, type);
+	if (ret < 0)
+		return ret;
 
 	return 0;
-
-fail:
-	return err;
 }
 
 static gint ftp_delete(struct ftp_session *ftp, const char *name)