return ret_data_size;
}
+static NTSTATUS fill_ea_chained_buffer(TALLOC_CTX *mem_ctx,
+ char *pdata,
+ unsigned int total_data_size,
+ unsigned int *ret_data_size,
+ connection_struct *conn,
+ struct ea_list *ea_list)
+{
+ uint8_t *p = (uint8_t *)pdata;
+ uint8_t *last_start = NULL;
+
+ *ret_data_size = 0;
+
+ if (!lp_ea_support(SNUM(conn))) {
+ return NT_STATUS_NO_EAS_ON_FILE;
+ }
+
+ for (; ea_list; ea_list = ea_list->next) {
+ size_t dos_namelen;
+ fstring dos_ea_name;
+ size_t this_size;
+
+ if (last_start) {
+ SIVAL(last_start, 0, PTR_DIFF(p, last_start));
+ }
+ last_start = p;
+
+ push_ascii_fstring(dos_ea_name, ea_list->ea.name);
+ dos_namelen = strlen(dos_ea_name);
+ if (dos_namelen > 255 || dos_namelen == 0) {
+ return NT_STATUS_INTERNAL_ERROR;
+ }
+ if (ea_list->ea.value.length > 65535) {
+ return NT_STATUS_INTERNAL_ERROR;
+ }
+
+ this_size = 0x08 + dos_namelen + 1 + ea_list->ea.value.length;
+
+ if (ea_list->next) {
+ size_t pad = 4 - (this_size % 4);
+ this_size += pad;
+ }
+
+ if (this_size > total_data_size) {
+ return NT_STATUS_INFO_LENGTH_MISMATCH;
+ }
+
+ /* We know we have room. */
+ SIVAL(p, 0x00, 0); /* next offset */
+ SCVAL(p, 0x04, ea_list->ea.flags);
+ SCVAL(p, 0x05, dos_namelen);
+ SSVAL(p, 0x06, ea_list->ea.value.length);
+ fstrcpy((char *)(p+0x08), dos_ea_name);
+ memcpy(p + 0x08 + dos_namelen + 1, ea_list->ea.value.data, ea_list->ea.value.length);
+
+ total_data_size -= this_size;
+ p += this_size;
+ }
+
+ *ret_data_size = PTR_DIFF(p, pdata);
+ DEBUG(10,("fill_ea_chained_buffer: data_size = %u\n", *ret_data_size));
+ return NT_STATUS_OK;
+}
+
static unsigned int estimate_ea_size(connection_struct *conn, files_struct *fsp, const char *fname)
{
size_t total_ea_len = 0;
const struct smb_filename *smb_fname, struct ea_list *ea_list)
{
char *fname = NULL;
- NTSTATUS status;
if (!lp_ea_support(SNUM(conn))) {
return NT_STATUS_EAS_NOT_SUPPORTED;
}
- status = get_full_smb_filename(talloc_tos(), smb_fname,
- &fname);
- if (!NT_STATUS_IS_OK(status)) {
- return status;
- }
+ /* For now setting EAs on streams isn't supported. */
+ fname = smb_fname->base_name;
for (;ea_list; ea_list = ea_list->next) {
int ret;
if (ea_list->ea.value.length == 0) {
/* Remove the attribute. */
if (fsp && (fsp->fh->fd != -1)) {
- DEBUG(10,("set_ea: deleting ea name %s on file %s by file descriptor.\n",
- unix_ea_name, fsp->fsp_name));
+ DEBUG(10,("set_ea: deleting ea name %s on "
+ "file %s by file descriptor.\n",
+ unix_ea_name, fsp_str_dbg(fsp)));
ret = SMB_VFS_FREMOVEXATTR(fsp, unix_ea_name);
} else {
DEBUG(10,("set_ea: deleting ea name %s on file %s.\n",
#endif
} else {
if (fsp && (fsp->fh->fd != -1)) {
- DEBUG(10,("set_ea: setting ea name %s on file %s by file descriptor.\n",
- unix_ea_name, fsp->fsp_name));
+ DEBUG(10,("set_ea: setting ea name %s on file "
+ "%s by file descriptor.\n",
+ unix_ea_name, fsp_str_dbg(fsp)));
ret = SMB_VFS_FSETXATTR(fsp, unix_ea_name,
ea_list->ea.value.data, ea_list->ea.value.length, 0);
} else {
conn,
req->flags2 & FLAGS2_DFS_PATHNAMES,
fname,
- &smb_fname,
- NULL);
+ 0,
+ NULL,
+ &smb_fname);
if (!NT_STATUS_IS_OK(status)) {
if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
reply_botherror(req,
goto out;
}
- if (!map_open_params_to_ntcreate(smb_fname->base_name, deny_mode,
- open_ofun,
- &access_mask,
- &share_mode,
- &create_disposition,
- &create_options)) {
+ if (!map_open_params_to_ntcreate(smb_fname, deny_mode, open_ofun,
+ &access_mask, &share_mode,
+ &create_disposition,
+ &create_options)) {
reply_doserror(req, ERRDOS, ERRbadaccess);
goto out;
}
SIVAL(params,20,inode);
SSVAL(params,24,0); /* Padding. */
if (flags & 8) {
- uint32 ea_size = estimate_ea_size(conn, fsp, fsp->fsp_name);
+ uint32 ea_size = estimate_ea_size(conn, fsp,
+ fsp->fsp_name->base_name);
SIVAL(params, 26, ea_size);
} else {
SIVAL(params, 26, 0);
Case can be significant or not.
**********************************************************/
-static bool exact_match(connection_struct *conn,
- const char *str,
- const char *mask)
+static bool exact_match(bool has_wild,
+ bool case_sensitive,
+ const char *str,
+ const char *mask)
{
- if (mask[0] == '.' && mask[1] == 0)
- return False;
- if (dptr_has_wild(conn->dirptr)) {
- return False;
+ if (mask[0] == '.' && mask[1] == 0) {
+ return false;
+ }
+
+ if (has_wild) {
+ return false;
}
- if (conn->case_sensitive)
+
+ if (case_sensitive) {
return strcmp(str,mask)==0;
- else
+ } else {
return StrCaseCmp(str,mask) == 0;
+ }
}
/****************************************************************************
Get a level dependent lanman2 dir entry.
****************************************************************************/
-static bool get_lanman2_dir_entry(TALLOC_CTX *ctx,
- connection_struct *conn,
- uint16 flags2,
- const char *path_mask,
- uint32 dirtype,
- int info_level,
- int requires_resume_key,
- bool dont_descend,
- bool ask_sharemode,
- char **ppdata,
- char *base_data,
- char *end_data,
- int space_remaining,
- bool *out_of_space,
- bool *got_exact_match,
- int *last_entry_off,
- struct ea_list *name_list)
+struct smbd_dirptr_lanman2_state {
+ connection_struct *conn;
+ uint32_t info_level;
+ bool check_mangled_names;
+ bool has_wild;
+ bool got_exact_match;
+};
+
+static bool smbd_dirptr_lanman2_match_fn(TALLOC_CTX *ctx,
+ void *private_data,
+ const char *dname,
+ const char *mask,
+ char **_fname)
+{
+ struct smbd_dirptr_lanman2_state *state =
+ (struct smbd_dirptr_lanman2_state *)private_data;
+ bool ok;
+ char mangled_name[13]; /* mangled 8.3 name. */
+ bool got_match;
+ const char *fname;
+
+ /* Mangle fname if it's an illegal name. */
+ if (mangle_must_mangle(dname, state->conn->params)) {
+ ok = name_to_8_3(dname, mangled_name,
+ true, state->conn->params);
+ if (!ok) {
+ return false;
+ }
+ fname = mangled_name;
+ } else {
+ fname = dname;
+ }
+
+ got_match = exact_match(state->has_wild,
+ state->conn->case_sensitive,
+ fname, mask);
+ state->got_exact_match = got_match;
+ if (!got_match) {
+ got_match = mask_match(fname, mask,
+ state->conn->case_sensitive);
+ }
+
+ if(!got_match && state->check_mangled_names &&
+ !mangle_is_8_3(fname, false, state->conn->params)) {
+ /*
+ * It turns out that NT matches wildcards against
+ * both long *and* short names. This may explain some
+ * of the wildcard wierdness from old DOS clients
+ * that some people have been seeing.... JRA.
+ */
+ /* Force the mangling into 8.3. */
+ ok = name_to_8_3(fname, mangled_name,
+ false, state->conn->params);
+ if (!ok) {
+ return false;
+ }
+
+ got_match = exact_match(state->has_wild,
+ state->conn->case_sensitive,
+ mangled_name, mask);
+ state->got_exact_match = got_match;
+ if (!got_match) {
+ got_match = mask_match(mangled_name, mask,
+ state->conn->case_sensitive);
+ }
+ }
+
+ if (!got_match) {
+ return false;
+ }
+
+ *_fname = talloc_strdup(ctx, fname);
+ if (*_fname == NULL) {
+ return false;
+ }
+
+ return true;
+}
+
+static bool smbd_dirptr_lanman2_mode_fn(TALLOC_CTX *ctx,
+ void *private_data,
+ struct smb_filename *smb_fname,
+ uint32_t *_mode)
+{
+ struct smbd_dirptr_lanman2_state *state =
+ (struct smbd_dirptr_lanman2_state *)private_data;
+ bool ms_dfs_link = false;
+ uint32_t mode = 0;
+
+ if (INFO_LEVEL_IS_UNIX(state->info_level)) {
+ if (SMB_VFS_LSTAT(state->conn, smb_fname) != 0) {
+ DEBUG(5,("smbd_dirptr_lanman2_mode_fn: "
+ "Couldn't lstat [%s] (%s)\n",
+ smb_fname_str_dbg(smb_fname),
+ strerror(errno)));
+ return false;
+ }
+ } else if (!VALID_STAT(smb_fname->st) &&
+ SMB_VFS_STAT(state->conn, smb_fname) != 0) {
+ /* Needed to show the msdfs symlinks as
+ * directories */
+
+ ms_dfs_link = check_msdfs_link(state->conn,
+ smb_fname->base_name,
+ &smb_fname->st);
+ if (!ms_dfs_link) {
+ DEBUG(5,("smbd_dirptr_lanman2_mode_fn: "
+ "Couldn't stat [%s] (%s)\n",
+ smb_fname_str_dbg(smb_fname),
+ strerror(errno)));
+ return false;
+ }
+ }
+
+ if (ms_dfs_link) {
+ mode = dos_mode_msdfs(state->conn, smb_fname);
+ } else {
+ mode = dos_mode(state->conn, smb_fname);
+ }
+
+ *_mode = mode;
+ return true;
+}
+
+static bool smbd_marshall_dir_entry(TALLOC_CTX *ctx,
+ connection_struct *conn,
+ uint16_t flags2,
+ uint32_t info_level,
+ struct ea_list *name_list,
+ bool check_mangled_names,
+ bool requires_resume_key,
+ uint32_t mode,
+ const char *fname,
+ const struct smb_filename *smb_fname,
+ uint64_t space_remaining,
+ char *base_data,
+ char **ppdata,
+ char *end_data,
+ bool *out_of_space,
+ uint64_t *last_entry_off)
{
- char *dname;
- bool found = False;
- SMB_STRUCT_STAT sbuf;
- const char *mask = NULL;
- char *pathreal = NULL;
- char *fname = NULL;
char *p, *q, *pdata = *ppdata;
- uint32 reskey=0;
- long prev_dirpos=0;
- uint32 mode=0;
- SMB_OFF_T file_size = 0;
+ uint32_t reskey=0;
+ uint64_t file_size = 0;
uint64_t allocation_size = 0;
- uint32 len;
+ uint32_t len;
struct timespec mdate_ts, adate_ts, create_date_ts;
time_t mdate = (time_t)0, adate = (time_t)0, create_date = (time_t)0;
char *nameptr;
char *last_entry_ptr;
bool was_8_3;
- uint32 nt_extmode; /* Used for NT connections instead of mode */
- bool needslash = ( conn->dirpath[strlen(conn->dirpath) -1] != '/');
- bool check_mangled_names = lp_manglednames(conn->params);
- char mangled_name[13]; /* mangled 8.3 name. */
+ uint32_t nt_extmode; /* Used for NT connections instead of mode */
- *out_of_space = False;
- *got_exact_match = False;
+ *out_of_space = false;
ZERO_STRUCT(mdate_ts);
ZERO_STRUCT(adate_ts);
ZERO_STRUCT(create_date_ts);
- if (!conn->dirptr) {
- return(False);
- }
-
- p = strrchr_m(path_mask,'/');
- if(p != NULL) {
- if(p[1] == '\0') {
- mask = talloc_strdup(ctx,"*.*");
- } else {
- mask = p+1;
- }
- } else {
- mask = path_mask;
+ if (!(mode & aDIR)) {
+ file_size = get_file_size_stat(&smb_fname->st);
}
+ allocation_size = SMB_VFS_GET_ALLOC_SIZE(conn, NULL, &smb_fname->st);
- while (!found) {
- bool got_match;
- bool ms_dfs_link = False;
+ mdate_ts = smb_fname->st.st_ex_mtime;
+ adate_ts = smb_fname->st.st_ex_atime;
+ create_date_ts = smb_fname->st.st_ex_btime;
- /* Needed if we run out of space */
- long curr_dirpos = prev_dirpos = dptr_TellDir(conn->dirptr);
- dname = dptr_ReadDirName(ctx,conn->dirptr,&curr_dirpos,&sbuf);
+ if (lp_dos_filetime_resolution(SNUM(conn))) {
+ dos_filetime_timespec(&create_date_ts);
+ dos_filetime_timespec(&mdate_ts);
+ dos_filetime_timespec(&adate_ts);
+ }
- /*
- * Due to bugs in NT client redirectors we are not using
- * resume keys any more - set them to zero.
- * Check out the related comments in findfirst/findnext.
- * JRA.
- */
+ create_date = convert_timespec_to_time_t(create_date_ts);
+ mdate = convert_timespec_to_time_t(mdate_ts);
+ adate = convert_timespec_to_time_t(adate_ts);
- reskey = 0;
+ p = pdata;
+ last_entry_ptr = p;
- DEBUG(8,("get_lanman2_dir_entry:readdir on dirptr 0x%lx now at offset %ld\n",
- (long)conn->dirptr,curr_dirpos));
+ nt_extmode = mode ? mode : FILE_ATTRIBUTE_NORMAL;
- if (!dname) {
- return(False);
+ switch (info_level) {
+ case SMB_FIND_INFO_STANDARD:
+ DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_INFO_STANDARD\n"));
+ if(requires_resume_key) {
+ SIVAL(p,0,reskey);
+ p += 4;
}
-
- /*
- * fname may get mangled, dname is never mangled.
- * Whenever we're accessing the filesystem we use
- * pathreal which is composed from dname.
- */
-
- pathreal = NULL;
- fname = dname;
-
- /* Mangle fname if it's an illegal name. */
- if (mangle_must_mangle(dname,conn->params)) {
- if (!name_to_8_3(dname,mangled_name,True,conn->params)) {
- TALLOC_FREE(fname);
- continue; /* Error - couldn't mangle. */
+ srv_put_dos_date2(p,0,create_date);
+ srv_put_dos_date2(p,4,adate);
+ srv_put_dos_date2(p,8,mdate);
+ SIVAL(p,12,(uint32)file_size);
+ SIVAL(p,16,(uint32)allocation_size);
+ SSVAL(p,20,mode);
+ p += 23;
+ nameptr = p;
+ if (flags2 & FLAGS2_UNICODE_STRINGS) {
+ p += ucs2_align(base_data, p, 0);
+ }
+ len = srvstr_push(base_data, flags2, p,
+ fname, PTR_DIFF(end_data, p),
+ STR_TERMINATE);
+ if (flags2 & FLAGS2_UNICODE_STRINGS) {
+ if (len > 2) {
+ SCVAL(nameptr, -1, len - 2);
+ } else {
+ SCVAL(nameptr, -1, 0);
}
- fname = talloc_strdup(ctx, mangled_name);
- if (!fname) {
- return False;
+ } else {
+ if (len > 1) {
+ SCVAL(nameptr, -1, len - 1);
+ } else {
+ SCVAL(nameptr, -1, 0);
}
}
+ p += len;
+ break;
- if(!(got_match = *got_exact_match = exact_match(conn, fname, mask))) {
- got_match = mask_match(fname, mask, conn->case_sensitive);
+ case SMB_FIND_EA_SIZE:
+ DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_EA_SIZE\n"));
+ if (requires_resume_key) {
+ SIVAL(p,0,reskey);
+ p += 4;
}
-
- if(!got_match && check_mangled_names &&
- !mangle_is_8_3(fname, False, conn->params)) {
- /*
- * It turns out that NT matches wildcards against
- * both long *and* short names. This may explain some
- * of the wildcard wierdness from old DOS clients
- * that some people have been seeing.... JRA.
- */
- /* Force the mangling into 8.3. */
- if (!name_to_8_3( fname, mangled_name, False, conn->params)) {
- TALLOC_FREE(fname);
- continue; /* Error - couldn't mangle. */
+ srv_put_dos_date2(p,0,create_date);
+ srv_put_dos_date2(p,4,adate);
+ srv_put_dos_date2(p,8,mdate);
+ SIVAL(p,12,(uint32)file_size);
+ SIVAL(p,16,(uint32)allocation_size);
+ SSVAL(p,20,mode);
+ {
+ unsigned int ea_size = estimate_ea_size(conn, NULL,
+ smb_fname->base_name);
+ SIVAL(p,22,ea_size); /* Extended attributes */
+ }
+ p += 27;
+ nameptr = p - 1;
+ len = srvstr_push(base_data, flags2,
+ p, fname, PTR_DIFF(end_data, p),
+ STR_TERMINATE | STR_NOALIGN);
+ if (flags2 & FLAGS2_UNICODE_STRINGS) {
+ if (len > 2) {
+ len -= 2;
+ } else {
+ len = 0;
}
-
- if(!(got_match = *got_exact_match = exact_match(conn, mangled_name, mask))) {
- got_match = mask_match(mangled_name, mask, conn->case_sensitive);
+ } else {
+ if (len > 1) {
+ len -= 1;
+ } else {
+ len = 0;
}
}
+ SCVAL(nameptr,0,len);
+ p += len;
+ SCVAL(p,0,0); p += 1; /* Extra zero byte ? - why.. */
+ break;
- if (got_match) {
- bool isdots = (ISDOT(dname) || ISDOTDOT(dname));
- struct smb_filename *smb_fname = NULL;
- NTSTATUS status;
-
- if (dont_descend && !isdots) {
- TALLOC_FREE(fname);
- continue;
- }
+ case SMB_FIND_EA_LIST:
+ {
+ struct ea_list *file_list = NULL;
+ size_t ea_len = 0;
- if (needslash) {
- pathreal = NULL;
- pathreal = talloc_asprintf(ctx,
- "%s/%s",
- conn->dirpath,
- dname);
+ DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_EA_LIST\n"));
+ if (!name_list) {
+ return false;
+ }
+ if (requires_resume_key) {
+ SIVAL(p,0,reskey);
+ p += 4;
+ }
+ srv_put_dos_date2(p,0,create_date);
+ srv_put_dos_date2(p,4,adate);
+ srv_put_dos_date2(p,8,mdate);
+ SIVAL(p,12,(uint32)file_size);
+ SIVAL(p,16,(uint32)allocation_size);
+ SSVAL(p,20,mode);
+ p += 22; /* p now points to the EA area. */
+
+ file_list = get_ea_list_from_file(ctx, conn, NULL,
+ smb_fname->base_name,
+ &ea_len);
+ name_list = ea_list_union(name_list, file_list, &ea_len);
+
+ /* We need to determine if this entry will fit in the space available. */
+ /* Max string size is 255 bytes. */
+ if (PTR_DIFF(p + 255 + ea_len,pdata) > space_remaining) {
+ *out_of_space = true;
+ DEBUG(9,("get_lanman2_dir_entry: out of space\n"));
+ return False; /* Not finished - just out of space */
+ }
+
+ /* Push the ea_data followed by the name. */
+ p += fill_ea_buffer(ctx, p, space_remaining, conn, name_list);
+ nameptr = p;
+ len = srvstr_push(base_data, flags2,
+ p + 1, fname, PTR_DIFF(end_data, p+1),
+ STR_TERMINATE | STR_NOALIGN);
+ if (flags2 & FLAGS2_UNICODE_STRINGS) {
+ if (len > 2) {
+ len -= 2;
} else {
- pathreal = talloc_asprintf(ctx,
- "%s%s",
- conn->dirpath,
- dname);
+ len = 0;
}
-
- if (!pathreal) {
- TALLOC_FREE(fname);
- return False;
+ } else {
+ if (len > 1) {
+ len -= 1;
+ } else {
+ len = 0;
}
+ }
+ SCVAL(nameptr,0,len);
+ p += len + 1;
+ SCVAL(p,0,0); p += 1; /* Extra zero byte ? - why.. */
+ break;
+ }
- /* A dirent from dptr_ReadDirName isn't a stream. */
- status = create_synthetic_smb_fname(ctx, pathreal,
- NULL, &sbuf,
- &smb_fname);
- if (!NT_STATUS_IS_OK(status)) {
- TALLOC_FREE(fname);
- return false;
+ case SMB_FIND_FILE_BOTH_DIRECTORY_INFO:
+ DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_FILE_BOTH_DIRECTORY_INFO\n"));
+ was_8_3 = mangle_is_8_3(fname, True, conn->params);
+ p += 4;
+ SIVAL(p,0,reskey); p += 4;
+ put_long_date_timespec(p,create_date_ts); p += 8;
+ put_long_date_timespec(p,adate_ts); p += 8;
+ put_long_date_timespec(p,mdate_ts); p += 8;
+ put_long_date_timespec(p,mdate_ts); p += 8;
+ SOFF_T(p,0,file_size); p += 8;
+ SOFF_T(p,0,allocation_size); p += 8;
+ SIVAL(p,0,nt_extmode); p += 4;
+ q = p; p += 4; /* q is placeholder for name length. */
+ {
+ unsigned int ea_size = estimate_ea_size(conn, NULL,
+ smb_fname->base_name);
+ SIVAL(p,0,ea_size); /* Extended attributes */
+ p += 4;
+ }
+ /* Clear the short name buffer. This is
+ * IMPORTANT as not doing so will trigger
+ * a Win2k client bug. JRA.
+ */
+ if (!was_8_3 && check_mangled_names) {
+ char mangled_name[13]; /* mangled 8.3 name. */
+ if (!name_to_8_3(fname,mangled_name,True,
+ conn->params)) {
+ /* Error - mangle failed ! */
+ memset(mangled_name,'\0',12);
}
-
- if (INFO_LEVEL_IS_UNIX(info_level)) {
- if (SMB_VFS_LSTAT(conn, smb_fname) != 0) {
- DEBUG(5,("get_lanman2_dir_entry: "
- "Couldn't lstat [%s] (%s)\n",
- smb_fname_str_dbg(smb_fname),
- strerror(errno)));
- TALLOC_FREE(smb_fname);
- TALLOC_FREE(pathreal);
- TALLOC_FREE(fname);
- continue;
- }
- } else if (!VALID_STAT(smb_fname->st) &&
- SMB_VFS_STAT(conn, smb_fname) != 0) {
- /* Needed to show the msdfs symlinks as
- * directories */
-
- ms_dfs_link =
- check_msdfs_link(conn,
- smb_fname->base_name,
- &smb_fname->st);
- if (!ms_dfs_link) {
- DEBUG(5,("get_lanman2_dir_entry: "
- "Couldn't stat [%s] (%s)\n",
- smb_fname_str_dbg(smb_fname),
- strerror(errno)));
- TALLOC_FREE(smb_fname);
- TALLOC_FREE(pathreal);
- TALLOC_FREE(fname);
- continue;
- }
+ mangled_name[12] = 0;
+ len = srvstr_push(base_data, flags2,
+ p+2, mangled_name, 24,
+ STR_UPPER|STR_UNICODE);
+ if (len < 24) {
+ memset(p + 2 + len,'\0',24 - len);
}
+ SSVAL(p, 0, len);
+ } else {
+ memset(p,'\0',26);
+ }
+ p += 2 + 24;
+ len = srvstr_push(base_data, flags2, p,
+ fname, PTR_DIFF(end_data, p),
+ STR_TERMINATE_ASCII);
+ SIVAL(q,0,len);
+ p += len;
+ SIVAL(p,0,0); /* Ensure any padding is null. */
+ len = PTR_DIFF(p, pdata);
+ len = (len + 3) & ~3;
+ SIVAL(pdata,0,len);
+ p = pdata + len;
+ break;
- if (ms_dfs_link) {
- mode = dos_mode_msdfs(conn, smb_fname);
- } else {
- mode = dos_mode(conn, smb_fname);
- }
+ case SMB_FIND_FILE_DIRECTORY_INFO:
+ DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_FILE_DIRECTORY_INFO\n"));
+ p += 4;
+ SIVAL(p,0,reskey); p += 4;
+ put_long_date_timespec(p,create_date_ts); p += 8;
+ put_long_date_timespec(p,adate_ts); p += 8;
+ put_long_date_timespec(p,mdate_ts); p += 8;
+ put_long_date_timespec(p,mdate_ts); p += 8;
+ SOFF_T(p,0,file_size); p += 8;
+ SOFF_T(p,0,allocation_size); p += 8;
+ SIVAL(p,0,nt_extmode); p += 4;
+ len = srvstr_push(base_data, flags2,
+ p + 4, fname, PTR_DIFF(end_data, p+4),
+ STR_TERMINATE_ASCII);
+ SIVAL(p,0,len);
+ p += 4 + len;
+ SIVAL(p,0,0); /* Ensure any padding is null. */
+ len = PTR_DIFF(p, pdata);
+ len = (len + 3) & ~3;
+ SIVAL(pdata,0,len);
+ p = pdata + len;
+ break;
- if (!dir_check_ftype(conn,mode,dirtype)) {
- DEBUG(5,("get_lanman2_dir_entry: [%s] attribs didn't match %x\n",fname,dirtype));
- TALLOC_FREE(smb_fname);
- TALLOC_FREE(pathreal);
- TALLOC_FREE(fname);
- continue;
- }
+ case SMB_FIND_FILE_FULL_DIRECTORY_INFO:
+ DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_FILE_FULL_DIRECTORY_INFO\n"));
+ p += 4;
+ SIVAL(p,0,reskey); p += 4;
+ put_long_date_timespec(p,create_date_ts); p += 8;
+ put_long_date_timespec(p,adate_ts); p += 8;
+ put_long_date_timespec(p,mdate_ts); p += 8;
+ put_long_date_timespec(p,mdate_ts); p += 8;
+ SOFF_T(p,0,file_size); p += 8;
+ SOFF_T(p,0,allocation_size); p += 8;
+ SIVAL(p,0,nt_extmode); p += 4;
+ q = p; p += 4; /* q is placeholder for name length. */
+ {
+ unsigned int ea_size = estimate_ea_size(conn, NULL,
+ smb_fname->base_name);
+ SIVAL(p,0,ea_size); /* Extended attributes */
+ p +=4;
+ }
+ len = srvstr_push(base_data, flags2, p,
+ fname, PTR_DIFF(end_data, p),
+ STR_TERMINATE_ASCII);
+ SIVAL(q, 0, len);
+ p += len;
+
+ SIVAL(p,0,0); /* Ensure any padding is null. */
+ len = PTR_DIFF(p, pdata);
+ len = (len + 3) & ~3;
+ SIVAL(pdata,0,len);
+ p = pdata + len;
+ break;
- if (!(mode & aDIR)) {
- file_size = get_file_size_stat(&smb_fname->st);
- }
- allocation_size =
- SMB_VFS_GET_ALLOC_SIZE(conn, NULL, &smb_fname->st);
-
- if (ask_sharemode) {
- struct timespec write_time_ts;
- struct file_id fileid;
-
- ZERO_STRUCT(write_time_ts);
- fileid = vfs_file_id_from_sbuf(conn,
- &smb_fname->st);
- get_file_infos(fileid, NULL, &write_time_ts);
- if (!null_timespec(write_time_ts)) {
- update_stat_ex_mtime(&smb_fname->st,
- write_time_ts);
- }
- }
+ case SMB_FIND_FILE_NAMES_INFO:
+ DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_FILE_NAMES_INFO\n"));
+ p += 4;
+ SIVAL(p,0,reskey); p += 4;
+ p += 4;
+ /* this must *not* be null terminated or w2k gets in a loop trying to set an
+ acl on a dir (tridge) */
+ len = srvstr_push(base_data, flags2, p,
+ fname, PTR_DIFF(end_data, p),
+ STR_TERMINATE_ASCII);
+ SIVAL(p, -4, len);
+ p += len;
+ SIVAL(p,0,0); /* Ensure any padding is null. */
+ len = PTR_DIFF(p, pdata);
+ len = (len + 3) & ~3;
+ SIVAL(pdata,0,len);
+ p = pdata + len;
+ break;
- mdate_ts = smb_fname->st.st_ex_mtime;
- adate_ts = smb_fname->st.st_ex_atime;
- create_date_ts = smb_fname->st.st_ex_btime;
+ case SMB_FIND_ID_FULL_DIRECTORY_INFO:
+ DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_ID_FULL_DIRECTORY_INFO\n"));
+ p += 4;
+ SIVAL(p,0,reskey); p += 4;
+ put_long_date_timespec(p,create_date_ts); p += 8;
+ put_long_date_timespec(p,adate_ts); p += 8;
+ put_long_date_timespec(p,mdate_ts); p += 8;
+ put_long_date_timespec(p,mdate_ts); p += 8;
+ SOFF_T(p,0,file_size); p += 8;
+ SOFF_T(p,0,allocation_size); p += 8;
+ SIVAL(p,0,nt_extmode); p += 4;
+ q = p; p += 4; /* q is placeholder for name length. */
+ {
+ unsigned int ea_size = estimate_ea_size(conn, NULL,
+ smb_fname->base_name);
+ SIVAL(p,0,ea_size); /* Extended attributes */
+ p +=4;
+ }
+ SIVAL(p,0,0); p += 4; /* Unknown - reserved ? */
+ SIVAL(p,0,smb_fname->st.st_ex_ino); p += 4; /* FileIndexLow */
+ SIVAL(p,0,smb_fname->st.st_ex_dev); p += 4; /* FileIndexHigh */
+ len = srvstr_push(base_data, flags2, p,
+ fname, PTR_DIFF(end_data, p),
+ STR_TERMINATE_ASCII);
+ SIVAL(q, 0, len);
+ p += len;
+ SIVAL(p,0,0); /* Ensure any padding is null. */
+ len = PTR_DIFF(p, pdata);
+ len = (len + 3) & ~3;
+ SIVAL(pdata,0,len);
+ p = pdata + len;
+ break;
- if (lp_dos_filetime_resolution(SNUM(conn))) {
- dos_filetime_timespec(&create_date_ts);
- dos_filetime_timespec(&mdate_ts);
- dos_filetime_timespec(&adate_ts);
+ case SMB_FIND_ID_BOTH_DIRECTORY_INFO:
+ DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_ID_BOTH_DIRECTORY_INFO\n"));
+ was_8_3 = mangle_is_8_3(fname, True, conn->params);
+ p += 4;
+ SIVAL(p,0,reskey); p += 4;
+ put_long_date_timespec(p,create_date_ts); p += 8;
+ put_long_date_timespec(p,adate_ts); p += 8;
+ put_long_date_timespec(p,mdate_ts); p += 8;
+ put_long_date_timespec(p,mdate_ts); p += 8;
+ SOFF_T(p,0,file_size); p += 8;
+ SOFF_T(p,0,allocation_size); p += 8;
+ SIVAL(p,0,nt_extmode); p += 4;
+ q = p; p += 4; /* q is placeholder for name length */
+ {
+ unsigned int ea_size = estimate_ea_size(conn, NULL,
+ smb_fname->base_name);
+ SIVAL(p,0,ea_size); /* Extended attributes */
+ p +=4;
+ }
+ /* Clear the short name buffer. This is
+ * IMPORTANT as not doing so will trigger
+ * a Win2k client bug. JRA.
+ */
+ if (!was_8_3 && check_mangled_names) {
+ char mangled_name[13]; /* mangled 8.3 name. */
+ if (!name_to_8_3(fname,mangled_name,True,
+ conn->params)) {
+ /* Error - mangle failed ! */
+ memset(mangled_name,'\0',12);
}
+ mangled_name[12] = 0;
+ len = srvstr_push(base_data, flags2,
+ p+2, mangled_name, 24,
+ STR_UPPER|STR_UNICODE);
+ SSVAL(p, 0, len);
+ if (len < 24) {
+ memset(p + 2 + len,'\0',24 - len);
+ }
+ SSVAL(p, 0, len);
+ } else {
+ memset(p,'\0',26);
+ }
+ p += 26;
+ SSVAL(p,0,0); p += 2; /* Reserved ? */
+ SIVAL(p,0,smb_fname->st.st_ex_ino); p += 4; /* FileIndexLow */
+ SIVAL(p,0,smb_fname->st.st_ex_dev); p += 4; /* FileIndexHigh */
+ len = srvstr_push(base_data, flags2, p,
+ fname, PTR_DIFF(end_data, p),
+ STR_TERMINATE_ASCII);
+ SIVAL(q,0,len);
+ p += len;
+ SIVAL(p,0,0); /* Ensure any padding is null. */
+ len = PTR_DIFF(p, pdata);
+ len = (len + 3) & ~3;
+ SIVAL(pdata,0,len);
+ p = pdata + len;
+ break;
- create_date = convert_timespec_to_time_t(create_date_ts);
- mdate = convert_timespec_to_time_t(mdate_ts);
- adate = convert_timespec_to_time_t(adate_ts);
-
- DEBUG(5,("get_lanman2_dir_entry: found %s fname=%s\n",
- smb_fname_str_dbg(smb_fname), fname));
+ /* CIFS UNIX Extension. */
- found = True;
+ case SMB_FIND_FILE_UNIX:
+ case SMB_FIND_FILE_UNIX_INFO2:
+ p+= 4;
+ SIVAL(p,0,reskey); p+= 4; /* Used for continuing search. */
- dptr_DirCacheAdd(conn->dirptr, dname, curr_dirpos);
- sbuf = smb_fname->st;
+ /* Begin of SMB_QUERY_FILE_UNIX_BASIC */
- TALLOC_FREE(smb_fname);
+ if (info_level == SMB_FIND_FILE_UNIX) {
+ DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_FILE_UNIX\n"));
+ p = store_file_unix_basic(conn, p,
+ NULL, &smb_fname->st);
+ len = srvstr_push(base_data, flags2, p,
+ fname, PTR_DIFF(end_data, p),
+ STR_TERMINATE);
+ } else {
+ DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_FILE_UNIX_INFO2\n"));
+ p = store_file_unix_basic_info2(conn, p,
+ NULL, &smb_fname->st);
+ nameptr = p;
+ p += 4;
+ len = srvstr_push(base_data, flags2, p, fname,
+ PTR_DIFF(end_data, p), 0);
+ SIVAL(nameptr, 0, len);
}
- if (!found)
- TALLOC_FREE(fname);
- }
+ p += len;
+ SIVAL(p,0,0); /* Ensure any padding is null. */
- p = pdata;
- last_entry_ptr = p;
+ len = PTR_DIFF(p, pdata);
+ len = (len + 3) & ~3;
+ SIVAL(pdata,0,len); /* Offset from this structure to the beginning of the next one */
+ p = pdata + len;
+ /* End of SMB_QUERY_FILE_UNIX_BASIC */
- nt_extmode = mode ? mode : FILE_ATTRIBUTE_NORMAL;
+ break;
- switch (info_level) {
- case SMB_FIND_INFO_STANDARD:
- DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_INFO_STANDARD\n"));
- if(requires_resume_key) {
- SIVAL(p,0,reskey);
- p += 4;
- }
- srv_put_dos_date2(p,0,create_date);
- srv_put_dos_date2(p,4,adate);
- srv_put_dos_date2(p,8,mdate);
- SIVAL(p,12,(uint32)file_size);
- SIVAL(p,16,(uint32)allocation_size);
- SSVAL(p,20,mode);
- p += 23;
- nameptr = p;
- if (flags2 & FLAGS2_UNICODE_STRINGS) {
- p += ucs2_align(base_data, p, 0);
- }
- len = srvstr_push(base_data, flags2, p,
- fname, PTR_DIFF(end_data, p),
- STR_TERMINATE);
- if (flags2 & FLAGS2_UNICODE_STRINGS) {
- if (len > 2) {
- SCVAL(nameptr, -1, len - 2);
- } else {
- SCVAL(nameptr, -1, 0);
- }
- } else {
- if (len > 1) {
- SCVAL(nameptr, -1, len - 1);
- } else {
- SCVAL(nameptr, -1, 0);
- }
- }
- p += len;
- break;
+ default:
+ return false;
+ }
- case SMB_FIND_EA_SIZE:
- DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_EA_SIZE\n"));
- if(requires_resume_key) {
- SIVAL(p,0,reskey);
- p += 4;
- }
- srv_put_dos_date2(p,0,create_date);
- srv_put_dos_date2(p,4,adate);
- srv_put_dos_date2(p,8,mdate);
- SIVAL(p,12,(uint32)file_size);
- SIVAL(p,16,(uint32)allocation_size);
- SSVAL(p,20,mode);
- {
- unsigned int ea_size = estimate_ea_size(conn, NULL, pathreal);
- SIVAL(p,22,ea_size); /* Extended attributes */
- }
- p += 27;
- nameptr = p - 1;
- len = srvstr_push(base_data, flags2,
- p, fname, PTR_DIFF(end_data, p),
- STR_TERMINATE | STR_NOALIGN);
- if (flags2 & FLAGS2_UNICODE_STRINGS) {
- if (len > 2) {
- len -= 2;
- } else {
- len = 0;
- }
- } else {
- if (len > 1) {
- len -= 1;
- } else {
- len = 0;
- }
- }
- SCVAL(nameptr,0,len);
- p += len;
- SCVAL(p,0,0); p += 1; /* Extra zero byte ? - why.. */
- break;
+ if (PTR_DIFF(p,pdata) > space_remaining) {
+ *out_of_space = true;
+ DEBUG(9,("get_lanman2_dir_entry: out of space\n"));
+ return false; /* Not finished - just out of space */
+ }
- case SMB_FIND_EA_LIST:
- {
- struct ea_list *file_list = NULL;
- size_t ea_len = 0;
+ /* Setup the last entry pointer, as an offset from base_data */
+ *last_entry_off = PTR_DIFF(last_entry_ptr,base_data);
+ /* Advance the data pointer to the next slot */
+ *ppdata = p;
- DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_EA_LIST\n"));
- if (!name_list) {
- return False;
- }
- if(requires_resume_key) {
- SIVAL(p,0,reskey);
- p += 4;
- }
- srv_put_dos_date2(p,0,create_date);
- srv_put_dos_date2(p,4,adate);
- srv_put_dos_date2(p,8,mdate);
- SIVAL(p,12,(uint32)file_size);
- SIVAL(p,16,(uint32)allocation_size);
- SSVAL(p,20,mode);
- p += 22; /* p now points to the EA area. */
-
- file_list = get_ea_list_from_file(ctx, conn, NULL, pathreal, &ea_len);
- name_list = ea_list_union(name_list, file_list, &ea_len);
-
- /* We need to determine if this entry will fit in the space available. */
- /* Max string size is 255 bytes. */
- if (PTR_DIFF(p + 255 + ea_len,pdata) > space_remaining) {
- /* Move the dirptr back to prev_dirpos */
- dptr_SeekDir(conn->dirptr, prev_dirpos);
- *out_of_space = True;
- DEBUG(9,("get_lanman2_dir_entry: out of space\n"));
- return False; /* Not finished - just out of space */
- }
+ return true;
+}
- /* Push the ea_data followed by the name. */
- p += fill_ea_buffer(ctx, p, space_remaining, conn, name_list);
- nameptr = p;
- len = srvstr_push(base_data, flags2,
- p + 1, fname, PTR_DIFF(end_data, p+1),
- STR_TERMINATE | STR_NOALIGN);
- if (flags2 & FLAGS2_UNICODE_STRINGS) {
- if (len > 2) {
- len -= 2;
- } else {
- len = 0;
- }
- } else {
- if (len > 1) {
- len -= 1;
- } else {
- len = 0;
- }
- }
- SCVAL(nameptr,0,len);
- p += len + 1;
- SCVAL(p,0,0); p += 1; /* Extra zero byte ? - why.. */
- break;
- }
-
- case SMB_FIND_FILE_BOTH_DIRECTORY_INFO:
- DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_FILE_BOTH_DIRECTORY_INFO\n"));
- was_8_3 = mangle_is_8_3(fname, True, conn->params);
- p += 4;
- SIVAL(p,0,reskey); p += 4;
- put_long_date_timespec(p,create_date_ts); p += 8;
- put_long_date_timespec(p,adate_ts); p += 8;
- put_long_date_timespec(p,mdate_ts); p += 8;
- put_long_date_timespec(p,mdate_ts); p += 8;
- SOFF_T(p,0,file_size); p += 8;
- SOFF_T(p,0,allocation_size); p += 8;
- SIVAL(p,0,nt_extmode); p += 4;
- q = p; p += 4; /* q is placeholder for name length. */
- {
- unsigned int ea_size = estimate_ea_size(conn, NULL, pathreal);
- SIVAL(p,0,ea_size); /* Extended attributes */
- p += 4;
- }
- /* Clear the short name buffer. This is
- * IMPORTANT as not doing so will trigger
- * a Win2k client bug. JRA.
- */
- if (!was_8_3 && check_mangled_names) {
- if (!name_to_8_3(fname,mangled_name,True,
- conn->params)) {
- /* Error - mangle failed ! */
- memset(mangled_name,'\0',12);
- }
- mangled_name[12] = 0;
- len = srvstr_push(base_data, flags2,
- p+2, mangled_name, 24,
- STR_UPPER|STR_UNICODE);
- if (len < 24) {
- memset(p + 2 + len,'\0',24 - len);
- }
- SSVAL(p, 0, len);
- } else {
- memset(p,'\0',26);
- }
- p += 2 + 24;
- len = srvstr_push(base_data, flags2, p,
- fname, PTR_DIFF(end_data, p),
- STR_TERMINATE_ASCII);
- SIVAL(q,0,len);
- p += len;
- SIVAL(p,0,0); /* Ensure any padding is null. */
- len = PTR_DIFF(p, pdata);
- len = (len + 3) & ~3;
- SIVAL(pdata,0,len);
- p = pdata + len;
- break;
-
- case SMB_FIND_FILE_DIRECTORY_INFO:
- DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_FILE_DIRECTORY_INFO\n"));
- p += 4;
- SIVAL(p,0,reskey); p += 4;
- put_long_date_timespec(p,create_date_ts); p += 8;
- put_long_date_timespec(p,adate_ts); p += 8;
- put_long_date_timespec(p,mdate_ts); p += 8;
- put_long_date_timespec(p,mdate_ts); p += 8;
- SOFF_T(p,0,file_size); p += 8;
- SOFF_T(p,0,allocation_size); p += 8;
- SIVAL(p,0,nt_extmode); p += 4;
- len = srvstr_push(base_data, flags2,
- p + 4, fname, PTR_DIFF(end_data, p+4),
- STR_TERMINATE_ASCII);
- SIVAL(p,0,len);
- p += 4 + len;
- SIVAL(p,0,0); /* Ensure any padding is null. */
- len = PTR_DIFF(p, pdata);
- len = (len + 3) & ~3;
- SIVAL(pdata,0,len);
- p = pdata + len;
- break;
-
- case SMB_FIND_FILE_FULL_DIRECTORY_INFO:
- DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_FILE_FULL_DIRECTORY_INFO\n"));
- p += 4;
- SIVAL(p,0,reskey); p += 4;
- put_long_date_timespec(p,create_date_ts); p += 8;
- put_long_date_timespec(p,adate_ts); p += 8;
- put_long_date_timespec(p,mdate_ts); p += 8;
- put_long_date_timespec(p,mdate_ts); p += 8;
- SOFF_T(p,0,file_size); p += 8;
- SOFF_T(p,0,allocation_size); p += 8;
- SIVAL(p,0,nt_extmode); p += 4;
- q = p; p += 4; /* q is placeholder for name length. */
- {
- unsigned int ea_size = estimate_ea_size(conn, NULL, pathreal);
- SIVAL(p,0,ea_size); /* Extended attributes */
- p +=4;
- }
- len = srvstr_push(base_data, flags2, p,
- fname, PTR_DIFF(end_data, p),
- STR_TERMINATE_ASCII);
- SIVAL(q, 0, len);
- p += len;
-
- SIVAL(p,0,0); /* Ensure any padding is null. */
- len = PTR_DIFF(p, pdata);
- len = (len + 3) & ~3;
- SIVAL(pdata,0,len);
- p = pdata + len;
- break;
-
- case SMB_FIND_FILE_NAMES_INFO:
- DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_FILE_NAMES_INFO\n"));
- p += 4;
- SIVAL(p,0,reskey); p += 4;
- p += 4;
- /* this must *not* be null terminated or w2k gets in a loop trying to set an
- acl on a dir (tridge) */
- len = srvstr_push(base_data, flags2, p,
- fname, PTR_DIFF(end_data, p),
- STR_TERMINATE_ASCII);
- SIVAL(p, -4, len);
- p += len;
- SIVAL(p,0,0); /* Ensure any padding is null. */
- len = PTR_DIFF(p, pdata);
- len = (len + 3) & ~3;
- SIVAL(pdata,0,len);
- p = pdata + len;
- break;
-
- case SMB_FIND_ID_FULL_DIRECTORY_INFO:
- DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_ID_FULL_DIRECTORY_INFO\n"));
- p += 4;
- SIVAL(p,0,reskey); p += 4;
- put_long_date_timespec(p,create_date_ts); p += 8;
- put_long_date_timespec(p,adate_ts); p += 8;
- put_long_date_timespec(p,mdate_ts); p += 8;
- put_long_date_timespec(p,mdate_ts); p += 8;
- SOFF_T(p,0,file_size); p += 8;
- SOFF_T(p,0,allocation_size); p += 8;
- SIVAL(p,0,nt_extmode); p += 4;
- q = p; p += 4; /* q is placeholder for name length. */
- {
- unsigned int ea_size = estimate_ea_size(conn, NULL, pathreal);
- SIVAL(p,0,ea_size); /* Extended attributes */
- p +=4;
- }
- SIVAL(p,0,0); p += 4; /* Unknown - reserved ? */
- SIVAL(p,0,sbuf.st_ex_ino); p += 4; /* FileIndexLow */
- SIVAL(p,0,sbuf.st_ex_dev); p += 4; /* FileIndexHigh */
- len = srvstr_push(base_data, flags2, p,
- fname, PTR_DIFF(end_data, p),
- STR_TERMINATE_ASCII);
- SIVAL(q, 0, len);
- p += len;
- SIVAL(p,0,0); /* Ensure any padding is null. */
- len = PTR_DIFF(p, pdata);
- len = (len + 3) & ~3;
- SIVAL(pdata,0,len);
- p = pdata + len;
- break;
-
- case SMB_FIND_ID_BOTH_DIRECTORY_INFO:
- DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_ID_BOTH_DIRECTORY_INFO\n"));
- was_8_3 = mangle_is_8_3(fname, True, conn->params);
- p += 4;
- SIVAL(p,0,reskey); p += 4;
- put_long_date_timespec(p,create_date_ts); p += 8;
- put_long_date_timespec(p,adate_ts); p += 8;
- put_long_date_timespec(p,mdate_ts); p += 8;
- put_long_date_timespec(p,mdate_ts); p += 8;
- SOFF_T(p,0,file_size); p += 8;
- SOFF_T(p,0,allocation_size); p += 8;
- SIVAL(p,0,nt_extmode); p += 4;
- q = p; p += 4; /* q is placeholder for name length */
- {
- unsigned int ea_size = estimate_ea_size(conn, NULL, pathreal);
- SIVAL(p,0,ea_size); /* Extended attributes */
- p +=4;
- }
- /* Clear the short name buffer. This is
- * IMPORTANT as not doing so will trigger
- * a Win2k client bug. JRA.
- */
- if (!was_8_3 && check_mangled_names) {
- if (!name_to_8_3(fname,mangled_name,True,
- conn->params)) {
- /* Error - mangle failed ! */
- memset(mangled_name,'\0',12);
- }
- mangled_name[12] = 0;
- len = srvstr_push(base_data, flags2,
- p+2, mangled_name, 24,
- STR_UPPER|STR_UNICODE);
- SSVAL(p, 0, len);
- if (len < 24) {
- memset(p + 2 + len,'\0',24 - len);
- }
- SSVAL(p, 0, len);
- } else {
- memset(p,'\0',26);
- }
- p += 26;
- SSVAL(p,0,0); p += 2; /* Reserved ? */
- SIVAL(p,0,sbuf.st_ex_ino); p += 4; /* FileIndexLow */
- SIVAL(p,0,sbuf.st_ex_dev); p += 4; /* FileIndexHigh */
- len = srvstr_push(base_data, flags2, p,
- fname, PTR_DIFF(end_data, p),
- STR_TERMINATE_ASCII);
- SIVAL(q,0,len);
- p += len;
- SIVAL(p,0,0); /* Ensure any padding is null. */
- len = PTR_DIFF(p, pdata);
- len = (len + 3) & ~3;
- SIVAL(pdata,0,len);
- p = pdata + len;
- break;
-
- /* CIFS UNIX Extension. */
-
- case SMB_FIND_FILE_UNIX:
- case SMB_FIND_FILE_UNIX_INFO2:
- p+= 4;
- SIVAL(p,0,reskey); p+= 4; /* Used for continuing search. */
-
- /* Begin of SMB_QUERY_FILE_UNIX_BASIC */
-
- if (info_level == SMB_FIND_FILE_UNIX) {
- DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_FILE_UNIX\n"));
- p = store_file_unix_basic(conn, p,
- NULL, &sbuf);
- len = srvstr_push(base_data, flags2, p,
- fname, PTR_DIFF(end_data, p),
- STR_TERMINATE);
- } else {
- DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_FILE_UNIX_INFO2\n"));
- p = store_file_unix_basic_info2(conn, p,
- NULL, &sbuf);
- nameptr = p;
- p += 4;
- len = srvstr_push(base_data, flags2, p, fname,
- PTR_DIFF(end_data, p), 0);
- SIVAL(nameptr, 0, len);
- }
-
- p += len;
- SIVAL(p,0,0); /* Ensure any padding is null. */
+static bool get_lanman2_dir_entry(TALLOC_CTX *ctx,
+ connection_struct *conn,
+ struct dptr_struct *dirptr,
+ uint16 flags2,
+ const char *path_mask,
+ uint32 dirtype,
+ int info_level,
+ int requires_resume_key,
+ bool dont_descend,
+ bool ask_sharemode,
+ char **ppdata,
+ char *base_data,
+ char *end_data,
+ int space_remaining,
+ bool *out_of_space,
+ bool *got_exact_match,
+ int *_last_entry_off,
+ struct ea_list *name_list)
+{
+ const char *p;
+ const char *mask = NULL;
+ long prev_dirpos = 0;
+ uint32_t mode = 0;
+ char *fname = NULL;
+ struct smb_filename *smb_fname = NULL;
+ struct smbd_dirptr_lanman2_state state;
+ bool ok;
+ uint64_t last_entry_off = 0;
- len = PTR_DIFF(p, pdata);
- len = (len + 3) & ~3;
- SIVAL(pdata,0,len); /* Offset from this structure to the beginning of the next one */
- p = pdata + len;
- /* End of SMB_QUERY_FILE_UNIX_BASIC */
+ ZERO_STRUCT(state);
+ state.conn = conn;
+ state.info_level = info_level;
+ state.check_mangled_names = lp_manglednames(conn->params);
+ state.has_wild = dptr_has_wild(dirptr);
+ state.got_exact_match = false;
- break;
+ *out_of_space = false;
+ *got_exact_match = false;
- default:
- TALLOC_FREE(fname);
- return(False);
+ p = strrchr_m(path_mask,'/');
+ if(p != NULL) {
+ if(p[1] == '\0') {
+ mask = "*.*";
+ } else {
+ mask = p+1;
+ }
+ } else {
+ mask = path_mask;
}
+ ok = smbd_dirptr_get_entry(ctx,
+ dirptr,
+ mask,
+ dirtype,
+ dont_descend,
+ ask_sharemode,
+ smbd_dirptr_lanman2_match_fn,
+ smbd_dirptr_lanman2_mode_fn,
+ &state,
+ &fname,
+ &smb_fname,
+ &mode,
+ &prev_dirpos);
+ if (!ok) {
+ return false;
+ }
+
+ *got_exact_match = state.got_exact_match;
+
+ ok = smbd_marshall_dir_entry(ctx,
+ conn,
+ flags2,
+ info_level,
+ name_list,
+ state.check_mangled_names,
+ requires_resume_key,
+ mode,
+ fname,
+ smb_fname,
+ space_remaining,
+ base_data,
+ ppdata,
+ end_data,
+ out_of_space,
+ &last_entry_off);
TALLOC_FREE(fname);
- if (PTR_DIFF(p,pdata) > space_remaining) {
- /* Move the dirptr back to prev_dirpos */
- dptr_SeekDir(conn->dirptr, prev_dirpos);
- *out_of_space = True;
- DEBUG(9,("get_lanman2_dir_entry: out of space\n"));
- return False; /* Not finished - just out of space */
+ TALLOC_FREE(smb_fname);
+ if (*out_of_space) {
+ dptr_SeekDir(dirptr, prev_dirpos);
+ return false;
+ }
+ if (!ok) {
+ return false;
}
- /* Setup the last entry pointer, as an offset from base_data */
- *last_entry_off = PTR_DIFF(last_entry_ptr,base_data);
- /* Advance the data pointer to the next slot */
- *ppdata = p;
-
- return(found);
+ *_last_entry_off = last_entry_off;
+ return true;
}
/****************************************************************************
NTSTATUS ntstatus = NT_STATUS_OK;
bool ask_sharemode = lp_parm_bool(SNUM(conn), "smbd", "search ask sharemode", true);
TALLOC_CTX *ctx = talloc_tos();
+ struct dptr_struct *dirptr = NULL;
+ struct smbd_server_connection *sconn = smbd_server_conn;
if (total_params < 13) {
reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
- return;
+ goto out;
}
dirtype = SVAL(params,0);
ask_sharemode = false;
if (!lp_unix_extensions()) {
reply_nterror(req, NT_STATUS_INVALID_LEVEL);
- return;
+ goto out;
}
break;
default:
reply_nterror(req, NT_STATUS_INVALID_LEVEL);
- return;
+ goto out;
}
srvstr_get_path_wcard(ctx, params, req->flags2, &directory,
STR_TERMINATE, &ntstatus, &mask_contains_wcard);
if (!NT_STATUS_IS_OK(ntstatus)) {
reply_nterror(req, ntstatus);
- return;
+ goto out;
}
- ntstatus = resolve_dfspath_wcard(ctx, conn,
- req->flags2 & FLAGS2_DFS_PATHNAMES,
- directory,
- &directory,
- &mask_contains_wcard);
+ ntstatus = filename_convert(ctx, conn,
+ req->flags2 & FLAGS2_DFS_PATHNAMES,
+ directory,
+ (UCF_SAVE_LCOMP |
+ UCF_ALWAYS_ALLOW_WCARD_LCOMP),
+ &mask_contains_wcard,
+ &smb_dname);
if (!NT_STATUS_IS_OK(ntstatus)) {
if (NT_STATUS_EQUAL(ntstatus,NT_STATUS_PATH_NOT_COVERED)) {
reply_botherror(req, NT_STATUS_PATH_NOT_COVERED,
ERRSRV, ERRbadpath);
- return;
+ goto out;
}
reply_nterror(req, ntstatus);
- return;
- }
-
- ntstatus = unix_convert(ctx, conn, directory, &smb_dname,
- (UCF_SAVE_LCOMP | UCF_ALLOW_WCARD_LCOMP));
- if (!NT_STATUS_IS_OK(ntstatus)) {
- reply_nterror(req, ntstatus);
- return;
+ goto out;
}
mask = smb_dname->original_lcomp;
- ntstatus = get_full_smb_filename(ctx, smb_dname, &directory);
- TALLOC_FREE(smb_dname);
- if (!NT_STATUS_IS_OK(ntstatus)) {
- reply_nterror(req, ntstatus);
- return;
- }
-
- ntstatus = check_name(conn, directory);
- if (!NT_STATUS_IS_OK(ntstatus)) {
- reply_nterror(req, ntstatus);
- return;
- }
+ directory = smb_dname->base_name;
p = strrchr_m(directory,'/');
if(p == NULL) {
mask = talloc_strdup(ctx,"*");
if (!mask) {
reply_nterror(req, NT_STATUS_NO_MEMORY);
- return;
+ goto out;
}
mask_contains_wcard = True;
}
directory = talloc_strdup(talloc_tos(), "./");
if (!directory) {
reply_nterror(req, NT_STATUS_NO_MEMORY);
- return;
+ goto out;
}
} else {
*p = 0;
if (total_data < 4) {
reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
- return;
+ goto out;
}
ea_size = IVAL(pdata,0);
DEBUG(4,("call_trans2findfirst: Rejecting EA request with incorrect \
total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pdata,0) ));
reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
- return;
+ goto out;
}
if (!lp_ea_support(SNUM(conn))) {
reply_doserror(req, ERRDOS, ERReasnotsupported);
- return;
+ goto out;
}
/* Pull out the list of names. */
ea_list = read_ea_name_list(ctx, pdata + 4, ea_size - 4);
if (!ea_list) {
reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
- return;
+ goto out;
}
}
*ppdata, max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
if(*ppdata == NULL ) {
reply_nterror(req, NT_STATUS_NO_MEMORY);
- return;
+ goto out;
}
pdata = *ppdata;
data_end = pdata + max_data_bytes + DIR_ENTRY_SAFETY_MARGIN - 1;
*pparams = (char *)SMB_REALLOC(*pparams, 10);
if (*pparams == NULL) {
reply_nterror(req, NT_STATUS_NO_MEMORY);
- return;
+ goto out;
}
params = *pparams;
mask,
mask_contains_wcard,
dirtype,
- &conn->dirptr);
+ &dirptr);
if (!NT_STATUS_IS_OK(ntstatus)) {
reply_nterror(req, ntstatus);
- return;
+ goto out;
}
- dptr_num = dptr_dnum(conn->dirptr);
+ dptr_num = dptr_dnum(dirptr);
DEBUG(4,("dptr_num is %d, wcard = %s, attr = %d\n", dptr_num, mask, dirtype));
/* Initialize per TRANS2_FIND_FIRST operation data */
- dptr_init_search_op(conn->dirptr);
+ dptr_init_search_op(dirptr);
/* We don't need to check for VOL here as this is returned by
a different TRANS2 call. */
- DEBUG(8,("dirpath=<%s> dontdescend=<%s>\n", conn->dirpath,lp_dontdescend(SNUM(conn))));
- if (in_list(conn->dirpath,lp_dontdescend(SNUM(conn)),conn->case_sensitive))
+ DEBUG(8,("dirpath=<%s> dontdescend=<%s>\n",
+ directory,lp_dontdescend(SNUM(conn))));
+ if (in_list(directory,lp_dontdescend(SNUM(conn)),conn->case_sensitive))
dont_descend = True;
p = pdata;
} else {
finished = !get_lanman2_dir_entry(ctx,
conn,
+ dirptr,
req->flags2,
mask,dirtype,info_level,
requires_resume_key,dont_descend,
/* Check if we can close the dirptr */
if(close_after_first || (finished && close_if_end)) {
DEBUG(5,("call_trans2findfirst - (2) closing dptr_num %d\n", dptr_num));
- dptr_close(&dptr_num);
+ dptr_close(sconn, &dptr_num);
}
/*
*/
if(numentries == 0) {
- dptr_close(&dptr_num);
+ dptr_close(sconn, &dptr_num);
if (Protocol < PROTOCOL_NT1) {
reply_doserror(req, ERRDOS, ERRnofiles);
- return;
+ goto out;
} else {
reply_botherror(req, NT_STATUS_NO_SUCH_FILE,
ERRDOS, ERRbadfile);
- return;
+ goto out;
}
}
send_trans2_replies(conn, req, params, 10, pdata, PTR_DIFF(p,pdata),
max_data_bytes);
- if ((! *directory) && dptr_path(dptr_num)) {
- directory = talloc_strdup(talloc_tos(),dptr_path(dptr_num));
+ if ((! *directory) && dptr_path(sconn, dptr_num)) {
+ directory = talloc_strdup(talloc_tos(),dptr_path(sconn, dptr_num));
if (!directory) {
reply_nterror(req, NT_STATUS_NO_MEMORY);
}
char mangled_name[13];
name_to_8_3(mask, mangled_name, True, conn->params);
}
-
+ out:
+ TALLOC_FREE(smb_dname);
return;
}
NTSTATUS ntstatus = NT_STATUS_OK;
bool ask_sharemode = lp_parm_bool(SNUM(conn), "smbd", "search ask sharemode", true);
TALLOC_CTX *ctx = talloc_tos();
+ struct dptr_struct *dirptr;
+ struct smbd_server_connection *sconn = smbd_server_conn;
if (total_params < 13) {
reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
params = *pparams;
/* Check that the dptr is valid */
- if(!(conn->dirptr = dptr_fetch_lanman2(dptr_num))) {
+ if(!(dirptr = dptr_fetch_lanman2(sconn, dptr_num))) {
reply_doserror(req, ERRDOS, ERRnofiles);
return;
}
- string_set(&conn->dirpath,dptr_path(dptr_num));
+ directory = dptr_path(sconn, dptr_num);
/* Get the wildcard mask from the dptr */
- if((p = dptr_wcard(dptr_num))== NULL) {
+ if((p = dptr_wcard(sconn, dptr_num))== NULL) {
DEBUG(2,("dptr_num %d has no wildcard\n", dptr_num));
reply_doserror(req, ERRDOS, ERRnofiles);
return;
}
mask = p;
- directory = conn->dirpath;
/* Get the attr mask from the dptr */
- dirtype = dptr_attr(dptr_num);
+ dirtype = dptr_attr(sconn, dptr_num);
DEBUG(3,("dptr_num is %d, mask = %s, attr = %x, dirptr=(0x%lX,%ld)\n",
dptr_num, mask, dirtype,
- (long)conn->dirptr,
- dptr_TellDir(conn->dirptr)));
+ (long)dirptr,
+ dptr_TellDir(dirptr)));
/* Initialize per TRANS2_FIND_NEXT operation data */
- dptr_init_search_op(conn->dirptr);
+ dptr_init_search_op(dirptr);
/* We don't need to check for VOL here as this is returned by
a different TRANS2 call. */
- DEBUG(8,("dirpath=<%s> dontdescend=<%s>\n",conn->dirpath,lp_dontdescend(SNUM(conn))));
- if (in_list(conn->dirpath,lp_dontdescend(SNUM(conn)),conn->case_sensitive))
+ DEBUG(8,("dirpath=<%s> dontdescend=<%s>\n",
+ directory,lp_dontdescend(SNUM(conn))));
+ if (in_list(directory,lp_dontdescend(SNUM(conn)),conn->case_sensitive))
dont_descend = True;
p = pdata;
* should already be at the correct place.
*/
- finished = !dptr_SearchDir(conn->dirptr, resume_name, ¤t_pos, &st);
+ finished = !dptr_SearchDir(dirptr, resume_name, ¤t_pos, &st);
} /* end if resume_name && !continue_bit */
for (i=0;(i<(int)maxentries) && !finished && !out_of_space ;i++) {
} else {
finished = !get_lanman2_dir_entry(ctx,
conn,
+ dirptr,
req->flags2,
mask,dirtype,info_level,
requires_resume_key,dont_descend,
/* Check if we can close the dirptr */
if(close_after_request || (finished && close_if_end)) {
DEBUG(5,("call_trans2findnext: closing dptr_num = %d\n", dptr_num));
- dptr_close(&dptr_num); /* This frees up the saved mask */
+ dptr_close(sconn, &dptr_num); /* This frees up the saved mask */
}
/* Set up the return parameter block */
"%s", samba_version_string());
}
-/****************************************************************************
- Reply to a TRANS2_QFSINFO (query filesystem info).
-****************************************************************************/
-
-static void call_trans2qfsinfo(connection_struct *conn,
- struct smb_request *req,
- char **pparams, int total_params,
- char **ppdata, int total_data,
- unsigned int max_data_bytes)
+NTSTATUS smbd_do_qfsinfo(connection_struct *conn,
+ TALLOC_CTX *mem_ctx,
+ uint16_t info_level,
+ uint16_t flags2,
+ unsigned int max_data_bytes,
+ char **ppdata,
+ int *ret_data_len)
{
char *pdata, *end_data;
- char *params = *pparams;
- uint16 info_level;
- int data_len, len;
- SMB_STRUCT_STAT st;
+ int data_len = 0, len;
const char *vname = volume_label(SNUM(conn));
int snum = SNUM(conn);
char *fstype = lp_fstype(SNUM(conn));
uint32 additional_flags = 0;
-
- if (total_params < 2) {
- reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
- return;
- }
-
- info_level = SVAL(params,0);
+ struct smb_filename *smb_fname_dot = NULL;
+ SMB_STRUCT_STAT st;
+ NTSTATUS status;
if (IS_IPC(conn)) {
if (info_level != SMB_QUERY_CIFS_UNIX_INFO) {
- DEBUG(0,("call_trans2qfsinfo: not an allowed "
+ DEBUG(0,("smbd_do_qfsinfo: not an allowed "
"info level (0x%x) on IPC$.\n",
(unsigned int)info_level));
- reply_nterror(req, NT_STATUS_ACCESS_DENIED);
- return;
+ return NT_STATUS_ACCESS_DENIED;
}
}
- if (ENCRYPTION_REQUIRED(conn) && !req->encrypted) {
- if (info_level != SMB_QUERY_CIFS_UNIX_INFO) {
- DEBUG(0,("call_trans2qfsinfo: encryption required "
- "and info level 0x%x sent.\n",
- (unsigned int)info_level));
- exit_server_cleanly("encryption required "
- "on connection");
- return;
- }
- }
+ DEBUG(3,("smbd_do_qfsinfo: level = %d\n", info_level));
- DEBUG(3,("call_trans2qfsinfo: level = %d\n", info_level));
+ status = create_synthetic_smb_fname(talloc_tos(), ".", NULL, NULL,
+ &smb_fname_dot);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
- if(vfs_stat_smb_fname(conn,".",&st)!=0) {
- DEBUG(2,("call_trans2qfsinfo: stat of . failed (%s)\n", strerror(errno)));
- reply_doserror(req, ERRSRV, ERRinvdevice);
- return;
+ if(SMB_VFS_STAT(conn, smb_fname_dot) != 0) {
+ DEBUG(2,("stat of . failed (%s)\n", strerror(errno)));
+ TALLOC_FREE(smb_fname_dot);
+ return map_nt_error_from_unix(errno);
}
+ st = smb_fname_dot->st;
+ TALLOC_FREE(smb_fname_dot);
+
*ppdata = (char *)SMB_REALLOC(
*ppdata, max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
- if (*ppdata == NULL ) {
- reply_nterror(req, NT_STATUS_NO_MEMORY);
- return;
+ if (*ppdata == NULL) {
+ return NT_STATUS_NO_MEMORY;
}
pdata = *ppdata;
uint64_t dfree,dsize,bsize,block_size,sectors_per_unit,bytes_per_sector;
data_len = 18;
if (get_dfree_info(conn,".",False,&bsize,&dfree,&dsize) == (uint64_t)-1) {
- reply_nterror(req, map_nt_error_from_unix(errno));
- return;
+ return map_nt_error_from_unix(errno);
}
block_size = lp_block_size(snum);
bytes_per_sector = 512;
sectors_per_unit = bsize/bytes_per_sector;
- DEBUG(5,("call_trans2qfsinfo : SMB_INFO_ALLOCATION id=%x, bsize=%u, cSectorUnit=%u, \
+ DEBUG(5,("smbd_do_qfsinfo : SMB_INFO_ALLOCATION id=%x, bsize=%u, cSectorUnit=%u, \
cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", (unsigned int)st.st_ex_dev, (unsigned int)bsize, (unsigned int)sectors_per_unit,
(unsigned int)bytes_per_sector, (unsigned int)dsize, (unsigned int)dfree));
* the pushed string. The change here was adding the STR_TERMINATE. JRA.
*/
len = srvstr_push(
- pdata, req->flags2,
+ pdata, flags2,
pdata+l2_vol_szVolLabel, vname,
PTR_DIFF(end_data, pdata+l2_vol_szVolLabel),
STR_NOALIGN|STR_TERMINATE);
SCVAL(pdata,l2_vol_cch,len);
data_len = l2_vol_szVolLabel + len;
- DEBUG(5,("call_trans2qfsinfo : time = %x, namelen = %d, name = %s\n",
+ DEBUG(5,("smbd_do_qfsinfo : time = %x, namelen = %d, name = %s\n",
(unsigned)convert_timespec_to_time_t(st.st_ex_ctime),
len, vname));
break;
SIVAL(pdata,4,255); /* Max filename component length */
/* NOTE! the fstype must *not* be null terminated or win98 won't recognise it
and will think we can't do long filenames */
- len = srvstr_push(pdata, req->flags2, pdata+12, fstype,
+ len = srvstr_push(pdata, flags2, pdata+12, fstype,
PTR_DIFF(end_data, pdata+12),
STR_UNICODE);
SIVAL(pdata,8,len);
case SMB_QUERY_FS_LABEL_INFO:
case SMB_FS_LABEL_INFORMATION:
- len = srvstr_push(pdata, req->flags2, pdata+4, vname,
+ len = srvstr_push(pdata, flags2, pdata+4, vname,
PTR_DIFF(end_data, pdata+4), 0);
data_len = 4 + len;
SIVAL(pdata,0,len);
(str_checksum(get_local_machine_name())<<16));
/* Max label len is 32 characters. */
- len = srvstr_push(pdata, req->flags2, pdata+18, vname,
+ len = srvstr_push(pdata, flags2, pdata+18, vname,
PTR_DIFF(end_data, pdata+18),
STR_UNICODE);
SIVAL(pdata,12,len);
data_len = 18+len;
- DEBUG(5,("call_trans2qfsinfo : SMB_QUERY_FS_VOLUME_INFO namelen = %d, vol=%s serv=%s\n",
+ DEBUG(5,("smbd_do_qfsinfo : SMB_QUERY_FS_VOLUME_INFO namelen = %d, vol=%s serv=%s\n",
(int)strlen(vname),vname, lp_servicename(snum)));
break;
uint64_t dfree,dsize,bsize,block_size,sectors_per_unit,bytes_per_sector;
data_len = 24;
if (get_dfree_info(conn,".",False,&bsize,&dfree,&dsize) == (uint64_t)-1) {
- reply_nterror(req, map_nt_error_from_unix(errno));
- return;
+ return map_nt_error_from_unix(errno);
}
block_size = lp_block_size(snum);
if (bsize < block_size) {
}
bytes_per_sector = 512;
sectors_per_unit = bsize/bytes_per_sector;
- DEBUG(5,("call_trans2qfsinfo : SMB_QUERY_FS_SIZE_INFO bsize=%u, cSectorUnit=%u, \
+ DEBUG(5,("smbd_do_qfsinfo : SMB_QUERY_FS_SIZE_INFO bsize=%u, cSectorUnit=%u, \
cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", (unsigned int)bsize, (unsigned int)sectors_per_unit,
(unsigned int)bytes_per_sector, (unsigned int)dsize, (unsigned int)dfree));
SBIG_UINT(pdata,0,dsize);
uint64_t dfree,dsize,bsize,block_size,sectors_per_unit,bytes_per_sector;
data_len = 32;
if (get_dfree_info(conn,".",False,&bsize,&dfree,&dsize) == (uint64_t)-1) {
- reply_nterror(req, map_nt_error_from_unix(errno));
- return;
+ return map_nt_error_from_unix(errno);
}
block_size = lp_block_size(snum);
if (bsize < block_size) {
}
bytes_per_sector = 512;
sectors_per_unit = bsize/bytes_per_sector;
- DEBUG(5,("call_trans2qfsinfo : SMB_QUERY_FS_FULL_SIZE_INFO bsize=%u, cSectorUnit=%u, \
+ DEBUG(5,("smbd_do_qfsinfo : SMB_QUERY_FS_FULL_SIZE_INFO bsize=%u, cSectorUnit=%u, \
cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", (unsigned int)bsize, (unsigned int)sectors_per_unit,
(unsigned int)bytes_per_sector, (unsigned int)dsize, (unsigned int)dfree));
SBIG_UINT(pdata,0,dsize); /* Total Allocation units. */
fsp.fnum = -1;
/* access check */
- if (conn->server_info->utok.uid != 0) {
+ if (conn->server_info->utok.uid != sec_initial_uid()) {
DEBUG(0,("set_user_quota: access_denied "
"service [%s] user [%s]\n",
lp_servicename(SNUM(conn)),
conn->server_info->unix_name));
- reply_doserror(req, ERRDOS, ERRnoaccess);
- return;
+ return NT_STATUS_ACCESS_DENIED;
}
if (vfs_get_ntquota(&fsp, SMB_USER_FS_QUOTA_TYPE, NULL, "as)!=0) {
DEBUG(0,("vfs_get_ntquota() failed for service [%s]\n",lp_servicename(SNUM(conn))));
- reply_doserror(req, ERRSRV, ERRerror);
- return;
+ return map_nt_error_from_unix(errno);
}
data_len = 48;
- DEBUG(10,("SMB_FS_QUOTA_INFORMATION: for service [%s]\n",lp_servicename(SNUM(conn))));
+ DEBUG(10,("SMB_FS_QUOTA_INFORMATION: for service [%s]\n",
+ lp_servicename(SNUM(conn))));
/* Unknown1 24 NULL bytes*/
SBIG_UINT(pdata,0,(uint64_t)0);
int encrypt_caps = 0;
if (!lp_unix_extensions()) {
- reply_nterror(req, NT_STATUS_INVALID_LEVEL);
- return;
+ return NT_STATUS_INVALID_LEVEL;
}
switch (conn->encrypt_level) {
vfs_statvfs_struct svfs;
if (!lp_unix_extensions()) {
- reply_nterror(req, NT_STATUS_INVALID_LEVEL);
- return;
+ return NT_STATUS_INVALID_LEVEL;
}
rc = SMB_VFS_STATVFS(conn, ".", &svfs);
SBIG_UINT(pdata,32,svfs.TotalFileNodes);
SBIG_UINT(pdata,40,svfs.FreeFileNodes);
SBIG_UINT(pdata,48,svfs.FsIdentifier);
- DEBUG(5,("call_trans2qfsinfo : SMB_QUERY_POSIX_FS_INFO succsessful\n"));
+ DEBUG(5,("smbd_do_qfsinfo : SMB_QUERY_POSIX_FS_INFO succsessful\n"));
#ifdef EOPNOTSUPP
} else if (rc == EOPNOTSUPP) {
- reply_nterror(req, NT_STATUS_INVALID_LEVEL);
- return;
+ return NT_STATUS_INVALID_LEVEL;
#endif /* EOPNOTSUPP */
} else {
DEBUG(0,("vfs_statvfs() failed for service [%s]\n",lp_servicename(SNUM(conn))));
- reply_doserror(req, ERRSRV, ERRerror);
- return;
+ return NT_STATUS_DOS(ERRSRV, ERRerror);
}
break;
}
int i;
if (!lp_unix_extensions()) {
- reply_nterror(req, NT_STATUS_INVALID_LEVEL);
- return;
+ return NT_STATUS_INVALID_LEVEL;
}
if (max_data_bytes < 40) {
- reply_nterror(req, NT_STATUS_BUFFER_TOO_SMALL);
- return;
+ return NT_STATUS_BUFFER_TOO_SMALL;
}
/* We ARE guest if global_sid_Builtin_Guests is
}
/* drop through */
default:
- reply_nterror(req, NT_STATUS_INVALID_LEVEL);
- return;
+ return NT_STATUS_INVALID_LEVEL;
}
-
- send_trans2_replies(conn, req, params, 0, pdata, data_len,
- max_data_bytes);
-
- DEBUG( 4, ( "%s info_level = %d\n",
- smb_fn_name(req->cmd), info_level) );
-
- return;
+ *ret_data_len = data_len;
+ return NT_STATUS_OK;
}
/****************************************************************************
- Reply to a TRANS2_SETFSINFO (set filesystem info).
+ Reply to a TRANS2_QFSINFO (query filesystem info).
****************************************************************************/
-static void call_trans2setfsinfo(connection_struct *conn,
- struct smb_request *req,
- char **pparams, int total_params,
- char **ppdata, int total_data,
- unsigned int max_data_bytes)
-{
+static void call_trans2qfsinfo(connection_struct *conn,
+ struct smb_request *req,
+ char **pparams, int total_params,
+ char **ppdata, int total_data,
+ unsigned int max_data_bytes)
+{
+ char *params = *pparams;
+ uint16_t info_level;
+ int data_len = 0;
+ NTSTATUS status;
+
+ if (total_params < 2) {
+ reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
+ return;
+ }
+
+ info_level = SVAL(params,0);
+
+ if (ENCRYPTION_REQUIRED(conn) && !req->encrypted) {
+ if (info_level != SMB_QUERY_CIFS_UNIX_INFO) {
+ DEBUG(0,("call_trans2qfsinfo: encryption required "
+ "and info level 0x%x sent.\n",
+ (unsigned int)info_level));
+ exit_server_cleanly("encryption required "
+ "on connection");
+ return;
+ }
+ }
+
+ DEBUG(3,("call_trans2qfsinfo: level = %d\n", info_level));
+
+ status = smbd_do_qfsinfo(conn, req,
+ info_level,
+ req->flags2,
+ max_data_bytes,
+ ppdata, &data_len);
+ if (!NT_STATUS_IS_OK(status)) {
+ reply_nterror(req, status);
+ return;
+ }
+
+ send_trans2_replies(conn, req, params, 0, *ppdata, data_len,
+ max_data_bytes);
+
+ DEBUG( 4, ( "%s info_level = %d\n",
+ smb_fn_name(req->cmd), info_level) );
+
+ return;
+}
+
+/****************************************************************************
+ Reply to a TRANS2_SETFSINFO (set filesystem info).
+****************************************************************************/
+
+static void call_trans2setfsinfo(connection_struct *conn,
+ struct smb_request *req,
+ char **pparams, int total_params,
+ char **ppdata, int total_data,
+ unsigned int max_data_bytes)
+{
char *pdata = *ppdata;
char *params = *pparams;
uint16 info_level;
ZERO_STRUCT(quotas);
/* access check */
- if ((conn->server_info->utok.uid != 0)
+ if ((conn->server_info->utok.uid != sec_initial_uid())
||!CAN_WRITE(conn)) {
DEBUG(0,("set_user_quota: access_denied service [%s] user [%s]\n",
lp_servicename(SNUM(conn)),
conn->server_info->unix_name));
- reply_doserror(req, ERRSRV, ERRaccess);
+ reply_nterror(req, NT_STATUS_ACCESS_DENIED);
return;
}
/* now set the quotas */
if (vfs_set_ntquota(fsp, SMB_USER_FS_QUOTA_TYPE, NULL, "as)!=0) {
DEBUG(0,("vfs_set_ntquota() failed for service [%s]\n",lp_servicename(SNUM(conn))));
- reply_doserror(req, ERRSRV, ERRerror);
+ reply_nterror(req, map_nt_error_from_unix(errno));
return;
}
return;
}
-static NTSTATUS smbd_do_qfilepathinfo(connection_struct *conn,
- TALLOC_CTX *mem_ctx,
- uint16_t info_level,
- files_struct *fsp,
- const struct smb_filename *smb_fname,
- bool delete_pending,
- struct timespec write_time_ts,
- bool ms_dfs_link,
- struct ea_list *ea_list,
- int lock_data_count,
- char *lock_data,
- uint16_t flags2,
- unsigned int max_data_bytes,
- char **ppdata,
- unsigned int *pdata_size)
+NTSTATUS smbd_do_qfilepathinfo(connection_struct *conn,
+ TALLOC_CTX *mem_ctx,
+ uint16_t info_level,
+ files_struct *fsp,
+ const struct smb_filename *smb_fname,
+ bool delete_pending,
+ struct timespec write_time_ts,
+ bool ms_dfs_link,
+ struct ea_list *ea_list,
+ int lock_data_count,
+ char *lock_data,
+ uint16_t flags2,
+ unsigned int max_data_bytes,
+ char **ppdata,
+ unsigned int *pdata_size)
{
char *pdata = *ppdata;
char *dstart, *dend;
time_t create_time, mtime, atime;
SMB_STRUCT_STAT sbuf;
char *p;
- char *fname;
char *base_name;
char *dos_fname;
int mode;
return NT_STATUS_INVALID_LEVEL;
}
- status = get_full_smb_filename(mem_ctx, smb_fname, &fname);
- if (!NT_STATUS_IS_OK(status)) {
- return status;
- }
-
DEBUG(5,("smbd_do_qfilepathinfo: %s (fnum = %d) level=%d max_data=%u\n",
- fname, fsp ? fsp->fnum : -1, info_level, max_data_bytes));
+ smb_fname_str_dbg(smb_fname), fsp ? fsp->fnum : -1,
+ info_level, max_data_bytes));
if (ms_dfs_link) {
mode = dos_mode_msdfs(conn, smb_fname);
} else {
dos_fname = talloc_asprintf(mem_ctx,
"\\%s",
- fname);
+ smb_fname->base_name);
if (!dos_fname) {
return NT_STATUS_NO_MEMORY;
}
+ if (is_ntfs_stream_smb_fname(smb_fname)) {
+ dos_fname = talloc_asprintf(dos_fname, "%s",
+ smb_fname->stream_name);
+ if (!dos_fname) {
+ return NT_STATUS_NO_MEMORY;
+ }
+ }
+
string_replace(dos_fname, '/', '\\');
}
file_size = get_file_size_stat(&sbuf);
}
- if (fsp && fsp->fh) {
+ if (fsp) {
pos = fsp->fh->position_information;
}
I think this causes us to fail the IFSKIT
BasicFileInformationTest. -tpot */
file_index = ((sbuf.st_ex_ino) & UINT32_MAX); /* FileIndexLow */
- file_index |= ((sbuf.st_ex_dev) & UINT32_MAX) << 32; /* FileIndexHigh */
+ file_index |= ((uint64_t)((sbuf.st_ex_dev) & UINT32_MAX)) << 32; /* FileIndexHigh */
switch (info_level) {
case SMB_INFO_STANDARD:
case SMB_INFO_QUERY_EA_SIZE:
{
- unsigned int ea_size = estimate_ea_size(conn, fsp, fname);
+ unsigned int ea_size =
+ estimate_ea_size(conn, fsp,
+ smb_fname->base_name);
DEBUG(10,("smbd_do_qfilepathinfo: SMB_INFO_QUERY_EA_SIZE\n"));
data_size = 26;
srv_put_dos_date2(pdata,0,create_time);
DEBUG(10,("smbd_do_qfilepathinfo: SMB_INFO_QUERY_EAS_FROM_LIST\n"));
- ea_file_list = get_ea_list_from_file(mem_ctx, conn, fsp, fname, &total_ea_len);
+ ea_file_list =
+ get_ea_list_from_file(mem_ctx, conn, fsp,
+ smb_fname->base_name,
+ &total_ea_len);
ea_list = ea_list_union(ea_list, ea_file_list, &total_ea_len);
if (!ea_list || (total_ea_len > data_size)) {
DEBUG(10,("smbd_do_qfilepathinfo: SMB_INFO_QUERY_ALL_EAS\n"));
- ea_list = get_ea_list_from_file(mem_ctx, conn, fsp, fname, &total_ea_len);
+ ea_list = get_ea_list_from_file(mem_ctx, conn, fsp,
+ smb_fname->base_name,
+ &total_ea_len);
if (!ea_list || (total_ea_len > data_size)) {
data_size = 4;
SIVAL(pdata,0,4); /* EA List Length must be set to 4 if no EA's. */
break;
}
+ case 0xFF0F:/*SMB2_INFO_QUERY_ALL_EAS*/
+ {
+ /* We have data_size bytes to put EA's into. */
+ size_t total_ea_len = 0;
+ struct ea_list *ea_file_list = NULL;
+
+ DEBUG(10,("smbd_do_qfilepathinfo: SMB2_INFO_QUERY_ALL_EAS\n"));
+
+ /*TODO: add filtering and index handling */
+
+ ea_file_list =
+ get_ea_list_from_file(mem_ctx, conn, fsp,
+ smb_fname->base_name,
+ &total_ea_len);
+ if (!ea_file_list) {
+ return NT_STATUS_NO_EAS_ON_FILE;
+ }
+
+ status = fill_ea_chained_buffer(mem_ctx,
+ pdata,
+ data_size,
+ &data_size,
+ conn, ea_file_list);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
+ break;
+ }
+
case SMB_FILE_BASIC_INFORMATION:
case SMB_QUERY_FILE_BASIC_INFO:
case SMB_FILE_EA_INFORMATION:
case SMB_QUERY_FILE_EA_INFO:
{
- unsigned int ea_size = estimate_ea_size(conn, fsp, fname);
+ unsigned int ea_size =
+ estimate_ea_size(conn, fsp, smb_fname->base_name);
DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_EA_INFORMATION\n"));
data_size = 4;
SIVAL(pdata,0,ea_size);
case SMB_FILE_ALL_INFORMATION:
{
int len;
- unsigned int ea_size = estimate_ea_size(conn, fsp, fname);
+ unsigned int ea_size =
+ estimate_ea_size(conn, fsp, smb_fname->base_name);
DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_ALL_INFORMATION\n"));
put_long_date_timespec(pdata,create_time_ts);
put_long_date_timespec(pdata+8,atime_ts);
data_size = PTR_DIFF(pdata,(*ppdata));
break;
}
+
+ case 0xFF12:/*SMB2_FILE_ALL_INFORMATION*/
+ {
+ int len;
+ unsigned int ea_size =
+ estimate_ea_size(conn, fsp, smb_fname->base_name);
+ DEBUG(10,("smbd_do_qfilepathinfo: SMB2_FILE_ALL_INFORMATION\n"));
+ put_long_date_timespec(pdata+0x00,create_time_ts);
+ put_long_date_timespec(pdata+0x08,atime_ts);
+ put_long_date_timespec(pdata+0x10,mtime_ts); /* write time */
+ put_long_date_timespec(pdata+0x18,mtime_ts); /* change time */
+ SIVAL(pdata, 0x20, mode);
+ SIVAL(pdata, 0x24, 0); /* padding. */
+ SBVAL(pdata, 0x28, allocation_size);
+ SBVAL(pdata, 0x30, file_size);
+ SIVAL(pdata, 0x38, nlink);
+ SCVAL(pdata, 0x3C, delete_pending);
+ SCVAL(pdata, 0x3D, (mode&aDIR)?1:0);
+ SSVAL(pdata, 0x3E, 0); /* padding */
+ SBVAL(pdata, 0x40, file_index);
+ SIVAL(pdata, 0x48, ea_size);
+ SIVAL(pdata, 0x4C, access_mask);
+ SBVAL(pdata, 0x50, pos);
+ SIVAL(pdata, 0x58, mode); /*TODO: mode != mode fix this!!! */
+ SIVAL(pdata, 0x5C, 0); /* No alignment needed. */
+
+ pdata += 0x60;
+
+ len = srvstr_push(dstart, flags2,
+ pdata+4, dos_fname,
+ PTR_DIFF(dend, pdata+4),
+ STR_UNICODE);
+ SIVAL(pdata,0,len);
+ pdata += 4 + len;
+ data_size = PTR_DIFF(pdata,(*ppdata));
+ break;
+ }
case SMB_FILE_INTERNAL_INFORMATION:
DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_INTERNAL_INFORMATION\n"));
DEBUG(10,("smbd_do_qfilepathinfo: "
"SMB_FILE_STREAM_INFORMATION\n"));
+ if (is_ntfs_stream_smb_fname(smb_fname)) {
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+
status = SMB_VFS_STREAMINFO(
- conn, fsp, fname, talloc_tos(),
+ conn, fsp, smb_fname->base_name, talloc_tos(),
&num_streams, &streams);
if (!NT_STATUS_IS_OK(status)) {
#else
return NT_STATUS_DOS(ERRDOS, ERRbadlink);
#endif
- len = SMB_VFS_READLINK(conn,fname,
- buffer, PATH_MAX);
+ len = SMB_VFS_READLINK(conn,
+ smb_fname->base_name,
+ buffer, PATH_MAX);
if (len == -1) {
return map_nt_error_from_unix(errno);
}
if (fsp && !fsp->is_directory && (fsp->fh->fd != -1)) {
file_acl = SMB_VFS_SYS_ACL_GET_FD(fsp);
} else {
- file_acl = SMB_VFS_SYS_ACL_GET_FILE(conn, fname, SMB_ACL_TYPE_ACCESS);
+ file_acl =
+ SMB_VFS_SYS_ACL_GET_FILE(conn,
+ smb_fname->base_name,
+ SMB_ACL_TYPE_ACCESS);
}
if (file_acl == NULL && no_acl_syscall_error(errno)) {
- DEBUG(5,("smbd_do_qfilepathinfo: ACLs not implemented on filesystem containing %s\n",
- fname ));
+ DEBUG(5,("smbd_do_qfilepathinfo: ACLs "
+ "not implemented on "
+ "filesystem containing %s\n",
+ smb_fname->base_name));
return NT_STATUS_NOT_IMPLEMENTED;
}
if (S_ISDIR(sbuf.st_ex_mode)) {
if (fsp && fsp->is_directory) {
- def_acl = SMB_VFS_SYS_ACL_GET_FILE(conn, fsp->fsp_name, SMB_ACL_TYPE_DEFAULT);
+ def_acl =
+ SMB_VFS_SYS_ACL_GET_FILE(
+ conn,
+ fsp->fsp_name->base_name,
+ SMB_ACL_TYPE_DEFAULT);
} else {
- def_acl = SMB_VFS_SYS_ACL_GET_FILE(conn, fname, SMB_ACL_TYPE_DEFAULT);
+ def_acl =
+ SMB_VFS_SYS_ACL_GET_FILE(
+ conn,
+ smb_fname->base_name,
+ SMB_ACL_TYPE_DEFAULT);
}
def_acl = free_empty_sys_acl(conn, def_acl);
}
uint32 lock_pid;
enum brl_type lock_type;
+ /* We need an open file with a real fd for this. */
+ if (!fsp || fsp->is_directory || fsp->fh->fd == -1) {
+ return NT_STATUS_INVALID_LEVEL;
+ }
+
if (lock_data_count != POSIX_LOCK_DATA_SIZE) {
return NT_STATUS_INVALID_PARAMETER;
}
uint16 info_level;
unsigned int data_size = 0;
unsigned int param_size = 2;
- char *fname = NULL;
struct smb_filename *smb_fname = NULL;
bool delete_pending = False;
struct timespec write_time_ts;
return;
}
- fname = talloc_strdup(talloc_tos(),fsp->fsp_name);
- if (!fname) {
- reply_nterror(req, NT_STATUS_NO_MEMORY);
- return;
- }
-
- status = create_synthetic_smb_fname_split(talloc_tos(), fname,
- NULL, &smb_fname);
+ status = copy_smb_filename(talloc_tos(), fsp->fsp_name,
+ &smb_fname);
if (!NT_STATUS_IS_OK(status)) {
reply_nterror(req, status);
return;
/* We know this name is ok, it's already passed the checks. */
- } else if(fsp && (fsp->is_directory || fsp->fh->fd == -1)) {
+ } else if(fsp->is_directory || fsp->fh->fd == -1) {
/*
* This is actually a QFILEINFO on a directory
* handle (returned from an NT SMB). NT5.0 seems
}
} else {
+ char *fname = NULL;
+
/* qpathinfo */
if (total_params < 7) {
reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
conn,
req->flags2 & FLAGS2_DFS_PATHNAMES,
fname,
- &smb_fname,
- &fname);
+ 0,
+ NULL,
+ &smb_fname);
if (!NT_STATUS_IS_OK(status)) {
if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
reply_botherror(req,
} else if (!VALID_STAT(smb_fname->st) &&
SMB_VFS_STAT(conn, smb_fname) &&
(info_level != SMB_INFO_IS_NAME_VALID)) {
- ms_dfs_link = check_msdfs_link(conn, fname,
+ ms_dfs_link = check_msdfs_link(conn,
+ smb_fname->base_name,
&smb_fname->st);
if (!ms_dfs_link) {
}
}
- DEBUG(3,("call_trans2qfilepathinfo %s (fnum = %d) level=%d call=%d total_data=%d\n",
- fname,fsp ? fsp->fnum : -1, info_level,tran_call,total_data));
+ DEBUG(3,("call_trans2qfilepathinfo %s (fnum = %d) level=%d call=%d "
+ "total_data=%d\n", smb_fname_str_dbg(smb_fname),
+ fsp ? fsp->fnum : -1, info_level,tran_call,total_data));
/* Pull out any data sent here before we realloc. */
switch (info_level) {
break;
}
+ if ((info_level & 0xFF00) == 0xFF00) {
+ /*
+ * We use levels that start with 0xFF00
+ * internally to represent SMB2 specific levels
+ */
+ reply_nterror(req, NT_STATUS_INVALID_LEVEL);
+ return;
+ }
+
status = smbd_do_qfilepathinfo(conn, req, info_level,
fsp, smb_fname,
delete_pending, write_time_ts,
const struct smb_filename *smb_fname_old,
const struct smb_filename *smb_fname_new)
{
- char *oldname = NULL;
- char *newname = NULL;
NTSTATUS status = NT_STATUS_OK;
/* source must already exist. */
return NT_STATUS_FILE_IS_A_DIRECTORY;
}
- status = get_full_smb_filename(ctx, smb_fname_new, &newname);
- if (!NT_STATUS_IS_OK(status)) {
- goto out;
- }
- status = get_full_smb_filename(ctx, smb_fname_old, &oldname);
- if (!NT_STATUS_IS_OK(status)) {
- goto out;
+ /* Setting a hardlink to/from a stream isn't currently supported. */
+ if (is_ntfs_stream_smb_fname(smb_fname_old) ||
+ is_ntfs_stream_smb_fname(smb_fname_new)) {
+ return NT_STATUS_INVALID_PARAMETER;
}
- DEBUG(10,("hardlink_internals: doing hard link %s -> %s\n", newname, oldname ));
+ DEBUG(10,("hardlink_internals: doing hard link %s -> %s\n",
+ smb_fname_old->base_name, smb_fname_new->base_name));
- if (SMB_VFS_LINK(conn,oldname,newname) != 0) {
+ if (SMB_VFS_LINK(conn, smb_fname_old->base_name,
+ smb_fname_new->base_name) != 0) {
status = map_nt_error_from_unix(errno);
DEBUG(3,("hardlink_internals: Error %s hard link %s -> %s\n",
- nt_errstr(status), newname, oldname));
+ nt_errstr(status), smb_fname_old->base_name,
+ smb_fname_new->base_name));
}
- out:
- TALLOC_FREE(newname);
- TALLOC_FREE(oldname);
return status;
}
uint32 action =
FILE_NOTIFY_CHANGE_LAST_ACCESS
|FILE_NOTIFY_CHANGE_LAST_WRITE;
+ bool set_createtime = false;
NTSTATUS status;
if (!VALID_STAT(smb_fname->st)) {
}
/* get some defaults (no modifications) if any info is zero or -1. */
+ if (null_timespec(ft->create_time)) {
+ ft->create_time = smb_fname->st.st_ex_btime;
+ } else {
+ set_createtime = true;
+ }
+
+ if (null_timespec(ft->ctime)) {
+ ft->ctime = smb_fname->st.st_ex_ctime;
+ }
+
if (null_timespec(ft->atime)) {
ft->atime= smb_fname->st.st_ex_atime;
action &= ~FILE_NOTIFY_CHANGE_LAST_ACCESS;
time_to_asc(convert_timespec_to_time_t(ft->atime))));
DEBUG(5,("smb_set_filetime: modtime: %s\n ",
time_to_asc(convert_timespec_to_time_t(ft->mtime))));
- if (!null_timespec(ft->create_time)) {
- DEBUG(5,("smb_set_file_time: createtime: %s\n ",
- time_to_asc(convert_timespec_to_time_t(ft->create_time))));
- }
+ DEBUG(5,("smb_set_filetime: ctime: %s\n ",
+ time_to_asc(convert_timespec_to_time_t(ft->ctime))));
+ DEBUG(5,("smb_set_file_time: createtime: %s\n ",
+ time_to_asc(convert_timespec_to_time_t(ft->create_time))));
/*
* Try and set the times of this file if
struct timespec ats = smb_fname->st.st_ex_atime;
if ((timespec_compare(&ft->atime, &ats) == 0) &&
(timespec_compare(&ft->mtime, &mts) == 0)) {
+ if (set_createtime) {
+ notify_fname(conn, NOTIFY_ACTION_MODIFIED,
+ FILE_NOTIFY_CHANGE_CREATION,
+ smb_fname->base_name);
+ }
return NT_STATUS_OK;
}
}
}
#endif /* LARGE_SMB_OFF_T */
- DEBUG(10,("smb_file_position_information: Set file position information for file %s to %.0f\n",
- fsp->fsp_name, (double)position_information ));
+ DEBUG(10,("smb_file_position_information: Set file position "
+ "information for file %s to %.0f\n", fsp_str_dbg(fsp),
+ (double)position_information));
fsp->fh->position_information = position_information;
return NT_STATUS_OK;
}
struct smb_request *req,
const char *pdata,
int total_data,
- const char *fname)
+ const struct smb_filename *smb_fname)
{
char *link_target = NULL;
- const char *newname = fname;
+ const char *newname = smb_fname->base_name;
NTSTATUS status = NT_STATUS_OK;
TALLOC_CTX *ctx = talloc_tos();
conn,
req->flags2 & FLAGS2_DFS_PATHNAMES,
oldname,
- &smb_fname_old,
- NULL);
+ 0,
+ NULL,
+ &smb_fname_old);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
const char *pdata,
int total_data,
files_struct *fsp,
- const char *fname)
+ struct smb_filename *smb_fname_src)
{
bool overwrite;
uint32 root_fid;
uint32 len;
char *newname = NULL;
- char *base_name = NULL;
- struct smb_filename *smb_fname = NULL;
+ struct smb_filename *smb_fname_dst = NULL;
bool dest_has_wcard = False;
NTSTATUS status = NT_STATUS_OK;
char *p;
/* Create an smb_fname to call rename_internals_fsp() with. */
status = create_synthetic_smb_fname(talloc_tos(),
- fsp->base_fsp->fsp_name,
- newname, NULL, &smb_fname);
+ fsp->base_fsp->fsp_name->base_name, newname, NULL,
+ &smb_fname_dst);
if (!NT_STATUS_IS_OK(status)) {
goto out;
}
* Set the original last component, since
* rename_internals_fsp() requires it.
*/
- smb_fname->original_lcomp = talloc_strdup(smb_fname, newname);
- if (smb_fname->original_lcomp == NULL) {
+ smb_fname_dst->original_lcomp = talloc_strdup(smb_fname_dst,
+ newname);
+ if (smb_fname_dst->original_lcomp == NULL) {
status = NT_STATUS_NO_MEMORY;
goto out;
}
- /* Create a char * to call rename_internals() with. */
- base_name = talloc_asprintf(ctx, "%s%s",
- fsp->base_fsp->fsp_name,
- newname);
- if (!base_name) {
- status = NT_STATUS_NO_MEMORY;
- goto out;
- }
} else {
+ /*
+ * Build up an smb_fname_dst based on the filename passed in.
+ * We basically just strip off the last component, and put on
+ * the newname instead.
+ */
+ char *base_name = NULL;
+
/* newname must *not* be a stream name. */
if (newname[0] == ':') {
return NT_STATUS_NOT_SUPPORTED;
}
- /* Create the base directory. */
- base_name = talloc_strdup(ctx, fname);
+ /*
+ * Strip off the last component (filename) of the path passed
+ * in.
+ */
+ base_name = talloc_strdup(ctx, smb_fname_src->base_name);
if (!base_name) {
return NT_STATUS_NO_MEMORY;
}
return NT_STATUS_NO_MEMORY;
}
- status = unix_convert(ctx, conn, base_name, &smb_fname,
- UCF_SAVE_LCOMP);
+ status = unix_convert(ctx, conn, base_name, &smb_fname_dst,
+ (UCF_SAVE_LCOMP |
+ (dest_has_wcard ?
+ UCF_ALWAYS_ALLOW_WCARD_LCOMP :
+ 0)));
/* If an error we expect this to be
* NT_STATUS_OBJECT_PATH_NOT_FOUND */
goto out;
}
/* Create an smb_fname to call rename_internals_fsp() */
- status = create_synthetic_smb_fname(talloc_tos(),
+ status = create_synthetic_smb_fname(ctx,
base_name, NULL,
- NULL, &smb_fname);
+ NULL,
+ &smb_fname_dst);
if (!NT_STATUS_IS_OK(status)) {
goto out;
}
}
-
}
if (fsp) {
- DEBUG(10,("smb_file_rename_information: SMB_FILE_RENAME_INFORMATION (fnum %d) %s -> %s\n",
- fsp->fnum, fsp->fsp_name, base_name ));
- status = rename_internals_fsp(conn, fsp, smb_fname, 0,
+ DEBUG(10,("smb_file_rename_information: "
+ "SMB_FILE_RENAME_INFORMATION (fnum %d) %s -> %s\n",
+ fsp->fnum, fsp_str_dbg(fsp),
+ smb_fname_str_dbg(smb_fname_dst)));
+ status = rename_internals_fsp(conn, fsp, smb_fname_dst, 0,
overwrite);
} else {
- DEBUG(10,("smb_file_rename_information: SMB_FILE_RENAME_INFORMATION %s -> %s\n",
- fname, base_name ));
- status = rename_internals(ctx, conn, req, fname, base_name, 0,
- overwrite, False, dest_has_wcard,
- FILE_WRITE_ATTRIBUTES);
+ DEBUG(10,("smb_file_rename_information: "
+ "SMB_FILE_RENAME_INFORMATION %s -> %s\n",
+ smb_fname_str_dbg(smb_fname_src),
+ smb_fname_str_dbg(smb_fname_dst)));
+ status = rename_internals(ctx, conn, req, smb_fname_src,
+ smb_fname_dst, 0, overwrite, false,
+ dest_has_wcard,
+ FILE_WRITE_ATTRIBUTES);
}
out:
- TALLOC_FREE(smb_fname);
+ TALLOC_FREE(smb_fname_dst);
return status;
}
const char *pdata,
int total_data,
files_struct *fsp,
- const char *fname,
- SMB_STRUCT_STAT *psbuf)
+ const struct smb_filename *smb_fname)
{
uint16 posix_acl_version;
uint16 num_file_acls;
}
DEBUG(10,("smb_set_posix_acl: file %s num_file_acls = %u, num_def_acls = %u\n",
- fname ? fname : fsp->fsp_name,
+ smb_fname ? smb_fname_str_dbg(smb_fname) : fsp_str_dbg(fsp),
(unsigned int)num_file_acls,
(unsigned int)num_def_acls));
- if (valid_file_acls && !set_unix_posix_acl(conn, fsp, fname, num_file_acls,
- pdata + SMB_POSIX_ACL_HEADER_SIZE)) {
+ if (valid_file_acls && !set_unix_posix_acl(conn, fsp,
+ smb_fname->base_name, num_file_acls,
+ pdata + SMB_POSIX_ACL_HEADER_SIZE)) {
return map_nt_error_from_unix(errno);
}
- if (valid_def_acls && !set_unix_posix_default_acl(conn, fname, psbuf, num_def_acls,
- pdata + SMB_POSIX_ACL_HEADER_SIZE +
- (num_file_acls*SMB_POSIX_ACL_ENTRY_SIZE))) {
+ if (valid_def_acls && !set_unix_posix_default_acl(conn,
+ smb_fname->base_name, &smb_fname->st, num_def_acls,
+ pdata + SMB_POSIX_ACL_HEADER_SIZE +
+ (num_file_acls*SMB_POSIX_ACL_ENTRY_SIZE))) {
return map_nt_error_from_unix(errno);
}
return NT_STATUS_OK;
DEBUG(10,("smb_set_posix_lock: file %s, lock_type = %u,"
"lock_pid = %u, count = %.0f, offset = %.0f\n",
- fsp->fsp_name,
+ fsp_str_dbg(fsp),
(unsigned int)lock_type,
(unsigned int)lock_pid,
(double)count,
}
/****************************************************************************
- Deal with SMB_INFO_STANDARD.
+ Deal with SMB_SET_FILE_BASIC_INFO.
****************************************************************************/
-static NTSTATUS smb_set_info_standard(connection_struct *conn,
+static NTSTATUS smb_set_file_basic_info(connection_struct *conn,
const char *pdata,
int total_data,
files_struct *fsp,
const struct smb_filename *smb_fname)
{
+ /* Patch to do this correctly from Paul Eggert <eggert@twinsun.com>. */
struct smb_file_time ft;
+ uint32 dosmode = 0;
+ NTSTATUS status = NT_STATUS_OK;
+
ZERO_STRUCT(ft);
- if (total_data < 12) {
+ if (total_data < 36) {
return NT_STATUS_INVALID_PARAMETER;
}
+ /* Set the attributes */
+ dosmode = IVAL(pdata,32);
+ status = smb_set_file_dosmode(conn, smb_fname, dosmode);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
+
/* create time */
ft.create_time = interpret_long_date(pdata);
/* access time */
- ft.atime = interpret_long_date(pdata + 8);
+ ft.atime = interpret_long_date(pdata+8);
- /* write time */
- ft.mtime = interpret_long_date(pdata + 16);
+ /* write time. */
+ ft.mtime = interpret_long_date(pdata+16);
- DEBUG(10,("smb_set_info_standard: file %s\n",
- smb_fname_str_dbg(smb_fname)));
+ /* change time. */
+ ft.ctime = interpret_long_date(pdata+24);
+
+ DEBUG(10, ("smb_set_file_basic_info: file %s\n",
+ smb_fname_str_dbg(smb_fname)));
- return smb_set_file_time(conn, fsp, smb_fname, &ft, true);
+ return smb_set_file_time(conn, fsp, smb_fname, &ft,
+ true);
}
/****************************************************************************
- Deal with SMB_SET_FILE_BASIC_INFO.
+ Deal with SMB_INFO_STANDARD.
****************************************************************************/
-static NTSTATUS smb_set_file_basic_info(connection_struct *conn,
+static NTSTATUS smb_set_info_standard(connection_struct *conn,
const char *pdata,
int total_data,
files_struct *fsp,
const struct smb_filename *smb_fname)
{
- /* Patch to do this correctly from Paul Eggert <eggert@twinsun.com>. */
- struct timespec write_time;
- struct timespec changed_time;
struct smb_file_time ft;
- uint32 dosmode = 0;
- NTSTATUS status = NT_STATUS_OK;
- bool setting_write_time = true;
ZERO_STRUCT(ft);
- if (total_data < 36) {
+ if (total_data < 12) {
return NT_STATUS_INVALID_PARAMETER;
}
- /* Set the attributes */
- dosmode = IVAL(pdata,32);
- status = smb_set_file_dosmode(conn, smb_fname, dosmode);
- if (!NT_STATUS_IS_OK(status)) {
- return status;
- }
-
- /* access time */
- ft.atime = interpret_long_date(pdata+8);
-
- write_time = interpret_long_date(pdata+16);
- changed_time = interpret_long_date(pdata+24);
-
- /* mtime */
- ft.mtime = timespec_min(&write_time, &changed_time);
-
/* create time */
- ft.create_time = interpret_long_date(pdata);
-
- if ((timespec_compare(&write_time, &ft.mtime) == 1) &&
- !null_timespec(write_time)) {
- ft.mtime = write_time;
- }
-
- /* Prefer a defined time to an undefined one. */
- if (null_timespec(ft.mtime)) {
- if (null_timespec(write_time)) {
- ft.mtime = changed_time;
- setting_write_time = false;
- } else {
- ft.mtime = write_time;
- }
- }
+ ft.create_time = convert_time_t_to_timespec(srv_make_unix_date2(pdata));
+ /* access time */
+ ft.atime = convert_time_t_to_timespec(srv_make_unix_date2(pdata+4));
+ /* write time */
+ ft.mtime = convert_time_t_to_timespec(srv_make_unix_date2(pdata+8));
- DEBUG(10, ("smb_set_file_basic_info: file %s\n",
- smb_fname_str_dbg(smb_fname)));
+ DEBUG(10,("smb_set_info_standard: file %s\n",
+ smb_fname_str_dbg(smb_fname)));
- return smb_set_file_time(conn, fsp, smb_fname, &ft,
- setting_write_time);
+ return smb_set_file_time(conn,
+ fsp,
+ smb_fname,
+ &ft,
+ true);
}
/****************************************************************************
struct smb_request *req,
char **ppdata,
int total_data,
- const char *fname,
- SMB_STRUCT_STAT *psbuf,
+ struct smb_filename *smb_fname,
int *pdata_return_size)
{
- struct smb_filename *smb_fname;
NTSTATUS status = NT_STATUS_OK;
uint32 raw_unixmode = 0;
uint32 mod_unixmode = 0;
raw_unixmode = IVAL(pdata,8);
/* Next 4 bytes are not yet defined. */
- status = unix_perms_from_wire(conn, psbuf, raw_unixmode, PERM_NEW_DIR, &unixmode);
+ status = unix_perms_from_wire(conn, &smb_fname->st, raw_unixmode,
+ PERM_NEW_DIR, &unixmode);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
mod_unixmode = (uint32)unixmode | FILE_FLAG_POSIX_SEMANTICS;
DEBUG(10,("smb_posix_mkdir: file %s, mode 0%o\n",
- fname, (unsigned int)unixmode ));
-
- status = create_synthetic_smb_fname_split(talloc_tos(), fname, psbuf,
- &smb_fname);
- if (!NT_STATUS_IS_OK(status)) {
- return status;
- }
+ smb_fname_str_dbg(smb_fname), (unsigned int)unixmode));
status = SMB_VFS_CREATE_FILE(
conn, /* conn */
&fsp, /* result */
&info); /* pinfo */
- *psbuf = smb_fname->st;
- TALLOC_FREE(smb_fname);
-
if (NT_STATUS_IS_OK(status)) {
close_file(req, fsp, NORMAL_CLOSE);
}
case SMB_QUERY_FILE_UNIX_BASIC:
SSVAL(pdata,8,SMB_QUERY_FILE_UNIX_BASIC);
SSVAL(pdata,10,0); /* Padding. */
- store_file_unix_basic(conn, pdata + 12, fsp, psbuf);
+ store_file_unix_basic(conn, pdata + 12, fsp,
+ &smb_fname->st);
break;
case SMB_QUERY_FILE_UNIX_INFO2:
SSVAL(pdata,8,SMB_QUERY_FILE_UNIX_INFO2);
SSVAL(pdata,10,0); /* Padding. */
- store_file_unix_basic_info2(conn, pdata + 12, fsp, psbuf);
+ store_file_unix_basic_info2(conn, pdata + 12, fsp,
+ &smb_fname->st);
break;
default:
SSVAL(pdata,8,SMB_NO_INFO_LEVEL_RETURNED);
struct smb_request *req,
char **ppdata,
int total_data,
- const char *fname,
- SMB_STRUCT_STAT *psbuf,
+ struct smb_filename *smb_fname,
int *pdata_return_size)
{
- struct smb_filename *smb_fname = NULL;
bool extended_oplock_granted = False;
char *pdata = *ppdata;
uint32 flags = 0;
return smb_posix_mkdir(conn, req,
ppdata,
total_data,
- fname,
- psbuf,
+ smb_fname,
pdata_return_size);
}
raw_unixmode = IVAL(pdata,8);
/* Next 4 bytes are not yet defined. */
- status = unix_perms_from_wire(conn,
- psbuf,
- raw_unixmode,
- VALID_STAT(*psbuf) ? PERM_EXISTING_FILE : PERM_NEW_FILE,
- &unixmode);
+ status = unix_perms_from_wire(conn, &smb_fname->st, raw_unixmode,
+ (VALID_STAT(smb_fname->st) ?
+ PERM_EXISTING_FILE : PERM_NEW_FILE),
+ &unixmode);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
DEBUG(10,("smb_posix_open: file %s, smb_posix_flags = %u, mode 0%o\n",
- fname,
+ smb_fname_str_dbg(smb_fname),
(unsigned int)wire_open_mode,
(unsigned int)unixmode ));
- status = create_synthetic_smb_fname_split(talloc_tos(), fname, psbuf,
- &smb_fname);
- if (!NT_STATUS_IS_OK(status)) {
- return status;
- }
-
status = SMB_VFS_CREATE_FILE(
conn, /* conn */
req, /* req */
&fsp, /* result */
&info); /* pinfo */
- *psbuf = smb_fname->st;
- TALLOC_FREE(smb_fname);
-
if (!NT_STATUS_IS_OK(status)) {
return status;
}
case SMB_QUERY_FILE_UNIX_BASIC:
SSVAL(pdata,8,SMB_QUERY_FILE_UNIX_BASIC);
SSVAL(pdata,10,0); /* padding. */
- store_file_unix_basic(conn, pdata + 12, fsp, psbuf);
+ store_file_unix_basic(conn, pdata + 12, fsp,
+ &smb_fname->st);
break;
case SMB_QUERY_FILE_UNIX_INFO2:
SSVAL(pdata,8,SMB_QUERY_FILE_UNIX_INFO2);
SSVAL(pdata,10,0); /* padding. */
- store_file_unix_basic_info2(conn, pdata + 12, fsp, psbuf);
+ store_file_unix_basic_info2(conn, pdata + 12, fsp,
+ &smb_fname->st);
break;
default:
SSVAL(pdata,8,SMB_NO_INFO_LEVEL_RETURNED);
NULL);
if (lck == NULL) {
DEBUG(0, ("smb_posix_unlink: Could not get share mode "
- "lock for file %s\n", fsp->fsp_name));
+ "lock for file %s\n", fsp_str_dbg(fsp)));
close_file(req, fsp, NORMAL_CLOSE);
return NT_STATUS_INVALID_PARAMETER;
}
return close_file(req, fsp, NORMAL_CLOSE);
}
-/****************************************************************************
- Reply to a TRANS2_SETFILEINFO (set file info by fileid or pathname).
-****************************************************************************/
-
-static void call_trans2setfilepathinfo(connection_struct *conn,
- struct smb_request *req,
- unsigned int tran_call,
- char **pparams, int total_params,
- char **ppdata, int total_data,
- unsigned int max_data_bytes)
+NTSTATUS smbd_do_setfilepathinfo(connection_struct *conn,
+ struct smb_request *req,
+ TALLOC_CTX *mem_ctx,
+ uint16_t info_level,
+ files_struct *fsp,
+ struct smb_filename *smb_fname,
+ char **ppdata, int total_data,
+ int *ret_data_size)
{
- char *params = *pparams;
char *pdata = *ppdata;
- uint16 info_level;
- SMB_STRUCT_STAT sbuf;
- char *fname = NULL;
- struct smb_filename *smb_fname = NULL;
- files_struct *fsp = NULL;
NTSTATUS status = NT_STATUS_OK;
int data_return_size = 0;
- TALLOC_CTX *ctx = talloc_tos();
- if (!params) {
- reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
- return;
+ *ret_data_size = 0;
+
+ if (INFO_LEVEL_IS_UNIX(info_level) && !lp_unix_extensions()) {
+ return NT_STATUS_INVALID_LEVEL;
}
- if (tran_call == TRANSACT2_SETFILEINFO) {
- if (total_params < 4) {
- reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
- return;
+ if (!CAN_WRITE(conn)) {
+ /* Allow POSIX opens. The open path will deny
+ * any non-readonly opens. */
+ if (info_level != SMB_POSIX_PATH_OPEN) {
+ return NT_STATUS_DOS(ERRSRV, ERRaccess);
}
+ }
- fsp = file_fsp(req, SVAL(params,0));
- /* Basic check for non-null fsp. */
- if (!check_fsp_open(conn, req, fsp)) {
- return;
- }
- info_level = SVAL(params,2);
-
- fname = talloc_strdup(talloc_tos(),fsp->fsp_name);
- if (!fname) {
- reply_nterror(req, NT_STATUS_NO_MEMORY);
- return;
- }
-
- status = create_synthetic_smb_fname_split(talloc_tos(), fname,
- NULL, &smb_fname);
- if (!NT_STATUS_IS_OK(status)) {
- reply_nterror(req, status);
- return;
- }
-
- if(fsp->is_directory || fsp->fh->fd == -1) {
- /*
- * This is actually a SETFILEINFO on a directory
- * handle (returned from an NT SMB). NT5.0 seems
- * to do this call. JRA.
- */
- if (INFO_LEVEL_IS_UNIX(info_level)) {
- /* Always do lstat for UNIX calls. */
- if (SMB_VFS_LSTAT(conn, smb_fname)) {
- DEBUG(3,("call_trans2setfilepathinfo: "
- "SMB_VFS_LSTAT of %s failed "
- "(%s)\n",
- smb_fname_str_dbg(smb_fname),
- strerror(errno)));
- reply_nterror(req, map_nt_error_from_unix(errno));
- return;
- }
- } else {
- if (SMB_VFS_STAT(conn, smb_fname) != 0) {
- DEBUG(3,("call_trans2setfilepathinfo: "
- "fileinfo of %s failed (%s)\n",
- smb_fname_str_dbg(smb_fname),
- strerror(errno)));
- reply_nterror(req, map_nt_error_from_unix(errno));
- return;
- }
- }
- } else if (fsp->print_file) {
- /*
- * Doing a DELETE_ON_CLOSE should cancel a print job.
- */
- if ((info_level == SMB_SET_FILE_DISPOSITION_INFO) && CVAL(pdata,0)) {
- fsp->fh->private_options |= FILE_DELETE_ON_CLOSE;
-
- DEBUG(3,("call_trans2setfilepathinfo: Cancelling print job (%s)\n", fsp->fsp_name ));
-
- SSVAL(params,0,0);
- send_trans2_replies(conn, req, params, 2,
- *ppdata, 0,
- max_data_bytes);
- return;
- } else {
- reply_doserror(req, ERRDOS, ERRbadpath);
- return;
- }
- } else {
- /*
- * Original code - this is an open file.
- */
- if (!check_fsp(conn, req, fsp)) {
- return;
- }
-
- if (SMB_VFS_FSTAT(fsp, &smb_fname->st) != 0) {
- DEBUG(3,("call_trans2setfilepathinfo: fstat "
- "of fnum %d failed (%s)\n", fsp->fnum,
- strerror(errno)));
- reply_nterror(req, map_nt_error_from_unix(errno));
- return;
- }
- }
- } else {
- /* set path info */
- if (total_params < 7) {
- reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
- return;
- }
-
- info_level = SVAL(params,0);
- srvstr_get_path(ctx, params, req->flags2, &fname, ¶ms[6],
- total_params - 6, STR_TERMINATE,
- &status);
- if (!NT_STATUS_IS_OK(status)) {
- reply_nterror(req, status);
- return;
- }
-
- 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);
- return;
- }
- reply_nterror(req, status);
- return;
- }
-
- if (INFO_LEVEL_IS_UNIX(info_level)) {
- /*
- * For CIFS UNIX extensions the target name may not exist.
- */
-
- /* Always do lstat for UNIX calls. */
- SMB_VFS_LSTAT(conn, smb_fname);
-
- } else if (!VALID_STAT(smb_fname->st) &&
- SMB_VFS_STAT(conn, smb_fname)) {
- DEBUG(3,("call_trans2setfilepathinfo: SMB_VFS_STAT of "
- "%s failed (%s)\n",
- smb_fname_str_dbg(smb_fname),
- strerror(errno)));
- reply_nterror(req, map_nt_error_from_unix(errno));
- return;
- }
- }
-
- /* Set sbuf for use below. */
- sbuf = smb_fname->st;
-
- if (INFO_LEVEL_IS_UNIX(info_level) && !lp_unix_extensions()) {
- reply_nterror(req, NT_STATUS_INVALID_LEVEL);
- return;
- }
-
- if (!CAN_WRITE(conn)) {
- /* Allow POSIX opens. The open path will deny
- * any non-readonly opens. */
- if (info_level != SMB_POSIX_PATH_OPEN) {
- reply_doserror(req, ERRSRV, ERRaccess);
- return;
- }
- }
-
- DEBUG(3,("call_trans2setfilepathinfo(%d) %s (fnum %d) info_level=%d totdata=%d\n",
- tran_call,fname, fsp ? fsp->fnum : -1, info_level,total_data));
-
- /* Realloc the parameter size */
- *pparams = (char *)SMB_REALLOC(*pparams,2);
- if (*pparams == NULL) {
- reply_nterror(req, NT_STATUS_NO_MEMORY);
- return;
- }
- params = *pparams;
-
- SSVAL(params,0,0);
+ DEBUG(3,("smbd_do_setfilepathinfo: %s (fnum %d) info_level=%d "
+ "totdata=%d\n", smb_fname_str_dbg(smb_fname),
+ fsp ? fsp->fnum : -1, info_level, total_data));
switch (info_level) {
case SMB_SET_FILE_UNIX_LINK:
{
- if (tran_call != TRANSACT2_SETPATHINFO) {
+ if (fsp) {
/* We must have a pathname for this. */
- reply_nterror(req, NT_STATUS_INVALID_LEVEL);
- return;
+ return NT_STATUS_INVALID_LEVEL;
}
status = smb_set_file_unix_link(conn, req, pdata,
- total_data, fname);
+ total_data, smb_fname);
break;
}
case SMB_SET_FILE_UNIX_HLINK:
{
- if (tran_call != TRANSACT2_SETPATHINFO || smb_fname == NULL) {
+ if (fsp) {
/* We must have a pathname for this. */
- reply_nterror(req, NT_STATUS_INVALID_LEVEL);
- return;
+ return NT_STATUS_INVALID_LEVEL;
}
status = smb_set_file_unix_hlink(conn, req,
pdata, total_data,
{
status = smb_file_rename_information(conn, req,
pdata, total_data,
- fsp, fname);
+ fsp, smb_fname);
break;
}
pdata,
total_data,
fsp,
- fname,
- &sbuf);
+ smb_fname);
break;
}
#endif
case SMB_SET_POSIX_LOCK:
{
- if (tran_call != TRANSACT2_SETFILEINFO) {
- reply_nterror(req, NT_STATUS_INVALID_LEVEL);
- return;
+ if (!fsp) {
+ return NT_STATUS_INVALID_LEVEL;
}
status = smb_set_posix_lock(conn, req,
pdata, total_data, fsp);
case SMB_POSIX_PATH_OPEN:
{
- if (tran_call != TRANSACT2_SETPATHINFO) {
+ if (fsp) {
/* We must have a pathname for this. */
- reply_nterror(req, NT_STATUS_INVALID_LEVEL);
- return;
+ return NT_STATUS_INVALID_LEVEL;
}
status = smb_posix_open(conn, req,
ppdata,
total_data,
- fname,
- &sbuf,
+ smb_fname,
&data_return_size);
break;
}
case SMB_POSIX_PATH_UNLINK:
{
- if (tran_call != TRANSACT2_SETPATHINFO) {
+ if (fsp) {
/* We must have a pathname for this. */
- reply_nterror(req, NT_STATUS_INVALID_LEVEL);
- return;
+ return NT_STATUS_INVALID_LEVEL;
}
status = smb_posix_unlink(conn, req,
}
default:
- reply_nterror(req, NT_STATUS_INVALID_LEVEL);
+ return NT_STATUS_INVALID_LEVEL;
+ }
+
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
+
+ *ret_data_size = data_return_size;
+ return NT_STATUS_OK;
+}
+
+/****************************************************************************
+ Reply to a TRANS2_SETFILEINFO (set file info by fileid or pathname).
+****************************************************************************/
+
+static void call_trans2setfilepathinfo(connection_struct *conn,
+ struct smb_request *req,
+ unsigned int tran_call,
+ char **pparams, int total_params,
+ char **ppdata, int total_data,
+ unsigned int max_data_bytes)
+{
+ char *params = *pparams;
+ char *pdata = *ppdata;
+ uint16 info_level;
+ struct smb_filename *smb_fname = NULL;
+ files_struct *fsp = NULL;
+ NTSTATUS status = NT_STATUS_OK;
+ int data_return_size = 0;
+
+ if (!params) {
+ reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
+ return;
+ }
+
+ if (tran_call == TRANSACT2_SETFILEINFO) {
+ if (total_params < 4) {
+ reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
+ return;
+ }
+
+ fsp = file_fsp(req, SVAL(params,0));
+ /* Basic check for non-null fsp. */
+ if (!check_fsp_open(conn, req, fsp)) {
+ return;
+ }
+ info_level = SVAL(params,2);
+
+ status = copy_smb_filename(talloc_tos(), fsp->fsp_name,
+ &smb_fname);
+ if (!NT_STATUS_IS_OK(status)) {
+ reply_nterror(req, status);
+ return;
+ }
+
+ if(fsp->is_directory || fsp->fh->fd == -1) {
+ /*
+ * This is actually a SETFILEINFO on a directory
+ * handle (returned from an NT SMB). NT5.0 seems
+ * to do this call. JRA.
+ */
+ if (INFO_LEVEL_IS_UNIX(info_level)) {
+ /* Always do lstat for UNIX calls. */
+ if (SMB_VFS_LSTAT(conn, smb_fname)) {
+ DEBUG(3,("call_trans2setfilepathinfo: "
+ "SMB_VFS_LSTAT of %s failed "
+ "(%s)\n",
+ smb_fname_str_dbg(smb_fname),
+ strerror(errno)));
+ reply_nterror(req, map_nt_error_from_unix(errno));
+ return;
+ }
+ } else {
+ if (SMB_VFS_STAT(conn, smb_fname) != 0) {
+ DEBUG(3,("call_trans2setfilepathinfo: "
+ "fileinfo of %s failed (%s)\n",
+ smb_fname_str_dbg(smb_fname),
+ strerror(errno)));
+ reply_nterror(req, map_nt_error_from_unix(errno));
+ return;
+ }
+ }
+ } else if (fsp->print_file) {
+ /*
+ * Doing a DELETE_ON_CLOSE should cancel a print job.
+ */
+ if ((info_level == SMB_SET_FILE_DISPOSITION_INFO) && CVAL(pdata,0)) {
+ fsp->fh->private_options |= FILE_DELETE_ON_CLOSE;
+
+ DEBUG(3,("call_trans2setfilepathinfo: "
+ "Cancelling print job (%s)\n",
+ fsp_str_dbg(fsp)));
+
+ SSVAL(params,0,0);
+ send_trans2_replies(conn, req, params, 2,
+ *ppdata, 0,
+ max_data_bytes);
+ return;
+ } else {
+ reply_doserror(req, ERRDOS, ERRbadpath);
+ return;
+ }
+ } else {
+ /*
+ * Original code - this is an open file.
+ */
+ if (!check_fsp(conn, req, fsp)) {
+ return;
+ }
+
+ if (SMB_VFS_FSTAT(fsp, &smb_fname->st) != 0) {
+ DEBUG(3,("call_trans2setfilepathinfo: fstat "
+ "of fnum %d failed (%s)\n", fsp->fnum,
+ strerror(errno)));
+ reply_nterror(req, map_nt_error_from_unix(errno));
+ return;
+ }
+ }
+ } else {
+ char *fname = NULL;
+
+ /* set path info */
+ if (total_params < 7) {
+ reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
+ return;
+ }
+
+ info_level = SVAL(params,0);
+ srvstr_get_path(req, params, req->flags2, &fname, ¶ms[6],
+ total_params - 6, STR_TERMINATE,
+ &status);
+ if (!NT_STATUS_IS_OK(status)) {
+ reply_nterror(req, status);
+ return;
+ }
+
+ status = filename_convert(req, conn,
+ req->flags2 & FLAGS2_DFS_PATHNAMES,
+ fname,
+ 0,
+ NULL,
+ &smb_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);
+ return;
+ }
+ reply_nterror(req, status);
+ return;
+ }
+
+ if (INFO_LEVEL_IS_UNIX(info_level)) {
+ /*
+ * For CIFS UNIX extensions the target name may not exist.
+ */
+
+ /* Always do lstat for UNIX calls. */
+ SMB_VFS_LSTAT(conn, smb_fname);
+
+ } else if (!VALID_STAT(smb_fname->st) &&
+ SMB_VFS_STAT(conn, smb_fname)) {
+ DEBUG(3,("call_trans2setfilepathinfo: SMB_VFS_STAT of "
+ "%s failed (%s)\n",
+ smb_fname_str_dbg(smb_fname),
+ strerror(errno)));
+ reply_nterror(req, map_nt_error_from_unix(errno));
return;
+ }
}
+ DEBUG(3,("call_trans2setfilepathinfo(%d) %s (fnum %d) info_level=%d "
+ "totdata=%d\n", tran_call, smb_fname_str_dbg(smb_fname),
+ fsp ? fsp->fnum : -1, info_level,total_data));
+
+ /* Realloc the parameter size */
+ *pparams = (char *)SMB_REALLOC(*pparams,2);
+ if (*pparams == NULL) {
+ reply_nterror(req, NT_STATUS_NO_MEMORY);
+ return;
+ }
+ params = *pparams;
+
+ SSVAL(params,0,0);
+
+ status = smbd_do_setfilepathinfo(conn, req, req,
+ info_level,
+ fsp,
+ smb_fname,
+ ppdata, total_data,
+ &data_return_size);
if (!NT_STATUS_IS_OK(status)) {
if (open_was_deferred(req->mid)) {
/* We have re-scheduled this call. */
return;
}
- SSVAL(params,0,0);
send_trans2_replies(conn, req, params, 2, *ppdata, data_return_size,
max_data_bytes);
conn,
req->flags2 & FLAGS2_DFS_PATHNAMES,
directory,
- &smb_dname,
- NULL);
+ 0,
+ NULL,
+ &smb_dname);
if (!NT_STATUS_IS_OK(status)) {
if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
void reply_findclose(struct smb_request *req)
{
int dptr_num;
+ struct smbd_server_connection *sconn = smbd_server_conn;
START_PROFILE(SMBfindclose);
DEBUG(3,("reply_findclose, dptr_num = %d\n", dptr_num));
- dptr_close(&dptr_num);
+ dptr_close(sconn, &dptr_num);
reply_outbuf(req, 0, 0);