diff options
author | Stefan Metzmacher <metze@samba.org> | 2006-07-06 08:00:24 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 14:09:49 -0500 |
commit | af0a9eb52955cfae570bfdc01821f56385c860cf (patch) | |
tree | 9a798fd727753c3d9ceb44512579dc5b3e7fbebf /source4/libcli/raw | |
parent | 51e0ae33acf3cd09ae0eb9ef5077cecab4780a3e (diff) | |
download | samba-af0a9eb52955cfae570bfdc01821f56385c860cf.tar.gz samba-af0a9eb52955cfae570bfdc01821f56385c860cf.tar.bz2 samba-af0a9eb52955cfae570bfdc01821f56385c860cf.zip |
r16834: split the level's of smb_search_first/smb_search_next and the levels
of smb_search_data
metze
(This used to be commit 78c201db8a47a71908698c4dda2add4cf85694d9)
Diffstat (limited to 'source4/libcli/raw')
-rw-r--r-- | source4/libcli/raw/interfaces.h | 74 | ||||
-rw-r--r-- | source4/libcli/raw/rawsearch.c | 120 |
2 files changed, 114 insertions, 80 deletions
diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index c581978b81..f77d31a1c7 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -2146,33 +2146,41 @@ struct smb_notify { } out; }; -enum smb_search_level {RAW_SEARCH_GENERIC = 0xF000, - RAW_SEARCH_SEARCH, /* SMBsearch */ - RAW_SEARCH_FFIRST, /* SMBffirst */ - RAW_SEARCH_FUNIQUE, /* SMBfunique */ - RAW_SEARCH_SMB2, /* SMB2 Find */ - RAW_SEARCH_STANDARD = SMB_FIND_STANDARD, - RAW_SEARCH_EA_SIZE = SMB_FIND_EA_SIZE, - RAW_SEARCH_EA_LIST = SMB_FIND_EA_LIST, - RAW_SEARCH_DIRECTORY_INFO = SMB_FIND_DIRECTORY_INFO, - RAW_SEARCH_FULL_DIRECTORY_INFO = SMB_FIND_FULL_DIRECTORY_INFO, - RAW_SEARCH_NAME_INFO = SMB_FIND_NAME_INFO, - RAW_SEARCH_BOTH_DIRECTORY_INFO = SMB_FIND_BOTH_DIRECTORY_INFO, - RAW_SEARCH_ID_FULL_DIRECTORY_INFO = SMB_FIND_ID_FULL_DIRECTORY_INFO, - RAW_SEARCH_ID_BOTH_DIRECTORY_INFO = SMB_FIND_ID_BOTH_DIRECTORY_INFO, - RAW_SEARCH_UNIX_INFO = SMB_FIND_UNIX_INFO}; +enum smb_search_level { + RAW_SEARCH_SEARCH, /* SMBsearch */ + RAW_SEARCH_FFIRST, /* SMBffirst */ + RAW_SEARCH_FUNIQUE, /* SMBfunique */ + RAW_SEARCH_TRANS2, /* SMBtrans2 */ + RAW_SEARCH_SMB2 /* SMB2 Find */ +}; +enum smb_search_data_level { + RAW_SEARCH_DATA_GENERIC = 0x10000, /* only used in the smbcli_ code */ + RAW_SEARCH_DATA_SEARCH, + RAW_SEARCH_DATA_STANDARD = SMB_FIND_STANDARD, + RAW_SEARCH_DATA_EA_SIZE = SMB_FIND_EA_SIZE, + RAW_SEARCH_DATA_EA_LIST = SMB_FIND_EA_LIST, + RAW_SEARCH_DATA_DIRECTORY_INFO = SMB_FIND_DIRECTORY_INFO, + RAW_SEARCH_DATA_FULL_DIRECTORY_INFO = SMB_FIND_FULL_DIRECTORY_INFO, + RAW_SEARCH_DATA_NAME_INFO = SMB_FIND_NAME_INFO, + RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO = SMB_FIND_BOTH_DIRECTORY_INFO, + RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO = SMB_FIND_ID_FULL_DIRECTORY_INFO, + RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO = SMB_FIND_ID_BOTH_DIRECTORY_INFO, + RAW_SEARCH_DATA_UNIX_INFO = SMB_FIND_UNIX_INFO +}; /* union for file search */ union smb_search_first { struct { enum smb_search_level level; + enum smb_search_data_level data_level; } generic; /* search (old) findfirst interface. Also used for ffirst and funique. */ struct { enum smb_search_level level; + enum smb_search_data_level data_level; struct { uint16_t max_count; @@ -2187,6 +2195,7 @@ union smb_search_first { /* trans2 findfirst interface */ struct { enum smb_search_level level; + enum smb_search_data_level data_level; struct { uint16_t search_attrib; @@ -2207,7 +2216,7 @@ union smb_search_first { } t2ffirst; /* - SMB2 uses different level numbers for the same old SMB search levels + SMB2 uses different level numbers for the same old SMB trans2 search levels */ #define SMB2_FIND_DIRECTORY_INFO 0x01 #define SMB2_FIND_FULL_DIRECTORY_INFO 0x02 @@ -2218,6 +2227,7 @@ union smb_search_first { /* SMB2 Find */ struct smb2_find { enum smb_search_level level; + enum smb_search_data_level data_level; struct { union smb_handle file; @@ -2228,7 +2238,7 @@ union smb_search_first { uint32_t unknown; /* perhaps a continue token? */ /* struct smb2_handle handle; */ /* uint16_t pattern_ofs; */ - /* uint32_t pattern_size; */ + /* uint16_t pattern_size; */ uint32_t max_response_size; /* dynamic body */ @@ -2250,12 +2260,14 @@ union smb_search_first { union smb_search_next { struct { enum smb_search_level level; + enum smb_search_data_level data_level; } generic; /* search (old) findnext interface. Also used for ffirst when continuing */ struct { enum smb_search_level level; + enum smb_search_data_level data_level; struct { uint16_t max_count; @@ -2276,6 +2288,7 @@ union smb_search_next { /* trans2 findnext interface */ struct { enum smb_search_level level; + enum smb_search_data_level data_level; struct { uint16_t handle; @@ -2297,7 +2310,10 @@ union smb_search_next { /* union for search reply file data */ union smb_search_data { - /* search (old) findfirst */ + /* + * search (old) findfirst + * RAW_SEARCH_DATA_SEARCH + */ struct { uint16_t attrib; time_t write_time; @@ -2305,8 +2321,8 @@ union smb_search_data { struct smb_search_id id; const char *name; } search; - - /* trans2 findfirst RAW_SEARCH_STANDARD level */ + + /* trans2 findfirst RAW_SEARCH_DATA_STANDARD level */ struct { uint32_t resume_key; time_t create_time; @@ -2318,7 +2334,7 @@ union smb_search_data { struct smb_wire_string name; } standard; - /* trans2 findfirst RAW_SEARCH_EA_SIZE level */ + /* trans2 findfirst RAW_SEARCH_DATA_EA_SIZE level */ struct { uint32_t resume_key; time_t create_time; @@ -2331,7 +2347,7 @@ union smb_search_data { struct smb_wire_string name; } ea_size; - /* trans2 findfirst RAW_SEARCH_EA_LIST level */ + /* trans2 findfirst RAW_SEARCH_DATA_EA_LIST level */ struct { uint32_t resume_key; time_t create_time; @@ -2344,7 +2360,7 @@ union smb_search_data { struct smb_wire_string name; } ea_list; - /* RAW_SEARCH_DIRECTORY_INFO interface */ + /* RAW_SEARCH_DATA_DIRECTORY_INFO interface */ struct { uint32_t file_index; NTTIME create_time; @@ -2357,7 +2373,7 @@ union smb_search_data { struct smb_wire_string name; } directory_info; - /* RAW_SEARCH_FULL_DIRECTORY_INFO interface */ + /* RAW_SEARCH_DATA_FULL_DIRECTORY_INFO interface */ struct { uint32_t file_index; NTTIME create_time; @@ -2371,13 +2387,13 @@ union smb_search_data { struct smb_wire_string name; } full_directory_info; - /* RAW_SEARCH_NAME_INFO interface */ + /* RAW_SEARCH_DATA_NAME_INFO interface */ struct { uint32_t file_index; struct smb_wire_string name; } name_info; - /* RAW_SEARCH_BOTH_DIRECTORY_INFO interface */ + /* RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO interface */ struct { uint32_t file_index; NTTIME create_time; @@ -2392,7 +2408,7 @@ union smb_search_data { struct smb_wire_string name; } both_directory_info; - /* RAW_SEARCH_ID_FULL_DIRECTORY_INFO interface */ + /* RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO interface */ struct { uint32_t file_index; NTTIME create_time; @@ -2407,7 +2423,7 @@ union smb_search_data { struct smb_wire_string name; } id_full_directory_info; - /* RAW_SEARCH_ID_BOTH_DIRECTORY_INFO interface */ + /* RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO interface */ struct { uint32_t file_index; NTTIME create_time; @@ -2423,7 +2439,7 @@ union smb_search_data { struct smb_wire_string name; } id_both_directory_info; - /* RAW_SEARCH_UNIX_INFO interface */ + /* RAW_SEARCH_DATA_UNIX_INFO interface */ struct { uint32_t file_index; uint64_t size; diff --git a/source4/libcli/raw/rawsearch.c b/source4/libcli/raw/rawsearch.c index 5e05d7c3c5..4836766a93 100644 --- a/source4/libcli/raw/rawsearch.c +++ b/source4/libcli/raw/rawsearch.c @@ -194,7 +194,6 @@ static NTSTATUS smb_raw_search_close_old(struct smbcli_tree *tree, static NTSTATUS smb_raw_search_first_blob(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, /* used to allocate output blobs */ union smb_search_first *io, - uint16_t info_level, DATA_BLOB *out_param_blob, DATA_BLOB *out_data_blob) { @@ -211,7 +210,15 @@ static NTSTATUS smb_raw_search_first_blob(struct smbcli_tree *tree, tp.in.max_data = 0xFFFF; tp.in.setup = &setup; - if (info_level == RAW_SEARCH_EA_LIST) { + if (io->t2ffirst.level != RAW_SEARCH_TRANS2) { + return NT_STATUS_INVALID_LEVEL; + } + + if (io->t2ffirst.data_level >= RAW_SEARCH_DATA_GENERIC) { + return NT_STATUS_INVALID_LEVEL; + } + + if (io->t2ffirst.data_level == RAW_SEARCH_DATA_EA_LIST) { if (!ea_push_name_list(mem_ctx, &tp.in.data, io->t2ffirst.in.num_names, @@ -219,7 +226,7 @@ static NTSTATUS smb_raw_search_first_blob(struct smbcli_tree *tree, return NT_STATUS_NO_MEMORY; } } - + tp.in.params = data_blob_talloc(mem_ctx, NULL, 12); if (!tp.in.params.data) { return NT_STATUS_NO_MEMORY; @@ -228,7 +235,7 @@ static NTSTATUS smb_raw_search_first_blob(struct smbcli_tree *tree, SSVAL(tp.in.params.data, 0, io->t2ffirst.in.search_attrib); SSVAL(tp.in.params.data, 2, io->t2ffirst.in.max_count); SSVAL(tp.in.params.data, 4, io->t2ffirst.in.flags); - SSVAL(tp.in.params.data, 6, info_level); + SSVAL(tp.in.params.data, 6, io->t2ffirst.data_level); SIVAL(tp.in.params.data, 8, io->t2ffirst.in.storage_type); smbcli_blob_append_string(tree->session, mem_ctx, &tp.in.params, @@ -255,7 +262,6 @@ static NTSTATUS smb_raw_search_first_blob(struct smbcli_tree *tree, static NTSTATUS smb_raw_search_next_blob(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_search_next *io, - uint16_t info_level, DATA_BLOB *out_param_blob, DATA_BLOB *out_data_blob) { @@ -272,7 +278,15 @@ static NTSTATUS smb_raw_search_next_blob(struct smbcli_tree *tree, tp.in.max_data = 0xFFFF; tp.in.setup = &setup; - if (info_level == RAW_SEARCH_EA_LIST) { + if (io->t2fnext.level != RAW_SEARCH_TRANS2) { + return NT_STATUS_INVALID_LEVEL; + } + + if (io->t2fnext.data_level >= RAW_SEARCH_DATA_GENERIC) { + return NT_STATUS_INVALID_LEVEL; + } + + if (io->t2fnext.data_level == RAW_SEARCH_DATA_EA_LIST) { if (!ea_push_name_list(mem_ctx, &tp.in.data, io->t2fnext.in.num_names, @@ -287,8 +301,8 @@ static NTSTATUS smb_raw_search_next_blob(struct smbcli_tree *tree, } SSVAL(tp.in.params.data, 0, io->t2fnext.in.handle); - SSVAL(tp.in.params.data, 2, io->t2fnext.in.max_count); - SSVAL(tp.in.params.data, 4, info_level); + SSVAL(tp.in.params.data, 2, io->t2fnext.in.max_count); + SSVAL(tp.in.params.data, 4, io->t2fnext.data_level); SIVAL(tp.in.params.data, 6, io->t2fnext.in.resume_key); SSVAL(tp.in.params.data, 10, io->t2fnext.in.flags); @@ -315,7 +329,7 @@ static NTSTATUS smb_raw_search_next_blob(struct smbcli_tree *tree, SMB2 */ NTSTATUS smb_raw_search_common(TALLOC_CTX *mem_ctx, - enum smb_search_level level, + enum smb_search_data_level level, const DATA_BLOB *blob, union smb_search_data *data, uint_t *next_ofs, @@ -335,7 +349,7 @@ NTSTATUS smb_raw_search_common(TALLOC_CTX *mem_ctx, } switch (level) { - case RAW_SEARCH_DIRECTORY_INFO: + case RAW_SEARCH_DATA_DIRECTORY_INFO: if (blen < 65) return NT_STATUS_INFO_LENGTH_MISMATCH; data->directory_info.file_index = IVAL(blob->data, 4); data->directory_info.create_time = smbcli_pull_nttime(blob->data, 8); @@ -353,7 +367,7 @@ NTSTATUS smb_raw_search_common(TALLOC_CTX *mem_ctx, } return NT_STATUS_OK; - case RAW_SEARCH_FULL_DIRECTORY_INFO: + case RAW_SEARCH_DATA_FULL_DIRECTORY_INFO: if (blen < 69) return NT_STATUS_INFO_LENGTH_MISMATCH; data->full_directory_info.file_index = IVAL(blob->data, 4); data->full_directory_info.create_time = smbcli_pull_nttime(blob->data, 8); @@ -372,7 +386,7 @@ NTSTATUS smb_raw_search_common(TALLOC_CTX *mem_ctx, } return NT_STATUS_OK; - case RAW_SEARCH_NAME_INFO: + case RAW_SEARCH_DATA_NAME_INFO: if (blen < 13) return NT_STATUS_INFO_LENGTH_MISMATCH; data->name_info.file_index = IVAL(blob->data, 4); len = smbcli_blob_pull_string(NULL, mem_ctx, blob, @@ -384,7 +398,7 @@ NTSTATUS smb_raw_search_common(TALLOC_CTX *mem_ctx, return NT_STATUS_OK; - case RAW_SEARCH_BOTH_DIRECTORY_INFO: + case RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO: if (blen < 95) return NT_STATUS_INFO_LENGTH_MISMATCH; data->both_directory_info.file_index = IVAL(blob->data, 4); data->both_directory_info.create_time = smbcli_pull_nttime(blob->data, 8); @@ -407,7 +421,7 @@ NTSTATUS smb_raw_search_common(TALLOC_CTX *mem_ctx, return NT_STATUS_OK; - case RAW_SEARCH_ID_FULL_DIRECTORY_INFO: + case RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO: if (blen < 81) return NT_STATUS_INFO_LENGTH_MISMATCH; data->id_full_directory_info.file_index = IVAL(blob->data, 4); data->id_full_directory_info.create_time = smbcli_pull_nttime(blob->data, 8); @@ -427,7 +441,7 @@ NTSTATUS smb_raw_search_common(TALLOC_CTX *mem_ctx, } return NT_STATUS_OK; - case RAW_SEARCH_ID_BOTH_DIRECTORY_INFO: + case RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO: if (blen < 105) return NT_STATUS_INFO_LENGTH_MISMATCH; data->id_both_directory_info.file_index = IVAL(blob->data, 4); data->id_both_directory_info.create_time = smbcli_pull_nttime(blob->data, 8); @@ -467,7 +481,7 @@ NTSTATUS smb_raw_search_common(TALLOC_CTX *mem_ctx, */ static int parse_trans2_search(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, - enum smb_search_level level, + enum smb_search_data_level level, uint16_t flags, DATA_BLOB *blob, union smb_search_data *data) @@ -478,15 +492,12 @@ static int parse_trans2_search(struct smbcli_tree *tree, NTSTATUS status; switch (level) { - case RAW_SEARCH_GENERIC: - case RAW_SEARCH_SEARCH: - case RAW_SEARCH_FFIRST: - case RAW_SEARCH_FUNIQUE: - case RAW_SEARCH_SMB2: + case RAW_SEARCH_DATA_GENERIC: + case RAW_SEARCH_DATA_SEARCH: /* handled elsewhere */ return -1; - case RAW_SEARCH_STANDARD: + case RAW_SEARCH_DATA_STANDARD: if (flags & FLAG_TRANS2_FIND_REQUIRE_RESUME) { if (blob->length < 4) return -1; data->standard.resume_key = IVAL(blob->data, 0); @@ -508,7 +519,7 @@ static int parse_trans2_search(struct smbcli_tree *tree, 22, 23, STR_LEN8BIT | STR_TERMINATE | STR_LEN_NOTERM); return len + 23; - case RAW_SEARCH_EA_SIZE: + case RAW_SEARCH_DATA_EA_SIZE: if (flags & FLAG_TRANS2_FIND_REQUIRE_RESUME) { if (blob->length < 4) return -1; data->ea_size.resume_key = IVAL(blob->data, 0); @@ -531,7 +542,7 @@ static int parse_trans2_search(struct smbcli_tree *tree, 26, 27, STR_LEN8BIT | STR_TERMINATE | STR_NOALIGN); return len + 27 + 1; - case RAW_SEARCH_EA_LIST: + case RAW_SEARCH_DATA_EA_LIST: if (flags & FLAG_TRANS2_FIND_REQUIRE_RESUME) { if (blob->length < 4) return -1; data->ea_list.resume_key = IVAL(blob->data, 0); @@ -569,7 +580,7 @@ static int parse_trans2_search(struct smbcli_tree *tree, STR_LEN8BIT | STR_NOALIGN); return len + ea_size + 23 + 1; - case RAW_SEARCH_UNIX_INFO: + case RAW_SEARCH_DATA_UNIX_INFO: if (blob->length < 109) return -1; ofs = IVAL(blob->data, 0); data->unix_info.file_index = IVAL(blob->data, 4); @@ -594,12 +605,12 @@ static int parse_trans2_search(struct smbcli_tree *tree, } return ofs; - case RAW_SEARCH_DIRECTORY_INFO: - case RAW_SEARCH_FULL_DIRECTORY_INFO: - case RAW_SEARCH_NAME_INFO: - case RAW_SEARCH_BOTH_DIRECTORY_INFO: - case RAW_SEARCH_ID_FULL_DIRECTORY_INFO: - case RAW_SEARCH_ID_BOTH_DIRECTORY_INFO: { + case RAW_SEARCH_DATA_DIRECTORY_INFO: + case RAW_SEARCH_DATA_FULL_DIRECTORY_INFO: + case RAW_SEARCH_DATA_NAME_INFO: + case RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO: + case RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO: + case RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO: { uint_t str_flags = STR_UNICODE; if (!(tree->session->transport->negotiate.capabilities & CAP_UNICODE)) { str_flags = STR_ASCII; @@ -622,7 +633,7 @@ static int parse_trans2_search(struct smbcli_tree *tree, ****************************************************************************/ static NTSTATUS smb_raw_t2search_backend(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, - enum smb_search_level level, + enum smb_search_data_level level, uint16_t flags, int16_t count, DATA_BLOB *blob, @@ -668,22 +679,24 @@ NTSTATUS smb_raw_search_first(struct smbcli_tree *tree, union smb_search_first *io, void *private, BOOL (*callback)(void *private, union smb_search_data *file)) { - uint16_t info_level = 0; DATA_BLOB p_blob, d_blob; NTSTATUS status; - - if (io->generic.level == RAW_SEARCH_SEARCH || - io->generic.level == RAW_SEARCH_FFIRST || - io->generic.level == RAW_SEARCH_FUNIQUE) { + + switch (io->generic.level) { + case RAW_SEARCH_SEARCH: + case RAW_SEARCH_FFIRST: + case RAW_SEARCH_FUNIQUE: return smb_raw_search_first_old(tree, mem_ctx, io, private, callback); - } - if (io->generic.level >= RAW_SEARCH_GENERIC) { + + case RAW_SEARCH_TRANS2: + break; + + case RAW_SEARCH_SMB2: return NT_STATUS_INVALID_LEVEL; } - info_level = (uint16_t)io->generic.level; status = smb_raw_search_first_blob(tree, mem_ctx, - io, info_level, &p_blob, &d_blob); + io, &p_blob, &d_blob); if (!NT_STATUS_IS_OK(status)) { return status; } @@ -698,9 +711,9 @@ NTSTATUS smb_raw_search_first(struct smbcli_tree *tree, io->t2ffirst.out.handle = SVAL(p_blob.data, 0); io->t2ffirst.out.count = SVAL(p_blob.data, 2); io->t2ffirst.out.end_of_search = SVAL(p_blob.data, 4); - + status = smb_raw_t2search_backend(tree, mem_ctx, - io->generic.level, + io->generic.data_level, io->t2ffirst.in.flags, io->t2ffirst.out.count, &d_blob, private, callback); @@ -714,21 +727,26 @@ NTSTATUS smb_raw_search_next(struct smbcli_tree *tree, union smb_search_next *io, void *private, BOOL (*callback)(void *private, union smb_search_data *file)) { - uint16_t info_level = 0; DATA_BLOB p_blob, d_blob; NTSTATUS status; - if (io->generic.level == RAW_SEARCH_SEARCH || - io->generic.level == RAW_SEARCH_FFIRST) { + switch (io->generic.level) { + case RAW_SEARCH_SEARCH: + case RAW_SEARCH_FFIRST: return smb_raw_search_next_old(tree, mem_ctx, io, private, callback); - } - if (io->generic.level >= RAW_SEARCH_GENERIC) { + + case RAW_SEARCH_FUNIQUE: + return NT_STATUS_INVALID_LEVEL; + + case RAW_SEARCH_TRANS2: + break; + + case RAW_SEARCH_SMB2: return NT_STATUS_INVALID_LEVEL; } - info_level = (uint16_t)io->generic.level; status = smb_raw_search_next_blob(tree, mem_ctx, - io, info_level, &p_blob, &d_blob); + io, &p_blob, &d_blob); if (!NT_STATUS_IS_OK(status)) { return status; } @@ -744,7 +762,7 @@ NTSTATUS smb_raw_search_next(struct smbcli_tree *tree, io->t2fnext.out.end_of_search = SVAL(p_blob.data, 2); status = smb_raw_t2search_backend(tree, mem_ctx, - io->generic.level, + io->generic.data_level, io->t2fnext.in.flags, io->t2fnext.out.count, &d_blob, private, callback); |