int main(int argc, char *argv[]) { GOptionContext *context; GError *error = NULL; int err; g_test_init(&argc, &argv, NULL); context = g_option_context_new(NULL); g_option_context_add_main_entries(context, options, NULL); if (!g_option_context_parse(context, &argc, &argv, &error)) { if (error) { g_printerr("%s\n", error->message); g_error_free(error); } else g_printerr("An unknown error occurred\n"); return 1; } g_option_context_free(context); __connman_log_init(argv[0], option_debug, false, false, "Unit Tests Connection Manager", VERSION); __connman_iptables_init(); __connman_firewall_init(); __connman_nat_init(); g_test_add_func("/iptables/chain0", test_iptables_chain0); g_test_add_func("/iptables/chain1", test_iptables_chain1); g_test_add_func("/iptables/chain2", test_iptables_chain2); g_test_add_func("/iptables/chain3", test_iptables_chain3); g_test_add_func("/iptables/rule0", test_iptables_rule0); g_test_add_func("/iptables/rule1", test_iptables_rule1); g_test_add_func("/iptables/rule2", test_iptables_rule2); g_test_add_func("/iptables/target0", test_iptables_target0); g_test_add_func("/nat/basic0", test_nat_basic0); g_test_add_func("/nat/basic1", test_nat_basic1); g_test_add_func("/firewall/basic0", test_firewall_basic0); g_test_add_func("/firewall/basic1", test_firewall_basic1); g_test_add_func("/firewall/basic2", test_firewall_basic2); err = g_test_run(); __connman_nat_cleanup(); __connman_firewall_cleanup(); __connman_iptables_cleanup(); g_free(option_debug); return err; }
int main(int argc, char *argv[]) { GOptionContext *context; GError *error = NULL; DBusConnection *conn; DBusError err; guint signal; context = g_option_context_new(NULL); g_option_context_add_main_entries(context, options, NULL); if (!g_option_context_parse(context, &argc, &argv, &error)) { if (error) { g_printerr("%s\n", error->message); g_error_free(error); } else g_printerr("An unknown error occurred\n"); exit(1); } g_option_context_free(context); if (option_version) { printf("%s\n", VERSION); exit(0); } if (option_detach) { if (daemon(0, 0)) { perror("Can't start daemon"); exit(1); } } if (mkdir(VPN_STATEDIR, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0) { if (errno != EEXIST) perror("Failed to create state directory"); } /* * At some point the VPN stuff is migrated into VPN_STORAGEDIR * and this mkdir() call can be removed. */ if (mkdir(STORAGEDIR, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0) { if (errno != EEXIST) perror("Failed to create storage directory"); } if (mkdir(VPN_STORAGEDIR, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0) { if (errno != EEXIST) perror("Failed to create VPN storage directory"); } umask(0077); main_loop = g_main_loop_new(NULL, FALSE); signal = setup_signalfd(); dbus_error_init(&err); conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, VPN_SERVICE, &err); if (!conn) { if (dbus_error_is_set(&err)) { fprintf(stderr, "%s\n", err.message); dbus_error_free(&err); } else fprintf(stderr, "Can't register with system bus\n"); exit(1); } g_dbus_set_disconnect_function(conn, disconnect_callback, NULL, NULL); __connman_log_init(argv[0], option_debug, option_detach, false, "Connection Manager VPN daemon", VERSION); __connman_dbus_init(conn); __connman_inotify_init(); __connman_storage_init(); if (!option_config) config_init(CONFIGMAINFILE); else config_init(option_config); __connman_agent_init(); __vpn_provider_init(option_routes); __vpn_manager_init(); __vpn_ipconfig_init(); __vpn_rtnl_init(); __connman_task_init(); __connman_plugin_init(option_plugin, option_noplugin); __vpn_config_init(); __vpn_rtnl_start(); g_free(option_plugin); g_free(option_noplugin); g_main_loop_run(main_loop); g_source_remove(signal); __vpn_config_cleanup(); __connman_plugin_cleanup(); __connman_task_cleanup(); __vpn_rtnl_cleanup(); __vpn_ipconfig_cleanup(); __vpn_manager_cleanup(); __vpn_provider_cleanup(); __connman_agent_cleanup(); __connman_storage_cleanup(); __connman_inotify_cleanup(); __connman_dbus_cleanup(); __connman_log_cleanup(false); dbus_connection_unref(conn); g_main_loop_unref(main_loop); g_free(option_debug); return 0; }
int main(int argc, char *argv[]) { GOptionContext *context; GError *error = NULL; DBusConnection *conn; DBusError err; guint signal; #ifdef NEED_THREADS if (g_thread_supported() == FALSE) g_thread_init(NULL); #endif context = g_option_context_new(NULL); g_option_context_add_main_entries(context, options, NULL); if (g_option_context_parse(context, &argc, &argv, &error) == FALSE) { if (error != NULL) { g_printerr("%s\n", error->message); g_error_free(error); } else g_printerr("An unknown error occurred\n"); exit(1); } g_option_context_free(context); if (option_version == TRUE) { printf("%s\n", VERSION); exit(0); } if (option_detach == TRUE) { if (daemon(0, 0)) { perror("Can't start daemon"); exit(1); } } if (mkdir(STATEDIR, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0) { if (errno != EEXIST) perror("Failed to create state directory"); } if (mkdir(STORAGEDIR, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0) { if (errno != EEXIST) perror("Failed to create storage directory"); } umask(0077); main_loop = g_main_loop_new(NULL, FALSE); #ifdef NEED_THREADS if (dbus_threads_init_default() == FALSE) { fprintf(stderr, "Can't init usage of threads\n"); exit(1); } #endif signal = setup_signalfd(); dbus_error_init(&err); conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, CONNMAN_SERVICE, &err); if (conn == NULL) { if (dbus_error_is_set(&err) == TRUE) { fprintf(stderr, "%s\n", err.message); dbus_error_free(&err); } else fprintf(stderr, "Can't register with system bus\n"); exit(1); } g_dbus_set_disconnect_function(conn, disconnect_callback, NULL, NULL); __connman_log_init(argv[0], option_debug, option_detach, option_backtrace, "Connection Manager", VERSION); __connman_dbus_init(conn); if (option_config == NULL) config_init(CONFIGMAINFILE); else config_init(option_config); __connman_inotify_init(); __connman_technology_init(); __connman_notifier_init(); __connman_agent_init(); __connman_service_init(); __connman_provider_init(); __connman_network_init(); __connman_device_init(option_device, option_nodevice); __connman_ippool_init(); __connman_iptables_init(); __connman_firewall_init(); __connman_nat_init(); __connman_tethering_init(); __connman_counter_init(); __connman_manager_init(); __connman_config_init(); __connman_stats_init(); __connman_clock_init(); __connman_resolver_init(option_dnsproxy); __connman_ipconfig_init(); __connman_rtnl_init(); __connman_task_init(); __connman_proxy_init(); __connman_detect_init(); __connman_session_init(); __connman_timeserver_init(); __connman_connection_init(); __connman_plugin_init(option_plugin, option_noplugin); __connman_rtnl_start(); __connman_dhcp_init(); __connman_dhcpv6_init(); __connman_wpad_init(); __connman_wispr_init(); __connman_rfkill_init(); g_free(option_config); g_free(option_device); g_free(option_plugin); g_free(option_nodevice); g_free(option_noplugin); #ifdef SYSTEMD /* Tell systemd that we have started up */ if( option_systemd ) sd_notify(0, "READY=1"); #endif g_main_loop_run(main_loop); g_source_remove(signal); __connman_rfkill_cleanup(); __connman_wispr_cleanup(); __connman_wpad_cleanup(); __connman_dhcpv6_cleanup(); __connman_dhcp_cleanup(); __connman_session_cleanup(); __connman_plugin_cleanup(); __connman_provider_cleanup(); __connman_connection_cleanup(); __connman_timeserver_cleanup(); __connman_detect_cleanup(); __connman_proxy_cleanup(); __connman_task_cleanup(); __connman_rtnl_cleanup(); __connman_resolver_cleanup(); __connman_clock_cleanup(); __connman_stats_cleanup(); __connman_config_cleanup(); __connman_manager_cleanup(); __connman_counter_cleanup(); __connman_tethering_cleanup(); __connman_nat_cleanup(); __connman_firewall_cleanup(); __connman_iptables_cleanup(); __connman_ippool_cleanup(); __connman_device_cleanup(); __connman_network_cleanup(); __connman_service_cleanup(); __connman_agent_cleanup(); __connman_ipconfig_cleanup(); __connman_notifier_cleanup(); __connman_technology_cleanup(); __connman_inotify_cleanup(); __connman_dbus_cleanup(); __connman_log_cleanup(option_backtrace); dbus_connection_unref(conn); g_main_loop_unref(main_loop); if (connman_settings.pref_timeservers != NULL) g_strfreev(connman_settings.pref_timeservers); g_free(connman_settings.auto_connect); g_free(connman_settings.preferred_techs); g_strfreev(connman_settings.fallback_nameservers); g_strfreev(connman_settings.blacklisted_interfaces); g_strfreev(connman_settings.tethering_technologies); g_free(option_debug); return 0; }
int main(int argc, char *argv[]) { GOptionContext *context; GError *error = NULL; DBusConnection *conn; DBusError err; struct sigaction sa; mode_t old_umask; #ifdef NEED_THREADS if (g_thread_supported() == FALSE) g_thread_init(NULL); #endif context = g_option_context_new(NULL); g_option_context_add_main_entries(context, options, NULL); if (g_option_context_parse(context, &argc, &argv, &error) == FALSE) { if (error != NULL) { g_printerr("%s\n", error->message); g_error_free(error); } else g_printerr("An unknown error occurred\n"); exit(1); } g_option_context_free(context); if (option_version == TRUE) { printf("%s\n", VERSION); exit(0); } if (option_detach == TRUE) { if (daemon(0, 0)) { perror("Can't start daemon"); exit(1); } } if (mkdir(STATEDIR, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0) { if (errno != EEXIST) perror("Failed to create state directory"); } if (mkdir(STORAGEDIR, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0) { if (errno != EEXIST) perror("Failed to create storage directory"); } old_umask = umask(077); main_loop = g_main_loop_new(NULL, FALSE); #ifdef NEED_THREADS if (dbus_threads_init_default() == FALSE) { fprintf(stderr, "Can't init usage of threads\n"); exit(1); } #endif dbus_error_init(&err); conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, CONNMAN_SERVICE, &err); if (conn == NULL) { if (dbus_error_is_set(&err) == TRUE) { fprintf(stderr, "%s\n", err.message); dbus_error_free(&err); } else fprintf(stderr, "Can't register with system bus\n"); exit(1); } g_dbus_set_disconnect_function(conn, disconnect_callback, NULL, NULL); if (option_compat == TRUE) { if (g_dbus_request_name(conn, NM_SERVICE, NULL) == FALSE) { fprintf(stderr, "Can't register compat service\n"); option_compat = FALSE; } } __connman_log_init(option_detach, option_debug ? DBG_ANY : 0); if (option_selftest == TRUE) { if (__connman_selftest() < 0) { connman_error("Self testing routines failed"); goto selftest; } } __connman_dbus_init(conn); __connman_storage_init(); __connman_element_init(option_device, option_nodevice); __connman_agent_init(); __connman_manager_init(option_compat); __connman_profile_init(); __connman_resolver_init(); __connman_ipconfig_init(); __connman_rtnl_init(); __connman_udev_init(); __connman_task_init(); __connman_plugin_init(option_plugin, option_noplugin); __connman_element_start(); g_free(option_device); g_free(option_plugin); g_free(option_nodevice); g_free(option_noplugin); memset(&sa, 0, sizeof(sa)); sa.sa_handler = sig_term; sigaction(SIGINT, &sa, NULL); sigaction(SIGTERM, &sa, NULL); g_main_loop_run(main_loop); __connman_element_stop(); __connman_plugin_cleanup(); __connman_task_cleanup(); __connman_udev_cleanup(); __connman_rtnl_cleanup(); __connman_ipconfig_cleanup(); __connman_resolver_cleanup(); __connman_profile_cleanup(); __connman_manager_cleanup(); __connman_agent_cleanup(); __connman_element_cleanup(); __connman_storage_cleanup(); __connman_dbus_cleanup(); selftest: __connman_log_cleanup(); dbus_connection_unref(conn); g_main_loop_unref(main_loop); return 0; }
int main(int argc, char *argv[]) { enum iptables_command cmd = IPTABLES_COMMAND_UNKNOWN; char *table = NULL, *chain = NULL, *rule = NULL, *tmp; int err, c, i; opterr = 0; while ((c = getopt_long(argc, argv, "-A:I:D:P:N:X:F:Lt:", NULL, NULL)) != -1) { switch (c) { case 'A': chain = optarg; cmd = IPTABLES_COMMAND_APPEND; break; case 'I': chain = optarg; cmd = IPTABLES_COMMAND_INSERT; break; case 'D': chain = optarg; cmd = IPTABLES_COMMAND_DELETE; break; case 'P': chain = optarg; /* The policy will be stored in rule. */ cmd = IPTABLES_COMMAND_POLICY; break; case 'N': chain = optarg; cmd = IPTABLES_COMMAND_CHAIN_INSERT; break; case 'X': chain = optarg; cmd = IPTABLES_COMMAND_CHAIN_DELETE; break; case 'F': chain = optarg; cmd = IPTABLES_COMMAND_CHAIN_FLUSH; break; case 'L': cmd = IPTABLES_COMMAND_DUMP; break; case 't': table = optarg; break; default: goto out; } } out: if (table == NULL) table = "filter"; for (i = optind - 1; i < argc; i++) { if (rule != NULL) { tmp = rule; rule = g_strdup_printf("%s %s", rule, argv[i]); g_free(tmp); } else rule = g_strdup(argv[i]); } __connman_iptables_init(); switch (cmd) { case IPTABLES_COMMAND_APPEND: err = __connman_iptables_append(table, chain, rule); break; case IPTABLES_COMMAND_INSERT: err = __connman_iptables_insert(table, chain, rule); break; case IPTABLES_COMMAND_DELETE: err = __connman_iptables_delete(table, chain, rule); break; case IPTABLES_COMMAND_POLICY: err = __connman_iptables_change_policy(table, chain, rule); break; case IPTABLES_COMMAND_CHAIN_INSERT: err = __connman_iptables_new_chain(table, chain); break; case IPTABLES_COMMAND_CHAIN_DELETE: err = __connman_iptables_delete_chain(table, chain); break; case IPTABLES_COMMAND_CHAIN_FLUSH: err = __connman_iptables_flush_chain(table, chain); break; case IPTABLES_COMMAND_DUMP: __connman_log_init(argv[0], "*", FALSE, FALSE, "iptables-test", "1"); err = __connman_iptables_dump(table); break; case IPTABLES_COMMAND_UNKNOWN: printf("Missing command\n"); printf("usage: iptables-test [-t table] {-A|-I|-D} chain rule\n"); printf(" iptables-test [-t table] {-N|-X|-F} chain\n"); printf(" iptables-test [-t table] -L\n"); printf(" iptables-test [-t table] -P chain target\n"); exit(-EINVAL); } if (err < 0) { printf("Error: %s\n", strerror(-err)); exit(err); } err = __connman_iptables_commit(table); if (err < 0) { printf("Failed to commit changes: %s\n", strerror(-err)); exit(err); } g_free(rule); __connman_iptables_cleanup(); return 0; }