Commit 6e2a3758 6e2a37582ae89b43438952059412ea4a994d546c by Sergey Poznyakoff

Port 0b1e16be to imap4d

* imap4d/imap4d.c (tls_required): Remove.
(tls_mode): New variable.
(imap4d_srv_config) <tls>: Remove.
(imap4d_srv_config) <tls_mode>: New member.
(imap4d_srv_param): Change the definition of the "tls" statement.
Mark "tls-required" as deprecated.
(imap4d_mainloop): Change type of the tls argument.
Initialize session and pass it to each handler.
* imap4d/imap4d.h (imap4d_session): New struct.
(imap4d_command) <func>: Change signature. All uses changed.
(tls_mode): New enum.
(tls_required): Remove.
(tls_available): New global.
* imap4d/io.c (io_setio): Don't call tls_encryption_on, leave it to
the caller.
* imap4d/login.c (imap4d_login): Use session.
* imap4d/starttls.c (tls_available): Global. Present even if !WITH_TLS
(tls_encryption_on): Change signature. All callers updated.
1 parent 27ac3a54
......@@ -195,7 +195,8 @@ imap4d_append0 (mu_mailbox_t mbox, int flags, char *date_time, char *text,
/* APPEND mbox [(flags)] [date_time] message_literal */
int
imap4d_append (struct imap4d_command *command, imap4d_tokbuf_t tok)
imap4d_append (struct imap4d_session *session,
struct imap4d_command *command, imap4d_tokbuf_t tok)
{
int i;
char *mboxname;
......
......@@ -90,7 +90,8 @@ imap4d_auth_capability ()
*/
int
imap4d_authenticate (struct imap4d_command *command, imap4d_tokbuf_t tok)
imap4d_authenticate (struct imap4d_session *session,
struct imap4d_command *command, imap4d_tokbuf_t tok)
{
char *auth_type;
struct imap4d_auth adata;
......
......@@ -68,7 +68,8 @@ print_capa (void *item, void *data)
}
int
imap4d_capability (struct imap4d_command *command, imap4d_tokbuf_t tok)
imap4d_capability (struct imap4d_session *session,
struct imap4d_command *command, imap4d_tokbuf_t tok)
{
if (imap4d_tokbuf_argc (tok) != 2)
return io_completion_response (command, RESP_BAD, "Invalid arguments");
......
......@@ -29,7 +29,8 @@
*/
int
imap4d_check (struct imap4d_command *command, imap4d_tokbuf_t tok)
imap4d_check (struct imap4d_session *session,
struct imap4d_command *command, imap4d_tokbuf_t tok)
{
if (imap4d_tokbuf_argc (tok) != 2)
return io_completion_response (command, RESP_BAD, "Invalid arguments");
......
......@@ -77,7 +77,8 @@ imap4d_close0 (struct imap4d_command *command, imap4d_tokbuf_t tok,
EXPUNGE responses are sent. */
int
imap4d_close (struct imap4d_command *command, imap4d_tokbuf_t tok)
imap4d_close (struct imap4d_session *session,
struct imap4d_command *command, imap4d_tokbuf_t tok)
{
return imap4d_close0 (command, tok, 1);
}
......@@ -101,7 +102,8 @@ imap4d_close (struct imap4d_command *command, imap4d_tokbuf_t tok)
selected mailbox.
*/
int
imap4d_unselect (struct imap4d_command *command, imap4d_tokbuf_t tok)
imap4d_unselect (struct imap4d_session *session,
struct imap4d_command *command, imap4d_tokbuf_t tok)
{
return imap4d_close0 (command, tok, 0);
}
......
......@@ -34,7 +34,8 @@
*/
int
imap4d_copy (struct imap4d_command *command, imap4d_tokbuf_t tok)
imap4d_copy (struct imap4d_session *session,
struct imap4d_command *command, imap4d_tokbuf_t tok)
{
int rc;
char *text;
......
......@@ -33,7 +33,8 @@
deleted, its unique identifiers MUST be greater than any unique identifiers
used in the previous incarnation of the mailbox. */
int
imap4d_create (struct imap4d_command *command, imap4d_tokbuf_t tok)
imap4d_create (struct imap4d_session *session,
struct imap4d_command *command, imap4d_tokbuf_t tok)
{
char *name;
int isdir = 0;
......
......@@ -28,7 +28,8 @@
BAD - command unknown or arguments invalid
*/
int
imap4d_delete (struct imap4d_command *command, imap4d_tokbuf_t tok)
imap4d_delete (struct imap4d_session *session,
struct imap4d_command *command, imap4d_tokbuf_t tok)
{
int rc = RESP_OK;
const char *msg = "Completed";
......
......@@ -31,7 +31,8 @@
BAD - command unknown or arguments invalid
*/
int
imap4d_examine (struct imap4d_command *command, imap4d_tokbuf_t tok)
imap4d_examine (struct imap4d_session *session,
struct imap4d_command *command, imap4d_tokbuf_t tok)
{
if (imap4d_tokbuf_argc (tok) != 3)
return io_completion_response (command, RESP_BAD, "Invalid arguments");
......
......@@ -31,7 +31,8 @@
*/
int
imap4d_expunge (struct imap4d_command *command, imap4d_tokbuf_t tok)
imap4d_expunge (struct imap4d_session *session,
struct imap4d_command *command, imap4d_tokbuf_t tok)
{
if (imap4d_tokbuf_argc (tok) != 2)
return io_completion_response (command, RESP_BAD, "Invalid arguments");
......
......@@ -1856,7 +1856,8 @@ imap4d_fetch0 (imap4d_tokbuf_t tok, int isuid, char **err_text)
mailbox. The data items to be fetched can be either a single atom
or a parenthesized list. */
int
imap4d_fetch (struct imap4d_command *command, imap4d_tokbuf_t tok)
imap4d_fetch (struct imap4d_session *session,
struct imap4d_command *command, imap4d_tokbuf_t tok)
{
int rc;
char *err_text = "Completed";
......
......@@ -163,7 +163,8 @@ get_id_value (const char *name)
}
int
imap4d_id (struct imap4d_command *command, imap4d_tokbuf_t tok)
imap4d_id (struct imap4d_session *session,
struct imap4d_command *command, imap4d_tokbuf_t tok)
{
int rc = eat_args (tok);
if (rc != RESP_OK)
......
......@@ -17,7 +17,8 @@
#include "imap4d.h"
int
imap4d_idle (struct imap4d_command *command, imap4d_tokbuf_t tok)
imap4d_idle (struct imap4d_session *session,
struct imap4d_command *command, imap4d_tokbuf_t tok)
{
time_t start;
char *token_str = NULL;
......
......@@ -17,6 +17,7 @@
#include "imap4d.h"
#include <mailutils/gsasl.h>
#include "mailutils/libargp.h"
#include "mailutils/kwd.h"
#include "tcpwrap.h"
mu_m_server_t server;
......@@ -30,8 +31,8 @@ char *modify_homedir; /* Expression to produce imap4d_homedir */
int state = STATE_NONAUTH; /* Current IMAP4 state */
struct mu_auth_data *auth_data;
enum tls_mode tls_mode;
int login_disabled; /* Disable LOGIN command */
int tls_required; /* Require STARTTLS */
int create_home_dir; /* Create home directory if it does not
exist */
int home_dir_mode = S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
......@@ -94,8 +95,6 @@ static const char *imap4d_capa[] = {
NULL
};
static int imap4d_mainloop (int, int, int);
static error_t
imap4d_parse_opt (int key, char *arg, struct argp_state *state)
{
......@@ -251,14 +250,61 @@ cb_mailbox_mode (void *data, mu_config_value_t *val)
struct imap4d_srv_config
{
struct mu_srv_config m_cfg;
int tls;
enum tls_mode tls_mode;
};
#ifdef WITH_TLS
static int
cb_tls (void *data, mu_config_value_t *val)
{
int *res = data;
static struct mu_kwd tls_kwd[] = {
{ "no", tls_no },
{ "false", tls_no },
{ "off", tls_no },
{ "0", tls_no },
{ "ondemand", tls_ondemand },
{ "stls", tls_ondemand },
{ "required", tls_required },
{ "connection", tls_connection },
/* For compatibility with prior versions: */
{ "yes", tls_connection },
{ "true", tls_connection },
{ "on", tls_connection },
{ "1", tls_connection },
{ NULL }
};
if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
return 1;
if (mu_kwd_xlat_name (tls_kwd, val->v.string, res))
mu_error (_("not a valid tls keyword: %s"), val->v.string);
return 0;
}
#endif
static int
cb_tls_required (void *data, mu_config_value_t *val)
{
int *res = data;
int bv;
if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
return 1;
if (mu_cfg_parse_boolean (val->v.string, &bv))
mu_error (_("Not a boolean value"));
else
*res = tls_required;
return 0;
}
static struct mu_cfg_param imap4d_srv_param[] = {
{ "tls", mu_cfg_bool, NULL, mu_offsetof (struct imap4d_srv_config, tls),
NULL,
N_("Use TLS encryption for this server")
},
#ifdef WITH_TLS
{ "tls", mu_cfg_callback,
NULL, mu_offsetof (struct imap4d_srv_config, tls_mode), cb_tls,
N_("Kind of TLS encryption to use for this server") },
#endif
{ NULL }
};
......@@ -287,8 +333,13 @@ static struct mu_cfg_param imap4d_cfg_param[] = {
{ "home-dir-mode", mu_cfg_callback, NULL, 0, cb_mode,
N_("File mode for creating user home directories (octal)."),
N_("mode") },
{ "tls-required", mu_cfg_bool, &tls_required, 0, NULL,
N_("Always require STARTTLS before entering authentication phase.") },
#ifdef WITH_TLS
{ "tls", mu_cfg_callback, &tls_mode, 0, cb_tls,
N_("Kind of TLS encryption to use") },
{ "tls-required", mu_cfg_callback, &tls_mode, 0, cb_tls_required,
N_("Always require STLS before entering authentication phase.\n"
"Deprecated, use \"tls required\" instead.") },
#endif
{ "preauth", mu_cfg_callback, NULL, 0, cb_preauth,
N_("Configure PREAUTH mode. MODE is one of:\n"
" prog:///<full-program-name: string>\n"
......@@ -480,11 +531,12 @@ imap4d_child_signal_setup (RETSIGTYPE (*handler) (int signo))
}
static int
imap4d_mainloop (int ifd, int ofd, int tls)
imap4d_mainloop (int ifd, int ofd, enum tls_mode tls)
{
imap4d_tokbuf_t tokp;
char *text;
int signo;
struct imap4d_session session;
if (!test_mode)
test_mode = isatty (ifd);
......@@ -521,7 +573,29 @@ imap4d_mainloop (int ifd, int ofd, int tls)
imap4d_child_signal_setup (imap4d_child_signal);
}
io_setio (ifd, ofd, tls);
if (tls == tls_unspecified)
tls = tls_available ? tls_ondemand : tls_no;
else if (tls != tls_no && !tls_available)
{
mu_error (_("TLS is not configured, but requested in the "
"configuration"));
tls = tls_no;
}
switch (tls)
{
case tls_required:
imap4d_capability_add (IMAP_CAPA_XTLSREQUIRED);
case tls_no:
imap4d_capability_remove (IMAP_CAPA_STARTTLS);
tls_available = 0;
}
session.tls_mode = tls;
io_setio (ifd, ofd, tls == tls_connection);
if (tls == tls_connection)
tls_encryption_on (&session);
if (imap4d_preauth_setup (ifd) == 0)
{
......@@ -555,7 +629,7 @@ imap4d_mainloop (int ifd, int ofd, int tls)
imap4d_readline (tokp);
/* check for updates */
imap4d_sync ();
util_do_command (tokp);
util_do_command (&session, tokp);
imap4d_sync ();
io_flush ();
}
......@@ -578,7 +652,7 @@ imap4d_connection (int fd, struct sockaddr *sa, int salen,
else
rc = 1;
imap4d_mainloop (fd, fd, cfg->tls);
imap4d_mainloop (fd, fd, cfg->tls_mode);
if (rc == 0)
clr_strerr_flt ();
......@@ -687,10 +761,6 @@ main (int argc, char **argv)
if (login_disabled)
imap4d_capability_add (IMAP_CAPA_LOGINDISABLED);
#ifdef WITH_TLS
if (tls_required)
imap4d_capability_add (IMAP_CAPA_XTLSREQUIRED);
#endif
namespace_init ();
......
......@@ -115,10 +115,13 @@ extern "C" {
typedef struct imap4d_tokbuf *imap4d_tokbuf_t;
struct imap4d_session;
struct imap4d_command
{
const char *name;
int (*func) (struct imap4d_command *, imap4d_tokbuf_t);
int (*func) (struct imap4d_session *, struct imap4d_command *,
imap4d_tokbuf_t);
int states;
int failure;
int success;
......@@ -175,6 +178,20 @@ enum imap4d_preauth
preauth_prog
};
/* TLS modes */
enum tls_mode
{
tls_unspecified,
tls_no,
tls_ondemand,
tls_required,
tls_connection
};
struct imap4d_session
{
enum tls_mode tls_mode;
};
extern struct imap4d_command imap4d_command_table[];
extern mu_mailbox_t mbox;
......@@ -190,7 +207,6 @@ extern const char *program_version;
extern int mailbox_mode[NS_MAX];
extern int login_disabled;
extern int tls_required;
extern enum imap4d_preauth preauth_mode;
extern char *preauth_program;
extern int preauth_only;
......@@ -207,6 +223,8 @@ extern jmp_buf child_jmp;
extern int test_mode;
extern int silent_expunge;
int tls_available;
/* Input functions */
extern mu_stream_t iostream;
extern int io_untagged_response (int, const char *, ...) MU_PRINTFLIKE(2,3);
......@@ -271,51 +289,81 @@ int imap4d_with_parsebuf (imap4d_tokbuf_t tok, int arg,
#define imap4d_parsebuf_data(p) ((p)->data)
/* Imap4 commands */
extern int imap4d_append (struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_authenticate (struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_append (struct imap4d_session *,
struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_authenticate (struct imap4d_session *,
struct imap4d_command *, imap4d_tokbuf_t);
extern void imap4d_auth_capability (void);
extern int imap4d_capability (struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_check (struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_close (struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_unselect (struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_copy (struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_capability (struct imap4d_session *,
struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_check (struct imap4d_session *,
struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_close (struct imap4d_session *,
struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_unselect (struct imap4d_session *,
struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_copy (struct imap4d_session *,
struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_copy0 (imap4d_tokbuf_t, int isuid, char **err_text);
extern int imap4d_create (struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_delete (struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_examine (struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_expunge (struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_fetch (struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_create (struct imap4d_session *,
struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_delete (struct imap4d_session *,
struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_examine (struct imap4d_session *,
struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_expunge (struct imap4d_session *,
struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_fetch (struct imap4d_session *,
struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_fetch0 (imap4d_tokbuf_t tok, int isuid, char **err_text);
extern int imap4d_list (struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_login (struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_logout (struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_noop (struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_rename (struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_list (struct imap4d_session *,
struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_login (struct imap4d_session *,
struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_logout (struct imap4d_session *,
struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_noop (struct imap4d_session *,
struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_rename (struct imap4d_session *,
struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_preauth_setup (int fd);
extern int imap4d_search (struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_search (struct imap4d_session *,
struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_search0 (imap4d_tokbuf_t, int isuid, char **repyptr);
extern int imap4d_select (struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_select (struct imap4d_session *,
struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_select0 (struct imap4d_command *, const char *, int);
extern int imap4d_select_status (void);
#ifdef WITH_TLS
extern int imap4d_starttls (struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_starttls (struct imap4d_session *,
struct imap4d_command *, imap4d_tokbuf_t);
extern void starttls_init (void);
void tls_encryption_on (void);
void tls_encryption_on (struct imap4d_session *);
#endif /* WITH_TLS */
extern int imap4d_status (struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_store (struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_status (struct imap4d_session *,
struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_store (struct imap4d_session *,
struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_store0 (imap4d_tokbuf_t, int, char **);
mu_property_t open_subscription (void);
extern int imap4d_subscribe (struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_unsubscribe (struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_lsub (struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_uid (struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_namespace (struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_version (struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_idle (struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_id (struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_subscribe (struct imap4d_session *,
struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_unsubscribe (struct imap4d_session *,
struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_lsub (struct imap4d_session *,
struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_uid (struct imap4d_session *,
struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_namespace (struct imap4d_session *,
struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_version (struct imap4d_session *,
struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_idle (struct imap4d_session *,
struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_id (struct imap4d_session *,
struct imap4d_command *, imap4d_tokbuf_t);
extern int imap4d_check_home_dir (const char *dir, uid_t uid, gid_t gid);
......@@ -364,7 +412,7 @@ extern void imap4d_capability_init (void);
extern int util_start (char *);
extern int util_getstate (void);
extern int util_do_command (imap4d_tokbuf_t);
extern int util_do_command (struct imap4d_session *, imap4d_tokbuf_t);
extern char *util_getfullpath (const char *);
extern struct imap4d_command *util_getcommand (char *,
struct imap4d_command []);
......
......@@ -48,7 +48,6 @@ io_setio (int ifd, int ofd, int tls)
mu_error (_("failed to create TLS stream: %s"), mu_strerror (rc));
imap4d_bye (ERR_STREAM_CREATE);
}
tls_encryption_on ();
}
else
#endif
......
......@@ -131,7 +131,8 @@ list_fun (mu_folder_t folder, struct mu_list_response *resp, void *data)
but it does not match the hierarchy delimiter. */
int
imap4d_list (struct imap4d_command *command, imap4d_tokbuf_t tok)
imap4d_list (struct imap4d_session *session,
struct imap4d_command *command, imap4d_tokbuf_t tok)
{
char *ref;
char *wcard;
......
......@@ -30,12 +30,13 @@
BAD - command unknown or arguments invalid
*/
int
imap4d_login (struct imap4d_command *command, imap4d_tokbuf_t tok)
imap4d_login (struct imap4d_session *session,
struct imap4d_command *command, imap4d_tokbuf_t tok)
{
char *username, *pass;
int rc;
if (login_disabled || tls_required)
if (login_disabled || session->tls_mode == tls_required)
return io_completion_response (command, RESP_NO, "Command disabled");
if (imap4d_tokbuf_argc (tok) != 4)
......
......@@ -29,7 +29,8 @@
*/
int
imap4d_logout (struct imap4d_command *command, imap4d_tokbuf_t tok)
imap4d_logout (struct imap4d_session *session,
struct imap4d_command *command, imap4d_tokbuf_t tok)
{
if (imap4d_tokbuf_argc (tok) != 2)
return io_completion_response (command, RESP_BAD, "Invalid arguments");
......
......@@ -30,7 +30,8 @@
BAD - command unknown or arguments invalid
*/
int
imap4d_lsub (struct imap4d_command *command, imap4d_tokbuf_t tok)
imap4d_lsub (struct imap4d_session *session,
struct imap4d_command *command, imap4d_tokbuf_t tok)
{
int rc;
char *ref;
......
......@@ -112,7 +112,8 @@ namespace_enumerate_all (nsfp_t f, void *closure)
*/
int
imap4d_namespace (struct imap4d_command *command, imap4d_tokbuf_t tok)
imap4d_namespace (struct imap4d_session *session,
struct imap4d_command *command, imap4d_tokbuf_t tok)
{
if (imap4d_tokbuf_argc (tok) != 2)
return io_completion_response (command, RESP_BAD, "Invalid arguments");
......
......@@ -18,7 +18,8 @@
#include "imap4d.h"
int
imap4d_noop (struct imap4d_command *command, imap4d_tokbuf_t tok)
imap4d_noop (struct imap4d_session *session,
struct imap4d_command *command, imap4d_tokbuf_t tok)
{
if (imap4d_tokbuf_argc (tok) != 2)
return io_completion_response (command, RESP_BAD, "Invalid arguments");
......
......@@ -101,7 +101,8 @@ make_interdir (const char *name, int delim, int perms)
of the mailbox. */
int
imap4d_rename (struct imap4d_command *command, imap4d_tokbuf_t tok)
imap4d_rename (struct imap4d_session *session,
struct imap4d_command *command, imap4d_tokbuf_t tok)
{
char *oldname;
char *newname;
......
......@@ -258,7 +258,8 @@ static void do_search (struct parsebuf *pb);
*/
int
imap4d_search (struct imap4d_command *command, imap4d_tokbuf_t tok)
imap4d_search (struct imap4d_session *session,
struct imap4d_command *command, imap4d_tokbuf_t tok)
{
int rc;
char *err_text= "";
......
......@@ -22,7 +22,8 @@ static int select_flags;
/* select ::= "SELECT" SPACE mailbox */
int
imap4d_select (struct imap4d_command *command, imap4d_tokbuf_t tok)
imap4d_select (struct imap4d_session *session,
struct imap4d_command *command, imap4d_tokbuf_t tok)
{
if (imap4d_tokbuf_argc (tok) != 3)
return io_completion_response (command, RESP_BAD, "Invalid arguments");
......
......@@ -16,9 +16,10 @@
#include "imap4d.h"
int tls_available;
#ifdef WITH_TLS
static int tls_available;
static int tls_done;
/*
......@@ -32,7 +33,8 @@ static int tls_done;
BAD - command unknown or arguments invalid
*/
int
imap4d_starttls (struct imap4d_command *command, imap4d_tokbuf_t tok)
imap4d_starttls (struct imap4d_session *session,
struct imap4d_command *command, imap4d_tokbuf_t tok)
{
int status;
......@@ -48,7 +50,7 @@ imap4d_starttls (struct imap4d_command *command, imap4d_tokbuf_t tok)
io_flush ();
if (imap4d_init_tls_server () == 0)
tls_encryption_on ();
tls_encryption_on (session);
else
{
mu_diag_output (MU_DIAG_ERROR, _("session terminated"));
......@@ -60,7 +62,7 @@ imap4d_starttls (struct imap4d_command *command, imap4d_tokbuf_t tok)
}
void
tls_encryption_on ()
tls_encryption_on (struct imap4d_session *session)
{
tls_done = 1;
imap4d_capability_remove (IMAP_CAPA_STARTTLS);
......@@ -68,7 +70,7 @@ tls_encryption_on ()
login_disabled = 0;
imap4d_capability_remove (IMAP_CAPA_LOGINDISABLED);
tls_required = 0;
session->tls_mode = tls_no;
imap4d_capability_remove (IMAP_CAPA_XTLSREQUIRED);
}
......
......@@ -65,7 +65,8 @@ status_get_handler (const char *name)
BAD - command unknown or arguments invalid
*/
int
imap4d_status (struct imap4d_command *command, imap4d_tokbuf_t tok)
imap4d_status (struct imap4d_session *session,
struct imap4d_command *command, imap4d_tokbuf_t tok)
{
char *name;
char *mailbox_name;
......
......@@ -164,7 +164,8 @@ imap4d_store0 (imap4d_tokbuf_t tok, int isuid, char **ptext)
}
int
imap4d_store (struct imap4d_command *command, imap4d_tokbuf_t tok)
imap4d_store (struct imap4d_session *session,
struct imap4d_command *command, imap4d_tokbuf_t tok)
{
int rc;
char *err_text = NULL;
......
......@@ -54,7 +54,8 @@ open_subscription ()
BAD - command unknown or arguments invalid
*/
int
imap4d_subscribe (struct imap4d_command *command, imap4d_tokbuf_t tok)
imap4d_subscribe (struct imap4d_session *session,
struct imap4d_command *command, imap4d_tokbuf_t tok)
{
int rc;
char *name;
......
......@@ -22,7 +22,8 @@
*/
int
imap4d_uid (struct imap4d_command *command, imap4d_tokbuf_t tok)
imap4d_uid (struct imap4d_session *session,
struct imap4d_command *command, imap4d_tokbuf_t tok)
{
char *cmd;
int rc = RESP_NO;
......
......@@ -34,7 +34,8 @@
only if the unsubscription is successful.
*/
int
imap4d_unsubscribe (struct imap4d_command *command, imap4d_tokbuf_t tok)
imap4d_unsubscribe (struct imap4d_session *session,
struct imap4d_command *command, imap4d_tokbuf_t tok)
{
int rc;
char *name;
......
......@@ -37,7 +37,7 @@ util_getfullpath (const char *name)
}
int
util_do_command (imap4d_tokbuf_t tok)
util_do_command (struct imap4d_session *session, imap4d_tokbuf_t tok)
{
char *tag, *cmd;
struct imap4d_command *command;
......@@ -73,7 +73,7 @@ util_do_command (imap4d_tokbuf_t tok)
if (command->states && (command->states & state) == 0)
return io_completion_response (command, RESP_BAD, "Wrong state");
return command->func (command, tok);
return command->func (session, command, tok);
}
struct imap4d_command *
......