drsuapi.idl: fix unknowns in drsuapi_DsReplicaObject*
[Samba.git] / source / librpc / ndr / ndr_drsuapi.c
blobaeb81c87bd7d796a0dc91604e8e6e716d210d3ff
1 /*
2 Unix SMB/CIFS implementation.
4 routines for printing some linked list structs in DRSUAPI
6 Copyright (C) Stefan (metze) Metzmacher 2005
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.
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.
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/>.
23 #include "includes.h"
24 #include "librpc/gen_ndr/ndr_drsuapi.h"
25 #include "librpc/gen_ndr/ndr_misc.h"
27 void ndr_print_drsuapi_DsReplicaObjectListItem(struct ndr_print *ndr, const char *name,
28 const struct drsuapi_DsReplicaObjectListItem *r)
30 ndr_print_struct(ndr, name, "drsuapi_DsReplicaObjectListItem");
31 ndr->depth++;
32 ndr_print_ptr(ndr, "next_object", r->next_object);
33 ndr_print_drsuapi_DsReplicaObject(ndr, "object", &r->object);
34 ndr->depth--;
35 if (r->next_object) {
36 ndr_print_drsuapi_DsReplicaObjectListItem(ndr, "next_object", r->next_object);
40 void ndr_print_drsuapi_DsReplicaObjectListItemEx(struct ndr_print *ndr, const char *name, const struct drsuapi_DsReplicaObjectListItemEx *r)
42 ndr_print_struct(ndr, name, "drsuapi_DsReplicaObjectListItemEx");
43 ndr->depth++;
44 ndr_print_ptr(ndr, "next_object", r->next_object);
45 ndr_print_drsuapi_DsReplicaObject(ndr, "object", &r->object);
46 ndr_print_uint32(ndr, "is_nc_prefix", r->is_nc_prefix);
47 ndr_print_ptr(ndr, "parent_object_guid", r->parent_object_guid);
48 ndr->depth++;
49 if (r->parent_object_guid) {
50 ndr_print_GUID(ndr, "parent_object_guid", r->parent_object_guid);
52 ndr->depth--;
53 ndr_print_ptr(ndr, "meta_data_ctr", r->meta_data_ctr);
54 ndr->depth++;
55 if (r->meta_data_ctr) {
56 ndr_print_drsuapi_DsReplicaMetaDataCtr(ndr, "meta_data_ctr", r->meta_data_ctr);
58 ndr->depth--;
59 ndr->depth--;
60 if (r->next_object) {
61 ndr_print_drsuapi_DsReplicaObjectListItemEx(ndr, "next_object", r->next_object);
65 #define _OID_PUSH_CHECK(call) do { \
66 bool _status; \
67 _status = call; \
68 if (_status != true) { \
69 return ndr_push_error(ndr, NDR_ERR_SUBCONTEXT, "OID Conversion Error: %s\n", __location__); \
70 } \
71 } while (0)
73 #define _OID_PULL_CHECK(call) do { \
74 bool _status; \
75 _status = call; \
76 if (_status != true) { \
77 return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT, "OID Conversion Error: %s\n", __location__); \
78 } \
79 } while (0)
81 enum ndr_err_code ndr_push_drsuapi_DsReplicaOID(struct ndr_push *ndr, int ndr_flags, const struct drsuapi_DsReplicaOID *r)
83 if (ndr_flags & NDR_SCALARS) {
84 NDR_CHECK(ndr_push_align(ndr, 4));
85 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, ndr_size_drsuapi_DsReplicaOID_oid(r->oid, 0)));
86 NDR_CHECK(ndr_push_unique_ptr(ndr, r->oid));
88 if (ndr_flags & NDR_BUFFERS) {
89 if (r->oid) {
90 DATA_BLOB blob;
92 if (StrnCaseCmp("ff", r->oid, 2) == 0) {
93 blob = strhex_to_data_blob(NULL, r->oid);
94 if (!blob.data) {
95 return ndr_push_error(ndr, NDR_ERR_SUBCONTEXT,
96 "HEX String Conversion Error: %s\n",
97 __location__);
99 } else {
100 _OID_PUSH_CHECK(ber_write_OID_String(&blob, r->oid));
102 talloc_steal(ndr, blob.data);
104 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, blob.length));
105 NDR_CHECK(ndr_push_array_uint8(ndr, NDR_SCALARS, blob.data, blob.length));
108 return NDR_ERR_SUCCESS;
111 enum ndr_err_code ndr_pull_drsuapi_DsReplicaOID(struct ndr_pull *ndr, int ndr_flags, struct drsuapi_DsReplicaOID *r)
113 uint32_t _ptr_oid;
114 TALLOC_CTX *_mem_save_oid_0;
115 if (ndr_flags & NDR_SCALARS) {
116 NDR_CHECK(ndr_pull_align(ndr, 4));
117 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->__ndr_size));
118 if (r->__ndr_size < 0 || r->__ndr_size > 10000) {
119 return ndr_pull_error(ndr, NDR_ERR_RANGE, "value out of range");
121 NDR_CHECK(ndr_pull_generic_ptr(ndr, &_ptr_oid));
122 if (_ptr_oid) {
123 NDR_PULL_ALLOC(ndr, r->oid);
124 } else {
125 r->oid = NULL;
128 if (ndr_flags & NDR_BUFFERS) {
129 if (r->oid) {
130 DATA_BLOB _oid_array;
131 const char *_oid;
133 _mem_save_oid_0 = NDR_PULL_GET_MEM_CTX(ndr);
134 NDR_PULL_SET_MEM_CTX(ndr, ndr, 0);
135 NDR_CHECK(ndr_pull_array_size(ndr, &r->oid));
136 _oid_array.length = ndr_get_array_size(ndr, &r->oid);
137 NDR_PULL_ALLOC_N(ndr, _oid_array.data, _oid_array.length);
138 NDR_CHECK(ndr_pull_array_uint8(ndr, NDR_SCALARS, _oid_array.data, _oid_array.length));
139 NDR_PULL_SET_MEM_CTX(ndr, _mem_save_oid_0, 0);
141 if (_oid_array.length && _oid_array.data[0] == 0xFF) {
142 _oid = data_blob_hex_string(ndr, &_oid_array);
143 NDR_ERR_HAVE_NO_MEMORY(_oid);
144 } else {
145 _OID_PULL_CHECK(ber_read_OID_String(ndr, _oid_array, &_oid));
147 TALLOC_FREE(_oid_array.data);
148 talloc_steal(r->oid, _oid);
149 r->oid = _oid;
151 if (r->oid) {
152 NDR_CHECK(ndr_check_array_size(ndr, (void*)&r->oid, r->__ndr_size));
155 return NDR_ERR_SUCCESS;
158 size_t ndr_size_drsuapi_DsReplicaOID_oid(const char *oid, int flags)
160 DATA_BLOB _blob;
161 size_t ret = 0;
163 if (!oid) return 0;
165 if (StrnCaseCmp("ff", oid, 2) == 0) {
166 _blob = strhex_to_data_blob(NULL, oid);
167 if (_blob.data) {
168 ret = _blob.length;
170 } else {
171 if (ber_write_OID_String(&_blob, oid)) {
172 ret = _blob.length;
175 data_blob_free(&_blob);
176 return ret;