Пример #1
0
void log_event(const char *format, ...)
{
	va_list args;
	int count1, count2;

	if (log.fd < 0) return;

/*
 * Handle possible recursion:
 * log_*() -> ... -> pexit() -> ... -> log_event()
 */
	if (in_logger) return;
	in_logger = 1;

	count1 = log_time();
	if (count1 > 0 &&
	    count1 + strlen(format) < LINE_BUFFER_SIZE - 500 - 1) {
		log.ptr += count1;

		va_start(args, format);
		count2 = (int)vsprintf(log.ptr, format, args);
		va_end(args);

		if (count2 > 0) {
			log.ptr += count2;
			*log.ptr++ = '\n';
		} else
			log.ptr -= count1;

		if (log_file_write(&log))
			log_file_flush(&pot);
	}

	in_logger = 0;
}
Пример #2
0
void log_event(const char *format, ...)
{
	va_list args;
	int count1, count2;

	if (options.flags & FLG_LOG_STDERR) {
		unsigned int time;

#ifndef HAVE_MPI
		if (options.fork)
#else
		if (options.fork || mpi_p > 1)
#endif
			fprintf(stderr, "%u ", options.node_min);

		time = pot.fd >= 0 ? status_get_time() : status_restored_time;

		fprintf(stderr, "%u:%02u:%02u:%02u ",
		        time / 86400, time % 86400 / 3600,
		        time % 3600 / 60, time % 60);

		va_start(args, format);
		vfprintf(stderr, format, args);
		va_end(args);
		fprintf(stderr, "\n");
		return;
	}

	if (log.fd < 0) return;

/*
 * Handle possible recursion:
 * log_*() -> ... -> pexit() -> ... -> log_event()
 */
	if (in_logger) return;
	in_logger = 1;

	count1 = log_time();
	if (count1 > 0 &&
	    count1 + strlen(format) < LINE_BUFFER_SIZE - 500 - 1) {
		log.ptr += count1;

		va_start(args, format);
		count2 = (int)vsprintf(log.ptr, format, args);
		va_end(args);

		if (count2 > 0) {
			log.ptr += count2;
			*log.ptr++ = '\n';
		} else
			log.ptr -= count1;

		if (log_file_write(&log))
			log_file_flush(&pot);
	}

	in_logger = 0;
}
Пример #3
0
static void log_file_fsync(struct log_file *f)
{
	if (f->fd < 0) return;

	log_file_flush(f);
#if HAVE_WINDOWS_H==0
	if (fsync(f->fd)) pexit("fsync");
#endif
}
Пример #4
0
static int log_file_write(struct log_file *f)
{
	if (f->ptr - f->buffer > f->size) {
		log_file_flush(f);
		return 1;
	}

	return 0;
}
Пример #5
0
static void log_file_fsync(struct log_file *f)
{
	if (f->fd < 0) return;

	log_file_flush(f);
#ifndef __CYGWIN32__
	if (fsync(f->fd)) pexit("fsync");
#endif
}
Пример #6
0
static void log_file_fsync(struct log_file *f)
{
	if (f->fd < 0) return;

	log_file_flush(f);
#if !defined(__CYGWIN32__) && !defined(__MINGW32__) && !defined(_MSC_VER)
	if (fsync(f->fd)) pexit("fsync");
#endif
}
Пример #7
0
void log_guess(char *login, char *ciphertext, char *plaintext)
{
	int count1, count2;

	printf("%-16s (%s)\n", plaintext, login);

	in_logger = 1;

	if (pot.fd >= 0 && ciphertext &&
	    strlen(ciphertext) + strlen(plaintext) <= LINE_BUFFER_SIZE - 3) {
		count1 = (int)sprintf(pot.ptr,
			"%s:%s\n", ciphertext, plaintext);
		if (count1 > 0) pot.ptr += count1;
	}

	if (log.fd >= 0 &&
	    strlen(login) < LINE_BUFFER_SIZE - 64) {
		count1 = log_time();
		if (count1 > 0) {
			log.ptr += count1;
			count2 = (int)sprintf(log.ptr,
				"+ Cracked %s\n", login);
			if (count2 > 0)
				log.ptr += count2;
			else
				log.ptr -= count1;
		}
	}

/* Try to keep the two files in sync */
	if (log_file_write(&pot))
		log_file_flush(&log);
	else
	if (log_file_write(&log))
		log_file_flush(&pot);

	in_logger = 0;

	if (cfg_beep)
		write_loop(fileno(stderr), "\007", 1);
}
Пример #8
0
void log_flush(void)
{
	in_logger = 1;

	if (options.fork)
		log_file_flush(&log);
	else
		log_file_fsync(&log);
	log_file_fsync(&pot);

	in_logger = 0;
}
Пример #9
0
static void log_file_done(struct log_file *f, int do_sync)
{
	if (f->fd < 0) return;

	if (do_sync)
		log_file_fsync(f);
	else
		log_file_flush(f);
	if (close(f->fd)) pexit("close");
	f->fd = -1;

	MEM_FREE(f->buffer);
}
Пример #10
0
void log_guess(char *login, char *uid, char *ciphertext, char *rep_plain,
               char *store_plain, char field_sep, int index)
{
	int count1, count2;
	int len;
	char spacer[] = "                ";
	char *secret = "";
	char uid_sep[2] = { 0 };
	char *uid_out = "";

/* This is because printf("%-16s") does not line up multibyte UTF-8.
   We need to count characters, not octets. */
	if (pers_opts.target_enc == UTF_8 || pers_opts.report_utf8)
		len = strlen8((UTF8*)rep_plain);
	else
		len = strlen(rep_plain);

	if (options.show_uid_on_crack && uid && *uid) {
		uid_sep[0] = field_sep;
		uid_out = uid;
	}

	if (options.verbosity > 1) {
		if (options.secure) {
			secret = components(rep_plain, len);
			printf("%-16s (%s%s%s)\n",
			       secret, login, uid_sep, uid_out);
		} else {
			spacer[len > 16 ? 0 : 16 - len] = 0;

			printf("%s%s (%s%s%s)\n",
			       rep_plain, spacer, login, uid_sep, uid_out);

			if (options.fork)
				fflush(stdout);
		}
	}

	in_logger = 1;

	if (pot.fd >= 0 && ciphertext ) {
#ifndef DYNAMIC_DISABLED
		if (!strncmp(ciphertext, "$dynamic_", 9))
			ciphertext = dynamic_FIX_SALT_TO_HEX(ciphertext);
#endif
		if (strlen(ciphertext) + strlen(store_plain) <= LINE_BUFFER_SIZE - 3) {
			if (options.secure) {
				secret = components(store_plain, len);
				count1 = (int)sprintf(pot.ptr,
				                      "%s%c%s\n",
				                      ciphertext,
				                      field_sep,
				                      secret);
			} else
				count1 = (int)sprintf(pot.ptr,
				                      "%s%c%s\n", ciphertext,
				                      field_sep, store_plain);
			if (count1 > 0) pot.ptr += count1;
		}
	}

	if (log.fd >= 0 &&
	    strlen(login) < LINE_BUFFER_SIZE - 64) {
		count1 = log_time();
		if (count1 > 0) {
			log.ptr += count1;
			count2 = (int)sprintf(log.ptr, "+ Cracked %s%s%s", login, uid_sep, uid_out);

			if (options.secure) {
				secret = components(rep_plain, len);
				count2 += (int)sprintf(log.ptr + count2,
				                       ": %s", secret);
			} else
			if (cfg_log_passwords)
				count2 += (int)sprintf(log.ptr + count2,
				                       ": %s", rep_plain);
			if (cfg_showcand)
				count2 += (int)sprintf(log.ptr + count2,
				                       " as candidate #"LLu"",
				                       ((unsigned long long)
				                       status.cands.hi << 32) +
				                       status.cands.lo + index + 1);
			count2 += (int)sprintf(log.ptr + count2, "\n");

			if (count2 > 0)
				log.ptr += count2;
			else
				log.ptr -= count1;
		}
	}

/* Try to keep the two files in sync */
	if (log_file_write(&pot))
		log_file_flush(&log);
	else
	if (log_file_write(&log))
		log_file_flush(&pot);

	in_logger = 0;

	if (cfg_beep)
		write_loop(fileno(stderr), "\007", 1);
}
Пример #11
0
void log_guess(char *login, char *ciphertext, char *rep_plain, char *store_plain, char field_sep)
{
	int count1, count2;
	int len;
	char spacer[] = "                ";

	// This is because printf("%-16s") does not line up multibyte UTF-8.
	// We need to count characters, not octets.
	if (options.utf8 || options.report_utf8)
		len = strlen8((UTF8*)rep_plain);
	else
		len = strlen(rep_plain);
	spacer[len > 16 ? 0 : 16 - len] = 0;

#ifdef HAVE_MPI
	// All but node 0 has stdout closed so we output to stderr
	if (mpi_p > 1)
		fprintf(stderr, "%s%s (%s)\n", rep_plain, spacer, login);
	else
#endif
		printf("%s%s (%s)\n", rep_plain, spacer, login);

	in_logger = 1;

	if (pot.fd >= 0 && ciphertext ) {
		if (!strncmp(ciphertext, "$dynamic_", 9))
			ciphertext = dynamic_FIX_SALT_TO_HEX(ciphertext);
		if (strlen(ciphertext) + strlen(store_plain) <= LINE_BUFFER_SIZE - 3) {
			count1 = (int)sprintf(pot.ptr,
				"%s%c%s\n", ciphertext, field_sep, store_plain);
			if (count1 > 0) pot.ptr += count1;
		}
	}

	if (log.fd >= 0 &&
	    strlen(login) < LINE_BUFFER_SIZE - 64) {
		count1 = log_time();
		if (count1 > 0) {
			log.ptr += count1;
			if (cfg_log_passwords)
				count2 = (int)sprintf(log.ptr,
				    "+ Cracked %s: %s\n", login, rep_plain);
			else
				count2 = (int)sprintf(log.ptr,
				    "+ Cracked %s\n", login);
			if (count2 > 0)
				log.ptr += count2;
			else
				log.ptr -= count1;
		}
	}

/* Try to keep the two files in sync */
	if (log_file_write(&pot))
		log_file_flush(&log);
	else
	if (log_file_write(&log))
		log_file_flush(&pot);

	in_logger = 0;

	if (cfg_beep)
		write_loop(fileno(stderr), "\007", 1);
}