[JDEV] bug in mod_privacy ?
Dudley Carr
dudley at cs.stanford.edu
Sat Jan 17 16:35:03 CST 2004
Robert Norris wrote:
> On Wed, Jan 07, 2004 at 01:17:49PM +0300, Alexey Nezhdanov wrote:
>
>>Testing privacy lists handling with xmpppy and jabberd2s1:
>>It seems that server return "all info at once" with lists list request
>>and ingnores a particular info request:
>
>
> mod_privacy isn't in great shape just now. I'm trying to get it fixed
> for 2.0s2.
>
> Rob.
>
Below is a patch for mod_privacy. The previously mentioned issues have been
resolved in addition to some other problems. Here's the list of problems fixed:
1. mod_privacy wasn't the producing list of privacy lists
2. No replies for individual privacy list requests
3. Renamed errors according to draft-ietf-xmpp-im-20 that were supposed to be
ITEM_NOT_FOUND but instead were BAD_REQUEST
4. Error packets were using an incorrect namespace (jabber:iq:privacy:error)
and so were being dropped by sm's mod_validate
5. Corrected copy-paste accident: Outbound packets were looking at the
recipient's privacy policy instead of the sender's privacy policy.
Regards,
Dudley
--- jabberd-2.0s1/sm/mod_privacy.c Thu Dec 11 18:47:22 2003
+++ jabberd-2.0s1-dev/sm/mod_privacy.c Sat Jan 17 14:14:58 2004
@@ -473,8 +473,8 @@
z = (zebra_t) user->module_data[mod->index];
/* find a session */
- if(*pkt->to->resource != '\0')
- sess = sess_match(user, pkt->to->resource);
+ if(*pkt->from->resource != '\0')
+ sess = sess_match(user, pkt->from->resource);
/* get the active list for the session */
if(sess != NULL)
@@ -489,7 +489,7 @@
return mod_PASS;
/* figure out the action */
- if(_privacy_action(user, zlist, pkt->from, pkt->type, 0) == 0)
+ if(_privacy_action(user, zlist, pkt->to, pkt->type, 0) == 0)
return mod_PASS;
/* deny */
@@ -568,6 +568,22 @@
}
}
+/** add a list to the return packet */
+static void _privacy_lists_result_builder(xht zhash, const char *name, void
*val, void *arg) {
+ zebra_list_t zlist = (zebra_list_t) val;
+ pkt_t pkt = (pkt_t) arg;
+ int ns, query, list, item;
+ zebra_item_t zitem;
+ char order[14];
+
+ ns = nad_find_scoped_namespace(pkt->nad, uri_PRIVACY, NULL);
+ query = nad_find_elem(pkt->nad, 1, ns, "query", 1);
+
+ list = nad_insert_elem(pkt->nad, query, ns, "list", NULL);
+ nad_set_attr(pkt->nad, list, -1, "name", zlist->name, 0);
+
+}
+
/** list management requests */
static mod_ret_t _privacy_in_sess(mod_instance_t mi, sess_t sess, pkt_t pkt) {
module_t mod = mi->mod;
@@ -617,11 +633,6 @@
if(nad_find_elem(pkt->nad, list, ns, "list", 0) >= 0) {
/* hack the error in */
pkt_error(pkt, stanza_err_BAD_REQUEST);
- ns = nad_find_scoped_namespace(pkt->nad, uri_CLIENT, NULL);
- query = nad_find_elem(pkt->nad, 1, ns, "error", 1);
- query = nad_find_elem(pkt->nad, query, ns, "bad-request", 1);
- ns = nad_add_namespace(pkt->nad, uri_PRIVACY ":error", NULL);
- nad_insert_elem(pkt->nad, query, ns, "too-many-lists", NULL);
pkt_sess(pkt, sess);
return mod_HANDLED;
@@ -885,12 +896,7 @@
log_debug(ZONE, "request to make list '%s' active, but
there's no such list");
/* hack the error in */
- pkt_error(pkt, stanza_err_BAD_REQUEST);
- ns = nad_find_scoped_namespace(pkt->nad, uri_CLIENT, NULL);
- query = nad_find_elem(pkt->nad, 1, ns, "error", 1);
- query = nad_find_elem(pkt->nad, query, ns, "bad-request", 1);
- ns = nad_add_namespace(pkt->nad, uri_PRIVACY ":error", NULL);
- nad_insert_elem(pkt->nad, query, ns, "no-such-list", NULL);
+ pkt_error(pkt, stanza_err_ITEM_NOT_FOUND);
pkt_sess(pkt, sess);
return mod_HANDLED;
@@ -920,12 +926,7 @@
log_debug(ZONE, "request to make list '%s' default, but
there's no such list");
/* hack the error in */
- pkt_error(pkt, stanza_err_BAD_REQUEST);
- ns = nad_find_scoped_namespace(pkt->nad, uri_CLIENT, NULL);
- query = nad_find_elem(pkt->nad, 1, ns, "error", 1);
- query = nad_find_elem(pkt->nad, query, ns, "bad-request", 1);
- ns = nad_add_namespace(pkt->nad, uri_PRIVACY ":error", NULL);
- nad_insert_elem(pkt->nad, query, ns, "no-such-list", NULL);
+ pkt_error(pkt, stanza_err_ITEM_NOT_FOUND);
pkt_sess(pkt, sess);
return mod_HANDLED;
@@ -968,11 +969,6 @@
if(list >= 0 && nad_find_elem(pkt->nad, list, ns, "list", 0) >= 0) {
/* hack the error in */
pkt_error(pkt, stanza_err_BAD_REQUEST);
- ns = nad_find_scoped_namespace(pkt->nad, uri_CLIENT, NULL);
- query = nad_find_elem(pkt->nad, 1, ns, "error", 1);
- query = nad_find_elem(pkt->nad, query, ns, "bad-request", 1);
- ns = nad_add_namespace(pkt->nad, uri_PRIVACY ":error", NULL);
- nad_insert_elem(pkt->nad, query, ns, "too-many-lists", NULL);
pkt_sess(pkt, sess);
return mod_HANDLED;
@@ -987,15 +983,12 @@
/* just do one */
if(list >= 0) {
- zlist = xhash_getx(z->lists, NAD_AVAL(pkt->nad, list),
NAD_AVAL_L(pkt->nad, list));
- if(zlist == NULL) {
+ name = nad_find_attr(pkt->nad, list, -1, "name", NULL);
+
+ zlist = xhash_getx(z->lists, NAD_AVAL(pkt->nad, name),
NAD_AVAL_L(pkt->nad, name));
+ if(zlist == NULL) {
/* hack the error in */
- pkt_error(pkt, stanza_err_BAD_REQUEST);
- ns = nad_find_scoped_namespace(pkt->nad, uri_CLIENT, NULL);
- query = nad_find_elem(pkt->nad, 1, ns, "error", 1);
- query = nad_find_elem(pkt->nad, query, ns, "bad-request", 1);
- ns = nad_add_namespace(pkt->nad, uri_PRIVACY ":error", NULL);
- nad_insert_elem(pkt->nad, query, ns, "no-such-list", NULL);
+ pkt_error(pkt, stanza_err_ITEM_NOT_FOUND);
pkt_sess(pkt, sess);
return mod_HANDLED;
@@ -1005,8 +998,9 @@
}
else {
+
/* walk the list hash and add the lists in */
- xhash_walk(z->lists, _privacy_result_builder, (void *) result);
+ xhash_walk(z->lists, _privacy_lists_result_builder, (void *) result);
}
/* tell them about current active and default list if they asked for
everything */
@@ -1056,3 +1050,5 @@
return 0;
}
+
+
More information about the JDev
mailing list