svn rev #3275: trunk/bsd/
ghudson@MIT.EDU
ghudson at MIT.EDU
Mon Nov 16 05:27:04 EST 2009
Commit By: ghudson
Log Message:
Stop using krb5_read_message, krb5_write_message, and krb5_net_read
in the bsd applications. They are simple functions, so just define
them ourselves in kcmd.c.
Changed Files:
U trunk/bsd/defines.h
U trunk/bsd/kcmd.c
U trunk/bsd/krlogind.c
U trunk/bsd/krshd.c
Modified: trunk/bsd/defines.h
===================================================================
--- trunk/bsd/defines.h 2009-11-13 21:04:39 UTC (rev 3274)
+++ trunk/bsd/defines.h 2009-11-16 10:27:04 UTC (rev 3275)
@@ -21,6 +21,8 @@
KCMD_UNKNOWN_PROTOCOL
};
+extern int read_message (int fd, krb5_data *inbuf);
+
extern int kcmd (int *sock, char **ahost, int /* u_short */ rport,
char *locuser, char *remuser, char *cmd,
int *fd2p, char *service, char *realm,
Modified: trunk/bsd/kcmd.c
===================================================================
--- trunk/bsd/kcmd.c 2009-11-13 21:04:39 UTC (rev 3274)
+++ trunk/bsd/kcmd.c 2009-11-16 10:27:04 UTC (rev 3275)
@@ -73,6 +73,7 @@
#include <sys/file.h>
#include <sys/socket.h>
#include <sys/stat.h>
+#include <sys/uio.h>
#ifdef _AIX
#include <sys/select.h>
#endif
@@ -169,7 +170,83 @@
#endif /* POSIX_SIGNALS */
}
+/*
+ * Read len bytes from fd into buf, continuing after partial reads or
+ * interrupts.
+ */
+static ssize_t
+full_read(int fd, void *buf, int len)
+{
+ ssize_t cc, len2 = 0;
+ char *ptr = buf;
+
+ do {
+ cc = read(fd, ptr, len);
+ if (cc < 0) {
+ if (errno == EINTR)
+ continue;
+ return cc;
+ } else if (cc == 0) {
+ return len2;
+ } else {
+ ptr += cc;
+ len2 += cc;
+ len -= cc;
+ }
+ } while (len > 0);
+ return len2;
+}
+
+/* Write outbuf->length in four-byte binary, followed by outbuf->data. */
static int
+write_message(int fd, krb5_data *outbuf)
+{
+ krb5_int32 len;
+ struct iovec iov[2];
+
+ len = htonl(outbuf->length);
+ iov[0].iov_base = &len;
+ iov[0].iov_len = 4;
+ iov[1].iov_base = outbuf->data;
+ iov[1].iov_len = outbuf->length;
+ if (writev(fd, iov, 2) < 0)
+ return errno;
+ return 0;
+}
+
+/* Read a four-byte length, allocate that much data, and store into inbuf. */
+int
+read_message(int fd, krb5_data *inbuf)
+{
+ krb5_int32 len;
+ int len2, ilen;
+ char *buf = NULL;
+
+ inbuf->data = NULL;
+ inbuf->length = 0;
+
+ if ((len2 = full_read(fd, &len, 4)) != 4)
+ return (len2 < 0) ? errno : ECONNABORTED;
+ len = ntohl(len);
+
+ if ((len & VALID_UINT_BITS) != (krb5_ui_4) len) /* Overflow size_t??? */
+ return ENOMEM;
+
+ inbuf->length = ilen = (int) len;
+ if (ilen) {
+ if (!(buf = malloc(inbuf->length))) {
+ return ENOMEM;
+ }
+ if ((len2 = full_read(fd, buf, ilen)) != ilen) {
+ free(buf);
+ return (len2 < 0) ? errno : ECONNABORTED;
+ }
+ }
+ inbuf->data = buf;
+ return(0);
+}
+
+static int
kcmd_connect (int *sp, int *addrfamilyp, struct sockaddr_in *sockinp,
char *hname, char **host_save, unsigned int rport, int *lportp,
struct sockaddr_in *laddrp)
@@ -560,13 +637,13 @@
}
/* Send forwarded credentials */
- status = krb5_write_message(bsd_context, (krb5_pointer)&s, &outbuf);
+ status = write_message(s, &outbuf);
if (status)
goto bad2;
}
else { /* Dummy write to signal no forwarding */
outbuf.length = 0;
- status = krb5_write_message(bsd_context, (krb5_pointer)&s, &outbuf);
+ status = write_message(s, &outbuf);
if (status)
goto bad2;
}
@@ -847,7 +924,7 @@
}
while (1) {
- cc = krb5_net_read(bsd_context, fd, &c, 1);
+ cc = full_read(fd, &c, 1);
/* we should check for non-blocking here, but we'd have
to make it save partial reads as well. */
if (cc <= 0) return cc; /* read error */
@@ -857,11 +934,11 @@
}
rd_len = c;
- if ((cc = krb5_net_read(bsd_context, fd, &c, 1)) != 1) return 0;
+ if ((cc = full_read(fd, &c, 1)) != 1) return 0;
rd_len = (rd_len << 8) | c;
- if ((cc = krb5_net_read(bsd_context, fd, &c, 1)) != 1) return 0;
+ if ((cc = full_read(fd, &c, 1)) != 1) return 0;
rd_len = (rd_len << 8) | c;
- if ((cc = krb5_net_read(bsd_context, fd, &c, 1)) != 1) return 0;
+ if ((cc = full_read(fd, &c, 1)) != 1) return 0;
rd_len = (rd_len << 8) | c;
ret = krb5_c_encrypt_length(bsd_context, keyblock->enctype,
@@ -877,7 +954,7 @@
errno = EIO;
return(-1);
}
- if ((cc = krb5_net_read(bsd_context, fd, desinbuf.data, net_len)) != net_len) {
+ if ((cc = full_read(fd, desinbuf.data, net_len)) != (ssize_t) net_len) {
/* probably out of sync */
errno = EIO;
return(-1);
Modified: trunk/bsd/krlogind.c
===================================================================
--- trunk/bsd/krlogind.c 2009-11-13 21:04:39 UTC (rev 3274)
+++ trunk/bsd/krlogind.c 2009-11-16 10:27:04 UTC (rev 3275)
@@ -1415,7 +1415,7 @@
if ((status = krb5_unparse_name(bsd_context, client, &krusername)))
return status;
- if ((status = krb5_read_message(bsd_context, (krb5_pointer)&netf, &inbuf)))
+ if ((status = read_message(netf, &inbuf)))
fatal(netf, "Error reading message");
if ((inbuf.length) && /* Forwarding being done, read creds */
Modified: trunk/bsd/krshd.c
===================================================================
--- trunk/bsd/krshd.c 2009-11-13 21:04:39 UTC (rev 3274)
+++ trunk/bsd/krshd.c 2009-11-16 10:27:04 UTC (rev 3275)
@@ -1874,8 +1874,7 @@
* key here, and we do not want krb5_free_ticket() to destroy it. */
ticket->enc_part2->session = 0;
- if ((status = krb5_read_message(bsd_context, (krb5_pointer)&netfd,
- &inbuf))) {
+ if ((status = read_message(netfd, &inbuf))) {
error("Error reading message: %s\n", error_message(status));
exit(1);
}
More information about the Krb5-appl-commits
mailing list