File: reglookup.c

package info (click to toggle)
reglookup 1.0.1+svn287-7
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 952 kB
  • sloc: ansic: 6,676; python: 3,762; makefile: 40; sh: 27
file content (700 lines) | stat: -rw-r--r-- 18,146 bytes parent folder | download | duplicates (2)
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
/*
 * A utility to read a Windows NT and later registry files.
 *
 * Copyright (C) 2005-2011 Timothy D. Morgan
 * Copyright (C) 2010 Tobias Mueller (portions of '-i' code)
 * Copyright (C) 2002 Richard Sharpe, rsharpe@richardsharpe.com
 *
 * 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; version 3 of the License.
 * 
 * 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.  
 *
 * $Id$
 */


#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <time.h>
#include "regfi.h"
#include "void_stack.h"

/* Globals, influenced by command line parameters */
bool print_value_mtime = false;
bool print_verbose = false;
bool print_security = false;
bool print_header = true;
bool path_filter_enabled = false;
bool type_filter_enabled = false;
char* path_filter = NULL;
int type_filter;
const char* registry_file = NULL;

/* Other globals */
REGFI_FILE* f;


/* XXX: A hack to share some functions with reglookup-recover.c.
 *      Should move these into a proper library at some point.
 */
#include "common.c"


static bool keysEqual(const REGFI_NK* x, const REGFI_NK* y)
{
  return (x != NULL && y != NULL && x->offset == y->offset);
}

void printValue(REGFI_ITERATOR* iter, const REGFI_VK* vk, char* prefix)
{
  const REGFI_NK* cur_key;
  const REGFI_DATA* data;
  char* quoted_value = NULL;
  char* quoted_name = NULL;
  char* conv_error = NULL;
  const char* str_type = NULL;
  char mtime[20];
  time_t tmp_time[1];
  struct tm* tmp_time_s = NULL;

  quoted_name = get_quoted_valuename(vk);
  if (quoted_name == NULL)
  { /* Value names are NULL when we're looking at the "(default)" value.
     * Currently we just return a 0-length string to try an eliminate 
     * ambiguity with a literal "(default)" value.  The data type of a line
     * in the output allows one to differentiate between the parent key and
     * this value.
     */
    quoted_name = malloc(1*sizeof(char));
    if(quoted_name == NULL)
      bailOut(REGLOOKUP_EXIT_OSERR, "ERROR: Could not allocate sufficient memory.\n");
    quoted_name[0] = '\0';
  }
  
  data = regfi_fetch_data(iter->f, vk);

  printMsgs(iter->f);
  if(data != NULL)
  {
    quoted_value = data_to_ascii(data, &conv_error);
    if(quoted_value == NULL)
    {
      if(conv_error == NULL)
	fprintf(stderr, "WARN: Could not quote value for '%s/%s'.  "
		"Memory allocation failure likely.\n", prefix, quoted_name);
      else
	fprintf(stderr, "WARN: Could not quote value for '%s/%s'.  "
		"Returned error: %s\n", prefix, quoted_name, conv_error);
    }
    else if(conv_error != NULL)
      fprintf(stderr, "WARN: While quoting value for '%s/%s', "
	      "warning returned: %s\n", prefix, quoted_name, conv_error);
    regfi_free_record(iter->f, data);
  }

  if(print_value_mtime)
  {
    cur_key = regfi_iterator_cur_key(iter);
    *tmp_time = regfi_nt2unix_time(cur_key->mtime);
    tmp_time_s = gmtime(tmp_time);
    strftime(mtime, sizeof(mtime), "%Y-%m-%d %H:%M:%S", tmp_time_s);
    regfi_free_record(iter->f, cur_key);
  }
  else
    mtime[0] = '\0';

  str_type = regfi_type_val2str(vk->type);
  if(print_security)
  {
    if(str_type == NULL)
      printf("%s/%s,0x%.8X,%s,%s,,,,\n", prefix, quoted_name,
	     vk->type, quoted_value, mtime);
    else
      printf("%s/%s,%s,%s,%s,,,,\n", prefix, quoted_name,
	     str_type, quoted_value, mtime);
  }
  else
  {
    if(str_type == NULL)
      printf("%s/%s,0x%.8X,%s,%s\n", prefix, quoted_name,
	     vk->type, quoted_value, mtime);
    else
      printf("%s/%s,%s,%s,%s\n", prefix, quoted_name,
	     str_type, quoted_value, mtime);
  }

  if(quoted_value != NULL)
    free(quoted_value);
  if(quoted_name != NULL)
    free(quoted_name);
  if(conv_error != NULL)
    free(conv_error);
}


