login-proxy-state.c revision 0d1b8b6bec79746c5d89d57dd8c1688946bd9237
2454dfa32c93c20a8522c6ed42fe057baaac9f9aStephan Bosch/* Copyright (c) 2009-2017 Dovecot authors, see the included COPYING file */
c53af2efae7a3484a23412e9be2c8e81523ab65eTimo Sirainenstatic int login_proxy_state_notify_open(struct login_proxy_state *state);
678d0463849ba777106eb7875f27db07a5d8e3dfTimo Sirainenstatic unsigned int
678d0463849ba777106eb7875f27db07a5d8e3dfTimo Sirainenlogin_proxy_record_hash(const struct login_proxy_record *rec)
678d0463849ba777106eb7875f27db07a5d8e3dfTimo Sirainenstatic int login_proxy_record_cmp(struct login_proxy_record *rec1,
6303191abcb37164f435ccdc56e9dbddf1288851Timo Sirainenstruct login_proxy_state *login_proxy_state_init(const char *notify_path)
088cb24027234024aff2c1ce5b6870c5a308a44bTimo Sirainen state->pool = pool_alloconly_create("login proxy state", 1024);
678d0463849ba777106eb7875f27db07a5d8e3dfTimo Sirainen hash_table_create(&state->hash, state->pool, 0,
678d0463849ba777106eb7875f27db07a5d8e3dfTimo Sirainen login_proxy_record_hash, login_proxy_record_cmp);
2129efcd74a72d051d182171b7e07916308e386dTimo Sirainen state->notify_path = p_strdup(state->pool, notify_path);
c53af2efae7a3484a23412e9be2c8e81523ab65eTimo Sirainenstatic void login_proxy_state_close(struct login_proxy_state *state)
c53af2efae7a3484a23412e9be2c8e81523ab65eTimo Sirainen i_error("close(%s) failed: %m", state->notify_path);
088cb24027234024aff2c1ce5b6870c5a308a44bTimo Sirainenvoid login_proxy_state_deinit(struct login_proxy_state **_state)
623eaaf530b2bd9cddbaeb88a211873ec9dee436Timo Sirainen /* sanity check: */
623eaaf530b2bd9cddbaeb88a211873ec9dee436Timo Sirainen while (hash_table_iterate(iter, state->hash, &rec, &rec))
088cb24027234024aff2c1ce5b6870c5a308a44bTimo Sirainenlogin_proxy_state_get(struct login_proxy_state *state,
088cb24027234024aff2c1ce5b6870c5a308a44bTimo Sirainen rec = p_new(state->pool, struct login_proxy_record, 1);
c53af2efae7a3484a23412e9be2c8e81523ab65eTimo Sirainenstatic void login_proxy_state_reopen(struct login_proxy_state *state)
2129efcd74a72d051d182171b7e07916308e386dTimo Sirainenstatic int login_proxy_state_notify_open(struct login_proxy_state *state)
c53af2efae7a3484a23412e9be2c8e81523ab65eTimo Sirainen /* reopen later */
2129efcd74a72d051d182171b7e07916308e386dTimo Sirainen state->notify_fd = open(state->notify_path, O_WRONLY);
c53af2efae7a3484a23412e9be2c8e81523ab65eTimo Sirainen i_error("open(%s) failed: %m", state->notify_path);
c53af2efae7a3484a23412e9be2c8e81523ab65eTimo Sirainen state->to_reopen = timeout_add(NOTIFY_RETRY_REOPEN_MSECS,
c53af2efae7a3484a23412e9be2c8e81523ab65eTimo Sirainenstatic bool login_proxy_state_try_notify(struct login_proxy_state *state,
6303191abcb37164f435ccdc56e9dbddf1288851Timo Sirainen const char *cmd;
6303191abcb37164f435ccdc56e9dbddf1288851Timo Sirainen cmd = t_strconcat(str_tabescape(user), "\n", NULL);
6303191abcb37164f435ccdc56e9dbddf1288851Timo Sirainen i_error("write(%s) failed: %m", state->notify_path);
c53af2efae7a3484a23412e9be2c8e81523ab65eTimo Sirainen /* retry sending */
c53af2efae7a3484a23412e9be2c8e81523ab65eTimo Sirainenvoid login_proxy_state_notify(struct login_proxy_state *state,
c53af2efae7a3484a23412e9be2c8e81523ab65eTimo Sirainen if (!login_proxy_state_try_notify(state, user))