1 | /*
|
---|
2 | Unix SMB/CIFS implementation.
|
---|
3 | client print routines
|
---|
4 | Copyright (C) Andrew Tridgell 1994-1998
|
---|
5 |
|
---|
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.
|
---|
10 |
|
---|
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.
|
---|
15 |
|
---|
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/>.
|
---|
18 | */
|
---|
19 |
|
---|
20 | #include "includes.h"
|
---|
21 | #include "libsmb/libsmb.h"
|
---|
22 | #include "libsmb/clirap.h"
|
---|
23 |
|
---|
24 | /*****************************************************************************
|
---|
25 | Convert a character pointer in a cli_call_api() response to a form we can use.
|
---|
26 | This function contains code to prevent core dumps if the server returns
|
---|
27 | invalid data.
|
---|
28 | *****************************************************************************/
|
---|
29 | static const char *fix_char_ptr(unsigned int datap, unsigned int converter,
|
---|
30 | char *rdata, int rdrcnt)
|
---|
31 | {
|
---|
32 | unsigned int offset;
|
---|
33 |
|
---|
34 | if (datap == 0) {
|
---|
35 | /* turn NULL pointers into zero length strings */
|
---|
36 | return "";
|
---|
37 | }
|
---|
38 |
|
---|
39 | offset = datap - converter;
|
---|
40 |
|
---|
41 | if (offset >= rdrcnt) {
|
---|
42 | DEBUG(1,("bad char ptr: datap=%u, converter=%u rdrcnt=%d>",
|
---|
43 | datap, converter, rdrcnt));
|
---|
44 | return "<ERROR>";
|
---|
45 | }
|
---|
46 | return &rdata[offset];
|
---|
47 | }
|
---|
48 |
|
---|
49 | /****************************************************************************
|
---|
50 | call fn() on each entry in a print queue
|
---|
51 | ****************************************************************************/
|
---|
52 |
|
---|
53 | int cli_print_queue(struct cli_state *cli,
|
---|
54 | void (*fn)(struct print_job_info *))
|
---|
55 | {
|
---|
56 | char *rparam = NULL;
|
---|
57 | char *rdata = NULL;
|
---|
58 | char *p;
|
---|
59 | unsigned int rdrcnt, rprcnt;
|
---|
60 | char param[1024];
|
---|
61 | int result_code=0;
|
---|
62 | int i = -1;
|
---|
63 |
|
---|
64 | memset(param,'\0',sizeof(param));
|
---|
65 |
|
---|
66 | p = param;
|
---|
67 | SSVAL(p,0,76); /* API function number 76 (DosPrintJobEnum) */
|
---|
68 | p += 2;
|
---|
69 | safe_strcpy_base(p,"zWrLeh", param, sizeof(param)); /* parameter description? */
|
---|
70 | p = skip_string(param,sizeof(param),p);
|
---|
71 | safe_strcpy_base(p,"WWzWWDDzz", param, sizeof(param)); /* returned data format */
|
---|
72 | p = skip_string(param,sizeof(param),p);
|
---|
73 | safe_strcpy_base(p,cli->share, param, sizeof(param)); /* name of queue */
|
---|
74 | p = skip_string(param,sizeof(param),p);
|
---|
75 | SSVAL(p,0,2); /* API function level 2, PRJINFO_2 data structure */
|
---|
76 | SSVAL(p,2,1000); /* size of bytes of returned data buffer */
|
---|
77 | p += 4;
|
---|
78 | safe_strcpy_base(p,"", param,sizeof(param)); /* subformat */
|
---|
79 | p = skip_string(param,sizeof(param),p);
|
---|
80 |
|
---|
81 | DEBUG(4,("doing cli_print_queue for %s\n", cli->share));
|
---|
82 |
|
---|
83 | if (cli_api(cli,
|
---|
84 | param, PTR_DIFF(p,param), 1024, /* Param, length, maxlen */
|
---|
85 | NULL, 0, CLI_BUFFER_SIZE, /* data, length, maxlen */
|
---|
86 | &rparam, &rprcnt, /* return params, length */
|
---|
87 | &rdata, &rdrcnt)) { /* return data, length */
|
---|
88 | int converter;
|
---|
89 | result_code = SVAL(rparam,0);
|
---|
90 | converter = SVAL(rparam,2); /* conversion factor */
|
---|
91 |
|
---|
92 | if (result_code == 0) {
|
---|
93 | struct print_job_info job;
|
---|
94 |
|
---|
95 | p = rdata;
|
---|
96 |
|
---|
97 | for (i = 0; i < SVAL(rparam,4); ++i) {
|
---|
98 | job.id = SVAL(p,0);
|
---|
99 | job.priority = SVAL(p,2);
|
---|
100 | fstrcpy(job.user,
|
---|
101 | fix_char_ptr(SVAL(p,4), converter,
|
---|
102 | rdata, rdrcnt));
|
---|
103 | job.t = make_unix_date3(
|
---|
104 | p + 12, cli->serverzone);
|
---|
105 | job.size = IVAL(p,16);
|
---|
106 | fstrcpy(job.name,fix_char_ptr(SVAL(p,24),
|
---|
107 | converter,
|
---|
108 | rdata, rdrcnt));
|
---|
109 | fn(&job);
|
---|
110 | p += 28;
|
---|
111 | }
|
---|
112 | }
|
---|
113 | }
|
---|
114 |
|
---|
115 | /* If any parameters or data were returned, free the storage. */
|
---|
116 | SAFE_FREE(rparam);
|
---|
117 | SAFE_FREE(rdata);
|
---|
118 |
|
---|
119 | return i;
|
---|
120 | }
|
---|
121 |
|
---|
122 | #ifdef __OS2__
|
---|
123 | // this is a exact copy of the above cli_print_queue, but we need to pass the
|
---|
124 | // state also to the callback, as our client needs that!!
|
---|
125 |
|
---|
126 | /****************************************************************************
|
---|
127 | call fn() on each entry in a print queue
|
---|
128 | ****************************************************************************/
|
---|
129 |
|
---|
130 | int cli_print_queue_state(struct cli_state *cli,
|
---|
131 | void (*fn)(struct print_job_info *, void *), void *state)
|
---|
132 | {
|
---|
133 | char *rparam = NULL;
|
---|
134 | char *rdata = NULL;
|
---|
135 | char *p;
|
---|
136 | unsigned int rdrcnt, rprcnt;
|
---|
137 | char param[1024];
|
---|
138 | int result_code=0;
|
---|
139 | int i = -1;
|
---|
140 |
|
---|
141 | memset(param,'\0',sizeof(param));
|
---|
142 |
|
---|
143 | p = param;
|
---|
144 | SSVAL(p,0,76); /* API function number 76 (DosPrintJobEnum) */
|
---|
145 | p += 2;
|
---|
146 | safe_strcpy_base(p,"zWrLeh", param, sizeof(param)); /* parameter description? */
|
---|
147 | p = skip_string(param,sizeof(param),p);
|
---|
148 | safe_strcpy_base(p,"WWzWWDDzz", param, sizeof(param)); /* returned data format */
|
---|
149 | p = skip_string(param,sizeof(param),p);
|
---|
150 | safe_strcpy_base(p,cli->share, param, sizeof(param)); /* name of queue */
|
---|
151 | p = skip_string(param,sizeof(param),p);
|
---|
152 | SSVAL(p,0,2); /* API function level 2, PRJINFO_2 data structure */
|
---|
153 | SSVAL(p,2,1000); /* size of bytes of returned data buffer */
|
---|
154 | p += 4;
|
---|
155 | safe_strcpy_base(p,"", param,sizeof(param)); /* subformat */
|
---|
156 | p = skip_string(param,sizeof(param),p);
|
---|
157 |
|
---|
158 | DEBUG(4,("doing cli_print_queue_state for %s\n", cli->share));
|
---|
159 |
|
---|
160 | if (cli_api(cli,
|
---|
161 | param, PTR_DIFF(p,param), 1024, /* Param, length, maxlen */
|
---|
162 | NULL, 0, CLI_BUFFER_SIZE, /* data, length, maxlen */
|
---|
163 | &rparam, &rprcnt, /* return params, length */
|
---|
164 | &rdata, &rdrcnt)) { /* return data, length */
|
---|
165 | int converter;
|
---|
166 | result_code = SVAL(rparam,0);
|
---|
167 | converter = SVAL(rparam,2); /* conversion factor */
|
---|
168 |
|
---|
169 | if (result_code == 0) {
|
---|
170 | struct print_job_info job;
|
---|
171 |
|
---|
172 | p = rdata;
|
---|
173 |
|
---|
174 | for (i = 0; i < SVAL(rparam,4); ++i) {
|
---|
175 | job.id = SVAL(p,0);
|
---|
176 | job.priority = SVAL(p,2);
|
---|
177 | fstrcpy(job.user,
|
---|
178 | fix_char_ptr(SVAL(p,4), converter,
|
---|
179 | rdata, rdrcnt));
|
---|
180 | job.t = make_unix_date3(
|
---|
181 | p + 12, cli->serverzone);
|
---|
182 | job.size = IVAL(p,16);
|
---|
183 | fstrcpy(job.name,fix_char_ptr(SVAL(p,24),
|
---|
184 | converter,
|
---|
185 | rdata, rdrcnt));
|
---|
186 | fn(&job, state);
|
---|
187 | p += 28;
|
---|
188 | }
|
---|
189 | }
|
---|
190 | }
|
---|
191 |
|
---|
192 | /* If any parameters or data were returned, free the storage. */
|
---|
193 | SAFE_FREE(rparam);
|
---|
194 | SAFE_FREE(rdata);
|
---|
195 |
|
---|
196 | return i;
|
---|
197 | }
|
---|
198 | #endif
|
---|
199 | /****************************************************************************
|
---|
200 | cancel a print job
|
---|
201 | ****************************************************************************/
|
---|
202 |
|
---|
203 | int cli_printjob_del(struct cli_state *cli, int job)
|
---|
204 | {
|
---|
205 | char *rparam = NULL;
|
---|
206 | char *rdata = NULL;
|
---|
207 | char *p;
|
---|
208 | unsigned int rdrcnt,rprcnt;
|
---|
209 | int ret = -1;
|
---|
210 | char param[1024];
|
---|
211 |
|
---|
212 | memset(param,'\0',sizeof(param));
|
---|
213 |
|
---|
214 | p = param;
|
---|
215 | SSVAL(p,0,81); /* DosPrintJobDel() */
|
---|
216 | p += 2;
|
---|
217 | safe_strcpy_base(p,"W", param,sizeof(param));
|
---|
218 | p = skip_string(param,sizeof(param),p);
|
---|
219 | safe_strcpy_base(p,"", param,sizeof(param));
|
---|
220 | p = skip_string(param,sizeof(param),p);
|
---|
221 | SSVAL(p,0,job);
|
---|
222 | p += 2;
|
---|
223 |
|
---|
224 | if (cli_api(cli,
|
---|
225 | param, PTR_DIFF(p,param), 1024, /* Param, length, maxlen */
|
---|
226 | NULL, 0, CLI_BUFFER_SIZE, /* data, length, maxlen */
|
---|
227 | &rparam, &rprcnt, /* return params, length */
|
---|
228 | &rdata, &rdrcnt)) { /* return data, length */
|
---|
229 | ret = SVAL(rparam,0);
|
---|
230 | }
|
---|
231 |
|
---|
232 | SAFE_FREE(rparam);
|
---|
233 | SAFE_FREE(rdata);
|
---|
234 |
|
---|
235 | return ret;
|
---|
236 | }
|
---|