1/* 2 * Copyright (c) 2000, Boris Popov 3 * All rights reserved. 4 * 5 * Portions Copyright (C) 2001 - 2010 Apple Inc. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by Boris Popov. 18 * 4. Neither the name of the author nor the names of any co-contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * $Id: print.c,v 1.1.1.3 2001/07/06 22:38:43 conrad Exp $ 35 */ 36#include <sys/param.h> 37#include <sys/sysctl.h> 38#include <sys/ioctl.h> 39#include <sys/time.h> 40#include <sys/mount.h> 41#include <fcntl.h> 42#include <ctype.h> 43#include <errno.h> 44#include <stdio.h> 45#include <string.h> 46#include <stdlib.h> 47#include <pwd.h> 48#include <grp.h> 49#include <unistd.h> 50 51#include <netsmb/upi_mbuf.h> 52#include <sys/mchain.h> 53#include <netsmb/smb_lib.h> 54#include <netsmb/rq.h> 55#include <netsmb/smb_conn.h> 56#include <netsmb/smb_converter.h> 57 58int 59smb_smb_open_print_file(struct smb_ctx *ctx, int setuplen, int mode, 60 const char *ident, smbfh *fhp) 61{ 62 struct smb_usr_rq *rqp; 63 mbchain_t mbp; 64 int error; 65 66 error = smb_usr_rq_init(ctx, SMB_COM_OPEN_PRINT_FILE, 0, &rqp); 67 if (error) 68 return error; 69 mbp = smb_usr_rq_getrequest(rqp); 70 smb_usr_rq_wstart(rqp); 71 mb_put_uint16le(mbp, setuplen); 72 mb_put_uint16le(mbp, mode); 73 smb_usr_rq_wend(rqp); 74 smb_usr_rq_bstart(rqp); 75 mb_put_uint8(mbp, SMB_DT_ASCII); 76 smb_usr_rq_put_dstring(ctx, mbp, ident, strlen(ident), SMB_UTF_SFM_CONVERSIONS, NULL); 77 smb_usr_rq_bend(rqp); 78 error = smb_usr_rq_simple(rqp); 79 if (!error) { 80 mdchain_t mdp; 81 82 mdp = smb_usr_rq_getreply(rqp); 83 md_get_uint8(mdp, NULL); /* Word Count */ 84 md_get_uint16(mdp, fhp); 85 } 86 smb_usr_rq_done(rqp); 87 return error; 88} 89 90int 91smb_smb_close_print_file(struct smb_ctx *ctx, smbfh fh) 92{ 93 struct smb_usr_rq *rqp; 94 mbchain_t mbp; 95 int error; 96 97 error = smb_usr_rq_init(ctx, SMB_COM_CLOSE_PRINT_FILE, 0, &rqp); 98 if (error) 99 return error; 100 mbp = smb_usr_rq_getrequest(rqp); 101 smb_usr_rq_wstart(rqp); 102 mb_put_mem(mbp, (char*)&fh, 2, MB_MSYSTEM); 103 smb_usr_rq_wend(rqp); 104 smb_usr_rq_bstart(rqp); 105 smb_usr_rq_bend(rqp); 106 error = smb_usr_rq_simple(rqp); 107 smb_usr_rq_done(rqp); 108 return error; 109} 110