FreeBSD/contrib/openbsm/libbsm/bsm_audit.c
/*
 * This call reserves memory for the audit record.  Memory must be guaranteed
 * before any auditable event can be generated.  The au_record_t structure
 * maintains a reference to the memory allocated above and also the list of
 * tokens associated with this record.  Descriptors are recyled once the
 * records are added to the audit trail following au_close().
 */
This call reserves memory for the audit record.  Memory must be guaranteed
before any auditable event can be generated.  The au_record_t structure
maintains a reference to the memory allocated above and also the list of
tokens associated with this record.  Descriptors are recyled once the
records are added to the audit trail following au_close().
This call reserves memory for the audit record . Memory must be guaranteed before any auditable event can be generated . The au_record_t structure maintains a reference to the memory allocated above and also the list of tokens associated with this record . Descriptors are recyled once the records are added to the audit trail following au_close () .
int
au_open(void)
{
	au_record_t *rec = NULL;
#ifdef HAVE_PTHREAD_MUTEX_LOCK
	pthread_mutex_lock(&mutex);
#endif
	if (audit_rec_count == 0)
		LIST_INIT(&audit_free_q);
	if (!LIST_EMPTY(&audit_free_q)) {
		rec = LIST_FIRST(&audit_free_q);
		rec->used = 1;
		LIST_REMOVE(rec, au_rec_q);
	}
#ifdef HAVE_PTHREAD_MUTEX_LOCK
	pthread_mutex_unlock(&mutex);
#endif
	if (rec == NULL) {
		rec = malloc (sizeof(au_record_t));
		if (rec == NULL)
			return (-1);
		rec->data = malloc (MAX_AUDIT_RECORD_SIZE * sizeof(u_char));
		if (rec->data == NULL) {
			free(rec);
			errno = ENOMEM;
			return (-1);
		}
#ifdef HAVE_PTHREAD_MUTEX_LOCK
		pthread_mutex_lock(&mutex);
#endif
		if (audit_rec_count == MAX_AUDIT_RECORDS) {
#ifdef HAVE_PTHREAD_MUTEX_LOCK
			pthread_mutex_unlock(&mutex);
#endif
			free(rec->data);
			free(rec);
			errno = ENOMEM;
			return (-1);
		}
		rec->desc = audit_rec_count;
		open_desc_table[audit_rec_count] = rec;
		audit_rec_count++;
#ifdef HAVE_PTHREAD_MUTEX_LOCK
		pthread_mutex_unlock(&mutex);
#endif
	}
	memset(rec->data, 0, MAX_AUDIT_RECORD_SIZE);
	TAILQ_INIT(&rec->token_q);
	rec->len = 0;
	rec->used = 1;
	return (rec->desc);
}
int au_open ( void ) { au_record_t * rec = NULL ; #ifdef HAVE_PTHREAD_MUTEX_LOCK pthread_mutex_lock ( & mutex ) ; #endif if ( audit_rec_count == 0 ) LIST_INIT ( & audit_free_q ) ; if ( ! LIST_EMPTY ( & audit_free_q ) ) { rec = LIST_FIRST ( & audit_free_q ) ; rec -> used = 1 ; LIST_REMOVE ( rec , au_rec_q ) ; } #ifdef HAVE_PTHREAD_MUTEX_LOCK pthread_mutex_unlock ( & mutex ) ; #endif if ( rec == NULL ) { rec = malloc ( sizeof ( au_record_t ) ) ; if ( rec == NULL ) return ( -1 ) ; rec -> data = malloc ( MAX_AUDIT_RECORD_SIZE * sizeof ( u_char ) ) ; if ( rec -> data == NULL ) { free ( rec ) ; errno = ENOMEM ; return ( -1 ) ; } #ifdef HAVE_PTHREAD_MUTEX_LOCK pthread_mutex_lock ( & mutex ) ; #endif if ( audit_rec_count == MAX_AUDIT_RECORDS ) { #ifdef HAVE_PTHREAD_MUTEX_LOCK pthread_mutex_unlock ( & mutex ) ; #endif free ( rec -> data ) ; free ( rec ) ; errno = ENOMEM ; return ( -1 ) ; } rec -> desc = audit_rec_count ; open_desc_table [ audit_rec_count ] = rec ; audit_rec_count ++ ; #ifdef HAVE_PTHREAD_MUTEX_LOCK pthread_mutex_unlock ( & mutex ) ; #endif } memset ( rec -> data , 0 , MAX_AUDIT_RECORD_SIZE ) ; TAILQ_INIT ( & rec -> token_q ) ; rec -> len = 0 ; rec -> used = 1 ; return ( rec -> desc ) ; }
This call reserves memory for the audit record.
This call reserves memory for the audit record .
/*
	 * Find an unused descriptor, remove it from the free list, mark as
	 * used.
	 */ /*
		 * Create a new au_record_t if no descriptors are available.
		 */ /* XXX We need to increase size of MAX_AUDIT_RECORDS */