Skip to content

Commit 62fe4eb

Browse files
run git-clang-format and checking format changes
1 parent 2d953d5 commit 62fe4eb

14 files changed

Lines changed: 1267 additions & 1186 deletions

examples/posix/wh_posix_server/wh_posix_server_cfg.c

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -656,18 +656,17 @@ int wh_PosixServer_ExampleNvmConfig(void* conf, const char* nvmInitFilePath)
656656

657657
/* Default auth callback structure */
658658
static whAuthCb default_auth_cb = {
659-
.Init = wh_AuthBase_Init,
660-
.Cleanup = wh_AuthBase_Cleanup,
661-
.Login = wh_AuthBase_Login,
662-
.Logout = wh_AuthBase_Logout,
659+
.Init = wh_AuthBase_Init,
660+
.Cleanup = wh_AuthBase_Cleanup,
661+
.Login = wh_AuthBase_Login,
662+
.Logout = wh_AuthBase_Logout,
663663
.CheckRequestAuthorization = wh_AuthBase_CheckRequestAuthorization,
664-
.CheckKeyAuthorization = wh_AuthBase_CheckKeyAuthorization,
665-
.UserAdd = wh_AuthBase_UserAdd,
666-
.UserDelete = wh_AuthBase_UserDelete,
667-
.UserSetPermissions = wh_AuthBase_UserSetPermissions,
668-
.UserGet = wh_AuthBase_UserGet,
669-
.UserSetCredentials = wh_AuthBase_UserSetCredentials
670-
};
664+
.CheckKeyAuthorization = wh_AuthBase_CheckKeyAuthorization,
665+
.UserAdd = wh_AuthBase_UserAdd,
666+
.UserDelete = wh_AuthBase_UserDelete,
667+
.UserSetPermissions = wh_AuthBase_UserSetPermissions,
668+
.UserGet = wh_AuthBase_UserGet,
669+
.UserSetCredentials = wh_AuthBase_UserSetCredentials};
671670
static whAuthContext auth_ctx = {0};
672671

673672
/**
@@ -678,21 +677,23 @@ static whAuthContext auth_ctx = {0};
678677
* For production use, a proper auth backend should be implemented.
679678
*
680679
* @param[in] conf Pointer to the server configuration
681-
* @return int Returns WH_ERROR_OK on success, or a negative error code on failure
680+
* @return int Returns WH_ERROR_OK on success, or a negative error code on
681+
* failure
682682
*/
683683
int wh_PosixServer_ExampleAuthConfig(void* conf)
684684
{
685-
int rc;
685+
int rc;
686686
whServerConfig* s_conf = (whServerConfig*)conf;
687-
static void* auth_backend_context = NULL; /* No backend context needed for stubs */
687+
static void* auth_backend_context =
688+
NULL; /* No backend context needed for stubs */
688689
static whAuthConfig auth_config = {0};
689690

690691
if (s_conf == NULL) {
691692
return WH_ERROR_BADARGS;
692693
}
693694

694695
/* Set up the auth config with default callbacks */
695-
auth_config.cb = &default_auth_cb;
696+
auth_config.cb = &default_auth_cb;
696697
auth_config.context = auth_backend_context;
697698

698699
/* Initialize the auth context */
@@ -705,7 +706,8 @@ int wh_PosixServer_ExampleAuthConfig(void* conf)
705706
/* Set the auth context in the server configuration */
706707
s_conf->auth = &auth_ctx;
707708

708-
WOLFHSM_CFG_PRINTF("Default auth context configured (stub implementation)\n");
709+
WOLFHSM_CFG_PRINTF(
710+
"Default auth context configured (stub implementation)\n");
709711

710712
return WH_ERROR_OK;
711713
}

src/wh_auth.c

Lines changed: 59 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,22 @@
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

7877
int 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 */
9593
int 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 */
159153
int 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 */
174168
int 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

185180
int 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

201196
int 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

213208
int 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

238232
int 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

Comments
 (0)