summaryrefslogtreecommitdiff
path: root/source4/librpc/ndr/ndr_wmi.c
blob: 6cf42471f8fec4455ad9966663c71b657005a27b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* 
   Unix SMB/CIFS implementation.

   routines for marshalling/unmarshalling DCOM string arrays

   Copyright (C) Jelmer Vernooij 2004
   
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
//#define NDR_CHECK_DEBUG
#include "includes.h"
#include "librpc/gen_ndr/ndr_dcom.h"
#include "librpc/gen_ndr/ndr_wmi.h"
#include "librpc/ndr/ndr_wmi.h"

// Just for debugging
int NDR_CHECK_depth = 0;
int NDR_CHECK_shift = 0x18;

int get_CIMTYPE_size(int t)
{
	if (t & CIM_FLAG_ARRAY) return 4;
	t &= 0x1FF;
	switch (t) {
        case CIM_SINT8:
        case CIM_UINT8:
		return 1;
        case CIM_SINT16:
        case CIM_UINT16:
        case CIM_BOOLEAN:
		return 2;
        case CIM_SINT32:
        case CIM_UINT32:
        case CIM_REAL32:
        case CIM_STRING:
        case CIM_DATETIME:
        case CIM_REFERENCE:
        case CIM_OBJECT:
		return 4;
        case CIM_SINT64:
        case CIM_UINT64:
        case CIM_REAL64:
		return 8;
	default:
		DEBUG(0, ("Unknown CIMTYPE size for %04X", t));
		return 4;
	}
}

enum ndr_err_code ndr_push_BSTR(struct ndr_push *ndr, int ndr_flags, const struct BSTR *r)
{
	uint32_t len;
	uint32_t flags;
	enum ndr_err_code status;
	len = strlen(r->data);
        if (ndr_flags & NDR_SCALARS) {
                NDR_CHECK(ndr_push_align(ndr, 4));
                NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, 0x72657355));
                NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, len));
                NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, 2*len));
		flags = ndr->flags;
		ndr_set_flags(&ndr->flags, LIBNDR_FLAG_STR_NOTERM | LIBNDR_FLAG_STR_SIZE4);
		status = ndr_push_string(ndr, NDR_SCALARS, r->data);
		ndr->flags = flags;
		return status;
        }
        return NDR_ERR_SUCCESS;
}

enum ndr_err_code ndr_pull_BSTR(struct ndr_pull *ndr, int ndr_flags, struct BSTR *r)
{
        return NDR_ERR_BAD_SWITCH;
}

void ndr_print_BSTR(struct ndr_print *ndr, const char *name, const struct BSTR *r)
{
	ndr->print(ndr, "%-25s: BSTR(\"%s\")", name, r->data);
}