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-2014 by Aerospike.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to
6  * deal in the Software without restriction, including without limitation the
7  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8  * sell copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20  * IN THE SOFTWARE.
21  *****************************************************************************/
22 #pragma once
23 
24 #include <aerospike/aerospike.h>
25 #include <aerospike/as_config.h>
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  * User and assigned roles.
42  */
43 typedef struct as_user_roles_s {
44  /**
45  * User name.
46  */
47  char user[AS_USER_SIZE];
48 
49  /**
50  * Length of roles array.
51  */
53 
54  /**
55  * Array of assigned roles.
56  */
57  char roles[][AS_ROLE_SIZE];
59 
60 /******************************************************************************
61  * FUNCTIONS
62  ******************************************************************************/
63 
64 /**
65  * Create user with password and roles. Clear-text password will be hashed using bcrypt before
66  * sending to server. Return zero on success.
67  */
68 int
69 aerospike_create_user(aerospike* as, const as_policy_admin* policy, const char* user, const char* password, const char** roles, int roles_size);
70 
71 /**
72  * Remove user from cluster. Return zero on success.
73  */
74 int
75 aerospike_drop_user(aerospike* as, const as_policy_admin* policy, const char* user);
76 
77 /**
78  * Set user's password by user administrator. Clear-text password will be hashed using bcrypt before sending to server.
79  * Return zero on success.
80  */
81 int
82 aerospike_set_password(aerospike* as, const as_policy_admin* policy, const char* user, const char* password);
83 
84 /**
85  * Change user's password by user. Clear-text password will be hashed using bcrypt before sending to server.
86  * Return zero on success.
87  */
88 int
89 aerospike_change_password(aerospike* as, const as_policy_admin* policy, const char* user, const char* password);
90 
91 /**
92  * Add role to user's list of roles. Return zero on success.
93  */
94 int
95 aerospike_grant_roles(aerospike* as, const as_policy_admin* policy, const char* user, const char** roles, int roles_size);
96 
97 /**
98  * Remove role from user's list of roles. Return zero on success.
99  */
100 int
101 aerospike_revoke_roles(aerospike* as, const as_policy_admin* policy, const char* user, const char** roles, int roles_size);
102 
103 /**
104  * Replace user's list of roles with a new list of roles. Return zero on success.
105  */
106 int
107 aerospike_replace_roles(aerospike* as, const as_policy_admin* policy, const char* user, const char** roles, int roles_size);
108 
109 /**
110  * Retrieve roles for a given user. Return zero on success.
111  * When successful, as_user_roles_destroy() must be called to free resources.
112  */
113 int
114 aerospike_query_user(aerospike* as, const as_policy_admin* policy, const char* user, as_user_roles** user_roles);
115 
116 /**
117  * Release as_user_roles memory.
118  */
119 void
121 
122 /**
123  * Retrieve all users and their roles. Return zero on success.
124  * When successful, as_user_roles_destroy_array() must be called to free resources.
125  */
126 int
127 aerospike_query_users(aerospike* as, const as_policy_admin* policy, as_user_roles*** user_roles, int* user_roles_size);
128 
129 /**
130  * Release memory for as_user_roles array.
131  */
132 void
133 as_user_roles_destroy_array(as_user_roles** user_roles, int user_roles_size);
134 
135 /**
136  * @private
137  * Authenticate user with a server node. This is done automatically after socket open.
138  * Do not use this method directly.
139  */
140 int
141 as_authenticate(int fd, const char* user, const char* credential, int timeout_ms);