commit: r364 - branches/branch_3_17/daemon
[email protected] Tue, 14 Nov 2006 02:56:32 -0500
| Newsgroups | gmane.network.spread.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: jonathan Date: 2006-11-14 02:56:32 -0500 (Tue, 14 Nov 2006) New Revision: 364 Modified: branches/branch_3_17/daemon/Changelog branches/branch_3_17/daemon/arch.h branches/branch_3_17/daemon/sp.c Log: More carefully specify the length of the spread_name and check for it. The name is now defined in termms of the os's max host name. Default connection string is now defined in terms of DEFAULT_SPREAD_PORT Define Q() and QQ() macros to help use #define's in strings. Modified: branches/branch_3_17/daemon/Changelog =================================================================== --- branches/branch_3_17/daemon/Changelog 2006-11-14 07:42:20 UTC (rev 363) +++ branches/branch_3_17/daemon/Changelog 2006-11-14 07:56:32 UTC (rev 364) @@ -1,3 +1,17 @@ +Tue Nov 14 01:40:43 2006 Jonathan Stanton <[email protected]> + + * sp.c (SP_connect_timeout): Rename variables to make more + readable. Define length of spread_name parameter in terms + of MAXHOSTNAMELEN because it is determined by how large a + host name can be. + + Define the default spread connection port (4803) in terms + of the DEFAULT_SPREAD_PORT to remove explicit port number + from source code. + + * arch.h: Add Q() and QQ() macros in order to make strings + from #define macros. + Tue Nov 14 00:20:02 2006 Jonathan Stanton <[email protected]> * groups.c (G_compute_and_notify,G_mess_to_group): Propagate Modified: branches/branch_3_17/daemon/arch.h =================================================================== --- branches/branch_3_17/daemon/arch.h 2006-11-14 07:42:20 UTC (rev 363) +++ branches/branch_3_17/daemon/arch.h 2006-11-14 07:56:32 UTC (rev 364) @@ -193,9 +193,12 @@ #else #define get_rand rand #endif - +/* Useful CPP macros to make strings from #defines */ +#define Q(x) # x +#define QQ(x) Q(x) + #define ENDIAN_TYPE 0x80000080 #define Get_endian( type ) ( (type) & ENDIAN_TYPE ) Modified: branches/branch_3_17/daemon/sp.c =================================================================== --- branches/branch_3_17/daemon/sp.c 2006-11-14 07:42:20 UTC (rev 363) +++ branches/branch_3_17/daemon/sp.c 2006-11-14 07:56:32 UTC (rev 364) @@ -46,6 +46,7 @@ #include <netinet/in.h> #include <netinet/tcp.h> #include <sys/un.h> +#include <sys/param.h> #include <netdb.h> #include <signal.h> #include <sys/ioctl.h> @@ -81,6 +82,16 @@ void *auth_data; }; +/* length of spread_name connect field is limited to 5 digit port # + '@' + hostname */ +#define SPREAD_MAXCONNECT_NAMELEN MAXHOSTNAMELEN + 6 + +/* default spread connection method depends on whether unix sockets are available */ +#ifndef ARCH_PC_WIN95 +# define DEFAULT_SPREAD_CONNECTION QQ(DEFAULT_SPREAD_PORT) +#else +# define DEFAULT_SPREAD_CONNECTION QQ(DEFAULT_SPREAD_PORT) "@localhost" +#endif /* ARCH_PC_WIN95 */ + static int sp_null_authenticate(int, void *); static struct auth_method_info Auth_Methods[MAX_AUTH_METHODS] = { {"NULL", sp_null_authenticate, NULL} }; static int Num_Reg_Auth_Methods = 1; @@ -462,9 +473,9 @@ int32 host_address; int32 lport, i1, i2, i3, i4; char *c_ptr; - char host_name[80]; - char s_name[80]; - char dummy_s[80]; + char host_name[MAXHOSTNAMELEN]; + char s_name[SPREAD_MAXCONNECT_NAMELEN + 1]; + char dummy_s[20]; char conn[MAX_PRIVATE_NAME+5]; signed char auth_list_len; char auth_list[MAX_AUTH_NAME * MAX_AUTH_METHODS]; @@ -477,7 +488,7 @@ int ret, i; unsigned int len; int sp_v1, sp_v2, sp_v3; - char l; + char cval; int32 on; struct sockaddr_in inet_addr; @@ -508,19 +519,18 @@ * [email protected] */ - if( spread_name == 0 || (!strcmp( spread_name, "" ) ) ) -#ifndef ARCH_PC_WIN95 - strcpy( s_name, "4803" ); -#else - strcpy( s_name, "4803@localhost" ); -#endif /* ARCH_PC_WIN95 */ - - else strcpy( s_name, spread_name ); + if( spread_name == NULL || (!strcmp( spread_name, "" ) ) ) { + strcpy( s_name, DEFAULT_SPREAD_CONNECTION ); + } else { + if (strlen(spread_name) > SPREAD_MAXCONNECT_NAMELEN) + return( ILLEGAL_SPREAD ); + strcpy( s_name, spread_name ); + } c_ptr = strchr( s_name, ' '); - if( c_ptr != 0 ) return ( ILLEGAL_SPREAD ); + if( c_ptr != NULL ) return ( ILLEGAL_SPREAD ); c_ptr = strchr( s_name, '@'); - if( c_ptr == 0 ) + if( c_ptr == NULL ) { #ifndef ARCH_PC_WIN95 @@ -537,7 +547,7 @@ ret = sscanf( s_name,"%d%s", &lport, host_name ); if( ret != 2) return( ILLEGAL_SPREAD ); host_ptr = gethostbyname( host_name ); - if( host_ptr != 0 ) + if( host_ptr != NULL ) { /* option [email protected] */ memcpy( &host_address, host_ptr->h_addr, sizeof(int32) ); @@ -546,7 +556,7 @@ for(i=0; i< 3; i++) { c_ptr = strchr(host_name, '.' ); - if ( c_ptr == 0) return( ILLEGAL_SPREAD ); + if ( c_ptr == NULL) return( ILLEGAL_SPREAD ); *c_ptr = ' '; } ret = sscanf( host_name, "%d%d%d%d%s", &i1, &i2, &i3, &i4, dummy_s ); @@ -732,46 +742,46 @@ return( REJECT_AUTH ); } - l=0; - ret = recv_nointr_timeout( s, &l, 1, 0, &time_out); + cval=0; + ret = recv_nointr_timeout( s, &cval, 1, 0, &time_out); if( ret <= 0 ) { Alarm( SESSION, "SP_connect: unable to read answer %d: %s\n", ret, sock_strerror(sock_errno)); close( s ); return( CONNECTION_CLOSED ); } - if( l != ACCEPT_SESSION ) + if( cval != ACCEPT_SESSION ) { - Alarm( SESSION, "SP_connect: session rejected %d\n", l); + Alarm( SESSION, "SP_connect: session rejected %d\n", cval); close( s ); - return( l ); + return( cval ); } - ret = recv_nointr_timeout( s, &l, 1, 0, &time_out); + ret = recv_nointr_timeout( s, &cval, 1, 0, &time_out); if( ret <= 0 ) { Alarm( SESSION, "SP_connect: unable to read version %d: %s\n", ret, sock_strerror(sock_errno)); close( s ); return( CONNECTION_CLOSED ); } - sp_v1 = l; + sp_v1 = cval; - ret = recv_nointr_timeout( s, &l, 1, 0, &time_out); + ret = recv_nointr_timeout( s, &cval, 1, 0, &time_out); if( ret <= 0 ) { Alarm( SESSION, "SP_connect: unable to read subversion %d: %s\n", ret, sock_strerror(sock_errno)); close( s ); return( CONNECTION_CLOSED ); } - sp_v2 = l; + sp_v2 = cval; - ret = recv_nointr_timeout( s, &l, 1, 0, &time_out); + ret = recv_nointr_timeout( s, &cval, 1, 0, &time_out); if( ret <= 0 ) { Alarm( SESSION, "SP_connect: unable to read patch version %d: %s\n", ret, sock_strerror(sock_errno)); close( s ); return( CONNECTION_CLOSED ); } - sp_v3 = l; + sp_v3 = cval; /* checking spread version. Should be at least 3.01 */ if( sp_v1*10000 + sp_v2*100 + sp_v3 < 30100 ) @@ -789,14 +799,14 @@ return( REJECT_VERSION ); } - ret = recv_nointr_timeout( s, &l, 1, 0, &time_out); + ret = recv_nointr_timeout( s, &cval, 1, 0, &time_out); if( ret <= 0 ) { Alarm( SESSION, "SP_connect: unable to read size of group %d: %s\n", ret, sock_strerror(sock_errno)); close( s ); return( CONNECTION_CLOSED ); } - len = l; + len = cval; ret = recv_nointr_timeout( s, private_group, len, 0, &time_out); if( ret <= 0 ) {