source: branches/samba-3.5.x/librpc/ndr/ndr_orpc.c

Last change on this file was 414, checked in by Herwig Bauernfeind, 15 years ago

Samba 3.5.0: Initial import

File size: 4.8 KB
Line 
1/*
2 Unix SMB/CIFS implementation.
3
4 routines for marshalling/unmarshalling DCOM string arrays
5
6 Copyright (C) Jelmer Vernooij 2004
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22
23#include "includes.h"
24#include "librpc/gen_ndr/ndr_orpc.h"
25
26enum ndr_err_code ndr_pull_DUALSTRINGARRAY(struct ndr_pull *ndr, int ndr_flags, struct DUALSTRINGARRAY *ar)
27{
28 uint16_t num_entries, security_offset;
29 uint16_t towerid;
30 uint32_t towernum = 0, conformant_size;
31
32 if (!(ndr_flags & NDR_SCALARS)) {
33 return NDR_ERR_SUCCESS;
34 }
35
36 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &conformant_size));
37 NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &num_entries));
38 NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &security_offset));
39
40 ar->stringbindings = talloc_array(ndr, struct STRINGBINDING *, num_entries);
41 ar->stringbindings[0] = NULL;
42
43 do {
44 /* 'Peek' */
45 NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &towerid));
46
47 if (towerid > 0) {
48 ndr->offset -= 2;
49 ar->stringbindings = talloc_realloc(ndr, ar->stringbindings, struct STRINGBINDING *, towernum+2);
50 ar->stringbindings[towernum] = talloc(ndr, struct STRINGBINDING);
51 NDR_CHECK(ndr_pull_STRINGBINDING(ndr, ndr_flags, ar->stringbindings[towernum]));
52 towernum++;
53 }
54 } while (towerid != 0);
55
56 ar->stringbindings[towernum] = NULL;
57 towernum = 0;
58
59 ar->securitybindings = talloc_array(ndr, struct SECURITYBINDING *, num_entries);
60 ar->securitybindings[0] = NULL;
61
62 do {
63 /* 'Peek' */
64 NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &towerid));
65
66 if (towerid > 0) {
67 ndr->offset -= 2;
68 ar->securitybindings = talloc_realloc(ndr, ar->securitybindings, struct SECURITYBINDING *, towernum+2);
69 ar->securitybindings[towernum] = talloc(ndr, struct SECURITYBINDING);
70 NDR_CHECK(ndr_pull_SECURITYBINDING(ndr, ndr_flags, ar->securitybindings[towernum]));
71 towernum++;
72 }
73 } while (towerid != 0);
74
75 ar->securitybindings[towernum] = NULL;
76
77 return NDR_ERR_SUCCESS;
78}
79
80enum ndr_err_code ndr_push_DUALSTRINGARRAY(struct ndr_push *ndr, int ndr_flags, const struct DUALSTRINGARRAY *ar)
81{
82 return ndr_push_error(ndr, NDR_ERR_STRING, "ndr_push_DUALSTRINGARRAY not implemented");
83}
84
85/*
86 print a dom_sid
87*/
88void ndr_print_DUALSTRINGARRAY(struct ndr_print *ndr, const char *name, const struct DUALSTRINGARRAY *ar)
89{
90 int i;
91 ndr->print(ndr, "%-25s: DUALSTRINGARRAY", name);
92 ndr->depth++;
93 ndr->print(ndr, "STRING BINDINGS");
94 ndr->depth++;
95 for (i=0;ar->stringbindings[i];i++) {
96 char *idx = NULL;
97 asprintf(&idx, "[%d]", i);
98 if (idx) {
99 ndr_print_STRINGBINDING(ndr, idx, ar->stringbindings[i]);
100 free(idx);
101 }
102 }
103 ndr->depth--;
104 ndr->print(ndr, "SECURITY BINDINGS");
105 ndr->depth++;
106 for (i=0;ar->securitybindings[i];i++) {
107 char *idx = NULL;
108 asprintf(&idx, "[%d]", i);
109 if (idx) {
110 ndr_print_SECURITYBINDING(ndr, idx, ar->securitybindings[i]);
111 free(idx);
112 }
113 }
114 ndr->depth--;
115}
116
117enum ndr_err_code ndr_pull_STRINGARRAY(struct ndr_pull *ndr, int ndr_flags, struct STRINGARRAY *ar)
118{
119 uint16_t towerid;
120 uint32_t towernum = 0;
121 uint16_t num_entries;
122
123 if (!(ndr_flags & NDR_SCALARS)) {
124 return NDR_ERR_SUCCESS;
125 }
126
127 NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &num_entries));
128
129 ar->stringbindings = talloc_array(ndr, struct STRINGBINDING *, 1);
130 ar->stringbindings[0] = NULL;
131
132 do {
133 /* 'Peek' */
134 NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &towerid));
135
136 if (towerid > 0) {
137 ndr->offset -= 2;
138 ar->stringbindings = talloc_realloc(ndr, ar->stringbindings, struct STRINGBINDING *, towernum+2);
139 ar->stringbindings[towernum] = talloc(ndr, struct STRINGBINDING);
140 NDR_CHECK(ndr_pull_STRINGBINDING(ndr, ndr_flags, ar->stringbindings[towernum]));
141 towernum++;
142 }
143 } while (towerid != 0);
144
145 ar->stringbindings[towernum] = NULL;
146 towernum = 0;
147
148 return NDR_ERR_SUCCESS;
149}
150
151enum ndr_err_code ndr_push_STRINGARRAY(struct ndr_push *ndr, int ndr_flags, const struct STRINGARRAY *ar)
152{
153 return ndr_push_error(ndr, NDR_ERR_STRING, "ndr_push_STRINGARRAY not implemented");
154}
155
156/*
157 print a dom_sid
158*/
159void ndr_print_STRINGARRAY(struct ndr_print *ndr, const char *name, const struct STRINGARRAY *ar)
160{
161 int i;
162 ndr->print(ndr, "%-25s: STRINGARRAY", name);
163 ndr->depth++;
164 for (i=0;ar->stringbindings[i];i++) {
165 char *idx = NULL;
166 asprintf(&idx, "[%d]", i);
167 if (idx) {
168 ndr_print_STRINGBINDING(ndr, idx, ar->stringbindings[i]);
169 free(idx);
170 }
171 }
172 ndr->depth--;
173}
Note: See TracBrowser for help on using the repository browser.