Let SMB clients set the file creation time.
authorJames Peach <jpeach@apple.com>
Mon, 15 Oct 2007 21:46:17 +0000 (14:46 -0700)
committerJames Peach <jpeach@apple.com>
Mon, 15 Oct 2007 21:46:17 +0000 (14:46 -0700)
This patch adds support for the protocol calls that sre used to set
the file creation time. Note that this does not trigger a file
change notification, so some refactoring is required.

source/smbd/trans2.c

index d266b95e5450d5e80bc33b949dc890fec9596b22..6f4866bc9d5d70718240a8d592b6b264b7a479ea 100644 (file)
@@ -4823,6 +4823,7 @@ static NTSTATUS smb_set_info_standard(connection_struct *conn,
                                        const SMB_STRUCT_STAT *psbuf)
 {
        struct timespec ts[2];
+       time_t create_time;
 
        if (total_data < 12) {
                return NT_STATUS_INVALID_PARAMETER;
@@ -4833,6 +4834,14 @@ static NTSTATUS smb_set_info_standard(connection_struct *conn,
        /* write time */
        ts[1] = convert_time_t_to_timespec(srv_make_unix_date2(pdata+l1_fdateLastWrite));
 
+       /* create time */
+       /* XXX: this code should be in smb_set_file_time() -- jpeach */
+       create_time = srv_make_unix_date2(pdata+l1_fdateCreation);
+       /* They want to set the create time and the share is writable */
+       if ((!null_mtime(create_time)) && (CAN_WRITE(conn)) && !fsp) {
+               SMB_VFS_SET_CREATE_TIME(conn, fname, create_time);
+       }
+
        DEBUG(10,("smb_set_info_standard: file %s\n",
                fname ? fname : fsp->fsp_name ));
 
@@ -4854,6 +4863,7 @@ static NTSTATUS smb_set_file_basic_info(connection_struct *conn,
                                        const char *fname,
                                        SMB_STRUCT_STAT *psbuf)
 {
+       time_t create_time;
        /* Patch to do this correctly from Paul Eggert <eggert@twinsun.com>. */
        struct timespec write_time;
        struct timespec changed_time;
@@ -4875,7 +4885,12 @@ static NTSTATUS smb_set_file_basic_info(connection_struct *conn,
                return status;
        }
 
-       /* Ignore create time at offset pdata. */
+       /* create time */
+       create_time = convert_timespec_to_time_t(interpret_long_date(pdata+0));
+       /* They want to set the create time and the share is writable */
+       if ((!null_mtime(create_time)) && (CAN_WRITE(conn)) && !fsp) {
+               SMB_VFS_SET_CREATE_TIME(conn, fname, create_time);
+       }
 
        /* access time */
        ts[0] = interpret_long_date(pdata+8);
@@ -5298,6 +5313,7 @@ static NTSTATUS smb_set_file_unix_info2(connection_struct *conn,
                                        const char *fname,
                                        SMB_STRUCT_STAT *psbuf)
 {
+       time_t create_time;
        NTSTATUS status;
        uint32 smb_fflags;
        uint32 smb_fmask;
@@ -5315,6 +5331,12 @@ static NTSTATUS smb_set_file_unix_info2(connection_struct *conn,
                return status;
        }
 
+       create_time = convert_timespec_to_time_t(interpret_long_date(pdata+100)); /* create_time */
+       /* They want to set the create time and the share is writable */
+       if ((!null_mtime(create_time)) && (CAN_WRITE(conn)) && !fsp) {
+               SMB_VFS_SET_CREATE_TIME(conn, fname, create_time);
+       }
+
        smb_fflags = IVAL(pdata, 108);
        smb_fmask = IVAL(pdata, 112);