tdb/tools/tdbdump.c

説明を見る。
00001 /* 
00002    Unix SMB/CIFS implementation.
00003    simple tdb dump util
00004    Copyright (C) Andrew Tridgell              2001
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014    GNU General Public License for more details.
00015    
00016    You should have received a copy of the GNU General Public License
00017    along with this program; if not, write to the Free Software
00018    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019 */
00020 
00021 #include <errno.h>
00022 #include <stdlib.h>
00023 #include <stdio.h>
00024 #include <fcntl.h>
00025 #include <unistd.h>
00026 #include <string.h>
00027 #include <fcntl.h>
00028 #include <time.h>
00029 #include <sys/stat.h>
00030 #include <sys/time.h>
00031 #include <ctype.h>
00032 #include <signal.h>
00033 #include "tdb.h"
00034 
00035 static void print_data(TDB_DATA d)
00036 {
00037         unsigned char *p = (unsigned char *)d.dptr;
00038         int len = d.dsize;
00039         while (len--) {
00040                 if (isprint(*p) && !strchr("\"\\", *p)) {
00041                         fputc(*p, stdout);
00042                 } else {
00043                         printf("\\%02X", *p);
00044                 }
00045                 p++;
00046         }
00047 }
00048 
00049 static int traverse_fn(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, void *state)
00050 {
00051         printf("{\n");
00052         printf("key(%d) = \"", (int)key.dsize);
00053         print_data(key);
00054         printf("\"\n");
00055         printf("data(%d) = \"", (int)dbuf.dsize);
00056         print_data(dbuf);
00057         printf("\"\n");
00058         printf("}\n");
00059         return 0;
00060 }
00061 
00062 static int dump_tdb(const char *fname, const char *keyname)
00063 {
00064         TDB_CONTEXT *tdb;
00065         TDB_DATA key, value;
00066         
00067         tdb = tdb_open(fname, 0, 0, O_RDONLY, 0);
00068         if (!tdb) {
00069                 printf("Failed to open %s\n", fname);
00070                 return 1;
00071         }
00072 
00073         if (!keyname) {
00074                 tdb_traverse(tdb, traverse_fn, NULL);
00075         } else {
00076                 key.dptr = (char *)keyname;
00077                 key.dsize = strlen( keyname);
00078                 value = tdb_fetch(tdb, key);
00079                 if (!value.dptr) {
00080                         return 1;
00081                 } else {
00082                         print_data(value);
00083                         free(value.dptr);
00084                 }
00085         }
00086 
00087         return 0;
00088 }
00089 
00090 static void usage( void)
00091 {
00092         printf( "Usage: tdbdump [options] <filename>\n\n");
00093         printf( "   -h          this help message\n");
00094         printf( "   -k keyname  dumps value of keyname\n");
00095 }
00096 
00097  int main(int argc, char *argv[])
00098 {
00099         char *fname, *keyname=NULL;
00100         int c;
00101 
00102         if (argc < 2) {
00103                 printf("Usage: tdbdump <fname>\n");
00104                 exit(1);
00105         }
00106 
00107         while ((c = getopt( argc, argv, "hk:")) != -1) {
00108                 switch (c) {
00109                 case 'h':
00110                         usage();
00111                         exit( 0);
00112                 case 'k':
00113                         keyname = optarg;
00114                         break;
00115                 default:
00116                         usage();
00117                         exit( 1);
00118                 }
00119         }
00120 
00121         fname = argv[optind];
00122 
00123         return dump_tdb(fname, keyname);
00124 }

Sambaに対してSat Aug 29 21:23:27 2009に生成されました。  doxygen 1.4.7