git-svn: trunk@2017
Tomasz Kojm authored on 2006/06/09 05:00:50... | ... |
@@ -40,6 +40,7 @@ |
40 | 40 |
#include "defaults.h" |
41 | 41 |
#include "memory.h" |
42 | 42 |
#include "output.h" |
43 |
+#include "misc.h" |
|
43 | 44 |
|
44 | 45 |
int treewalk(const char *dirname, struct cl_node *root, const struct passwd *user, const struct optstruct *opt, const struct cl_limits *limits, int options, unsigned int depth) |
45 | 46 |
{ |
... | ... |
@@ -135,65 +136,6 @@ int treewalk(const char *dirname, struct cl_node *root, const struct passwd *use |
135 | 135 |
|
136 | 136 |
} |
137 | 137 |
|
138 |
-int rmdirs(const char *dirname) |
|
139 |
-{ |
|
140 |
- DIR *dd; |
|
141 |
- struct dirent *dent; |
|
142 |
- struct stat maind, statbuf; |
|
143 |
- char *fname; |
|
144 |
- |
|
145 |
- if((dd = opendir(dirname)) != NULL) { |
|
146 |
- while(stat(dirname, &maind) != -1) { |
|
147 |
- if(!rmdir(dirname)) break; |
|
148 |
- if(errno != ENOTEMPTY && errno != EEXIST && errno != EBADF) { |
|
149 |
- logg("^Can't remove temporary directory %s: %s\n", dirname, strerror(errno)); |
|
150 |
- closedir(dd); |
|
151 |
- return 0; |
|
152 |
- } |
|
153 |
- |
|
154 |
- while((dent = readdir(dd))) { |
|
155 |
-#ifndef C_INTERIX |
|
156 |
- if(dent->d_ino) |
|
157 |
-#endif |
|
158 |
- { |
|
159 |
- if(strcmp(dent->d_name, ".") && strcmp(dent->d_name, "..")) { |
|
160 |
- fname = mcalloc(strlen(dirname) + strlen(dent->d_name) + 2, sizeof(char)); |
|
161 |
- sprintf(fname, "%s/%s", dirname, dent->d_name); |
|
162 |
- |
|
163 |
- /* stat the file */ |
|
164 |
- if(lstat(fname, &statbuf) != -1) { |
|
165 |
- if(S_ISDIR(statbuf.st_mode) && !S_ISLNK(statbuf.st_mode)) { |
|
166 |
- if(rmdir(fname) == -1) { /* can't be deleted */ |
|
167 |
- if(errno == EACCES) { |
|
168 |
- logg("^Can't remove some temporary directories due to access problem.\n"); |
|
169 |
- closedir(dd); |
|
170 |
- return 0; |
|
171 |
- } |
|
172 |
- rmdirs(fname); |
|
173 |
- } |
|
174 |
- } else |
|
175 |
- unlink(fname); |
|
176 |
- } |
|
177 |
- |
|
178 |
- free(fname); |
|
179 |
- } |
|
180 |
- } |
|
181 |
- } |
|
182 |
- |
|
183 |
- rewinddir(dd); |
|
184 |
- |
|
185 |
- } |
|
186 |
- |
|
187 |
- } else { |
|
188 |
- if(!printinfected) |
|
189 |
- logg("%s: Can't open directory.\n", dirname); |
|
190 |
- return 53; |
|
191 |
- } |
|
192 |
- |
|
193 |
- closedir(dd); |
|
194 |
- return 0; |
|
195 |
-} |
|
196 |
- |
|
197 | 138 |
int clamav_rmdirs(const char *dir) |
198 | 139 |
{ |
199 | 140 |
#ifndef C_CYGWIN |
... | ... |
@@ -32,7 +32,6 @@ struct s_du { |
32 | 32 |
|
33 | 33 |
int treewalk(const char *dirname, struct cl_node *root, const struct passwd *user, const struct optstruct *opt, const struct cl_limits *limits, int options, unsigned int depth); |
34 | 34 |
|
35 |
-int rmdirs(const char *dirname); |
|
36 | 35 |
int clamav_rmdirs(const char *dir); |
37 | 36 |
int fixperms(const char *dirname); |
38 | 37 |
int du(const char *dirname, struct s_du *n); |
... | ... |
@@ -28,8 +28,10 @@ |
28 | 28 |
#include <time.h> |
29 | 29 |
#include <sys/types.h> |
30 | 30 |
#include <sys/stat.h> |
31 |
+#include <dirent.h> |
|
31 | 32 |
#include <fcntl.h> |
32 | 33 |
#include <ctype.h> |
34 |
+#include <errno.h> |
|
33 | 35 |
|
34 | 36 |
#include "clamav.h" |
35 | 37 |
#include "cfgparser.h" |
... | ... |
@@ -150,6 +152,62 @@ int filecopy(const char *src, const char *dest) |
150 | 150 |
|
151 | 151 |
} |
152 | 152 |
|
153 |
+int rmdirs(const char *dirname) |
|
154 |
+{ |
|
155 |
+ DIR *dd; |
|
156 |
+ struct dirent *dent; |
|
157 |
+ struct stat maind, statbuf; |
|
158 |
+ char *fname; |
|
159 |
+ |
|
160 |
+ |
|
161 |
+ if((dd = opendir(dirname)) != NULL) { |
|
162 |
+ while(stat(dirname, &maind) != -1) { |
|
163 |
+ if(!rmdir(dirname)) break; |
|
164 |
+ if(errno != ENOTEMPTY && errno != EEXIST && errno != EBADF) { |
|
165 |
+ closedir(dd); |
|
166 |
+ return 0; |
|
167 |
+ } |
|
168 |
+ |
|
169 |
+ while((dent = readdir(dd))) { |
|
170 |
+#ifndef C_INTERIX |
|
171 |
+ if(dent->d_ino) |
|
172 |
+#endif |
|
173 |
+ { |
|
174 |
+ if(strcmp(dent->d_name, ".") && strcmp(dent->d_name, "..")) { |
|
175 |
+ fname = mcalloc(strlen(dirname) + strlen(dent->d_name) + 2, sizeof(char)); |
|
176 |
+ sprintf(fname, "%s/%s", dirname, dent->d_name); |
|
177 |
+ |
|
178 |
+ /* stat the file */ |
|
179 |
+ if(lstat(fname, &statbuf) != -1) { |
|
180 |
+ if(S_ISDIR(statbuf.st_mode) && !S_ISLNK(statbuf.st_mode)) { |
|
181 |
+ if(rmdir(fname) == -1) { /* can't be deleted */ |
|
182 |
+ if(errno == EACCES) { |
|
183 |
+ closedir(dd); |
|
184 |
+ free(fname); |
|
185 |
+ return 0; |
|
186 |
+ } |
|
187 |
+ rmdirs(fname); |
|
188 |
+ } |
|
189 |
+ } else |
|
190 |
+ unlink(fname); |
|
191 |
+ } |
|
192 |
+ |
|
193 |
+ free(fname); |
|
194 |
+ } |
|
195 |
+ } |
|
196 |
+ } |
|
197 |
+ |
|
198 |
+ rewinddir(dd); |
|
199 |
+ } |
|
200 |
+ |
|
201 |
+ } else { |
|
202 |
+ return 1; |
|
203 |
+ } |
|
204 |
+ |
|
205 |
+ closedir(dd); |
|
206 |
+ return 0; |
|
207 |
+} |
|
208 |
+ |
|
153 | 209 |
int isnumb(const char *str) |
154 | 210 |
{ |
155 | 211 |
while(*str) { |