test_security_events.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2009, Digium, Inc.
  5. *
  6. * Russell Bryant <russell@digium.com>
  7. *
  8. * See http://www.asterisk.org for more information about
  9. * the Asterisk project. Please do not directly contact
  10. * any of the maintainers of this project for assistance;
  11. * the project provides a web site, mailing lists and IRC
  12. * channels for your use.
  13. *
  14. * This program is free software, distributed under the terms of
  15. * the GNU General Public License Version 2. See the LICENSE file
  16. * at the top of the source tree.
  17. */
  18. /*! \file
  19. *
  20. * \brief Test security event generation
  21. *
  22. * \author Russell Bryant <russell@digium.com>
  23. */
  24. /*** MODULEINFO
  25. <defaultenabled>no</defaultenabled>
  26. <support_level>extended</support_level>
  27. ***/
  28. #include "asterisk.h"
  29. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  30. #include "asterisk/module.h"
  31. #include "asterisk/cli.h"
  32. #include "asterisk/utils.h"
  33. #include "asterisk/security_events.h"
  34. static void evt_gen_failed_acl(void);
  35. static void evt_gen_inval_acct_id(void);
  36. static void evt_gen_session_limit(void);
  37. static void evt_gen_mem_limit(void);
  38. static void evt_gen_load_avg(void);
  39. static void evt_gen_req_no_support(void);
  40. static void evt_gen_req_not_allowed(void);
  41. static void evt_gen_auth_method_not_allowed(void);
  42. static void evt_gen_req_bad_format(void);
  43. static void evt_gen_successful_auth(void);
  44. static void evt_gen_unexpected_addr(void);
  45. static void evt_gen_chal_resp_failed(void);
  46. static void evt_gen_inval_password(void);
  47. typedef void (*evt_generator)(void);
  48. static const evt_generator evt_generators[AST_SECURITY_EVENT_NUM_TYPES] = {
  49. [AST_SECURITY_EVENT_FAILED_ACL] = evt_gen_failed_acl,
  50. [AST_SECURITY_EVENT_INVAL_ACCT_ID] = evt_gen_inval_acct_id,
  51. [AST_SECURITY_EVENT_SESSION_LIMIT] = evt_gen_session_limit,
  52. [AST_SECURITY_EVENT_MEM_LIMIT] = evt_gen_mem_limit,
  53. [AST_SECURITY_EVENT_LOAD_AVG] = evt_gen_load_avg,
  54. [AST_SECURITY_EVENT_REQ_NO_SUPPORT] = evt_gen_req_no_support,
  55. [AST_SECURITY_EVENT_REQ_NOT_ALLOWED] = evt_gen_req_not_allowed,
  56. [AST_SECURITY_EVENT_AUTH_METHOD_NOT_ALLOWED] = evt_gen_auth_method_not_allowed,
  57. [AST_SECURITY_EVENT_REQ_BAD_FORMAT] = evt_gen_req_bad_format,
  58. [AST_SECURITY_EVENT_SUCCESSFUL_AUTH] = evt_gen_successful_auth,
  59. [AST_SECURITY_EVENT_UNEXPECTED_ADDR] = evt_gen_unexpected_addr,
  60. [AST_SECURITY_EVENT_CHAL_RESP_FAILED] = evt_gen_chal_resp_failed,
  61. [AST_SECURITY_EVENT_INVAL_PASSWORD] = evt_gen_inval_password,
  62. };
  63. static void evt_gen_failed_acl(void)
  64. {
  65. struct sockaddr_in sin_local = {
  66. .sin_family = AF_INET
  67. };
  68. struct sockaddr_in sin_remote = {
  69. .sin_family = AF_INET
  70. };
  71. struct timeval session_tv = ast_tvnow();
  72. struct ast_security_event_failed_acl failed_acl_event = {
  73. .common.event_type = AST_SECURITY_EVENT_FAILED_ACL,
  74. .common.version = AST_SECURITY_EVENT_FAILED_ACL_VERSION,
  75. .common.service = "TEST",
  76. .common.module = AST_MODULE,
  77. .common.account_id = "Username",
  78. .common.session_id = "Session123",
  79. .common.session_tv = &session_tv,
  80. .common.local_addr = {
  81. .sin = &sin_local,
  82. .transport = AST_SECURITY_EVENT_TRANSPORT_UDP,
  83. },
  84. .common.remote_addr = {
  85. .sin = &sin_remote,
  86. .transport = AST_SECURITY_EVENT_TRANSPORT_UDP,
  87. },
  88. .acl_name = "TEST_ACL",
  89. };
  90. inet_aton("192.168.1.1", &sin_local.sin_addr);
  91. sin_local.sin_port = htons(12121);
  92. inet_aton("192.168.1.2", &sin_remote.sin_addr);
  93. sin_remote.sin_port = htons(12345);
  94. ast_security_event_report(AST_SEC_EVT(&failed_acl_event));
  95. }
  96. static void evt_gen_inval_acct_id(void)
  97. {
  98. struct sockaddr_in sin_local = {
  99. .sin_family = AF_INET
  100. };
  101. struct sockaddr_in sin_remote = {
  102. .sin_family = AF_INET
  103. };
  104. struct timeval session_tv = ast_tvnow();
  105. struct ast_security_event_inval_acct_id inval_acct_id = {
  106. .common.event_type = AST_SECURITY_EVENT_INVAL_ACCT_ID,
  107. .common.version = AST_SECURITY_EVENT_INVAL_ACCT_ID_VERSION,
  108. .common.service = "TEST",
  109. .common.module = AST_MODULE,
  110. .common.account_id = "FakeUser",
  111. .common.session_id = "Session456",
  112. .common.session_tv = &session_tv,
  113. .common.local_addr = {
  114. .sin = &sin_local,
  115. .transport = AST_SECURITY_EVENT_TRANSPORT_TCP,
  116. },
  117. .common.remote_addr = {
  118. .sin = &sin_remote,
  119. .transport = AST_SECURITY_EVENT_TRANSPORT_TCP,
  120. },
  121. };
  122. inet_aton("10.1.2.3", &sin_local.sin_addr);
  123. sin_local.sin_port = htons(4321);
  124. inet_aton("10.1.2.4", &sin_remote.sin_addr);
  125. sin_remote.sin_port = htons(1234);
  126. ast_security_event_report(AST_SEC_EVT(&inval_acct_id));
  127. }
  128. static void evt_gen_session_limit(void)
  129. {
  130. struct sockaddr_in sin_local = {
  131. .sin_family = AF_INET
  132. };
  133. struct sockaddr_in sin_remote = {
  134. .sin_family = AF_INET
  135. };
  136. struct timeval session_tv = ast_tvnow();
  137. struct ast_security_event_session_limit session_limit = {
  138. .common.event_type = AST_SECURITY_EVENT_SESSION_LIMIT,
  139. .common.version = AST_SECURITY_EVENT_SESSION_LIMIT_VERSION,
  140. .common.service = "TEST",
  141. .common.module = AST_MODULE,
  142. .common.account_id = "Jenny",
  143. .common.session_id = "8675309",
  144. .common.session_tv = &session_tv,
  145. .common.local_addr = {
  146. .sin = &sin_local,
  147. .transport = AST_SECURITY_EVENT_TRANSPORT_TLS,
  148. },
  149. .common.remote_addr = {
  150. .sin = &sin_remote,
  151. .transport = AST_SECURITY_EVENT_TRANSPORT_TLS,
  152. },
  153. };
  154. inet_aton("10.5.4.3", &sin_local.sin_addr);
  155. sin_local.sin_port = htons(4444);
  156. inet_aton("10.5.4.2", &sin_remote.sin_addr);
  157. sin_remote.sin_port = htons(3333);
  158. ast_security_event_report(AST_SEC_EVT(&session_limit));
  159. }
  160. static void evt_gen_mem_limit(void)
  161. {
  162. struct sockaddr_in sin_local = {
  163. .sin_family = AF_INET
  164. };
  165. struct sockaddr_in sin_remote = {
  166. .sin_family = AF_INET
  167. };
  168. struct timeval session_tv = ast_tvnow();
  169. struct ast_security_event_mem_limit mem_limit = {
  170. .common.event_type = AST_SECURITY_EVENT_MEM_LIMIT,
  171. .common.version = AST_SECURITY_EVENT_MEM_LIMIT_VERSION,
  172. .common.service = "TEST",
  173. .common.module = AST_MODULE,
  174. .common.account_id = "Felix",
  175. .common.session_id = "Session2604",
  176. .common.session_tv = &session_tv,
  177. .common.local_addr = {
  178. .sin = &sin_local,
  179. .transport = AST_SECURITY_EVENT_TRANSPORT_UDP,
  180. },
  181. .common.remote_addr = {
  182. .sin = &sin_remote,
  183. .transport = AST_SECURITY_EVENT_TRANSPORT_UDP,
  184. },
  185. };
  186. inet_aton("10.10.10.10", &sin_local.sin_addr);
  187. sin_local.sin_port = htons(555);
  188. inet_aton("10.10.10.12", &sin_remote.sin_addr);
  189. sin_remote.sin_port = htons(5656);
  190. ast_security_event_report(AST_SEC_EVT(&mem_limit));
  191. }
  192. static void evt_gen_load_avg(void)
  193. {
  194. struct sockaddr_in sin_local = {
  195. .sin_family = AF_INET
  196. };
  197. struct sockaddr_in sin_remote = {
  198. .sin_family = AF_INET
  199. };
  200. struct timeval session_tv = ast_tvnow();
  201. struct ast_security_event_load_avg load_avg = {
  202. .common.event_type = AST_SECURITY_EVENT_LOAD_AVG,
  203. .common.version = AST_SECURITY_EVENT_LOAD_AVG_VERSION,
  204. .common.service = "TEST",
  205. .common.module = AST_MODULE,
  206. .common.account_id = "GuestAccount",
  207. .common.session_id = "XYZ123",
  208. .common.session_tv = &session_tv,
  209. .common.local_addr = {
  210. .sin = &sin_local,
  211. .transport = AST_SECURITY_EVENT_TRANSPORT_UDP,
  212. },
  213. .common.remote_addr = {
  214. .sin = &sin_remote,
  215. .transport = AST_SECURITY_EVENT_TRANSPORT_UDP,
  216. },
  217. };
  218. inet_aton("10.11.12.13", &sin_local.sin_addr);
  219. sin_local.sin_port = htons(9876);
  220. inet_aton("10.12.11.10", &sin_remote.sin_addr);
  221. sin_remote.sin_port = htons(9825);
  222. ast_security_event_report(AST_SEC_EVT(&load_avg));
  223. }
  224. static void evt_gen_req_no_support(void)
  225. {
  226. struct sockaddr_in sin_local = {
  227. .sin_family = AF_INET
  228. };
  229. struct sockaddr_in sin_remote = {
  230. .sin_family = AF_INET
  231. };
  232. struct timeval session_tv = ast_tvnow();
  233. struct ast_security_event_req_no_support req_no_support = {
  234. .common.event_type = AST_SECURITY_EVENT_REQ_NO_SUPPORT,
  235. .common.version = AST_SECURITY_EVENT_REQ_NO_SUPPORT_VERSION,
  236. .common.service = "TEST",
  237. .common.module = AST_MODULE,
  238. .common.account_id = "George",
  239. .common.session_id = "asdkl23478289lasdkf",
  240. .common.session_tv = &session_tv,
  241. .common.local_addr = {
  242. .sin = &sin_local,
  243. .transport = AST_SECURITY_EVENT_TRANSPORT_UDP,
  244. },
  245. .common.remote_addr = {
  246. .sin = &sin_remote,
  247. .transport = AST_SECURITY_EVENT_TRANSPORT_UDP,
  248. },
  249. .request_type = "MakeMeDinner",
  250. };
  251. inet_aton("10.110.120.130", &sin_local.sin_addr);
  252. sin_local.sin_port = htons(9888);
  253. inet_aton("10.120.110.100", &sin_remote.sin_addr);
  254. sin_remote.sin_port = htons(9777);
  255. ast_security_event_report(AST_SEC_EVT(&req_no_support));
  256. }
  257. static void evt_gen_req_not_allowed(void)
  258. {
  259. struct sockaddr_in sin_local = {
  260. .sin_family = AF_INET
  261. };
  262. struct sockaddr_in sin_remote = {
  263. .sin_family = AF_INET
  264. };
  265. struct timeval session_tv = ast_tvnow();
  266. struct ast_security_event_req_not_allowed req_not_allowed = {
  267. .common.event_type = AST_SECURITY_EVENT_REQ_NOT_ALLOWED,
  268. .common.version = AST_SECURITY_EVENT_REQ_NOT_ALLOWED_VERSION,
  269. .common.service = "TEST",
  270. .common.module = AST_MODULE,
  271. .common.account_id = "George",
  272. .common.session_id = "alksdjf023423h4lka0df",
  273. .common.session_tv = &session_tv,
  274. .common.local_addr = {
  275. .sin = &sin_local,
  276. .transport = AST_SECURITY_EVENT_TRANSPORT_UDP,
  277. },
  278. .common.remote_addr = {
  279. .sin = &sin_remote,
  280. .transport = AST_SECURITY_EVENT_TRANSPORT_UDP,
  281. },
  282. .request_type = "MakeMeBreakfast",
  283. .request_params = "BACONNNN!",
  284. };
  285. inet_aton("10.110.120.130", &sin_local.sin_addr);
  286. sin_local.sin_port = htons(9888);
  287. inet_aton("10.120.110.100", &sin_remote.sin_addr);
  288. sin_remote.sin_port = htons(9777);
  289. ast_security_event_report(AST_SEC_EVT(&req_not_allowed));
  290. }
  291. static void evt_gen_auth_method_not_allowed(void)
  292. {
  293. struct sockaddr_in sin_local = {
  294. .sin_family = AF_INET
  295. };
  296. struct sockaddr_in sin_remote = {
  297. .sin_family = AF_INET
  298. };
  299. struct timeval session_tv = ast_tvnow();
  300. struct ast_security_event_auth_method_not_allowed auth_method_not_allowed = {
  301. .common.event_type = AST_SECURITY_EVENT_AUTH_METHOD_NOT_ALLOWED,
  302. .common.version = AST_SECURITY_EVENT_AUTH_METHOD_NOT_ALLOWED_VERSION,
  303. .common.service = "TEST",
  304. .common.module = AST_MODULE,
  305. .common.account_id = "Bob",
  306. .common.session_id = "010101010101",
  307. .common.session_tv = &session_tv,
  308. .common.local_addr = {
  309. .sin = &sin_local,
  310. .transport = AST_SECURITY_EVENT_TRANSPORT_TCP,
  311. },
  312. .common.remote_addr = {
  313. .sin = &sin_remote,
  314. .transport = AST_SECURITY_EVENT_TRANSPORT_TCP,
  315. },
  316. .auth_method = "PlainText"
  317. };
  318. inet_aton("10.110.120.135", &sin_local.sin_addr);
  319. sin_local.sin_port = htons(8754);
  320. inet_aton("10.120.110.105", &sin_remote.sin_addr);
  321. sin_remote.sin_port = htons(8745);
  322. ast_security_event_report(AST_SEC_EVT(&auth_method_not_allowed));
  323. }
  324. static void evt_gen_req_bad_format(void)
  325. {
  326. struct sockaddr_in sin_local = {
  327. .sin_family = AF_INET
  328. };
  329. struct sockaddr_in sin_remote = {
  330. .sin_family = AF_INET
  331. };
  332. struct timeval session_tv = ast_tvnow();
  333. struct ast_security_event_req_bad_format req_bad_format = {
  334. .common.event_type = AST_SECURITY_EVENT_REQ_BAD_FORMAT,
  335. .common.version = AST_SECURITY_EVENT_REQ_BAD_FORMAT_VERSION,
  336. .common.service = "TEST",
  337. .common.module = AST_MODULE,
  338. .common.account_id = "Larry",
  339. .common.session_id = "838383fhfhf83hf8h3f8h",
  340. .common.session_tv = &session_tv,
  341. .common.local_addr = {
  342. .sin = &sin_local,
  343. .transport = AST_SECURITY_EVENT_TRANSPORT_TCP,
  344. },
  345. .common.remote_addr = {
  346. .sin = &sin_remote,
  347. .transport = AST_SECURITY_EVENT_TRANSPORT_TCP,
  348. },
  349. .request_type = "CheeseBurger",
  350. .request_params = "Onions,Swiss,MotorOil",
  351. };
  352. inet_aton("10.110.220.230", &sin_local.sin_addr);
  353. sin_local.sin_port = htons(1212);
  354. inet_aton("10.120.210.200", &sin_remote.sin_addr);
  355. sin_remote.sin_port = htons(2121);
  356. ast_security_event_report(AST_SEC_EVT(&req_bad_format));
  357. }
  358. static void evt_gen_successful_auth(void)
  359. {
  360. struct sockaddr_in sin_local = {
  361. .sin_family = AF_INET
  362. };
  363. struct sockaddr_in sin_remote = {
  364. .sin_family = AF_INET
  365. };
  366. struct timeval session_tv = ast_tvnow();
  367. struct ast_security_event_successful_auth successful_auth = {
  368. .common.event_type = AST_SECURITY_EVENT_SUCCESSFUL_AUTH,
  369. .common.version = AST_SECURITY_EVENT_SUCCESSFUL_AUTH_VERSION,
  370. .common.service = "TEST",
  371. .common.module = AST_MODULE,
  372. .common.account_id = "ValidUser",
  373. .common.session_id = "Session456",
  374. .common.session_tv = &session_tv,
  375. .common.local_addr = {
  376. .sin = &sin_local,
  377. .transport = AST_SECURITY_EVENT_TRANSPORT_TCP,
  378. },
  379. .common.remote_addr = {
  380. .sin = &sin_remote,
  381. .transport = AST_SECURITY_EVENT_TRANSPORT_TCP,
  382. },
  383. };
  384. inet_aton("10.1.2.3", &sin_local.sin_addr);
  385. sin_local.sin_port = htons(4321);
  386. inet_aton("10.1.2.4", &sin_remote.sin_addr);
  387. sin_remote.sin_port = htons(1234);
  388. ast_security_event_report(AST_SEC_EVT(&successful_auth));
  389. }
  390. static void evt_gen_unexpected_addr(void)
  391. {
  392. struct sockaddr_in sin_local = {
  393. .sin_family = AF_INET
  394. };
  395. struct sockaddr_in sin_remote = {
  396. .sin_family = AF_INET
  397. };
  398. struct sockaddr_in sin_expected = {
  399. .sin_family = AF_INET
  400. };
  401. struct timeval session_tv = ast_tvnow();
  402. struct ast_security_event_unexpected_addr unexpected_addr = {
  403. .common.event_type = AST_SECURITY_EVENT_UNEXPECTED_ADDR,
  404. .common.version = AST_SECURITY_EVENT_UNEXPECTED_ADDR_VERSION,
  405. .common.service = "TEST",
  406. .common.module = AST_MODULE,
  407. .common.account_id = "CoolUser",
  408. .common.session_id = "Session789",
  409. .common.session_tv = &session_tv,
  410. .common.local_addr = {
  411. .sin = &sin_local,
  412. .transport = AST_SECURITY_EVENT_TRANSPORT_UDP,
  413. },
  414. .common.remote_addr = {
  415. .sin = &sin_remote,
  416. .transport = AST_SECURITY_EVENT_TRANSPORT_UDP,
  417. },
  418. .expected_addr = {
  419. .sin = &sin_expected,
  420. .transport = AST_SECURITY_EVENT_TRANSPORT_UDP,
  421. },
  422. };
  423. inet_aton("10.1.2.3", &sin_local.sin_addr);
  424. sin_local.sin_port = htons(4321);
  425. inet_aton("10.1.2.4", &sin_remote.sin_addr);
  426. sin_remote.sin_port = htons(1234);
  427. inet_aton("10.1.2.5", &sin_expected.sin_addr);
  428. sin_expected.sin_port = htons(2343);
  429. ast_security_event_report(AST_SEC_EVT(&unexpected_addr));
  430. }
  431. static void evt_gen_chal_resp_failed(void)
  432. {
  433. struct sockaddr_in sin_local = {
  434. .sin_family = AF_INET
  435. };
  436. struct sockaddr_in sin_remote = {
  437. .sin_family = AF_INET
  438. };
  439. struct timeval session_tv = ast_tvnow();
  440. struct ast_security_event_chal_resp_failed chal_resp_failed = {
  441. .common.event_type = AST_SECURITY_EVENT_CHAL_RESP_FAILED,
  442. .common.version = AST_SECURITY_EVENT_CHAL_RESP_FAILED_VERSION,
  443. .common.service = "TEST",
  444. .common.module = AST_MODULE,
  445. .common.account_id = "SuperDuperUser",
  446. .common.session_id = "Session1231231231",
  447. .common.session_tv = &session_tv,
  448. .common.local_addr = {
  449. .sin = &sin_local,
  450. .transport = AST_SECURITY_EVENT_TRANSPORT_TCP,
  451. },
  452. .common.remote_addr = {
  453. .sin = &sin_remote,
  454. .transport = AST_SECURITY_EVENT_TRANSPORT_TCP,
  455. },
  456. .challenge = "8adf8a9sd8fas9df23ljk4",
  457. .response = "9u3jlaksdjflakjsdfoi23",
  458. .expected_response = "oiafaljhadf9834luahk3k",
  459. };
  460. inet_aton("10.1.2.3", &sin_local.sin_addr);
  461. sin_local.sin_port = htons(4321);
  462. inet_aton("10.1.2.4", &sin_remote.sin_addr);
  463. sin_remote.sin_port = htons(1234);
  464. ast_security_event_report(AST_SEC_EVT(&chal_resp_failed));
  465. }
  466. static void evt_gen_inval_password(void)
  467. {
  468. struct sockaddr_in sin_local = {
  469. .sin_family = AF_INET
  470. };
  471. struct sockaddr_in sin_remote = {
  472. .sin_family = AF_INET
  473. };
  474. struct timeval session_tv = ast_tvnow();
  475. struct ast_security_event_inval_password inval_password = {
  476. .common.event_type = AST_SECURITY_EVENT_INVAL_PASSWORD,
  477. .common.version = AST_SECURITY_EVENT_INVAL_PASSWORD_VERSION,
  478. .common.service = "TEST",
  479. .common.module = AST_MODULE,
  480. .common.account_id = "AccountIDGoesHere",
  481. .common.session_id = "SessionIDGoesHere",
  482. .common.session_tv = &session_tv,
  483. .common.local_addr = {
  484. .sin = &sin_local,
  485. .transport = AST_SECURITY_EVENT_TRANSPORT_TCP,
  486. },
  487. .common.remote_addr = {
  488. .sin = &sin_remote,
  489. .transport = AST_SECURITY_EVENT_TRANSPORT_TCP,
  490. },
  491. };
  492. inet_aton("10.200.100.30", &sin_local.sin_addr);
  493. sin_local.sin_port = htons(4321);
  494. inet_aton("10.200.100.40", &sin_remote.sin_addr);
  495. sin_remote.sin_port = htons(1234);
  496. ast_security_event_report(AST_SEC_EVT(&inval_password));
  497. }
  498. static void gen_events(struct ast_cli_args *a)
  499. {
  500. unsigned int i;
  501. ast_cli(a->fd, "Generating some security events ...\n");
  502. for (i = 0; i < ARRAY_LEN(evt_generators); i++) {
  503. const char *event_type = ast_security_event_get_name(i);
  504. if (!evt_generators[i]) {
  505. ast_cli(a->fd, "*** No event generator for event type '%s' ***\n",
  506. event_type);
  507. continue;
  508. }
  509. ast_cli(a->fd, "Generating a '%s' security event ...\n", event_type);
  510. evt_generators[i]();
  511. }
  512. ast_cli(a->fd, "Security event generation complete.\n");
  513. }
  514. static char *handle_cli_sec_evt_test(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
  515. {
  516. switch (cmd) {
  517. case CLI_INIT:
  518. e->command = "securityevents test generation";
  519. e->usage = ""
  520. "Usage: securityevents test generation"
  521. "";
  522. return NULL;
  523. case CLI_GENERATE:
  524. return NULL;
  525. case CLI_HANDLER:
  526. gen_events(a);
  527. return CLI_SUCCESS;
  528. }
  529. return CLI_FAILURE;
  530. }
  531. static struct ast_cli_entry cli_sec_evt[] = {
  532. AST_CLI_DEFINE(handle_cli_sec_evt_test, "Test security event generation"),
  533. };
  534. static int unload_module(void)
  535. {
  536. return ast_cli_unregister_multiple(cli_sec_evt, ARRAY_LEN(cli_sec_evt));
  537. }
  538. static int load_module(void)
  539. {
  540. int res;
  541. res = ast_cli_register_multiple(cli_sec_evt, ARRAY_LEN(cli_sec_evt));
  542. return res ? AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS;
  543. }
  544. AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Test Security Event Generation");