Netservices modded to read fragmented HTTP respsonse/payload from special purpose server - 180 bytes only

Committer:
RodColeman
Date:
Thu Sep 08 10:41:36 2011 +0000
Revision:
0:8f5825f330b0
setDataLen hacked to 180bytes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RodColeman 0:8f5825f330b0 1 /* Copyright (C) 2007 MySQL AB & Michael Widenius
RodColeman 0:8f5825f330b0 2
RodColeman 0:8f5825f330b0 3 This program is free software; you can redistribute it and/or modify
RodColeman 0:8f5825f330b0 4 it under the terms of the GNU General Public License as published by
RodColeman 0:8f5825f330b0 5 the Free Software Foundation; version 2 of the License.
RodColeman 0:8f5825f330b0 6
RodColeman 0:8f5825f330b0 7 This program is distributed in the hope that it will be useful,
RodColeman 0:8f5825f330b0 8 but WITHOUT ANY WARRANTY; without even the implied warranty of
RodColeman 0:8f5825f330b0 9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
RodColeman 0:8f5825f330b0 10 GNU General Public License for more details.
RodColeman 0:8f5825f330b0 11
RodColeman 0:8f5825f330b0 12 You should have received a copy of the GNU General Public License
RodColeman 0:8f5825f330b0 13 along with this program; if not, write to the Free Software
RodColeman 0:8f5825f330b0 14 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
RodColeman 0:8f5825f330b0 15
RodColeman 0:8f5825f330b0 16 #define SCRAMBLE_LENGTH_323 8
RodColeman 0:8f5825f330b0 17
RodColeman 0:8f5825f330b0 18 #include <string.h>
RodColeman 0:8f5825f330b0 19 #include <math.h>
RodColeman 0:8f5825f330b0 20
RodColeman 0:8f5825f330b0 21 typedef unsigned int uint;
RodColeman 0:8f5825f330b0 22 typedef unsigned long ulong;
RodColeman 0:8f5825f330b0 23 typedef unsigned char uchar;
RodColeman 0:8f5825f330b0 24
RodColeman 0:8f5825f330b0 25 struct my_rnd_struct {
RodColeman 0:8f5825f330b0 26 unsigned long seed1,seed2,max_value;
RodColeman 0:8f5825f330b0 27 double max_value_dbl;
RodColeman 0:8f5825f330b0 28 };
RodColeman 0:8f5825f330b0 29
RodColeman 0:8f5825f330b0 30 static void my_rnd_init(struct my_rnd_struct *rand_st, ulong seed1, ulong seed2);
RodColeman 0:8f5825f330b0 31 static double my_rnd(struct my_rnd_struct *rand_st);
RodColeman 0:8f5825f330b0 32 static void hash_password(ulong *result, const char *password, uint password_len);
RodColeman 0:8f5825f330b0 33
RodColeman 0:8f5825f330b0 34 /*
RodColeman 0:8f5825f330b0 35 Initialize random generator
RodColeman 0:8f5825f330b0 36
RodColeman 0:8f5825f330b0 37 NOTES
RodColeman 0:8f5825f330b0 38 MySQL's password checks depends on this, so don't do any changes
RodColeman 0:8f5825f330b0 39 that changes the random numbers that are generated!
RodColeman 0:8f5825f330b0 40 */
RodColeman 0:8f5825f330b0 41
RodColeman 0:8f5825f330b0 42 static void my_rnd_init(struct my_rnd_struct *rand_st, ulong seed1, ulong seed2)
RodColeman 0:8f5825f330b0 43 {
RodColeman 0:8f5825f330b0 44 rand_st->max_value= 0x3FFFFFFFL;
RodColeman 0:8f5825f330b0 45 rand_st->max_value_dbl=(double) rand_st->max_value;
RodColeman 0:8f5825f330b0 46 rand_st->seed1=seed1%rand_st->max_value ;
RodColeman 0:8f5825f330b0 47 rand_st->seed2=seed2%rand_st->max_value;
RodColeman 0:8f5825f330b0 48 }
RodColeman 0:8f5825f330b0 49
RodColeman 0:8f5825f330b0 50 /*
RodColeman 0:8f5825f330b0 51 Generate random number.
RodColeman 0:8f5825f330b0 52
RodColeman 0:8f5825f330b0 53 SYNOPSIS
RodColeman 0:8f5825f330b0 54 my_rnd()
RodColeman 0:8f5825f330b0 55 rand_st INOUT Structure used for number generation
RodColeman 0:8f5825f330b0 56
RodColeman 0:8f5825f330b0 57 RETURN VALUE
RodColeman 0:8f5825f330b0 58 generated pseudo random number
RodColeman 0:8f5825f330b0 59 */
RodColeman 0:8f5825f330b0 60
RodColeman 0:8f5825f330b0 61 static double my_rnd(struct my_rnd_struct *rand_st)
RodColeman 0:8f5825f330b0 62 {
RodColeman 0:8f5825f330b0 63 rand_st->seed1=(rand_st->seed1*3+rand_st->seed2) % rand_st->max_value;
RodColeman 0:8f5825f330b0 64 rand_st->seed2=(rand_st->seed1+rand_st->seed2+33) % rand_st->max_value;
RodColeman 0:8f5825f330b0 65 return (((double) rand_st->seed1)/rand_st->max_value_dbl);
RodColeman 0:8f5825f330b0 66 }
RodColeman 0:8f5825f330b0 67
RodColeman 0:8f5825f330b0 68 /*
RodColeman 0:8f5825f330b0 69 Generate binary hash from raw text string
RodColeman 0:8f5825f330b0 70 Used for Pre-4.1 password handling
RodColeman 0:8f5825f330b0 71 SYNOPSIS
RodColeman 0:8f5825f330b0 72 hash_password()
RodColeman 0:8f5825f330b0 73 result OUT store hash in this location
RodColeman 0:8f5825f330b0 74 password IN plain text password to build hash
RodColeman 0:8f5825f330b0 75 password_len IN password length (password may be not null-terminated)
RodColeman 0:8f5825f330b0 76 */
RodColeman 0:8f5825f330b0 77
RodColeman 0:8f5825f330b0 78 static void hash_password(ulong *result, const char *password, uint password_len)
RodColeman 0:8f5825f330b0 79 {
RodColeman 0:8f5825f330b0 80 register ulong nr=1345345333L, add=7, nr2=0x12345671L;
RodColeman 0:8f5825f330b0 81 ulong tmp;
RodColeman 0:8f5825f330b0 82 const char *password_end= password + password_len;
RodColeman 0:8f5825f330b0 83 for (; password < password_end; password++)
RodColeman 0:8f5825f330b0 84 {
RodColeman 0:8f5825f330b0 85 if (*password == ' ' || *password == '\t')
RodColeman 0:8f5825f330b0 86 continue; /* skip space in password */
RodColeman 0:8f5825f330b0 87 tmp= (ulong) (uchar) *password;
RodColeman 0:8f5825f330b0 88 nr^= (((nr & 63)+add)*tmp)+ (nr << 8);
RodColeman 0:8f5825f330b0 89 nr2+=(nr2 << 8) ^ nr;
RodColeman 0:8f5825f330b0 90 add+=tmp;
RodColeman 0:8f5825f330b0 91 }
RodColeman 0:8f5825f330b0 92 result[0]=nr & (((ulong) 1L << 31) -1L); /* Don't use sign bit (str2int) */;
RodColeman 0:8f5825f330b0 93 result[1]=nr2 & (((ulong) 1L << 31) -1L);
RodColeman 0:8f5825f330b0 94 }
RodColeman 0:8f5825f330b0 95
RodColeman 0:8f5825f330b0 96
RodColeman 0:8f5825f330b0 97
RodColeman 0:8f5825f330b0 98 /*
RodColeman 0:8f5825f330b0 99 Scramble string with password.
RodColeman 0:8f5825f330b0 100 Used in pre 4.1 authentication phase.
RodColeman 0:8f5825f330b0 101 SYNOPSIS
RodColeman 0:8f5825f330b0 102 scramble_323()
RodColeman 0:8f5825f330b0 103 to OUT Store scrambled message here. Buffer must be at least
RodColeman 0:8f5825f330b0 104 SCRAMBLE_LENGTH_323+1 bytes long
RodColeman 0:8f5825f330b0 105 message IN Message to scramble. Message must be at least
RodColeman 0:8f5825f330b0 106 SRAMBLE_LENGTH_323 bytes long.
RodColeman 0:8f5825f330b0 107 password IN Password to use while scrambling
RodColeman 0:8f5825f330b0 108 */
RodColeman 0:8f5825f330b0 109
RodColeman 0:8f5825f330b0 110 void scramble_323(char *to, const char *message, const char *password)
RodColeman 0:8f5825f330b0 111 {
RodColeman 0:8f5825f330b0 112 struct my_rnd_struct rand_st;
RodColeman 0:8f5825f330b0 113 ulong hash_pass[2], hash_message[2];
RodColeman 0:8f5825f330b0 114
RodColeman 0:8f5825f330b0 115 if (password && password[0])
RodColeman 0:8f5825f330b0 116 {
RodColeman 0:8f5825f330b0 117 char extra, *to_start=to;
RodColeman 0:8f5825f330b0 118 const char *message_end= message + SCRAMBLE_LENGTH_323;
RodColeman 0:8f5825f330b0 119 hash_password(hash_pass,password, (uint) strlen(password));
RodColeman 0:8f5825f330b0 120 hash_password(hash_message, message, SCRAMBLE_LENGTH_323);
RodColeman 0:8f5825f330b0 121 my_rnd_init(&rand_st,hash_pass[0] ^ hash_message[0],
RodColeman 0:8f5825f330b0 122 hash_pass[1] ^ hash_message[1]);
RodColeman 0:8f5825f330b0 123 for (; message < message_end; message++)
RodColeman 0:8f5825f330b0 124 *to++= (char) (floor(my_rnd(&rand_st)*31)+64);
RodColeman 0:8f5825f330b0 125 extra=(char) (floor(my_rnd(&rand_st)*31));
RodColeman 0:8f5825f330b0 126 while (to_start != to)
RodColeman 0:8f5825f330b0 127 *(to_start++)^=extra;
RodColeman 0:8f5825f330b0 128 }
RodColeman 0:8f5825f330b0 129 *to= 0;
RodColeman 0:8f5825f330b0 130 }
RodColeman 0:8f5825f330b0 131