summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tools/libltgrey.c20
-rw-r--r--tools/ltgrey.c12
2 files changed, 25 insertions, 7 deletions
diff --git a/tools/libltgrey.c b/tools/libltgrey.c
index 7104c69..9b02642 100644
--- a/tools/libltgrey.c
+++ b/tools/libltgrey.c
@@ -126,28 +126,36 @@ void whatsit::update(const string msg, const timeval new_mod,
}
#endif
-int whatsit::maybe_mkdir(const string somedir, const string msg){
+int whatsit::maybe_mkdir(const string subdir, const string msg){
// see if our directory exists:
+ string mydir = parent_dir;
+ if (subdir != ".") {
+ mydir += "/" + subdir;
+ }
struct stat dirstat;
- int rslt = stat(somedir.c_str(), &dirstat);
+ int rslt = stat(mydir.c_str(), &dirstat);
if (rslt != 0){
if (errno != ENOENT) {
cerr << progid << " stat failed for "
<< msg
- << " '" << somedir << "' : ";
+ << " '" << mydir << "' : ";
perror(0);
+ return(ex_syserr);
}
- rslt = mkdir(somedir.c_str(), 0755);
+ /* else it simply does not exist */
+ rslt = mkdir(mydir.c_str(), 0755);
if (rslt != 0) {
cerr << progid
- << "uid " << getuid()
+ << " uid " << getuid()
+ << " euid " << geteuid()
<< " mkdir failed for "
<< msg
- << "' " << somedir << "' : ";
+ << " '" << mydir << "' : ";
perror(0);
return(ex_syserr);
}
}
+ // here if stat succeeded
return 0;
}
diff --git a/tools/ltgrey.c b/tools/ltgrey.c
index bc41a99..ee6b4e5 100644
--- a/tools/ltgrey.c
+++ b/tools/ltgrey.c
@@ -18,6 +18,17 @@ int main(int _argc, char** _argv){
char** argv(_argv);
const string parent_dir("/var/qmail/ltgrey");
whatsit foo(argv[0], parent_dir); argc--; argv++;
+
+ if (foo.setup()) return ex_syserr;
+
+ int rslt;
+ rslt = foo.maybe_mkdir(".", "parent dir");
+ if (rslt) return rslt;
+ rslt = foo.maybe_mkdir(box_40.dir, "quarantine dir");
+ if (rslt) return rslt;
+ rslt = foo.maybe_mkdir(box_rep.dir, "reputation dir");
+ if (rslt) return rslt;
+
int scan40mode(0);
int scanrepmode(0);
int copies(1);
@@ -89,7 +100,6 @@ int main(int _argc, char** _argv){
exeunt(ex_syserr);
}
}
- if (foo.setup()) return ex_syserr;
// dns_mode mode ...
// Probably it would be better to make more thorough DNS checks.