summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Hudson <ghudson@mit.edu>2013-04-10 18:36:08 -0400
committerGreg Hudson <ghudson@mit.edu>2013-04-12 11:03:48 -0400
commit3e0faa329b0599c775547603dea21a6e18b4029d (patch)
tree7abca79c3358f4e86f5b902e6f204e1fae7d024f
parente4de1f768e818911e6c035ddcbaf0127e0eccb40 (diff)
downloadkrb5-3e0faa329b0599c775547603dea21a6e18b4029d.tar.gz
krb5-3e0faa329b0599c775547603dea21a6e18b4029d.tar.xz
krb5-3e0faa329b0599c775547603dea21a6e18b4029d.zip
Get rid of cm.c and cm.h
Since net-server.c now uses libverto, only sendto_kdc.c consumes cm.c. Move stuff out of cm.c and cm.h into sendto_kdc.c and get rid of them. Change the sendto_kdc callback (used by chpw.c) to receive the socket descriptor instead of the entire conn_state structure, and move the declarations into os-proto.h. struct remote_address also needs to be in os-proto.h so that trace.c and t_trace.c can use it. k5_curtime isn't needed since k5-platform.h now guarantees the presence of gettimeofday().
-rw-r--r--src/include/cm.h102
-rw-r--r--src/include/k5-int.h2
-rw-r--r--src/lib/krb5/libkrb5.exports1
-rw-r--r--src/lib/krb5/os/Makefile.in3
-rw-r--r--src/lib/krb5/os/changepw.c15
-rw-r--r--src/lib/krb5/os/cm.c98
-rw-r--r--src/lib/krb5/os/deps65
-rw-r--r--src/lib/krb5/os/os-proto.h13
-rw-r--r--src/lib/krb5/os/sendto_kdc.c110
-rw-r--r--src/lib/krb5/os/t_trace.c2
-rw-r--r--src/lib/krb5/os/trace.c1
11 files changed, 137 insertions, 275 deletions
diff --git a/src/include/cm.h b/src/include/cm.h
deleted file mode 100644
index 837a549b0c..0000000000
--- a/src/include/cm.h
+++ /dev/null
@@ -1,102 +0,0 @@
-/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
-/* include/cm.h */
-/*
- * Copyright 2002 by the Massachusetts Institute of Technology.
- * All Rights Reserved.
- *
- * Export of this software from the United States of America may
- * require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. Furthermore if you modify this software you must label
- * your software as modified software and not distribute it in such a
- * fashion that it might be confused with the original M.I.T. software.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-/*
- * Since fd_set is large on some platforms (8K on AIX 5.2), this probably
- * shouldn't be allocated in automatic storage. Define USE_POLL and
- * MAX_POLLFDS in the consumer of this header file to use poll state instead of
- * select state.
- */
-struct select_state {
-#ifdef USE_POLL
- struct pollfd fds[MAX_POLLFDS];
-#else
- int max;
- fd_set rfds, wfds, xfds;
-#endif
- int nfds;
- struct timeval end_time; /* magic: tv_sec==0 => never time out */
-};
-
-
-/* Select state flags. */
-#define SSF_READ 0x01
-#define SSF_WRITE 0x02
-#define SSF_EXCEPTION 0x04
-
-
-static const char *const state_strings[] = {
- "INITIALIZING", "CONNECTING", "WRITING", "READING", "FAILED"
-};
-
-
-/* connection states */
-enum conn_states { INITIALIZING, CONNECTING, WRITING, READING, FAILED };
-struct incoming_krb5_message {
- size_t bufsizebytes_read;
- size_t bufsize;
- char *buf;
- char *pos;
- unsigned char bufsizebytes[4];
- size_t n_left;
-};
-struct remote_address {
- int family;
- int type;
- socklen_t len;
- struct sockaddr_storage saddr;
-};
-struct conn_state {
- SOCKET fd;
- krb5_error_code err;
- enum conn_states state;
- unsigned int is_udp : 1;
- int (*service)(krb5_context context, struct conn_state *,
- struct select_state *, int);
- struct remote_address addr;
- struct {
- struct {
- sg_buf sgbuf[2];
- sg_buf *sgp;
- int sg_count;
- unsigned char msg_len_buf[4];
- } out;
- struct incoming_krb5_message in;
- } x;
- krb5_data callback_buffer;
- size_t server_index;
- struct conn_state *next;
-};
-
-struct sendto_callback_info {
- int (*pfn_callback) (struct conn_state *, void *, krb5_data *);
- void (*pfn_cleanup) (void *, krb5_data *);
- void *context;
-};
-
-
-krb5_error_code krb5int_cm_call_select (const struct select_state *,
- struct select_state *, int *);
diff --git a/src/include/k5-int.h b/src/include/k5-int.h
index a489ce3839..37bd9ffb06 100644
--- a/src/include/k5-int.h
+++ b/src/include/k5-int.h
@@ -562,8 +562,6 @@ extern char *strdup (const char *);
#include "k5-gmt_mktime.h"
-struct sendto_callback_info;
-
/* libos.spec */
krb5_error_code krb5_lock_file(krb5_context, int, int);
krb5_error_code krb5_unlock_file(krb5_context, int);
diff --git a/src/lib/krb5/libkrb5.exports b/src/lib/krb5/libkrb5.exports
index 03273df1ab..15f93c23a4 100644
--- a/src/lib/krb5/libkrb5.exports
+++ b/src/lib/krb5/libkrb5.exports
@@ -596,7 +596,6 @@ krb5_write_message
krb5int_accessor
krb5int_cc_default
krb5int_cleanup_library
-krb5int_cm_call_select
krb5int_copy_data_contents
krb5int_copy_data_contents_add0
krb5int_find_pa_data
diff --git a/src/lib/krb5/os/Makefile.in b/src/lib/krb5/os/Makefile.in
index f013899bbd..6a0961990c 100644
--- a/src/lib/krb5/os/Makefile.in
+++ b/src/lib/krb5/os/Makefile.in
@@ -18,7 +18,6 @@ STLIBOBJS= \
def_realm.o \
ccdefname.o \
changepw.o \
- cm.o \
dnsglue.o \
dnssrv.o \
expand_path.o \
@@ -63,7 +62,6 @@ OBJS= \
$(OUTPRE)def_realm.$(OBJEXT) \
$(OUTPRE)ccdefname.$(OBJEXT) \
$(OUTPRE)changepw.$(OBJEXT) \
- $(OUTPRE)cm.$(OBJEXT) \
$(OUTPRE)dnsglue.$(OBJEXT) \
$(OUTPRE)dnssrv.$(OBJEXT) \
$(OUTPRE)expand_path.$(OBJEXT) \
@@ -108,7 +106,6 @@ SRCS= \
$(srcdir)/def_realm.c \
$(srcdir)/ccdefname.c \
$(srcdir)/changepw.c \
- $(srcdir)/cm.c \
$(srcdir)/dnsglue.c \
$(srcdir)/dnssrv.c \
$(srcdir)/expand_path.c \
diff --git a/src/lib/krb5/os/changepw.c b/src/lib/krb5/os/changepw.c
index 25b89db49f..462910f6ba 100644
--- a/src/lib/krb5/os/changepw.c
+++ b/src/lib/krb5/os/changepw.c
@@ -34,7 +34,6 @@
#include "fake-addrinfo.h"
#include "k5-int.h"
#include "os-proto.h"
-#include "cm.h"
#include "../krb/auth_con.h"
#include "../krb/int-proto.h"
@@ -100,23 +99,21 @@ locate_kpasswd(krb5_context context, const krb5_data *realm,
static void
-kpasswd_sendto_msg_cleanup (void* callback_context, krb5_data* message)
+kpasswd_sendto_msg_cleanup(void *data, krb5_data *message)
{
- struct sendto_callback_context *ctx = callback_context;
+ struct sendto_callback_context *ctx = data;
krb5_free_data_contents(ctx->context, message);
}
static int
-kpasswd_sendto_msg_callback(struct conn_state *conn,
- void *callback_context,
- krb5_data *message)
+kpasswd_sendto_msg_callback(SOCKET fd, void *data, krb5_data *message)
{
krb5_error_code code = 0;
struct sockaddr_storage local_addr;
krb5_address local_kaddr;
- struct sendto_callback_context *ctx = callback_context;
+ struct sendto_callback_context *ctx = data;
GETSOCKNAME_ARG3_TYPE addrlen;
krb5_data output;
@@ -127,7 +124,7 @@ kpasswd_sendto_msg_callback(struct conn_state *conn,
*/
addrlen = sizeof(local_addr);
- if (getsockname(conn->fd, ss2sa(&local_addr), &addrlen) < 0) {
+ if (getsockname(fd, ss2sa(&local_addr), &addrlen) < 0) {
code = SOCKET_ERRNO;
goto cleanup;
}
@@ -259,7 +256,7 @@ change_set_password(krb5_context context,
addrlen = sizeof(remote_addr);
- callback_info.context = (void*) &callback_ctx;
+ callback_info.data = &callback_ctx;
callback_info.pfn_callback = kpasswd_sendto_msg_callback;
callback_info.pfn_cleanup = kpasswd_sendto_msg_cleanup;
krb5_free_data_contents(callback_ctx.context, &chpw_rep);
diff --git a/src/lib/krb5/os/cm.c b/src/lib/krb5/os/cm.c
deleted file mode 100644
index a9e1eb4779..0000000000
--- a/src/lib/krb5/os/cm.c
+++ /dev/null
@@ -1,98 +0,0 @@
-/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
-/* lib/krb5/os/cm.c - Connection manager functions */
-/*
- * Copyright (C) 2011 by the Massachusetts Institute of Technology.
- * All rights reserved.
- *
- * Export of this software from the United States of America may
- * require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. Furthermore if you modify this software you must label
- * your software as modified software and not distribute it in such a
- * fashion that it might be confused with the original M.I.T. software.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-/*
- * This file include krb5int_cm_call_select, which is used by
- * lib/apputils/net-server.c and sometimes by sendto_kdc.c.
- */
-
-#include "k5-int.h"
-#include "os-proto.h"
-#ifdef HAVE_SYS_SELECT_H
-#include <sys/select.h>
-#endif
-#ifdef _WIN32
-#include <sys/timeb.h>
-#endif
-#include "cm.h"
-
-int
-k5_getcurtime(struct timeval *tvp)
-{
-#ifdef _WIN32
- struct _timeb tb;
- _ftime(&tb);
- tvp->tv_sec = tb.time;
- tvp->tv_usec = tb.millitm * 1000;
- /* Can _ftime fail? */
- return 0;
-#else
- if (gettimeofday(tvp, 0))
- return errno;
- return 0;
-#endif
-}
-
-/*
- * Call select and return results.
- * Input: interesting file descriptors and absolute timeout
- * Output: select return value (-1 or num fds ready) and fd_sets
- * Return: 0 (for i/o available or timeout) or error code.
- */
-krb5_error_code
-krb5int_cm_call_select (const struct select_state *in,
- struct select_state *out, int *sret)
-{
- struct timeval now, *timo;
- krb5_error_code e;
-
- *out = *in;
- e = k5_getcurtime(&now);
- if (e)
- return e;
- if (out->end_time.tv_sec == 0)
- timo = 0;
- else {
- timo = &out->end_time;
- out->end_time.tv_sec -= now.tv_sec;
- out->end_time.tv_usec -= now.tv_usec;
- if (out->end_time.tv_usec < 0) {
- out->end_time.tv_usec += 1000000;
- out->end_time.tv_sec--;
- }
- if (out->end_time.tv_sec < 0) {
- *sret = 0;
- return 0;
- }
- }
-
- *sret = select(out->max, &out->rfds, &out->wfds, &out->xfds, timo);
- e = SOCKET_ERRNO;
-
- if (*sret < 0)
- return e;
- return 0;
-}
diff --git a/src/lib/krb5/os/deps b/src/lib/krb5/os/deps
index 1b19d785e4..63caf75c28 100644
--- a/src/lib/krb5/os/deps
+++ b/src/lib/krb5/os/deps
@@ -50,26 +50,15 @@ changepw.so changepw.po $(OUTPRE)changepw.$(OBJEXT): \
$(BUILDTOP)/include/autoconf.h $(BUILDTOP)/include/krb5/krb5.h \
$(BUILDTOP)/include/osconf.h $(BUILDTOP)/include/profile.h \
$(COM_ERR_DEPS) $(srcdir)/../krb/auth_con.h $(srcdir)/../krb/int-proto.h \
- $(top_srcdir)/include/cm.h $(top_srcdir)/include/fake-addrinfo.h \
- $(top_srcdir)/include/k5-buf.h $(top_srcdir)/include/k5-err.h \
- $(top_srcdir)/include/k5-gmt_mktime.h $(top_srcdir)/include/k5-int-pkinit.h \
- $(top_srcdir)/include/k5-int.h $(top_srcdir)/include/k5-platform.h \
- $(top_srcdir)/include/k5-plugin.h $(top_srcdir)/include/k5-thread.h \
- $(top_srcdir)/include/k5-trace.h $(top_srcdir)/include/krb5.h \
- $(top_srcdir)/include/krb5/authdata_plugin.h $(top_srcdir)/include/krb5/locate_plugin.h \
- $(top_srcdir)/include/krb5/plugin.h $(top_srcdir)/include/port-sockets.h \
- $(top_srcdir)/include/socket-utils.h changepw.c os-proto.h
-cm.so cm.po $(OUTPRE)cm.$(OBJEXT): $(BUILDTOP)/include/autoconf.h \
- $(BUILDTOP)/include/krb5/krb5.h $(BUILDTOP)/include/osconf.h \
- $(BUILDTOP)/include/profile.h $(COM_ERR_DEPS) $(top_srcdir)/include/cm.h \
- $(top_srcdir)/include/k5-buf.h $(top_srcdir)/include/k5-err.h \
- $(top_srcdir)/include/k5-gmt_mktime.h $(top_srcdir)/include/k5-int-pkinit.h \
- $(top_srcdir)/include/k5-int.h $(top_srcdir)/include/k5-platform.h \
- $(top_srcdir)/include/k5-plugin.h $(top_srcdir)/include/k5-thread.h \
- $(top_srcdir)/include/k5-trace.h $(top_srcdir)/include/krb5.h \
- $(top_srcdir)/include/krb5/authdata_plugin.h $(top_srcdir)/include/krb5/locate_plugin.h \
- $(top_srcdir)/include/krb5/plugin.h $(top_srcdir)/include/port-sockets.h \
- $(top_srcdir)/include/socket-utils.h cm.c os-proto.h
+ $(top_srcdir)/include/fake-addrinfo.h $(top_srcdir)/include/k5-buf.h \
+ $(top_srcdir)/include/k5-err.h $(top_srcdir)/include/k5-gmt_mktime.h \
+ $(top_srcdir)/include/k5-int-pkinit.h $(top_srcdir)/include/k5-int.h \
+ $(top_srcdir)/include/k5-platform.h $(top_srcdir)/include/k5-plugin.h \
+ $(top_srcdir)/include/k5-thread.h $(top_srcdir)/include/k5-trace.h \
+ $(top_srcdir)/include/krb5.h $(top_srcdir)/include/krb5/authdata_plugin.h \
+ $(top_srcdir)/include/krb5/locate_plugin.h $(top_srcdir)/include/krb5/plugin.h \
+ $(top_srcdir)/include/port-sockets.h $(top_srcdir)/include/socket-utils.h \
+ changepw.c os-proto.h
dnsglue.so dnsglue.po $(OUTPRE)dnsglue.$(OBJEXT): $(BUILDTOP)/include/autoconf.h \
$(BUILDTOP)/include/krb5/krb5.h $(BUILDTOP)/include/osconf.h \
$(BUILDTOP)/include/profile.h $(COM_ERR_DEPS) $(top_srcdir)/include/k5-buf.h \
@@ -395,7 +384,7 @@ port2ip.so port2ip.po $(OUTPRE)port2ip.$(OBJEXT): $(BUILDTOP)/include/autoconf.h
sendto_kdc.so sendto_kdc.po $(OUTPRE)sendto_kdc.$(OBJEXT): \
$(BUILDTOP)/include/autoconf.h $(BUILDTOP)/include/krb5/krb5.h \
$(BUILDTOP)/include/osconf.h $(BUILDTOP)/include/profile.h \
- $(COM_ERR_DEPS) $(top_srcdir)/include/cm.h $(top_srcdir)/include/fake-addrinfo.h \
+ $(COM_ERR_DEPS) $(top_srcdir)/include/fake-addrinfo.h \
$(top_srcdir)/include/k5-buf.h $(top_srcdir)/include/k5-err.h \
$(top_srcdir)/include/k5-gmt_mktime.h $(top_srcdir)/include/k5-int-pkinit.h \
$(top_srcdir)/include/k5-int.h $(top_srcdir)/include/k5-platform.h \
@@ -450,15 +439,15 @@ toffset.so toffset.po $(OUTPRE)toffset.$(OBJEXT): $(BUILDTOP)/include/autoconf.h
$(top_srcdir)/include/socket-utils.h toffset.c
trace.so trace.po $(OUTPRE)trace.$(OBJEXT): $(BUILDTOP)/include/autoconf.h \
$(BUILDTOP)/include/krb5/krb5.h $(BUILDTOP)/include/osconf.h \
- $(BUILDTOP)/include/profile.h $(COM_ERR_DEPS) $(top_srcdir)/include/cm.h \
- $(top_srcdir)/include/k5-buf.h $(top_srcdir)/include/k5-err.h \
- $(top_srcdir)/include/k5-gmt_mktime.h $(top_srcdir)/include/k5-int-pkinit.h \
- $(top_srcdir)/include/k5-int.h $(top_srcdir)/include/k5-platform.h \
- $(top_srcdir)/include/k5-plugin.h $(top_srcdir)/include/k5-thread.h \
- $(top_srcdir)/include/k5-trace.h $(top_srcdir)/include/krb5.h \
- $(top_srcdir)/include/krb5/authdata_plugin.h $(top_srcdir)/include/krb5/locate_plugin.h \
- $(top_srcdir)/include/krb5/plugin.h $(top_srcdir)/include/port-sockets.h \
- $(top_srcdir)/include/socket-utils.h os-proto.h trace.c
+ $(BUILDTOP)/include/profile.h $(COM_ERR_DEPS) $(top_srcdir)/include/k5-buf.h \
+ $(top_srcdir)/include/k5-err.h $(top_srcdir)/include/k5-gmt_mktime.h \
+ $(top_srcdir)/include/k5-int-pkinit.h $(top_srcdir)/include/k5-int.h \
+ $(top_srcdir)/include/k5-platform.h $(top_srcdir)/include/k5-plugin.h \
+ $(top_srcdir)/include/k5-thread.h $(top_srcdir)/include/k5-trace.h \
+ $(top_srcdir)/include/krb5.h $(top_srcdir)/include/krb5/authdata_plugin.h \
+ $(top_srcdir)/include/krb5/locate_plugin.h $(top_srcdir)/include/krb5/plugin.h \
+ $(top_srcdir)/include/port-sockets.h $(top_srcdir)/include/socket-utils.h \
+ os-proto.h trace.c
unlck_file.so unlck_file.po $(OUTPRE)unlck_file.$(OBJEXT): \
$(BUILDTOP)/include/autoconf.h $(BUILDTOP)/include/krb5/krb5.h \
$(BUILDTOP)/include/osconf.h $(BUILDTOP)/include/profile.h \
@@ -532,12 +521,12 @@ t_std_conf.so t_std_conf.po $(OUTPRE)t_std_conf.$(OBJEXT): \
$(top_srcdir)/include/socket-utils.h os-proto.h t_std_conf.c
t_trace.so t_trace.po $(OUTPRE)t_trace.$(OBJEXT): $(BUILDTOP)/include/autoconf.h \
$(BUILDTOP)/include/krb5/krb5.h $(BUILDTOP)/include/osconf.h \
- $(BUILDTOP)/include/profile.h $(COM_ERR_DEPS) $(top_srcdir)/include/cm.h \
- $(top_srcdir)/include/k5-buf.h $(top_srcdir)/include/k5-err.h \
- $(top_srcdir)/include/k5-gmt_mktime.h $(top_srcdir)/include/k5-int-pkinit.h \
- $(top_srcdir)/include/k5-int.h $(top_srcdir)/include/k5-platform.h \
- $(top_srcdir)/include/k5-plugin.h $(top_srcdir)/include/k5-thread.h \
- $(top_srcdir)/include/k5-trace.h $(top_srcdir)/include/krb5.h \
- $(top_srcdir)/include/krb5/authdata_plugin.h $(top_srcdir)/include/krb5/plugin.h \
+ $(BUILDTOP)/include/profile.h $(COM_ERR_DEPS) $(top_srcdir)/include/k5-buf.h \
+ $(top_srcdir)/include/k5-err.h $(top_srcdir)/include/k5-gmt_mktime.h \
+ $(top_srcdir)/include/k5-int-pkinit.h $(top_srcdir)/include/k5-int.h \
+ $(top_srcdir)/include/k5-platform.h $(top_srcdir)/include/k5-plugin.h \
+ $(top_srcdir)/include/k5-thread.h $(top_srcdir)/include/k5-trace.h \
+ $(top_srcdir)/include/krb5.h $(top_srcdir)/include/krb5/authdata_plugin.h \
+ $(top_srcdir)/include/krb5/locate_plugin.h $(top_srcdir)/include/krb5/plugin.h \
$(top_srcdir)/include/port-sockets.h $(top_srcdir)/include/socket-utils.h \
- t_trace.c
+ os-proto.h t_trace.c
diff --git a/src/lib/krb5/os/os-proto.h b/src/lib/krb5/os/os-proto.h
index 83c9d65f92..78f2caa548 100644
--- a/src/lib/krb5/os/os-proto.h
+++ b/src/lib/krb5/os/os-proto.h
@@ -55,6 +55,19 @@ struct serverlist {
};
#define SERVERLIST_INIT { NULL, 0 }
+struct remote_address {
+ int family;
+ int type;
+ socklen_t len;
+ struct sockaddr_storage saddr;
+};
+
+struct sendto_callback_info {
+ int (*pfn_callback)(SOCKET fd, void *data, krb5_data *message);
+ void (*pfn_cleanup)(void *data, krb5_data *message);
+ void *data;
+};
+
krb5_error_code k5_locate_server(krb5_context, const krb5_data *realm,
struct serverlist *,
enum locate_service_type svc, int socktype);
diff --git a/src/lib/krb5/os/sendto_kdc.c b/src/lib/krb5/os/sendto_kdc.c
index 04c9a7ae64..cd1d03e375 100644
--- a/src/lib/krb5/os/sendto_kdc.c
+++ b/src/lib/krb5/os/sendto_kdc.c
@@ -55,6 +55,61 @@
#define DEFAULT_UDP_PREF_LIMIT 1465
#define HARD_UDP_LIMIT 32700 /* could probably do 64K-epsilon ? */
+/* Select state flags. */
+#define SSF_READ 0x01
+#define SSF_WRITE 0x02
+#define SSF_EXCEPTION 0x04
+
+/* Since fd_set is large on some platforms (8K on AIX 5.2), this probably
+ * shouldn't be allocated in automatic storage. */
+struct select_state {
+#ifdef USE_POLL
+ struct pollfd fds[MAX_POLLFDS];
+#else
+ int max;
+ fd_set rfds, wfds, xfds;
+#endif
+ int nfds;
+ struct timeval end_time; /* magic: tv_sec==0 => never time out */
+};
+
+static const char *const state_strings[] = {
+ "INITIALIZING", "CONNECTING", "WRITING", "READING", "FAILED"
+};
+
+/* connection states */
+enum conn_states { INITIALIZING, CONNECTING, WRITING, READING, FAILED };
+struct incoming_krb5_message {
+ size_t bufsizebytes_read;
+ size_t bufsize;
+ char *buf;
+ char *pos;
+ unsigned char bufsizebytes[4];
+ size_t n_left;
+};
+
+struct conn_state {
+ SOCKET fd;
+ krb5_error_code err;
+ enum conn_states state;
+ unsigned int is_udp : 1;
+ int (*service)(krb5_context context, struct conn_state *,
+ struct select_state *, int);
+ struct remote_address addr;
+ struct {
+ struct {
+ sg_buf sgbuf[2];
+ sg_buf *sgp;
+ int sg_count;
+ unsigned char msg_len_buf[4];
+ } out;
+ struct incoming_krb5_message in;
+ } x;
+ krb5_data callback_buffer;
+ size_t server_index;
+ struct conn_state *next;
+};
+
#undef DEBUG
#ifdef DEBUG
@@ -411,18 +466,6 @@ cleanup:
* connections already in progress
*/
-#include "cm.h"
-
-/*
- * Currently only sendto_kdc.c knows how to use poll(); the other candidate
- * user, lib/apputils/net-server.c, is stuck using select() for the moment
- * since it is entangled with the RPC library. The following cm_* functions
- * are not fully generic, are O(n^2) in the poll case, and are limited to
- * handling 1024 connections (in order to maintain a constant-sized selstate).
- * More rearchitecting would be appropriate before extending this support to
- * the KDC and kadmind.
- */
-
static void
cm_init_selstate(struct select_state *selstate)
{
@@ -518,7 +561,7 @@ cm_select_or_poll(const struct select_state *in, struct select_state *out,
if (in->end_time.tv_sec == 0)
timeout = -1;
else {
- e = k5_getcurtime(&now);
+ e = gettimeofday(&now, NULL);
if (e)
return e;
timeout = (in->end_time.tv_sec - now.tv_sec) * 1000 +
@@ -528,15 +571,42 @@ cm_select_or_poll(const struct select_state *in, struct select_state *out,
return 0;
}
}
- /* We don't need a separate copy of the selstate for poll, but use one
- * anyone for consistency with the select wrapper. */
+ /* We don't need a separate copy of the selstate for poll, but use one for
+ * consistency with how we use select. */
*out = *in;
*sret = poll(out->fds, out->nfds, timeout);
e = SOCKET_ERRNO;
return (*sret < 0) ? e : 0;
#else
- /* Use the select wrapper from cm.c. */
- return krb5int_cm_call_select(in, out, sret);
+ struct timeval now, *timo;
+ krb5_error_code e;
+
+ *out = *in;
+ e = gettimeofday(&now, NULL);
+ if (e)
+ return e;
+ if (out->end_time.tv_sec == 0) {
+ timo = 0;
+ } else {
+ timo = &out->end_time;
+ out->end_time.tv_sec -= now.tv_sec;
+ out->end_time.tv_usec -= now.tv_usec;
+ if (out->end_time.tv_usec < 0) {
+ out->end_time.tv_usec += 1000000;
+ out->end_time.tv_sec--;
+ }
+ if (out->end_time.tv_sec < 0) {
+ *sret = 0;
+ return 0;
+ }
+ }
+
+ *sret = select(out->max, &out->rfds, &out->wfds, &out->xfds, timo);
+ e = SOCKET_ERRNO;
+
+ if (*sret < 0)
+ return e;
+ return 0;
#endif
}
@@ -820,7 +890,7 @@ start_connection(krb5_context context, struct conn_state *state,
*/
if (callback_info) {
- e = callback_info->pfn_callback(state, callback_info->context,
+ e = callback_info->pfn_callback(state->fd, callback_info->data,
&state->callback_buffer);
if (e != 0) {
dprint("callback failed: %m\n", e);
@@ -1155,7 +1225,7 @@ service_fds(krb5_context context, struct select_state *selstate, int interval,
*winner_out = NULL;
- e = k5_getcurtime(&now);
+ e = gettimeofday(&now, NULL);
if (e)
return 1;
selstate->end_time = now;
@@ -1344,7 +1414,7 @@ cleanup:
if (state->state == READING && state->x.in.buf != udpbuf)
free(state->x.in.buf);
if (callback_info) {
- callback_info->pfn_cleanup(callback_info->context,
+ callback_info->pfn_cleanup(callback_info->data,
&state->callback_buffer);
}
free(state);
diff --git a/src/lib/krb5/os/t_trace.c b/src/lib/krb5/os/t_trace.c
index ed53181bae..36044f5d5e 100644
--- a/src/lib/krb5/os/t_trace.c
+++ b/src/lib/krb5/os/t_trace.c
@@ -38,7 +38,7 @@
#define TEST
#include "k5-int.h"
-#include "cm.h"
+#include "os-proto.h"
const char *prog;
diff --git a/src/lib/krb5/os/trace.c b/src/lib/krb5/os/trace.c
index fcfc70b442..525742cb84 100644
--- a/src/lib/krb5/os/trace.c
+++ b/src/lib/krb5/os/trace.c
@@ -39,7 +39,6 @@
#include "k5-int.h"
#include "os-proto.h"
-#include "cm.h"
#ifndef DISABLE_TRACING