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