master-connection.c revision 22535a9e685e29214082878e37a267157044618e
7cb128dc4cae2a03a742f63ba7afee23c78e3af0Phil Carmody/* Copyright (C) 2002 Timo Sirainen */
da7f1a07f583df8905684a7b78469960afd7c78dPhil Carmodystatic unsigned int master_pos;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenstatic char master_buf[sizeof(struct auth_master_request)];
300e4e43ed1ca46d0614459161ca2fb460ef661aTimo Sirainenstatic size_t reply_add(buffer_t *buf, const char *str)
da7f1a07f583df8905684a7b78469960afd7c78dPhil Carmody index = buffer_get_used_size(buf) - sizeof(struct auth_master_reply);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenfill_reply(const struct user_data *user, size_t *reply_size)
263fa7b43fb222f9805b80f62090907fe3f9ec13Timo Sirainen reply = buffer_append_space(buf, sizeof(*reply));
8ae72ad7d0c69e972cfa65d1e2ce4e3e9a8b765cTimo Sirainen reply->system_user_idx = reply_add(buf, user->system_user);
f7f25f9e1a38678d0e97d2e609beac16285fac6bTimo Sirainen reply->virtual_user_idx = reply_add(buf, user->virtual_user);
300e4e43ed1ca46d0614459161ca2fb460ef661aTimo Sirainen reply->data_size = *reply_size - sizeof(*reply);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenstatic void send_reply(struct auth_master_reply *reply, size_t reply_size,
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen unsigned int tag)
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen ret = o_stream_send(output, reply, reply_size);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen /* master died, kill ourself too */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen /* buffer full, we have to block */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen i_warning("Master transmit buffer full, blocking..");
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen /* transmit error, probably master died */
861f53be0cc2fa5665f3c107a7576e2a53bb2eb0Timo Sirainenstatic void userdb_callback(struct user_data *user, void *context)
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen unsigned int tag = POINTER_CAST_TO(context, unsigned int);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen send_reply(&failure_reply, sizeof(failure_reply), tag);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenstatic void master_handle_request(struct auth_master_request *request,
935960e45571872e38f730964f8ca1d116a1b532Timo Sirainen login_conn = login_connection_lookup(request->login_pid);
935960e45571872e38f730964f8ca1d116a1b532Timo Sirainen send_reply(&failure_reply, sizeof(failure_reply), request->tag);
935960e45571872e38f730964f8ca1d116a1b532Timo Sirainen userdb->lookup(auth_request->user, auth_request->realm,
int ret;
if (ret < 0) {
master_pos = 0;
void master_connection_init(void)
master_pos = 0;
FALSE);
void master_connection_deinit(void)