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 2 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, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23
24 #include "includes.h"
25 #include "librpc/gen_ndr/ndr_orpc.h"
26
ndr_pull_DUALSTRINGARRAY(struct ndr_pull * ndr,int ndr_flags,struct DUALSTRINGARRAY * ar)27 NTSTATUS ndr_pull_DUALSTRINGARRAY(struct ndr_pull *ndr, int ndr_flags, struct DUALSTRINGARRAY *ar)
28 {
29 uint16_t num_entries, security_offset;
30 uint16_t towerid;
31 uint32_t towernum = 0, conformant_size;
32 TALLOC_CTX *mem_ctx = ndr->current_mem_ctx;
33
34 if (!(ndr_flags & NDR_SCALARS)) {
35 return NT_STATUS_OK;
36 }
37
38 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &conformant_size));
39 NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &num_entries));
40 NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &security_offset));
41
42 ar->stringbindings = talloc_array(mem_ctx, struct STRINGBINDING *, num_entries + 1);
43 ar->stringbindings[0] = NULL;
44
45 do {
46 /* 'Peek' */
47 NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &towerid));
48
49 if (towerid > 0) {
50 ndr->offset -= 2;
51 ar->stringbindings = talloc_realloc(mem_ctx, ar->stringbindings, struct STRINGBINDING *, towernum+2);
52 ar->stringbindings[towernum] = talloc(ar->stringbindings, struct STRINGBINDING);
53 ndr->current_mem_ctx = ar->stringbindings[towernum];
54 NDR_CHECK(ndr_pull_STRINGBINDING(ndr, ndr_flags, ar->stringbindings[towernum]));
55 towernum++;
56 }
57 } while (towerid != 0);
58
59 ar->stringbindings[towernum] = NULL;
60 towernum = 0;
61
62 ar->securitybindings = talloc_array(mem_ctx, struct SECURITYBINDING *, num_entries);
63 ar->securitybindings[0] = NULL;
64
65 do {
66 /* 'Peek' */
67 NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &towerid));
68
69 if (towerid > 0) {
70 ndr->offset -= 2;
71 ar->securitybindings = talloc_realloc(mem_ctx, ar->securitybindings, struct SECURITYBINDING *, towernum+2);
72 ar->securitybindings[towernum] = talloc(ar->securitybindings, struct SECURITYBINDING);
73 ndr->current_mem_ctx = ar->securitybindings[towernum];
74 NDR_CHECK(ndr_pull_SECURITYBINDING(ndr, ndr_flags, ar->securitybindings[towernum]));
75 towernum++;
76 }
77 } while (towerid != 0);
78
79 ar->securitybindings[towernum] = NULL;
80 ndr->current_mem_ctx = mem_ctx;
81
82 return NT_STATUS_OK;
83 }
84
ndr_push_DUALSTRINGARRAY(struct ndr_push * ndr,int ndr_flags,const struct DUALSTRINGARRAY * ar)85 NTSTATUS ndr_push_DUALSTRINGARRAY(struct ndr_push *ndr, int ndr_flags, const struct DUALSTRINGARRAY *ar)
86 {
87 return NT_STATUS_NOT_SUPPORTED;
88 }
89
90 /*
91 print a dom_sid
92 */
ndr_print_DUALSTRINGARRAY(struct ndr_print * ndr,const char * name,const struct DUALSTRINGARRAY * ar)93 void ndr_print_DUALSTRINGARRAY(struct ndr_print *ndr, const char *name, const struct DUALSTRINGARRAY *ar)
94 {
95 int i;
96 ndr->print(ndr, "%-25s: DUALSTRINGARRAY", name);
97 ndr->depth++;
98 ndr->print(ndr, "STRING BINDINGS");
99 ndr->depth++;
100 for (i=0;ar->stringbindings[i];i++) {
101 char *idx = NULL;
102 asprintf(&idx, "[%d]", i);
103 if (idx) {
104 ndr_print_STRINGBINDING(ndr, idx, ar->stringbindings[i]);
105 free(idx);
106 }
107 }
108 ndr->depth--;
109 ndr->print(ndr, "SECURITY BINDINGS");
110 ndr->depth++;
111 for (i=0;ar->securitybindings[i];i++) {
112 char *idx = NULL;
113 asprintf(&idx, "[%d]", i);
114 if (idx) {
115 ndr_print_SECURITYBINDING(ndr, idx, ar->securitybindings[i]);
116 free(idx);
117 }
118 }
119 ndr->depth--;
120 }
121
ndr_pull_STRINGARRAY(struct ndr_pull * ndr,int ndr_flags,struct STRINGARRAY * ar)122 NTSTATUS ndr_pull_STRINGARRAY(struct ndr_pull *ndr, int ndr_flags, struct STRINGARRAY *ar)
123 {
124 uint16_t towerid;
125 uint32_t towernum = 0;
126 uint16_t num_entries;
127 TALLOC_CTX *mem_ctx = ndr->current_mem_ctx;
128
129 if (!(ndr_flags & NDR_SCALARS)) {
130 return NT_STATUS_OK;
131 }
132
133 NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &num_entries));
134
135 ar->stringbindings = talloc_array(mem_ctx, struct STRINGBINDING *, 1);
136 ar->stringbindings[0] = NULL;
137
138 do {
139 /* 'Peek' */
140 NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &towerid));
141
142 if (towerid > 0) {
143 ndr->offset -= 2;
144 ar->stringbindings = talloc_realloc(mem_ctx, ar->stringbindings, struct STRINGBINDING *, towernum+2);
145 ar->stringbindings[towernum] = talloc(ar->stringbindings, struct STRINGBINDING);
146 ndr->current_mem_ctx = ar->stringbindings[towernum];
147 NDR_CHECK(ndr_pull_STRINGBINDING(ndr, ndr_flags, ar->stringbindings[towernum]));
148 towernum++;
149 }
150 } while (towerid != 0);
151
152 ar->stringbindings[towernum] = NULL;
153 towernum = 0;
154
155 ndr->current_mem_ctx = mem_ctx;
156 return NT_STATUS_OK;
157 }
158
ndr_push_STRINGARRAY(struct ndr_push * ndr,int ndr_flags,const struct STRINGARRAY * ar)159 NTSTATUS ndr_push_STRINGARRAY(struct ndr_push *ndr, int ndr_flags, const struct STRINGARRAY *ar)
160 {
161 return NT_STATUS_NOT_SUPPORTED;
162 }
163
164 /*
165 print a dom_sid
166 */
ndr_print_STRINGARRAY(struct ndr_print * ndr,const char * name,const struct STRINGARRAY * ar)167 void ndr_print_STRINGARRAY(struct ndr_print *ndr, const char *name, const struct STRINGARRAY *ar)
168 {
169 int i;
170 ndr->print(ndr, "%-25s: STRINGARRAY", name);
171 ndr->depth++;
172 for (i=0;ar->stringbindings[i];i++) {
173 char *idx = NULL;
174 asprintf(&idx, "[%d]", i);
175 if (idx) {
176 ndr_print_STRINGBINDING(ndr, idx, ar->stringbindings[i]);
177 free(idx);
178 }
179 }
180 ndr->depth--;
181 }
182