static int
sieve_attribute_set(struct mailbox_transaction_context *t,
		    enum mail_attribute_type type, const char *key,
		    const struct mail_attribute_value *value)
{
	struct mail_user *user = t->box->storage->user;
	union mailbox_module_context *sbox = SIEVE_MAIL_CONTEXT(t->box);

	if (t->box->storage->user->dsyncing &&
	    type == MAIL_ATTRIBUTE_TYPE_PRIVATE &&
	    strncmp(key, MAILBOX_ATTRIBUTE_PREFIX_SIEVE,
		    strlen(MAILBOX_ATTRIBUTE_PREFIX_SIEVE)) == 0) {
		time_t ts =
			(value->last_change != 0 ? value->last_change : ioloop_time);

		if (sieve_attribute_set_sieve(t->box->storage, key, value) < 0)
			return -1;

		if (user->mail_debug) {
			const char *change;
			if (value->last_change != 0) {
				change = t_strflocaltime
					("(last change: %Y-%m-%d %H:%M:%S)", value->last_change);
			} else {
				change = t_strflocaltime
					("(time: %Y-%m-%d %H:%M:%S)", ioloop_time);
			}
			i_debug("doveadm-sieve: Assigned value for key `%s' %s",
				key, change);
		}

		/* FIXME: set value len to sieve script size / active name
		   length */
		if (value->value != NULL || value->value_stream != NULL)
			mail_index_attribute_set(t->itrans, TRUE, key, ts, 0);
		else
			mail_index_attribute_unset(t->itrans, TRUE, key, ts);
		return 0;
	}
	return sbox->super.attribute_set(t, type, key, value);
}
static bool
client_auth_handle_reply(struct client *client,
			 const struct client_auth_reply *reply, bool success)
{
	if (reply->proxy) {
		/* we want to proxy the connection to another server.
		   don't do this unless authentication succeeded. with
		   master user proxying we can get FAIL with proxy still set.

		   proxy host=.. [port=..] [destuser=..] pass=.. */
		if (!success)
			return FALSE;
		if (proxy_start(client, reply) < 0)
			client_auth_failed(client);
		return TRUE;
	}

	if (reply->host != NULL) {
		const char *reason;

		if (reply->reason != NULL)
			reason = reply->reason;
		else if (reply->nologin)
			reason = "Try this server instead.";
		else
			reason = "Logged in, but you should use this server instead.";

		if (reply->nologin) {
			client_auth_result(client,
				CLIENT_AUTH_RESULT_REFERRAL_NOLOGIN,
				reply, reason);
		} else {
			client_auth_result(client,
				CLIENT_AUTH_RESULT_REFERRAL_SUCCESS,
				reply, reason);
			return TRUE;
		}
	} else if (reply->nologin) {
		/* Authentication went ok, but for some reason user isn't
		   allowed to log in. Shouldn't probably happen. */
		if (reply->reason != NULL) {
			client_auth_result(client,
				CLIENT_AUTH_RESULT_AUTHFAILED_REASON,
				reply, reply->reason);
		} else if (reply->temp) {
			const char *timestamp, *msg;

			timestamp = t_strflocaltime("%Y-%m-%d %H:%M:%S", ioloop_time);
			msg = t_strdup_printf(AUTH_TEMP_FAILED_MSG" [%s:%s]",
				      my_hostname, timestamp);
			client_auth_result(client, CLIENT_AUTH_RESULT_TEMPFAIL,
					   reply, msg);
		} else if (reply->authz_failure) {
			client_auth_result(client,
				CLIENT_AUTH_RESULT_AUTHZFAILED, reply,
				"Authorization failed");
		} else {
			client_auth_result(client,
				CLIENT_AUTH_RESULT_AUTHFAILED, reply,
				AUTH_FAILED_MSG);
		}
	} else {
		/* normal login/failure */
		return FALSE;
	}

	i_assert(reply->nologin);

	if (!client->destroyed)
		client_auth_failed(client);
	return TRUE;
}
void client_send_internal_error(struct client_command_context *cmd)
{
	client_send_tagline(cmd,
		t_strflocaltime("NO "MAIL_ERRSTR_CRITICAL_MSG_STAMP, ioloop_time));
}
Beispiel #4
0
const char *unixdate2str(time_t timestamp)
{
	return t_strflocaltime("%Y-%m-%d %H:%M:%S", timestamp);
}
static int sieve_ldap_script_binary_read_metadata
(struct sieve_script *script, struct sieve_binary_block *sblock,
	sieve_size_t *offset)
{
	struct sieve_ldap_script *lscript =
		(struct sieve_ldap_script *)script;
	struct sieve_instance *svinst = script->storage->svinst;
	struct sieve_ldap_storage *lstorage =
		(struct sieve_ldap_storage *)script->storage;		
	struct sieve_binary *sbin =
		sieve_binary_block_get_binary(sblock);
	time_t bmtime = sieve_binary_mtime(sbin);
	string_t *dn, *modattr;

	/* config file changed? */
	if ( bmtime <= lstorage->set_mtime ) {
		if ( svinst->debug ) {
			sieve_script_sys_debug(script,
				"Sieve binary `%s' is not newer "
				"than the LDAP configuration `%s' (%s <= %s)",
				sieve_binary_path(sbin), lstorage->config_file,
				t_strflocaltime("%Y-%m-%d %H:%M:%S", bmtime),
				t_strflocaltime("%Y-%m-%d %H:%M:%S", lstorage->set_mtime));
		}
		return 0;
	}

	/* open script if not open already */
	if ( lscript->dn == NULL &&
		sieve_script_open(script, NULL) < 0 )
		return 0;

	/* if modattr not found, recompile always */
	if ( lscript->modattr == NULL || *lscript->modattr == '\0' ) {
		sieve_script_sys_error(script,
			"LDAP entry for script `%s' "
			"has no modified attribute `%s'",
			sieve_script_location(script),
			lstorage->set.sieve_ldap_mod_attr);
		return 0;
	}

	/* compare DN in binary and from search result */
	if ( !sieve_binary_read_string(sblock, offset, &dn) ) {
		sieve_script_sys_error(script,
			"Binary `%s' has invalid metadata for script `%s': "
			"Invalid DN",
			sieve_binary_path(sbin), sieve_script_location(script));
		return -1;
	}
	i_assert( lscript->dn != NULL );
	if ( strcmp(str_c(dn), lscript->dn) != 0 ) {
		sieve_script_sys_debug(script,
			"Binary `%s' reports different LDAP DN for script `%s' "
			"(`%s' rather than `%s')",
			sieve_binary_path(sbin), sieve_script_location(script),
			str_c(dn), lscript->dn);
		return 0;
	}

	/* compare modattr in binary and from search result */
	if ( !sieve_binary_read_string(sblock, offset, &modattr) ) {
		sieve_script_sys_error(script,
			"Binary `%s' has invalid metadata for script `%s': "
			"Invalid modified attribute",
			sieve_binary_path(sbin), sieve_script_location(script));
		return -1;
	}
	if ( strcmp(str_c(modattr), lscript->modattr) != 0 ) {
		sieve_script_sys_debug(script,
			"Binary `%s' reports different modified attribute content "
			"for script `%s' (`%s' rather than `%s')",
			sieve_binary_path(sbin), sieve_script_location(script),
			str_c(modattr), lscript->modattr);
		return 0;
	}
	return 1;
}