xref: /onnv-gate/usr/src/lib/libsmbfs/smb/print.c (revision 11332:ed3411181494)
16007Sthurlow /*
26007Sthurlow  * Copyright (c) 2000, Boris Popov
36007Sthurlow  * All rights reserved.
46007Sthurlow  *
56007Sthurlow  * Redistribution and use in source and binary forms, with or without
66007Sthurlow  * modification, are permitted provided that the following conditions
76007Sthurlow  * are met:
86007Sthurlow  * 1. Redistributions of source code must retain the above copyright
96007Sthurlow  *    notice, this list of conditions and the following disclaimer.
106007Sthurlow  * 2. Redistributions in binary form must reproduce the above copyright
116007Sthurlow  *    notice, this list of conditions and the following disclaimer in the
126007Sthurlow  *    documentation and/or other materials provided with the distribution.
136007Sthurlow  * 3. All advertising materials mentioning features or use of this software
146007Sthurlow  *    must display the following acknowledgement:
156007Sthurlow  *    This product includes software developed by Boris Popov.
166007Sthurlow  * 4. Neither the name of the author nor the names of any co-contributors
176007Sthurlow  *    may be used to endorse or promote products derived from this software
186007Sthurlow  *    without specific prior written permission.
196007Sthurlow  *
206007Sthurlow  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
216007Sthurlow  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
226007Sthurlow  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
236007Sthurlow  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
246007Sthurlow  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
256007Sthurlow  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
266007Sthurlow  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
276007Sthurlow  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
286007Sthurlow  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
296007Sthurlow  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
306007Sthurlow  * SUCH DAMAGE.
316007Sthurlow  *
326007Sthurlow  * $Id: print.c,v 1.1.1.3 2001/07/06 22:38:43 conrad Exp $
336007Sthurlow  */
346007Sthurlow 
356007Sthurlow #include <sys/param.h>
366007Sthurlow #include <sys/ioctl.h>
376007Sthurlow #include <sys/time.h>
386007Sthurlow #include <sys/mount.h>
396007Sthurlow #include <fcntl.h>
406007Sthurlow #include <ctype.h>
416007Sthurlow #include <errno.h>
426007Sthurlow #include <stdio.h>
436007Sthurlow #include <string.h>
446007Sthurlow #include <stdlib.h>
456007Sthurlow #include <pwd.h>
466007Sthurlow #include <grp.h>
476007Sthurlow #include <unistd.h>
486007Sthurlow 
4910023SGordon.Ross@Sun.COM #include <netsmb/smb.h>
506007Sthurlow #include <netsmb/smb_lib.h>
518271SGordon.Ross@Sun.COM #include "private.h"
526007Sthurlow 
536007Sthurlow int
smb_printer_open(struct smb_ctx * ctx,int setuplen,int mode,const char * ident,int * fhp)5410023SGordon.Ross@Sun.COM smb_printer_open(struct smb_ctx *ctx, int setuplen, int mode,
5510023SGordon.Ross@Sun.COM 	const char *ident, int *fhp)
5610023SGordon.Ross@Sun.COM {
5710023SGordon.Ross@Sun.COM 	struct smb_rq *rqp;
5810023SGordon.Ross@Sun.COM 	struct mbdata *mbp;
5910023SGordon.Ross@Sun.COM 	int error, flags2, uc;
6010023SGordon.Ross@Sun.COM 	uint16_t fh;
6110023SGordon.Ross@Sun.COM 	uint8_t wc;
6210023SGordon.Ross@Sun.COM 
6310023SGordon.Ross@Sun.COM 	flags2 = smb_ctx_flags2(ctx);
6410023SGordon.Ross@Sun.COM 	if (flags2 == -1)
6510023SGordon.Ross@Sun.COM 		return (EIO);
6610023SGordon.Ross@Sun.COM 	uc = flags2 & SMB_FLAGS2_UNICODE;
6710023SGordon.Ross@Sun.COM 
6810023SGordon.Ross@Sun.COM 	error = smb_rq_init(ctx, SMB_COM_OPEN_PRINT_FILE, &rqp);
6910023SGordon.Ross@Sun.COM 	if (error)
7010023SGordon.Ross@Sun.COM 		return (error);
7110023SGordon.Ross@Sun.COM 	mbp = smb_rq_getrequest(rqp);
7210023SGordon.Ross@Sun.COM 	smb_rq_wstart(rqp);
7310023SGordon.Ross@Sun.COM 	mb_put_uint16le(mbp, setuplen);
7410023SGordon.Ross@Sun.COM 	mb_put_uint16le(mbp, mode);
7510023SGordon.Ross@Sun.COM 	smb_rq_wend(rqp);
7610023SGordon.Ross@Sun.COM 	smb_rq_bstart(rqp);
7710023SGordon.Ross@Sun.COM 	mb_put_uint8(mbp, SMB_DT_ASCII);
78*11332SGordon.Ross@Sun.COM 	mb_put_string(mbp, ident, uc);
7910023SGordon.Ross@Sun.COM 	smb_rq_bend(rqp);
8010023SGordon.Ross@Sun.COM 	error = smb_rq_simple(rqp);
8110023SGordon.Ross@Sun.COM 	if (error)
8210023SGordon.Ross@Sun.COM 		goto out;
8310023SGordon.Ross@Sun.COM 
8410023SGordon.Ross@Sun.COM 	mbp = smb_rq_getreply(rqp);
85*11332SGordon.Ross@Sun.COM 	error = md_get_uint8(mbp, &wc);
8610023SGordon.Ross@Sun.COM 	if (error || wc < 1) {
8710023SGordon.Ross@Sun.COM 		error = EBADRPC;
8810023SGordon.Ross@Sun.COM 		goto out;
8910023SGordon.Ross@Sun.COM 	}
90*11332SGordon.Ross@Sun.COM 	md_get_uint16le(mbp, &fh);
9110023SGordon.Ross@Sun.COM 	*fhp = fh;
9210023SGordon.Ross@Sun.COM 	error = 0;
9310023SGordon.Ross@Sun.COM 
9410023SGordon.Ross@Sun.COM out:
9510023SGordon.Ross@Sun.COM 	smb_rq_done(rqp);
9610023SGordon.Ross@Sun.COM 	return (error);
9710023SGordon.Ross@Sun.COM }
9810023SGordon.Ross@Sun.COM 
9910023SGordon.Ross@Sun.COM /*
10010023SGordon.Ross@Sun.COM  * Similar to smb_fh_close
10110023SGordon.Ross@Sun.COM  */
10210023SGordon.Ross@Sun.COM int
smb_printer_close(struct smb_ctx * ctx,int fh)10310023SGordon.Ross@Sun.COM smb_printer_close(struct smb_ctx *ctx, int fh)
1046007Sthurlow {
1056007Sthurlow 	struct smb_rq *rqp;
1066007Sthurlow 	struct mbdata *mbp;
1076007Sthurlow 	int error;
1086007Sthurlow 
10910023SGordon.Ross@Sun.COM 	error = smb_rq_init(ctx, SMB_COM_CLOSE_PRINT_FILE, &rqp);
1106007Sthurlow 	if (error)
1116007Sthurlow 		return (error);
1126007Sthurlow 	mbp = smb_rq_getrequest(rqp);
11310023SGordon.Ross@Sun.COM 	smb_rq_wstart(rqp);
11410023SGordon.Ross@Sun.COM 	mb_put_uint16le(mbp, (uint16_t)fh);
1156007Sthurlow 	smb_rq_wend(rqp);
11610023SGordon.Ross@Sun.COM 	mb_put_uint16le(mbp, 0);	/* byte count */
11710023SGordon.Ross@Sun.COM 
1186007Sthurlow 	error = smb_rq_simple(rqp);
1196007Sthurlow 	smb_rq_done(rqp);
12010023SGordon.Ross@Sun.COM 
1216007Sthurlow 	return (error);
1226007Sthurlow }
123