14bff34e3Sthurlow /* 2*430b4c46SGordon Ross * Copyright 2011 Nexenta Systems, Inc. All rights reserved. 34bff34e3Sthurlow * Copyright (c) 2000, Boris Popov 44bff34e3Sthurlow * All rights reserved. 54bff34e3Sthurlow * 64bff34e3Sthurlow * Redistribution and use in source and binary forms, with or without 74bff34e3Sthurlow * modification, are permitted provided that the following conditions 84bff34e3Sthurlow * are met: 94bff34e3Sthurlow * 1. Redistributions of source code must retain the above copyright 104bff34e3Sthurlow * notice, this list of conditions and the following disclaimer. 114bff34e3Sthurlow * 2. Redistributions in binary form must reproduce the above copyright 124bff34e3Sthurlow * notice, this list of conditions and the following disclaimer in the 134bff34e3Sthurlow * documentation and/or other materials provided with the distribution. 144bff34e3Sthurlow * 3. All advertising materials mentioning features or use of this software 154bff34e3Sthurlow * must display the following acknowledgement: 164bff34e3Sthurlow * This product includes software developed by Boris Popov. 174bff34e3Sthurlow * 4. Neither the name of the author nor the names of any co-contributors 184bff34e3Sthurlow * may be used to endorse or promote products derived from this software 194bff34e3Sthurlow * without specific prior written permission. 204bff34e3Sthurlow * 214bff34e3Sthurlow * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 224bff34e3Sthurlow * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 234bff34e3Sthurlow * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 244bff34e3Sthurlow * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 254bff34e3Sthurlow * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 264bff34e3Sthurlow * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 274bff34e3Sthurlow * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 284bff34e3Sthurlow * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 294bff34e3Sthurlow * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 304bff34e3Sthurlow * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 314bff34e3Sthurlow * SUCH DAMAGE. 324bff34e3Sthurlow * 334bff34e3Sthurlow * $Id: print.c,v 1.1.1.3 2001/07/06 22:38:43 conrad Exp $ 344bff34e3Sthurlow */ 354bff34e3Sthurlow 364bff34e3Sthurlow #include <sys/param.h> 374bff34e3Sthurlow #include <sys/ioctl.h> 384bff34e3Sthurlow #include <sys/time.h> 394bff34e3Sthurlow #include <sys/mount.h> 404bff34e3Sthurlow #include <fcntl.h> 414bff34e3Sthurlow #include <ctype.h> 424bff34e3Sthurlow #include <errno.h> 434bff34e3Sthurlow #include <stdio.h> 444bff34e3Sthurlow #include <string.h> 45*430b4c46SGordon Ross #include <strings.h> 464bff34e3Sthurlow #include <stdlib.h> 474bff34e3Sthurlow #include <pwd.h> 484bff34e3Sthurlow #include <grp.h> 494bff34e3Sthurlow #include <unistd.h> 50*430b4c46SGordon Ross #include <libintl.h> 514bff34e3Sthurlow 52613a2f6bSGordon Ross #include <netsmb/smb.h> 534bff34e3Sthurlow #include <netsmb/smb_lib.h> 54*430b4c46SGordon Ross 559c9af259SGordon Ross #include "private.h" 564bff34e3Sthurlow 574bff34e3Sthurlow int 58*430b4c46SGordon Ross smb_open_printer(struct smb_ctx *ctx, const char *title, 59*430b4c46SGordon Ross int setuplen, int mode) 604bff34e3Sthurlow { 61*430b4c46SGordon Ross smbioc_printjob_t ioc; 62*430b4c46SGordon Ross int err, tlen, new_fd; 63*430b4c46SGordon Ross int32_t from_fd; 644bff34e3Sthurlow 65*430b4c46SGordon Ross tlen = strlen(title); 66*430b4c46SGordon Ross if (tlen >= SMBIOC_MAX_NAME) 67*430b4c46SGordon Ross return (EINVAL); 68613a2f6bSGordon Ross 69*430b4c46SGordon Ross /* 70*430b4c46SGordon Ross * Will represent this SMB-level open as a new 71*430b4c46SGordon Ross * open device handle. Get one, then duplicate 72*430b4c46SGordon Ross * the driver session and tree bindings. 73*430b4c46SGordon Ross */ 74*430b4c46SGordon Ross new_fd = smb_open_driver(); 75*430b4c46SGordon Ross if (new_fd < 0) 76*430b4c46SGordon Ross return (errno); 77*430b4c46SGordon Ross from_fd = ctx->ct_dev_fd; 78*430b4c46SGordon Ross if (ioctl(new_fd, SMBIOC_DUP_DEV, &from_fd) == -1) { 79*430b4c46SGordon Ross err = errno; 80*430b4c46SGordon Ross goto errout; 814bff34e3Sthurlow } 824bff34e3Sthurlow 83613a2f6bSGordon Ross /* 84*430b4c46SGordon Ross * Do the SMB-level open with the new dev handle. 85613a2f6bSGordon Ross */ 86*430b4c46SGordon Ross bzero(&ioc, sizeof (ioc)); 87*430b4c46SGordon Ross ioc.ioc_setuplen = setuplen; 88*430b4c46SGordon Ross ioc.ioc_prmode = mode; 89*430b4c46SGordon Ross strlcpy(ioc.ioc_title, title, SMBIOC_MAX_NAME); 904bff34e3Sthurlow 91*430b4c46SGordon Ross if (ioctl(new_fd, SMBIOC_PRINTJOB, &ioc) == -1) { 92*430b4c46SGordon Ross err = errno; 93*430b4c46SGordon Ross goto errout; 94*430b4c46SGordon Ross } 95613a2f6bSGordon Ross 96*430b4c46SGordon Ross return (new_fd); 97613a2f6bSGordon Ross 98*430b4c46SGordon Ross errout: 99*430b4c46SGordon Ross close(new_fd); 100*430b4c46SGordon Ross errno = err; 101*430b4c46SGordon Ross return (-1); 1024bff34e3Sthurlow } 103