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/clirap.h"
23 /*****************************************************************************
24 Convert a character pointer in a cli_call_api() response to a form we can use.
25 This function contains code to prevent core dumps if the server returns
27 *****************************************************************************/
28 static const char *fix_char_ptr(unsigned int datap
, unsigned int converter
,
29 char *rdata
, int rdrcnt
)
34 /* turn NULL pointers into zero length strings */
38 offset
= datap
- converter
;
40 if (offset
>= rdrcnt
) {
41 DEBUG(1,("bad char ptr: datap=%u, converter=%u rdrcnt=%d>",
42 datap
, converter
, rdrcnt
));
45 return &rdata
[offset
];
48 /****************************************************************************
49 call fn() on each entry in a print queue
50 ****************************************************************************/
52 int cli_print_queue(struct cli_state
*cli
,
53 void (*fn
)(struct print_job_info
*))
58 unsigned int rdrcnt
, rprcnt
;
63 memset(param
,'\0',sizeof(param
));
66 SSVAL(p
,0,76); /* API function number 76 (DosPrintJobEnum) */
68 safe_strcpy_base(p
,"zWrLeh", param
, sizeof(param
)); /* parameter description? */
69 p
= skip_string(param
,sizeof(param
),p
);
70 safe_strcpy_base(p
,"WWzWWDDzz", param
, sizeof(param
)); /* returned data format */
71 p
= skip_string(param
,sizeof(param
),p
);
72 safe_strcpy_base(p
,cli
->share
, param
, sizeof(param
)); /* name of queue */
73 p
= skip_string(param
,sizeof(param
),p
);
74 SSVAL(p
,0,2); /* API function level 2, PRJINFO_2 data structure */
75 SSVAL(p
,2,1000); /* size of bytes of returned data buffer */
77 safe_strcpy_base(p
,"", param
,sizeof(param
)); /* subformat */
78 p
= skip_string(param
,sizeof(param
),p
);
80 DEBUG(4,("doing cli_print_queue for %s\n", cli
->share
));
83 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
84 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, maxlen */
85 &rparam
, &rprcnt
, /* return params, length */
86 &rdata
, &rdrcnt
)) { /* return data, length */
88 result_code
= SVAL(rparam
,0);
89 converter
= SVAL(rparam
,2); /* conversion factor */
91 if (result_code
== 0) {
92 struct print_job_info job
;
96 for (i
= 0; i
< SVAL(rparam
,4); ++i
) {
98 job
.priority
= SVAL(p
,2);
100 fix_char_ptr(SVAL(p
,4), converter
,
102 job
.t
= make_unix_date3(
103 p
+ 12, cli
->serverzone
);
104 job
.size
= IVAL(p
,16);
105 fstrcpy(job
.name
,fix_char_ptr(SVAL(p
,24),
114 /* If any parameters or data were returned, free the storage. */
121 /****************************************************************************
123 ****************************************************************************/
125 int cli_printjob_del(struct cli_state
*cli
, int job
)
130 unsigned int rdrcnt
,rprcnt
;
134 memset(param
,'\0',sizeof(param
));
137 SSVAL(p
,0,81); /* DosPrintJobDel() */
139 safe_strcpy_base(p
,"W", param
,sizeof(param
));
140 p
= skip_string(param
,sizeof(param
),p
);
141 safe_strcpy_base(p
,"", param
,sizeof(param
));
142 p
= skip_string(param
,sizeof(param
),p
);
147 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
148 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, maxlen */
149 &rparam
, &rprcnt
, /* return params, length */
150 &rdata
, &rdrcnt
)) { /* return data, length */
151 ret
= SVAL(rparam
,0);