static void
get_active_connection_details (const char *obj_path)
{
	GDBusProxy *props_proxy;
	GVariant *ret = NULL, *path_value = NULL;
	const char *path = NULL;
	GError *error = NULL;

	/* This function gets the backing Connection object that describes the
	 * network configuration that the ActiveConnection object is actually using.
	 * The ActiveConnection object contains the mapping between the configuration
	 * and the actual network interfaces that are using that configuration.
	 */

	/* Create a D-Bus object proxy for the active connection object's properties */
	props_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
	                                             G_DBUS_PROXY_FLAGS_NONE,
	                                             NULL,
	                                             NM_DBUS_SERVICE,
	                                             obj_path,
	                                             "org.freedesktop.DBus.Properties",
	                                             NULL, NULL);
	g_assert (props_proxy);

	/* Get the object path of the Connection details */
	ret = g_dbus_proxy_call_sync (props_proxy,
	                              "Get",
	                              g_variant_new ("(ss)",
	                                             NM_DBUS_INTERFACE_ACTIVE_CONNECTION,
	                                             "Connection"),
	                              G_DBUS_CALL_FLAGS_NONE, -1,
	                              NULL, &error);
	if (!ret) {
		g_dbus_error_strip_remote_error (error);
		g_warning ("Failed to get active connection Connection property: %s\n",
		           error->message);
		g_error_free (error);
		goto out;
	}

	g_variant_get (ret, "(v)", &path_value);
	if (!g_variant_is_of_type (path_value, G_VARIANT_TYPE_OBJECT_PATH)) {
		g_warning ("Unexpected type returned getting Connection property: %s",
		           g_variant_get_type_string (path_value));
		goto out;
	}

	path = g_variant_get_string (path_value, NULL);

	/* Print out the actual connection details */
	print_connection (path);

