1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright 2013 Nexenta Systems, Inc. All rights reserved.
*/
#include <sys/list.h>
#include <assert.h>
#include <alloca.h>
#include <door.h>
#include <errno.h>
#include <syslog.h>
#include <unistd.h>
#include <stdio.h>
#include <synch.h>
#include <string.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <pthread.h>
#include <strings.h>
#include <umem.h>
#include <smbsrv/smb_door.h>
#include <smbsrv/smb_xdr.h>
#include <smbsrv/smb_token.h>
#include <smbsrv/libmlsvc.h>
#include <smbsrv/libsmbns.h>
#include "smbd.h"
/*
* Special version of smb_door_dispatch() for the
* "fake" smbsrv (running in user space).
*
* This is called via function pointer from
* smbsrv: smb_kdoor_upcall()
*
* The args and response go RPC encoded, just so we can
* borrow some of the common doorsvc code, even though
* there's no need for RPC encoding in this scenario.
*/
int
fksmbd_door_dispatch(smb_doorarg_t *da)
{
smbd_arg_t dop_arg;
smb_doorhdr_t *hdr;
char *rbuf = NULL;
char *argp = da->da_arg.data_ptr;
size_t arg_size = da->da_arg.data_size;
size_t hdr_size, rsize;
/*
* Decode
*
* da->da_arg.data_ptr = (arg data, xdr encoded)
* da->da_arg.data_size = (arg data len)
*/
bzero(&dop_arg, sizeof (smbd_arg_t));
hdr = &dop_arg.hdr;
hdr_size = xdr_sizeof(smb_doorhdr_xdr, hdr);
if ((argp == NULL) || (arg_size < hdr_size)) {
syslog(LOG_DEBUG, "fksmbd_door_dispatch: bad args");
return (-1);
}
if (smb_doorhdr_decode(hdr, (uint8_t *)argp, hdr_size) == -1) {
syslog(LOG_DEBUG, "smbd_door_dispatch: header decode failed");
return (-1);
}
if ((hdr->dh_magic != SMB_DOOR_HDR_MAGIC) ||
(hdr->dh_flags != SMB_DF_FAKE_KERNEL)) {
syslog(LOG_DEBUG, "fksmbd_door_dispatch: invalid header");
return (-1);
}
dop_arg.opname = smb_doorhdr_opname(hdr->dh_op);
dop_arg.data = argp + hdr_size;
dop_arg.datalen = hdr->dh_datalen;
if (hdr->dh_op == SMB_DR_ASYNC_RESPONSE) {
/*
* ASYNC_RESPONSE is not used here.
*/
syslog(LOG_DEBUG, "fksmbd_door_dispatch: ASYNC?");
return (-1);
}
/*
* Dispatch
*
* Call the common smbd_doorsvc.c code.
*/
(void) smbd_door_dispatch_op(&dop_arg);
/*
* Encode
*
* da->da_arg.rbuf = (return data buf)
* da->da_arg.rsize = (return data size)
*
* Note that the return data buffer initially
* points to the same buffer as the args.
* If that's not large enough, umem_alloc.
*/
rsize = dop_arg.rsize + hdr_size;
rbuf = umem_alloc(rsize, UMEM_DEFAULT);
if (rbuf == NULL) {
syslog(LOG_DEBUG, "fksmbd_door_dispatch[%s]: alloc %m",
dop_arg.opname);
return (-1);
}
/* Copy caller's return data after the header. */
if (dop_arg.rbuf != NULL) {
(void) memcpy(rbuf + hdr_size, dop_arg.rbuf, dop_arg.rsize);
free(dop_arg.rbuf);
}
hdr->dh_datalen = dop_arg.rsize;
(void) smb_doorhdr_encode(hdr, (uint8_t *)rbuf, hdr_size);
/* Let's update da->da_hdr too. */
da->da_hdr = *hdr;
/*
* Was door_return()
* NB: The "fake kernel" smbsrv code will umem_free rbuf.
*/
da->da_arg.rbuf = rbuf;
da->da_arg.rsize = rsize;
return (0);
}
|