void dsl_connection_new (FUNC_TAG_PAGE_NEW_CONNECTION_IMPL, GtkWindow *parent, const char *detail, gpointer detail_data, NMConnection *connection, NMClient *client, PageNewConnectionResultFunc result_func, gpointer user_data) { NMSetting *setting; gs_unref_object NMConnection *connection_tmp = NULL; connection = _ensure_connection_other (connection, &connection_tmp); ce_page_complete_connection (connection, _("DSL connection %d"), NM_SETTING_PPPOE_SETTING_NAME, FALSE, client); nm_connection_add_setting (connection, nm_setting_pppoe_new ()); nm_connection_add_setting (connection, nm_setting_wired_new ()); setting = nm_setting_ppp_new (); /* Set default values for lcp-echo-failure and lcp-echo-interval */ g_object_set (G_OBJECT (setting), NM_SETTING_PPP_LCP_ECHO_FAILURE, 5, NM_SETTING_PPP_LCP_ECHO_INTERVAL, 30, NULL); nm_connection_add_setting (connection, setting); (*result_func) (FUNC_TAG_PAGE_NEW_CONNECTION_RESULT_CALL, connection, FALSE, NULL, user_data); }
CEPage * ce_page_ppp_new (NMConnection *connection, GtkWindow *parent_window, NMClient *client, const char **out_secrets_setting_name, GError **error) { CEPagePpp *self; CEPagePppPrivate *priv; NMSettingConnection *s_con; self = CE_PAGE_PPP (ce_page_new (CE_TYPE_PAGE_PPP, connection, parent_window, client, UIDIR "/ce-page-ppp.ui", "PppPage", _("PPP Settings"))); if (!self) { g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("Could not load PPP user interface.")); return NULL; } ppp_private_init (self); priv = CE_PAGE_PPP_GET_PRIVATE (self); priv->setting = nm_connection_get_setting_ppp (connection); if (!priv->setting) { priv->setting = NM_SETTING_PPP (nm_setting_ppp_new ()); g_object_set (G_OBJECT (priv->setting), NM_SETTING_PPP_LCP_ECHO_FAILURE, 5, NM_SETTING_PPP_LCP_ECHO_INTERVAL, 30, NULL); nm_connection_add_setting (connection, NM_SETTING (priv->setting)); } priv->window_group = gtk_window_group_new (); s_con = nm_connection_get_setting_connection (connection); g_assert (s_con); priv->connection_id = g_strdup (nm_setting_connection_get_id (s_con)); g_signal_connect (self, "initialized", G_CALLBACK (finish_setup), NULL); *out_secrets_setting_name = NM_SETTING_PPP_SETTING_NAME; return CE_PAGE (self); }
static NMConnection * dun_new_gsm (NMAMobileWizardAccessMethod *method) { NMConnection *connection; NMSetting *setting; char *uuid, *id; connection = nm_connection_new (); setting = nm_setting_gsm_new (); g_object_set (setting, NM_SETTING_GSM_NUMBER, "*99#", NM_SETTING_GSM_USERNAME, method->username, NM_SETTING_GSM_PASSWORD, method->password, NM_SETTING_GSM_PASSWORD_FLAGS, NM_SETTING_SECRET_FLAG_AGENT_OWNED, NM_SETTING_GSM_APN, method->gsm_apn, NULL); nm_connection_add_setting (connection, setting); /* Serial setting */ setting = nm_setting_serial_new (); g_object_set (setting, NM_SETTING_SERIAL_BAUD, 115200, NM_SETTING_SERIAL_BITS, 8, NM_SETTING_SERIAL_PARITY, 'n', NM_SETTING_SERIAL_STOPBITS, 1, NULL); nm_connection_add_setting (connection, setting); nm_connection_add_setting (connection, nm_setting_ppp_new ()); setting = nm_setting_connection_new (); id = utils_create_mobile_connection_id (method->provider_name, method->plan_name); uuid = nm_utils_uuid_generate (); g_object_set (setting, NM_SETTING_CONNECTION_ID, id, NM_SETTING_CONNECTION_TYPE, NM_SETTING_BLUETOOTH_SETTING_NAME, NM_SETTING_CONNECTION_AUTOCONNECT, FALSE, NM_SETTING_CONNECTION_UUID, uuid, NULL); g_free (uuid); g_free (id); nm_setting_connection_add_permission ((NMSettingConnection *) setting, "user", g_get_user_name (), NULL); nm_connection_add_setting (connection, setting); return connection; }
static NMConnection * dun_new_cdma (NMAMobileWizardAccessMethod *method) { NMConnection *connection; NMSetting *setting; char *uuid, *id; connection = nm_connection_new (); setting = nm_setting_cdma_new (); g_object_set (setting, NM_SETTING_CDMA_NUMBER, "#777", NM_SETTING_CDMA_USERNAME, method->username, NM_SETTING_CDMA_PASSWORD, method->password, NULL); nm_connection_add_setting (connection, setting); /* Serial setting */ setting = nm_setting_serial_new (); g_object_set (setting, NM_SETTING_SERIAL_BAUD, 115200, NM_SETTING_SERIAL_BITS, 8, NM_SETTING_SERIAL_PARITY, 'n', NM_SETTING_SERIAL_STOPBITS, 1, NULL); nm_connection_add_setting (connection, setting); nm_connection_add_setting (connection, nm_setting_ppp_new ()); setting = nm_setting_connection_new (); id = utils_create_mobile_connection_id (method->provider_name, method->plan_name); uuid = nm_utils_uuid_generate (); g_object_set (setting, NM_SETTING_CONNECTION_ID, id, NM_SETTING_CONNECTION_TYPE, NM_SETTING_BLUETOOTH_SETTING_NAME, NM_SETTING_CONNECTION_AUTOCONNECT, FALSE, NM_SETTING_CONNECTION_UUID, uuid, NULL); g_free (uuid); g_free (id); nm_connection_add_setting (connection, setting); return connection; }
static gboolean complete_connection (NMModem *modem, NMConnection *connection, const GSList *existing_connections, GError **error) { NMSettingGsm *s_gsm; NMSettingPPP *s_ppp; s_gsm = nm_connection_get_setting_gsm (connection); if (!s_gsm || !nm_setting_gsm_get_apn (s_gsm)) { /* Need an APN at least */ g_set_error_literal (error, NM_SETTING_GSM_ERROR, NM_SETTING_GSM_ERROR_MISSING_PROPERTY, NM_SETTING_GSM_APN); return FALSE; } if (!nm_setting_gsm_get_number (s_gsm)) g_object_set (G_OBJECT (s_gsm), NM_SETTING_GSM_NUMBER, "*99#", NULL); s_ppp = nm_connection_get_setting_ppp (connection); if (!s_ppp) { s_ppp = (NMSettingPPP *) nm_setting_ppp_new (); g_object_set (G_OBJECT (s_ppp), NM_SETTING_PPP_LCP_ECHO_FAILURE, 5, NM_SETTING_PPP_LCP_ECHO_INTERVAL, 30, NULL); nm_connection_add_setting (connection, NM_SETTING (s_ppp)); } nm_utils_complete_generic (connection, NM_SETTING_GSM_SETTING_NAME, existing_connections, _("GSM connection %d"), NULL, FALSE); /* No IPv6 yet by default */ return TRUE; }
static void nmt_page_ppp_constructed (GObject *object) { NmtPagePpp *ppp = NMT_PAGE_PPP (object); NmtPagePppPrivate *priv = NMT_PAGE_PPP_GET_PRIVATE (ppp); NmtEditorSection *section; NmtEditorGrid *grid; NMSettingPpp *s_ppp; NmtNewtWidget *widget, *use_mppe; NmtNewtGrid *auth_grid, *mppe_grid; NmtNewtSection *auth_section, *mppe_section; NMConnection *conn; conn = nmt_editor_page_get_connection (NMT_EDITOR_PAGE (ppp)); s_ppp = nm_connection_get_setting_ppp (conn); if (s_ppp) { priv->lcp_echo_interval = nm_setting_ppp_get_lcp_echo_interval (s_ppp); priv->lcp_echo_failure = nm_setting_ppp_get_lcp_echo_failure (s_ppp); } else { s_ppp = (NMSettingPpp *) nm_setting_ppp_new (); nm_connection_add_setting (conn, (NMSetting *) s_ppp); priv->lcp_echo_interval = 30; priv->lcp_echo_failure = 5; } section = nmt_editor_section_new (_("PPP CONFIGURATION"), NULL, TRUE); grid = nmt_editor_section_get_body (section); /* Auth methods */ widget = nmt_newt_section_new (FALSE); auth_section = NMT_NEWT_SECTION (widget); g_object_set (auth_section, "open", TRUE, NULL); nmt_editor_grid_append (grid, NULL, widget, NULL); widget = nmt_newt_label_new (_("Allowed authentication methods:")); nmt_newt_section_set_header (auth_section, widget); widget = nmt_newt_grid_new (); auth_grid = NMT_NEWT_GRID (widget); nmt_newt_section_set_body (auth_section, widget); widget = nmt_newt_checkbox_new (_("EAP")); g_object_bind_property (s_ppp, NM_SETTING_PPP_REFUSE_EAP, widget, "active", G_BINDING_BIDIRECTIONAL | G_BINDING_INVERT_BOOLEAN | G_BINDING_SYNC_CREATE); nmt_newt_grid_add (auth_grid, widget, 0, 0); widget = nmt_newt_checkbox_new (_("PAP")); g_object_bind_property (s_ppp, NM_SETTING_PPP_REFUSE_PAP, widget, "active", G_BINDING_BIDIRECTIONAL | G_BINDING_INVERT_BOOLEAN | G_BINDING_SYNC_CREATE); nmt_newt_grid_add (auth_grid, widget, 0, 1); widget = nmt_newt_checkbox_new (_("CHAP")); g_object_bind_property (s_ppp, NM_SETTING_PPP_REFUSE_CHAP, widget, "active", G_BINDING_BIDIRECTIONAL | G_BINDING_INVERT_BOOLEAN | G_BINDING_SYNC_CREATE); nmt_newt_grid_add (auth_grid, widget, 0, 2); widget = nmt_newt_checkbox_new (_("MSCHAPv2")); g_object_bind_property (s_ppp, NM_SETTING_PPP_REFUSE_MSCHAPV2, widget, "active", G_BINDING_BIDIRECTIONAL | G_BINDING_INVERT_BOOLEAN | G_BINDING_SYNC_CREATE); nmt_newt_grid_add (auth_grid, widget, 0, 3); widget = nmt_newt_checkbox_new (_("MSCHAP")); g_object_bind_property (s_ppp, NM_SETTING_PPP_REFUSE_MSCHAP, widget, "active", G_BINDING_BIDIRECTIONAL | G_BINDING_INVERT_BOOLEAN | G_BINDING_SYNC_CREATE); nmt_newt_grid_add (auth_grid, widget, 0, 4); nmt_editor_grid_append (grid, NULL, nmt_newt_separator_new (), NULL); /* MPPE */ widget = nmt_newt_section_new (FALSE); mppe_section = NMT_NEWT_SECTION (widget); g_object_set (mppe_section, "open", TRUE, NULL); nmt_editor_grid_append (grid, NULL, widget, NULL); widget = nmt_newt_checkbox_new (_("Use point-to-point encryption (MPPE)")); g_object_bind_property (s_ppp, NM_SETTING_PPP_REQUIRE_MPPE, widget, "active", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); use_mppe = widget; nmt_newt_section_set_header (mppe_section, widget); widget = nmt_newt_grid_new (); mppe_grid = NMT_NEWT_GRID (widget); nmt_newt_section_set_body (mppe_section, widget); widget = nmt_newt_checkbox_new (_("Require 128-bit encryption")); g_object_bind_property (use_mppe, "active", widget, "sensitive", G_BINDING_SYNC_CREATE); g_object_bind_property (s_ppp, NM_SETTING_PPP_REQUIRE_MPPE_128, widget, "active", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); nmt_newt_grid_add (mppe_grid, widget, 0, 0); widget = nmt_newt_checkbox_new (_("Use stateful MPPE")); g_object_bind_property (use_mppe, "active", widget, "sensitive", G_BINDING_SYNC_CREATE); g_object_bind_property (s_ppp, NM_SETTING_PPP_MPPE_STATEFUL, widget, "active", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); nmt_newt_grid_add (mppe_grid, widget, 0, 1); nmt_editor_grid_append (grid, NULL, nmt_newt_separator_new (), NULL); widget = nmt_newt_checkbox_new (_("Allow BSD data compression")); g_object_bind_property (s_ppp, NM_SETTING_PPP_NOBSDCOMP, widget, "active", G_BINDING_BIDIRECTIONAL | G_BINDING_INVERT_BOOLEAN | G_BINDING_SYNC_CREATE); nmt_editor_grid_append (grid, NULL, widget, NULL); widget = nmt_newt_checkbox_new (_("Allow Deflate data compression")); g_object_bind_property (s_ppp, NM_SETTING_PPP_NODEFLATE, widget, "active", G_BINDING_BIDIRECTIONAL | G_BINDING_INVERT_BOOLEAN | G_BINDING_SYNC_CREATE); nmt_editor_grid_append (grid, NULL, widget, NULL); widget = nmt_newt_checkbox_new (_("Use TCP header compression")); g_object_bind_property (s_ppp, NM_SETTING_PPP_NO_VJ_COMP, widget, "active", G_BINDING_BIDIRECTIONAL | G_BINDING_INVERT_BOOLEAN | G_BINDING_SYNC_CREATE); nmt_editor_grid_append (grid, NULL, widget, NULL); nmt_editor_grid_append (grid, NULL, nmt_newt_separator_new (), NULL); widget = nmt_newt_checkbox_new (_("Send PPP echo packets")); g_object_bind_property_full (s_ppp, NM_SETTING_PPP_LCP_ECHO_INTERVAL, widget, "active", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE, transform_lcp_echo_properties_to_checkbox, transform_checkbox_to_lcp_echo_interval, ppp, NULL); g_object_bind_property_full (s_ppp, NM_SETTING_PPP_LCP_ECHO_FAILURE, widget, "active", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE, transform_lcp_echo_properties_to_checkbox, transform_checkbox_to_lcp_echo_failure, ppp, NULL); nmt_editor_grid_append (grid, NULL, widget, NULL); nmt_editor_page_add_section (NMT_EDITOR_PAGE (ppp), section); G_OBJECT_CLASS (nmt_page_ppp_parent_class)->constructed (object); }
static void new_connection_mobile_wizard_done (NMAMobileWizard *wizard, gboolean canceled, NMAMobileWizardAccessMethod *method, gpointer user_data) { WizardInfo *info = user_data; NMConnection *connection = NULL; if (!canceled && method) { NMSetting *type_setting; const char *ctype = NULL; char *detail = NULL; switch (method->devtype) { case NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS: ctype = NM_SETTING_GSM_SETTING_NAME; type_setting = nm_setting_gsm_new (); /* De-facto standard for GSM */ g_object_set (type_setting, NM_SETTING_GSM_NUMBER, "*99#", NM_SETTING_GSM_USERNAME, method->username, NM_SETTING_GSM_PASSWORD, method->password, NM_SETTING_GSM_APN, method->gsm_apn, NULL); break; case NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO: ctype = NM_SETTING_CDMA_SETTING_NAME; type_setting = nm_setting_cdma_new (); /* De-facto standard for CDMA */ g_object_set (type_setting, NM_SETTING_CDMA_NUMBER, "#777", NM_SETTING_GSM_USERNAME, method->username, NM_SETTING_GSM_PASSWORD, method->password, NULL); break; default: g_assert_not_reached (); break; } if (method->plan_name) detail = g_strdup_printf ("%s %s %%d", method->provider_name, method->plan_name); else detail = g_strdup_printf ("%s connection %%d", method->provider_name); connection = ce_page_new_connection (detail, ctype, FALSE, info->settings, info->user_data); g_free (detail); nm_connection_add_setting (connection, type_setting); add_default_serial_setting (connection); nm_connection_add_setting (connection, nm_setting_ppp_new ()); } (*info->result_func) (connection, canceled, NULL, info->user_data); if (wizard) nma_mobile_wizard_destroy (wizard); g_object_unref (info->settings); g_free (info); }
static void mobile_wizard_done (NMAMobileWizard *wizard, gboolean cancelled, NMAMobileWizardAccessMethod *method, gpointer user_data) { AutoWizardInfo *info = user_data; NMConnection *connection = NULL; if (!cancelled && method) { NMSetting *setting; char *uuid, *id; const char *setting_name; if (method->devtype != info->requested_capability) { g_warning ("Unexpected device type"); cancelled = TRUE; goto done; } connection = nm_connection_new (); if (method->devtype == NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO) { setting_name = NM_SETTING_CDMA_SETTING_NAME; setting = nm_setting_cdma_new (); g_object_set (setting, NM_SETTING_CDMA_NUMBER, "#777", NM_SETTING_CDMA_USERNAME, method->username, NM_SETTING_CDMA_PASSWORD, method->password, NM_SETTING_CDMA_PASSWORD_FLAGS, NM_SETTING_SECRET_FLAG_AGENT_OWNED, NULL); nm_connection_add_setting (connection, setting); } else if (method->devtype == NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS) { setting_name = NM_SETTING_GSM_SETTING_NAME; setting = nm_setting_gsm_new (); g_object_set (setting, NM_SETTING_GSM_NUMBER, "*99#", NM_SETTING_GSM_USERNAME, method->username, NM_SETTING_GSM_PASSWORD, method->password, NM_SETTING_GSM_APN, method->gsm_apn, NM_SETTING_GSM_PASSWORD_FLAGS, NM_SETTING_SECRET_FLAG_AGENT_OWNED, NULL); nm_connection_add_setting (connection, setting); } else g_assert_not_reached (); /* Serial setting */ setting = nm_setting_serial_new (); g_object_set (setting, NM_SETTING_SERIAL_BAUD, 115200, NM_SETTING_SERIAL_BITS, 8, NM_SETTING_SERIAL_PARITY, 'n', NM_SETTING_SERIAL_STOPBITS, 1, NULL); nm_connection_add_setting (connection, setting); nm_connection_add_setting (connection, nm_setting_ppp_new ()); setting = nm_setting_connection_new (); id = utils_create_mobile_connection_id (method->provider_name, method->plan_name); uuid = nm_utils_uuid_generate (); g_object_set (setting, NM_SETTING_CONNECTION_ID, id, NM_SETTING_CONNECTION_TYPE, setting_name, NM_SETTING_CONNECTION_AUTOCONNECT, FALSE, NM_SETTING_CONNECTION_UUID, uuid, NULL); g_free (uuid); g_free (id); nm_setting_connection_add_permission ((NMSettingConnection *) setting, "user", g_get_user_name (), NULL); nm_connection_add_setting (connection, setting); } done: (*(info->callback)) (connection, TRUE, cancelled, info->callback_data); if (wizard) nma_mobile_wizard_destroy (wizard); g_free (info); }
static int add_connection (DBusGProxy *proxy, char *con_name, char *apn, char *pin, char *username, char *password, int ntype, char *number, char *auth, char *comp, char *aut, char *netid, char *enc, int ecoint, int ecofail, char *uuid, int sbits, char sparity, int stbits, int sbaud) { NMConnection *connection; NMSettingConnection *s_con; NMSettingIP4Config *s_ip4; NMSettingGsm *s_gsm; NMSettingPPP *s_ppp; NMSettingSerial *s_serial; char *new_con_path = NULL; GHashTable *hash; GError *error = NULL; int autoconnect = 1; int uuid_generated = 0; if ((aut != NULL) && (aut[0] != 't')) autoconnect = 0; connection = (NMConnection *)nm_connection_new (); if (connection == NULL){ printf("Unable to allocate new connection... Sorry.\n"); return NMC_RESULT_ERROR_CON_ADD; } s_con = (NMSettingConnection *) nm_setting_connection_new (); if (s_con == NULL){ printf("Failed to allocate new %s setting... Sorry.\n",NM_SETTING_CONNECTION_SETTING_NAME); return NMC_RESULT_ERROR_CON_ADD; } nm_connection_add_setting (connection, NM_SETTING (s_con)); if (uuid == NULL){ uuid = nm_utils_uuid_generate (); uuid_generated = 1; } /*global settings*/ g_object_set (s_con, NM_SETTING_CONNECTION_ID, con_name, NM_SETTING_CONNECTION_UUID, uuid, NM_SETTING_CONNECTION_AUTOCONNECT, (autoconnect == 1) ? TRUE : FALSE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_GSM_SETTING_NAME, NULL); if(uuid_generated == 1) g_free (uuid); /* GSM setting */ s_gsm = (NMSettingGsm *) nm_setting_gsm_new (); if (s_gsm == NULL){ printf("Failed to allocate new %s setting...Sorry.\n",NM_SETTING_GSM_SETTING_NAME); return NMC_RESULT_ERROR_CON_ADD; } nm_connection_add_setting (connection, NM_SETTING (s_gsm)); /*Network type Network preference to force the device to only use specific network technologies. The permitted values are: -1: any, 0: 3G only, 1: GPRS/EDGE only, 2: prefer 3G, and 3: prefer 2G, 4: prefer 4G (LTE), 5: 4G (LTE) only. Note that not all devices allow network preference control. */ g_object_set (s_gsm, NM_SETTING_GSM_NUMBER, (number == NULL) ? "*99#" : number, NM_SETTING_GSM_APN, apn, NM_SETTING_GSM_USERNAME, username, NM_SETTING_GSM_PASSWORD, password, NM_SETTING_GSM_PIN, pin, NM_SETTING_GSM_NETWORK_TYPE, ntype, NM_SETTING_GSM_NETWORK_ID, netid, NULL); /* Serial setting */ s_serial = (NMSettingSerial *) nm_setting_serial_new (); if (s_serial == NULL){ printf("Failed to allocate new %s setting...Sorry.\n",NM_SETTING_SERIAL_SETTING_NAME); return NMC_RESULT_ERROR_CON_ADD; } nm_connection_add_setting (connection, NM_SETTING (s_serial)); g_object_set (s_serial, NM_SETTING_SERIAL_BAUD, sbaud, NM_SETTING_SERIAL_BITS, sbits, NM_SETTING_SERIAL_PARITY, sparity, NM_SETTING_SERIAL_STOPBITS, stbits, NULL); /* IP4 setting */ s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); if (s_ip4 == NULL){ printf("Failed to allocate new %s setting... Sorry.\n",NM_SETTING_IP4_CONFIG_SETTING_NAME); return NMC_RESULT_ERROR_CON_ADD; } nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* PPP setting */ s_ppp = (NMSettingPPP *) nm_setting_ppp_new (); if (s_ppp == NULL){ printf("Failed to allocate new %s setting... Sorry.\n", NM_SETTING_PPP_SETTING_NAME); return NMC_RESULT_ERROR_CON_ADD; } g_object_set(s_ppp, NM_SETTING_PPP_REFUSE_EAP, (auth[0] == 't') ? FALSE : TRUE, NM_SETTING_PPP_REFUSE_PAP, (auth[1] == 't') ? FALSE : TRUE, NM_SETTING_PPP_REFUSE_CHAP, (auth[2] == 't') ? FALSE : TRUE, NM_SETTING_PPP_REFUSE_MSCHAP, (auth[3] == 't') ? FALSE : TRUE, NM_SETTING_PPP_REFUSE_MSCHAPV2, (auth[4] == 't') ? FALSE : TRUE, NM_SETTING_PPP_NOBSDCOMP, (comp[0] == 't') ? FALSE : TRUE, NM_SETTING_PPP_NODEFLATE, (comp[1] == 't') ? FALSE : TRUE, NM_SETTING_PPP_NO_VJ_COMP,(comp[2] == 't') ? FALSE : TRUE, //tcp header compression NM_SETTING_PPP_REQUIRE_MPPE, (strcmp(enc, "ff")==0) ? FALSE : TRUE, NM_SETTING_PPP_MPPE_STATEFUL, (enc[1] == 't') ? TRUE : FALSE, NM_SETTING_PPP_REQUIRE_MPPE_128, (enc[0] == 't') ? TRUE : FALSE, NM_SETTING_PPP_LCP_ECHO_FAILURE, (ecofail > 0) ? ecofail : 0, NM_SETTING_PPP_LCP_ECHO_INTERVAL, (ecoint > 0) ? ecoint: 0, NULL); nm_connection_add_setting (connection, NM_SETTING (s_ppp)); hash = nm_connection_to_hash (connection, NM_SETTING_HASH_FLAG_ALL); /* Call AddConnection with the hash as argument */ if (!dbus_g_proxy_call (proxy, "AddConnection", &error, DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, hash, G_TYPE_INVALID, DBUS_TYPE_G_OBJECT_PATH, &new_con_path, G_TYPE_INVALID)) { g_print ("Error adding connection: %s %s\n", dbus_g_error_get_name (error), error->message); g_clear_error (&error); g_hash_table_destroy (hash); g_object_unref (connection); return NMC_RESULT_ERROR_CON_ADD; } else { g_print ("\n\tConnection added successfully at: %s \n\tUse: nmcli con list id %s - to see connection detailed info \n\tcon delete id %s - to delete connection\n", new_con_path, con_name, con_name); g_print ("\tTo bring connection up use: nmcli con up id %s.\n",con_name); g_print ("\tTo see connection status use: nmcli con status id %s.\n\n",con_name); g_free (new_con_path); } g_hash_table_destroy (hash); g_object_unref (connection); return 0; }
gboolean nm_ppp_manager_start (NMPPPManager *manager, NMActRequest *req, const char *ppp_name, guint32 timeout_secs, GError **err) { NMPPPManagerPrivate *priv; NMConnection *connection; NMSettingPpp *s_ppp; gboolean s_ppp_created = FALSE; NMSettingPppoe *pppoe_setting; NMSettingAdsl *adsl_setting; NMCmdLine *ppp_cmd; char *cmd_str; struct stat st; g_return_val_if_fail (NM_IS_PPP_MANAGER (manager), FALSE); g_return_val_if_fail (NM_IS_ACT_REQUEST (req), FALSE); priv = NM_PPP_MANAGER_GET_PRIVATE (manager); #if !WITH_PPP /* PPP support disabled */ g_set_error_literal (err, NM_MANAGER_ERROR, NM_MANAGER_ERROR_FAILED, "PPP support is not enabled."); return FALSE; #endif priv->pid = 0; /* Make sure /dev/ppp exists (bgo #533064) */ if (stat ("/dev/ppp", &st) || !S_ISCHR (st.st_mode)) nm_utils_modprobe (NULL, FALSE, "ppp_generic", NULL); connection = nm_act_request_get_applied_connection (req); g_assert (connection); s_ppp = nm_connection_get_setting_ppp (connection); if (!s_ppp) { /* If the PPP settings are all default we may not have a PPP setting yet, * so just make a default one here. */ s_ppp = NM_SETTING_PPP (nm_setting_ppp_new ()); s_ppp_created = TRUE; } pppoe_setting = nm_connection_get_setting_pppoe (connection); if (pppoe_setting) pppoe_fill_defaults (s_ppp); adsl_setting = (NMSettingAdsl *) nm_connection_get_setting (connection, NM_TYPE_SETTING_ADSL); ppp_cmd = create_pppd_cmd_line (manager, s_ppp, pppoe_setting, adsl_setting, ppp_name, err); if (!ppp_cmd) goto out; g_ptr_array_add (ppp_cmd->array, NULL); _LOGI ("starting PPP connection"); cmd_str = nm_cmd_line_to_str (ppp_cmd); _LOGD ("command line: %s", cmd_str); g_free (cmd_str); priv->pid = 0; if (!g_spawn_async (NULL, (char **) ppp_cmd->array->pdata, NULL, G_SPAWN_DO_NOT_REAP_CHILD, nm_utils_setpgid, NULL, &priv->pid, err)) { goto out; } _LOGI ("pppd started with pid %d", priv->pid); priv->ppp_watch_id = g_child_watch_add (priv->pid, (GChildWatchFunc) ppp_watch_cb, manager); priv->ppp_timeout_handler = g_timeout_add_seconds (timeout_secs, pppd_timed_out, manager); priv->act_req = g_object_ref (req); out: if (s_ppp_created) g_object_unref (s_ppp); if (ppp_cmd) nm_cmd_line_destroy (ppp_cmd); return priv->pid > 0; }
static void gsm_mobile_wizard_done (NMAMobileWizard *wizard, gboolean canceled, NMAMobileWizardAccessMethod *method, gpointer user_data) { NMConnection *connection = NULL; if (!canceled && method) { NMSetting *setting; char *uuid, *id; if (method->devtype != NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS) { g_warning ("Unexpected device type (not GSM)."); canceled = TRUE; goto done; } connection = nm_connection_new (); setting = nm_setting_gsm_new (); g_object_set (setting, NM_SETTING_GSM_NUMBER, "*99#", NM_SETTING_GSM_USERNAME, method->username, NM_SETTING_GSM_PASSWORD, method->password, NM_SETTING_GSM_APN, method->gsm_apn, NULL); nm_connection_add_setting (connection, setting); /* Serial setting */ setting = nm_setting_serial_new (); g_object_set (setting, NM_SETTING_SERIAL_BAUD, 115200, NM_SETTING_SERIAL_BITS, 8, NM_SETTING_SERIAL_PARITY, 'n', NM_SETTING_SERIAL_STOPBITS, 1, NULL); nm_connection_add_setting (connection, setting); nm_connection_add_setting (connection, nm_setting_ppp_new ()); setting = nm_setting_connection_new (); if (method->plan_name) id = g_strdup_printf ("%s %s", method->provider_name, method->plan_name); else id = g_strdup_printf ("%s connection", method->provider_name); uuid = nm_utils_uuid_generate (); g_object_set (setting, NM_SETTING_CONNECTION_ID, id, NM_SETTING_CONNECTION_TYPE, NM_SETTING_GSM_SETTING_NAME, NM_SETTING_CONNECTION_AUTOCONNECT, FALSE, NM_SETTING_CONNECTION_UUID, uuid, NULL); g_free (uuid); g_free (id); nm_connection_add_setting (connection, setting); } done: connect_3g (connection, canceled, user_data); nma_mobile_wizard_destroy (wizard); }
NMConnection * connection_from_file (const char *filename, GError **error) { GKeyFile *key_file; struct stat statbuf; gboolean bad_owner, bad_permissions; NMConnection *connection = NULL; NMSettingConnection *s_con; NMSettingBluetooth *s_bt; NMSetting *setting; gchar **groups; gsize length; int i; gboolean vpn_secrets = FALSE; const char *ctype, *tmp; GError *verify_error = NULL; if (stat (filename, &statbuf) != 0 || !S_ISREG (statbuf.st_mode)) { g_set_error_literal (error, KEYFILE_PLUGIN_ERROR, 0, "File did not exist or was not a regular file"); return NULL; } bad_owner = getuid () != statbuf.st_uid; bad_permissions = statbuf.st_mode & 0077; if (bad_owner || bad_permissions) { g_set_error (error, KEYFILE_PLUGIN_ERROR, 0, "File permissions (%o) or owner (%d) were insecure", statbuf.st_mode, statbuf.st_uid); return NULL; } key_file = g_key_file_new (); if (!g_key_file_load_from_file (key_file, filename, G_KEY_FILE_NONE, error)) goto out; connection = nm_connection_new (); groups = g_key_file_get_groups (key_file, &length); for (i = 0; i < length; i++) { /* Only read out secrets when needed */ if (!strcmp (groups[i], VPN_SECRETS_GROUP)) { vpn_secrets = TRUE; continue; } setting = read_setting (key_file, groups[i]); if (setting) nm_connection_add_setting (connection, setting); } /* Make sure that we have the base device type setting even if * the keyfile didn't include it, which can happen when the base * device type setting is all default values (like ethernet). */ s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION); if (s_con) { ctype = nm_setting_connection_get_connection_type (s_con); setting = nm_connection_get_setting_by_name (connection, ctype); if (ctype) { gboolean add_serial = FALSE; NMSetting *new_setting = NULL; if (!setting && !strcmp (ctype, NM_SETTING_WIRED_SETTING_NAME)) new_setting = nm_setting_wired_new (); else if (!strcmp (ctype, NM_SETTING_BLUETOOTH_SETTING_NAME)) { s_bt = (NMSettingBluetooth *) nm_connection_get_setting (connection, NM_TYPE_SETTING_BLUETOOTH); if (s_bt) { tmp = nm_setting_bluetooth_get_connection_type (s_bt); if (tmp && !strcmp (tmp, NM_SETTING_BLUETOOTH_TYPE_DUN)) add_serial = TRUE; } } else if (!strcmp (ctype, NM_SETTING_GSM_SETTING_NAME)) add_serial = TRUE; else if (!strcmp (ctype, NM_SETTING_CDMA_SETTING_NAME)) add_serial = TRUE; /* Bluetooth DUN, GSM, and CDMA connections require a serial setting */ if (add_serial && !nm_connection_get_setting (connection, NM_TYPE_SETTING_SERIAL)) new_setting = nm_setting_serial_new (); if (new_setting) nm_connection_add_setting (connection, new_setting); } } /* Serial connections require a PPP setting too */ if (nm_connection_get_setting (connection, NM_TYPE_SETTING_SERIAL)) { if (!nm_connection_get_setting (connection, NM_TYPE_SETTING_PPP)) nm_connection_add_setting (connection, nm_setting_ppp_new ()); } /* Handle vpn secrets after the 'vpn' setting was read */ if (vpn_secrets) { NMSettingVPN *s_vpn; s_vpn = (NMSettingVPN *) nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN); if (s_vpn) read_vpn_secrets (key_file, s_vpn); } g_strfreev (groups); /* Verify the connection */ if (!nm_connection_verify (connection, &verify_error)) { g_set_error (error, KEYFILE_PLUGIN_ERROR, 0, "invalid or missing connection property '%s'", (verify_error && verify_error->message) ? verify_error->message : "(unknown)"); g_clear_error (&verify_error); g_object_unref (connection); connection = NULL; } out: g_key_file_free (key_file); return connection; }