Finish conversion of Browse options
[Samba.git] / source / lib / genparser_samba.c
blobbece5877473cc270f93a01918707c0baa8d5ca0c
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[GUID_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 < GUID_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 < GUID_SIZE; i++) {
86 ((GUID *)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;
123 /* DUMP functions */
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)
142 uint32 low, high;
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)
151 fstring sidstr;
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)
164 int i, r;
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)
194 uint32 low, high;
196 high = ((LUID *)(ptr))->high;
197 low = ((LUID *)(ptr))->low;
198 return addshort(mem_ctx, p, "%u,%u", high, low);