1/*++
2/* NAME
3/*	stream_pass_connect 3
4/* SUMMARY
5/*	connect to stream-based descriptor listener
6/* SYNOPSIS
7/*	#include <connect.h>
8/*
9/*	int	stream_pass_connect(path, block_mode, timeout)
10/*	const char *path;
11/*	int	block_mode;
12/*	int	timeout;
13/* DESCRIPTION
14/*	stream_pass_connect() connects to a stream-based descriptor
15/*	listener for the specified pathname, and returns the resulting
16/*	file descriptor. The next operation is to stream_send_fd()
17/*	a file descriptor and then close() the connection once the
18/*	server has received the file descriptor.
19/*
20/*	Arguments:
21/* .IP path
22/*	Null-terminated string with listener endpoint name.
23/* .IP block_mode
24/*	Either NON_BLOCKING for a non-blocking stream, or BLOCKING for
25/*	blocking mode. However, a stream connection succeeds or fails
26/*	immediately.
27/* .IP timeout
28/*	This argument is ignored; it is present for compatibility with
29/*	other interfaces. Stream connections succeed or fail immediately.
30/* DIAGNOSTICS
31/*	The result is -1 in case the connection could not be made.
32/*	Fatal errors: other system call failures.
33/* LICENSE
34/* .ad
35/* .fi
36/*	The Secure Mailer license must be distributed with this software.
37/* AUTHOR(S)
38/*	Wietse Venema
39/*	IBM T.J. Watson Research
40/*	P.O. Box 704
41/*	Yorktown Heights, NY 10598, USA
42/*--*/
43
44/* System library. */
45
46#include <sys_defs.h>
47
48#ifdef STREAM_CONNECTIONS
49
50#include <sys/stat.h>
51#include <unistd.h>
52#include <fcntl.h>
53#include <errno.h>
54
55#endif
56
57/* Utility library. */
58
59#include <msg.h>
60#include <connect.h>
61
62/* stream_pass_connect - connect to stream-based descriptor listener */
63
64int     stream_pass_connect(const char *path, int block_mode, int unused_timeout)
65{
66#ifdef STREAM_CONNECTIONS
67    const char *myname = "stream_pass_connect";
68    int     fifo;
69
70    /*
71     * The requested file system object must exist, otherwise we can't reach
72     * the server.
73     */
74    if ((fifo = open(path, O_WRONLY | O_NONBLOCK, 0)) < 0)
75	return (-1);
76
77    /*
78     * This is for {unix,inet}_connect() compatibility.
79     */
80    non_blocking(fifo, block_mode);
81
82    return (fifo);
83#else
84    msg_fatal("stream connections are not implemented");
85#endif
86}
87