Add autogen.sh from distcc via mbp.
[kai/samba.git] / source / lib / genparser_samba.c
1 /*
2    Copyright (C) Andrew Tridgell <genstruct@tridgell.net> 2002
3    Copyright (C) Simo Sorce <idra@samba.org> 2002
4    
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.
9    
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.
14    
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.
18 */
19
20 #include "includes.h"
21 #include "genparser_samba.h"
22
23 /* PARSE functions */
24
25 int gen_parse_uint8(char *ptr, const char *str)
26 {
27         *(uint8 *)ptr = atoi(str);
28         return 0;
29 }
30
31 int gen_parse_uint16(char *ptr, const char *str)
32 {
33         *(uint16 *)ptr = atoi(str);
34         return 0;
35 }
36
37 int gen_parse_uint32(char *ptr, const char *str)
38 {
39         *(uint32 *)ptr = strtoul(str, NULL, 10);
40         return 0;
41 }
42
43 int gen_parse_NTTIME(char *ptr, const char *str)
44 {
45         if(sscanf(str, "%u,%u", &(((NTTIME *)(ptr))->high), &(((NTTIME *)(ptr))->low)) != 2) {
46                 errno = EINVAL;
47                 return -1;
48         }
49         return 0;
50 }
51
52 int gen_parse_DOM_SID(char *ptr, const char *str)
53 {
54         if(!string_to_sid((DOM_SID *)ptr, str)) return -1;
55         return 0;
56 }
57
58 int gen_parse_SEC_ACCESS(char *ptr, const char *str)
59 {
60         ((SEC_ACCESS *)ptr)->mask = strtoul(str, NULL, 10);
61         return 0;
62 }
63
64 int gen_parse_GUID(char *ptr, const char *str)
65 {
66         int info[GUID_SIZE];
67         int i;
68         char *sc;
69         char *p;
70         char *m;
71
72         m = strdup(str);
73         if (!m) return -1;
74         sc = m;
75         
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;
82         }
83         free(m);
84                 
85         for (i = 0; i < GUID_SIZE; i++) {
86                 ((GUID *)ptr)->info[i] = info[i];
87         }
88                 
89         return 0;
90 }
91
92 int gen_parse_SEC_ACE(char *ptr, const char *str)
93 {
94         return gen_parse_struct(pinfo_security_ace_info, ptr, str);
95 }
96
97 int gen_parse_SEC_ACL(char *ptr, const char *str)
98 {
99         return gen_parse_struct(pinfo_security_acl_info, ptr, str);
100 }
101
102 int gen_parse_SEC_DESC(char *ptr, const char *str)
103 {
104         return gen_parse_struct(pinfo_security_descriptor_info, ptr, str);
105 }
106
107 int gen_parse_LUID_ATTR(char *ptr, const char *str)
108 {
109         return gen_parse_struct(pinfo_luid_attr_info, ptr, str);
110 }
111
112 int gen_parse_LUID(char *ptr, const char *str)
113 {
114         if(sscanf(str, "%u,%u", &(((LUID *)(ptr))->high), &(((LUID *)(ptr))->low)) != 2) {
115                 errno = EINVAL;
116                 return -1;
117         }
118         return 0;
119 }
120
121
122
123 /* DUMP functions */
124
125 int gen_dump_uint8(struct parse_string *p, const char *ptr, unsigned indent)
126 {
127         return addshort(p, "%u", *(uint8 *)(ptr));
128 }
129
130 int gen_dump_uint16(struct parse_string *p, const char *ptr, unsigned indent)
131 {
132         return addshort(p, "%u", *(uint16 *)(ptr));
133 }
134
135 int gen_dump_uint32(struct parse_string *p, const char *ptr, unsigned indent)
136 {
137         return addshort(p, "%u", *(uint32 *)(ptr));
138 }
139
140 int gen_dump_NTTIME(struct parse_string *p, const char *ptr, unsigned indent)
141 {
142         uint32 low, high;
143
144         high = ((NTTIME *)(ptr))->high;
145         low = ((NTTIME *)(ptr))->low;
146         return addshort(p, "%u,%u", high, low);
147 }
148
149 int gen_dump_DOM_SID(struct parse_string *p, const char *ptr, unsigned indent)
150 {
151         fstring sidstr;
152
153         sid_to_string(sidstr, (DOM_SID *)ptr);
154         return addstr(p, sidstr);
155 }
156
157 int gen_dump_SEC_ACCESS(struct parse_string *p, const char *ptr, unsigned indent)
158 {
159         return addshort(p, "%u", ((SEC_ACCESS *)ptr)->mask);
160 }
161
162 int gen_dump_GUID(struct parse_string *p, const char *ptr, unsigned indent)
163 {
164         int i, r;
165
166         for (i = 0; i < (GUID_SIZE - 1); i++) {
167                 if (!(r = addshort(p, "%d,", ((GUID *)ptr)->info[i]))) return r;
168         }
169         return addshort(p, "%d", ((GUID *)ptr)->info[i]);
170 }
171
172 int gen_dump_SEC_ACE(struct parse_string *p, const char *ptr, unsigned indent)
173 {
174         return gen_dump_struct(pinfo_security_ace_info, p, ptr, indent);
175 }
176
177 int gen_dump_SEC_ACL(struct parse_string *p, const char *ptr, unsigned indent)
178 {
179         return gen_dump_struct(pinfo_security_acl_info, p, ptr, indent);
180 }
181
182 int gen_dump_SEC_DESC(struct parse_string *p, const char *ptr, unsigned indent)
183 {
184         return gen_dump_struct(pinfo_security_descriptor_info, p, ptr, indent);
185 }
186
187 int gen_dump_LUID_ATTR(struct parse_string *p, const char *ptr, unsigned indent)
188 {
189         return gen_dump_struct(pinfo_luid_attr_info, p, ptr, indent);
190 }
191
192 int gen_dump_LUID(struct parse_string *p, const char *ptr, unsigned indent)
193 {
194         uint32 low, high;
195
196         high = ((LUID *)(ptr))->high;
197         low = ((LUID *)(ptr))->low;
198         return addshort(p, "%u,%u", high, low);
199 }
200