2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1994-1998
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "libsmb/libsmb.h"
22 #include "libsmb/clirap.h"
23 #include "../libcli/smb/smbXcli_base.h"
24 #include "lib/util/string_wrappers.h"
26 /*****************************************************************************
27 Convert a character pointer in a cli_call_api() response to a form we can use.
28 This function contains code to prevent core dumps if the server returns
30 *****************************************************************************/
31 static const char *fix_char_ptr(unsigned int datap
, unsigned int converter
,
32 char *rdata
, int rdrcnt
)
37 /* turn NULL pointers into zero length strings */
41 offset
= datap
- converter
;
43 if (offset
>= rdrcnt
) {
44 DEBUG(1,("bad char ptr: datap=%u, converter=%u rdrcnt=%d>\n",
45 datap
, converter
, rdrcnt
));
48 return &rdata
[offset
];
51 /****************************************************************************
52 call fn() on each entry in a print queue
53 ****************************************************************************/
55 NTSTATUS
cli_print_queue(struct cli_state
*cli
,
56 void (*fn
)(struct print_job_info
*))
58 uint8_t *rparam
= NULL
;
59 uint8_t *rdata
= NULL
;
61 uint32_t rdrcnt
, rprcnt
;
68 memset(param
,'\0',sizeof(param
));
71 SSVAL(p
,0,76); /* API function number 76 (DosPrintJobEnum) */
73 strlcpy_base(p
,"zWrLeh", param
, sizeof(param
)); /* parameter description? */
74 p
= skip_string(param
,sizeof(param
),p
);
75 strlcpy_base(p
,"WWzWWDDzz", param
, sizeof(param
)); /* returned data format */
76 p
= skip_string(param
,sizeof(param
),p
);
77 strlcpy_base(p
,cli
->share
, param
, sizeof(param
)); /* name of queue */
78 p
= skip_string(param
,sizeof(param
),p
);
79 SSVAL(p
,0,2); /* API function level 2, PRJINFO_2 data structure */
80 SSVAL(p
,2,1000); /* size of bytes of returned data buffer */
82 strlcpy_base(p
,"", param
,sizeof(param
)); /* subformat */
83 p
= skip_string(param
,sizeof(param
),p
);
85 DEBUG(4,("doing cli_print_queue for %s\n", cli
->share
));
90 SMBtrans
, /* trans_cmd */
91 "\\PIPE\\LANMAN", /* name */
98 (uint8_t *)param
, /* param */
99 PTR_DIFF(p
,param
), /* num_param */
100 1024, /* max_param */
103 CLI_BUFFER_SIZE
, /* max_data */
104 NULL
, /* recv_flags2 */
107 NULL
, /* num_rsetup */
108 &rparam
, /* rparam */
110 &rprcnt
, /* num_rparam */
113 &rdrcnt
); /* num_rdata */
114 if (!NT_STATUS_IS_OK(status
)) {
118 result_code
= SVAL(rparam
,0);
119 converter
= SVAL(rparam
,2); /* conversion factor */
121 if (result_code
== 0) {
122 struct print_job_info job
;
126 for (i
= 0; i
< SVAL(rparam
,4); ++i
) {
128 job
.priority
= SVAL(p
,2);
130 fix_char_ptr(SVAL(p
,4), converter
,
131 (char *)rdata
, rdrcnt
));
132 job
.t
= make_unix_date3(
133 p
+ 12, smb1cli_conn_server_time_zone(cli
->conn
));
134 job
.size
= IVAL(p
,16);
135 fstrcpy(job
.name
,fix_char_ptr(SVAL(p
,24),
137 (char *)rdata
, rdrcnt
));
143 /* If any parameters or data were returned, free the storage. */
150 /****************************************************************************
152 ****************************************************************************/
154 NTSTATUS
cli_printjob_del(struct cli_state
*cli
, int job
)
156 uint8_t *rparam
= NULL
;
157 uint8_t *rdata
= NULL
;
159 uint32_t rdrcnt
, rprcnt
;
162 NTSTATUS status
= NT_STATUS_OK
;
164 memset(param
,'\0',sizeof(param
));
167 SSVAL(p
,0,81); /* DosPrintJobDel() */
169 strlcpy_base(p
,"W", param
,sizeof(param
));
170 p
= skip_string(param
,sizeof(param
),p
);
171 strlcpy_base(p
,"", param
,sizeof(param
));
172 p
= skip_string(param
,sizeof(param
),p
);
176 status
= cli_trans(talloc_tos(),
178 SMBtrans
, /* trans_cmd */
179 "\\PIPE\\LANMAN", /* name */
186 (uint8_t *)param
, /* param */
187 PTR_DIFF(p
, param
), /* num_param */
188 1024, /* max_param */
191 CLI_BUFFER_SIZE
, /* max_data */
192 NULL
, /* recv_flags2 */
195 NULL
, /* num_rsetup */
196 &rparam
, /* rparam */
198 &rprcnt
, /* num_rparam */
201 &rdrcnt
); /* num_rdata */
202 if (!NT_STATUS_IS_OK(status
)) {
206 result_code
= SVAL(rparam
, 0);
211 if (result_code
== ERRnosuchprintjob
) {
212 status
= NT_STATUS_INVALID_PARAMETER
;