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 2 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, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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
)
31 if (datap
== 0) { /* turn NULL pointers into zero length strings */
34 unsigned int offset
= datap
- converter
;
36 if (offset
>= rdrcnt
) {
37 DEBUG(1,("bad char ptr: datap=%u, converter=%u rdrcnt=%d>",
38 datap
, converter
, rdrcnt
));
41 return &rdata
[offset
];
47 /****************************************************************************
48 call fn() on each entry in a print queue
49 ****************************************************************************/
50 int cli_print_queue(struct cli_state
*cli
,
51 void (*fn
)(struct print_job_info
*))
56 unsigned int rdrcnt
, rprcnt
;
61 memset(param
,'\0',sizeof(param
));
64 SSVAL(p
,0,76); /* API function number 76 (DosPrintJobEnum) */
66 pstrcpy_base(p
,"zWrLeh", param
); /* parameter description? */
67 p
= skip_string(param
,sizeof(param
),p
);
68 pstrcpy_base(p
,"WWzWWDDzz", param
); /* returned data format */
69 p
= skip_string(param
,sizeof(param
),p
);
70 pstrcpy_base(p
,cli
->share
, param
); /* name of queue */
71 p
= skip_string(param
,sizeof(param
),p
);
72 SSVAL(p
,0,2); /* API function level 2, PRJINFO_2 data structure */
73 SSVAL(p
,2,1000); /* size of bytes of returned data buffer */
75 pstrcpy_base(p
,"", param
); /* subformat */
76 p
= skip_string(param
,sizeof(param
),p
);
78 DEBUG(4,("doing cli_print_queue for %s\n", cli
->share
));
81 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
82 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, maxlen */
83 &rparam
, &rprcnt
, /* return params, length */
84 &rdata
, &rdrcnt
)) { /* return data, length */
86 result_code
= SVAL(rparam
,0);
87 converter
= SVAL(rparam
,2); /* conversion factor */
89 if (result_code
== 0) {
90 struct print_job_info job
;
94 for (i
= 0; i
< SVAL(rparam
,4); ++i
) {
96 job
.priority
= SVAL(p
,2);
98 fix_char_ptr(SVAL(p
,4), converter
,
100 job
.t
= cli_make_unix_date3(cli
, p
+ 12);
101 job
.size
= IVAL(p
,16);
102 fstrcpy(job
.name
,fix_char_ptr(SVAL(p
,24),
111 /* If any parameters or data were returned, free the storage. */
118 /****************************************************************************
120 ****************************************************************************/
121 int cli_printjob_del(struct cli_state
*cli
, int job
)
126 unsigned int rdrcnt
,rprcnt
;
130 memset(param
,'\0',sizeof(param
));
133 SSVAL(p
,0,81); /* DosPrintJobDel() */
135 pstrcpy_base(p
,"W", param
);
136 p
= skip_string(param
,sizeof(param
),p
);
137 pstrcpy_base(p
,"", param
);
138 p
= skip_string(param
,sizeof(param
),p
);
143 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
144 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, maxlen */
145 &rparam
, &rprcnt
, /* return params, length */
146 &rdata
, &rdrcnt
)) { /* return data, length */
147 ret
= SVAL(rparam
,0);
157 /****************************************************************************
159 ****************************************************************************/
161 int cli_spl_open(struct cli_state
*cli
, const char *fname
, int flags
, int share_mode
)
165 unsigned accessmode
=0;
169 if (!(flags
& O_EXCL
)) {
176 accessmode
= (share_mode
<<4);
178 if ((flags
& O_ACCMODE
) == O_RDWR
) {
180 } else if ((flags
& O_ACCMODE
) == O_WRONLY
) {
185 if ((flags
& O_SYNC
) == O_SYNC
) {
186 accessmode
|= (1<<14);
190 if (share_mode
== DENY_FCB
) {
194 memset(cli
->outbuf
,'\0',smb_size
);
195 memset(cli
->inbuf
,'\0',smb_size
);
197 set_message(NULL
,cli
->outbuf
,15,0,True
);
199 SCVAL(cli
->outbuf
,smb_com
,SMBsplopen
);
200 SSVAL(cli
->outbuf
,smb_tid
,cli
->cnum
);
201 cli_setup_packet(cli
);
203 SSVAL(cli
->outbuf
,smb_vwv0
,0xFF);
204 SSVAL(cli
->outbuf
,smb_vwv2
,0); /* no additional info */
205 SSVAL(cli
->outbuf
,smb_vwv3
,accessmode
);
206 SSVAL(cli
->outbuf
,smb_vwv4
,aSYSTEM
| aHIDDEN
);
207 SSVAL(cli
->outbuf
,smb_vwv5
,0);
208 SSVAL(cli
->outbuf
,smb_vwv8
,openfn
);
210 if (cli
->use_oplocks
) {
211 /* if using oplocks then ask for a batch oplock via
212 core and extended methods */
213 SCVAL(cli
->outbuf
,smb_flg
, CVAL(cli
->outbuf
,smb_flg
)|
214 FLAG_REQUEST_OPLOCK
|FLAG_REQUEST_BATCH_OPLOCK
);
215 SSVAL(cli
->outbuf
,smb_vwv2
,SVAL(cli
->outbuf
,smb_vwv2
) | 6);
218 p
= smb_buf(cli
->outbuf
);
219 p
+= clistr_push(cli
, p
, fname
, -1, STR_TERMINATE
);
221 cli_setup_bcc(cli
, p
);
224 if (!cli_receive_smb(cli
)) {
228 if (cli_is_error(cli
)) {
232 return SVAL(cli
->inbuf
,smb_vwv2
);
235 /****************************************************************************
237 ****************************************************************************/
239 BOOL
cli_spl_close(struct cli_state
*cli
, int fnum
)
241 memset(cli
->outbuf
,'\0',smb_size
);
242 memset(cli
->inbuf
,'\0',smb_size
);
244 set_message(NULL
,cli
->outbuf
,3,0,True
);
246 SCVAL(cli
->outbuf
,smb_com
,SMBsplclose
);
247 SSVAL(cli
->outbuf
,smb_tid
,cli
->cnum
);
248 cli_setup_packet(cli
);
250 SSVAL(cli
->outbuf
,smb_vwv0
,fnum
);
251 SIVALS(cli
->outbuf
,smb_vwv1
,-1);
254 if (!cli_receive_smb(cli
)) {
258 return !cli_is_error(cli
);