Greenbone Vulnerability Manager  8.0.1~git
manage_acl.h
Go to the documentation of this file.
1 /* Copyright (C) 2013-2018 Greenbone Networks GmbH
2  *
3  * SPDX-License-Identifier: GPL-2.0-or-later
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
25 #ifndef _GVMD_MANAGE_ACL_H
26 #define _GVMD_MANAGE_ACL_H
27 
28 #include "manage_sql.h"
29 
30 #include <glib.h>
31 
37 #define ACL_USER_MAY(resource) \
38  "SELECT count(*) > 0 FROM permissions" \
39  " WHERE resource = " resource " AND subject_location = " G_STRINGIFY ( \
40  LOCATION_TABLE) " AND ((subject_type = 'user'" \
41  " AND subject" \
42  " = (SELECT id FROM users" \
43  " WHERE users.uuid = '%s'))" \
44  " OR (subject_type = 'group'" \
45  " AND subject" \
46  " IN (SELECT DISTINCT \"group\"" \
47  " FROM group_users" \
48  " WHERE \"user\" = (SELECT id" \
49  " FROM users" \
50  " WHERE users.uuid" \
51  " = '%s')))" \
52  " OR (subject_type = 'role'" \
53  " AND subject" \
54  " IN (SELECT DISTINCT role" \
55  " FROM role_users" \
56  " WHERE \"user\" = (SELECT id" \
57  " FROM users" \
58  " WHERE users.uuid" \
59  " = '%s'))))" /* Any permission implies GET. */ \
60  " AND ((lower (substr ('%s', 1, 3)) = 'get'" \
61  " AND name LIKE '%%'" \
62  " || lower (substr ('%s'," \
63  " 5," \
64  " length ('%s') - " \
65  "5)))" \
66  " OR name = lower ('%s'))"
67 
73 #define ACL_IS_GLOBAL() "owner IS NULL"
74 
83 #define ACL_USER_OWNS() \
84  " (owner = (SELECT users.id FROM users" \
85  " WHERE users.uuid = '%s'))"
86 
95 #define ACL_GLOBAL_OR_USER_OWNS() \
96  " ((" ACL_IS_GLOBAL () ")" \
97  " OR (owner = (SELECT users.id FROM users" \
98  " WHERE users.uuid = '%s')))"
99 
100 int
101 acl_user_may (const char *);
102 
103 int
104 acl_user_can_everything (const char *);
105 
106 int
107 acl_role_can_super_everyone (const char *);
108 
109 int
110 acl_user_can_super_everyone (const char *);
111 
112 int
113 acl_user_has_super (const char *, user_t);
114 
115 int
116 acl_user_is_admin (const char *);
117 
118 int
119 acl_user_is_user (const char *);
120 
121 int
122 acl_user_is_super_admin (const char *);
123 
124 int
125 acl_user_is_observer (const char *);
126 
127 int
128 acl_user_owns (const char *, resource_t, int);
129 
130 int
131 acl_user_is_owner (const char *, const char *);
132 
133 int
134 acl_user_owns_uuid (const char *, const char *, int);
135 
136 int
137 acl_user_owns_trash_uuid (const char *resource, const char *uuid);
138 
139 int
140 acl_user_has_access_uuid (const char *, const char *, const char *, int);
141 
142 gchar *
143 acl_where_owned (const char *,
144  const get_data_t *,
145  int,
146  const gchar *,
147  resource_t,
148  array_t *,
149  gchar **);
150 
151 gchar *
152 acl_where_owned_for_get (const char *, const char *, gchar **);
153 
154 gchar *
155 acl_users_with_access_sql (const char *, const char *, const char *);
156 
157 gchar *
158 acl_users_with_access_where (const char *,
159  const char *,
160  const char *,
161  const char *);
162 
163 #endif /* not _GVMD_MANAGE_ACL_H */
int acl_user_has_super(const char *, user_t)
Test whether a user has super permission on another user.
Definition: manage_acl.c:230
gchar * acl_where_owned_for_get(const char *, const char *, gchar **)
Generate ownership part of WHERE, for getting a type of resource.
Definition: manage_acl.c:1481
int acl_user_can_everything(const char *)
Test whether a user may perform any operation.
Definition: manage_acl.c:182
gchar * acl_where_owned(const char *, const get_data_t *, int, const gchar *, resource_t, array_t *, gchar **)
Generate the ownership part of an SQL WHERE clause.
Definition: manage_acl.c:1442
gchar * acl_users_with_access_where(const char *, const char *, const char *, const char *)
Get a static SQL condition selecting users that can get a resource.
Definition: manage_acl.c:1590
int acl_user_can_super_everyone(const char *)
Check whether a user is a Super Admin.
Definition: manage_acl.c:123
int acl_user_owns_uuid(const char *, const char *, int)
Test whether a user effectively owns a resource.
Definition: manage_acl.c:569
int acl_user_is_admin(const char *)
Check whether a user is an Admin.
Definition: manage_acl.c:307
Command data for a get command.
Definition: manage.h:316
int acl_user_is_observer(const char *)
Check whether a user is an Observer.
Definition: manage_acl.c:330
int acl_user_owns_trash_uuid(const char *resource, const char *uuid)
Test whether a user effectively owns a resource.
Definition: manage_acl.c:693
int acl_user_owns(const char *, resource_t, int)
Test whether a user effectively owns a resource.
Definition: manage_acl.c:641
gchar * acl_users_with_access_sql(const char *, const char *, const char *)
Get an SQL values expression of users that can get a resource.
Definition: manage_acl.c:1528
int acl_user_has_access_uuid(const char *, const char *, const char *, int)
Test whether the user may access a resource.
Definition: manage_acl.c:728
int acl_user_may(const char *)
Test whether a user may perform an operation.
Definition: manage_acl.c:52
int acl_user_is_user(const char *)
Check whether a user has the User role.
Definition: manage_acl.c:376
int acl_role_can_super_everyone(const char *)
Check whether a role has Super Admin capability.
Definition: manage_acl.c:90
int acl_user_is_owner(const char *, const char *)
Test whether a user is the actual owner of a resource.
Definition: manage_acl.c:536
int acl_user_is_super_admin(const char *)
Check whether a user is a Super Admin.
Definition: manage_acl.c:353
long long int resource_t
A resource, like a task or target.
Definition: iterator.h:40