Avoid two logging prompts when using sudo.

Close https://github.com/cgsecurity/testdisk/issues/61
This commit is contained in:
Christophe Grenier 2019-04-29 19:22:57 +02:00
parent bfe4aad16c
commit b45cb7fb45
4 changed files with 30 additions and 10 deletions

View file

@ -182,6 +182,10 @@ int main( int argc, char **argv )
} }
logfile=argv[++i]; logfile=argv[++i];
} }
else if((strcmp(argv[i],"/nolog")==0) ||(strcmp(argv[i],"-nolog")==0))
{
create_log=TD_LOG_NONE;
}
else if((strcmp(argv[i],"/log")==0) ||(strcmp(argv[i],"-log")==0)) else if((strcmp(argv[i],"/log")==0) ||(strcmp(argv[i],"-log")==0))
{ {
if(create_log==TD_LOG_NONE) if(create_log==TD_LOG_NONE)
@ -387,7 +391,7 @@ int main( int argc, char **argv )
printf("PhotoRec will try to restart itself using the sudo command to get\n"); printf("PhotoRec will try to restart itself using the sudo command to get\n");
printf("root (superuser) privileges.\n"); printf("root (superuser) privileges.\n");
printf("\n"); printf("\n");
run_sudo(argc, argv); run_sudo(argc, argv, create_log);
} }
#endif #endif
delete_list_disk(list_disk); delete_list_disk(list_disk);

View file

@ -38,16 +38,28 @@
#include "types.h" #include "types.h"
#include "common.h" #include "common.h"
#include "sudo.h" #include "sudo.h"
#include "log.h"
void run_sudo(int argc, char **argv) void run_sudo(const int argc, char **argv, const int create_log)
{ {
int i;
char **argv2; char **argv2;
argv2 = (char **)MALLOC(sizeof(char *) * (argc + 2)); if(argc==1)
argv2[0]=strdup(SUDO_BIN); {
for (i=0; i < argc; i++) argv2 = (char **)MALLOC(sizeof(char *) * 4);
argv2[i+1] = argv[i]; argv2[0] = strdup(SUDO_BIN);
argv2[i+1]=NULL; argv2[1] = argv[0];
argv2[2] = strdup(create_log==TD_LOG_NONE?"/nolog":"/debug");
argv2[3] = NULL;
}
else
{
int i;
argv2 = (char **)MALLOC(sizeof(char *) * (argc + 2));
argv2[0]=strdup(SUDO_BIN);
for (i=0; i < argc; i++)
argv2[i+1] = argv[i];
argv2[i+1]=NULL;
}
printf("sudo may ask your user password, it doesn't ask for the root password.\n"); printf("sudo may ask your user password, it doesn't ask for the root password.\n");
printf("Usually there is no echo or '*' displayed when you type your password.\n"); printf("Usually there is no echo or '*' displayed when you type your password.\n");
printf("\n"); printf("\n");

View file

@ -23,7 +23,7 @@
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
void run_sudo(int argc, char **argv); void run_sudo(const int argc, char **argv, const int create_log);
#ifdef __cplusplus #ifdef __cplusplus
} /* closing brace for extern "C" */ } /* closing brace for extern "C" */
#endif #endif

View file

@ -257,6 +257,10 @@ int main( int argc, char **argv )
} }
logfile=argv[++i]; logfile=argv[++i];
} }
else if((strcmp(argv[i],"/nolog")==0) ||(strcmp(argv[i],"-nolog")==0))
{
create_log=TD_LOG_NONE;
}
else if((strcmp(argv[i],"/log")==0) ||(strcmp(argv[i],"-log")==0)) else if((strcmp(argv[i],"/log")==0) ||(strcmp(argv[i],"-log")==0))
{ {
if(create_log==TD_LOG_NONE) if(create_log==TD_LOG_NONE)
@ -513,7 +517,7 @@ int main( int argc, char **argv )
printf("TestDisk will try to restart itself using the sudo command to get\n"); printf("TestDisk will try to restart itself using the sudo command to get\n");
printf("root (superuser) privileges.\n"); printf("root (superuser) privileges.\n");
printf("\n"); printf("\n");
run_sudo(argc, argv); run_sudo(argc, argv, create_log);
} }
#endif #endif
return 0; return 0;