2010-12-20 12:29:10 -08:00
|
|
|
/*
|
2011-02-22 03:51:16 -08:00
|
|
|
* Copyright (c) 2003-2008 Novell, Inc. (All rights reserved)
|
|
|
|
* Copyright 2009-2010 Canonical Ltd.
|
|
|
|
*
|
|
|
|
* The libapparmor library is licensed under the terms of the GNU
|
|
|
|
* Lesser General Public License, version 2.1. Please see the file
|
|
|
|
* COPYING.LGPL.
|
|
|
|
*
|
2011-02-23 14:02:45 -08:00
|
|
|
* This library 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 Lesser General Public License for more details.
|
|
|
|
*
|
2011-02-22 03:51:16 -08:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2007-07-28 15:41:04 +00:00
|
|
|
|
2013-11-04 12:02:53 -08:00
|
|
|
#ifndef _SYS_APPARMOR_H
|
2007-07-28 15:41:04 +00:00
|
|
|
#define _SYS_APPARMOR_H 1
|
|
|
|
|
2015-03-25 17:09:27 -05:00
|
|
|
#include <stdbool.h>
|
2013-07-31 09:22:40 -07:00
|
|
|
#include <stdint.h>
|
2011-08-31 16:01:54 -07:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
2007-07-28 15:41:04 +00:00
|
|
|
__BEGIN_DECLS
|
|
|
|
|
2013-07-31 09:22:40 -07:00
|
|
|
/*
|
2013-12-06 11:20:40 -08:00
|
|
|
* Class of public mediation types in the AppArmor policy db
|
2013-07-31 09:22:40 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define AA_CLASS_DBUS 32
|
|
|
|
|
|
|
|
|
Move public mediation class types and perms to apparmor.h
Now that the parser links against libapparmor, it makes sense to move
all public permission types and flags to libapparmor's apparmor.h. This
prevents duplication across header files for the parser and libapparmor.
Additionally, this patch breaks the connection between
AA_DBUS_{SEND,RECEIVE,BIND} and AA_MAY_{WRITE,READ,BIND} by using raw
values when defining the AA_DBUS_{SEND,RECEIVE,BIND} macros. This makes
sense because the two sets of permission flags are from two distinctly
different mediation types (AA_CLASS_DBUS and AA_CLASS_FILE). While it is
nice that they share some of the same values, the macros don't need to
be linked together. In other words, when you're creating a D-Bus rule,
it would be incorrect to use permission flags from the AA_CLASS_FILE
type.
The change mentioned above allows the AA_MAY_{WRITE,READ,BIND} macros
to be removed from public-facing apparmor.h header.
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2013-12-06 11:20:06 -08:00
|
|
|
/* Permission flags for the AA_CLASS_DBUS mediation class */
|
|
|
|
#define AA_DBUS_SEND (1 << 1)
|
|
|
|
#define AA_DBUS_RECEIVE (1 << 2)
|
|
|
|
#define AA_DBUS_EAVESDROP (1 << 5)
|
|
|
|
#define AA_DBUS_BIND (1 << 6)
|
|
|
|
#define AA_VALID_DBUS_PERMS (AA_DBUS_SEND | AA_DBUS_RECEIVE | \
|
|
|
|
AA_DBUS_BIND | AA_DBUS_EAVESDROP)
|
2013-07-31 09:22:40 -07:00
|
|
|
|
|
|
|
|
2011-08-09 06:48:17 -07:00
|
|
|
/* Prototypes for apparmor state queries */
|
2011-08-09 06:48:56 -07:00
|
|
|
extern int aa_is_enabled(void);
|
2011-08-09 06:48:17 -07:00
|
|
|
extern int aa_find_mountpoint(char **mnt);
|
|
|
|
|
2011-02-22 03:51:16 -08:00
|
|
|
/* Prototypes for self directed domain transitions
|
|
|
|
* see <http://apparmor.net>
|
|
|
|
* Please see the change_hat(2) manpage for information.
|
|
|
|
*/
|
2007-07-28 15:41:04 +00:00
|
|
|
|
2010-02-11 15:38:24 -08:00
|
|
|
#define change_hat(X, Y) aa_change_hat((X), (Y))
|
2007-08-16 04:26:19 +00:00
|
|
|
extern int (change_hat)(const char *subprofile, unsigned int magic_token);
|
|
|
|
extern int aa_change_hat(const char *subprofile, unsigned long magic_token);
|
2007-09-15 05:41:44 +00:00
|
|
|
extern int aa_change_profile(const char *profile);
|
2010-02-11 15:37:25 -08:00
|
|
|
extern int aa_change_onexec(const char *profile);
|
2007-08-16 04:26:19 +00:00
|
|
|
|
2011-02-22 03:55:16 -08:00
|
|
|
extern int aa_change_hatv(const char *subprofiles[], unsigned long token);
|
|
|
|
extern int (aa_change_hat_vargs)(unsigned long token, int count, ...);
|
2010-02-11 15:38:24 -08:00
|
|
|
|
2015-05-19 21:28:47 -05:00
|
|
|
extern char *aa_splitcon(char *con, char **mode);
|
2011-08-09 06:47:40 -07:00
|
|
|
/* Protypes for introspecting task confinement
|
|
|
|
* Please see the aa_getcon(2) manpage for information
|
|
|
|
*/
|
2011-08-09 06:45:51 -07:00
|
|
|
extern int aa_getprocattr_raw(pid_t tid, const char *attr, char *buf, int len,
|
|
|
|
char **mode);
|
2015-02-09 18:46:46 -06:00
|
|
|
extern int aa_getprocattr(pid_t tid, const char *attr, char **label,
|
|
|
|
char **mode);
|
|
|
|
extern int aa_gettaskcon(pid_t target, char **label, char **mode);
|
|
|
|
extern int aa_getcon(char **label, char **mode);
|
2013-06-25 15:55:08 -07:00
|
|
|
extern int aa_getpeercon_raw(int fd, char *buf, int *len, char **mode);
|
2015-02-09 18:46:46 -06:00
|
|
|
extern int aa_getpeercon(int fd, char **label, char **mode);
|
2011-08-09 06:45:51 -07:00
|
|
|
|
2013-07-31 09:22:40 -07:00
|
|
|
/* A NUL character is used to separate the query command prefix string from the
|
|
|
|
* rest of the query string. The query command sizes intentionally include the
|
|
|
|
* NUL-terminator in their values.
|
|
|
|
*/
|
|
|
|
#define AA_QUERY_CMD_LABEL "label"
|
|
|
|
#define AA_QUERY_CMD_LABEL_SIZE sizeof(AA_QUERY_CMD_LABEL)
|
|
|
|
|
|
|
|
extern int aa_query_label(uint32_t mask, char *query, size_t size, int *allow,
|
|
|
|
int *audit);
|
|
|
|
|
2010-02-11 15:38:24 -08:00
|
|
|
#define __macroarg_counter(Y...) __macroarg_count1 ( , ##Y)
|
|
|
|
#define __macroarg_count1(Y...) __macroarg_count2 (Y, 16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0)
|
|
|
|
#define __macroarg_count2(_,x0,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,n,Y...) n
|
|
|
|
|
|
|
|
/**
|
|
|
|
* change_hat_vargs - a wrapper macro for change_hat_vargs
|
|
|
|
* @T: the magic token
|
|
|
|
* @X...: the parameter list of hats being passed
|
|
|
|
*
|
|
|
|
* The change_hat_vargs macro makes it so the caller doesn't have to
|
|
|
|
* specify the number of hats passed as parameters to the change_hat_vargs
|
|
|
|
* fn.
|
|
|
|
*
|
|
|
|
* eg.
|
|
|
|
* change_hat_vargs(10, hat1, hat2, hat3, hat4);
|
|
|
|
* expandes to
|
|
|
|
* (change_hat_vargs)(10, 4, hat1, hat2, hat3, hat4);
|
|
|
|
*
|
|
|
|
* to call change_hat_vargs direction do
|
|
|
|
* (change_hat_vargs)(token, nhats, hat1, hat2...)
|
|
|
|
*/
|
|
|
|
#define aa_change_hat_vargs(T, X...) \
|
|
|
|
(aa_change_hat_vargs)(T, __macroarg_counter(X), X)
|
2007-07-28 15:41:04 +00:00
|
|
|
|
2015-03-25 17:09:27 -05:00
|
|
|
typedef struct aa_features aa_features;
|
|
|
|
int aa_features_new(aa_features **features, const char *path);
|
|
|
|
int aa_features_new_from_string(aa_features **features,
|
|
|
|
const char *string, size_t size);
|
|
|
|
int aa_features_new_from_kernel(aa_features **features);
|
|
|
|
aa_features *aa_features_ref(aa_features *features);
|
|
|
|
void aa_features_unref(aa_features *features);
|
|
|
|
|
|
|
|
int aa_features_write_to_file(aa_features *features, const char *path);
|
|
|
|
bool aa_features_is_equal(aa_features *features1, aa_features *features2);
|
|
|
|
bool aa_features_supports(aa_features *features, const char *str);
|
|
|
|
|
2015-03-25 17:09:27 -05:00
|
|
|
typedef struct aa_kernel_interface aa_kernel_interface;
|
|
|
|
int aa_kernel_interface_new(aa_kernel_interface **kernel_interface,
|
|
|
|
aa_features *kernel_features,
|
|
|
|
const char *apparmorfs);
|
|
|
|
aa_kernel_interface *aa_kernel_interface_ref(aa_kernel_interface *kernel_interface);
|
|
|
|
void aa_kernel_interface_unref(aa_kernel_interface *kernel_interface);
|
|
|
|
|
|
|
|
int aa_kernel_interface_load_policy(aa_kernel_interface *kernel_interface,
|
|
|
|
const char *buffer, size_t size);
|
|
|
|
int aa_kernel_interface_load_policy_from_file(aa_kernel_interface *kernel_interface,
|
|
|
|
const char *path);
|
|
|
|
int aa_kernel_interface_load_policy_from_fd(aa_kernel_interface *kernel_interface,
|
|
|
|
int fd);
|
|
|
|
int aa_kernel_interface_replace_policy(aa_kernel_interface *kernel_interface,
|
|
|
|
const char *buffer, size_t size);
|
|
|
|
int aa_kernel_interface_replace_policy_from_file(aa_kernel_interface *kernel_interface,
|
|
|
|
const char *path);
|
|
|
|
int aa_kernel_interface_replace_policy_from_fd(aa_kernel_interface *kernel_interface,
|
|
|
|
int fd);
|
|
|
|
int aa_kernel_interface_remove_policy(aa_kernel_interface *kernel_interface,
|
|
|
|
const char *fqname);
|
|
|
|
int aa_kernel_interface_write_policy(int fd, const char *buffer, size_t size);
|
|
|
|
|
2015-03-25 17:09:27 -05:00
|
|
|
typedef struct aa_policy_cache aa_policy_cache;
|
|
|
|
int aa_policy_cache_new(aa_policy_cache **policy_cache,
|
|
|
|
aa_features *kernel_features, const char *path,
|
|
|
|
bool create);
|
|
|
|
aa_policy_cache *aa_policy_cache_ref(aa_policy_cache *policy_cache);
|
|
|
|
void aa_policy_cache_unref(aa_policy_cache *policy_cache);
|
|
|
|
|
|
|
|
bool aa_policy_cache_is_valid(aa_policy_cache *policy_cache);
|
|
|
|
int aa_policy_cache_create(aa_policy_cache *policy_cache);
|
|
|
|
int aa_policy_cache_remove(const char *path);
|
|
|
|
int aa_policy_cache_replace_all(aa_policy_cache *policy_cache,
|
|
|
|
aa_kernel_interface *kernel_interface);
|
|
|
|
|
2007-07-28 15:41:04 +00:00
|
|
|
__END_DECLS
|
|
|
|
|
|
|
|
#endif /* sys/apparmor.h */
|