ndrdump: Fix one more NTSTATUS rather than friendly ndr message
[gd/samba-autobuild/.git] / librpc / tools / ndrdump.c
1 /* 
2    Unix SMB/CIFS implementation.
3    SMB torture tester
4    Copyright (C) Andrew Tridgell 2003
5    Copyright (C) Jelmer Vernooij 2006
6    
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
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, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "includes.h"
22 #include "system/filesys.h"
23 #include "system/locale.h"
24 #include "librpc/ndr/libndr.h"
25 #include "librpc/ndr/ndr_table.h"
26 #include "librpc/gen_ndr/ndr_dcerpc.h"
27 #include "lib/cmdline/popt_common.h"
28 #include "param/param.h"
29
30 static const struct ndr_interface_call *find_function(
31         const struct ndr_interface_table *p,
32         const char *function)
33 {
34         unsigned int i;
35         if (isdigit(function[0])) {
36                 char *eptr = NULL;
37                 i = strtoul(function, &eptr, 0);
38                 if (i >= p->num_calls
39                     || eptr == NULL
40                     || eptr[0] != '\0') {
41                         printf("Function number '%s' not found\n",
42                                function);
43                         exit(1);
44                 }
45                 return &p->calls[i];
46         }
47         for (i=0;i<p->num_calls;i++) {
48                 if (strcmp(p->calls[i].name, function) == 0) {
49                         break;
50                 }
51         }
52         if (i == p->num_calls) {
53                 printf("Function '%s' not found\n", function);
54                 exit(1);
55         }
56         return &p->calls[i];
57 }
58
59 /*
60  * Find a public structure on the pipe and return it as if it were
61  * a function (as the rest of ndrdump is based around functions)
62  */
63 static const struct ndr_interface_call *find_struct(
64         const struct ndr_interface_table *p,
65         const char *struct_name,
66         struct ndr_interface_call *out_buffer)
67 {
68         unsigned int i;
69         const struct ndr_interface_public_struct *public_struct = NULL;
70         if (isdigit(struct_name[0])) {
71                 char *eptr = NULL;
72                 i = strtoul(struct_name, &eptr, 0);
73                 if (i >= p->num_public_structs
74                     || eptr == NULL
75                     || eptr[0] != '\0') {
76                         printf("Public structure number '%s' not found\n",
77                                struct_name);
78                         exit(1);
79                 }
80                 public_struct = &p->public_structs[i];
81         } else {
82                 for (i=0;i<p->num_public_structs;i++) {
83                         if (strcmp(p->public_structs[i].name, struct_name) == 0) {
84                                 break;
85                         }
86                 }
87                 if (i == p->num_public_structs) {
88                         printf("Public structure '%s' not found\n", struct_name);
89                         exit(1);
90                 }
91                 public_struct = &p->public_structs[i];
92         }
93         *out_buffer = (struct ndr_interface_call) {
94                 .name = public_struct->name,
95                 .struct_size = public_struct->struct_size,
96                 .ndr_pull = public_struct->ndr_pull,
97                 .ndr_push = public_struct->ndr_push,
98                 .ndr_print = public_struct->ndr_print
99         };
100         return out_buffer;
101 }
102
103 _NORETURN_ static void show_pipes(void)
104 {
105         const struct ndr_interface_list *l;
106         printf("\nYou must specify a pipe\n");
107         printf("known pipes are:\n");
108         for (l=ndr_table_list();l;l=l->next) {
109                 if(l->table->helpstring) {
110                         printf("\t%s - %s\n", l->table->name, l->table->helpstring);
111                 } else {
112                         printf("\t%s\n", l->table->name);
113                 }
114         }
115         exit(1);
116 }
117
118 _NORETURN_ static void show_functions(const struct ndr_interface_table *p)
119 {
120         int i;
121         printf("\nYou must specify a function\n");
122         printf("known functions on '%s' are:\n", p->name);
123         for (i=0;i<p->num_calls;i++) {
124                 printf("\t0x%02x (%2d) %s\n", i, i, p->calls[i].name);
125         }
126         printf("known public structures on '%s' are:\n", p->name);
127         for (i=0;i<p->num_public_structs;i++) {
128                 printf("\t%s\n", p->public_structs[i].name);
129         }
130         exit(1);
131 }
132
133 static char *stdin_load(TALLOC_CTX *mem_ctx, size_t *size)
134 {
135         int num_read, total_len = 0;
136         char buf[255];
137         char *result = NULL;
138
139         while((num_read = read(STDIN_FILENO, buf, 255)) > 0) {
140
141                 if (result) {
142                         result = talloc_realloc(
143                                 mem_ctx, result, char, total_len + num_read);
144                 } else {
145                         result = talloc_array(mem_ctx, char, num_read);
146                 }
147
148                 memcpy(result + total_len, buf, num_read);
149
150                 total_len += num_read;
151         }
152
153         if (size)
154                 *size = total_len;
155
156         return result;
157 }
158
159 static const struct ndr_interface_table *load_iface_from_plugin(const char *plugin, const char *pipe_name)
160 {
161         const struct ndr_interface_table *p;
162         void *handle;
163         char *symbol;
164
165         handle = dlopen(plugin, RTLD_NOW);
166         if (handle == NULL) {
167                 printf("%s: Unable to open: %s\n", plugin, dlerror());
168                 return NULL;
169         }
170
171         symbol = talloc_asprintf(NULL, "ndr_table_%s", pipe_name);
172         p = (const struct ndr_interface_table *)dlsym(handle, symbol);
173
174         if (!p) {
175                 printf("%s: Unable to find DCE/RPC interface table for '%s': %s\n", plugin, pipe_name, dlerror());
176                 talloc_free(symbol);
177                 dlclose(handle);
178                 return NULL;
179         }
180
181         talloc_free(symbol);
182         
183         return p;
184 }
185
186 static void ndrdump_data(uint8_t *d, uint32_t l, bool force)
187 {
188         dump_data_file(d, l, !force, stdout);
189 }
190
191 static NTSTATUS ndrdump_pull_and_print_pipes(const char *function,
192                                 struct ndr_pull *ndr_pull,
193                                 struct ndr_print *ndr_print,
194                                 const struct ndr_interface_call_pipes *pipes)
195 {
196         enum ndr_err_code ndr_err;
197         uint32_t i;
198
199         for (i=0; i < pipes->num_pipes; i++) {
200                 uint64_t idx = 0;
201                 while (true) {
202                         void *saved_mem_ctx;
203                         uint32_t *count;
204                         void *c;
205                         char *n;
206
207                         c = talloc_zero_size(ndr_pull, pipes->pipes[i].chunk_struct_size);
208                         talloc_set_name(c, "struct %s", pipes->pipes[i].name);
209                         /*
210                          * Note: the first struct member is always
211                          * 'uint32_t count;'
212                          */
213                         count = (uint32_t *)c;
214
215                         n = talloc_asprintf(c, "%s: %s[%llu]",
216                                         function, pipes->pipes[i].name,
217                                         (unsigned long long)idx);
218
219                         saved_mem_ctx = ndr_pull->current_mem_ctx;
220                         ndr_pull->current_mem_ctx = c;
221                         ndr_err = pipes->pipes[i].ndr_pull(ndr_pull, NDR_SCALARS, c);
222                         ndr_pull->current_mem_ctx = saved_mem_ctx;
223
224                         printf("pull returned %s\n",
225                                ndr_map_error2string(ndr_err));
226                         if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
227                                 talloc_free(c);
228                                 return ndr_map_error2ntstatus(ndr_err);
229                         }
230                         pipes->pipes[i].ndr_print(ndr_print, n, c);
231                         if (*count == 0) {
232                                 talloc_free(c);
233                                 break;
234                         }
235                         talloc_free(c);
236                         idx++;
237                 }
238         }
239
240         return NT_STATUS_OK;
241 }
242
243 static void ndr_print_dummy(struct ndr_print *ndr, const char *format, ...)
244 {
245         /* This is here so that you can turn ndr printing off for the purposes
246            of benchmarking ndr parsing. */
247 }
248
249  int main(int argc, const char *argv[])
250 {
251         const struct ndr_interface_table *p = NULL;
252         const struct ndr_interface_call *f;
253         struct ndr_interface_call f_buffer;
254         const char *pipe_name = NULL;
255         const char *filename = NULL;
256         /*
257          * The format type:
258          *   in:     a request
259          *   out:    a response
260          *   struct: a public structure
261          */
262         const char *type = NULL;
263         /*
264          * Format is either the name of the decoding function or the
265          * name of a public structure
266          */
267         const char *format = NULL;
268         uint8_t *data;
269         size_t size;
270         DATA_BLOB blob;
271         struct ndr_pull *ndr_pull;
272         struct ndr_print *ndr_print;
273         TALLOC_CTX *mem_ctx;
274         int flags = 0;
275         poptContext pc;
276         NTSTATUS status;
277         enum ndr_err_code ndr_err;
278         void *st;
279         void *v_st;
280         const char *ctx_filename = NULL;
281         const char *plugin = NULL;
282         bool validate = false;
283         bool dumpdata = false;
284         bool assume_ndr64 = false;
285         bool quiet = false;
286         bool hex_input = false;
287         bool stop_on_parse_failure = false;
288         int opt;
289         enum {
290                 OPT_CONTEXT_FILE=1000,
291                 OPT_VALIDATE,
292                 OPT_DUMP_DATA,
293                 OPT_LOAD_DSO,
294                 OPT_NDR64,
295                 OPT_QUIET,
296                 OPT_HEX_INPUT,
297                 OPT_STOP_ON_PARSE_FAILURE,
298         };
299         struct poptOption long_options[] = {
300                 POPT_AUTOHELP
301                 {"context-file", 'c', POPT_ARG_STRING, NULL, OPT_CONTEXT_FILE, "In-filename to parse first", "CTX-FILE" },
302                 {"validate", 0, POPT_ARG_NONE, NULL, OPT_VALIDATE, "try to validate the data", NULL },  
303                 {"dump-data", 0, POPT_ARG_NONE, NULL, OPT_DUMP_DATA, "dump the hex data", NULL },       
304                 {"load-dso", 'l', POPT_ARG_STRING, NULL, OPT_LOAD_DSO, "load from shared object file", NULL },
305                 {"ndr64", 0, POPT_ARG_NONE, NULL, OPT_NDR64, "Assume NDR64 data", NULL },
306                 {"quiet", 0, POPT_ARG_NONE, NULL, OPT_QUIET, "Don't actually dump anything", NULL },
307                 {"hex-input", 0, POPT_ARG_NONE, NULL, OPT_HEX_INPUT, "Read the input file in as a hex dump", NULL },
308                 {"stop-on-parse-failure", 0, POPT_ARG_NONE, NULL, OPT_STOP_ON_PARSE_FAILURE,
309                  "Do not try to print structures that fail to parse.", NULL },
310                 POPT_COMMON_SAMBA
311                 POPT_COMMON_VERSION
312                 { NULL }
313         };
314         uint32_t highest_ofs;
315         struct dcerpc_sec_verification_trailer *sec_vt = NULL;
316         
317         ndr_table_init();
318
319         /* Initialise samba stuff */
320         smb_init_locale();
321
322         setlinebuf(stdout);
323
324         setup_logging("ndrdump", DEBUG_STDOUT);
325
326         pc = poptGetContext("ndrdump", argc, argv, long_options, 0);
327         
328         poptSetOtherOptionHelp(
329                 pc, "<pipe|uuid> <format> <in|out|struct> [<filename>]");
330
331         while ((opt = poptGetNextOpt(pc)) != -1) {
332                 switch (opt) {
333                 case OPT_CONTEXT_FILE:
334                         ctx_filename = poptGetOptArg(pc);
335                         break;
336                 case OPT_VALIDATE:
337                         validate = true;
338                         break;
339                 case OPT_DUMP_DATA:
340                         dumpdata = true;
341                         break;
342                 case OPT_LOAD_DSO:
343                         plugin = poptGetOptArg(pc);
344                         break;
345                 case OPT_NDR64:
346                         assume_ndr64 = true;
347                         break;
348                 case OPT_QUIET:
349                         quiet = true;
350                         break;
351                 case OPT_HEX_INPUT:
352                         hex_input = true;
353                         break;
354                 case OPT_STOP_ON_PARSE_FAILURE:
355                         stop_on_parse_failure = true;
356                         break;
357                 }
358         }
359
360         pipe_name = poptGetArg(pc);
361
362         if (!pipe_name) {
363                 poptPrintUsage(pc, stderr, 0);
364                 show_pipes();
365                 exit(1);
366         }
367
368         if (plugin != NULL) {
369                 p = load_iface_from_plugin(plugin, pipe_name);
370         } 
371         if (!p) {
372                 p = ndr_table_by_name(pipe_name);
373         }
374
375         if (!p) {
376                 struct GUID uuid;
377
378                 status = GUID_from_string(pipe_name, &uuid);
379
380                 if (NT_STATUS_IS_OK(status)) {
381                         p = ndr_table_by_uuid(&uuid);
382                 }
383         }
384
385         if (!p) {
386                 printf("Unknown pipe or UUID '%s'\n", pipe_name);
387                 exit(1);
388         }
389
390         format = poptGetArg(pc);
391         type = poptGetArg(pc);
392         filename = poptGetArg(pc);
393
394         if (!format || !type) {
395                 poptPrintUsage(pc, stderr, 0);
396                 show_functions(p);
397                 exit(1);
398         }
399
400         if (strcmp(type, "struct") == 0) {
401                 flags = NDR_SCALARS|NDR_BUFFERS; /* neither NDR_IN nor NDR_OUT */
402                 f = find_struct(p, format, &f_buffer);
403         } else {
404                 f = find_function(p, format);
405                 if (strcmp(type, "in") == 0 ||
406                     strcmp(type, "request") == 0) {
407                         flags |= NDR_IN;
408                 } else if (strcmp(type, "out") == 0 ||
409                            strcmp(type, "response") == 0) {
410                         flags |= NDR_OUT;
411                 } else {
412                         printf("Bad type value '%s'\n", type);
413                         exit(1);
414                 }
415         }
416
417
418         mem_ctx = talloc_init("ndrdump");
419
420         st = talloc_zero_size(mem_ctx, f->struct_size);
421         if (!st) {
422                 printf("Unable to allocate %d bytes\n", (int)f->struct_size);
423                 exit(1);
424         }
425
426         v_st = talloc_zero_size(mem_ctx, f->struct_size);
427         if (!v_st) {
428                 printf("Unable to allocate %d bytes\n", (int)f->struct_size);
429                 exit(1);
430         }
431
432         if (ctx_filename) {
433                 if (flags & NDR_IN) {
434                         printf("Context file can only be used for \"out\" packages\n");
435                         exit(1);
436                 }
437                         
438                 data = (uint8_t *)file_load(ctx_filename, &size, 0, mem_ctx);
439                 if (!data) {
440                         perror(ctx_filename);
441                         exit(1);
442                 }
443
444                 blob.data = data;
445                 blob.length = size;
446
447                 ndr_pull = ndr_pull_init_blob(&blob, mem_ctx);
448                 if (ndr_pull == NULL) {
449                         perror("ndr_pull_init_blob");
450                         exit(1);
451                 }
452                 ndr_pull->flags |= LIBNDR_FLAG_REF_ALLOC;
453                 if (assume_ndr64) {
454                         ndr_pull->flags |= LIBNDR_FLAG_NDR64;
455                 }
456
457                 ndr_err = f->ndr_pull(ndr_pull, NDR_IN, st);
458
459                 if (ndr_pull->offset > ndr_pull->relative_highest_offset) {
460                         highest_ofs = ndr_pull->offset;
461                 } else {
462                         highest_ofs = ndr_pull->relative_highest_offset;
463                 }
464
465                 if (highest_ofs != ndr_pull->data_size) {
466                         printf("WARNING! %d unread bytes while parsing context file\n", ndr_pull->data_size - highest_ofs);
467                 }
468
469                 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
470                         printf("pull for context file returned %s\n",
471                                ndr_map_error2string(ndr_err));
472                         exit(1);
473                 }
474                 memcpy(v_st, st, f->struct_size);
475         }
476
477         if (filename)
478                 data = (uint8_t *)file_load(filename, &size, 0, mem_ctx);
479         else
480                 data = (uint8_t *)stdin_load(mem_ctx, &size);
481
482         if (!data) {
483                 if (filename)
484                         perror(filename);
485                 else
486                         perror("stdin");
487                 exit(1);
488         }
489         
490         if (hex_input) {
491                 blob = hexdump_to_data_blob(mem_ctx, (char *)data, size);
492         } else {
493                 blob.data = data;
494                 blob.length = size;
495         }
496
497         ndr_pull = ndr_pull_init_blob(&blob, mem_ctx);
498         if (ndr_pull == NULL) {
499                 perror("ndr_pull_init_blob");
500                 exit(1);
501         }
502         ndr_pull->flags |= LIBNDR_FLAG_REF_ALLOC;
503         if (assume_ndr64) {
504                 ndr_pull->flags |= LIBNDR_FLAG_NDR64;
505         }
506
507         ndr_print = talloc_zero(mem_ctx, struct ndr_print);
508         if (quiet) {
509                 ndr_print->print = ndr_print_dummy;
510         } else {
511                 ndr_print->print = ndr_print_printf_helper;
512         }
513         ndr_print->depth = 1;
514
515         ndr_err = ndr_pop_dcerpc_sec_verification_trailer(ndr_pull, mem_ctx, &sec_vt);
516         if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
517                 printf("ndr_pop_dcerpc_sec_verification_trailer returned %s\n",
518                        ndr_map_error2string(ndr_err));
519         }
520
521         if (sec_vt != NULL && sec_vt->count.count > 0) {
522                 printf("SEC_VT: consumed %d bytes\n",
523                        (int)(blob.length - ndr_pull->data_size));
524                 if (dumpdata) {
525                         ndrdump_data(blob.data + ndr_pull->data_size,
526                                      blob.length - ndr_pull->data_size,
527                                      dumpdata);
528                 }
529                 ndr_print_dcerpc_sec_verification_trailer(ndr_print, "SEC_VT", sec_vt);
530         }
531         TALLOC_FREE(sec_vt);
532
533         if (flags & NDR_OUT) {
534                 status = ndrdump_pull_and_print_pipes(format,
535                                                       ndr_pull,
536                                                       ndr_print,
537                                                       &f->out_pipes);
538                 if (!NT_STATUS_IS_OK(status)) {
539                         printf("dump FAILED\n");
540                         exit(1);
541                 }
542         }
543
544         ndr_err = f->ndr_pull(ndr_pull, flags, st);
545         printf("pull returned %s\n",
546                ndr_map_error2string(ndr_err));
547
548         if (stop_on_parse_failure && !NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
549                 printf("not printing because --stop-on-parse-failure\n");
550                 exit(1);
551         }
552
553         if (ndr_pull->offset > ndr_pull->relative_highest_offset) {
554                 highest_ofs = ndr_pull->offset;
555         } else {
556                 highest_ofs = ndr_pull->relative_highest_offset;
557         }
558
559         if (highest_ofs != ndr_pull->data_size) {
560                 printf("WARNING! %d unread bytes\n", ndr_pull->data_size - highest_ofs);
561                 ndrdump_data(ndr_pull->data+highest_ofs,
562                              ndr_pull->data_size - highest_ofs,
563                              dumpdata);
564         }
565
566         if (dumpdata) {
567                 printf("%d bytes consumed\n", highest_ofs);
568                 ndrdump_data(blob.data, blob.length, dumpdata);
569         }
570
571         f->ndr_print(ndr_print, format, flags, st);
572
573         if (flags & NDR_IN) {
574                 status = ndrdump_pull_and_print_pipes(format,
575                                                       ndr_pull,
576                                                       ndr_print,
577                                                       &f->in_pipes);
578                 if (!NT_STATUS_IS_OK(status)) {
579                         printf("dump FAILED\n");
580                         exit(1);
581                 }
582         }
583
584         if (validate) {
585                 DATA_BLOB v_blob;
586                 struct ndr_push *ndr_v_push;
587                 struct ndr_pull *ndr_v_pull;
588                 struct ndr_print *ndr_v_print;
589                 uint32_t highest_v_ofs;
590                 uint32_t i;
591                 uint8_t byte_a, byte_b;
592                 bool differ;
593
594                 ndr_v_push = ndr_push_init_ctx(mem_ctx);
595                 if (ndr_v_push == NULL) {
596                         printf("No memory\n");
597                         exit(1);
598                 }
599
600                 if (assume_ndr64) {
601                         ndr_v_push->flags |= LIBNDR_FLAG_NDR64;
602                 }
603
604                 ndr_err = f->ndr_push(ndr_v_push, flags, st);
605                 printf("push returned %s\n",
606                        ndr_map_error2string(ndr_err));
607                 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
608                         printf("validate push FAILED\n");
609                         exit(1);
610                 }
611
612                 v_blob = ndr_push_blob(ndr_v_push);
613
614                 if (dumpdata) {
615                         printf("%ld bytes generated (validate)\n", (long)v_blob.length);
616                         ndrdump_data(v_blob.data, v_blob.length, dumpdata);
617                 }
618
619                 ndr_v_pull = ndr_pull_init_blob(&v_blob, mem_ctx);
620                 if (ndr_v_pull == NULL) {
621                         perror("ndr_pull_init_blob");
622                         exit(1);
623                 }
624                 ndr_v_pull->flags |= LIBNDR_FLAG_REF_ALLOC;
625
626                 ndr_err = f->ndr_pull(ndr_v_pull, flags, v_st);
627                 printf("pull returned %s\n",
628                        ndr_map_error2string(ndr_err));
629                 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
630                         printf("validate pull FAILED\n");
631                         exit(1);
632                 }
633
634                 if (ndr_v_pull->offset > ndr_v_pull->relative_highest_offset) {
635                         highest_v_ofs = ndr_v_pull->offset;
636                 } else {
637                         highest_v_ofs = ndr_v_pull->relative_highest_offset;
638                 }
639
640                 if (highest_v_ofs != ndr_v_pull->data_size) {
641                         printf("WARNING! %d unread bytes in validation\n",
642                                ndr_v_pull->data_size - highest_v_ofs);
643                         ndrdump_data(ndr_v_pull->data + highest_v_ofs,
644                                      ndr_v_pull->data_size - highest_v_ofs,
645                                      dumpdata);
646                 }
647
648                 ndr_v_print = talloc_zero(mem_ctx, struct ndr_print);
649                 ndr_v_print->print = ndr_print_debug_helper;
650                 ndr_v_print->depth = 1;
651                 f->ndr_print(ndr_v_print,
652                              format,
653                              flags, v_st);
654
655                 if (blob.length != v_blob.length) {
656                         printf("WARNING! orig bytes:%llu validated pushed bytes:%llu\n", 
657                                (unsigned long long)blob.length, (unsigned long long)v_blob.length);
658                 }
659
660                 if (highest_ofs != highest_v_ofs) {
661                         printf("WARNING! orig pulled bytes:%llu validated pulled bytes:%llu\n", 
662                                (unsigned long long)highest_ofs, (unsigned long long)highest_v_ofs);
663                 }
664
665                 differ = false;
666                 byte_a = 0x00;
667                 byte_b = 0x00;
668                 for (i=0; i < blob.length; i++) {
669                         byte_a = blob.data[i];
670
671                         if (i == v_blob.length) {
672                                 byte_b = 0x00;
673                                 differ = true;
674                                 break;
675                         }
676
677                         byte_b = v_blob.data[i];
678
679                         if (byte_a != byte_b) {
680                                 differ = true;
681                                 break;
682                         }
683                 }
684                 if (differ) {
685                         printf("WARNING! orig and validated differ at byte 0x%02X (%u)\n", i, i);
686                         printf("WARNING! orig byte[0x%02X] = 0x%02X validated byte[0x%02X] = 0x%02X\n",
687                                 i, byte_a, i, byte_b);
688                 }
689         }
690
691         printf("dump OK\n");
692         talloc_free(mem_ctx);
693
694         poptFreeContext(pc);
695         
696         return 0;
697 }