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); }
/* ** 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); }