Extend NTIMES to allow setting create_time
[metze/samba/wip.git] / source3 / modules / vfs_recycle.c
index fef65efa7790cd52ea79673e2fd5f1a7cb1bfc13..2b0edcdb4a198aaa2a9ce382c694902b77e526f0 100644 (file)
@@ -269,6 +269,7 @@ static bool recycle_create_dir(vfs_handle_struct *handle, const char *dname)
        char *token;
        char *tok_str;
        bool ret = False;
+       char *saveptr;
 
        mode = recycle_directory_mode(handle);
 
@@ -286,7 +287,8 @@ static bool recycle_create_dir(vfs_handle_struct *handle, const char *dname)
        }
 
        /* Create directory tree if neccessary */
-       for(token = strtok(tok_str, "/"); token; token = strtok(NULL, "/")) {
+       for(token = strtok_r(tok_str, "/", &saveptr); token;
+           token = strtok_r(NULL, "/", &saveptr)) {
                safe_strcat(new_dir, token, len);
                if (recycle_directory_exist(handle, new_dir))
                        DEBUG(10, ("recycle: dir %s already exists\n", new_dir));
@@ -389,19 +391,21 @@ static void recycle_do_touch(vfs_handle_struct *handle, const char *fname,
                             bool touch_mtime)
 {
        SMB_STRUCT_STAT st;
-       struct timespec ts[2];
+       struct smb_file_time ft;
        int ret, err;
 
+       ZERO_STRUCT(ft);
+
        if (SMB_VFS_NEXT_STAT(handle, fname, &st) != 0) {
                DEBUG(0,("recycle: stat for %s returned %s\n",
                         fname, strerror(errno)));
                return;
        }
-       ts[0] = timespec_current(); /* atime */
-       ts[1] = touch_mtime ? ts[0] : get_mtimespec(&st); /* mtime */
+       ft.atime = timespec_current(); /* atime */
+       ft.mtime = touch_mtime ? ft.atime : get_mtimespec(&st); /* mtime */
 
        become_root();
-       ret = SMB_VFS_NEXT_NTIMES(handle, fname, ts);
+       ret = SMB_VFS_NEXT_NTIMES(handle, fname, &ft);
        err = errno;
        unbecome_root();
        if (ret == -1 ) {
@@ -410,8 +414,6 @@ static void recycle_do_touch(vfs_handle_struct *handle, const char *fname,
        }
 }
 
-extern userdom_struct current_user_info;
-
 /**
  * Check if file should be recycled
  **/
@@ -430,10 +432,11 @@ static int recycle_unlink(vfs_handle_struct *handle, const char *file_name)
        int rc = -1;
 
        repository = talloc_sub_advanced(NULL, lp_servicename(SNUM(conn)),
-                                       conn->user,
-                                       conn->connectpath, conn->gid,
-                                       get_current_username(),
-                                       current_user_info.domain,
+                                       conn->server_info->unix_name,
+                                       conn->connectpath,
+                                       conn->server_info->utok.gid,
+                                       conn->server_info->sanitized_username,
+                                       pdb_get_domain(conn->server_info->sam_account),
                                        recycle_repository(handle));
        ALLOC_CHECK(repository, done);
        /* shouldn't we allow absolute path names here? --metze */
@@ -524,7 +527,9 @@ static int recycle_unlink(vfs_handle_struct *handle, const char *file_name)
        }
 
        if (recycle_keep_dir_tree(handle) == True) {
-               asprintf(&temp_name, "%s/%s", repository, path_name);
+               if (asprintf(&temp_name, "%s/%s", repository, path_name) == -1) {
+                       ALLOC_CHECK(temp_name, done);
+               }
        } else {
                temp_name = SMB_STRDUP(repository);
        }
@@ -542,8 +547,9 @@ static int recycle_unlink(vfs_handle_struct *handle, const char *file_name)
                }
        }
 
-       asprintf(&final_name, "%s/%s", temp_name, base);
-       ALLOC_CHECK(final_name, done);
+       if (asprintf(&final_name, "%s/%s", temp_name, base) == -1) {
+               ALLOC_CHECK(final_name, done);
+       }
        DEBUG(10, ("recycle: recycled file name: %s\n", final_name));           /* new filename with path */
 
        /* check if we should delete file from recycle bin */
@@ -560,7 +566,9 @@ static int recycle_unlink(vfs_handle_struct *handle, const char *file_name)
        i = 1;
        while (recycle_file_exist(handle, final_name)) {
                SAFE_FREE(final_name);
-               asprintf(&final_name, "%s/Copy #%d of %s", temp_name, i++, base);
+               if (asprintf(&final_name, "%s/Copy #%d of %s", temp_name, i++, base) == -1) {
+                       ALLOC_CHECK(final_name, done);
+               }
        }
 
        DEBUG(10, ("recycle: Moving %s to %s\n", file_name, final_name));