/* * twnauth.c * * TWN authentication * * (c) 2002-2005 Thomas White * Part of TuxMessenger - GTK+-based MSN Messenger client * * This package is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 2 dated June, 1991. * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this package; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * */ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include "debug.h" #include "options.h" #include "routines.h" /* Nothing insecure happens if the server data won't fit in this - anything beyond this limit simply gets ignored. */ #define TWNAUTH_WGETSIZE 4096 //#define TWNAUTH_DEBUG 1 /* Internally called to get the login URL from Nexus */ char *twnauth_loginurl() { char *shellcommand; int read_more; FILE *wget_stream; char *nexus = NULL; char *wget_buffer; int wget_offset = 0; size_t i; shellcommand = malloc(1024); strncpy(shellcommand, options_wget(), 256); shellcommand[255] = '\0'; strcat(shellcommand, " -S -O - https://nexus.passport.com/rdr/pprdr.asp 2>&1"); debug_print("twnauth: nexus: %s\n", shellcommand); wget_stream = popen(shellcommand, "r"); if ( wget_stream == NULL ) { debug_print("twnauth: Nexus failed.\n"); return strdup(""); } wget_buffer = malloc(TWNAUTH_WGETSIZE); read_more = 1; while ( read_more ) { ssize_t readval; readval = fread(wget_buffer + wget_offset, 1, TWNAUTH_WGETSIZE-wget_offset, wget_stream); if ( (readval != 0) && (readval != -1) && (wget_offset < TWNAUTH_WGETSIZE) ) { wget_offset += readval; } else { read_more = 0; wget_buffer[wget_offset] = '\0'; } } pclose(wget_stream); #ifdef TWNAUTH_DEBUG debug_print("'%s'\n", wget_buffer); #endif /* Now try and find the new nexus in the wget output */ for ( i=0; i&1"); shellcommand[1023] = '\0'; #ifdef TWNAUTH_DEBUG debug_print("twnauth: %s\n", shellcommand); #else debug_print("twnauth: (sending authentication data)\n"); #endif wget_stream = popen(shellcommand, "r"); if ( wget_stream == NULL ) { return NULL; } wget_buffer = malloc(TWNAUTH_WGETSIZE); read_more = 1; while ( read_more ) { ssize_t readval; readval = fread(wget_buffer + wget_offset, 1, TWNAUTH_WGETSIZE-wget_offset, wget_stream); if ( (readval != 0) && (readval != -1) && (wget_offset < TWNAUTH_WGETSIZE) ) { wget_offset += readval; } else { read_more = 0; wget_buffer[wget_offset] = '\0'; } } pclose(wget_stream); #ifdef TWNAUTH_DEBUG debug_print("'%s'\n", wget_buffer); #endif /* Now try and find the ticket in the wget output */ for ( i=0; i