Ejemplo n.º 1
0
/*
** Delete an entry.
** @param #1 LDAP connection.
** @param #2 String with entry's DN.
** @return Boolean.
*/
static int lualdap_delete (lua_State *L) {
	conn_data *conn = getconnection (L);
	ldap_pchar_t dn = (ldap_pchar_t) luaL_checkstring (L, 2);
	ldap_int_t rc, msgid;
	rc = ldap_delete_ext (conn->ld, dn, NULL, NULL, &msgid);
	return create_future (L, rc, 1, msgid, LDAP_RES_DELETE);
}
Ejemplo n.º 2
0
static int lua_apr_ldap_modify(lua_State *L)
{
  lua_apr_ldap_object *object;
  ldap_pchar_t dn;
  attrs_data attrs;
  ldap_int_t rc, msgid;
  int param = 3;

  object = check_ldap_connection(L, 1);
  dn = (ldap_pchar_t) luaL_checkstring(L, 2);
  A_init (&attrs);

  while (lua_istable(L, param)) {
    int op;
    /* get operation ('+','-','=' operations allowed) */
    lua_rawgeti(L, param, 1);
    op = op2code(lua_tostring(L, -1));
    if (op == LUA_APR_LDAP_NOOP)
      return luaL_error(L, "Forgotten operation on argument #%d!", param);
    /* get array of attributes and values */
    A_tab2mod(L, &attrs, param, op);
    param++;
  }
  A_lastattr(L, &attrs);
  rc = ldap_modify_ext(object->ldap, dn, attrs.attrs, NULL, NULL, &msgid);
  return create_future(L, rc, 1, msgid, LDAP_RES_MODIFY);
}
Ejemplo n.º 3
0
/*
** Change the distinguished name of an entry.
*/
static int lualdap_rename (lua_State *L) {
	conn_data *conn = getconnection (L);
	ldap_pchar_t dn = (ldap_pchar_t) luaL_checkstring (L, 2);
	ldap_pchar_t rdn = (ldap_pchar_t) luaL_checkstring (L, 3);
	ldap_pchar_t par = (ldap_pchar_t) luaL_optlstring (L, 4, NULL, NULL);
	const int del = luaL_optnumber (L, 5, 0);
	ldap_int_t msgid;
	ldap_int_t rc = ldap_rename (conn->ld, dn, rdn, par, del, NULL, NULL, &msgid);
	return create_future (L, rc, 1, msgid, LDAP_RES_MODDN);
}
Ejemplo n.º 4
0
/*
** Compare a value against an entry.
** @param #1 LDAP connection.
** @param #2 String with entry's DN.
** @param #3 String with attribute's name.
** @param #4 String with attribute's value.
** @return Function to process the LDAP result.
*/
static int lualdap_compare (lua_State *L) {
	conn_data *conn = getconnection (L);
	ldap_pchar_t dn = (ldap_pchar_t) luaL_checkstring (L, 2);
	ldap_pchar_t attr = (ldap_pchar_t) luaL_checkstring (L, 3);
	BerValue bvalue;
	ldap_int_t rc, msgid;
	bvalue.bv_val = (char *)luaL_checkstring (L, 4);
	bvalue.bv_len = lua_strlen (L, 4);
	rc = ldap_compare_ext (conn->ld, dn, attr, &bvalue, NULL, NULL, &msgid);
	return create_future (L, rc, 1, msgid, LDAP_RES_COMPARE);
}
Ejemplo n.º 5
0
static int lua_apr_ldap_delete(lua_State *L)
{
  lua_apr_ldap_object *object;
  ldap_pchar_t dn;
  ldap_int_t rc, msgid;

  object = check_ldap_connection(L, 1);
  dn = (ldap_pchar_t) luaL_checkstring(L, 2);
  rc = ldap_delete_ext(object->ldap, dn, NULL, NULL, &msgid);
  return create_future(L, rc, 1, msgid, LDAP_RES_DELETE);
}
Ejemplo n.º 6
0
/*
** Add a new entry to the directory.
** @param #1 LDAP connection.
** @param #2 String with new entry's DN.
** @param #3 Table with new entry's attributes and values.
** @return Function to process the LDAP result.
*/
static int lualdap_add (lua_State *L) {
	conn_data *conn = getconnection (L);
	ldap_pchar_t dn = (ldap_pchar_t) luaL_checkstring (L, 2);
	attrs_data attrs;
	ldap_int_t rc, msgid;
	A_init (&attrs);
	if (lua_istable (L, 3))
		A_tab2mod (L, &attrs, 3, LUALDAP_MOD_ADD);
	A_lastattr (L, &attrs);
	rc = ldap_add_ext (conn->ld, dn, attrs.attrs, NULL, NULL, &msgid);
	return create_future (L, rc, 1, msgid, LDAP_RES_ADD);
}
Ejemplo n.º 7
0
static int lua_apr_ldap_compare(lua_State *L)
{
  lua_apr_ldap_object *object;
  ldap_pchar_t dn, attr;
  BerValue bvalue;
  ldap_int_t rc, msgid;

  object = check_ldap_connection(L, 1);
  dn = (ldap_pchar_t) luaL_checkstring(L, 2);
  attr = (ldap_pchar_t) luaL_checkstring(L, 3);
  bvalue.bv_val = (char *)luaL_checkstring(L, 4);
  bvalue.bv_len = lua_strlen(L, 4);
  rc = ldap_compare_ext(object->ldap, dn, attr, &bvalue, NULL, NULL, &msgid);
  return create_future(L, rc, 1, msgid, LDAP_RES_COMPARE);
}
Ejemplo n.º 8
0
static int lua_apr_ldap_rename(lua_State *L)
{
  lua_apr_ldap_object *object;
  ldap_pchar_t dn, rdn, par;
  ldap_int_t msgid;
  ldap_int_t rc;
  int del;

  object = check_ldap_connection(L, 1);
  dn = (ldap_pchar_t) luaL_checkstring(L, 2);
  rdn = (ldap_pchar_t) luaL_checkstring(L, 3);
  par = (ldap_pchar_t) luaL_optstring(L, 4, NULL);
  del = luaL_optint(L, 5, 0);
  rc = ldap_rename(object->ldap, dn, rdn, par, del, NULL, NULL, &msgid);
  return create_future(L, rc, 1, msgid, LDAP_RES_MODDN);
}
Ejemplo n.º 9
0
static int lua_apr_ldap_add(lua_State *L)
{
  lua_apr_ldap_object *object;
  ldap_pchar_t dn;
  attrs_data attrs;
  ldap_int_t rc, msgid;

  object = check_ldap_connection(L, 1);
  dn = (ldap_pchar_t) luaL_checkstring(L, 2);

  A_init(&attrs);
  if (lua_istable(L, 3))
    A_tab2mod(L, &attrs, 3, LUA_APR_LDAP_MOD_ADD);
  A_lastattr(L, &attrs);
  rc = ldap_add_ext(object->ldap, dn, attrs.attrs, NULL, NULL, &msgid);
  return create_future(L, rc, 1, msgid, LDAP_RES_ADD);
}
Ejemplo n.º 10
0
/*
** Modify an entry.
** @param #1 LDAP connection.
** @param #2 String with entry's DN.
** @param #3, #4... Tables with modifications to apply.
** @return True on success or nil, error message otherwise.
*/
static int lualdap_modify (lua_State *L) {
	conn_data *conn = getconnection (L);
	ldap_pchar_t dn = (ldap_pchar_t) luaL_checkstring (L, 2);
	attrs_data attrs;
	ldap_int_t rc, msgid;
	int param = 3;
	A_init (&attrs);
	while (lua_istable (L, param)) {
		int op;
		/* get operation ('+','-','=' operations allowed) */
		lua_rawgeti (L, param, 1);
		op = op2code (lua_tostring (L, -1));
		if (op == LUALDAP_NO_OP)
			return luaL_error (L, LUALDAP_PREFIX"forgotten operation on argument #%d", param);
		/* get array of attributes and values */
		A_tab2mod (L, &attrs, param, op);
		param++;
	}
	A_lastattr (L, &attrs);
	rc = ldap_modify_ext (conn->ld, dn, attrs.attrs, NULL, NULL, &msgid);
	return create_future (L, rc, 1, msgid, LDAP_RES_MODIFY);
}