<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <assert.h>

#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include <stdarg.h>
#include <inttypes.h>
#include <fcntl.h>
#include <time.h>
#include <limits.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/queue.h>
#include <sys/tree.h>
#include <sys/resource.h>
#include <sys/syscall.h>
#include <arpa/inet.h>
#include <errno.h>
#include <ctype.h>
#include <signal.h>
#include <syslog.h>
#include <getopt.h>

#define USE_DEBUG

#include <event.h>

#include <mand/logx.h>

#ifdef HAVE_TALLOC_TALLOC_H
# include <talloc/talloc.h>
#else
# include <talloc.h>
#endif

#include "cfgd.h"
#include "comm.h"

static const char _ident[] = "cfgd v" VERSION;
static const char _build[] = "build on " __DATE__ " " __TIME__ " with gcc " __VERSION__;

struct event_base *ev_base;


int vsystem(const char *cmd)
{
        int rc = 0;
        int _errno;

        fprintf(stderr, "cmd=[%s]\n", cmd);

        errno = 0;
        rc = system(cmd);

        _errno = errno;
        fprintf(stderr, "cmd=[%s], rc=%d, error=%s\n", cmd, rc, strerror(_errno));
	errno = _errno;

        return rc;
}

int vasystem(const char *fmt, ...)
{
        va_list args;
        char    buf[1024];

        va_start(args, fmt);
        vsnprintf(buf, sizeof(buf), fmt, args);
        va_end(args);

        return vsystem(buf);
}

void set_ntp_server(const struct ntp_servers *servers)
{
	int i;

	vsystem("uci delete system.ntp.server");
	for (i = 0; i < servers->count; i++) {
		vasystem("uci add_list system.ntp.server='%s'", servers->server[i]);
	}
	vsystem("uci commit system.ntp.server");
	vsystem("/etc/init.d/sysntpd restart");
}

void set_dns(const struct string_list *search, const struct string_list *servers)
{
	char *s;
	int i;

	s = talloc_strdup(NULL, "uci set dnsmasq.server");
	for (i = 0; i < servers->count; i++) {
		s = talloc_asprintf_append(s, " %s", servers->s[i]);
	}
	talloc_free(s);

	if (search->count != 0)
		vasystem("uci set dhcp.@dnsmasq[0].domain %s", search->s[0]);
	vsystem("uci commit dhcp");
	vsystem("/etc/init.d/dnsmasq restart");
}

void set_if_addr(struct interface_list *info)
{
	int i, j;

	for (i = 0; i < info->count; i++) {
		for (j = 0; j < info->iface[i].ipv4.addr.count; j++) {
			vasystem("uci set network.%s.ipaddr=%s", info->iface[i].name, info->iface[i].ipv4.addr.ip[j].address);
			vasystem("uci set network.%s.netmask=%s", info->iface[i].name, info->iface[i].ipv4.addr.ip[j].value);
		}
		for (j = 0; j < info->iface[i].ipv6.addr.count; j++)
			vasystem("uci set network.%s.ip6addr=%s/%s", info->iface[i].name, info->iface[i].ipv6.addr.ip[j].address, info->iface[i].ipv6.addr.ip[j].value);
	}
}

void set_if_neigh(struct interface_list *info)
{
	int i, j;

	vsystem("ip neigh flush nud permanent");

	for (i = 0; i < info->count; i++) {
		for (j = 0; j < info->iface[i].ipv4.neigh.count; j++)
			vasystem("ip neigh add %s lladdr %s nud permanent dev %s", info->iface[i].ipv4.neigh.ip[j].address, info->iface[i].ipv4.neigh.ip[j].value, info->iface[i].name);
<commit_msg>properly quote the dns paramters<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <assert.h>

#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include <stdarg.h>
#include <inttypes.h>
#include <fcntl.h>
#include <time.h>
#include <limits.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/queue.h>
#include <sys/tree.h>
#include <sys/resource.h>
#include <sys/syscall.h>
#include <arpa/inet.h>
#include <errno.h>
#include <ctype.h>
#include <signal.h>
#include <syslog.h>
#include <getopt.h>

#define USE_DEBUG

#include <event.h>

#include <mand/logx.h>

#ifdef HAVE_TALLOC_TALLOC_H
# include <talloc/talloc.h>
#else
# include <talloc.h>
#endif

#include "cfgd.h"
#include "comm.h"

static const char _ident[] = "cfgd v" VERSION;
static const char _build[] = "build on " __DATE__ " " __TIME__ " with gcc " __VERSION__;

struct event_base *ev_base;


int vsystem(const char *cmd)
{
        int rc = 0;
        int _errno;

        fprintf(stderr, "cmd=[%s]\n", cmd);

        errno = 0;
        rc = system(cmd);

        _errno = errno;
        fprintf(stderr, "cmd=[%s], rc=%d, error=%s\n", cmd, rc, strerror(_errno));
	errno = _errno;

        return rc;
}

int vasystem(const char *fmt, ...)
{
        va_list args;
        char    buf[1024];

        va_start(args, fmt);
        vsnprintf(buf, sizeof(buf), fmt, args);
        va_end(args);

        return vsystem(buf);
}

void set_ntp_server(const struct ntp_servers *servers)
{
	int i;

	vsystem("uci delete system.ntp.server");
	for (i = 0; i < servers->count; i++) {
		vasystem("uci add_list system.ntp.server='%s'", servers->server[i]);
	}
	vsystem("uci commit system.ntp.server");
	vsystem("/etc/init.d/sysntpd restart");
}

void set_dns(const struct string_list *search, const struct string_list *servers)
{
	char *s;
	int i;

	s = talloc_strdup(NULL, "uci set dnsmasq.server");
	for (i = 0; i < servers->count; i++) {
		s = talloc_asprintf_append(s, " %s", servers->s[i]);
	}
	talloc_free(s);

	if (search->count != 0)
		vasystem("uci set dhcp.@dnsmasq[0].domain=\"%s\"", search->s[0]);
	vsystem("uci commit dhcp");
	vsystem("/etc/init.d/dnsmasq restart");
}

void set_if_addr(struct interface_list *info)
{
	int i, j;

	for (i = 0; i < info->count; i++) {
		for (j = 0; j < info->iface[i].ipv4.addr.count; j++) {
			vasystem("uci set network.%s.ipaddr=%s", info->iface[i].name, info->iface[i].ipv4.addr.ip[j].address);
			vasystem("uci set network.%s.netmask=%s", info->iface[i].name, info->iface[i].ipv4.addr.ip[j].value);
		}
		for (j = 0; j < info->iface[i].ipv6.addr.count; j++)
			vasystem("uci set network.%s.ip6addr=%s/%s", info->iface[i].name, info->iface[i].ipv6.addr.ip[j].address, info->iface[i].ipv6.addr.ip[j].value);
	}
}

void set_if_neigh(struct interface_list *info)
{
	int i, j;

	vsystem("ip neigh flush nud permanent");

	for (i = 0; i < info->count; i++) {
		for (j = 0; j < info->iface[i].ipv4.neigh.count; j++)
			vasystem("ip neigh add %s lladdr %s nud permanent dev %s", info->iface[i].ipv4.neigh.ip[j].address, info->iface[i].ipv4.neigh.ip[j].value, info->iface[i].name);

{'fraction_non_alphanumeric': 0.1851963291710546, 'fraction_numerical': 0.009026628554234993, 'mean_word_length': 3.7148936170212767, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 97, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2162170', 'n_tokens_mistral': 2743, 'n_tokens_neox': 2675, 'n_words': 631}