예제 #1
0
파일: dns.c 프로젝트: ahf/charybdis
/* See lookup_ip's comment */
struct dns_query *
lookup_hostname(const char *ip, DNSCB callback, void *data)
{
	struct dns_query *query = rb_malloc(sizeof(struct dns_query));
	int aftype;

	if(!rb_inet_pton_sock(ip, (struct sockaddr *)&query->addr))
	{
		rb_free(query);
		return NULL;
	}

	aftype = GET_SS_FAMILY(&query->addr);

	if(aftype == AF_INET)
		query->type = QUERY_PTR_A;
	else if(aftype == AF_INET6)
		query->type = QUERY_PTR_AAAA;
	else
	{
		rb_free(query);
		return NULL;
	}

	query->id = query_count++;
	query->callback = callback;
	query->data = data;

	query->query.ptr = query;
	query->query.callback = handle_lookup_hostname_reply;

	gethost_byaddr(&query->addr, &query->query);

	return query;
}
예제 #2
0
void start_auth(struct Client* client)
{
  struct AuthRequest* auth = 0;

  assert(0 != client);

  if (conf_check_slines(client)) {
    sendheader(client, REPORT_USING_SLINE);
    SetSLined(client);
    release_auth_client(client);
    return;
  }

  auth = make_auth_request(client);
  assert(0 != auth);

  Debug((DEBUG_INFO, "Beginning auth request on client %p", client));

  if (!feature_bool(FEAT_NODNS)) {
    if (LOOPBACK == inet_netof(cli_ip(client)))
      strcpy(cli_sockhost(client), cli_name(&me));
    else {
      struct DNSQuery query;

      query.vptr     = auth;
      query.callback = auth_dns_callback;

      if (IsUserPort(auth->client))
	sendheader(client, REPORT_DO_DNS);

      cli_dns_reply(client) = gethost_byaddr((const char*) &(cli_ip(client)),
					     &query);

      if (cli_dns_reply(client)) {
	++(cli_dns_reply(client))->ref_count;
	ircd_strncpy(cli_sockhost(client), cli_dns_reply(client)->hp->h_name,
		     HOSTLEN);
	if (IsUserPort(auth->client))
	  sendheader(client, REPORT_FIN_DNSC);
	Debug((DEBUG_LIST, "DNS entry for %p was cached", auth->client));
      } else
	SetDNSPending(auth);
    }
  }

  if (start_auth_query(auth)) {
    Debug((DEBUG_LIST, "identd query for %p initiated successfully",
	   auth->client));
    link_auth_request(auth, &AuthPollList);
  } else if (IsDNSPending(auth)) {
    Debug((DEBUG_LIST, "identd query for %p not initiated successfully; "
	   "waiting on DNS", auth->client));
    link_auth_request(auth, &AuthIncompleteList);
  } else {
    Debug((DEBUG_LIST, "identd query for %p not initiated successfully; "
	   "no DNS pending; releasing immediately", auth->client));
    free_auth_request(auth);
    release_auth_client(client);
  }
}
예제 #3
0
static void
resolve_ip(char **parv)
{
	char *requestid = parv[1];
	char *iptype = parv[2];
	char *rec = parv[3];
	int aftype;
	struct dns_request *req;
	if(strlen(requestid) >= REQIDLEN)
		exit(3);

	req = rb_malloc(sizeof(struct dns_request));
	req->revfwd = REQREV;
	strcpy(req->reqid, requestid);

	if(!rb_inet_pton_sock(rec, (struct sockaddr *)&req->addr))
		exit(6);

	aftype = GET_SS_FAMILY(&req->addr);
	switch (*iptype)
	{
	case '4':
		req->reqtype = REVIPV4;
		if(aftype != AF_INET)
			exit(6);
		break;
	case '6':
		req->reqtype = REVIPV6;
		if(aftype != AF_INET6)
			exit(6);
		break;
	default:
		exit(7);
	}
	req->query.ptr = req;
	req->query.callback = send_answer;
	gethost_byaddr(&req->addr, &req->query);
}