Commit 0ef983f4 0ef983f43d00bca69a83a839652c19513e481337 by Sergey Poznyakoff

Do not create anything and return OK if the argument is suffixed with a hierarch…

…y separator. Fixes [bug #15142].
1 parent a6ff27ea
......@@ -33,6 +33,7 @@ imap4d_create (struct imap4d_command *command, char *arg)
char *name;
char *sp = NULL;
const char *delim = "/";
int isdir = 0;
int rc = RESP_OK;
const char *msg = "Completed";
......@@ -49,6 +50,23 @@ imap4d_create (struct imap4d_command *command, char *arg)
if (strcasecmp (name, "INBOX") == 0)
return util_finish (command, RESP_BAD, "Already exist");
/* RFC 3501:
If the mailbox name is suffixed with the server's hierarchy
separator character, this is a declaration that the client intends
to create mailbox names under this name in the hierarchy.
The trailing delimiter will be removed by namespace normalizer, so
test for it now.
The RFC goes on:
Server implementations that do not require this declaration MUST
ignore the declaration.
That's it! If isdir is set, we do all checks but do not create anything.
*/
if (name[strlen (name) - 1] == delim[0])
isdir = 1;
/* Allocates memory. */
name = namespace_getfullpath (name, delim);
......@@ -58,47 +76,45 @@ imap4d_create (struct imap4d_command *command, char *arg)
/* It will fail if the mailbox already exists. */
if (access (name, F_OK) != 0)
{
char *dir;
char *d = name + strlen (delim); /* Pass the root delimeter. */
/*If the server's hierarchy separtor character appears elsewhere in
name, the server SHOULD create any superior hierarchcal names
that are needed for the CREATE command to complete successfully. */
if (chdir (delim) == 0) /* start on the root. */
for (; (dir = strchr (d, delim[0])); d = dir)
{
*dir++ = '\0';
if (chdir (d) != 0)
if (!isdir)
{
char *dir;
char *d = name + strlen (delim); /* Pass the root delimeter. */
/* If the server's hierarchy separtor character appears elsewhere in
name, the server SHOULD create any superior hierarchcal names
that are needed for the CREATE command to complete successfully.
*/
if (chdir (delim) == 0) /* start on the root. */
for (; (dir = strchr (d, delim[0])); d = dir)
{
if (mkdir (d, 0700) == 0)
*dir++ = '\0';
if (chdir (d) != 0)
{
if (chdir (d) == 0)
{
continue;
}
else
if (mkdir (d, 0700) == 0)
{
rc = RESP_NO;
msg = "Can not create mailbox";
break;
if (chdir (d) == 0)
continue;
else
{
rc = RESP_NO;
msg = "Can not create mailbox";
break;
}
}
}
}
}
/* If the mailbox name is suffixed with the server's hierarchy
separator character, this is a declaration that the client intends
to create mailbox names under this name in the hierarchy.
In other words is d == '\0' it is not an error. */
if (rc == RESP_OK && d && *d != '\0')
{
int fd = creat (d, 0600);
if (fd != -1)
close (fd);
else
if (rc == RESP_OK && d && *d != '\0')
{
rc = RESP_NO;
msg = "Can not create mailbox";
int fd = creat (d, 0600);
if (fd != -1)
close (fd);
else
{
rc = RESP_NO;
msg = "Can not create mailbox";
}
}
}
}
......