From c7f1e0228770f69ebadb3781f61f75e935786bbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Deschner?= Date: Wed, 23 Sep 2009 20:41:44 +0200 Subject: [PATCH 1/6] winreg: add winreg_Data union to IDL. Guenther --- librpc/gen_ndr/misc.h | 41 ++++++++ librpc/gen_ndr/ndr_misc.c | 219 +++++++++++++++++++++++++++++++++++++++++++ librpc/gen_ndr/ndr_misc.h | 6 + librpc/gen_ndr/ndr_winreg.c | 36 +------- librpc/gen_ndr/ndr_winreg.h | 3 - librpc/gen_ndr/winreg.h | 34 +------- librpc/idl/misc.idl | 26 +++++ librpc/idl/winreg.idl | 17 +--- 8 files changed, 295 insertions(+), 87 deletions(-) diff --git a/librpc/gen_ndr/misc.h b/librpc/gen_ndr/misc.h index 824483d..8d7ae55 100644 --- a/librpc/gen_ndr/misc.h +++ b/librpc/gen_ndr/misc.h @@ -50,4 +50,45 @@ struct KRB5_EDATA_NTSTATUS { uint32_t unknown2; }/* [public] */; +enum winreg_Type +#ifndef USE_UINT_ENUMS + { + REG_NONE=0, + REG_SZ=1, + REG_EXPAND_SZ=2, + REG_BINARY=3, + REG_DWORD=4, + REG_DWORD_BIG_ENDIAN=5, + REG_LINK=6, + REG_MULTI_SZ=7, + REG_RESOURCE_LIST=8, + REG_FULL_RESOURCE_DESCRIPTOR=9, + REG_RESOURCE_REQUIREMENTS_LIST=10, + REG_QWORD=11 +} +#else + { __donnot_use_enum_winreg_Type=0x7FFFFFFF} +#define REG_NONE ( 0 ) +#define REG_SZ ( 1 ) +#define REG_EXPAND_SZ ( 2 ) +#define REG_BINARY ( 3 ) +#define REG_DWORD ( 4 ) +#define REG_DWORD_BIG_ENDIAN ( 5 ) +#define REG_LINK ( 6 ) +#define REG_MULTI_SZ ( 7 ) +#define REG_RESOURCE_LIST ( 8 ) +#define REG_FULL_RESOURCE_DESCRIPTOR ( 9 ) +#define REG_RESOURCE_REQUIREMENTS_LIST ( 10 ) +#define REG_QWORD ( 11 ) +#endif +; + +union winreg_Data { + const char * string;/* [flag(LIBNDR_FLAG_STR_NULLTERM),case(REG_SZ)] */ + DATA_BLOB binary;/* [flag(LIBNDR_FLAG_REMAINING),case(REG_BINARY)] */ + uint32_t value;/* [case(REG_DWORD)] */ + const char ** string_array;/* [flag(LIBNDR_FLAG_STR_NULLTERM),case(REG_MULTI_SZ)] */ + DATA_BLOB data;/* [flag(LIBNDR_FLAG_REMAINING),default] */ +}/* [nodiscriminant,public] */; + #endif /* _HEADER_misc */ diff --git a/librpc/gen_ndr/ndr_misc.c b/librpc/gen_ndr/ndr_misc.c index 28c8560..a5563d4 100644 --- a/librpc/gen_ndr/ndr_misc.c +++ b/librpc/gen_ndr/ndr_misc.c @@ -168,3 +168,222 @@ _PUBLIC_ void ndr_print_KRB5_EDATA_NTSTATUS(struct ndr_print *ndr, const char *n ndr->depth--; } +_PUBLIC_ enum ndr_err_code ndr_push_winreg_Type(struct ndr_push *ndr, int ndr_flags, enum winreg_Type r) +{ + NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, r)); + return NDR_ERR_SUCCESS; +} + +_PUBLIC_ enum ndr_err_code ndr_pull_winreg_Type(struct ndr_pull *ndr, int ndr_flags, enum winreg_Type *r) +{ + uint32_t v; + NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &v)); + *r = v; + return NDR_ERR_SUCCESS; +} + +_PUBLIC_ void ndr_print_winreg_Type(struct ndr_print *ndr, const char *name, enum winreg_Type r) +{ + const char *val = NULL; + + switch (r) { + case REG_NONE: val = "REG_NONE"; break; + case REG_SZ: val = "REG_SZ"; break; + case REG_EXPAND_SZ: val = "REG_EXPAND_SZ"; break; + case REG_BINARY: val = "REG_BINARY"; break; + case REG_DWORD: val = "REG_DWORD"; break; + case REG_DWORD_BIG_ENDIAN: val = "REG_DWORD_BIG_ENDIAN"; break; + case REG_LINK: val = "REG_LINK"; break; + case REG_MULTI_SZ: val = "REG_MULTI_SZ"; break; + case REG_RESOURCE_LIST: val = "REG_RESOURCE_LIST"; break; + case REG_FULL_RESOURCE_DESCRIPTOR: val = "REG_FULL_RESOURCE_DESCRIPTOR"; break; + case REG_RESOURCE_REQUIREMENTS_LIST: val = "REG_RESOURCE_REQUIREMENTS_LIST"; break; + case REG_QWORD: val = "REG_QWORD"; break; + } + ndr_print_enum(ndr, name, "ENUM", val, r); +} + +_PUBLIC_ enum ndr_err_code ndr_push_winreg_Data(struct ndr_push *ndr, int ndr_flags, const union winreg_Data *r) +{ + if (ndr_flags & NDR_SCALARS) { + int level = ndr_push_get_switch_value(ndr, r); + switch (level) { + case REG_NONE: { + break; } + + case REG_SZ: { + { + uint32_t _flags_save_string = ndr->flags; + ndr_set_flags(&ndr->flags, LIBNDR_FLAG_STR_NULLTERM); + NDR_CHECK(ndr_push_string(ndr, NDR_SCALARS, r->string)); + ndr->flags = _flags_save_string; + } + break; } + + case REG_BINARY: { + { + uint32_t _flags_save_DATA_BLOB = ndr->flags; + ndr_set_flags(&ndr->flags, LIBNDR_FLAG_REMAINING); + NDR_CHECK(ndr_push_DATA_BLOB(ndr, NDR_SCALARS, r->binary)); + ndr->flags = _flags_save_DATA_BLOB; + } + break; } + + case REG_DWORD: { + NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, r->value)); + break; } + + case REG_MULTI_SZ: { + { + uint32_t _flags_save_string_array = ndr->flags; + ndr_set_flags(&ndr->flags, LIBNDR_FLAG_STR_NULLTERM); + NDR_CHECK(ndr_push_string_array(ndr, NDR_SCALARS, r->string_array)); + ndr->flags = _flags_save_string_array; + } + break; } + + default: { + { + uint32_t _flags_save_DATA_BLOB = ndr->flags; + ndr_set_flags(&ndr->flags, LIBNDR_FLAG_REMAINING); + NDR_CHECK(ndr_push_DATA_BLOB(ndr, NDR_SCALARS, r->data)); + ndr->flags = _flags_save_DATA_BLOB; + } + break; } + + } + } + if (ndr_flags & NDR_BUFFERS) { + int level = ndr_push_get_switch_value(ndr, r); + switch (level) { + case REG_NONE: + break; + + case REG_SZ: + break; + + case REG_BINARY: + break; + + case REG_DWORD: + break; + + case REG_MULTI_SZ: + break; + + default: + break; + + } + } + return NDR_ERR_SUCCESS; +} + +_PUBLIC_ enum ndr_err_code ndr_pull_winreg_Data(struct ndr_pull *ndr, int ndr_flags, union winreg_Data *r) +{ + int level; + level = ndr_pull_get_switch_value(ndr, r); + if (ndr_flags & NDR_SCALARS) { + switch (level) { + case REG_NONE: { + break; } + + case REG_SZ: { + { + uint32_t _flags_save_string = ndr->flags; + ndr_set_flags(&ndr->flags, LIBNDR_FLAG_STR_NULLTERM); + NDR_CHECK(ndr_pull_string(ndr, NDR_SCALARS, &r->string)); + ndr->flags = _flags_save_string; + } + break; } + + case REG_BINARY: { + { + uint32_t _flags_save_DATA_BLOB = ndr->flags; + ndr_set_flags(&ndr->flags, LIBNDR_FLAG_REMAINING); + NDR_CHECK(ndr_pull_DATA_BLOB(ndr, NDR_SCALARS, &r->binary)); + ndr->flags = _flags_save_DATA_BLOB; + } + break; } + + case REG_DWORD: { + NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->value)); + break; } + + case REG_MULTI_SZ: { + { + uint32_t _flags_save_string_array = ndr->flags; + ndr_set_flags(&ndr->flags, LIBNDR_FLAG_STR_NULLTERM); + NDR_CHECK(ndr_pull_string_array(ndr, NDR_SCALARS, &r->string_array)); + ndr->flags = _flags_save_string_array; + } + break; } + + default: { + { + uint32_t _flags_save_DATA_BLOB = ndr->flags; + ndr_set_flags(&ndr->flags, LIBNDR_FLAG_REMAINING); + NDR_CHECK(ndr_pull_DATA_BLOB(ndr, NDR_SCALARS, &r->data)); + ndr->flags = _flags_save_DATA_BLOB; + } + break; } + + } + } + if (ndr_flags & NDR_BUFFERS) { + switch (level) { + case REG_NONE: + break; + + case REG_SZ: + break; + + case REG_BINARY: + break; + + case REG_DWORD: + break; + + case REG_MULTI_SZ: + break; + + default: + break; + + } + } + return NDR_ERR_SUCCESS; +} + +_PUBLIC_ void ndr_print_winreg_Data(struct ndr_print *ndr, const char *name, const union winreg_Data *r) +{ + int level; + level = ndr_print_get_switch_value(ndr, r); + ndr_print_union(ndr, name, level, "winreg_Data"); + switch (level) { + case REG_NONE: + break; + + case REG_SZ: + ndr_print_string(ndr, "string", r->string); + break; + + case REG_BINARY: + ndr_print_DATA_BLOB(ndr, "binary", r->binary); + break; + + case REG_DWORD: + ndr_print_uint32(ndr, "value", r->value); + break; + + case REG_MULTI_SZ: + ndr_print_string_array(ndr, "string_array", r->string_array); + break; + + default: + ndr_print_DATA_BLOB(ndr, "data", r->data); + break; + + } +} + diff --git a/librpc/gen_ndr/ndr_misc.h b/librpc/gen_ndr/ndr_misc.h index 938c946..99f9752 100644 --- a/librpc/gen_ndr/ndr_misc.h +++ b/librpc/gen_ndr/ndr_misc.h @@ -23,4 +23,10 @@ void ndr_print_netr_SchannelType(struct ndr_print *ndr, const char *name, enum n enum ndr_err_code ndr_push_KRB5_EDATA_NTSTATUS(struct ndr_push *ndr, int ndr_flags, const struct KRB5_EDATA_NTSTATUS *r); enum ndr_err_code ndr_pull_KRB5_EDATA_NTSTATUS(struct ndr_pull *ndr, int ndr_flags, struct KRB5_EDATA_NTSTATUS *r); void ndr_print_KRB5_EDATA_NTSTATUS(struct ndr_print *ndr, const char *name, const struct KRB5_EDATA_NTSTATUS *r); +enum ndr_err_code ndr_push_winreg_Type(struct ndr_push *ndr, int ndr_flags, enum winreg_Type r); +enum ndr_err_code ndr_pull_winreg_Type(struct ndr_pull *ndr, int ndr_flags, enum winreg_Type *r); +void ndr_print_winreg_Type(struct ndr_print *ndr, const char *name, enum winreg_Type r); +enum ndr_err_code ndr_push_winreg_Data(struct ndr_push *ndr, int ndr_flags, const union winreg_Data *r); +enum ndr_err_code ndr_pull_winreg_Data(struct ndr_pull *ndr, int ndr_flags, union winreg_Data *r); +void ndr_print_winreg_Data(struct ndr_print *ndr, const char *name, const union winreg_Data *r); #endif /* _HEADER_NDR_misc */ diff --git a/librpc/gen_ndr/ndr_winreg.c b/librpc/gen_ndr/ndr_winreg.c index fe76bca..f5d6029 100644 --- a/librpc/gen_ndr/ndr_winreg.c +++ b/librpc/gen_ndr/ndr_winreg.c @@ -5,6 +5,7 @@ #include "librpc/gen_ndr/ndr_lsa.h" #include "librpc/gen_ndr/ndr_security.h" +#include "librpc/gen_ndr/ndr_misc.h" static enum ndr_err_code ndr_push_winreg_AccessMask(struct ndr_push *ndr, int ndr_flags, uint32_t r) { NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, r)); @@ -34,41 +35,6 @@ _PUBLIC_ void ndr_print_winreg_AccessMask(struct ndr_print *ndr, const char *nam ndr->depth--; } -_PUBLIC_ enum ndr_err_code ndr_push_winreg_Type(struct ndr_push *ndr, int ndr_flags, enum winreg_Type r) -{ - NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, r)); - return NDR_ERR_SUCCESS; -} - -_PUBLIC_ enum ndr_err_code ndr_pull_winreg_Type(struct ndr_pull *ndr, int ndr_flags, enum winreg_Type *r) -{ - uint32_t v; - NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &v)); - *r = v; - return NDR_ERR_SUCCESS; -} - -_PUBLIC_ void ndr_print_winreg_Type(struct ndr_print *ndr, const char *name, enum winreg_Type r) -{ - const char *val = NULL; - - switch (r) { - case REG_NONE: val = "REG_NONE"; break; - case REG_SZ: val = "REG_SZ"; break; - case REG_EXPAND_SZ: val = "REG_EXPAND_SZ"; break; - case REG_BINARY: val = "REG_BINARY"; break; - case REG_DWORD: val = "REG_DWORD"; break; - case REG_DWORD_BIG_ENDIAN: val = "REG_DWORD_BIG_ENDIAN"; break; - case REG_LINK: val = "REG_LINK"; break; - case REG_MULTI_SZ: val = "REG_MULTI_SZ"; break; - case REG_RESOURCE_LIST: val = "REG_RESOURCE_LIST"; break; - case REG_FULL_RESOURCE_DESCRIPTOR: val = "REG_FULL_RESOURCE_DESCRIPTOR"; break; - case REG_RESOURCE_REQUIREMENTS_LIST: val = "REG_RESOURCE_REQUIREMENTS_LIST"; break; - case REG_QWORD: val = "REG_QWORD"; break; - } - ndr_print_enum(ndr, name, "ENUM", val, r); -} - _PUBLIC_ enum ndr_err_code ndr_push_winreg_String(struct ndr_push *ndr, int ndr_flags, const struct winreg_String *r) { if (ndr_flags & NDR_SCALARS) { diff --git a/librpc/gen_ndr/ndr_winreg.h b/librpc/gen_ndr/ndr_winreg.h index a8766f4..a496d4c 100644 --- a/librpc/gen_ndr/ndr_winreg.h +++ b/librpc/gen_ndr/ndr_winreg.h @@ -83,9 +83,6 @@ extern const struct ndr_interface_table ndr_table_winreg; #define NDR_WINREG_CALL_COUNT (35) void ndr_print_winreg_AccessMask(struct ndr_print *ndr, const char *name, uint32_t r); -enum ndr_err_code ndr_push_winreg_Type(struct ndr_push *ndr, int ndr_flags, enum winreg_Type r); -enum ndr_err_code ndr_pull_winreg_Type(struct ndr_pull *ndr, int ndr_flags, enum winreg_Type *r); -void ndr_print_winreg_Type(struct ndr_print *ndr, const char *name, enum winreg_Type r); enum ndr_err_code ndr_push_winreg_String(struct ndr_push *ndr, int ndr_flags, const struct winreg_String *r); enum ndr_err_code ndr_pull_winreg_String(struct ndr_pull *ndr, int ndr_flags, struct winreg_String *r); void ndr_print_winreg_String(struct ndr_print *ndr, const char *name, const struct winreg_String *r); diff --git a/librpc/gen_ndr/winreg.h b/librpc/gen_ndr/winreg.h index 103817c..1f19bc9 100644 --- a/librpc/gen_ndr/winreg.h +++ b/librpc/gen_ndr/winreg.h @@ -6,6 +6,7 @@ #include "librpc/gen_ndr/lsa.h" #include "librpc/gen_ndr/security.h" +#include "librpc/gen_ndr/misc.h" #ifndef _HEADER_winreg #define _HEADER_winreg @@ -23,39 +24,6 @@ #define KEY_WOW64_64KEY ( 0x00100 ) #define KEY_WOW64_32KEY ( 0x00200 ) -enum winreg_Type -#ifndef USE_UINT_ENUMS - { - REG_NONE=0, - REG_SZ=1, - REG_EXPAND_SZ=2, - REG_BINARY=3, - REG_DWORD=4, - REG_DWORD_BIG_ENDIAN=5, - REG_LINK=6, - REG_MULTI_SZ=7, - REG_RESOURCE_LIST=8, - REG_FULL_RESOURCE_DESCRIPTOR=9, - REG_RESOURCE_REQUIREMENTS_LIST=10, - REG_QWORD=11 -} -#else - { __donnot_use_enum_winreg_Type=0x7FFFFFFF} -#define REG_NONE ( 0 ) -#define REG_SZ ( 1 ) -#define REG_EXPAND_SZ ( 2 ) -#define REG_BINARY ( 3 ) -#define REG_DWORD ( 4 ) -#define REG_DWORD_BIG_ENDIAN ( 5 ) -#define REG_LINK ( 6 ) -#define REG_MULTI_SZ ( 7 ) -#define REG_RESOURCE_LIST ( 8 ) -#define REG_FULL_RESOURCE_DESCRIPTOR ( 9 ) -#define REG_RESOURCE_REQUIREMENTS_LIST ( 10 ) -#define REG_QWORD ( 11 ) -#endif -; - struct winreg_String { uint16_t name_len;/* [value(strlen_m_term(name)*2)] */ uint16_t name_size;/* [value(strlen_m_term(name)*2)] */ diff --git a/librpc/idl/misc.idl b/librpc/idl/misc.idl index c4d8c62..d00c2fc 100644 --- a/librpc/idl/misc.idl +++ b/librpc/idl/misc.idl @@ -1,3 +1,5 @@ +#include "idl_types.h" + /* miscellaneous IDL structures */ @@ -41,4 +43,28 @@ interface misc uint32 unknown1; uint32 unknown2; /* 0x00000001 */ } KRB5_EDATA_NTSTATUS; + + typedef [public,v1_enum] enum { + REG_NONE = 0, + REG_SZ = 1, + REG_EXPAND_SZ = 2, + REG_BINARY = 3, + REG_DWORD = 4, + REG_DWORD_BIG_ENDIAN = 5, + REG_LINK = 6, + REG_MULTI_SZ = 7, + REG_RESOURCE_LIST = 8, + REG_FULL_RESOURCE_DESCRIPTOR = 9, + REG_RESOURCE_REQUIREMENTS_LIST = 10, + REG_QWORD = 11 + } winreg_Type; + + typedef [nodiscriminant,public] union { + [case(REG_NONE)]; + [case(REG_SZ)] nstring string; + [case(REG_BINARY),flag(NDR_REMAINING)] DATA_BLOB binary; + [case(REG_DWORD)] uint32 value; + [case(REG_MULTI_SZ)] nstring_array string_array; + [default,flag(NDR_REMAINING)] DATA_BLOB data; + } winreg_Data; } diff --git a/librpc/idl/winreg.idl b/librpc/idl/winreg.idl index 18b5edc..f1f4dfb 100644 --- a/librpc/idl/winreg.idl +++ b/librpc/idl/winreg.idl @@ -2,7 +2,7 @@ winreg interface definition */ -import "lsa.idl", "security.idl"; +import "lsa.idl", "security.idl", "misc.idl"; [ uuid("338cd001-2244-31f1-aaaa-900038001003"), @@ -45,21 +45,6 @@ import "lsa.idl", "security.idl"; REG_KEY_WRITE | KEY_CREATE_LINK); - typedef [public,v1_enum] enum { - REG_NONE = 0, - REG_SZ = 1, - REG_EXPAND_SZ = 2, - REG_BINARY = 3, - REG_DWORD = 4, - REG_DWORD_BIG_ENDIAN = 5, - REG_LINK = 6, - REG_MULTI_SZ = 7, - REG_RESOURCE_LIST = 8, - REG_FULL_RESOURCE_DESCRIPTOR = 9, - REG_RESOURCE_REQUIREMENTS_LIST = 10, - REG_QWORD = 11 - } winreg_Type; - typedef [public] struct { [value(strlen_m_term(name)*2)] uint16 name_len; [value(strlen_m_term(name)*2)] uint16 name_size; -- 1.6.5.2 From be70df44b96837a7e7214db923f23e9930c1a6d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Deschner?= Date: Wed, 23 Sep 2009 20:42:20 +0200 Subject: [PATCH 2/6] s3-util: add push_reg_sz() and push_reg_multi_sz() convenience functions. Guenther (cherry picked from commit fcee9d2c97a673347baf58f749f35785a896e468) --- source3/include/proto.h | 2 ++ source3/lib/util_reg.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 0 deletions(-) diff --git a/source3/include/proto.h b/source3/include/proto.h index d91dbf8..4800607 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -1253,6 +1253,8 @@ struct passwd *getpwuid_alloc(TALLOC_CTX *mem_ctx, uid_t uid) ; const char *reg_type_lookup(enum winreg_Type type); WERROR reg_pull_multi_sz(TALLOC_CTX *mem_ctx, const void *buf, size_t len, uint32 *num_values, char ***values); +bool push_reg_sz(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const char *s); +bool push_reg_multi_sz(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const char **a); /* The following definitions come from lib/util_reg_api.c */ diff --git a/source3/lib/util_reg.c b/source3/lib/util_reg.c index 6570bb0..39a42e9 100644 --- a/source3/lib/util_reg.c +++ b/source3/lib/util_reg.c @@ -18,6 +18,7 @@ */ #include "includes.h" +#include "../librpc/gen_ndr/ndr_winreg.h" #undef DBGC_CLASS #define DBGC_CLASS DBGC_REGISTRY @@ -110,3 +111,32 @@ WERROR reg_pull_multi_sz(TALLOC_CTX *mem_ctx, const void *buf, size_t len, return WERR_OK; } + +/******************************************************************* + push a string in unix charset into a REG_SZ UCS2 null terminated blob + ********************************************************************/ + +bool push_reg_sz(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const char *s) +{ + union winreg_Data data; + enum ndr_err_code ndr_err; + data.string = s; + ndr_err = ndr_push_union_blob(blob, mem_ctx, NULL, &data, REG_SZ, + (ndr_push_flags_fn_t)ndr_push_winreg_Data); + return NDR_ERR_CODE_IS_SUCCESS(ndr_err); +} + +/******************************************************************* + push a string_array in unix charset into a REG_MULTI_SZ UCS2 double-null + terminated blob + ********************************************************************/ + +bool push_reg_multi_sz(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const char **a) +{ + union winreg_Data data; + enum ndr_err_code ndr_err; + data.string_array = a; + ndr_err = ndr_push_union_blob(blob, mem_ctx, NULL, &data, REG_MULTI_SZ, + (ndr_push_flags_fn_t)ndr_push_winreg_Data); + return NDR_ERR_CODE_IS_SUCCESS(ndr_err); +} -- 1.6.5.2 From 081e1e0d4d1601416a8268096ab1940e6434ac37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Deschner?= Date: Fri, 25 Sep 2009 00:56:17 +0200 Subject: [PATCH 3/6] s3-util: add pull_reg_sz() and pull_reg_multi_sz() convenience functions. Guenther (cherry picked from commit f8016cfee922cba97b70f56c752827e4584da6c6) --- source3/include/proto.h | 2 ++ source3/lib/util_reg.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 0 deletions(-) diff --git a/source3/include/proto.h b/source3/include/proto.h index 4800607..dee8f85 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -1255,6 +1255,8 @@ WERROR reg_pull_multi_sz(TALLOC_CTX *mem_ctx, const void *buf, size_t len, uint32 *num_values, char ***values); bool push_reg_sz(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const char *s); bool push_reg_multi_sz(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const char **a); +bool pull_reg_sz(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob, const char **s); +bool pull_reg_multi_sz(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob, const char ***a); /* The following definitions come from lib/util_reg_api.c */ diff --git a/source3/lib/util_reg.c b/source3/lib/util_reg.c index 39a42e9..3f8033b 100644 --- a/source3/lib/util_reg.c +++ b/source3/lib/util_reg.c @@ -140,3 +140,38 @@ bool push_reg_multi_sz(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const char **a) (ndr_push_flags_fn_t)ndr_push_winreg_Data); return NDR_ERR_CODE_IS_SUCCESS(ndr_err); } + +/******************************************************************* + pull a string in unix charset out of a REG_SZ UCS2 null terminated blob + ********************************************************************/ + +bool pull_reg_sz(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob, const char **s) +{ + union winreg_Data data; + enum ndr_err_code ndr_err; + ndr_err = ndr_pull_union_blob(blob, mem_ctx, NULL, &data, REG_SZ, + (ndr_pull_flags_fn_t)ndr_pull_winreg_Data); + if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { + return false; + } + *s = data.string; + return true; +} + +/******************************************************************* + pull a string_array in unix charset out of a REG_MULTI_SZ UCS2 double-null + terminated blob + ********************************************************************/ + +bool pull_reg_multi_sz(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob, const char ***a) +{ + union winreg_Data data; + enum ndr_err_code ndr_err; + ndr_err = ndr_pull_union_blob(blob, mem_ctx, NULL, &data, REG_MULTI_SZ, + (ndr_pull_flags_fn_t)ndr_pull_winreg_Data); + if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { + return false; + } + *a = data.string_array; + return true; +} -- 1.6.5.2 From 6b11f5f5c745c78353d9be9bb1a82bd51767c875 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Deschner?= Date: Fri, 20 Nov 2009 12:57:13 +0100 Subject: [PATCH 4/6] spoolss: fix spoolss_EnumPrinterKey IDL. Guenther --- librpc/gen_ndr/cli_spoolss.c | 4 +- librpc/gen_ndr/cli_spoolss.h | 2 +- librpc/gen_ndr/ndr_spoolss.c | 80 ++++++++++++++++-------------------------- librpc/gen_ndr/spoolss.h | 2 +- librpc/gen_ndr/srv_spoolss.c | 4 +- librpc/idl/spoolss.idl | 2 +- 6 files changed, 37 insertions(+), 57 deletions(-) diff --git a/librpc/gen_ndr/cli_spoolss.c b/librpc/gen_ndr/cli_spoolss.c index 1e94a2a..70dfab3 100644 --- a/librpc/gen_ndr/cli_spoolss.c +++ b/librpc/gen_ndr/cli_spoolss.c @@ -3811,7 +3811,7 @@ NTSTATUS rpccli_spoolss_EnumPrinterKey(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, struct policy_handle *handle /* [in] [ref] */, const char *key_name /* [in] [charset(UTF16)] */, - const char ** *key_buffer /* [out] [subcontext_size(offered),ref,subcontext(0),flag(LIBNDR_FLAG_STR_NULLTERM)] */, + uint16_t *key_buffer /* [out] [ref,size_is(offered/2)] */, uint32_t offered /* [in] */, uint32_t *needed /* [out] [ref] */, WERROR *werror) @@ -3847,7 +3847,7 @@ NTSTATUS rpccli_spoolss_EnumPrinterKey(struct rpc_pipe_client *cli, } /* Return variables */ - *key_buffer = *r.out.key_buffer; + memcpy(key_buffer, r.out.key_buffer, r.in.offered / 2 * sizeof(*key_buffer)); *needed = *r.out.needed; /* Return result */ diff --git a/librpc/gen_ndr/cli_spoolss.h b/librpc/gen_ndr/cli_spoolss.h index eb86e8c..4c621f4 100644 --- a/librpc/gen_ndr/cli_spoolss.h +++ b/librpc/gen_ndr/cli_spoolss.h @@ -497,7 +497,7 @@ NTSTATUS rpccli_spoolss_EnumPrinterKey(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, struct policy_handle *handle /* [in] [ref] */, const char *key_name /* [in] [charset(UTF16)] */, - const char ** *key_buffer /* [out] [subcontext_size(offered),ref,subcontext(0),flag(LIBNDR_FLAG_STR_NULLTERM)] */, + uint16_t *key_buffer /* [out] [ref,size_is(offered/2)] */, uint32_t offered /* [in] */, uint32_t *needed /* [out] [ref] */, WERROR *werror); diff --git a/librpc/gen_ndr/ndr_spoolss.c b/librpc/gen_ndr/ndr_spoolss.c index d4195e4..d03196e 100644 --- a/librpc/gen_ndr/ndr_spoolss.c +++ b/librpc/gen_ndr/ndr_spoolss.c @@ -26619,6 +26619,7 @@ _PUBLIC_ void ndr_print_spoolss_EnumPrinterDataEx(struct ndr_print *ndr, const c _PUBLIC_ enum ndr_err_code ndr_push_spoolss_EnumPrinterKey(struct ndr_push *ndr, int flags, const struct spoolss_EnumPrinterKey *r) { + uint32_t cntr_key_buffer_1; if (flags & NDR_IN) { if (r->in.handle == NULL) { return ndr_push_error(ndr, NDR_ERR_INVALID_POINTER, "NULL [ref] pointer"); @@ -26631,22 +26632,12 @@ _PUBLIC_ enum ndr_err_code ndr_push_spoolss_EnumPrinterKey(struct ndr_push *ndr, NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, r->in.offered)); } if (flags & NDR_OUT) { - { - uint32_t _flags_save_string_array = ndr->flags; - ndr_set_flags(&ndr->flags, LIBNDR_FLAG_STR_NULLTERM); - if (r->out.key_buffer == NULL) { - return ndr_push_error(ndr, NDR_ERR_INVALID_POINTER, "NULL [ref] pointer"); - } - NDR_CHECK(ndr_push_unique_ptr(ndr, *r->out.key_buffer)); - if (*r->out.key_buffer) { - { - struct ndr_push *_ndr_key_buffer; - NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_key_buffer, 0, r->in.offered)); - NDR_CHECK(ndr_push_string_array(_ndr_key_buffer, NDR_SCALARS, *r->out.key_buffer)); - NDR_CHECK(ndr_push_subcontext_end(ndr, _ndr_key_buffer, 0, r->in.offered)); - } - } - ndr->flags = _flags_save_string_array; + if (r->out.key_buffer == NULL) { + return ndr_push_error(ndr, NDR_ERR_INVALID_POINTER, "NULL [ref] pointer"); + } + NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, r->in.offered / 2)); + for (cntr_key_buffer_1 = 0; cntr_key_buffer_1 < r->in.offered / 2; cntr_key_buffer_1++) { + NDR_CHECK(ndr_push_uint16(ndr, NDR_SCALARS, r->out.key_buffer[cntr_key_buffer_1])); } if (r->out.needed == NULL) { return ndr_push_error(ndr, NDR_ERR_INVALID_POINTER, "NULL [ref] pointer"); @@ -26659,9 +26650,8 @@ _PUBLIC_ enum ndr_err_code ndr_push_spoolss_EnumPrinterKey(struct ndr_push *ndr, _PUBLIC_ enum ndr_err_code ndr_pull_spoolss_EnumPrinterKey(struct ndr_pull *ndr, int flags, struct spoolss_EnumPrinterKey *r) { - uint32_t _ptr_key_buffer; + uint32_t cntr_key_buffer_1; TALLOC_CTX *_mem_save_handle_0; - TALLOC_CTX *_mem_save_key_buffer_0; TALLOC_CTX *_mem_save_key_buffer_1; TALLOC_CTX *_mem_save_needed_0; if (flags & NDR_IN) { @@ -26682,40 +26672,22 @@ _PUBLIC_ enum ndr_err_code ndr_pull_spoolss_EnumPrinterKey(struct ndr_pull *ndr, NDR_CHECK(ndr_check_string_terminator(ndr, ndr_get_array_length(ndr, &r->in.key_name), sizeof(uint16_t))); NDR_CHECK(ndr_pull_charset(ndr, NDR_SCALARS, &r->in.key_name, ndr_get_array_length(ndr, &r->in.key_name), sizeof(uint16_t), CH_UTF16)); NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->in.offered)); - NDR_PULL_ALLOC(ndr, r->out.key_buffer); - ZERO_STRUCTP(r->out.key_buffer); + NDR_PULL_ALLOC_N(ndr, r->out.key_buffer, r->in.offered / 2); + memset(r->out.key_buffer, 0, (r->in.offered / 2) * sizeof(*r->out.key_buffer)); NDR_PULL_ALLOC(ndr, r->out.needed); ZERO_STRUCTP(r->out.needed); } if (flags & NDR_OUT) { - { - uint32_t _flags_save_string_array = ndr->flags; - ndr_set_flags(&ndr->flags, LIBNDR_FLAG_STR_NULLTERM); - if (ndr->flags & LIBNDR_FLAG_REF_ALLOC) { - NDR_PULL_ALLOC(ndr, r->out.key_buffer); - } - _mem_save_key_buffer_0 = NDR_PULL_GET_MEM_CTX(ndr); - NDR_PULL_SET_MEM_CTX(ndr, r->out.key_buffer, LIBNDR_FLAG_REF_ALLOC); - NDR_CHECK(ndr_pull_generic_ptr(ndr, &_ptr_key_buffer)); - if (_ptr_key_buffer) { - NDR_PULL_ALLOC(ndr, *r->out.key_buffer); - } else { - *r->out.key_buffer = NULL; - } - if (*r->out.key_buffer) { - _mem_save_key_buffer_1 = NDR_PULL_GET_MEM_CTX(ndr); - NDR_PULL_SET_MEM_CTX(ndr, *r->out.key_buffer, 0); - { - struct ndr_pull *_ndr_key_buffer; - NDR_CHECK(ndr_pull_subcontext_start(ndr, &_ndr_key_buffer, 0, r->in.offered)); - NDR_CHECK(ndr_pull_string_array(_ndr_key_buffer, NDR_SCALARS, r->out.key_buffer)); - NDR_CHECK(ndr_pull_subcontext_end(ndr, _ndr_key_buffer, 0, r->in.offered)); - } - NDR_PULL_SET_MEM_CTX(ndr, _mem_save_key_buffer_1, 0); - } - NDR_PULL_SET_MEM_CTX(ndr, _mem_save_key_buffer_0, LIBNDR_FLAG_REF_ALLOC); - ndr->flags = _flags_save_string_array; + NDR_CHECK(ndr_pull_array_size(ndr, &r->out.key_buffer)); + if (ndr->flags & LIBNDR_FLAG_REF_ALLOC) { + NDR_PULL_ALLOC_N(ndr, r->out.key_buffer, ndr_get_array_size(ndr, &r->out.key_buffer)); } + _mem_save_key_buffer_1 = NDR_PULL_GET_MEM_CTX(ndr); + NDR_PULL_SET_MEM_CTX(ndr, r->out.key_buffer, 0); + for (cntr_key_buffer_1 = 0; cntr_key_buffer_1 < r->in.offered / 2; cntr_key_buffer_1++) { + NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &r->out.key_buffer[cntr_key_buffer_1])); + } + NDR_PULL_SET_MEM_CTX(ndr, _mem_save_key_buffer_1, 0); if (ndr->flags & LIBNDR_FLAG_REF_ALLOC) { NDR_PULL_ALLOC(ndr, r->out.needed); } @@ -26724,12 +26696,16 @@ _PUBLIC_ enum ndr_err_code ndr_pull_spoolss_EnumPrinterKey(struct ndr_pull *ndr, NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, r->out.needed)); NDR_PULL_SET_MEM_CTX(ndr, _mem_save_needed_0, LIBNDR_FLAG_REF_ALLOC); NDR_CHECK(ndr_pull_WERROR(ndr, NDR_SCALARS, &r->out.result)); + if (r->out.key_buffer) { + NDR_CHECK(ndr_check_array_size(ndr, (void*)&r->out.key_buffer, r->in.offered / 2)); + } } return NDR_ERR_SUCCESS; } _PUBLIC_ void ndr_print_spoolss_EnumPrinterKey(struct ndr_print *ndr, const char *name, int flags, const struct spoolss_EnumPrinterKey *r) { + uint32_t cntr_key_buffer_1; ndr_print_struct(ndr, name, "spoolss_EnumPrinterKey"); ndr->depth++; if (flags & NDR_SET_VALUES) { @@ -26751,10 +26727,14 @@ _PUBLIC_ void ndr_print_spoolss_EnumPrinterKey(struct ndr_print *ndr, const char ndr->depth++; ndr_print_ptr(ndr, "key_buffer", r->out.key_buffer); ndr->depth++; - ndr_print_ptr(ndr, "key_buffer", *r->out.key_buffer); + ndr->print(ndr, "%s: ARRAY(%d)", "key_buffer", (int)r->in.offered / 2); ndr->depth++; - if (*r->out.key_buffer) { - ndr_print_string_array(ndr, "key_buffer", *r->out.key_buffer); + for (cntr_key_buffer_1=0;cntr_key_buffer_1in.offered / 2;cntr_key_buffer_1++) { + char *idx_1=NULL; + if (asprintf(&idx_1, "[%d]", cntr_key_buffer_1) != -1) { + ndr_print_uint16(ndr, "key_buffer", r->out.key_buffer[cntr_key_buffer_1]); + free(idx_1); + } } ndr->depth--; ndr->depth--; diff --git a/librpc/gen_ndr/spoolss.h b/librpc/gen_ndr/spoolss.h index a9f7aaf..2053065 100644 --- a/librpc/gen_ndr/spoolss.h +++ b/librpc/gen_ndr/spoolss.h @@ -3030,7 +3030,7 @@ struct spoolss_EnumPrinterKey { } in; struct { - const char ** *key_buffer;/* [subcontext_size(offered),ref,subcontext(0),flag(LIBNDR_FLAG_STR_NULLTERM)] */ + uint16_t *key_buffer;/* [ref,size_is(offered/2)] */ uint32_t *needed;/* [ref] */ WERROR result; } out; diff --git a/librpc/gen_ndr/srv_spoolss.c b/librpc/gen_ndr/srv_spoolss.c index 79efbb5..3bbe401 100644 --- a/librpc/gen_ndr/srv_spoolss.c +++ b/librpc/gen_ndr/srv_spoolss.c @@ -6296,7 +6296,7 @@ static bool api_spoolss_EnumPrinterKey(pipes_struct *p) } ZERO_STRUCT(r->out); - r->out.key_buffer = talloc_zero(r, const char **); + r->out.key_buffer = talloc_zero_array(r, uint16_t, r->in.offered / 2); if (r->out.key_buffer == NULL) { talloc_free(r); return false; @@ -8399,7 +8399,7 @@ NTSTATUS rpc_spoolss_dispatch(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, case NDR_SPOOLSS_ENUMPRINTERKEY: { struct spoolss_EnumPrinterKey *r = (struct spoolss_EnumPrinterKey *)_r; ZERO_STRUCT(r->out); - r->out.key_buffer = talloc_zero(mem_ctx, const char **); + r->out.key_buffer = talloc_zero_array(mem_ctx, uint16_t, r->in.offered / 2); if (r->out.key_buffer == NULL) { return NT_STATUS_NO_MEMORY; } diff --git a/librpc/idl/spoolss.idl b/librpc/idl/spoolss.idl index f306462..e4f03e5 100644 --- a/librpc/idl/spoolss.idl +++ b/librpc/idl/spoolss.idl @@ -2302,7 +2302,7 @@ import "misc.idl", "security.idl", "winreg.idl"; [public] WERROR spoolss_EnumPrinterKey( [in, ref] policy_handle *handle, [in] [string,charset(UTF16)] uint16 key_name[], - [out,ref] [subcontext(0),subcontext_size(offered)] nstring_array **key_buffer, + [out,ref] [size_is(offered/2)] uint16 *key_buffer, [in] uint32 offered, [out,ref] uint32 *needed ); -- 1.6.5.2 From 9548d04df390e2fd584ca76658f0b669e54d9158 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Deschner?= Date: Fri, 20 Nov 2009 16:34:00 +0100 Subject: [PATCH 5/6] s3-spoolss: fix spoolss_EnumPrinterKey client and server code. Guenther (cherry picked from commit d464151f3b47c675664f464b1645ca85de663655) --- source3/rpc_client/cli_spoolss.c | 24 +++++++++++++++++++++--- source3/rpc_server/srv_spoolss_nt.c | 23 +++++++++++++++++++---- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/source3/rpc_client/cli_spoolss.c b/source3/rpc_client/cli_spoolss.c index 3f369bd..ff8736d 100644 --- a/source3/rpc_client/cli_spoolss.c +++ b/source3/rpc_client/cli_spoolss.c @@ -760,27 +760,45 @@ WERROR rpccli_spoolss_enumprinterkey(struct rpc_pipe_client *cli, NTSTATUS status; WERROR werror; uint32_t needed; + uint16_t *buffer = NULL; + + *key_buffer = NULL; + + if (offered) { + buffer = talloc_array(mem_ctx, uint16_t, offered); + W_ERROR_HAVE_NO_MEMORY(buffer); + } status = rpccli_spoolss_EnumPrinterKey(cli, mem_ctx, handle, key_name, - key_buffer, + buffer, offered, &needed, &werror); if (W_ERROR_EQUAL(werror, WERR_MORE_DATA)) { offered = needed; - + buffer = talloc_realloc(mem_ctx, buffer, uint16_t, needed); + W_ERROR_HAVE_NO_MEMORY(buffer); status = rpccli_spoolss_EnumPrinterKey(cli, mem_ctx, handle, key_name, - key_buffer, + buffer, offered, &needed, &werror); } + if (W_ERROR_IS_OK(werror)) { + const char **array; + DATA_BLOB blob = data_blob_const((uint8_t *)buffer, offered); + if (!pull_reg_multi_sz(mem_ctx, &blob, &array)) { + return WERR_NOMEM; + } + *key_buffer = array; + } + return werror; } diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 87735d3..f0bf851 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -9259,7 +9259,7 @@ WERROR _spoolss_EnumPrinterKey(pipes_struct *p, WERROR result = WERR_BADFILE; int i; const char **array = NULL; - + DATA_BLOB blob; DEBUG(4,("_spoolss_EnumPrinterKey\n")); @@ -9288,7 +9288,9 @@ WERROR _spoolss_EnumPrinterKey(pipes_struct *p, goto done; } - *r->out.needed = 4; + /* two byte termination (a multisz) */ + + *r->out.needed = 2; array = talloc_zero_array(r->out.key_buffer, const char *, num_keys + 1); if (!array) { @@ -9297,6 +9299,10 @@ WERROR _spoolss_EnumPrinterKey(pipes_struct *p, } for (i=0; i < num_keys; i++) { + + DEBUG(10,("_spoolss_EnumPrinterKey: adding keyname: %s\n", + keynames[i])); + array[i] = talloc_strdup(array, keynames[i]); if (!array[i]) { result = WERR_NOMEM; @@ -9313,12 +9319,21 @@ WERROR _spoolss_EnumPrinterKey(pipes_struct *p, result = WERR_OK; - *r->out.key_buffer = array; + if (!push_reg_multi_sz(p->mem_ctx, &blob, array)) { + result = WERR_NOMEM; + goto done; + } + + if (r->in.offered == blob.length) { + memcpy(r->out.key_buffer, blob.data, blob.length); + } done: if (!W_ERROR_IS_OK(result)) { TALLOC_FREE(array); - ZERO_STRUCTP(r->out.key_buffer); + if (!W_ERROR_EQUAL(result, WERR_MORE_DATA)) { + *r->out.needed = 0; + } } free_a_printer(&printer, 2); -- 1.6.5.2 From 6129d9579160b7dd6f1f0e2601f94df970e230ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Deschner?= Date: Tue, 24 Nov 2009 15:22:04 +0100 Subject: [PATCH 6/6] s3-spoolss: fixes for _spoolss_EnumPrinterKey client and server. Thanks Metze for review! Guenther (cherry picked from commit 846aa18648f3b34ab5cbc4dc4ba334bbedeab2f4) --- source3/rpc_client/cli_spoolss.c | 4 ++-- source3/rpc_server/srv_spoolss_nt.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source3/rpc_client/cli_spoolss.c b/source3/rpc_client/cli_spoolss.c index ff8736d..5522ca7 100644 --- a/source3/rpc_client/cli_spoolss.c +++ b/source3/rpc_client/cli_spoolss.c @@ -765,7 +765,7 @@ WERROR rpccli_spoolss_enumprinterkey(struct rpc_pipe_client *cli, *key_buffer = NULL; if (offered) { - buffer = talloc_array(mem_ctx, uint16_t, offered); + buffer = talloc_array(mem_ctx, uint16_t, offered/2); W_ERROR_HAVE_NO_MEMORY(buffer); } @@ -779,7 +779,7 @@ WERROR rpccli_spoolss_enumprinterkey(struct rpc_pipe_client *cli, if (W_ERROR_EQUAL(werror, WERR_MORE_DATA)) { offered = needed; - buffer = talloc_realloc(mem_ctx, buffer, uint16_t, needed); + buffer = talloc_realloc(mem_ctx, buffer, uint16_t, needed/2); W_ERROR_HAVE_NO_MEMORY(buffer); status = rpccli_spoolss_EnumPrinterKey(cli, mem_ctx, handle, diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index f0bf851..bf02ee0 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -9324,7 +9324,7 @@ WERROR _spoolss_EnumPrinterKey(pipes_struct *p, goto done; } - if (r->in.offered == blob.length) { + if (r->in.offered >= blob.length) { memcpy(r->out.key_buffer, blob.data, blob.length); } -- 1.6.5.2