validate maildirs more strictly

now that "SyncState *" won't create fake mailboxes any more, we can make
a full validity check again.
This commit is contained in:
Oswald Buddenhagen 2011-07-24 20:26:10 +02:00
parent 05fd0b9970
commit 3169c59e10

View File

@ -231,7 +231,7 @@ maildir_validate( const char *prefix, const char *box, int create, maildir_store
DIR *dirp; DIR *dirp;
struct dirent *entry; struct dirent *entry;
time_t now; time_t now;
int i, j, bl; int i, bl;
struct stat st; struct stat st;
char buf[_POSIX_PATH_MAX]; char buf[_POSIX_PATH_MAX];
@ -245,7 +245,6 @@ maildir_validate( const char *prefix, const char *box, int create, maildir_store
maildir_invoke_bad_callback( &ctx->gen ); maildir_invoke_bad_callback( &ctx->gen );
return DRV_CANCELED; return DRV_CANCELED;
} }
mkdirs:
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++) {
memcpy( buf + bl, subdirs[i], 4 ); memcpy( buf + bl, subdirs[i], 4 );
if (mkdir( buf, 0700 )) { if (mkdir( buf, 0700 )) {
@ -264,16 +263,12 @@ maildir_validate( const char *prefix, const char *box, int create, maildir_store
return DRV_BOX_BAD; return DRV_BOX_BAD;
} }
} else { } else {
for (i = j = 0; i < 3; i++) { for (i = 0; i < 3; i++) {
memcpy( buf + bl, subdirs[i], 4 ); memcpy( buf + bl, subdirs[i], 4 );
if (!stat( buf, &st ) && S_ISDIR(st.st_mode)) if (stat( buf, &st ) || !S_ISDIR(st.st_mode)) {
j++; error( "Maildir error: '%.*s' is no valid mailbox\n", bl, buf );
} return DRV_BOX_BAD;
if (!j) }
goto mkdirs;
if (j != 3) {
error( "Maildir error: '%.*s' is no valid mailbox\n", bl, buf );
return DRV_BOX_BAD;
} }
memcpy( buf + bl, "tmp/", 5 ); memcpy( buf + bl, "tmp/", 5 );
bl += 4; bl += 4;