libcli: Add tstream_npa_socketpair() function.
authorAndreas Schneider <asn@samba.org>
Thu, 19 Sep 2013 12:52:22 +0000 (14:52 +0200)
committerStefan Metzmacher <metze@samba.org>
Tue, 29 Oct 2013 14:31:45 +0000 (15:31 +0100)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
libcli/named_pipe_auth/npa_tstream.c
libcli/named_pipe_auth/npa_tstream.h

index c2eb7bf7148d73f14992e9dcd0ad46f2d5bd3abf..2728e0478a369c9fbb6d4aad7482a969255d833e 100644 (file)
@@ -1442,3 +1442,60 @@ int _tstream_npa_accept_existing_recv(struct tevent_req *req,
        tevent_req_received(req);
        return 0;
 }
+
+
+/* SOCKETPAIR for internal rpc communication */
+
+/* file_type is FILE_TYPE_BYTE_MODE_PIPE or FILE_TYPE_MESSAGE_MODE_PIPE */
+int _tstream_npa_socketpair(uint16_t file_type,
+                           TALLOC_CTX *mem_ctx1,
+                           struct tstream_context **pstream1,
+                           TALLOC_CTX *mem_ctx2,
+                           struct tstream_context **pstream2,
+                           const char *location)
+{
+       struct tstream_context *stream1 = NULL;
+       struct tstream_context *stream2 = NULL;
+       int fds[2];
+       int fd1;
+       int fd2;
+       int rc;
+
+       rc = socketpair(AF_UNIX, SOCK_STREAM, 0, fds);
+       if (rc == -1) {
+               return -1;
+       }
+       fd1 = fds[0];
+       fd2 = fds[1];
+
+       rc = _tstream_npa_existing_socket(mem_ctx1,
+                                         fd1,
+                                         file_type,
+                                         &stream1,
+                                         location);
+       if (rc == -1) {
+               int sys_errno = errno;
+               close(fd1);
+               close(fd2);
+               errno = sys_errno;
+               return -1;
+       }
+
+       rc = _tstream_npa_existing_socket(mem_ctx2,
+                                         fd2,
+                                         file_type,
+                                         &stream2,
+                                         location);
+       if (rc == -1) {
+               int sys_errno = errno;
+               talloc_free(stream1);
+               close(fd2);
+               errno = sys_errno;
+               return -1;
+       }
+
+       *pstream1 = stream1;
+       *pstream2 = stream2;
+
+       return 0;
+}
index 1d85de7d911ecb3ece1bc0865cdd1a1b28dc8061..e7a1ac76d43bf6b34d8659a65faa9d2072b6b577 100644 (file)
@@ -117,4 +117,14 @@ int _tstream_npa_accept_existing_recv(struct tevent_req *req,
                                          session_info, \
                                          __location__)
 
+int _tstream_npa_socketpair(uint16_t file_type,
+                           TALLOC_CTX *mem_ctx1,
+                           struct tstream_context **pstream1,
+                           TALLOC_CTX *mem_ctx2,
+                           struct tstream_context **pstream2,
+                           const char *location);
+#define tstream_npa_socketpair(ft, mem1, stream1, mem2, stream2) \
+       _tstream_npa_socketpair(ft, mem1, stream1, mem2, stream2, \
+                               __location__)
+
 #endif /* NPA_TSTREAM_H */