Exemple #1
0
/**********************************
*func name:
*function:
*parameters:
*call:
*called:
*return:
*/
void
show_version_info(void)
{
    char *version;
    printf("eAudit System Version Info:\n");
    printf("Copyright:%s",get_copyright_info());
    printf("Libpcap Lib version:%s\n",get_pcap_version());

    version = get_sys_version();
    printf("system version:%s\n",version);
    FREE(version);
}
Exemple #2
0
/* returns 0 on success, -1 on error */
int init_lock_ops(void)
{
#ifdef USE_FUTEX
	int os_ver;
	
	os_ver=get_sys_version(0, 0, 0);
	if (os_ver < 0x020546 ){ /* if ver < 2.5.70 */
		LOG(L_CRIT, "ERROR: init_lock_ops: old kernel:"
				" compiled with FUTEX support which is not present in the"
				" running kernel (try  2.6+)\n");
		return -1;
	}
#endif
	return 0;
}
Exemple #3
0
/*!
 * \brief Choose a IO poll method
 * \return the choosen poll method
 */
enum poll_types choose_poll_method(void)
{
	enum poll_types poll_method;
	unsigned int os_ver;

	os_ver=get_sys_version(0,0,0);
	(void)os_ver;
	poll_method=0;
#ifdef HAVE_EPOLL
	if (os_ver>=0x020542) /* if ver >= 2.5.66 */
		poll_method=POLL_EPOLL_LT; /* or POLL_EPOLL_ET */

#endif
#ifdef HAVE_KQUEUE
	if (poll_method==0)
		/* only in FreeBSD 4.1, NETBSD 2.0, OpenBSD 2.9, Darwin */
	#ifdef __OS_freebsd
		if (os_ver>=0x0401) /* if ver >= 4.1 */
	#elif defined (__OS_netbsd)
		if (os_ver>=0x020000) /* if ver >= 2.0 */
	#elif defined (__OS_openbsd)
		if (os_ver>=0x0209) /* if ver >= 2.9 (?) */
	#endif /* assume that the rest support kqueue ifdef HAVE_KQUEUE */
			poll_method=POLL_KQUEUE;
#endif
#ifdef HAVE_DEVPOLL
	#ifdef __OS_solaris
	if (poll_method==0)
		/* only in Solaris >= 7.0 (?) */
		if (os_ver>=0x0507) /* if ver >=SunOS 5.7 */
			poll_method=POLL_DEVPOLL;
	#endif
#endif
#ifdef  HAVE_SIGIO_RT
		if (poll_method==0)
			if (os_ver>=0x020200) /* if ver >= 2.2.0 */
				poll_method=POLL_SIGIO_RT;
#endif
		if (poll_method==0) poll_method=POLL_POLL;
	return poll_method;
}
Exemple #4
0
/*!
 * \brief Check preferred OS poll method
 * \param poll_method supported IO poll methods
 * \return 0 on success, and an error message on error
 */
char* check_poll_method(enum poll_types poll_method)
{
	char* ret;
	unsigned int os_ver;

	ret=0;
	os_ver=get_sys_version(0,0,0);
	(void)os_ver;
	switch(poll_method){
		case POLL_NONE:
			break;
		case POLL_POLL:
			/* always supported */
			break;
		case POLL_SELECT:
			/* should be always supported */
#ifndef HAVE_SELECT
			ret="select not supported, try re-compiling with -DHAVE_SELECT";
#endif
			break;
		case POLL_EPOLL_LT:
		case POLL_EPOLL_ET:
#ifndef HAVE_EPOLL
			ret="epoll not supported, try re-compiling with -DHAVE_EPOLL";
#else
			/* only on 2.6 + */
			if (os_ver<0x020542) /* if ver < 2.5.66 */
			 	ret="epoll not supported on kernels < 2.6";
#endif
			break;
		case POLL_SIGIO_RT:
#ifndef HAVE_SIGIO_RT
			ret="sigio_rt not supported, try re-compiling with"
				" -DHAVE_SIGIO_RT";
#else
			/* only on 2.2 +  ?? */
			if (os_ver<0x020200) /* if ver < 2.2.0 */
			 	ret="epoll not supported on kernels < 2.2 (?)";
#endif
			break;
		case POLL_KQUEUE:
#ifndef HAVE_KQUEUE
			ret="kqueue not supported, try re-compiling with -DHAVE_KQUEUE";
#else
		/* only in FreeBSD 4.1, NETBSD 2.0, OpenBSD 2.9, Darwin */
	#ifdef __OS_freebsd
			if (os_ver<0x0401) /* if ver < 4.1 */
				ret="kqueue not supported on FreeBSD < 4.1";
	#elif defined (__OS_netbsd)
			if (os_ver<0x020000) /* if ver < 2.0 */
				ret="kqueue not supported on NetBSD < 2.0";
	#elif defined (__OS_openbsd)
			if (os_ver<0x0209) /* if ver < 2.9 ? */
				ret="kqueue not supported on OpenBSD < 2.9 (?)";
	#endif /* assume that the rest support kqueue ifdef HAVE_KQUEUE */
#endif
			break;
		case POLL_DEVPOLL:
#ifndef HAVE_DEVPOLL
			ret="/dev/poll not supported, try re-compiling with"
					" -DHAVE_DEVPOLL";
#else
	/* only in Solaris >= 7.0 (?) */
	#ifdef __OS_solaris
		if (os_ver<0x0507) /* ver < 5.7 */
			ret="/dev/poll not supported on Solaris < 7.0 (SunOS 5.7)";
	#endif
#endif
			break;

		default:
			ret="unknown not supported method";
	}
	return ret;
}
Exemple #5
0
/* initializes the static vars/arrays
 * params:      h - pointer to the io_wait_h that will be initialized
 *         max_fd - maximum allowed fd number
 *         poll_m - poll method (0 for automatic best fit)
 */
