--- etc/afpd/filedir.c.orig	Sun Aug 17 09:20:09 1997
+++ etc/afpd/filedir.c	Wed Nov 24 15:15:48 1999
@@ -13,7 +13,8 @@
 #include <atalk/afp.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <strings.h>
+#include <unistd.h>
+#include <string.h>
 #include <fcntl.h>
 #include <dirent.h>
 
@@ -27,41 +28,41 @@
 
 char	getwdbuf[ MAXPATHLEN ];
 
+int
 afp_getfildirparams( ibuf, ibuflen, rbuf, rbuflen )
     char	*ibuf, *rbuf;
     int		ibuflen, *rbuflen;
 {
     struct stat		st;
-    struct adouble	ad;
     struct vol		*vol;
     struct dir		*directory;
-    int			did, buflen, adret, ret;
+    int			did, buflen, ret;
     char		*path;
-    u_short		fbitmap, dbitmap, vid;
+    u_int16_t		fbitmap, dbitmap, vid;
 
     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 ) {
 	*rbuflen = 0;
 	return( AFPERR_PARAM );
     }
 
-    bcopy( ibuf, &did, sizeof( int ));
-    ibuf += sizeof( int );
+    memcpy( &did, ibuf, sizeof( did ));
+    ibuf += sizeof( did );
 
     if (( directory = dirsearch( vol, did )) == NULL ) {
 	*rbuflen = 0;
 	return( AFPERR_NOOBJ );
     }
 
-    bcopy( ibuf, &fbitmap, sizeof( u_short ));
+    memcpy( &fbitmap, ibuf, sizeof( fbitmap ));
     fbitmap = ntohs( fbitmap );
-    ibuf += sizeof( u_short );
-    bcopy( ibuf, &dbitmap, sizeof( u_short ));
+    ibuf += sizeof( fbitmap );
+    memcpy( &dbitmap, ibuf, sizeof( dbitmap ));
     dbitmap = ntohs( dbitmap );
-    ibuf += sizeof( u_short );
+    ibuf += sizeof( dbitmap );
 
     if (( path = cname( vol, directory, &ibuf )) == NULL ) {
 	*rbuflen = 0;
@@ -73,34 +74,35 @@
 	return( AFPERR_NOOBJ );
     }
 
-    buflen = *rbuflen - 3 * sizeof( u_short );
+    buflen = *rbuflen - 3 * sizeof( u_int16_t );
     if ( st.st_mode & S_IFDIR ) {
 	if (( ret = getdirparams( dbitmap, ".", curdir,
-		&st, rbuf + 3 * sizeof( u_short ), &buflen )) != AFP_OK ) {
+		&st, rbuf + 3 * sizeof( u_int16_t ), &buflen )) != AFP_OK ) {
 	    *rbuflen = 0;
 	    return( ret );
 	}
-	*(rbuf + 2 * sizeof( u_short )) = 1<<7;	/* this is a directory */
+	*(rbuf + 2 * sizeof( u_int16_t )) = 1<<7;	/* this is a directory */
     } else {
 	if (( ret = getfilparams( fbitmap, path, curdir, &st,
-		rbuf + 3 * sizeof( u_short ), &buflen )) != AFP_OK ) {
+		rbuf + 3 * sizeof( u_int16_t ), &buflen )) != AFP_OK ) {
 	    *rbuflen = 0;
 	    return( ret );
 	}
-	*(rbuf + 2 * sizeof( u_short )) = 0;	/* this is a file */
+	*(rbuf + 2 * sizeof( u_int16_t )) = 0;	/* this is a file */
     }
-    *rbuflen = buflen + 3 * sizeof( u_short );
+    *rbuflen = buflen + 3 * sizeof( u_int16_t );
     fbitmap = htons( fbitmap );
-    bcopy( &fbitmap, rbuf, sizeof( u_short ));
-    rbuf += sizeof( u_short );
+    memcpy( rbuf, &fbitmap, sizeof( fbitmap ));
+    rbuf += sizeof( fbitmap );
     dbitmap = htons( dbitmap );
-    bcopy( &dbitmap, rbuf, sizeof( u_short ));
-    rbuf += sizeof( u_short ) + sizeof( u_char );
+    memcpy( rbuf, &dbitmap, sizeof( dbitmap ));
+    rbuf += sizeof( dbitmap ) + sizeof( u_char );
     *rbuf = 0;
 
     return( AFP_OK );
 }
 
+int
 afp_setfildirparams( ibuf, ibuflen, rbuf, rbuflen )
     char	*ibuf, *rbuf;
     int		ibuflen, *rbuflen;
