FreeBSD/contrib/openbsm/libauditd/auditd_lib.c
/*
 * Parses the "dir" entry in audit_control(5) into an ordered list.  Also, will
 * set the minfree and host values if not already set.  Arguments include
 * function pointers to audit_warn functions for soft and hard limits. Returns:
 *	ADE_NOERR	on success,
 *	ADE_PARSE	error parsing audit_control(5),
 *	ADE_AUDITON	error getting/setting auditon(2) value,
 *	ADE_NOMEM	error allocating memory,
 *	ADE_SOFTLIM	if all the directories are over the soft limit,
 *	ADE_HARDLIM	if all the directories are over the hard limit,
 */
Parses the "dir" entry in audit_control(5) into an ordered list.  Also, will
set the minfree and host values if not already set.  Arguments include
function pointers to audit_warn functions for soft and hard limits. Returns:
ADE_NOERR       on success,
ADE_PARSE       error parsing audit_control(5),
ADE_AUDITON     error getting/setting auditon(2) value,
ADE_NOMEM       error allocating memory,
ADE_SOFTLIM     if all the directories are over the soft limit,
ADE_HARDLIM     if all the directories are over the hard limit.
Parses the " dir " entry in audit_control ( 5 ) into an ordered list . Also will set the minfree and host values if not already set . Arguments include function pointers to audit_warn functions for soft and hard limits . Returns : ADE_NOERR on success ADE_PARSE error parsing audit_control ( 5 ) ADE_AUDITON error getting / setting auditon ( 2 ) value ADE_NOMEM error allocating memory ADE_SOFTLIM if all the directories are over the soft limit ADE_HARDLIM if all the directories are over the hard limit .
int
auditd_read_dirs(int (*warn_soft)(char *), int (*warn_hard)(char *))
{
	char cur_dir[MAXNAMLEN];
	struct dir_ent *dirent;
	struct statfs sfs;
	int err;
	char soft, hard;
	int tcnt = 0;
	int scnt = 0;
	int hcnt = 0;
	if (auditd_minval == -1 && (err = auditd_set_minfree()) != 0)
		return (err);
	if (auditd_hostlen == -1)
		auditd_set_host();
	free_dir_q();
	endac();
	while (getacdir(cur_dir, MAXNAMLEN) >= 0) {
		if (statfs(cur_dir, &sfs) < 0)
			continue;  
		soft = (sfs.f_bfree < (sfs.f_blocks * auditd_minval / 100 )) ?
		    1 : 0;
		hard = (sfs.f_bfree < AUDIT_HARD_LIMIT_FREE_BLOCKS) ? 1 : 0;
		if (soft) {
			if (warn_soft)
				(*warn_soft)(cur_dir);
			scnt++;
		}
		if (hard) {
			if (warn_hard)
				(*warn_hard)(cur_dir);
			hcnt++;
		}
		dirent = (struct dir_ent *) malloc(sizeof(struct dir_ent));
		if (dirent == NULL)
			return (ADE_NOMEM);
		dirent->softlim = soft;
		dirent->hardlim = hard;
		dirent->dirname = (char *) malloc(MAXNAMLEN);
		if (dirent->dirname == NULL) {
			free(dirent);
			return (ADE_NOMEM);
		}
		strlcpy(dirent->dirname, cur_dir, MAXNAMLEN);
		insert_orderly(dirent);
		tcnt++;
	}
	if (hcnt == tcnt)
		return (ADE_HARDLIM);
	if (scnt == tcnt)
		return (ADE_SOFTLIM);
	return (0);
}
int auditd_read_dirs ( int ( * warn_soft ) ( char * ) , int ( * warn_hard ) ( char * ) ) { char cur_dir [ MAXNAMLEN ] ; struct dir_ent * dirent ; struct statfs sfs ; int err ; char soft , hard ; int tcnt = 0 ; int scnt = 0 ; int hcnt = 0 ; if ( auditd_minval == -1 && ( err = auditd_set_minfree ( ) ) != 0 ) return ( err ) ; if ( auditd_hostlen == -1 ) auditd_set_host ( ) ; free_dir_q ( ) ; endac ( ) ; while ( getacdir ( cur_dir , MAXNAMLEN ) >= 0 ) { if ( statfs ( cur_dir , & sfs ) < 0 ) continue ; soft = ( sfs . f_bfree < ( sfs . f_blocks * auditd_minval / 100 ) ) ? 1 : 0 ; hard = ( sfs . f_bfree < AUDIT_HARD_LIMIT_FREE_BLOCKS ) ? 1 : 0 ; if ( soft ) { if ( warn_soft ) ( * warn_soft ) ( cur_dir ) ; scnt ++ ; } if ( hard ) { if ( warn_hard ) ( * warn_hard ) ( cur_dir ) ; hcnt ++ ; } dirent = ( struct dir_ent * ) malloc ( sizeof ( struct dir_ent ) ) ; if ( dirent == NULL ) return ( ADE_NOMEM ) ; dirent -> softlim = soft ; dirent -> hardlim = hard ; dirent -> dirname = ( char * ) malloc ( MAXNAMLEN ) ; if ( dirent -> dirname == NULL ) { free ( dirent ) ; return ( ADE_NOMEM ) ; } strlcpy ( dirent -> dirname , cur_dir , MAXNAMLEN ) ; insert_orderly ( dirent ) ; tcnt ++ ; } if ( hcnt == tcnt ) return ( ADE_HARDLIM ) ; if ( scnt == tcnt ) return ( ADE_SOFTLIM ) ; return ( 0 ) ; }
Parses the "dir" entry in audit_control(5) into an ordered list.
Parses the " dir " entry in audit_control ( 5 ) into an ordered list .
/*
	 * Init directory q.  Force a re-read of the file the next time.
	 */ /*
	 * Read the list of directories into an ordered linked list
	 * admin's preference, then those over soft limit and, finally,
	 * those over the hard limit.
	 *
	 * XXX We should use the reentrant interfaces once they are
	 * available.
	 */ /* XXX should warn */