• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.10.1/Heimdal-398.1.2/lib/krb5/

Lines Matching refs:host

290 struct host;
293 krb5_error_code (*prepare)(krb5_context, struct host *, const krb5_data *);
294 krb5_error_code (*send)(krb5_context, struct host *);
295 krb5_error_code (*recv)(krb5_context, struct host *, krb5_data *);
299 struct host {
315 debug_host(krb5_context context, int level, struct host *host, const char *fmt, ...)
319 debug_host(krb5_context context, int level, struct host *host, const char *fmt, ...)
336 if (host->hi->proto == KRB5_KRBHST_HTTP)
338 else if (host->hi->proto == KRB5_KRBHST_TCP)
340 else if (host->hi->proto == KRB5_KRBHST_UDP)
342 else if (host->hi->proto == KRB5_KRBHST_KKDCP)
345 if (host->ai == NULL ||
346 getnameinfo(host->ai->ai_addr, host->ai->ai_addrlen,
354 text, proto, name, port, host->hi->hostname, host->tid);
362 struct host *host = ptr;
363 if (!rk_IS_BAD_SOCKET(host->fd))
364 rk_closesocket(host->fd);
365 if (!rk_IS_BAD_SOCKET(host->fd2))
366 rk_closesocket(host->fd2);
367 krb5_data_free(&host->data);
368 host->ai = NULL;
372 host_dead(krb5_context context, struct host *host, const char *msg)
374 debug_host(context, 5, host, "%s", msg);
375 rk_closesocket(host->fd);
376 host->fd = rk_INVALID_SOCKET;
377 host->state = DEAD;
381 send_stream(krb5_context context, struct host *host)
385 len = write(host->fd, host->data.data, host->data.length);
389 else if ((size_t)len < host->data.length) {
390 host->data.length -= len;
391 memmove(host->data.data, ((uint8_t *)host->data.data) + len, host->data.length - len);
394 krb5_data_free(&host->data);
400 recv_stream(krb5_context context, struct host *host)
407 if (rk_SOCK_IOCTL(host->fd, FIONREAD, &nbytes) != 0 || nbytes <= 0) {
408 debug_host(context, 5, host, "failed to get nbytes from socket, no bytes there?");
412 if (context->max_msg_size - host->data.length < (size_t)nbytes) {
415 (int)(host->data.length + nbytes));
419 oldlen = host->data.length;
421 ret = krb5_data_realloc(&host->data, oldlen + nbytes + 1 /* NUL */);
425 sret = read(host->fd, ((uint8_t *)host->data.data) + oldlen, nbytes);
428 debug_host(context, 5, host, "failed to read bytes from stream: %d", ret);
431 host->data.length = oldlen + sret;
433 ((uint8_t *)host->data.data)[host->data.length] = '\0';
443 send_kkdcp(krb5_context context, struct host *host)
448 char *path = host->hi->path;
453 heim_retain(host);
454 heim_retain(host->ctx);
459 if (host->hi->def_port != host->hi->port)
460 asprintf(&url, "https://%s:%d/%s", host->hi->hostname, host->hi->port, path);
462 asprintf(&url, "https://%s/%s", host->hi->hostname, path);
466 data = host->data;
467 krb5_data_zero(&host->data);
469 debug_host(context, 5, host, "sending request to: %s", url);
479 ret = _krb5_kkdcp_request(context, host->ctx->realm, url,
486 debug_host(context, 5, host, "kkdcp: got %d bytes, feeding them back", (int)retdata.length);
489 krb5_net_write_block(context, &host->fd2, length, sizeof(length), 2);
490 krb5_net_write_block(context, &host->fd2, retdata.data, retdata.length, 2);
493 close(host->fd2);
494 host->fd2 = -1;
495 heim_release(host->ctx);
496 heim_release(host);
501 close(host->fd2);
502 host->fd2 = -1;
511 host_next_timeout(krb5_context context, struct host *host)
513 host->timeout = context->kdc_timeout / host->fun->ntries;
514 if (host->timeout == 0)
515 host->timeout = 1;
517 host->timeout += time(NULL);
521 * connected host
525 host_connected(krb5_context context, krb5_sendto_ctx ctx, struct host *host)
529 host->state = CONNECTED;
531 * Now prepare data to send to host
538 ret = ctx->prexmit_func(context, host->hi->proto,
539 ctx->prexmit_ctx, host->fd, &data);
542 host_dead(context, host, "prexmit function didn't send data");
545 ret = host->fun->prepare(context, host, &data);
550 ret = host->fun->prepare(context, host, ctx->send_data);
553 debug_host(context, 5, host, "failed to prexmit/prepare");
557 * connect host
561 host_connect(krb5_context context, krb5_sendto_ctx ctx, struct host *host)
563 krb5_krbhst_info *hi = host->hi;
564 struct addrinfo *ai = host->ai;
566 debug_host(context, 5, host, "connecting to host");
568 if (connect(host->fd, ai->ai_addr, ai->ai_addrlen) < 0) {
570 debug_host(context, 5, host, "connecting to %d", host->fd);
571 host->state = CONNECTING;
573 host_dead(context, host, "failed to connect");
576 host_connected(context, ctx, host);
579 host_next_timeout(context, host);
587 prepare_http(krb5_context context, struct host *host, const krb5_data *data)
593 heim_assert(host->data.length == 0, "prepare_http called twice");
600 ret = asprintf(&request, "GET http://%s/%s HTTP/1.0\r\n\r\n", host->hi->hostname, str);
607 host->data.data = request;
608 host->data.length = strlen(request);
614 recv_http(krb5_context context, struct host *host, krb5_data *data)
625 ret = recv_stream(context, host);
629 p = strstr(host->data.data, "\r\n\r\n");
634 len = host->data.length - (p - (char *)host->data.data);
644 memmove(host->data.data, p, rep_len);
645 host->data.length = rep_len;
647 *data = host->data;
648 krb5_data_zero(&host->data);
658 prepare_tcp(krb5_context context, struct host *host, const krb5_data *data)
663 heim_assert(host->data.length == 0, "prepare_tcp called twice");
674 ret = krb5_storage_to_data(sp, &host->data);
681 recv_tcp(krb5_context context, struct host *host, krb5_data *data)
686 ret = recv_stream(context, host);
690 if (host->data.length < 4)
693 _krb5_get_int(host->data.data, &pktlen, 4);
695 if (pktlen > host->data.length - 4)
698 memmove(host->data.data, ((uint8_t *)host->data.data) + 4, host->data.length - 4);
699 host->data.length -= 4;
701 *data = host->data;
702 krb5_data_zero(&host->data);
712 prepare_udp(krb5_context context, struct host *host, const krb5_data *data)
714 return krb5_data_copy(&host->data, data->data, data->length);
718 send_udp(krb5_context context, struct host *host)
720 if (send(host->fd, host->data.data, host->data.length, 0) < 0)
726 recv_udp(krb5_context context, struct host *host, krb5_data *data)
732 if (rk_SOCK_IOCTL(host->fd, FIONREAD, &nbytes) != 0 || nbytes <= 0) {
733 debug_host(context, 5, host, "failed to get nbytes from socket, no bytes there?");
738 debug_host(context, 5, host, "server sent too large message %d (max is %d)",
750 sret = recv(host->fd, data->data, data->length, 0);
752 debug_host(context, 5, host, "read data from nbytes from host: %d", errno);
795 struct host *host,
800 if (host->state == CONNECTING && writeable)
801 host_connected(context, ctx, host);
805 debug_host(context, 5, host, "reading packet");
807 ret = host->fun->recv(context, host, &ctx->response);
812 debug_host(context, 5, host, "host completed");
815 host_dead(context, host, "host disconnected");
820 if (writeable && host->state == CONNECTED) {
824 debug_host(context, 5, host, "writing packet");
826 ret = host->fun->send(context, host);
830 host_dead(context, host, "host dead, write failed");
832 host->state = WAITING_REPLY;
842 static struct host *
849 struct host *host;
851 host = heim_uniq_alloc(sizeof(*host), "sendto-host", deallocate_host);
852 if (host == NULL)
855 host->hi = hi;
856 host->fd = fd;
857 host->fd2 = -1;
858 host->ai = ai;
859 host->ctx = ctx;
861 host->tid = ctx->stid = (ctx->stid & 0xffff0000) | ((ctx->stid & 0xffff) + 1);
863 host->state = CONNECT;
865 switch (host->hi->proto) {
867 host->fun = &http_fun;
870 host->fun = &kkdcp_fun;
873 host->fun = &tcp_fun;
876 host->fun = &udp_fun;
880 host->tries = host->fun->ntries;
882 heim_array_append_value(ctx->hosts, host);
884 return host;
900 struct host *host;
985 host = host_create(context, ctx, hi, a, fd);
986 if (host == NULL) {
992 * Connect directly next host, wait a host_timeout for each next address
995 host_connect(context, ctx, host);
997 debug_host(context, 5, host,
998 "Queuing host in future (in %ds), "
1002 host->timeout = time(NULL) + (submitted_host * context->host_timeout);
1006 heim_release(host);
1012 heim_assert(ai == NULL, "kkdcp host with ai ?");
1022 host = host_create(context, ctx, hi, NULL, fds[0]);
1023 if (host == NULL) {
1028 host->fd2 = fds[1];
1030 host_next_timeout(context, host);
1031 host_connected(context, ctx, host);
1034 heim_release(host);
1048 set_fd_status(struct host *h, fd_set *rfds, fd_set *wfds, int *max_fd)
1075 __block struct host *next_pending = NULL;
1094 struct host *h = (struct host *)obj;
1114 /* if host timed out, dec tries and (retry or kill host) */
1119 host_dead(context, h, "host timed out");
1132 * We have no host to wait for, but there is one pending, lets
1142 * Move all waiting host forward in time too, only if the next
1143 * host didn't happen the same about the same time as the last
1148 struct host *h = (struct host *)obj;
1160 struct host *h = (struct host *)obj;
1193 struct host *h = (struct host *)obj;
1195 heim_assert(h->state != DEAD, "dead host resurected");
1322 * Pull out next host, if there is no more, close the
1339 _krb5_debugx(context, 5, "submissing new requests to new host");