int params_sent_thistime, data_sent_thistime, total_sent_thistime;
int alignment_offset = 3;
int data_alignment_offset = 0;
+ struct smbd_server_connection *sconn = smbd_server_conn;
+ int max_send = sconn->smb1.sessions.max_send;
/*
* If there genuinely are no parameters or data to send just send
show_msg((char *)req->outbuf);
if (!srv_send_smb(smbd_server_fd(),
(char *)req->outbuf,
+ true, req->seqnum+1,
IS_CONN_ENCRYPTED(conn),
&req->pcd)) {
exit_server_cleanly("send_nt_replies: srv_send_smb failed.");
return true;
}
+/****************************************************************************
+ Simple check to determine if the filename is a stream.
+ ***************************************************************************/
+bool is_ntfs_stream_smb_fname(const struct smb_filename *smb_fname)
+{
+ if (lp_posix_pathnames()) {
+ return false;
+ }
+
+ return smb_fname->stream_name;
+}
+
+/****************************************************************************
+ Returns true if the filename's stream == "::$DATA"
+ ***************************************************************************/
+bool is_ntfs_default_stream_smb_fname(const struct smb_filename *smb_fname)
+{
+ if (!is_ntfs_stream_smb_fname(smb_fname)) {
+ return false;
+ }
+
+ return StrCaseCmp(smb_fname->stream_name, "::$DATA") == 0;
+}
+
/****************************************************************************
Reply to an NT create and X call on a pipe
****************************************************************************/
void reply_ntcreate_and_X(struct smb_request *req)
{
connection_struct *conn = req->conn;
+ struct smb_filename *smb_fname = NULL;
char *fname = NULL;
uint32 flags;
uint32 access_mask;
reply bits separately. */
uint32 fattr=0;
SMB_OFF_T file_len = 0;
- SMB_STRUCT_STAT sbuf;
int info = 0;
files_struct *fsp = NULL;
char *p = NULL;
if (!NT_STATUS_IS_OK(status)) {
reply_nterror(req, status);
- END_PROFILE(SMBntcreateX);
- return;
+ goto out;
}
DEBUG(10,("reply_ntcreate_and_X: flags = 0x%x, access_mask = 0x%x "
if (IS_IPC(conn)) {
if (lp_nt_pipe_support()) {
do_ntcreate_pipe_open(conn, req);
- END_PROFILE(SMBntcreateX);
- return;
+ goto out;
}
reply_doserror(req, ERRDOS, ERRnoaccess);
- END_PROFILE(SMBntcreateX);
- return;
+ goto out;
}
oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
? BATCH_OPLOCK : 0;
}
+ status = filename_convert(ctx,
+ conn,
+ req->flags2 & FLAGS2_DFS_PATHNAMES,
+ fname,
+ &smb_fname,
+ &fname);
+
+ if (!NT_STATUS_IS_OK(status)) {
+ if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
+ reply_botherror(req,
+ NT_STATUS_PATH_NOT_COVERED,
+ ERRSRV, ERRbadpath);
+ goto out;
+ }
+ reply_nterror(req, status);
+ goto out;
+ }
+
status = SMB_VFS_CREATE_FILE(
conn, /* conn */
req, /* req */
root_dir_fid, /* root_dir_fid */
- fname, /* fname */
- CFF_DOS_PATH, /* create_file_flags */
+ smb_fname, /* fname */
access_mask, /* access_mask */
share_access, /* share_access */
create_disposition, /* create_disposition*/
NULL, /* sd */
NULL, /* ea_list */
&fsp, /* result */
- &info, /* pinfo */
- &sbuf); /* psbuf */
+ &info); /* pinfo */
if (!NT_STATUS_IS_OK(status)) {
if (open_was_deferred(req->mid)) {
/* We have re-scheduled this call, no error. */
- END_PROFILE(SMBntcreateX);
- return;
+ goto out;
}
if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
reply_botherror(req, status, ERRDOS, ERRfilexists);
else {
reply_nterror(req, status);
}
- END_PROFILE(SMBntcreateX);
- return;
+ goto out;
}
/*
oplock_granted = NO_OPLOCK_RETURN;
}
- file_len = sbuf.st_size;
- fattr = dos_mode(conn,fsp->fsp_name,&sbuf);
+ file_len = smb_fname->st.st_ex_size;
+ fattr = dos_mode(conn,fsp->fsp_name,&smb_fname->st);
if (fattr == 0) {
fattr = FILE_ATTRIBUTE_NORMAL;
}
p += 4;
/* Create time. */
- c_timespec = get_create_timespec(
- &sbuf,lp_fake_dir_create_times(SNUM(conn)));
- a_timespec = get_atimespec(&sbuf);
- m_timespec = get_mtimespec(&sbuf);
+ c_timespec = smb_fname->st.st_ex_btime;
+ a_timespec = smb_fname->st.st_ex_atime;
+ m_timespec = smb_fname->st.st_ex_mtime;
if (lp_dos_filetime_resolution(SNUM(conn))) {
dos_filetime_timespec(&c_timespec);
p += 8;
SIVAL(p,0,fattr); /* File Attributes. */
p += 4;
- SOFF_T(p, 0, SMB_VFS_GET_ALLOC_SIZE(conn,fsp,&sbuf));
+ SOFF_T(p, 0, SMB_VFS_GET_ALLOC_SIZE(conn,fsp,&smb_fname->st));
p += 8;
SOFF_T(p,0,file_len);
p += 8;
if (flags & EXTENDED_RESPONSE_REQUIRED) {
uint32 perms = 0;
p += 25;
- if (fsp->is_directory
- || can_write_to_file(conn, fsp->fsp_name, &sbuf)) {
+ if (fsp->is_directory ||
+ can_write_to_file(conn, smb_fname)) {
perms = FILE_GENERIC_ALL;
} else {
perms = FILE_GENERIC_READ|FILE_EXECUTE;
fsp->fnum, fsp->fsp_name));
chain_reply(req);
+ out:
+ TALLOC_FREE(smb_fname);
END_PROFILE(SMBntcreateX);
return;
}
char **ppdata, uint32 data_count,
uint32 max_data_count)
{
+ struct smb_filename *smb_fname = NULL;
char *fname = NULL;
char *params = *ppparams;
char *data = *ppdata;
/* Breakout the oplock request bits so we can set the reply bits separately. */
uint32 fattr=0;
SMB_OFF_T file_len = 0;
- SMB_STRUCT_STAT sbuf;
int info = 0;
files_struct *fsp = NULL;
char *p = NULL;
ppsetup, setup_count,
ppparams, parameter_count,
ppdata, data_count);
- return;
+ goto out;
}
reply_doserror(req, ERRDOS, ERRnoaccess);
- return;
+ goto out;
}
/*
if(parameter_count < 54) {
DEBUG(0,("call_nt_transact_create - insufficient parameters (%u)\n", (unsigned int)parameter_count));
reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
- return;
+ goto out;
}
flags = IVAL(params,0);
"%u, data_count = %u\n", (unsigned int)ea_len,
(unsigned int)sd_len, (unsigned int)data_count));
reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
- return;
+ goto out;
}
if (sd_len) {
"unmarshall_sec_desc failed: %s\n",
nt_errstr(status)));
reply_nterror(req, status);
- return;
+ goto out;
}
}
"EA's not supported.\n",
(unsigned int)ea_len));
reply_nterror(req, NT_STATUS_EAS_NOT_SUPPORTED);
- return;
+ goto out;
}
if (ea_len < 10) {
"too small (should be more than 10)\n",
(unsigned int)ea_len ));
reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
- return;
+ goto out;
}
/* We have already checked that ea_len <= data_count here. */
ea_len);
if (ea_list == NULL) {
reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
- return;
+ goto out;
}
}
STR_TERMINATE, &status);
if (!NT_STATUS_IS_OK(status)) {
reply_nterror(req, status);
- return;
+ goto out;
+ }
+
+ status = filename_convert(ctx,
+ conn,
+ req->flags2 & FLAGS2_DFS_PATHNAMES,
+ fname,
+ &smb_fname,
+ &fname);
+
+ if (!NT_STATUS_IS_OK(status)) {
+ if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
+ reply_botherror(req,
+ NT_STATUS_PATH_NOT_COVERED,
+ ERRSRV, ERRbadpath);
+ goto out;
+ }
+ reply_nterror(req, status);
+ goto out;
}
oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
conn, /* conn */
req, /* req */
root_dir_fid, /* root_dir_fid */
- fname, /* fname */
- CFF_DOS_PATH, /* create_file_flags */
+ smb_fname, /* fname */
access_mask, /* access_mask */
share_access, /* share_access */
create_disposition, /* create_disposition*/
sd, /* sd */
ea_list, /* ea_list */
&fsp, /* result */
- &info, /* pinfo */
- &sbuf); /* psbuf */
+ &info); /* pinfo */
if(!NT_STATUS_IS_OK(status)) {
if (open_was_deferred(req->mid)) {
return;
}
reply_openerror(req, status);
- return;
+ goto out;
}
/*
oplock_granted = NO_OPLOCK_RETURN;
}
- file_len = sbuf.st_size;
- fattr = dos_mode(conn,fsp->fsp_name,&sbuf);
+ file_len = smb_fname->st.st_ex_size;
+ fattr = dos_mode(conn, fsp->fsp_name, &smb_fname->st);
if (fattr == 0) {
fattr = FILE_ATTRIBUTE_NORMAL;
}
params = nttrans_realloc(ppparams, param_len);
if(params == NULL) {
reply_doserror(req, ERRDOS, ERRnomem);
- return;
+ goto out;
}
p = params;
p += 8;
/* Create time. */
- c_timespec = get_create_timespec(
- &sbuf,lp_fake_dir_create_times(SNUM(conn)));
- a_timespec = get_atimespec(&sbuf);
- m_timespec = get_mtimespec(&sbuf);
+ c_timespec = smb_fname->st.st_ex_btime;
+ a_timespec = smb_fname->st.st_ex_atime;
+ m_timespec = smb_fname->st.st_ex_mtime;
if (lp_dos_filetime_resolution(SNUM(conn))) {
dos_filetime_timespec(&c_timespec);
p += 8;
SIVAL(p,0,fattr); /* File Attributes. */
p += 4;
- SOFF_T(p, 0, SMB_VFS_GET_ALLOC_SIZE(conn,fsp,&sbuf));
+ SOFF_T(p, 0, SMB_VFS_GET_ALLOC_SIZE(conn, fsp, &smb_fname->st));
p += 8;
SOFF_T(p,0,file_len);
p += 8;
if (flags & EXTENDED_RESPONSE_REQUIRED) {
uint32 perms = 0;
p += 25;
- if (fsp->is_directory
- || can_write_to_file(conn, fsp->fsp_name, &sbuf)) {
+ if (fsp->is_directory ||
+ can_write_to_file(conn, smb_fname)) {
perms = FILE_GENERIC_ALL;
} else {
perms = FILE_GENERIC_READ|FILE_EXECUTE;
/* Send the required number of replies */
send_nt_replies(conn, req, NT_STATUS_OK, params, param_len, *ppdata, 0);
-
+ out:
+ TALLOC_FREE(smb_fname);
return;
}
*/
START_PROFILE(SMBntcancel);
+ srv_cancel_sign_response(smbd_server_conn);
remove_pending_change_notify_requests_by_mid(req->mid);
remove_pending_lock_requests_by_mid(req->mid);
- srv_cancel_sign_response(req->mid);
DEBUG(3,("reply_ntcancel: cancel called on mid = %d.\n", req->mid));
static NTSTATUS copy_internals(TALLOC_CTX *ctx,
connection_struct *conn,
struct smb_request *req,
- const char *oldname_in,
- const char *newname_in,
+ struct smb_filename *smb_fname_src,
+ struct smb_filename *smb_fname_dst,
uint32 attrs)
{
- SMB_STRUCT_STAT sbuf1, sbuf2;
char *oldname = NULL;
char *newname = NULL;
- char *last_component_oldname = NULL;
- char *last_component_newname = NULL;
files_struct *fsp1,*fsp2;
uint32 fattr;
int info;
NTSTATUS status = NT_STATUS_OK;
char *parent;
- ZERO_STRUCT(sbuf1);
- ZERO_STRUCT(sbuf2);
-
if (!CAN_WRITE(conn)) {
- return NT_STATUS_MEDIA_WRITE_PROTECTED;
+ status = NT_STATUS_MEDIA_WRITE_PROTECTED;
+ goto out;
}
- status = unix_convert(ctx, conn, oldname_in, False, &oldname,
- &last_component_oldname, &sbuf1);
- if (!NT_STATUS_IS_OK(status)) {
- return status;
+ /* Source must already exist. */
+ if (!VALID_STAT(smb_fname_src->st)) {
+ status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
+ goto out;
}
- status = check_name(conn, oldname);
+ status = get_full_smb_filename(ctx, smb_fname_src, &oldname);
if (!NT_STATUS_IS_OK(status)) {
- return status;
+ goto out;
}
- /* Source must already exist. */
- if (!VALID_STAT(sbuf1)) {
- return NT_STATUS_OBJECT_NAME_NOT_FOUND;
- }
/* Ensure attributes match. */
- fattr = dos_mode(conn,oldname,&sbuf1);
+ fattr = dos_mode(conn, oldname, &smb_fname_src->st);
if ((fattr & ~attrs) & (aHIDDEN | aSYSTEM)) {
- return NT_STATUS_NO_SUCH_FILE;
+ status = NT_STATUS_NO_SUCH_FILE;
+ goto out;
}
- status = unix_convert(ctx, conn, newname_in, False, &newname,
- &last_component_newname, &sbuf2);
- if (!NT_STATUS_IS_OK(status)) {
- return status;
- }
-
- status = check_name(conn, newname);
- if (!NT_STATUS_IS_OK(status)) {
- return status;
- }
-
- /* Disallow if newname already exists. */
- if (VALID_STAT(sbuf2)) {
- return NT_STATUS_OBJECT_NAME_COLLISION;
+ /* Disallow if dst file already exists. */
+ if (VALID_STAT(smb_fname_dst->st)) {
+ status = NT_STATUS_OBJECT_NAME_COLLISION;
+ goto out;
}
/* No links from a directory. */
- if (S_ISDIR(sbuf1.st_mode)) {
- return NT_STATUS_FILE_IS_A_DIRECTORY;
- }
-
- /* Ensure this is within the share. */
- status = check_reduced_name(conn, oldname);
- if (!NT_STATUS_IS_OK(status)) {
- return status;
+ if (S_ISDIR(smb_fname_src->st.st_ex_mode)) {
+ status = NT_STATUS_FILE_IS_A_DIRECTORY;
+ goto out;
}
DEBUG(10,("copy_internals: doing file copy %s to %s\n",
- oldname, newname));
+ smb_fname_str_dbg(smb_fname_src),
+ smb_fname_str_dbg(smb_fname_dst)));
status = SMB_VFS_CREATE_FILE(
conn, /* conn */
req, /* req */
0, /* root_dir_fid */
- oldname, /* fname */
- 0, /* create_file_flags */
+ smb_fname_src, /* fname */
FILE_READ_DATA, /* access_mask */
(FILE_SHARE_READ | FILE_SHARE_WRITE | /* share_access */
FILE_SHARE_DELETE),
NULL, /* sd */
NULL, /* ea_list */
&fsp1, /* result */
- &info, /* pinfo */
- &sbuf1); /* psbuf */
+ &info); /* pinfo */
if (!NT_STATUS_IS_OK(status)) {
- return status;
+ goto out;
}
status = SMB_VFS_CREATE_FILE(
conn, /* conn */
req, /* req */
0, /* root_dir_fid */
- newname, /* fname */
- 0, /* create_file_flags */
+ smb_fname_dst, /* fname */
FILE_WRITE_DATA, /* access_mask */
(FILE_SHARE_READ | FILE_SHARE_WRITE | /* share_access */
FILE_SHARE_DELETE),
NULL, /* sd */
NULL, /* ea_list */
&fsp2, /* result */
- &info, /* pinfo */
- &sbuf2); /* psbuf */
+ &info); /* pinfo */
if (!NT_STATUS_IS_OK(status)) {
close_file(NULL, fsp1, ERROR_CLOSE);
- return status;
+ goto out;
}
- if (sbuf1.st_size) {
- ret = vfs_transfer_file(fsp1, fsp2, sbuf1.st_size);
+ if (smb_fname_src->st.st_ex_size) {
+ ret = vfs_transfer_file(fsp1, fsp2, smb_fname_src->st.st_ex_size);
}
/*
close_file(NULL, fsp1, NORMAL_CLOSE);
/* Ensure the modtime is set correctly on the destination file. */
- set_close_write_time(fsp2, get_mtimespec(&sbuf1));
+ set_close_write_time(fsp2, smb_fname_src->st.st_ex_mtime);
status = close_file(NULL, fsp2, NORMAL_CLOSE);
+ status = get_full_smb_filename(ctx, smb_fname_dst, &newname);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto out;
+ }
+
/* Grrr. We have to do this as open_file_ntcreate adds aARCH when it
creates the file. This isn't the correct thing to do in the copy
case. JRA */
if (!parent_dirname(talloc_tos(), newname, &parent, NULL)) {
- return NT_STATUS_NO_MEMORY;
+ status = NT_STATUS_NO_MEMORY;
+ goto out;
}
- file_set_dosmode(conn, newname, fattr, &sbuf2, parent, false);
+ file_set_dosmode(conn, newname, fattr, &smb_fname_dst->st, parent,
+ false);
TALLOC_FREE(parent);
- if (ret < (SMB_OFF_T)sbuf1.st_size) {
- return NT_STATUS_DISK_FULL;
+ if (ret < (SMB_OFF_T)smb_fname_src->st.st_ex_size) {
+ status = NT_STATUS_DISK_FULL;
+ goto out;
}
-
+ out:
if (!NT_STATUS_IS_OK(status)) {
DEBUG(3,("copy_internals: Error %s copy file %s to %s\n",
- nt_errstr(status), oldname, newname));
+ nt_errstr(status), smb_fname_str_dbg(smb_fname_src),
+ smb_fname_str_dbg(smb_fname_dst)));
}
+
+ TALLOC_FREE(oldname);
+ TALLOC_FREE(newname);
+
return status;
}
void reply_ntrename(struct smb_request *req)
{
connection_struct *conn = req->conn;
+ struct smb_filename *smb_fname_old = NULL;
+ struct smb_filename *smb_fname_new = NULL;
char *oldname = NULL;
char *newname = NULL;
const char *p;
return;
}
- status = resolve_dfspath(ctx, conn,
+ status = filename_convert(ctx, conn,
req->flags2 & FLAGS2_DFS_PATHNAMES,
oldname,
+ &smb_fname_old,
&oldname);
if (!NT_STATUS_IS_OK(status)) {
if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
return;
}
- status = resolve_dfspath(ctx, conn,
+ status = filename_convert(ctx, conn,
req->flags2 & FLAGS2_DFS_PATHNAMES,
newname,
+ &smb_fname_new,
&newname);
if (!NT_STATUS_IS_OK(status)) {
if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
} else {
status = hardlink_internals(ctx,
conn,
- oldname,
- newname);
+ smb_fname_old,
+ smb_fname_new);
}
break;
case RENAME_FLAG_COPY:
/* No wildcards. */
status = NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
} else {
- status = copy_internals(ctx, conn, req, oldname,
- newname, attrs);
+ status = copy_internals(ctx, conn, req,
+ smb_fname_old,
+ smb_fname_new,
+ attrs);
}
break;
case RENAME_FLAG_MOVE_CLUSTER_INFORMATION: