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"
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
28 *****************************************************************************/
29 static const char *fix_char_ptr(unsigned int datap
, unsigned int converter
,
30 char *rdata
, int rdrcnt
)
35 /* turn NULL pointers into zero length strings */
39 offset
= datap
- converter
;
41 if (offset
>= rdrcnt
) {
42 DEBUG(1,("bad char ptr: datap=%u, converter=%u rdrcnt=%d>",
43 datap
, converter
, rdrcnt
));
46 return &rdata
[offset
];
49 /****************************************************************************
50 call fn() on each entry in a print queue
51 ****************************************************************************/
53 int cli_print_queue(struct cli_state
*cli
,
54 void (*fn
)(struct print_job_info
*))
59 unsigned int rdrcnt
, rprcnt
;
64 memset(param
,'\0',sizeof(param
));
67 SSVAL(p
,0,76); /* API function number 76 (DosPrintJobEnum) */
69 strlcpy_base(p
,"zWrLeh", param
, sizeof(param
)); /* parameter description? */
70 p
= skip_string(param
,sizeof(param
),p
);
71 strlcpy_base(p
,"WWzWWDDzz", param
, sizeof(param
)); /* returned data format */
72 p
= skip_string(param
,sizeof(param
),p
);
73 strlcpy_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 */
78 strlcpy_base(p
,"", param
,sizeof(param
)); /* subformat */
79 p
= skip_string(param
,sizeof(param
),p
);
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(
104 p
+ 12, cli_state_server_time_zone(cli
));
105 job
.size
= IVAL(p
,16);
106 fstrcpy(job
.name
,fix_char_ptr(SVAL(p
,24),
115 /* If any parameters or data were returned, free the storage. */
122 /****************************************************************************
124 ****************************************************************************/
126 int cli_printjob_del(struct cli_state
*cli
, int job
)
131 unsigned int rdrcnt
,rprcnt
;
135 memset(param
,'\0',sizeof(param
));
138 SSVAL(p
,0,81); /* DosPrintJobDel() */
140 strlcpy_base(p
,"W", param
,sizeof(param
));
141 p
= skip_string(param
,sizeof(param
),p
);
142 strlcpy_base(p
,"", param
,sizeof(param
));
143 p
= skip_string(param
,sizeof(param
),p
);
148 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
149 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, maxlen */
150 &rparam
, &rprcnt
, /* return params, length */
151 &rdata
, &rdrcnt
)) { /* return data, length */
152 ret
= SVAL(rparam
,0);