#ifndef _LSM_EXAMPLE_H
#define _LSM_EXAMPLE_H

/*
 * This is the code for the example module.
 */

#include <linux/config.h>
#include <linux/major.h>

#define security_alert(normal_msg, flood_msg, args...)			\
({									\
 	static unsigned long warning_time = 0, no_flood_yet = 0;	\
	static spinlock_t security_alert_lock = SPIN_LOCK_UNLOCKED;	\
									\
	spin_lock(&security_alert_lock);				\
									\
/* Make sure at least one minute passed since the last warning logged */\
	if (!warning_time || jiffies - warning_time > 60 * HZ) {	\
		warning_time = jiffies; no_flood_yet = 1;		\
		printk(KERN_ALERT "Security: " normal_msg "\n", ## args);\
	} else if (no_flood_yet) {					\
		warning_time = jiffies; no_flood_yet = 0;		\
		printk(KERN_ALERT "Security: more " flood_msg		\
			", logging disabled for a minute\n");		\
	}								\
									\
	spin_unlock(&security_alert_lock);				\
})

/*
 * Conditional defines for Openwall LSM helper functions
 */

#ifdef CONFIG_SECURITY_EX
static inline int do_example_inode_permission(struct inode *inode, int mask)
{
	printk(KERN_INFO "inode %d has been accessed by %d\n", inode->i_ino, 
		current->uid);
	return 0;
}
#else
static inline int do_example_inode_permission(struct inode *inode, int mask)
{
	return 0;
}
#endif /* CONFIG_SECURITY_EX */


#endif /* _LSM_EXAMPLE_H */
