summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2020-03-20 16:57:57 +0100
committerChristophe Grenier <grenier@cgsecurity.org>2020-03-20 16:57:57 +0100
commit0fea045597acaefdf129ed882ffa06034c825b40 (patch)
tree2dabc53a58c45fc9785950795263ffe893db9071
parent5934cf54e9d22ee80759d0e78d784f53fa19d78a (diff)
Cleanup code using SUDO_BIN
-rw-r--r--src/nodisk.c8
-rw-r--r--src/pdiskseln.c11
-rw-r--r--src/phmain.c25
-rw-r--r--src/sudo.c5
-rw-r--r--src/tdisksel.c8
-rw-r--r--src/testdisk.c29
6 files changed, 41 insertions, 45 deletions
diff --git a/src/nodisk.c b/src/nodisk.c
index b98e933..86b7161 100644
--- a/src/nodisk.c
+++ b/src/nodisk.c
@@ -22,6 +22,10 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+
+#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(DJGPP) || !defined(HAVE_GETEUID)
+#undef SUDO_BIN
+#endif
#ifdef HAVE_NCURSES
#include <stdio.h>
@@ -53,8 +57,7 @@ int intrf_no_disk_ncurses(const char *prog_name)
wmove(stdscr,11,0);
wprintw(stdscr,"choose \"Run as administrator\".\n");
#elif defined(DJGPP)
-#else
-#ifdef HAVE_GETEUID
+#elif defined(HAVE_GETEUID)
if(geteuid()!=0)
{
wmove(stdscr,8,0);
@@ -78,7 +81,6 @@ int intrf_no_disk_ncurses(const char *prog_name)
#endif
}
#endif
-#endif
wmove(stdscr,22,0);
wattrset(stdscr, A_REVERSE);
waddstr(stdscr,"[ Quit ]");
diff --git a/src/pdiskseln.c b/src/pdiskseln.c
index 9779c8c..b7ed7b5 100644
--- a/src/pdiskseln.c
+++ b/src/pdiskseln.c
@@ -24,6 +24,10 @@
#include <config.h>
#endif
+#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(DJGPP) || !defined(HAVE_GETEUID)
+#undef SUDO_BIN
+#endif
+
#include <stdio.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
@@ -126,10 +130,7 @@ static int photorec_disk_selection_ncurses(struct ph_param *params, struct ph_op
}
{
mvwaddstr(stdscr, INTER_NOTE_Y,0,"Note: ");
-#if defined(__CYGWIN__) || defined(__MINGW32__)
-#else
-#ifndef DJGPP
-#ifdef HAVE_GETEUID
+#if defined(HAVE_GETEUID) && !defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(DJGPP)
if(geteuid()!=0)
{
if(has_colors())
@@ -142,8 +143,6 @@ static int photorec_disk_selection_ncurses(struct ph_param *params, struct ph_op
#endif
}
#endif
-#endif
-#endif
wmove(stdscr, INTER_NOTE_Y+1, 0);
wprintw(stdscr,"Disk capacity must be correctly detected for a successful recovery.");
wmove(stdscr, INTER_NOTE_Y+2, 0);
diff --git a/src/phmain.c b/src/phmain.c
index 34a802f..5f9864f 100644
--- a/src/phmain.c
+++ b/src/phmain.c
@@ -24,6 +24,10 @@
#include <config.h>
#endif
+#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(DJGPP) || !defined(HAVE_GETEUID)
+#undef SUDO_BIN
+#endif
+
#include <stdio.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
@@ -133,7 +137,7 @@ int main( int argc, char **argv )
{
int i;
#ifdef SUDO_BIN
- int use_sudo=0;
+ int use_sudo;
#endif
int create_log=TD_LOG_NONE;
int run_setlocale=1;
@@ -349,15 +353,12 @@ int main( int argc, char **argv )
#endif
log_info("ext2fs lib: %s, ntfs lib: %s, ewf lib: %s, libjpeg: %s, curses lib: %s\n",
td_ext2fs_version(), td_ntfs_version(), td_ewf_version(), td_jpeg_version(), td_curses_version());
-#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(DJGPP)
-#else
-#ifdef HAVE_GETEUID
+#if defined(HAVE_GETEUID) && !defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(DJGPP)
if(geteuid()!=0)
{
log_warning("User is not root!\n");
}
#endif
-#endif
log_flush();
screen_buffer_reset();
/* Scan for available device only if no device or image has been supplied in parameter */
@@ -373,18 +374,14 @@ int main( int argc, char **argv )
reset_array_file_enable(options.list_file_format);
file_options_load(options.list_file_format);
#ifdef SUDO_BIN
- if(list_disk==NULL)
+ if(list_disk==NULL && geteuid()!=0)
{
-#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(DJGPP)
-#else
-#ifdef HAVE_GETEUID
- if(geteuid()!=0)
- use_sudo=2;
-#endif
-#endif
+ use_sudo=2;
}
- if(use_sudo==0)
+ else
+ {
use_sudo=do_curses_photorec(&params, &options, list_disk);
+ }
#else
do_curses_photorec(&params, &options, list_disk);
#endif
diff --git a/src/sudo.c b/src/sudo.c
index 245b006..e1307da 100644
--- a/src/sudo.c
+++ b/src/sudo.c
@@ -23,6 +23,11 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+
+#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(DJGPP) || !defined(HAVE_GETEUID)
+#undef SUDO_BIN
+#endif
+
#ifdef SUDO_BIN
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
diff --git a/src/tdisksel.c b/src/tdisksel.c
index 7bebd3f..89f87c7 100644
--- a/src/tdisksel.c
+++ b/src/tdisksel.c
@@ -22,6 +22,9 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(DJGPP) || !defined(HAVE_GETEUID)
+#undef SUDO_BIN
+#endif
#include <stdio.h>
#ifdef HAVE_UNISTD_H
@@ -113,9 +116,7 @@ static int testdisk_disk_selection_ncurses(int verbose,int dump_ind, const list_
{
int line=INTER_NOTE_Y;
mvwaddstr(stdscr,line++,0,"Note: ");
-#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(DJGPP)
-#else
-#ifdef HAVE_GETEUID
+#if defined(HAVE_GETEUID) && !defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(DJGPP)
if(geteuid()!=0)
{
if(has_colors())
@@ -129,7 +130,6 @@ static int testdisk_disk_selection_ncurses(int verbose,int dump_ind, const list_
#endif
}
#endif
-#endif
waddstr(stdscr,"Disk capacity must be correctly detected for a successful recovery.");
wmove(stdscr,line++,0);
wprintw(stdscr,"If a disk listed above has an incorrect size, check HD jumper settings and BIOS");
diff --git a/src/testdisk.c b/src/testdisk.c
index 4317cc7..8a263e1 100644
--- a/src/testdisk.c
+++ b/src/testdisk.c
@@ -23,6 +23,9 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(DJGPP) || !defined(HAVE_GETEUID)
+#undef SUDO_BIN
+#endif
#include <stdio.h>
#ifdef HAVE_STDLIB_H
@@ -134,15 +137,12 @@ static int display_disk_list(list_disk_t *list_disk, const int testdisk_mode,
if(list_disk==NULL)
{
printf("No disk detected.\n");
-#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(DJGPP)
-#else
-#ifdef HAVE_GETEUID
+#if defined(HAVE_GETEUID) && !defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(DJGPP)
if(geteuid()!=0)
{
printf("You need to be root to use TestDisk.\n");
}
#endif
-#endif
return 1;
}
@@ -202,7 +202,7 @@ int main( int argc, char **argv )
{
int i;
#ifdef SUDO_BIN
- int use_sudo=0;
+ int use_sudo;
#endif
int verbose=0, dump_ind=0;
int create_log=TD_LOG_NONE;
@@ -415,15 +415,12 @@ int main( int argc, char **argv )
#endif
log_info("ext2fs lib: %s, ntfs lib: %s, reiserfs lib: %s, ewf lib: %s, curses lib: %s\n",
td_ext2fs_version(), td_ntfs_version(), td_reiserfs_version(), td_ewf_version(), td_curses_version());
-#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(DJGPP)
-#else
-#ifdef HAVE_GETEUID
+#if defined(HAVE_GETEUID) && !defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(DJGPP)
if(geteuid()!=0)
{
log_warning("User is not root!\n");
}
#endif
-#endif
log_flush();
#ifdef HAVE_NCURSES
aff_copy(stdscr);
@@ -449,18 +446,14 @@ int main( int argc, char **argv )
hd_update_all_geometry(list_disk, verbose);
log_disk_list(list_disk);
#ifdef SUDO_BIN
- if(list_disk==NULL)
+ if(list_disk==NULL && geteuid()!=0)
{
-#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(DJGPP)
-#else
-#ifdef HAVE_GETEUID
- if(geteuid()!=0)
- use_sudo=2;
-#endif
-#endif
+ use_sudo=2;
}
- if(use_sudo==0)
+ else
+ {
use_sudo=do_curses_testdisk(verbose,dump_ind,list_disk,saveheader,cmd_device,&cmd_run);
+ }
#else
do_curses_testdisk(verbose,dump_ind,list_disk,saveheader,cmd_device,&cmd_run);
#endif