out:
	if (path_value)
		g_variant_unref (path_value);
	if (ret)
		g_variant_unref (ret);
	g_object_unref (props_proxy);
}
Exemplo n.º 2
0
char *print_connections_list(connection_t **connection_list) {

    if (*connection_list == NULL) {
        ERR("connections list is not initialized yet\n");
        return NULL;
    }

    char *result = 0;
    int success;

    connection_t *current;
    current = *connection_list;

    char *connection_info = NULL;

    result = print_connection(current);
    while (current->next != NULL) {
        connection_info = print_connection(current->next);

        success = asprintf(
                &result,
                "%s%s",
                result, connection_info
        );

        if (success == -1) {
            ERR("asprintf failed to allocate memory\n");
            return NULL;
        }

        if (connection_info != NULL)
            free(connection_info);

        current = current->next;
    }

    return result;
}
Exemplo n.º 3
0
static void print_session(sdp_printer_t *p, sdp_session_t const *sdp)
{
  p->pr_ok = 1;

  if (p->pr_ok && sdp->sdp_version)
    print_version(p, sdp->sdp_version);
  if (p->pr_ok && sdp->sdp_origin)
    print_origin(p, sdp->sdp_origin);
  if (p->pr_ok && sdp->sdp_subject)
    print_subject(p, sdp->sdp_subject);
  if (p->pr_ok && sdp->sdp_information)
    print_information(p, sdp->sdp_information);
  if (p->pr_ok && sdp->sdp_uri)
    print_uri(p, sdp->sdp_uri);
  if (p->pr_ok && sdp->sdp_emails)
    print_emails(p, sdp->sdp_emails);
  if (p->pr_ok && sdp->sdp_phones)
    print_phones(p, sdp->sdp_phones);
  if (p->pr_ok && sdp->sdp_connection)
    print_connection(p, sdp->sdp_connection);
  if (p->pr_ok && sdp->sdp_bandwidths)
    print_bandwidths(p, sdp->sdp_bandwidths);
  if (p->pr_ok)
    print_time(p, sdp->sdp_time);
  if (p->pr_ok && sdp->sdp_time) {
    if (p->pr_ok && sdp->sdp_time->t_repeat)
      print_repeat(p, sdp->sdp_time->t_repeat);
    if (p->pr_ok && sdp->sdp_time->t_zone)
      print_zone(p, sdp->sdp_time->t_zone);
  }
  if (p->pr_ok && sdp->sdp_key)
    print_key(p, sdp->sdp_key);
  if (p->pr_ok && sdp->sdp_charset)
    print_charset(p, sdp->sdp_charset);
  if (p->pr_ok && sdp->sdp_attributes)
    print_attributes(p, sdp->sdp_attributes);
  if (p->pr_ok && sdp->sdp_media)
    print_media(p, sdp, sdp->sdp_media);
}
static void
get_active_connection_details (DBusGConnection *bus, const char *obj_path)
{
	DBusGProxy *props_proxy;
	GValue path_value = { 0 };
	GValue serv_value = { 0 };
	GError *error = NULL;
	const char *path = NULL, *service = NULL;

	/* This function gets the backing Connection object that describes the
	 * network configuration that the ActiveConnection object is actually using.
	 * The ActiveConnection object contains the mapping between the configuration
	 * and the actual network interfaces that are using that configuration.
	 */

	/* Create a D-Bus object proxy for the active connection object's properties */
	props_proxy = dbus_g_proxy_new_for_name (bus,
	                                         NM_DBUS_SERVICE,
	                                         obj_path,
	                                         DBUS_INTERFACE_PROPERTIES);
	g_assert (props_proxy);
	
	/* Get the object path of the Connection details */
	if (!dbus_g_proxy_call (props_proxy, "Get", &error,
	                        G_TYPE_STRING, NM_DBUS_INTERFACE_ACTIVE_CONNECTION,
	                        G_TYPE_STRING, "Connection",
	                        G_TYPE_INVALID,
	                        G_TYPE_VALUE, &path_value,
	                        G_TYPE_INVALID)) {
		g_warning ("Failed to get active connection Connection property: %s",
		           error->message);
		g_error_free (error);
		goto out;
	}

	if (!G_VALUE_HOLDS (&path_value, DBUS_TYPE_G_OBJECT_PATH)) {
		g_warning ("Unexpected type returned getting Connection property: %s",
		           G_VALUE_TYPE_NAME (&path_value));
		goto out;
	}

	path = g_value_get_boxed (&path_value);
	if (!path) {
		g_warning ("Missing connection path!");
		goto out;
	}

	/* Get the service name of the D-Bus service that provides the Connection */
	if (!dbus_g_proxy_call (props_proxy, "Get", &error,
	                        G_TYPE_STRING, NM_DBUS_INTERFACE_ACTIVE_CONNECTION,
	                        G_TYPE_STRING, "ServiceName",
	                        G_TYPE_INVALID,
	                        G_TYPE_VALUE, &serv_value,
	                        G_TYPE_INVALID)) {
		g_warning ("Failed to get active connection ServiceName property: %s",
		           error->message);
		g_error_free (error);
		goto out;
	}

	if (!G_VALUE_HOLDS (&serv_value, G_TYPE_STRING)) {
		g_warning ("Unexpected type returned getting Connection property: %s",
		           G_VALUE_TYPE_NAME (&serv_value));
		goto out;
	}

	service = g_value_get_string (&serv_value);
	if (!service) {
		g_warning ("Missing connection service name!");
		goto out;
	}

	/* Print out the actual connection details */
	print_connection (bus, service, path);

out:
	g_value_unset (&path_value);
	g_value_unset (&serv_value);
	g_object_unref (props_proxy);
}
Exemplo n.º 5
0
/**
 * Parse message content for message of type #AUTH_REQUEST or #AUTH_CONTROL
 * using structure ::nufw_to_nuauth_auth_message_t.
 *
 * \param dgram Pointer to packet datas
 * \param dgram_size Number of bytes in the packet
 * \param conn Pointer of pointer to the ::connection_t that we have to authenticate
 * \return A nu_error_t
 */
