#include "includes.h"
#include "smbd/globals.h"
-extern enum protocol_types Protocol;
extern const struct generic_mapping file_generic_mapping;
static char *nttrans_realloc(char **ptr, size_t size)
}
}
-/****************************************************************************
- Is it an NTFS stream name ?
- An NTFS file name is <path>.<extention>:<stream name>:<stream type>
- $DATA can be used as both a stream name and a stream type. A missing stream
- name or type implies $DATA.
-
- Both Windows stream names and POSIX files can contain the ':' character.
- This function first checks for the existence of a colon in the last component
- of the given name. If the name contains a colon we differentiate between a
- stream and POSIX file by checking if the latter exists through a POSIX stat.
-
- Function assumes we've already chdir() to the "root" directory of fname.
-****************************************************************************/
-
-bool is_ntfs_stream_name(const char *fname)
-{
- const char *lastcomp;
- SMB_STRUCT_STAT sbuf;
-
- /* If all pathnames are treated as POSIX we ignore streams. */
- if (lp_posix_pathnames()) {
- return false;
- }
-
- /* Find the last component of the name. */
- if ((lastcomp = strrchr_m(fname, '/')) != NULL)
- ++lastcomp;
- else
- lastcomp = fname;
-
- /* If there is no colon in the last component, it's not a stream. */
- if (strchr_m(lastcomp, ':') == NULL)
- return false;
-
- /*
- * If file already exists on disk, it's not a stream. The stat must
- * bypass the vfs layer so streams modules don't intefere.
- */
- if (sys_stat(fname, &sbuf) == 0) {
- DEBUG(5, ("is_ntfs_stream_name: file %s contains a ':' but is "
- "not a stream\n", fname));
- return false;
- }
-
- 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
****************************************************************************/
chain_reply(req);
}
+struct case_semantics_state {
+ connection_struct *conn;
+ bool case_sensitive;
+ bool case_preserve;
+ bool short_case_preserve;
+};
+
+/****************************************************************************
+ Restore case semantics.
+****************************************************************************/
+
+static int restore_case_semantics(struct case_semantics_state *state)
+{
+ state->conn->case_sensitive = state->case_sensitive;
+ state->conn->case_preserve = state->case_preserve;
+ state->conn->short_case_preserve = state->short_case_preserve;
+ return 0;
+}
+
+/****************************************************************************
+ Save case semantics.
+****************************************************************************/
+
+static struct case_semantics_state *set_posix_case_semantics(TALLOC_CTX *mem_ctx,
+ connection_struct *conn)
+{
+ struct case_semantics_state *result;
+
+ if (!(result = talloc(mem_ctx, struct case_semantics_state))) {
+ return NULL;
+ }
+
+ result->conn = conn;
+ result->case_sensitive = conn->case_sensitive;
+ result->case_preserve = conn->case_preserve;
+ result->short_case_preserve = conn->short_case_preserve;
+
+ /* Set to POSIX. */
+ conn->case_sensitive = True;
+ conn->case_preserve = True;
+ conn->short_case_preserve = True;
+
+ talloc_set_destructor(result, restore_case_semantics);
+
+ return result;
+}
+
/****************************************************************************
Reply to an NT create and X call.
****************************************************************************/
int info = 0;
files_struct *fsp = NULL;
char *p = NULL;
+ struct timespec create_timespec;
struct timespec c_timespec;
struct timespec a_timespec;
struct timespec m_timespec;
NTSTATUS status;
int oplock_request;
uint8_t oplock_granted = NO_OPLOCK_RETURN;
+ struct case_semantics_state *case_state = NULL;
TALLOC_CTX *ctx = talloc_tos();
START_PROFILE(SMBntcreateX);
if (req->wct < 24) {
reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
- return;
+ goto out;
}
flags = IVAL(req->vwv+3, 1);
? BATCH_OPLOCK : 0;
}
+ if (file_attributes & FILE_FLAG_POSIX_SEMANTICS) {
+ case_state = set_posix_case_semantics(ctx, conn);
+ if (!case_state) {
+ reply_nterror(req, NT_STATUS_NO_MEMORY);
+ goto out;
+ }
+ }
+
status = filename_convert(ctx,
conn,
req->flags2 & FLAGS2_DFS_PATHNAMES,
fname,
- &smb_fname,
- NULL);
+ 0,
+ NULL,
+ &smb_fname);
+
+ TALLOC_FREE(case_state);
if (!NT_STATUS_IS_OK(status)) {
if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
goto out;
}
+ /*
+ * Bug #6898 - clients using Windows opens should
+ * never be able to set this attribute into the
+ * VFS.
+ */
+ file_attributes &= ~FILE_FLAG_POSIX_SEMANTICS;
+
status = SMB_VFS_CREATE_FILE(
conn, /* conn */
req, /* req */
/* We have re-scheduled this call, no error. */
goto out;
}
- if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
- reply_botherror(req, status, ERRDOS, ERRfilexists);
- }
- else {
- reply_nterror(req, status);
- }
+ reply_openerror(req, status);
goto out;
}
+ /* Ensure we're pointing at the correct stat struct. */
+ TALLOC_FREE(smb_fname);
+ smb_fname = fsp->fsp_name;
+
/*
* If the caller set the extended oplock request bit
* and we granted one (by whatever means) - set the
}
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;
- }
if (flags & EXTENDED_RESPONSE_REQUIRED) {
/* This is very strange. We
}
p += 4;
+ fattr = dos_mode(conn, smb_fname);
+ if (fattr == 0) {
+ fattr = FILE_ATTRIBUTE_NORMAL;
+ }
+
/* Deal with other possible opens having a modified
write time. JRA. */
ZERO_STRUCT(write_time_ts);
get_file_infos(fsp->file_id, NULL, &write_time_ts);
if (!null_timespec(write_time_ts)) {
- update_stat_ex_writetime(&smb_fname->st, write_time_ts);
+ update_stat_ex_mtime(&smb_fname->st, write_time_ts);
}
/* Create time. */
- c_timespec = smb_fname->st.st_ex_btime;
+ create_timespec = get_create_timespec(conn, fsp, smb_fname);
a_timespec = smb_fname->st.st_ex_atime;
m_timespec = smb_fname->st.st_ex_mtime;
+ c_timespec = get_change_timespec(conn, fsp, smb_fname);
if (lp_dos_filetime_resolution(SNUM(conn))) {
- dos_filetime_timespec(&c_timespec);
+ dos_filetime_timespec(&create_timespec);
dos_filetime_timespec(&a_timespec);
dos_filetime_timespec(&m_timespec);
+ dos_filetime_timespec(&c_timespec);
}
- put_long_date_timespec(p, c_timespec); /* create time. */
+ put_long_date_timespec(conn->ts_res, p, create_timespec); /* create time. */
p += 8;
- put_long_date_timespec(p, a_timespec); /* access time */
+ put_long_date_timespec(conn->ts_res, p, a_timespec); /* access time */
p += 8;
- put_long_date_timespec(p, m_timespec); /* write time */
+ put_long_date_timespec(conn->ts_res, p, m_timespec); /* write time */
p += 8;
- put_long_date_timespec(p, m_timespec); /* change time */
+ put_long_date_timespec(conn->ts_res, p, c_timespec); /* change time */
p += 8;
SIVAL(p,0,fattr); /* File Attributes. */
p += 4;
SOFF_T(p,0,file_len);
p += 8;
if (flags & EXTENDED_RESPONSE_REQUIRED) {
- SSVAL(p,2,0x7);
+ uint16_t file_status = (NO_EAS|NO_SUBSTREAMS|NO_REPARSETAG);
+ size_t num_names = 0;
+ unsigned int num_streams;
+ 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;
+ }
+ status = SMB_VFS_STREAMINFO(conn, NULL, smb_fname->base_name, ctx,
+ &num_streams, &streams);
+ /* There is always one stream, ::$DATA. */
+ if (NT_STATUS_IS_OK(status) && num_streams > 1) {
+ file_status &= ~NO_SUBSTREAMS;
+ }
+ TALLOC_FREE(streams);
+ SSVAL(p,2,file_status);
}
p += 4;
SCVAL(p,0,fsp->is_directory ? 1 : 0);
}
DEBUG(5,("reply_ntcreate_and_X: fnum = %d, open name = %s\n",
- fsp->fnum, fsp->fsp_name));
+ fsp->fnum, smb_fname_str_dbg(smb_fname)));
chain_reply(req);
out:
- TALLOC_FREE(smb_fname);
END_PROFILE(SMBntcreateX);
return;
}
security_acl_map_generic(psd->sacl, &file_generic_mapping);
if (DEBUGLEVEL >= 10) {
- DEBUG(10,("set_sd for file %s\n", fsp->fsp_name ));
+ DEBUG(10,("set_sd for file %s\n", fsp_str_dbg(fsp)));
NDR_PRINT_DEBUG(security_descriptor, psd);
}
Read a list of EA names and data from an incoming data buffer. Create an ea_list with them.
****************************************************************************/
-static struct ea_list *read_nttrans_ea_list(TALLOC_CTX *ctx, const char *pdata, size_t data_size)
+struct ea_list *read_nttrans_ea_list(TALLOC_CTX *ctx, const char *pdata, size_t data_size)
{
struct ea_list *ea_list_head = NULL;
size_t offset = 0;
struct security_descriptor *sd = NULL;
uint32 ea_len;
uint16 root_dir_fid;
+ struct timespec create_timespec;
struct timespec c_timespec;
struct timespec a_timespec;
struct timespec m_timespec;
uint64_t allocation_size;
int oplock_request;
uint8_t oplock_granted;
+ struct case_semantics_state *case_state = NULL;
TALLOC_CTX *ctx = talloc_tos();
DEBUG(5,("call_nt_transact_create\n"));
goto out;
}
+ if (file_attributes & FILE_FLAG_POSIX_SEMANTICS) {
+ case_state = set_posix_case_semantics(ctx, conn);
+ if (!case_state) {
+ reply_nterror(req, NT_STATUS_NO_MEMORY);
+ goto out;
+ }
+ }
+
status = filename_convert(ctx,
conn,
req->flags2 & FLAGS2_DFS_PATHNAMES,
fname,
- &smb_fname,
- NULL);
+ 0,
+ NULL,
+ &smb_fname);
+
+ TALLOC_FREE(case_state);
if (!NT_STATUS_IS_OK(status)) {
if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
? BATCH_OPLOCK : 0;
}
+ /*
+ * Bug #6898 - clients using Windows opens should
+ * never be able to set this attribute into the
+ * VFS.
+ */
+ file_attributes &= ~FILE_FLAG_POSIX_SEMANTICS;
+
status = SMB_VFS_CREATE_FILE(
conn, /* conn */
req, /* req */
goto out;
}
+ /* Ensure we're pointing at the correct stat struct. */
+ TALLOC_FREE(smb_fname);
+ smb_fname = fsp->fsp_name;
+
/*
* If the caller set the extended oplock request bit
* and we granted one (by whatever means) - set the
}
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;
- }
/* Realloc the size of parameters and data we will return */
if (flags & EXTENDED_RESPONSE_REQUIRED) {
}
p += 8;
+ fattr = dos_mode(conn, smb_fname);
+ if (fattr == 0) {
+ fattr = FILE_ATTRIBUTE_NORMAL;
+ }
+
/* Deal with other possible opens having a modified
write time. JRA. */
ZERO_STRUCT(write_time_ts);
get_file_infos(fsp->file_id, NULL, &write_time_ts);
if (!null_timespec(write_time_ts)) {
- update_stat_ex_writetime(&smb_fname->st, write_time_ts);
+ update_stat_ex_mtime(&smb_fname->st, write_time_ts);
}
/* Create time. */
- c_timespec = smb_fname->st.st_ex_btime;
+ create_timespec = get_create_timespec(conn, fsp, smb_fname);
a_timespec = smb_fname->st.st_ex_atime;
m_timespec = smb_fname->st.st_ex_mtime;
+ c_timespec = get_change_timespec(conn, fsp, smb_fname);
if (lp_dos_filetime_resolution(SNUM(conn))) {
- dos_filetime_timespec(&c_timespec);
+ dos_filetime_timespec(&create_timespec);
dos_filetime_timespec(&a_timespec);
dos_filetime_timespec(&m_timespec);
+ dos_filetime_timespec(&c_timespec);
}
- put_long_date_timespec(p, c_timespec); /* create time. */
+ put_long_date_timespec(conn->ts_res, p, create_timespec); /* create time. */
p += 8;
- put_long_date_timespec(p, a_timespec); /* access time */
+ put_long_date_timespec(conn->ts_res, p, a_timespec); /* access time */
p += 8;
- put_long_date_timespec(p, m_timespec); /* write time */
+ put_long_date_timespec(conn->ts_res, p, m_timespec); /* write time */
p += 8;
- put_long_date_timespec(p, m_timespec); /* change time */
+ put_long_date_timespec(conn->ts_res, p, c_timespec); /* change time */
p += 8;
SIVAL(p,0,fattr); /* File Attributes. */
p += 4;
SIVAL(p,0,perms);
}
- DEBUG(5,("call_nt_transact_create: open name = %s\n", fsp->fsp_name));
+ DEBUG(5,("call_nt_transact_create: open name = %s\n",
+ smb_fname_str_dbg(smb_fname)));
/* 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;
}
struct smb_filename *smb_fname_dst,
uint32 attrs)
{
- char *oldname = NULL;
files_struct *fsp1,*fsp2;
uint32 fattr;
int info;
goto out;
}
- status = get_full_smb_filename(ctx, smb_fname_src, &oldname);
- if (!NT_STATUS_IS_OK(status)) {
- goto out;
- }
-
/* Ensure attributes match. */
- fattr = dos_mode(conn, oldname, &smb_fname_src->st);
+ fattr = dos_mode(conn, smb_fname_src);
if ((fattr & ~attrs) & (aHIDDEN | aSYSTEM)) {
status = NT_STATUS_NO_SUCH_FILE;
goto out;
smb_fname_str_dbg(smb_fname_dst)));
}
- TALLOC_FREE(oldname);
return status;
}
bool src_has_wcard = False;
bool dest_has_wcard = False;
uint32 attrs;
+ uint32_t ucf_flags_src = 0;
+ uint32_t ucf_flags_dst = 0;
uint16 rename_type;
TALLOC_CTX *ctx = talloc_tos();
if (req->wct < 4) {
reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
- END_PROFILE(SMBntrename);
- return;
+ goto out;
}
attrs = SVAL(req->vwv+0, 0);
&status, &src_has_wcard);
if (!NT_STATUS_IS_OK(status)) {
reply_nterror(req, status);
- END_PROFILE(SMBntrename);
- return;
+ goto out;
}
if (ms_has_wild(oldname)) {
reply_nterror(req, NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
- END_PROFILE(SMBntrename);
- return;
+ goto out;
}
p++;
&status, &dest_has_wcard);
if (!NT_STATUS_IS_OK(status)) {
reply_nterror(req, status);
- END_PROFILE(SMBntrename);
- return;
+ goto out;
+ }
+
+ /* The newname must begin with a ':' if the oldname contains a ':'. */
+ if (strchr_m(oldname, ':') && (newname[0] != ':')) {
+ reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
+ goto out;
+ }
+
+ /*
+ * If this is a rename operation, allow wildcards and save the
+ * 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;
}
+ /* rename_internals() calls unix_convert(), so don't call it here. */
status = filename_convert(ctx, conn,
- req->flags2 & FLAGS2_DFS_PATHNAMES,
- oldname,
- &smb_fname_old,
- &oldname);
+ req->flags2 & FLAGS2_DFS_PATHNAMES,
+ oldname,
+ ucf_flags_src,
+ NULL,
+ &smb_fname_old);
if (!NT_STATUS_IS_OK(status)) {
- if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
- reply_botherror(req, NT_STATUS_PATH_NOT_COVERED,
+ if (NT_STATUS_EQUAL(status,
+ NT_STATUS_PATH_NOT_COVERED)) {
+ reply_botherror(req,
+ NT_STATUS_PATH_NOT_COVERED,
ERRSRV, ERRbadpath);
- END_PROFILE(SMBntrename);
- return;
+ goto out;
}
reply_nterror(req, status);
- END_PROFILE(SMBntrename);
- return;
+ goto out;
}
status = filename_convert(ctx, conn,
- req->flags2 & FLAGS2_DFS_PATHNAMES,
- newname,
- &smb_fname_new,
- &newname);
+ req->flags2 & FLAGS2_DFS_PATHNAMES,
+ newname,
+ ucf_flags_dst,
+ &dest_has_wcard,
+ &smb_fname_new);
if (!NT_STATUS_IS_OK(status)) {
- if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
- reply_botherror(req, NT_STATUS_PATH_NOT_COVERED,
+ if (NT_STATUS_EQUAL(status,
+ NT_STATUS_PATH_NOT_COVERED)) {
+ reply_botherror(req,
+ NT_STATUS_PATH_NOT_COVERED,
ERRSRV, ERRbadpath);
- END_PROFILE(SMBntrename);
- return;
+ goto out;
}
reply_nterror(req, status);
- END_PROFILE(SMBntrename);
- 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;
+ goto out;
}
- DEBUG(3,("reply_ntrename : %s -> %s\n",oldname,newname));
+ DEBUG(3,("reply_ntrename: %s -> %s\n",
+ smb_fname_str_dbg(smb_fname_old),
+ smb_fname_str_dbg(smb_fname_new)));
switch(rename_type) {
case RENAME_FLAG_RENAME:
- status = rename_internals(ctx, conn, req, oldname,
- newname, attrs, False, src_has_wcard,
- dest_has_wcard, DELETE_ACCESS);
+ status = rename_internals(ctx, conn, req,
+ smb_fname_old, smb_fname_new,
+ attrs, False, src_has_wcard,
+ dest_has_wcard,
+ DELETE_ACCESS);
break;
case RENAME_FLAG_HARD_LINK:
if (src_has_wcard || dest_has_wcard) {
/* No wildcards. */
status = NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
} else {
- status = hardlink_internals(ctx,
- conn,
- smb_fname_old,
- smb_fname_new);
+ status = hardlink_internals(ctx, conn,
+ smb_fname_old,
+ smb_fname_new);
}
break;
case RENAME_FLAG_COPY:
if (!NT_STATUS_IS_OK(status)) {
if (open_was_deferred(req->mid)) {
/* We have re-scheduled this call. */
- END_PROFILE(SMBntrename);
- return;
+ goto out;
}
reply_nterror(req, status);
- END_PROFILE(SMBntrename);
- return;
+ goto out;
}
reply_outbuf(req, 0, 0);
-
+ out:
END_PROFILE(SMBntrename);
return;
}
DEBUG(3,("call_nt_transact_notify_change: notify change "
"called on %s, filter = %s, recursive = %d\n",
- fsp->fsp_name, filter_string, recursive));
+ fsp_str_dbg(fsp), filter_string, recursive));
TALLOC_FREE(filter_string);
}
send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
DEBUG(3,("nt transact rename from = %s, to = %s ignored!\n",
- fsp->fsp_name, new_name));
+ fsp_str_dbg(fsp), new_name));
return;
}
security_info_wanted = IVAL(params,4);
- DEBUG(3,("call_nt_transact_query_security_desc: file = %s, info_wanted = 0x%x\n", fsp->fsp_name,
- (unsigned int)security_info_wanted ));
+ DEBUG(3,("call_nt_transact_query_security_desc: file = %s, "
+ "info_wanted = 0x%x\n", fsp_str_dbg(fsp),
+ (unsigned int)security_info_wanted));
params = nttrans_realloc(ppparams, 4);
if(params == NULL) {
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));
+ DEBUG(10,("call_nt_transact_query_security_desc for file %s\n",
+ fsp_str_dbg(fsp)));
NDR_PRINT_DEBUG(security_descriptor, psd);
}
security_info_sent = IVAL(params,4);
- DEBUG(3,("call_nt_transact_set_security_desc: file = %s, sent 0x%x\n", fsp->fsp_name,
- (unsigned int)security_info_sent ));
+ DEBUG(3,("call_nt_transact_set_security_desc: file = %s, sent 0x%x\n",
+ fsp_str_dbg(fsp), (unsigned int)security_info_sent));
if (data_count == 0) {
reply_doserror(req, ERRDOS, ERRnoaccess);
}
/* needed_data_count 4 bytes */
- SIVAL(pdata,8,labels_data_count);
+ SIVAL(pdata, 8, labels_data_count+4);
cur_pdata+=12;
DEBUG(10,("FSCTL_GET_SHADOW_COPY_DATA: %u volumes for path[%s].\n",
- shadow_data->num_volumes,fsp->fsp_name));
+ shadow_data->num_volumes, fsp_str_dbg(fsp)));
if (labels && shadow_data->labels) {
for (i=0;i<shadow_data->num_volumes;i++) {
srvstr_push(pdata, req->flags2,
struct trans_state *state,
struct smb_request *req)
{
- if (Protocol >= PROTOCOL_NT1) {
+ if (get_Protocol() >= PROTOCOL_NT1) {
req->flags2 |= 0x40; /* IS_LONG_NAME */
SSVAL(req->inbuf,smb_flg2,req->flags2);
}