char** splitPath(const char* s)
{
  char** ret_val;
  const char* cur = s;
  char* next = NULL;
  char* copy;
  uint32_t ret_cur = 0;

  ret_val = (char**)malloc((REGFI_MAX_DEPTH+1+1)*sizeof(char**));
  if (ret_val == NULL)
    return NULL;
  ret_val[0] = NULL;

  /* We return a well-formed, 0-length, path even when input is icky. */
  if (s == NULL)
    return ret_val;
  
  while((next = strchr(cur, '/')) != NULL)
  {
    if ((next-cur) > 0)
    {
      copy = (char*)malloc((next-cur+1)*sizeof(char));
      if(copy == NULL)
	bailOut(REGLOOKUP_EXIT_OSERR, "ERROR: Memory allocation problem.\n");
	  
      memcpy(copy, cur, next-cur);
      copy[next-cur] = '\0';
      ret_val[ret_cur++] = copy;
      if(ret_cur < (REGFI_MAX_DEPTH+1+1))
	ret_val[ret_cur] = NULL;
      else
	bailOut(REGLOOKUP_EXIT_DATAERR, "ERROR: Registry maximum depth exceeded.\n");
    }
    cur = next+1;
  }

  /* Grab last element, if path doesn't end in '/'. */
  if(strlen(cur) > 0)
  {
    copy = strdup(cur);
    ret_val[ret_cur++] = copy;
    if(ret_cur < (REGFI_MAX_DEPTH+1+1))
      ret_val[ret_cur] = NULL;
    else
      bailOut(REGLOOKUP_EXIT_DATAERR, "ERROR: Registry maximum depth exceeded.\n");
  }

  return ret_val;
}


void freePath(char** path)
{
  uint32_t i;

  if(path == NULL)
    return;

  for(i=0; path[i] != NULL; i++)
    free(path[i]);

  free(path);
}


/* Returns a quoted path of the current iterator's position */
char* iter2Path(REGFI_ITERATOR* i)
{
  const REGFI_NK** path;
  uint32_t k;
  uint32_t buf_left = 127;
  uint32_t buf_len = buf_left+1;
  uint32_t name_len = 0;
  uint32_t grow_amt;
  char* buf;
  char* new_buf;
  char* name;
  
  buf = (char*)malloc((buf_len)*sizeof(char));
  if (buf == NULL)
    return NULL;
  buf[0] = '\0';

  path = regfi_iterator_ancestry(i);
  if(path == NULL)
  {
    free(buf);
    return NULL;
  }

  for(k=0; path[k] != NULL; k++)
  {
    /* skip root element's name */
    if(k == 0)
    {
      buf[0] = '/';
      buf[1] = '\0';
    }
    else
    {
      name = get_quoted_keyname(path[k]);

      buf[buf_len-buf_left-1] = '/';
      buf_left -= 1;
      name_len = strlen(name);
      if(name_len+1 > buf_left)
      {
        grow_amt = (uint32_t)(buf_len/2);
        buf_len += name_len+1+grow_amt-buf_left;
        if((new_buf = realloc(buf, buf_len)) == NULL)
        {
          regfi_free_record(i->f, path);
          free(name);
          free(buf);
          return NULL;
        }
        buf = new_buf;
        buf_left = grow_amt + name_len + 1;
      }
      strncpy(buf+(buf_len-buf_left-1), name, name_len);
      buf_left -= name_len;
      buf[buf_len-buf_left-1] = '\0';
      free(name);
    }
  }

  regfi_free_record(i->f, path);
  return buf;
}


void printValueList(REGFI_ITERATOR* iter, char* prefix)
{
  const REGFI_VK* value;

  regfi_iterator_first_value(iter);
  while((value = regfi_iterator_cur_value(iter)) != NULL)
  {
    if(!type_filter_enabled || (value->type == type_filter))
      printValue(iter, value, prefix);
    regfi_free_record(iter->f, value);
    regfi_iterator_next_value(iter);
    printMsgs(iter->f);
  }
}


