@@ -35,18 +35,18 @@ const SIZE_OF_BOOL: i64 = std::mem::size_of::<BoolStorage>() as i64;
3535const MOD_OFFSET : i64 = SIZE_OF_TS + SIZE_OF_BOOL ;
3636
3737#[ derive( Debug ) ]
38- pub struct SessionRecordFile < ' u > {
38+ pub struct SessionRecordFile {
3939 file : File ,
4040 timeout : Duration ,
41- for_user : & ' u str ,
41+ for_user : UserId ,
4242}
4343
44- impl < ' u > SessionRecordFile < ' u > {
44+ impl SessionRecordFile {
4545 const BASE_PATH : & ' static str = "/var/run/sudo-rs/ts" ;
4646
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 > {
4848 let mut path = PathBuf :: from ( Self :: BASE_PATH ) ;
49- path. push ( user) ;
49+ path. push ( user. to_string ( ) ) ;
5050 SessionRecordFile :: new ( user, secure_open_cookie_file ( & path) ?, timeout)
5151 }
5252
@@ -59,7 +59,7 @@ impl<'u> SessionRecordFile<'u> {
5959 /// Create a new SessionRecordFile from the given i/o stream.
6060 /// Timestamps in this file are considered valid if they were created or
6161 /// 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 > {
6363 let mut session_records = SessionRecordFile {
6464 file : io,
6565 timeout,
@@ -578,6 +578,8 @@ mod tests {
578578
579579 use crate :: system:: tests:: tempfile;
580580
581+ const TEST_USER_ID : UserId = 1000 ;
582+
581583 impl SetLength for Cursor < Vec < u8 > > {
582584 fn set_len ( & mut self , new_len : usize ) -> io:: Result < ( ) > {
583585 self . get_mut ( ) . truncate ( new_len) ;
@@ -714,25 +716,25 @@ mod tests {
714716 // valid header should remain valid
715717 let c = tempfile_with_data ( & [ 0xD0 , 0x50 , 0x01 , 0x00 ] ) . unwrap ( ) ;
716718 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( ) ) ;
718720 let v = data_from_tempfile ( c) . unwrap ( ) ;
719721 assert_eq ! ( & v[ ..] , & [ 0xD0 , 0x50 , 0x01 , 0x00 ] ) ;
720722
721723 // invalid headers should be corrected
722724 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( ) ) ;
724726 let v = data_from_tempfile ( c) . unwrap ( ) ;
725727 assert_eq ! ( & v[ ..] , & [ 0xD0 , 0x50 , 0x01 , 0x00 ] ) ;
726728
727729 // empty header should be filled in
728730 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( ) ) ;
730732 let v = data_from_tempfile ( c) . unwrap ( ) ;
731733 assert_eq ! ( & v[ ..] , & [ 0xD0 , 0x50 , 0x01 , 0x00 ] ) ;
732734
733735 // invalid version should reset file
734736 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( ) ) ;
736738 let v = data_from_tempfile ( c) . unwrap ( ) ;
737739 assert_eq ! ( & v[ ..] , & [ 0xD0 , 0x50 , 0x01 , 0x00 ] ) ;
738740 }
@@ -741,7 +743,8 @@ mod tests {
741743 fn can_create_and_update_valid_file ( ) {
742744 let timeout = Duration :: seconds ( 30 ) ;
743745 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 ( ) ;
745748 let tty_scope = RecordScope :: Tty {
746749 tty_device : 0 ,
747750 session_pid : 0 ,
0 commit comments