auth-master.c revision 36bf6cd88b1c71055ef12b07253f5223d981e43d
ee1e4c0fa7e8a973ecf16b7535664b8f47fc7e75Niranjan M.R/* Copyright (c) 2005-2010 Dovecot authors, see the included COPYING file */
ee1e4c0fa7e8a973ecf16b7535664b8f47fc7e75Niranjan M.R#define DEFAULT_USERDB_LOOKUP_PREFIX "userdb lookup"
ee1e4c0fa7e8a973ecf16b7535664b8f47fc7e75Niranjan M.R bool (*reply_callback)(const char *cmd, const char *const *args,
ee1e4c0fa7e8a973ecf16b7535664b8f47fc7e75Niranjan M.R const char *user;
ee1e4c0fa7e8a973ecf16b7535664b8f47fc7e75Niranjan M.R const char **fields;
ee1e4c0fa7e8a973ecf16b7535664b8f47fc7e75Niranjan M.R const char *const *user_strings;
ee1e4c0fa7e8a973ecf16b7535664b8f47fc7e75Niranjan M.Rstatic void auth_input(struct auth_master_connection *conn);
ee1e4c0fa7e8a973ecf16b7535664b8f47fc7e75Niranjan M.Rauth_master_init(const char *auth_socket_path, enum auth_master_flags flags)
ee1e4c0fa7e8a973ecf16b7535664b8f47fc7e75Niranjan M.R conn = i_new(struct auth_master_connection, 1);
ee1e4c0fa7e8a973ecf16b7535664b8f47fc7e75Niranjan M.R conn->auth_socket_path = i_strdup(auth_socket_path);
ee1e4c0fa7e8a973ecf16b7535664b8f47fc7e75Niranjan M.Rstatic void auth_connection_close(struct auth_master_connection *conn)
ee1e4c0fa7e8a973ecf16b7535664b8f47fc7e75Niranjan M.R i_error("close(%s) failed: %m", conn->auth_socket_path);
ee1e4c0fa7e8a973ecf16b7535664b8f47fc7e75Niranjan M.Rvoid auth_master_deinit(struct auth_master_connection **_conn)
ee1e4c0fa7e8a973ecf16b7535664b8f47fc7e75Niranjan M.Rstatic void auth_request_lookup_abort(struct auth_master_connection *conn)
ee1e4c0fa7e8a973ecf16b7535664b8f47fc7e75Niranjan M.Rstatic int auth_input_handshake(struct auth_master_connection *conn)
ee1e4c0fa7e8a973ecf16b7535664b8f47fc7e75Niranjan M.R while ((line = i_stream_next_line(conn->input)) != NULL) {
ee1e4c0fa7e8a973ecf16b7535664b8f47fc7e75Niranjan M.R if (strcmp(tmp[1], dec2str(AUTH_PROTOCOL_MAJOR)) != 0) {
ee1e4c0fa7e8a973ecf16b7535664b8f47fc7e75Niranjan M.R "Auth protocol version mismatch "
ee1e4c0fa7e8a973ecf16b7535664b8f47fc7e75Niranjan M.Rstatic int parse_reply(const char *cmd, const char *const *args,
ee1e4c0fa7e8a973ecf16b7535664b8f47fc7e75Niranjan M.R const char *expected_reply, const char *user, bool debug)
ee1e4c0fa7e8a973ecf16b7535664b8f47fc7e75Niranjan M.R } else if (debug) {
ee1e4c0fa7e8a973ecf16b7535664b8f47fc7e75Niranjan M.R i_debug("user %s: Auth %s lookup returned temporary failure: %s",
ee1e4c0fa7e8a973ecf16b7535664b8f47fc7e75Niranjan M.Rstatic bool auth_lookup_reply_callback(const char *cmd, const char *const *args,
ee1e4c0fa7e8a973ecf16b7535664b8f47fc7e75Niranjan M.R unsigned int i, len;
ee1e4c0fa7e8a973ecf16b7535664b8f47fc7e75Niranjan M.R bool debug = (ctx->conn->flags & AUTH_MASTER_FLAG_DEBUG) != 0;
ee1e4c0fa7e8a973ecf16b7535664b8f47fc7e75Niranjan M.R parse_reply(cmd, args, ctx->expected_reply, ctx->user, debug);
ee1e4c0fa7e8a973ecf16b7535664b8f47fc7e75Niranjan M.R ctx->fields = p_new(ctx->pool, const char *, len + 1);
ee1e4c0fa7e8a973ecf16b7535664b8f47fc7e75Niranjan M.R for (i = 0; i < len; i++)
ee1e4c0fa7e8a973ecf16b7535664b8f47fc7e75Niranjan M.R /* put the reason string into first field */
ee1e4c0fa7e8a973ecf16b7535664b8f47fc7e75Niranjan M.R ctx->fields = p_new(ctx->pool, const char *, 2);
ee1e4c0fa7e8a973ecf16b7535664b8f47fc7e75Niranjan M.R for (i = 0; i < len; i++) {
ee1e4c0fa7e8a973ecf16b7535664b8f47fc7e75Niranjan M.R i_debug("auth input: %s", t_strarray_join(args, " "));
ee1e4c0fa7e8a973ecf16b7535664b8f47fc7e75Niranjan M.Rauth_handle_line(struct auth_master_connection *conn, const char *line)
ee1e4c0fa7e8a973ecf16b7535664b8f47fc7e75Niranjan M.R const char *cmd, *const *args, *id, *wanted_id;
return FALSE;
const char *line;
bool ret;
T_BEGIN {
} T_END;
if (!ret)
int fd;
return FALSE;
return TRUE;
const char *cmd)
const char *str;
const char *const **fields_r)
void *context)
const char *user;
return TRUE;
return TRUE;
return FALSE;
struct auth_master_user_list_ctx *
const char *str;
return ctx;
return NULL;
return ret;