1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
/*
Copyright (C) Andrew Tridgell <genstruct@tridgell.net> 2002
Copyright (C) Simo Sorce <idra@samba.org> 2002
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
#include "genparser_samba.h"
/* PARSE functions */
int gen_parse_uint8(TALLOC_CTX *mem_ctx, char *ptr, const char *str)
{
*(uint8 *)ptr = atoi(str);
return 0;
}
int gen_parse_uint16(TALLOC_CTX *mem_ctx, char *ptr, const char *str)
{
*(uint16 *)ptr = atoi(str);
return 0;
}
int gen_parse_uint32(TALLOC_CTX *mem_ctx, char *ptr, const char *str)
{
*(uint32 *)ptr = strtoul(str, NULL, 10);
return 0;
}
int gen_parse_NTTIME(TALLOC_CTX *mem_ctx, char *ptr, const char *str)
{
if(sscanf(str, "%u,%u", &(((NTTIME *)(ptr))->high), &(((NTTIME *)(ptr))->low)) != 2) {
errno = EINVAL;
return -1;
}
return 0;
}
int gen_parse_DOM_SID(TALLOC_CTX *mem_ctx, char *ptr, const char *str)
{
if(!string_to_sid((DOM_SID *)ptr, str)) return -1;
return 0;
}
int gen_parse_SEC_ACCESS(TALLOC_CTX *mem_ctx, char *ptr, const char *str)
{
((SEC_ACCESS *)ptr)->mask = strtoul(str, NULL, 10);
return 0;
}
int gen_parse_GUID(TALLOC_CTX *mem_ctx, char *ptr, const char *str)
{
int info[GUID_SIZE];
int i;
char *sc;
char *p;
char *m;
m = strdup(str);
if (!m) return -1;
sc = m;
memset(info, 0, sizeof(info));
for (i = 0; i < GUID_SIZE; i++) {
p = strchr(sc, ',');
if (p != NULL) p = '\0';
info[i] = atoi(sc);
if (p != NULL) sc = p + 1;
}
free(m);
for (i = 0; i < GUID_SIZE; i++) {
((GUID *)ptr)->info[i] = info[i];
}
return 0;
}
int gen_parse_SEC_ACE(TALLOC_CTX *mem_ctx, char *ptr, const char *str)
{
return gen_parse_struct(mem_ctx, pinfo_security_ace_info, ptr, str);
}
int gen_parse_SEC_ACL(TALLOC_CTX *mem_ctx, char *ptr, const char *str)
{
return gen_parse_struct(mem_ctx, pinfo_security_acl_info, ptr, str);
}
int gen_parse_SEC_DESC(TALLOC_CTX *mem_ctx, char *ptr, const char *str)
{
return gen_parse_struct(mem_ctx, pinfo_security_descriptor_info, ptr, str);
}
int gen_parse_LUID_ATTR(TALLOC_CTX *mem_ctx, char *ptr, const char *str)
{
return gen_parse_struct(mem_ctx, pinfo_luid_attr_info, ptr, str);
}
int gen_parse_LUID(TALLOC_CTX *mem_ctx, char *ptr, const char *str)
{
if(sscanf(str, "%u,%u", &(((LUID *)(ptr))->high), &(((LUID *)(ptr))->low)) != 2) {
errno = EINVAL;
return -1;
}
return 0;
}
/* DUMP functions */
int gen_dump_uint8(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent)
{
return addshort(mem_ctx, p, "%u", *(uint8 *)(ptr));
}
int gen_dump_uint16(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent)
{
return addshort(mem_ctx, p, "%u", *(uint16 *)(ptr));
}
int gen_dump_uint32(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent)
{
return addshort(mem_ctx, p, "%u", *(uint32 *)(ptr));
}
int gen_dump_NTTIME(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent)
{
uint32 low, high;
high = ((NTTIME *)(ptr))->high;
low = ((NTTIME *)(ptr))->low;
return addshort(mem_ctx, p, "%u,%u", high, low);
}
int gen_dump_DOM_SID(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent)
{
fstring sidstr;
sid_to_string(sidstr, (DOM_SID *)ptr);
return addstr(mem_ctx, p, sidstr);
}
int gen_dump_SEC_ACCESS(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent)
{
return addshort(mem_ctx, p, "%u", ((SEC_ACCESS *)ptr)->mask);
}
int gen_dump_GUID(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent)
{
int i, r;
for (i = 0; i < (GUID_SIZE - 1); i++) {
if (!(r = addshort(mem_ctx, p, "%d,", ((GUID *)ptr)->info[i]))) return r;
}
return addshort(mem_ctx, p, "%d", ((GUID *)ptr)->info[i]);
}
int gen_dump_SEC_ACE(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent)
{
return gen_dump_struct(mem_ctx, pinfo_security_ace_info, p, ptr, indent);
}
int gen_dump_SEC_ACL(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent)
{
return gen_dump_struct(mem_ctx, pinfo_security_acl_info, p, ptr, indent);
}
int gen_dump_SEC_DESC(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent)
{
return gen_dump_struct(mem_ctx, pinfo_security_descriptor_info, p, ptr, indent);
}
int gen_dump_LUID_ATTR(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent)
{
return gen_dump_struct(mem_ctx, pinfo_luid_attr_info, p, ptr, indent);
}
int gen_dump_LUID(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent)
{
uint32 low, high;
high = ((LUID *)(ptr))->high;
low = ((LUID *)(ptr))->low;
return addshort(mem_ctx, p, "%u,%u", high, low);
}
|