Exemplo n.º 1
0
static int noit_lua_dns_lookup(lua_State *L) {
  dns_lookup_ctx_t *dlc, **holder;
  const char *c, *query = "", *ctype = "IN", *rtype = "A";
  char *ctype_up, *rtype_up, *d;
  void *vnv_pair;
  noit_lua_check_info_t *ci;

  ci = get_ci(L);
  assert(ci);

  holder = (dns_lookup_ctx_t **)lua_touserdata(L, lua_upvalueindex(1));
  if(holder != lua_touserdata(L,1))
    luaL_error(L, "Must be called as method\n");
  dlc = *holder;

  if(lua_gettop(L) > 1) query = lua_tostring(L, 2);
  if(lua_gettop(L) > 2) rtype = lua_tostring(L, 3);
  if(lua_gettop(L) > 3) ctype = lua_tostring(L, 4);

  ctype_up = alloca(strlen(ctype)+1);
  for(d = ctype_up, c = ctype; *c; d++, c++) *d = toupper(*c);
  *d = '\0';
  rtype_up = alloca(strlen(rtype)+1);
  for(d = rtype_up, c = rtype; *c; d++, c++) *d = toupper(*c);
  *d = '\0';

  if(!noit_hash_retrieve(&dns_ctypes, ctype_up, strlen(ctype_up), &vnv_pair))
    dlc->error = strdup("bad class");
  else
    dlc->query_ctype = ((struct dns_nameval *)vnv_pair)->val;

  if(!noit_hash_retrieve(&dns_rtypes, rtype_up, strlen(rtype_up), &vnv_pair)) 
    dlc->error = strdup("bad rr type");
  else
    dlc->query_rtype = ((struct dns_nameval *)vnv_pair)->val;

  dlc->active = 1;
  noit_atomic_inc32(&dlc->refcnt);
  if(!dlc->error) {
    int abs;
    if(!dns_ptodn(query, strlen(query), dlc->dn, sizeof(dlc->dn), &abs) ||
       !dns_submit_dn(dlc->h->ctx, dlc->dn, dlc->query_ctype, dlc->query_rtype,
                      abs | DNS_NOSRCH, NULL, dns_cb, dlc)) {
      dlc->error = strdup("submission error");
      noit_atomic_dec32(&dlc->refcnt);
    }
    else {
      struct timeval now;
      gettimeofday(&now, NULL);
      dns_timeouts(dlc->h->ctx, -1, now.tv_sec);
    }
  }
  if(dlc->error) {
    dlc->active = 0;
    luaL_error(L, "dns: %s\n", dlc->error);
  }
  return noit_lua_yield(ci, 0);
}
Exemplo n.º 2
0
int nl_dns_lookup(lua_State *L) {
  dns_lookup_ctx_t *dlc, **holder;
  const char *nameserver = NULL;
  noit_lua_check_info_t *ci;

  ci = get_ci(L);
  assert(ci);
  if(lua_gettop(L) > 0)
    nameserver = lua_tostring(L, 1);
  holder = (dns_lookup_ctx_t **)lua_newuserdata(L, sizeof(*holder));
  dlc = calloc(1, sizeof(*dlc));
  dlc->refcnt = 1;
  dlc->ci = ci;
  dlc->h = dns_ctx_alloc(nameserver);
  *holder = dlc;
  luaL_getmetatable(L, "noit.dns");
  lua_setmetatable(L, -2);
  return 1;
}
static int secure_gain_ci(void)	// from EFUSE
{
	char buf[128];
	char *pTemp= &(pci->data[0]);
	int ret;
	
	memset(buf, 0, 128);
	pTemp = &(pci->data[0]);
	if(!get_ci(buf, FROM_KERNEL)){		
		memcpy(pTemp, buf, CONFIG_EFUSE_CI_DATA_SIZE);
		pci->status = 0;
		ret = 0;
	}
	else{
		memset(pTemp, 0, CONFIG_EFUSE_CI_DATA_SIZE);
		pci->status = -1;
		ret = -1;
	}	
	return ret;
}