- 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:
- lib
- Files:
-
- 1 added
- 15 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
lib/Makefile
r9730d72 r6738a67 10 10 11 11 # [SH] Program variables 12 objects = arc.o base64.o $(EVENT_HANDLER) http_client.o ini.o md5.o misc.o proxy.o sha1.o $(SSL_CLIENT) url.o 12 objects = arc.o base64.o $(EVENT_HANDLER) http_client.o ini.o md5.o misc.o proxy.o sha1.o $(SSL_CLIENT) url.o xmltree.o 13 13 14 14 CFLAGS += -Wall -
lib/arc.c
r9730d72 r6738a67 131 131 132 132 Both functions return the number of bytes in the result string. 133 134 Note that if you use the pad_to argument, you will need zero-termi- 135 nation to find back the original string length after decryption. So 136 it shouldn't be used if your string contains \0s by itself! 133 137 */ 134 138 135 int arc_encode( char *clear, int clear_len, unsigned char **crypt, char *password )139 int arc_encode( char *clear, int clear_len, unsigned char **crypt, char *password, int pad_to ) 136 140 { 137 141 struct arc_state *st; 138 142 unsigned char *key; 139 int key_len, i; 143 char *padded = NULL; 144 int key_len, i, padded_len; 140 145 141 146 key_len = strlen( password ) + ARC_IV_LEN; 142 147 if( clear_len <= 0 ) 143 148 clear_len = strlen( clear ); 149 150 /* Pad the string to the closest multiple of pad_to. This makes it 151 impossible to see the exact length of the password. */ 152 if( pad_to > 0 && ( clear_len % pad_to ) > 0 ) 153 { 154 padded_len = clear_len + pad_to - ( clear_len % pad_to ); 155 padded = g_malloc( padded_len ); 156 memcpy( padded, clear, clear_len ); 157 158 /* First a \0 and then random data, so we don't have to do 159 anything special when decrypting. */ 160 padded[clear_len] = 0; 161 random_bytes( (unsigned char*) padded + clear_len + 1, padded_len - clear_len - 1 ); 162 163 clear = padded; 164 clear_len = padded_len; 165 } 144 166 145 167 /* Prepare buffers and the key + IV */ … … 161 183 162 184 g_free( st ); 185 g_free( padded ); 163 186 164 187 return clear_len + ARC_IV_LEN; -
lib/arc.h
r9730d72 r6738a67 31 31 }; 32 32 33 struct arc_state *arc_keymaker( unsigned char *key, int kl, int cycles ); 33 #ifndef G_GNUC_MALLOC 34 #define G_GNUC_MALLOC 35 #endif 36 37 G_GNUC_MALLOC struct arc_state *arc_keymaker( unsigned char *key, int kl, int cycles ); 34 38 unsigned char arc_getbyte( struct arc_state *st ); 35 int arc_encode( char *clear, int clear_len, unsigned char **crypt, char *password );39 int arc_encode( char *clear, int clear_len, unsigned char **crypt, char *password, int pad_to ); 36 40 int arc_decode( unsigned char *crypt, int crypt_len, char **clear, char *password ); -
lib/base64.c
r9730d72 r6738a67 118 118 int i, outlen = 0; 119 119 120 for( i = 0; in[i] ; i += 4 )120 for( i = 0; in[i] && in[i+1] && in[i+2] && in[i+3]; i += 4 ) 121 121 { 122 122 int sx; -
lib/events_glib.c
r9730d72 r6738a67 51 51 } GaimIOClosure; 52 52 53 static GMainLoop *loop ;53 static GMainLoop *loop = NULL; 54 54 55 55 void b_main_init() 56 56 { 57 loop = g_main_new( FALSE ); 57 if( loop == NULL ) 58 loop = g_main_new( FALSE ); 58 59 } 59 60 -
lib/misc.c
r9730d72 r6738a67 33 33 #define BITLBEE_CORE 34 34 #include "nogaim.h" 35 #include "base64.h" 35 36 #include <stdio.h> 36 37 #include <stdlib.h> … … 59 60 strcpy(text, text2); 60 61 g_free(text2); 61 }62 63 char *normalize(const char *s)64 {65 static char buf[BUF_LEN];66 char *t, *u;67 int x = 0;68 69 g_return_val_if_fail((s != NULL), NULL);70 71 u = t = g_strdup(s);72 73 strcpy(t, s);74 g_strdown(t);75 76 while (*t && (x < BUF_LEN - 1)) {77 if (*t != ' ') {78 buf[x] = *t;79 x++;80 }81 t++;82 }83 buf[x] = '\0';84 g_free(u);85 return buf;86 62 } 87 63 … … 408 384 void random_bytes( unsigned char *buf, int count ) 409 385 { 386 #ifndef _WIN32 410 387 static int use_dev = -1; 411 388 … … 457 434 458 435 if( !use_dev ) 436 #endif 459 437 { 460 438 int i; … … 608 586 return sockerr_again(); 609 587 } 588 589 /* Returns values: -1 == Failure (base64-decoded to something unexpected) 590 0 == Okay 591 1 == Password doesn't match the hash. */ 592 int md5_verify_password( char *password, char *hash ) 593 { 594 md5_byte_t *pass_dec = NULL; 595 md5_byte_t pass_md5[16]; 596 md5_state_t md5_state; 597 int ret = -1, i; 598 599 if( base64_decode( hash, &pass_dec ) == 21 ) 600 { 601 md5_init( &md5_state ); 602 md5_append( &md5_state, (md5_byte_t*) password, strlen( password ) ); 603 md5_append( &md5_state, (md5_byte_t*) pass_dec + 16, 5 ); /* Hmmm, salt! */ 604 md5_finish( &md5_state, pass_md5 ); 605 606 for( i = 0; i < 16; i ++ ) 607 { 608 if( pass_dec[i] != pass_md5[i] ) 609 { 610 ret = 1; 611 break; 612 } 613 } 614 615 /* If we reached the end of the loop, it was a match! */ 616 if( i == 16 ) 617 ret = 0; 618 } 619 620 g_free( pass_dec ); 621 622 return ret; 623 } -
lib/misc.h
r9730d72 r6738a67 41 41 G_MODULE_EXPORT char *add_cr( char *text ); 42 42 G_MODULE_EXPORT char *strip_newlines(char *source); 43 G_MODULE_EXPORT char *normalize( const char *s );44 43 45 44 G_MODULE_EXPORT time_t get_time( int year, int month, int day, int hour, int min, int sec ); … … 67 66 G_MODULE_EXPORT gboolean ssl_sockerr_again( void *ssl ); 68 67 68 G_MODULE_EXPORT int md5_verify_password( char *password, char *hash ); 69 69 70 #endif -
lib/proxy.c
r9730d72 r6738a67 114 114 { 115 115 struct sockaddr_in *sin; 116 struct sockaddr_in me; 116 117 int fd = -1; 117 118 … … 127 128 128 129 sock_make_nonblocking(fd); 130 131 if( global.conf->iface_out ) 132 { 133 me.sin_family = AF_INET; 134 me.sin_port = 0; 135 me.sin_addr.s_addr = inet_addr( global.conf->iface_out ); 136 137 if( bind( fd, (struct sockaddr *) &me, sizeof( me ) ) != 0 ) 138 event_debug( "bind( %d, \"%s\" ) failure\n", fd, global.conf->iface_out ); 139 } 129 140 130 141 event_debug("proxy_connect_none( \"%s\", %d ) = %d\n", host, port, fd); … … 530 541 struct PHB *phb; 531 542 532 if (!host || !port || (port == -1)|| !func || strlen(host) > 128) {543 if (!host || port <= 0 || !func || strlen(host) > 128) { 533 544 return -1; 534 545 } … … 538 549 phb->data = data; 539 550 540 if ( (proxytype == PROXY_NONE) || strlen(proxyhost) > 0 || !proxyport || (proxyport == -1))551 if (proxytype == PROXY_NONE || !proxyhost[0] || proxyport <= 0) 541 552 return proxy_connect_none(host, port, phb); 542 553 else if (proxytype == PROXY_HTTP) -
lib/ssl_bogus.c
r9730d72 r6738a67 65 65 return GAIM_INPUT_READ; 66 66 } 67 68 int ssl_pending( void *conn ) 69 { 70 return 0; 71 } -
lib/ssl_client.h
r9730d72 r6738a67 63 63 G_MODULE_EXPORT int ssl_write( void *conn, const char *buf, int len ); 64 64 65 /* See ssl_openssl.c for an explanation. */ 66 G_MODULE_EXPORT int ssl_pending( void *conn ); 67 65 68 /* Abort the SSL connection and disconnect the socket. Do not use close() 66 69 directly, both the SSL library and the peer will be unhappy! */ -
lib/ssl_gnutls.c
r9730d72 r6738a67 216 216 } 217 217 218 /* See ssl_openssl.c for an explanation. */ 219 int ssl_pending( void *conn ) 220 { 221 return 0; 222 } 223 218 224 void ssl_disconnect( void *conn_ ) 219 225 { -
lib/ssl_nss.c
r9730d72 r6738a67 175 175 } 176 176 177 /* See ssl_openssl.c for an explanation. */ 178 int ssl_pending( void *conn ) 179 { 180 return 0; 181 } 182 177 183 void ssl_disconnect( void *conn_ ) 178 184 { -
lib/ssl_openssl.c
r9730d72 r6738a67 68 68 69 69 conn->fd = proxy_connect( host, port, ssl_connected, conn ); 70 if( conn->fd < 0 ) 71 { 72 g_free( conn ); 73 return NULL; 74 } 75 70 76 conn->func = func; 71 77 conn->data = data; 72 78 conn->inpa = -1; 73 74 if( conn->fd < 0 )75 {76 g_free( conn );77 return NULL;78 }79 79 80 80 return conn; … … 236 236 } 237 237 238 /* Only OpenSSL *really* needs this (and well, maybe NSS). See for more info: 239 http://www.gnu.org/software/gnutls/manual/gnutls.html#index-gnutls_005frecord_005fcheck_005fpending-209 240 http://www.openssl.org/docs/ssl/SSL_pending.html 241 242 Required because OpenSSL empties the TCP buffer completely but doesn't 243 necessarily give us all the unencrypted data. 244 245 Returns 0 if there's nothing left or if we don't have to care (GnuTLS), 246 1 if there's more data. */ 247 int ssl_pending( void *conn ) 248 { 249 return ( ((struct scd*)conn) && ((struct scd*)conn)->established ) ? 250 SSL_pending( ((struct scd*)conn)->ssl ) > 0 : 0; 251 } 252 238 253 void ssl_disconnect( void *conn_ ) 239 254 { -
lib/url.c
r9730d72 r6738a67 26 26 #include "url.h" 27 27 28 /* Convert an URL to a url_t structure 28 /* Convert an URL to a url_t structure */ 29 29 int url_set( url_t *url, char *set_url ) 30 30 { 31 char s[MAX_STRING ];31 char s[MAX_STRING+1]; 32 32 char *i; 33 33 34 /* protocol:// */ 34 memset( url, 0, sizeof( url_t ) ); 35 memset( s, 0, sizeof( s ) ); 36 37 /* protocol:// */ 35 38 if( ( i = strstr( set_url, "://" ) ) == NULL ) 36 39 { … … 49 52 url->proto = PROTO_SOCKS5; 50 53 else 51 { 52 return( 0 ); 53 } 54 return 0; 55 54 56 strncpy( s, i + 3, MAX_STRING ); 55 57 } 56 58 57 /* Split 59 /* Split */ 58 60 if( ( i = strchr( s, '/' ) ) == NULL ) 59 61 { … … 67 69 strncpy( url->host, s, MAX_STRING ); 68 70 69 /* Check for username in host field 71 /* Check for username in host field */ 70 72 if( strrchr( url->host, '@' ) != NULL ) 71 73 { … … 76 78 *url->pass = 0; 77 79 } 78 /* If not: Fill in defaults 80 /* If not: Fill in defaults */ 79 81 else 80 82 { … … 82 84 } 83 85 84 /* Password? 86 /* Password? */ 85 87 if( ( i = strchr( url->user, ':' ) ) != NULL ) 86 88 { … … 88 90 strcpy( url->pass, i + 1 ); 89 91 } 90 /* Port number? 92 /* Port number? */ 91 93 if( ( i = strchr( url->host, ':' ) ) != NULL ) 92 94 { -
lib/url.h
r9730d72 r6738a67 26 26 #include "bitlbee.h" 27 27 28 #define PROTO_HTTP 29 #define PROTO_HTTPS 30 #define PROTO_SOCKS4 31 #define PROTO_SOCKS5 32 #define PROTO_DEFAULT 28 #define PROTO_HTTP 2 29 #define PROTO_HTTPS 5 30 #define PROTO_SOCKS4 3 31 #define PROTO_SOCKS5 4 32 #define PROTO_DEFAULT PROTO_HTTP 33 33 34 34 typedef struct url … … 36 36 int proto; 37 37 int port; 38 char host[MAX_STRING ];39 char file[MAX_STRING ];40 char user[MAX_STRING ];41 char pass[MAX_STRING ];38 char host[MAX_STRING+1]; 39 char file[MAX_STRING+1]; 40 char user[MAX_STRING+1]; 41 char pass[MAX_STRING+1]; 42 42 } url_t; 43 43 -
lib/xmltree.c
r9730d72 r6738a67 111 111 }; 112 112 113 struct xt_parser *xt_new( gpointer data )113 struct xt_parser *xt_new( const struct xt_handler_entry *handlers, gpointer data ) 114 114 { 115 115 struct xt_parser *xt = g_new0( struct xt_parser, 1 ); 116 116 117 117 xt->data = data; 118 xt->handlers = handlers; 118 119 xt_reset( xt ); 119 120 -
lib/xmltree.h
r9730d72 r6738a67 71 71 struct xt_node *cur; 72 72 73 struct xt_handler_entry *handlers;73 const struct xt_handler_entry *handlers; 74 74 gpointer data; 75 75 … … 77 77 }; 78 78 79 struct xt_parser *xt_new( gpointer data );79 struct xt_parser *xt_new( const struct xt_handler_entry *handlers, gpointer data ); 80 80 void xt_reset( struct xt_parser *xt ); 81 81 int xt_feed( struct xt_parser *xt, char *text, int text_len );
Note: See TracChangeset
for help on using the changeset viewer.