~ubuntu-dev/sleuthkit/trunk

« back to all changes in this revision

Viewing changes to tsk3/auto/auto_db.cpp

  • Committer: carriersvn
  • Date: 2011-10-05 02:47:12 UTC
  • Revision ID: svn-v4:1db85b72-fc57-0410-9196-8d408266ab40:trunk:399
udpated multi-image database code. Patch by Peter Martel

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
TskAutoDb::~TskAutoDb()
33
33
{
34
34
    closeImage();
35
 
 
36
 
    delete m_db;
37
 
    m_db = NULL;
38
35
}
39
36
 
40
37
void
140
137
 * @return Returns 1 on error
141
138
 */
142
139
 
143
 
uint8_t
144
 
TskAutoDb::addImageDetails(const char *const img_ptrs[], int a_num)
 
140
uint8_t TskAutoDb::addImageDetails(const char *const img_ptrs[], int a_num)
145
141
{
146
142
    if (m_db->addImageInfo(m_img_info->itype, m_img_info->sector_size,
147
143
            m_curImgId)) {
150
146
 
151
147
    // Add the image names
152
148
    for (int i = 0; i < a_num; i++) {
153
 
        int a;
154
 
        const char *img_ptr = NULL;
 
149
        const char *
 
150
            img_ptr = NULL;
155
151
        img_ptr = img_ptrs[i];
156
152
 
157
 
        // get only the file name (ignore the directory name)
158
 
        for (a = strlen(img_ptr) - 1; a > 0; a--) {
159
 
            if ((img_ptr[a] == '/') || (img_ptr[a] == '\\')) {
160
 
                a++;
161
 
                break;
162
 
            }
163
 
        }
 
153
        //// get only the file name (ignore the directory name)
 
154
        //for (a = strlen(img_ptr) - 1; a > 0; a--) {
 
155
        //    if ((img_ptr[a] == '/') || (img_ptr[a] == '\\')) {
 
156
        //        a++;
 
157
        //        break;
 
158
        //    }
 
159
        //}
164
160
 
165
 
        if (m_db->addImageName(m_curImgId, &img_ptr[a], i)) {
 
161
        if (m_db->addImageName(m_curImgId, img_ptr, i)) {
166
162
            return 1;
167
163
        }
168
164
    }
175
171
 * Analyzes the open image and adds image info to a database.
176
172
 * @returns 1 on error
177
173
 */
178
 
uint8_t TskAutoDb::addFilesInImgToDb()
 
174
uint8_t
 
175
TskAutoDb::addFilesInImgToDb()
179
176
{
180
177
    if (m_db == NULL || !m_db->dbExist()) {
181
178
        tsk_error_reset();
187
184
    setVolFilterFlags((TSK_VS_PART_FLAG_ENUM) (TSK_VS_PART_FLAG_ALLOC |
188
185
            TSK_VS_PART_FLAG_UNALLOC));
189
186
 
190
 
    uint8_t
191
 
        retval = findFilesInImg();
 
187
    uint8_t retval = findFilesInImg();
192
188
    if (retval)
193
189
        return retval;
194
190
 
195
191
    return 0;
196
192
}
197
193
 
198
 
TSK_FILTER_ENUM TskAutoDb::filterVs(const TSK_VS_INFO * vs_info)
 
194
TSK_FILTER_ENUM
 
195
TskAutoDb::filterVs(const TSK_VS_INFO * vs_info)
199
196
{
200
197
    m_vsFound = true;
201
198
    if (m_db->addVsInfo(vs_info, m_curImgId, m_curVsId)) {
205
202
    return TSK_FILTER_CONT;
206
203
}
207
204
 
208
 
TSK_FILTER_ENUM
209
 
TskAutoDb::filterVol(const TSK_VS_PART_INFO * vs_part)
 
205
TSK_FILTER_ENUM TskAutoDb::filterVol(const TSK_VS_PART_INFO * vs_part)
210
206
{
211
207
    m_volFound = true;
212
208
 
218
214
}
219
215
 
220
216
 
221
 
TSK_FILTER_ENUM
222
 
TskAutoDb::filterFs(TSK_FS_INFO * fs_info)
 
217
TSK_FILTER_ENUM TskAutoDb::filterFs(TSK_FS_INFO * fs_info)
223
218
{
224
 
    TSK_FS_FILE *file_root;
 
219
    TSK_FS_FILE *
 
220
        file_root;
225
221
 
226
222
    if (m_volFound && m_vsFound) {
227
223
        // there's a volume system and volume
272
268
 * or revertProcess() to revert them.
273
269
 */
274
270
uint8_t
275
 
TskAutoDb::runProcess(int numImg, const TSK_TCHAR * const imagePaths[],
 
271
    TskAutoDb::runProcess(int numImg, const TSK_TCHAR * const imagePaths[],
276
272
    TSK_IMG_TYPE_ENUM imgType, unsigned int sSize)
277
273
{
278
274
    if (m_db->savepoint(TSK_ADD_IMAGE_SAVEPOINT))
279
275
        return 1;
 
276
    if (m_db->setup())
 
277
        return 1;
 
278
 
280
279
    if (openImage(numImg, imagePaths, imgType, sSize)
281
280
        || addFilesInImgToDb()) {
282
 
        m_db->rollbackSavepoint(TSK_ADD_IMAGE_SAVEPOINT);
 
281
        // rollback on error
 
282
 
 
283
        // rollbackSavepoint can throw errors too, need to make sure original
 
284
        // error message is preserved;
 
285
        const char *prior_msg = tsk_error_get();
 
286
        if (m_db->rollbackSavepoint(TSK_ADD_IMAGE_SAVEPOINT) ||
 
287
            m_db->releaseSavepoint(TSK_ADD_IMAGE_SAVEPOINT)) {
 
288
            if (prior_msg) {
 
289
                tsk_error_set_errstr("%s caused: %s", prior_msg,
 
290
                    tsk_error_get());
 
291
            }
 
292
        }
 
293
        m_db->cleanup();
283
294
        return 1;
284
295
    }
285
296
 
 
297
    m_db->cleanup();
286
298
    return 0;
287
299
}
288
300
 
289
301
#ifdef WIN32
290
302
uint8_t
291
 
TskAutoDb::runProcess(int numImg, const char *const imagePaths[],
 
303
    TskAutoDb::runProcess(int numImg, const char *const imagePaths[],
292
304
    TSK_IMG_TYPE_ENUM imgType, unsigned int sSize)
293
305
{
294
306
    if (m_db->savepoint(TSK_ADD_IMAGE_SAVEPOINT))
295
307
        return 1;
 
308
    if (m_db->setup())
 
309
        return 1;
 
310
 
296
311
    if (openImageUtf8(numImg, imagePaths, imgType, sSize)
297
312
        || addFilesInImgToDb()) {
298
 
        // rollback on stop command or error
299
 
        m_db->rollbackSavepoint(TSK_ADD_IMAGE_SAVEPOINT);
 
313
        // rollback on error
 
314
 
 
315
        // rollbackSavepoint can throw errors too, need to make sure original
 
316
        // error message is preserved;
 
317
        const char *prior_msg = tsk_error_get();
 
318
        if (m_db->rollbackSavepoint(TSK_ADD_IMAGE_SAVEPOINT) ||
 
319
            m_db->releaseSavepoint(TSK_ADD_IMAGE_SAVEPOINT)) {
 
320
            if (prior_msg) {
 
321
                tsk_error_set_errstr("%s caused: %s", prior_msg,
 
322
                    tsk_error_get());
 
323
            }
 
324
        }
 
325
        m_db->cleanup();
 
326
        return 1;
300
327
    }
301
328
 
 
329
    m_db->cleanup();
302
330
    return 0;
303
331
}
304
332
#endif
305
333
 
306
334
 
307
335
/**
308
 
 * Cancel (and subesquently revert) the running process.
 
336
 * Cancel the running process.
309
337
 */
310
338
void
311
 
TskAutoDb::stopProcess()
 
339
 TskAutoDb::stopProcess()
312
340
{
313
341
    m_stopped = true;
314
342
    // flag is checked every time processFile() is called
318
346
 * Revert all changes after the process has run sucessfully.
319
347
 */
320
348
void
321
 
TskAutoDb::revertProcess()
 
349
 TskAutoDb::revertProcess()
322
350
{
323
351
    m_db->rollbackSavepoint(TSK_ADD_IMAGE_SAVEPOINT);
 
352
    m_db->releaseSavepoint(TSK_ADD_IMAGE_SAVEPOINT);
324
353
}
325
354
 
326
355
/**
327
356
 * Finish the process after it has run sucessfully by committing the changes.
328
357
 * Returns the id of the image that was added.
329
358
 */
330
 
int64_t
331
 
TskAutoDb::commitProcess()
 
359
int64_t TskAutoDb::commitProcess()
332
360
{
333
361
    m_db->releaseSavepoint(TSK_ADD_IMAGE_SAVEPOINT);
334
362
    return m_curImgId;
373
401
            return TSK_ERR;
374
402
    }
375
403
 
376
 
 
377
 
 
378
404
    // add the block map, if requested and the file is non-resident
379
405
    if ((m_blkMapFlag) && (isNonResident(fs_attr))
380
406
        && (isDotDir(fs_file, path) == 0)) {