void printKey(REGFI_ITERATOR* iter, char* full_path)
{
  static char empty_str[1] = "";
  char* owner = NULL;
  char* group = NULL;
  char* sacl = NULL;
  char* dacl = NULL;
  char mtime[24];
  char* quoted_classname;
  const REGFI_SK* sk;
  const REGFI_NK* key = regfi_iterator_cur_key(iter);
  const REGFI_CLASSNAME* classname;

  formatTime(key->mtime, mtime);

  if(print_security && (sk=regfi_fetch_sk(iter->f, key)))
  {
    owner = regfi_get_owner(sk->sec_desc);
    group = regfi_get_group(sk->sec_desc);
    sacl = regfi_get_sacl(sk->sec_desc);
    dacl = regfi_get_dacl(sk->sec_desc);
    regfi_free_record(iter->f, sk);

    if(owner == NULL)
      owner = empty_str;
    if(group == NULL)
      group = empty_str;
    if(sacl == NULL)
      sacl = empty_str;
    if(dacl == NULL)
      dacl = empty_str;

    classname = regfi_fetch_classname(iter->f, key);
    printMsgs(iter->f);
    if(classname != NULL)
    {
      if(classname->interpreted == NULL)
      {
	fprintf(stderr, "WARN: Could not convert class name"
		" charset for key '%s'.  Quoting raw...\n", full_path);
	quoted_classname = quote_buffer(classname->raw, classname->size,
					key_special_chars);
      }
      else
	quoted_classname = quote_string(classname->interpreted, 
					key_special_chars);

      if(quoted_classname == NULL)
      {
	fprintf(stderr, "ERROR: Could not quote classname"
		" for key '%s' due to unknown error.\n", full_path);
	quoted_classname = empty_str;
      }
    }
    else
      quoted_classname = empty_str;
    regfi_free_record(iter->f, classname);

    printMsgs(iter->f);
    printf("%s,KEY,,%s,%s,%s,%s,%s,%s\n", full_path, mtime, 
	   owner, group, sacl, dacl, quoted_classname);

    if(owner != empty_str)
      free(owner);
    if(group != empty_str)
      free(group);
    if(sacl != empty_str)
      free(sacl);
    if(dacl != empty_str)
      free(dacl);
    if(quoted_classname != empty_str)
      free(quoted_classname);
  }
  else
    printf("%s,KEY,,%s\n", full_path, mtime);

  regfi_free_record(iter->f, key);
}


void printKeyTree(REGFI_ITERATOR* iter)
{
  const REGFI_NK* root = NULL;
  const REGFI_NK* cur = NULL;
  const REGFI_NK* sub = NULL;
  char* path = NULL;
  int key_type = regfi_type_str2val("KEY");
  bool print_this = true;

  root = regfi_iterator_cur_key(iter);
  cur = root = regfi_reference_record(iter->f, root);
  regfi_iterator_first_subkey(iter);
  sub = regfi_iterator_cur_subkey(iter);
  printMsgs(iter->f);

  if(root == NULL)
    bailOut(REGLOOKUP_EXIT_DATAERR, "ERROR: root cannot be NULL.\n");
  
  do
  {
    if(print_this)
    {
      path = iter2Path(iter);
      if(path == NULL)
	bailOut(REGLOOKUP_EXIT_OSERR, "ERROR: Could not construct iterator's path.\n");

      if(!type_filter_enabled || (key_type == type_filter))
	printKey(iter, path);
      if(!type_filter_enabled || (key_type != type_filter))
	printValueList(iter, path);
      
      free(path);
    }
    
    if(sub == NULL)
    {
      if(!keysEqual(cur, root))
      {
        regfi_free_record(iter->f, cur);
        cur = NULL;
	/* We're done with this sub-tree, going up and hitting other branches. */
	if(!regfi_iterator_up(iter))
	{
	  printMsgs(iter->f);
	  bailOut(REGLOOKUP_EXIT_DATAERR, "ERROR: could not traverse iterator upward.\n");
	}

	cur = regfi_iterator_cur_key(iter);
	if(cur == NULL)
	{
	  printMsgs(iter->f);
	  bailOut(REGLOOKUP_EXIT_DATAERR, "ERROR: unexpected NULL for key.\n");
	}
	
	regfi_iterator_next_subkey(iter);
	sub = regfi_iterator_cur_subkey(iter);
      }
      print_this = false;
    }
    else
    { /* We have unexplored sub-keys.  
       * Let's move down and print this first sub-tree out. 
       */
      regfi_free_record(iter->f, cur);
      cur = NULL;
      if(!regfi_iterator_down(iter))
      {
	printMsgs(iter->f);
	bailOut(REGLOOKUP_EXIT_DATAERR, "ERROR: could not traverse iterator downward.\n");
      }

      cur = regfi_iterator_cur_key(iter);
      regfi_free_record(iter->f, sub);
      regfi_iterator_first_subkey(iter);
      sub = regfi_iterator_cur_subkey(iter);
      print_this = true;
    }
    printMsgs(iter->f);
  } while(!(keysEqual(cur, root) && (sub == NULL)));
  if(cur != NULL)
    regfi_free_record(iter->f, cur);
  regfi_free_record(iter->f, root);

  if(print_verbose)
    fprintf(stderr, "INFO: Finished printing key tree.\n");
}