int init_io_wait(io_wait_h* h, int max_fd, enum poll_types poll_method)
{
	char * poll_err;
	
	if (_os_ver==0) _os_ver=get_sys_version(0,0,0);
	memset(h, 0, sizeof(*h));
	h->max_fd_no=max_fd;
#ifdef HAVE_EPOLL
	h->epfd=-1;
#endif
#ifdef HAVE_KQUEUE
	h->kq_fd=-1;
#endif
#ifdef HAVE_DEVPOLL
	h->dpoll_fd=-1;
#endif
	poll_err=check_poll_method(poll_method);
	
	/* set an appropiate poll method */
	if (poll_err || (poll_method==0)){
		poll_method=choose_poll_method();
		if (poll_err){
			LOG(L_ERR, "ERROR: init_io_wait: %s, using %s instead\n",
					poll_err, poll_method_str[poll_method]);
		}else{
			LOG(L_INFO, "init_io_wait: using %s as the io watch method"
					" (auto detected)\n", poll_method_str[poll_method]);
		}
	}
	
	h->poll_method=poll_method;
	
	/* common stuff, everybody has fd_hash */
	h->fd_hash=local_malloc(sizeof(*(h->fd_hash))*h->max_fd_no);
	if (h->fd_hash==0){
		LOG(L_CRIT, "ERROR: init_io_wait: could not alloc"
					" fd hashtable (%ld bytes)\n",
					(long)sizeof(*(h->fd_hash))*h->max_fd_no );
		goto error;
	}
	memset((void*)h->fd_hash, 0, sizeof(*(h->fd_hash))*h->max_fd_no);
	
	switch(poll_method){
		case POLL_POLL:
#ifdef HAVE_SELECT
		case POLL_SELECT:
#endif
#ifdef HAVE_SIGIO_RT
		case POLL_SIGIO_RT:
#endif
#ifdef HAVE_DEVPOLL
		case POLL_DEVPOLL:
#endif
			h->fd_array=local_malloc(sizeof(*(h->fd_array))*h->max_fd_no);
			if (h->fd_array==0){
				LOG(L_CRIT, "ERROR: init_io_wait: could not"
							" alloc fd array (%ld bytes)\n",
							(long)sizeof(*(h->fd_hash))*h->max_fd_no);
				goto error;
			}
			memset((void*)h->fd_array, 0, sizeof(*(h->fd_array))*h->max_fd_no);
#ifdef HAVE_SIGIO_RT
			if ((poll_method==POLL_SIGIO_RT) && (init_sigio(h, 0)<0)){
				LOG(L_CRIT, "ERROR: init_io_wait: sigio init failed\n");
				goto error;
			}
#endif
#ifdef HAVE_DEVPOLL
			if ((poll_method==POLL_DEVPOLL) && (init_devpoll(h)<0)){
				LOG(L_CRIT, "ERROR: init_io_wait: /dev/poll init failed\n");
				goto error;
			}
#endif
#ifdef HAVE_SELECT
			if ((poll_method==POLL_SELECT) && (init_select(h)<0)){
				LOG(L_CRIT, "ERROR: init_io_wait: select init failed\n");
				goto error;
			}
#endif
			
			break;
#ifdef HAVE_EPOLL
		case POLL_EPOLL_LT:
		case POLL_EPOLL_ET:
			h->ep_array=local_malloc(sizeof(*(h->ep_array))*h->max_fd_no);
			if (h->ep_array==0){
				LOG(L_CRIT, "ERROR: init_io_wait: could not alloc"
							" epoll array\n");
				goto error;
			}
			memset((void*)h->ep_array, 0, sizeof(*(h->ep_array))*h->max_fd_no);
			if (init_epoll(h)<0){
				LOG(L_CRIT, "ERROR: init_io_wait: epoll init failed\n");
				goto error;
			}
			break;
#endif
#ifdef HAVE_KQUEUE
		case POLL_KQUEUE:
			h->kq_array=local_malloc(sizeof(*(h->kq_array))*h->max_fd_no);
			if (h->kq_array==0){
				LOG(L_CRIT, "ERROR: init_io_wait: could not alloc"
							" kqueue event array\n");
				goto error;
			}
			h->kq_changes_size=KQ_CHANGES_ARRAY_SIZE;
			h->kq_changes=local_malloc(sizeof(*(h->kq_changes))*
										h->kq_changes_size);
			if (h->kq_changes==0){
				LOG(L_CRIT, "ERROR: init_io_wait: could not alloc"
							" kqueue changes array\n");
				goto error;
			}
			h->kq_nchanges=0;
			memset((void*)h->kq_array, 0, sizeof(*(h->kq_array))*h->max_fd_no);
			memset((void*)h->kq_changes, 0,
						sizeof(*(h->kq_changes))* h->kq_changes_size);
			if (init_kqueue(h)<0){
				LOG(L_CRIT, "ERROR: init_io_wait: kqueue init failed\n");
				goto error;
			}
			break;
#endif
		default:
			LOG(L_CRIT, "BUG: init_io_wait: unknown/unsupported poll"
						" method %s (%d)\n",
						poll_method_str[poll_method], poll_method);
			goto error;
	}
	return 0;
error:
	return -1;
}