mirror of
https://github.com/samba-team/samba.git
synced 2025-02-26 21:57:41 +03:00
libsmb: Move symlink_reparse_buffer_parse() to reparse.c
The goal of this is to eventually remove reparse_symlink.c once we have marshalling routines for symlinks in reparse.c Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
parent
e99e676bd2
commit
8ad55c382a
@ -22,6 +22,7 @@
|
||||
#include "python/py3compat.h"
|
||||
#include "libcli/util/pyerrors.h"
|
||||
#include "reparse.h"
|
||||
#include "reparse_symlink.h"
|
||||
#include "smb_constants.h"
|
||||
|
||||
static PyObject *py_reparse_put(PyObject *module, PyObject *args)
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "lib/util/debug.h"
|
||||
#include "lib/util/bytearray.h"
|
||||
#include "lib/util/charset/charset.h"
|
||||
#include "smb_util.h"
|
||||
|
||||
static NTSTATUS reparse_buffer_check(const uint8_t *in_data,
|
||||
size_t in_len,
|
||||
@ -112,6 +113,100 @@ static int nfs_reparse_buffer_parse(TALLOC_CTX *mem_ctx,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int symlink_reparse_buffer_parse(TALLOC_CTX *mem_ctx,
|
||||
struct symlink_reparse_struct *dst,
|
||||
const uint8_t *src,
|
||||
size_t srclen)
|
||||
{
|
||||
uint16_t reparse_data_length;
|
||||
uint16_t substitute_name_offset, substitute_name_length;
|
||||
uint16_t print_name_offset, print_name_length;
|
||||
bool ok;
|
||||
|
||||
if (srclen < 20) {
|
||||
DBG_DEBUG("srclen = %zu, expected >= 20\n", srclen);
|
||||
return EINVAL;
|
||||
}
|
||||
if (PULL_LE_U32(src, 0) != IO_REPARSE_TAG_SYMLINK) {
|
||||
DBG_DEBUG("Got ReparseTag %8.8x, expected %8.8x\n",
|
||||
PULL_LE_U32(src, 0),
|
||||
IO_REPARSE_TAG_SYMLINK);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
reparse_data_length = PULL_LE_U16(src, 4);
|
||||
substitute_name_offset = PULL_LE_U16(src, 8);
|
||||
substitute_name_length = PULL_LE_U16(src, 10);
|
||||
print_name_offset = PULL_LE_U16(src, 12);
|
||||
print_name_length = PULL_LE_U16(src, 14);
|
||||
|
||||
if (reparse_data_length < 12) {
|
||||
DBG_DEBUG("reparse_data_length = %"PRIu16", expected >= 12\n",
|
||||
reparse_data_length);
|
||||
return EINVAL;
|
||||
}
|
||||
if (smb_buffer_oob(srclen - 8, reparse_data_length, 0)) {
|
||||
DBG_DEBUG("reparse_data_length (%"PRIu16") too large for "
|
||||
"src_len (%zu)\n",
|
||||
reparse_data_length,
|
||||
srclen);
|
||||
return EINVAL;
|
||||
}
|
||||
if (smb_buffer_oob(reparse_data_length - 12, substitute_name_offset,
|
||||
substitute_name_length)) {
|
||||
DBG_DEBUG("substitute_name (%"PRIu16"/%"PRIu16") does not fit "
|
||||
"in reparse_data_length (%"PRIu16")\n",
|
||||
substitute_name_offset,
|
||||
substitute_name_length,
|
||||
reparse_data_length - 12);
|
||||
return EINVAL;
|
||||
}
|
||||
if (smb_buffer_oob(reparse_data_length - 12, print_name_offset,
|
||||
print_name_length)) {
|
||||
DBG_DEBUG("print_name (%"PRIu16"/%"PRIu16") does not fit in "
|
||||
"reparse_data_length (%"PRIu16")\n",
|
||||
print_name_offset,
|
||||
print_name_length,
|
||||
reparse_data_length - 12);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
*dst = (struct symlink_reparse_struct) {
|
||||
.unparsed_path_length = PULL_LE_U16(src, 6),
|
||||
.flags = PULL_LE_U32(src, 16),
|
||||
};
|
||||
|
||||
ok = convert_string_talloc(mem_ctx,
|
||||
CH_UTF16,
|
||||
CH_UNIX,
|
||||
src + 20 + substitute_name_offset,
|
||||
substitute_name_length,
|
||||
&dst->substitute_name,
|
||||
NULL);
|
||||
if (!ok) {
|
||||
int ret = errno;
|
||||
DBG_DEBUG("convert_string_talloc for substitute_name "
|
||||
"failed\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ok = convert_string_talloc(mem_ctx,
|
||||
CH_UTF16,
|
||||
CH_UNIX,
|
||||
src + 20 + print_name_offset,
|
||||
print_name_length,
|
||||
&dst->print_name,
|
||||
NULL);
|
||||
if (!ok) {
|
||||
int ret = errno;
|
||||
DBG_DEBUG("convert_string_talloc for print_name failed\n");
|
||||
TALLOC_FREE(dst->substitute_name);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
NTSTATUS reparse_data_buffer_parse(TALLOC_CTX *mem_ctx,
|
||||
struct reparse_data_buffer *dst,
|
||||
const uint8_t *buf,
|
||||
|
@ -20,9 +20,15 @@
|
||||
|
||||
#include <talloc.h>
|
||||
#include "replace.h"
|
||||
#include "libcli/smb/reparse_symlink.h"
|
||||
#include "libcli/util/ntstatus.h"
|
||||
|
||||
struct symlink_reparse_struct {
|
||||
uint16_t unparsed_path_length; /* reserved for the reparse point */
|
||||
char *substitute_name;
|
||||
char *print_name;
|
||||
uint32_t flags;
|
||||
};
|
||||
|
||||
struct nfs_reparse_data_buffer {
|
||||
uint64_t type;
|
||||
|
||||
|
@ -165,97 +165,3 @@ fail:
|
||||
TALLOC_FREE(print_utf16);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int symlink_reparse_buffer_parse(TALLOC_CTX *mem_ctx,
|
||||
struct symlink_reparse_struct *dst,
|
||||
const uint8_t *src,
|
||||
size_t srclen)
|
||||
{
|
||||
uint16_t reparse_data_length;
|
||||
uint16_t substitute_name_offset, substitute_name_length;
|
||||
uint16_t print_name_offset, print_name_length;
|
||||
bool ok;
|
||||
|
||||
if (srclen < 20) {
|
||||
DBG_DEBUG("srclen = %zu, expected >= 20\n", srclen);
|
||||
return EINVAL;
|
||||
}
|
||||
if (PULL_LE_U32(src, 0) != IO_REPARSE_TAG_SYMLINK) {
|
||||
DBG_DEBUG("Got ReparseTag %8.8x, expected %8.8x\n",
|
||||
PULL_LE_U32(src, 0),
|
||||
IO_REPARSE_TAG_SYMLINK);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
reparse_data_length = PULL_LE_U16(src, 4);
|
||||
substitute_name_offset = PULL_LE_U16(src, 8);
|
||||
substitute_name_length = PULL_LE_U16(src, 10);
|
||||
print_name_offset = PULL_LE_U16(src, 12);
|
||||
print_name_length = PULL_LE_U16(src, 14);
|
||||
|
||||
if (reparse_data_length < 12) {
|
||||
DBG_DEBUG("reparse_data_length = %"PRIu16", expected >= 12\n",
|
||||
reparse_data_length);
|
||||
return EINVAL;
|
||||
}
|
||||
if (smb_buffer_oob(srclen - 8, reparse_data_length, 0)) {
|
||||
DBG_DEBUG("reparse_data_length (%"PRIu16") too large for "
|
||||
"src_len (%zu)\n",
|
||||
reparse_data_length,
|
||||
srclen);
|
||||
return EINVAL;
|
||||
}
|
||||
if (smb_buffer_oob(reparse_data_length - 12, substitute_name_offset,
|
||||
substitute_name_length)) {
|
||||
DBG_DEBUG("substitute_name (%"PRIu16"/%"PRIu16") does not fit "
|
||||
"in reparse_data_length (%"PRIu16")\n",
|
||||
substitute_name_offset,
|
||||
substitute_name_length,
|
||||
reparse_data_length - 12);
|
||||
return EINVAL;
|
||||
}
|
||||
if (smb_buffer_oob(reparse_data_length - 12, print_name_offset,
|
||||
print_name_length)) {
|
||||
DBG_DEBUG("print_name (%"PRIu16"/%"PRIu16") does not fit in "
|
||||
"reparse_data_length (%"PRIu16")\n",
|
||||
print_name_offset,
|
||||
print_name_length,
|
||||
reparse_data_length - 12);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
*dst = (struct symlink_reparse_struct) {
|
||||
.unparsed_path_length = PULL_LE_U16(src, 6),
|
||||
.flags = PULL_LE_U32(src, 16),
|
||||
};
|
||||
|
||||
ok = convert_string_talloc(mem_ctx,
|
||||
CH_UTF16,
|
||||
CH_UNIX,
|
||||
src + 20 + substitute_name_offset,
|
||||
substitute_name_length,
|
||||
&dst->substitute_name,
|
||||
NULL);
|
||||
if (!ok) {
|
||||
int ret = errno;
|
||||
DBG_DEBUG("convert_string_talloc for substitute_name "
|
||||
"failed\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ok = convert_string_talloc(mem_ctx,
|
||||
CH_UTF16,
|
||||
CH_UNIX,
|
||||
src + 20 + print_name_offset,
|
||||
print_name_length,
|
||||
&dst->print_name,
|
||||
NULL);
|
||||
if (!ok) {
|
||||
int ret = errno;
|
||||
DBG_DEBUG("convert_string_talloc for print_name failed\n");
|
||||
TALLOC_FREE(dst->substitute_name);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -27,13 +27,6 @@
|
||||
#include <talloc.h>
|
||||
#include "lib/util/iov_buf.h"
|
||||
|
||||
struct symlink_reparse_struct {
|
||||
uint16_t unparsed_path_length; /* reserved for the reparse point */
|
||||
char *substitute_name;
|
||||
char *print_name;
|
||||
uint32_t flags;
|
||||
};
|
||||
|
||||
ssize_t reparse_buffer_marshall(
|
||||
uint32_t reparse_tag,
|
||||
uint16_t reserved,
|
||||
@ -50,9 +43,5 @@ bool symlink_reparse_buffer_marshall(
|
||||
TALLOC_CTX *mem_ctx,
|
||||
uint8_t **pdst,
|
||||
size_t *pdstlen);
|
||||
int symlink_reparse_buffer_parse(TALLOC_CTX *mem_ctx,
|
||||
struct symlink_reparse_struct *dst,
|
||||
const uint8_t *src,
|
||||
size_t srclen);
|
||||
|
||||
#endif
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "libcli/security/security.h"
|
||||
#include "../libcli/smb/smbXcli_base.h"
|
||||
#include "libcli/smb/reparse.h"
|
||||
#include "libcli/smb/reparse_symlink.h"
|
||||
|
||||
struct cli_symlink_state {
|
||||
struct tevent_context *ev;
|
||||
|
@ -51,6 +51,7 @@ c = libsmb.Conn("127.0.0.1",
|
||||
#include "python/modules.h"
|
||||
#include "libcli/smb/smbXcli_base.h"
|
||||
#include "libcli/smb/smb2_negotiate_context.h"
|
||||
#include "libcli/smb/reparse.h"
|
||||
#include "libcli/smb/reparse_symlink.h"
|
||||
#include "libsmb/libsmb.h"
|
||||
#include "libcli/security/security.h"
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include "../lib/util/memcache.h"
|
||||
#include "../librpc/gen_ndr/open_files.h"
|
||||
#include "lib/util/string_wrappers.h"
|
||||
#include "libcli/smb/reparse_symlink.h"
|
||||
#include "libcli/smb/reparse.h"
|
||||
|
||||
/*
|
||||
This module implements directory related functions for Samba.
|
||||
|
@ -30,7 +30,7 @@
|
||||
#include "smbd/smbd.h"
|
||||
#include "smbd/globals.h"
|
||||
#include "lib/util/memcache.h"
|
||||
#include "libcli/smb/reparse_symlink.h"
|
||||
#include "libcli/smb/reparse.h"
|
||||
|
||||
uint32_t ucf_flags_from_smb_request(struct smb_request *req)
|
||||
{
|
||||
|
@ -25,7 +25,7 @@
|
||||
#include "util_tdb.h"
|
||||
#include "lib/util/bitmap.h"
|
||||
#include "lib/util/strv.h"
|
||||
#include "libcli/smb/reparse_symlink.h"
|
||||
#include "libcli/smb/reparse.h"
|
||||
|
||||
#define FILE_HANDLE_OFFSET 0x1000
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user