/* XXX: What if there is BOTH a value AND a key with that name?? 
 *      What if there are multiple keys/values with the same name?? 
 */
/*
 * Returns 0 if path was not found.
 * Returns 1 if path was found as value.
 * Returns 2 if path was found as key.
 * Returns less than 0 on other error.
 */
int retrievePath(REGFI_ITERATOR* iter, char** path)
{
  const REGFI_VK* value;
  char* tmp_path_joined;
  const char** tmp_path;
  uint32_t i;
  
  if(path == NULL)
    return -1;

  /* One extra for any value at the end, and one more for NULL */
  tmp_path = (const char**)malloc(sizeof(const char**)*(REGFI_MAX_DEPTH+1+1));
  if(tmp_path == NULL)
    return -2;

  /* Strip any potential value name at end of path */
  for(i=0; 
      (path[i] != NULL) && (path[i+1] != NULL) && (i < REGFI_MAX_DEPTH+1);
      i++)
  { tmp_path[i] = path[i]; }
  tmp_path[i] = NULL;

  if(print_verbose)
    fprintf(stderr, "INFO: Attempting to retrieve specified path: %s\n",
	    path_filter);

  /* Special check for '/' path filter */
  if(path[0] == NULL)
  {
    if(print_verbose)
      fprintf(stderr, "INFO: Found final path element as root key.\n");
    free(tmp_path);
    return 2;
  }

  if(!regfi_iterator_descend(iter, tmp_path))
  {
    printMsgs(iter->f);
    free(tmp_path);
    return 0;
  }

  if(regfi_iterator_find_value(iter, path[i]))
  {
    if(print_verbose)
      fprintf(stderr, "INFO: Found final path element as value.\n");

    value = regfi_iterator_cur_value(iter);
    printMsgs(iter->f);
    tmp_path_joined = iter2Path(iter);

    if((value == NULL) || (tmp_path_joined == NULL))
      bailOut(REGLOOKUP_EXIT_OSERR, "ERROR: Unexpected error before printValue.\n");

    if(!type_filter_enabled || (value->type == type_filter))
      printValue(iter, value, tmp_path_joined);

    regfi_free_record(iter->f, value);
    free(tmp_path);
    free(tmp_path_joined);
    return 1;
  }
  else if(regfi_iterator_find_subkey(iter, path[i]))
  {
    printMsgs(iter->f);
    if(print_verbose)
      fprintf(stderr, "INFO: Found final path element as key.\n");

    if(!regfi_iterator_down(iter))
    {
      printMsgs(iter->f);
      bailOut(REGLOOKUP_EXIT_DATAERR, "ERROR: Unexpected error on traversing path filter key.\n");
    }

    return 2;
  }
  printMsgs(iter->f);

  if(print_verbose)
    fprintf(stderr, "INFO: Could not find last element of path.\n");

  return 0;
}


static void usage(void)
{
  fprintf(stderr, "Usage: reglookup [-v] [-s]"
	  " [-p <PATH_FILTER>] [-t <TYPE_FILTER>]"
	  " <REGISTRY_FILE>\n");
  fprintf(stderr, "Version: %s\n", regfi_version());
  fprintf(stderr, "Options:\n");
  fprintf(stderr, "\t-v\t sets verbose mode.\n");
  fprintf(stderr, "\t-h\t enables header row. (default)\n");
  fprintf(stderr, "\t-H\t disables header row.\n");
  fprintf(stderr, "\t-s\t enables security descriptor output.\n");
  fprintf(stderr, "\t-S\t disables security descriptor output. (default)\n");
  fprintf(stderr, "\t-p\t restrict output to elements below this path.\n");
  fprintf(stderr, "\t-t\t restrict results to this specific data type.\n");
  fprintf(stderr, "\t-i\t includes parent key modification times with child values.\n");
  fprintf(stderr, "\n");
}


