5b680ac8ef46fc1714f2ab59a07f68ac386ad89bSumit Bose Helper routines for file descriptor events
5b680ac8ef46fc1714f2ab59a07f68ac386ad89bSumit Bose Sumit Bose <sbose@redhat.com>
5b680ac8ef46fc1714f2ab59a07f68ac386ad89bSumit Bose Copyright (C) 2010 Red Hat
5b680ac8ef46fc1714f2ab59a07f68ac386ad89bSumit Bose This program is free software; you can redistribute it and/or modify
5b680ac8ef46fc1714f2ab59a07f68ac386ad89bSumit Bose it under the terms of the GNU General Public License as published by
5b680ac8ef46fc1714f2ab59a07f68ac386ad89bSumit Bose the Free Software Foundation; either version 3 of the License, or
5b680ac8ef46fc1714f2ab59a07f68ac386ad89bSumit Bose (at your option) any later version.
5b680ac8ef46fc1714f2ab59a07f68ac386ad89bSumit Bose This program is distributed in the hope that it will be useful,
5b680ac8ef46fc1714f2ab59a07f68ac386ad89bSumit Bose but WITHOUT ANY WARRANTY; without even the implied warranty of
5b680ac8ef46fc1714f2ab59a07f68ac386ad89bSumit Bose MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5b680ac8ef46fc1714f2ab59a07f68ac386ad89bSumit Bose GNU General Public License for more details.
5b680ac8ef46fc1714f2ab59a07f68ac386ad89bSumit Bose You should have received a copy of the GNU General Public License
5b680ac8ef46fc1714f2ab59a07f68ac386ad89bSumit Bose along with this program. If not, see <http://www.gnu.org/licenses/>.
48a038d077ed2de18a5211e010c18ab680107293Stephen Gallagher ret = ldap_get_option(ldap, LDAP_OPT_DESC, fd);
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to get fd from ldap!!\n");
7bfc287b693d3696bd5b3c60bdb7e543eb230f9bStephen Gallagherint remove_ldap_connection_callbacks(struct sdap_handle *sh)
63fb0857378c450d9806b1a3c6bb5657f00a8ba1Jakub Hrozek /* sdap_fd_events might be NULL here if the back end was marked offline
63fb0857378c450d9806b1a3c6bb5657f00a8ba1Jakub Hrozek * before a connection was established.
5b680ac8ef46fc1714f2ab59a07f68ac386ad89bSumit Bosestatic int remove_connection_callback(TALLOC_CTX *mem_ctx)
5b680ac8ef46fc1714f2ab59a07f68ac386ad89bSumit Bose struct ldap_conncb *conncb = talloc_get_type(mem_ctx, struct ldap_conncb);
5b680ac8ef46fc1714f2ab59a07f68ac386ad89bSumit Bose struct ldap_cb_data *cb_data = talloc_get_type(conncb->lc_arg,
5b680ac8ef46fc1714f2ab59a07f68ac386ad89bSumit Bose lret = ldap_get_option(cb_data->sh->ldap, LDAP_OPT_CONNECT_CB, conncb);
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to remove connection callback.\n");
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_TRACE_ALL, "Successfully removed connection callback.\n");
5b680ac8ef46fc1714f2ab59a07f68ac386ad89bSumit Bosestatic int sdap_ldap_connect_callback_add(LDAP *ld, Sockbuf *sb,
5b680ac8ef46fc1714f2ab59a07f68ac386ad89bSumit Bose struct ldap_cb_data *cb_data = talloc_get_type(ctx->lc_arg,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "sdap_ldap_connect_callback_add called without "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "callback data.\n");
5b680ac8ef46fc1714f2ab59a07f68ac386ad89bSumit Bose ret = ber_sockbuf_ctrl(sb, LBER_SB_OPT_GET_FD, &ber_fd);
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "ber_sockbuf_ctrl failed.\n");
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_TRACE_LIBS, "New LDAP connection to [%s] with fd [%d].\n",
5b680ac8ef46fc1714f2ab59a07f68ac386ad89bSumit Bose fd_event_item = talloc_zero(cb_data, struct fd_event_item);
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "talloc failed.\n");
5b680ac8ef46fc1714f2ab59a07f68ac386ad89bSumit Bose fd_event_item->fde = tevent_add_fd(cb_data->ev, fd_event_item, ber_fd,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "tevent_add_fd failed.\n");
5b680ac8ef46fc1714f2ab59a07f68ac386ad89bSumit Bosestatic void sdap_ldap_connect_callback_del(LDAP *ld, Sockbuf *sb,
5b680ac8ef46fc1714f2ab59a07f68ac386ad89bSumit Bose struct ldap_cb_data *cb_data = talloc_get_type(ctx->lc_arg,
5b680ac8ef46fc1714f2ab59a07f68ac386ad89bSumit Bose ret = ber_sockbuf_ctrl(sb, LBER_SB_OPT_GET_FD, &ber_fd);
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "ber_sockbuf_ctrl failed.\n");
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_TRACE_ALL, "Closing LDAP connection with fd [%d].\n", ber_fd);
5b680ac8ef46fc1714f2ab59a07f68ac386ad89bSumit Bose DLIST_FOR_EACH(fd_event_item, cb_data->fd_list) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "No event for fd [%d] found.\n", ber_fd);
5b680ac8ef46fc1714f2ab59a07f68ac386ad89bSumit Bosestatic int sdap_install_ldap_callbacks(struct sdap_handle *sh,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "sdap_install_ldap_callbacks is called with already "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "initialized sdap_fd_events.\n");
5b680ac8ef46fc1714f2ab59a07f68ac386ad89bSumit Bose sh->sdap_fd_events = talloc_zero(sh, struct sdap_fd_events);
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "talloc_zero failed.\n");
5b680ac8ef46fc1714f2ab59a07f68ac386ad89bSumit Bose sh->sdap_fd_events->fde = tevent_add_fd(ev, sh->sdap_fd_events, fd,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "Trace: sh[%p], connected[%d], ops[%p], fde[%p], ldap[%p]\n",
5b680ac8ef46fc1714f2ab59a07f68ac386ad89bSumit Bose sh, (int)sh->connected, sh->ops, sh->sdap_fd_events->fde,
5b680ac8ef46fc1714f2ab59a07f68ac386ad89bSumit Boseerrno_t setup_ldap_connection_callbacks(struct sdap_handle *sh,
5b680ac8ef46fc1714f2ab59a07f68ac386ad89bSumit Bose sh->sdap_fd_events = talloc_zero(sh, struct sdap_fd_events);
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "talloc_zero failed.\n");
5b680ac8ef46fc1714f2ab59a07f68ac386ad89bSumit Bose sh->sdap_fd_events->conncb = talloc_zero(sh->sdap_fd_events,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "talloc_zero failed.\n");
5b680ac8ef46fc1714f2ab59a07f68ac386ad89bSumit Bose cb_data = talloc_zero(sh->sdap_fd_events->conncb, struct ldap_cb_data);
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "talloc_zero failed.\n");
5b680ac8ef46fc1714f2ab59a07f68ac386ad89bSumit Bose sh->sdap_fd_events->conncb->lc_add = sdap_ldap_connect_callback_add;
5b680ac8ef46fc1714f2ab59a07f68ac386ad89bSumit Bose sh->sdap_fd_events->conncb->lc_del = sdap_ldap_connect_callback_del;
5b680ac8ef46fc1714f2ab59a07f68ac386ad89bSumit Bose ret = ldap_set_option(sh->ldap, LDAP_OPT_CONNECT_CB,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to set connection callback\n");
5b680ac8ef46fc1714f2ab59a07f68ac386ad89bSumit Bose talloc_set_destructor((TALLOC_CTX *) sh->sdap_fd_events->conncb,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_TRACE_ALL, "LDAP connection callbacks are not supported.\n");
5b680ac8ef46fc1714f2ab59a07f68ac386ad89bSumit Boseerrno_t sdap_set_connected(struct sdap_handle *sh, struct tevent_context *ev)
0eb8bf8c05a5535ed44c71342f4bed5b821cfa06Sumit Boseerrno_t sdap_call_conn_cb(const char *uri,int fd, struct sdap_handle *sh)
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "ber_sockbuf_alloc failed.\n");
0eb8bf8c05a5535ed44c71342f4bed5b821cfa06Sumit Bose ret = ber_sockbuf_ctrl(sb, LBER_SB_OPT_SET_FD, &fd);
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "ber_sockbuf_ctrl failed.\n");
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "ldap_url_parse failed to validate [%s] on fd [%d].\n",
0eb8bf8c05a5535ed44c71342f4bed5b821cfa06Sumit Bose ret = sdap_ldap_connect_callback_add(NULL, sb, lud, NULL,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_TRACE_ALL, "LDAP connection callbacks are not supported.\n");