Last of the GUID->struct uuid changes.
[Samba/nascimento.git] / source3 / lib / genparser_samba.c
blob8f469a46d6a35a2ca8b6986a4ccc6f84c1df381f
1 /*
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.
20 #include "includes.h"
21 #include "genparser_samba.h"
23 /* PARSE functions */
25 int gen_parse_uint8(TALLOC_CTX *mem_ctx, char *ptr, const char *str)
27 *(uint8 *)ptr = atoi(str);
28 return 0;
31 int gen_parse_uint16(TALLOC_CTX *mem_ctx, char *ptr, const char *str)
33 *(uint16 *)ptr = atoi(str);
34 return 0;
37 int gen_parse_uint32(TALLOC_CTX *mem_ctx, char *ptr, const char *str)
39 *(uint32 *)ptr = strtoul(str, NULL, 10);
40 return 0;
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) {
46 errno = EINVAL;
47 return -1;
49 return 0;
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;
55 return 0;
58 int gen_parse_SEC_ACCESS(TALLOC_CTX *mem_ctx, char *ptr, const char *str)
60 ((SEC_ACCESS *)ptr)->mask = strtoul(str, NULL, 10);
61 return 0;
64 int gen_parse_GUID(TALLOC_CTX *mem_ctx, char *ptr, const char *str)
66 int info[UUID_FLAT_SIZE];
67 int i;
68 char *sc;
69 char *p;
70 char *m;
72 m = strdup(str);
73 if (!m) return -1;
74 sc = m;
76 memset(info, 0, sizeof(info));
77 for (i = 0; i < UUID_FLAT_SIZE; i++) {
78 p = strchr(sc, ',');
79 if (p != NULL) p = '\0';
80 info[i] = atoi(sc);
81 if (p != NULL) sc = p + 1;
83 free(m);
85 for (i = 0; i < UUID_FLAT_SIZE; i++) {
86 ((UUID_FLAT *)ptr)->info[i] = info[i];
89 return 0;
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) {
115 errno = EINVAL;
116 return -1;
118 return 0;
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;
129 return 0;
132 /* DUMP functions */
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)
151 uint32 low, high;
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)
160 fstring sidstr;
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)
173 int i, r;
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)
203 uint32 low, high;
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");