-/*
- handle fd send events on a KDC socket
-*/
-static void kdc_send_handler(struct kdc_socket *kdc_socket)
-{
- while (kdc_socket->send_queue) {
- struct kdc_reply *rep = kdc_socket->send_queue;
- NTSTATUS status;
- size_t sendlen;
-
- status = socket_sendto(kdc_socket->sock, &rep->packet, &sendlen,
- rep->dest);
- if (NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES)) {
- break;
- }
- if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_BUFFER_SIZE)) {
- /* Replace with a krb err, response to big */
- }
-
- DLIST_REMOVE(kdc_socket->send_queue, rep);
- talloc_free(rep);
- }
-
- if (kdc_socket->send_queue == NULL) {
- EVENT_FD_NOT_WRITEABLE(kdc_socket->fde);
- }
-}
-
-
-/*
- handle fd recv events on a KDC socket
-*/
-static void kdc_recv_handler(struct kdc_socket *kdc_socket)
-{
- NTSTATUS status;
- TALLOC_CTX *tmp_ctx = talloc_new(kdc_socket);
- DATA_BLOB blob;
- struct kdc_reply *rep;
- DATA_BLOB reply;
- size_t nread, dsize;
- struct socket_address *src;
- struct socket_address *my_addr;
- struct tsocket_address *tsrcaddr;
- struct tsocket_address *tmyaddr;
- int ret;
-
- status = socket_pending(kdc_socket->sock, &dsize);
- if (!NT_STATUS_IS_OK(status)) {
- talloc_free(tmp_ctx);
- return;
- }
-
- blob = data_blob_talloc(tmp_ctx, NULL, dsize);
- if (blob.data == NULL) {
- /* hope this is a temporary low memory condition */
- talloc_free(tmp_ctx);
- return;
- }
-
- status = socket_recvfrom(kdc_socket->sock, blob.data, blob.length, &nread,
- tmp_ctx, &src);
- if (!NT_STATUS_IS_OK(status)) {
- talloc_free(tmp_ctx);
- return;
- }
- blob.length = nread;
-
- DEBUG(10,("Received krb5 UDP packet of length %lu from %s:%u\n",
- (long)blob.length, src->addr, (uint16_t)src->port));
-
- my_addr = socket_get_my_addr(kdc_socket->sock, tmp_ctx);
- if (!my_addr) {
- talloc_free(tmp_ctx);
- return;
- }
-
- ret = tsocket_address_bsd_from_sockaddr(tmp_ctx, src->sockaddr,
- src->sockaddrlen, &tsrcaddr);
- if (ret < 0) {
- talloc_free(tmp_ctx);
- return;
- }
-
- ret = tsocket_address_bsd_from_sockaddr(tmp_ctx, my_addr->sockaddr,
- my_addr->sockaddrlen, &tmyaddr);
- if (ret < 0) {
- talloc_free(tmp_ctx);
- return;
- }
-
- /* Call krb5 */
- ret = kdc_socket->process(kdc_socket->kdc,
- tmp_ctx,
- &blob,
- &reply,
- tsrcaddr,
- tmyaddr,
- 1 /* Datagram */);
- if (!ret) {
- talloc_free(tmp_ctx);
- return;
- }
-
- /* queue a pending reply */
- rep = talloc(kdc_socket, struct kdc_reply);
- if (rep == NULL) {
- talloc_free(tmp_ctx);
- return;
- }
- rep->dest = talloc_steal(rep, src);
- rep->packet = reply;
- talloc_steal(rep, reply.data);
-
- if (rep->packet.data == NULL) {
- talloc_free(rep);
- talloc_free(tmp_ctx);
- return;
- }
-
- DLIST_ADD_END(kdc_socket->send_queue, rep, struct kdc_reply *);
- EVENT_FD_WRITEABLE(kdc_socket->fde);
- talloc_free(tmp_ctx);
-}
-
-/*
- handle fd events on a KDC socket
-*/
-static void kdc_socket_handler(struct tevent_context *ev, struct tevent_fd *fde,
- uint16_t flags, void *private_data)
-{
- struct kdc_socket *kdc_socket = talloc_get_type(private_data, struct kdc_socket);
- if (flags & EVENT_FD_WRITE) {
- kdc_send_handler(kdc_socket);
- }
- if (flags & EVENT_FD_READ) {
- kdc_recv_handler(kdc_socket);
- }
-}
-