From: Andrew M. <fit...@us...> - 2006-03-01 00:14:33
|
Update of /cvsroot/radmind/radmind In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24957 Modified Files: Tag: radmind-1-6-0-branch applefile.c applefile.h cksum.c lcksum.c retr.c stor.c Log Message: [Bug 1438290]: AppleSingle support on i386 hardware. Index: applefile.c =================================================================== RCS file: /cvsroot/radmind/radmind/applefile.c,v retrieving revision 1.25 retrieving revision 1.25.4.1 diff -C2 -d -r1.25 -r1.25.4.1 *** applefile.c 20 Sep 2004 21:22:28 -0000 1.25 --- applefile.c 1 Mar 2006 00:14:27 -0000 1.25.4.1 *************** *** 6,9 **** --- 6,11 ---- #include "config.h" #include "applefile.h" + #include <arpa/inet.h> + #include <stdio.h> #ifdef __APPLE__ *************** *** 52,53 **** --- 54,80 ---- extern struct as_header as_header; + + /* endian handlers for x86 Macs */ + void + as_entry_netswap( struct as_entry *e ) + { + #ifdef __BIG_ENDIAN__ + return; + #else /* __BIG_ENDIAN__ */ + e->ae_id = htonl( e->ae_id ); + e->ae_offset = htonl( e->ae_offset ); + e->ae_length = htonl( e->ae_length ); + #endif /* __BIG_ENDIAN__ */ + } + + void + as_entry_hostswap( struct as_entry *e ) + { + #ifdef __BIG_ENDIAN__ + return; + #else /* __BIG_ENDIAN__ */ + e->ae_id = ntohl( e->ae_id ); + e->ae_offset = ntohl( e->ae_offset ); + e->ae_length = ntohl( e->ae_length ); + #endif /* __BIG_ENDIAN__ */ + } Index: cksum.c =================================================================== RCS file: /cvsroot/radmind/radmind/cksum.c,v retrieving revision 1.16 retrieving revision 1.16.2.1 diff -C2 -d -r1.16 -r1.16.2.1 *** cksum.c 3 Oct 2005 17:02:21 -0000 1.16 --- cksum.c 1 Mar 2006 00:14:27 -0000 1.16.2.1 *************** *** 15,18 **** --- 15,19 ---- #include <stdlib.h> #include <stdio.h> + #include <string.h> #include <fcntl.h> #include <unistd.h> *************** *** 100,103 **** --- 101,105 ---- off_t size = 0; extern struct as_header as_header; + struct as_entry as_entries_endian[ 3 ]; unsigned int md_len; extern EVP_MD *md; *************** *** 111,116 **** size += (size_t)AS_HEADERLEN; /* checksum header entries */ ! EVP_DigestUpdate( &mdctx, (char *)&afinfo->as_ents, (unsigned int)( 3 * sizeof( struct as_entry ))); size += sizeof( 3 * sizeof( struct as_entry )); --- 113,125 ---- size += (size_t)AS_HEADERLEN; + /* endian handling, sum big-endian header entries */ + memcpy( &as_entries_endian, &afinfo->as_ents, + ( 3 * sizeof( struct as_entry ))); + as_entry_netswap( &as_entries_endian[ AS_FIE ] ); + as_entry_netswap( &as_entries_endian[ AS_RFE ] ); + as_entry_netswap( &as_entries_endian[ AS_DFE ] ); + /* checksum header entries */ ! EVP_DigestUpdate( &mdctx, (char *)&as_entries_endian, (unsigned int)( 3 * sizeof( struct as_entry ))); size += sizeof( 3 * sizeof( struct as_entry )); Index: applefile.h =================================================================== RCS file: /cvsroot/radmind/radmind/applefile.h,v retrieving revision 1.19 retrieving revision 1.19.4.1 diff -C2 -d -r1.19 -r1.19.4.1 *** applefile.h 20 Sep 2004 21:22:28 -0000 1.19 --- applefile.h 1 Mar 2006 00:14:27 -0000 1.19.4.1 *************** *** 26,36 **** #define AS_HEADERLEN 26 - #define AS_MAGIC 0x00051600 - #define AS_VERSION 0x00020000 - #define AS_NENTRIES 3 ! #define ASEID_DFORK 1 ! #define ASEID_RFORK 2 ! #define ASEID_FINFO 9 #define AS_FIE 0 /* for array of ae_entry structs */ --- 26,47 ---- #define AS_HEADERLEN 26 ! #ifdef __BIG_ENDIAN__ ! ! #define AS_MAGIC 0x00051600 ! #define AS_VERSION 0x00020000 ! #define AS_NENTRIES 0x0003 ! ! #else /* __BIG_ENDIAN__ */ ! ! #define AS_MAGIC 0x00160500 ! #define AS_VERSION 0x00000200 ! #define AS_NENTRIES 0x0300 ! ! #endif /* __BIG_ENDIAN__ */ ! ! #define ASEID_DFORK 1 ! #define ASEID_RFORK 2 ! #define ASEID_FINFO 9 #define AS_FIE 0 /* for array of ae_entry structs */ *************** *** 73,75 **** --- 84,88 ---- }; + void as_entry_netswap( struct as_entry *e ); + void as_entry_hostswap( struct as_entry *e ); off_t ckapplefile( char *applefile, int afd ); Index: stor.c =================================================================== RCS file: /cvsroot/radmind/radmind/stor.c,v retrieving revision 1.45 retrieving revision 1.45.2.1 diff -C2 -d -r1.45 -r1.45.2.1 *** stor.c 24 Jan 2006 20:44:14 -0000 1.45 --- stor.c 1 Mar 2006 00:14:27 -0000 1.45.2.1 *************** *** 261,267 **** struct timeval tv; unsigned int md_len; extern EVP_MD *md; EVP_MD_CTX mdctx; ! unsigned char md_value[ EVP_MAX_MD_SIZE ]; char cksum_b64[ EVP_MAX_MD_SIZE ]; --- 261,268 ---- struct timeval tv; unsigned int md_len; + unsigned int rsrc_len; extern EVP_MD *md; EVP_MD_CTX mdctx; ! unsigned char md_value[ EVP_MAX_MD_SIZE ]; char cksum_b64[ EVP_MAX_MD_SIZE ]; *************** *** 288,291 **** --- 289,298 ---- size = afinfo->as_size; + /* endian handling, swap header entries if necessary */ + rsrc_len = afinfo->as_ents[ AS_RFE ].ae_length; + as_entry_netswap( &afinfo->as_ents[ AS_FIE ] ); + as_entry_netswap( &afinfo->as_ents[ AS_RFE ] ); + as_entry_netswap( &afinfo->as_ents[ AS_DFE ] ); + /* open data and rsrc fork */ if (( dfd = open( path, O_RDONLY )) < 0 ) { *************** *** 293,297 **** exit( 2 ); } ! if ( afinfo->as_ents[ AS_RFE ].ae_length > 0 ) { if (( rfd = open( afinfo->rsrc_path, O_RDONLY )) < 0 ) { perror( afinfo->rsrc_path ); --- 300,304 ---- exit( 2 ); } ! if ( rsrc_len > 0 ) { if (( rfd = open( afinfo->rsrc_path, O_RDONLY )) < 0 ) { perror( afinfo->rsrc_path ); *************** *** 372,376 **** /* write rsrc fork data to server */ ! if ( afinfo->as_ents[ AS_RFE ].ae_length > 0 ) { while (( rc = read( rfd, buf, sizeof( buf ))) > 0 ) { tv = timeout; --- 379,383 ---- /* write rsrc fork data to server */ ! if ( rsrc_len > 0 ) { while (( rc = read( rfd, buf, sizeof( buf ))) > 0 ) { tv = timeout; *************** *** 527,530 **** --- 534,542 ---- if ( dodots ) { putc( '.', stdout ); fflush( stdout ); } + /* endian handling, convert to valid AppleSingle format, if necessary */ + as_entry_netswap( &afinfo.as_ents[ AS_FIE ] ); + as_entry_netswap( &afinfo.as_ents[ AS_RFE ] ); + as_entry_netswap( &afinfo.as_ents[ AS_DFE ] ); + /* write header entries to server */ tv = timeout; Index: retr.c =================================================================== RCS file: /cvsroot/radmind/radmind/retr.c,v retrieving revision 1.53.2.1 retrieving revision 1.53.2.2 diff -C2 -d -r1.53.2.1 -r1.53.2.2 *** retr.c 21 Feb 2006 21:23:03 -0000 1.53.2.1 --- retr.c 1 Mar 2006 00:14:27 -0000 1.53.2.2 *************** *** 373,376 **** --- 373,385 ---- } + /* + * endian handling: swap bytes to architecture + * native from AppleSingle big-endian. + * + * This doesn't affect the checksum, since we + * already summed the header entries above. + */ + as_entry_hostswap( &ae_ents[ AS_RFE ] ); + if ( ae_ents[ AS_RFE ].ae_length > 0 ) { /* make rsrc fork name */ *************** *** 389,393 **** }; ! for ( rsize = ae_ents[ AS_RFE ].ae_length; rsize > 0; rsize -= rc ) { tv = timeout; if (( rc = snet_read( sn, buf, ( int )MIN( sizeof( buf ), rsize ), --- 398,403 ---- }; ! for ( rsize = ae_ents[ AS_RFE ].ae_length; ! rsize > 0; rsize -= rc ) { tv = timeout; if (( rc = snet_read( sn, buf, ( int )MIN( sizeof( buf ), rsize ), Index: lcksum.c =================================================================== RCS file: /cvsroot/radmind/radmind/lcksum.c,v retrieving revision 1.70 retrieving revision 1.70.2.1 diff -C2 -d -r1.70 -r1.70.2.1 *** lcksum.c 5 Oct 2005 14:53:00 -0000 1.70 --- lcksum.c 1 Mar 2006 00:14:27 -0000 1.70.2.1 *************** *** 9,12 **** --- 9,13 ---- #include <sys/stat.h> #include <sys/param.h> + #include <arpa/inet.h> #include <errno.h> #include <fcntl.h> *************** *** 62,65 **** --- 63,67 ---- exit( 2 ); } + if ( rr != AS_HEADERLEN || memcmp( &as_header, &header, AS_HEADERLEN ) != 0 ) { *************** *** 79,82 **** --- 81,88 ---- size += rr; + as_entry_netswap( &as_ents[ AS_FIE ] ); + as_entry_netswap( &as_ents[ AS_RFE ] ); + as_entry_netswap( &as_ents[ AS_DFE ] ); + /* check entry IDs */ if ( as_ents[ AS_FIE ].ae_id != ASEID_FINFO || *************** *** 93,102 **** } if ( as_ents[ AS_RFE ].ae_offset != ! ( as_ents[ AS_FIE ].ae_offset + as_ents[ AS_FIE ].ae_length )) { fprintf( stderr, "%s: incorrect rsrc fork offset\n", applefile ); return( -1 ); } if ( as_ents[ AS_DFE ].ae_offset != ! ( as_ents[ AS_RFE ].ae_offset + as_ents[ AS_RFE ].ae_length )) { fprintf( stderr, "%s: incorrect data fork offset\n", applefile ); return( -1 ); --- 99,110 ---- } if ( as_ents[ AS_RFE ].ae_offset != ! ( as_ents[ AS_FIE ].ae_offset + ! as_ents[ AS_FIE ].ae_length )) { fprintf( stderr, "%s: incorrect rsrc fork offset\n", applefile ); return( -1 ); } if ( as_ents[ AS_DFE ].ae_offset != ! ( as_ents[ AS_RFE ].ae_offset + ! as_ents[ AS_RFE ].ae_length )) { fprintf( stderr, "%s: incorrect data fork offset\n", applefile ); return( -1 ); |