--- etc/afpd/file.c.orig	Tue Mar 31 02:24:45 1998
+++ etc/afpd/file.c	Thu Nov 11 16:49:00 1999
@@ -20,7 +20,7 @@
 #include <utime.h>
 #include <fcntl.h>
 #include <dirent.h>
-#include <strings.h>
+#include <string.h>
 #include <stdio.h>
 #include <unistd.h>
 
@@ -28,10 +28,13 @@
 #include "desktop.h"
 #include "volume.h"
 #include "file.h"
+#include "fork.h"
 #include "globals.h"
 
 extern int	errno;
 
+int		copyfile();
+
 u_char		ufinderi[] = {
     'T', 'E', 'X', 'T', 'U', 'N', 'I', 'X',
     0, 0, 0, 0, 0, 0, 0, 0,
@@ -39,8 +42,9 @@
     0, 0, 0, 0, 0, 0, 0, 0,
 };
 
+int
 getfilparams( bitmap, path, dir, st, buf, buflen )
-    u_short	bitmap;
+    u_int16_t	bitmap;
     char	*path;
     struct dir	*dir;
     struct stat	*st;
@@ -51,8 +55,11 @@
     struct adouble	ad;
     struct extmap	*em;
     char		*data, *nameoff = 0;
-    int			bit = 0, isad = 1, aint;
-    u_short		ashort;
+    int			bit = 0, isad = 1;
+    int32_t		aint;
+    u_int16_t		ashort;
+    u_int8_t		achar;
+    u_char		fdType[4];
 
     if ( ad_open( mtoupath( path ), ADFLAGS_HF, O_RDONLY, 0, &ad ) < 0 ) {
 	isad = 0;
@@ -72,35 +79,35 @@
 	switch ( bit ) {
 	case FILPBIT_ATTR :
 	    if ( isad ) {
-		bcopy( ad_entry( &ad, ADEID_FILEI ) + FILEIOFF_ATTR, &ashort,
-			sizeof( u_short ));
+		memcpy( &ashort, ad_entry( &ad, ADEID_FILEI ) + FILEIOFF_ATTR,
+			sizeof( ashort ));
 	    } else {
 		ashort = 0;
 	    }
-	    bcopy( &ashort, data, sizeof( u_short ));
-	    data += sizeof( u_short );
+	    memcpy( data, &ashort, sizeof( ashort ));
+	    data += sizeof( ashort );
 	    break;
 
 	case FILPBIT_PDID :
-	    bcopy( &dir->d_did, data, sizeof( int ));
-	    data += sizeof( int );
+	    memcpy( data, &dir->d_did, sizeof( dir->d_did ));
+	    data += sizeof( dir->d_did );
 	    break;
 
 	case FILPBIT_CDATE :
 	    if ( isad ) {
-		bcopy( ad_entry( &ad, ADEID_FILEI ) + FILEIOFF_CREATE, &aint,
-			sizeof( int ));
+		memcpy( &aint, ad_entry( &ad, ADEID_FILEI ) + FILEIOFF_CREATE,
+			sizeof( aint ));
 	    } else {
 		aint = htonl( st->st_mtime );
 	    }
-	    bcopy( &aint, data, sizeof( int ));
-	    data += sizeof( int );
+	    memcpy( data, &aint, sizeof( aint ));
+	    data += sizeof( aint );
 	    break;
 
 	case FILPBIT_MDATE :
 	    if ( isad ) {
-		bcopy( ad_entry( &ad, ADEID_FILEI ) + FILEIOFF_MODIFY, &aint,
-			sizeof( int ));
+		memcpy( &aint, ad_entry( &ad, ADEID_FILEI ) + FILEIOFF_MODIFY,
+			sizeof( aint ));
 		aint = ntohl( aint );
 		if ( st->st_mtime > aint && hst.st_mtime < st->st_mtime ) {
 		    aint = st->st_mtime;
@@ -109,44 +116,44 @@
 		aint = st->st_mtime;
 	    }
 	    aint = htonl( aint );
-	    bcopy( &aint, data, sizeof( int ));
-	    data += sizeof( int );
+	    memcpy( data, &aint, sizeof( aint ));
+	    data += sizeof( aint );
 	    break;
 
 	case FILPBIT_BDATE :
 	    if ( isad ) {
-		bcopy( ad_entry( &ad, ADEID_FILEI ) + FILEIOFF_BACKUP, &aint,
-			sizeof( int ));
+		memcpy( &aint, ad_entry( &ad, ADEID_FILEI ) + FILEIOFF_BACKUP,
+			sizeof( aint ));
 	    } else {
 		aint = 0;
 	    }
-	    bcopy( &aint, data, sizeof( int ));
-	    data += sizeof( int );
+	    memcpy( data, &aint, sizeof( aint ));
+	    data += sizeof( aint );
 	    break;
 
 	case FILPBIT_FINFO :
 	    if ( !isad ) {
-		bcopy( ufinderi, data, 32 );
+		memcpy( data, ufinderi, 32 );
 	    } else {
-		bcopy( ad_entry( &ad, ADEID_FINDERI ), data, 32 );
+		memcpy( data, ad_entry( &ad, ADEID_FINDERI ), 32 );
 	    }
-	    if ( bcmp( data, ufinderi, 8 ) == 0 &&
+	    if ( memcmp( data, ufinderi, 8 ) == 0 &&
 		    ( em = getextmap( path )) != NULL ) {
-		bcopy( em->em_type, data, sizeof( em->em_type ));
-		bcopy( em->em_creator, data + 4, sizeof( em->em_creator ));
+		memcpy( data, em->em_type, sizeof( em->em_type ));
+		memcpy( data + 4, em->em_creator, sizeof( em->em_creator ));
 	    }
 	    data += 32;
 	    break;
 
 	case FILPBIT_LNAME :
 	    nameoff = data;
-	    data += sizeof( u_short );
+	    data += sizeof( ashort ); /* ashort will get copied here later */
 	    break;
 
 	case FILPBIT_SNAME :
 	    ashort = 0;
-	    bcopy( &ashort, data, sizeof( u_short ));
-	    data += sizeof( u_short );
+	    memcpy( data, &ashort, sizeof( ashort ));
+	    data += sizeof( ashort );
 	    break;
 
 	case FILPBIT_FNUM :
@@ -168,14 +175,14 @@
 #else AFS
 	    aint = ( st->st_dev << 16 ) | ( st->st_ino & 0x0000ffff );
 #endif AFS
-	    bcopy( &aint, data, sizeof( int ));
-	    data += sizeof( int );
+	    memcpy( data, &aint, sizeof( aint ));
+	    data += sizeof( aint );
 	    break;
 
 	case FILPBIT_DFLEN :
 	    aint = htonl( st->st_size );
-	    bcopy( &aint, data, sizeof( int ));
-	    data += sizeof( int );
+	    memcpy( data, &aint, sizeof( aint ));
+	    data += sizeof( aint );
 	    break;
 
 	case FILPBIT_RFLEN :
@@ -184,10 +191,65 @@
 	    } else {
 		aint = 0;
 	    }
-	    bcopy( &aint, data, sizeof( int ));
-	    data += sizeof( int );
+	    memcpy( data, &aint, sizeof( aint ));
+	    data += sizeof( aint );
 	    break;
 
+ 	    /* Current client needs ProDOS info block for this file.
+ 	       Use simple heuristic and let the Mac "type" string tell
+ 	       us what the PD file code should be.  Everything gets a
+ 	       subtype of 0x0000 unless the original value was hashed
+ 	       to "pXYZ" when we created it.  See IA, Ver 2.
+ 	       <shirsch@ibm.net> */
+ 	case FILPBIT_PDINFO :
+ 	    if ( isad ) {
+ 	      memcpy( fdType, ad_entry( &ad, ADEID_FINDERI ), 4 );
+ 	      
+ 	      if ( memcmp( fdType, "TEXT", 4 ) == 0 ) {
+ 		achar = '\x04';
+ 		ashort = 0x0000;
+ 	      }
+ 	      else if ( memcmp( fdType, "PSYS", 4 ) == 0 ) {
+ 		achar = '\xff';
+ 		ashort = 0x0000;
+ 	      }
+ 	      else if ( memcmp( fdType, "PS16", 4 ) == 0 ) {
+ 		achar = '\xb3';
+ 		ashort = 0x0000;
+ 	      }
+ 	      else if ( memcmp( fdType, "BINA", 4 ) == 0 ) {
+ 		achar = '\x00';
+ 		ashort = 0x0000;
+ 	      }
+ 	      else if ( fdType[0] == 'p' ) {
+ 		achar = fdType[1];
+ 		ashort = (fdType[2] * 256) + fdType[3];
+ 	      } 
+ 	      else {
+ 		achar = '\x00';
+ 		ashort = 0x0000;
+ 	      }
+ 	    } 
+ 	    else {
+ 	      achar = '\x00';
+ 	      ashort = 0x0000;
+ 	    }
+ 	    
+ 	    memcpy( data, &achar, sizeof( achar ));
+ 	    data += sizeof( achar );
+ 
+ 	    achar = 0x00;
+ 	    memcpy( data, &achar, sizeof( achar ));
+ 	    data += sizeof( achar );
+ 
+ 	    memcpy( data, &ashort, sizeof( ashort ));
+ 	    data += sizeof( ashort );
+ 
+ 	    ashort = 0x0000;
+ 	    memcpy( data, &ashort, sizeof( ashort ));
+ 	    data += sizeof( ashort );
+ 	    break;
+
 	default :
 	    if ( isad ) {
 		ad_close( &ad, ADFLAGS_HF );
@@ -199,11 +261,11 @@
     }
     if ( nameoff != 0 ) {
 	ashort = htons( data - buf );
-	bcopy( &ashort, nameoff, sizeof( u_short ));
+	memcpy( nameoff, &ashort, sizeof( ashort ));
 	aint = strlen( path );
 	aint = ( aint > 31 ) ? 31 : aint;
 	*data++ = aint;
-	bcopy( path, data, aint );
+	memcpy( data, path, aint );
 	data += aint;
     }
     if ( isad ) {
@@ -213,6 +275,7 @@
     return( AFP_OK );
 }
 
+int
 afp_createfile( ibuf, ibuflen, rbuf, rbuflen )
     char	*ibuf, *rbuf;
     int		ibuflen, *rbuflen;
@@ -222,22 +285,24 @@
     struct vol		*vol;
     struct dir		*dir;
     char		*path;
-    int			creatf, did, openf;
-    u_short		vid;
+    int			creatf, openf;
+    int32_t		did;
+    u_int16_t		vid;
+    int32_t		secs;
 
     *rbuflen = 0;
     ibuf++;
     creatf = *ibuf++;
 
-    bcopy( ibuf, &vid, sizeof( u_short ));
-    ibuf += sizeof( u_short );
+    memcpy( &vid, ibuf, sizeof( vid ));
+    ibuf += sizeof( vid );
 
     if (( vol = getvolbyvid( vid )) == NULL ) {
 	return( AFPERR_PARAM );
     }
 
-    bcopy( ibuf, &did, sizeof( int ));
-    ibuf += sizeof( int );
+    memcpy( &did, ibuf, sizeof( did ));
+    ibuf += sizeof( did );
 
     if (( dir = dirsearch( vol, did )) == NULL ) {
 	return( AFPERR_NOOBJ );
@@ -266,18 +331,19 @@
     }
 
     ad_setentrylen( &ad, ADEID_NAME, strlen( path ));
-    bcopy( path, ad_entry( &ad, ADEID_NAME ),
-	    ad_getentrylen( &ad, ADEID_NAME ));
+    memcpy( ad_entry( &ad, ADEID_NAME ),
+	    path, ad_getentrylen( &ad, ADEID_NAME ));
 
     if ( gettimeofday( &tv, 0 ) < 0 ) {
 	syslog( LOG_ERR, "afp_createfile: gettimeofday: %m" );
 	exit( 1 );
     }
-    tv.tv_sec = htonl( tv.tv_sec );
-    bcopy( &tv.tv_sec, ad_entry( &ad, ADEID_FILEI ) + FILEIOFF_CREATE,
-	    sizeof( tv.tv_sec ));
-    bcopy( &tv.tv_sec, ad_entry( &ad, ADEID_FILEI ) + FILEIOFF_MODIFY,
-	    sizeof( tv.tv_sec ));
+    secs = tv.tv_sec;
+    secs = htonl(secs);
+    memcpy( ad_entry( &ad, ADEID_FILEI ) + FILEIOFF_CREATE,
+	    &secs, sizeof( secs ));
+    memcpy( ad_entry( &ad, ADEID_FILEI ) + FILEIOFF_MODIFY,
+	    &secs, sizeof( secs ));
 
     ad_flush( &ad, ADFLAGS_DF|ADFLAGS_HF );
     ad_close( &ad, ADFLAGS_DF|ADFLAGS_HF );
@@ -285,6 +351,7 @@
     return( AFP_OK );
 }
 
+int
 afp_setfilparams( ibuf, ibuflen, rbuf, rbuflen )
     char	*ibuf, *rbuf;
     int		ibuflen, *rbuflen;
@@ -292,27 +359,28 @@
     struct vol	*vol;
     struct dir	*dir;
     char	*path;
-    int		did, rc;
-    u_short	vid, bitmap;
+    int32_t	did;
+    int		rc;
+    u_int16_t	vid, bitmap;
 
     *rbuflen = 0;
     ibuf += 2;
 
-    bcopy( ibuf, &vid, sizeof( u_short ));
-    ibuf += sizeof( u_short );
+    memcpy( &vid, ibuf, sizeof( vid ));
+    ibuf += sizeof( vid );
     if (( vol = getvolbyvid( vid )) == NULL ) {
 	return( AFPERR_PARAM );
     }
 
-    bcopy( ibuf, &did, sizeof( int ));
-    ibuf += sizeof( int );
+    memcpy( &did, ibuf, sizeof( did ));
+    ibuf += sizeof( did );
     if (( dir = dirsearch( vol, did )) == NULL ) {
 	return( AFPERR_NOOBJ );
     }
 
-    bcopy( ibuf, &bitmap, sizeof( u_short ));
+    memcpy( &bitmap, ibuf, sizeof( bitmap ));
     bitmap = ntohs( bitmap );
-    ibuf += sizeof( u_short );
+    ibuf += sizeof( bitmap );
 
     if (( path = cname( vol, dir, &ibuf )) == NULL ) {
 	return( AFPERR_NOOBJ );
@@ -329,17 +397,21 @@
     return( rc );
 }
 
+int
 setfilparams( path, bitmap, buf )
     char	*path, *buf;
-    u_short	bitmap;
+    u_int16_t	bitmap;
 {
     struct adouble	ad;
     struct extmap	*em;
     int			bit = 0;
-    u_short		ashort, bshort;
-    u_long		along;
+    u_int16_t		ashort, bshort;
+    u_int32_t		along;
     time_t		atime;
+    u_char		achar;
     struct utimbuf	ut;
+    u_char		*fdType;
+    u_char		xyy[4];
 
     if ( ad_open( mtoupath( path ), ADFLAGS_HF, O_RDWR|O_CREAT,
 	    0666, &ad ) < 0 ) {
@@ -349,8 +421,8 @@
 
     if ( ad_getoflags( &ad, ADFLAGS_HF ) & O_CREAT ) {
 	ad_setentrylen( &ad, ADEID_NAME, strlen( path ));
-	bcopy( path, ad_entry( &ad, ADEID_NAME ),
-		ad_getentrylen( &ad, ADEID_NAME ));
+	memcpy( ad_entry( &ad, ADEID_NAME ),
+		path, ad_getentrylen( &ad, ADEID_NAME ));
     }
 
     while ( bitmap != 0 ) {
@@ -361,56 +433,96 @@
 
 	switch(  bit ) {
 	case FILPBIT_ATTR :
-	    bcopy( buf, &ashort, sizeof( u_short ));
-	    bcopy( ad_entry( &ad, ADEID_FILEI ) + FILEIOFF_ATTR, &bshort,
-		    sizeof( u_short ));
+	    memcpy( &ashort, buf, sizeof( ashort ));
+	    memcpy( &bshort, ad_entry( &ad, ADEID_FILEI ) + FILEIOFF_ATTR,
+		    sizeof( bshort ));
 	    if ( ntohs( ashort ) & ATTRBIT_SETCLR ) {
 		bshort |= htons( ntohs( ashort ) & ~ATTRBIT_SETCLR );
 	    } else {
 		bshort &= ~ashort;
 	    }
-	    bcopy( &bshort, ad_entry( &ad, ADEID_FILEI ) + FILEIOFF_ATTR,
-		    sizeof( u_short ));
-	    buf += sizeof( u_short );
+	    memcpy( ad_entry( &ad, ADEID_FILEI ) + FILEIOFF_ATTR,
+		    &bshort, sizeof( bshort ));
+	    buf += sizeof( bshort );
 	    break;
 
 	case FILPBIT_CDATE :
-	    bcopy( buf, ad_entry( &ad, ADEID_FILEI ) + FILEIOFF_CREATE,
-		    sizeof( int ));
-	    buf += sizeof( int );
+	    memcpy( ad_entry( &ad, ADEID_FILEI ) + FILEIOFF_CREATE, buf, 4);
+	    buf += 4;
 	    break;
 
 	case FILPBIT_MDATE :
-	    bcopy( buf, ad_entry( &ad, ADEID_FILEI ) + FILEIOFF_MODIFY,
-		    sizeof( int ));
-	    bcopy( buf, &along, sizeof( along ));
+	    memcpy( ad_entry( &ad, ADEID_FILEI ) + FILEIOFF_MODIFY, buf, 4);
+	    memcpy( &along, buf, sizeof( along ));
+	    buf += sizeof( along );
 	    atime = ntohl( along );
 	    ut.actime = atime;
 	    ut.modtime = atime;
 	    utime( mtoupath( path ), &ut );
-	    buf += sizeof( int );
 	    break;
 
 	case FILPBIT_BDATE :
-	    bcopy( buf, ad_entry( &ad, ADEID_FILEI ) + FILEIOFF_BACKUP,
-		    sizeof( int ));
-	    buf += sizeof( int );
+	    memcpy( ad_entry( &ad, ADEID_FILEI ) + FILEIOFF_BACKUP, buf, 4);
+	    buf += 4;
 	    break;
 
 	case FILPBIT_FINFO :
 	    if (( ad_getoflags( &ad, ADFLAGS_HF ) & O_CREAT ) ||
-		    bcmp( ad_entry( &ad, ADEID_FINDERI ), ufinderi, 8 ) == 0 ) {
+		    memcmp( ad_entry( &ad, ADEID_FINDERI ), ufinderi, 8 ) == 0 ) {
 		if (( em = getextmap( path )) != NULL ) {
-		    if ( bcmp( buf, em->em_type, sizeof( em->em_type )) == 0 &&
-			    bcmp( buf + 4, em->em_creator,
+		    if ( memcmp( buf, em->em_type, sizeof( em->em_type )) == 0 &&
+			    memcmp( buf + 4, em->em_creator,
 			    sizeof( em->em_creator )) == 0 ) {
-			bcopy( ufinderi, buf, 8 );
+			memcpy( buf, ufinderi, 8 );
 		    }
 		}
 	    }
-	    bcopy( buf, ad_entry( &ad, ADEID_FINDERI ), 32 );
+	    memcpy( ad_entry( &ad, ADEID_FINDERI ), buf, 32 );
 	    buf += 32;
 	    break;
+ 
+ 	    /* Client needs to set the ProDOS file info for this file.
+ 	       Use defined strings for the simple cases, and convert
+ 	       all else into pXYY per Inside Appletalk.  Always set
+ 	       the creator as "pdos". <shirsch@ibm.net> */
+ 	case FILPBIT_PDINFO :
+ 	    memcpy( &achar, buf, sizeof( achar ));
+ 	    buf += 2 * sizeof( achar );
+ 	  
+ 	    memcpy( &ashort, buf, sizeof( ashort ));
+ 	    ashort = ntohs( ashort );
+ 	    buf += 2 * sizeof( achar );
+ 
+ 	    switch ( (unsigned int) achar )
+ 	      {
+ 	      case 0x04 :
+ 		fdType = ( u_char *) "TEXT";
+ 		break;
+ 		
+ 	      case 0xff :
+ 		fdType = ( u_char *) "PSYS";
+ 		break;
+ 
+ 	      case 0xb3 :
+ 		fdType = ( u_char *) "PS16";
+ 		break;
+ 
+ 	      case 0x00 :
+ 		fdType = ( u_char *) "BINA";
+ 		break;
+ 
+ 	      default :
+ 		xyy[0] = ( u_char ) 'p';
+ 		xyy[1] = achar;
+ 		xyy[2] = ( u_char ) ( ashort >> 8 ) & 0xff;
+ 		xyy[3] = ( u_char ) ashort & 0xff;
+ 		fdType = xyy;
+ 		break;
+ 	      }
+ 	    
+ 	    memcpy( ad_entry( &ad, ADEID_FINDERI ), fdType, 4 );
+ 	    memcpy( ad_entry( &ad, ADEID_FINDERI ) + 4, "pdos", 4 );
+	break;
 
 	default :
 	    return( AFPERR_BITMAP );
@@ -432,6 +544,7 @@
  * renamefile and copyfile take the old and new unix pathnames
  * and the new mac name.
  */
+int
 renamefile( src, dst, newname )
     char	*src, *dst, *newname;
 {
@@ -468,7 +581,7 @@
 	}
     }
 
-    strcpy( adsrc, ad_path( src, 0 ));
+    (void)strlcpy( adsrc, ad_path( src, 0 ), sizeof(adsrc));
     if ( rename( adsrc, ad_path( dst, 0 )) < 0 ) {
 	switch ( errno ) {
 	case ENOENT :
@@ -492,13 +605,14 @@
     }
     len = strlen( newname );
     ad_setentrylen( &ad, ADEID_NAME, len );
-    bcopy( newname, ad_entry( &ad, ADEID_NAME ), len );
+    memcpy( ad_entry( &ad, ADEID_NAME ), newname, len );
     ad_flush( &ad, ADFLAGS_HF );
     ad_close( &ad, ADFLAGS_HF );
 
     return( AFP_OK );
 }
 
+int
 afp_copyfile( ibuf, ibuflen, rbuf, rbuflen )
     char	*ibuf, *rbuf;
     int		ibuflen, *rbuflen;
@@ -513,22 +627,22 @@
     *rbuflen = 0;
     ibuf += 2;
 
-    bcopy( ibuf, &svid, sizeof( short ));
-    ibuf += sizeof( short );
+    memcpy( &svid, ibuf, sizeof( svid ));
+    ibuf += sizeof( svid );
     if (( vol = getvolbyvid( svid )) == NULL ) {
 	return( AFPERR_PARAM );
     }
 
-    bcopy( ibuf, &sdid, sizeof( int ));
-    ibuf += sizeof( int );
+    memcpy( &sdid, ibuf, sizeof( sdid ));
+    ibuf += sizeof( sdid );
     if (( dir = dirsearch( vol, sdid )) == NULL ) {
 	return( AFPERR_PARAM );
     }
 
-    bcopy( ibuf, &dvid, sizeof( short ));
-    ibuf += sizeof( short );
-    bcopy( ibuf, &ddid, sizeof( int ));
-    ibuf += sizeof( int );
+    memcpy( &dvid, ibuf, sizeof( dvid ));
+    ibuf += sizeof( dvid );
+    memcpy( &ddid, ibuf, sizeof( ddid ));
+    ibuf += sizeof( ddid );
 
     if (( path = cname( vol, dir, &ibuf )) == NULL ) {
 	return( AFPERR_NOOBJ );
@@ -536,7 +650,7 @@
     if ( *path == '\0' ) {
 	return( AFPERR_BADTYPE );
     }
-    strcpy( newname, path );
+    (void)strlcpy( newname, path, sizeof(newname) );
 
     p = ctoupath( vol, dir, newname );
 
@@ -570,6 +684,7 @@
     return( AFP_OK );
 }
 
+int
 copyfile( src, dst, newname )
     char	*src, *dst, *newname;
 {
@@ -655,13 +770,14 @@
     }
     len = strlen( newname );
     ad_setentrylen( &ad, ADEID_NAME, len );
-    bcopy( newname, ad_entry( &ad, ADEID_NAME ), len );
+    memcpy( ad_entry( &ad, ADEID_NAME ), newname, len );
     ad_flush( &ad, ADFLAGS_HF );
     ad_close( &ad, ADFLAGS_HF );
 
     return( AFP_OK );
 }
 
+int
 deletefile( file )
     char		*file;
 {
