All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
as_admin.h
Go to the documentation of this file.
1 /*
2  * Copyright 2008-2016 Aerospike, Inc.
3  *
4  * Portions may be licensed to Aerospike, Inc. under one or more contributor
5  * license agreements.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
8  * use this file except in compliance with the License. You may obtain a copy of
9  * the License at http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14  * License for the specific language governing permissions and limitations under
15  * the License.
16  */
17 #pragma once
18 
19 #include <aerospike/aerospike.h>
20 #include <aerospike/as_config.h>
21 #include <aerospike/as_key.h>
22 #include <aerospike/as_socket.h>
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 /******************************************************************************
29  * MACROS
30  *****************************************************************************/
31 
32 /**
33  * Maximum size of role string including null byte.
34  */
35 #define AS_ROLE_SIZE 32
36 
37 /******************************************************************************
38  * TYPES
39  *****************************************************************************/
40 
41 /**
42  * Permission codes define the type of permission granted for a user's role.
43  */
44 typedef enum as_privilege_code_e {
45  /**
46  * User can edit/remove other users. Global scope only.
47  */
49 
50  /**
51  * User can perform systems administration functions on a database that do not involve user
52  * administration. Examples include setting dynamic server configuration.
53  * Global scope only.
54  */
56 
57  /**
58  * User can perform data administration functions on a database that do not involve user
59  * administration. Examples include create/drop index and user defined functions.
60  * Global scope only.
61  */
63 
64  /**
65  * User can read data only.
66  */
68 
69  /**
70  * User can read and write data.
71  */
73 
74  /**
75  * User can read and write data through user defined functions.
76  */
79 
80 /**
81  * User privilege.
82  */
83 typedef struct as_privilege_s {
84  /**
85  * Namespace scope. Apply permission to this null terminated namespace only.
86  * If string length is zero, the privilege applies to all namespaces.
87  */
89 
90  /**
91  * Set name scope. Apply permission to this null terminated set within namespace only.
92  * If string length is zero, the privilege applies to all sets within namespace.
93  */
95 
96  /**
97  * Privilege code.
98  */
100 } as_privilege;
101 
102 /**
103  * Role definition.
104  */
105 typedef struct as_role_s {
106  /**
107  * Role name.
108  */
109  char name[AS_ROLE_SIZE];
110 
111  /**
112  * Length of privileges array.
113  */
115 
116  /**
117  * Array of assigned privileges.
118  */
119  as_privilege privileges[];
120 } as_role;
121 
122 /**
123  * User and assigned roles.
124  */
125 typedef struct as_user_s {
126  /**
127  * User name.
128  */
129  char name[AS_USER_SIZE];
130 
131  /**
132  * Length of roles array.
133  */
135 
136  /**
137  * Array of assigned role names.
138  */
139  char roles[][AS_ROLE_SIZE];
140 } as_user;
141 
142 /******************************************************************************
143  * FUNCTIONS
144  ******************************************************************************/
145 
146 /**
147  * Create user with password and roles. Clear-text password will be hashed using bcrypt before
148  * sending to server.
149  */
150 as_status
151 aerospike_create_user(aerospike* as, as_error* err, const as_policy_admin* policy, const char* user_name, const char* password, const char** roles, int roles_size);
152 
153 /**
154  * Remove user from cluster.
155  */
156 as_status
157 aerospike_drop_user(aerospike* as, as_error* err, const as_policy_admin* policy, const char* user_name);
158 
159 /**
160  * Set user's password by user administrator. Clear-text password will be hashed using bcrypt before sending to server.
161  */
162 as_status
163 aerospike_set_password(aerospike* as, as_error* err, const as_policy_admin* policy, const char* user_name, const char* password);
164 
165 /**
166  * Change user's password by user. Clear-text password will be hashed using bcrypt before sending to server.
167  */
168 as_status
169 aerospike_change_password(aerospike* as, as_error* err, const as_policy_admin* policy, const char* user_name, const char* password);
170 
171 /**
172  * Add role to user's list of roles.
173  */
174 as_status
175 aerospike_grant_roles(aerospike* as, as_error* err, const as_policy_admin* policy, const char* user_name, const char** roles, int roles_size);
176 
177 /**
178  * Remove role from user's list of roles.
179  */
180 as_status
181 aerospike_revoke_roles(aerospike* as, as_error* err, const as_policy_admin* policy, const char* user_name, const char** roles, int roles_size);
182 
183 /**
184  * Create user defined role.
185  */
186 as_status
187 aerospike_create_role(aerospike* as, as_error* err, const as_policy_admin* policy, const char* role, as_privilege** privileges, int privileges_size);
188 
189 /**
190  * Delete user defined role.
191  */
192 as_status
193 aerospike_drop_role(aerospike* as, as_error* err, const as_policy_admin* policy, const char* role);
194 
195 /**
196  * Add specified privileges to user.
197  */
198 as_status
199 aerospike_grant_privileges(aerospike* as, as_error* err, const as_policy_admin* policy, const char* role, as_privilege** privileges, int privileges_size);
200 
201 /**
202  * Remove specified privileges from user.
203  */
204 as_status
205 aerospike_revoke_privileges(aerospike* as, as_error* err, const as_policy_admin* policy, const char* role, as_privilege** privileges, int privileges_size);
206 
207 /**
208  * Retrieve roles for a given user.
209  * When successful, as_user_destroy() must be called to free resources.
210  */
211 as_status
212 aerospike_query_user(aerospike* as, as_error* err, const as_policy_admin* policy, const char* user_name, as_user** user);
213 
214 /**
215  * Release as_user_roles memory.
216  */
217 void
218 as_user_destroy(as_user* user);
219 
220 /**
221  * Retrieve all users and their roles.
222  * When successful, as_users_destroy() must be called to free resources.
223  */
224 as_status
225 aerospike_query_users(aerospike* as, as_error* err, const as_policy_admin* policy, as_user*** users, int* users_size);
226 
227 /**
228  * Release memory for as_user_roles array.
229  */
230 void
231 as_users_destroy(as_user** users, int users_size);
232 
233 /**
234  * Retrieve role definition for a given role name.
235  * When successful, as_role_destroy() must be called to free resources.
236  */
237 as_status
238 aerospike_query_role(aerospike* as, as_error* err, const as_policy_admin* policy, const char* role_name, as_role** role);
239 
240 /**
241  * Release as_role memory.
242  */
243 void
244 as_role_destroy(as_role* role);
245 
246 /**
247  * Retrieve all roles and their privileges.
248  * When successful, as_roles_destroy() must be called to free resources.
249  */
250 as_status
251 aerospike_query_roles(aerospike* as, as_error* err, const as_policy_admin* policy, as_role*** roles, int* roles_size);
252 
253 /**
254  * Release memory for as_role array.
255  */
256 void
257 as_roles_destroy(as_role** roles, int roles_size);
258 
259 /**
260  * @private
261  * Authenticate user with a server node. This is done automatically after socket open.
262  * Do not use this method directly.
263  */
264 as_status
265 as_authenticate(as_error* err, as_socket* sock, const char* user, const char* credential, uint64_t deadline_ms);
266 
267 /**
268  * @private
269  * Write authentication command to buffer. Return buffer length.
270  */
271 uint32_t
272 as_authenticate_set(const char* user, const char* credential, uint8_t* buffer);
273 
274 #ifdef __cplusplus
275 } // end extern "C"
276 #endif
as_status aerospike_drop_role(aerospike *as, as_error *err, const as_policy_admin *policy, const char *role)
#define AS_USER_SIZE
Definition: as_password.h:28
as_status aerospike_create_role(aerospike *as, as_error *err, const as_policy_admin *policy, const char *role, as_privilege **privileges, int privileges_size)
as_status as_authenticate(as_error *err, as_socket *sock, const char *user, const char *credential, uint64_t deadline_ms)
as_status aerospike_create_user(aerospike *as, as_error *err, const as_policy_admin *policy, const char *user_name, const char *password, const char **roles, int roles_size)
as_status aerospike_revoke_privileges(aerospike *as, as_error *err, const as_policy_admin *policy, const char *role, as_privilege **privileges, int privileges_size)
as_privilege_code code
Definition: as_admin.h:99
as_set set
Definition: as_admin.h:94
as_status
Definition: as_status.h:30
int privileges_size
Definition: as_admin.h:114
void as_users_destroy(as_user **users, int users_size)
char as_namespace[AS_NAMESPACE_MAX_SIZE]
Definition: as_key.h:66
as_status aerospike_query_role(aerospike *as, as_error *err, const as_policy_admin *policy, const char *role_name, as_role **role)
as_status aerospike_grant_roles(aerospike *as, as_error *err, const as_policy_admin *policy, const char *user_name, const char **roles, int roles_size)
as_status aerospike_query_users(aerospike *as, as_error *err, const as_policy_admin *policy, as_user ***users, int *users_size)
as_namespace ns
Definition: as_admin.h:88
void as_role_destroy(as_role *role)
as_privilege_code
Definition: as_admin.h:44
uint32_t as_authenticate_set(const char *user, const char *credential, uint8_t *buffer)
as_status aerospike_change_password(aerospike *as, as_error *err, const as_policy_admin *policy, const char *user_name, const char *password)
as_status aerospike_query_user(aerospike *as, as_error *err, const as_policy_admin *policy, const char *user_name, as_user **user)
void as_roles_destroy(as_role **roles, int roles_size)
int roles_size
Definition: as_admin.h:134
as_status aerospike_grant_privileges(aerospike *as, as_error *err, const as_policy_admin *policy, const char *role, as_privilege **privileges, int privileges_size)
#define AS_ROLE_SIZE
Definition: as_admin.h:35
as_status aerospike_query_roles(aerospike *as, as_error *err, const as_policy_admin *policy, as_role ***roles, int *roles_size)
as_status aerospike_set_password(aerospike *as, as_error *err, const as_policy_admin *policy, const char *user_name, const char *password)
as_status aerospike_revoke_roles(aerospike *as, as_error *err, const as_policy_admin *policy, const char *user_name, const char **roles, int roles_size)
char as_set[AS_SET_MAX_SIZE]
Definition: as_key.h:73
void as_user_destroy(as_user *user)
as_status aerospike_drop_user(aerospike *as, as_error *err, const as_policy_admin *policy, const char *user_name)