Cleanup code using SUDO_BIN

This commit is contained in:
Christophe Grenier 2020-03-20 16:57:57 +01:00
parent 5934cf54e9
commit 0fea045597
6 changed files with 41 additions and 45 deletions

View file

@ -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);
@ -77,7 +80,6 @@ int intrf_no_disk_ncurses(const char *prog_name)
}
#endif
}
#endif
#endif
wmove(stdscr,22,0);
wattrset(stdscr, A_REVERSE);

View file

@ -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())
@ -141,8 +142,6 @@ static int photorec_disk_selection_ncurses(struct ph_param *params, struct ph_op
use_sudo=1;
#endif
}
#endif
#endif
#endif
wmove(stdscr, INTER_NOTE_Y+1, 0);
wprintw(stdscr,"Disk capacity must be correctly detected for a successful recovery.");

View file

@ -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,14 +353,11 @@ 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();
@ -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

View file

@ -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>

View file

@ -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())
@ -128,7 +129,6 @@ static int testdisk_disk_selection_ncurses(int verbose,int dump_ind, const list_
use_sudo=1;
#endif
}
#endif
#endif
waddstr(stdscr,"Disk capacity must be correctly detected for a successful recovery.");
wmove(stdscr,line++,0);

View file

@ -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,14 +137,11 @@ 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,14 +415,11 @@ 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
@ -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