Changeset 988 for vendor/current/source3/smbd/trans2.c
- Timestamp:
- Nov 24, 2016, 1:14:11 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source3/smbd/trans2.c
r860 r988 33 33 #include "../librpc/gen_ndr/xattr.h" 34 34 #include "../librpc/gen_ndr/ndr_security.h" 35 #include "../librpc/gen_ndr/open_files.h" 35 36 #include "libcli/security/security.h" 36 37 #include "trans2.h" … … 38 39 #include "smbprofile.h" 39 40 #include "rpc_server/srv_pipe_hnd.h" 40 #include "libsmb/libsmb.h" 41 #include "printing.h" 42 #include "lib/util_ea.h" 43 #include "lib/readdir_attr.h" 41 44 42 45 #define DIR_ENTRY_SAFETY_MARGIN 4096 … … 51 54 files_struct *fsp, 52 55 const SMB_STRUCT_STAT *psbuf); 56 57 /**************************************************************************** 58 Check if an open file handle or pathname is a symlink. 59 ****************************************************************************/ 60 61 static NTSTATUS refuse_symlink(connection_struct *conn, 62 const files_struct *fsp, 63 const char *name) 64 { 65 SMB_STRUCT_STAT sbuf; 66 const SMB_STRUCT_STAT *pst = NULL; 67 68 if (fsp) { 69 pst = &fsp->fsp_name->st; 70 } else { 71 int ret = vfs_stat_smb_basename(conn, 72 name, 73 &sbuf); 74 if (ret == -1) { 75 return map_nt_error_from_unix(errno); 76 } 77 pst = &sbuf; 78 } 79 if (S_ISLNK(pst->st_ex_mode)) { 80 return NT_STATUS_ACCESS_DENIED; 81 } 82 return NT_STATUS_OK; 83 } 84 85 NTSTATUS check_access_fsp(const struct files_struct *fsp, 86 uint32_t access_mask) 87 { 88 if (!(fsp->access_mask & access_mask)) { 89 return NT_STATUS_ACCESS_DENIED; 90 } 91 return NT_STATUS_OK; 92 } 93 94 /******************************************************************** 95 The canonical "check access" based on object handle or path function. 96 ********************************************************************/ 97 98 NTSTATUS check_access(connection_struct *conn, 99 files_struct *fsp, 100 const struct smb_filename *smb_fname, 101 uint32_t access_mask) 102 { 103 NTSTATUS status; 104 105 if (fsp) { 106 status = check_access_fsp(fsp, access_mask); 107 } else { 108 status = smbd_check_access_rights(conn, smb_fname, 109 false, access_mask); 110 } 111 112 return status; 113 } 53 114 54 115 /******************************************************************** … … 94 155 ****************************************************************************/ 95 156 96 staticbool samba_private_attr_name(const char *unix_ea_name)157 bool samba_private_attr_name(const char *unix_ea_name) 97 158 { 98 159 static const char * const prohibited_ea_names[] = { … … 110 171 return true; 111 172 } 112 if ( StrnCaseCmp(unix_ea_name, SAMBA_XATTR_DOSSTREAM_PREFIX,173 if (strncasecmp_m(unix_ea_name, SAMBA_XATTR_DOSSTREAM_PREFIX, 113 174 strlen(SAMBA_XATTR_DOSSTREAM_PREFIX)) == 0) { 114 175 return true; … … 132 193 again: 133 194 134 val = TALLOC_REALLOC_ARRAY(mem_ctx, val, char, attr_size);195 val = talloc_realloc(mem_ctx, val, char, attr_size); 135 196 if (!val) { 136 197 return NT_STATUS_NO_MEMORY; … … 153 214 154 215 DEBUG(10,("get_ea_value: EA %s is of length %u\n", ea_name, (unsigned int)sizeret)); 155 dump_data(10, (uint8 *)val, sizeret);216 dump_data(10, (uint8_t *)val, sizeret); 156 217 157 218 pea->flags = 0; … … 182 243 size_t num_names; 183 244 ssize_t sizeret = -1; 245 NTSTATUS status; 246 247 if (pnames) { 248 *pnames = NULL; 249 } 250 *pnum_names = 0; 184 251 185 252 if (!lp_ea_support(SNUM(conn))) { 186 if (pnames) { 187 *pnames = NULL; 188 } 189 *pnum_names = 0; 253 return NT_STATUS_OK; 254 } 255 256 status = refuse_symlink(conn, fsp, fname); 257 if (!NT_STATUS_IS_OK(status)) { 258 /* 259 * Just return no EA's on a symlink. 260 */ 190 261 return NT_STATUS_OK; 191 262 } … … 195 266 */ 196 267 197 names = TALLOC_ARRAY(mem_ctx, char *, 1);268 names = talloc_array(mem_ctx, char *, 1); 198 269 if (names == NULL) { 199 270 DEBUG(0, ("talloc failed\n")); … … 203 274 while (ea_namelist_size <= 65536) { 204 275 205 ea_namelist = TALLOC_REALLOC_ARRAY(276 ea_namelist = talloc_realloc( 206 277 names, ea_namelist, char, ea_namelist_size); 207 278 if (ea_namelist == NULL) { … … 232 303 } 233 304 234 DEBUG(10, (" get_ea_list_from_file: ea_namelist size = %u\n",235 (unsigned int)sizeret));305 DEBUG(10, ("%s: ea_namelist size = %u\n", 306 __func__, (unsigned int)sizeret)); 236 307 237 308 if (sizeret == 0) { 238 309 TALLOC_FREE(names); 239 if (pnames) {240 *pnames = NULL;241 }242 *pnum_names = 0;243 310 return NT_STATUS_OK; 244 311 } … … 262 329 } 263 330 264 tmp = TALLOC_REALLOC_ARRAY(mem_ctx, names, char *, num_names);331 tmp = talloc_realloc(mem_ctx, names, char *, num_names); 265 332 if (tmp == NULL) { 266 333 DEBUG(0, ("talloc failed\n")); … … 289 356 ****************************************************************************/ 290 357 291 static struct ea_list *get_ea_list_from_file(TALLOC_CTX *mem_ctx, connection_struct *conn, files_struct *fsp,292 const char *fname, size_t *pea_total_len)358 static NTSTATUS get_ea_list_from_file_path(TALLOC_CTX *mem_ctx, connection_struct *conn, files_struct *fsp, 359 const char *fname, size_t *pea_total_len, struct ea_list **ea_list) 293 360 { 294 361 /* Get a list of all xattrs. Max namesize is 64k. */ … … 299 366 300 367 *pea_total_len = 0; 301 302 if (!lp_ea_support(SNUM(conn))) { 303 return NULL; 304 } 368 *ea_list = NULL; 305 369 306 370 status = get_ea_names_from_file(talloc_tos(), conn, fsp, fname, 307 371 &names, &num_names); 308 372 309 if (!NT_STATUS_IS_OK(status) || (num_names == 0)) { 310 return NULL; 373 if (!NT_STATUS_IS_OK(status)) { 374 return status; 375 } 376 377 if (num_names == 0) { 378 *ea_list = NULL; 379 return NT_STATUS_OK; 311 380 } 312 381 … … 319 388 continue; 320 389 321 listp = TALLOC_P(mem_ctx, struct ea_list); 390 /* 391 * Filter out any underlying POSIX EA names 392 * that a Windows client can't handle. 393 */ 394 if (!lp_posix_pathnames() && 395 is_invalid_windows_ea_name(names[i])) { 396 continue; 397 } 398 399 listp = talloc(mem_ctx, struct ea_list); 322 400 if (listp == NULL) { 323 return NULL; 324 } 325 326 if (!NT_STATUS_IS_OK(get_ea_value(mem_ctx, conn, fsp, 327 fname, names[i], 328 &listp->ea))) { 329 return NULL; 401 return NT_STATUS_NO_MEMORY; 402 } 403 404 status = get_ea_value(listp, conn, fsp, 405 fname, names[i], 406 &listp->ea); 407 408 if (!NT_STATUS_IS_OK(status)) { 409 TALLOC_FREE(listp); 410 return status; 330 411 } 331 412 … … 348 429 (unsigned int)listp->ea.value.length)); 349 430 350 DLIST_ADD_END(ea_list_head, listp , struct ea_list *);431 DLIST_ADD_END(ea_list_head, listp); 351 432 352 433 } … … 360 441 (unsigned int)*pea_total_len)); 361 442 362 return ea_list_head; 443 *ea_list = ea_list_head; 444 return NT_STATUS_OK; 445 } 446 447 static NTSTATUS get_ea_list_from_file(TALLOC_CTX *mem_ctx, connection_struct *conn, files_struct *fsp, 448 const struct smb_filename *smb_fname, size_t *pea_total_len, struct ea_list **ea_list) 449 { 450 *pea_total_len = 0; 451 *ea_list = NULL; 452 453 if (!lp_ea_support(SNUM(conn))) { 454 return NT_STATUS_OK; 455 } 456 457 if (is_ntfs_stream_smb_fname(smb_fname)) { 458 return NT_STATUS_INVALID_PARAMETER; 459 } 460 461 return get_ea_list_from_file_path(mem_ctx, conn, fsp, smb_fname->base_name, pea_total_len, ea_list); 363 462 } 364 463 … … 400 499 SCVAL(p,1,dos_namelen); 401 500 SSVAL(p,2,ea_list->ea.value.length); 402 fstrcpy(p+4, dos_ea_name);501 strlcpy(p+4, dos_ea_name, dos_namelen+1); 403 502 memcpy( p + 4 + dos_namelen + 1, ea_list->ea.value.data, ea_list->ea.value.length); 404 503 … … 422 521 uint8_t *p = (uint8_t *)pdata; 423 522 uint8_t *last_start = NULL; 424 bool store_data = (pdata != NULL);523 bool do_store_data = (pdata != NULL); 425 524 426 525 *ret_data_size = 0; … … 436 535 size_t pad = 0; 437 536 438 if (last_start &&store_data) {537 if (last_start != NULL && do_store_data) { 439 538 SIVAL(last_start, 0, PTR_DIFF(p, last_start)); 440 539 } … … 457 556 } 458 557 459 if ( this_size > total_data_size) {460 return NT_STATUS_INFO_LENGTH_MISMATCH;461 }462 463 /* We know we have room. */ 464 if (store_data) {558 if (do_store_data) { 559 if (this_size > total_data_size) { 560 return NT_STATUS_INFO_LENGTH_MISMATCH; 561 } 562 563 /* We know we have room. */ 465 564 SIVAL(p, 0x00, 0); /* next offset */ 466 565 SCVAL(p, 0x04, ea_list->ea.flags); 467 566 SCVAL(p, 0x05, dos_namelen); 468 567 SSVAL(p, 0x06, ea_list->ea.value.length); 469 fstrcpy((char *)(p+0x08), dos_ea_name);568 strlcpy((char *)(p+0x08), dos_ea_name, dos_namelen+1); 470 569 memcpy(p + 0x08 + dos_namelen + 1, ea_list->ea.value.data, ea_list->ea.value.length); 471 570 if (pad) { … … 474 573 pad); 475 574 } 476 }477 478 total_data_size -= this_size; 575 total_data_size -= this_size; 576 } 577 479 578 p += this_size; 480 579 } … … 485 584 } 486 585 487 static unsigned int estimate_ea_size(connection_struct *conn, files_struct *fsp, const char *fname)586 static unsigned int estimate_ea_size(connection_struct *conn, files_struct *fsp, const struct smb_filename *smb_fname) 488 587 { 489 588 size_t total_ea_len = 0; 589 TALLOC_CTX *mem_ctx; 490 590 struct ea_list *ea_list = NULL; 491 TALLOC_CTX *mem_ctx = NULL;492 591 493 592 if (!lp_ea_support(SNUM(conn))) { 494 593 return 0; 495 594 } 496 mem_ctx = talloc_tos(); 497 ea_list = get_ea_list_from_file(mem_ctx, conn, fsp, fname, &total_ea_len); 498 if (ea_list == NULL) { 499 return 0; 500 } 595 mem_ctx = talloc_stackframe(); 596 597 /* If this is a stream fsp, then we need to instead find the 598 * estimated ea len from the main file, not the stream 599 * (streams cannot have EAs), but the estimate isn't just 0 in 600 * this case! */ 601 if (is_ntfs_stream_smb_fname(smb_fname)) { 602 fsp = NULL; 603 } 604 (void)get_ea_list_from_file_path(mem_ctx, conn, fsp, smb_fname->base_name, &total_ea_len, &ea_list); 501 605 if(conn->sconn->using_smb2) { 502 606 NTSTATUS status; … … 510 614 status = fill_ea_chained_buffer(mem_ctx, 511 615 NULL, 512 65535,616 0, 513 617 &ret_data_size, 514 618 conn, … … 519 623 total_ea_len = ret_data_size; 520 624 } 521 625 TALLOC_FREE(mem_ctx); 522 626 return total_ea_len; 523 627 } … … 531 635 size_t total_ea_len; 532 636 TALLOC_CTX *mem_ctx = talloc_tos(); 533 struct ea_list *ea_list = get_ea_list_from_file(mem_ctx, conn, fsp, fname, &total_ea_len); 637 struct ea_list *ea_list; 638 NTSTATUS status = get_ea_list_from_file_path(mem_ctx, conn, fsp, fname, &total_ea_len, &ea_list); 639 if (!NT_STATUS_IS_OK(status)) { 640 return; 641 } 534 642 535 643 for (; ea_list; ea_list = ea_list->next) { … … 537 645 DEBUG(10,("canonicalize_ea_name: %s -> %s\n", 538 646 &unix_ea_name[5], ea_list->ea.name)); 539 s afe_strcpy(&unix_ea_name[5], ea_list->ea.name, sizeof(fstring)-6);647 strlcpy(&unix_ea_name[5], ea_list->ea.name, sizeof(fstring)-5); 540 648 break; 541 649 } … … 550 658 const struct smb_filename *smb_fname, struct ea_list *ea_list) 551 659 { 660 NTSTATUS status; 552 661 char *fname = NULL; 553 662 … … 556 665 } 557 666 558 if (fsp && !(fsp->access_mask & FILE_WRITE_EA)) { 559 return NT_STATUS_ACCESS_DENIED; 560 } 561 562 /* For now setting EAs on streams isn't supported. */ 667 status = refuse_symlink(conn, fsp, smb_fname->base_name); 668 if (!NT_STATUS_IS_OK(status)) { 669 return status; 670 } 671 672 status = check_access(conn, fsp, smb_fname, FILE_WRITE_EA); 673 if (!NT_STATUS_IS_OK(status)) { 674 return status; 675 } 676 677 /* Setting EAs on streams isn't supported. */ 678 if (is_ntfs_stream_smb_fname(smb_fname)) { 679 return NT_STATUS_INVALID_PARAMETER; 680 } 681 682 /* 683 * Filter out invalid Windows EA names - before 684 * we set *any* of them. 685 */ 686 687 if (ea_list_has_invalid_name(ea_list)) { 688 return STATUS_INVALID_EA_NAME; 689 } 690 563 691 fname = smb_fname->base_name; 564 692 … … 636 764 637 765 while (offset + 2 < data_size) { 638 struct ea_list *eal = TALLOC_ZERO_P(ctx, struct ea_list);766 struct ea_list *eal = talloc_zero(ctx, struct ea_list); 639 767 unsigned int namelen = CVAL(pdata,offset); 640 768 … … 661 789 662 790 offset += (namelen + 1); /* Go past the name + terminating zero. */ 663 DLIST_ADD_END(ea_list_head, eal , struct ea_list *);791 DLIST_ADD_END(ea_list_head, eal); 664 792 DEBUG(10,("read_ea_name_list: read ea name %s\n", eal->ea.name)); 665 793 } 666 794 667 795 return ea_list_head; 668 }669 670 /****************************************************************************671 Read one EA list entry from the buffer.672 ****************************************************************************/673 674 struct ea_list *read_ea_list_entry(TALLOC_CTX *ctx, const char *pdata, size_t data_size, size_t *pbytes_used)675 {676 struct ea_list *eal = TALLOC_ZERO_P(ctx, struct ea_list);677 uint16 val_len;678 unsigned int namelen;679 size_t converted_size;680 681 if (!eal) {682 return NULL;683 }684 685 if (data_size < 6) {686 return NULL;687 }688 689 eal->ea.flags = CVAL(pdata,0);690 namelen = CVAL(pdata,1);691 val_len = SVAL(pdata,2);692 693 if (4 + namelen + 1 + val_len > data_size) {694 return NULL;695 }696 697 /* Ensure the name is null terminated. */698 if (pdata[namelen + 4] != '\0') {699 return NULL;700 }701 if (!pull_ascii_talloc(ctx, &eal->ea.name, pdata + 4, &converted_size)) {702 DEBUG(0,("read_ea_list_entry: pull_ascii_talloc failed: %s",703 strerror(errno)));704 }705 if (!eal->ea.name) {706 return NULL;707 }708 709 eal->ea.value = data_blob_talloc(eal, NULL, (size_t)val_len + 1);710 if (!eal->ea.value.data) {711 return NULL;712 }713 714 memcpy(eal->ea.value.data, pdata + 4 + namelen + 1, val_len);715 716 /* Ensure we're null terminated just in case we print the value. */717 eal->ea.value.data[val_len] = '\0';718 /* But don't count the null. */719 eal->ea.value.length--;720 721 if (pbytes_used) {722 *pbytes_used = 4 + namelen + 1 + val_len;723 }724 725 DEBUG(10,("read_ea_list_entry: read ea name %s\n", eal->ea.name));726 dump_data(10, eal->ea.value.data, eal->ea.value.length);727 728 return eal;729 796 } 730 797 … … 746 813 } 747 814 748 DLIST_ADD_END(ea_list_head, eal , struct ea_list *);815 DLIST_ADD_END(ea_list_head, eal); 749 816 offset += bytes_used; 750 817 } … … 816 883 void send_trans2_replies(connection_struct *conn, 817 884 struct smb_request *req, 885 NTSTATUS status, 818 886 const char *params, 819 887 int paramsize, … … 837 905 int data_alignment_offset = 0; 838 906 bool overflow = False; 839 struct smb d_server_connection *sconn = req->sconn;840 int max_send = sconn->smb1.sessions.max_send;907 struct smbXsrv_connection *xconn = req->xconn; 908 int max_send = xconn->smb1.sessions.max_send; 841 909 842 910 /* Modify the data_to_send and datasize and set the error if … … 856 924 if(params_to_send == 0 && data_to_send == 0) { 857 925 reply_outbuf(req, 10, 0); 926 if (NT_STATUS_V(status)) { 927 uint8_t eclass; 928 uint32_t ecode; 929 ntstatus_to_dos(status, &eclass, &ecode); 930 error_packet_set((char *)req->outbuf, 931 eclass, ecode, status, 932 __LINE__,__FILE__); 933 } 858 934 show_msg((char *)req->outbuf); 859 if (!srv_send_smb( sconn,935 if (!srv_send_smb(xconn, 860 936 (char *)req->outbuf, 861 937 true, req->seqnum+1, … … 986 1062 STATUS_BUFFER_OVERFLOW, 987 1063 __LINE__,__FILE__); 1064 } else if (NT_STATUS_V(status)) { 1065 uint8_t eclass; 1066 uint32_t ecode; 1067 ntstatus_to_dos(status, &eclass, &ecode); 1068 error_packet_set((char *)req->outbuf, 1069 eclass, ecode, status, 1070 __LINE__,__FILE__); 988 1071 } 989 1072 990 1073 /* Send the packet */ 991 1074 show_msg((char *)req->outbuf); 992 if (!srv_send_smb( sconn,1075 if (!srv_send_smb(xconn, 993 1076 (char *)req->outbuf, 994 1077 true, req->seqnum+1, … … 1030 1113 char *pdata = *ppdata; 1031 1114 int deny_mode; 1032 int32 open_attr;1115 int32_t open_attr; 1033 1116 bool oplock_request; 1034 1117 #if 0 … … 1038 1121 #endif 1039 1122 int open_ofun; 1040 uint32 open_size;1123 uint32_t open_size; 1041 1124 char *pname; 1042 1125 char *fname = NULL; 1043 SMB_OFF_Tsize=0;1126 off_t size=0; 1044 1127 int fattr=0,mtime=0; 1045 1128 SMB_INO_T inode = 0; … … 1047 1130 files_struct *fsp; 1048 1131 struct ea_list *ea_list = NULL; 1049 uint16 flags = 0;1132 uint16_t flags = 0; 1050 1133 NTSTATUS status; 1051 uint32 access_mask;1052 uint32 share_mode;1053 uint32 create_disposition;1054 uint32 create_options = 0;1134 uint32_t access_mask; 1135 uint32_t share_mode; 1136 uint32_t create_disposition; 1137 uint32_t create_options = 0; 1055 1138 uint32_t private_flags = 0; 1139 uint32_t ucf_flags = (req->posix_pathnames ? UCF_POSIX_PATHNAMES : 0); 1056 1140 TALLOC_CTX *ctx = talloc_tos(); 1057 1141 … … 1087 1171 } 1088 1172 1089 srvstr_get_path(ctx, params, req->flags2, &fname, pname, 1090 total_params - 28, STR_TERMINATE, 1173 if (req->posix_pathnames) { 1174 srvstr_get_path_posix(ctx, 1175 params, 1176 req->flags2, 1177 &fname, 1178 pname, 1179 total_params - 28, 1180 STR_TERMINATE, 1091 1181 &status); 1182 } else { 1183 srvstr_get_path(ctx, 1184 params, 1185 req->flags2, 1186 &fname, 1187 pname, 1188 total_params - 28, 1189 STR_TERMINATE, 1190 &status); 1191 } 1092 1192 if (!NT_STATUS_IS_OK(status)) { 1093 1193 reply_nterror(req, status); … … 1103 1203 req->flags2 & FLAGS2_DFS_PATHNAMES, 1104 1204 fname, 1105 0,1205 ucf_flags, 1106 1206 NULL, 1107 1207 &smb_fname); … … 1155 1255 if (!lp_ea_support(SNUM(conn))) { 1156 1256 reply_nterror(req, NT_STATUS_EAS_NOT_SUPPORTED); 1257 goto out; 1258 } 1259 1260 if (ea_list_has_invalid_name(ea_list)) { 1261 int param_len = 30; 1262 *pparams = (char *)SMB_REALLOC(*pparams, param_len); 1263 if(*pparams == NULL ) { 1264 reply_nterror(req, NT_STATUS_NO_MEMORY); 1265 goto out; 1266 } 1267 params = *pparams; 1268 memset(params, '\0', param_len); 1269 send_trans2_replies(conn, req, STATUS_INVALID_EA_NAME, 1270 params, param_len, NULL, 0, max_data_bytes); 1157 1271 goto out; 1158 1272 } … … 1170 1284 open_attr, /* file_attributes */ 1171 1285 oplock_request, /* oplock_request */ 1286 NULL, /* lease */ 1172 1287 open_size, /* allocation_size */ 1173 1288 private_flags, … … 1175 1290 ea_list, /* ea_list */ 1176 1291 &fsp, /* result */ 1177 &smb_action); /* psbuf */ 1292 &smb_action, /* psbuf */ 1293 NULL, NULL); /* create context */ 1178 1294 1179 1295 if (!NT_STATUS_IS_OK(status)) { 1180 if (open_was_deferred(req-> mid)) {1296 if (open_was_deferred(req->xconn, req->mid)) { 1181 1297 /* We have re-scheduled this call. */ 1182 1298 goto out; … … 1207 1323 SSVAL(params,2,fattr); 1208 1324 srv_put_dos_date2(params,4, mtime); 1209 SIVAL(params,8, (uint32 )size);1325 SIVAL(params,8, (uint32_t)size); 1210 1326 SSVAL(params,12,deny_mode); 1211 1327 SSVAL(params,14,0); /* open_type - file or directory. */ … … 1224 1340 SSVAL(params,24,0); /* Padding. */ 1225 1341 if (flags & 8) { 1226 uint32 ea_size = estimate_ea_size(conn, fsp,1227 fsp->fsp_name->base_name);1342 uint32_t ea_size = estimate_ea_size(conn, fsp, 1343 smb_fname); 1228 1344 SIVAL(params, 26, ea_size); 1229 1345 } else { … … 1232 1348 1233 1349 /* Send the required number of replies */ 1234 send_trans2_replies(conn, req, params, 30, *ppdata, 0, max_data_bytes);1350 send_trans2_replies(conn, req, NT_STATUS_OK, params, 30, *ppdata, 0, max_data_bytes); 1235 1351 out: 1236 1352 TALLOC_FREE(smb_fname); … … 1260 1376 return strcmp(str,mask)==0; 1261 1377 } else { 1262 return StrCaseCmp(str,mask) == 0;1378 return strcasecmp_m(str,mask) == 0; 1263 1379 } 1264 1380 } … … 1268 1384 ****************************************************************************/ 1269 1385 1270 static uint32 unix_filetype(mode_t mode)1386 static uint32_t unix_filetype(mode_t mode) 1271 1387 { 1272 1388 if(S_ISREG(mode)) … … 1307 1423 static NTSTATUS unix_perms_from_wire( connection_struct *conn, 1308 1424 const SMB_STRUCT_STAT *psbuf, 1309 uint32 perms,1425 uint32_t perms, 1310 1426 enum perm_type ptype, 1311 1427 mode_t *ret_perms) … … 1341 1457 #endif 1342 1458 1343 switch (ptype) { 1344 case PERM_NEW_FILE: 1345 /* Apply mode mask */ 1459 if (ptype == PERM_NEW_FILE) { 1460 /* 1461 * "create mask"/"force create mode" are 1462 * only applied to new files, not existing ones. 1463 */ 1346 1464 ret &= lp_create_mask(SNUM(conn)); 1347 1465 /* Add in force bits */ 1348 1466 ret |= lp_force_create_mode(SNUM(conn)); 1349 break; 1350 case PERM_NEW_DIR: 1351 ret &= lp_dir_mask(SNUM(conn)); 1467 } else if (ptype == PERM_NEW_DIR) { 1468 /* 1469 * "directory mask"/"force directory mode" are 1470 * only applied to new directories, not existing ones. 1471 */ 1472 ret &= lp_directory_mask(SNUM(conn)); 1352 1473 /* Add in force bits */ 1353 ret |= lp_force_dir_mode(SNUM(conn)); 1354 break; 1355 case PERM_EXISTING_FILE: 1356 /* Apply mode mask */ 1357 ret &= lp_security_mask(SNUM(conn)); 1358 /* Add in force bits */ 1359 ret |= lp_force_security_mode(SNUM(conn)); 1360 break; 1361 case PERM_EXISTING_DIR: 1362 /* Apply mode mask */ 1363 ret &= lp_dir_security_mask(SNUM(conn)); 1364 /* Add in force bits */ 1365 ret |= lp_force_dir_security_mode(SNUM(conn)); 1366 break; 1474 ret |= lp_force_directory_mode(SNUM(conn)); 1367 1475 } 1368 1476 … … 1424 1532 /* Mangle fname if it's an illegal name. */ 1425 1533 if (mangle_must_mangle(dname, state->conn->params)) { 1534 /* 1535 * Slow path - ensure we can push the original name as UCS2. If 1536 * not, then just don't return this name. 1537 */ 1538 NTSTATUS status; 1539 size_t ret_len = 0; 1540 size_t len = (strlen(dname) + 2) * 4; /* Allow enough space. */ 1541 uint8_t *tmp = talloc_array(talloc_tos(), 1542 uint8_t, 1543 len); 1544 1545 status = srvstr_push(NULL, 1546 FLAGS2_UNICODE_STRINGS, 1547 tmp, 1548 dname, 1549 len, 1550 STR_TERMINATE, 1551 &ret_len); 1552 1553 TALLOC_FREE(tmp); 1554 1555 if (!NT_STATUS_IS_OK(status)) { 1556 return false; 1557 } 1558 1426 1559 ok = name_to_8_3(dname, mangled_name, 1427 1560 true, state->conn->params); … … 1525 1658 } 1526 1659 1527 static boolsmbd_marshall_dir_entry(TALLOC_CTX *ctx,1660 static NTSTATUS smbd_marshall_dir_entry(TALLOC_CTX *ctx, 1528 1661 connection_struct *conn, 1529 1662 uint16_t flags2, … … 1541 1674 char **ppdata, 1542 1675 char *end_data, 1543 bool *out_of_space,1544 1676 uint64_t *last_entry_off) 1545 1677 { … … 1549 1681 uint64_t allocation_size = 0; 1550 1682 uint64_t file_index = 0; 1551 uint32_t len; 1552 struct timespec mdate_ts, adate_ts, cdate_ts, create_date_ts; 1683 size_t len = 0; 1684 struct timespec mdate_ts = {0}; 1685 struct timespec adate_ts = {0}; 1686 struct timespec cdate_ts = {0}; 1687 struct timespec create_date_ts = {0}; 1553 1688 time_t mdate = (time_t)0, adate = (time_t)0, create_date = (time_t)0; 1554 time_t c_date = (time_t)0;1555 1689 char *nameptr; 1556 1690 char *last_entry_ptr; … … 1558 1692 int off; 1559 1693 int pad = 0; 1560 1561 *out_of_space = false; 1562 1563 ZERO_STRUCT(mdate_ts); 1564 ZERO_STRUCT(adate_ts); 1565 ZERO_STRUCT(create_date_ts); 1566 ZERO_STRUCT(cdate_ts); 1694 NTSTATUS status; 1695 struct readdir_attr_data *readdir_attr_data = NULL; 1567 1696 1568 1697 if (!(mode & FILE_ATTRIBUTE_DIRECTORY)) { … … 1570 1699 } 1571 1700 allocation_size = SMB_VFS_GET_ALLOC_SIZE(conn, NULL, &smb_fname->st); 1701 1702 status = SMB_VFS_READDIR_ATTR(conn, smb_fname, ctx, &readdir_attr_data); 1703 if (!NT_STATUS_IS_OK(status)) { 1704 if (!NT_STATUS_EQUAL(NT_STATUS_NOT_SUPPORTED, status)) { 1705 return status; 1706 } 1707 } 1572 1708 1573 1709 file_index = get_FileIndex(conn, &smb_fname->st); … … 1588 1724 mdate = convert_timespec_to_time_t(mdate_ts); 1589 1725 adate = convert_timespec_to_time_t(adate_ts); 1590 c_date = convert_timespec_to_time_t(cdate_ts);1591 1726 1592 1727 /* align the record */ … … 1598 1733 1599 1734 if (pad && pad > space_remaining) { 1600 *out_of_space = true;1601 1735 DEBUG(9,("smbd_marshall_dir_entry: out of space " 1602 1736 "for padding (wanted %u, had %d)\n", 1603 1737 (unsigned int)pad, 1604 1738 space_remaining )); 1605 return false; /* Not finished - just out of space */1739 return STATUS_MORE_ENTRIES; /* Not finished - just out of space */ 1606 1740 } 1607 1741 … … 1633 1767 srv_put_dos_date2(p,4,adate); 1634 1768 srv_put_dos_date2(p,8,mdate); 1635 SIVAL(p,12,(uint32 )file_size);1636 SIVAL(p,16,(uint32 )allocation_size);1769 SIVAL(p,12,(uint32_t)file_size); 1770 SIVAL(p,16,(uint32_t)allocation_size); 1637 1771 SSVAL(p,20,mode); 1638 1772 p += 23; … … 1641 1775 p += ucs2_align(base_data, p, 0); 1642 1776 } 1643 len= srvstr_push(base_data, flags2, p,1777 status = srvstr_push(base_data, flags2, p, 1644 1778 fname, PTR_DIFF(end_data, p), 1645 STR_TERMINATE); 1779 STR_TERMINATE, &len); 1780 if (!NT_STATUS_IS_OK(status)) { 1781 return status; 1782 } 1646 1783 if (flags2 & FLAGS2_UNICODE_STRINGS) { 1647 1784 if (len > 2) { … … 1669 1806 srv_put_dos_date2(p,4,adate); 1670 1807 srv_put_dos_date2(p,8,mdate); 1671 SIVAL(p,12,(uint32 )file_size);1672 SIVAL(p,16,(uint32 )allocation_size);1808 SIVAL(p,12,(uint32_t)file_size); 1809 SIVAL(p,16,(uint32_t)allocation_size); 1673 1810 SSVAL(p,20,mode); 1674 1811 { 1675 1812 unsigned int ea_size = estimate_ea_size(conn, NULL, 1676 smb_fname ->base_name);1813 smb_fname); 1677 1814 SIVAL(p,22,ea_size); /* Extended attributes */ 1678 1815 } 1679 1816 p += 27; 1680 1817 nameptr = p - 1; 1681 len= srvstr_push(base_data, flags2,1818 status = srvstr_push(base_data, flags2, 1682 1819 p, fname, PTR_DIFF(end_data, p), 1683 STR_TERMINATE | STR_NOALIGN); 1820 STR_TERMINATE | STR_NOALIGN, &len); 1821 if (!NT_STATUS_IS_OK(status)) { 1822 return status; 1823 } 1684 1824 if (flags2 & FLAGS2_UNICODE_STRINGS) { 1685 1825 if (len > 2) { … … 1707 1847 DEBUG(10,("smbd_marshall_dir_entry: SMB_FIND_EA_LIST\n")); 1708 1848 if (!name_list) { 1709 return false;1849 return NT_STATUS_INVALID_PARAMETER; 1710 1850 } 1711 1851 if (requires_resume_key) { … … 1716 1856 srv_put_dos_date2(p,4,adate); 1717 1857 srv_put_dos_date2(p,8,mdate); 1718 SIVAL(p,12,(uint32 )file_size);1719 SIVAL(p,16,(uint32 )allocation_size);1858 SIVAL(p,12,(uint32_t)file_size); 1859 SIVAL(p,16,(uint32_t)allocation_size); 1720 1860 SSVAL(p,20,mode); 1721 1861 p += 22; /* p now points to the EA area. */ 1722 1862 1723 file_list = get_ea_list_from_file(ctx, conn, NULL, 1724 smb_fname->base_name, 1725 &ea_len); 1863 status = get_ea_list_from_file(ctx, conn, NULL, 1864 smb_fname, 1865 &ea_len, &file_list); 1866 if (!NT_STATUS_IS_OK(status)) { 1867 file_list = NULL; 1868 } 1726 1869 name_list = ea_list_union(name_list, file_list, &ea_len); 1727 1870 … … 1729 1872 /* Max string size is 255 bytes. */ 1730 1873 if (PTR_DIFF(p + 255 + ea_len,pdata) > space_remaining) { 1731 *out_of_space = true;1732 1874 DEBUG(9,("smbd_marshall_dir_entry: out of space " 1733 1875 "(wanted %u, had %d)\n", 1734 1876 (unsigned int)PTR_DIFF(p + 255 + ea_len,pdata), 1735 1877 space_remaining )); 1736 return False; /* Not finished - just out of space */1878 return STATUS_MORE_ENTRIES; /* Not finished - just out of space */ 1737 1879 } 1738 1880 … … 1740 1882 p += fill_ea_buffer(ctx, p, space_remaining, conn, name_list); 1741 1883 nameptr = p; 1742 len= srvstr_push(base_data, flags2,1884 status = srvstr_push(base_data, flags2, 1743 1885 p + 1, fname, PTR_DIFF(end_data, p+1), 1744 STR_TERMINATE | STR_NOALIGN); 1886 STR_TERMINATE | STR_NOALIGN, &len); 1887 if (!NT_STATUS_IS_OK(status)) { 1888 return status; 1889 } 1745 1890 if (flags2 & FLAGS2_UNICODE_STRINGS) { 1746 1891 if (len > 2) { … … 1779 1924 } else { 1780 1925 unsigned int ea_size = estimate_ea_size(conn, NULL, 1781 smb_fname ->base_name);1926 smb_fname); 1782 1927 SIVAL(p,0,ea_size); /* Extended attributes */ 1783 1928 } … … 1795 1940 } 1796 1941 mangled_name[12] = 0; 1797 len= srvstr_push(base_data, flags2,1942 status = srvstr_push(base_data, flags2, 1798 1943 p+2, mangled_name, 24, 1799 STR_UPPER|STR_UNICODE); 1944 STR_UPPER|STR_UNICODE, &len); 1945 if (!NT_STATUS_IS_OK(status)) { 1946 return status; 1947 } 1800 1948 if (len < 24) { 1801 1949 memset(p + 2 + len,'\0',24 - len); … … 1806 1954 } 1807 1955 p += 2 + 24; 1808 len= srvstr_push(base_data, flags2, p,1956 status = srvstr_push(base_data, flags2, p, 1809 1957 fname, PTR_DIFF(end_data, p), 1810 STR_TERMINATE_ASCII); 1958 STR_TERMINATE_ASCII, &len); 1959 if (!NT_STATUS_IS_OK(status)) { 1960 return status; 1961 } 1811 1962 SIVAL(q,0,len); 1812 1963 p += len; … … 1842 1993 SOFF_T(p,0,allocation_size); p += 8; 1843 1994 SIVAL(p,0,mode); p += 4; 1844 len= srvstr_push(base_data, flags2,1995 status = srvstr_push(base_data, flags2, 1845 1996 p + 4, fname, PTR_DIFF(end_data, p+4), 1846 STR_TERMINATE_ASCII); 1997 STR_TERMINATE_ASCII, &len); 1998 if (!NT_STATUS_IS_OK(status)) { 1999 return status; 2000 } 1847 2001 SIVAL(p,0,len); 1848 2002 p += 4 + len; … … 1881 2035 { 1882 2036 unsigned int ea_size = estimate_ea_size(conn, NULL, 1883 smb_fname ->base_name);2037 smb_fname); 1884 2038 SIVAL(p,0,ea_size); /* Extended attributes */ 1885 2039 p +=4; 1886 2040 } 1887 len= srvstr_push(base_data, flags2, p,2041 status = srvstr_push(base_data, flags2, p, 1888 2042 fname, PTR_DIFF(end_data, p), 1889 STR_TERMINATE_ASCII); 2043 STR_TERMINATE_ASCII, &len); 2044 if (!NT_STATUS_IS_OK(status)) { 2045 return status; 2046 } 1890 2047 SIVAL(q, 0, len); 1891 2048 p += len; … … 1917 2074 /* this must *not* be null terminated or w2k gets in a loop trying to set an 1918 2075 acl on a dir (tridge) */ 1919 len= srvstr_push(base_data, flags2, p,2076 status = srvstr_push(base_data, flags2, p, 1920 2077 fname, PTR_DIFF(end_data, p), 1921 STR_TERMINATE_ASCII); 2078 STR_TERMINATE_ASCII, &len); 2079 if (!NT_STATUS_IS_OK(status)) { 2080 return status; 2081 } 1922 2082 SIVAL(p, -4, len); 1923 2083 p += len; … … 1958 2118 } else { 1959 2119 unsigned int ea_size = estimate_ea_size(conn, NULL, 1960 smb_fname ->base_name);2120 smb_fname); 1961 2121 SIVAL(p,0,ea_size); /* Extended attributes */ 1962 2122 } 1963 p += 4;2123 p += 4; 1964 2124 SIVAL(p,0,0); p += 4; /* Unknown - reserved ? */ 1965 2125 SBVAL(p,0,file_index); p += 8; 1966 len= srvstr_push(base_data, flags2, p,2126 status = srvstr_push(base_data, flags2, p, 1967 2127 fname, PTR_DIFF(end_data, p), 1968 STR_TERMINATE_ASCII); 2128 STR_TERMINATE_ASCII, &len); 2129 if (!NT_STATUS_IS_OK(status)) { 2130 return status; 2131 } 1969 2132 SIVAL(q, 0, len); 1970 2133 p += len; … … 2004 2167 if (mode & FILE_ATTRIBUTE_REPARSE_POINT) { 2005 2168 SIVAL(p, 0, IO_REPARSE_TAG_DFS); 2169 } else if (readdir_attr_data && 2170 readdir_attr_data->type == RDATTR_AAPL) { 2171 /* 2172 * OS X specific SMB2 extension negotiated via 2173 * AAPL create context: return max_access in 2174 * ea_size field. 2175 */ 2176 SIVAL(p, 0, readdir_attr_data->attr_data.aapl.max_access); 2006 2177 } else { 2007 2178 unsigned int ea_size = estimate_ea_size(conn, NULL, 2008 smb_fname ->base_name);2179 smb_fname); 2009 2180 SIVAL(p,0,ea_size); /* Extended attributes */ 2010 2181 } 2011 p +=4; 2012 /* Clear the short name buffer. This is 2013 * IMPORTANT as not doing so will trigger 2014 * a Win2k client bug. JRA. 2015 */ 2016 if (!was_8_3 && check_mangled_names) { 2182 p += 4; 2183 2184 if (readdir_attr_data && 2185 readdir_attr_data->type == RDATTR_AAPL) { 2186 /* 2187 * OS X specific SMB2 extension negotiated via 2188 * AAPL create context: return resource fork 2189 * length and compressed FinderInfo in 2190 * shortname field. 2191 * 2192 * According to documentation short_name_len 2193 * should be 0, but on the wire behaviour 2194 * shows its set to 24 by clients. 2195 */ 2196 SSVAL(p, 0, 24); 2197 2198 /* Resourefork length */ 2199 SBVAL(p, 2, readdir_attr_data->attr_data.aapl.rfork_size); 2200 2201 /* Compressed FinderInfo */ 2202 memcpy(p + 10, &readdir_attr_data->attr_data.aapl.finder_info, 16); 2203 } else if (!was_8_3 && check_mangled_names) { 2017 2204 char mangled_name[13]; /* mangled 8.3 name. */ 2018 2205 if (!name_to_8_3(fname,mangled_name,True, … … 2022 2209 } 2023 2210 mangled_name[12] = 0; 2024 len= srvstr_push(base_data, flags2,2211 status = srvstr_push(base_data, flags2, 2025 2212 p+2, mangled_name, 24, 2026 STR_UPPER|STR_UNICODE); 2213 STR_UPPER|STR_UNICODE, &len); 2214 if (!NT_STATUS_IS_OK(status)) { 2215 return status; 2216 } 2027 2217 SSVAL(p, 0, len); 2028 2218 if (len < 24) { … … 2031 2221 SSVAL(p, 0, len); 2032 2222 } else { 2223 /* Clear the short name buffer. This is 2224 * IMPORTANT as not doing so will trigger 2225 * a Win2k client bug. JRA. 2226 */ 2033 2227 memset(p,'\0',26); 2034 2228 } 2035 2229 p += 26; 2036 SSVAL(p,0,0); p += 2; /* Reserved ? */ 2230 2231 /* Reserved ? */ 2232 if (readdir_attr_data && 2233 readdir_attr_data->type == RDATTR_AAPL) { 2234 /* 2235 * OS X specific SMB2 extension negotiated via 2236 * AAPL create context: return UNIX mode in 2237 * reserved field. 2238 */ 2239 uint16_t aapl_mode = (uint16_t)readdir_attr_data->attr_data.aapl.unix_mode; 2240 SSVAL(p, 0, aapl_mode); 2241 } else { 2242 SSVAL(p, 0, 0); 2243 } 2244 p += 2; 2245 2037 2246 SBVAL(p,0,file_index); p += 8; 2038 len= srvstr_push(base_data, flags2, p,2247 status = srvstr_push(base_data, flags2, p, 2039 2248 fname, PTR_DIFF(end_data, p), 2040 STR_TERMINATE_ASCII); 2249 STR_TERMINATE_ASCII, &len); 2250 if (!NT_STATUS_IS_OK(status)) { 2251 return status; 2252 } 2041 2253 SIVAL(q,0,len); 2042 2254 p += len; … … 2074 2286 p = store_file_unix_basic(conn, p, 2075 2287 NULL, &smb_fname->st); 2076 len= srvstr_push(base_data, flags2, p,2288 status = srvstr_push(base_data, flags2, p, 2077 2289 fname, PTR_DIFF(end_data, p), 2078 STR_TERMINATE); 2290 STR_TERMINATE, &len); 2291 if (!NT_STATUS_IS_OK(status)) { 2292 return status; 2293 } 2079 2294 } else { 2080 2295 DEBUG(10,("smbd_marshall_dir_entry: SMB_FIND_FILE_UNIX_INFO2\n")); … … 2083 2298 nameptr = p; 2084 2299 p += 4; 2085 len = srvstr_push(base_data, flags2, p, fname, 2086 PTR_DIFF(end_data, p), 0); 2300 status = srvstr_push(base_data, flags2, p, fname, 2301 PTR_DIFF(end_data, p), 0, &len); 2302 if (!NT_STATUS_IS_OK(status)) { 2303 return status; 2304 } 2087 2305 SIVAL(nameptr, 0, len); 2088 2306 } … … 2112 2330 2113 2331 default: 2114 return false;2332 return NT_STATUS_INVALID_LEVEL; 2115 2333 } 2116 2334 2117 2335 if (PTR_DIFF(p,pdata) > space_remaining) { 2118 *out_of_space = true;2119 2336 DEBUG(9,("smbd_marshall_dir_entry: out of space " 2120 2337 "(wanted %u, had %d)\n", 2121 2338 (unsigned int)PTR_DIFF(p,pdata), 2122 2339 space_remaining )); 2123 return false; /* Not finished - just out of space */2340 return STATUS_MORE_ENTRIES; /* Not finished - just out of space */ 2124 2341 } 2125 2342 … … 2129 2346 *ppdata = p; 2130 2347 2131 return true;2348 return NT_STATUS_OK; 2132 2349 } 2133 2350 2134 boolsmbd_dirptr_lanman2_entry(TALLOC_CTX *ctx,2351 NTSTATUS smbd_dirptr_lanman2_entry(TALLOC_CTX *ctx, 2135 2352 connection_struct *conn, 2136 2353 struct dptr_struct *dirptr, 2137 uint16 flags2,2354 uint16_t flags2, 2138 2355 const char *path_mask, 2139 uint32 dirtype,2356 uint32_t dirtype, 2140 2357 int info_level, 2141 2358 int requires_resume_key, … … 2148 2365 char *end_data, 2149 2366 int space_remaining, 2150 bool *out_of_space,2151 2367 bool *got_exact_match, 2152 2368 int *_last_entry_off, … … 2162 2378 bool ok; 2163 2379 uint64_t last_entry_off = 0; 2380 NTSTATUS status; 2164 2381 2165 2382 ZERO_STRUCT(state); 2166 2383 state.conn = conn; 2167 2384 state.info_level = info_level; 2168 state.check_mangled_names = lp_mangled names(conn->params);2385 state.check_mangled_names = lp_mangled_names(conn->params); 2169 2386 state.has_wild = dptr_has_wild(dirptr); 2170 2387 state.got_exact_match = false; 2171 2388 2172 *out_of_space = false;2173 2389 *got_exact_match = false; 2174 2390 … … 2198 2414 &prev_dirpos); 2199 2415 if (!ok) { 2200 return false;2416 return NT_STATUS_END_OF_FILE; 2201 2417 } 2202 2418 2203 2419 *got_exact_match = state.got_exact_match; 2204 2420 2205 ok= smbd_marshall_dir_entry(ctx,2421 status = smbd_marshall_dir_entry(ctx, 2206 2422 conn, 2207 2423 flags2, … … 2219 2435 ppdata, 2220 2436 end_data, 2221 out_of_space,2222 2437 &last_entry_off); 2438 if (NT_STATUS_EQUAL(status, NT_STATUS_ILLEGAL_CHARACTER)) { 2439 DEBUG(1,("Conversion error: illegal character: %s\n", 2440 smb_fname_str_dbg(smb_fname))); 2441 } 2223 2442 TALLOC_FREE(fname); 2224 2443 TALLOC_FREE(smb_fname); 2225 if ( *out_of_space) {2444 if (NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES)) { 2226 2445 dptr_SeekDir(dirptr, prev_dirpos); 2227 return false;2228 } 2229 if (! ok) {2230 return false;2446 return status; 2447 } 2448 if (!NT_STATUS_IS_OK(status)) { 2449 return status; 2231 2450 } 2232 2451 2233 2452 *_last_entry_off = last_entry_off; 2234 return true;2453 return NT_STATUS_OK; 2235 2454 } 2236 2455 2237 static boolget_lanman2_dir_entry(TALLOC_CTX *ctx,2456 static NTSTATUS get_lanman2_dir_entry(TALLOC_CTX *ctx, 2238 2457 connection_struct *conn, 2239 2458 struct dptr_struct *dirptr, 2240 uint16 flags2,2459 uint16_t flags2, 2241 2460 const char *path_mask, 2242 uint32 dirtype,2461 uint32_t dirtype, 2243 2462 int info_level, 2244 2463 bool requires_resume_key, … … 2249 2468 char *end_data, 2250 2469 int space_remaining, 2251 bool *out_of_space,2252 2470 bool *got_exact_match, 2253 2471 int *last_entry_off, … … 2268 2486 ppdata, base_data, end_data, 2269 2487 space_remaining, 2270 out_of_space,got_exact_match,2488 got_exact_match, 2271 2489 last_entry_off, name_list); 2272 2490 } … … 2291 2509 char *pdata = *ppdata; 2292 2510 char *data_end; 2293 uint32 dirtype;2511 uint32_t dirtype; 2294 2512 int maxentries; 2295 uint16 findfirst_flags;2513 uint16_t findfirst_flags; 2296 2514 bool close_after_first; 2297 2515 bool close_if_end; … … 2316 2534 struct dptr_struct *dirptr = NULL; 2317 2535 struct smbd_server_connection *sconn = req->sconn; 2318 uint32_t ucf_flags = (UCF_SAVE_LCOMP | UCF_ALWAYS_ALLOW_WCARD_LCOMP); 2536 uint32_t ucf_flags = UCF_SAVE_LCOMP | UCF_ALWAYS_ALLOW_WCARD_LCOMP | 2537 (req->posix_pathnames ? UCF_POSIX_PATHNAMES : 0); 2538 bool backup_priv = false; 2539 bool as_root = false; 2319 2540 2320 2541 if (total_params < 13) { … … 2329 2550 close_if_end = (findfirst_flags & FLAG_TRANS2_FIND_CLOSE_IF_END); 2330 2551 requires_resume_key = (findfirst_flags & FLAG_TRANS2_FIND_REQUIRE_RESUME); 2552 backup_priv = ((findfirst_flags & FLAG_TRANS2_FIND_BACKUP_INTENT) && 2553 security_token_has_privilege(get_current_nttok(conn), 2554 SEC_PRIV_BACKUP)); 2555 2331 2556 info_level = SVAL(params,6); 2332 2557 2333 2558 DEBUG(3,("call_trans2findfirst: dirtype = %x, maxentries = %d, close_after_first=%d, \ 2334 close_if_end = %d requires_resume_key = %d level = 0x%x, max_data_bytes = %d\n",2559 close_if_end = %d requires_resume_key = %d backup_priv = %d level = 0x%x, max_data_bytes = %d\n", 2335 2560 (unsigned int)dirtype, maxentries, close_after_first, close_if_end, requires_resume_key, 2561 (int)backup_priv, 2336 2562 info_level, max_data_bytes)); 2337 2563 … … 2367 2593 } 2368 2594 2369 srvstr_get_path_wcard(ctx, params, req->flags2, &directory, 2370 params+12, total_params - 12, 2371 STR_TERMINATE, &ntstatus, &mask_contains_wcard); 2595 if (req->posix_pathnames) { 2596 srvstr_get_path_wcard_posix(ctx, 2597 params, 2598 req->flags2, 2599 &directory, 2600 params+12, 2601 total_params - 12, 2602 STR_TERMINATE, 2603 &ntstatus, 2604 &mask_contains_wcard); 2605 } else { 2606 srvstr_get_path_wcard(ctx, 2607 params, 2608 req->flags2, 2609 &directory, 2610 params+12, 2611 total_params - 12, 2612 STR_TERMINATE, 2613 &ntstatus, 2614 &mask_contains_wcard); 2615 } 2372 2616 if (!NT_STATUS_IS_OK(ntstatus)) { 2373 2617 reply_nterror(req, ntstatus); … … 2375 2619 } 2376 2620 2377 ntstatus = filename_convert(ctx, conn, 2621 if (backup_priv) { 2622 become_root(); 2623 as_root = true; 2624 ntstatus = filename_convert_with_privilege(ctx, 2625 conn, 2626 req, 2627 directory, 2628 ucf_flags, 2629 &mask_contains_wcard, 2630 &smb_dname); 2631 } else { 2632 ntstatus = filename_convert(ctx, conn, 2378 2633 req->flags2 & FLAGS2_DFS_PATHNAMES, 2379 2634 directory, … … 2381 2636 &mask_contains_wcard, 2382 2637 &smb_dname); 2638 } 2639 2383 2640 if (!NT_STATUS_IS_OK(ntstatus)) { 2384 2641 if (NT_STATUS_EQUAL(ntstatus,NT_STATUS_PATH_NOT_COVERED)) { … … 2422 2679 2423 2680 if (info_level == SMB_FIND_EA_LIST) { 2424 uint32 ea_size;2681 uint32_t ea_size; 2425 2682 2426 2683 if (total_data < 4) { … … 2450 2707 } 2451 2708 2709 if (max_data_bytes + DIR_ENTRY_SAFETY_MARGIN < max_data_bytes) { 2710 reply_nterror(req, NT_STATUS_INVALID_PARAMETER); 2711 goto out; 2712 } 2713 2452 2714 *ppdata = (char *)SMB_REALLOC( 2453 2715 *ppdata, max_data_bytes + DIR_ENTRY_SAFETY_MARGIN); … … 2458 2720 pdata = *ppdata; 2459 2721 data_end = pdata + max_data_bytes + DIR_ENTRY_SAFETY_MARGIN - 1; 2460 2722 /* 2723 * squash valgrind "writev(vector[...]) points to uninitialised byte(s)" 2724 * error. 2725 */ 2726 memset(pdata + total_data, 0, ((max_data_bytes + DIR_ENTRY_SAFETY_MARGIN) - total_data)); 2461 2727 /* Realloc the params space */ 2462 2728 *pparams = (char *)SMB_REALLOC(*pparams, 10); … … 2471 2737 2472 2738 ntstatus = dptr_create(conn, 2739 req, 2473 2740 NULL, /* fsp */ 2474 2741 directory, … … 2486 2753 } 2487 2754 2755 if (backup_priv) { 2756 /* Remember this in case we have 2757 to do a findnext. */ 2758 dptr_set_priv(dirptr); 2759 } 2760 2488 2761 dptr_num = dptr_dnum(dirptr); 2489 2762 DEBUG(4,("dptr_num is %d, wcard = %s, attr = %d\n", dptr_num, mask, dirtype)); … … 2496 2769 2497 2770 DEBUG(8,("dirpath=<%s> dontdescend=<%s>\n", 2498 directory,lp_dontdescend(SNUM(conn))));2499 if (in_list(directory,lp_dont descend(SNUM(conn)),conn->case_sensitive))2771 directory,lp_dont_descend(ctx, SNUM(conn)))); 2772 if (in_list(directory,lp_dont_descend(ctx, SNUM(conn)),conn->case_sensitive)) 2500 2773 dont_descend = True; 2501 2774 … … 2513 2786 finished = False; 2514 2787 } else { 2515 finished = !get_lanman2_dir_entry(ctx,2788 ntstatus = get_lanman2_dir_entry(ctx, 2516 2789 conn, 2517 2790 dirptr, … … 2521 2794 ask_sharemode, 2522 2795 &p,pdata,data_end, 2523 space_remaining, &out_of_space,2796 space_remaining, 2524 2797 &got_exact_match, 2525 2798 &last_entry_off, ea_list); 2526 } 2527 2528 if (finished && out_of_space) 2529 finished = False; 2799 if (NT_STATUS_EQUAL(ntstatus, 2800 NT_STATUS_ILLEGAL_CHARACTER)) { 2801 /* 2802 * Bad character conversion on name. Ignore this 2803 * entry. 2804 */ 2805 continue; 2806 } 2807 if (NT_STATUS_EQUAL(ntstatus, STATUS_MORE_ENTRIES)) { 2808 out_of_space = true; 2809 } else { 2810 finished = !NT_STATUS_IS_OK(ntstatus); 2811 } 2812 } 2530 2813 2531 2814 if (!finished && !out_of_space) … … 2585 2868 SSVAL(params,8,last_entry_off); 2586 2869 2587 send_trans2_replies(conn, req, params, 10, pdata, PTR_DIFF(p,pdata),2870 send_trans2_replies(conn, req, NT_STATUS_OK, params, 10, pdata, PTR_DIFF(p,pdata), 2588 2871 max_data_bytes); 2589 2872 … … 2612 2895 } 2613 2896 out: 2897 2898 if (as_root) { 2899 unbecome_root(); 2900 } 2901 2614 2902 TALLOC_FREE(smb_dname); 2615 2903 return; … … 2636 2924 int dptr_num; 2637 2925 int maxentries; 2638 uint16 info_level;2639 uint32 resume_key;2640 uint16 findnext_flags;2926 uint16_t info_level; 2927 uint32_t resume_key; 2928 uint16_t findnext_flags; 2641 2929 bool close_after_request; 2642 2930 bool close_if_end; … … 2648 2936 const char *directory = NULL; 2649 2937 char *p = NULL; 2650 uint16 dirtype;2938 uint16_t dirtype; 2651 2939 int numentries = 0; 2652 2940 int i, last_entry_off=0; … … 2661 2949 struct dptr_struct *dirptr; 2662 2950 struct smbd_server_connection *sconn = req->sconn; 2951 bool backup_priv = false; 2952 bool as_root = false; 2663 2953 2664 2954 if (total_params < 13) { … … 2679 2969 if (!continue_bit) { 2680 2970 /* We only need resume_name if continue_bit is zero. */ 2681 srvstr_get_path_wcard(ctx, params, req->flags2, &resume_name, 2682 params+12, 2683 total_params - 12, STR_TERMINATE, &ntstatus, 2684 &mask_contains_wcard); 2971 if (req->posix_pathnames) { 2972 srvstr_get_path_wcard_posix(ctx, 2973 params, 2974 req->flags2, 2975 &resume_name, 2976 params+12, 2977 total_params - 12, 2978 STR_TERMINATE, 2979 &ntstatus, 2980 &mask_contains_wcard); 2981 } else { 2982 srvstr_get_path_wcard(ctx, 2983 params, 2984 req->flags2, 2985 &resume_name, 2986 params+12, 2987 total_params - 12, 2988 STR_TERMINATE, 2989 &ntstatus, 2990 &mask_contains_wcard); 2991 } 2685 2992 if (!NT_STATUS_IS_OK(ntstatus)) { 2686 2993 /* Win9x or OS/2 can send a resume name of ".." or ".". This will cause the parser to … … 2738 3045 2739 3046 if (info_level == SMB_FIND_EA_LIST) { 2740 uint32 ea_size;3047 uint32_t ea_size; 2741 3048 2742 3049 if (total_data < 4) { … … 2766 3073 } 2767 3074 3075 if (max_data_bytes + DIR_ENTRY_SAFETY_MARGIN < max_data_bytes) { 3076 reply_nterror(req, NT_STATUS_INVALID_PARAMETER); 3077 return; 3078 } 3079 2768 3080 *ppdata = (char *)SMB_REALLOC( 2769 3081 *ppdata, max_data_bytes + DIR_ENTRY_SAFETY_MARGIN); … … 2776 3088 data_end = pdata + max_data_bytes + DIR_ENTRY_SAFETY_MARGIN - 1; 2777 3089 3090 /* 3091 * squash valgrind "writev(vector[...]) points to uninitialised byte(s)" 3092 * error. 3093 */ 3094 memset(pdata + total_data, 0, (max_data_bytes + DIR_ENTRY_SAFETY_MARGIN) - total_data); 2778 3095 /* Realloc the params space */ 2779 3096 *pparams = (char *)SMB_REALLOC(*pparams, 6*SIZEOFWORD); … … 2794 3111 2795 3112 /* Get the wildcard mask from the dptr */ 2796 if(( p= dptr_wcard(sconn, dptr_num))== NULL) {3113 if((mask = dptr_wcard(sconn, dptr_num))== NULL) { 2797 3114 DEBUG(2,("dptr_num %d has no wildcard\n", dptr_num)); 2798 3115 reply_nterror(req, STATUS_NO_MORE_FILES); … … 2800 3117 } 2801 3118 2802 mask = p;2803 2804 3119 /* Get the attr mask from the dptr */ 2805 3120 dirtype = dptr_attr(sconn, dptr_num); 2806 3121 2807 DEBUG(3,("dptr_num is %d, mask = %s, attr = %x, dirptr=(0x%lX,%ld)\n", 3122 backup_priv = dptr_get_priv(dirptr); 3123 3124 DEBUG(3,("dptr_num is %d, mask = %s, attr = %x, dirptr=(0x%lX,%ld) " 3125 "backup_priv = %d\n", 2808 3126 dptr_num, mask, dirtype, 2809 3127 (long)dirptr, 2810 dptr_TellDir(dirptr))); 3128 dptr_TellDir(dirptr), 3129 (int)backup_priv)); 2811 3130 2812 3131 /* Initialize per TRANS2_FIND_NEXT operation data */ … … 2817 3136 2818 3137 DEBUG(8,("dirpath=<%s> dontdescend=<%s>\n", 2819 directory,lp_dont descend(SNUM(conn))));2820 if (in_list(directory,lp_dont descend(SNUM(conn)),conn->case_sensitive))3138 directory,lp_dont_descend(ctx, SNUM(conn)))); 3139 if (in_list(directory,lp_dont_descend(ctx, SNUM(conn)),conn->case_sensitive)) 2821 3140 dont_descend = True; 2822 3141 … … 2824 3143 space_remaining = max_data_bytes; 2825 3144 out_of_space = False; 3145 3146 if (backup_priv) { 3147 become_root(); 3148 as_root = true; 3149 } 2826 3150 2827 3151 /* … … 2872 3196 finished = False; 2873 3197 } else { 2874 finished = !get_lanman2_dir_entry(ctx,3198 ntstatus = get_lanman2_dir_entry(ctx, 2875 3199 conn, 2876 3200 dirptr, … … 2880 3204 ask_sharemode, 2881 3205 &p,pdata,data_end, 2882 space_remaining, &out_of_space,3206 space_remaining, 2883 3207 &got_exact_match, 2884 3208 &last_entry_off, ea_list); 2885 } 2886 2887 if (finished && out_of_space) 2888 finished = False; 3209 if (NT_STATUS_EQUAL(ntstatus, 3210 NT_STATUS_ILLEGAL_CHARACTER)) { 3211 /* 3212 * Bad character conversion on name. Ignore this 3213 * entry. 3214 */ 3215 continue; 3216 } 3217 if (NT_STATUS_EQUAL(ntstatus, STATUS_MORE_ENTRIES)) { 3218 out_of_space = true; 3219 } else { 3220 finished = !NT_STATUS_IS_OK(ntstatus); 3221 } 3222 } 2889 3223 2890 3224 if (!finished && !out_of_space) … … 2914 3248 } 2915 3249 3250 if (as_root) { 3251 unbecome_root(); 3252 } 3253 2916 3254 /* Set up the return parameter block */ 2917 3255 SSVAL(params,0,numentries); … … 2920 3258 SSVAL(params,6,last_entry_off); 2921 3259 2922 send_trans2_replies(conn, req, params, 8, pdata, PTR_DIFF(p,pdata),3260 send_trans2_replies(conn, req, NT_STATUS_OK, params, 8, pdata, PTR_DIFF(p,pdata), 2923 3261 max_data_bytes); 2924 3262 … … 2928 3266 unsigned char *create_volume_objectid(connection_struct *conn, unsigned char objid[16]) 2929 3267 { 2930 E_md4hash(lp_servicename( SNUM(conn)),objid);3268 E_md4hash(lp_servicename(talloc_tos(), SNUM(conn)),objid); 2931 3269 return objid; 2932 3270 } … … 2967 3305 } 2968 3306 2969 NTSTATUS smbd_do_qfsinfo(connection_struct *conn, 3307 NTSTATUS smbd_do_qfsinfo(struct smbXsrv_connection *xconn, 3308 connection_struct *conn, 2970 3309 TALLOC_CTX *mem_ctx, 2971 3310 uint16_t info_level, … … 2978 3317 { 2979 3318 char *pdata, *end_data; 2980 int data_len = 0, len; 2981 const char *vname = volume_label(SNUM(conn)); 3319 int data_len = 0; 3320 size_t len = 0; 3321 const char *vname = volume_label(talloc_tos(), SNUM(conn)); 2982 3322 int snum = SNUM(conn); 2983 c har *fstype = lp_fstype(SNUM(conn));3323 const char *fstype = lp_fstype(SNUM(conn)); 2984 3324 const char *filename = NULL; 2985 uint32 additional_flags = 0; 3325 const uint64_t bytes_per_sector = 512; 3326 uint32_t additional_flags = 0; 2986 3327 struct smb_filename smb_fname; 2987 3328 SMB_STRUCT_STAT st; 2988 3329 NTSTATUS status = NT_STATUS_OK; 3330 uint64_t df_ret; 2989 3331 2990 3332 if (fname == NULL || fname->base_name == NULL) { … … 3015 3357 st = smb_fname.st; 3016 3358 3359 if (max_data_bytes + DIR_ENTRY_SAFETY_MARGIN < max_data_bytes) { 3360 return NT_STATUS_INVALID_PARAMETER; 3361 } 3362 3017 3363 *ppdata = (char *)SMB_REALLOC( 3018 3364 *ppdata, max_data_bytes + DIR_ENTRY_SAFETY_MARGIN); … … 3030 3376 case SMB_INFO_ALLOCATION: 3031 3377 { 3032 uint64_t dfree,dsize,bsize,block_size,sectors_per_unit ,bytes_per_sector;3378 uint64_t dfree,dsize,bsize,block_size,sectors_per_unit; 3033 3379 data_len = 18; 3034 if (get_dfree_info(conn,filename,False,&bsize,&dfree,&dsize) == (uint64_t)-1) { 3380 df_ret = get_dfree_info(conn, filename, &bsize, &dfree, 3381 &dsize); 3382 if (df_ret == (uint64_t)-1) { 3035 3383 return map_nt_error_from_unix(errno); 3036 3384 } … … 3049 3397 dfree *= factor; 3050 3398 } 3051 bytes_per_sector = 512;3052 3399 sectors_per_unit = bsize/bytes_per_sector; 3053 3400 … … 3070 3417 * the called hostname and the service name. 3071 3418 */ 3072 SIVAL(pdata,0,str_checksum(lp_servicename( snum)) ^ (str_checksum(get_local_machine_name())<<16) );3419 SIVAL(pdata,0,str_checksum(lp_servicename(talloc_tos(), snum)) ^ (str_checksum(get_local_machine_name())<<16) ); 3073 3420 /* 3074 3421 * Win2k3 and previous mess this up by sending a name length … … 3077 3424 * the pushed string. The change here was adding the STR_TERMINATE. JRA. 3078 3425 */ 3079 len= srvstr_push(3426 status = srvstr_push( 3080 3427 pdata, flags2, 3081 3428 pdata+l2_vol_szVolLabel, vname, 3082 3429 PTR_DIFF(end_data, pdata+l2_vol_szVolLabel), 3083 STR_NOALIGN|STR_TERMINATE); 3430 STR_NOALIGN|STR_TERMINATE, &len); 3431 if (!NT_STATUS_IS_OK(status)) { 3432 return status; 3433 } 3084 3434 SCVAL(pdata,l2_vol_cch,len); 3085 3435 data_len = l2_vol_szVolLabel + len; 3086 DEBUG(5,("smbd_do_qfsinfo : time = %x, namelen = % d, name = %s\n",3436 DEBUG(5,("smbd_do_qfsinfo : time = %x, namelen = %u, name = %s\n", 3087 3437 (unsigned)convert_timespec_to_time_t(st.st_ex_ctime), 3088 len, vname));3438 (unsigned)len, vname)); 3089 3439 break; 3090 3440 … … 3114 3464 /* NOTE! the fstype must *not* be null terminated or win98 won't recognise it 3115 3465 and will think we can't do long filenames */ 3116 len= srvstr_push(pdata, flags2, pdata+12, fstype,3466 status = srvstr_push(pdata, flags2, pdata+12, fstype, 3117 3467 PTR_DIFF(end_data, pdata+12), 3118 STR_UNICODE); 3468 STR_UNICODE, &len); 3469 if (!NT_STATUS_IS_OK(status)) { 3470 return status; 3471 } 3119 3472 SIVAL(pdata,8,len); 3120 3473 data_len = 12 + len; … … 3130 3483 case SMB_QUERY_FS_LABEL_INFO: 3131 3484 case SMB_FS_LABEL_INFORMATION: 3132 len = srvstr_push(pdata, flags2, pdata+4, vname, 3133 PTR_DIFF(end_data, pdata+4), 0); 3485 status = srvstr_push(pdata, flags2, pdata+4, vname, 3486 PTR_DIFF(end_data, pdata+4), 0, &len); 3487 if (!NT_STATUS_IS_OK(status)) { 3488 return status; 3489 } 3134 3490 data_len = 4 + len; 3135 3491 SIVAL(pdata,0,len); … … 3143 3499 * the called hostname and the service name. 3144 3500 */ 3145 SIVAL(pdata,8,str_checksum(lp_servicename( snum)) ^3501 SIVAL(pdata,8,str_checksum(lp_servicename(talloc_tos(), snum)) ^ 3146 3502 (str_checksum(get_local_machine_name())<<16)); 3147 3503 3148 3504 /* Max label len is 32 characters. */ 3149 len= srvstr_push(pdata, flags2, pdata+18, vname,3505 status = srvstr_push(pdata, flags2, pdata+18, vname, 3150 3506 PTR_DIFF(end_data, pdata+18), 3151 STR_UNICODE); 3507 STR_UNICODE, &len); 3508 if (!NT_STATUS_IS_OK(status)) { 3509 return status; 3510 } 3152 3511 SIVAL(pdata,12,len); 3153 3512 data_len = 18+len; 3154 3513 3155 3514 DEBUG(5,("smbd_do_qfsinfo : SMB_QUERY_FS_VOLUME_INFO namelen = %d, vol=%s serv=%s\n", 3156 (int)strlen(vname),vname, lp_servicename(snum))); 3515 (int)strlen(vname),vname, 3516 lp_servicename(talloc_tos(), snum))); 3157 3517 if (max_data_bytes >= 24 && data_len > max_data_bytes) { 3158 3518 /* the client only requested a portion of the … … 3161 3521 status = STATUS_BUFFER_OVERFLOW; 3162 3522 } 3163 3523 *fixed_portion = 24; 3164 3524 break; 3165 3525 … … 3167 3527 case SMB_FS_SIZE_INFORMATION: 3168 3528 { 3169 uint64_t dfree,dsize,bsize,block_size,sectors_per_unit ,bytes_per_sector;3529 uint64_t dfree,dsize,bsize,block_size,sectors_per_unit; 3170 3530 data_len = 24; 3171 if (get_dfree_info(conn,filename,False,&bsize,&dfree,&dsize) == (uint64_t)-1) { 3531 df_ret = get_dfree_info(conn, filename, &bsize, &dfree, 3532 &dsize); 3533 if (df_ret == (uint64_t)-1) { 3172 3534 return map_nt_error_from_unix(errno); 3173 3535 } … … 3185 3547 dfree *= factor; 3186 3548 } 3187 bytes_per_sector = 512;3188 3549 sectors_per_unit = bsize/bytes_per_sector; 3189 3550 DEBUG(5,("smbd_do_qfsinfo : SMB_QUERY_FS_SIZE_INFO bsize=%u, cSectorUnit=%u, \ … … 3200 3561 case SMB_FS_FULL_SIZE_INFORMATION: 3201 3562 { 3202 uint64_t dfree,dsize,bsize,block_size,sectors_per_unit ,bytes_per_sector;3563 uint64_t dfree,dsize,bsize,block_size,sectors_per_unit; 3203 3564 data_len = 32; 3204 if (get_dfree_info(conn,filename,False,&bsize,&dfree,&dsize) == (uint64_t)-1) { 3565 df_ret = get_dfree_info(conn, filename, &bsize, &dfree, 3566 &dsize); 3567 if (df_ret == (uint64_t)-1) { 3205 3568 return map_nt_error_from_unix(errno); 3206 3569 } … … 3218 3581 dfree *= factor; 3219 3582 } 3220 bytes_per_sector = 512;3221 3583 sectors_per_unit = bsize/bytes_per_sector; 3222 3584 DEBUG(5,("smbd_do_qfsinfo : SMB_QUERY_FS_FULL_SIZE_INFO bsize=%u, cSectorUnit=%u, \ … … 3279 3641 3280 3642 fsp.conn = conn; 3281 fsp.fnum = -1;3643 fsp.fnum = FNUM_FIELD_INVALID; 3282 3644 3283 3645 /* access check */ 3284 3646 if (get_current_uid(conn) != 0) { 3285 DEBUG(0,(" set_user_quota: access_denied "3647 DEBUG(0,("get_user_quota: access_denied " 3286 3648 "service [%s] user [%s]\n", 3287 lp_servicename( SNUM(conn)),3288 conn->session_info->unix_ name));3649 lp_servicename(talloc_tos(), SNUM(conn)), 3650 conn->session_info->unix_info->unix_name)); 3289 3651 return NT_STATUS_ACCESS_DENIED; 3290 3652 } 3291 3653 3292 3654 if (vfs_get_ntquota(&fsp, SMB_USER_FS_QUOTA_TYPE, NULL, "as)!=0) { 3293 DEBUG(0,("vfs_get_ntquota() failed for service [%s]\n",lp_servicename( SNUM(conn))));3655 DEBUG(0,("vfs_get_ntquota() failed for service [%s]\n",lp_servicename(talloc_tos(), SNUM(conn)))); 3294 3656 return map_nt_error_from_unix(errno); 3295 3657 } … … 3298 3660 3299 3661 DEBUG(10,("SMB_FS_QUOTA_INFORMATION: for service [%s]\n", 3300 lp_servicename( SNUM(conn))));3662 lp_servicename(talloc_tos(), SNUM(conn)))); 3301 3663 3302 3664 /* Unknown1 24 NULL bytes*/ … … 3336 3698 } 3337 3699 3700 case SMB_FS_SECTOR_SIZE_INFORMATION: 3701 { 3702 data_len = 28; 3703 /* 3704 * These values match a physical Windows Server 2012 3705 * share backed by NTFS atop spinning rust. 3706 */ 3707 DEBUG(5, ("SMB_FS_SECTOR_SIZE_INFORMATION:")); 3708 /* logical_bytes_per_sector */ 3709 SIVAL(pdata, 0, bytes_per_sector); 3710 /* phys_bytes_per_sector_atomic */ 3711 SIVAL(pdata, 4, bytes_per_sector); 3712 /* phys_bytes_per_sector_perf */ 3713 SIVAL(pdata, 8, bytes_per_sector); 3714 /* fs_effective_phys_bytes_per_sector_atomic */ 3715 SIVAL(pdata, 12, bytes_per_sector); 3716 /* flags */ 3717 SIVAL(pdata, 16, SSINFO_FLAGS_ALIGNED_DEVICE 3718 | SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE); 3719 /* byte_off_sector_align */ 3720 SIVAL(pdata, 20, 0); 3721 /* byte_off_partition_align */ 3722 SIVAL(pdata, 24, 0); 3723 *fixed_portion = 28; 3724 break; 3725 } 3726 3727 3338 3728 /* 3339 3729 * Query the version and capabilities of the CIFS UNIX extensions … … 3344 3734 { 3345 3735 bool large_write = lp_min_receive_file_size() && 3346 !srv_is_signing_active( conn->sconn);3347 bool large_read = !srv_is_signing_active( conn->sconn);3736 !srv_is_signing_active(xconn); 3737 bool large_read = !srv_is_signing_active(xconn); 3348 3738 int encrypt_caps = 0; 3349 3739 … … 3353 3743 3354 3744 switch (conn->encrypt_level) { 3355 case 0:3745 case SMB_SIGNING_OFF: 3356 3746 encrypt_caps = 0; 3357 3747 break; 3358 case 1: 3359 case Auto: 3748 case SMB_SIGNING_DESIRED: 3749 case SMB_SIGNING_IF_REQUIRED: 3750 case SMB_SIGNING_DEFAULT: 3360 3751 encrypt_caps = CIFS_UNIX_TRANSPORT_ENCRYPTION_CAP; 3361 3752 break; 3362 case Required:3753 case SMB_SIGNING_REQUIRED: 3363 3754 encrypt_caps = CIFS_UNIX_TRANSPORT_ENCRYPTION_CAP| 3364 3755 CIFS_UNIX_TRANSPORT_ENCRYPTION_MANDATORY_CAP; … … 3415 3806 #endif /* EOPNOTSUPP */ 3416 3807 } else { 3417 DEBUG(0,("vfs_statvfs() failed for service [%s]\n",lp_servicename( SNUM(conn))));3808 DEBUG(0,("vfs_statvfs() failed for service [%s]\n",lp_servicename(talloc_tos(), SNUM(conn)))); 3418 3809 return NT_STATUS_DOS(ERRSRV, ERRerror); 3419 3810 } 3420 *fixed_portion = 24;3421 3811 break; 3422 3812 } … … 3436 3826 } 3437 3827 3438 /* We ARE guest if global_sid_Builtin_Guests is 3439 * in our list of SIDs. 3440 */ 3441 if (nt_token_check_sid(&global_sid_Builtin_Guests, 3442 conn->session_info->security_token)) { 3828 if (security_session_user_level(conn->session_info, NULL) < SECURITY_USER) { 3443 3829 flags |= SMB_WHOAMI_GUEST; 3444 }3445 3446 /* We are NOT guest if global_sid_Authenticated_Users3447 * is in our list of SIDs.3448 */3449 if (nt_token_check_sid(&global_sid_Authenticated_Users,3450 conn->session_info->security_token)) {3451 flags &= ~SMB_WHOAMI_GUEST;3452 3830 } 3453 3831 … … 3464 3842 + 4 /* SID bytes */ 3465 3843 + 4 /* pad/reserved */ 3466 + (conn->session_info->u tok.ngroups * 8)3844 + (conn->session_info->unix_token->ngroups * 8) 3467 3845 /* groups list */ 3468 3846 + (conn->session_info->security_token->num_sids * … … 3473 3851 SIVAL(pdata, 4, SMB_WHOAMI_MASK); 3474 3852 SBIG_UINT(pdata, 8, 3475 (uint64_t)conn->session_info->u tok.uid);3853 (uint64_t)conn->session_info->unix_token->uid); 3476 3854 SBIG_UINT(pdata, 16, 3477 (uint64_t)conn->session_info->u tok.gid);3855 (uint64_t)conn->session_info->unix_token->gid); 3478 3856 3479 3857 … … 3490 3868 } 3491 3869 3492 SIVAL(pdata, 24, conn->session_info->u tok.ngroups);3870 SIVAL(pdata, 24, conn->session_info->unix_token->ngroups); 3493 3871 SIVAL(pdata, 28, conn->session_info->security_token->num_sids); 3494 3872 … … 3512 3890 3513 3891 /* GID list */ 3514 for (i = 0; i < conn->session_info->u tok.ngroups; ++i) {3892 for (i = 0; i < conn->session_info->unix_token->ngroups; ++i) { 3515 3893 SBIG_UINT(pdata, data_len, 3516 (uint64_t)conn->session_info->u tok.groups[i]);3894 (uint64_t)conn->session_info->unix_token->groups[i]); 3517 3895 data_len += 8; 3518 3896 } … … 3525 3903 0); 3526 3904 3527 sid_linearize(pdata + data_len, sid_len, 3905 sid_linearize((uint8_t *)(pdata + data_len), 3906 sid_len, 3528 3907 &conn->session_info->security_token->sids[i]); 3529 3908 data_len += sid_len; … … 3550 3929 *ret_data_len = data_len; 3551 3930 return status; 3931 } 3932 3933 static NTSTATUS smb_set_fsquota(connection_struct *conn, 3934 struct smb_request *req, 3935 files_struct *fsp, 3936 const DATA_BLOB *qdata) 3937 { 3938 NTSTATUS status; 3939 SMB_NTQUOTA_STRUCT quotas; 3940 3941 ZERO_STRUCT(quotas); 3942 3943 /* access check */ 3944 if ((get_current_uid(conn) != 0) || !CAN_WRITE(conn)) { 3945 DEBUG(3, ("set_fsquota: access_denied service [%s] user [%s]\n", 3946 lp_servicename(talloc_tos(), SNUM(conn)), 3947 conn->session_info->unix_info->unix_name)); 3948 return NT_STATUS_ACCESS_DENIED; 3949 } 3950 3951 if (!check_fsp_ntquota_handle(conn, req, 3952 fsp)) { 3953 DEBUG(1, ("set_fsquota: no valid QUOTA HANDLE\n")); 3954 return NT_STATUS_INVALID_HANDLE; 3955 } 3956 3957 /* note: normally there're 48 bytes, 3958 * but we didn't use the last 6 bytes for now 3959 * --metze 3960 */ 3961 if (qdata->length < 42) { 3962 DEBUG(0,("set_fsquota: requires total_data(%u) >= 42 bytes!\n", 3963 (unsigned int)qdata->length)); 3964 return NT_STATUS_INVALID_PARAMETER; 3965 } 3966 3967 /* unknown_1 24 NULL bytes in pdata*/ 3968 3969 /* the soft quotas 8 bytes (uint64_t)*/ 3970 quotas.softlim = BVAL(qdata->data,24); 3971 3972 /* the hard quotas 8 bytes (uint64_t)*/ 3973 quotas.hardlim = BVAL(qdata->data,32); 3974 3975 /* quota_flags 2 bytes **/ 3976 quotas.qflags = SVAL(qdata->data,40); 3977 3978 /* unknown_2 6 NULL bytes follow*/ 3979 3980 /* now set the quotas */ 3981 if (vfs_set_ntquota(fsp, SMB_USER_FS_QUOTA_TYPE, NULL, "as)!=0) { 3982 DEBUG(1, ("vfs_set_ntquota() failed for service [%s]\n", 3983 lp_servicename(talloc_tos(), SNUM(conn)))); 3984 status = map_nt_error_from_unix(errno); 3985 } else { 3986 status = NT_STATUS_OK; 3987 } 3988 return status; 3989 } 3990 3991 NTSTATUS smbd_do_setfsinfo(connection_struct *conn, 3992 struct smb_request *req, 3993 TALLOC_CTX *mem_ctx, 3994 uint16_t info_level, 3995 files_struct *fsp, 3996 const DATA_BLOB *pdata) 3997 { 3998 switch (info_level) { 3999 case SMB_FS_QUOTA_INFORMATION: 4000 { 4001 return smb_set_fsquota(conn, 4002 req, 4003 fsp, 4004 pdata); 4005 } 4006 4007 default: 4008 break; 4009 } 4010 return NT_STATUS_INVALID_LEVEL; 3552 4011 } 3553 4012 … … 3580 4039 "and info level 0x%x sent.\n", 3581 4040 (unsigned int)info_level)); 3582 exit_server_cleanly("encryption required " 3583 "on connection"); 4041 reply_nterror(req, NT_STATUS_ACCESS_DENIED); 3584 4042 return; 3585 4043 } … … 3588 4046 DEBUG(3,("call_trans2qfsinfo: level = %d\n", info_level)); 3589 4047 3590 status = smbd_do_qfsinfo( conn, req,4048 status = smbd_do_qfsinfo(req->xconn, conn, req, 3591 4049 info_level, 3592 4050 req->flags2, … … 3600 4058 } 3601 4059 3602 send_trans2_replies(conn, req, params, 0, *ppdata, data_len,4060 send_trans2_replies(conn, req, NT_STATUS_OK, params, 0, *ppdata, data_len, 3603 4061 max_data_bytes); 3604 4062 … … 3619 4077 unsigned int max_data_bytes) 3620 4078 { 4079 struct smbXsrv_connection *xconn = req->xconn; 3621 4080 char *pdata = *ppdata; 3622 4081 char *params = *pparams; 3623 uint16 info_level; 3624 3625 DEBUG(10,("call_trans2setfsinfo: for service [%s]\n",lp_servicename(SNUM(conn)))); 4082 uint16_t info_level; 4083 4084 DEBUG(10,("call_trans2setfsinfo: for service [%s]\n", 4085 lp_servicename(talloc_tos(), SNUM(conn)))); 3626 4086 3627 4087 /* */ … … 3651 4111 "and info level 0x%x sent.\n", 3652 4112 (unsigned int)info_level)); 3653 exit_server_cleanly("encryption required " 3654 "on connection"); 4113 reply_nterror(req, NT_STATUS_ACCESS_DENIED); 3655 4114 return; 3656 4115 } … … 3659 4118 switch(info_level) { 3660 4119 case SMB_SET_CIFS_UNIX_INFO: 3661 { 3662 uint16 client_unix_major; 3663 uint16 client_unix_minor; 3664 uint32 client_unix_cap_low; 3665 uint32 client_unix_cap_high; 3666 3667 if (!lp_unix_extensions()) { 3668 reply_nterror(req, 3669 NT_STATUS_INVALID_LEVEL); 3670 return; 3671 } 3672 3673 /* There should be 12 bytes of capabilities set. */ 3674 if (total_data < 8) { 3675 reply_nterror( 3676 req, 3677 NT_STATUS_INVALID_PARAMETER); 3678 return; 3679 } 3680 client_unix_major = SVAL(pdata,0); 3681 client_unix_minor = SVAL(pdata,2); 3682 client_unix_cap_low = IVAL(pdata,4); 3683 client_unix_cap_high = IVAL(pdata,8); 3684 /* Just print these values for now. */ 3685 DEBUG(10,("call_trans2setfsinfo: set unix info. major = %u, minor = %u \ 3686 cap_low = 0x%x, cap_high = 0x%x\n", 3687 (unsigned int)client_unix_major, 3688 (unsigned int)client_unix_minor, 3689 (unsigned int)client_unix_cap_low, 3690 (unsigned int)client_unix_cap_high )); 3691 3692 /* Here is where we must switch to posix pathname processing... */ 3693 if (client_unix_cap_low & CIFS_UNIX_POSIX_PATHNAMES_CAP) { 3694 lp_set_posix_pathnames(); 3695 mangle_change_to_posix(); 3696 } 3697 3698 if ((client_unix_cap_low & CIFS_UNIX_FCNTL_LOCKS_CAP) && 3699 !(client_unix_cap_low & CIFS_UNIX_POSIX_PATH_OPERATIONS_CAP)) { 3700 /* Client that knows how to do posix locks, 3701 * but not posix open/mkdir operations. Set a 3702 * default type for read/write checks. */ 3703 3704 lp_set_posix_default_cifsx_readwrite_locktype(POSIX_LOCK); 3705 3706 } 3707 break; 3708 } 4120 if (!lp_unix_extensions()) { 4121 DEBUG(2,("call_trans2setfsinfo: " 4122 "SMB_SET_CIFS_UNIX_INFO is invalid with " 4123 "unix extensions off\n")); 4124 reply_nterror(req, 4125 NT_STATUS_INVALID_LEVEL); 4126 return; 4127 } 4128 4129 /* There should be 12 bytes of capabilities set. */ 4130 if (total_data < 12) { 4131 reply_nterror( 4132 req, 4133 NT_STATUS_INVALID_PARAMETER); 4134 return; 4135 } 4136 xconn->smb1.unix_info.client_major = SVAL(pdata,0); 4137 xconn->smb1.unix_info.client_minor = SVAL(pdata,2); 4138 xconn->smb1.unix_info.client_cap_low = IVAL(pdata,4); 4139 xconn->smb1.unix_info.client_cap_high = IVAL(pdata,8); 4140 /* Just print these values for now. */ 4141 DEBUG(10, ("call_trans2setfsinfo: set unix_info info. " 4142 "major = %u, minor = %u cap_low = 0x%x, " 4143 "cap_high = 0x%xn", 4144 (unsigned int)xconn-> 4145 smb1.unix_info.client_major, 4146 (unsigned int)xconn-> 4147 smb1.unix_info.client_minor, 4148 (unsigned int)xconn-> 4149 smb1.unix_info.client_cap_low, 4150 (unsigned int)xconn-> 4151 smb1.unix_info.client_cap_high)); 4152 4153 /* Here is where we must switch to posix pathname processing... */ 4154 if (xconn->smb1.unix_info.client_cap_low & CIFS_UNIX_POSIX_PATHNAMES_CAP) { 4155 lp_set_posix_pathnames(); 4156 mangle_change_to_posix(); 4157 } 4158 4159 if ((xconn->smb1.unix_info.client_cap_low & CIFS_UNIX_FCNTL_LOCKS_CAP) && 4160 !(xconn->smb1.unix_info.client_cap_low & CIFS_UNIX_POSIX_PATH_OPERATIONS_CAP)) { 4161 /* Client that knows how to do posix locks, 4162 * but not posix open/mkdir operations. Set a 4163 * default type for read/write checks. */ 4164 4165 lp_set_posix_default_cifsx_readwrite_locktype(POSIX_LOCK); 4166 4167 } 4168 break; 3709 4169 3710 4170 case SMB_REQUEST_TRANSPORT_ENCRYPTION: … … 3721 4181 } 3722 4182 3723 if (lp_smb_encrypt(SNUM(conn)) == false) {4183 if (lp_smb_encrypt(SNUM(conn)) == SMB_SIGNING_OFF) { 3724 4184 reply_nterror( 3725 4185 req, … … 3728 4188 } 3729 4189 3730 if ( req->sconn->smb1.echo_handler.trusted_fde) {4190 if (xconn->smb1.echo_handler.trusted_fde) { 3731 4191 DEBUG( 2,("call_trans2setfsinfo: " 3732 4192 "request transport encryption disabled" … … 3754 4214 3755 4215 send_trans2_replies(conn, req, 4216 NT_STATUS_OK, 3756 4217 *pparams, 3757 4218 param_len, … … 3765 4226 status = srv_encryption_start(conn); 3766 4227 if (!NT_STATUS_IS_OK(status)) { 3767 exit_server_cleanly( 3768 "Failure in setting " 3769 "up encrypted transport"); 4228 char *reason = talloc_asprintf(talloc_tos(), 4229 "Failure in setting " 4230 "up encrypted transport: %s", 4231 nt_errstr(status)); 4232 exit_server_cleanly(reason); 3770 4233 } 3771 4234 } … … 3775 4238 case SMB_FS_QUOTA_INFORMATION: 3776 4239 { 4240 NTSTATUS status; 4241 DATA_BLOB qdata = { 4242 .data = (uint8_t *)pdata, 4243 .length = total_data 4244 }; 3777 4245 files_struct *fsp = NULL; 3778 SMB_NTQUOTA_STRUCT quotas; 3779 3780 ZERO_STRUCT(quotas); 3781 3782 /* access check */ 3783 if ((get_current_uid(conn) != 0) || !CAN_WRITE(conn)) { 3784 DEBUG(0,("set_user_quota: access_denied service [%s] user [%s]\n", 3785 lp_servicename(SNUM(conn)), 3786 conn->session_info->unix_name)); 3787 reply_nterror(req, NT_STATUS_ACCESS_DENIED); 4246 fsp = file_fsp(req, SVAL(params,0)); 4247 4248 status = smb_set_fsquota(conn, 4249 req, 4250 fsp, 4251 &qdata); 4252 if (!NT_STATUS_IS_OK(status)) { 4253 reply_nterror(req, status); 3788 4254 return; 3789 4255 } 3790 3791 /* note: normaly there're 48 bytes,3792 * but we didn't use the last 6 bytes for now3793 * --metze3794 */3795 fsp = file_fsp(req, SVAL(params,0));3796 3797 if (!check_fsp_ntquota_handle(conn, req,3798 fsp)) {3799 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));3800 reply_nterror(3801 req, NT_STATUS_INVALID_HANDLE);3802 return;3803 }3804 3805 if (total_data < 42) {3806 DEBUG(0,("call_trans2setfsinfo: SET_FS_QUOTA: requires total_data(%d) >= 42 bytes!\n",3807 total_data));3808 reply_nterror(3809 req,3810 NT_STATUS_INVALID_PARAMETER);3811 return;3812 }3813 3814 /* unknown_1 24 NULL bytes in pdata*/3815 3816 /* the soft quotas 8 bytes (uint64_t)*/3817 quotas.softlim = BVAL(pdata,24);3818 3819 /* the hard quotas 8 bytes (uint64_t)*/3820 quotas.hardlim = BVAL(pdata,32);3821 3822 /* quota_flags 2 bytes **/3823 quotas.qflags = SVAL(pdata,40);3824 3825 /* unknown_2 6 NULL bytes follow*/3826 3827 /* now set the quotas */3828 if (vfs_set_ntquota(fsp, SMB_USER_FS_QUOTA_TYPE, NULL, "as)!=0) {3829 DEBUG(0,("vfs_set_ntquota() failed for service [%s]\n",lp_servicename(SNUM(conn))));3830 reply_nterror(req, map_nt_error_from_unix(errno));3831 return;3832 }3833 3834 4256 break; 3835 4257 } … … 3862 4284 SMB_ACL_ENTRY_T entry; 3863 4285 3864 while ( posix_acl && ( SMB_VFS_SYS_ACL_GET_ENTRY(conn,posix_acl, entry_id, &entry) == 1)) {4286 while ( posix_acl && (sys_acl_get_entry(posix_acl, entry_id, &entry) == 1)) { 3865 4287 /* get_next... */ 3866 4288 if (entry_id == SMB_ACL_FIRST_ENTRY) { … … 3881 4303 SMB_ACL_ENTRY_T entry; 3882 4304 3883 while ( posix_acl && ( SMB_VFS_SYS_ACL_GET_ENTRY(conn,posix_acl, entry_id, &entry) == 1)) {4305 while ( posix_acl && (sys_acl_get_entry(posix_acl, entry_id, &entry) == 1)) { 3884 4306 SMB_ACL_TAG_T tagtype; 3885 4307 SMB_ACL_PERMSET_T permset; … … 3892 4314 } 3893 4315 3894 if ( SMB_VFS_SYS_ACL_GET_TAG_TYPE(conn,entry, &tagtype) == -1) {4316 if (sys_acl_get_tag_type(entry, &tagtype) == -1) { 3895 4317 DEBUG(0,("marshall_posix_acl: SMB_VFS_SYS_ACL_GET_TAG_TYPE failed.\n")); 3896 4318 return False; 3897 4319 } 3898 4320 3899 if ( SMB_VFS_SYS_ACL_GET_PERMSET(conn,entry, &permset) == -1) {4321 if (sys_acl_get_permset(entry, &permset) == -1) { 3900 4322 DEBUG(0,("marshall_posix_acl: SMB_VFS_SYS_ACL_GET_PERMSET failed.\n")); 3901 4323 return False; 3902 4324 } 3903 4325 3904 perms |= ( SMB_VFS_SYS_ACL_GET_PERM(conn,permset, SMB_ACL_READ) ? SMB_POSIX_ACL_READ : 0);3905 perms |= ( SMB_VFS_SYS_ACL_GET_PERM(conn,permset, SMB_ACL_WRITE) ? SMB_POSIX_ACL_WRITE : 0);3906 perms |= ( SMB_VFS_SYS_ACL_GET_PERM(conn,permset, SMB_ACL_EXECUTE) ? SMB_POSIX_ACL_EXECUTE : 0);4326 perms |= (sys_acl_get_perm(permset, SMB_ACL_READ) ? SMB_POSIX_ACL_READ : 0); 4327 perms |= (sys_acl_get_perm(permset, SMB_ACL_WRITE) ? SMB_POSIX_ACL_WRITE : 0); 4328 perms |= (sys_acl_get_perm(permset, SMB_ACL_EXECUTE) ? SMB_POSIX_ACL_EXECUTE : 0); 3907 4329 3908 4330 SCVAL(pdata,1,perms); … … 3917 4339 case SMB_ACL_USER: 3918 4340 { 3919 uid_t *puid = (uid_t *) SMB_VFS_SYS_ACL_GET_QUALIFIER(conn,entry);4341 uid_t *puid = (uid_t *)sys_acl_get_qualifier(entry); 3920 4342 if (!puid) { 3921 4343 DEBUG(0,("marshall_posix_acl: SMB_VFS_SYS_ACL_GET_QUALIFIER failed.\n")); … … 3923 4345 } 3924 4346 own_grp = (unsigned int)*puid; 3925 SMB_VFS_SYS_ACL_FREE_QUALIFIER(conn, (void *)puid,tagtype);3926 4347 SCVAL(pdata,0,SMB_POSIX_ACL_USER); 3927 4348 SIVAL(pdata,2,own_grp); … … 3937 4358 case SMB_ACL_GROUP: 3938 4359 { 3939 gid_t *pgid= (gid_t *) SMB_VFS_SYS_ACL_GET_QUALIFIER(conn,entry);4360 gid_t *pgid= (gid_t *)sys_acl_get_qualifier(entry); 3940 4361 if (!pgid) { 3941 4362 DEBUG(0,("marshall_posix_acl: SMB_VFS_SYS_ACL_GET_QUALIFIER failed.\n")); … … 3943 4364 } 3944 4365 own_grp = (unsigned int)*pgid; 3945 SMB_VFS_SYS_ACL_FREE_QUALIFIER(conn, (void *)pgid,tagtype);3946 4366 SCVAL(pdata,0,SMB_POSIX_ACL_GROUP); 3947 4367 SIVAL(pdata,2,own_grp); … … 3980 4400 { 3981 4401 uint64_t file_index = get_FileIndex(conn, psbuf); 4402 dev_t devno; 3982 4403 3983 4404 DEBUG(10,("store_file_unix_basic: SMB_QUERY_FILE_UNIX_BASIC\n")); … … 4006 4427 pdata += 4; 4007 4428 4008 SIVAL(pdata,0,unix_dev_major(psbuf->st_ex_rdev)); /* Major device number if type is device */ 4429 if (S_ISBLK(psbuf->st_ex_mode) || S_ISCHR(psbuf->st_ex_mode)) { 4430 devno = psbuf->st_ex_rdev; 4431 } else { 4432 devno = psbuf->st_ex_dev; 4433 } 4434 4435 SIVAL(pdata,0,unix_dev_major(devno)); /* Major device number if type is device */ 4009 4436 SIVAL(pdata,4,0); 4010 4437 pdata += 8; 4011 4438 4012 SIVAL(pdata,0,unix_dev_minor( psbuf->st_ex_rdev)); /* Minor device number if type is device */4439 SIVAL(pdata,0,unix_dev_minor(devno)); /* Minor device number if type is device */ 4013 4440 SIVAL(pdata,4,0); 4014 4441 pdata += 8; … … 4063 4490 4064 4491 static void map_info2_flags_from_sbuf(const SMB_STRUCT_STAT *psbuf, 4065 uint32 *smb_fflags, uint32*smb_fmask)4492 uint32_t *smb_fflags, uint32_t *smb_fmask) 4066 4493 { 4067 4494 int i; … … 4076 4503 4077 4504 static bool map_info2_flags_to_sbuf(const SMB_STRUCT_STAT *psbuf, 4078 const uint32 smb_fflags,4079 const uint32 smb_fmask,4505 const uint32_t smb_fflags, 4506 const uint32_t smb_fmask, 4080 4507 int *stat_fflags) 4081 4508 { 4082 uint32 max_fmask = 0;4509 uint32_t max_fmask = 0; 4083 4510 int i; 4084 4511 … … 4120 4547 const SMB_STRUCT_STAT *psbuf) 4121 4548 { 4122 uint32 file_flags = 0;4123 uint32 flags_mask = 0;4549 uint32_t file_flags = 0; 4550 uint32_t flags_mask = 0; 4124 4551 4125 4552 pdata = store_file_unix_basic(conn, pdata, fsp, psbuf); … … 4233 4660 unsigned int data_size = 0; 4234 4661 unsigned int param_size = 2; 4235 uint16 info_level;4662 uint16_t info_level; 4236 4663 files_struct *fsp; 4237 4664 … … 4261 4688 params = *pparams; 4262 4689 SSVAL(params,0,0); 4690 if (max_data_bytes + DIR_ENTRY_SAFETY_MARGIN < max_data_bytes) { 4691 reply_nterror(req, NT_STATUS_INVALID_PARAMETER); 4692 return; 4693 } 4263 4694 data_size = max_data_bytes + DIR_ENTRY_SAFETY_MARGIN; 4264 4695 *ppdata = (char *)SMB_REALLOC(*ppdata, data_size); … … 4283 4714 } 4284 4715 4285 send_trans2_replies(conn, req, params, param_size, *ppdata, data_size,4716 send_trans2_replies(conn, req, NT_STATUS_OK, params, param_size, *ppdata, data_size, 4286 4717 max_data_bytes); 4287 4718 … … 4322 4753 uint64_t file_index = 0; 4323 4754 uint32_t access_mask = 0; 4755 size_t len = 0; 4324 4756 4325 4757 if (INFO_LEVEL_IS_UNIX(info_level) && !lp_unix_extensions()) { … … 4327 4759 } 4328 4760 4329 DEBUG(5,("smbd_do_qfilepathinfo: %s (fnum = %d) level=%d max_data=%u\n", 4330 smb_fname_str_dbg(smb_fname), fsp ? fsp->fnum : -1, 4761 DEBUG(5,("smbd_do_qfilepathinfo: %s (%s) level=%d max_data=%u\n", 4762 smb_fname_str_dbg(smb_fname), 4763 fsp_fnum_dbg(fsp), 4331 4764 info_level, max_data_bytes)); 4332 4765 … … 4340 4773 if ((nlink > 0) && delete_pending) { 4341 4774 nlink -= 1; 4775 } 4776 4777 if (max_data_bytes + DIR_ENTRY_SAFETY_MARGIN < max_data_bytes) { 4778 return NT_STATUS_INVALID_PARAMETER; 4342 4779 } 4343 4780 … … 4446 4883 srv_put_dos_date2(pdata,l1_fdateLastAccess,atime); 4447 4884 srv_put_dos_date2(pdata,l1_fdateLastWrite,mtime); /* write time */ 4448 SIVAL(pdata,l1_cbFile,(uint32 )file_size);4449 SIVAL(pdata,l1_cbFileAlloc,(uint32 )allocation_size);4885 SIVAL(pdata,l1_cbFile,(uint32_t)file_size); 4886 SIVAL(pdata,l1_cbFileAlloc,(uint32_t)allocation_size); 4450 4887 SSVAL(pdata,l1_attrFile,mode); 4451 4888 break; … … 4455 4892 unsigned int ea_size = 4456 4893 estimate_ea_size(conn, fsp, 4457 smb_fname ->base_name);4894 smb_fname); 4458 4895 DEBUG(10,("smbd_do_qfilepathinfo: SMB_INFO_QUERY_EA_SIZE\n")); 4459 4896 data_size = 26; … … 4461 4898 srv_put_dos_date2(pdata,4,atime); 4462 4899 srv_put_dos_date2(pdata,8,mtime); /* write time */ 4463 SIVAL(pdata,12,(uint32 )file_size);4464 SIVAL(pdata,16,(uint32 )allocation_size);4900 SIVAL(pdata,12,(uint32_t)file_size); 4901 SIVAL(pdata,16,(uint32_t)allocation_size); 4465 4902 SSVAL(pdata,20,mode); 4466 4903 SIVAL(pdata,22,ea_size); … … 4482 4919 size_t total_ea_len = 0; 4483 4920 struct ea_list *ea_file_list = NULL; 4484 4485 4921 DEBUG(10,("smbd_do_qfilepathinfo: SMB_INFO_QUERY_EAS_FROM_LIST\n")); 4486 4922 4487 ea_file_list=4923 status = 4488 4924 get_ea_list_from_file(mem_ctx, conn, fsp, 4489 smb_fname->base_name, 4490 &total_ea_len); 4925 smb_fname, 4926 &total_ea_len, &ea_file_list); 4927 if (!NT_STATUS_IS_OK(status)) { 4928 return status; 4929 } 4930 4491 4931 ea_list = ea_list_union(ea_list, ea_file_list, &total_ea_len); 4492 4932 … … 4505 4945 /* We have data_size bytes to put EA's into. */ 4506 4946 size_t total_ea_len = 0; 4507 4508 4947 DEBUG(10,("smbd_do_qfilepathinfo: SMB_INFO_QUERY_ALL_EAS\n")); 4509 4948 4510 ea_list = get_ea_list_from_file(mem_ctx, conn, fsp, 4511 smb_fname->base_name, 4512 &total_ea_len); 4949 status = get_ea_list_from_file(mem_ctx, conn, fsp, 4950 smb_fname, 4951 &total_ea_len, &ea_list); 4952 if (!NT_STATUS_IS_OK(status)) { 4953 return status; 4954 } 4955 4513 4956 if (!ea_list || (total_ea_len > data_size)) { 4514 4957 data_size = 4; … … 4534 4977 /*TODO: add filtering and index handling */ 4535 4978 4536 ea_file_list = 4537 get_ea_list_from_file(mem_ctx, conn, fsp, 4538 smb_fname->base_name, 4539 &total_ea_len); 4979 status = 4980 get_ea_list_from_file(mem_ctx, conn, fsp, 4981 smb_fname, 4982 &total_ea_len, &ea_file_list); 4983 if (!NT_STATUS_IS_OK(status)) { 4984 return status; 4985 } 4540 4986 if (!ea_file_list) { 4541 4987 return NT_STATUS_NO_EAS_ON_FILE; … … 4597 5043 { 4598 5044 unsigned int ea_size = 4599 estimate_ea_size(conn, fsp, smb_fname ->base_name);5045 estimate_ea_size(conn, fsp, smb_fname); 4600 5046 DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_EA_INFORMATION\n")); 4601 5047 data_size = 4; … … 4609 5055 case SMB_FILE_ALTERNATE_NAME_INFORMATION: 4610 5056 { 4611 int len;4612 5057 char mangled_name[13]; 4613 5058 DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_ALTERNATE_NAME_INFORMATION\n")); … … 4616 5061 return NT_STATUS_NO_MEMORY; 4617 5062 } 4618 len= srvstr_push(dstart, flags2,5063 status = srvstr_push(dstart, flags2, 4619 5064 pdata+4, mangled_name, 4620 5065 PTR_DIFF(dend, pdata+4), 4621 STR_UNICODE); 5066 STR_UNICODE, &len); 5067 if (!NT_STATUS_IS_OK(status)) { 5068 return status; 5069 } 4622 5070 data_size = 4 + len; 4623 5071 SIVAL(pdata,0,len); … … 4628 5076 case SMB_QUERY_FILE_NAME_INFO: 4629 5077 { 4630 int len;4631 5078 /* 4632 5079 this must be *exactly* right for ACLs on mapped drives to work 4633 5080 */ 4634 len= srvstr_push(dstart, flags2,5081 status = srvstr_push(dstart, flags2, 4635 5082 pdata+4, dos_fname, 4636 5083 PTR_DIFF(dend, pdata+4), 4637 STR_UNICODE); 5084 STR_UNICODE, &len); 5085 if (!NT_STATUS_IS_OK(status)) { 5086 return status; 5087 } 4638 5088 DEBUG(10,("smbd_do_qfilepathinfo: SMB_QUERY_FILE_NAME_INFO\n")); 4639 5089 data_size = 4 + len; … … 4659 5109 case SMB_FILE_ALL_INFORMATION: 4660 5110 { 4661 int len;4662 5111 unsigned int ea_size = 4663 estimate_ea_size(conn, fsp, smb_fname ->base_name);5112 estimate_ea_size(conn, fsp, smb_fname); 4664 5113 DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_ALL_INFORMATION\n")); 4665 5114 put_long_date_timespec(conn->ts_res,pdata,create_time_ts); … … 4679 5128 SIVAL(pdata,0,ea_size); 4680 5129 pdata += 4; /* EA info */ 4681 len= srvstr_push(dstart, flags2,5130 status = srvstr_push(dstart, flags2, 4682 5131 pdata+4, dos_fname, 4683 5132 PTR_DIFF(dend, pdata+4), 4684 STR_UNICODE); 5133 STR_UNICODE, &len); 5134 if (!NT_STATUS_IS_OK(status)) { 5135 return status; 5136 } 4685 5137 SIVAL(pdata,0,len); 4686 5138 pdata += 4 + len; … … 4692 5144 case 0xFF12:/*SMB2_FILE_ALL_INFORMATION*/ 4693 5145 { 4694 int len;4695 5146 unsigned int ea_size = 4696 estimate_ea_size(conn, fsp, smb_fname ->base_name);5147 estimate_ea_size(conn, fsp, smb_fname); 4697 5148 DEBUG(10,("smbd_do_qfilepathinfo: SMB2_FILE_ALL_INFORMATION\n")); 4698 5149 put_long_date_timespec(conn->ts_res,pdata+0x00,create_time_ts); … … 4717 5168 pdata += 0x60; 4718 5169 4719 len= srvstr_push(dstart, flags2,5170 status = srvstr_push(dstart, flags2, 4720 5171 pdata+4, dos_fname, 4721 5172 PTR_DIFF(dend, pdata+4), 4722 STR_UNICODE); 5173 STR_UNICODE, &len); 5174 if (!NT_STATUS_IS_OK(status)) { 5175 return status; 5176 } 4723 5177 SIVAL(pdata,0,len); 4724 5178 pdata += 4 + len; … … 4892 5346 case SMB_QUERY_FILE_UNIX_LINK: 4893 5347 { 4894 int l en;4895 char *buffer = TALLOC_ARRAY(mem_ctx, char, PATH_MAX+1);5348 int link_len = 0; 5349 char *buffer = talloc_array(mem_ctx, char, PATH_MAX+1); 4896 5350 4897 5351 if (!buffer) { … … 4907 5361 return NT_STATUS_DOS(ERRDOS, ERRbadlink); 4908 5362 #endif 4909 l en = SMB_VFS_READLINK(conn,5363 link_len = SMB_VFS_READLINK(conn, 4910 5364 smb_fname->base_name, 4911 5365 buffer, PATH_MAX); 4912 if (l en == -1) {5366 if (link_len == -1) { 4913 5367 return map_nt_error_from_unix(errno); 4914 5368 } 4915 buffer[l en] = 0;4916 len= srvstr_push(dstart, flags2,5369 buffer[link_len] = 0; 5370 status = srvstr_push(dstart, flags2, 4917 5371 pdata, buffer, 4918 5372 PTR_DIFF(dend, pdata), 4919 STR_TERMINATE); 5373 STR_TERMINATE, &len); 5374 if (!NT_STATUS_IS_OK(status)) { 5375 return status; 5376 } 4920 5377 pdata += len; 4921 5378 data_size = PTR_DIFF(pdata,(*ppdata)); … … 4929 5386 SMB_ACL_T file_acl = NULL; 4930 5387 SMB_ACL_T def_acl = NULL; 4931 uint16 num_file_acls = 0; 4932 uint16 num_def_acls = 0; 5388 uint16_t num_file_acls = 0; 5389 uint16_t num_def_acls = 0; 5390 5391 status = refuse_symlink(conn, 5392 fsp, 5393 smb_fname->base_name); 5394 if (!NT_STATUS_IS_OK(status)) { 5395 return status; 5396 } 4933 5397 4934 5398 if (fsp && fsp->fh->fd != -1) { 4935 file_acl = SMB_VFS_SYS_ACL_GET_FD(fsp); 5399 file_acl = SMB_VFS_SYS_ACL_GET_FD(fsp, 5400 talloc_tos()); 4936 5401 } else { 4937 5402 file_acl = 4938 5403 SMB_VFS_SYS_ACL_GET_FILE(conn, 4939 5404 smb_fname->base_name, 4940 SMB_ACL_TYPE_ACCESS); 5405 SMB_ACL_TYPE_ACCESS, 5406 talloc_tos()); 4941 5407 } 4942 5408 … … 4955 5421 conn, 4956 5422 fsp->fsp_name->base_name, 4957 SMB_ACL_TYPE_DEFAULT); 5423 SMB_ACL_TYPE_DEFAULT, 5424 talloc_tos()); 4958 5425 } else { 4959 5426 def_acl = … … 4961 5428 conn, 4962 5429 smb_fname->base_name, 4963 SMB_ACL_TYPE_DEFAULT); 5430 SMB_ACL_TYPE_DEFAULT, 5431 talloc_tos()); 4964 5432 } 4965 5433 def_acl = free_empty_sys_acl(conn, def_acl); … … 4975 5443 SMB_POSIX_ACL_HEADER_SIZE) )); 4976 5444 if (file_acl) { 4977 SMB_VFS_SYS_ACL_FREE_ACL(conn,file_acl);5445 TALLOC_FREE(file_acl); 4978 5446 } 4979 5447 if (def_acl) { 4980 SMB_VFS_SYS_ACL_FREE_ACL(conn,def_acl);5448 TALLOC_FREE(def_acl); 4981 5449 } 4982 5450 return NT_STATUS_BUFFER_TOO_SMALL; … … 4988 5456 if (!marshall_posix_acl(conn, pdata + SMB_POSIX_ACL_HEADER_SIZE, psbuf, file_acl)) { 4989 5457 if (file_acl) { 4990 SMB_VFS_SYS_ACL_FREE_ACL(conn,file_acl);5458 TALLOC_FREE(file_acl); 4991 5459 } 4992 5460 if (def_acl) { 4993 SMB_VFS_SYS_ACL_FREE_ACL(conn,def_acl);5461 TALLOC_FREE(def_acl); 4994 5462 } 4995 5463 return NT_STATUS_INTERNAL_ERROR; … … 4997 5465 if (!marshall_posix_acl(conn, pdata + SMB_POSIX_ACL_HEADER_SIZE + (num_file_acls*SMB_POSIX_ACL_ENTRY_SIZE), psbuf, def_acl)) { 4998 5466 if (file_acl) { 4999 SMB_VFS_SYS_ACL_FREE_ACL(conn,file_acl);5467 TALLOC_FREE(file_acl); 5000 5468 } 5001 5469 if (def_acl) { 5002 SMB_VFS_SYS_ACL_FREE_ACL(conn,def_acl);5470 TALLOC_FREE(def_acl); 5003 5471 } 5004 5472 return NT_STATUS_INTERNAL_ERROR; … … 5006 5474 5007 5475 if (file_acl) { 5008 SMB_VFS_SYS_ACL_FREE_ACL(conn,file_acl);5476 TALLOC_FREE(file_acl); 5009 5477 } 5010 5478 if (def_acl) { 5011 SMB_VFS_SYS_ACL_FREE_ACL(conn,def_acl);5479 TALLOC_FREE(def_acl); 5012 5480 } 5013 5481 data_size = (num_file_acls + num_def_acls)*SMB_POSIX_ACL_ENTRY_SIZE + SMB_POSIX_ACL_HEADER_SIZE; … … 5047 5515 5048 5516 smblctx = (uint64_t)IVAL(pdata, POSIX_LOCK_PID_OFFSET); 5049 #if defined(HAVE_LONGLONG) 5050 offset = (((uint64_t) IVAL(pdata,(POSIX_LOCK_START_OFFSET+4))) << 32) | 5051 ((uint64_t) IVAL(pdata,POSIX_LOCK_START_OFFSET)); 5052 count = (((uint64_t) IVAL(pdata,(POSIX_LOCK_LEN_OFFSET+4))) << 32) | 5053 ((uint64_t) IVAL(pdata,POSIX_LOCK_LEN_OFFSET)); 5054 #else /* HAVE_LONGLONG */ 5055 offset = (uint64_t)IVAL(pdata,POSIX_LOCK_START_OFFSET); 5056 count = (uint64_t)IVAL(pdata,POSIX_LOCK_LEN_OFFSET); 5057 #endif /* HAVE_LONGLONG */ 5517 offset = BVAL(pdata,POSIX_LOCK_START_OFFSET); 5518 count = BVAL(pdata,POSIX_LOCK_LEN_OFFSET); 5058 5519 5059 5520 status = query_lock(fsp, … … 5071 5532 SSVAL(pdata, POSIX_LOCK_FLAGS_OFFSET, 0); 5072 5533 SIVAL(pdata, POSIX_LOCK_PID_OFFSET, (uint32_t)smblctx); 5073 #if defined(HAVE_LONGLONG) 5074 SIVAL(pdata, POSIX_LOCK_START_OFFSET, (uint32)(offset & 0xFFFFFFFF)); 5075 SIVAL(pdata, POSIX_LOCK_START_OFFSET + 4, (uint32)((offset >> 32) & 0xFFFFFFFF)); 5076 SIVAL(pdata, POSIX_LOCK_LEN_OFFSET, (uint32)(count & 0xFFFFFFFF)); 5077 SIVAL(pdata, POSIX_LOCK_LEN_OFFSET + 4, (uint32)((count >> 32) & 0xFFFFFFFF)); 5078 #else /* HAVE_LONGLONG */ 5079 SIVAL(pdata, POSIX_LOCK_START_OFFSET, offset); 5080 SIVAL(pdata, POSIX_LOCK_LEN_OFFSET, count); 5081 #endif /* HAVE_LONGLONG */ 5534 SBVAL(pdata, POSIX_LOCK_START_OFFSET, offset); 5535 SBVAL(pdata, POSIX_LOCK_LEN_OFFSET, count); 5082 5536 5083 5537 } else if (NT_STATUS_IS_OK(status)) { … … 5115 5569 char *params = *pparams; 5116 5570 char *pdata = *ppdata; 5117 uint16 info_level;5571 uint16_t info_level; 5118 5572 unsigned int data_size = 0; 5119 5573 unsigned int param_size = 2; … … 5165 5619 } 5166 5620 5167 status = copy_smb_filename(talloc_tos(), fsp->fsp_name, 5168 &smb_fname); 5169 if (!NT_STATUS_IS_OK(status)) { 5170 reply_nterror(req, status); 5621 smb_fname = cp_smb_filename(talloc_tos(), fsp->fsp_name); 5622 if (smb_fname == NULL) { 5623 reply_nterror(req, NT_STATUS_NO_MEMORY); 5171 5624 return; 5172 5625 } … … 5215 5668 */ 5216 5669 if (SMB_VFS_FSTAT(fsp, &smb_fname->st) != 0) { 5217 DEBUG(3, ("fstat of fnum %dfailed (%s)\n",5218 fsp ->fnum, strerror(errno)));5670 DEBUG(3, ("fstat of %s failed (%s)\n", 5671 fsp_fnum_dbg(fsp), strerror(errno))); 5219 5672 reply_nterror(req, 5220 5673 map_nt_error_from_unix(errno)); … … 5228 5681 uint32_t name_hash; 5229 5682 char *fname = NULL; 5230 uint32_t ucf_flags = 0; 5683 uint32_t ucf_flags = (req->posix_pathnames ? 5684 UCF_POSIX_PATHNAMES : 0); 5231 5685 5232 5686 /* qpathinfo */ … … 5252 5706 } 5253 5707 5254 srvstr_get_path(req, params, req->flags2, &fname, ¶ms[6], 5708 if (req->posix_pathnames) { 5709 srvstr_get_path_posix(req, 5710 params, 5711 req->flags2, 5712 &fname, 5713 ¶ms[6], 5255 5714 total_params - 6, 5256 STR_TERMINATE, &status); 5715 STR_TERMINATE, 5716 &status); 5717 } else { 5718 srvstr_get_path(req, 5719 params, 5720 req->flags2, 5721 &fname, 5722 ¶ms[6], 5723 total_params - 6, 5724 STR_TERMINATE, 5725 &status); 5726 } 5257 5727 if (!NT_STATUS_IS_OK(status)) { 5258 5728 reply_nterror(req, status); … … 5281 5751 if ((conn->fs_capabilities & FILE_NAMED_STREAMS) 5282 5752 && is_ntfs_stream_smb_fname(smb_fname)) { 5283 struct smb_filename *smb_fname_base = NULL;5753 struct smb_filename *smb_fname_base; 5284 5754 5285 5755 /* Create an smb_filename with stream_name == NULL. */ 5286 status = 5287 create_synthetic_smb_fname(talloc_tos(), 5288 smb_fname->base_name, 5289 NULL, NULL, 5290 &smb_fname_base); 5291 if (!NT_STATUS_IS_OK(status)) { 5292 reply_nterror(req, status); 5756 smb_fname_base = synthetic_smb_fname( 5757 talloc_tos(), smb_fname->base_name, 5758 NULL, NULL); 5759 if (smb_fname_base == NULL) { 5760 reply_nterror(req, NT_STATUS_NO_MEMORY); 5293 5761 return; 5294 5762 } … … 5380 5848 } 5381 5849 5382 DEBUG(3,("call_trans2qfilepathinfo %s ( fnum = %d) level=%d call=%d "5850 DEBUG(3,("call_trans2qfilepathinfo %s (%s) level=%d call=%d " 5383 5851 "total_data=%d\n", smb_fname_str_dbg(smb_fname), 5384 fsp ? fsp->fnum : -1, info_level,tran_call,total_data)); 5852 fsp_fnum_dbg(fsp), 5853 info_level,tran_call,total_data)); 5385 5854 5386 5855 /* Pull out any data sent here before we realloc. */ … … 5389 5858 { 5390 5859 /* Pull any EA list from the data portion. */ 5391 uint32 ea_size;5860 uint32_t ea_size; 5392 5861 5393 5862 if (total_data < 4) { … … 5435 5904 5436 5905 /* Copy the lock range data. */ 5437 lock_data = (char *) TALLOC_MEMDUP(5906 lock_data = (char *)talloc_memdup( 5438 5907 req, pdata, total_data); 5439 5908 if (!lock_data) { … … 5499 5968 } 5500 5969 5501 send_trans2_replies(conn, req, params, param_size, *ppdata, data_size,5970 send_trans2_replies(conn, req, NT_STATUS_OK, params, param_size, *ppdata, data_size, 5502 5971 max_data_bytes); 5503 5972 … … 5569 6038 /**************************************************************************** 5570 6039 Deal with setting the time from any of the setfilepathinfo functions. 6040 NOTE !!!! The check for FILE_WRITE_ATTRIBUTES access must be done *before* 6041 calling this function. 5571 6042 ****************************************************************************/ 5572 6043 … … 5578 6049 { 5579 6050 struct smb_filename smb_fname_base; 5580 uint32 action =6051 uint32_t action = 5581 6052 FILE_NOTIFY_CHANGE_LAST_ACCESS 5582 6053 |FILE_NOTIFY_CHANGE_LAST_WRITE … … 5585 6056 if (!VALID_STAT(smb_fname->st)) { 5586 6057 return NT_STATUS_OBJECT_NAME_NOT_FOUND; 5587 }5588 5589 if (fsp && !(fsp->access_mask & FILE_WRITE_ATTRIBUTES)) {5590 return NT_STATUS_ACCESS_DENIED;5591 6058 } 5592 6059 … … 5671 6138 /**************************************************************************** 5672 6139 Deal with setting the dosmode from any of the setfilepathinfo functions. 6140 NB. The check for FILE_WRITE_ATTRIBUTES access on this path must have been 6141 done before calling this function. 5673 6142 ****************************************************************************/ 5674 6143 5675 6144 static NTSTATUS smb_set_file_dosmode(connection_struct *conn, 5676 6145 const struct smb_filename *smb_fname, 5677 uint32 dosmode)6146 uint32_t dosmode) 5678 6147 { 5679 struct smb_filename *smb_fname_base = NULL;6148 struct smb_filename *smb_fname_base; 5680 6149 NTSTATUS status; 5681 6150 … … 5685 6154 5686 6155 /* Always operate on the base_name, even if a stream was passed in. */ 5687 status = create_synthetic_smb_fname(talloc_tos(), smb_fname->base_name, 5688 NULL, &smb_fname->st, 5689 &smb_fname_base); 5690 if (!NT_STATUS_IS_OK(status)) { 5691 return status; 6156 smb_fname_base = synthetic_smb_fname( 6157 talloc_tos(), smb_fname->base_name, NULL, &smb_fname->st); 6158 if (smb_fname_base == NULL) { 6159 return NT_STATUS_NO_MEMORY; 5692 6160 } 5693 6161 … … 5733 6201 const struct smb_filename *smb_fname, 5734 6202 const SMB_STRUCT_STAT *psbuf, 5735 SMB_OFF_Tsize,6203 off_t size, 5736 6204 bool fail_after_createfile) 5737 6205 { … … 5744 6212 } 5745 6213 5746 if (fsp && !(fsp->access_mask & FILE_WRITE_DATA)) {5747 return NT_STATUS_ACCESS_DENIED;5748 }5749 5750 6214 DEBUG(6,("smb_set_file_size: size: %.0f ", (double)size)); 5751 6215 … … 5759 6223 if (fsp && fsp->fh->fd != -1) { 5760 6224 /* Handle based call. */ 6225 if (!(fsp->access_mask & FILE_WRITE_DATA)) { 6226 return NT_STATUS_ACCESS_DENIED; 6227 } 6228 5761 6229 if (vfs_set_filelen(fsp, size) == -1) { 5762 6230 return map_nt_error_from_unix(errno); … … 5766 6234 } 5767 6235 5768 s tatus = copy_smb_filename(talloc_tos(), smb_fname, &smb_fname_tmp);5769 if ( !NT_STATUS_IS_OK(status)) {5770 return status;6236 smb_fname_tmp = cp_smb_filename(talloc_tos(), smb_fname); 6237 if (smb_fname_tmp == NULL) { 6238 return NT_STATUS_NO_MEMORY; 5771 6239 } 5772 6240 … … 5784 6252 0, /* create_options */ 5785 6253 FILE_ATTRIBUTE_NORMAL, /* file_attributes */ 5786 FORCE_OPLOCK_BREAK_TO_NONE, /* oplock_request */ 6254 0, /* oplock_request */ 6255 NULL, /* lease */ 5787 6256 0, /* allocation_size */ 5788 6257 0, /* private_flags */ … … 5790 6259 NULL, /* ea_list */ 5791 6260 &new_fsp, /* result */ 5792 NULL); /* pinfo */ 6261 NULL, /* pinfo */ 6262 NULL, NULL); /* create context */ 5793 6263 5794 6264 TALLOC_FREE(smb_fname_tmp); … … 5855 6325 } 5856 6326 5857 if (fsp && !(fsp->access_mask & FILE_WRITE_EA)) {5858 return NT_STATUS_ACCESS_DENIED;5859 }5860 5861 6327 status = set_ea(conn, fsp, smb_fname, ea_list); 5862 6328 … … 5900 6366 if (!ea_list) { 5901 6367 return NT_STATUS_INVALID_PARAMETER; 5902 }5903 5904 if (fsp && !(fsp->access_mask & FILE_WRITE_EA)) {5905 return NT_STATUS_ACCESS_DENIED;5906 6368 } 5907 6369 … … 5928 6390 NTSTATUS status = NT_STATUS_OK; 5929 6391 bool delete_on_close; 5930 uint32 dosmode = 0;6392 uint32_t dosmode = 0; 5931 6393 5932 6394 if (total_data < 1) { … … 5957 6419 if (!set_delete_on_close(fsp, delete_on_close, 5958 6420 conn->session_info->security_token, 5959 &conn->session_info->utok)) {6421 conn->session_info->unix_token)) { 5960 6422 return NT_STATUS_ACCESS_DENIED; 5961 6423 } … … 5984 6446 5985 6447 position_information = (uint64_t)IVAL(pdata,0); 5986 #ifdef LARGE_SMB_OFF_T5987 6448 position_information |= (((uint64_t)IVAL(pdata,4)) << 32); 5988 #else /* LARGE_SMB_OFF_T */5989 if (IVAL(pdata,4) != 0) {5990 /* more than 32 bits? */5991 return NT_STATUS_INVALID_PARAMETER;5992 }5993 #endif /* LARGE_SMB_OFF_T */5994 6449 5995 6450 DEBUG(10,("smb_file_position_information: Set file position " … … 6008 6463 int total_data) 6009 6464 { 6010 uint32 mode;6465 uint32_t mode; 6011 6466 6012 6467 if (total_data < 4) { … … 6041 6496 } 6042 6497 6043 if (!lp_ symlinks(SNUM(conn))) {6498 if (!lp_follow_symlinks(SNUM(conn))) { 6044 6499 return NT_STATUS_ACCESS_DENIED; 6045 6500 } … … 6073 6528 char *oldname = NULL; 6074 6529 struct smb_filename *smb_fname_old = NULL; 6530 uint32_t ucf_flags = (req->posix_pathnames ? UCF_POSIX_PATHNAMES : 0); 6075 6531 TALLOC_CTX *ctx = talloc_tos(); 6076 6532 NTSTATUS status = NT_STATUS_OK; … … 6081 6537 } 6082 6538 6083 srvstr_get_path(ctx, pdata, req->flags2, &oldname, pdata, 6084 total_data, STR_TERMINATE, &status); 6539 if (req->posix_pathnames) { 6540 srvstr_get_path_posix(ctx, 6541 pdata, 6542 req->flags2, 6543 &oldname, 6544 pdata, 6545 total_data, 6546 STR_TERMINATE, 6547 &status); 6548 } else { 6549 srvstr_get_path(ctx, 6550 pdata, 6551 req->flags2, 6552 &oldname, 6553 pdata, 6554 total_data, 6555 STR_TERMINATE, 6556 &status); 6557 } 6085 6558 if (!NT_STATUS_IS_OK(status)) { 6086 6559 return status; … … 6094 6567 req->flags2 & FLAGS2_DFS_PATHNAMES, 6095 6568 oldname, 6096 0,6569 ucf_flags, 6097 6570 NULL, 6098 6571 &smb_fname_old); … … 6120 6593 char *newname = NULL; 6121 6594 struct smb_filename *smb_fname_dst = NULL; 6595 uint32_t ucf_flags = UCF_SAVE_LCOMP | 6596 (req->posix_pathnames ? UCF_POSIX_PATHNAMES : 0); 6122 6597 NTSTATUS status = NT_STATUS_OK; 6123 6598 TALLOC_CTX *ctx = talloc_tos(); … … 6138 6613 } 6139 6614 6140 srvstr_get_path(ctx, pdata, req->flags2, &newname, 6141 &pdata[20], len, STR_TERMINATE, 6615 if (req->posix_pathnames) { 6616 srvstr_get_path_posix(ctx, 6617 pdata, 6618 req->flags2, 6619 &newname, 6620 &pdata[20], 6621 len, 6622 STR_TERMINATE, 6142 6623 &status); 6624 } else { 6625 srvstr_get_path(ctx, 6626 pdata, 6627 req->flags2, 6628 &newname, 6629 &pdata[20], 6630 len, 6631 STR_TERMINATE, 6632 &status); 6633 } 6143 6634 if (!NT_STATUS_IS_OK(status)) { 6144 6635 return status; … … 6152 6643 req->flags2 & FLAGS2_DFS_PATHNAMES, 6153 6644 newname, 6154 UCF_SAVE_LCOMP,6645 ucf_flags, 6155 6646 NULL, 6156 6647 &smb_fname_dst); … … 6166 6657 6167 6658 /* Create an smb_fname to call rename_internals_fsp() with. */ 6168 status = create_synthetic_smb_fname(talloc_tos(), 6169 fsp->base_fsp->fsp_name->base_name, newname, NULL, 6170 &smb_fname_dst); 6171 if (!NT_STATUS_IS_OK(status)) { 6659 smb_fname_dst = synthetic_smb_fname( 6660 talloc_tos(), fsp->base_fsp->fsp_name->base_name, 6661 newname, NULL); 6662 if (smb_fname_dst == NULL) { 6663 status = NT_STATUS_NO_MEMORY; 6172 6664 goto out; 6173 6665 } … … 6187 6679 6188 6680 DEBUG(10,("smb2_file_rename_information: " 6189 "SMB_FILE_RENAME_INFORMATION ( fnum %d) %s -> %s\n",6190 fsp ->fnum, fsp_str_dbg(fsp),6681 "SMB_FILE_RENAME_INFORMATION (%s) %s -> %s\n", 6682 fsp_fnum_dbg(fsp), fsp_str_dbg(fsp), 6191 6683 smb_fname_str_dbg(smb_fname_dst))); 6192 6684 status = rename_internals_fsp(conn, fsp, smb_fname_dst, … … 6211 6703 struct smb_filename *smb_fname_dst = NULL; 6212 6704 NTSTATUS status = NT_STATUS_OK; 6705 uint32_t ucf_flags = UCF_SAVE_LCOMP | 6706 (req->posix_pathnames ? UCF_POSIX_PATHNAMES : 0); 6213 6707 TALLOC_CTX *ctx = talloc_tos(); 6214 6708 … … 6228 6722 } 6229 6723 6230 srvstr_get_path(ctx, pdata, req->flags2, &newname, 6231 &pdata[20], len, STR_TERMINATE, 6724 if (req->posix_pathnames) { 6725 srvstr_get_path_posix(ctx, 6726 pdata, 6727 req->flags2, 6728 &newname, 6729 &pdata[20], 6730 len, 6731 STR_TERMINATE, 6232 6732 &status); 6733 } else { 6734 srvstr_get_path(ctx, 6735 pdata, 6736 req->flags2, 6737 &newname, 6738 &pdata[20], 6739 len, 6740 STR_TERMINATE, 6741 &status); 6742 } 6233 6743 if (!NT_STATUS_IS_OK(status)) { 6234 6744 return status; … … 6242 6752 req->flags2 & FLAGS2_DFS_PATHNAMES, 6243 6753 newname, 6244 UCF_SAVE_LCOMP,6754 ucf_flags, 6245 6755 NULL, 6246 6756 &smb_fname_dst); … … 6255 6765 6256 6766 DEBUG(10,("smb_file_link_information: " 6257 "SMB_FILE_LINK_INFORMATION ( fnum %d) %s -> %s\n",6258 fsp ->fnum, fsp_str_dbg(fsp),6767 "SMB_FILE_LINK_INFORMATION (%s) %s -> %s\n", 6768 fsp_fnum_dbg(fsp), fsp_str_dbg(fsp), 6259 6769 smb_fname_str_dbg(smb_fname_dst))); 6260 6770 status = hardlink_internals(ctx, … … 6281 6791 { 6282 6792 bool overwrite; 6283 uint32 root_fid;6284 uint32 len;6793 uint32_t root_fid; 6794 uint32_t len; 6285 6795 char *newname = NULL; 6286 6796 struct smb_filename *smb_fname_dst = NULL; … … 6302 6812 } 6303 6813 6304 srvstr_get_path_wcard(ctx, pdata, req->flags2, &newname, &pdata[12], 6305 len, 0, &status, 6306 &dest_has_wcard); 6814 if (req->posix_pathnames) { 6815 srvstr_get_path_wcard_posix(ctx, 6816 pdata, 6817 req->flags2, 6818 &newname, 6819 &pdata[12], 6820 len, 6821 0, 6822 &status, 6823 &dest_has_wcard); 6824 } else { 6825 srvstr_get_path_wcard(ctx, 6826 pdata, 6827 req->flags2, 6828 &newname, 6829 &pdata[12], 6830 len, 6831 0, 6832 &status, 6833 &dest_has_wcard); 6834 } 6307 6835 if (!NT_STATUS_IS_OK(status)) { 6308 6836 return status; … … 6316 6844 newname, 6317 6845 true, 6846 !conn->sconn->using_smb2, 6318 6847 &newname, 6319 6848 &dest_has_wcard); … … 6334 6863 6335 6864 /* Create an smb_fname to call rename_internals_fsp() with. */ 6336 status = create_synthetic_smb_fname(talloc_tos(), 6337 fsp->base_fsp->fsp_name->base_name, newname, NULL, 6338 &smb_fname_dst); 6339 if (!NT_STATUS_IS_OK(status)) { 6865 smb_fname_dst = synthetic_smb_fname( 6866 talloc_tos(), fsp->base_fsp->fsp_name->base_name, 6867 newname, NULL); 6868 if (smb_fname_dst == NULL) { 6869 status = NT_STATUS_NO_MEMORY; 6340 6870 goto out; 6341 6871 } … … 6405 6935 } 6406 6936 /* Create an smb_fname to call rename_internals_fsp() */ 6407 status = create_synthetic_smb_fname(ctx, 6408 base_name, NULL, 6409 NULL, 6410 &smb_fname_dst); 6411 if (!NT_STATUS_IS_OK(status)) { 6937 smb_fname_dst = synthetic_smb_fname( 6938 ctx, base_name, NULL, NULL); 6939 if (smb_fname_dst == NULL) { 6940 status = NT_STATUS_NO_MEMORY; 6412 6941 goto out; 6413 6942 } … … 6417 6946 if (fsp) { 6418 6947 DEBUG(10,("smb_file_rename_information: " 6419 "SMB_FILE_RENAME_INFORMATION ( fnum %d) %s -> %s\n",6420 fsp ->fnum, fsp_str_dbg(fsp),6948 "SMB_FILE_RENAME_INFORMATION (%s) %s -> %s\n", 6949 fsp_fnum_dbg(fsp), fsp_str_dbg(fsp), 6421 6950 smb_fname_str_dbg(smb_fname_dst))); 6422 6951 status = rename_internals_fsp(conn, fsp, smb_fname_dst, 0, … … 6448 6977 const struct smb_filename *smb_fname) 6449 6978 { 6450 uint16 posix_acl_version;6451 uint16 num_file_acls;6452 uint16 num_def_acls;6979 uint16_t posix_acl_version; 6980 uint16_t num_file_acls; 6981 uint16_t num_def_acls; 6453 6982 bool valid_file_acls = True; 6454 6983 bool valid_def_acls = True; 6984 NTSTATUS status; 6455 6985 6456 6986 if (total_data < SMB_POSIX_ACL_HEADER_SIZE) { … … 6478 7008 (num_file_acls+num_def_acls)*SMB_POSIX_ACL_ENTRY_SIZE) { 6479 7009 return NT_STATUS_INVALID_PARAMETER; 7010 } 7011 7012 status = refuse_symlink(conn, fsp, smb_fname->base_name); 7013 if (!NT_STATUS_IS_OK(status)) { 7014 return status; 6480 7015 } 6481 7016 … … 6558 7093 6559 7094 smblctx = (uint64_t)IVAL(pdata, POSIX_LOCK_PID_OFFSET); 6560 #if defined(HAVE_LONGLONG)6561 7095 offset = (((uint64_t) IVAL(pdata,(POSIX_LOCK_START_OFFSET+4))) << 32) | 6562 7096 ((uint64_t) IVAL(pdata,POSIX_LOCK_START_OFFSET)); 6563 7097 count = (((uint64_t) IVAL(pdata,(POSIX_LOCK_LEN_OFFSET+4))) << 32) | 6564 7098 ((uint64_t) IVAL(pdata,POSIX_LOCK_LEN_OFFSET)); 6565 #else /* HAVE_LONGLONG */6566 offset = (uint64_t)IVAL(pdata,POSIX_LOCK_START_OFFSET);6567 count = (uint64_t)IVAL(pdata,POSIX_LOCK_LEN_OFFSET);6568 #endif /* HAVE_LONGLONG */6569 7099 6570 7100 DEBUG(10,("smb_set_posix_lock: file %s, lock_type = %u," … … 6595 7125 blocking_lock, 6596 7126 &status, 6597 &block_smblctx, 6598 NULL); 7127 &block_smblctx); 6599 7128 6600 7129 if (br_lck && blocking_lock && ERROR_WAS_LOCK_DENIED(status)) { … … 6637 7166 /* Patch to do this correctly from Paul Eggert <eggert@twinsun.com>. */ 6638 7167 struct smb_file_time ft; 6639 uint32 dosmode = 0;7168 uint32_t dosmode = 0; 6640 7169 NTSTATUS status = NT_STATUS_OK; 6641 7170 … … 6646 7175 } 6647 7176 6648 if (fsp && !(fsp->access_mask & FILE_WRITE_ATTRIBUTES)) { 6649 return NT_STATUS_ACCESS_DENIED; 7177 status = check_access(conn, fsp, smb_fname, FILE_WRITE_ATTRIBUTES); 7178 if (!NT_STATUS_IS_OK(status)) { 7179 return status; 6650 7180 } 6651 7181 … … 6686 7216 const struct smb_filename *smb_fname) 6687 7217 { 7218 NTSTATUS status; 6688 7219 struct smb_file_time ft; 6689 7220 … … 6692 7223 if (total_data < 12) { 6693 7224 return NT_STATUS_INVALID_PARAMETER; 6694 }6695 6696 if (fsp && !(fsp->access_mask & FILE_WRITE_ATTRIBUTES)) {6697 return NT_STATUS_ACCESS_DENIED;6698 7225 } 6699 7226 … … 6707 7234 DEBUG(10,("smb_set_info_standard: file %s\n", 6708 7235 smb_fname_str_dbg(smb_fname))); 7236 7237 status = check_access(conn, fsp, smb_fname, FILE_WRITE_ATTRIBUTES); 7238 if (!NT_STATUS_IS_OK(status)) { 7239 return status; 7240 } 6709 7241 6710 7242 return smb_set_file_time(conn, … … 6739 7271 6740 7272 allocation_size = (uint64_t)IVAL(pdata,0); 6741 #ifdef LARGE_SMB_OFF_T6742 7273 allocation_size |= (((uint64_t)IVAL(pdata,4)) << 32); 6743 #else /* LARGE_SMB_OFF_T */6744 if (IVAL(pdata,4) != 0) {6745 /* more than 32 bits? */6746 return NT_STATUS_INVALID_PARAMETER;6747 }6748 #endif /* LARGE_SMB_OFF_T */6749 6750 7274 DEBUG(10,("smb_set_file_allocation_info: Set file allocation info for " 6751 7275 "file %s to %.0f\n", smb_fname_str_dbg(smb_fname), … … 6756 7280 } 6757 7281 6758 if (fsp && !(fsp->access_mask & FILE_WRITE_DATA)) {6759 return NT_STATUS_ACCESS_DENIED;6760 }6761 6762 7282 DEBUG(10,("smb_set_file_allocation_info: file %s : setting new " 6763 7283 "allocation size to %.0f\n", smb_fname_str_dbg(smb_fname), … … 6766 7286 if (fsp && fsp->fh->fd != -1) { 6767 7287 /* Open file handle. */ 7288 if (!(fsp->access_mask & FILE_WRITE_DATA)) { 7289 return NT_STATUS_ACCESS_DENIED; 7290 } 7291 6768 7292 /* Only change if needed. */ 6769 7293 if (allocation_size != get_file_size_stat(&smb_fname->st)) { … … 6793 7317 0, /* create_options */ 6794 7318 FILE_ATTRIBUTE_NORMAL, /* file_attributes */ 6795 FORCE_OPLOCK_BREAK_TO_NONE, /* oplock_request */ 7319 0, /* oplock_request */ 7320 NULL, /* lease */ 6796 7321 0, /* allocation_size */ 6797 7322 0, /* private_flags */ … … 6799 7324 NULL, /* ea_list */ 6800 7325 &new_fsp, /* result */ 6801 NULL); /* pinfo */ 7326 NULL, /* pinfo */ 7327 NULL, NULL); /* create context */ 6802 7328 6803 7329 if (!NT_STATUS_IS_OK(status)) { … … 6821 7347 */ 6822 7348 trigger_write_time_update_immediate(new_fsp); 6823 6824 7349 close_file(req, new_fsp, NORMAL_CLOSE); 6825 7350 return NT_STATUS_OK; … … 6838 7363 bool fail_after_createfile) 6839 7364 { 6840 SMB_OFF_Tsize;7365 off_t size; 6841 7366 6842 7367 if (total_data < 8) { … … 6845 7370 6846 7371 size = IVAL(pdata,0); 6847 #ifdef LARGE_SMB_OFF_T 6848 size |= (((SMB_OFF_T)IVAL(pdata,4)) << 32); 6849 #else /* LARGE_SMB_OFF_T */ 6850 if (IVAL(pdata,4) != 0) { 6851 /* more than 32 bits? */ 6852 return NT_STATUS_INVALID_PARAMETER; 6853 } 6854 #endif /* LARGE_SMB_OFF_T */ 7372 size |= (((off_t)IVAL(pdata,4)) << 32); 6855 7373 DEBUG(10,("smb_set_file_end_of_file_info: Set end of file info for " 6856 7374 "file %s to %.0f\n", smb_fname_str_dbg(smb_fname), 6857 7375 (double)size)); 6858 6859 if (fsp && !(fsp->access_mask & FILE_WRITE_DATA)) {6860 return NT_STATUS_ACCESS_DENIED;6861 }6862 7376 6863 7377 return smb_set_file_size(conn, req, … … 6878 7392 const struct smb_filename *smb_fname) 6879 7393 { 6880 uint32 file_type = IVAL(pdata,56);7394 uint32_t file_type = IVAL(pdata,56); 6881 7395 #if defined(HAVE_MAKEDEV) 6882 uint32 dev_major = IVAL(pdata,60);6883 uint32 dev_minor = IVAL(pdata,68);7396 uint32_t dev_major = IVAL(pdata,60); 7397 uint32_t dev_minor = IVAL(pdata,68); 6884 7398 #endif 6885 7399 SMB_DEV_T dev = (SMB_DEV_T)0; 6886 uint32 raw_unixmode = IVAL(pdata,84);7400 uint32_t raw_unixmode = IVAL(pdata,84); 6887 7401 NTSTATUS status; 6888 7402 mode_t unixmode; … … 6940 7454 */ 6941 7455 6942 if (lp_inherit_perm s(SNUM(conn))) {7456 if (lp_inherit_permissions(SNUM(conn))) { 6943 7457 char *parent; 6944 7458 if (!parent_dirname(talloc_tos(), smb_fname->base_name, … … 6966 7480 { 6967 7481 struct smb_file_time ft; 6968 uint32 raw_unixmode;7482 uint32_t raw_unixmode; 6969 7483 mode_t unixmode; 6970 SMB_OFF_Tsize = 0;7484 off_t size = 0; 6971 7485 uid_t set_owner = (uid_t)SMB_UID_NO_CHANGE; 6972 7486 gid_t set_grp = (uid_t)SMB_GID_NO_CHANGE; … … 6989 7503 IVAL(pdata, 4) != SMB_SIZE_NO_CHANGE_HI) { 6990 7504 size=IVAL(pdata,0); /* first 8 Bytes are size */ 6991 #ifdef LARGE_SMB_OFF_T 6992 size |= (((SMB_OFF_T)IVAL(pdata,4)) << 32); 6993 #else /* LARGE_SMB_OFF_T */ 6994 if (IVAL(pdata,4) != 0) { 6995 /* more than 32 bits? */ 6996 return NT_STATUS_INVALID_PARAMETER; 6997 } 6998 #endif /* LARGE_SMB_OFF_T */ 7505 size |= (((off_t)IVAL(pdata,4)) << 32); 6999 7506 } 7000 7507 … … 7044 7551 } 7045 7552 7046 status = copy_smb_filename(talloc_tos(), smb_fname, 7047 &smb_fname_tmp); 7048 if (!NT_STATUS_IS_OK(status)) { 7049 return status; 7553 smb_fname_tmp = cp_smb_filename(talloc_tos(), smb_fname); 7554 if (smb_fname_tmp == NULL) { 7555 return NT_STATUS_NO_MEMORY; 7050 7556 } 7051 7557 … … 7087 7593 7088 7594 if (raw_unixmode != SMB_MODE_NO_CHANGE) { 7595 int ret; 7596 7089 7597 DEBUG(10,("smb_set_file_unix_basic: SMB_SET_FILE_UNIX_BASIC " 7090 7598 "setting mode 0%o for file %s\n", 7091 7599 (unsigned int)unixmode, 7092 7600 smb_fname_str_dbg(smb_fname))); 7093 if (SMB_VFS_CHMOD(conn, smb_fname->base_name, unixmode) != 0) { 7601 if (fsp && fsp->fh->fd != -1) { 7602 ret = SMB_VFS_FCHMOD(fsp, unixmode); 7603 } else { 7604 ret = SMB_VFS_CHMOD(conn, smb_fname->base_name, unixmode); 7605 } 7606 if (ret != 0) { 7094 7607 return map_nt_error_from_unix(errno); 7095 7608 } … … 7109 7622 smb_fname_str_dbg(smb_fname))); 7110 7623 7111 if (S_ISLNK(sbuf.st_ex_mode)) { 7624 if (fsp && fsp->fh->fd != -1) { 7625 ret = SMB_VFS_FCHOWN(fsp, set_owner, (gid_t)-1); 7626 } else { 7627 /* 7628 * UNIX extensions calls must always operate 7629 * on symlinks. 7630 */ 7112 7631 ret = SMB_VFS_LCHOWN(conn, smb_fname->base_name, 7113 7632 set_owner, (gid_t)-1); 7114 } else {7115 ret = SMB_VFS_CHOWN(conn, smb_fname->base_name,7116 set_owner, (gid_t)-1);7117 7633 } 7118 7634 … … 7132 7648 if ((set_grp != (uid_t)SMB_GID_NO_CHANGE) && 7133 7649 (sbuf.st_ex_gid != set_grp)) { 7650 int ret; 7651 7134 7652 DEBUG(10,("smb_set_file_unix_basic: SMB_SET_FILE_UNIX_BASIC " 7135 7653 "changing group %u for file %s\n", 7136 7654 (unsigned int)set_owner, 7137 7655 smb_fname_str_dbg(smb_fname))); 7138 if (SMB_VFS_CHOWN(conn, smb_fname->base_name, (uid_t)-1, 7139 set_grp) != 0) { 7656 if (fsp && fsp->fh->fd != -1) { 7657 ret = SMB_VFS_FCHOWN(fsp, set_owner, (gid_t)-1); 7658 } else { 7659 /* 7660 * UNIX extensions calls must always operate 7661 * on symlinks. 7662 */ 7663 ret = SMB_VFS_LCHOWN(conn, smb_fname->base_name, (uid_t)-1, 7664 set_grp); 7665 } 7666 if (ret != 0) { 7140 7667 status = map_nt_error_from_unix(errno); 7141 7668 if (delete_on_fail) { … … 7209 7736 { 7210 7737 NTSTATUS status; 7211 uint32 smb_fflags;7212 uint32 smb_fmask;7738 uint32_t smb_fflags; 7739 uint32_t smb_fmask; 7213 7740 7214 7741 if (total_data < 116) { … … 7271 7798 { 7272 7799 NTSTATUS status = NT_STATUS_OK; 7273 uint32 raw_unixmode = 0;7274 uint32 mod_unixmode = 0;7800 uint32_t raw_unixmode = 0; 7801 uint32_t mod_unixmode = 0; 7275 7802 mode_t unixmode = (mode_t)0; 7276 7803 files_struct *fsp = NULL; 7277 uint16 info_level_return = 0;7804 uint16_t info_level_return = 0; 7278 7805 int info; 7279 7806 char *pdata = *ppdata; … … 7292 7819 } 7293 7820 7294 mod_unixmode = (uint32 )unixmode | FILE_FLAG_POSIX_SEMANTICS;7821 mod_unixmode = (uint32_t)unixmode | FILE_FLAG_POSIX_SEMANTICS; 7295 7822 7296 7823 DEBUG(10,("smb_posix_mkdir: file %s, mode 0%o\n", … … 7308 7835 mod_unixmode, /* file_attributes */ 7309 7836 0, /* oplock_request */ 7837 NULL, /* lease */ 7310 7838 0, /* allocation_size */ 7311 7839 0, /* private_flags */ … … 7313 7841 NULL, /* ea_list */ 7314 7842 &fsp, /* result */ 7315 &info); /* pinfo */ 7843 &info, /* pinfo */ 7844 NULL, NULL); /* create context */ 7316 7845 7317 7846 if (NT_STATUS_IS_OK(status)) { … … 7379 7908 bool extended_oplock_granted = False; 7380 7909 char *pdata = *ppdata; 7381 uint32 flags = 0;7382 uint32 wire_open_mode = 0;7383 uint32 raw_unixmode = 0;7384 uint32 mod_unixmode = 0;7385 uint32 create_disp = 0;7386 uint32 access_mask = 0;7387 uint32 create_options = FILE_NON_DIRECTORY_FILE;7910 uint32_t flags = 0; 7911 uint32_t wire_open_mode = 0; 7912 uint32_t raw_unixmode = 0; 7913 uint32_t mod_unixmode = 0; 7914 uint32_t create_disp = 0; 7915 uint32_t access_mask = 0; 7916 uint32_t create_options = FILE_NON_DIRECTORY_FILE; 7388 7917 NTSTATUS status = NT_STATUS_OK; 7389 7918 mode_t unixmode = (mode_t)0; … … 7391 7920 int oplock_request = 0; 7392 7921 int info = 0; 7393 uint16 info_level_return = 0;7922 uint16_t info_level_return = 0; 7394 7923 7395 7924 if (total_data < 18) { … … 7502 8031 } 7503 8032 7504 mod_unixmode = (uint32 )unixmode | FILE_FLAG_POSIX_SEMANTICS;8033 mod_unixmode = (uint32_t)unixmode | FILE_FLAG_POSIX_SEMANTICS; 7505 8034 7506 8035 if (wire_open_mode & SMB_O_SYNC) { … … 7540 8069 mod_unixmode, /* file_attributes */ 7541 8070 oplock_request, /* oplock_request */ 8071 NULL, /* lease */ 7542 8072 0, /* allocation_size */ 7543 8073 0, /* private_flags */ … … 7545 8075 NULL, /* ea_list */ 7546 8076 &fsp, /* result */ 7547 &info); /* pinfo */ 8077 &info, /* pinfo */ 8078 NULL, NULL); /* create context */ 7548 8079 7549 8080 if (!NT_STATUS_IS_OK(status)) { … … 7628 8159 NTSTATUS status = NT_STATUS_OK; 7629 8160 files_struct *fsp = NULL; 7630 uint16 flags = 0;8161 uint16_t flags = 0; 7631 8162 char del = 1; 7632 8163 int info = 0; … … 7670 8201 FILE_FLAG_POSIX_SEMANTICS|0777, /* file_attributes */ 7671 8202 0, /* oplock_request */ 8203 NULL, /* lease */ 7672 8204 0, /* allocation_size */ 7673 8205 0, /* private_flags */ … … 7675 8207 NULL, /* ea_list */ 7676 8208 &fsp, /* result */ 7677 &info); /* pinfo */ 8209 &info, /* pinfo */ 8210 NULL, NULL); /* create context */ 7678 8211 7679 8212 if (!NT_STATUS_IS_OK(status)) { … … 7686 8219 */ 7687 8220 7688 lck = get_share_mode_lock(talloc_tos(), fsp->file_id, NULL, NULL, 7689 NULL); 8221 lck = get_existing_share_mode_lock(talloc_tos(), fsp->file_id); 7690 8222 if (lck == NULL) { 7691 8223 DEBUG(0, ("smb_posix_unlink: Could not get share mode " … … 7700 8232 * on close disposition. 7701 8233 */ 7702 for (i=0; i<lck-> num_share_modes; i++) {7703 struct share_mode_entry *e = &lck-> share_modes[i];8234 for (i=0; i<lck->data->num_share_modes; i++) { 8235 struct share_mode_entry *e = &lck->data->share_modes[i]; 7704 8236 if (is_valid_share_mode_entry(e)) { 7705 8237 if (e->flags & SHARE_MODE_FLAG_POSIX_OPEN) { 8238 continue; 8239 } 8240 if (share_mode_stale_pid(lck->data, i)) { 7706 8241 continue; 7707 8242 } … … 7758 8293 } 7759 8294 7760 DEBUG(3,("smbd_do_setfilepathinfo: %s ( fnum %d) info_level=%d "8295 DEBUG(3,("smbd_do_setfilepathinfo: %s (%s) info_level=%d " 7761 8296 "totdata=%d\n", smb_fname_str_dbg(smb_fname), 7762 fsp ? fsp->fnum : -1, info_level, total_data)); 8297 fsp_fnum_dbg(fsp), 8298 info_level, total_data)); 7763 8299 7764 8300 switch (info_level) { … … 8028 8564 char *params = *pparams; 8029 8565 char *pdata = *ppdata; 8030 uint16 info_level;8566 uint16_t info_level; 8031 8567 struct smb_filename *smb_fname = NULL; 8032 8568 files_struct *fsp = NULL; … … 8052 8588 info_level = SVAL(params,2); 8053 8589 8054 status = copy_smb_filename(talloc_tos(), fsp->fsp_name, 8055 &smb_fname); 8056 if (!NT_STATUS_IS_OK(status)) { 8057 reply_nterror(req, status); 8590 smb_fname = cp_smb_filename(talloc_tos(), fsp->fsp_name); 8591 if (smb_fname == NULL) { 8592 reply_nterror(req, NT_STATUS_NO_MEMORY); 8058 8593 return; 8059 8594 } … … 8098 8633 8099 8634 SSVAL(params,0,0); 8100 send_trans2_replies(conn, req, params, 2,8635 send_trans2_replies(conn, req, NT_STATUS_OK, params, 2, 8101 8636 *ppdata, 0, 8102 8637 max_data_bytes); … … 8113 8648 if (SMB_VFS_FSTAT(fsp, &smb_fname->st) != 0) { 8114 8649 DEBUG(3,("call_trans2setfilepathinfo: fstat " 8115 "of fnum %d failed (%s)\n", fsp->fnum,8650 "of %s failed (%s)\n", fsp_fnum_dbg(fsp), 8116 8651 strerror(errno))); 8117 8652 reply_nterror(req, map_nt_error_from_unix(errno)); … … 8121 8656 } else { 8122 8657 char *fname = NULL; 8123 uint32_t ucf_flags = 0; 8658 uint32_t ucf_flags = (req->posix_pathnames ? 8659 UCF_POSIX_PATHNAMES : 0); 8124 8660 8125 8661 /* set path info */ … … 8130 8666 8131 8667 info_level = SVAL(params,0); 8132 srvstr_get_path(req, params, req->flags2, &fname, ¶ms[6], 8133 total_params - 6, STR_TERMINATE, 8668 if (req->posix_pathnames) { 8669 srvstr_get_path_posix(req, 8670 params, 8671 req->flags2, 8672 &fname, 8673 ¶ms[6], 8674 total_params - 6, 8675 STR_TERMINATE, 8134 8676 &status); 8677 } else { 8678 srvstr_get_path(req, 8679 params, 8680 req->flags2, 8681 &fname, 8682 ¶ms[6], 8683 total_params - 6, 8684 STR_TERMINATE, 8685 &status); 8686 } 8135 8687 if (!NT_STATUS_IS_OK(status)) { 8136 8688 reply_nterror(req, status); … … 8181 8733 } 8182 8734 8183 DEBUG(3,("call_trans2setfilepathinfo(%d) %s ( fnum %d) info_level=%d "8735 DEBUG(3,("call_trans2setfilepathinfo(%d) %s (%s) info_level=%d " 8184 8736 "totdata=%d\n", tran_call, smb_fname_str_dbg(smb_fname), 8185 fsp ? fsp->fnum : -1, info_level,total_data)); 8737 fsp_fnum_dbg(fsp), 8738 info_level,total_data)); 8186 8739 8187 8740 /* Realloc the parameter size */ … … 8202 8755 &data_return_size); 8203 8756 if (!NT_STATUS_IS_OK(status)) { 8204 if (open_was_deferred(req-> mid)) {8757 if (open_was_deferred(req->xconn, req->mid)) { 8205 8758 /* We have re-scheduled this call. */ 8206 8759 return; … … 8220 8773 } 8221 8774 8222 reply_nterror(req, status); 8775 /* 8776 * Invalid EA name needs to return 2 param bytes, 8777 * not a zero-length error packet. 8778 */ 8779 if (NT_STATUS_EQUAL(status, STATUS_INVALID_EA_NAME)) { 8780 send_trans2_replies(conn, req, status, params, 2, NULL, 0, 8781 max_data_bytes); 8782 } else { 8783 reply_nterror(req, status); 8784 } 8223 8785 return; 8224 8786 } 8225 8787 8226 send_trans2_replies(conn, req, params, 2, *ppdata, data_return_size,8788 send_trans2_replies(conn, req, NT_STATUS_OK, params, 2, *ppdata, data_return_size, 8227 8789 max_data_bytes); 8228 8790 … … 8245 8807 NTSTATUS status = NT_STATUS_OK; 8246 8808 struct ea_list *ea_list = NULL; 8809 uint32_t ucf_flags = (req->posix_pathnames ? UCF_POSIX_PATHNAMES : 0); 8247 8810 TALLOC_CTX *ctx = talloc_tos(); 8248 8811 … … 8257 8820 } 8258 8821 8259 srvstr_get_path(ctx, params, req->flags2, &directory, ¶ms[4], 8260 total_params - 4, STR_TERMINATE, 8822 if (req->posix_pathnames) { 8823 srvstr_get_path_posix(ctx, 8824 params, 8825 req->flags2, 8826 &directory, 8827 ¶ms[4], 8828 total_params - 4, 8829 STR_TERMINATE, 8261 8830 &status); 8831 } else { 8832 srvstr_get_path(ctx, 8833 params, 8834 req->flags2, 8835 &directory, 8836 ¶ms[4], 8837 total_params - 4, 8838 STR_TERMINATE, 8839 &status); 8840 } 8262 8841 if (!NT_STATUS_IS_OK(status)) { 8263 8842 reply_nterror(req, status); … … 8271 8850 req->flags2 & FLAGS2_DFS_PATHNAMES, 8272 8851 directory, 8273 0,8852 ucf_flags, 8274 8853 NULL, 8275 8854 &smb_dname); … … 8349 8928 SSVAL(params,0,0); 8350 8929 8351 send_trans2_replies(conn, req, params, 2, *ppdata, 0, max_data_bytes);8930 send_trans2_replies(conn, req, NT_STATUS_OK, params, 2, *ppdata, 0, max_data_bytes); 8352 8931 8353 8932 out: … … 8368 8947 { 8369 8948 char *params = *pparams; 8370 uint16 info_level;8949 uint16_t info_level; 8371 8950 8372 8951 if (total_params < 6) { … … 8404 8983 fnf_handle = 257; 8405 8984 8406 send_trans2_replies(conn, req, params, 6, *ppdata, 0, max_data_bytes);8985 send_trans2_replies(conn, req, NT_STATUS_OK, params, 6, *ppdata, 0, max_data_bytes); 8407 8986 8408 8987 return; … … 8435 9014 SSVAL(params,2,0); /* No EA errors */ 8436 9015 8437 send_trans2_replies(conn, req, params, 4, *ppdata, 0, max_data_bytes);9016 send_trans2_replies(conn, req, NT_STATUS_OK, params, 4, *ppdata, 0, max_data_bytes); 8438 9017 8439 9018 return; … … 8483 9062 } 8484 9063 8485 SSVAL( req->inbuf, smb_flg2,9064 SSVAL((discard_const_p(uint8_t, req->inbuf)), smb_flg2, 8486 9065 SVAL(req->inbuf,smb_flg2) | FLAGS2_DFS_PATHNAMES); 8487 send_trans2_replies(conn, req, 0,0,*ppdata,reply_size, max_data_bytes);9066 send_trans2_replies(conn, req, NT_STATUS_OK, 0,0,*ppdata,reply_size, max_data_bytes); 8488 9067 8489 9068 return; … … 8505 9084 char *pdata = *ppdata; 8506 9085 files_struct *fsp = file_fsp(req, SVAL(req->vwv+15, 0)); 9086 NTSTATUS status; 9087 size_t len = 0; 8507 9088 8508 9089 /* check for an invalid fid before proceeding */ … … 8526 9107 8527 9108 /* Job number */ 8528 if (fsp->print_file) { 8529 SSVAL(pdata, 0, fsp->print_file->rap_jobid); 8530 } else { 8531 SSVAL(pdata, 0, 0); 8532 } 8533 srvstr_push(pdata, req->flags2, pdata + 2, 8534 global_myname(), 15, 8535 STR_ASCII|STR_TERMINATE); /* Our NetBIOS name */ 8536 srvstr_push(pdata, req->flags2, pdata+18, 8537 lp_servicename(SNUM(conn)), 13, 8538 STR_ASCII|STR_TERMINATE); /* Service name */ 8539 send_trans2_replies(conn, req, *pparams, 0, *ppdata, 32, 9109 SSVAL(pdata, 0, print_spool_rap_jobid(fsp->print_file)); 9110 9111 status = srvstr_push(pdata, req->flags2, pdata + 2, 9112 lp_netbios_name(), 15, 9113 STR_ASCII|STR_TERMINATE, &len); /* Our NetBIOS name */ 9114 if (!NT_STATUS_IS_OK(status)) { 9115 reply_nterror(req, status); 9116 return; 9117 } 9118 status = srvstr_push(pdata, req->flags2, pdata+18, 9119 lp_servicename(talloc_tos(), SNUM(conn)), 13, 9120 STR_ASCII|STR_TERMINATE, &len); /* Service name */ 9121 if (!NT_STATUS_IS_OK(status)) { 9122 reply_nterror(req, status); 9123 return; 9124 } 9125 send_trans2_replies(conn, req, NT_STATUS_OK, *pparams, 0, *ppdata, 32, 8540 9126 max_data_bytes); 8541 9127 return; … … 8614 9200 if (get_Protocol() >= PROTOCOL_NT1) { 8615 9201 req->flags2 |= 0x40; /* IS_LONG_NAME */ 8616 SSVAL( req->inbuf,smb_flg2,req->flags2);8617 } 8618 8619 if ( conn->encrypt_level == Required&& !req->encrypted) {9202 SSVAL((discard_const_p(uint8_t, req->inbuf)),smb_flg2,req->flags2); 9203 } 9204 9205 if (ENCRYPTION_REQUIRED(conn) && !req->encrypted) { 8620 9206 if (state->call != TRANSACT2_QFSINFO && 8621 9207 state->call != TRANSACT2_SETFSINFO) { 8622 9208 DEBUG(0,("handle_trans2: encryption required " 8623 9209 "with call 0x%x\n", … … 8827 9413 } 8828 9414 8829 if ((state = TALLOC_P(conn, struct trans_state)) == NULL) {9415 if ((state = talloc(conn, struct trans_state)) == NULL) { 8830 9416 DEBUG(0, ("talloc failed\n")); 8831 9417 reply_nterror(req, NT_STATUS_NO_MEMORY); … … 8973 9559 START_PROFILE(SMBtranss2); 8974 9560 8975 show_msg((c har *)req->inbuf);9561 show_msg((const char *)req->inbuf); 8976 9562 8977 9563 /* Windows clients expect all replies to
Note:
See TracChangeset
for help on using the changeset viewer.