2 Unix SMB/Netbios implementation.
3 SMB client library implementation
4 Copyright (C) Andrew Tridgell 1998
5 Copyright (C) Richard Sharpe 2000, 2002
6 Copyright (C) John Terpstra 2000
7 Copyright (C) Tom Jansen (Ninja ISD) 2002
8 Copyright (C) Derrell Lipman 2003-2008
9 Copyright (C) Jeremy Allison 2007, 2008
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include "libsmb/libsmb.h"
27 #include "libsmbclient.h"
28 #include "libsmb_internal.h"
32 * Open a print file to be written to by other calls
36 SMBC_open_print_job_ctx(SMBCCTX
*context
,
42 char *password
= NULL
;
44 TALLOC_CTX
*frame
= talloc_stackframe();
46 if (!context
|| !context
->internal
->initialized
) {
58 DEBUG(4, ("SMBC_open_print_job_ctx(%s)\n", fname
));
60 if (SMBC_parse_path(frame
,
75 /* What if the path is empty, or the file exists? */
78 return smbc_getFunctionOpen(context
)(context
, fname
, O_WRONLY
, 666);
82 * Routine to print a file on a remote server ...
84 * We open the file, which we assume to be on a remote server, and then
85 * copy it to a print file on the share specified by printq.
89 SMBC_print_file_ctx(SMBCCTX
*c_file
,
100 TALLOC_CTX
*frame
= talloc_stackframe();
102 if (!c_file
|| !c_file
->internal
->initialized
||
103 !c_print
|| !c_print
->internal
->initialized
) {
109 if (!fname
&& !printq
) {
115 /* Try to open the file for reading ... */
117 if ((long)(fid1
= smbc_getFunctionOpen(c_file
)(c_file
, fname
,
118 O_RDONLY
, 0666)) < 0) {
119 DEBUG(3, ("Error, fname=%s, errno=%i\n", fname
, errno
));
121 return -1; /* smbc_open sets errno */
124 /* Now, try to open the printer file for writing */
126 if ((long)(fid2
= smbc_getFunctionOpenPrintJob(c_print
)(c_print
,
128 saverr
= errno
; /* Save errno */
129 smbc_getFunctionClose(c_file
)(c_file
, fid1
);
135 while ((bytes
= smbc_getFunctionRead(c_file
)(c_file
, fid1
,
136 buf
, sizeof(buf
))) > 0) {
139 if ((smbc_getFunctionWrite(c_print
)(c_print
, fid2
,
142 smbc_getFunctionClose(c_file
)(c_file
, fid1
);
143 smbc_getFunctionClose(c_print
)(c_print
, fid2
);
150 smbc_getFunctionClose(c_file
)(c_file
, fid1
);
151 smbc_getFunctionClose(c_print
)(c_print
, fid2
);
164 * Routine to list print jobs on a printer share ...
168 SMBC_list_print_jobs_ctx(SMBCCTX
*context
,
170 smbc_list_print_job_fn fn
)
176 char *password
= NULL
;
177 char *workgroup
= NULL
;
179 TALLOC_CTX
*frame
= talloc_stackframe();
181 if (!context
|| !context
->internal
->initialized
) {
193 DEBUG(4, ("smbc_list_print_jobs(%s)\n", fname
));
195 if (SMBC_parse_path(frame
,
210 if (!user
|| user
[0] == (char)0) {
211 user
= talloc_strdup(frame
, smbc_getUser(context
));
219 srv
= SMBC_server(frame
, context
, True
,
220 server
, share
, &workgroup
, &user
, &password
);
224 return -1; /* errno set by SMBC_server */
227 if (cli_print_queue(srv
->cli
,
228 (void (*)(struct print_job_info
*))fn
) < 0) {
229 errno
= SMBC_errno(context
, srv
->cli
);
239 * Delete a print job from a remote printer share
243 SMBC_unlink_print_job_ctx(SMBCCTX
*context
,
251 char *password
= NULL
;
252 char *workgroup
= NULL
;
255 TALLOC_CTX
*frame
= talloc_stackframe();
257 if (!context
|| !context
->internal
->initialized
) {
269 DEBUG(4, ("smbc_unlink_print_job(%s)\n", fname
));
271 if (SMBC_parse_path(frame
,
286 if (!user
|| user
[0] == (char)0) {
287 user
= talloc_strdup(frame
, smbc_getUser(context
));
295 srv
= SMBC_server(frame
, context
, True
,
296 server
, share
, &workgroup
, &user
, &password
);
300 return -1; /* errno set by SMBC_server */
303 if ((err
= cli_printjob_del(srv
->cli
, id
)) != 0) {
305 errno
= SMBC_errno(context
, srv
->cli
);
306 else if (err
== ERRnosuchprintjob
)