FreeBSD/contrib/openbsm/libauditd/auditd_lib.c
/*
 * Check for a 'current' symlink and do crash recovery, if needed. Create a new
 * 'current' symlink. The argument 'curfile' is the file the 'current' symlink
 * should point to.  Returns:
 *	ADE_NOERR	on success,
 *	ADE_AU_OPEN	if au_open(3) fails,
 *	ADE_AU_CLOSE	if au_close(3) fails.
 *	ADE_RENAME	if error renaming audit trail file,
 *	ADE_READLINK	if error reading the 'current' link,
 *	ADE_SYMLINK	if error creating 'current' link.
 */
Check for a 'current' symlink and do crash recovery, if needed. Create a new
'current' symlink. The argument 'curfile' is the file the 'current' symlink
should point to.
Check for a ' current ' symlink and do crash recovery if needed . Create a new ' current ' symlink . The argument ' curfile ' is the file the ' current ' symlink should point to .
int
auditd_new_curlink(char *curfile)
{
	int len, err;
	char *ptr;
	char *path = NULL;
	struct stat sb;
	char recoveredname[MAXPATHLEN];
	char newname[MAXPATHLEN];
	len = readlink(AUDIT_CURRENT_LINK, recoveredname,
	    sizeof(recoveredname) - 1);
	if (len > 0) {
		recoveredname[len++] = '\0';
		if (stat(recoveredname, &sb) == 0) {
			strlcpy(newname, recoveredname, sizeof(newname));
			if ((ptr = strstr(newname, NOT_TERMINATED)) != NULL) {
				memcpy(ptr, CRASH_RECOVERY, POSTFIX_LEN);
				if (auditd_rename(recoveredname, newname) != 0)
					return (ADE_RENAME);
			} else
				return (ADE_STRERR);
			path = newname;
		}
		(void) unlink(AUDIT_CURRENT_LINK);
		err = auditd_gen_record(AUE_audit_recovery, path);
		if (err)
			return (err);
	}
	if (len < 0 && errno != ENOENT)
		return (ADE_READLINK);
	if (symlink(curfile, AUDIT_CURRENT_LINK) != 0)
		return (ADE_SYMLINK);
	return (0);
}
int auditd_new_curlink ( char * curfile ) { int len , err ; char * ptr ; char * path = NULL ; struct stat sb ; char recoveredname [ MAXPATHLEN ] ; char newname [ MAXPATHLEN ] ; len = readlink ( AUDIT_CURRENT_LINK , recoveredname , sizeof ( recoveredname ) - 1 ) ; if ( len > 0 ) { recoveredname [ len ++ ] = ' \0 ' ; if ( stat ( recoveredname , & sb ) == 0 ) { strlcpy ( newname , recoveredname , sizeof ( newname ) ) ; if ( ( ptr = strstr ( newname , NOT_TERMINATED ) ) != NULL ) { memcpy ( ptr , CRASH_RECOVERY , POSTFIX_LEN ) ; if ( auditd_rename ( recoveredname , newname ) != 0 ) return ( ADE_RENAME ) ; } else return ( ADE_STRERR ) ; path = newname ; } ( void ) unlink ( AUDIT_CURRENT_LINK ) ; err = auditd_gen_record ( AUE_audit_recovery , path ) ; if ( err ) return ( err ) ; } if ( len < 0 && errno != ENOENT ) return ( ADE_READLINK ) ; if ( symlink ( curfile , AUDIT_CURRENT_LINK ) != 0 ) return ( ADE_SYMLINK ) ; return ( 0 ) ; }
Check for a 'current' symlink and do crash recovery, if needed.
Check for a ' current ' symlink and do crash recovery if needed .
/*
	 * Check to see if audit was shutdown properly.  If not, clean up,
	 * recover previous audit trail file, and generate audit record.
	 */ /* 'current' exist but is it pointing at a valid file?  */ /* Yes, rename it to a crash recovery file. */ /* 'current' symlink is (now) invalid so remove it. */ /* Note the crash recovery in current audit trail */