@@ -109,28 +111,29 @@
     struct vol	*vol;
     struct dir	*dir;
     char	*path;
-    u_short	vid, bitmap;
-    int		did, rc;
+    u_int16_t	vid, bitmap;
+    int		rc;
+    int32_t	did;
 
     *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 );
@@ -158,6 +161,7 @@
     return( rc );
 }
 
+int
 afp_rename( ibuf, ibuflen, rbuf, rbuflen )
     char	*ibuf, *rbuf;
     int		ibuflen, *rbuflen;
@@ -168,21 +172,22 @@
     struct dir		*dir, *odir;
     char		*path, *upath, newpath[ MAXNAMLEN ];
     char		newadpath[ MAXNAMLEN ];
-    int			did, isdir = 0;
+    int32_t		did;
+    int			isdir = 0;
     int			plen;
-    u_short		vid;
+    u_int16_t		vid;
 
     *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 );
     }
@@ -216,7 +221,7 @@
     }
 #endif notdef
 
-    strcpy( newpath, mtoupath( ibuf ));
+    (void)strlcpy( newpath, mtoupath( ibuf ), sizeof(newpath));
     if ( stat( newpath, &st ) == 0 ) {
 	return( AFPERR_EXIST );
     }
@@ -234,7 +239,8 @@
     }
 
     if ( !isdir ) {
-	strcpy( newadpath, ad_path( newpath, 0 ));
+	(void)strlcpy( newadpath, ad_path( newpath, 0 ),
+				sizeof(newadpath));
 	if ( rename( ad_path( upath, 0 ), newadpath ) < 0 ) {
 	    if ( errno == ENOENT ) {	/* no adouble header file */
 		if (( unlink( newadpath ) < 0 ) && ( errno != ENOENT )) {
@@ -257,11 +263,11 @@
 	    syslog( LOG_ERR, "afp_rename: realloc: %m" );
 	    exit( 1 );
 	}
-	strcpy( odir->d_name, ibuf );
+	(void)strlcpy( odir->d_name, ibuf, (plen + 1) );
     }
 
     ad_setentrylen( &ad, ADEID_NAME, plen );
-    bcopy( ibuf, ad_entry( &ad, ADEID_NAME ), plen );
+    memcpy( ad_entry( &ad, ADEID_NAME ), ibuf, plen );
     ad_flush( &ad, ADFLAGS_HF );
     ad_close( &ad, ADFLAGS_HF );
 out:
@@ -271,6 +277,7 @@
 }
 
 
+int
 afp_delete( ibuf, ibuflen, rbuf, rbuflen )
     char	*ibuf, *rbuf;
     int		ibuflen, *rbuflen;
@@ -278,20 +285,21 @@
     struct vol		*vol;
     struct dir		*dir;
     char		*path;
-    int			did, rc;
-    u_short		vid;
+    int32_t		did;
+    int			rc;
+    u_int16_t		vid;
 
     *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 );
     }
@@ -311,6 +319,7 @@
     return( rc );
 }
 
+int
 afp_moveandrename( ibuf, ibuflen, rbuf, rbuflen )
     char	*ibuf, *rbuf;
     int		ibuflen, *rbuflen;
@@ -318,38 +327,39 @@
     struct vol	*vol;
     struct dir	*dir, *odir;
     char	newname[ MAXNAMLEN ], *path, *p;
-    int		sdid, ddid, isdir = 0, rc;
+    int32_t	sdid, ddid;
+    int		isdir = 0, rc;
     int		plen;
-    short	vid;
+    u_int16_t	vid;
 
     *rbuflen = 0;
     ibuf += 2;
 
-    bcopy( ibuf, &vid, sizeof( short ));
-    ibuf += sizeof( short );
+    memcpy( &vid, ibuf, sizeof( vid ));
+    ibuf += sizeof( vid );
     if (( vol = getvolbyvid( vid )) == 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, &ddid, sizeof( int ));
-    ibuf += sizeof( int );
+    memcpy( &ddid, ibuf, sizeof( ddid ));
+    ibuf += sizeof( ddid );
 
     if (( path = cname( vol, dir, &ibuf )) == NULL ) {
 	return( AFPERR_NOOBJ );
     }
 
     if ( *path != '\0' ) {
-	strcpy( newname, path );
+	(void)strlcpy( newname, path, sizeof(newname) );
 	p = ctoupath( vol, dir, newname );
     } else {
 	odir = curdir;
-	strcpy( newname, odir->d_name );
+	(void)strlcpy( newname, odir->d_name, sizeof(newname) );
 	p = ctoupath( vol, odir->d_parent, newname );
 	isdir = 1;
     }
