Date/Time für NCP22/25
All checks were successful
Source release / source-package (push) Successful in 36s
All checks were successful
Source release / source-package (push) Successful in 36s
This commit is contained in:
114
src/connect.c
114
src/connect.c
@@ -1238,6 +1238,110 @@ time_t nw_2_un_time(uint8 *d, uint8 *t)
|
||||
return(mktime(&s_tm));
|
||||
}
|
||||
|
||||
static void un_time_2_nw_parts(time_t t, uint16 *date, uint16 *timev)
|
||||
{
|
||||
uint8 b[2];
|
||||
|
||||
if (date) {
|
||||
un_date_2_nw(t, b, 0);
|
||||
*date = (uint16)GET_16(b);
|
||||
}
|
||||
if (timev) {
|
||||
un_time_2_nw(t, b, 0);
|
||||
*timev = (uint16)GET_16(b);
|
||||
}
|
||||
}
|
||||
|
||||
static time_t nw_2_un_time_parts(uint16 xdate, uint16 xtime)
|
||||
{
|
||||
int year = (xdate >> 9) + 80;
|
||||
int month = (xdate >> 5) & 0x0f;
|
||||
int day = xdate & 0x1f;
|
||||
int hour = xtime >> 11;
|
||||
int minu = (xtime >> 5) & 0x3f;
|
||||
int sec = (xtime & 0x1f) << 1;
|
||||
struct tm s_tm;
|
||||
|
||||
if (month < 1 || month > 12 || day < 1 || day > 31 ||
|
||||
hour > 23 || minu > 59 || sec > 59)
|
||||
return((time_t)-1);
|
||||
|
||||
memset(&s_tm, 0, sizeof(s_tm));
|
||||
s_tm.tm_year = year;
|
||||
s_tm.tm_mon = month - 1;
|
||||
s_tm.tm_mday = day;
|
||||
s_tm.tm_hour = hour;
|
||||
s_tm.tm_min = minu;
|
||||
s_tm.tm_sec = sec;
|
||||
s_tm.tm_isdst = -1;
|
||||
return(mktime(&s_tm));
|
||||
}
|
||||
|
||||
#define DM_MODIFY_DATE 0x0100UL
|
||||
#define DM_MODIFY_TIME 0x0200UL
|
||||
#define DM_LAST_ACCESS_DATE 0x0800UL
|
||||
#define DM_NCP22_25_TIME_BITS \
|
||||
(DM_MODIFY_DATE | DM_MODIFY_TIME | DM_LAST_ACCESS_DATE)
|
||||
|
||||
static int set_ncp22_25_times(int volume, char *unixname, struct stat *stb,
|
||||
NW_SET_DIR_INFO *f, uint32 change_mask,
|
||||
int is_dir)
|
||||
{
|
||||
uint16 mdate;
|
||||
uint16 mtimev;
|
||||
uint16 adate;
|
||||
uint16 atimev;
|
||||
struct utimbuf ut;
|
||||
|
||||
if (!(change_mask & DM_NCP22_25_TIME_BITS))
|
||||
return(0);
|
||||
|
||||
if (tru_eff_rights_exists(volume, unixname, stb, TRUSTEE_M))
|
||||
return(-0x8c);
|
||||
|
||||
ut.actime = stb->st_atime;
|
||||
ut.modtime = stb->st_mtime;
|
||||
|
||||
if (change_mask & (DM_MODIFY_DATE | DM_MODIFY_TIME)) {
|
||||
un_time_2_nw_parts(stb->st_mtime, &mdate, &mtimev);
|
||||
|
||||
if (is_dir) {
|
||||
if (change_mask & DM_MODIFY_DATE)
|
||||
mdate = (uint16)GET_16(f->u.d.modify_date);
|
||||
if (change_mask & DM_MODIFY_TIME)
|
||||
mtimev = (uint16)GET_16(f->u.d.modify_time);
|
||||
} else {
|
||||
if (change_mask & DM_MODIFY_DATE)
|
||||
mdate = (uint16)GET_16(f->u.f.updated.date);
|
||||
if (change_mask & DM_MODIFY_TIME)
|
||||
mtimev = (uint16)GET_16(f->u.f.updated.time);
|
||||
}
|
||||
|
||||
ut.modtime = nw_2_un_time_parts(mdate, mtimev);
|
||||
if (ut.modtime == (time_t)-1)
|
||||
return(-0x8c);
|
||||
}
|
||||
|
||||
if (!is_dir && (change_mask & DM_LAST_ACCESS_DATE)) {
|
||||
un_time_2_nw_parts(stb->st_atime, &adate, &atimev);
|
||||
adate = (uint16)GET_16(f->u.f.last_access_date);
|
||||
ut.actime = nw_2_un_time_parts(adate, atimev);
|
||||
if (ut.actime == (time_t)-1)
|
||||
return(-0x8c);
|
||||
}
|
||||
|
||||
if (utime(unixname, &ut)) {
|
||||
if (seteuid(0)) {}
|
||||
if (utime(unixname, &ut)) {
|
||||
(void)reseteuid();
|
||||
return(-0x8c);
|
||||
}
|
||||
(void)reseteuid();
|
||||
}
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
static int get_file_attrib(NW_FILE_INFO *f, char *unixname, struct stat *stb,
|
||||
NW_PATH *nwpath)
|
||||
{
|
||||
@@ -2880,6 +2984,16 @@ int nw_set_a_directory_entry(int dirhandle,
|
||||
if (change_mask & 0x2) {
|
||||
completition=set_nw_attrib_dword(nwpath.volume, unixname, &stbuff,
|
||||
GET_32(f->u.f.attributes));
|
||||
if (!completition)
|
||||
s_stat(unixname, &stbuff, NULL);
|
||||
}
|
||||
if (!completition) {
|
||||
int result=set_ncp22_25_times(nwpath.volume, unixname, &stbuff,
|
||||
f, change_mask, S_ISDIR(stbuff.st_mode));
|
||||
if (result)
|
||||
completition=result;
|
||||
else if (change_mask & DM_NCP22_25_TIME_BITS)
|
||||
s_stat(unixname, &stbuff, NULL);
|
||||
}
|
||||
if (S_ISDIR(stbuff.st_mode)) {
|
||||
if (change_mask & 0x1000) {
|
||||
|
||||
Reference in New Issue
Block a user