/*
 * Copyright (C) 1999-2000 Wojciech Purczynski <wp@elzabsoft.pl>
 *
 * THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
 * IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE AS PUBLISHED BY
 * THE FREE SOFTWARE  FOUNDATION;  EITHER  VERSION 2 OF THE LICENSE, OR
 * (AT YOUR OPTION) ANY LATER VERSION.
 *
 * THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
 * BUT WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED  WARRANTY OF
 * MERCHANTABILITY OR FITNESS  FOR A PARTICULAR  PURPOSE.  SEE THE
 * GNU GENERAL PUBLIC LICENSE FOR MORE DETAILS.
 */

#ifndef _CONFIG_H
#define _CONFIG_H

#include <linux/capability.h>

#ifndef TRUE
#define TRUE	-1
#endif

#ifndef FALSE
#define FALSE	0
#endif

#define EXEC_DENY	0
#define EXEC_ALLOW	-1

#define EXEC_NONE	0
#define EXEC_LIST	1
#define EXEC_ALL	-1

#define LOG_NOTHING	0
#define LOG_DEBUG	1
#define LOG_SECURITY	2

#define CAP_EFFECTIVE	1
#define CAP_PERMITTED	2
#define CAP_INHERITABLE	4

struct executable_t;
typedef struct executable_t executable_t;

/* List of allowed executables */
struct executable_t {
	char * name;
	executable_t * next;
};

/* Capabilities that are set when new process is executed */
typedef struct cap_mask_t {
	kernel_cap_t raise;
	kernel_cap_t lower;
} cap_mask_t;

typedef struct capabilities_t {
	cap_mask_t effective;
	cap_mask_t permitted;
	cap_mask_t inheritable;
} capabilities_t;

/* Rule definition */
struct rule_t;
typedef struct rule_t rule_t;
struct rule_t {
	char * name;
	/* Options */
	int 		check_uid	:1;
	uid_t 		uid;
	int 		check_gid	:1;
	gid_t 		gid;
	int 		check_groups	:1;
	int		check_execve	:2;
	int		perm_execve	:1;
	int		check_chroot	:1;
	int 		ignore		:1;
	unsigned 	log_level	:2;
	executable_t 	* executables;		/* list of executables */
	char		* root;			/* root directory */
	capabilities_t 	caps;
#ifdef USE_UIDCAP
	capabilities_t	uidcaps;		/* setuid capabilities mask */
#endif /* USE_UIDCAP */
	rule_t * next;
};

/* Below is a definition of array of capabilities names and their values */
typedef struct {
	char * name;
	kernel_cap_t value;
} cap_name_t;

extern cap_name_t cap_names[];
extern rule_t * first_rule;	/* list of rules */
extern rule_t default_rule;

/* Functions */
int read_conf(const char *);
void close_conf(void);
size_t allocated_memory(void);
rule_t * find_rule(const char *);

#endif /* _CONFIG_H */
