directory write ability check for some piler binaries

This commit is contained in:
SJ 2014-10-02 10:02:33 +02:00
parent c8a4c3c358
commit d26b3a7e74
7 changed files with 28 additions and 1 deletions

View File

@ -14,7 +14,7 @@
#define VERSION "1.1.1-pre" #define VERSION "1.1.1-pre"
#define BUILD 889 #define BUILD 890
#define HOSTID "mailarchiver" #define HOSTID "mailarchiver"

View File

@ -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 #ifndef _GNU_SOURCE
char *strcasestr(const char *s, const char *find){ char *strcasestr(const char *s, const char *find){
char c, sc; char c, sc;

View File

@ -42,6 +42,8 @@ void strtolower(char *s);
void *get_in_addr(struct sockaddr *sa); void *get_in_addr(struct sockaddr *sa);
int can_i_write_current_directory();
#ifndef _GNU_SOURCE #ifndef _GNU_SOURCE
char *strcasestr(const char *s, const char *find); char *strcasestr(const char *s, const char *find);
#endif #endif

View File

@ -351,6 +351,8 @@ int main(int argc, char **argv){
regfree(&regexp); regfree(&regexp);
if(!can_i_write_current_directory()) __fatal("cannot write current directory!");
(void) openlog("pilerexport", LOG_PID, LOG_MAIL); (void) openlog("pilerexport", LOG_PID, LOG_MAIL);
if(exportall == 1){ if(exportall == 1){

View File

@ -647,6 +647,8 @@ int main(int argc, char **argv){
if(!mbox[0] && !mboxdir && !emlfile && !directory && !imapserver && !pop3server && import_from_gui == 0) usage(); 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); cfg = read_config(configfile);
/* make sure we don't discard messages without a valid Message-Id when importing manually */ /* make sure we don't discard messages without a valid Message-Id when importing manually */

View File

@ -205,6 +205,7 @@ int main(int argc, char **argv){
if(all == 0 && (from_id <= 0 || to_id <= 0) ) usage(); 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); (void) openlog("reindex", LOG_PID, LOG_MAIL);

View File

@ -32,6 +32,8 @@ int main(int argc, char **argv){
exit(1); exit(1);
} }
if(!can_i_write_current_directory()) __fatal("cannot write current directory!");
if(stat(argv[1], &st) != 0){ if(stat(argv[1], &st) != 0){
fprintf(stderr, "%s is not found\n", argv[1]); fprintf(stderr, "%s is not found\n", argv[1]);
return 0; return 0;