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