/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "hostpid.h"
#include "var-expand.h"
#include "hmac.h"
#include "sha1.h"
#include "randgen.h"
#include "safe-memset.h"
#include "mail-storage.h"
#include "mail-storage-service.h"
#include "mail-namespace.h"
#include "mail-user.h"
#include "imap-url.h"
#include "imap-msgpart-url.h"
#include "imap-urlauth-backend.h"
#include "imap-urlauth-fetch.h"
#include "imap-urlauth-connection.h"
#include "imap-urlauth-private.h"
#include <time.h>
struct imap_urlauth_context *
const struct imap_urlauth_config *config)
{
unsigned int timeout;
if (config->access_anonymous)
else
} else {
}
}
return uctx;
}
{
}
static const unsigned char *
const unsigned char mailbox_key[IMAP_URLAUTH_KEY_LEN],
{
unsigned char *token;
return token;
}
static bool
const unsigned char mailbox_key[IMAP_URLAUTH_KEY_LEN],
{
const unsigned char *valtoken;
return FALSE;
&valtoken_len);
if (token_len != valtoken_len)
return FALSE;
}
static bool
{
const char *const *application;
if (access_applications == NULL)
return FALSE;
have_userid = TRUE;
if (!have_userid) {
/* this access application must have no userid */
}
/* this access application must have a userid */
}
}
return FALSE;
}
static bool
const char **error_r)
{
const char *userid;
*error_r = "URL is missing URLAUTH";
return FALSE;
}
/* these access types are only allowed if URL is accessed through imap */
/* user+<access_user> */
*error_r = "URLAUTH `user' access is missing userid";
return FALSE;
}
if (!uctx->access_anonymous ||
return TRUE;
/* authuser */
if (!uctx->access_anonymous)
return TRUE;
/* anonymous */
return TRUE;
} else if (ignore_unknown || access_applications_have_access
return TRUE;
}
/* accessed directly through submission service */
"No '%s%s' access allowed for submission service",
return FALSE;
*error_r = "URLAUTH `submit' access is missing userid";
return FALSE;
} else if (!uctx->access_anonymous &&
return TRUE;
}
}
if (uctx->access_anonymous) {
"No '%s%s' access allowed for anonymous user",
} else {
"No '%s%s' access allowed for user %s",
}
return FALSE;
}
static bool
{
/* validate host */
*error_r = "Invalid URL: Inappropriate host name";
return FALSE;
}
/* validate port */
*error_r = "Invalid URL: Inappropriate server port";
return FALSE;
}
return TRUE;
}
{
const char *error;
const unsigned char *token;
int ret;
/* validate mechanism */
return 0;
}
/* validate URL */
return 0;
}
*error_r = "Invalid URL: Must be an URLAUTH rump URL";
return 0;
}
/* validate expiry time */
return 0;
}
}
/* validate user */
*error_r = "Invalid URL: Missing user name";
return 0;
}
"Not permitted to generate URLAUTH for user %s",
return 0;
}
/* validate host:port */
return 0;
/* validate mailbox */
return ret;
}
/* obtain mailbox key */
error_r, &error_code);
if (ret < 0) {
return ret;
}
return 1;
}
const char **error_r)
{
/* validate URL fields */
*error_r = "Invalid URL: Must be a full URLAUTH URL";
return FALSE;
}
/* check presence of userid */
*error_r = "Invalid URLAUTH: Missing user name";
return FALSE;
}
/* validate mechanism */
return FALSE;
}
/* validate expiry time */
return FALSE;
}
}
/* validate access */
error_r))
return FALSE;
/* validate host:port */
return FALSE;
return TRUE;
}
struct imap_msgpart_url **mpurl_r,
enum mail_error *error_code_r,
const char **error_r)
{
const char *error;
int ret;
/* check urlauth mechanism, access, userid and authority */
return 0;
}
/* validate target user */
return 0;
}
/* validate mailbox */
return ret;
}
&error)) < 0) {
*error_r = "Internal server error";
return -1;
}
if (ret == 0) {
/* RFC says: `If the mailbox cannot be identified, an
authorization token is calculated on the rump URL, using
random "plausible" keys (selected by the server) as needed,
before returning a validation failure. This prevents timing
attacks aimed at identifying mailbox names.' */
return 0;
}
/* obtain mailbox key */
if (ret < 0) {
return -1;
}
if (ret == 0 ||
url->uauth_token_size)) {
*error_r = "URLAUTH verification failed";
ret = 0;
} else {
ret = 1;
}
return ret;
}
{
const char *error;
/* validate URL */
return 0;
}
}
{
}
{
}