int main(int argc, char** argv)
{
  char** path = NULL;
  REGFI_ITERATOR* iter;
  int retr_path_ret, fd;
  uint32_t argi, arge;

  /* Process command line arguments */
  if(argc < 2)
  {
    usage();
    bailOut(REGLOOKUP_EXIT_USAGE, "ERROR: Requires at least one argument.\n");
  }
  
  arge = argc-1;
  for(argi = 1; argi < arge; argi++)
  {
    if (strcmp("-p", argv[argi]) == 0)
    {
      if(++argi >= arge)
      {
	usage();
	bailOut(REGLOOKUP_EXIT_USAGE, "ERROR: '-p' option requires parameter.\n");
      }
      if((path_filter = strdup(argv[argi])) == NULL)
	bailOut(REGLOOKUP_EXIT_OSERR, "ERROR: Memory allocation problem.\n");

      path_filter_enabled = true;
    }
    else if (strcmp("-t", argv[argi]) == 0)
    {
      if(++argi >= arge)
      {
	usage();
	bailOut(REGLOOKUP_EXIT_USAGE, "ERROR: '-t' option requires parameter.\n");
      }
      if((type_filter = regfi_type_str2val(argv[argi])) < 0)
      {
	fprintf(stderr, "ERROR: Invalid type specified: %s.\n", argv[argi]);
	bailOut(REGLOOKUP_EXIT_USAGE, "");
      }
      type_filter_enabled = true;
    }
    else if (strcmp("-h", argv[argi]) == 0)
      print_header = true;
    else if (strcmp("-H", argv[argi]) == 0)
      print_header = false;
    else if (strcmp("-s", argv[argi]) == 0)
      print_security = true;
    else if (strcmp("-S", argv[argi]) == 0)
      print_security = false;
    else if (strcmp("-v", argv[argi]) == 0)
      print_verbose = true;
    else if (strcmp("-i", argv[argi]) == 0)
      print_value_mtime = true;
    else
    {
      usage();
      fprintf(stderr, "ERROR: Unrecognized option: %s\n", argv[argi]);
      bailOut(REGLOOKUP_EXIT_USAGE, "");
    }
  }
  registry_file = argv[argi];

  if(print_verbose)
    regfi_log_set_mask(REGFI_LOG_INFO|REGFI_LOG_WARN|REGFI_LOG_ERROR);

  fd = openHive(registry_file);
  if(fd < 0)
  {
    fprintf(stderr, "ERROR: Couldn't open registry file: %s\n", registry_file);
    bailOut(REGLOOKUP_EXIT_NOINPUT, "");
  }
    
  /* XXX: add command line option to choose output encoding */
  f = regfi_alloc(fd, REGFI_ENCODING_ASCII);
  if(f == NULL)
  {
    close(fd);
    bailOut(REGLOOKUP_EXIT_NOINPUT, "ERROR: Failed to create REGFI_FILE structure.\n");
  }

  iter = regfi_iterator_new(f);
  if(iter == NULL)
  {
    printMsgs(f);
    bailOut(REGLOOKUP_EXIT_OSERR, "ERROR: Couldn't create registry iterator.\n");
  }

  if(print_header)
  {
    if(print_security)
      printf("PATH,TYPE,VALUE,MTIME,OWNER,GROUP,SACL,DACL,CLASS\n");
    else
      printf("PATH,TYPE,VALUE,MTIME\n");
  }

  if(path_filter_enabled && path_filter != NULL)
    path = splitPath(path_filter);

  if(path != NULL)
  {
    retr_path_ret = retrievePath(iter, path);
    printMsgs(iter->f);
    freePath(path);

    if(retr_path_ret == 0)
      fprintf(stderr, "WARN: Specified path '%s' not found.\n", path_filter);
    else if (retr_path_ret == 2)
      printKeyTree(iter);
    else if(retr_path_ret < 0)
    {
      fprintf(stderr, "ERROR: retrievePath() returned %d.\n", 
	      retr_path_ret);
      bailOut(REGLOOKUP_EXIT_DATAERR,
	      "ERROR: Unknown error occurred in retrieving path.\n");
    }
  }
  else
    printKeyTree(iter);

  regfi_iterator_free(iter);
  regfi_free(f);
  close(fd);

  return 0;
}