summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2007-11-28 22:42:36 +0100
committerChristophe Grenier <grenier@cgsecurity.org>2007-11-28 22:42:36 +0100
commit66c34423c10b576b7e91d6b218a962ee6c5143d6 (patch)
tree2502e46d83cdaa2bd4d24a7c2cbd4f3e85ba6d5a
parent22ed9d7d0fc0b571aee5e692467ed90034feab6f (diff)
Can use sudo if user is not root
-rwxr-xr-xcompile.sh18
-rw-r--r--configure.ac31
-rw-r--r--src/Makefile.am5
-rw-r--r--src/intrf.c30
-rw-r--r--src/intrf.h2
-rw-r--r--src/intrface.c6
-rw-r--r--src/photorec.c7
-rw-r--r--src/phrecn.c6
-rw-r--r--src/phrecn.h2
-rw-r--r--src/testdisk.c7
10 files changed, 79 insertions, 35 deletions
diff --git a/compile.sh b/compile.sh
index 0781b4e..4ccfdb2 100755
--- a/compile.sh
+++ b/compile.sh
@@ -216,13 +216,21 @@ then
if [ ! -e $compiledir/Makefile ];
then
cd $compiledir
- if [ "X$crosscompile_target" = 'Xpowerpc-apple-darwin' ];
- then
+ case "$crosscompile_target" in
+ powerpc-apple-darwin)
# libewf should work under MacOSX but it hasn't been tested
- $confdir/configure --host=$crosscompile_target --prefix=$prefix $CONFIGUREOPT --without-ewf
- else
+ $confdir/configure --host=$crosscompile_target --prefix=$prefix $CONFIGUREOPT --without-ewf --enable-sudo --with-sudo-bin=/usr/bin/sudo
+ ;;
+ i586-pc-msdosdjgpp)
+ $confdir/configure --host=$crosscompile_target --prefix=$prefix $CONFIGUREOPT --without-ewf --without-iconv
+ ;;
+ i386-pc-cygwin)
+ $confdir/configure --host=$crosscompile_target --prefix=$prefix $CONFIGUREOPT --without-iconv
+ ;;
+ *)
$confdir/configure --host=$crosscompile_target --prefix=$prefix $CONFIGUREOPT
- fi
+ ;;
+ esac
cd $pwd_saved
fi
if [ -e $compiledir/Makefile ];
diff --git a/configure.ac b/configure.ac
index 289dc47..fe77928 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3,7 +3,7 @@
AC_PREREQ(2.59)
AC_INIT([testdisk],[6.9-WIP],[grenier@cgsecurity.org])
-TESTDISKDATE="October 2007"
+TESTDISKDATE="November 2007"
AC_SUBST(TESTDISKDATE)
AC_DEFINE_UNQUOTED([TESTDISKDATE],"$TESTDISKDATE",[Date of release])
AC_CONFIG_AUX_DIR(config)
@@ -139,6 +139,15 @@ AC_ARG_WITH(giconv-includes,
AS_HELP_STRING(--with-giconv-includes=DIR,location of the giconv includes files),
[CPPFLAGS="${CPPFLAGS} -I${withval}"])
+AC_ARG_ENABLE([sudo],
+ AS_HELP_STRING(--enable-sudo,enable use of sudo (default is NO)),
+ [ use_sudo="yes" ],
+ [ use_sudo="no" ])
+
+AC_ARG_WITH(sudo-bin,
+ AS_HELP_STRING(--with-sudo-bin=PROG,location of the sudo binary),
+ [SUDO_BIN="${withval}"])
+
use_icon=no
case "$target" in
@@ -470,18 +479,26 @@ case "$target" in
;;
esac
-AC_CHECK_FUNCS([atexit atoll chdir delscreen dirname dup2 ftruncate getcwd geteuid lstat memset mkdir posix_fadvise posix_memalign pwrite readlink setenv setlocale signal snprintf strchr strdup strerror strncasecmp strtol touchwin utime vsnprintf])
-if test $ac_cv_func_mkdir = no; then
+AC_CHECK_FUNCS([atexit atoll chdir delscreen dirname dup2 execv ftruncate getcwd geteuid lstat memset mkdir posix_fadvise posix_memalign pwrite readlink setenv setlocale signal snprintf strchr strdup strerror strncasecmp strtol touchwin utime vsnprintf])
+if test "$ac_cv_func_mkdir" = "no"; then
AC_MSG_ERROR(No mkdir function detected)
fi
+
+if test "$ac_cv_func_execv" = "yes" -a "$use_sudo" = "yes";
+then
+ if test -z "$SUDO_BIN"; then
+ AC_PATH_PROG([SUDO], [sudo], [AC_MSG_ERROR([sudo requested but not found])])
+ SUDO_BIN="$SUDO"
+ fi
+ AC_DEFINE_UNQUOTED([SUDO_BIN], "$SUDO_BIN", [Path to sudo for privileged operations])
+fi
+
#reiserfs_fs_open_fast may not been detected because of lack of -ldal
OLDLIBS="$LIBS"
-LIBS="$LIBS $testdisk_LDADD -ldal"
+LIBS="$OLDLIBS $testdisk_LDADD -ldal"
AC_CHECK_FUNCS([reiserfs_fs_open_fast])
-LIBS="$LIBS $testdisk_LDADD"
-AC_CHECK_FUNCS([ntfs_libntfs_version ntfs_volume_startup])
LIBS="$OLDLIBS"
-
+AC_CHECK_FUNCS([ntfs_libntfs_version ntfs_volume_startup])
AC_SUBST(CFLAGS)
AC_SUBST(CPPFLAGS)
diff --git a/src/Makefile.am b/src/Makefile.am
index a0dba08..1d2fcf2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -10,8 +10,8 @@ endif
sbin_PROGRAMS = testdisk photorec
#diskcp
-base_C = common.c crc.c ewf.c fnctdsk.c hdaccess.c hdcache.c intrf.c log.c parti386.c partgpt.c partmac.c partsun.c partnone.c partxbox.c chgtype.c io_redir.c ntfs_io.c ntfs_utl.c partauto.c unicode.c
-base_H = common.h crc.h ewf.h fnctdsk.h hdaccess.h guid_cmp.h guid_cpy.h hdcache.h intrf.h intrfn.h lang.h log.h types.h chgtype.h io_redir.h ntfs_utl.h partgpt.h partmac.h partnone.h partxbox.h partauto.h unicode.h
+base_C = common.c crc.c ewf.c fnctdsk.c hdaccess.c hdcache.c intrf.c log.c parti386.c partgpt.c partmac.c partsun.c partnone.c partxbox.c chgtype.c io_redir.c ntfs_io.c ntfs_utl.c partauto.c sudo.c unicode.c
+base_H = common.h crc.h ewf.h fnctdsk.h hdaccess.h guid_cmp.h guid_cpy.h hdcache.h intrf.h intrfn.h lang.h log.h types.h chgtype.h io_redir.h ntfs_utl.h partgpt.h partmac.h partnone.h partxbox.h partauto.h sudo.h unicode.h
fs_C = analyse.c bfs.c bsd.c cramfs.c fat.c fatx.c ext2.c jfs.c hfs.c hfsp.c luks.c lvm.c md.c netware.c ntfs.c rfs.c savehdr.c sun.c swap.c sysv.c ufs.c xfs.c
fs_H = analyse.h bfs.h bsd.h cramfs.h fat.h fatx.h ext2.h jfs_superblock.h jfs.h hfs.h hfsp.h luks.h lvm.h md.h netware.h ntfs.h rfs.h savehdr.h sun.h swap.h sysv.h ufs.h xfs.h
@@ -19,7 +19,6 @@ fs_H = analyse.h bfs.h bsd.h cramfs.h fat.h fatx.h ext2.h jfs_superblock.h jfs
testdisk_SOURCES = testdisk.c $(base_C) $(base_H) $(fs_C) $(fs_H) testdisk.h adv.c adv.h dir.c dir.h dirpart.c dirpart.h edit.c edit.h ext2_dir.c ext2_dir.h ext2_inc.h fat_adv.c fat_dir.c fat_dir.h geometry.c godmode.c godmode.h intrface.c intrface.h ntfs_adv.c ntfs_dir.c ntfs_dir.h ntfs_fix.c ntfs_inc.h rfs_dir.c rfs_dir.h $(ICON_TESTDISK) next.c next.h
#ntfs_udl.c ntfs_udl.h
-
photorec_SOURCES = photorec.c photorec.h phrecn.c phrecn.h dir.c dir.h ext2p.c ext2p.h ext2_dir.c ext2_dir.h ext2_inc.h fat_dir.c fat_dir.h fatp.c fatp.h filegen.c filegen.h file_7z.c file_a.c file_ab.c file_ace.c file_aif.c file_all.c file_asf.c file_au.c file_bkf.c file_bld.c file_bmp.c file_bz2.c file_cab.c file_cam.c file_cm.c file_crw.c file_ctg.c file_cwk.c file_dat.c file_dbf.c file_dir.c file_djv.c file_doc.c file_dpx.c file_dsc.c file_dta.c file_dv.c file_dwg.c file_elf.c file_evt.c file_exe.c pe.h file_ext.c file_fh10.c file_fh5.c file_flac.c file_flv.c file_fs.c file_gif.c file_gz.c file_imb.c file_indd.c file_dump.c file_itu.c file_jpg.c file_jpg.h file_kdb.c file_max.c file_mdb.c file_mdf.c file_mid.c file_mkv.c file_mov.c file_mp3.c file_mpg.c file_mrw.c file_mus.c file_mysql.c file_njx.c file_ogg.c file_orf.c file_pap.c file_pcx.c file_pdf.c file_png.c file_prc.c file_ps.c file_psd.c file_pst.c file_ptb.c file_qbb.c file_qdf.c file_qxd.c file_ra.c file_raf.c file_rar.c file_raw.c file_rdc.c file_reg.c file_riff.c file_rm.c file_rns.c file_rpm.c file_sit.c file_skp.c file_spe.c file_spss.c file_stu.c file_swf.c file_tar.c file_tib.c file_tiff.c file_txt.c file_vmdk.c file_wpd.c file_wmf.c file_x3f.c file_xcf.c file_xm.c file_zip.c geometry.c list.c list.h ole.h ntfs_dir.c ntfs_dir.h ntfsp.c ntfsp.h ntfs_inc.h sessionp.c sessionp.h $(base_C) $(base_H) $(fs_C) $(fs_H) $(ICON_PHOTOREC)
#diskcp_SOURCES = diskcp.c types.h
diff --git a/src/intrf.c b/src/intrf.c
index 5a3316b..fe8da3a 100644
--- a/src/intrf.c
+++ b/src/intrf.c
@@ -1326,7 +1326,6 @@ char *ask_log_location(const char*filename)
*/
int ask_log_creation()
{
- int command;
unsigned int menu=0;
static struct MenuItem menuLogCreation[]=
{
@@ -1364,6 +1363,7 @@ int ask_log_creation()
wprintw(stdscr,"Use arrow keys to select, then press Enter key:");
while(1)
{
+ int command;
command = wmenuSelect_ext(stdscr,17, 0, menuLogCreation, 8,
"CAQ", MENU_VERT | MENU_VERT_WARN | MENU_BUTTON, &menu,NULL);
switch(command)
@@ -1383,7 +1383,7 @@ int ask_log_creation()
}
}
-static void intrf_no_disk_ncurses(const char *prog_name)
+static int intrf_no_disk_ncurses(const char *prog_name)
{
aff_copy(stdscr);
wmove(stdscr,4,0);
@@ -1399,26 +1399,37 @@ static void intrf_no_disk_ncurses(const char *prog_name)
wprintw(stdscr,"Under Win9x, use the DOS version instead.\n");
wmove(stdscr,10,0);
wprintw(stdscr,"Under Vista, select %s, right-click and choose \"Run as administrator\".\n", prog_name);
+#elif defined(DJGPP)
#else
-#ifndef DJGPP
#ifdef HAVE_GETEUID
if(geteuid()!=0)
{
+ static const struct MenuItem menuSudo[]=
+ {
+ {'S',"Sudo","Use the sudo command to restart as root"},
+ {'Q',"Quit",""},
+ {0,NULL,NULL}
+ };
+ unsigned int menu=0;
+ int command;
wprintw(stdscr,"You need to be root to use %s.\n", prog_name);
-#if defined(__APPLE__)
- wmove(stdscr,9,0);
- wprintw(stdscr,"Use the sudo command to launch %s.\n", prog_name);
+#ifdef SUDO_BIN
+ command = wmenuSelect_ext(stdscr,21, 0, menuSudo, 8,
+ "SQ", MENU_VERT | MENU_VERT_WARN | MENU_BUTTON, &menu,NULL);
+ if(command=='s' || command=='S')
+ return 1;
+ return 0;
#endif
}
#endif
#endif
-#endif
wmove(stdscr,22,0);
wattrset(stdscr, A_REVERSE);
wprintw(stdscr,"[ Quit ]");
wattroff(stdscr, A_REVERSE);
wrefresh(stdscr);
while(wgetch(stdscr)==ERR);
+ return 0;
}
int check_enter_key_or_s(WINDOW *window)
@@ -1995,13 +2006,14 @@ int display_message(const char*msg)
#endif
}
-void intrf_no_disk(const char *prog_name)
+int intrf_no_disk(const char *prog_name)
{
log_critical("No disk found\n");
#ifdef HAVE_NCURSES
- intrf_no_disk_ncurses(prog_name);
+ return intrf_no_disk_ncurses(prog_name);
#else
printf("No disk found\n");
+ return 0;
#endif
}
diff --git a/src/intrf.h b/src/intrf.h
index f0ffd51..553823b 100644
--- a/src/intrf.h
+++ b/src/intrf.h
@@ -92,7 +92,7 @@ int get_string(char *str, int len, char *def);
void not_implemented(const char *msg);
void screen_buffer_to_log(void);
int interface_partition_type(disk_t *disk_car, const int verbose, char**current_cmd);
-void intrf_no_disk(const char *prog_name);
+int intrf_no_disk(const char *prog_name);
char *ask_log_location(const char*filename);
int ask_log_creation(void);
char *ask_location(const char*msg, const char *src_dir);
diff --git a/src/intrface.c b/src/intrface.c
index 7c03c78..815eda7 100644
--- a/src/intrface.c
+++ b/src/intrface.c
@@ -417,8 +417,7 @@ static int testdisk_disk_selection_cli(int verbose,int dump_ind, const list_disk
current_disk=list_disk;
if(current_disk==NULL)
{
- intrf_no_disk("TestDisk");
- return 0;
+ return intrf_no_disk("TestDisk");
}
if(*current_cmd!=NULL)
{
@@ -458,8 +457,7 @@ static int testdisk_disk_selection_ncurses(int verbose,int dump_ind, const list_
current_disk=list_disk;
if(current_disk==NULL)
{
- intrf_no_disk("TestDisk");
- return 0;
+ return intrf_no_disk("TestDisk");
}
/* ncurses interface */
while(1)
diff --git a/src/photorec.c b/src/photorec.c
index ab851e7..ba4fe5f 100644
--- a/src/photorec.c
+++ b/src/photorec.c
@@ -735,6 +735,7 @@ alloc_data_t * update_blocksize(unsigned int blocksize, alloc_data_t *list_searc
int main( int argc, char **argv )
{
int i;
+ int use_sudo=0;
int help=0, create_log=0, verbose=0;
int run_setlocale=1;
int testdisk_mode=TESTDISK_O_RDONLY|TESTDISK_O_READAHEAD_32K;
@@ -1011,7 +1012,7 @@ int main( int argc, char **argv )
}
printf("\n");
log_info("\n");
- do_curses_photorec(verbose, recup_dir, list_disk, list_file_enable, cmd_device, &cmd_run);
+ use_sudo=do_curses_photorec(verbose, recup_dir, list_disk, list_file_enable, cmd_device, &cmd_run);
#ifdef HAVE_NCURSES
end_ncurses();
#endif
@@ -1025,6 +1026,10 @@ int main( int argc, char **argv )
{
printf("PhotoRec exited normally.\n");
}
+#ifdef SUDO_BIN
+ if(use_sudo>0)
+ run_sudo(argc, argv);
+#endif
return 0;
}
diff --git a/src/phrecn.c b/src/phrecn.c
index c4364d3..3be4bca 100644
--- a/src/phrecn.c
+++ b/src/phrecn.c
@@ -1807,7 +1807,7 @@ static void photorec_disk_selection_ncurses(int verbose, const char *recup_dir,
}
#endif
-void do_curses_photorec(int verbose, const char *recup_dir, const list_disk_t *list_disk, file_enable_t *file_enable, char *cmd_device, char **current_cmd)
+int do_curses_photorec(int verbose, const char *recup_dir, const list_disk_t *list_disk, file_enable_t *file_enable, char *cmd_device, char **current_cmd)
{
const list_disk_t *current_disk=list_disk;
static alloc_data_t list_search_space={
@@ -1842,8 +1842,7 @@ void do_curses_photorec(int verbose, const char *recup_dir, const list_disk_t *l
}
if(current_disk==NULL)
{
- intrf_no_disk("PhotoRec");
- return;
+ return intrf_no_disk("PhotoRec");
}
if(*current_cmd!=NULL)
{
@@ -1859,6 +1858,7 @@ void do_curses_photorec(int verbose, const char *recup_dir, const list_disk_t *l
#endif
}
log_info("\n");
+ return 0;
}
#ifdef HAVE_NCURSES
diff --git a/src/phrecn.h b/src/phrecn.h
index 1704e39..1a8e927 100644
--- a/src/phrecn.h
+++ b/src/phrecn.h
@@ -19,5 +19,5 @@
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-void do_curses_photorec(int verbose, const char *recup_dir, const list_disk_t *list_disk, file_enable_t *file_enable, char *cmd_device, char**cmd_run);
+int do_curses_photorec(int verbose, const char *recup_dir, const list_disk_t *list_disk, file_enable_t *file_enable, char *cmd_device, char**cmd_run);
diff --git a/src/testdisk.c b/src/testdisk.c
index 1f942c6..48ced13 100644
--- a/src/testdisk.c
+++ b/src/testdisk.c
@@ -91,6 +91,7 @@ void aff_copy(WINDOW *window)
int main( int argc, char **argv )
{
int i;
+ int use_sudo=0;
int help=0, verbose=0, dump_ind=0;
int create_log=0; /* 0: no_log, 1: append, 2 create */
int do_list=0;
@@ -315,7 +316,7 @@ int main( int argc, char **argv )
for(element_disk=list_disk;element_disk!=NULL;element_disk=element_disk->next)
log_info("%s, sector size=%u\n",element_disk->disk->description(element_disk->disk),element_disk->disk->sector_size);
log_info("\n");
- do_curses_testdisk(verbose,dump_ind,list_disk,saveheader,cmd_device,&cmd_run);
+ use_sudo=do_curses_testdisk(verbose,dump_ind,list_disk,saveheader,cmd_device,&cmd_run);
#ifdef HAVE_NCURSES
end_ncurses();
#endif
@@ -366,5 +367,9 @@ int main( int argc, char **argv )
{
printf("You have to reboot for the change to take effect.\n");
}
+#ifdef SUDO_BIN
+ if(use_sudo>0)
+ run_sudo(argc, argv);
+#endif
return 0;
}