static NMConnection * build_edit_connection (NMConnection *orig_connection) { NMConnection *edit_connection; GHashTable *settings, *secrets; GHashTableIter iter; const char *setting_name; NmtSyncOp op; edit_connection = nm_connection_duplicate (orig_connection); if (!NM_IS_REMOTE_CONNECTION (orig_connection)) return edit_connection; settings = nm_connection_to_hash (orig_connection, NM_SETTING_HASH_FLAG_NO_SECRETS); g_hash_table_iter_init (&iter, settings); while (g_hash_table_iter_next (&iter, (gpointer) &setting_name, NULL)) { nmt_sync_op_init (&op); nm_remote_connection_get_secrets (NM_REMOTE_CONNECTION (orig_connection), setting_name, got_secrets, &op); /* FIXME: error handling */ secrets = nmt_sync_op_wait_pointer (&op, NULL); if (secrets) (void) nm_connection_update_secrets (edit_connection, setting_name, secrets, NULL); } g_hash_table_unref (settings); return edit_connection; }
static gpointer agent_new_save_delete (NMSecretAgent *self, NMConnection *connection, NMSettingHashFlags hash_flags, const char *method, NMSecretAgentCallback callback, gpointer callback_data) { NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self); GHashTable *hash; Request *r; const char *cpath = nm_connection_get_path (connection); hash = nm_connection_to_hash (connection, hash_flags); r = request_new (self, cpath, NULL, callback, callback_data); r->call = dbus_g_proxy_begin_call_with_timeout (priv->proxy, method, agent_save_delete_cb, r, NULL, 10000, /* 10 seconds */ DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, hash, DBUS_TYPE_G_OBJECT_PATH, cpath, G_TYPE_INVALID); g_hash_table_insert (priv->requests, r->call, r); g_hash_table_destroy (hash); return r->call; }
static void update_connection (NetConnectionEditor *editor) { GHashTable *settings; settings = nm_connection_to_hash (editor->connection, NM_SETTING_HASH_FLAG_ALL); nm_connection_replace_settings (editor->orig_connection, settings, NULL); g_hash_table_destroy (settings); }
gconstpointer nm_secret_agent_get_secrets (NMSecretAgent *self, NMConnection *connection, const char *setting_name, const char *hint, NMSettingsGetSecretsFlags flags, NMSecretAgentCallback callback, gpointer callback_data) { NMSecretAgentPrivate *priv; GHashTable *hash; const char *hints[2] = { hint, NULL }; Request *r; g_return_val_if_fail (self != NULL, NULL); g_return_val_if_fail (connection != NULL, NULL); g_return_val_if_fail (setting_name != NULL, NULL); priv = NM_SECRET_AGENT_GET_PRIVATE (self); hash = nm_connection_to_hash (connection, NM_SETTING_HASH_FLAG_ALL); /* Mask off the private ONLY_SYSTEM flag if present */ flags &= ~NM_SETTINGS_GET_SECRETS_FLAG_ONLY_SYSTEM; r = request_new (self, nm_connection_get_path (connection), setting_name, callback, callback_data); r->call = dbus_g_proxy_begin_call_with_timeout (priv->proxy, "GetSecrets", get_callback, r, NULL, 120000, /* 120 seconds */ DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, hash, DBUS_TYPE_G_OBJECT_PATH, nm_connection_get_path (connection), G_TYPE_STRING, setting_name, G_TYPE_STRV, hints, G_TYPE_UINT, flags, G_TYPE_INVALID); g_hash_table_insert (priv->requests, r->call, r); g_hash_table_destroy (hash); return r->call; }
/** * nm_remote_settings_add_connection: * @settings: the %NMRemoteSettings * @connection: the connection to add. Note that this object's settings will be * added, not the object itself * @callback: (scope async): callback to be called when the add operation completes * @user_data: caller-specific data passed to @callback * * Requests that the remote settings service add the given settings to a new * connection. * * Returns: TRUE if the request was successful, FALSE if it failed **/ gboolean nm_remote_settings_add_connection (NMRemoteSettings *settings, NMConnection *connection, NMRemoteSettingsAddConnectionFunc callback, gpointer user_data) { NMRemoteSettingsPrivate *priv; AddConnectionInfo *info; GHashTable *new_settings; g_return_val_if_fail (settings != NULL, FALSE); g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), FALSE); g_return_val_if_fail (connection != NULL, FALSE); g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE); g_return_val_if_fail (callback != NULL, FALSE); priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings); info = g_malloc0 (sizeof (AddConnectionInfo)); info->self = settings; info->callback = callback; info->callback_data = user_data; new_settings = nm_connection_to_hash (connection, NM_SETTING_HASH_FLAG_ALL); dbus_g_proxy_begin_call (priv->proxy, "AddConnection", add_connection_done, info, NULL, DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, new_settings, G_TYPE_INVALID); g_hash_table_destroy (new_settings); priv->add_list = g_slist_append (priv->add_list, info); return TRUE; }
static gboolean add_connection (NMSettingsInterface *settings, NMConnection *connection, NMSettingsAddConnectionFunc callback, gpointer user_data) { NMRemoteSettings *self = NM_REMOTE_SETTINGS (settings); NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self); AddConnectionInfo *info; GHashTable *new_settings; info = g_malloc0 (sizeof (AddConnectionInfo)); info->self = settings; info->callback = callback; info->callback_data = user_data; new_settings = nm_connection_to_hash (connection); org_freedesktop_NetworkManagerSettings_add_connection_async (priv->proxy, new_settings, add_connection_done, info); g_hash_table_destroy (new_settings); return TRUE; }
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; }
static void add_connection (pam_handle_t *pamh, DBusGProxy *proxy, const char *con_name, const char *con_identity, const char *con_pwd) { NMConnection *connection; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSetting8021x *s_8021x; NMSettingIP4Config *s_ip4; char *uuid, *new_con_path = NULL; GHashTable *hash; GError *error = NULL; /* Create a new connection object */ if (debug) { pam_syslog (pamh, LOG_INFO, "Creating new connection object."); } connection = (NMConnection *) nm_connection_new (); /* Build up the 'connection' Setting */ if (debug) { pam_syslog (pamh, LOG_INFO, "Building up the 'connection' setting."); } s_con = (NMSettingConnection *) nm_setting_connection_new (); uuid = nm_utils_uuid_generate (); g_object_set (G_OBJECT (s_con), NM_SETTING_CONNECTION_UUID, uuid, NM_SETTING_CONNECTION_ID, con_name, NM_SETTING_CONNECTION_TYPE, "802-3-ethernet", NULL); g_free (uuid); nm_connection_add_setting (connection, NM_SETTING (s_con)); /* Build up the 'wired' Setting */ if (debug) { pam_syslog (pamh, LOG_INFO, "Building up the 'wired' setting."); } s_wired = (NMSettingWired *) nm_setting_wired_new (); nm_connection_add_setting (connection, NM_SETTING (s_wired)); /* Build up the '8021x' Setting */ if (debug) { pam_syslog (pamh, LOG_INFO, "Building up the '8021x' setting."); } s_8021x = (NMSetting8021x *) nm_setting_802_1x_new (); g_object_set (G_OBJECT (s_8021x), NM_SETTING_802_1X_SYSTEM_CA_CERTS, TRUE, NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD_FLAGS, TRUE, NM_SETTING_802_1X_ANONYMOUS_IDENTITY, "*****@*****.**", NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD_FLAGS, TRUE, NM_SETTING_802_1X_IDENTITY, con_identity, NM_SETTING_802_1X_PHASE2_AUTH, "mschapv2", NM_SETTING_802_1X_PASSWORD, con_pwd, NULL); nm_setting_802_1x_add_phase2_altsubject_match(s_8021x, "DNS:radius.example.com"); nm_setting_802_1x_add_eap_method(s_8021x, "peap"); nm_connection_add_setting (connection, NM_SETTING (s_8021x)); /* Build up the 'ipv4' Setting */ if (debug) { pam_syslog (pamh, LOG_INFO, "Building up the 'ipv4' setting."); } s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); g_object_set (G_OBJECT (s_ip4), NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); hash = nm_connection_to_hash (connection, NM_SETTING_HASH_FLAG_ALL); /* Call AddConnection with the hash as argument */ if (debug) { pam_syslog (pamh, LOG_INFO, "Calling AddConnection D-BUS method."); } 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", dbus_g_error_get_name (error), error->message); pam_syslog (pamh, LOG_ERR, "Error adding connection: %s %s", dbus_g_error_get_name (error), error->message); g_clear_error (&error); } else { g_print ("Added: %s\n", new_con_path); pam_syslog (pamh, LOG_ERR, "Added: %s\n", new_con_path); g_free (new_con_path); } g_hash_table_destroy (hash); g_object_unref (connection); }