From 6c4b6ba514c7911bdbfa02bfadbe09799fd3cdaf Mon Sep 17 00:00:00 2001 From: Vinicius Costa Gomes Date: Tue, 23 Mar 2010 19:36:09 -0300 Subject: [PATCH] obexd: obexd core should know nothing about filesystems obexd core should not assume that it is dealing with "real" files. --- obexd/plugins/filesystem.c | 16 +++++++++++ obexd/plugins/ftp.c | 59 ++++++-------------------------------- 2 files changed, 24 insertions(+), 51 deletions(-) diff --git a/obexd/plugins/filesystem.c b/obexd/plugins/filesystem.c index c88d96572..75c1c30f1 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 e9cb96a42..899d46360 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) -- 2.47.3