comparison libpurple/protocols/jabber/auth.c @ 20117:f24a2cacacd1

Use PurpleDisconnectReasons in prpl-jabber.
author Will Thompson <will.thompson@collabora.co.uk>
date Wed, 19 Sep 2007 15:03:59 +0000
parents da29f5c7dc1a
children f3cfcbbac3d8
comparison
equal deleted inserted replaced
20116:a61aa7cc757d 20117:f24a2cacacd1
47 if(purple_ssl_is_supported()) { 47 if(purple_ssl_is_supported()) {
48 jabber_send_raw(js, 48 jabber_send_raw(js,
49 "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>", -1); 49 "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>", -1);
50 return TRUE; 50 return TRUE;
51 } else if(xmlnode_get_child(starttls, "required")) { 51 } else if(xmlnode_get_child(starttls, "required")) {
52 purple_connection_error(js->gc, _("Server requires TLS/SSL for login. No TLS/SSL support found.")); 52 purple_connection_error_reason (js->gc, PURPLE_REASON_ENCRYPTION_ERROR,
53 _("Server requires TLS/SSL for login. No TLS/SSL support found."));
53 return TRUE; 54 return TRUE;
54 } 55 }
55 } 56 }
56 57
57 return FALSE; 58 return FALSE;
110 finish_plaintext_authentication(account->gc->proto_data); 111 finish_plaintext_authentication(account->gc->proto_data);
111 } 112 }
112 113
113 static void disallow_plaintext_auth(PurpleAccount *account) 114 static void disallow_plaintext_auth(PurpleAccount *account)
114 { 115 {
115 purple_connection_error(account->gc, _("Server requires plaintext authentication over an unencrypted stream")); 116 purple_connection_error_reason (account->gc, PURPLE_REASON_ENCRYPTION_ERROR,
117 _("Server requires plaintext authentication over an unencrypted stream"));
116 } 118 }
117 119
118 #ifdef HAVE_CYRUS_SASL 120 #ifdef HAVE_CYRUS_SASL
119 121
120 static void jabber_auth_start_cyrus(JabberStream *); 122 static void jabber_auth_start_cyrus(JabberStream *);
251 if (!PURPLE_CONNECTION_IS_VALID(conn)) 253 if (!PURPLE_CONNECTION_IS_VALID(conn))
252 return; 254 return;
253 255
254 js = conn->proto_data; 256 js = conn->proto_data;
255 257
256 purple_connection_error(conn, _("Password is required to sign on.")); 258 purple_connection_error_reason (conn, PURPLE_REASON_AUTHENTICATION_FAILED,
259 _("Password is required to sign on."));
257 } 260 }
258 261
259 static void jabber_auth_start_cyrus(JabberStream *js) 262 static void jabber_auth_start_cyrus(JabberStream *js)
260 { 263 {
261 const char *clientout = NULL, *mech = NULL; 264 const char *clientout = NULL, *mech = NULL;
327 /* Everything else has failed, so fail the 330 /* Everything else has failed, so fail the
328 * connection. Should probably have a better 331 * connection. Should probably have a better
329 * error here. 332 * error here.
330 */ 333 */
331 } else { 334 } else {
332 purple_connection_error(js->gc, _("Server does not use any supported authentication method")); 335 purple_connection_error_reason (js->gc,
336 PURPLE_REASON_AUTHENTICATION_IMPOSSIBLE,
337 _("Server does not use any supported authentication method"));
333 return; 338 return;
334 } 339 }
335 /* not reached */ 340 /* not reached */
336 break; 341 break;
337 342
382 } 387 }
383 } 388 }
384 jabber_send(js, auth); 389 jabber_send(js, auth);
385 xmlnode_free(auth); 390 xmlnode_free(auth);
386 } else { 391 } else {
387 purple_connection_error(js->gc, "SASL authentication failed\n"); 392 purple_connection_error_reason (js->gc,
393 PURPLE_REASON_AUTHENTICATION_IMPOSSIBLE,
394 "SASL authentication failed\n");
388 } 395 }
389 } 396 }
390 397
391 static int 398 static int
392 jabber_sasl_cb_log(void *context, int level, const char *message) 399 jabber_sasl_cb_log(void *context, int level, const char *message)
455 } 462 }
456 463
457 mechs = xmlnode_get_child(packet, "mechanisms"); 464 mechs = xmlnode_get_child(packet, "mechanisms");
458 465
459 if(!mechs) { 466 if(!mechs) {
460 purple_connection_error(js->gc, _("Invalid response from server.")); 467 purple_connection_error_reason (js->gc, PURPLE_REASON_NETWORK_ERROR,
468 _("Invalid response from server."));
461 return; 469 return;
462 } 470 }
463 471
464 #ifdef HAVE_CYRUS_SASL 472 #ifdef HAVE_CYRUS_SASL
465 js->sasl_mechs = g_string_new(""); 473 js->sasl_mechs = g_string_new("");
515 g_free(msg); 523 g_free(msg);
516 return; 524 return;
517 } 525 }
518 finish_plaintext_authentication(js); 526 finish_plaintext_authentication(js);
519 } else { 527 } else {
520 purple_connection_error(js->gc, 528 purple_connection_error_reason (js->gc, PURPLE_REASON_AUTHENTICATION_IMPOSSIBLE,
521 _("Server does not use any supported authentication method")); 529 _("Server does not use any supported authentication method"));
522 } 530 }
523 #endif 531 #endif
524 } 532 }
525 533
541 /* Clear the pasword if it isn't being saved */ 549 /* Clear the pasword if it isn't being saved */
542 if (!purple_account_get_remember_password(js->gc->account)) 550 if (!purple_account_get_remember_password(js->gc->account))
543 purple_account_set_password(js->gc->account, NULL); 551 purple_account_set_password(js->gc->account, NULL);
544 } 552 }
545 553
546 purple_connection_error(js->gc, msg); 554 purple_connection_error_reason (js->gc, PURPLE_REASON_OTHER_ERROR, msg);
547 g_free(msg); 555 g_free(msg);
548 } 556 }
549 } 557 }
550 558
551 static void auth_old_cb(JabberStream *js, xmlnode *packet, gpointer data) 559 static void auth_old_cb(JabberStream *js, xmlnode *packet, gpointer data)
554 xmlnode *query, *x; 562 xmlnode *query, *x;
555 const char *type = xmlnode_get_attrib(packet, "type"); 563 const char *type = xmlnode_get_attrib(packet, "type");
556 const char *pw = purple_connection_get_password(js->gc); 564 const char *pw = purple_connection_get_password(js->gc);
557 565
558 if(!type) { 566 if(!type) {
559 purple_connection_error(js->gc, _("Invalid response from server.")); 567 purple_connection_error_reason (js->gc, PURPLE_REASON_NETWORK_ERROR,
568 _("Invalid response from server."));
560 return; 569 return;
561 } else if(!strcmp(type, "error")) { 570 } else if(!strcmp(type, "error")) {
562 char *msg = jabber_parse_error(js, packet); 571 char *msg = jabber_parse_error(js, packet);
563 purple_connection_error(js->gc, msg); 572 purple_connection_error_reason (js->gc, PURPLE_REASON_AUTHENTICATION_FAILED,
573 msg);
564 g_free(msg); 574 g_free(msg);
565 } else if(!strcmp(type, "result")) { 575 } else if(!strcmp(type, "result")) {
566 query = xmlnode_get_child(packet, "query"); 576 query = xmlnode_get_child(packet, "query");
567 if(js->stream_id && xmlnode_get_child(query, "digest")) { 577 if(js->stream_id && xmlnode_get_child(query, "digest")) {
568 unsigned char hashval[20]; 578 unsigned char hashval[20];
602 disallow_plaintext_auth); 612 disallow_plaintext_auth);
603 return; 613 return;
604 } 614 }
605 finish_plaintext_authentication(js); 615 finish_plaintext_authentication(js);
606 } else { 616 } else {
607 purple_connection_error(js->gc, 617 purple_connection_error_reason (js->gc,
608 _("Server does not use any supported authentication method")); 618 PURPLE_REASON_AUTHENTICATION_IMPOSSIBLE,
619 _("Server does not use any supported authentication method"));
609 return; 620 return;
610 } 621 }
611 } 622 }
612 } 623 }
613 624
769 char *dec_in; 780 char *dec_in;
770 char *enc_out; 781 char *enc_out;
771 GHashTable *parts; 782 GHashTable *parts;
772 783
773 if(!enc_in) { 784 if(!enc_in) {
774 purple_connection_error(js->gc, _("Invalid response from server.")); 785 purple_connection_error_reason (js->gc, PURPLE_REASON_NETWORK_ERROR,
786 _("Invalid response from server."));
775 return; 787 return;
776 } 788 }
777 789
778 dec_in = (char *)purple_base64_decode(enc_in, NULL); 790 dec_in = (char *)purple_base64_decode(enc_in, NULL);
779 purple_debug(PURPLE_DEBUG_MISC, "jabber", "decoded challenge (%d): %s\n", 791 purple_debug(PURPLE_DEBUG_MISC, "jabber", "decoded challenge (%d): %s\n",
790 !strcmp(rspauth, js->expected_rspauth)) { 802 !strcmp(rspauth, js->expected_rspauth)) {
791 jabber_send_raw(js, 803 jabber_send_raw(js,
792 "<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl' />", 804 "<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl' />",
793 -1); 805 -1);
794 } else { 806 } else {
795 purple_connection_error(js->gc, _("Invalid challenge from server")); 807 purple_connection_error_reason (js->gc, PURPLE_REASON_NETWORK_ERROR,
808 _("Invalid challenge from server"));
796 } 809 }
797 g_free(js->expected_rspauth); 810 g_free(js->expected_rspauth);
798 } else { 811 } else {
799 /* assemble a response, and send it */ 812 /* assemble a response, and send it */
800 /* see RFC 2831 */ 813 /* see RFC 2831 */
813 realm = g_hash_table_lookup(parts, "realm"); 826 realm = g_hash_table_lookup(parts, "realm");
814 if(!realm) 827 if(!realm)
815 realm = js->user->domain; 828 realm = js->user->domain;
816 829
817 if (nonce == NULL || realm == NULL) 830 if (nonce == NULL || realm == NULL)
818 purple_connection_error(js->gc, _("Invalid challenge from server")); 831 purple_connection_error_reason (js->gc, PURPLE_REASON_NETWORK_ERROR,
832 _("Invalid challenge from server"));
819 else { 833 else {
820 GString *response = g_string_new(""); 834 GString *response = g_string_new("");
821 char *a2; 835 char *a2;
822 char *auth_resp; 836 char *auth_resp;
823 char *buf; 837 char *buf;
885 NULL, &c_out, &clen); 899 NULL, &c_out, &clen);
886 g_free(enc_in); 900 g_free(enc_in);
887 g_free(dec_in); 901 g_free(dec_in);
888 if (js->sasl_state != SASL_CONTINUE && js->sasl_state != SASL_OK) { 902 if (js->sasl_state != SASL_CONTINUE && js->sasl_state != SASL_OK) {
889 purple_debug_error("jabber", "Error is %d : %s\n",js->sasl_state,sasl_errdetail(js->sasl)); 903 purple_debug_error("jabber", "Error is %d : %s\n",js->sasl_state,sasl_errdetail(js->sasl));
890 purple_connection_error(js->gc, _("SASL error")); 904 purple_connection_error_reason (js->gc, PURPLE_REASON_NETWORK_ERROR,
905 _("SASL error"));
891 return; 906 return;
892 } else { 907 } else {
893 response = xmlnode_new("response"); 908 response = xmlnode_new("response");
894 xmlnode_set_namespace(response, "urn:ietf:params:xml:ns:xmpp-sasl"); 909 xmlnode_set_namespace(response, "urn:ietf:params:xml:ns:xmpp-sasl");
895 if (clen > 0) { 910 if (clen > 0) {
910 #ifdef HAVE_CYRUS_SASL 925 #ifdef HAVE_CYRUS_SASL
911 const void *x; 926 const void *x;
912 #endif 927 #endif
913 928
914 if(!ns || strcmp(ns, "urn:ietf:params:xml:ns:xmpp-sasl")) { 929 if(!ns || strcmp(ns, "urn:ietf:params:xml:ns:xmpp-sasl")) {
915 purple_connection_error(js->gc, _("Invalid response from server.")); 930 purple_connection_error_reason (js->gc, PURPLE_REASON_NETWORK_ERROR,
931 _("Invalid response from server."));
916 return; 932 return;
917 } 933 }
918 934
919 #ifdef HAVE_CYRUS_SASL 935 #ifdef HAVE_CYRUS_SASL
920 /* The SASL docs say that if the client hasn't returned OK yet, we 936 /* The SASL docs say that if the client hasn't returned OK yet, we
935 g_free(enc_in); 951 g_free(enc_in);
936 g_free(dec_in); 952 g_free(dec_in);
937 953
938 if (js->sasl_state != SASL_OK) { 954 if (js->sasl_state != SASL_OK) {
939 /* This should never happen! */ 955 /* This should never happen! */
940 purple_connection_error(js->gc, _("Invalid response from server.")); 956 purple_connection_error_reason (js->gc, PURPLE_REASON_NETWORK_ERROR,
957 _("Invalid response from server."));
941 } 958 }
942 } 959 }
943 /* If we've negotiated a security layer, we need to enable it */ 960 /* If we've negotiated a security layer, we need to enable it */
944 sasl_getprop(js->sasl, SASL_SSF, &x); 961 sasl_getprop(js->sasl, SASL_SSF, &x);
945 if (*(int *)x > 0) { 962 if (*(int *)x > 0) {
954 void jabber_auth_handle_failure(JabberStream *js, xmlnode *packet) 971 void jabber_auth_handle_failure(JabberStream *js, xmlnode *packet)
955 { 972 {
956 char *msg = jabber_parse_error(js, packet); 973 char *msg = jabber_parse_error(js, packet);
957 974
958 if(!msg) { 975 if(!msg) {
959 purple_connection_error(js->gc, _("Invalid response from server.")); 976 purple_connection_error_reason (js->gc, PURPLE_REASON_NETWORK_ERROR,
977 _("Invalid response from server."));
960 } else { 978 } else {
961 purple_connection_error(js->gc, msg); 979 purple_connection_error_reason (js->gc, PURPLE_REASON_AUTHENTICATION_FAILED,
980 msg);
962 g_free(msg); 981 g_free(msg);
963 } 982 }
964 } 983 }