xref: /titanic_51/usr/src/uts/common/fs/smbsrv/smb_print.c (revision 3d5869cc80c26887ee2c78b0f35e58f574e97192)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*
27  * SMB print interface.
28  */
29 
30 #include <smbsrv/smb_kproto.h>
31 
32 
33 /*
34  * smb_com_open_print_file
35  *
36  * This message is sent to create a new printer file which will be deleted
37  * once it has been closed and printed.
38  *
39  * Client Request                     Description
40  * ================================== =================================
41  *
42  * UCHAR WordCount;                   Count of parameter words = 2
43  * USHORT SetupLength;                Length of printer setup data
44  * USHORT Mode;                       0 = Text mode (DOS expands TABs)
45  *                                     1 = Graphics mode
46  * USHORT ByteCount;                  Count of data bytes;  min = 2
47  * UCHAR BufferFormat;                0x04
48  * STRING IdentifierString[];         Identifier string
49  *
50  * Tid in the SMB header must refer to a printer resource type.
51  *
52  * SetupLength is the number of bytes in the first part of the resulting
53  * print spool file which contains printer-specific control strings.
54  *
55  * Mode can have the following values:
56  *
57  *      0     Text mode.  The server may optionally
58  *            expand tabs to a series of spaces.
59  *      1     Graphics mode.  No conversion of data
60  *            should be done by the server.
61  *
62  * IdentifierString can be used by the server to provide some sort of per-
63  * client identifying component to the print file.
64  *
65  * Server Response                    Description
66  * ================================== =================================
67  *
68  * UCHAR WordCount;                   Count of parameter words = 1
69  * USHORT Fid;                        File handle
70  * USHORT ByteCount;                  Count of data bytes = 0
71  *
72  * Fid is the returned handle which may be used by subsequent write and
73  * close operations.  When the file is finally closed, it will be sent to
74  * the spooler and printed.
75  *
76  * 4.5.1.1   Errors
77  *
78  * ERRDOS/ERRnoaccess
79  * ERRDOS/ERRnofids
80  * ERRSRV/ERRinvdevice
81  * ERRSRV/ERRbaduid
82  * ERRSRV/ERRqfull
83  * ERRSRV/ERRqtoobig
84  */
85 smb_sdrc_t
86 smb_pre_open_print_file(smb_request_t *sr)
87 {
88 	DTRACE_SMB_1(op__OpenPrintFile__start, smb_request_t *, sr);
89 	return (SDRC_SUCCESS);
90 }
91 
92 void
93 smb_post_open_print_file(smb_request_t *sr)
94 {
95 	DTRACE_SMB_1(op__OpenPrintFile__done, smb_request_t *, sr);
96 }
97 
98 smb_sdrc_t /*ARGSUSED*/
99 smb_com_open_print_file(smb_request_t *sr)
100 {
101 	return (SDRC_NOT_IMPLEMENTED);
102 }
103 
104 
105 /*
106  * smb_com_close_print_file
107  *
108  *
109  * This message invalidates the specified file handle and queues the file
110  * for printing.
111  *
112  *   Client Request                     Description
113  *   ================================== =================================
114  *
115  *   UCHAR WordCount;                   Count of parameter words = 1
116  *   USHORT Fid;                        File handle
117  *   USHORT ByteCount;                  Count of data bytes = 0
118  *
119  * Fid refers to a file previously created with SMB_COM_OPEN_PRINT_FILE.
120  * On successful completion of this request, the file is queued for
121  * printing by the server.
122  *
123  *   Server Response                    Description
124  *   ================================== =================================
125  *
126  *   UCHAR WordCount;                   Count of parameter words = 0
127  *   USHORT ByteCount;                  Count of data bytes = 0
128  *
129  * Servers which negotiate dialects of LANMAN1.0 and newer allow all the
130  * other types of Fid closing requests to invalidate the Fid and begin
131  * spooling.
132  */
133 smb_sdrc_t
134 smb_pre_close_print_file(smb_request_t *sr)
135 {
136 	DTRACE_SMB_1(op__ClosePrintFile__start, smb_request_t *, sr);
137 	return (SDRC_SUCCESS);
138 }
139 
140 void
141 smb_post_close_print_file(smb_request_t *sr)
142 {
143 	DTRACE_SMB_1(op__ClosePrintFile__done, smb_request_t *, sr);
144 }
145 
146 smb_sdrc_t /*ARGSUSED*/
147 smb_com_close_print_file(smb_request_t *sr)
148 {
149 	return (SDRC_NOT_IMPLEMENTED);
150 }
151 
152 
153 /*
154  * smb_com_get_print_queue
155  *
156  * This message obtains a list of the elements currently in the print queue
157  * on the server.
158  *
159  *   Client Request                     Description
160  *   ================================== =================================
161  *
162  *   UCHAR WordCount;                   Count of parameter words = 2
163  *   USHORT MaxCount;                   Max number of entries to return
164  *   USHORT StartIndex;                 First queue entry to return
165  *   USHORT ByteCount;                  Count of data bytes = 0
166  *
167  * StartIndex specifies the first entry in the queue to return.
168  *
169  * MaxCount specifies the maximum number of entries to return, this may be
170  * a positive or negative number.  A positive number requests a forward
171  * search, a negative number indicates a backward search.
172  *
173  *   Server Response                    Description
174  *   ================================== =================================
175  *
176  *   UCHAR WordCount;                   Count of parameter words = 2
177  *   USHORT Count;                      Number of entries returned
178  *   USHORT RestartIndex;               Index of entry after last
179  *                                       returned
180  *   USHORT ByteCount;                  Count of data bytes;  min = 3
181  *   UCHAR BufferFormat;                0x01 -- Data block
182  *   USHORT DataLength;                 Length of data
183  *   UCHAR Data[];                      Queue elements
184  *
185  * Count indicates how many entries were actually returned.  RestartIndex
186  * is the index of the entry following the last entry returned; it may be
187  * used as the StartIndex in a subsequent request to resume the queue
188  * listing.
189  *
190  * The format of each returned queue element is:
191  *
192  *   Queue Element Member             Description
193  *   ================================ ===================================
194  *
195  *   SMB_DATE FileDate;               Date file was queued
196  *   SMB_TIME FileTime;               Time file was queued
197  *   UCHAR Status;                    Entry status.  One of:
198  *                                     01 = held or stopped
199  *                                     02 = printing
200  *                                     03 = awaiting print
201  *                                     04 = in intercept
202  *                                     05 = file had error
203  *                                     06 = printer error
204  *                                     07-FF = reserved
205  *   USHORT SpoolFileNumber;          Assigned by the spooler
206  *   ULONG SpoolFileSize;             Number of bytes in spool file
207  *   UCHAR Reserved;
208  *   UCHAR SpoolFileName[16];         Client which created the spool file
209  *
210  * SMB_COM_GET_PRINT_QUEUE will return less than the requested number of
211  * elements only when the top or end of the queue is encountered.
212  *
213  * Support for this SMB is server optional.  In particular, no current
214  * Microsoft client software issues this request.
215  *
216  * 4.5.2.1   Errors
217  *
218  * ERRHRD/ERRnotready
219  * ERRHRD/ERRerror
220  * ERRSRV/ERRbaduid
221  */
222 smb_sdrc_t
223 smb_pre_get_print_queue(smb_request_t *sr)
224 {
225 	DTRACE_SMB_1(op__GetPrintQueue__start, smb_request_t *, sr);
226 	return (SDRC_SUCCESS);
227 }
228 
229 void
230 smb_post_get_print_queue(smb_request_t *sr)
231 {
232 	DTRACE_SMB_1(op__GetPrintQueue__done, smb_request_t *, sr);
233 }
234 
235 smb_sdrc_t
236 smb_com_get_print_queue(smb_request_t *sr)
237 {
238 	unsigned short max_count, start_ix;
239 
240 	if (smbsr_decode_vwv(sr, "ww", &max_count, &start_ix) != 0)
241 		return (SDRC_ERROR);
242 
243 	if (smbsr_encode_result(sr, 2, 3, "bwwwbw", 2, 0, 0, 3, 1, 0))
244 		return (SDRC_ERROR);
245 
246 	return (SDRC_SUCCESS);
247 }
248 
249 
250 /*
251  * smb_com_write_print_file
252  *
253  * This message is sent to write bytes into a print spool file.
254  *
255  * Client Request                     Description
256  * ================================== =================================
257  *
258  * UCHAR WordCount;                   Count of parameter words = 1
259  * USHORT Fid;                        File handle
260  * USHORT ByteCount;                  Count of data bytes;  min = 4
261  * UCHAR BufferFormat;                0x01 -- Data block
262  * USHORT DataLength;                 Length of data
263  * UCHAR Data[];                      Data
264  *
265  * Fid indicates the print spool file to be written, it must refer to a
266  * print spool file.
267  *
268  * ByteCount specifies the number of bytes to be written, and must be less
269  * than MaxBufferSize for the Tid specified.
270  *
271  * Data contains the bytes to append to the print spool file.  The first
272  * SetupLength bytes in the resulting print spool file contain printer
273  * setup data.  SetupLength is specified in the SMB_COM_OPEN_PRINT_FILE SMB
274  * request.
275  *
276  * Server Response                    Description
277  * ================================== =================================
278  *
279  * UCHAR WordCount;                   Count of parameter words = 0
280  * USHORT ByteCount;                  Count of data bytes = 0
281  *
282  * Servers which negotiate a protocol dialect of LANMAN1.0 or later also
283  * support the application of normal write requests to print spool files.
284  *
285  */
286 smb_sdrc_t
287 smb_pre_write_print_file(smb_request_t *sr)
288 {
289 	DTRACE_SMB_1(op__WritePrintFile__start, smb_request_t *, sr);
290 	return (SDRC_SUCCESS);
291 }
292 
293 void
294 smb_post_write_print_file(smb_request_t *sr)
295 {
296 	DTRACE_SMB_1(op__WritePrintFile__done, smb_request_t *, sr);
297 }
298 
299 smb_sdrc_t /*ARGSUSED*/
300 smb_com_write_print_file(smb_request_t *sr)
301 {
302 	return (SDRC_NOT_IMPLEMENTED);
303 }
304