]> andersk Git - gssapi-openssh.git/blobdiff - openssh/monitor_fdpass.c
update to http://www.psc.edu/networking/projects/hpn-ssh/openssh-4.7p1-hpn13v1.diff.gz
[gssapi-openssh.git] / openssh / monitor_fdpass.c
index 0d7628fa247b3a792d90c096931679777ff5db4a..9f8e9cd550fe0764ee8bafdf23e0aca2e1cadcec 100644 (file)
@@ -1,3 +1,4 @@
+/* $OpenBSD: monitor_fdpass.c,v 1.12 2006/08/03 03:34:42 deraadt Exp $ */
 /*
  * Copyright 2001 Niels Provos <provos@citi.umich.edu>
  * All rights reserved.
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: monitor_fdpass.c,v 1.3 2002/06/04 23:05:49 markus Exp $");
 
+#include <sys/types.h>
+#include <sys/socket.h>
 #include <sys/uio.h>
+#ifdef HAVE_SYS_UN_H
+#include <sys/un.h>
+#endif
+
+#include <errno.h>
+#include <string.h>
+#include <stdarg.h>
 
 #include "log.h"
 #include "monitor_fdpass.h"
 
 void
-mm_send_fd(int socket, int fd)
+mm_send_fd(int sock, int fd)
 {
 #if defined(HAVE_SENDMSG) && (defined(HAVE_ACCRIGHTS_IN_MSGHDR) || defined(HAVE_CONTROL_IN_MSGHDR))
        struct msghdr msg;
        struct iovec vec;
        char ch = '\0';
-       int n;
+       ssize_t n;
 #ifndef HAVE_ACCRIGHTS_IN_MSGHDR
        char tmp[CMSG_SPACE(sizeof(int))];
        struct cmsghdr *cmsg;
@@ -63,12 +72,12 @@ mm_send_fd(int socket, int fd)
        msg.msg_iov = &vec;
        msg.msg_iovlen = 1;
 
-       if ((n = sendmsg(socket, &msg, 0)) == -1)
+       if ((n = sendmsg(sock, &msg, 0)) == -1)
                fatal("%s: sendmsg(%d): %s", __func__, fd,
                    strerror(errno));
        if (n != 1)
-               fatal("%s: sendmsg: expected sent 1 got %d",
-                   __func__, n);
+               fatal("%s: sendmsg: expected sent 1 got %ld",
+                   __func__, (long)n);
 #else
        fatal("%s: UsePrivilegeSeparation=yes not supported",
            __func__);
@@ -76,13 +85,14 @@ mm_send_fd(int socket, int fd)
 }
 
 int
-mm_receive_fd(int socket)
+mm_receive_fd(int sock)
 {
 #if defined(HAVE_RECVMSG) && (defined(HAVE_ACCRIGHTS_IN_MSGHDR) || defined(HAVE_CONTROL_IN_MSGHDR))
        struct msghdr msg;
        struct iovec vec;
+       ssize_t n;
        char ch;
-       int fd, n;
+       int fd;
 #ifndef HAVE_ACCRIGHTS_IN_MSGHDR
        char tmp[CMSG_SPACE(sizeof(int))];
        struct cmsghdr *cmsg;
@@ -101,20 +111,24 @@ mm_receive_fd(int socket)
        msg.msg_controllen = sizeof(tmp);
 #endif
 
-       if ((n = recvmsg(socket, &msg, 0)) == -1)
+       if ((n = recvmsg(sock, &msg, 0)) == -1)
                fatal("%s: recvmsg: %s", __func__, strerror(errno));
        if (n != 1)
-               fatal("%s: recvmsg: expected received 1 got %d",
-                   __func__, n);
+               fatal("%s: recvmsg: expected received 1 got %ld",
+                   __func__, (long)n);
 
 #ifdef HAVE_ACCRIGHTS_IN_MSGHDR
        if (msg.msg_accrightslen != sizeof(fd))
                fatal("%s: no fd", __func__);
 #else
        cmsg = CMSG_FIRSTHDR(&msg);
+       if (cmsg == NULL)
+               fatal("%s: no message header", __func__);
+#ifndef BROKEN_CMSG_TYPE
        if (cmsg->cmsg_type != SCM_RIGHTS)
                fatal("%s: expected type %d got %d", __func__,
                    SCM_RIGHTS, cmsg->cmsg_type);
+#endif
        fd = (*(int *)CMSG_DATA(cmsg));
 #endif
        return fd;
This page took 0.053258 seconds and 4 git commands to generate.