1 | /* |
---|
2 | * A utility to read a Windows NT/2K/XP/2K3 registry file, using |
---|
3 | * Gerald Carter''s regfio interface. |
---|
4 | * |
---|
5 | * Copyright (C) 2005-2008 Timothy D. Morgan |
---|
6 | * Copyright (C) 2002 Richard Sharpe, rsharpe@richardsharpe.com |
---|
7 | * |
---|
8 | * This program is free software; you can redistribute it and/or modify |
---|
9 | * it under the terms of the GNU General Public License as published by |
---|
10 | * the Free Software Foundation; version 3 of the License. |
---|
11 | * |
---|
12 | * This program is distributed in the hope that it will be useful, |
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | * GNU General Public License for more details. |
---|
16 | * |
---|
17 | * You should have received a copy of the GNU General Public License |
---|
18 | * along with this program; if not, write to the Free Software |
---|
19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
20 | * |
---|
21 | * $Id: reglookup.c 116 2008-08-03 19:34:27Z tim $ |
---|
22 | */ |
---|
23 | |
---|
24 | |
---|
25 | #include <stdlib.h> |
---|
26 | #include <sysexits.h> |
---|
27 | #include <stdio.h> |
---|
28 | #include <string.h> |
---|
29 | #include <strings.h> |
---|
30 | #include <time.h> |
---|
31 | #include "../include/regfi.h" |
---|
32 | #include "../include/void_stack.h" |
---|
33 | |
---|
34 | /* Globals, influenced by command line parameters */ |
---|
35 | bool print_verbose = false; |
---|
36 | bool print_security = false; |
---|
37 | bool print_header = true; |
---|
38 | bool path_filter_enabled = false; |
---|
39 | bool type_filter_enabled = false; |
---|
40 | char* path_filter = NULL; |
---|
41 | int type_filter; |
---|
42 | char* registry_file = NULL; |
---|
43 | |
---|
44 | /* Other globals */ |
---|
45 | REGF_FILE* f; |
---|
46 | |
---|
47 | |
---|
48 | /* XXX: A hack to share some functions with reglookup-recover.c. |
---|
49 | * Should move these into a properly library at some point. |
---|
50 | */ |
---|
51 | #include "common.c" |
---|
52 | |
---|
53 | |
---|
54 | void printValue(const REGF_VK_REC* vk, char* prefix) |
---|
55 | { |
---|
56 | char* quoted_value = NULL; |
---|
57 | char* quoted_name = NULL; |
---|
58 | char* conv_error = NULL; |
---|
59 | const char* str_type = NULL; |
---|
60 | uint32 size = vk->data_size; |
---|
61 | |
---|
62 | /* Microsoft's documentation indicates that "available memory" is |
---|
63 | * the limit on value sizes. Annoying. We limit it to 1M which |
---|
64 | * should rarely be exceeded, unless the file is corrupt or |
---|
65 | * malicious. For more info, see: |
---|
66 | * http://msdn2.microsoft.com/en-us/library/ms724872.aspx |
---|
67 | */ |
---|
68 | if(size > VK_MAX_DATA_LENGTH) |
---|
69 | { |
---|
70 | fprintf(stderr, "WARNING: value data size %d larger than " |
---|
71 | "%d, truncating...\n", size, VK_MAX_DATA_LENGTH); |
---|
72 | size = VK_MAX_DATA_LENGTH; |
---|
73 | } |
---|
74 | |
---|
75 | quoted_name = quote_string(vk->valuename, key_special_chars); |
---|
76 | if (quoted_name == NULL) |
---|
77 | { /* Value names are NULL when we're looking at the "(default)" value. |
---|
78 | * Currently we just return a 0-length string to try an eliminate |
---|
79 | * ambiguity with a literal "(default)" value. The data type of a line |
---|
80 | * in the output allows one to differentiate between the parent key and |
---|
81 | * this value. |
---|
82 | */ |
---|
83 | quoted_name = malloc(1*sizeof(char)); |
---|
84 | if(quoted_name == NULL) |
---|
85 | bailOut(EX_OSERR, "ERROR: Could not allocate sufficient memory.\n"); |
---|
86 | quoted_name[0] = '\0'; |
---|
87 | } |
---|
88 | |
---|
89 | quoted_value = data_to_ascii(vk->data, size, vk->type, &conv_error); |
---|
90 | if(quoted_value == NULL) |
---|
91 | { |
---|
92 | if(conv_error == NULL) |
---|
93 | fprintf(stderr, "WARNING: Could not quote value for '%s/%s'. " |
---|
94 | "Memory allocation failure likely.\n", prefix, quoted_name); |
---|
95 | else if(print_verbose) |
---|
96 | fprintf(stderr, "WARNING: Could not quote value for '%s/%s'. " |
---|
97 | "Returned error: %s\n", prefix, quoted_name, conv_error); |
---|
98 | } |
---|
99 | /* XXX: should these always be printed? */ |
---|
100 | else if(conv_error != NULL && print_verbose) |
---|
101 | fprintf(stderr, "VERBOSE: While quoting value for '%s/%s', " |
---|
102 | "warning returned: %s\n", prefix, quoted_name, conv_error); |
---|
103 | |
---|
104 | str_type = regfi_type_val2str(vk->type); |
---|
105 | if(print_security) |
---|
106 | { |
---|
107 | if(str_type == NULL) |
---|
108 | printf("%s/%s,0x%.8X,%s,,,,,\n", prefix, quoted_name, |
---|
109 | vk->type, quoted_value); |
---|
110 | else |
---|
111 | printf("%s/%s,%s,%s,,,,,\n", prefix, quoted_name, |
---|
112 | str_type, quoted_value); |
---|
113 | } |
---|
114 | else |
---|
115 | { |
---|
116 | if(str_type == NULL) |
---|
117 | printf("%s/%s,0x%.8X,%s,\n", prefix, quoted_name, |
---|
118 | vk->type, quoted_value); |
---|
119 | else |
---|
120 | printf("%s/%s,%s,%s,\n", prefix, quoted_name, |
---|
121 | str_type, quoted_value); |
---|
122 | } |
---|
123 | |
---|
124 | if(quoted_value != NULL) |
---|
125 | free(quoted_value); |
---|
126 | if(quoted_name != NULL) |
---|
127 | free(quoted_name); |
---|
128 | if(conv_error != NULL) |
---|
129 | free(conv_error); |
---|
130 | } |
---|
131 | |
---|
132 | |
---|
133 | |
---|
134 | /* XXX: Each chunk must be unquoted after it is split out. |
---|
135 | * Quoting syntax may need to be standardized and pushed into the API |
---|
136 | * to deal with this issue and others. |
---|
137 | */ |
---|
138 | char** splitPath(const char* s) |
---|
139 | { |
---|
140 | char** ret_val; |
---|
141 | const char* cur = s; |
---|
142 | char* next = NULL; |
---|
143 | char* copy; |
---|
144 | uint32 ret_cur = 0; |
---|
145 | |
---|
146 | ret_val = (char**)malloc((REGF_MAX_DEPTH+1+1)*sizeof(char**)); |
---|
147 | if (ret_val == NULL) |
---|
148 | return NULL; |
---|
149 | ret_val[0] = NULL; |
---|
150 | |
---|
151 | /* We return a well-formed, 0-length, path even when input is icky. */ |
---|
152 | if (s == NULL) |
---|
153 | return ret_val; |
---|
154 | |
---|
155 | while((next = strchr(cur, '/')) != NULL) |
---|
156 | { |
---|
157 | if ((next-cur) > 0) |
---|
158 | { |
---|
159 | copy = (char*)malloc((next-cur+1)*sizeof(char)); |
---|
160 | if(copy == NULL) |
---|
161 | bailOut(EX_OSERR, "ERROR: Memory allocation problem.\n"); |
---|
162 | |
---|
163 | memcpy(copy, cur, next-cur); |
---|
164 | copy[next-cur] = '\0'; |
---|
165 | ret_val[ret_cur++] = copy; |
---|
166 | if(ret_cur < (REGF_MAX_DEPTH+1+1)) |
---|
167 | ret_val[ret_cur] = NULL; |
---|
168 | else |
---|
169 | bailOut(EX_DATAERR, "ERROR: Registry maximum depth exceeded.\n"); |
---|
170 | } |
---|
171 | cur = next+1; |
---|
172 | } |
---|
173 | |
---|
174 | /* Grab last element, if path doesn't end in '/'. */ |
---|
175 | if(strlen(cur) > 0) |
---|
176 | { |
---|
177 | copy = strdup(cur); |
---|
178 | ret_val[ret_cur++] = copy; |
---|
179 | if(ret_cur < (REGF_MAX_DEPTH+1+1)) |
---|
180 | ret_val[ret_cur] = NULL; |
---|
181 | else |
---|
182 | bailOut(EX_DATAERR, "ERROR: Registry maximum depth exceeded.\n"); |
---|
183 | } |
---|
184 | |
---|
185 | return ret_val; |
---|
186 | } |
---|
187 | |
---|
188 | |
---|
189 | void freePath(char** path) |
---|
190 | { |
---|
191 | uint32 i; |
---|
192 | |
---|
193 | if(path == NULL) |
---|
194 | return; |
---|
195 | |
---|
196 | for(i=0; path[i] != NULL; i++) |
---|
197 | free(path[i]); |
---|
198 | |
---|
199 | free(path); |
---|
200 | } |
---|
201 | |
---|
202 | |
---|
203 | /* Returns a quoted path from an iterator's stack */ |
---|
204 | /* XXX: Some way should be found to integrate this into regfi's API |
---|
205 | * The problem is that the escaping is sorta reglookup-specific. |
---|
206 | */ |
---|
207 | char* iter2Path(REGFI_ITERATOR* i) |
---|
208 | { |
---|
209 | const REGFI_ITER_POSITION* cur; |
---|
210 | uint32 buf_left = 127; |
---|
211 | uint32 buf_len = buf_left+1; |
---|
212 | uint32 name_len = 0; |
---|
213 | uint32 grow_amt; |
---|
214 | char* buf; |
---|
215 | char* new_buf; |
---|
216 | char* name; |
---|
217 | const char* cur_name; |
---|
218 | void_stack_iterator* iter; |
---|
219 | |
---|
220 | buf = (char*)malloc((buf_len)*sizeof(char)); |
---|
221 | if (buf == NULL) |
---|
222 | return NULL; |
---|
223 | buf[0] = '\0'; |
---|
224 | |
---|
225 | iter = void_stack_iterator_new(i->key_positions); |
---|
226 | if (iter == NULL) |
---|
227 | { |
---|
228 | free(buf); |
---|
229 | return NULL; |
---|
230 | } |
---|
231 | |
---|
232 | /* skip root element */ |
---|
233 | if(void_stack_size(i->key_positions) < 1) |
---|
234 | { |
---|
235 | buf[0] = '/'; |
---|
236 | buf[1] = '\0'; |
---|
237 | return buf; |
---|
238 | } |
---|
239 | cur = void_stack_iterator_next(iter); |
---|
240 | |
---|
241 | do |
---|
242 | { |
---|
243 | cur = void_stack_iterator_next(iter); |
---|
244 | if (cur == NULL) |
---|
245 | cur_name = i->cur_key->keyname; |
---|
246 | else |
---|
247 | cur_name = cur->nk->keyname; |
---|
248 | |
---|
249 | buf[buf_len-buf_left-1] = '/'; |
---|
250 | buf_left -= 1; |
---|
251 | name = quote_string(cur_name, key_special_chars); |
---|
252 | name_len = strlen(name); |
---|
253 | if(name_len+1 > buf_left) |
---|
254 | { |
---|
255 | grow_amt = (uint32)(buf_len/2); |
---|
256 | buf_len += name_len+1+grow_amt-buf_left; |
---|
257 | if((new_buf = realloc(buf, buf_len)) == NULL) |
---|
258 | { |
---|
259 | free(buf); |
---|
260 | free(iter); |
---|
261 | return NULL; |
---|
262 | } |
---|
263 | buf = new_buf; |
---|
264 | buf_left = grow_amt + name_len + 1; |
---|
265 | } |
---|
266 | strncpy(buf+(buf_len-buf_left-1), name, name_len); |
---|
267 | buf_left -= name_len; |
---|
268 | buf[buf_len-buf_left-1] = '\0'; |
---|
269 | free(name); |
---|
270 | } while(cur != NULL); |
---|
271 | |
---|
272 | return buf; |
---|
273 | } |
---|
274 | |
---|
275 | |
---|
276 | void printValueList(REGFI_ITERATOR* i, char* prefix) |
---|
277 | { |
---|
278 | const REGF_VK_REC* value; |
---|
279 | |
---|
280 | value = regfi_iterator_first_value(i); |
---|
281 | while(value != NULL) |
---|
282 | { |
---|
283 | if(!type_filter_enabled || (value->type == type_filter)) |
---|
284 | printValue(value, prefix); |
---|
285 | value = regfi_iterator_next_value(i); |
---|
286 | } |
---|
287 | } |
---|
288 | |
---|
289 | |
---|
290 | void printKey(REGFI_ITERATOR* i, char* full_path) |
---|
291 | { |
---|
292 | static char empty_str[1] = ""; |
---|
293 | char* owner = NULL; |
---|
294 | char* group = NULL; |
---|
295 | char* sacl = NULL; |
---|
296 | char* dacl = NULL; |
---|
297 | char mtime[20]; |
---|
298 | time_t tmp_time[1]; |
---|
299 | struct tm* tmp_time_s = NULL; |
---|
300 | const REGF_SK_REC* sk; |
---|
301 | const REGF_NK_REC* k = regfi_iterator_cur_key(i); |
---|
302 | |
---|
303 | *tmp_time = nt_time_to_unix(&k->mtime); |
---|
304 | tmp_time_s = gmtime(tmp_time); |
---|
305 | strftime(mtime, sizeof(mtime), "%Y-%m-%d %H:%M:%S", tmp_time_s); |
---|
306 | |
---|
307 | if(print_security && (sk=regfi_iterator_cur_sk(i))) |
---|
308 | { |
---|
309 | owner = regfi_get_owner(sk->sec_desc); |
---|
310 | group = regfi_get_group(sk->sec_desc); |
---|
311 | sacl = regfi_get_sacl(sk->sec_desc); |
---|
312 | dacl = regfi_get_dacl(sk->sec_desc); |
---|
313 | if(owner == NULL) |
---|
314 | owner = empty_str; |
---|
315 | if(group == NULL) |
---|
316 | group = empty_str; |
---|
317 | if(sacl == NULL) |
---|
318 | sacl = empty_str; |
---|
319 | if(dacl == NULL) |
---|
320 | dacl = empty_str; |
---|
321 | |
---|
322 | printf("%s,KEY,,%s,%s,%s,%s,%s\n", full_path, mtime, |
---|
323 | owner, group, sacl, dacl); |
---|
324 | |
---|
325 | if(owner != empty_str) |
---|
326 | free(owner); |
---|
327 | if(group != empty_str) |
---|
328 | free(group); |
---|
329 | if(sacl != empty_str) |
---|
330 | free(sacl); |
---|
331 | if(dacl != empty_str) |
---|
332 | free(dacl); |
---|
333 | } |
---|
334 | else |
---|
335 | printf("%s,KEY,,%s\n", full_path, mtime); |
---|
336 | } |
---|
337 | |
---|
338 | |
---|
339 | void printKeyTree(REGFI_ITERATOR* iter) |
---|
340 | { |
---|
341 | const REGF_NK_REC* root = NULL; |
---|
342 | const REGF_NK_REC* cur = NULL; |
---|
343 | const REGF_NK_REC* sub = NULL; |
---|
344 | char* path = NULL; |
---|
345 | int key_type = regfi_type_str2val("KEY"); |
---|
346 | bool print_this = true; |
---|
347 | |
---|
348 | root = cur = regfi_iterator_cur_key(iter); |
---|
349 | sub = regfi_iterator_first_subkey(iter); |
---|
350 | |
---|
351 | if(root == NULL) |
---|
352 | bailOut(EX_DATAERR, "ERROR: root cannot be NULL.\n"); |
---|
353 | |
---|
354 | do |
---|
355 | { |
---|
356 | if(print_this) |
---|
357 | { |
---|
358 | path = iter2Path(iter); |
---|
359 | if(path == NULL) |
---|
360 | bailOut(EX_OSERR, "ERROR: Could not construct iterator's path.\n"); |
---|
361 | |
---|
362 | if(!type_filter_enabled || (key_type == type_filter)) |
---|
363 | printKey(iter, path); |
---|
364 | if(!type_filter_enabled || (key_type != type_filter)) |
---|
365 | printValueList(iter, path); |
---|
366 | |
---|
367 | free(path); |
---|
368 | } |
---|
369 | |
---|
370 | if(sub == NULL) |
---|
371 | { |
---|
372 | if(cur != root) |
---|
373 | { |
---|
374 | /* We're done with this sub-tree, going up and hitting other branches. */ |
---|
375 | if(!regfi_iterator_up(iter)) |
---|
376 | bailOut(EX_DATAERR, "ERROR: could not traverse iterator upward.\n"); |
---|
377 | |
---|
378 | cur = regfi_iterator_cur_key(iter); |
---|
379 | if(cur == NULL) |
---|
380 | bailOut(EX_DATAERR, "ERROR: unexpected NULL for key.\n"); |
---|
381 | |
---|
382 | sub = regfi_iterator_next_subkey(iter); |
---|
383 | } |
---|
384 | print_this = false; |
---|
385 | } |
---|
386 | else |
---|
387 | { /* We have unexplored sub-keys. |
---|
388 | * Let's move down and print this first sub-tree out. |
---|
389 | */ |
---|
390 | if(!regfi_iterator_down(iter)) |
---|
391 | bailOut(EX_DATAERR, "ERROR: could not traverse iterator downward.\n"); |
---|
392 | |
---|
393 | cur = sub; |
---|
394 | sub = regfi_iterator_first_subkey(iter); |
---|
395 | print_this = true; |
---|
396 | } |
---|
397 | } while(!((cur == root) && (sub == NULL))); |
---|
398 | |
---|
399 | if(print_verbose) |
---|
400 | fprintf(stderr, "VERBOSE: Finished printing key tree.\n"); |
---|
401 | } |
---|
402 | |
---|
403 | |
---|
404 | /* XXX: what if there is BOTH a value AND a key with that name?? */ |
---|
405 | /* |
---|
406 | * Returns 0 if path was not found. |
---|
407 | * Returns 1 if path was found as value. |
---|
408 | * Returns 2 if path was found as key. |
---|
409 | * Returns less than 0 on other error. |
---|
410 | */ |
---|
411 | int retrievePath(REGFI_ITERATOR* iter, char** path) |
---|
412 | { |
---|
413 | const REGF_VK_REC* value; |
---|
414 | char* tmp_path_joined; |
---|
415 | const char** tmp_path; |
---|
416 | uint32 i; |
---|
417 | |
---|
418 | if(path == NULL) |
---|
419 | return -1; |
---|
420 | |
---|
421 | /* One extra for any value at the end, and one more for NULL */ |
---|
422 | tmp_path = (const char**)malloc(sizeof(const char**)*(REGF_MAX_DEPTH+1+1)); |
---|
423 | if(tmp_path == NULL) |
---|
424 | return -2; |
---|
425 | |
---|
426 | /* Strip any potential value name at end of path */ |
---|
427 | for(i=0; |
---|
428 | (path[i] != NULL) && (path[i+1] != NULL) |
---|
429 | && (i < REGF_MAX_DEPTH+1+1); |
---|
430 | i++) |
---|
431 | tmp_path[i] = path[i]; |
---|
432 | |
---|
433 | tmp_path[i] = NULL; |
---|
434 | |
---|
435 | if(print_verbose) |
---|
436 | fprintf(stderr, "VERBOSE: Attempting to retrieve specified path: %s\n", |
---|
437 | path_filter); |
---|
438 | |
---|
439 | /* Special check for '/' path filter */ |
---|
440 | if(path[0] == NULL) |
---|
441 | { |
---|
442 | if(print_verbose) |
---|
443 | fprintf(stderr, "VERBOSE: Found final path element as root key.\n"); |
---|
444 | return 2; |
---|
445 | } |
---|
446 | |
---|
447 | if(!regfi_iterator_walk_path(iter, tmp_path)) |
---|
448 | { |
---|
449 | free(tmp_path); |
---|
450 | return 0; |
---|
451 | } |
---|
452 | |
---|
453 | if(regfi_iterator_find_value(iter, path[i])) |
---|
454 | { |
---|
455 | if(print_verbose) |
---|
456 | fprintf(stderr, "VERBOSE: Found final path element as value.\n"); |
---|
457 | |
---|
458 | value = regfi_iterator_cur_value(iter); |
---|
459 | tmp_path_joined = iter2Path(iter); |
---|
460 | |
---|
461 | if((value == NULL) || (tmp_path_joined == NULL)) |
---|
462 | bailOut(EX_OSERR, "ERROR: Unexpected error before printValue.\n"); |
---|
463 | |
---|
464 | printValue(value, tmp_path_joined); |
---|
465 | |
---|
466 | free(tmp_path); |
---|
467 | free(tmp_path_joined); |
---|
468 | return 1; |
---|
469 | } |
---|
470 | else if(regfi_iterator_find_subkey(iter, path[i])) |
---|
471 | { |
---|
472 | if(print_verbose) |
---|
473 | fprintf(stderr, "VERBOSE: Found final path element as key.\n"); |
---|
474 | |
---|
475 | if(!regfi_iterator_down(iter)) |
---|
476 | bailOut(EX_DATAERR, "ERROR: Unexpected error on traversing path filter key.\n"); |
---|
477 | |
---|
478 | return 2; |
---|
479 | } |
---|
480 | |
---|
481 | if(print_verbose) |
---|
482 | fprintf(stderr, "VERBOSE: Could not find last element of path.\n"); |
---|
483 | |
---|
484 | return 0; |
---|
485 | } |
---|
486 | |
---|
487 | |
---|
488 | static void usage(void) |
---|
489 | { |
---|
490 | fprintf(stderr, "Usage: reglookup [-v] [-s]" |
---|
491 | " [-p <PATH_FILTER>] [-t <TYPE_FILTER>]" |
---|
492 | " <REGISTRY_FILE>\n"); |
---|
493 | fprintf(stderr, "Version: %s\n", REGLOOKUP_VERSION); |
---|
494 | fprintf(stderr, "Options:\n"); |
---|
495 | fprintf(stderr, "\t-v\t sets verbose mode.\n"); |
---|
496 | fprintf(stderr, "\t-h\t enables header row. (default)\n"); |
---|
497 | fprintf(stderr, "\t-H\t disables header row.\n"); |
---|
498 | fprintf(stderr, "\t-s\t enables security descriptor output.\n"); |
---|
499 | fprintf(stderr, "\t-S\t disables security descriptor output. (default)\n"); |
---|
500 | fprintf(stderr, "\t-p\t restrict output to elements below this path.\n"); |
---|
501 | fprintf(stderr, "\t-t\t restrict results to this specific data type.\n"); |
---|
502 | fprintf(stderr, "\n"); |
---|
503 | } |
---|
504 | |
---|
505 | |
---|
506 | int main(int argc, char** argv) |
---|
507 | { |
---|
508 | char** path = NULL; |
---|
509 | REGFI_ITERATOR* iter; |
---|
510 | int retr_path_ret; |
---|
511 | uint32 argi, arge; |
---|
512 | |
---|
513 | /* Process command line arguments */ |
---|
514 | if(argc < 2) |
---|
515 | { |
---|
516 | usage(); |
---|
517 | bailOut(EX_USAGE, "ERROR: Requires at least one argument.\n"); |
---|
518 | } |
---|
519 | |
---|
520 | arge = argc-1; |
---|
521 | for(argi = 1; argi < arge; argi++) |
---|
522 | { |
---|
523 | if (strcmp("-p", argv[argi]) == 0) |
---|
524 | { |
---|
525 | if(++argi >= arge) |
---|
526 | { |
---|
527 | usage(); |
---|
528 | bailOut(EX_USAGE, "ERROR: '-p' option requires parameter.\n"); |
---|
529 | } |
---|
530 | if((path_filter = strdup(argv[argi])) == NULL) |
---|
531 | bailOut(EX_OSERR, "ERROR: Memory allocation problem.\n"); |
---|
532 | |
---|
533 | path_filter_enabled = true; |
---|
534 | } |
---|
535 | else if (strcmp("-t", argv[argi]) == 0) |
---|
536 | { |
---|
537 | if(++argi >= arge) |
---|
538 | { |
---|
539 | usage(); |
---|
540 | bailOut(EX_USAGE, "ERROR: '-t' option requires parameter.\n"); |
---|
541 | } |
---|
542 | if((type_filter = regfi_type_str2val(argv[argi])) < 0) |
---|
543 | { |
---|
544 | fprintf(stderr, "ERROR: Invalid type specified: %s.\n", argv[argi]); |
---|
545 | bailOut(EX_USAGE, ""); |
---|
546 | } |
---|
547 | type_filter_enabled = true; |
---|
548 | } |
---|
549 | else if (strcmp("-h", argv[argi]) == 0) |
---|
550 | print_header = true; |
---|
551 | else if (strcmp("-H", argv[argi]) == 0) |
---|
552 | print_header = false; |
---|
553 | else if (strcmp("-s", argv[argi]) == 0) |
---|
554 | print_security = true; |
---|
555 | else if (strcmp("-S", argv[argi]) == 0) |
---|
556 | print_security = false; |
---|
557 | else if (strcmp("-v", argv[argi]) == 0) |
---|
558 | print_verbose = true; |
---|
559 | else |
---|
560 | { |
---|
561 | usage(); |
---|
562 | fprintf(stderr, "ERROR: Unrecognized option: %s\n", argv[argi]); |
---|
563 | bailOut(EX_USAGE, ""); |
---|
564 | } |
---|
565 | } |
---|
566 | if((registry_file = strdup(argv[argi])) == NULL) |
---|
567 | bailOut(EX_OSERR, "ERROR: Memory allocation problem.\n"); |
---|
568 | |
---|
569 | f = regfi_open(registry_file); |
---|
570 | if(f == NULL) |
---|
571 | { |
---|
572 | fprintf(stderr, "ERROR: Couldn't open registry file: %s\n", registry_file); |
---|
573 | bailOut(EX_NOINPUT, ""); |
---|
574 | } |
---|
575 | |
---|
576 | iter = regfi_iterator_new(f); |
---|
577 | if(iter == NULL) |
---|
578 | bailOut(EX_OSERR, "ERROR: Couldn't create registry iterator.\n"); |
---|
579 | |
---|
580 | if(print_header) |
---|
581 | { |
---|
582 | if(print_security) |
---|
583 | printf("PATH,TYPE,VALUE,MTIME,OWNER,GROUP,SACL,DACL\n"); |
---|
584 | else |
---|
585 | printf("PATH,TYPE,VALUE,MTIME\n"); |
---|
586 | } |
---|
587 | |
---|
588 | if(path_filter_enabled && path_filter != NULL) |
---|
589 | path = splitPath(path_filter); |
---|
590 | |
---|
591 | if(path != NULL) |
---|
592 | { |
---|
593 | retr_path_ret = retrievePath(iter, path); |
---|
594 | freePath(path); |
---|
595 | |
---|
596 | if(retr_path_ret == 0) |
---|
597 | fprintf(stderr, "WARNING: specified path not found.\n"); |
---|
598 | else if (retr_path_ret == 2) |
---|
599 | printKeyTree(iter); |
---|
600 | else if(retr_path_ret < 0) |
---|
601 | { |
---|
602 | fprintf(stderr, "ERROR: retrievePath() returned %d.\n", |
---|
603 | retr_path_ret); |
---|
604 | bailOut(EX_DATAERR,"ERROR: Unknown error occurred in retrieving path.\n"); |
---|
605 | } |
---|
606 | } |
---|
607 | else |
---|
608 | printKeyTree(iter); |
---|
609 | |
---|
610 | regfi_iterator_free(iter); |
---|
611 | regfi_close(f); |
---|
612 | |
---|
613 | return 0; |
---|
614 | } |
---|