summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2008-03-09 14:10:58 +0100
committerChristophe Grenier <grenier@cgsecurity.org>2008-03-09 14:10:58 +0100
commit67aed3e03dd9f594be5d865365ca4ce313e34b27 (patch)
tree9938daa9e11f3ec1131d49bf940db72faa4bfa18 /src
parente533688f8f4c003729cf5661c2a43e91e953f514 (diff)
Add /cmd device ...,list,recursive support
Diffstat (limited to 'src')
-rw-r--r--src/dir.c51
-rw-r--r--src/dir.h1
-rw-r--r--src/dirpart.c10
3 files changed, 60 insertions, 2 deletions
diff --git a/src/dir.c b/src/dir.c
index b8950e2..b80e790 100644
--- a/src/dir.c
+++ b/src/dir.c
@@ -497,6 +497,7 @@ static int dir_partition_aux(disk_t *disk_car, const partition_t *partition, dir
#define MAX_DIR_NBR 256
static unsigned int dir_nbr=0;
static unsigned long int inode_known[MAX_DIR_NBR];
+ const unsigned int current_directory_namelength=strlen(dir_data->current_directory);
if(dir_nbr==MAX_DIR_NBR)
return 1; /* subdirectories depth is too high => Back */
if(dir_data->verbose>0)
@@ -512,13 +513,12 @@ static int dir_partition_aux(disk_t *disk_car, const partition_t *partition, dir
inode_known[dir_nbr++]=inode;
while(1)
{
- unsigned int current_directory_namelength=strlen(dir_data->current_directory);
unsigned int new_inode_ok=1;
unsigned int i;
#ifdef HAVE_NCURSES
new_inode=dir_aff_ncurses(disk_car,partition,dir_data,dir_list,inode,first_time);
#endif
- if(new_inode<0 || new_inode==1) /* Quit or Back */
+ if(new_inode<=1) /* Quit or Back */
{
delete_list_file(dir_list);
dir_nbr--;
@@ -541,6 +541,53 @@ static int dir_partition_aux(disk_t *disk_car, const partition_t *partition, dir
}
}
+int dir_whole_partition_log(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const unsigned long int inode)
+{
+ file_data_t *dir_list;
+ file_data_t *current_file;
+#define MAX_DIR_NBR 256
+ static unsigned int dir_nbr=0;
+ static unsigned long int inode_known[MAX_DIR_NBR];
+ const unsigned int current_directory_namelength=strlen(dir_data->current_directory);
+ if(dir_nbr==MAX_DIR_NBR)
+ return 1; /* subdirectories depth is too high => Back */
+ if(dir_data->verbose>0)
+ log_info("\ndir_partition inode=%lu\n",inode);
+ dir_list=dir_data->get_dir(disk_car,partition,dir_data,inode);
+ dir_aff_log(disk_car, partition, dir_data, dir_list);
+ /* Not perfect for FAT32 root cluster */
+ inode_known[dir_nbr++]=inode;
+ for(current_file=dir_list;current_file!=NULL;current_file=current_file->next)
+ {
+ if(LINUX_S_ISDIR(current_file->filestat.st_mode)!=0)
+ {
+ const unsigned long int new_inode=current_file->filestat.st_ino;
+ unsigned int new_inode_ok=1;
+ unsigned int i;
+ if(new_inode<2)
+ new_inode_ok=0;
+ for(i=0;i<dir_nbr && new_inode_ok!=0;i++)
+ if(new_inode==inode_known[i]) /* Avoid loop */
+ new_inode_ok=0;
+ if(new_inode_ok>0)
+ {
+ if(strlen(dir_data->current_directory)+1+strlen(current_file->name)<sizeof(dir_data->current_directory)-1)
+ {
+ if(strcmp(dir_data->current_directory,"/"))
+ strcat(dir_data->current_directory,"/");
+ strcat(dir_data->current_directory,current_file->name);
+ dir_whole_partition_log(disk_car, partition, dir_data, new_inode);
+ /* restore current_directory name */
+ dir_data->current_directory[current_directory_namelength]='\0';
+ }
+ }
+ }
+ }
+ delete_list_file(dir_list);
+ dir_nbr--;
+ return 0;
+}
+
/*
Returns
-2: no file copied
diff --git a/src/dir.h b/src/dir.h
index 0f13b3f..655d2a2 100644
--- a/src/dir.h
+++ b/src/dir.h
@@ -60,6 +60,7 @@ struct file_data
int dir_aff_log(const disk_t *disk_car, const partition_t *partition, const dir_data_t *dir_data, const file_data_t*dir_list);
void delete_list_file(file_data_t *file_list);
int dir_partition_aff(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const unsigned long int inode, char **current_cmd);
+int dir_whole_partition_log(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const unsigned long int inode);
void mode_string (const unsigned int mode, char *str);
FILE *create_file(const char *filename);
int set_date(const char *pathname, time_t actime, time_t modtime);
diff --git a/src/dirpart.c b/src/dirpart.c
index 05ef717..8a79154 100644
--- a/src/dirpart.c
+++ b/src/dirpart.c
@@ -144,6 +144,16 @@ int dir_partition(disk_t *disk_car, const partition_t *partition, const int verb
}
break;
default:
+ if(*current_cmd!=NULL)
+ {
+ while(*current_cmd[0]==',')
+ (*current_cmd)++;
+ if(strncmp(*current_cmd,"recursive",9)==0)
+ {
+ (*current_cmd)+=9;
+ dir_whole_partition_log(disk_car,partition,&dir_data,dir_data.current_inode);
+ }
+ }
dir_partition_aff(disk_car,partition,&dir_data,dir_data.current_inode,current_cmd);
dir_data.close(&dir_data);
break;