b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * CDDL HEADER START
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * The contents of this file are subject to the terms of the
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Common Development and Distribution License (the "License").
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * You may not use this file except in compliance with the License.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * See the License for the specific language governing permissions
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * and limitations under the License.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * When distributing Covered Code, include this CDDL HEADER in each
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * If applicable, add the following below this CDDL HEADER, with the
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * fields enclosed by brackets "[]" replaced with your own identifying
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * information: Portions Copyright [yyyy] [name of copyright owner]
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * CDDL HEADER END
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Special version of smb_door_dispatch() for the
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * "fake" smbsrv (running in user space).
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * This is called via function pointer from
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * smbsrv: smb_kdoor_upcall()
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * The args and response go RPC encoded, just so we can
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * borrow some of the common doorsvc code, even though
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * there's no need for RPC encoding in this scenario.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * da->da_arg.data_ptr = (arg data, xdr encoded)
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * da->da_arg.data_size = (arg data len)
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross syslog(LOG_DEBUG, "fksmbd_door_dispatch: bad args");
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross return (-1);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross if (smb_doorhdr_decode(hdr, (uint8_t *)argp, hdr_size) == -1) {
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross syslog(LOG_DEBUG, "smbd_door_dispatch: header decode failed");
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross return (-1);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross syslog(LOG_DEBUG, "fksmbd_door_dispatch: invalid header");
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross return (-1);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross dop_arg.opname = smb_doorhdr_opname(hdr->dh_op);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * ASYNC_RESPONSE is not used here.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross syslog(LOG_DEBUG, "fksmbd_door_dispatch: ASYNC?");
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross return (-1);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Call the common smbd_doorsvc.c code.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * da->da_arg.rbuf = (return data buf)
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * da->da_arg.rsize = (return data size)
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Note that the return data buffer initially
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * points to the same buffer as the args.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * If that's not large enough, umem_alloc.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross syslog(LOG_DEBUG, "fksmbd_door_dispatch[%s]: alloc %m",
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross return (-1);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross /* Copy caller's return data after the header. */
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross (void) memcpy(rbuf + hdr_size, dop_arg.rbuf, dop_arg.rsize);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross (void) smb_doorhdr_encode(hdr, (uint8_t *)rbuf, hdr_size);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross /* Let's update da->da_hdr too. */
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Was door_return()
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * NB: The "fake kernel" smbsrv code will umem_free rbuf.