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
;
45 TALLOC_CTX
*frame
= talloc_stackframe();
47 if (!context
|| !context
->internal
->initialized
) {
59 DEBUG(4, ("SMBC_open_print_job_ctx(%s)\n", fname
));
61 if (SMBC_parse_path(frame
,
77 /* What if the path is empty, or the file exists? */
80 return smbc_getFunctionOpen(context
)(context
, fname
, O_WRONLY
, 666);
84 * Routine to print a file on a remote server ...
86 * We open the file, which we assume to be on a remote server, and then
87 * copy it to a print file on the share specified by printq.
91 SMBC_print_file_ctx(SMBCCTX
*c_file
,
99 smbc_open_print_job_fn f_open_pj2
;
104 TALLOC_CTX
*frame
= talloc_stackframe();
106 if (!c_file
|| !c_file
->internal
->initialized
||
107 !c_print
|| !c_print
->internal
->initialized
) {
113 if (!fname
&& !printq
) {
119 /* Try to open the file for reading ... */
120 f_open1
= smbc_getFunctionOpen(c_file
);
121 if (f_open1
== NULL
) {
127 fid1
= f_open1(c_file
, fname
, O_RDONLY
, 0666);
129 DEBUG(3, ("Error, fname=%s, errno=%i\n", fname
, errno
));
131 return -1; /* smbc_open sets errno */
134 /* Now, try to open the printer file for writing */
135 f_open_pj2
= smbc_getFunctionOpenPrintJob(c_print
);
136 if (f_open_pj2
== NULL
) {
142 fid2
= f_open_pj2(c_print
, printq
);
144 saverr
= errno
; /* Save errno */
145 smbc_getFunctionClose(c_file
)(c_file
, fid1
);
151 while ((bytes
= smbc_getFunctionRead(c_file
)(c_file
, fid1
,
152 buf
, sizeof(buf
))) > 0) {
155 if ((smbc_getFunctionWrite(c_print
)(c_print
, fid2
,
158 smbc_getFunctionClose(c_file
)(c_file
, fid1
);
159 smbc_getFunctionClose(c_print
)(c_print
, fid2
);
166 smbc_getFunctionClose(c_file
)(c_file
, fid1
);
167 smbc_getFunctionClose(c_print
)(c_print
, fid2
);
180 * Routine to list print jobs on a printer share ...
184 SMBC_list_print_jobs_ctx(SMBCCTX
*context
,
186 smbc_list_print_job_fn fn
)
192 char *password
= NULL
;
193 char *workgroup
= NULL
;
196 TALLOC_CTX
*frame
= talloc_stackframe();
199 if (!context
|| !context
->internal
->initialized
) {
211 DEBUG(4, ("smbc_list_print_jobs(%s)\n", fname
));
213 if (SMBC_parse_path(frame
,
229 if (!user
|| user
[0] == (char)0) {
230 user
= talloc_strdup(frame
, smbc_getUser(context
));
238 srv
= SMBC_server(frame
, context
, True
,
239 server
, port
, share
, &workgroup
, &user
, &password
);
243 return -1; /* errno set by SMBC_server */
246 status
= cli_print_queue(srv
->cli
,
247 (void (*)(struct print_job_info
*))fn
);
248 if (!NT_STATUS_IS_OK(status
)) {
250 errno
= cli_status_to_errno(status
);
259 * Delete a print job from a remote printer share
263 SMBC_unlink_print_job_ctx(SMBCCTX
*context
,
271 char *password
= NULL
;
272 char *workgroup
= NULL
;
275 TALLOC_CTX
*frame
= talloc_stackframe();
278 if (!context
|| !context
->internal
->initialized
) {
290 DEBUG(4, ("smbc_unlink_print_job(%s)\n", fname
));
292 if (SMBC_parse_path(frame
,
308 if (!user
|| user
[0] == (char)0) {
309 user
= talloc_strdup(frame
, smbc_getUser(context
));
317 srv
= SMBC_server(frame
, context
, True
,
318 server
, port
, share
, &workgroup
, &user
, &password
);
322 return -1; /* errno set by SMBC_server */
325 status
= cli_printjob_del(srv
->cli
, id
);
326 if (!NT_STATUS_IS_OK(status
)) {
327 errno
= cli_status_to_errno(status
);