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
)
76 memset(info
, 0, sizeof(info
));
77 for (i
= 0; i
< GUID_SIZE
; i
++) {
79 if (p
!= NULL
) p
= '\0';
81 if (p
!= NULL
) sc
= p
+ 1;
85 for (i
= 0; i
< GUID_SIZE
; i
++) {
86 ((GUID
*)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) {
125 int gen_dump_uint8(TALLOC_CTX
*mem_ctx
, struct parse_string
*p
, const char *ptr
, unsigned indent
)
127 return addshort(mem_ctx
, p
, "%u", *(uint8
*)(ptr
));
130 int gen_dump_uint16(TALLOC_CTX
*mem_ctx
, struct parse_string
*p
, const char *ptr
, unsigned indent
)
132 return addshort(mem_ctx
, p
, "%u", *(uint16
*)(ptr
));
135 int gen_dump_uint32(TALLOC_CTX
*mem_ctx
, struct parse_string
*p
, const char *ptr
, unsigned indent
)
137 return addshort(mem_ctx
, p
, "%u", *(uint32
*)(ptr
));
140 int gen_dump_NTTIME(TALLOC_CTX
*mem_ctx
, struct parse_string
*p
, const char *ptr
, unsigned indent
)
144 high
= ((NTTIME
*)(ptr
))->high
;
145 low
= ((NTTIME
*)(ptr
))->low
;
146 return addshort(mem_ctx
, p
, "%u,%u", high
, low
);
149 int gen_dump_DOM_SID(TALLOC_CTX
*mem_ctx
, struct parse_string
*p
, const char *ptr
, unsigned indent
)
153 sid_to_string(sidstr
, (DOM_SID
*)ptr
);
154 return addstr(mem_ctx
, p
, sidstr
);
157 int gen_dump_SEC_ACCESS(TALLOC_CTX
*mem_ctx
, struct parse_string
*p
, const char *ptr
, unsigned indent
)
159 return addshort(mem_ctx
, p
, "%u", ((SEC_ACCESS
*)ptr
)->mask
);
162 int gen_dump_GUID(TALLOC_CTX
*mem_ctx
, struct parse_string
*p
, const char *ptr
, unsigned indent
)
166 for (i
= 0; i
< (GUID_SIZE
- 1); i
++) {
167 if (!(r
= addshort(mem_ctx
, p
, "%d,", ((GUID
*)ptr
)->info
[i
]))) return r
;
169 return addshort(mem_ctx
, p
, "%d", ((GUID
*)ptr
)->info
[i
]);
172 int gen_dump_SEC_ACE(TALLOC_CTX
*mem_ctx
, struct parse_string
*p
, const char *ptr
, unsigned indent
)
174 return gen_dump_struct(mem_ctx
, pinfo_security_ace_info
, p
, ptr
, indent
);
177 int gen_dump_SEC_ACL(TALLOC_CTX
*mem_ctx
, struct parse_string
*p
, const char *ptr
, unsigned indent
)
179 return gen_dump_struct(mem_ctx
, pinfo_security_acl_info
, p
, ptr
, indent
);
182 int gen_dump_SEC_DESC(TALLOC_CTX
*mem_ctx
, struct parse_string
*p
, const char *ptr
, unsigned indent
)
184 return gen_dump_struct(mem_ctx
, pinfo_security_descriptor_info
, p
, ptr
, indent
);
187 int gen_dump_LUID_ATTR(TALLOC_CTX
*mem_ctx
, struct parse_string
*p
, const char *ptr
, unsigned indent
)
189 return gen_dump_struct(mem_ctx
, pinfo_luid_attr_info
, p
, ptr
, indent
);
192 int gen_dump_LUID(TALLOC_CTX
*mem_ctx
, struct parse_string
*p
, const char *ptr
, unsigned indent
)
196 high
= ((LUID
*)(ptr
))->high
;
197 low
= ((LUID
*)(ptr
))->low
;
198 return addshort(mem_ctx
, p
, "%u,%u", high
, low
);