Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
aerospike
as_admin.h
Go to the documentation of this file.
1
/*
2
* Copyright 2008-2017 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
*/
48
AS_PRIVILEGE_USER_ADMIN
= 0,
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
*/
55
AS_PRIVILEGE_SYS_ADMIN
= 1,
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
*/
62
AS_PRIVILEGE_DATA_ADMIN
= 2,
63
64
/**
65
* User can read data only.
66
*/
67
AS_PRIVILEGE_READ
= 10,
68
69
/**
70
* User can read and write data.
71
*/
72
AS_PRIVILEGE_READ_WRITE
= 11,
73
74
/**
75
* User can read and write data through user defined functions.
76
*/
77
AS_PRIVILEGE_READ_WRITE_UDF
= 12
78
}
as_privilege_code
;
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
*/
88
as_namespace
ns
;
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
*/
94
as_set
set
;
95
96
/**
97
* Privilege code.
98
*/
99
as_privilege_code
code
;
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
*/
114
int
privileges_size
;
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
*/
134
int
roles_size
;
135
136
/**
137
* Array of assigned role names.
138
*/
139
char
roles[][
AS_ROLE_SIZE
];
140
}
as_user
;
141
142
struct
as_node_s;
143
144
/******************************************************************************
145
* FUNCTIONS
146
******************************************************************************/
147
148
/**
149
* Create user with password and roles. Clear-text password will be hashed using bcrypt before
150
* sending to server.
151
*/
152
as_status
153
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);
154
155
/**
156
* Remove user from cluster.
157
*/
158
as_status
159
aerospike_drop_user
(
aerospike
* as,
as_error
* err,
const
as_policy_admin
* policy,
const
char
* user_name);
160
161
/**
162
* Set user's password by user administrator. Clear-text password will be hashed using bcrypt before sending to server.
163
*/
164
as_status
165
aerospike_set_password
(
aerospike
* as,
as_error
* err,
const
as_policy_admin
* policy,
const
char
* user_name,
const
char
* password);
166
167
/**
168
* Change user's password by user. Clear-text password will be hashed using bcrypt before sending to server.
169
*/
170
as_status
171
aerospike_change_password
(
aerospike
* as,
as_error
* err,
const
as_policy_admin
* policy,
const
char
* user_name,
const
char
* password);
172
173
/**
174
* Add role to user's list of roles.
175
*/
176
as_status
177
aerospike_grant_roles
(
aerospike
* as,
as_error
* err,
const
as_policy_admin
* policy,
const
char
* user_name,
const
char
** roles,
int
roles_size);
178
179
/**
180
* Remove role from user's list of roles.
181
*/
182
as_status
183
aerospike_revoke_roles
(
aerospike
* as,
as_error
* err,
const
as_policy_admin
* policy,
const
char
* user_name,
const
char
** roles,
int
roles_size);
184
185
/**
186
* Create user defined role.
187
*/
188
as_status
189
aerospike_create_role
(
aerospike
* as,
as_error
* err,
const
as_policy_admin
* policy,
const
char
* role,
as_privilege
** privileges,
int
privileges_size);
190
191
/**
192
* Delete user defined role.
193
*/
194
as_status
195
aerospike_drop_role
(
aerospike
* as,
as_error
* err,
const
as_policy_admin
* policy,
const
char
* role);
196
197
/**
198
* Add specified privileges to user.
199
*/
200
as_status
201
aerospike_grant_privileges
(
aerospike
* as,
as_error
* err,
const
as_policy_admin
* policy,
const
char
* role,
as_privilege
** privileges,
int
privileges_size);
202
203
/**
204
* Remove specified privileges from user.
205
*/
206
as_status
207
aerospike_revoke_privileges
(
aerospike
* as,
as_error
* err,
const
as_policy_admin
* policy,
const
char
* role,
as_privilege
** privileges,
int
privileges_size);
208
209
/**
210
* Retrieve roles for a given user.
211
* When successful, as_user_destroy() must be called to free resources.
212
*/
213
as_status
214
aerospike_query_user
(
aerospike
* as,
as_error
* err,
const
as_policy_admin
* policy,
const
char
* user_name,
as_user
** user);
215
216
/**
217
* Release as_user_roles memory.
218
*/
219
void
220
as_user_destroy
(
as_user
* user);
221
222
/**
223
* Retrieve all users and their roles.
224
* When successful, as_users_destroy() must be called to free resources.
225
*/
226
as_status
227
aerospike_query_users
(
aerospike
* as,
as_error
* err,
const
as_policy_admin
* policy,
as_user
*** users,
int
* users_size);
228
229
/**
230
* Release memory for as_user_roles array.
231
*/
232
void
233
as_users_destroy
(
as_user
** users,
int
users_size);
234
235
/**
236
* Retrieve role definition for a given role name.
237
* When successful, as_role_destroy() must be called to free resources.
238
*/
239
as_status
240
aerospike_query_role
(
aerospike
* as,
as_error
* err,
const
as_policy_admin
* policy,
const
char
* role_name,
as_role
** role);
241
242
/**
243
* Release as_role memory.
244
*/
245
void
246
as_role_destroy
(
as_role
* role);
247
248
/**
249
* Retrieve all roles and their privileges.
250
* When successful, as_roles_destroy() must be called to free resources.
251
*/
252
as_status
253
aerospike_query_roles
(
aerospike
* as,
as_error
* err,
const
as_policy_admin
* policy,
as_role
*** roles,
int
* roles_size);
254
255
/**
256
* Release memory for as_role array.
257
*/
258
void
259
as_roles_destroy
(
as_role
** roles,
int
roles_size);
260
261
/**
262
* @private
263
* Authenticate user with a server node. This is done automatically after socket open.
264
* Do not use this method directly.
265
*/
266
as_status
267
as_authenticate
(
as_error
* err,
as_socket
* sock,
struct
as_node_s* node,
const
char
* user,
const
char
* credential, uint64_t deadline_ms);
268
269
/**
270
* @private
271
* Write authentication command to buffer. Return buffer length.
272
*/
273
uint32_t
274
as_authenticate_set
(
const
char
* user,
const
char
* credential, uint8_t* buffer);
275
276
#ifdef __cplusplus
277
}
// end extern "C"
278
#endif