root/source4/libcli/raw/rawsetfileinfo.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. smb_raw_setfileinfo_passthru
  2. smb_raw_setinfo_backend
  3. smb_raw_setfileinfo_blob_send
  4. smb_raw_setpathinfo_blob_send
  5. smb_raw_setattr_send
  6. smb_raw_setattrE_send
  7. smb_raw_setfileinfo_send
  8. smb_raw_setfileinfo
  9. smb_raw_setpathinfo_send
  10. smb_raw_setpathinfo

   1 /* 
   2    Unix SMB/CIFS implementation.
   3    RAW_SFILEINFO_* calls
   4    Copyright (C) James Myers 2003
   5    Copyright (C) Andrew Tridgell 2003
   6    Copyright (C) James Peach 2007
   7    
   8    This program is free software; you can redistribute it and/or modify
   9    it under the terms of the GNU General Public License as published by
  10    the Free Software Foundation; either version 3 of the License, or
  11    (at your option) any later version.
  12    
  13    This program is distributed in the hope that it will be useful,
  14    but WITHOUT ANY WARRANTY; without even the implied warranty of
  15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16    GNU General Public License for more details.
  17    
  18    You should have received a copy of the GNU General Public License
  19    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  20 */
  21 
  22 #include "includes.h"
  23 #include "libcli/raw/libcliraw.h"
  24 #include "libcli/raw/raw_proto.h"
  25 #include "librpc/gen_ndr/ndr_security.h"
  26 
  27 
  28 /*
  29   Handle setfileinfo/setpathinfo passthu constructions
  30 */
  31 bool smb_raw_setfileinfo_passthru(TALLOC_CTX *mem_ctx,
     /* [<][>][^][v][top][bottom][index][help] */
  32                                   enum smb_setfileinfo_level level,
  33                                   union smb_setfileinfo *parms, 
  34                                   DATA_BLOB *blob)
  35 {       
  36         uint_t len;
  37 
  38 #define NEED_BLOB(n) do { \
  39           *blob = data_blob_talloc(mem_ctx, NULL, n); \
  40           if (blob->data == NULL && n != 0) return false; \
  41         } while (0)
  42 
  43         switch (level) {
  44         case RAW_SFILEINFO_BASIC_INFORMATION:
  45                 NEED_BLOB(40);
  46                 smbcli_push_nttime(blob->data,  0, parms->basic_info.in.create_time);
  47                 smbcli_push_nttime(blob->data,  8, parms->basic_info.in.access_time);
  48                 smbcli_push_nttime(blob->data, 16, parms->basic_info.in.write_time);
  49                 smbcli_push_nttime(blob->data, 24, parms->basic_info.in.change_time);
  50                 SIVAL(blob->data,           32, parms->basic_info.in.attrib);
  51                 SIVAL(blob->data,           36, 0); /* padding */
  52                 return true;
  53 
  54         case RAW_SFILEINFO_DISPOSITION_INFORMATION:
  55                 NEED_BLOB(4);
  56                 SIVAL(blob->data, 0, parms->disposition_info.in.delete_on_close);
  57                 return true;
  58 
  59         case RAW_SFILEINFO_ALLOCATION_INFORMATION:
  60                 NEED_BLOB(8);
  61                 SBVAL(blob->data, 0, parms->allocation_info.in.alloc_size);
  62                 return true;
  63 
  64         case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
  65                 NEED_BLOB(8);
  66                 SBVAL(blob->data, 0, parms->end_of_file_info.in.size);
  67                 return true;
  68 
  69         case RAW_SFILEINFO_RENAME_INFORMATION:
  70                 NEED_BLOB(12);
  71                 SIVAL(blob->data, 0, parms->rename_information.in.overwrite);
  72                 SIVAL(blob->data, 4, parms->rename_information.in.root_fid);
  73                 len = smbcli_blob_append_string(NULL, mem_ctx, blob,
  74                                                 parms->rename_information.in.new_name, 
  75                                                 STR_UNICODE|STR_TERMINATE);
  76                 SIVAL(blob->data, 8, len - 2);
  77                 return true;
  78 
  79         case RAW_SFILEINFO_RENAME_INFORMATION_SMB2:
  80                 NEED_BLOB(20);
  81                 SIVAL(blob->data, 0, parms->rename_information.in.overwrite);
  82                 SBVAL(blob->data, 8, parms->rename_information.in.root_fid);
  83                 len = smbcli_blob_append_string(NULL, mem_ctx, blob,
  84                                                 parms->rename_information.in.new_name, 
  85                                                 STR_UNICODE|STR_TERMINATE);
  86                 SIVAL(blob->data, 16, len - 2);
  87                 return true;
  88 
  89         case RAW_SFILEINFO_POSITION_INFORMATION:
  90                 NEED_BLOB(8);
  91                 SBVAL(blob->data, 0, parms->position_information.in.position);
  92                 return true;
  93 
  94         case RAW_SFILEINFO_MODE_INFORMATION:
  95                 NEED_BLOB(4);
  96                 SIVAL(blob->data, 0, parms->mode_information.in.mode);
  97                 return true;
  98 
  99         case RAW_FILEINFO_SEC_DESC: {
 100                 enum ndr_err_code ndr_err;
 101 
 102                 ndr_err = ndr_push_struct_blob(blob, mem_ctx, NULL,
 103                                                parms->set_secdesc.in.sd,
 104                                                (ndr_push_flags_fn_t)ndr_push_security_descriptor);
 105                 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
 106                         return false;
 107                 }
 108 
 109                 return true;
 110         }
 111 
 112         case RAW_SFILEINFO_FULL_EA_INFORMATION:
 113                 printf("num_eas=%d\n", parms->full_ea_information.in.eas.num_eas);
 114                 NEED_BLOB(ea_list_size_chained(
 115                                   parms->full_ea_information.in.eas.num_eas,
 116                                   parms->full_ea_information.in.eas.eas, 4));
 117                 ea_put_list_chained(blob->data, 
 118                                     parms->full_ea_information.in.eas.num_eas,
 119                                     parms->full_ea_information.in.eas.eas, 4);
 120                 return true;
 121 
 122                 /* Unhandled levels */
 123         case RAW_SFILEINFO_PIPE_INFORMATION:
 124         case RAW_SFILEINFO_VALID_DATA_INFORMATION:
 125         case RAW_SFILEINFO_SHORT_NAME_INFORMATION:
 126         case RAW_SFILEINFO_1025:
 127         case RAW_SFILEINFO_1027:
 128         case RAW_SFILEINFO_1029:
 129         case RAW_SFILEINFO_1030:
 130         case RAW_SFILEINFO_1031:
 131         case RAW_SFILEINFO_1032:
 132         case RAW_SFILEINFO_1036:
 133         case RAW_SFILEINFO_1041:
 134         case RAW_SFILEINFO_1042:
 135         case RAW_SFILEINFO_1043:
 136         case RAW_SFILEINFO_1044:
 137                 break;
 138 
 139         default:
 140                 DEBUG(0,("Unhandled setfileinfo passthru level %d\n", level));
 141                 return false;
 142         }
 143 
 144         return false;
 145 }
 146 
 147 /*
 148   Handle setfileinfo/setpathinfo trans2 backend.
 149 */
 150 static bool smb_raw_setinfo_backend(struct smbcli_tree *tree,
     /* [<][>][^][v][top][bottom][index][help] */
 151                                     TALLOC_CTX *mem_ctx,
 152                                     union smb_setfileinfo *parms, 
 153                                     DATA_BLOB *blob)
 154 {       
 155         switch (parms->generic.level) {
 156         case RAW_SFILEINFO_GENERIC:
 157         case RAW_SFILEINFO_SETATTR:
 158         case RAW_SFILEINFO_SETATTRE:
 159         case RAW_SFILEINFO_SEC_DESC:
 160                 /* not handled here */
 161                 return false;
 162 
 163         case RAW_SFILEINFO_STANDARD:
 164                 NEED_BLOB(12);
 165                 raw_push_dos_date2(tree->session->transport, 
 166                                   blob->data, 0, parms->standard.in.create_time);
 167                 raw_push_dos_date2(tree->session->transport, 
 168                                   blob->data, 4, parms->standard.in.access_time);
 169                 raw_push_dos_date2(tree->session->transport, 
 170                                   blob->data, 8, parms->standard.in.write_time);
 171                 return true;
 172 
 173         case RAW_SFILEINFO_EA_SET:
 174                 NEED_BLOB(ea_list_size(parms->ea_set.in.num_eas, parms->ea_set.in.eas));
 175                 ea_put_list(blob->data, parms->ea_set.in.num_eas, parms->ea_set.in.eas);
 176                 return true;
 177 
 178         case RAW_SFILEINFO_BASIC_INFO:
 179         case RAW_SFILEINFO_BASIC_INFORMATION:
 180                 return smb_raw_setfileinfo_passthru(mem_ctx, RAW_SFILEINFO_BASIC_INFORMATION, 
 181                                                     parms, blob);
 182 
 183         case RAW_SFILEINFO_UNIX_BASIC:
 184                 NEED_BLOB(100);
 185                 SBVAL(blob->data, 0, parms->unix_basic.in.end_of_file);
 186                 SBVAL(blob->data, 8, parms->unix_basic.in.num_bytes);
 187                 smbcli_push_nttime(blob->data, 16, parms->unix_basic.in.status_change_time);
 188                 smbcli_push_nttime(blob->data, 24, parms->unix_basic.in.access_time);
 189                 smbcli_push_nttime(blob->data, 32, parms->unix_basic.in.change_time);
 190                 SBVAL(blob->data, 40, parms->unix_basic.in.uid);
 191                 SBVAL(blob->data, 48, parms->unix_basic.in.gid);
 192                 SIVAL(blob->data, 56, parms->unix_basic.in.file_type);
 193                 SBVAL(blob->data, 60, parms->unix_basic.in.dev_major);
 194                 SBVAL(blob->data, 68, parms->unix_basic.in.dev_minor);
 195                 SBVAL(blob->data, 76, parms->unix_basic.in.unique_id);
 196                 SBVAL(blob->data, 84, parms->unix_basic.in.permissions);
 197                 SBVAL(blob->data, 92, parms->unix_basic.in.nlink);
 198                 return true;
 199 
 200         case RAW_SFILEINFO_UNIX_INFO2:
 201                 NEED_BLOB(116);
 202                 SBVAL(blob->data,   0, parms->unix_info2.in.end_of_file);
 203                 SBVAL(blob->data,   8, parms->unix_info2.in.num_bytes);
 204                 smbcli_push_nttime(blob->data, 16, parms->unix_info2.in.status_change_time);
 205                 smbcli_push_nttime(blob->data, 24, parms->unix_info2.in.access_time);
 206                 smbcli_push_nttime(blob->data, 32, parms->unix_info2.in.change_time);
 207                 SBVAL(blob->data,  40,parms->unix_info2.in.uid);
 208                 SBVAL(blob->data,  48,parms->unix_info2.in.gid);
 209                 SIVAL(blob->data,  56,parms->unix_info2.in.file_type);
 210                 SBVAL(blob->data,  60,parms->unix_info2.in.dev_major);
 211                 SBVAL(blob->data,  68,parms->unix_info2.in.dev_minor);
 212                 SBVAL(blob->data,  76,parms->unix_info2.in.unique_id);
 213                 SBVAL(blob->data,  84,parms->unix_info2.in.permissions);
 214                 SBVAL(blob->data,  92,parms->unix_info2.in.nlink);
 215                 smbcli_push_nttime(blob->data, 100, parms->unix_info2.in.create_time);
 216                 SIVAL(blob->data, 108, parms->unix_info2.in.file_flags);
 217                 SIVAL(blob->data, 112, parms->unix_info2.in.flags_mask);
 218                 return true;
 219 
 220         case RAW_SFILEINFO_DISPOSITION_INFO:
 221         case RAW_SFILEINFO_DISPOSITION_INFORMATION:
 222                 return smb_raw_setfileinfo_passthru(mem_ctx, RAW_SFILEINFO_DISPOSITION_INFORMATION,
 223                                                     parms, blob);
 224 
 225         case RAW_SFILEINFO_ALLOCATION_INFO:
 226         case RAW_SFILEINFO_ALLOCATION_INFORMATION:
 227                 return smb_raw_setfileinfo_passthru(mem_ctx, RAW_SFILEINFO_ALLOCATION_INFORMATION,
 228                                                     parms, blob);
 229 
 230         case RAW_SFILEINFO_END_OF_FILE_INFO:
 231         case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
 232                 return smb_raw_setfileinfo_passthru(mem_ctx, RAW_SFILEINFO_END_OF_FILE_INFORMATION,
 233                                                     parms, blob);
 234 
 235         case RAW_SFILEINFO_RENAME_INFORMATION:
 236                 return smb_raw_setfileinfo_passthru(mem_ctx, RAW_SFILEINFO_RENAME_INFORMATION,
 237                                                     parms, blob);
 238 
 239         case RAW_SFILEINFO_POSITION_INFORMATION:
 240                 return smb_raw_setfileinfo_passthru(mem_ctx, RAW_SFILEINFO_POSITION_INFORMATION,
 241                                                     parms, blob);
 242 
 243         case RAW_SFILEINFO_MODE_INFORMATION:
 244                 return smb_raw_setfileinfo_passthru(mem_ctx, RAW_SFILEINFO_MODE_INFORMATION,
 245                                                     parms, blob);
 246                 
 247                 /* Unhandled passthru levels */
 248         case RAW_SFILEINFO_PIPE_INFORMATION:
 249         case RAW_SFILEINFO_VALID_DATA_INFORMATION:
 250         case RAW_SFILEINFO_SHORT_NAME_INFORMATION:
 251         case RAW_SFILEINFO_FULL_EA_INFORMATION:
 252         case RAW_SFILEINFO_1025:
 253         case RAW_SFILEINFO_1027:
 254         case RAW_SFILEINFO_1029:
 255         case RAW_SFILEINFO_1030:
 256         case RAW_SFILEINFO_1031:
 257         case RAW_SFILEINFO_1032:
 258         case RAW_SFILEINFO_1036:
 259         case RAW_SFILEINFO_1041:
 260         case RAW_SFILEINFO_1042:
 261         case RAW_SFILEINFO_1043:
 262         case RAW_SFILEINFO_1044:
 263                 return smb_raw_setfileinfo_passthru(mem_ctx, parms->generic.level,
 264                                                     parms, blob);
 265 
 266                 /* Unhandled levels */
 267 
 268         case RAW_SFILEINFO_UNIX_LINK:
 269         case RAW_SFILEINFO_UNIX_HLINK:
 270         case RAW_SFILEINFO_RENAME_INFORMATION_SMB2:
 271                 break;
 272         }
 273 
 274         return false;
 275 }
 276 
 277 /****************************************************************************
 278  Very raw set file info - takes data blob (async send)
 279 ****************************************************************************/
 280 static struct smbcli_request *smb_raw_setfileinfo_blob_send(struct smbcli_tree *tree,
     /* [<][>][^][v][top][bottom][index][help] */
 281                                                          TALLOC_CTX *mem_ctx,
 282                                                          uint16_t fnum,
 283                                                          uint16_t info_level,
 284                                                          DATA_BLOB *blob)
 285 {
 286         struct smb_trans2 tp;
 287         uint16_t setup = TRANSACT2_SETFILEINFO;
 288         
 289         tp.in.max_setup = 0;
 290         tp.in.flags = 0; 
 291         tp.in.timeout = 0;
 292         tp.in.setup_count = 1;
 293         tp.in.max_param = 2;
 294         tp.in.max_data = 0;
 295         tp.in.setup = &setup;
 296         
 297         tp.in.params = data_blob_talloc(mem_ctx, NULL, 6);
 298         if (!tp.in.params.data) {
 299                 return NULL;
 300         }
 301         SSVAL(tp.in.params.data, 0, fnum);
 302         SSVAL(tp.in.params.data, 2, info_level);
 303         SSVAL(tp.in.params.data, 4, 0); /* reserved */
 304 
 305         tp.in.data = *blob;
 306 
 307         return smb_raw_trans2_send(tree, &tp);
 308 }
 309 
 310 /****************************************************************************
 311  Very raw set path info - takes data blob
 312 ****************************************************************************/
 313 static struct smbcli_request *smb_raw_setpathinfo_blob_send(struct smbcli_tree *tree,
     /* [<][>][^][v][top][bottom][index][help] */
 314                                                             TALLOC_CTX *mem_ctx,
 315                                                             const char *fname,
 316                                                             uint16_t info_level,
 317                                                             DATA_BLOB *blob)
 318 {
 319         struct smb_trans2 tp;
 320         uint16_t setup = TRANSACT2_SETPATHINFO;
 321         
 322         tp.in.max_setup = 0;
 323         tp.in.flags = 0; 
 324         tp.in.timeout = 0;
 325         tp.in.setup_count = 1;
 326         tp.in.max_param = 2;
 327         tp.in.max_data = 0;
 328         tp.in.setup = &setup;
 329         
 330         tp.in.params = data_blob_talloc(mem_ctx, NULL, 6);
 331         if (!tp.in.params.data) {
 332                 return NULL;
 333         }
 334         SSVAL(tp.in.params.data, 0, info_level);
 335         SIVAL(tp.in.params.data, 2, 0);
 336         smbcli_blob_append_string(tree->session, mem_ctx, 
 337                                   &tp.in.params,
 338                                   fname, STR_TERMINATE);
 339 
 340         tp.in.data = *blob;
 341 
 342         return smb_raw_trans2_send(tree, &tp);
 343 }
 344                 
 345 /****************************************************************************
 346  Handle setattr (async send)
 347 ****************************************************************************/
 348 static struct smbcli_request *smb_raw_setattr_send(struct smbcli_tree *tree,
     /* [<][>][^][v][top][bottom][index][help] */
 349                                                 union smb_setfileinfo *parms)
 350 {
 351         struct smbcli_request *req;
 352 
 353         req = smbcli_request_setup(tree, SMBsetatr, 8, 0);
 354         if (!req) return NULL;
 355         
 356         SSVAL(req->out.vwv,         VWV(0), parms->setattr.in.attrib);
 357         raw_push_dos_date3(tree->session->transport, 
 358                           req->out.vwv, VWV(1), parms->setattr.in.write_time);
 359         memset(req->out.vwv + VWV(3), 0, 10); /* reserved */
 360         smbcli_req_append_ascii4(req, parms->setattr.in.file.path, STR_TERMINATE);
 361         smbcli_req_append_ascii4(req, "", STR_TERMINATE);
 362         
 363         if (!smbcli_request_send(req)) {
 364                 smbcli_request_destroy(req);
 365                 return NULL;
 366         }
 367 
 368         return req;
 369 }
 370                 
 371 /****************************************************************************
 372  Handle setattrE. (async send)
 373 ****************************************************************************/
 374 static struct smbcli_request *smb_raw_setattrE_send(struct smbcli_tree *tree,
     /* [<][>][^][v][top][bottom][index][help] */
 375                                                  union smb_setfileinfo *parms)
 376 {
 377         struct smbcli_request *req;
 378 
 379         req = smbcli_request_setup(tree, SMBsetattrE, 7, 0);
 380         if (!req) return NULL;
 381         
 382         SSVAL(req->out.vwv,         VWV(0), parms->setattre.in.file.fnum);
 383         raw_push_dos_date2(tree->session->transport, 
 384                           req->out.vwv, VWV(1), parms->setattre.in.create_time);
 385         raw_push_dos_date2(tree->session->transport, 
 386                           req->out.vwv, VWV(3), parms->setattre.in.access_time);
 387         raw_push_dos_date2(tree->session->transport, 
 388                           req->out.vwv, VWV(5), parms->setattre.in.write_time);
 389 
 390         if (!smbcli_request_send(req)) {
 391                 smbcli_request_destroy(req);
 392                 return NULL;
 393         }
 394 
 395         return req;
 396 }
 397 
 398 /****************************************************************************
 399  Set file info (async send)
 400 ****************************************************************************/
 401 struct smbcli_request *smb_raw_setfileinfo_send(struct smbcli_tree *tree,
     /* [<][>][^][v][top][bottom][index][help] */
 402                                              union smb_setfileinfo *parms)
 403 {
 404         DATA_BLOB blob;
 405         TALLOC_CTX *mem_ctx;
 406         struct smbcli_request *req;
 407 
 408         if (parms->generic.level == RAW_SFILEINFO_SETATTRE) {
 409                 return smb_raw_setattrE_send(tree, parms);
 410         }
 411         if (parms->generic.level == RAW_SFILEINFO_SEC_DESC) {
 412                 return smb_raw_set_secdesc_send(tree, parms);
 413         }
 414         if (parms->generic.level >= RAW_SFILEINFO_GENERIC) {
 415                 return NULL;
 416         }
 417 
 418         mem_ctx = talloc_init("setpathinfo");
 419         if (!mem_ctx) return NULL;
 420 
 421         if (!smb_raw_setinfo_backend(tree, mem_ctx, parms, &blob)) {
 422                 talloc_free(mem_ctx);
 423                 return NULL;
 424         }
 425         
 426         /* send request and process the output */
 427         req = smb_raw_setfileinfo_blob_send(tree, 
 428                                             mem_ctx,
 429                                             parms->generic.in.file.fnum, 
 430                                             parms->generic.level, 
 431                                             &blob);
 432 
 433         talloc_free(mem_ctx);
 434         return req;
 435 }
 436 
 437 /****************************************************************************
 438  Set file info (async send)
 439 ****************************************************************************/
 440 _PUBLIC_ NTSTATUS smb_raw_setfileinfo(struct smbcli_tree *tree,
     /* [<][>][^][v][top][bottom][index][help] */
 441                              union smb_setfileinfo *parms)
 442 {
 443         struct smbcli_request *req = smb_raw_setfileinfo_send(tree, parms);
 444         return smbcli_request_simple_recv(req);
 445 }
 446 
 447 
 448 /****************************************************************************
 449  Set path info (async send)
 450 ****************************************************************************/
 451 _PUBLIC_ struct smbcli_request *smb_raw_setpathinfo_send(struct smbcli_tree *tree,
     /* [<][>][^][v][top][bottom][index][help] */
 452                                              union smb_setfileinfo *parms)
 453 {
 454         DATA_BLOB blob;
 455         TALLOC_CTX *mem_ctx;
 456         struct smbcli_request *req;
 457 
 458         if (parms->generic.level == RAW_SFILEINFO_SETATTR) {
 459                 return smb_raw_setattr_send(tree, parms);
 460         }
 461         if (parms->generic.level >= RAW_SFILEINFO_GENERIC) {
 462                 return NULL;
 463         }
 464 
 465         mem_ctx = talloc_init("setpathinfo");
 466         if (!mem_ctx) return NULL;
 467 
 468         if (!smb_raw_setinfo_backend(tree, mem_ctx, parms, &blob)) {
 469                 talloc_free(mem_ctx);
 470                 return NULL;
 471         }
 472 
 473         /* send request and process the output */
 474         req = smb_raw_setpathinfo_blob_send(tree, 
 475                                             mem_ctx,
 476                                             parms->generic.in.file.path, 
 477                                             parms->generic.level,
 478                                             &blob);
 479 
 480         talloc_free(mem_ctx);
 481         return req;
 482 }
 483 
 484 /****************************************************************************
 485  Set path info (sync interface)
 486 ****************************************************************************/
 487 _PUBLIC_ NTSTATUS smb_raw_setpathinfo(struct smbcli_tree *tree,
     /* [<][>][^][v][top][bottom][index][help] */
 488                              union smb_setfileinfo *parms)
 489 {
 490         struct smbcli_request *req = smb_raw_setpathinfo_send(tree, parms);
 491         return smbcli_request_simple_recv(req);
 492 }

/* [<][>][^][v][top][bottom][index][help] */