tizen 2.3 release
[external/buxton.git] / src / security / smack.h
1 /*
2  * This file is part of buxton.
3  *
4  * Copyright (C) 2013 Intel Corporation
5  *
6  * buxton is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as
8  * published by the Free Software Foundation; either version 2.1
9  * of the License, or (at your option) any later version.
10  */
11
12 #pragma once
13
14 #ifdef HAVE_CONFIG_H
15         #include "config.h"
16 #endif
17
18 #include "backend.h"
19 #include "buxton.h"
20
21 /**
22  * Maximum length for a Smack label
23  */
24 #define SMACK_LABEL_LEN 255
25
26 /**
27  * Smack label xattr key
28  */
29 #define SMACK_ATTR_NAME "security.SMACK64"
30
31 /**
32  * Smackfs mount directory
33  */
34 #define SMACK_MOUNT_DIR "/sys/fs/smackfs"
35
36 /**
37  * Maximum length of a Smack rule access string
38  */
39 #define ACC_LEN 5
40
41 /**
42  * Represents client access to a given resource
43  */
44 typedef enum BuxtonKeyAccessType {
45         ACCESS_NONE = 0, /**<No access permitted */
46         ACCESS_READ = 1 << 0, /**<Read access permitted */
47         ACCESS_WRITE = 1 << 1, /**<Write access permitted */
48         ACCESS_MAXACCESSTYPES = 1 << 2
49 } BuxtonKeyAccessType;
50
51 /**
52  * Check whether Smack is enabled in buxtond
53  * @return a boolean value, indicating whether Smack is enabled
54  */
55 bool buxton_smack_enabled(void)
56         __attribute__((warn_unused_result));
57
58 /**
59  * Load Smack rules from the kernel
60  * @return a boolean value, indicating success of the operation
61  */
62 bool buxton_cache_smack_rules(void)
63         __attribute__((warn_unused_result));
64
65 /**
66  * Check whether the smack access matches the buxton client access
67  * @param subject Smack subject label
68  * @param object Smack object label
69  * @param request The buxton access type being queried
70  * @return true if the smack access matches the given request, otherwise false
71  */
72 bool buxton_check_smack_access(BuxtonString *subject,
73                                BuxtonString *object,
74                                BuxtonKeyAccessType request)
75         __attribute__((warn_unused_result));
76
77 /**
78  * Set up inotify to track Smack rule file for changes
79  * @return an exit code for the operation
80  */
81 int buxton_watch_smack_rules(void)
82         __attribute__((warn_unused_result));
83
84 /*
85  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
86  *
87  * Local variables:
88  * c-basic-offset: 8
89  * tab-width: 8
90  * indent-tabs-mode: t
91  * End:
92  *
93  * vi: set shiftwidth=8 tabstop=8 noexpandtab:
94  * :indentSize=8:tabSize=8:noTabs=false:
95  */