mirror of
https://github.com/samba-team/samba.git
synced 2025-01-25 06:04:04 +03:00
s3:smbd: split the dir entry marshalling into smbd_marshall_dir_entry()
So that we can reuse it for SMB2 Find. metze
This commit is contained in:
parent
59c3f5e3ca
commit
50f54250f4
@ -1446,88 +1446,41 @@ static bool smbd_dirptr_lanman2_mode_fn(TALLOC_CTX *ctx,
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool get_lanman2_dir_entry(TALLOC_CTX *ctx,
|
||||
static bool smbd_marshall_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,
|
||||
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,
|
||||
int space_remaining,
|
||||
bool *out_of_space,
|
||||
bool *got_exact_match,
|
||||
int *last_entry_off,
|
||||
struct ea_list *name_list)
|
||||
uint64_t *last_entry_off)
|
||||
{
|
||||
const char *mask = 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 */
|
||||
char *fname = NULL;
|
||||
struct smb_filename *smb_fname = NULL;
|
||||
struct smbd_dirptr_lanman2_state state;
|
||||
bool ok;
|
||||
uint32_t nt_extmode; /* Used for NT connections instead of mode */
|
||||
|
||||
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;
|
||||
|
||||
*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);
|
||||
|
||||
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;
|
||||
|
||||
if (!(mode & aDIR)) {
|
||||
file_size = get_file_size_stat(&smb_fname->st);
|
||||
}
|
||||
@ -1636,9 +1589,7 @@ static bool get_lanman2_dir_entry(TALLOC_CTX *ctx,
|
||||
|
||||
DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_EA_LIST\n"));
|
||||
if (!name_list) {
|
||||
TALLOC_FREE(fname);
|
||||
TALLOC_FREE(smb_fname);
|
||||
return False;
|
||||
return false;
|
||||
}
|
||||
if (requires_resume_key) {
|
||||
SIVAL(p,0,reskey);
|
||||
@ -1660,11 +1611,7 @@ static bool get_lanman2_dir_entry(TALLOC_CTX *ctx,
|
||||
/* 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) {
|
||||
TALLOC_FREE(fname);
|
||||
TALLOC_FREE(smb_fname);
|
||||
/* Move the dirptr back to prev_dirpos */
|
||||
dptr_SeekDir(dirptr, prev_dirpos);
|
||||
*out_of_space = True;
|
||||
*out_of_space = true;
|
||||
DEBUG(9,("get_lanman2_dir_entry: out of space\n"));
|
||||
return False; /* Not finished - just out of space */
|
||||
}
|
||||
@ -1717,7 +1664,7 @@ static bool get_lanman2_dir_entry(TALLOC_CTX *ctx,
|
||||
* IMPORTANT as not doing so will trigger
|
||||
* a Win2k client bug. JRA.
|
||||
*/
|
||||
if (!was_8_3 && state.check_mangled_names) {
|
||||
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)) {
|
||||
@ -1877,7 +1824,7 @@ static bool get_lanman2_dir_entry(TALLOC_CTX *ctx,
|
||||
* IMPORTANT as not doing so will trigger
|
||||
* a Win2k client bug. JRA.
|
||||
*/
|
||||
if (!was_8_3 && state.check_mangled_names) {
|
||||
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)) {
|
||||
@ -1951,20 +1898,13 @@ static bool get_lanman2_dir_entry(TALLOC_CTX *ctx,
|
||||
break;
|
||||
|
||||
default:
|
||||
TALLOC_FREE(fname);
|
||||
TALLOC_FREE(smb_fname);
|
||||
return false;
|
||||
}
|
||||
|
||||
TALLOC_FREE(fname);
|
||||
TALLOC_FREE(smb_fname);
|
||||
|
||||
if (PTR_DIFF(p,pdata) > space_remaining) {
|
||||
/* Move the dirptr back to prev_dirpos */
|
||||
dptr_SeekDir(dirptr, prev_dirpos);
|
||||
*out_of_space = True;
|
||||
*out_of_space = true;
|
||||
DEBUG(9,("get_lanman2_dir_entry: out of space\n"));
|
||||
return False; /* Not finished - just out of space */
|
||||
return false; /* Not finished - just out of space */
|
||||
}
|
||||
|
||||
/* Setup the last entry pointer, as an offset from base_data */
|
||||
@ -1975,6 +1915,105 @@ static bool get_lanman2_dir_entry(TALLOC_CTX *ctx,
|
||||
return true;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
*out_of_space = false;
|
||||
*got_exact_match = 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);
|
||||
TALLOC_FREE(smb_fname);
|
||||
if (*out_of_space) {
|
||||
dptr_SeekDir(dirptr, prev_dirpos);
|
||||
return false;
|
||||
}
|
||||
if (!ok) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*_last_entry_off = last_entry_off;
|
||||
return true;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
Reply to a TRANS2_FINDFIRST.
|
||||
****************************************************************************/
|
||||
|
Loading…
x
Reference in New Issue
Block a user