nu_error_t authpckt_new_connection(unsigned char *dgram,
				   unsigned int dgram_size,
				   connection_t ** conn)
{
	nuv4_nufw_to_nuauth_auth_message_t *msg =
	    (nuv4_nufw_to_nuauth_auth_message_t *) dgram;
	connection_t *connection;
	nu_error_t ret;

	if (dgram_size < sizeof(nuv4_nufw_to_nuauth_auth_message_t)) {
		log_message(WARNING, DEBUG_AREA_PACKET | DEBUG_AREA_GW,
			    "NuFW packet too small: %d for a minimum of %lu",
			    dgram_size,
			    (unsigned long)sizeof(nuv4_nufw_to_nuauth_auth_message_t));
		return NU_EXIT_ERROR;
	}
	dgram += sizeof(nuv4_nufw_to_nuauth_auth_message_t);
	dgram_size -= sizeof(nuv4_nufw_to_nuauth_auth_message_t);

	/* allocate new connection */
	connection = g_new0(connection_t, 1);
	if (connection == NULL) {
		log_message(WARNING, DEBUG_AREA_PACKET | DEBUG_AREA_GW,
			    "Can not allocate connection");
		return NU_EXIT_ERROR;
	}
#ifdef PERF_DISPLAY_ENABLE
	if (nuauthconf->debug_areas & DEBUG_AREA_PERF) {
		gettimeofday(&(connection->arrival_time), NULL);
	}
#endif
	connection->acl_groups = NULL;
	connection->user_groups = NULL;
	connection->decision = DECISION_NODECIDE;
	connection->expire = -1;
	connection->payload_len = 0;

	connection->packet_id =
	    g_slist_append(NULL, GUINT_TO_POINTER(ntohl(msg->packet_id)));
	debug_log_message(DEBUG, DEBUG_AREA_PACKET | DEBUG_AREA_GW,
			  "Auth pckt: Working on new connection (id=%u)",
			  (uint32_t) GPOINTER_TO_UINT(connection->
						      packet_id->data));

	/* timestamp */
	connection->timestamp = ntohl(msg->timestamp);
	if (connection->timestamp == 0) {
		connection->timestamp = time(NULL);
	}

	connection->flags = ACL_FLAGS_NONE;
	connection->nufw_version = msg->protocol_version;

	ret = parse_dgram(connection, dgram, dgram_size, conn,
			msg->msg_type);
	if (ret != NU_EXIT_CONTINUE) {
		return ret;
	}

	/* parse supplementary fields */
	if (parse_v4_fields(msg, connection) != NU_EXIT_OK) {
		return ret;
	}

	if (DEBUG_OR_NOT(DEBUG_LEVEL_DEBUG, DEBUG_AREA_PACKET)) {
		print_connection(connection, "NuFW Packet");
	}
	*conn = connection;
	return NU_EXIT_OK;
}
Exemplo n.º 6
0
Arquivo: main.c Projeto: czhu12/cs317
static inline void print_state(system_state *state) {
  
  int i;
  connection conn;
  
  printf("\n");
  
#if PART==1
  for (i = 0; i < NUM_TRUNK_PORTS; i++)
    printf("% 4d ", i);
  printf("\n");
  conn.type = CONN_TRUNK;
  conn.switch_number = 0;
  for (conn.trunk_index = 0; conn.trunk_index < NUM_TRUNK_PORTS;
       conn.trunk_index++) {
    print_connection(switch_current_connection(state, conn), 'S');
  }
  
  printf("\n");
  for (i = 0; i < NUM_PHONES_PER_SWITCH; i++)
    printf("% 4d ", i);
  printf("\n");
  conn.type = CONN_LINE;
  conn.switch_number = 0;
  for (conn.phone_number = 0; conn.phone_number < NUM_PHONES_PER_SWITCH;
       conn.phone_number++) {
    print_connection(switch_current_connection(state, conn), 'S');
  }
  printf("\n");
  
#endif
#if PART==2 || PART==3
  
  printf("   ");
  for (i = 0; i < NUM_TRUNKS; i++)
    printf("% 4d ", i);
  printf("\n");
  conn.type = CONN_TRUNK;
  for (conn.trunk_index = 0; conn.trunk_index < NUM_TRUNK_PORTS; conn.trunk_index++) {
    printf("% 2d ", conn.trunk_index);
    for (conn.switch_number = 0; conn.switch_number < NUM_TRUNKS; conn.switch_number++) {
      print_connection(root_current_connection(state, conn), 'R');
    }
    printf("\n");
  }
  
#endif
#if PART==3
  
  printf("   ");
  for (i = 0; i < NUM_TRUNKS; i++)
    printf("% 4d ", i);
  printf("\n");
  conn.type = CONN_TRUNK;
  for (conn.trunk_index = 0; conn.trunk_index < NUM_TRUNK_PORTS; conn.trunk_index++) {
    printf("% 2d ", conn.trunk_index);
    for (conn.switch_number = 0; conn.switch_number < NUM_TRUNKS; conn.switch_number++) {
      print_connection(switch_current_connection(state, conn), 'S');
    }
    printf("\n");
  }
  
  printf("   ");
  for (i = 0; i < NUM_TRUNKS; i++)
    printf("% 4d ", i);
  printf("\n");
  conn.type = CONN_LINE;
  for (conn.phone_number = 0; conn.phone_number < NUM_PHONES_PER_SWITCH; conn.phone_number++) {
    printf("% 2d ", conn.phone_number);
    for (conn.switch_number = 0; conn.switch_number < NUM_TRUNKS; conn.switch_number++) {
      print_connection(switch_current_connection(state, conn), 'S');
    }
    printf("\n");
  }
  
#endif
}