/* Copyright (c) 2008-2018 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "ioloop.h"
#include "str.h"
#include "read-full.h"
#include "write-full.h"
#include "eacces-error.h"
#include "mailbox-list.h"
#include "mailbox-uidvalidity.h"
#include <stdio.h>
#include <unistd.h>
#include <dirent.h>
#include <fcntl.h>
{
/* we failed to use the uidvalidity file. don't fail the mailbox
creation because of it though, most of the time it's safe enough
to use the current time as the uidvalidity value. */
else
uid_validity++;
if (uid_validity == 0)
uid_validity = 1;
return uid_validity;
}
{
int fd;
if (fd == -1) {
return;
}
} else {
i_error("fchown(%s, -1, %ld) failed: %m",
}
}
i_unreached();
}
static int
bool log_enoent)
{
unsigned int i;
int ret;
for (i = 0; i < RETRY_COUNT; i++) {
*uid_validity += 1;
if (*uid_validity == 0)
*uid_validity += 1;
break;
/* possibly a race condition. try the next value. */
}
return ret;
}
static uint32_t
{
DIR *d;
unsigned int i;
int fd;
dir = ".";
} else {
fname++;
}
/* FIXME: the PATH_TYPE_CONTROL should come as a parameter, but
that's an API change, do it in v2.3. it's not really a
problem though, since currently all backends use control
dirs for the uidvalidity file. */
}
if (d == NULL) {
return mailbox_uidvalidity_next_fallback();
}
/* just in case there happens to be multiple matching uidvalidity
min value file. */
}
}
}
if (closedir(d) < 0)
if (max_value == 0) {
/* no uidvalidity files. create one. */
for (i = 0; i < RETRY_COUNT; i++) {
/* the file is empty, don't bother with permissions */
break;
/* already exists. although it's quite unlikely we'll
hit this race condition. more likely we'll create
a duplicate file.. */
}
if (fd == -1) {
return cur_value;
}
i_close_fd(&fd);
return cur_value;
}
/* duplicate uidvalidity files, delete the oldest */
}
return mailbox_uidvalidity_next_fallback();
return cur_value;
}
{
if (fd == -1) {
}
if (ret < 0) {
i_close_fd(&fd);
}
cur_value == 0) {
/* broken value */
i_close_fd(&fd);
}
/* we now have the current uidvalidity value that's hopefully correct */
i_close_fd(&fd);
}
/* fast path succeeded. write the current value to the main
uidvalidity file. */
i_unreached();
return cur_value;
}