Deleted Added
full compact
bundle.c (37019) bundle.c (37054)
1/*-
2 * Copyright (c) 1998 Brian Somers <brian@Awfulhak.org>
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 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
1/*-
2 * Copyright (c) 1998 Brian Somers <brian@Awfulhak.org>
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 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $Id: bundle.c,v 1.18 1998/06/16 19:40:24 brian Exp $
26 * $Id: bundle.c,v 1.19 1998/06/16 19:40:34 brian Exp $
27 */
28
29#include <sys/param.h>
30#include <sys/socket.h>
31#include <netinet/in.h>
32#include <net/if.h>
33#include <arpa/inet.h>
34#include <net/route.h>

--- 1409 unchanged lines hidden (view full) ---

1444 log_Printf(LogERROR, "Failed recvmsg: Got %d, not %d\n", f, expect);
1445 while (niov--)
1446 free(iov[niov].iov_base);
1447 close(s);
1448 return;
1449 }
1450
1451 write(s, "!", 1); /* ACK */
27 */
28
29#include <sys/param.h>
30#include <sys/socket.h>
31#include <netinet/in.h>
32#include <net/if.h>
33#include <arpa/inet.h>
34#include <net/route.h>

--- 1409 unchanged lines hidden (view full) ---

1444 log_Printf(LogERROR, "Failed recvmsg: Got %d, not %d\n", f, expect);
1445 while (niov--)
1446 free(iov[niov].iov_base);
1447 close(s);
1448 return;
1449 }
1450
1451 write(s, "!", 1); /* ACK */
1452 close(s);
1452
1453
1453 if (cmsg->cmsg_type == SCM_RIGHTS) {
1454 /* We've successfully received an open file descriptor through our socket */
1455 log_Printf(LogDEBUG, "Receiving non-tty device\n");
1456 link_fd = *(int *)CMSG_DATA(cmsg);
1457 } else {
1458 /* It's a ``controlling'' tty device via CATPROG */
1459 log_Printf(LogDEBUG, "Receiving tty device\n");
1460 link_fd = dup(s);
1461 fcntl(link_fd, F_SETFL, fcntl(link_fd, F_GETFL, 0) | O_NONBLOCK);
1454 if (cmsg->cmsg_type != SCM_RIGHTS) {
1455 log_Printf(LogERROR, "Recvmsg: no descriptor received !\n");
1456 while (niov--)
1457 free(iov[niov].iov_base);
1458 return;
1462 }
1463
1459 }
1460
1461 /* We've successfully received an open file descriptor through our socket */
1462 log_Printf(LogDEBUG, "Receiving device descriptor\n");
1463 link_fd = *(int *)CMSG_DATA(cmsg);
1464
1464 if (strncmp(Version, iov[0].iov_base, iov[0].iov_len)) {
1465 log_Printf(LogWARN, "Cannot receive datalink, incorrect version"
1466 " (\"%.*s\", not \"%s\")\n", (int)iov[0].iov_len,
1467 iov[0].iov_base, Version);
1468 close(link_fd);
1469 while (niov--)
1470 free(iov[niov].iov_base);
1471 return;
1472 }
1473
1474 niov = 1;
1475 dl = iov2datalink(bundle, iov, &niov, sizeof iov / sizeof *iov, link_fd);
1476 if (dl) {
1477 bundle_DatalinkLinkin(bundle, dl);
1478 datalink_AuthOk(dl);
1479 } else
1480 close(link_fd);
1481
1482 free(iov[0].iov_base);
1465 if (strncmp(Version, iov[0].iov_base, iov[0].iov_len)) {
1466 log_Printf(LogWARN, "Cannot receive datalink, incorrect version"
1467 " (\"%.*s\", not \"%s\")\n", (int)iov[0].iov_len,
1468 iov[0].iov_base, Version);
1469 close(link_fd);
1470 while (niov--)
1471 free(iov[niov].iov_base);
1472 return;
1473 }
1474
1475 niov = 1;
1476 dl = iov2datalink(bundle, iov, &niov, sizeof iov / sizeof *iov, link_fd);
1477 if (dl) {
1478 bundle_DatalinkLinkin(bundle, dl);
1479 datalink_AuthOk(dl);
1480 } else
1481 close(link_fd);
1482
1483 free(iov[0].iov_base);
1483 close(s);
1484}
1485
1486void
1487bundle_SendDatalink(struct datalink *dl, int s, struct sockaddr_un *sun)
1488{
1489 char cmsgbuf[sizeof(struct cmsghdr) + sizeof(int)], ack;
1490 struct cmsghdr *cmsg = (struct cmsghdr *)cmsgbuf;
1491 struct msghdr msg;

--- 211 unchanged lines hidden ---
1484}
1485
1486void
1487bundle_SendDatalink(struct datalink *dl, int s, struct sockaddr_un *sun)
1488{
1489 char cmsgbuf[sizeof(struct cmsghdr) + sizeof(int)], ack;
1490 struct cmsghdr *cmsg = (struct cmsghdr *)cmsgbuf;
1491 struct msghdr msg;

--- 211 unchanged lines hidden ---