auth.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. *********************************************************************************************************
  3. * uC/Common
  4. * Common Features for Micrium Stacks
  5. *
  6. * Copyright 2013-2020 Silicon Laboratories Inc. www.silabs.com
  7. *
  8. * SPDX-License-Identifier: APACHE-2.0
  9. *
  10. * This software is subject to an open source license and is distributed by
  11. * Silicon Laboratories Inc. pursuant to the terms of the Apache License,
  12. * Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
  13. *
  14. *********************************************************************************************************
  15. */
  16. /*
  17. *********************************************************************************************************
  18. *
  19. * uC/Common - Authentication Module (Auth)
  20. *
  21. * Filename : auth.h
  22. * Version : V1.02.00
  23. *********************************************************************************************************
  24. */
  25. /*
  26. *********************************************************************************************************
  27. *********************************************************************************************************
  28. * MODULE
  29. *
  30. * Note(s) : (1) This library header file is protected from multiple pre-processor inclusion through
  31. * use of the library module present pre-processor macro definition.
  32. *********************************************************************************************************
  33. *********************************************************************************************************
  34. */
  35. #ifndef AUTH_MODULE_PRESENT /* See Note #1. */
  36. #define AUTH_MODULE_PRESENT
  37. /*
  38. *********************************************************************************************************
  39. *********************************************************************************************************
  40. * INCLUDE FILES
  41. *********************************************************************************************************
  42. *********************************************************************************************************
  43. */
  44. #include <lib_mem.h>
  45. #include "common_err.h"
  46. /*
  47. *********************************************************************************************************
  48. *********************************************************************************************************
  49. * DEFINES
  50. *********************************************************************************************************
  51. *********************************************************************************************************
  52. */
  53. #define AUTH_PWD_MAX_LENGTH 32
  54. #define AUTH_NAME_MAX_LENGTH 32
  55. #define AUTH_NB_USERS_MAX 10
  56. #define AUTH_RIGHT_NONE DEF_BIT_NONE
  57. #define AUTH_RIGHT_0 DEF_BIT_00
  58. #define AUTH_RIGHT_1 DEF_BIT_01
  59. #define AUTH_RIGHT_2 DEF_BIT_02
  60. #define AUTH_RIGHT_3 DEF_BIT_03
  61. #define AUTH_RIGHT_4 DEF_BIT_04
  62. #define AUTH_RIGHT_5 DEF_BIT_05
  63. #define AUTH_RIGHT_6 DEF_BIT_06
  64. #define AUTH_RIGHT_7 DEF_BIT_07
  65. #define AUTH_RIGHT_8 DEF_BIT_08
  66. #define AUTH_RIGHT_9 DEF_BIT_09
  67. #define AUTH_RIGHT_10 DEF_BIT_10
  68. #define AUTH_RIGHT_11 DEF_BIT_11
  69. #define AUTH_RIGHT_12 DEF_BIT_12
  70. #define AUTH_RIGHT_13 DEF_BIT_13
  71. #define AUTH_RIGHT_14 DEF_BIT_14
  72. #define AUTH_RIGHT_15 DEF_BIT_15
  73. #define AUTH_RIGHT_16 DEF_BIT_16
  74. #define AUTH_RIGHT_17 DEF_BIT_17
  75. #define AUTH_RIGHT_18 DEF_BIT_18
  76. #define AUTH_RIGHT_19 DEF_BIT_19
  77. #define AUTH_RIGHT_20 DEF_BIT_20
  78. #define AUTH_RIGHT_21 DEF_BIT_21
  79. #define AUTH_RIGHT_22 DEF_BIT_22
  80. #define AUTH_RIGHT_23 DEF_BIT_23
  81. #define AUTH_RIGHT_24 DEF_BIT_24
  82. #define AUTH_RIGHT_25 DEF_BIT_25
  83. #define AUTH_RIGHT_26 DEF_BIT_26
  84. #define AUTH_RIGHT_27 DEF_BIT_27
  85. #define AUTH_RIGHT_RSVD_1 DEF_BIT_28
  86. #define AUTH_RIGHT_RSVD_2 DEF_BIT_29
  87. #define AUTH_RIGHT_MNG DEF_BIT_30
  88. #define AUTH_RIGHT_ROOT DEF_BIT_31
  89. /*
  90. *********************************************************************************************************
  91. *********************************************************************************************************
  92. * DATA TYPES
  93. *********************************************************************************************************
  94. *********************************************************************************************************
  95. */
  96. typedef CPU_INT32U AUTH_RIGHT; /* Auth right is a 32-bit bitmap. */
  97. typedef struct auth_user { /* --------------------- AUTH USER -------------------- */
  98. CPU_CHAR Name[AUTH_NAME_MAX_LENGTH]; /* Name of the user. */
  99. AUTH_RIGHT Rights; /* Rights associated to this user. */
  100. } AUTH_USER;
  101. /*
  102. *********************************************************************************************************
  103. *********************************************************************************************************
  104. * GLOBAL VARIABLES
  105. *********************************************************************************************************
  106. *********************************************************************************************************
  107. */
  108. extern AUTH_USER Auth_RootUser;
  109. /*
  110. *********************************************************************************************************
  111. *********************************************************************************************************
  112. * FUNCTION PROTOTYPES
  113. *********************************************************************************************************
  114. *********************************************************************************************************
  115. */
  116. CPU_BOOLEAN Auth_Init ( RTOS_ERR *p_err);
  117. CPU_BOOLEAN Auth_CreateUser (const CPU_CHAR *p_name,
  118. const CPU_CHAR *p_pwd,
  119. AUTH_USER *p_user,
  120. RTOS_ERR *p_err);
  121. CPU_BOOLEAN Auth_GetUser (const CPU_CHAR *p_name,
  122. AUTH_USER *p_user,
  123. RTOS_ERR *p_err);
  124. CPU_BOOLEAN Auth_ValidateCredentials (const CPU_CHAR *p_name,
  125. const CPU_CHAR *p_pwd,
  126. AUTH_USER *p_user,
  127. RTOS_ERR *p_err);
  128. CPU_BOOLEAN Auth_GrantRight ( AUTH_RIGHT right,
  129. AUTH_USER *p_user,
  130. AUTH_USER *p_as_user,
  131. RTOS_ERR *p_err);
  132. CPU_BOOLEAN Auth_RevokeRight ( AUTH_RIGHT right,
  133. AUTH_USER *p_user,
  134. AUTH_USER *p_as_user,
  135. RTOS_ERR *p_err);
  136. /*
  137. *********************************************************************************************************
  138. *********************************************************************************************************
  139. * MODULE END
  140. *********************************************************************************************************
  141. *********************************************************************************************************
  142. */
  143. #endif /* AUTH_MODULE_PRESENT */