s3/smbd: redesign macOS copyfile copy-chunk
[vlendec/samba-autobuild/.git] / source3 / smbd / nttrans.c
index 6d9db1f52d68161e4e27a05791f36bc4e020f2d0..7b7f2056099e9cde7ac4deac84f21f79d32ca507 100644 (file)
@@ -461,8 +461,7 @@ void reply_ntcreate_and_X(struct smb_request *req)
        int oplock_request;
        uint8_t oplock_granted = NO_OPLOCK_RETURN;
        struct case_semantics_state *case_state = NULL;
-       uint32_t ucf_flags = UCF_PREP_CREATEFILE |
-                       (lp_posix_pathnames() ? UCF_POSIX_PATHNAMES : 0);
+       uint32_t ucf_flags;
        TALLOC_CTX *ctx = talloc_tos();
 
        START_PROFILE(SMBntcreateX);
@@ -536,9 +535,9 @@ void reply_ntcreate_and_X(struct smb_request *req)
                }
        }
 
+       ucf_flags = filename_create_ucf_flags(req, create_disposition);
        status = filename_convert(ctx,
                                conn,
-                               req->flags2 & FLAGS2_DFS_PATHNAMES,
                                fname,
                                ucf_flags,
                                NULL,
@@ -688,17 +687,20 @@ void reply_ntcreate_and_X(struct smb_request *req)
        p += 8;
        if (flags & EXTENDED_RESPONSE_REQUIRED) {
                uint16_t file_status = (NO_EAS|NO_SUBSTREAMS|NO_REPARSETAG);
-               size_t num_names = 0;
                unsigned int num_streams = 0;
                struct stream_struct *streams = NULL;
 
-               /* Do we have any EA's ? */
-               status = get_ea_names_from_file(ctx, conn, fsp,
-                               smb_fname->base_name, NULL, &num_names);
-               if (NT_STATUS_IS_OK(status) && num_names) {
-                       file_status &= ~NO_EAS;
+               if (lp_ea_support(SNUM(conn))) {
+                       size_t num_names = 0;
+                       /* Do we have any EA's ? */
+                       status = get_ea_names_from_file(
+                           ctx, conn, fsp, smb_fname, NULL, &num_names);
+                       if (NT_STATUS_IS_OK(status) && num_names) {
+                               file_status &= ~NO_EAS;
+                       }
                }
-               status = vfs_streaminfo(conn, NULL, smb_fname->base_name, ctx,
+
+               status = vfs_streaminfo(conn, NULL, smb_fname, ctx,
                        &num_streams, &streams);
                /* There is always one stream, ::$DATA. */
                if (NT_STATUS_IS_OK(status) && num_streams > 1) {
@@ -762,7 +764,7 @@ static void do_nt_transact_create_pipe(connection_struct *conn,
 
        flags = IVAL(params,0);
 
-       if (lp_posix_pathnames()) {
+       if (req->posix_pathnames) {
                srvstr_get_path_posix(ctx,
                        params,
                        req->flags2,
@@ -893,6 +895,12 @@ NTSTATUS set_sd(files_struct *fsp, struct security_descriptor *psd,
                return NT_STATUS_OK;
        }
 
+       if (S_ISLNK(fsp->fsp_name->st.st_ex_mode)) {
+               DEBUG(10, ("ACL set on symlink %s denied.\n",
+                       fsp_str_dbg(fsp)));
+               return NT_STATUS_ACCESS_DENIED;
+       }
+
        if (psd->owner_sid == NULL) {
                security_info_sent &= ~SECINFO_OWNER;
        }
@@ -1018,8 +1026,7 @@ static void call_nt_transact_create(connection_struct *conn,
        int oplock_request;
        uint8_t oplock_granted;
        struct case_semantics_state *case_state = NULL;
-       uint32_t ucf_flags = UCF_PREP_CREATEFILE |
-                       (lp_posix_pathnames() ? UCF_POSIX_PATHNAMES : 0);
+       uint32_t ucf_flags;
        TALLOC_CTX *ctx = talloc_tos();
 
        DEBUG(5,("call_nt_transact_create\n"));
@@ -1068,7 +1075,7 @@ static void call_nt_transact_create(connection_struct *conn,
         */
        create_options &= ~NTCREATEX_OPTIONS_MUST_IGNORE_MASK;
 
-       if (lp_posix_pathnames()) {
+       if (req->posix_pathnames) {
                srvstr_get_path_posix(ctx,
                        params,
                        req->flags2,
@@ -1100,9 +1107,9 @@ static void call_nt_transact_create(connection_struct *conn,
                }
        }
 
+       ucf_flags = filename_create_ucf_flags(req, create_disposition);
        status = filename_convert(ctx,
                                conn,
-                               req->flags2 & FLAGS2_DFS_PATHNAMES,
                                fname,
                                ucf_flags,
                                NULL,
@@ -1172,7 +1179,8 @@ static void call_nt_transact_create(connection_struct *conn,
                        goto out;
                }
 
-               if (ea_list_has_invalid_name(ea_list)) {
+               if (!req->posix_pathnames &&
+                               ea_list_has_invalid_name(ea_list)) {
                        /* Realloc the size of parameters and data we will return */
                        if (flags & EXTENDED_RESPONSE_REQUIRED) {
                                /* Extended response is 32 more byyes. */
@@ -1327,17 +1335,20 @@ static void call_nt_transact_create(connection_struct *conn,
        p += 8;
        if (flags & EXTENDED_RESPONSE_REQUIRED) {
                uint16_t file_status = (NO_EAS|NO_SUBSTREAMS|NO_REPARSETAG);
-               size_t num_names = 0;
                unsigned int num_streams = 0;
                struct stream_struct *streams = NULL;
 
-               /* Do we have any EA's ? */
-               status = get_ea_names_from_file(ctx, conn, fsp,
-                               smb_fname->base_name, NULL, &num_names);
-               if (NT_STATUS_IS_OK(status) && num_names) {
-                       file_status &= ~NO_EAS;
+               if (lp_ea_support(SNUM(conn))) {
+                       size_t num_names = 0;
+                       /* Do we have any EA's ? */
+                       status = get_ea_names_from_file(
+                           ctx, conn, fsp, smb_fname, NULL, &num_names);
+                       if (NT_STATUS_IS_OK(status) && num_names) {
+                               file_status &= ~NO_EAS;
+                       }
                }
-               status = vfs_streaminfo(conn, NULL, smb_fname->base_name, ctx,
+
+               status = vfs_streaminfo(conn, NULL, smb_fname, ctx,
                        &num_streams, &streams);
                /* There is always one stream, ::$DATA. */
                if (NT_STATUS_IS_OK(status) && num_streams > 1) {
@@ -1560,8 +1571,8 @@ void reply_ntrename(struct smb_request *req)
        bool src_has_wcard = False;
        bool dest_has_wcard = False;
        uint32_t attrs;
-       uint32_t ucf_flags_src = (lp_posix_pathnames() ? UCF_POSIX_PATHNAMES : 0);
-       uint32_t ucf_flags_dst = (lp_posix_pathnames() ? UCF_POSIX_PATHNAMES : 0);
+       uint32_t ucf_flags_src = ucf_flags_from_smb_request(req);
+       uint32_t ucf_flags_dst = ucf_flags_from_smb_request(req);
        uint16_t rename_type;
        TALLOC_CTX *ctx = talloc_tos();
        bool stream_rename = false;
@@ -1584,7 +1595,7 @@ void reply_ntrename(struct smb_request *req)
                goto out;
        }
 
-       if (!lp_posix_pathnames() && ms_has_wild(oldname)) {
+       if (!req->posix_pathnames && ms_has_wild(oldname)) {
                reply_nterror(req, NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
                goto out;
        }
@@ -1597,7 +1608,7 @@ void reply_ntrename(struct smb_request *req)
                goto out;
        }
 
-       if (!lp_posix_pathnames()) {
+       if (!req->posix_pathnames) {
                /* The newname must begin with a ':' if the
                   oldname contains a ':'. */
                if (strchr_m(oldname, ':')) {
@@ -1614,13 +1625,12 @@ void reply_ntrename(struct smb_request *req)
         * destination's last component.
         */
        if (rename_type == RENAME_FLAG_RENAME) {
-               ucf_flags_src = UCF_COND_ALLOW_WCARD_LCOMP;
-               ucf_flags_dst = UCF_COND_ALLOW_WCARD_LCOMP | UCF_SAVE_LCOMP;
+               ucf_flags_src |= UCF_COND_ALLOW_WCARD_LCOMP;
+               ucf_flags_dst |= UCF_COND_ALLOW_WCARD_LCOMP | UCF_SAVE_LCOMP;
        }
 
        /* rename_internals() calls unix_convert(), so don't call it here. */
        status = filename_convert(ctx, conn,
-                                 req->flags2 & FLAGS2_DFS_PATHNAMES,
                                  oldname,
                                  ucf_flags_src,
                                  NULL,
@@ -1638,7 +1648,6 @@ void reply_ntrename(struct smb_request *req)
        }
 
        status = filename_convert(ctx, conn,
-                                 req->flags2 & FLAGS2_DFS_PATHNAMES,
                                  newname,
                                  ucf_flags_dst,
                                  &dest_has_wcard,
@@ -1867,7 +1876,7 @@ static void call_nt_transact_rename(connection_struct *conn,
        if (!check_fsp(conn, req, fsp)) {
                return;
        }
-       if (lp_posix_pathnames()) {
+       if (req->posix_pathnames) {
                srvstr_get_path_wcard_posix(ctx,
                                params,
                                req->flags2,
@@ -1960,6 +1969,13 @@ NTSTATUS smbd_do_query_security_desc(connection_struct *conn,
                return NT_STATUS_ACCESS_DENIED;
        }
 
+       if (S_ISLNK(fsp->fsp_name->st.st_ex_mode)) {
+               DEBUG(10, ("ACL get on symlink %s denied.\n",
+                       fsp_str_dbg(fsp)));
+               TALLOC_FREE(frame);
+               return NT_STATUS_ACCESS_DENIED;
+       }
+
        if (security_info_wanted & (SECINFO_DACL|SECINFO_OWNER|
                        SECINFO_GROUP|SECINFO_SACL)) {
                /* Don't return SECINFO_LABEL if anything else was
@@ -2310,7 +2326,7 @@ static void call_nt_transact_get_user_quota(connection_struct *conn,
        ZERO_STRUCT(qt);
 
        /* access check */
-       if (get_current_uid(conn) != 0) {
+       if (get_current_uid(conn) != sec_initial_uid()) {
                DEBUG(1,("get_user_quota: access_denied service [%s] user "
                         "[%s]\n", lp_servicename(talloc_tos(), SNUM(conn)),
                         conn->session_info->unix_info->unix_name));
@@ -2495,13 +2511,11 @@ static void call_nt_transact_get_user_quota(connection_struct *conn,
                                return;
                        }
 
-                       if (vfs_get_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
-                               ZERO_STRUCT(qt);
-                               /*
-                                * we have to return zero's in all fields
-                                * instead of returning an error here
-                                * --metze
-                                */
+                       nt_status = vfs_get_ntquota(fsp, SMB_USER_QUOTA_TYPE,
+                                                   &sid, &qt);
+                       if (!NT_STATUS_IS_OK(nt_status)) {
+                               reply_nterror(req, nt_status);
+                               return;
                        }
 
                        /* Realloc the size of parameters and data we will return */