68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross * This file and its contents are supplied under the terms of the
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross * Common Development and Distribution License ("CDDL"), version 1.0.
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross * You may only use this file in accordance with the terms of version
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross * 1.0 of the CDDL.
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross * A full copy of the text of the CDDL should have accompanied this
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross * source. A copy of the CDDL is also available via the Internet at
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross * This is the named pipe service for smbd.
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Rossstatic void *pipesvc_listener(void *);
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Rossstatic void *pipesvc_worker(void *);
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Rossstatic int pipe_send(ndr_pipe_t *, void *, size_t);
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Rossstatic int pipe_recv(ndr_pipe_t *, void *, size_t);
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Rossuint16_t pipe_max_msgsize = SMB_PIPE_MAX_MSGSIZE;
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross * Allow more opens on SRVSVC because that's used by many clients
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross * to get the share list, etc.
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross * Allocating ndr_pipe_t + smb_netuserinfo_t as one.
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross * We could just make that part of ndr_pipe_t, but
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross * that struct is opaque to libmlrpc.
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross len = sizeof (*np) + sizeof (smb_netuserinfo_t);
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross * Create the smbd opipe door service.
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross * Returns the door descriptor on success. Otherwise returns -1.
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross return (-1);
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross (void) pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross for (i = 0; i < NLISTENERS; i++) {
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross smb_config_getbool(SMB_CI_PRINT_ENABLE) == B_FALSE)
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross rc = pthread_create(&tid, &tattr, pipesvc_listener, pl);
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross for (i = 0; i < NLISTENERS; i++) {
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross (void) pthread_kill(pipe_listeners[i].tid, SIGTERM);
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Rossstatic void *
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross smbd_report("pipesvc_listener, so_create: %d", errno);
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross (void) snprintf(sa.sun_path, sizeof (sa.sun_path),
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross /* Bind it to a listening name. */
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross if (bind(listen_fd, (struct sockaddr *)&sa, sizeof (sa)) < 0) {
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross smbd_report("pipesvc_listener, so_bind: %d", errno);
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross smbd_report("pipesvc_listener, listen: %d", errno);
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross newfd = accept(listen_fd, (struct sockaddr *)&sa, &snlen);
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross /* normal termination */
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross smbd_report("pipesvc_listener, accept: %d", err);
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross rc = pthread_create(&tid, NULL, pipesvc_worker, np);
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross smbd_report("pipesvc_listener, pthread_create: %d",
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross /* Note: np_free in pipesvc_worker */
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Rossstatic void *
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross if (pipesvc_workers_cur >= pipesvc_workers_max ||
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross (void) send(np->np_fid, &status, sizeof (status), 0);
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross * The smbsrv kmod sends us one initial message containing an
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross * XDR encoded smb_netuserinfo_t that we read and decode here,
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross * all unbeknownst to libmlrpc.
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross * Might be nice to enhance getpeerucred() so it can give us
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross * all the info smb_netuserinfo_t carries, and then use that,
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross * which would allow using a more generic RPC service.
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross xdrmem_create(&xdrs, buf, phdr.ph_uilen, XDR_DECODE);
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross * Later, could disallow opens of some pipes by
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross * anonymous users, etc. For now, reply "OK".
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross * Run the RPC service loop worker, which
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross * returns when it sees the pipe close.
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross /* Cleanup what came in by varg. */
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross * These are the transport get/put callback functions provided
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross * via the ndr_pipe_t object to the libmlrpc`ndr_pipe_worker.
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross * These are called only with known PDU sizes and should
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross * loop as needed to transfer the entire message.
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross while (len > 0) {
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross while (len > 0) {