Ejemplo n.º 1
0
Archivo: proxy.c Proyecto: fbbs/fbbs
static void connection_error_callback(int fd)
{
	connection_t *conn = connections + fd;
	bool client = conn->client;
	int remote_fd = valid_remote_fd(fd) ? conn->remote_fd : REMOTE_NULL;

	connection_reset(conn);
	ev_io_stop(EV_DEFAULT_ &conn->watcher);
	close(fd);

	if (client) {
		if (remote_fd >= 0) {
			server_t *server = find_server(remote_fd);
			if (server && server->pid >= 0)
				kill(server->pid, SIGHUP);
		}
	} else {
		server_t *server = find_server(fd);
		if (server) {
			server->pid = -1;
			server->fd = -1;
			--server_size;
			if (proxy_shutdown) {
				if (!server_size)
					ev_break(EV_DEFAULT_ EVBREAK_ALL);
			} else {
				spawn_server(server);
			}
		}
	}
}
Ejemplo n.º 2
0
static void start_auth_request(PgSocket *client, const char *username)
{
	int res;
	char quoted_username[64], query[128];

	client->auth_user = client->db->auth_user;
	/* have to fetch user info from db */
	client->pool = get_pool(client->db, client->db->auth_user);
	if (!find_server(client)) {
		client->wait_for_user_conn = true;
		return;
	}
	slog_noise(client, "Doing auth_conn query");
	client->wait_for_user_conn = false;
	client->wait_for_user = true;
	if (!sbuf_pause(&client->sbuf)) {
		release_server(client->link);
		disconnect_client(client, true, "pause failed");
		return;
	}
	client->link->ready = 0;

	pg_quote_literal(quoted_username, username, sizeof(quoted_username));
	snprintf(query, sizeof(query), "SELECT usename, passwd FROM pg_shadow WHERE usename=%s", quoted_username);
	SEND_generic(res, client->link, 'Q', "s", query);
	if (!res)
		disconnect_server(client->link, false, "unable to send login query");
}
Ejemplo n.º 3
0
static int
m_alis(struct Client *client_p, struct Client *source_p,
	int parc, const char *parv[])
{
	char buf[BUFSIZE];
	int i = 1;

	if(find_server(NULL, "services.azzurra.org") == NULL)
	{
		sendto_one(source_p, 
			":%s 440 %s alis :Services are currently unavailable",
			me.name, source_p->name);
		return 0;
	}

	buf[0] = '\0';

	while(i < parc)
	{
		rb_strlcat(buf, parv[i], sizeof(buf));
		rb_strlcat(buf, " ", sizeof(buf));
		i++;
	}

	sendto_match_servs(client_p, "services.azzurra.org", CAP_ENCAP, NOCAPS,
			"ENCAP services.azzurra.org RSMSG alis %s",
			buf);
	return 0;
}
Ejemplo n.º 4
0
Archivo: db_tsig.c Proyecto: aosm/bind
DST_KEY *
tsig_key_from_addr(struct in_addr addr) {
	server_info si = find_server(addr);
	if (si == NULL || si->key_list == NULL || si->key_list->first == NULL)
		return(NULL);
	return(si->key_list->first->key);
}
Ejemplo n.º 5
0
void avrcp_unregister(const bdaddr_t *src)
{
	struct avctp_server *server;

	server = find_server(servers, src);
	if (!server)
		return;

	servers = g_slist_remove(servers, server);

#ifndef ANDROID
	remove_record_from_server(server->ct_record_id);
#endif
	remove_record_from_server(server->tg_record_id);

	g_io_channel_shutdown(server->io, TRUE, NULL);
	g_io_channel_unref(server->io);
	g_free(server);

	if (servers)
		return;

	dbus_connection_unref(connection);
	connection = NULL;
}
Ejemplo n.º 6
0
int server_unregister(struct btd_adapter *adapter, uint16_t id)
{
	struct network_adapter *na;
	struct network_server *ns;

	na = find_adapter(adapters, adapter);
	if (!na)
		return -EINVAL;

	ns = find_server(na->servers, id);
	if (!ns)
		return -EINVAL;

	na->servers = g_slist_remove(na->servers, ns);
	server_free(ns);

	if (g_slist_length(na->servers) > 0)
		return 0;

	g_dbus_unregister_interface(btd_get_dbus_connection(),
						adapter_get_path(adapter),
						NETWORK_SERVER_INTERFACE);

	return 0;
}
Ejemplo n.º 7
0
/*
** m_ping
**      parv[1] = origin
**      parv[2] = destination
*/
static int
m_ping(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
{
    struct Client *target_p;
    const char *destination;

    destination = parv[2];	/* Will get NULL or pointer (parc >= 2!!) */

    if(!EmptyString(destination) && !match(destination, me.name))
    {
        if((target_p = find_server(source_p, destination)))
        {
            sendto_one(target_p, ":%s PING %s :%s",
                       get_id(source_p, target_p),
                       source_p->name, get_id(target_p, target_p));
        }
        else
        {
            sendto_one_numeric(source_p, ERR_NOSUCHSERVER,
                               form_str(ERR_NOSUCHSERVER),
                               destination);
            return 0;
        }
    }
    else
        sendto_one(source_p, ":%s PONG %s :%s", me.name,
                   (destination) ? destination : me.name, parv[1]);

    return 0;
}
Ejemplo n.º 8
0
static struct avctp *avctp_get_internal(const bdaddr_t *src,
							const bdaddr_t *dst)
{
	struct avctp_server *server;
	struct avctp *session;

	assert(src != NULL);
	assert(dst != NULL);

	server = find_server(servers, src);
	if (server == NULL)
		return NULL;

	session = find_session(server->sessions, dst);
	if (session)
		return session;

	session = g_new0(struct avctp, 1);

	session->server = server;
	bacpy(&session->dst, dst);
	session->state = AVCTP_STATE_DISCONNECTED;

	server->sessions = g_slist_append(server->sessions, session);

	return session;
}
Ejemplo n.º 9
0
static void ms_ping(struct Client *client_p,
                   struct Client *source_p,
                   int parc,
                   char *parv[])
{
  struct Client *target_p;
  char  *origin, *destination;

  if (parc < 2 || *parv[1] == '\0')
  {
    sendto_one(source_p, form_str(ERR_NOORIGIN), me.name, parv[0]);
    return;
  }

/* origin == source_p->name, lets not even both wasting effort on it --fl_ */
  origin = source_p->name;
  destination = parv[2]; /* Will get NULL or pointer (parc >= 2!!) */

  if (!EmptyString(destination) && irccmp(destination, me.name))
  {
    if ((target_p = find_server(destination)))
      sendto_one(target_p,":%s PING %s :%s", parv[0],
                 origin, destination);
    else
    {
      sendto_one(source_p, form_str(ERR_NOSUCHSERVER),
                 me.name, parv[0], destination);
      return;
    }
  }
  else
    sendto_one(source_p,":%s PONG %s :%s", me.name,
               (destination) ? destination : me.name, origin);
}
Ejemplo n.º 10
0
static void
ms_pong(struct Client *client_p, struct Client *source_p, int parc, char *parv[])
{
	struct Client *target_p;
	const char *origin, *destination;

	if(parc < 2 || *parv[1] == '\0')
	{
		sendto_one(source_p, form_str(ERR_NOORIGIN), me.name, parv[0]);
		return;
	}

	origin = parv[1];
	destination = parv[2];

	/* Now attempt to route the PONG, comstud pointed out routable PING
	 * is used for SPING.  routable PING should also probably be left in
	 *        -Dianora
	 * That being the case, we will route, but only for registered clients (a
	 * case can be made to allow them only from servers). -Shadowfax
	 */
	if(!EmptyString(destination) && !match(destination, me.name) && irccmp(destination, me.id))
	{
		if((target_p = find_client(destination)) || (target_p = find_server(destination)))
			sendto_one(target_p, ":%s PONG %s %s", parv[0], origin, destination);
		else
		{
			sendto_one(source_p, form_str(ERR_NOSUCHSERVER),
				   me.name, parv[0], destination);
			return;
		}
	}
	else if(!HasSentEob(source_p))
		server_eob(source_p);
}
Ejemplo n.º 11
0
void avctp_unregister(const bdaddr_t *src)
{
	struct avctp_server *server;

	server = find_server(servers, src);
	if (!server)
		return;

	while (server->sessions)
		avctp_disconnected(server->sessions->data);

	servers = g_slist_remove(servers, server);

	g_io_channel_shutdown(server->io, TRUE, NULL);
	g_io_channel_unref(server->io);
	g_free(server);

	if (servers)
		return;

	if (passthrough_id) {
		avctp_unregister_pdu_handler(passthrough_id);
		passthrough_id = 0;
	}

	if (unit_id) {
		avctp_unregister_pdu_handler(unit_id);
		passthrough_id = 0;
	}

	if (subunit_id) {
		avctp_unregister_pdu_handler(subunit_id);
		subunit_id = 0;
	}
}
Ejemplo n.º 12
0
int sasl_capability_visible(void)
{
	if (!SASL_SERVER || !find_server(SASL_SERVER, NULL))
		return 0;
	
	return 1;
}
Ejemplo n.º 13
0
static void
ms_ping(struct Client *client_p, struct Client *source_p, int parc, char *parv[])
{
	struct Client *target_p;
	const char *origin, *destination;

	if(parc < 2 || *parv[1] == '\0')
	{
		sendto_one(source_p, form_str(ERR_NOORIGIN), me.name, parv[0]);
		return;
	}

	origin = source_p->name;
	destination = parv[2];	/* Will get NULL or pointer (parc >= 2!!) */

	if(!EmptyString(destination) && irccmp(destination, me.name) != 0
	   && irccmp(destination, me.id) != 0)
	{
		if((target_p = find_server(destination)))
			sendto_one(target_p, ":%s PING %s :%s", parv[0], origin, destination);
		else
		{
			sendto_one(source_p, form_str(ERR_NOSUCHSERVER),
				   ID_or_name(&me, client_p), parv[0], destination);
			return;
		}
	}
	else
		sendto_one(source_p, ":%s PONG %s :%s",
			   ID_or_name(&me, client_p), (destination) ? destination : me.name,
			   origin);
}
Ejemplo n.º 14
0
/*
 * mo_restart
 *
 */
static int
mo_restart(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
{
	if (!IsOperDie(source_p)) {
		sendto_one(source_p, form_str(ERR_NOPRIVS),
		           me.name, source_p->name, "die");
		return 0;
	}
	if (parc < 2 || EmptyString(parv[1])) {
		sendto_one_notice(source_p, ":Need server name /restart %s", me.name);
		return 0;
	}
	if (parc > 2) {
		/* Remote restart. Pass it along. */
		struct Client *server_p = find_server(NULL, parv[2]);
		if (!server_p) {
			sendto_one_numeric(source_p, ERR_NOSUCHSERVER, form_str(ERR_NOSUCHSERVER), parv[2]);
			return 0;
		}
		if (!IsMe(server_p)) {
			sendto_one(server_p, ":%s ENCAP %s RESTART %s", source_p->name, parv[2], parv[1]);
			return 0;
		}
	}
	return do_restart(source_p, parv[1]);
}
Ejemplo n.º 15
0
int m_map(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
{
  struct ConfItem* conf;

  if (!HasUmode(sptr,UMODE_SEEROUTING))
    {
      if (SeesOperMessages(sptr))
	sendto_one(sptr,":%s NOTICE %s :You have no V umode", me.name, parv[0]);
      else
	sendto_one(sptr, form_str(ERR_NOPRIVILEGES), me.name, parv[0]);
      return 0;
    }
  if (parc > 1)
    if (hunt_server(cptr, sptr, ":%s MAP %s", 1, parc, parv) != HUNTED_ISME)
      return 0;

  header_length = 0;
  header[0] = '\0';
  map_send_server(sptr, parv[0], &me);
  for (conf = ConfigItemList; conf; conf = conf->next)
    {
      if (conf->status != CONF_NOCONNECT_SERVER)
	continue;
      if (strcmp(conf->name, me.name) == 0)
	continue;
      if (!find_server(conf->name))
	sendto_one(sptr, form_str(RPL_MAP), me.name, parv[0], "** ", conf->name, -1);
    }
  sendto_one(sptr,form_str(RPL_ENDOFMAP),me.name,parv[0]);

  return 0;
}
Ejemplo n.º 16
0
/*
** m_ping
**      parv[0] = sender prefix
**      parv[1] = origin
**      parv[2] = destination
*/
static void
m_ping(struct Client *client_p, struct Client *source_p,
       int parc, char *parv[])
{
  struct Client *target_p;
  char  *origin, *destination;

  if (parc < 2 || *parv[1] == '\0')
  {
    sendto_one(source_p, form_str(ERR_NOORIGIN), me.name, parv[0]);
    return;
  }

  origin = parv[1];
  destination = parv[2]; /* Will get NULL or pointer (parc >= 2!!) */

  if (ConfigFileEntry.disable_remote && !IsOper(source_p))
  {
    sendto_one(source_p,":%s PONG %s :%s", me.name,
              (destination) ? destination : me.name, origin);
    return;
  }

  if (!EmptyString(destination) && irccmp(destination, me.name) != 0)
  {
    /* We're sending it across servers.. origin == client_p->name --fl_ */
    origin = client_p->name;

    /* XXX - sendto_server() ? --fl_ */
    if ((target_p = find_server(destination)) != NULL)
    {
      struct Client *ll_p;

      /* use the direct link for LL checking */
      ll_p = target_p->from;

      if(ServerInfo.hub && IsCapable(ll_p, CAP_LL))
      {
        if((ll_p->lazyLinkClientExists & target_p->localClient->serverMask) == 0)
          client_burst_if_needed(target_p, ll_p);
      }

      sendto_one(target_p,":%s PING %s :%s", parv[0],
                 origin, destination);
    }
    else
    {
      sendto_one(source_p, form_str(ERR_NOSUCHSERVER),
                 me.name, parv[0], destination);
      return;
    }
  }
  else
    sendto_one(source_p,":%s PONG %s :%s", me.name,
               (destination) ? destination : me.name, origin);
}
Ejemplo n.º 17
0
/*
** m_pong
**      parv[0] = sender prefix
**      parv[1] = origin
**      parv[2] = destination
*/
int     m_pong(struct Client *cptr,
               struct Client *sptr,
               int parc,
               char *parv[])
{
  struct Client *acptr = NULL;
  char  *origin, *destination;

  if (parc < 2 || *parv[1] == '\0')
    {
      sendto_one(sptr, form_str(ERR_NOORIGIN), me.name, parv[0]);
      return 0;
    }

  origin = parv[1];
  destination = parv[2];

  /* Now attempt to route the PONG, comstud pointed out routable PING
   * is used for SPING.  routable PING should also probably be left in
   *        -Dianora
   * That being the case, we will route, but only for registered clients (a
   * case can be made to allow them only from servers). -Shadowfax
   */
  if (!EmptyString(destination) && irccmp(destination, me.name) != 0
                && IsRegistered(sptr))
    {
      if ((acptr = find_client(destination, NULL)) ||
          (acptr = find_server(destination)))
        sendto_one(acptr,":%s PONG %s %s",
                   parv[0], origin, destination);
      else
        {
          sendto_one(sptr, form_str(ERR_NOSUCHSERVER),
                     me.name, parv[0], destination);
          return 0;
        }
    }
  else
    {
      if (MyConnect(sptr))
      {
        sptr->flags &= ~FLAGS_PINGSENT;
#ifdef NEED_SPLITCODE
#ifdef SPLIT_PONG
        if (IsServer(sptr))
          got_server_pong = 1;
#endif
#endif
      }
#ifdef  DEBUGMODE
      Debug((DEBUG_NOTICE, "PONG: %s %s", origin,
           destination ? destination : "*"));
#endif
    }
  return 0;
}
Ejemplo n.º 18
0
/*
** m_ping
**      parv[0] = sender prefix
**      parv[1] = origin
**      parv[2] = destination
*/
int     m_ping(struct Client *cptr,
               struct Client *sptr,
               int parc,
               char *parv[])
{
  struct Client *acptr;
  char  *origin, *destination;

  if (parc < 2 || *parv[1] == '\0')
    {
      sendto_one(sptr, form_str(ERR_NOORIGIN), me.name, parv[0]);
      return 0;
    }
  origin = parv[1];
  destination = parv[2]; /* Will get NULL or pointer (parc >= 2!!) */

  acptr = find_client(origin, NULL);
  if (!acptr)
    acptr = find_server(origin);
  if (acptr && acptr != sptr)
    origin = cptr->name;
  if (!EmptyString(destination) && irccmp(destination, me.name) != 0)
    {
      if ((acptr = find_server(destination)))
        sendto_one(acptr,":%s PING %s :%s", parv[0],
                   origin, destination);
      else
        {
          sendto_one(sptr, form_str(ERR_NOSUCHSERVER),
                     me.name, parv[0], destination);
          return 0;
        }
    }
  else
    {
      sendto_one(sptr,":%s PONG %s :%s", me.name,
               (destination) ? destination : me.name, origin);

      if(MyClient(sptr) && cptr->user)
          check_idle_actions(cptr);
    }
  return 0;
}
Ejemplo n.º 19
0
static void confirm_event(GIOChannel *chan, gpointer user_data)
{
	struct network_adapter *na = user_data;
	struct network_server *ns;
	int perr;
	bdaddr_t src, dst;
	char address[18];
	GError *err = NULL;

	bt_io_get(chan, BT_IO_L2CAP, &err,
			BT_IO_OPT_SOURCE_BDADDR, &src,
			BT_IO_OPT_DEST_BDADDR, &dst,
			BT_IO_OPT_DEST, address,
			BT_IO_OPT_INVALID);
	if (err) {
		error("%s", err->message);
		g_error_free(err);
		goto drop;
	}

	DBG("BNEP: incoming connect from %s", address);

	if (na->setup) {
		error("Refusing connect from %s: setup in progress", address);
		goto drop;
	}

	ns = find_server(na->servers, BNEP_SVC_NAP);
	if (!ns)
		goto drop;

	if (!ns->record_id)
		goto drop;

	if (!ns->bridge)
		goto drop;

	na->setup = g_new0(struct network_session, 1);
	bacpy(&na->setup->dst, &dst);
	na->setup->io = g_io_channel_ref(chan);

	perr = btd_request_authorization(&src, &dst, BNEP_SVC_UUID,
					auth_cb, na);
	if (perr < 0) {
		error("Refusing connect from %s: %s (%d)", address,
				strerror(-perr), -perr);
		setup_destroy(na);
		goto drop;
	}

	return;

drop:
	g_io_channel_shutdown(chan, TRUE, NULL);
}
Ejemplo n.º 20
0
void serverlist_frame() {
    int i;
    for (i = 0; i < server_count; i++) {
        msg_t *msg = sock_recv(&serverlist[i].sock);
        if (msg) {
            serverlist[i].ping_end = millis();
            skip_data(msg, strlen("info\n"));
            read_server(serverlist + i, read_string(msg));
            if (partial_match(filter, serverlist[i].name) || partial_match(filter, serverlist[i].map)
                    || partial_match(filter, serverlist[i].mod) || partial_match(filter, serverlist[i].gametype))
                ui_output(output_client, "^5%i ^7(%i) %s %s ^5[^7%s^5] [^7%s:%s^5]\n", i, serverlist[i].ping_end - serverlist[i].ping_start,
                        serverlist[i].players, serverlist[i].name, serverlist[i].map, serverlist[i].mod, serverlist[i].gametype);
            serverlist[i].received = qtrue;
        }
        if (serverlist[i].ping_retries > 0
                && !serverlist[i].received && millis() >= serverlist[i].ping_start + PING_TIMEOUT)
            ping_server(serverlist + i);
    }

    master_t *master;
    for (master = masters; master->address; master++) {
        msg_t *msg = sock_recv(&master->sock);
        if (!msg)
            continue;

        char address_string[32];
        qbyte address[4];
        unsigned short port;

        skip_data(msg, strlen("getserversResponse"));
        while (msg->readcount + 7 <= msg->cursize) {
            char prefix = read_char(msg);
            port = 0;

            if (prefix == '\\') {
                read_data(msg, address, 4);
                port = ShortSwap(read_short(msg));
                sprintf(address_string, "%u.%u.%u.%u", address[0], address[1], address[2], address[3]);
            }

            if (port != 0) {
                server_t *server = find_server(address_string, port);
                if (server != NULL)
                    continue;
                server = serverlist + server_count++;
                sock_init(&server->sock);
                strcpy(server->address, address_string);
                server->port = port;
                server->received = qfalse;
                server->ping_retries = MAX_PING_RETRIES + 1;
                ping_server(server);
            }
        }
    }
}
Ejemplo n.º 21
0
void ec_server(char *from, char *to)
{
	Server	*sv;
	char	*s;

	if ((sv = find_server(current->server)))
		s = (*sv->realname) ? sv->realname : sv->name;
	else
		s = TEXT_NOTINSERVLIST;
	nobo_strcpy(s);
}
static gboolean
slmock_check_login(GDBusConnection * session, slmock_table_t * slmockdata, gboolean clear_cache)
{
	if (clear_cache) {
		gchar *username_sha = g_compute_checksum_for_string (G_CHECKSUM_SHA256, slmockdata->username, -1);
		gchar *file_path = g_build_path ("/", g_get_user_cache_dir(), "remote-logon-service", "cache", username_sha, NULL);
		unlink (file_path);
		g_free (username_sha);
		g_free (file_path);
	}
	GVariant * retval = g_dbus_connection_call_sync(session,
	                                                "org.ArcticaProject.RemoteLogon",
	                                                "/org/ArcticaProject/RemoteLogon",
	                                                "org.ArcticaProject.RemoteLogon",
	                                                "GetServersForLogin",
	                                                g_variant_new("(sssb)",
	                                                              "https://slmock.com/",
	                                                              slmockdata->username,
	                                                              slmockdata->password,
	                                                              TRUE), /* params */
	                                                G_VARIANT_TYPE("(bsa(sssba(sbva{sv})a(si)))"), /* ret type */
	                                                G_DBUS_CALL_FLAGS_NONE,
	                                                -1,
	                                                NULL,
	                                                NULL);

	g_assert(retval != NULL);
	g_assert(g_variant_n_children(retval) == 3);

	GVariant * loggedin = g_variant_get_child_value(retval, 0);
	g_assert(g_variant_get_boolean(loggedin));
	g_variant_unref(loggedin); loggedin = NULL;

	GVariant * data = g_variant_get_child_value(retval, 1);
	g_assert(g_strcmp0(g_variant_get_string(data, NULL), "network") == 0);
	g_variant_unref(data); data = NULL;

	GVariant * array = g_variant_get_child_value(retval, 2);
	int i;
	// Check all servers should be in the result are in the result
	for (i = 0; slmockdata->servers[i].name != NULL; i++) {
		g_assert(find_server(array, &slmockdata->servers[i]));
	}
	// Check there is no more servers in the result than we expected
	g_assert(i == g_variant_n_children(array));
	g_variant_unref(array);

	g_variant_unref(retval);

	return TRUE;
}
Ejemplo n.º 23
0
static void ms_pong(struct Client *client_p,
                   struct Client *source_p,
                   int parc,
                   char *parv[])
{
  struct Client *target_p;
  char  *origin, *destination;

  cluster_prefix(client_p, parc, parv, 0, 0, 0);
  if (parc > 0 && parv[1] && !strchr(parv[1], '.'))
  	cluster_prefix(client_p, parc, parv, 1, 0, 0);
  if (parc > 1 && parv[2] && !strchr(parv[2], '.'))
  	cluster_prefix(client_p, parc, parv, 2, 0, 0);

  if (parc < 2 || *parv[1] == '\0')
    {
      sendto_one(source_p, form_str(source_p,ERR_NOORIGIN), me.name, parv[0]);
      return;
    }

  origin = parv[1];
  destination = parv[2];
  source_p->flags &= ~FLAGS_PINGSENT;

  /* Now attempt to route the PONG, comstud pointed out routable PING
   * is used for SPING.  routable PING should also probably be left in
   *        -Dianora
   * That being the case, we will route, but only for registered clients (a
   * case can be made to allow them only from servers). -Shadowfax
   */
  if (!EmptyString(destination) && !match(destination, me.name))
    {
      if ((target_p = find_client(destination)) ||
          (target_p = find_server(destination)))
        sendto_one(target_p,":%s PONG %s %s",
                   parv[0], origin, destination);
      else
        {
          sendto_one(source_p, form_str(source_p,ERR_NOSUCHSERVER),
                     me.name, parv[0], destination);
          return;
        }
    }

#ifdef  DEBUGMODE
  else
    Debug((DEBUG_NOTICE, "PONG: %s %s", origin,
           destination ? destination : "*"));
#endif
  return;
}
Ejemplo n.º 24
0
/*
** m_ping
**      parv[0] = sender prefix
**      parv[1] = origin
**      parv[2] = destination
*/
static void m_ping(struct Client *client_p,
                  struct Client *source_p,
                  int parc,
                  char *parv[])
{
  struct Client *target_p;
  char  *origin, *destination;

  if (parc < 2 || *parv[1] == '\0')
  {
    sendto_one(source_p, form_str(ERR_NOORIGIN), me.name, parv[0]);
    return;
  }

  origin = parv[1];
  destination = parv[2]; /* Will get NULL or pointer (parc >= 2!!) */

  if (ConfigServerHide.disable_remote && !IsOper(source_p))
  {
   sendto_one(source_p,":%s PONG %s :%s", me.name,
              (destination) ? destination : me.name, origin);
   return;
  }

  if (!EmptyString(destination) && irccmp(destination, me.name))
  {
    /* We're sending it across servers.. origin == client_p->name --fl_ */
    origin = client_p->name;

    /* XXX - sendto_server() ? --fl_ */
    if ((target_p = find_server(destination)))
    {
      /* use the direct link for LL checking */
      target_p = target_p->from;

      sendto_one(target_p,":%s PING %s :%s", parv[0],
                 origin, destination);
    }
    else
    {
      sendto_one(source_p, form_str(ERR_NOSUCHSERVER),
                 me.name, parv[0], destination);
      return;
    }
  }
  else
    sendto_one(source_p,":%s PONG %s :%s", me.name,
               (destination) ? destination : me.name, origin);
}
Ejemplo n.º 25
0
int server_register(struct btd_adapter *adapter, uint16_t id)
{
	struct network_adapter *na;
	struct network_server *ns;
	const char *path;

	na = find_adapter(adapters, adapter);
	if (!na) {
		na = create_adapter(adapter);
		if (!na)
			return -EINVAL;
		adapters = g_slist_append(adapters, na);
	}

	ns = find_server(na->servers, id);
	if (ns)
		return 0;

	ns = g_new0(struct network_server, 1);

	ns->name = g_strdup("Network service");

	path = adapter_get_path(adapter);

	if (g_slist_length(na->servers) > 0)
		goto done;

	if (!g_dbus_register_interface(btd_get_dbus_connection(), path,
						NETWORK_SERVER_INTERFACE,
						server_methods, NULL, NULL, na,
						path_unregister)) {
		error("D-Bus failed to register %s interface",
						NETWORK_SERVER_INTERFACE);
		server_free(ns);
		return -1;
	}

	DBG("Registered interface %s on path %s", NETWORK_SERVER_INTERFACE,
									path);

done:
	bacpy(&ns->src, btd_adapter_get_address(adapter));
	ns->id = id;
	ns->na = na;
	ns->record_id = 0;
	na->servers = g_slist_append(na->servers, ns);

	return 0;
}
Ejemplo n.º 26
0
/*
 * m_spingtime - SPINGTIME
 * parv[0] - sender
 * parv[1] - server to set ping time for
 * parv[2] - ping time
 */
static void ms_spingtime(struct Client *client_p, struct Client *source_p,
              int parc, char *parv[])
{

  struct Client *target_p;

  if ((target_p = find_server(parv[1])) == NULL)
      return;

  target_p->ping_time.tv_sec = 0;
  target_p->ping_time.tv_usec = atol(parv[2]);
  
  sendto_server(client_p, NULL, NULL, NOCAPS, NOCAPS, NOFLAGS,
                    ":%s SPINGTIME %s %s", parv[0], parv[1],
                  parv[2]);
}
Ejemplo n.º 27
0
/*
 * m_svinfo - SVINFO message handler
 *      parv[0] = sender prefix
 *      parv[1] = TS_CURRENT for the server
 *      parv[2] = TS_MIN for the server
 *      parv[3] = clock ts 
 */
int m_svinfo(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
{
  aConfItem *aconf;
  time_t remote_ts = 0;
  struct Client *acptr;
  
  if (MyConnect(sptr) && IsUnknown(sptr))
    return exit_client(sptr, sptr, sptr, "Need SERVER before SVINFO");

  if (!IsServer(sptr) || !MyConnect(sptr) || parc < 3)
    return 0;
    
  if (TS_CURRENT < atoi(parv[2]) || atoi(parv[1]) < TS_MIN)
    {
      /*
       * a server with the wrong TS version connected; since we're
       * TS_ONLY we can't fall back to the non-TS protocol so
       * we drop the link  -orabidoo
       */
#ifdef HIDE_SERVERS_IPS
      sendto_realops("Link %s dropped, incompatible TS protocol version (%s,%s)",
                 get_client_name(sptr,MASK_IP), parv[1], parv[2]);
#else
      sendto_realops("Link %s dropped, incompatible TS protocol version (%s,%s)",
                 get_client_name(sptr, TRUE), parv[1], parv[2]);
#endif     
      return exit_client(sptr, sptr, sptr, "Incompatible TS version");
    }

  if(parc>3)
    {
      remote_ts = atol(parv[3]);
      if (UseIRCNTP && (remote_ts > 0)) 
        {
          if(IsService(cptr) || 
          ((aconf = find_conf_host(cptr->confs, sptr->name, CONF_HUB)) 
          	&& !(acptr = find_server(ServicesServer))))
            {
              ircntp_offset = remote_ts - time(NULL);
              sendto_realops("Adjusting IRCNTP offset to %d",
                ircntp_offset);
            }
        }
    }
    
  return 0;
}
Ejemplo n.º 28
0
static int
ms_pong(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
{
    struct Client *target_p;
    const char *destination;

    destination = parv[2];
    source_p->flags &= ~FLAGS_PINGSENT;

    /* Now attempt to route the PONG, comstud pointed out routable PING
     * is used for SPING.  routable PING should also probably be left in
     *        -Dianora
     * That being the case, we will route, but only for registered clients (a
     * case can be made to allow them only from servers). -Shadowfax
     */
    if(!EmptyString(destination) && !match(destination, me.name) &&
            irccmp(destination, me.id))
    {
        if((target_p = find_client(destination)) ||
                (target_p = find_server(NULL, destination)))
            sendto_one(target_p, ":%s PONG %s %s",
                       get_id(source_p, target_p), parv[1],
                       get_id(target_p, target_p));
        else
        {
            if(!IsDigit(*destination))
                sendto_one_numeric(source_p, ERR_NOSUCHSERVER,
                                   form_str(ERR_NOSUCHSERVER), destination);
            return 0;
        }
    }

    /* destination is us, emulate EOB */
    if(IsServer(source_p) && !HasSentEob(source_p))
    {
        if(MyConnect(source_p))
            sendto_realops_snomask(SNO_GENERAL, L_ALL,
                                   "End of burst (emulated) from %s (%d seconds)",
                                   source_p->name,
                                   (signed int) (CurrentTime - source_p->localClient->firsttime));
        SetEob(source_p);
        eob_count++;
        call_hook(h_server_eob, source_p);
    }

    return 0;
}
Ejemplo n.º 29
0
int server_register(struct btd_adapter *adapter)
{
	struct network_adapter *na;
	struct network_server *ns;
	const char *path;

	na = find_adapter(adapters, adapter);
	if (!na) {
		na = create_adapter(adapter);
		if (!na)
			return -EINVAL;
		adapters = g_slist_append(adapters, na);
	}

	ns = find_server(na->servers, BNEP_SVC_NAP);
	if (ns)
		return 0;

	ns = g_new0(struct network_server, 1);

	ns->iface = g_strdup(NETWORK_SERVER_INTERFACE);
	ns->name = g_strdup("Network service");

	path = adapter_get_path(adapter);

	if (!g_dbus_register_interface(connection, path, ns->iface,
					server_methods, NULL, NULL,
					ns, path_unregister)) {
		error("D-Bus failed to register %s interface",
				ns->iface);
		server_free(ns);
		return -1;
	}

	adapter_get_address(adapter, &ns->src);
	ns->id = BNEP_SVC_NAP;
	ns->na = na;
	ns->record_id = 0;
	na->servers = g_slist_append(na->servers, ns);

	DBG("Registered interface %s on path %s", ns->iface, path);

	return 0;
}
Ejemplo n.º 30
0
int server_unregister(struct btd_adapter *adapter)
{
	struct network_adapter *na;
	struct network_server *ns;
	uint16_t id = BNEP_SVC_NAP;

	na = find_adapter(adapters, adapter);
	if (!na)
		return -EINVAL;

	ns = find_server(na->servers, id);
	if (!ns)
		return -EINVAL;

	g_dbus_unregister_interface(connection, adapter_get_path(adapter),
					ns->iface);

	return 0;
}