@@ -35,18 +35,18 @@ const SIZE_OF_BOOL: i64 = std::mem::size_of::<BoolStorage>() as i64;
35
35
const MOD_OFFSET : i64 = SIZE_OF_TS + SIZE_OF_BOOL ;
36
36
37
37
#[ derive( Debug ) ]
38
- pub struct SessionRecordFile < ' u > {
38
+ pub struct SessionRecordFile {
39
39
file : File ,
40
40
timeout : Duration ,
41
- for_user : & ' u str ,
41
+ for_user : UserId ,
42
42
}
43
43
44
- impl < ' u > SessionRecordFile < ' u > {
44
+ impl SessionRecordFile {
45
45
const BASE_PATH : & ' static str = "/var/run/sudo-rs/ts" ;
46
46
47
- pub fn open_for_user ( user : & ' u str , timeout : Duration ) -> io:: Result < Self > {
47
+ pub fn open_for_user ( user : UserId , timeout : Duration ) -> io:: Result < Self > {
48
48
let mut path = PathBuf :: from ( Self :: BASE_PATH ) ;
49
- path. push ( user) ;
49
+ path. push ( user. to_string ( ) ) ;
50
50
SessionRecordFile :: new ( user, secure_open_cookie_file ( & path) ?, timeout)
51
51
}
52
52
@@ -59,7 +59,7 @@ impl<'u> SessionRecordFile<'u> {
59
59
/// Create a new SessionRecordFile from the given i/o stream.
60
60
/// Timestamps in this file are considered valid if they were created or
61
61
/// updated at most `timeout` time ago.
62
- pub fn new ( for_user : & ' u str , io : File , timeout : Duration ) -> io:: Result < Self > {
62
+ pub fn new ( for_user : UserId , io : File , timeout : Duration ) -> io:: Result < Self > {
63
63
let mut session_records = SessionRecordFile {
64
64
file : io,
65
65
timeout,
@@ -578,6 +578,8 @@ mod tests {
578
578
579
579
use crate :: system:: tests:: tempfile;
580
580
581
+ const TEST_USER_ID : UserId = 1000 ;
582
+
581
583
impl SetLength for Cursor < Vec < u8 > > {
582
584
fn set_len ( & mut self , new_len : usize ) -> io:: Result < ( ) > {
583
585
self . get_mut ( ) . truncate ( new_len) ;
@@ -714,25 +716,25 @@ mod tests {
714
716
// valid header should remain valid
715
717
let c = tempfile_with_data ( & [ 0xD0 , 0x50 , 0x01 , 0x00 ] ) . unwrap ( ) ;
716
718
let timeout = Duration :: seconds ( 30 ) ;
717
- assert ! ( SessionRecordFile :: new( "test" , c. try_clone( ) . unwrap( ) , timeout) . is_ok( ) ) ;
719
+ assert ! ( SessionRecordFile :: new( TEST_USER_ID , c. try_clone( ) . unwrap( ) , timeout) . is_ok( ) ) ;
718
720
let v = data_from_tempfile ( c) . unwrap ( ) ;
719
721
assert_eq ! ( & v[ ..] , & [ 0xD0 , 0x50 , 0x01 , 0x00 ] ) ;
720
722
721
723
// invalid headers should be corrected
722
724
let c = tempfile_with_data ( & [ 0xAB , 0xBA ] ) . unwrap ( ) ;
723
- assert ! ( SessionRecordFile :: new( "test" , c. try_clone( ) . unwrap( ) , timeout) . is_ok( ) ) ;
725
+ assert ! ( SessionRecordFile :: new( TEST_USER_ID , c. try_clone( ) . unwrap( ) , timeout) . is_ok( ) ) ;
724
726
let v = data_from_tempfile ( c) . unwrap ( ) ;
725
727
assert_eq ! ( & v[ ..] , & [ 0xD0 , 0x50 , 0x01 , 0x00 ] ) ;
726
728
727
729
// empty header should be filled in
728
730
let c = tempfile_with_data ( & [ ] ) . unwrap ( ) ;
729
- assert ! ( SessionRecordFile :: new( "test" , c. try_clone( ) . unwrap( ) , timeout) . is_ok( ) ) ;
731
+ assert ! ( SessionRecordFile :: new( TEST_USER_ID , c. try_clone( ) . unwrap( ) , timeout) . is_ok( ) ) ;
730
732
let v = data_from_tempfile ( c) . unwrap ( ) ;
731
733
assert_eq ! ( & v[ ..] , & [ 0xD0 , 0x50 , 0x01 , 0x00 ] ) ;
732
734
733
735
// invalid version should reset file
734
736
let c = tempfile_with_data ( & [ 0xD0 , 0x50 , 0xAB , 0xBA , 0x0 , 0x0 ] ) . unwrap ( ) ;
735
- assert ! ( SessionRecordFile :: new( "test" , c. try_clone( ) . unwrap( ) , timeout) . is_ok( ) ) ;
737
+ assert ! ( SessionRecordFile :: new( TEST_USER_ID , c. try_clone( ) . unwrap( ) , timeout) . is_ok( ) ) ;
736
738
let v = data_from_tempfile ( c) . unwrap ( ) ;
737
739
assert_eq ! ( & v[ ..] , & [ 0xD0 , 0x50 , 0x01 , 0x00 ] ) ;
738
740
}
@@ -741,7 +743,8 @@ mod tests {
741
743
fn can_create_and_update_valid_file ( ) {
742
744
let timeout = Duration :: seconds ( 30 ) ;
743
745
let c = tempfile_with_data ( & [ ] ) . unwrap ( ) ;
744
- let mut srf = SessionRecordFile :: new ( "test" , c. try_clone ( ) . unwrap ( ) , timeout) . unwrap ( ) ;
746
+ let mut srf =
747
+ SessionRecordFile :: new ( TEST_USER_ID , c. try_clone ( ) . unwrap ( ) , timeout) . unwrap ( ) ;
745
748
let tty_scope = RecordScope :: Tty {
746
749
tty_device : 0 ,
747
750
session_pid : 0 ,
0 commit comments