diff --git a/src/config.h b/src/config.h index ad89f328..a7c82ce2 100644 --- a/src/config.h +++ b/src/config.h @@ -14,7 +14,7 @@ #define VERSION "1.1.1-pre" -#define BUILD 889 +#define BUILD 890 #define HOSTID "mailarchiver" diff --git a/src/misc.c b/src/misc.c index b6a1f392..14fcdf00 100644 --- a/src/misc.c +++ b/src/misc.c @@ -560,6 +560,24 @@ void *get_in_addr(struct sockaddr *sa){ } +int can_i_write_current_directory(){ + int fd; + char filename[SMALLBUFSIZE]; + + snprintf(filename, sizeof(filename)-1, "__piler_%d", getpid()); + + fd = open(filename, O_CREAT|O_RDWR, S_IRUSR|S_IWUSR|S_IRGRP); + if(fd == -1){ + return 0; + } + + close(fd); + unlink(filename); + + return 1; +} + + #ifndef _GNU_SOURCE char *strcasestr(const char *s, const char *find){ char c, sc; diff --git a/src/misc.h b/src/misc.h index 27f41c93..6643c27b 100644 --- a/src/misc.h +++ b/src/misc.h @@ -42,6 +42,8 @@ void strtolower(char *s); void *get_in_addr(struct sockaddr *sa); +int can_i_write_current_directory(); + #ifndef _GNU_SOURCE char *strcasestr(const char *s, const char *find); #endif diff --git a/src/pilerexport.c b/src/pilerexport.c index 407a477e..de997459 100644 --- a/src/pilerexport.c +++ b/src/pilerexport.c @@ -351,6 +351,8 @@ int main(int argc, char **argv){ regfree(®exp); + if(!can_i_write_current_directory()) __fatal("cannot write current directory!"); + (void) openlog("pilerexport", LOG_PID, LOG_MAIL); if(exportall == 1){ diff --git a/src/pilerimport.c b/src/pilerimport.c index 0e8ec802..cb7d9a83 100644 --- a/src/pilerimport.c +++ b/src/pilerimport.c @@ -647,6 +647,8 @@ int main(int argc, char **argv){ if(!mbox[0] && !mboxdir && !emlfile && !directory && !imapserver && !pop3server && import_from_gui == 0) usage(); + if(!can_i_write_current_directory()) __fatal("cannot write current directory!"); + cfg = read_config(configfile); /* make sure we don't discard messages without a valid Message-Id when importing manually */ diff --git a/src/reindex.c b/src/reindex.c index 956b93b0..1c183275 100644 --- a/src/reindex.c +++ b/src/reindex.c @@ -205,6 +205,7 @@ int main(int argc, char **argv){ if(all == 0 && (from_id <= 0 || to_id <= 0) ) usage(); + if(!can_i_write_current_directory()) __fatal("cannot write current directory!"); (void) openlog("reindex", LOG_PID, LOG_MAIL); diff --git a/src/test.c b/src/test.c index f2170205..1d70ba3c 100644 --- a/src/test.c +++ b/src/test.c @@ -32,6 +32,8 @@ int main(int argc, char **argv){ exit(1); } + if(!can_i_write_current_directory()) __fatal("cannot write current directory!"); + if(stat(argv[1], &st) != 0){ fprintf(stderr, "%s is not found\n", argv[1]); return 0;