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 "libsmbclient.h"
27 #include "libsmb_internal.h"
31 * Open a print file to be written to by other calls
35 SMBC_open_print_job_ctx(SMBCCTX
*context
,
41 char *password
= NULL
;
43 TALLOC_CTX
*frame
= talloc_stackframe();
45 if (!context
|| !context
->internal
->initialized
) {
57 DEBUG(4, ("SMBC_open_print_job_ctx(%s)\n", fname
));
59 if (SMBC_parse_path(frame
,
74 /* What if the path is empty, or the file exists? */
77 return smbc_getFunctionOpen(context
)(context
, fname
, O_WRONLY
, 666);
81 * Routine to print a file on a remote server ...
83 * We open the file, which we assume to be on a remote server, and then
84 * copy it to a print file on the share specified by printq.
88 SMBC_print_file_ctx(SMBCCTX
*c_file
,
99 TALLOC_CTX
*frame
= talloc_stackframe();
101 if (!c_file
|| !c_file
->internal
->initialized
||
102 !c_print
|| !c_print
->internal
->initialized
) {
108 if (!fname
&& !printq
) {
114 /* Try to open the file for reading ... */
116 if ((long)(fid1
= smbc_getFunctionOpen(c_file
)(c_file
, fname
,
117 O_RDONLY
, 0666)) < 0) {
118 DEBUG(3, ("Error, fname=%s, errno=%i\n", fname
, errno
));
120 return -1; /* smbc_open sets errno */
123 /* Now, try to open the printer file for writing */
125 if ((long)(fid2
= smbc_getFunctionOpenPrintJob(c_print
)(c_print
,
127 saverr
= errno
; /* Save errno */
128 smbc_getFunctionClose(c_file
)(c_file
, fid1
);
134 while ((bytes
= smbc_getFunctionRead(c_file
)(c_file
, fid1
,
135 buf
, sizeof(buf
))) > 0) {
138 if ((smbc_getFunctionWrite(c_print
)(c_print
, fid2
,
141 smbc_getFunctionClose(c_file
)(c_file
, fid1
);
142 smbc_getFunctionClose(c_print
)(c_print
, fid2
);
149 smbc_getFunctionClose(c_file
)(c_file
, fid1
);
150 smbc_getFunctionClose(c_print
)(c_print
, fid2
);
163 * Routine to list print jobs on a printer share ...
167 SMBC_list_print_jobs_ctx(SMBCCTX
*context
,
169 smbc_list_print_job_fn fn
)
175 char *password
= NULL
;
176 char *workgroup
= NULL
;
178 TALLOC_CTX
*frame
= talloc_stackframe();
180 if (!context
|| !context
->internal
->initialized
) {
192 DEBUG(4, ("smbc_list_print_jobs(%s)\n", fname
));
194 if (SMBC_parse_path(frame
,
209 if (!user
|| user
[0] == (char)0) {
210 user
= talloc_strdup(frame
, smbc_getUser(context
));
218 srv
= SMBC_server(frame
, context
, True
,
219 server
, share
, &workgroup
, &user
, &password
);
223 return -1; /* errno set by SMBC_server */
226 if (cli_print_queue(srv
->cli
,
227 (void (*)(struct print_job_info
*))fn
) < 0) {
228 errno
= SMBC_errno(context
, srv
->cli
);
238 * Delete a print job from a remote printer share
242 SMBC_unlink_print_job_ctx(SMBCCTX
*context
,
250 char *password
= NULL
;
251 char *workgroup
= NULL
;
254 TALLOC_CTX
*frame
= talloc_stackframe();
256 if (!context
|| !context
->internal
->initialized
) {
268 DEBUG(4, ("smbc_unlink_print_job(%s)\n", fname
));
270 if (SMBC_parse_path(frame
,
285 if (!user
|| user
[0] == (char)0) {
286 user
= talloc_strdup(frame
, smbc_getUser(context
));
294 srv
= SMBC_server(frame
, context
, True
,
295 server
, share
, &workgroup
, &user
, &password
);
299 return -1; /* errno set by SMBC_server */
302 if ((err
= cli_printjob_del(srv
->cli
, id
)) != 0) {
304 errno
= SMBC_errno(context
, srv
->cli
);
305 else if (err
== ERRnosuchprintjob
)