ca76526b11
if it exists.
218 lines
6.1 KiB
Plaintext
218 lines
6.1 KiB
Plaintext
--- etc/afpd/enumerate.c.orig Sun Aug 17 09:20:06 1997
|
|
+++ etc/afpd/enumerate.c Wed Nov 24 17:15:31 1999
|
|
@@ -5,6 +5,7 @@
|
|
|
|
#include <sys/syslog.h>
|
|
#include <sys/types.h>
|
|
+#include <sys/param.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/file.h>
|
|
#include <netatalk/endian.h>
|
|
@@ -13,12 +14,13 @@
|
|
#include <atalk/adouble.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
-#include <strings.h>
|
|
+#include <string.h>
|
|
#include <dirent.h>
|
|
|
|
#include "desktop.h"
|
|
-#include "directory.h"
|
|
#include "volume.h"
|
|
+#include "directory.h"
|
|
+#include "file.h"
|
|
#include "globals.h"
|
|
|
|
struct dir *
|
|
@@ -44,7 +46,7 @@
|
|
syslog( LOG_ERR, "adddir: malloc: %m" );
|
|
exit( 1 );
|
|
}
|
|
- strcpy( cdir->d_name, name );
|
|
+ (void)strlcpy( cdir->d_name, name, (namlen + 1) );
|
|
if ( dirinsert( vol, cdir ) < 0 ) {
|
|
return( NULL );
|
|
}
|
|
@@ -60,7 +62,7 @@
|
|
* O(n^2) searches on a directory.
|
|
*/
|
|
struct savedir {
|
|
- u_short sd_vid;
|
|
+ u_int16_t sd_vid;
|
|
int sd_did;
|
|
int sd_buflen;
|
|
char *sd_buf;
|
|
@@ -69,21 +71,22 @@
|
|
};
|
|
#define SDBUFBRK 1024
|
|
|
|
+int
|
|
afp_enumerate( ibuf, ibuflen, rbuf, rbuflen )
|
|
char *ibuf, *rbuf;
|
|
int ibuflen, *rbuflen;
|
|
{
|
|
struct stat st;
|
|
- struct adouble ad;
|
|
static struct savedir sd = { 0, 0, 0, 0, 0, 0 };
|
|
struct vol *vol;
|
|
struct dir *dir;
|
|
struct dirent *de;
|
|
DIR *dp;
|
|
- int did, adret, ret, esz, len;
|
|
- char *path, *data, *end, *start, dbuf[ MAXPATHLEN ];
|
|
- u_short vid, fbitmap, dbitmap, reqcnt, actcnt = 0;
|
|
- u_short sindex, maxsz, sz = 0;
|
|
+ int did, ret, esz, len;
|
|
+ char *path, *data, *end, *start;
|
|
+ u_int16_t vid, fbitmap, dbitmap, reqcnt, actcnt = 0;
|
|
+ u_int16_t sindex, maxsz, sz = 0;
|
|
+ int ucflag;
|
|
|
|
if ( sd.sd_buflen == 0 ) {
|
|
if (( sd.sd_buf = (char *)malloc( SDBUFBRK )) == NULL ) {
|
|
@@ -96,53 +99,58 @@
|
|
ibuf += 2;
|
|
ibuflen -= 2;
|
|
|
|
- bcopy( ibuf, &vid, sizeof( u_short ));
|
|
- ibuf += sizeof( u_short );
|
|
- ibuflen -= sizeof( u_short );
|
|
+ memcpy( &vid, ibuf, sizeof( vid ));
|
|
+ ibuf += sizeof( vid );
|
|
+ ibuflen -= sizeof( vid );
|
|
if (( vol = getvolbyvid( vid )) == NULL ) {
|
|
*rbuflen = 0;
|
|
return( AFPERR_PARAM );
|
|
}
|
|
|
|
- bcopy( ibuf, &did, sizeof( int ));
|
|
- ibuf += sizeof( int );
|
|
- ibuflen -= sizeof( int );
|
|
+ /* If this volume is to be used by a ProDOS-8 client, the
|
|
+ designated bit in the volume flags will be
|
|
+ set. <shirsch@ibm.net> */
|
|
+ ucflag = vol->v_flags & AFPVOL_TOUPPER;
|
|
+
|
|
+ memcpy( &did, ibuf, sizeof( did ));
|
|
+ ibuf += sizeof( did );
|
|
+ ibuflen -= sizeof( did );
|
|
if (( dir = dirsearch( vol, did )) == NULL ) {
|
|
*rbuflen = 0;
|
|
return( AFPERR_NODIR );
|
|
}
|
|
|
|
- bcopy( ibuf, &fbitmap, sizeof( u_short ));
|
|
+ memcpy( &fbitmap, ibuf, sizeof( fbitmap ));
|
|
fbitmap = ntohs( fbitmap );
|
|
- ibuf += sizeof( u_short );
|
|
- ibuflen -= sizeof( u_short );
|
|
+ ibuf += sizeof( fbitmap );
|
|
+ ibuflen -= sizeof( fbitmap );
|
|
|
|
- bcopy( ibuf, &dbitmap, sizeof( u_short ));
|
|
+ memcpy( &dbitmap, ibuf, sizeof( dbitmap ));
|
|
dbitmap = ntohs( dbitmap );
|
|
- ibuf += sizeof( u_short );
|
|
- ibuflen -= sizeof( u_short );
|
|
+ ibuf += sizeof( dbitmap );
|
|
+ ibuflen -= sizeof( dbitmap );
|
|
|
|
- bcopy( ibuf, &reqcnt, sizeof( u_short ));
|
|
+ memcpy( &reqcnt, ibuf, sizeof( reqcnt ));
|
|
reqcnt = ntohs( reqcnt );
|
|
- ibuf += sizeof( u_short );
|
|
- ibuflen -= sizeof( u_short );
|
|
+ ibuf += sizeof( reqcnt );
|
|
+ ibuflen -= sizeof( reqcnt );
|
|
|
|
- bcopy( ibuf, &sindex, sizeof( u_short ));
|
|
+ memcpy( &sindex, ibuf, sizeof( sindex ));
|
|
sindex = ntohs( sindex );
|
|
- ibuf += sizeof( u_short );
|
|
- ibuflen -= sizeof( u_short );
|
|
+ ibuf += sizeof( sindex );
|
|
+ ibuflen -= sizeof( sindex );
|
|
|
|
- bcopy( ibuf, &maxsz, sizeof( u_short ));
|
|
+ memcpy( &maxsz, ibuf, sizeof( maxsz ));
|
|
maxsz = ntohs( maxsz );
|
|
- ibuf += sizeof( u_short );
|
|
- ibuflen -= sizeof( u_short );
|
|
+ ibuf += sizeof( maxsz );
|
|
+ ibuflen -= sizeof( maxsz );
|
|
|
|
if (( path = cname( vol, dir, &ibuf )) == NULL ) {
|
|
*rbuflen = 0;
|
|
return( AFPERR_NODIR );
|
|
}
|
|
- data = rbuf + 3 * sizeof( u_short );
|
|
- sz = 3 * sizeof( u_short );
|
|
+ data = rbuf + 3 * sizeof( u_int16_t );
|
|
+ sz = 3 * sizeof( u_int16_t );
|
|
|
|
/*
|
|
* Read the directory into a pre-malloced buffer, stored
|
|
@@ -179,7 +187,7 @@
|
|
end = sd.sd_buf + sd.sd_buflen;
|
|
}
|
|
|
|
- bcopy( de->d_name, sd.sd_last, strlen( de->d_name ) + 1 );
|
|
+ memcpy( sd.sd_last, de->d_name, strlen( de->d_name ) + 1 );
|
|
sd.sd_last += strlen( de->d_name ) + 1;
|
|
}
|
|
*sd.sd_last = 0;
|
|
@@ -236,12 +244,12 @@
|
|
* inaccurate, since that means /dev/null is a file, /dev/printer
|
|
* is a file, etc.
|
|
*/
|
|
- if ( st.st_mode & S_IFDIR ) {
|
|
+ if ( S_ISDIR(st.st_mode)) {
|
|
if ( dbitmap == 0 ) {
|
|
sd.sd_last += len + 1;
|
|
continue;
|
|
}
|
|
- path = utompath( sd.sd_last );
|
|
+ path = utompath( sd.sd_last, ucflag );
|
|
|
|
for ( dir = curdir->d_child; dir; dir = dir->d_next ) {
|
|
if ( strcmp( dir->d_name, path ) == 0 ) {
|
|
@@ -263,7 +271,7 @@
|
|
sd.sd_last += len + 1;
|
|
continue;
|
|
}
|
|
- if (( ret = getfilparams( fbitmap, utompath( sd.sd_last ),
|
|
+ if (( ret = getfilparams( fbitmap, utompath( sd.sd_last, ucflag ),
|
|
curdir, &st, data + 2 * sizeof( u_char ), &esz )) !=
|
|
AFP_OK ) {
|
|
*rbuflen = 0;
|
|
@@ -290,7 +298,7 @@
|
|
|
|
sz += esz + 2 * sizeof( u_char );
|
|
*data++ = esz + 2 * sizeof( u_char );
|
|
- if ( st.st_mode & S_IFDIR ) {
|
|
+ if ( S_ISDIR(st.st_mode)) {
|
|
*data++ = 1<<7;
|
|
} else {
|
|
*data++ = 0;
|
|
@@ -311,14 +319,14 @@
|
|
* All done, fill in misc junk in rbuf
|
|
*/
|
|
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 );
|
|
+ memcpy( rbuf, &dbitmap, sizeof( dbitmap ));
|
|
+ rbuf += sizeof( dbitmap );
|
|
actcnt = htons( actcnt );
|
|
- bcopy( &actcnt, rbuf, sizeof( u_short ));
|
|
- rbuf += sizeof( u_short );
|
|
+ memcpy( rbuf, &actcnt, sizeof( actcnt ));
|
|
+ rbuf += sizeof( actcnt );
|
|
*rbuflen = sz;
|
|
return( AFP_OK );
|
|
}
|