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-2015 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 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /******************************************************************************
28  * MACROS
29  *****************************************************************************/
30 
31 /**
32  * Maximum size of role string including null byte.
33  */
34 #define AS_ROLE_SIZE 32
35 
36 /******************************************************************************
37  * TYPES
38  *****************************************************************************/
39 
40 /**
41  * Permission codes define the type of permission granted for a user's role.
42  */
43 typedef enum as_privilege_code_e {
44  /**
45  * User can edit/remove other users. Global scope only.
46  */
48 
49  /**
50  * User can perform systems administration functions on a database that do not involve user
51  * administration. Global scope only.
52  */
54 
55  /**
56  * User can read data only.
57  */
59 
60  /**
61  * User can read and write data.
62  */
64 
65  /**
66  * User can read and write data through user defined functions.
67  */
70 
71 /**
72  * User privilege.
73  */
74 typedef struct as_privilege_s {
75  /**
76  * Namespace scope. Apply permission to this null terminated namespace only.
77  * If string length is zero, the privilege applies to all namespaces.
78  */
80 
81  /**
82  * Set name scope. Apply permission to this null terminated set within namespace only.
83  * If string length is zero, the privilege applies to all sets within namespace.
84  */
86 
87  /**
88  * Privilege code.
89  */
91 } as_privilege;
92 
93 /**
94  * Role definition.
95  */
96 typedef struct as_role_s {
97  /**
98  * Role name.
99  */
100  char name[AS_ROLE_SIZE];
101 
102  /**
103  * Length of privileges array.
104  */
106 
107  /**
108  * Array of assigned privileges.
109  */
110  as_privilege privileges[];
111 } as_role;
112 
113 /**
114  * User and assigned roles.
115  */
116 typedef struct as_user_s {
117  /**
118  * User name.
119  */
120  char name[AS_USER_SIZE];
121 
122  /**
123  * Length of roles array.
124  */
126 
127  /**
128  * Array of assigned role names.
129  */
130  char roles[][AS_ROLE_SIZE];
131 } as_user;
132 
133 /******************************************************************************
134  * FUNCTIONS
135  ******************************************************************************/
136 
137 /**
138  * Create user with password and roles. Clear-text password will be hashed using bcrypt before
139  * sending to server.
140  */
141 as_status
142 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);
143 
144 /**
145  * Remove user from cluster.
146  */
147 as_status
148 aerospike_drop_user(aerospike* as, as_error* err, const as_policy_admin* policy, const char* user_name);
149 
150 /**
151  * Set user's password by user administrator. Clear-text password will be hashed using bcrypt before sending to server.
152  */
153 as_status
154 aerospike_set_password(aerospike* as, as_error* err, const as_policy_admin* policy, const char* user_name, const char* password);
155 
156 /**
157  * Change user's password by user. Clear-text password will be hashed using bcrypt before sending to server.
158  */
159 as_status
160 aerospike_change_password(aerospike* as, as_error* err, const as_policy_admin* policy, const char* user_name, const char* password);
161 
162 /**
163  * Add role to user's list of roles.
164  */
165 as_status
166 aerospike_grant_roles(aerospike* as, as_error* err, const as_policy_admin* policy, const char* user_name, const char** roles, int roles_size);
167 
168 /**
169  * Remove role from user's list of roles.
170  */
171 as_status
172 aerospike_revoke_roles(aerospike* as, as_error* err, const as_policy_admin* policy, const char* user_name, const char** roles, int roles_size);
173 
174 /**
175  * Create user defined role.
176  */
177 as_status
178 aerospike_create_role(aerospike* as, as_error* err, const as_policy_admin* policy, const char* role, as_privilege** privileges, int privileges_size);
179 
180 /**
181  * Delete user defined role.
182  */
183 as_status
184 aerospike_drop_role(aerospike* as, as_error* err, const as_policy_admin* policy, const char* role);
185 
186 /**
187  * Add specified privileges to user.
188  */
189 as_status
190 aerospike_grant_privileges(aerospike* as, as_error* err, const as_policy_admin* policy, const char* role, as_privilege** privileges, int privileges_size);
191 
192 /**
193  * Remove specified privileges from user.
194  */
195 as_status
196 aerospike_revoke_privileges(aerospike* as, as_error* err, const as_policy_admin* policy, const char* role, as_privilege** privileges, int privileges_size);
197 
198 /**
199  * Retrieve roles for a given user.
200  * When successful, as_user_destroy() must be called to free resources.
201  */
202 as_status
203 aerospike_query_user(aerospike* as, as_error* err, const as_policy_admin* policy, const char* user_name, as_user** user);
204 
205 /**
206  * Release as_user_roles memory.
207  */
208 void
209 as_user_destroy(as_user* user);
210 
211 /**
212  * Retrieve all users and their roles.
213  * When successful, as_users_destroy() must be called to free resources.
214  */
215 as_status
216 aerospike_query_users(aerospike* as, as_error* err, const as_policy_admin* policy, as_user*** users, int* users_size);
217 
218 /**
219  * Release memory for as_user_roles array.
220  */
221 void
222 as_users_destroy(as_user** users, int users_size);
223 
224 /**
225  * Retrieve role definition for a given role name.
226  * When successful, as_role_destroy() must be called to free resources.
227  */
228 as_status
229 aerospike_query_role(aerospike* as, as_error* err, const as_policy_admin* policy, const char* role_name, as_role** role);
230 
231 /**
232  * Release as_role memory.
233  */
234 void
235 as_role_destroy(as_role* role);
236 
237 /**
238  * Retrieve all roles and their privileges.
239  * When successful, as_roles_destroy() must be called to free resources.
240  */
241 as_status
242 aerospike_query_roles(aerospike* as, as_error* err, const as_policy_admin* policy, as_role*** roles, int* roles_size);
243 
244 /**
245  * Release memory for as_role array.
246  */
247 void
248 as_roles_destroy(as_role** roles, int roles_size);
249 
250 /**
251  * @private
252  * Authenticate user with a server node. This is done automatically after socket open.
253  * Do not use this method directly.
254  */
255 as_status
256 as_authenticate(as_error* err, int fd, const char* user, const char* credential, uint64_t deadline_ms);
257 
258 #ifdef __cplusplus
259 } // end extern "C"
260 #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 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:90
as_set set
Definition: as_admin.h:85
as_status
Definition: as_status.h:30
int privileges_size
Definition: as_admin.h:105
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:79
void as_role_destroy(as_role *role)
as_privilege_code
Definition: as_admin.h:43
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:125
as_status aerospike_grant_privileges(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, int fd, const char *user, const char *credential, uint64_t deadline_ms)
#define AS_ROLE_SIZE
Definition: as_admin.h:34
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)