1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-11-30 03:48:17 +00:00

Merge pull request #570 from magnumripper/master

Fix file locking (again).
This commit is contained in:
Jens Steube 2016-11-05 23:26:59 +01:00 committed by GitHub
commit 2d743706cb
8 changed files with 57 additions and 1 deletions

View File

@ -8,6 +8,7 @@
#include "memory.h" #include "memory.h"
#include "event.h" #include "event.h"
#include "debugfile.h" #include "debugfile.h"
#include "locking.h"
static void debugfile_format_plain (hashcat_ctx_t *hashcat_ctx, const u8 *plain_ptr, const u32 plain_len) static void debugfile_format_plain (hashcat_ctx_t *hashcat_ctx, const u8 *plain_ptr, const u32 plain_len)
{ {
@ -112,6 +113,13 @@ int debugfile_init (hashcat_ctx_t *hashcat_ctx)
return -1; return -1;
} }
if (lock_file (debugfile_ctx->fp) == -1)
{
event_log_error (hashcat_ctx, "%s: %s", debugfile_ctx->filename, strerror (errno));
return -1;
}
} }
else else
{ {

View File

@ -8,6 +8,7 @@
#include "memory.h" #include "memory.h"
#include "event.h" #include "event.h"
#include "dictstat.h" #include "dictstat.h"
#include "locking.h"
int sort_by_dictstat (const void *s1, const void *s2) int sort_by_dictstat (const void *s1, const void *s2)
{ {
@ -125,6 +126,13 @@ int dictstat_write (hashcat_ctx_t *hashcat_ctx)
return -1; return -1;
} }
if (lock_file (fp) == -1)
{
event_log_error (hashcat_ctx, "%s: %s", dictstat_ctx->filename, strerror (errno));
return -1;
}
fwrite (dictstat_ctx->base, sizeof (dictstat_t), dictstat_ctx->cnt, fp); fwrite (dictstat_ctx->base, sizeof (dictstat_t), dictstat_ctx->cnt, fp);
fclose (fp); fclose (fp);

View File

@ -24,6 +24,7 @@
#include "shared.h" #include "shared.h"
#include "thread.h" #include "thread.h"
#include "timer.h" #include "timer.h"
#include "locking.h"
int sort_by_digest_p0p1 (const void *v1, const void *v2, void *v3) int sort_by_digest_p0p1 (const void *v1, const void *v2, void *v3)
{ {
@ -144,6 +145,13 @@ int save_hash (hashcat_ctx_t *hashcat_ctx)
return -1; return -1;
} }
if (lock_file (fp) == -1)
{
event_log_error (hashcat_ctx, "%s: %s", new_hashfile, strerror (errno));
return -1;
}
for (u32 salt_pos = 0; salt_pos < hashes->salts_cnt; salt_pos++) for (u32 salt_pos = 0; salt_pos < hashes->salts_cnt; salt_pos++)
{ {
if (hashes->salts_shown[salt_pos] == 1) continue; if (hashes->salts_shown[salt_pos] == 1) continue;

View File

@ -18,7 +18,11 @@ int lock_file (FILE *fp)
lock.l_type = F_WRLCK; lock.l_type = F_WRLCK;
if (fcntl (fileno (fp), F_SETLKW, &lock)) return -1; /* Needs this loop because a signal may interrupt a wait for lock */
while (fcntl (fileno (fp), F_SETLKW, &lock))
{
if (errno != EINTR) return -1;
}
return 0; return 0;
} }

View File

@ -8,6 +8,7 @@
#include "memory.h" #include "memory.h"
#include "event.h" #include "event.h"
#include "logfile.h" #include "logfile.h"
#include "locking.h"
static int logfile_generate_id (void) static int logfile_generate_id (void)
{ {
@ -50,6 +51,8 @@ void logfile_append (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...)
FILE *fp = fopen (logfile_ctx->logfile, "ab"); FILE *fp = fopen (logfile_ctx->logfile, "ab");
lock_file (fp);
va_list ap; va_list ap;
va_start (ap, fmt); va_start (ap, fmt);

View File

@ -9,6 +9,7 @@
#include "event.h" #include "event.h"
#include "shared.h" #include "shared.h"
#include "loopback.h" #include "loopback.h"
#include "locking.h"
static void loopback_format_plain (hashcat_ctx_t *hashcat_ctx, const u8 *plain_ptr, const unsigned int plain_len) static void loopback_format_plain (hashcat_ctx_t *hashcat_ctx, const u8 *plain_ptr, const unsigned int plain_len)
{ {
@ -111,6 +112,13 @@ int loopback_write_open (hashcat_ctx_t *hashcat_ctx)
return -1; return -1;
} }
if (lock_file (loopback_ctx->fp) == -1)
{
event_log_error (hashcat_ctx, "%s: %s", loopback_ctx->filename, strerror (errno));
return -1;
}
loopback_ctx->unused = true; loopback_ctx->unused = true;
return 0; return 0;

View File

@ -16,6 +16,7 @@
#include "opencl.h" #include "opencl.h"
#include "shared.h" #include "shared.h"
#include "outfile.h" #include "outfile.h"
#include "locking.h"
int build_plain (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, plain_t *plain, u32 *plain_buf, int *out_len) int build_plain (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, plain_t *plain, u32 *plain_buf, int *out_len)
{ {
@ -312,6 +313,13 @@ int outfile_write_open (hashcat_ctx_t *hashcat_ctx)
return -1; return -1;
} }
if (lock_file (outfile_ctx->fp) == -1)
{
event_log_error (hashcat_ctx, "%s: %s", outfile_ctx->filename, strerror (errno));
return -1;
}
return 0; return 0;
} }

View File

@ -12,6 +12,7 @@
#include "filehandling.h" #include "filehandling.h"
#include "outfile.h" #include "outfile.h"
#include "potfile.h" #include "potfile.h"
#include "locking.h"
#if defined (_WIN) #if defined (_WIN)
#define __WINDOWS__ #define __WINDOWS__
@ -318,7 +319,15 @@ void potfile_write_append (hashcat_ctx_t *hashcat_ctx, const char *out_buf, u8 *
tmp_buf[tmp_len] = 0; tmp_buf[tmp_len] = 0;
if (lock_file (potfile_ctx->fp) == -1)
{
event_log_error (hashcat_ctx, "%s: %s", potfile_ctx->filename, strerror (errno));
}
fprintf (potfile_ctx->fp, "%s" EOL, tmp_buf); fprintf (potfile_ctx->fp, "%s" EOL, tmp_buf);
fflush(potfile_ctx->fp);
unlock_file (potfile_ctx->fp);
} }
int potfile_remove_parse (hashcat_ctx_t *hashcat_ctx) int potfile_remove_parse (hashcat_ctx_t *hashcat_ctx)