2 Copyright (C) Andrew Tridgell <genstruct@tridgell.net> 2002
3 Copyright (C) Simo Sorce <idra@samba.org> 2002
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "genparser_samba.h"
25 int gen_parse_uint8(TALLOC_CTX
*mem_ctx
, char *ptr
, const char *str
)
27 *(uint8
*)ptr
= atoi(str
);
31 int gen_parse_uint16(TALLOC_CTX
*mem_ctx
, char *ptr
, const char *str
)
33 *(uint16
*)ptr
= atoi(str
);
37 int gen_parse_uint32(TALLOC_CTX
*mem_ctx
, char *ptr
, const char *str
)
39 *(uint32
*)ptr
= strtoul(str
, NULL
, 10);
43 int gen_parse_NTTIME(TALLOC_CTX
*mem_ctx
, char *ptr
, const char *str
)
45 if(sscanf(str
, "%u,%u", &(((NTTIME
*)(ptr
))->high
), &(((NTTIME
*)(ptr
))->low
)) != 2) {
52 int gen_parse_DOM_SID(TALLOC_CTX
*mem_ctx
, char *ptr
, const char *str
)
54 if(!string_to_sid((DOM_SID
*)ptr
, str
)) return -1;
58 int gen_parse_SEC_ACCESS(TALLOC_CTX
*mem_ctx
, char *ptr
, const char *str
)
60 ((SEC_ACCESS
*)ptr
)->mask
= strtoul(str
, NULL
, 10);
64 int gen_parse_GUID(TALLOC_CTX
*mem_ctx
, char *ptr
, const char *str
)
66 int info
[UUID_FLAT_SIZE
];
76 memset(info
, 0, sizeof(info
));
77 for (i
= 0; i
< UUID_FLAT_SIZE
; i
++) {
79 if (p
!= NULL
) p
= '\0';
81 if (p
!= NULL
) sc
= p
+ 1;
85 for (i
= 0; i
< UUID_FLAT_SIZE
; i
++) {
86 ((UUID_FLAT
*)ptr
)->info
[i
] = info
[i
];
92 int gen_parse_SEC_ACE(TALLOC_CTX
*mem_ctx
, char *ptr
, const char *str
)
94 return gen_parse_struct(mem_ctx
, pinfo_security_ace_info
, ptr
, str
);
97 int gen_parse_SEC_ACL(TALLOC_CTX
*mem_ctx
, char *ptr
, const char *str
)
99 return gen_parse_struct(mem_ctx
, pinfo_security_acl_info
, ptr
, str
);
102 int gen_parse_SEC_DESC(TALLOC_CTX
*mem_ctx
, char *ptr
, const char *str
)
104 return gen_parse_struct(mem_ctx
, pinfo_security_descriptor_info
, ptr
, str
);
107 int gen_parse_LUID_ATTR(TALLOC_CTX
*mem_ctx
, char *ptr
, const char *str
)
109 return gen_parse_struct(mem_ctx
, pinfo_luid_attr_info
, ptr
, str
);
112 int gen_parse_LUID(TALLOC_CTX
*mem_ctx
, char *ptr
, const char *str
)
114 if(sscanf(str
, "%u,%u", &(((LUID
*)(ptr
))->high
), &(((LUID
*)(ptr
))->low
)) != 2) {
121 int gen_parse_DATA_BLOB(TALLOC_CTX
*mem_ctx
, char *ptr
, const char *str
)
123 return gen_parse_struct(mem_ctx
, pinfo_data_blob_info
, ptr
, str
);
126 int gen_parse_TALLOC_CTX(TALLOC_CTX
*mem_ctx
, char *ptr
, const char *str
)
128 (TALLOC_CTX
*)ptr
= NULL
;
134 int gen_dump_uint8(TALLOC_CTX
*mem_ctx
, struct parse_string
*p
, const char *ptr
, unsigned indent
)
136 return addshort(mem_ctx
, p
, "%u", *(uint8
*)(ptr
));
139 int gen_dump_uint16(TALLOC_CTX
*mem_ctx
, struct parse_string
*p
, const char *ptr
, unsigned indent
)
141 return addshort(mem_ctx
, p
, "%u", *(uint16
*)(ptr
));
144 int gen_dump_uint32(TALLOC_CTX
*mem_ctx
, struct parse_string
*p
, const char *ptr
, unsigned indent
)
146 return addshort(mem_ctx
, p
, "%u", *(uint32
*)(ptr
));
149 int gen_dump_NTTIME(TALLOC_CTX
*mem_ctx
, struct parse_string
*p
, const char *ptr
, unsigned indent
)
153 high
= ((NTTIME
*)(ptr
))->high
;
154 low
= ((NTTIME
*)(ptr
))->low
;
155 return addshort(mem_ctx
, p
, "%u,%u", high
, low
);
158 int gen_dump_DOM_SID(TALLOC_CTX
*mem_ctx
, struct parse_string
*p
, const char *ptr
, unsigned indent
)
162 sid_to_string(sidstr
, (DOM_SID
*)ptr
);
163 return addstr(mem_ctx
, p
, sidstr
);
166 int gen_dump_SEC_ACCESS(TALLOC_CTX
*mem_ctx
, struct parse_string
*p
, const char *ptr
, unsigned indent
)
168 return addshort(mem_ctx
, p
, "%u", ((SEC_ACCESS
*)ptr
)->mask
);
171 int gen_dump_GUID(TALLOC_CTX
*mem_ctx
, struct parse_string
*p
, const char *ptr
, unsigned indent
)
175 for (i
= 0; i
< (UUID_FLAT_SIZE
- 1); i
++) {
176 if (!(r
= addshort(mem_ctx
, p
, "%d,", ((UUID_FLAT
*)ptr
)->info
[i
]))) return r
;
178 return addshort(mem_ctx
, p
, "%d", ((UUID_FLAT
*)ptr
)->info
[i
]);
181 int gen_dump_SEC_ACE(TALLOC_CTX
*mem_ctx
, struct parse_string
*p
, const char *ptr
, unsigned indent
)
183 return gen_dump_struct(mem_ctx
, pinfo_security_ace_info
, p
, ptr
, indent
);
186 int gen_dump_SEC_ACL(TALLOC_CTX
*mem_ctx
, struct parse_string
*p
, const char *ptr
, unsigned indent
)
188 return gen_dump_struct(mem_ctx
, pinfo_security_acl_info
, p
, ptr
, indent
);
191 int gen_dump_SEC_DESC(TALLOC_CTX
*mem_ctx
, struct parse_string
*p
, const char *ptr
, unsigned indent
)
193 return gen_dump_struct(mem_ctx
, pinfo_security_descriptor_info
, p
, ptr
, indent
);
196 int gen_dump_LUID_ATTR(TALLOC_CTX
*mem_ctx
, struct parse_string
*p
, const char *ptr
, unsigned indent
)
198 return gen_dump_struct(mem_ctx
, pinfo_luid_attr_info
, p
, ptr
, indent
);
201 int gen_dump_LUID(TALLOC_CTX
*mem_ctx
, struct parse_string
*p
, const char *ptr
, unsigned indent
)
205 high
= ((LUID
*)(ptr
))->high
;
206 low
= ((LUID
*)(ptr
))->low
;
207 return addshort(mem_ctx
, p
, "%u,%u", high
, low
);
210 int gen_dump_DATA_BLOB(TALLOC_CTX
*mem_ctx
, struct parse_string
*p
, const char *ptr
, unsigned indent
)
212 return gen_dump_struct(mem_ctx
, pinfo_data_blob_info
, p
, ptr
, indent
);
215 int gen_dump_TALLOC_CTX(TALLOC_CTX
*mem_ctx
, struct parse_string
*p
, const char *ptr
, unsigned indent
)
217 return addshort(mem_ctx
, p
, "TALLOC_CTX");