-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.c
742 lines (605 loc) · 25.1 KB
/
auth.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
/*
*********************************************************************************************************
* uC/Common
* Common Features for Micrium Stacks
*
* Copyright 2013-2020 Silicon Laboratories Inc. www.silabs.com
*
* SPDX-License-Identifier: APACHE-2.0
*
* This software is subject to an open source license and is distributed by
* Silicon Laboratories Inc. pursuant to the terms of the Apache License,
* Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
*
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* uC/Common - Authentication Module (Auth)
*
* Filename : auth.c
* Version : V1.02.00
*********************************************************************************************************
* Note(s) : (1) 'goto' statements were used in this software module. Their usage
* is restricted to cleanup purposes in exceptional program flow (e.g.
* error handling), in compliance with CERT MEM12-C and MISRA C:2012
* rules 15.2, 15.3 and 15.4.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*********************************************************************************************************
*/
#include <lib_str.h>
#include "kal.h"
#include "auth.h"
/*
*********************************************************************************************************
*********************************************************************************************************
* LOCAL DATA TYPES
*********************************************************************************************************
*********************************************************************************************************
*/
typedef struct auth_user_credentials { /* --------------- AUTH USER CREDENTIALS -------------- */
AUTH_USER User; /* User structure. */
CPU_CHAR Pwd[AUTH_PWD_MAX_LENGTH]; /* Password for this user. */
} AUTH_USER_CREDENTIALS;
/*
*********************************************************************************************************
*********************************************************************************************************
* GLOBAL VARIABLES
*********************************************************************************************************
*********************************************************************************************************
*/
AUTH_USER Auth_RootUser = {
{ 'r', 'o', 'o', 't', '\0' },
AUTH_RIGHT_ROOT
};
/*
*********************************************************************************************************
*********************************************************************************************************
* LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*********************************************************************************************************
*/
static KAL_LOCK_HANDLE Auth_LockHandle;
static CPU_SIZE_T Auth_UserNbr = 1;
static AUTH_USER_CREDENTIALS Auth_UsersCredentials[AUTH_NB_USERS_MAX] = {
{
{
{ 'r', 'o', 'o', 't', '\0' },
AUTH_RIGHT_ROOT
},
{ 'a', 'd', 'm', 'i', 'n', '\0' }
}
};
/*
*********************************************************************************************************
*********************************************************************************************************
* LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*********************************************************************************************************
*/
static CPU_BOOLEAN Auth_GetUserHandler (const CPU_CHAR *p_name,
AUTH_USER *p_user,
RTOS_ERR *p_err);
/*
*********************************************************************************************************
*********************************************************************************************************
* GLOBAL FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* Auth_Init()
*
* Description : (1) Initialize Authentication module:
*
* (a) Create Lock.
*
* Argument(s) : p_err Pointer to variable that will receive the return error code from this function :
*
* --------------- RETURNED BY KAL_LockCreate() --------------
* See KAL_LockCreate() for additional return error codes.
*
* Return(s) : DEF_OK, if initialization was successful.
* DEF_FAIL, otherwise.
*
* Note(s) : none.
*********************************************************************************************************
*/
CPU_BOOLEAN Auth_Init (RTOS_ERR *p_err)
{
CPU_BOOLEAN res = DEF_OK;
Auth_LockHandle = KAL_LockCreate("Auth Lock",
KAL_OPT_CREATE_NONE,
p_err);
if (*p_err != RTOS_ERR_NONE) {
res = DEF_FAIL;
}
return (res);
}
/*
*********************************************************************************************************
* Auth_CreateUser()
*
* Description : Create a user and fill the user structure provided.
*
* Argument(s) : p_name Pointer to user name string.
*
* p_pwd Pointer to password string.
*
* p_user Pointer to user object to fill.
*
* p_err Pointer to variable that will receive the return error code from this function :
*
* RTOS_ERR_NONE
* RTOS_ERR_INVALID_STR_LEN
* RTOS_ERR_NO_MORE_RSRC
* RTOS_ERR_ALREADY_EXISTS
*
* ----------- RETURNED BY KAL_LockAcquire/Release() ---------
* See KAL_LockAcquire/Release() for additional return error codes.
*
* Return(s) : DEF_OK, if user created successfully.
* DEF_FAIL, otherwise.
*
* Note(s) : None.
*********************************************************************************************************
*/
CPU_BOOLEAN Auth_CreateUser (const CPU_CHAR *p_name,
const CPU_CHAR *p_pwd,
AUTH_USER *p_user,
RTOS_ERR *p_err)
{
AUTH_USER_CREDENTIALS *p_user_cred;
CPU_SIZE_T name_len;
CPU_SIZE_T pwd_len;
CPU_SIZE_T i;
CPU_INT16S cmp_result;
CPU_BOOLEAN result = DEF_FAIL;
RTOS_ERR local_err;
KAL_LockAcquire(Auth_LockHandle, KAL_OPT_PEND_NONE, KAL_TIMEOUT_INFINITE, p_err);
if (*p_err != RTOS_ERR_NONE) {
goto exit;
}
name_len = Str_Len_N(p_name, AUTH_NAME_MAX_LENGTH + 1);
pwd_len = Str_Len_N(p_pwd, AUTH_PWD_MAX_LENGTH + 1);
if (name_len > AUTH_NAME_MAX_LENGTH) {
*p_err = RTOS_ERR_INVALID_STR_LEN;
goto exit_release;
}
if (pwd_len > AUTH_PWD_MAX_LENGTH) {
*p_err = RTOS_ERR_INVALID_STR_LEN;
goto exit_release;
}
if (Auth_UserNbr >= AUTH_NB_USERS_MAX) {
*p_err = RTOS_ERR_NO_MORE_RSRC;
goto exit_release;
}
for (i = 0; i < Auth_UserNbr; ++i) {
cmp_result = Str_Cmp_N(Auth_UsersCredentials[i].User.Name, p_name, name_len);
if (cmp_result == 0) {
*p_err = RTOS_ERR_ALREADY_EXISTS;
goto exit_release;
}
}
p_user_cred = &Auth_UsersCredentials[Auth_UserNbr];
++Auth_UserNbr;
name_len = DEF_MIN(name_len + 1, AUTH_NAME_MAX_LENGTH);
pwd_len = DEF_MIN(pwd_len + 1, AUTH_PWD_MAX_LENGTH);
(void)Str_Copy_N(p_user_cred->User.Name,
p_name,
name_len);
(void)Str_Copy_N(p_user_cred->Pwd,
p_pwd,
pwd_len);
p_user_cred->User.Rights = AUTH_RIGHT_NONE;
(void)Str_Copy_N(p_user->Name,
p_name,
name_len);
p_user->Rights = AUTH_RIGHT_NONE;
result = DEF_OK;
*p_err = RTOS_ERR_NONE;
exit_release:
KAL_LockRelease(Auth_LockHandle, &local_err);
(void)local_err;
exit:
return (result);
}
/*
*********************************************************************************************************
* Auth_ChangePassword()
*
* Description : Change the user's password.
*
* Argument(s) : p_user Pointer to user object.
*
* p_pwd Pointer to the new password.
*
* p_as_user Pointer to user that have the permission level to do the action.
* Must be the same as p_user or the ROOT user.
*
* p_err Pointer to variable that will receive the return error code from this function :
*
* RTOS_ERR_NONE
* RTOS_ERR_INVALID_STR_LEN
* RTOS_ERR_PERMISSION
* RTOS_ERR_NOT_FOUND
*
* ----------- RETURNED BY KAL_LockAcquire/Release() ---------
* See KAL_LockAcquire/Release() for additional return error codes.
*
* Return(s) : DEF_OK, if password changed successfully.
* DEF_FAIL, otherwise.
*
* Note(s) : none.
*********************************************************************************************************
*/
#if 0
CPU_BOOLEAN Auth_ChangePassword ( AUTH_USER *p_user,
const CPU_CHAR *p_pwd,
const AUTH_USER *p_as_user,
RTOS_ERR *p_err)
{
CPU_SIZE_T name_len;
CPU_SIZE_T pwd_len;
CPU_SIZE_T i;
CPU_INT16S cmp_result;
CPU_BOOLEAN result = DEF_FAIL;
RTOS_ERR local_err;
KAL_LockAcquire(Auth_LockHandle, KAL_OPT_PEND_NONE, KAL_TIMEOUT_INFINITE, p_err);
if (*p_err != RTOS_ERR_NONE) {
goto exit;
}
name_len = Str_Len_N(p_user->Name, AUTH_NAME_MAX_LENGTH + 1);
pwd_len = Str_Len_N(p_pwd, AUTH_PWD_MAX_LENGTH + 1);
if (pwd_len > AUTH_PWD_MAX_LENGTH) {
*p_err = RTOS_ERR_INVALID_STR_LEN;
goto exit_release;
}
if ((Str_Cmp(p_as_user->Name, p_user->Name) != 0) &&
(DEF_BIT_IS_CLR(p_as_user->Rights, AUTH_RIGHT_ROOT) == DEF_YES)) {
*p_err = RTOS_ERR_PERMISSION;
goto exit_release;
}
for (i = 0; i < Auth_UserNbr; ++i) {
cmp_result = Str_Cmp_N(Auth_UsersCredentials[i].User.Name, p_user->Name, name_len);
if (cmp_result == 0) {
(void)Str_Copy_N(Auth_UsersCredentials[i].Pwd,
p_pwd,
pwd_len);
result = DEF_OK;
*p_err = RTOS_ERR_NONE;
goto exit_release;
}
}
*p_err = RTOS_ERR_NOT_FOUND;
exit_release:
KAL_LockRelease(Auth_LockHandle, &local_err);
(void)local_err;
exit:
return (result);
}
#endif
/*
*********************************************************************************************************
* Auth_GetUser()
*
* Description : Get the user structure with the given name.
*
* Argument(s) : p_name Pointer to user name string to retrieve.
*
* p_user Pointer to user object that will be filled with the data retrieved.
*
* p_err Pointer to variable that will receive the return error code from this function :
*
* RTOS_ERR_NONE
*
* ----------- RETURNED BY KAL_LockAcquire/Release() ---------
* See KAL_LockAcquire/Release() for additional return error codes.
*
* ------------ RETURNED BY Auth_GetUserHandler() ------------
* See Auth_GetUserHandler() for additional return error codes.
*
* Return(s) : DEF_OK, if user was successfully found.
* DEF_FAIL, otherwise.
*
* Note(s) : none.
*********************************************************************************************************
*/
CPU_BOOLEAN Auth_GetUser (const CPU_CHAR *p_name,
AUTH_USER *p_user,
RTOS_ERR *p_err)
{
CPU_BOOLEAN result;
RTOS_ERR local_err;
KAL_LockAcquire(Auth_LockHandle, KAL_OPT_PEND_NONE, KAL_TIMEOUT_INFINITE, p_err);
if (*p_err != RTOS_ERR_NONE) {
result = DEF_FAIL;
goto exit;
}
result = Auth_GetUserHandler(p_name, p_user, p_err);
KAL_LockRelease(Auth_LockHandle, &local_err);
(void)local_err;
exit:
return (result);
}
/*
*********************************************************************************************************
* Auth_ValidateCredentials()
*
* Description : Validates the user and password tuple with known users.
*
* Argument(s) : p_name Pointer to user name string.
*
* p_pwd Pointer to password string.
*
* p_user Pointer to user object that will be filled with the data retrieved.
*
* p_err Pointer to variable that will receive the return error code from this function :
*
* RTOS_ERR_NONE
* RTOS_ERR_INVALID_STR_LEN
* RTOS_ERR_INVALID_CREDENTIALS
*
* ----------- RETURNED BY KAL_LockAcquire/Release() ---------
* See KAL_LockAcquire/Release() for additional return error codes.
*
* Return(s) : DEF_OK, if credentials are valid.
* DEF_FAIL, otherwise.
*
* Note(s) : none.
*********************************************************************************************************
*/
CPU_BOOLEAN Auth_ValidateCredentials (const CPU_CHAR *p_name,
const CPU_CHAR *p_pwd,
AUTH_USER *p_user,
RTOS_ERR *p_err)
{
CPU_SIZE_T name_len;
CPU_SIZE_T pwd_len;
CPU_SIZE_T i;
CPU_INT16S cmp_result;
CPU_BOOLEAN result = DEF_FAIL;
RTOS_ERR local_err;
KAL_LockAcquire(Auth_LockHandle, KAL_OPT_PEND_NONE, KAL_TIMEOUT_INFINITE, p_err);
if (*p_err != RTOS_ERR_NONE) {
goto exit;
}
name_len = Str_Len_N(p_name, AUTH_NAME_MAX_LENGTH + 1);
pwd_len = Str_Len_N(p_pwd, AUTH_PWD_MAX_LENGTH + 1);
if (name_len > AUTH_NAME_MAX_LENGTH) {
*p_err = RTOS_ERR_INVALID_STR_LEN;
goto exit_release;
}
if (pwd_len > AUTH_PWD_MAX_LENGTH) {
*p_err = RTOS_ERR_INVALID_STR_LEN;
goto exit_release;
}
for (i = 0; i < Auth_UserNbr; ++i) {
cmp_result = Str_Cmp_N(Auth_UsersCredentials[i].User.Name, p_name, name_len);
if (cmp_result == 0) {
cmp_result = Str_Cmp_N(Auth_UsersCredentials[i].Pwd, p_pwd, pwd_len);
if (cmp_result == 0) {
(void)Str_Copy_N(p_user->Name, p_name, name_len);
p_user->Rights = Auth_UsersCredentials[i].User.Rights;
result = DEF_OK;
*p_err = RTOS_ERR_NONE;
goto exit_release;
}
break;
}
}
*p_err = RTOS_ERR_INVALID_CREDENTIALS;
exit_release:
KAL_LockRelease(Auth_LockHandle, &local_err);
(void)local_err;
exit:
return (result);
}
/*
*********************************************************************************************************
* Auth_GrantRight()
*
* Description : Grants a right to a user as another user (limits the rights granted).
*
* Argument(s) : right New right to grant.
*
* p_user Pointer to user object that will received the new right.
*
* p_as_user Pointer to user that has the permission level to do the action.
*
* p_err Pointer to variable that will receive the return error code from this function :
*
* RTOS_ERR_NONE
* RTOS_ERR_PERMISSION
* RTOS_ERR_NOT_FOUND
*
* ----------- RETURNED BY KAL_LockAcquire/Release() ---------
* See KAL_LockAcquire/Release() for additional return error codes.
*
* ------------ RETURNED BY Auth_GetUserHandler() ------------
* See Auth_GetUserHandler() for additional return error codes.
*
* Return(s) : DEF_OK, if right was granted successfully.
* DEF_FAIL, otherwise.
*
* Note(s) : none.
*********************************************************************************************************
*/
CPU_BOOLEAN Auth_GrantRight (AUTH_RIGHT right,
AUTH_USER *p_user,
AUTH_USER *p_as_user,
RTOS_ERR *p_err)
{
CPU_SIZE_T name_len;
CPU_SIZE_T i;
CPU_INT16S cmp_result;
CPU_BOOLEAN result = DEF_FAIL;
RTOS_ERR local_err;
KAL_LockAcquire(Auth_LockHandle, KAL_OPT_PEND_NONE, KAL_TIMEOUT_INFINITE, p_err);
if (*p_err != RTOS_ERR_NONE) {
goto exit;
}
(void)Auth_GetUserHandler(p_as_user->Name, p_as_user, p_err);
if (*p_err != RTOS_ERR_NONE) {
goto exit_release;
}
if (((DEF_BIT_IS_SET(p_as_user->Rights, AUTH_RIGHT_MNG) == DEF_NO) ||
(DEF_BIT_IS_SET(p_as_user->Rights, right) == DEF_NO)) &&
(DEF_BIT_IS_SET(p_as_user->Rights, AUTH_RIGHT_ROOT) == DEF_NO)) {
*p_err = RTOS_ERR_PERMISSION;
goto exit_release;
}
name_len = Str_Len_N(p_user->Name, AUTH_NAME_MAX_LENGTH + 1);
for (i = 0; i < Auth_UserNbr; ++i) {
cmp_result = Str_Cmp_N(Auth_UsersCredentials[i].User.Name, p_user->Name, name_len);
if (cmp_result == 0) {
DEF_BIT_SET(Auth_UsersCredentials[i].User.Rights, right);
p_user->Rights = Auth_UsersCredentials[i].User.Rights;
result = DEF_OK;
*p_err = RTOS_ERR_NONE;
goto exit_release;
}
}
*p_err = RTOS_ERR_NOT_FOUND;
exit_release:
KAL_LockRelease(Auth_LockHandle, &local_err);
(void)local_err;
exit:
return (result);
}
/*
*********************************************************************************************************
* Auth_RevokeRight()
*
* Description : Revokes the right of a specified user.
*
* Argument(s) : right Right to revoke.
*
* p_user Pointer to user object which right will be revoked.
*
* p_as_user Pointer to user that has the permission level to do the action.
*
* p_err Pointer to variable that will receive the return error code from this function :
*
* RTOS_ERR_NONE
* RTOS_ERR_PERMISSION
* RTOS_ERR_NOT_FOUND
*
* ----------- RETURNED BY KAL_LockAcquire/Release() ---------
* See KAL_LockAcquire/Release() for additional return error codes.
*
* ------------ RETURNED BY Auth_GetUserHandler() ------------
* See Auth_GetUserHandler() for additional return error codes.
*
* Return(s) : DEF_OK, if right was revoked successfully.
* DEF_FAIL, otherwise.
*
* Note(s) : none.
*********************************************************************************************************
*/
CPU_BOOLEAN Auth_RevokeRight (AUTH_RIGHT right,
AUTH_USER *p_user,
AUTH_USER *p_as_user,
RTOS_ERR *p_err)
{
CPU_SIZE_T name_len;
CPU_SIZE_T i;
CPU_INT16S cmp_result;
CPU_BOOLEAN result = DEF_FAIL;
RTOS_ERR local_err;
KAL_LockAcquire(Auth_LockHandle, KAL_OPT_PEND_NONE, KAL_TIMEOUT_INFINITE, p_err);
if (*p_err != RTOS_ERR_NONE) {
goto exit;
}
(void)Auth_GetUserHandler(p_as_user->Name, p_as_user, p_err);
if (*p_err != RTOS_ERR_NONE) {
goto exit_release;
}
/* This implementation allows the ROOT user ... */
/* ... to revoke it's own ROOT right. */
if (((DEF_BIT_IS_SET(p_as_user->Rights, AUTH_RIGHT_MNG) == DEF_NO) ||
(DEF_BIT_IS_SET(p_as_user->Rights, right) == DEF_NO) ) &&
(DEF_BIT_IS_SET(p_as_user->Rights, AUTH_RIGHT_ROOT) == DEF_NO ) ) {
*p_err = RTOS_ERR_PERMISSION;
goto exit_release;
}
name_len = Str_Len_N(p_user->Name, AUTH_NAME_MAX_LENGTH + 1);
for (i = 0; i < Auth_UserNbr; ++i) {
cmp_result = Str_Cmp_N(Auth_UsersCredentials[i].User.Name, p_user->Name, name_len);
if (cmp_result == 0) {
DEF_BIT_CLR(Auth_UsersCredentials[i].User.Rights, right);
p_user->Rights = Auth_UsersCredentials[i].User.Rights;
result = DEF_OK;
*p_err = RTOS_ERR_NONE;
goto exit_release;
}
}
*p_err = RTOS_ERR_NOT_FOUND;
exit_release:
KAL_LockRelease(Auth_LockHandle, &local_err);
(void)local_err;
exit:
return (result);
}
/*
*********************************************************************************************************
*********************************************************************************************************
* LOCAL FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* Auth_GetUserHandler()
*
* Description : Get the user structure with the given name.
*
* Argument(s) : p_name Pointer to user name string to retrieve.
*
* p_user Pointer to user object that will be filled with the data retrieved.
*
* p_err Pointer to variable that will receive the return error code from this function :
*
* RTOS_ERR_NONE
* RTOS_ERR_NOT_FOUND
*
* Return(s) : DEF_OK, if user was successfully found.
* DEF_FAIL, otherwise.
*
* Note(s) : None.
*********************************************************************************************************
*/
static CPU_BOOLEAN Auth_GetUserHandler (const CPU_CHAR *p_name,
AUTH_USER *p_user,
RTOS_ERR *p_err)
{
CPU_SIZE_T name_len;
CPU_SIZE_T i;
CPU_INT16S cmp_result;
CPU_BOOLEAN result;
name_len = Str_Len_N(p_name, AUTH_NAME_MAX_LENGTH + 1);
for (i = 0; i < Auth_UserNbr; ++i) {
cmp_result = Str_Cmp_N(Auth_UsersCredentials[i].User.Name, p_user->Name, name_len);
if (cmp_result == 0) {
(void)Str_Copy_N(p_user->Name,
Auth_UsersCredentials[i].User.Name,
name_len);
p_user->Rights = Auth_UsersCredentials[i].User.Rights;
result = DEF_OK;
*p_err = RTOS_ERR_NONE;
goto exit;
}
}
result = DEF_FAIL;
*p_err = RTOS_ERR_NOT_FOUND;
exit:
return (result);
}