eapol_auth_dump.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /*
  2. * IEEE 802.1X-2004 Authenticator - State dump
  3. * Copyright (c) 2002-2013, Jouni Malinen <j@w1.fi>
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. */
  8. #include "includes.h"
  9. #include "common.h"
  10. #include "eap_server/eap.h"
  11. #include "eapol_auth_sm.h"
  12. #include "eapol_auth_sm_i.h"
  13. static inline const char * port_type_txt(PortTypes pt)
  14. {
  15. switch (pt) {
  16. case ForceUnauthorized: return "ForceUnauthorized";
  17. case ForceAuthorized: return "ForceAuthorized";
  18. case Auto: return "Auto";
  19. default: return "Unknown";
  20. }
  21. }
  22. static inline const char * port_state_txt(PortState ps)
  23. {
  24. switch (ps) {
  25. case Unauthorized: return "Unauthorized";
  26. case Authorized: return "Authorized";
  27. default: return "Unknown";
  28. }
  29. }
  30. static inline const char * ctrl_dir_txt(ControlledDirection dir)
  31. {
  32. switch (dir) {
  33. case Both: return "Both";
  34. case In: return "In";
  35. default: return "Unknown";
  36. }
  37. }
  38. static inline const char * auth_pae_state_txt(int s)
  39. {
  40. switch (s) {
  41. case AUTH_PAE_INITIALIZE: return "INITIALIZE";
  42. case AUTH_PAE_DISCONNECTED: return "DISCONNECTED";
  43. case AUTH_PAE_CONNECTING: return "CONNECTING";
  44. case AUTH_PAE_AUTHENTICATING: return "AUTHENTICATING";
  45. case AUTH_PAE_AUTHENTICATED: return "AUTHENTICATED";
  46. case AUTH_PAE_ABORTING: return "ABORTING";
  47. case AUTH_PAE_HELD: return "HELD";
  48. case AUTH_PAE_FORCE_AUTH: return "FORCE_AUTH";
  49. case AUTH_PAE_FORCE_UNAUTH: return "FORCE_UNAUTH";
  50. case AUTH_PAE_RESTART: return "RESTART";
  51. default: return "Unknown";
  52. }
  53. }
  54. static inline const char * be_auth_state_txt(int s)
  55. {
  56. switch (s) {
  57. case BE_AUTH_REQUEST: return "REQUEST";
  58. case BE_AUTH_RESPONSE: return "RESPONSE";
  59. case BE_AUTH_SUCCESS: return "SUCCESS";
  60. case BE_AUTH_FAIL: return "FAIL";
  61. case BE_AUTH_TIMEOUT: return "TIMEOUT";
  62. case BE_AUTH_IDLE: return "IDLE";
  63. case BE_AUTH_INITIALIZE: return "INITIALIZE";
  64. case BE_AUTH_IGNORE: return "IGNORE";
  65. default: return "Unknown";
  66. }
  67. }
  68. static inline const char * reauth_timer_state_txt(int s)
  69. {
  70. switch (s) {
  71. case REAUTH_TIMER_INITIALIZE: return "INITIALIZE";
  72. case REAUTH_TIMER_REAUTHENTICATE: return "REAUTHENTICATE";
  73. default: return "Unknown";
  74. }
  75. }
  76. static inline const char * auth_key_tx_state_txt(int s)
  77. {
  78. switch (s) {
  79. case AUTH_KEY_TX_NO_KEY_TRANSMIT: return "NO_KEY_TRANSMIT";
  80. case AUTH_KEY_TX_KEY_TRANSMIT: return "KEY_TRANSMIT";
  81. default: return "Unknown";
  82. }
  83. }
  84. static inline const char * key_rx_state_txt(int s)
  85. {
  86. switch (s) {
  87. case KEY_RX_NO_KEY_RECEIVE: return "NO_KEY_RECEIVE";
  88. case KEY_RX_KEY_RECEIVE: return "KEY_RECEIVE";
  89. default: return "Unknown";
  90. }
  91. }
  92. static inline const char * ctrl_dir_state_txt(int s)
  93. {
  94. switch (s) {
  95. case CTRL_DIR_FORCE_BOTH: return "FORCE_BOTH";
  96. case CTRL_DIR_IN_OR_BOTH: return "IN_OR_BOTH";
  97. default: return "Unknown";
  98. }
  99. }
  100. int eapol_auth_dump_state(struct eapol_state_machine *sm, char *buf,
  101. size_t buflen)
  102. {
  103. char *pos, *end;
  104. int ret;
  105. pos = buf;
  106. end = pos + buflen;
  107. ret = os_snprintf(pos, end - pos, "aWhile=%d\nquietWhile=%d\n"
  108. "reAuthWhen=%d\n",
  109. sm->aWhile, sm->quietWhile, sm->reAuthWhen);
  110. if (ret < 0 || ret >= end - pos)
  111. return pos - buf;
  112. pos += ret;
  113. #define _SB(b) ((b) ? "TRUE" : "FALSE")
  114. ret = os_snprintf(pos, end - pos,
  115. "authAbort=%s\n"
  116. "authFail=%s\n"
  117. "authPortStatus=%s\n"
  118. "authStart=%s\n"
  119. "authTimeout=%s\n"
  120. "authSuccess=%s\n"
  121. "eapFail=%s\n"
  122. "eapolEap=%s\n"
  123. "eapSuccess=%s\n"
  124. "eapTimeout=%s\n"
  125. "initialize=%s\n"
  126. "keyAvailable=%s\n"
  127. "keyDone=%s\n"
  128. "keyRun=%s\n"
  129. "keyTxEnabled=%s\n"
  130. "portControl=%s\n"
  131. "portEnabled=%s\n"
  132. "portValid=%s\n"
  133. "reAuthenticate=%s\n",
  134. _SB(sm->authAbort),
  135. _SB(sm->authFail),
  136. port_state_txt(sm->authPortStatus),
  137. _SB(sm->authStart),
  138. _SB(sm->authTimeout),
  139. _SB(sm->authSuccess),
  140. _SB(sm->eap_if->eapFail),
  141. _SB(sm->eapolEap),
  142. _SB(sm->eap_if->eapSuccess),
  143. _SB(sm->eap_if->eapTimeout),
  144. _SB(sm->initialize),
  145. _SB(sm->eap_if->eapKeyAvailable),
  146. _SB(sm->keyDone), _SB(sm->keyRun),
  147. _SB(sm->keyTxEnabled),
  148. port_type_txt(sm->portControl),
  149. _SB(sm->eap_if->portEnabled),
  150. _SB(sm->portValid),
  151. _SB(sm->reAuthenticate));
  152. if (ret < 0 || ret >= end - pos)
  153. return pos - buf;
  154. pos += ret;
  155. ret = os_snprintf(pos, end - pos,
  156. "auth_pae_state=%s\n"
  157. "eapolLogoff=%s\n"
  158. "eapolStart=%s\n"
  159. "eapRestart=%s\n"
  160. "portMode=%s\n"
  161. "reAuthCount=%d\n"
  162. "quietPeriod=%d\n"
  163. "reAuthMax=%d\n"
  164. "authEntersConnecting=%d\n"
  165. "authEapLogoffsWhileConnecting=%d\n"
  166. "authEntersAuthenticating=%d\n"
  167. "authAuthSuccessesWhileAuthenticating=%d\n"
  168. "authAuthTimeoutsWhileAuthenticating=%d\n"
  169. "authAuthFailWhileAuthenticating=%d\n"
  170. "authAuthEapStartsWhileAuthenticating=%d\n"
  171. "authAuthEapLogoffWhileAuthenticating=%d\n"
  172. "authAuthReauthsWhileAuthenticated=%d\n"
  173. "authAuthEapStartsWhileAuthenticated=%d\n"
  174. "authAuthEapLogoffWhileAuthenticated=%d\n",
  175. auth_pae_state_txt(sm->auth_pae_state),
  176. _SB(sm->eapolLogoff),
  177. _SB(sm->eapolStart),
  178. _SB(sm->eap_if->eapRestart),
  179. port_type_txt(sm->portMode),
  180. sm->reAuthCount,
  181. sm->quietPeriod, sm->reAuthMax,
  182. sm->authEntersConnecting,
  183. sm->authEapLogoffsWhileConnecting,
  184. sm->authEntersAuthenticating,
  185. sm->authAuthSuccessesWhileAuthenticating,
  186. sm->authAuthTimeoutsWhileAuthenticating,
  187. sm->authAuthFailWhileAuthenticating,
  188. sm->authAuthEapStartsWhileAuthenticating,
  189. sm->authAuthEapLogoffWhileAuthenticating,
  190. sm->authAuthReauthsWhileAuthenticated,
  191. sm->authAuthEapStartsWhileAuthenticated,
  192. sm->authAuthEapLogoffWhileAuthenticated);
  193. if (ret < 0 || ret >= end - pos)
  194. return pos - buf;
  195. pos += ret;
  196. ret = os_snprintf(pos, end - pos,
  197. "be_auth_state=%s\n"
  198. "eapNoReq=%s\n"
  199. "eapReq=%s\n"
  200. "eapResp=%s\n"
  201. "serverTimeout=%d\n"
  202. "backendResponses=%d\n"
  203. "backendAccessChallenges=%d\n"
  204. "backendOtherRequestsToSupplicant=%d\n"
  205. "backendAuthSuccesses=%d\n"
  206. "backendAuthFails=%d\n",
  207. be_auth_state_txt(sm->be_auth_state),
  208. _SB(sm->eap_if->eapNoReq),
  209. _SB(sm->eap_if->eapReq),
  210. _SB(sm->eap_if->eapResp),
  211. sm->serverTimeout,
  212. sm->backendResponses,
  213. sm->backendAccessChallenges,
  214. sm->backendOtherRequestsToSupplicant,
  215. sm->backendAuthSuccesses,
  216. sm->backendAuthFails);
  217. if (ret < 0 || ret >= end - pos)
  218. return pos - buf;
  219. pos += ret;
  220. ret = os_snprintf(pos, end - pos,
  221. "reauth_timer_state=%s\n"
  222. "reAuthPeriod=%d\n"
  223. "reAuthEnabled=%s\n",
  224. reauth_timer_state_txt(sm->reauth_timer_state),
  225. sm->reAuthPeriod,
  226. _SB(sm->reAuthEnabled));
  227. if (ret < 0 || ret >= end - pos)
  228. return pos - buf;
  229. pos += ret;
  230. ret = os_snprintf(pos, end - pos,
  231. "auth_key_tx_state=%s\n",
  232. auth_key_tx_state_txt(sm->auth_key_tx_state));
  233. if (ret < 0 || ret >= end - pos)
  234. return pos - buf;
  235. pos += ret;
  236. ret = os_snprintf(pos, end - pos,
  237. "key_rx_state=%s\n"
  238. "rxKey=%s\n",
  239. key_rx_state_txt(sm->key_rx_state),
  240. _SB(sm->rxKey));
  241. if (ret < 0 || ret >= end - pos)
  242. return pos - buf;
  243. pos += ret;
  244. ret = os_snprintf(pos, end - pos,
  245. "ctrl_dir_state=%s\n"
  246. "adminControlledDirections=%s\n"
  247. "operControlledDirections=%s\n"
  248. "operEdge=%s\n",
  249. ctrl_dir_state_txt(sm->ctrl_dir_state),
  250. ctrl_dir_txt(sm->adminControlledDirections),
  251. ctrl_dir_txt(sm->operControlledDirections),
  252. _SB(sm->operEdge));
  253. if (ret < 0 || ret >= end - pos)
  254. return pos - buf;
  255. pos += ret;
  256. #undef _SB
  257. return pos - buf;
  258. }