Print this page
Build provider 3rd arg from smb_request_t
hacking...
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/fs/smbsrv/smb_print.c
+++ new/usr/src/uts/common/fs/smbsrv/smb_print.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
24 24 */
25 25
26 26 /*
27 27 * SMB print interface.
28 28 */
29 29
30 30 #include <smbsrv/smb_kproto.h>
31 31 #include <sys/unistd.h>
32 32 #include <sys/stat.h>
33 33 #include <sys/types.h>
34 34 #include <sys/fcntl.h>
35 35 #include <smbsrv/smb_share.h>
36 36
37 37 /*
38 38 * Starts the creation of a new printer file, which will be deleted
39 39 * automatically once it has been closed and printed.
40 40 *
41 41 * SetupLength is the number of bytes in the first part of the resulting
42 42 * print spool file which contains printer-specific control strings.
43 43 *
44 44 * Mode can have the following values:
45 45 * 0 Text mode. The server may optionally
46 46 * expand tabs to a series of spaces.
47 47 * 1 Graphics mode. No conversion of data
48 48 * should be done by the server.
49 49 *
50 50 * IdentifierString can be used by the server to provide some sort of
51 51 * per-client identifying component to the print file.
52 52 *
53 53 * When the file is closed, it will be sent to the spooler and printed.
54 54 */
55 55 smb_sdrc_t
56 56 smb_pre_open_print_file(smb_request_t *sr)
57 57 {
58 58 struct open_param *op = &sr->arg.open;
59 59 char *path;
60 60 char *identifier;
61 61 uint32_t new_id;
62 62 uint16_t setup;
63 63 uint16_t mode;
64 64 int rc;
65 65 static uint32_t tmp_id = 10000;
66 66
67 67 bzero(op, sizeof (sr->arg.open));
68 68 rc = smbsr_decode_vwv(sr, "ww", &setup, &mode);
69 69 if (rc == 0)
70 70 rc = smbsr_decode_data(sr, "%S", sr, &identifier);
↓ open down ↓ |
70 lines elided |
↑ open up ↑ |
71 71
72 72 if (rc == 0) {
73 73 path = smb_srm_zalloc(sr, MAXPATHLEN);
74 74 op->fqi.fq_path.pn_path = path;
75 75 new_id = atomic_inc_32_nv(&tmp_id);
76 76 (void) snprintf(path, MAXPATHLEN, "%s%05u", identifier, new_id);
77 77 }
78 78
79 79 op->create_disposition = FILE_OVERWRITE_IF;
80 80 op->create_options = FILE_NON_DIRECTORY_FILE;
81 - DTRACE_SMB_2(op__OpenPrintFile__start, smb_request_t *, sr,
82 - struct open_param *, op);
81 + DTRACE_SMB_1(op__OpenPrintFile__start, smb_request_t *, sr); /* arg.open */
83 82
84 83 return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
85 84 }
86 85
87 86 void
88 87 smb_post_open_print_file(smb_request_t *sr)
89 88 {
90 89 DTRACE_SMB_1(op__OpenPrintFile__done, smb_request_t *, sr);
91 90 }
92 91
93 92 /*
94 93 * Creates a new spool file which will be later copied and
95 94 * deleted by cupsd. After the file is created, information
96 95 * related to the file will be placed in a spooldoc list
97 96 * to be later used by cupsd
98 97 *
99 98 * Return values
100 99 * rc 0 SDRC_SUCCESS
101 100 * rc non-zero SDRC_ERROR
102 101 */
103 102
104 103 smb_sdrc_t
105 104 smb_com_open_print_file(smb_request_t *sr)
106 105 {
107 106 int rc;
108 107 smb_kspooldoc_t *sp;
109 108 smb_kshare_t *si;
110 109 struct open_param *op = &sr->arg.open;
111 110
112 111 if (sr->sr_server->sv_cfg.skc_print_enable == 0 ||
113 112 !STYPE_ISPRN(sr->tid_tree->t_res_type)) {
114 113 cmn_err(CE_WARN, "smb_com_open_print_file: bad device");
115 114 smbsr_error(sr, NT_STATUS_BAD_DEVICE_TYPE,
116 115 ERRDOS, ERROR_BAD_DEV_TYPE);
117 116 return (SDRC_ERROR);
118 117 }
119 118 if ((rc = smb_common_create(sr)) != NT_STATUS_SUCCESS) {
120 119 cmn_err(CE_WARN, "smb_com_open_print_file: error rc=%d", rc);
121 120 return (SDRC_ERROR);
122 121 }
123 122 if ((rc = smbsr_encode_result(sr, 1, 0,
124 123 "bww", 1, sr->smb_fid, 0)) == 0) {
125 124 si = smb_kshare_lookup(sr->sr_server, SMB_SHARE_PRINT);
126 125 if (si == NULL) {
127 126 cmn_err(CE_NOTE, "smb_com_open_print_file: SDRC_ERROR");
128 127 return (SDRC_ERROR);
129 128 }
130 129 sp = kmem_zalloc(sizeof (smb_kspooldoc_t), KM_SLEEP);
131 130 (void) snprintf(sp->sd_path, MAXPATHLEN, "%s/%s", si->shr_path,
132 131 op->fqi.fq_path.pn_path);
133 132 /* sp->sd_spool_num set by smb_spool_add_doc() */
134 133 sp->sd_ipaddr = sr->session->ipaddr;
135 134 (void) strlcpy(sp->sd_username, sr->uid_user->u_name,
136 135 MAXNAMELEN);
137 136 sp->sd_fid = sr->smb_fid;
138 137 if (smb_spool_add_doc(sr->tid_tree, sp))
139 138 kmem_free(sp, sizeof (smb_kspooldoc_t));
140 139 smb_kshare_release(sr->sr_server, si);
141 140 }
142 141 return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
143 142 }
144 143
145 144 /*
146 145 * Close the specified file handle and queue the file for printing.
147 146 * The fid refers to a file previously created as a print spool file.
148 147 * On successful completion of this request, the file is queued for
149 148 * printing by the server.
150 149 *
151 150 * Servers that negotiate LANMAN1.0 or later allow all the the fid
152 151 * to be closed and printed via any close request.
153 152 */
154 153 smb_sdrc_t
155 154 smb_pre_close_print_file(smb_request_t *sr)
156 155 {
157 156 int rc;
158 157
159 158 rc = smbsr_decode_vwv(sr, "w", &sr->smb_fid);
160 159
161 160 DTRACE_SMB_1(op__ClosePrintFile__start, smb_request_t *, sr);
162 161 return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
163 162 }
164 163
165 164 void
166 165 smb_post_close_print_file(smb_request_t *sr)
167 166 {
168 167 DTRACE_SMB_1(op__ClosePrintFile__done, smb_request_t *, sr);
169 168 }
170 169
171 170 /*
172 171 *
173 172 * Adds the print file fid to a list to be used as a search
174 173 * key in the spooldoc list. It then wakes up the smbd
175 174 * spool monitor thread to copy the spool file.
176 175 *
177 176 * Return values
178 177 * rc - 0 success
179 178 *
180 179 */
181 180
182 181 smb_sdrc_t
183 182 smb_com_close_print_file(smb_request_t *sr)
184 183 {
185 184 smb_sdrc_t rc;
186 185
187 186 /*
188 187 * If sv_cfg.skc_print_enable somehow went false while
189 188 * we have a print FID open, close the FID. In this
190 189 * situation, smb_spool_add_fid() will do nothing.
191 190 */
192 191 if (!STYPE_ISPRN(sr->tid_tree->t_res_type)) {
193 192 smbsr_error(sr, NT_STATUS_BAD_DEVICE_TYPE,
194 193 ERRDOS, ERROR_BAD_DEV_TYPE);
195 194 cmn_err(CE_WARN, "smb_com_close_print_file: SDRC_ERROR");
196 195 return (SDRC_ERROR);
197 196 }
198 197 rc = smb_com_close(sr);
199 198
200 199 smb_spool_add_fid(sr->sr_server, sr->smb_fid);
201 200
202 201 return (rc);
203 202 }
204 203
205 204 /*
206 205 * Get a list of print queue entries on the server. Support for
207 206 * this request is optional (not required for Windows clients).
208 207 */
209 208 smb_sdrc_t
210 209 smb_pre_get_print_queue(smb_request_t *sr)
211 210 {
212 211 DTRACE_SMB_1(op__GetPrintQueue__start, smb_request_t *, sr);
213 212 return (SDRC_SUCCESS);
214 213 }
215 214
216 215 void
217 216 smb_post_get_print_queue(smb_request_t *sr)
218 217 {
219 218 DTRACE_SMB_1(op__GetPrintQueue__done, smb_request_t *, sr);
220 219 }
221 220
222 221 smb_sdrc_t
223 222 smb_com_get_print_queue(smb_request_t *sr)
224 223 {
225 224 unsigned short max_count, start_ix;
226 225
227 226 if (smbsr_decode_vwv(sr, "ww", &max_count, &start_ix) != 0)
228 227 return (SDRC_ERROR);
229 228
230 229 if (smbsr_encode_result(sr, 2, 3, "bwwwbw", 2, 0, 0, 3, 1, 0))
231 230 return (SDRC_ERROR);
232 231
233 232 return (SDRC_SUCCESS);
234 233 }
235 234
236 235 /*
237 236 * Write (append) data to a print spool file. The fid must refer to
238 237 * a print spool file.
239 238 *
240 239 * The first SetupLength bytes (see SMB_COM_OPEN_PRINT_FILE) in the
241 240 * print spool file contain printer setup data.
242 241 *
243 242 * Servers that negotiate LANMAN1.0 or later also support the use of
244 243 * normal write requests with print spool files.
245 244 */
246 245 smb_sdrc_t
247 246 smb_pre_write_print_file(smb_request_t *sr)
248 247 {
249 248 smb_rw_param_t *param;
250 249 int rc;
251 250
252 251 param = kmem_zalloc(sizeof (smb_rw_param_t), KM_SLEEP);
253 252 sr->arg.rw = param;
254 253 param->rw_magic = SMB_RW_MAGIC;
255 254
256 255 rc = smbsr_decode_vwv(sr, "w", &sr->smb_fid);
257 256
258 257 DTRACE_SMB_1(op__WritePrintFile__start, smb_request_t *, sr);
259 258 return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
260 259 }
261 260
262 261 void
263 262 smb_post_write_print_file(smb_request_t *sr)
264 263 {
265 264 DTRACE_SMB_1(op__WritePrintFile__done, smb_request_t *, sr);
266 265
267 266 kmem_free(sr->arg.rw, sizeof (smb_rw_param_t));
268 267 }
269 268
270 269 smb_sdrc_t
271 270 smb_com_write_print_file(smb_request_t *sr)
272 271 {
273 272 smb_rw_param_t *param = sr->arg.rw;
274 273 smb_node_t *node;
275 274 smb_attr_t attr;
276 275 int rc;
277 276
278 277 if (sr->sr_server->sv_cfg.skc_print_enable == 0 ||
279 278 !STYPE_ISPRN(sr->tid_tree->t_res_type)) {
280 279 smbsr_error(sr, NT_STATUS_BAD_DEVICE_TYPE,
281 280 ERRDOS, ERROR_BAD_DEV_TYPE);
282 281 return (SDRC_ERROR);
283 282 }
284 283
285 284 smbsr_lookup_file(sr);
286 285 if (sr->fid_ofile == NULL) {
287 286 smbsr_error(sr, NT_STATUS_INVALID_HANDLE, ERRDOS, ERRbadfid);
288 287 return (SDRC_ERROR);
289 288 }
290 289
291 290 node = sr->fid_ofile->f_node;
292 291 sr->user_cr = smb_ofile_getcred(sr->fid_ofile);
293 292
294 293 bzero(&attr, sizeof (attr));
295 294 attr.sa_mask = SMB_AT_SIZE;
296 295 rc = smb_node_getattr(sr, node, sr->user_cr, sr->fid_ofile, &attr);
297 296 if (rc != 0) {
298 297 smbsr_error(sr, NT_STATUS_INTERNAL_ERROR,
299 298 ERRDOS, ERROR_INTERNAL_ERROR);
300 299 return (SDRC_ERROR);
301 300 }
302 301
303 302 if ((smbsr_decode_data(sr, "D", ¶m->rw_vdb)) != 0) {
304 303 smbsr_error(sr, NT_STATUS_INVALID_PARAMETER,
305 304 ERRDOS, ERROR_INVALID_PARAMETER);
306 305 return (SDRC_ERROR);
307 306 }
308 307
309 308 param->rw_count = param->rw_vdb.vdb_len;
310 309 param->rw_offset = attr.sa_vattr.va_size;
311 310 param->rw_vdb.vdb_uio.uio_loffset = (offset_t)param->rw_offset;
312 311
313 312 if ((rc = smb_common_write(sr, param)) != 0) {
314 313 if (sr->smb_error.status != NT_STATUS_FILE_LOCK_CONFLICT)
315 314 smbsr_errno(sr, rc);
316 315 return (SDRC_ERROR);
317 316 }
318 317
319 318 rc = smbsr_encode_empty_result(sr);
320 319 return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
321 320 }
↓ open down ↓ |
229 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX