1 /*
2 
3     File: dir.h
4 
5     Copyright (C) 2004-2008 Christophe GRENIER <grenier@cgsecurity.org>
6 
7     This software is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation; either version 2 of the License, or
10     (at your option) any later version.
11 
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16 
17     You should have received a copy of the GNU General Public License along
18     with this program; if not, write the Free Software Foundation, Inc., 51
19     Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 
21  */
22 #ifndef _DIR_H
23 #define _DIR_H
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 #ifdef HAVE_SYS_STAT_H
28 #include <sys/stat.h>
29 #endif
30 #include "list.h"
31 #define DIR_NAME_LEN 1024
32 #define FLAG_LIST_DELETED	1
33 #define FLAG_LIST_MASK12	2
34 #define FLAG_LIST_MASK16	4
35 #define FLAG_LIST_PATHNAME	8
36 #define FLAG_LIST_ADS		16
37 #define FLAG_LIST_SYSTEM	32
38 /* capabilities */
39 #define CAPA_LIST_DELETED	1
40 #define CAPA_LIST_ADS		2
41 
42 typedef enum { DIR_PART_ENOIMP=-3, DIR_PART_ENOSYS=-2, DIR_PART_EIO=-1, DIR_PART_OK=0} dir_partition_t;
43 typedef struct dir_data dir_data_t;
44 typedef struct
45 {
46   struct td_list_head list;
47   char *name;
48   uint32_t st_ino;
49   uint32_t st_mode;
50   uint32_t st_uid;
51   uint32_t st_gid;
52   uint64_t st_size;
53   time_t    td_atime;   /* time of last access */
54   time_t    td_mtime;   /* time of last modification */
55   time_t    td_ctime;   /* time of last status change */
56   unsigned int status;
57 } file_info_t;
58 
59 struct dir_data
60 {
61   void *display;
62   char current_directory[DIR_NAME_LEN];
63   unsigned long int current_inode;
64   int verbose;
65   unsigned int param;
66   unsigned int capabilities;
67   int(*get_dir)(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const unsigned long int first_inode, file_info_t*list);
68   int (*copy_file)(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const file_info_t *file);
69   void (*close)(dir_data_t *dir_data);
70   char *local_dir;
71   void *private_dir_data;
72 };
73 
74 #define	FILE_STATUS_DELETED	1
75 #define	FILE_STATUS_MARKED	2
76 #define	FILE_STATUS_ADS		4
77 
78 int set_datestr(char *datestr, size_t n, const time_t timev);
79 int dir_aff_log(const dir_data_t *dir_data, const file_info_t*dir_list);
80 void log_list_file(const disk_t *disk_car, const partition_t *partition, const dir_data_t *dir_data, const file_info_t*list);
81 unsigned int delete_list_file(file_info_t *list);
82 int dir_whole_partition_log(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const unsigned long int inode);
83 void dir_whole_partition_copy(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const unsigned long int inode);
84 void mode_string (const unsigned int mode, char *str);
85 int set_mode(const char *pathname, unsigned int mode);
86 FILE *fopen_local(char **localfilename, const char *localroot, const char *filename);
87 char *gen_local_filename(const char *filename);
88 char *mkdir_local(const char *localroot, const char *pathname);
89 void mkdir_local_for_file(const char *filename);
90 
91 #define LINUX_S_IFMT  00170000
92 #define LINUX_S_IFSOCK 0140000
93 #define LINUX_S_IFLNK    0120000
94 #define LINUX_S_IFREG  0100000
95 #define LINUX_S_IFBLK  0060000
96 #define LINUX_S_IFDIR  0040000
97 #define LINUX_S_IFCHR  0020000
98 #define LINUX_S_IFIFO  0010000
99 #define LINUX_S_ISUID  0004000
100 #define LINUX_S_ISGID  0002000
101 #define LINUX_S_ISVTX  0001000
102 
103 
104 #define LINUX_S_IRWXU 00700
105 #define LINUX_S_IRUSR 00400
106 #define LINUX_S_IWUSR 00200
107 #define LINUX_S_IXUSR 00100
108 
109 #define LINUX_S_IRWXG 00070
110 #define LINUX_S_IRGRP 00040
111 #define LINUX_S_IWGRP 00020
112 #define LINUX_S_IXGRP 00010
113 
114 #define LINUX_S_IRWXO 00007
115 #define LINUX_S_IROTH 00004
116 #define LINUX_S_IWOTH 00002
117 #define LINUX_S_IXOTH 00001
118 
119 #define LINUX_S_IRWXUGO       (LINUX_S_IRWXU|LINUX_S_IRWXG|LINUX_S_IRWXO)
120 #define LINUX_S_IALLUGO       (LINUX_S_ISUID|LINUX_S_ISGID|LINUX_S_ISVTX|LINUX_S_IRWXUGO)
121 #define LINUX_S_IRUGO         (LINUX_S_IRUSR|LINUX_S_IRGRP|LINUX_S_IROTH)
122 #define LINUX_S_IWUGO         (LINUX_S_IWUSR|LINUX_S_IWGRP|LINUX_S_IWOTH)
123 #define LINUX_S_IXUGO         (LINUX_S_IXUSR|LINUX_S_IXGRP|LINUX_S_IXOTH)
124 
125 #define LINUX_S_ISLNK(m)        (((m) & LINUX_S_IFMT) == LINUX_S_IFLNK)
126 #define LINUX_S_ISREG(m)        (((m) & LINUX_S_IFMT) == LINUX_S_IFREG)
127 #define LINUX_S_ISDIR(m)        (((m) & LINUX_S_IFMT) == LINUX_S_IFDIR)
128 #define LINUX_S_ISCHR(m)        (((m) & LINUX_S_IFMT) == LINUX_S_IFCHR)
129 #define LINUX_S_ISBLK(m)        (((m) & LINUX_S_IFMT) == LINUX_S_IFBLK)
130 #define LINUX_S_ISFIFO(m)       (((m) & LINUX_S_IFMT) == LINUX_S_IFIFO)
131 #define LINUX_S_ISSOCK(m)       (((m) & LINUX_S_IFMT) == LINUX_S_IFSOCK)
132 
133 int filesort(const struct td_list_head *a, const struct td_list_head *b);
134 #ifdef __cplusplus
135 } /* closing brace for extern "C" */
136 #endif
137 #endif
138