diff --git a/src/internal/toksvc_driver_impl.h b/src/internal/toksvc_driver_impl.h index 83c3216..2c3a6c2 100644 --- a/src/internal/toksvc_driver_impl.h +++ b/src/internal/toksvc_driver_impl.h @@ -283,6 +283,7 @@ static inline void toks_query_performance_counters(const struct toks_driver_ctx ticks->quad = 0; } +int32_t toks_open_log_file(void ** hfile, void * hat, const char * arg, bool fprivate); int32_t toks_open_file(void ** hfile, void * hat, const char * arg, bool fprivate); int32_t toks_open_dir(void ** hfile, void * hat, const char * arg, bool fprivate); diff --git a/src/internal/toksvc_open_impl.c b/src/internal/toksvc_open_impl.c index 6cd6926..030501a 100644 --- a/src/internal/toksvc_open_impl.c +++ b/src/internal/toksvc_open_impl.c @@ -10,6 +10,51 @@ #include #include "toksvc_driver_impl.h" +static const uint32_t toks_sd_access_bits[8] = { + 0, + NT_GENERIC_EXECUTE, + NT_GENERIC_WRITE, + NT_GENERIC_WRITE | NT_GENERIC_EXECUTE, + NT_GENERIC_READ, + NT_GENERIC_READ | NT_GENERIC_EXECUTE , + NT_GENERIC_READ | NT_GENERIC_WRITE, + NT_GENERIC_READ | NT_GENERIC_WRITE | NT_GENERIC_EXECUTE +}; + +static nt_sd * toks_fsfile_sd( + nt_sd_common_buffer * sd, + uint32_t mode) +{ + uint32_t access_owner; + uint32_t access_group; + uint32_t access_other; + uint32_t access_admin; + nt_sid * admin_sid; + + access_owner = (((mode & 0700) >> 6) == 7) + ? NT_GENERIC_ALL | NT_SEC_SPECIFIC_RIGHTS_ALL + : toks_sd_access_bits[(mode & 0700) >> 6] + | NT_SEC_STANDARD_RIGHTS_ALL; + + access_group = toks_sd_access_bits[(mode & 0070) >> 3]; + access_group |= NT_SEC_READ_CONTROL|NT_FILE_READ_ATTRIBUTES; + + access_other = toks_sd_access_bits[(mode & 0007) >> 0]; + access_other |= NT_SEC_READ_CONTROL|NT_FILE_READ_ATTRIBUTES; + + admin_sid = 0; + access_admin = access_owner; + + ntapi->acl_init_common_descriptor( + sd,0,0, + 0,admin_sid, + access_owner,access_group,access_other, + access_admin,access_owner, + 0); + + return &sd->sd; +} + static int32_t toks_open( void ** hfile, void * hat, @@ -123,6 +168,48 @@ int32_t toks_open_file(void ** hfile, void * hat, const char * arg, bool fprivat fprivate); } +int32_t toks_open_log_file(void ** hfile, void * hat, const char * arg, bool fprivate) +{ + int32_t status; + nt_iosb iosb; + nt_fsi fsi; + nt_fpi fpi; + nt_sd_common_buffer sd; + + if ((status = toks_open_volume( + hfile,hat,arg, + toks_fsfile_sd(&sd,0644), + NT_FILE_ATTRIBUTE_NORMAL, + NT_FILE_NON_DIRECTORY_FILE, + NT_FILE_OPEN_IF, + fprivate))) + return status; + + status = ntapi->zw_query_information_file( + *hfile,&iosb, + &fsi,sizeof(fsi), + NT_FILE_STANDARD_INFORMATION); + + if (status) { + ntapi->zw_close(*hfile); + return status; + } + + fpi.current_byte_offset.quad = fsi.end_of_file.quad; + + status = ntapi->zw_set_information_file( + *hfile,&iosb, + &fpi,sizeof(fpi), + NT_FILE_POSITION_INFORMATION); + + if (status) { + ntapi->zw_close(*hfile); + return status; + } + + return NT_STATUS_SUCCESS; +} + int32_t toks_open_dir(void ** hfile, void * hat, const char * arg, bool fprivate) { return toks_open_volume(