add MDBPATH search

fix segfault in mdb-tables
This commit is contained in:
brianb
2003-01-05 23:49:56 +00:00
parent c6da2f1845
commit 52528c6e95
5 changed files with 79 additions and 22 deletions

10
TODO
View File

@@ -3,7 +3,7 @@ Things to Do
file format:
. how does global allocation map work?
. how does global allocation map work? (done)
. export VBA script
. re-examine KKD records for form design (OLE streams?)
. write support
@@ -17,8 +17,7 @@ libmdb:
. Sargs need to support all datatypes
. Need a way to express logical relationships between sargs (tree)
. Add support for index scanning when using sargs
. Use allocation maps to read tables, should be more efficient (done
if -DFAST_READ specified)
. Use allocation maps to read tables, should be more efficient (done)
. write support
utils:
@@ -45,6 +44,7 @@ ODBC:
GMDB:
. Finish debug dissectors
. Export schema not implemented
. Export schema not implemented (done)
. Printing not implemented
. Export needs finishing
. Export needs finishing (done)
. Fix bitmask size bug in debugger

View File

@@ -1,6 +1,6 @@
dnl Process this file with autoconf to produce a configure script.
AC_INIT(src/extras/mdb-dump.c)
AM_INIT_AUTOMAKE(mdbtools,0.4)
AM_INIT_AUTOMAKE(mdbtools,0.5)
AC_PROG_CC(gcc)
dnl Checks for programs.

View File

@@ -14,7 +14,7 @@ OPTIONS
-H Supress header row.
-F Supress footer row.
-p Turn off pretty printing. By default results are printed in an
ascii table format which looks nice but is not condusive to manipulating the
ascii table format which looks nice but is not conducive to manipulating the
output with unix tools. This option prints output plainly in a tab separated
format.
-d Specify an alternative column delimiter. If no delimiter is
@@ -43,7 +43,7 @@ SQL LANGUAGE
column list: <column> [, <column list>]
where clause: <column> <operator> <literal> [AND <where clause>]
where clause: <column> <operator> <literal> [AND <where clause>]
operator: =, =>, =<, <>, like, <, >

View File

@@ -27,36 +27,89 @@ MdbFormatConstants MdbJet3Constants = {
};
static size_t _mdb_read_pg(MdbHandle *mdb, unsigned char *pg_buf, unsigned long pg);
static int mdb_find_file(char *file_name, char *file_path, int bufsize)
{
struct stat status;
gchar *s, *mdbpath;
gchar *dir, *tmpfname;
int ret;
/* try the provided file name first */
if (!stat(file_name, &status)) {
if (strlen(file_name)> bufsize)
return strlen(file_name);
strcpy(file_path, file_name);
return 0;
}
/* Now pull apart $MDBPATH and try those */
s = (gchar *) getenv("MDBPATH");
if (!s || !strlen(s)) return -1; /* no path, can't find file */
mdbpath = g_strdup(s);
dir = strtok(mdbpath,":");
do {
tmpfname = (gchar *) g_malloc(strlen(dir)+strlen(file_name)+2);
strcpy(tmpfname, dir);
if (dir[strlen(dir)-1]!='/') strcat(tmpfname, "/");
strcat(tmpfname, file_name);
if (!stat(tmpfname, &status)) {
if (strlen(tmpfname)> bufsize) {
ret = strlen(tmpfname);
g_free(tmpfname);
return ret;
}
strcpy(file_path, tmpfname);
g_free(tmpfname);
return 0;
}
g_free(tmpfname);
} while (dir = strtok(NULL, ":"));
return -1;
}
MdbHandle *_mdb_open(char *filename, gboolean writable)
{
MdbHandle *mdb;
int key[] = {0x86, 0xfb, 0xec, 0x37, 0x5d, 0x44, 0x9c, 0xfa, 0xc6, 0x5e, 0x28, 0xe6, 0x13, 0xb6};
int j,pos;
int bufsize;
MdbFile *f;
mdb = mdb_alloc_handle();
/* need something to bootstrap with, reassign after page 0 is read */
mdb->fmt = &MdbJet3Constants;
mdb->f = mdb_alloc_file();
mdb->f->filename = (char *) malloc(strlen(filename)+1);
strcpy(mdb->f->filename, filename);
f = mdb->f;
f->filename = (char *) malloc(strlen(filename)+1);
bufsize = strlen(filename)+1;
bufsize = mdb_find_file(filename, f->filename, bufsize);
if (bufsize) {
f->filename = (char *) realloc(f->filename, bufsize+1);
bufsize = mdb_find_file(filename, f->filename, bufsize);
if (bufsize) {
fprintf(stderr, "Can't alloc filename\n");
mdb_free_handle(mdb);
return NULL;
}
}
//strcpy(f->filename, filename);
if (writable) {
mdb->f->writable = TRUE;
mdb->f->fd = open(filename,O_RDWR);
f->writable = TRUE;
f->fd = open(f->filename,O_RDWR);
} else {
mdb->f->fd = open(filename,O_RDONLY);
f->fd = open(f->filename,O_RDONLY);
}
if (mdb->f->fd==-1) {
/* fprintf(stderr,"Couldn't open file %s\n",filename); */
if (f->fd==-1) {
fprintf(stderr,"Couldn't open file %s\n",f->filename);
return NULL;
}
mdb->f->refs++;
f->refs++;
if (!mdb_read_pg(mdb, 0)) {
fprintf(stderr,"Couldn't read first page.\n");
return NULL;
}
mdb->f->jet_version = mdb_get_int32(mdb, 0x14);
f->jet_version = mdb_get_int32(mdb, 0x14);
if (IS_JET4(mdb)) {
mdb->fmt = &MdbJet4Constants;
} else {
@@ -64,8 +117,8 @@ int j,pos;
}
/* get the db encryption key and xor it back to clear text */
mdb->f->db_key = mdb_get_int32(mdb, 0x3e);
mdb->f->db_key ^= 0xe15e01b9;
f->db_key = mdb_get_int32(mdb, 0x3e);
f->db_key ^= 0xe15e01b9;
/* get the db password located at 0x42 bytes into the file */
@@ -73,9 +126,9 @@ int j,pos;
j = mdb_get_int32(mdb,0x42+pos);
j ^= key[pos];
if ( j != 0)
mdb->f->db_passwd[pos] = j;
f->db_passwd[pos] = j;
else
mdb->f->db_passwd[pos] = '\0';
f->db_passwd[pos] = '\0';
}
return mdb;

View File

@@ -56,7 +56,11 @@ int opt;
mdb_init();
/* open the database */
mdb = mdb_open (argv[optind]);
if (!(mdb = mdb_open (argv[optind]))) {
fprintf(stderr,"Couldn't open database.\n");
exit(1);
}
/* read the catalog */
mdb_read_catalog (mdb, MDB_TABLE);