1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-22 22:04:08 +03:00

smbd: Introduce srv_put_dos_date2_ts()

All but one uses of srv_put_dos_date2() converted from struct
timespec. Put that into a new routine.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Guenther Deschner <gd@samba.org>
This commit is contained in:
Volker Lendecke 2023-11-26 15:17:45 +01:00 committed by Günther Deschner
parent e3b4073d3c
commit d5a0d6f7e9
5 changed files with 43 additions and 38 deletions

View File

@ -239,6 +239,7 @@ char *timeval_string(TALLOC_CTX *ctx, const struct timeval *tp, bool hires);
char *current_timestring(TALLOC_CTX *ctx, bool hires);
void srv_put_dos_date(char *buf,int offset,time_t unixdate);
void srv_put_dos_date2(char *buf,int offset, time_t unixdate);
void srv_put_dos_date2_ts(char *buf, int offset, struct timespec unix_ts);
void srv_put_dos_date3(char *buf,int offset,time_t unixdate);
void round_timespec(enum timestamp_set_resolution res, struct timespec *ts);
void put_long_date_timespec(enum timestamp_set_resolution res, char *p, struct timespec ts);

View File

@ -134,6 +134,12 @@ void srv_put_dos_date2(char *buf,int offset, time_t unixdate)
push_dos_date2((uint8_t *)buf, offset, unixdate, server_zone_offset);
}
void srv_put_dos_date2_ts(char *buf, int offset, struct timespec unix_ts)
{
time_t unixdate = convert_timespec_to_time_t(unix_ts);
srv_put_dos_date2(buf, offset, unixdate);
}
void srv_put_dos_date3(char *buf,int offset,time_t unixdate)
{
push_dos_date3((uint8_t *)buf, offset, unixdate, server_zone_offset);

View File

@ -7063,12 +7063,14 @@ void reply_getattrE(struct smb_request *req)
reply_smb1_outbuf(req, 11, 0);
create_ts = get_create_timespec(conn, fsp, fsp->fsp_name);
srv_put_dos_date2((char *)req->outbuf, smb_vwv0, create_ts.tv_sec);
srv_put_dos_date2((char *)req->outbuf, smb_vwv2,
convert_timespec_to_time_t(fsp->fsp_name->st.st_ex_atime));
srv_put_dos_date2_ts((char *)req->outbuf, smb_vwv0, create_ts);
srv_put_dos_date2_ts((char *)req->outbuf,
smb_vwv2,
fsp->fsp_name->st.st_ex_atime);
/* Should we check pending modtime here ? JRA */
srv_put_dos_date2((char *)req->outbuf, smb_vwv4,
convert_timespec_to_time_t(fsp->fsp_name->st.st_ex_mtime));
srv_put_dos_date2_ts((char *)req->outbuf,
smb_vwv4,
fsp->fsp_name->st.st_ex_mtime);
if (mode & FILE_ATTRIBUTE_DIRECTORY) {
SIVAL(req->outbuf, smb_vwv6, 0);

View File

@ -512,7 +512,7 @@ static void call_trans2open(connection_struct *conn,
char *pname;
char *fname = NULL;
off_t size=0;
int fattr=0,mtime=0;
int fattr = 0;
SMB_INO_T inode = 0;
int smb_action = 0;
struct files_struct *dirfsp = NULL;
@ -722,7 +722,6 @@ static void call_trans2open(connection_struct *conn,
size = get_file_size_stat(&smb_fname->st);
fattr = fdos_mode(fsp);
mtime = convert_timespec_to_time_t(smb_fname->st.st_ex_mtime);
inode = smb_fname->st.st_ex_ino;
if (fattr & FILE_ATTRIBUTE_DIRECTORY) {
close_file_free(req, &fsp, ERROR_CLOSE);
@ -740,7 +739,7 @@ static void call_trans2open(connection_struct *conn,
SSVAL(params,0,fsp->fnum);
SSVAL(params,2,fattr);
srv_put_dos_date2(params,4, mtime);
srv_put_dos_date2_ts(params, 4, smb_fname->st.st_ex_mtime);
SIVAL(params,8, (uint32_t)size);
SSVAL(params,12,deny_mode);
SSVAL(params,14,0); /* open_type - file or directory. */

View File

@ -1047,7 +1047,6 @@ static NTSTATUS smbd_marshall_dir_entry(TALLOC_CTX *ctx,
struct timespec adate_ts = {0};
struct timespec cdate_ts = {0};
struct timespec create_date_ts = {0};
time_t mdate = (time_t)0, adate = (time_t)0, create_date = (time_t)0;
char *nameptr;
char *last_entry_ptr;
bool was_8_3;
@ -1093,10 +1092,6 @@ static NTSTATUS smbd_marshall_dir_entry(TALLOC_CTX *ctx,
dos_filetime_timespec(&cdate_ts);
}
create_date = convert_timespec_to_time_t(create_date_ts);
mdate = convert_timespec_to_time_t(mdate_ts);
adate = convert_timespec_to_time_t(adate_ts);
/* align the record */
SMB_ASSERT(align >= 1);
@ -1136,9 +1131,9 @@ static NTSTATUS smbd_marshall_dir_entry(TALLOC_CTX *ctx,
SIVAL(p,0,reskey);
p += 4;
}
srv_put_dos_date2(p,0,create_date);
srv_put_dos_date2(p,4,adate);
srv_put_dos_date2(p,8,mdate);
srv_put_dos_date2_ts(p, 0, create_date_ts);
srv_put_dos_date2_ts(p, 4, adate_ts);
srv_put_dos_date2_ts(p, 8, mdate_ts);
SIVAL(p,12,(uint32_t)file_size);
SIVAL(p,16,(uint32_t)allocation_size);
SSVAL(p,20,mode);
@ -1175,9 +1170,9 @@ static NTSTATUS smbd_marshall_dir_entry(TALLOC_CTX *ctx,
SIVAL(p,0,reskey);
p += 4;
}
srv_put_dos_date2(p,0,create_date);
srv_put_dos_date2(p,4,adate);
srv_put_dos_date2(p,8,mdate);
srv_put_dos_date2_ts(p, 0, create_date_ts);
srv_put_dos_date2_ts(p, 4, adate_ts);
srv_put_dos_date2_ts(p, 8, mdate_ts);
SIVAL(p,12,(uint32_t)file_size);
SIVAL(p,16,(uint32_t)allocation_size);
SSVAL(p,20,mode);
@ -1224,9 +1219,9 @@ static NTSTATUS smbd_marshall_dir_entry(TALLOC_CTX *ctx,
SIVAL(p,0,reskey);
p += 4;
}
srv_put_dos_date2(p,0,create_date);
srv_put_dos_date2(p,4,adate);
srv_put_dos_date2(p,8,mdate);
srv_put_dos_date2_ts(p, 0, create_date_ts);
srv_put_dos_date2_ts(p, 4, adate_ts);
srv_put_dos_date2_ts(p, 8, mdate_ts);
SIVAL(p,12,(uint32_t)file_size);
SIVAL(p,16,(uint32_t)allocation_size);
SSVAL(p,20,mode);
@ -2976,7 +2971,6 @@ NTSTATUS smbd_do_qfilepathinfo(connection_struct *conn,
char *dstart, *dend;
unsigned int data_size;
struct timespec create_time_ts, mtime_ts, atime_ts, ctime_ts;
time_t create_time, mtime, atime, c_time;
SMB_STRUCT_STAT *psbuf = NULL;
SMB_STRUCT_STAT *base_sp = NULL;
char *p;
@ -3076,11 +3070,6 @@ NTSTATUS smbd_do_qfilepathinfo(connection_struct *conn,
dos_filetime_timespec(&ctime_ts);
}
create_time = convert_timespec_to_time_t(create_time_ts);
mtime = convert_timespec_to_time_t(mtime_ts);
atime = convert_timespec_to_time_t(atime_ts);
c_time = convert_timespec_to_time_t(ctime_ts);
p = strrchr_m(smb_fname->base_name,'/');
if (!p)
base_name = smb_fname->base_name;
@ -3152,9 +3141,15 @@ NTSTATUS smbd_do_qfilepathinfo(connection_struct *conn,
case SMB_INFO_STANDARD:
DEBUG(10,("smbd_do_qfilepathinfo: SMB_INFO_STANDARD\n"));
data_size = 22;
srv_put_dos_date2(pdata,l1_fdateCreation,create_time);
srv_put_dos_date2(pdata,l1_fdateLastAccess,atime);
srv_put_dos_date2(pdata,l1_fdateLastWrite,mtime); /* write time */
srv_put_dos_date2_ts(pdata,
l1_fdateCreation,
create_time_ts);
srv_put_dos_date2_ts(pdata,
l1_fdateLastAccess,
atime_ts);
srv_put_dos_date2_ts(pdata,
l1_fdateLastWrite,
mtime_ts); /* write time */
SIVAL(pdata,l1_cbFile,(uint32_t)file_size);
SIVAL(pdata,l1_cbFileAlloc,(uint32_t)allocation_size);
SSVAL(pdata,l1_attrFile,mode);
@ -3166,9 +3161,11 @@ NTSTATUS smbd_do_qfilepathinfo(connection_struct *conn,
estimate_ea_size(smb_fname->fsp);
DEBUG(10,("smbd_do_qfilepathinfo: SMB_INFO_QUERY_EA_SIZE\n"));
data_size = 26;
srv_put_dos_date2(pdata,0,create_time);
srv_put_dos_date2(pdata,4,atime);
srv_put_dos_date2(pdata,8,mtime); /* write time */
srv_put_dos_date2_ts(pdata, 0, create_time_ts);
srv_put_dos_date2_ts(pdata, 4, atime_ts);
srv_put_dos_date2_ts(pdata,
8,
mtime_ts); /* write time */
SIVAL(pdata,12,(uint32_t)file_size);
SIVAL(pdata,16,(uint32_t)allocation_size);
SSVAL(pdata,20,mode);
@ -3285,10 +3282,10 @@ NTSTATUS smbd_do_qfilepathinfo(connection_struct *conn,
SIVAL(pdata,32,mode);
DEBUG(5,("SMB_QFBI - "));
DEBUG(5,("create: %s ", ctime(&create_time)));
DEBUG(5,("access: %s ", ctime(&atime)));
DEBUG(5,("write: %s ", ctime(&mtime)));
DEBUG(5,("change: %s ", ctime(&c_time)));
DEBUG(5,("create: %s ", ctime(&create_time_ts.tv_sec)));
DEBUG(5,("access: %s ", ctime(&atime_ts.tv_sec)));
DEBUG(5,("write: %s ", ctime(&mtime_ts.tv_sec)));
DEBUG(5,("change: %s ", ctime(&ctime_ts.tv_sec)));
DEBUG(5,("mode: %x\n", mode));
*fixed_portion = data_size;
break;