5050#include "wolfhsm/wh_auth.h"
5151
5252
53- int wh_Auth_Init (whAuthContext * context , const whAuthConfig * config )
53+ int wh_Auth_Init (whAuthContext * context , const whAuthConfig * config )
5454{
5555 int rc = 0 ;
5656
57- if ( (context == NULL ) ||
58- (config == NULL ) ) {
57+ if ((context == NULL ) || (config == NULL )) {
5958 return WH_ERROR_BADARGS ;
6059 }
6160
62- context -> cb = config -> cb ;
61+ context -> cb = config -> cb ;
6362 context -> context = config -> context ;
6463 memset (& context -> user , 0 , sizeof (whAuthUser ));
6564
6665 if (context -> cb != NULL && context -> cb -> Init != NULL ) {
6766 rc = context -> cb -> Init (context -> context , config -> config );
6867 if (rc != 0 ) {
69- context -> cb = NULL ;
68+ context -> cb = NULL ;
7069 context -> context = NULL ;
7170 }
7271 }
@@ -77,8 +76,7 @@ int wh_Auth_Init(whAuthContext* context, const whAuthConfig *config)
7776
7877int wh_Auth_Cleanup (whAuthContext * context )
7978{
80- if ( (context == NULL ) ||
81- (context -> cb == NULL ) ) {
79+ if ((context == NULL ) || (context -> cb == NULL )) {
8280 return WH_ERROR_BADARGS ;
8381 }
8482
@@ -93,39 +91,36 @@ int wh_Auth_Cleanup(whAuthContext* context)
9391 * The result of the login attempt is stored in loggedIn -- 1 for success,
9492 * 0 for failure */
9593int wh_Auth_Login (whAuthContext * context , uint8_t client_id ,
96- whAuthMethod method , const char * username ,
97- const void * auth_data ,
98- uint16_t auth_data_len ,
99- int * loggedIn )
94+ whAuthMethod method , const char * username ,
95+ const void * auth_data , uint16_t auth_data_len , int * loggedIn )
10096{
101- int rc ;
102- whUserId out_user_id ;
97+ int rc ;
98+ whUserId out_user_id ;
10399 whAuthPermissions out_permissions ;
104100
105101 if (loggedIn == NULL ) {
106102 return WH_ERROR_BADARGS ;
107103 }
108104 * loggedIn = 0 ;
109105
110- if ( (context == NULL ) ||
111- (context -> cb == NULL ) ||
112- (context -> cb -> Login == NULL ) ) {
106+ if ((context == NULL ) || (context -> cb == NULL ) ||
107+ (context -> cb -> Login == NULL )) {
113108 return WH_ERROR_BADARGS ;
114109 }
115110
116111 /* allowing only one user logged in to an open connection at a time */
117112 if (context -> user .user_id != WH_USER_ID_INVALID ) {
118113 * loggedIn = 0 ;
119- rc = WH_ERROR_OK ; /* login attempt happened but failed */
114+ rc = WH_ERROR_OK ; /* login attempt happened but failed */
120115 }
121116 else {
122- rc = context -> cb -> Login (context -> context , client_id , method ,
123- username , auth_data , auth_data_len , & out_user_id ,
124- & out_permissions , loggedIn );
117+ rc = context -> cb -> Login (context -> context , client_id , method , username ,
118+ auth_data , auth_data_len , & out_user_id ,
119+ & out_permissions , loggedIn );
125120 if (rc == WH_ERROR_OK && * loggedIn ) {
126- context -> user .user_id = out_user_id ;
121+ context -> user .user_id = out_user_id ;
127122 context -> user .permissions = out_permissions ;
128- context -> user .is_active = true;
123+ context -> user .is_active = true;
129124 }
130125 }
131126
@@ -137,9 +132,8 @@ int wh_Auth_Logout(whAuthContext* context, whUserId user_id)
137132{
138133 int rc ;
139134
140- if ( (context == NULL ) ||
141- (context -> cb == NULL ) ||
142- (context -> cb -> Logout == NULL ) ) {
135+ if ((context == NULL ) || (context -> cb == NULL ) ||
136+ (context -> cb -> Logout == NULL )) {
143137 return WH_ERROR_BADARGS ;
144138 }
145139
@@ -157,97 +151,97 @@ int wh_Auth_Logout(whAuthContext* context, whUserId user_id)
157151/* Check on request authorization and action permissions for current user
158152 * logged in */
159153int wh_Auth_CheckRequestAuthorization (whAuthContext * context , uint16_t group ,
160- uint16_t action )
154+ uint16_t action )
161155{
162156 uint16_t user_id = context -> user .user_id ;
163- int rc ;
157+ int rc ;
164158
165159 /* @TODO add logging call here and with resulting return value */
166160
167161 rc = context -> cb -> CheckRequestAuthorization (context -> context , user_id ,
168- group , action );
162+ group , action );
169163 return rc ;
170164}
171165
172166
173167/* Check on key ID use after request has been parsed */
174168int wh_Auth_CheckKeyAuthorization (whAuthContext * context , uint32_t key_id ,
175- uint16_t action )
169+ uint16_t action )
176170{
177171 uint16_t user_id = context -> user .user_id ;
178172
179173 return context -> cb -> CheckKeyAuthorization (context -> context , user_id , key_id ,
180- action );
174+ action );
181175}
182176
183- /********** API That Interact With User Database *******************************/
177+ /********** API That Interact With User Database
178+ * *******************************/
184179
185180int wh_Auth_UserAdd (whAuthContext * context , const char * username ,
186- whUserId * out_user_id , whAuthPermissions permissions ,
187- whAuthMethod method , const void * credentials ,
188- uint16_t credentials_len )
181+ whUserId * out_user_id , whAuthPermissions permissions ,
182+ whAuthMethod method , const void * credentials ,
183+ uint16_t credentials_len )
189184{
190- if ( (context == NULL ) ||
191- (context -> cb == NULL ) ||
192- (context -> cb -> UserAdd == NULL ) ) {
185+ if ((context == NULL ) || (context -> cb == NULL ) ||
186+ (context -> cb -> UserAdd == NULL )) {
193187 return WH_ERROR_BADARGS ;
194188 }
195189
196- return context -> cb -> UserAdd (context -> context , username , out_user_id , permissions ,
197- method , credentials , credentials_len );
190+ return context -> cb -> UserAdd (context -> context , username , out_user_id ,
191+ permissions , method , credentials ,
192+ credentials_len );
198193}
199194
200195
201196int wh_Auth_UserDelete (whAuthContext * context , whUserId user_id )
202197{
203- if ( (context == NULL ) ||
204- (context -> cb == NULL ) ||
205- (context -> cb -> UserDelete == NULL ) ) {
198+ if ((context == NULL ) || (context -> cb == NULL ) ||
199+ (context -> cb -> UserDelete == NULL )) {
206200 return WH_ERROR_BADARGS ;
207201 }
208202
209- return context -> cb -> UserDelete (context -> context , context -> user .user_id , user_id );
203+ return context -> cb -> UserDelete (context -> context , context -> user .user_id ,
204+ user_id );
210205}
211206
212207
213208int wh_Auth_UserSetPermissions (whAuthContext * context , whUserId user_id ,
214- whAuthPermissions permissions )
209+ whAuthPermissions permissions )
215210{
216- if ( (context == NULL ) ||
217- (context -> cb == NULL ) ||
218- (context -> cb -> UserSetPermissions == NULL ) ) {
211+ if ((context == NULL ) || (context -> cb == NULL ) ||
212+ (context -> cb -> UserSetPermissions == NULL )) {
219213 return WH_ERROR_BADARGS ;
220214 }
221215
222- return context -> cb -> UserSetPermissions (context -> context ,
223- context -> user .user_id , user_id , permissions );
216+ return context -> cb -> UserSetPermissions (
217+ context -> context , context -> user .user_id , user_id , permissions );
224218}
225219
226- int wh_Auth_UserGet (whAuthContext * context , const char * username , whUserId * out_user_id ,
227- whAuthPermissions * out_permissions )
220+ int wh_Auth_UserGet (whAuthContext * context , const char * username ,
221+ whUserId * out_user_id , whAuthPermissions * out_permissions )
228222{
229- if ( (context == NULL ) ||
230- (context -> cb == NULL ) ||
231- (context -> cb -> UserGet == NULL ) ) {
223+ if ((context == NULL ) || (context -> cb == NULL ) ||
224+ (context -> cb -> UserGet == NULL )) {
232225 return WH_ERROR_BADARGS ;
233226 }
234227
235- return context -> cb -> UserGet (context -> context , username , out_user_id , out_permissions );
228+ return context -> cb -> UserGet (context -> context , username , out_user_id ,
229+ out_permissions );
236230}
237231
238232int wh_Auth_UserSetCredentials (whAuthContext * context , whUserId user_id ,
239- whAuthMethod method ,
240- const void * current_credentials , uint16_t current_credentials_len ,
241- const void * new_credentials , uint16_t new_credentials_len )
233+ whAuthMethod method ,
234+ const void * current_credentials ,
235+ uint16_t current_credentials_len ,
236+ const void * new_credentials ,
237+ uint16_t new_credentials_len )
242238{
243- if ( (context == NULL ) ||
244- (context -> cb == NULL ) ||
245- (context -> cb -> UserSetCredentials == NULL ) ) {
239+ if ((context == NULL ) || (context -> cb == NULL ) ||
240+ (context -> cb -> UserSetCredentials == NULL )) {
246241 return WH_ERROR_BADARGS ;
247242 }
248243
249- return context -> cb -> UserSetCredentials (context -> context , user_id , method ,
250- current_credentials , current_credentials_len ,
251- new_credentials , new_credentials_len );
244+ return context -> cb -> UserSetCredentials (
245+ context -> context , user_id , method , current_credentials ,
246+ current_credentials_len , new_credentials , new_credentials_len );
252247}
253-
0 commit comments