Changeset 228 for branches/samba-3.2.x/source/smbd/open.c
- Timestamp:
- May 26, 2009, 9:44:50 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/samba-3.2.x/source/smbd/open.c
r204 r228 285 285 (!file_existed && (local_flags & O_CREAT)) || 286 286 ((local_flags & O_TRUNC) == O_TRUNC) ) { 287 const char *wild; 287 288 288 289 /* … … 306 307 307 308 /* Don't create files with Microsoft wildcard characters. */ 309 if (fsp->base_fsp) { 310 /* 311 * wildcard characters are allowed in stream names 312 * only test the basefilename 313 */ 314 wild = fsp->base_fsp->fsp_name; 315 } else { 316 wild = path; 317 } 308 318 if ((local_flags & O_CREAT) && !file_existed && 309 ms_has_wild( path)) {319 ms_has_wild(wild)) { 310 320 return NT_STATUS_OBJECT_NAME_INVALID; 311 321 } … … 405 415 current_user_info.smb_name : conn->user,fsp->fsp_name, 406 416 BOOLSTR(fsp->can_read), BOOLSTR(fsp->can_write), 407 conn->num_files_open + 1));417 conn->num_files_open)); 408 418 409 419 errno = 0; … … 894 904 ****************************************************************************/ 895 905 896 static files_struct *fcb_or_dos_open(connection_struct *conn, 906 static NTSTATUS fcb_or_dos_open(connection_struct *conn, 907 files_struct *fsp_to_dup_into, 897 908 const char *fname, 898 909 struct file_id id, … … 904 915 { 905 916 files_struct *fsp; 906 files_struct *dup_fsp;907 917 908 918 DEBUG(5,("fcb_or_dos_open: attempting old open semantics for " … … 933 943 934 944 if (!fsp) { 935 return N ULL;945 return NT_STATUS_NOT_FOUND; 936 946 } 937 947 … … 940 950 (fsp->fh->private_options & NTCREATEX_OPTIONS_PRIVATE_DENY_DOS)) { 941 951 DEBUG(10,("fcb_or_dos_open: file fail due to is_executable.\n")); 942 return N ULL;952 return NT_STATUS_INVALID_PARAMETER; 943 953 } 944 954 945 955 /* We need to duplicate this fsp. */ 946 if (!NT_STATUS_IS_OK(dup_file_fsp(fsp, access_mask, share_access, 947 create_options, &dup_fsp))) { 948 return NULL; 949 } 950 951 return dup_fsp; 956 dup_file_fsp(fsp, access_mask, share_access, 957 create_options, fsp_to_dup_into); 958 959 return NT_STATUS_OK; 952 960 } 953 961 … … 1129 1137 1130 1138 /**************************************************************************** 1131 Open a file with a share mode. 1139 Open a file with a share mode. Passed in an already created files_struct *. 1132 1140 ****************************************************************************/ 1133 1141 1134 NTSTATUS open_file_ntcreate(connection_struct *conn,1142 static NTSTATUS open_file_ntcreate_internal(connection_struct *conn, 1135 1143 struct smb_request *req, 1136 1144 const char *fname, … … 1144 1152 /* Information (FILE_EXISTS etc.) */ 1145 1153 int *pinfo, 1146 files_struct * *result)1154 files_struct *fsp) 1147 1155 { 1148 1156 int flags=0; … … 1154 1162 struct file_id id; 1155 1163 NTSTATUS fsp_open = NT_STATUS_ACCESS_DENIED; 1156 files_struct *fsp = NULL;1157 1164 mode_t new_unx_mode = (mode_t)0; 1158 1165 mode_t unx_mode = (mode_t)0; … … 1171 1178 1172 1179 if (conn->printer) { 1173 /* 1180 /* 1174 1181 * Printers are handled completely differently. 1175 1182 * Most of the passed parameters are ignored. … … 1182 1189 DEBUG(10, ("open_file_ntcreate: printer open fname=%s\n", fname)); 1183 1190 1184 return print_fsp_open(conn, fname, result);1191 return print_fsp_open(conn, fname, fsp); 1185 1192 } 1186 1193 … … 1439 1446 } 1440 1447 1441 status = file_new(conn, &fsp);1442 if(!NT_STATUS_IS_OK(status)) {1443 return status;1444 }1445 1446 1448 fsp->file_id = vfs_file_id_from_sbuf(conn, psbuf); 1447 1449 fsp->share_access = share_access; … … 1468 1470 1469 1471 if (lck == NULL) { 1470 file_free(fsp);1471 1472 DEBUG(0, ("Could not get share mode lock\n")); 1472 1473 return NT_STATUS_SHARING_VIOLATION; … … 1479 1480 schedule_defer_open(lck, request_time, req); 1480 1481 TALLOC_FREE(lck); 1481 file_free(fsp);1482 1482 return NT_STATUS_SHARING_VIOLATION; 1483 1483 } … … 1499 1499 schedule_defer_open(lck, request_time, req); 1500 1500 TALLOC_FREE(lck); 1501 file_free(fsp);1502 1501 return NT_STATUS_SHARING_VIOLATION; 1503 1502 } … … 1507 1506 /* DELETE_PENDING is not deferred for a second */ 1508 1507 TALLOC_FREE(lck); 1509 file_free(fsp);1510 1508 return status; 1511 1509 } … … 1522 1520 (NTCREATEX_OPTIONS_PRIVATE_DENY_DOS| 1523 1521 NTCREATEX_OPTIONS_PRIVATE_DENY_FCB)) { 1524 files_struct *fsp_dup;1525 1526 1522 if (req == NULL) { 1527 1523 DEBUG(0, ("DOS open without an SMB " 1528 1524 "request!\n")); 1529 1525 TALLOC_FREE(lck); 1530 file_free(fsp);1531 1526 return NT_STATUS_INTERNAL_ERROR; 1532 1527 } … … 1534 1529 /* Use the client requested access mask here, 1535 1530 * not the one we open with. */ 1536 fsp_dup = fcb_or_dos_open(conn, fname, id, 1531 status = fcb_or_dos_open(conn, 1532 fsp, 1533 fname, 1534 id, 1537 1535 req->smbpid, 1538 1536 req->vuid, … … 1541 1539 create_options); 1542 1540 1543 if ( fsp_dup) {1541 if (NT_STATUS_IS_OK(status)) { 1544 1542 TALLOC_FREE(lck); 1545 file_free(fsp);1546 1543 if (pinfo) { 1547 1544 *pinfo = FILE_WAS_OPENED; 1548 1545 } 1549 conn->num_files_open++;1550 *result = fsp_dup;1551 1546 return NT_STATUS_OK; 1552 1547 } … … 1629 1624 status = NT_STATUS_ACCESS_DENIED; 1630 1625 } 1631 file_free(fsp);1632 1626 return status; 1633 1627 } … … 1667 1661 TALLOC_FREE(lck); 1668 1662 } 1669 file_free(fsp);1670 1663 return fsp_open; 1671 1664 } … … 1698 1691 "mode lock for %s\n", fname)); 1699 1692 fd_close(fsp); 1700 file_free(fsp);1701 1693 return NT_STATUS_SHARING_VIOLATION; 1702 1694 } … … 1709 1701 TALLOC_FREE(lck); 1710 1702 fd_close(fsp); 1711 file_free(fsp);1712 1703 return NT_STATUS_SHARING_VIOLATION; 1713 1704 } … … 1728 1719 TALLOC_FREE(lck); 1729 1720 fd_close(fsp); 1730 file_free(fsp);1731 1721 return NT_STATUS_SHARING_VIOLATION; 1732 1722 } … … 1737 1727 1738 1728 fd_close(fsp); 1739 file_free(fsp);1740 1729 1741 1730 state.delayed_for_oplocks = False; … … 1779 1768 TALLOC_FREE(lck); 1780 1769 fd_close(fsp); 1781 file_free(fsp);1782 1770 1783 1771 return NT_STATUS_SHARING_VIOLATION; … … 1805 1793 TALLOC_FREE(lck); 1806 1794 fd_close(fsp); 1807 file_free(fsp);1808 1795 return status; 1809 1796 } … … 1865 1852 TALLOC_FREE(lck); 1866 1853 fd_close(fsp); 1867 file_free(fsp);1868 1854 return status; 1869 1855 } … … 1941 1927 TALLOC_FREE(lck); 1942 1928 1943 conn->num_files_open++; 1929 return NT_STATUS_OK; 1930 } 1931 1932 /**************************************************************************** 1933 Open a file with a share mode. 1934 ****************************************************************************/ 1935 1936 NTSTATUS open_file_ntcreate(connection_struct *conn, 1937 struct smb_request *req, 1938 const char *fname, 1939 SMB_STRUCT_STAT *psbuf, 1940 uint32 access_mask, /* access bits (FILE_READ_DATA etc.) */ 1941 uint32 share_access, /* share constants (FILE_SHARE_READ etc) */ 1942 uint32 create_disposition, /* FILE_OPEN_IF etc. */ 1943 uint32 create_options, /* options such as delete on close. */ 1944 uint32 new_dos_attributes, /* attributes used for new file. */ 1945 int oplock_request, /* internal Samba oplock codes. */ 1946 /* Information (FILE_EXISTS etc.) */ 1947 int *pinfo, 1948 files_struct **result) 1949 { 1950 NTSTATUS status; 1951 files_struct *fsp = NULL; 1952 1953 *result = NULL; 1954 1955 status = file_new(conn, &fsp); 1956 if(!NT_STATUS_IS_OK(status)) { 1957 return status; 1958 } 1959 1960 status = open_file_ntcreate_internal(conn, 1961 req, 1962 fname, 1963 psbuf, 1964 access_mask, 1965 share_access, 1966 create_disposition, 1967 create_options, 1968 new_dos_attributes, 1969 oplock_request, 1970 pinfo, 1971 fsp); 1972 1973 if(!NT_STATUS_IS_OK(status)) { 1974 file_free(fsp); 1975 return status; 1976 } 1944 1977 1945 1978 *result = fsp; 1946 return NT_STATUS_OK;1979 return status; 1947 1980 } 1948 1981 … … 1971 2004 0, FILE_WRITE_DATA, FILE_WRITE_DATA); 1972 2005 1973 /* 2006 /* 1974 2007 * This is not a user visible file open. 1975 * Don't set a share mode and don't increment 1976 * the conn->num_files_open. 2008 * Don't set a share mode. 1977 2009 */ 1978 2010 … … 2279 2311 } 2280 2312 2281 conn->num_files_open++;2282 2283 2313 *result = fsp; 2284 2314 return NT_STATUS_OK; … … 2355 2385 string_set(&fsp->fsp_name,fname); 2356 2386 2357 conn->num_files_open++;2358 2359 2387 *result = fsp; 2360 2388 return NT_STATUS_OK; … … 2663 2691 && (share_access & FILE_SHARE_DELETE) 2664 2692 && (access_mask & DELETE_ACCESS) 2665 && (((dos_mode(conn, fname, &sbuf) & FILE_ATTRIBUTE_READONLY) 2666 && !lp_delete_readonly(SNUM(conn))) 2667 || !can_delete_file_in_directory(conn, fname))) { 2693 && (!can_delete_file_in_directory(conn, fname))) { 2668 2694 status = NT_STATUS_ACCESS_DENIED; 2669 2695 goto fail; … … 2710 2736 break; 2711 2737 } 2738 2739 DEBUG(10, ("Recursing into create_file_unixpath for " 2740 "base %s\n", base)); 2712 2741 2713 2742 status = create_file_unixpath(conn, NULL, base, 0, … … 2723 2752 goto fail; 2724 2753 } 2754 /* we don't need to low level fd */ 2755 fd_close(base_fsp); 2725 2756 } 2726 2757 … … 2759 2790 */ 2760 2791 2761 status = open_file_ntcreate( 2762 conn, req, fname, &sbuf, access_mask, share_access, 2763 create_disposition, create_options, file_attributes, 2764 oplock_request, &info, &fsp); 2792 if (base_fsp) { 2793 /* 2794 * We're opening the stream element of a base_fsp 2795 * we already opened. We need to initialize 2796 * the fsp first, and set up the base_fsp pointer. 2797 */ 2798 status = file_new(conn, &fsp); 2799 if(!NT_STATUS_IS_OK(status)) { 2800 goto fail; 2801 } 2802 2803 fsp->base_fsp = base_fsp; 2804 2805 status = open_file_ntcreate_internal(conn, 2806 req, 2807 fname, 2808 &sbuf, 2809 access_mask, 2810 share_access, 2811 create_disposition, 2812 create_options, 2813 file_attributes, 2814 oplock_request, 2815 &info, 2816 fsp); 2817 2818 if(!NT_STATUS_IS_OK(status)) { 2819 file_free(fsp); 2820 fsp = NULL; 2821 } 2822 } else { 2823 status = open_file_ntcreate( 2824 conn, req, fname, &sbuf, access_mask, share_access, 2825 create_disposition, create_options, file_attributes, 2826 oplock_request, &info, &fsp); 2827 } 2765 2828 2766 2829 if (NT_STATUS_EQUAL(status, NT_STATUS_FILE_IS_A_DIRECTORY)) { 2830 2831 /* A stream open never opens a directory */ 2832 2833 if (base_fsp) { 2834 status = NT_STATUS_FILE_IS_A_DIRECTORY; 2835 goto fail; 2836 } 2767 2837 2768 2838 /* … … 2788 2858 goto fail; 2789 2859 } 2860 2861 fsp->base_fsp = base_fsp; 2790 2862 2791 2863 /* … … 2866 2938 DEBUG(10, ("create_file_unixpath: info=%d\n", info)); 2867 2939 2868 /*2869 * Set fsp->base_fsp late enough that we can't "goto fail" anymore. In2870 * the fail: branch we call close_file(fsp, ERROR_CLOSE) which would2871 * also close fsp->base_fsp which we have to also do explicitly in2872 * this routine here, as not in all "goto fail:" we have the fsp set2873 * up already to be initialized with the base_fsp.2874 */2875 2876 fsp->base_fsp = base_fsp;2877 2878 2940 *result = fsp; 2879 2941 if (pinfo != NULL) { … … 2894 2956 2895 2957 if (fsp != NULL) { 2958 if (base_fsp && fsp->base_fsp == base_fsp) { 2959 /* 2960 * The close_file below will close 2961 * fsp->base_fsp. 2962 */ 2963 base_fsp = NULL; 2964 } 2896 2965 close_file(fsp, ERROR_CLOSE); 2897 2966 fsp = NULL; … … 3053 3122 * close it 3054 3123 */ 3124 3055 3125 status = open_fake_file(conn, fake_file_type, fname, 3056 3126 access_mask, &fsp);
Note:
See TracChangeset
for help on using the changeset viewer.