xref: /titanic_50/usr/src/lib/libsmbfs/smb/print.c (revision 613a2f6ba31e891e3d947a356daf5e563d43c1ce)
14bff34e3Sthurlow /*
24bff34e3Sthurlow  * Copyright (c) 2000, Boris Popov
34bff34e3Sthurlow  * All rights reserved.
44bff34e3Sthurlow  *
54bff34e3Sthurlow  * Redistribution and use in source and binary forms, with or without
64bff34e3Sthurlow  * modification, are permitted provided that the following conditions
74bff34e3Sthurlow  * are met:
84bff34e3Sthurlow  * 1. Redistributions of source code must retain the above copyright
94bff34e3Sthurlow  *    notice, this list of conditions and the following disclaimer.
104bff34e3Sthurlow  * 2. Redistributions in binary form must reproduce the above copyright
114bff34e3Sthurlow  *    notice, this list of conditions and the following disclaimer in the
124bff34e3Sthurlow  *    documentation and/or other materials provided with the distribution.
134bff34e3Sthurlow  * 3. All advertising materials mentioning features or use of this software
144bff34e3Sthurlow  *    must display the following acknowledgement:
154bff34e3Sthurlow  *    This product includes software developed by Boris Popov.
164bff34e3Sthurlow  * 4. Neither the name of the author nor the names of any co-contributors
174bff34e3Sthurlow  *    may be used to endorse or promote products derived from this software
184bff34e3Sthurlow  *    without specific prior written permission.
194bff34e3Sthurlow  *
204bff34e3Sthurlow  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
214bff34e3Sthurlow  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
224bff34e3Sthurlow  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
234bff34e3Sthurlow  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
244bff34e3Sthurlow  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
254bff34e3Sthurlow  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
264bff34e3Sthurlow  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
274bff34e3Sthurlow  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
284bff34e3Sthurlow  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
294bff34e3Sthurlow  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
304bff34e3Sthurlow  * SUCH DAMAGE.
314bff34e3Sthurlow  *
324bff34e3Sthurlow  * $Id: print.c,v 1.1.1.3 2001/07/06 22:38:43 conrad Exp $
334bff34e3Sthurlow  */
344bff34e3Sthurlow 
354bff34e3Sthurlow #include <sys/param.h>
364bff34e3Sthurlow #include <sys/ioctl.h>
374bff34e3Sthurlow #include <sys/time.h>
384bff34e3Sthurlow #include <sys/mount.h>
394bff34e3Sthurlow #include <fcntl.h>
404bff34e3Sthurlow #include <ctype.h>
414bff34e3Sthurlow #include <errno.h>
424bff34e3Sthurlow #include <stdio.h>
434bff34e3Sthurlow #include <string.h>
444bff34e3Sthurlow #include <stdlib.h>
454bff34e3Sthurlow #include <pwd.h>
464bff34e3Sthurlow #include <grp.h>
474bff34e3Sthurlow #include <unistd.h>
484bff34e3Sthurlow 
49*613a2f6bSGordon Ross #include <netsmb/smb.h>
504bff34e3Sthurlow #include <netsmb/smb_lib.h>
519c9af259SGordon Ross #include "private.h"
524bff34e3Sthurlow 
534bff34e3Sthurlow int
54*613a2f6bSGordon Ross smb_printer_open(struct smb_ctx *ctx, int setuplen, int mode,
55*613a2f6bSGordon Ross 	const char *ident, int *fhp)
564bff34e3Sthurlow {
574bff34e3Sthurlow 	struct smb_rq *rqp;
584bff34e3Sthurlow 	struct mbdata *mbp;
59*613a2f6bSGordon Ross 	int error, flags2, uc;
60*613a2f6bSGordon Ross 	uint16_t fh;
61*613a2f6bSGordon Ross 	uint8_t wc;
624bff34e3Sthurlow 
63*613a2f6bSGordon Ross 	flags2 = smb_ctx_flags2(ctx);
64*613a2f6bSGordon Ross 	if (flags2 == -1)
65*613a2f6bSGordon Ross 		return (EIO);
66*613a2f6bSGordon Ross 	uc = flags2 & SMB_FLAGS2_UNICODE;
67*613a2f6bSGordon Ross 
68*613a2f6bSGordon Ross 	error = smb_rq_init(ctx, SMB_COM_OPEN_PRINT_FILE, &rqp);
694bff34e3Sthurlow 	if (error)
704bff34e3Sthurlow 		return (error);
714bff34e3Sthurlow 	mbp = smb_rq_getrequest(rqp);
72*613a2f6bSGordon Ross 	smb_rq_wstart(rqp);
734bff34e3Sthurlow 	mb_put_uint16le(mbp, setuplen);
744bff34e3Sthurlow 	mb_put_uint16le(mbp, mode);
754bff34e3Sthurlow 	smb_rq_wend(rqp);
76*613a2f6bSGordon Ross 	smb_rq_bstart(rqp);
774bff34e3Sthurlow 	mb_put_uint8(mbp, SMB_DT_ASCII);
78*613a2f6bSGordon Ross 	mb_put_dstring(mbp, ident, uc);
79*613a2f6bSGordon Ross 	smb_rq_bend(rqp);
804bff34e3Sthurlow 	error = smb_rq_simple(rqp);
81*613a2f6bSGordon Ross 	if (error)
82*613a2f6bSGordon Ross 		goto out;
83*613a2f6bSGordon Ross 
844bff34e3Sthurlow 	mbp = smb_rq_getreply(rqp);
85*613a2f6bSGordon Ross 	error = mb_get_uint8(mbp, &wc);
86*613a2f6bSGordon Ross 	if (error || wc < 1) {
87*613a2f6bSGordon Ross 		error = EBADRPC;
88*613a2f6bSGordon Ross 		goto out;
894bff34e3Sthurlow 	}
90*613a2f6bSGordon Ross 	mb_get_uint16(mbp, &fh);
91*613a2f6bSGordon Ross 	*fhp = fh;
92*613a2f6bSGordon Ross 	error = 0;
93*613a2f6bSGordon Ross 
94*613a2f6bSGordon Ross out:
954bff34e3Sthurlow 	smb_rq_done(rqp);
964bff34e3Sthurlow 	return (error);
974bff34e3Sthurlow }
984bff34e3Sthurlow 
99*613a2f6bSGordon Ross /*
100*613a2f6bSGordon Ross  * Similar to smb_fh_close
101*613a2f6bSGordon Ross  */
1024bff34e3Sthurlow int
103*613a2f6bSGordon Ross smb_printer_close(struct smb_ctx *ctx, int fh)
1044bff34e3Sthurlow {
1054bff34e3Sthurlow 	struct smb_rq *rqp;
1064bff34e3Sthurlow 	struct mbdata *mbp;
1074bff34e3Sthurlow 	int error;
1084bff34e3Sthurlow 
109*613a2f6bSGordon Ross 	error = smb_rq_init(ctx, SMB_COM_CLOSE_PRINT_FILE, &rqp);
1104bff34e3Sthurlow 	if (error)
1114bff34e3Sthurlow 		return (error);
1124bff34e3Sthurlow 	mbp = smb_rq_getrequest(rqp);
113*613a2f6bSGordon Ross 	smb_rq_wstart(rqp);
114*613a2f6bSGordon Ross 	mb_put_uint16le(mbp, (uint16_t)fh);
1154bff34e3Sthurlow 	smb_rq_wend(rqp);
116*613a2f6bSGordon Ross 	mb_put_uint16le(mbp, 0);	/* byte count */
117*613a2f6bSGordon Ross 
1184bff34e3Sthurlow 	error = smb_rq_simple(rqp);
1194bff34e3Sthurlow 	smb_rq_done(rqp);
120*613a2f6bSGordon Ross 
1214bff34e3Sthurlow 	return (error);
1224bff34e3Sthurlow }
123