Print this page
NEX-14666 Need to provide SMB 2.1 Client
NEX-17187 panic in smbfs_acl_store
NEX-17231 smbfs create xattr files finds wrong file
NEX-17224 smbfs lookup EINVAL should be ENOENT
NEX-17260 SMB1 client fails to list directory after NEX-14666
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Matt Barden <matt.barden@nexenta.com>
Reviewed by: Rick McNeal <rick.mcneal@nexenta.com>
Reviewed by: Saso Kiselkov <saso.kiselkov@nexenta.com>
Reviewed by: Joyce McIntosh <joyce.mcintosh@nexenta.com>
and: (cleanup)
NEX-16824 SMB client connection setup rework
NEX-17232 SMB client reconnect failures
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Matt Barden <matt.barden@nexenta.com>
and: (improve debug)
NEX-16818 Add fksmbcl development tool
NEX-17264 SMB client test tp_smbutil_013 fails after NEX-14666
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Matt Barden <matt.barden@nexenta.com>
and: (fix ref leaks)
1575 untangle libmlrpc from SMB server
Reviewed by: Matt Barden <matt.barden@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Toomas Soome <tsoome@me.com>
Approved by: Richard Lowe <richlowe@richlowe.net>
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/lib/libsmbfs/smb/file.c
+++ new/usr/src/lib/libsmbfs/smb/file.c
1 1 /*
2 2 * Copyright (c) 2000, Boris Popov
3 3 * All rights reserved.
4 4 *
5 5 * Redistribution and use in source and binary forms, with or without
6 6 * modification, are permitted provided that the following conditions
7 7 * are met:
8 8 * 1. Redistributions of source code must retain the above copyright
9 9 * notice, this list of conditions and the following disclaimer.
10 10 * 2. Redistributions in binary form must reproduce the above copyright
11 11 * notice, this list of conditions and the following disclaimer in the
12 12 * documentation and/or other materials provided with the distribution.
13 13 * 3. All advertising materials mentioning features or use of this software
14 14 * must display the following acknowledgement:
15 15 * This product includes software developed by Boris Popov.
16 16 * 4. Neither the name of the author nor the names of any co-contributors
17 17 * may be used to endorse or promote products derived from this software
18 18 * without specific prior written permission.
19 19 *
20 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
↓ open down ↓ |
25 lines elided |
↑ open up ↑ |
26 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 30 * SUCH DAMAGE.
31 31 *
32 32 * $Id: file.c,v 1.4 2004/12/13 00:25:21 lindak Exp $
33 33 */
34 34
35 35 /*
36 - * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
37 36 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
38 37 * Use is subject to license terms.
38 + *
39 + * Copyright 2018 Nexenta Systems, Inc. All rights reserved.
39 40 */
40 41
41 42 #include <sys/param.h>
42 43 #include <sys/ioctl.h>
43 44 #include <sys/time.h>
44 45 #include <sys/mount.h>
45 46 #include <fcntl.h>
46 47 #include <ctype.h>
47 48 #include <errno.h>
48 49 #include <stdio.h>
49 50 #include <string.h>
50 51 #include <strings.h>
51 52 #include <stdlib.h>
52 53 #include <pwd.h>
53 54 #include <grp.h>
54 55 #include <unistd.h>
|
↓ open down ↓ |
6 lines elided |
↑ open up ↑ |
55 56 #include <libintl.h>
56 57
57 58 #include <sys/types.h>
58 59 #include <sys/file.h>
59 60
60 61 #include <netsmb/smb.h>
61 62 #include <netsmb/smb_lib.h>
62 63
63 64 #include "private.h"
64 65
66 +/*
67 + * It's not actually necessary to call the CLOSEFH ioctl, but doing it
68 + * makes debugging a little easier. If we were to skip the ioctl,
69 + * nsmb_close would cleanup the handle, here or in process exit.
70 + */
65 71 int
66 72 smb_fh_close(int fd)
67 73 {
68 - return (close(fd));
74 + (void) nsmb_ioctl(fd, SMBIOC_CLOSEFH, NULL);
75 + return (nsmb_close(fd));
69 76 }
70 77
71 78 int
72 79 smb_fh_ntcreate(
73 80 struct smb_ctx *ctx, char *path,
74 81 int req_acc, int efattr, int share_acc,
75 82 int open_disp, int create_opts)
76 83 {
77 84 smbioc_ntcreate_t ioc;
78 85 int err, nmlen;
79 86 int new_fd = -1;
80 87 int32_t from_fd;
81 88
82 89 nmlen = strlen(path);
83 90 if (nmlen >= SMBIOC_MAX_NAME) {
84 91 err = EINVAL;
85 92 goto errout;
86 93 }
87 94
88 95 /*
|
↓ open down ↓ |
10 lines elided |
↑ open up ↑ |
89 96 * Will represent this SMB-level open as a new
90 97 * open device handle. Get one, then duplicate
91 98 * the driver session and tree bindings.
92 99 */
93 100 new_fd = smb_open_driver();
94 101 if (new_fd < 0) {
95 102 err = errno;
96 103 goto errout;
97 104 }
98 105 from_fd = ctx->ct_dev_fd;
99 - if (ioctl(new_fd, SMBIOC_DUP_DEV, &from_fd) == -1) {
106 + if (nsmb_ioctl(new_fd, SMBIOC_DUP_DEV, &from_fd) == -1) {
100 107 err = errno;
101 108 goto errout;
102 109 }
103 110
104 111 /*
105 112 * Do the SMB-level open with the new dev handle.
106 113 */
107 114 bzero(&ioc, sizeof (ioc));
108 115 strlcpy(ioc.ioc_name, path, SMBIOC_MAX_NAME);
109 116 ioc.ioc_req_acc = req_acc;
110 117 ioc.ioc_efattr = efattr;
111 118 ioc.ioc_share_acc = share_acc;
112 119 ioc.ioc_open_disp = open_disp;
113 120 ioc.ioc_creat_opts = create_opts;
114 - if (ioctl(new_fd, SMBIOC_NTCREATE, &ioc) == -1) {
121 + if (nsmb_ioctl(new_fd, SMBIOC_NTCREATE, &ioc) == -1) {
115 122 err = errno;
116 123 goto errout;
117 124 }
118 125
119 126 return (new_fd);
120 127
121 128 errout:
122 129 if (new_fd != -1)
123 - close(new_fd);
130 + nsmb_close(new_fd);
124 131 errno = err;
125 132 return (-1);
126 133 }
127 134
128 135 /*
129 136 * Conveinence wrapper for smb_fh_ntcreate
130 137 * Converts Unix-style open call to NTCreate.
131 138 */
132 139 int
133 140 smb_fh_open(struct smb_ctx *ctx, const char *path, int oflag)
134 141 {
135 142 int mode, open_disp, req_acc, share_acc;
136 143 char *p, *ntpath = NULL;
137 144 int fd = -1;
138 145
139 146 /*
140 147 * Convert Unix path to NT (backslashes)
141 148 */
142 149 ntpath = strdup(path);
143 150 if (ntpath == NULL)
144 151 return (-1); /* errno was set */
145 152 for (p = ntpath; *p; p++)
146 153 if (*p == '/')
147 154 *p = '\\';
148 155
149 156 /*
150 157 * Map O_RDONLY, O_WRONLY, O_RDWR
151 158 * to FREAD, FWRITE
152 159 */
153 160 mode = (oflag & 3) + 1;
154 161
155 162 /*
156 163 * Compute requested access, share access.
157 164 */
158 165 req_acc = (
159 166 STD_RIGHT_READ_CONTROL_ACCESS |
160 167 STD_RIGHT_SYNCHRONIZE_ACCESS);
161 168 share_acc = NTCREATEX_SHARE_ACCESS_NONE;
162 169 if (mode & FREAD) {
163 170 req_acc |= (
164 171 SA_RIGHT_FILE_READ_DATA |
165 172 SA_RIGHT_FILE_READ_EA |
166 173 SA_RIGHT_FILE_READ_ATTRIBUTES);
167 174 share_acc |= NTCREATEX_SHARE_ACCESS_READ;
168 175 }
169 176 if (mode & FWRITE) {
170 177 req_acc |= (
171 178 SA_RIGHT_FILE_WRITE_DATA |
172 179 SA_RIGHT_FILE_APPEND_DATA |
173 180 SA_RIGHT_FILE_WRITE_EA |
174 181 SA_RIGHT_FILE_WRITE_ATTRIBUTES);
175 182 share_acc |= NTCREATEX_SHARE_ACCESS_WRITE;
176 183 }
177 184
178 185 /*
179 186 * Compute open disposition
180 187 */
181 188 if (oflag & FCREAT) {
182 189 /* Creat if necessary. */
183 190 if (oflag & FEXCL) {
184 191 /* exclusive */
185 192 open_disp = NTCREATEX_DISP_CREATE;
186 193 } else if (oflag & FTRUNC)
187 194 open_disp = NTCREATEX_DISP_OVERWRITE_IF;
188 195 else
189 196 open_disp = NTCREATEX_DISP_OPEN_IF;
190 197 } else {
191 198 /* Not creating. */
192 199 if (oflag & FTRUNC)
193 200 open_disp = NTCREATEX_DISP_OVERWRITE;
194 201 else
195 202 open_disp = NTCREATEX_DISP_OPEN;
196 203 }
|
↓ open down ↓ |
63 lines elided |
↑ open up ↑ |
197 204
198 205 fd = smb_fh_ntcreate(ctx, ntpath,
199 206 req_acc, SMB_EFA_NORMAL, share_acc, open_disp,
200 207 NTCREATEX_OPTIONS_NON_DIRECTORY_FILE);
201 208
202 209 free(ntpath);
203 210 return (fd);
204 211 }
205 212
206 213 int
207 -smb_fh_read(int fd, off_t offset, size_t count,
214 +smb_fh_read(int fd, off64_t offset, size_t count,
208 215 char *dst)
209 216 {
210 217 struct smbioc_rw rwrq;
211 218
212 219 bzero(&rwrq, sizeof (rwrq));
213 - rwrq.ioc_fh = -1; /* tell driver to supply this */
214 220 rwrq.ioc_base = dst;
215 221 rwrq.ioc_cnt = count;
216 222 rwrq.ioc_offset = offset;
217 - if (ioctl(fd, SMBIOC_READ, &rwrq) == -1) {
223 + if (nsmb_ioctl(fd, SMBIOC_READ, &rwrq) == -1) {
218 224 return (-1);
219 225 }
220 226 return (rwrq.ioc_cnt);
221 227 }
222 228
223 229 int
224 -smb_fh_write(int fd, off_t offset, size_t count,
230 +smb_fh_write(int fd, off64_t offset, size_t count,
225 231 const char *src)
226 232 {
227 233 struct smbioc_rw rwrq;
228 234
229 235 bzero(&rwrq, sizeof (rwrq));
230 - rwrq.ioc_fh = -1; /* tell driver to supply this */
231 236 rwrq.ioc_base = (char *)src;
232 237 rwrq.ioc_cnt = count;
233 238 rwrq.ioc_offset = offset;
234 - if (ioctl(fd, SMBIOC_WRITE, &rwrq) == -1) {
239 + if (nsmb_ioctl(fd, SMBIOC_WRITE, &rwrq) == -1) {
235 240 return (-1);
236 241 }
237 242 return (rwrq.ioc_cnt);
238 243 }
239 244
240 245 /*
241 246 * Do a TRANSACT_NAMED_PIPE, which is basically just a
242 247 * pipe write and pipe read, all in one round trip.
243 248 *
244 249 * tdlen, tdata describe the data to send.
245 250 * rdlen, rdata on input describe the receive buffer,
246 251 * and on output *rdlen is the received length.
247 252 */
248 253 int
249 254 smb_fh_xactnp(int fd,
250 255 int tdlen, const char *tdata, /* transmit */
251 256 int *rdlen, char *rdata, /* receive */
252 257 int *more)
253 258 {
254 - int err, rparamcnt;
255 - uint16_t setup[2];
259 + smbioc_xnp_t ioc;
256 260
257 - setup[0] = TRANS_TRANSACT_NAMED_PIPE;
258 - setup[1] = 0xFFFF; /* driver replaces this */
259 - rparamcnt = 0;
261 + /* this gets copyin & copyout */
262 + bzero(&ioc, sizeof (ioc));
263 + ioc.ioc_tdlen = tdlen;
264 + ioc.ioc_rdlen = *rdlen;
265 + ioc.ioc_more = 0;
266 + ioc.ioc_tdata = (char *)tdata;
267 + ioc.ioc_rdata = rdata;
260 268
261 - err = smb_t2_request(fd, 2, setup, "\\PIPE\\",
262 - 0, NULL, /* TX paramcnt, params */
263 - tdlen, (void *)tdata,
264 - &rparamcnt, NULL, /* no RX params */
265 - rdlen, rdata, more);
266 -
267 - if (err)
269 + if (nsmb_ioctl(fd, SMBIOC_XACTNP, &ioc) == -1) {
268 270 *rdlen = 0;
271 + return (-1);
272 + }
269 273
270 - return (err);
274 + *rdlen = ioc.ioc_rdlen;
275 + *more = ioc.ioc_more;
276 +
277 + return (0);
271 278 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX