2 Unix SMB/Netbios implementation.
5 Copyright (C) Andrew Tridgell 1994-1998
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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 char *fix_char_ptr(unsigned int datap
, unsigned int converter
,
32 char *rdata
, int rdrcnt
)
34 if (datap
== 0) { /* turn NULL pointers into zero length strings */
37 unsigned int offset
= datap
- converter
;
39 if (offset
>= rdrcnt
) {
40 DEBUG(1,("bad char ptr: datap=%u, converter=%u rdrcnt=%d>",
41 datap
, converter
, rdrcnt
));
44 return &rdata
[offset
];
50 /****************************************************************************
51 call fn() on each entry in a print queue
52 ****************************************************************************/
53 int cli_print_queue(struct cli_state
*cli
,
54 void (*fn
)(struct print_job_info
*))
64 memset(param
,'\0',sizeof(param
));
67 SSVAL(p
,0,76); /* API function number 76 (DosPrintJobEnum) */
69 pstrcpy(p
,"zWrLeh"); /* parameter description? */
71 pstrcpy(p
,"WWzWWDDzz"); /* returned data format */
73 pstrcpy(p
,cli
->share
); /* name of queue */
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 */
78 pstrcpy(p
,""); /* subformat */
81 DEBUG(4,("doing cli_print_queue for %s\n", cli
->share
));
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 */
89 result_code
= SVAL(rparam
,0);
90 converter
= SVAL(rparam
,2); /* conversion factor */
92 if (result_code
== 0) {
93 struct print_job_info job
;
97 for (i
= 0; i
< SVAL(rparam
,4); ++i
) {
99 job
.priority
= SVAL(p
,2);
101 fix_char_ptr(SVAL(p
,4), converter
,
103 job
.t
= make_unix_date3(p
+ 12);
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 ****************************************************************************/
124 int cli_printjob_del(struct cli_state
*cli
, int job
)
129 int rdrcnt
,rprcnt
, ret
= -1;
132 memset(param
,'\0',sizeof(param
));
135 SSVAL(p
,0,81); /* DosPrintJobDel() */
138 p
= skip_string(p
,1);
140 p
= skip_string(p
,1);
145 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
146 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, maxlen */
147 &rparam
, &rprcnt
, /* return params, length */
148 &rdata
, &rdrcnt
)) { /* return data, length */
149 ret
= SVAL(rparam
,0);