Esempio n. 1
0
static int log_time(void)
{
	int count1, count2;
	unsigned int time;

	count1 = 0;
#ifndef HAVE_MPI
	if (options.fork) {
#else
	if (options.fork || mpi_p > 1) {
#endif
		count1 = (int)sprintf(log.ptr, "%u ", options.node_min);
		if (count1 < 0)
			return count1;
	}

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

	count2 = (int)sprintf(log.ptr + count1, "%u:%02u:%02u:%02u ",
	    time / 86400, time % 86400 / 3600,
	    time % 3600 / 60, time % 60);
	if (count2 < 0)
		return count2;

	return count1 + count2;
}

void log_init(char *log_name, char *pot_name, char *session)
{
	in_logger = 1;

	if (log_name && log.fd < 0) {
		if (session)
			log_name = path_session(session, LOG_SUFFIX);

		log_file_init(&log, log_name, LOG_BUFFER_SIZE);
	}

	if (pot_name && pot.fd < 0) {
		log_file_init(&pot, pot_name, POT_BUFFER_SIZE);

		cfg_beep = cfg_get_bool(SECTION_OPTIONS, NULL, "Beep", 0);
	}

	cfg_log_passwords = cfg_get_bool(SECTION_OPTIONS, NULL,
	                                 "LogCrackedPasswords", 0);
	cfg_showcand = cfg_get_bool(SECTION_OPTIONS, NULL,
	                            "StatusShowCandidates", 0);

	in_logger = 0;
}
Esempio n. 2
0
int main(int argc, char **argv)
{
	int listenfd,port,clientlen;
	int *connfdp;
	pthread_t tid;
	struct sockaddr_in clientaddr;
	clientlen = sizeof(clientaddr);
	if(argc != 2)
	{
		fprintf(stderr, "usage: %s <port>\n", argv[0]);
		exit(1);
	}
	//init
	signal(SIGPIPE, SIG_IGN);
	sem_init(&mutex, 0, 1);
	num_blocked_address = read_blocked_address();
	logfd = log_file_init();
	//listen
	port = atoi(argv[1]);
	listenfd = open_listenfd(port);
	while(1)
	{
		connfdp = malloc(sizeof(int));
		*connfdp = accept(listenfd, (SA*)&clientaddr, &clientlen);
		pthread_create(&tid, NULL, thread, connfdp);
	}
}
Esempio n. 3
0
void log_init(char *log_name, char *pot_name, char *session)
{
	in_logger = 1;

	if (log_name && log.fd < 0) {
		if (session)
			log_name = path_session(session, LOG_SUFFIX);

		log_file_init(&log, log_name, LOG_BUFFER_SIZE);
	}

	if (pot_name && pot.fd < 0) {
		log_file_init(&pot, pot_name, POT_BUFFER_SIZE);

		cfg_beep = cfg_get_bool(SECTION_OPTIONS, NULL, "Beep", 0);
	}

	in_logger = 0;
}
void log_write(logd_file * plf, char * p, int len)
{
	int ret;
	int cur_hr, pre_hr;
        time_t cur_time;
        struct tm loctime;
	char temp_syslog_buf[8096];

        if(plf->replicate_syslog) {
                strncpy(temp_syslog_buf, p, len);
                temp_syslog_buf[len] = '\0';
                syslog(LOG_NOTICE, "%s", temp_syslog_buf);
        }

	//in case of TYPE_SYSLOG, we don't do any thing to our log files
	if(plf->type == TYPE_SYSLOG)
		return;
	// adjust the fillin_accesslog_size,
	// So we will write into accesslog next time.
	while(len) {
	    ret = fwrite(p, 1, len, plf->fp);
	    if (ret <= 0) {
		    log_write_report_err(ret, plf);
		    return;

	    }
		p += ret;
		len -= ret;
		plf->cur_filesize += ret;
	}
	//fflush(plf->fp);

	cur_time = time(NULL);
	localtime_r(&cur_time, &loctime);
	cur_hr = loctime.tm_hour;
	pre_hr = atoi((char*)plf->hour);
    /* Check whether time-interval is hit, if so, close & re-init
     * else, chck if size is hit.
     * If neither, return.
     */
	if ((plf->max_filesize)
		&& (plf->cur_filesize > plf->max_filesize)) {
	    goto reinit;
	}else if(plf->on_the_hour){//on the hour is set
	    if (cur_hr != pre_hr){
		goto reinit;
	    }
	}

	return;

reinit:
	    log_file_exit(plf);
	    log_file_init(plf);
	}
Esempio n. 5
0
int log_init(void)
{
	log_file_set_dir("./log");

	do
	{
		log_file_sys = log_file_init(SYSLOG_FILENAME, "a+");
		if( NULL == log_file_sys ) break;

		log_file_err = log_file_init(SYSERR_FILENAME, "a+");
		if( NULL == log_file_err ) break;

		log_file_pt = log_file_init(PTS_FILENAME, "w");
		if( NULL == log_file_pt ) break;

		return true;
	}
	while( false );

	return false;
}