FreeBSD/contrib/openbsm/libauditd/auditd_lib.c
/*
 * Create the new audit trail file, swap with existing audit file.  Arguments
 * include timestamp for the filename, a pointer to a string for returning the
 * new file name, GID for trail file, and audit_warn function pointer for
 * 'getacdir()' errors.  Returns:
 *	ADE_NOERR	on success,
 *	ADE_STRERR	if the file name string could not be created,
 *	ADE_SWAPERR	if the audit trail file could not be swapped,
 *	ADE_ACTL	if the auditctl(2) call failed but file swap still
 *			successful.
 *	ADE_ACTLERR	if the auditctl(2) call failed and file swap failed.
 *	ADE_SYMLINK	if symlink(2) failed updating the current link.
 */
Create the new audit trail file, swap with existing audit file.  Arguments
include timestamp for the filename, a pointer to a string for returning the
new file name, GID for trail file, and audit_warn function pointer for
'getacdir()' errors.  Returns:
ADE_NOERR       on success,
ADE_STRERR      if the file name string could not be created,
ADE_SWAPERR     if the audit trail file could not be swapped,
ADE_ACTL        if the auditctl(2) call failed but file swap still
successful.
ADE_ACTLERR     if the auditctl(2) call failed and file swap failed.
ADE_SYMLINK     if symlink(2) failed updating the current link.
Create the new audit trail file swap with existing audit file . Arguments include timestamp for the filename a pointer to a string for returning the new file name GID for trail file and audit_warn function pointer for ' getacdir () ' errors . Returns : ADE_NOERR on success ADE_STRERR if the file name string could not be created ADE_SWAPERR if the audit trail file could not be swapped ADE_ACTL if the auditctl ( 2 ) call failed but file swap still successful . ADE_ACTLERR if the auditctl ( 2 ) call failed and file swap failed . ADE_SYMLINK if symlink ( 2 ) failed updating the current link .
int
auditd_swap_trail(char *TS, char **newfile, gid_t gid,
    int (*warn_getacdir)(char *))
{
	char timestr[FILENAME_LEN + 1];
	char *fn;
	struct dir_ent *dirent;
	int saverrno = 0;
	if (strlen(TS) != TIMESTAMP_LEN ||
	    snprintf(timestr, sizeof(timestr), "%s.%s", TS,
	    NOT_TERMINATED) < 0) {
		errno = EINVAL;
		return (ADE_STRERR);
	}
	TAILQ_FOREACH(dirent, &dir_q, dirs) {
		if (dirent->hardlim)
			continue;
		if ((fn = affixdir(timestr, dirent)) == NULL)
			return (ADE_STRERR);
		if (open_trail(fn, gid, &saverrno) == 0) {
			*newfile = fn;
			if (saverrno) {
				errno = saverrno;
				return (ADE_ACTL);
			}
			return (ADE_NOERR);
		}
		if (warn_getacdir != NULL)
			(*warn_getacdir)(dirent->dirname);
	}
	if (saverrno) {
		errno = saverrno;
		return (ADE_ACTLERR);
	} else
		return (ADE_SWAPERR);
}
int auditd_swap_trail ( char * TS , char * * newfile , gid_t gid , int ( * warn_getacdir ) ( char * ) ) { char timestr [ FILENAME_LEN + 1 ] ; char * fn ; struct dir_ent * dirent ; int saverrno = 0 ; if ( strlen ( TS ) != TIMESTAMP_LEN || snprintf ( timestr , sizeof ( timestr ) , " " , TS , NOT_TERMINATED ) < 0 ) { errno = EINVAL ; return ( ADE_STRERR ) ; } TAILQ_FOREACH ( dirent , & dir_q , dirs ) { if ( dirent -> hardlim ) continue ; if ( ( fn = affixdir ( timestr , dirent ) ) == NULL ) return ( ADE_STRERR ) ; if ( open_trail ( fn , gid , & saverrno ) == 0 ) { * newfile = fn ; if ( saverrno ) { errno = saverrno ; return ( ADE_ACTL ) ; } return ( ADE_NOERR ) ; } if ( warn_getacdir != NULL ) ( * warn_getacdir ) ( dirent -> dirname ) ; } if ( saverrno ) { errno = saverrno ; return ( ADE_ACTLERR ) ; } else return ( ADE_SWAPERR ) ; }
Create the new audit trail file, swap with existing audit file.
Create the new audit trail file swap with existing audit file .
/* Try until we succeed. */ /*
		 * Create the file and pass to the kernel if all went well.
		 */ /* Success. */ /*
				 * auditctl() failed but still
				 * successful. Return errno and "soft"
				 * error.
				 */ /*
		 * auditctl failed setting log file. Try again.
		 */ /*
		 * Tell the administrator about lack of permissions for dir.
		 */