~ubuntu-branches/ubuntu/saucy/suricata/saucy-updates

« back to all changes in this revision

Viewing changes to src/log-filestore.c

  • Committer: Package Import Robot
  • Author(s): Pierre Chifflier
  • Date: 2012-12-14 00:02:51 UTC
  • mfrom: (1.1.18)
  • Revision ID: package-import@ubuntu.com-20121214000251-3326bvmr1x6ofsy5
Tags: 1.4-1
* Imported Upstream version 1.4
* Enable Jansson and LuaJIT support, and add libjansson-dev libluajit-5.1-dev
  to build-deps
* Add python to recommends, for the suricatasc script
* Create /var/run/suricata directory when starting daemon

Show diffs side-by-side

added added

removed removed

Lines of Context:
166
166
    fprintf(fp, "<unknown>");
167
167
}
168
168
 
 
169
static void LogFilestoreMetaGetUserAgent(FILE *fp, Packet *p, File *ff) {
 
170
    HtpState *htp_state = (HtpState *)p->flow->alstate;
 
171
    if (htp_state != NULL) {
 
172
        htp_tx_t *tx = list_get(htp_state->connp->conn->transactions, ff->txid);
 
173
        if (tx != NULL) {
 
174
            table_t *headers;
 
175
            headers = tx->request_headers;
 
176
            htp_header_t *h = NULL;
 
177
 
 
178
            table_iterator_reset(headers);
 
179
            while (table_iterator_next(headers, (void **)&h) != NULL) {
 
180
                if (bstr_len(h->name) >= 10 &&
 
181
                        SCMemcmpLowercase((uint8_t *)"user-agent", (uint8_t *)bstr_ptr(h->name), bstr_len(h->name)) == 0) {
 
182
                    PrintRawUriFp(fp, (uint8_t *)bstr_ptr(h->value),
 
183
                        bstr_len(h->value));
 
184
                    return;
 
185
                }
 
186
            }
 
187
        }
 
188
    }
 
189
 
 
190
    fprintf(fp, "<unknown>");
 
191
}
 
192
 
169
193
static void LogFilestoreLogCreateMetaFile(Packet *p, File *ff, char *filename, int ipver) {
170
194
    char metafilename[PATH_MAX] = "";
171
195
    snprintf(metafilename, sizeof(metafilename), "%s.meta", filename);
215
239
        fprintf(fp, "HTTP REFERER:      ");
216
240
        LogFilestoreMetaGetReferer(fp, p, ff);
217
241
        fprintf(fp, "\n");
 
242
        fprintf(fp, "HTTP USER AGENT:   ");
 
243
        LogFilestoreMetaGetUserAgent(fp, p, ff);
 
244
        fprintf(fp, "\n");
218
245
        fprintf(fp, "FILENAME:          ");
219
246
        PrintRawUriFp(fp, ff->name, ff->name_len);
220
247
        fprintf(fp, "\n");
296
323
            int file_fd = -1;
297
324
 
298
325
            if (FileForceMagic() && ff->magic == NULL) {
299
 
                FilemagicLookup(ff);
 
326
                FilemagicGlobalLookup(ff);
300
327
            }
301
328
 
302
329
            SCLogDebug("ff %p", ff);
305
332
                continue;
306
333
            }
307
334
 
308
 
            if (ff->store != 1) {
309
 
                SCLogDebug("ff->store %d, so not 1", ff->store);
 
335
            if (!(ff->flags & FILE_STORE)) {
 
336
                SCLogDebug("ff FILE_STORE not set");
310
337
                continue;
311
338
            }
312
339
 
424
451
TmEcode LogFilestoreLogThreadInit(ThreadVars *t, void *initdata, void **data)
425
452
{
426
453
    LogFilestoreLogThread *aft = SCMalloc(sizeof(LogFilestoreLogThread));
427
 
    if (aft == NULL)
 
454
    if (unlikely(aft == NULL))
428
455
        return TM_ECODE_FAILED;
429
456
    memset(aft, 0, sizeof(LogFilestoreLogThread));
430
457
 
440
467
 
441
468
    struct stat stat_buf;
442
469
    if (stat(g_logfile_base_dir, &stat_buf) != 0) {
443
 
        SCLogError(SC_ERR_LOGDIR_CONFIG, "The file drop directory \"%s\" "
444
 
                "supplied doesn't exist. Shutting down the engine",
445
 
                g_logfile_base_dir);
446
 
        exit(EXIT_FAILURE);
 
470
        int ret;
 
471
        ret = mkdir(g_logfile_base_dir, S_IRWXU|S_IXGRP|S_IRGRP);
 
472
        if (ret != 0) {
 
473
            int err = errno;
 
474
            if (err != EEXIST) {
 
475
                SCLogError(SC_ERR_LOGDIR_CONFIG,
 
476
                        "Cannot create file drop directory %s: %s",
 
477
                        g_logfile_base_dir, strerror(err));
 
478
                exit(EXIT_FAILURE);
 
479
            }
 
480
        } else {
 
481
            SCLogInfo("Created file drop directory %s",
 
482
                    g_logfile_base_dir);
 
483
        }
 
484
 
447
485
    }
448
486
 
449
487
    *data = (void *)aft;
539
577
    }
540
578
 
541
579
    OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
542
 
    if (output_ctx == NULL)
 
580
    if (unlikely(output_ctx == NULL))
543
581
        return NULL;
544
582
 
545
583
    output_ctx->data = NULL;