]> code.citadel.org Git - citadel.git/commitdiff
This implementation of non-SASL Jabber authentication
authorArt Cancro <ajc@citadel.org>
Thu, 6 Dec 2007 22:44:59 +0000 (22:44 +0000)
committerArt Cancro <ajc@citadel.org>
Thu, 6 Dec 2007 22:44:59 +0000 (22:44 +0000)
seems to work.

citadel/modules/jabber/serv_xmpp.c
citadel/modules/jabber/serv_xmpp.h
citadel/modules/jabber/xmpp_sasl_service.c

index 00c08bd893facb95666de2247975a6e892f83f08..c7e3fb92c8c5d261a29e1b800802864910b02250 100644 (file)
@@ -89,8 +89,8 @@ void xmpp_stream_start(void *data, const char *supplied_el, const char **attr)
                /* If we're not logged in yet, offer SASL as our feature set */
                xmpp_output_auth_mechs();
 
-               /* Also offer non-SASL authentication 
-               cprintf("<auth xmlns=\"http://jabber.org/features/iq-auth\"/>"); */
+               /* Also offer non-SASL authentication */
+               cprintf("<auth xmlns=\"http://jabber.org/features/iq-auth\"/>");
        }
 
        /* Offer binding and sessions as part of our feature set */
@@ -193,6 +193,23 @@ void xmpp_xml_end(void *data, const char *supplied_el) {
                if (XMPP->chardata_len > 0) {
                        safestrncpy(XMPP->iq_client_resource, XMPP->chardata,
                                sizeof XMPP->iq_client_resource);
+                       striplt(XMPP->iq_client_resource);
+               }
+       }
+
+       if (!strcasecmp(el, "username")) {              /* NON SASL ONLY */
+               if (XMPP->chardata_len > 0) {
+                       safestrncpy(XMPP->iq_client_username, XMPP->chardata,
+                               sizeof XMPP->iq_client_username);
+                       striplt(XMPP->iq_client_username);
+               }
+       }
+
+       if (!strcasecmp(el, "password")) {              /* NON SASL ONLY */
+               if (XMPP->chardata_len > 0) {
+                       safestrncpy(XMPP->iq_client_password, XMPP->chardata,
+                               sizeof XMPP->iq_client_password);
+                       striplt(XMPP->iq_client_password);
                }
        }
 
@@ -220,6 +237,22 @@ void xmpp_xml_end(void *data, const char *supplied_el) {
                        }
                }
 
+               /*
+                * Non SASL authentication
+                */
+               else if (
+                       (!strcasecmp(XMPP->iq_type, "set"))
+                       && (!strcasecmp(XMPP->iq_query_xmlns, "jabber:iq:auth:query"))
+                       ) {
+
+                       jabber_non_sasl_authenticate(
+                               XMPP->iq_id,
+                               XMPP->iq_client_username,
+                               XMPP->iq_client_password,
+                               XMPP->iq_client_resource
+                       );
+               }       
+
                /*
                 * If this <iq> stanza was a "bind" attempt, process it ...
                 */
index f00bd743d859018a8dde16d80b499a7ebfa6cc06..2b62606c28407ff38a50c108c7c8127b26403892 100644 (file)
@@ -16,6 +16,8 @@ struct citxmpp {                      /* Information about the current session */
        char iq_id[256];
        char iq_from[256];
        char iq_to[256];
+       char iq_client_username[256];   /* username requested by the client (NON SASL ONLY) */
+       char iq_client_password[256];   /* password requested by the client (NON SASL ONLY) */
        char iq_client_resource[256];   /* resource name requested by the client */
        int iq_session;                 /* nonzero == client is requesting a session */
        char iq_query_xmlns[256];       /* Namespace of <query> */
@@ -62,3 +64,4 @@ void xmpp_process_events(void);
 void xmpp_presence_notify(char *, char *);
 void jabber_roster_item(struct CitContext *);
 void jabber_send_message(char *, char *);
+void jabber_non_sasl_authenticate(char *, char *, char *, char *);
index d3c9742a561134ec414671f9946b9ce3267d7ac5..2f2dc419a33cd292c8cf7781b4fe7d39cf331328 100644 (file)
@@ -118,4 +118,34 @@ void xmpp_sasl_auth(char *sasl_auth_mech, char *authstring) {
        }
 }
 
+
+
+/*
+ * Non-SASL authentication
+ */
+void jabber_non_sasl_authenticate(char *iq_id, char *username, char *password, char *resource) {
+       int result;
+
+        if (CC->logged_in) logout(CC);  /* Client may try to log in twice.  Handle this. */
+
+       result = CtdlLoginExistingUser(NULL, username);
+       if (result == login_ok) {
+               result = CtdlTryPassword(password);
+               if (result == pass_ok) {
+                       cprintf("<iq type=\"result\" id=\"%s\"></iq>", iq_id);  /* success */
+                       return;
+               }
+       }
+
+       /* failure */
+       cprintf("<iq type=\"error\" id=\"%s\">", iq_id);
+       cprintf("<error code=\"401\" type=\"auth\">"
+               "<not-authorized xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"/>"
+               "</error>"
+               "</iq>"
+       );
+}
+
+
+
 #endif /* HAVE_EXPAT */