| 1 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{ |
| 2 | fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#, |
| 3 | iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::{selfrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/, Cursorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/Cursor#, Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#, Seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#, Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#}, |
| 4 | pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#, |
| 5 | timerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/::Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#, |
| 6 | }; |
| 7 | |
| 8 | use craterust-analyzer cargo sudo-rs 0.2.14 crate/::commonrust-analyzer cargo sudo-rs 0.2.14 common/::resolverust-analyzer cargo sudo-rs 0.2.14 common/resolve/::AuthUserrust-analyzer cargo sudo-rs 0.2.14 common/resolve/AuthUser#; |
| 9 | use craterust-analyzer cargo sudo-rs 0.2.14 crate/::{ |
| 10 | commonrust-analyzer cargo sudo-rs 0.2.14 common/::resolverust-analyzer cargo sudo-rs 0.2.14 common/resolve/::CurrentUserrust-analyzer cargo sudo-rs 0.2.14 common/resolve/CurrentUser#, |
| 11 | logrust-analyzer cargo sudo-rs 0.2.14 log/::{auth_inforust-analyzer cargo sudo-rs 0.2.14 log/auth_info!, auth_warnrust-analyzer cargo sudo-rs 0.2.14 log/auth_warn!}, |
| 12 | }; |
| 13 | |
| 14 | use superrust-analyzer cargo sudo-rs 0.2.14 system/::{ |
| 15 | Processrust-analyzer cargo sudo-rs 0.2.14 system/Process#, WithProcessrust-analyzer cargo sudo-rs 0.2.14 system/WithProcess#, |
| 16 | auditrust-analyzer cargo sudo-rs 0.2.14 system/audit/::secure_open_cookie_filerust-analyzer cargo sudo-rs 0.2.14 system/audit/secure_open_cookie_file()., |
| 17 | filerust-analyzer cargo sudo-rs 0.2.14 system/file/::FileLockrust-analyzer cargo sudo-rs 0.2.14 system/file/lock/FileLock#, |
| 18 | interfacerust-analyzer cargo sudo-rs 0.2.14 system/interface/::{DeviceIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/DeviceId#, ProcessIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/ProcessId#, UserIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/UserId#}, |
| 19 | timerust-analyzer cargo sudo-rs 0.2.14 system/time/::{ProcessCreateTimerust-analyzer cargo sudo-rs 0.2.14 system/time/ProcessCreateTime#, SystemTimerust-analyzer cargo sudo-rs 0.2.14 system/time/SystemTime#}, |
| 20 | }; |
| 21 | |
| 22 | type BoolStoragerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/BoolStorage# = u8; |
| 23 | |
| 24 | const SIZE_OF_TSrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SIZE_OF_TS.: i64 = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<SystemTimerust-analyzer cargo sudo-rs 0.2.14 system/time/SystemTime#>() as i64; |
| 25 | const SIZE_OF_BOOLrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SIZE_OF_BOOL.: i64 = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<BoolStoragerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/BoolStorage#>() as i64; |
| 26 | const MOD_OFFSETrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/MOD_OFFSET.: i64 = SIZE_OF_TSrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SIZE_OF_TS. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Add<Self>`]add().SIZE_OF_BOOLrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SIZE_OF_BOOL.; |
| 27 | |
| 28 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 29 | pub struct SessionRecordFilerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile# { |
| 30 | filerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile#file.: Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#, |
| 31 | timeoutrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile#timeout.: Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#, |
| 32 | for_userrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile#for_user.: UserIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/UserId#, |
| 33 | } |
| 34 | |
| 35 | impl SessionRecordFilerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile# { |
| 36 | const BASE_PATHrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]BASE_PATH.: &'static str = "/var/run/sudo-rs/ts"; |
| 37 | |
| 38 | pub fn open_for_userrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]open_for_user().(user: &CurrentUserrust-analyzer cargo sudo-rs 0.2.14 common/resolve/CurrentUser#, timeout: Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<Selfrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]> { |
| 39 | let uid = user.uidrust-analyzer cargo sudo-rs 0.2.14 system/User#uid.; |
| 40 | let mut path = PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf][`From<&T>`]from().(Selfrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]::BASE_PATHrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]BASE_PATH.); |
| 41 | path.pushrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf]push().(uid.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 42 | SessionRecordFilerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile#::newrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]new().(uid, secure_open_cookie_filerust-analyzer cargo sudo-rs 0.2.14 system/audit/secure_open_cookie_file().(&path)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., timeout) |
| 43 | } |
| 44 | |
| 45 | const FILE_VERSIONrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]FILE_VERSION.: u16 = 2; |
| 46 | const MAGIC_NUMrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]MAGIC_NUM.: u16 = 0x50D0; |
| 47 | const VERSION_OFFSETrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]VERSION_OFFSET.: u64 = Selfrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]::MAGIC_NUMrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]MAGIC_NUM..to_le_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]to_le_bytes().().lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator#len().() as u64; |
| 48 | const FIRST_RECORD_OFFSETrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]FIRST_RECORD_OFFSET.: u64 = |
| 49 | Selfrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]::VERSION_OFFSETrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]VERSION_OFFSET. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add().Selfrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]::FILE_VERSIONrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]FILE_VERSION..to_le_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]to_le_bytes().().lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator#len().() as u64; |
| 50 | |
| 51 | /// Create a new SessionRecordFile from the given i/o stream. |
| 52 | /// Timestamps in this file are considered valid if they were created or |
| 53 | /// updated at most `timeout` time ago. |
| 54 | pub fn newrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]new().(for_user: UserIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/UserId#, io: Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#, timeout: Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<Selfrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]> { |
| 55 | let mut session_records = SessionRecordFilerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile# { |
| 56 | filerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile#file.: io, |
| 57 | timeoutrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile#timeout., |
| 58 | for_userrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile#for_user., |
| 59 | }; |
| 60 | |
| 61 | // match the magic number, otherwise reset the file |
| 62 | match session_records.read_magicrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]read_magic().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 63 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(magic) if magic rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq().Selfrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]::MAGIC_NUMrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]MAGIC_NUM. => (), |
| 64 | x => { |
| 65 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(_magic) = x { |
| 66 | auth_inforust-analyzer cargo sudo-rs 0.2.14 log/auth_info!!("Session records file for user '{for_user}' is invalid, resetting"); |
| 67 | } |
| 68 | |
| 69 | session_records.initrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]init().(Selfrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]::VERSION_OFFSETrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]VERSION_OFFSET.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | // match the file version |
| 74 | match session_records.read_versionrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]read_version().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 75 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v) if v rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq().Selfrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]::FILE_VERSIONrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]FILE_VERSION. => (), |
| 76 | x => { |
| 77 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v) = x { |
| 78 | auth_inforust-analyzer cargo sudo-rs 0.2.14 log/auth_info!!( |
| 79 | "Session records file for user '{for_user}' has invalid version {v}, only file version {} is supported, resetting", |
| 80 | Selfrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]::FILE_VERSIONrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]FILE_VERSION. |
| 81 | ); |
| 82 | } else { |
| 83 | auth_inforust-analyzer cargo sudo-rs 0.2.14 log/auth_info!!( |
| 84 | "Session records file did not contain file version information, resetting" |
| 85 | ); |
| 86 | } |
| 87 | |
| 88 | session_records.initrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]init().(Selfrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]::FIRST_RECORD_OFFSETrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]FIRST_RECORD_OFFSET.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | // we are ready to read records |
| 93 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(session_records) |
| 94 | } |
| 95 | |
| 96 | /// Read the magic number from the input stream |
| 97 | fn read_magicrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]read_magic().(&mut self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<u16>> { |
| 98 | let mut magic_bytes = [0; stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<u16>()]; |
| 99 | match self.filerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile#file..read_exactrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#read_exact().(&mut magic_bytes) { |
| 100 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) if e.kindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]kind().() rust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[ErrorKind][`PartialEq<Self>`]eq().==rust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[ErrorKind][`PartialEq<Self>`]eq(). rust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[ErrorKind][`PartialEq<Self>`]eq().iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::UnexpectedEofrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#UnexpectedEof# => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#), |
| 101 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e), |
| 102 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(u16::from_le_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]from_le_bytes().(magic_bytes))), |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | /// Read the version number from the input stream |
| 107 | fn read_versionrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]read_version().(&mut self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<u16>> { |
| 108 | let mut version_bytes = [0; stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<u16>()]; |
| 109 | match self.filerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile#file..read_exactrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#read_exact().(&mut version_bytes) { |
| 110 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) if e.kindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]kind().() rust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[ErrorKind][`PartialEq<Self>`]eq().==rust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[ErrorKind][`PartialEq<Self>`]eq(). rust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[ErrorKind][`PartialEq<Self>`]eq().iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::UnexpectedEofrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#UnexpectedEof# => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#), |
| 111 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e), |
| 112 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(u16::from_le_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]from_le_bytes().(version_bytes))), |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | /// Initialize a new empty stream. If the stream/file was already filled |
| 117 | /// before it will be truncated. |
| 118 | fn initrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]init().(&mut self, offset: u64) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> { |
| 119 | // lock the file to indicate that we are currently writing to it |
| 120 | let lock = FileLockrust-analyzer cargo sudo-rs 0.2.14 system/file/lock/FileLock#::exclusiverust-analyzer cargo sudo-rs 0.2.14 system/file/lock/impl#[FileLock]exclusive().(&self.filerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile#file., false)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 121 | |
| 122 | self.filerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile#file..set_lenrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]set_len().(0)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 123 | self.filerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile#file..rewindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#rewind().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 124 | self.filerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile#file..write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(&Selfrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]::MAGIC_NUMrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]MAGIC_NUM..to_le_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]to_le_bytes().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 125 | self.filerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile#file..write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(&Selfrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]::FILE_VERSIONrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]FILE_VERSION..to_le_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]to_le_bytes().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 126 | self.filerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile#file..seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File][Seek]seek().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::SeekFromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/SeekFrom#::Startrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/SeekFrom#Start#(offset))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 127 | |
| 128 | lock.unlockrust-analyzer cargo sudo-rs 0.2.14 system/file/lock/impl#[FileLock]unlock().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 129 | |
| 130 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 131 | } |
| 132 | |
| 133 | /// Read the next record and keep note of the start and end positions in the file of that record |
| 134 | /// |
| 135 | /// This method assumes that the file is already exclusively locked. |
| 136 | fn next_recordrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]next_record().(&mut self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<SessionRecordrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecord#>> { |
| 137 | // record the position at which this record starts (including size bytes) |
| 138 | let mut record_length_bytes = [0; stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<u16>()]; |
| 139 | |
| 140 | let curr_pos = self.filerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile#file..stream_positionrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File][Seek]stream_position().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 141 | |
| 142 | // if eof occurs here we assume we reached the end of the file |
| 143 | let record_length = match self.filerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile#file..read_exactrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#read_exact().(&mut record_length_bytes) { |
| 144 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) if e.kindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]kind().() rust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[ErrorKind][`PartialEq<Self>`]eq().==rust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[ErrorKind][`PartialEq<Self>`]eq(). rust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[ErrorKind][`PartialEq<Self>`]eq().iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::UnexpectedEofrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#UnexpectedEof# => return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#), |
| 145 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e), |
| 146 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) => u16::from_le_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]from_le_bytes().(record_length_bytes), |
| 147 | }; |
| 148 | |
| 149 | // special case when record_length is zero |
| 150 | if record_length rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq().0 { |
| 151 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().( |
| 152 | iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::InvalidInputrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#InvalidInput#, |
| 153 | "Found empty record", |
| 154 | )); |
| 155 | } |
| 156 | |
| 157 | let mut buf = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0; record_length as usize]; |
| 158 | match self.filerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile#file..read_exactrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#read_exact().(&mut buf) { |
| 159 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) if e.kindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]kind().() rust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[ErrorKind][`PartialEq<Self>`]eq().==rust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[ErrorKind][`PartialEq<Self>`]eq(). rust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[ErrorKind][`PartialEq<Self>`]eq().iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::UnexpectedEofrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#UnexpectedEof# => { |
| 160 | // there was half a record here, we clear the rest of the file |
| 161 | auth_inforust-analyzer cargo sudo-rs 0.2.14 log/auth_info!!( |
| 162 | "Found incomplete record in session records file for {}, clearing rest of the file", |
| 163 | self.for_userrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile#for_user. |
| 164 | ); |
| 165 | self.filerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile#file..set_lenrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]set_len().(curr_pos)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 166 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 167 | } |
| 168 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e), |
| 169 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) => (), |
| 170 | } |
| 171 | |
| 172 | // we now try and decode the data read into a session record |
| 173 | match SessionRecordrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecord#::from_bytesrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecord]from_bytes().(&buf) { |
| 174 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(_) => { |
| 175 | // any error assumes that this file is nonsense from this point |
| 176 | // onwards, so we clear the file up to the start of this record |
| 177 | auth_inforust-analyzer cargo sudo-rs 0.2.14 log/auth_info!!( |
| 178 | "Found invalid record in session records file for {}, clearing rest of the file", |
| 179 | self.for_userrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile#for_user. |
| 180 | ); |
| 181 | |
| 182 | self.filerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile#file..set_lenrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]set_len().(curr_pos)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 183 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) |
| 184 | } |
| 185 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(record) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(record)), |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | /// Try and find a record for the given scope and auth user id and update |
| 190 | /// that record time to the current time. This will not create a new record |
| 191 | /// when one is not found. A record will only be updated if it is still |
| 192 | /// valid at this time. |
| 193 | pub fn touchrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]touch().(&mut self, scope: RecordScoperust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#, auth_user: &AuthUserrust-analyzer cargo sudo-rs 0.2.14 common/resolve/AuthUser#) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<TouchResultrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/TouchResult#> { |
| 194 | // lock the file to indicate that we are currently in a writing operation |
| 195 | let lock = FileLockrust-analyzer cargo sudo-rs 0.2.14 system/file/lock/FileLock#::exclusiverust-analyzer cargo sudo-rs 0.2.14 system/file/lock/impl#[FileLock]exclusive().(&self.filerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile#file., false)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 196 | self.seek_to_first_recordrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]seek_to_first_record().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 197 | while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(record) = self.next_recordrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]next_record().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 198 | // only touch if record is enabled |
| 199 | if record.enabledrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecord#enabled. && record.matchesrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecord]matches().(&scope, auth_user) { |
| 200 | let now = SystemTimerust-analyzer cargo sudo-rs 0.2.14 system/time/SystemTime#::nowrust-analyzer cargo sudo-rs 0.2.14 system/time/impl#[SystemTime]now().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 201 | if record.written_betweenrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecord]written_between().(now rust-analyzer cargo sudo-rs 0.2.14 system/time/impl#[SystemTime][`Sub<Duration>`]sub().-rust-analyzer cargo sudo-rs 0.2.14 system/time/impl#[SystemTime][`Sub<Duration>`]sub(). rust-analyzer cargo sudo-rs 0.2.14 system/time/impl#[SystemTime][`Sub<Duration>`]sub().self.timeoutrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile#timeout., now) { |
| 202 | // move back to where the timestamp is and overwrite with the latest time |
| 203 | self.filerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile#file..seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File][Seek]seek().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::SeekFromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/SeekFrom#::Currentrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/SeekFrom#Current#(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().MOD_OFFSETrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/MOD_OFFSET.))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 204 | let new_time = SystemTimerust-analyzer cargo sudo-rs 0.2.14 system/time/SystemTime#::nowrust-analyzer cargo sudo-rs 0.2.14 system/time/impl#[SystemTime]now().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 205 | new_time.encoderust-analyzer cargo sudo-rs 0.2.14 system/time/impl#[SystemTime]encode().(&mut self.filerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile#file.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 206 | |
| 207 | // make sure we can still go to the end of the record |
| 208 | self.filerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile#file..seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File][Seek]seek().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::SeekFromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/SeekFrom#::Currentrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/SeekFrom#Current#(SIZE_OF_BOOLrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SIZE_OF_BOOL.))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 209 | |
| 210 | // writing is done, unlock and return |
| 211 | lock.unlockrust-analyzer cargo sudo-rs 0.2.14 system/file/lock/impl#[FileLock]unlock().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 212 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(TouchResultrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/TouchResult#::Updatedrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/TouchResult#Updated# { |
| 213 | old_timerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/TouchResult#Updated#old_time.: record.timestamprust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecord#timestamp., |
| 214 | new_timerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/TouchResult#Updated#new_time., |
| 215 | }); |
| 216 | } else { |
| 217 | lock.unlockrust-analyzer cargo sudo-rs 0.2.14 system/file/lock/impl#[FileLock]unlock().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 218 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(TouchResultrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/TouchResult#::Outdatedrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/TouchResult#Outdated# { |
| 219 | timerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/TouchResult#Outdated#time.: record.timestamprust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecord#timestamp., |
| 220 | }); |
| 221 | } |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | lock.unlockrust-analyzer cargo sudo-rs 0.2.14 system/file/lock/impl#[FileLock]unlock().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 226 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(TouchResultrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/TouchResult#::NotFoundrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/TouchResult#NotFound#) |
| 227 | } |
| 228 | |
| 229 | /// Disable all records that match the given scope. |
| 230 | pub fn disablerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]disable().(&mut self, scope: RecordScoperust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> { |
| 231 | let lock = FileLockrust-analyzer cargo sudo-rs 0.2.14 system/file/lock/FileLock#::exclusiverust-analyzer cargo sudo-rs 0.2.14 system/file/lock/impl#[FileLock]exclusive().(&self.filerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile#file., false)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 232 | self.seek_to_first_recordrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]seek_to_first_record().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 233 | while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(record) = self.next_recordrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]next_record().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 234 | if record.scoperust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecord#scope. rust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[RecordScope][`PartialEq<Self>`]eq().==rust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[RecordScope][`PartialEq<Self>`]eq(). rust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[RecordScope][`PartialEq<Self>`]eq().scope { |
| 235 | self.filerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile#file..seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File][Seek]seek().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::SeekFromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/SeekFrom#::Currentrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/SeekFrom#Current#(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().SIZE_OF_BOOLrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SIZE_OF_BOOL.))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 236 | write_boolrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/write_bool().(false, &mut self.filerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile#file.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 237 | } |
| 238 | } |
| 239 | lock.unlockrust-analyzer cargo sudo-rs 0.2.14 system/file/lock/impl#[FileLock]unlock().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 240 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 241 | } |
| 242 | |
| 243 | /// Create a new record for the given scope and auth user id. |
| 244 | /// If there is an existing record that matches the scope and auth user, |
| 245 | /// then that record will be updated. |
| 246 | pub fn createrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]create().(&mut self, scope: RecordScoperust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#, auth_user: &AuthUserrust-analyzer cargo sudo-rs 0.2.14 common/resolve/AuthUser#) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<CreateResultrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/CreateResult#> { |
| 247 | // lock the file to indicate that we are currently writing to it |
| 248 | let lock = FileLockrust-analyzer cargo sudo-rs 0.2.14 system/file/lock/FileLock#::exclusiverust-analyzer cargo sudo-rs 0.2.14 system/file/lock/impl#[FileLock]exclusive().(&self.filerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile#file., false)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 249 | self.seek_to_first_recordrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]seek_to_first_record().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 250 | while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(record) = self.next_recordrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]next_record().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 251 | if record.matchesrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecord]matches().(&scope, auth_user) { |
| 252 | self.filerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile#file..seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File][Seek]seek().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::SeekFromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/SeekFrom#::Currentrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/SeekFrom#Current#(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().MOD_OFFSETrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/MOD_OFFSET.))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 253 | let new_time = SystemTimerust-analyzer cargo sudo-rs 0.2.14 system/time/SystemTime#::nowrust-analyzer cargo sudo-rs 0.2.14 system/time/impl#[SystemTime]now().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 254 | new_time.encoderust-analyzer cargo sudo-rs 0.2.14 system/time/impl#[SystemTime]encode().(&mut self.filerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile#file.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 255 | write_boolrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/write_bool().(true, &mut self.filerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile#file.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 256 | lock.unlockrust-analyzer cargo sudo-rs 0.2.14 system/file/lock/impl#[FileLock]unlock().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 257 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(CreateResultrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/CreateResult#::Updatedrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/CreateResult#Updated# { |
| 258 | old_timerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/CreateResult#Updated#old_time.: record.timestamprust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecord#timestamp., |
| 259 | new_timerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/CreateResult#Updated#new_time., |
| 260 | }); |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | // record was not found in the list so far, create a new one |
| 265 | let record = SessionRecordrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecord#::newrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecord]new().(scope, auth_user.uidrust-analyzer cargo sudo-rs 0.2.14 system/User#uid.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 266 | |
| 267 | // make sure we really are at the end of the file |
| 268 | self.filerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile#file..seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File][Seek]seek().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::SeekFromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/SeekFrom#::Endrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/SeekFrom#End#(0))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 269 | |
| 270 | self.write_recordrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]write_record().(&record)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 271 | lock.unlockrust-analyzer cargo sudo-rs 0.2.14 system/file/lock/impl#[FileLock]unlock().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 272 | |
| 273 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(CreateResultrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/CreateResult#::Createdrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/CreateResult#Created# { |
| 274 | timerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/CreateResult#Created#time.: record.timestamprust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecord#timestamp., |
| 275 | }) |
| 276 | } |
| 277 | |
| 278 | /// Completely resets the entire file and removes all records. |
| 279 | pub fn resetrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]reset().(&mut self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> { |
| 280 | self.initrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]init().(0) |
| 281 | } |
| 282 | |
| 283 | /// Write a new record at the current position in the file. |
| 284 | fn write_recordrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]write_record().(&mut self, record: &SessionRecordrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecord#) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> { |
| 285 | // convert the new record to byte representation and make sure that it fits |
| 286 | let bytes = record.as_bytesrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecord]as_bytes().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 287 | let record_length = bytes.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(); |
| 288 | if record_length rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().u16::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]MAX. as usize { |
| 289 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().( |
| 290 | iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::InvalidInputrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#InvalidInput#, |
| 291 | "A record with an unexpectedly large size was created", |
| 292 | )); |
| 293 | } |
| 294 | let record_length = record_length as u16; // store as u16 |
| 295 | |
| 296 | // write the record |
| 297 | self.filerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile#file..write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(&record_length.to_le_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]to_le_bytes().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 298 | self.filerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile#file..write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(&bytes)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 299 | |
| 300 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 301 | } |
| 302 | |
| 303 | /// Move to where the first record starts. |
| 304 | fn seek_to_first_recordrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]seek_to_first_record().(&mut self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> { |
| 305 | self.filerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile#file. |
| 306 | .seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File][Seek]seek().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::SeekFromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/SeekFrom#::Startrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/SeekFrom#Start#(Selfrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]::FIRST_RECORD_OFFSETrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]FIRST_RECORD_OFFSET.))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 307 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)] |
| 312 | pub enum TouchResultrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/TouchResult# { |
| 313 | /// The record was found and within the timeout, and it was refreshed |
| 314 | Updatedrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/TouchResult#Updated# { |
| 315 | old_timerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/TouchResult#Updated#old_time.: SystemTimerust-analyzer cargo sudo-rs 0.2.14 system/time/SystemTime#, |
| 316 | new_timerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/TouchResult#Updated#new_time.: SystemTimerust-analyzer cargo sudo-rs 0.2.14 system/time/SystemTime#, |
| 317 | }, |
| 318 | /// A record was found, but it was no longer valid |
| 319 | Outdatedrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/TouchResult#Outdated# { timerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/TouchResult#Outdated#time.: SystemTimerust-analyzer cargo sudo-rs 0.2.14 system/time/SystemTime# }, |
| 320 | /// A record was not found that matches the input |
| 321 | NotFoundrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/TouchResult#NotFound#, |
| 322 | } |
| 323 | |
| 324 | #[cfg_attr(not(test), allow(dead_code))] |
| 325 | pub enum CreateResultrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/CreateResult# { |
| 326 | /// The record was found and it was refreshed |
| 327 | Updatedrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/CreateResult#Updated# { |
| 328 | old_timerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/CreateResult#Updated#old_time.: SystemTimerust-analyzer cargo sudo-rs 0.2.14 system/time/SystemTime#, |
| 329 | new_timerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/CreateResult#Updated#new_time.: SystemTimerust-analyzer cargo sudo-rs 0.2.14 system/time/SystemTime#, |
| 330 | }, |
| 331 | /// A new record was created and was set to the time returned |
| 332 | Createdrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/CreateResult#Created# { timerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/CreateResult#Created#time.: SystemTimerust-analyzer cargo sudo-rs 0.2.14 system/time/SystemTime# }, |
| 333 | } |
| 334 | |
| 335 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)] |
| 336 | pub enum RecordScoperust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope# { |
| 337 | Ttyrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Tty# { |
| 338 | tty_devicerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Tty#tty_device.: DeviceIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/DeviceId#, |
| 339 | session_pidrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Tty#session_pid.: ProcessIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/ProcessId#, |
| 340 | init_timerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Tty#init_time.: ProcessCreateTimerust-analyzer cargo sudo-rs 0.2.14 system/time/ProcessCreateTime#, |
| 341 | }, |
| 342 | Ppidrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Ppid# { |
| 343 | group_pidrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Ppid#group_pid.: ProcessIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/ProcessId#, |
| 344 | session_pidrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Ppid#session_pid.: ProcessIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/ProcessId#, |
| 345 | init_timerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Ppid#init_time.: ProcessCreateTimerust-analyzer cargo sudo-rs 0.2.14 system/time/ProcessCreateTime#, |
| 346 | }, |
| 347 | } |
| 348 | |
| 349 | impl RecordScoperust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope# { |
| 350 | fn encoderust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[RecordScope]encode().(&self, target: &mut impl Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> { |
| 351 | match self { |
| 352 | RecordScoperust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#::Ttyrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Tty# { |
| 353 | tty_devicerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Tty#tty_device., |
| 354 | session_pidrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Tty#session_pid., |
| 355 | init_timerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Tty#init_time., |
| 356 | } => { |
| 357 | target.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(&[1u8])?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 358 | let b = tty_device.innerrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[DeviceId]inner().().to_le_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]to_le_bytes().(); |
| 359 | target.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(&b)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 360 | let b = session_pid.innerrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[ProcessId]inner().().to_le_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i32]to_le_bytes().(); |
| 361 | target.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(&b)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 362 | init_time.encoderust-analyzer cargo sudo-rs 0.2.14 system/time/impl#[ProcessCreateTime]encode().(target)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 363 | } |
| 364 | RecordScoperust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#::Ppidrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Ppid# { |
| 365 | group_pidrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Ppid#group_pid., |
| 366 | session_pidrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Ppid#session_pid., |
| 367 | init_timerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Ppid#init_time., |
| 368 | } => { |
| 369 | target.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(&[2u8])?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 370 | let b = group_pid.innerrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[ProcessId]inner().().to_le_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i32]to_le_bytes().(); |
| 371 | target.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(&b)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 372 | let b = session_pid.innerrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[ProcessId]inner().().to_le_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i32]to_le_bytes().(); |
| 373 | target.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(&b)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 374 | init_time.encoderust-analyzer cargo sudo-rs 0.2.14 system/time/impl#[ProcessCreateTime]encode().(target)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 379 | } |
| 380 | |
| 381 | fn decoderust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[RecordScope]decode().(from: &mut impl Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<RecordScoperust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#> { |
| 382 | let mut buf = [0; 1]; |
| 383 | from.read_exactrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#read_exact().(&mut buf)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 384 | match buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index(). { |
| 385 | 1 => { |
| 386 | let mut buf = [0; stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<libcrust-analyzer cargo libc 0.2.186 crate/::dev_trust-analyzer cargo libc 0.2.186 unix/linux_like/linux/dev_t#>()]; |
| 387 | from.read_exactrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#read_exact().(&mut buf)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 388 | let tty_device = libcrust-analyzer cargo libc 0.2.186 crate/::dev_trust-analyzer cargo libc 0.2.186 unix/linux_like/linux/dev_t#::from_le_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]from_le_bytes().(buf); |
| 389 | let mut buf = [0; stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<libcrust-analyzer cargo libc 0.2.186 crate/::pid_trust-analyzer cargo libc 0.2.186 unix/pid_t#>()]; |
| 390 | from.read_exactrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#read_exact().(&mut buf)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 391 | let session_pid = libcrust-analyzer cargo libc 0.2.186 crate/::pid_trust-analyzer cargo libc 0.2.186 unix/pid_t#::from_le_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i32]from_le_bytes().(buf); |
| 392 | let init_time = ProcessCreateTimerust-analyzer cargo sudo-rs 0.2.14 system/time/ProcessCreateTime#::decoderust-analyzer cargo sudo-rs 0.2.14 system/time/impl#[ProcessCreateTime]decode().(from)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 393 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(RecordScoperust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#::Ttyrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Tty# { |
| 394 | tty_devicerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Tty#tty_device.: DeviceIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/DeviceId#::newrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[DeviceId]new().(tty_device), |
| 395 | session_pidrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Tty#session_pid.: ProcessIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/ProcessId#::newrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[ProcessId]new().(session_pid), |
| 396 | init_timerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Tty#init_time., |
| 397 | }) |
| 398 | } |
| 399 | 2 => { |
| 400 | let mut buf = [0; stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<libcrust-analyzer cargo libc 0.2.186 crate/::pid_trust-analyzer cargo libc 0.2.186 unix/pid_t#>()]; |
| 401 | from.read_exactrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#read_exact().(&mut buf)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 402 | let group_pid = libcrust-analyzer cargo libc 0.2.186 crate/::pid_trust-analyzer cargo libc 0.2.186 unix/pid_t#::from_le_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i32]from_le_bytes().(buf); |
| 403 | let mut buf = [0; stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<libcrust-analyzer cargo libc 0.2.186 crate/::pid_trust-analyzer cargo libc 0.2.186 unix/pid_t#>()]; |
| 404 | from.read_exactrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#read_exact().(&mut buf)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 405 | let session_pid = libcrust-analyzer cargo libc 0.2.186 crate/::pid_trust-analyzer cargo libc 0.2.186 unix/pid_t#::from_le_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i32]from_le_bytes().(buf); |
| 406 | let init_time = ProcessCreateTimerust-analyzer cargo sudo-rs 0.2.14 system/time/ProcessCreateTime#::decoderust-analyzer cargo sudo-rs 0.2.14 system/time/impl#[ProcessCreateTime]decode().(from)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 407 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(RecordScoperust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#::Ppidrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Ppid# { |
| 408 | group_pidrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Ppid#group_pid.: ProcessIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/ProcessId#::newrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[ProcessId]new().(group_pid), |
| 409 | session_pidrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Ppid#session_pid.: ProcessIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/ProcessId#::newrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[ProcessId]new().(session_pid), |
| 410 | init_timerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Ppid#init_time., |
| 411 | }) |
| 412 | } |
| 413 | x => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().( |
| 414 | iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::InvalidInputrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#InvalidInput#, |
| 415 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Unexpected scope variant discriminator: {x}"), |
| 416 | )), |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | /// Tries to determine a record match scope for the current context. |
| 421 | /// This should never produce an error since any actual error should just be |
| 422 | /// ignored and no session record file should be used in that case. |
| 423 | pub fn for_processrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[RecordScope]for_process().(process: &Processrust-analyzer cargo sudo-rs 0.2.14 system/Process#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<RecordScoperust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#> { |
| 424 | let tty = Processrust-analyzer cargo sudo-rs 0.2.14 system/Process#::tty_device_idrust-analyzer cargo sudo-rs 0.2.14 system/impl#[Process]tty_device_id().(WithProcessrust-analyzer cargo sudo-rs 0.2.14 system/WithProcess#::Currentrust-analyzer cargo sudo-rs 0.2.14 system/WithProcess#Current#); |
| 425 | if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(tty_device)) = tty { |
| 426 | if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(init_time) = Processrust-analyzer cargo sudo-rs 0.2.14 system/Process#::starting_timerust-analyzer cargo sudo-rs 0.2.14 system/impl#[Process]starting_time().(WithProcessrust-analyzer cargo sudo-rs 0.2.14 system/WithProcess#::Otherrust-analyzer cargo sudo-rs 0.2.14 system/WithProcess#Other#(process.session_idrust-analyzer cargo sudo-rs 0.2.14 system/Process#session_id.)) { |
| 427 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(RecordScoperust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#::Ttyrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Tty# { |
| 428 | tty_devicerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Tty#tty_device., |
| 429 | session_pidrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Tty#session_pid.: process.session_idrust-analyzer cargo sudo-rs 0.2.14 system/Process#session_id., |
| 430 | init_timerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Tty#init_time., |
| 431 | }) |
| 432 | } else { |
| 433 | auth_warnrust-analyzer cargo sudo-rs 0.2.14 log/auth_warn!!("Could not get terminal foreground process starting time"); |
| 434 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 435 | } |
| 436 | } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(parent_pid) = process.parent_pidrust-analyzer cargo sudo-rs 0.2.14 system/Process#parent_pid. { |
| 437 | if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(init_time) = Processrust-analyzer cargo sudo-rs 0.2.14 system/Process#::starting_timerust-analyzer cargo sudo-rs 0.2.14 system/impl#[Process]starting_time().(WithProcessrust-analyzer cargo sudo-rs 0.2.14 system/WithProcess#::Otherrust-analyzer cargo sudo-rs 0.2.14 system/WithProcess#Other#(parent_pid)) { |
| 438 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(RecordScoperust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#::Ppidrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Ppid# { |
| 439 | group_pidrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Ppid#group_pid.: parent_pid, |
| 440 | session_pidrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Ppid#session_pid.: process.session_idrust-analyzer cargo sudo-rs 0.2.14 system/Process#session_id., |
| 441 | init_timerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Ppid#init_time., |
| 442 | }) |
| 443 | } else { |
| 444 | auth_warnrust-analyzer cargo sudo-rs 0.2.14 log/auth_warn!!("Could not get parent process starting time"); |
| 445 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 446 | } |
| 447 | } else { |
| 448 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 449 | } |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | fn write_boolrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/write_bool().(b: bool, target: &mut impl Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> { |
| 454 | let s: BoolStoragerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/BoolStorage# = if b { 0xFF } else { 0x00 }; |
| 455 | let bytes = s.to_le_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u8]to_le_bytes().(); |
| 456 | target.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(&bytes)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 457 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 458 | } |
| 459 | |
| 460 | /// A record in the session record file |
| 461 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)] |
| 462 | pub struct SessionRecordrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecord# { |
| 463 | /// The scope for which the current record applies, i.e. what process group |
| 464 | /// or which TTY for interactive sessions |
| 465 | scoperust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecord#scope.: RecordScoperust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#, |
| 466 | /// The user that needs to be authenticated against |
| 467 | auth_userrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecord#auth_user.: UserIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/UserId#, |
| 468 | /// The timestamp at which the time was created. This must always be a time |
| 469 | /// originating from a monotonic clock that continues counting during system |
| 470 | /// sleep. |
| 471 | timestamprust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecord#timestamp.: SystemTimerust-analyzer cargo sudo-rs 0.2.14 system/time/SystemTime#, |
| 472 | /// Disabled records act as if they do not exist, but their storage can |
| 473 | /// be re-used when recreating for the same scope and auth user |
| 474 | enabledrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecord#enabled.: bool, |
| 475 | } |
| 476 | |
| 477 | impl SessionRecordrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecord# { |
| 478 | /// Create a new record that is scoped to the specified scope and has `auth_user` as |
| 479 | /// the target for authentication for the session. |
| 480 | fn newrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecord]new().(scope: RecordScoperust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#, auth_user: UserIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/UserId#) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<SessionRecordrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecord#> { |
| 481 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecord]::initrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecord]init().(scope, auth_user, true, SystemTimerust-analyzer cargo sudo-rs 0.2.14 system/time/SystemTime#::nowrust-analyzer cargo sudo-rs 0.2.14 system/time/impl#[SystemTime]now().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().)) |
| 482 | } |
| 483 | |
| 484 | /// Initialize a new record with the given parameters |
| 485 | fn initrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecord]init().( |
| 486 | scope: RecordScoperust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#, |
| 487 | auth_user: UserIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/UserId#, |
| 488 | enabled: bool, |
| 489 | timestamp: SystemTimerust-analyzer cargo sudo-rs 0.2.14 system/time/SystemTime#, |
| 490 | ) -> SessionRecordrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecord# { |
| 491 | SessionRecordrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecord# { |
| 492 | scoperust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecord#scope., |
| 493 | auth_userrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecord#auth_user., |
| 494 | timestamprust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecord#timestamp., |
| 495 | enabledrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecord#enabled., |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | /// Encode a record into the given stream |
| 500 | fn encoderust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecord]encode().(&self, target: &mut impl Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> { |
| 501 | self.scoperust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecord#scope..encoderust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[RecordScope]encode().(target)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 502 | |
| 503 | // write user id |
| 504 | let buf = self.auth_userrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecord#auth_user..innerrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[UserId]inner().().to_le_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]to_le_bytes().(); |
| 505 | target.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(&buf)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 506 | |
| 507 | // write timestamp |
| 508 | self.timestamprust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecord#timestamp..encoderust-analyzer cargo sudo-rs 0.2.14 system/time/impl#[SystemTime]encode().(target)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 509 | |
| 510 | // write enabled boolean |
| 511 | write_boolrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/write_bool().(self.enabledrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecord#enabled., target)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 512 | |
| 513 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 514 | } |
| 515 | |
| 516 | /// Decode a record from the given stream |
| 517 | fn decoderust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecord]decode().(from: &mut impl Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<SessionRecordrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecord#> { |
| 518 | let scope = RecordScoperust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#::decoderust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[RecordScope]decode().(from)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 519 | |
| 520 | // auth user id |
| 521 | let mut buf = [0; stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<libcrust-analyzer cargo libc 0.2.186 crate/::uid_trust-analyzer cargo libc 0.2.186 unix/uid_t#>()]; |
| 522 | from.read_exactrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#read_exact().(&mut buf)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 523 | let auth_user = libcrust-analyzer cargo libc 0.2.186 crate/::uid_trust-analyzer cargo libc 0.2.186 unix/uid_t#::from_le_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]from_le_bytes().(buf); |
| 524 | let auth_user = UserIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/UserId#::newrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[UserId]new().(auth_user); |
| 525 | |
| 526 | // timestamp |
| 527 | let timestamp = SystemTimerust-analyzer cargo sudo-rs 0.2.14 system/time/SystemTime#::decoderust-analyzer cargo sudo-rs 0.2.14 system/time/impl#[SystemTime]decode().(from)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 528 | |
| 529 | // enabled boolean |
| 530 | let mut buf = [0; stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<BoolStoragerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/BoolStorage#>()]; |
| 531 | from.read_exactrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#read_exact().(&mut buf)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 532 | let enabled = match BoolStoragerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/BoolStorage#::from_le_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u8]from_le_bytes().(buf) { |
| 533 | 0xFF => true, |
| 534 | 0x00 => false, |
| 535 | _ => { |
| 536 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().( |
| 537 | iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::InvalidDatarust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#InvalidData#, |
| 538 | "Invalid boolean value detected in input stream", |
| 539 | )); |
| 540 | } |
| 541 | }; |
| 542 | |
| 543 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(SessionRecordrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecord#::initrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecord]init().(scope, auth_user, enabled, timestamp)) |
| 544 | } |
| 545 | |
| 546 | /// Convert the record to a vector of bytes for storage. |
| 547 | pub fn as_bytesrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecord]as_bytes().(&self) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>> { |
| 548 | let mut v = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]; |
| 549 | self.encoderust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecord]encode().(&mut v)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 550 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(v) |
| 551 | } |
| 552 | |
| 553 | /// Convert the given byte slice to a session record, the byte slice must |
| 554 | /// be fully consumed for this conversion to be valid. |
| 555 | pub fn from_bytesrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecord]from_bytes().(data: &[u8]) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<SessionRecordrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecord#> { |
| 556 | let mut cursor = Cursorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/Cursor#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`]new().(data); |
| 557 | let record = SessionRecordrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecord#::decoderust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecord]decode().(&mut cursor)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 558 | if cursor.positionrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`]position().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne().data.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() as u64 { |
| 559 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().( |
| 560 | iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::InvalidInputrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#InvalidInput#, |
| 561 | "Record size and record length did not match", |
| 562 | )) |
| 563 | } else { |
| 564 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(record) |
| 565 | } |
| 566 | } |
| 567 | |
| 568 | /// Returns true if this record matches the specified scope and is for the |
| 569 | /// specified target auth user. |
| 570 | pub fn matchesrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecord]matches().(&self, scope: &RecordScoperust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#, auth_user: &AuthUserrust-analyzer cargo sudo-rs 0.2.14 common/resolve/AuthUser#) -> bool { |
| 571 | self.scoperust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecord#scope. rust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[RecordScope][`PartialEq<Self>`]eq().==rust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[RecordScope][`PartialEq<Self>`]eq(). rust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[RecordScope][`PartialEq<Self>`]eq().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().scope && self.auth_userrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecord#auth_user. rust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[UserId][`PartialEq<Self>`]eq().==rust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[UserId][`PartialEq<Self>`]eq(). rust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[UserId][`PartialEq<Self>`]eq().auth_user.uidrust-analyzer cargo sudo-rs 0.2.14 system/User#uid. |
| 572 | } |
| 573 | |
| 574 | /// Returns true if this record was written somewhere in the time range |
| 575 | /// between `early_time` (inclusive) and `later_time` (inclusive), where |
| 576 | /// early timestamp may not be later than the later timestamp. |
| 577 | pub fn written_betweenrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecord]written_between().(&self, early_time: SystemTimerust-analyzer cargo sudo-rs 0.2.14 system/time/SystemTime#, later_time: SystemTimerust-analyzer cargo sudo-rs 0.2.14 system/time/SystemTime#) -> bool { |
| 578 | early_time rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le().later_time && self.timestamprust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecord#timestamp. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#ge().early_time && self.timestamprust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecord#timestamp. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le().later_time |
| 579 | } |
| 580 | } |
| 581 | |
| 582 | #[cfg(test)] |
| 583 | mod testsrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/tests/ { |
| 584 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#; |
| 585 | |
| 586 | use superrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/::*; |
| 587 | use craterust-analyzer cargo sudo-rs 0.2.14 crate/::commonrust-analyzer cargo sudo-rs 0.2.14 common/::{SudoPathrust-analyzer cargo sudo-rs 0.2.14 common/path/SudoPath#, SudoStringrust-analyzer cargo sudo-rs 0.2.14 common/string/SudoString#}; |
| 588 | use craterust-analyzer cargo sudo-rs 0.2.14 crate/::systemrust-analyzer cargo sudo-rs 0.2.14 system/::Userrust-analyzer cargo sudo-rs 0.2.14 system/User#; |
| 589 | use craterust-analyzer cargo sudo-rs 0.2.14 crate/::systemrust-analyzer cargo sudo-rs 0.2.14 system/::interfacerust-analyzer cargo sudo-rs 0.2.14 system/interface/::GroupIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/GroupId#; |
| 590 | use craterust-analyzer cargo sudo-rs 0.2.14 crate/::systemrust-analyzer cargo sudo-rs 0.2.14 system/::testsrust-analyzer cargo sudo-rs 0.2.14 system/tests/::tempfilerust-analyzer cargo sudo-rs 0.2.14 system/tests/tempfile().; |
| 591 | |
| 592 | static TEST_USER_IDrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/tests/TEST_USER_ID.: UserIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/UserId# = UserIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/UserId#::ROOTrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[UserId]ROOT.; |
| 593 | |
| 594 | fn auth_user_from_uidrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/tests/auth_user_from_uid().(uid: libcrust-analyzer cargo libc 0.2.186 crate/::uid_trust-analyzer cargo libc 0.2.186 unix/uid_t#) -> AuthUserrust-analyzer cargo sudo-rs 0.2.14 common/resolve/AuthUser# { |
| 595 | AuthUserrust-analyzer cargo sudo-rs 0.2.14 common/resolve/AuthUser#::from_user_for_targetpwrust-analyzer cargo sudo-rs 0.2.14 common/resolve/impl#[AuthUser]from_user_for_targetpw().(Userrust-analyzer cargo sudo-rs 0.2.14 system/User# { |
| 596 | uidrust-analyzer cargo sudo-rs 0.2.14 system/User#uid.: UserIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/UserId#::newrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[UserId]new().(uid), |
| 597 | gidrust-analyzer cargo sudo-rs 0.2.14 system/User#gid.: GroupIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/GroupId#::newrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[GroupId]new().(0), |
| 598 | namerust-analyzer cargo sudo-rs 0.2.14 system/User#name.: SudoStringrust-analyzer cargo sudo-rs 0.2.14 common/string/SudoString#::newrust-analyzer cargo sudo-rs 0.2.14 common/string/impl#[SudoString]new().("dummy".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 599 | homerust-analyzer cargo sudo-rs 0.2.14 system/User#home.: SudoPathrust-analyzer cargo sudo-rs 0.2.14 common/path/SudoPath#::newrust-analyzer cargo sudo-rs 0.2.14 common/path/impl#[SudoPath]new().(Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().("/nonexistent").to_ownedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path][ToOwned]to_owned().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 600 | shellrust-analyzer cargo sudo-rs 0.2.14 system/User#shell.: Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().("/bin/sh").to_ownedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path][ToOwned]to_owned().(), |
| 601 | groupsrust-analyzer cargo sudo-rs 0.2.14 system/User#groups.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![], |
| 602 | }) |
| 603 | } |
| 604 | |
| 605 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 606 | fn can_encode_and_decoderust-analyzer cargo sudo-rs 0.2.14 system/timestamp/tests/can_encode_and_decode().() { |
| 607 | let tty_sample = SessionRecordrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecord#::newrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecord]new().( |
| 608 | RecordScoperust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#::Ttyrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Tty# { |
| 609 | tty_devicerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Tty#tty_device.: DeviceIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/DeviceId#::newrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[DeviceId]new().(10), |
| 610 | session_pidrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Tty#session_pid.: ProcessIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/ProcessId#::newrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[ProcessId]new().(42), |
| 611 | init_timerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Tty#init_time.: ProcessCreateTimerust-analyzer cargo sudo-rs 0.2.14 system/time/ProcessCreateTime#::newrust-analyzer cargo sudo-rs 0.2.14 system/time/impl#[ProcessCreateTime]new().(1, 0), |
| 612 | }, |
| 613 | UserIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/UserId#::newrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[UserId]new().(999), |
| 614 | ) |
| 615 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 616 | |
| 617 | let mut bytes = tty_sample.as_bytesrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecord]as_bytes().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 618 | let decoded = SessionRecordrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecord#::from_bytesrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecord]from_bytes().(&bytes).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 619 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(tty_sample, decoded); |
| 620 | |
| 621 | // we provide some invalid input |
| 622 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(SessionRecordrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecord#::from_bytesrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecord]from_bytes().(&bytes[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().1..]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 623 | |
| 624 | // we have remaining input after decoding |
| 625 | bytes.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(0); |
| 626 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(SessionRecordrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecord#::from_bytesrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecord]from_bytes().(&bytes).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 627 | |
| 628 | let ppid_sample = SessionRecordrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecord#::newrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecord]new().( |
| 629 | RecordScoperust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#::Ppidrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Ppid# { |
| 630 | group_pidrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Ppid#group_pid.: ProcessIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/ProcessId#::newrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[ProcessId]new().(42), |
| 631 | session_pidrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Ppid#session_pid.: ProcessIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/ProcessId#::newrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[ProcessId]new().(43), |
| 632 | init_timerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Ppid#init_time.: ProcessCreateTimerust-analyzer cargo sudo-rs 0.2.14 system/time/ProcessCreateTime#::newrust-analyzer cargo sudo-rs 0.2.14 system/time/impl#[ProcessCreateTime]new().(151, 0), |
| 633 | }, |
| 634 | UserIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/UserId#::newrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[UserId]new().(123), |
| 635 | ) |
| 636 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 637 | let bytes = ppid_sample.as_bytesrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecord]as_bytes().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 638 | let decoded = SessionRecordrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecord#::from_bytesrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecord]from_bytes().(&bytes).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 639 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(ppid_sample, decoded); |
| 640 | } |
| 641 | |
| 642 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 643 | fn timestamp_record_matches_worksrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/tests/timestamp_record_matches_works().() { |
| 644 | let init_time = ProcessCreateTimerust-analyzer cargo sudo-rs 0.2.14 system/time/ProcessCreateTime#::newrust-analyzer cargo sudo-rs 0.2.14 system/time/impl#[ProcessCreateTime]new().(1, 0); |
| 645 | let scope = RecordScoperust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#::Ttyrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Tty# { |
| 646 | tty_devicerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Tty#tty_device.: DeviceIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/DeviceId#::newrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[DeviceId]new().(12), |
| 647 | session_pidrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Tty#session_pid.: ProcessIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/ProcessId#::newrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[ProcessId]new().(1234), |
| 648 | init_timerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Tty#init_time., |
| 649 | }; |
| 650 | |
| 651 | let tty_sample = SessionRecordrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecord#::newrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecord]new().(scope, UserIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/UserId#::newrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[UserId]new().(675)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 652 | |
| 653 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(tty_sample.matchesrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecord]matches().(&scope, &auth_user_from_uidrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/tests/auth_user_from_uid().(675))); |
| 654 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().tty_sample.matchesrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecord]matches().(&scope, &auth_user_from_uidrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/tests/auth_user_from_uid().(789))); |
| 655 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().tty_sample.matchesrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecord]matches().( |
| 656 | &RecordScoperust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#::Ttyrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Tty# { |
| 657 | tty_devicerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Tty#tty_device.: DeviceIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/DeviceId#::newrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[DeviceId]new().(20), |
| 658 | session_pidrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Tty#session_pid.: ProcessIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/ProcessId#::newrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[ProcessId]new().(1234), |
| 659 | init_timerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Tty#init_time. |
| 660 | }, |
| 661 | &auth_user_from_uidrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/tests/auth_user_from_uid().(675), |
| 662 | )); |
| 663 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().tty_sample.matchesrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecord]matches().( |
| 664 | &RecordScoperust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#::Ppidrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Ppid# { |
| 665 | group_pidrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Ppid#group_pid.: ProcessIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/ProcessId#::newrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[ProcessId]new().(42), |
| 666 | session_pidrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Ppid#session_pid.: ProcessIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/ProcessId#::newrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[ProcessId]new().(43), |
| 667 | init_timerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Ppid#init_time. |
| 668 | }, |
| 669 | &auth_user_from_uidrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/tests/auth_user_from_uid().(675), |
| 670 | )); |
| 671 | |
| 672 | // make sure time is different |
| 673 | stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::threadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/::sleeprust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/functions/sleep().(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::timerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/::Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::from_millisrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]from_millis().(1)); |
| 674 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().tty_sample.matchesrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecord]matches().( |
| 675 | &RecordScoperust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#::Ttyrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Tty# { |
| 676 | tty_devicerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Tty#tty_device.: DeviceIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/DeviceId#::newrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[DeviceId]new().(12), |
| 677 | session_pidrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Tty#session_pid.: ProcessIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/ProcessId#::newrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[ProcessId]new().(1234), |
| 678 | init_timerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Tty#init_time.: ProcessCreateTimerust-analyzer cargo sudo-rs 0.2.14 system/time/ProcessCreateTime#::newrust-analyzer cargo sudo-rs 0.2.14 system/time/impl#[ProcessCreateTime]new().(1, 1) |
| 679 | }, |
| 680 | &auth_user_from_uidrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/tests/auth_user_from_uid().(675), |
| 681 | )); |
| 682 | } |
| 683 | |
| 684 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 685 | fn timestamp_record_written_between_worksrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/tests/timestamp_record_written_between_works().() { |
| 686 | let some_time = SystemTimerust-analyzer cargo sudo-rs 0.2.14 system/time/SystemTime#::nowrust-analyzer cargo sudo-rs 0.2.14 system/time/impl#[SystemTime]now().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().() rust-analyzer cargo sudo-rs 0.2.14 system/time/impl#[SystemTime][`Add<Duration>`]add().+rust-analyzer cargo sudo-rs 0.2.14 system/time/impl#[SystemTime][`Add<Duration>`]add(). rust-analyzer cargo sudo-rs 0.2.14 system/time/impl#[SystemTime][`Add<Duration>`]add().Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::from_secsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]from_secs().(100 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().60); |
| 687 | let scope = RecordScoperust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#::Ttyrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Tty# { |
| 688 | tty_devicerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Tty#tty_device.: DeviceIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/DeviceId#::newrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[DeviceId]new().(12), |
| 689 | session_pidrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Tty#session_pid.: ProcessIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/ProcessId#::newrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[ProcessId]new().(1234), |
| 690 | init_timerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Tty#init_time.: ProcessCreateTimerust-analyzer cargo sudo-rs 0.2.14 system/time/ProcessCreateTime#::newrust-analyzer cargo sudo-rs 0.2.14 system/time/impl#[ProcessCreateTime]new().(0, 0), |
| 691 | }; |
| 692 | let sample = SessionRecordrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecord#::initrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecord]init().(scope, UserIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/UserId#::newrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[UserId]new().(1234), true, some_time); |
| 693 | |
| 694 | let dur = Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::from_secsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]from_secs().(30); |
| 695 | |
| 696 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(sample.written_betweenrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecord]written_between().(some_time, some_time)); |
| 697 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(sample.written_betweenrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecord]written_between().(some_time, some_time +rust-analyzer cargo sudo-rs 0.2.14 system/time/impl#[SystemTime][`Add<Duration>`]add(). dur)); |
| 698 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(sample.written_betweenrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecord]written_between().(some_time -rust-analyzer cargo sudo-rs 0.2.14 system/time/impl#[SystemTime][`Sub<Duration>`]sub(). dur, some_time)); |
| 699 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().sample.written_betweenrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecord]written_between().(some_time +rust-analyzer cargo sudo-rs 0.2.14 system/time/impl#[SystemTime][`Add<Duration>`]add(). dur, some_time -rust-analyzer cargo sudo-rs 0.2.14 system/time/impl#[SystemTime][`Sub<Duration>`]sub(). dur)); |
| 700 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().sample.written_betweenrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecord]written_between().(some_time +rust-analyzer cargo sudo-rs 0.2.14 system/time/impl#[SystemTime][`Add<Duration>`]add(). dur, some_time +rust-analyzer cargo sudo-rs 0.2.14 system/time/impl#[SystemTime][`Add<Duration>`]add(). dur +rust-analyzer cargo sudo-rs 0.2.14 system/time/impl#[SystemTime][`Add<Duration>`]add(). dur)); |
| 701 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().sample.written_betweenrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecord]written_between().(some_time -rust-analyzer cargo sudo-rs 0.2.14 system/time/impl#[SystemTime][`Sub<Duration>`]sub(). dur -rust-analyzer cargo sudo-rs 0.2.14 system/time/impl#[SystemTime][`Sub<Duration>`]sub(). dur, some_time -rust-analyzer cargo sudo-rs 0.2.14 system/time/impl#[SystemTime][`Sub<Duration>`]sub(). dur)); |
| 702 | } |
| 703 | |
| 704 | fn tempfile_with_datarust-analyzer cargo sudo-rs 0.2.14 system/timestamp/tests/tempfile_with_data().(data: &[u8]) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#> { |
| 705 | let mut file = tempfilerust-analyzer cargo sudo-rs 0.2.14 system/tests/tempfile().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 706 | file.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(data)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 707 | file.rewindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#rewind().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 708 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(file) |
| 709 | } |
| 710 | |
| 711 | fn data_from_tempfilerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/tests/data_from_tempfile().(mut f: Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>> { |
| 712 | let mut v = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]; |
| 713 | f.rewindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#rewind().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 714 | f.read_to_endrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File][Read]read_to_end().(&mut v)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 715 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(v) |
| 716 | } |
| 717 | |
| 718 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 719 | fn session_record_file_header_checksrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/tests/session_record_file_header_checks().() { |
| 720 | // valid header should remain valid |
| 721 | let c = tempfile_with_datarust-analyzer cargo sudo-rs 0.2.14 system/timestamp/tests/tempfile_with_data().(&[0xD0, 0x50, 0x02, 0x00]).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 722 | let timeout = Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::from_secsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]from_secs().(30); |
| 723 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(SessionRecordFilerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile#::newrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]new().(TEST_USER_IDrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/tests/TEST_USER_ID., c.try_clonerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]try_clone().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), timeout).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 724 | let v = data_from_tempfilerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/tests/data_from_tempfile().(c).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 725 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&v[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., &[0xD0, 0x50, 0x02, 0x00]); |
| 726 | |
| 727 | // invalid headers should be corrected |
| 728 | let c = tempfile_with_datarust-analyzer cargo sudo-rs 0.2.14 system/timestamp/tests/tempfile_with_data().(&[0xAB, 0xBA]).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 729 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(SessionRecordFilerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile#::newrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]new().(TEST_USER_IDrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/tests/TEST_USER_ID., c.try_clonerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]try_clone().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), timeout).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 730 | let v = data_from_tempfilerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/tests/data_from_tempfile().(c).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 731 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&v[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., &[0xD0, 0x50, 0x02, 0x00]); |
| 732 | |
| 733 | // empty header should be filled in |
| 734 | let c = tempfile_with_datarust-analyzer cargo sudo-rs 0.2.14 system/timestamp/tests/tempfile_with_data().(&[]).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 735 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(SessionRecordFilerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile#::newrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]new().(TEST_USER_IDrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/tests/TEST_USER_ID., c.try_clonerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]try_clone().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), timeout).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 736 | let v = data_from_tempfilerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/tests/data_from_tempfile().(c).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 737 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&v[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., &[0xD0, 0x50, 0x02, 0x00]); |
| 738 | |
| 739 | // invalid version should reset file |
| 740 | let c = tempfile_with_datarust-analyzer cargo sudo-rs 0.2.14 system/timestamp/tests/tempfile_with_data().(&[0xD0, 0x50, 0xAB, 0xBA, 0x0, 0x0]).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 741 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(SessionRecordFilerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile#::newrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]new().(TEST_USER_IDrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/tests/TEST_USER_ID., c.try_clonerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]try_clone().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), timeout).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 742 | let v = data_from_tempfilerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/tests/data_from_tempfile().(c).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 743 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&v[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., &[0xD0, 0x50, 0x02, 0x00]); |
| 744 | } |
| 745 | |
| 746 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 747 | fn can_create_and_update_valid_filerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/tests/can_create_and_update_valid_file().() { |
| 748 | let timeout = Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::from_secsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]from_secs().(30); |
| 749 | let c = tempfile_with_datarust-analyzer cargo sudo-rs 0.2.14 system/timestamp/tests/tempfile_with_data().(&[]).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 750 | let mut srf = |
| 751 | SessionRecordFilerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/SessionRecordFile#::newrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]new().(TEST_USER_IDrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/tests/TEST_USER_ID., c.try_clonerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]try_clone().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), timeout).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 752 | let tty_scope = RecordScoperust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#::Ttyrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Tty# { |
| 753 | tty_devicerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Tty#tty_device.: DeviceIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/DeviceId#::newrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[DeviceId]new().(0), |
| 754 | session_pidrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Tty#session_pid.: ProcessIdrust-analyzer cargo sudo-rs 0.2.14 system/interface/ProcessId#::newrust-analyzer cargo sudo-rs 0.2.14 system/interface/impl#[ProcessId]new().(0), |
| 755 | init_timerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/RecordScope#Tty#init_time.: ProcessCreateTimerust-analyzer cargo sudo-rs 0.2.14 system/time/ProcessCreateTime#::newrust-analyzer cargo sudo-rs 0.2.14 system/time/impl#[ProcessCreateTime]new().(0, 0), |
| 756 | }; |
| 757 | let auth_user = auth_user_from_uidrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/tests/auth_user_from_uid().(2424); |
| 758 | let res = srf.createrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]create().(tty_scope, &auth_user).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 759 | let CreateResultrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/CreateResult#::Createdrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/CreateResult#Created# { timerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/CreateResult#Created#time. } = res else { |
| 760 | panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Expected record to be created"); |
| 761 | }; |
| 762 | |
| 763 | stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::threadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/::sleeprust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/functions/sleep().(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::timerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/::Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::from_millisrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]from_millis().(1)); |
| 764 | let second = srf.touchrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]touch().(tty_scope, &auth_user).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 765 | let TouchResultrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/TouchResult#::Updatedrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/TouchResult#Updated# { old_timerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/TouchResult#Updated#old_time., new_timerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/TouchResult#Updated#new_time. } = second else { |
| 766 | panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Expected record to be updated"); |
| 767 | }; |
| 768 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(time, old_time); |
| 769 | assert_nerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_ne!!(old_time, new_time); |
| 770 | |
| 771 | stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::threadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/::sleeprust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/functions/sleep().(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::timerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/::Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::from_millisrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]from_millis().(1)); |
| 772 | let res = srf.createrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]create().(tty_scope, &auth_user).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 773 | let CreateResultrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/CreateResult#::Updatedrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/CreateResult#Updated# { old_timerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/CreateResult#Updated#old_time., new_timerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/CreateResult#Updated#new_time. } = res else { |
| 774 | panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Expected record to be updated"); |
| 775 | }; |
| 776 | assert_nerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_ne!!(old_time, new_time); |
| 777 | |
| 778 | // reset the file |
| 779 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(srf.resetrust-analyzer cargo sudo-rs 0.2.14 system/timestamp/impl#[SessionRecordFile]reset().().is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 780 | |
| 781 | // after all this the data should be just an empty header |
| 782 | let data = data_from_tempfilerust-analyzer cargo sudo-rs 0.2.14 system/timestamp/tests/data_from_tempfile().(c).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 783 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&data, &[0xD0, 0x50, 0x02, 0x00]); |
| 784 | } |
| 785 | } |