summaryrefslogtreecommitdiff
path: root/usr/src/uts/common/fs/smbsrv/smb_print.c
blob: 4e21dfdd2bd3f52486a6eedcc57d508fe8fc55ba (plain)
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
/*
 * 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 2009 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

/*
 * SMB print interface.
 */

#include <smbsrv/smb_kproto.h>


/*
 * smb_com_open_print_file
 *
 * This message is sent to create a new printer file which will be deleted
 * once it has been closed and printed.
 *
 * Client Request                     Description
 * ================================== =================================
 *
 * UCHAR WordCount;                   Count of parameter words = 2
 * USHORT SetupLength;                Length of printer setup data
 * USHORT Mode;                       0 = Text mode (DOS expands TABs)
 *                                     1 = Graphics mode
 * USHORT ByteCount;                  Count of data bytes;  min = 2
 * UCHAR BufferFormat;                0x04
 * STRING IdentifierString[];         Identifier string
 *
 * Tid in the SMB header must refer to a printer resource type.
 *
 * SetupLength is the number of bytes in the first part of the resulting
 * print spool file which contains printer-specific control strings.
 *
 * Mode can have the following values:
 *
 *      0     Text mode.  The server may optionally
 *            expand tabs to a series of spaces.
 *      1     Graphics mode.  No conversion of data
 *            should be done by the server.
 *
 * IdentifierString can be used by the server to provide some sort of per-
 * client identifying component to the print file.
 *
 * Server Response                    Description
 * ================================== =================================
 *
 * UCHAR WordCount;                   Count of parameter words = 1
 * USHORT Fid;                        File handle
 * USHORT ByteCount;                  Count of data bytes = 0
 *
 * Fid is the returned handle which may be used by subsequent write and
 * close operations.  When the file is finally closed, it will be sent to
 * the spooler and printed.
 *
 * 4.5.1.1   Errors
 *
 * ERRDOS/ERRnoaccess
 * ERRDOS/ERRnofids
 * ERRSRV/ERRinvdevice
 * ERRSRV/ERRbaduid
 * ERRSRV/ERRqfull
 * ERRSRV/ERRqtoobig
 */
smb_sdrc_t
smb_pre_open_print_file(smb_request_t *sr)
{
	DTRACE_SMB_1(op__OpenPrintFile__start, smb_request_t *, sr);
	return (SDRC_SUCCESS);
}

void
smb_post_open_print_file(smb_request_t *sr)
{
	DTRACE_SMB_1(op__OpenPrintFile__done, smb_request_t *, sr);
}

smb_sdrc_t /*ARGSUSED*/
smb_com_open_print_file(smb_request_t *sr)
{
	return (SDRC_NOT_IMPLEMENTED);
}


/*
 * smb_com_close_print_file
 *
 *
 * This message invalidates the specified file handle and queues the file
 * for printing.
 *
 *   Client Request                     Description
 *   ================================== =================================
 *
 *   UCHAR WordCount;                   Count of parameter words = 1
 *   USHORT Fid;                        File handle
 *   USHORT ByteCount;                  Count of data bytes = 0
 *
 * Fid refers to a file previously created with SMB_COM_OPEN_PRINT_FILE.
 * On successful completion of this request, the file is queued for
 * printing by the server.
 *
 *   Server Response                    Description
 *   ================================== =================================
 *
 *   UCHAR WordCount;                   Count of parameter words = 0
 *   USHORT ByteCount;                  Count of data bytes = 0
 *
 * Servers which negotiate dialects of LANMAN1.0 and newer allow all the
 * other types of Fid closing requests to invalidate the Fid and begin
 * spooling.
 */
smb_sdrc_t
smb_pre_close_print_file(smb_request_t *sr)
{
	DTRACE_SMB_1(op__ClosePrintFile__start, smb_request_t *, sr);
	return (SDRC_SUCCESS);
}

void
smb_post_close_print_file(smb_request_t *sr)
{
	DTRACE_SMB_1(op__ClosePrintFile__done, smb_request_t *, sr);
}

smb_sdrc_t /*ARGSUSED*/
smb_com_close_print_file(smb_request_t *sr)
{
	return (SDRC_NOT_IMPLEMENTED);
}


