remove the use of one switch_to_real_user()
authorroot <root@rcn1.VSOFS1.COM>
Tue, 14 Jul 2009 04:59:44 +0000 (14:59 +1000)
committerroot <root@rcn1.VSOFS1.COM>
Tue, 14 Jul 2009 04:59:44 +0000 (14:59 +1000)
migrate/remote-cache.c

index 76dfcfde03729d58edf0b868a9e5086b126d9e62..f54d730a73905eb5a2696975db29060579704782 100644 (file)
@@ -2847,45 +2847,51 @@ finished:
 
 static int remote_cache_rename(const char *path, const char *newpath)
 {
-       char *new_path = NULL;
        char *old_path = NULL;
-       char *new_newpath = NULL;
        char *old_newpath = NULL;
+       char *old_ppath = NULL;
+       char *old_newppath = NULL;
+       uid_t uid = fuse_get_context()->uid;
+       gid_t gid = fuse_get_context()->gid;
        int ret;
 
+       DEBUG(DEBUG_DEBUG, (__location__ " RENAME %s -> %s\n", path, newpath));
+
        if (!read_write) {
                ret = -EROFS;
                goto finished;
        }
 
-       if (asprintf(&new_path, "%s/%s", cache, path) == -1) {
-               DEBUG(DEBUG_ERR,(__location__ " Failed to malloc new path\n"));
+       if (asprintf(&old_path, "%s/%s", remote, path) == -1) {
+               DEBUG(DEBUG_ERR,(__location__ " Failed to malloc old path\n"));
                ret = -ENOMEM;
                goto finished;
        }
-       if (asprintf(&old_path, "%s/%s", remote, path) == -1) {
-               DEBUG(DEBUG_ERR,(__location__ " Failed to malloc old path\n"));
+       if (asprintf(&old_newpath, "%s/%s", remote, newpath) == -1) {
+               DEBUG(DEBUG_ERR,(__location__ " Failed to malloc old newpath\n"));
                ret = -ENOMEM;
                goto finished;
        }
-       if (asprintf(&new_newpath, "%s/%s", cache, newpath) == -1) {
-               DEBUG(DEBUG_ERR,(__location__ " Failed to malloc new newpath\n"));
+       old_ppath = get_parent_path(old_path);
+       if (old_ppath == NULL) {
                ret = -ENOMEM;
                goto finished;
        }
-       if (asprintf(&old_newpath, "%s/%s", remote, newpath) == -1) {
-               DEBUG(DEBUG_ERR,(__location__ " Failed to malloc old newpath\n"));
+       old_newppath = get_parent_path(old_newpath);
+       if (old_newppath == NULL) {
                ret = -ENOMEM;
                goto finished;
        }
 
+       ret = verify_permission(uid, gid, old_ppath, CAN_WRITE);
+       if (ret != 0) {
+               DEBUG(DEBUG_DEBUG,("SRC directory does not allow rename\n"));
+               goto finished;
+       }
 
-
-       DEBUG(DEBUG_DEBUG, (__location__ " RENAME %s -> %s\n", path, newpath));
-
-       ret = switch_to_real_user();
+       ret = verify_permission(uid, gid, old_newppath, CAN_WRITE);
        if (ret != 0) {
-               DEBUG(DEBUG_ERR, (__location__ " SETEUID failed\n"));
+               DEBUG(DEBUG_DEBUG,("DST directory does not allow rename\n"));
                goto finished;
        }
 
@@ -2896,27 +2902,27 @@ static int remote_cache_rename(const char *path, const char *newpath)
                goto finished;
        }
 
+#if 0
        /* if the link was successful we try to delete any local cached
           entries for this name
        */
-       switch_back_to_root();
        unlink_object(new_path);
        unlink_object(new_newpath);
        unlink_parent_dir_cache(new_path);
+#endif
 
 finished:
-       switch_back_to_root();
        if (old_path != NULL) {
                free(old_path);
        }
-       if (new_path != NULL) {
-               free(new_path);
-       }
        if (old_newpath != NULL) {
                free(old_newpath);
        }
-       if (new_newpath != NULL) {
-               free(new_newpath);
+       if (old_ppath != NULL) {
+               free(old_ppath);
+       }
+       if (old_newppath != NULL) {
+               free(old_newppath);
        }
        return ret;
 }