auth-master-connection.c revision 401b0787fff2dc986a5321ddb32acb1947ff66b0
2454dfa32c93c20a8522c6ed42fe057baaac9f9aStephan Bosch/* Copyright (c) 2002-2010 Dovecot authors, see the included COPYING file */
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainen unsigned int id;
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen unsigned int id;
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainenstatic void master_input(struct auth_master_connection *conn);
7ff6268cc35102675d73d44d680bed13d0709f7bTimo SirainenARRAY_TYPE(auth_master_connections) auth_master_connections;
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainenvoid auth_master_request_callback(struct auth_stream_reply *reply,
7ff6268cc35102675d73d44d680bed13d0709f7bTimo Sirainen struct auth_master_connection *conn = context;
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainenmaster_input_request(struct auth_master_connection *conn, const char *args)
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen const char *const *list;
0f97c2b6ec76e7f600e983cb952cf265a6189114Timo Sirainen /* <id> <client-pid> <client-id> <cookie> */
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen buffer_create_data(&buf, cookie, sizeof(cookie));
402e999a878e0cc41a0afb830fea0a93afc75f0dTimo Sirainen i_error("BUG: Master sent broken REQUEST cookie");
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen client_conn = auth_client_connection_lookup(client_pid);
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen i_error("Master requested auth for nonexisting client %u",
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen } else if (memcmp(client_conn->cookie, cookie, sizeof(cookie)) != 0) {
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen i_error("Master requested auth for client %u with invalid cookie",
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen client_conn->request_handler, conn, id, client_id);
85c9cf2c39903ecb102d701e8b19a7cf364dce83Timo Sirainenmaster_input_auth_request(struct auth_master_connection *conn, const char *args,
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen const char *cmd, struct auth_request **request_r,
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen const char **error_r)
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen unsigned int id;
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen /* <id> <userid> [<parameters>] */
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen if (!auth_request_set_username(auth_request, list[1], error_r)) {
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen (void)auth_request_import(auth_request, name, arg);
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen i_error("BUG: Master sent %s request without service", cmd);
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen struct auth_master_connection *conn = auth_request->context;
b936882755cc7819463e503edca4cb5f1782ae4bAki Tuomi struct auth_stream_reply *reply = auth_request->userdb_reply;
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen str_printfa(str, "FAIL\t%u", auth_request->id);
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen value = auth_stream_reply_find(reply, "reason");
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen str_printfa(str, "NOTFOUND\t%u", auth_request->id);
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen str_printfa(str, "USER\t%u\t", auth_request->id);
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen (void)o_stream_send(conn->output, str_data(str), str_len(str));
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainenmaster_input_user(struct auth_master_connection *conn, const char *args)
if (ret <= 0) {
if (ret < 0)
return FALSE;
return TRUE;
switch (result) {
case PASSDB_RESULT_OK:
const char *error;
int ret;
if (ret <= 0) {
if (ret < 0)
return FALSE;
return TRUE;
int ret;
if (ret > 0)
int ret;
const char *str;
T_BEGIN {
const char *str;
} T_END;
if (ret < 0) {
const char *str;
unsigned int id;
return FALSE;
return TRUE;
return TRUE;
return FALSE;
return FALSE;
char *line;
bool ret;
(int)MAX_INBUF_SIZE);
T_BEGIN {
} T_END;
if (!ret) {
struct auth_master_connection *
const char *line;
my_pid);
return conn;
unsigned int idx;
masters);
void auth_master_connections_init(void)
void auth_master_connections_deinit(void)
unsigned int i, count;
for (i = count; i > 0; i--)