summaryrefslogtreecommitdiff
path: root/monitor_fdpass.c
diff options
context:
space:
mode:
authorBen Lindstrom <mouring@eviladmin.org>2002-03-22 02:30:41 +0000
committerBen Lindstrom <mouring@eviladmin.org>2002-03-22 02:30:41 +0000
commit7a2073c50b92c053594d48a651ebafae052a71ed (patch)
tree7cfceb925262a07a356b0667e19f33eec497b602 /monitor_fdpass.c
parent0f345f5ee1e71e1e9f8780ec13b2da23b6a9f7f8 (diff)
- provos@cvs.openbsd.org 2002/03/18 17:50:31
[auth-bsdauth.c auth-options.c auth-rh-rsa.c auth-rsa.c auth-skey.c auth.h auth1.c auth2-chall.c auth2.c kex.c kex.h kexdh.c kexgex.c servconf.c session.h servconf.h serverloop.c session.c sshd.c] integrate privilege separated openssh; its turned off by default for now. work done by me and markus@ applied, but outside of ensure that smaller code bits migrated with their owners.. no work was tried to 'fix' it to work. =) Later project!
Diffstat (limited to 'monitor_fdpass.c')
-rw-r--r--monitor_fdpass.c86
1 files changed, 86 insertions, 0 deletions
diff --git a/monitor_fdpass.c b/monitor_fdpass.c
new file mode 100644
index 000000000..7785535bb
--- /dev/null
+++ b/monitor_fdpass.c
@@ -0,0 +1,86 @@
1/*
2 * Copyright 2001 Niels Provos <provos@citi.umich.edu>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#include "includes.h"
27RCSID("$OpenBSD: monitor_fdpass.c,v 1.1 2002/03/18 17:27:22 provos Exp $");
28
29#include <sys/uio.h>
30
31#include "log.h"
32#include "monitor_fdpass.h"
33
34void
35mm_send_fd(int socket, int fd)
36{
37 struct msghdr msg;
38 char tmp[CMSG_SPACE(sizeof(int))];
39 struct cmsghdr *cmsg;
40 struct iovec vec;
41 char ch;
42
43 memset(&msg, 0, sizeof(msg));
44 msg.msg_control = (caddr_t)tmp;
45 msg.msg_controllen = CMSG_LEN(sizeof(int));
46 cmsg = CMSG_FIRSTHDR(&msg);
47 cmsg->cmsg_len = CMSG_LEN(sizeof(int));
48 cmsg->cmsg_level = SOL_SOCKET;
49 cmsg->cmsg_type = SCM_RIGHTS;
50 *(int *)CMSG_DATA(cmsg) = fd;
51
52 vec.iov_base = &ch;
53 vec.iov_len = 1;
54 msg.msg_iov = &vec;
55 msg.msg_iovlen = 1;
56
57 if (sendmsg(socket, &msg, 0) == -1)
58 fatal("%s: sendmsg(%d)", __FUNCTION__, fd);
59}
60
61int
62mm_receive_fd(int socket)
63{
64 struct msghdr msg;
65 char tmp[CMSG_SPACE(sizeof(int))];
66 struct cmsghdr *cmsg;
67 struct iovec vec;
68 char ch;
69
70 memset(&msg, 0, sizeof(msg));
71 vec.iov_base = &ch;
72 vec.iov_len = 1;
73 msg.msg_iov = &vec;
74 msg.msg_iovlen = 1;
75 msg.msg_control = tmp;
76 msg.msg_controllen = sizeof(tmp);
77
78 if (recvmsg(socket, &msg, 0) == -1)
79 fatal("%s: recvmsg", __FUNCTION__);
80
81 cmsg = CMSG_FIRSTHDR(&msg);
82 if (cmsg->cmsg_type != SCM_RIGHTS)
83 fatal("%s: expected type %d got %d", __FUNCTION__,
84 SCM_RIGHTS, cmsg->cmsg_type);
85 return (*(int *)CMSG_DATA(cmsg));
86}