xref: /onnv-gate/usr/src/uts/common/fs/smbsrv/smb_print.c (revision 10966:37e5dcdf36d3)
15331Samw /*
25331Samw  * CDDL HEADER START
35331Samw  *
45331Samw  * The contents of this file are subject to the terms of the
55331Samw  * Common Development and Distribution License (the "License").
65331Samw  * You may not use this file except in compliance with the License.
75331Samw  *
85331Samw  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
95331Samw  * or http://www.opensolaris.org/os/licensing.
105331Samw  * See the License for the specific language governing permissions
115331Samw  * and limitations under the License.
125331Samw  *
135331Samw  * When distributing Covered Code, include this CDDL HEADER in each
145331Samw  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
155331Samw  * If applicable, add the following below this CDDL HEADER, with the
165331Samw  * fields enclosed by brackets "[]" replaced with your own identifying
175331Samw  * information: Portions Copyright [yyyy] [name of copyright owner]
185331Samw  *
195331Samw  * CDDL HEADER END
205331Samw  */
215331Samw /*
22*10966SJordan.Brown@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
235331Samw  * Use is subject to license terms.
245331Samw  */
255331Samw 
265331Samw /*
275331Samw  * SMB print interface.
285331Samw  */
295331Samw 
30*10966SJordan.Brown@Sun.COM #include <smbsrv/smb_kproto.h>
315331Samw 
325331Samw 
335331Samw /*
345331Samw  * smb_com_open_print_file
355331Samw  *
365331Samw  * This message is sent to create a new printer file which will be deleted
375331Samw  * once it has been closed and printed.
385331Samw  *
395331Samw  * Client Request                     Description
405331Samw  * ================================== =================================
415331Samw  *
425331Samw  * UCHAR WordCount;                   Count of parameter words = 2
435331Samw  * USHORT SetupLength;                Length of printer setup data
445331Samw  * USHORT Mode;                       0 = Text mode (DOS expands TABs)
455331Samw  *                                     1 = Graphics mode
465331Samw  * USHORT ByteCount;                  Count of data bytes;  min = 2
475331Samw  * UCHAR BufferFormat;                0x04
485331Samw  * STRING IdentifierString[];         Identifier string
495331Samw  *
505331Samw  * Tid in the SMB header must refer to a printer resource type.
515331Samw  *
525331Samw  * SetupLength is the number of bytes in the first part of the resulting
535331Samw  * print spool file which contains printer-specific control strings.
545331Samw  *
555331Samw  * Mode can have the following values:
565331Samw  *
575331Samw  *      0     Text mode.  The server may optionally
585331Samw  *            expand tabs to a series of spaces.
595331Samw  *      1     Graphics mode.  No conversion of data
605331Samw  *            should be done by the server.
615331Samw  *
625331Samw  * IdentifierString can be used by the server to provide some sort of per-
635331Samw  * client identifying component to the print file.
645331Samw  *
655331Samw  * Server Response                    Description
665331Samw  * ================================== =================================
675331Samw  *
685331Samw  * UCHAR WordCount;                   Count of parameter words = 1
695331Samw  * USHORT Fid;                        File handle
705331Samw  * USHORT ByteCount;                  Count of data bytes = 0
715331Samw  *
725331Samw  * Fid is the returned handle which may be used by subsequent write and
735331Samw  * close operations.  When the file is finally closed, it will be sent to
745331Samw  * the spooler and printed.
755331Samw  *
765331Samw  * 4.5.1.1   Errors
775331Samw  *
785331Samw  * ERRDOS/ERRnoaccess
795331Samw  * ERRDOS/ERRnofids
805331Samw  * ERRSRV/ERRinvdevice
815331Samw  * ERRSRV/ERRbaduid
825331Samw  * ERRSRV/ERRqfull
835331Samw  * ERRSRV/ERRqtoobig
845331Samw  */
856139Sjb150015 smb_sdrc_t
866139Sjb150015 smb_pre_open_print_file(smb_request_t *sr)
876139Sjb150015 {
886139Sjb150015 	DTRACE_SMB_1(op__OpenPrintFile__start, smb_request_t *, sr);
896139Sjb150015 	return (SDRC_SUCCESS);
906139Sjb150015 }
916139Sjb150015 
926139Sjb150015 void
936139Sjb150015 smb_post_open_print_file(smb_request_t *sr)
946139Sjb150015 {
956139Sjb150015 	DTRACE_SMB_1(op__OpenPrintFile__done, smb_request_t *, sr);
966139Sjb150015 }
976139Sjb150015 
986030Sjb150015 smb_sdrc_t /*ARGSUSED*/
996139Sjb150015 smb_com_open_print_file(smb_request_t *sr)
1005331Samw {
1016139Sjb150015 	return (SDRC_NOT_IMPLEMENTED);
1025331Samw }
1035331Samw 
1045331Samw 
1055331Samw /*
1065331Samw  * smb_com_close_print_file
1075331Samw  *
1085331Samw  *
1095331Samw  * This message invalidates the specified file handle and queues the file
1105331Samw  * for printing.
1115331Samw  *
1125331Samw  *   Client Request                     Description
1135331Samw  *   ================================== =================================
1145331Samw  *
1155331Samw  *   UCHAR WordCount;                   Count of parameter words = 1
1165331Samw  *   USHORT Fid;                        File handle
1175331Samw  *   USHORT ByteCount;                  Count of data bytes = 0
1185331Samw  *
1195331Samw  * Fid refers to a file previously created with SMB_COM_OPEN_PRINT_FILE.
1205331Samw  * On successful completion of this request, the file is queued for
1215331Samw  * printing by the server.
1225331Samw  *
1235331Samw  *   Server Response                    Description
1245331Samw  *   ================================== =================================
1255331Samw  *
1265331Samw  *   UCHAR WordCount;                   Count of parameter words = 0
1275331Samw  *   USHORT ByteCount;                  Count of data bytes = 0
1285331Samw  *
1295331Samw  * Servers which negotiate dialects of LANMAN1.0 and newer allow all the
1305331Samw  * other types of Fid closing requests to invalidate the Fid and begin
1315331Samw  * spooling.
1325331Samw  */
1336139Sjb150015 smb_sdrc_t
1346139Sjb150015 smb_pre_close_print_file(smb_request_t *sr)
1356139Sjb150015 {
1366139Sjb150015 	DTRACE_SMB_1(op__ClosePrintFile__start, smb_request_t *, sr);
1376139Sjb150015 	return (SDRC_SUCCESS);
1386139Sjb150015 }
1396139Sjb150015 
1406139Sjb150015 void
1416139Sjb150015 smb_post_close_print_file(smb_request_t *sr)
1426139Sjb150015 {
1436139Sjb150015 	DTRACE_SMB_1(op__ClosePrintFile__done, smb_request_t *, sr);
1446139Sjb150015 }
1456139Sjb150015 
1466030Sjb150015 smb_sdrc_t /*ARGSUSED*/
1476139Sjb150015 smb_com_close_print_file(smb_request_t *sr)
1485331Samw {
1496139Sjb150015 	return (SDRC_NOT_IMPLEMENTED);
1505331Samw }
1515331Samw 
1525331Samw 
1535331Samw /*
1545331Samw  * smb_com_get_print_queue
1555331Samw  *
1565331Samw  * This message obtains a list of the elements currently in the print queue
1575331Samw  * on the server.
1585331Samw  *
1595331Samw  *   Client Request                     Description
1605331Samw  *   ================================== =================================
1615331Samw  *
1625331Samw  *   UCHAR WordCount;                   Count of parameter words = 2
1635331Samw  *   USHORT MaxCount;                   Max number of entries to return
1645331Samw  *   USHORT StartIndex;                 First queue entry to return
1655331Samw  *   USHORT ByteCount;                  Count of data bytes = 0
1665331Samw  *
1675331Samw  * StartIndex specifies the first entry in the queue to return.
1685331Samw  *
1695331Samw  * MaxCount specifies the maximum number of entries to return, this may be
1705331Samw  * a positive or negative number.  A positive number requests a forward
1715331Samw  * search, a negative number indicates a backward search.
1725331Samw  *
1735331Samw  *   Server Response                    Description
1745331Samw  *   ================================== =================================
1755331Samw  *
1765331Samw  *   UCHAR WordCount;                   Count of parameter words = 2
1775331Samw  *   USHORT Count;                      Number of entries returned
1785331Samw  *   USHORT RestartIndex;               Index of entry after last
1795331Samw  *                                       returned
1805331Samw  *   USHORT ByteCount;                  Count of data bytes;  min = 3
1815331Samw  *   UCHAR BufferFormat;                0x01 -- Data block
1825331Samw  *   USHORT DataLength;                 Length of data
1835331Samw  *   UCHAR Data[];                      Queue elements
1845331Samw  *
1855331Samw  * Count indicates how many entries were actually returned.  RestartIndex
1865331Samw  * is the index of the entry following the last entry returned; it may be
1875331Samw  * used as the StartIndex in a subsequent request to resume the queue
1885331Samw  * listing.
1895331Samw  *
1905331Samw  * The format of each returned queue element is:
1915331Samw  *
1925331Samw  *   Queue Element Member             Description
1935331Samw  *   ================================ ===================================
1945331Samw  *
1955331Samw  *   SMB_DATE FileDate;               Date file was queued
1965331Samw  *   SMB_TIME FileTime;               Time file was queued
1975331Samw  *   UCHAR Status;                    Entry status.  One of:
1985331Samw  *                                     01 = held or stopped
1995331Samw  *                                     02 = printing
2005331Samw  *                                     03 = awaiting print
2015331Samw  *                                     04 = in intercept
2025331Samw  *                                     05 = file had error
2035331Samw  *                                     06 = printer error
2045331Samw  *                                     07-FF = reserved
2055331Samw  *   USHORT SpoolFileNumber;          Assigned by the spooler
2065331Samw  *   ULONG SpoolFileSize;             Number of bytes in spool file
2075331Samw  *   UCHAR Reserved;
2085331Samw  *   UCHAR SpoolFileName[16];         Client which created the spool file
2095331Samw  *
2105331Samw  * SMB_COM_GET_PRINT_QUEUE will return less than the requested number of
2115331Samw  * elements only when the top or end of the queue is encountered.
2125331Samw  *
2135331Samw  * Support for this SMB is server optional.  In particular, no current
2145331Samw  * Microsoft client software issues this request.
2155331Samw  *
2165331Samw  * 4.5.2.1   Errors
2175331Samw  *
2185331Samw  * ERRHRD/ERRnotready
2195331Samw  * ERRHRD/ERRerror
2205331Samw  * ERRSRV/ERRbaduid
2215331Samw  */
2226030Sjb150015 smb_sdrc_t
2236139Sjb150015 smb_pre_get_print_queue(smb_request_t *sr)
2246139Sjb150015 {
2256139Sjb150015 	DTRACE_SMB_1(op__GetPrintQueue__start, smb_request_t *, sr);
2266139Sjb150015 	return (SDRC_SUCCESS);
2276139Sjb150015 }
2286139Sjb150015 
2296139Sjb150015 void
2306139Sjb150015 smb_post_get_print_queue(smb_request_t *sr)
2316139Sjb150015 {
2326139Sjb150015 	DTRACE_SMB_1(op__GetPrintQueue__done, smb_request_t *, sr);
2336139Sjb150015 }
2346139Sjb150015 
2356139Sjb150015 smb_sdrc_t
2366139Sjb150015 smb_com_get_print_queue(smb_request_t *sr)
2375331Samw {
2385331Samw 	unsigned short max_count, start_ix;
2395331Samw 
2406030Sjb150015 	if (smbsr_decode_vwv(sr, "ww", &max_count, &start_ix) != 0)
2416139Sjb150015 		return (SDRC_ERROR);
2425331Samw 
2436030Sjb150015 	if (smbsr_encode_result(sr, 2, 3, "bwwwbw", 2, 0, 0, 3, 1, 0))
2446139Sjb150015 		return (SDRC_ERROR);
2456030Sjb150015 
2466139Sjb150015 	return (SDRC_SUCCESS);
2475331Samw }
2485331Samw 
2495331Samw 
2505331Samw /*
2515331Samw  * smb_com_write_print_file
2525331Samw  *
2535331Samw  * This message is sent to write bytes into a print spool file.
2545331Samw  *
2555331Samw  * Client Request                     Description
2565331Samw  * ================================== =================================
2575331Samw  *
2585331Samw  * UCHAR WordCount;                   Count of parameter words = 1
2595331Samw  * USHORT Fid;                        File handle
2605331Samw  * USHORT ByteCount;                  Count of data bytes;  min = 4
2615331Samw  * UCHAR BufferFormat;                0x01 -- Data block
2625331Samw  * USHORT DataLength;                 Length of data
2635331Samw  * UCHAR Data[];                      Data
2645331Samw  *
2655331Samw  * Fid indicates the print spool file to be written, it must refer to a
2665331Samw  * print spool file.
2675331Samw  *
2685331Samw  * ByteCount specifies the number of bytes to be written, and must be less
2695331Samw  * than MaxBufferSize for the Tid specified.
2705331Samw  *
2715331Samw  * Data contains the bytes to append to the print spool file.  The first
2725331Samw  * SetupLength bytes in the resulting print spool file contain printer
2735331Samw  * setup data.  SetupLength is specified in the SMB_COM_OPEN_PRINT_FILE SMB
2745331Samw  * request.
2755331Samw  *
2765331Samw  * Server Response                    Description
2775331Samw  * ================================== =================================
2785331Samw  *
2795331Samw  * UCHAR WordCount;                   Count of parameter words = 0
2805331Samw  * USHORT ByteCount;                  Count of data bytes = 0
2815331Samw  *
2825331Samw  * Servers which negotiate a protocol dialect of LANMAN1.0 or later also
2835331Samw  * support the application of normal write requests to print spool files.
2845331Samw  *
2855331Samw  */
2866139Sjb150015 smb_sdrc_t
2876139Sjb150015 smb_pre_write_print_file(smb_request_t *sr)
2885331Samw {
2896139Sjb150015 	DTRACE_SMB_1(op__WritePrintFile__start, smb_request_t *, sr);
2906139Sjb150015 	return (SDRC_SUCCESS);
2915331Samw }
2926139Sjb150015 
2936139Sjb150015 void
2946139Sjb150015 smb_post_write_print_file(smb_request_t *sr)
2956139Sjb150015 {
2966139Sjb150015 	DTRACE_SMB_1(op__WritePrintFile__done, smb_request_t *, sr);
2976139Sjb150015 }
2986139Sjb150015 
2996139Sjb150015 smb_sdrc_t /*ARGSUSED*/
3006139Sjb150015 smb_com_write_print_file(smb_request_t *sr)
3016139Sjb150015 {
3026139Sjb150015 	return (SDRC_NOT_IMPLEMENTED);
3036139Sjb150015 }
304