/*
 * smb_com_get_print_queue
 *
 * This message obtains a list of the elements currently in the print queue
 * on the server.
 *
 *   Client Request                     Description
 *   ================================== =================================
 *
 *   UCHAR WordCount;                   Count of parameter words = 2
 *   USHORT MaxCount;                   Max number of entries to return
 *   USHORT StartIndex;                 First queue entry to return
 *   USHORT ByteCount;                  Count of data bytes = 0
 *
 * StartIndex specifies the first entry in the queue to return.
 *
 * MaxCount specifies the maximum number of entries to return, this may be
 * a positive or negative number.  A positive number requests a forward
 * search, a negative number indicates a backward search.
 *
 *   Server Response                    Description
 *   ================================== =================================
 *
 *   UCHAR WordCount;                   Count of parameter words = 2
 *   USHORT Count;                      Number of entries returned
 *   USHORT RestartIndex;               Index of entry after last
 *                                       returned
 *   USHORT ByteCount;                  Count of data bytes;  min = 3
 *   UCHAR BufferFormat;                0x01 -- Data block
 *   USHORT DataLength;                 Length of data
 *   UCHAR Data[];                      Queue elements
 *
 * Count indicates how many entries were actually returned.  RestartIndex
 * is the index of the entry following the last entry returned; it may be
 * used as the StartIndex in a subsequent request to resume the queue
 * listing.
 *
 * The format of each returned queue element is:
 *
 *   Queue Element Member             Description
 *   ================================ ===================================
 *
 *   SMB_DATE FileDate;               Date file was queued
 *   SMB_TIME FileTime;               Time file was queued
 *   UCHAR Status;                    Entry status.  One of:
 *                                     01 = held or stopped
 *                                     02 = printing
 *                                     03 = awaiting print
 *                                     04 = in intercept
 *                                     05 = file had error
 *                                     06 = printer error
 *                                     07-FF = reserved
 *   USHORT SpoolFileNumber;          Assigned by the spooler
 *   ULONG SpoolFileSize;             Number of bytes in spool file
 *   UCHAR Reserved;
 *   UCHAR SpoolFileName[16];         Client which created the spool file
 *
 * SMB_COM_GET_PRINT_QUEUE will return less than the requested number of
 * elements only when the top or end of the queue is encountered.
 *
 * Support for this SMB is server optional.  In particular, no current
 * Microsoft client software issues this request.
 *
 * 4.5.2.1   Errors
 *
 * ERRHRD/ERRnotready
 * ERRHRD/ERRerror
 * ERRSRV/ERRbaduid
 */
smb_sdrc_t
smb_pre_get_print_queue(smb_request_t *sr)
{
	DTRACE_SMB_1(op__GetPrintQueue__start, smb_request_t *, sr);
	return (SDRC_SUCCESS);
}

void
smb_post_get_print_queue(smb_request_t *sr)
{
	DTRACE_SMB_1(op__GetPrintQueue__done, smb_request_t *, sr);
}

smb_sdrc_t
smb_com_get_print_queue(smb_request_t *sr)
{
	unsigned short max_count, start_ix;

	if (smbsr_decode_vwv(sr, "ww", &max_count, &start_ix) != 0)
		return (SDRC_ERROR);

	if (smbsr_encode_result(sr, 2, 3, "bwwwbw", 2, 0, 0, 3, 1, 0))
		return (SDRC_ERROR);

	return (SDRC_SUCCESS);
}


/*
 * smb_com_write_print_file
 *
 * This message is sent to write bytes into a print spool file.
 *
 * Client Request                     Description
 * ================================== =================================
 *
 * UCHAR WordCount;                   Count of parameter words = 1
 * USHORT Fid;                        File handle
 * USHORT ByteCount;                  Count of data bytes;  min = 4
 * UCHAR BufferFormat;                0x01 -- Data block
 * USHORT DataLength;                 Length of data
 * UCHAR Data[];                      Data
 *
 * Fid indicates the print spool file to be written, it must refer to a
 * print spool file.
 *
 * ByteCount specifies the number of bytes to be written, and must be less
 * than MaxBufferSize for the Tid specified.
 *
 * Data contains the bytes to append to the print spool file.  The first
 * SetupLength bytes in the resulting print spool file contain printer
 * setup data.  SetupLength is specified in the SMB_COM_OPEN_PRINT_FILE SMB
 * request.
 *
 * Server Response                    Description
 * ================================== =================================
 *
 * UCHAR WordCount;                   Count of parameter words = 0
 * USHORT ByteCount;                  Count of data bytes = 0
 *
 * Servers which negotiate a protocol dialect of LANMAN1.0 or later also
 * support the application of normal write requests to print spool files.
 *
 */
smb_sdrc_t
smb_pre_write_print_file(smb_request_t *sr)
{
	DTRACE_SMB_1(op__WritePrintFile__start, smb_request_t *, sr);
	return (SDRC_SUCCESS);
}

void
smb_post_write_print_file(smb_request_t *sr)
{
	DTRACE_SMB_1(op__WritePrintFile__done, smb_request_t *, sr);
}

smb_sdrc_t /*ARGSUSED*/
smb_com_write_print_file(smb_request_t *sr)
{
	return (SDRC_NOT_IMPLEMENTED);
}