Skip to content

Commit

Permalink
fix a bug when running tests with sudo
Browse files Browse the repository at this point in the history
  • Loading branch information
mhogomchungu committed Jun 7, 2024
1 parent cad9bcc commit 953f9ff
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
10 changes: 8 additions & 2 deletions zuluCrypt-cli/bin/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,18 @@

static void _seteuid( uid_t uid )
{
if( seteuid( uid ) ){;}
if( seteuid( uid ) != 0 ){

perror( "seteuid" ) ;
}
}

static void _setuid( uid_t uid )
{
if( setuid( uid ) ){;}
if( setuid( uid ) != 0 ){

perror( "setuid" ) ;
}
}

static int zuluCryptEXEGetDevice( const char * device )
Expand Down
40 changes: 39 additions & 1 deletion zuluCrypt-cli/bin/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -381,17 +381,55 @@ static int _loop_device_module_is_not_present( void )

int zuluCryptRunTest( void )
{
unsetenv( "SUDO_UID" ) ;

uid_t uid = getuid() ;
struct stat st ;

int r = seteuid( 0 ) ;

if( r != 0 ){

perror( "seteuid" ) ;

return 1 ;
}

r = setgid( uid ) ;

if( r != 0 ){

perror( "setgid" ) ;

return 1 ;
}

r = setgroups( 1,&uid ) ;

if( r != 0 ){

perror( "setgroups" ) ;

return 1 ;
}

r = setegid( uid ) ;

if( r != 0 ){

perror( "setegid" ) ;

return 1 ;
}

r = setuid( uid ) ;

if( r ){}
if( r != 0 ){

perror( "setuid" ) ;

return 1 ;
}

if( _loop_device_module_is_not_present() ){
printf( "\nWARNING: \"loop\" kernel module does not appear to be loaded,\n" ) ;
Expand Down

0 comments on commit 953f9ff

Please sign in to comment.