summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2019-04-29 19:22:57 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2019-04-29 19:22:57 +0200
commitb45cb7fb4556d8822751c9fe5e29b028c747c804 (patch)
tree58c19e1da86cb1ac74dd7964af37660fbc549db8
parentbfe4aad16cfc99f142c75f914d536d10b551188b (diff)
Avoid two logging prompts when using sudo.
Close https://github.com/cgsecurity/testdisk/issues/61
-rw-r--r--src/phmain.c6
-rw-r--r--src/sudo.c26
-rw-r--r--src/sudo.h2
-rw-r--r--src/testdisk.c6
4 files changed, 30 insertions, 10 deletions
diff --git a/src/phmain.c b/src/phmain.c
index 6a9c382..0949376 100644
--- a/src/phmain.c
+++ b/src/phmain.c
@@ -182,6 +182,10 @@ int main( int argc, char **argv )
}
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))
{
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("root (superuser) privileges.\n");
printf("\n");
- run_sudo(argc, argv);
+ run_sudo(argc, argv, create_log);
}
#endif
delete_list_disk(list_disk);
diff --git a/src/sudo.c b/src/sudo.c
index 5f346ba..245b006 100644
--- a/src/sudo.c
+++ b/src/sudo.c
@@ -38,16 +38,28 @@
#include "types.h"
#include "common.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;
- 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;
+ if(argc==1)
+ {
+ argv2 = (char **)MALLOC(sizeof(char *) * 4);
+ argv2[0] = strdup(SUDO_BIN);
+ 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("Usually there is no echo or '*' displayed when you type your password.\n");
printf("\n");
diff --git a/src/sudo.h b/src/sudo.h
index fce6f3c..d16ee66 100644
--- a/src/sudo.h
+++ b/src/sudo.h
@@ -23,7 +23,7 @@
#ifdef __cplusplus
extern "C" {
#endif
-void run_sudo(int argc, char **argv);
+void run_sudo(const int argc, char **argv, const int create_log);
#ifdef __cplusplus
} /* closing brace for extern "C" */
#endif
diff --git a/src/testdisk.c b/src/testdisk.c
index 9a1580a..4317cc7 100644
--- a/src/testdisk.c
+++ b/src/testdisk.c
@@ -257,6 +257,10 @@ int main( int argc, char **argv )
}
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))
{
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("root (superuser) privileges.\n");
printf("\n");
- run_sudo(argc, argv);
+ run_sudo(argc, argv, create_log);
}
#endif
return 0;