summaryrefslogtreecommitdiffstats
path: root/src/testdisk.c
diff options
context:
space:
mode:
authorChristophe Grenier <[email protected]>2013-04-11 18:36:22 +0200
committerChristophe Grenier <[email protected]>2013-04-11 18:36:22 +0200
commit968b8fd059dc9528d295c1fc4aa362a810d04fde (patch)
treeaf6634f7336babd849d2bb723bc297ddfa0f51e7 /src/testdisk.c
parent7d216e7bb4841c16e2b856a1d2d8a58c5844d439 (diff)
If no disk is detected, the user isn't root and TestDisk/PhotoRec are compiled with sudo support, restart using sudo without asking first the user.
Diffstat (limited to 'src/testdisk.c')
-rw-r--r--src/testdisk.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/testdisk.c b/src/testdisk.c
index 209fc39f..9d52c855 100644
--- a/src/testdisk.c
+++ b/src/testdisk.c
@@ -412,7 +412,20 @@ int main( int argc, char **argv )
log_info("\n");
}
log_info("\n");
- use_sudo=do_curses_testdisk(verbose,dump_ind,list_disk,saveheader,cmd_device,&cmd_run);
+#ifdef SUDO_BIN
+ if(list_disk==NULL)
+ {
+#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(DJGPP)
+#else
+#ifdef HAVE_GETEUID
+ if(geteuid()!=0)
+ use_sudo=2;
+#endif
+#endif
+ }
+#endif
+ if(use_sudo==0)
+ use_sudo=do_curses_testdisk(verbose,dump_ind,list_disk,saveheader,cmd_device,&cmd_run);
#ifdef HAVE_NCURSES
end_ncurses();
#endif
@@ -455,17 +468,21 @@ int main( int argc, char **argv )
{
printf("TestDisk: Log file corrupted!\n");
}
- else
- {
- printf("TestDisk exited normally.\n");
- }
if(write_used!=0)
{
printf("You have to reboot for the change to take effect.\n");
}
#ifdef SUDO_BIN
if(use_sudo>0)
+ {
+ printf("\n");
+ if(use_sudo>1)
+ printf("No disk found.\n");
+ 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);
+ }
#endif
return 0;
}