API int pkgmgr_set_preload_to_pkgdbinfo(pkgmgr_pkgdbinfo_h handle, int preload)
{
	if (!handle) {
		_LOGE("Argument supplied is NULL\n");
		return PKGMGR_R_EINVAL;
	}
	if (preload < 0 || preload > 1) {
		_LOGE("Argument supplied is invalid\n");
		return PKGMGR_R_EINVAL;
	}
	manifest_x *mfx = (manifest_x *)handle;
	if (mfx->preload == NULL) {
		mfx->preload = (char *)calloc(1, strlen("false"));
		if (mfx->preload == NULL) {
			_LOGE("Malloc Failed\n");
			return PKGMGR_R_ERROR;
		}
	}
	if (preload == 0) {
		strcpy(mfx->preload, "false");
	} else if (preload == 1) {
		strcpy(mfx->preload, "true");
	} else {
		_LOGE("Invalid preload type\n");
		return PKGMGR_R_ERROR;
	}
	PKGMGR_R_OK;
}
Beispiel #2
0
static gboolean
_netns_switch_pop (NMPNetns *self, int ns_types)
{
	int errsv;
	NMPNetns *current;
	int success = TRUE;

	if (   NM_FLAGS_HAS (ns_types, CLONE_NEWNET)
	    && (!self || !_stack_current_ns_types (self, CLONE_NEWNET))) {
		current = _stack_current_netns (CLONE_NEWNET);
		if (!current) {
			g_warn_if_reached ();
			success = FALSE;
		} else if (_setns (current, CLONE_NEWNET) != 0) {
			errsv = errno;
			_LOGE (self, "failed to switch netns: %s", g_strerror (errsv));
			success = FALSE;
		}
	}
	if (   NM_FLAGS_HAS (ns_types, CLONE_NEWNS)
	    && (!self || !_stack_current_ns_types (self, CLONE_NEWNS))) {
		current = _stack_current_netns (CLONE_NEWNS);
		if (!current) {
			g_warn_if_reached ();
			success = FALSE;
		} else if (_setns (current, CLONE_NEWNS) != 0) {
			errsv = errno;
			_LOGE (self, "failed to switch mntns: %s", g_strerror (errsv));
			success = FALSE;
		}
	}

	return success;
}
API int pkgmgr_set_description_to_pkgdbinfo(pkgmgr_pkgdbinfo_h handle, const char *desc_txt, const char *locale)
{
	if (!handle || !desc_txt) {
		_LOGE("Argument supplied is NULL\n");
		return PKGMGR_R_EINVAL;
	}
	int len = strlen(desc_txt);
	manifest_x *mfx = (manifest_x *)handle;
	if (len > PKG_VALUE_STRING_LEN_MAX) {
		_LOGE("description length exceeds the max limit\n");
		return PKGMGR_R_EINVAL;
	}
	description_x *description = calloc(1, sizeof(description_x));
	if (description == NULL) {
		_LOGE("Malloc Failed\n");
		return PKGMGR_R_ERROR;
	}
	LISTADD(mfx->description, description);
	if (locale)
		mfx->description->lang = strdup(locale);
	else
		mfx->description->lang = strdup(DEFAULT_LOCALE);
	mfx->description->text = strdup(desc_txt);

	return PKGMGR_R_OK;
}
API int pkgmgr_set_removable_to_pkgdbinfo(pkgmgr_pkgdbinfo_h handle, int removable)
{
	if (!handle) {
		_LOGE("Argument supplied is NULL\n");
		return PKGMGR_R_EINVAL;
	}
	if (removable < 0 || removable > 1) {
		_LOGE("Argument supplied is invalid\n");
		return PKGMGR_R_EINVAL;
	}
	manifest_x *mfx = (manifest_x *)handle;
	if (mfx->removable == NULL) {
		mfx->removable = (char *)calloc(1, strlen("false"));
		if (mfx->removable == NULL) {
			_LOGE("Malloc Failed\n");
			return PKGMGR_R_ERROR;
		}
	}
	if (removable == 0) {
		strcpy(mfx->removable, "false");
	} else if (removable == 1) {
		strcpy(mfx->removable, "true");
	} else {
		_LOGE("Invalid removable type\n");
		return PKGMGR_R_ERROR;
	}
	PKGMGR_R_OK;
}
API int pkgmgr_set_author_to_pkgdbinfo(pkgmgr_pkgdbinfo_h handle, const char *author_name,
										const char *author_email, const char *author_href, const char *locale)
{
	if (!handle) {
		_LOGE("Argument supplied is NULL\n");
		return PKGMGR_R_EINVAL;
	}
	manifest_x *mfx = (manifest_x *)handle;
	author_x *author = calloc(1, sizeof(author_x));
	if (author == NULL) {
		_LOGE("Malloc Failed\n");
		return PKGMGR_R_ERROR;
	}
	LISTADD(mfx->author, author);
	if (author_name)
		mfx->author->text = strdup(author_name);
	if (author_email)
		mfx->author->email = strdup(author_email);
	if (author_href)
		mfx->author->href = strdup(author_href);
	if (locale)
		mfx->author->lang = strdup(locale);
	else
		mfx->author->lang = strdup(DEFAULT_LOCALE);
	return PKGMGR_R_OK;
}
API int pkgmgr_set_install_location_to_pkgdbinfo(pkgmgr_pkgdbinfo_h handle, INSTALL_LOCATION location)
{
	if (!handle) {
		_LOGE("Argument supplied is NULL\n");
		return PKGMGR_R_EINVAL;
	}
	if (location < 0 || location > 1) {
		_LOGE("Argument supplied is invalid\n");
		return PKGMGR_R_EINVAL;
	}
	manifest_x *mfx = (manifest_x *)handle;
	if (mfx->installlocation == NULL) {
		mfx->installlocation = (char *)calloc(1, strlen("prefer-external"));
		if (mfx->installlocation == NULL) {
			_LOGE("Malloc Failed\n");
			return PKGMGR_R_ERROR;
		}
	}
	if (location == INSTALL_INTERNAL) {
		strcpy(mfx->installlocation, "internal-only");
	} else if (location == INSTALL_EXTERNAL) {
		strcpy(mfx->installlocation, "prefer-external");
	} else {
		_LOGE("Invalid location type\n");
		return PKGMGR_R_ERROR;
	}
	return PKGMGR_R_OK;
}
Beispiel #7
0
static gboolean
_netns_switch_push (NMPNetns *self, int ns_types)
{
	int errsv;

	if (   NM_FLAGS_HAS (ns_types, CLONE_NEWNET)
	    && !_stack_current_ns_types (self, CLONE_NEWNET)
	    && _setns (self, CLONE_NEWNET) != 0) {
		errsv = errno;
		_LOGE (self, "failed to switch netns: %s", g_strerror (errsv));
		return FALSE;
	}
	if (   NM_FLAGS_HAS (ns_types, CLONE_NEWNS)
	    && !_stack_current_ns_types (self, CLONE_NEWNS)
	    && _setns (self, CLONE_NEWNS) != 0) {
		errsv = errno;
		_LOGE (self, "failed to switch mntns: %s", g_strerror (errsv));

		/* try to fix the mess by returning to the previous netns. */
		if (   NM_FLAGS_HAS (ns_types, CLONE_NEWNET)
	        && !_stack_current_ns_types (self, CLONE_NEWNET)) {
			self = _stack_current_netns (CLONE_NEWNET);
			if (   self
			    && _setns (self, CLONE_NEWNET) != 0) {
				errsv = errno;
				_LOGE (self, "failed to restore netns: %s", g_strerror (errsv));
			}
		}
		return FALSE;
	}

	return TRUE;
}
int
plugin_init (void)
{
	GDBusConnection *bus;
	GError *error = NULL;
	const char *bus_name;

	nm_g_type_init ();

	g_return_val_if_fail (!gl.proxy, -1);

	bus_name = getenv ("NM_DBUS_SERVICE_L2TP");
	if (!bus_name)
		bus_name = NM_DBUS_SERVICE_L2TP;

	gl.log_level = _nm_utils_ascii_str_to_int64 (getenv ("NM_VPN_LOG_LEVEL"),
	                                             10, 0, LOG_DEBUG,
	                                             LOG_NOTICE);
	gl.log_prefix_token = getenv ("NM_VPN_LOG_PREFIX_TOKEN") ?: "???";

	_LOGI ("initializing");

	bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
	if (!bus) {
		_LOGE ("couldn't connect to system bus: %s",
		       error->message);
		g_error_free (error);
		return -1;
	}

	gl.proxy = g_dbus_proxy_new_sync (bus,
	                                  G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
	                                  NULL,
	                                  bus_name,
	                                  NM_DBUS_PATH_L2TP_PPP,
	                                  NM_DBUS_INTERFACE_L2TP_PPP,
	                                  NULL, &error);
	g_object_unref (bus);

	if (!gl.proxy) {
		_LOGE ("couldn't create D-Bus proxy: %s",
		       error->message);
		g_error_free (error);
		return -1;
	}

	chap_passwd_hook = get_credentials;
	chap_check_hook = get_chap_check;
	pap_passwd_hook = get_credentials;
	pap_check_hook = get_pap_check;
#ifdef USE_EAPTLS
	eaptls_passwd_hook = get_credentials;
#endif

	add_notifier (&phasechange, nm_phasechange, NULL);
	add_notifier (&ip_up_notifier, nm_ip_up, NULL);
	add_notifier (&exitnotify, nm_exit_notify, NULL);
	return 0;
}
Beispiel #9
0
gboolean
nmp_netns_bind_to_path (NMPNetns *self, const char *filename, int *out_fd)
{
	gs_free char *dirname = NULL;
	int errsv;
	int fd;
	nm_auto_pop_netns NMPNetns *netns_pop = NULL;

	g_return_val_if_fail (NMP_IS_NETNS (self), FALSE);
	g_return_val_if_fail (filename && filename[0] == '/', FALSE);

	if (!nmp_netns_push_type (self, CLONE_NEWNET))
		return FALSE;
	netns_pop = self;

	dirname = g_path_get_dirname (filename);
	if (mkdir (dirname, 0) != 0) {
		errsv = errno;
		if (errsv != EEXIST) {
			_LOGE (self, "bind: failed to create directory %s: %s",
			       dirname, g_strerror (errsv));
			return FALSE;
		}
	}

	if ((fd = creat (filename, S_IRUSR | S_IRGRP | S_IROTH)) == -1) {
		errsv = errno;
		_LOGE (self, "bind: failed to create %s: %s",
		       filename, g_strerror (errsv));
		return FALSE;
	}
	close (fd);

	if (mount (PROC_SELF_NS_NET, filename, "none", MS_BIND, NULL) != 0) {
		errsv = errno;
		_LOGE (self, "bind: failed to mount %s to %s: %s",
		       PROC_SELF_NS_NET, filename, g_strerror (errsv));
		unlink (filename);
		return FALSE;
	}

	if (out_fd) {
		if ((fd = open (filename, O_RDONLY)) == -1) {
			errsv = errno;
			_LOGE (self, "bind: failed to open %s: %s", filename, g_strerror (errsv));
			umount2 (filename, MNT_DETACH);
			unlink (filename);
			return FALSE;
		}
		*out_fd = fd;
	}

	return TRUE;
}
Beispiel #10
0
NMPNetns *
nmp_netns_new (void)
{
	NMPNetns *self;
	int errsv;
	GError *error = NULL;

	_stack_ensure_init ();

	if (!_stack_peek ()) {
		/* there are no netns instances. We cannot create a new one
		 * (because after unshare we couldn't return to the original one). */
		return NULL;
	}

	if (unshare (_CLONE_NS_ALL) != 0) {
		errsv = errno;
		_LOGE (NULL, "failed to create new net and mnt namespace: %s", g_strerror (errsv));
		return NULL;
	}

	if (mount ("", "/", "none", MS_SLAVE | MS_REC, NULL) != 0) {
		errsv = errno;
		_LOGE (NULL, "failed mount --make-rslave: %s", g_strerror (errsv));
		goto err_out;
	}

	if (umount2 ("/sys", MNT_DETACH) != 0) {
		errsv = errno;
		_LOGE (NULL, "failed umount /sys: %s", g_strerror (errsv));
		goto err_out;
	}

	if (mount ("sysfs", "/sys", "sysfs", 0, NULL) != 0) {
		errsv = errno;
		_LOGE (NULL, "failed mount /sys: %s", g_strerror (errsv));
		goto err_out;
	}

	self = _netns_new (&error);
	if (!self) {
		_LOGE (NULL, "failed to create netns after unshare: %s", error->message);
		g_clear_error (&error);
		goto err_out;
	}

	_stack_push (self, _CLONE_NS_ALL);

	return self;
err_out:
	_netns_switch_pop (NULL, _CLONE_NS_ALL);
	return NULL;
}
int _pkg_plugin_get_library_path(const char *pkg_type, char *library_path)
{
	FILE *fp = NULL;
	char buffer[1024] = { 0 };

	if (pkg_type == NULL || library_path == NULL) {
		_LOGE("invalid argument\n");
		return -1;
	}

	fp = fopen(PKG_CONF_PATH, "r");
	if (fp == NULL) {
		_LOGE("no matching backendlib\n");
		return PKGMGR_R_ERROR;
	}

	char *path = NULL;
	while (fgets(buffer, 1024, fp) != NULL) {
		if (buffer[0] == '#')
			continue;

		_app_str_trim(buffer);

		if ((path = strstr(buffer, PKG_BACKENDLIB)) != NULL) {
			_LOGD("[%s]\n", buffer);
			_LOGD("[%s]\n", path);
			path = path + strlen(PKG_BACKENDLIB);
			_LOGD("[%s]\n", path);

			break;
		}

		memset(buffer, 0x00, 1024);
	}

	if (fp != NULL)
		fclose(fp);

	if (path == NULL) {
		_LOGE("no matching backendlib\n");
		return PKGMGR_R_ERROR;
	}

	snprintf(library_path, 1024, "%slib%s.so", path, pkg_type);

	return PKGMGR_R_OK;

}
Beispiel #12
0
static GObject*
constructor (GType type,
			 guint n_construct_params,
			 GObjectConstructParam *construct_params)
{
	GObject *object;
	NMDeviceAdsl *self;
	NMDeviceAdslPrivate *priv;

	object = G_OBJECT_CLASS (nm_device_adsl_parent_class)->constructor (type,
	                                                                    n_construct_params,
	                                                                    construct_params);
	if (!object)
		return NULL;

	self = NM_DEVICE_ADSL (object);
	priv = NM_DEVICE_ADSL_GET_PRIVATE (object);

	priv->atm_index = get_atm_index (nm_device_get_iface (NM_DEVICE (object)));
	if (priv->atm_index < 0) {
		_LOGE (LOGD_ADSL, "error reading ATM device index");
		g_object_unref (object);
		return NULL;
	} else
		_LOGD (LOGD_ADSL, "ATM device index %d", priv->atm_index);

	/* Poll the carrier */
	priv->carrier_poll_id = g_timeout_add_seconds (5, carrier_update_cb, object);

	return object;
}
static gboolean
set_ip_config_common (NMPPPManager *self,
                      GVariant *config_dict,
                      const char *iface_prop,
                      guint32 *out_mtu)
{
	NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (self);
	NMConnection *applied_connection;
	NMSettingPpp *s_ppp;
	const char *iface;

	if (!g_variant_lookup (config_dict, iface_prop, "&s", &iface)) {
		_LOGE ("no interface received!");
		return FALSE;
	}
	if (priv->ip_iface == NULL)
		priv->ip_iface = g_strdup (iface);

	/* Got successful IP config; obviously the secrets worked */
	applied_connection = nm_act_request_get_applied_connection (priv->act_req);
	g_object_set_data (G_OBJECT (applied_connection), PPP_MANAGER_SECRET_TRIES, NULL);

	if (out_mtu) {
		/* Get any custom MTU */
		s_ppp = nm_connection_get_setting_ppp (applied_connection);
		*out_mtu = s_ppp ? nm_setting_ppp_get_mtu (s_ppp) : 0;
	}

	monitor_stats (self);
	return TRUE;
}
Beispiel #14
0
static void
_stack_ensure_init_impl (void)
{
	NMPNetns *netns;
	GError *error = NULL;

	nm_assert (!netns_stack);

	netns_stack = g_array_new (FALSE, FALSE, sizeof (NetnsInfo));

	/* at the bottom of the stack we must try to create a netns instance
	 * that we never pop. It's the base to which we need to return. */

	netns = _netns_new (&error);

	if (!netns) {
		/* don't know how to recover from this error. Netns are not supported. */
		_LOGE (NULL, "failed to create initial netns: %s", error->message);
		g_clear_error (&error);
		return;
	}

	_stack_push (netns, _CLONE_NS_ALL);

	/* we leak this instance inside netns_stack. It cannot be popped. */
	g_object_unref (netns);
}
static void
update_connection (NMDevice *device, NMConnection *connection)
{
	NMDeviceTeam *self = NM_DEVICE_TEAM (device);
	NMSettingTeam *s_team = nm_connection_get_setting_team (connection);
	NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE (self);

	if (!s_team) {
		s_team = (NMSettingTeam *) nm_setting_team_new ();
		nm_connection_add_setting (connection, (NMSetting *) s_team);
	}
	g_object_set (G_OBJECT (s_team), NM_SETTING_TEAM_CONFIG, NULL, NULL);

	if (priv->tdc) {
		const char *config = NULL;
		int err;

		err = teamdctl_config_get_raw_direct (NM_DEVICE_TEAM_GET_PRIVATE (device)->tdc,
		                                      (char **)&config);
		if (err == 0)
			g_object_set (G_OBJECT (s_team), NM_SETTING_TEAM_CONFIG, config, NULL);
		else
			_LOGE (LOGD_TEAM, "failed to read teamd config (err=%d)", err);
	}
}
API int pkgmgr_create_pkgdbinfo(const char *pkg_name, pkgmgr_pkgdbinfo_h *handle)
{
	if (!pkg_name || !handle) {
		_LOGE("Argument supplied is NULL\n");
		return PKGMGR_R_EINVAL;
	}
	manifest_x *mfx = NULL;
	mfx = calloc(1, sizeof(manifest_x));
	if (!mfx) {
		_LOGE("Malloc Failed\n");
		return PKGMGR_R_ERROR;
	}
	mfx->package = strdup(pkg_name);
	*handle = (void *)mfx;
	return PKGMGR_R_OK;
}
void
nm_dispatcher_init (void)
{
	GFile *file;
	guint i;
	GError *error = NULL;

	for (i = 0; i < G_N_ELEMENTS (monitors); i++) {
		file = g_file_new_for_path (monitors[i].dir);
		monitors[i].monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, NULL);
		if (monitors[i].monitor) {
			g_signal_connect (monitors[i].monitor, "changed", G_CALLBACK (dispatcher_dir_changed), &monitors[i]);
			dispatcher_dir_changed (monitors[i].monitor, file, NULL, 0, &monitors[i]);
		}
		g_object_unref (file);
	}

	dispatcher_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
	                                                  G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
	                                                      G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
	                                                  NULL,
	                                                  NM_DISPATCHER_DBUS_SERVICE,
	                                                  NM_DISPATCHER_DBUS_PATH,
	                                                  NM_DISPATCHER_DBUS_INTERFACE,
	                                                  NULL, &error);
	if (!dispatcher_proxy) {
		_LOGE ("could not get dispatcher proxy! %s", error->message);
		g_clear_error (&error);
	}
}
static void
set_property (GObject *object, guint property_id,
              const GValue *value, GParamSpec *pspec)
{
	NMConnectivity *self = NM_CONNECTIVITY (object);
	NMConnectivityPrivate *priv = NM_CONNECTIVITY_GET_PRIVATE (self);
	const char *uri, *response;
	guint interval;
	gboolean changed;

	switch (property_id) {
	case PROP_URI:
		uri = g_value_get_string (value);
		if (uri && !*uri)
			uri = NULL;
		changed = g_strcmp0 (uri, priv->uri) != 0;
#if WITH_CONCHECK
		if (uri) {
			SoupURI *soup_uri = soup_uri_new (uri);

			if (!soup_uri || !SOUP_URI_VALID_FOR_HTTP (soup_uri)) {
				_LOGE ("invalid uri '%s' for connectivity check.", uri);
				uri = NULL;
			}
			if (uri && soup_uri && changed &&
			    soup_uri_get_scheme(soup_uri) == SOUP_URI_SCHEME_HTTPS)
				_LOGW ("use of HTTPS for connectivity checking is not reliable and is discouraged (URI: %s)", uri);
			if (soup_uri)
				soup_uri_free (soup_uri);
		}
#endif
		if (changed) {
			g_free (priv->uri);
			priv->uri = g_strdup (uri);
			_reschedule_periodic_checks (self, TRUE);
		}
		break;
	case PROP_INTERVAL:
		interval = g_value_get_uint (value);
		if (priv->interval != interval) {
			priv->interval = interval;
			_reschedule_periodic_checks (self, TRUE);
		}
		break;
	case PROP_RESPONSE:
		response = g_value_get_string (value);
		if (g_strcmp0 (response, priv->response) != 0) {
			/* a response %NULL means, NM_CONFIG_DEFAULT_CONNECTIVITY_RESPONSE. Any other response
			 * (including "") is accepted. */
			g_free (priv->response);
			priv->response = g_strdup (response);
			_reschedule_periodic_checks (self, TRUE);
		}
		break;
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}
static void
constructed (GObject *object)
{
	NMDeviceVlan *self = NM_DEVICE_VLAN (object);
	NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (self);
	int ifindex = nm_device_get_ifindex (NM_DEVICE (self));
	int parent_ifindex = -1, itype;
	int vlan_id;

	if (G_OBJECT_CLASS (nm_device_vlan_parent_class)->constructed)
		G_OBJECT_CLASS (nm_device_vlan_parent_class)->constructed (object);

	if (!priv->parent) {
		_LOGE (LOGD_VLAN, "no parent specified.");
		priv->invalid = TRUE;
		return;
	}

	itype = nm_platform_link_get_type (ifindex);
	if (itype != NM_LINK_TYPE_VLAN) {
		_LOGE (LOGD_VLAN, "failed to get VLAN interface type.");
		priv->invalid = TRUE;
		return;
	}

	if (!nm_platform_vlan_get_info (ifindex, &parent_ifindex, &vlan_id)) {
		_LOGW (LOGD_VLAN, "failed to get VLAN interface info.");
		priv->invalid = TRUE;
		return;
	}

	if (   parent_ifindex < 0
	    || parent_ifindex != nm_device_get_ip_ifindex (priv->parent)
	    || vlan_id < 0) {
		_LOGW (LOGD_VLAN, "VLAN parent ifindex (%d) or VLAN ID (%d) invalid.",
		       parent_ifindex, priv->vlan_id);
		priv->invalid = TRUE;
		return;
	}

	priv->vlan_id = vlan_id;
	_LOGI (LOGD_HW | LOGD_VLAN, "VLAN ID %d with parent %s",
	       priv->vlan_id, nm_device_get_iface (priv->parent));
}
Beispiel #20
0
static gboolean
enslave_slave (NMDevice *device,
               NMDevice *slave,
               NMConnection *connection,
               gboolean configure)
{
	NMDeviceTeam *self = NM_DEVICE_TEAM (device);
	NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE (device);
	gboolean success = TRUE, no_firmware = FALSE;
	const char *slave_iface = nm_device_get_ip_iface (slave);
	NMSettingTeamPort *s_team_port;

	nm_device_master_check_slave_physical_port (device, slave, LOGD_TEAM);

	if (configure) {
		nm_device_take_down (slave, TRUE);

		s_team_port = nm_connection_get_setting_team_port (connection);
		if (s_team_port) {
			const char *config = nm_setting_team_port_get_config (s_team_port);

			if (config) {
				if (!priv->tdc) {
					_LOGW (LOGD_TEAM, "enslaved team port %s config not changed, not connected to teamd",
					       slave_iface);
				} else {
					int err;
					char *sanitized_config;

					sanitized_config = g_strdelimit (g_strdup (config), "\r\n", ' ');
					err = teamdctl_port_config_update_raw (priv->tdc, slave_iface, sanitized_config);
					g_free (sanitized_config);
					if (err != 0) {
						_LOGE (LOGD_TEAM, "failed to update config for port %s (err=%d)",
						       slave_iface, err);
						return FALSE;
					}
				}
			}
		}
		success = nm_platform_link_enslave (NM_PLATFORM_GET,
		                                    nm_device_get_ip_ifindex (device),
		                                    nm_device_get_ip_ifindex (slave));
		nm_device_bring_up (slave, TRUE, &no_firmware);

		if (!success)
			return FALSE;

		_LOGI (LOGD_TEAM, "enslaved team port %s", slave_iface);
	} else
		_LOGI (LOGD_TEAM, "team port %s was enslaved", slave_iface);

	g_object_notify (G_OBJECT (device), NM_DEVICE_TEAM_SLAVES);

	return TRUE;
}
API int pkgmgr_set_type_to_pkgdbinfo(pkgmgr_pkgdbinfo_h handle, const char *type)
{
	if (!type || !handle) {
		_LOGE("Argument supplied is NULL\n");
		return PKGMGR_R_EINVAL;
	}
	int len = strlen(type);
	manifest_x *mfx = (manifest_x *)handle;
	if (len > PKG_TYPE_STRING_LEN_MAX) {
		_LOGE("pkg type length exceeds the max limit\n");
		return PKGMGR_R_EINVAL;
	}
	if (mfx->type == NULL)
		mfx->type = strndup(type, PKG_TYPE_STRING_LEN_MAX);
	else
		mfx->type = type;

	return PKGMGR_R_OK;
}
API int pkgmgr_set_version_to_pkgdbinfo(pkgmgr_pkgdbinfo_h handle, const char *version)
{
	if (!version || !handle) {
		_LOGE("Argument supplied is NULL\n");
		return PKGMGR_R_EINVAL;
	}
	int len = strlen(version);
	manifest_x *mfx = (manifest_x *)handle;
	if (len > PKG_VERSION_STRING_LEN_MAX) {
		_LOGE("pkg version length exceeds the max limit\n");
		return PKGMGR_R_EINVAL;
	}
	if (mfx->version == NULL)
		mfx->version = strndup(version, PKG_VERSION_STRING_LEN_MAX);
	else
		mfx->version = version;

	return PKGMGR_R_OK;
}
API int pkgmgr_destroy_pkgdbinfo(pkgmgr_pkgdbinfo_h handle)
{
	if (!handle) {
		_LOGE("Argument supplied is NULL\n");
		return PKGMGR_R_EINVAL;
	}
	manifest_x *mfx = NULL;
	mfx = (manifest_x *)handle;
	pkgmgr_parser_free_manifest_xml(mfx);
	return PKGMGR_R_OK;
}
Beispiel #24
0
static gboolean
br2684_create_iface (NMDeviceAdsl *self, NMSettingAdsl *s_adsl)
{
	NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE (self);
	struct atm_newif_br2684 ni;
	int err, fd, errsv;
	gboolean success = FALSE;
	guint num = 0;

	g_return_val_if_fail (s_adsl != NULL, FALSE);

	fd = socket (PF_ATMPVC, SOCK_DGRAM, ATM_AAL5);
	if (fd < 0) {
		errsv = errno;
		_LOGE (LOGD_ADSL, "failed to open ATM control socket (%d)", errsv);
		return FALSE;
	}

	memset (&ni, 0, sizeof (ni));
	ni.backend_num = ATM_BACKEND_BR2684;
	ni.media = BR2684_MEDIA_ETHERNET;
	ni.mtu = 1500;

	/* Loop attempting to create an interface that doesn't exist yet.  The
	 * kernel can create one for us automatically, but due to API issues it
	 * cannot return that name to us.  Since we want to know the name right
	 * away, just brute-force it.
	 */
	while (num < 10000) {
		memset (&ni.ifname, 0, sizeof (ni.ifname));
		g_snprintf (ni.ifname, sizeof (ni.ifname), "nas%d", num);

		err = ioctl (fd, ATM_NEWBACKENDIF, &ni);
		if (err == 0) {
			set_nas_iface (self, -1, ni.ifname);
			_LOGI (LOGD_ADSL, "using NAS interface %s (%d)",
			       priv->nas_ifname, priv->nas_ifindex);
			success = TRUE;
			break;
		} else {
			errsv = errno;
			if (errsv == -EEXIST) {
				/* Try again */
				num++;
			} else {
				_LOGW (LOGD_ADSL, "failed to create br2684 interface (%d)", errsv);
				break;
			}
		}
	}

	close (fd);
	return success;
}
Beispiel #25
0
gboolean
nmp_netns_bind_to_path_destroy (NMPNetns *self, const char *filename)
{
	int errsv;

	g_return_val_if_fail (NMP_IS_NETNS (self), FALSE);
	g_return_val_if_fail (filename && filename[0] == '/', FALSE);

	if (umount2 (filename, MNT_DETACH) != 0) {
		errsv = errno;
		_LOGE (self, "bind: failed to unmount2 %s: %s", filename, g_strerror (errsv));
		return FALSE;
	}
	if (unlink (filename) != 0) {
		errsv = errno;
		_LOGE (self, "bind: failed to unlink %s: %s", filename, g_strerror (errsv));
		return FALSE;
	}
	return TRUE;
}
API int pkgmgr_save_pkgdbinfo(pkgmgr_pkgdbinfo_h handle)
{
	if (!handle) {
		_LOGE("Argument supplied is NULL\n");
		return PKGMGR_R_EINVAL;
	}
	int ret = 0;
	manifest_x *mfx = NULL;
	label_x *tmp1 = NULL;
	icon_x *tmp2 = NULL;
	description_x *tmp3 = NULL;
	author_x *tmp4 = NULL;
	mfx = (manifest_x *)handle;
	/*First move to head of all list pointers*/
	if (mfx->label) {
		LISTHEAD(mfx->label, tmp1);
		mfx->label = tmp1;
	}
	if (mfx->icon) {
		LISTHEAD(mfx->icon, tmp2);
		mfx->icon = tmp2;
	}
	if (mfx->description) {
		LISTHEAD(mfx->description, tmp3);
		mfx->description= tmp3;
	}
	if (mfx->author) {
		LISTHEAD(mfx->author, tmp4);
		mfx->author = tmp4;
	}
	ret = pkgmgr_parser_insert_manifest_info_in_db(mfx);
	if (ret == 0) {
		_LOGE("Successfully stored info in DB\n");
		return PKGMGR_R_OK;
	} else {
		_LOGE("Failed to store info in DB\n");
		return PKGMGR_R_ERROR;
	}
}
static void
run_check_complete (GObject      *object,
                    GAsyncResult *result,
                    gpointer      user_data)
{
	NMConnectivity *self = NM_CONNECTIVITY (object);
	GError *error = NULL;

	nm_connectivity_check_finish (self, result, &error);
	if (error) {
		_LOGE ("check failed: %s", error->message);
		g_error_free (error);
	}
}
pkg_plugin_set *_package_manager_load_library(const char *pkg_type)
{
	char package_path[1024] = { 0 };
	pkg_plugin_set *plugin_set = NULL;

	if (pkg_type == NULL) {
		_LOGE("can not load library - pkg_type is null\n");
		return NULL;
	}

	if (_pkg_plugin_get_library_path(pkg_type, package_path) ==
	    PKGMGR_R_OK) {
		plugin_set = _pkg_plugin_load_library(pkg_type, package_path);
		if (plugin_set == NULL) {
			_LOGE("can not load library \n");
			return NULL;
		}
	} else {
		_LOGE("can not find path \n");
		return NULL;
	}

	return plugin_set;
}
Beispiel #29
0
static gboolean
send_rs (NMRDisc *rdisc)
{
	NMLNDPRDiscPrivate *priv = NM_LNDP_RDISC_GET_PRIVATE (rdisc);
	struct ndp_msg *msg;
	int error;

	error = ndp_msg_new (&msg, NDP_MSG_RS);
	g_assert (!error);
	ndp_msg_ifindex_set (msg, rdisc->ifindex);

	error = ndp_msg_send (priv->ndp, msg);
	ndp_msg_destroy (msg);
	if (error) {
		_LOGE ("cannot send router solicitation: %d.", error);
		return FALSE;
	}

	return TRUE;
}
static gboolean
ensure_teamd_connection (NMDevice *device)
{
	NMDeviceTeam *self = NM_DEVICE_TEAM (device);
	NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE (self);
	int err;

	if (priv->tdc)
		return TRUE;

	priv->tdc = teamdctl_alloc ();
	g_assert (priv->tdc);
	err = teamdctl_connect (priv->tdc, nm_device_get_iface (device), NULL, NULL);
	if (err != 0) {
		_LOGE (LOGD_TEAM, "failed to connect to teamd (err=%d)", err);
		teamdctl_free (priv->tdc);
		priv->tdc = NULL;
	}

	return !!priv->tdc;
}