sdap_fd_events.c revision 3662413d65e9ba2a899e8ce98ec9c3a549be20c8
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync Helper routines for file descriptor events
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync Sumit Bose <sbose@redhat.com>
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync Copyright (C) 2010 Red Hat
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync This program is free software; you can redistribute it and/or modify
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync it under the terms of the GNU General Public License as published by
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync the Free Software Foundation; either version 3 of the License, or
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync (at your option) any later version.
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync This program is distributed in the hope that it will be useful,
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync but WITHOUT ANY WARRANTY; without even the implied warranty of
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync GNU General Public License for more details.
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync You should have received a copy of the GNU General Public License
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync along with this program. If not, see <http://www.gnu.org/licenses/>.
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsyncint remove_ldap_connection_callbacks(struct sdap_handle *sh)
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync /* sdap_fd_events might be NULL here if sdap_mark_offline()
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync * was called before a connection was established.
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsyncstatic int remove_connection_callback(TALLOC_CTX *mem_ctx)
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync struct ldap_conncb *conncb = talloc_get_type(mem_ctx, struct ldap_conncb);
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync struct ldap_cb_data *cb_data = talloc_get_type(conncb->lc_arg,
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync lret = ldap_get_option(cb_data->sh->ldap, LDAP_OPT_CONNECT_CB, conncb);
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync DEBUG(1, ("Failed to remove connection callback.\n"));
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync DEBUG(9, ("Successfully removed connection callback.\n"));
cac8713bfe400aa111c0662b57ea5c39d771dfdevboxsyncstatic int sdap_ldap_connect_callback_add(LDAP *ld, Sockbuf *sb,
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync struct ldap_cb_data *cb_data = talloc_get_type(ctx->lc_arg,
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync DEBUG(1, ("sdap_ldap_connect_callback_add called without "
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync "callback data.\n"));
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync ret = ber_sockbuf_ctrl(sb, LBER_SB_OPT_GET_FD, &ber_fd);
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync DEBUG(9, ("New LDAP connection to [%s] with fd [%d].\n",
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync fd_event_item = talloc_zero(cb_data, struct fd_event_item);
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync fd_event_item->fde = tevent_add_fd(cb_data->ev, fd_event_item, ber_fd,
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsyncstatic void sdap_ldap_connect_callback_del(LDAP *ld, Sockbuf *sb,
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync struct ldap_cb_data *cb_data = talloc_get_type(ctx->lc_arg,
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync ret = ber_sockbuf_ctrl(sb, LBER_SB_OPT_GET_FD, &ber_fd);
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync DEBUG(9, ("Closing LDAP connection with fd [%d].\n", ber_fd));
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync DEBUG(1, ("No event for fd [%d] found.\n", ber_fd));
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsyncstatic int sdap_install_ldap_callbacks(struct sdap_handle *sh,
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync DEBUG(1, ("sdap_install_ldap_callbacks is called with already "
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync "initialized sdap_fd_events.\n"));
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync sh->sdap_fd_events = talloc_zero(sh, struct sdap_fd_events);
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync sh->sdap_fd_events->fde = tevent_add_fd(ev, sh->sdap_fd_events, fd,
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync DEBUG(8, ("Trace: sh[%p], connected[%d], ops[%p], fde[%p], ldap[%p]\n",
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync sh, (int)sh->connected, sh->ops, sh->sdap_fd_events->fde,
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsyncerrno_t setup_ldap_connection_callbacks(struct sdap_handle *sh,
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync sh->sdap_fd_events = talloc_zero(sh, struct sdap_fd_events);
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync sh->sdap_fd_events->conncb = talloc_zero(sh->sdap_fd_events,
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync cb_data = talloc_zero(sh->sdap_fd_events->conncb, struct ldap_cb_data);
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync sh->sdap_fd_events->conncb->lc_add = sdap_ldap_connect_callback_add;
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync sh->sdap_fd_events->conncb->lc_del = sdap_ldap_connect_callback_del;
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync ret = ldap_set_option(sh->ldap, LDAP_OPT_CONNECT_CB,
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync talloc_set_destructor((TALLOC_CTX *) sh->sdap_fd_events->conncb,
2e848e79ccf2e4285250a0af98ddb9eb28864878vboxsync DEBUG(9, ("LDAP connection callbacks are not supported.\n"));