Agrego eliminación de nameservers por el resolvconf.

master
Félix Arreola Rodríguez 2025-01-13 20:25:22 -06:00
parent 0ea2ec7ca3
commit 840b20a768
6 changed files with 60 additions and 4 deletions

View File

@ -163,6 +163,7 @@ FList * resolv_parser_parse_local_file (FList *all_entries, FILE *fd, int origin
entry->resolv_type = type; entry->resolv_type = type;
entry->origin = origin; entry->origin = origin;
entry->was_new = 1;
entry->for_purge = 0; entry->for_purge = 0;
entry->ns_family = family; entry->ns_family = family;

View File

@ -55,6 +55,7 @@ typedef struct _ResolvConfEntry {
int file_order; int file_order;
int tagged; int tagged;
int for_purge; int for_purge;
int was_new;
int priority; int priority;
int ns_family; int ns_family;

View File

@ -108,6 +108,7 @@ void resolv_manager_clear_tag_on_all (NetworkInadorHandle *handle) {
entry = (ResolvConfEntry *) pos->data; entry = (ResolvConfEntry *) pos->data;
entry->tagged = 0; entry->tagged = 0;
entry->was_new = 0;
pos = pos->next; pos = pos->next;
} }
} }
@ -392,7 +393,11 @@ void resolv_manager_read_local_etc_resolv (NetworkInadorHandle *handle) {
free (entry); free (entry);
entry = NULL; entry = NULL;
} else { } 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; pos = next;
} }
@ -408,6 +413,7 @@ void resolv_manager_write (NetworkInadorHandle *handle) {
Interface *iface; Interface *iface;
/* Antes de hacer la escritura, siempre hacemos una lectura */ /* 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); resolv_manager_read_local_etc_resolv (handle);
/* Intentar la escritura */ /* Intentar la escritura */

View File

@ -157,3 +157,50 @@ void _manager_resolvconf_handle_feed (ManagerClientInfo *manager_client, unsigne
network_inador_resolvconf_free_all_entries (resolv_entries); 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);
}

View File

@ -32,6 +32,7 @@
#include "network-inador-manager.h" #include "network-inador-manager.h"
void _manager_resolvconf_handle_feed (ManagerClientInfo *manager_client, unsigned char *buffer, int buffer_len); 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__ */ #endif /* __MANAGER_RESOLVCONF_H__ */

View File

@ -214,9 +214,9 @@ static gboolean _manager_on_client_data_recv (GIOChannel *source, GIOCondition c
case NET_INADOR_COMMAND_RESOLVCONF_FEED: case NET_INADOR_COMMAND_RESOLVCONF_FEED:
_manager_resolvconf_handle_feed (manager_client, buffer, bytes); _manager_resolvconf_handle_feed (manager_client, buffer, bytes);
break; break;
/*case NET_INADOR_COMMAND_RESOLVCONF_REMOVE: case NET_INADOR_COMMAND_RESOLVCONF_REMOVE:
_manager_execute_resolvconf_remove (manager_client, buffer, bytes); _manager_resolvconf_handle_remove_feed (manager_client, buffer, bytes);
break;*/ break;
default: default:
_manager_send_error (manager_client, NET_INADOR_ERROR_WRONG_COMMAND, command); _manager_send_error (manager_client, NET_INADOR_ERROR_WRONG_COMMAND, command);
} }