FreeBSD/contrib/openbsm/libauditd/auditd_lib.c
/*
 * Generate and submit audit record for audit startup or shutdown.  The event
 * argument can be AUE_audit_recovery, AUE_audit_startup or
 * AUE_audit_shutdown. The path argument will add a path token, if not NULL.
 * Returns:
 *	AUE_NOERR	on success,
 *	ADE_NOMEM	if memory allocation fails,
 *	ADE_AU_OPEN	if au_open(3) fails,
 *	ADE_AU_CLOSE	if au_close(3) fails.
 */
Generate and submit audit record for audit startup or shutdown.
Generate and submit audit record for audit startup or shutdown .
int
auditd_gen_record(int event, char *path)
{
	int aufd;
	uid_t uid;
	pid_t pid;
	char *autext = NULL;
	token_t *tok;
	struct auditinfo_addr aia;
	if (event == AUE_audit_startup)
		asprintf(&autext, "%s::Audit startup", getprogname());
	else if (event == AUE_audit_shutdown)
		asprintf(&autext, "%s::Audit shutdown", getprogname());
	else if (event == AUE_audit_recovery)
		asprintf(&autext, "%s::Audit recovery", getprogname());
	else
		return (ADE_INVAL);
	if (autext == NULL)
		return (ADE_NOMEM);
	if ((aufd = au_open()) == -1) {
		free(autext);
		return (ADE_AU_OPEN);
	}
	bzero(&aia, sizeof(aia));
	uid = getuid(); pid = getpid();
	if ((tok = au_to_subject32_ex(uid, geteuid(), getegid(), uid, getgid(),
	    pid, pid, &aia.ai_termid)) != NULL)
		au_write(aufd, tok);
	if ((tok = au_to_text(autext)) != NULL)
		au_write(aufd, tok);
	free(autext);
	if (path != NULL && (tok = au_to_path(path)) != NULL)
		au_write(aufd, tok);
	if ((tok = au_to_return32(0, 0)) != NULL)
		au_write(aufd, tok);
	if (au_close(aufd, 1, event) == -1)
		return (ADE_AU_CLOSE);
	return (ADE_NOERR);
}
int auditd_gen_record ( int event , char * path ) { int aufd ; uid_t uid ; pid_t pid ; char * autext = NULL ; token_t * tok ; struct auditinfo_addr aia ; if ( event == AUE_audit_startup ) asprintf ( & autext , " " , getprogname ( ) ) ; else if ( event == AUE_audit_shutdown ) asprintf ( & autext , " " , getprogname ( ) ) ; else if ( event == AUE_audit_recovery ) asprintf ( & autext , " " , getprogname ( ) ) ; else return ( ADE_INVAL ) ; if ( autext == NULL ) return ( ADE_NOMEM ) ; if ( ( aufd = au_open ( ) ) == -1 ) { free ( autext ) ; return ( ADE_AU_OPEN ) ; } bzero ( & aia , sizeof ( aia ) ) ; uid = getuid ( ) ; pid = getpid ( ) ; if ( ( tok = au_to_subject32_ex ( uid , geteuid ( ) , getegid ( ) , uid , getgid ( ) , pid , pid , & aia . ai_termid ) ) != NULL ) au_write ( aufd , tok ) ; if ( ( tok = au_to_text ( autext ) ) != NULL ) au_write ( aufd , tok ) ; free ( autext ) ; if ( path != NULL && ( tok = au_to_path ( path ) ) != NULL ) au_write ( aufd , tok ) ; if ( ( tok = au_to_return32 ( 0 , 0 ) ) != NULL ) au_write ( aufd , tok ) ; if ( au_close ( aufd , 1 , event ) == -1 ) return ( ADE_AU_CLOSE ) ; return ( ADE_NOERR ) ; }
Generate and submit audit record for audit startup or shutdown.
Generate and submit audit record for audit startup or shutdown .