r9372: - make the subcontext handling autogenerated code look nicer,
[samba.git] / source / librpc / ndr / ndr_krb5pac.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    routines for marshalling/unmarshalling spoolss subcontext buffer structures
5
6    Copyright (C) Stefan Metzmacher 2005
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_krb5pac.h"
26
27 static size_t _ndr_size_PAC_INFO(const union PAC_INFO *r, uint32_t level, int flags)
28 {
29         size_t s = ndr_size_PAC_INFO(r, level, flags);
30         switch (level) {
31                 case PAC_TYPE_LOGON_INFO:
32                         return NDR_ROUND(s,8);
33                 default:
34                         return s;
35         }
36 }
37
38 static size_t _subcontext_size_PAC_INFO(const union PAC_INFO *r, uint32_t level, int flags)
39 {
40         size_t s = ndr_size_PAC_INFO(r, level, flags);
41         return NDR_ROUND(s,8);
42 }
43
44 NTSTATUS ndr_push_PAC_BUFFER(struct ndr_push *ndr, int ndr_flags, const struct PAC_BUFFER *r)
45 {
46         if (ndr_flags & NDR_SCALARS) {
47                 NDR_CHECK(ndr_push_align(ndr, 4));
48                 NDR_CHECK(ndr_push_PAC_TYPE(ndr, NDR_SCALARS, r->type));
49                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, _ndr_size_PAC_INFO(r->info,r->type,0)));
50                 {
51                         uint32_t _flags_save_PAC_INFO = ndr->flags;
52                         ndr_set_flags(&ndr->flags, LIBNDR_FLAG_ALIGN8);
53                         NDR_CHECK(ndr_push_relative_ptr1(ndr, r->info));
54                         ndr->flags = _flags_save_PAC_INFO;
55                 }
56                 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, 0));
57         }
58         if (ndr_flags & NDR_BUFFERS) {
59                 {
60                         uint32_t _flags_save_PAC_INFO = ndr->flags;
61                         ndr_set_flags(&ndr->flags, LIBNDR_FLAG_ALIGN8);
62                         if (r->info) {
63                                 NDR_CHECK(ndr_push_relative_ptr2(ndr, r->info));
64                                 {
65                                         struct ndr_push *_ndr_info;
66                                         NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_info, 0, _subcontext_size_PAC_INFO(r->info,r->type,0)));
67                                         NDR_CHECK(ndr_push_set_switch_value(_ndr_info, r->info, r->type));
68                                         NDR_CHECK(ndr_push_PAC_INFO(_ndr_info, NDR_SCALARS|NDR_BUFFERS, r->info));
69                                         NDR_CHECK(ndr_push_subcontext_end(ndr, _ndr_info, 0, _subcontext_size_PAC_INFO(r->info,r->type,0)));
70                                 }
71                         }
72                         ndr->flags = _flags_save_PAC_INFO;
73                 }
74         }
75         return NT_STATUS_OK;
76 }
77
78 NTSTATUS ndr_pull_PAC_BUFFER(struct ndr_pull *ndr, int ndr_flags, struct PAC_BUFFER *r)
79 {
80         uint32_t _ptr_info;
81         if (ndr_flags & NDR_SCALARS) {
82                 NDR_CHECK(ndr_pull_align(ndr, 4));
83                 NDR_CHECK(ndr_pull_PAC_TYPE(ndr, NDR_SCALARS, &r->type));
84                 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->_ndr_size));
85                 {
86                         uint32_t _flags_save_PAC_INFO = ndr->flags;
87                         ndr_set_flags(&ndr->flags, LIBNDR_FLAG_ALIGN8);
88                         NDR_CHECK(ndr_pull_generic_ptr(ndr, &_ptr_info));
89                         if (_ptr_info) {
90                                 NDR_ALLOC(ndr, r->info);
91                                 NDR_CHECK(ndr_pull_relative_ptr1(ndr, r->info, _ptr_info));
92                         } else {
93                                 r->info = NULL;
94                         }
95                         ndr->flags = _flags_save_PAC_INFO;
96                 }
97                 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->_pad));
98         }
99         if (ndr_flags & NDR_BUFFERS) {
100                 {
101                         uint32_t _flags_save_PAC_INFO = ndr->flags;
102                         ndr_set_flags(&ndr->flags, LIBNDR_FLAG_ALIGN8);
103                         if (r->info) {
104                                 struct ndr_pull_save _relative_save;
105                                 ndr_pull_save(ndr, &_relative_save);
106                                 NDR_CHECK(ndr_pull_relative_ptr2(ndr, r->info));
107                                 {
108                                         struct ndr_pull *_ndr_info;
109                                         NDR_CHECK(ndr_pull_subcontext_start(ndr, &_ndr_info, 0, r->_ndr_size));
110                                         NDR_CHECK(ndr_pull_set_switch_value(_ndr_info, r->info, r->type));
111                                         NDR_CHECK(ndr_pull_PAC_INFO(_ndr_info, NDR_SCALARS|NDR_BUFFERS, r->info));
112                                         NDR_CHECK(ndr_pull_subcontext_end(ndr, _ndr_info, 0, r->_ndr_size));
113                                 }
114                                 ndr_pull_restore(ndr, &_relative_save);
115                         }
116                         ndr->flags = _flags_save_PAC_INFO;
117                 }
118         }
119         return NT_STATUS_OK;
120 }
121
122 void ndr_print_PAC_BUFFER(struct ndr_print *ndr, const char *name, const struct PAC_BUFFER *r)
123 {
124         ndr_print_struct(ndr, name, "PAC_BUFFER");
125         ndr->depth++;
126         ndr_print_PAC_TYPE(ndr, "type", r->type);
127         ndr_print_uint32(ndr, "_ndr_size", (ndr->flags & LIBNDR_PRINT_SET_VALUES)?_ndr_size_PAC_INFO(r->info,r->type,0):r->_ndr_size);
128         ndr_print_ptr(ndr, "info", r->info);
129         ndr->depth++;
130         if (r->info) {
131                 ndr_print_set_switch_value(ndr, r->info, r->type);
132                 ndr_print_PAC_INFO(ndr, "info", r->info);
133         }
134         ndr->depth--;
135         ndr_print_uint32(ndr, "_pad", r->_pad);
136         ndr->depth--;
137 }