@@ -33,6 +33,7 @@ use libc::{O_RDONLY, O_RDWR, O_WRONLY};
3333use input_linux:: { uinput:: UInputHandle , EventKind , Key , SynchronizeKind } ;
3434use input_linux_sys:: { uinput_setup, input_id, timeval, input_event} ;
3535use nix:: poll:: { poll, PollFd , PollFlags } ;
36+ use privdrop;
3637
3738const DFR_WIDTH : i32 = 2008 ;
3839const DFR_HEIGHT : i32 = 64 ;
@@ -298,8 +299,7 @@ fn find_backlight() -> Result<PathBuf> {
298299 Err ( anyhow ! ( "No backlight device found" ) )
299300}
300301
301- fn set_backlight ( path : & Path , value : u32 ) {
302- let mut file = OpenOptions :: new ( ) . write ( true ) . open ( path) . unwrap ( ) ;
302+ fn set_backlight ( mut file : & File , value : u32 ) {
303303 file. write ( format ! ( "{}\n " , value) . as_bytes ( ) ) . unwrap ( ) ;
304304}
305305
@@ -395,6 +395,16 @@ fn main() {
395395 ]
396396 } ) . unwrap ( ) ;
397397 uinput. dev_create ( ) . unwrap ( ) ;
398+
399+ let bl_file = OpenOptions :: new ( ) . write ( true ) . open ( bl_path) . unwrap ( ) ;
400+
401+ privdrop:: PrivDrop :: default ( )
402+ . chroot ( "/var/empty" )
403+ . user ( "nobody" )
404+ . group ( "nobody" )
405+ . apply ( )
406+ . unwrap_or_else ( |e| { panic ! ( "Failed to drop privileges: {}" , e) } ) ;
407+
398408 let mut digitizer: Option < InputDevice > = None ;
399409 let mut touches = HashMap :: new ( ) ;
400410 let mut last_active = Instant :: now ( ) ;
@@ -499,7 +509,7 @@ fn main() {
499509 } ;
500510 if current_bl != new_bl {
501511 current_bl = new_bl;
502- set_backlight ( & bl_path , current_bl) ;
512+ set_backlight ( & bl_file , current_bl) ;
503513 }
504514 }
505515}
0 commit comments