if (message) {
g_variant_get(message, "(a(oa{sv}))", &iter);
- while (g_variant_iter_loop(iter, "(oa{sv})", &key, &value)) {
+ if (g_variant_iter_loop(iter, "(oa{sv})", &key, &value))
profile = strdup(key);
- break;
- }
if (value)
g_variant_iter_free(value);
return VPNSVC_ERROR_NONE;
}
-static int _check_config_str(void)
-{
- char *buf = NULL;
- size_t len;
-
- len = confstr(_CS_PATH, NULL, 0);
- if (len == 0)
- return -1;
-
- if ((buf = malloc(len)) == NULL)
- return -1;
-
- if (confstr(_CS_PATH, buf, len) == 0) {
- free(buf);
- return -1;
- }
-
- free(buf);
-
- return 0;
-}
-
#if 0
static void dns_nat_register(char **vpn_dns_address, size_t nr_dns, char *vpn_device_address)
{
if (netconfig_execute_cmd(buf))
ERR("Failed to execute command: %s", buf);
- memset(buf, '0', sizeof(buf));
+ memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf), IPTABLES_FMT_FLUSH_CHAIN_FROM_NAT,
iptables_cmd, iptables_nat_chain_name);
if (netconfig_execute_cmd(buf))
ERR("Failed to execute command: %s", buf);
- memset(buf, '0', sizeof(buf));
+ memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf), IPTABLES_FMT_DEL_CHAIN_FROM_NAT,
iptables_cmd, iptables_nat_chain_name);
if (netconfig_execute_cmd(buf))
if (netconfig_execute_cmd(buf))
ERR("Failed to execute command: %s", buf);
- memset(buf, '0', sizeof(buf));
+ memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf), IPTABLES_FMT_FLUSH_CHAIN,
iptables_cmd, iptables_filter_prefix, filter);
if (netconfig_execute_cmd(buf))
ERR("Failed to execute command: %s", buf);
- memset(buf, '0', sizeof(buf));
+ memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf), IPTABLES_FMT_APPEND_DROP_RULE,
iptables_cmd, iptables_filter_prefix, filter);
if (netconfig_execute_cmd(buf))
ERR("Failed to execute command: %s", buf);
- memset(buf, '0', sizeof(buf));
+ memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf), IPTABLES_FMT_APPEND_RETURN_RULE,
iptables_cmd, iptables_filter_prefix, filter);
if (netconfig_execute_cmd(buf))
ERR("Failed to execute command: %s", buf);
- memset(buf, '0', sizeof(buf));
+ memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf), IPTABLES_FMT_INSERT_RULE,
iptables_cmd, filter, iptables_filter_prefix, filter);
filter = iptables_filter_in;
- memset(buf, '0', sizeof(buf));
+ memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf), IPTABLES_FMT_CREATE_CHAIN,
iptables_cmd, iptables_filter_prefix, filter);
if (netconfig_execute_cmd(buf))
ERR("Failed to execute command: %s", buf);
- memset(buf, '0', sizeof(buf));
+ memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf), IPTABLES_FMT_FLUSH_CHAIN,
iptables_cmd, iptables_filter_prefix, filter);
if (netconfig_execute_cmd(buf))
ERR("Failed to execute command: %s", buf);
- memset(buf, '0', sizeof(buf));
+ memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf), IPTABLES_FMT_APPEND_DROP_RULE,
iptables_cmd, iptables_filter_prefix, filter);
if (netconfig_execute_cmd(buf))
ERR("Failed to execute command: %s", buf);
- memset(buf, '0', sizeof(buf));
+ memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf), IPTABLES_FMT_APPEND_RETURN_RULE,
iptables_cmd, iptables_filter_prefix, filter);
if (netconfig_execute_cmd(buf))
ERR("Failed to execute command: %s", buf);
- memset(buf, '0', sizeof(buf));
+ memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf), IPTABLES_FMT_INSERT_RULE,
iptables_cmd, filter, iptables_filter_prefix, filter);
}
if (netconfig_execute_cmd(buf))
ERR("Failed to execute command: %s", buf);
- memset(buf, '0', sizeof(buf));
+ memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf), IPTABLES_FMT_FLUSH_CHAIN,
iptables_cmd, iptables_filter_prefix, filter);
if (netconfig_execute_cmd(buf))
ERR("Failed to execute command: %s", buf);
- memset(buf, '0', sizeof(buf));
+ memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf), IPTABLES_FMT_DEL_CHAIN,
iptables_cmd, iptables_filter_prefix, filter);
if (netconfig_execute_cmd(buf))
filter = iptables_filter_in;
- memset(buf, '0', sizeof(buf));
+ memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf), IPTABLES_FMT_DEL_RULE,
iptables_cmd, filter, iptables_filter_prefix, filter);
if (netconfig_execute_cmd(buf))
ERR("Failed to execute command: %s", buf);
- memset(buf, '0', sizeof(buf));
+ memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf), IPTABLES_FMT_FLUSH_CHAIN,
iptables_cmd, iptables_filter_prefix, filter);
if (netconfig_execute_cmd(buf))
ERR("Failed to execute command: %s", buf);
- memset(buf, '0', sizeof(buf));
+ memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf), IPTABLES_FMT_DEL_CHAIN,
iptables_cmd, iptables_filter_prefix, filter);
if (netconfig_execute_cmd(buf))
if (netconfig_execute_cmd(buf))
ERR("Failed to execute command: %s", buf);
- memset(buf, '0', sizeof(buf));
+ memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf), IPTABLES_FMT_APPEND_ACCEPT_RULE,
iptables_cmd, c, iptables_filter_prefix,
iptables_filter_in, 's', addr, mask);
if (netconfig_execute_cmd(buf))
ERR("Failed to execute command: %s", buf);
- memset(buf, '0', sizeof(buf));
+ memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf), IPTABLES_FMT_APPEND_ACCEPT_RULE_WITH_INTF,
iptables_cmd, c, iptables_filter_prefix, iptables_filter_in,
'i', interface, 's', addr, mask);
memset(&ifr, 0, sizeof(ifr));
if (*iface_name)
- strncpy(ifr.ifr_name, iface_name, IFNAMSIZ);
+ strncpy(ifr.ifr_name, iface_name, IFNAMSIZ - 1);
/* get an interface name by ifindex */
if (ioctl(sk, SIOCGIFINDEX, &ifr) < 0) {
int vpn_service_init(const char* iface_name, size_t iface_name_len, int fd, vpnsvc_tun_s *handle_s)
{
struct ifreq ifr;
- size_t len = 0;
char buf[BUF_SIZE_FOR_ERR] = { 0 };
- DBG("enter vpn_daemon_init, iface_name : %s, iface_name_len : %d, fd : %d\n", iface_name, iface_name_len, fd);
+ DBG("enter vpn_daemon_init, iface_name : %s, iface_name_len : %zd, fd : %d\n", iface_name, iface_name_len, fd);
memset(&ifr, 0, sizeof(ifr));
if (*iface_name)
strncpy(ifr.ifr_name, iface_name, iface_name_len);
+ ifr.ifr_name[iface_name_len] = '\0';
DBG("before init, ifindex : %d", ifr.ifr_ifindex);
handle_s->fd = 0; /* server fd does not meaning */
handle_s->index = get_interface_index(iface_name);
- len = strlen(ifr.ifr_name);
- strncpy(handle_s->name, ifr.ifr_name, len);
- handle_s->name[len] = '\0';
+ g_strlcpy(handle_s->name, ifr.ifr_name, VPNSVC_VPN_IFACE_NAME_LEN);
return VPNSVC_ERROR_NONE;
}
int vpn_service_deinit(const char* dev_name)
{
- char buf[100], *cmd;
- FILE *fp = NULL;
-
- if (_check_config_str() != 0) {
- ERR("Failed to get configuration string");
- return VPNSVC_ERROR_IO_ERROR;
- }
+ char buf[100];
snprintf(buf, sizeof(buf), "/usr/sbin/ip link del %s", dev_name);
- cmd = g_try_malloc0(strlen(buf) + 1);
- strncpy(cmd, buf, strlen(buf));
-
- DBG("link delete cmd : %s", cmd);
-
- fp = popen(cmd, "r");
- g_free(cmd);
-
- if (fp != NULL) {
- pclose(fp);
- return VPNSVC_ERROR_NONE;
- } else {
+ if (netconfig_execute_cmd(buf)) {
+ ERR("Failed to execute command: %s", buf);
return VPNSVC_ERROR_IO_ERROR;
}
+
+ return VPNSVC_ERROR_NONE;
}
int vpn_service_protect(int socket_fd, const char* dev_name)