summaryrefslogtreecommitdiff
path: root/source4/librpc
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2003-11-21 13:14:17 +0000
committerAndrew Tridgell <tridge@samba.org>2003-11-21 13:14:17 +0000
commita465add90f3291f022104600c6221e8d90287e64 (patch)
tree155a7f43e7a50027be5d9144755bf134ee585810 /source4/librpc
parent82d6f5587b6052a226f90a82314573fb348fb0ce (diff)
downloadsamba-a465add90f3291f022104600c6221e8d90287e64.tar.gz
samba-a465add90f3291f022104600c6221e8d90287e64.tar.bz2
samba-a465add90f3291f022104600c6221e8d90287e64.zip
* changed the way strings are handled in pidl to a much more general
interface. We now support an arbitrary set of flags to each parser, and these can be used to control the string types. I have provided some common IDL string types in librpc/idl/idl_types.h which needs to be included in every IDL file. * added IDL for the endpoint mapper. Added a test suite that enumerates all endpoints on the server. (This used to be commit d2665f36a75b482ff82733f72ffac938c2acf87a)
Diffstat (limited to 'source4/librpc')
-rw-r--r--source4/librpc/idl/atsvc.idl2
-rw-r--r--source4/librpc/idl/dfs.idl2
-rw-r--r--source4/librpc/idl/echo.idl3
-rw-r--r--source4/librpc/idl/epmapper.idl134
-rw-r--r--source4/librpc/idl/eventlog.idl2
-rw-r--r--source4/librpc/idl/lsa.idl4
-rw-r--r--source4/librpc/idl/misc.idl2
-rw-r--r--source4/librpc/idl/samr.idl24
-rw-r--r--source4/librpc/idl/spoolss.idl4
-rw-r--r--source4/librpc/idl/srvsvc.idl4
-rw-r--r--source4/librpc/idl/winreg.idl2
-rw-r--r--source4/librpc/idl/wkssvc.idl2
-rw-r--r--source4/librpc/ndr/libndr.h24
-rw-r--r--source4/librpc/ndr/ndr.c78
-rw-r--r--source4/librpc/ndr/ndr_basic.c408
15 files changed, 449 insertions, 246 deletions
diff --git a/source4/librpc/idl/atsvc.idl b/source4/librpc/idl/atsvc.idl
index 81394c747b..39add81b09 100644
--- a/source4/librpc/idl/atsvc.idl
+++ b/source4/librpc/idl/atsvc.idl
@@ -2,6 +2,8 @@
atsvc interface definition
*/
+#include "idl_types.h"
+
[ uuid(1ff70682-0a51-30e8-076d-740be8cee98b),
version(1.0),
pointer_default(unique)
diff --git a/source4/librpc/idl/dfs.idl b/source4/librpc/idl/dfs.idl
index 8e8488e367..fd9e164ffa 100644
--- a/source4/librpc/idl/dfs.idl
+++ b/source4/librpc/idl/dfs.idl
@@ -2,6 +2,8 @@
dfs interface definition
*/
+#include "idl_types.h"
+
[ uuid(4fc742e0-4a10-11cf-8273-00aa004ae673),
version(3.0),
pointer_default(unique)
diff --git a/source4/librpc/idl/echo.idl b/source4/librpc/idl/echo.idl
index 38650e990d..e6d93e52c4 100644
--- a/source4/librpc/idl/echo.idl
+++ b/source4/librpc/idl/echo.idl
@@ -1,3 +1,6 @@
+#include "idl_types.h"
+
+
[
uuid(60a15ec5-4de8-11d7-a637-005056a20182),
version(1.0)
diff --git a/source4/librpc/idl/epmapper.idl b/source4/librpc/idl/epmapper.idl
new file mode 100644
index 0000000000..c58ceb1fc0
--- /dev/null
+++ b/source4/librpc/idl/epmapper.idl
@@ -0,0 +1,134 @@
+#include "idl_types.h"
+
+/*
+ endpoint mapper interface
+*/
+
+[
+ uuid(e1af8308-5d1f-11c9-91a4-08002b14a0fa),
+ version(3.0),
+ pointer_default(unique)
+]
+interface epmapper
+{
+
+ typedef struct {
+ GUID uuid;
+ uint16 version;
+ } epm_prot_uuid;
+
+ typedef [nodiscriminant] union {
+ [case(13)] epm_prot_uuid uuid;
+ [default] ;
+ } epm_protocol_info;
+
+ typedef struct {
+ uint8 protocol;
+ [switch_is(protocol)] epm_protocol_info info;
+ } epm_lhs;
+
+ typedef struct {
+ uint16 unknown;
+ } epm_rhs;
+
+ typedef struct {
+ [subcontext(2)] epm_lhs lhs;
+ [subcontext(2)] epm_rhs rhs;
+ } epm_floor;
+
+ typedef [flag(NDR_NOALIGN)] struct {
+ uint16 num_floors;
+ epm_floor floors[num_floors];
+ } epm_towers;
+
+ typedef struct {
+ uint32 tower_length;
+ [subcontext(4)] epm_towers towers;
+ } twr_t;
+
+ typedef struct {
+ GUID object;
+ twr_t *tower;
+ ascstr2 annotation;
+ } epm_entry_t;
+
+ typedef struct {
+ GUID uuid;
+ uint16 vers_major;
+ uint16 vers_minor;
+ } rpc_if_id_t;
+
+ /**********************/
+ /* Function 0x0 */
+ void epm_Insert(
+ [in] uint32 num_ents,
+ [in,size_is(num_ents)] epm_entry_t entries[],
+ [in] uint32 replace,
+ [out] uint32 *status
+ );
+
+ /**********************/
+ /* Function 0x1 */
+ void epm_Delete(
+ [in] uint32 num_ents,
+ [in, size_is(num_ents)] epm_entry_t entries[],
+ [out] uint32 *status
+ );
+
+ /**********************/
+ /* Function 0x02 */
+ void epm_Lookup(
+ [in] uint32 inquiry_type,
+ [in] GUID *object,
+ [in] rpc_if_id_t *interface_id,
+ [in] uint32 vers_option,
+ [in, out, ref] policy_handle *entry_handle,
+ [in] uint32 max_ents,
+ [out] uint32 num_ents,
+ [out, length_is(num_ents), size_is(max_ents)] epm_entry_t entries[],
+ [out] uint32 status
+ );
+
+
+ /**********************/
+ /* Function 0x03 */
+
+ typedef struct {
+ twr_t *twr;
+ } twr_p_t;
+
+ void epm_Map(
+ [in] GUID *object,
+ [in] twr_t *map_tower,
+ [in, out] policy_handle *entry_handle,
+ [in] uint32 max_towers,
+ [out] uint32 *num_towers,
+ [out, length_is(*num_towers), size_is(max_towers)] twr_p_t towers[],
+ [out] uint32 *status
+ );
+
+
+ /**********************/
+ /* Function 0x04 */
+ void epm_LookupHandleFree(
+ [in, out] policy_handle *entry_handle,
+ [out] uint32 *status
+ );
+
+ /**********************/
+ /* Function 0x05 */
+ void epm_InqObject(
+ [out] GUID *epm_object,
+ [out] uint32 *status
+ );
+
+
+ /**********************/
+ /* Function 0x05 */
+ void epm_MgmtDelete(
+ [in] uint32 object_speced,
+ [in] GUID *object,
+ [in] twr_t *tower,
+ [out] uint32 *status
+ );
+}
diff --git a/source4/librpc/idl/eventlog.idl b/source4/librpc/idl/eventlog.idl
index a8eba4ae16..ee5bd8bba8 100644
--- a/source4/librpc/idl/eventlog.idl
+++ b/source4/librpc/idl/eventlog.idl
@@ -1,3 +1,5 @@
+#include "idl_types.h"
+
/*
eventlog interface definition
*/
diff --git a/source4/librpc/idl/lsa.idl b/source4/librpc/idl/lsa.idl
index 6aedd33b97..7b2de5bd8f 100644
--- a/source4/librpc/idl/lsa.idl
+++ b/source4/librpc/idl/lsa.idl
@@ -1,3 +1,5 @@
+#include "idl_types.h"
+
/*
lsa interface definition
*/
@@ -54,7 +56,7 @@
typedef struct {
uint32 size;
- [subcontext] security_descriptor *sd;
+ [subcontext(4)] security_descriptor *sd;
} sec_desc_buf;
NTSTATUS lsa_QuerySecObj (
diff --git a/source4/librpc/idl/misc.idl b/source4/librpc/idl/misc.idl
index 031ca89821..04e03fc814 100644
--- a/source4/librpc/idl/misc.idl
+++ b/source4/librpc/idl/misc.idl
@@ -1,3 +1,5 @@
+#include "idl_types.h"
+
/*
miscellaneous IDL structures
*/
diff --git a/source4/librpc/idl/samr.idl b/source4/librpc/idl/samr.idl
index 29ba402503..bb0e85b7de 100644
--- a/source4/librpc/idl/samr.idl
+++ b/source4/librpc/idl/samr.idl
@@ -1,6 +1,7 @@
+#include "idl_types.h"
+
/*
samr interface definition
-
*/
/*
@@ -44,7 +45,7 @@
typedef struct {
uint32 sd_size;
- [subcontext] security_descriptor *sd;
+ [subcontext(4)] security_descriptor *sd;
} samr_SdBuf;
NTSTATUS samr_QuerySecurity (
@@ -727,9 +728,26 @@
/* Function 0x2b */
NTSTATUS samr_TEST_PRIVATE_FUNCTIONS_USER();
+
/************************/
/* Function 0x2c */
- NTSTATUS samr_GET_USRDOM_PWINFO();
+
+/*
+const ULONG DOMAIN_PASSWORD_COMPLEX = 0x00000001;
+const ULONG DOMAIN_PASSWORD_NO_ANON_CHANGE = 0x00000002;
+const ULONG DOMAIN_PASSWORD_NO_CLEAR_CHANGE = 0x00000004;
+const ULONG DOMAIN_PASSWORD_STORE_CLEARTEXT = 0x00000010;
+const ULONG DOMAIN_REFUSE_PASSWORD_CHANGE = 0x00000020;
+*/
+ typedef struct {
+ uint16 min_pwd_len;
+ uint32 passwd_properties;
+ } samr_PwInfo;
+
+ NTSTATUS samr_GetUserPwInfo(
+ [in,ref] policy_handle *handle,
+ [out] samr_PwInfo info
+ );
/************************/
/* Function 0x2d */
diff --git a/source4/librpc/idl/spoolss.idl b/source4/librpc/idl/spoolss.idl
index 586536b69c..a9d653458b 100644
--- a/source4/librpc/idl/spoolss.idl
+++ b/source4/librpc/idl/spoolss.idl
@@ -1,3 +1,5 @@
+#include "idl_types.h"
+
/*
spoolss interface definitions
*/
@@ -179,7 +181,7 @@
[in,ref] policy_handle *handle,
[in] uint32 level,
[in] DATA_BLOB *buffer,
- [out,subcontext,switch_is(level)] spoolss_PrinterInfo *info,
+ [out,subcontext(4),switch_is(level)] spoolss_PrinterInfo *info,
[in,out,ref] uint32 *buf_size
);
diff --git a/source4/librpc/idl/srvsvc.idl b/source4/librpc/idl/srvsvc.idl
index 530b19d6cf..ac421d8626 100644
--- a/source4/librpc/idl/srvsvc.idl
+++ b/source4/librpc/idl/srvsvc.idl
@@ -1,3 +1,5 @@
+#include "idl_types.h"
+
/*
srvsvc interface definitions
*/
@@ -302,7 +304,7 @@
unistr *path;
uint32 *password;
uint32 unknown;
- [subcontext] security_descriptor *sd;
+ [subcontext(4)] security_descriptor *sd;
} srvsvc_NetShare502;
typedef struct {
diff --git a/source4/librpc/idl/winreg.idl b/source4/librpc/idl/winreg.idl
index 68b13f8245..84250a61a5 100644
--- a/source4/librpc/idl/winreg.idl
+++ b/source4/librpc/idl/winreg.idl
@@ -1,3 +1,5 @@
+#include "idl_types.h"
+
/*
winreg interface definition
*/
diff --git a/source4/librpc/idl/wkssvc.idl b/source4/librpc/idl/wkssvc.idl
index 2a1fb83f79..31e37d4759 100644
--- a/source4/librpc/idl/wkssvc.idl
+++ b/source4/librpc/idl/wkssvc.idl
@@ -1,3 +1,5 @@
+#include "idl_types.h"
+
/*
wkssvc interface definitions
*/
diff --git a/source4/librpc/ndr/libndr.h b/source4/librpc/ndr/libndr.h
index 7876d3cc1c..5c771ff2d2 100644
--- a/source4/librpc/ndr/libndr.h
+++ b/source4/librpc/ndr/libndr.h
@@ -91,8 +91,15 @@ struct ndr_print {
void *private;
};
-#define LIBNDR_FLAG_BIGENDIAN 1
+#define LIBNDR_FLAG_BIGENDIAN (1<<0)
+#define LIBNDR_FLAG_NOALIGN (1<<1)
+#define LIBNDR_FLAG_STR_ASCII (1<<2)
+#define LIBNDR_FLAG_STR_LEN4 (1<<3)
+#define LIBNDR_FLAG_STR_SIZE4 (1<<4)
+#define LIBNDR_FLAG_STR_NOTERM (1<<5)
+#define LIBNDR_FLAG_STR_NULLTERM (1<<6)
+#define LIBNDR_STRING_FLAGS (0x7C)
/* useful macro for debugging */
#define NDR_PRINT_DEBUG(type, p) ndr_print_debug((ndr_print_fn_t)ndr_print_ ##type, #p, p)
@@ -110,7 +117,9 @@ enum ndr_err_code {
NDR_ERR_OFFSET,
NDR_ERR_RELATIVE,
NDR_ERR_CHARCNV,
- NDR_ERR_LENGTH
+ NDR_ERR_LENGTH,
+ NDR_ERR_SUBCONTEXT,
+ NDR_ERR_STRING
};
/*
@@ -133,7 +142,9 @@ enum ndr_err_code {
} while(0)
#define NDR_PULL_ALIGN(ndr, n) do { \
- ndr->offset = (ndr->offset + (n-1)) & ~(n-1); \
+ if (!(ndr->flags & LIBNDR_FLAG_NOALIGN)) { \
+ ndr->offset = (ndr->offset + (n-1)) & ~(n-1); \
+ } \
if (ndr->offset >= ndr->data_size) { \
return NT_STATUS_BUFFER_TOO_SMALL; \
} \
@@ -142,8 +153,10 @@ enum ndr_err_code {
#define NDR_PUSH_NEED_BYTES(ndr, n) NDR_CHECK(ndr_push_expand(ndr, ndr->offset+(n)))
#define NDR_PUSH_ALIGN(ndr, n) do { \
- uint32 _pad = (ndr->offset & (n-1)); \
- while (_pad--) NDR_CHECK(ndr_push_uint8(ndr, 0)); \
+ if (!(ndr->flags & LIBNDR_FLAG_NOALIGN)) { \
+ uint32 _pad = (ndr->offset & (n-1)); \
+ while (_pad--) NDR_CHECK(ndr_push_uint8(ndr, 0)); \
+ } \
} while(0)
@@ -201,4 +214,5 @@ typedef void (*ndr_print_union_fn_t)(struct ndr_print *, const char *, uint32, v
#include "librpc/gen_ndr/ndr_srvsvc.h"
#include "librpc/gen_ndr/ndr_atsvc.h"
#include "librpc/gen_ndr/ndr_eventlog.h"
+#include "librpc/gen_ndr/ndr_epmapper.h"
#include "librpc/gen_ndr/ndr_winreg.h"
diff --git a/source4/librpc/ndr/ndr.c b/source4/librpc/ndr/ndr.c
index 2f0754d78f..dcd0066083 100644
--- a/source4/librpc/ndr/ndr.c
+++ b/source4/librpc/ndr/ndr.c
@@ -61,6 +61,7 @@ NTSTATUS ndr_pull_subcontext(struct ndr_pull *ndr, struct ndr_pull *ndr2, uint32
ndr2->data += ndr2->offset;
ndr2->offset = 0;
ndr2->data_size = size;
+ ndr2->flags = ndr->flags;
return NT_STATUS_OK;
}
@@ -400,53 +401,94 @@ NTSTATUS ndr_push_error(struct ndr_push *ndr, enum ndr_err_code err, const char
handle subcontext buffers, which in midl land are user-marshalled, but
we use magic in pidl to make them easier to cope with
*/
+static NTSTATUS ndr_pull_subcontext_header(struct ndr_pull *ndr,
+ size_t sub_size,
+ struct ndr_pull *ndr2)
+{
+ switch (sub_size) {
+ case 0: {
+ uint32 size = ndr->data_size - ndr->offset;
+ if (size == 0) return NT_STATUS_OK;
+ NDR_CHECK(ndr_pull_subcontext(ndr, ndr2, size));
+ break;
+ }
+
+ case 2: {
+ uint16 size;
+ NDR_CHECK(ndr_pull_uint16(ndr, &size));
+ if (size == 0) return NT_STATUS_OK;
+ NDR_CHECK(ndr_pull_subcontext(ndr, ndr2, size));
+ break;
+ }
+
+ case 4: {
+ uint32 size;
+ NDR_CHECK(ndr_pull_uint32(ndr, &size));
+ if (size == 0) return NT_STATUS_OK;
+ NDR_CHECK(ndr_pull_subcontext(ndr, ndr2, size));
+ break;
+ }
+ default:
+ return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext size %d",
+ sub_size);
+ }
+ return NT_STATUS_OK;
+}
+
+/*
+ handle subcontext buffers, which in midl land are user-marshalled, but
+ we use magic in pidl to make them easier to cope with
+*/
NTSTATUS ndr_pull_subcontext_fn(struct ndr_pull *ndr,
+ size_t sub_size,
void *base,
NTSTATUS (*fn)(struct ndr_pull *, void *))
{
- uint32 size;
struct ndr_pull ndr2;
- NDR_CHECK(ndr_pull_uint32(ndr, &size));
- NDR_CHECK(ndr_pull_subcontext(ndr, &ndr2, size));
+ NDR_CHECK(ndr_pull_subcontext_header(ndr, sub_size, &ndr2));
NDR_CHECK(fn(&ndr2, base));
- NDR_CHECK(ndr_pull_advance(ndr, size));
+ if (sub_size) {
+ NDR_CHECK(ndr_pull_advance(ndr, ndr2.data_size));
+ } else {
+ NDR_CHECK(ndr_pull_advance(ndr, ndr2.offset));
+ }
return NT_STATUS_OK;
}
NTSTATUS ndr_pull_subcontext_flags_fn(struct ndr_pull *ndr,
+ size_t sub_size,
void *base,
NTSTATUS (*fn)(struct ndr_pull *, int , void *))
{
- uint32 size;
struct ndr_pull ndr2;
- NDR_CHECK(ndr_pull_uint32(ndr, &size));
- if (size == 0) {
- return NT_STATUS_OK;
- }
- NDR_CHECK(ndr_pull_subcontext(ndr, &ndr2, size));
+ NDR_CHECK(ndr_pull_subcontext_header(ndr, sub_size, &ndr2));
NDR_CHECK(fn(&ndr2, NDR_SCALARS|NDR_BUFFERS, base));
- NDR_CHECK(ndr_pull_advance(ndr, size));
+ if (sub_size) {
+ NDR_CHECK(ndr_pull_advance(ndr, ndr2.data_size));
+ } else {
+ NDR_CHECK(ndr_pull_advance(ndr, ndr2.offset));
+ }
return NT_STATUS_OK;
}
NTSTATUS ndr_pull_subcontext_union_fn(struct ndr_pull *ndr,
+ size_t sub_size,
uint32 level,
void *base,
NTSTATUS (*fn)(struct ndr_pull *, int , uint32 , void *))
{
- uint32 size;
struct ndr_pull ndr2;
- NDR_CHECK(ndr_pull_uint32(ndr, &size));
- if (size == 0) {
- return NT_STATUS_OK;
- }
- NDR_CHECK(ndr_pull_subcontext(ndr, &ndr2, size));
+ NDR_CHECK(ndr_pull_subcontext_header(ndr, sub_size, &ndr2));
NDR_CHECK(fn(&ndr2, NDR_SCALARS|NDR_BUFFERS, level, base));
- NDR_CHECK(ndr_pull_advance(ndr, size));
+ if (sub_size) {
+ NDR_CHECK(ndr_pull_advance(ndr, ndr2.data_size));
+ } else {
+ NDR_CHECK(ndr_pull_advance(ndr, ndr2.offset));
+ }
return NT_STATUS_OK;
}
diff --git a/source4/librpc/ndr/ndr_basic.c b/source4/librpc/ndr/ndr_basic.c
index 49cff11480..56c0ab231e 100644
--- a/source4/librpc/ndr/ndr_basic.c
+++ b/source4/librpc/ndr/ndr_basic.c
@@ -314,119 +314,219 @@ NTSTATUS ndr_push_ptr(struct ndr_push *ndr, const void *p)
which means we can handle the case where a MS programmer
forgot to mark a pointer as unique */
ndr->ptr_count++;
- ptr = 0xaabbcc00 + ndr->ptr_count;
+ ptr = ndr->ptr_count;
}
return ndr_push_uint32(ndr, ptr);
}
-/*
- push a comformant, variable ucs2 string onto the wire from a C string
-*/
-NTSTATUS ndr_push_unistr(struct ndr_push *ndr, const char *s)
-{
- char *ws;
- ssize_t len;
- len = push_ucs2_talloc(ndr->mem_ctx, (smb_ucs2_t **)&ws, s);
- if (len == -1) {
- return NT_STATUS_INVALID_PARAMETER;
- }
- NDR_CHECK(ndr_push_uint32(ndr, len/2));
- NDR_CHECK(ndr_push_uint32(ndr, 0));
- NDR_CHECK(ndr_push_uint32(ndr, len/2));
- NDR_CHECK(ndr_push_bytes(ndr, ws, len));
- return NT_STATUS_OK;
-}
/*
- push a comformant, variable ascii string onto the wire from a C string
- TODO: need to look at what charset this should be in
+ pull a general string from the wire
*/
-NTSTATUS ndr_push_ascstr(struct ndr_push *ndr, const char *s)
+NTSTATUS ndr_pull_string(struct ndr_pull *ndr, int ndr_flags, const char **s)
{
- ssize_t len = s?strlen(s):0;
- NDR_CHECK(ndr_push_uint32(ndr, len));
- NDR_CHECK(ndr_push_uint32(ndr, 0));
- NDR_CHECK(ndr_push_uint32(ndr, len?len+1:0));
- if (s) {
- NDR_CHECK(ndr_push_bytes(ndr, s, len));
+ char *as=NULL;
+ uint32 len1, ofs, len2;
+ int ret;
+
+ if (!(ndr_flags & NDR_SCALARS)) {
+ return NT_STATUS_OK;
}
- return NT_STATUS_OK;
-}
-/*
- push a comformant, variable ucs2 string onto the wire from a C string
- don't send the null
-*/
-NTSTATUS ndr_push_unistr_noterm(struct ndr_push *ndr, const char *s)
-{
- char *ws;
- ssize_t len;
- len = push_ucs2_talloc(ndr->mem_ctx, (smb_ucs2_t **)&ws, s);
- if (len == -1) {
- return NT_STATUS_INVALID_PARAMETER;
+ switch (ndr->flags & LIBNDR_STRING_FLAGS) {
+ case LIBNDR_FLAG_STR_LEN4|LIBNDR_FLAG_STR_SIZE4:
+ case LIBNDR_FLAG_STR_LEN4|LIBNDR_FLAG_STR_SIZE4|LIBNDR_FLAG_STR_NOTERM:
+ NDR_CHECK(ndr_pull_uint32(ndr, &len1));
+ NDR_CHECK(ndr_pull_uint32(ndr, &ofs));
+ NDR_CHECK(ndr_pull_uint32(ndr, &len2));
+ if (len2 > len1) {
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+ if (len2 == 0) {
+ *s = talloc_strdup(ndr->mem_ctx, "");
+ break;
+ }
+ NDR_PULL_NEED_BYTES(ndr, len2*2);
+ ret = convert_string_talloc(ndr->mem_ctx, CH_UCS2, CH_UNIX,
+ ndr->data+ndr->offset,
+ len2*2,
+ (const void **)&as);
+ if (ret == -1) {
+ return ndr_pull_error(ndr, NDR_ERR_CHARCNV,
+ "Bad character conversion");
+ }
+ NDR_CHECK(ndr_pull_advance(ndr, len2*2));
+ *s = as;
+ break;
+
+ case LIBNDR_FLAG_STR_SIZE4:
+ NDR_CHECK(ndr_pull_uint32(ndr, &len1));
+ NDR_PULL_NEED_BYTES(ndr, len1*2);
+ if (len1 == 0) {
+ *s = talloc_strdup(ndr->mem_ctx, "");
+ break;
+ }
+ ret = convert_string_talloc(ndr->mem_ctx, CH_UCS2, CH_UNIX,
+ ndr->data+ndr->offset,
+ len1*2,
+ (const void **)&as);
+ if (ret == -1) {
+ return ndr_pull_error(ndr, NDR_ERR_CHARCNV,
+ "Bad character conversion");
+ }
+ NDR_CHECK(ndr_pull_advance(ndr, len1*2));
+ *s = as;
+ break;
+
+ case LIBNDR_FLAG_STR_NULLTERM:
+ ret = convert_string_talloc(ndr->mem_ctx, CH_UCS2, CH_UNIX,
+ ndr->data+ndr->offset,
+ ndr->data_size - ndr->offset,
+ (const void **)s);
+ if (ret == -1) {
+ return ndr_pull_error(ndr, NDR_ERR_CHARCNV,
+ "Bad character conversion");
+ }
+ NDR_CHECK(ndr_pull_advance(ndr, ret));
+ break;
+
+ case LIBNDR_FLAG_STR_ASCII|LIBNDR_FLAG_STR_LEN4|LIBNDR_FLAG_STR_SIZE4:
+ NDR_CHECK(ndr_pull_uint32(ndr, &len1));
+ NDR_CHECK(ndr_pull_uint32(ndr, &ofs));
+ NDR_CHECK(ndr_pull_uint32(ndr, &len2));
+ if (len2 > len1) {
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+ NDR_ALLOC_N(ndr, as, (len2+1));
+ NDR_CHECK(ndr_pull_bytes(ndr, as, len2));
+ as[len2] = 0;
+ (*s) = as;
+ break;
+
+ case LIBNDR_FLAG_STR_ASCII|LIBNDR_FLAG_STR_LEN4:
+ NDR_CHECK(ndr_pull_uint32(ndr, &ofs));
+ NDR_CHECK(ndr_pull_uint32(ndr, &len2));
+ NDR_ALLOC_N(ndr, as, (len2+1));
+ NDR_CHECK(ndr_pull_bytes(ndr, as, len2));
+ as[len2] = 0;
+ (*s) = as;
+ break;
+
+ default:
+ return ndr_pull_error(ndr, NDR_ERR_STRING, "Bad string flags 0x%x\n",
+ ndr->flags & LIBNDR_STRING_FLAGS);
}
- NDR_CHECK(ndr_push_uint32(ndr, len/2 - 1));
- NDR_CHECK(ndr_push_uint32(ndr, 0));
- NDR_CHECK(ndr_push_uint32(ndr, len/2 - 1));
- NDR_CHECK(ndr_push_bytes(ndr, ws, len - 2));
+
return NT_STATUS_OK;
}
+
/*
- pull a comformant, variable ucs2 string from the wire into a C string
+ push a general string onto the wire
*/
-NTSTATUS ndr_pull_unistr(struct ndr_pull *ndr, const char **s)
+NTSTATUS ndr_push_string(struct ndr_push *ndr, int ndr_flags, const char *s)
{
- char *ws, *as=NULL;
- uint32 len1, ofs, len2;
+ ssize_t s_len, c_len;
+ int ret;
- NDR_CHECK(ndr_pull_uint32(ndr, &len1));
- NDR_CHECK(ndr_pull_uint32(ndr, &ofs));
- NDR_CHECK(ndr_pull_uint32(ndr, &len2));
- if (len2 > len1) {
- return NT_STATUS_INVALID_PARAMETER;
- }
- NDR_ALLOC_N(ndr, ws, (len1+1)*2);
- NDR_CHECK(ndr_pull_bytes(ndr, ws, len2*2));
- SSVAL(ws, len1*2, 0);
- SSVAL(ws, len2*2, 0);
- pull_ucs2_talloc(ndr->mem_ctx, &as, (const smb_ucs2_t *)ws);
- if (!as) {
- return NT_STATUS_INVALID_PARAMETER;
+ if (!(ndr_flags & NDR_SCALARS)) {
+ return NT_STATUS_OK;
}
- *s = as;
- return NT_STATUS_OK;
-}
+
+ s_len = s?strlen(s):0;
+ c_len = s?strlen_m(s):0;
-/*
- pull a comformant, variable ascii string from the wire into a C string
- TODO: check what charset this is in
-*/
-NTSTATUS ndr_pull_ascstr(struct ndr_pull *ndr, const char **s)
-{
- uint32 len1, ofs, len2;
- char *as;
+ switch (ndr->flags & LIBNDR_STRING_FLAGS) {
+ case LIBNDR_FLAG_STR_LEN4|LIBNDR_FLAG_STR_SIZE4:
+ NDR_CHECK(ndr_push_uint32(ndr, c_len+1));
+ NDR_CHECK(ndr_push_uint32(ndr, 0));
+ NDR_CHECK(ndr_push_uint32(ndr, c_len+1));
+ NDR_PUSH_NEED_BYTES(ndr, c_len*2 + 2);
+ ret = convert_string(CH_UNIX, CH_UCS2,
+ s, s_len+1,
+ ndr->data+ndr->offset, c_len*2 + 2);
+ if (ret == -1) {
+ return ndr_push_error(ndr, NDR_ERR_CHARCNV,
+ "Bad character conversion");
+ }
+ ndr->offset += c_len*2 + 2;
+ break;
+
+ case LIBNDR_FLAG_STR_LEN4|LIBNDR_FLAG_STR_SIZE4|LIBNDR_FLAG_STR_NOTERM:
+ NDR_CHECK(ndr_push_uint32(ndr, c_len));
+ NDR_CHECK(ndr_push_uint32(ndr, 0));
+ NDR_CHECK(ndr_push_uint32(ndr, c_len));
+ NDR_PUSH_NEED_BYTES(ndr, c_len*2);
+ ret = convert_string(CH_UNIX, CH_UCS2,
+ s, s_len,
+ ndr->data+ndr->offset, c_len*2);
+ if (ret == -1) {
+ return ndr_push_error(ndr, NDR_ERR_CHARCNV,
+ "Bad character conversion");
+ }
+ ndr->offset += c_len*2;
+ break;
+
+ case LIBNDR_FLAG_STR_SIZE4:
+ NDR_CHECK(ndr_push_uint32(ndr, c_len + 1));
+ NDR_PUSH_NEED_BYTES(ndr, c_len*2 + 2);
+ ret = convert_string(CH_UNIX, CH_UCS2,
+ s, s_len + 1,
+ ndr->data+ndr->offset, c_len*2 + 2);
+ if (ret == -1) {
+ return ndr_push_error(ndr, NDR_ERR_CHARCNV,
+ "Bad character conversion");
+ }
+ ndr->offset += c_len*2 + 2;
+ break;
+
+ case LIBNDR_FLAG_STR_NULLTERM:
+ NDR_PUSH_NEED_BYTES(ndr, c_len*2 + 2);
+ ret = convert_string(CH_UNIX, CH_UCS2,
+ s, s_len+1,
+ ndr->data+ndr->offset, c_len*2 + 2);
+ if (ret == -1) {
+ return ndr_push_error(ndr, NDR_ERR_CHARCNV,
+ "Bad character conversion");
+ }
+ ndr->offset += c_len*2 + 2;
+ break;
+
+ case LIBNDR_FLAG_STR_ASCII|LIBNDR_FLAG_STR_LEN4|LIBNDR_FLAG_STR_SIZE4:
+ NDR_CHECK(ndr_push_uint32(ndr, c_len+1));
+ NDR_CHECK(ndr_push_uint32(ndr, 0));
+ NDR_CHECK(ndr_push_uint32(ndr, c_len+1));
+ NDR_PUSH_NEED_BYTES(ndr, c_len + 1);
+ ret = convert_string(CH_UNIX, CH_DOS,
+ s, s_len + 1,
+ ndr->data+ndr->offset, c_len + 1);
+ if (ret == -1) {
+ return ndr_push_error(ndr, NDR_ERR_CHARCNV,
+ "Bad character conversion");
+ }
+ ndr->offset += c_len + 1;
+ break;
+
+ case LIBNDR_FLAG_STR_ASCII|LIBNDR_FLAG_STR_LEN4:
+ NDR_CHECK(ndr_push_uint32(ndr, 0));
+ NDR_CHECK(ndr_push_uint32(ndr, c_len+1));
+ NDR_PUSH_NEED_BYTES(ndr, c_len + 1);
+ ret = convert_string(CH_UNIX, CH_DOS,
+ s, s_len + 1,
+ ndr->data+ndr->offset, c_len + 1);
+ if (ret == -1) {
+ return ndr_push_error(ndr, NDR_ERR_CHARCNV,
+ "Bad character conversion");
+ }
+ ndr->offset += c_len + 1;
+ break;
- NDR_CHECK(ndr_pull_uint32(ndr, &len1));
- NDR_CHECK(ndr_pull_uint32(ndr, &ofs));
- NDR_CHECK(ndr_pull_uint32(ndr, &len2));
- if (len2 > len1) {
- return NT_STATUS_INVALID_PARAMETER;
+ default:
+ return ndr_push_error(ndr, NDR_ERR_STRING, "Bad string flags 0x%x\n",
+ ndr->flags & LIBNDR_STRING_FLAGS);
}
- NDR_ALLOC_N(ndr, as, (len1+1));
- NDR_CHECK(ndr_pull_bytes(ndr, as, len2));
- as[len2] = 0;
- as[len1] = 0;
- (*s) = as;
- return NT_STATUS_OK;
-}
-/*
- pull a comformant, variable ucs2 string from the wire into a C string
-*/
-NTSTATUS ndr_pull_unistr_noterm(struct ndr_pull *ndr, const char **s)
-{
- return ndr_pull_unistr(ndr, s);
+ return NT_STATUS_OK;
}
/*
@@ -523,7 +623,7 @@ void ndr_print_ptr(struct ndr_print *ndr, const char *name, const void *p)
}
}
-void ndr_print_unistr(struct ndr_print *ndr, const char *name, const char *s)
+void ndr_print_string(struct ndr_print *ndr, const char *name, const char *s)
{
if (s) {
ndr->print(ndr, "%-25s: '%s'", name, s);
@@ -532,16 +632,6 @@ void ndr_print_unistr(struct ndr_print *ndr, const char *name, const char *s)
}
}
-void ndr_print_unistr_noterm(struct ndr_print *ndr, const char *name, const char *s)
-{
- ndr_print_unistr(ndr, name, s);
-}
-
-void ndr_print_ascstr(struct ndr_print *ndr, const char *name, const char *s)
-{
- ndr_print_unistr(ndr, name, s);
-}
-
void ndr_print_NTTIME(struct ndr_print *ndr, const char *name, NTTIME t)
{
ndr->print(ndr, "%-25s: %s", name, nt_time_string(ndr->mem_ctx, &t));
@@ -603,122 +693,6 @@ void ndr_print_GUID(struct ndr_print *ndr, const char *name, const struct GUID *
guid->info[14], guid->info[15]);
}
-
-/*
- pull a null terminated UCS2 string
-*/
-NTSTATUS ndr_pull_nstring(struct ndr_pull *ndr, int ndr_flags, const char **s)
-{
- int ret;
-
- if (!(ndr_flags & NDR_SCALARS)) {
- return NT_STATUS_OK;
- }
-
- ret = convert_string_talloc(ndr->mem_ctx, CH_UCS2, CH_UNIX,
- ndr->data+ndr->offset,
- ndr->data_size - ndr->offset,
- (const void **)s);
- if (ret == -1) {
- return ndr_pull_error(ndr, NDR_ERR_CHARCNV, "Bad character conversion");
- }
- ndr->offset += ret;
- return NT_STATUS_OK;
-}
-
-/*
- pull a length prefixed UCS2 string
-*/
-NTSTATUS ndr_pull_lstring(struct ndr_pull *ndr, int ndr_flags, const char **s)
-{
- int ret;
- uint32 size;
-
- if (!(ndr_flags & NDR_SCALARS)) {
- return NT_STATUS_OK;
- }
-
- NDR_CHECK(ndr_pull_uint32(ndr, &size));
- if (size == 0) {
- *s = NULL;
- return NT_STATUS_OK;
- }
-
- NDR_PULL_NEED_BYTES(ndr, size*2);
-
- ret = convert_string_talloc(ndr->mem_ctx, CH_UCS2, CH_UNIX,
- ndr->data+ndr->offset,
- size*2,
- (const void **)s);
- if (ret == -1) {
- return ndr_pull_error(ndr, NDR_ERR_CHARCNV, "Bad character conversion");
- }
- ndr->offset += size*2;
- return NT_STATUS_OK;
-}
-
-/*
- push a spoolss style "relative string"
-*/
-NTSTATUS ndr_push_nstring(struct ndr_push *ndr, int ndr_flags, const char **s)
-{
- uint32 len;
- int ret;
-
- if (!(ndr_flags & NDR_SCALARS)) {
- return NT_STATUS_OK;
- }
-
- len = 2*(strlen_m(*s)+1);
- NDR_PUSH_NEED_BYTES(ndr, len);
- ret = push_ucs2(NULL, ndr->data + ndr->offset, *s, len, STR_TERMINATE);
- if (ret == -1) {
- return ndr_push_error(ndr, NDR_ERR_CHARCNV, "Bad string conversion");
- }
- ndr->offset += len;
- return NT_STATUS_OK;
-}
-
-/*
- push a length prefixed ucs2 string
-*/
-NTSTATUS ndr_push_lstring(struct ndr_push *ndr, int ndr_flags, const char **s)
-{
- uint32 len;
- int ret;
-
- if (!(ndr_flags & NDR_SCALARS)) {
- return NT_STATUS_OK;
- }
-
- if (! *s) {
- NDR_CHECK(ndr_push_uint32(ndr, 0));
- return NT_STATUS_OK;
- }
-
- len = (strlen_m(*s)+1);
-
- NDR_CHECK(ndr_push_uint32(ndr, len));
- NDR_PUSH_NEED_BYTES(ndr, len*2);
-
- ret = push_ucs2(NULL, ndr->data + ndr->offset, *s, len*2, STR_TERMINATE);
- if (ret == -1) {
- return ndr_push_error(ndr, NDR_ERR_CHARCNV, "Bad string conversion");
- }
- ndr->offset += len*2;
- return NT_STATUS_OK;
-}
-
-void ndr_print_nstring(struct ndr_print *ndr, const char *name, const char **s)
-{
- ndr_print_unistr(ndr, name, *s);
-}
-
-void ndr_print_lstring(struct ndr_print *ndr, const char *name, const char **s)
-{
- ndr_print_unistr(ndr, name, *s);
-}
-
void ndr_print_DATA_BLOB(struct ndr_print *ndr, const char *name, DATA_BLOB r)
{
ndr->print(ndr, "%-25s: DATA_BLOB length=%u", name, r.length);