| 1 | /* | 
|---|
| 2 | Unix SMB/CIFS implementation. | 
|---|
| 3 | client file operations | 
|---|
| 4 | Copyright (C) Andrew Tridgell 1994-1998 | 
|---|
| 5 | Copyright (C) Jeremy Allison 2001-2002 | 
|---|
| 6 |  | 
|---|
| 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 3 of the License, or | 
|---|
| 10 | (at your option) any later version. | 
|---|
| 11 |  | 
|---|
| 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. | 
|---|
| 16 |  | 
|---|
| 17 | You should have received a copy of the GNU General Public License | 
|---|
| 18 | along with this program.  If not, see <http://www.gnu.org/licenses/>. | 
|---|
| 19 | */ | 
|---|
| 20 |  | 
|---|
| 21 | #include "includes.h" | 
|---|
| 22 |  | 
|---|
| 23 | /**************************************************************************** | 
|---|
| 24 | Hard/Symlink a file (UNIX extensions). | 
|---|
| 25 | Creates new name (sym)linked to oldname. | 
|---|
| 26 | ****************************************************************************/ | 
|---|
| 27 |  | 
|---|
| 28 | static bool cli_link_internal(struct cli_state *cli, const char *oldname, const char *newname, bool hard_link) | 
|---|
| 29 | { | 
|---|
| 30 | unsigned int data_len = 0; | 
|---|
| 31 | unsigned int param_len = 0; | 
|---|
| 32 | uint16 setup = TRANSACT2_SETPATHINFO; | 
|---|
| 33 | char *param; | 
|---|
| 34 | char *data; | 
|---|
| 35 | char *rparam=NULL, *rdata=NULL; | 
|---|
| 36 | char *p; | 
|---|
| 37 | size_t oldlen = 2*(strlen(oldname)+1); | 
|---|
| 38 | size_t newlen = 2*(strlen(newname)+1); | 
|---|
| 39 |  | 
|---|
| 40 | param = SMB_MALLOC_ARRAY(char, 6+newlen+2); | 
|---|
| 41 |  | 
|---|
| 42 | if (!param) { | 
|---|
| 43 | return false; | 
|---|
| 44 | } | 
|---|
| 45 |  | 
|---|
| 46 | data = SMB_MALLOC_ARRAY(char, oldlen+2); | 
|---|
| 47 |  | 
|---|
| 48 | if (!data) { | 
|---|
| 49 | SAFE_FREE(param); | 
|---|
| 50 | return false; | 
|---|
| 51 | } | 
|---|
| 52 |  | 
|---|
| 53 | SSVAL(param,0,hard_link ? SMB_SET_FILE_UNIX_HLINK : SMB_SET_FILE_UNIX_LINK); | 
|---|
| 54 | SIVAL(param,2,0); | 
|---|
| 55 | p = ¶m[6]; | 
|---|
| 56 |  | 
|---|
| 57 | p += clistr_push(cli, p, newname, newlen, STR_TERMINATE); | 
|---|
| 58 | param_len = PTR_DIFF(p, param); | 
|---|
| 59 |  | 
|---|
| 60 | p = data; | 
|---|
| 61 | p += clistr_push(cli, p, oldname, oldlen, STR_TERMINATE); | 
|---|
| 62 | data_len = PTR_DIFF(p, data); | 
|---|
| 63 |  | 
|---|
| 64 | if (!cli_send_trans(cli, SMBtrans2, | 
|---|
| 65 | NULL,                        /* name */ | 
|---|
| 66 | -1, 0,                          /* fid, flags */ | 
|---|
| 67 | &setup, 1, 0,                   /* setup, length, max */ | 
|---|
| 68 | param, param_len, 2,            /* param, length, max */ | 
|---|
| 69 | data,  data_len, cli->max_xmit  /* data, length, max */ | 
|---|
| 70 | )) { | 
|---|
| 71 | SAFE_FREE(data); | 
|---|
| 72 | SAFE_FREE(param); | 
|---|
| 73 | return false; | 
|---|
| 74 | } | 
|---|
| 75 |  | 
|---|
| 76 | SAFE_FREE(data); | 
|---|
| 77 | SAFE_FREE(param); | 
|---|
| 78 |  | 
|---|
| 79 | if (!cli_receive_trans(cli, SMBtrans2, | 
|---|
| 80 | &rparam, ¶m_len, | 
|---|
| 81 | &rdata, &data_len)) { | 
|---|
| 82 | return false; | 
|---|
| 83 | } | 
|---|
| 84 |  | 
|---|
| 85 | SAFE_FREE(data); | 
|---|
| 86 | SAFE_FREE(param); | 
|---|
| 87 | SAFE_FREE(rdata); | 
|---|
| 88 | SAFE_FREE(rparam); | 
|---|
| 89 |  | 
|---|
| 90 | return true; | 
|---|
| 91 | } | 
|---|
| 92 |  | 
|---|
| 93 | /**************************************************************************** | 
|---|
| 94 | Map standard UNIX permissions onto wire representations. | 
|---|
| 95 | ****************************************************************************/ | 
|---|
| 96 |  | 
|---|
| 97 | uint32 unix_perms_to_wire(mode_t perms) | 
|---|
| 98 | { | 
|---|
| 99 | unsigned int ret = 0; | 
|---|
| 100 |  | 
|---|
| 101 | ret |= ((perms & S_IXOTH) ?  UNIX_X_OTH : 0); | 
|---|
| 102 | ret |= ((perms & S_IWOTH) ?  UNIX_W_OTH : 0); | 
|---|
| 103 | ret |= ((perms & S_IROTH) ?  UNIX_R_OTH : 0); | 
|---|
| 104 | ret |= ((perms & S_IXGRP) ?  UNIX_X_GRP : 0); | 
|---|
| 105 | ret |= ((perms & S_IWGRP) ?  UNIX_W_GRP : 0); | 
|---|
| 106 | ret |= ((perms & S_IRGRP) ?  UNIX_R_GRP : 0); | 
|---|
| 107 | ret |= ((perms & S_IXUSR) ?  UNIX_X_USR : 0); | 
|---|
| 108 | ret |= ((perms & S_IWUSR) ?  UNIX_W_USR : 0); | 
|---|
| 109 | ret |= ((perms & S_IRUSR) ?  UNIX_R_USR : 0); | 
|---|
| 110 | #ifdef S_ISVTX | 
|---|
| 111 | ret |= ((perms & S_ISVTX) ?  UNIX_STICKY : 0); | 
|---|
| 112 | #endif | 
|---|
| 113 | #ifdef S_ISGID | 
|---|
| 114 | ret |= ((perms & S_ISGID) ?  UNIX_SET_GID : 0); | 
|---|
| 115 | #endif | 
|---|
| 116 | #ifdef S_ISUID | 
|---|
| 117 | ret |= ((perms & S_ISUID) ?  UNIX_SET_UID : 0); | 
|---|
| 118 | #endif | 
|---|
| 119 | return ret; | 
|---|
| 120 | } | 
|---|
| 121 |  | 
|---|
| 122 | /**************************************************************************** | 
|---|
| 123 | Map wire permissions to standard UNIX. | 
|---|
| 124 | ****************************************************************************/ | 
|---|
| 125 |  | 
|---|
| 126 | mode_t wire_perms_to_unix(uint32 perms) | 
|---|
| 127 | { | 
|---|
| 128 | mode_t ret = (mode_t)0; | 
|---|
| 129 |  | 
|---|
| 130 | ret |= ((perms & UNIX_X_OTH) ? S_IXOTH : 0); | 
|---|
| 131 | ret |= ((perms & UNIX_W_OTH) ? S_IWOTH : 0); | 
|---|
| 132 | ret |= ((perms & UNIX_R_OTH) ? S_IROTH : 0); | 
|---|
| 133 | ret |= ((perms & UNIX_X_GRP) ? S_IXGRP : 0); | 
|---|
| 134 | ret |= ((perms & UNIX_W_GRP) ? S_IWGRP : 0); | 
|---|
| 135 | ret |= ((perms & UNIX_R_GRP) ? S_IRGRP : 0); | 
|---|
| 136 | ret |= ((perms & UNIX_X_USR) ? S_IXUSR : 0); | 
|---|
| 137 | ret |= ((perms & UNIX_W_USR) ? S_IWUSR : 0); | 
|---|
| 138 | ret |= ((perms & UNIX_R_USR) ? S_IRUSR : 0); | 
|---|
| 139 | #ifdef S_ISVTX | 
|---|
| 140 | ret |= ((perms & UNIX_STICKY) ? S_ISVTX : 0); | 
|---|
| 141 | #endif | 
|---|
| 142 | #ifdef S_ISGID | 
|---|
| 143 | ret |= ((perms & UNIX_SET_GID) ? S_ISGID : 0); | 
|---|
| 144 | #endif | 
|---|
| 145 | #ifdef S_ISUID | 
|---|
| 146 | ret |= ((perms & UNIX_SET_UID) ? S_ISUID : 0); | 
|---|
| 147 | #endif | 
|---|
| 148 | return ret; | 
|---|
| 149 | } | 
|---|
| 150 |  | 
|---|
| 151 | /**************************************************************************** | 
|---|
| 152 | Return the file type from the wire filetype for UNIX extensions. | 
|---|
| 153 | ****************************************************************************/ | 
|---|
| 154 |  | 
|---|
| 155 | static mode_t unix_filetype_from_wire(uint32 wire_type) | 
|---|
| 156 | { | 
|---|
| 157 | switch (wire_type) { | 
|---|
| 158 | case UNIX_TYPE_FILE: | 
|---|
| 159 | return S_IFREG; | 
|---|
| 160 | case UNIX_TYPE_DIR: | 
|---|
| 161 | return S_IFDIR; | 
|---|
| 162 | #ifdef S_IFLNK | 
|---|
| 163 | case UNIX_TYPE_SYMLINK: | 
|---|
| 164 | return S_IFLNK; | 
|---|
| 165 | #endif | 
|---|
| 166 | #ifdef S_IFCHR | 
|---|
| 167 | case UNIX_TYPE_CHARDEV: | 
|---|
| 168 | return S_IFCHR; | 
|---|
| 169 | #endif | 
|---|
| 170 | #ifdef S_IFBLK | 
|---|
| 171 | case UNIX_TYPE_BLKDEV: | 
|---|
| 172 | return S_IFBLK; | 
|---|
| 173 | #endif | 
|---|
| 174 | #ifdef S_IFIFO | 
|---|
| 175 | case UNIX_TYPE_FIFO: | 
|---|
| 176 | return S_IFIFO; | 
|---|
| 177 | #endif | 
|---|
| 178 | #ifdef S_IFSOCK | 
|---|
| 179 | case UNIX_TYPE_SOCKET: | 
|---|
| 180 | return S_IFSOCK; | 
|---|
| 181 | #endif | 
|---|
| 182 | default: | 
|---|
| 183 | return (mode_t)0; | 
|---|
| 184 | } | 
|---|
| 185 | } | 
|---|
| 186 |  | 
|---|
| 187 | /**************************************************************************** | 
|---|
| 188 | Do a POSIX getfacl (UNIX extensions). | 
|---|
| 189 | ****************************************************************************/ | 
|---|
| 190 |  | 
|---|
| 191 | bool cli_unix_getfacl(struct cli_state *cli, const char *name, size_t *prb_size, char **retbuf) | 
|---|
| 192 | { | 
|---|
| 193 | unsigned int param_len = 0; | 
|---|
| 194 | unsigned int data_len = 0; | 
|---|
| 195 | uint16 setup = TRANSACT2_QPATHINFO; | 
|---|
| 196 | char *param; | 
|---|
| 197 | size_t nlen = 2*(strlen(name)+1); | 
|---|
| 198 | char *rparam=NULL, *rdata=NULL; | 
|---|
| 199 | char *p; | 
|---|
| 200 |  | 
|---|
| 201 | param = SMB_MALLOC_ARRAY(char, 6+nlen+2); | 
|---|
| 202 | if (!param) { | 
|---|
| 203 | return false; | 
|---|
| 204 | } | 
|---|
| 205 |  | 
|---|
| 206 | p = param; | 
|---|
| 207 | memset(p, '\0', 6); | 
|---|
| 208 | SSVAL(p, 0, SMB_QUERY_POSIX_ACL); | 
|---|
| 209 | p += 6; | 
|---|
| 210 | p += clistr_push(cli, p, name, nlen, STR_TERMINATE); | 
|---|
| 211 | param_len = PTR_DIFF(p, param); | 
|---|
| 212 |  | 
|---|
| 213 | if (!cli_send_trans(cli, SMBtrans2, | 
|---|
| 214 | NULL,                        /* name */ | 
|---|
| 215 | -1, 0,                       /* fid, flags */ | 
|---|
| 216 | &setup, 1, 0,                /* setup, length, max */ | 
|---|
| 217 | param, param_len, 2,         /* param, length, max */ | 
|---|
| 218 | NULL,  0, cli->max_xmit      /* data, length, max */ | 
|---|
| 219 | )) { | 
|---|
| 220 | SAFE_FREE(param); | 
|---|
| 221 | return false; | 
|---|
| 222 | } | 
|---|
| 223 |  | 
|---|
| 224 | SAFE_FREE(param); | 
|---|
| 225 |  | 
|---|
| 226 | if (!cli_receive_trans(cli, SMBtrans2, | 
|---|
| 227 | &rparam, ¶m_len, | 
|---|
| 228 | &rdata, &data_len)) { | 
|---|
| 229 | return false; | 
|---|
| 230 | } | 
|---|
| 231 |  | 
|---|
| 232 | if (data_len < 6) { | 
|---|
| 233 | SAFE_FREE(rdata); | 
|---|
| 234 | SAFE_FREE(rparam); | 
|---|
| 235 | return false; | 
|---|
| 236 | } | 
|---|
| 237 |  | 
|---|
| 238 | SAFE_FREE(rparam); | 
|---|
| 239 | *retbuf = rdata; | 
|---|
| 240 | *prb_size = (size_t)data_len; | 
|---|
| 241 |  | 
|---|
| 242 | return true; | 
|---|
| 243 | } | 
|---|
| 244 |  | 
|---|
| 245 | /**************************************************************************** | 
|---|
| 246 | Stat a file (UNIX extensions). | 
|---|
| 247 | ****************************************************************************/ | 
|---|
| 248 |  | 
|---|
| 249 | bool cli_unix_stat(struct cli_state *cli, const char *name, SMB_STRUCT_STAT *sbuf) | 
|---|
| 250 | { | 
|---|
| 251 | unsigned int param_len = 0; | 
|---|
| 252 | unsigned int data_len = 0; | 
|---|
| 253 | uint16 setup = TRANSACT2_QPATHINFO; | 
|---|
| 254 | char *param; | 
|---|
| 255 | size_t nlen = 2*(strlen(name)+1); | 
|---|
| 256 | char *rparam=NULL, *rdata=NULL; | 
|---|
| 257 | char *p; | 
|---|
| 258 |  | 
|---|
| 259 | ZERO_STRUCTP(sbuf); | 
|---|
| 260 |  | 
|---|
| 261 | param = SMB_MALLOC_ARRAY(char, 6+nlen+2); | 
|---|
| 262 | if (!param) { | 
|---|
| 263 | return false; | 
|---|
| 264 | } | 
|---|
| 265 | p = param; | 
|---|
| 266 | memset(p, '\0', 6); | 
|---|
| 267 | SSVAL(p, 0, SMB_QUERY_FILE_UNIX_BASIC); | 
|---|
| 268 | p += 6; | 
|---|
| 269 | p += clistr_push(cli, p, name, nlen, STR_TERMINATE); | 
|---|
| 270 | param_len = PTR_DIFF(p, param); | 
|---|
| 271 |  | 
|---|
| 272 | if (!cli_send_trans(cli, SMBtrans2, | 
|---|
| 273 | NULL,                        /* name */ | 
|---|
| 274 | -1, 0,                       /* fid, flags */ | 
|---|
| 275 | &setup, 1, 0,                /* setup, length, max */ | 
|---|
| 276 | param, param_len, 2,         /* param, length, max */ | 
|---|
| 277 | NULL,  0, cli->max_xmit      /* data, length, max */ | 
|---|
| 278 | )) { | 
|---|
| 279 | SAFE_FREE(param); | 
|---|
| 280 | return false; | 
|---|
| 281 | } | 
|---|
| 282 |  | 
|---|
| 283 | SAFE_FREE(param); | 
|---|
| 284 |  | 
|---|
| 285 | if (!cli_receive_trans(cli, SMBtrans2, | 
|---|
| 286 | &rparam, ¶m_len, | 
|---|
| 287 | &rdata, &data_len)) { | 
|---|
| 288 | return false; | 
|---|
| 289 | } | 
|---|
| 290 |  | 
|---|
| 291 | if (data_len < 96) { | 
|---|
| 292 | SAFE_FREE(rdata); | 
|---|
| 293 | SAFE_FREE(rparam); | 
|---|
| 294 | return false; | 
|---|
| 295 | } | 
|---|
| 296 |  | 
|---|
| 297 | sbuf->st_size = IVAL2_TO_SMB_BIG_UINT(rdata,0);     /* total size, in bytes */ | 
|---|
| 298 | sbuf->st_blocks = IVAL2_TO_SMB_BIG_UINT(rdata,8);   /* number of blocks allocated */ | 
|---|
| 299 | #if defined (HAVE_STAT_ST_BLOCKS) && defined(STAT_ST_BLOCKSIZE) | 
|---|
| 300 | sbuf->st_blocks /= STAT_ST_BLOCKSIZE; | 
|---|
| 301 | #else | 
|---|
| 302 | /* assume 512 byte blocks */ | 
|---|
| 303 | sbuf->st_blocks /= 512; | 
|---|
| 304 | #endif | 
|---|
| 305 | set_ctimespec(sbuf, interpret_long_date(rdata + 16));    /* time of last change */ | 
|---|
| 306 | set_atimespec(sbuf, interpret_long_date(rdata + 24));    /* time of last access */ | 
|---|
| 307 | set_mtimespec(sbuf, interpret_long_date(rdata + 32));    /* time of last modification */ | 
|---|
| 308 |  | 
|---|
| 309 | sbuf->st_uid = (uid_t) IVAL(rdata,40);      /* user ID of owner */ | 
|---|
| 310 | sbuf->st_gid = (gid_t) IVAL(rdata,48);      /* group ID of owner */ | 
|---|
| 311 | sbuf->st_mode |= unix_filetype_from_wire(IVAL(rdata, 56)); | 
|---|
| 312 | #if defined(HAVE_MAKEDEV) | 
|---|
| 313 | { | 
|---|
| 314 | uint32 dev_major = IVAL(rdata,60); | 
|---|
| 315 | uint32 dev_minor = IVAL(rdata,68); | 
|---|
| 316 | sbuf->st_rdev = makedev(dev_major, dev_minor); | 
|---|
| 317 | } | 
|---|
| 318 | #endif | 
|---|
| 319 | sbuf->st_ino = (SMB_INO_T)IVAL2_TO_SMB_BIG_UINT(rdata,76);      /* inode */ | 
|---|
| 320 | sbuf->st_mode |= wire_perms_to_unix(IVAL(rdata,84));     /* protection */ | 
|---|
| 321 | sbuf->st_nlink = IVAL(rdata,92);    /* number of hard links */ | 
|---|
| 322 |  | 
|---|
| 323 | SAFE_FREE(rdata); | 
|---|
| 324 | SAFE_FREE(rparam); | 
|---|
| 325 |  | 
|---|
| 326 | return true; | 
|---|
| 327 | } | 
|---|
| 328 |  | 
|---|
| 329 | /**************************************************************************** | 
|---|
| 330 | Symlink a file (UNIX extensions). | 
|---|
| 331 | ****************************************************************************/ | 
|---|
| 332 |  | 
|---|
| 333 | bool cli_unix_symlink(struct cli_state *cli, const char *oldname, const char *newname) | 
|---|
| 334 | { | 
|---|
| 335 | return cli_link_internal(cli, oldname, newname, False); | 
|---|
| 336 | } | 
|---|
| 337 |  | 
|---|
| 338 | /**************************************************************************** | 
|---|
| 339 | Hard a file (UNIX extensions). | 
|---|
| 340 | ****************************************************************************/ | 
|---|
| 341 |  | 
|---|
| 342 | bool cli_unix_hardlink(struct cli_state *cli, const char *oldname, const char *newname) | 
|---|
| 343 | { | 
|---|
| 344 | return cli_link_internal(cli, oldname, newname, True); | 
|---|
| 345 | } | 
|---|
| 346 |  | 
|---|
| 347 | /**************************************************************************** | 
|---|
| 348 | Chmod or chown a file internal (UNIX extensions). | 
|---|
| 349 | ****************************************************************************/ | 
|---|
| 350 |  | 
|---|
| 351 | static bool cli_unix_chmod_chown_internal(struct cli_state *cli, const char *fname, uint32 mode, uint32 uid, uint32 gid) | 
|---|
| 352 | { | 
|---|
| 353 | unsigned int data_len = 0; | 
|---|
| 354 | unsigned int param_len = 0; | 
|---|
| 355 | uint16 setup = TRANSACT2_SETPATHINFO; | 
|---|
| 356 | size_t nlen = 2*(strlen(fname)+1); | 
|---|
| 357 | char *param; | 
|---|
| 358 | char data[100]; | 
|---|
| 359 | char *rparam=NULL, *rdata=NULL; | 
|---|
| 360 | char *p; | 
|---|
| 361 |  | 
|---|
| 362 | param = SMB_MALLOC_ARRAY(char, 6+nlen+2); | 
|---|
| 363 | if (!param) { | 
|---|
| 364 | return false; | 
|---|
| 365 | } | 
|---|
| 366 | memset(param, '\0', 6); | 
|---|
| 367 | memset(data, 0, sizeof(data)); | 
|---|
| 368 |  | 
|---|
| 369 | SSVAL(param,0,SMB_SET_FILE_UNIX_BASIC); | 
|---|
| 370 | p = ¶m[6]; | 
|---|
| 371 |  | 
|---|
| 372 | p += clistr_push(cli, p, fname, nlen, STR_TERMINATE); | 
|---|
| 373 | param_len = PTR_DIFF(p, param); | 
|---|
| 374 |  | 
|---|
| 375 | memset(data, 0xff, 40); /* Set all sizes/times to no change. */ | 
|---|
| 376 |  | 
|---|
| 377 | SIVAL(data,40,uid); | 
|---|
| 378 | SIVAL(data,48,gid); | 
|---|
| 379 | SIVAL(data,84,mode); | 
|---|
| 380 |  | 
|---|
| 381 | data_len = 100; | 
|---|
| 382 |  | 
|---|
| 383 | if (!cli_send_trans(cli, SMBtrans2, | 
|---|
| 384 | NULL,                        /* name */ | 
|---|
| 385 | -1, 0,                          /* fid, flags */ | 
|---|
| 386 | &setup, 1, 0,                   /* setup, length, max */ | 
|---|
| 387 | param, param_len, 2,            /* param, length, max */ | 
|---|
| 388 | (char *)&data,  data_len, cli->max_xmit /* data, length, max */ | 
|---|
| 389 | )) { | 
|---|
| 390 | SAFE_FREE(param); | 
|---|
| 391 | return False; | 
|---|
| 392 | } | 
|---|
| 393 |  | 
|---|
| 394 | SAFE_FREE(param); | 
|---|
| 395 |  | 
|---|
| 396 | if (!cli_receive_trans(cli, SMBtrans2, | 
|---|
| 397 | &rparam, ¶m_len, | 
|---|
| 398 | &rdata, &data_len)) { | 
|---|
| 399 | return false; | 
|---|
| 400 | } | 
|---|
| 401 |  | 
|---|
| 402 | SAFE_FREE(rdata); | 
|---|
| 403 | SAFE_FREE(rparam); | 
|---|
| 404 |  | 
|---|
| 405 | return true; | 
|---|
| 406 | } | 
|---|
| 407 |  | 
|---|
| 408 | /**************************************************************************** | 
|---|
| 409 | chmod a file (UNIX extensions). | 
|---|
| 410 | ****************************************************************************/ | 
|---|
| 411 |  | 
|---|
| 412 | bool cli_unix_chmod(struct cli_state *cli, const char *fname, mode_t mode) | 
|---|
| 413 | { | 
|---|
| 414 | return cli_unix_chmod_chown_internal(cli, fname, | 
|---|
| 415 | unix_perms_to_wire(mode), SMB_UID_NO_CHANGE, SMB_GID_NO_CHANGE); | 
|---|
| 416 | } | 
|---|
| 417 |  | 
|---|
| 418 | /**************************************************************************** | 
|---|
| 419 | chown a file (UNIX extensions). | 
|---|
| 420 | ****************************************************************************/ | 
|---|
| 421 |  | 
|---|
| 422 | bool cli_unix_chown(struct cli_state *cli, const char *fname, uid_t uid, gid_t gid) | 
|---|
| 423 | { | 
|---|
| 424 | return cli_unix_chmod_chown_internal(cli, fname, | 
|---|
| 425 | SMB_MODE_NO_CHANGE, (uint32)uid, (uint32)gid); | 
|---|
| 426 | } | 
|---|
| 427 |  | 
|---|
| 428 | /**************************************************************************** | 
|---|
| 429 | Rename a file. | 
|---|
| 430 | ****************************************************************************/ | 
|---|
| 431 |  | 
|---|
| 432 | bool cli_rename(struct cli_state *cli, const char *fname_src, const char *fname_dst) | 
|---|
| 433 | { | 
|---|
| 434 | char *p; | 
|---|
| 435 |  | 
|---|
| 436 | memset(cli->outbuf,'\0',smb_size); | 
|---|
| 437 | memset(cli->inbuf,'\0',smb_size); | 
|---|
| 438 |  | 
|---|
| 439 | cli_set_message(cli->outbuf,1, 0, true); | 
|---|
| 440 |  | 
|---|
| 441 | SCVAL(cli->outbuf,smb_com,SMBmv); | 
|---|
| 442 | SSVAL(cli->outbuf,smb_tid,cli->cnum); | 
|---|
| 443 | cli_setup_packet(cli); | 
|---|
| 444 |  | 
|---|
| 445 | SSVAL(cli->outbuf,smb_vwv0,aSYSTEM | aHIDDEN | aDIR); | 
|---|
| 446 |  | 
|---|
| 447 | p = smb_buf(cli->outbuf); | 
|---|
| 448 | *p++ = 4; | 
|---|
| 449 | p += clistr_push(cli, p, fname_src, | 
|---|
| 450 | cli->bufsize - PTR_DIFF(p,cli->outbuf), STR_TERMINATE); | 
|---|
| 451 | *p++ = 4; | 
|---|
| 452 | p += clistr_push(cli, p, fname_dst, | 
|---|
| 453 | cli->bufsize - PTR_DIFF(p,cli->outbuf), STR_TERMINATE); | 
|---|
| 454 |  | 
|---|
| 455 | cli_setup_bcc(cli, p); | 
|---|
| 456 |  | 
|---|
| 457 | cli_send_smb(cli); | 
|---|
| 458 | if (!cli_receive_smb(cli)) { | 
|---|
| 459 | return false; | 
|---|
| 460 | } | 
|---|
| 461 |  | 
|---|
| 462 | if (cli_is_error(cli)) { | 
|---|
| 463 | return false; | 
|---|
| 464 | } | 
|---|
| 465 |  | 
|---|
| 466 | return true; | 
|---|
| 467 | } | 
|---|
| 468 |  | 
|---|
| 469 | /**************************************************************************** | 
|---|
| 470 | NT Rename a file. | 
|---|
| 471 | ****************************************************************************/ | 
|---|
| 472 |  | 
|---|
| 473 | bool cli_ntrename(struct cli_state *cli, const char *fname_src, const char *fname_dst) | 
|---|
| 474 | { | 
|---|
| 475 | char *p; | 
|---|
| 476 |  | 
|---|
| 477 | memset(cli->outbuf,'\0',smb_size); | 
|---|
| 478 | memset(cli->inbuf,'\0',smb_size); | 
|---|
| 479 |  | 
|---|
| 480 | cli_set_message(cli->outbuf, 4, 0, true); | 
|---|
| 481 |  | 
|---|
| 482 | SCVAL(cli->outbuf,smb_com,SMBntrename); | 
|---|
| 483 | SSVAL(cli->outbuf,smb_tid,cli->cnum); | 
|---|
| 484 | cli_setup_packet(cli); | 
|---|
| 485 |  | 
|---|
| 486 | SSVAL(cli->outbuf,smb_vwv0,aSYSTEM | aHIDDEN | aDIR); | 
|---|
| 487 | SSVAL(cli->outbuf,smb_vwv1, RENAME_FLAG_RENAME); | 
|---|
| 488 |  | 
|---|
| 489 | p = smb_buf(cli->outbuf); | 
|---|
| 490 | *p++ = 4; | 
|---|
| 491 | p += clistr_push(cli, p, fname_src, | 
|---|
| 492 | cli->bufsize - PTR_DIFF(p,cli->outbuf), STR_TERMINATE); | 
|---|
| 493 | *p++ = 4; | 
|---|
| 494 | p += clistr_push(cli, p, fname_dst, | 
|---|
| 495 | cli->bufsize - PTR_DIFF(p,cli->outbuf), STR_TERMINATE); | 
|---|
| 496 |  | 
|---|
| 497 | cli_setup_bcc(cli, p); | 
|---|
| 498 |  | 
|---|
| 499 | cli_send_smb(cli); | 
|---|
| 500 | if (!cli_receive_smb(cli)) { | 
|---|
| 501 | return false; | 
|---|
| 502 | } | 
|---|
| 503 |  | 
|---|
| 504 | if (cli_is_error(cli)) { | 
|---|
| 505 | return false; | 
|---|
| 506 | } | 
|---|
| 507 |  | 
|---|
| 508 | return true; | 
|---|
| 509 | } | 
|---|
| 510 |  | 
|---|
| 511 | /**************************************************************************** | 
|---|
| 512 | NT hardlink a file. | 
|---|
| 513 | ****************************************************************************/ | 
|---|
| 514 |  | 
|---|
| 515 | bool cli_nt_hardlink(struct cli_state *cli, const char *fname_src, const char *fname_dst) | 
|---|
| 516 | { | 
|---|
| 517 | char *p; | 
|---|
| 518 |  | 
|---|
| 519 | memset(cli->outbuf,'\0',smb_size); | 
|---|
| 520 | memset(cli->inbuf,'\0',smb_size); | 
|---|
| 521 |  | 
|---|
| 522 | cli_set_message(cli->outbuf, 4, 0, true); | 
|---|
| 523 |  | 
|---|
| 524 | SCVAL(cli->outbuf,smb_com,SMBntrename); | 
|---|
| 525 | SSVAL(cli->outbuf,smb_tid,cli->cnum); | 
|---|
| 526 | cli_setup_packet(cli); | 
|---|
| 527 |  | 
|---|
| 528 | SSVAL(cli->outbuf,smb_vwv0,aSYSTEM | aHIDDEN | aDIR); | 
|---|
| 529 | SSVAL(cli->outbuf,smb_vwv1, RENAME_FLAG_HARD_LINK); | 
|---|
| 530 |  | 
|---|
| 531 | p = smb_buf(cli->outbuf); | 
|---|
| 532 | *p++ = 4; | 
|---|
| 533 | p += clistr_push(cli, p, fname_src, | 
|---|
| 534 | cli->bufsize - PTR_DIFF(p,cli->outbuf), STR_TERMINATE); | 
|---|
| 535 | *p++ = 4; | 
|---|
| 536 | p += clistr_push(cli, p, fname_dst, | 
|---|
| 537 | cli->bufsize - PTR_DIFF(p,cli->outbuf), STR_TERMINATE); | 
|---|
| 538 |  | 
|---|
| 539 | cli_setup_bcc(cli, p); | 
|---|
| 540 |  | 
|---|
| 541 | cli_send_smb(cli); | 
|---|
| 542 | if (!cli_receive_smb(cli)) { | 
|---|
| 543 | return false; | 
|---|
| 544 | } | 
|---|
| 545 |  | 
|---|
| 546 | if (cli_is_error(cli)) { | 
|---|
| 547 | return false; | 
|---|
| 548 | } | 
|---|
| 549 |  | 
|---|
| 550 | return true; | 
|---|
| 551 | } | 
|---|
| 552 |  | 
|---|
| 553 | /**************************************************************************** | 
|---|
| 554 | Delete a file. | 
|---|
| 555 | ****************************************************************************/ | 
|---|
| 556 |  | 
|---|
| 557 | bool cli_unlink_full(struct cli_state *cli, const char *fname, uint16 attrs) | 
|---|
| 558 | { | 
|---|
| 559 | char *p; | 
|---|
| 560 |  | 
|---|
| 561 | memset(cli->outbuf,'\0',smb_size); | 
|---|
| 562 | memset(cli->inbuf,'\0',smb_size); | 
|---|
| 563 |  | 
|---|
| 564 | cli_set_message(cli->outbuf,1, 0, true); | 
|---|
| 565 |  | 
|---|
| 566 | SCVAL(cli->outbuf,smb_com,SMBunlink); | 
|---|
| 567 | SSVAL(cli->outbuf,smb_tid,cli->cnum); | 
|---|
| 568 | cli_setup_packet(cli); | 
|---|
| 569 |  | 
|---|
| 570 | SSVAL(cli->outbuf,smb_vwv0, attrs); | 
|---|
| 571 |  | 
|---|
| 572 | p = smb_buf(cli->outbuf); | 
|---|
| 573 | *p++ = 4; | 
|---|
| 574 | p += clistr_push(cli, p, fname, | 
|---|
| 575 | cli->bufsize - PTR_DIFF(p,cli->outbuf), STR_TERMINATE); | 
|---|
| 576 |  | 
|---|
| 577 | cli_setup_bcc(cli, p); | 
|---|
| 578 | cli_send_smb(cli); | 
|---|
| 579 | if (!cli_receive_smb(cli)) { | 
|---|
| 580 | return false; | 
|---|
| 581 | } | 
|---|
| 582 |  | 
|---|
| 583 | if (cli_is_error(cli)) { | 
|---|
| 584 | return false; | 
|---|
| 585 | } | 
|---|
| 586 |  | 
|---|
| 587 | return true; | 
|---|
| 588 | } | 
|---|
| 589 |  | 
|---|
| 590 | /**************************************************************************** | 
|---|
| 591 | Delete a file. | 
|---|
| 592 | ****************************************************************************/ | 
|---|
| 593 |  | 
|---|
| 594 | bool cli_unlink(struct cli_state *cli, const char *fname) | 
|---|
| 595 | { | 
|---|
| 596 | return cli_unlink_full(cli, fname, aSYSTEM | aHIDDEN); | 
|---|
| 597 | } | 
|---|
| 598 |  | 
|---|
| 599 | /**************************************************************************** | 
|---|
| 600 | Create a directory. | 
|---|
| 601 | ****************************************************************************/ | 
|---|
| 602 |  | 
|---|
| 603 | bool cli_mkdir(struct cli_state *cli, const char *dname) | 
|---|
| 604 | { | 
|---|
| 605 | char *p; | 
|---|
| 606 |  | 
|---|
| 607 | memset(cli->outbuf,'\0',smb_size); | 
|---|
| 608 | memset(cli->inbuf,'\0',smb_size); | 
|---|
| 609 |  | 
|---|
| 610 | cli_set_message(cli->outbuf,0, 0, true); | 
|---|
| 611 |  | 
|---|
| 612 | SCVAL(cli->outbuf,smb_com,SMBmkdir); | 
|---|
| 613 | SSVAL(cli->outbuf,smb_tid,cli->cnum); | 
|---|
| 614 | cli_setup_packet(cli); | 
|---|
| 615 |  | 
|---|
| 616 | p = smb_buf(cli->outbuf); | 
|---|
| 617 | *p++ = 4; | 
|---|
| 618 | p += clistr_push(cli, p, dname, | 
|---|
| 619 | cli->bufsize - PTR_DIFF(p,cli->outbuf), STR_TERMINATE); | 
|---|
| 620 |  | 
|---|
| 621 | cli_setup_bcc(cli, p); | 
|---|
| 622 |  | 
|---|
| 623 | cli_send_smb(cli); | 
|---|
| 624 | if (!cli_receive_smb(cli)) { | 
|---|
| 625 | return False; | 
|---|
| 626 | } | 
|---|
| 627 |  | 
|---|
| 628 | if (cli_is_error(cli)) { | 
|---|
| 629 | return False; | 
|---|
| 630 | } | 
|---|
| 631 |  | 
|---|
| 632 | return True; | 
|---|
| 633 | } | 
|---|
| 634 |  | 
|---|
| 635 | /**************************************************************************** | 
|---|
| 636 | Remove a directory. | 
|---|
| 637 | ****************************************************************************/ | 
|---|
| 638 |  | 
|---|
| 639 | bool cli_rmdir(struct cli_state *cli, const char *dname) | 
|---|
| 640 | { | 
|---|
| 641 | char *p; | 
|---|
| 642 |  | 
|---|
| 643 | memset(cli->outbuf,'\0',smb_size); | 
|---|
| 644 | memset(cli->inbuf,'\0',smb_size); | 
|---|
| 645 |  | 
|---|
| 646 | cli_set_message(cli->outbuf,0, 0, true); | 
|---|
| 647 |  | 
|---|
| 648 | SCVAL(cli->outbuf,smb_com,SMBrmdir); | 
|---|
| 649 | SSVAL(cli->outbuf,smb_tid,cli->cnum); | 
|---|
| 650 | cli_setup_packet(cli); | 
|---|
| 651 |  | 
|---|
| 652 | p = smb_buf(cli->outbuf); | 
|---|
| 653 | *p++ = 4; | 
|---|
| 654 | p += clistr_push(cli, p, dname, | 
|---|
| 655 | cli->bufsize - PTR_DIFF(p,cli->outbuf), STR_TERMINATE); | 
|---|
| 656 |  | 
|---|
| 657 | cli_setup_bcc(cli, p); | 
|---|
| 658 |  | 
|---|
| 659 | cli_send_smb(cli); | 
|---|
| 660 | if (!cli_receive_smb(cli)) { | 
|---|
| 661 | return false; | 
|---|
| 662 | } | 
|---|
| 663 |  | 
|---|
| 664 | if (cli_is_error(cli)) { | 
|---|
| 665 | return false; | 
|---|
| 666 | } | 
|---|
| 667 |  | 
|---|
| 668 | return true; | 
|---|
| 669 | } | 
|---|
| 670 |  | 
|---|
| 671 | /**************************************************************************** | 
|---|
| 672 | Set or clear the delete on close flag. | 
|---|
| 673 | ****************************************************************************/ | 
|---|
| 674 |  | 
|---|
| 675 | int cli_nt_delete_on_close(struct cli_state *cli, int fnum, bool flag) | 
|---|
| 676 | { | 
|---|
| 677 | unsigned int data_len = 1; | 
|---|
| 678 | unsigned int param_len = 6; | 
|---|
| 679 | uint16 setup = TRANSACT2_SETFILEINFO; | 
|---|
| 680 | char param[6]; | 
|---|
| 681 | unsigned char data; | 
|---|
| 682 | char *rparam=NULL, *rdata=NULL; | 
|---|
| 683 |  | 
|---|
| 684 | memset(param, 0, param_len); | 
|---|
| 685 | SSVAL(param,0,fnum); | 
|---|
| 686 | SSVAL(param,2,SMB_SET_FILE_DISPOSITION_INFO); | 
|---|
| 687 |  | 
|---|
| 688 | data = flag ? 1 : 0; | 
|---|
| 689 |  | 
|---|
| 690 | if (!cli_send_trans(cli, SMBtrans2, | 
|---|
| 691 | NULL,                        /* name */ | 
|---|
| 692 | -1, 0,                          /* fid, flags */ | 
|---|
| 693 | &setup, 1, 0,                   /* setup, length, max */ | 
|---|
| 694 | param, param_len, 2,            /* param, length, max */ | 
|---|
| 695 | (char *)&data,  data_len, cli->max_xmit /* data, length, max */ | 
|---|
| 696 | )) { | 
|---|
| 697 | return false; | 
|---|
| 698 | } | 
|---|
| 699 |  | 
|---|
| 700 | if (!cli_receive_trans(cli, SMBtrans2, | 
|---|
| 701 | &rparam, ¶m_len, | 
|---|
| 702 | &rdata, &data_len)) { | 
|---|
| 703 | return false; | 
|---|
| 704 | } | 
|---|
| 705 |  | 
|---|
| 706 | SAFE_FREE(rdata); | 
|---|
| 707 | SAFE_FREE(rparam); | 
|---|
| 708 |  | 
|---|
| 709 | return true; | 
|---|
| 710 | } | 
|---|
| 711 |  | 
|---|
| 712 | /**************************************************************************** | 
|---|
| 713 | Open a file - exposing the full horror of the NT API :-). | 
|---|
| 714 | Used in smbtorture. | 
|---|
| 715 | ****************************************************************************/ | 
|---|
| 716 |  | 
|---|
| 717 | int cli_nt_create_full(struct cli_state *cli, const char *fname, | 
|---|
| 718 | uint32 CreatFlags, uint32 DesiredAccess, | 
|---|
| 719 | uint32 FileAttributes, uint32 ShareAccess, | 
|---|
| 720 | uint32 CreateDisposition, uint32 CreateOptions, | 
|---|
| 721 | uint8 SecuityFlags) | 
|---|
| 722 | { | 
|---|
| 723 | char *p; | 
|---|
| 724 | int len; | 
|---|
| 725 |  | 
|---|
| 726 | memset(cli->outbuf,'\0',smb_size); | 
|---|
| 727 | memset(cli->inbuf,'\0',smb_size); | 
|---|
| 728 |  | 
|---|
| 729 | cli_set_message(cli->outbuf,24,0, true); | 
|---|
| 730 |  | 
|---|
| 731 | SCVAL(cli->outbuf,smb_com,SMBntcreateX); | 
|---|
| 732 | SSVAL(cli->outbuf,smb_tid,cli->cnum); | 
|---|
| 733 | cli_setup_packet(cli); | 
|---|
| 734 |  | 
|---|
| 735 | SSVAL(cli->outbuf,smb_vwv0,0xFF); | 
|---|
| 736 | if (cli->use_oplocks) | 
|---|
| 737 | CreatFlags |= (REQUEST_OPLOCK|REQUEST_BATCH_OPLOCK); | 
|---|
| 738 |  | 
|---|
| 739 | SIVAL(cli->outbuf,smb_ntcreate_Flags, CreatFlags); | 
|---|
| 740 | SIVAL(cli->outbuf,smb_ntcreate_RootDirectoryFid, 0x0); | 
|---|
| 741 | SIVAL(cli->outbuf,smb_ntcreate_DesiredAccess, DesiredAccess); | 
|---|
| 742 | SIVAL(cli->outbuf,smb_ntcreate_FileAttributes, FileAttributes); | 
|---|
| 743 | SIVAL(cli->outbuf,smb_ntcreate_ShareAccess, ShareAccess); | 
|---|
| 744 | SIVAL(cli->outbuf,smb_ntcreate_CreateDisposition, CreateDisposition); | 
|---|
| 745 | SIVAL(cli->outbuf,smb_ntcreate_CreateOptions, CreateOptions); | 
|---|
| 746 | SIVAL(cli->outbuf,smb_ntcreate_ImpersonationLevel, 0x02); | 
|---|
| 747 | SCVAL(cli->outbuf,smb_ntcreate_SecurityFlags, SecuityFlags); | 
|---|
| 748 |  | 
|---|
| 749 | p = smb_buf(cli->outbuf); | 
|---|
| 750 | /* this alignment and termination is critical for netapp filers. Don't change */ | 
|---|
| 751 | p += clistr_align_out(cli, p, 0); | 
|---|
| 752 | len = clistr_push(cli, p, fname, | 
|---|
| 753 | cli->bufsize - PTR_DIFF(p,cli->outbuf), 0); | 
|---|
| 754 | p += len; | 
|---|
| 755 | SSVAL(cli->outbuf,smb_ntcreate_NameLength, len); | 
|---|
| 756 | /* sigh. this copes with broken netapp filer behaviour */ | 
|---|
| 757 | p += clistr_push(cli, p, "", | 
|---|
| 758 | cli->bufsize - PTR_DIFF(p,cli->outbuf), STR_TERMINATE); | 
|---|
| 759 |  | 
|---|
| 760 | cli_setup_bcc(cli, p); | 
|---|
| 761 |  | 
|---|
| 762 | cli_send_smb(cli); | 
|---|
| 763 | if (!cli_receive_smb(cli)) { | 
|---|
| 764 | return -1; | 
|---|
| 765 | } | 
|---|
| 766 |  | 
|---|
| 767 | if (cli_is_error(cli)) { | 
|---|
| 768 | return -1; | 
|---|
| 769 | } | 
|---|
| 770 |  | 
|---|
| 771 | return SVAL(cli->inbuf,smb_vwv2 + 1); | 
|---|
| 772 | } | 
|---|
| 773 |  | 
|---|
| 774 | /**************************************************************************** | 
|---|
| 775 | Open a file. | 
|---|
| 776 | ****************************************************************************/ | 
|---|
| 777 |  | 
|---|
| 778 | int cli_nt_create(struct cli_state *cli, const char *fname, uint32 DesiredAccess) | 
|---|
| 779 | { | 
|---|
| 780 | return cli_nt_create_full(cli, fname, 0, DesiredAccess, 0, | 
|---|
| 781 | FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0x0, 0x0); | 
|---|
| 782 | } | 
|---|
| 783 |  | 
|---|
| 784 | /**************************************************************************** | 
|---|
| 785 | Open a file | 
|---|
| 786 | WARNING: if you open with O_WRONLY then getattrE won't work! | 
|---|
| 787 | ****************************************************************************/ | 
|---|
| 788 |  | 
|---|
| 789 | int cli_open(struct cli_state *cli, const char *fname, int flags, int share_mode) | 
|---|
| 790 | { | 
|---|
| 791 | char *p; | 
|---|
| 792 | unsigned openfn=0; | 
|---|
| 793 | unsigned accessmode=0; | 
|---|
| 794 |  | 
|---|
| 795 | if (flags & O_CREAT) | 
|---|
| 796 | openfn |= (1<<4); | 
|---|
| 797 | if (!(flags & O_EXCL)) { | 
|---|
| 798 | if (flags & O_TRUNC) | 
|---|
| 799 | openfn |= (1<<1); | 
|---|
| 800 | else | 
|---|
| 801 | openfn |= (1<<0); | 
|---|
| 802 | } | 
|---|
| 803 |  | 
|---|
| 804 | accessmode = (share_mode<<4); | 
|---|
| 805 |  | 
|---|
| 806 | if ((flags & O_ACCMODE) == O_RDWR) { | 
|---|
| 807 | accessmode |= 2; | 
|---|
| 808 | } else if ((flags & O_ACCMODE) == O_WRONLY) { | 
|---|
| 809 | accessmode |= 1; | 
|---|
| 810 | } | 
|---|
| 811 |  | 
|---|
| 812 | #if defined(O_SYNC) | 
|---|
| 813 | if ((flags & O_SYNC) == O_SYNC) { | 
|---|
| 814 | accessmode |= (1<<14); | 
|---|
| 815 | } | 
|---|
| 816 | #endif /* O_SYNC */ | 
|---|
| 817 |  | 
|---|
| 818 | if (share_mode == DENY_FCB) { | 
|---|
| 819 | accessmode = 0xFF; | 
|---|
| 820 | } | 
|---|
| 821 |  | 
|---|
| 822 | memset(cli->outbuf,'\0',smb_size); | 
|---|
| 823 | memset(cli->inbuf,'\0',smb_size); | 
|---|
| 824 |  | 
|---|
| 825 | cli_set_message(cli->outbuf,15,0, true); | 
|---|
| 826 |  | 
|---|
| 827 | SCVAL(cli->outbuf,smb_com,SMBopenX); | 
|---|
| 828 | SSVAL(cli->outbuf,smb_tid,cli->cnum); | 
|---|
| 829 | cli_setup_packet(cli); | 
|---|
| 830 |  | 
|---|
| 831 | SSVAL(cli->outbuf,smb_vwv0,0xFF); | 
|---|
| 832 | SSVAL(cli->outbuf,smb_vwv2,0);  /* no additional info */ | 
|---|
| 833 | SSVAL(cli->outbuf,smb_vwv3,accessmode); | 
|---|
| 834 | SSVAL(cli->outbuf,smb_vwv4,aSYSTEM | aHIDDEN); | 
|---|
| 835 | SSVAL(cli->outbuf,smb_vwv5,0); | 
|---|
| 836 | SSVAL(cli->outbuf,smb_vwv8,openfn); | 
|---|
| 837 |  | 
|---|
| 838 | if (cli->use_oplocks) { | 
|---|
| 839 | /* if using oplocks then ask for a batch oplock via | 
|---|
| 840 | core and extended methods */ | 
|---|
| 841 | SCVAL(cli->outbuf,smb_flg, CVAL(cli->outbuf,smb_flg)| | 
|---|
| 842 | FLAG_REQUEST_OPLOCK|FLAG_REQUEST_BATCH_OPLOCK); | 
|---|
| 843 | SSVAL(cli->outbuf,smb_vwv2,SVAL(cli->outbuf,smb_vwv2) | 6); | 
|---|
| 844 | } | 
|---|
| 845 |  | 
|---|
| 846 | p = smb_buf(cli->outbuf); | 
|---|
| 847 | p += clistr_push(cli, p, fname, | 
|---|
| 848 | cli->bufsize - PTR_DIFF(p,cli->outbuf), STR_TERMINATE); | 
|---|
| 849 |  | 
|---|
| 850 | cli_setup_bcc(cli, p); | 
|---|
| 851 |  | 
|---|
| 852 | cli_send_smb(cli); | 
|---|
| 853 | if (!cli_receive_smb(cli)) { | 
|---|
| 854 | return -1; | 
|---|
| 855 | } | 
|---|
| 856 |  | 
|---|
| 857 | if (cli_is_error(cli)) { | 
|---|
| 858 | return -1; | 
|---|
| 859 | } | 
|---|
| 860 |  | 
|---|
| 861 | return SVAL(cli->inbuf,smb_vwv2); | 
|---|
| 862 | } | 
|---|
| 863 |  | 
|---|
| 864 | /**************************************************************************** | 
|---|
| 865 | Close a file. | 
|---|
| 866 | ****************************************************************************/ | 
|---|
| 867 |  | 
|---|
| 868 | bool cli_close(struct cli_state *cli, int fnum) | 
|---|
| 869 | { | 
|---|
| 870 | memset(cli->outbuf,'\0',smb_size); | 
|---|
| 871 | memset(cli->inbuf,'\0',smb_size); | 
|---|
| 872 |  | 
|---|
| 873 | cli_set_message(cli->outbuf,3,0,True); | 
|---|
| 874 |  | 
|---|
| 875 | SCVAL(cli->outbuf,smb_com,SMBclose); | 
|---|
| 876 | SSVAL(cli->outbuf,smb_tid,cli->cnum); | 
|---|
| 877 | cli_setup_packet(cli); | 
|---|
| 878 |  | 
|---|
| 879 | SSVAL(cli->outbuf,smb_vwv0,fnum); | 
|---|
| 880 | SIVALS(cli->outbuf,smb_vwv1,-1); | 
|---|
| 881 |  | 
|---|
| 882 | cli_send_smb(cli); | 
|---|
| 883 | if (!cli_receive_smb(cli)) { | 
|---|
| 884 | return False; | 
|---|
| 885 | } | 
|---|
| 886 |  | 
|---|
| 887 | return !cli_is_error(cli); | 
|---|
| 888 | } | 
|---|
| 889 |  | 
|---|
| 890 |  | 
|---|
| 891 | /**************************************************************************** | 
|---|
| 892 | Truncate a file to a specified size | 
|---|
| 893 | ****************************************************************************/ | 
|---|
| 894 |  | 
|---|
| 895 | bool cli_ftruncate(struct cli_state *cli, int fnum, uint64_t size) | 
|---|
| 896 | { | 
|---|
| 897 | unsigned int param_len = 6; | 
|---|
| 898 | unsigned int data_len = 8; | 
|---|
| 899 | uint16 setup = TRANSACT2_SETFILEINFO; | 
|---|
| 900 | char param[6]; | 
|---|
| 901 | unsigned char data[8]; | 
|---|
| 902 | char *rparam=NULL, *rdata=NULL; | 
|---|
| 903 | int saved_timeout = cli->timeout; | 
|---|
| 904 |  | 
|---|
| 905 | SSVAL(param,0,fnum); | 
|---|
| 906 | SSVAL(param,2,SMB_SET_FILE_END_OF_FILE_INFO); | 
|---|
| 907 | SSVAL(param,4,0); | 
|---|
| 908 |  | 
|---|
| 909 | SBVAL(data, 0, size); | 
|---|
| 910 |  | 
|---|
| 911 | if (!cli_send_trans(cli, SMBtrans2, | 
|---|
| 912 | NULL,                    /* name */ | 
|---|
| 913 | -1, 0,                   /* fid, flags */ | 
|---|
| 914 | &setup, 1, 0,            /* setup, length, max */ | 
|---|
| 915 | param, param_len, 2,     /* param, length, max */ | 
|---|
| 916 | (char *)&data,  data_len,/* data, length, ... */ | 
|---|
| 917 | cli->max_xmit)) {        /* ... max */ | 
|---|
| 918 | cli->timeout = saved_timeout; | 
|---|
| 919 | return False; | 
|---|
| 920 | } | 
|---|
| 921 |  | 
|---|
| 922 | if (!cli_receive_trans(cli, SMBtrans2, | 
|---|
| 923 | &rparam, ¶m_len, | 
|---|
| 924 | &rdata, &data_len)) { | 
|---|
| 925 | cli->timeout = saved_timeout; | 
|---|
| 926 | SAFE_FREE(rdata); | 
|---|
| 927 | SAFE_FREE(rparam); | 
|---|
| 928 | return False; | 
|---|
| 929 | } | 
|---|
| 930 |  | 
|---|
| 931 | cli->timeout = saved_timeout; | 
|---|
| 932 |  | 
|---|
| 933 | SAFE_FREE(rdata); | 
|---|
| 934 | SAFE_FREE(rparam); | 
|---|
| 935 |  | 
|---|
| 936 | return True; | 
|---|
| 937 | } | 
|---|
| 938 |  | 
|---|
| 939 |  | 
|---|
| 940 | /**************************************************************************** | 
|---|
| 941 | send a lock with a specified locktype | 
|---|
| 942 | this is used for testing LOCKING_ANDX_CANCEL_LOCK | 
|---|
| 943 | ****************************************************************************/ | 
|---|
| 944 |  | 
|---|
| 945 | NTSTATUS cli_locktype(struct cli_state *cli, int fnum, | 
|---|
| 946 | uint32 offset, uint32 len, | 
|---|
| 947 | int timeout, unsigned char locktype) | 
|---|
| 948 | { | 
|---|
| 949 | char *p; | 
|---|
| 950 | int saved_timeout = cli->timeout; | 
|---|
| 951 |  | 
|---|
| 952 | memset(cli->outbuf,'\0',smb_size); | 
|---|
| 953 | memset(cli->inbuf,'\0', smb_size); | 
|---|
| 954 |  | 
|---|
| 955 | cli_set_message(cli->outbuf,8,0,True); | 
|---|
| 956 |  | 
|---|
| 957 | SCVAL(cli->outbuf,smb_com,SMBlockingX); | 
|---|
| 958 | SSVAL(cli->outbuf,smb_tid,cli->cnum); | 
|---|
| 959 | cli_setup_packet(cli); | 
|---|
| 960 |  | 
|---|
| 961 | SCVAL(cli->outbuf,smb_vwv0,0xFF); | 
|---|
| 962 | SSVAL(cli->outbuf,smb_vwv2,fnum); | 
|---|
| 963 | SCVAL(cli->outbuf,smb_vwv3,locktype); | 
|---|
| 964 | SIVALS(cli->outbuf, smb_vwv4, timeout); | 
|---|
| 965 | SSVAL(cli->outbuf,smb_vwv6,0); | 
|---|
| 966 | SSVAL(cli->outbuf,smb_vwv7,1); | 
|---|
| 967 |  | 
|---|
| 968 | p = smb_buf(cli->outbuf); | 
|---|
| 969 | SSVAL(p, 0, cli->pid); | 
|---|
| 970 | SIVAL(p, 2, offset); | 
|---|
| 971 | SIVAL(p, 6, len); | 
|---|
| 972 |  | 
|---|
| 973 | p += 10; | 
|---|
| 974 |  | 
|---|
| 975 | cli_setup_bcc(cli, p); | 
|---|
| 976 |  | 
|---|
| 977 | cli_send_smb(cli); | 
|---|
| 978 |  | 
|---|
| 979 | if (timeout != 0) { | 
|---|
| 980 | cli->timeout = (timeout == -1) ? 0x7FFFFFFF : (timeout + 2*1000); | 
|---|
| 981 | } | 
|---|
| 982 |  | 
|---|
| 983 | if (!cli_receive_smb(cli)) { | 
|---|
| 984 | cli->timeout = saved_timeout; | 
|---|
| 985 | return NT_STATUS_UNSUCCESSFUL; | 
|---|
| 986 | } | 
|---|
| 987 |  | 
|---|
| 988 | cli->timeout = saved_timeout; | 
|---|
| 989 |  | 
|---|
| 990 | return cli_nt_error(cli); | 
|---|
| 991 | } | 
|---|
| 992 |  | 
|---|
| 993 | /**************************************************************************** | 
|---|
| 994 | Lock a file. | 
|---|
| 995 | note that timeout is in units of 2 milliseconds | 
|---|
| 996 | ****************************************************************************/ | 
|---|
| 997 |  | 
|---|
| 998 | bool cli_lock(struct cli_state *cli, int fnum, | 
|---|
| 999 | uint32 offset, uint32 len, int timeout, enum brl_type lock_type) | 
|---|
| 1000 | { | 
|---|
| 1001 | char *p; | 
|---|
| 1002 | int saved_timeout = cli->timeout; | 
|---|
| 1003 |  | 
|---|
| 1004 | memset(cli->outbuf,'\0',smb_size); | 
|---|
| 1005 | memset(cli->inbuf,'\0', smb_size); | 
|---|
| 1006 |  | 
|---|
| 1007 | cli_set_message(cli->outbuf,8,0,True); | 
|---|
| 1008 |  | 
|---|
| 1009 | SCVAL(cli->outbuf,smb_com,SMBlockingX); | 
|---|
| 1010 | SSVAL(cli->outbuf,smb_tid,cli->cnum); | 
|---|
| 1011 | cli_setup_packet(cli); | 
|---|
| 1012 |  | 
|---|
| 1013 | SCVAL(cli->outbuf,smb_vwv0,0xFF); | 
|---|
| 1014 | SSVAL(cli->outbuf,smb_vwv2,fnum); | 
|---|
| 1015 | SCVAL(cli->outbuf,smb_vwv3,(lock_type == READ_LOCK? 1 : 0)); | 
|---|
| 1016 | SIVALS(cli->outbuf, smb_vwv4, timeout); | 
|---|
| 1017 | SSVAL(cli->outbuf,smb_vwv6,0); | 
|---|
| 1018 | SSVAL(cli->outbuf,smb_vwv7,1); | 
|---|
| 1019 |  | 
|---|
| 1020 | p = smb_buf(cli->outbuf); | 
|---|
| 1021 | SSVAL(p, 0, cli->pid); | 
|---|
| 1022 | SIVAL(p, 2, offset); | 
|---|
| 1023 | SIVAL(p, 6, len); | 
|---|
| 1024 |  | 
|---|
| 1025 | p += 10; | 
|---|
| 1026 |  | 
|---|
| 1027 | cli_setup_bcc(cli, p); | 
|---|
| 1028 |  | 
|---|
| 1029 | cli_send_smb(cli); | 
|---|
| 1030 |  | 
|---|
| 1031 | if (timeout != 0) { | 
|---|
| 1032 | cli->timeout = (timeout == -1) ? 0x7FFFFFFF : (timeout*2 + 5*1000); | 
|---|
| 1033 | } | 
|---|
| 1034 |  | 
|---|
| 1035 | if (!cli_receive_smb(cli)) { | 
|---|
| 1036 | cli->timeout = saved_timeout; | 
|---|
| 1037 | return False; | 
|---|
| 1038 | } | 
|---|
| 1039 |  | 
|---|
| 1040 | cli->timeout = saved_timeout; | 
|---|
| 1041 |  | 
|---|
| 1042 | if (cli_is_error(cli)) { | 
|---|
| 1043 | return False; | 
|---|
| 1044 | } | 
|---|
| 1045 |  | 
|---|
| 1046 | return True; | 
|---|
| 1047 | } | 
|---|
| 1048 |  | 
|---|
| 1049 | /**************************************************************************** | 
|---|
| 1050 | Unlock a file. | 
|---|
| 1051 | ****************************************************************************/ | 
|---|
| 1052 |  | 
|---|
| 1053 | bool cli_unlock(struct cli_state *cli, int fnum, uint32 offset, uint32 len) | 
|---|
| 1054 | { | 
|---|
| 1055 | char *p; | 
|---|
| 1056 |  | 
|---|
| 1057 | memset(cli->outbuf,'\0',smb_size); | 
|---|
| 1058 | memset(cli->inbuf,'\0',smb_size); | 
|---|
| 1059 |  | 
|---|
| 1060 | cli_set_message(cli->outbuf,8,0,True); | 
|---|
| 1061 |  | 
|---|
| 1062 | SCVAL(cli->outbuf,smb_com,SMBlockingX); | 
|---|
| 1063 | SSVAL(cli->outbuf,smb_tid,cli->cnum); | 
|---|
| 1064 | cli_setup_packet(cli); | 
|---|
| 1065 |  | 
|---|
| 1066 | SCVAL(cli->outbuf,smb_vwv0,0xFF); | 
|---|
| 1067 | SSVAL(cli->outbuf,smb_vwv2,fnum); | 
|---|
| 1068 | SCVAL(cli->outbuf,smb_vwv3,0); | 
|---|
| 1069 | SIVALS(cli->outbuf, smb_vwv4, 0); | 
|---|
| 1070 | SSVAL(cli->outbuf,smb_vwv6,1); | 
|---|
| 1071 | SSVAL(cli->outbuf,smb_vwv7,0); | 
|---|
| 1072 |  | 
|---|
| 1073 | p = smb_buf(cli->outbuf); | 
|---|
| 1074 | SSVAL(p, 0, cli->pid); | 
|---|
| 1075 | SIVAL(p, 2, offset); | 
|---|
| 1076 | SIVAL(p, 6, len); | 
|---|
| 1077 | p += 10; | 
|---|
| 1078 | cli_setup_bcc(cli, p); | 
|---|
| 1079 | cli_send_smb(cli); | 
|---|
| 1080 | if (!cli_receive_smb(cli)) { | 
|---|
| 1081 | return False; | 
|---|
| 1082 | } | 
|---|
| 1083 |  | 
|---|
| 1084 | if (cli_is_error(cli)) { | 
|---|
| 1085 | return False; | 
|---|
| 1086 | } | 
|---|
| 1087 |  | 
|---|
| 1088 | return True; | 
|---|
| 1089 | } | 
|---|
| 1090 |  | 
|---|
| 1091 | /**************************************************************************** | 
|---|
| 1092 | Lock a file with 64 bit offsets. | 
|---|
| 1093 | ****************************************************************************/ | 
|---|
| 1094 |  | 
|---|
| 1095 | bool cli_lock64(struct cli_state *cli, int fnum, | 
|---|
| 1096 | SMB_BIG_UINT offset, SMB_BIG_UINT len, int timeout, enum brl_type lock_type) | 
|---|
| 1097 | { | 
|---|
| 1098 | char *p; | 
|---|
| 1099 | int saved_timeout = cli->timeout; | 
|---|
| 1100 | int ltype; | 
|---|
| 1101 |  | 
|---|
| 1102 | if (! (cli->capabilities & CAP_LARGE_FILES)) { | 
|---|
| 1103 | return cli_lock(cli, fnum, offset, len, timeout, lock_type); | 
|---|
| 1104 | } | 
|---|
| 1105 |  | 
|---|
| 1106 | ltype = (lock_type == READ_LOCK? 1 : 0); | 
|---|
| 1107 | ltype |= LOCKING_ANDX_LARGE_FILES; | 
|---|
| 1108 |  | 
|---|
| 1109 | memset(cli->outbuf,'\0',smb_size); | 
|---|
| 1110 | memset(cli->inbuf,'\0', smb_size); | 
|---|
| 1111 |  | 
|---|
| 1112 | cli_set_message(cli->outbuf,8,0,True); | 
|---|
| 1113 |  | 
|---|
| 1114 | SCVAL(cli->outbuf,smb_com,SMBlockingX); | 
|---|
| 1115 | SSVAL(cli->outbuf,smb_tid,cli->cnum); | 
|---|
| 1116 | cli_setup_packet(cli); | 
|---|
| 1117 |  | 
|---|
| 1118 | SCVAL(cli->outbuf,smb_vwv0,0xFF); | 
|---|
| 1119 | SSVAL(cli->outbuf,smb_vwv2,fnum); | 
|---|
| 1120 | SCVAL(cli->outbuf,smb_vwv3,ltype); | 
|---|
| 1121 | SIVALS(cli->outbuf, smb_vwv4, timeout); | 
|---|
| 1122 | SSVAL(cli->outbuf,smb_vwv6,0); | 
|---|
| 1123 | SSVAL(cli->outbuf,smb_vwv7,1); | 
|---|
| 1124 |  | 
|---|
| 1125 | p = smb_buf(cli->outbuf); | 
|---|
| 1126 | SIVAL(p, 0, cli->pid); | 
|---|
| 1127 | SOFF_T_R(p, 4, offset); | 
|---|
| 1128 | SOFF_T_R(p, 12, len); | 
|---|
| 1129 | p += 20; | 
|---|
| 1130 |  | 
|---|
| 1131 | cli_setup_bcc(cli, p); | 
|---|
| 1132 | cli_send_smb(cli); | 
|---|
| 1133 |  | 
|---|
| 1134 | if (timeout != 0) { | 
|---|
| 1135 | cli->timeout = (timeout == -1) ? 0x7FFFFFFF : (timeout + 5*1000); | 
|---|
| 1136 | } | 
|---|
| 1137 |  | 
|---|
| 1138 | if (!cli_receive_smb(cli)) { | 
|---|
| 1139 | cli->timeout = saved_timeout; | 
|---|
| 1140 | return False; | 
|---|
| 1141 | } | 
|---|
| 1142 |  | 
|---|
| 1143 | cli->timeout = saved_timeout; | 
|---|
| 1144 |  | 
|---|
| 1145 | if (cli_is_error(cli)) { | 
|---|
| 1146 | return False; | 
|---|
| 1147 | } | 
|---|
| 1148 |  | 
|---|
| 1149 | return True; | 
|---|
| 1150 | } | 
|---|
| 1151 |  | 
|---|
| 1152 | /**************************************************************************** | 
|---|
| 1153 | Unlock a file with 64 bit offsets. | 
|---|
| 1154 | ****************************************************************************/ | 
|---|
| 1155 |  | 
|---|
| 1156 | bool cli_unlock64(struct cli_state *cli, int fnum, SMB_BIG_UINT offset, SMB_BIG_UINT len) | 
|---|
| 1157 | { | 
|---|
| 1158 | char *p; | 
|---|
| 1159 |  | 
|---|
| 1160 | if (! (cli->capabilities & CAP_LARGE_FILES)) { | 
|---|
| 1161 | return cli_unlock(cli, fnum, offset, len); | 
|---|
| 1162 | } | 
|---|
| 1163 |  | 
|---|
| 1164 | memset(cli->outbuf,'\0',smb_size); | 
|---|
| 1165 | memset(cli->inbuf,'\0',smb_size); | 
|---|
| 1166 |  | 
|---|
| 1167 | cli_set_message(cli->outbuf,8,0,True); | 
|---|
| 1168 |  | 
|---|
| 1169 | SCVAL(cli->outbuf,smb_com,SMBlockingX); | 
|---|
| 1170 | SSVAL(cli->outbuf,smb_tid,cli->cnum); | 
|---|
| 1171 | cli_setup_packet(cli); | 
|---|
| 1172 |  | 
|---|
| 1173 | SCVAL(cli->outbuf,smb_vwv0,0xFF); | 
|---|
| 1174 | SSVAL(cli->outbuf,smb_vwv2,fnum); | 
|---|
| 1175 | SCVAL(cli->outbuf,smb_vwv3,LOCKING_ANDX_LARGE_FILES); | 
|---|
| 1176 | SIVALS(cli->outbuf, smb_vwv4, 0); | 
|---|
| 1177 | SSVAL(cli->outbuf,smb_vwv6,1); | 
|---|
| 1178 | SSVAL(cli->outbuf,smb_vwv7,0); | 
|---|
| 1179 |  | 
|---|
| 1180 | p = smb_buf(cli->outbuf); | 
|---|
| 1181 | SIVAL(p, 0, cli->pid); | 
|---|
| 1182 | SOFF_T_R(p, 4, offset); | 
|---|
| 1183 | SOFF_T_R(p, 12, len); | 
|---|
| 1184 | p += 20; | 
|---|
| 1185 | cli_setup_bcc(cli, p); | 
|---|
| 1186 | cli_send_smb(cli); | 
|---|
| 1187 | if (!cli_receive_smb(cli)) { | 
|---|
| 1188 | return False; | 
|---|
| 1189 | } | 
|---|
| 1190 |  | 
|---|
| 1191 | if (cli_is_error(cli)) { | 
|---|
| 1192 | return False; | 
|---|
| 1193 | } | 
|---|
| 1194 |  | 
|---|
| 1195 | return True; | 
|---|
| 1196 | } | 
|---|
| 1197 |  | 
|---|
| 1198 | /**************************************************************************** | 
|---|
| 1199 | Get/unlock a POSIX lock on a file - internal function. | 
|---|
| 1200 | ****************************************************************************/ | 
|---|
| 1201 |  | 
|---|
| 1202 | static bool cli_posix_lock_internal(struct cli_state *cli, int fnum, | 
|---|
| 1203 | SMB_BIG_UINT offset, SMB_BIG_UINT len, bool wait_lock, enum brl_type lock_type) | 
|---|
| 1204 | { | 
|---|
| 1205 | unsigned int param_len = 4; | 
|---|
| 1206 | unsigned int data_len = POSIX_LOCK_DATA_SIZE; | 
|---|
| 1207 | uint16 setup = TRANSACT2_SETFILEINFO; | 
|---|
| 1208 | char param[4]; | 
|---|
| 1209 | unsigned char data[POSIX_LOCK_DATA_SIZE]; | 
|---|
| 1210 | char *rparam=NULL, *rdata=NULL; | 
|---|
| 1211 | int saved_timeout = cli->timeout; | 
|---|
| 1212 |  | 
|---|
| 1213 | SSVAL(param,0,fnum); | 
|---|
| 1214 | SSVAL(param,2,SMB_SET_POSIX_LOCK); | 
|---|
| 1215 |  | 
|---|
| 1216 | switch (lock_type) { | 
|---|
| 1217 | case READ_LOCK: | 
|---|
| 1218 | SSVAL(data, POSIX_LOCK_TYPE_OFFSET, POSIX_LOCK_TYPE_READ); | 
|---|
| 1219 | break; | 
|---|
| 1220 | case WRITE_LOCK: | 
|---|
| 1221 | SSVAL(data, POSIX_LOCK_TYPE_OFFSET, POSIX_LOCK_TYPE_WRITE); | 
|---|
| 1222 | break; | 
|---|
| 1223 | case UNLOCK_LOCK: | 
|---|
| 1224 | SSVAL(data, POSIX_LOCK_TYPE_OFFSET, POSIX_LOCK_TYPE_UNLOCK); | 
|---|
| 1225 | break; | 
|---|
| 1226 | default: | 
|---|
| 1227 | return False; | 
|---|
| 1228 | } | 
|---|
| 1229 |  | 
|---|
| 1230 | if (wait_lock) { | 
|---|
| 1231 | SSVAL(data, POSIX_LOCK_FLAGS_OFFSET, POSIX_LOCK_FLAG_WAIT); | 
|---|
| 1232 | cli->timeout = 0x7FFFFFFF; | 
|---|
| 1233 | } else { | 
|---|
| 1234 | SSVAL(data, POSIX_LOCK_FLAGS_OFFSET, POSIX_LOCK_FLAG_NOWAIT); | 
|---|
| 1235 | } | 
|---|
| 1236 |  | 
|---|
| 1237 | SIVAL(data, POSIX_LOCK_PID_OFFSET, cli->pid); | 
|---|
| 1238 | SOFF_T(data, POSIX_LOCK_START_OFFSET, offset); | 
|---|
| 1239 | SOFF_T(data, POSIX_LOCK_LEN_OFFSET, len); | 
|---|
| 1240 |  | 
|---|
| 1241 | if (!cli_send_trans(cli, SMBtrans2, | 
|---|
| 1242 | NULL,                        /* name */ | 
|---|
| 1243 | -1, 0,                          /* fid, flags */ | 
|---|
| 1244 | &setup, 1, 0,                   /* setup, length, max */ | 
|---|
| 1245 | param, param_len, 2,            /* param, length, max */ | 
|---|
| 1246 | (char *)&data,  data_len, cli->max_xmit /* data, length, max */ | 
|---|
| 1247 | )) { | 
|---|
| 1248 | cli->timeout = saved_timeout; | 
|---|
| 1249 | return False; | 
|---|
| 1250 | } | 
|---|
| 1251 |  | 
|---|
| 1252 | if (!cli_receive_trans(cli, SMBtrans2, | 
|---|
| 1253 | &rparam, ¶m_len, | 
|---|
| 1254 | &rdata, &data_len)) { | 
|---|
| 1255 | cli->timeout = saved_timeout; | 
|---|
| 1256 | SAFE_FREE(rdata); | 
|---|
| 1257 | SAFE_FREE(rparam); | 
|---|
| 1258 | return False; | 
|---|
| 1259 | } | 
|---|
| 1260 |  | 
|---|
| 1261 | cli->timeout = saved_timeout; | 
|---|
| 1262 |  | 
|---|
| 1263 | SAFE_FREE(rdata); | 
|---|
| 1264 | SAFE_FREE(rparam); | 
|---|
| 1265 |  | 
|---|
| 1266 | return True; | 
|---|
| 1267 | } | 
|---|
| 1268 |  | 
|---|
| 1269 | /**************************************************************************** | 
|---|
| 1270 | POSIX Lock a file. | 
|---|
| 1271 | ****************************************************************************/ | 
|---|
| 1272 |  | 
|---|
| 1273 | bool cli_posix_lock(struct cli_state *cli, int fnum, | 
|---|
| 1274 | SMB_BIG_UINT offset, SMB_BIG_UINT len, | 
|---|
| 1275 | bool wait_lock, enum brl_type lock_type) | 
|---|
| 1276 | { | 
|---|
| 1277 | if (lock_type != READ_LOCK && lock_type != WRITE_LOCK) { | 
|---|
| 1278 | return False; | 
|---|
| 1279 | } | 
|---|
| 1280 | return cli_posix_lock_internal(cli, fnum, offset, len, wait_lock, lock_type); | 
|---|
| 1281 | } | 
|---|
| 1282 |  | 
|---|
| 1283 | /**************************************************************************** | 
|---|
| 1284 | POSIX Unlock a file. | 
|---|
| 1285 | ****************************************************************************/ | 
|---|
| 1286 |  | 
|---|
| 1287 | bool cli_posix_unlock(struct cli_state *cli, int fnum, SMB_BIG_UINT offset, SMB_BIG_UINT len) | 
|---|
| 1288 | { | 
|---|
| 1289 | return cli_posix_lock_internal(cli, fnum, offset, len, False, UNLOCK_LOCK); | 
|---|
| 1290 | } | 
|---|
| 1291 |  | 
|---|
| 1292 | /**************************************************************************** | 
|---|
| 1293 | POSIX Get any lock covering a file. | 
|---|
| 1294 | ****************************************************************************/ | 
|---|
| 1295 |  | 
|---|
| 1296 | bool cli_posix_getlock(struct cli_state *cli, int fnum, SMB_BIG_UINT *poffset, SMB_BIG_UINT *plen) | 
|---|
| 1297 | { | 
|---|
| 1298 | return True; | 
|---|
| 1299 | } | 
|---|
| 1300 |  | 
|---|
| 1301 | /**************************************************************************** | 
|---|
| 1302 | Do a SMBgetattrE call. | 
|---|
| 1303 | ****************************************************************************/ | 
|---|
| 1304 |  | 
|---|
| 1305 | bool cli_getattrE(struct cli_state *cli, int fd, | 
|---|
| 1306 | uint16 *attr, SMB_OFF_T *size, | 
|---|
| 1307 | time_t *change_time, | 
|---|
| 1308 | time_t *access_time, | 
|---|
| 1309 | time_t *write_time) | 
|---|
| 1310 | { | 
|---|
| 1311 | memset(cli->outbuf,'\0',smb_size); | 
|---|
| 1312 | memset(cli->inbuf,'\0',smb_size); | 
|---|
| 1313 |  | 
|---|
| 1314 | cli_set_message(cli->outbuf,1,0,True); | 
|---|
| 1315 |  | 
|---|
| 1316 | SCVAL(cli->outbuf,smb_com,SMBgetattrE); | 
|---|
| 1317 | SSVAL(cli->outbuf,smb_tid,cli->cnum); | 
|---|
| 1318 | cli_setup_packet(cli); | 
|---|
| 1319 |  | 
|---|
| 1320 | SSVAL(cli->outbuf,smb_vwv0,fd); | 
|---|
| 1321 |  | 
|---|
| 1322 | cli_send_smb(cli); | 
|---|
| 1323 | if (!cli_receive_smb(cli)) { | 
|---|
| 1324 | return False; | 
|---|
| 1325 | } | 
|---|
| 1326 |  | 
|---|
| 1327 | if (cli_is_error(cli)) { | 
|---|
| 1328 | return False; | 
|---|
| 1329 | } | 
|---|
| 1330 |  | 
|---|
| 1331 | if (size) { | 
|---|
| 1332 | *size = IVAL(cli->inbuf, smb_vwv6); | 
|---|
| 1333 | } | 
|---|
| 1334 |  | 
|---|
| 1335 | if (attr) { | 
|---|
| 1336 | *attr = SVAL(cli->inbuf,smb_vwv10); | 
|---|
| 1337 | } | 
|---|
| 1338 |  | 
|---|
| 1339 | if (change_time) { | 
|---|
| 1340 | *change_time = cli_make_unix_date2(cli, cli->inbuf+smb_vwv0); | 
|---|
| 1341 | } | 
|---|
| 1342 |  | 
|---|
| 1343 | if (access_time) { | 
|---|
| 1344 | *access_time = cli_make_unix_date2(cli, cli->inbuf+smb_vwv2); | 
|---|
| 1345 | } | 
|---|
| 1346 |  | 
|---|
| 1347 | if (write_time) { | 
|---|
| 1348 | *write_time = cli_make_unix_date2(cli, cli->inbuf+smb_vwv4); | 
|---|
| 1349 | } | 
|---|
| 1350 |  | 
|---|
| 1351 | return True; | 
|---|
| 1352 | } | 
|---|
| 1353 |  | 
|---|
| 1354 | /**************************************************************************** | 
|---|
| 1355 | Do a SMBgetatr call | 
|---|
| 1356 | ****************************************************************************/ | 
|---|
| 1357 |  | 
|---|
| 1358 | bool cli_getatr(struct cli_state *cli, const char *fname, | 
|---|
| 1359 | uint16 *attr, SMB_OFF_T *size, time_t *write_time) | 
|---|
| 1360 | { | 
|---|
| 1361 | char *p; | 
|---|
| 1362 |  | 
|---|
| 1363 | memset(cli->outbuf,'\0',smb_size); | 
|---|
| 1364 | memset(cli->inbuf,'\0',smb_size); | 
|---|
| 1365 |  | 
|---|
| 1366 | cli_set_message(cli->outbuf,0,0,True); | 
|---|
| 1367 |  | 
|---|
| 1368 | SCVAL(cli->outbuf,smb_com,SMBgetatr); | 
|---|
| 1369 | SSVAL(cli->outbuf,smb_tid,cli->cnum); | 
|---|
| 1370 | cli_setup_packet(cli); | 
|---|
| 1371 |  | 
|---|
| 1372 | p = smb_buf(cli->outbuf); | 
|---|
| 1373 | *p++ = 4; | 
|---|
| 1374 | p += clistr_push(cli, p, fname, | 
|---|
| 1375 | cli->bufsize - PTR_DIFF(p,cli->outbuf), STR_TERMINATE); | 
|---|
| 1376 |  | 
|---|
| 1377 | cli_setup_bcc(cli, p); | 
|---|
| 1378 |  | 
|---|
| 1379 | cli_send_smb(cli); | 
|---|
| 1380 | if (!cli_receive_smb(cli)) { | 
|---|
| 1381 | return False; | 
|---|
| 1382 | } | 
|---|
| 1383 |  | 
|---|
| 1384 | if (cli_is_error(cli)) { | 
|---|
| 1385 | return False; | 
|---|
| 1386 | } | 
|---|
| 1387 |  | 
|---|
| 1388 | if (size) { | 
|---|
| 1389 | *size = IVAL(cli->inbuf, smb_vwv3); | 
|---|
| 1390 | } | 
|---|
| 1391 |  | 
|---|
| 1392 | if (write_time) { | 
|---|
| 1393 | *write_time = cli_make_unix_date3(cli, cli->inbuf+smb_vwv1); | 
|---|
| 1394 | } | 
|---|
| 1395 |  | 
|---|
| 1396 | if (attr) { | 
|---|
| 1397 | *attr = SVAL(cli->inbuf,smb_vwv0); | 
|---|
| 1398 | } | 
|---|
| 1399 |  | 
|---|
| 1400 | return True; | 
|---|
| 1401 | } | 
|---|
| 1402 |  | 
|---|
| 1403 | /**************************************************************************** | 
|---|
| 1404 | Do a SMBsetattrE call. | 
|---|
| 1405 | ****************************************************************************/ | 
|---|
| 1406 |  | 
|---|
| 1407 | bool cli_setattrE(struct cli_state *cli, int fd, | 
|---|
| 1408 | time_t change_time, | 
|---|
| 1409 | time_t access_time, | 
|---|
| 1410 | time_t write_time) | 
|---|
| 1411 |  | 
|---|
| 1412 | { | 
|---|
| 1413 | char *p; | 
|---|
| 1414 |  | 
|---|
| 1415 | memset(cli->outbuf,'\0',smb_size); | 
|---|
| 1416 | memset(cli->inbuf,'\0',smb_size); | 
|---|
| 1417 |  | 
|---|
| 1418 | cli_set_message(cli->outbuf,7,0,True); | 
|---|
| 1419 |  | 
|---|
| 1420 | SCVAL(cli->outbuf,smb_com,SMBsetattrE); | 
|---|
| 1421 | SSVAL(cli->outbuf,smb_tid,cli->cnum); | 
|---|
| 1422 | cli_setup_packet(cli); | 
|---|
| 1423 |  | 
|---|
| 1424 | SSVAL(cli->outbuf,smb_vwv0, fd); | 
|---|
| 1425 | cli_put_dos_date2(cli, cli->outbuf,smb_vwv1, change_time); | 
|---|
| 1426 | cli_put_dos_date2(cli, cli->outbuf,smb_vwv3, access_time); | 
|---|
| 1427 | cli_put_dos_date2(cli, cli->outbuf,smb_vwv5, write_time); | 
|---|
| 1428 |  | 
|---|
| 1429 | p = smb_buf(cli->outbuf); | 
|---|
| 1430 | *p++ = 4; | 
|---|
| 1431 |  | 
|---|
| 1432 | cli_setup_bcc(cli, p); | 
|---|
| 1433 |  | 
|---|
| 1434 | cli_send_smb(cli); | 
|---|
| 1435 | if (!cli_receive_smb(cli)) { | 
|---|
| 1436 | return False; | 
|---|
| 1437 | } | 
|---|
| 1438 |  | 
|---|
| 1439 | if (cli_is_error(cli)) { | 
|---|
| 1440 | return False; | 
|---|
| 1441 | } | 
|---|
| 1442 |  | 
|---|
| 1443 | return True; | 
|---|
| 1444 | } | 
|---|
| 1445 |  | 
|---|
| 1446 | /**************************************************************************** | 
|---|
| 1447 | Do a SMBsetatr call. | 
|---|
| 1448 | ****************************************************************************/ | 
|---|
| 1449 |  | 
|---|
| 1450 | bool cli_setatr(struct cli_state *cli, const char *fname, uint16 attr, time_t t) | 
|---|
| 1451 | { | 
|---|
| 1452 | char *p; | 
|---|
| 1453 |  | 
|---|
| 1454 | memset(cli->outbuf,'\0',smb_size); | 
|---|
| 1455 | memset(cli->inbuf,'\0',smb_size); | 
|---|
| 1456 |  | 
|---|
| 1457 | cli_set_message(cli->outbuf,8,0,True); | 
|---|
| 1458 |  | 
|---|
| 1459 | SCVAL(cli->outbuf,smb_com,SMBsetatr); | 
|---|
| 1460 | SSVAL(cli->outbuf,smb_tid,cli->cnum); | 
|---|
| 1461 | cli_setup_packet(cli); | 
|---|
| 1462 |  | 
|---|
| 1463 | SSVAL(cli->outbuf,smb_vwv0, attr); | 
|---|
| 1464 | cli_put_dos_date3(cli, cli->outbuf,smb_vwv1, t); | 
|---|
| 1465 |  | 
|---|
| 1466 | p = smb_buf(cli->outbuf); | 
|---|
| 1467 | *p++ = 4; | 
|---|
| 1468 | p += clistr_push(cli, p, fname, | 
|---|
| 1469 | cli->bufsize - PTR_DIFF(p,cli->outbuf), STR_TERMINATE); | 
|---|
| 1470 | *p++ = 4; | 
|---|
| 1471 |  | 
|---|
| 1472 | cli_setup_bcc(cli, p); | 
|---|
| 1473 |  | 
|---|
| 1474 | cli_send_smb(cli); | 
|---|
| 1475 | if (!cli_receive_smb(cli)) { | 
|---|
| 1476 | return False; | 
|---|
| 1477 | } | 
|---|
| 1478 |  | 
|---|
| 1479 | if (cli_is_error(cli)) { | 
|---|
| 1480 | return False; | 
|---|
| 1481 | } | 
|---|
| 1482 |  | 
|---|
| 1483 | return True; | 
|---|
| 1484 | } | 
|---|
| 1485 |  | 
|---|
| 1486 | /**************************************************************************** | 
|---|
| 1487 | Check for existance of a dir. | 
|---|
| 1488 | ****************************************************************************/ | 
|---|
| 1489 |  | 
|---|
| 1490 | bool cli_chkpath(struct cli_state *cli, const char *path) | 
|---|
| 1491 | { | 
|---|
| 1492 | char *path2 = NULL; | 
|---|
| 1493 | char *p; | 
|---|
| 1494 | TALLOC_CTX *frame = talloc_stackframe(); | 
|---|
| 1495 |  | 
|---|
| 1496 | path2 = talloc_strdup(frame, path); | 
|---|
| 1497 | if (!path2) { | 
|---|
| 1498 | TALLOC_FREE(frame); | 
|---|
| 1499 | return false; | 
|---|
| 1500 | } | 
|---|
| 1501 | trim_char(path2,'\0','\\'); | 
|---|
| 1502 | if (!*path2) { | 
|---|
| 1503 | path2 = talloc_strdup(frame, "\\"); | 
|---|
| 1504 | if (!path2) { | 
|---|
| 1505 | TALLOC_FREE(frame); | 
|---|
| 1506 | return false; | 
|---|
| 1507 | } | 
|---|
| 1508 | } | 
|---|
| 1509 |  | 
|---|
| 1510 | memset(cli->outbuf,'\0',smb_size); | 
|---|
| 1511 | cli_set_message(cli->outbuf,0,0,True); | 
|---|
| 1512 | SCVAL(cli->outbuf,smb_com,SMBcheckpath); | 
|---|
| 1513 | SSVAL(cli->outbuf,smb_tid,cli->cnum); | 
|---|
| 1514 | cli_setup_packet(cli); | 
|---|
| 1515 | p = smb_buf(cli->outbuf); | 
|---|
| 1516 | *p++ = 4; | 
|---|
| 1517 | p += clistr_push(cli, p, path2, | 
|---|
| 1518 | cli->bufsize - PTR_DIFF(p,cli->outbuf), STR_TERMINATE); | 
|---|
| 1519 |  | 
|---|
| 1520 | cli_setup_bcc(cli, p); | 
|---|
| 1521 |  | 
|---|
| 1522 | cli_send_smb(cli); | 
|---|
| 1523 | if (!cli_receive_smb(cli)) { | 
|---|
| 1524 | TALLOC_FREE(frame); | 
|---|
| 1525 | return False; | 
|---|
| 1526 | } | 
|---|
| 1527 |  | 
|---|
| 1528 | TALLOC_FREE(frame); | 
|---|
| 1529 |  | 
|---|
| 1530 | if (cli_is_error(cli)) return False; | 
|---|
| 1531 |  | 
|---|
| 1532 | return True; | 
|---|
| 1533 | } | 
|---|
| 1534 |  | 
|---|
| 1535 | /**************************************************************************** | 
|---|
| 1536 | Query disk space. | 
|---|
| 1537 | ****************************************************************************/ | 
|---|
| 1538 |  | 
|---|
| 1539 | bool cli_dskattr(struct cli_state *cli, int *bsize, int *total, int *avail) | 
|---|
| 1540 | { | 
|---|
| 1541 | memset(cli->outbuf,'\0',smb_size); | 
|---|
| 1542 | cli_set_message(cli->outbuf,0,0,True); | 
|---|
| 1543 | SCVAL(cli->outbuf,smb_com,SMBdskattr); | 
|---|
| 1544 | SSVAL(cli->outbuf,smb_tid,cli->cnum); | 
|---|
| 1545 | cli_setup_packet(cli); | 
|---|
| 1546 |  | 
|---|
| 1547 | cli_send_smb(cli); | 
|---|
| 1548 | if (!cli_receive_smb(cli)) { | 
|---|
| 1549 | return False; | 
|---|
| 1550 | } | 
|---|
| 1551 |  | 
|---|
| 1552 | *bsize = SVAL(cli->inbuf,smb_vwv1)*SVAL(cli->inbuf,smb_vwv2); | 
|---|
| 1553 | *total = SVAL(cli->inbuf,smb_vwv0); | 
|---|
| 1554 | *avail = SVAL(cli->inbuf,smb_vwv3); | 
|---|
| 1555 |  | 
|---|
| 1556 | return True; | 
|---|
| 1557 | } | 
|---|
| 1558 |  | 
|---|
| 1559 | /**************************************************************************** | 
|---|
| 1560 | Create and open a temporary file. | 
|---|
| 1561 | ****************************************************************************/ | 
|---|
| 1562 |  | 
|---|
| 1563 | int cli_ctemp(struct cli_state *cli, const char *path, char **tmp_path) | 
|---|
| 1564 | { | 
|---|
| 1565 | int len; | 
|---|
| 1566 | char *p; | 
|---|
| 1567 |  | 
|---|
| 1568 | memset(cli->outbuf,'\0',smb_size); | 
|---|
| 1569 | memset(cli->inbuf,'\0',smb_size); | 
|---|
| 1570 |  | 
|---|
| 1571 | cli_set_message(cli->outbuf,3,0,True); | 
|---|
| 1572 |  | 
|---|
| 1573 | SCVAL(cli->outbuf,smb_com,SMBctemp); | 
|---|
| 1574 | SSVAL(cli->outbuf,smb_tid,cli->cnum); | 
|---|
| 1575 | cli_setup_packet(cli); | 
|---|
| 1576 |  | 
|---|
| 1577 | SSVAL(cli->outbuf,smb_vwv0,0); | 
|---|
| 1578 | SIVALS(cli->outbuf,smb_vwv1,-1); | 
|---|
| 1579 |  | 
|---|
| 1580 | p = smb_buf(cli->outbuf); | 
|---|
| 1581 | *p++ = 4; | 
|---|
| 1582 | p += clistr_push(cli, p, path, | 
|---|
| 1583 | cli->bufsize - PTR_DIFF(p,cli->outbuf), STR_TERMINATE); | 
|---|
| 1584 |  | 
|---|
| 1585 | cli_setup_bcc(cli, p); | 
|---|
| 1586 |  | 
|---|
| 1587 | cli_send_smb(cli); | 
|---|
| 1588 | if (!cli_receive_smb(cli)) { | 
|---|
| 1589 | return -1; | 
|---|
| 1590 | } | 
|---|
| 1591 |  | 
|---|
| 1592 | if (cli_is_error(cli)) { | 
|---|
| 1593 | return -1; | 
|---|
| 1594 | } | 
|---|
| 1595 |  | 
|---|
| 1596 | /* despite the spec, the result has a -1, followed by | 
|---|
| 1597 | length, followed by name */ | 
|---|
| 1598 | p = smb_buf(cli->inbuf); | 
|---|
| 1599 | p += 4; | 
|---|
| 1600 | len = smb_buflen(cli->inbuf) - 4; | 
|---|
| 1601 | if (len <= 0 || len > PATH_MAX) return -1; | 
|---|
| 1602 |  | 
|---|
| 1603 | if (tmp_path) { | 
|---|
| 1604 | char *path2 = SMB_MALLOC_ARRAY(char, len+1); | 
|---|
| 1605 | if (!path2) { | 
|---|
| 1606 | return -1; | 
|---|
| 1607 | } | 
|---|
| 1608 | clistr_pull(cli, path2, p, | 
|---|
| 1609 | len+1, len, STR_ASCII); | 
|---|
| 1610 | *tmp_path = path2; | 
|---|
| 1611 | } | 
|---|
| 1612 |  | 
|---|
| 1613 | return SVAL(cli->inbuf,smb_vwv0); | 
|---|
| 1614 | } | 
|---|
| 1615 |  | 
|---|
| 1616 | /* | 
|---|
| 1617 | send a raw ioctl - used by the torture code | 
|---|
| 1618 | */ | 
|---|
| 1619 | NTSTATUS cli_raw_ioctl(struct cli_state *cli, int fnum, uint32 code, DATA_BLOB *blob) | 
|---|
| 1620 | { | 
|---|
| 1621 | memset(cli->outbuf,'\0',smb_size); | 
|---|
| 1622 | memset(cli->inbuf,'\0',smb_size); | 
|---|
| 1623 |  | 
|---|
| 1624 | cli_set_message(cli->outbuf, 3, 0, True); | 
|---|
| 1625 | SCVAL(cli->outbuf,smb_com,SMBioctl); | 
|---|
| 1626 | cli_setup_packet(cli); | 
|---|
| 1627 |  | 
|---|
| 1628 | SSVAL(cli->outbuf, smb_vwv0, fnum); | 
|---|
| 1629 | SSVAL(cli->outbuf, smb_vwv1, code>>16); | 
|---|
| 1630 | SSVAL(cli->outbuf, smb_vwv2, (code&0xFFFF)); | 
|---|
| 1631 |  | 
|---|
| 1632 | cli_send_smb(cli); | 
|---|
| 1633 | if (!cli_receive_smb(cli)) { | 
|---|
| 1634 | return NT_STATUS_UNEXPECTED_NETWORK_ERROR; | 
|---|
| 1635 | } | 
|---|
| 1636 |  | 
|---|
| 1637 | if (cli_is_error(cli)) { | 
|---|
| 1638 | return cli_nt_error(cli); | 
|---|
| 1639 | } | 
|---|
| 1640 |  | 
|---|
| 1641 | *blob = data_blob_null; | 
|---|
| 1642 |  | 
|---|
| 1643 | return NT_STATUS_OK; | 
|---|
| 1644 | } | 
|---|
| 1645 |  | 
|---|
| 1646 | /********************************************************* | 
|---|
| 1647 | Set an extended attribute utility fn. | 
|---|
| 1648 | *********************************************************/ | 
|---|
| 1649 |  | 
|---|
| 1650 | static bool cli_set_ea(struct cli_state *cli, uint16 setup, char *param, unsigned int param_len, | 
|---|
| 1651 | const char *ea_name, const char *ea_val, size_t ea_len) | 
|---|
| 1652 | { | 
|---|
| 1653 | unsigned int data_len = 0; | 
|---|
| 1654 | char *data = NULL; | 
|---|
| 1655 | char *rparam=NULL, *rdata=NULL; | 
|---|
| 1656 | char *p; | 
|---|
| 1657 | size_t ea_namelen = strlen(ea_name); | 
|---|
| 1658 |  | 
|---|
| 1659 | if (ea_namelen == 0 && ea_len == 0) { | 
|---|
| 1660 | data_len = 4; | 
|---|
| 1661 | data = (char *)SMB_MALLOC(data_len); | 
|---|
| 1662 | if (!data) { | 
|---|
| 1663 | return False; | 
|---|
| 1664 | } | 
|---|
| 1665 | p = data; | 
|---|
| 1666 | SIVAL(p,0,data_len); | 
|---|
| 1667 | } else { | 
|---|
| 1668 | data_len = 4 + 4 + ea_namelen + 1 + ea_len; | 
|---|
| 1669 | data = (char *)SMB_MALLOC(data_len); | 
|---|
| 1670 | if (!data) { | 
|---|
| 1671 | return False; | 
|---|
| 1672 | } | 
|---|
| 1673 | p = data; | 
|---|
| 1674 | SIVAL(p,0,data_len); | 
|---|
| 1675 | p += 4; | 
|---|
| 1676 | SCVAL(p, 0, 0); /* EA flags. */ | 
|---|
| 1677 | SCVAL(p, 1, ea_namelen); | 
|---|
| 1678 | SSVAL(p, 2, ea_len); | 
|---|
| 1679 | memcpy(p+4, ea_name, ea_namelen+1); /* Copy in the name. */ | 
|---|
| 1680 | memcpy(p+4+ea_namelen+1, ea_val, ea_len); | 
|---|
| 1681 | } | 
|---|
| 1682 |  | 
|---|
| 1683 | if (!cli_send_trans(cli, SMBtrans2, | 
|---|
| 1684 | NULL,                        /* name */ | 
|---|
| 1685 | -1, 0,                          /* fid, flags */ | 
|---|
| 1686 | &setup, 1, 0,                   /* setup, length, max */ | 
|---|
| 1687 | param, param_len, 2,            /* param, length, max */ | 
|---|
| 1688 | data,  data_len, cli->max_xmit /* data, length, max */ | 
|---|
| 1689 | )) { | 
|---|
| 1690 | SAFE_FREE(data); | 
|---|
| 1691 | return False; | 
|---|
| 1692 | } | 
|---|
| 1693 |  | 
|---|
| 1694 | if (!cli_receive_trans(cli, SMBtrans2, | 
|---|
| 1695 | &rparam, ¶m_len, | 
|---|
| 1696 | &rdata, &data_len)) { | 
|---|
| 1697 | SAFE_FREE(data); | 
|---|
| 1698 | return false; | 
|---|
| 1699 | } | 
|---|
| 1700 |  | 
|---|
| 1701 | SAFE_FREE(data); | 
|---|
| 1702 | SAFE_FREE(rdata); | 
|---|
| 1703 | SAFE_FREE(rparam); | 
|---|
| 1704 |  | 
|---|
| 1705 | return True; | 
|---|
| 1706 | } | 
|---|
| 1707 |  | 
|---|
| 1708 | /********************************************************* | 
|---|
| 1709 | Set an extended attribute on a pathname. | 
|---|
| 1710 | *********************************************************/ | 
|---|
| 1711 |  | 
|---|
| 1712 | bool cli_set_ea_path(struct cli_state *cli, const char *path, const char *ea_name, const char *ea_val, size_t ea_len) | 
|---|
| 1713 | { | 
|---|
| 1714 | uint16 setup = TRANSACT2_SETPATHINFO; | 
|---|
| 1715 | unsigned int param_len = 0; | 
|---|
| 1716 | char *param; | 
|---|
| 1717 | size_t srclen = 2*(strlen(path)+1); | 
|---|
| 1718 | char *p; | 
|---|
| 1719 | bool ret; | 
|---|
| 1720 |  | 
|---|
| 1721 | param = SMB_MALLOC_ARRAY(char, 6+srclen+2); | 
|---|
| 1722 | if (!param) { | 
|---|
| 1723 | return false; | 
|---|
| 1724 | } | 
|---|
| 1725 | memset(param, '\0', 6); | 
|---|
| 1726 | SSVAL(param,0,SMB_INFO_SET_EA); | 
|---|
| 1727 | p = ¶m[6]; | 
|---|
| 1728 |  | 
|---|
| 1729 | p += clistr_push(cli, p, path, srclen, STR_TERMINATE); | 
|---|
| 1730 | param_len = PTR_DIFF(p, param); | 
|---|
| 1731 |  | 
|---|
| 1732 | ret = cli_set_ea(cli, setup, param, param_len, ea_name, ea_val, ea_len); | 
|---|
| 1733 | SAFE_FREE(param); | 
|---|
| 1734 | return ret; | 
|---|
| 1735 | } | 
|---|
| 1736 |  | 
|---|
| 1737 | /********************************************************* | 
|---|
| 1738 | Set an extended attribute on an fnum. | 
|---|
| 1739 | *********************************************************/ | 
|---|
| 1740 |  | 
|---|
| 1741 | bool cli_set_ea_fnum(struct cli_state *cli, int fnum, const char *ea_name, const char *ea_val, size_t ea_len) | 
|---|
| 1742 | { | 
|---|
| 1743 | char param[6]; | 
|---|
| 1744 | uint16 setup = TRANSACT2_SETFILEINFO; | 
|---|
| 1745 |  | 
|---|
| 1746 | memset(param, 0, 6); | 
|---|
| 1747 | SSVAL(param,0,fnum); | 
|---|
| 1748 | SSVAL(param,2,SMB_INFO_SET_EA); | 
|---|
| 1749 |  | 
|---|
| 1750 | return cli_set_ea(cli, setup, param, 6, ea_name, ea_val, ea_len); | 
|---|
| 1751 | } | 
|---|
| 1752 |  | 
|---|
| 1753 | /********************************************************* | 
|---|
| 1754 | Get an extended attribute list tility fn. | 
|---|
| 1755 | *********************************************************/ | 
|---|
| 1756 |  | 
|---|
| 1757 | static bool cli_get_ea_list(struct cli_state *cli, | 
|---|
| 1758 | uint16 setup, char *param, unsigned int param_len, | 
|---|
| 1759 | TALLOC_CTX *ctx, | 
|---|
| 1760 | size_t *pnum_eas, | 
|---|
| 1761 | struct ea_struct **pea_list) | 
|---|
| 1762 | { | 
|---|
| 1763 | unsigned int data_len = 0; | 
|---|
| 1764 | unsigned int rparam_len, rdata_len; | 
|---|
| 1765 | char *rparam=NULL, *rdata=NULL; | 
|---|
| 1766 | char *p; | 
|---|
| 1767 | size_t ea_size; | 
|---|
| 1768 | size_t num_eas; | 
|---|
| 1769 | bool ret = False; | 
|---|
| 1770 | struct ea_struct *ea_list; | 
|---|
| 1771 |  | 
|---|
| 1772 | *pnum_eas = 0; | 
|---|
| 1773 | if (pea_list) { | 
|---|
| 1774 | *pea_list = NULL; | 
|---|
| 1775 | } | 
|---|
| 1776 |  | 
|---|
| 1777 | if (!cli_send_trans(cli, SMBtrans2, | 
|---|
| 1778 | NULL,           /* Name */ | 
|---|
| 1779 | -1, 0,          /* fid, flags */ | 
|---|
| 1780 | &setup, 1, 0,   /* setup, length, max */ | 
|---|
| 1781 | param, param_len, 10, /* param, length, max */ | 
|---|
| 1782 | #ifdef __OS2__ | 
|---|
| 1783 | NULL, data_len, CLI_BUFFER_SIZE /* data, length, max */ | 
|---|
| 1784 | #else | 
|---|
| 1785 | NULL, data_len, cli->max_xmit /* data, length, max */ | 
|---|
| 1786 | #endif | 
|---|
| 1787 | )) { | 
|---|
| 1788 | return False; | 
|---|
| 1789 | } | 
|---|
| 1790 |  | 
|---|
| 1791 | if (!cli_receive_trans(cli, SMBtrans2, | 
|---|
| 1792 | &rparam, &rparam_len, | 
|---|
| 1793 | &rdata, &rdata_len)) { | 
|---|
| 1794 | return False; | 
|---|
| 1795 | } | 
|---|
| 1796 |  | 
|---|
| 1797 | if (!rdata || rdata_len < 4) { | 
|---|
| 1798 | goto out; | 
|---|
| 1799 | } | 
|---|
| 1800 |  | 
|---|
| 1801 | ea_size = (size_t)IVAL(rdata,0); | 
|---|
| 1802 | if (ea_size > rdata_len) { | 
|---|
| 1803 | goto out; | 
|---|
| 1804 | } | 
|---|
| 1805 |  | 
|---|
| 1806 | if (ea_size == 0) { | 
|---|
| 1807 | /* No EA's present. */ | 
|---|
| 1808 | ret = True; | 
|---|
| 1809 | goto out; | 
|---|
| 1810 | } | 
|---|
| 1811 |  | 
|---|
| 1812 | p = rdata + 4; | 
|---|
| 1813 | ea_size -= 4; | 
|---|
| 1814 |  | 
|---|
| 1815 | /* Validate the EA list and count it. */ | 
|---|
| 1816 | for (num_eas = 0; ea_size >= 4; num_eas++) { | 
|---|
| 1817 | unsigned int ea_namelen = CVAL(p,1); | 
|---|
| 1818 | unsigned int ea_valuelen = SVAL(p,2); | 
|---|
| 1819 | if (ea_namelen == 0) { | 
|---|
| 1820 | goto out; | 
|---|
| 1821 | } | 
|---|
| 1822 | if (4 + ea_namelen + 1 + ea_valuelen > ea_size) { | 
|---|
| 1823 | goto out; | 
|---|
| 1824 | } | 
|---|
| 1825 | ea_size -= 4 + ea_namelen + 1 + ea_valuelen; | 
|---|
| 1826 | p += 4 + ea_namelen + 1 + ea_valuelen; | 
|---|
| 1827 | } | 
|---|
| 1828 |  | 
|---|
| 1829 | if (num_eas == 0) { | 
|---|
| 1830 | ret = True; | 
|---|
| 1831 | goto out; | 
|---|
| 1832 | } | 
|---|
| 1833 |  | 
|---|
| 1834 | *pnum_eas = num_eas; | 
|---|
| 1835 | if (!pea_list) { | 
|---|
| 1836 | /* Caller only wants number of EA's. */ | 
|---|
| 1837 | ret = True; | 
|---|
| 1838 | goto out; | 
|---|
| 1839 | } | 
|---|
| 1840 |  | 
|---|
| 1841 | ea_list = TALLOC_ARRAY(ctx, struct ea_struct, num_eas); | 
|---|
| 1842 | if (!ea_list) { | 
|---|
| 1843 | goto out; | 
|---|
| 1844 | } | 
|---|
| 1845 |  | 
|---|
| 1846 | ea_size = (size_t)IVAL(rdata,0); | 
|---|
| 1847 | p = rdata + 4; | 
|---|
| 1848 |  | 
|---|
| 1849 | for (num_eas = 0; num_eas < *pnum_eas; num_eas++ ) { | 
|---|
| 1850 | struct ea_struct *ea = &ea_list[num_eas]; | 
|---|
| 1851 | fstring unix_ea_name; | 
|---|
| 1852 | unsigned int ea_namelen = CVAL(p,1); | 
|---|
| 1853 | unsigned int ea_valuelen = SVAL(p,2); | 
|---|
| 1854 |  | 
|---|
| 1855 | ea->flags = CVAL(p,0); | 
|---|
| 1856 | unix_ea_name[0] = '\0'; | 
|---|
| 1857 | pull_ascii_fstring(unix_ea_name, p + 4); | 
|---|
| 1858 | ea->name = talloc_strdup(ctx, unix_ea_name); | 
|---|
| 1859 | /* Ensure the value is null terminated (in case it's a string). */ | 
|---|
| 1860 | ea->value = data_blob_talloc(ctx, NULL, ea_valuelen + 1); | 
|---|
| 1861 | if (!ea->value.data) { | 
|---|
| 1862 | goto out; | 
|---|
| 1863 | } | 
|---|
| 1864 | if (ea_valuelen) { | 
|---|
| 1865 | memcpy(ea->value.data, p+4+ea_namelen+1, ea_valuelen); | 
|---|
| 1866 | } | 
|---|
| 1867 | ea->value.data[ea_valuelen] = 0; | 
|---|
| 1868 | ea->value.length--; | 
|---|
| 1869 | p += 4 + ea_namelen + 1 + ea_valuelen; | 
|---|
| 1870 | } | 
|---|
| 1871 |  | 
|---|
| 1872 | *pea_list = ea_list; | 
|---|
| 1873 | ret = True; | 
|---|
| 1874 |  | 
|---|
| 1875 | out : | 
|---|
| 1876 |  | 
|---|
| 1877 | SAFE_FREE(rdata); | 
|---|
| 1878 | SAFE_FREE(rparam); | 
|---|
| 1879 | return ret; | 
|---|
| 1880 | } | 
|---|
| 1881 |  | 
|---|
| 1882 | /********************************************************* | 
|---|
| 1883 | Get an extended attribute list from a pathname. | 
|---|
| 1884 | *********************************************************/ | 
|---|
| 1885 |  | 
|---|
| 1886 | bool cli_get_ea_list_path(struct cli_state *cli, const char *path, | 
|---|
| 1887 | TALLOC_CTX *ctx, | 
|---|
| 1888 | size_t *pnum_eas, | 
|---|
| 1889 | struct ea_struct **pea_list) | 
|---|
| 1890 | { | 
|---|
| 1891 | uint16 setup = TRANSACT2_QPATHINFO; | 
|---|
| 1892 | unsigned int param_len = 0; | 
|---|
| 1893 | char *param; | 
|---|
| 1894 | char *p; | 
|---|
| 1895 | size_t srclen = 2*(strlen(path)+1); | 
|---|
| 1896 | bool ret; | 
|---|
| 1897 |  | 
|---|
| 1898 | param = SMB_MALLOC_ARRAY(char, 6+srclen+2); | 
|---|
| 1899 | if (!param) { | 
|---|
| 1900 | return false; | 
|---|
| 1901 | } | 
|---|
| 1902 | p = param; | 
|---|
| 1903 | memset(p, 0, 6); | 
|---|
| 1904 | SSVAL(p, 0, SMB_INFO_QUERY_ALL_EAS); | 
|---|
| 1905 | p += 6; | 
|---|
| 1906 | p += clistr_push(cli, p, path, srclen, STR_TERMINATE); | 
|---|
| 1907 | param_len = PTR_DIFF(p, param); | 
|---|
| 1908 |  | 
|---|
| 1909 | ret = cli_get_ea_list(cli, setup, param, param_len, ctx, pnum_eas, pea_list); | 
|---|
| 1910 | SAFE_FREE(param); | 
|---|
| 1911 | return ret; | 
|---|
| 1912 | } | 
|---|
| 1913 |  | 
|---|
| 1914 | /********************************************************* | 
|---|
| 1915 | Get an extended attribute list from an fnum. | 
|---|
| 1916 | *********************************************************/ | 
|---|
| 1917 |  | 
|---|
| 1918 | bool cli_get_ea_list_fnum(struct cli_state *cli, int fnum, | 
|---|
| 1919 | TALLOC_CTX *ctx, | 
|---|
| 1920 | size_t *pnum_eas, | 
|---|
| 1921 | struct ea_struct **pea_list) | 
|---|
| 1922 | { | 
|---|
| 1923 | uint16 setup = TRANSACT2_QFILEINFO; | 
|---|
| 1924 | char param[6]; | 
|---|
| 1925 |  | 
|---|
| 1926 | memset(param, 0, 6); | 
|---|
| 1927 | SSVAL(param,0,fnum); | 
|---|
| 1928 | SSVAL(param,2,SMB_INFO_SET_EA); | 
|---|
| 1929 |  | 
|---|
| 1930 | return cli_get_ea_list(cli, setup, param, 6, ctx, pnum_eas, pea_list); | 
|---|
| 1931 | } | 
|---|
| 1932 |  | 
|---|
| 1933 | /**************************************************************************** | 
|---|
| 1934 | Convert open "flags" arg to uint32 on wire. | 
|---|
| 1935 | ****************************************************************************/ | 
|---|
| 1936 |  | 
|---|
| 1937 | static uint32 open_flags_to_wire(int flags) | 
|---|
| 1938 | { | 
|---|
| 1939 | int open_mode = flags & O_ACCMODE; | 
|---|
| 1940 | uint32 ret = 0; | 
|---|
| 1941 |  | 
|---|
| 1942 | switch (open_mode) { | 
|---|
| 1943 | case O_WRONLY: | 
|---|
| 1944 | ret |= SMB_O_WRONLY; | 
|---|
| 1945 | break; | 
|---|
| 1946 | case O_RDWR: | 
|---|
| 1947 | ret |= SMB_O_RDWR; | 
|---|
| 1948 | break; | 
|---|
| 1949 | default: | 
|---|
| 1950 | case O_RDONLY: | 
|---|
| 1951 | ret |= SMB_O_RDONLY; | 
|---|
| 1952 | break; | 
|---|
| 1953 | } | 
|---|
| 1954 |  | 
|---|
| 1955 | if (flags & O_CREAT) { | 
|---|
| 1956 | ret |= SMB_O_CREAT; | 
|---|
| 1957 | } | 
|---|
| 1958 | if (flags & O_EXCL) { | 
|---|
| 1959 | ret |= SMB_O_EXCL; | 
|---|
| 1960 | } | 
|---|
| 1961 | if (flags & O_TRUNC) { | 
|---|
| 1962 | ret |= SMB_O_TRUNC; | 
|---|
| 1963 | } | 
|---|
| 1964 | #if defined(O_SYNC) | 
|---|
| 1965 | if (flags & O_SYNC) { | 
|---|
| 1966 | ret |= SMB_O_SYNC; | 
|---|
| 1967 | } | 
|---|
| 1968 | #endif /* O_SYNC */ | 
|---|
| 1969 | if (flags & O_APPEND) { | 
|---|
| 1970 | ret |= SMB_O_APPEND; | 
|---|
| 1971 | } | 
|---|
| 1972 | #if defined(O_DIRECT) | 
|---|
| 1973 | if (flags & O_DIRECT) { | 
|---|
| 1974 | ret |= SMB_O_DIRECT; | 
|---|
| 1975 | } | 
|---|
| 1976 | #endif | 
|---|
| 1977 | #if defined(O_DIRECTORY) | 
|---|
| 1978 | if (flags & O_DIRECTORY) { | 
|---|
| 1979 | ret &= ~(SMB_O_RDONLY|SMB_O_RDWR|SMB_O_WRONLY); | 
|---|
| 1980 | ret |= SMB_O_DIRECTORY; | 
|---|
| 1981 | } | 
|---|
| 1982 | #endif | 
|---|
| 1983 | return ret; | 
|---|
| 1984 | } | 
|---|
| 1985 |  | 
|---|
| 1986 | /**************************************************************************** | 
|---|
| 1987 | Open a file - POSIX semantics. Returns fnum. Doesn't request oplock. | 
|---|
| 1988 | ****************************************************************************/ | 
|---|
| 1989 |  | 
|---|
| 1990 | static int cli_posix_open_internal(struct cli_state *cli, const char *fname, int flags, mode_t mode, bool is_dir) | 
|---|
| 1991 | { | 
|---|
| 1992 | unsigned int data_len = 0; | 
|---|
| 1993 | unsigned int param_len = 0; | 
|---|
| 1994 | uint16 setup = TRANSACT2_SETPATHINFO; | 
|---|
| 1995 | char *param; | 
|---|
| 1996 | char data[18]; | 
|---|
| 1997 | char *rparam=NULL, *rdata=NULL; | 
|---|
| 1998 | char *p; | 
|---|
| 1999 | int fnum = -1; | 
|---|
| 2000 | uint32 wire_flags = open_flags_to_wire(flags); | 
|---|
| 2001 | size_t srclen = 2*(strlen(fname)+1); | 
|---|
| 2002 |  | 
|---|
| 2003 | param = SMB_MALLOC_ARRAY(char, 6+srclen+2); | 
|---|
| 2004 | if (!param) { | 
|---|
| 2005 | return false; | 
|---|
| 2006 | } | 
|---|
| 2007 | memset(param, '\0', 6); | 
|---|
| 2008 | SSVAL(param,0, SMB_POSIX_PATH_OPEN); | 
|---|
| 2009 | p = ¶m[6]; | 
|---|
| 2010 |  | 
|---|
| 2011 | p += clistr_push(cli, p, fname, srclen, STR_TERMINATE); | 
|---|
| 2012 | param_len = PTR_DIFF(p, param); | 
|---|
| 2013 |  | 
|---|
| 2014 | if (is_dir) { | 
|---|
| 2015 | wire_flags &= ~(SMB_O_RDONLY|SMB_O_RDWR|SMB_O_WRONLY); | 
|---|
| 2016 | wire_flags |= SMB_O_DIRECTORY; | 
|---|
| 2017 | } | 
|---|
| 2018 |  | 
|---|
| 2019 | p = data; | 
|---|
| 2020 | SIVAL(p,0,0); /* No oplock. */ | 
|---|
| 2021 | SIVAL(p,4,wire_flags); | 
|---|
| 2022 | SIVAL(p,8,unix_perms_to_wire(mode)); | 
|---|
| 2023 | SIVAL(p,12,0); /* Top bits of perms currently undefined. */ | 
|---|
| 2024 | SSVAL(p,16,SMB_NO_INFO_LEVEL_RETURNED); /* No info level returned. */ | 
|---|
| 2025 |  | 
|---|
| 2026 | data_len = 18; | 
|---|
| 2027 |  | 
|---|
| 2028 | if (!cli_send_trans(cli, SMBtrans2, | 
|---|
| 2029 | NULL,                        /* name */ | 
|---|
| 2030 | -1, 0,                          /* fid, flags */ | 
|---|
| 2031 | &setup, 1, 0,                   /* setup, length, max */ | 
|---|
| 2032 | param, param_len, 2,            /* param, length, max */ | 
|---|
| 2033 | (char *)&data,  data_len, cli->max_xmit /* data, length, max */ | 
|---|
| 2034 | )) { | 
|---|
| 2035 | SAFE_FREE(param); | 
|---|
| 2036 | return -1; | 
|---|
| 2037 | } | 
|---|
| 2038 |  | 
|---|
| 2039 | SAFE_FREE(param); | 
|---|
| 2040 |  | 
|---|
| 2041 | if (!cli_receive_trans(cli, SMBtrans2, | 
|---|
| 2042 | &rparam, ¶m_len, | 
|---|
| 2043 | &rdata, &data_len)) { | 
|---|
| 2044 | return -1; | 
|---|
| 2045 | } | 
|---|
| 2046 |  | 
|---|
| 2047 | fnum = SVAL(rdata,2); | 
|---|
| 2048 |  | 
|---|
| 2049 | SAFE_FREE(rdata); | 
|---|
| 2050 | SAFE_FREE(rparam); | 
|---|
| 2051 |  | 
|---|
| 2052 | return fnum; | 
|---|
| 2053 | } | 
|---|
| 2054 |  | 
|---|
| 2055 | /**************************************************************************** | 
|---|
| 2056 | open - POSIX semantics. | 
|---|
| 2057 | ****************************************************************************/ | 
|---|
| 2058 |  | 
|---|
| 2059 | int cli_posix_open(struct cli_state *cli, const char *fname, int flags, mode_t mode) | 
|---|
| 2060 | { | 
|---|
| 2061 | return cli_posix_open_internal(cli, fname, flags, mode, False); | 
|---|
| 2062 | } | 
|---|
| 2063 |  | 
|---|
| 2064 | /**************************************************************************** | 
|---|
| 2065 | mkdir - POSIX semantics. | 
|---|
| 2066 | ****************************************************************************/ | 
|---|
| 2067 |  | 
|---|
| 2068 | int cli_posix_mkdir(struct cli_state *cli, const char *fname, mode_t mode) | 
|---|
| 2069 | { | 
|---|
| 2070 | return (cli_posix_open_internal(cli, fname, O_CREAT, mode, True) == -1) ? -1 : 0; | 
|---|
| 2071 | } | 
|---|
| 2072 |  | 
|---|
| 2073 | /**************************************************************************** | 
|---|
| 2074 | unlink or rmdir - POSIX semantics. | 
|---|
| 2075 | ****************************************************************************/ | 
|---|
| 2076 |  | 
|---|
| 2077 | static bool cli_posix_unlink_internal(struct cli_state *cli, const char *fname, bool is_dir) | 
|---|
| 2078 | { | 
|---|
| 2079 | unsigned int data_len = 0; | 
|---|
| 2080 | unsigned int param_len = 0; | 
|---|
| 2081 | uint16 setup = TRANSACT2_SETPATHINFO; | 
|---|
| 2082 | char *param; | 
|---|
| 2083 | char data[2]; | 
|---|
| 2084 | char *rparam=NULL, *rdata=NULL; | 
|---|
| 2085 | char *p; | 
|---|
| 2086 | size_t srclen = 2*(strlen(fname)+1); | 
|---|
| 2087 |  | 
|---|
| 2088 | param = SMB_MALLOC_ARRAY(char, 6+srclen+2); | 
|---|
| 2089 | if (!param) { | 
|---|
| 2090 | return false; | 
|---|
| 2091 | } | 
|---|
| 2092 | memset(param, '\0', 6); | 
|---|
| 2093 | SSVAL(param,0, SMB_POSIX_PATH_UNLINK); | 
|---|
| 2094 | p = ¶m[6]; | 
|---|
| 2095 |  | 
|---|
| 2096 | p += clistr_push(cli, p, fname, srclen, STR_TERMINATE); | 
|---|
| 2097 | param_len = PTR_DIFF(p, param); | 
|---|
| 2098 |  | 
|---|
| 2099 | SSVAL(data, 0, is_dir ? SMB_POSIX_UNLINK_DIRECTORY_TARGET : | 
|---|
| 2100 | SMB_POSIX_UNLINK_FILE_TARGET); | 
|---|
| 2101 | data_len = 2; | 
|---|
| 2102 |  | 
|---|
| 2103 | if (!cli_send_trans(cli, SMBtrans2, | 
|---|
| 2104 | NULL,                        /* name */ | 
|---|
| 2105 | -1, 0,                          /* fid, flags */ | 
|---|
| 2106 | &setup, 1, 0,                   /* setup, length, max */ | 
|---|
| 2107 | param, param_len, 2,            /* param, length, max */ | 
|---|
| 2108 | (char *)&data,  data_len, cli->max_xmit /* data, length, max */ | 
|---|
| 2109 | )) { | 
|---|
| 2110 | SAFE_FREE(param); | 
|---|
| 2111 | return False; | 
|---|
| 2112 | } | 
|---|
| 2113 |  | 
|---|
| 2114 | SAFE_FREE(param); | 
|---|
| 2115 |  | 
|---|
| 2116 | if (!cli_receive_trans(cli, SMBtrans2, | 
|---|
| 2117 | &rparam, ¶m_len, | 
|---|
| 2118 | &rdata, &data_len)) { | 
|---|
| 2119 | return False; | 
|---|
| 2120 | } | 
|---|
| 2121 |  | 
|---|
| 2122 | SAFE_FREE(rdata); | 
|---|
| 2123 | SAFE_FREE(rparam); | 
|---|
| 2124 |  | 
|---|
| 2125 | return True; | 
|---|
| 2126 | } | 
|---|
| 2127 |  | 
|---|
| 2128 | /**************************************************************************** | 
|---|
| 2129 | unlink - POSIX semantics. | 
|---|
| 2130 | ****************************************************************************/ | 
|---|
| 2131 |  | 
|---|
| 2132 | bool cli_posix_unlink(struct cli_state *cli, const char *fname) | 
|---|
| 2133 | { | 
|---|
| 2134 | return cli_posix_unlink_internal(cli, fname, False); | 
|---|
| 2135 | } | 
|---|
| 2136 |  | 
|---|
| 2137 | /**************************************************************************** | 
|---|
| 2138 | rmdir - POSIX semantics. | 
|---|
| 2139 | ****************************************************************************/ | 
|---|
| 2140 |  | 
|---|
| 2141 | int cli_posix_rmdir(struct cli_state *cli, const char *fname) | 
|---|
| 2142 | { | 
|---|
| 2143 | return cli_posix_unlink_internal(cli, fname, True); | 
|---|
| 2144 | } | 
|---|