Exemplo n.º 1
0
/**
 * Parse the URL provided into an apr_ldap_url_desc_t object.
 *
 * APR_SUCCESS is returned on success, APR_EGENERAL on failure.
 * The LDAP result code and reason string is returned in the
 * apr_ldap_err_t structure.
 */
APU_DECLARE(int) apr_ldap_url_parse(apr_pool_t *pool,
                                    const char *url_in,
                                    apr_ldap_url_desc_t **ludpp,
                                    apr_ldap_err_t **result_err)
{

    int rc = apr_ldap_url_parse_ext(pool, url_in, ludpp, result_err);
    if( rc != APR_SUCCESS ) {
        return rc;
    }

    if ((*ludpp)->lud_scope == -1) {
        (*ludpp)->lud_scope = LDAP_SCOPE_BASE;
    }

    if ((*ludpp)->lud_host != NULL && *(*ludpp)->lud_host == '\0') {
        (*ludpp)->lud_host = NULL;
    }

    return rc;

}
Exemplo n.º 2
0
int lua_apr_ldap_url_parse(lua_State*L)
{
  apr_ldap_url_desc_t *ludpp;
  apr_pool_t *memory_pool;
  apr_ldap_err_t *error = NULL;
  const char *url;
  int status, i;
  char *attr, *ext;

  memory_pool = to_pool(L);
  url = luaL_checkstring(L, 1);
  status = apr_ldap_url_parse_ext(memory_pool, url, &ludpp, &error);
  if (status != APR_LDAP_URL_SUCCESS) {
    push_ldap_error(L, status, error);
    lua_pop(L, 1);
    switch (status) {
      case APR_LDAP_URL_ERR_MEM:          lua_pushliteral(L, "MEM");          return 3;
      case APR_LDAP_URL_ERR_PARAM:        lua_pushliteral(L, "PARAM");        return 3;
      case APR_LDAP_URL_ERR_BADSCHEME:    lua_pushliteral(L, "BADSCHEME");    return 3;
      case APR_LDAP_URL_ERR_BADENCLOSURE: lua_pushliteral(L, "BADENCLOSURE"); return 3;
      case APR_LDAP_URL_ERR_BADURL:       lua_pushliteral(L, "BADURL");       return 3;
      case APR_LDAP_URL_ERR_BADHOST:      lua_pushliteral(L, "BADHOST");      return 3;
      case APR_LDAP_URL_ERR_BADATTRS:     lua_pushliteral(L, "BADATTRS");     return 3;
      case APR_LDAP_URL_ERR_BADSCOPE:     lua_pushliteral(L, "BADSCOPE");     return 3;
      case APR_LDAP_URL_ERR_BADFILTER:    lua_pushliteral(L, "BADFILTER");    return 3;
      case APR_LDAP_URL_ERR_BADEXTS:      lua_pushliteral(L, "BADEXTS");      return 3;
      default:                                                                return 2;
    }
  }

  lua_newtable(L);

  lua_pushstring(L, ludpp->lud_scheme);
  lua_setfield(L, -2, "scheme");

  lua_pushstring(L, ludpp->lud_host);
  lua_setfield(L, -2, "host");

  lua_pushinteger(L, ludpp->lud_port);
  lua_setfield(L, -2, "port");

  if (ludpp->lud_scope == LDAP_SCOPE_BASE)
    lua_pushliteral(L, "base");
  else if (ludpp->lud_scope == LDAP_SCOPE_ONELEVEL)
    lua_pushliteral(L, "one");
  else
    lua_pushliteral(L, "sub");
  lua_setfield(L, -2, "scope");

  lua_pushstring(L, ludpp->lud_filter);
  lua_setfield(L, -2, "filter");

  lua_pushstring(L, ludpp->lud_dn);
  lua_setfield(L, -2, "dn");

  lua_pushinteger(L, ludpp->lud_crit_exts);
  lua_setfield(L, -2, "crit_exts");

  if (ludpp->lud_attrs != NULL) {
    i = 0;
    lua_newtable(L);
    while ((attr = ludpp->lud_attrs[i++]) != NULL) {
      lua_pushinteger(L, i + 1);
      lua_pushstring(L, attr);
      lua_settable(L, -3);
    }
    lua_setfield(L, -2, "attrs");
  }

  if (ludpp->lud_exts != NULL) {
    i = 0;
    lua_newtable(L);
    while ((ext = ludpp->lud_exts[i++]) != NULL) {
      lua_pushinteger(L, i + 1);
      lua_pushstring(L, ext);
      lua_settable(L, -3);
    }
    lua_setfield(L, -2, "exts");
  }

  return 1;
}