From 840b20a768a5193b708f784dc842b81aa77bf16a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Arreola=20Rodr=C3=ADguez?= Date: Mon, 13 Jan 2025 20:25:22 -0600 Subject: [PATCH] =?UTF-8?q?Agrego=20eliminaci=C3=B3n=20de=20nameservers=20?= =?UTF-8?q?por=20el=20resolvconf.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/resolv_conf_parser.c | 1 + lib/resolv_conf_defs.h | 1 + lib/resolv_manager.c | 8 ++++++- src/manager-resolvconf.c | 47 +++++++++++++++++++++++++++++++++++++ src/manager-resolvconf.h | 1 + src/manager.c | 6 ++--- 6 files changed, 60 insertions(+), 4 deletions(-) diff --git a/common/resolv_conf_parser.c b/common/resolv_conf_parser.c index f098649..711f5a1 100644 --- a/common/resolv_conf_parser.c +++ b/common/resolv_conf_parser.c @@ -163,6 +163,7 @@ FList * resolv_parser_parse_local_file (FList *all_entries, FILE *fd, int origin entry->resolv_type = type; entry->origin = origin; + entry->was_new = 1; entry->for_purge = 0; entry->ns_family = family; diff --git a/lib/resolv_conf_defs.h b/lib/resolv_conf_defs.h index f7d89d8..e80b479 100644 --- a/lib/resolv_conf_defs.h +++ b/lib/resolv_conf_defs.h @@ -55,6 +55,7 @@ typedef struct _ResolvConfEntry { int file_order; int tagged; int for_purge; + int was_new; int priority; int ns_family; diff --git a/lib/resolv_manager.c b/lib/resolv_manager.c index 376d11e..b454387 100644 --- a/lib/resolv_manager.c +++ b/lib/resolv_manager.c @@ -108,6 +108,7 @@ void resolv_manager_clear_tag_on_all (NetworkInadorHandle *handle) { entry = (ResolvConfEntry *) pos->data; entry->tagged = 0; + entry->was_new = 0; pos = pos->next; } } @@ -392,7 +393,11 @@ void resolv_manager_read_local_etc_resolv (NetworkInadorHandle *handle) { free (entry); entry = NULL; } else { - printf ("/// La entrada %s del resolv.conf sigue en el archivo.\n", entry->value); + if (entry->was_new) { + printf ("/// La entrada %s es nueva en el resolv.conf\n", entry->value); + } else { + printf ("/// La entrada %s del resolv.conf sigue en el archivo.\n", entry->value); + } } pos = next; } @@ -408,6 +413,7 @@ void resolv_manager_write (NetworkInadorHandle *handle) { Interface *iface; /* Antes de hacer la escritura, siempre hacemos una lectura */ + printf ("/// Ejecutando pre-lectura de resolv.conf para poderlo modificar\n"); resolv_manager_read_local_etc_resolv (handle); /* Intentar la escritura */ diff --git a/src/manager-resolvconf.c b/src/manager-resolvconf.c index 7c61e24..1dc2c6a 100644 --- a/src/manager-resolvconf.c +++ b/src/manager-resolvconf.c @@ -157,3 +157,50 @@ void _manager_resolvconf_handle_feed (ManagerClientInfo *manager_client, unsigne network_inador_resolvconf_free_all_entries (resolv_entries); } +void _manager_resolvconf_handle_remove_feed (ManagerClientInfo *manager_client, unsigned char *buffer, int buffer_len) { + int name_len; + unsigned char iface_prog[256]; + unsigned char iface_name[256], prog[256]; + char *point; + Interface *iface; + uint32_t iface_index; + + name_len = buffer[2]; + + if (buffer_len < 3 + name_len || name_len == 0) { + _manager_send_error (manager_client, NET_INADOR_ERROR_INCOMPLETE_REQUEST, NET_INADOR_COMMAND_RESOLVCONF_REMOVE); + return; + } + + memcpy (iface_prog, &buffer[3], name_len); + iface_prog[name_len] = 0; + + if (iface_prog[0] == '.') { + /* No permitimos interfaces vacĂ­as */ + _manager_send_error (manager_client, NET_INADOR_ERROR_INVALID_VALUE, NET_INADOR_COMMAND_RESOLVCONF_REMOVE); + + return; + } + + point = strchr (iface_prog, '.'); + if (point == NULL) { + prog[0] = 0; + strncpy (iface_name, iface_prog, sizeof (iface_name)); + } else { + point[0] = 0; + strncpy (iface_name, iface_prog, sizeof (iface_name)); + strncpy (prog, &point[1], sizeof (prog)); + } + + iface = network_inador_get_iface_by_name (manager_client->manager->handle, iface_name); + if (iface == NULL) { + iface_index = 0; + } else { + iface_index = network_inador_iface_get_index (iface); + } + + resolv_manager_clear_entries_by_prog (manager_client->manager->handle, iface_index, prog); + + _manager_send_executed (manager_client); +} + diff --git a/src/manager-resolvconf.h b/src/manager-resolvconf.h index abdc154..4472791 100644 --- a/src/manager-resolvconf.h +++ b/src/manager-resolvconf.h @@ -32,6 +32,7 @@ #include "network-inador-manager.h" void _manager_resolvconf_handle_feed (ManagerClientInfo *manager_client, unsigned char *buffer, int buffer_len); +void _manager_resolvconf_handle_remove_feed (ManagerClientInfo *manager_client, unsigned char *buffer, int buffer_len); #endif /* __MANAGER_RESOLVCONF_H__ */ diff --git a/src/manager.c b/src/manager.c index 31790c0..5d5b1b4 100644 --- a/src/manager.c +++ b/src/manager.c @@ -214,9 +214,9 @@ static gboolean _manager_on_client_data_recv (GIOChannel *source, GIOCondition c case NET_INADOR_COMMAND_RESOLVCONF_FEED: _manager_resolvconf_handle_feed (manager_client, buffer, bytes); break; - /*case NET_INADOR_COMMAND_RESOLVCONF_REMOVE: - _manager_execute_resolvconf_remove (manager_client, buffer, bytes); - break;*/ + case NET_INADOR_COMMAND_RESOLVCONF_REMOVE: + _manager_resolvconf_handle_remove_feed (manager_client, buffer, bytes); + break; default: _manager_send_error (manager_client, NET_INADOR_ERROR_WRONG_COMMAND, command); }