From: Jouni Malinen Date: Sun, 22 Dec 2024 11:24:14 +0000 (+0200) Subject: hlr_auc_gw: Add TERMINATE command X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4e8686cd1a263eb423354883795915873ccc13d2;p=thirdparty%2Fhostap.git hlr_auc_gw: Add TERMINATE command The new TERMINATE command can be used to terminate hlr_auc_gw more cleanly without having to use signals. Signed-off-by: Jouni Malinen --- diff --git a/hostapd/hlr_auc_gw.c b/hostapd/hlr_auc_gw.c index 5caa779dd..291acf9ff 100644 --- a/hostapd/hlr_auc_gw.c +++ b/hostapd/hlr_auc_gw.c @@ -1,6 +1,6 @@ /* * HLR/AuC testing gateway for hostapd EAP-SIM/AKA database/authenticator - * Copyright (c) 2005-2007, 2012-2017, Jouni Malinen + * Copyright (c) 2005-2007, 2012-2024, Jouni Malinen * * This software may be distributed under the terms of the BSD license. * See README for more details. @@ -66,6 +66,7 @@ static int update_milenage = 0; static int sqn_changes = 0; static int ind_len = 5; static int stdout_debug = 1; +static bool stop = false; /* GSM triplets */ struct gsm_triplet { @@ -877,6 +878,12 @@ static int process_cmd(char *cmd, char *resp, size_t resp_len) if (os_strncmp(cmd, "AKA-AUTS ", 9) == 0) return aka_auts(cmd + 9, resp, resp_len); + if (strncmp(cmd, "TERMINATE", 9) == 0) { + stop = true; + resp[0] = '\0'; + return 0; + } + printf("Unknown request: %s\n", cmd); return -1; } @@ -931,10 +938,13 @@ static void cleanup(void) struct gsm_triplet *g, *gprev; struct milenage_parameters *m, *prev; - if (update_milenage && milenage_file && sqn_changes) + if (update_milenage && milenage_file && sqn_changes) { + sqn_changes = 0; update_milenage_file(milenage_file); + } g = gsm_db; + gsm_db = NULL; while (g) { gprev = g; g = g->next; @@ -942,16 +952,21 @@ static void cleanup(void) } m = milenage_db; + milenage_db = NULL; while (m) { prev = m; m = m->next; os_free(prev); } - if (serv_sock >= 0) + if (serv_sock >= 0) { close(serv_sock); - if (socket_path) + serv_sock = -1; + } + if (socket_path) { unlink(socket_path); + socket_path = NULL; + } #ifdef CONFIG_SQLITE if (sqlite_db) { @@ -965,6 +980,7 @@ static void cleanup(void) static void handle_term(int sig) { printf("Signal %d - terminate\n", sig); + cleanup(); exit(0); } @@ -973,7 +989,7 @@ static void usage(void) { printf("HLR/AuC testing gateway for hostapd EAP-SIM/AKA " "database/authenticator\n" - "Copyright (c) 2005-2017, Jouni Malinen \n" + "Copyright (c) 2005-2024, Jouni Malinen \n" "\n" "usage:\n" "hlr_auc_gw [-hu] [-s] [-g] " @@ -1081,8 +1097,9 @@ int main(int argc, char *argv[]) signal(SIGTERM, handle_term); signal(SIGINT, handle_term); - for (;;) + while (!stop) process(serv_sock); + cleanup(); } else { char buf[1000]; socket_path = NULL;