summaryrefslogtreecommitdiffstats
path: root/librpc/ndr/ndr_orpc.c
blob: 936a56b5e65984009daad473432ecd38f4532815 (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/* 
   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 3 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, see <http://www.gnu.org/licenses/>.
*/


#include "includes.h"
#include "librpc/gen_ndr/ndr_orpc.h"

enum ndr_err_code ndr_pull_DUALSTRINGARRAY(struct ndr_pull *ndr, int ndr_flags, struct DUALSTRINGARRAY *ar)
{
	uint16_t num_entries, security_offset;
	uint16_t towerid;
	uint32_t towernum = 0, conformant_size;

	if (!(ndr_flags & NDR_SCALARS)) {
		return NDR_ERR_SUCCESS;
	}

	NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &conformant_size));
	NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &num_entries));
	NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &security_offset));

	ar->stringbindings = talloc_array(ndr, struct STRINGBINDING *, num_entries);
	ar->stringbindings[0] = NULL;

	do {
		/* 'Peek' */
		NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &towerid));

		if (towerid > 0) {
			ndr->offset -= 2; 
			ar->stringbindings = talloc_realloc(ndr, ar->stringbindings, struct STRINGBINDING *, towernum+2);
			ar->stringbindings[towernum] = talloc(ndr, struct STRINGBINDING);
			NDR_CHECK(ndr_pull_STRINGBINDING(ndr, ndr_flags, ar->stringbindings[towernum]));
			towernum++;
		}
	} while (towerid != 0);

	ar->stringbindings[towernum] = NULL;
	towernum = 0;

	ar->securitybindings = talloc_array(ndr, struct SECURITYBINDING *, num_entries);
	ar->securitybindings[0] = NULL;

	do {
		/* 'Peek' */
		NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &towerid));

		if (towerid > 0) {
			ndr->offset -= 2; 
			ar->securitybindings = talloc_realloc(ndr, ar->securitybindings, struct SECURITYBINDING *, towernum+2);
			ar->securitybindings[towernum] = talloc(ndr, struct SECURITYBINDING);
			NDR_CHECK(ndr_pull_SECURITYBINDING(ndr, ndr_flags, ar->securitybindings[towernum]));
			towernum++;
		}
	} while (towerid != 0);
	
	ar->securitybindings[towernum] = NULL;
	
	return NDR_ERR_SUCCESS;
}

enum ndr_err_code ndr_push_DUALSTRINGARRAY(struct ndr_push *ndr, int ndr_flags, const struct DUALSTRINGARRAY *ar)
{
	return ndr_push_error(ndr, NDR_ERR_STRING, "ndr_push_DUALSTRINGARRAY not implemented");
}

/*
  print a dom_sid
*/
void ndr_print_DUALSTRINGARRAY(struct ndr_print *ndr, const char *name, const struct DUALSTRINGARRAY *ar)
{
	int i;
	ndr->print(ndr, "%-25s: DUALSTRINGARRAY", name);
	ndr->depth++;
	ndr->print(ndr, "STRING BINDINGS");
	ndr->depth++;
	for (i=0;ar->stringbindings[i];i++)	{
		char idx[13];	/* 2^32 has 10 digits */
		snprintf(idx, sizeof(idx), "[%d]", i);
		ndr_print_STRINGBINDING(ndr, idx, ar->stringbindings[i]);
	}
	ndr->depth--;
	ndr->print(ndr, "SECURITY BINDINGS");
	ndr->depth++;
	for (i=0;ar->securitybindings[i];i++)	{
		char idx[13];	/* 2^32 has 10 digits */
		snprintf(idx, sizeof(idx), "[%d]", i);
		ndr_print_SECURITYBINDING(ndr, idx, ar->securitybindings[i]);
	}
	ndr->depth--;
}

enum ndr_err_code ndr_pull_STRINGARRAY(struct ndr_pull *ndr, int ndr_flags, struct STRINGARRAY *ar)
{
	uint16_t towerid;
	uint32_t towernum = 0;
	uint16_t num_entries;

	if (!(ndr_flags & NDR_SCALARS)) {
		return NDR_ERR_SUCCESS;
	}

	NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &num_entries));

	ar->stringbindings = talloc_array(ndr, struct STRINGBINDING *, 1);
	ar->stringbindings[0] = NULL;

	do {
		/* 'Peek' */
		NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &towerid));

		if (towerid > 0) {
			ndr->offset -= 2; 
			ar->stringbindings = talloc_realloc(ndr, ar->stringbindings, struct STRINGBINDING *, towernum+2);
			ar->stringbindings[towernum] = talloc(ndr, struct STRINGBINDING);
			NDR_CHECK(ndr_pull_STRINGBINDING(ndr, ndr_flags, ar->stringbindings[towernum]));
			towernum++;
		}
	} while (towerid != 0);

	ar->stringbindings[towernum] = NULL;
	towernum = 0;

	return NDR_ERR_SUCCESS;
}

enum ndr_err_code ndr_push_STRINGARRAY(struct ndr_push *ndr, int ndr_flags, const struct STRINGARRAY *ar)
{
	return ndr_push_error(ndr, NDR_ERR_STRING, "ndr_push_STRINGARRAY not implemented");
}

/*
  print a dom_sid
*/
void ndr_print_STRINGARRAY(struct ndr_print *ndr, const char *name, const struct STRINGARRAY *ar)
{
	int i;
	ndr->print(ndr, "%-25s: STRINGARRAY", name);
	ndr->depth++;
	for (i=0;ar->stringbindings[i];i++)	{
		char idx[13];	/* 2^32 has 10 digits */
		snprintf(idx, sizeof(idx), "[%d]", i);
		ndr_print_STRINGBINDING(ndr, idx, ar->stringbindings[i]);
	}
	ndr->depth--;
}