Changeset 6738a67 for protocols/msn
- Timestamp:
- 2008-07-16T23:22:52Z (16 years ago)
- Branches:
- master
- Children:
- 9b55485
- Parents:
- 9730d72 (diff), 6a78c0e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- protocols/msn
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/msn/msn.h
r9730d72 r6738a67 29 29 #define GROUPCHAT_SWITCHBOARD_MESSAGE "\r\r\rME WANT TALK TO MANY PEOPLE\r\r\r" 30 30 31 #ifdef DEBUG 31 #ifdef DEBUG_MSN 32 32 #define debug( text... ) imcb_log( ic, text ); 33 33 #else -
protocols/msn/msn_util.c
r9730d72 r6738a67 90 90 }; 91 91 92 static void msn_buddy_ask_yes( gpointer w, struct msn_buddy_ask_data *bla ) 93 { 92 static void msn_buddy_ask_yes( void *data ) 93 { 94 struct msn_buddy_ask_data *bla = data; 95 94 96 msn_buddy_list_add( bla->ic, "AL", bla->handle, bla->realname ); 95 97 … … 102 104 } 103 105 104 static void msn_buddy_ask_no( gpointer w, struct msn_buddy_ask_data *bla ) 105 { 106 static void msn_buddy_ask_no( void *data ) 107 { 108 struct msn_buddy_ask_data *bla = data; 109 106 110 msn_buddy_list_add( bla->ic, "BL", bla->handle, bla->realname ); 107 111 -
protocols/msn/ns.c
r9730d72 r6738a67 34 34 static int msn_ns_message( gpointer data, char *msg, int msglen, char **cmd, int num_parts ); 35 35 36 static void msn_auth_got_passport_ id( struct passport_reply *rep);36 static void msn_auth_got_passport_token( struct msn_auth_data *mad ); 37 37 38 38 gboolean msn_ns_connected( gpointer data, gint source, b_input_condition cond ) … … 178 178 179 179 debug( "Connecting to a new switchboard with key %s", cmd[5] ); 180 sb = msn_sb_create( ic, server, port, cmd[5], MSN_SB_NEW ); 180 181 if( ( sb = msn_sb_create( ic, server, port, cmd[5], MSN_SB_NEW ) ) == NULL ) 182 { 183 /* Although this isn't strictly fatal for the NS connection, it's 184 definitely something serious (we ran out of file descriptors?). */ 185 imcb_error( ic, "Could not create new switchboard" ); 186 imc_logout( ic, TRUE ); 187 return( 0 ); 188 } 181 189 182 190 if( md->msgq ) … … 214 222 { 215 223 /* Time for some Passport black magic... */ 216 if( !passport_get_ id( msn_auth_got_passport_id, ic, ic->acc->user, ic->acc->pass, cmd[4] ) )224 if( !passport_get_token( msn_auth_got_passport_token, ic, ic->acc->user, ic->acc->pass, cmd[4] ) ) 217 225 { 218 226 imcb_error( ic, "Error while contacting Passport server" ); … … 270 278 if( num_parts == 5 ) 271 279 { 280 int i, groupcount; 281 282 groupcount = atoi( cmd[4] ); 283 if( groupcount > 0 ) 284 { 285 /* valgrind says this is leaking memory, I'm guessing 286 that this happens during server redirects. */ 287 if( md->grouplist ) 288 { 289 for( i = 0; i < md->groupcount; i ++ ) 290 g_free( md->grouplist[i] ); 291 g_free( md->grouplist ); 292 } 293 294 md->groupcount = groupcount; 295 md->grouplist = g_new0( char *, md->groupcount ); 296 } 297 272 298 md->buddycount = atoi( cmd[3] ); 273 md->groupcount = atoi( cmd[4] );274 if( md->groupcount > 0 )275 md->grouplist = g_new0( char *, md->groupcount );276 277 299 if( !*cmd[3] || md->buddycount == 0 ) 278 300 msn_logged_in( ic ); … … 468 490 debug( "Got a call from %s (session %d). Key = %s", cmd[5], session, cmd[4] ); 469 491 470 sb = msn_sb_create( ic, server, port, cmd[4], session ); 471 sb->who = g_strdup( cmd[5] ); 492 if( ( sb = msn_sb_create( ic, server, port, cmd[4], session ) ) == NULL ) 493 { 494 /* Although this isn't strictly fatal for the NS connection, it's 495 definitely something serious (we ran out of file descriptors?). */ 496 imcb_error( ic, "Could not create new switchboard" ); 497 imc_logout( ic, TRUE ); 498 return( 0 ); 499 } 500 else 501 { 502 sb->who = g_strdup( cmd[5] ); 503 } 472 504 } 473 505 else if( strcmp( cmd[0], "ADD" ) == 0 ) … … 647 679 imcb_log( ic, "INBOX contains %s new messages, plus %s messages in other folders.", inbox, folders ); 648 680 } 681 682 g_free( inbox ); 683 g_free( folders ); 649 684 } 650 685 else if( g_strncasecmp( ct, "text/x-msmsgsemailnotification", 30 ) == 0 ) … … 674 709 } 675 710 676 static void msn_auth_got_passport_ id( struct passport_reply *rep)711 static void msn_auth_got_passport_token( struct msn_auth_data *mad ) 677 712 { 678 struct im_connection *ic = rep->data; 679 struct msn_data *md = ic->proto_data; 680 char *key = rep->result; 681 char buf[1024]; 682 683 if( key == NULL ) 684 { 685 imcb_error( ic, "Error during Passport authentication (%s)", 686 rep->error_string ? rep->error_string : "Unknown error" ); 713 struct im_connection *ic = mad->data; 714 struct msn_data *md; 715 716 /* Dead connection? */ 717 if( g_slist_find( msn_connections, ic ) == NULL ) 718 return; 719 720 md = ic->proto_data; 721 if( mad->token ) 722 { 723 char buf[1024]; 724 725 g_snprintf( buf, sizeof( buf ), "USR %d TWN S %s\r\n", ++md->trId, mad->token ); 726 msn_write( ic, buf, strlen( buf ) ); 727 } 728 else 729 { 730 imcb_error( ic, "Error during Passport authentication: %s", mad->error ); 687 731 imc_logout( ic, TRUE ); 688 732 } 689 else690 {691 g_snprintf( buf, sizeof( buf ), "USR %d TWN S %s\r\n", ++md->trId, key );692 msn_write( ic, buf, strlen( buf ) );693 }694 733 } -
protocols/msn/passport.c
r9730d72 r6738a67 1 /* passport.c1 /** passport.c 2 2 * 3 * Functions to login to microsoft passport service for Messenger 4 * Copyright (C) 2004 Wouter Paesen <wouter@blue-gate.be> 5 * Copyright (C) 2004 Wilmer van der Gaast <wilmer@gaast.net> 3 * Functions to login to Microsoft Passport service for Messenger 4 * Copyright (C) 2004-2008 Wilmer van der Gaast <wilmer@gaast.net> 6 5 * 7 6 * This program is free software; you can redistribute it and/or modify … … 24 23 #include "msn.h" 25 24 #include "bitlbee.h" 25 #include "url.h" 26 #include "misc.h" 27 #include "xmltree.h" 26 28 #include <ctype.h> 27 29 #include <errno.h> 28 30 29 #define MSN_BUF_LEN 8192 31 static int passport_get_token_real( struct msn_auth_data *mad ); 32 static void passport_get_token_ready( struct http_request *req ); 30 33 31 static char *prd_cached = NULL; 32 33 static int passport_get_id_real( gpointer func, gpointer data, char *header ); 34 static void passport_get_id_ready( struct http_request *req ); 35 36 static int passport_retrieve_dalogin( gpointer data, gpointer func, char *header ); 37 static void passport_retrieve_dalogin_ready( struct http_request *req ); 38 39 static char *passport_create_header( char *cookie, char *email, char *pwd ); 40 static void destroy_reply( struct passport_reply *rep ); 41 42 int passport_get_id( gpointer func, gpointer data, char *username, char *password, char *cookie ) 34 int passport_get_token( gpointer func, gpointer data, char *username, char *password, char *cookie ) 43 35 { 44 char *header = passport_create_header( cookie, username, password ); 36 struct msn_auth_data *mad = g_new0( struct msn_auth_data, 1 ); 37 int i; 45 38 46 if( prd_cached == NULL ) 47 return passport_retrieve_dalogin( func, data, header ); 48 else 49 return passport_get_id_real( func, data, header ); 39 mad->username = g_strdup( username ); 40 mad->password = g_strdup( password ); 41 mad->cookie = g_strdup( cookie ); 42 43 mad->callback = func; 44 mad->data = data; 45 46 mad->url = g_strdup( SOAP_AUTHENTICATION_URL ); 47 mad->ttl = 3; /* Max. # of redirects. */ 48 49 /* HTTP-escape stuff and s/,/&/ */ 50 http_decode( mad->cookie ); 51 for( i = 0; mad->cookie[i]; i ++ ) 52 if( mad->cookie[i] == ',' ) 53 mad->cookie[i] = '&'; 54 55 /* Microsoft doesn't allow password longer than 16 chars and silently 56 fails authentication if you give the "full version" of your passwd. */ 57 if( strlen( mad->password ) > MAX_PASSPORT_PWLEN ) 58 mad->password[MAX_PASSPORT_PWLEN] = 0; 59 60 return passport_get_token_real( mad ); 50 61 } 51 62 52 static int passport_get_ id_real( gpointer func, gpointer data, char *header)63 static int passport_get_token_real( struct msn_auth_data *mad ) 53 64 { 54 struct passport_reply *rep; 55 char *server, *dummy, *reqs; 65 char *post_payload, *post_request; 56 66 struct http_request *req; 67 url_t url; 57 68 58 rep = g_new0( struct passport_reply, 1 ); 59 rep->data = data; 60 rep->func = func; 61 rep->header = header; 69 url_set( &url, mad->url ); 62 70 63 server = g_strdup( prd_cached ); 64 dummy = strchr( server, '/' ); 71 post_payload = g_markup_printf_escaped( SOAP_AUTHENTICATION_PAYLOAD, 72 mad->username, 73 mad->password, 74 mad->cookie ); 65 75 66 if( dummy == NULL ) 67 { 68 destroy_reply( rep ); 69 return( 0 ); 70 } 76 post_request = g_strdup_printf( SOAP_AUTHENTICATION_REQUEST, 77 url.file, url.host, 78 (int) strlen( post_payload ), 79 post_payload ); 80 81 req = http_dorequest( url.host, url.port, 1, post_request, 82 passport_get_token_ready, mad ); 71 83 72 reqs = g_strdup_printf( "GET %s HTTP/1.0\r\n%s\r\n\r\n", dummy, header ); 84 g_free( post_request ); 85 g_free( post_payload ); 73 86 74 *dummy = 0; 75 req = http_dorequest( server, 443, 1, reqs, passport_get_id_ready, rep ); 76 77 g_free( server ); 78 g_free( reqs ); 79 80 if( req == NULL ) 81 destroy_reply( rep ); 82 83 return( req != NULL ); 87 return req != NULL; 84 88 } 85 89 86 static void passport_get_id_ready( struct http_request *req ) 90 static xt_status passport_xt_extract_token( struct xt_node *node, gpointer data ); 91 static xt_status passport_xt_handle_fault( struct xt_node *node, gpointer data ); 92 93 static const struct xt_handler_entry passport_xt_handlers[] = { 94 { "wsse:BinarySecurityToken", "wst:RequestedSecurityToken", passport_xt_extract_token }, 95 { "S:Fault", "S:Envelope", passport_xt_handle_fault }, 96 { NULL, NULL, NULL } 97 }; 98 99 static void passport_get_token_ready( struct http_request *req ) 87 100 { 88 struct passport_reply *rep = req->data; 101 struct msn_auth_data *mad = req->data; 102 struct xt_parser *parser; 89 103 90 if( !g_slist_find( msn_connections, rep->data ) ) 104 g_free( mad->url ); 105 g_free( mad->error ); 106 mad->url = mad->error = NULL; 107 108 if( req->status_code == 200 ) 91 109 { 92 destroy_reply( rep ); 93 return; 94 } 95 96 if( req->finished && req->reply_headers && req->status_code == 200 ) 97 { 98 char *dummy; 99 100 if( ( dummy = strstr( req->reply_headers, "from-PP='" ) ) ) 101 { 102 char *responseend; 103 104 dummy += strlen( "from-PP='" ); 105 responseend = strchr( dummy, '\'' ); 106 if( responseend ) 107 *responseend = 0; 108 109 rep->result = g_strdup( dummy ); 110 } 111 else 112 { 113 rep->error_string = g_strdup( "Could not parse Passport server response" ); 114 } 110 parser = xt_new( passport_xt_handlers, mad ); 111 xt_feed( parser, req->reply_body, req->body_size ); 112 xt_handle( parser, NULL, -1 ); 113 xt_free( parser ); 115 114 } 116 115 else 117 116 { 118 rep->error_string = g_strdup_printf( "HTTP error: %s",119 req->status_string ? req->status_string : "Unknown error" );117 mad->error = g_strdup_printf( "HTTP error %d (%s)", req->status_code, 118 req->status_string ? req->status_string : "unknown" ); 120 119 } 121 120 122 rep->func( rep ); 123 destroy_reply( rep ); 121 if( mad->error == NULL && mad->token == NULL ) 122 mad->error = g_strdup( "Could not parse Passport server response" ); 123 124 if( mad->url && mad->token == NULL ) 125 { 126 passport_get_token_real( mad ); 127 } 128 else 129 { 130 mad->callback( mad ); 131 132 g_free( mad->url ); 133 g_free( mad->username ); 134 g_free( mad->password ); 135 g_free( mad->cookie ); 136 g_free( mad->token ); 137 g_free( mad->error ); 138 g_free( mad ); 139 } 124 140 } 125 141 126 static char *passport_create_header( char *cookie, char *email, char *pwd)142 static xt_status passport_xt_extract_token( struct xt_node *node, gpointer data ) 127 143 { 128 char *buffer; 129 char *currenttoken; 130 char *email_enc, *pwd_enc; 144 struct msn_auth_data *mad = data; 145 char *s; 131 146 132 currenttoken = strstr( cookie, "lc=" ); 133 if( currenttoken == NULL ) 134 return NULL; 147 if( ( s = xt_find_attr( node, "Id" ) ) && strcmp( s, "PPToken1" ) == 0 ) 148 mad->token = g_memdup( node->text, node->text_len + 1 ); 135 149 136 email_enc = g_new0( char, strlen( email ) * 3 + 1 ); 137 strcpy( email_enc, email ); 138 http_encode( email_enc ); 139 140 pwd_enc = g_new0( char, strlen( pwd ) * 3 + 1 ); 141 strcpy( pwd_enc, pwd ); 142 http_encode( pwd_enc ); 143 144 buffer = g_strdup_printf( "Authorization: Passport1.4 OrgVerb=GET," 145 "OrgURL=http%%3A%%2F%%2Fmessenger%%2Emsn%%2Ecom," 146 "sign-in=%s,pwd=%s,%s", email_enc, pwd_enc, 147 currenttoken ); 148 149 g_free( email_enc ); 150 g_free( pwd_enc ); 151 152 return buffer; 150 return XT_HANDLED; 153 151 } 154 152 155 static int passport_retrieve_dalogin( gpointer func, gpointer data, char *header)153 static xt_status passport_xt_handle_fault( struct xt_node *node, gpointer data ) 156 154 { 157 struct passport_reply *rep = g_new0( struct passport_reply, 1 ); 158 struct http_request *req; 155 struct msn_auth_data *mad = data; 156 struct xt_node *code = xt_find_node( node->children, "faultcode" ); 157 struct xt_node *string = xt_find_node( node->children, "faultstring" ); 158 struct xt_node *redirect = xt_find_node( node->children, "psf:redirectUrl" ); 159 159 160 rep->data = data; 161 rep->func = func; 162 rep->header = header; 160 if( redirect && redirect->text_len && mad->ttl-- > 0 ) 161 mad->url = g_memdup( redirect->text, redirect->text_len + 1 ); 163 162 164 req = http_dorequest_url( "https://nexus.passport.com/rdr/pprdr.asp", passport_retrieve_dalogin_ready, rep ); 163 if( code == NULL || code->text_len == 0 ) 164 mad->error = g_strdup( "Unknown error" ); 165 else 166 mad->error = g_strdup_printf( "%s (%s)", code->text, string && string->text_len ? 167 string->text : "no description available" ); 165 168 166 if( !req ) 167 destroy_reply( rep ); 168 169 return( req != NULL ); 169 return XT_HANDLED; 170 170 } 171 172 static void passport_retrieve_dalogin_ready( struct http_request *req )173 {174 struct passport_reply *rep = req->data;175 char *dalogin;176 char *urlend;177 178 if( !g_slist_find( msn_connections, rep->data ) )179 {180 destroy_reply( rep );181 return;182 }183 184 if( !req->finished || !req->reply_headers || req->status_code != 200 )185 {186 rep->error_string = g_strdup_printf( "HTTP error while fetching DALogin: %s",187 req->status_string ? req->status_string : "Unknown error" );188 goto failure;189 }190 191 dalogin = strstr( req->reply_headers, "DALogin=" );192 193 if( !dalogin )194 {195 rep->error_string = g_strdup( "Parse error while fetching DALogin" );196 goto failure;197 }198 199 dalogin += strlen( "DALogin=" );200 urlend = strchr( dalogin, ',' );201 if( urlend )202 *urlend = 0;203 204 /* strip the http(s):// part from the url */205 urlend = strstr( urlend, "://" );206 if( urlend )207 dalogin = urlend + strlen( "://" );208 209 if( prd_cached == NULL )210 prd_cached = g_strdup( dalogin );211 212 if( passport_get_id_real( rep->func, rep->data, rep->header ) )213 {214 rep->header = NULL;215 destroy_reply( rep );216 return;217 }218 219 failure:220 rep->func( rep );221 destroy_reply( rep );222 }223 224 static void destroy_reply( struct passport_reply *rep )225 {226 g_free( rep->result );227 g_free( rep->header );228 g_free( rep->error_string );229 g_free( rep );230 } -
protocols/msn/passport.h
r9730d72 r6738a67 1 #ifndef __PASSPORT_H__2 #define __PASSPORT_H__3 1 /* passport.h 4 2 * 5 * Functions to login to Microsoft Passport Service for Messenger 6 * Copyright (C) 2004 Wouter Paesen <wouter@blue-gate.be>, 7 * Wilmer van der Gaast <wilmer@gaast.net> 3 * Functions to login to Microsoft Passport service for Messenger 4 * Copyright (C) 2004-2008 Wilmer van der Gaast <wilmer@gaast.net> 8 5 * 9 6 * This program is free software; you can redistribute it and/or modify … … 18 15 * You should have received a copy of the GNU General Public License 19 16 * along with this program; if not, write to the Free Software 20 * 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 18 */ 19 20 /* Thanks to http://msnpiki.msnfanatic.com/index.php/MSNP13:SOAPTweener 21 for the specs! */ 22 23 #ifndef __PASSPORT_H__ 24 #define __PASSPORT_H__ 22 25 23 26 #include <stdio.h> … … 33 36 #include "nogaim.h" 34 37 35 struct passport_reply 38 #define MAX_PASSPORT_PWLEN 16 39 40 struct msn_auth_data 36 41 { 37 void (*func)( struct passport_reply * ); 38 void *data; 39 char *result; 40 char *header; 41 char *error_string; 42 char *url; 43 int ttl; 44 45 char *username; 46 char *password; 47 char *cookie; 48 49 /* The end result, the only thing we'll really be interested in 50 once finished. */ 51 char *token; 52 char *error; /* Yeah, or that... */ 53 54 void (*callback)( struct msn_auth_data *mad ); 55 gpointer data; 42 56 }; 43 57 44 int passport_get_id( gpointer func, gpointer data, char *username, char *password, char *cookie ); 58 #define SOAP_AUTHENTICATION_URL "https://loginnet.passport.com/RST.srf" 59 60 #define SOAP_AUTHENTICATION_REQUEST \ 61 "POST %s HTTP/1.0\r\n" \ 62 "Accept: text/*\r\n" \ 63 "User-Agent: BitlBee " BITLBEE_VERSION "\r\n" \ 64 "Host: %s\r\n" \ 65 "Content-Length: %d\r\n" \ 66 "Cache-Control: no-cache\r\n" \ 67 "\r\n" \ 68 "%s" 69 70 #define SOAP_AUTHENTICATION_PAYLOAD \ 71 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" \ 72 "<Envelope xmlns=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:wsse=\"http://schemas.xmlsoap.org/ws/2003/06/secext\" xmlns:saml=\"urn:oasis:names:tc:SAML:1.0:assertion\" xmlns:wsp=\"http://schemas.xmlsoap.org/ws/2002/12/policy\" xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\" xmlns:wsa=\"http://schemas.xmlsoap.org/ws/2004/03/addressing\" xmlns:wssc=\"http://schemas.xmlsoap.org/ws/2004/04/sc\" xmlns:wst=\"http://schemas.xmlsoap.org/ws/2004/04/trust\">" \ 73 "<Header>" \ 74 "<ps:AuthInfo xmlns:ps=\"http://schemas.microsoft.com/Passport/SoapServices/PPCRL\" Id=\"PPAuthInfo\">" \ 75 "<ps:HostingApp>{7108E71A-9926-4FCB-BCC9-9A9D3F32E423}</ps:HostingApp>" \ 76 "<ps:BinaryVersion>4</ps:BinaryVersion>" \ 77 "<ps:UIVersion>1</ps:UIVersion>" \ 78 "<ps:Cookies></ps:Cookies>" \ 79 "<ps:RequestParams>AQAAAAIAAABsYwQAAAAzMDg0</ps:RequestParams>" \ 80 "</ps:AuthInfo>" \ 81 "<wsse:Security>" \ 82 "<wsse:UsernameToken Id=\"user\">" \ 83 "<wsse:Username>%s</wsse:Username>" \ 84 "<wsse:Password>%s</wsse:Password>" \ 85 "</wsse:UsernameToken>" \ 86 "</wsse:Security>" \ 87 "</Header>" \ 88 "<Body>" \ 89 "<ps:RequestMultipleSecurityTokens xmlns:ps=\"http://schemas.microsoft.com/Passport/SoapServices/PPCRL\" Id=\"RSTS\">" \ 90 "<wst:RequestSecurityToken Id=\"RST0\">" \ 91 "<wst:RequestType>http://schemas.xmlsoap.org/ws/2004/04/security/trust/Issue</wst:RequestType>" \ 92 "<wsp:AppliesTo>" \ 93 "<wsa:EndpointReference>" \ 94 "<wsa:Address>http://Passport.NET/tb</wsa:Address>" \ 95 "</wsa:EndpointReference>" \ 96 "</wsp:AppliesTo>" \ 97 "</wst:RequestSecurityToken>" \ 98 "<wst:RequestSecurityToken Id=\"RST1\">" \ 99 "<wst:RequestType>http://schemas.xmlsoap.org/ws/2004/04/security/trust/Issue</wst:RequestType>" \ 100 "<wsp:AppliesTo>" \ 101 "<wsa:EndpointReference>" \ 102 "<wsa:Address>messenger.msn.com</wsa:Address>" \ 103 "</wsa:EndpointReference>" \ 104 "</wsp:AppliesTo>" \ 105 "<wsse:PolicyReference URI=\"?%s\"></wsse:PolicyReference>" \ 106 "</wst:RequestSecurityToken>" \ 107 "</ps:RequestMultipleSecurityTokens>" \ 108 "</Body>" \ 109 "</Envelope>" 110 111 int passport_get_token( gpointer func, gpointer data, char *username, char *password, char *cookie ); 45 112 46 113 #endif /* __PASSPORT_H__ */
Note: See TracChangeset
for help on using the changeset viewer.