s3: Fix shadow copy display on Windows 7
[samba.git] / source / smbd / nttrans.c
index 7dcb0a95dd4bad5b1efc38a7971244a6b4c7ceba..c392380b5ec7e39adff73fe2a2c8b991c71dc464 100644 (file)
@@ -22,6 +22,7 @@
 
 extern int max_send;
 extern enum protocol_types Protocol;
+extern const struct generic_mapping file_generic_mapping;
 
 static char *nttrans_realloc(char **ptr, size_t size)
 {
@@ -713,7 +714,6 @@ static void do_nt_transact_create_pipe(connection_struct *conn,
 static NTSTATUS set_sd(files_struct *fsp, uint8 *data, uint32 sd_len,
                       uint32 security_info_sent)
 {
-       extern const struct generic_mapping file_generic_mapping;
        SEC_DESC *psd = NULL;
        NTSTATUS status;
 
@@ -727,23 +727,22 @@ static NTSTATUS set_sd(files_struct *fsp, uint8 *data, uint32 sd_len,
                return status;
        }
 
-       if (psd->owner_sid==0) {
+       if (psd->owner_sid == NULL) {
                security_info_sent &= ~OWNER_SECURITY_INFORMATION;
        }
-       if (psd->group_sid==0) {
+       if (psd->group_sid == NULL) {
                security_info_sent &= ~GROUP_SECURITY_INFORMATION;
        }
-       if (psd->sacl==0) {
-               security_info_sent &= ~SACL_SECURITY_INFORMATION;
-       }
-       if (psd->dacl==0) {
-               security_info_sent &= ~DACL_SECURITY_INFORMATION;
-       }
 
        /* Convert all the generic bits. */
        security_acl_map_generic(psd->dacl, &file_generic_mapping);
        security_acl_map_generic(psd->sacl, &file_generic_mapping);
 
+       if (DEBUGLEVEL >= 10) {
+               DEBUG(10,("set_sd for file %s\n", fsp->fsp_name ));
+               NDR_PRINT_DEBUG(security_descriptor, psd);
+       }
+
        status = SMB_VFS_FSET_NT_ACL(fsp, security_info_sent, psd);
 
        TALLOC_FREE(psd);
@@ -1077,7 +1076,7 @@ void reply_ntcancel(struct smb_request *req)
        START_PROFILE(SMBntcancel);
        remove_pending_change_notify_requests_by_mid(req->mid);
        remove_pending_lock_requests_by_mid(req->mid);
-       srv_cancel_sign_response(req->mid);
+       srv_cancel_sign_response(req->mid, true);
 
        DEBUG(3,("reply_ntcancel: cancel called on mid = %d.\n", req->mid));
 
@@ -1264,13 +1263,6 @@ void reply_ntrename(struct smb_request *req)
                return;
        }
 
-       if( is_ntfs_stream_name(oldname)) {
-               /* Can't rename a stream. */
-               reply_nterror(req, NT_STATUS_ACCESS_DENIED);
-               END_PROFILE(SMBntrename);
-               return;
-       }
-
        if (ms_has_wild(oldname)) {
                reply_nterror(req, NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
                END_PROFILE(SMBntrename);
@@ -1319,6 +1311,13 @@ void reply_ntrename(struct smb_request *req)
                return;
        }
 
+       /* The new name must begin with a ':' if the old name is a stream. */
+       if (is_ntfs_stream_name(oldname) && (newname[0] != ':')) {
+               reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
+               END_PROFILE(SMBntrename);
+               return;
+       }
+
        DEBUG(3,("reply_ntrename : %s -> %s\n",oldname,newname));
 
        switch(rename_type) {
@@ -1595,16 +1594,29 @@ static void call_nt_transact_query_security_desc(connection_struct *conn,
                status = SMB_VFS_FGET_NT_ACL(
                        fsp, security_info_wanted, &psd);
        }
-
        if (!NT_STATUS_IS_OK(status)) {
                reply_nterror(req, status);
                return;
        }
 
+       /* If the SACL/DACL is NULL, but was requested, we mark that it is
+        * present in the reply to match Windows behavior */
+       if (psd->sacl == NULL &&
+           security_info_wanted & SACL_SECURITY_INFORMATION)
+               psd->type |= SEC_DESC_SACL_PRESENT;
+       if (psd->dacl == NULL &&
+           security_info_wanted & DACL_SECURITY_INFORMATION)
+               psd->type |= SEC_DESC_DACL_PRESENT;
+
        sd_size = ndr_size_security_descriptor(psd, 0);
 
        DEBUG(3,("call_nt_transact_query_security_desc: sd_size = %lu.\n",(unsigned long)sd_size));
 
+       if (DEBUGLEVEL >= 10) {
+               DEBUG(10,("call_nt_transact_query_security_desc for file %s\n", fsp->fsp_name ));
+               NDR_PRINT_DEBUG(security_descriptor, psd);
+       }
+
        SIVAL(params,0,(uint32)sd_size);
 
        if (max_data_count < sd_size) {
@@ -1892,7 +1904,7 @@ static void call_nt_transact_ioctl(connection_struct *conn,
                }
 
                /* needed_data_count 4 bytes */
-               SIVAL(pdata,8,labels_data_count);
+               SIVAL(pdata, 8, labels_data_count+4);
 
                cur_pdata+=12;
 
@@ -2813,10 +2825,10 @@ void reply_nttranss(struct smb_request *req)
                        goto bad_param;
                }
 
-               if (ddisp > av_size ||
+               if (doff > av_size ||
                                dcnt > av_size ||
-                               ddisp+dcnt > av_size ||
-                               ddisp+dcnt < ddisp) {
+                               doff+dcnt > av_size ||
+                               doff+dcnt < doff) {
                        goto bad_param;
                }