diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2008-10-15 15:57:39 +0200 |
---|---|---|
committer | Jelmer Vernooij <jelmer@samba.org> | 2008-10-15 15:57:39 +0200 |
commit | 0c840bd8d2f650e805bd7d03c2b3fe530b431a4f (patch) | |
tree | 8cbf02b27578ea8a4fc382c35691778dd8539660 | |
parent | 760dfa76d9c912fd352e26be9be8a3d567f12375 (diff) | |
download | samba-0c840bd8d2f650e805bd7d03c2b3fe530b431a4f.tar.gz samba-0c840bd8d2f650e805bd7d03c2b3fe530b431a4f.tar.bz2 samba-0c840bd8d2f650e805bd7d03c2b3fe530b431a4f.zip |
Share xattr implementation.
-rw-r--r-- | librpc/idl/xattr.idl (renamed from source4/librpc/idl/xattr.idl) | 6 | ||||
-rw-r--r-- | source3/Makefile.in | 2 | ||||
-rw-r--r-- | source3/include/proto.h | 9 | ||||
-rw-r--r-- | source3/librpc/gen_ndr/ndr_xattr.c | 492 | ||||
-rw-r--r-- | source3/librpc/gen_ndr/ndr_xattr.h | 17 | ||||
-rw-r--r-- | source3/librpc/gen_ndr/xattr.h | 63 | ||||
-rw-r--r-- | source3/librpc/idl/xattr.idl | 54 | ||||
-rw-r--r-- | source3/modules/vfs_xattr_tdb.c | 64 |
8 files changed, 582 insertions, 125 deletions
diff --git a/source4/librpc/idl/xattr.idl b/librpc/idl/xattr.idl index ba0123aed0..c1af4791ae 100644 --- a/source4/librpc/idl/xattr.idl +++ b/librpc/idl/xattr.idl @@ -75,6 +75,12 @@ interface xattr [size_is(num_eas)] xattr_EA *eas; } xattr_DosEAs; + /* Slightly different version, used by the vfs_xattr_tdb module */ + typedef [public] struct { + uint32 num_eas; + xattr_EA eas[num_eas]; + } tdb_xattrs; + /* we store stream information in this xattr structure. Then the streams themselves are stored in user.DosStream.STREAMNAME or in external files, according diff --git a/source3/Makefile.in b/source3/Makefile.in index 46fa97b153..e3fee9a316 100644 --- a/source3/Makefile.in +++ b/source3/Makefile.in @@ -1204,7 +1204,7 @@ samba3-idl:: librpc/idl/initshutdown.idl librpc/idl/srvsvc.idl ../librpc/idl/svcctl.idl \ librpc/idl/eventlog.idl librpc/idl/wkssvc.idl librpc/idl/netlogon.idl \ ../librpc/idl/notify.idl ../librpc/idl/epmapper.idl librpc/idl/messaging.idl \ - librpc/idl/xattr.idl ../librpc/idl/misc.idl librpc/idl/samr.idl \ + ../librpc/idl/xattr.idl ../librpc/idl/misc.idl librpc/idl/samr.idl \ ../librpc/idl/security.idl ../librpc/idl/dssetup.idl librpc/idl/krb5pac.idl \ ../librpc/idl/ntsvcs.idl librpc/idl/libnetapi.idl librpc/idl/drsuapi.idl \ librpc/idl/drsblobs.idl librpc/idl/nbt.idl diff --git a/source3/include/proto.h b/source3/include/proto.h index 8f2c813954..180ae1aae5 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -3677,15 +3677,6 @@ _PUBLIC_ void ndr_print_wkssvc_NetrRemoveAlternateComputerName(struct ndr_print _PUBLIC_ void ndr_print_wkssvc_NetrSetPrimaryComputername(struct ndr_print *ndr, const char *name, int flags, const struct wkssvc_NetrSetPrimaryComputername *r); _PUBLIC_ void ndr_print_wkssvc_NetrEnumerateComputerNames(struct ndr_print *ndr, const char *name, int flags, const struct wkssvc_NetrEnumerateComputerNames *r); -/* The following definitions come from librpc/gen_ndr/ndr_xattr.c */ - -_PUBLIC_ enum ndr_err_code ndr_push_tdb_xattr(struct ndr_push *ndr, int ndr_flags, const struct tdb_xattr *r); -_PUBLIC_ enum ndr_err_code ndr_pull_tdb_xattr(struct ndr_pull *ndr, int ndr_flags, struct tdb_xattr *r); -_PUBLIC_ void ndr_print_tdb_xattr(struct ndr_print *ndr, const char *name, const struct tdb_xattr *r); -_PUBLIC_ enum ndr_err_code ndr_push_tdb_xattrs(struct ndr_push *ndr, int ndr_flags, const struct tdb_xattrs *r); -_PUBLIC_ enum ndr_err_code ndr_pull_tdb_xattrs(struct ndr_pull *ndr, int ndr_flags, struct tdb_xattrs *r); -_PUBLIC_ void ndr_print_tdb_xattrs(struct ndr_print *ndr, const char *name, const struct tdb_xattrs *r); - /* The following definitions come from librpc/gen_ndr/srv_dfs.c */ void netdfs_get_pipe_fns(struct api_struct **fns, int *n_fns); diff --git a/source3/librpc/gen_ndr/ndr_xattr.c b/source3/librpc/gen_ndr/ndr_xattr.c index 92369835cf..0e9dda9f47 100644 --- a/source3/librpc/gen_ndr/ndr_xattr.c +++ b/source3/librpc/gen_ndr/ndr_xattr.c @@ -3,7 +3,244 @@ #include "includes.h" #include "librpc/gen_ndr/ndr_xattr.h" -_PUBLIC_ enum ndr_err_code ndr_push_tdb_xattr(struct ndr_push *ndr, int ndr_flags, const struct tdb_xattr *r) +#include "librpc/gen_ndr/ndr_security.h" +static enum ndr_err_code ndr_push_xattr_DosInfo1(struct ndr_push *ndr, int ndr_flags, const struct xattr_DosInfo1 *r) +{ + if (ndr_flags & NDR_SCALARS) { + NDR_CHECK(ndr_push_align(ndr, 4)); + NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, r->attrib)); + NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, r->ea_size)); + NDR_CHECK(ndr_push_udlong(ndr, NDR_SCALARS, r->size)); + NDR_CHECK(ndr_push_udlong(ndr, NDR_SCALARS, r->alloc_size)); + NDR_CHECK(ndr_push_NTTIME(ndr, NDR_SCALARS, r->create_time)); + NDR_CHECK(ndr_push_NTTIME(ndr, NDR_SCALARS, r->change_time)); + } + if (ndr_flags & NDR_BUFFERS) { + } + return NDR_ERR_SUCCESS; +} + +static enum ndr_err_code ndr_pull_xattr_DosInfo1(struct ndr_pull *ndr, int ndr_flags, struct xattr_DosInfo1 *r) +{ + if (ndr_flags & NDR_SCALARS) { + NDR_CHECK(ndr_pull_align(ndr, 4)); + NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->attrib)); + NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->ea_size)); + NDR_CHECK(ndr_pull_udlong(ndr, NDR_SCALARS, &r->size)); + NDR_CHECK(ndr_pull_udlong(ndr, NDR_SCALARS, &r->alloc_size)); + NDR_CHECK(ndr_pull_NTTIME(ndr, NDR_SCALARS, &r->create_time)); + NDR_CHECK(ndr_pull_NTTIME(ndr, NDR_SCALARS, &r->change_time)); + } + if (ndr_flags & NDR_BUFFERS) { + } + return NDR_ERR_SUCCESS; +} + +_PUBLIC_ void ndr_print_xattr_DosInfo1(struct ndr_print *ndr, const char *name, const struct xattr_DosInfo1 *r) +{ + ndr_print_struct(ndr, name, "xattr_DosInfo1"); + ndr->depth++; + ndr_print_uint32(ndr, "attrib", r->attrib); + ndr_print_uint32(ndr, "ea_size", r->ea_size); + ndr_print_udlong(ndr, "size", r->size); + ndr_print_udlong(ndr, "alloc_size", r->alloc_size); + ndr_print_NTTIME(ndr, "create_time", r->create_time); + ndr_print_NTTIME(ndr, "change_time", r->change_time); + ndr->depth--; +} + +static enum ndr_err_code ndr_push_xattr_DosInfo2Old(struct ndr_push *ndr, int ndr_flags, const struct xattr_DosInfo2Old *r) +{ + if (ndr_flags & NDR_SCALARS) { + NDR_CHECK(ndr_push_align(ndr, 4)); + NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, r->flags)); + NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, r->attrib)); + NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, r->ea_size)); + NDR_CHECK(ndr_push_udlong(ndr, NDR_SCALARS, r->size)); + NDR_CHECK(ndr_push_udlong(ndr, NDR_SCALARS, r->alloc_size)); + NDR_CHECK(ndr_push_NTTIME(ndr, NDR_SCALARS, r->create_time)); + NDR_CHECK(ndr_push_NTTIME(ndr, NDR_SCALARS, r->change_time)); + NDR_CHECK(ndr_push_NTTIME(ndr, NDR_SCALARS, r->write_time)); + { + uint32_t _flags_save_string = ndr->flags; + ndr_set_flags(&ndr->flags, LIBNDR_FLAG_STR_UTF8|LIBNDR_FLAG_STR_NULLTERM); + NDR_CHECK(ndr_push_string(ndr, NDR_SCALARS, r->name)); + ndr->flags = _flags_save_string; + } + } + if (ndr_flags & NDR_BUFFERS) { + } + return NDR_ERR_SUCCESS; +} + +static enum ndr_err_code ndr_pull_xattr_DosInfo2Old(struct ndr_pull *ndr, int ndr_flags, struct xattr_DosInfo2Old *r) +{ + if (ndr_flags & NDR_SCALARS) { + NDR_CHECK(ndr_pull_align(ndr, 4)); + NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->flags)); + NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->attrib)); + NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->ea_size)); + NDR_CHECK(ndr_pull_udlong(ndr, NDR_SCALARS, &r->size)); + NDR_CHECK(ndr_pull_udlong(ndr, NDR_SCALARS, &r->alloc_size)); + NDR_CHECK(ndr_pull_NTTIME(ndr, NDR_SCALARS, &r->create_time)); + NDR_CHECK(ndr_pull_NTTIME(ndr, NDR_SCALARS, &r->change_time)); + NDR_CHECK(ndr_pull_NTTIME(ndr, NDR_SCALARS, &r->write_time)); + { + uint32_t _flags_save_string = ndr->flags; + ndr_set_flags(&ndr->flags, LIBNDR_FLAG_STR_UTF8|LIBNDR_FLAG_STR_NULLTERM); + NDR_CHECK(ndr_pull_string(ndr, NDR_SCALARS, &r->name)); + ndr->flags = _flags_save_string; + } + } + if (ndr_flags & NDR_BUFFERS) { + } + return NDR_ERR_SUCCESS; +} + +_PUBLIC_ void ndr_print_xattr_DosInfo2Old(struct ndr_print *ndr, const char *name, const struct xattr_DosInfo2Old *r) +{ + ndr_print_struct(ndr, name, "xattr_DosInfo2Old"); + ndr->depth++; + ndr_print_uint32(ndr, "flags", r->flags); + ndr_print_uint32(ndr, "attrib", r->attrib); + ndr_print_uint32(ndr, "ea_size", r->ea_size); + ndr_print_udlong(ndr, "size", r->size); + ndr_print_udlong(ndr, "alloc_size", r->alloc_size); + ndr_print_NTTIME(ndr, "create_time", r->create_time); + ndr_print_NTTIME(ndr, "change_time", r->change_time); + ndr_print_NTTIME(ndr, "write_time", r->write_time); + ndr_print_string(ndr, "name", r->name); + ndr->depth--; +} + +static enum ndr_err_code ndr_push_xattr_DosInfo(struct ndr_push *ndr, int ndr_flags, const union xattr_DosInfo *r) +{ + if (ndr_flags & NDR_SCALARS) { + int level = ndr_push_get_switch_value(ndr, r); + NDR_CHECK(ndr_push_uint16(ndr, NDR_SCALARS, level)); + switch (level) { + case 1: { + NDR_CHECK(ndr_push_xattr_DosInfo1(ndr, NDR_SCALARS, &r->info1)); + break; } + + case 2: { + NDR_CHECK(ndr_push_xattr_DosInfo2Old(ndr, NDR_SCALARS, &r->oldinfo2)); + break; } + + default: + return ndr_push_error(ndr, NDR_ERR_BAD_SWITCH, "Bad switch value %u", level); + } + } + if (ndr_flags & NDR_BUFFERS) { + int level = ndr_push_get_switch_value(ndr, r); + switch (level) { + case 1: + break; + + case 2: + break; + + default: + return ndr_push_error(ndr, NDR_ERR_BAD_SWITCH, "Bad switch value %u", level); + } + } + return NDR_ERR_SUCCESS; +} + +static enum ndr_err_code ndr_pull_xattr_DosInfo(struct ndr_pull *ndr, int ndr_flags, union xattr_DosInfo *r) +{ + int level; + uint16_t _level; + level = ndr_pull_get_switch_value(ndr, r); + if (ndr_flags & NDR_SCALARS) { + NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &_level)); + if (_level != level) { + return ndr_pull_error(ndr, NDR_ERR_BAD_SWITCH, "Bad switch value %u for r", _level); + } + switch (level) { + case 1: { + NDR_CHECK(ndr_pull_xattr_DosInfo1(ndr, NDR_SCALARS, &r->info1)); + break; } + + case 2: { + NDR_CHECK(ndr_pull_xattr_DosInfo2Old(ndr, NDR_SCALARS, &r->oldinfo2)); + break; } + + default: + return ndr_pull_error(ndr, NDR_ERR_BAD_SWITCH, "Bad switch value %u", level); + } + } + if (ndr_flags & NDR_BUFFERS) { + switch (level) { + case 1: + break; + + case 2: + break; + + default: + return ndr_pull_error(ndr, NDR_ERR_BAD_SWITCH, "Bad switch value %u", level); + } + } + return NDR_ERR_SUCCESS; +} + +_PUBLIC_ void ndr_print_xattr_DosInfo(struct ndr_print *ndr, const char *name, const union xattr_DosInfo *r) +{ + int level; + level = ndr_print_get_switch_value(ndr, r); + ndr_print_union(ndr, name, level, "xattr_DosInfo"); + switch (level) { + case 1: + ndr_print_xattr_DosInfo1(ndr, "info1", &r->info1); + break; + + case 2: + ndr_print_xattr_DosInfo2Old(ndr, "oldinfo2", &r->oldinfo2); + break; + + default: + ndr_print_bad_level(ndr, name, level); + } +} + +_PUBLIC_ enum ndr_err_code ndr_push_xattr_DosAttrib(struct ndr_push *ndr, int ndr_flags, const struct xattr_DosAttrib *r) +{ + if (ndr_flags & NDR_SCALARS) { + NDR_CHECK(ndr_push_align(ndr, 4)); + NDR_CHECK(ndr_push_uint16(ndr, NDR_SCALARS, r->version)); + NDR_CHECK(ndr_push_set_switch_value(ndr, &r->info, r->version)); + NDR_CHECK(ndr_push_xattr_DosInfo(ndr, NDR_SCALARS, &r->info)); + } + if (ndr_flags & NDR_BUFFERS) { + } + return NDR_ERR_SUCCESS; +} + +_PUBLIC_ enum ndr_err_code ndr_pull_xattr_DosAttrib(struct ndr_pull *ndr, int ndr_flags, struct xattr_DosAttrib *r) +{ + if (ndr_flags & NDR_SCALARS) { + NDR_CHECK(ndr_pull_align(ndr, 4)); + NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &r->version)); + NDR_CHECK(ndr_pull_set_switch_value(ndr, &r->info, r->version)); + NDR_CHECK(ndr_pull_xattr_DosInfo(ndr, NDR_SCALARS, &r->info)); + } + if (ndr_flags & NDR_BUFFERS) { + } + return NDR_ERR_SUCCESS; +} + +_PUBLIC_ void ndr_print_xattr_DosAttrib(struct ndr_print *ndr, const char *name, const struct xattr_DosAttrib *r) +{ + ndr_print_struct(ndr, name, "xattr_DosAttrib"); + ndr->depth++; + ndr_print_uint16(ndr, "version", r->version); + ndr_print_set_switch_value(ndr, &r->info, r->version); + ndr_print_xattr_DosInfo(ndr, "info", &r->info); + ndr->depth--; +} + +static enum ndr_err_code ndr_push_xattr_EA(struct ndr_push *ndr, int ndr_flags, const struct xattr_EA *r) { if (ndr_flags & NDR_SCALARS) { NDR_CHECK(ndr_push_align(ndr, 4)); @@ -20,7 +257,7 @@ _PUBLIC_ enum ndr_err_code ndr_push_tdb_xattr(struct ndr_push *ndr, int ndr_flag return NDR_ERR_SUCCESS; } -_PUBLIC_ enum ndr_err_code ndr_pull_tdb_xattr(struct ndr_pull *ndr, int ndr_flags, struct tdb_xattr *r) +static enum ndr_err_code ndr_pull_xattr_EA(struct ndr_pull *ndr, int ndr_flags, struct xattr_EA *r) { if (ndr_flags & NDR_SCALARS) { NDR_CHECK(ndr_pull_align(ndr, 4)); @@ -37,23 +274,103 @@ _PUBLIC_ enum ndr_err_code ndr_pull_tdb_xattr(struct ndr_pull *ndr, int ndr_flag return NDR_ERR_SUCCESS; } -_PUBLIC_ void ndr_print_tdb_xattr(struct ndr_print *ndr, const char *name, const struct tdb_xattr *r) +_PUBLIC_ void ndr_print_xattr_EA(struct ndr_print *ndr, const char *name, const struct xattr_EA *r) { - ndr_print_struct(ndr, name, "tdb_xattr"); + ndr_print_struct(ndr, name, "xattr_EA"); ndr->depth++; ndr_print_string(ndr, "name", r->name); ndr_print_DATA_BLOB(ndr, "value", r->value); ndr->depth--; } +_PUBLIC_ enum ndr_err_code ndr_push_xattr_DosEAs(struct ndr_push *ndr, int ndr_flags, const struct xattr_DosEAs *r) +{ + uint32_t cntr_eas_1; + if (ndr_flags & NDR_SCALARS) { + NDR_CHECK(ndr_push_align(ndr, 4)); + NDR_CHECK(ndr_push_uint16(ndr, NDR_SCALARS, r->num_eas)); + NDR_CHECK(ndr_push_unique_ptr(ndr, r->eas)); + } + if (ndr_flags & NDR_BUFFERS) { + if (r->eas) { + NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, r->num_eas)); + for (cntr_eas_1 = 0; cntr_eas_1 < r->num_eas; cntr_eas_1++) { + NDR_CHECK(ndr_push_xattr_EA(ndr, NDR_SCALARS, &r->eas[cntr_eas_1])); + } + } + } + return NDR_ERR_SUCCESS; +} + +_PUBLIC_ enum ndr_err_code ndr_pull_xattr_DosEAs(struct ndr_pull *ndr, int ndr_flags, struct xattr_DosEAs *r) +{ + uint32_t _ptr_eas; + uint32_t cntr_eas_1; + TALLOC_CTX *_mem_save_eas_0; + TALLOC_CTX *_mem_save_eas_1; + if (ndr_flags & NDR_SCALARS) { + NDR_CHECK(ndr_pull_align(ndr, 4)); + NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &r->num_eas)); + NDR_CHECK(ndr_pull_generic_ptr(ndr, &_ptr_eas)); + if (_ptr_eas) { + NDR_PULL_ALLOC(ndr, r->eas); + } else { + r->eas = NULL; + } + } + if (ndr_flags & NDR_BUFFERS) { + if (r->eas) { + _mem_save_eas_0 = NDR_PULL_GET_MEM_CTX(ndr); + NDR_PULL_SET_MEM_CTX(ndr, r->eas, 0); + NDR_CHECK(ndr_pull_array_size(ndr, &r->eas)); + NDR_PULL_ALLOC_N(ndr, r->eas, ndr_get_array_size(ndr, &r->eas)); + _mem_save_eas_1 = NDR_PULL_GET_MEM_CTX(ndr); + NDR_PULL_SET_MEM_CTX(ndr, r->eas, 0); + for (cntr_eas_1 = 0; cntr_eas_1 < r->num_eas; cntr_eas_1++) { + NDR_CHECK(ndr_pull_xattr_EA(ndr, NDR_SCALARS, &r->eas[cntr_eas_1])); + } + NDR_PULL_SET_MEM_CTX(ndr, _mem_save_eas_1, 0); + NDR_PULL_SET_MEM_CTX(ndr, _mem_save_eas_0, 0); + } + if (r->eas) { + NDR_CHECK(ndr_check_array_size(ndr, (void*)&r->eas, r->num_eas)); + } + } + return NDR_ERR_SUCCESS; +} + +_PUBLIC_ void ndr_print_xattr_DosEAs(struct ndr_print *ndr, const char *name, const struct xattr_DosEAs *r) +{ + uint32_t cntr_eas_1; + ndr_print_struct(ndr, name, "xattr_DosEAs"); + ndr->depth++; + ndr_print_uint16(ndr, "num_eas", r->num_eas); + ndr_print_ptr(ndr, "eas", r->eas); + ndr->depth++; + if (r->eas) { + ndr->print(ndr, "%s: ARRAY(%d)", "eas", (int)r->num_eas); + ndr->depth++; + for (cntr_eas_1=0;cntr_eas_1<r->num_eas;cntr_eas_1++) { + char *idx_1=NULL; + if (asprintf(&idx_1, "[%d]", cntr_eas_1) != -1) { + ndr_print_xattr_EA(ndr, "eas", &r->eas[cntr_eas_1]); + free(idx_1); + } + } + ndr->depth--; + } + ndr->depth--; + ndr->depth--; +} + _PUBLIC_ enum ndr_err_code ndr_push_tdb_xattrs(struct ndr_push *ndr, int ndr_flags, const struct tdb_xattrs *r) { - uint32_t cntr_xattrs_0; + uint32_t cntr_eas_0; if (ndr_flags & NDR_SCALARS) { NDR_CHECK(ndr_push_align(ndr, 4)); - NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, r->num_xattrs)); - for (cntr_xattrs_0 = 0; cntr_xattrs_0 < r->num_xattrs; cntr_xattrs_0++) { - NDR_CHECK(ndr_push_tdb_xattr(ndr, NDR_SCALARS, &r->xattrs[cntr_xattrs_0])); + NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, r->num_eas)); + for (cntr_eas_0 = 0; cntr_eas_0 < r->num_eas; cntr_eas_0++) { + NDR_CHECK(ndr_push_xattr_EA(ndr, NDR_SCALARS, &r->eas[cntr_eas_0])); } } if (ndr_flags & NDR_BUFFERS) { @@ -63,18 +380,18 @@ _PUBLIC_ enum ndr_err_code ndr_push_tdb_xattrs(struct ndr_push *ndr, int ndr_fla _PUBLIC_ enum ndr_err_code ndr_pull_tdb_xattrs(struct ndr_pull *ndr, int ndr_flags, struct tdb_xattrs *r) { - uint32_t cntr_xattrs_0; - TALLOC_CTX *_mem_save_xattrs_0; + uint32_t cntr_eas_0; + TALLOC_CTX *_mem_save_eas_0; if (ndr_flags & NDR_SCALARS) { NDR_CHECK(ndr_pull_align(ndr, 4)); - NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->num_xattrs)); - NDR_PULL_ALLOC_N(ndr, r->xattrs, r->num_xattrs); - _mem_save_xattrs_0 = NDR_PULL_GET_MEM_CTX(ndr); - NDR_PULL_SET_MEM_CTX(ndr, r->xattrs, 0); - for (cntr_xattrs_0 = 0; cntr_xattrs_0 < r->num_xattrs; cntr_xattrs_0++) { - NDR_CHECK(ndr_pull_tdb_xattr(ndr, NDR_SCALARS, &r->xattrs[cntr_xattrs_0])); + NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->num_eas)); + NDR_PULL_ALLOC_N(ndr, r->eas, r->num_eas); + _mem_save_eas_0 = NDR_PULL_GET_MEM_CTX(ndr); + NDR_PULL_SET_MEM_CTX(ndr, r->eas, 0); + for (cntr_eas_0 = 0; cntr_eas_0 < r->num_eas; cntr_eas_0++) { + NDR_CHECK(ndr_pull_xattr_EA(ndr, NDR_SCALARS, &r->eas[cntr_eas_0])); } - NDR_PULL_SET_MEM_CTX(ndr, _mem_save_xattrs_0, 0); + NDR_PULL_SET_MEM_CTX(ndr, _mem_save_eas_0, 0); } if (ndr_flags & NDR_BUFFERS) { } @@ -83,16 +400,16 @@ _PUBLIC_ enum ndr_err_code ndr_pull_tdb_xattrs(struct ndr_pull *ndr, int ndr_fla _PUBLIC_ void ndr_print_tdb_xattrs(struct ndr_print *ndr, const char *name, const struct tdb_xattrs *r) { - uint32_t cntr_xattrs_0; + uint32_t cntr_eas_0; ndr_print_struct(ndr, name, "tdb_xattrs"); ndr->depth++; - ndr_print_uint32(ndr, "num_xattrs", r->num_xattrs); - ndr->print(ndr, "%s: ARRAY(%d)", "xattrs", (int)r->num_xattrs); + ndr_print_uint32(ndr, "num_eas", r->num_eas); + ndr->print(ndr, "%s: ARRAY(%d)", "eas", (int)r->num_eas); ndr->depth++; - for (cntr_xattrs_0=0;cntr_xattrs_0<r->num_xattrs;cntr_xattrs_0++) { + for (cntr_eas_0=0;cntr_eas_0<r->num_eas;cntr_eas_0++) { char *idx_0=NULL; - if (asprintf(&idx_0, "[%d]", cntr_xattrs_0) != -1) { - ndr_print_tdb_xattr(ndr, "xattrs", &r->xattrs[cntr_xattrs_0]); + if (asprintf(&idx_0, "[%d]", cntr_eas_0) != -1) { + ndr_print_xattr_EA(ndr, "eas", &r->eas[cntr_eas_0]); free(idx_0); } } @@ -100,6 +417,135 @@ _PUBLIC_ void ndr_print_tdb_xattrs(struct ndr_print *ndr, const char *name, cons ndr->depth--; } +static enum ndr_err_code ndr_push_xattr_DosStream(struct ndr_push *ndr, int ndr_flags, const struct xattr_DosStream *r) +{ + if (ndr_flags & NDR_SCALARS) { + NDR_CHECK(ndr_push_align(ndr, 4)); + NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, r->flags)); + NDR_CHECK(ndr_push_udlong(ndr, NDR_SCALARS, r->size)); + NDR_CHECK(ndr_push_udlong(ndr, NDR_SCALARS, r->alloc_size)); + { + uint32_t _flags_save_string = ndr->flags; + ndr_set_flags(&ndr->flags, LIBNDR_FLAG_STR_UTF8|LIBNDR_FLAG_STR_NULLTERM); + NDR_CHECK(ndr_push_string(ndr, NDR_SCALARS, r->name)); + ndr->flags = _flags_save_string; + } + } + if (ndr_flags & NDR_BUFFERS) { + } + return NDR_ERR_SUCCESS; +} + +static enum ndr_err_code ndr_pull_xattr_DosStream(struct ndr_pull *ndr, int ndr_flags, struct xattr_DosStream *r) +{ + if (ndr_flags & NDR_SCALARS) { + NDR_CHECK(ndr_pull_align(ndr, 4)); + NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->flags)); + NDR_CHECK(ndr_pull_udlong(ndr, NDR_SCALARS, &r->size)); + NDR_CHECK(ndr_pull_udlong(ndr, NDR_SCALARS, &r->alloc_size)); + { + uint32_t _flags_save_string = ndr->flags; + ndr_set_flags(&ndr->flags, LIBNDR_FLAG_STR_UTF8|LIBNDR_FLAG_STR_NULLTERM); + NDR_CHECK(ndr_pull_string(ndr, NDR_SCALARS, &r->name)); + ndr->flags = _flags_save_string; + } + } + if (ndr_flags & NDR_BUFFERS) { + } + return NDR_ERR_SUCCESS; +} + +_PUBLIC_ void ndr_print_xattr_DosStream(struct ndr_print *ndr, const char *name, const struct xattr_DosStream *r) +{ + ndr_print_struct(ndr, name, "xattr_DosStream"); + ndr->depth++; + ndr_print_uint32(ndr, "flags", r->flags); + ndr_print_udlong(ndr, "size", r->size); + ndr_print_udlong(ndr, "alloc_size", r->alloc_size); + ndr_print_string(ndr, "name", r->name); + ndr->depth--; +} + +_PUBLIC_ enum ndr_err_code ndr_push_xattr_DosStreams(struct ndr_push *ndr, int ndr_flags, const struct xattr_DosStreams *r) +{ + uint32_t cntr_streams_1; + if (ndr_flags & NDR_SCALARS) { + NDR_CHECK(ndr_push_align(ndr, 4)); + NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, r->num_streams)); + NDR_CHECK(ndr_push_unique_ptr(ndr, r->streams)); + } + if (ndr_flags & NDR_BUFFERS) { + if (r->streams) { + NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, r->num_streams)); + for (cntr_streams_1 = 0; cntr_streams_1 < r->num_streams; cntr_streams_1++) { + NDR_CHECK(ndr_push_xattr_DosStream(ndr, NDR_SCALARS, &r->streams[cntr_streams_1])); + } + } + } + return NDR_ERR_SUCCESS; +} + +_PUBLIC_ enum ndr_err_code ndr_pull_xattr_DosStreams(struct ndr_pull *ndr, int ndr_flags, struct xattr_DosStreams *r) +{ + uint32_t _ptr_streams; + uint32_t cntr_streams_1; + TALLOC_CTX *_mem_save_streams_0; + TALLOC_CTX *_mem_save_streams_1; + if (ndr_flags & NDR_SCALARS) { + NDR_CHECK(ndr_pull_align(ndr, 4)); + NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->num_streams)); + NDR_CHECK(ndr_pull_generic_ptr(ndr, &_ptr_streams)); + if (_ptr_streams) { + NDR_PULL_ALLOC(ndr, r->streams); + } else { + r->streams = NULL; + } + } + if (ndr_flags & NDR_BUFFERS) { + if (r->streams) { + _mem_save_streams_0 = NDR_PULL_GET_MEM_CTX(ndr); + NDR_PULL_SET_MEM_CTX(ndr, r->streams, 0); + NDR_CHECK(ndr_pull_array_size(ndr, &r->streams)); + NDR_PULL_ALLOC_N(ndr, r->streams, ndr_get_array_size(ndr, &r->streams)); + _mem_save_streams_1 = NDR_PULL_GET_MEM_CTX(ndr); + NDR_PULL_SET_MEM_CTX(ndr, r->streams, 0); + for (cntr_streams_1 = 0; cntr_streams_1 < r->num_streams; cntr_streams_1++) { + NDR_CHECK(ndr_pull_xattr_DosStream(ndr, NDR_SCALARS, &r->streams[cntr_streams_1])); + } + NDR_PULL_SET_MEM_CTX(ndr, _mem_save_streams_1, 0); + NDR_PULL_SET_MEM_CTX(ndr, _mem_save_streams_0, 0); + } + if (r->streams) { + NDR_CHECK(ndr_check_array_size(ndr, (void*)&r->streams, r->num_streams)); + } + } + return NDR_ERR_SUCCESS; +} + +_PUBLIC_ void ndr_print_xattr_DosStreams(struct ndr_print *ndr, const char *name, const struct xattr_DosStreams *r) +{ + uint32_t cntr_streams_1; + ndr_print_struct(ndr, name, "xattr_DosStreams"); + ndr->depth++; + ndr_print_uint32(ndr, "num_streams", r->num_streams); + ndr_print_ptr(ndr, "streams", r->streams); + ndr->depth++; + if (r->streams) { + ndr->print(ndr, "%s: ARRAY(%d)", "streams", (int)r->num_streams); + ndr->depth++; + for (cntr_streams_1=0;cntr_streams_1<r->num_streams;cntr_streams_1++) { + char *idx_1=NULL; + if (asprintf(&idx_1, "[%d]", cntr_streams_1) != -1) { + ndr_print_xattr_DosStream(ndr, "streams", &r->streams[cntr_streams_1]); + free(idx_1); + } + } + ndr->depth--; + } + ndr->depth--; + ndr->depth--; +} + _PUBLIC_ enum ndr_err_code ndr_push_security_descriptor_timestamp(struct ndr_push *ndr, int ndr_flags, const struct security_descriptor_timestamp *r) { if (ndr_flags & NDR_SCALARS) { diff --git a/source3/librpc/gen_ndr/ndr_xattr.h b/source3/librpc/gen_ndr/ndr_xattr.h index 21c5ae03b5..38701b1aca 100644 --- a/source3/librpc/gen_ndr/ndr_xattr.h +++ b/source3/librpc/gen_ndr/ndr_xattr.h @@ -7,12 +7,23 @@ #define _HEADER_NDR_xattr #define NDR_XATTR_CALL_COUNT (0) -enum ndr_err_code ndr_push_tdb_xattr(struct ndr_push *ndr, int ndr_flags, const struct tdb_xattr *r); -enum ndr_err_code ndr_pull_tdb_xattr(struct ndr_pull *ndr, int ndr_flags, struct tdb_xattr *r); -void ndr_print_tdb_xattr(struct ndr_print *ndr, const char *name, const struct tdb_xattr *r); +void ndr_print_xattr_DosInfo1(struct ndr_print *ndr, const char *name, const struct xattr_DosInfo1 *r); +void ndr_print_xattr_DosInfo2Old(struct ndr_print *ndr, const char *name, const struct xattr_DosInfo2Old *r); +void ndr_print_xattr_DosInfo(struct ndr_print *ndr, const char *name, const union xattr_DosInfo *r); +enum ndr_err_code ndr_push_xattr_DosAttrib(struct ndr_push *ndr, int ndr_flags, const struct xattr_DosAttrib *r); +enum ndr_err_code ndr_pull_xattr_DosAttrib(struct ndr_pull *ndr, int ndr_flags, struct xattr_DosAttrib *r); +void ndr_print_xattr_DosAttrib(struct ndr_print *ndr, const char *name, const struct xattr_DosAttrib *r); +void ndr_print_xattr_EA(struct ndr_print *ndr, const char *name, const struct xattr_EA *r); +enum ndr_err_code ndr_push_xattr_DosEAs(struct ndr_push *ndr, int ndr_flags, const struct xattr_DosEAs *r); +enum ndr_err_code ndr_pull_xattr_DosEAs(struct ndr_pull *ndr, int ndr_flags, struct xattr_DosEAs *r); +void ndr_print_xattr_DosEAs(struct ndr_print *ndr, const char *name, const struct xattr_DosEAs *r); enum ndr_err_code ndr_push_tdb_xattrs(struct ndr_push *ndr, int ndr_flags, const struct tdb_xattrs *r); enum ndr_err_code ndr_pull_tdb_xattrs(struct ndr_pull *ndr, int ndr_flags, struct tdb_xattrs *r); void ndr_print_tdb_xattrs(struct ndr_print *ndr, const char *name, const struct tdb_xattrs *r); +void ndr_print_xattr_DosStream(struct ndr_print *ndr, const char *name, const struct xattr_DosStream *r); +enum ndr_err_code ndr_push_xattr_DosStreams(struct ndr_push *ndr, int ndr_flags, const struct xattr_DosStreams *r); +enum ndr_err_code ndr_pull_xattr_DosStreams(struct ndr_pull *ndr, int ndr_flags, struct xattr_DosStreams *r); +void ndr_print_xattr_DosStreams(struct ndr_print *ndr, const char *name, const struct xattr_DosStreams *r); enum ndr_err_code ndr_push_security_descriptor_timestamp(struct ndr_push *ndr, int ndr_flags, const struct security_descriptor_timestamp *r); enum ndr_err_code ndr_pull_security_descriptor_timestamp(struct ndr_pull *ndr, int ndr_flags, struct security_descriptor_timestamp *r); void ndr_print_security_descriptor_timestamp(struct ndr_print *ndr, const char *name, const struct security_descriptor_timestamp *r); diff --git a/source3/librpc/gen_ndr/xattr.h b/source3/librpc/gen_ndr/xattr.h index b0b9db99c1..1d8da3f5e2 100644 --- a/source3/librpc/gen_ndr/xattr.h +++ b/source3/librpc/gen_ndr/xattr.h @@ -2,18 +2,75 @@ #include <stdint.h> +#include "librpc/gen_ndr/security.h" #ifndef _HEADER_xattr #define _HEADER_xattr +#define XATTR_DOSATTRIB_NAME ( "user.DosAttrib" ) +#define XATTR_DOSATTRIB_ESTIMATED_SIZE ( 64 ) +#define XATTR_DOSEAS_NAME ( "user.DosEAs" ) +#define XATTR_DOSSTREAMS_NAME ( "user.DosStreams" ) +#define XATTR_STREAM_FLAG_INTERNAL ( 0x00000001 ) +#define XATTR_DOSSTREAM_PREFIX ( "user.DosStream." ) +#define XATTR_MAX_STREAM_SIZE ( 0x4000 ) +#define XATTR_MAX_STREAM_SIZE_TDB ( 0x100000 ) #define XATTR_NTACL_NAME ( "security.NTACL" ) -struct tdb_xattr { +struct xattr_DosInfo1 { + uint32_t attrib; + uint32_t ea_size; + uint64_t size; + uint64_t alloc_size; + NTTIME create_time; + NTTIME change_time; +}; + +struct xattr_DosInfo2Old { + uint32_t flags; + uint32_t attrib; + uint32_t ea_size; + uint64_t size; + uint64_t alloc_size; + NTTIME create_time; + NTTIME change_time; + NTTIME write_time; + const char * name;/* [flag(LIBNDR_FLAG_STR_UTF8|LIBNDR_FLAG_STR_NULLTERM)] */ +}; + +union xattr_DosInfo { + struct xattr_DosInfo1 info1;/* [case] */ + struct xattr_DosInfo2Old oldinfo2;/* [case(2)] */ +}/* [switch_type(uint16)] */; + +struct xattr_DosAttrib { + uint16_t version; + union xattr_DosInfo info;/* [switch_is(version)] */ +}/* [public] */; + +struct xattr_EA { const char * name;/* [flag(LIBNDR_FLAG_STR_UTF8|LIBNDR_FLAG_STR_NULLTERM)] */ DATA_BLOB value; +}; + +struct xattr_DosEAs { + uint16_t num_eas; + struct xattr_EA *eas;/* [unique,size_is(num_eas)] */ }/* [public] */; struct tdb_xattrs { - uint32_t num_xattrs; - struct tdb_xattr *xattrs; + uint32_t num_eas; + struct xattr_EA *eas; +}/* [public] */; + +struct xattr_DosStream { + uint32_t flags; + uint64_t size; + uint64_t alloc_size; + const char * name;/* [flag(LIBNDR_FLAG_STR_UTF8|LIBNDR_FLAG_STR_NULLTERM)] */ +}; + +struct xattr_DosStreams { + uint32_t num_streams; + struct xattr_DosStream *streams;/* [unique,size_is(num_streams)] */ }/* [public] */; struct security_descriptor_timestamp { diff --git a/source3/librpc/idl/xattr.idl b/source3/librpc/idl/xattr.idl deleted file mode 100644 index 23af2df404..0000000000 --- a/source3/librpc/idl/xattr.idl +++ /dev/null @@ -1,54 +0,0 @@ -#include "idl_types.h" - -/* - IDL structures for xattrs -*/ - -[ - pointer_default(unique) -] -interface xattr -{ - /* xattrs for file systems that don't have any */ - - typedef [public] struct { - utf8string name; - DATA_BLOB value; - } tdb_xattr; - - typedef [public] struct { - uint32 num_xattrs; - tdb_xattr xattrs[num_xattrs]; - } tdb_xattrs; - - /* we store the NT ACL a NTACL xattr. It is versioned so we - can later add other acl attribs (such as posix acl mapping) - - we put this xattr in the security namespace to ensure that - only trusted users can write to the ACL - - stored in "security.NTACL" - - Version 1. raw SD stored as Samba4 does it. - Version 2. raw SD + last changed timestamp so we - can discard if this doesn't match the POSIX st_ctime. - */ - - const char *XATTR_NTACL_NAME = "security.NTACL"; - - typedef [public] struct { - security_descriptor *sd; - NTTIME last_changed; - } security_descriptor_timestamp; - - typedef [switch_type(uint16)] union { - [case(1)] security_descriptor *sd; - [case(2)] security_descriptor_timestamp *sd_ts; - } xattr_NTACL_Info; - - typedef [public] struct { - uint16 version; - [switch_is(version)] xattr_NTACL_Info info; - } xattr_NTACL; - -} diff --git a/source3/modules/vfs_xattr_tdb.c b/source3/modules/vfs_xattr_tdb.c index c707a1828f..8320a5820a 100644 --- a/source3/modules/vfs_xattr_tdb.c +++ b/source3/modules/vfs_xattr_tdb.c @@ -177,25 +177,25 @@ static ssize_t xattr_tdb_getattr(struct db_context *db_ctx, return -1; } - for (i=0; i<attribs->num_xattrs; i++) { - if (strcmp(attribs->xattrs[i].name, name) == 0) { + for (i=0; i<attribs->num_eas; i++) { + if (strcmp(attribs->eas[i].name, name) == 0) { break; } } - if (i == attribs->num_xattrs) { + if (i == attribs->num_eas) { errno = ENOATTR; goto fail; } - if (attribs->xattrs[i].value.length > size) { + if (attribs->eas[i].value.length > size) { errno = ERANGE; goto fail; } - memcpy(value, attribs->xattrs[i].value.data, - attribs->xattrs[i].value.length); - result = attribs->xattrs[i].value.length; + memcpy(value, attribs->eas[i].value.data, + attribs->eas[i].value.length); + result = attribs->eas[i].value.length; fail: TALLOC_FREE(attribs); @@ -273,8 +273,8 @@ static int xattr_tdb_setattr(struct db_context *db_ctx, return -1; } - for (i=0; i<attribs->num_xattrs; i++) { - if (strcmp(attribs->xattrs[i].name, name) == 0) { + for (i=0; i<attribs->num_eas; i++) { + if (strcmp(attribs->eas[i].name, name) == 0) { if (flags & XATTR_CREATE) { TALLOC_FREE(rec); errno = EEXIST; @@ -284,8 +284,8 @@ static int xattr_tdb_setattr(struct db_context *db_ctx, } } - if (i == attribs->num_xattrs) { - struct tdb_xattr *tmp; + if (i == attribs->num_eas) { + struct xattr_EA *tmp; if (flags & XATTR_REPLACE) { TALLOC_FREE(rec); @@ -294,8 +294,8 @@ static int xattr_tdb_setattr(struct db_context *db_ctx, } tmp = TALLOC_REALLOC_ARRAY( - attribs, attribs->xattrs, struct tdb_xattr, - attribs->num_xattrs + 1); + attribs, attribs->eas, struct xattr_EA, + attribs->num_eas+ 1); if (tmp == NULL) { DEBUG(0, ("TALLOC_REALLOC_ARRAY failed\n")); @@ -304,13 +304,13 @@ static int xattr_tdb_setattr(struct db_context *db_ctx, return -1; } - attribs->xattrs = tmp; - attribs->num_xattrs += 1; + attribs->eas = tmp; + attribs->num_eas += 1; } - attribs->xattrs[i].name = name; - attribs->xattrs[i].value.data = CONST_DISCARD(uint8 *, value); - attribs->xattrs[i].value.length = size; + attribs->eas[i].name = name; + attribs->eas[i].value.data = CONST_DISCARD(uint8 *, value); + attribs->eas[i].value.length = size; status = xattr_tdb_save_attrs(rec, attribs); @@ -386,15 +386,15 @@ static ssize_t xattr_tdb_listattr(struct db_context *db_ctx, } DEBUG(10, ("xattr_tdb_listattr: Found %d xattrs\n", - attribs->num_xattrs)); + attribs->num_eas)); - for (i=0; i<attribs->num_xattrs; i++) { + for (i=0; i<attribs->num_eas; i++) { size_t tmp; DEBUG(10, ("xattr_tdb_listattr: xattrs[i].name: %s\n", - attribs->xattrs[i].name)); + attribs->eas[i].name)); - tmp = strlen(attribs->xattrs[i].name); + tmp = strlen(attribs->eas[i].name); /* * Try to protect against overflow @@ -420,10 +420,10 @@ static ssize_t xattr_tdb_listattr(struct db_context *db_ctx, len = 0; - for (i=0; i<attribs->num_xattrs; i++) { - strlcpy(list+len, attribs->xattrs[i].name, + for (i=0; i<attribs->num_eas; i++) { + strlcpy(list+len, attribs->eas[i].name, size-len); - len += (strlen(attribs->xattrs[i].name) + 1); + len += (strlen(attribs->eas[i].name) + 1); } TALLOC_FREE(attribs); @@ -496,23 +496,23 @@ static int xattr_tdb_removeattr(struct db_context *db_ctx, return -1; } - for (i=0; i<attribs->num_xattrs; i++) { - if (strcmp(attribs->xattrs[i].name, name) == 0) { + for (i=0; i<attribs->num_eas; i++) { + if (strcmp(attribs->eas[i].name, name) == 0) { break; } } - if (i == attribs->num_xattrs) { + if (i == attribs->num_eas) { TALLOC_FREE(rec); errno = ENOATTR; return -1; } - attribs->xattrs[i] = - attribs->xattrs[attribs->num_xattrs-1]; - attribs->num_xattrs -= 1; + attribs->eas[i] = + attribs->eas[attribs->num_eas-1]; + attribs->num_eas -= 1; - if (attribs->num_xattrs == 0) { + if (attribs->num_eas == 0) { rec->delete_rec(rec); TALLOC_FREE(rec); return 0; |