187866Ssheldonh/*
287866Ssheldonh * Copyright (c) 2000, Boris Popov
387866Ssheldonh * All rights reserved.
487866Ssheldonh *
587866Ssheldonh * Redistribution and use in source and binary forms, with or without
687866Ssheldonh * modification, are permitted provided that the following conditions
787866Ssheldonh * are met:
887866Ssheldonh * 1. Redistributions of source code must retain the above copyright
987866Ssheldonh *    notice, this list of conditions and the following disclaimer.
1087866Ssheldonh * 2. Redistributions in binary form must reproduce the above copyright
1187866Ssheldonh *    notice, this list of conditions and the following disclaimer in the
1287866Ssheldonh *    documentation and/or other materials provided with the distribution.
1387866Ssheldonh * 3. All advertising materials mentioning features or use of this software
1487866Ssheldonh *    must display the following acknowledgement:
1587866Ssheldonh *    This product includes software developed by Boris Popov.
1687866Ssheldonh * 4. Neither the name of the author nor the names of any co-contributors
1787866Ssheldonh *    may be used to endorse or promote products derived from this software
1887866Ssheldonh *    without specific prior written permission.
1987866Ssheldonh *
2087866Ssheldonh * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
2187866Ssheldonh * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2287866Ssheldonh * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2387866Ssheldonh * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2487866Ssheldonh * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2587866Ssheldonh * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2687866Ssheldonh * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2787866Ssheldonh * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2887866Ssheldonh * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2987866Ssheldonh * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3087866Ssheldonh * SUCH DAMAGE.
3187866Ssheldonh *
3287866Ssheldonh * $Id: print.c,v 1.4 2001/04/16 04:33:01 bp Exp $
3387866Ssheldonh */
3487866Ssheldonh#include <sys/param.h>
3587866Ssheldonh#include <sys/sysctl.h>
3687866Ssheldonh#include <sys/ioctl.h>
3787866Ssheldonh#include <sys/time.h>
3887866Ssheldonh#include <sys/mount.h>
3987866Ssheldonh#include <fcntl.h>
4087866Ssheldonh#include <ctype.h>
4187866Ssheldonh#include <errno.h>
4287866Ssheldonh#include <stdio.h>
4387866Ssheldonh#include <string.h>
4487866Ssheldonh#include <stdlib.h>
4587866Ssheldonh#include <pwd.h>
4687866Ssheldonh#include <grp.h>
4787866Ssheldonh#include <unistd.h>
4887866Ssheldonh
4987866Ssheldonh/*#include <netnb/netbios.h>*/
5087866Ssheldonh
5187866Ssheldonh#include <netsmb/smb_lib.h>
5287866Ssheldonh#include <netsmb/smb_conn.h>
5387866Ssheldonh#include <cflib.h>
5487866Ssheldonh
5587866Ssheldonhint
5687866Ssheldonhsmb_smb_open_print_file(struct smb_ctx *ctx, int setuplen, int mode,
57281550Stijl	char *ident, smbfh *fhp)
5887866Ssheldonh{
5987866Ssheldonh	struct smb_rq *rqp;
6087866Ssheldonh	struct mbdata *mbp;
6187866Ssheldonh	int error;
6287866Ssheldonh
6387866Ssheldonh	error = smb_rq_init(ctx, SMB_COM_OPEN_PRINT_FILE, 2, &rqp);
6487866Ssheldonh	if (error)
6587866Ssheldonh		return error;
6687866Ssheldonh	mbp = smb_rq_getrequest(rqp);
6787866Ssheldonh	mb_put_uint16le(mbp, setuplen);
6887866Ssheldonh	mb_put_uint16le(mbp, mode);
6987866Ssheldonh	smb_rq_wend(rqp);
7087866Ssheldonh	mb_put_uint8(mbp, SMB_DT_ASCII);
7187866Ssheldonh	smb_rq_dstring(mbp, ident);
7287866Ssheldonh	error = smb_rq_simple(rqp);
7387866Ssheldonh	if (!error) {
7487866Ssheldonh		mbp = smb_rq_getreply(rqp);
7587866Ssheldonh		mb_get_uint16(mbp, fhp);
7687866Ssheldonh	}
7787866Ssheldonh	smb_rq_done(rqp);
7887866Ssheldonh	return error;
7987866Ssheldonh}
8087866Ssheldonh
8187866Ssheldonhint
8287866Ssheldonhsmb_smb_close_print_file(struct smb_ctx *ctx, smbfh fh)
8387866Ssheldonh{
8487866Ssheldonh	struct smb_rq *rqp;
8587866Ssheldonh	struct mbdata *mbp;
8687866Ssheldonh	int error;
8787866Ssheldonh
8887866Ssheldonh	error = smb_rq_init(ctx, SMB_COM_CLOSE_PRINT_FILE, 0, &rqp);
8987866Ssheldonh	if (error)
9087866Ssheldonh		return error;
9187866Ssheldonh	mbp = smb_rq_getrequest(rqp);
9287866Ssheldonh	mb_put_mem(mbp, (char*)&fh, 2);
9387866Ssheldonh	smb_rq_wend(rqp);
9487866Ssheldonh	error = smb_rq_simple(rqp);
9587866Ssheldonh	smb_rq_done(rqp);
9687866Ssheldonh	return error;
9787866Ssheldonh}
98