Mercurial > illumos > illumos-gate
annotate usr/src/cmd/fs.d/smbclnt/smbutil/print.c @ 13394:96340372b72d
1120 Use real file descriptors for smbfs named pipes.
Reviewed by: Eric Schrock <eric.schrock@delphix.com>
Reviewed by: Albert Lee <trisk@nexenta.com>
Approved by: Garrett D'Amore <garrett@nexenta.com>
author | Gordon Ross <gwr@nexenta.com> |
---|---|
date | Thu, 30 Jun 2011 17:58:05 -0400 |
parents | 71bf38dba3d6 |
children |
rev | line source |
---|---|
6007 | 1 /* |
2 * Copyright (c) 2000, Boris Popov | |
3 * All rights reserved. | |
4 * | |
5 * Redistribution and use in source and binary forms, with or without | |
6 * modification, are permitted provided that the following conditions | |
7 * are met: | |
8 * 1. Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * 2. Redistributions in binary form must reproduce the above copyright | |
11 * notice, this list of conditions and the following disclaimer in the | |
12 * documentation and/or other materials provided with the distribution. | |
13 * 3. All advertising materials mentioning features or use of this software | |
14 * must display the following acknowledgement: | |
15 * This product includes software developed by Boris Popov. | |
16 * 4. Neither the name of the author nor the names of any co-contributors | |
17 * may be used to endorse or promote products derived from this software | |
18 * without specific prior written permission. | |
19 * | |
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | |
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | |
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
30 * SUCH DAMAGE. | |
31 * | |
10023
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
32 * from: Id: print.c,v 1.4 2001/01/28 07:35:01 bp Exp |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
33 */ |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
34 |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
35 /* |
13394
96340372b72d
1120 Use real file descriptors for smbfs named pipes.
Gordon Ross <gwr@nexenta.com>
parents:
10023
diff
changeset
|
36 * Copyright 2011 Nexenta Systems, Inc. All rights reserved. |
10023
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
37 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
38 * Use is subject to license terms. |
6007 | 39 */ |
40 | |
10023
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
41 #include <sys/types.h> |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
42 #include <err.h> |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
43 #include <errno.h> |
6007 | 44 #include <fcntl.h> |
45 #include <stdio.h> | |
10023
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
46 #include <string.h> |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
47 #include <stdlib.h> |
6007 | 48 #include <unistd.h> |
49 #include <libintl.h> | |
50 | |
51 #include <cflib.h> | |
52 | |
53 #include <netsmb/smb_lib.h> | |
54 | |
55 #include "common.h" | |
56 | |
10023
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
57 static char titlebuf[256]; |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
58 static char databuf[4096]; |
6007 | 59 |
10023
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
60 static int print_file(smb_ctx_t *, char *, int); |
6007 | 61 |
62 void | |
63 print_usage(void) | |
64 { | |
65 printf(gettext("usage: smbutil print [connection options] //" | |
66 "[workgroup;][user[:password]@]" | |
10023
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
67 "server/share {print_file|-}\n")); |
6007 | 68 exit(1); |
69 } | |
10023
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
70 |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
71 int |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
72 cmd_print(int argc, char *argv[]) |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
73 { |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
74 struct smb_ctx *ctx = NULL; |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
75 char *filename; |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
76 int error, opt; |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
77 int file = -1; |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
78 |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
79 /* last arg is the print file. */ |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
80 if (argc < 3) |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
81 print_usage(); |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
82 |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
83 error = smb_ctx_alloc(&ctx); |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
84 if (error) |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
85 goto out; |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
86 |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
87 error = smb_ctx_scan_argv(ctx, argc-1, argv, |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
88 SMBL_SHARE, SMBL_SHARE, USE_SPOOLDEV); |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
89 if (error) |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
90 goto out; |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
91 |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
92 error = smb_ctx_readrc(ctx); |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
93 if (error) |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
94 goto out; |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
95 |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
96 while ((opt = getopt(argc-1, argv, STDPARAM_OPT)) != EOF) { |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
97 if (opt == '?') |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
98 print_usage(); |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
99 error = smb_ctx_opt(ctx, opt, optarg); |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
100 if (error) |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
101 goto out; |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
102 } |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
103 if (optind != argc-2) |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
104 print_usage(); |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
105 filename = argv[argc-1]; |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
106 |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
107 if (strcmp(filename, "-") == 0) { |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
108 file = 0; /* stdin */ |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
109 filename = "stdin"; |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
110 } else { |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
111 file = open(filename, O_RDONLY, 0); |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
112 if (file < 0) { |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
113 smb_error("could not open file %s\n", errno, filename); |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
114 exit(1); |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
115 } |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
116 } |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
117 |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
118 /* |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
119 * Resolve the server address, |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
120 * setup derived defaults. |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
121 */ |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
122 error = smb_ctx_resolve(ctx); |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
123 if (error) |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
124 goto out; |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
125 |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
126 /* |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
127 * Have server + share names, options etc. |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
128 * Get the session and tree. |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
129 */ |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
130 again: |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
131 error = smb_ctx_get_ssn(ctx); |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
132 if (error == EAUTH) { |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
133 int err2 = smb_get_authentication(ctx); |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
134 if (err2 == 0) |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
135 goto again; |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
136 } |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
137 if (error) { |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
138 smb_error(gettext("//%s: login failed"), |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
139 error, ctx->ct_fullserver); |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
140 goto out; |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
141 } |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
142 |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
143 error = smb_ctx_get_tree(ctx); |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
144 if (error) { |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
145 smb_error(gettext("//%s/%s: tree connect failed"), |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
146 error, ctx->ct_fullserver, ctx->ct_origshare); |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
147 goto out; |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
148 } |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
149 |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
150 /* |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
151 * Have the printer share connection. |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
152 * Print the file. |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
153 */ |
13394
96340372b72d
1120 Use real file descriptors for smbfs named pipes.
Gordon Ross <gwr@nexenta.com>
parents:
10023
diff
changeset
|
154 snprintf(titlebuf, sizeof (titlebuf), "%s %s", |
10023
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
155 ctx->ct_user, filename); |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
156 |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
157 error = print_file(ctx, titlebuf, file); |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
158 |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
159 |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
160 out: |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
161 /* don't close stdin (file=0) */ |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
162 if (file > 0) |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
163 close(file); |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
164 |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
165 smb_ctx_free(ctx); |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
166 |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
167 return (error); |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
168 } |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
169 |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
170 /* |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
171 * Documentation for OPEN_PRINT_FILE is scarse. |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
172 * It's in a 1996 MS doc. entitled: |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
173 * SMB FILE SHARING PROTOCOL |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
174 * |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
175 * The extra parameters are: |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
176 * SetupLength: what part of the file is printer setup |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
177 * Mode: text or graphics (raw data) |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
178 * IdentifierString: job title |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
179 */ |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
180 enum { |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
181 MODE_TEXT = 0, /* TAB expansion, etc. */ |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
182 MODE_GRAPHICS /* raw data */ |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
183 }; |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
184 |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
185 static int |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
186 print_file(smb_ctx_t *ctx, char *title, int file) |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
187 { |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
188 off_t offset; |
13394
96340372b72d
1120 Use real file descriptors for smbfs named pipes.
Gordon Ross <gwr@nexenta.com>
parents:
10023
diff
changeset
|
189 int rcnt, wcnt; |
10023
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
190 int setup_len = 0; /* No printer setup data */ |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
191 int mode = MODE_GRAPHICS; /* treat as raw data */ |
13394
96340372b72d
1120 Use real file descriptors for smbfs named pipes.
Gordon Ross <gwr@nexenta.com>
parents:
10023
diff
changeset
|
192 int error = 0; |
96340372b72d
1120 Use real file descriptors for smbfs named pipes.
Gordon Ross <gwr@nexenta.com>
parents:
10023
diff
changeset
|
193 int pfd = -1; |
10023
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
194 |
13394
96340372b72d
1120 Use real file descriptors for smbfs named pipes.
Gordon Ross <gwr@nexenta.com>
parents:
10023
diff
changeset
|
195 pfd = smb_open_printer(ctx, title, setup_len, mode); |
96340372b72d
1120 Use real file descriptors for smbfs named pipes.
Gordon Ross <gwr@nexenta.com>
parents:
10023
diff
changeset
|
196 if (pfd < 0) { |
96340372b72d
1120 Use real file descriptors for smbfs named pipes.
Gordon Ross <gwr@nexenta.com>
parents:
10023
diff
changeset
|
197 error = errno; |
10023
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
198 smb_error("could not open print job", error); |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
199 return (error); |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
200 } |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
201 |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
202 offset = 0; |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
203 for (;;) { |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
204 rcnt = read(file, databuf, sizeof (databuf)); |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
205 if (rcnt < 0) { |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
206 error = errno; |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
207 smb_error("error reading input file\n", error); |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
208 break; |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
209 } |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
210 if (rcnt == 0) |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
211 break; |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
212 |
13394
96340372b72d
1120 Use real file descriptors for smbfs named pipes.
Gordon Ross <gwr@nexenta.com>
parents:
10023
diff
changeset
|
213 wcnt = smb_fh_write(pfd, offset, rcnt, databuf); |
10023
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
214 if (wcnt < 0) { |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
215 error = errno; |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
216 smb_error("error writing spool file\n", error); |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
217 break; |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
218 } |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
219 if (wcnt != rcnt) { |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
220 smb_error("incomplete write to spool file\n", 0); |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
221 error = EIO; |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
222 break; |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
223 } |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
224 offset += wcnt; |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
225 } |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
226 |
13394
96340372b72d
1120 Use real file descriptors for smbfs named pipes.
Gordon Ross <gwr@nexenta.com>
parents:
10023
diff
changeset
|
227 (void) smb_fh_close(pfd); |
10023
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
228 return (error); |
71bf38dba3d6
6584198 SMB Client needs authentication improvements
Gordon Ross <Gordon.Ross@Sun.COM>
parents:
6007
diff
changeset
|
229 } |