Subject: [netatalk-admins] help me find the afpd code... ?

From: Brian Reid <[email-masked]>
Date: Sat, 30 Jan 99 10:49:04 -0800

Last week members of this list helped me understand the problem with
the AppleDouble file's magic number suddenly mattering when I switched
to a recent asun version of netatalk from the old groty UMich version.

The summary, per my understanding, is that there was a bug in older
netatalks that created AD files with bad magic numbers, but older
versions also did not check those magic numbers, so it wasn't a big
problem. New afpd needs a good magic number, and checks for it.

I absolutely have to find the place in 1.4b2+asun2.1.1 where afpd is
checking the magic number and disable the check, or I am completely
#&#^$ed. I can't go back to older netatalk and attempts to read some of
the older files cause the share to dismount from the desktop.

I have a million files to move. I don't mind if 5% of them move over as
unusable junk, but I can't live with having afpd abort every time I try
to open a file with a bad magic number.

I've been studying afpd source code all morning and I absolutely cannot
find the place where it is checking magic number. In fact, the only
place I can find where any code is checking magic numbers is in
megatron, which is not part of afpd.

Any ideas or help?

Brian Reid

---

From: "Steven N. Hirsch" <[email-masked]>
Date: Sat, 30 Jan 1999 15:21:03 -0500 (EST)

> the older files cause the share to dismount from the desktop.

It's not in afpd, per se.  Look in ./libatalk/adouble/ad_open.c for the
action..

> to open a file with a bad magic number.

If you have a backup, this script will recurse through an entire netatalk
tree and insert magic numbers in the files under .AppleDouble.  It's been
used only under Unix, but should be portable.

I believe Adrian's latest and greatest release has a switch to turn off
magic number checking as well.

Steve

------------------------ Cut Here ---------------------
:	# -*-perl-*-
eval 'exec perl -w -S $0 ${1+"$@"}'
    if 0;

# fixad - A forcible remedy to .AppleDouble files missing magic numbers.

use strict;
use POSIX qw(fcntl_h);
use IO::File;
use File::Find;
use Cwd;

# Traverse desired filesystems

my $magic = pack "C4", 0x00, 0x05, 0x16, 0x07; 
my $adVersion = pack "C4", 0x00, 0x01, 0x00, 0x00;

sub fixADFiles {
  my $curdir = cwd();
  chdir('.AppleDouble');
  foreach ( glob '*' ) {
    my $fh = new IO::File;
    print "$_\n";
    $fh->open($_, O_WRONLY) || die "Can't open $File::Find::name: $!\n";
    $fh->print($magic);
    $fh->print($adVersion);
    $fh->close;
  }
  chdir($curdir);
}

sub wanted {
  my $globalSave = $_;

    (my ($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
    -d _ &&
    /^\.AppleDouble$/ &&
    fixADFiles();

  $_ = $globalSave;
}

@ARGV == 1 || die "Usage: fixad <dir>\n";

my $dir = shift;

find(\&wanted, $dir);

exit;

--------------------------- Cut Here --------------------------