]> arthur.barton.de Git - netatalk.git/commitdiff
Merge master
authorFrank Lahm <franklahm@googlemail.com>
Tue, 3 Jan 2012 14:26:39 +0000 (15:26 +0100)
committerFrank Lahm <franklahm@googlemail.com>
Tue, 3 Jan 2012 14:26:39 +0000 (15:26 +0100)
478 files changed:
Makefile.am
VERSION
bin/Makefile.am
bin/ad/ad.h
bin/ad/ad_cp.c
bin/ad/ad_ls.c
bin/ad/ad_mv.c
bin/adv1tov2/.gitignore [deleted file]
bin/adv1tov2/Makefile.am [deleted file]
bin/adv1tov2/adv1tov2.c [deleted file]
bin/aecho/.gitignore [deleted file]
bin/aecho/Makefile.am [deleted file]
bin/aecho/aecho.c [deleted file]
bin/afppasswd/afppasswd.c
bin/getzones/.gitignore [deleted file]
bin/getzones/Makefile.am [deleted file]
bin/getzones/getzones.c [deleted file]
bin/megatron/Makefile.am
bin/megatron/asingle.c
bin/megatron/hqx.c
bin/megatron/macbin.c
bin/megatron/megatron.c
bin/megatron/nad.c
bin/misc/fce.c
bin/nbp/.gitignore [deleted file]
bin/nbp/Makefile.am [deleted file]
bin/nbp/nbplkup.c [deleted file]
bin/nbp/nbprgstr.c [deleted file]
bin/nbp/nbpunrgstr.c [deleted file]
bin/pap/.gitignore [deleted file]
bin/pap/Makefile.am [deleted file]
bin/pap/pap.c [deleted file]
bin/pap/papstatus.c [deleted file]
bin/psorder/.gitignore [deleted file]
bin/psorder/Makefile.am [deleted file]
bin/psorder/pa.c [deleted file]
bin/psorder/pa.h [deleted file]
bin/psorder/psorder.c [deleted file]
bin/psorder/psorder.h [deleted file]
bin/uniconv/iso8859_1_adapted.c
bin/uniconv/uniconv.c
bootstrap
config/Makefile.am
config/atalkd.conf [deleted file]
config/papd.conf [deleted file]
configure.ac
contrib/Makefile.am
contrib/a2boot/.gitignore [deleted file]
contrib/a2boot/COPYRIGHT [deleted file]
contrib/a2boot/Makefile.am [deleted file]
contrib/a2boot/VERSION [deleted file]
contrib/a2boot/a2boot.c [deleted file]
contrib/misc/libevent.patch [new file with mode: 0644]
contrib/printing/.gitignore [deleted file]
contrib/printing/Makefile.am [deleted file]
contrib/printing/add_netatalk_printer [deleted file]
contrib/printing/netatalk.template [deleted file]
contrib/timelord/.gitignore [deleted file]
contrib/timelord/COPYRIGHT [deleted file]
contrib/timelord/Makefile.am [deleted file]
contrib/timelord/README [deleted file]
contrib/timelord/VERSION [deleted file]
contrib/timelord/timelord.c [deleted file]
etc/Makefile.am
etc/afpd/Makefile.am
etc/afpd/acl_mappings.h
etc/afpd/acls.c
etc/afpd/afp_asp.c [deleted file]
etc/afpd/afp_config.c
etc/afpd/afp_config.h
etc/afpd/afp_dsi.c
etc/afpd/afp_options.c
etc/afpd/afprun.c
etc/afpd/afs.c
etc/afpd/appl.c
etc/afpd/auth.c
etc/afpd/auth.h
etc/afpd/catsearch.c
etc/afpd/desktop.c
etc/afpd/desktop.h
etc/afpd/directory.c
etc/afpd/directory.h
etc/afpd/enumerate.c
etc/afpd/extattrs.c
etc/afpd/file.c
etc/afpd/file.h
etc/afpd/filedir.c
etc/afpd/filedir.h
etc/afpd/fork.c
etc/afpd/fork.h
etc/afpd/gettok.c
etc/afpd/icon.h
etc/afpd/main.c
etc/afpd/mangle.c
etc/afpd/messages.c
etc/afpd/misc.h
etc/afpd/nfsquota.c
etc/afpd/ofork.c
etc/afpd/quota.c
etc/afpd/status.c
etc/afpd/status.h
etc/afpd/uam.c
etc/afpd/uam_auth.h
etc/afpd/uid.c
etc/afpd/uid.h
etc/afpd/unix.c
etc/afpd/unix.h
etc/afpd/volume.c
etc/afpd/volume.h
etc/atalkd/.gitignore [deleted file]
etc/atalkd/Makefile.am [deleted file]
etc/atalkd/aep.c [deleted file]
etc/atalkd/atserv.h [deleted file]
etc/atalkd/config.c [deleted file]
etc/atalkd/gate.h [deleted file]
etc/atalkd/interface.h [deleted file]
etc/atalkd/list.h [deleted file]
etc/atalkd/main.c [deleted file]
etc/atalkd/main.h [deleted file]
etc/atalkd/multicast.c [deleted file]
etc/atalkd/multicast.h [deleted file]
etc/atalkd/nbp.c [deleted file]
etc/atalkd/nbp.h [deleted file]
etc/atalkd/route.c [deleted file]
etc/atalkd/route.h [deleted file]
etc/atalkd/rtmp.c [deleted file]
etc/atalkd/rtmp.h [deleted file]
etc/atalkd/zip.c [deleted file]
etc/atalkd/zip.h [deleted file]
etc/cnid_dbd/cmd_dbd_scanvol.c
etc/cnid_dbd/cnid_metad.c
etc/cnid_dbd/comm.c
etc/cnid_dbd/db_param.h
etc/cnid_dbd/dbd.h
etc/cnid_dbd/dbd_add.c
etc/cnid_dbd/dbd_dbcheck.c
etc/cnid_dbd/dbd_delete.c
etc/cnid_dbd/dbd_get.c
etc/cnid_dbd/dbd_getstamp.c
etc/cnid_dbd/dbd_lookup.c
etc/cnid_dbd/dbd_rebuild_add.c
etc/cnid_dbd/dbd_resolve.c
etc/cnid_dbd/dbd_search.c
etc/cnid_dbd/dbd_update.c
etc/cnid_dbd/dbif.c
etc/cnid_dbd/dbif.h
etc/cnid_dbd/main.c
etc/cnid_dbd/pack.c
etc/cnid_dbd/usockfd.c
etc/papd/.gitignore [deleted file]
etc/papd/Makefile.am [deleted file]
etc/papd/auth.c [deleted file]
etc/papd/comment.c [deleted file]
etc/papd/comment.h [deleted file]
etc/papd/file.c [deleted file]
etc/papd/file.h [deleted file]
etc/papd/headers.c [deleted file]
etc/papd/lp.c [deleted file]
etc/papd/lp.h [deleted file]
etc/papd/magics.c [deleted file]
etc/papd/main.c [deleted file]
etc/papd/ppd.c [deleted file]
etc/papd/ppd.h [deleted file]
etc/papd/print_cups.c [deleted file]
etc/papd/print_cups.h [deleted file]
etc/papd/printcap.c [deleted file]
etc/papd/printcap.h [deleted file]
etc/papd/printer.h [deleted file]
etc/papd/queries.c [deleted file]
etc/papd/session.c [deleted file]
etc/papd/session.h [deleted file]
etc/papd/showppd.c [deleted file]
etc/papd/uam.c [deleted file]
etc/papd/uam_auth.h [deleted file]
etc/psf/.gitignore [deleted file]
etc/psf/Makefile.am [deleted file]
etc/psf/etc2ps.sh [deleted file]
etc/psf/pagecount.ps [deleted file]
etc/psf/psa.c [deleted file]
etc/psf/psf.c [deleted file]
etc/uams/Makefile.am
etc/uams/uams_dhx2_pam.c
etc/uams/uams_dhx2_passwd.c
etc/uams/uams_dhx_pam.c
etc/uams/uams_dhx_passwd.c
etc/uams/uams_gss.c
etc/uams/uams_guest.c
etc/uams/uams_krb4/.gitignore [deleted file]
etc/uams/uams_krb4/Makefile.am [deleted file]
etc/uams/uams_krb4/kuam.c [deleted file]
etc/uams/uams_krb4/lifetime.c [deleted file]
etc/uams/uams_krb4/send_to_kdc.c [deleted file]
etc/uams/uams_krb4/uams_krb4.c [deleted file]
etc/uams/uams_pam.c
etc/uams/uams_passwd.c
etc/uams/uams_pgp.c
etc/uams/uams_randnum.c
include/atalk/.gitignore
include/atalk/Makefile.am
include/atalk/adouble.h
include/atalk/aep.h [deleted file]
include/atalk/afp.h
include/atalk/asp.h [deleted file]
include/atalk/atp.h [deleted file]
include/atalk/cnid.h
include/atalk/cnid_dbd_private.h
include/atalk/compat.h
include/atalk/ddp.h [deleted file]
include/atalk/directory.h
include/atalk/dsi.h
include/atalk/ea.h
include/atalk/globals.h
include/atalk/nbp.h [deleted file]
include/atalk/netddp.h [deleted file]
include/atalk/pap.h [deleted file]
include/atalk/rpc.h [new file with mode: 0644]
include/atalk/rtmp.h [deleted file]
include/atalk/server_child.h
include/atalk/tdb.h
include/atalk/uam.h
include/atalk/unicode.h
include/atalk/util.h
include/atalk/uuid.h
include/atalk/volinfo.h
include/atalk/volume.h
libatalk/Makefile.am
libatalk/acl/cache.c
libatalk/acl/cache.h
libatalk/acl/uuid.c
libatalk/adouble/Makefile.am
libatalk/adouble/ad_attr.c
libatalk/adouble/ad_date.c
libatalk/adouble/ad_flush.c
libatalk/adouble/ad_lock.c
libatalk/adouble/ad_lock.h [new file with mode: 0644]
libatalk/adouble/ad_mmap.c
libatalk/adouble/ad_open.c
libatalk/adouble/ad_private.h [deleted file]
libatalk/adouble/ad_read.c
libatalk/adouble/ad_sendfile.c
libatalk/adouble/ad_size.c
libatalk/adouble/ad_write.c
libatalk/asp/.gitignore [deleted file]
libatalk/asp/Makefile.am [deleted file]
libatalk/asp/asp_attn.c [deleted file]
libatalk/asp/asp_child.h [deleted file]
libatalk/asp/asp_close.c [deleted file]
libatalk/asp/asp_cmdreply.c [deleted file]
libatalk/asp/asp_getreq.c [deleted file]
libatalk/asp/asp_getsess.c [deleted file]
libatalk/asp/asp_init.c [deleted file]
libatalk/asp/asp_shutdown.c [deleted file]
libatalk/asp/asp_tickle.c [deleted file]
libatalk/asp/asp_write.c [deleted file]
libatalk/atp/.gitignore [deleted file]
libatalk/atp/Makefile.am [deleted file]
libatalk/atp/atp_bufs.c [deleted file]
libatalk/atp/atp_close.c [deleted file]
libatalk/atp/atp_internals.h [deleted file]
libatalk/atp/atp_open.c [deleted file]
libatalk/atp/atp_packet.c [deleted file]
libatalk/atp/atp_rreq.c [deleted file]
libatalk/atp/atp_rresp.c [deleted file]
libatalk/atp/atp_rsel.c [deleted file]
libatalk/atp/atp_sreq.c [deleted file]
libatalk/atp/atp_sresp.c [deleted file]
libatalk/cnid/cdb/cnid_cdb.h
libatalk/cnid/cdb/cnid_cdb_add.c
libatalk/cnid/cdb/cnid_cdb_delete.c
libatalk/cnid/cdb/cnid_cdb_get.c
libatalk/cnid/cdb/cnid_cdb_lookup.c
libatalk/cnid/cdb/cnid_cdb_open.c
libatalk/cnid/cdb/cnid_cdb_private.h
libatalk/cnid/cdb/cnid_cdb_rebuild_add.c
libatalk/cnid/cdb/cnid_cdb_update.c
libatalk/cnid/cnid.c
libatalk/cnid/dbd/cnid_dbd.c
libatalk/cnid/dbd/cnid_dbd.h
libatalk/cnid/last/cnid_last.c
libatalk/cnid/last/cnid_last.h
libatalk/cnid/tdb/cnid_tdb.h
libatalk/cnid/tdb/cnid_tdb_add.c
libatalk/cnid/tdb/cnid_tdb_get.c
libatalk/cnid/tdb/cnid_tdb_lookup.c
libatalk/cnid/tdb/cnid_tdb_open.c
libatalk/cnid/tdb/cnid_tdb_update.c
libatalk/compat/Makefile.am
libatalk/compat/misc.c
libatalk/compat/rquota_xdr.c
libatalk/compat/snprintf.c [deleted file]
libatalk/compat/strcasecmp.c [deleted file]
libatalk/compat/strdup.c [deleted file]
libatalk/compat/strlcpy.c [new file with mode: 0644]
libatalk/compat/strstr.c [deleted file]
libatalk/dsi/dsi_attn.c
libatalk/dsi/dsi_close.c
libatalk/dsi/dsi_cmdreply.c
libatalk/dsi/dsi_getsess.c
libatalk/dsi/dsi_getstat.c
libatalk/dsi/dsi_init.c
libatalk/dsi/dsi_opensess.c
libatalk/dsi/dsi_private.h
libatalk/dsi/dsi_read.c
libatalk/dsi/dsi_stream.c
libatalk/dsi/dsi_tcp.c
libatalk/dsi/dsi_tickle.c
libatalk/dsi/dsi_write.c
libatalk/locking/.gitignore [new file with mode: 0644]
libatalk/locking/Makefile.am [new file with mode: 0644]
libatalk/locking/locking.c [new file with mode: 0644]
libatalk/nbp/.gitignore [deleted file]
libatalk/nbp/Makefile.am [deleted file]
libatalk/nbp/nbp_conf.h [deleted file]
libatalk/nbp/nbp_lkup.c [deleted file]
libatalk/nbp/nbp_rgstr.c [deleted file]
libatalk/nbp/nbp_unrgstr.c [deleted file]
libatalk/nbp/nbp_util.c [deleted file]
libatalk/netddp/.gitignore [deleted file]
libatalk/netddp/Makefile.am [deleted file]
libatalk/netddp/netddp_open.c [deleted file]
libatalk/netddp/netddp_recvfrom.c [deleted file]
libatalk/netddp/netddp_sendto.c [deleted file]
libatalk/tdb/Makefile.am
libatalk/tdb/check.c [new file with mode: 0644]
libatalk/tdb/dump.c [new file with mode: 0644]
libatalk/tdb/error.c [new file with mode: 0644]
libatalk/tdb/freelist.c [new file with mode: 0644]
libatalk/tdb/freelistcheck.c [new file with mode: 0644]
libatalk/tdb/io.c [new file with mode: 0644]
libatalk/tdb/lock.c [new file with mode: 0644]
libatalk/tdb/open.c [new file with mode: 0644]
libatalk/tdb/spinlock.c [deleted file]
libatalk/tdb/spinlock.h [deleted file]
libatalk/tdb/tdb.c
libatalk/tdb/tdb_private.h [new file with mode: 0644]
libatalk/tdb/transaction.c [new file with mode: 0644]
libatalk/tdb/traverse.c [new file with mode: 0644]
libatalk/unicode/byteorder.h
libatalk/unicode/charcnv.c
libatalk/unicode/charsets/generic_cjk.c
libatalk/unicode/charsets/generic_cjk.h
libatalk/unicode/charsets/generic_mb.c
libatalk/unicode/charsets/mac_centraleurope.c
libatalk/unicode/charsets/mac_chinese_simp.c
libatalk/unicode/charsets/mac_chinese_simp.h
libatalk/unicode/charsets/mac_chinese_trad.c
libatalk/unicode/charsets/mac_chinese_trad.h
libatalk/unicode/charsets/mac_cyrillic.c
libatalk/unicode/charsets/mac_greek.c
libatalk/unicode/charsets/mac_hebrew.c
libatalk/unicode/charsets/mac_japanese.c
libatalk/unicode/charsets/mac_japanese.h
libatalk/unicode/charsets/mac_korean.c
libatalk/unicode/charsets/mac_korean.h
libatalk/unicode/charsets/mac_roman.c
libatalk/unicode/charsets/mac_turkish.c
libatalk/unicode/iconv.c
libatalk/unicode/utf16_casetable.h
libatalk/unicode/utf8.c
libatalk/unicode/util_unistr.c
libatalk/util/Makefile.am
libatalk/util/atalk_addr.c [deleted file]
libatalk/util/bprint.c
libatalk/util/fault.c
libatalk/util/getiface.c
libatalk/util/server_child.c
libatalk/util/server_ipc.c
libatalk/util/server_lock.c
libatalk/util/strcasestr.c [deleted file]
libatalk/util/strlcpy.c [deleted file]
libatalk/util/unix.c
libatalk/util/volinfo.c
libatalk/vfs/Makefile.am
libatalk/vfs/ea.c [deleted file]
libatalk/vfs/ea_ad.c [new file with mode: 0644]
libatalk/vfs/ea_sys.c
libatalk/vfs/extattr.c [new file with mode: 0644]
libatalk/vfs/sys_ea.c [deleted file]
libatalk/vfs/unix.c
libatalk/vfs/vfs.c
macros/Makefile.am
macros/afs-check.m4
macros/config-checks.m4
macros/cups.m4 [deleted file]
macros/db3-check.m4
macros/gssapi-check.m4
macros/iconv.m4
macros/libgcrypt.m4
macros/netatalk.m4 [new file with mode: 0644]
macros/pam-check.m4
macros/quota-check.m4
macros/snprintf-check.m4 [deleted file]
macros/srvloc.m4
macros/ssl-check.m4
macros/summary.m4
macros/tcp-wrappers.m4
macros/webmin.m4
macros/zeroconf.m4
man/Makefile.am
man/man1/Makefile.am
man/man1/aecho.1 [deleted file]
man/man1/getzones.1 [deleted file]
man/man1/nbp.1 [deleted file]
man/man1/nbplkup.1 [deleted file]
man/man1/nbprgstr.1 [deleted file]
man/man1/nbpunrgstr.1 [deleted file]
man/man1/pap.1 [deleted file]
man/man1/papstatus.1 [deleted file]
man/man1/psorder.1 [deleted file]
man/man3/.gitignore [deleted file]
man/man3/Makefile.am [deleted file]
man/man3/atalk_aton.3 [deleted file]
man/man3/nbp_name.3 [deleted file]
man/man4/.gitignore [deleted file]
man/man4/Makefile.am [deleted file]
man/man4/atalk.4 [deleted file]
man/man5/Makefile.am
man/man5/atalkd.conf.5.tmpl [deleted file]
man/man5/papd.conf.5.tmpl [deleted file]
man/man8/Makefile.am
man/man8/atalkd.8.tmpl [deleted file]
man/man8/papd.8.tmpl [deleted file]
man/man8/papstatus.8.tmpl [deleted file]
man/man8/psf.8.tmpl [deleted file]
man/man8/timelord.8 [deleted file]
sys/.gitignore [deleted file]
sys/Makefile.am [deleted file]
sys/generic/.gitignore [deleted file]
sys/generic/Makefile.am [deleted file]
sys/generic/sys/.gitignore [deleted file]
sys/generic/sys/Makefile.am [deleted file]
sys/generic/sys/cdefs.h [deleted file]
sys/netatalk/.gitignore [deleted file]
sys/netatalk/Makefile.am [deleted file]
sys/netatalk/aarp.c [deleted file]
sys/netatalk/aarp.h [deleted file]
sys/netatalk/at.h [deleted file]
sys/netatalk/at_control.c [deleted file]
sys/netatalk/at_proto.c [deleted file]
sys/netatalk/at_var.h [deleted file]
sys/netatalk/ddp.h [deleted file]
sys/netatalk/ddp_input.c [deleted file]
sys/netatalk/ddp_output.c [deleted file]
sys/netatalk/ddp_usrreq.c [deleted file]
sys/netatalk/ddp_var.h [deleted file]
sys/netatalk/endian.h [deleted file]
sys/netatalk/phase2.h [deleted file]
sys/netbsd/.gitignore [deleted file]
sys/netbsd/Makefile.am [deleted file]
sys/netbsd/netatalk/.gitignore [deleted file]
sys/netbsd/netatalk/Makefile.am [deleted file]
sys/netbsd/netatalk/endian.h [deleted file]
sys/solaris/.gitignore [deleted file]
sys/solaris/Makefile.in [deleted file]
sys/solaris/aarp.c [deleted file]
sys/solaris/ddp.c [deleted file]
sys/solaris/ddp.conf [deleted file]
sys/solaris/dlpi.c [deleted file]
sys/solaris/if.c [deleted file]
sys/solaris/if.h [deleted file]
sys/solaris/ioc.c [deleted file]
sys/solaris/ioc.h [deleted file]
sys/solaris/linkage.c [deleted file]
sys/solaris/rt.c [deleted file]
sys/solaris/rt.h [deleted file]
sys/solaris/sock.c [deleted file]
sys/solaris/sock.h [deleted file]
sys/solaris/tpi.c [deleted file]
sys/sunos/.gitignore [deleted file]
sys/sunos/Makefile.am [deleted file]
sys/sunos/Makefile.kernel [deleted file]
sys/sunos/at_sun.c [deleted file]
sys/ultrix/.gitignore [deleted file]
sys/ultrix/Makefile.am [deleted file]
sys/ultrix/Makefile.kernel [deleted file]
sys/ultrix/at_ultrix.c [deleted file]
sys/ultrix/kpatch-4.1 [deleted file]
sys/ultrix/kpatch-4.2 [deleted file]

index 1203023118901ebe8c00249ef3cc2889222fe104..e56c257997a4dcbb3c0abc125d8b0b1bc6f5207e 100644 (file)
@@ -1,6 +1,6 @@
 # Makefile.am for top level of netatalk package
 
-SUBDIRS = libatalk bin config etc man contrib distrib include sys doc macros test
+SUBDIRS = libatalk bin config etc man contrib distrib include doc macros test
 
 EXTRA_DIST = CONTRIBUTORS COPYRIGHT COPYING NEWS VERSION services.atalk
 
diff --git a/VERSION b/VERSION
index 89fbff8f4a97fefd64a478518d14320a709a13ea..48898d6a616ca58a9e8798ab09639b25511eaf08 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-2.2.2dev
\ No newline at end of file
+3.0dev
\ No newline at end of file
index 7c633f748f409ed1fecf5ba637ebfa75d7ce572b..f5d1448ae3621d70a8241af4864a925335693e68 100644 (file)
@@ -1,10 +1,6 @@
 # Makefile.am for bin/
 
-SUBDIRS = adv1tov2 afppasswd cnid megatron uniconv misc
-
-if USE_APPLETALK
-SUBDIRS += aecho getzones nbp pap psorder
-endif
+SUBDIRS = afppasswd cnid megatron uniconv misc
 
 if HAVE_ATFUNCS
 SUBDIRS += ad
index 6e41a9c02ba932cd5e2829b11b5da05f9aacb668..b0e8efba4a0d3aca3907eb31e23e525a4f315469 100644 (file)
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <signal.h>
+#include <arpa/inet.h>
 
 #include <atalk/ftw.h>
 #include <atalk/volinfo.h>
 #include <atalk/cnid.h>
+#include <atalk/compat.h>
 
 #define DIR_DOT_OR_DOTDOT(a) \
         ((strcmp(a, ".") == 0) || (strcmp(a, "..") == 0))
index 720ea6d3175027bc5d62480cbd31a58b61f2bcd3..f280aeb98ea8e36e023725627244a1c4afa91bc5 100644 (file)
@@ -543,8 +543,8 @@ static int copy(const char *path,
                 badcp = rval = 1;
                 break;
             }
-            ad_init(&ad, dvolume.volinfo.v_adouble, dvolume.volinfo.v_ad_options);
-            if (ad_open_metadata(to.p_path, ADFLAGS_DIR, O_RDWR | O_CREAT, &ad) != 0) {
+            ad_init_old(&ad, dvolume.volinfo.v_adouble, dvolume.volinfo.v_ad_options);
+            if (ad_open(&ad, to.p_path, ADFLAGS_HF | ADFLAGS_DIR | ADFLAGS_RDWR | ADFLAGS_CREATE, 0666) != 0) {
                 ERROR("Error opening adouble for: %s", to.p_path);
             }
             ad_setid( &ad, st.st_dev, st.st_ino, did, pdid, dvolume.db_stamp);
@@ -554,7 +554,7 @@ static int copy(const char *path,
             ad_setdate(&ad, AD_DATE_ACCESS | AD_DATE_UNIX, st.st_mtime);
             ad_setdate(&ad, AD_DATE_BACKUP, AD_DATE_START);
             ad_flush(&ad);
-            ad_close_metadata(&ad);
+            ad_close(&ad, ADFLAGS_HF);
 
             umask(omask);
         }
@@ -610,8 +610,8 @@ static int copy(const char *path,
                 badcp = rval = 1;
                 break;
             }
-            ad_init(&ad, dvolume.volinfo.v_adouble, dvolume.volinfo.v_ad_options);
-            if (ad_open_metadata(to.p_path, 0, O_RDWR | O_CREAT, &ad) != 0) {
+            ad_init_old(&ad, dvolume.volinfo.v_adouble, dvolume.volinfo.v_ad_options);
+            if (ad_open(&ad, to.p_path, ADFLAGS_HF | ADFLAGS_RDWR | ADFLAGS_CREATE, 0666) != 0) {
                 ERROR("Error opening adouble for: %s", to.p_path);
             }
             ad_setid( &ad, st.st_dev, st.st_ino, cnid, did, dvolume.db_stamp);
@@ -621,7 +621,7 @@ static int copy(const char *path,
             ad_setdate(&ad, AD_DATE_ACCESS | AD_DATE_UNIX, st.st_mtime);
             ad_setdate(&ad, AD_DATE_BACKUP, AD_DATE_START);
             ad_flush(&ad);
-            ad_close_metadata(&ad);
+            ad_close(&ad, ADFLAGS_HF);
             umask(omask);
         }
         break;
index 63226a37cd77ccc5a174ad285151546481a88268..ef3f4c33d2e02d4aff7de7bdbf86beefaaa7e613 100644 (file)
@@ -231,7 +231,7 @@ static void print_flags(char *path, afpvol_t *vol, const struct stat *st)
     if (vol->volinfo.v_path == NULL)
         return;
 
-    ad_init(&ad, vol->volinfo.v_adouble, vol->volinfo.v_ad_options);
+    ad_init_old(&ad, vol->volinfo.v_adouble, vol->volinfo.v_ad_options);
 
     if ( ad_metadata(path, adflags, &ad) < 0 )
         return;
@@ -381,7 +381,7 @@ static void print_flags(char *path, afpvol_t *vol, const struct stat *st)
     else
         printf(" !ADVOL_CACHE ");
 
-    ad_close_metadata(&ad);
+    ad_close(&ad, ADFLAGS_HF);
 }
 
 #define TYPE(b) ((st->st_mode & (S_IFMT)) == (b))
index 4d23183ae13865c3c59a8298cde36e5cedbfeb91..7dab6c6fc35102cb7118414e0e13a352deb61b7a 100644 (file)
@@ -373,14 +373,14 @@ static int do_move(const char *from, const char *to)
         free(p);
 
         struct adouble ad;
-        ad_init(&ad, dvolume.volinfo.v_adouble, dvolume.volinfo.v_ad_options);
-        if (ad_open_metadata(to, S_ISDIR(sb.st_mode) ? ADFLAGS_DIR : 0, O_RDWR, &ad) != 0) {
+        ad_init_old(&ad, dvolume.volinfo.v_adouble, dvolume.volinfo.v_ad_options);
+        if (ad_open(&ad, to, S_ISDIR(sb.st_mode) ? (ADFLAGS_DIR | ADFLAGS_HF | ADFLAGS_RDWR) : ADFLAGS_HF | ADFLAGS_RDWR) != 0) {
             SLOG("Error opening adouble for: %s", to);
             return 1;
         }
         ad_setid(&ad, sb.st_dev, sb.st_ino, cnid, newdid, dvolume.db_stamp);
         ad_flush(&ad);
-        ad_close_metadata(&ad);
+        ad_close(&ad, ADFLAGS_HF);
 
         if (vflg)
             printf("%s -> %s\n", from, to);
diff --git a/bin/adv1tov2/.gitignore b/bin/adv1tov2/.gitignore
deleted file mode 100644 (file)
index 4fada59..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-Makefile
-Makefile.in
-adv1tov2
-.deps
-.libs
-.gitignore
-adv1tov2.o
diff --git a/bin/adv1tov2/Makefile.am b/bin/adv1tov2/Makefile.am
deleted file mode 100644 (file)
index 1bfc6ca..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-# Makefile.am for bin/adv1tov2/
-
-INCLUDES = -I$(top_srcdir)/include -I$(top_srcdir)/sys
-
-bin_PROGRAMS = adv1tov2
-
-adv1tov2_SOURCES = adv1tov2.c
-adv1tov2_LDADD = $(top_builddir)/libatalk/libatalk.la
diff --git a/bin/adv1tov2/adv1tov2.c b/bin/adv1tov2/adv1tov2.c
deleted file mode 100644 (file)
index eade898..0000000
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- * $Id: adv1tov2.c,v 1.5 2009-10-14 01:38:28 didg Exp $
- * v1tov2: given a root directory, run down and convert all the
- * files/directories into appledouble v2.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <atalk/adouble.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <dirent.h>
-#ifdef HAVE_FCNTL_H
-#include <fcntl.h>
-#endif /* HAVE_FCNTL_H */
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
-#include <ctype.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/param.h>
-#include <errno.h>
-#include <string.h>
-
-#include <atalk/util.h>
-
-#if AD_VERSION == AD_VERSION2
-#if 0
-/* translate characters */
-static void xlate(char *name, int flags) {
-  static const char hexdig[] = "0123456789abcdef";
-  char upath[MAXPATHLEN + 1];
-  char *m, *u;
-  int doit = 0;
-
-  m = name;
-  u = upath;
-  while (*m != '\0') {
-    if (isascii(*m) && !isprint(*m)) {
-      doit = 1;
-      *u++ = ':';
-      *u++ = hexdig[(*m & 0xf0) >> 4];
-      *u++ = hexdig[*m & 0x0f];
-    } else
-      *u++ = *m;
-    m++;
-  }
-  
-  if (doit) {
-    *u = '\0';
-    rename(name, upath);
-    if ((flags & ADFLAGS_DIR) == 0)
-      rename(ad_path(name, flags), ad_path(upath, flags)); /* rename rfork */
-  }
-}
-#endif
-
-#define MAXDESCEND 0xFFFF
-/* recursively descend subdirectories. 
- * oh the stack space we use up! */
-static void descend(DIR *dp)
-{
-  DIR *dpnew;
-  struct dirent *de;
-  struct stat st;
-  struct adouble ad;
-  int flags;
-  static int count = 0;
-
-  ad_init(&ad, AD_VERSION2, 0);
-  if (count++ > MAXDESCEND) {
-    fprintf(stderr, "FAILURE: too many subdirectories! possible infinite recursion.");
-    return;
-  }
-    
-  putc('(', stderr);
-  for (de = readdir(dp); de; de = readdir(dp)) {
-    if (de->d_name[0] == '.') 
-      continue;
-
-    if (stat(de->d_name, &st) < 0) {
-      fprintf(stderr, "FAILURE: can't stat %s\n", de->d_name);
-      continue;
-    }
-
-    /* go down subdirectory */
-    flags = ADFLAGS_HF;
-    if (S_ISDIR(st.st_mode) && (dpnew = opendir(de->d_name))) {
-      chdir(de->d_name);
-      descend(dpnew);
-      closedir(dpnew);
-      chdir("..");
-      flags |= ADFLAGS_DIR;
-    }
-
-    if (ad_open(de->d_name, flags, O_RDWR, 0, &ad) < 0) {
-      if (errno != ENOENT)
-          fprintf(stderr, "\nFAILURE: can't convert %s, %s\n", fullpathname(de->d_name), strerror(errno));
-      continue;
-    }
-    ad_close(&ad, ADFLAGS_HF);
-    fputc('.', stderr);
-  }
-  putc(')', stderr);
-}
-
-
-int main(int argc, char **argv)
-{
-  DIR           *dp;
-  struct adouble ad;
-  ad_init(&ad, AD_VERSION2, 0);
-  if (argc != 2) {
-    fprintf(stderr, "%s <directory>\n", *argv);
-    return -1;
-  }
-    
-  /* convert main directory */
-  if (ad_open(argv[1], ADFLAGS_HF | ADFLAGS_DIR, O_RDWR, 0, 
-             &ad) < 0) {
-    fprintf(stderr, "FAILURE: can't convert %s\n", argv[1]);
-    return -1;
-  }
-
-  ad_close(&ad, ADFLAGS_HF);
-  if ((dp = opendir(argv[1])) == NULL) {
-    fprintf(stderr, "%s: unable to open %s\n", *argv, argv[1]);
-    return -1;
-  }
-
-  chdir(argv[1]);
-  descend(dp);
-  closedir(dp);
-  chdir("..");
-
-  putc('\n', stderr);
-  return 0;
-}
-
-#else /* AD_VERSION == AD_VERSION2 */
-int main(int argc, char **argv)
-{
-  fprintf(stderr, "%s not built for v2 AppleDouble files.\n", *argv);
-  return -1;
-}
-#endif /* AD_VERSION == AD_VERSION2 */
diff --git a/bin/aecho/.gitignore b/bin/aecho/.gitignore
deleted file mode 100644 (file)
index 76402fb..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-Makefile
-Makefile.in
-aecho
-.deps
-.libs
-.gitignore
-aecho.o
diff --git a/bin/aecho/Makefile.am b/bin/aecho/Makefile.am
deleted file mode 100644 (file)
index d3e487e..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-# Makefile.am for bin/aecho/
-
-INCLUDES = -I$(top_srcdir)/include -I$(top_srcdir)/sys
-
-bin_PROGRAMS = aecho
-
-aecho_SOURCES = aecho.c
-aecho_LDADD = $(top_builddir)/libatalk/libatalk.la
diff --git a/bin/aecho/aecho.c b/bin/aecho/aecho.c
deleted file mode 100644 (file)
index 274421b..0000000
+++ /dev/null
@@ -1,264 +0,0 @@
-/*
- * $Id: aecho.c,v 1.9 2009-10-14 01:38:28 didg Exp $
- *
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- * All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software and
- * its documentation for any purpose and without fee is hereby granted,
- * provided that the above copyright notice appears in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation, and that the name of The University
- * of Michigan not be used in advertising or publicity pertaining to
- * distribution of the software without specific, written prior
- * permission. This software is supplied as is without expressed or
- * implied warranties of any kind.
- *
- *     Research Systems Unix Group
- *     The University of Michigan
- *     c/o Mike Clark
- *     535 W. William Street
- *     Ann Arbor, Michigan
- *     +1-313-763-0525
- *     netatalk@itd.umich.edu
- */
-
-/*
- * AppleTalk Echo Protocol Client
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-#include <errno.h>
-
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#ifdef HAVE_NETDB_H
-#include <netdb.h>
-#endif /* HAVE_NETDB_H */
-
-#include <netatalk/endian.h>
-#include <netatalk/at.h>
-#include <atalk/compat.h>
-#include <atalk/aep.h>
-#include <atalk/nbp.h>
-#include <atalk/netddp.h>
-#include <atalk/ddp.h>
-#include <atalk/util.h>
-
-/* FIXME/SOCKLEN_T: socklen_t is a unix98 feature */
-#ifndef SOCKLEN_T
-#define SOCKLEN_T unsigned int
-#endif /* ! SOCKLEN_T */
-
-static struct sockaddr_at      target;
-static int                     sock;
-static unsigned int            nsent = 0, nrecv = 0;
-static time_t                  totalms = 0, minms = -1, maxms = -1;
-static unsigned int            pings = 0;
-
-static void usage(char *);
-
-static void done(int sig _U_)
-{
-    if ( nsent) {
-       printf( "\n----%d.%d AEP Statistics----\n",
-               ntohs( target.sat_addr.s_net ), target.sat_addr.s_node );
-       printf( "%d packets sent, %d packets received, %d%% packet loss\n",
-               nsent, nrecv, (( nsent - nrecv ) * 100 ) / nsent );
-       if ( nrecv ) {
-           printf( "round-trip (ms)  min/avg/max = %ld/%ld/%ld\n",
-                   minms, totalms / nrecv, maxms );
-       }       
-    }
-    exit( 0 );
-}
-  
-static void aep_send(int sig _U_)
-{
-    struct timeval     tv;
-    char               *p, buf[ 1024 ];
-    static unsigned int        seq = 0;
-
-    p = buf;
-    *p++ = DDPTYPE_AEP;
-    *p++ = AEPOP_REQUEST;
-    memcpy( p, &seq, sizeof( unsigned int ));
-    p += sizeof( unsigned int );
-    seq++;
-
-    if ( gettimeofday( &tv, (struct timezone *)0 ) < 0 ) {
-       perror( "gettimeofday" );
-       exit( 1 );
-    }
-    memcpy( p, &tv, sizeof( struct timeval ));
-    p += sizeof( struct timeval );
-
-    if ( netddp_sendto( sock, buf, p - buf, 0, (struct sockaddr *) &target,
-           sizeof( struct sockaddr_at )) < 0 ) {
-       perror( "sendto" );
-       exit( 1 );
-    }
-    nsent++;
-    if (pings && nsent > pings) done(0);
-}
-
-int main(int ac, char **av)
-{
-    struct servent     *se;
-    struct sigaction   sv;
-    struct itimerval   it;
-    struct sockaddr_at sat, saddr;
-    struct timeval     tv, atv;
-    struct nbpnve      nn;
-    char               *obj = NULL, *type = "Workstation", *zone = "*";
-    int                        cc;
-    SOCKLEN_T          satlen;
-    unsigned int       seq;
-    time_t             ms;
-    char               buf[ 1024 ], *p;
-    unsigned char      port;
-
-    extern char                *optarg;
-    extern int         optind;
-  
-    memset(&saddr, 0, sizeof(saddr));
-    while (( cc = getopt( ac, av, "c:A:" )) != EOF ) {
-       switch ( cc ) {
-       case 'A':
-           if (!atalk_aton(optarg, &saddr.sat_addr)) {
-               fprintf(stderr, "Bad address.\n");
-               exit(1);
-           }
-           break;
-
-         case 'c' :
-           pings = atoi( optarg );
-           break;
-
-       default :
-           usage( av[ 0 ] );
-           exit( 1 );
-       }
-    }
-    if ( ac - optind != 1 ) {
-       usage( av[ 0 ] );
-       exit( 1 );
-    }
-    
-    /*
-     * Save the port, since nbp_lookup calls getservbyname() to get the
-     * nbp port.
-     */
-    if (( se = getservbyname( "echo", "ddp" )) == NULL ) 
-       port = 4;
-    else
-       port = ntohs( se->s_port );
-
-    memset( &target, 0, sizeof( struct sockaddr_at ));
-#ifdef BSD4_4
-    target.sat_len = sizeof( struct sockaddr_at );
-#endif /* BSD4_4 */
-    target.sat_family = AF_APPLETALK;
-    if ( !atalk_aton( av[ optind ], &target.sat_addr )) {
-       if ( nbp_name( av[ optind ], &obj, &type, &zone ) || !obj ) {
-           fprintf( stderr, "Bad name: %s\n", av[ optind ] );
-           exit( 1 );
-       }
-       if ( nbp_lookup( obj, type, zone, &nn, 1, &saddr.sat_addr) <= 0 ) {
-           fprintf( stderr, "Can't find: %s\n", av[ optind ] );
-           exit( 1 );
-       }
-       memcpy( &target, &nn.nn_sat, sizeof( struct sockaddr_at ));
-    }
-    target.sat_port = port;
-
-    if ((sock = netddp_open(saddr.sat_addr.s_net || saddr.sat_addr.s_node ? 
-                        &saddr : NULL, NULL)) < 0) {
-       perror("ddp_open");
-       exit(1);
-    }        
-
-    sv.sa_handler = aep_send;
-    sigemptyset( &sv.sa_mask );
-    sigaddset( &sv.sa_mask, SIGINT );
-    sv.sa_flags = SA_RESTART;
-    if ( sigaction( SIGALRM, &sv, (struct sigaction *)0 ) < 0 ) {
-       perror( "sigaction" );
-       exit( 1 );
-    }
-
-    sv.sa_handler = done;
-    sigemptyset( &sv.sa_mask );
-    sigaddset( &sv.sa_mask, SIGALRM );
-    sv.sa_flags = SA_RESTART;
-    if ( sigaction( SIGINT, &sv, (struct sigaction *)0 ) < 0 ) {
-       perror( "sigaction" );
-       exit( 1 );
-    }
-
-    it.it_interval.tv_sec = 1L;
-    it.it_interval.tv_usec = 0L;
-    it.it_value.tv_sec = 1L;
-    it.it_value.tv_usec = 0L;
-
-    if ( setitimer( ITIMER_REAL, &it, (struct itimerval *)0 ) < 0 ) {
-       perror( "setitimer" );
-       exit( 1 );
-    }
-
-    for (;;) {
-       satlen = sizeof( struct sockaddr_at );
-       if (( cc = netddp_recvfrom( sock, buf, sizeof( buf ), 0, 
-                                   (struct sockaddr *) &sat,
-                                   &satlen )) < 0 ) {
-           if ( errno == EINTR ) {
-               errno = 0;
-               continue;
-           } else {
-               perror( "recvfrom" );
-               exit( 1 );
-           }
-       }
-       p = buf;
-       if ( *p++ != DDPTYPE_AEP || *p++ != AEPOP_REPLY ) {
-           fprintf( stderr, "%s: bad packet!\n", av[ 0 ] );
-           continue;
-       }
-       if ( gettimeofday( &tv, (struct timezone *)0 ) < 0 ) {
-           perror( "gettimeofday" );
-           exit( 1 );
-       }
-       memcpy( &seq, p, sizeof( unsigned int ));
-       p += sizeof( unsigned int );
-       memcpy( &atv, p, sizeof( struct timeval ));
-       nrecv++;
-       ms = ( tv.tv_sec - atv.tv_sec ) * 1000 +
-               ( tv.tv_usec - atv.tv_usec ) / 1000;
-       totalms += ms;
-       if ( ms > maxms ) {
-           maxms = ms;
-       }
-       if ( ms < minms || minms == -1 ) {
-           minms = ms;
-       }
-       printf( "%d bytes from %u.%u: aep_seq=%d. time=%ld. ms\n",
-               cc, ntohs( sat.sat_addr.s_net ), sat.sat_addr.s_node,
-               seq, ms );
-        if (pings && seq + 1 >= pings) done(0);
-    }
-}
-
-static void usage( char * av0 )
-{
-    fprintf( stderr, "usage:\t%s [-A source address ] [-c count] ( addr | nbpname )\n", av0 );
-    exit( 1 );
-}
index 7a003560b2c9a677128a369008a02ef582e8d53d..f5778a53d03ba6b398ece79cb0d163ba44a7eb8e 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
-#ifdef HAVE_UNISTD_H
 #include <unistd.h>
-#endif /* HAVE_UNISTD_H */
 #include <ctype.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/param.h>
-#ifdef HAVE_FCNTL_H
 #include <fcntl.h>
-#endif /* HAVE_FCNTL_H */
 #include <pwd.h>
-
-#include <netatalk/endian.h>
+#include <arpa/inet.h>
 
 #include <des.h>
 
@@ -69,7 +64,7 @@ static char buf[MAXPATHLEN + 1];
 #define unhex(x)  (isdigit(x) ? (x) - '0' : toupper(x) + 10 - 'A')
 static void convert_passwd(char *buf, char *newpwd, const int keyfd)
 {
-  u_int8_t key[HEXPASSWDLEN];
+  uint8_t key[HEXPASSWDLEN];
   Key_schedule schedule;
   unsigned int i, j;
 
diff --git a/bin/getzones/.gitignore b/bin/getzones/.gitignore
deleted file mode 100644 (file)
index 2cbaa2c..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-Makefile
-Makefile.in
-getzones
-.deps
-.libs
-.gitignore
-getzones.o
diff --git a/bin/getzones/Makefile.am b/bin/getzones/Makefile.am
deleted file mode 100644 (file)
index e99d41f..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-# Makefile.am for bin/getzones/
-
-INCLUDES = -I$(top_srcdir)/include -I$(top_srcdir)/sys
-
-bin_PROGRAMS = getzones
-
-getzones_SOURCES = getzones.c
-getzones_LDADD = $(top_builddir)/libatalk/libatalk.la
diff --git a/bin/getzones/getzones.c b/bin/getzones/getzones.c
deleted file mode 100644 (file)
index b175710..0000000
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * $Id: getzones.c,v 1.9 2009-10-14 01:38:28 didg Exp $
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/param.h>
-#include <sys/uio.h>
-#include <sys/time.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
-#ifdef HAVE_NETDB_H
-#include <netdb.h>
-#endif /* HAVE_NETDB_H */
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <netatalk/endian.h>
-#include <netatalk/at.h>
-#include <atalk/atp.h>
-#include <atalk/util.h>
-#include <atalk/unicode.h>
-#include <atalk/zip.h>
-
-static void print_zones(short n, char *buf);
-
-static void usage( char *s)
-{
-    fprintf( stderr, "usage:\t%s [-m | -l] [address]\n", s );
-    exit( 1 );
-}
-
-int main( int argc, char *argv[])
-{
-    struct atp_handle  *ah;
-    struct atp_block   atpb;
-    struct sockaddr_at saddr;
-    struct servent     *se;
-    char               reqdata[4], buf[ ATP_MAXDATA ];
-    struct iovec       iov;
-    short              temp, index = 0;
-    int                        c, myzoneflg = 0, localzonesflg = 0, errflg = 0;
-    extern int         optind;
-
-    reqdata[ 0 ] = ZIPOP_GETZONELIST;
-
-    while (( c = getopt( argc, argv, "ml" )) != EOF ) {
-       switch (c) {
-       case 'm':
-           if ( localzonesflg ) {
-               ++errflg;
-           }
-           ++myzoneflg;
-           reqdata[ 0 ] = ZIPOP_GETMYZONE;
-           break;
-       case 'l':
-           if ( myzoneflg ) {
-               ++errflg;
-           }
-           ++localzonesflg;
-           reqdata[ 0 ] = ZIPOP_GETLOCALZONES;
-           break;
-       default:
-           ++errflg;
-       }
-    }
-
-    if ( errflg || argc - optind > 1 ) {
-       usage( argv[ 0 ] );
-    }
-
-    memset( &saddr, 0, sizeof( struct sockaddr_at ));
-#ifdef BSD4_4
-    saddr.sat_len = sizeof( struct sockaddr_at );
-#endif /* BSD4_4 */
-    saddr.sat_family = AF_APPLETALK;
-    if (( se = getservbyname( "zip", "ddp" )) == NULL )
-       saddr.sat_port = 6;
-    else 
-        saddr.sat_port = ntohs( se->s_port );
-
-    if ( argc == optind ) {
-       saddr.sat_addr.s_net = ATADDR_ANYNET;
-       saddr.sat_addr.s_node = ATADDR_ANYNODE;
-    } else {
-       if ( !atalk_aton( argv[ optind ], &saddr.sat_addr )) {
-           fprintf( stderr, "Bad address.\n" );
-           exit( 1 );
-       }
-    }
-
-    if (( ah = atp_open( ATADDR_ANYPORT, &saddr.sat_addr )) == NULL ) {
-       perror( "atp_open" );
-       exit( 1 );
-    }
-
-    index = ( myzoneflg ? 0 : 1 );
-    reqdata[1] = 0;
-
-    do {
-       atpb.atp_saddr = &saddr;
-       temp = htons( index );
-       memcpy( reqdata + 2, &temp, 2 );
-       atpb.atp_sreqdata = reqdata;
-       atpb.atp_sreqdlen = 4;
-       atpb.atp_sreqto = 2;
-       atpb.atp_sreqtries = 5;
-
-       /* send getzone request zones (or get my zone)
-       */
-       if ( atp_sreq( ah, &atpb, 1, 0 ) < 0 ) {
-           perror( "atp_sreq" );
-           exit( 1 );
-       }
-
-       iov.iov_base = buf;
-       iov.iov_len = ATP_MAXDATA;
-       atpb.atp_rresiov = &iov;
-       atpb.atp_rresiovcnt = 1;
-
-       if ( atp_rresp( ah, &atpb ) < 0 ) {
-           perror( "atp_rresp" );
-           exit( 1 );
-       }
-
-       memcpy( &temp, (char *) iov.iov_base + 2, 2 );
-       temp = ntohs( temp );
-       print_zones( temp, (char *) iov.iov_base+4 );
-       index += temp;
-    } while ( !myzoneflg && !((char *)iov.iov_base)[ 0 ] );
-
-    if ( atp_close( ah ) != 0 ) {
-       perror( "atp_close" );
-       exit( 1 );
-    }
-
-    exit( 0 );
-}
-
-
-/*
- * n:   number of zones in this packet
- * buf: zone length/name pairs
- */
-static void print_zones( short n, char *buf )
-{
-    size_t zone_len;
-    char *zone;
-
-    for ( ; n--; buf += (*buf) + 1 ) {
-
-        if ((size_t)(-1) == (zone_len = convert_string_allocate( CH_MAC,
-                       CH_UNIX, buf+1, *buf, &zone)) ) {
-            zone_len = *buf;
-            if (( zone = strdup(buf+1)) == NULL ) {
-               perror( "strdup" );
-               exit( 1 );
-            }
-        }
-
-       printf( "%.*s\n", (int)zone_len, zone );
-
-       free(zone);
-    }
-}
index c93e201fd3fe696f371b86e0242ce286823d3f04..3032efa4bc2e09716bc7e8929326d71ca38b377b 100644 (file)
@@ -1,23 +1,4 @@
 # Makefile.am for bin/megatron/
 
-INCLUDES = -I$(top_srcdir)/include -I$(top_srcdir)/sys
-
-bin_PROGRAMS = megatron
-
-megatron_SOURCES = asingle.c hqx.c macbin.c megatron.c nad.c updcrc.c
-megatron_LDADD = $(top_builddir)/libatalk/libatalk.la
-
-noinst_HEADERS = asingle.h megatron.h hqx.h macbin.h nad.h updcrc.h
-
-LINKS = unbin unhex unsingle hqx2bin single2bin macbinary binheader nadheader
-
-install-exec-hook:
-       @for LINK in $(LINKS); do \
-               rm -f $(DESTDIR)$(bindir)/$$LINK; \
-               $(LN_S) megatron $(DESTDIR)$(bindir)/$$LINK; \
-       done
-
-uninstall-hook:
-       @for LINK in $(LINKS); do \
-               rm -f $(DESTDIR)$(bindir)/$$LINK; \
-       done
+# EXTRADIST = asingle.c hqx.c macbin.c megatron.c nad.c updcrc.c \
+#      asingle.h megatron.h hqx.h macbin.h nad.h updcrc.h
index 467ac5f7eb302ab576a70b8b7dafe5716eeb61f2..73e4ffaaff1022e6bc60a160ae2d550338b56d17 100644 (file)
 #include <sys/uio.h>
 #include <sys/time.h>
 #include <sys/param.h>
-#ifdef HAVE_FCNTL_H
 #include <fcntl.h>
-#endif /* HAVE_FCNTL_H */
 #include <time.h>
 #include <string.h>
 #include <ctype.h>
 #include <stdio.h>
-#ifdef HAVE_UNISTD_H
 #include <unistd.h>
-#endif /* HAVE_UNISTD_H */
+
 #include <atalk/adouble.h>
 #include <netatalk/endian.h>
 #include "asingle.h"
index 117c9dd65d08b0726ab83168cfb18c83a93aa89f..da2f71cf58f04f7c25d6a0851fd8d8659ff78605 100644 (file)
@@ -18,9 +18,7 @@
 #include <time.h>
 
 #include <unistd.h>
-#ifdef HAVE_FCNTL_H
 #include <fcntl.h>
-#endif /* HAVE_FCNTL_H */
 
 #include <netinet/in.h>
 
index 73ae629204b4ff0afd55b417a03e72cbe61062ef..51b7ac5f616ede35aeb604892e423e3bbf4a35e6 100644 (file)
 #include <sys/uio.h>
 #include <sys/time.h>
 #include <sys/param.h>
-#ifdef HAVE_FCNTL_H
 #include <fcntl.h>
-#endif /* HAVE_FCNTL_H */
-#ifdef HAVE_UNISTD_H
 #include <unistd.h>
-#endif /* HAVE_UNISTD_H */
 #include <string.h>
 #include <strings.h>
 #include <ctype.h>
index c86ba637a8980119600e025e1c46041526c59b73..573a3dc88696c408e92a2173687cec417c978107 100644 (file)
@@ -6,9 +6,7 @@
 #include <sys/param.h>
 #include <sys/stat.h>
 #include <sys/uio.h>
-#ifdef HAVE_FCNTL_H
 #include <fcntl.h>
-#endif /* HAVE_FCNTL_H */
 #include <time.h>
 #include <ctype.h>
 #include <stdio.h>
index 92be35413fc8ed3c17a91ef2dc120e42ea5e55bc..9d0b64bf5627612a6bfeb1502d0512b6b8d27f1a 100644 (file)
@@ -16,9 +16,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <dirent.h>
-#ifdef HAVE_FCNTL_H
 #include <fcntl.h>
-#endif /* HAVE_FCNTL_H */
 
 #include <atalk/adouble.h>
 #include <atalk/util.h>
index 76ca0a8e6a63505b41d736245b768ae1682345d3..d69699079ff99c63df589f5450fbddc226f3ee3f 100644 (file)
@@ -14,9 +14,7 @@
 #include <netdb.h>
 #include <inttypes.h>
 #include <sys/types.h>
-
 #include <sys/param.h>
-#include <sys/cdefs.h>
 
 #include <atalk/fce_api.h>
 #include <atalk/util.h>
diff --git a/bin/nbp/.gitignore b/bin/nbp/.gitignore
deleted file mode 100644 (file)
index e70b05a..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-Makefile
-Makefile.in
-nbplkup
-nbprgstr
-nbpunrgstr
-.deps
-.libs
-.gitignore
-nbplkup.o nbprgstr.o nbpunrgstr.o
diff --git a/bin/nbp/Makefile.am b/bin/nbp/Makefile.am
deleted file mode 100644 (file)
index c369c1e..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-# Makefile.am for bin/nbp/
-
-INCLUDES = -I$(top_srcdir)/include -I$(top_srcdir)/sys
-
-bin_PROGRAMS = nbplkup nbprgstr nbpunrgstr
-
-nbplkup_SOURCES = nbplkup.c
-nbplkup_LDADD = $(top_builddir)/libatalk/libatalk.la
-
-nbprgstr_SOURCES = nbprgstr.c
-nbprgstr_LDADD = $(top_builddir)/libatalk/libatalk.la
-
-nbpunrgstr_SOURCES = nbpunrgstr.c
-nbpunrgstr_LDADD = $(top_builddir)/libatalk/libatalk.la
diff --git a/bin/nbp/nbplkup.c b/bin/nbp/nbplkup.c
deleted file mode 100644 (file)
index a43ac41..0000000
+++ /dev/null
@@ -1,187 +0,0 @@
-/*
- * $Id: nbplkup.c,v 1.9 2009-10-29 11:35:57 didg Exp $
- *
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- * All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software and
- * its documentation for any purpose and without fee is hereby granted,
- * provided that the above copyright notice appears in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation, and that the name of The University
- * of Michigan not be used in advertising or publicity pertaining to
- * distribution of the software without specific, written prior
- * permission. This software is supplied as is without expressed or
- * implied warranties of any kind.
- *
- *     Research Systems Unix Group
- *     The University of Michigan
- *     c/o Mike Clark
- *     535 W. William Street
- *     Ann Arbor, Michigan
- *     +1-313-763-0525
- *     netatalk@itd.umich.edu
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <sys/types.h>
-#include <netatalk/endian.h>
-#include <netatalk/at.h>
-#include <atalk/nbp.h>
-#include <atalk/util.h>
-#include <string.h>
-#include <stdio.h>
-#ifdef HAVE_STDLIB_H
-#include <stdlib.h>
-#endif
-
-
-#include <atalk/unicode.h>
-
-static char *Obj = "=";
-static char *Type = "=";
-static char *Zone = "*";
-
-static void Usage(char *av0)
-{
-    char       *p;
-
-    if (( p = strrchr( av0, '/' )) == NULL ) {
-       p = av0;
-    } else {
-       p++;
-    }
-
-    printf( "Usage:\t%s [ -A address ] [ -r responses] [-m Mac charset] [ obj:type@zone ]\n", p );
-    exit( 1 );
-}
-
-int main(int ac, char **av)
-{
-    struct nbpnve      *nn;
-    char               *name;
-    int                        i, c, nresp = 1000;
-    struct at_addr      addr;
-    char               *obj = NULL;
-    size_t             obj_len;
-    charset_t          chMac = CH_MAC;
-    char *             convname;
-
-    extern char                *optarg;
-    extern int         optind;
-
-    memset(&addr, 0, sizeof(addr));
-    while (( c = getopt( ac, av, "r:A:m:" )) != EOF ) {
-       switch ( c ) {
-       case 'A':
-           if (!atalk_aton(optarg, &addr)) {
-               fprintf(stderr, "Bad address.\n");
-               exit(1);
-           }
-           break;
-       case 'r' :
-           nresp = atoi( optarg );
-           break;
-        case 'm':
-            if ((charset_t)-1 == (chMac = add_charset(optarg)) ) {
-               fprintf(stderr, "Invalid Mac charset.\n");
-               exit(1);
-           }
-            break;
-
-       default :
-           Usage( av[ 0 ] );
-           exit( 1 );
-       }
-    }
-
-    if (( nn = (struct nbpnve *)malloc( nresp * sizeof( struct nbpnve )))
-           == NULL ) {
-       perror( "malloc" );
-       exit( 1 );
-    }
-
-    if ( ac - optind > 1 ) {
-       Usage( av[ 0 ] );
-       exit( 1 );
-    }
-
-    /*
-     * Get default values from the environment. We need to copy out
-     * the results, here, since nbp_name returns it's parameters
-     * in static space, and we'll clobber them when we call it again
-     * later.
-     */
-    if (( name = getenv( "NBPLKUP" )) != NULL ) {
-       if ( nbp_name( name, &Obj, &Type, &Zone )) {
-           fprintf( stderr,
-                   "Environment variable syntax error: NBPLKUP = %s\n",
-                   name );
-           exit( 1 );
-       }
-
-       if (( name = (char *)malloc( strlen( Obj ) + 1 )) == NULL ) {
-           perror( "malloc" );
-           exit( 1 );
-       }
-       strcpy( name, Obj );
-       Obj = name;
-
-       if (( name = (char *)malloc( strlen( Type ) + 1 )) == NULL ) {
-           perror( "malloc" );
-           exit( 1 );
-       }
-       strcpy( name, Type );
-       Type = name;
-
-       if (( name = (char *)malloc( strlen( Zone ) + 1 )) == NULL ) {
-           perror( "malloc" );
-           exit( 1 );
-       }
-       strcpy( name, Zone );
-       Zone = name;
-
-    }
-
-    if ( ac - optind == 1 ) {
-       if ((size_t)(-1) == convert_string_allocate( CH_UNIX, chMac,
-                           av[ optind ], -1, &convname))
-            convname = av[ optind ];
-
-       if ( nbp_name( convname, &Obj, &Type, &Zone )) {
-           Usage( av[ 0 ] );
-           exit( 1 );
-       }
-    }
-
-    if (( c = nbp_lookup( Obj, Type, Zone, nn, nresp, &addr)) < 0 ) {
-       perror( "nbp_lookup" );
-       exit( -1 );
-    }
-    for ( i = 0; i < c; i++ ) {
-       
-       if ((size_t)(-1) == (obj_len = convert_string_allocate( chMac, 
-                       CH_UNIX, nn[ i ].nn_obj, nn[ i ].nn_objlen, &obj)) ) {
-            obj_len = nn[ i ].nn_objlen;
-            if (( obj = strdup(nn[ i ].nn_obj)) == NULL ) {
-               perror( "strdup" );
-               exit( 1 );
-           }
-        }
-
-       printf( "%31.*s:%-34.*s %u.%u:%u\n",
-               (int)obj_len, obj,
-               nn[ i ].nn_typelen, nn[ i ].nn_type,
-               ntohs( nn[ i ].nn_sat.sat_addr.s_net ),
-               nn[ i ].nn_sat.sat_addr.s_node,
-               nn[ i ].nn_sat.sat_port );
-
-       free(obj);
-    }
-
-    free(nn);
-    return 0;
-}
diff --git a/bin/nbp/nbprgstr.c b/bin/nbp/nbprgstr.c
deleted file mode 100644 (file)
index bef33a1..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * $Id: nbprgstr.c,v 1.9 2009-10-29 11:35:58 didg Exp $
- *
- * Copyright (c) 1990,1993 Regents of The University of Michigan.
- * All Rights Reserved.  See COPYRIGHT.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/param.h>
-
-#include <netatalk/endian.h>
-#include <netatalk/at.h>
-#include <atalk/netddp.h>
-#include <atalk/nbp.h>
-#include <atalk/util.h>
-#include <atalk/unicode.h>
-
-static void Usage(char *av0)
-{
-    char       *p;
-
-    if (( p = strrchr( av0, '/' )) == NULL ) {
-       p = av0;
-    } else {
-       p++;
-    }
-
-    fprintf( stderr, "Usage: %s [ -A address ] [-m Mac charset] [ -p port] obj:type@zone\n", p );
-    exit( 1 );
-}
-
-int main(int ac, char **av)
-{
-    struct sockaddr_at addr;
-    struct at_addr      ataddr;
-    char               *Obj = NULL, *Type = NULL, *Zone = NULL;
-    char               *convname = NULL;
-    int                        s, c, port = 0;
-    charset_t          chMac = CH_MAC;
-    
-    extern char                *optarg;
-    extern int         optind;
-
-    memset(&ataddr, 0, sizeof(ataddr));
-    while (( c = getopt( ac, av, "p:A:m:" )) != EOF ) {
-       switch ( c ) {
-       case 'A':
-           if (!atalk_aton(optarg, &ataddr)) {
-               fprintf(stderr, "Bad address.\n");
-               exit(1);
-           }
-           break;
-
-        case 'm':
-            if ((charset_t)-1 == (chMac = add_charset(optarg)) ) {
-                fprintf(stderr, "Invalid Mac charset.\n");
-                exit(1);
-            }
-            break;
-
-       case 'p' :
-           port = atoi( optarg );
-           break;
-
-       default :
-           Usage( av[ 0 ] );
-       }
-    }
-
-    if ( ac - optind != 1 ) {
-       Usage( av[ 0 ] );
-    }
-
-    /* Convert the name */
-    if ((size_t)(-1) == convert_string_allocate(CH_UNIX, chMac,
-                        av[optind], -1, &convname))
-        convname = av[optind];
-
-    /*
-     * Get the name. If Type or Obj aren't specified, error.
-     */
-    if ( nbp_name( convname, &Obj, &Type, &Zone ) || !Obj || !Type ) {
-       Usage( av[ 0 ] );
-    }
-
-    memset(&addr, 0, sizeof(addr));
-    memcpy(&addr.sat_addr, &ataddr, sizeof(addr.sat_addr));
-    if ((s = netddp_open(&addr, NULL)) < 0)
-       return( -1 );
-
-    if ( port ) {
-       addr.sat_port = port;
-    }
-
-    if ( nbp_rgstr( &addr, Obj, Type, Zone ) < 0 ) {
-       perror( "nbp_rgstr" );
-       fprintf( stderr, "Can't register %s:%s@%s\n", Obj, Type,
-               Zone ? Zone : "*" );
-       exit( 1 );
-    }
-    netddp_close(s);
-
-    return 0;
-}
diff --git a/bin/nbp/nbpunrgstr.c b/bin/nbp/nbpunrgstr.c
deleted file mode 100644 (file)
index a4a9465..0000000
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * $Id: nbpunrgstr.c,v 1.10 2009-10-29 11:35:58 didg Exp $
- *
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- * All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software and
- * its documentation for any purpose and without fee is hereby granted,
- * provided that the above copyright notice appears in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation, and that the name of The University
- * of Michigan not be used in advertising or publicity pertaining to
- * distribution of the software without specific, written prior
- * permission. This software is supplied as is without expressed or
- * implied warranties of any kind.
- *
- *     Research Systems Unix Group
- *     The University of Michigan
- *     c/o Mike Clark
- *     535 W. William Street
- *     Ann Arbor, Michigan
- *     +1-313-763-0525
- *     netatalk@itd.umich.edu
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <sys/types.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
-#include <netatalk/endian.h>
-#include <netatalk/at.h>
-#include <atalk/util.h>
-#include <atalk/nbp.h>
-
-#include <atalk/unicode.h>
-
-static void Usage(char *av0)
-{
-    char       *p;
-
-    if (( p = strrchr( av0, '/' )) == NULL ) {
-       p = av0;
-    } else {
-       p++;
-    }
-
-    fprintf( stderr, "Usage: %s [ -A address ] [ -m Mac charset] obj:type@zone\n", p );
-    exit( 1 );
-}
-
-int main(int ac, char **av)
-{
-    char               *Obj = NULL, *Type = NULL, *Zone = NULL;
-    char               *convname = NULL;
-    struct at_addr      addr;
-    int                 c;
-    charset_t          chMac = CH_MAC;
-
-    extern char                *optarg;
-    extern int         optind;
-    
-    memset(&addr, 0, sizeof(addr));
-    while ((c = getopt(ac, av, "A:m:")) != EOF) {
-      switch (c) {
-      case 'A':
-       if (!atalk_aton(optarg, &addr)) {
-         fprintf(stderr, "Bad address.\n");
-         exit(1);
-       }
-       break;
-      case 'm':
-        if ((charset_t)-1 == (chMac = add_charset(optarg)) ) {
-          fprintf(stderr, "Invalid Mac charset.\n");
-          exit(1);
-        }
-        break;
-
-      default:
-       Usage(av[0]);
-       break;
-      }
-    }
-
-    if (ac - optind != 1) {
-       Usage( av[ 0 ] );
-    }
-
-    /* Convert the name */
-    if ((size_t)(-1) == convert_string_allocate(CH_UNIX, chMac, 
-                        av[optind], -1, &convname))
-        convname = av[optind]; 
-
-    /*
-     * Get the name. If Type or Obj aren't specified, error.
-     */
-    if ( nbp_name( convname, &Obj, &Type, &Zone ) || !Obj || !Type ) {
-       Usage( av[ 0 ] );
-    }
-
-    if ( nbp_unrgstr( Obj, Type, Zone, &addr ) < 0 ) {
-       fprintf( stderr, "Can't unregister %s:%s@%s\n", Obj, Type,
-               Zone ? Zone : "*" );
-       exit( 1 );
-    }
-
-    return 0;
-}
diff --git a/bin/pap/.gitignore b/bin/pap/.gitignore
deleted file mode 100644 (file)
index 850951f..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-Makefile
-Makefile.in
-pap
-papstatus
-.deps
-.libs
-.gitignore
-pap.o papstatus.o
diff --git a/bin/pap/Makefile.am b/bin/pap/Makefile.am
deleted file mode 100644 (file)
index 344cf72..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-# Makefile.am for bin/pap/
-
-INCLUDES = -I$(top_srcdir)/include -I$(top_srcdir)/sys
-
-bin_PROGRAMS = pap papstatus
-
-pap_SOURCES = pap.c
-pap_LDADD = $(top_builddir)/libatalk/libatalk.la
-
-papstatus_SOURCES = papstatus.c
-papstatus_LDADD = $(top_builddir)/libatalk/libatalk.la
diff --git a/bin/pap/pap.c b/bin/pap/pap.c
deleted file mode 100644 (file)
index a8c97ad..0000000
+++ /dev/null
@@ -1,870 +0,0 @@
-/*
- * $Id: pap.c,v 1.14 2009-10-16 01:10:59 didg Exp $
- *
- * Copyright (c) 1990,1994 Regents of The University of Michigan.
- * All Rights Reserved.  See COPYRIGHT.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/uio.h>
-#include <netatalk/endian.h>
-#include <netatalk/at.h>
-#include <errno.h>
-#include <atalk/atp.h>
-#include <atalk/pap.h>
-#include <atalk/nbp.h>
-#include <atalk/util.h>
-#ifdef HAVE_FCNTL_H
-#include <fcntl.h>
-#endif /* HAVE_FCNTL_H */
-#include <stdio.h>
-#include <string.h>
-#include <string.h>
-#include <stdlib.h>
-
-#define FUCKED
-
-#define _PATH_PAPRC    ".paprc"
-
-/* Forward Declarations */
-static void updatestatus(char *s, int len);
-static int send_file(int fd, ATP atp, int lastfile);
-
-static void usage(char *path)
-{
-    char       *p;
-
-    if (( p = strrchr( path, '/' )) == NULL ) {
-       p = path;
-    } else {
-       p++;
-    }
-    fprintf( stderr,
-       "Usage:\t%s [ -A address ] [ -c ] [ -d ] [ -e ] [ -E ] [ -p printer ]\n"
-       "    [ -s statusfile ] [ -w ] [ -W ] [ FILES ]\n"
-       "  -A address    - printer Appletalk address\n"
-       "  -c            - take cuts (lie about wait time)\n"
-       "  -d            - enable debug\n"
-       "  -e            - send stdout to stderr\n"
-       "  -E            - don't wait for EOF from printer\n"
-       "  -p printer    - printer name\n"
-       "  -s statusfile - put current printer status in statusfile\n"
-       "  -w            - wait for printer status = 'waiting'\n"
-       "  -W            - wait for printer status = 'idle'\n"
-       "  FILES         - send FILES to printer\n"
-       , p );
-    exit( 2 );
-}
-
-static char *
-paprc(void)
-{
-    static char        s[ 32 + 1 + 32 + 1 + 32 ];
-    char       *name = NULL;
-    FILE       *f;
-
-    if (( f = fopen( _PATH_PAPRC, "r" )) == NULL ) {
-       if ( errno == ENOENT ) {
-           return( NULL );
-       } else {
-           perror( _PATH_PAPRC );
-           exit( 2 );
-       }
-    }
-    while ( fgets( s, sizeof( s ), f ) != NULL ) {
-       s[ strlen( s ) - 1 ] = '\0';    /* remove trailing newline */
-       if ( *s == '#' ) {
-           continue;
-       }
-       name = s;
-       break;
-    }
-    fclose( f );
-    return( name );
-}
-
-static char                    *printer = NULL;
-static char                    *status = NULL;
-static int                     noeof = 0;
-static int                     waitforprinter = 0;
-
-static unsigned char           connid, quantum, oquantum = PAP_MAXQUANTUM;
-static struct sockaddr_at      sat;
-
-static char                    cbuf[ 8 ];
-static struct nbpnve           nn;
-static ATP                     satp;
-
-static char            fbuf[ PAP_MAXQUANTUM ][ 4 + PAP_MAXDATA ];
-static struct iovec    rfiov[ PAP_MAXQUANTUM ] = {
-    { fbuf[ 0 ] + 4,   0 },
-    { fbuf[ 1 ] + 4,   0 },
-    { fbuf[ 2 ] + 4,   0 },
-    { fbuf[ 3 ] + 4,   0 },
-    { fbuf[ 4 ] + 4,   0 },
-    { fbuf[ 5 ] + 4,   0 },
-    { fbuf[ 6 ] + 4,   0 },
-    { fbuf[ 7 ] + 4,   0 },
-};
-
-static struct iovec    sniov[ PAP_MAXQUANTUM ] = {
-    { fbuf[ 0 ],       0 },
-    { fbuf[ 1 ],       0 },
-    { fbuf[ 2 ],       0 },
-    { fbuf[ 3 ],       0 },
-    { fbuf[ 4 ],       0 },
-    { fbuf[ 5 ],       0 },
-    { fbuf[ 6 ],       0 },
-    { fbuf[ 7 ],       0 },
-};
-
-static char            nbuf[ PAP_MAXQUANTUM ][ 4 + PAP_MAXDATA ];
-static struct iovec    rniov[ PAP_MAXQUANTUM ] = {
-    { nbuf[ 0 ],       0 },
-    { nbuf[ 1 ],       0 },
-    { nbuf[ 2 ],       0 },
-    { nbuf[ 3 ],       0 },
-    { nbuf[ 4 ],       0 },
-    { nbuf[ 5 ],       0 },
-    { nbuf[ 6 ],       0 },
-    { nbuf[ 7 ],       0 },
-};
-
-static struct iovec    sfiov[ PAP_MAXQUANTUM ] = {
-    { nbuf[ 0 ] + 4,   0 },
-    { nbuf[ 1 ] + 4,   0 },
-    { nbuf[ 2 ] + 4,   0 },
-    { nbuf[ 3 ] + 4,   0 },
-    { nbuf[ 4 ] + 4,   0 },
-    { nbuf[ 5 ] + 4,   0 },
-    { nbuf[ 6 ] + 4,   0 },
-    { nbuf[ 7 ] + 4,   0 },
-};
-
-static int debug;
-
-int main( int ac, char **av)
-{
-    ATP                        atp;
-    struct atp_block   atpb;
-    int                        c, err = 0, fd, cuts = 0;
-    char               *obj = NULL, *type = "LaserWriter", *zone = "*";
-    struct timeval     stv, tv;
-    char               rbuf[ ATP_MAXDATA ];
-    struct iovec       iov;
-    unsigned short     waiting, result;
-    int                        connattempts = 10;
-    int                        waitforidle = 0;
-    struct at_addr      addr;
-
-    extern char                *optarg;
-    extern int         optind;
-
-    memset(&addr, 0, sizeof(addr));
-    while (( c = getopt( ac, av, "dWwcep:s:EA:" )) != EOF ) {
-       switch ( c ) {
-#ifdef FUCKED
-       case 'w' :
-           waitforprinter = 1;
-           break;
-
-       case 'W' :
-           waitforidle = 1;
-           break;
-#endif /* FUCKED */
-
-       /* enable debugging */
-       case 'd' :
-           debug++;
-           break;
-
-       case 'c' :
-           cuts++;
-           break;
-
-       case 'e' :      /* send stdout to stderr */
-           dup2( 2, 1 );
-           break;
-
-       case 'p' :
-           printer = optarg;
-           break;
-
-       case 's' :
-           status = optarg;
-           break;
-
-       case 'E' :
-           noeof = 1;
-           break;
-          
-       case 'A':
-           if (!atalk_aton(optarg, &addr)) {
-             fprintf(stderr, "Bad address.\n");
-             exit(1);
-           }
-           break;
-
-       default :
-           err++;
-       }
-    }
-    if ( err ) {
-       usage( *av );
-    }
-    if ( printer == NULL && (( printer = paprc()) == NULL )) {
-       fprintf( stderr, "No printer specified and ./.paprc not found.\n" );
-       exit( 2 );
-    }
-
-    /*
-     * Open connection.
-     */
-    if ( nbp_name( printer, &obj, &type, &zone ) < 0 ) {
-       fprintf( stderr, "%s: Bad name\n", printer );
-       exit( 2 );
-    }
-    if ( obj == NULL ) {
-       fprintf( stderr, "%s: Bad name\n", printer );
-       exit( 2 );
-    }
-
-    if ( nbp_lookup( obj, type, zone, &nn, 1, &addr ) <= 0 ) {
-       if ( errno != 0 ) {
-           perror( "nbp_lookup" );
-           exit( 2 );
-       }
-       fprintf( stderr, "%s:%s@%s: NBP Lookup failed\n", obj, type, zone );
-       exit( 1 );
-    }
-
-    if ( isatty( 1 )) {
-       printf( "Trying %u.%d:%d ...\n", ntohs( nn.nn_sat.sat_addr.s_net ),
-               nn.nn_sat.sat_addr.s_node, nn.nn_sat.sat_port );
-    }
-
-    if (( atp = atp_open( ATADDR_ANYPORT, &addr )) == NULL ) {
-       perror( "atp_open" );
-       exit( 2 );
-    }
-    if (( satp = atp_open( ATADDR_ANYPORT, &addr )) == NULL ) {
-       perror( "atp_open" );
-       exit( 2 );
-    }
-
-    while ( waitforidle ) {
-       char    st_buf[ 1024 ]; /* XXX too big */
-
-       cbuf[ 0 ] = 0;
-       cbuf[ 1 ] = PAP_SENDSTATUS;
-       cbuf[ 2 ] = cbuf[ 3 ] = 0;
-       atpb.atp_saddr = &nn.nn_sat;
-       atpb.atp_sreqdata = cbuf;
-       atpb.atp_sreqdlen = 4;  /* bytes in SendStatus request */
-       atpb.atp_sreqto = 2;            /* retry timer */
-       atpb.atp_sreqtries = 5;         /* retry count */
-       if ( atp_sreq( satp, &atpb, 1, 0 ) < 0 ) {
-           perror( "atp_sreq" );
-           exit( 1 );
-       }
-
-       if(debug){ printf( "SENDSTATUS >\n" ), fflush( stdout );}
-
-       atpb.atp_saddr = &nn.nn_sat;
-       rniov[ 0 ].iov_len = PAP_MAXDATA + 4;
-       atpb.atp_rresiov = rniov;
-       atpb.atp_rresiovcnt = 1;
-       if ( atp_rresp( satp, &atpb ) < 0 ) {
-           perror( "atp_rresp" );
-           continue;
-       }
-
-#ifndef NONZEROSTATUS
-       /*
-        * The stinking LaserWriter IINTX puts crap in this
-        * field.
-        */
-       if ( ((char *)rniov[ 0 ].iov_base)[ 0 ] != 0 ) {
-           fprintf( stderr, "Bad status response!\n" );
-           exit( 1 );
-       }
-#endif /* NONZEROSTATUS */
-
-       if ( ((char *)rniov[ 0 ].iov_base)[ 1 ] != PAP_STATUS ||
-               atpb.atp_rresiovcnt != 1 ) {
-           fprintf( stderr, "Bad status response!\n" );
-           exit( 1 );
-       }
-
-       if(debug){ printf( "< STATUS\n" ), fflush( stdout );}
-
-       memcpy( st_buf, (char *) rniov[ 0 ].iov_base + 9, 
-               ((char *)rniov[ 0 ].iov_base)[ 8 ] );
-       st_buf[ (int) ((char *)rniov[ 0 ].iov_base)[ 8 ]] = '\0';
-       if ( strstr( st_buf, "idle" ) != NULL ) {
-           waitforidle = 0;
-       } else {
-           updatestatus( (char *) rniov[ 0 ].iov_base + 9,
-                   ((char *)rniov[ 0 ].iov_base)[ 8 ] );
-           sleep( 5 );
-       }
-    }
-
-    cbuf[ 0 ] = connid = getpid() & 0xff;
-    cbuf[ 1 ] = PAP_OPEN;
-    cbuf[ 2 ] = cbuf[ 3 ] = 0;
-    cbuf[ 4 ] = atp_sockaddr( atp )->sat_port;
-    cbuf[ 5 ] = oquantum;      /* flow quantum */
-    if ( gettimeofday( &stv, NULL ) < 0 ) {
-       perror( "gettimeofday" );
-       exit( 2 );
-    }
-    for (;;) {
-       if ( cuts ) {
-           waiting = 0xffff;
-       } else {
-           if ( gettimeofday( &tv, NULL ) < 0 ) {
-               perror( "gettimeofday" );
-               exit( 2 );
-           }
-           waiting = htons( tv.tv_sec - stv.tv_sec );
-       }
-       memcpy(cbuf +  6, &waiting, sizeof( waiting ));
-
-       atpb.atp_saddr = &nn.nn_sat;
-       atpb.atp_sreqdata = cbuf;
-       atpb.atp_sreqdlen = 8;          /* bytes in OpenConn request */
-       atpb.atp_sreqto = 2;            /* retry timer */
-       atpb.atp_sreqtries = 5;         /* retry count */
-       if ( atp_sreq( atp, &atpb, 1, ATP_XO ) < 0 ) {
-           perror( "atp_sreq" );
-           exit( 1 );
-       }
-
-       if(debug){ printf( "OPEN >\n" ), fflush( stdout );}
-
-       iov.iov_base = rbuf;
-       iov.iov_len = sizeof( rbuf );
-       atpb.atp_rresiov = &iov;
-       atpb.atp_rresiovcnt = 1;
-       if ( atp_rresp( atp, &atpb ) < 0 ) {
-           perror( "atp_rresp" );
-           if ( connattempts-- <= 0 ) {
-               fprintf( stderr, "Can't connect!\n" );
-               exit( 1 );
-           }
-           continue;
-       }
-
-       /* sanity */
-       if ( iov.iov_len < 8 || (unsigned char)rbuf[ 0 ] != connid ||
-               rbuf[ 1 ] != PAP_OPENREPLY ) {
-           fprintf( stderr, "Bad response!\n" );
-           continue;   /* This is weird, since TIDs must match... */
-       }
-
-       if(debug){ printf( "< OPENREPLY\n" ), fflush( stdout );}
-
-       if ( isatty( 1 )) {
-           printf( "%.*s\n", (int)iov.iov_len - 9, (char *) iov.iov_base + 9 );
-       }
-       updatestatus( (char *) iov.iov_base + 9, iov.iov_len - 9 );
-
-       memcpy( &result, rbuf +  6,  sizeof( result ));
-       if ( result != 0 ) {
-           sleep( 2 );
-       } else {
-           memcpy( &sat, &nn.nn_sat, sizeof( struct sockaddr_at ));
-           sat.sat_port = rbuf[ 4 ];
-           quantum = rbuf[ 5 ];
-           break;
-       }
-    }
-
-    if ( isatty( 1 )) {
-       printf( "Connected to %.*s:%.*s@%.*s.\n",
-               nn.nn_objlen, nn.nn_obj,
-               nn.nn_typelen, nn.nn_type,
-               nn.nn_zonelen, nn.nn_zone );
-    }
-
-    if ( optind == ac ) {
-       send_file( 0, atp, 1 );
-    } else {
-       for (; optind < ac; optind++ ) {
-           if ( strcmp( av[ optind ], "-" ) == 0 ) {
-               fd = 0;
-           } else if (( fd = open( av[ optind ], O_RDONLY )) < 0 ) {
-               perror( av[ optind ] );
-               continue;
-           }
-           send_file( fd, atp, ( optind == ac - 1 ) ? 1 : 0 );
-           if ( fd != 0 ) {
-               close( fd );
-           }
-       }
-    }
-
-    /*
-     * Close connection.
-     */
-    cbuf[ 0 ] = connid;
-    cbuf[ 1 ] = PAP_CLOSE;
-    cbuf[ 2 ] = cbuf[ 3 ] = 0;
-
-    atpb.atp_saddr = &sat;
-    atpb.atp_sreqdata = cbuf;
-    atpb.atp_sreqdlen = 4;             /* bytes in CloseConn request */
-    atpb.atp_sreqto = 2;               /* retry timer */
-    atpb.atp_sreqtries = 5;            /* retry count */
-    if ( atp_sreq( atp, &atpb, 1, ATP_XO ) < 0 ) {
-       perror( "atp_sreq" );
-       exit( 1 );
-    }
-
-       if(debug){ printf( "CLOSE >\n" ), fflush( stdout );}
-
-    iov.iov_base = rbuf;
-    iov.iov_len = sizeof( rbuf );
-    atpb.atp_rresiov = &iov;
-    atpb.atp_rresiovcnt = 1;
-    if ( atp_rresp( atp, &atpb ) < 0 ) {
-       perror( "atp_rresp" );
-       exit( 1 );
-    }
-
-    /* sanity */
-    if ( iov.iov_len != 4 || rbuf[ 1 ] != PAP_CLOSEREPLY ) {
-       fprintf( stderr, "Bad response!\n" );
-       exit( 1 );
-    }
-
-#ifndef ZEROCONNID
-    /*
-     * The AGFA Viper Rip doesn't have the connection id in the close request.
-     */
-    if ((unsigned char)rbuf[ 0 ] != connid ) {
-       fprintf( stderr, "Bad connid in close!\n" );
-       exit( 1 );
-    }
-#endif /* ZEROCONNID */
-
-       if(debug){ printf( "< CLOSEREPLY\n" ), fflush( stdout );}
-
-    if ( isatty( 1 )) {
-       printf( "Connection closed.\n" );
-    }
-    exit( 0 );
-}
-
-static int             data = 0;
-static unsigned char   port;
-static u_int16_t       seq = 0;
-
-static int send_file( int fd, ATP atp, int lastfile)
-{
-    struct timeval     stv, tv;
-    struct sockaddr_at ssat;
-    struct atp_block   atpb;
-    fd_set             fds;
-    int                        fiovcnt = 0, eof = 0, senteof = 0, to = 0;
-    int                        cc, i;
-    unsigned short     netseq;
-
-    if ( gettimeofday( &stv, NULL ) < 0 ) {
-       perror( "gettimeofday" );
-       exit( 2 );
-    }
-
-    /*
-     * Ask for more data.
-     */
-    cbuf[ 0 ] = connid;
-    cbuf[ 1 ] = PAP_READ;
-    if ( ++seq == 0 ) seq = 1;
-    netseq = htons( seq );
-    memcpy( cbuf +  2, &netseq, sizeof( netseq ));
-    atpb.atp_saddr = &sat;
-    atpb.atp_sreqdata = cbuf;
-    atpb.atp_sreqdlen = 4;             /* bytes in SendData request */
-    atpb.atp_sreqto = 15;              /* retry timer */
-    atpb.atp_sreqtries = -1;           /* retry count */
-    if ( atp_sreq( atp, &atpb, oquantum, ATP_XO ) < 0 ) {
-       perror( "atp_sreq" );
-       exit( 1 );
-    }
-
-       if(debug){ printf( "READ %d >\n", seq ), fflush( stdout );}
-
-    for (;;) {
-       if ( gettimeofday( &tv, NULL ) < 0 ) {
-           perror( "gettimeofday" );
-           exit( 2 );
-       }
-
-       if (( tv.tv_sec - stv.tv_sec ) >= 60 ) {
-           stv = tv;
-
-           /*
-            * Send a tickle.
-            */
-           cbuf[ 0 ] = connid;
-           cbuf[ 1 ] = PAP_TICKLE;
-           cbuf[ 2 ] = cbuf[ 3 ] = 0;
-           atpb.atp_saddr = &sat;
-           atpb.atp_sreqdata = cbuf;
-           atpb.atp_sreqdlen = 4;              /* bytes in Tickle request */
-           atpb.atp_sreqto = 0;                /* retry timer */
-           atpb.atp_sreqtries = 1;             /* retry count */
-           if ( atp_sreq( satp, &atpb, 0, 0 ) < 0 ) {
-               perror( "atp_sreq" );
-               exit( 1 );
-           }
-
-       if(debug){ printf( "TICKLE >\n" ), fflush( stdout );}
-       }
-
-       tv.tv_sec = stv.tv_sec + 60 - tv.tv_sec;
-       tv.tv_usec = 0;
-
-       FD_ZERO( &fds );
-       if ( !waitforprinter && !eof && fiovcnt == 0 ) {
-           FD_SET( fd, &fds );
-       }
-       FD_SET( atp_fileno( atp ), &fds );
-
-       if (( cc = select( FD_SETSIZE, &fds, NULL, NULL, &tv )) < 0 ) {
-           perror( "select" );
-           exit( 2 );
-       }
-
-       /*
-        * A timeout has occured. Keep track of it.
-        */
-       if ( cc == 0 ) {
-           if ( to++ > 2 ) {
-               fprintf( stderr, "Connection timed out.\n" );
-               exit( 1 );
-           }
-           continue;
-       }
-
-       /*
-        * Read data.
-        */
-       if ( !fiovcnt && FD_ISSET( fd, &fds )) {
-           for ( i = 0; i < quantum; i++ ) {
-               rfiov[ i ].iov_len = PAP_MAXDATA;
-           }
-           if (( cc = readv( fd, rfiov, quantum )) < 0 ) {
-               perror( "readv" );
-               exit( 2 );
-           }
-           if ( cc == 0 ) {
-               eof = 1;
-           }
-           fiovcnt = cc / PAP_MAXDATA + ( cc % PAP_MAXDATA > 0 );
-           for ( i = 0; cc > 0; i++ ) {
-               rfiov[ i ].iov_len = ( cc > PAP_MAXDATA ) ? PAP_MAXDATA : cc;
-               cc -= ( cc > PAP_MAXDATA ) ? PAP_MAXDATA : cc;
-           }
-       }
-
-       if ( FD_ISSET( atp_fileno( atp ), &fds )) {
-           ssat = sat;
-           ssat.sat_port = ATADDR_ANYPORT;
-           switch( atp_rsel( atp, &ssat, ATP_TRESP | ATP_TREQ )) {
-           case ATP_TREQ :
-               atpb.atp_saddr = &ssat;
-               atpb.atp_rreqdata = cbuf;
-               atpb.atp_rreqdlen = sizeof( cbuf );
-               if ( atp_rreq( atp, &atpb ) < 0 ) {
-                   perror( "atp_rreq" );
-                   exit( 1 );
-               }
-
-               if ( (unsigned char)cbuf[ 0 ] != connid ) {
-                   break;
-               }
-
-               /* reset timeout counter for all valid requests */
-               to = 0;
-
-               switch ( cbuf[ 1 ] ) {
-               case PAP_READ :
-                   memcpy( cbuf +  2, &netseq, sizeof( netseq ));
-       if(debug){ printf( "< READ %d\n", ntohs( netseq )), fflush( stdout );}
-#ifdef notdef
-                   if ( netseq != 0 ) {
-                       if ( rseq != ntohs( netseq )) {
-       if(debug){ printf( "| DUP %d\n", rseq ), fflush( stdout );}
-                           break;
-                       }
-                       if ( rseq++ == 0xffff ) rseq = 1;
-                   }
-#endif /* notdef */
-
-                   data = 1;
-                   port = ssat.sat_port;
-                   break;
-
-               case PAP_CLOSE :
-
-       if(debug){ printf( "< CLOSE\n" ), fflush( stdout );}
-
-                   /*
-                    * Respond to the close request, and fail.
-                    */
-                   sniov[ 0 ].iov_len = 4;
-                   ((char *)sniov[ 0 ].iov_base)[ 0 ] = connid;
-                   ((char *)sniov[ 0 ].iov_base)[ 1 ] = PAP_CLOSEREPLY;
-                   ((char *)sniov[ 0 ].iov_base)[ 2 ] =
-                           ((char *)sniov[ 0 ].iov_base)[ 3 ] = 0;
-                   atpb.atp_sresiov = sniov;
-                   atpb.atp_sresiovcnt = 1;
-                   if ( atp_sresp( atp, &atpb ) < 0 ) {
-                       perror( "atp_sresp" );
-                       exit( 1 );
-                   }
-
-       if(debug){ printf( "CLOSEREPLY >\n" ), fflush( stdout );}
-
-                   fprintf( stderr, "Connection closed by foreign host.\n" );
-                   exit( 1 );
-
-               case PAP_TICKLE :
-
-       if(debug){ printf( "< TICKLE\n" ), fflush( stdout );}
-
-                   break;
-               default :
-                   fprintf( stderr, "Bad PAP request!\n" );
-                   exit( 1 );
-               }
-               break;
-
-           case ATP_TRESP :
-               /* reset timeout counter for all valid requests */
-               to = 0;
-
-               atpb.atp_saddr = &ssat;
-               for ( i = 0; i < oquantum; i++ ) {
-                   rniov[ i ].iov_len = PAP_MAXDATA + 4;
-               }
-               atpb.atp_rresiov = rniov;
-               atpb.atp_rresiovcnt = oquantum;
-               if ( atp_rresp( atp, &atpb ) < 0 ) {
-                   perror( "atp_rresp" );
-                   exit( 1 );
-               }
-
-#ifndef ZEROCONNID
-               /*
-                * The HP LJIIISI w/ BridgePort LocalTalk card sends
-                * zero instead of the connid.
-                */
-               if ( ((unsigned char *)rniov[ 0 ].iov_base)[ 0 ] != connid ) {
-                   fprintf( stderr, "Bad data response!\n" );
-                   exit( 1 );
-               }
-#endif /* ZEROCONNID */
-               if ( ((char *)rniov[ 0 ].iov_base)[ 1 ] != PAP_DATA ) {
-                   fprintf( stderr, "Bad data response!\n" );
-                   exit( 1 );
-               }
-
-               for ( cc = 0, i = 0; i < atpb.atp_rresiovcnt; i++ ) {
-                   sfiov[ i ].iov_len = rniov[ i ].iov_len - 4;
-                   cc += sfiov[ i ].iov_len;
-               }
-               if ( cc && writev( 1, sfiov, atpb.atp_rresiovcnt ) < cc ) {
-                   perror( "writev" );
-                   exit( 2 );
-               }
-
-               /* eof */
-               if ( ((char *)rniov[ 0 ].iov_base)[ 2 ] ) {
-
-       if(debug){ printf( "< DATA (eof)\n" ), fflush( stdout );}
-
-                   return( 0 );
-               }
-
-       if(debug){ printf( "< DATA\n" ), fflush( stdout );}
-
-
-               /*
-                * Ask for more data.
-                */
-               cbuf[ 0 ] = connid;
-               cbuf[ 1 ] = PAP_READ;
-               if ( ++seq == 0 ) seq = 1;
-               netseq = htons( seq );
-               memcpy( cbuf +  2, &netseq, sizeof( netseq ));
-               atpb.atp_saddr = &sat;
-               atpb.atp_sreqdata = cbuf;
-               atpb.atp_sreqdlen = 4;          /* bytes in SendData request */
-               atpb.atp_sreqto = 15;           /* retry timer */
-               atpb.atp_sreqtries = -1;        /* retry count */
-               if ( atp_sreq( atp, &atpb, oquantum, ATP_XO ) < 0 ) {
-                   perror( "atp_sreq" );
-                   exit( 1 );
-               }
-
-       if(debug){ printf( "READ %d >\n", seq ), fflush( stdout );}
-
-               break;
-
-           case 0:
-
-       if(debug){ printf( "| RETRANS\n" ), fflush( stdout );}
-
-               break;
-
-           default:
-               perror( "atp_rsel" );
-               exit( 1 );
-           }
-       }
-
-       /*
-        * Send whatever is pending.
-        */
-       if ( !waitforprinter && !senteof && data && ( fiovcnt || eof )) {
-           ssat.sat_port = port;
-           atpb.atp_saddr = &ssat;
-           if ( fiovcnt ) {
-               for ( i = 0; i < fiovcnt; i++ ) {
-                   sniov[ i ].iov_len = rfiov[ i ].iov_len + 4;
-                   ((char *)sniov[ i ].iov_base)[ 0 ] = connid;
-                   ((char *)sniov[ i ].iov_base)[ 1 ] = PAP_DATA;
-                   senteof = ((char *)sniov[ i ].iov_base)[ 2 ] = eof;
-                   ((char *)sniov[ i ].iov_base)[ 3 ] = 0;
-               }
-           } else {
-               sniov[ 0 ].iov_len = 4;
-               ((char *)sniov[ 0 ].iov_base)[ 0 ] = connid;
-               ((char *)sniov[ 0 ].iov_base)[ 1 ] = PAP_DATA;
-               senteof = ((char *)sniov[ 0 ].iov_base)[ 2 ] = eof;
-               ((char *)sniov[ 0 ].iov_base)[ 3 ] = 0;
-           }
-           atpb.atp_sresiov = sniov;
-           atpb.atp_sresiovcnt = fiovcnt ? fiovcnt : 1;
-           if ( atp_sresp( atp, &atpb ) < 0 ) {
-               perror( "atp_sresp" );
-               exit( 1 );
-           }
-           data = fiovcnt = 0;
-
-       if(debug){ printf( "DATA %s\n", eof ? "(eof) >" : ">" ), fflush( stdout );}
-
-           /*
-            * The Apple LaserWriter IIf, the HP LWIIISi, and IV, don't
-            * seem to send us an EOF on large jobs.  To work around
-            * this heinous protocol violation, we won't wait for their
-            * EOF before closing.
-            */
-           if ( eof && noeof && lastfile ) {
-               return( 0 );
-           }
-       } else {
-           /*
-            * If we can't send data right now, go ahead and get the
-            * status. This is cool, because we get here reliably
-            * if there is a problem.
-            */
-           cbuf[ 0 ] = 0;
-           cbuf[ 1 ] = PAP_SENDSTATUS;
-           cbuf[ 2 ] = cbuf[ 3 ] = 0;
-           atpb.atp_saddr = &nn.nn_sat;
-           atpb.atp_sreqdata = cbuf;
-           atpb.atp_sreqdlen = 4;      /* bytes in SendStatus request */
-           atpb.atp_sreqto = 2;                /* retry timer */
-           atpb.atp_sreqtries = 5;             /* retry count */
-           if ( atp_sreq( satp, &atpb, 1, 0 ) < 0 ) {
-               perror( "atp_sreq" );
-               exit( 1 );
-           }
-
-       if(debug){ printf( "SENDSTATUS >\n" ), fflush( stdout );}
-
-           atpb.atp_saddr = &nn.nn_sat;
-           rniov[ 0 ].iov_len = PAP_MAXDATA + 4;
-           atpb.atp_rresiov = rniov;
-           atpb.atp_rresiovcnt = 1;
-           if ( atp_rresp( satp, &atpb ) < 0 ) {
-               perror( "atp_rresp" );
-               continue;
-           }
-
-#ifndef NONZEROSTATUS
-           /*
-            * The stinking LaserWriter IINTX puts crap in this
-            * field.
-            */
-           if ( ((char *)rniov[ 0 ].iov_base)[ 0 ] != 0 ) {
-               fprintf( stderr, "Bad status response!\n" );
-               exit( 1 );
-           }
-#endif /* NONZEROSTATUS */
-
-           if ( ((char *)rniov[ 0 ].iov_base)[ 1 ] != PAP_STATUS ||
-                   atpb.atp_rresiovcnt != 1 ) {
-               fprintf( stderr, "Bad status response!\n" );
-               exit( 1 );
-           }
-
-       if(debug){ printf( "< STATUS\n" ), fflush( stdout );}
-
-#ifdef FUCKED
-           if ( waitforprinter ) {
-               char    st_buf[ 1024 ]; /* XXX too big */
-
-               memcpy( st_buf, (char *) rniov[ 0 ].iov_base + 9, 
-                       ((char *)rniov[ 0 ].iov_base)[ 8 ] );
-               st_buf[ (int) ((char *)rniov[ 0 ].iov_base)[ 8 ]] = '\0';
-               if ( strstr( st_buf, "waiting" ) != NULL ) {
-                   waitforprinter = 0;
-               }
-           }
-#endif /* FUCKED */
-
-           updatestatus( (char *) rniov[ 0 ].iov_base + 9,
-                   ((char *)rniov[ 0 ].iov_base)[ 8 ] );
-       }
-    }
-}
-
-static void updatestatus(char *s, int len)
-{
-    int                        fd = -1;
-    struct iovec       iov[ 3 ];
-
-    if ( status ) {
-       if (( fd = open( status, O_WRONLY|O_TRUNC )) < 0 ) {
-           perror( status );
-           status = NULL;
-       }
-    }
-
-    if ( fd < 0 ) {
-       fd = 2;
-    }
-
-    iov[ 0 ].iov_base = "%%[ ";
-    iov[ 0 ].iov_len = 4;
-    iov[ 1 ].iov_base = s;
-    iov[ 1 ].iov_len = len;
-    iov[ 2 ].iov_base = " ]%%\n";
-    iov[ 2 ].iov_len = 5;
-
-    writev( fd, iov, 3 );
-    if ( status ) {
-       close( fd );
-    }
-}
diff --git a/bin/pap/papstatus.c b/bin/pap/papstatus.c
deleted file mode 100644 (file)
index 0ada9c0..0000000
+++ /dev/null
@@ -1,204 +0,0 @@
-/*
- * $Id: papstatus.c,v 1.7 2009-10-14 01:38:28 didg Exp $
- *
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- * All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software and
- * its documentation for any purpose and without fee is hereby granted,
- * provided that the above copyright notice appears in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation, and that the name of The University
- * of Michigan not be used in advertising or publicity pertaining to
- * distribution of the software without specific, written prior
- * permission. This software is supplied as is without expressed or
- * implied warranties of any kind.
- *
- *     Research Systems Unix Group
- *     The University of Michigan
- *     c/o Mike Clark
- *     535 W. William Street
- *     Ann Arbor, Michigan
- *     +1-313-763-0525
- *     netatalk@itd.umich.edu
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/uio.h>
-#include <sys/file.h>
-#include <netatalk/endian.h>
-#include <netatalk/at.h>
-#include <errno.h>
-#include <atalk/atp.h>
-#include <atalk/pap.h>
-#include <atalk/nbp.h>
-#include <atalk/util.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#define _PATH_PAPRC    ".paprc"
-
-/* Forward Declaration */
-static void getstatus(ATP atp, struct sockaddr_at *sat);
-
-static void usage(char *path)
-{
-    char       *p;
-
-    if (( p = strrchr( path, '/' )) == NULL ) {
-       p = path;
-    } else {
-       p++;
-    }
-    fprintf( stderr,
-       "Usage:\t%s [ -A address ] [ -p printername ]\n", p );
-    exit( 1 );
-}
-
-static char *
-paprc(void)
-{
-    static char        s[ 32 + 1 + 32 + 1 + 32 ];
-    char       *name = NULL;
-    FILE       *f;
-
-    if (( f = fopen( _PATH_PAPRC, "r" )) == NULL ) {
-       return( NULL );
-    }
-    while ( fgets( s, sizeof( s ), f ) != NULL ) {
-       s[ strlen( s ) - 1 ] = '\0';    /* remove trailing newline */
-       if ( *s == '#' ) {
-           continue;
-       }
-       name = s;
-       break;
-    }
-    fclose( f );
-    return( name );
-}
-
-static char                    *printer = NULL;
-
-static char                    cbuf[ 8 ];
-static struct nbpnve           nn;
-
-int main( int ac, char **av)
-{
-    ATP                        atp;
-    int                        wait, c, err = 0;
-    char               *obj = NULL, *type = "LaserWriter", *zone = "*";
-    struct at_addr      addr;
-
-    extern char                *optarg;
-    extern int         optind;
-
-    memset(&addr, 0, sizeof(addr));
-    while (( c = getopt( ac, av, "p:s:A:" )) != EOF ) {
-       switch ( c ) {
-       case 'A':
-           if (!atalk_aton(optarg, &addr)) {
-             fprintf(stderr, "Bad address.\n");
-             exit(1);
-           }
-           break;
-       case 'p' :
-           printer = optarg;
-           break;
-
-       default :
-           fprintf( stderr, "Unknown option: '%c'\n", c );
-           err++;
-       }
-    }
-    if ( err ) {
-       usage( *av );
-    }
-    if ( printer == NULL && (( printer = paprc()) == NULL )) {
-       usage( *av );
-    }
-
-    /*
-     * Open connection.
-     */
-    if ( nbp_name( printer, &obj, &type, &zone ) < 0 ) {
-       fprintf( stderr, "%s: Bad name\n", printer );
-       exit( 1 );
-    }
-    if ( obj == NULL ) {
-       fprintf( stderr, "%s: Bad name\n", printer );
-       exit( 1 );
-    }
-    if ( nbp_lookup( obj, type, zone, &nn, 1, &addr ) <= 0 ) {
-       if ( errno != 0 ) {
-           perror( "nbp_lookup" );
-       } else {
-           fprintf( stderr, "%s:%s@%s: NBP Lookup failed\n", obj, type, zone );
-       }
-       exit( 1 );
-    }
-
-    if (( atp = atp_open( ATADDR_ANYPORT, &addr )) == NULL ) {
-       perror( "atp_open" );
-       exit( 1 );
-    }
-
-    if ( optind == ac ) {
-       getstatus( atp, &nn.nn_sat );
-       exit( 0 );
-    }
-    if ( optind - ac > 1 ) {
-       usage( *av );
-    }
-    wait = atoi( av[ optind ] );
-    for (;;) {
-       getstatus( atp, &nn.nn_sat );
-       sleep( wait );
-    }
-
-    return 0;
-}
-
-static void getstatus(ATP atp, struct sockaddr_at *sat)
-{
-    struct iovec       iov;
-    struct atp_block   atpb;
-    char               rbuf[ ATP_MAXDATA ];
-
-    cbuf[ 0 ] = 0;
-    cbuf[ 1 ] = PAP_SENDSTATUS;
-    cbuf[ 2 ] = cbuf[ 3 ] = 0;
-
-    atpb.atp_saddr = sat;
-    atpb.atp_sreqdata = cbuf;
-    atpb.atp_sreqdlen = 4;             /* bytes in SendStatus request */
-    atpb.atp_sreqto = 2;               /* retry timer */
-    atpb.atp_sreqtries = 5;            /* retry count */
-    if ( atp_sreq( atp, &atpb, 1, ATP_XO ) < 0 ) {
-       perror( "atp_sreq" );
-       exit( 1 );
-    }
-
-    iov.iov_base = rbuf;
-    iov.iov_len = sizeof( rbuf );
-    atpb.atp_rresiov = &iov;
-    atpb.atp_rresiovcnt = 1;
-    if ( atp_rresp( atp, &atpb ) < 0 ) {
-       perror( "atp_rresp" );
-       exit( 1 );
-    }
-
-    /* sanity */
-    if ( iov.iov_len < 8 ||
-           rbuf[ 1 ] != PAP_STATUS ) {
-       fprintf( stderr, "Bad response!\n" );
-       return; /* This is weird, since TIDs must match... */
-    }
-
-    printf( "%.*s\n", (int)iov.iov_len - 9, (char *) iov.iov_base + 9 );
-}
diff --git a/bin/psorder/.gitignore b/bin/psorder/.gitignore
deleted file mode 100644 (file)
index 379b39e..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-Makefile
-Makefile.in
-psorder
-.deps
-.libs
-.gitignore
-pa.o psorder.o
diff --git a/bin/psorder/Makefile.am b/bin/psorder/Makefile.am
deleted file mode 100644 (file)
index b54fa36..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-# Makefile.am for bin/psorder
-
-INCLUDES = -I$(top_srcdir)/include -I$(top_srcdir)/sys
-
-bin_PROGRAMS = psorder
-
-psorder_SOURCES = psorder.c pa.c
-psorder_LDADD = $(top_builddir)/libatalk/libatalk.la
-
-noinst_HEADERS = psorder.h pa.h
diff --git a/bin/psorder/pa.c b/bin/psorder/pa.c
deleted file mode 100644 (file)
index 8728065..0000000
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * $Id: pa.c,v 1.6 2009-10-14 02:24:05 didg Exp $
- *
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- * All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software and
- * its documentation for any purpose and without fee is hereby granted,
- * provided that the above copyright notice appears in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation, and that the name of The University
- * of Michigan not be used in advertising or publicity pertaining to
- * distribution of the software without specific, written prior
- * permission. This software is supplied as is without expressed or
- * implied warranties of any kind.
- *
- *     Research Systems Unix Group
- *     The University of Michigan
- *     c/o Mike Clark
- *     535 W. William Street
- *     Ann Arbor, Michigan
- *     +1-313-763-0525
- *     netatalk@itd.umich.edu
- */
-
-/* This is used with pa.h */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <stdlib.h>
-#include <string.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
-
-#include "pa.h"
-
-pa_buf_t *pa_init(int fd)
-{
-       pa_buf_t *h;
-       int rc;
-
-       h = (pa_buf_t *) malloc( sizeof( pa_buf_t ));
-       h->buf = (char *) malloc( PA_BUFBLK * 2 );
-       h->bufsz = PA_BUFBLK * 2;
-
-       if (( rc = read( fd, h->buf, PA_BUFBLK )) < 0 ) {
-               return( NULL );
-       }
-
-       h->cur = h->buf - 1;
-       h->end = h->buf + rc - 1;
-       h->state = PA_NORMAL;
-       h->fd = fd;
-
-       return( h );
-}
-
-char *pa_gettok(pa_buf_t *h)
-{
-       h->state = PA_NORMAL;
-       h->tmp = *(h->cur);
-       *(h->cur) = 0;
-       return( h->mark );
-}
-
-char _pa_fixbuf(pa_buf_t *h)
-{
-       int rc;
-       char *t;
-
-       if ( h->state == PA_NORMAL ) {
-               *(h->buf) = *(h->cur);
-               h->cur = h->buf;
-       } else {
-               bcopy( h->mark, h->buf, h->end - h->mark + 1 );
-               h->cur = h->buf + ( h->cur - h->mark );
-               h->end = h->buf + ( h->end - h->mark );
-               h->mark = h->buf;
-       }
-
-       if ( h->bufsz - (( h->cur - h->buf ) + 1 ) < PA_BUFBLK ) {
-               t = h->buf;
-               h->buf = (char *) realloc( h->buf, h->bufsz + PA_BUFBLK );
-               h->bufsz += PA_BUFBLK;
-               h->mark = h->buf + ( h->mark - t );
-               h->cur = h->buf + ( h->cur - t );
-               h->end = h->buf + ( h->end - t );
-       }
-
-       if (( rc = read( h->fd, h->cur + 1, PA_BUFBLK )) <= 0 ) {
-               return( (char) 0 );
-       }
-
-       h->end = h->cur + rc;
-       return( *(++(h->cur)) );
-}
diff --git a/bin/psorder/pa.h b/bin/psorder/pa.h
deleted file mode 100644 (file)
index 7839970..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * $Id: pa.h,v 1.3 2009-10-13 22:55:36 didg Exp $
- *
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- * All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software and
- * its documentation for any purpose and without fee is hereby granted,
- * provided that the above copyright notice appears in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation, and that the name of The University
- * of Michigan not be used in advertising or publicity pertaining to
- * distribution of the software without specific, written prior
- * permission. This software is supplied as is without expressed or
- * implied warranties of any kind.
- *
- *     Research Systems Unix Group
- *     The University of Michigan
- *     c/o Mike Clark
- *     535 W. William Street
- *     Ann Arbor, Michigan
- *     +1-313-763-0525
- *     netatalk@itd.umich.edu
- */
-
-/*
- * Functions to aid in parsing:
- *
- *     pa_init( fd )           Allocate and return a handle. Reads
- *                             from fd. Call this first, always.
- *     pa_getchar( h )         Return a single character or nul, 0,
- *                             to indicate end-of-file.
- *     pa_match( h )           Mark the character last read as the start
- *                             of a match.
- *     pa_gettok( h )          The match up to but excluding the last
- *                             character is returned.
- *     pa_cont( h )            Continue match with previous match. Call
- *                             immediately after pa_gettok() to get
- *                             correct behavior.
- *     pa_cancel( h )          Cancel previous match start.
- */
-
-#ifndef _PA_H
-#define _PA_H 1
-
-#ifndef FILE_H
-#include <stdio.h>
-#endif /* FILE_H */
-
-#define PA_BUFBLK      1024
-
-#define PA_NORMAL      0
-#define PA_MATCHING    1
-
-typedef struct pa_buf_t {
-       char *buf;
-       char *cur;
-       char *mark;
-       char *end;
-       int fd;
-       int state;
-       unsigned bufsz;
-       char tmp;
-} pa_buf_t;
-
-extern pa_buf_t *pa_init(int fd);
-extern char _pa_fixbuf(pa_buf_t *h);
-extern char *pa_gettok(pa_buf_t *h);
-
-#define pa_getchar(h)  (((h)->cur==(h)->end)?(_pa_fixbuf(h)):\
-                       (*(++((h)->cur))))
-#define pa_match(h)    ((h)->state=PA_MATCHING,(h)->mark=(h)->cur)
-#define pa_cont(h)     (*((h)->cur)=(h)->tmp,(h)->state=PA_MATCHING)
-#define pa_cancel(h)   ((h)->state=PA_NORMAL)
-#define pa_back(h)     (--((h)->cur))
-
-#endif /* _PA_H */
diff --git a/bin/psorder/psorder.c b/bin/psorder/psorder.c
deleted file mode 100644 (file)
index 4a37bab..0000000
+++ /dev/null
@@ -1,555 +0,0 @@
-/*
- * $Id: psorder.c,v 1.10 2010-04-12 14:28:47 franklahm Exp $
- *
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- * All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software and
- * its documentation for any purpose and without fee is hereby granted,
- * provided that the above copyright notice appears in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation, and that the name of The University
- * of Michigan not be used in advertising or publicity pertaining to
- * distribution of the software without specific, written prior
- * permission. This software is supplied as is without expressed or
- * implied warranties of any kind.
- *
- *     Research Systems Unix Group
- *     The University of Michigan
- *     c/o Mike Clark
- *     535 W. William Street
- *     Ann Arbor, Michigan
- *     +1-313-763-0525
- *     netatalk@itd.umich.edu
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/time.h>
-#include <sys/stat.h>
-#include <sys/uio.h>
-#include <sys/file.h>
-#include <ctype.h>
-#include <limits.h>
-#ifdef HAVE_FCNTL_H
-#include <fcntl.h>
-#endif /* HAVE_FCNTL_H */
-#include <stdio.h>
-#include <string.h>
-#include <dirent.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
-#include "pa.h"
-#include "psorder.h"
-
-#include <atalk/paths.h>
-
-/*
- *                     Global Variables
- */
-
-static u_char                  psbuf[ 8192 ];
-static struct psinfo_st                psinfo;
-static int                     orderflag, forceflag;
-
-static void
-filecleanup( int errorcode, int tfd, char *tfile)
-{
-
-/*
-       Close and unlink the temporary file.
- */
-
-    if ( tfd != 0 ) {
-       if ( close( tfd ) != 0 ) {
-           perror( tfile );
-           exit( errorcode );
-       }
-       if ( unlink( tfile ) != 0 ) {
-           perror( tfile );
-           exit( errorcode );
-       }
-    }
-
-    exit( errorcode );
-}
-
-static void
-filesetup( char *inputfile, int *infd, char *tfile, int *tfd)
-{
-    struct stat                st;
-    char               *template = _PATH_TMPPAGEORDER;
-
-    if ( strcmp( inputfile, STDIN ) != 0 ) {
-       if ( stat( inputfile, &st ) < 0 ) {
-           perror( inputfile );
-           filecleanup( -1, -1, "" );
-       }
-       if ( st.st_mode & S_IFMT & S_IFDIR ) {
-           fprintf( stderr, "%s is a directory.\n", inputfile );
-           filecleanup( 0, -1, "" );
-       }
-       if (( *infd = open( inputfile, O_RDONLY, 0600 )) < 0 ) {
-           perror( inputfile );
-           filecleanup( -1, -1, "" );
-       }
-    } else {
-       *infd = 0;
-    }
-
-#if DEBUG
-    fprintf( stderr, "Input file or stdin and stdout opened.\n" );
-    fprintf( stderr, "Input file descriptor is %d .\n", *infd );
-#endif /* DEBUG */
-
-/*
-       make temporary file
- */
-
-#if defined(NAME_MAX)
-    (void *)strncpy( tfile, template, NAME_MAX );
-#else
-    (void *)strncpy( tfile, template, MAXNAMLEN );
-#endif
-    if (( *tfd = mkstemp( tfile )) == -1 ) {
-       fprintf( stderr, "can't create temporary file %s\n", tfile );
-       filecleanup( -1, -1, "" );
-    }
-
-#if DEBUG
-    fprintf( stderr, "Temporary file %s created and opened.\n", tfile );
-    fprintf( stderr, "Temporary file descriptor is %d .\n", *tfd );
-#endif /* DEBUG */
-
-    psinfo.firstpage = NULL;
-    psinfo.lastpage = NULL;
-    psinfo.trailer = 0;
-    psinfo.pages.offset = 0;
-    psinfo.pages.end = 0;
-    psinfo.pages.num[0] = '\0';
-    psinfo.pages.order[0] = '\0';
-
-    return;
-}
-
-static struct pspage_st
-*getpspage(off_t off)
-{
-    struct pspage_st   *newpspage;
-
-    newpspage = (struct pspage_st *)malloc( sizeof( struct pspage_st )); 
-    if ( newpspage != NULL ) {
-       newpspage->offset = off;
-       newpspage->nextpage = NULL;
-       *newpspage->lable = '\0';
-       *newpspage->ord = '\0';
-    }
-    return( newpspage );
-}
-
-static int
-handletok(off_t count, char *token)
-{
-    int                        incdoc = 0;
-    struct pspage_st   *newpage;
-    char               *tmp;
-
-    if (( strncmp( PENDDOC, token, strlen( PENDDOC )) == 0 ) && incdoc ) {
-       incdoc--;
-#if DEBUG
-       fprintf( stderr, "found an EndDoc\n" );
-#endif /* DEBUG */
-
-    } else if ( strncmp( PBEGINDOC, token, strlen( PBEGINDOC )) == 0 ) {
-       incdoc++;
-#if DEBUG
-       fprintf( stderr, "found a BeginDoc\n" );
-#endif /* DEBUG */
-
-    } else if ( !incdoc && 
-           ( strncmp( PPAGE, token, strlen( PPAGE )) == 0 )) {
-#if DEBUG
-       fprintf( stderr, "found a Page\n" );
-#endif /* DEBUG */
-       if (( newpage = getpspage( count )) == NULL ) {
-           return( -1 );
-       }
-       if ( psinfo.firstpage == NULL ) {
-           newpage->prevpage = NULL;
-           psinfo.firstpage = newpage;
-       } else {
-           newpage->prevpage = psinfo.lastpage;
-           psinfo.lastpage->nextpage = newpage;
-       }
-       psinfo.lastpage = newpage;
-       while ( *token++ != ':' );
-       if (( tmp = strtok( token, WHITESPACE )) != NULL ) {
-           (void)strncpy( newpage->lable, tmp, NUMLEN );
-           if (( tmp = strtok( NULL, WHITESPACE )) != NULL ) {
-               (void)strncpy( newpage->ord, tmp, ORDLEN );
-           }
-       }
-#if DEBUG
-       fprintf( stderr, "page lable %s, page ord %s\n", newpage->lable,
-               newpage->ord );
-#endif /* DEBUG */
-
-    } else if ( !incdoc && 
-           ( strncmp( PPAGES, token, strlen( PPAGES )) == 0 )) {
-#if DEBUG
-       fprintf( stderr, "found a Pages\n" );
-#endif /* DEBUG */
-       psinfo.pages.offset = count;
-       psinfo.pages.end = strlen( token ) + count;
-       while ( *token++ != ':' );
-       while ( isspace( *token )) token++;
-       if ( strncmp( ATEND, token, strlen( ATEND )) == 0 ) {
-#if DEBUG
-           fprintf( stderr, "it is a Pages: (atend)\n" );
-#endif /* DEBUG */
-           psinfo.pages.offset = 0;
-           psinfo.pages.end = 0;
-       } else {
-           if (( tmp = strtok( token, WHITESPACE )) != NULL ) {
-               (void)strncpy( psinfo.pages.num, tmp, NUMLEN );
-               if (( tmp = strtok( NULL, WHITESPACE )) != NULL ) {
-                   (void)strncpy( psinfo.pages.order, tmp, ORDERLEN );
-               }
-           }
-#if DEBUG
-           fprintf( stderr, "number of pages %s\n", psinfo.pages.num );
-           fprintf( stderr, "order control number %s\n", psinfo.pages.order );
-#endif /* DEBUG */
-       }
-
-    } else if ( !incdoc && 
-           ( strncmp( PTRAILER, token, strlen( PTRAILER )) == 0 )) {
-#if DEBUG
-       fprintf( stderr, "found the Trailer\n" );
-#endif /* DEBUG */
-       if  ( psinfo.trailer == 0 ) {
-           psinfo.trailer = count;
-       }
-    }
-
-    return( 0 );
-}
-
-static void
-readps(int inputfd, int tempfd, char *tempfile)
-{
-    off_t              ccread = 0;
-    off_t              ccmatch;
-    char               *curtok = NULL;
-    FILE               *tempstream;
-    pa_buf_t           *pb;
-    int                        n;
-    char               c = -1;
-    char               pc, cc = 0;
-
-    pb = pa_init( inputfd );
-    if (( tempstream = fdopen( tempfd, "w" )) == NULL ) {
-       perror( "fdopen fails for tempfile" );
-       filecleanup( -1, tempfd, tempfile );
-    }
-
-    if (( c = pa_getchar( pb )) != 0 ) {
-       ccread++;
-       (void)putc( c, tempstream );
-       pc = 0;
-       cc = c;
-       pa_match( pb );
-       n = strlen( PPSADOBE );
-       for ( ; ( n > 0 ) && (( c = pa_getchar( pb )) != 0 ) ; n-- ) {
-           ccread++ ;
-           (void)putc( c, tempstream );
-           pc = cc;
-           cc = c;
-       }
-       curtok = pa_gettok( pb );
-    }
-#if DEBUG
-    fprintf( stderr, "%s\n", curtok );
-#endif /* DEBUG */
-
-/*
- * not postscript
- */
-    if ( strcmp( curtok, PPSADOBE ) != 0 ) {
-#if DEBUG
-    fprintf( stderr, "in the not postscript section of readps\n" );
-#endif /* DEBUG */
-       while (( c = pa_getchar( pb )) != 0 ) {
-           ccread++;
-           (void)putc( c, tempstream );
-           pc = cc;
-           cc = c;
-       }
-
-       (void)fflush( tempstream );
-       return;
-    }
-
-/*
- * postscript
- */
-#if DEBUG
-    fprintf( stderr, "in the postscript section of readps\n" );
-#endif /* DEBUG */
-    while (( c = pa_getchar( pb )) != 0 ) {
-       ccread++;
-       (void)putc( c, tempstream );
-       pc = cc;
-       cc = c;
-       if ((( pc == '\r' ) || ( pc == '\n' )) && ( cc == '%' )) {
-#if DEBUG
-           fprintf( stderr, "supposed start of match, cc = %c\n", cc );
-#endif /* DEBUG */
-           pa_match( pb );
-           ccmatch = ccread - 1;
-           while ( ( c = pa_getchar( pb ) ) ) {
-               if ( c != 0 ) {
-                   ccread++;
-                   (void)putc( c, tempstream );
-                   pc = cc;
-                   cc = c;
-               }
-               if (( c == '\r' ) || ( c == '\n' ) || ( cc == '\0' )) {
-                   curtok = pa_gettok( pb );
-#if DEBUG
-                   fprintf( stderr, "%s\n", curtok );
-#endif /* DEBUG */
-                   if ( handletok( ccmatch, curtok ) < 0 ) {
-                       perror( "malloc died" );
-                       filecleanup( -1, tempfd, tempfile );
-                   }
-                   break;
-               }
-               if ( c == 0 ) break;
-           }
-           if ( c == 0 ) break;
-       }
-    }
-
-    (void)fflush( tempstream );
-    return;
-}
-
-static void
-temp2out(int tempfd, char *tempfile, off_t length)
-{
-    int                        ccread;
-    int                        ccwrite;
-    int                        size;
-
-    while ( length > 0 ) {
-       if ( length > sizeof( psbuf )) {
-           size = sizeof( psbuf );
-       } else size = length;
-       if (( ccread = read( tempfd, psbuf, size )) > 0 ) {
-           size = ccread;
-           while ( ccread > 0 ) {
-               ccwrite = write( 1, psbuf, ccread );
-               if ( ccwrite < 0 ) {
-                   perror( "stdout" );
-                   filecleanup( ccwrite, tempfd, tempfile );
-               } else {
-                   ccread -= ccwrite;
-               }
-           }
-       }
-       if ( ccread < 0 ) {
-           perror( "temporary file" );
-           filecleanup( ccread, tempfd, tempfile );
-       }
-       length -= size;
-    }
-}
-
-static void
-writelable(int tempfd, char *tempfile, char *lable)
-{
-    char               line[256];
-    int                        ccwrite;
-    int                        linelen;
-    char               *argone;
-    char               *argtwo;
-
-    if ( strcmp( lable, PPAGES ) == 0 ) {
-       argone = psinfo.pages.num;
-       argtwo = psinfo.pages.order;
-    } else {
-       argone = argtwo = NULL;
-    }
-    (void)sprintf( line, "%s %s %s", lable, argone, argtwo );
-    linelen = strlen( line );
-
-    ccwrite = write( 1, line, linelen );
-    if ( ccwrite < 0 ) {
-       perror( "stdout" );
-       filecleanup( ccwrite, tempfd, tempfile );
-    } else {
-       linelen -= ccwrite;
-    }
-}
-
-static void
-writeps(int tempfd, char *tempfile)
-{
-    struct stat                st;
-    off_t              endofpage;
-    int                        order;
-
-    if ( stat( tempfile, &st ) < 0 ) {
-       perror( "stat failed" );
-       filecleanup( -1, tempfd, tempfile );
-    }
-    if ( psinfo.trailer == 0 ) {
-       endofpage = st.st_size;
-    } else endofpage = psinfo.trailer;
-
-    if (( psinfo.firstpage == NULL ) || 
-           ( psinfo.firstpage == psinfo.lastpage )) {
-       order = FORWARD;
-    } else if ( psinfo.pages.offset == 0 ) {
-       order = orderflag;
-    } else if (( strncmp( psinfo.pages.order, "", ORDERLEN ) == 0 ) ||
-           ( strncmp( psinfo.pages.order, "1", ORDERLEN ) == 0 )) {
-       order = orderflag;
-       if ( order == REVERSE ) strcpy( psinfo.pages.order, "-1" );
-    } else if ( strncmp( psinfo.pages.order, "-1", ORDERLEN ) == 0 ) {
-       if ( orderflag == FORWARD ) {
-           order = REVERSE;
-           strcpy( psinfo.pages.order, "1" );
-       } else order = FORWARD;
-    } else if (( strncmp( psinfo.pages.order, "0", ORDERLEN ) == 0 ) &&
-           forceflag ) {
-       order = orderflag;
-    } else order = FORWARD;
-
-    if ( order == FORWARD ) {
-       temp2out( tempfd, tempfile, st.st_size );
-    } else {
-/*
- *     output the header stuff and rewrite the $$Pages line
- *     if it is in the header and not %%Pages: (atend)
- */
-       if ( psinfo.firstpage->offset > 0 ) {
-           if (( psinfo.firstpage->offset > psinfo.pages.offset ) &&
-                   ( psinfo.pages.offset != 0 )) {
-               temp2out( tempfd, tempfile, psinfo.pages.offset );
-               writelable( tempfd, tempfile, PPAGES );
-               if ( lseek( tempfd, psinfo.pages.end, SEEK_SET ) < 0 ) {
-                   perror( tempfile );
-                   filecleanup( -1, tempfd, tempfile );
-               }
-               temp2out( tempfd, tempfile, 
-                       psinfo.firstpage->offset - psinfo.pages.end );
-           } else temp2out( tempfd, tempfile, psinfo.firstpage->offset );
-       }
-/*
- *     output the pages, last to first
- */
-       while ( psinfo.lastpage != NULL ) {
-           if ( lseek( tempfd, psinfo.lastpage->offset, SEEK_SET ) < 0 ) {
-               perror( tempfile );
-               filecleanup( -1, tempfd, tempfile );
-           }
-           temp2out( tempfd, tempfile, endofpage - psinfo.lastpage->offset );
-           endofpage = psinfo.lastpage->offset;
-           psinfo.lastpage = psinfo.lastpage->prevpage;
-           if ( psinfo.lastpage != NULL ) {
-               (void)free( psinfo.lastpage->nextpage );
-               psinfo.lastpage->nextpage = NULL;
-           }
-       }
-/*
- *     output the trailer stuff and rewrite the $$Pages line
- *     if it is in the trailer
- */
-       if ( psinfo.trailer != 0 ) {
-           if ( lseek( tempfd, psinfo.trailer, SEEK_SET ) < 0 ) {
-               perror( tempfile );
-               filecleanup( -1, tempfd, tempfile );
-           }
-           if ( psinfo.trailer < psinfo.pages.offset ) {
-               temp2out( tempfd, tempfile,
-                       psinfo.pages.offset - psinfo.trailer );
-               writelable( tempfd, tempfile, PPAGES );
-               if ( lseek( tempfd, psinfo.pages.end, SEEK_SET ) < 0 ) {
-                   perror( tempfile );
-                   filecleanup( -1, tempfd, tempfile );
-               }
-               temp2out( tempfd, tempfile, st.st_size - psinfo.pages.end );
-           } else temp2out( tempfd, tempfile, st.st_size - psinfo.trailer );
-       }
-    }
-
-    return;
-}
-
-static int
-psorder(char *path)
-{
-    int                        tempfd;
-    int                        inputfd;
-#if defined(NAME_MAX)
-    char               tempfile[NAME_MAX];
-#else
-    char               tempfile[MAXNAMLEN];
-#endif
-
-    filesetup( path, &inputfd, tempfile, &tempfd );
-    readps( inputfd, tempfd, tempfile );
-    if ( lseek( tempfd, REWIND, SEEK_SET ) < 0 ) {
-       perror( tempfile );
-       filecleanup( -1, tempfd, tempfile );
-    }
-    writeps( tempfd, tempfile );
-    filecleanup( 0, tempfd, tempfile );
-    return( 0 );
-}
-
-int main(int argc, char **argv)
-{
-    extern int optind;
-    char       *progname;
-    int                errflag = 0;
-    int                c;
-
-    while (( c = getopt( argc, argv, OPTSTR )) != -1 ) {
-       switch ( c ) {
-       case REVCHAR:
-           if ( orderflag ) errflag++;
-           else orderflag = REVERSE;
-           break;
-       case FORWCHAR:
-           if ( orderflag ) errflag++;
-           else orderflag = FORWARD;
-           break;
-       case FORCECHAR:
-           if ( forceflag ) errflag++;
-           else forceflag++;
-           break;
-       }
-    }
-    if ( errflag ) {
-       if (( progname = strrchr( argv[ 0 ], '/' )) == NULL ) {
-           progname = argv[ 0 ];
-       } else progname++;
-       fprintf( stderr, "usage: %s [-duf] [sourcefile]\n", progname );
-       return( -1 );
-    } else if ( !orderflag ) orderflag = FORWARD;
-
-    if ( optind >= argc ) {
-       return( psorder( STDIN ));
-    }
-    return( psorder( argv[ optind ] ));
-}
-
diff --git a/bin/psorder/psorder.h b/bin/psorder/psorder.h
deleted file mode 100644 (file)
index 5d810b4..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * $Id: psorder.h,v 1.3 2009-10-13 22:55:36 didg Exp $
- *
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- * All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software and
- * its documentation for any purpose and without fee is hereby granted,
- * provided that the above copyright notice appears in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation, and that the name of The University
- * of Michigan not be used in advertising or publicity pertaining to
- * distribution of the software without specific, written prior
- * permission. This software is supplied as is without expressed or
- * implied warranties of any kind.
- *
- *     Research Systems Unix Group
- *     The University of Michigan
- *     c/o Mike Clark
- *     535 W. William Street
- *     Ann Arbor, Michigan
- *     +1-313-763-0525
- *     netatalk@itd.umich.edu
- */
-
-#ifndef        STDIN
-#      define  STDIN   "-"
-#endif /* ! STDIN */
-#ifndef FALSE
-#      define  FALSE   0
-#      define  TRUE    1
-#endif /* ! FALSE */
-
-#define REVCHAR                'd'
-#define FORWCHAR       'u'
-#define FORCECHAR      'f'
-#define OPTSTR         "duf"
-
-#define WHITESPACE     " \t"
-#define ATEND          "(atend)"
-#define PPSADOBE       "%!PS-Adobe-"
-#define        PPAGE           "%%Page:"
-#define PPAGES         "%%Pages:"
-#define PTRAILER       "%%Trailer"
-#define PBEGINDOC      "%%BeginDocument:"
-#define PENDDOC                "%%EndDocument"
-#define PBEGINBIN      "%%BeginBinary:"
-#define PENDBIN                "%%EndBinary"
-
-#define REWIND         0L
-#define REVERSE                1
-#define FORWARD                2
-
-#define LABELLEN       32
-#define ORDLEN         4
-struct pspage_st {
-    struct pspage_st   *nextpage;
-    struct pspage_st   *prevpage;
-    off_t              offset;
-    char               lable[ LABELLEN ];
-    char               ord[ ORDLEN ];
-};
-
-#define NUMLEN         10
-#define ORDERLEN       3
-struct pages_st {
-    off_t              offset;
-    off_t              end;
-    char               num[ NUMLEN ];
-    char               order[ ORDERLEN ];
-};
-
-struct psinfo_st {
-    struct pspage_st   *firstpage;
-    struct pspage_st   *lastpage;
-    off_t              trailer;
-    struct pages_st    pages;
-};
-
index 38e7d336dc16ca5da52887e90b1358d5d0bf25c0..7cdd43c3995d31ee455910d872f9071d589085b6 100644 (file)
@@ -23,8 +23,8 @@
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
+#include <arpa/inet.h>
 
-#include <netatalk/endian.h>
 #include <atalk/unicode.h>
 #include <atalk/logger.h>
 
index e6d1daeb4d5fa470bb677687d3fcfc2ec7ad726d..8a786a601dd4c1c641bc8c3d4c2bb8730e67eea6 100644 (file)
 #include <sys/param.h>
 #include <pwd.h>
 #include <dirent.h>
+#include <arpa/inet.h>
+
 #include <atalk/afp.h>
 #include <atalk/unicode.h>
 #include <atalk/util.h>
 #include <atalk/logger.h>
+#include <atalk/compat.h>
 
 #include "atalk/cnid.h"
 #ifndef MAXPATHLEN
@@ -57,7 +60,7 @@ char* to_charset;
 static charset_t ch_mac;
 char* mac_charset;
 static int usedots = 0;
-static u_int16_t conv_flags = 0;
+static uint16_t conv_flags = 0;
 static int dry_run = 0;
 static int verbose=0;
 char *cnid_type;
@@ -146,7 +149,7 @@ static char *convert_name(char *name, struct stat *st, cnid_t cur_did)
        size_t outlen = 0;
        unsigned char *p,*q;
        int require_conversion = 0;
-    u_int16_t    flags = conv_flags;
+    uint16_t    flags = conv_flags;
        cnid_t id;
 
        p = (unsigned char *)name;
index 1cd523f23a9a372920f744dbca39027a4601dd2c..7d0c8330f061c881e625dbdbc31df333a092486c 100755 (executable)
--- a/bootstrap
+++ b/bootstrap
@@ -11,15 +11,5 @@ libtoolize --force --copy
 automake --include-deps --add-missing --foreign --copy || exit 1
 autoconf || exit 1
 
-# Original configure call was:
-#./configure --enable-maintainer-mode "$@"
-# However, according to:
-#  http://sources.redhat.com/autobook/autobook/autobook_43.html#SEC43
-# we need to have AM_MAINTAINER_MODE in configure.in in order to use
-# this feature.  It's not there at the moment, so I'm changing the
-# configure call.
-# And sometimes I don't want this to run.
-# [ -z "$NOEXECCONFIGURE" ] && ./configure "$@"
-
 # Let's not fall off the end...
 exit 0
index ce0fb96e2d3c02f02620a88f843082299a31d6c6..bd503aebb8a407065ae8ea8d4964be4f26a5fc9d 100644 (file)
@@ -11,9 +11,7 @@ EXTRA_DIST = \
        AppleVolumes.system \
        afp_ldap.conf \
        afpd.conf.tmpl \
-       atalkd.conf \
-       netatalk.conf \
-       papd.conf
+       netatalk.conf
 
 OVERWRITE_CONFIG = @OVERWRITE_CONFIG@
 
@@ -27,10 +25,6 @@ if HAVE_ACLS
 CONFFILES += afp_ldap.conf
 endif
 
-if USE_APPLETALK
-CONFFILES += atalkd.conf papd.conf
-endif
-
 pkgconfdir = @PKGCONFDIR@
 webminpath = @WEBMIN_PATH@
 webminuser = @WEBMIN_USER@
diff --git a/config/atalkd.conf b/config/atalkd.conf
deleted file mode 100644 (file)
index 4648e3a..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-#
-# Format of lines in this file:
-#
-#    interface [ -seed ] [ -router | -dontroute ] 
-#       [ -phase { 1 | 2 } ] [ -addr net.node ]
-#      [ -net first[-last] ] [ -zone ZoneName ] ...
-#
-# -seed only works if you have multi-interfaces.  Any missing arguments are
-# automatically configured from the network.  Note: lines can't actually be
-# split, tho it's a good idea.
-#
-# -router is like -seed but it allows single-interface routing. -dontroute 
-# disables routing for the specified interface.
-#
-# Some examples:
-#
-#      The simplest case is no atalkd.conf.  This works on most platforms
-#      (notably not Solaris), since atalkd can discover the local interfaces
-#      on the machine.
-#
-#      Very slightly more complicated:
-#
-#              le0
-#      or
-#              eth0
-#
-#      for Solaris/SunOS or Linux.
-#
-#      A much more complicated example:
-#
-#              le0 -phase 1
-#              le1 -seed -phase 2 -addr 66.6 -net 66-67 -zone "No Parking"
-#
-#      This turns on transition routing between the le0 and le1
-#      interfaces on a Sun.  It also causes atalkd to fail if other
-#      routers disagree about it's configuration of le1.
-#
diff --git a/config/papd.conf b/config/papd.conf
deleted file mode 100644 (file)
index ec36a6a..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-# Attributes are:
-#
-#      Name Type Default       Description
-#      pd   str  ".ppd"        Pathname to ppd file.
-#      pr   str  "lp"          LPD printer name.
-#       pa   str  "0.0"         AppleTalk address (not usually needed).
-#      op   str  "operator"    Operator name, for LPD spooling.
-#      au   flag not-present   If present, authentication required
-#                              note that if ca and sp are both set,
-#                              ca will be tried first and then sp
-#      am   str  none          Comma separated list of uams to use
-#                              (for every printer) whenever 
-#                              authentication is on
-#      ca   str  not-present   If present, use cap-style authentication
-#                              directory to place print authentication files 
-#      sp   flag not-present   use PSSP authentication.
-#
-# Some examples:
-#
-#      On many systems (notably not Solaris), no papd.conf is required,
-#      since papd shares the same defaults as lpd.
-#
-#      A simple example:
-#
-#              terminator:\
-#                      :pr=lp:op=wes:\
-#                      :pd=/usr/share/lib/ppd/HPLJ_4M.PPD:
-#
-#      An example with authenticated printing:
-#              authprn:\
-#                      :pr=|/usr/bin/lpr -Plp:\
-#                      :pd=/usr/share/lib/ppd/HPLJ_4M.PPD:\
-#                      :sp:ca=/tmp/print:\
-#                      :am=uams_clrtxt.so:
-#
-#      Note also that papd.conf can list several printers.
-#
-#      The printer name in papd may be a full NBP-name of the form
-#      name:type@zone, for example:
-#              Printer 1:LaserWriter@Printing and Mailing:\
-#                      :pr=|/usr/bin/lpr -Plp1:
-#
-# Warning: If you are using more than 15 printers and you do not
-# specify the zone in the printer name, only some of the printers may
-# appear in the Chooser.
index 176c03b144f3af0aeca66efbbdb94d8c6b5c6e28..bf0b3c2be83922e837d6d619eab21242963e9aad 100644 (file)
@@ -22,35 +22,40 @@ AC_PROG_LIBTOOL
 AC_PROG_PERL
 AC_PROG_GREP
 AC_PROG_PS
-
 AM_PROG_CC_C_O
 
-dnl Checks for header files.
-AC_HEADER_DIRENT
-AC_HEADER_STDC
-AC_HEADER_SYS_WAIT
-AC_CHECK_HEADERS(fcntl.h limits.h stdint.h strings.h time.h sys/param.h sys/fcntl.h sys/file.h sys/ioctl.h sys/time.h sys/mnttab.h sys/statvfs.h sys/stat.h sys/vfs.h mntent.h syslog.h unistd.h termios.h sys/termios.h netdb.h sgtty.h ufs/quota.h mount.h statfs.h sys/types.h dlfcn.h errno.h sys/errno.h sys/uio.h langinfo.h locale.h sys/filio.h)
-AC_CHECK_HEADER(sys/cdefs.h,,
-       AC_MSG_RESULT([enabling generic cdefs.h from tree])
-       CFLAGS="-I\$(top_srcdir)/sys/generic $CFLAGS"
-)
+dnl Checks for typedefs, structures, and compiler characteristics.
+AC_C_INLINE
+
+dnl Request SUSv3 standard interfaces plus anything else the platform may have
+CFLAGS="$CFLAGS -D_XOPEN_SOURCE=600 -D__EXTENSIONS__ -D_GNU_SOURCE"
+
+dnl Check if we can use attribute unused (gcc only) from ethereal
+AC_MSG_CHECKING(to see if we can add '__attribute__((unused))' to CFLAGS)
+if test x$GCC != x ; then
+  CFLAGS="-D_U_=\"__attribute__((unused))\" $CFLAGS"
+  AC_MSG_RESULT(yes)
+else
+  CFLAGS="-D_U_=\"\" $CFLAGS"
+  AC_MSG_RESULT(no)
+fi
+
+dnl Checks for header files, some checks are obsolete, unfortunately the code
+dnl uses the resulting macros, so the code has to cleaned up too before
+dnl we can remove the checks here.
+AC_CHECK_HEADERS(mntent.h unistd.h termios.h ufs/quota.h)
+AC_CHECK_HEADERS(netdb.h sgtty.h statfs.h dlfcn.h langinfo.h locale.h)
+AC_CHECK_HEADERS(sys/param.h sys/fcntl.h sys/termios.h)
+AC_CHECK_HEADERS(sys/mnttab.h sys/statvfs.h sys/stat.h sys/vfs.h)
+dnl Checks for header files, confirmed to be required as of 2011
+AC_CHECK_HEADERS(sys/epoll.h)
 AC_CHECK_HEADERS([sys/mount.h], , , 
 [#ifdef HAVE_SYS_PARAM_H
 #include <sys/param.h>
 #endif
 ])
 
-dnl Checks for typedefs, structures, and compiler characteristics.
-AC_C_CONST
-AC_TYPE_UID_T
-AC_C_INLINE
-AC_TYPE_MODE_T
-AC_TYPE_OFF_T
-AC_TYPE_PID_T
-AC_TYPE_SIZE_T
-AC_STRUCT_ST_RDEV
-AC_HEADER_TIME
-AC_STRUCT_TM
+AC_SYS_LARGEFILE([], AC_MSG_ERROR([AFP 3.x support requires Large File Support.]))
 
 dnl --------------------------------------------------------------------------
 dnl check if dlsym needs to add an underscore, uses libtool macros 
@@ -62,40 +67,33 @@ if test x"$libltdl_cv_need_uscore" = xyes; then
     AC_DEFINE(DLSYM_PREPEND_UNDERSCORE, 1, [BSD compatibility macro])
 fi
 
-dnl Checks for library functions.
-AC_TYPE_GETGROUPS
-AC_PROG_GCC_TRADITIONAL
-AC_FUNC_MEMCMP
-AC_HEADER_MAJOR
-AC_FUNC_MMAP
-AC_TYPE_SIGNAL
-AC_FUNC_UTIME_NULL
-AC_FUNC_WAIT3
-AC_CHECK_FUNCS(getcwd gethostname gettimeofday getusershell mkdir rmdir select socket strdup strcasestr strstr strtoul strchr memcpy)
-AC_CHECK_FUNCS(backtrace_symbols setlocale nl_langinfo strlcpy strlcat setlinebuf dirfd pselect access pread pwrite)
-AC_CHECK_FUNCS(waitpid getcwd strdup strndup strnlen strtoul strerror chown fchown chmod fchmod chroot link mknod mknod64)
+dnl Special hecks
 ac_neta_haveatfuncs=yes
 AC_CHECK_FUNCS(openat renameat fstatat unlinkat, , ac_neta_haveatfuncs=no)
 if test x"$ac_neta_haveatfuncs" = x"yes" ; then
    AC_DEFINE([_ATFILE_SOURCE], 1, AT file source)
    AC_DEFINE([HAVE_ATFUNCS], 1, whether at funcs are available)
 fi
-
 AC_CHECK_MEMBERS(struct tm.tm_gmtoff,,, [#include <time.h>])
 
-AC_CHECK_FUNC(gethostbyname,,[AC_CHECK_LIB(nsl,gethostbyname)])
-AC_CHECK_FUNC(connect,,[AC_CHECK_LIB(socket,connect)])
-dnl search for necessary libs for libpthread stuff
-AC_SEARCH_LIBS(pthread_sigmask, pthread,, 
-               [AC_MSG_ERROR([cannot find pthread_sigmask in libc or libpthread])])
+dnl these tests have been comfirmed to be needed in 2011
+AC_CHECK_FUNC(epoll_create, AC_DEFINE([HAVE_EPOLL], 1, Whether Linux epoll is available)) 
+AC_CHECK_FUNCS(backtrace_symbols dirfd getusershell pread pwrite pselect)
+AC_CHECK_FUNCS(setlinebuf strlcat strlcpy strnlen)
+AC_CHECK_FUNCS(mmap utime getpagesize) dnl needed by tbd
+
+dnl search for necessary libraries
+AC_SEARCH_LIBS(gethostbyname, nsl)
+AC_SEARCH_LIBS(connect, socket)
+AC_SEARCH_LIBS(pthread_sigmask, pthread,,[AC_MSG_ERROR([missing pthread_sigmask])])
 if test x"$ac_cv_search_pthread_sigmask" != x"none required" ; then
    PTHREAD_LIBS=$ac_cv_search_pthread_sigmask
 fi
 AC_SUBST(PTHREAD_LIBS)
-AC_CACHE_SAVE
 
-dnl Checks for (v)snprintf
-NETATALK_SNPRINTF_CHECK
+AC_DEFINE(OPEN_NOFOLLOW_ERRNO, ELOOP, errno returned by open with O_NOFOLLOW)
+
+AC_CACHE_SAVE
 
 dnl --------------------------------------------------------------------------
 dnl 64bit platform check
@@ -141,379 +139,98 @@ dnl --------------------------------------------------------------------------
 dnl specific configuration comes in here:
 dnl --------------------------------------------------------------------------
 
+dnl Check for optional admin group support
+AC_NETATALK_ADMIN_GROUP
 
-netatalk_cv_admin_group=yes
-AC_MSG_CHECKING([for administrative group support])
-AC_ARG_ENABLE(admin-group,
-       [  --disable-admin-group   disable admin group],[
-        if test x"$enableval" = x"no"; then
-               AC_DEFINE(ADMIN_GRP, 0, [Define if the admin group should be enabled])
-               netatalk_cv_admin_group=no
-               AC_MSG_RESULT([no])
-       else
-               AC_DEFINE(ADMIN_GRP, 1, [Define if the admin group should be enabled])
-               AC_MSG_RESULT([yes])
-        fi],[
-               AC_DEFINE(ADMIN_GRP, 1, [Define if the admin group should be enabled])
-               AC_MSG_RESULT([yes])
-       ]
-)
-
-NETATALK_AFS_CHECK
-
-NETATALK_CONFIG_DIRS
-
-netatalk_cv_with_cracklib=no
-AC_ARG_WITH(cracklib,
-       [  --with-cracklib=DICT    enable/set location of cracklib dictionary],[
-       if test "x$withval" != "xno" ; then
-               cracklib="$withval"
-               AC_CHECK_LIB(crack, main, [
-                       AC_DEFINE(USE_CRACKLIB, 1, [Define if cracklib should be used])
-                       LIBS="$LIBS -lcrack"
-                       if test "$cracklib" = "yes"; then
-                               cracklib="/usr/$atalk_libname/cracklib_dict"
-                       fi
-                       AC_DEFINE_UNQUOTED(_PATH_CRACKLIB, "$cracklib",
-                               [path to cracklib dictionary])
-                       AC_MSG_RESULT([setting cracklib dictionary to $cracklib])
-                       netatalk_cv_with_cracklib=yes
-                       ],[
-                       AC_MSG_ERROR([cracklib not found!])
-                       ]
-               )
-       fi
-       ]
-)
-AC_MSG_CHECKING([for cracklib support])
-AC_MSG_RESULT([$netatalk_cv_with_cracklib])
-
-netatalk_cv_ddp_enabled=no
-AC_MSG_CHECKING([whether to enable DDP])
-AC_ARG_ENABLE(ddp,
-       [  --enable-ddp            enable DDP (AppleTalk)],[
-       if test "$enableval" = "yes"; then 
-               AC_MSG_RESULT([yes])
-               netatalk_cv_ddp_enabled=yes
-       else
-               AC_MSG_RESULT([yes])
-               AC_DEFINE(NO_DDP, 1, [Define if DDP should be disabled])
-       fi
-       ],[
-               AC_MSG_RESULT([no])
-               AC_DEFINE(NO_DDP, 1, [Define if DDP should be disabled])
-       ]
-)
+dnl Check for optional AFS support
+AC_NETATALK_AFS_CHECK
 
-AC_MSG_CHECKING([whether to enable debug code])
-AC_ARG_ENABLE(debug1,
-       [  --enable-debug1         enable debug code],[
-       if test "$enableval" != "no"; then
-               if test "$enableval" = "yes"; then
-                       AC_DEFINE(DEBUG1, 1, [Define if debugging information should be included])
-               else
-                       AC_DEFINE_UNQUOTED(DEBUG1, $enableval, [Define if debugging information should be included])
-               fi 
-               AC_MSG_RESULT([yes])
-       else
-               AC_MSG_RESULT([no])
-       fi
-       ],[
-               AC_MSG_RESULT([no])
-       ]
-)
+dnl --with-pkgconfdir check to change configuration directory location
+AC_NETATALK_CONFIG_DIRS
 
-AC_MSG_CHECKING([whether to enable verbose debug code])
-AC_ARG_ENABLE(debug,
-       [  --enable-debug          enable verbose debug code],[
-       if test "$enableval" != "no"; then
-               if test "$enableval" = "yes"; then
-                       AC_DEFINE(DEBUG, 1, [Define if verbose debugging information should be included])
-               else
-                       AC_DEFINE_UNQUOTED(DEBUG, $enableval, [Define if verbose debugging information should be included])
-               fi 
-               AC_MSG_RESULT([yes])
-       else
-               AC_MSG_RESULT([no])
-        AC_DEFINE(NDEBUG, 1, [Disable assertions])
-       fi
-       ],[
-               AC_MSG_RESULT([no])
-        AC_DEFINE(NDEBUG, 1, [Disable assertions])
-       ]
-)
+dnl Check for optional cracklib support
+AC_NETATALK_CRACKLIB
 
-AC_MSG_CHECKING([whether to enable debugging with debuggers])
-AC_ARG_ENABLE(debugging,
-       [  --enable-debugging      disable SIGALRM timers and DSI tickles (eg for debugging with gdb/dbx/...)],[
-       if test "$enableval" != "no"; then
-               if test "$enableval" = "yes"; then
-                       AC_DEFINE(DEBUGGING, 1, [Define if you want to disable SIGALRM timers and DSI tickles])
-               else
-                       AC_DEFINE_UNQUOTED(DEBUGGING, $enableval, [Define if you want to disable SIGALRM timers and DSI tickles])
-               fi 
-               AC_MSG_RESULT([yes])
-       else
-               AC_MSG_RESULT([no])
-       fi
-       ],[
-               AC_MSG_RESULT([no])
-       ]
-)
+dnl Check whether to enable debug code
+AC_NETATALK_DEBUG
 
-AC_SYS_LARGEFILE([], AC_MSG_ERROR([AFP 3.x support requires Large File Support.]))
-AC_CHECK_ICONV
-
-dnl ----------- A NOTE ABOUT DROPKLUDGE
-dnl The trouble with this fix is that if you know what the file is called, it
-dnl can be read from the Unix side.  That's okay for most academic institutions
-dnl since the students don't have telnet access to the Mac servers.  There is
-dnl currently no one working on further development/fixes of DROPKLUDGE.
-dnl -----------
-
-netatalk_cv_dropkludge=no
-AC_MSG_CHECKING([whether to enable experimental dropbox support])
-AC_ARG_ENABLE(dropkludge,
-       [  --enable-dropkludge     enable the experimental dropbox fix (INSECURE!) ],[
-       if test "$enableval" = "yes"; then 
-               AC_DEFINE(DROPKLUDGE, 1, [Define if you want to use the experimental dropkludge support])
-               AC_MSG_RESULT([yes])
-               netatalk_cv_dropkludge=yes
-       else
-               AC_MSG_RESULT([no])
-       fi
-       ],[
-               AC_MSG_RESULT([no])
-       ]
-)
+dnl Check whethe to disable tickle SIGALARM stuff, which eases debugging
+AC_NETATALK_DEBUGGING
 
-netatalk_cv_force_uidgid=no
-AC_MSG_CHECKING([whether to enable forcing of uid/gid per volume])
-AC_ARG_ENABLE(force-uidgid,
-       [  --enable-force-uidgid   allow forcing of uid/gid per volume (BROKEN) ],[
-       if test "$enableval" = "yes"; then
-               AC_DEFINE(FORCE_UIDGID, 1, [Define if you want forcing of uid/gid per volume])
-               AC_MSG_RESULT([enabling forcing of uid/gid per volume])
-               AC_MSG_RESULT([yes])
-               netatalk_cv_force_uidgid=yes
-       else
-               AC_MSG_RESULT([no])
-       fi
-       ],[
-               AC_MSG_RESULT([no])
-       ]
-)
+dnl    Check for libiconv support
+AC_NETATALK_CHECK_ICONV
 
 dnl Check for CNID database backends
-bdb_required=no
 AC_NETATALK_CNID([bdb_required=yes],[bdb_required=no])
 
 dnl Check for quota support
-AC_CHECK_QUOTA
+AC_NETATALK_CHECK_QUOTA
 
 dnl Check for optional server location protocol support (used by MacOS X)
-NETATALK_SRVLOC
+AC_NETATALK_SRVLOC
 
 dnl Check for optional Zeroconf support
-NETATALK_ZEROCONF
+AC_NETATALK_ZEROCONF
 
-dnl Check for PAM libs
-netatalk_cv_use_pam=no
-AC_PATH_PAM([
-       use_pam_so=yes
-       compile_pam=yes
-       netatalk_cv_use_pam=yes
-       AC_DEFINE(USE_PAM, 1, [Define to enable PAM support])
-])
+dnl Check for optional TCP-wrappers support
+AC_NETATALK_TCP_WRAPPERS
 
-netatalk_cv_use_shadowpw=no
-AC_ARG_WITH(shadow,
-       [  --with-shadow           enable shadow password support [[auto]]],
-       [netatalk_cv_use_shadowpw="$withval"],
-       [netatalk_cv_use_shadowpw=auto]
-)
-
-if test "x$netatalk_cv_use_shadowpw" != "xno"; then
-    AC_CHECK_HEADER([shadow.h])
-    if test x"$ac_cv_header_shadow_h" = x"yes"; then
-       netatalk_cv_use_shadowpw=yes
-       AC_DEFINE(SHADOWPW, 1, [Define if shadow passwords should be used])
-    else 
-      if test "x$shadowpw" = "xyes"; then
-        AC_MSG_ERROR([shadow support not available])
-      else
-               netatalk_cv_use_shadowpw=no
-      fi
-    fi 
-fi
+dnl Check for PAM libs
+AC_NETATALK_PATH_PAM
 
-AC_MSG_CHECKING([whether shadow support should be enabled])
-if test "x$netatalk_cv_use_shadowpw" = "xyes"; then
-       AC_MSG_RESULT([yes])
-else
-       AC_MSG_RESULT([no])
-fi
-       
+dnl Check for optional shadow password support
+AC_NETATALK_SHADOW
        
-       
-netatalk_cv_use_shellcheck=yes
-AC_MSG_CHECKING([whether checking for a valid shell should be enabled])
-AC_ARG_ENABLE(shell-check,
-       [  --disable-shell-check   disable checking for a valid shell],[
-       if test "$enableval" = "no"; then 
-               AC_DEFINE(DISABLE_SHELLCHECK, 1, [Define if shell check should be disabled])
-               AC_MSG_RESULT([no])
-               netatalk_cv_use_shellcheck=no
-       else
-               AC_MSG_RESULT([yes])
-       fi
-       ],[
-               AC_MSG_RESULT([yes])
-       ]
-)
+dnl Check for optional valid-shell-check support
+AC_NETATALK_SHELL_CHECK
 
-NETATALK_TCP_WRAPPERS
-
-AC_MSG_CHECKING([whether system (fcntl) locking should be disabled])
-AC_ARG_ENABLE(locking,
-        [  --disable-locking       disable system locking],[
-               if test "$enableval" = "no"; then
-                       AC_DEFINE(DISABLE_LOCKING, 1, [Define if system (fcntl) locking should be disabled])
-                       AC_MSG_RESULT([yes])
-               else
-                       AC_MSG_RESULT([no])
-               fi
-               
-       ],[
-               AC_MSG_RESULT([no])
-       ]
+dnl Check for optional Webmin
+AC_NETATALK_WEBMIN
 
-)
+dnl Check for optional sysv initscript install
+AC_NETATALK_SYSV_STYLE
 
-AC_ARG_ENABLE(redhat,
-       [  --enable-redhat         obsoleted ],[
-       echo "ERROR: --enable-redhat is obsoleted. Use --enable-redhat-sysv or --enable-redhat-systemd."
-       exit 1
-       ]
-)
+dnl Path where UAM modules shall be installed
+AC_ARG_WITH(uams-path, [  --with-uams-path=PATH   path to UAMs [[PKGCONF/uams]]], [uams_path="$withval"], [uams_path="${PKGCONFDIR}/uams"])
 
-AC_ARG_ENABLE(redhat-sysv,
-       [  --enable-redhat-sysv    use redhat-style sysv (upstart) configuration ],[
-       if test "$enableval" = "yes"; then
-               sysv_style=redhat-sysv
-       fi
-       AC_MSG_RESULT([enabling redhat-style sysv support])
-       ]
-)
+dnl Check for libgcrypt, if found enables DHX2 UAM
+AC_NETATALK_PATH_LIBGCRYPT([1:1.2.3])
 
-AC_ARG_ENABLE(redhat-systemd,
-       [  --enable-redhat-systemd use redhat-style systemd (>=Fedora15) configuration ],[
-       if test "$enableval" = "yes"; then
-               sysv_style=redhat-systemd
-       fi
-       AC_MSG_RESULT([enabling redhat-style systemd support])
-       ]
-)
+dnl Check for openssl, if found enables DHX UAM and Randnum UAM
+AC_NETATALK_PATH_SSL
 
-AC_ARG_ENABLE(suse,
-       [  --enable-suse           obsoleted ],[
-       echo "ERROR: --enable-suse is obsoleted. Use --enable-suse-sysv or --enable-suse-systemd."
-       exit 1
-       ]
-)
+dnl Check for Berkeley DB library
+AC_NETATALK_PATH_BDB
 
-AC_ARG_ENABLE(suse-sysv,
-       [  --enable-suse-sysv      use suse-style sysv configuration ],[
-       if test "$enableval" = "yes"; then
-               sysv_style=suse-sysv
-       fi
-       AC_MSG_RESULT([enabling suse-style sysv support])
-       ]
-)
+dnl Check for crypt
+AC_NETATALK_CRYPT
 
-AC_ARG_ENABLE(suse-systemd,
-       [  --enable-suse-systemd   use suse-style systemd (>=openSUSE12.1) configuration ],[
-       if test "$enableval" = "yes"; then
-               sysv_style=suse-systemd
-       fi
-       AC_MSG_RESULT([enabling suse-style systemd support])
-       ]
-)
+dnl Check for building PGP UAM module
+AC_NETATALK_PGP_UAM
 
-AC_ARG_ENABLE(gentoo,
-       [  --enable-gentoo         use gentoo-style sysv configuration ],[
-       if test "$enableval" = "yes"; then
-               sysv_style=gentoo
-       fi
-       AC_MSG_RESULT([enabling gentoo-style sysv support])
-       ]
-)
+dnl Check for building Kerberos V UAM module
+AC_NETATALK_KRB5_UAM
 
-AC_ARG_ENABLE(netbsd,
-       [  --enable-netbsd         use NetBSD-style rc.d configuration ],
-       if test "x$enableval" = "xyes"; then
-               sysv_style=netbsd
-       fi
-       AC_MSG_RESULT([enabling NetBSD-style rc.d support])
-)
+dnl Check for overwrite the config files or not
+AC_NETATALK_OVERWRITE_CONFIG
 
-AC_ARG_ENABLE(debian,
-       [  --enable-debian         use debian-style sysv configuration ],[
-       if test "$enableval" = "yes"; then
-               sysv_style=debian
-       fi
-       AC_MSG_RESULT([enabling debian-style sysv support])
-       ]
-)
+dnl Check for LDAP support, for client-side ACL visibility
+AC_NETATALK_LDAP
 
-AC_ARG_ENABLE(systemd,
-       [  --enable-systemd        use general systemd configuration],[
-       if test "$enableval" = "yes"; then
-               sysv_style=systemd
-       fi
-       AC_MSG_RESULT([enabling general systemd support])
-       ]
-)
+dnl Check for ACL support
+AC_NETATALK_ACL
 
-dnl ----- timelord compilation (disabled by default)
-AC_MSG_CHECKING([whether timelord should be compiled])
-compile_timelord=no
-AC_ARG_ENABLE(timelord,
-       [  --enable-timelord       enable compilation of timelord server],
-       [compile_timelord="$enableval"],
-       [compile_timelord="no"]
-)
-AC_MSG_RESULT([$compile_timelord])
-
-dnl ----- a2boot compilation (disabled by default)
-AC_MSG_CHECKING([whether a2boot should be compiled])
-compile_a2boot=no
-AC_ARG_ENABLE(a2boot,
-       [  --enable-a2boot         enable compilation of Apple2 boot server],
-       [compile_a2boot="$enableval"],
-       [compile_a2boot="no"]
-)
-AC_MSG_RESULT([$compile_a2boot])
+dnl Check for Extended Attributes support
+AC_NETATALK_EXTENDED_ATTRIBUTES
 
-AC_ARG_WITH(uams-path,
-       [  --with-uams-path=PATH   path to UAMs [[PKGCONF/uams]]],[
-               uams_path="$withval"
-       ],[
-               uams_path="${PKGCONFDIR}/uams"
-       ]
-)
+dnl Check for libsmbsharemodes from Samba for Samba/Netatalk access/deny/share modes interop
+AC_NETATALK_SMB_SHAREMODES
 
-NETATALK_AC_CUPS
+dnl Check if realpath() takes NULL
+AC_NETATALK_REALPATH
 
-dnl check if we can use attribute unused (gcc only) from ethereal
-AC_MSG_CHECKING(to see if we can add '__attribute__((unused))' to CFLAGS)
-if test x$GCC != x ; then
-  CFLAGS="-D_U_=\"__attribute__((unused))\" $CFLAGS"
-  AC_MSG_RESULT(yes)
-else
-  CFLAGS="-D_U_=\"\" $CFLAGS"
-  AC_MSG_RESULT(no)
-fi
+dnl Check for sendfile()
+AC_NETATALK_SENDFILE
 
 dnl --------------------------------------------------------------------------
 dnl FHS stuff has to be done last because it overrides other defaults
@@ -543,12 +260,17 @@ dnl --------------------------------------------------------------------------
 dnl post-FHS substitutions, etc
 dnl --------------------------------------------------------------------------
 
-dnl ***** UAMS_PATH
-dnl AC_DEFINE_UNQUOTED(UAMS_PATH, "${uams_path}",
-dnl    [path to UAMs [default=PKGCONF/uams]])
 UAMS_PATH="${uams_path}"
 AC_SUBST(UAMS_PATH)
 
+
+dnl --------------------------------------------------------------------------
+dnl OS specific configuration comes in here:
+dnl --------------------------------------------------------------------------
+
+AC_NETATALK_OS_SPECIFIC
+
+
 dnl --------------------------------------------------------------------------
 dnl drop in includes for top level directory structures here...
 dnl --------------------------------------------------------------------------
@@ -557,734 +279,18 @@ dnl Note: $(top_srcdir)/include should be added before all other includes
 dnl       so that includes from that directory a preferred to includes from
 dnl       /usr/include or similar places.
 LIBS="$LIBS -L\$(top_srcdir)/libatalk"
-CFLAGS="-I\$(top_srcdir)/include $CFLAGS -I\$(top_srcdir)/sys"
+CFLAGS="-I\$(top_srcdir)/include -I\$(top_srcdir)/sys $CFLAGS"
 
-AC_DEFINE(OPEN_NOFOLLOW_ERRNO, ELOOP, errno returned by open with O_NOFOLLOW)
 
 dnl --------------------------------------------------------------------------
-dnl specific configuration comes in here:
+dnl Last minute substitutions
 dnl --------------------------------------------------------------------------
 
 dnl ac_cv_target_os is now host_os, ac_cv_target_cpu is now host_cpu
-
-dnl --------------------- determine operating system from "target"
-case "$host_os" in
-       *aix*)                          this_os=aix ;;
-       *kfreebsd*-gnu)                 this_os=kfreebsd-gnu ;;
-       *freebsd*)                      this_os=freebsd ;;
-       *hpux11*)                       this_os=hpux11 ;;
-       *irix*)                         this_os=irix ;;
-       *linux*)                        this_os=linux ;;
-       *osx*)                          this_os=macosx ;;
-       *darwin*)                       this_os=macosx ;;
-       *netbsd*)                       this_os=netbsd ;;
-       *openbsd*)                      this_os=openbsd ;;
-       *osf*)                          this_os=tru64 ;;
-       *solaris*)                      this_os=solaris ;;
-esac
-
-case "$host_cpu" in
-       i386|i486|i586|i686|k7)         this_cpu=x86 ;;
-       alpha)                                          this_cpu=alpha ;;
-       mips)                                           this_cpu=mips ;;
-       powerpc|ppc)                            this_cpu=ppc ;;
-esac
-
-dnl --------------------- GNU source
-case "$this_os" in
-       linux)  AC_DEFINE(_GNU_SOURCE, 1, [Whether to use GNU libc extensions])
-        ;;
-     kfreebsd-gnu) AC_DEFINE(_GNU_SOURCE, 1, [Whether to use GNU libc extensions])
-        ;;
-esac
-
-dnl --------------------- operating system specific flags (port from sys/*)
-
-dnl ----- AIX specific -----
-if test x"$this_os" = "xaix"; then
-       AC_MSG_RESULT([ * AIX specific configuration])
-       AC_DEFINE(NO_STRUCT_TM_GMTOFF, 1, [Define if the gmtoff member of struct tm is not available])
-
-       dnl This is probably a lie; AIX 4.3 supports a 64-bit long
-       dnl compilation environment.  It's enough to get things defined
-       dnl right in endian.h provided that long long is supported, though.
-       AC_DEFINE(HAVE_32BIT_LONGS, 1, [Define if the data type long has 32 bit])
-fi
-
-dnl ----- FreeBSD specific -----
-if test x"$this_os" = "xfreebsd"; then 
-       AC_MSG_RESULT([ * FreeBSD specific configuration])
-       AC_DEFINE(BSD4_4, 1, [BSD compatiblity macro])
-       AC_DEFINE(FREEBSD, 1, [Define if OS is FreeBSD])
-    AC_DEFINE(OPEN_NOFOLLOW_ERRNO, EMLINK, errno returned by open with O_NOFOLLOW)
-fi
-
-dnl ----- GNU/kFreeBSD specific -----
-if test x"$this_os" = "xkfreebsd-gnu"; then 
-       AC_MSG_RESULT([ * GNU/kFreeBSD specific configuration])
-       AC_DEFINE(BSD4_4, 1, [BSD compatiblity macro])
-       AC_DEFINE(FREEBSD, 1, [Define if OS is FreeBSD])
-    AC_DEFINE(OPEN_NOFOLLOW_ERRNO, EMLINK, errno returned by open with O_NOFOLLOW)
-fi
-
-dnl ----- HP-UX 11 specific -----
-if test x"$this_os" = "xhpux11"; then
-       AC_MSG_RESULT([ * HP-UX 11 specific configuration])
-
-       AC_DEFINE(_ISOC9X_SOURCE, 1, [Compatibility macro])
-       AC_DEFINE(NO_STRUCT_TM_GMTOFF, 1, [Define if the gmtoff member of struct tm is not available])
-fi
-
-dnl ----- IRIX specific -----
-if test x"$this_os" = "xirix"; then
-       AC_MSG_RESULT([ * IRIX specific configuration])
-
-       AC_DEFINE(NO_STRUCT_TM_GMTOFF, 1, [Define if the gmtoff member of struct tm is not available])
-fi
-
-dnl ----- Linux specific -----
-if test x"$this_os" = "xlinux"; then 
-       AC_MSG_RESULT([ * Linux specific configuration])
-       
-       dnl ----- kernel 2.6 changed struct at_addr to atalk_addr
-       AC_MSG_CHECKING([for struct atalk_addr])
-dnl    AC_COMPILE_IFELSE([
-       AC_TRY_COMPILE([
-#include <sys/socket.h>
-#include <asm/types.h>
-#include <linux/atalk.h>
-
-       struct atalk_addr foo;
-],
-[ ], [
-               ac_have_atalk_addr=yes
-               AC_MSG_RESULT([yes])
-       ], [
-               AC_MSG_RESULT([no])
-       ])
-
-if test "x$ac_have_atalk_addr" = "xyes"; then
-       AC_DEFINE(HAVE_ATALK_ADDR, 1, [set if struct at_addr is called atalk_addr])
-fi
-
-       dnl ----- check if we need the quotactl wrapper
-#      AC_CHECK_HEADERS(sys/quota.h linux/quota.h)
-#      AC_CHECK_FUNC(quotactl,,
-#              AC_DEFINE(NEED_QUOTACTL_WRAPPER, 1, [Define if the quotactl wrapper is needed])
-#              AC_MSG_RESULT([enabling quotactl wrapper])
-#      )
-
-        # For quotas on Linux XFS filesystems
-        
-        # For linux > 2.5.56
-        AC_CHECK_HEADERS(linux/dqblk_xfs.h,,
-               [AC_CHECK_HEADERS(linux/xqm.h linux/xfs_fs.h)
-               AC_CHECK_HEADERS(xfs/libxfs.h xfs/xqm.h xfs/xfs_fs.h)]
-       )
-
-
-       dnl ----- as far as I can tell, dbtob always does the wrong thing
-       dnl ----- on every single version of linux I've ever played with.
-       dnl ----- see etc/afpd/quota.c
-       AC_DEFINE(HAVE_BROKEN_DBTOB, 1, [Define if dbtob is broken])
-
-
-       dnl ----- Linux/alpha specific -----
-       if test x"$this_cpu" = "xalpha"; then 
-               AC_MSG_RESULT([enabling gcc memcpy bug workaround])
-               AC_DEFINE(HAVE_GCC_MEMCPY_BUG, 1, [Define if memcpy is buggy])
-       fi
-       need_dash_r=no
-
-
-fi
-
-dnl ----- Mac OSX specific -----
-if test x"$this_os" = "xmacosx"; then 
-       AC_MSG_RESULT([ * Mac OSX specific configuration])
-       AC_DEFINE(BSD4_4, 1, [BSD compatiblity macro])
-       AC_DEFINE(HAVE_2ARG_DBTOB, 1, [Define if dbtob takes two arguments])
-       dnl AC_DEFINE(NO_DLFCN_H)
-       AC_DEFINE(NO_DDP, 1, [Define if DDP should be disabled])
-       AC_DEFINE(NO_QUOTA_SUPPORT, 1, [Define if Quota support should be disabled])
-       AC_DEFINE(MACOSX_SERVER, 1, [Define if compiling for MacOS X Server])
-fi
-
-dnl ----- NetBSD specific -----
-if test x"$this_os" = "xnetbsd"; then 
-       AC_MSG_RESULT([ * NetBSD specific configuration])
-       AC_DEFINE(BSD4_4, 1, [BSD compatiblity macro])
-       AC_DEFINE(NETBSD, 1, [Define if OS is NetBSD])
-    AC_DEFINE(OPEN_NOFOLLOW_ERRNO, EFTYPE, errno returned by open with O_NOFOLLOW)
-
-       CFLAGS="-I\$(top_srcdir)/sys/netbsd $CFLAGS"
-       need_dash_r=yes 
-
-       dnl ----- NetBSD does not have crypt.h, uses unistd.h -----
-       AC_DEFINE(UAM_DHX, 1, [Define if the DHX UAM modules should be compiled])
-fi
-
-dnl ----- OpenBSD specific -----
-if test x"$this_os" = "xopenbsd"; then 
-       AC_MSG_RESULT([ * OpenBSD specific configuration])
-    AC_DEFINE(BSD4_4, 1, [BSD compatiblity macro])
-       dnl ----- OpenBSD does not have crypt.h, uses unistd.h -----
-       AC_DEFINE(UAM_DHX, 1, [Define if the DHX UAM modules should be compiled])
-    AC_DEFINE(NO_DDP, 1, [Define if DDP should be disabled])
-fi
-
-dnl ----- Solaris specific -----
-if test x"$this_os" = "xsolaris"; then 
-       AC_MSG_RESULT([ * Solaris specific configuration])
-       AC_DEFINE(__svr4__, 1, [Solaris compatibility macro])
-       AC_DEFINE(_ISOC9X_SOURCE, 1, [Compatibility macro])
-       AC_DEFINE(NO_STRUCT_TM_GMTOFF, 1, [Define if the gmtoff member of struct tm is not available])
-       AC_DEFINE(SOLARIS, 1, [Solaris compatibility macro])
-    AC_DEFINE(_XOPEN_SOURCE, 600, [Solaris compilation environment])
-    AC_DEFINE(__EXTENSIONS__,  1, [Solaris compilation environment])
-       CFLAGS="-I\$(top_srcdir)/sys/generic $CFLAGS"
-       need_dash_r=yes
-       sysv_style=solaris
-
-       solaris_module=no
-       AC_MSG_CHECKING([if we can build Solaris kernel module])
-       if test -x /usr/ccs/bin/ld && test x"$netatalk_cv_ddp_enabled" = x"yes" ; then
-               solaris_module=yes
-       fi
-       AC_MSG_RESULT([$solaris_module])
-
-       COMPILE_64BIT_KMODULE=no
-       KCFLAGS=""
-       KLDFLAGS=""
-       COMPILE_KERNEL_GCC=no
-
-       if test "$solaris_module" = "yes"; then
-          dnl Solaris kernel module stuff
-           AC_MSG_CHECKING([if we have to build a 64bit kernel module])
-
-          # check for isainfo, if not found it has to be a 32 bit kernel (<=2.6)       
-          if test -x /usr/bin/isainfo; then
-               # check for 64 bit platform
-               if isainfo -kv | grep '^64-bit'; then
-                       COMPILE_64BIT_KMODULE=yes
-               fi
-          fi
-
-          AC_MSG_RESULT([$COMPILE_64BIT_KMODULE])
-
-          if test "${GCC}" = yes; then
-               COMPILE_KERNEL_GCC=yes
-               if test "$COMPILE_64BIT_KMODULE" = yes; then
-               
-                        AC_MSG_CHECKING([if we can build a 64bit kernel module])
-                       
-                        case `$CC --version 2>/dev/null` in
-                       [[12]].* | 3.0.*)
-                               COMPILE_64BIT_KMODULE=no
-                               COMPILE_KERNEL_GCC=no   
-                               solaris_module=no;;
-                       *)
-                               # use for 64 bit
-                               KCFLAGS="-m64"
-                               #KLDFLAGS="-melf64_sparc"
-                               KLDFLAGS="-64";;
-                       esac    
-                       
-                       AC_MSG_RESULT([$COMPILE_64BIT_KMODULE])
-                       
-               else
-                       KCFLAGS=""
-                       KLDFLAGS=""
-               fi
-               KCFLAGS="$KCFLAGS -D_KERNEL -Wall -Wstrict-prototypes"
-           else
-               if test "$COMPILE_64BIT_KMODULE" = yes; then
-                # use Sun CC (for a 64-bit kernel, uncomment " -xarch=v9 -xregs=no%appl ")
-                       KCFLAGS="-xarch=v9 -xregs=no%appl"
-                       KLDFLAGS="-64"
-               else
-                       KCFLAGS=""
-                       KLDFLAGS=""
-               fi
-               KCFLAGS="-D_KERNEL $KCFLAGS -mno-app-regs -munaligned-doubles -fpcc-struct-return"
-          fi
-
-           AC_CACHE_CHECK([for timeout_id_t],netatalk_cv_HAVE_TIMEOUT_ID_T,[
-           AC_TRY_LINK([\
-#include <sys/stream.h>
-#include <sys/ddi.h>],
-[\
-timeout_id_t dummy;
-],
-netatalk_cv_HAVE_TIMEOUT_ID_T=yes,netatalk_cv_HAVE_TIMEOUT_ID_T=no,netatalk_cv_HAVE_TIMEOUT_ID_T=cross)])
-
-          AC_DEFINE(HAVE_TIMEOUT_ID_T, test x"$netatalk_cv_HAVE_TIMEOUT_ID" = x"yes", [define for timeout_id_t])
-       fi
-
-       AC_SUBST(COMPILE_KERNEL_GCC)
-       AC_SUBST(COMPILE_64BIT_KMODULE)
-       AC_SUBST(KCFLAGS)
-       AC_SUBST(KLDFLAGS)
-fi
-
-dnl ----- Tru64 specific -----
-if test x"$this_os" = "xtru64"; then 
-       AC_MSG_RESULT([ * Tru64 specific configuration])
-       AC_DEFINE(NO_DDP, 1, [Define if DDP should be disabled])
-       AC_DEFINE(HAVE_64BIT_LONGS, 1, [Define if the data type long has 64 bit])
-       dnl AC_DEFINE(USE_MOUNT_H)
-       AC_DEFINE(USE_OLD_RQUOTA, 1, [Define to use old rquota])
-       dnl AC_DEFINE(USE_UFS_QUOTA_H)
-       AC_DEFINE(TRU64, 1, [Define on Tru64 platforms])
-       AC_DEFINE(_OSF_SOURCE, 1, [Define if the *passwd UAMs should be used])
-       AC_DEFINE(_XOPEN_SOURCE_EXTENDED, 1, [Define for Berkeley DB 4])
-       AC_CHECK_LIB(security,set_auth_parameters)
-       CFLAGS="-I\$(top_srcdir)/sys/tru64 $CFLAGS"
-       need_dash_r=no
-       sysv_style=tru64
-fi
-
-dnl ------ Check for sendfile() --------
-netatalk_cv_search_sendfile=yes
-AC_ARG_ENABLE(sendfile,
-    [  --disable-sendfile       disable sendfile syscall],
-    [if test x"$enableval" = x"no"; then
-            netatalk_cv_search_sendfile=no
-        fi]
-)
-
-if test x"$netatalk_cv_search_sendfile" = x"yes"; then
-   case "$host_os" in
-   *linux*)
-        AC_DEFINE(SENDFILE_FLAVOR_LINUX,1,[Whether linux sendfile() API is available])
-        AC_CHECK_FUNC([sendfile], [netatalk_cv_HAVE_SENDFILE=yes])
-        ;;
-
-    *solaris*)
-        AC_DEFINE(SENDFILE_FLAVOR_SOLARIS, 1, [Solaris sendfile()])
-        AC_SEARCH_LIBS(sendfile, sendfile)
-        AC_CHECK_FUNC([sendfile], [netatalk_cv_HAVE_SENDFILE=yes])
-        ;;
-
-    *freebsd*)
-        AC_DEFINE(SENDFILE_FLAVOR_BSD, 1, [Define if the sendfile() function uses BSD semantics])
-        AC_CHECK_FUNC([sendfile], [netatalk_cv_HAVE_SENDFILE=yes])
-        ;;
-
-    *)
-        ;;
-
-    esac
-
-    if test x"$netatalk_cv_HAVE_SENDFILE" = x"yes"; then
-        AC_DEFINE(WITH_SENDFILE,1,[Whether sendfile() should be used])
-    fi
-fi
-
-dnl -- check for libgcrypt, if found enables DHX UAM
-AM_PATH_LIBGCRYPT([1:1.2.3],[neta_cv_compile_dhx2=yes
-                       neta_cv_have_libgcrypt=yes
-                       AC_MSG_NOTICE([Enabling DHX2 UAM])
-                       AC_DEFINE(HAVE_LIBGCRYPT, 1, [Define if the DHX2 modules should be built with libgcrypt])
-                       AC_DEFINE(UAM_DHX2, 1, [Define if the DHX2 UAM modules should be compiled])
-                       ])
-
-dnl -- look for openssl, if found enables DHX UAM and Randnum UAM
-AC_PATH_SSL
-
-dnl Check for Berkeley DB library
-if test "x$bdb_required" = "xyes"; then
-       AC_PATH_BDB(, [
-               AC_MSG_RESULT([])
-               AC_MSG_RESULT([Make sure you have the required Berkeley DB libraries AND headers installed.])
-               AC_MSG_RESULT([You can download the latest version from http://www.sleepycat.com.])
-               AC_MSG_RESULT([If you have installed BDB in a non standard location use the])
-               AC_MSG_RESULT([--with-bdb=/path/to/bdb configure option and make sure])
-               AC_MSG_RESULT([your linker is configured to check for libraries there.])
-               AC_MSG_ERROR([Berkeley DB library required but not found!])
-       ])
-fi
-
-dnl -- check for crypt
-AC_CRYPT
-
-dnl --------------------- check for building PGP UAM module
-
-AC_MSG_CHECKING([whether the PGP UAM should be build])
-AC_ARG_ENABLE(pgp-uam,
-       [  --enable-pgp-uam        enable build of PGP UAM module],[
-       if test "$enableval" = "yes"; then 
-               if test "x$neta_cv_have_openssl" = "xyes"; then 
-                       AC_DEFINE(UAM_PGP, 1, [Define if the PGP UAM module should be compiled])
-                       compile_pgp=yes
-                       AC_MSG_RESULT([yes])
-               else
-                       AC_MSG_RESULT([no])
-               fi
-       fi
-       ],[
-               AC_MSG_RESULT([no])
-       ]
-)
-
-dnl --------------------- check for building Kerberos v4 UAM module
-
-AC_MSG_CHECKING([whether the Kerberos IV UAM should be build])
-AC_ARG_ENABLE(krb4-uam,
-       [  --enable-krb4-uam       enable build of Kerberos v4 UAM module],[
-       if test "$enableval" = "yes"; then
-               AC_DEFINE(UAM_KRB4, 1, [Define if the Kerberos 4 UAM module should be compiled])
-               compile_kerberos=yes
-               AC_MSG_RESULT([yes])
-       else
-               AC_MSG_RESULT([no])
-       fi
-       ],[
-               AC_MSG_RESULT([no])
-       ]
-)
-
-dnl --------------------- check for building Kerberos V UAM module
-
-netatalk_cv_build_krb5_uam=no
-AC_ARG_ENABLE(krbV-uam,
-       [  --enable-krbV-uam       enable build of Kerberos V UAM module],
-       [
-               if test x"$enableval" = x"yes"; then
-                       NETATALK_GSSAPI_CHECK([
-                               netatalk_cv_build_krb5_uam=yes
-                       ],[
-                               AC_MSG_ERROR([need GSSAPI to build Kerberos V UAM])
-                       ])
-               fi
-       ]
-       
-)
-
-AC_MSG_CHECKING([whether Kerberos V UAM should be build])
-if test x"$netatalk_cv_build_krb5_uam" = x"yes"; then
-       AC_MSG_RESULT([yes])
-else
-       AC_MSG_RESULT([no])
-fi
-AM_CONDITIONAL(USE_GSSAPI, test x"$netatalk_cv_build_krb5_uam" = x"yes")
-
-dnl --------------------- overwrite the config files . . . or not.
-
-AC_MSG_CHECKING([whether configuration files should be overwritten])
-AC_ARG_ENABLE(overwrite,
-       [  --enable-overwrite      overwrite configuration files during installation],
-       [OVERWRITE_CONFIG="${enable_overwrite}"],
-       [OVERWRITE_CONFIG="no"]
-)
-AC_MSG_RESULT([$OVERWRITE_CONFIG])
-
-dnl --------------------- check for LDAP support, for client-side ACL visibility
-AC_MSG_CHECKING(for LDAP (necessary for client-side ACL visibility))
-AC_ARG_WITH(ldap,
-    [AS_HELP_STRING([--with-ldap],
-        [LDAP support (default=auto)])],
-    [ case "$withval" in
-      yes|no)
-          with_ldap="$withval"
-                 ;;
-      *)
-          with_ldap=auto
-          ;;
-      esac ])
-AC_MSG_RESULT($with_ldap)
-
-if test x"$with_ldap" != x"no" ; then
-       AC_CHECK_HEADER([ldap.h], with_ldap=yes,
-        [ if test x"$with_ldap" = x"yes" ; then
-            AC_MSG_ERROR([Missing LDAP headers])
-        fi
-               with_ldap=no
-        ])
-       AC_CHECK_LIB(ldap, ldap_init, with_ldap=yes,
-        [ if test x"$with_ldap" = x"yes" ; then
-            AC_MSG_ERROR([Missing LDAP library])
-        fi
-               with_ldap=no
-        ])
-fi
-
-if test x"$with_ldap" = x"yes"; then
-       AC_DEFINE(HAVE_LDAP,1,[Whether LDAP is available])
-fi
-
-dnl --------------------- check for ACL support
-AC_MSG_CHECKING(whether to support ACLs)
-AC_ARG_WITH(acls,
-    [AS_HELP_STRING([--with-acls],
-        [Include ACL support (default=auto)])],
-    [ case "$withval" in
-      yes|no)
-          with_acl_support="$withval"
-                 ;;
-      *)
-          with_acl_support=auto
-          ;;
-      esac ],
-    [with_acl_support=auto])
-AC_MSG_RESULT($with_acl_support)
-
-if test x"$with_acl_support" = x"no"; then
-       AC_MSG_RESULT(Disabling ACL support)
-       AC_DEFINE(HAVE_NO_ACLS,1,[Whether no ACLs support should be built in])
-else
-    with_acl_support=yes
-fi
-
-if test x"$with_acl_support" = x"yes" ; then
-       AC_MSG_NOTICE(checking whether ACL support is available:)
-       case "$host_os" in
-       *sysv5*)
-               AC_MSG_NOTICE(Using UnixWare ACLs)
-               AC_DEFINE(HAVE_UNIXWARE_ACLS,1,[Whether UnixWare ACLs are available])
-               ;;
-       *solaris*)
-               AC_MSG_NOTICE(Using solaris ACLs)
-               AC_DEFINE(HAVE_SOLARIS_ACLS,1,[Whether solaris ACLs are available])
-               ACL_LIBS="$ACL_LIBS -lsec"
-               ;;
-       *hpux*)
-               AC_MSG_NOTICE(Using HPUX ACLs)
-               AC_DEFINE(HAVE_HPUX_ACLS,1,[Whether HPUX ACLs are available])
-               ;;
-       *irix*)
-               AC_MSG_NOTICE(Using IRIX ACLs)
-               AC_DEFINE(HAVE_IRIX_ACLS,1,[Whether IRIX ACLs are available])
-               ;;
-       *aix*)
-               AC_MSG_NOTICE(Using AIX ACLs)
-               AC_DEFINE(HAVE_AIX_ACLS,1,[Whether AIX ACLs are available])
-               ;;
-       *osf*)
-               AC_MSG_NOTICE(Using Tru64 ACLs)
-               AC_DEFINE(HAVE_TRU64_ACLS,1,[Whether Tru64 ACLs are available])
-               ACL_LIBS="$ACL_LIBS -lpacl"
-               ;;
-       *darwin*)
-               AC_MSG_NOTICE(ACLs on Darwin currently not supported)
-               AC_DEFINE(HAVE_NO_ACLS,1,[Whether no ACLs support is available])
-               ;;
-       *)
-               AC_CHECK_LIB(acl,acl_get_file,[ACL_LIBS="$ACL_LIBS -lacl"])
-               case "$host_os" in
-               *linux*)
-                       AC_CHECK_LIB(attr,getxattr,[ACL_LIBS="$ACL_LIBS -lattr"])
-                       ;;
-               esac
-               AC_CACHE_CHECK([for POSIX ACL support],netatalk_cv_HAVE_POSIX_ACLS,[
-                       acl_LIBS=$LIBS
-                       LIBS="$LIBS $ACL_LIBS"
-                       AC_TRY_LINK([
-                               #include <sys/types.h>
-                               #include <sys/acl.h>
-                       ],[
-                               acl_t acl;
-                               int entry_id;
-                               acl_entry_t *entry_p;
-                               return acl_get_entry(acl, entry_id, entry_p);
-                       ],
-                       [netatalk_cv_HAVE_POSIX_ACLS=yes],
-                       [netatalk_cv_HAVE_POSIX_ACLS=no
-                with_acl_support=no])
-                       LIBS=$acl_LIBS
-               ])
-               if test x"$netatalk_cv_HAVE_POSIX_ACLS" = x"yes"; then
-                       AC_MSG_NOTICE(Using POSIX ACLs)
-                       AC_DEFINE(HAVE_POSIX_ACLS,1,[Whether POSIX ACLs are available])
-                       AC_CACHE_CHECK([for acl_get_perm_np],netatalk_cv_HAVE_ACL_GET_PERM_NP,[
-                               acl_LIBS=$LIBS
-                               LIBS="$LIBS $ACL_LIBS"
-                               AC_TRY_LINK([
-                                       #include <sys/types.h>
-                                       #include <sys/acl.h>
-                               ],[
-                                       acl_permset_t permset_d;
-                                       acl_perm_t perm;
-                                       return acl_get_perm_np(permset_d, perm);
-                               ],
-                               [netatalk_cv_HAVE_ACL_GET_PERM_NP=yes],
-                               [netatalk_cv_HAVE_ACL_GET_PERM_NP=no])
-                               LIBS=$acl_LIBS
-                       ])
-                       if test x"$netatalk_cv_HAVE_ACL_GET_PERM_NP" = x"yes"; then
-                               AC_DEFINE(HAVE_ACL_GET_PERM_NP,1,[Whether acl_get_perm_np() is available])
-                       fi
-
-                       AC_CACHE_CHECK([for acl_from_mode], netatalk_cv_HAVE_ACL_FROM_MODE,[
-                               acl_LIBS=$LIBS
-                               LIBS="$LIBS $ACL_LIBS"
-                AC_CHECK_FUNCS(acl_from_mode,
-                               [netatalk_cv_HAVE_ACL_FROM_MODE=yes],
-                               [netatalk_cv_HAVE_ACL_FROM_MODE=no])
-                               LIBS=$acl_LIBS
-                       ])
-                       if test x"netatalk_cv_HAVE_ACL_FROM_MODE" = x"yes"; then
-                               AC_DEFINE(HAVE_ACL_FROM_MODE,1,[Whether acl_from_mode() is available])
-                       fi
-
-
-               else
-                       AC_MSG_NOTICE(ACL support is not avaliable)
-                       AC_DEFINE(HAVE_NO_ACLS,1,[Whether no ACLs support is available])
-               fi
-               ;;
-    esac
-fi
-
-if test x"$with_acl_support" = x"yes" ; then
-   AC_CHECK_HEADERS([acl/libacl.h])
-    AC_DEFINE(HAVE_ACLS,1,[Whether ACLs support is available])
-    AC_SUBST(ACL_LIBS)
-fi
-
-dnl --------------------- check for Extended Attributes support
-neta_cv_eas="ad"
-neta_cv_eas_sys_found=no
-neta_cv_eas_sys_not_found=no
-
-AC_CHECK_HEADERS(sys/attributes.h attr/xattr.h sys/xattr.h sys/extattr.h sys/uio.h sys/ea.h)
-
-case "$this_os" in
-
-  *osf*)
-       AC_SEARCH_LIBS(getproplist, [proplist])
-       AC_CHECK_FUNCS([getproplist fgetproplist setproplist fsetproplist],
-                   [neta_cv_eas_sys_found=yes],
-                   [neta_cv_eas_sys_not_found=yes])
-       AC_CHECK_FUNCS([delproplist fdelproplist add_proplist_entry get_proplist_entry],,
-                   [neta_cv_eas_sys_not_found=yes])
-       AC_CHECK_FUNCS([sizeof_proplist_entry],,
-                   [neta_cv_eas_sys_not_found=yes])
-  ;;
-
-  *solaris*)
-       AC_CHECK_FUNCS([attropen],
-                   [neta_cv_eas_sys_found=yes],
-                   [neta_cv_eas_sys_not_found=yes])
-  ;;
-
-  'freebsd')
-    AC_CHECK_FUNCS([extattr_delete_fd extattr_delete_file extattr_delete_link],
-                   [neta_cv_eas_sys_found=yes],
-                   [neta_cv_eas_sys_not_found=yes])
-    AC_CHECK_FUNCS([extattr_get_fd extattr_get_file extattr_get_link],,
-                   [neta_cv_eas_sys_not_found=yes])
-    AC_CHECK_FUNCS([extattr_list_fd extattr_list_file extattr_list_link],,
-                   [neta_cv_eas_sys_not_found=yes])
-    AC_CHECK_FUNCS([extattr_set_fd extattr_set_file extattr_set_link],,
-                   [neta_cv_eas_sys_not_found=yes])
-  ;;
-
-  *freebsd4* | *dragonfly* )
-    AC_DEFINE(BROKEN_EXTATTR, 1, [Does extattr API work])
-  ;;
-
-  *)
-       AC_SEARCH_LIBS(getxattr, [attr])
-
-    if test "x$neta_cv_eas_sys_found" != "xyes" ; then
-       AC_CHECK_FUNCS([getxattr lgetxattr fgetxattr listxattr llistxattr],
-                      [neta_cv_eas_sys_found=yes],
-                      [neta_cv_eas_sys_not_found=yes])
-          AC_CHECK_FUNCS([flistxattr removexattr lremovexattr fremovexattr],,
-                      [neta_cv_eas_sys_not_found=yes])
-          AC_CHECK_FUNCS([setxattr lsetxattr fsetxattr],,
-                      [neta_cv_eas_sys_not_found=yes])
-    fi
-
-    if test "x$neta_cv_eas_sys_found" != "xyes" ; then
-          AC_CHECK_FUNCS([getea fgetea lgetea listea flistea llistea],
-                      [neta_cv_eas_sys_found=yes],
-                      [neta_cv_eas_sys_not_found=yes])
-          AC_CHECK_FUNCS([removeea fremoveea lremoveea setea fsetea lsetea],,
-                      [neta_cv_eas_sys_not_found=yes])
-    fi
-
-    if test "x$neta_cv_eas_sys_found" != "xyes" ; then
-          AC_CHECK_FUNCS([attr_get attr_list attr_set attr_remove],,
-                      [neta_cv_eas_sys_not_found=yes])
-       AC_CHECK_FUNCS([attr_getf attr_listf attr_setf attr_removef],,
-                      [neta_cv_eas_sys_not_found=yes])
-    fi
-  ;;
-esac
-
-# Do xattr functions take additional options like on Darwin?
-if test x"$ac_cv_func_getxattr" = x"yes" ; then
-       AC_CACHE_CHECK([whether xattr interface takes additional options], smb_attr_cv_xattr_add_opt, [
-               old_LIBS=$LIBS
-               LIBS="$LIBS $ACL_LIBS"
-               AC_TRY_COMPILE([
-                       #include <sys/types.h>
-                       #if HAVE_ATTR_XATTR_H
-                       #include <attr/xattr.h>
-                       #elif HAVE_SYS_XATTR_H
-                       #include <sys/xattr.h>
-                       #endif
-               ],[
-                       getxattr(0, 0, 0, 0, 0, 0);
-               ],
-               [smb_attr_cv_xattr_add_opt=yes],
-               [smb_attr_cv_xattr_add_opt=no;LIBS=$old_LIBS])
-       ])
-       if test x"$smb_attr_cv_xattr_add_opt" = x"yes"; then
-               AC_DEFINE(XATTR_ADD_OPT, 1, [xattr functions have additional options])
-       fi
-fi
-
-if test "x$neta_cv_eas_sys_found" = "xyes" ; then
-   if test "x$neta_cv_eas_sys_not_found" != "xyes" ; then
-      neta_cv_eas="$neta_cv_eas | sys"
-   fi
-fi
-AC_DEFINE_UNQUOTED(EA_MODULES,["$neta_cv_eas"],[Available Extended Attributes modules])
-
-dnl --------------------- Check if realpath() takes NULL
-AC_CACHE_CHECK([if the realpath function allows a NULL argument],
-    neta_cv_REALPATH_TAKES_NULL, [
-        AC_TRY_RUN([
-            #include <stdio.h>
-            #include <limits.h>
-            #include <signal.h>
-
-            void exit_on_core(int ignored) {
-                 exit(1);
-            }
-
-            main() {
-                char *newpath;
-                signal(SIGSEGV, exit_on_core);
-                newpath = realpath("/tmp", NULL);
-                exit((newpath != NULL) ? 0 : 1);
-            }],
-            neta_cv_REALPATH_TAKES_NULL=yes,
-            neta_cv_REALPATH_TAKES_NULL=no,
-            neta_cv_REALPATH_TAKES_NULL=cross
-        )
-    ]
-)
-
-if test x"$neta_cv_REALPATH_TAKES_NULL" = x"yes"; then
-    AC_DEFINE(REALPATH_TAKES_NULL,1,[Whether the realpath function allows NULL])
-fi
-
-dnl --------------------- Netatalk Webmin
-NETATALK_WEBMIN
-
-dnl --------------------- last minute substitutions
-
 AC_SUBST(LIBS)
 AC_SUBST(CFLAGS)
-AC_SUBST(OVERWRITE_CONFIG)
 
 AM_CONDITIONAL(SOLARIS_MODULE, test x$solaris_module = xyes)
-AM_CONDITIONAL(COMPILE_TIMELORD, test x$compile_timelord = xyes)
-AM_CONDITIONAL(COMPILE_A2BOOT, test x$compile_a2boot = xyes)
 AM_CONDITIONAL(HAVE_LIBGCRYPT, test x$neta_cv_have_libgcrypt = xyes)
 AM_CONDITIONAL(HAVE_OPENSSL, test x$neta_cv_have_openssl = xyes)
 AM_CONDITIONAL(HAVE_ACLS, test x"$with_acl_support" = x"yes")
@@ -1292,24 +298,12 @@ AM_CONDITIONAL(HAVE_LDAP, test x"$with_ldap" = x"yes")
 AM_CONDITIONAL(USE_DHX, test x$neta_cv_compile_dhx = xyes)
 AM_CONDITIONAL(USE_DHX2, test x$neta_cv_compile_dhx2 = xyes)
 AM_CONDITIONAL(USE_RANDNUM, test x$neta_cv_have_openssl = xyes)
-AM_CONDITIONAL(USE_KERBEROS, test x$compile_kerberos = xyes)
 AM_CONDITIONAL(USE_PAM_SO, test x$use_pam_so = xyes)
 AM_CONDITIONAL(USE_PAM, test x$netatalk_cv_install_pam = xyes)
 AM_CONDITIONAL(BUILD_PAM, test x$compile_pam = xyes)
 AM_CONDITIONAL(USE_PGP, test x$compile_pgp = xyes)
 AM_CONDITIONAL(DEFAULT_HOOK, test x$neta_cv_have_libgcrypt != xyes && test x$neta_cv_have_openssl != xyes)
-AM_CONDITIONAL(USE_NETBSD, test x$sysv_style = xnetbsd)
-AM_CONDITIONAL(USE_REDHAT_SYSV, test x$sysv_style = xredhat-sysv)
-AM_CONDITIONAL(USE_SUSE_SYSV, test x$sysv_style = xsuse-sysv)
-AM_CONDITIONAL(USE_SHADOWPW, test x$shadowpw = xyes)
-AM_CONDITIONAL(USE_TRU64, test x$sysv_style = xtru64)
-AM_CONDITIONAL(USE_SOLARIS, test x$sysv_style = xsolaris)
-AM_CONDITIONAL(USE_GENTOO, test x$sysv_style = xgentoo)
-AM_CONDITIONAL(USE_DEBIAN, test x$sysv_style = xdebian)
-AM_CONDITIONAL(USE_SYSTEMD, test x$sysv_style = xsystemd || test x$sysv_style = xredhat-systemd || test x$sysv_style = xsuse-systemd)
-AM_CONDITIONAL(USE_UNDEF, test x$sysv_style = x)
 AM_CONDITIONAL(USE_BDB, test x$bdb_required = xyes)
-AM_CONDITIONAL(USE_APPLETALK, test x$netatalk_cv_ddp_enabled = xyes)
 AM_CONDITIONAL(HAVE_ATFUNCS, test x"$ac_neta_haveatfuncs" = x"yes")
 
 dnl --------------------- generate files
@@ -1317,30 +311,20 @@ dnl --------------------- generate files
 AC_OUTPUT([Makefile
        bin/Makefile
        bin/ad/Makefile
-       bin/adv1tov2/Makefile
-       bin/aecho/Makefile
        bin/afppasswd/Makefile
        bin/cnid/Makefile
        bin/cnid/cnid2_create
-       bin/getzones/Makefile
        bin/megatron/Makefile
-       bin/misc/Makefile
-       bin/nbp/Makefile
-       bin/pap/Makefile
-       bin/psorder/Makefile
+    bin/misc/Makefile
        bin/uniconv/Makefile
        config/Makefile
        config/pam/Makefile
        contrib/Makefile
        contrib/macusers/Makefile
        contrib/macusers/macusers
-       contrib/misc/Makefile
-       contrib/printing/Makefile
        contrib/shell_utils/Makefile
        contrib/shell_utils/apple_dump
        contrib/shell_utils/asip-status.pl
-       contrib/timelord/Makefile
-       contrib/a2boot/Makefile
        distrib/Makefile
        distrib/config/Makefile
        distrib/config/netatalk-config
@@ -1350,19 +334,13 @@ AC_OUTPUT([Makefile
        doc/Makefile
        etc/Makefile
        etc/afpd/Makefile
-       etc/atalkd/Makefile
        etc/cnid_dbd/Makefile
        etc/uams/Makefile
-       etc/uams/uams_krb4/Makefile
-       etc/papd/Makefile
-       etc/psf/Makefile
        include/Makefile
        include/atalk/Makefile
        libatalk/Makefile
        libatalk/acl/Makefile
        libatalk/adouble/Makefile
-       libatalk/asp/Makefile
-       libatalk/atp/Makefile
        libatalk/bstring/Makefile
        libatalk/cnid/Makefile
        libatalk/cnid/cdb/Makefile
@@ -1371,29 +349,16 @@ AC_OUTPUT([Makefile
        libatalk/cnid/tdb/Makefile
        libatalk/compat/Makefile
        libatalk/dsi/Makefile
-       libatalk/nbp/Makefile
-       libatalk/netddp/Makefile
-       libatalk/util/Makefile
        libatalk/tdb/Makefile
        libatalk/unicode/Makefile
        libatalk/unicode/charsets/Makefile
+       libatalk/util/Makefile
        libatalk/vfs/Makefile
        macros/Makefile
        man/Makefile
        man/man1/Makefile
-       man/man3/Makefile
-       man/man4/Makefile
        man/man5/Makefile
        man/man8/Makefile
-       sys/Makefile
-       sys/generic/Makefile
-       sys/generic/sys/Makefile
-       sys/netatalk/Makefile
-       sys/netbsd/Makefile
-       sys/netbsd/netatalk/Makefile
-       sys/solaris/Makefile
-       sys/sunos/Makefile
-       sys/ultrix/Makefile
        test/Makefile
        test/afpd/Makefile
        ],
index 0d2f10741ae95fa8f208fba46270e6fbe7013fcb..3c076643be908516495c3d69a1988eba0861a5c6 100644 (file)
@@ -1,15 +1,3 @@
 # Makefile.am for contrib/
 
-SUBDIRS = macusers misc shell_utils
-
-if COMPILE_TIMELORD
-SUBDIRS += timelord
-endif
-
-if COMPILE_A2BOOT
-SUBDIRS += a2boot
-endif
-
-if USE_APPLETALK
-SUBDIRS += printing
-endif
+SUBDIRS = macusers shell_utils
diff --git a/contrib/a2boot/.gitignore b/contrib/a2boot/.gitignore
deleted file mode 100644 (file)
index a751359..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-Makefile
-Makefile.in
-a2boot
-.deps
-.libs
-.gitignore
-*.o
diff --git a/contrib/a2boot/COPYRIGHT b/contrib/a2boot/COPYRIGHT
deleted file mode 100644 (file)
index c698aba..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
-       Recoding circa Dec 2002-early 2003          by Marsha Jackson
-       support booting of Apple 2 computers,   with aid of Steven N. Hirsch
-       Code is copyrighted as listed below...
-       M. Jackson is establishing no personal copyright
-       or personal restrictions on this software.  Only the below rights exist
-*/
-
-/*
- * Copyright (c) 1990,1994 Regents of The University of Michigan.
- * All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software and
- * its documentation for any purpose and without fee is hereby granted,
- * provided that the above copyright notice appears in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation, and that the name of The University
- * of Michigan not be used in advertising or publicity pertaining to
- * distribution of the software without specific, written prior
- * permission. This software is supplied as is without expressed or
- * implied warranties of any kind.
- *
- *     Research Systems Unix Group
- *     The University of Michigan
- *     c/o Wesley Craig
- *     535 W. William Street
- *     Ann Arbor, Michigan
- *     +1 313 764 2278
- *     netatalk@umich.edu
- */
-
-/*
- * The "timelord protocol" was reverse engineered from Timelord,
- * distributed with CAP, Copyright (c) 1990, The University of
- * Melbourne.  The following copyright, supplied by The University
- * of Melbourne, may apply to this code:
- *
- *     This version of timelord.c is based on code distributed
- *     by the University of Melbourne as part of the CAP package.
- *
- *     The tardis/Timelord package for Macintosh/CAP is
- *     Copyright (c) 1990, The University of Melbourne.
- */
diff --git a/contrib/a2boot/Makefile.am b/contrib/a2boot/Makefile.am
deleted file mode 100644 (file)
index 9ab8cba..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-# Makefile.am for contrib/a2boot/
-
-sbin_PROGRAMS = a2boot
-
-a2boot_SOURCES = a2boot.c
-a2boot_LDADD = $(top_builddir)/libatalk/libatalk.la
-
-LIBS = @LIBS@
-
-EXTRA_DIST = COPYRIGHT VERSION
-
-AM_CFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/sys \
-        @SLP_CFLAGS@ \
-        -D_PATH_A_GS_BLOCKS=\"$(PKGCONFDIR)/a2boot/ProDOS16\ Boot\ Blocks\" \
-        -D_PATH_A_2E_BLOCKS=\"$(PKGCONFDIR)/a2boot/Apple\ :2f:2fe\ Boot\ Blocks\" \
-        -D_PATH_P16_IMAGE=\"$(PKGCONFDIR)/a2boot/ProDOS16\ Image\"
diff --git a/contrib/a2boot/VERSION b/contrib/a2boot/VERSION
deleted file mode 100644 (file)
index 8e8299d..0000000
+++ /dev/null
@@ -1 +0,0 @@
-2.4.2
diff --git a/contrib/a2boot/a2boot.c b/contrib/a2boot/a2boot.c
deleted file mode 100644 (file)
index 77fc641..0000000
+++ /dev/null
@@ -1,317 +0,0 @@
-/*
- * $Id: a2boot.c,v 1.2 2003-01-15 06:24:28 jmarcus Exp $
- *   Apple II boot support code.       with aid of Steven N. Hirsch
- *
- * based on timelord 1.6 so below copyrights still apply
- *
- * Copyright (c) 1990,1992 Regents of The University of Michigan.
- * All Rights Reserved. See COPYRIGHT.
- *
- * The "timelord protocol" was reverse engineered from Timelord,
- * distributed with CAP, Copyright (c) 1990, The University of
- * Melbourne.  The following copyright, supplied by The University
- * of Melbourne, may apply to this code:
- *
- *     This version of timelord.c is based on code distributed
- *     by the University of Melbourne as part of the CAP package.
- *
- *     The tardis/Timelord package for Macintosh/CAP is
- *     Copyright (c) 1990, The University of Melbourne.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <sys/param.h>
-#include <sys/types.h>
-#include <sys/file.h>
-#include <sys/uio.h>
-
-#include <unistd.h>
-
-#include <netatalk/at.h>
-#include <netatalk/endian.h>
-#include <atalk/atp.h>
-#include <atalk/nbp.h>
-
-#ifdef HAVE_SGTTY_H
-#include <sgtty.h>
-#endif /* HAVE_SGTTY_H */
-
-#include <errno.h>
-#include <signal.h>
-#include <atalk/logger.h>
-#include <stdio.h>
-#include <string.h>
-
-#ifdef HAVE_NETDB_H
-#include <netdb.h>
-#endif /* HAVE_NETDB_H */
-
-#ifdef HAVE_FCNTL_H
-#include <fcntl.h>
-#endif /* HAVE_FCNTL_H */
-#ifdef HAVE_SYS_FCNTL_H
-#include <sys/fcntl.h>
-#endif /* HAVE_SYS_FCNTL_H */
-
-#ifdef HAVE_TERMIOS_H
-#include <termios.h>
-#endif /* HAVE_TERMIOS_H */
-#ifdef HAVE_SYS_TERMIOS_H
-#include <sys/termios.h>
-#endif /* HAVE_SYS_TERMIOS_H */
-
-#define        TL_OK           '\0'
-#define TL_EOF         '\1'
-
-int    debug = 0;
-char   *bad = "Bad request!";
-char   buf[ 4624 ];
-char   *server;
-int32_t fileoff;
-
-long a2bootreq(char *fname);
-
-void usage( char *p )
-{
-    char       *s;
-
-    if (( s = rindex( p, '/' )) == NULL ) {
-       s = p;
-    } else {
-       s++;
-    }
-    fprintf( stderr, "Usage:\t%s -d -n nbpname\n", s );
-    exit( 1 );
-}
-
-/*
- * Unregister ourself on signal.
- */
-void
-goaway(int signal)
-{
-    int regerr;
-    regerr = nbp_unrgstr( server, "Apple //gs", "*", NULL );
-    regerr += nbp_unrgstr( server, "Apple //e Boot", "*", NULL );
-    regerr += nbp_unrgstr( server, "ProDOS16 Image", "*", NULL );
-    if ( regerr < 0 ) {
-       LOG(log_error, logtype_default, "Can't unregister Apple II boot files %s", server );
-       exit( 1 );
-    }
-    LOG(log_info, logtype_default, "going down" );
-    exit( 0 );
-}
-
-int main( int ac, char **av )
-{
-    ATP                atp;
-    struct sockaddr_at sat;
-    struct atp_block   atpb;
-    struct iovec       iov;
-    char       hostname[ MAXHOSTNAMELEN ];
-    char       *p;
-    int                c;
-    int32_t    req, resp;
-    int        regerr;
-    extern char        *optarg;
-    extern int         optind;
-
-
-    if ( gethostname( hostname, sizeof( hostname )) < 0 ) {
-       perror( "gethostname" );
-       exit( 1 );
-    }
-    if (( server = index( hostname, '.' )) != 0 ) {
-       *server = '\0';
-    }
-    server = hostname;
-
-    while (( c = getopt( ac, av, "dn:" )) != EOF ) {
-       switch ( c ) {
-       case 'd' :
-           debug++;
-           break;
-       case 'n' :
-           server = optarg;
-           break;
-       default :
-           fprintf( stderr, "Unknown option -- '%c'\n", c );
-           usage( *av );
-       }
-    }
-
-    /*
-     * Disassociate from controlling tty.
-     */
-    if ( !debug ) {
-       int             i, dt;
-
-       switch ( fork()) {
-       case 0 :
-           dt = getdtablesize();
-           for ( i = 0; i < dt; i++ ) {
-               (void)close( i );
-           }
-           if (( i = open( "/dev/tty", O_RDWR )) >= 0 ) {
-               (void)ioctl( i, TIOCNOTTY, 0 );
-               setpgid( 0, getpid());
-               (void)close( i );
-           }
-           break;
-       case -1 :
-           perror( "fork" );
-           exit( 1 );
-       default :
-           exit( 0 );
-       }
-    }
-
-    if (( p = rindex( *av, '/' )) == NULL ) {
-       p = *av;
-    } else {
-       p++;
-    }
-
-#ifdef ultrix
-    openlog( p, LOG_PID );
-#else /* ultrix */
-    set_processname(p);
-    syslog_setup(log_debug, logtype_default, logoption_ndelay|logoption_pid, logfacility_daemon );
-#endif /* ultrix */
-
-    /* allocate memory */
-    memset (&sat.sat_addr, 0, sizeof (sat.sat_addr));
-
-/*
-       force port 3 as the semi-official ATP access port        MJ 2002
-*/
-    if (( atp = atp_open( (u_int8_t)3, &sat.sat_addr )) == NULL ) {
-       LOG(log_error, logtype_default, "main: atp_open: %s", strerror( errno ) );
-       exit( 1 );
-    }
-
-    regerr = nbp_rgstr( atp_sockaddr( atp ), server, "Apple //gs", "*" );
-    regerr += nbp_rgstr( atp_sockaddr( atp ), server, "Apple //e Boot", "*" );
-    regerr += nbp_rgstr( atp_sockaddr( atp ), server, "ProDOS16 Image", "*" );
-    if ( regerr < 0 ) {
-       LOG(log_error, logtype_default, "Can't register Apple II boot files %s", server );
-       exit( 1 );
-    }
-
-    LOG(log_info, logtype_default, "%s:Apple 2 Boot started", server );
-
-       signal(SIGHUP, goaway);
-       signal(SIGTERM, goaway);
-
-    for (;;) {
-       /*
-        * Something seriously wrong with atp, since these assigns must
-        * be in the loop...
-        */
-       atpb.atp_saddr = &sat;
-       atpb.atp_rreqdata = buf;
-       bzero( &sat, sizeof( struct sockaddr_at ));
-       atpb.atp_rreqdlen = sizeof( buf );
-
-       if ( atp_rreq( atp, &atpb ) < 0 ) {
-       LOG(log_error, logtype_default, "main: atp_rreq: %s", strerror( errno ) );
-           exit( 1 );
-       }
-
-       p = buf;
-       bcopy( p, &req, sizeof( int32_t ));
-       req = ntohl( req );
-       p += sizeof( int32_t );
-
-/*
-    LOG(log_info, logtype_default, "req = %08lx",(long)req );
-*/
-       /* Byte-swap and multiply by 0x200. Converts block number to
-          file offset. */
-       fileoff = (( req & 0x00ff0000 ) >> 7 ) | (( req & 0x0000ff00 ) << 9 );
-       req &= 0xff000000;
-
-/*
-    LOG(log_info, logtype_default, "       reqblklo = %02x",(int)reqblklo );
-    LOG(log_info, logtype_default, "       reqblkhi = %02x",(int)reqblkhi );
-    LOG(log_info, logtype_default, "       req now = %08lx",(long)req );
-*/
-
-       switch( req ) {
-       case 0x01000000 :       /* Apple IIgs both ROM 1 and ROM 3 */
-/*    LOG(log_info, logtype_default, "          Req ProDOS16 Boot Blocks" ); */
-               resp = a2bootreq(_PATH_A_GS_BLOCKS);
-           break;
-
-       case 0x02000000 :       /* Apple 2 Workstation card  */
-/*    LOG(log_info, logtype_default, "          Req Apple //e Boot" );  */
-               resp = a2bootreq(_PATH_A_2E_BLOCKS);
-           break;
-
-       case 0x03000000 :       /* Apple IIgs both ROM 1 and ROM 3 */
-/*    LOG(log_info, logtype_default, "          Req ProDOS16 Image" );    */
-               resp = a2bootreq(_PATH_P16_IMAGE);
-           break;
-
-       default :
-           LOG(log_error, logtype_default, bad );
-
-           resp = TL_EOF;
-           *( buf + sizeof( int32_t ) ) = (unsigned char)strlen( bad );
-           strcpy( buf + 1 + sizeof( int32_t ), bad );
-
-           break;
-       }
-
-       bcopy( &resp, buf, sizeof( int32_t ));
-
-       iov.iov_len = sizeof( int32_t ) + 512;
-       iov.iov_base = buf;
-       atpb.atp_sresiov = &iov;
-       atpb.atp_sresiovcnt = 1;
-
-       if ( atp_sresp( atp, &atpb ) < 0 ) {
-           LOG(log_error, logtype_default, "main: atp_sresp: %s", strerror( errno ) );
-           exit( 1 );
-       }
-    }
-}
-
-
-/* below MJ 2002 (initially borrowed from aep_packet */
-long a2bootreq(fname)
-       char    *fname;
-{
-       int f,m;
-       int32_t readlen;
-/*
-    LOG(log_info, logtype_default, "          a2bootreq( %s )",fname );
-*/
-       f=open(fname,O_RDONLY );
-       if(f==EOF) {
-       LOG(log_error, logtype_default, "a2boot open error on %s",fname);
-               return close(f);
-       }
-
-/*
-    LOG(log_info, logtype_default, "would lseek to %08lx",fileoff);
-*/
-       lseek(f,fileoff,0);
-       readlen=read(f, buf + sizeof( int32_t ), 512 );
-
-/*
-    LOG(log_info, logtype_default, "length is %08lx", readlen);
-*/
-
-       if(readlen < 0x200) {
-/*    LOG(log_info, logtype_default, "Read to EOF");  */
-               close(f);
-               return TL_EOF;
-       }
-       close(f);
-       return  TL_OK;
-}
-
diff --git a/contrib/misc/libevent.patch b/contrib/misc/libevent.patch
new file mode 100644 (file)
index 0000000..7d69713
--- /dev/null
@@ -0,0 +1,19 @@
+diff --git a/libevent/Makefile.am b/libevent/Makefile.am
+index 46f6d34..dda19b2 100644
+--- a/libevent/Makefile.am
++++ b/libevent/Makefile.am
+@@ -173,7 +173,7 @@ NO_UNDEFINED =
+ MAYBE_CORE =
+ endif
+-GENERIC_LDFLAGS = -version-info $(VERSION_INFO) $(RELEASE) $(NO_UNDEFINED)
++GENERIC_LDFLAGS = -static
+ libevent_la_SOURCES = $(CORE_SRC) $(EXTRA_SRC)
+ libevent_la_LIBADD = @LTLIBOBJS@ $(SYS_LIBS)
+@@ -221,3 +221,5 @@ FORCE:
+ DISTCLEANFILES = *~ libevent.pc ./include/event2/event-config.h
++install:
++
diff --git a/contrib/printing/.gitignore b/contrib/printing/.gitignore
deleted file mode 100644 (file)
index f2f0549..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-Makefile
-Makefile.in
-timeout
-.deps
-.libs
-.gitignore
-*.o
diff --git a/contrib/printing/Makefile.am b/contrib/printing/Makefile.am
deleted file mode 100644 (file)
index 649c5fb..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-# Makefile.am for contrib/printing/
-
-bin_SCRIPTS = add_netatalk_printer
-
-EXTRA_DIST = netatalk.template add_netatalk_printer
diff --git a/contrib/printing/add_netatalk_printer b/contrib/printing/add_netatalk_printer
deleted file mode 100644 (file)
index 40de174..0000000
+++ /dev/null
@@ -1,366 +0,0 @@
-#! /bin/sh
-#
-# $Id: add_netatalk_printer,v 1.7 2003-02-23 03:16:34 srittau Exp $
-#
-# A lovely script to add netatalk printers 
-#
-#ident  "@(#)netatalk   0.5     99/06/22 job@uchicago.edu"  /* Netatalk 1.4*/
-#
-# This File is released under the Perl Artistic Licence.
-# See http://www.perl.org for details
-#
-# Or you can use it under the licence that accompanies Netatalk 1.3 =)
-#
-# This file is maintained by Job Bogan <job@uchicago.edu>
-# Please contact me at this address for bug reports, problems, etc.
-# Please do not bother the netatalk  maintainers with problems from
-# this program.
-#
-#
-#
-# Exit Codes ...  1 for missed path or user input
-# 2 for an aborted run (by not saying yes to a 'are you sure?'
-# 3 for failed lpadmin commands
-# 4 for possible security problem
-
-# make base name for temp files.
-
-TMP_STUFF="/tmp/`basename $0`.$$"
-export TMP_STUFF
-rm -rf ${TMP_STUFF}
-mkdir -m 700 ${TMP_STUFF} || exit 4
-trap 'rm -f $TMP_STUFF > /dev/null 2>&1' 0
-trap 'exit' 1 2 3
-
-# grab the pathname the script was called w/
-# if it was run by ./add...  then make the path == `pwd`
-
-RUNHOME=`dirname $0`
-
-if [ "$RUNHOME" = "." ]; then
-       RUNHOME=`pwd`
-fi
-
-# allow for the env NETATALKHOME to override the guessed one from above
-
-NETATALKHOME=${NETATALKHOME:-$RUNHOME}
-export NETATALKHOME
-
-PATH=/bin:${PATH}:${NETATALKHOME}/bin:${NETATALKHOME}/etc:${NETATALKHOME}/libexec:/usr/lib:/usr/sbin
-
-if [ ! -x ${NETATALKHOME}/bin/pap ]; then
-       echo "OOPS:     I don't see ${NETATALKHOME}/bin/pap ,"
-       echo '  Check that it is executable or set ${NETATALKHOME}'
-       echo '  so i can find pap at ${NETATALKHOME}/bin/pap'
-       echo '[We are guessing the location of the binary from the'
-       echo 'path that was used to run this script or $NETATALKHOME]'
-       exit 1
-fi
-
-# get the user to tell us where to look for things, and list things there.
-
-echo ''
-echo "Enter Appletalk zone [default: local]: \c"
-
-read ZONE
-
-echo ""
-echo "Looking for LaserWriters in Zone ${ZONE} ..."
-${NETATALKHOME}/bin/nbplkup ":LaserWriter@${ZONE}"
-
-echo ""
-echo "Enter AppleTalk printer name: \c"
-
-read DEST
-
-if [ "$DEST" = "" ]; then
-       echo "OOPS: you need to tell me a printer name"
-       exit 1
-fi
-
-echo "checking nbplkup ${DEST}:LaserWriter@${ZONE}"
-echo ""
-TestDEST=`${NETATALKHOME}/bin/nbplkup "${DEST}:LaserWriter@${ZONE}"`
-echo "${TestDEST}"
-echo ""
-
-if [ "${TestDEST}" = "" ]; then
-    echo "I don't see that printer on the network.  You may have entered an incorrect"
-    echo "printer name - if so, exit and restart."
-    echo "[You should only enter the printer name, not the :LaserWriter portion]"
-    sleep 3
-fi
-
-unset TestDEST
-
-NBPNAME="${DEST}@${ZONE}"
-
-echo ""
-echo ""
-
-# scrunch all of the whitespace and / out of the appletalk name and suggest
-# that as the unix name
-
-SUGGEST=`echo "$DEST" | cut -d: -f1 | sed 's/ //g' | sed 's#/##g` ; export SUGGEST
-
-# truncate the suggested name to 14 chars to conform to lp specs.
-
-SUGGEST1=`expr ${SUGGEST} : '\(..............\)'`
-SUGGEST=${SUGGEST1:-$SUGGEST}
-
-echo "Enter Unix printer name - [default: ${SUGGEST}] : \c"
-read UNIXPRINT
-echo ''
-if [ "${UNIXPRINT}" = "" ]; then
-       UNIXPRINT="${SUGGEST}"
-fi
-export UNIXPRINT
-
-#####
-# Here we check for legal names again. >14 chars
-#####
-
-UNIXPRINT1=`expr "${UNIXPRINT}" : '\(..............\)'`
-
-# if UNIXPRINT is shorter than 14chars, UNIXPRINT1 ends up null ("")
-# if UNIXPRINT was longer, then we get a 14char version of it.  bleah.
-
-if [ "${UNIXPRINT1}" = "" ]; then
-       UNIXPRINT1="${UNIXPRINT}"
-else
-#if [ "${UNIXPRINT1}" != "${UNIXPRINT}" ]; then
-    echo "Oops, that name was too long...  Truncating to 14 chars."
-    echo "setting printer name to '${UNIXPRINT}'"
-    UNIXPRINT="${UNIXPRINT1}"
-fi
-
-echo "Enter a description for this printer.  [The Appletalk name will"
-echo "be included by default, and must be included for the printing"
-echo "filters to work.] : \c"
-read DESC
-
-DESC="${DESC} [${NBPNAME}]"
-
-echo ""
-echo "Do you want all print jobs to print out in reversed page order?"
-echo "This is usually only desired if this printer stacks jobs"
-echo "face up in the output bin. [N/y] \c"
-read REV
-case ${REV} in         [Yy]*)  REV="Netatalk-R" ;;
-                       *)      REV="Netatalk"   ;;
-esac
-export REV
-
-if lpstat -p ${UNIXPRINT} >/dev/null 2>&1 ; then
-       echo '\a'
-       echo "OOPS:     There already exists a printer named '${UNIXPRINT}'"
-       echo "          here are the comments from /etc/lp/printers/${UNIXPRINT}/comment"
-       cat /etc/lp/printers/${UNIXPRINT}/comment
-       echo ""
-       echo "Do you still want to do this? This will flush "
-       echo "all pending jobs!  [Y/n]? \c"
-       read DOTHIS
-       case ${DOTHIS} in       [Yy]*)         ;;
-                               *)      exit 2 ;;
-       esac
-
-       echo "Rejecting all new jobs for ${UNIXPRINT}"
-       reject -r "Making ${UNIXPRINT} a netatalk printer" ${UNIXPRINT}
-       echo "Disabling and Flushing the ${UNIXPRINT} queue"
-       disable -c -r "Making ${UNIXPRINT} a netatalk printer" ${UNIXPRINT}
-fi
-
-#####
-# Check if we need to do silly tricks to share the printer... only on 5.5.1 or older
-#####
-
-if [ "`uname -r`" -lt "5.6" ]; then
-    echo ""
-    echo "Do you want to share this printer with other machines [Y/n]?\c"
-    read SHARE
-else
-    echo "You're running SunOS 5.6 or higher... skipping 'sacadm' and 'pmadm'"
-fi
-
-if nistest printers.org_dir; then
-    echo "Do you want to add this printer to your NIS printer map? [y/N]"
-    echo "(You will need to share this printer with other machines)"
-    read NIS
-    case ${NIS} in     [Yy]*)    ADD_NIS=1 ;;
-                           *)              ;;
-    esac
-fi
-
-echo "Do you want to save the error messages from pap in"
-echo "'/var/spool/lp/tmp/Netatalk/${UNIXPRINT}' [y/N]"
-echo "(If you answer N, error messages will go to /dev/null.)"
-read SAVEerr
-case ${SAVEerr} in      [Yy]*)     SAVEerr=1 ;;
-                           *)     unset SAVEerr ;;
-esac
-
-echo "Making ${UNIXPRINT} print to ${DEST} via netatalk"
-
-if [ "${SAVEerr}" = "" ]; then
-    LOCKDEV=/dev/null
-else
-    LOCKS=/var/spool/lp/tmp/Netatalk
-    if [ ! -d ${LOCKS} ]; then
-           mkdir -m 0771       ${LOCKS}
-           chown lp    ${LOCKS}
-           chgrp lp    ${LOCKS}
-    fi
-    LOCKDEV=${LOCKS}/${UNIXPRINT}
-    touch              ${LOCKDEV}
-    chown lp:lp        ${LOCKDEV}
-    chmod 600  ${LOCKDEV}
-fi
-
-echo ""
-
-if [ ! -r /etc/lp/filter.table ]; then
-        echo "Setting up the existing print filters..."
-        for i in `ls /etc/lp/fd | sed 's/.fd$//'`; do
-                lpfilter -f ${i} -F/etc/lp/fd/${i}.fd
-        done
-fi
-if lpfilter -f netatalk -l > /dev/null 2>&1 ; then
-       echo 'Looks like you have a Netatalk printer filter defined. Good!'
-else
-       echo "Humm... You need a Netatalk printer filter..."
-       echo "... making you one ..."
-       cat > /etc/lp/fd/netatalk.fd << EOF
-#ident  "@(#)netatalk.fd 0.2 97/09/04 job@uchicago.edu"      /* Netatalk 1.4 */
-
-Input types: postscript
-Output types: PS
-Printer types: Netatalk
-Printers: any
-Filter type: fast
-Command: ${NETATALKHOME}/libexec/ifpap 2>&1 > /dev/null
-EOF
-       chown lp:lp /etc/lp/fd/netatalk.fd
-       chmod 664   /etc/lp/fd/netatalk.fd
-       lpfilter -f netatalk -F /etc/lp/fd/netatalk.fd
-fi
-
-if lpfilter -f netatalk-r -l 2>&1 > /dev/null ; then
-       echo 'Looks like you have a Reverse Netatalk printer filter defined. Good!'
-else
-       echo "Humm... You need a Reverse Netatalk printer filter..."
-       echo "... making you one ..."
-       cat > /etc/lp/fd/netatalk-r.fd << EOF
-#ident  "@(#)netatalk-r.fd 0.2 97/09/04 job@uchicago.edu"      /* Netatalk 1.4 */
-
-Input types: postscript
-Output types: PS
-Printer types: Netatalk-R
-Printers: any
-Filter type: fast
-Command: "/usr/lib/lp/postscript/postreverse | ${NETATALKHOME}/libexec/ifpap 2>&1 >/dev/null"
-EOF
-       chown lp:lp /etc/lp/fd/netatalk-r.fd
-       chmod 664   /etc/lp/fd/netatalk-r.fd
-       lpfilter -f netatalk-r -F /etc/lp/fd/netatalk-r.fd
-fi
-
-if [ ! -r /usr/share/lib/terminfo/N/Netatalk ]; then
-       echo "Making a Terminfo entry for Netatalk printers"
-       cat > ${TMP_STUFF}/terminfo << EOF
-Netatalk,
-       cols#80, lines#66,
-       cpi=null, csnm=^D, lpi=null, scs=^D, slines=^D, u9=^D,
-EOF
-       tic ${TMP_STUFF}/terminfo
-       chown bin:bin /usr/share/lib/terminfo/N/Netatalk
-       chmod 644     /usr/share/lib/terminfo/N/Netatalk
-fi
-
-if [ ! -r /usr/share/lib/terminfo/N/Netatalk-R ]; then
-       echo "Making a Terminfo entry for Reversed Netatalk printers"
-       cat > ${TMP_STUFF}/terminfoR << EOF
-Netatalk-R,
-       cols#80, lines#66,
-       cpi=null, csnm=^D, lpi=null, scs=^D, slines=^D, u9=^D,
-EOF
-       tic "${TMP_STUFF}/terminfoR"
-       chown bin:bin /usr/share/lib/terminfo/N/Netatalk-R
-       chmod 644     /usr/share/lib/terminfo/N/Netatalk-R
-fi
-
-###
-# this is old cruft...  we should not have done this in the 1st place.
-# we need to edit the template interface file to point to the local netatalk bins
-#cat ${RUNHOME}/etc/netatalk.template | sed "s#DEFAULT_NETATALK_HOME#${RUNHOME}#g" \
-#      > "/etc/lp/interfaces/${UNIXPRINT}"
-#chown lp:lp   /etc/lp/interfaces/${UNIXPRINT}
-#chmod 0775    /etc/lp/interfaces/${UNIXPRINT}
-# below is the correct way.
-###
-
-echo "Setting up ${UNIXPRINT} ...  Edit options later as you see fit."
-lpadmin -p ${UNIXPRINT} -D "${DESC}" -T ${REV} \
-    -i ${RUNHOME}/netatalk.template -I PS -v ${LOCKDEV} -A none || exit 3
-accept ${UNIXPRINT} || exit 3
-enable ${UNIXPRINT} || exit 3
-
-case ${SHARE} in       [Nn]*)  exit; ;;
-                       *)            ;;
-esac
-
-echo "Setting up network sharing for ${UNIXPRINT}"
-
-# from p925 in the Solaris Administration Guide, Vol. II (2.5)
-
-echo ""
-if sacadm -l -p tcp > /dev/null; then
-   echo "already running a tcp listener"
-else
-   echo "Defining tcp listener ..."
-   sacadm -a -p tcp -t listen -c "/usr/lib/saf/listen tcp" \
-          -v `nlsadmin -V` -n 999
-fi
-
-# this is extra, but a good idea...
-
-LPD_ADDR="\\x`lpsystem -A`" ; export LPD_ADDR
-ADDR_0=`echo $LPD_ADDR | sed -e 's/\\x00020203/\\x00020ACE/g'`; export ADDR_0
-
-if pmadm -l -p tcp -s 0 > /dev/null; then
-   echo "<0> service is already defined."
-else
-   echo "Defining <0>/tcp service ..."
-   pmadm -a -p tcp -s 0 -i root \
-         -m `nlsadmin -c /usr/lib/saf/nlps_server -A ${ADDR_0}` \
-         -v `nlsadmin -V`
-fi
-
-# again from the solaris book noted above.
-
-if pmadm -l -p tcp -s lp > /dev/null; then
-   echo "<lp> service is already defined."
-else
-   echo "Defining <lp>/tcp service ..."
-   pmadm -a -p tcp -s lp -i root \
-         -m `nlsadmin -o /var/spool/lp/fifos/listenS5` \
-         -v `nlsadmin -V`
-fi
-
-if pmadm -l -p tcp -s lpd > /dev/null; then
-   echo "<lpd> service is already defined."
-else
-   echo "Defining <lpd>/tcp service ..."
-   pmadm -a -p tcp -s lpd -i root \
-         -m `nlsadmin -o /var/spool/lp/fifos/listenBSD -A ${LPD_ADDR}` \
-         -v `nlsadmin -V`
-fi
-
-if [ "${ADD_NIS}" = 1 ] ; then
-    if nistest "[printer_name=${UNIXPRINT}]printers.org_dir"; then
-       nistbladm -m    printer_host=`uname -n` \
-       "[printer_name=${UNIXPRINT}]printers.org_dir"  description="$DESC"
-    else
-       nistbladm -a    printer_name=${UNIXPRINT} \
-       description="$DESC" printer_host=`uname -n` printers.org_dir
-    fi
-fi
diff --git a/contrib/printing/netatalk.template b/contrib/printing/netatalk.template
deleted file mode 100644 (file)
index f639914..0000000
+++ /dev/null
@@ -1,610 +0,0 @@
-#ident "@(#)netatalk   0.7     99/06/22 job@uchicago.edu"  /* Netatalk 1.4*/
-
-#####
-# User configuration:
-#
-# Set timeout for pap($time) and papstatus($time2).  both are in seconds.
-# extraneous if you do not have NETATALKHOME/bin/timeout
-# set how many times to loop before we just abort entirely ($attempts)
-# what flags pap is run w/. -c makes pap claim to have been waiting forever
-#####
-
-time=1800
-time2=60
-attempts=3
-pap_flags="-c"
-
-#####
-# this should get "fixed" to something like
-# NETATALKHOME=/opt ; export NETATALKHOME
-# by the add_netatalk_printer script
-#
-# DO NOT use the user's env for this or the PATH above.
-#####
-
-NETATALKHOME=DEFAULT_NETATALK_HOME ; export NETATALKHOME
-#NETATALKHOME=/opt ; export NETATALKHOME
-
-if [ "${NETATALKHOME}" = "DEFAULT_NETATALK_HOME" ]; then
-   echo "bleah, NETATALKHOME not set, exiting..." ; exit 5
-fi
-
-#####
-# BUGS/TODO:
-# move all TMP stuff to use a directory for security reasons
-# run nbplkup to check if the reason we cannot print, is that it's not on 
-#      the net
-# move to "${foo}" from $foo and ${foo}
-# add debuging info that gets sent to "logger lpd.debug"
-# if we timeout while printing the banner page, we do not keep trying to print.
-# perhaps filter_timeout should only complain once per job; like badfile.
-# check if the timeout messages are duplicated by the lp system
-# psa will not drop in for pap to use accting.  perhaps lp does not need it?
-# make pap print all the files at once; kill for file in ($files)
-# move badfile error to printfile function
-#####
-
-# This File is released under the Perl Artistic Licence.  
-# See http://www.perl.org for details
-#
-# Or you can use it under the licence that accompanies Netatalk 1.3 =)
-
-###########
-## Netatalk printer interface.  Heavily modified from 
-## /usr/lib/lp/model/standard on Sparc Solaris 2.5.1 (May 97)
-##
-## Meant to be used w/ add_netatalk_printer
-###########
-
-#####
-# This program is invoked as
-#
-# ${SPOOLDIR}/.../printer request-id user title copies options files...
-#
-# The first three arguments are simply reprinted on the banner page,
-# the fourth (copies) is used to control the number of copies to print,
-# the fifth (options) is a blank separated list (in a single argument)
-# of user or Spooler supplied options (without the -o prefix),
-# and the last argument(s) is/are the file(s) to print.
-#####
-
-#####
-#
-# The protocol between the interface program and the Spooler
-# is fairly simple:
-#
-#      All standard error output is assumed to indicate a
-#      fault WITH THE REQUEST. The output is mailed to the
-#      user who submitted the print request and the print
-#      request is finished.
-#
-#      If the interface program sets a zero exit code,
-#      it is assumed that the file printed correctly.
-#      If the interface program sets a non-zero exit code
-#      less than 128, it is assumed that the file did not
-#      print correctly, and the user will be notified.
-#      In either case the print request is finished.
-#
-#      If the interface program sets an exit code greater
-#      than 128, it is assumed that the file did not print
-#      because of a printer fault. If an alert isn't already
-#      active (see below) one will be activated. (Exit code
-#      128 should not be used at all. The shell, which executes
-#      this program, turns SIGTERM, used to kill this program
-#      for a cancellation or disabling, into exit 128. The
-#      Spooler thus interpretes 128 as SIGTERM.)
-#
-#      A message sent to the standard input of the ${LPTELL}
-#      program is assumed to describe a fault WITH THE PRINTER.
-#      The output is used in an alert (if alerts are defined).
-#      If the fault recovery is "wait" or "begin", the printer
-#      is disabled (killing the interface program if need be),
-#      and the print request is left on the queue.
-#      If the fault recovery is "continue", the interface program
-#      is allowed to wait for the printer fault to be cleared so
-#      it can resume printing.
-#
-#####
-
-###########################################################################
-#
-# Set up the basic traps. and other important things
-#
-###########################################################################
-
-#####
-# For the time being, just exit if we are poked.
-#####
-
-# SIGTERM handler
-
-trap 'exit' 15
-
-#####
-# We can be clever about getting a hangup or interrupt, though, at least
-# until the filter runs. Do this early, even though $LPTELL
-# isn't defined, so that we're covered.
-#####
-
-trap 'catch_hangup; exit_code=129 exit 129' 1
-trap 'catch_interrupt; exit_code=129 exit 129' 2 3
-
-#####
-# VARIBLE DECLARED - put here so we don't ever run the trap below w/o
-# TMPPREFIX defined.  We hard code /tmp for the moment, but fix that later
-#
-# Use ${TMPPREFIX} as the prefix for all temporary files, so
-# that cleanup is easy. The prefix may be up to 13 characters
-# long, so you only have space for one more character to make
-# a file name. If necessary, make a directory using this prefix
-# for better management of unique temporary file names.
-#####
-
-TMPPREFIX=/tmp/`uname -n`$$
-
-#####
-# Before exiting, set ${exit_code} to the value with which to exit.
-# Otherwise, the exit from this script will be 0.
-#####
-
-trap 'rm -fr ${TMPPREFIX}*; exit ${exit_code}' 0
-
-catch_hangup () {
-       if [ -n "${LPTELL}" ]
-       then
-               echo \
-    "Humm, we got a SIGHUP.  Not sure what it means, but... we'll keep going anyway" \
-          | ${LPTELL} "${printer}"
-       fi
-       return 0
-}
-
-catch_interrupt () {
-       if [ -n "${LPTELL}" ]
-       then
-           echo \
-       "Received an interrupt from the printer.  The reason is unknown." \
-           | ${LPTELL} "${printer}"
-       fi
-       return 0
-}
-
-#####
-# Most of the time we don't want the standard error to be captured
-# by the Spooler, mainly to avoid "Terminated" messages that the
-# shell puts out when we get a SIGTERM. We'll save the standard
-# error channel under another number, so we can use it when it
-# should be captured.
-#
-# Open another channel to the printer port, for use when the
-# regular standard output won't be directed there, such as in
-# command substitution (`cmd`).
-#####
-
-exec 5>&2 2>/dev/null 3>&1
-
-###########################################################################
-#
-# Define local varibles and such
-#
-###########################################################################
-
-#####
-# There is one more varible set by the shell that execs us.
-# FILTER       The filter to run ; we ignore this directive
-#####
-
-#####
-# Use the user set env, or else default to standard values.
-#####
-
-: ${SPOOLDIR:=/usr/spool/lp}
-: ${TMPDIR:=/tmp} ; export TMPDIR
-: ${LOCALPATH:=${SPOOLDIR}/bin} ; export LOCALPATH
-
-PATH="/bin:/usr/bin:${LOCALPATH}:${NETATALKHOME}/bin:${NETATALKHOME}/etc"
-export PATH
-
-TMPPREFIX=${TMPDIR}/`uname -n`$$
-
-#####
-# Error levels for the errmsg() func.
-#####
-
-LP_ERR_LABEL="UX:lp" ; export LP_ERR_LABEL
-
-E_IP_ARGS=1
-E_IP_OPTS=2
-E_IP_UNKNOWN=5
-E_IP_BADFILE=6
-
-#####
-# Error message formatter:
-#
-# Invoke as
-#
-#      errmsg severity message-number problem help
-#
-# where severity is "ERROR" or "WARNING", message-number is
-# a unique identifier, problem is a short description of the
-# problem, and help is a short suggestion for fixing the problem.
-#####
-
-errmsg () {
-        case $1 in
-        ERROR )
-                sev="  ERROR";
-                ;;
-        WARNING )
-                sev="WARNING";
-                ;;
-        esac
-        echo "${LP_ERR_LABEL}: ${sev}: $3
-        TO FIX: $4" >&5
-}
-
-parse () {
-        echo "`expr \"$1\" : \"^[^=]*=\(.*\)\"`"
-}
-
-#####
-# die quickly if we do not have the right number of arguments.
-#####
-
-if [ $# -lt 5 ]
-then
-       errmsg ERROR ${E_IP_ARGS} \
-               "wrong number of arguments to interface program" \
-               "consult your system administrator"
-       exit 1
-fi
-
-printer=`basename $0`
-request_id=$1
-
-# this will formated be machine!username, so we want to split that up...
-
-user_name=$2
-machine=`echo $user_name | cut -d! -f1`
-user_name=`echo $user_name | cut -d! -f2`
-
-title=$3
-copies=$4
-option_list=$5
-
-shift 5
-files="$*"
-
-nobanner="yes"
-
-inlist=
-
-for i in ${option_list}
-do
-case "${inlist}${i}" in
-    nobanner )
-       nobanner="yes" ;;
-    banner )
-       nobanner="no" ;;
-#####
-#
-# If you want to add simple options (e.g. -o simple)
-# identify them here.
-#####
-#    simple )
-#      simple="yes" ;;
-
-#####
-# These get ignored, but would matter little anyway since all we see 
-# here is PS anyway.
-#####
-       cpi=* )
-#          cpi=`parse ${i}` ;;
-           true ;;
-       lpi=* )
-#          lpi=`parse ${i}` ;;
-           true ;;
-       length=* )
-#          length=`parse ${i}` ;;
-           true ;;
-       width=* )
-#          width=`parse ${i}` ;;
-           true ;;
-
-       #####
-       # If you want to add simple-value options (e.g. -o value=a)
-       # identify them here.
-       #####
-       #value=* )
-       #    value=`parse ${i}` ;;
-
-       flist=* )
-           flist=`parse ${i}` ;;
-       input* )
-           true ;;
-       * )
-           errmsg WARNING ${E_IP_OPTS} \
-           "unrecognized \"-o ${i}\" option" \
-           "check the option, resubmit if necessary
-           printing continues" ;;
-
-       esac
-done
-
-#####
-# A bit ugly, but grabs the appletalk printer name from the lp system printer
-# description, so it's right up there in admintool.  the appletalk name must 
-# be delimited by [ and ].
-#
-# eg - 'this is the printer [hp-mrsec-l114:lasershared@Research Insitutes] that i use.'
-#####
-
-PAPDEST="`lpstat -D -p "${printer}" | grep -i descrip | sed 's/.*Description:.*\[//g' | sed 's/\].*//g'`"
-
-export PAPDEST
-
-###########################################################################
-#
-# Define our local functions  (parse is declared above option parsing)
-#
-###########################################################################
-
-banner () {
-    echo "#####    User: ${user_name}"
-    echo ""
-    echo "##### Machine: ${user_name}"
-    echo ""
-
-   if [ -n "${title}" ]
-   then
-    echo "#####   Title: ${title}"
-    echo ""
-   fi
-
-    echo "#####   Files: ${flist}"
-    echo ""
-
-#####
-# this should deal w/ the year 2000 ok.  But will die in 2038. =)
-#####
-
-    YEAR=`date '+%y'`
-    YEAR=`expr 1900 + ${YEAR}`
-
-    echo "#####    Date: `date '+%a %H:%M %h %d,'` ${YEAR}"
-    echo ""
-    echo "#####     Job: ${request_id}"
-    echo ""
-
-}
-
-print_banner() {
-    if [ -x ${NETATALKHOME}/bin/timeout ]
-    then
-       banner | ${NETATALKHOME}/etc/psf \
-           | ${NETATALKHOME}/bin/timeout "${time}" ${NETATALKHOME}/bin/pap -c -p "${PAPDEST}"
-    else
-       banner | ${NETATALKHOME}/etc/psf \
-           | ${NETATALKHOME}/bin/pap -c -p "{PAPDEST}"
-    fi
-
-    if [ ${?} -ne 0 ]
-    then
-       filter_timeout
-    fi 
-}
-
-#####
-# ${LPTELL} is the name of a program that will send its
-# standard input to the Spooler. It is used to forward
-# the description of a printer fault to the Spooler,
-# which uses it in an alert to the administrator.
-#####
-if [ ! -x "${LPTELL:=${LOCALPATH}/lp.tell}" ]
-then
-    fake_lptell(){
-       header="no"
-       while read line
-       do
-           if [ "no" = "${header}" ]
-           then
-               errmsg ERROR ${E_IP_UNKNOWN} \
-               "unknown printer/interface failure" \
-               "consult your system administrator; \
-               reasons for failure (if any) follow:"
-               header=yes
-           fi
-           echo "${line}" >&2
-       done
-    return 1
-    }
-    LPTELL=fake_lptell
-fi
-
-
-#####
-# timeout catcher for the printing filter
-#####
-
-filter_timeout() {
-
-       cat > ${TMPPREFIX}D <<EOF
-
-The printer ${printer} either timed out at ${time} seconds or pap exited
-abnormally.  As well, we may have exceeded ${print_tries} print attempts.
-The job ${request_id} from ${user_name} on ${machine} was
-printing when this happened.
-
-It may be that the only problem is the size of the job and the speed
-of the printer.
-
-Here is what $NETATALKHOME/bin/papstatus reports as the current 
-state of the printer:
-
-EOF
-#####
-# We don't need to test for timeout, since we cannot get here w/o it.
-#####
-
-    ${NETATALKHOME}/bin/timeout ${time2} ${NETATALKHOME}/bin/papstatus -p "${PAPDEST}" 2>&1 >> ${TMPPREFIX}D 
-    paperr=${?}
-
-    errmsg WARNING ${E_IP_UNKNOWN} "`cat ${TMPPREFIX}D`" "printing continues"
-#####
-# This ought to deal w/ the problem of nonexistent appletalk names, but...
-# for the moment, it calls filter_death.  But it sends the  papstatus 
-# info to LPTELL anyhow, so you should be able to see the error.
-#####
-
-    if [ ${paperr} -ne 0 -o ${too_many} = "1" ]; then
-       paperr=
-       filter_death
-    fi
-    paperr=
-    echo "serverdict begin 0 exitserver systemdict /quit get exec" | \
-                ${NETATALKHOME}/bin/pap -c -p "${PAPDEST}"
-    return 0
-}
-
-#####
-# Death catcher for filter_timeout
-#####
-
-filter_death() {
-
-    cat > ${TMPPREFIX}Z <<EOF
-Excessive delays w/ the printer ${printer}!
-
-While processing on printer ${printer} the job ${request_id} 
-from ${user_name} on ${machine} timed out at ${time} seconds.  
-
-Then while cleaning that timeout, the cleanup operation failed as
-well.
-
-EOF
-    errmsg ERROR ${E_IP_UNKNOWN} "`cat ${TMPPREFIX}Z`"
-    exit 129
-#####
-# Exit and fault the printer.
-#####
-}
-
-#####
-# Print the job
-#####
-printfile() {
-    trap '' 1  # Let the filter handle a hangup
-    trap '' 2 3        # and interrupts
-#####
-# We use timeout so as to not hang the print queue indefinately.  (pap does not
-# timeout on it's own.)
-#
-# Put the 0<${files} before the "eval" to keep clever users from giving 
-# a file name that evaluates as something to execute.
-#####
-    if [ "${TERM}" == "Netatalk-R" ]; then
-       if [ -x ${NETATALKHOME}/bin/timeout ]; then
-           0<${file} /usr/lib/lp/postscript/postreverse | ${NETATALKHOME}/bin/timeout ${time} ${NETATALKHOME}/bin/pap -c -p "${PAPDEST}"
-       else
-           0<${file} /usr/lib/lp/postscript/postreverse | ${NETATALKHOME}/bin/pap -c -p "${PAPDEST}"
-       fi
-    else
-       if [ -x ${NETATALKHOME}/bin/timeout ]; then
-           0<${file} ${NETATALKHOME}/bin/timeout ${time} ${NETATALKHOME}/bin/pap -c -p "${PAPDEST}"
-       else
-           0<${file} ${NETATALKHOME}/bin/pap -c -p "${PAPDEST}"
-       fi
-    fi
-    paperr=${?}
-    print_tries=`expr "${print_tries}" + 1`
-    if [ "${paperr}" != "0" -a "${print_tries}" -gt "${attempts}" ]; then
-       too_many=1
-    fi
-    trap 'catch_hangup; exit_code=129 exit 129' 1
-    trap 'catch_interrupt; exit_code=129 exit 129' 2 3
-    return ${paperr}
-}
-
-#####
-# Some basic sanity checking:
-#####
-
-if [ ! -x $NETATALKHOME/bin/pap ]
-then
-    echo "Opps, cannot find $NETATALKHOME/bin/pap, so I don't know how to"
-    echo "print things"
-    # exit w/ less than 128 to mark an error w/ the job, and call it done
-    exit 1 
-fi
-
-###########################################################################
-#
-# Start the main section of the program.
-#
-###########################################################################
-
-#####
-# Here i should have a "job canceled" page ready in a trap in case of getting killed
-# but, alas, that would most likely muck up the PS.  So we just drop the job on the 
-# floor.
-#####
-
-#####
-# If you want a custom banner, change the code up in the functions section.
-#####
-
-if [ "no" = "${nobanner}" -a "${TERM}" != "Netatalk-R" ]
-then
-    print_banner
-fi
-
-#####
-# Print some copies of the file(s)
-#####
-
-badfileyet=
-i=1
-while [ $i -le $copies ]
-do
-    for file in ${files}
-    do
-       if [ -r "${file}" ]
-        then
-            print_tries=0
-           until printfile
-           do
-               filter_timeout;
-           done
-       else
-#####
-# Don't complain about not being able to read a file on second and
-# subsequent copies, unless we've not complained yet. This removes
-# repeated messages about the same file yet reduces the chance that the
-# user can remove a file and not know that we had trouble finding it.
-#####
-           if [ "${i}" -le 1 -o -z "${badfileyet}" ]
-           then
-               errmsg WARNING ${E_IP_BADFILE} \
-                   "cannot read file \"${file}\" " \
-                   "see if the file still exists and is readable by the user\
-                   lp (or world), or consult your system administrator; \
-                   We will keep trying to print the other files or copies"
-               badfileyet=yes
-           fi
-       fi
-    done
-    i=`expr $i + 1`
-done
-
-#####
-# print the banner page if we are a reversed queue
-#####
-if [ "no" = "${nobanner}" -a "${TERM}" == "Netatalk-R" ]
-then
-    print_banner
-fi
-
-echo "serverdict begin 0 exitserver systemdict /quit get exec" | \
-                ${NETATALKHOME}/bin/pap -c -p "${PAPDEST}"
-
-Exit_code=0 exit 0
diff --git a/contrib/timelord/.gitignore b/contrib/timelord/.gitignore
deleted file mode 100644 (file)
index 47b8196..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-Makefile
-Makefile.in
-timelord
-.deps
-.libs
-.gitignore
-*.o
diff --git a/contrib/timelord/COPYRIGHT b/contrib/timelord/COPYRIGHT
deleted file mode 100644 (file)
index f6141ea..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (c) 1990,1994 Regents of The University of Michigan.
- * All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software and
- * its documentation for any purpose and without fee is hereby granted,
- * provided that the above copyright notice appears in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation, and that the name of The University
- * of Michigan not be used in advertising or publicity pertaining to
- * distribution of the software without specific, written prior
- * permission. This software is supplied as is without expressed or
- * implied warranties of any kind.
- *
- *     Research Systems Unix Group
- *     The University of Michigan
- *     c/o Wesley Craig
- *     535 W. William Street
- *     Ann Arbor, Michigan
- *     +1 313 764 2278
- *     netatalk@umich.edu
- */
-
-/*
- * The "timelord protocol" was reverse engineered from Timelord,
- * distributed with CAP, Copyright (c) 1990, The University of
- * Melbourne.  The following copyright, supplied by The University
- * of Melbourne, may apply to this code:
- *
- *     This version of timelord.c is based on code distributed
- *     by the University of Melbourne as part of the CAP package.
- *
- *     The tardis/Timelord package for Macintosh/CAP is
- *     Copyright (c) 1990, The University of Melbourne.
- */
diff --git a/contrib/timelord/Makefile.am b/contrib/timelord/Makefile.am
deleted file mode 100644 (file)
index b592695..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-# Makefile.am for contrib/timelord/
-
-sbin_PROGRAMS = timelord
-
-timelord_SOURCES = timelord.c
-timelord_LDADD = $(top_builddir)/libatalk/libatalk.la
-
-LIBS = @LIBS@
-
-EXTRA_DIST = COPYRIGHT README VERSION
diff --git a/contrib/timelord/README b/contrib/timelord/README
deleted file mode 100644 (file)
index 37446f1..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-$Id: README,v 1.3 2002-02-21 09:59:24 srittau Exp $
-
-This is the README file for timelord 1.0 (previously known as
-ntimelord), for use with netatalk 1.5. Previous versions of this
-software were designed to work with netatalk 1.3, but this has
-been patched to work with netatalk 1.5.  Please see the COPYRIGHT
-file.  This package's COPYRIGHT is *not* the same as netatalk's.
-
-Building timelord:
-
-1.  Run ./configure from the base directory of your netatalk
-    distribution, and add --enable-timelord to your command line
-    options.
-
-2.  Run "make all" for netatalk, and timelord will be built along
-    with the rest of netatalk.
-
-Installing timelord:
-
-1.  To install the binaries, type "make install" from either the base
-    directory of your netatalk distribution or from this directory. 
-    This will install all of the binaries in the directory specified
-    by ./configure.
-
-2.  The file rc.atalk as distributed with netatalk 1.5 includes lines to
-    start timelord.
diff --git a/contrib/timelord/VERSION b/contrib/timelord/VERSION
deleted file mode 100644 (file)
index d3827e7..0000000
+++ /dev/null
@@ -1 +0,0 @@
-1.0
diff --git a/contrib/timelord/timelord.c b/contrib/timelord/timelord.c
deleted file mode 100644 (file)
index 60fdb8e..0000000
+++ /dev/null
@@ -1,266 +0,0 @@
-/*
- * $Id: timelord.c,v 1.8 2005-04-28 20:49:36 bfernhomberg Exp $
- *
- * Copyright (c) 1990,1992 Regents of The University of Michigan.
- * All Rights Reserved. See COPYRIGHT.
- *
- * The "timelord protocol" was reverse engineered from Timelord,
- * distributed with CAP, Copyright (c) 1990, The University of
- * Melbourne.  The following copyright, supplied by The University
- * of Melbourne, may apply to this code:
- *
- *     This version of timelord.c is based on code distributed
- *     by the University of Melbourne as part of the CAP package.
- *
- *     The tardis/Timelord package for Macintosh/CAP is
- *     Copyright (c) 1990, The University of Melbourne.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <sys/param.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/file.h>
-#include <sys/uio.h>
-#include <stdlib.h>
-
-#include <unistd.h>
-
-#include <netatalk/at.h>
-#include <netatalk/endian.h>
-#include <atalk/atp.h>
-#include <atalk/nbp.h>
-
-#include <time.h>
-#ifdef HAVE_SGTTY_H
-#include <sgtty.h>
-#endif /* HAVE_SGTTY_H */
-#include <errno.h>
-#include <signal.h>
-#pragma warn "testing 123"
-#include <atalk/logger.h>
-#include <stdio.h>
-#include <string.h>
-#ifdef HAVE_NETDB_H
-#include <netdb.h>
-#endif /* HAVE_NETDB_H */
-
-#ifdef HAVE_FCNTL_H
-#include <fcntl.h>
-#endif /* HAVE_FCNTL_H */
-#ifdef HAVE_SYS_FCNTL_H
-#include <sys/fcntl.h>
-#endif /* HAVE_SYS_FCNTL_H */
-
-#ifdef HAVE_TERMIOS_H
-#include <termios.h>
-#endif /* HAVE_TERMIOS_H */
-#ifdef HAVE_SYS_TERMIOS_H
-#include <sys/termios.h>
-#endif /* HAVE_SYS_TERMIOS_H */
-
-#define        TL_GETTIME      0
-#define        TL_OK           12
-#define TL_BAD         10
-#define EPOCH          0x7C25B080      /* 00:00:00 GMT Jan 1, 1970 for Mac */
-
-int    debug = 0;
-char   *bad = "Bad request!";
-char   buf[ 4624 ];
-char   *server;
-
-void usage( char *p )
-{
-    char       *s;
-
-    if (( s = rindex( p, '/' )) == NULL ) {
-       s = p;
-    } else {
-       s++;
-    }
-    fprintf( stderr, "Usage:\t%s -d -n nbpname\n", s );
-    exit( 1 );
-}
-
-/*
- * Unregister ourself on signal.
- */
-void
-goaway(int signal)
-{
-    if ( nbp_unrgstr( server, "TimeLord", "*", NULL ) < 0 ) {
-       LOG(log_error, logtype_default, "Can't unregister %s", server );
-       exit( 1 );
-    }
-    LOG(log_info, logtype_default, "going down" );
-    exit( 0 );
-}
-
-int main( int ac, char **av )
-{
-    ATP                        atp;
-    struct sockaddr_at sat;
-    struct atp_block   atpb;
-    struct timeval     tv;
-    struct timezone    tz;
-    struct iovec       iov;
-    struct tm          *tm;
-    char               hostname[ MAXHOSTNAMELEN ];
-    char               *p;
-    int                        c;
-    long               req, mtime, resp;
-    extern char                *optarg;
-    extern int         optind;
-
-    if ( gethostname( hostname, sizeof( hostname )) < 0 ) {
-       perror( "gethostname" );
-       exit( 1 );
-    }
-    if (( server = index( hostname, '.' )) != 0 ) {
-       *server = '\0';
-    }
-    server = hostname;
-
-    while (( c = getopt( ac, av, "dn:" )) != EOF ) {
-       switch ( c ) {
-       case 'd' :
-           debug++;
-           break;
-       case 'n' :
-           server = optarg;
-           break;
-       default :
-           fprintf( stderr, "Unknown option -- '%c'\n", c );
-           usage( *av );
-       }
-    }
-
-    /*
-     * Disassociate from controlling tty.
-     */
-    if ( !debug ) {
-       int             i, dt;
-
-       switch ( fork()) {
-       case 0 :
-           dt = getdtablesize();
-           for ( i = 0; i < dt; i++ ) {
-               (void)close( i );
-           }
-           if (( i = open( "/dev/tty", O_RDWR )) >= 0 ) {
-               (void)ioctl( i, TIOCNOTTY, 0 );
-               setpgid( 0, getpid());
-               (void)close( i );
-           }
-           break;
-       case -1 :
-           perror( "fork" );
-           exit( 1 );
-       default :
-           exit( 0 );
-       }
-    }
-
-    if (( p = rindex( *av, '/' )) == NULL ) {
-       p = *av;
-    } else {
-       p++;
-    }
-
-#ifdef ultrix
-    openlog( p, LOG_PID );
-#else /* ultrix */
-    set_processname(p);
-    syslog_setup(log_debug, logtype_default, logoption_ndelay|logoption_pid, logfacility_daemon );
-#endif /* ultrix */
-
-    /* allocate memory */
-    memset (&sat.sat_addr, 0, sizeof (sat.sat_addr));
-
-    if (( atp = atp_open( ATADDR_ANYPORT, &sat.sat_addr )) == NULL ) {
-       LOG(log_error, logtype_default, "main: atp_open: %s", strerror( errno ) );
-       exit( 1 );
-    }
-
-    if ( nbp_rgstr( atp_sockaddr( atp ), server, "TimeLord", "*" ) < 0 ) {
-       LOG(log_error, logtype_default, "Can't register %s", server );
-       exit( 1 );
-    }
-    LOG(log_info, logtype_default, "%s:TimeLord started", server );
-
-       signal(SIGHUP, goaway);
-       signal(SIGTERM, goaway);
-
-    for (;;) {
-       /*
-        * Something seriously wrong with atp, since these assigns must
-        * be in the loop...
-        */
-       atpb.atp_saddr = &sat;
-       atpb.atp_rreqdata = buf;
-       bzero( &sat, sizeof( struct sockaddr_at ));
-       atpb.atp_rreqdlen = sizeof( buf );
-       if ( atp_rreq( atp, &atpb ) < 0 ) {
-           LOG(log_error, logtype_default, "main: atp_rreq: %s", strerror( errno ) );
-           exit( 1 );
-       }
-
-       p = buf;
-       bcopy( p, &req, sizeof( long ));
-       req = ntohl( req );
-       p += sizeof( long );
-
-       switch( req ) {
-       case TL_GETTIME :
-           if ( atpb.atp_rreqdlen > 5 ) {
-                   bcopy( p + 1, &mtime, sizeof( long ));
-                   mtime = ntohl( mtime );
-                   LOG(log_info, logtype_default, "gettime from %s %s was %lu",
-                           (*( p + 5 ) == '\0' ) ? "<unknown>" : p + 5,
-                           ( *p == 0 ) ? "at boot" : "in chooser",
-                           mtime );
-           } else {
-                   LOG(log_info, logtype_default, "gettime" );
-           }
-
-           if ( gettimeofday( &tv, &tz ) < 0 ) {
-               LOG(log_error, logtype_default, "main: gettimeofday: %s", strerror( errno ) );
-               exit( 1 );
-           }
-           if (( tm = gmtime( &tv.tv_sec )) == 0 ) {
-               perror( "localtime" );
-               exit( 1 );
-           }
-
-           mtime = tv.tv_sec + EPOCH;
-           mtime = htonl( mtime );
-
-           resp = TL_OK;
-           bcopy( &resp, buf, sizeof( long ));
-           bcopy( &mtime, buf + sizeof( long ), sizeof( long ));
-           iov.iov_len = sizeof( long ) + sizeof( long );
-           break;
-
-       default :
-           LOG(log_error, logtype_default, bad );
-
-           resp = TL_BAD;
-           bcopy( &resp, buf, sizeof( long ));
-           *( buf + 4 ) = (unsigned char)strlen( bad );
-           strcpy( buf + 5, bad );
-           iov.iov_len = sizeof( long ) + 2 + strlen( bad );
-           break;
-       }
-
-       iov.iov_base = buf;
-       atpb.atp_sresiov = &iov;
-       atpb.atp_sresiovcnt = 1;
-       if ( atp_sresp( atp, &atpb ) < 0 ) {
-           LOG(log_error, logtype_default, "main: atp_sresp: %s", strerror( errno ) );
-           exit( 1 );
-       }
-    }
-}
index 6ad182a5693bd5b7278f9804bf0c0708e52282ca..ee603ee52abee79e2fbab687ae368eefed346992 100644 (file)
@@ -1,7 +1,3 @@
 # Makefile.am for etc/
 
 SUBDIRS = afpd cnid_dbd uams
-
-if USE_APPLETALK
-SUBDIRS += atalkd papd psf
-endif
index 4e9c02155e90281691d48deca067c41656316263..0295d71cd4f0a00036160184b13e0e50305b3028 100644 (file)
@@ -6,7 +6,6 @@ sbin_PROGRAMS = afpd
 noinst_PROGRAMS = hash fce
 
 afpd_SOURCES = \
-       afp_asp.c \
        afp_avahi.c \
        afp_config.c \
        afp_dsi.c \
@@ -46,9 +45,9 @@ afpd_SOURCES = \
 afpd_LDADD =  \
        $(top_builddir)/libatalk/cnid/libcnid.la \
        $(top_builddir)/libatalk/libatalk.la \
-       @LIBGCRYPT_LIBS@ @ZEROCONF_LIBS@ @QUOTA_LIBS@ @SLP_LIBS@ @WRAP_LIBS@ @LIBADD_DL@ @ACL_LIBS@ @PTHREAD_LIBS@
+       @LIBGCRYPT_LIBS@ @QUOTA_LIBS@ @SLP_LIBS@ @WRAP_LIBS@ @LIBADD_DL@ @ACL_LIBS@ @ZEROCONF_LIBS@ @PTHREAD_LIBS@
 
-afpd_LDFLAGS = -export-dynamic 
+afpd_LDFLAGS = -export-dynamic -static
 
 afpd_CFLAGS = \
        -I$(top_srcdir)/include \
index b7c4b6d266fdb9863005c61dc889cd66785453e7..87ff5decefdc75d9c09feab9af8c8d971fa54b14 100644 (file)
@@ -31,8 +31,8 @@
 #endif
 
 struct ace_rights_map {
-    u_int32_t from;
-    u_int32_t to;
+    uint32_t from;
+    uint32_t to;
 };
 
 #ifdef HAVE_SOLARIS_ACLS
@@ -71,8 +71,8 @@ struct ace_rights_map darwin_to_nfsv4_rights[] = {
 };
 
 struct nfsv4_to_darwin_flags_map {
-    u_int16_t from;
-    u_int32_t to;
+    uint16_t from;
+    uint32_t to;
 };
 
 struct nfsv4_to_darwin_flags_map nfsv4_to_darwin_flags[] = {
@@ -85,8 +85,8 @@ struct nfsv4_to_darwin_flags_map nfsv4_to_darwin_flags[] = {
 };
 
 struct darwin_to_nfsv4_flags_map {
-    u_int32_t from;
-    u_int16_t to;
+    uint32_t from;
+    uint16_t to;
 };
 
 struct darwin_to_nfsv4_flags_map darwin_to_nfsv4_flags[] = {
index 82d61eb5444d88512ae58aa9ef6ed9c6496f4247..40281bcc9b079260922af9db90b38a0c879f5069 100644 (file)
@@ -985,7 +985,7 @@ static int get_and_map_acl(char *name, char *rbuf, size_t *rbuflen)
     EC_INIT;
     int mapped_aces = 0;
     int dirflag;
-    uint32_t *darwin_ace_count = (u_int32_t *)rbuf;
+    uint32_t *darwin_ace_count = (uint32_t *)rbuf;
 #ifdef HAVE_SOLARIS_ACLS
     int ace_count = 0;
     ace_t *aces = NULL;
diff --git a/etc/afpd/afp_asp.c b/etc/afpd/afp_asp.c
deleted file mode 100644 (file)
index 3e208f7..0000000
+++ /dev/null
@@ -1,421 +0,0 @@
-/*
- * $Id: afp_asp.c,v 1.29 2010-03-09 06:55:12 franklahm Exp $
- *
- * Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu)
- * Copyright (c) 1990,1993 Regents of The University of Michigan.
- * All Rights Reserved.  See COPYRIGHT.
- *
- * modified from main.c. this handles afp over asp. 
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#ifndef NO_DDP
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <signal.h>
-#include <atalk/logger.h>
-#include <errno.h>
-#ifdef HAVE_SYS_TIME_H
-#include <sys/time.h>
-#endif /* HAVE_SYS_TIME_H */
-#ifdef HAVE_SYS_STAT_H
-#include <sys/stat.h>
-#endif /* HAVE_SYS_STAT_H */
-
-#include <netatalk/endian.h>
-#include <atalk/atp.h>
-#include <atalk/asp.h>
-#include <atalk/compat.h>
-#include <atalk/util.h>
-#include <atalk/globals.h>
-
-#include "switch.h"
-#include "auth.h"
-#include "fork.h"
-
-#ifdef FORCE_UIDGID
-#warning UIDGID
-#include "uid.h"
-#endif /* FORCE_UIDGID */
-
-static AFPObj *child;
-
-static void afp_authprint_remove(AFPObj *);
-
-static void afp_asp_close(AFPObj *obj)
-{
-    ASP asp = obj->handle;
-
-    if (seteuid( obj->uid ) < 0) {
-        LOG(log_error, logtype_afpd, "can't seteuid back %s", strerror(errno));
-        exit(EXITERR_SYS);
-    }
-    close_all_vol();
-    if (obj->options.authprintdir) afp_authprint_remove(obj);
-
-    if (obj->logout)
-        (*obj->logout)();
-
-    LOG(log_info, logtype_afpd, "%.2fKB read, %.2fKB written",
-        asp->read_count / 1024.0, asp->write_count / 1024.0);
-    asp_close( asp );
-}
-
-/* removes the authprint trailing when appropriate */
-static void afp_authprint_remove(AFPObj *obj)
-{
-    ASP asp = obj->handle;
-    char addr_filename[256];
-    char addr_filename_buff[256];
-    struct stat cap_st;
-
-    sprintf(addr_filename, "%s/net%d.%dnode%d", obj->options.authprintdir,
-                ntohs( asp->asp_sat.sat_addr.s_net )/256,
-                ntohs( asp->asp_sat.sat_addr.s_net )%256,
-                asp->asp_sat.sat_addr.s_node );
-
-    memset( addr_filename_buff, 0, 256 );
-
-    if(lstat(addr_filename, &cap_st) == 0) {
-       if( S_ISREG(cap_st.st_mode) ) {
-           int len;
-           int capfd = open( addr_filename, O_RDONLY );
-           if ((len = read( capfd, addr_filename_buff, 256 )) > 0) {
-               int file_pid;
-               char *p_filepid;
-               addr_filename_buff[len] = 0;
-               if ( (p_filepid = strrchr(addr_filename_buff, ':')) != NULL) {
-                   *p_filepid = '\0';
-                   p_filepid++;
-                   file_pid = atoi(p_filepid);
-                   if (file_pid == (int)getpid()) {
-                       if(unlink(addr_filename) == 0) {
-                           LOG(log_info, logtype_afpd, "removed %s", addr_filename);
-                       } else {
-                           LOG(log_info, logtype_afpd, "error removing %s: %s",
-                                   addr_filename, strerror(errno));
-                       }
-                   } else {
-                       LOG(log_info, logtype_afpd, "%s belongs to another pid %d",
-                            addr_filename, file_pid );
-                   }
-               } else { /* no pid info */
-                   if (unlink(addr_filename) == 0) {
-                       LOG(log_info, logtype_afpd, "removed %s", addr_filename );
-                   } else {
-                       LOG(log_info, logtype_afpd, "error removing %s: %s",
-                               addr_filename, strerror(errno));
-                   }
-               }
-           } else {
-               LOG(log_info, logtype_afpd, "couldn't read data from %s", addr_filename );
-           }
-        if (capfd != -1)
-            close(capfd);
-       } else {
-           LOG(log_info, logtype_afpd, "%s is not a regular file", addr_filename );
-       }
-    } else {
-        LOG(log_info, logtype_afpd, "error stat'ing %s: %s",
-                   addr_filename, strerror(errno));
-    }
-}
-
-/* ------------------------
- * SIGTERM
-*/
-static void afp_asp_die(const int sig)
-{
-    ASP asp = child->handle;
-
-    asp_attention(asp, AFPATTN_SHUTDOWN);
-    if ( asp_shutdown( asp ) < 0 ) {
-        LOG(log_error, logtype_afpd, "afp_die: asp_shutdown: %s", strerror(errno) );
-    }
-
-    afp_asp_close(child);
-    if (sig == SIGTERM || sig == SIGALRM)
-        exit( 0 );
-    else
-        exit(sig);
-}
-
-/* -----------------------------
- * SIGUSR1
- */
-static void afp_asp_timedown(int sig _U_)
-{
-    struct sigaction   sv;
-    struct itimerval   it;
-
-    /* shutdown and don't reconnect. server going down in 5 minutes. */
-    asp_attention(child->handle, AFPATTN_SHUTDOWN | AFPATTN_NORECONNECT |
-                  AFPATTN_TIME(5));
-
-    it.it_interval.tv_sec = 0;
-    it.it_interval.tv_usec = 0;
-    it.it_value.tv_sec = 300;
-    it.it_value.tv_usec = 0;
-    if ( setitimer( ITIMER_REAL, &it, NULL ) < 0 ) {
-        LOG(log_error, logtype_afpd, "afp_timedown: setitimer: %s", strerror(errno) );
-        afp_asp_die(EXITERR_SYS);
-    }
-
-    memset(&sv, 0, sizeof(sv));
-    sv.sa_handler = afp_asp_die;
-    sigemptyset( &sv.sa_mask );
-    sigaddset(&sv.sa_mask, SIGHUP);
-    sigaddset(&sv.sa_mask, SIGTERM);
-    sv.sa_flags = SA_RESTART;
-    if ( sigaction( SIGALRM, &sv, NULL ) < 0 ) {
-        LOG(log_error, logtype_afpd, "afp_timedown: sigaction: %s", strerror(errno) );
-        afp_asp_die(EXITERR_SYS);
-    }
-
-    /* ignore myself */
-    sv.sa_handler = SIG_IGN;
-    sigemptyset( &sv.sa_mask );
-    sv.sa_flags = SA_RESTART;
-    if ( sigaction( SIGUSR1, &sv, NULL ) < 0 ) {
-        LOG(log_error, logtype_afpd, "afp_timedown: sigaction SIGUSR1: %s", strerror(errno) );
-        afp_asp_die(EXITERR_SYS);
-    }
-}
-
-/* ---------------------------------
- * SIGHUP reload configuration file
-*/
-extern volatile int reload_request;
-
-static void afp_asp_reload(int sig _U_)
-{
-    reload_request = 1;
-}
-
-/* ---------------------- */
-#ifdef SERVERTEXT
-static void afp_asp_getmesg (int sig _U_)
-{
-    readmessage(child);
-    asp_attention(child->handle, AFPATTN_MESG | AFPATTN_TIME(5));
-}
-#endif /* SERVERTEXT */
-
-/* ---------------------- */
-void afp_over_asp(AFPObj *obj)
-{
-    ASP asp;
-    struct sigaction  action;
-    int                func,  reply = 0;
-#ifdef DEBUG1
-    int ccnt = 0;
-#endif    
-
-    AFPobj = obj;
-    obj->exit = afp_asp_die;
-    obj->reply = (int (*)()) asp_cmdreply;
-    obj->attention = (int (*)(void *, AFPUserBytes)) asp_attention;
-    child = obj;
-    asp = (ASP) obj->handle;
-
-    /* install signal handlers 
-     * With ASP tickle handler is done in the parent process
-    */
-    memset(&action, 0, sizeof(action));
-
-    /* install SIGHUP */
-    action.sa_handler = afp_asp_reload; 
-    sigemptyset( &action.sa_mask );
-    sigaddset(&action.sa_mask, SIGTERM);
-    sigaddset(&action.sa_mask, SIGUSR1);
-#ifdef SERVERTEXT
-    sigaddset(&action.sa_mask, SIGUSR2);
-#endif    
-    action.sa_flags = SA_RESTART;
-    if ( sigaction( SIGHUP, &action, NULL ) < 0 ) {
-        LOG(log_error, logtype_afpd, "afp_over_asp: sigaction: %s", strerror(errno) );
-        afp_asp_die(EXITERR_SYS);
-    }
-
-    /*  install SIGTERM */
-    action.sa_handler = afp_asp_die;
-    sigemptyset( &action.sa_mask );
-    sigaddset(&action.sa_mask, SIGHUP);
-    sigaddset(&action.sa_mask, SIGUSR1);
-#ifdef SERVERTEXT
-    sigaddset(&action.sa_mask, SIGUSR2);
-#endif    
-    action.sa_flags = SA_RESTART;
-    if ( sigaction( SIGTERM, &action, NULL ) < 0 ) {
-        LOG(log_error, logtype_afpd, "afp_over_asp: sigaction: %s", strerror(errno) );
-        afp_asp_die(EXITERR_SYS);
-    }
-
-#ifdef SERVERTEXT
-    /* Added for server message support */
-    action.sa_handler = afp_asp_getmesg;
-    sigemptyset( &action.sa_mask );
-    sigaddset(&action.sa_mask, SIGTERM);
-    sigaddset(&action.sa_mask, SIGUSR1);
-    sigaddset(&action.sa_mask, SIGHUP);
-    action.sa_flags = SA_RESTART;
-    if ( sigaction( SIGUSR2, &action, NULL) < 0 ) {
-        LOG(log_error, logtype_afpd, "afp_over_asp: sigaction: %s", strerror(errno) );
-        afp_asp_die(EXITERR_SYS);
-    }
-#endif /* SERVERTEXT */
-
-    /*  SIGUSR1 - set down in 5 minutes  */
-    action.sa_handler = afp_asp_timedown; 
-    sigemptyset( &action.sa_mask );
-    sigaddset(&action.sa_mask, SIGHUP);
-    sigaddset(&action.sa_mask, SIGTERM);
-#ifdef SERVERTEXT
-    sigaddset(&action.sa_mask, SIGUSR2);
-#endif    
-    action.sa_flags = SA_RESTART;
-    if ( sigaction( SIGUSR1, &action, NULL ) < 0 ) {
-        LOG(log_error, logtype_afpd, "afp_over_asp: sigaction: %s", strerror(errno) );
-        afp_asp_die(EXITERR_SYS);
-    }
-
-    if (dircache_init(obj->options.dircachesize) != 0) {
-        LOG(log_error, logtype_afpd, "afp_over_asp: dircache_init error");
-        afp_asp_die(EXITERR_SYS);
-    }
-
-    LOG(log_info, logtype_afpd, "session from %u.%u:%u on %u.%u:%u",
-        ntohs( asp->asp_sat.sat_addr.s_net ),
-        asp->asp_sat.sat_addr.s_node, asp->asp_sat.sat_port,
-        ntohs( atp_sockaddr( asp->asp_atp )->sat_addr.s_net ),
-        atp_sockaddr( asp->asp_atp )->sat_addr.s_node,
-        atp_sockaddr( asp->asp_atp )->sat_port );
-
-    while ((reply = asp_getrequest(asp))) {
-        if (reload_request) {
-            reload_request = 0;
-            load_volumes(child);
-        }
-        switch (reply) {
-        case ASPFUNC_CLOSE :
-            afp_asp_close(obj);
-            LOG(log_info, logtype_afpd, "done" );
-
-#ifdef DEBUG1
-            if ( obj->options.flags & OPTION_DEBUG ) {
-                printf( "done\n" );
-            }
-#endif
-            return;
-            break;
-
-        case ASPFUNC_CMD :
-#ifdef AFS
-            if ( writtenfork ) {
-                if ( flushfork( writtenfork ) < 0 ) {
-                    LOG(log_error, logtype_afpd, "main flushfork: %s",
-                                               strerror(errno));
-                }
-                writtenfork = NULL;
-            }
-#endif /* AFS */
-            func = (u_char) asp->commands[0];
-#ifdef DEBUG1
-            if ( obj->options.flags & OPTION_DEBUG ) {
-                printf("command: %d (%s)\n", func, AfpNum2name(func));
-                bprint( asp->commands, asp->cmdlen );
-            }
-#endif            
-            if ( afp_switch[ func ] != NULL ) {
-                /*
-                 * The function called from afp_switch is expected to
-                 * read its parameters out of buf, put its
-                 * results in replybuf (updating rbuflen), and
-                 * return an error code.
-                */
-                asp->datalen = ASP_DATASIZ;
-                reply = (*afp_switch[ func ])(obj,
-                                              asp->commands, asp->cmdlen,
-                                              asp->data, &asp->datalen);
-#ifdef FORCE_UIDGID
-               /* bring everything back to old euid, egid */
-               if (obj->force_uid)
-                   restore_uidgid ( &obj->uidgid );
-#endif /* FORCE_UIDGID */
-            } else {
-                LOG(log_error, logtype_afpd, "bad function %X", func );
-                asp->datalen = 0;
-                reply = AFPERR_NOOP;
-            }
-#ifdef DEBUG1
-            if ( obj->options.flags & OPTION_DEBUG ) {
-                printf( "reply: %d, %d\n", reply, ccnt++ );
-                bprint( asp->data, asp->datalen );
-            }
-#endif
-            if ( asp_cmdreply( asp, reply ) < 0 ) {
-                LOG(log_error, logtype_afpd, "asp_cmdreply: %s", strerror(errno) );
-                afp_asp_die(EXITERR_CLNT);
-            }
-            break;
-
-        case ASPFUNC_WRITE :
-            func = (u_char) asp->commands[0];
-#ifdef DEBUG1
-            if ( obj->options.flags & OPTION_DEBUG ) {
-                printf( "(write) command: %d\n", func );
-                bprint( asp->commands, asp->cmdlen );
-            }
-#endif
-            if ( afp_switch[ func ] != NULL ) {
-                asp->datalen = ASP_DATASIZ;
-                reply = (*afp_switch[ func ])(obj,
-                                              asp->commands, asp->cmdlen,
-                                              asp->data, &asp->datalen);
-#ifdef FORCE_UIDGID
-               /* bring everything back to old euid, egid */
-               if (obj->force_uid)
-                   restore_uidgid ( &obj->uidgid );
-#endif /* FORCE_UIDGID */
-            } else {
-                LOG(log_error, logtype_afpd, "(write) bad function %X", func );
-                asp->datalen = 0;
-                reply = AFPERR_NOOP;
-            }
-#ifdef DEBUG1
-            if ( obj->options.flags & OPTION_DEBUG ) {
-                printf( "(write) reply code: %d, %d\n", reply, ccnt++ );
-                bprint( asp->data, asp->datalen );
-            }
-#endif
-            if ( asp_wrtreply( asp, reply ) < 0 ) {
-                LOG(log_error, logtype_afpd, "asp_wrtreply: %s", strerror(errno) );
-                afp_asp_die(EXITERR_CLNT);
-            }
-            break;
-        default:
-            /*
-               * Bad asp packet.  Probably should have asp filter them,
-               * since they are typically things like out-of-order packet.
-               */
-            LOG(log_info, logtype_afpd, "main: asp_getrequest: %d", reply );
-            break;
-        }
-#ifdef DEBUG1
-        if ( obj->options.flags & OPTION_DEBUG ) {
-#ifdef notdef
-            pdesc( stdout );
-#endif /* notdef */
-            of_pforkdesc( stdout );
-            fflush( stdout );
-        }
-#endif
-    }
-}
-
-#endif
index 291148c3458eeeca77432d751f5813128620d198..4b451527c87230584a783d5713c361498d36ab6c 100644 (file)
@@ -25,9 +25,6 @@
 #include <atalk/logger.h>
 #include <atalk/util.h>
 #include <atalk/dsi.h>
-#include <atalk/atp.h>
-#include <atalk/asp.h>
-#include <atalk/nbp.h>
 #include <atalk/afp.h>
 #include <atalk/compat.h>
 #include <atalk/server_child.h>
@@ -64,15 +61,6 @@ void configfree(AFPConfig *configs, const AFPConfig *config)
         }
 
         switch (p->obj.proto) {
-#ifndef NO_DDP
-        case AFPPROTO_ASP:
-            free(p->obj.Obj);
-            free(p->obj.Type);
-            free(p->obj.Zone);
-            atp_close(((ASP) p->obj.handle)->asp_atp);
-            free(p->obj.handle);
-            break;
-#endif /* no afp/asp */
         case AFPPROTO_DSI:
             close(p->fd);
             free(p->obj.handle);
@@ -98,9 +86,6 @@ static char * srvloc_encode(const struct afp_options *options, const char *name)
        char *conv_name;
        unsigned char *p;
        unsigned int i = 0;
-#ifndef NO_DDP
-       char *Obj, *Type = "", *Zone = "";
-#endif
 
        /* Convert name to maccharset */
         if ((size_t)-1 ==(convert_string_allocate( options->unixcharset, options->maccharset,
@@ -129,15 +114,6 @@ static char * srvloc_encode(const struct afp_options *options, const char *name)
        }
        buf[i] = '\0';
 
-#ifndef NO_DDP
-       /* Add ZONE,  */
-        if (nbp_name(options->server, &Obj, &Type, &Zone )) {
-               LOG(log_error, logtype_afpd, "srvloc_encode: can't parse %s", options->server );
-       }
-       else {
-               snprintf( buf+i, sizeof(buf)-i-1 ,"&ZONE=%s", Zone);
-       }
-#endif
        free (conv_name);
 
        return buf;
@@ -182,38 +158,6 @@ srvloc_dereg_err:
 #endif /* USE_SRVLOC */
 }
 
-#ifndef NO_DDP
-static void asp_cleanup(const AFPConfig *config)
-{
-    /* we need to stop tickle handler */
-    asp_stop_tickle();
-    nbp_unrgstr(config->obj.Obj, config->obj.Type, config->obj.Zone,
-                &config->obj.options.ddpaddr);
-}
-
-/* these two are almost identical. it should be possible to collapse them
- * into one with minimal junk. */
-static int asp_start(AFPConfig *config, AFPConfig *configs,
-                     server_child *server_children)
-{
-    ASP asp;
-
-    if (!(asp = asp_getsession(config->obj.handle, server_children,
-                               config->obj.options.tickleval))) {
-        LOG(log_error, logtype_afpd, "main: asp_getsession: %s", strerror(errno) );
-        exit( EXITERR_CLNT );
-    }
-
-    if (asp->child) {
-        configfree(configs, config); /* free a bunch of stuff */
-        afp_over_asp(&config->obj);
-        exit (0);
-    }
-
-    return 0;
-}
-#endif /* no afp/asp */
-
 static afp_child_t *dsi_start(AFPConfig *config, AFPConfig *configs,
                               server_child *server_children)
 {
@@ -240,102 +184,6 @@ static afp_child_t *dsi_start(AFPConfig *config, AFPConfig *configs,
     return child;
 }
 
-#ifndef NO_DDP
-static AFPConfig *ASPConfigInit(const struct afp_options *options,
-                                unsigned char *refcount)
-{
-    AFPConfig *config;
-    ATP atp;
-    ASP asp;
-    char *Obj, *Type = "AFPServer", *Zone = "*";
-    char *convname = NULL;
-
-    if ((config = (AFPConfig *) calloc(1, sizeof(AFPConfig))) == NULL)
-        return NULL;
-
-    if ((atp = atp_open(ATADDR_ANYPORT, &options->ddpaddr)) == NULL)  {
-        LOG(log_error, logtype_afpd, "main: atp_open: %s", strerror(errno) );
-        free(config);
-        return NULL;
-    }
-
-    if ((asp = asp_init( atp )) == NULL) {
-        LOG(log_error, logtype_afpd, "main: asp_init: %s", strerror(errno) );
-        atp_close(atp);
-        free(config);
-        return NULL;
-    }
-
-    /* register asp server */
-    Obj = (char *) options->hostname;
-    if (options->server && (size_t)-1 ==(convert_string_allocate( options->unixcharset, options->maccharset,
-                         options->server, strlen(options->server), &convname)) ) {
-        if ((convname = strdup(options->server)) == NULL ) {
-            LOG(log_error, logtype_afpd, "malloc: %s", strerror(errno) );
-            goto serv_free_return;
-        }
-    }
-
-    if (nbp_name(convname, &Obj, &Type, &Zone )) {
-        LOG(log_error, logtype_afpd, "main: can't parse %s", options->server );
-        goto serv_free_return;
-    }
-    if (convname)
-        free (convname);
-
-    /* dup Obj, Type and Zone as they get assigned to a single internal
-     * buffer by nbp_name */
-    if ((config->obj.Obj  = strdup(Obj)) == NULL)
-        goto serv_free_return;
-
-    if ((config->obj.Type = strdup(Type)) == NULL) {
-        free(config->obj.Obj);
-        goto serv_free_return;
-    }
-
-    if ((config->obj.Zone = strdup(Zone)) == NULL) {
-        free(config->obj.Obj);
-        free(config->obj.Type);
-        goto serv_free_return;
-    }
-
-    /* make sure we're not registered */
-    nbp_unrgstr(Obj, Type, Zone, &options->ddpaddr);
-    if (nbp_rgstr( atp_sockaddr( atp ), Obj, Type, Zone ) < 0 ) {
-        LOG(log_error, logtype_afpd, "Can't register %s:%s@%s", Obj, Type, Zone );
-        free(config->obj.Obj);
-        free(config->obj.Type);
-        free(config->obj.Zone);
-        goto serv_free_return;
-    }
-
-    LOG(log_info, logtype_afpd, "%s:%s@%s started on %u.%u:%u (%s)", Obj, Type, Zone,
-        ntohs( atp_sockaddr( atp )->sat_addr.s_net ),
-        atp_sockaddr( atp )->sat_addr.s_node,
-        atp_sockaddr( atp )->sat_port, VERSION );
-
-    config->fd = atp_fileno(atp);
-    config->obj.handle = asp;
-    config->obj.config = config;
-    config->obj.proto = AFPPROTO_ASP;
-
-    memcpy(&config->obj.options, options, sizeof(struct afp_options));
-    config->optcount = refcount;
-    (*refcount)++;
-
-    config->server_start = asp_start;
-    config->server_cleanup = asp_cleanup;
-
-    return config;
-
-serv_free_return:
-                    asp_close(asp);
-    free(config);
-    return NULL;
-}
-#endif /* no afp/asp */
-
-
 static AFPConfig *DSIConfigInit(const struct afp_options *options,
                                 unsigned char *refcount,
                                 const dsi_proto protocol)
@@ -473,7 +321,7 @@ srvloc_reg_err:
 static AFPConfig *AFPConfigInit(struct afp_options *options,
                                 const struct afp_options *defoptions)
 {
-    AFPConfig *config = NULL, *next = NULL;
+    AFPConfig *next = NULL;
     unsigned char *refcount;
 
     if ((refcount = (unsigned char *)
@@ -482,14 +330,6 @@ static AFPConfig *AFPConfigInit(struct afp_options *options,
         return NULL;
     }
 
-#ifndef NO_DDP
-    /* handle asp transports */
-    if ((options->transports & AFPTRANS_DDP) &&
-            (config = ASPConfigInit(options, refcount)))
-        config->defoptions = defoptions;
-#endif /* NO_DDP */
-
-
     /* set signature */
     set_signature(options);
 
@@ -502,10 +342,11 @@ static AFPConfig *AFPConfigInit(struct afp_options *options,
      *     (next = DSIConfigInit(options, refcount, i)))
      *     next->defoptions = defoptions;
      */
-    if ((options->transports & AFPTRANS_TCP) &&
-            (((options->flags & OPTION_PROXY) == 0) ||
-             ((options->flags & OPTION_PROXY) && config))
-            && (next = DSIConfigInit(options, refcount, DSI_TCPIP)))
+    if ( (options->transports & AFPTRANS_TCP)
+         &&
+         ((options->flags & OPTION_PROXY) == 0)
+         &&
+         (next = DSIConfigInit(options, refcount, DSI_TCPIP)))
         next->defoptions = defoptions;
 
     /* load in all the authentication modules. we can load the same
@@ -517,13 +358,7 @@ static AFPConfig *AFPConfigInit(struct afp_options *options,
 
     /* this should be able to accept multiple dsi transports. i think
      * the only thing that gets affected is the net addresses. */
-    status_init(config, next, options);
-
-    /* attach dsi config to tail of asp config */
-    if (config) {
-        config->next = next;
-        return config;
-    }
+    status_init(next, options);
 
     return next;
 }
index 7d5c482a16951a17c4e87923a099b8d5069b0c14..022a6e65d41e1c979fb7597408b41fb1dd47c139 100644 (file)
@@ -1,16 +1,7 @@
-/*
- * $Id: afp_config.h,v 1.5 2009-10-13 22:55:36 didg Exp $
- */
-
 #ifndef AFPD_CONFIG_H
 #define AFPD_CONFIG_H 1
 
-#ifdef HAVE_SYS_CDEFS_H
-#include <sys/cdefs.h>
-#endif /* HAVE_SYS_CDEFS_H */
-
 #include <atalk/server_child.h>
-#include <atalk/atp.h>
 #include <atalk/globals.h>
 
 typedef struct AFPConfig {
index 3105db63efb4fde7831736e11204b83646b8fa48..94e6f0c8fc79d814d5ab7dc91f04f2d660c7ba0a 100644 (file)
 #include <atalk/paths.h>
 #include <atalk/server_ipc.h>
 #include <atalk/fce_api.h>
-
 #include <atalk/globals.h>
+
 #include "switch.h"
 #include "auth.h"
 #include "fork.h"
 #include "dircache.h"
 
-#ifdef FORCE_UIDGID
-#warning UIDGID
-#include "uid.h"
-#endif /* FORCE_UIDGID */
-
 /* 
  * We generally pass this from afp_over_dsi to all afp_* funcs, so it should already be
  * available everywhere. Unfortunately some funcs (eg acltoownermode) need acces to it
@@ -379,8 +374,8 @@ void afp_over_dsi(AFPObj *obj)
 {
     DSI *dsi = (DSI *) obj->handle;
     int rc_idx;
-    u_int32_t err, cmd;
-    u_int8_t function;
+    uint32_t err, cmd;
+    uint8_t function;
     struct sigaction action;
 
     AFPobj = obj;
@@ -618,11 +613,6 @@ void afp_over_dsi(AFPObj *obj)
 
                     dir_free_invalid_q();
 
-#ifdef FORCE_UIDGID
-                    /* bring everything back to old euid, egid */
-                    if (obj->force_uid)
-                        restore_uidgid ( &obj->uidgid );
-#endif /* FORCE_UIDGID */
                     dsi->flags &= ~DSI_RUNNING;
 
                     /* Add result to the AFP replay cache */
@@ -663,11 +653,6 @@ void afp_over_dsi(AFPObj *obj)
                     AfpNum2name(function), AfpErr2name(err));
 
                 dsi->flags &= ~DSI_RUNNING;
-#ifdef FORCE_UIDGID
-               /* bring everything back to old euid, egid */
-               if (obj->force_uid)
-                   restore_uidgid ( &obj->uidgid );
-#endif /* FORCE_UIDGID */
             } else {
                 LOG(log_error, logtype_afpd, "(write) bad function %x", function);
                 dsi->datalen = 0;
index a66ef8a9c783d35a7e4828b99d0e22470029fc44..256c91a56676a535c4e428ff9f16b23f117d3317 100644 (file)
@@ -431,10 +431,6 @@ int afp_options_parseline(char *buf, struct afp_options *options)
 
     if ((c = getoption(buf, "-port")))
         options->port = strdup(c);
-#ifndef NO_DDP
-    if ((c = getoption(buf, "-ddpaddr")))
-        atalk_aton(c, &options->ddpaddr);
-#endif
     if ((c = getoption(buf, "-signature")) && (opt = strdup(c)))
         options->signatureopt = opt;
 
@@ -544,13 +540,6 @@ static void show_version( void )
        }
        puts( "" );
 
-       printf( "DDP(AppleTalk) Support:\t" );
-#ifdef NO_DDP
-       puts( "No" );
-#else
-       puts( "Yes" );
-#endif
-
        printf( "         CNID backends:\t" );
 #ifdef CNID_BACKEND_CDB
        printf( "cdb ");
@@ -637,20 +626,6 @@ static void show_version_extended(void )
        puts( "No" );
 #endif
 
-       printf( "        Dropbox kludge:\t" );
-#ifdef DROPKLUDGE
-       puts( "Yes" );
-#else
-       puts( "No" );
-#endif
-
-       printf( "  Force volume uid/gid:\t" );
-#ifdef FORCE_UIDGID
-       puts( "Yes" );
-#else
-       puts( "No" );
-#endif
-
        printf( "            EA support:\t" );
        puts( EA_MODULES );
 
index cd506a58ca2aadce8f13238aa4eb451f496b97ee..74a732e60bdd3a2359754aceb162d1bc58606342 100644 (file)
 
 #include <stdio.h>
 #include <stdlib.h>
-
 #include <sys/types.h>
-#define __USE_GNU 1
+/* #define __USE_GNU 1 */
 #include <unistd.h>
 
 #include <errno.h>
-
-#ifdef HAVE_SYS_WAIT_H 
 #include <sys/wait.h>
-#endif
-
 #include <sys/param.h>  
 #include <string.h>
 
index 377d5fb5a6389c2d99a3faf0f0b220f8dc71a741..aebd1adbc52f00bacd1c022cdca3d8b23f5fa087 100644 (file)
@@ -32,7 +32,7 @@
 int afs_getvolspace( vol, bfree, btotal, bsize )
 struct vol     *vol;
 VolSpace       *bfree, *btotal;
-u_int32_t   *bsize;
+uint32_t   *bsize;
 {
     struct ViceIoctl   vi;
     struct VolumeStatus        *vs;
@@ -81,8 +81,8 @@ int afp_getdiracl(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *r
     struct vol         *vol;
     struct dir         *dir;
     struct path                *path;
-    u_int32_t          did;
-    u_int16_t          vid;
+    uint32_t           did;
+    uint16_t           vid;
 
     ibuf += 2;
     memcpy( &vid, ibuf, sizeof( vid ));
@@ -170,8 +170,8 @@ int afp_setdiracl(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *r
     struct dir         *dir;
     char               *iend;
     struct path                *path;
-    u_int32_t          did;
-    u_int16_t          vid;
+    uint32_t           did;
+    uint16_t           vid;
 
     *rbuflen = 0;
     iend = ibuf + ibuflen;
@@ -236,7 +236,7 @@ int afp_afschangepw(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t
     char       realm[ MAXKTCREALMLEN ];
     char       oldpw[ 9 ], newpw[ 9 ];
     int                len, rc;
-    u_int16_t  clen;
+    uint16_t   clen;
     struct ktc_encryptionKey   oldkey, newkey;
     struct ktc_token           adtok;
     struct ubik_client         *conn;
index d791d280843e842e61ea8f7ddbcd891a3a1101c5..59de70e37a4d2ab04a9719f0b80d0b89ea519106 100644 (file)
@@ -87,8 +87,8 @@ static int copyapplfile(int sfd, int dfd, char *mpath, u_short mplen)
 {
     int                cc;
     char       *p;
-    u_int16_t  len;
-    u_char     appltag[ 4 ];
+    uint16_t   len;
+    unsigned char      appltag[ 4 ];
     char       buf[ MAXPATHLEN ];
 
     while (( cc = read( sfd, buf, sizeof(appltag) + sizeof( u_short ))) > 0 ) {
@@ -199,12 +199,12 @@ int afp_addappl(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, siz
     struct vol         *vol;
     struct dir         *dir;
     int                        tfd, cc;
-    u_int32_t           did;
-    u_int16_t          vid, mplen;
+    uint32_t           did;
+    uint16_t           vid, mplen;
     struct path         *path;
     char                *dtf, *p, *mp;
-    u_char             creator[ 4 ];
-    u_char             appltag[ 4 ];
+    unsigned char              creator[ 4 ];
+    unsigned char              appltag[ 4 ];
     char               *mpath, *tempfile;
 
     *rbuflen = 0;
@@ -288,11 +288,11 @@ int afp_rmvappl(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, siz
     struct vol         *vol;
     struct dir         *dir;
     int                        tfd, cc;
-    u_int32_t           did;
-    u_int16_t          vid, mplen;
+    uint32_t           did;
+    uint16_t           vid, mplen;
     struct path        *path;
     char                *dtf, *mp;
-    u_char             creator[ 4 ];
+    unsigned char              creator[ 4 ];
     char                *tempfile, *mpath;
 
     *rbuflen = 0;
@@ -360,9 +360,9 @@ int afp_getappl(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t
     char               *p, *q;
     int                        cc; 
     size_t             buflen;
-    u_int16_t          vid, aindex, bitmap, len;
-    u_char             creator[ 4 ];
-    u_char             appltag[ 4 ];
+    uint16_t           vid, aindex, bitmap, len;
+    unsigned char              creator[ 4 ];
+    unsigned char              appltag[ 4 ];
     char                *buf, *cbuf;
     struct path         *path;
     
index 5220493e09d00632285a63a9fba1c413148ee76f..60a5b69c8c5c76cb8c0c785ed8f278f934f639f7 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 #include <errno.h>
-#ifdef HAVE_UNISTD_H
 #include <unistd.h>
-#endif /* HAVE_UNISTD_H */
 #include <sys/types.h>
 #include <sys/param.h>
 #include <sys/stat.h>
-#include <netatalk/endian.h>
+#include <arpa/inet.h>
+
 #include <atalk/afp.h>
 #include <atalk/compat.h>
 #include <atalk/util.h>
@@ -78,23 +77,16 @@ static struct uam_obj uam_changepw = {"", "", 0, {{NULL, NULL, NULL, NULL}}, &ua
 static struct uam_obj *afp_uam = NULL;
 
 
-void status_versions(char *data,
-#ifndef NO_DDP
-                     const ASP asp,
-#endif
-                     const DSI *dsi)
+void status_versions( char *data, const DSI *dsi)
 {
     char                *start = data;
-    u_int16_t           status;
+    uint16_t           status;
     int         len, num, i, count = 0;
 
     memcpy(&status, start + AFPSTATUS_VERSOFF, sizeof(status));
     num = sizeof( afp_versions ) / sizeof( afp_versions[ 0 ] );
 
     for ( i = 0; i < num; i++ ) {
-#ifndef NO_DDP
-        if ( !asp && (afp_versions[ i ].av_number <= 21)) continue;
-#endif /* ! NO_DDP */
         if ( !dsi && (afp_versions[ i ].av_number >= 22)) continue;
         count++;
     }
@@ -102,9 +94,6 @@ void status_versions(char *data,
     *data++ = count;
 
     for ( i = 0; i < num; i++ ) {
-#ifndef NO_DDP
-        if ( !asp && (afp_versions[ i ].av_number <= 21)) continue;
-#endif /* ! NO_DDP */
         if ( !dsi && (afp_versions[ i ].av_number >= 22)) continue;
         len = strlen( afp_versions[ i ].av_name );
         *data++ = len;
@@ -118,7 +107,7 @@ void status_versions(char *data,
 void status_uams(char *data, const char *authlist)
 {
     char                *start = data;
-    u_int16_t           status;
+    uint16_t           status;
     struct uam_obj      *uams;
     int         len, num = 0;
 
@@ -269,45 +258,6 @@ static int login(AFPObj *obj, struct passwd *pwd, void (*logout)(void), int expi
     LOG(log_note, logtype_afpd, "%s Login by %s",
         afp_versions[afp_version_index].av_name, pwd->pw_name);
 
-#ifndef NO_DDP
-    if (obj->proto == AFPPROTO_ASP) {
-        ASP asp = obj->handle;
-        int addr_net = ntohs( asp->asp_sat.sat_addr.s_net );
-        int addr_node  = asp->asp_sat.sat_addr.s_node;
-
-        if (obj->options.authprintdir) {
-            if(addr_net && addr_node) { /* Do we have a valid Appletalk address? */
-                char nodename[256];
-                FILE *fp;
-                int mypid = getpid();
-                struct stat stat_buf;
-
-                sprintf(nodename, "%s/net%d.%dnode%d", obj->options.authprintdir,
-                        addr_net / 256, addr_net % 256, addr_node);
-                LOG(log_info, logtype_afpd, "registering %s (uid %d) on %u.%u as %s",
-                    pwd->pw_name, pwd->pw_uid, addr_net, addr_node, nodename);
-
-                if (stat(nodename, &stat_buf) == 0) { /* file exists */
-                    if (S_ISREG(stat_buf.st_mode)) { /* normal file */
-                        unlink(nodename);
-                        fp = fopen(nodename, "w");
-                        fprintf(fp, "%s:%d\n", pwd->pw_name, mypid);
-                        fclose(fp);
-                        chown( nodename, pwd->pw_uid, -1 );
-                    } else { /* somebody is messing with us */
-                        LOG(log_error, logtype_afpd, "print authfile %s is not a normal file, it will not be modified", nodename );
-                    }
-                } else { /* file 'nodename' does not exist */
-                    fp = fopen(nodename, "w");
-                    fprintf(fp, "%s:%d\n", pwd->pw_name, mypid);
-                    fclose(fp);
-                    chown( nodename, pwd->pw_uid, -1 );
-                }
-            } /* if (addr_net && addr_node ) */
-        } /* if (options->authprintdir) */
-    } /* if (obj->proto == AFPPROTO_ASP) */
-#endif
-
     if (initgroups( pwd->pw_name, pwd->pw_gid ) < 0) {
 #ifdef RUN_AS_USER
         LOG(log_info, logtype_afpd, "running with uid %d", geteuid());
@@ -407,11 +357,6 @@ static int login(AFPObj *obj, struct passwd *pwd, void (*logout)(void), int expi
     obj->uid = geteuid();
     obj->logout = logout;
 
-#ifdef FORCE_UIDGID
-    obj->force_uid = 1;
-    save_uidgid ( &obj->uidgid );
-#endif
-
     return( AFP_OK );
 }
 
@@ -511,10 +456,10 @@ int afp_getsession(
     char   *ibuf, size_t ibuflen, 
     char   *rbuf, size_t *rbuflen)
 {
-    u_int16_t           type;
-    u_int32_t           idlen = 0;
-    u_int32_t       boottime;
-    u_int32_t           tklen, tp;
+    uint16_t           type;
+    uint32_t           idlen = 0;
+    uint32_t       boottime;
+    uint32_t           tklen, tp;
     char                *token;
     char                *p;
 
@@ -613,8 +558,8 @@ int afp_getsession(
 int afp_disconnect(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen)
 {
     DSI                 *dsi = (DSI *)obj->handle;
-    u_int16_t           type;
-    u_int32_t           tklen;
+    uint16_t           type;
+    uint32_t           tklen;
     pid_t               token;
     int                 i;
 
@@ -780,7 +725,7 @@ int afp_login_ext(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *r
     size_t  len;
     int     i;
     char        type;
-    u_int16_t   len16;
+    uint16_t   len16;
     char        *username;
 
     *rbuflen = 0;
@@ -1012,9 +957,9 @@ int afp_changepw(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rb
 /* FPGetUserInfo */
 int afp_getuserinfo(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbuflen)
 {
-    u_int8_t  thisuser;
-    u_int32_t id;
-    u_int16_t bitmap;
+    uint8_t  thisuser;
+    uint32_t id;
+    uint16_t bitmap;
     char *bitmapp;
 
     LOG(log_debug, logtype_afpd, "begin afp_getuserinfo:");
index beda0d02ffdcb9d2c92d818560e84423017c93ae..46c23fbd1fc7bfe856ef3377bb42ee1879c6f030 100644 (file)
@@ -6,13 +6,7 @@
 #ifndef AFPD_AUTH_H
 #define AFPD_AUTH_H 1
 
-#ifdef HAVE_LIMITS_H
 #include <limits.h>
-#endif /* HAVE_LIMITS_H */
-
-#ifdef HAVE_SYS_CDEFS_H
-#include <sys/cdefs.h>
-#endif /* HAVE_SYS_CDEFS_H */
 
 #include <atalk/globals.h>
 
index 71d1a44608af098cefa519234a15bdb216461e1d..ad28c6f668d4f36f539d1884c2bd61d3f83f2351 100644 (file)
 
 
 struct finderinfo {
-       u_int32_t f_type;
-       u_int32_t creator;
-       u_int16_t attrs;    /* File attributes (high 8 bits)*/
-       u_int16_t label;    /* Label (low 8 bits )*/
+       uint32_t f_type;
+       uint32_t creator;
+       uint16_t attrs;    /* File attributes (high 8 bits)*/
+       uint16_t label;    /* Label (low 8 bits )*/
        char reserved[22]; /* Unknown (at least for now...) */
 };
 
@@ -86,14 +86,14 @@ typedef char packed_finder[ADEDLEN_FINDERI];
 
 /* This is our search-criteria structure. */
 struct scrit {
-       u_int32_t rbitmap;          /* Request bitmap - which values should we check ? */
-       u_int16_t fbitmap, dbitmap; /* file & directory bitmap - which values should we return ? */
-       u_int16_t attr;             /* File attributes */
+       uint32_t rbitmap;          /* Request bitmap - which values should we check ? */
+       uint16_t fbitmap, dbitmap; /* file & directory bitmap - which values should we return ? */
+       uint16_t attr;             /* File attributes */
        time_t cdate;               /* Creation date */
        time_t mdate;               /* Last modification date */
        time_t bdate;               /* Last backup date */
-       u_int32_t pdid;             /* Parent DID */
-    u_int16_t offcnt;           /* Offspring count */
+       uint32_t pdid;             /* Parent DID */
+    uint16_t offcnt;           /* Offspring count */
        struct finderinfo finfo;    /* Finder info */
        char lname[64];             /* Long name */ 
        char utf8name[514];         /* UTF8 or UCS2 name */ /* for convert_charset dest_len parameter +2 */
@@ -210,7 +210,7 @@ static struct adouble *adl_lkup(struct vol *vol, struct path *path, struct adoub
        if (!isdir && (of = of_findname(path))) {
                adp = of->of_ad;
        } else {
-               ad_init(&ad, vol->v_adouble, vol->v_ad_options);
+               ad_init(&ad, vol);
                adp = &ad;
        } 
 
@@ -257,11 +257,11 @@ unpack_finderinfo(struct vol *vol, struct path *path, struct adouble **adp, stru
  */
 static int crit_check(struct vol *vol, struct path *path) {
        int result = 0;
-       u_int16_t attr, flags = CONV_PRECOMPOSE;
+       uint16_t attr, flags = CONV_PRECOMPOSE;
        struct finderinfo *finfo = NULL, finderinfo;
        struct adouble *adp = NULL;
        time_t c_date, b_date;
-       u_int32_t ac_date, ab_date;
+       uint32_t ac_date, ab_date;
        static char convbuf[514]; /* for convert_charset dest_len parameter +2 */
        size_t len;
     int islnk;
@@ -418,7 +418,7 @@ static int crit_check(struct vol *vol, struct path *path) {
        result |= 1;
 crit_check_ret:
        if (adp != NULL)
-               ad_close_metadata(adp);
+               ad_close(adp, ADFLAGS_HF);
        return result;
 }  
 
@@ -429,7 +429,7 @@ static int rslt_add ( struct vol *vol, struct path *path, char **buf, int ext)
        char            *p = *buf;
        int             ret;
        size_t          tbuf =0;
-       u_int16_t       resultsize;
+       uint16_t        resultsize;
        int             isdir = S_ISDIR(path->st.st_mode); 
 
        /* Skip resultsize */
@@ -502,7 +502,7 @@ static int catsearch(struct vol *vol,
                      int *rsize,
                      int ext)
 {
-    static u_int32_t cur_pos;    /* Saved position index (ID) - used to remember "position" across FPCatSearch calls */
+    static uint32_t cur_pos;    /* Saved position index (ID) - used to remember "position" across FPCatSearch calls */
     static DIR *dirpos;                 /* UNIX structure describing currently opened directory. */
     struct dir *currentdir;      /* struct dir of current directory */
        int cidx, r;
@@ -846,17 +846,17 @@ static int catsearch_afp(AFPObj *obj _U_, char *ibuf, size_t ibuflen,
                   char *rbuf, size_t *rbuflen, int ext)
 {
     struct vol *vol;
-    u_int16_t   vid;
-    u_int16_t   spec_len;
-    u_int32_t   rmatches, reserved;
-    u_int32_t  catpos[4];
-    u_int32_t   pdid = 0;
+    uint16_t   vid;
+    uint16_t   spec_len;
+    uint32_t   rmatches, reserved;
+    uint32_t   catpos[4];
+    uint32_t   pdid = 0;
     int ret, rsize;
-    u_int32_t nrecs = 0;
+    uint32_t nrecs = 0;
     unsigned char *spec1, *spec2, *bspec1, *bspec2;
     size_t     len;
-    u_int16_t  namelen;
-    u_int16_t  flags;
+    uint16_t   namelen;
+    uint16_t   flags;
     char           tmppath[256];
     char        *uname;
 
index 8b6efd7e1bdac95dc73170d0ab6c0bdc4940b42c..adf6bbb3d0023dcefac8634b3da5ddd75db9024e 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: desktop.c,v 1.50.2.1 2010-02-01 10:56:08 franklahm Exp $
- *
  * See COPYRIGHT.
  *
  * bug:
 #include <sys/uio.h>
 #include <sys/param.h>
 #include <sys/socket.h>
-#include <netatalk/at.h>
-#include <netatalk/endian.h>
+#include <arpa/inet.h>
+
 #include <atalk/dsi.h>
-#include <atalk/atp.h>
-#include <atalk/asp.h>
 #include <atalk/afp.h>
 #include <atalk/util.h>
 #include <atalk/logger.h>
@@ -42,7 +38,7 @@
 int afp_opendt(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbuflen)
 {
     struct vol *vol;
-    u_int16_t  vid;
+    uint16_t   vid;
 
     ibuf += 2;
 
@@ -118,14 +114,11 @@ static int iconopen(struct vol *vol, u_char creator[ 4 ], int flags, int mode)
 int afp_addicon(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbuflen)
 {
     struct vol         *vol;
-#ifndef NO_DDP
-    struct iovec       iov[ 2 ];
-#endif
     u_char             fcreator[ 4 ], imh[ 12 ], irh[ 12 ], *p;
     int                        itype, cc = AFP_OK, iovcnt = 0;
     size_t             buflen;
-    u_int32_t           ftype, itag;
-    u_int16_t          bsize, rsize, vid;
+    uint32_t           ftype, itag;
+    uint16_t           bsize, rsize, vid;
 
     buflen = *rbuflen;
     *rbuflen = 0;
@@ -219,44 +212,6 @@ addicon_err:
     }
 
     switch (obj->proto) {
-#ifndef NO_DDP
-    case AFPPROTO_ASP:
-        buflen = bsize;
-        if ((asp_wrtcont(obj->handle, rbuf, &buflen) < 0) || buflen != bsize)
-            return( AFPERR_PARAM );
-
-#ifdef DEBUG1
-        if (obj->options.flags & OPTION_DEBUG) {
-            printf("(write) len: %d\n", buflen);
-            bprint(rbuf, buflen);
-        }
-#endif
-
-        /*
-         * We're at the end of the file, add the headers, etc.  */
-        if ( cc == 0 ) {
-            iov[ 0 ].iov_base = (caddr_t)imh;
-            iov[ 0 ].iov_len = sizeof( imh );
-            iov[ 1 ].iov_base = rbuf;
-            iov[ 1 ].iov_len = bsize;
-            iovcnt = 2;
-        }
-
-        /*
-         * We found an icon to replace.
-         */
-        if ( cc > 0 ) {
-            iov[ 0 ].iov_base = rbuf;
-            iov[ 0 ].iov_len = bsize;
-            iovcnt = 1;
-        }
-
-        if ( writev( si.sdt_fd, iov, iovcnt ) < 0 ) {
-            LOG(log_error, logtype_afpd, "afp_addicon(%s): writev: %s", icon_dtfile(vol, fcreator), strerror(errno) );
-            return( AFPERR_PARAM );
-        }
-        break;
-#endif /* no afp/asp */      
     case AFPPROTO_DSI:
         {
             DSI *dsi = obj->handle;
@@ -337,8 +292,8 @@ static const u_char uicon[] = {
 int afp_geticoninfo(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbuflen)
 {
     struct vol *vol;
-    u_char     fcreator[ 4 ], ih[ 12 ];
-    u_int16_t  vid, iindex, bsize;
+    unsigned char      fcreator[ 4 ], ih[ 12 ];
+    uint16_t   vid, iindex, bsize;
 
     *rbuflen = 0;
     ibuf += 2;
@@ -411,7 +366,7 @@ int afp_geticon(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t
     off_t       offset;
     ssize_t    rc, buflen;
     u_char     fcreator[ 4 ], ftype[ 4 ], itype, ih[ 12 ];
-    u_int16_t  vid, bsize, rsize;
+    uint16_t   vid, bsize, rsize;
 
     buflen = *rbuflen;
     *rbuflen = 0;
@@ -597,7 +552,7 @@ char *mtoupath(const struct vol *vol, char *mpath, cnid_t did, int utf8)
     char       *m, *u;
     size_t       inplen;
     size_t       outlen;
-    u_int16_t   flags;
+    uint16_t    flags;
         
     if ( *mpath == '\0' ) {
         strcpy(upath, ".");
@@ -636,7 +591,7 @@ char *utompath(const struct vol *vol, char *upath, cnid_t id, int utf8)
 {
     static char  mpath[ MAXPATHLEN + 2]; /* for convert_charset dest_len parameter +2 */
     char        *m, *u;
-    u_int16_t    flags;
+    uint16_t    flags;
     size_t       outlen;
 
     m = mpath;
@@ -689,12 +644,14 @@ static int ad_addcomment(struct vol *vol, struct path *path, char *ibuf)
     
     isadir = path_isadir(path);
     if (isadir || !(of = of_findname(path))) {
-        ad_init(&ad, vol->v_adouble, vol->v_ad_options);
+        ad_init(&ad, vol);
         adp = &ad;
     } else
         adp = of->of_ad;
 
-    if (ad_open_metadata( upath , ( (isadir) ? ADFLAGS_DIR : 0), O_CREAT, adp) < 0 ) {
+    if (ad_open(adp, upath,
+                ADFLAGS_HF | ( (isadir) ? ADFLAGS_DIR : 0) | ADFLAGS_CREATE | ADFLAGS_RDWR,
+                0666) < 0 ) {
         return( AFPERR_ACCESS );
     }
 
@@ -711,7 +668,7 @@ static int ad_addcomment(struct vol *vol, struct path *path, char *ibuf)
         memcpy( ad_entry( adp, ADEID_COMMENT ), ibuf, clen );
         ad_flush( adp );
     }
-    ad_close_metadata( adp);
+    ad_close(adp, ADFLAGS_HF);
     return( AFP_OK );
 }
 
@@ -721,8 +678,8 @@ int afp_addcomment(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf _
     struct vol         *vol;
     struct dir         *dir;
     struct path         *path;
-    u_int32_t           did;
-    u_int16_t          vid;
+    uint32_t           did;
+    uint16_t           vid;
 
     *rbuflen = 0;
     ibuf += 2;
@@ -762,7 +719,7 @@ static int ad_getcomment(struct vol *vol, struct path *path, char *rbuf, size_t
     upath = path->u_name;
     isadir = path_isadir(path);
     if (isadir || !(of = of_findname(path))) {
-        ad_init(&ad, vol->v_adouble, vol->v_ad_options);
+        ad_init(&ad, vol);
         adp = &ad;
     } else
         adp = of->of_ad;
@@ -772,7 +729,7 @@ static int ad_getcomment(struct vol *vol, struct path *path, char *rbuf, size_t
     }
 
     if (!ad_getentryoff(adp, ADEID_COMMENT)) {
-        ad_close_metadata( adp );
+        ad_close(adp, ADFLAGS_HF);
         return AFPERR_NOITEM;
     }
     /*
@@ -780,7 +737,7 @@ static int ad_getcomment(struct vol *vol, struct path *path, char *rbuf, size_t
      */
     if ( ad_getentrylen( adp, ADEID_COMMENT ) <= 0 ||
             ad_getentrylen( adp, ADEID_COMMENT ) > 199 ) {
-        ad_close_metadata( adp );
+        ad_close(adp, ADFLAGS_HF);
         return( AFPERR_NOITEM );
     }
 
@@ -788,7 +745,7 @@ static int ad_getcomment(struct vol *vol, struct path *path, char *rbuf, size_t
     *rbuf++ = clen;
     memcpy( rbuf, ad_entry( adp, ADEID_COMMENT ), clen);
     *rbuflen = clen + 1;
-    ad_close_metadata( adp);
+    ad_close(adp, ADFLAGS_HF);
 
     return( AFP_OK );
 }
@@ -799,8 +756,8 @@ int afp_getcomment(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf,
     struct vol         *vol;
     struct dir         *dir;
     struct path         *s_path;
-    u_int32_t          did;
-    u_int16_t          vid;
+    uint32_t           did;
+    uint16_t           vid;
     
     *rbuflen = 0;
     ibuf += 2;
@@ -839,12 +796,12 @@ static int ad_rmvcomment(struct vol *vol, struct path *path)
 
     isadir = path_isadir(path);
     if (isadir || !(of = of_findname(path))) {
-        ad_init(&ad, vol->v_adouble, vol->v_ad_options);
+        ad_init(&ad, vol);
         adp = &ad;
     } else
         adp = of->of_ad;
 
-    if ( ad_open_metadata( upath, (isadir) ? ADFLAGS_DIR : 0, 0, adp) < 0 ) {
+    if ( ad_open(adp, upath, ADFLAGS_HF | ADFLAGS_RDWR | ((isadir) ? ADFLAGS_DIR : 0)) < 0 ) {
         switch ( errno ) {
         case ENOENT :
             return( AFPERR_NOITEM );
@@ -859,7 +816,7 @@ static int ad_rmvcomment(struct vol *vol, struct path *path)
         ad_setentrylen( adp, ADEID_COMMENT, 0 );
         ad_flush( adp );
     }
-    ad_close_metadata( adp);
+    ad_close(adp, ADFLAGS_HF);
     return( AFP_OK );
 }
 
@@ -869,8 +826,8 @@ int afp_rmvcomment(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf _
     struct vol         *vol;
     struct dir         *dir;
     struct path         *s_path;
-    u_int32_t          did;
-    u_int16_t          vid;
+    uint32_t           did;
+    uint16_t           vid;
 
     *rbuflen = 0;
     ibuf += 2;
index a220a478ee7eebf19841f3c69fcb2f43217ab32f..ccaa1654ab3b9c63a8f1c57b9c5ed3a679cee469 100644 (file)
@@ -26,8 +26,8 @@
 #ifndef AFPD_DESKTOP_H
 #define AFPD_DESKTOP_H 1
 
-#include <sys/cdefs.h>
 #include <atalk/globals.h>
+
 #include "volume.h"
 
 struct savedt {
index 78670ac1cfb1c6b339ae7d71f7f07c3d0ab87cda..53bfb201092f2b545e14d3431df0842a79464f0c 100644 (file)
@@ -710,7 +710,7 @@ int caseenumerate(const struct vol *vol, struct path *path, struct dir *dir)
     DIR               *dp;
     struct dirent     *de;
     int               ret;
-    static u_int32_t  did = 0;
+    static uint32_t  did = 0;
     static char       cname[MAXPATHLEN];
     static char       lname[MAXPATHLEN];
     ucs2_t        u2_path[MAXPATHLEN];
@@ -912,8 +912,8 @@ struct dir *dir_add(struct vol *vol, const struct dir *dir, struct path *path, i
     }
 
     /* get_id needs adp for reading CNID from adouble file */
-    ad_init(&ad, vol->v_adouble, vol->v_ad_options);
-    if ((ad_open_metadata(path->u_name, ADFLAGS_DIR, 0, &ad)) == 0) /* 1 */
+    ad_init(&ad, vol);
+    if ((ad_open(&ad, path->u_name, ADFLAGS_HF | ADFLAGS_DIR | ADFLAGS_RDONLY)) == 0) /* 1 */
         adp = &ad;
 
     /* Get CNID */
@@ -923,7 +923,7 @@ struct dir *dir_add(struct vol *vol, const struct dir *dir, struct path *path, i
     }
 
     if (adp)
-        ad_close_metadata(adp);
+        ad_close(adp, ADFLAGS_HF);
 
     /* Get macname from unixname */
     if (path->m_name == NULL) {
@@ -966,7 +966,7 @@ exit:
             cfrombstr(dir->d_u_name), path->u_name, err);
 
         if (adp)
-            ad_close_metadata(adp);
+            ad_close(adp, ADFLAGS_HF);
         if (!cdir && fullpath)
             bdestroy(fullpath);
         if (cdir)
@@ -1143,8 +1143,8 @@ struct path *cname(struct vol *vol, struct dir *dir, char **cpath)
     struct dir  *cdir;
     char        *data, *p;
     int         len;
-    u_int32_t   hint;
-    u_int16_t   len16;
+    uint32_t   hint;
+    uint16_t   len16;
     int         size = 0;
     int         toUTF8 = 0;
 
@@ -1456,7 +1456,7 @@ int file_access(struct path *path, int mode)
 }
 
 /* --------------------- */
-void setdiroffcnt(struct dir *dir, struct stat *st,  u_int32_t count)
+void setdiroffcnt(struct dir *dir, struct stat *st,  uint32_t count)
 {
     dir->d_offcnt = count;
     dir->d_ctime = st->st_ctime;
@@ -1478,7 +1478,7 @@ int dirreenumerate(struct dir *dir, struct stat *st)
 */
 
 int getdirparams(const struct vol *vol,
-                 u_int16_t bitmap, struct path *s_path,
+                 uint16_t bitmap, struct path *s_path,
                  struct dir *dir,
                  char *buf, size_t *buflen )
 {
@@ -1486,10 +1486,10 @@ int getdirparams(const struct vol *vol,
     struct adouble  ad;
     char        *data, *l_nameoff = NULL, *utf_nameoff = NULL;
     int         bit = 0, isad = 0;
-    u_int32_t           aint;
-    u_int16_t       ashort;
+    uint32_t           aint;
+    uint16_t       ashort;
     int                 ret;
-    u_int32_t           utf8 = 0;
+    uint32_t           utf8 = 0;
     cnid_t              pdid;
     struct stat *st = &s_path->st;
     char *upath = s_path->u_name;
@@ -1500,10 +1500,10 @@ int getdirparams(const struct vol *vol,
                    (1 << DIRPBIT_BDATE) |
                    (1 << DIRPBIT_FINFO)))) {
 
-        ad_init(&ad, vol->v_adouble, vol->v_ad_options);
-        if ( !ad_metadata( upath, ADFLAGS_CREATE|ADFLAGS_DIR, &ad) ) {
+        ad_init(&ad, vol);
+        if ( !ad_metadata( upath, ADFLAGS_DIR, &ad) ) {
             isad = 1;
-            if (ad.ad_md->adf_flags & O_CREAT) {
+            if (ad.ad_mdp->adf_flags & O_CREAT) {
                 /* We just created it */
                 if (s_path->m_name == NULL) {
                     if ((s_path->m_name = utompath(vol,
@@ -1598,13 +1598,13 @@ int getdirparams(const struct vol *vol,
             if (dir->d_m_name) /* root of parent can have a null name */
                 l_nameoff = data;
             else
-                memset(data, 0, sizeof(u_int16_t));
-            data += sizeof( u_int16_t );
+                memset(data, 0, sizeof(uint16_t));
+            data += sizeof( uint16_t );
             break;
 
         case DIRPBIT_SNAME :
-            memset(data, 0, sizeof(u_int16_t));
-            data += sizeof( u_int16_t );
+            memset(data, 0, sizeof(uint16_t));
+            data += sizeof( uint16_t );
             break;
 
         case DIRPBIT_DID :
@@ -1659,8 +1659,8 @@ int getdirparams(const struct vol *vol,
                 if (dir->d_m_name) /* root of parent can have a null name */
                     utf_nameoff = data;
                 else
-                    memset(data, 0, sizeof(u_int16_t));
-                data += sizeof( u_int16_t );
+                    memset(data, 0, sizeof(uint16_t));
+                data += sizeof( uint16_t );
                 aint = 0;
                 memcpy(data, &aint, sizeof( aint ));
                 data += sizeof( aint );
@@ -1700,7 +1700,7 @@ int getdirparams(const struct vol *vol,
 
         default :
             if ( isad ) {
-                ad_close_metadata( &ad );
+                ad_close(&ad, ADFLAGS_HF);
             }
             return( AFPERR_BITMAP );
         }
@@ -1718,7 +1718,7 @@ int getdirparams(const struct vol *vol,
         data = set_name(vol, data, pdid, cfrombstr(dir->d_m_name), dir->d_did, utf8);
     }
     if ( isad ) {
-        ad_close_metadata( &ad );
+        ad_close(&ad, ADFLAGS_HF);
     }
     *buflen = data - buf;
     return( AFP_OK );
@@ -1744,8 +1744,8 @@ int afp_setdirparams(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_
     struct vol  *vol;
     struct dir  *dir;
     struct path *path;
-    u_int16_t   vid, bitmap;
-    u_int32_t   did;
+    uint16_t   vid, bitmap;
+    uint32_t   did;
     int     rc;
 
     *rbuflen = 0;
@@ -1800,7 +1800,7 @@ int afp_setdirparams(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_
  *
  * assume path == '\0' eg. it's a directory in canonical form
  */
-int setdirparams(struct vol *vol, struct path *path, u_int16_t d_bitmap, char *buf )
+int setdirparams(struct vol *vol, struct path *path, uint16_t d_bitmap, char *buf )
 {
     struct maccess  ma;
     struct adouble  ad;
@@ -1812,16 +1812,16 @@ int setdirparams(struct vol *vol, struct path *path, u_int16_t d_bitmap, char *b
     int         bit, isad = 1;
     int                 cdate, bdate;
     int                 owner, group;
-    u_int16_t       ashort, bshort, oshort;
+    uint16_t       ashort, bshort, oshort;
     int                 err = AFP_OK;
     int                 change_mdate = 0;
     int                 change_parent_mdate = 0;
     int                 newdate = 0;
-    u_int16_t           bitmap = d_bitmap;
+    uint16_t           bitmap = d_bitmap;
     u_char              finder_buf[32];
-    u_int32_t       upriv;
+    uint32_t       upriv;
     mode_t              mpriv = 0;
-    u_int16_t           upriv_bit = 0;
+    uint16_t           upriv_bit = 0;
 
     bit = 0;
     upath = path->u_name;
@@ -1927,9 +1927,9 @@ int setdirparams(struct vol *vol, struct path *path, u_int16_t d_bitmap, char *b
         bitmap = bitmap>>1;
         bit++;
     }
-    ad_init(&ad, vol->v_adouble, vol->v_ad_options);
+    ad_init(&ad, vol);
 
-    if (ad_open_metadata( upath, ADFLAGS_DIR, O_CREAT, &ad) < 0) {
+    if (ad_open(&ad, upath, ADFLAGS_HF | ADFLAGS_DIR | ADFLAGS_CREATE | ADFLAGS_RDWR, 0777) != 0) {
         /*
          * Check to see what we're trying to set.  If it's anything
          * but ACCESS, UID, or GID, give an error.  If it's any of those
@@ -1951,7 +1951,7 @@ int setdirparams(struct vol *vol, struct path *path, u_int16_t d_bitmap, char *b
          * Check to see if a create was necessary. If it was, we'll want
          * to set our name, etc.
          */
-        if ( (ad_get_HF_flags( &ad ) & O_CREAT)) {
+        if ( (ad_get_MD_flags( &ad ) & O_CREAT)) {
             ad_setname(&ad, cfrombstr(curdir->d_m_name));
         }
     }
@@ -1994,7 +1994,7 @@ int setdirparams(struct vol *vol, struct path *path, u_int16_t d_bitmap, char *b
         case DIRPBIT_FINFO :
             if (isad) {
                 /* Fixes #2802236 */
-                u_int16_t *fflags = (u_int16_t *)(finder_buf + FINDERINFO_FRFLAGOFF);
+                uint16_t *fflags = (uint16_t *)(finder_buf + FINDERINFO_FRFLAGOFF);
                 *fflags &= htons(~FINDERINFO_ISHARED);
                 /* #2802236 end */
                 if (  dir->d_did == DIRDID_ROOT ) {
@@ -2113,8 +2113,8 @@ setdirparam_done:
                 ad_setid(&ad, st->st_dev, st->st_ino,  dir->d_did, dir->d_pdid, vol->v_stamp);
             }
         }
-        ad_flush( &ad);
-        ad_close_metadata( &ad);
+        ad_flush(&ad);
+        ad_close(&ad, ADFLAGS_HF);
     }
 
     if (change_parent_mdate && dir->d_did != DIRDID_ROOT
@@ -2139,8 +2139,8 @@ int afp_syncdir(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf _U_,
     int                  dfd;
     struct vol           *vol;
     struct dir           *dir;
-    u_int32_t            did;
-    u_int16_t            vid;
+    uint32_t            did;
+    uint16_t            vid;
 
     *rbuflen = 0;
     ibuf += 2;
@@ -2228,8 +2228,8 @@ int afp_createdir(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_
     struct dir      *dir;
     char        *upath;
     struct path         *s_path;
-    u_int32_t       did;
-    u_int16_t       vid;
+    uint32_t       did;
+    uint16_t       vid;
     int                 err;
 
     *rbuflen = 0;
@@ -2281,8 +2281,8 @@ int afp_createdir(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_
         return( AFPERR_PARAM );
     }
 
-    ad_init(&ad, vol->v_adouble, vol->v_ad_options);
-    if (ad_open_metadata( ".", ADFLAGS_DIR, O_CREAT, &ad ) < 0)  {
+    ad_init(&ad, vol);
+    if (ad_open(&ad, ".", ADFLAGS_HF | ADFLAGS_DIR | ADFLAGS_CREATE | ADFLAGS_RDWR, 0777) < 0)  {
         if (vol_noadouble(vol))
             goto createdir_done;
         return( AFPERR_ACCESS );
@@ -2292,12 +2292,12 @@ int afp_createdir(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_
 
     fce_register_new_dir(s_path);
 
-    ad_flush( &ad);
-    ad_close_metadata( &ad);
+    ad_flush(&ad);
+    ad_close(&ad, ADFLAGS_HF);
 
 createdir_done:
-    memcpy( rbuf, &dir->d_did, sizeof( u_int32_t ));
-    *rbuflen = sizeof( u_int32_t );
+    memcpy( rbuf, &dir->d_did, sizeof( uint32_t ));
+    *rbuflen = sizeof( uint32_t );
     setvoltime(obj, vol );
     return( AFP_OK );
 }
@@ -2348,12 +2348,12 @@ int renamedir(const struct vol *vol,
 
     vol->vfs->vfs_renamedir(vol, dirfd, src, dst);
 
-    ad_init(&ad, vol->v_adouble, vol->v_ad_options);
+    ad_init(&ad, vol);
 
-    if (!ad_open_metadata( dst, ADFLAGS_DIR, 0, &ad)) {
+    if (ad_open(&ad, dst, ADFLAGS_HF | ADFLAGS_DIR | ADFLAGS_RDWR) == 0) {
         ad_setname(&ad, newname);
-        ad_flush( &ad);
-        ad_close_metadata( &ad);
+        ad_flush(&ad);
+        ad_close(&ad, ADFLAGS_HF);
     }
 
     return( AFP_OK );
@@ -2367,7 +2367,7 @@ int deletecurdir(struct vol *vol)
     struct dir  *fdir, *pdir;
     DIR *dp;
     struct adouble  ad;
-    u_int16_t       ashort;
+    uint16_t       ashort;
     int err;
 
     if ((pdir = dirlookup(vol, curdir->d_pdid)) == NULL) {
@@ -2376,12 +2376,12 @@ int deletecurdir(struct vol *vol)
 
     fdir = curdir;
 
-    ad_init(&ad, vol->v_adouble, vol->v_ad_options);
+    ad_init(&ad, vol);
     /* we never want to create a resource fork here, we are going to delete it */
     if ( ad_metadata( ".", ADFLAGS_DIR, &ad) == 0 ) {
 
         ad_getattr(&ad, &ashort);
-        ad_close_metadata(&ad);
+        ad_close(&ad, ADFLAGS_HF);
         if ((ashort & htons(ATTRBIT_NODELETE))) {
             return  AFPERR_OLOCK;
         }
@@ -2448,7 +2448,7 @@ int afp_mapid(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *r
     struct passwd   *pw;
     struct group    *gr;
     char        *name;
-    u_int32_t           id;
+    uint32_t           id;
     int         len, sfunc;
     int         utf8 = 0;
 
@@ -2542,7 +2542,7 @@ int afp_mapid(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *r
         len = strlen( name );
 
     if (utf8) {
-        u_int16_t tp = htons(len);
+        uint16_t tp = htons(len);
         memcpy(rbuf, &tp, sizeof(tp));
         rbuf += sizeof(tp);
         *rbuflen += 2;
@@ -2565,8 +2565,8 @@ int afp_mapname(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, siz
     struct passwd   *pw;
     struct group    *gr;
     int             len, sfunc;
-    u_int32_t       id;
-    u_int16_t       ulen;
+    uint32_t       id;
+    uint16_t       ulen;
 
     ibuf++;
     sfunc = (unsigned char) *ibuf++;
@@ -2653,8 +2653,8 @@ int afp_closedir(AFPObj *obj _U_, char *ibuf _U_, size_t ibuflen _U_, char *rbuf
 #if 0
     struct vol   *vol;
     struct dir   *dir;
-    u_int16_t    vid;
-    u_int32_t    did;
+    uint16_t    vid;
+    uint32_t    did;
 #endif /* 0 */
 
     *rbuflen = 0;
@@ -2689,8 +2689,8 @@ int afp_opendir(AFPObj *obj _U_, char *ibuf, size_t ibuflen  _U_, char *rbuf, si
     struct vol      *vol;
     struct dir      *parentdir;
     struct path     *path;
-    u_int32_t       did;
-    u_int16_t       vid;
+    uint32_t       did;
+    uint16_t       vid;
 
     *rbuflen = 0;
     ibuf += 2;
index e9c6a457f4344cb2865f0295d0d78885c4f096c7..533d30f9fe8ba39dc9b1c8034106131cbdfa14eb 100644 (file)
 #ifndef AFPD_DIRECTORY_H
 #define AFPD_DIRECTORY_H 1
 
-#include <sys/cdefs.h>
 #include <sys/types.h>
-/*#include <sys/stat.h>*/ /* including it here causes some confusion */
-#include <netatalk/endian.h>
+#include <arpa/inet.h>
 #include <dirent.h>
 
 /* sys/types.h usually snarfs in major/minor macros. if they don't
@@ -114,14 +112,14 @@ extern struct path *cname (struct vol *, struct dir *, char **);
 extern int         deletecurdir (struct vol *);
 extern mode_t      mtoumode (struct maccess *);
 extern void        utommode (struct stat *, struct maccess *);
-extern int         getdirparams (const struct vol *, u_int16_t, struct path *,
+extern int         getdirparams (const struct vol *, uint16_t, struct path *,
                                  struct dir *, char *, size_t *);
 
-extern int         setdirparams(struct vol *, struct path *, u_int16_t, char *);
+extern int         setdirparams(struct vol *, struct path *, uint16_t, char *);
 extern int         renamedir(const struct vol *, int, char *, char *, struct dir *,
                              struct dir *, char *);
 extern int         path_error(struct path *, int error);
-extern void        setdiroffcnt(struct dir *dir, struct stat *st,  u_int32_t count);
+extern void        setdiroffcnt(struct dir *dir, struct stat *st,  uint32_t count);
 extern int         dirreenumerate(struct dir *dir, struct stat *st);
 extern int         for_each_dirent(const struct vol *, char *, dir_loop , void *);
 extern int         check_access(char *name , int mode);
index fe5a66d993746610ce45747d347abc1e409036e4..4867640d8d63d9884cb148c2c7360722f80f2a6a 100644 (file)
@@ -40,7 +40,7 @@
  */
 struct savedir {
     u_short     sd_vid;
-    u_int32_t   sd_did;
+    uint32_t    sd_did;
     int                 sd_buflen;
     char        *sd_buf;
     char        *sd_last;
@@ -169,9 +169,9 @@ static int enumerate(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_,
     int                                did, ret, len, first = 1;
     size_t                     esz;
     char                        *data, *start;
-    u_int16_t                  vid, fbitmap, dbitmap, reqcnt, actcnt = 0;
-    u_int16_t                  temp16;
-    u_int32_t                  sindex, maxsz, sz = 0;
+    uint16_t                   vid, fbitmap, dbitmap, reqcnt, actcnt = 0;
+    uint16_t                   temp16;
+    uint32_t                   sindex, maxsz, sz = 0;
     struct path                 *o_path;
     struct path                 s_path;
     int                         header;
@@ -272,8 +272,8 @@ static int enumerate(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_,
     LOG(log_debug, logtype_afpd, "enumerate(\"%s/%s\", f/d:%04x/%04x, rc:%u, i:%u, max:%u)",
         getcwdpath(), o_path->u_name, fbitmap, dbitmap, reqcnt, sindex, maxsz);
 
-    data = rbuf + 3 * sizeof( u_int16_t );
-    sz = 3 * sizeof( u_int16_t );      /* fbitmap, dbitmap, reqcount */
+    data = rbuf + 3 * sizeof( uint16_t );
+    sz = 3 * sizeof( uint16_t );       /* fbitmap, dbitmap, reqcount */
 
     /*
      * Read the directory into a pre-malloced buffer, stored
index 40298b50737ccfa62000ac1469c2e4749a4ef511..c9747f2792e8f0dcfff226e2681eb0390fde10d5 100644 (file)
@@ -1,5 +1,4 @@
 /*
-  $Id: extattrs.c,v 1.29 2010-01-05 12:06:33 franklahm Exp $
   Copyright (c) 2009 Frank Lahm <franklahm@gmail.com>
 
   This program is free software; you can redistribute it and/or modify
@@ -139,7 +138,6 @@ int afp_listextattr(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf,
             return( AFPERR_NOOBJ );
         }
 
-        adp = of_ad(vol, s_path, &ad);
         uname = s_path->u_name;
         /*
           We have to check the FinderInfo for the file, because if they aren't all 0
@@ -151,10 +149,11 @@ int afp_listextattr(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf,
         if (S_ISDIR(st->st_mode))
             adflags = ADFLAGS_DIR;
 
-        if ( ad_metadata( uname, adflags, adp) < 0 ) {
+        adp = &ad;
+        ad_init(adp, vol);
+        if (ad_metadata(uname, adflags, adp) != 0 ) {
             switch (errno) {
             case ENOENT:
-                adp = NULL;
                 break;
             case EACCES:
                 LOG(log_error, logtype_afpd, "afp_listextattr(%s): %s: check resource fork permission?",
@@ -164,16 +163,9 @@ int afp_listextattr(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf,
                 LOG(log_error, logtype_afpd, "afp_listextattr(%s): error getting metadata: %s", uname, strerror(errno));
                 return AFPERR_MISC;
             }
-        }
-
-        if (adp) {
+        } else {
             FinderInfo = ad_entry(adp, ADEID_FINDERI);
 
-#ifdef DEBUG
-            LOG(log_maxdebug, logtype_afpd, "afp_listextattr(%s): FinderInfo:", uname);
-            hexdump( FinderInfo, 32);
-#endif
-
             if ((adflags & ADFLAGS_DIR)) {
                 /* set default view */
                 uint16 = htons(FINDERINFO_CLOSEDVIEW);
@@ -214,7 +206,7 @@ int afp_listextattr(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf,
         default:
             buf_valid = 1;
         }
-    }
+    } /* if ((maxreply == 0) || (buf_valid == 0)) */
 
     /* Start building reply packet */
     bitmap = htons(bitmap);
@@ -240,8 +232,9 @@ int afp_listextattr(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf,
 exit:
     if (ret != AFP_OK)
         buf_valid = 0;
+
     if (adp)
-        ad_close_metadata( adp);
+        ad_close(adp, ADFLAGS_HF);
 
     return ret;
 }
index 36798904ad0802b9d5d89ca25d17432f456be6af..342349a00347d5966cc9028377278ee2ac1120ce 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 
-/* STDC check */
-#if STDC_HEADERS
 #include <string.h>
-#else /* STDC_HEADERS */
-#ifndef HAVE_STRCHR
-#define strchr index
-#define strrchr index
-#endif /* HAVE_STRCHR */
-char *strchr (), *strrchr ();
-
-#ifndef HAVE_MEMCPY
-#define memcpy(d,s,n) bcopy ((s), (d), (n))
-#define memmove(d,s,n) bcopy ((s), (d), (n))
-#endif /* ! HAVE_MEMCPY */
-#endif /* STDC_HEADERS */
-
 #include <utime.h>
 #include <errno.h>
 #include <sys/param.h>
@@ -108,7 +93,7 @@ void *get_finderinfo(const struct vol *vol, const char *upath, struct adouble *a
         memcpy(data, ufinderi, ADEDLEN_FINDERI);
         chk_ext = 1;
         if (vol_inv_dots(vol) && *upath == '.') { /* make it invisible */
-            u_int16_t ashort;
+            uint16_t ashort;
             
             ashort = htons(FINDERINFO_INVISIBLE);
             memcpy((char *)data + FINDERINFO_FRFLAGOFF, &ashort, sizeof(ashort));
@@ -116,7 +101,7 @@ void *get_finderinfo(const struct vol *vol, const char *upath, struct adouble *a
     }
 
     if (islink){
-        u_int16_t linkflag;
+        uint16_t linkflag;
         memcpy(&linkflag, (char *)data + FINDERINFO_FRFLAGOFF, 2);
         linkflag |= htons(FINDERINFO_ISALIAS);
         memcpy((char *)data + FINDERINFO_FRFLAGOFF, &linkflag, 2);
@@ -135,9 +120,9 @@ void *get_finderinfo(const struct vol *vol, const char *upath, struct adouble *a
 
 /* ---------------------
 */
-char *set_name(const struct vol *vol, char *data, cnid_t pid, char *name, cnid_t id, u_int32_t utf8) 
+char *set_name(const struct vol *vol, char *data, cnid_t pid, char *name, cnid_t id, uint32_t utf8) 
 {
-    u_int32_t   aint;
+    uint32_t   aint;
     char        *tp = NULL;
     char        *src = name;
     aint = strlen( name );
@@ -164,7 +149,7 @@ char *set_name(const struct vol *vol, char *data, cnid_t pid, char *name, cnid_t
         *data++ = aint;
     }
     else {
-        u_int16_t temp;
+        uint16_t temp;
 
         if (aint > UTF8FILELEN_EARLY)  /* FIXME safeguard, anyway if no ascii char it's game over*/
            aint = UTF8FILELEN_EARLY;
@@ -224,8 +209,8 @@ uint32_t get_id(struct vol *vol,
                 const int len) 
 {
     static int first = 1;       /* mark if this func is called the first time */
-    u_int32_t adcnid;
-    u_int32_t dbcnid = CNID_INVALID;
+    uint32_t adcnid;
+    uint32_t dbcnid = CNID_INVALID;
 
 restart:
     if (vol->v_cdb != NULL) {
@@ -302,18 +287,18 @@ exit:
              
 /* -------------------------- */
 int getmetadata(struct vol *vol,
-                 u_int16_t bitmap,
+                 uint16_t bitmap,
                  struct path *path, struct dir *dir, 
                  char *buf, size_t *buflen, struct adouble *adp)
 {
     char               *data, *l_nameoff = NULL, *upath;
     char                *utf_nameoff = NULL;
     int                        bit = 0;
-    u_int32_t          aint;
+    uint32_t           aint;
     cnid_t              id = 0;
-    u_int16_t          ashort;
+    uint16_t           ashort;
     u_char              achar, fdType[4];
-    u_int32_t           utf8 = 0;
+    uint32_t           utf8 = 0;
     struct stat         *st;
     struct maccess     ma;
 
@@ -409,8 +394,8 @@ int getmetadata(struct vol *vol,
             break;
 
         case FILPBIT_PDID :
-            memcpy(data, &dir->d_did, sizeof( u_int32_t ));
-            data += sizeof( u_int32_t );
+            memcpy(data, &dir->d_did, sizeof( uint32_t ));
+            data += sizeof( uint32_t );
             LOG(log_debug, logtype_afpd, "metadata('%s'):     Parent DID: %u",
                 path->u_name, ntohl(dir->d_did));
             break;
@@ -448,12 +433,12 @@ int getmetadata(struct vol *vol,
 
         case FILPBIT_LNAME :
             l_nameoff = data;
-            data += sizeof( u_int16_t );
+            data += sizeof( uint16_t );
             break;
 
         case FILPBIT_SNAME :
-            memset(data, 0, sizeof(u_int16_t));
-            data += sizeof( u_int16_t );
+            memset(data, 0, sizeof(uint16_t));
+            data += sizeof( uint16_t );
             break;
 
         case FILPBIT_FNUM :
@@ -495,7 +480,7 @@ int getmetadata(struct vol *vol,
             if (afp_version >= 30) { /* UTF8 name */
                 utf8 = kTextEncodingUTF8;
                 utf_nameoff = data;
-                data += sizeof( u_int16_t );
+                data += sizeof( uint16_t );
                 aint = 0;
                 memcpy(data, &aint, sizeof( aint ));
                 data += sizeof( aint );
@@ -617,7 +602,7 @@ int getmetadata(struct vol *vol,
                 
 /* ----------------------- */
 int getfilparams(struct vol *vol,
-                 u_int16_t bitmap,
+                 uint16_t bitmap,
                  struct path *path, struct dir *dir, 
                  char *buf, size_t *buflen )
 {
@@ -632,12 +617,12 @@ int getfilparams(struct vol *vol,
 
     if (opened) {
         char *upath;
-        int  flags = (bitmap & (1 << FILPBIT_ATTR))?ADFLAGS_OPENFORKS:0;
+        int  flags = (bitmap & (1 << FILPBIT_ATTR)) ? ADFLAGS_CHECK_OF : 0;
 
         adp = of_ad(vol, path, &ad);
         upath = path->u_name;
 
-        if ( ad_metadata( upath, flags|ADFLAGS_CREATE, adp) < 0 ) {
+        if ( ad_metadata( upath, flags, adp) < 0 ) {
             switch (errno) {
             case EACCES:
                 LOG(log_error, logtype_afpd, "getfilparams(%s): %s: check resource fork permission?",
@@ -654,9 +639,7 @@ int getfilparams(struct vol *vol,
         }
     }
     rc = getmetadata(vol, bitmap, path, dir, buf, buflen, adp);
-    if ( adp ) {
-        ad_close_metadata( adp);
-    }
+    ad_close(adp, ADFLAGS_HF);
 
     return( rc );
 }
@@ -664,13 +647,13 @@ int getfilparams(struct vol *vol,
 /* ----------------------------- */
 int afp_createfile(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen)
 {
-    struct adouble     ad, *adp;
+    struct adouble     ad;
     struct vol         *vol;
     struct dir         *dir;
     struct ofork        *of = NULL;
     char               *path, *upath;
     int                        creatf, did, openf, retvalue = AFP_OK;
-    u_int16_t          vid;
+    uint16_t           vid;
     struct path                *s_path;
     
     *rbuflen = 0;
@@ -680,9 +663,8 @@ int afp_createfile(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_,
     memcpy(&vid, ibuf, sizeof( vid ));
     ibuf += sizeof( vid );
 
-    if (NULL == ( vol = getvolbyvid( vid )) ) {
+    if (NULL == ( vol = getvolbyvid( vid )) )
         return( AFPERR_PARAM );
-    }
 
     if (vol->v_flags & AFPVOL_RO)
         return AFPERR_VLOCK;
@@ -690,44 +672,34 @@ int afp_createfile(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_,
     memcpy(&did, ibuf, sizeof( did));
     ibuf += sizeof( did );
 
-    if (NULL == ( dir = dirlookup( vol, did )) ) {
+    if (NULL == ( dir = dirlookup( vol, did )) )
         return afp_errno;
-    }
 
-    if (NULL == ( s_path = cname( vol, dir, &ibuf )) ) {
+    if (NULL == ( s_path = cname( vol, dir, &ibuf )) )
         return get_afp_errno(AFPERR_PARAM);
-    }
 
-    if ( *s_path->m_name == '\0' ) {
+    if ( *s_path->m_name == '\0' )
         return( AFPERR_BADTYPE );
-    }
 
     upath = s_path->u_name;
+    ad_init(&ad, vol);
     
     /* if upath is deleted we already in trouble anyway */
     if ((of = of_findname(s_path))) {
-        adp = of->of_ad;
-    } else {
-        ad_init(&ad, vol->v_adouble, vol->v_ad_options);
-        adp = &ad;
-    }
-    if ( creatf) {
-        /* on a hard create, fail if file exists and is open */
-        if (of)
+        if (creatf)
             return AFPERR_BUSY;
-        openf = O_RDWR|O_CREAT|O_TRUNC;
-    } else {
-       /* on a soft create, if the file is open then ad_open won't fail
-          because open syscall is not called
-       */
-       if (of) {
-               return AFPERR_EXIST;
-       }
-        openf = O_RDWR|O_CREAT|O_EXCL;
+        else
+            return AFPERR_EXIST;
     }
 
-    if ( ad_open( upath, ADFLAGS_DF|ADFLAGS_HF|ADFLAGS_NOHF|ADFLAGS_CREATE,
-                  openf, 0666, adp) < 0 ) {
+    if (creatf)
+        openf = ADFLAGS_RDWR | ADFLAGS_CREATE | ADFLAGS_TRUNC;
+    else
+       /* on a soft create, if the file is open then ad_open won't fail
+          because open syscall is not called */
+        openf = ADFLAGS_RDWR | ADFLAGS_CREATE | ADFLAGS_EXCL;
+
+    if (ad_open(&ad, upath, ADFLAGS_DF | ADFLAGS_HF | ADFLAGS_NOHF | openf, 0666) < 0) {
         switch ( errno ) {
         case EROFS:
             return AFPERR_VLOCK;
@@ -744,48 +716,40 @@ int afp_createfile(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_,
             return( AFPERR_PARAM );
         }
     }
-    if ( ad_reso_fileno( adp ) == -1 ) { /* Hard META / HF */
+    if ( ad_meta_fileno( &ad ) == -1 ) { /* Hard META / HF */
          /* on noadouble volumes, just creating the data fork is ok */
          if (vol_noadouble(vol)) {
-             ad_close( adp, ADFLAGS_DF );
+             ad_close( &ad, ADFLAGS_DF );
              goto createfile_done;
          }
          /* FIXME with hard create on an existing file, we already
           * corrupted the data file.
           */
          netatalk_unlink( upath );
-         ad_close( adp, ADFLAGS_DF );
+         ad_close( &ad, ADFLAGS_DF );
          return AFPERR_ACCESS;
     }
 
     path = s_path->m_name;
-    ad_setname(adp, path);
+    ad_setname(&ad, path);
 
     struct stat st;
     if (lstat(upath, &st) != 0) {
         LOG(log_error, logtype_afpd, "afp_createfile(\"%s\"): stat: %s",
             upath, strerror(errno));
-        ad_close( adp, ADFLAGS_DF|ADFLAGS_HF);
+        ad_close(&ad, ADFLAGS_DF|ADFLAGS_HF);
         return AFPERR_MISC;
     }
 
-    (void)get_id(vol, adp, &st, dir->d_did, upath, strlen(upath));
-
-    ad_flush( adp);
+    (void)get_id(vol, &ad, &st, dir->d_did, upath, strlen(upath));
 
+    ad_flush(&ad);
+    ad_close(&ad, ADFLAGS_DF|ADFLAGS_HF );
     fce_register_new_file(s_path);
 
-    ad_close( adp, ADFLAGS_DF|ADFLAGS_HF );
-
 createfile_done:
     curdir->d_offcnt++;
 
-#ifdef DROPKLUDGE
-    if (vol->v_flags & AFPVOL_DROPBOX) {
-        retvalue = matchfile2dirperms(upath, vol, did);
-    }
-#endif /* DROPKLUDGE */
-
     setvoltime(obj, vol );
 
     return (retvalue);
@@ -797,7 +761,7 @@ int afp_setfilparams(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_
     struct dir *dir;
     struct path *s_path;
     int                did, rc;
-    u_int16_t  vid, bitmap;
+    uint16_t   vid, bitmap;
 
     *rbuflen = 0;
     ibuf += 2;
@@ -851,17 +815,17 @@ int afp_setfilparams(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_
 extern struct path Cur_Path;
 
 int setfilparams(struct vol *vol,
-                 struct path *path, u_int16_t f_bitmap, char *buf )
+                 struct path *path, uint16_t f_bitmap, char *buf )
 {
     struct adouble     ad, *adp;
     struct extmap      *em;
     int                        bit, isad = 1, err = AFP_OK;
     char                *upath;
     u_char              achar, *fdType, xyy[4]; /* uninitialized, OK 310105 */
-    u_int16_t          ashort, bshort, oshort;
-    u_int32_t          aint;
-    u_int32_t          upriv;
-    u_int16_t           upriv_bit = 0;
+    uint16_t           ashort, bshort, oshort;
+    uint32_t           aint;
+    uint32_t           upriv;
+    uint16_t           upriv_bit = 0;
     
     struct utimbuf     ut;
 
@@ -871,8 +835,8 @@ int setfilparams(struct vol *vol,
     struct timeval      tv;
     uid_t              f_uid;
     gid_t              f_gid;
-    u_int16_t           bitmap = f_bitmap;
-    u_int32_t           cdate,bdate;
+    uint16_t           bitmap = f_bitmap;
+    uint32_t           cdate,bdate;
     u_char              finder_buf[32];
 
 #ifdef DEBUG
@@ -1000,7 +964,7 @@ int setfilparams(struct vol *vol,
 
     /* second try with adouble open 
     */
-    if ( ad_open_metadata( upath, 0, O_CREAT, adp) < 0) {
+    if (ad_open(adp, upath, ADFLAGS_HF | ADFLAGS_RDWR | ADFLAGS_CREATE, 0666) < 0) {
         LOG(log_debug, logtype_afpd, "setfilparams: ad_open_metadata error");
         /*
          * For some things, we don't need an adouble header:
@@ -1013,7 +977,7 @@ int setfilparams(struct vol *vol,
         }
         LOG(log_debug, logtype_afpd, "setfilparams: no adouble perms, but only FILPBIT_MDATE and/or FILPBIT_UNIXPR");
         isad = 0;
-    } else if ((ad_get_HF_flags( adp ) & O_CREAT) ) {
+    } else if ((ad_get_MD_flags( adp ) & O_CREAT) ) {
         ad_setname(adp, path->m_name);
     }
     
@@ -1092,9 +1056,8 @@ setfilparam_done:
     }
 
     if (isad) {
-        ad_flush( adp);
-        ad_close_metadata( adp);
-
+        ad_flush(adp);
+        ad_close(adp, ADFLAGS_HF);
     }
 
     if (change_parent_mdate && gettimeofday(&tv, NULL) == 0) {
@@ -1180,9 +1143,8 @@ int renamefile(const struct vol *vol, int sdir_fd, char *src, char *dst, char *n
         }
     }
 
-    /* don't care if we can't open the newly renamed ressource fork
-     */
-    if (!ad_open( dst, ADFLAGS_HF, O_RDWR, 0666, adp)) {
+    /* don't care if we can't open the newly renamed ressource fork */
+    if (ad_open(adp, dst, ADFLAGS_HF | ADFLAGS_RDWR) == 0) {
         ad_setname(adp, newname);
         ad_flush( adp );
         ad_close( adp, ADFLAGS_HF );
@@ -1209,8 +1171,8 @@ int copy_path_name(const struct vol *vol, char *newname, char *ibuf)
 {
 char        type = *ibuf;
 size_t      plen = 0;
-u_int16_t   len16;
-u_int32_t   hint;
+uint16_t   len16;
+uint32_t   hint;
 
     if ( type != 2 && !(afp_version >= 30 && type == 3) ) {
         return -1;
@@ -1268,9 +1230,9 @@ int afp_copyfile(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, si
     struct dir *dir;
     char       *newname, *p, *upath;
     struct path *s_path;
-    u_int32_t  sdid, ddid;
+    uint32_t   sdid, ddid;
     int         err, retvalue = AFP_OK;
-    u_int16_t  svid, dvid;
+    uint16_t   svid, dvid;
 
     struct adouble ad, *adp;
     int denyreadset;
@@ -1310,11 +1272,11 @@ int afp_copyfile(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, si
 
     adp = of_ad(s_vol, s_path, &ad);
 
-    if (ad_open(s_path->u_name , ADFLAGS_DF |ADFLAGS_HF | ADFLAGS_NOHF, O_RDONLY, 0, adp) < 0) {
+    if (ad_open(adp, s_path->u_name, ADFLAGS_DF | ADFLAGS_HF | ADFLAGS_NOHF | ADFLAGS_RDONLY) < 0) {
         return AFPERR_DENYCONF;
     }
-    denyreadset = (getforkmode(adp, ADEID_DFORK, AD_FILELOCK_DENY_RD) != 0 || 
-                  getforkmode(adp, ADEID_RFORK, AD_FILELOCK_DENY_RD) != 0 );
+    denyreadset = (ad_testlock(adp, ADEID_DFORK, AD_FILELOCK_DENY_RD) != 0 || 
+                  ad_testlock(adp, ADEID_RFORK, AD_FILELOCK_DENY_RD) != 0 );
 
     if (denyreadset) {
         retvalue = AFPERR_DENYCONF;
@@ -1330,9 +1292,6 @@ int afp_copyfile(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, si
         goto copy_exit;
     }
 
-#ifdef FORCE_UIDGID
-    /* FIXME svid != dvid && dvid's user can't read svid */
-#endif
     if (NULL == ( d_vol = getvolbyvid( dvid )) ) {
         retvalue = AFPERR_PARAM;
         goto copy_exit;
@@ -1377,12 +1336,6 @@ int afp_copyfile(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, si
     }
     curdir->d_offcnt++;
 
-#ifdef DROPKLUDGE
-    if (vol->v_flags & AFPVOL_DROPBOX) {
-        retvalue=matchfile2dirperms(upath, vol, ddid); /* FIXME sdir or ddid */
-    }
-#endif /* DROPKLUDGE */
-
     setvoltime(obj, d_vol );
 
 copy_exit:
@@ -1512,7 +1465,7 @@ int copyfile(const struct vol *s_vol,
         sfd, src, dst, newname);
 
     if (adp == NULL) {
-        ad_init(&ads, s_vol->v_adouble, s_vol->v_ad_options); 
+        ad_init(&ads, s_vol);
         adp = &ads;
     }
 
@@ -1521,7 +1474,7 @@ int copyfile(const struct vol *s_vol,
         adflags |= ADFLAGS_HF;
     }
 
-    if (ad_openat(sfd, src, adflags | ADFLAGS_NOHF, O_RDONLY, 0, adp) < 0) {
+    if (ad_openat(adp, sfd, src, adflags | ADFLAGS_NOHF | ADFLAGS_RDONLY) < 0) {
         ret_err = errno;
         goto done;
     }
@@ -1538,8 +1491,8 @@ int copyfile(const struct vol *s_vol,
       st.st_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
     }
 
-    ad_init(&add, d_vol->v_adouble, d_vol->v_ad_options);
-    if (ad_open(dst , adflags, O_RDWR|O_CREAT|O_EXCL, st.st_mode, &add) < 0) {
+    ad_init(&add, d_vol);
+    if (ad_open(&add, dst, adflags | ADFLAGS_RDWR | ADFLAGS_CREATE | ADFLAGS_EXCL, st.st_mode) < 0) {
         ret_err = errno;
         ad_close( adp, adflags );
         if (EEXIST != ret_err) {
@@ -1622,7 +1575,7 @@ done:
 
 static int check_attrib(struct adouble *adp)
 {
-u_int16_t   bshort = 0;
+uint16_t   bshort = 0;
 
        ad_getattr(adp, &bshort);
     /*
@@ -1648,16 +1601,16 @@ int deletefile(const struct vol *vol, int dirfd, char *file, int checkAttrib)
 
     LOG(log_debug, logtype_afpd, "deletefile('%s')", file);
 
-    ad_init(&ad, vol->v_adouble, vol->v_ad_options);
+    ad_init(&ad, vol);
     if (checkAttrib) {
         /* was EACCESS error try to get only metadata */
         /* we never want to create a resource fork here, we are going to delete it 
          * moreover sometimes deletefile is called with a no existent file and 
          * ad_open would create a 0 byte resource fork
         */
-        if ( ad_metadataat(dirfd, file, ADFLAGS_OPENFORKS, &ad) == 0 ) {
+        if ( ad_metadataat(dirfd, file, ADFLAGS_CHECK_OF, &ad) == 0 ) {
             if ((err = check_attrib(&ad))) {
-               ad_close_metadata(&ad);
+                ad_close(&ad, ADFLAGS_HF);
                return err;
             }
             meta = 1;
@@ -1666,7 +1619,7 @@ int deletefile(const struct vol *vol, int dirfd, char *file, int checkAttrib)
  
     /* try to open both forks at once */
     adflags = ADFLAGS_DF;
-    if ( ad_openat(dirfd, file, adflags |ADFLAGS_HF|ADFLAGS_NOHF, O_RDONLY, 0, &ad ) < 0 ) {
+    if (ad_openat(&ad, dirfd, file, adflags | ADFLAGS_HF | ADFLAGS_NOHF | ADFLAGS_RDONLY) < 0 ) {
         switch (errno) {
         case ENOENT:
             err = AFPERR_NOOBJ;
@@ -1713,7 +1666,7 @@ int deletefile(const struct vol *vol, int dirfd, char *file, int checkAttrib)
 
 end:
     if (meta)
-        ad_close_metadata(&ad);
+        ad_close(&ad, ADFLAGS_HF);
 
     if (adp)
         ad_close( &ad, adflags );  /* ad_close removes locks if any */
@@ -1809,32 +1762,12 @@ static int reenumerate_loop(struct dirent *de, char *mname _U_, void *data)
     cnid_t        did  = param->did;
     cnid_t       aint;
     
-    if ( lstat(de->d_name, &path.st)<0 )
+    if ( lstat(de->d_name, &path.st) < 0 )
         return 0;
     
     /* update or add to cnid */
     aint = cnid_add(vol->v_cdb, &path.st, did, de->d_name, strlen(de->d_name), 0); /* ignore errors */
 
-#if AD_VERSION > AD_VERSION1
-    if (aint != CNID_INVALID && !S_ISDIR(path.st.st_mode)) {
-        struct adouble  ad, *adp;
-
-        path.st_errno = 0;
-        path.st_valid = 1;
-        path.u_name = de->d_name;
-            
-        adp = of_ad(vol, &path, &ad);
-            
-        if ( ad_open_metadata( de->d_name, 0, 0, adp ) < 0 ) {
-            return 0;
-        }
-        if (ad_setid(adp, path.st.st_dev, path.st.st_ino, aint, did, vol->v_stamp)) {
-            ad_flush(adp);
-        }
-        ad_close_metadata(adp);
-    }
-#endif /* AD_VERSION > AD_VERSION1 */
-
     return 0;
 }
 
@@ -1884,7 +1817,7 @@ int afp_resolveid(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, s
     int                 err, retry=0;
     size_t             buflen;
     cnid_t             id, cnid;
-    u_int16_t          vid, bitmap;
+    uint16_t           vid, bitmap;
 
     static char buffer[12 + MAXPATHLEN + 1];
     int len = 12 + MAXPATHLEN + 1;
@@ -2096,7 +2029,7 @@ static struct adouble *find_adouble(struct path *path, struct ofork **of, struct
         adp = (*of)->of_ad;
     }
     else {
-        ret = ad_open( path->u_name, ADFLAGS_HF, O_RDONLY, 0, adp);
+        ret = ad_open(adp, path->u_name, ADFLAGS_HF | ADFLAGS_RDWR);
         /* META and HF */
         if ( !ret && ad_reso_fileno(adp) != -1 && !(adp->ad_resource_fork.adf_flags & ( O_RDWR | O_WRONLY))) {
             /* from AFP spec.
@@ -2130,8 +2063,8 @@ int afp_exchangefiles(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U
     int                 crossdev;
     
     int                 slen, dlen;
-    u_int32_t          sid, did;
-    u_int16_t          vid;
+    uint32_t           sid, did;
+    uint16_t           vid;
 
     uid_t              uid;
     gid_t              gid;
@@ -2181,7 +2114,7 @@ int afp_exchangefiles(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U
         return AFPERR_PARAM ;
     }
     
-    ad_init(&ads, vol->v_adouble, vol->v_ad_options);
+    ad_init(&ads, vol);
     if (!(adsp = find_adouble( path, &s_of, &ads))) {
         return afp_errno;
     }
@@ -2214,7 +2147,7 @@ int afp_exchangefiles(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U
         goto err_exchangefile;
     }
 
-    ad_init(&add, vol->v_adouble, vol->v_ad_options);
+    ad_init(&add, vol);
     if (!(addp = find_adouble( path, &d_of, &add))) {
         err = afp_errno;
         goto err_exchangefile;
index 077cd1203b214f98eebccb634fc8b83c82593dcc..76485a3f87f23e2abe89e7979c427f4f6f6d99a7 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: file.h,v 1.26 2010/03/12 15:16:49 franklahm Exp $
- *
  * Copyright (c) 1990,1991 Regents of The University of Michigan.
  * All Rights Reserved.
  *
@@ -28,8 +26,7 @@
 
 /*#include <sys/stat.h>*/ /* including it here causes some confusion */
 #include <sys/param.h>
-#include <sys/cdefs.h>
-#include <netatalk/endian.h>
+#include <arpa/inet.h>
 #include <atalk/adouble.h>
 #include <atalk/globals.h>
 
@@ -106,20 +103,20 @@ typedef enum {
   kTextEncodingMacKeyboardGlyphs = 41,
 } kTextEncoding_t;
 
-extern char *set_name   (const struct vol *, char *, cnid_t, char *, cnid_t, u_int32_t );
+extern char *set_name   (const struct vol *, char *, cnid_t, char *, cnid_t, uint32_t );
 
 extern struct extmap   *getextmap (const char *);
 extern struct extmap   *getdefextmap (void);
 
-extern int getfilparams (struct vol *, u_int16_t, struct path *,
-                                 struct dir *, char *buf, size_t *);
+extern int getfilparams (struct vol *, uint16_t, struct path *,
+                         struct dir *, char *buf, size_t *);
 
-extern int setfilparams (struct vol *, struct path *, u_int16_t, char *);
+extern int setfilparams (struct vol *, struct path *, uint16_t, char *);
 extern int renamefile   (const struct vol *, int, char *, char *, char *, struct adouble *);
 extern int copyfile     (const struct vol *, const struct vol *, int, char *, char *, char *, struct adouble *);
 extern int deletefile   (const struct vol *, int, char *, int);
 
-extern int getmetadata  (struct vol *vol, u_int16_t bitmap, struct path *path, 
+extern int getmetadata  (struct vol *vol, uint16_t bitmap, struct path *path, 
                          struct dir *dir, char *buf, size_t *buflen, struct adouble *adp);
 
 extern void *get_finderinfo (const struct vol *, const char *, struct adouble *, void *, int);
index 6fe3c855b2d32d007432a9623ffa2cb2f0b6f8f8..67eb3201dbc65f022b91dca8cf2e9e2a98ceb23f 100644 (file)
@@ -9,24 +9,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-/* STDC check */
-#if STDC_HEADERS
 #include <string.h>
-#else /* STDC_HEADERS */
-#ifndef HAVE_STRCHR
-#define strchr index
-#define strrchr index
-#endif /* HAVE_STRCHR */
-char *strchr (), *strrchr ();
-#ifndef HAVE_MEMCPY
-#define memcpy(d,s,n) bcopy ((s), (d), (n))
-#define memmove(d,s,n) bcopy ((s), (d), (n))
-#endif /* ! HAVE_MEMCPY */
-#endif /* STDC_HEADERS */
-
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif
 #include <errno.h>
 #include <sys/param.h>
 
@@ -52,96 +35,15 @@ char *strchr (), *strrchr ();
 #include "filedir.h"
 #include "unix.h"
 
-#ifdef DROPKLUDGE
-int matchfile2dirperms(
-/* Since it's kinda' big; I decided against an
-   inline function */
-    char    *upath,
-    struct vol  *vol,
-    int     did)
-/* The below code changes the way file ownership is determined in the name of
-   fixing dropboxes.  It has known security problem.  See the netatalk FAQ for
-   more information */
-{
-    struct stat st, sb;
-    struct dir  *dir;
-    char    *adpath;
-    uid_t       uid;
-    int         ret = AFP_OK;
-#ifdef DEBUG
-    LOG(log_debug9, logtype_afpd, "begin matchfile2dirperms:");
-#endif
-
-    if (stat(upath, &st ) < 0) {
-        LOG(log_error, logtype_afpd, "Could not stat %s: %s", upath, strerror(errno));
-        return AFPERR_NOOBJ ;
-    }
-
-    adpath = vol->vfs->ad_path( upath, ADFLAGS_HF );
-    /* FIXME dirsearch doesn't move cwd to did ! */
-    if (( dir = dirlookup( vol, did )) == NULL ) {
-        LOG(log_error, logtype_afpd, "matchfile2dirperms: Unable to get directory info.");
-        ret = AFPERR_NOOBJ;
-    }
-    else if (stat(".", &sb) < 0) {
-        LOG(log_error, logtype_afpd,
-            "matchfile2dirperms: Error checking directory \"%s\": %s",
-            dir->d_m_name, strerror(errno));
-        ret = AFPERR_NOOBJ;
-    }
-    else {
-        uid=geteuid();
-        if ( uid != sb.st_uid )
-        {
-            seteuid(0);
-            if (lchown(upath, sb.st_uid, sb.st_gid) < 0)
-            {
-                LOG(log_error, logtype_afpd,
-                    "matchfile2dirperms(%s): Error changing owner/gid: %s",
-                    upath, strerror(errno));
-                ret = AFPERR_ACCESS;
-            }
-            else if ((!S_ISLNK(st->st_mode)) && (chmod_acl(upath,(st.st_mode&~default_options.umask)| S_IRGRP| S_IROTH) < 0))
-            {
-                LOG(log_error, logtype_afpd,
-                    "matchfile2dirperms(%s): Error adding file read permissions: %s",
-                    upath, strerror(errno));
-                ret = AFPERR_ACCESS;
-            }
-            else if (lchown(adpath, sb.st_uid, sb.st_gid) < 0)
-            {
-                LOG(log_error, logtype_afpd,
-                    "matchfile2dirperms(%s): Error changing AppleDouble owner/gid: %s",
-                    adpath, strerror(errno));
-                ret = AFPERR_ACCESS;
-            }
-            else if (chmod_acl(adpath, (st.st_mode&~default_options.umask)| S_IRGRP| S_IROTH) < 0)
-            {
-                LOG(log_error, logtype_afpd,
-                    "matchfile2dirperms(%s):  Error adding AD file read permissions: %s",
-                    adpath, strerror(errno));
-                ret = AFPERR_ACCESS;
-            }
-            seteuid(uid);
-        }
-    } /* end else if stat success */
-
-#ifdef DEBUG
-    LOG(log_debug9, logtype_afpd, "end matchfile2dirperms:");
-#endif
-    return ret;
-}
-#endif
-
 int afp_getfildirparams(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbuflen)
 {
     struct stat     *st;
     struct vol      *vol;
     struct dir      *dir;
-    u_int32_t           did;
+    uint32_t           did;
     int         ret;
     size_t      buflen;
-    u_int16_t       fbitmap, dbitmap, vid;
+    uint16_t       fbitmap, dbitmap, vid;
     struct path         *s_path;
 
     *rbuflen = 0;
@@ -202,21 +104,21 @@ int afp_getfildirparams(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *r
                 return AFPERR_NOOBJ;
 
             ret = getdirparams(vol, dbitmap, s_path, dir,
-                               rbuf + 3 * sizeof( u_int16_t ), &buflen );
+                               rbuf + 3 * sizeof( uint16_t ), &buflen );
             if (ret != AFP_OK )
                 return( ret );
         }
         /* this is a directory */
-        *(rbuf + 2 * sizeof( u_int16_t )) = (char) FILDIRBIT_ISDIR;
+        *(rbuf + 2 * sizeof( uint16_t )) = (char) FILDIRBIT_ISDIR;
     } else {
         if (fbitmap && AFP_OK != (ret = getfilparams(vol, fbitmap, s_path, curdir,
-                                                     rbuf + 3 * sizeof( u_int16_t ), &buflen )) ) {
+                                                     rbuf + 3 * sizeof( uint16_t ), &buflen )) ) {
             return( ret );
         }
         /* this is a file */
-        *(rbuf + 2 * sizeof( u_int16_t )) = FILDIRBIT_ISFILE;
+        *(rbuf + 2 * sizeof( uint16_t )) = FILDIRBIT_ISFILE;
     }
-    *rbuflen = buflen + 3 * sizeof( u_int16_t );
+    *rbuflen = buflen + 3 * sizeof( uint16_t );
     fbitmap = htons( fbitmap );
     memcpy( rbuf, &fbitmap, sizeof( fbitmap ));
     rbuf += sizeof( fbitmap );
@@ -234,7 +136,7 @@ int afp_setfildirparams(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf
     struct vol  *vol;
     struct dir  *dir;
     struct path *path;
-    u_int16_t   vid, bitmap;
+    uint16_t   vid, bitmap;
     int     did, rc;
 
     *rbuflen = 0;
@@ -345,7 +247,7 @@ static int moveandrename(const struct vol *vol,
         "moveandrename: [\"%s\"/\"%s\"] -> \"%s\"",
         cfrombstr(sdir->d_u_name), oldname, newname);
 
-    ad_init(&ad, vol->v_adouble, vol->v_ad_options);
+    ad_init(&ad, vol);
     adp = &ad;
     adflags = 0;
 
@@ -399,10 +301,11 @@ static int moveandrename(const struct vol *vol,
         }
     }
     if (!ad_metadata(oldunixname, adflags, adp)) {
-        u_int16_t bshort;
+        uint16_t bshort;
 
         ad_getattr(adp, &bshort);
-        ad_close_metadata( adp);
+        
+        ad_close(adp, ADFLAGS_HF);
         if ((bshort & htons(ATTRBIT_NORENAME))) {
             rc = AFPERR_OLOCK;
             goto exit;
@@ -477,7 +380,7 @@ static int moveandrename(const struct vol *vol,
         if (!ad_metadata(upath, adflags, adp)) {
             ad_setid(adp, st->st_dev, st->st_ino, id, curdir->d_did, vol->v_stamp);
             ad_flush(adp);
-            ad_close_metadata(adp);
+            ad_close(adp, ADFLAGS_HF);
         }
 
         /* fix up the catalog entry */
@@ -499,9 +402,9 @@ int afp_rename(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size
     struct dir  *sdir;
     char        *oldname, *newname;
     struct path *path;
-    u_int32_t   did;
+    uint32_t   did;
     int         plen;
-    u_int16_t   vid;
+    uint16_t   vid;
     int         isdir = 0;
     int         rc;
 
@@ -575,7 +478,7 @@ int afp_delete(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size
     struct path         *s_path;
     char        *upath;
     int         did, rc;
-    u_int16_t       vid;
+    uint16_t       vid;
 
     *rbuflen = 0;
     ibuf += 2;
@@ -689,11 +592,8 @@ int afp_moveandrename(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U
     int     did;
     int     pdid;
     int         plen;
-    u_int16_t   vid;
+    uint16_t   vid;
     int         rc;
-#ifdef DROPKLUDGE
-    int     retvalue;
-#endif /* DROPKLUDGE */
     int     sdir_fd = -1;
 
 
@@ -780,25 +680,13 @@ int afp_moveandrename(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U
             rc = AFPERR_PARAM;
             goto exit;
         }
-        curdir->d_offcnt++;
-        sdir->d_offcnt--;
-#ifdef DROPKLUDGE
-        if (vol->v_flags & AFPVOL_DROPBOX) {
-            /* FIXME did is not always the source id */
-            if ((retvalue=matchfile2dirperms (upath, vol, did)) != AFP_OK) {
-                rc = retvalue;
-                goto exit;
-            }
+        /* if unix priv don't try to match perm with dest folder */
+        if (!isdir && !vol_unix_priv(vol)) {
+            int  admode = ad_mode("", 0777) | vol->v_fperm;
+
+            setfilmode(upath, admode, NULL, vol->v_umask);
+            vol->vfs->vfs_setfilmode(vol, upath, admode, NULL);
         }
-        else
-#endif /* DROPKLUDGE */
-            /* if unix priv don't try to match perm with dest folder */
-            if (!isdir && !vol_unix_priv(vol)) {
-                int  admode = ad_mode("", 0777) | vol->v_fperm;
-
-                setfilmode(upath, admode, NULL, vol->v_umask);
-                vol->vfs->vfs_setfilmode(vol, upath, admode, NULL);
-            }
         setvoltime(obj, vol );
     }
 
index 5daf73f3c975bf0fb000f00a56d77c621b1a62a2..02c9ac15b5382ed99c5ee4cf7a84166d4e85cfda 100644 (file)
@@ -1,11 +1,6 @@
-/*
- * $Id: filedir.h,v 1.11 2009-10-15 10:43:13 didg Exp $
- */
-
 #ifndef AFPD_FILEDIR_H
 #define AFPD_FILEDIR_H 1
 
-#include <sys/cdefs.h>
 #include <sys/stat.h>
 #include <atalk/globals.h>
 #include "volume.h"
index 41749b944308a6fdbeab9a4788d98e613ffd9c4b..8092fd398d8b423723f785402748258ec98b2f3b 100644 (file)
@@ -1,7 +1,7 @@
 /*
- * $Id: fork.c,v 1.73 2010-03-30 12:55:26 franklahm Exp $
- *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
+ * Copyright (c) 2010      Frank Lahm
+ *
  * All Rights Reserved.  See COPYRIGHT.
  */
 
 #endif /* HAVE_CONFIG_H */
 
 #include <stdio.h>
-
 #include <string.h>
 #include <errno.h>
-
-#include <atalk/adouble.h>
-#include <atalk/logger.h>
-
 #include <sys/param.h>
 #include <sys/socket.h>
-
-#include <netatalk/at.h>
+#include <inttypes.h>
 
 #include <atalk/dsi.h>
-#include <atalk/atp.h>
-#include <atalk/asp.h>
 #include <atalk/afp.h>
+#include <atalk/adouble.h>
+#include <atalk/logger.h>
 #include <atalk/util.h>
 #include <atalk/cnid.h>
+#include <atalk/bstradd.h>
 #include <atalk/globals.h>
 
 #include "fork.h"
 #include "desktop.h"
 #include "volume.h"
 
-#ifdef DEBUG1
-#define Debug(a) ((a)->options.flags & OPTION_DEBUG)
-#else
-#define Debug(a) (0)
-#endif
-
 #ifdef AFS
 struct ofork *writtenfork;
 #endif
 
-static int getforkparams(struct ofork *ofork, u_int16_t bitmap, char *buf, size_t *buflen)
+static int getforkparams(struct ofork *ofork, uint16_t bitmap, char *buf, size_t *buflen)
 {
     struct path         path;
-    struct stat                *st;
+    struct stat     *st;
+
+    struct adouble  *adp;
+    struct dir      *dir;
+    struct vol      *vol;
 
-    struct adouble     *adp;
-    struct dir         *dir;
-    struct vol         *vol;
-    
 
     /* can only get the length of the opened fork */
-    if ( ( (bitmap & ((1<<FILPBIT_DFLEN) | (1<<FILPBIT_EXTDFLEN))) 
-                  && (ofork->of_flags & AFPFORK_RSRC)) 
-        ||
-          ( (bitmap & ((1<<FILPBIT_RFLEN) | (1<<FILPBIT_EXTRFLEN))) 
-                  && (ofork->of_flags & AFPFORK_DATA))) {
+    if ( ( (bitmap & ((1<<FILPBIT_DFLEN) | (1<<FILPBIT_EXTDFLEN)))
+           && (ofork->of_flags & AFPFORK_RSRC))
+         ||
+         ( (bitmap & ((1<<FILPBIT_RFLEN) | (1<<FILPBIT_EXTRFLEN)))
+           && (ofork->of_flags & AFPFORK_DATA))) {
         return( AFPERR_BITMAP );
     }
 
@@ -80,8 +69,8 @@ static int getforkparams(struct ofork *ofork, u_int16_t bitmap, char *buf, size_
     path.m_name = of_name(ofork);
     path.id = 0;
     st = &path.st;
-    if ( bitmap & ( (1<<FILPBIT_DFLEN) | (1<<FILPBIT_EXTDFLEN) | 
-                    (1<<FILPBIT_FNUM) | (1 << FILPBIT_CDATE) | 
+    if ( bitmap & ( (1<<FILPBIT_DFLEN) | (1<<FILPBIT_EXTDFLEN) |
+                    (1<<FILPBIT_FNUM) | (1 << FILPBIT_CDATE) |
                     (1 << FILPBIT_MDATE) | (1 << FILPBIT_BDATE))) {
         if ( ad_data_fileno( ofork->of_ad ) <= 0 ) {
             /* 0 is for symlink */
@@ -98,10 +87,9 @@ static int getforkparams(struct ofork *ofork, u_int16_t bitmap, char *buf, size_
     return getmetadata(vol, bitmap, &path, dir, buf, buflen, adp );
 }
 
-/* ---------------------------- */
 static off_t get_off_t(char **ibuf, int is64)
 {
-    u_int32_t             temp;
+    uint32_t             temp;
     off_t                 ret;
 
     ret = 0;
@@ -115,15 +103,14 @@ static off_t get_off_t(char **ibuf, int is64)
         ret = ntohl(temp)| (ret << 32);
     }
     else {
-       ret = (int)ret; /* sign extend */
+        ret = (int)ret; /* sign extend */
     }
     return ret;
 }
 
-/* ---------------------- */
 static int set_off_t(off_t offset, char *rbuf, int is64)
 {
-    u_int32_t  temp;
+    uint32_t  temp;
     int        ret;
 
     ret = 0;
@@ -141,38 +128,20 @@ static int set_off_t(off_t offset, char *rbuf, int is64)
     return ret;
 }
 
-/* ------------------------ 
-*/
 static int is_neg(int is64, off_t val)
 {
     if (val < 0 || (sizeof(off_t) == 8 && !is64 && (val & 0x80000000U)))
-       return 1;
+        return 1;
     return 0;
 }
 
-static int sum_neg(int is64, off_t offset, off_t reqcount) 
+static int sum_neg(int is64, off_t offset, off_t reqcount)
 {
-    if (is_neg(is64, offset +reqcount) ) 
-       return 1;
+    if (is_neg(is64, offset +reqcount) )
+        return 1;
     return 0;
 }
 
-/* -------------------------
-*/
-static int setforkmode(struct adouble *adp, int eid, int ofrefnum, off_t what)
-{
-    return ad_lock(adp, eid, ADLOCK_RD | ADLOCK_FILELOCK, what, 1, ofrefnum);
-}
-
-/* -------------------------
-*/
-int getforkmode(struct adouble *adp, int eid, off_t what)
-{
-    return ad_testlock(adp, eid,  what);
-}
-
-/* -------------------------
-*/
 static int fork_setmode(struct adouble *adp, int eid, int access, int ofrefnum)
 {
     int ret;
@@ -182,13 +151,13 @@ static int fork_setmode(struct adouble *adp, int eid, int access, int ofrefnum)
     int denywriteset;
 
     if (! (access & (OPENACC_WR | OPENACC_RD | OPENACC_DWR | OPENACC_DRD))) {
-        return setforkmode(adp, eid, ofrefnum, AD_FILELOCK_OPEN_NONE);
+        return ad_lock(adp, eid, ADLOCK_RD | ADLOCK_FILELOCK, AD_FILELOCK_OPEN_NONE, 1, ofrefnum);
     }
 
     if ((access & (OPENACC_RD | OPENACC_DRD))) {
-        if ((readset = getforkmode(adp, eid, AD_FILELOCK_OPEN_RD)) <0)
+        if ((readset = ad_testlock(adp, eid, AD_FILELOCK_OPEN_RD)) <0)
             return readset;
-        if ((denyreadset = getforkmode(adp, eid, AD_FILELOCK_DENY_RD)) <0)
+        if ((denyreadset = ad_testlock(adp, eid, AD_FILELOCK_DENY_RD)) <0)
             return denyreadset;
 
         if ((access & OPENACC_RD) && denyreadset) {
@@ -198,26 +167,26 @@ static int fork_setmode(struct adouble *adp, int eid, int access, int ofrefnum)
         if ((access & OPENACC_DRD) && readset) {
             errno = EACCES;
             return -1;
-        }   
+        }
         /* boolean logic is not enough, because getforkmode is not always telling the
-         * true 
+         * true
          */
         if ((access & OPENACC_RD)) {
-            ret = setforkmode(adp, eid, ofrefnum, AD_FILELOCK_OPEN_RD);
+            ret = ad_lock(adp, eid, ADLOCK_RD | ADLOCK_FILELOCK, AD_FILELOCK_OPEN_RD, 1, ofrefnum);
             if (ret)
                 return ret;
         }
         if ((access & OPENACC_DRD)) {
-            ret = setforkmode(adp, eid, ofrefnum, AD_FILELOCK_DENY_RD);
+            ret = ad_lock(adp, eid, ADLOCK_RD | ADLOCK_FILELOCK, AD_FILELOCK_DENY_RD, 1, ofrefnum);
             if (ret)
                 return ret;
         }
     }
     /* ------------same for writing -------------- */
     if ((access & (OPENACC_WR | OPENACC_DWR))) {
-        if ((writeset = getforkmode(adp, eid, AD_FILELOCK_OPEN_WR)) <0)
+        if ((writeset = ad_testlock(adp, eid, AD_FILELOCK_OPEN_WR)) <0)
             return writeset;
-        if ((denywriteset = getforkmode(adp, eid, AD_FILELOCK_DENY_WR)) <0)
+        if ((denywriteset = ad_testlock(adp, eid, AD_FILELOCK_DENY_WR)) <0)
             return denywriteset;
 
         if ((access & OPENACC_WR) && denywriteset) {
@@ -227,40 +196,38 @@ static int fork_setmode(struct adouble *adp, int eid, int access, int ofrefnum)
         if ((access & OPENACC_DWR) && writeset) {
             errno = EACCES;
             return -1;
-        }   
+        }
         if ((access & OPENACC_WR)) {
-            ret = setforkmode(adp, eid, ofrefnum, AD_FILELOCK_OPEN_WR);
+            ret = ad_lock(adp, eid, ADLOCK_RD | ADLOCK_FILELOCK, AD_FILELOCK_OPEN_WR, 1, ofrefnum);
             if (ret)
                 return ret;
         }
         if ((access & OPENACC_DWR)) {
-            ret = setforkmode(adp, eid, ofrefnum, AD_FILELOCK_DENY_WR);
+            ret = ad_lock(adp, eid, ADLOCK_RD | ADLOCK_FILELOCK, AD_FILELOCK_DENY_WR, 1, ofrefnum);
             if (ret)
                 return ret;
         }
     }
-    if ( access == (OPENACC_WR | OPENACC_RD | OPENACC_DWR | OPENACC_DRD)) {
-        return ad_excl_lock(adp, eid);
-    }
+
     return 0;
 }
 
 /* ----------------------- */
 int afp_openfork(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbuflen)
 {
-    struct vol         *vol;
-    struct dir         *dir;
-    struct ofork       *ofork, *opened;
-    struct adouble      *adsame = NULL;
-    size_t             buflen;
-    int                        ret, adflags, eid;
-    u_int32_t           did;
-    u_int16_t          vid, bitmap, access, ofrefnum;
-    char               fork, *path, *upath;
-    struct stat         *st;
-    u_int16_t           bshort;
-    struct path         *s_path;
-    
+    struct vol      *vol;
+    struct dir      *dir;
+    struct ofork    *ofork, *opened;
+    struct adouble  *adsame = NULL;
+    size_t          buflen;
+    int             ret, adflags, eid;
+    uint32_t        did;
+    uint16_t        vid, bitmap, access, ofrefnum;
+    char            fork, *path, *upath;
+    struct stat     *st;
+    uint16_t        bshort;
+    struct path     *s_path;
+
     ibuf++;
     fork = *ibuf++;
     memcpy(&vid, ibuf, sizeof( vid ));
@@ -275,7 +242,7 @@ int afp_openfork(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, si
     ibuf += sizeof( int );
 
     if (NULL == ( dir = dirlookup( vol, did ))) {
-       return afp_errno;    
+        return afp_errno;
     }
 
     memcpy(&bitmap, ibuf, sizeof( bitmap ));
@@ -290,14 +257,17 @@ int afp_openfork(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, si
     }
 
     if (NULL == ( s_path = cname( vol, dir, &ibuf ))) {
-       return get_afp_errno(AFPERR_PARAM);    
+        return get_afp_errno(AFPERR_PARAM);
     }
 
     if (*s_path->m_name == '\0') {
-       /* it's a dir ! */
-       return  AFPERR_BADTYPE;
+        /* it's a dir ! */
+        return  AFPERR_BADTYPE;
     }
 
+    LOG(log_debug, logtype_afpd, "afp_openfork(\"%s\", %s)",
+        fullpathname(s_path->u_name), (fork & OPENFORK_RSCS) ? "RSRC" : "DATA");
+
     /* stat() data fork st is set because it's not a dir */
     switch ( s_path->st_errno ) {
     case 0:
@@ -307,7 +277,7 @@ int afp_openfork(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, si
     case EACCES:
         return (access & OPENACC_WR) ? AFPERR_LOCK : AFPERR_ACCESS;
     default:
-        LOG(log_error, logtype_afpd, "afp_openfork(%s): ad_open: %s", s_path->m_name, strerror(errno) );
+        LOG(log_error, logtype_afpd, "afp_openfork(%s): %s", s_path->m_name, strerror(errno));
         return AFPERR_PARAM;
     }
     /* FIXME should we check it first ? */
@@ -316,8 +286,7 @@ int afp_openfork(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, si
         if (check_access(upath, access ) < 0) {
             return AFPERR_ACCESS;
         }
-    }
-    else {
+    } else {
         if (file_access(s_path, access ) < 0) {
             return AFPERR_ACCESS;
         }
@@ -327,9 +296,9 @@ int afp_openfork(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, si
     /* XXX: this probably isn't the best way to do this. the already
        open bits should really be set if the fork is opened by any
        program, not just this one. however, that's problematic to do
-       if we can't write lock files somewhere. opened is also passed to 
+       if we can't write lock files somewhere. opened is also passed to
        ad_open so that we can keep file locks together.
-       FIXME: add the fork we are opening? 
+       FIXME: add the fork we are opening?
     */
     if ((opened = of_findname(s_path))) {
         adsame = opened->of_ad;
@@ -337,10 +306,10 @@ int afp_openfork(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, si
 
     if ( fork == OPENFORK_DATA ) {
         eid = ADEID_DFORK;
-        adflags = ADFLAGS_DF|ADFLAGS_HF;
+        adflags = ADFLAGS_DF | ADFLAGS_HF ;
     } else {
         eid = ADEID_RFORK;
-        adflags = ADFLAGS_HF;
+        adflags = ADFLAGS_RF | ADFLAGS_HF;
     }
 
     path = s_path->m_name;
@@ -352,7 +321,8 @@ int afp_openfork(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, si
     ret = AFPERR_NOOBJ;
     if (access & OPENACC_WR) {
         /* try opening in read-write mode */
-        if (ad_open(upath, adflags, O_RDWR, 0, ofork->of_ad) < 0) {
+        if (ad_open(ofork->of_ad, upath,
+                    adflags | ADFLAGS_RDWR | ADFLAGS_SETSHRMD) < 0) {
             switch ( errno ) {
             case EROFS:
                 ret = AFPERR_VLOCK;
@@ -362,15 +332,16 @@ int afp_openfork(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, si
             case ENOENT:
                 if (fork == OPENFORK_DATA) {
                     /* try to open only the data fork */
-                    if (ad_open(upath, ADFLAGS_DF, O_RDWR, 0, ofork->of_ad) < 0) {
+                    if (ad_open(ofork->of_ad, upath,
+                                ADFLAGS_DF | ADFLAGS_RDWR | ADFLAGS_SETSHRMD) < 0) {
                         goto openfork_err;
                     }
                     adflags = ADFLAGS_DF;
-                }
-                else {
+                } else {
                     /* here's the deal. we only try to create the resource
-                    * fork if the user wants to open it for write acess. */
-                    if (ad_open(upath, adflags, O_RDWR | O_CREAT, 0666, ofork->of_ad) < 0)
+                     * fork if the user wants to open it for write acess. */
+                    if (ad_open(ofork->of_ad, upath,
+                                adflags | ADFLAGS_RDWR | ADFLAGS_SETSHRMD | ADFLAGS_CREATE, 0666) < 0)
                         goto openfork_err;
                     ofork->of_flags |= AFPFORK_OPEN;
                 }
@@ -398,29 +369,30 @@ int afp_openfork(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, si
     } else {
         /* try opening in read-only mode */
         ret = AFPERR_NOOBJ;
-        if (ad_open(upath, adflags, O_RDONLY, 0, ofork->of_ad) < 0) {
+        /* we need w access for setting deny mode fcntl excl lock */
+        if (ad_open(ofork->of_ad, upath, adflags | ADFLAGS_RDONLY | ADFLAGS_SETSHRMD) < 0) {
             switch ( errno ) {
             case EROFS:
                 ret = AFPERR_VLOCK;
+                goto openfork_err;
             case EACCES:
                 goto openfork_err;
-                break;
             case ENOENT:
                 /* see if client asked for a read only data fork */
                 if (fork == OPENFORK_DATA) {
-                    if (ad_open(upath, ADFLAGS_DF, O_RDONLY, 0, ofork->of_ad) < 0) {
+                    if (ad_open(ofork->of_ad, upath, ADFLAGS_DF | ADFLAGS_RDONLY | ADFLAGS_SETSHRMD) < 0) {
                         goto openfork_err;
                     }
                     adflags = ADFLAGS_DF;
                 }
-                /* else we don't set AFPFORK_OPEN because there's no ressource fork file 
+                /* else we don't set AFPFORK_OPEN because there's no ressource fork file
                  * We need to check AFPFORK_OPEN in afp_closefork(). eg fork open read-only
                  * then create in open read-write.
                  * FIXME , it doesn't play well with byte locking example:
                  * ressource fork open read only
                  * locking set on it (no effect, there's no file!)
                  * ressource fork open read write now
-                */
+                 */
                 break;
             case EMFILE :
             case ENFILE :
@@ -432,8 +404,8 @@ int afp_openfork(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, si
                 goto openfork_err;
                 break;
             default:
-                LOG(log_error, logtype_afpd, "afp_openfork('%s/%s'): ad_open: errno: %i (%s)",
-                    getcwdpath, s_path->m_name, errno, strerror(errno) );
+                LOG(log_error, logtype_afpd, "afp_openfork(\"%s\"): %s",
+                    fullpathname(s_path->m_name), strerror(errno) );
                 goto openfork_err;
                 break;
             }
@@ -444,25 +416,24 @@ int afp_openfork(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, si
         }
     }
 
-    if ((adflags & ADFLAGS_HF) && (ad_get_HF_flags( ofork->of_ad) & O_CREAT)) {
+    if ((adflags & ADFLAGS_RF) && (ad_get_RF_flags( ofork->of_ad) & O_CREAT)) {
         if (ad_setname(ofork->of_ad, path)) {
             ad_flush( ofork->of_ad );
         }
     }
 
-    if (( ret = getforkparams(ofork, bitmap, rbuf + 2 * sizeof( u_int16_t ),
-                              &buflen )) != AFP_OK ) {
+    if ((ret = getforkparams(ofork, bitmap, rbuf + 2 * sizeof(int16_t), &buflen)) != AFP_OK) {
         ad_close( ofork->of_ad, adflags );
         goto openfork_err;
     }
 
-    *rbuflen = buflen + 2 * sizeof( u_int16_t );
+    *rbuflen = buflen + 2 * sizeof( uint16_t );
     bitmap = htons( bitmap );
-    memcpy(rbuf, &bitmap, sizeof( u_int16_t ));
-    rbuf += sizeof( u_int16_t );
+    memcpy(rbuf, &bitmap, sizeof( uint16_t ));
+    rbuf += sizeof( uint16_t );
 
     /* check  WriteInhibit bit if we have a ressource fork
-     * the test is done here, after some Mac trafic capture 
+     * the test is done here, after some Mac trafic capture
      */
     if (ad_meta_fileno(ofork->of_ad) != -1) {   /* META */
         ad_getattr(ofork->of_ad, &bshort);
@@ -480,7 +451,9 @@ int afp_openfork(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, si
      */
 
     /* don't try to lock non-existent rforks. */
-    if ((eid == ADEID_DFORK) || (ad_meta_fileno(ofork->of_ad) != -1)) { /* META */
+    if ((eid == ADEID_DFORK)
+        || (ad_meta_fileno(ofork->of_ad) != -1)
+        || (vol->v_adouble & AD_VERSION_EA)) { /* META */
 
         ret = fork_setmode(ofork->of_ad, eid, access, ofrefnum);
         /* can we access the fork? */
@@ -521,14 +494,14 @@ openfork_err:
 
 int afp_setforkparams(AFPObj *obj _U_, char *ibuf, size_t ibuflen, char *rbuf _U_, size_t *rbuflen)
 {
-    struct ofork       *ofork;
-    off_t              size;
-    u_int16_t          ofrefnum, bitmap;
+    struct ofork    *ofork;
+    off_t       size;
+    uint16_t       ofrefnum, bitmap;
     int                 err;
     int                 is64;
     int                 eid;
-    off_t              st_size;
-    
+    off_t       st_size;
+
     ibuf += 2;
 
     memcpy(&ofrefnum, ibuf, sizeof( ofrefnum ));
@@ -557,26 +530,26 @@ int afp_setforkparams(AFPObj *obj _U_, char *ibuf, size_t ibuflen, char *rbuf _U
     } else
         return AFPERR_PARAM;
 
-    if ( ( (bitmap & ( (1<<FILPBIT_DFLEN) | (1<<FILPBIT_EXTDFLEN) )) 
-                  && eid == ADEID_RFORK 
-         ) ||
-         ( (bitmap & ( (1<<FILPBIT_RFLEN) | (1<<FILPBIT_EXTRFLEN) )) 
-                  && eid == ADEID_DFORK)) {
+    if ( ( (bitmap & ( (1<<FILPBIT_DFLEN) | (1<<FILPBIT_EXTDFLEN) ))
+           && eid == ADEID_RFORK
+             ) ||
+         ( (bitmap & ( (1<<FILPBIT_RFLEN) | (1<<FILPBIT_EXTRFLEN) ))
+           && eid == ADEID_DFORK)) {
         return AFPERR_BITMAP;
     }
-    
+
     is64 = 0;
     if ((bitmap & ( (1<<FILPBIT_EXTDFLEN) | (1<<FILPBIT_EXTRFLEN) ))) {
         if (afp_version >= 30) {
             is64 = 4;
         }
-        else 
-           return AFPERR_BITMAP;
+        else
+            return AFPERR_BITMAP;
     }
 
     if (ibuflen < 2+ sizeof(ofrefnum) + sizeof(bitmap) + is64 +4)
         return AFPERR_PARAM ;
-    
+
     size = get_off_t(&ibuf, is64);
 
     if (size < 0)
@@ -584,29 +557,29 @@ int afp_setforkparams(AFPObj *obj _U_, char *ibuf, size_t ibuflen, char *rbuf _U
 
 
     if (bitmap == (1<<FILPBIT_DFLEN) || bitmap == (1<<FILPBIT_EXTDFLEN)) {
-       st_size = ad_size(ofork->of_ad, eid);
-       err = -2;
-       if (st_size > size && 
-             ad_tmplock(ofork->of_ad, eid, ADLOCK_WR, size, st_size -size, ofork->of_refnum) < 0) 
+        st_size = ad_size(ofork->of_ad, eid);
+        err = -2;
+        if (st_size > size &&
+            ad_tmplock(ofork->of_ad, eid, ADLOCK_WR, size, st_size -size, ofork->of_refnum) < 0)
             goto afp_setfork_err;
 
         err = ad_dtruncate( ofork->of_ad, size );
         if (st_size > size)
-           ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, size, st_size -size, ofork->of_refnum);  
+            ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, size, st_size -size, ofork->of_refnum);
         if (err < 0)
             goto afp_setfork_err;
     } else if (bitmap == (1<<FILPBIT_RFLEN) || bitmap == (1<<FILPBIT_EXTRFLEN)) {
         ad_refresh( ofork->of_ad );
 
-       st_size = ad_size(ofork->of_ad, eid);
-       err = -2;
-       if (st_size > size && 
-              ad_tmplock(ofork->of_ad, eid, ADLOCK_WR, size, st_size -size, ofork->of_refnum) < 0) {
+        st_size = ad_size(ofork->of_ad, eid);
+        err = -2;
+        if (st_size > size &&
+            ad_tmplock(ofork->of_ad, eid, ADLOCK_WR, size, st_size -size, ofork->of_refnum) < 0) {
             goto afp_setfork_err;
-       }
+        }
         err = ad_rtruncate(ofork->of_ad, size);
         if (st_size > size)
-           ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, size, st_size -size, ofork->of_refnum);  
+            ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, size, st_size -size, ofork->of_refnum);
         if (err < 0)
             goto afp_setfork_err;
 
@@ -649,7 +622,7 @@ afp_setfork_err:
  * read and write. that's most easily handled by always doing an
  * appropriate check before each ad_read/ad_write. other things
  * that can change files like truncate are handled internally to those
- * functions. 
+ * functions.
  */
 #define ENDBIT(a)  ((a) & 0x80)
 #define UNLOCKBIT(a) ((a) & 0x01)
@@ -658,13 +631,13 @@ afp_setfork_err:
 /* ---------------------- */
 static int byte_lock(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbuflen, int is64)
 {
-    struct ofork       *ofork;
+    struct ofork    *ofork;
     off_t               offset, length;
     int                 eid;
-    u_int16_t          ofrefnum;
-    u_int8_t            flags;
+    uint16_t       ofrefnum;
+    uint8_t            flags;
     int                 lockop;
-    
+
     *rbuflen = 0;
 
     /* figure out parameters */
@@ -692,15 +665,15 @@ static int byte_lock(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf
     /* FIXME AD_FILELOCK test is surely wrong */
     if (length == -1)
         length = BYTELOCK_MAX;
-     else if (!length || is_neg(is64, length)) {
-       return AFPERR_PARAM;
-     } else if ((length >= AD_FILELOCK_BASE) && -1 == (ad_reso_fileno(ofork->of_ad))) { /* HF ?*/
+    else if (!length || is_neg(is64, length)) {
+        return AFPERR_PARAM;
+    } else if ((length >= AD_FILELOCK_BASE) && -1 == (ad_reso_fileno(ofork->of_ad))) { /* HF ?*/
         return AFPERR_LOCK;
     }
 
     if (ENDBIT(flags)) {
         offset += ad_size(ofork->of_ad, eid);
-        /* FIXME what do we do if file size > 2 GB and 
+        /* FIXME what do we do if file size > 2 GB and
            it's not byte_lock_ext?
         */
     }
@@ -737,13 +710,13 @@ static int byte_lock(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf
 /* --------------------------- */
 int afp_bytelock(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)
 {
-   return byte_lock ( obj, ibuf, ibuflen, rbuf, rbuflen , 0);
+    return byte_lock ( obj, ibuf, ibuflen, rbuf, rbuflen , 0);
 }
 
 /* --------------------------- */
 int afp_bytelock_ext(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)
 {
-   return byte_lock ( obj, ibuf, ibuflen, rbuf, rbuflen , 1);
+    return byte_lock ( obj, ibuf, ibuflen, rbuf, rbuflen , 1);
 }
 
 #undef UNLOCKBIT
@@ -751,13 +724,13 @@ int afp_bytelock_ext(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t
 /* --------------------------- */
 static int crlf(struct ofork *of)
 {
-    struct extmap      *em;
+    struct extmap   *em;
 
     if ( ad_meta_fileno( of->of_ad ) == -1 || !memcmp( ufinderi, ad_entry( of->of_ad, ADEID_FINDERI),8)) { /* META */
         /* no resource fork or no finderinfo, use our files extension mapping */
         if (!( em = getextmap( of_name(of) )) || memcmp( "TEXT", em->em_type, sizeof( em->em_type ))) {
             return 0;
-        } 
+        }
         /* file type is TEXT */
         return 1;
 
@@ -769,9 +742,9 @@ static int crlf(struct ofork *of)
 
 
 static ssize_t read_file(struct ofork *ofork, int eid,
-                                    off_t offset, u_char nlmask,
-                                    u_char nlchar, char *rbuf,
-                                    size_t *rbuflen, const int xlate)
+                         off_t offset, u_char nlmask,
+                         u_char nlchar, char *rbuf,
+                         size_t *rbuflen, const int xlate)
 {
     ssize_t cc;
     int eof = 0;
@@ -824,7 +797,7 @@ static ssize_t read_file(struct ofork *ofork, int eid,
 }
 
 /* -----------------------------
- * with ddp, afp_read can return fewer bytes than in reqcount 
+ * with ddp, afp_read can return fewer bytes than in reqcount
  * so return EOF only if read actually past end of file not
  * if offset +reqcount > size of file
  * e.g.:
@@ -832,18 +805,18 @@ static ssize_t read_file(struct ofork *ofork, int eid,
  * read fork offset 0 size 10752 ????  ==> 4264 bytes (without EOF)
  * read fork offset 4264 size 6128 ==> 4264 (without EOF)
  * read fork offset 9248 size 1508 ==> 1182 (EOF)
- * 10752 is a bug in Mac 7.5.x finder 
+ * 10752 is a bug in Mac 7.5.x finder
  *
- * with dsi, should we check that reqcount < server quantum? 
-*/
+ * with dsi, should we check that reqcount < server quantum?
+ */
 static int read_fork(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbuflen, int is64)
 {
-    struct ofork       *ofork;
-    off_t              offset, saveoff, reqcount, savereqcount;
-    ssize_t            cc, err;
-    int                        eid, xlate = 0;
-    u_int16_t          ofrefnum;
-    u_char             nlmask, nlchar;
+    struct ofork    *ofork;
+    off_t       offset, saveoff, reqcount, savereqcount;
+    ssize_t     cc, err;
+    int         eid, xlate = 0;
+    uint16_t       ofrefnum;
+    u_char      nlmask, nlchar;
 
     ibuf += 2;
     memcpy(&ofrefnum, ibuf, sizeof( ofrefnum ));
@@ -862,6 +835,10 @@ static int read_fork(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, si
     offset   = get_off_t(&ibuf, is64);
     reqcount = get_off_t(&ibuf, is64);
 
+    LOG(log_debug, logtype_afpd,
+        "afp_read(off: %" PRIu64 ", size: %" PRIu64 ", fork: %s)", offset, reqcount,
+        (ofork->of_flags & AFPFORK_DATA) ? "d" : "r");
+
     if (is64) {
         nlmask = nlchar = 0;
     }
@@ -906,6 +883,7 @@ static int read_fork(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, si
     *rbuflen = MIN(reqcount, *rbuflen);
     LOG(log_debug, logtype_afpd, "afp_read(name: \"%s\", offset: %jd, reqcount: %jd): reading %jd bytes from file",
         of_name(ofork), (intmax_t)offset, (intmax_t)reqcount, (intmax_t)*rbuflen);
+
     err = read_file(ofork, eid, offset, nlmask, nlchar, rbuf, rbuflen, xlate);
     if (err < 0)
         goto afp_read_done;
@@ -924,8 +902,8 @@ static int read_fork(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, si
         /* subtract off the offset */
         size -= offset;
         if (reqcount > size) {
-          reqcount = size;
-           err = AFPERR_EOF;
+            reqcount = size;
+            err = AFPERR_EOF;
         }
 
         offset += *rbuflen;
@@ -938,10 +916,10 @@ static int read_fork(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, si
         *rbuflen = cc;
         /* due to the nature of afp packets, we have to exit if we get
            an error. we can't do this with translation on. */
-#ifdef WITH_SENDFILE 
-        if (!(xlate || Debug(obj) )) {
+#ifdef WITH_SENDFILE
+        if (!(xlate)) {
             int fd;
-                        
+
             fd = ad_readfile_init(ofork->of_ad, eid, &offset, 0);
 
             if (dsi_stream_read_file(dsi, fd, offset, dsi->datasize) < 0) {
@@ -957,8 +935,8 @@ static int read_fork(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, si
             goto afp_read_done;
         }
 
-afp_read_loop:
-#endif 
+    afp_read_loop:
+#endif
 
         /* fill up our buffer. */
         while (*rbuflen > 0) {
@@ -976,7 +954,7 @@ afp_read_loop:
         dsi_readdone(dsi);
         goto afp_read_done;
 
-afp_read_exit:
+    afp_read_exit:
         LOG(log_error, logtype_afpd, "afp_read(%s): %s", of_name(ofork), strerror(errno));
         dsi_readdone(dsi);
         ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, saveoff, savereqcount,ofork->of_refnum);
@@ -1008,7 +986,7 @@ int afp_read_ext(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rb
 int afp_flush(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen)
 {
     struct vol *vol;
-    u_int16_t vid;
+    uint16_t vid;
 
     *rbuflen = 0;
     ibuf += 2;
@@ -1022,10 +1000,10 @@ int afp_flush(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, s
     return( AFP_OK );
 }
 
-int afp_flushfork(AFPObj *obj _U_, char        *ibuf, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen)
+int afp_flushfork(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen)
 {
-    struct ofork       *ofork;
-    u_int16_t          ofrefnum;
+    struct ofork    *ofork;
+    uint16_t       ofrefnum;
 
     *rbuflen = 0;
     ibuf += 2;
@@ -1036,6 +1014,9 @@ int afp_flushfork(AFPObj *obj _U_, char   *ibuf, size_t ibuflen _U_, char *rbuf _U
         return( AFPERR_PARAM );
     }
 
+    LOG(log_debug, logtype_afpd, "afp_flushfork(fork: %s)",
+        (ofork->of_flags & AFPFORK_DATA) ? "d" : "r");
+
     if ( flushfork( ofork ) < 0 ) {
         LOG(log_error, logtype_afpd, "afp_flushfork(%s): %s", of_name(ofork), strerror(errno) );
     }
@@ -1048,11 +1029,11 @@ int afp_flushfork(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf _U
   There is a lot to tell about fsync, fdatasync, F_FULLFSYNC.
   fsync(2) on OSX is implemented differently than on other platforms.
   see: http://mirror.linux.org.au/pub/linux.conf.au/2007/video/talks/278.pdf.
- */
+*/
 int afp_syncfork(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen)
 {
     struct ofork        *ofork;
-    u_int16_t           ofrefnum;
+    uint16_t           ofrefnum;
 
     *rbuflen = 0;
     ibuf += 2;
@@ -1065,9 +1046,12 @@ int afp_syncfork(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf _U_
         return( AFPERR_PARAM );
     }
 
+    LOG(log_debug, logtype_afpd, "afp_syncfork(fork: %s)",
+        (ofork->of_flags & AFPFORK_DATA) ? "d" : "r");
+
     if ( flushfork( ofork ) < 0 ) {
-       LOG(log_error, logtype_afpd, "flushfork(%s): %s", of_name(ofork), strerror(errno) );
-       return AFPERR_MISC;
+        LOG(log_error, logtype_afpd, "flushfork(%s): %s", of_name(ofork), strerror(errno) );
+        return AFPERR_MISC;
     }
 
     return( AFP_OK );
@@ -1081,14 +1065,14 @@ int flushfork(struct ofork *ofork)
     int err = 0, doflush = 0;
 
     if ( ad_data_fileno( ofork->of_ad ) != -1 &&
-            fsync( ad_data_fileno( ofork->of_ad )) < 0 ) {
+         fsync( ad_data_fileno( ofork->of_ad )) < 0 ) {
         LOG(log_error, logtype_afpd, "flushfork(%s): dfile(%d) %s",
             of_name(ofork), ad_data_fileno(ofork->of_ad), strerror(errno) );
         err = -1;
     }
 
     if ( ad_reso_fileno( ofork->of_ad ) != -1 &&  /* HF */
-        (ofork->of_flags & AFPFORK_RSRC)) {
+         (ofork->of_flags & AFPFORK_RSRC)) {
 
         /* read in the rfork length */
         ad_refresh(ofork->of_ad);
@@ -1102,7 +1086,7 @@ int flushfork(struct ofork *ofork)
 
         /* flush the header */
         if (doflush && ad_flush(ofork->of_ad) < 0)
-                err = -1;
+            err = -1;
 
         if (fsync( ad_reso_fileno( ofork->of_ad )) < 0)
             err = -1;
@@ -1117,8 +1101,8 @@ int flushfork(struct ofork *ofork)
 
 int afp_closefork(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen)
 {
-    struct ofork       *ofork;
-    u_int16_t          ofrefnum;
+    struct ofork    *ofork;
+    uint16_t       ofrefnum;
 
     *rbuflen = 0;
     ibuf += 2;
@@ -1128,6 +1112,10 @@ int afp_closefork(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf _U
         LOG(log_error, logtype_afpd, "afp_closefork: of_find(%d) could not locate fork", ofrefnum );
         return( AFPERR_PARAM );
     }
+
+    LOG(log_debug, logtype_afpd, "afp_closefork(fork: %s)",
+        (ofork->of_flags & AFPFORK_DATA) ? "d" : "r");
+
     if ( of_closefork( ofork ) < 0 ) {
         LOG(log_error, logtype_afpd, "afp_closefork(%s): of_closefork: %s", of_name(ofork), strerror(errno) );
         return( AFPERR_PARAM );
@@ -1138,8 +1126,8 @@ int afp_closefork(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf _U
 
 
 static ssize_t write_file(struct ofork *ofork, int eid,
-                                     off_t offset, char *rbuf,
-                                     size_t rbuflen, const int xlate)
+                          off_t offset, char *rbuf,
+                          size_t rbuflen, const int xlate)
 {
     char *p, *q;
     ssize_t cc;
@@ -1177,14 +1165,14 @@ static ssize_t write_file(struct ofork *ofork, int eid,
 
 
 /* FPWrite. NOTE: on an error, we always use afp_write_err as
- * the client may have sent us a bunch of data that's not reflected 
+ * the client may have sent us a bunch of data that's not reflected
  * in reqcount et al. */
 static int write_fork(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbuflen, int is64)
 {
-    struct ofork       *ofork;
-    off_t           offset, saveoff, reqcount, oldsize, newsize;
-    int                        endflag, eid, xlate = 0, err = AFP_OK;
-    u_int16_t          ofrefnum;
+    struct ofork    *ofork;
+    off_t               offset, saveoff, reqcount, oldsize, newsize;
+    int             endflag, eid, xlate = 0, err = AFP_OK;
+    uint16_t       ofrefnum;
     ssize_t             cc;
 
     /* figure out parameters */
@@ -1203,6 +1191,9 @@ static int write_fork(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, s
         goto afp_write_err;
     }
 
+    LOG(log_debug, logtype_afpd, "afp_write(off: %" PRIu64 ", size: %" PRIu64 ", fork: %s)",
+        offset, reqcount, (ofork->of_flags & AFPFORK_DATA) ? "d" : "r");
+
     if ((ofork->of_flags & AFPFORK_ACCWR) == 0) {
         err = AFPERR_ACCESS;
         goto afp_write_err;
@@ -1236,7 +1227,7 @@ static int write_fork(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, s
 
     /* offset can overflow on 64-bit capable filesystems.
      * report disk full if that's going to happen. */
-     if (sum_neg(is64, offset, reqcount)) {
+    if (sum_neg(is64, offset, reqcount)) {
         err = AFPERR_DFULL;
         goto afp_write_err;
     }
@@ -1256,84 +1247,60 @@ static int write_fork(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, s
 
     /* this is yucky, but dsi can stream i/o and asp can't */
     switch (obj->proto) {
-#ifndef NO_DDP
-    case AFPPROTO_ASP:
-        if (asp_wrtcont(obj->handle, rbuf, rbuflen) < 0) {
-            *rbuflen = 0;
-            LOG(log_error, logtype_afpd, "afp_write: asp_wrtcont: %s", strerror(errno) );
-            return( AFPERR_PARAM );
-        }
+    case AFPPROTO_DSI:
+    {
+        DSI *dsi = obj->handle;
 
-#ifdef DEBUG1
-        if (obj->options.flags & OPTION_DEBUG) {
-            printf("(write) len: %d\n", *rbuflen);
-            bprint(rbuf, *rbuflen);
-        }
-#endif
-        if ((cc = write_file(ofork, eid, offset, rbuf, *rbuflen,
-                             xlate)) < 0) {
+        /* find out what we have already and write it out. */
+        cc = dsi_writeinit(dsi, rbuf, *rbuflen);
+        if (!cc || (cc = write_file(ofork, eid, offset, rbuf, cc, xlate)) < 0) {
+            dsi_writeflush(dsi);
             *rbuflen = 0;
             ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, saveoff, reqcount, ofork->of_refnum);
             return cc;
         }
         offset += cc;
-        break;
-#endif /* no afp/asp */
-
-    case AFPPROTO_DSI:
-        {
-            DSI *dsi = obj->handle;
 
-            /* find out what we have already and write it out. */
-            cc = dsi_writeinit(dsi, rbuf, *rbuflen);
-            if (!cc || (cc = write_file(ofork, eid, offset, rbuf, cc, xlate)) < 0) {
+#if 0 /*def HAVE_SENDFILE_WRITE*/
+        if (!(xlate || obj->options.flags & OPTION_DEBUG)) {
+            if ((cc = ad_writefile(ofork->of_ad, eid, dsi->socket,
+                                   offset, dsi->datasize)) < 0) {
+                switch (errno) {
+                case EDQUOT :
+                case EFBIG :
+                case ENOSPC :
+                    cc = AFPERR_DFULL;
+                    break;
+                default :
+                    LOG(log_error, logtype_afpd, "afp_write: ad_writefile: %s", strerror(errno) );
+                    goto afp_write_loop;
+                }
                 dsi_writeflush(dsi);
                 *rbuflen = 0;
-                ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, saveoff, reqcount, ofork->of_refnum);
+                ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, saveoff,
+                           reqcount,  ofork->of_refnum);
                 return cc;
             }
-            offset += cc;
 
-#if 0 /*def HAVE_SENDFILE_WRITE*/
-            if (!(xlate || obj->options.flags & OPTION_DEBUG)) {
-                if ((cc = ad_writefile(ofork->of_ad, eid, dsi->socket,
-                                       offset, dsi->datasize)) < 0) {
-                    switch (errno) {
-                    case EDQUOT :
-                    case EFBIG :
-                    case ENOSPC :
-                        cc = AFPERR_DFULL;
-                        break;
-                    default :
-                        LOG(log_error, logtype_afpd, "afp_write: ad_writefile: %s", strerror(errno) );
-                        goto afp_write_loop;
-                    }
-                    dsi_writeflush(dsi);
-                    *rbuflen = 0;
-                    ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, saveoff,
-                               reqcount,  ofork->of_refnum);
-                    return cc;
-                }
-
-                offset += cc;
-                goto afp_write_done;
-            }
+            offset += cc;
+            goto afp_write_done;
+        }
 #endif /* 0, was HAVE_SENDFILE_WRITE */
 
-            /* loop until everything gets written. currently
-                    * dsi_write handles the end case by itself. */
-            while ((cc = dsi_write(dsi, rbuf, *rbuflen))) {
-                if ((cc = write_file(ofork, eid, offset, rbuf, cc, xlate)) < 0) {
-                    dsi_writeflush(dsi);
-                    *rbuflen = 0;
-                    ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, saveoff,
-                               reqcount,  ofork->of_refnum);
-                    return cc;
-                }
-                offset += cc;
+        /* loop until everything gets written. currently
+         * dsi_write handles the end case by itself. */
+        while ((cc = dsi_write(dsi, rbuf, *rbuflen))) {
+            if ((cc = write_file(ofork, eid, offset, rbuf, cc, xlate)) < 0) {
+                dsi_writeflush(dsi);
+                *rbuflen = 0;
+                ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, saveoff,
+                           reqcount,  ofork->of_refnum);
+                return cc;
             }
+            offset += cc;
         }
-        break;
+    }
+    break;
     }
 
     ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, saveoff, reqcount,  ofork->of_refnum);
@@ -1366,9 +1333,9 @@ int afp_write(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbufl
     return write_fork(obj, ibuf, ibuflen, rbuf, rbuflen, 0);
 }
 
-/* ---------------------------- 
+/* ----------------------------
  * FIXME need to deal with SIGXFSZ signal
-*/
+ */
 int afp_write_ext(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)
 {
     return write_fork(obj, ibuf, ibuflen, rbuf, rbuflen, 1);
@@ -1377,9 +1344,9 @@ int afp_write_ext(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *r
 /* ---------------------------- */
 int afp_getforkparams(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbuflen)
 {
-    struct ofork       *ofork;
+    struct ofork    *ofork;
     int             ret;
-    u_int16_t          ofrefnum, bitmap;
+    uint16_t       ofrefnum, bitmap;
     size_t          buflen;
     ibuf += 2;
     memcpy(&ofrefnum, ibuf, sizeof( ofrefnum ));
@@ -1402,7 +1369,7 @@ int afp_getforkparams(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbu
     }
 
     if (AFP_OK != ( ret = getforkparams( ofork, bitmap,
-                               rbuf + sizeof( u_short ), &buflen ))) {
+                                         rbuf + sizeof( u_short ), &buflen ))) {
         return( ret );
     }
 
index 0ad46a9779ff519afcac78183db69c9c8e24e33a..9355c5e545d3a3bf3ede322c4af737dcdfed1b40 100644 (file)
@@ -7,9 +7,8 @@
 #define AFPD_FORK_H 1
 
 #include <stdio.h>
-#include <sys/cdefs.h>
+#include <arpa/inet.h>
 
-#include <netatalk/endian.h>
 #include <atalk/adouble.h>
 #include "volume.h"
 #include "directory.h"
@@ -55,18 +54,17 @@ extern struct ofork *writtenfork;
 #define of_name(a) (a)->of_ad->ad_m_name
 /* in ofork.c */
 extern struct ofork *of_alloc    (struct vol *, struct dir *,
-                                                      char *, u_int16_t *, const int,
+                                                      char *, uint16_t *, const int,
                                                       struct adouble *,
                                                       struct stat *);
 extern void         of_dealloc   (struct ofork *);
-extern struct ofork *of_find     (const u_int16_t);
+extern struct ofork *of_find     (const uint16_t);
 extern struct ofork *of_findname (struct path *);
 extern int          of_rename    (const struct vol *,
                                           struct ofork *,
                                           struct dir *, const char *,
                                           struct dir *, const char *);
 extern int          of_flush     (const struct vol *);
-extern void         of_pforkdesc (FILE *);
 extern int          of_stat      (struct path *);
 extern int          of_statdir   (struct vol *vol, struct path *);
 extern int          of_closefork (struct ofork *ofork);
@@ -82,7 +80,6 @@ extern int of_fstatat(int dirfd, struct path *path);
 
 /* in fork.c */
 extern int          flushfork    (struct ofork *);
-extern int          getforkmode  (struct adouble *, int , off_t );
 
 /* FP functions */
 int afp_openfork (AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf,  size_t *rbuflen);
index 6c9d473b34379f4741060826197e542dbf56b462..fd48db688e1a56b39ca2d817efe00a15c6cf9f06 100644 (file)
 #endif /* HAVE_CONFIG_H */
 
 #include <sys/param.h>
-
-/* STDC check */
-#if STDC_HEADERS
 #include <string.h>
-#else /* STDC_HEADERS */
-#ifndef HAVE_STRCHR
-#define strchr index
-#define strrchr index
-#endif /* HAVE_STRCHR */
-char *strchr (), *strrchr ();
-#ifndef HAVE_MEMCPY
-#define memcpy(d,s,n) bcopy ((s), (d), (n))
-#define memmove(d,s,n) bcopy ((s), (d), (n))
-#endif /* ! HAVE_MEMCPY */
-#endif /* STDC_HEADERS */
-
 #include <ctype.h>
 #include <pwd.h>
 
index c3214a0a762b71cc84e4f469f0c14d99dc95451a..c26b6fd63e4e56cc647155f9f47e850a0274523f 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: icon.h,v 1.5 2009-10-16 00:11:42 didg Exp $
- *
  * Copyright (c) 1990,1994 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
  */
@@ -8,7 +6,6 @@
 #ifndef AFPD_ICON_H
 #define AFPD_ICON_H 1
 
-#include <sys/cdefs.h>
 #include <atalk/globals.h>
 
 static const unsigned char apple_atalk_icon[] = { /* default appletalk icon */
index edcfe6a7565d8339e5239b8ecead0a39fb66a821..c549fa09a49349aaee6f4c5e24c6d6ca015b7bbd 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 #include <signal.h>
-
 #include <sys/param.h>
 #include <sys/uio.h>
-#include <atalk/logger.h>
 #include <sys/time.h>
 #include <sys/socket.h>
 #include <sys/poll.h>
 #include <sys/wait.h>
 #include <sys/resource.h>
 
+#include <atalk/logger.h>
 #include <atalk/adouble.h>
-
-#include <netatalk/at.h>
 #include <atalk/compat.h>
 #include <atalk/dsi.h>
-#include <atalk/atp.h>
-#include <atalk/asp.h>
 #include <atalk/afp.h>
 #include <atalk/paths.h>
 #include <atalk/util.h>
 #include <atalk/server_child.h>
 #include <atalk/server_ipc.h>
+#include <atalk/errchk.h>
 #include <atalk/globals.h>
 
 #include "afp_config.h"
@@ -56,6 +52,7 @@ static char **argv = NULL;
 
 unsigned char  nologin = 0;
 struct afp_options default_options;
+
 static AFPConfig *configs;
 static server_child *server_children;
 static sig_atomic_t reloadconfig = 0;
@@ -133,11 +130,7 @@ static void fd_reset_listening_sockets(void)
 /* ------------------ */
 static void afp_goaway(int sig)
 {
-        AFPConfig *config;
-
-#ifndef NO_DDP
-    asp_kill(sig);
-#endif /* ! NO_DDP */
+    AFPConfig *config;
 
     switch( sig ) {
 
@@ -393,9 +386,9 @@ int main(int ac, char **av)
     }
     pthread_sigmask(SIG_UNBLOCK, &sigs, NULL);
 
-    /* Register CNID  */
+    /* Initialize */
     cnid_init();
-
+    
     /* watch atp, dsi sockets and ipc parent/child file descriptor. */
 
     if (default_options.flags & OPTION_KEEPSESSIONS) {
index cb2b60ed0c15e5bd63bb0cb1ca1c66e7a02089ba..e4cbd311d9022094e6f74a109cbc91e509a55e73 100644 (file)
@@ -30,7 +30,7 @@ static size_t mangle_extension(const struct vol *vol, const char* uname,
   char *p = strrchr(uname, '.');
 
   if (p && p != uname) {
-    u_int16_t flags = CONV_FORCE | CONV_UNESCAPEHEX;
+    uint16_t flags = CONV_FORCE | CONV_UNESCAPEHEX;
     size_t len = convert_charset(vol->v_volcharset, charset,
                                 vol->v_maccharset, p, strlen(p),
                                 extension, MAX_EXT_LENGTH, &flags);
@@ -42,7 +42,7 @@ static size_t mangle_extension(const struct vol *vol, const char* uname,
 
 static char *demangle_checks(const struct vol *vol, char* uname, char * mfilename, size_t prefix, char * ext)
 {
-    u_int16_t flags;
+    uint16_t flags;
     static char buffer[MAXPATHLEN +2];  /* for convert_charset dest_len parameter +2 */
     size_t len;
     size_t mfilenamelen;
@@ -136,7 +136,7 @@ private_demangle(const struct vol *vol, char *mfilename, cnid_t did, cnid_t *osx
 {
     char *t;
     char *u_name;
-    u_int32_t id, file_id;
+    uint32_t id, file_id;
     static char buffer[12 + MAXPATHLEN + 1];
     int len = 12 + MAXPATHLEN + 1;
     struct dir *dir;
@@ -266,7 +266,7 @@ mangle(const struct vol *vol, char *filename, size_t filenamelen, char *uname, c
     k = sprintf(mangle_suffix, "%c%X", MANGLE_CHAR, ntohl(id));
 
     if (filenamelen + k + ext_len > maxlen) {
-      u_int16_t opt = CONV_FORCE | CONV_UNESCAPEHEX;
+      uint16_t opt = CONV_FORCE | CONV_UNESCAPEHEX;
       size_t n = convert_charset(vol->v_volcharset,
                                 (flags & 2) ? CH_UTF8_MAC : vol->v_maccharset,
                                 vol->v_maccharset, uname, strlen(uname),
index 2784e8260280ee20e3af9298dd903decb2e3c75b..ba72e38206dd0aa7d06c20a49c3111b0cf1b5e15 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: messages.c,v 1.23 2009-11-24 15:44:40 didg Exp $
- *
  * Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu)
  * All Rights Reserved.  See COPYRIGHT.
  */
@@ -9,9 +7,7 @@
 #include "config.h"
 #endif /* HAVE_CONFIG_H */
 
-#ifdef HAVE_UNISTD_H
 #include <unistd.h>
-#endif /* HAVE_UNISTD_H */
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
@@ -46,7 +42,7 @@ void readmessage(AFPObj *obj)
     int rc;
     static int c;
     uid_t euid;
-    u_int32_t maxmsgsize;
+    uint32_t maxmsgsize;
 
     maxmsgsize = (obj->proto == AFPPROTO_DSI)?MIN(MAX(((DSI*)obj->handle)->attn_quantum, MAXMESGSIZE),MAXPATHLEN):MAXMESGSIZE;
 
@@ -117,8 +113,8 @@ void readmessage(AFPObj *obj)
 int afp_getsrvrmesg(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbuflen)
 {
     char *message;
-    u_int16_t type, bitmap;
-    u_int16_t msgsize;
+    uint16_t type, bitmap;
+    uint16_t msgsize;
     size_t outlen = 0;
     size_t msglen = 0;
     int utf8 = 0;
index 9f3d70bfc71df244b58189f45ab5c5f5854cdb82..b18826df7be9cb2907672161f5ce0ca38df362cb 100644 (file)
@@ -1,11 +1,6 @@
-/*
- * $Id: misc.h,v 1.5 2009-10-15 10:43:13 didg Exp $
- */
-
 #ifndef AFPD_MISC_H
 #define AFPD_MISC_H 1
 
-#include <sys/cdefs.h>
 #include <atalk/globals.h>
 
 /* FP functions */
index 28e61695722f402dc6bb1e8c806d62da60be3243..b250c16633991d0a6a36a365f1cd48c585220bdb 100644 (file)
 
 #if !defined(NO_QUOTA_SUPPORT) && !defined(HAVE_LIBQUOTA)
 #include <stdio.h>
-/* STDC check */
-#if STDC_HEADERS
 #include <string.h>
-#else /* STDC_HEADERS */
-#ifndef HAVE_STRCHR
-#define strchr index
-#define strrchr index
-#endif /* HAVE_STRCHR */
-char *strchr (), *strrchr ();
-#ifndef HAVE_MEMCPY
-#define memcpy(d,s,n) bcopy ((s), (d), (n))
-#define memmove(d,s,n) bcopy ((s), (d), (n))
-#endif /* ! HAVE_MEMCPY */
-#endif /* STDC_HEADERS */
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/param.h> /* for DEV_BSIZE */
@@ -104,7 +91,7 @@ callaurpc(struct vol *vol,
 #define GQR_RQUOTA getquota_rslt_u.gqr_rquota
 #endif /* USE_OLD_RQUOTA */
 
-int getnfsquota(struct vol *vol, const int uid, const u_int32_t bsize,
+int getnfsquota(struct vol *vol, const int uid, const uint32_t bsize,
                 struct dqblk *dqp)
 {
 
index 2d2600895cb5cc37a730a84a5bb1bdb1b9c6380e..2a8c5443705375d3a763929788bbf6d5afc8a88d 100644 (file)
@@ -62,22 +62,6 @@ static void of_unhash(struct ofork *of)
     }
 }
 
-#ifdef DEBUG1
-void of_pforkdesc( FILE *f)
-{
-    int ofrefnum;
-
-    if (!oforks)
-        return;
-
-    for ( ofrefnum = 0; ofrefnum < nforks; ofrefnum++ ) {
-        if ( oforks[ ofrefnum ] != NULL ) {
-            fprintf( f, "%hu <%s>\n", ofrefnum, of_name(oforks[ ofrefnum ]));
-        }
-    }
-}
-#endif
-
 int of_flush(const struct vol *vol)
 {
     int refnum;
@@ -131,13 +115,13 @@ struct ofork *
 of_alloc(struct vol *vol,
          struct dir    *dir,
          char      *path,
-         u_int16_t     *ofrefnum,
+         uint16_t     *ofrefnum,
          const int      eid,
          struct adouble *ad,
          struct stat    *st)
 {
     struct ofork        *of;
-    u_int16_t       refnum, of_refnum;
+    uint16_t       refnum, of_refnum;
 
     int         i;
 
@@ -202,7 +186,7 @@ of_alloc(struct vol *vol,
 
         /* initialize to zero. This is important to ensure that
            ad_open really does reinitialize the structure. */
-        ad_init(ad, vol->v_adouble, vol->v_ad_options);
+        ad_init(ad, vol);
 
         ad->ad_m_namelen = UTF8FILELEN_EARLY +1;
         /* here's the deal: we allocate enough for the standard mac file length.
@@ -219,7 +203,7 @@ of_alloc(struct vol *vol,
     } else {
         /* Increase the refcount on this struct adouble. This is
            decremented again in oforc_dealloc. */
-        ad->ad_refcount++;
+        ad_ref(ad);
     }
 
     of->of_ad = ad;
@@ -239,7 +223,7 @@ of_alloc(struct vol *vol,
     return( of );
 }
 
-struct ofork *of_find(const u_int16_t ofrefnum )
+struct ofork *of_find(const uint16_t ofrefnum )
 {
     if (!oforks || !nforks)
         return NULL;
@@ -458,7 +442,7 @@ struct adouble *of_ad(const struct vol *vol, struct path *path, struct adouble *
     if ((of = of_findname(path))) {
         adp = of->of_ad;
     } else {
-        ad_init(ad, vol->v_adouble, vol->v_ad_options);
+        ad_init(ad, vol);
         adp = ad;
     }
     return adp;
index 577ddab795961a2fd35be68614ba9745ba20011f..1df5eee51d2f74195bd43d12358f6a986aaa3c9e 100644 (file)
 #include <string.h>
 #include <errno.h>
 #include <sys/types.h>
-/* STDC check */
-#if STDC_HEADERS
 #include <string.h>
-#else /* STDC_HEADERS */
-#ifndef HAVE_STRCHR
-#define strchr index
-#define strrchr index
-#endif /* HAVE_STRCHR */
-char *strchr (), *strrchr ();
-#ifndef HAVE_MEMCPY
-#define memcpy(d,s,n) bcopy ((s), (d), (n))
-#define memmove(d,s,n) bcopy ((s), (d), (n))
-#endif /* ! HAVE_MEMCPY */
-#endif /* STDC_HEADERS */
 #include <sys/stat.h>
 #include <sys/time.h>
 #include <sys/param.h>
-#ifdef HAVE_UNISTD_H
 #include <unistd.h>
-#endif /* HAVE_UNISTD_H */
-#ifdef HAVE_FCNTL_H
 #include <fcntl.h>
-#endif /* HAVE_FCNTL_H */
 
 #include <atalk/logger.h>
 #include <atalk/afp.h>
@@ -292,13 +275,13 @@ static int get_linux_xfs_quota(int what, char *path, uid_t euser_id, struct dqbl
        if ((ret = quotactl(QCMD(Q_XGETQUOTA,(what ? GRPQUOTA : USRQUOTA)), path, euser_id, (caddr_t)&D)))
                return ret;
 
-       dqb->bsize = (u_int64_t)512;
-        dqb->dqb_bsoftlimit  = (u_int64_t)D.d_blk_softlimit;
-        dqb->dqb_bhardlimit  = (u_int64_t)D.d_blk_hardlimit;
-        dqb->dqb_ihardlimit  = (u_int64_t)D.d_ino_hardlimit;
-        dqb->dqb_isoftlimit  = (u_int64_t)D.d_ino_softlimit;
-        dqb->dqb_curinodes   = (u_int64_t)D.d_icount;
-        dqb->dqb_curblocks   = (u_int64_t)D.d_bcount; 
+       dqb->bsize = (uint64_t)512;
+        dqb->dqb_bsoftlimit  = (uint64_t)D.d_blk_softlimit;
+        dqb->dqb_bhardlimit  = (uint64_t)D.d_blk_hardlimit;
+        dqb->dqb_ihardlimit  = (uint64_t)D.d_ino_hardlimit;
+        dqb->dqb_isoftlimit  = (uint64_t)D.d_ino_softlimit;
+        dqb->dqb_curinodes   = (uint64_t)D.d_icount;
+        dqb->dqb_curblocks   = (uint64_t)D.d_bcount; 
 #endif
        return ret;
 }
@@ -607,12 +590,12 @@ static int getfsquota(struct vol *vol, const int uid, struct dqblk *dq)
     if( 
         /* if overquota, free space is 0 otherwise hard-current */
         ( overquota( dq ) ? 0 : ( dq->dqb_bhardlimit ? dq->dqb_bhardlimit - 
-                                  dq->dqb_curblocks : ~((u_int64_t) 0) ) )
+                                  dq->dqb_curblocks : ~((uint64_t) 0) ) )
 
       >
         
         ( overquota( &dqg ) ? 0 : ( dqg.dqb_bhardlimit ? dqg.dqb_bhardlimit - 
-                                    dqg.dqb_curblocks : ~((u_int64_t) 0) ) )
+                                    dqg.dqb_curblocks : ~((uint64_t) 0) ) )
 
       ) /* if */
     {
@@ -632,7 +615,7 @@ static int getfsquota(struct vol *vol, const int uid, struct dqblk *dq)
 }
 
 
-static int getquota( struct vol *vol, struct dqblk *dq, const u_int32_t bsize)
+static int getquota( struct vol *vol, struct dqblk *dq, const uint32_t bsize)
 {
     char *p;
 
@@ -770,9 +753,9 @@ static int overquota( struct dqblk *dqblk)
 #define tobytes(a, b)  dbtob((VolSpace) (a))
 #endif
 
-int uquota_getvolspace( struct vol *vol, VolSpace *bfree, VolSpace *btotal, const u_int32_t bsize)
+int uquota_getvolspace( struct vol *vol, VolSpace *bfree, VolSpace *btotal, const uint32_t bsize)
 {
-       u_int64_t this_bsize;
+       uint64_t this_bsize;
        struct dqblk dqblk;
 
        this_bsize = bsize;
index acb363a3e9d4ef8ecb9076e79ab93894b0ffce2e..897af8dc21abc0e4d80b1ab20c13dd1b59399d92 100644 (file)
 #endif /* BSD4_4 */
 #endif
 
-#include <netatalk/at.h>
-#include <netatalk/endian.h>
+#include <arpa/inet.h>
+
 #include <atalk/dsi.h>
-#include <atalk/atp.h>
-#include <atalk/asp.h>
-#include <atalk/nbp.h>
 #include <atalk/unicode.h>
 #include <atalk/util.h>
 #include <atalk/globals.h>
@@ -77,7 +74,7 @@ static int status_server(char *data, const char *server, const struct afp_option
     char                *start = data;
     char                *Obj, *Type, *Zone;
     char               buf[32];
-    u_int16_t           status;
+    uint16_t           status;
     size_t             len;
 
     /* make room for all offsets before server name */
@@ -85,9 +82,6 @@ static int status_server(char *data, const char *server, const struct afp_option
 
     /* extract the obj part of the server */
     Obj = (char *) server;
-#ifndef NO_DDP
-    nbp_name(server, &Obj, &Type, &Zone);
-#endif
     if ((size_t)-1 == (len = convert_string( 
                            options->unixcharset, options->maccharset, 
                            Obj, -1, buf, sizeof(buf))) ) {
@@ -125,7 +119,7 @@ static int status_server(char *data, const char *server, const struct afp_option
 static void status_machine(char *data)
 {
     char                *start = data;
-    u_int16_t           status;
+    uint16_t           status;
     int                        len;
 #ifdef AFS
     const char         *machine = "afs";
@@ -160,11 +154,11 @@ static void status_machine(char *data)
 }
 
 /* server signature is a 16-byte quantity */
-static u_int16_t status_signature(char *data, int *servoffset,
+static uint16_t status_signature(char *data, int *servoffset,
                                   const struct afp_options *options)
 {
     char                 *status;
-    u_int16_t            offset, sigoff;
+    uint16_t            offset, sigoff;
 
     status = data;
 
@@ -187,14 +181,11 @@ static u_int16_t status_signature(char *data, int *servoffset,
 }
 
 static size_t status_netaddress(char *data, int *servoffset,
-#ifndef NO_DDP
-                                const ASP asp,
-#endif
-                                const DSI *dsi,
-                                const struct afp_options *options)
+                             const DSI *dsi,
+                             const struct afp_options *options)
 {
     char               *begin;
-    u_int16_t          offset;
+    uint16_t          offset;
     size_t             addresses_len = 0;
 
     begin = data;
@@ -215,9 +206,6 @@ static size_t status_netaddress(char *data, int *servoffset,
        connection, but we don't have the ip address. to get around this,
        we turn off the status flag for tcp/ip. */
     *data++ = ((options->fqdn && dsi)? 1 : 0) + (dsi ? 1 : 0) +
-#ifndef NO_DDP
-        (asp ? 1 : 0) +
-#endif
               (((options->flags & OPTION_ANNOUNCESSH) && options->fqdn && dsi)? 1 : 0);
 
     /* ip address */
@@ -291,23 +279,6 @@ static size_t status_netaddress(char *data, int *servoffset,
         }
     }
 
-#ifndef NO_DDP
-    if (asp) {
-        const struct sockaddr_at *ddpaddr = atp_sockaddr(asp->asp_atp);
-
-        /* ddp address */
-        *data++ = 6;
-        *data++ = 0x03; /* ddp address */
-        memcpy(data, &ddpaddr->sat_addr.s_net, sizeof(ddpaddr->sat_addr.s_net));
-        data += sizeof(ddpaddr->sat_addr.s_net);
-        memcpy(data, &ddpaddr->sat_addr.s_node,
-               sizeof(ddpaddr->sat_addr.s_node));
-        data += sizeof(ddpaddr->sat_addr.s_node);
-        memcpy(data, &ddpaddr->sat_port, sizeof(ddpaddr->sat_port));
-        data += sizeof(ddpaddr->sat_port);
-    }
-#endif /* ! NO_DDP */
-
     /* calculate/store Directory Services Names offset */
     offset = htons(data - begin); 
     *servoffset += sizeof(offset);
@@ -322,7 +293,7 @@ static size_t status_directorynames(char *data, int *diroffset,
                                 const struct afp_options *options)
 {
     char *begin = data;
-    u_int16_t offset;
+    uint16_t offset;
     memcpy(&offset, data + *diroffset, sizeof(offset));
     offset = ntohs(offset);
     data += offset;
@@ -362,9 +333,9 @@ static size_t status_directorynames(char *data, int *diroffset,
     }
 
     /* Calculate and store offset for UTF8ServerName */
-    *diroffset += sizeof(u_int16_t);
+    *diroffset += sizeof(uint16_t);
     offset = htons(data - begin);
-    memcpy(begin + *diroffset, &offset, sizeof(u_int16_t));
+    memcpy(begin + *diroffset, &offset, sizeof(uint16_t));
 
     /* return length of buffer */
     return (data - begin);
@@ -375,10 +346,10 @@ static size_t status_utf8servername(char *data, int *nameoffset,
                                 const struct afp_options *options)
 {
     char *Obj, *Type, *Zone;
-    u_int16_t namelen;
+    uint16_t namelen;
     size_t len;
     char *begin = data;
-    u_int16_t offset, status;
+    uint16_t offset, status;
 
     memcpy(&offset, data + *nameoffset, sizeof(offset));
     offset = ntohs(offset);
@@ -394,25 +365,21 @@ static size_t status_utf8servername(char *data, int *nameoffset,
 
     /* extract the obj part of the server */
     Obj = (char *) (options->server ? options->server : options->hostname);
-#ifndef NO_DDP
-    nbp_name(options->server ? options->server : options->hostname, &Obj, &Type, &Zone);
-#endif
     if ((size_t) -1 == (len = convert_string (
-                                       options->unixcharset, CH_UTF8_MAC, 
-                                       Obj, -1, data+sizeof(namelen), maxstatuslen-offset )) ) {
-       LOG ( log_error, logtype_afpd, "Could not set utf8 servername");
+                            options->unixcharset, CH_UTF8_MAC, 
+                            Obj, -1, data+sizeof(namelen), maxstatuslen-offset )) ) {
+        LOG ( log_error, logtype_afpd, "Could not set utf8 servername");
 
-       /* set offset to 0 */
-       memset(begin + *nameoffset, 0, sizeof(offset));
+        /* set offset to 0 */
+        memset(begin + *nameoffset, 0, sizeof(offset));
         data = begin + offset;
-    }
-    else {
+    } else {
        namelen = htons(len);
        memcpy( data, &namelen, sizeof(namelen));
        data += sizeof(namelen);
        data += len;
        offset = htons(offset);
-       memcpy(begin + *nameoffset, &offset, sizeof(u_int16_t));
+       memcpy(begin + *nameoffset, &offset, sizeof(uint16_t));
     }
 
     /* return length of buffer */
@@ -426,7 +393,7 @@ static void status_icon(char *data, const unsigned char *icondata,
 {
     char                *start = data;
     char                *sigdata = data + sigoffset;
-    u_int16_t          ret, status;
+    uint16_t           ret, status;
 
     memcpy(&status, start + AFPSTATUS_ICONOFF, sizeof(status));
     if ( icondata == NULL ) {
@@ -446,28 +413,16 @@ static void status_icon(char *data, const unsigned char *icondata,
 
 /* ---------------------
  */
-void status_init(AFPConfig *aspconfig, AFPConfig *dsiconfig,
+void status_init(AFPConfig *dsiconfig,
                  const struct afp_options *options)
 {
-#ifndef NO_DDP
-    ASP asp;
-#endif
     DSI *dsi;
     char *status = NULL;
     size_t statuslen;
     int c, sigoff, ipok;
 
-    if (!(aspconfig || dsiconfig) || !options)
+    if (!dsiconfig || !options)
         return;
-
-#ifndef NO_DDP
-    if (aspconfig) {
-        status = aspconfig->status;
-        maxstatuslen=sizeof(aspconfig->status);
-        asp = aspconfig->obj.handle;
-    } else
-        asp = NULL;
-#endif
        
     ipok = 0;
     if (dsiconfig) {
@@ -519,11 +474,7 @@ void status_init(AFPConfig *aspconfig, AFPConfig *dsiconfig,
     c = status_server(status, options->server ? options->server :
                       options->hostname, options);
     status_machine(status);
-    status_versions(status,
-#ifndef NO_DDP
-                    asp,
-#endif
-                    dsi);
+    status_versions(status, dsi);
     status_uams(status, options->uamlist);
     if (options->flags & OPTION_CUSTOMICON)
         status_icon(status, icon, sizeof(icon), c);
@@ -533,11 +484,7 @@ void status_init(AFPConfig *aspconfig, AFPConfig *dsiconfig,
     sigoff = status_signature(status, &c, options);
     /* c now contains the offset where the netaddress offset lives */
 
-    status_netaddress(status, &c,
-#ifndef NO_DDP
-                      asp,
-#endif
-                      dsi, options);
+    status_netaddress(status, &c, dsi, options);
     /* c now contains the offset where the Directory Names Count offset lives */
 
     statuslen = status_directorynames(status, &c, dsi, options);
@@ -546,16 +493,6 @@ void status_init(AFPConfig *aspconfig, AFPConfig *dsiconfig,
     if ( statuslen < maxstatuslen) 
         statuslen = status_utf8servername(status, &c, dsi, options);
 
-#ifndef NO_DDP
-    if (aspconfig) {
-        if (dsiconfig) /* status is dsiconfig->status */
-            memcpy(aspconfig->status, status, statuslen);
-        asp_setstatus(asp, status, statuslen);
-        aspconfig->signature = status + sigoff;
-        aspconfig->statuslen = statuslen;
-    }
-#endif /* ! NO_DDP */
-
     if (dsiconfig) {
         if ((options->flags & OPTION_CUSTOMICON) == 0) {
             status_icon(status, apple_tcp_icon, sizeof(apple_tcp_icon), 0);
index 17753f95c77211a78a987f3621101272ee5cd3e2..1a1365e3dc678e8b493e8a9896baca7babc794ea 100644 (file)
@@ -1,9 +1,7 @@
 #ifndef AFPD_STATUS_H
 #define AFPD_STATUS_H 1
 
-#include <sys/cdefs.h>
 #include <atalk/dsi.h>
-#include <atalk/asp.h>
 #include <atalk/globals.h>
 
 #include "afp_config.h"
 #define PASSWD_NOSAVE  (1 << 1)
 #define PASSWD_ALL     (PASSWD_SET | PASSWD_NOSAVE)
 
-extern void status_versions (char * /*status*/,
-#ifndef NO_DDP
-                             const ASP,
-#endif
-                             const DSI *);
+extern void status_versions (char * /*status*/, const DSI *);
 extern void status_uams (char * /*status*/, const char * /*authlist*/);
-extern void status_init (AFPConfig *, AFPConfig *,
-                                 const struct afp_options *);
+extern void status_init (AFPConfig *, const struct afp_options *);
 extern void set_signature(struct afp_options *);
 
 /* FP functions */
index 7a1c034e317ab6119042f405650ab9678f2d36bf..de0fae7ceb0aec7e34c50a106eaaa38086fa5a92 100644 (file)
 
 #include <stdio.h>
 #include <stdlib.h>
-
-/* STDC check */
-#if STDC_HEADERS
 #include <string.h>
-#else /* STDC_HEADERS */
-#ifndef HAVE_STRCHR
-#define strchr index
-#define strrchr index
-#endif /* HAVE_STRCHR */
-char *strchr (), *strrchr ();
-#ifndef HAVE_MEMCPY
-#define memcpy(d,s,n) bcopy ((s), (d), (n))
-#define memmove(d,s,n) bcopy ((s), (d), (n))
-#endif /* ! HAVE_MEMCPY */
-#endif /* STDC_HEADERS */
-
-#ifdef HAVE_UNISTD_H
 #include <unistd.h>
-#endif /* HAVE_UNISTD_H */
-#ifdef HAVE_FCNTL_H
 #include <fcntl.h>
-#endif /* HAVE_FCNTL_H */
 #include <ctype.h>
 #include <atalk/logger.h>
 #include <sys/param.h>
@@ -45,8 +26,6 @@ char *strchr (), *strrchr ();
 #include <netinet/in.h>
 #include <arpa/inet.h>
 
-#include <netatalk/endian.h>
-#include <atalk/asp.h>
 #include <atalk/dsi.h>
 #include <atalk/afp.h>
 #include <atalk/util.h>
@@ -317,7 +296,7 @@ int uam_checkuser(const struct passwd *pwd)
 
 int uam_random_string (AFPObj *obj, char *buf, int len)
 {
-    u_int32_t result;
+    uint32_t result;
     int ret;
     int fd;
 
@@ -359,7 +338,7 @@ int uam_afpserver_option(void *private, const int what, void *option,
 
     switch (what) {
     case UAM_OPTION_USERNAME:
-        *buf = obj->username;
+        *buf = &(obj->username[0]);
         if (len)
             *len = sizeof(obj->username) - 1;
         break;
@@ -487,15 +466,6 @@ int uam_afp_read(void *handle, char *buf, size_t *buflen,
     if (!obj)
         return AFPERR_PARAM;
 
-    switch (obj->proto) {
-#ifndef NO_DDP
-    case AFPPROTO_ASP:
-        if ((len = asp_wrtcont(obj->handle, buf, buflen )) < 0)
-            goto uam_afp_read_err;
-        return action(handle, buf, *buflen);
-        break;
-#endif
-    case AFPPROTO_DSI:
         len = dsi_writeinit(obj->handle, buf, *buflen);
         if (!len || ((len = action(handle, buf, len)) < 0)) {
             dsi_writeflush(obj->handle);
@@ -508,10 +478,6 @@ int uam_afp_read(void *handle, char *buf, size_t *buflen,
                 goto uam_afp_read_err;
             }
         }
-        break;
-    default:
-        return -1;
-    }
     return 0;
 
 uam_afp_read_err:
index 18f010bbb0b81ddebb5c2570a2753e96c3022002..a553ffabff4aaac03c3f787c4e42b77d27c69a39 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: uam_auth.h,v 1.7 2009-10-22 12:35:38 franklahm Exp $
- *
  * Copyright (c) 1999 Adrian Sun (asun@zoology.washington.edu)
  * All Rights Reserved.  See COPYRIGHT.
  *
@@ -10,7 +8,6 @@
 #ifndef AFPD_UAM_AUTH_H
 #define AFPD_UAM_AUTH_H 1
 
-#include <sys/cdefs.h>
 #include <pwd.h>
 
 #include <atalk/uam.h>
index 817ac6590802568e718675b67d954a052838a160..e26e6d1f1b50f702da0fb3ea0d9786937b275e99 100644 (file)
 #include "config.h"
 #endif /* HAVE_CONFIG_H */
 
-/* don't compile this file at all unless FORCE_UIDGID is set */
-#ifdef FORCE_UIDGID
-
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include <atalk/logger.h>
-
-/* functions for username and group */
-#include <pwd.h>
-#include <grp.h>
-#include "uid.h"
-
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
-
-extern uid_t    uuid; 
-
-void save_uidgid ( pair )
-uidgidset *pair;
-{
-    pair->uid = geteuid ();
-    pair->gid = getegid ();
-} 
-
-void restore_uidgid ( pair )
-uidgidset *pair;
-{
-    uid_t uid
-    gid_t gid;   
-    
-    uid = geteuid ();
-    gid = getegid ();
-
-    if (uid == pair->uid && gid == pair->gid)
-       return;
-
-    if (seteuid(0) < 0) {
-        LOG(log_error, logtype_afpd, "set_uidgid: Could not switch back to root: %s",
-                               strerror(errno));
-    }
-
-    if ( setegid ( pair->gid ) < 0 )
-        LOG(log_error, logtype_afpd, "restore_uidgid: unable to setegid '%s': %s",
-            pair->gid, strerror(errno) );
-
-    if ( seteuid ( pair->uid ) < 0 )
-        LOG(log_error, logtype_afpd, "restore_uidgid: unable to seteuid '%s': %s",
-            pair->uid, strerror(errno) );
-    else
-       uuid = pair->uid;       /* ugly hack for utommode */
-}
-
-void set_uidgid ( this_volume )
-const struct vol       *this_volume;
-{
-    int                uid, gid;   /* derived ones go in here */
-
-    /* check to see if we have to switch users */
-    uid = user_to_uid ( (this_volume)->v_forceuid);
-    gid = group_to_gid ( (this_volume)->v_forcegid);
-
-    if ((!uid || uid == geteuid()) && (!gid || gid == getegid()))
-       return;
-
-    if ( seteuid(0) < 0) {
-        LOG(log_error, logtype_afpd, "set_uidgid: Could not switch back to root: %s",
-                               strerror(errno));
-       return;
-    }
-
-    /* check to see if we have to switch groups */
-    if ( gid ) {
-        if ( setegid ( gid ) < 0 )
-            LOG(log_error, logtype_afpd, "set_uidgid: unable to setegid '%s': %s",
-                (this_volume)->v_forcegid, strerror(errno) );
-    } /* end of checking for (this_volume)->v_forcegid */
-
-    if ( uid) {
-        if ( seteuid ( uid ) < 0 )
-            LOG(log_error, logtype_afpd, "set_uidgid: unable to seteuid '%s': %s",
-                (this_volume)->v_forceuid, strerror(errno) );
-       else
-           uuid = uid; /* ugly hack for utommode */
-
-    } /* end of checking for (this_volume)->v_forceuid */
-
-} /* end function void set_uidgid ( username, group ) */
-
-int user_to_uid ( username )
-char   *username;
-{
-    struct passwd *this_passwd;
-
-    /* check for anything */
-    if ( !username || strlen ( username ) < 1 ) return 0;
-
-    /* grab the /etc/passwd record relating to username */
-    this_passwd = getpwnam ( username );
-
-    /* return false if there is no structure returned */
-    if (this_passwd == NULL) return 0;
-
-    /* return proper uid */
-    return this_passwd->pw_uid;
-
-} /* end function int user_to_uid ( username ) */
-
-int group_to_gid ( group )
-char   *group;
-{
-    struct group *this_group;
-
-    /* check for anything */
-    if ( !group || strlen ( group ) < 1 ) return 0;
-
-    /* grab the /etc/groups record relating to group */
-    this_group = getgrnam ( group );
-
-    /* return false if there is no structure returned */
-    if (this_group == NULL) return 0;
-
-    /* return proper gid */
-    return this_group->gr_gid;
-
-} /* end function int group_to_gid ( group ) */
-
-#endif /* FORCE_UIDGID */
index 7f00b20676a73bf74705a0e6cb4dc7d964d6c5e0..647cbd8d164a76182953c420c3650ae773f2a2a2 100644 (file)
@@ -6,20 +6,4 @@
 #ifndef AFPD_UID_H
 #define AFPD_UID_H 1
 
-#ifdef FORCE_UIDGID
-
-/* have to make sure struct vol is defined */
-#include "volume.h"
-
-/* functions to save and restore uid/gid pairs */
-extern void save_uidgid    ( uidgidset * );
-extern void restore_uidgid ( uidgidset * );
-extern void set_uidgid     ( const struct vol * );
-
-/* internal functions to convert user and group names to ids */
-extern int  user_to_uid  ( char * );
-extern int  group_to_gid ( char * );
-
-#endif /* FORCE_UIDGID */
-
 #endif
index cc10d97ba02dbf39e58118eed7b6a4bba75503ec..d692b11cbdab2c9d8e83cd6e622a2a8e49d80e2b 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 #include <inttypes.h>
-
-/* STDC check */
-#ifdef STDC_HEADERS
 #include <string.h>
-#else /* STDC_HEADERS */
-
-#ifndef HAVE_STRCHR
-#define strchr index
-#define strrchr index
-#endif /* HAVE_STRCHR */
-char *strchr (), *strrchr ();
-
-#ifndef HAVE_MEMCPY
-#define memcpy(d,s,n) bcopy ((s), (d), (n))
-#define memmove(d,s,n) bcopy ((s), (d), (n))
-#endif /* ! HAVE_MEMCPY */
-#endif /* STDC_HEADERS */
-
 #include <errno.h>
 #include <limits.h>
 #include <sys/param.h>
@@ -51,7 +34,7 @@ char *strchr (), *strrchr ();
 /*
  * Get the free space on a partition.
  */
-int ustatfs_getvolspace(const struct vol *vol, VolSpace *bfree, VolSpace *btotal, u_int32_t *bsize)
+int ustatfs_getvolspace(const struct vol *vol, VolSpace *bfree, VolSpace *btotal, uint32_t *bsize)
 {
     VolSpace maxVolSpace = UINT64_MAX;
 
@@ -332,9 +315,6 @@ int setfilunixmode (const struct vol *vol, struct path* path, mode_t mode)
 /* --------------------- */
 int setdirunixmode(const struct vol *vol, const char *name, mode_t mode)
 {
-
-    int dropbox = (vol->v_flags & AFPVOL_DROPBOX);
-
     LOG(log_debug, logtype_afpd, "setdirunixmode('%s', mode:%04o) {v_dperm:%04o}",
         fullpathname(name), mode, vol->v_dperm);
 
@@ -342,14 +322,14 @@ int setdirunixmode(const struct vol *vol, const char *name, mode_t mode)
 
     if (dir_rx_set(mode)) {
        /* extending right? dir first then .AppleDouble in rf_setdirmode */
-       if ( stickydirmode(name, DIRBITS | mode, dropbox, vol->v_umask) < 0 )
+       if ( stickydirmode(name, DIRBITS | mode, 0, vol->v_umask) < 0 )
                return -1;
     }
     if (vol->vfs->vfs_setdirunixmode(vol, name, mode, NULL) < 0 && !vol_noadouble(vol)) {
         return  -1 ;
     }
     if (!dir_rx_set(mode)) {
-       if ( stickydirmode(name, DIRBITS | mode, dropbox, vol->v_umask) < 0 )
+       if ( stickydirmode(name, DIRBITS | mode, 0, vol->v_umask) < 0 )
             return -1;
     }
     return 0;
@@ -361,16 +341,12 @@ int setdirmode(const struct vol *vol, const char *name, mode_t mode)
     struct stat                st;
     struct dirent      *dirp;
     DIR                        *dir;
-    mode_t              hf_mode;
-    int                 osx = vol->v_adouble == AD_VERSION2_OSX;
-    int                 dropbox = (vol->v_flags & AFPVOL_DROPBOX);
     
     mode |= vol->v_dperm;
-    hf_mode = ad_hf_mode(mode);
 
     if (dir_rx_set(mode)) {
        /* extending right? dir first */
-       if ( stickydirmode(name, DIRBITS | mode, dropbox, vol->v_umask) < 0 )
+       if ( stickydirmode(name, DIRBITS | mode, 0, vol->v_umask) < 0 )
                return -1;
     }
     
@@ -381,7 +357,7 @@ int setdirmode(const struct vol *vol, const char *name, mode_t mode)
 
     for ( dirp = readdir( dir ); dirp != NULL; dirp = readdir( dir )) {
         /* FIXME */
-        if ( *dirp->d_name == '.' && (!osx || dirp->d_name[1] != '_')) {
+        if (*dirp->d_name == '.') {
             continue;
         }
         if ( lstat( dirp->d_name, &st ) < 0 ) {
@@ -390,9 +366,7 @@ int setdirmode(const struct vol *vol, const char *name, mode_t mode)
         }
 
         if (!S_ISDIR(st.st_mode)) {
-           int setmode = (osx && *dirp->d_name == '.')?hf_mode:mode;
-
-           if (setfilmode(dirp->d_name, setmode, &st, vol->v_umask) < 0) {
+           if (setfilmode(dirp->d_name, mode, &st, vol->v_umask) < 0) {
                closedir( dir );
                 LOG(log_error, logtype_afpd, "setdirmode: chmod %s: %s",dirp->d_name, strerror(errno) );
                 return -1;
@@ -406,7 +380,7 @@ int setdirmode(const struct vol *vol, const char *name, mode_t mode)
     }
 
     if (!dir_rx_set(mode)) {
-       if ( stickydirmode(name, DIRBITS | mode, dropbox, vol->v_umask) < 0 )
+       if ( stickydirmode(name, DIRBITS | mode, 0, vol->v_umask) < 0 )
                return -1;
     }
     return( 0 );
@@ -511,13 +485,12 @@ int setdirowner(const struct vol *vol, const char *name, const uid_t uid, const
     struct stat                st;
     struct dirent      *dirp;
     DIR                        *dir;
-    int                 osx = vol->v_adouble == AD_VERSION2_OSX;
 
     if (( dir = opendir( name )) == NULL ) {
         return( -1 );
     }
     for ( dirp = readdir( dir ); dirp != NULL; dirp = readdir( dir )) {
-        if ( *dirp->d_name == '.' && (!osx || dirp->d_name[1] != '_')) {
+        if ( *dirp->d_name == '.') {
             continue;
         }
         if ( lstat( dirp->d_name, &st ) < 0 ) {
index 54ebf3d69bfac079b576a6eae4f00edaf757181f..417acb172e1561eff6abf9159a311fd9db4475a9 100644 (file)
@@ -1,14 +1,8 @@
-/*
- * $Id: unix.h,v 1.23 2010-04-12 14:28:47 franklahm Exp $
- */
-
 #ifndef AFPD_UNIX_H
 #define AFPD_UNIX_H
 
-#ifdef HAVE_SYS_CDEFS_H
-#include <sys/cdefs.h>
-#endif /* HAVE_SYS_CDEFS_H */
-#include <netatalk/endian.h>
+#include <arpa/inet.h>
+
 #include "config.h"
 #include "volume.h"
 
@@ -209,12 +203,12 @@ extern long quotactl (unsigned int, const char *, int, caddr_t);
 
 #endif /* linux */
 
-extern int getnfsquota (struct vol *, const int, const u_int32_t,
-                                struct dqblk *);
+extern int getnfsquota (struct vol *, const int, const uint32_t,
+                        struct dqblk *);
 
 #endif /* ! HAVE_LIBQUOTA */
 extern int uquota_getvolspace (struct vol *, VolSpace *, VolSpace *,
-                                       const u_int32_t);
+                               const uint32_t);
 #endif /* NO_QUOTA_SUPPORT */
 
 extern struct afp_options default_options;
index 50bafbe55b555e5aa0d12d89721a714b7d344879..716387925373fb38e0c7d69515318e39505a63b1 100644 (file)
 #include <grp.h>
 #include <utime.h>
 #include <errno.h>
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif
-/* STDC check */
-#if STDC_HEADERS
 #include <string.h>
-#else /* STDC_HEADERS */
-#ifndef HAVE_STRCHR
-#define strchr index
-#define strrchr index
-#endif /* HAVE_STRCHR */
-char *strchr (), *strrchr ();
-#ifndef HAVE_MEMCPY
-#define memcpy(d,s,n) bcopy ((s), (d), (n))
-#define memmove(d,s,n) bcopy ((s), (d), (n))
-#endif /* ! HAVE_MEMCPY */
-#endif /* STDC_HEADERS */
 #include <sys/param.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -38,7 +22,6 @@ char *strchr (), *strrchr ();
 #include <inttypes.h>
 #include <time.h>
 
-#include <atalk/asp.h>
 #include <atalk/dsi.h>
 #include <atalk/adouble.h>
 #include <atalk/afp.h>
@@ -47,6 +30,7 @@ char *strchr (), *strrchr ();
 #include <atalk/logger.h>
 #include <atalk/vfs.h>
 #include <atalk/uuid.h>
+#include <atalk/ea.h>
 #include <atalk/bstrlib.h>
 #include <atalk/bstradd.h>
 #include <atalk/ftw.h>
@@ -81,7 +65,7 @@ extern int afprun(int root, char *cmd, int *outfd);
 struct vol *current_vol;        /* last volume from getvolbyvid() */
 
 static struct vol *Volumes = NULL;
-static u_int16_t    lastvid = 0;
+static uint16_t    lastvid = 0;
 static char     *Trash = "\02\024Network Trash Folder";
 
 static struct extmap    *Extmap = NULL, *Defextmap = NULL;
@@ -107,15 +91,7 @@ static void             free_extmap(void);
 #define VOLOPT_MACCHARSET    16
 #define VOLOPT_CNIDSCHEME    17
 #define VOLOPT_ADOUBLE       18  /* adouble version */
-
-#ifdef FORCE_UIDGID
-#warning UIDGID
-#include "uid.h"
-
-#define VOLOPT_FORCEUID      19  /* force uid for username x */
-#define VOLOPT_FORCEGID      20  /* force gid for group x */
-#endif /* FORCE_UIDGID */
-
+/* Usable slot: 19/20 */
 #define VOLOPT_UMASK         21
 #define VOLOPT_ALLOWED_HOSTS 22
 #define VOLOPT_DENIED_HOSTS  23
@@ -147,12 +123,7 @@ typedef struct _special_folder {
 
 static const _special_folder special_folders[] = {
     {"Network Trash Folder",     1,  0777,  1},
-    {"Temporary Items",          1,  0777,  1},
     {".AppleDesktop",            1,  0777,  0},
-#if 0
-    {"TheFindByContentFolder",   0,     0,  1},
-    {"TheVolumeSettingsFolder",  0,     0,  1},
-#endif
     {NULL, 0, 0, 0}};
 
 /* Forward declarations */
@@ -266,25 +237,12 @@ static char *volxlate(AFPObj *obj,
         } else if (is_var(p, "$c")) {
             if (afpmaster && xlatevolname)
                 return NULL;
-#ifndef NO_DDP
-            if (obj->proto == AFPPROTO_ASP) {
-                ASP asp = obj->handle;
-
-                len = sprintf(dest, "%u.%u", ntohs(asp->asp_sat.sat_addr.s_net),
-                              asp->asp_sat.sat_addr.s_node);
-                dest += len;
-                destlen -= len;
-
-            }
-#endif
-            if (obj->proto == AFPPROTO_DSI) {
-                DSI *dsi = obj->handle;
-                len = sprintf(dest, "%s:%u",
-                              getip_string((struct sockaddr *)&dsi->client),
-                              getip_port((struct sockaddr *)&dsi->client));
-                dest += len;
-                destlen -= len;
-            }
+            DSI *dsi = obj->handle;
+            len = sprintf(dest, "%s:%u",
+                          getip_string((struct sockaddr *)&dsi->client),
+                          getip_port((struct sockaddr *)&dsi->client));
+            dest += len;
+            destlen -= len;
         } else if (is_var(p, "$d")) {
             if (afpmaster && xlatevolname)
                 return NULL;
@@ -306,19 +264,8 @@ static char *volxlate(AFPObj *obj,
         } else if (is_var(p, "$i")) {
             if (afpmaster && xlatevolname)
                 return NULL;
-#ifndef NO_DDP
-            if (obj->proto == AFPPROTO_ASP) {
-                ASP asp = obj->handle;
-                len = sprintf(dest, "%u", ntohs(asp->asp_sat.sat_addr.s_net));
-                dest += len;
-                destlen -= len;
-
-            }
-#endif
-            if (obj->proto == AFPPROTO_DSI) {
-                DSI *dsi = obj->handle;
-                q = getip_string((struct sockaddr *)&dsi->client);
-            }
+            DSI *dsi = obj->handle;
+            q = getip_string((struct sockaddr *)&dsi->client);
         } else if (is_var(p, "$s")) {
             if (obj->Obj)
                 q = obj->Obj;
@@ -447,16 +394,10 @@ static void volset(struct vol_option *options, struct vol_option *save,
         else if (strcasecmp(val + 1, "xlateupper") == 0)
             options[VOLOPT_CASEFOLD].i_value = AFPVOL_ULOWERMUPPER;
     } else if (optionok(tmp, "adouble:", val)) {
-        if (strcasecmp(val + 1, "v1") == 0)
-            options[VOLOPT_ADOUBLE].i_value = AD_VERSION1;
-#if AD_VERSION == AD_VERSION2
-        else if (strcasecmp(val + 1, "v2") == 0)
+        if (strcasecmp(val + 1, "v2") == 0)
             options[VOLOPT_ADOUBLE].i_value = AD_VERSION2;
-        else if (strcasecmp(val + 1, "osx") == 0)
-            options[VOLOPT_ADOUBLE].i_value = AD_VERSION2_OSX;
-        else if (strcasecmp(val + 1, "sfm") == 0)
-            options[VOLOPT_ADOUBLE].i_value = AD_VERSION1_SFM;
-#endif
+        else if (strcasecmp(val + 1, "ea") == 0)
+            options[VOLOPT_ADOUBLE].i_value = AD_VERSION_EA;
     } else if (optionok(tmp, "options:", val)) {
         char *p;
 
@@ -482,11 +423,6 @@ static void volset(struct vol_option *options, struct vol_option *save,
                 options[VOLOPT_FLAGS].i_value |= AFPVOL_USEDOTS | AFPVOL_INV_DOTS;
             else if (strcasecmp(p, "limitsize") == 0)
                 options[VOLOPT_FLAGS].i_value |= AFPVOL_LIMITSIZE;
-            /* support for either "dropbox" or "dropkludge" */
-            else if (strcasecmp(p, "dropbox") == 0)
-                options[VOLOPT_FLAGS].i_value |= AFPVOL_DROPBOX;
-            else if (strcasecmp(p, "dropkludge") == 0)
-                options[VOLOPT_FLAGS].i_value |= AFPVOL_DROPBOX;
             else if (strcasecmp(p, "nofileid") == 0)
                 options[VOLOPT_FLAGS].i_value |= AFPVOL_NOFILEID;
             else if (strcasecmp(p, "nostat") == 0)
@@ -541,16 +477,6 @@ static void volset(struct vol_option *options, struct vol_option *save,
         options[VOLOPT_DFLTPERM].i_value = (int)strtol(val+1, NULL, 8);
     } else if (optionok(tmp, "password:", val)) {
         setoption(options, save, VOLOPT_PASSWORD, val);
-
-#ifdef FORCE_UIDGID
-
-        /* this code allows forced uid/gid per volume settings */
-    } else if (optionok(tmp, "forceuid:", val)) {
-        setoption(options, save, VOLOPT_FORCEUID, val);
-    } else if (optionok(tmp, "forcegid:", val)) {
-        setoption(options, save, VOLOPT_FORCEGID, val);
-
-#endif /* FORCE_UIDGID */
     } else if (optionok(tmp, "root_preexec:", val)) {
         setoption(options, save, VOLOPT_ROOTPREEXEC, val);
 
@@ -612,7 +538,7 @@ static int creatvol(AFPObj *obj, struct passwd *pwd,
     char        tmpname[AFPVOL_U8MNAMELEN+1];
     ucs2_t      u8mtmpname[(AFPVOL_U8MNAMELEN+1)*2], mactmpname[(AFPVOL_MACNAMELEN+1)*2];
     char        suffix[6]; /* max is #FFFF */
-    u_int16_t   flags;
+    uint16_t   flags;
 
     LOG(log_debug, logtype_afpd, "createvol: Volume '%s'", name);
 
@@ -847,19 +773,6 @@ static int creatvol(AFPObj *obj, struct passwd *pwd,
         if ((volume->v_flags & AFPVOL_EILSEQ))
             volume->v_utom_flags |= CONV__EILSEQ;
 
-#ifdef FORCE_UIDGID
-        if (options[VOLOPT_FORCEUID].c_value) {
-            volume->v_forceuid = strdup(options[VOLOPT_FORCEUID].c_value);
-        } else {
-            volume->v_forceuid = NULL; /* set as null so as to return 0 later on */
-        }
-
-        if (options[VOLOPT_FORCEGID].c_value) {
-            volume->v_forcegid = strdup(options[VOLOPT_FORCEGID].c_value);
-        } else {
-            volume->v_forcegid = NULL; /* set as null so as to return 0 later on */
-        }
-#endif
         if (!user) {
             if (options[VOLOPT_PREEXEC].c_value)
                 volume->v_preexec = volxlate(obj, NULL, MAXPATHLEN, options[VOLOPT_PREEXEC].c_value, pwd, path, name);
@@ -1383,10 +1296,6 @@ static void volume_free(struct vol *vol)
     free(vol->v_cnidscheme);
     free(vol->v_dbpath);
     free(vol->v_gvs);
-#ifdef FORCE_UIDGID
-    free(vol->v_forceuid);
-    free(vol->v_forcegid);
-#endif /* FORCE_UIDGID */
     if (vol->v_uuid)
         free(vol->v_uuid);
 }
@@ -1595,11 +1504,11 @@ EC_CLEANUP:
 }
 
 static int getvolspace(struct vol *vol,
-                       u_int32_t *bfree, u_int32_t *btotal,
-                       VolSpace *xbfree, VolSpace *xbtotal, u_int32_t *bsize)
+                       uint32_t *bfree, uint32_t *btotal,
+                       VolSpace *xbfree, VolSpace *xbtotal, uint32_t *bsize)
 {
     int         spaceflag, rc;
-    u_int32_t   maxsize;
+    uint32_t   maxsize;
     VolSpace    used;
 #ifndef NO_QUOTA_SUPPORT
     VolSpace    qfree, qtotal;
@@ -1674,7 +1583,7 @@ void vol_fce_tm_event(void)
  * set volume creation date
  * avoid duplicate, well at least it tries
  */
-static void vol_setdate(u_int16_t id, struct adouble *adp, time_t date)
+static void vol_setdate(uint16_t id, struct adouble *adp, time_t date)
 {
     struct vol  *volume;
     struct vol  *vol = Volumes;
@@ -1693,13 +1602,13 @@ static void vol_setdate(u_int16_t id, struct adouble *adp, time_t date)
 }
 
 /* ----------------------- */
-static int getvolparams( u_int16_t bitmap, struct vol *vol, struct stat *st, char *buf, size_t *buflen)
+static int getvolparams( uint16_t bitmap, struct vol *vol, struct stat *st, char *buf, size_t *buflen)
 {
     struct adouble  ad;
     int         bit = 0, isad = 1;
-    u_int32_t       aint;
+    uint32_t       aint;
     u_short     ashort;
-    u_int32_t       bfree, btotal, bsize;
+    uint32_t       bfree, btotal, bsize;
     VolSpace            xbfree, xbtotal; /* extended bytes */
     char        *data, *nameoff = NULL;
     char                *slash;
@@ -1710,8 +1619,8 @@ static int getvolparams( u_int16_t bitmap, struct vol *vol, struct stat *st, cha
      * For MacOS8.x support we need to create the
      * .Parent file here if it doesn't exist. */
 
-    ad_init(&ad, vol->v_adouble, vol->v_ad_options);
-    if ( ad_open_metadata( vol->v_path, ADFLAGS_DIR, O_CREAT, &ad) < 0 ) {
+    ad_init(&ad, vol);
+    if (ad_open(&ad, vol->v_path, ADFLAGS_HF | ADFLAGS_DIR | ADFLAGS_RDWR | ADFLAGS_CREATE, 0666) != 0 ) {
         isad = 0;
         vol->v_ctime = AD_DATE_FROM_UNIX(st->st_mtime);
 
@@ -1843,28 +1752,20 @@ static int getvolparams( u_int16_t bitmap, struct vol *vol, struct stat *st, cha
 #ifndef NO_LARGE_VOL_SUPPORT
         case VOLPBIT_XBFREE :
             xbfree = hton64( xbfree );
-#if defined(__GNUC__) && defined(HAVE_GCC_MEMCPY_BUG)
-            bcopy(&xbfree, data, sizeof(xbfree));
-#else /* __GNUC__ && HAVE_GCC_MEMCPY_BUG */
             memcpy(data, &xbfree, sizeof( xbfree ));
-#endif /* __GNUC__ && HAVE_GCC_MEMCPY_BUG */
             data += sizeof( xbfree );
             break;
 
         case VOLPBIT_XBTOTAL :
             xbtotal = hton64( xbtotal );
-#if defined(__GNUC__) && defined(HAVE_GCC_MEMCPY_BUG)
-            bcopy(&xbtotal, data, sizeof(xbtotal));
-#else /* __GNUC__ && HAVE_GCC_MEMCPY_BUG */
             memcpy(data, &xbtotal, sizeof( xbtotal ));
-#endif /* __GNUC__ && HAVE_GCC_MEMCPY_BUG */
             data += sizeof( xbfree );
             break;
 #endif /* ! NO_LARGE_VOL_SUPPORT */
 
         case VOLPBIT_NAME :
             nameoff = data;
-            data += sizeof( u_int16_t );
+            data += sizeof( uint16_t );
             break;
 
         case VOLPBIT_BSIZE:  /* block size */
@@ -1896,14 +1797,14 @@ static int getvolparams( u_int16_t bitmap, struct vol *vol, struct stat *st, cha
         data += aint;
     }
     if ( isad ) {
-        ad_close_metadata( &ad);
+        ad_close(&ad, ADFLAGS_HF);
     }
     *buflen = data - buf;
     return( AFP_OK );
 }
 
 /* ------------------------- */
-static int stat_vol(u_int16_t bitmap, struct vol *vol, char *rbuf, size_t *rbuflen)
+static int stat_vol(uint16_t bitmap, struct vol *vol, char *rbuf, size_t *rbuflen)
 {
     struct stat st;
     int     ret;
@@ -2073,8 +1974,8 @@ int afp_getsrvrparms(AFPObj *obj, char *ibuf _U_, size_t ibuflen _U_, char *rbuf
         return AFPERR_PARAM;
     }
     tv.tv_sec = AD_DATE_FROM_UNIX(tv.tv_sec);
-    memcpy(data, &tv.tv_sec, sizeof( u_int32_t));
-    data += sizeof( u_int32_t);
+    memcpy(data, &tv.tv_sec, sizeof( uint32_t));
+    data += sizeof( uint32_t);
     *data = vcnt;
     return( AFP_OK );
 }
@@ -2244,7 +2145,7 @@ int afp_openvol(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t
     struct dir  *dir;
     int     len, ret;
     size_t  namelen;
-    u_int16_t   bitmap;
+    uint16_t   bitmap;
     char        path[ MAXPATHLEN + 1];
     char        *vol_uname;
     char        *vol_mname;
@@ -2299,9 +2200,6 @@ int afp_openvol(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t
 
     if (( volume->v_flags & AFPVOL_OPEN  ) ) {
         /* the volume is already open */
-#ifdef FORCE_UIDGID
-        set_uidgid ( volume );
-#endif
         return stat_vol(bitmap, volume, rbuf, rbuflen);
     }
 
@@ -2312,10 +2210,6 @@ int afp_openvol(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t
         }
     }
 
-#ifdef FORCE_UIDGID
-    set_uidgid ( volume );
-#endif
-
     if (volume->v_preexec) {
         if ((ret = afprun(0, volume->v_preexec, NULL)) && volume->v_preexec_close) {
             LOG(log_error, logtype_afpd, "afp_openvol(%s): preexec : %d", volume->v_path, ret );
@@ -2530,7 +2424,7 @@ static void deletevol(struct vol *vol)
 int afp_closevol(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen)
 {
     struct vol  *vol;
-    u_int16_t   vid;
+    uint16_t   vid;
 
     *rbuflen = 0;
     ibuf += 2;
@@ -2546,7 +2440,7 @@ int afp_closevol(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf _U_
 }
 
 /* ------------------------- */
-struct vol *getvolbyvid(const u_int16_t vid )
+struct vol *getvolbyvid(const uint16_t vid )
 {
     struct vol  *vol;
 
@@ -2559,10 +2453,6 @@ struct vol *getvolbyvid(const u_int16_t vid )
         return( NULL );
     }
 
-#ifdef FORCE_UIDGID
-    set_uidgid ( vol );
-#endif /* FORCE_UIDGID */
-
     current_vol = vol;
 
     return( vol );
@@ -2670,7 +2560,7 @@ void setvoltime(AFPObj *obj, struct vol *vol)
 int afp_getvolparams(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_,char *rbuf, size_t *rbuflen)
 {
     struct vol  *vol;
-    u_int16_t   vid, bitmap;
+    uint16_t   vid, bitmap;
 
     ibuf += 2;
     memcpy(&vid, ibuf, sizeof( vid ));
@@ -2691,8 +2581,8 @@ int afp_setvolparams(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf
 {
     struct adouble ad;
     struct vol  *vol;
-    u_int16_t   vid, bitmap;
-    u_int32_t   aint;
+    uint16_t   vid, bitmap;
+    uint32_t   aint;
 
     ibuf += 2;
     *rbuflen = 0;
@@ -2714,9 +2604,8 @@ int afp_setvolparams(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf
     if (bitmap != (1 << VOLPBIT_BDATE))
         return AFPERR_BITMAP;
 
-    ad_init(&ad, vol->v_adouble, vol->v_ad_options);
-    if ( ad_open( vol->v_path, ADFLAGS_HF|ADFLAGS_DIR, O_RDWR,
-                  0666, &ad) < 0 ) {
+    ad_init(&ad, vol);
+    if ( ad_open(&ad,  vol->v_path, ADFLAGS_HF | ADFLAGS_DIR | ADFLAGS_RDWR) < 0 ) {
         if (errno == EROFS)
             return AFPERR_VLOCK;
 
@@ -2766,7 +2655,7 @@ static int create_special_folder (const struct vol *vol, const struct _special_f
 {
     char        *p,*q,*r;
     struct adouble  ad;
-    u_int16_t   attr;
+    uint16_t   attr;
     struct stat st;
     int     ret;
 
@@ -2810,9 +2699,9 @@ static int create_special_folder (const struct vol *vol, const struct _special_f
 
     if ( !ret && folder->hide) {
         /* Hide it */
-        ad_init(&ad, vol->v_adouble, vol->v_ad_options);
-        if (ad_open_metadata( p, ADFLAGS_DIR, O_CREAT, &ad) < 0) {
-            free (p);
+        ad_init(&ad, vol);
+        if (ad_open(&ad, p, ADFLAGS_HF | ADFLAGS_DIR | ADFLAGS_RDWR | ADFLAGS_CREATE, 0666) != 0) {
+            free(p);
             free(q);
             return (-1);
         }
@@ -2830,8 +2719,8 @@ static int create_special_folder (const struct vol *vol, const struct _special_f
             memcpy(ad_entry(&ad, ADEID_FINDERI) + FINDERINFO_FRFLAGOFF,&attr, sizeof(attr));
         }
 
-        ad_flush( &ad );
-        ad_close_metadata( &ad);
+        ad_flush(&ad);
+        ad_close(&ad, ADFLAGS_HF);
     }
     free(p);
     free(q);
index eedc622bd275107758b7522e570f6e37eb278b4c..0a9f0f01fedba48e3e23fdc8566bee32c67e281f 100644 (file)
@@ -6,19 +6,18 @@
 #ifndef AFPD_VOLUME_H
 #define AFPD_VOLUME_H 1
 
-#include <sys/cdefs.h>
 #include <sys/types.h>
-#include <netatalk/endian.h>
+#include <arpa/inet.h>
 
 #include <atalk/volume.h>
 #include <atalk/cnid.h>
 #include <atalk/unicode.h>
 #include <atalk/globals.h>
 
-extern struct vol       *getvolbyvid (const u_int16_t);
+extern struct vol       *getvolbyvid (const uint16_t);
 extern int              ustatfs_getvolspace (const struct vol *,
             VolSpace *, VolSpace *,
-            u_int32_t *);
+            uint32_t *);
 extern void             setvoltime (AFPObj *, struct vol *);
 extern int              pollvoltime (AFPObj *);
 extern void             load_volumes (AFPObj *obj);
diff --git a/etc/atalkd/.gitignore b/etc/atalkd/.gitignore
deleted file mode 100644 (file)
index 681f201..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-Makefile
-Makefile.in
-atalkd
-.deps
-.libs
-.gitignore
-aep.o config.o main.o multicast.o nbp.o route.o rtmp.o zip.o
diff --git a/etc/atalkd/Makefile.am b/etc/atalkd/Makefile.am
deleted file mode 100644 (file)
index 098a529..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-# Makefile.am for etc/atalkd/
-
-pkgconfdir = @PKGCONFDIR@
-
-sbin_PROGRAMS = atalkd
-
-atalkd_SOURCES = aep.c config.c main.c multicast.c nbp.c route.c rtmp.c zip.c 
-atalkd_LDADD = $(top_builddir)/libatalk/libatalk.la
-
-noinst_HEADERS =       \
-       atserv.h        \
-       gate.h          \
-       interface.h     \
-       list.h          \
-       main.h          \
-       multicast.h     \
-       nbp.h           \
-       route.h         \
-       rtmp.h          \
-       zip.h
-
-AM_CFLAGS = -D_PATH_ATALKDCONF=\"$(pkgconfdir)/atalkd.conf\"
diff --git a/etc/atalkd/aep.c b/etc/atalkd/aep.c
deleted file mode 100644 (file)
index 6d3ace9..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * $Id: aep.c,v 1.9 2009-10-13 22:55:37 didg Exp $
- *
- * Copyright (c) 1990,1993 Regents of The University of Michigan.
- * All Rights Reserved. See COPYRIGHT.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <string.h>
-#include <errno.h>
-
-#include <atalk/logger.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netatalk/at.h>
-#include <atalk/aep.h>
-#include <atalk/ddp.h>
-
-#include "atserv.h"
-
-int aep_packet(
-    struct atport      *ap,
-    struct sockaddr_at *from,
-    char               *data,
-    int                        len)
-{
-    char               *end;
-
-    end = data + len;
-    if ( data + 2 > end || *data != DDPTYPE_AEP ||
-           *( data + 1 ) != AEPOP_REQUEST ) {
-       LOG(log_info, logtype_atalkd, "aep_packet malformed packet" );
-       return 1;
-    }
-
-    *( data + 1 ) = AEPOP_REPLY;
-    if ( sendto( ap->ap_fd, data, len, 0, (struct sockaddr *)from,
-           sizeof( struct sockaddr_at )) < 0 ) {
-       LOG(log_error, logtype_atalkd, "aep sendto: %s", strerror(errno) );
-       return 1;
-    }
-
-    return 0;
-}
diff --git a/etc/atalkd/atserv.h b/etc/atalkd/atserv.h
deleted file mode 100644 (file)
index 9052ab3..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * $Id: atserv.h,v 1.4 2009-10-13 22:55:37 didg Exp $
- *
- * Copyright (c) 1990,1992 Regents of The University of Michigan.
- * All Rights Reserved. See COPYRIGHT.
- */
-#ifndef ATALKD_ATSERV_H
-#define ATALKD_ATSERV_H 1
-
-struct atport {
-    int                        ap_fd;
-    struct atport      *ap_next;
-    struct interface   *ap_iface;
-    u_char             ap_port;
-    int                        (*ap_packet)(struct atport *ap, struct sockaddr_at *from, char *data, int len);
-};
-
-struct atserv {
-    char       *as_name;
-    u_char     as_port;                /* Used as a fall back */
-    int                (*as_packet)(struct atport *ap, struct sockaddr_at *from, char *data, int len);
-};
-
-#endif
diff --git a/etc/atalkd/config.c b/etc/atalkd/config.c
deleted file mode 100644 (file)
index 4005d69..0000000
+++ /dev/null
@@ -1,880 +0,0 @@
-/*
- * $Id: config.c,v 1.20 2009-10-29 11:35:58 didg Exp $
- *
- * Copyright (c) 1990,1993 Regents of The University of Michigan.
- * All Rights Reserved. See COPYRIGHT.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/socket.h>
-#include <sys/ioctl.h>
-#include <atalk/logger.h>
-#include <sys/param.h>
-#ifdef TRU64
-#include <sys/mbuf.h>
-#include <net/route.h>
-#endif /* TRU64 */
-#include <net/if.h>
-#include <netatalk/at.h>
-#include <netatalk/endian.h>
-#include <atalk/paths.h>
-#include <atalk/util.h>
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <ctype.h>
-
-/* STDC check */
-#if STDC_HEADERS
-#include <string.h>
-#else /* STDC_HEADERS */
-#ifndef HAVE_STRCHR
-#define strchr index
-#define strrchr index
-#endif /* HAVE_STRCHR */
-char *strchr (), *strrchr ();
-#ifndef HAVE_MEMCPY
-#define memcpy(d,s,n) bcopy ((s), (d), (n))
-#define memmove(d,s,n) bcopy ((s), (d), (n))
-#endif /* ! HAVE_MEMCPY */
-#endif /* STDC_HEADERS */
-
-#ifdef HAVE_FCNTL_H
-#include <fcntl.h>
-#endif /* HAVE_FCNTL_H */
-
-#ifdef __svr4__
-#include <sys/sockio.h>
-#include <sys/stropts.h>
-#endif /* __svr4__ */
-
-#include <atalk/unicode.h>
-#include "interface.h"
-#include "multicast.h"
-#include "rtmp.h"
-#include "zip.h"
-#include "list.h"
-#include "main.h"
-
-#ifndef IFF_SLAVE /* a little backward compatibility */
-#define IFF_SLAVE 0
-#endif /* IFF_SLAVE */
-
-int router(struct interface *iface, char **av);
-int dontroute(struct interface *iface, char **av);
-int seed(struct interface *iface, char **av);
-int phase(struct interface *iface, char **av); 
-int net(struct interface *iface, char **av);
-int addr(struct interface *iface, char **av); 
-int zone(struct interface *iface, char **av);
-int noallmulti(struct interface *iface, char **av);
-
-static const struct param {
-    char       *p_name;
-    int                (*p_func)(struct interface *iface, char **av);
-} params[] = {
-    { "router", router },
-    { "dontroute", dontroute },
-    { "seed",  seed },
-    { "phase", phase },
-    { "net",   net },
-    { "addr",  addr },
-    { "zone",  zone },
-    { "noallmulti", noallmulti }
-};
-
-#define ARGV_CHUNK_SIZE 128
-#define MAXLINELEN 2048
-static char **parseline(const char *line)
-{
-    const char  *p;
-    int                  argc = 0;
-    char        *buffer, *tmpbuf;
-    char       **argv;
-
-    /* Ignore empty lines and lines with leading hash marks. */
-    p = line;
-    while ( isspace( *p ) ) {
-       p++;
-    }
-    if ( *p == '#' || *p == '\0' ) {
-       return NULL;
-    }
-
-    buffer = (char *) malloc( strlen( p ) + 1 );
-    if ( !buffer ) {
-       /* FIXME: error handling */
-       return NULL;
-    }
-    strcpy( buffer, p );
-    tmpbuf = buffer;
-
-    argv = (char **) malloc( ARGV_CHUNK_SIZE * sizeof( char * ) );
-    if ( !argv ) {
-       /* FIXME: error handling */
-       free( buffer );
-       return NULL;
-    }
-
-    /*
-     * This parser should be made more powerful -- it should
-     * handle various escapes, e.g. \" and \031.
-     */
-    do {
-       if ( *tmpbuf == '"' ) {
-           argv[ argc++ ] = ++tmpbuf;
-           while ( *tmpbuf != '\0' && *tmpbuf != '"' ) {
-               tmpbuf++;
-           }
-           if ( *tmpbuf == '"' ) {
-               /* FIXME: error handling */
-           }
-       } else {
-           argv[ argc++ ] = tmpbuf;
-           while ( *tmpbuf != '\0' && !isspace( *tmpbuf )) {
-               tmpbuf++;
-           }
-       }
-       *tmpbuf++ = '\0';
-
-       /* Make room for a NULL pointer and our special pointer (s.b.) */
-       if ( (argc + 1) % ARGV_CHUNK_SIZE == 0 ) {
-           char **tmp;
-           tmp = (char **) realloc( argv, argc + 1 + ARGV_CHUNK_SIZE * sizeof( char * ) );
-           if ( !tmp ) {
-               /* FIXME: error handling */
-               free( argv );
-               free( buffer );
-               return NULL;
-           }
-           argv = tmp;
-       }
-
-       /* Skip white spaces. */
-        while ( isspace( *tmpbuf ) ) {
-            tmpbuf++;
-        }
-    } while ( *tmpbuf != '\0' );
-
-    argv[ argc++ ] = NULL;
-    /* We store our buffer pointer in argv, too, so we can free it later.
-     * (But don't tell anyone.)
-     */
-    argv[ argc ] = buffer;
-
-    return argv;
-}
-
-static void freeline( char **argv )
-{
-    char **tmp = argv;
-
-    if ( argv ) {
-       while ( *tmp ) {
-           tmp++;
-       }
-       free( *++tmp );
-       free( argv );
-    }
-}
-
-int writeconf(char *cf)
-{
-    struct stat                st;
-    char               *path, *p, newpath[ MAXPATHLEN ], line[ MAXLINELEN ];
-    char               **argv;
-    FILE               *conf, *newconf;
-    struct interface   *iface;
-    struct list                *l;
-    int                        mode = 0644, fd;
-    size_t             len;
-    char               *zonename;
-
-    if ( cf == NULL ) {
-       path = _PATH_ATALKDCONF;
-    } else {
-       path = cf;
-    }
-
-    /* check if old conf is writable */
-    if ( stat( path, &st ) == 0 ) {
-       if (( st.st_mode & S_IWUSR ) == 0 ) {
-           LOG(log_info, logtype_atalkd, "%s not writable, won't rewrite", path );
-           return( -1 );
-       }
-        mode = st.st_mode;
-    }
-
-    if (( p = strrchr( path, '/' )) == NULL ) {
-       strcpy( newpath, _PATH_ATALKDTMP );
-    } else {
-       sprintf( newpath, "%.*s/%s", (int)(p - path), path, _PATH_ATALKDTMP );
-    }
-    if (( fd = open( newpath, O_WRONLY|O_CREAT|O_TRUNC, mode )) < 0 ) {
-       LOG(log_error, logtype_atalkd, "%s: %s", newpath, strerror(errno) );
-       return( -1 );
-    }
-    if (( newconf = fdopen( fd, "w" )) == NULL ) {
-       LOG(log_error, logtype_atalkd, "fdreopen %s: %s", newpath, strerror(errno) );
-       return( -1 );
-    }
-
-    if (( conf = fopen( path, "r" )) == NULL && cf ) {
-       LOG(log_error, logtype_atalkd, "%s: %s", path, strerror(errno) );
-       return( -1 );
-    }
-
-    iface = interfaces->i_next;
-
-    while ( conf == NULL || fgets( line, sizeof( line ), conf ) != NULL ) {
-       if ( conf != NULL && ( argv = parseline( line )) == NULL ) {
-           if ( fputs( line, newconf ) == EOF ) {
-               LOG(log_error, logtype_atalkd, "fputs: %s", strerror(errno) );
-               return( -1 );
-           }
-           freeline( argv );
-           continue;
-       }
-
-       /* write real lines */
-       if ( iface ) {
-           fprintf( newconf, "%s", iface->i_name );
-           if ( iface->i_flags & IFACE_RSEED ) {
-               fprintf( newconf, " -router" );
-           } else if ( iface->i_flags & IFACE_SEED ) {
-               fprintf( newconf, " -seed" );
-           }
-           if ( iface->i_flags & IFACE_DONTROUTE) {
-               fprintf( newconf, " -dontroute");
-           }
-#ifdef linux
-            if ( !(iface->i_flags & IFACE_ALLMULTI)) {
-               fprintf( newconf, " -noallmulti");
-            }
-#endif
-
-           fprintf( newconf, " -phase %d",
-                   ( iface->i_flags & IFACE_PHASE1 ) ? 1 : 2 );
-           fprintf( newconf, " -net %d", ntohs( iface->i_rt->rt_firstnet ));
-           if ( iface->i_rt->rt_lastnet != iface->i_rt->rt_firstnet ) {
-               fprintf( newconf, "-%d", ntohs( iface->i_rt->rt_lastnet ));
-           }
-           fprintf( newconf, " -addr %u.%u",
-                   ntohs( iface->i_addr.sat_addr.s_net ),
-                   iface->i_addr.sat_addr.s_node );
-           for ( l = iface->i_rt->rt_zt; l; l = l->l_next ) {
-                /* codepage conversion */
-                if ((size_t)(-1) == (len = convert_string_allocate(CH_MAC, CH_UNIX, 
-                                      ((struct ziptab *)l->l_data)->zt_name,
-                                      ((struct ziptab *)l->l_data)->zt_len,
-                                      &zonename)) ) {
-                    if ( NULL == 
-                      (zonename = strdup(((struct ziptab *)l->l_data)->zt_name))) {
-                       LOG(log_error, logtype_atalkd, "malloc: %s",  strerror(errno) );
-                       return( -1 );
-                    }
-                    len = ((struct ziptab *)l->l_data)->zt_len;
-                } 
-               fprintf( newconf, " -zone \"%.*s\"", (int)len, zonename);
-                free(zonename);
-           }
-           fprintf( newconf, "\n" );
-
-           iface = iface->i_next;
-           if ( conf == NULL && iface == NULL ) {
-               break;
-           }
-       }
-    }
-    if ( conf != NULL ) {
-       fclose( conf );
-    }
-    fclose( newconf );
-
-    if ( rename( newpath, path ) < 0 ) {
-       LOG(log_error, logtype_atalkd, "rename %s to %s: %s", newpath, path, strerror(errno) );
-       return( -1 );
-    }
-    return( 0 );
-}
-
-/*
- * Read our config file. If it's not there, return -1. If it is there,
- * but has syntax errors, exit. Format of the file is as follows:
- *
- *     interface [ -seed ] [ -phase number ] [ -net net-range ]
- *     [ -addr net.node ] [ -zone zonename ]...
- * e.g.
- *     le0 -phase 1 -net 7938 -zone Argus
- * or
- *     le0 -phase 2 -net 8043-8044 -zone Argus -zone "Research Systems"
- *     le0 -phase 1 -net 7938 -zone Argus
- *
- * Pretty much everything is optional. Anything that is unspecified is
- * searched for on the network.  If -seed is not specified, the
- * configuration is assumed to be soft, i.e. it can be overridden by
- * another router. If -seed is specified, atalkd will exit if another
- * router disagrees.  If the phase is unspecified, it defaults to phase
- * 2 (the default can be overridden on the command line).  -addr can
- * replace -net, if the network in question isn't a range.  The default
- * zone for an interface is the first zone encountered for that
- * interface.
- */
-int readconf(char *cf)
-{
-    struct ifreq       ifr;
-    struct interface   *iface, *niface;
-    char               line[ MAXLINELEN ], **argv, *p;
-    unsigned int       i, j;
-    int                        s, cc = 0;
-    FILE               *conf;
-
-    if ( cf == NULL ) {
-       p = _PATH_ATALKDCONF;
-    } else {
-       p = cf;
-    }
-    if (( conf = fopen( p, "r" )) == NULL ) {
-        return( -1 );
-    }
-
-#ifndef __svr4__
-    if (( s = socket( AF_APPLETALK, SOCK_DGRAM, 0 )) < 0 ) {
-       perror( "socket" );
-       fclose(conf);
-       return -1;
-    }
-#endif /* __svr4__ */
-
-    while ( fgets( line, sizeof( line ), conf ) != NULL ) {
-       if (( argv = parseline( line )) == NULL ) {
-           continue;
-       }
-
-#ifndef __svr4__
-       /*
-        * Check that av[ 0 ] is a valid interface.
-        * Not possible under sysV.
-        */
-       strlcpy( ifr.ifr_name, argv[ 0 ], sizeof(ifr.ifr_name) );
-
-       /* for devices that don't support appletalk */
-       if ((ioctl(s, SIOCGIFADDR, &ifr) < 0) && (errno == ENODEV)) {
-         perror(argv[0]);
-         goto read_conf_err;
-       }
-
-       if ( ioctl( s, SIOCGIFFLAGS, &ifr ) < 0 ) {
-           perror( argv[ 0 ] );
-           goto read_conf_err;
-       }
-
-       if (ifr.ifr_flags & (IFF_LOOPBACK | IFF_POINTOPOINT |IFF_SLAVE)) {
-           fprintf( stderr, "%s: can't configure.\n", ifr.ifr_name );
-           goto read_conf_err;
-       }
-
-#ifdef IFF_MULTICAST
-       if ((ifr.ifr_flags & IFF_MULTICAST) == 0)
-           fprintf(stderr, "%s: multicast may not work properly.\n",
-                   ifr.ifr_name);
-#endif /* IFF_MULTICAST */
-
-       /* configure hw multicast for this interface. */
-       if (addmulti(ifr.ifr_name, NULL) < 0) {
-         perror(ifr.ifr_name);
-         fprintf(stderr, "Can't configure multicast.\n");
-         goto read_conf_err;
-       }
-
-#endif /* __svr4__ */
-
-       if (( niface = newiface( argv[ 0 ] )) == NULL ) {
-           perror( "newiface" );
-           goto read_conf_err;
-       }
-
-       for ( i = 1; argv[ i ]; i += cc ) {
-           if ( argv[ i ][ 0 ] == '-' ) {
-               argv[ i ]++;
-           }
-           for ( j = 0; j < sizeof( params ) / sizeof( params[ 0 ] ); j++ ) {
-               if ( strcmp( argv[ i ], params[ j ].p_name ) == 0 ) {
-                   if ( params[ j ].p_func != NULL ) {
-                       cc = (*params[ j ].p_func)( niface, &argv[ i + 1 ] );
-                       if (cc < 0) 
-                         goto read_conf_err;
-                       break;
-                   }
-               }
-           }
-           if ( j >= sizeof( params ) / sizeof( params[ 0 ] )) {
-               fprintf( stderr, "%s: attribute not found.\n", argv[ i ] );
-               goto read_conf_err;
-           }
-       }
-
-       for ( iface = interfaces; iface; iface = iface->i_next ) {
-           if ( strcmp( niface->i_name, iface->i_name ) == 0 &&
-                   ((( niface->i_flags & iface->i_flags &
-                   ( IFACE_PHASE1|IFACE_PHASE2 )) != 0 ) ||
-                   niface->i_flags == 0 || iface->i_flags == 0 )) {
-               break;
-           }
-       }
-       if ( iface ) {  /* Already have this interface and phase */
-           fprintf( stderr, "%s already configured!\n", niface->i_name );
-           goto read_conf_err;
-       }
-
-#ifdef linux
-       /* Don't set interface to allmulti if it already is, or -noallmulti was given */
-       if ((ifr.ifr_flags & IFF_ALLMULTI))
-               niface->i_flags |= IFACE_WASALLMULTI; 
-
-       if ((niface->i_flags & IFACE_ALLMULTI) && !(niface->i_flags & IFACE_WASALLMULTI))
-               ifsetallmulti(ifr.ifr_name, 1);
-#endif
-
-       if ( interfaces == NULL ) {
-           interfaces = niface;
-       } else {
-           for ( iface = interfaces; iface->i_next; iface = iface->i_next )
-               ;
-           iface->i_next = niface;
-       }
-       niface->i_next = NULL;
-    }
-
-#ifndef __svr4__
-    close( s );
-#endif /* __svr4__ */
-
-    fclose( conf );
-
-    /*
-     * Note: we've added lo0 to the interface list previously, so we must
-     * have configured more than one interface...
-     */
-    for ( iface = interfaces, cc = 0; iface; iface = iface->i_next, cc++ )
-       ;
-    if ( cc >= IFBASE ) {
-       return( 0 );
-    } else {
-       return( -1 );
-    }
-
-read_conf_err:
-#ifndef __svr4__
-    close(s);
-#endif /* __svr4__ */
-    fclose(conf);
-    return -1;
-}
-
-int noallmulti( struct interface *iface, char **av _U_)
-{
-    /* Linux specific, no effect on other platforms */
-    iface->i_flags &= !IFACE_ALLMULTI;
-
-    return (1);
-}
-       
-/*ARGSUSED*/
-int router(struct interface *iface, char **av _U_)
-{
-    /* make sure "-router" and "-dontroute" aren't both on the same line. */
-    if (iface->i_flags & IFACE_DONTROUTE) {
-       fprintf( stderr, "Can't specify both -router and -dontroute.\n");
-       return -1;
-    }
-
-    /*
-     * Check to be sure "-router" is before "-zone".
-     */
-    if ( iface->i_czt ) {
-       fprintf( stderr, "Must specify -router before -zone.\n");
-       return -1;
-    }
-
-    /* -router also implies -seed */
-    iface->i_flags |= IFACE_RSEED | IFACE_SEED | IFACE_ISROUTER;
-    return( 1 );
-}
-
-/*ARGSUSED*/
-int dontroute(struct interface *iface, char **av _U_)
-{
-    /* make sure "-router" and "-dontroute" aren't both on the same line. */
-    if (iface->i_flags & IFACE_RSEED) {
-       fprintf( stderr, "Can't specify both -router and -dontroute.\n");
-       return -1;
-    }
-
-    iface->i_flags |= IFACE_DONTROUTE;
-    return( 1 );
-}
-
-/*ARGSUSED*/
-int seed( struct interface *iface, char **av _U_)
-{
-    /*
-     * Check to be sure "-seed" is before "-zone". we keep the old
-     * semantics of just ignoring this in a routerless world.
-     */
-    if ( iface->i_czt ) {
-       fprintf( stderr, "Must specify -seed before -zone(%s).\n",
-                iface->i_czt->zt_name);
-       return -1;
-    }
-
-    iface->i_flags |= IFACE_SEED;
-    return( 1 );
-}
-
-int phase(struct interface *iface, char **av)
-{
-    int                        n;
-    char               *pnum;
-
-    if (( pnum = av[ 0 ] ) == NULL ) {
-       fprintf( stderr, "No phase.\n" );
-       return -1;
-    }
-
-    switch ( n = atoi( pnum )) {
-    case 1 :
-       iface->i_flags |= IFACE_PHASE1;
-       break;
-
-    case 2 :
-       iface->i_flags |= IFACE_PHASE2;
-       break;
-
-    default :
-       fprintf( stderr, "No phase %d.\n", n );
-       return -1;
-    }
-    return( 2 );
-}
-
-int net(struct interface *iface, char **av)
-{
-    char               *nrange;
-    char               *stop;
-    int                        net;
-
-    if (( nrange = av[ 0 ] ) == NULL ) {
-       fprintf( stderr, "No network.\n" );
-       return -1;
-    }
-
-    if (( stop = strchr( nrange, '-' )) != NULL ) {
-       stop++;
-    }
-    net = atoi( nrange );
-    if ( net < 0 || net >= 0xffff ) {
-       fprintf( stderr, "Bad network: %d\n", net );
-       return -1;
-    }
-
-    if ( iface->i_rt == NULL && ( iface->i_rt = newrt(iface)) == NULL ) {
-       perror( "newrt" );
-       return -1;
-    }
-
-    if ( iface->i_flags & IFACE_PHASE1 ) {
-       if ( stop != NULL ) {
-           fprintf( stderr, "Phase 1 doesn't use an address range.\n" );
-           return -1;
-       }
-       if ( iface->i_caddr.sat_addr.s_net != ATADDR_ANYNET &&
-               ntohs( iface->i_caddr.sat_addr.s_net ) != net ) {
-           fprintf( stderr, "Net-range (%u) doesn't match net %u.\n",
-                   net, ntohs( iface->i_caddr.sat_addr.s_net ));
-           return -1;
-       }
-       iface->i_rt->rt_firstnet = iface->i_rt->rt_lastnet = htons( net );
-    } else if ( iface->i_flags & IFACE_PHASE2 ) {
-       iface->i_rt->rt_firstnet = htons( net );
-       if ( stop != NULL ) {
-           net = atoi( stop );
-           if ( net < 0 || net >= 0xffff ) {
-               fprintf( stderr, "Bad network: %d\n", net );
-               return -1;
-           }
-       }
-       iface->i_rt->rt_lastnet = htons( net );
-       if ( iface->i_caddr.sat_addr.s_net != ATADDR_ANYNET &&
-               ( ntohs( iface->i_rt->rt_firstnet ) >
-               ntohs( iface->i_caddr.sat_addr.s_net ) ||
-               ntohs( iface->i_rt->rt_lastnet ) <
-               ntohs( iface->i_caddr.sat_addr.s_net ))) {
-           fprintf( stderr, "Net-range (%u-%u) doesn't contain net (%u).\n",
-                   ntohs( iface->i_rt->rt_firstnet ),
-                   ntohs( iface->i_rt->rt_lastnet ),
-                   ntohs( iface->i_caddr.sat_addr.s_net ));
-           return -1;
-       }
-       if ( iface->i_rt->rt_firstnet != iface->i_rt->rt_lastnet ) {
-           iface->i_rt->rt_flags |= RTMPTAB_EXTENDED;
-       }
-    } else {
-       fprintf( stderr, "Must specify phase before networks.\n" );
-       return -1;
-    }
-    return( 2 );
-}
-
-int addr(struct interface *iface, char **av)
-{
-    if ( av[ 0 ] == NULL ) {
-       fprintf( stderr, "No address.\n" );
-       return -1;
-    }
-    if ( atalk_aton( av[ 0 ], &iface->i_caddr.sat_addr ) == 0 ) {
-       fprintf( stderr, "Bad address, %s\n", av[ 0 ] );
-       return -1;
-    }
-
-    if ( iface->i_rt ) {
-       if ( ntohs( iface->i_rt->rt_firstnet ) >
-               ntohs( iface->i_caddr.sat_addr.s_net ) ||
-               ntohs( iface->i_rt->rt_lastnet ) <
-               ntohs( iface->i_caddr.sat_addr.s_net )) {
-           fprintf( stderr, "Net (%u) not in net-range (%u-%u).\n",
-                   ntohs( iface->i_caddr.sat_addr.s_net ),
-                   ntohs( iface->i_rt->rt_firstnet ),
-                   ntohs( iface->i_rt->rt_lastnet ));
-           return -1;
-       }
-    } else {
-       if (( iface->i_rt = newrt(iface)) == NULL ) {
-           perror( "newrt" );
-           return -1;
-       }
-       iface->i_rt->rt_firstnet = iface->i_rt->rt_lastnet =
-               iface->i_caddr.sat_addr.s_net;
-    }
-
-    return( 2 );
-}
-
-int zone(struct interface *iface, char **av)
-{
-    struct ziptab      *zt;
-    char               *zname;
-
-    if ( av[ 0 ]  == NULL ) {
-       fprintf( stderr, "No zone.\n" );
-       return -1;
-    }
-
-    /* codepage conversion */
-    if ((size_t)(-1) == convert_string_allocate(CH_UNIX, CH_MAC, av[0], -1, &zname)) {
-       zname = strdup(av[0]);
-    }
-
-    /*
-     * Only process "-zone" if this interface has "-seed".  We keep our
-     * list of configured zones in the interface structure.  Then we can
-     * check that the network has given us good zones.
-     */
-    if ( iface->i_flags & IFACE_SEED ) {
-        if ( iface->i_rt == NULL ) {
-           fprintf( stderr, "Must specify net-range before zones.\n" );
-           return -1;
-        }
-
-       if (( zt = newzt( strlen( zname ), zname )) == NULL ) {
-           perror( "newzt" );
-           return -1;
-       }
-       if ( iface->i_czt == NULL ) {
-           iface->i_czt = zt;
-       } else {
-           zt->zt_next = iface->i_czt->zt_next;
-           iface->i_czt->zt_next = zt;
-       }
-    }
-    free(zname);
-
-    return( 2 );
-}
-
-/*
- * Get the configuration from the kernel. Only called if there's no
- * configuration.
- */
-int getifconf(void)
-{
-    struct interface   *iface, *niface;
-    struct ifreq        ifr;
-    char                **start, **list;
-    int                        s;
-
-    if (( s = socket( AF_APPLETALK, SOCK_DGRAM, 0 )) < 0 ) {
-       perror( "socket" );
-       return -1;
-    }
-
-    start = list = getifacelist();
-    while (list && *list) {
-        strlcpy(ifr.ifr_name, *list, sizeof(ifr.ifr_name));
-       list++;
-
-       if (ioctl(s, SIOCGIFFLAGS, &ifr) < 0)
-         continue;
-
-       if (ifr.ifr_flags & (IFF_LOOPBACK | IFF_POINTOPOINT | IFF_SLAVE))
-         continue;
-
-       if ((ifr.ifr_flags & IFF_UP) == 0)
-         continue;
-
-       /* for devices that don't support appletalk */
-       if (ioctl(s, SIOCGIFADDR, &ifr) < 0 && (errno == ENODEV))
-         continue;
-
-       for ( iface = interfaces; iface; iface = iface->i_next ) {
-           if ( strcmp( iface->i_name, ifr.ifr_name ) == 0 ) {
-               break;
-           }
-       }
-       if ( iface ) {  /* Already have this interface name */
-           continue;
-       }
-
-
-#ifdef IFF_MULTICAST
-       if ((ifr.ifr_flags & IFF_MULTICAST) == 0)
-         fprintf(stderr, "%s: multicast may not work correctly.\n",
-                 ifr.ifr_name);
-#endif /* IFF_MULTICAST */
-
-       if (addmulti(ifr.ifr_name, NULL) < 0) {
-         fprintf(stderr, "%s: disabled.\n", ifr.ifr_name);
-         continue;
-       }
-       
-       if (( niface = newiface( ifr.ifr_name )) == NULL ) {
-           perror( "newiface" );
-           close(s);
-           freeifacelist(start);
-           return -1;
-       }
-       /*
-        * Could try to get the address from the kernel...
-        */
-
-       if ( interfaces == NULL ) {
-           interfaces = niface;
-       } else {
-           for ( iface = interfaces; iface->i_next; iface = iface->i_next )
-               ;
-           iface->i_next = niface;
-       }
-       niface->i_next = NULL;
-    }
-    freeifacelist(start);
-    (void)close( s );
-    return( 0 );
-}
-
-/*
- * Allocate a new interface structure.  Centralized here so we can change
- * the interface structure and have it updated nicely.
- */
-
-struct interface *newiface( const char *name)
-{
-    struct interface   *niface;
-
-    if (( niface = (struct interface *)calloc(1, sizeof( struct interface )))
-           == NULL ) {
-       return( NULL );
-    }
-    strlcpy( niface->i_name, name, sizeof(niface->i_name));
-#ifdef BSD4_4
-    niface->i_addr.sat_len = sizeof( struct sockaddr_at );
-#endif /* BSD4_4 */
-    niface->i_addr.sat_family = AF_APPLETALK;
-#ifdef BSD4_4
-    niface->i_caddr.sat_len = sizeof( struct sockaddr_at );
-#endif /* BSD4_4 */
-    niface->i_caddr.sat_family = AF_APPLETALK;
-#ifdef linux
-    niface->i_flags = IFACE_ALLMULTI;
-#endif
-    return( niface );
-}
-
-#ifdef __svr4__
-int plumb(void)
-{
-    struct interface   *iface;
-    char               device[ MAXPATHLEN + 1], *p, *t;
-    int                        fd, ppa;
-    int                        digits = 0;
-
-    for ( iface = interfaces; iface != NULL; iface = iface->i_next ) {
-       if ( strcmp( iface->i_name, LOOPIFACE ) == 0 ) {
-           continue;
-       }
-
-       strcpy( device, "/dev/" );
-       strcat( device, iface->i_name );
-       for (t = device; *t != '\0' ; ++t) {
-           if (isdigit(*t) == 0) {
-               p = t + 1;
-           }
-           else {
-               digits++;
-           }
-       }
-
-       if (digits == 0) {
-           LOG(log_error, logtype_atalkd, "plumb: invalid device: %s", device );
-           return -1;
-       }
-       ppa = atoi( p );
-       *p = '\0';
-
-       if (( fd = open( device, O_RDWR, 0 )) < 0 ) {
-           LOG(log_error, logtype_atalkd, "%s: %s", device, strerror(errno) );
-           return -1;
-       }
-       if ( ioctl( fd, I_PUSH, "ddp" ) < 0 ) {
-           LOG(log_error, logtype_atalkd, "I_PUSH: %s", strerror(errno) );
-           close(fd);
-           return -1;
-       }
-       if ( ioctl( fd, IF_UNITSEL, ppa ) < 0 ) {
-           LOG(log_error, logtype_atalkd, "IF_UNITSEL: %s", strerror(errno) );
-           close(fd);
-           return -1;
-       }
-
-       /* configure multicast. */
-       if (addmulti(iface->i_name, NULL) < 0) {
-         perror(iface->i_name);
-         fprintf(stderr,"Can't configure multicast.\n");
-         close(fd);
-         return -1;
-       }
-
-       LOG(log_info, logtype_atalkd, "plumbed %s%d", device, ppa );
-
-    close(fd);
-    }
-
-    return( 0 );
-}
-#endif /* __svr4__ */
diff --git a/etc/atalkd/gate.h b/etc/atalkd/gate.h
deleted file mode 100644 (file)
index 9d2869f..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-/*
- * $Id: gate.h,v 1.2 2001-06-25 20:13:45 rufustfirefly Exp $
- *
- * Copyright (c) 1990,1993 Regents of The University of Michigan.
- * All Rights Reserved. See COPYRIGHT.
- */
-
-struct gate {
-    struct gate                *g_next,
-                       *g_prev;
-    int                        g_state;
-    struct interface   *g_iface;
-    struct rtmptab     *g_rt;
-    struct sockaddr_at g_sat;
-};
diff --git a/etc/atalkd/interface.h b/etc/atalkd/interface.h
deleted file mode 100644 (file)
index eaefae5..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * $Id: interface.h,v 1.6 2009-12-13 02:21:47 didg Exp $
- * Copyright (c) 1990,1992 Regents of The University of Michigan.
- * All Rights Reserved. See COPYRIGHT.
- */
-
-#ifndef ATALKD_INTERFACE_H
-#define ATALKD_INTERFACE_H 1
-
-#include <sys/cdefs.h>
-
-struct interface {
-    struct interface   *i_next;
-    char               i_name[ IFNAMSIZ ];
-    int                        i_flags;
-    int                        i_time;
-    int                 i_group; /* for isolated appletalk domains */
-    struct sockaddr_at i_addr;
-    struct sockaddr_at i_caddr;
-    struct ziptab      *i_czt;
-    struct rtmptab     *i_rt;
-    struct gate                *i_gate;
-    struct atport      *i_ports;
-};
-
-#define IFACE_PHASE1   0x001
-#define IFACE_PHASE2   0x002
-#define IFACE_LOOPBACK 0x004           /* is the loopback interface */
-#define IFACE_SEED     0x008           /* act as seed */
-#define IFACE_ADDR     0x010           /* has an address set */
-#define IFACE_CONFIG   0x020           /* has been configured */
-#define IFACE_NOROUTER 0x040           /* no router on interface */
-#define IFACE_LOOP     0x080           /* has a loopback route */
-#define IFACE_RSEED     0x100           /* almost the same as seed. RSEED
-                                          says that we should try to 
-                                          do routing. */
-#define IFACE_DONTROUTE 0x200           /* don't route this interface */
-#define IFACE_ISROUTER  0x400           /* act as a router. */
-#define IFACE_ALLMULTI  0x800          /* set allmulti on this interface, linux only */
-#define IFACE_WASALLMULTI 0x1000       /* don't unset allmulti on this interface on shutdown, linux only */
-#define IFACE_ERROR    0x2000          /* sendto returned an error */
-
-#define UNSTABLE       2
-#define STABLE         0
-#define STABLEANYWAY   -2
-
-#define IFBASE         2       /* base number of interfaces */
-
-#ifdef linux
-#define LOOPIFACE      "lo"
-#else /* !linux */
-#define LOOPIFACE      "lo0"
-#endif /* linux */
-
-extern struct interface        *interfaces;
-extern struct interface        *ciface;
-struct interface       *newiface (const char *);
-
-#endif /* ATALKD_INTERFACE_H */
diff --git a/etc/atalkd/list.h b/etc/atalkd/list.h
deleted file mode 100644 (file)
index 17b7cce..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-/*
- * $Id: list.h,v 1.2 2001-06-25 20:13:45 rufustfirefly Exp $
- *
- * Copyright (c) 1990,1992 Regents of The University of Michigan.
- * All Rights Reserved. See COPYRIGHT.
- */
-
-struct list {
-    void       *l_data;
-    struct list        *l_next,
-               *l_prev;
-};
diff --git a/etc/atalkd/main.c b/etc/atalkd/main.c
deleted file mode 100644 (file)
index 469678d..0000000
+++ /dev/null
@@ -1,1559 +0,0 @@
-/*
- * $Id: main.c,v 1.25 2009-12-13 02:21:47 didg Exp $
- *
- * Copyright (c) 1990,1993 Regents of The University of Michigan.
- * All Rights Reserved. See COPYRIGHT.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <sys/file.h>
-#include <sys/time.h>
-#include <sys/resource.h>
-#include <sys/ioctl.h>
-
-/* POSIX.1 check */
-#include <sys/types.h>
-#ifdef HAVE_SYS_WAIT_H
-#include <sys/wait.h>
-#endif /* HAVE_SYS_WAIT_H */
-#ifndef WEXITSTATUS 
-#define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
-#endif /* ! WEXITSTATUS */
-#ifndef WIFEXITED
-#define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
-#endif /* ! WIFEXITED */
-#ifndef WIFSTOPPED
-#define WIFSTOPPED(status) (((status) & 0xff) == 0x7f)
-#endif
-
-#include <errno.h>
-#ifdef TRU64
-#include <sys/mbuf.h>
-#include <net/route.h>
-#endif /* TRU64 */
-#include <net/if.h>
-#include <net/route.h>
-
-#include <netinet/in.h>
-
-#include <signal.h>
-#include <atalk/logger.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <netdb.h>
-#include <fcntl.h>
-#include <unistd.h>
-
-#include <netatalk/endian.h>
-#include <netatalk/at.h>
-#include <atalk/compat.h>
-#include <atalk/zip.h>
-#include <atalk/rtmp.h>
-#include <atalk/nbp.h>
-#include <atalk/ddp.h>
-#include <atalk/atp.h>
-#include <atalk/paths.h>
-#include <atalk/util.h>
-
-#ifdef __svr4__
-#include <sys/sockio.h>
-#include <termios.h>
-#endif /* __svr4__ */
-
-#include "interface.h"
-#include "gate.h"
-#include "list.h"
-#include "rtmp.h"
-#include "zip.h"
-#include "nbp.h"
-#include "atserv.h"
-#include "main.h"
-
-/* Forward Declarations */
-int ifconfig(const char *iname, unsigned long cmd, struct sockaddr_at *sa);
-
-/* FIXME/SOCKLEN_T: socklen_t is a unix98 feature */
-#ifndef SOCKLEN_T
-#define SOCKLEN_T unsigned int
-#endif /* SOCKLEN_T */
-
-#ifndef WEXITSTATUS
-#define WEXITSTATUS(x) ((x).w_retcode)
-#endif /* WEXITSTATUS */
-
-/* linux has a special ioctl for appletalk device destruction.  as of
- * 2.1.57, SIOCDIFADDR works w/ linux. okay, we need to deal with the
- * fact that SIOCDIFADDR may be defined on linux despite the fact that
- * it doesn't work. */
-#if !defined(SIOCDIFADDR) && defined(SIOCATALKDIFADDR)
-#define SIOCDIFADDR SIOCATALKDIFADDR
-#endif
-
-#define elements(a)    (sizeof(a)/sizeof((a)[0]))
-
-#define PKTSZ  1024
-
-extern int aep_packet(struct atport *ap, struct sockaddr_at *from, char *data, int len);
-
-int            rtfd;
-int            transition = 0;
-int            stabletimer, newrtmpdata = 0;
-
-static struct atserv   atserv[] = {
-    { "rtmp",          1,      rtmp_packet },          /* 0 */
-    { "nbp",           2,      nbp_packet },           /* 1 */
-    { "echo",          4,      aep_packet },           /* 2 */
-    { "zip",           6,      zip_packet },           /* 3 */
-};
-static int             atservNATSERV = elements( atserv );
-
-struct interface       *interfaces = NULL, *ciface = NULL;
-
-static int             debug = 0, quiet = 0, chatty = 0;
-static char            *configfile = NULL;
-static int             ziptimeout = 0;
-static int             stable = 0, noparent = 0;
-static int             ninterfaces;
-static int             defphase = IFACE_PHASE2;
-static int             nfds = 0;
-static fd_set          fds;
-static char            Packet[ PKTSZ ];
-static char            *version = VERSION;
-static char            *pidfile = _PATH_ATALKDLOCK;
-
-
-/* from config.c */
-
-int readconf( char * );
-int getifconf( void );
-int writeconf( char * );
-
-/* this is the messiest of the bunch as atalkd can exit pretty much
- * everywhere. we delete interfaces here instead of in as_down. */
-static void atalkd_exit(const int i)
-{
-#ifdef SIOCDIFADDR
-  struct interface *iface;
-
-  for (iface = interfaces; iface; iface = iface->i_next) {
-    if (ifconfig( iface->i_name, SIOCDIFADDR, &iface->i_addr)) {
-#ifdef SIOCATALKDIFADDR
-#if (SIOCDIFADDR != SIOCATALKDIFADDR)
-      if (!ifconfig(iface->i_name, SIOCATALKDIFADDR, &iface->i_addr)) 
-       continue;
-#endif /* SIOCDIFADDR != SIOCATALKDIFADDR */
-#endif /* SIOCATALKIFADDR */
-      LOG(log_error, logtype_atalkd, "difaddr(%u.%u): %s", 
-             ntohs(iface->i_addr.sat_addr.s_net), 
-             iface->i_addr.sat_addr.s_node, strerror(errno));
-    }
-#ifdef linux
-    if (!(iface->i_flags & IFACE_WASALLMULTI) && (iface->i_flags & IFACE_ALLMULTI))
-        ifsetallmulti(iface->i_name, 0);
-#endif /* linux */
-  }
-#endif /* SOPCDOFADDR */
-
-  server_unlock(pidfile);
-  exit(i);
-}
-
-/* XXX need better error handling for gone interfaces, delete routes and so on 
- * moreover there's no way to put an interface back short of restarting atalkd
- * thus after the first time, silently fail
-*/
-static ssize_t sendto_iface(struct interface *iface, int sockfd, const void *buf, size_t len, 
-                       const struct sockaddr_at         *dest_addr)
-{
-    ssize_t ret = sendto( sockfd, buf, len, 0, (struct sockaddr *)dest_addr, sizeof( struct sockaddr_at ));
-
-    if (ret < 0 ) {
-        if (!(iface->i_flags & IFACE_ERROR)) {
-            LOG(log_error, logtype_atalkd, "as_timer sendto %u.%u (%u): %s",
-                                   ntohs( dest_addr->sat_addr.s_net ),
-                                   dest_addr->sat_addr.s_node,
-                                   ntohs( iface->i_rt->rt_firstnet ),
-                                   strerror(errno) );
-        }
-        iface->i_flags |= IFACE_ERROR;
-    }
-    else {
-        iface->i_flags &= ~IFACE_ERROR;
-    }
-    return ret;
-}
-
-static void as_timer(int sig _U_)
-{
-    struct sockaddr_at sat;
-    struct ziphdr      zh;
-    struct rtmp_head   rh;
-    struct rtmp_tuple  rt;
-    struct atport      *ap, *zap, *rap;
-    struct interface   *iface, *iface2;
-    struct gate                *gate, *fgate = NULL;
-    struct rtmptab     *rtmp, *frtmp;
-    struct ziptab      *zt;
-    char               *data, *end, packet[ ATP_BUFSIZ ];
-    int                        sentzipq = 0;
-    int                        n, cc;
-
-    ap=zap=rap=NULL;
-
-    memset(&sat, 0, sizeof( struct sockaddr_at ));
-
-    for ( iface = interfaces; iface; iface = iface->i_next ) {
-       if ( iface->i_flags & IFACE_LOOPBACK ) {
-           continue;
-       }
-       for ( ap = iface->i_ports; ap; ap = ap->ap_next ) {
-           if ( ap->ap_packet == zip_packet ) {
-               zap = ap;
-           }
-           if ( ap->ap_packet == rtmp_packet ) {
-               rap = ap;
-           }
-       }
-
-       if (( iface->i_flags & ( IFACE_ADDR|IFACE_CONFIG|IFACE_NOROUTER )) == IFACE_ADDR ) {
-           if ( iface->i_time < 3 ) {
-               if ( iface->i_flags & IFACE_PHASE1 ) {
-                 if (rtmp_request( iface ) < 0) {
-                     LOG(log_error, logtype_atalkd, "rtmp_request: %s", strerror(errno));
-                     atalkd_exit(1);
-                 }
-                   newrtmpdata = 1;
-               } else {
-                 if (zip_getnetinfo( iface ) < 0) {
-                   LOG(log_error, logtype_atalkd, "zip_getnetinfo: %s", strerror(errno));
-                   atalkd_exit(1);
-                 }
-                 sentzipq = 1;
-               }
-               iface->i_time++;
-           } else {
-               iface->i_flags |= IFACE_NOROUTER;
-               if ((iface->i_flags & IFACE_ISROUTER)) {
-                   if (( iface->i_flags & IFACE_SEED ) == 0 ) {
-                       /*
-                        * No seed info, and we've got multiple interfaces.
-                        * Wait forever.
-                        */
-                       LOG(log_info, logtype_atalkd, "as_timer multiple interfaces, no seed" );
-                       LOG(log_info, logtype_atalkd, "as_timer can't configure %s", iface->i_name );
-                       LOG(log_info, logtype_atalkd, "as_timer waiting for router" );
-                       iface->i_time = 0;
-                       continue;
-                   } else {
-                       /*
-                        * Complete configuration for iface, and boot next
-                        * interface.
-                        */
-                       iface->i_flags |= IFACE_CONFIG;
-                       for ( zt = iface->i_czt; zt; zt = zt->zt_next ) {
-                           if (addzone( iface->i_rt, zt->zt_len, zt->zt_name) < 0) {
-                             LOG(log_error, logtype_atalkd, "addzone: %s", strerror(errno));
-                             atalkd_exit(1);
-                           }
-                       }
-                       if ( iface->i_rt->rt_zt ) {
-                           iface->i_rt->rt_flags &= ~RTMPTAB_ZIPQUERY;
-                           iface->i_rt->rt_flags |= RTMPTAB_HASZONES;
-                       }
-                       if ( iface->i_flags & IFACE_PHASE1 ) {
-                           LOG(log_info, logtype_atalkd, "as_timer configured %s phase 1 from seed", iface->i_name );
-                           setaddr( iface, IFACE_PHASE1,
-                                   iface->i_caddr.sat_addr.s_net,
-                                   iface->i_addr.sat_addr.s_node,
-                                   iface->i_caddr.sat_addr.s_net,
-                                   iface->i_caddr.sat_addr.s_net );
-                       } else {
-                           LOG(log_info, logtype_atalkd, "as_timer configured %s phase 2 from seed", iface->i_name );
-                       }
-
-                       if ( looproute( iface, RTMP_ADD )) { /* -1 or 1 */
-                           LOG(log_error, logtype_atalkd, "as_timer: can't route %u.%u to loop: %s", 
-                                   ntohs( iface->i_addr.sat_addr.s_net ),
-                                   iface->i_addr.sat_addr.s_node, strerror(errno) );
-                           atalkd_exit( 1 );
-                       }
-                       if ( iface == ciface ) {
-                           ciface = ciface->i_next;
-                           bootaddr( ciface );
-                       }
-                   }
-               } else {
-                   /*
-                    * Configure for no router operation.  Wait for a route
-                    * to become available in rtmp_packet().
-                    */
-                   LOG(log_info, logtype_atalkd, "config for no router" );
-                     
-                   if ( iface->i_flags & IFACE_PHASE2 ) {
-                       iface->i_rt->rt_firstnet = 0;
-                       iface->i_rt->rt_lastnet = htons( STARTUP_LASTNET );
-                       setaddr( iface, IFACE_PHASE2, iface->i_addr.sat_addr.s_net, iface->i_addr.sat_addr.s_node,
-                               0, htons( STARTUP_LASTNET ));
-                   }
-                   if ( looproute( iface, RTMP_ADD ) ) { /* -1 or 1 */
-                       LOG(log_error, logtype_atalkd, "as_timer: can't route %u.%u to loopback: %s",
-                               ntohs( iface->i_addr.sat_addr.s_net ), iface->i_addr.sat_addr.s_node,
-                               strerror(errno) );
-                       atalkd_exit( 1 );
-                   }
-
-                   if ( iface == ciface ) {
-                     ciface = ciface->i_next;
-                     bootaddr( ciface );
-                   }
-               }
-           }
-       }
-
-       for ( gate = iface->i_gate; gate; gate = gate->g_next ) {
-           if ( fgate ) {
-               free( (caddr_t)fgate );
-               fgate = NULL;
-           }
-
-           n = 0;
-           data = packet + 1 + sizeof( struct ziphdr );
-           end = packet + sizeof( packet );
-
-           sat = gate->g_sat;
-           sat.sat_port = zap->ap_port;
-
-           /*
-            * Perform timeouts on routers.  If we've only got one
-            * interface, we'll use these timeouts to decide that
-            * our zone has gone away.
-            */
-           if ( ++gate->g_state >= RTMPTAB_BAD ) {
-               LOG(log_info, logtype_atalkd, "as_timer gateway %u.%u down", ntohs( gate->g_sat.sat_addr.s_net ),
-                       gate->g_sat.sat_addr.s_node );
-               rtmp = gate->g_rt;
-               while ( rtmp ) {
-                   frtmp = rtmp->rt_next;
-                   if ( rtmp->rt_hops == RTMPHOPS_POISON || rtmp->rt_iprev == NULL ) {
-                       rtmp_free( rtmp );
-                   } else {
-                       rtmp->rt_hops = RTMPHOPS_POISON;
-                       if ((cc = rtmp_replace( rtmp )) < 0) {
-                         LOG(log_error, logtype_atalkd, "rtmp_replace: %s", strerror(errno));
-                         atalkd_exit(1);
-                       }
-                       if (cc) {
-                           gate->g_state = rtmp->rt_state = RTMPTAB_GOOD;
-                       }
-                   }
-                   rtmp = frtmp;
-               }
-               if ( gate->g_rt == NULL ) {
-                   if ( gate->g_prev == NULL ) {
-                       gate->g_iface->i_gate = gate->g_next;
-                   } else {
-                       gate->g_prev->g_next = gate->g_next;
-                   }
-                   if ( gate->g_next != NULL ) {
-                       gate->g_next->g_prev = gate->g_prev;
-                   }
-                   fgate = gate;       /* can't free here, just mark it */
-               }
-               /*
-                * If this is the last router on the only interface,
-                * reconfigure our netrange.  By marking the interface
-                * as having no router, we will notice when a router
-                * comes back up.
-                *
-                * XXX: actually, we always reconfigure an interface
-                * if we're not a seed router.
-                */
-
-               if ( gate->g_iface->i_gate == NULL && ((iface->i_flags & IFACE_SEED) == 0)) {
-                   gate->g_iface->i_flags |= IFACE_NOROUTER;
-                   gate->g_iface->i_flags &= ~IFACE_CONFIG;
-
-                   /* get rid of any zones associated with this iface */
-                   if (gate->g_iface->i_rt->rt_zt) {
-                     rtmp_delzonemap(gate->g_iface->i_rt);
-                     gate->g_iface->i_rt->rt_flags &= ~RTMPTAB_HASZONES;
-                   }
-
-                   LOG(log_info, logtype_atalkd, "as_timer last gateway down" );
-
-                   /* Set netrange to 0-fffe.  */
-                   if ( gate->g_iface->i_flags & IFACE_PHASE2 ) {
-                       gate->g_iface->i_rt->rt_firstnet = 0;
-                       gate->g_iface->i_rt->rt_lastnet =
-                               htons( STARTUP_LASTNET );
-                       setaddr( iface, IFACE_PHASE2,
-                               iface->i_addr.sat_addr.s_net,
-                               iface->i_addr.sat_addr.s_node,
-                               0, htons( STARTUP_LASTNET ));
-                   }
-               }
-               continue;
-           }
-
-           /*
-            * If we don't have a zone for our interface yet, ask for
-            * it from any router (all routers) on the interface.
-            */
-           if (( iface->i_rt->rt_flags & RTMPTAB_HASZONES ) == 0 ) {
-               iface->i_rt->rt_flags |= RTMPTAB_ZIPQUERY;
-               memcpy( data, &iface->i_rt->rt_firstnet, sizeof( u_short ));
-               data += sizeof( u_short );
-               n++;
-           }
-
-           rtmp = gate->g_rt;
-           while ( rtmp ) {
-               /*
-                * Delete old routing tuples.
-                */
-               if ( rtmp->rt_state != RTMPTAB_PERM ) {
-                   rtmp->rt_state++;
-               }
-
-               /*
-                * We've not been updated for this route in a while.  If
-                * it's not in use, go ahead and remove it.  If it is in
-                * use, mark the route as down (POISON), and look for a
-                * better route.  If one is found, delete this route and use
-                * the new one.  If it's not found, mark the route as GOOD
-                * (so we'll propogate our poison) and delete it the next
-                * time it becomes BAD.
-                */
-               if ( rtmp->rt_state >= RTMPTAB_BAD ) {
-                   frtmp = rtmp->rt_next;
-                   if ( rtmp->rt_iprev == NULL ) {     /* not in use */
-                       rtmp_free( rtmp );
-                   } else {                            /* in use */
-                       if ( rtmp->rt_hops == RTMPHOPS_POISON ) {
-                           rtmp_free( rtmp );
-                       } else {
-                           rtmp->rt_hops = RTMPHOPS_POISON;
-                           if ((cc = rtmp_replace( rtmp )) < 0) {
-                               LOG(log_error, logtype_atalkd, "rtmp_replace: %s", strerror(errno));
-                               atalkd_exit(1);
-                           }
-                           if (cc)
-                               rtmp->rt_state = RTMPTAB_GOOD;
-                       }
-                   }
-                   rtmp = frtmp;
-                   continue;
-               }
-
-               /*
-                * Do ZIP lookups.
-                */
-               if ( rtmp->rt_iprev && ( rtmp->rt_flags & RTMPTAB_HASZONES ) == 0 ) {
-                   if ( data + sizeof( u_short ) > end || n == 255 ) {
-                       /* send what we've got */
-                       zh.zh_op = ZIPOP_QUERY;
-                       zh.zh_count = n;
-                       cc = data - packet;
-                       data = packet;
-                       *data++ = DDPTYPE_ZIP;
-                       memcpy( data, &zh, sizeof( struct ziphdr ));
-
-                       sendto_iface(iface,  zap->ap_fd, packet, cc, &sat);
-                       sentzipq = 1;
-
-                       n = 0;
-                       data = packet + 1 + sizeof( struct ziphdr );
-                       end = packet + sizeof( packet );
-                   }
-
-                   /*
-                    * rt_nzq is number of ZIP Queries we've issued for a
-                    * given netrange.  If we've got ziptimeout on, we
-                    * will only ask 3 times for any given netrange.
-                    * Interestingly enough, since rt_nzq is a u_char,
-                    * it will overflow after a while.  This means we will
-                    * periodically ask for nets that we've decided not to
-                    * ask about, and warn that we can't get it's zone.
-                    */
-                   if ( rtmp->rt_nzq++ == 3 ) {
-                       LOG(log_info, logtype_atalkd, "as_timer can't get zone for %u", ntohs( rtmp->rt_firstnet ));
-                   }
-                   if ( rtmp->rt_nzq > 3 ) {
-                       if ( ziptimeout ) {
-                           rtmp = rtmp->rt_next;
-                           continue;
-                       }
-                   } else {
-                       sentzipq = 1;
-                   }
-                   rtmp->rt_flags |= RTMPTAB_ZIPQUERY;
-                   memcpy( data, &rtmp->rt_firstnet, sizeof( u_short ));
-                   data += sizeof( u_short );
-                   n++;
-               }
-               rtmp = rtmp->rt_next;
-           }
-
-           /* send what we've got */
-           if ( n > 0 ) {
-               zh.zh_op = ZIPOP_QUERY;
-               zh.zh_count = n;
-               cc = data - packet;
-               data = packet;
-               *data++ = DDPTYPE_ZIP;
-               memcpy( data, &zh, sizeof( struct ziphdr ));
-
-               sendto_iface( iface, zap->ap_fd, packet, cc, &sat);
-           }
-       }
-       if ( fgate ) {
-           free( (caddr_t)fgate );
-           fgate = NULL;
-       }
-
-       /*
-        * Send RTMP broadcasts if we have multiple interfaces or our 
-        * interface is configured as a router.  
-        */
-       if ((iface->i_flags & IFACE_ISROUTER)) {
-#ifdef BSD4_4
-           sat.sat_len = sizeof( struct sockaddr_at );
-#endif /* BSD4_4 */
-           sat.sat_family = AF_APPLETALK;
-           sat.sat_addr.s_net = ATADDR_ANYNET;
-           sat.sat_addr.s_node = ATADDR_BCAST;
-           sat.sat_port = rap->ap_port;
-
-           data = packet;
-           end = data + sizeof( packet );
-           *data++ = DDPTYPE_RTMPRD;
-           rh.rh_net = iface->i_addr.sat_addr.s_net;
-           rh.rh_nodelen = 8;
-           rh.rh_node = iface->i_addr.sat_addr.s_node;
-           memcpy( data, &rh, sizeof( struct rtmp_head ));
-           data += sizeof( struct rtmp_head );
-           n = 0;
-
-
-           if ( iface->i_flags & IFACE_PHASE1 ) {
-               rt.rt_net = 0;
-               rt.rt_dist = 0x82;
-               memcpy( data, &rt, SZ_RTMPTUPLE );
-               data += SZ_RTMPTUPLE;
-           } else {
-               rt.rt_net = iface->i_rt->rt_firstnet;
-               rt.rt_dist = 0x80;
-               memcpy( data, &rt, SZ_RTMPTUPLE );
-               data += SZ_RTMPTUPLE;
-
-               rt.rt_net = iface->i_rt->rt_lastnet;
-               rt.rt_dist = 0x82;
-               memcpy( data, &rt, SZ_RTMPTUPLE );
-               data += SZ_RTMPTUPLE;
-           }
-
-           for ( iface2 = interfaces; iface2; iface2 = iface2->i_next ) {
-
-             /* XXX: there used to be a bit checking against iface ==
-                iface2. also, we don't want to send an rtmp broadcast
-                to an interface that doesn't want it.  */
-               if ((( iface2->i_flags & IFACE_CONFIG ) == 0) ||
-                   ((iface2->i_flags & IFACE_ISROUTER) == 0)) {
-                   continue;
-               }
-               /*
-                * Fill in tuples.  Always send the same thing, regardless
-                * of the phase of the destination.  Routers who don't
-                * understand extended rtmp packets will toss extended
-                * tuples because their distance will have the high bit set.
-                */
-               for ( rtmp = iface2->i_rt; rtmp; rtmp = rtmp->rt_inext ) {
-                   /* don't broadcast routes we have no zone for */
-                   if ( rtmp->rt_zt == NULL ||
-                           ( rtmp->rt_flags & RTMPTAB_ZIPQUERY ) ||
-                           ( rtmp->rt_flags & RTMPTAB_HASZONES ) == 0 ) {
-                       continue;
-                   }
-
-                   /* split horizon */
-                   if (rtmp->rt_iface == iface) {
-                       continue;
-                   }
-
-                   if ((( rtmp->rt_flags & RTMPTAB_EXTENDED ) &&
-                           data + 2 * SZ_RTMPTUPLE > end ) ||
-                           data + SZ_RTMPTUPLE > end ) {
-
-                       sendto_iface(iface,rap->ap_fd, packet, data - packet, &sat);
-
-                       if ( iface->i_flags & IFACE_PHASE2 ) {
-                           data = packet + 1 + sizeof( struct rtmp_head ) + 2 * SZ_RTMPTUPLE;
-                       } else {
-                           data = packet + 1 + sizeof( struct rtmp_head ) + SZ_RTMPTUPLE;
-                       }
-                       n = 0;
-                   }
-
-                   rt.rt_net = rtmp->rt_firstnet;
-                   rt.rt_dist = rtmp->rt_hops;
-                   if ( rtmp->rt_flags & RTMPTAB_EXTENDED ) {
-                       rt.rt_dist |= 0x80;
-                   }
-                   memcpy( data, &rt, SZ_RTMPTUPLE );
-                   data += SZ_RTMPTUPLE;
-
-                   if ( rtmp->rt_flags & RTMPTAB_EXTENDED ) {
-                       rt.rt_net = rtmp->rt_lastnet;
-                       rt.rt_dist = 0x82;
-                       memcpy( data, &rt, SZ_RTMPTUPLE );
-                       data += SZ_RTMPTUPLE;
-                   }
-                   n++;
-               }
-           }
-
-           /* send rest */
-           if ( n ) {
-               sendto_iface(iface, rap->ap_fd, packet, data - packet, &sat);
-           }
-       }
-    }
-
-    /*
-     * Check if we're stable.  Each time we configure an interface, we
-     * sent stabletimer to UNSTABLE.  If stabletimer ever gets to
-     * STABLEANYWAY, we give up and decide to "be" stable anyway.
-     * Normally, we wait for stabletimer get <= STABLE with no new rtmp
-     * data and all zip data complete.
-     */
-    if ( !stable ) {
-       if ( stabletimer <= STABLE && !newrtmpdata && !sentzipq ) {
-           /* write out config file */
-           stable = 1;
-           writeconf( configfile );
-       } else {
-           if ( stabletimer-- <= STABLEANYWAY ) {
-               stable = 1;
-           }
-       }
-       newrtmpdata = 0;
-
-       if ( stable && !noparent ) {
-           noparent = 1;
-           LOG(log_info, logtype_atalkd, "ready %d/%d/%d", stabletimer, newrtmpdata,
-                   sentzipq );
-           if ( !debug ) {
-               /*
-                * Seems like we could get here more than once...
-                */
-               if ( kill( getpid(), SIGSTOP ) < 0 ) {
-                   LOG(log_error, logtype_atalkd, "as_timer: kill-self failed!" );
-                   atalkd_exit( 1 );
-               }
-           }
-       }
-    }
-
-#ifdef DEBUG
-    consistency();
-#endif /* DEBUG */
-}
-
-#ifdef DEBUG
-/*
-* Consistency check...
-*/
-consistency()
-{
-    struct rtmptab     *rtmp;
-    struct list                *lr, *lz;
-    struct ziptab      *zt;
-
-    for ( zt = ziptab; zt; zt = zt->zt_next ) {
-       for ( lr = zt->zt_rt; lr; lr = lr->l_next ) {
-           rtmp = (struct rtmptab *)lr->l_data;
-           if ( rtmp->rt_iprev == 0 && rtmp->rt_gate != 0 ) {
-               LOG(log_error, logtype_atalkd, "%.*s has %u-%u (unused)",
-                       zt->zt_len, zt->zt_name, ntohs( rtmp->rt_firstnet ),
-                       ntohs( rtmp->rt_lastnet ));
-               atalkd_exit(1);
-           }
-           for ( lz = rtmp->rt_zt; lz; lz = lz->l_next ) {
-               if ( zt == (struct ziptab *)lz->l_data ) {
-                   break;
-               }
-           }
-           if ( lz == 0 ) {
-               LOG(log_error, logtype_atalkd, "no map from %u-%u to %.*s", 
-                       ntohs( rtmp->rt_firstnet ),
-                       ntohs( rtmp->rt_lastnet ),
-                       zt->zt_len, zt->zt_name );
-               atalkd_exit(1);
-           }
-       }
-    }
-}
-#endif /* DEBUG */
-
-static void
-as_debug(int sig _U_)
-{
-    struct interface   *iface;
-    struct list                *l;
-    struct ziptab      *zt;
-    struct gate                *gate;
-    struct rtmptab     *rt;
-    FILE               *rtmpdebug;
-
-    if (( rtmpdebug = fopen( _PATH_ATALKDEBUG, "w" )) == NULL ) {
-       LOG(log_error, logtype_atalkd, "rtmp: %s", strerror(errno) );
-    }
-
-    for ( iface = interfaces; iface; iface = iface->i_next ) {
-       fprintf( rtmpdebug, "interface %s %u.%u ", iface->i_name,
-               ntohs( iface->i_addr.sat_addr.s_net ),
-               iface->i_addr.sat_addr.s_node );
-       if ( iface->i_flags & IFACE_PHASE1 ) {
-           putc( '1', rtmpdebug );
-       }
-       if ( iface->i_flags & IFACE_PHASE2 ) {
-           putc( '2', rtmpdebug );
-       }
-       if ( iface->i_flags & IFACE_RSEED ) {
-           putc( 'R', rtmpdebug );
-       }
-       if ( iface->i_flags & IFACE_SEED ) {
-           putc( 'S', rtmpdebug );
-       }
-       if ( iface->i_flags & IFACE_DONTROUTE ) {
-           putc( 'D', rtmpdebug );
-       }
-       if ( iface->i_flags & IFACE_ADDR ) {
-           putc( 'A', rtmpdebug );
-       }
-       if ( iface->i_flags & IFACE_CONFIG ) {
-           putc( 'C', rtmpdebug );
-       }
-       if ( iface->i_flags & IFACE_NOROUTER ) {
-           putc( 'N', rtmpdebug );
-       }
-       if ( iface->i_flags & IFACE_LOOP ) {
-           putc( 'L', rtmpdebug );
-       }
-       putc( '\n', rtmpdebug );
-
-       if ( iface->i_rt ) {
-           fprintf( rtmpdebug, "\t%u-%u ",
-                   ntohs( iface->i_rt->rt_firstnet ),
-                   ntohs( iface->i_rt->rt_lastnet ));
-           if ( iface->i_rt->rt_flags & RTMPTAB_ZIPQUERY ) {
-               putc( 'q', rtmpdebug );
-           }
-           if ( iface->i_rt->rt_flags & RTMPTAB_HASZONES ) {
-               putc( 'z', rtmpdebug );
-           }
-           if ( iface->i_rt->rt_flags & RTMPTAB_EXTENDED ) {
-               putc( 'x', rtmpdebug );
-           }
-           putc( 'i', rtmpdebug );
-           for ( l = iface->i_rt->rt_zt; l; l = l->l_next ) {
-               zt = (struct ziptab *)l->l_data;
-               fprintf( rtmpdebug, " '%.*s'", zt->zt_len, zt->zt_name );
-           }
-           fprintf( rtmpdebug, "\n" );
-       }
-
-       for ( gate = iface->i_gate; gate; gate = gate->g_next ) {
-           fprintf( rtmpdebug, "gate %u.%u %X\n",
-                   ntohs( gate->g_sat.sat_addr.s_net ),
-                   gate->g_sat.sat_addr.s_node, gate->g_state );
-           for ( rt = gate->g_rt; rt; rt = rt->rt_next ) {
-               fprintf( rtmpdebug, "\t%u-%u ", ntohs( rt->rt_firstnet ),
-                       ntohs( rt->rt_lastnet ));
-               if ( rt->rt_flags & RTMPTAB_ZIPQUERY ) {
-                   putc( 'q', rtmpdebug );
-               }
-               if ( rt->rt_flags & RTMPTAB_HASZONES ) {
-                   putc( 'z', rtmpdebug );
-               }
-               if ( rt->rt_flags & RTMPTAB_EXTENDED ) {
-                   putc( 'x', rtmpdebug );
-               }
-               if ( rt->rt_iprev ) {
-                   putc( 'i', rtmpdebug );
-               }
-               for ( l = rt->rt_zt; l; l = l->l_next ) {
-                   zt = (struct ziptab *)l->l_data;
-                   fprintf( rtmpdebug, " '%.*s'", zt->zt_len, zt->zt_name );
-               }
-               fprintf( rtmpdebug, "\n" );
-           }
-       }
-    }
-
-    fclose( rtmpdebug );
-}
-
-/*
- * Called when SIGTERM is recieved.  Remove all routes and then exit.
- */
-static void
-as_down(int sig _U_)
-{
-    struct interface   *iface;
-    struct gate                *gate;
-    struct rtmptab     *rt;
-
-    for ( iface = interfaces; iface; iface = iface->i_next ) {
-       for ( gate = iface->i_gate; gate; gate = gate->g_next ) {
-           for ( rt = gate->g_rt; rt; rt = rt->rt_next ) {
-               if ( rt->rt_iprev ) {
-                   if ( gateroute( RTMP_DEL, rt ) < 0 ) {
-                       LOG(log_error, logtype_atalkd, "as_down remove %u-%u failed: %s",
-                               ntohs( rt->rt_firstnet ),
-                               ntohs( rt->rt_lastnet ),
-                               strerror(errno) );
-                   }
-               }
-           }
-       }
-       if ( iface->i_flags & IFACE_LOOP ) {
-         if (looproute( iface, RTMP_DEL )) {
-           LOG(log_error, logtype_atalkd, "as_down remove %s %u.%u failed: %s",
-                   iface->i_name, ntohs( iface->i_addr.sat_addr.s_net ),
-                   iface->i_addr.sat_addr.s_node,
-                   strerror(errno) );
-         }
-       }
-    }
-
-    LOG(log_info, logtype_atalkd, "done" );
-    atalkd_exit( 0 );
-}
-
-int main( int ac, char **av)
-{
-    extern char         *optarg;
-    extern int          optind;
-
-    struct sockaddr_at sat;
-    struct sigaction   sv;
-    struct itimerval   it;
-    sigset_t            signal_set, old_set;
-    
-    struct interface   *iface;
-    int                        status;
-    struct atport      *ap;
-    fd_set             readfds;
-    int                        i, c;
-    SOCKLEN_T          fromlen;
-    char               *prog;
-
-    while (( c = getopt( ac, av, "12qsdtf:P:v" )) != EOF ) {
-       switch ( c ) {
-       case '1' :
-           defphase = IFACE_PHASE1;
-           break;
-
-       case '2' :
-           defphase = IFACE_PHASE2;
-           break;
-
-       case 'd' :
-           debug++;
-           break;
-
-       case 'f' :
-           configfile = optarg;
-           break;
-
-       case 'q' :      /* don't seed */
-           quiet++;
-           break;
-
-       case 's' :      /* seed */
-           chatty++;
-           break;
-
-       case 't' :      /* transition */
-           transition++;
-           break;
-
-       case 'P' :      /* pid file */
-           pidfile = optarg;
-           break;
-
-       case 'v' :      /* version */
-           printf( "atalkd (version %s)\n", version );
-           exit ( 1 );
-           break;
-
-       default :
-           fprintf( stderr, "Unknown option -- '%c'\n", c );
-           exit( 1 );
-       }
-    }
-    if ( optind != ac ) {
-       fprintf( stderr, "Too many arguments.\n" );
-       exit( 1 );
-    }
-
-    if (( prog = strrchr( av[ 0 ], '/' )) == NULL ) {
-       prog = av[ 0 ];
-    } else {
-       prog++;
-    }
-
-    /*
-     * Configure loop back address first, so appearances of "lo0" in
-     * the config file fail.  Also insures that lo0 gets configured,
-     * even if there's some hangup during configuration of some
-     * other interface.
-     */
-    if (( interfaces = newiface( LOOPIFACE )) == NULL ) {
-       perror( "newiface" );
-       exit( 1 );
-    }
-    interfaces->i_flags |= IFACE_PHASE2 | IFACE_LOOPBACK;
-
-    /*
-     * Check our initial configuration before we fork. This way we can
-     * complain about syntax errors on stdout.
-     *
-     * Basically, if we're going to read our config file, we should read
-     * it and initialize our data structures. If we're not going to read
-     * our config file, use GIFCONF to initialize our data structures.
-     */
-    if ( readconf( configfile ) < 0 && getifconf() < 0 ) {
-       fprintf( stderr, "%s: can't get interfaces, exiting.\n", prog );
-       exit( 1 );
-    }
-
-    /* we need to count up our interfaces so that we can simplify things
-     * later. we also need to figure out if we have more than one interface
-     * that is routing. */
-    for (i = 0, ninterfaces = 0, iface = interfaces; iface;
-        iface=iface->i_next) {
-      if (iface->i_flags & IFACE_DONTROUTE)
-       i++;
-      ninterfaces++;
-    }
-    i = ninterfaces - i; /* number of routable interfaces */
-
-    /*
-     * At this point, we have (at least partially) initialized data
-     * structures. Fill in what we can and verify that nothing is obviously
-     * broken.
-     */
-    for (iface = interfaces; iface; iface = iface->i_next) {
-       /* Apply the default phase */
-       if (( iface->i_flags & IFACE_PHASE1 ) == 0 &&
-               ( iface->i_flags & IFACE_PHASE2 ) == 0 ) {
-           iface->i_flags |= defphase;
-       }
-
-        /* set up router flag information. if we have multiple interfaces
-        * and DONTROUTE isn't set, set up ROUTER. i is the number of 
-        * interfaces that don't have the DONTROUTE flag set. */
-       if ((i > IFBASE) && ((iface->i_flags & IFACE_DONTROUTE) == 0)) {
-         iface->i_flags |= IFACE_ISROUTER;
-       }
-
-       /* Set default addresses */
-       if ( iface->i_rt == NULL ) {
-           if (( iface->i_rt = newrt(iface)) == NULL ) {
-               perror( "newrt" );
-               exit( 1 );
-           }
-
-           if ( iface->i_flags & IFACE_PHASE1 ) {
-               iface->i_rt->rt_firstnet = iface->i_rt->rt_lastnet =
-                       iface->i_caddr.sat_addr.s_net;
-           } else {
-               if ( iface->i_caddr.sat_addr.s_net != ATADDR_ANYNET ||
-                       ( iface->i_flags & IFACE_LOOPBACK )) {
-                   iface->i_rt->rt_firstnet = iface->i_rt->rt_lastnet =
-                           iface->i_caddr.sat_addr.s_net;
-               } else {
-                   iface->i_rt->rt_firstnet = htons( STARTUP_FIRSTNET );
-                   iface->i_rt->rt_lastnet = htons( STARTUP_LASTNET );
-               }
-           }
-       }
-       
-       if (( iface->i_flags & IFACE_PHASE1 ) == 0 ) {
-           iface->i_rt->rt_flags |= RTMPTAB_EXTENDED;
-       }
-
-       if ( iface->i_caddr.sat_addr.s_net == ATADDR_ANYNET ) {
-           iface->i_caddr.sat_addr.s_net = iface->i_rt->rt_firstnet;
-       }
-
-       if ( debug ) {
-           dumpconfig( iface );        /* probably needs args */
-       }
-    }
-
-    /*
-     * A little consistency check...
-     */
-    if ( ninterfaces < IFBASE ) {
-       fprintf( stderr, "%s: zero interfaces, exiting.\n", prog );
-       exit( 1 );
-    }
-
-    /*
-     * Set process name for logging
-     */
-
-    set_processname("atalkd");
-
-    /* do this here so that we can use ifconfig */
-#ifdef __svr4__
-    if ( plumb() < 0 ) {
-       fprintf(stderr, "can't establish STREAMS plumbing, exiting.\n" );
-       atalkd_exit( 1 );
-    }
-#endif /* __svr4__ */
-
-    /* delete pre-existing interface addresses. */
-#ifdef SIOCDIFADDR
-    for (iface = interfaces; iface; iface = iface->i_next) {
-      if (ifconfig(iface->i_name, SIOCDIFADDR, &iface->i_addr)) {
-#ifdef SIOCATALKDIFADDR
-#if (SIOCDIFADDR != SIOCATALKDIFADDR)
-       ifconfig(iface->i_name, SIOCATALKDIFADDR, &iface->i_addr);
-#endif /* SIOCDIFADDR != SIOCATALKDIFADDR */
-#endif /* SIOCATALKDIFADDR */
-      }
-    }
-#endif /* SIOCDIFADDR */
-
-    /*
-     * Disassociate. The child will send itself a signal when it is
-     * stable. This indicates that other processes may begin using
-     * AppleTalk.
-     */
-    switch (i = server_lock("atalkd", pidfile, debug)) {
-    case -1:
-      exit(1);
-    case 0: /* child */
-      break;
-    default: /* parent */
-      /*
-       * Wait for the child to send itself a SIGSTOP, after which
-       * we send it a SIGCONT and exit ourself.
-       */
-      if ( wait3( &status, WUNTRACED, (struct rusage *)0 ) != i) {
-       perror( "wait3" );      /* Child died? */
-       atalkd_exit( 1 );
-      }
-      if ( !WIFSTOPPED( status )) {
-       fprintf( stderr, "AppleTalk not up! Check your syslog for the reason." );
-       if ( WIFEXITED( status )) {
-         fprintf( stderr, " Child exited with %d.\n",
-                  WEXITSTATUS( status ));
-       } else {
-         fprintf( stderr, " Child died.\n" );
-       }
-       atalkd_exit( 1 );
-      }
-      if ( kill(i, SIGCONT ) < 0 ) {
-       perror( "kill" );
-       atalkd_exit( 1 );
-      }
-      exit( 0 );
-    }
-
-#ifdef ultrix
-    openlog( prog, LOG_PID );
-#else /* ultrix */
-    set_processname(prog);
-    syslog_setup(log_debug, logtype_default, logoption_pid, logfacility_daemon );
-#endif /* ultrix */
-
-    LOG(log_info, logtype_atalkd, "restart (%s)", version );
-
-    /*
-     * Socket for use in routing ioctl()s. Can't add routes to our
-     * interfaces until we have our routing socket.
-     */
-#ifdef BSD4_4
-    if (( rtfd = socket( PF_ROUTE, SOCK_RAW, AF_APPLETALK )) < 0 ) {
-       LOG(log_error, logtype_atalkd, "route socket: %s", strerror(errno) );
-       atalkd_exit( 1 );
-    }
-    if ( shutdown( rtfd, 0 ) < 0 ) {
-       LOG(log_error, logtype_atalkd, "route shutdown: %s", strerror(errno) );
-       atalkd_exit( 1 );
-    }
-#else /* BSD4_4 */
-    if (( rtfd = socket( AF_APPLETALK, SOCK_DGRAM, 0 )) < 0 ) {
-       LOG(log_error, logtype_atalkd, "route socket: %s", strerror(errno) );
-       atalkd_exit( 1 );
-    }
-#endif /* BSD4_4 */
-
-    ciface = interfaces;
-    bootaddr( ciface );
-
-    memset(&sv, 0, sizeof(sv));
-    sv.sa_handler = as_down;
-    sigemptyset( &sv.sa_mask );
-    sigaddset( &sv.sa_mask, SIGUSR1 );
-    sigaddset( &sv.sa_mask, SIGALRM );
-    sigaddset( &sv.sa_mask, SIGTERM );
-    sv.sa_flags = SA_RESTART;
-    if ( sigaction( SIGTERM, &sv, NULL) < 0 ) {
-       LOG(log_error, logtype_atalkd, "sigterm: %s", strerror(errno) );
-       atalkd_exit( 1 );
-    }
-
-    sv.sa_handler = as_debug;
-    sigemptyset( &sv.sa_mask );
-    sigaddset( &sv.sa_mask, SIGUSR1 );
-    sigaddset( &sv.sa_mask, SIGALRM );
-    sigaddset( &sv.sa_mask, SIGTERM );
-    sv.sa_flags = SA_RESTART;
-    if ( sigaction( SIGUSR1, &sv, NULL) < 0 ) {
-       LOG(log_error, logtype_atalkd, "sigusr1: %s", strerror(errno) );
-       atalkd_exit( 1 );
-    }
-
-    sv.sa_handler = as_timer;
-    sigemptyset( &sv.sa_mask );
-    sigaddset( &sv.sa_mask, SIGUSR1 );
-    sigaddset( &sv.sa_mask, SIGALRM );
-    sigaddset( &sv.sa_mask, SIGTERM );
-    sv.sa_flags = SA_RESTART;
-    if ( sigaction( SIGALRM, &sv, NULL) < 0 ) {
-       LOG(log_error, logtype_atalkd, "sigalrm: %s", strerror(errno) );
-       atalkd_exit( 1 );
-    }
-
-    it.it_interval.tv_sec = 10L;
-    it.it_interval.tv_usec = 0L;
-    it.it_value.tv_sec = 10L;
-    it.it_value.tv_usec = 0L;
-    if ( setitimer( ITIMER_REAL, &it, NULL) < 0 ) {
-       LOG(log_error, logtype_atalkd, "setitimer: %s", strerror(errno) );
-       atalkd_exit( 1 );
-    }
-
-    sigemptyset( &signal_set );
-    sigaddset(&signal_set, SIGALRM);
-#if 0
-    /* don't block SIGTERM */
-    sigaddset(&signal_set, SIGTERM);
-#endif
-    sigaddset(&signal_set, SIGUSR1);
-
-    for (;;) {
-       readfds = fds;
-       if ( select( nfds, &readfds, NULL, NULL, NULL) < 0 ) {
-           if ( errno == EINTR ) {
-               errno = 0;
-               continue;
-           } else {
-               LOG(log_error, logtype_atalkd, "select: %s", strerror(errno) );
-               atalkd_exit( 1 );
-           }
-       }
-
-       for ( iface = interfaces; iface; iface = iface->i_next ) {
-           for ( ap = iface->i_ports; ap; ap = ap->ap_next ) {
-               if ( FD_ISSET( ap->ap_fd, &readfds )) {
-                   if ( ap->ap_packet ) {
-                       fromlen = sizeof( struct sockaddr_at );
-                       if (( c = recvfrom( ap->ap_fd, Packet, sizeof( Packet ),
-                               0, (struct sockaddr *)&sat, &fromlen )) < 0 ) {
-                           LOG(log_error, logtype_atalkd, "recvfrom: %s", strerror(errno) );
-                           continue;
-                       }
-#ifdef DEBUG1
-                       if ( debug ) {
-                           printf( "packet from %u.%u on %s (%x) %d (%d)\n",
-                                   ntohs( sat.sat_addr.s_net ),
-                                   sat.sat_addr.s_node, iface->i_name,
-                                   iface->i_flags, ap->ap_port, ap->ap_fd );
-                           bprint( Packet, c );
-                       }
-#endif 
-                       if (sigprocmask(SIG_BLOCK, &signal_set, &old_set) < 0) {
-                           LOG(log_error, logtype_atalkd, "sigprocmask: %s", strerror(errno) );
-                           atalkd_exit( 1 );
-                       }
-
-                       if (( *ap->ap_packet )( ap, &sat, Packet, c ) < 0) {
-                         LOG(log_error, logtype_atalkd, "ap->ap_packet: %s", strerror(errno));
-                         atalkd_exit(1);
-                       }
-
-#ifdef DEBUG
-                       consistency();
-#endif 
-                       if (sigprocmask(SIG_SETMASK, &old_set, NULL) < 0) {
-                           LOG(log_error, logtype_atalkd, "sigprocmask old set: %s", strerror(errno) );
-                           atalkd_exit( 1 );
-                       }
-
-                   }
-               }
-           }
-       }
-    }
-}
-
-/*
- * This code is called (from main(), as_timer(), zip_packet(),
- * and rtmp_packet()) to set the initial "bootstrapping" address
- * on an interface.
- */
-void bootaddr(struct interface *iface)
-{
-    if ( iface == NULL ) {
-       return;
-    }
-
-    /* consistency */
-    if ( iface->i_flags & IFACE_ADDR ) {
-       LOG(log_error, logtype_atalkd, "bootaddr OOPS!" );
-       atalkd_exit(1);
-    }
-
-    if ( iface->i_flags & IFACE_PHASE1 ) {
-       setaddr( iface, IFACE_PHASE1, 0,
-               iface->i_caddr.sat_addr.s_node, 0, 0 );
-
-       if ( iface->i_flags & IFACE_LOOPBACK ) {
-           iface->i_flags |= IFACE_CONFIG | IFACE_ADDR;
-           if ( ciface == iface ) {
-               ciface = ciface->i_next;
-               bootaddr( ciface );
-           }
-
-       } else if (rtmp_request( iface ) < 0) {
-         LOG(log_error, logtype_atalkd, "bootaddr (rtmp_request): %s", strerror(errno));
-         atalkd_exit(1);
-       }
-
-    } else {
-       setaddr( iface, IFACE_PHASE2, iface->i_caddr.sat_addr.s_net,
-               iface->i_caddr.sat_addr.s_node,
-               iface->i_rt->rt_firstnet, iface->i_rt->rt_lastnet );
-
-       if ( iface->i_flags & IFACE_LOOPBACK ) {
-           iface->i_flags |= IFACE_CONFIG | IFACE_ADDR;
-           if ( ciface == iface ) {
-               ciface = ciface->i_next;
-               bootaddr( ciface );
-           }
-           
-       } else if (zip_getnetinfo( iface ) < 0) {
-         LOG(log_error, logtype_atalkd, "bootaddr (zip_getnetinfo): %s", strerror(errno));
-         atalkd_exit(1);
-       }
-    }
-    ++iface->i_time;
-    iface->i_flags |= IFACE_ADDR;
-    stabletimer = UNSTABLE;
-}
-
-
-/*
- * Change setaddr()
- * to manage the i_ports field and the fds for select().
- */
-void setaddr(struct interface *iface,
-             u_int8_t  phase, u_int16_t net, u_int8_t node,
-            u_int16_t first, u_int16_t last)
-{
-    int                        i;
-    struct atserv      *as;
-    struct atport      *ap;
-    struct servent     *se;
-    struct sockaddr_at sat;
-    struct netrange    nr;
-
-    if ( iface->i_ports == NULL ) {    /* allocate port structures */
-       for ( i = 0, as = atserv; i < atservNATSERV; i++, as++ ) {
-           if (( se = getservbyname( as->as_name, "ddp" )) == NULL ) {
-               LOG(log_info, logtype_atalkd, "%s: service unknown", as->as_name );
-           } else {
-               as->as_port = ntohs( se->s_port );
-           }
-           if (( ap = (struct atport *)malloc( sizeof( struct atport ))) ==
-                   NULL ) {
-               LOG(log_error, logtype_atalkd, "malloc: %s", strerror(errno) );
-               atalkd_exit( 1 );
-           }
-           ap->ap_fd = 0;
-           ap->ap_next = iface->i_ports;
-           ap->ap_iface = iface;
-           ap->ap_port = as->as_port;
-           ap->ap_packet = as->as_packet;
-
-           iface->i_ports = ap;
-       }
-    } else {                           /* close ports */
-       for ( ap = iface->i_ports; ap; ap = ap->ap_next ) {
-           (void)close( ap->ap_fd );
-       }
-    }
-
-#ifdef BSD4_4
-    iface->i_addr.sat_len = sizeof( struct sockaddr_at );
-#endif /* BSD4_4 */
-    iface->i_addr.sat_family = AF_APPLETALK;
-    iface->i_addr.sat_addr.s_net = net;
-    iface->i_addr.sat_addr.s_node = node;
-
-    nr.nr_phase = phase;
-    nr.nr_firstnet = first;
-    nr.nr_lastnet = last;
-    memcpy( iface->i_addr.sat_zero, &nr, sizeof( struct netrange ));
-
-    if ( ifconfig( iface->i_name, SIOCSIFADDR, &iface->i_addr )) {
-      LOG(log_error, logtype_atalkd, "setifaddr: %s (%u-%u): %s. try specifying a \
-smaller net range.", iface->i_name, ntohs(first), ntohs(last), strerror(errno));
-       atalkd_exit( 1 );
-    }
-    if ( ifconfig( iface->i_name, SIOCGIFADDR, &iface->i_addr )) {
-       LOG(log_error, logtype_atalkd, "getifaddr: %s: %s", iface->i_name, strerror(errno) );
-       atalkd_exit( 1 );
-    }
-
-    /* open ports */
-    i = 1; /* enable broadcasts */
-#if 0
-    /* useless message, no? */
-    LOG(log_info, logtype_atalkd, "setsockopt incompatible w/ Solaris STREAMS module.");
-#endif /* __svr4__ */
-    for ( ap = iface->i_ports; ap; ap = ap->ap_next ) {
-       if (( ap->ap_fd = socket( AF_APPLETALK, SOCK_DGRAM, 0 )) < 0 ) {
-           LOG(log_error, logtype_atalkd, "socket: %s", strerror(errno) );
-           atalkd_exit( 1 );
-       }
-#ifndef __svr4__
-       setsockopt(ap->ap_fd, SOL_SOCKET, SO_BROADCAST, &i, sizeof(i));
-#endif /* ! __svr4 */
-
-       memset( &sat, 0, sizeof( struct sockaddr_at ));
-#ifdef BSD4_4
-       sat.sat_len = sizeof( struct sockaddr_at );
-#endif /* BSD4_4 */
-       sat.sat_family = AF_APPLETALK;
-       sat.sat_addr.s_net = iface->i_addr.sat_addr.s_net;
-       sat.sat_addr.s_node = iface->i_addr.sat_addr.s_node;
-       sat.sat_port = ap->ap_port;
-
-       if ( bind( ap->ap_fd, (struct sockaddr *)&sat,
-               sizeof( struct sockaddr_at )) < 0 ) {
-           LOG(log_error, logtype_atalkd, "bind %u.%u:%u: %s",
-                   ntohs( sat.sat_addr.s_net ),
-                   sat.sat_addr.s_node, sat.sat_port, strerror(errno) );
-#ifdef SIOCDIFADDR
-           /* remove all interfaces if we have a problem with bind */
-           for (iface = interfaces; iface; iface = iface->i_next) {
-             if (ifconfig( iface->i_name, SIOCDIFADDR, &iface->i_addr )) {
-#ifdef SIOCATALKDIFADDR
-#if (SIOCDIFADDR != SIOCATALKDIFADDR)
-               ifconfig( iface->i_name, SIOCATALKDIFADDR, &iface->i_addr );
-#endif /* SIOCDIFADDR != SIOCATALKDIFADDR */
-#endif /* SIOCATALKDIFADDR */
-             }
-           }
-#endif /* SIOCDIFADDR */
-           atalkd_exit( 1 );
-       }
-    }
-
-    /* recalculate nfds and fds */
-    FD_ZERO( &fds );
-    for ( nfds = 0, iface = interfaces; iface; iface = iface->i_next ) {
-       for ( ap = iface->i_ports; ap; ap = ap->ap_next ) {
-           FD_SET( ap->ap_fd, &fds );
-           if ( ap->ap_fd > nfds ) {
-               nfds = ap->ap_fd;
-           }
-       }
-    }
-    nfds++;
-}
-
-int ifsetallmulti (const char *iname, int set)
-{
-    int sock;
-    struct ifreq ifr;
-
-    memset(&ifr, 0, sizeof(ifr));
-
-    if (( sock = socket( AF_APPLETALK, SOCK_DGRAM, 0 )) < 0 ) {
-        return( -1 );
-    }
-
-    /* get interface config */
-    strlcpy(ifr.ifr_name, iname, sizeof(ifr.ifr_name));
-    if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0) {
-        close(sock);
-        return (-1);
-    }
-
-    /* should we set or unset IFF_ALLMULTI */
-    if (set)
-           ifr.ifr_flags |= IFF_ALLMULTI;
-    else
-           ifr.ifr_flags &= ~IFF_ALLMULTI;
-
-    /* set interface config */
-    strlcpy(ifr.ifr_name, iname, sizeof(ifr.ifr_name));
-    if (ioctl(sock, SIOCSIFFLAGS, &ifr) < 0) {
-        close(sock);   
-        return -1;
-    }
-
-    close(sock);
-    return (0);
-}
-
-int ifconfig( const char *iname, unsigned long cmd, struct sockaddr_at *sa)
-{
-    struct ifreq       ifr;
-    int                        s;
-
-    memset(&ifr, 0, sizeof(ifr));
-    strcpy( ifr.ifr_name, iname );
-    ifr.ifr_addr = *(struct sockaddr *)sa;
-
-    if (( s = socket( AF_APPLETALK, SOCK_DGRAM, 0 )) < 0 ) {
-       return( 1 );
-    }
-    if ( ioctl( s, cmd, &ifr ) < 0 ) {
-       close(s);
-       return( 1 );
-    }
-    close( s );
-    if ( cmd == SIOCGIFADDR ) {
-       *(struct sockaddr *)sa = ifr.ifr_addr;
-    }
-    return( 0 );
-}
-
-void dumpconfig( struct interface *iface)
-{
-    struct list                *l;
-
-    printf( "%s", iface->i_name );
-    if ( iface->i_flags & IFACE_RSEED ) {
-       printf( " -router" );
-    } else if ( iface->i_flags & IFACE_SEED ) {
-       printf( " -seed" );
-    }
-
-    if ( iface->i_flags & IFACE_DONTROUTE) 
-        printf( " -dontroute");
-
-    printf( " -phase" );
-    if ( iface->i_flags & IFACE_PHASE1 ) {
-       printf( " 1" );
-    } else {
-       printf( " 2" );
-    }
-    printf( " -net %d", ntohs( iface->i_rt->rt_firstnet ));
-    if ( iface->i_rt->rt_lastnet != iface->i_rt->rt_firstnet ) {
-       printf( "-%d", ntohs( iface->i_rt->rt_lastnet ));
-    }
-    printf( " -addr %u.%u", ntohs( iface->i_addr.sat_addr.s_net ),
-           iface->i_addr.sat_addr.s_node );
-    printf( " -caddr %u.%u", ntohs( iface->i_caddr.sat_addr.s_net ),
-           iface->i_caddr.sat_addr.s_node );
-    for ( l = iface->i_rt->rt_zt; l; l = l->l_next ) {
-       printf( " -zone %.*s", ((struct ziptab *)l->l_data)->zt_len,
-               ((struct ziptab *)l->l_data)->zt_name );
-    }
-    printf( "\n" );
-}
-
-#ifdef DEBUG
-void dumproutes(void)
-{
-    struct interface   *iface;
-    struct rtmptab     *rtmp;
-    struct list                *l;
-    struct ziptab      *zt;
-
-    for ( iface = interfaces; iface; iface = iface->i_next ) {
-       for ( rtmp = iface->i_rt; rtmp; rtmp = rtmp->rt_inext ) {
-           if ( rtmp->rt_gate == 0 ) {
-               if ( rtmp->rt_flags & RTMPTAB_EXTENDED ) {
-                   printf( "%u-%u", ntohs( rtmp->rt_firstnet ),
-                           ntohs( rtmp->rt_lastnet ));
-               } else {
-                   printf( "%u", ntohs( rtmp->rt_firstnet ));
-               }
-           } else {
-               if ( rtmp->rt_flags & RTMPTAB_EXTENDED ) {
-                   printf( "%u.%u for %u-%u",
-                           ntohs( rtmp->rt_gate->g_sat.sat_addr.s_net ),
-                           rtmp->rt_gate->g_sat.sat_addr.s_node,
-                           ntohs( rtmp->rt_firstnet ),
-                           ntohs( rtmp->rt_lastnet ));
-               } else {
-                   printf( "%u.%u for %u",
-                           ntohs( rtmp->rt_gate->g_sat.sat_addr.s_net ),
-                           rtmp->rt_gate->g_sat.sat_addr.s_node,
-                           ntohs( rtmp->rt_firstnet ));
-               }
-           }
-
-           if ( rtmp->rt_iprev == 0 && rtmp != iface->i_rt ) {
-               printf( " *" );
-           }
-
-           for ( l = rtmp->rt_zt; l; l = l->l_next ) {
-               zt = (struct ziptab *)l->l_data;
-               printf( " %.*s", zt->zt_len, zt->zt_name );
-           }
-
-           printf( "\n" );
-       }
-    }
-
-    printf( "\n" );
-    fflush( stdout );
-}
-
-void dumpzones(void)
-{
-    struct interface   *iface;
-    struct rtmptab     *rtmp;
-    struct list                *l;
-    struct ziptab      *zt;
-
-    for ( zt = ziptab; zt; zt = zt->zt_next ) {
-       printf( "%.*s", zt->zt_len, zt->zt_name );
-       for ( l = zt->zt_rt; l; l = l->l_next ) {
-           rtmp = (struct rtmptab *)l->l_data;
-           if ( rtmp->rt_flags & RTMPTAB_EXTENDED ) {
-               printf( " %u-%u", ntohs( rtmp->rt_firstnet ),
-                       ntohs( rtmp->rt_lastnet ));
-           } else {
-               printf( " %u", ntohs( rtmp->rt_firstnet ));
-           }
-           if ( rtmp->rt_iprev == 0 && rtmp->rt_gate != 0 ) {
-               printf( "*" );
-           }
-       }
-       printf( "\n" );
-    }
-
-    printf( "\n" );
-    fflush( stdout );
-}
-#endif /* DEBUG */
diff --git a/etc/atalkd/main.h b/etc/atalkd/main.h
deleted file mode 100644 (file)
index 39e6b52..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * $Id: main.h,v 1.6 2009-10-14 01:38:28 didg Exp $
- */
-
-#ifndef ATALKD_MAIN_H
-#define ATALKD_MAIN_H
-
-#include <sys/cdefs.h>
-#include "config.h"
-
-extern int transition;
-extern int stabletimer, newrtmpdata;
-
-int ifconfig ( const char *, unsigned long, struct sockaddr_at * );
-void setaddr ( struct interface *, u_int8_t, u_int16_t,
-        u_int8_t, u_int16_t, u_int16_t );
-void bootaddr ( struct interface * );
-void dumpconfig ( struct interface * );
-
-#ifdef linux
-int ifsetallmulti ( const char *, int);
-#endif
-
-#endif /* ATALKD_MAIN_H */
diff --git a/etc/atalkd/multicast.c b/etc/atalkd/multicast.c
deleted file mode 100644 (file)
index 3b7785c..0000000
+++ /dev/null
@@ -1,381 +0,0 @@
-/*
- * $Id: multicast.c,v 1.13 2009-10-14 01:38:28 didg Exp $
- *
- * Copyright (c) 1990,1993 Regents of The University of Michigan.
- * All Rights Reserved. See COPYRIGHT.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <sys/param.h>
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <sys/socket.h>
-#ifdef TRU64
-#include <sys/mbuf.h>
-#include <net/route.h>
-#endif /* TRU64 */
-#include <net/if.h>
-#include <atalk/logger.h>
-
-/* work around for FreeBSD */
-#if defined(__FreeBSD__) && (__FreeBSD__ >= 2)
-#include <osreldate.h>
-#if __FreeBSD_version >= 300000
-#include <net/if_dl.h>
-#define NO_DATA_LINK_PASSTHROUGH
-#endif /* __FreeBSD_version >= 300000 */
-#endif /* __FreeBSD__ */
-
-#ifdef __svr4__
-#include <sys/sockio.h>
-#endif /* __svr4__ */
-
-#include <atalk/util.h>
-#include <netatalk/endian.h>
-#include "rtmp.h"
-#include "zip.h"
-#include "main.h"
-#include "multicast.h"
-
-
-static const unsigned char     ethermulti[ 6 ] = {
-    0x09, 0x00, 0x07, 0xff, 0xff, 0xff,
-};
-
-static const unsigned char     ethermultitab[ 253 ][ 6 ] = {
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x00, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x01, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x02, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x03, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x04, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x05, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x06, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x07, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x08, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x09, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x0a, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x0b, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x0c, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x0d, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x0e, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x0f, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x10, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x11, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x12, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x13, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x14, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x15, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x16, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x17, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x18, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x19, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x1a, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x1b, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x1c, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x1d, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x1e, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x1f, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x20, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x21, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x22, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x23, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x24, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x25, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x26, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x27, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x28, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x29, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x2a, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x2b, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x2c, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x2d, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x2e, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x2f, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x30, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x31, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x32, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x33, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x34, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x35, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x36, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x37, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x38, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x39, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x3a, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x3b, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x3c, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x3d, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x3e, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x3f, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x40, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x41, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x42, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x43, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x44, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x45, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x46, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x47, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x48, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x49, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x4a, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x4b, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x4c, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x4d, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x4e, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x4f, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x50, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x51, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x52, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x53, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x54, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x55, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x56, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x57, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x58, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x59, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x5a, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x5b, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x5c, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x5d, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x5e, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x5f, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x60, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x61, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x62, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x63, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x64, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x65, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x66, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x67, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x68, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x69, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x6a, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x6b, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x6c, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x6d, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x6e, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x6f, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x70, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x71, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x72, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x73, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x74, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x75, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x76, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x77, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x78, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x79, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x7a, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x7b, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x7c, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x7d, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x7e, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x7f, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x80, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x81, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x82, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x83, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x84, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x85, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x86, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x87, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x88, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x89, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x8a, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x8b, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x8c, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x8d, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x8e, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x8f, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x90, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x91, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x92, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x93, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x94, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x95, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x96, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x97, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x98, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x99, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x9a, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x9b, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x9c, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x9d, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x9e, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0x9f, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xa0, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xa1, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xa2, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xa3, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xa4, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xa5, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xa6, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xa7, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xa8, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xa9, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xaa, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xab, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xac, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xad, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xae, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xaf, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xb0, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xb1, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xb2, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xb3, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xb4, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xb5, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xb6, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xb7, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xb8, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xb9, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xba, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xbb, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xbc, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xbd, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xbe, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xbf, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xc0, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xc1, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xc2, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xc3, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xc4, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xc5, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xc6, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xc7, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xc8, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xc9, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xca, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xcb, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xcc, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xcd, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xce, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xcf, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xd0, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xd1, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xd2, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xd3, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xd4, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xd5, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xd6, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xd7, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xd8, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xd9, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xda, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xdb, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xdc, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xdd, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xde, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xdf, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xe0, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xe1, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xe2, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xe3, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xe4, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xe5, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xe6, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xe7, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xe8, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xe9, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xea, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xeb, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xec, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xed, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xee, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xef, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xf0, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xf1, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xf2, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xf3, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xf4, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xf5, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xf6, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xf7, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xf8, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xf9, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xfa, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xfb, },
-    { 0x09, 0x00, 0x07, 0x00, 0x00, 0xfc, },
-};
-
-
-
-/* configure multicast for a given named interface */
-int addmulti(const char *name, const unsigned char *data)
-{
-#ifdef NO_DATA_LINK_PASSTHROUGH
-    struct sockaddr_dl sa;
-#else /* NO_DATA_LINK_PASSTHROUGH */
-    struct sockaddr sa;
-#endif /* NO_DATA_LINK_PASSTHROUGH */
-
-    memset(&sa, 0, sizeof(sa));
-#ifdef NO_DATA_LINK_PASSTHROUGH
-    sa.sdl_family = AF_LINK;
-    memcpy(LLADDR(&sa), data ? data : ethermulti, sizeof(ethermulti));
-    sa.sdl_alen = sizeof(ethermulti);
-    sa.sdl_len = sizeof(sa);
-#else /* NO_DATA_LINK_PASSTHROUGH */
-    memcpy(sa.sa_data, data ? data : ethermulti, sizeof(ethermulti));
-#endif /* NO_DATA_LINK_PASSTHROUGH */
-    if (ifconfig(name, SIOCADDMULTI, (struct sockaddr_at *)&sa))
-      return -1;
-
-    return 0;
-}
-
-static u_int16_t
-atalk_cksum( u_char *data, int len)
-{
-    u_char     *end;
-    u_int32_t  cksum = 0;
-
-    for ( end = data + len; data < end; data++ ) {
-       cksum = ( cksum + *data ) << 1;
-       if ( cksum & 0x00010000 ) {
-           cksum++;
-       }
-       cksum &= 0x0000ffff;
-    }
-
-    if ( cksum == 0 ) {
-       cksum = 0x0000ffff;
-    }
-
-    return( (u_int16_t) cksum );
-}
-
-/*
- * Fill in multicast for zone.  There is a general issue here:  how can
- * we tell the type of interface we're configuring for?  E.g.  Is it
- * ethernet, tokenring, or FDDI?  (Of course, FDDI and Ethernet look just
- * alike.)
- */
-int
-zone_bcast( struct ziptab *zt)
-{
-    u_char             uname[ 32 ];
-    u_int16_t          cksum;
-    int                        i;
-
-    if (!zt->zt_bcast &&
-       (zt->zt_bcast = (u_char *) malloc(sizeof( ethermulti ))) == NULL) {
-       LOG(log_error, logtype_atalkd, "zone_bcast malloc: %s", strerror(errno) );
-       return -1;
-     }
-
-    for ( i = 0; i < zt->zt_len; i++ ) {
-       uname[ i ] = diatoupper((int) zt->zt_name[ i ]);
-    }
-    cksum = atalk_cksum( uname, zt->zt_len );
-#define elements(a)   (sizeof(a)/sizeof((a)[0]))
-    memcpy(zt->zt_bcast, ethermultitab[ cksum % elements( ethermultitab ) ],
-          sizeof( ethermulti ));
-    return 0;
-}
diff --git a/etc/atalkd/multicast.h b/etc/atalkd/multicast.h
deleted file mode 100644 (file)
index 988b189..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-/*
- * $Id: multicast.h,v 1.5 2009-10-14 01:38:28 didg Exp $
- *
- * Copyright (c) 1990,1997 Regents of The University of Michigan.
- * All Rights Reserved. See COPYRIGHT.
- */
-
-#ifndef ATALKD_MULTICAST_H
-#define ATALKD_MULTICAST_H 1
-
-#include <sys/cdefs.h>
-#include "zip.h"
-
-int addmulti (const char *, const unsigned char *);
-int zone_bcast (struct ziptab *);
-
-#endif /* atalkd/multicast.h */
diff --git a/etc/atalkd/nbp.c b/etc/atalkd/nbp.c
deleted file mode 100644 (file)
index 2d2e5b0..0000000
+++ /dev/null
@@ -1,650 +0,0 @@
-/*
- * $Id: nbp.c,v 1.13 2009-10-14 02:24:05 didg Exp $
- *
- * Copyright (c) 1990,1993 Regents of The University of Michigan.
- * All Rights Reserved. See COPYRIGHT.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <atalk/logger.h>
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <sys/ioctl.h>
-#ifdef TRU64
-#include <sys/mbuf.h>
-#include <net/route.h>
-#endif /* TRU64 */
-#include <net/if.h>
-#include <netatalk/at.h>
-#include <atalk/ddp.h>
-#include <atalk/atp.h>
-#include <atalk/nbp.h>
-#include <atalk/util.h>
-
-#ifdef __svr4__
-#include <sys/sockio.h>
-#endif /* __svr4__ */
-
-#include "atserv.h"
-#include "interface.h"
-#include "list.h"
-#include "rtmp.h"
-#include "gate.h"
-#include "zip.h"
-#include "nbp.h"
-#include "multicast.h"
-
-extern int  transition;
-
-struct nbptab   *nbptab = NULL;
-
-static
-void nbp_ack( int fd, int nh_op, int nh_id, struct sockaddr_at *to)
-{
-    struct nbphdr   nh;
-    char        *data, packet[ SZ_NBPHDR + 1 ];
-
-    nh.nh_op = nh_op;
-    nh.nh_cnt = 0;
-    nh.nh_id = nh_id;
-    data = packet;
-    *data++ = DDPTYPE_NBP;
-    memcpy( data, &nh, SZ_NBPHDR );
-    data += SZ_NBPHDR;
-    if ( sendto( fd, packet, data - packet, 0, (struct sockaddr *)to,
-                 sizeof( struct sockaddr_at )) < 0 ) {
-        LOG(log_error, logtype_atalkd, "sendto: %s", strerror(errno) );
-    }
-}
-
-int nbp_packet(struct atport *ap, struct sockaddr_at *from, char *data, int len)
-{
-    struct nbphdr   nh;
-    struct nbptuple nt;
-    struct nbpnve   nn;
-    struct sockaddr_at  sat;
-    struct nbptab   *ntab;
-    struct ziptab   *zt=NULL;
-    struct interface    *iface;
-    struct list     *l;
-    struct rtmptab  *rtmp;
-    char        *end, *nbpop, *zonep, packet[ ATP_BUFSIZ ];
-    int         n, i, cc, locallkup;
-    u_char      tmplen;
-
-    end = data + len;
-    if ( data >= end ) {
-        LOG(log_info, logtype_atalkd, "nbp_packet malformed packet" );
-        return 1;
-    }
-    if ( *data++ != DDPTYPE_NBP ) {
-        LOG(log_info, logtype_atalkd, "nbp_packet bad ddp type" );
-        return 1;
-    }
-
-    if ( data + SZ_NBPHDR + SZ_NBPTUPLE > end ) {
-        LOG(log_info, logtype_atalkd, "nbp_packet: malformed packet" );
-        return 1;
-    }
-    memcpy( &nh, data, SZ_NBPHDR );
-    nbpop = data;           /* remember for fwd and brrq */
-    data += SZ_NBPHDR;
-    if ( nh.nh_cnt != 1 ) {
-        LOG(log_info, logtype_atalkd, "nbp_packet: bad tuple count (%d/%d)", nh.nh_cnt,
-            nh.nh_op );
-        return 1;
-    }
-
-    memcpy( &nt, data, SZ_NBPTUPLE );
-    data += SZ_NBPTUPLE;
-
-    memset( &nn.nn_sat, 0, sizeof( struct sockaddr_at ));
-#ifdef BSD4_4
-    nn.nn_sat.sat_len = sizeof( struct sockaddr_at );
-#endif /* BSD4_4 */
-    nn.nn_sat.sat_family = AF_APPLETALK;
-    nn.nn_sat.sat_addr.s_net = nt.nt_net;
-    nn.nn_sat.sat_addr.s_node = nt.nt_node;
-    nn.nn_sat.sat_port = nt.nt_port;
-
-    /* object */
-    tmplen = (u_char) *data;
-    if ( data >= end || tmplen > 32 || data + tmplen > end ) {
-        LOG(log_info, logtype_atalkd, "nbp_packet: malformed packet" );
-        return 1;
-    }
-    nn.nn_objlen = tmplen;
-    data++;
-    memcpy( nn.nn_obj, data, nn.nn_objlen );
-    data += nn.nn_objlen;
-
-    /* type */
-    tmplen = (u_char) *data;
-    if ( data >= end || tmplen > 32 || data + tmplen > end ) {
-        LOG(log_info, logtype_atalkd, "nbp_packet: malformed packet" );
-        return 1;
-    }
-    nn.nn_typelen = tmplen;
-    data++;
-    memcpy( nn.nn_type, data, nn.nn_typelen );
-    data += nn.nn_typelen;
-
-    /* zone */
-    tmplen = (u_char) *data;
-    if ( data >= end || tmplen > 32 || data + tmplen > end ) {
-        LOG(log_info, logtype_atalkd, "nbp_packet: malformed packet" );
-        return 1;
-    }
-    zonep = data;           /* remember for fwd */
-    nn.nn_zonelen = tmplen;
-    data++;
-    memcpy( nn.nn_zone, data, nn.nn_zonelen );
-    data += nn.nn_zonelen;
-
-    if ( data != end ) {
-        LOG(log_info, logtype_atalkd, "nbp_packet: malformed packet" );
-        return 1;
-    }
-
-    locallkup = 0;
-    switch ( nh.nh_op ) {
-
-    case NBPOP_RGSTR :
-        /*
-         * Find the ziptab entry for the zone we're trying to register in.
-         */
-        if ( nn.nn_zonelen == 0 ||
-             ( nn.nn_zonelen == 1 && *nn.nn_zone == '*' )) {
-            if ( interfaces->i_next->i_rt->rt_zt ) {
-                zt = (struct ziptab *)interfaces->i_next->i_rt->rt_zt->l_data;
-            } else {
-                zt = NULL;
-            }
-        } else {
-            for ( zt = ziptab; zt; zt = zt->zt_next ) {
-                if ( zt->zt_len == nn.nn_zonelen && strndiacasecmp( zt->zt_name,
-                                                                    nn.nn_zone, zt->zt_len ) == 0 ) {
-                    break;
-                }
-            }
-            if ( zt == NULL ) {
-                nbp_ack( ap->ap_fd, NBPOP_ERROR, (int)nh.nh_id, from );
-                return 0;
-            }
-        }
-
-        /*
-         * Observe that we don't have to do any local-zone verification
-         * if the zone aleady has a multicast address set.
-         */
-        if ( zt != NULL && zt->zt_bcast == NULL ) {
-            /*
-             * Check if zone is associated with any of our local interfaces.
-             */
-            for ( iface = interfaces; iface; iface = iface->i_next ) {
-                for ( l = iface->i_rt->rt_zt; l; l = l->l_next ) {
-                    if ( zt == (struct ziptab *)l->l_data ) {
-                        break;
-                    }
-                }
-                if ( l != NULL ) {
-                    break;
-                }
-            }
-            if ( iface == NULL ) {
-                nbp_ack( ap->ap_fd, NBPOP_ERROR, (int)nh.nh_id, from );
-                return 0;
-            }
-
-            /* calculate and save multicast address */
-            if (zone_bcast(zt) < 0) {
-                LOG(log_error, logtype_atalkd, "nbp_packet: zone_bcast");
-                return -1;
-            }
-
-            for ( iface = interfaces; iface; iface = iface->i_next ) {
-                if (( iface->i_flags & IFACE_PHASE2 ) == 0 ) {
-                    continue;
-                }
-                for ( l = iface->i_rt->rt_zt; l; l = l->l_next ) {
-                    if ( zt == (struct ziptab *)l->l_data ) {
-                        /* add multicast */
-                        if (addmulti(iface->i_name, zt->zt_bcast) < 0) {
-                            LOG(log_error, logtype_atalkd, "nbp_packet: addmulti: %s",
-                                strerror(errno) );
-                            return -1;
-                        }
-                    }
-                }
-            }
-        }
-
-        if (( ntab = (struct nbptab *)malloc( sizeof( struct nbptab )))
-            == NULL ) {
-            LOG(log_error, logtype_atalkd, "nbp_packet: malloc: %s", strerror(errno) );
-            return -1;
-        }
-        memcpy( &ntab->nt_nve, &nn, sizeof( struct nbpnve ));
-        ntab->nt_iface = ap->ap_iface;
-        ntab->nt_next = nbptab;
-        ntab->nt_prev = NULL;
-        if ( nbptab ) {
-            nbptab->nt_prev = ntab;
-        }
-        nbptab = ntab;
-
-        nbp_ack( ap->ap_fd, NBPOP_OK, (int)nh.nh_id, from );
-        break;
-
-    case NBPOP_UNRGSTR :
-        /* deal with local zone info */
-        if (( nn.nn_zonelen == 1 && *nn.nn_zone == '*' ) ||
-            ( nn.nn_zonelen == 0 )) {
-            locallkup = 1;
-            if ( interfaces->i_next->i_rt->rt_zt ) {
-                zt = (struct ziptab *)interfaces->i_next->i_rt->rt_zt->l_data;
-            } else {
-                zt = NULL;
-            }
-        }
-
-        /* remove from our data, perhaps removing a multicast address */
-        for ( ntab = nbptab; ntab; ntab = ntab->nt_next ) {
-            if ( ntab->nt_nve.nn_objlen != nn.nn_objlen ||
-                 strndiacasecmp( ntab->nt_nve.nn_obj, nn.nn_obj,
-                                 nn.nn_objlen )) {
-                continue;
-            }
-            if ( ntab->nt_nve.nn_typelen != nn.nn_typelen ||
-                 strndiacasecmp( ntab->nt_nve.nn_type, nn.nn_type,
-                                 nn.nn_typelen )) {
-                continue;
-            }
-            /*
-             * I *think* we really do check the zone, here.
-             *
-             * i changed it to better handle local zone cases as well.
-             * -- asun
-             */
-
-            /* match local zones */
-            if (locallkup) {
-                /* ntab is also local zone */
-                if (( ntab->nt_nve.nn_zonelen == 1 &&
-                      *ntab->nt_nve.nn_zone == '*' ) ||
-                    (ntab->nt_nve.nn_zonelen == 0))
-                    break;
-
-                /* ntab is default zone */
-                if (zt && (zt->zt_len == ntab->nt_nve.nn_zonelen) &&
-                    (strndiacasecmp(ntab->nt_nve.nn_zone, zt->zt_name,
-                                    zt->zt_len) == 0)) {
-                    break;
-                }
-            }
-
-            /* match particular zone */
-            if ((ntab->nt_nve.nn_zonelen == nn.nn_zonelen) &&
-                (strndiacasecmp( ntab->nt_nve.nn_zone, nn.nn_zone,
-                                 nn.nn_zonelen ) == 0)) {
-                break;
-            }
-        }
-        if ( ntab == NULL ) {
-            nbp_ack( ap->ap_fd, NBPOP_ERROR, (int)nh.nh_id, from );
-            return 0;
-        }
-
-        if ( ntab->nt_next != NULL ) {
-            ntab->nt_next->nt_prev = ntab->nt_prev;
-        }
-        if ( ntab->nt_prev != NULL ) {
-            ntab->nt_prev->nt_next = ntab->nt_next;
-        }
-        if ( ntab == nbptab ) {
-            nbptab = ntab->nt_next;
-        }
-
-        /*
-         * Check for another nbptab entry with the same zone.  If
-         * there isn't one, find the ziptab entry for the zone and
-         * remove the multicast address from the appropriate interfaces.
-         * XXX
-         */
-
-        nbp_ack( ap->ap_fd, NBPOP_OK, (int)nh.nh_id, from );
-        break;
-
-    case NBPOP_BRRQ :
-        /*
-         * Couple of things:  1. Unless we have the -t flag (which is sort
-         * of a misnomer, since you need it if you're doing any phase 1
-         * work), always send NBPOP_FWD.  2. If we get a zone of '*',
-         * and we know what the sender meant by '*', we copy the real
-         * zone into the packet.
-         */
-        if ( nn.nn_zonelen == 0 ||
-             ( nn.nn_zonelen == 1 && *nn.nn_zone == '*' )) {
-            iface = ap->ap_iface;
-            if ( iface && iface->i_rt->rt_zt ) {
-                zt = (struct ziptab *)iface->i_rt->rt_zt->l_data;
-            } else if ( interfaces->i_next->i_rt->rt_zt ) {
-                zt = (struct ziptab *)interfaces->i_next->i_rt->rt_zt->l_data;
-            } else {
-                zt = NULL;
-            }
-
-            /*
-             * Copy zone into packet.  Note that we're changing len, data, and
-             * nbpop.  Later, we'll use ( data - len ) to mean the beginning
-             * of this packet.
-             */
-            if ( zt ) {
-                memcpy( packet, data - len, len );
-                nbpop = packet + ( len - ( data - nbpop ));
-                data = packet + ( len - ( data - zonep ));
-                *data++ = zt->zt_len;
-                memcpy( data, zt->zt_name, zt->zt_len );
-                data += zt->zt_len;
-                len = data - packet;
-            }
-        } else {
-            for ( zt = ziptab; zt; zt = zt->zt_next ) {
-                if ( zt->zt_len == nn.nn_zonelen && strndiacasecmp( zt->zt_name,
-                                                                    nn.nn_zone, zt->zt_len ) == 0 ) {
-                    break;
-                }
-            }
-            if ( zt == NULL ) {
-                nbp_ack( ap->ap_fd, NBPOP_ERROR, (int)nh.nh_id, from );
-                return 0;
-            }
-        }
-
-        /*
-         * If we've got no zones, send out LKUP on the local net.
-         * Otherwise, look through the zone table.
-         */
-        if ( zt == NULL ) {
-#ifdef BSD4_4
-            sat.sat_len = sizeof( struct sockaddr_at );
-#endif /* BSD4_4 */
-            sat.sat_family = AF_APPLETALK;
-            sat.sat_port = ap->ap_port;
-
-            nh.nh_op = NBPOP_LKUP;
-            memcpy( nbpop, &nh, SZ_NBPHDR );
-            sat.sat_addr.s_net = 0;         /* XXX */
-            sat.sat_addr.s_node = ATADDR_BCAST;
-
-            /* Find the first non-loopback ap */
-            for ( iface = interfaces; iface; iface = iface->i_next ) {
-                if ((( iface->i_flags & IFACE_LOOPBACK ) == 0) &&
-                    (iface == ap->ap_iface ||
-                     (iface->i_flags & IFACE_ISROUTER))) {
-                    break;
-                }
-            }
-            if ( iface == NULL ) {
-                return 0;
-            }
-            for ( ap = iface->i_ports; ap; ap = ap->ap_next ) {
-                if ( ap->ap_packet == nbp_packet ) {
-                    break;
-                }
-            }
-            if (ap == NULL)
-                return 0;
-
-            if ( sendto( ap->ap_fd, data - len, len, 0, (struct sockaddr *)&sat,
-                         sizeof( struct sockaddr_at )) < 0 ) {
-                LOG(log_error, logtype_atalkd, "nbp brrq sendto: %s", strerror(errno) );
-            }
-
-            locallkup = 1;
-        } else {
-#ifdef BSD4_4
-            sat.sat_len = sizeof( struct sockaddr_at );
-#endif /* BSD4_4 */
-            sat.sat_family = AF_APPLETALK;
-            sat.sat_port = ap->ap_port;
-            for ( l = zt->zt_rt; l; l = l->l_next ) {
-                rtmp = (struct rtmptab *)l->l_data;
-
-                if ( rtmp->rt_gate == NULL ) {
-                    for ( iface = interfaces; iface;
-                          iface = iface->i_next ) {
-                        if ( iface->i_rt == rtmp ) {
-                            break;
-                        }
-                    }
-                    if ( !iface ) {
-                        LOG(log_error, logtype_atalkd, "nbp_packet: \
-Can't find route's interface!" );
-                        return -1;
-                    }
-                    ap = iface->i_ports;
-                } else {
-                    ap = rtmp->rt_gate->g_iface->i_ports;
-                }
-                for ( ; ap; ap = ap->ap_next ) {
-                    if ( ap->ap_packet == nbp_packet ) {
-                        break;
-                    }
-                }
-                if ( !ap ) {
-                    LOG(log_error, logtype_atalkd, "nbp_packet: Can't find port!" );
-                    return -1;
-                }
-
-                if ( transition &&
-                     ( rtmp->rt_flags & RTMPTAB_EXTENDED ) == 0 ) {
-                    if ( rtmp->rt_gate == NULL ) {
-                        locallkup = 1;
-                    }
-                    nh.nh_op = NBPOP_LKUP;
-                    memcpy( nbpop, &nh, SZ_NBPHDR );
-                    sat.sat_addr.s_net = rtmp->rt_firstnet;
-                    sat.sat_addr.s_node = ATADDR_BCAST;
-                } else {
-                    if ( rtmp->rt_gate == NULL ) {
-                        nh.nh_op = NBPOP_LKUP;
-                        memcpy( nbpop, &nh, SZ_NBPHDR );
-                        sat.sat_addr.s_net = 0;
-                        sat.sat_addr.s_node = ATADDR_BCAST;
-                        locallkup = 1;
-                    } else {
-                        nh.nh_op = NBPOP_FWD;
-                        memcpy( nbpop, &nh, SZ_NBPHDR );
-                        sat.sat_addr.s_net = rtmp->rt_firstnet;
-                        sat.sat_addr.s_node = 0;
-                    }
-                }
-
-                if ( sendto( ap->ap_fd, data - len, len, 0,
-                             (struct sockaddr *)&sat,
-                             sizeof( struct sockaddr_at )) < 0 ) {
-                    LOG(log_error, logtype_atalkd, "nbp brrq sendto %u.%u: %s",
-                        ntohs( sat.sat_addr.s_net ), sat.sat_addr.s_node,
-                        strerror(errno) );
-                    continue;
-                }
-            }
-        }
-
-        if ( !locallkup ) {
-            break;
-        }
-        /*FALL THROUGH*/
-
-    case NBPOP_FWD :
-        /* send lkup on net. we need to make sure we're a router. */
-        if ( !locallkup && (ap->ap_iface->i_flags & IFACE_ISROUTER)) {
-            nh.nh_op = NBPOP_LKUP;
-            memcpy( nbpop, &nh, SZ_NBPHDR );
-            from->sat_addr.s_net = 0;
-            from->sat_addr.s_node = ATADDR_BCAST;
-            if ( sendto( ap->ap_fd, data - len, len, 0, (struct sockaddr *)from,
-                         sizeof( struct sockaddr_at )) < 0 ) {
-                LOG(log_error, logtype_atalkd, "nbp fwd sendto %u.%u: %s",
-                    ntohs( from->sat_addr.s_net ), from->sat_addr.s_node,
-                    strerror(errno) );
-                return 0;
-            }
-        }
-        /*FALL THROUGH*/
-
-    case NBPOP_LKUP :
-        /* search our data */
-        n = i = 0;
-        data = packet + 1 + SZ_NBPHDR;
-        end = packet + sizeof( packet );
-
-        for ( ntab = nbptab; ntab; ntab = ntab->nt_next ) {
-            /* don't send out entries if we don't want to route. */
-            if ((ap->ap_iface != ntab->nt_iface) &&
-                (ntab->nt_iface->i_flags & IFACE_ISROUTER) == 0) {
-                continue;
-            }
-
-            if ( nn.nn_objlen != 1 || *nn.nn_obj != '=' ) {
-                if ( ntab->nt_nve.nn_objlen != nn.nn_objlen ||
-                     strndiacasecmp( ntab->nt_nve.nn_obj, nn.nn_obj,
-                                     nn.nn_objlen )) {
-                    continue;
-                }
-            }
-
-            if ( nn.nn_typelen != 1 || *nn.nn_type != '=' ) {
-                if ( ntab->nt_nve.nn_typelen != nn.nn_typelen ||
-                     strndiacasecmp( ntab->nt_nve.nn_type, nn.nn_type,
-                                     nn.nn_typelen )) {
-                    continue;
-                }
-            }
-
-            if ( nn.nn_zonelen != 0 &&
-                 ( nn.nn_zonelen != 1 || *nn.nn_zone != '*' )) {
-                if ( ntab->nt_nve.nn_zonelen == 0 ||
-                     ( ntab->nt_nve.nn_zonelen == 1 &&
-                       *ntab->nt_nve.nn_zone == '*' )) {
-                    if ( interfaces->i_next->i_rt->rt_zt ) {
-                        zt = (struct ziptab *)interfaces->i_next->i_rt->
-                            rt_zt->l_data;
-                        if ( zt->zt_len != nn.nn_zonelen ||
-                             strndiacasecmp( zt->zt_name, nn.nn_zone,
-                                             zt->zt_len )) {
-                            continue;
-                        }
-                    }
-                } else {
-                    if ( ntab->nt_nve.nn_zonelen != nn.nn_zonelen ||
-                         strndiacasecmp( ntab->nt_nve.nn_zone, nn.nn_zone,
-                                         nn.nn_zonelen )) {
-                        continue;
-                    }
-                }
-            }
-
-            /*
-             * Another tuple won't fit. Send what we've already
-             * got, and start the next packet.
-             */
-            if ( n > 14 || data + SZ_NBPTUPLE + 3 + ntab->nt_nve.nn_objlen +
-                 ntab->nt_nve.nn_typelen + ntab->nt_nve.nn_zonelen > end ) {
-                nh.nh_op = NBPOP_LKUPREPLY;
-                nh.nh_cnt = n;
-                cc = data - packet;
-                data = packet;
-                *data++ = DDPTYPE_NBP;
-                memcpy( data, &nh, SZ_NBPHDR );
-
-                if ( sendto( ap->ap_fd, packet, cc, 0,
-                             (struct sockaddr *)&nn.nn_sat,
-                             sizeof( struct sockaddr_at )) < 0 ) {
-                    LOG(log_error, logtype_atalkd, "nbp lkup sendto %u.%u: %s",
-                        ntohs( nn.nn_sat.sat_addr.s_net ),
-                        nn.nn_sat.sat_addr.s_node,
-                        strerror(errno) );
-                    return 0;
-                }
-
-                n = 0;
-                data = packet + 1 + SZ_NBPHDR;
-                end = packet + sizeof( packet );
-            }
-
-            nt.nt_net = ntab->nt_nve.nn_sat.sat_addr.s_net;
-            nt.nt_node = ntab->nt_nve.nn_sat.sat_addr.s_node;
-            nt.nt_port = ntab->nt_nve.nn_sat.sat_port;
-            /*
-             * Right now, we'll just give each name a unique enum.  In
-             * the future, we might need to actually assign and save
-             * an enum, based on the associated address.  For the moment,
-             * the enums will be unique and constant, since the order
-             * is fixed.
-             */
-            nt.nt_enum = i++;
-
-            memcpy( data, &nt, SZ_NBPTUPLE );
-            data += SZ_NBPTUPLE;
-
-            *data++ = ntab->nt_nve.nn_objlen;
-            memcpy( data, ntab->nt_nve.nn_obj, ntab->nt_nve.nn_objlen );
-            data += ntab->nt_nve.nn_objlen;
-
-            *data++ = ntab->nt_nve.nn_typelen;
-            memcpy(data, ntab->nt_nve.nn_type, ntab->nt_nve.nn_typelen );
-            data += ntab->nt_nve.nn_typelen;
-
-            /*
-             * Macs won't see something with a zone of 0 length.  We
-             * will always return '*' instead.  Perhaps we should
-             * unconditionally return the real zone?
-             */
-            if ( ntab->nt_nve.nn_zonelen ) {
-                *data++ = ntab->nt_nve.nn_zonelen;
-                memcpy( data, ntab->nt_nve.nn_zone, ntab->nt_nve.nn_zonelen );
-                data += ntab->nt_nve.nn_zonelen;
-            } else {
-                *data++ = 1;
-                *data++ = '*';
-            }
-
-            n++;
-        }
-
-        if ( n != 0 ) {
-            nh.nh_op = NBPOP_LKUPREPLY;
-            nh.nh_cnt = n;
-            cc = data - packet;
-            data = packet;
-            *data++ = DDPTYPE_NBP;
-            memcpy( data, &nh, SZ_NBPHDR );
-
-            if ( sendto( ap->ap_fd, packet, cc, 0,
-                         (struct sockaddr *)&nn.nn_sat,
-                         sizeof( struct sockaddr_at )) < 0 ) {
-                LOG(log_error, logtype_atalkd, "nbp lkup sendto %u.%u: %s",
-                    ntohs( nn.nn_sat.sat_addr.s_net ),
-                    nn.nn_sat.sat_addr.s_node,
-                    strerror(errno) );
-                return 0;
-            }
-        }
-        break;
-
-    default :
-        LOG(log_info, logtype_atalkd, "nbp_packet: bad op (%d)", nh.nh_op );
-        return 1;
-    }
-
-    return 0;
-}
diff --git a/etc/atalkd/nbp.h b/etc/atalkd/nbp.h
deleted file mode 100644 (file)
index 13f511d..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * $Id: nbp.h,v 1.3 2009-10-13 22:55:37 didg Exp $
- *
- * Copyright (c) 1990,1993 Regents of The University of Michigan.
- * All Rights Reserved. See COPYRIGHT.
- */
-
-#ifndef ATALKD_NBP_H
-#define ATALKD_NBP_H 1
-
-struct nbptab {
-    struct nbptab      *nt_prev, *nt_next;
-    struct nbpnve      nt_nve;
-    struct interface    *nt_iface;
-};
-
-extern struct nbptab   *nbptab;
-
-int nbp_packet(struct atport *ap, struct sockaddr_at *from, char *data, int len);
-
-#endif
diff --git a/etc/atalkd/route.c b/etc/atalkd/route.c
deleted file mode 100644 (file)
index 4e7dfac..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * $Id: route.c,v 1.8 2009-10-13 22:55:37 didg Exp $
- *
- * Copyright (c) 1990,1996 Regents of The University of Michigan.
- * All Rights Reserved. See COPYRIGHT.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#include <string.h>
-#include <sys/param.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <net/route.h>
-#include <sys/ioctl.h>
-#include <netatalk/at.h>
-
-#include "rtmp.h"
-#include "route.h"
-
-#ifndef BSD4_4
-int route( int message, struct sockaddr *dst, struct sockaddr *gate, int flags)
-{
-#ifdef TRU64
-    struct ortentry    rtent;
-#else /* TRU64 */
-    struct rtentry     rtent;
-#endif /* TRU64 */
-
-    memset( &rtent, 0, sizeof( struct rtentry ));
-    rtent.rt_dst = *dst;
-    rtent.rt_gateway = *gate;
-    rtent.rt_flags = flags;
-    return( ioctl( rtfd, message, &rtent ));
-}
-
-#else /* BSD4_4 */
-
-struct sockaddr_m {
-    u_char     sam_len;
-    u_char     sam_family;
-    u_short    sam_pad;
-    u_short    sam_mask;
-    u_short    sam_pad2;
-} mask = { sizeof( struct sockaddr_m ), 0, 0, 0xffff, 0 };
-
-struct rt_msg_at {
-    struct rt_msghdr   rtma_rtm;
-    struct sockaddr_at rtma_dst;
-    struct sockaddr_at rtma_gate;
-    struct sockaddr_m  rtma_mask;
-} rtma;
-
-route( int message, struct sockaddr_at *dst, struct sockaddr_at *gate, int flags)
-{
-    int                        rc;
-
-    memset( &rtma, 0, sizeof( struct rt_msg_at ));
-    rtma.rtma_rtm.rtm_msglen = sizeof( struct rt_msg_at );
-    rtma.rtma_rtm.rtm_version = RTM_VERSION;
-    rtma.rtma_rtm.rtm_type = message;
-    rtma.rtma_rtm.rtm_pid = getpid();
-    rtma.rtma_rtm.rtm_addrs = RTA_DST|RTA_GATEWAY;
-    if ( flags & RTF_HOST ) {
-       rtma.rtma_rtm.rtm_msglen = sizeof( struct rt_msg_at ) -
-               sizeof( struct sockaddr_m );
-    } else {
-       rtma.rtma_rtm.rtm_msglen = sizeof( struct rt_msg_at );
-       rtma.rtma_rtm.rtm_addrs |= RTA_NETMASK;
-       rtma.rtma_mask = mask;
-    }
-
-    rtma.rtma_rtm.rtm_flags = flags;
-    rtma.rtma_dst = *dst;
-    rtma.rtma_gate = *gate;
-    if (( rc = write( rtfd, &rtma, rtma.rtma_rtm.rtm_msglen )) !=
-           rtma.rtma_rtm.rtm_msglen ) {
-       return( -1 );
-    }
-    return( 0 );
-}
-#endif /* BSD4_4 */
diff --git a/etc/atalkd/route.h b/etc/atalkd/route.h
deleted file mode 100644 (file)
index 5f3c0f9..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * $Id: route.h,v 1.3 2009-10-13 22:55:37 didg Exp $
- */
-
-#ifndef ATALKD_ROUTE_H
-#define ATALKD_ROUTE_H 1
-
-#include <sys/cdefs.h>
-
-#ifndef BSD4_4
-int route ( int, struct sockaddr *, struct sockaddr *, int );
-#else /* BSD4_4 */
-int route ( int, struct sockaddr_at *, struct sockaddr_at *, int);
-#endif /* BSD4_4 */
-
-#endif /* ATALKD_ROUTE_H */
diff --git a/etc/atalkd/rtmp.c b/etc/atalkd/rtmp.c
deleted file mode 100644 (file)
index 727562b..0000000
+++ /dev/null
@@ -1,997 +0,0 @@
-/*
- * $Id: rtmp.c,v 1.17 2009-12-08 03:21:16 didg Exp $
- *
- * Copyright (c) 1990,1993 Regents of The University of Michigan.
- * All Rights Reserved. See COPYRIGHT.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <atalk/logger.h>
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <sys/ioctl.h>
-#ifdef TRU64
-#include <sys/mbuf.h>
-#include <net/route.h>
-#endif /* TRU64 */
-#include <net/if.h>
-#include <net/route.h>
-#include <netatalk/endian.h>
-#include <netatalk/at.h>
-
-#ifdef __svr4__
-#include <sys/sockio.h>
-#endif /* __svr4__ */
-
-#include <atalk/ddp.h>
-#include <atalk/atp.h>
-#include <atalk/rtmp.h>
-
-#include "interface.h"
-#include "gate.h"
-#include "rtmp.h"
-#include "zip.h"
-#include "list.h"
-#include "atserv.h"
-#include "route.h"
-#include "main.h"
-
-void rtmp_delzonemap(struct rtmptab *rtmp)
-{
-    struct list                *lz, *flz, *lr, *flr;
-    struct ziptab      *zt;
-
-    lz = rtmp->rt_zt;
-    while ( lz ) {                                     /* for each zone */
-       zt = (struct ziptab *)lz->l_data;
-       lr = zt->zt_rt;
-       while ( lr ) {                                  /* for each route */
-           if ( (struct rtmptab *)lr->l_data == rtmp ) {
-               if ( lr->l_prev == NULL ) {             /* head */
-                   if ( lr->l_next == NULL ) {         /* last route in zone */
-                       if ( zt->zt_prev == NULL ) {
-                           ziptab = zt->zt_next;
-                       } else {
-                           zt->zt_prev->zt_next = zt->zt_next;
-                       }
-                       if ( zt->zt_next == NULL ) {
-                           ziplast = zt->zt_prev;
-                       } else {
-                           zt->zt_next->zt_prev = zt->zt_prev;
-                       }
-                       free( zt->zt_bcast );
-                       free( zt->zt_name );
-                       free( zt );
-                   } else {
-                       zt->zt_rt = lr->l_next;
-                   }
-               } else {
-                   lr->l_prev->l_next = lr->l_next;
-               }
-               if ( lr->l_next != NULL ) {
-                   lr->l_next->l_prev = lr->l_prev;
-               }
-               flr = lr;
-               lr = lr->l_next;
-               free( flr );
-           } else {
-               lr = lr->l_next;
-           }
-       }
-       flz = lz;
-       lz = lz->l_next;
-       free( flz );
-    }
-    rtmp->rt_zt = NULL;
-}
-
-
-/*
- * Complete configuration for phase 1 interface using RTMP information.
- */
-static int rtmp_config( struct rtmp_head *rh, struct interface *iface)
-{
-    extern int         stabletimer;
-    int cc;
-
-    /*
-     * If we're configuring a phase 2 interface, don't complete
-     * configuration with RTMP.
-     */
-    if ( iface->i_flags & IFACE_PHASE2 ) {
-       LOG(log_info, logtype_atalkd, "rtmp_config ignoring data" );
-       return 0;
-    }
-
-    /*
-     * Check our seed information, and reconfigure.
-     */
-    if ( rh->rh_net != iface->i_addr.sat_addr.s_net ) {
-       if (( iface->i_flags & IFACE_SEED ) &&
-               rh->rh_net != iface->i_caddr.sat_addr.s_net) {
-           LOG(log_error, logtype_atalkd, "rtmp_config net mismatch %u != %u",
-                   ntohs( rh->rh_net ),
-                   ntohs( iface->i_addr.sat_addr.s_net ));
-           return 1;
-       }
-       iface->i_addr.sat_addr.s_net = rh->rh_net;
-
-       /*
-        * It is possible that we will corrupt our route database
-        * by just forcing this change.  XXX
-        */
-       iface->i_rt->rt_firstnet = iface->i_rt->rt_lastnet = rh->rh_net;
-
-       setaddr( iface, IFACE_PHASE1, iface->i_addr.sat_addr.s_net,
-               iface->i_addr.sat_addr.s_node, rh->rh_net, rh->rh_net );
-       stabletimer = UNSTABLE;
-    }
-
-    /* add addr to loopback route */
-    if ((cc = looproute( iface, RTMP_ADD )) < 0 )
-      return -1;
-
-    if (cc) {
-       LOG(log_error, logtype_atalkd, "rtmp_config: can't route %u.%u to loopback: %s",
-               ntohs( iface->i_addr.sat_addr.s_net ),
-               iface->i_addr.sat_addr.s_node,
-               strerror(errno) );
-    }
-
-    LOG(log_info, logtype_atalkd, "rtmp_config configured %s", iface->i_name );
-    iface->i_flags |= IFACE_CONFIG;
-    if ( iface == ciface ) {
-       ciface = ciface->i_next;
-       bootaddr( ciface );
-    }
-
-    return 0;
-}
-
-/*
- * Delete rtmp from the per-interface in-use table, remove all
- * zone references, and remove the route from the kernel.
- */
-static void rtmp_delinuse(struct rtmptab *rtmp)
-{
-    struct rtmptab     *irt;
-
-    irt = rtmp->rt_gate->g_iface->i_rt;
-    if ( irt->rt_inext == rtmp ) {                     /* first */
-       if ( rtmp->rt_iprev == rtmp ) {                 /* only */
-           irt->rt_inext = NULL;
-       } else {
-           irt->rt_inext = rtmp->rt_inext;
-           rtmp->rt_inext->rt_iprev = rtmp->rt_iprev;
-       }
-    } else {
-       if ( rtmp->rt_inext == NULL ) {                 /* last */
-           rtmp->rt_iprev->rt_inext = NULL;
-           irt->rt_inext->rt_iprev = rtmp->rt_iprev;
-       } else {
-           rtmp->rt_iprev->rt_inext = rtmp->rt_inext;
-           rtmp->rt_inext->rt_iprev = rtmp->rt_iprev;
-       }
-    }
-    rtmp->rt_iprev = NULL;
-    rtmp->rt_inext = NULL;
-
-    /* remove zone map */
-    rtmp_delzonemap(rtmp);
-
-    /* remove old route */
-    gateroute( RTMP_DEL, rtmp );
-}
-
-/*
- * Add rtmp to the per-interface in-use table.  No verification is done...
- */
-static void rtmp_addinuse( struct rtmptab *rtmp)
-{
-    struct rtmptab     *irt;
-
-    gateroute( RTMP_ADD, rtmp );
-
-    irt = rtmp->rt_gate->g_iface->i_rt;
-    if ( irt->rt_inext == NULL ) {     /* empty list */
-       rtmp->rt_inext = NULL;
-       rtmp->rt_iprev = rtmp;
-       irt->rt_inext = rtmp;
-    } else {
-       rtmp->rt_inext = irt->rt_inext;
-       rtmp->rt_iprev = irt->rt_inext->rt_iprev;
-       irt->rt_inext->rt_iprev = rtmp;
-       irt->rt_inext = rtmp;
-    }
-}
-
-
-/*
- * Change the zone mapping to replace "from" with "to".  This code assumes
- * the consistency of both the route -> zone map and the zone -> route map.
- * This is probably a bad idea.  How can we insure that the data is good
- * at this point?  What do we do if we get several copies of a route in
- * an RTMP packet?
- */
-static int rtmp_copyzones( struct rtmptab *to,struct rtmptab *from)
-{
-    struct list                *lz, *lr;
-
-    to->rt_zt = from->rt_zt;
-    from->rt_zt = NULL;
-    if ( from->rt_flags & RTMPTAB_HASZONES ) {
-       to->rt_flags |= RTMPTAB_HASZONES;
-    }
-    for ( lz = to->rt_zt; lz; lz = lz->l_next ) {
-       for ( lr = ((struct ziptab *)lz->l_data)->zt_rt; lr; lr = lr->l_next ) {
-           if ( (struct rtmptab *)lr->l_data == from ) {
-               lr->l_data = (void *)to;        /* cast BS */
-               break;
-           }
-       }
-       if ( lr == NULL ) {
-           LOG(log_error, logtype_atalkd, "rtmp_copyzones z -> r without r -> z, abort" );
-           return -1;
-       }
-    }
-
-    return 0;
-}
-
-
-/*
- * Remove rtmp from the in-use table and the per-gate table.
- * Free any associated space.
- */
-void rtmp_free( struct rtmptab *rtmp)
-{
-    struct gate                *gate;
-
-    LOG(log_info, logtype_atalkd, "rtmp_free: %u-%u", ntohs(rtmp->rt_firstnet),
-          ntohs(rtmp->rt_lastnet));
-    if ( rtmp->rt_iprev ) {
-       rtmp_delinuse( rtmp );
-    }
-
-    /* remove from per-gate */
-    gate = rtmp->rt_gate;
-    if ( gate->g_rt == rtmp ) {                                /* first */
-       if ( rtmp->rt_prev == rtmp ) {                  /* only */
-           gate->g_rt = NULL;
-       } else {
-           gate->g_rt = rtmp->rt_next;
-           rtmp->rt_next->rt_prev = rtmp->rt_prev;
-       }
-    } else {
-       if ( rtmp->rt_next == NULL ) {                  /* last */
-           rtmp->rt_prev->rt_next = NULL;
-           gate->g_rt->rt_prev = rtmp->rt_prev;
-       } else {
-           rtmp->rt_prev->rt_next = rtmp->rt_next;
-           rtmp->rt_next->rt_prev = rtmp->rt_prev;
-       }
-    }
-
-    free( rtmp );
-}
-
-
-/*
- * Find a replacement for "replace".  If we can't find a replacement,
- * return 1.  If we do find a replacement, return 0. -1 on error.
- */
-int rtmp_replace(struct rtmptab *replace)
-{
-    struct interface   *iface;
-    struct gate                *gate;
-    struct rtmptab     *rtmp, *found = NULL;
-
-    LOG(log_info, logtype_atalkd, "rtmp_replace %u-%u", ntohs(replace->rt_firstnet),
-          ntohs(replace->rt_lastnet));
-    for ( iface = interfaces; iface; iface = iface->i_next ) {
-        if ((replace->rt_iface != iface) && 
-           ((iface->i_flags & IFACE_ISROUTER) == 0))
-         continue;
-
-       for ( gate = iface->i_gate; gate; gate = gate->g_next ) {
-           for ( rtmp = gate->g_rt; rtmp; rtmp = rtmp->rt_next ) {
-               if ( rtmp->rt_firstnet == replace->rt_firstnet &&
-                       rtmp->rt_lastnet == replace->rt_lastnet ) {
-                   if ( found == NULL || rtmp->rt_hops < found->rt_hops ) {
-                       found = rtmp;
-                   }
-                   break;
-               }
-           }
-       }
-    }
-
-    if ( found != replace ) {
-       if (rtmp_copyzones( found, replace ) < 0)
-         return -1;
-       rtmp_delinuse( replace );
-       rtmp_addinuse( found );
-       if ( replace->rt_state == RTMPTAB_BAD ) {
-           rtmp_free( replace );
-       }
-       return( 0 );
-    } else {
-       if ( replace->rt_hops == RTMPHOPS_POISON ) {
-           gateroute( RTMP_DEL, replace );
-       }
-       return( 1 );
-    }
-}
-
-
-static int rtmp_new(struct rtmptab *rtmp)
-{
-    struct interface   *i;
-    struct rtmptab     *r;
-    extern int         newrtmpdata;
-
-    newrtmpdata = 1;
-
-    /*
-     * Do we already have a gateway for this route?
-     */
-    for ( i = interfaces; i; i = i->i_next ) {
-        if ((rtmp->rt_iface != i) && 
-           ((i->i_flags & IFACE_ISROUTER) == 0))
-         continue;
-
-       for ( r = i->i_rt; r; r = r->rt_inext ) {
-           /* Should check RTMPTAB_EXTENDED here. XXX */
-           if (( ntohs( r->rt_firstnet ) <= ntohs( rtmp->rt_firstnet ) &&
-                   ntohs( r->rt_lastnet ) >= ntohs( rtmp->rt_firstnet )) ||
-                   ( ntohs( r->rt_firstnet ) <= ntohs( rtmp->rt_lastnet ) &&
-                   ntohs( r->rt_lastnet ) >= ntohs( rtmp->rt_lastnet ))) {
-               break;
-           }
-       }
-       if ( r ) {
-           break;
-       }
-    }
-
-    /*
-     * This part of this routine is almost never run.
-     */
-    if ( i ) { /* can we get here without r being set? */
-       if ( r->rt_firstnet != rtmp->rt_firstnet ||
-               r->rt_lastnet != rtmp->rt_lastnet ) {
-           LOG(log_info, logtype_atalkd, "rtmp_new netrange mismatch %u-%u != %u-%u",
-                   ntohs( r->rt_firstnet ), ntohs( r->rt_lastnet ),
-                   ntohs( rtmp->rt_firstnet ), ntohs( rtmp->rt_lastnet ));
-           return 1;
-       }
-
-       /*
-        * Note that our whole methodology is wrong, if we want to do
-        * route "load balancing."  This entails changing our route
-        * each time we receive a tuple of equal value.  In fact, we can't
-        * do this, using our method, since we only check against in-use
-        * routes when a tuple is new from a router.
-        */
-       if ( r->rt_hops < rtmp->rt_hops ) {
-           return 1;
-       }
-
-       if (rtmp_copyzones( rtmp, r ) < 0)
-         return -1;
-       rtmp_delinuse( r );
-    }
-
-    rtmp_addinuse( rtmp );
-    return 0;
-}
-
-
-int rtmp_packet(struct atport *ap, struct sockaddr_at *from, char *data, int len)
-{
-    struct rtmp_head   rh;
-    struct rtmp_tuple  rt, xrt;
-    struct gate                *gate;
-    struct interface   *iface;
-    struct interface   *iface2;
-    struct rtmptab     *rtmp;
-    char               *end, packet[ ATP_BUFSIZ ];
-    int                 cc;
-
-    end = data + len;
-
-    if ( data >= end ) {
-       LOG(log_info, logtype_atalkd, "rtmp_packet no data" );
-       return 1;
-    }
-
-    iface = ap->ap_iface;
-
-    /* linux 2.6 sends broadcast queries to the first available socket 
-       (in our case the last configured) 
-       try to find the right one.
-       Note: now a misconfigured or plugged router can broadcast
-       a wrong route
-    */
-    for ( iface2 = interfaces; iface2; iface2 = iface2->i_next ) {
-        if ( iface2->i_rt && from->sat_addr.s_net >= iface2->i_rt->rt_firstnet && 
-                from->sat_addr.s_net <= iface2->i_rt->rt_lastnet) 
-        {
-              iface = iface2;
-        }
-    }
-    /* end of linux 2.6 workaround */
-    
-    /* ignore our own packets */
-    if ( from->sat_addr.s_net == iface->i_addr.sat_addr.s_net &&
-           from->sat_addr.s_node == iface->i_addr.sat_addr.s_node  ) {
-       return 0;
-    }
-
-    switch( *data++ ) {
-    case DDPTYPE_RTMPRD :
-       /*
-        * Response and Data.
-        */
-       if ( data + sizeof( struct rtmprdhdr ) > end ) {
-           LOG(log_info, logtype_atalkd, "rtmp_packet no data header" );
-           return 1;
-       }
-       memcpy( &rh, data, sizeof( struct rtmprdhdr ));
-       data += sizeof( struct rtmprdhdr );
-
-       /* check rh address against from address */
-       if ( rh.rh_nodelen != 8 ) {
-           LOG(log_info, logtype_atalkd, "rtmp_packet bad node len (%d)", rh.rh_nodelen );
-           return 1;
-       }
-       if (( from->sat_addr.s_net != 0 && 
-             from->sat_addr.s_net != rh.rh_net ) ||
-             from->sat_addr.s_node != rh.rh_node ) {
-           LOG(log_info, logtype_atalkd, "rtmp_packet address mismatch" );
-           return 1;
-       }
-
-       if (( iface->i_flags & ( IFACE_ADDR|IFACE_CONFIG )) == IFACE_ADDR ) {
-           if ( iface->i_flags & IFACE_NOROUTER ) {
-               /* remove addr to loopback route */
-               if ((cc = looproute( iface, RTMP_DEL )) < 0) {
-                 LOG(log_error, logtype_atalkd, "rtmp_packet: looproute");
-                 return -1;
-               } 
-
-               if (cc)
-                 LOG(log_error, logtype_atalkd, "rtmp_packet: can't remove loopback: %s",
-                         strerror(errno) );
-
-               iface->i_flags &= ~IFACE_NOROUTER;
-               iface->i_time = 0;
-               LOG(log_info, logtype_atalkd, "rtmp_packet router has become available" );
-           }
-           if ( iface->i_flags & IFACE_PHASE1 ) {
-             if (rtmp_config( &rh, iface ) < 0) {
-                 LOG(log_error, logtype_atalkd, "rtmp_packet: rtmp_config");
-                 return -1;
-             }
-           } else if (zip_getnetinfo( iface ) < 0) {
-             LOG(log_error, logtype_atalkd, "rtmp_packet: zip_getnetinfo");
-             return -1;
-           }
-           return 0;
-       }
-
-       if (( iface->i_flags & IFACE_CONFIG ) == 0 ) {
-           return 0;
-       }
-
-       /*
-        * Parse first tuple.  For phase 2, verify that net is correct.
-        */
-       if ( data + SZ_RTMPTUPLE > end ) {
-           LOG(log_info, logtype_atalkd, "rtmp_packet missing first tuple" );
-           return 1;
-       }
-       memcpy( &rt, data, SZ_RTMPTUPLE );
-       data += SZ_RTMPTUPLE;
-
-       if ( rt.rt_net == 0 ) {
-           if ( rt.rt_dist != 0x82 ) {
-               LOG(log_info, logtype_atalkd, "rtmp_packet bad phase 1 version" );
-               return 1;
-           }
-
-           /*
-            * Grab the next tuple, since we don't want to pass the version
-            * number to the parsing code.  We're assuming that there are
-            * no extended tuples in this packet.
-            */
-           if ( data + SZ_RTMPTUPLE > end ) {
-               LOG(log_info, logtype_atalkd, "rtmp_packet missing second tuple" );
-               return 1;
-           }
-           memcpy( &rt, data, SZ_RTMPTUPLE );
-           data += SZ_RTMPTUPLE;
-       } else if ( rt.rt_dist & 0x80 ) {
-           if ( data + SZ_RTMPTUPLE > end ) {
-               LOG(log_info, logtype_atalkd, "rtmp_packet missing first range-end" );
-               return 1;
-           }
-           memcpy( &xrt, data, SZ_RTMPTUPLE );
-           data += SZ_RTMPTUPLE;
-
-           if ( xrt.rt_dist != 0x82 ) {
-               LOG(log_info, logtype_atalkd, "rtmp_packet bad phase 2 version" );
-               return 1;
-           }
-
-           /*
-            * Check for net range conflict.
-            */
-           if ( rt.rt_net != iface->i_rt->rt_firstnet ||
-                   xrt.rt_net != iface->i_rt->rt_lastnet ) {
-               LOG(log_info, logtype_atalkd, "rtmp_packet interface mismatch" );
-               return 1;
-           }
-       } else {
-#ifdef PHASE1NET
-           /*
-            * Gatorboxes put a net number in the first tuple, even on
-            * phase 1 nets.  This is wrong, but since we've got it, we
-            * might just as well check it.
-           if ( rt.rt_net != iface->i_rt->rt_firstnet ||
-                   rt.rt_net != iface->i_rt->rt_lastnet ) {
-               LOG(log_info, logtype_atalkd, "rtmp_packet phase 1 interface mismatch" );
-               return 1;
-           }
-            */
-#else /* PHASE1NET */
-           LOG(log_info, logtype_atalkd, "rtmp_packet bad first tuple" );
-           return 1;
-#endif /* PHASE1NET */
-       }
-
-       /*
-        * Find gateway.
-        */
-       for ( gate = iface->i_gate; gate; gate = gate->g_next ) {
-           if ( gate->g_sat.sat_addr.s_net == from->sat_addr.s_net &&
-                   gate->g_sat.sat_addr.s_node == from->sat_addr.s_node ) {
-               break;
-           }
-       }
-       if ( !gate ) {  /* new gateway */
-           if (( gate = (struct gate *)malloc( sizeof( struct gate ))) == NULL ) {
-               LOG(log_error, logtype_atalkd, "rtmp_packet: malloc: %s", strerror(errno) );
-               return -1;
-           }
-           gate->g_next = iface->i_gate;
-           gate->g_prev = NULL;
-           gate->g_rt = NULL;
-           gate->g_iface = iface;      /* need this? */
-           gate->g_sat = *from;
-           if ( iface->i_gate ) {
-               iface->i_gate->g_prev = gate;
-           }
-           iface->i_gate = gate;
-           LOG(log_info, logtype_atalkd, "rtmp_packet gateway %u.%u up",
-                   ntohs( gate->g_sat.sat_addr.s_net ),
-                   gate->g_sat.sat_addr.s_node );
-       }
-
-       /*
-        * Reset the timeout on this gateway.  We'll remove the gateway
-        * entry, if the timeout gets to RTMPTAB_BAD.
-        */
-       gate->g_state = RTMPTAB_GOOD;
-
-       /*
-        * Parse remaining tuples.
-        */
-       for (;;) {
-           /*
-            * Is route on this gateway?
-            */
-           for ( rtmp = gate->g_rt; rtmp; rtmp = rtmp->rt_next ) {
-               if ( ntohs( rtmp->rt_firstnet ) <= ntohs( rt.rt_net ) &&
-                       ntohs( rtmp->rt_lastnet ) >= ntohs( rt.rt_net )) {
-                   break;
-               }
-               if (( rt.rt_dist & 0x80 ) &&
-                       ntohs( rtmp->rt_firstnet ) <= ntohs( xrt.rt_net ) &&
-                       ntohs( rtmp->rt_lastnet ) >= ntohs( xrt.rt_net )) {
-                   break;
-               }
-           }
-
-           if ( rtmp ) {       /* found it */
-               /*
-                * Check for range conflicts.  (This is getting a little
-                * ugly.)
-                */
-               if ( rtmp->rt_firstnet != rt.rt_net ) {
-                   LOG(log_info, logtype_atalkd, "rtmp_packet firstnet mismatch %u!=%u",
-                           ntohs( rtmp->rt_firstnet ), ntohs( rt.rt_net ));
-                   return 1;
-               }
-               if ( rt.rt_dist & 0x80 ) {
-                   if (( rtmp->rt_flags & RTMPTAB_EXTENDED ) == 0 ) {
-                       LOG(log_info, logtype_atalkd, "rtmp_packet extended mismatch %u",
-                               ntohs( rtmp->rt_firstnet ));
-                       return 1;
-                   }
-                   if ( rtmp->rt_lastnet != xrt.rt_net ) {
-                       LOG(log_info, logtype_atalkd, "rtmp_packet lastnet mismatch %u!=%u",
-                           ntohs( rtmp->rt_lastnet ), ntohs( xrt.rt_net ));
-                       return 1;
-                   }
-               } else {
-                   if ( rtmp->rt_flags & RTMPTAB_EXTENDED ) {
-                       LOG(log_info, logtype_atalkd, "rtmp_packet !extended mismatch %u",
-                               ntohs( rtmp->rt_firstnet ));
-                       return 1;
-                   }
-                   if ( rtmp->rt_lastnet != rt.rt_net ) {
-                       LOG(log_info, logtype_atalkd, "rtmp_packet lastnet mismatch %u!=%u",
-                           ntohs( rtmp->rt_lastnet ), ntohs( rt.rt_net ));
-                       return 1;
-                   }
-               }
-
-               rtmp->rt_state = RTMPTAB_GOOD;
-
-               /*
-                * Check hop count.  If the count has changed, update
-                * the routing database.
-                */
-               if (( rtmp->rt_hops != ( rt.rt_dist & 0x7f ) + 1 ) &&
-                       ( rtmp->rt_hops != RTMPHOPS_POISON ||
-                       ( rt.rt_dist & 0x7f ) + 1 <= RTMPHOPS_MAX )) {
-                   if ( rtmp->rt_iprev ) {     /* route is in use */
-                       if ( rtmp->rt_hops > ( rt.rt_dist & 0x7f ) + 1 ) {
-                           /*
-                            * If this was POISON, we've deleted it from
-                            * the kernel.  Add it back in.
-                            */
-                           if ( rtmp->rt_hops == RTMPHOPS_POISON ) {
-                               gateroute( RTMP_ADD, rtmp );
-                           }
-                           rtmp->rt_hops = ( rt.rt_dist & 0x7f ) + 1;
-                       } else {
-                           /*
-                            * Hop count has gone up for this route.
-                            * Search for a new best route.  If we can't
-                            * find one, just keep this route.  "poison"
-                            * route are deleted in as_timer().
-                            */
-                           if (( rt.rt_dist & 0x7f ) + 1 > RTMPHOPS_MAX ) {
-                               rtmp->rt_hops = RTMPHOPS_POISON;
-                           } else {
-                               rtmp->rt_hops = ( rt.rt_dist & 0x7f ) + 1;
-                           }
-                           if (rtmp_replace( rtmp ) < 0) {
-                             LOG(log_error, logtype_atalkd, "rtmp_packet: rtmp_replace");
-                             return -1;
-                           }
-                       }
-                   } else {                    /* route not in use */
-                       rtmp->rt_hops = ( rt.rt_dist & 0x7f ) + 1;
-                       if ( rtmp->rt_hops > ( rt.rt_dist & 0x7f ) + 1 ) {
-                         if (rtmp_new( rtmp ) < 0) {
-                             LOG(log_error, logtype_atalkd, "rtmp_packet: rtmp_new");
-                             return -1;
-                         }
-                       }
-                   }
-               }
-
-               /*
-                * Make the *next* node the head, since
-                * we're not likely to be asked for the same tuple twice
-                * in a row.
-                */
-               if ( rtmp->rt_next != NULL ) {
-                   gate->g_rt->rt_prev->rt_next = gate->g_rt;
-                   gate->g_rt = rtmp->rt_next;
-                   rtmp->rt_next = NULL;
-               }
-           } else if (( rt.rt_dist & 0x7f ) + 1 > RTMPHOPS_MAX ) {
-               LOG(log_info, logtype_atalkd, "rtmp_packet bad hop count from %u.%u for %u",
-                       ntohs( from->sat_addr.s_net ), from->sat_addr.s_node,
-                       ntohs( rt.rt_net ));
-           } else {            /* new for router */
-               if (( rtmp = newrt(iface)) == NULL ) {
-                   LOG(log_error, logtype_atalkd, "rtmp_packet: newrt: %s", strerror(errno) );
-                   return -1;
-               }
-               rtmp->rt_firstnet = rt.rt_net;
-               if ( rt.rt_dist & 0x80 ) {
-                   rtmp->rt_lastnet = xrt.rt_net;
-                   rtmp->rt_flags = RTMPTAB_EXTENDED;
-               } else {
-                   rtmp->rt_lastnet = rt.rt_net;
-               }
-               rtmp->rt_hops = ( rt.rt_dist & 0x7f ) + 1;
-               rtmp->rt_state = RTMPTAB_GOOD;
-               rtmp->rt_gate = gate;
-
-               /*
-                * Add rtmptab entry to end of list (leave head alone).
-                */
-               if ( gate->g_rt == NULL ) {
-                   rtmp->rt_prev = rtmp;
-                   gate->g_rt = rtmp;
-               } else {
-                   rtmp->rt_prev = gate->g_rt->rt_prev;
-                   gate->g_rt->rt_prev->rt_next = rtmp;
-                   gate->g_rt->rt_prev = rtmp;
-               }
-               
-               if (rtmp_new( rtmp ) < 0) {
-                   LOG(log_error, logtype_atalkd, "rtmp_packet: rtmp_new");
-                   return -1;
-               }
-           }
-
-           if ( data + SZ_RTMPTUPLE > end ) {
-               break;
-           }
-           memcpy( &rt, data, SZ_RTMPTUPLE );
-           data += SZ_RTMPTUPLE;
-           if ( rt.rt_dist & 0x80 ) {
-               if ( data + SZ_RTMPTUPLE > end ) {
-                   LOG(log_info, logtype_atalkd, "rtmp_packet missing range-end" );
-                   return 1;
-               }
-               memcpy( &xrt, data, SZ_RTMPTUPLE );
-               data += SZ_RTMPTUPLE;
-           }
-       }
-
-       /*
-        * Make sure we've processed the whole packet.
-        */
-       if ( data != end ) {
-           LOG(log_info, logtype_atalkd, "rtmp_packet length and count mismatch" );
-       }
-       break;
-
-    case DDPTYPE_RTMPR :
-       /*
-        * Request and RDR.
-        */
-        if (((iface->i_flags & IFACE_ISROUTER) == 0) ||
-           iface->i_rt->rt_zt == NULL ||
-           ( iface->i_flags & IFACE_CONFIG ) == 0 ) {
-           return 0;
-       }
-       if ( *data == 1 ) {
-           data = packet;
-           *data++ = DDPTYPE_RTMPRD;
-           rh.rh_net = iface->i_addr.sat_addr.s_net;
-           rh.rh_nodelen = 8;
-           rh.rh_node = iface->i_addr.sat_addr.s_node;
-           memcpy( data, &rh, sizeof( struct rtmp_head ));
-           data += sizeof( struct rtmp_head );
-
-           if ( iface->i_flags & IFACE_PHASE2 ) {
-               rt.rt_net = iface->i_rt->rt_firstnet;
-               rt.rt_dist = 0x80;
-               memcpy( data, &rt, SZ_RTMPTUPLE );
-               data += SZ_RTMPTUPLE;
-
-               rt.rt_net = iface->i_rt->rt_lastnet;
-               rt.rt_dist = 0x82;
-               memcpy( data, &rt, SZ_RTMPTUPLE );
-               data += SZ_RTMPTUPLE;
-           }
-           if ( sendto( ap->ap_fd, packet, data - packet, 0,
-                   (struct sockaddr *)from,
-                   sizeof( struct sockaddr_at )) < 0 ) {
-               LOG(log_error, logtype_atalkd, "as_timer sendto: %s", strerror(errno) );
-           }
-       } else if ( *data == 2 || *data == 3 ) {
-#ifdef DEBUG
-           printf( "rtmp_packet rdr (%d) from %u.%u\n",
-                   *data, ntohs( from->sat_addr.s_net ),
-                   from->sat_addr.s_node );
-#endif /* DEBUG */
-       } else {
-           LOG(log_info, logtype_atalkd, "rtmp_packet unknown request from %u.%u",
-                   ntohs( from->sat_addr.s_net ), from->sat_addr.s_node );
-       }
-       break;
-
-    default :
-       LOG(log_info, logtype_atalkd, "rtmp_packet bad ddp type from %u.%u",
-                   ntohs( from->sat_addr.s_net ), from->sat_addr.s_node );
-       return 0;
-    }
-
-    return 0;
-}
-
-int rtmp_request( struct interface *iface)
-{
-    struct sockaddr_at sat;
-    struct atport      *ap;
-    char               *data, packet[ 2 ];
-
-    LOG(log_info, logtype_atalkd, "rtmp_request for %s", iface->i_name );
-
-    for ( ap = iface->i_ports; ap; ap = ap->ap_next ) {
-       if ( ap->ap_packet == rtmp_packet ) {
-           break;
-       }
-    }
-    if ( ap == NULL ) {
-       LOG(log_error, logtype_atalkd, "rtmp_request can't find rtmp socket!" );
-       return -1;
-    }
-
-    data = packet;
-    *data++ = DDPTYPE_RTMPR;
-    *data++ = RTMPROP_REQUEST;
-
-    /*
-     * There is a problem with the net zero "hint" hack.
-     */
-    memset( &sat, 0, sizeof( struct sockaddr_at ));
-#ifdef BSD4_4
-    sat.sat_len = sizeof( struct sockaddr_at );
-#endif /* BSD4_4 */
-    sat.sat_family = AF_APPLETALK;
-    sat.sat_addr.s_net = iface->i_addr.sat_addr.s_net;
-    sat.sat_addr.s_node = ATADDR_BCAST;
-    sat.sat_port = ap->ap_port;
-    if ( sendto( ap->ap_fd, packet, data - packet, 0, (struct sockaddr *)&sat,
-           sizeof( struct sockaddr_at )) < 0 ) {
-       LOG(log_error, logtype_atalkd, "rtmp_request sendto: %s", strerror(errno) );
-       return -1;
-    }
-    return 0;
-}
-
-
-int looproute(struct interface *iface, unsigned int cmd)
-{
-    struct sockaddr_at dst, loop;
-
-    if ( cmd == RTMP_DEL && ( iface->i_flags & IFACE_LOOP ) == 0 ) {
-       LOG(log_error, logtype_atalkd, "looproute panic no route" );
-       return -1;
-    }
-
-    if ( cmd == RTMP_ADD && ( iface->i_flags & IFACE_LOOP )) {
-       LOG(log_error, logtype_atalkd, "looproute panic two routes" );
-       return -1;
-    }
-
-    memset( &dst, 0, sizeof( struct sockaddr_at ));
-#ifdef BSD4_4
-    dst.sat_len = sizeof( struct sockaddr_at );
-#endif /* BSD4_4 */
-    dst.sat_family = AF_APPLETALK;
-    dst.sat_addr.s_net = iface->i_addr.sat_addr.s_net;
-    dst.sat_addr.s_node = iface->i_addr.sat_addr.s_node;
-    memset( &loop, 0, sizeof( struct sockaddr_at ));
-#ifdef BSD4_4
-    loop.sat_len = sizeof( struct sockaddr_at );
-#endif /* BSD4_4 */
-    loop.sat_family = AF_APPLETALK;
-    loop.sat_addr.s_net = htons( ATADDR_ANYNET );
-    loop.sat_addr.s_node = ATADDR_ANYNODE;
-
-#ifndef BSD4_4
-    if ( route( cmd,
-               (struct sockaddr *) &dst,
-               (struct sockaddr *) &loop,
-               RTF_UP | RTF_HOST ) ) {
-       return( 1 );
-    }
-#else /* ! BSD4_4 */
-    if ( route( cmd,
-               (struct sockaddr_at *) &dst,
-               (struct sockaddr_at *) &loop,
-               RTF_UP | RTF_HOST ) ) {
-       return ( 1);
-    }
-#endif /* BSD4_4 */
-    if ( cmd == RTMP_ADD ) {
-       iface->i_flags |= IFACE_LOOP;
-    }
-    if ( cmd == RTMP_DEL ) {
-       iface->i_flags &= ~IFACE_LOOP;
-    }
-    return( 0 );
-}
-
-int gateroute(unsigned int command, struct rtmptab *rtmp)
-{
-    struct sockaddr_at dst, gate;
-    unsigned short     net;
-
-    if ( command == RTMP_DEL && ( rtmp->rt_flags & RTMPTAB_ROUTE ) == 0 ) {
-       return( -1 );
-    }
-    if ( command == RTMP_ADD && ( rtmp->rt_flags & RTMPTAB_ROUTE )) {
-       return( -1 );
-    }
-
-    net = ntohs( rtmp->rt_firstnet );
-    /*
-     * Since we will accept routes from gateways who advertise their
-     * address as 0.YY, we must munge the gateway address we give to
-     * the kernel.  Otherwise, we'll get a bunch of routes to the loop
-     * back interface, and who wants that?
-     */
-    memset( &gate, 0, sizeof( struct sockaddr_at ));
-#ifdef BSD4_4
-    gate.sat_len = sizeof( struct sockaddr_at );
-#endif /* BSD4_4 */
-    gate.sat_family = AF_APPLETALK;
-    gate.sat_addr.s_net = rtmp->rt_gate->g_sat.sat_addr.s_net;
-    gate.sat_addr.s_node = rtmp->rt_gate->g_sat.sat_addr.s_node;
-    if ( gate.sat_addr.s_net == 0 ) {
-       gate.sat_addr.s_net = net;
-    }
-
-    memset( &dst, 0, sizeof( struct sockaddr_at ));
-#ifdef BSD4_4
-    dst.sat_len = sizeof( struct sockaddr_at );
-#endif /* BSD4_4 */
-    dst.sat_family = AF_APPLETALK;
-    dst.sat_addr.s_node = ATADDR_ANYNODE;
-
-    do {
-       dst.sat_addr.s_net = htons( net );
-#ifndef BSD4_4
-       if ( route( command,
-                   (struct sockaddr *) &dst,
-                   (struct sockaddr *) &gate,
-                   RTF_UP | RTF_GATEWAY )) {
-           LOG(log_error, logtype_atalkd, "route: %u -> %u.%u: %s", net,
-                   ntohs( gate.sat_addr.s_net ), gate.sat_addr.s_node,
-                   strerror(errno) );
-           continue;
-       }
-#else /* ! BSD4_4 */
-       if ( route( command,
-                   (struct sockaddr_at *) &dst,
-                   (struct sockaddr_at *) &gate,
-                   RTF_UP | RTF_GATEWAY )) {
-           LOG(log_error, logtype_atalkd, "route: %u -> %u.%u: %s", net,
-                   ntohs( gate.sat_addr.s_net ), gate.sat_addr.s_node, strerror(errno) );
-           continue;
-       }
-#endif /* ! BSD4_4 */
-    } while ( net++ < ntohs( rtmp->rt_lastnet ));
-
-    if ( command == RTMP_ADD ) {
-       rtmp->rt_flags |= RTMPTAB_ROUTE;
-    }
-    if ( command == RTMP_DEL ) {
-       rtmp->rt_flags &= ~RTMPTAB_ROUTE;
-    }
-
-    return( 0 );
-}
-
-    struct rtmptab *
-newrt(const struct interface *iface)
-{
-    struct rtmptab     *rtmp;
-
-    if (( rtmp = (struct rtmptab *)calloc(1, sizeof(struct rtmptab))) == NULL ) {
-       return( NULL );
-    }
-
-    rtmp->rt_iface = iface;
-    return( rtmp );
-}
diff --git a/etc/atalkd/rtmp.h b/etc/atalkd/rtmp.h
deleted file mode 100644 (file)
index 99e15db..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * $Id: rtmp.h,v 1.5 2009-10-13 22:55:37 didg Exp $
- * Copyright (c) 1990,1993 Regents of The University of Michigan.
- * All Rights Reserved. See COPYRIGHT.
- *
- * We have an rtmptab circular linked list for each gateway.  Entries
- * are inserted in the order we get them.  The expectation is that
- * we will get a complexity of N for the stable case.  If we have N
- * existing entries, and M new entries, we'll have on the order of
- * N + ( M * N ) complexity (really it will be something more than
- * that, maybe N + ( M * ( N + 1/2 M )).  Note that having a list to
- * search is superior to a hash table if you are expecting bad data:
- * you have the opportunity to range-check the incoming data.
- *
- * We keep several ZIP related flags and counters here.  For ZIP Extended
- * Replies, we must keep a flag indicating that the zone is up or down.
- * This flag is necessary for ZIP Extended Replies which cross packet
- * boundaries: even tho the rtmptab entry has data, it is not yet
- * complete.  For ZIP in general, we keep a flag indicating that we've
- * asked for a ZIP (E)Reply.  If this flag is not set, we won't process
- * ZIP Reply data for given rtmptab entries.  Lastly, we keep a count of
- * the number of times we've asked for ZIP Reply data.  When this value
- * reaches some value (3?), we can optionally stop asking.
- */
-
-#ifndef ATALKD_RTMP_H
-#define ATALKD_RTMP_H 1
-
-#include <sys/cdefs.h>
-
-struct rtmptab {
-    struct rtmptab     *rt_next,
-                       *rt_prev;
-    struct rtmptab     *rt_inext,
-                       *rt_iprev;
-    u_short            rt_firstnet, rt_lastnet;
-    u_char             rt_hops;
-    u_char             rt_state;
-    u_char             rt_flags;
-    u_char             rt_nzq;         /* number of zip queries issued */
-    struct gate                *rt_gate;       /* gate is NULL for interfaces */
-    struct list                *rt_zt;
-    const struct interface    *rt_iface;
-};
-
-struct rtmp_head {
-    u_short    rh_net;
-    u_char     rh_nodelen;
-    u_char     rh_node;
-};
-
-struct rtmp_tuple {
-    u_short    rt_net;
-    u_char     rt_dist;
-};
-#define SZ_RTMPTUPLE   3
-
-#define RTMPTAB_PERM   0
-#define RTMPTAB_GOOD   1
-#define RTMPTAB_SUSP1  2
-#define RTMPTAB_SUSP2  3
-#define RTMPTAB_BAD    4
-
-#define RTMPTAB_ZIPQUERY       0x01
-#define RTMPTAB_HASZONES       0x02
-#define RTMPTAB_EXTENDED       0x04
-#define RTMPTAB_ROUTE          0x08
-
-#ifndef BSD4_4
-#define RTMP_ADD       SIOCADDRT
-#define RTMP_DEL       SIOCDELRT
-#else /* BSD4_4 */
-#define RTMP_ADD       RTM_ADD
-#define RTMP_DEL       RTM_DELETE
-#endif /* BSD4_4 */
-
-#define STARTUP_FIRSTNET       0xff00
-#define STARTUP_LASTNET                0xfffe
-
-extern int     rtfd;
-struct rtmptab *newrt (const struct interface *);
-void rtmp_delzonemap  (struct rtmptab *);
-
-int rtmp_request ( struct interface * );
-void rtmp_free ( struct rtmptab * );
-int rtmp_replace ( struct rtmptab * );
-int looproute ( struct interface *, unsigned int );
-int gateroute ( unsigned int, struct rtmptab * );
-
-struct atport;
-
-int rtmp_packet(struct atport *ap, struct sockaddr_at *from, char *data, int len);
-
-#endif /* atalkd/rtmp.h */
diff --git a/etc/atalkd/zip.c b/etc/atalkd/zip.c
deleted file mode 100644 (file)
index 23d8188..0000000
+++ /dev/null
@@ -1,1055 +0,0 @@
-/*
- * $Id: zip.c,v 1.15 2009-12-13 00:31:50 didg Exp $
- *
- * Copyright (c) 1990,1993 Regents of The University of Michigan.
- * All Rights Reserved. See COPYRIGHT.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <sys/param.h>
-#include <sys/types.h>
-#include <atalk/logger.h>
-#include <sys/socket.h>
-#include <sys/ioctl.h>
-#include <sys/time.h>
-#ifdef TRU64
-#include <sys/mbuf.h>
-#include <net/route.h>
-#endif /* TRU64 */
-#include <net/if.h>
-#include <net/route.h>
-#include <netatalk/endian.h>
-#include <netatalk/at.h>
-
-#ifdef __svr4__
-#include <sys/sockio.h>
-#endif /* __svr4__ */
-
-#include <atalk/ddp.h>
-#include <atalk/zip.h>
-#include <atalk/atp.h>
-#include <atalk/util.h>
-
-#include "atserv.h"
-#include "interface.h"
-#include "gate.h"
-#include "zip.h"
-#include "rtmp.h"
-#include "list.h"
-#include "multicast.h"
-#include "main.h"
-
-struct ziptab  *ziptab = NULL, *ziplast = NULL;
-
-
-static int zonecheck(struct rtmptab *rtmp, struct interface *iface)
-{
-    struct list                *l;
-    struct ziptab      *czt, *zt;
-    int                        cztcnt, ztcnt;
-
-    if (( iface->i_flags & IFACE_SEED ) == 0 ) {
-       return( 0 );
-    }
-
-    for ( cztcnt = 0, czt = iface->i_czt; czt; czt = czt->zt_next, cztcnt++ ) {
-       for ( l = rtmp->rt_zt; l; l = l->l_next ) {
-           zt = (struct ziptab *)l->l_data;
-           if ( czt->zt_len == zt->zt_len &&
-                   !strndiacasecmp( czt->zt_name, zt->zt_name, czt->zt_len )) {
-               break;
-           }
-       }
-       if ( l == NULL ) {
-           LOG(log_error, logtype_atalkd, "zonecheck: %.*s not in zone list", czt->zt_len,
-                   czt->zt_name );
-           return( -1 );       /* configured zone not found in net zones */
-       }
-    }
-
-    for ( ztcnt = 0, l = rtmp->rt_zt; l; l = l->l_next, ztcnt++ )
-       ;
-
-    if ( cztcnt != ztcnt ) {
-       LOG(log_error, logtype_atalkd, "zonecheck: %d configured zones, %d zones found",
-               cztcnt, ztcnt );
-       return( -1 );           /* more net zones than configured zones */
-    }
-
-    return( 0 );
-}
-
-
-int zip_packet(struct atport *ap,struct sockaddr_at *from, char *data, int len)
-{
-    struct ziphdr      zh;
-    struct atphdr      ah;
-    struct interface   *iface;
-    struct gate                *gate;
-    struct rtmptab     *rtmp = NULL;
-    struct list                *l;
-    struct ziptab      *zt;
-    u_short            firstnet, lastnet, index, nz;
-    char               *end, zname[ 32 ], packet[ ATP_BUFSIZ ], *nzones, *lastflag;
-    char               *reply, *rend, *ziphdr;
-    int                        zlen, n, zipop, rcnt, qcnt, zcnt, zsz;
-    extern int         stabletimer;
-
-    end = data + len;
-
-    if ( data >= end ) {
-       LOG(log_info, logtype_atalkd, "zip_packet malformed packet" );
-       return 1;
-    }
-
-    /* get interface */
-    iface = ap->ap_iface;
-
-    switch( *data++ ) {
-    case DDPTYPE_ZIP :
-       if ( data + sizeof( struct ziphdr ) > end ) {
-           LOG(log_info, logtype_atalkd, "zip_packet malformed packet" );
-           return 1;
-       }
-       memcpy( &zh, data, sizeof( struct ziphdr ));
-       data += sizeof( struct ziphdr );
-
-       switch ( zh.zh_op ) {
-       case ZIPOP_QUERY :
-           /* set up reply */
-           reply = packet;
-           rend = packet + sizeof( packet );
-           *reply++ = DDPTYPE_ZIP;
-           ziphdr = reply;
-           reply += 2;
-           rcnt = 0;
-
-           qcnt = zh.zh_count;
-
-           while ( data + sizeof( u_short ) <= end && qcnt-- > 0 ) {
-               memcpy( &firstnet, data, sizeof( u_short ));
-               data += sizeof( u_short );
-
-               /*
-                * Look for the given network number (firstnet).
-                * Perhaps we could do better than brute force?
-                */
-               for ( iface = interfaces; iface; iface = iface->i_next ) {
-                   for ( rtmp = iface->i_rt; rtmp; rtmp = rtmp->rt_inext ) {
-                       if ( firstnet == rtmp->rt_firstnet ) {
-                           break;
-                       }
-                   }
-                   if ( rtmp ) {
-                       break;
-                   }
-               }
-               if ( rtmp == NULL ) {
-                   continue;
-               }
-
-               /*
-                * Count the number of zones in this list, and the
-                * number of byte it will consume in a reply.
-                */
-               for ( zsz = 0, zcnt = 0, l = rtmp->rt_zt; l; l = l->l_next ) {
-                   zcnt++;
-                   zt = (struct ziptab *)l->l_data;
-                   zsz += sizeof( u_short ) + 1 + zt->zt_len;
-               }
-
-               /*
-                * We might send this list in the current reply, as the
-                * first thing in the next reply, or as an extended packet.
-                */
-               if ( reply + zsz > rend ) {
-                   if ( rcnt > 0 ) {
-                       zh.zh_op = ZIPOP_REPLY;
-                       zh.zh_cnt = rcnt;
-                       memcpy( ziphdr, &zh, sizeof( struct ziphdr ));
-                       if ( sendto( ap->ap_fd, packet, reply - packet, 0,
-                               (struct sockaddr *)from,
-                               sizeof( struct sockaddr_at )) < 0 ) {
-                           LOG(log_error, logtype_atalkd, "zip reply sendto: %s",
-                                   strerror(errno) );
-                       }
-
-                       reply = packet + 3;
-                       rcnt = 0;
-                   }
-
-                   if ( reply + zsz > rend ) {
-                       /* ereply */
-                       for ( l = rtmp->rt_zt; l; l = l->l_next, rcnt++ ) {
-                           zt = (struct ziptab *)l->l_data;
-                           if ( reply + sizeof( u_short ) + 1 + zt->zt_len >
-                                   rend ) {
-                               zh.zh_op = ZIPOP_EREPLY;
-                               zh.zh_cnt = zcnt;
-                               memcpy( ziphdr, &zh, sizeof( struct ziphdr ));
-                               if ( sendto( ap->ap_fd, packet, reply - packet,
-                                       0, (struct sockaddr *)from,
-                                       sizeof( struct sockaddr_at )) < 0 ) {
-                                   LOG(log_error, logtype_atalkd, "zip reply sendto: %s",
-                                           strerror(errno) );
-                               }
-
-                               reply = packet + 3;
-                               rcnt = 0;
-                           }
-
-                           memcpy( reply, &firstnet, sizeof( u_short ));
-                           reply += sizeof( u_short );
-                           *reply++ = zt->zt_len;
-                           memcpy( reply, zt->zt_name, zt->zt_len );
-                           reply += zt->zt_len;
-                       }
-
-                       if ( rcnt > 0 ) {
-                           zh.zh_op = ZIPOP_EREPLY;
-                           zh.zh_cnt = zcnt;
-                           memcpy( ziphdr, &zh, sizeof( struct ziphdr ));
-                           if ( sendto( ap->ap_fd, packet, reply - packet, 0,
-                                   (struct sockaddr *)from,
-                                   sizeof( struct sockaddr_at )) < 0 ) {
-                               LOG(log_error, logtype_atalkd, "zip reply sendto: %s",
-                                       strerror(errno) );
-                           }
-
-                           reply = packet + 3;
-                           rcnt = 0;
-                       }
-                       continue;
-                   }
-               }
-
-               for ( l = rtmp->rt_zt; l; l = l->l_next, rcnt++ ) {
-                   zt = (struct ziptab *)l->l_data;
-                   memcpy( reply, &firstnet, sizeof( u_short ));
-                   reply += sizeof( u_short );
-                   *reply++ = zt->zt_len;
-                   memcpy( reply, zt->zt_name, zt->zt_len );
-                   reply += zt->zt_len;
-               }
-           }
-
-           if ( rcnt > 0 ) {
-               zh.zh_op = ZIPOP_REPLY;
-               zh.zh_cnt = rcnt;
-               memcpy( ziphdr, &zh, sizeof( struct ziphdr ));
-               if ( sendto( ap->ap_fd, packet, reply - packet, 0,
-                       (struct sockaddr *)from,
-                       sizeof( struct sockaddr_at )) < 0 ) {
-                   LOG(log_error, logtype_atalkd, "zip reply sendto: %s",
-                           strerror(errno) );
-               }
-           }
-           break;
-
-       case ZIPOP_REPLY :
-           for ( gate = iface->i_gate; gate; gate = gate->g_next ) {
-               if (( from->sat_addr.s_net == 0 ||
-                       gate->g_sat.sat_addr.s_net == from->sat_addr.s_net ) &&
-                       gate->g_sat.sat_addr.s_node == from->sat_addr.s_node ) {
-                   break;
-               }
-           }
-           if ( gate == NULL ) {
-               LOG(log_info, logtype_atalkd, "zip reply from non-gateway %u.%u", 
-                   ntohs( from->sat_addr.s_net ), from->sat_addr.s_node );
-               return 1;
-           }
-
-           rtmp = NULL;
-
-           do {
-               if ( data + sizeof( u_short ) + 1 > end ) {     /* + strlen */
-                   LOG(log_info, logtype_atalkd, "zip reply short (%d)", len );
-                   return 1;
-               }
-               memcpy( &firstnet, data, sizeof( u_short ));
-               data += sizeof( u_short );
-
-               if ( rtmp && rtmp->rt_firstnet != firstnet ) {
-                   /* XXX */
-                   if ( rtmp->rt_gate == NULL &&
-                           zonecheck( rtmp, gate->g_iface ) != 0 ) {
-                       LOG(log_error, logtype_atalkd, "zip_packet seed zonelist mismatch" );
-                       return -1;
-                   }
-                   rtmp->rt_flags &= ~RTMPTAB_ZIPQUERY;
-               }
-
-               /* Check if this is the interface's route. */
-               if ( firstnet == gate->g_iface->i_rt->rt_firstnet ) {
-                   rtmp = gate->g_iface->i_rt;
-               } else {
-                   for ( rtmp = gate->g_rt; rtmp; rtmp = rtmp->rt_next ) {
-                       if ( rtmp->rt_firstnet == firstnet ) {
-                           break;
-                       }
-                   }
-
-                   /*
-                    * Update head to this rtmp entry.
-                    */
-                   if ( rtmp != NULL && gate->g_rt != rtmp ) {
-                       gate->g_rt->rt_prev->rt_next = gate->g_rt;
-                       gate->g_rt = rtmp;
-                       rtmp->rt_prev->rt_next = NULL;
-                   }
-               }
-
-               zlen = *data++;
-               if ( zlen > 32 || zlen <= 0 ) {
-                   LOG(log_info, logtype_atalkd, "zip reply bad packet" );
-                   return 1;
-               }
-               if ( data + zlen > end ) {
-                   LOG(log_info, logtype_atalkd, "zip reply short (%d)", len );
-                   return 1;
-               }
-               memcpy( zname, data, zlen );
-               data += zlen;
-
-               /*
-                * We won't find any rtmp entry if the gateway is no longer
-                * telling us about the entry.
-                */
-               if ( rtmp == NULL ) {
-                   LOG(log_info, logtype_atalkd, "zip skip reply %u from %u.%u (no rtmp)",
-                           ntohs( firstnet ), ntohs( from->sat_addr.s_net ),
-                           from->sat_addr.s_node );
-               /*
-                * Check if the route is still in use (the iprev check is
-                * no good if rtmp is the interface's route).
-                */
-               } else if ( rtmp->rt_iprev == NULL && rtmp->rt_prev != NULL ) {
-                   LOG(log_info, logtype_atalkd,
-                           "zip skip reply %u-%u from %u.%u (rtmp not in use)",
-                           ntohs( rtmp->rt_firstnet ),
-                           ntohs( rtmp->rt_lastnet ),
-                           ntohs( from->sat_addr.s_net ),
-                           from->sat_addr.s_node );
-               /*
-                * Check if we've got an outstanding query for this route.
-                * We will often get this, since we ask every router on a
-                * net to verify our interface's zone(s).
-                */
-               } else if (( rtmp->rt_flags & RTMPTAB_ZIPQUERY ) == 0 ) {
-                   LOG(log_info, logtype_atalkd,
-                           "zip skip reply %u-%u from %u.%u (no query)",
-                           ntohs( rtmp->rt_firstnet ),
-                           ntohs( rtmp->rt_lastnet ),
-                           ntohs( from->sat_addr.s_net ),
-                           from->sat_addr.s_node );
-               } else {
-                   if (addzone( rtmp, zlen, zname ) < 0) {
-                       LOG(log_error, logtype_atalkd, "zip_packet: addzone");
-                       return -1;
-                   }
-                   rtmp->rt_flags |= RTMPTAB_HASZONES;
-               }
-           } while ( data < end );
-
-           if ( rtmp && rtmp->rt_flags & RTMPTAB_HASZONES ) {
-               /* XXX */
-               if ( rtmp->rt_gate == NULL &&
-                       zonecheck( rtmp, gate->g_iface ) != 0 ) {
-                   LOG(log_error, logtype_atalkd, "zip_packet seed zonelist mismatch" );
-                   return -1;
-               }
-               rtmp->rt_flags &= ~RTMPTAB_ZIPQUERY;
-           }
-           break;
-
-       case ZIPOP_EREPLY :
-           for ( gate = iface->i_gate; gate; gate = gate->g_next ) {
-               if (( from->sat_addr.s_net == 0 ||
-                       gate->g_sat.sat_addr.s_net == from->sat_addr.s_net ) &&
-                       gate->g_sat.sat_addr.s_node == from->sat_addr.s_node ) {
-                   break;
-               }
-           }
-           if ( gate == NULL ) {
-               LOG(log_info, logtype_atalkd, "zip ereply from non-gateway %u.%u", 
-                   ntohs( from->sat_addr.s_net ), from->sat_addr.s_node );
-               return 1;
-           }
-
-           /*
-            * Note that we're not advancing "data" here.  We do that
-            * at the top of the do-while loop, below.
-            */
-           if ( data + sizeof( u_short ) + 1 > end ) { /* + strlen */
-               LOG(log_info, logtype_atalkd, "zip ereply short (%d)", len );
-               return 1;
-           }
-           memcpy( &firstnet, data, sizeof( u_short ));
-
-           /* Check if this is the interface's route. */
-           if ( firstnet == gate->g_iface->i_rt->rt_firstnet ) {
-               rtmp = gate->g_iface->i_rt;
-           } else {
-               for ( rtmp = gate->g_rt; rtmp; rtmp = rtmp->rt_next ) {
-                   if ( rtmp->rt_firstnet == firstnet ) {
-                       break;
-                   }
-               }
-               if ( rtmp == NULL ) {
-                   LOG(log_info, logtype_atalkd, "zip ereply %u from %u.%u (no rtmp)",
-                           ntohs( firstnet ), ntohs( from->sat_addr.s_net ),
-                           from->sat_addr.s_node );
-                   return 1;
-               }
-               if ( rtmp->rt_iprev == NULL ) {
-                   LOG(log_info, logtype_atalkd,
-                           "zip ereply %u-%u from %u.%u (rtmp not in use)",
-                           ntohs( rtmp->rt_firstnet ),
-                           ntohs( rtmp->rt_lastnet ),
-                           ntohs( from->sat_addr.s_net ),
-                           from->sat_addr.s_node );
-               }
-
-               /* update head to *next* rtmp entry */
-               if ( rtmp->rt_next != NULL ) {
-                   gate->g_rt->rt_prev->rt_next = gate->g_rt;
-                   gate->g_rt = rtmp->rt_next;
-                   rtmp->rt_next = NULL;
-               }
-           }
-
-           if (( rtmp->rt_flags & RTMPTAB_ZIPQUERY ) == 0 ) {
-               LOG(log_info, logtype_atalkd, "zip ereply %u-%u from %u.%u (no query)",
-                       ntohs( rtmp->rt_firstnet ),
-                       ntohs( rtmp->rt_lastnet ),
-                       ntohs( from->sat_addr.s_net ),
-                       from->sat_addr.s_node );
-               return 0;
-           }
-
-           do {
-               /*
-                * We copy out firstnet, twice (see above).  Not
-                * a big deal, and it makes the end condition cleaner.
-                */
-               if ( data + sizeof( u_short ) + 1 > end ) {     /* + strlen */
-                   LOG(log_info, logtype_atalkd, "zip ereply short (%d)", len );
-                   return 1;
-               }
-               memcpy( &firstnet, data, sizeof( u_short ));
-               data += sizeof( u_short );
-
-               /* check route */
-               if ( firstnet != rtmp->rt_firstnet ) {
-                   LOG(log_info, logtype_atalkd, "zip ereply with multiple nets" );
-                   return 1;
-               }
-
-               zlen = *data++;
-               if ( zlen > 32 || zlen <= 0 ) {
-                   LOG(log_info, logtype_atalkd, "zip ereply bad zone length (%d)", zlen );
-                   return 1;
-               }
-               if ( data + zlen > end ) {
-                   LOG(log_info, logtype_atalkd, "zip ereply short (%d)", len );
-                   return 1;
-               }
-               memcpy( zname, data, zlen );
-               data += zlen;
-               if (addzone( rtmp, zlen, zname ) < 0) {
-                   LOG(log_error, logtype_atalkd, "zip_packet: addzone");
-                   return -1;
-               }
-           } while ( data < end );
-
-           if ( rtmp ) {
-               /*
-                * Count zones for rtmptab entry.
-                */
-               for ( n = 0, l = rtmp->rt_zt; l; l = l->l_next, n++ )
-                   ;
-               if ( n == zh.zh_count ) {
-                   rtmp->rt_flags |= RTMPTAB_HASZONES;
-                   /* XXX */
-                   if ( rtmp->rt_gate == NULL &&
-                           zonecheck( rtmp, gate->g_iface ) != 0 ) {
-                       LOG(log_error, logtype_atalkd, "zip_packet seed zonelist mismatch" );
-                       return -1;
-                   }
-                   rtmp->rt_flags &= ~RTMPTAB_ZIPQUERY;
-               }
-           }
-           break;
-
-       case ZIPOP_GNI :
-           /*
-            * Don't answer with bogus information.
-            */
-           if (((iface->i_flags & IFACE_ISROUTER) == 0) ||
-               iface->i_rt->rt_zt == NULL ||
-               ( iface->i_flags & IFACE_CONFIG ) == 0 ) {
-               return 0;
-           }
-
-           if ( zh.zh_zero != 0 || data + 2 * sizeof( u_short ) > end ) {
-               LOG(log_info, logtype_atalkd, "zip_packet malformed packet" );
-               return 1;
-           }
-
-           memcpy( &firstnet, data, sizeof( u_short ));
-           data += sizeof( u_short );
-           memcpy( &lastnet, data, sizeof( u_short ));
-           data += sizeof( u_short );
-           if ( firstnet != 0 || lastnet != 0 || data >= end ) {
-               LOG(log_info, logtype_atalkd, "zip_packet malformed packet" );
-               return 1;
-           }
-
-           zlen = *data++;
-           if ( zlen < 0 || zlen > 32 ) {
-               LOG(log_info, logtype_atalkd, "zip_packet malformed packet" );
-               return 1;
-           }
-           memcpy( zname, data, zlen );
-
-           data = packet;
-           end = data + sizeof( packet );
-           zh.zh_op = ZIPOP_GNIREPLY;
-           zh.zh_flags = 0;
-
-           /*
-            * Skip to the nets.  Fill in header when we're done.
-            */
-           data += 1 + sizeof( struct ziphdr );
-           memcpy( data, &iface->i_rt->rt_firstnet, sizeof( u_short ));
-           data += sizeof( u_short );
-           memcpy( data, &iface->i_rt->rt_lastnet, sizeof( u_short ));
-           data += sizeof( u_short );
-
-           *data++ = zlen;
-           memcpy( data, zname, zlen );
-           data += zlen;
-
-           /*
-            * Check if the given zone is valid.  If it's valid, just fill in
-            * the multicast address.  If it's not, fill the multicast address
-            * in with the default zone and return the default zone.
-            */
-           for ( l = iface->i_rt->rt_zt; l; l = l->l_next ) {
-               zt = (struct ziptab *)l->l_data;
-               if ( zt->zt_len == zlen &&
-                       strndiacasecmp( zname, zt->zt_name, zlen ) == 0 ) {
-                   break;
-               }
-           }
-           if ( l == NULL ) {
-               zt = (struct ziptab *)iface->i_rt->rt_zt->l_data;
-               zh.zh_flags |= ZIPGNI_INVALID;
-           }
-
-           for ( n = 0, l = iface->i_rt->rt_zt; l; l = l->l_next, n++ )
-               ;
-           if ( n == 1 ) {
-               zh.zh_flags |= ZIPGNI_ONEZONE;
-           }
-
-           /* multicast */
-           *data++ = 6;        /* sizeof ??? */
-           if (zone_bcast(zt) < 0) {
-             LOG(log_error, logtype_atalkd, "zip_packet: zone_bcast");
-             return -1;
-           }
-           memcpy(data, zt->zt_bcast, 6);
-           data += 6;
-
-           /*
-            * Add default zone.
-            */
-           if ( zh.zh_flags & ZIPGNI_INVALID ) {
-               *data++ = zt->zt_len;
-               memcpy( data, zt->zt_name, zt->zt_len );
-               data += zt->zt_len;
-           }
-
-           /* fill in header */
-           *packet = DDPTYPE_ZIP;
-           memcpy( packet + 1, &zh, sizeof( struct ziphdr ));
-
-           /*
-            * If the address we received this request from isn't correct
-            * for the net we received it on, send a broadcast.
-            */
-           if ( ntohs( from->sat_addr.s_net ) <
-                   ntohs( iface->i_rt->rt_firstnet ) ||
-                   ntohs( from->sat_addr.s_net ) >
-                   ntohs( iface->i_rt->rt_lastnet )) {
-               from->sat_addr.s_net = 0;
-               from->sat_addr.s_node = ATADDR_BCAST;
-           }
-
-           if ( sendto( ap->ap_fd, packet, data - packet, 0,
-                   (struct sockaddr *)from,
-                   sizeof( struct sockaddr_at )) < 0 ) {
-               LOG(log_error, logtype_atalkd, "zip gni sendto %u.%u: %s",
-                       ntohs( from->sat_addr.s_net ), from->sat_addr.s_node,
-                       strerror(errno) );
-               return 1;
-           }
-           break;
-
-       case ZIPOP_GNIREPLY :
-           /*
-            * Ignore ZIP GNIReplys which are either late or unsolicited.
-            */
-           LOG(log_debug, logtype_atalkd, "zip gnireply from %u.%u (%s %x)",
-                   ntohs( from->sat_addr.s_net ), from->sat_addr.s_node,
-                   iface->i_name, iface->i_flags );
-
-           if (( iface->i_flags & ( IFACE_CONFIG|IFACE_PHASE1 )) ||
-                   ( iface->i_flags & IFACE_ADDR ) == 0 ) {
-               LOG(log_debug, logtype_atalkd, "zip ignoring gnireply" );
-               return 1;
-           }
-
-           if ( data + 2 * sizeof( u_short ) > end ) {
-               LOG(log_info, logtype_atalkd, "zip_packet malformed packet" );
-               return 1;
-           }
-           memcpy( &firstnet, data, sizeof( u_short ));
-           data += sizeof( u_short );
-           memcpy( &lastnet, data, sizeof( u_short ));
-           data += sizeof( u_short );
-
-           /*
-            * We never ask for a zone, so we can get back what the
-            * default zone is.
-            */
-           if ( data >= end || data + *data > end ) {
-               LOG(log_info, logtype_atalkd, "zip_packet malformed packet" );
-               return 1;
-           }
-           if ( *data++ != 0 ) {
-               LOG(log_info, logtype_atalkd, "zip_packet unsolicited zone" );
-               return 1;
-           }
-
-           /* skip multicast (should really check it) */
-           if ( data >= end || data + *data > end ) {
-               LOG(log_info, logtype_atalkd, "zip_packet malformed packet" );
-               return 1;
-           }
-           data += *data + 1;
-
-           if ( data >= end || data + *data > end ) {
-               LOG(log_info, logtype_atalkd, "zip_packet malformed packet" );
-               return 1;
-           }
-
-           /*
-            * First, if we're not seed, we always get our zone information
-            * from the net -- we don't even save what was in the file.
-            * Second, if we are seed, we keep our zone list in the
-            * interface structure, not in the zone table.  This allows us
-            * to check that the net is giving us good zones.
-            */
-           if ( (iface->i_flags & IFACE_SEED) && iface->i_czt) {
-               if ( iface->i_czt->zt_len != *data ||
-                       strndiacasecmp( iface->i_czt->zt_name,
-                       data + 1, *data ) != 0 ) {
-                   LOG(log_error, logtype_atalkd, "default zone mismatch on %s",
-                           iface->i_name );
-                   LOG(log_error, logtype_atalkd, "%.*s != %.*s",
-                           iface->i_czt->zt_len, iface->i_czt->zt_name,
-                           *data, data + 1 );
-                   LOG(log_error, logtype_atalkd, "Seed error! Exiting!" );
-                   return -1;
-               }
-           }
-
-           if (addzone( iface->i_rt, *data, data + 1 ) < 0) {
-               LOG(log_error, logtype_atalkd, "zip_packet: addzone");
-               return -1;
-           }
-           
-           /*
-            * The netrange we received from the router doesn't match the
-            * range we have locally. This is not a problem, unless we
-            * have seed information.
-            */
-           if ( firstnet != iface->i_rt->rt_firstnet ||
-                   lastnet != iface->i_rt->rt_lastnet ) {
-               if ( iface->i_flags & IFACE_SEED ) {
-                   LOG(log_error, logtype_atalkd, "netrange mismatch on %s",
-                           iface->i_name );
-                   LOG(log_error, logtype_atalkd, "%u-%u != %u-%u",
-                           ntohs( firstnet ), ntohs( lastnet ),
-                           ntohs( iface->i_rt->rt_firstnet ),
-                           ntohs( iface->i_rt->rt_lastnet ));
-                   LOG(log_error, logtype_atalkd, "Seed error! Exiting!" );
-                   return -1;
-               }
-
-
-               /*
-                * It is possible that we will corrupt our route database
-                * by just forcing this change.  A better solution would
-                * be to search all of our current routes, looking for
-                * this new route, and delete any old versions.  Also, we
-                * would call rtmp_delete() on the old net range, in case
-                * there is some other net which actually had that range.  XXX
-                */
-               iface->i_rt->rt_firstnet = firstnet;
-               iface->i_rt->rt_lastnet = lastnet;
-
-               if ( ntohs( iface->i_addr.sat_addr.s_net ) <
-                       ntohs( firstnet ) ||
-                       ntohs( iface->i_addr.sat_addr.s_net ) >
-                       ntohs( lastnet )) {
-                   iface->i_addr.sat_addr.s_net = 0;   /* ATADDR_ANYNET? */
-               }
-               setaddr( iface, IFACE_PHASE2, iface->i_addr.sat_addr.s_net,
-                       iface->i_addr.sat_addr.s_node, firstnet, lastnet );
-               stabletimer = UNSTABLE;
-           }
-
-           /* add addr to loopback route */
-           if ( looproute( iface, RTMP_ADD )) { /* -1 or 1 */
-               LOG(log_error, logtype_atalkd,
-                       "zip_packet: can't route %u.%u to loopback: %s",
-                       ntohs( iface->i_addr.sat_addr.s_net ),
-                       iface->i_addr.sat_addr.s_node,
-                       strerror(errno) );
-               return -1;
-           }
-
-           LOG(log_info, logtype_atalkd, "zip_packet configured %s from %u.%u",
-                   iface->i_name, ntohs( from->sat_addr.s_net ),
-                   from->sat_addr.s_node );
-           iface->i_flags |= IFACE_CONFIG;
-           if ( iface == ciface ) {
-               ciface = ciface->i_next;
-               bootaddr( ciface );
-           }
-           break;
-
-       case ZIPOP_NOTIFY :
-#ifdef DEBUG
-           printf( "zip notify from %u.%u\n", ntohs( from->sat_addr.s_net ),
-                   from->sat_addr.s_node );
-#endif /* DEBUG */
-           break;
-
-       default :
-           LOG(log_info, logtype_atalkd, "zip_packet bad zip op from %u.%u",
-                   ntohs( from->sat_addr.s_net ), from->sat_addr.s_node );
-       }
-       break;
-
-    case DDPTYPE_ATP :
-       if ( data + sizeof( struct atphdr ) > end ) {
-           LOG(log_info, logtype_atalkd, "zip atp malformed packet" );
-           return 1;
-       }
-       memcpy( &ah, data, sizeof( struct atphdr ));
-       data += sizeof( struct atphdr );
-       if ( ah.atphd_ctrlinfo != ATP_TREQ ) {
-           LOG(log_info, logtype_atalkd, "zip atp bad control" );
-           return 1;
-       }
-       ah.atphd_ctrlinfo = ATP_TRESP | ATP_EOM;
-       if ( ah.atphd_bitmap != 1 ) {
-           LOG(log_error, logtype_atalkd, "zip atp bad bitmap" );
-           return 1;
-       }
-       ah.atphd_bitmap = 0;
-
-       zipop = *data++;
-       data++;
-       memcpy( &index, data, sizeof( u_short ));
-       data += sizeof( u_short );
-       index = ntohs( index );
-       if ( data != end ) {
-           LOG(log_info, logtype_atalkd, "zip atp malformed packet" );
-           return 1;
-       }
-
-       data = packet;
-       end = data + sizeof( packet );
-       *data++ = DDPTYPE_ATP;
-       memcpy( data, &ah, sizeof( struct atphdr ));
-       data += sizeof( struct atphdr );
-       lastflag = data++;              /* mark and space for last flag */
-       *data++ = 0;
-       nzones = data;                  /* mark and space for zone count */
-       data += sizeof( u_short );
-
-       switch ( zipop ) {
-       case ZIPOP_GETMYZONE :
-           if ( index != 0 ) {
-               LOG(log_info, logtype_atalkd, "zip atp gmz bad index" );
-               return 1;
-           }
-
-           if ( iface->i_flags & IFACE_LOOPBACK ) {
-               iface = interfaces->i_next;     /* first interface */
-           } else if ( ntohs( iface->i_rt->rt_firstnet ) >
-                   ntohs( from->sat_addr.s_net ) ||
-                   ntohs( iface->i_rt->rt_lastnet ) <
-                   ntohs( from->sat_addr.s_net )) {
-               return 0;
-           }
-
-           if ( iface->i_rt->rt_zt == NULL ) {
-               return 0;
-           }
-           zt = (struct ziptab *)iface->i_rt->rt_zt->l_data;
-           if ( data + 1 + zt->zt_len > end ) {
-               LOG(log_info, logtype_atalkd, "zip atp gmz reply too long" );
-               return 1;
-           }
-           *data++ = zt->zt_len;
-           memcpy( data, zt->zt_name, zt->zt_len );
-           data += zt->zt_len;
-
-           *lastflag = 0;
-           nz = 1;
-           break;
-
-       case ZIPOP_GETZONELIST :
-           for ( zt = ziptab; zt && ( index > 1 ); zt = zt->zt_next, index-- )
-               ;
-           for ( nz = 0; zt; zt = zt->zt_next, nz++ ) {
-               if ( data + 1 + zt->zt_len > end ) {
-                   break;
-               }
-               *data++ = zt->zt_len;
-               memcpy( data, zt->zt_name, zt->zt_len );
-               data += zt->zt_len;
-           }
-
-           *lastflag = ( zt == NULL );         /* Too clever? */
-           break;
-
-       case ZIPOP_GETLOCALZONES :
-           if ( iface->i_flags & IFACE_LOOPBACK ) {
-               iface = interfaces->i_next;     /* first interface */
-           } else if ( ntohs( iface->i_rt->rt_firstnet ) >
-                   ntohs( from->sat_addr.s_net ) ||
-                   ntohs( iface->i_rt->rt_lastnet ) <
-                   ntohs( from->sat_addr.s_net )) {
-               return 0;
-           }
-
-           for ( l = iface->i_rt->rt_zt; l && ( index > 1 );
-                   l = l->l_next, index-- )
-               ;
-           for ( nz = 0; l; l = l->l_next, nz++ ) {
-               zt = (struct ziptab *)l->l_data;
-               if ( data + 1 + zt->zt_len > end ) {
-                   break;
-               }
-               *data++ = zt->zt_len;
-               memcpy( data, zt->zt_name, zt->zt_len );
-               data += zt->zt_len;
-           }
-
-           *lastflag = ( l == NULL );
-           break;
-
-       default :
-           LOG(log_info, logtype_atalkd, "zip atp bad option" );
-           return 1;
-       }
-
-       /* send reply */
-       if ( nz > 0 ) {
-           nz = htons( nz );
-           memcpy( nzones, &nz, sizeof( u_short ));
-           if ( sendto( ap->ap_fd, packet, data - packet, 0,
-                   (struct sockaddr *)from,
-                   sizeof( struct sockaddr_at )) < 0 ) {
-               LOG(log_error, logtype_atalkd, "zip atp sendto %u.%u: %s",
-                       ntohs( from->sat_addr.s_net ), from->sat_addr.s_node,
-                       strerror(errno) );
-               return 1;
-           }
-       }
-       break;
-
-    default :
-       LOG(log_info, logtype_atalkd, "zip_packet bad ddp type from %u.%u",
-               ntohs( from->sat_addr.s_net ), from->sat_addr.s_node );
-       return 1;
-    }
-
-    return 0;
-}
-
-int zip_getnetinfo(struct interface *iface)
-{
-    struct atport      *ap;
-    struct ziphdr      zh;
-    struct sockaddr_at sat;
-    char               *data, packet[ 40 ];
-    u_short            net;
-
-    LOG(log_info, logtype_atalkd, "zip_getnetinfo for %s", iface->i_name );
-
-    for ( ap = iface->i_ports; ap; ap = ap->ap_next ) {
-       if ( ap->ap_packet == zip_packet ) {
-           break;
-       }
-    }
-    if ( ap == NULL ) {
-       LOG(log_error, logtype_atalkd, "zip_getnetinfo can't find zip socket!" );
-       return -1;
-    }
-
-    data = packet;
-
-    *data++ = DDPTYPE_ZIP;
-
-    zh.zh_op = ZIPOP_GNI;
-    zh.zh_zero = 0;
-    memcpy( data, &zh, sizeof( struct ziphdr ));
-    data += sizeof( struct ziphdr );
-    net = 0;
-    memcpy( data, &net, sizeof( u_short ));
-    data += sizeof( u_short );
-    memcpy( data, &net, sizeof( u_short ));
-    data += sizeof( u_short );
-
-    /*
-     * Set our requesting zone to NULL, so the response will contain
-     * the default zone.
-     */
-    *data++ = 0;
-
-#ifdef BSD4_4
-    sat.sat_len = sizeof( struct sockaddr_at );
-#endif /* BSD4_4 */
-    sat.sat_family = AF_APPLETALK;
-    sat.sat_addr.s_net = 0;
-    sat.sat_addr.s_node = ATADDR_BCAST;
-    sat.sat_port = ap->ap_port;
-
-    if ( sendto( ap->ap_fd, packet, data - packet, 0, (struct sockaddr *)&sat,
-           sizeof( struct sockaddr_at )) < 0 ) {
-       LOG(log_error, logtype_atalkd, "zip_getnetinfo sendto: %s", strerror(errno) );
-       return -1;
-    }
-    return 0;
-}
-
-struct ziptab *newzt(const int len, const char *name)
-{
-    struct ziptab      *zt;
-
-    if (( zt = (struct ziptab *)calloc(1, sizeof( struct ziptab ))) == NULL ) {
-       return( NULL );
-    }
-
-    zt->zt_len = len;
-    if (( zt->zt_name = (char *)malloc( len )) == NULL ) {
-       free(zt);
-       return( NULL );
-    }
-
-    memcpy( zt->zt_name, name, len );
-    return( zt );
-}
-
-
-/*
- * Insert at the end.  Return 1 if a mapping already exists, 0 otherwise.
- * -1 on error.
- */
-static int add_list(struct list **head, void *data)
-{
-    struct list        *l, *l2;
-
-    for ( l = *head; l; l = l->l_next ) {
-       if ( l->l_data == data ) {
-           return( 1 );
-       }
-    }
-    if (( l = (struct list *)malloc( sizeof( struct list ))) == NULL ) {
-       LOG(log_error, logtype_atalkd, "add_list malloc: %s", strerror(errno) );
-       return -1;
-    }
-
-    l->l_data = data;
-    l->l_next = NULL;
-    if ( *head == NULL ) {
-       l->l_prev = NULL;
-       *head = l;
-    } else {
-       /* find end of list */
-       for ( l2 = *head; l2->l_next; l2 = l2->l_next )
-           ;
-       l->l_prev = l2;
-       l2->l_next = l;
-    }
-    return( 0 );
-}
-
-int addzone(struct rtmptab *rt, int len, char *zone)
-{
-    struct ziptab      *zt;
-    int                        cc, exists = 0;
-
-    for ( zt = ziptab; zt; zt = zt->zt_next ) {
-       if ( zt->zt_len == len &&
-               strndiacasecmp( zt->zt_name, zone, len ) == 0 ) {
-           break;
-       }
-    }
-    if ( zt == NULL ) {
-       if (( zt = newzt( len, zone )) == NULL ) {
-           LOG(log_error, logtype_atalkd, "addzone newzt: %s", strerror(errno) );
-           return -1;
-       }
-       if ( ziptab == NULL ) {
-           zt->zt_prev = NULL;
-           ziptab = zt;
-       } else {
-           zt->zt_prev = ziplast;
-           ziplast->zt_next = zt;
-       }
-       ziplast = zt;
-    }
-
-    if ((cc = add_list( &zt->zt_rt, rt )) < 0) 
-      return -1;
-
-    if (cc)
-      exists++;
-
-    if ((cc = add_list( &rt->rt_zt, zt )) < 0 )
-      return -1;
-
-    if (cc) {
-        if ( !exists ) {
-           LOG(log_error, logtype_atalkd, "addzone corrupted route/zone mapping" );
-           return -1;
-       }
-       /*
-        * We get the repeat for local nets which have zone information
-        * already: we ask anyway, just to make sure.
-        */
-       
-       return 0;
-    }
-    if ( exists ) {
-       LOG(log_error, logtype_atalkd, "addzone corrupted zone/route mapping" );
-       return -1;
-    }
-    return 0;
-}
diff --git a/etc/atalkd/zip.h b/etc/atalkd/zip.h
deleted file mode 100644 (file)
index e8bf1db..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * $Id: zip.h,v 1.4 2009-10-13 22:55:37 didg Exp $
- *
- * Copyright (c) 1990,1993 Regents of The University of Michigan.
- * All Rights Reserved. See COPYRIGHT.
- */
-
-#ifndef ATALKD_ZIP_H
-#define ATALKD_ZIP_H 1
-
-#include <sys/cdefs.h>
-
-struct ziptab {
-    struct ziptab      *zt_next,
-                       *zt_prev;
-    u_char             zt_len;
-    char               *zt_name;
-    u_char             *zt_bcast;
-    struct list                *zt_rt;
-};
-
-extern struct ziptab   *ziptab, *ziplast;
-struct ziptab  *newzt (const int, const char *);
-
-int addzone ( struct rtmptab *, int, char * );
-int zip_getnetinfo ( struct interface * );
-int zip_packet(struct atport *ap,struct sockaddr_at *from, char *data, int len);
-
-#endif /* atalkd/zip.h */
index 50433c66de807a1dab6888ad7ca815a4cbd9729b..3c61f920fa888f0218246b584763ae122d221478 100644 (file)
@@ -34,6 +34,7 @@
 #include <atalk/ea.h>
 #include <atalk/util.h>
 #include <atalk/acl.h>
+#include <atalk/compat.h>
 
 #include "cmd_dbd.h"
 #include "dbif.h"
@@ -292,17 +293,16 @@ static const char *check_special_dirs(const char *name)
 */
 static int check_adfile(const char *fname, const struct stat *st)
 {
-    int ret, adflags;
+    int ret;
+    int adflags = ADFLAGS_HF;
     struct adouble ad;
-    char *adname;
+    const char *adname;
 
     if (dbd_flags & DBD_FLAGS_CLEANUP)
         return 0;
 
     if (S_ISREG(st->st_mode))
-        adflags = 0;
-    else
-        adflags = ADFLAGS_DIR;
+        adflags |= ADFLAGS_DIR;
 
     adname = myvolinfo->ad_path(fname, adflags);
 
@@ -320,9 +320,9 @@ static int check_adfile(const char *fname, const struct stat *st)
             return -1;
 
         /* Create ad file */
-        ad_init(&ad, myvolinfo->v_adouble, myvolinfo->v_ad_options);
+        ad_init_old(&ad, myvolinfo->v_adouble, myvolinfo->v_ad_options);
 
-        if ((ret = ad_open_metadata( fname, adflags, O_CREAT, &ad)) != 0) {
+        if ((ret = ad_open(&ad, fname, adflags | ADFLAGS_CREATE | ADFLAGS_RDWR, 0666)) != 0) {
             dbd_log( LOGSTD, "Error creating AppleDouble file '%s/%s': %s",
                      cwdbuf, adname, strerror(errno));
 
@@ -332,7 +332,7 @@ static int check_adfile(const char *fname, const struct stat *st)
         /* Set name in ad-file */
         ad_setname(&ad, utompath((char *)fname));
         ad_flush(&ad);
-        ad_close_metadata(&ad);
+        ad_close(&ad, ADFLAGS_HF);
 
         chown(adname, st->st_uid, st->st_gid);
         /* FIXME: should we inherit mode too here ? */
@@ -340,12 +340,12 @@ static int check_adfile(const char *fname, const struct stat *st)
         chmod(adname, st->st_mode);
 #endif
     } else {
-        ad_init(&ad, myvolinfo->v_adouble, myvolinfo->v_ad_options);
-        if (ad_open_metadata( fname, adflags, O_RDONLY, &ad) != 0) {
+        ad_init_old(&ad, myvolinfo->v_adouble, myvolinfo->v_ad_options);
+        if (ad_open(&ad, fname, adflags | ADFLAGS_RDONLY) != 0) {
             dbd_log( LOGSTD, "Error opening AppleDouble file for '%s/%s'", cwdbuf, fname);
             return -1;
         }
-        ad_close_metadata(&ad);
+        ad_close(&ad, ADFLAGS_HF);
     }
     return 0;
 }
@@ -497,9 +497,9 @@ static int check_addir(int volroot)
         }
 
         /* Create ad dir and set name */
-        ad_init(&ad, myvolinfo->v_adouble, myvolinfo->v_ad_options);
+        ad_init_old(&ad, myvolinfo->v_adouble, myvolinfo->v_ad_options);
 
-        if (ad_open_metadata( ".", ADFLAGS_DIR, O_CREAT, &ad) != 0) {
+        if (ad_open(&ad, ".", ADFLAGS_HF | ADFLAGS_DIR | ADFLAGS_CREATE | ADFLAGS_RDWR, 0777) != 0) {
             dbd_log( LOGSTD, "Error creating AppleDouble dir in %s: %s", cwdbuf, strerror(errno));
             return -1;
         }
@@ -510,7 +510,7 @@ static int check_addir(int volroot)
         /* Update name in ad file */
         ad_setname(&ad, mname);
         ad_flush(&ad);
-        ad_close_metadata(&ad);
+        ad_close(&ad, ADFLAGS_HF);
 
         /* Inherit owner/group from "." to ".AppleDouble" and ".Parent" */
         if ((lstat(".", &st)) != 0) {
@@ -694,8 +694,8 @@ static cnid_t check_cnid(const char *name, cnid_t did, struct stat *st, int adfi
     /* Get CNID from ad-file if volume is using AFPVOL_CACHE */
     ad_cnid = 0;
     if ( (myvolinfo->v_flags & AFPVOL_CACHE) && ADFILE_OK) {
-        ad_init(&ad, myvolinfo->v_adouble, myvolinfo->v_ad_options);
-        if (ad_open_metadata( name, adflags, O_RDWR, &ad) != 0) {
+        ad_init_old(&ad, myvolinfo->v_adouble, myvolinfo->v_ad_options);
+        if (ad_open(&ad, name, adflags | ADFLAGS_RDWR) != 0) {
             
             if (dbd_flags & DBD_FLAGS_CLEANUP)
                 return CNID_INVALID;
@@ -718,7 +718,7 @@ static cnid_t check_cnid(const char *name, cnid_t did, struct stat *st, int adfi
         else
             dbd_log( LOGDEBUG, "CNID from .AppleDouble file for '%s/%s': %u", cwdbuf, name, ntohl(ad_cnid));
 
-        ad_close_metadata(&ad);
+        ad_close(&ad, ADFLAGS_HF);
     }
 
     /* Get CNID from database */
@@ -760,15 +760,15 @@ static cnid_t check_cnid(const char *name, cnid_t did, struct stat *st, int adfi
         if ( ! (dbd_flags & DBD_FLAGS_SCAN)) {
             dbd_log(LOGSTD, "Updating AppleDouble file for '%s/%s' with CNID: %u from database",
                             cwdbuf, name, ntohl(db_cnid));
-            ad_init(&ad, myvolinfo->v_adouble, myvolinfo->v_ad_options);
-            if (ad_open_metadata( name, adflags, O_RDWR, &ad) != 0) {
+            ad_init_old(&ad, myvolinfo->v_adouble, myvolinfo->v_ad_options);
+            if (ad_open(&ad, name, adflags | ADFLAGS_HF | ADFLAGS_RDWR) != 0) {
                 dbd_log(LOGSTD, "Error opening AppleDouble file for '%s/%s': %s",
                         cwdbuf, name, strerror(errno));
                 return CNID_INVALID;
             }
             ad_setid( &ad, st->st_dev, st->st_ino, db_cnid, did, stamp);
             ad_flush(&ad);
-            ad_close_metadata(&ad);
+            ad_close(&ad, ADFLAGS_HF);
         }
         return db_cnid;
     } else if (ad_cnid && (db_cnid == 0)) {
@@ -793,15 +793,15 @@ static cnid_t check_cnid(const char *name, cnid_t did, struct stat *st, int adfi
                     && ( ! (dbd_flags & DBD_FLAGS_SCAN))) {
                     dbd_log(LOGSTD, "Writing CNID data for '%s/%s' to AppleDouble file",
                             cwdbuf, name, ntohl(db_cnid));
-                    ad_init(&ad, myvolinfo->v_adouble, myvolinfo->v_ad_options);
-                    if (ad_open_metadata( name, adflags, O_RDWR, &ad) != 0) {
+                    ad_init_old(&ad, myvolinfo->v_adouble, myvolinfo->v_ad_options);
+                    if (ad_open(&ad, name, adflags | ADFLAGS_RDWR) != 0) {
                         dbd_log(LOGSTD, "Error opening AppleDouble file for '%s/%s': %s",
                                 cwdbuf, name, strerror(errno));
                         return CNID_INVALID;
                     }
                     ad_setid( &ad, st->st_dev, st->st_ino, db_cnid, did, stamp);
                     ad_flush(&ad);
-                    ad_close_metadata(&ad);
+                    ad_close(&ad, ADFLAGS_HF);
                 }
                 return db_cnid;
             }
@@ -833,15 +833,15 @@ static cnid_t check_cnid(const char *name, cnid_t did, struct stat *st, int adfi
             if ( ! (dbd_flags & DBD_FLAGS_SCAN)) {
                 dbd_log(LOGSTD, "Writing CNID data for '%s/%s' to AppleDouble file",
                         cwdbuf, name, ntohl(db_cnid));
-                ad_init(&ad, myvolinfo->v_adouble, myvolinfo->v_ad_options);
-                if (ad_open_metadata( name, adflags, O_RDWR, &ad) != 0) {
+                ad_init_old(&ad, myvolinfo->v_adouble, myvolinfo->v_ad_options);
+                if (ad_open(&ad, name, adflags | ADFLAGS_RDWR) != 0) {
                     dbd_log(LOGSTD, "Error opening AppleDouble file for '%s/%s': %s",
                             cwdbuf, name, strerror(errno));
                     return CNID_INVALID;
                 }
                 ad_setid( &ad, st->st_dev, st->st_ino, db_cnid, did, stamp);
                 ad_flush(&ad);
-                ad_close_metadata(&ad);
+                ad_close(&ad, ADFLAGS_HF);
             }
         }
         return db_cnid;
index aec73ecac842f11657aa1b3582f7d15473b6f3d2..2a3bc6b9f32ce83e4ad0930dab5ab80bd8021e91 100644 (file)
@@ -44,7 +44,7 @@
 #include <sys/wait.h>
 #include <sys/uio.h>
 #include <sys/un.h>
-#define _XPG4_2 1
+// #define _XPG4_2 1
 #include <sys/socket.h>
 #include <stdio.h>
 #include <time.h>
@@ -90,6 +90,7 @@
 #include <atalk/cnid_dbd_private.h>
 #include <atalk/paths.h>
 #include <atalk/volinfo.h>
+#include <atalk/compat.h>
 
 #include "usockfd.h"
 
index dbe8da14c0707df7d03d4079f9fe52ee5417638a..23c6a58edaa18cfdeef1189759c047453ffd2416 100644 (file)
@@ -210,7 +210,7 @@ int comm_rcv(struct cnid_dbd_rqst *rqst, time_t timeout, const sigset_t *sigmask
         return -1;
     }
 
-    nametmp = rqst->name;
+    nametmp = (char *)rqst->name;
     if ((b = readt(cur_fd, rqst, sizeof(struct cnid_dbd_rqst), 1, CNID_DBD_TIMEOUT))
         != sizeof(struct cnid_dbd_rqst)) {
         if (b)
@@ -220,7 +220,7 @@ int comm_rcv(struct cnid_dbd_rqst *rqst, time_t timeout, const sigset_t *sigmask
         return 0;
     }
     rqst->name = nametmp;
-    if (rqst->namelen && readt(cur_fd, rqst->name, rqst->namelen, 1, CNID_DBD_TIMEOUT)
+    if (rqst->namelen && readt(cur_fd, (char *)rqst->name, rqst->namelen, 1, CNID_DBD_TIMEOUT)
         != rqst->namelen) {
         LOG(log_error, logtype_cnid, "error reading message name: %s", strerror(errno));
         invalidate_fd(cur_fd);
@@ -228,7 +228,7 @@ int comm_rcv(struct cnid_dbd_rqst *rqst, time_t timeout, const sigset_t *sigmask
     }
     /* We set this to make life easier for logging. None of the other stuff
        needs zero terminated strings. */
-    rqst->name[rqst->namelen] = '\0';
+    ((char *)(rqst->name))[rqst->namelen] = '\0';
 
     LOG(log_maxdebug, logtype_cnid, "comm_rcv: got %u bytes", b + rqst->namelen);
 
index 37ca4b6758374b906e6e81cd9d9843dd79d1b003..0d6e9b9eb7b2b28d0599886d3c71703defc3e569 100644 (file)
@@ -8,7 +8,6 @@
 #define CNID_DBD_DB_PARAM_H 1
 
 #include <sys/param.h>
-#include <sys/cdefs.h>
 
 #define DEFAULT_LOGFILE_AUTOREMOVE 1
 #define DEFAULT_CACHESIZE          (8 * 1024) /* KB, so 8 MB */
index b4f7e5d4a0013adfa8f50be1825d0e9ed7f664bc..bfa60954037c19bbfca7d998ab34d9725f50792a 100644 (file)
@@ -7,6 +7,8 @@
 #ifndef CNID_DBD_DBD_H
 #define CNID_DBD_DBD_H 1
 
+#include <arpa/inet.h>
+
 #include <atalk/cnid_dbd_private.h>
 
 extern int add_cnid(DBD *dbd, struct cnid_dbd_rqst *rqst, struct cnid_dbd_rply *rply);
index 6a818a3b325063f27fe37a0a412d6081bf6bb0b8..418a10f9da9a22919780b5ade075c5e35eecac1f 100644 (file)
@@ -9,16 +9,10 @@
 #endif /* HAVE_CONFIG_H */
 
 #include <string.h>
-#ifdef HAVE_UNISTD_H
 #include <unistd.h>
-#endif /* HAVE_UNISTD_H */
-#ifdef HAVE_FCNTL_H
 #include <fcntl.h>
-#endif /* HAVE_FCNTL_H */
 #include <errno.h>
-#ifdef HAVE_SYS_TIME_H
 #include <sys/time.h>
-#endif /* HAVE_SYS_TIME_H */
 
 #include <atalk/logger.h>
 #include <atalk/cnid_dbd_private.h>
index 3ea137e463dea4ff23aa12a50ae404966062a162..e621704f9339305aeac21c9e1e35555c65bdcb30 100644 (file)
@@ -9,12 +9,12 @@
 #include "config.h"
 #endif /* HAVE_CONFIG_H */
 
-
 #include <stdio.h>
 #include <string.h>
 #include <sys/param.h>
 #include <errno.h>
-#include <netatalk/endian.h>
+#include <arpa/inet.h>
+
 #include <atalk/logger.h>
 #include <atalk/cnid_dbd_private.h>
 
index dbbe521c85f9e1c2b4641188f7f30ee1fc65d46f..a4a3ca63e29a8c58aad3b15a1ace3e66a2793701 100644 (file)
@@ -11,7 +11,8 @@
 
 #include <string.h>
 #include <errno.h>
-#include <netatalk/endian.h>
+#include <arpa/inet.h>
+
 #include <atalk/logger.h>
 #include <atalk/cnid_dbd_private.h>
 
index 9c07c40519799f4ad3ef94524a2d6c07c3ba0dea..0ef71b19670c8c734ec34d3f825604559a41e682 100644 (file)
@@ -13,7 +13,8 @@
 #include <sys/param.h>
 #include <atalk/logger.h>
 #include <errno.h>
-#include <netatalk/endian.h>
+#include <arpa/inet.h>
+
 #include <atalk/cnid_dbd_private.h>
 
 
index ea75c4aba67799356636162a70c5c0a4194c63a4..b805d42863366310bc803a0178518c6794a0de3b 100644 (file)
@@ -13,7 +13,8 @@
 #include <string.h>
 #include <atalk/logger.h>
 #include <errno.h>
-#include <netatalk/endian.h>
+#include <arpa/inet.h>
+
 #include <atalk/cnid_dbd_private.h>
 
 #include "dbif.h"
index cd60223ed80ec5c90d224516971a9bfbdc69149d..04c536584b96a7d765bae32df9276bb2de78fea0 100644 (file)
@@ -116,7 +116,8 @@ to be safe we must assign new CNIDs to both files.
 #include <string.h>
 #include <sys/param.h>
 #include <errno.h>
-#include <netatalk/endian.h>
+#include <arpa/inet.h>
+
 #include <atalk/logger.h>
 #include <atalk/cnid_dbd_private.h>
 
index f3a93e4ca54d3d9ae03fb3bd0f60771f3551542e..562838b384a28dacc46873f8742a8296a6a2eba1 100644 (file)
 
 #include <stdio.h>
 #include <string.h>
+#include <arpa/inet.h>
+
 #include <atalk/logger.h>
-#include <netatalk/endian.h>
 #include <atalk/cnid_dbd_private.h>
 
-
 #include "pack.h"
 #include "dbif.h"
 #include "dbd.h"
index 1c2e2da914bc0143df5d1c54f523be86c99e5281..bb3561caba7a1018605be36649d85b13abb8ab29 100644 (file)
@@ -12,7 +12,8 @@
 #include <string.h>
 #include <atalk/logger.h>
 #include <errno.h>
-#include <netatalk/endian.h>
+#include <arpa/inet.h>
+
 #include <atalk/cnid_dbd_private.h>
 
 #include "dbif.h"
index a2efc33cfa6520071f302ee1f4947c4793638bf0..66979424f868f8507c5ba0368d6c330067cb43a3 100644 (file)
@@ -9,7 +9,8 @@
 
 #include <string.h>
 #include <errno.h>
-#include <netatalk/endian.h>
+#include <arpa/inet.h>
+
 #include <atalk/logger.h>
 #include <atalk/cnid_dbd_private.h>
 
@@ -29,7 +30,7 @@ int dbd_search(DBD *dbd, struct cnid_dbd_rqst *rqst, struct cnid_dbd_rply *rply)
     rply->name = resbuf;
     rply->namelen = 0;
 
-    key.data = rqst->name;
+    key.data = (char *)rqst->name;
     key.size = rqst->namelen;
 
     if ((results = dbif_search(dbd, &key, resbuf)) < 0) {
index d2ce83eca388ae6381be8ed2fa030a43dae58f0b..e8abf5d23dd3df7ee946b7ea8e362b2c62b4485e 100644 (file)
@@ -11,7 +11,8 @@
 #include <string.h>
 #include <errno.h>
 #include <atalk/logger.h>
-#include <netatalk/endian.h>
+#include <arpa/inet.h>
+
 #include <atalk/cnid_dbd_private.h>
 
 
index b96b2e6878c38f0f807a10387d12a69b487faa34..217fdd6d73d7255e6e1a16acc8c9acc3f7ada82b 100644 (file)
@@ -14,8 +14,8 @@
 #include <string.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <sys/cdefs.h>
 #include <unistd.h>
+#include <arpa/inet.h>
 
 #include <db.h>
 
index c936a2b93705daf7b5bf1a8061131f7a3174dd37..8c71de36b96221f598f64f4943b0878e7906f444 100644 (file)
@@ -53,7 +53,6 @@
 #ifndef CNID_DBD_DBIF_H
 #define CNID_DBD_DBIF_H 1
 
-#include <sys/cdefs.h>
 #include <db.h>
 #include <atalk/adouble.h>
 #include "db_param.h"
index e050a0e5137c4c1010f98ffc30865edffd4d384a..55bbcddbb100c3b34fb34f5355d965c00bc6b3f0 100644 (file)
@@ -8,28 +8,20 @@
 #include "config.h"
 #endif /* HAVE_CONFIG_H */
 
-#ifdef HAVE_UNISTD_H
 #include <unistd.h>
-#endif /* HAVE_UNISTD_H */
-#ifdef HAVE_FCNTL_H
 #include <fcntl.h>
-#endif /* HAVE_FCNTL_H */
 #include <stdio.h>
 #include <stdlib.h>
 #include <errno.h>
 #include <signal.h>
 #include <string.h>
-#ifdef HAVE_SYS_TYPES_H
 #include <sys/types.h>
-#endif /* HAVE_SYS_TYPES_H */
 #include <sys/param.h>
-#ifdef HAVE_SYS_STAT_H
 #include <sys/stat.h>
-#endif /* HAVE_SYS_STAT_H */
 #include <time.h>
 #include <sys/file.h>
+#include <arpa/inet.h>
 
-#include <netatalk/endian.h>
 #include <atalk/cnid_dbd_private.h>
 #include <atalk/logger.h>
 #include <atalk/volinfo.h>
index 2612469415eaa5582d71712bca82dc5b63c33770..69f5fa627e7125c157a273448bf948a374679566 100644 (file)
@@ -8,12 +8,11 @@
 #include "config.h"
 #endif /* HAVE_CONFIG_H */
 
-#include <netatalk/endian.h>
+#include <arpa/inet.h>
 
 #include <string.h>
 #include <inttypes.h>
 #include <sys/param.h>
-#include <sys/cdefs.h>
 #include <db.h>
 
 #include <atalk/unicode.h>
index ceb6ff211ad6628693b18e48bb2c1fbec2925c03..ff1538b340c334c2428457455c8e3cf2bfda9f21 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
-#ifdef HAVE_UNISTD_H
 #include <unistd.h>
-#endif /* HAVE_UNISTD_H */
 #include <sys/un.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <netdb.h>
-
-#ifdef HAVE_SYS_TYPES_H
 #include <sys/types.h>
-#endif /* HAVE_SYS_TYPES_H */
-#ifdef HAVE_SYS_TIME_H
 #include <sys/time.h>
-#endif /* HAVE_SYS_TIME_H */
-
 
 #include <atalk/logger.h>
 #include "usockfd.h"
diff --git a/etc/papd/.gitignore b/etc/papd/.gitignore
deleted file mode 100644 (file)
index b15fd9a..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-Makefile
-Makefile.in
-papd
-showppd
-.deps
-.libs
-.gitignore
-auth.o comment.o file.o headers.o lp.o magics.o main.o ppd.o printcap.o print_cups.o queries.o session.o showppd-ppd.o showppd-showppd.o uam.o
diff --git a/etc/papd/Makefile.am b/etc/papd/Makefile.am
deleted file mode 100644 (file)
index 6a09abd..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-# Makefile.am for etc/papd/
-
-pkgconfdir = @PKGCONFDIR@
-spooldir = @SPOOLDIR@
-
-sbin_PROGRAMS = papd
-bin_PROGRAMS = showppd
-
-papd_SOURCES = main.c printcap.c session.c file.c comment.c lp.c ppd.c \
-              magics.c headers.c queries.c auth.c uam.c print_cups.c
-
-papd_LDADD = $(top_builddir)/libatalk/libatalk.la @CUPS_LIBS@ @LIBADD_DL@
-papd_LDFLAGS = -export-dynamic @CUPS_LDFLAGS@
-
-showppd_SOURCES = showppd.c ppd.c
-showppd_CFLAGS = -DSHOWPPD
-showppd_LDADD = $(top_builddir)/libatalk/libatalk.la
-
-noinst_HEADERS =       \
-       comment.h       \
-       file.h          \
-       lp.h            \
-       ppd.h           \
-       printcap.h      \
-       printer.h       \
-       session.h       \
-       print_cups.h    \
-       uam_auth.h
-
-AM_CFLAGS = \
-       -I$(top_srcdir)/include -I$(top_srcdir)/sys \
-       @CUPS_CFLAGS@\
-       -D_PATH_PAPDCONF=\"$(pkgconfdir)/papd.conf\" \
-       -D_PATH_PAPDUAMPATH=\"$(UAMS_PATH)/\" \
-       -DSPOOLDIR=\"$(spooldir)/\"
-
-if USE_SPOOLDIR
-install-exec-hook:
-       echo "Creating SPOOLDIR $(DESTDIR)$(spooldir)..."
-       $(mkinstalldirs) $(DESTDIR)$(spooldir)
-       chmod 0777 $(DESTDIR)$(spooldir)
-
-else
-install-exec-hook:
-
-endif
diff --git a/etc/papd/auth.c b/etc/papd/auth.c
deleted file mode 100644 (file)
index a8ba6fd..0000000
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * $Id: auth.c,v 1.9 2009-10-13 22:55:37 didg Exp $
- *
- * Copyright (c) 1990,1993 Regents of The University of Michigan.
- * All Rights Reserved.  See COPYRIGHT.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <stdio.h>
-#include <stdlib.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/stat.h>
-#include <netatalk/endian.h>
-#include <atalk/afp.h>
-#include <atalk/compat.h>
-#include <atalk/util.h>
-#include <limits.h>
-#include <string.h>
-#include <ctype.h>
-#include <pwd.h>
-#include <grp.h>
-#include <atalk/logger.h>
-
-#include "uam_auth.h"
-
-static struct uam_mod uam_modules = {NULL, NULL, &uam_modules, &uam_modules};
-static struct uam_obj uam_login = {"", "", 0, {{NULL, NULL, NULL}}, &uam_login,
-                                  &uam_login};
-static struct uam_obj uam_changepw = {"", "", 0, {{NULL, NULL, NULL}}, &uam_changepw, 
-                                     &uam_changepw};
-static struct uam_obj uam_printer = {"", "", 0, {{NULL, NULL, NULL}}, &uam_printer,
-                                       &uam_printer};
-
-
-/*
- * Return a list of names for loaded uams
- */
-int getuamnames(const int type, char *uamnames)
-{
-    struct uam_obj *prev, *start;
-  
-    if (!(start = UAM_LIST(type)))
-        return(-1);
-  
-    prev = start;
-      
-    while((prev = prev->uam_prev) != start) {
-        strcat(uamnames, prev->uam_name);
-        strcat(uamnames, "\n");
-    }
-    strcat(uamnames, "*\n");
-    return(0);
-}
-  
-
-/* just do a linked list search. this could be sped up with a hashed
- * list, but i doubt anyone's going to have enough uams to matter. */
-struct uam_obj *auth_uamfind(const int type, const char *name, 
-                            const int len)
-{
-  struct uam_obj *prev, *start;
-
-  if (!name || !(start = UAM_LIST(type)))
-    return NULL;
-
-  prev = start;
-  while ((prev = prev->uam_prev) != start) 
-    if (strndiacasecmp(prev->uam_name, name, len) == 0)
-      return prev;
-
-  return NULL;
-}
-
-int auth_register(const int type, struct uam_obj *uam)
-{
-  struct uam_obj *start;
-
-  if (!uam || !uam->uam_name || (*uam->uam_name == '\0'))
-    return -1;
-
-  if (!(start = UAM_LIST(type)))
-    return 1; 
-
-  uam_attach(start, uam);
-  return 0;
-}
-
-/* load all of the modules */
-int auth_load(const char *path, const char *list)
-{
-  char name[MAXPATHLEN + 1], buf[MAXPATHLEN + 1], *p; 
-  struct uam_mod *mod;
-  struct stat st;
-  size_t len;
-  
-  if (!path || !list || (len = strlen(path)) > sizeof(name) - 2)
-    return -1;
-
-  strlcpy(buf, list, sizeof(buf));
-  if ((p = strtok(buf, ",")) == NULL)
-    return -1;
-
-  strcpy(name, path);
-  if (name[len - 1] != '/') {
-    strcat(name, "/");
-    len++;
-  }
-
-  while (p) {
-    strlcpy(name + len, p, sizeof(name) - len);
-    if ((stat(name, &st) == 0) && (mod = uam_load(name, p))) {
-      uam_attach(&uam_modules, mod);
-      LOG(log_info, logtype_papd, "uam: %s loaded", p);
-    }
-    p = strtok(NULL, ",");
-  }
-  return 0;
-}
-
-/* get rid of all of the uams */
-void auth_unload(void)
-{
-  struct uam_mod *mod, *prev, *start = &uam_modules;
-
-  prev = start->uam_prev;
-  while ((mod = prev) != start) {
-    prev = prev->uam_prev;
-    uam_detach(mod);
-    uam_unload(mod);
-  }
-}
diff --git a/etc/papd/comment.c b/etc/papd/comment.c
deleted file mode 100644 (file)
index 1a2964d..0000000
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * $Id: comment.c,v 1.10 2009-10-13 22:55:37 didg Exp $
- *
- * Copyright (c) 1990,1994 Regents of The University of Michigan.
- * All Rights Reserved.  See COPYRIGHT.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <atalk/logger.h>
-#include <sys/param.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-#include "comment.h"
-
-struct comstate        *comstate;
-
-char   *comcont = "%%+";
-
-void compop( void )
-{
-    struct comstate    *cs;
-
-    cs = comstate;
-    comstate = cs->cs_prev;
-    free( cs );
-}
-
-void compush(struct papd_comment *comment)
-{
-    struct comstate    *cs;
-
-    if (( cs = (struct comstate *)malloc( sizeof( struct comstate ))) ==
-           NULL ) {
-       LOG(log_error, logtype_papd, "malloc: %s", strerror(errno) );
-       exit( 1 );
-    }
-
-    cs->cs_comment = comment;
-    cs->cs_prev = comstate;
-    cs->cs_flags = 0;
-    comstate = cs;
-}
-
-int comswitch(struct papd_comment *comments, int (*handler)())
-{
-    struct papd_comment        *c, *comment = NULL;
-
-    for ( c = comments; c->c_begin; c++ ) {
-       if ( c->c_handler == handler ) {
-           comment = c;
-       }
-    }
-    if ( comment == NULL || comment->c_handler != handler ) {
-       LOG(log_error, logtype_papd, "comswitch: can't find handler!" );
-       return( -1 );
-    }
-    compop();
-    compush( comment );
-    return( 0 );
-}
-
-int comcmp( char *start, char *stop, char *str,int how)
-{
-    int                cc, len;
-
-    len = stop - start;
-    cc = strlen( str );
-    if ( how & C_FULL ) {
-       if ( (cc == len) && (strncmp( str, start, cc ) == 0) ) {
-           return( 0 );
-       }
-    } else {
-       if ( (cc <= len) && (strncmp( str, start, cc ) == 0) ) {
-           return( 0 );
-       }
-    }
-
-    return( 1 );
-}
-
-struct papd_comment *commatch( char *start, char *stop, struct papd_comment comments[])
-{
-    struct papd_comment        *comment;
-
-    for ( comment = comments; comment->c_begin; comment++ ) {
-       if ( comcmp( start, stop, comment->c_begin, comment->c_flags ) == 0 ) {
-           break;
-       }
-    }
-    if ( comment->c_begin ) {
-       return( comment );
-    } else {
-       return( NULL );
-    }
-}
-
-char *comtoken( char *start, char *stop, char *pos, char *delim)
-{
-    if ( pos < start || pos > stop ) {
-       abort();
-    }
-
-    for ( ; pos < stop; pos++ ) {
-       if ( index( delim, *pos )) {
-           break;
-       }
-    }
-    if ( ++pos < stop ) {
-       return( pos );
-    } else {
-       return( NULL );
-    }
-}
diff --git a/etc/papd/comment.h b/etc/papd/comment.h
deleted file mode 100644 (file)
index 1cac2d0..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * $Id: comment.h,v 1.6 2009-10-13 22:55:37 didg Exp $
- *
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- * All Rights Reserved.  See COPYRIGHT.
- */
-
-#ifndef PAPD_COMMENT_H
-#define PAPD_COMMENT_H 1
-
-#include <sys/cdefs.h>
-
-struct papd_comment {
-    char               *c_begin;
-    char               *c_end;
-    int                        (*c_handler)();
-    int                        c_flags;
-};
-
-#define CH_DONE                0
-#define CH_MORE                1
-#define CH_ERROR       -1
-
-struct comstate {
-    struct papd_comment        *cs_comment;
-    struct comstate    *cs_prev;
-    int                        cs_flags;
-};
-
-extern struct papd_comment     *commatch();
-extern struct comstate         *comstate;
-extern struct papd_comment     magics[];
-extern struct papd_comment     queries[];
-extern struct papd_comment     headers[];
-extern char                    *comcont;
-
-#define compeek()      (comstate==NULL?NULL:(comstate->cs_comment))
-#define comgetflags()  (comstate->cs_flags)
-#define comsetflags(f) (comstate->cs_flags=(f))
-
-/*
- * Comment flags.  0-15 reserved for "global" flags, 16-31 for specific
- * subtypes.
- */
-#define C_FULL         (1<<0)                          /* or prefix */
-#define C_CONTINUE     (1<<1)
-
-/*
- * Query subtypes.
- */
-
-/*
- * Magic "number" subtypes.
- */
-#define CM_NOPRINT     (1<<16)                         /* or print */
-
-void compop ( void );
-void compush ( struct papd_comment * );
-int comswitch ( struct papd_comment *, int (*)() );
-int comcmp ( char *, char *, char *, int );
-struct papd_comment *commatch ( char *, char *, struct papd_comment * );
-char *comtoken ( char *, char *, char *, char * );
-
-#endif /* PAPD_COMMENT_H */
diff --git a/etc/papd/file.c b/etc/papd/file.c
deleted file mode 100644 (file)
index 068b5d7..0000000
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * $Id: file.c,v 1.12 2009-10-14 02:24:05 didg Exp $
- *
- * Copyright (c) 1990,1994 Regents of The University of Michigan.
- * All Rights Reserved.  See COPYRIGHT.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <atalk/logger.h>
-#include <sys/param.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "file.h"
-
-/* 
-*/
-int markline( struct papfile *pf, char **start, int *linelength, int *crlflength )
-{
-    char               *p;
-
-    if ( pf->pf_datalen == 0 && ( pf->pf_state & PF_EOF )) {
-       return( 0 );
-    }
-
-    *start = pf->pf_data;
-
-    /* get a line */
-    for ( *linelength=0; *linelength < pf->pf_datalen; (*linelength)++) {
-       if (pf->pf_data[*linelength] == '\n' ||
-           pf->pf_data[*linelength] == '\r') {
-           break;
-       }
-    }
-
-    if ( *linelength >= pf->pf_datalen ) {
-       if ( pf->pf_state & PF_EOF ) {
-           append( pf, "\n", 1 );
-       } else if (*linelength < 1024) {
-           return( -1 );
-       }
-    }
-
-    p = pf->pf_data + *linelength;
-
-    *crlflength=0;
-    while(*crlflength < pf->pf_datalen-*linelength && 
-    (p[*crlflength]=='\r' || p[*crlflength]=='\n')) {
-       (*crlflength)++;
-    }
-    
-    if (!*crlflength) {
-        /* line is way too long, something fishy is going on, give up */
-        LOG(log_error, logtype_papd, "markline: no crlf in comment, give up" );
-        return( -2 );
-    }
-
-    /* success, return 1 */
-    return( 1 );
-}
-
-void morespace(struct papfile *pf, const char *data, int len)
-{
-    char               *nbuf;
-    int                        nsize;
-
-    if ( pf->pf_data != pf->pf_buf ) {                 /* pull up */
-       bcopy( pf->pf_data, pf->pf_buf, pf->pf_datalen);
-       pf->pf_data = pf->pf_buf;
-    }
-
-    if ( pf->pf_datalen + len > pf->pf_bufsize ) {     /* make more space */
-       nsize = (( pf->pf_bufsize + len ) / PF_MORESPACE +
-               (( pf->pf_bufsize + len ) % PF_MORESPACE != 0 )) * PF_MORESPACE;
-       if ( pf->pf_buf ) {
-           if (( nbuf = (char *)realloc( pf->pf_buf, nsize )) == NULL ) {
-               exit( 1 );
-           }
-       } else {
-           if (( nbuf = (char *)malloc( nsize )) == NULL ) {
-               exit( 1 );
-           }
-       }
-       pf->pf_bufsize = nsize;
-       pf->pf_data = nbuf + ( pf->pf_data - pf->pf_buf );
-       pf->pf_buf = nbuf;
-    }
-
-    bcopy( data, pf->pf_data + pf->pf_datalen, len );
-    pf->pf_datalen += len;
-}
-
-
-void append(struct papfile *pf, const char *data, int len)
-{
-    if ((pf->pf_data + pf->pf_datalen + len) >
-       (pf->pf_buf + pf->pf_bufsize)) {
-               morespace(pf, data, len);
-    } else {
-       memcpy(pf->pf_data + pf->pf_datalen, data, len);
-       pf->pf_datalen += len;
-    }
-}
-
-
-void spoolerror(struct papfile *out, char *str)
-{
-    char       *pserr1 = "%%[ Error: ";
-    char       *pserr2 = " ]%%\n";
-
-    if ( str == NULL ) {
-       str = "Spooler error.";
-    }
-
-    append( out, pserr1, strlen( pserr1 ));
-    append( out, str, strlen( str ));
-    append( out, pserr2, strlen( pserr2 ));
-}
diff --git a/etc/papd/file.h b/etc/papd/file.h
deleted file mode 100644 (file)
index 9f1f52d..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * $Id: file.h,v 1.8 2009-10-13 22:55:37 didg Exp $
- *
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- * All Rights Reserved.  See COPYRIGHT.
- */
-
-#ifndef PAPD_FILE_H
-#define PAPD_FILE_H 1
-
-#include <sys/cdefs.h>
-
-struct papfile {
-    int                        pf_state;
-    struct state       *pf_xstate;
-    int                        pf_bufsize;
-    int                        pf_datalen;
-    char               *pf_buf;
-    char               *pf_data;
-    int                origin;
-};
-
-#define PF_BOT         (1<<0)
-#define PF_EOF         (1<<1)
-#define PF_QUERY       (1<<2)
-#define PF_STW         (1<<3)
-#define PF_TRANSLATE   (1<<4)
-
-#define CONSUME( pf, len )  {   (pf)->pf_data += (len); \
-                               (pf)->pf_datalen -= (len); \
-                               if ((pf)->pf_datalen <= 0) { \
-                                   (pf)->pf_data = (pf)->pf_buf; \
-                                   (pf)->pf_datalen = 0; \
-                               } \
-                           }
-
-#define PF_MORESPACE   1024
-
-int markline ( struct papfile *, char **, int *, int * );
-void morespace ( struct papfile *, const char *, int );
-void append ( struct papfile *, const char *, int );
-void spoolerror ( struct papfile *, char * );
-
-#endif /* PAPD_FILE_H */
diff --git a/etc/papd/headers.c b/etc/papd/headers.c
deleted file mode 100644 (file)
index dd31539..0000000
+++ /dev/null
@@ -1,330 +0,0 @@
-/*
- * $Id: headers.c,v 1.14 2009-10-29 13:38:15 didg Exp $
- *
- * Copyright (c) 1990,1994 Regents of The University of Michigan.
- * All Rights Reserved.  See COPYRIGHT.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h" 
-#endif /* HAVE_CONFIG_H */
-
-#include <sys/param.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <netatalk/at.h>
-#include <atalk/logger.h>
-
-#include "file.h"
-#include "comment.h"
-#include "lp.h"
-
-int ch_title( struct papfile *, struct papfile * );
-int ch_for( struct papfile *, struct papfile * );
-
-static char *get_text(char *start, int linelength)
-{
-    char *p, *q;
-    char *t, *ret;
-    char *stop;
-    
-    /* 1023 is arbitrary 255 max for comment but some may be escape \xxx and space and keyword */
-
-    if (linelength > 1023)
-        return NULL;
-
-    t = ret = calloc(1, linelength +1);
-
-    if (!ret)
-        return NULL;
-
-    stop = start + linelength;
-    for ( p = start; p < stop; p++ ) {
-        if ( *p == ':' ) {
-            p++;
-            break;
-        }
-    }
-    
-    for ( ; p < stop; p++ ) {
-        if (*p != ' ' && *p != '\t') {
-            break;
-        }
-    }
-
-    if ( p < stop && *p == '(' ) {
-        int count;
-        /* start with ( then it's a <text> */ 
-        p++;
-        for ( q = p, count = 1; q < stop; q++, t++ ) {
-            if (*q == '(') {
-              count++;
-            }
-            else if ( *q == ')' ) {
-                count--;
-                if (!count) {
-                    break;
-                }
-            }
-            *t = *q;
-        }
-    }
-    else {
-        /* it's a textline */
-        for ( q = p; q < stop; q++, t++ ) {
-            *t = *q;
-        }
-    }
-    return ret;
-}
-
-int ch_for( struct papfile *in, struct papfile *out _U_)
-{
-    char                *start, *cmt;
-    int                 linelength, crlflength;
-
-    switch ( markline( in, &start, &linelength, &crlflength )) {
-    case 0 :
-        return( 0 );
-
-    case -1 :
-        return( CH_MORE );
-
-    case -2 :
-        return( CH_ERROR );
-    }
-
-    cmt = get_text(start, linelength);
-
-    if ( cmt ) {
-       lp_for ( cmt );
-       free(cmt);
-    }
-
-    in->pf_state |= PF_TRANSLATE;
-    lp_write( in, start, linelength + crlflength );
-    in->pf_state &= ~PF_TRANSLATE;
-    compop();
-    CONSUME( in, linelength + crlflength );
-    return( CH_DONE );
-}
-
-int ch_title( struct papfile *in, struct papfile *out _U_)
-{
-    char               *start, *cmt;
-    int                        linelength, crlflength;
-
-    switch ( markline( in, &start, &linelength, &crlflength )) {
-    case 0 :
-       return( 0 );
-
-    case -1 :
-       return( CH_MORE );
-
-    case -2 :
-        return( CH_ERROR );
-    }
-
-#ifdef DEBUG
-    LOG(log_debug9, logtype_papd, "Parsing %%Title");
-#endif
-
-    cmt = get_text(start, linelength);
-
-    if ( cmt ) {
-       lp_job( cmt );
-       free(cmt);
-    }
-
-    in->pf_state |= PF_TRANSLATE;
-    lp_write( in, start, linelength + crlflength );
-    in->pf_state &= ~PF_TRANSLATE;
-    compop();
-    CONSUME( in, linelength + crlflength );
-    return( CH_DONE );
-}
-
-static int guess_creator ( char *creator )
-{
-       if (strstr(creator, "LaserWriter"))
-               return 1;
-       if (strstr(creator, "cgpdftops"))
-               return 2;
-
-       return 0;
-}
-
-
-int ch_creator( struct papfile *in, struct papfile *out _U_)
-{
-    char               *start, *cmt;
-    int                        linelength, crlflength;
-
-    switch ( markline( in, &start, &linelength, &crlflength )) {
-    case 0 :
-       return( 0 );
-
-    case -1 :
-       return( CH_MORE );
-
-    case -2 :
-        return( CH_ERROR );
-    }
-
-    cmt = get_text(start, linelength);
-
-    if ( cmt ) {
-       in->origin = guess_creator ( cmt );
-       free(cmt);
-       lp_origin(in->origin);
-    }
-
-    in->pf_state |= PF_TRANSLATE;
-    lp_write( in, start, linelength + crlflength );
-    in->pf_state &= ~PF_TRANSLATE;
-    compop();
-    CONSUME( in, linelength + crlflength );
-    return( CH_DONE );
-}
-
-int ch_endcomm( struct papfile *in, struct papfile *out _U_)
-{
-    char                *start;
-    int                 linelength, crlflength;
-
-#ifdef DEBUG
-    LOG(log_debug9, logtype_papd, "End Comment");
-#endif
-    in->pf_state |= PF_STW;
-
-    switch ( markline( in, &start, &linelength, &crlflength )) {
-    case 0 :
-       return( 0 );
-
-    case -1 :
-       return( CH_MORE );
-
-    case -2 :
-        return( CH_ERROR );
-    }
-
-    in->pf_state |= PF_TRANSLATE;
-    lp_write( in, start, linelength + crlflength );
-    in->pf_state &= ~PF_TRANSLATE;
-    compop();
-    CONSUME( in, linelength + crlflength );
-    return ( CH_DONE);
-}
-
-int ch_starttranslate( struct papfile *in, struct papfile *out _U_)
-{
-    char                *start;
-    int                 linelength, crlflength;
-
-#ifdef DEBUG
-    LOG(log_debug9, logtype_papd, "Start translate");
-#endif
-
-    switch ( markline( in, &start, &linelength, &crlflength )) {
-    case 0 :
-        return( 0 );
-
-    case -1 :
-        return( CH_MORE );
-
-    case -2 :
-        return( CH_ERROR );
-    }
-
-    in->pf_state |= PF_TRANSLATE;
-    lp_write( in, start, linelength + crlflength );
-    compop();
-    CONSUME( in, linelength + crlflength );
-    return ( CH_DONE);
-}
-
-int ch_endtranslate(struct papfile *in, struct papfile *out _U_)
-{
-    char                *start;
-    int                 linelength, crlflength;
-
-#ifdef DEBUG
-    LOG(log_debug9, logtype_papd, "EndTranslate");
-#endif
-
-    switch ( markline( in, &start, &linelength, &crlflength )) {
-    case 0 :
-        return( 0 );
-
-    case -1 :
-        return( CH_MORE );
-
-    case -2 :
-        return( CH_ERROR );
-    }
-
-    lp_write( in, start, linelength + crlflength );
-    in->pf_state &= ~PF_TRANSLATE;
-    compop();
-    CONSUME( in, linelength + crlflength );
-    return ( CH_DONE);
-}
-
-int ch_translateone( struct papfile *in, struct papfile *out _U_)
-{
-    char                *start;
-    int                 linelength, crlflength;
-
-#ifdef DEBUG
-    LOG(log_debug9, logtype_papd, "TranslateOne");
-#endif
-
-    switch ( markline( in, &start, &linelength, &crlflength )) {
-    case 0 :
-        return( 0 );
-
-    case -1 :
-        return( CH_MORE );
-
-    case -2 :
-        return( CH_ERROR );
-    }
-
-    in->pf_state |= PF_TRANSLATE;
-    lp_write( in, start, linelength + crlflength );
-    in->pf_state &= ~PF_TRANSLATE;
-    compop();
-    CONSUME( in, linelength + crlflength );
-    return ( CH_DONE);
-}
-
-
-
-
-/*
- * "Header" comments.
- */
-struct papd_comment    headers[] = {
-    { "%%Title:",                      NULL,           ch_title,       0 },
-    { "%%For:",                                NULL,           ch_for,         0 },
-    { "%%Creator:",                    NULL,           ch_creator,     0 },
-    { "%%EndComments",                 NULL,           ch_endcomm,     0 },
-    { "%%BeginFeature",                        NULL,           ch_starttranslate,  0 },
-    { "%%EndFeature",                  NULL,           ch_endtranslate,  0 },
-    { "%%BeginPageSetup",              NULL,           ch_starttranslate, 0 },
-    { "%%EndPageSetup",                        NULL,           ch_endtranslate, 0 },
-#if 0
-    { "%%BeginSetup",                  NULL,           ch_translateone,  0 },
-    { "%%EndSetup",                    NULL,           ch_translateone,  0 },
-    { "%%BeginProlog",                 NULL,           ch_translateone,  0 },
-    { "%%EndProlog",                   NULL,           ch_translateone,  0 },
-    { "%%Page:",                       NULL,           ch_translateone, 0 },
-    { "%%PageTrailer",                 NULL,           ch_translateone, 0 },
-    { "%%Trailer",                     NULL,           ch_translateone, 0 },
-    { "%%EOF",                         NULL,           ch_translateone, 0 },
-#endif
-    { "%%",                            NULL,           ch_translateone, 0 },
-    { NULL,                            NULL,           NULL,           0 },
-};
diff --git a/etc/papd/lp.c b/etc/papd/lp.c
deleted file mode 100644 (file)
index d315b12..0000000
+++ /dev/null
@@ -1,1153 +0,0 @@
-/*
- * $Id: lp.c,v 1.33 2009-10-29 13:38:15 didg Exp $
- *
- * Copyright (c) 1990,1994 Regents of The University of Michigan.
- * All Rights Reserved.  See COPYRIGHT.
- *
- * Portions:
- * Copyright (c) 1983 Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *      This product includes software developed by the University of
- *      California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * Interface to lpr system.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <sys/param.h>
-#include <sys/time.h>
-#include <sys/socket.h>
-#include <sys/stat.h>
-#include <ctype.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
-
-#include <sys/file.h>
-#include <sys/un.h>
-#include <netinet/in.h>
-#undef s_net
-
-#ifdef ABS_PRINT
-#include <math.h>
-#endif /* ABS_PRINT */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <netdb.h>
-#ifdef HAVE_FCNTL_H
-#include <fcntl.h>
-#endif /* HAVE_FCNTL_H */
-#include <pwd.h>
-
-#include <atalk/logger.h>
-#include <netatalk/at.h>
-#include <atalk/atp.h>
-#include <atalk/paths.h>
-#include <atalk/unicode.h>
-
-#include "printer.h"
-#include "file.h"
-#include "lp.h"
-
-#ifdef HAVE_CUPS
-#include  "print_cups.h"
-#endif
-
-
-/* These functions aren't used outside of lp.c */
-int lp_conn_inet();
-int lp_disconn_inet( int );
-int lp_conn_unix();
-int lp_disconn_unix( int );
-
-static char hostname[ MAXHOSTNAMELEN ];
-
-extern struct sockaddr_at *sat;
-
-static struct lp {
-    int                        lp_flags;
-    FILE               *lp_stream;
-    int                        lp_seq;
-    int                lp_origin;
-    char               lp_letter;
-    char               *lp_person;
-    char               *lp_created_for; /* Holds the content of the Postscript %%For Comment if available */
-    char               *lp_host;
-    char               *lp_job;
-    char               *lp_spoolfile;
-} lp;
-#define LP_INIT                (1<<0)
-#define LP_OPEN                (1<<1)
-#define LP_PIPE                (1<<2)
-#define LP_CONNECT     (1<<3)
-#define LP_QUEUE       (1<<4)
-#define LP_JOBPENDING  (1<<5)
-
-void lp_origin (int origin)
-{
-    lp.lp_origin = origin;
-}
-
-/* the converted string should always be shorter, but ... FIXME! */
-static void convert_octal (char *string, charset_t dest)
-{
-    unsigned char *p, *q;
-    char temp[4];
-    long int ch;
-
-    q=p=(unsigned char *)string;
-    while ( *p != '\0' ) {
-        ch = 0;
-        if ( *p == '\\' ) {
-            p++;
-            if (dest && isdigit(*p) && isdigit(*(p+1)) && isdigit(*(p+2)) ) {
-                temp[0] = *p;
-                temp[1] = *(p+1);
-                temp[2] = *(p+2);
-                temp[3] = 0;
-                ch = strtol( temp, NULL, 8);
-                if ( ch && ch < 0xff)
-                    *q = ch;
-               else
-                    *q = '.';
-                p += 2;
-            }
-                   else 
-                *q = '.';
-       }
-       else {
-           *q = *p;
-       }
-           p++;
-           q++;
-    }
-    *q = 0;
-}
-
-
-static void translate(charset_t from, charset_t dest, char **option)
-{
-    char *translated;
-
-    if (*option != NULL) {
-        convert_octal(*option, from);
-        if (from) {
-             if ((size_t) -1 != (convert_string_allocate(from, dest, *option, -1, &translated)) ) {
-                 free (*option);
-                 *option = translated;
-             }
-        }
-    }
-}
-
-
-static void lp_setup_comments (charset_t dest)
-{
-    charset_t from=0;
-
-    switch (lp.lp_origin) {
-       case 1:
-               from=CH_MAC;
-               break;
-       case 2:
-               from=CH_UTF8_MAC;
-               break;
-    }
-
-    if (lp.lp_job) {
-#ifdef DEBUG1
-        LOG(log_debug9, logtype_papd, "job: %s", lp.lp_job );
-#endif
-        translate(from, dest, &lp.lp_job);
-    }
-    if (lp.lp_created_for) {
-#ifdef DEBUG1
-        LOG(log_debug9, logtype_papd, "for: %s", lp.lp_created_for );
-#endif
-        translate(from, dest, &lp.lp_created_for);
-    }
-    if (lp.lp_person) {
-#ifdef DEBUG1
-       LOG(log_debug9, logtype_papd, "person: %s", lp.lp_person );
-#endif
-       translate(from, dest, &lp.lp_person);
-    }
-}
-
-#define is_var(a, b) (strncmp((a), (b), 2) == 0)
-
-#if 0
-/* removed, it's not used and a pain to get it right from a security POV */
-static size_t quote(char *dest, char *src, const size_t bsize, size_t len)
-{
-size_t used = 0;
-
-    while (len && used < bsize ) {
-        switch (*src) {
-          case '$':
-          case '\\':
-          case '"':
-          case '`':
-            if (used + 2 > bsize )
-              return used;
-            *dest = '\\';
-            dest++;
-            used++;
-            break;
-        }
-        *dest = *src;
-        src++;
-        dest++;
-        len--;
-        used++;
-    }
-    return used;
-}
-
-static char* pipexlate(char *src)
-{
-    char *p, *q, *dest; 
-    static char destbuf[MAXPATHLEN +1];
-    size_t destlen = MAXPATHLEN;
-    int len = 0;
-   
-    dest = destbuf; 
-
-    if (!src)
-       return NULL;
-
-    memset(dest, 0, MAXPATHLEN +1);
-    if ((p = strchr(src, '%')) == NULL) { /* nothing to do */
-        strncpy(dest, src, MAXPATHLEN);
-        return destbuf;
-    }
-    /* first part of the path. copy and forward to the next variable. */
-    len = MIN((size_t)(p - src), destlen);
-    if (len > 0) {
-        strncpy(dest, src, len);
-        destlen -= len;
-        dest += len;
-    }
-
-    while (p && destlen > 0) {
-        /* now figure out what the variable is */
-        q = NULL;
-        if (is_var(p, "%U")) {
-           q = lp.lp_person;
-        } else if (is_var(p, "%C") || is_var(p, "%J") ) {
-            q = lp.lp_job;
-        } else if (is_var(p, "%F")) {
-            q =  lp.lp_created_for;
-        } else if (is_var(p, "%%")) {
-            q = "%";
-        } 
-
-        /* copy the stuff over. if we don't understand something that we
-         * should, just skip it over. */
-        if (q) {
-            len = MIN(strlen(q), destlen);
-            len = quote(dest, q, destlen, len);
-        }
-        else {
-            len = MIN(2, destlen);
-            strncpy(dest, q, len);
-        }
-        dest += len;
-        destlen -= len;
-
-        /* stuff up to next % */
-        src = p + 2;
-        p = strchr(src, '%');
-        len = p ? MIN((size_t)(p - src), destlen) : destlen;
-        if (len > 0) {
-            strncpy(dest, src, len);
-            dest += len;
-            destlen -= len;
-        }
-    }
-    if (!destlen) {
-        /* reach end of buffer, maybe prematurely, give up */
-        return NULL;
-    }
-    return destbuf;
-}
-#endif
-
-void lp_person(char *person)
-{
-    if ( lp.lp_person != NULL ) {
-       free( lp.lp_person );
-    }
-    if (( lp.lp_person = (char *)malloc( strlen( person ) + 1 )) == NULL ) {
-       LOG(log_error, logtype_papd, "malloc: %s", strerror(errno) );
-       exit( 1 );
-    }
-    strcpy( lp.lp_person, person );
-}
-
-#ifdef ABS_PRINT
-int lp_pagecost(void)
-{
-    char       cost[ 22 ];
-    char       balance[ 22 ];
-    int                err;
-
-    if ( lp.lp_person == NULL ) {
-       return( -1 );
-    }
-    err = ABS_canprint( lp.lp_person, printer->p_role, printer->p_srvid,
-           cost, balance );
-    printer->p_pagecost = floor( atof( cost ) * 10000.0 );
-    printer->p_balance = atof( balance ) + atof( cost );
-    return( err < 0 ? -1 : 0 );
-}
-#endif /* ABS_PRINT */
-
-void lp_host( char *host)
-{
-    if ( lp.lp_host != NULL ) {
-       free( lp.lp_host );
-    }
-    if (( lp.lp_host = (char *)malloc( strlen( host ) + 1 )) == NULL ) {
-       LOG(log_error, logtype_papd, "malloc: %s", strerror(errno) );
-       exit( 1 );
-    }
-    strcpy( lp.lp_host, host );
-    LOG(log_debug, logtype_papd, "host: %s", lp.lp_host );
-}
-
-/* Currently lp_job and lp_for will not handle the
- * conversion of macroman chars > 0x7f correctly
- * This should be added.
- */
-
-void lp_job(char *job)
-{
-    if ( lp.lp_job != NULL ) {
-       free( lp.lp_job );
-    }
-
-    lp.lp_job = strdup(job);
-#ifdef DEBUG
-    LOG(log_debug9, logtype_papd, "job: %s", lp.lp_job );
-#endif
-    
-}
-
-void lp_for (char *lpfor)
-{
-    if ( lp.lp_created_for != NULL ) {
-       free( lp.lp_created_for );
-    }
-
-    lp.lp_created_for = strdup(lpfor);
-}
-
-
-static int lp_init(struct papfile *out, struct sockaddr_at *sat)
-{
-    int                authenticated = 0;
-#ifndef HAVE_CUPS
-    int                fd, n, len;
-    char       *cp, buf[ BUFSIZ ];
-    struct stat        st;
-#endif /* HAVE_CUPS */
-#ifdef ABS_PRINT
-    char       cost[ 22 ];
-    char       balance[ 22 ];
-#endif /* ABS_PRINT */
-
-    if ( printer->p_flags & P_AUTH ) {
-       authenticated = 0;
-
-       /* cap style "log on to afp server before printing" authentication */
-
-       if ( printer->p_authprintdir && (printer->p_flags & P_AUTH_CAP) ) {
-           int addr_net = ntohs( sat->sat_addr.s_net );
-           int addr_node  = sat->sat_addr.s_node;
-           char addr_filename[256];
-           char auth_string[256];
-           char *username, *afpdpid;
-           struct stat cap_st;
-           FILE *cap_file;
-
-           memset( auth_string, 0, 256 );
-           sprintf(addr_filename, "%s/net%d.%dnode%d", 
-               printer->p_authprintdir, addr_net/256, addr_net%256, 
-               addr_node);
-           if (stat(addr_filename, &cap_st) == 0) {
-               if ((cap_file = fopen(addr_filename, "r")) != NULL) {
-                   if (fgets(auth_string, 256, cap_file) != NULL) {
-                       username = auth_string;
-                       if ((afpdpid = strrchr( auth_string, ':' )) != NULL) {
-                           *afpdpid = '\0';
-                           afpdpid++;
-                       }
-                       if (getpwnam(username) != NULL ) {
-                           LOG(log_info, logtype_papd, "CAP authenticated %s", username);
-                           lp_person(username);
-                           authenticated = 1;
-                       } else {
-                           LOG(log_info, logtype_papd, "CAP error: invalid username: '%s'", username);
-                       }
-                   } else {
-                       LOG(log_info, logtype_papd, "CAP error: could not read username");
-                   }
-               } else {
-                   LOG(log_info, logtype_papd, "CAP error: %s", strerror(errno));
-               }
-           } else {
-               LOG(log_info, logtype_papd, "CAP error: %s", strerror(errno));
-           }
-       }
-
-       if ( printer->p_flags & P_AUTH_PSSP ) {
-           if ( lp.lp_person != NULL ) {
-               authenticated = 1;
-           }
-       }
-
-       if ( authenticated == 0 ) {
-           LOG(log_error, logtype_papd, "lp_init: must authenticate" );
-           spoolerror( out, "Authentication required." );
-           return( -1 );
-       }
-
-#ifdef ABS_PRINT
-       if (( printer->p_flags & P_ACCOUNT ) && printer->p_pagecost > 0 &&
-               ! ABS_canprint( lp.lp_person, printer->p_role,
-               printer->p_srvid, cost, balance )) {
-           LOG(log_error, logtype_papd, "lp_init: no ABS funds" );
-           spoolerror( out, "No ABS funds available." );
-           return( -1 );
-       }
-#endif /* ABS_PRINT */
-    }
-
-    if ( gethostname( hostname, sizeof( hostname )) < 0 ) {
-       LOG(log_error, logtype_papd, "gethostname: %s", strerror(errno) );
-       exit( 1 );
-    }
-
-    if ( lp.lp_flags & LP_INIT ) {
-       LOG(log_error, logtype_papd, "lp_init: already inited, die!" );
-       abort();
-    }
-
-    lp.lp_flags = 0;
-    lp.lp_stream = NULL;
-    lp.lp_letter = 'A';
-
-    if ( printer->p_flags & P_SPOOLED ) {
-
-#ifndef HAVE_CUPS
-       /* check if queuing is enabled: mode & 010 on lock file */
-       if ( stat( printer->p_lock, &st ) < 0 ) {
-           LOG(log_error, logtype_papd, "lp_init: %s: %s", printer->p_lock, strerror(errno) );
-           spoolerror( out, NULL );
-           return( -1 );
-       }
-       if ( st.st_mode & 010 ) {
-           LOG(log_info, logtype_papd, "lp_init: queuing is disabled" );
-           spoolerror( out, "Queuing is disabled." );
-           return( -1 );
-       }
-
-       if (( fd = open( ".seq", O_RDWR|O_CREAT, 0661 )) < 0 ) {
-           LOG(log_error, logtype_papd, "lp_init: can't create .seq" );
-           spoolerror( out, NULL );
-           return( -1 );
-       }
-
-#ifndef SOLARIS /* flock is unsupported, I doubt this stuff works anyway with newer solaris so ignore for now */
-       if ( flock( fd, LOCK_EX ) < 0 ) {
-           LOG(log_error, logtype_papd, "lp_init: can't lock .seq" );
-           spoolerror( out, NULL );
-           return( -1 );
-       }
-#endif
-
-       n = 0;
-       if (( len = read( fd, buf, sizeof( buf ))) < 0 ) {
-           LOG(log_error, logtype_papd, "lp_init read: %s", strerror(errno) );
-           spoolerror( out, NULL );
-           return( -1 );
-       }
-       if ( len > 0 ) {
-           for ( cp = buf; len; len--, cp++ ) {
-               if ( *cp < '0' || *cp > '9' ) {
-                   break;
-               }
-               n = n * 10 + ( *cp - '0' );
-           }
-       }
-       lp.lp_seq = n;
-
-       n = ( n + 1 ) % 1000;
-       sprintf( buf, "%03d\n", n );
-       lseek( fd, 0L, 0 );
-       write( fd, buf, strlen( buf ));
-       close( fd );
-#else
-
-       if (cups_get_printer_status ( printer ) == 0)
-       {
-           spoolerror( out, "Queuing is disabled." );
-           return( -1 );
-       }
-
-       lp.lp_seq = getpid();
-#endif /* HAVE CUPS */
-    } else {
-       lp.lp_flags |= LP_PIPE;
-       lp.lp_seq = getpid();
-    }
-
-    lp.lp_flags |= LP_INIT;
-    return( 0 );
-}
-
-int lp_open(struct papfile *out, struct sockaddr_at *sat)
-{
-    char       name[ MAXPATHLEN ];
-    int                fd;
-    struct passwd      *pwent;
-
-#ifdef DEBUG
-    LOG (log_debug9, logtype_papd, "lp_open");
-#endif
-
-    if ( lp.lp_flags & LP_JOBPENDING ) {
-       lp_print();
-    }
-
-    if (( lp.lp_flags & LP_INIT ) == 0 && lp_init( out, sat ) != 0 ) {
-       return( -1 );
-    }
-    if ( lp.lp_flags & LP_OPEN ) {
-       /* LOG(log_error, logtype_papd, "lp_open already open" ); */
-       /* abort(); */
-       return (-1);
-    }
-
-    if ( lp.lp_flags & LP_PIPE ) {
-        char *pipe_cmd;
-
-       /* go right to program */
-       if (lp.lp_person != NULL) {
-           if((pwent = getpwnam(lp.lp_person)) != NULL) {
-               if(setreuid(pwent->pw_uid, pwent->pw_uid) != 0) {
-                   LOG(log_error, logtype_papd, "setreuid error: %s", strerror(errno));
-                   exit(1);
-               }
-           } else {
-               LOG(log_error, logtype_papd, "Error getting username (%s)", lp.lp_person);
-                exit(1);
-           }
-       }
-
-       lp_setup_comments(CH_UNIX);
-       pipe_cmd = printer->p_printer;
-       if (!pipe_cmd) {
-           LOG(log_error, logtype_papd, "lp_open: no pipe cmd" );
-           spoolerror( out, NULL );
-           return( -1 );
-       }
-       if (( lp.lp_stream = popen(pipe_cmd, "w" )) == NULL ) {
-           LOG(log_error, logtype_papd, "lp_open popen %s: %s", printer->p_printer, strerror(errno) );
-           spoolerror( out, NULL );
-           return( -1 );
-       }
-        LOG(log_debug, logtype_papd, "lp_open: opened %s",  pipe_cmd );
-    } else {
-       sprintf( name, "df%c%03d%s", lp.lp_letter++, lp.lp_seq, hostname );
-
-       if (( fd = open( name, O_WRONLY|O_CREAT|O_EXCL, 0660 )) < 0 ) {
-           LOG(log_error, logtype_papd, "lp_open %s: %s", name, strerror(errno) );
-           spoolerror( out, NULL );
-           return( -1 );
-       }
-
-       if ( NULL == (lp.lp_spoolfile = (char *) malloc (strlen (name) +1)) ) {
-           LOG(log_error, logtype_papd, "malloc: %s", strerror(errno));
-           exit(1);
-       }
-       strcpy ( lp.lp_spoolfile, name);        
-
-       if (lp.lp_person != NULL) {
-           if ((pwent = getpwnam(lp.lp_person)) == NULL) {
-               LOG(log_error, logtype_papd, "getpwnam %s: no such user", lp.lp_person);
-               spoolerror( out, NULL );
-               return( -1 );
-           }
-       } else {
-           if ((pwent = getpwnam(printer->p_operator)) == NULL) {
-               LOG(log_error, logtype_papd, "getpwnam %s: no such user", printer->p_operator);
-               spoolerror( out, NULL );
-               return( -1 );
-           }
-       }
-
-       if (fchown(fd, pwent->pw_uid, -1) < 0) {
-           LOG(log_error, logtype_papd, "chown %s %s: %s", pwent->pw_name, name, strerror(errno));
-           spoolerror( out, NULL );
-           return( -1 );
-       }
-
-       if (( lp.lp_stream = fdopen( fd, "w" )) == NULL ) {
-           LOG(log_error, logtype_papd, "lp_open fdopen: %s", strerror(errno) );
-           spoolerror( out, NULL );
-           return( -1 );
-       }
-#ifdef DEBUG        
-        LOG(log_debug9, logtype_papd, "lp_open: opened %s", name );
-#endif 
-    }
-    lp.lp_flags |= LP_OPEN;
-    return( 0 );
-}
-
-int lp_close(void)
-{
-    if (( lp.lp_flags & LP_INIT ) == 0 || ( lp.lp_flags & LP_OPEN ) == 0 ) {
-       return 0;
-    }
-    fclose( lp.lp_stream );
-    lp.lp_stream = NULL;
-    lp.lp_flags &= ~LP_OPEN;
-    lp.lp_flags |= LP_JOBPENDING;
-    return 0;
-}
-
-
-
-int lp_write(struct papfile *in, char *buf, size_t len)
-{
-#define BUFSIZE 32768
-    static char tempbuf[BUFSIZE];
-    static char tempbuf2[BUFSIZE];
-    static size_t bufpos = 0;
-    static int last_line_translated = 1; /* if 0, append a \n a the start */
-    char *tbuf = buf;
-
-    /* Before we write out anything check for a pending job, e.g. cover page */
-    if (lp.lp_flags & LP_JOBPENDING)
-       lp_print();
-
-    /* foomatic doesn't handle mac line endings, so we convert them for 
-     * the Postscript headers
-     * REALLY ugly hack, remove ASAP again */
-    if ((printer->p_flags & P_FOOMATIC_HACK) && (in->pf_state & PF_TRANSLATE) && 
-        (buf[len-1] != '\n') ) {
-        if (len <= BUFSIZE) {
-           if (!last_line_translated) {
-               tempbuf2[0] = '\n';
-               memcpy(tempbuf2+1, buf, len++);
-           }
-           else
-               memcpy(tempbuf2, buf, len);
-               
-            if (tempbuf2[len-1] == '\r')
-               tempbuf2[len-1] = '\n';
-            tempbuf2[len] = 0;
-            tbuf = tempbuf2;
-            last_line_translated = 1;
-#ifdef DEBUG
-            LOG(log_debug9, logtype_papd, "lp_write: %s", tbuf );
-#endif
-        }
-        else {
-            LOG(log_error, logtype_papd, "lp_write: conversion buffer too small" );
-            abort();
-        }
-    }
-    else {
-        if (printer->p_flags & P_FOOMATIC_HACK && buf[len-1] == '\n') {
-            last_line_translated = 1;
-       }
-        else
-           last_line_translated = 0;
-    }
-
-    /* To be able to do commandline substitutions on piped printers
-     * we store the start of the print job in a buffer.
-     * %%EndComment triggers writing to file */
-    if (( lp.lp_flags & LP_OPEN ) == 0 ) {
-#ifdef DEBUG
-        LOG(log_debug9, logtype_papd, "lp_write: writing to temporary buffer" );
-#endif
-       if ((bufpos+len) > BUFSIZE) {
-            LOG(log_error, logtype_papd, "lp_write: temporary buffer too small" );
-            /* FIXME: call lp_open here? abort isn't nice... */
-            abort();
-        }
-       else {
-            memcpy(tempbuf + bufpos, tbuf, len);
-            bufpos += len;
-            if (bufpos > BUFSIZE/2)
-                in->pf_state |= PF_STW; /* we used half of the buffer, start writing */
-            return(0);
-       }
-    }
-    else if ( bufpos) {
-        if ( fwrite( tempbuf, 1, bufpos, lp.lp_stream ) != bufpos ) {
-            LOG(log_error, logtype_papd, "lp_write: %s", strerror(errno) );
-            abort();
-        }
-        bufpos=0;
-    }
-
-    if ( fwrite( tbuf, 1, len, lp.lp_stream ) != len ) {
-       LOG(log_error, logtype_papd, "lp_write: %s", strerror(errno) );
-       abort();
-    }
-    return( 0 );
-}
-
-int lp_cancel(void)
-{
-    char       name[ MAXPATHLEN ];
-    char       letter;
-
-    if (( lp.lp_flags & LP_INIT ) == 0 || lp.lp_letter == 'A' ) {
-       return 0;
-    }
-
-    if ( lp.lp_flags & LP_OPEN ) {
-       lp_close();
-    }
-
-    for ( letter = 'A'; letter < lp.lp_letter; letter++ ) {
-       sprintf( name, "df%c%03d%s", letter, lp.lp_seq, hostname );
-       if ( unlink( name ) < 0 ) {
-           LOG(log_error, logtype_papd, "lp_cancel unlink %s: %s", name, strerror(errno) );
-       }
-    }
-
-    return 0;
-}
-
-/*
- * Create printcap control file, signal printer.  Errors here should
- * remove queue files.
- *
- * XXX piped?
- */
-int lp_print(void)
-{
-#ifndef HAVE_CUPS
-    char               buf[ MAXPATHLEN ];
-    char               tfname[ MAXPATHLEN ];
-    char               cfname[ MAXPATHLEN ];
-    char               letter;
-    int                        fd, n, s;
-    FILE               *cfile;
-#endif /* HAVE_CUPS */
-
-    if (( lp.lp_flags & LP_INIT ) == 0 || lp.lp_letter == 'A' ) {
-       return 0;
-    }
-    lp_close();
-    lp.lp_flags &= ~LP_JOBPENDING;
-
-    if ( printer->p_flags & P_SPOOLED ) {
-#ifndef HAVE_CUPS
-       sprintf( tfname, "tfA%03d%s", lp.lp_seq, hostname );
-       if (( fd = open( tfname, O_WRONLY|O_EXCL|O_CREAT, 0660 )) < 0 ) {
-           LOG(log_error, logtype_papd, "lp_print %s: %s", tfname, strerror(errno) );
-           return 0;
-       }
-       if (( cfile = fdopen( fd, "w" )) == NULL ) {
-           LOG(log_error, logtype_papd, "lp_print %s: %s", tfname, strerror(errno) );
-           return 0;
-       }
-       fprintf( cfile, "H%s\n", hostname );    /* XXX lp_host? */
-
-       if ( lp.lp_person ) {
-           fprintf( cfile, "P%s\n", lp.lp_person );
-       } else {
-           fprintf( cfile, "P%s\n", printer->p_operator );
-       }
-
-       if ( lp.lp_job && *lp.lp_job ) {
-           fprintf( cfile, "J%s\n", lp.lp_job );
-           fprintf( cfile, "T%s\n", lp.lp_job );
-       } else {
-           fprintf( cfile, "JMac Job\n" );
-           fprintf( cfile, "TMac Job\n" );
-       }
-
-       fprintf( cfile, "C%s\n", hostname );    /* XXX lp_host? */
-
-       if ( lp.lp_person ) {
-           fprintf( cfile, "L%s\n", lp.lp_person );
-       } else {
-           fprintf( cfile, "L%s\n", printer->p_operator );
-       }
-
-       for ( letter = 'A'; letter < lp.lp_letter; letter++ ) {
-           fprintf( cfile, "fdf%c%03d%s\n", letter, lp.lp_seq, hostname );
-           fprintf( cfile, "Udf%c%03d%s\n", letter, lp.lp_seq, hostname );
-       }
-
-       if ( lp.lp_job && *lp.lp_job ) {
-           fprintf( cfile, "N%s\n", lp.lp_job );
-       } else {
-           fprintf( cfile, "NMac Job\n" );
-       }
-       fclose( cfile );
-
-       sprintf( cfname, "cfA%03d%s", lp.lp_seq, hostname );
-       if ( link( tfname, cfname ) < 0 ) {
-           LOG(log_error, logtype_papd, "lp_print can't link %s to %s: %s", cfname,
-                   tfname, strerror(errno) );
-           return 0;
-       }
-       unlink( tfname );
-
-       if (( s = lp_conn_unix()) < 0 ) {
-           LOG(log_error, logtype_papd, "lp_print: lp_conn_unix: %s", strerror(errno) );
-           return 0;
-       }
-
-       sprintf( buf, "\1%s\n", printer->p_printer );
-       n = strlen( buf );
-       if ( write( s, buf, n ) != n ) {
-           LOG(log_error, logtype_papd, "lp_print write: %s" , strerror(errno));
-           return 0;
-       }
-       if ( read( s, buf, 1 ) != 1 ) {
-           LOG(log_error, logtype_papd, "lp_print read: %s" , strerror(errno));
-           return 0;
-       }
-
-       lp_disconn_unix( s );
-
-       if ( buf[ 0 ] != '\0' ) {
-           LOG(log_error, logtype_papd, "lp_print lpd said %c: %s", buf[ 0 ], strerror(errno) );
-           return 0;
-       }
-#else
-        if ( ! (lp.lp_job && *lp.lp_job) ) {
-            lp.lp_job = strdup("Mac Job");
-        }
-
-        lp_setup_comments(add_charset(cups_get_language ()));
-
-        if (lp.lp_person != NULL) {
-           cups_print_job ( printer->p_printer, lp.lp_spoolfile, lp.lp_job, lp.lp_person, printer->p_cupsoptions);
-        } else if (lp.lp_created_for != NULL) {
-            cups_print_job ( printer->p_printer, lp.lp_spoolfile, lp.lp_job, lp.lp_created_for, printer->p_cupsoptions);
-        } else {
-            cups_print_job ( printer->p_printer, lp.lp_spoolfile, lp.lp_job, printer->p_operator, printer->p_cupsoptions);
-        }
-
-       /*LOG(log_info, logtype_papd, "lp_print unlink %s", lp.lp_spoolfile );*/
-        unlink ( lp.lp_spoolfile );
-       return 0;
-#endif /* HAVE_CUPS*/
-    }
-    LOG(log_info, logtype_papd, "lp_print queued" );
-    return 0;
-}
-
-#ifndef HAVE_CUPS
-int lp_disconn_unix( int fd )
-{
-    return( close( fd ));
-}
-
-int lp_conn_unix(void)
-{
-    int                        s;
-    struct sockaddr_un saun;
-
-    if (( s = socket( AF_UNIX, SOCK_STREAM, 0 )) < 0 ) {
-       LOG(log_error, logtype_papd, "lp_conn_unix socket: %s", strerror(errno) );
-       return( -1 );
-    }
-    memset( &saun, 0, sizeof( struct sockaddr_un ));
-    saun.sun_family = AF_UNIX;
-    strcpy( saun.sun_path, _PATH_DEVPRINTER );
-    if ( connect( s, (struct sockaddr *)&saun,
-           strlen( saun.sun_path ) + 2 ) < 0 ) {
-       LOG(log_error, logtype_papd, "lp_conn_unix connect %s: %s", saun.sun_path, strerror(errno) );
-       close( s );
-       return( -1 );
-    }
-
-    return( s );
-}
-
-int lp_disconn_inet( int fd )
-{
-    return( close( fd ));
-}
-
-int lp_conn_inet(void)
-{
-    int                        privfd, port = IPPORT_RESERVED - 1;
-    struct sockaddr_in sin;
-    struct servent     *sp;
-    struct hostent     *hp;
-
-    if (( sp = getservbyname( "printer", "tcp" )) == NULL ) {
-       LOG(log_error, logtype_papd, "printer/tcp: unknown service" );
-       return( -1 );
-    }
-
-    if ( gethostname( hostname, sizeof( hostname )) < 0 ) {
-       LOG(log_error, logtype_papd, "gethostname: %s", strerror(errno) );
-       exit( 1 );
-    }
-
-    if (( hp = gethostbyname( hostname )) == NULL ) {
-       LOG(log_error, logtype_papd, "%s: unknown host", hostname );
-       return( -1 );
-    }
-
-    if (( privfd = rresvport( &port )) < 0 ) {
-       LOG(log_error, logtype_papd, "lp_connect: socket: %s", strerror(errno) );
-       close( privfd );
-       return( -1 );
-    }
-
-    memset( &sin, 0, sizeof( struct sockaddr_in ));
-    sin.sin_family = AF_INET;
-/*    sin.sin_addr.s_addr = htonl( INADDR_LOOPBACK ); */
-    memcpy( &sin.sin_addr, hp->h_addr, hp->h_length );
-    sin.sin_port = sp->s_port;
-
-    if ( connect( privfd, (struct sockaddr *)&sin,
-           sizeof( struct sockaddr_in )) < 0 ) {
-       LOG(log_error, logtype_papd, "lp_connect: %s", strerror(errno) );
-       close( privfd );
-       return( -1 );
-    }
-
-    return( privfd );
-}
-
-int lp_rmjob( int job)
-{
-    char       buf[ 1024 ];
-    int                n, s;
-
-    if (( s = lp_conn_inet()) < 0 ) {
-       LOG(log_error, logtype_papd, "lp_rmjob: %s", strerror(errno) );
-       return( -1 );
-    }
-
-    if ( lp.lp_person == NULL ) {
-       return( -1 );
-    }
-
-    sprintf( buf, "\5%s %s %d\n", printer->p_printer, lp.lp_person, job );
-    n = strlen( buf );
-    if ( write( s, buf, n ) != n ) {
-       LOG(log_error, logtype_papd, "lp_rmjob write: %s", strerror(errno) );
-       lp_disconn_inet( s );
-       return( -1 );
-    }
-    while (( n = read( s, buf, sizeof( buf ))) > 0 ) {
-       LOG(log_debug, logtype_papd, "read %.*s", n, buf );
-    }
-
-    lp_disconn_inet( s );
-    return( 0 );
-}
-
-char   *kw_rank = "Rank";
-char   *kw_active = "active";
-
-char   *tag_rank = "rank: ";
-char   *tag_owner = "owner: ";
-char   *tag_job = "job: ";
-char   *tag_files = "files: ";
-char   *tag_size = "size: ";
-char   *tag_status = "status: ";
-
-int lp_queue( struct papfile *out)
-{
-    char                       buf[ 1024 ], *start, *stop, *p, *q;
-    int                                linelength, crlflength;
-    static struct papfile      pf;
-    int                                s;
-    size_t                     len;
-    ssize_t                    n;
-       
-    if (( s = lp_conn_unix()) < 0 ) {
-       LOG(log_error, logtype_papd, "lp_queue: %s", strerror(errno) );
-       return( -1 );
-    }
-
-    sprintf( buf, "\3%s\n", printer->p_printer );
-    n = strlen( buf );
-    if ( write( s, buf, n ) != n ) {
-       LOG(log_error, logtype_papd, "lp_queue write: %s", strerror(errno) );
-       lp_disconn_unix( s );
-       return( -1 );
-    }
-    pf.pf_state = PF_BOT;
-
-    while (( n = read( s, buf, sizeof( buf ))) > 0 ) {
-       append( &pf, buf, n );
-    }
-
-    for (;;) {
-       if ( markline( &pf, &start, &linelength, &crlflength ) > 0 ) {
-           /* parse */
-           stop = start + linelength;
-           for ( p = start; p < stop; p++ ) {
-               if ( *p == ' ' || *p == '\t' ) {
-                   break;
-               }
-           }
-           if ( p >= stop ) {
-               CONSUME( &pf , linelength + crlflength);
-               continue;
-           }
-
-           /*
-            * Keys: "Rank", a number, "active"
-            * Anything else is status.
-            */
-           len = p - start;
-           if ( len == strlen( kw_rank ) &&
-                   strncmp( kw_rank, start, len ) == 0 ) {
-               CONSUME( &pf, linelength + crlflength );
-               continue;
-           }
-           if (( len == strlen( kw_active ) &&
-                   strncmp( kw_active, start, len ) == 0 ) ||
-                   isdigit( *start )) {                /* a job line */
-               append( out, tag_rank, strlen( tag_rank ));
-               append( out, start, p - start );
-               append( out, "\n", 1 );
-
-               for ( ; p < stop; p++ ) {
-                   if ( *p != ' ' && *p != '\t' ) {
-                       break;
-                   }
-               }
-               for ( q = p; p < stop; p++ ) {
-                   if ( *p == ' ' || *p == '\t' ) {
-                       break;
-                   }
-               }
-               if ( p >= stop ) {
-                   append( out, ".\n", 2 );
-                   CONSUME( &pf, linelength + crlflength );
-                   continue;
-               }
-               append( out, tag_owner, strlen( tag_owner ));
-               append( out, q, p - q );
-               append( out, "\n", 1 );
-
-               for ( ; p < stop; p++ ) {
-                   if ( *p != ' ' && *p != '\t' ) {
-                       break;
-                   }
-               }
-               for ( q = p; p < stop; p++ ) {
-                   if ( *p == ' ' || *p == '\t' ) {
-                       break;
-                   }
-               }
-               if ( p >= stop ) {
-                   append( out, ".\n", 2 );
-                   CONSUME( &pf , linelength + crlflength );
-                   continue;
-               }
-               append( out, tag_job, strlen( tag_job ));
-               append( out, q, p - q );
-               append( out, "\n", 1 );
-
-               for ( ; p < stop; p++ ) {
-                   if ( *p != ' ' && *p != '\t' ) {
-                       break;
-                   }
-               }
-               for ( q = p, p = stop; p > q; p-- ) {
-                   if ( *p == ' ' || *p == '\t' ) {
-                       break;
-                   }
-               }
-               for ( ; p > q; p-- ) {
-                   if ( *p != ' ' && *p != '\t' ) {
-                       break;
-                   }
-               }
-               for ( ; p > q; p-- ) {
-                   if ( *p == ' ' || *p == '\t' ) {
-                       break;
-                   }
-               }
-               if ( p <= q ) {
-                   append( out, ".\n", 2 );
-                   CONSUME( &pf, linelength + crlflength );
-                   continue;
-               }
-               append( out, tag_files, strlen( tag_files ));
-               append( out, q, p - q );
-               append( out, "\n", 1 );
-
-               for ( ; p < stop; p++ ) {
-                   if ( *p != ' ' && *p != '\t' ) {
-                       break;
-                   }
-               }
-               append( out, tag_size, strlen( tag_size ));
-               append( out, p, stop - p );
-               append( out, "\n.\n", 3 );
-
-               CONSUME( &pf, linelength + crlflength );
-               continue;
-           }
-
-           /* status */
-           append( out, tag_status, strlen( tag_status ));
-           append( out, start, linelength );
-           append( out, "\n.\n", 3 );
-
-           CONSUME( &pf, linelength + crlflength );
-       } else {
-           append( out, "*\n", 2 );
-           lp_disconn_unix( s );
-           return( 0 );
-       }
-    }
-}
-#endif /* HAVE_CUPS */
diff --git a/etc/papd/lp.h b/etc/papd/lp.h
deleted file mode 100644 (file)
index 6a3dd68..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * $Id: lp.h,v 1.6 2009-10-13 22:55:37 didg Exp $
- */
-
-#ifndef PAPD_LP_H
-#define PAPD_LP_H 1
-
-#include <sys/socket.h>
-#include <sys/cdefs.h>
-#include "file.h"
-
-void lp_person ( char * );
-int lp_pagecost ( void );
-void lp_host ( char * );
-void lp_job ( char * );
-void lp_for ( char * );
-void lp_origin ( int );
-int lp_rmjob ( int );
-int lp_queue ( struct papfile * );
-
-/* cancel current job */
-int lp_cancel ( void );
-/* print current job */
-int lp_print ( void );
-/* open a file for spooling */
-int lp_open ( struct papfile *, struct sockaddr_at * );
-/* open a buffer to the current open file */
-int lp_write ( struct papfile *,char *, size_t );
-/* close current spooling file */
-int lp_close ( void );
-
-#endif /* PAPD_LP_H */
diff --git a/etc/papd/magics.c b/etc/papd/magics.c
deleted file mode 100644 (file)
index 5e128e5..0000000
+++ /dev/null
@@ -1,231 +0,0 @@
-/*
- * $Id: magics.c,v 1.15 2009-10-13 22:55:37 didg Exp $
- *
- * Copyright (c) 1990,1994 Regents of The University of Michigan.
- * All Rights Reserved.  See COPYRIGHT.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <atalk/logger.h>
-#include <sys/param.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-
-#include <netatalk/at.h>
-
-#include "file.h"
-#include "comment.h"
-#include "lp.h"
-
-static int state=0;
-
-static void parser_error(struct papfile *outfile)
-{
-                spoolerror( outfile, "Comments error, Ignoring job." );
-               outfile->pf_state |= PF_EOF;
-               lp_close();
-}
-
-int ps( struct papfile *infile, struct papfile *outfile, struct sockaddr_at *sat)
-{
-    char                       *start;
-    int                                linelength, crlflength;
-    struct papd_comment                *comment;
-
-    for (;;) {
-        if ( infile->pf_state & PF_STW ) {
-               infile->pf_state &= ~PF_STW;
-               /* set up spool file */
-               if ( lp_open( outfile, sat ) < 0 && !state) {
-                   LOG(log_error, logtype_papd, "lp_open failed" );
-                   spoolerror( outfile, "Ignoring job." );
-               }
-               state = 1;
-       }       
-       if ( (comment = compeek()) ) {
-           switch( (*comment->c_handler)( infile, outfile, sat )) {
-           case CH_DONE :
-               continue;
-
-           case CH_MORE :
-               return( CH_MORE );
-
-           case CH_ERROR :
-               parser_error(outfile);
-               return( 0 );
-
-           default :
-               return( CH_ERROR );
-           }
-       } else {
-           switch ( markline( infile, &start, &linelength, &crlflength )) {
-           case 0 :
-               /* eof on infile */
-               outfile->pf_state |= PF_EOF;
-               lp_close();
-               return( 0 );
-
-           case -2:
-               parser_error(outfile);
-               return( 0 );
-
-           case -1 :
-               return( 0 );
-           }
-
-           if ( infile->pf_state & PF_BOT ) {
-               if (( comment = commatch( start, start+linelength, magics )) != NULL ) {
-                   compush( comment );
-                   continue;   /* top of for (;;) */
-               }
-#if 0
-               infile->pf_state &= ~PF_BOT;
-
-               /* set up spool file */
-               if ( lp_open( outfile, sat ) < 0 ) {
-                   LOG(log_error, logtype_papd, "lp_open failed" );
-                   spoolerror( outfile, "Ignoring job." );
-               }
-#endif
-           }
-
-           /* write to file */
-           lp_write( infile, start, linelength + crlflength );
-           CONSUME( infile, linelength + crlflength );
-       }
-    }
-}
-
-int cm_psquery( struct papfile *in, struct papfile *out, struct sockaddr_at *sat _U_)
-{
-    struct papd_comment        *comment;
-    char               *start;
-    int                        linelength, crlflength;
-
-    for (;;) {
-       switch ( markline( in, &start, &linelength, &crlflength )) {
-       case 0 :
-           /* eof on infile */
-           out->pf_state |= PF_EOF;
-           compop();
-           return( CH_DONE );
-
-       case -1 :
-           return( CH_MORE );
-
-        case -2 :
-            return( CH_ERROR );
-       }
-
-       if ( in->pf_state & PF_BOT ) {
-           in->pf_state &= ~PF_BOT;
-       } else {
-           if (( comment = commatch( start, start+linelength, queries )) != NULL ) {
-               compush( comment );
-               return( CH_DONE );
-           }
-       }
-
-       CONSUME( in, linelength + crlflength );
-    }
-}
-
-int cm_psadobe( struct papfile *in, struct papfile *out, struct sockaddr_at *sat _U_)
-{
-    char               *start;
-    int                        linelength, crlflength;
-    struct papd_comment        *comment = compeek();
-
-    for (;;) {
-       switch ( markline( in, &start, &linelength, &crlflength )) {
-       case 0 :
-           /* eof on infile */
-           out->pf_state |= PF_EOF;
-           compop();
-           return( CH_DONE );
-
-       case -1 :
-           return( CH_MORE );
-
-        case -2 :
-            return( CH_ERROR );
-       }
-       if ( in->pf_state & PF_BOT ) {
-           in->pf_state &= ~PF_BOT;
-#if 0
-           if ( lp_open( out, sat ) < 0 ) {
-               LOG(log_error, logtype_papd, "lp_open failed" );
-               spoolerror( out, "Ignoring job." );
-           }
-#endif
-       } else {
-           if (( comment = commatch( start, start + linelength, headers )) != NULL ) {
-               compush( comment );
-               return( CH_DONE );
-           }
-       }
-
-       lp_write( in, start, linelength + crlflength );
-       CONSUME( in, linelength + crlflength );
-    }
-}
-
-char   *Query = "Query";
-
-int cm_psswitch(struct papfile *in, struct papfile *out, struct sockaddr_at *sat _U_)
-{
-    char               *start, *stop, *p;
-    int                        linelength, crlflength;
-
-    switch ( markline( in, &start, &linelength, &crlflength )) {
-    case 0 :
-       /* eof on infile */
-       out->pf_state |= PF_EOF;
-       compop();
-       return( 0 );
-
-    case -1 :
-       return( CH_MORE );
-
-    case -2 :
-        return( CH_ERROR );
-    }
-
-    stop = start + linelength;
-    for ( p = start; p < stop; p++ ) {
-       if ( *p == ' ' || *p == '\t' ) {
-           break;
-       }
-    }
-    for ( ; p < stop; p++ ) {
-       if ( *p != ' ' && *p != '\t' ) {
-           break;
-       }
-    }
-
-    if ( (size_t)(stop - p) >= strlen( Query ) &&
-           strncmp( p, Query, strlen( Query )) == 0 ) {
-       if ( comswitch( magics, cm_psquery ) < 0 ) {
-           LOG(log_error, logtype_papd, "cm_psswitch: can't find psquery!" );
-           exit( 1 );
-       }
-    } else {
-       if ( comswitch( magics, cm_psadobe ) < 0 ) {
-           LOG(log_error, logtype_papd, "cm_psswitch: can't find psadobe!" );
-           exit( 1 );
-       }
-    }
-    return( CH_DONE );
-}
-
-
-struct papd_comment    magics[] = {
-    { "%!PS-Adobe-3.0 Query",  NULL,                   cm_psquery, C_FULL },
-    { "%!PS-Adobe-3.0",                NULL,                   cm_psadobe, C_FULL },
-    { "%!PS-Adobe-",           NULL,                   cm_psswitch,    0 },
-    { NULL,                    NULL,                   NULL,           0 },
-};
diff --git a/etc/papd/main.c b/etc/papd/main.c
deleted file mode 100644 (file)
index d0c4645..0000000
+++ /dev/null
@@ -1,950 +0,0 @@
-/*
- * $Id: main.c,v 1.31 2009-10-29 13:38:15 didg Exp $
- *
- * Copyright (c) 1990,1995 Regents of The University of Michigan.
- * All Rights Reserved.  See COPYRIGHT.
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif /* HAVE_CONFIG_H */
-
-#include <string.h>
-
-#include <sys/param.h>
-#include <sys/time.h>
-#include <sys/uio.h>
-#include <sys/file.h>
-#include <sys/socket.h>
-#include <atalk/logger.h>
-
-/* POSIX.1 sys/wait.h check */
-#include <sys/types.h>
-#ifdef HAVE_SYS_WAIT_H
-#include <sys/wait.h>
-#endif /* HAVE_SYS_WAIT_H */
-#ifndef WEXITSTATUS
-#define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
-#endif /* ! WEXITSTATUS */
-#ifndef WIFEXITED
-#define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
-#endif /* ! WIFEXITED */
-
-#include <errno.h>
-
-/* STDC check */
-#if STDC_HEADERS
-#include <string.h>
-#else /* STDC_HEADERS */
-#ifndef HAVE_STRCHR
-#define strchr index
-#define strrchr index
-#endif /* HAVE_STRCHR */
-char *strchr (), *strrchr ();
-#ifndef HAVE_MEMCPY
-#define memcpy(d,s,n) bcopy ((s), (d), (n))
-#define memmove(d,s,n) bcopy ((s), (d), (n))
-#endif /* ! HAVE_MEMCPY */
-#endif /* STDC_HEADERS */
-
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <netdb.h>
-#include <fcntl.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
-
-#include <netatalk/endian.h>
-#include <netatalk/at.h>
-#include <atalk/compat.h>
-#include <atalk/atp.h>
-#include <atalk/pap.h>
-#include <atalk/paths.h>
-#include <atalk/util.h>
-#include <atalk/nbp.h>
-#include <atalk/unicode.h>
-
-#include "printer.h"
-#include "printcap.h"
-#include "session.h"
-#include "uam_auth.h"
-#include "print_cups.h"
-
-
-#define PIPED_STATUS   "status: print spooler processing job"
-
-struct printer defprinter;
-struct printer *printers = NULL;
-
-int            debug = 0;
-static char    *conffile = _PATH_PAPDCONF;
-char           *printcap = _PATH_PAPDPRINTCAP;
-unsigned char  connid, quantum, sock, oquantum = PAP_MAXQUANTUM;
-char           *cannedstatus = PIPED_STATUS;
-struct printer *printer = NULL;
-char           *version = VERSION;
-static char    *pidfile = _PATH_PAPDLOCK;
-
-char           *uamlist;
-char           *uampath = _PATH_PAPDUAMPATH;
-
-/* Prototypes for locally used functions */
-int getstatus( struct printer *pr, char *buf );
-int rprintcap( struct printer *pr );
-static void getprinters( char *cf );
-
-
-/* this only needs to be used by the server process */
-static void papd_exit(const int i)
-{
-  server_unlock(pidfile);
-  auth_unload();
-  exit(i);
-}
-
-static void
-die(int n)
-{
-    struct printer     *pr;
-    struct at_addr     addr;
-
-    memset(&addr, 0, sizeof(addr));
-
-    for ( pr = printers; pr; pr = pr->p_next ) {
-       if ( pr->p_flags & P_REGISTERED ) {
-           if ( nbp_unrgstr( pr->p_name, pr->p_type, pr->p_zone, &addr ) < 0 ) {
-               LOG(log_error, logtype_papd, "can't unregister %s:%s@%s", pr->p_name,
-                       pr->p_type, pr->p_zone );
-               papd_exit( n + 1 );
-           }
-           LOG(log_info, logtype_papd, "unregister %s:%s@%s", pr->p_name, pr->p_type,
-                   pr->p_zone );
-       }
-#ifdef HAVE_CUPS
-       if ( pr->p_flags & P_SPOOLED && pr->p_flags & P_CUPS_PPD ) {
-               LOG(log_info, logtype_papd, "Deleting CUPS temp PPD file for %s (%s)", pr->p_name, pr->p_ppdfile);
-               unlink (pr->p_ppdfile);
-       }
-#endif /* HAVE_CUPS */
-
-    }
-    papd_exit( n );
-}
-
-static void
-reap(int sig _U_)
-{
-    int                status;
-    int                pid;
-
-    while (( pid = wait3( &status, WNOHANG, NULL )) > 0 ) {
-       if ( WIFEXITED( status )) {
-           if ( WEXITSTATUS( status )) {
-               LOG(log_error, logtype_papd, "child %d exited with %d", pid,
-                       WEXITSTATUS( status ));
-           } else {
-               LOG(log_info, logtype_papd, "child %d done", pid );
-           }
-       } else {
-           if ( WIFSIGNALED( status )) {
-               LOG(log_error, logtype_papd, "child %d killed with %d", pid,
-                       WTERMSIG( status ));
-           } else {
-               LOG(log_error, logtype_papd, "child %d died", pid );
-           }
-       }
-    }
-    return;
-}
-
-static char rbuf[ 255 + 1 + 8 ];
-
-int main(int ac, char **av)
-{
-    extern char         *optarg;
-
-    ATP                        atp;
-    struct atp_block   atpb;
-    struct sockaddr_at sat;
-    struct sigaction   sv;
-    struct iovec       iov;
-    fd_set             fdset;
-    struct printer     *pr;
-    char               *p, hostname[ MAXHOSTNAMELEN ];
-    char               cbuf[ 8 ];
-    int                        c;
-    char               *atname;
-
-    if ( gethostname( hostname, sizeof( hostname )) < 0 ) {
-       perror( "gethostname" );
-       exit( 1 );
-    }
-    if (( p = strchr( hostname, '.' )) != NULL ) {
-       *p = '\0';
-    }
-    if (( defprinter.p_name = (char *)malloc( strlen( hostname ) + 1 ))
-           == NULL ) {
-       perror( "malloc" );
-       exit( 1 );
-    }
-    strcpy( defprinter.p_name, hostname );
-    defprinter.p_type = "LaserWriter";
-    defprinter.p_zone = "*";
-    memset(&defprinter.p_addr, 0, sizeof(defprinter.p_addr));
-#ifdef __svr4__
-    defprinter.p_flags = P_PIPED;
-    defprinter.p_printer = "/usr/bin/lp -T PS";
-#else /* __svr4__ */
-    defprinter.p_flags = P_SPOOLED;
-    defprinter.p_printer = "lp";
-#endif /* __svr4__ */
-    defprinter.p_operator = "operator";
-    defprinter.p_spool = _PATH_PAPDSPOOLDIR;
-#ifdef ABS_PRINT
-    defprinter.p_role = NULL;
-    defprinter.p_srvid = 0;
-#endif /* ABS_PRINT */
-    defprinter.p_pagecost = 200;               /* default cost */
-    defprinter.p_pagecost_msg = NULL;
-    defprinter.p_lock = "lock";
-
-    while (( c = getopt( ac, av, "adf:p:P:v" )) != EOF ) {
-       switch ( c ) {
-       case 'a' :              /* for compatibility with old papd */
-           break;
-
-       case 'd' :              /* debug */
-           debug++;
-           break;
-
-       case 'f' :              /* conffile */
-           conffile = optarg;
-           break;
-
-       case 'p' :              /* printcap */
-           printcap = optarg;
-           break;
-
-       case 'P' :
-           pidfile = optarg;
-           break;
-
-       case 'v' :              /* version */
-           printf( "papd (version %s)\n", VERSION );
-           exit ( 1 );
-           break;
-
-       default :
-           fprintf( stderr,
-                   "Usage:\t%s [ -d ] [ -f conffile ] [ -p printcap ]\n",
-                   *av );
-           exit( 1 );
-       }
-    }
-
-
-    switch (server_lock("papd", pidfile, debug)) {
-    case 0: /* open a couple things again in the child */
-      if (!debug && (c = open("/", O_RDONLY)) >= 0) {
-       dup2(c, 1);
-       dup2(c, 2);
-      }
-      break;
-    case -1:
-      exit(1);
-    default:
-      exit(0);
-    }      
-
-#ifdef DEBUG1
-    fault_setup(NULL);
-#endif
-
-    /*
-     * Start logging.
-     */
-    if (( p = strrchr( av[ 0 ], '/' )) == NULL ) {
-       p = av[ 0 ];
-    } else {
-       p++;
-    }
-#ifdef ultrix
-    openlog( p, LOG_PID );
-#else /* ultrix */
-    set_processname(p);
-    syslog_setup(log_debug, logtype_default, logoption_ndelay | logoption_pid |
-               debug ? logoption_perror : 0, logfacility_lpr );
-#endif /* ultrix */
-
-    LOG(log_info, logtype_papd, "restart (%s)", version );
-#ifdef HAVE_CUPS
-    LOG(log_info, logtype_papd, "CUPS support enabled (%s)", CUPS_API_VERSION );
-#endif
-
-    getprinters( conffile );
-
-    for ( pr = printers; pr; pr = pr->p_next ) {
-       if (( pr->p_flags & P_SPOOLED ) && rprintcap( pr ) < 0 ) {
-           LOG(log_error, logtype_papd, "printcap problem: %s", pr->p_printer );
-       }
-
-       if (!(pr->p_flags & P_CUPS)) {
-               if ((size_t)-1 != convert_string_allocate(CH_UNIX, CH_MAC, pr->p_name, -1, &atname)) {
-                       pr->p_u_name = pr->p_name;
-                       pr->p_name = atname;
-               }
-       }
-                       
-       if (( pr->p_atp = atp_open( ATADDR_ANYPORT, &pr->p_addr )) == NULL ) {
-           LOG(log_error, logtype_papd, "atp_open: %s", strerror(errno) );
-           papd_exit( 1 );
-       }
-       if ( nbp_rgstr( atp_sockaddr( pr->p_atp ), pr->p_name, pr->p_type,
-               pr->p_zone ) < 0 ) {
-           LOG(log_error, logtype_papd, "can't register %s:%s@%s", pr->p_u_name, pr->p_type,
-                   pr->p_zone );
-           die( 1 );
-       }
-       if ( pr->p_flags & P_AUTH ) {
-               LOG(log_info, logtype_papd, "Authentication enabled: %s", pr->p_u_name );
-       }
-       else {
-               LOG(log_info, logtype_papd, "Authentication disabled: %s", pr->p_u_name );
-       }
-       LOG(log_info, logtype_papd, "register %s:%s@%s", pr->p_u_name, pr->p_type,
-               pr->p_zone );
-       pr->p_flags |= P_REGISTERED;
-    }
-
-    memset(&sv, 0, sizeof(sv));
-    sv.sa_handler = die;
-    sigemptyset( &sv.sa_mask );
-    sv.sa_flags = SA_RESTART;
-    if ( sigaction( SIGTERM, &sv, NULL ) < 0 ) {
-       LOG(log_error, logtype_papd, "sigaction: %s", strerror(errno) );
-       papd_exit( 1 );
-    }
-
-    sv.sa_handler = reap;
-    sigemptyset( &sv.sa_mask );
-    sv.sa_flags = SA_RESTART;
-    if ( sigaction( SIGCHLD, &sv, NULL ) < 0 ) {
-       LOG(log_error, logtype_papd, "sigaction: %s", strerror(errno) );
-       papd_exit( 1 );
-    }
-
-    /*
-     * Load UAMS
-     */
-    auth_load(uampath, uamlist);
-
-    /*
-     * Begin accepting connections.
-     */
-    FD_ZERO( &fdset );
-    for (;;) {
-       for ( pr = printers; pr; pr = pr->p_next ) {
-           FD_SET( atp_fileno( pr->p_atp ), &fdset );
-       }
-       if (( c = select( FD_SETSIZE, &fdset, NULL, NULL, NULL )) < 0 ) {
-           if ( errno == EINTR ) {
-               continue;
-           }
-           LOG(log_error, logtype_papd, "select: %s", strerror(errno) );
-           papd_exit( 1 );
-       }
-
-       for ( pr = printers; pr; pr = pr->p_next ) {
-           if ( FD_ISSET( atp_fileno( pr->p_atp ), &fdset )) {
-               int             err = 0;
-
-               memset( &sat, 0, sizeof( struct sockaddr_at ));
-#ifdef BSD4_4
-               sat.sat_len = sizeof( struct sockaddr_at );
-#endif /* BSD4_4 */
-               sat.sat_family = AF_APPLETALK;
-               sat.sat_addr.s_net = ATADDR_ANYNET;
-               sat.sat_addr.s_node = ATADDR_ANYNODE;
-               sat.sat_port = ATADDR_ANYPORT;
-               /* do an atp_rsel(), to prevent hangs */
-               if (( c = atp_rsel( pr->p_atp, &sat, ATP_TREQ )) != ATP_TREQ ) {
-                   continue;
-               }
-               atpb.atp_saddr = &sat;
-               atpb.atp_rreqdata = cbuf;
-               atpb.atp_rreqdlen = sizeof( cbuf );
-               if ( atp_rreq( pr->p_atp, &atpb ) < 0 ) {
-                   LOG(log_error, logtype_papd, "atp_rreq: %s", strerror(errno) );
-                   continue;
-               }
-
-               /* should check length of req buf */
-
-               switch( cbuf[ 1 ] ) {
-               case PAP_OPEN :
-                   connid = (unsigned char)cbuf[ 0 ];
-                   sock = (unsigned char)cbuf[ 4 ];
-                   quantum = (unsigned char)cbuf[ 5 ];
-                   rbuf[ 0 ] = cbuf[ 0 ];
-                   rbuf[ 1 ] = PAP_OPENREPLY;
-                   rbuf[ 2 ] = rbuf[ 3 ] = 0;
-
-                   if (( pr->p_flags & P_SPOOLED ) && rprintcap( pr ) != 0 ) {
-                       LOG(log_error, logtype_papd, "printcap problem: %s",
-                               pr->p_printer );
-                       rbuf[ 2 ] = rbuf[ 3 ] = 0xff;
-                       err = 1;
-                   }
-
-#ifdef HAVE_CUPS
-                  /*
-                   * If cups is not accepting jobs, we return
-                   * 0xffff to indicate we're busy
-                   */
-#ifdef DEBUG
-                    LOG(log_debug9, logtype_papd, "CUPS: PAP_OPEN");
-#endif
-                   if ( (pr->p_flags & P_SPOOLED) && (cups_get_printer_status ( pr ) == 0)) {
-                        LOG(log_error, logtype_papd, "CUPS_PAP_OPEN: %s is not accepting jobs",
-                                pr->p_printer );
-                        rbuf[ 2 ] = rbuf[ 3 ] = 0xff;
-                        err = 1;
-                    }
-#endif /* HAVE_CUPS */
-
-                   /*
-                    * If this fails, we've run out of sockets. Rather than
-                    * just die(), let's try to continue. Maybe some sockets
-                    * will close, and we can continue;
-                    */
-                   if (( atp = atp_open( ATADDR_ANYPORT, 
-                                         &pr->p_addr)) == NULL ) {
-                       LOG(log_error, logtype_papd, "atp_open: %s", strerror(errno) );
-                       rbuf[ 2 ] = rbuf[ 3 ] = 0xff;  /* printer busy */
-                       rbuf[ 4 ] = 0; /* FIXME is it right? */
-                       err = 1;
-                   }
-                   else {
-                      rbuf[ 4 ] = atp_sockaddr( atp )->sat_port;
-                    }
-                   rbuf[ 5 ] = oquantum;
-                   rbuf[ 6 ] = rbuf[ 7 ] = 0;
-
-                   iov.iov_base = rbuf;
-                   iov.iov_len = 8 + getstatus( pr, &rbuf[ 8 ] );
-                   atpb.atp_sresiov = &iov;
-                   atpb.atp_sresiovcnt = 1;
-                   /*
-                    * This may error out if we lose a route, so we won't die().
-                    */
-                   if ( atp_sresp( pr->p_atp, &atpb ) < 0 ) {
-                       LOG(log_error, logtype_papd, "atp_sresp: %s", strerror(errno) );
-                       err = 1;
-                   }
-
-                   if ( err ) {
-                       if (atp) {
-                          atp_close(atp);
-                        }
-                       continue;
-                   }
-
-                   switch ( c = fork()) {
-                   case -1 :
-                       LOG(log_error, logtype_papd, "fork: %s", strerror(errno) );
-                        atp_close(atp);
-                       continue;
-
-                   case 0 : /* child */
-                       printer = pr;
-
-                       #ifndef HAVE_CUPS
-                       if (( printer->p_flags & P_SPOOLED ) &&
-                               chdir( printer->p_spool ) < 0 ) {
-                           LOG(log_error, logtype_papd, "chdir %s: %s", printer->p_spool, strerror(errno) );
-                           exit( 1 );
-                       }
-                       #else
-                       if (( printer->p_flags & P_SPOOLED ) &&
-                               chdir( SPOOLDIR ) < 0 ) {
-                           LOG(log_error, logtype_papd, "chdir %s: %s", SPOOLDIR, strerror(errno) );
-                           exit( 1 );
-                       }
-
-                       #endif
-
-                       sv.sa_handler = SIG_DFL;
-                       sigemptyset( &sv.sa_mask );
-                       sv.sa_flags = SA_RESTART;
-                       if ( sigaction( SIGTERM, &sv, NULL ) < 0 ) {
-                           LOG(log_error, logtype_papd, "sigaction: %s", strerror(errno) );
-                           exit( 1 );
-                       }
-                       
-                       if ( sigaction( SIGCHLD, &sv, NULL ) < 0 ) {
-                           LOG(log_error, logtype_papd, "sigaction: %s", strerror(errno) );
-                           exit( 1 );
-                        }
-
-                       for ( pr = printers; pr; pr = pr->p_next ) {
-                           atp_close( pr->p_atp );
-                       }
-                       sat.sat_port = sock;
-                       if ( session( atp, &sat ) < 0 ) {
-                           LOG(log_error, logtype_papd, "bad session" );
-                           exit( 1 );
-                       }
-                       exit( 0 );
-                       break;
-
-                   default : /* parent */
-                       LOG(log_info, logtype_papd, "child %d for \"%s\" from %u.%u",
-                               c, pr->p_name, ntohs( sat.sat_addr.s_net ),
-                               sat.sat_addr.s_node);
-                       atp_close( atp );
-                   }
-                   break;
-
-               case PAP_SENDSTATUS :
-                   rbuf[ 0 ] = 0;
-                   rbuf[ 1 ] = PAP_STATUS;
-                   rbuf[ 2 ] = rbuf[ 3 ] = 0;
-                   rbuf[ 4 ] = rbuf[ 5 ] = 0;
-                   rbuf[ 6 ] = rbuf[ 7 ] = 0;
-
-                   iov.iov_base = rbuf;
-                   iov.iov_len = 8 + getstatus( pr, &rbuf[ 8 ] );
-                   atpb.atp_sresiov = &iov;
-                   atpb.atp_sresiovcnt = 1;
-                   /*
-                    * This may error out if we lose a route, so we won't die().
-                    */
-                   if ( atp_sresp( pr->p_atp, &atpb ) < 0 ) {
-                       LOG(log_error, logtype_papd, "atp_sresp: %s", strerror(errno) );
-                   }
-                   break;
-
-               default :
-                   LOG(log_error, logtype_papd, "Bad request from %u.%u!",
-                           ntohs( sat.sat_addr.s_net ), sat.sat_addr.s_node );
-                   continue;
-                   break;
-               }
-
-#ifdef notdef
-               /*
-                * Sometimes the child process will send its first READ
-                * before the parent has sent the OPEN REPLY.  Moving this
-                * code into the OPEN/STATUS switch fixes this problem.
-                */
-               iov.iov_base = rbuf;
-               iov.iov_len = 8 + getstatus( pr, &rbuf[ 8 ] );
-               atpb.atp_sresiov = &iov;
-               atpb.atp_sresiovcnt = 1;
-               /*
-                * This may error out if we lose a route, so we won't die().
-                */
-               if ( atp_sresp( pr->p_atp, &atpb ) < 0 ) {
-                   LOG(log_error, logtype_papd, "atp_sresp: %s", strerror(errno) );
-               }
-#endif /* notdef */
-           }
-       }
-    }
-    return 0;
-}
-
-/*
- * We assume buf is big enough for 255 bytes of data and a length byte.
- */
-
-int getstatus(struct printer *pr, char *buf)
-{
-
-#ifdef HAVE_CUPS
-    if ( pr->p_flags & P_PIPED ) {
-       *buf = strlen( cannedstatus );
-       strncpy( &buf[ 1 ], cannedstatus, *buf );
-       return( *buf + 1 );
-    } else {
-       cups_get_printer_status( pr );
-       *buf = strlen ( pr->p_status );
-       strncpy ( &buf[1], pr->p_status, *buf);
-       return ( *buf + 1);
-    }
-#else
-
-    char               path[ MAXPATHLEN ];
-    int                        fd = -1, rc;
-
-    if ( pr->p_flags & P_SPOOLED && ( pr->p_spool != NULL )) {
-       strcpy( path, pr->p_spool );
-       strcat( path, "/status" );
-       fd = open( path, O_RDONLY);
-    }
-
-    if (( pr->p_flags & P_PIPED ) || ( fd < 0 )) {
-       *buf = strlen( cannedstatus );
-       strncpy( &buf[ 1 ], cannedstatus, *buf );
-       return( *buf + 1 );
-    } else {
-       if (( rc = read( fd, &buf[ 1 ], 255 )) < 0 ) {
-           rc = 0;
-       }
-       close( fd );
-       if ( rc && buf[ rc ] == '\n' ) {        /* remove trailing newline */
-           rc--;
-       }
-       *buf = rc;
-       return( rc + 1 );
-    }
-#endif /* HAVE_CUPS */
-}
-
-char   *pgetstr(char *id, char **area);
-char   *getpname(char **area, int bufsize);
-
-#define PF_CONFBUFFER  1024
-
-static void getprinters( char *cf)
-{
-    char               buf[ PF_CONFBUFFER ], area[ PF_CONFBUFFER ], *a, *p, *name, *type, *zone;
-    struct printer     *pr;
-    int                        c;
-
-    while (( c = getprent( cf, buf, PF_CONFBUFFER )) > 0 ) {
-       a = area;
-       /*
-        * Get the printer's nbp name.
-        */
-       if (( p = getpname( &a, PF_CONFBUFFER )) == NULL ) {
-           fprintf( stderr, "No printer name\n" );
-           exit( 1 );
-       }
-
-       if (( pr = (struct printer *)malloc( sizeof( struct printer )))
-               == NULL ) {
-           perror( "malloc" );
-           exit( 1 );
-       }
-       memset( pr, 0, sizeof( struct printer ));
-
-       name = defprinter.p_name;
-       type = defprinter.p_type;
-       zone = defprinter.p_zone;
-       if ( nbp_name( p, &name, &type, &zone )) {
-           fprintf( stderr, "Can't parse \"%s\"\n", name );
-           exit( 1 );
-       }
-       if ( name != defprinter.p_name ) {
-           if (( pr->p_name = (char *)malloc( strlen( name ) + 1 )) == NULL ) {
-               perror( "malloc" );
-               exit( 1 );
-           }
-           strcpy( pr->p_name, name );
-       } else {
-           pr->p_name = name;
-       }
-       if ( type != defprinter.p_type ) {
-           if (( pr->p_type = (char *)malloc( strlen( type ) + 1 )) == NULL ) {
-               perror( "malloc" );
-               exit( 1 );
-           }
-           strcpy( pr->p_type, type );
-       } else {
-           pr->p_type = type;
-       }
-       if ( zone != defprinter.p_zone ) {
-           if (( pr->p_zone = (char *)malloc( strlen( zone ) + 1 )) == NULL ) {
-               perror( "malloc" );
-               exit( 1 );
-           }
-           strcpy( pr->p_zone, zone );
-       } else {
-           pr->p_zone = zone;
-       }
-
-       if ( pnchktc( cf ) != 1 ) {
-           fprintf( stderr, "Bad papcap entry\n" );
-           exit( 1 );
-       }
-
-       /*
-        * Get PPD file.
-        */
-       if (( p = pgetstr( "pd", &a ) )) {
-           if (( pr->p_ppdfile = (char *)malloc( strlen( p ) + 1 )) == NULL ) {
-               perror( "malloc" );
-               exit( 1 );
-           }
-           strcpy( pr->p_ppdfile, p );
-       }
-
-       /*
-        * Get lpd printer name.
-        */
-       if (( p = pgetstr( "pr", &a )) == NULL ) {
-           pr->p_printer = defprinter.p_printer;
-           pr->p_flags = defprinter.p_flags;
-       } else {
-           if ( *p == '|' ) {
-               p++;
-               pr->p_flags = P_PIPED;
-           } else {
-               pr->p_flags = P_SPOOLED;
-           }
-           if (( pr->p_printer = (char *)malloc( strlen( p ) + 1 )) == NULL ) {
-               perror( "malloc" );
-               exit( 1 );
-           }
-           strcpy( pr->p_printer, p );
-       }
-
-       /*
-        * Do we want authenticated printing?
-        */
-       if ((p = pgetstr( "ca", &a )) != NULL ) {
-           if ((pr->p_authprintdir = (char *)malloc(strlen(p)+1)) == NULL) {
-               perror( "malloc" );
-               exit(1);
-           }
-           strcpy( pr->p_authprintdir, p );
-           pr->p_flags |= P_AUTH;
-           pr->p_flags |= P_AUTH_CAP;
-       } else { pr->p_authprintdir = NULL; }
-
-       if ( pgetflag( "sp" ) == 1 ) {
-           pr->p_flags |= P_AUTH;
-           pr->p_flags |= P_AUTH_PSSP;
-       }
-
-       if ((p = pgetstr("am", &a)) != NULL ) {
-               if ((uamlist = (char *)malloc(strlen(p)+1)) == NULL ) {
-                       perror("malloc");
-                       exit(1);
-               }
-               strcpy(uamlist, p);
-       }
-
-       if ( pr->p_flags & P_SPOOLED ) {
-           /*
-            * Get operator name.
-            */
-           if (( p = pgetstr( "op", &a )) == NULL ) {
-               pr->p_operator = defprinter.p_operator;
-           } else {
-               if (( pr->p_operator = (char *)malloc( strlen( p ) + 1 ))
-                       == NULL ) {
-                   perror( "malloc" );
-                   exit( 1 );
-               }
-               strcpy( pr->p_operator, p );
-           }
-       }
-
-       /* get printer's appletalk address. */
-       if (( p = pgetstr( "pa", &a )) == NULL ) 
-           memcpy(&pr->p_addr, &defprinter.p_addr, sizeof(pr->p_addr));
-       else 
-           atalk_aton(p, &pr->p_addr);
-
-#ifdef HAVE_CUPS
-       if ((p = pgetstr("co", &a)) != NULL ) {
-            pr->p_cupsoptions = strdup(p);
-            LOG (log_error, logtype_papd, "enabling cups-options for %s: %s", pr->p_name, pr->p_cupsoptions);
-       }
-#endif
-
-       /* convert line endings for setup sections.
-           real ugly work around for foomatic deficiencies,
-          need to get rid of this */
-       if ( pgetflag("fo") == 1 ) {
-            pr->p_flags |= P_FOOMATIC_HACK;
-            LOG (log_error, logtype_papd, "enabling foomatic hack for %s", pr->p_name);
-       }
-
-       if (strncasecmp (pr->p_name, "cupsautoadd", 11) == 0)
-       {
-#ifdef HAVE_CUPS
-               pr = cups_autoadd_printers (pr, printers);
-               printers = pr;
-#else
-               LOG (log_error, logtype_papd, "cupsautoadd: Cups support not compiled in");
-#endif /* HAVE_CUPS */
-       }
-       else {
-#ifdef HAVE_CUPS
-               if ( cups_check_printer ( pr, printers, 1) == 0)
-               {
-                       pr->p_next = printers;
-                       printers = pr;
-               }
-#else
-               pr->p_next = printers;
-               printers = pr;
-#endif /* HAVE_CUPS */
-       }
-    }
-    if ( c == 0 ) {
-       endprent();
-    } else {                   /* No capability file, do default */
-       printers = &defprinter;
-    }
-}
-
-int rprintcap( struct printer *pr)
-{
-
-#ifdef HAVE_CUPS
-
-    char               *p;
-
-    if ( pr->p_flags & P_SPOOLED && !(pr->p_flags & P_CUPS_AUTOADDED) ) { /* Skip check if autoadded */
-       if ( cups_printername_ok ( pr->p_printer ) != 1) {
-           LOG(log_error, logtype_papd, "No such CUPS printer: '%s'", pr->p_printer );
-           return( -1 );
-       }
-    }
-
-    /*
-     * Check for ppd file, moved here because of cups_autoadd we cannot check at the usual location
-     */
-
-    if ( pr->p_ppdfile == NULL ) {
-       if ( (p = (char *) cups_get_printer_ppd ( pr->p_printer )) != NULL ) {
-           if (( pr->p_ppdfile = (char *)malloc( strlen( p ) + 1 )) == NULL ) {
-               LOG(log_error, logtype_papd, "malloc: %s", strerror(errno) );
-               exit( 1 );
-           }
-           strcpy( pr->p_ppdfile, p );
-           pr->p_flags |= P_CUPS_PPD;
-           LOG(log_info, logtype_papd, "PPD File for %s set to %s", pr->p_printer, pr->p_ppdfile );
-       }
-    }
-
-
-#else
-
-    char               buf[ 1024 ], area[ 1024 ], *a, *p;
-    int                        c;
-
-    /*
-     * Spool directory from printcap file.
-     */
-    if ( pr->p_flags & P_SPOOLED ) {
-       if ( pgetent( printcap, buf, pr->p_printer ) != 1 ) {
-           LOG(log_error, logtype_papd, "No such printer: %s", pr->p_printer );
-           return( -1 );
-       }
-
-       /*
-        * Spool directory.
-        */
-       if ( pr->p_spool != NULL && pr->p_spool != defprinter.p_spool ) {
-           free( pr->p_spool );
-       }
-       a = area;
-       if (( p = pgetstr( "sd", &a )) == NULL ) {
-           pr->p_spool = defprinter.p_spool;
-       } else {
-           if (( pr->p_spool = (char *)malloc( strlen( p ) + 1 )) == NULL ) {
-               LOG(log_error, logtype_papd, "malloc: %s", strerror(errno) );
-               exit( 1 );
-           }
-           strcpy( pr->p_spool, p );
-       }
-
-       /*
-        * Is accounting on?
-        */
-       a = area;
-       if ( pgetstr( "af", &a ) == NULL ) {
-           pr->p_flags &= ~P_ACCOUNT;
-       } else {
-           pr->p_flags |= P_ACCOUNT;
-#ifdef ABS_PRINT
-           if ( pr->p_role != NULL && pr->p_role != defprinter.p_role ) {
-               free( pr->p_role );
-           }
-           a = area;
-           if (( p = pgetstr( "ro", &a )) == NULL ) {
-               pr->p_role = defprinter.p_role;
-           } else {
-               if (( pr->p_role =
-                       (char *)malloc( strlen( p ) + 1 )) == NULL ) {
-                   LOG(log_error, logtype_papd, "malloc: %s", strerror(errno) );
-                   exit( 1 );
-               }
-               strcpy( pr->p_role, p );
-           }
-
-           if (( c = pgetnum( "si" )) < 0 ) {
-               pr->p_srvid = defprinter.p_srvid;
-           } else {
-               pr->p_srvid = c;
-           }
-#endif /* ABS_PRINT */
-       }
-
-
-       /*
-        * Cost of printer.
-        */
-       if ( pr->p_pagecost_msg != NULL &&
-               pr->p_pagecost_msg != defprinter.p_pagecost_msg ) {
-           free( pr->p_pagecost_msg );
-       }
-       a = area;
-       if (( p = pgetstr( "pc", &a )) != NULL ) {
-           if (( pr->p_pagecost_msg =
-                   (char *)malloc( strlen( p ) + 1 )) == NULL ) {
-               LOG(log_error, logtype_papd, "malloc: %s", strerror(errno) );
-               exit( 1 );
-           }
-           strcpy( pr->p_pagecost_msg, p );
-           pr->p_pagecost = 0;
-       } else if ( pr->p_flags & P_ACCOUNT ) {
-           if (( c = pgetnum( "pc" )) < 0 ) {
-               pr->p_pagecost = defprinter.p_pagecost;
-           } else {
-               pr->p_pagecost = c;
-           }
-           pr->p_pagecost_msg = NULL;
-       }
-
-       /*
-        * Get lpd lock file.
-        */
-       if ( pr->p_lock != NULL && pr->p_lock != defprinter.p_lock ) {
-           free( pr->p_lock );
-       }
-       a = area;
-       if (( p = pgetstr( "lo", &a )) == NULL ) {
-           pr->p_lock = defprinter.p_lock;
-       } else {
-           if (( pr->p_lock = (char *)malloc( strlen( p ) + 1 )) == NULL ) {
-               LOG(log_error, logtype_papd, "malloc: %s", strerror(errno) );
-               exit( 1 );
-           }
-           strcpy( pr->p_lock, p );
-       }
-
-#ifdef KRB
-       /*
-        * Must Kerberos authenticate?
-        */
-       if ( pgetflag( "ka" ) == 1 ) {
-           pr->p_flags |= P_KRB;
-       } else {
-           pr->p_flags &= ~P_KRB;
-       }
-#endif /* KRB */
-
-       endprent();
-    }
-#endif /* HAVE_CUPS */
-
-    return( 0 );
-}
diff --git a/etc/papd/ppd.c b/etc/papd/ppd.c
deleted file mode 100644 (file)
index f164692..0000000
+++ /dev/null
@@ -1,302 +0,0 @@
-/*
- * $Id: ppd.c,v 1.17 2009-10-14 02:24:05 didg Exp $
- *
- * Copyright (c) 1995 Regents of The University of Michigan.
- * All Rights Reserved.  See COPYRIGHT.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <atalk/logger.h>
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/time.h>
-#include <netatalk/at.h>
-#include <atalk/atp.h>
-
-#include "printer.h"
-#include "ppd.h"
-
-struct ppd_font                *ppd_fonts = NULL;
-
-struct ppd_feature     ppd_features[] = {
-    { "*LanguageLevel",        NULL },
-    { "*PSVersion",    NULL },
-#ifdef HAVE_CUPS
-    { "*FreeVM",       "33554432" },
-#else
-    { "*FreeVM",       NULL },
-#endif
-    { "*Product",      NULL },
-    { "*PCFileName",   NULL },
-    { "*ModelName",    NULL },
-    { "*NickName",     NULL },
-    { "*ColorDevice",  NULL },
-    { "*FaxSupport",   NULL },
-    { "*TTRasterizer", NULL },
-    { NULL, NULL },
-};
-
-struct ppdent {
-    char       *pe_main;
-    char       *pe_option;
-    char       *pe_translation;
-    char       *pe_value;
-};
-
-#ifndef SHOWPPD
-static int ppd_inited;
-
-static void ppd_init(void)
-{
-    if (ppd_inited)
-        return;
-
-    ppd_inited++;
-
-    if (printer->p_ppdfile)
-        read_ppd( printer->p_ppdfile, 0 );
-}
-#endif /* SHOWPPD */
-
-
-/* quick and ugly hack to be able to read
-   ppd files with Mac line ending */
-static char* my_fgets(char *buf, size_t bufsize, FILE *stream)
-{
-    int p;           /* uninitialized, OK 310105 */
-    size_t count = 0;
-    while (count < (bufsize - 1) && EOF != (p=fgetc(stream))) {
-        buf[count] = p;
-        count++;
-        if ( p == '\r' || p == '\n')
-           break;
-    }
-
-    if (p == EOF && count == 0)
-        return NULL;
-
-    /* translate line endings */
-    if ( buf[count - 1] == '\r')
-        buf[count - 1] = '\n';
-
-    buf[count] = 0;
-    return buf;
-}
-
-static struct ppdent *getppdent( FILE *stream)
-{
-    static char                        buf[ 1024 ];
-    static struct ppdent       ppdent;
-    char                       *p, *q;
-
-    ppdent.pe_main = ppdent.pe_option = ppdent.pe_translation =
-           ppdent.pe_value = NULL;
-
-    while (( p = my_fgets( buf, sizeof( buf ), stream )) != NULL ) {
-       if ( *p != '*' ) {      /* main key word */
-           continue;
-       }
-       if ( p[ strlen( p ) - 1 ] != '\n') {
-           LOG(log_error, logtype_papd, "getppdent: line too long" );
-           continue;
-       }
-
-       q = p;
-       while ( (*p != ' ') && (*p != '\t') && (*p != ':') && (*p != '\n') ) {
-           p++;
-       }
-       if ( (*( q + 1 ) == '%') || (*( q + 1 ) == '?') ) {     /* comments & queries */
-           continue;
-       }
-       ppdent.pe_main = q;
-       if ( *p == '\n' ) {
-           *p = '\0';
-           ppdent.pe_option = ppdent.pe_translation = ppdent.pe_value = NULL;
-           return( &ppdent );
-       }
-
-       if ( *p != ':' ) {      /* option key word */
-           *p++ = '\0';
-
-           while ( (*p == ' ') || (*p == '\t') ) {
-               p++;
-           }
-
-           q = p;
-           while ( (*p != ':') && (*p != '/') && (*p != '\n') ) {
-               p++;
-           }
-
-           if ( *p == '\n' ) {
-               continue;
-           }
-
-           ppdent.pe_option = q;
-           if ( *p == '/' ) {  /* translation string */
-               *p++ = '\0';
-               q = p;
-               while ( *p != ':' && *p != '\n' ) {
-                   p++;
-               }
-               if ( *p != ':' ) {
-                   continue;
-               }
-
-               ppdent.pe_translation = q;
-           } else {
-               ppdent.pe_translation = NULL;
-           }
-       }
-       *p++ = '\0';
-
-       while ( (*p == ' ') || (*p == '\t') ) {
-           p++;
-       }
-
-       /* value */
-       q = p;
-       while ( *p != '\n' ) {
-           p++;
-       }
-       *p = '\0';
-       ppdent.pe_value = q;
-
-       return( &ppdent );
-    }
-
-    return( NULL );
-}
-
-int read_ppd(char *file, int fcnt)
-{
-    FILE               *ppdfile;
-    struct ppdent      *pe;
-    struct ppd_feature *pfe;
-    struct ppd_font    *pfo;
-
-    if ( fcnt > 20 ) {
-       LOG(log_error, logtype_papd, "read_ppd: %s: Too many files!", file );
-       return( -1 );
-    }
-
-    if (( ppdfile = fopen( file, "r" )) == NULL ) {
-       LOG(log_error, logtype_papd, "read_ppd %s: %s", file, strerror(errno) );
-       return( -1 );
-    }
-
-    while (( pe = getppdent( ppdfile )) != NULL ) {
-       /* *Include files */
-       if ( strcmp( pe->pe_main, "*Include" ) == 0 ) {
-           read_ppd( pe->pe_value, fcnt + 1 );
-           continue;
-       }
-
-       /* *Font */
-       if ( strcmp( pe->pe_main, "*Font" ) == 0 && pe->pe_option ) {
-           for ( pfo = ppd_fonts; pfo; pfo = pfo->pd_next ) {
-               if ( strcmp( pfo->pd_font, pe->pe_option ) == 0 ) {
-                   break;
-               }
-           }
-           if ( pfo ) {
-               continue;
-           }
-
-           if (( pfo = (struct ppd_font *)malloc( sizeof( struct ppd_font )))
-                   == NULL ) {
-               LOG(log_error, logtype_papd, "malloc: %s", strerror(errno) );
-               exit( 1 );
-           }
-           if (( pfo->pd_font =
-                   (char *)malloc( strlen( pe->pe_option ) + 1 )) == NULL ) {
-               LOG(log_error, logtype_papd, "malloc: %s", strerror(errno) );
-               exit( 1 );
-           }
-           strcpy( pfo->pd_font, pe->pe_option );
-           pfo->pd_next = ppd_fonts;
-           ppd_fonts = pfo;
-           continue;
-       }
-
-
-       /* Features */
-       for ( pfe = ppd_features; pfe->pd_name; pfe++ ) {
-           if ( strcmp( pe->pe_main, pfe->pd_name ) == 0 ) {
-               break;
-           }
-       }
-       if ( pfe->pd_name && pe->pe_value ) { 
-           if (( pfe->pd_value =
-                   (char *)malloc( strlen( pe->pe_value ) + 1 )) == NULL ) {
-               LOG(log_error, logtype_papd, "malloc: %s", strerror(errno) );
-               exit( 1 );
-           }
-
-           strcpy( pfe->pd_value, pe->pe_value );
-           continue;
-       }
-    }
-
-    fclose( ppdfile );
-    return( 0 );
-}
-
-struct ppd_font *ppd_font( char *font)
-{
-    struct ppd_font    *pfo;
-
-#ifndef SHOWPPD
-    if ( ! ppd_inited ) {
-       ppd_init();
-    }
-#endif /* SHOWPPD */
-
-    for ( pfo = ppd_fonts; pfo; pfo = pfo->pd_next ) {
-       if ( strcmp( pfo->pd_font, font ) == 0 ) {
-           return( pfo );
-       }
-    }
-    return( NULL );
-}
-
-struct ppd_feature *ppd_feature( const char *feature, int len)
-{
-    struct ppd_feature *pfe;
-    char               ppd_feature_main[ 256 ];
-    const char         *end, *p;
-    char               *q;
-
-#ifndef SHOWPPD
-    if ( ! ppd_inited ) {
-       ppd_init();
-    }
-#endif /* SHOWPPD */
-
-    if (len > sizeof(ppd_feature_main) -1)
-        return( NULL );
-        
-    for ( end = feature + len, p = feature, q = ppd_feature_main;
-           (p <= end) && (*p != '\n') && (*p != '\r'); p++, q++ ) {
-       *q = *p;
-    }
-    if ( p > end ) {
-       return( NULL );
-    }
-    *q = '\0';
-
-    for ( pfe = ppd_features; pfe->pd_name; pfe++ ) {
-       if ( (strcmp( pfe->pd_name, ppd_feature_main ) == 0) && pfe->pd_value ) {
-           return( pfe );
-       }
-    }
-
-    return( NULL );
-}
diff --git a/etc/papd/ppd.h b/etc/papd/ppd.h
deleted file mode 100644 (file)
index ad989dd..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * $Id: ppd.h,v 1.6 2009-10-13 22:55:37 didg Exp $
- *
- * Copyright (c) 1995 Regents of The University of Michigan.
- * All Rights Reserved.  See COPYRIGHT.
- */
-
-#ifndef PAPD_PPD_H
-#define PAPD_PPD_H 1
-
-#include <sys/cdefs.h>
-
-struct ppd_font {
-    char               *pd_font;
-    struct ppd_font    *pd_next;
-};
-
-struct ppd_feature {
-    char       *pd_name;
-    char       *pd_value;
-};
-
-struct ppd_feature     *ppd_feature (const char *, int);
-struct ppd_font                *ppd_font (char *);
-int read_ppd (char *, int);
-
-#endif /* PAPD_PPD_H */
diff --git a/etc/papd/print_cups.c b/etc/papd/print_cups.c
deleted file mode 100644 (file)
index ca8644c..0000000
+++ /dev/null
@@ -1,646 +0,0 @@
-/*
- * $Id: print_cups.c,v 1.6 2010-01-26 20:43:11 didg Exp $
- *
- * Copyright 2004 Bjoern Fernhomberg.
- *
- * Some code copied or adapted from print_cups.c for samba
- * Copyright 1999-2003 by Michael R Sweet.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <ctype.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
-#include <sys/types.h>
-#include <sys/param.h>
-#include <errno.h>
-
-
-#ifdef HAVE_CUPS
-
-#include <cups/cups.h>
-#include <cups/language.h>
-#include <atalk/unicode.h>
-#include <atalk/logger.h>
-#include <atalk/atp.h>
-#include <atalk/pap.h>
-#include <atalk/util.h>
-
-#include "printer.h"
-#include "print_cups.h"
-
-#define MAXCHOOSERLEN 31
-#define HTTP_MAX_URI 1024
-
-static const char* cups_status_msg[] = {
-        "status: busy; info: \"%s\" is rejecting jobs; ",
-        "status: idle; info: \"%s\" is stopped, accepting jobs ;",
-        "status: idle; info: \"%s\" is ready ; ",
-};
-
-/* Local functions */
-static int     convert_to_mac_name ( const char *encoding, char * inptr, char * outptr, size_t outlen);
-static size_t  to_ascii ( char *inbuf, char **outbuf);
-static int     cups_mangle_printer_name ( struct printer *pr, struct printer *printers);
-static void     cups_free_printer ( struct printer *pr);
-
-
-const char * cups_get_language (void)
-{
-        cups_lang_t *language;
-
-        language = cupsLangDefault();           /* needed for conversion */
-        return cupsLangEncoding(language);
-}
-
-/*
- * 'cups_passwd_cb()' - The CUPS password callback...
- */
-
-static const char *                            /* O - Password or NULL */
-cups_passwd_cb(const char *prompt _U_)      /* I - Prompt */
-{
- /*
-  * Always return NULL to indicate that no password is available...
-  */
-  return (NULL);
-}
-
-
-/*
- * 'cups_printername_ok()' - Verify supplied printer name is a valid cups printer
- */
-
-int                                     /* O - 1 if printer name OK */
-cups_printername_ok(char *name)         /* I - Name of printer */
-{
-        http_t          *http;          /* HTTP connection to server */
-        ipp_t           *request,       /* IPP Request */
-                        *response;      /* IPP Response */
-        cups_lang_t     *language;      /* Default language */
-        char            uri[HTTP_MAX_URI]; /* printer-uri attribute */
-
-       /*
-        * Make sure we don't ask for passwords...
-        */
-
-        cupsSetPasswordCB(cups_passwd_cb);
-
-       /*
-        * Try to connect to the server...
-        */
-
-        if ((http = httpConnect(cupsServer(), ippPort())) == NULL)
-        {
-               LOG(log_error, logtype_papd, "Unable to connect to CUPS server %s - %s",
-                         cupsServer(), strerror(errno));
-                return (0);
-        }
-
-
-       /*
-        * Build an IPP_GET_PRINTER_ATTRS request, which requires the following
-        * attributes:
-        *
-        *    attributes-charset
-        *    attributes-natural-language
-        *    requested-attributes
-        *    printer-uri
-        */
-
-        request = ippNew();
-
-        request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES;
-        request->request.op.request_id   = 1;
-
-        language = cupsLangDefault();
-
-        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
-                     "attributes-charset", NULL, cupsLangEncoding(language));
-
-        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
-                     "attributes-natural-language", NULL, language->language);
-
-        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
-                     "requested-attributes", NULL, "printer-uri");
-
-        sprintf(uri, "ipp://localhost/printers/%s", name);
-
-        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
-                     "printer-uri", NULL, uri);
-
-       /*
-        * Do the request and get back a response...
-        */
-
-        if ((response = cupsDoRequest(http, request, "/")) == NULL)
-        {
-               LOG(log_error, logtype_papd, "Unable to get printer status for %s - %s", name,
-                         ippErrorString(cupsLastError()));
-                httpClose(http);
-                return (0);
-        }
-
-        httpClose(http);
-
-        if (response->request.status.status_code >= IPP_OK_CONFLICT)
-        {
-               LOG(log_error, logtype_papd, "Unable to get printer status for %s - %s", name,
-                         ippErrorString(response->request.status.status_code));
-                ippDelete(response);
-                return (0);
-        }
-        else
-        {
-                ippDelete(response);
-                return (1);
-        }
-
-       return (0);
-}
-
-const char * 
-cups_get_printer_ppd ( char * name)
-{
-       cupsSetPasswordCB(cups_passwd_cb);
-       return cupsGetPPD( name );
-}
-
-int
-cups_get_printer_status (struct printer *pr)
-{
-
-        http_t          *http;          /* HTTP connection to server */
-        ipp_t           *request,       /* IPP Request */
-                        *response;      /* IPP Response */
-        ipp_attribute_t *attr;          /* Current attribute */
-        cups_lang_t     *language;      /* Default language */
-        char            uri[HTTP_MAX_URI]; /* printer-uri attribute */
-       int             status = -1;
-
-        static const char *pattrs[] =   /* Requested printer attributes */
-                        {
-                          "printer-state",
-                          "printer-state-message",
-                         "printer-is-accepting-jobs"
-                        };
-
-       /*
-        * Make sure we don't ask for passwords...
-        */
-
-        cupsSetPasswordCB(cups_passwd_cb);
-
-       /*
-        * Try to connect to the server...
-        */
-
-        if ((http = httpConnect(cupsServer(), ippPort())) == NULL)
-        {
-               LOG(log_error, logtype_papd, "Unable to connect to CUPS server %s - %s",
-                         cupsServer(), strerror(errno));
-                return (0);
-        }
-
-       /*
-        * Generate the printer URI...
-        */
-
-        sprintf(uri, "ipp://localhost/printers/%s", pr->p_printer);
-
-
-
-       /*
-        * Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the
-        * following attributes:
-        *
-        *    attributes-charset
-        *    attributes-natural-language
-        *    requested-attributes
-        *    printer-uri
-        */
-
-        request = ippNew();
-
-        request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES;
-        request->request.op.request_id   = 1;
-
-        language = cupsLangDefault();
-
-        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
-                     "attributes-charset", NULL, cupsLangEncoding(language));
-
-        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
-                     "attributes-natural-language", NULL, language->language);
-
-        ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
-                      "requested-attributes",
-                      (sizeof(pattrs) / sizeof(pattrs[0])),
-                      NULL, pattrs);
-
-        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
-                     "printer-uri", NULL, uri);
-
-       /*
-        * Do the request and get back a response...
-        */
-
-        if ((response = cupsDoRequest(http, request, "/")) == NULL)
-        {
-               LOG(log_error, logtype_papd, "Unable to get printer status for %s - %s", pr->p_printer,
-                         ippErrorString(cupsLastError()));
-                httpClose(http);
-                return (0);
-        }
-
-        if (response->request.status.status_code >= IPP_OK_CONFLICT)
-        {
-               LOG(log_error, logtype_papd, "Unable to get printer status for %s - %s", pr->p_printer,
-                         ippErrorString(response->request.status.status_code));
-                ippDelete(response);
-                httpClose(http);
-                return (0);
-        }
-
-       /*
-        * Get the current printer status and convert it to the status values.
-        */
-
-       memset ( pr->p_status, 0 ,sizeof(pr->p_status));
-
-        if ((attr = ippFindAttribute(response, "printer-state", IPP_TAG_ENUM)) != NULL)
-        {
-                if (attr->values[0].integer == IPP_PRINTER_STOPPED)
-                       status = 1;
-                else if (attr->values[0].integer == IPP_NOT_ACCEPTING)
-                       status = 0;
-               else
-                       status = 2;
-        }
-
-       if ((attr = ippFindAttribute(response, "printer-is-accepting-jobs", IPP_TAG_BOOLEAN)) != NULL)
-       {
-               if ( attr->values[0].integer == 0 ) 
-                       status = 0;
-       }
-               
-       snprintf ( pr->p_status, 255, cups_status_msg[status], pr->p_printer );
-
-        if ((attr = ippFindAttribute(response, "printer-state-message", IPP_TAG_TEXT)) != NULL)
-               strncat ( pr->p_status, attr->values[0].string.text, 255-strlen(pr->p_status));
-
-        ippDelete(response);
-
-       /*
-        * Return the print status ...
-        */
-
-        httpClose(http);
-
-       return (status);
-}
-
-
-/*------------------------------------------------------------------------*/
-
-/* pass the job to cups */
-
-int cups_print_job ( char * name, char *filename, char *job, char *username, char * cupsoptions )
-{
-       int             jobid;
-       char            filepath[MAXPATHLEN];
-       int             num_options;
-       cups_option_t   *options;
-
-       /* Initialize the options array */
-       num_options = 0;
-       options     = (cups_option_t *)0;
-
-        cupsSetPasswordCB(cups_passwd_cb);
-
-       if ( username != NULL )
-       {
-               /* Add options using cupsAddOption() */
-               num_options = cupsAddOption("job-originating-user-name", username, num_options, &options);
-               num_options = cupsAddOption("originating-user-name", username, num_options, &options);
-               cupsSetUser ( username );
-       }
-
-       if (cupsoptions != NULL)
-       {
-              num_options = cupsParseOptions(cupsoptions, num_options, &options);
-       }
-       
-       strlcpy ( filepath, SPOOLDIR, sizeof(filepath));
-       strlcat ( filepath , "/", sizeof(filepath));
-       strlcat ( filepath , filename, sizeof(filepath));
-       
-       if ((jobid = cupsPrintFile( name, filepath, job, 0, options)) == 0)
-               LOG(log_error, logtype_papd, "Unable to print job '%s' (%s) to printer '%s' for user '%s' - CUPS error : '%s'", job, filepath, name, username, ippErrorString(cupsLastError()));
-       else 
-               LOG(log_info, logtype_papd, "Job '%s' queued to printer '%s' with id '%d'", job, name, jobid);
-
-       cupsFreeOptions(num_options, options);
-       return (jobid);
-}
-
-
-/*------------------------------------------------------------------------*/
-
-struct printer *
-cups_autoadd_printers ( struct printer *defprinter, struct printer *printers)
-{
-       struct printer  *pr;
-        int            num_dests,i;
-       int             ret;
-        cups_dest_t    *dests;
-        cups_lang_t    *language;
-       char            name[MAXCHOOSERLEN+1], *p;
-
-        language  = cupsLangDefault();         /* needed for conversion */
-        num_dests = cupsGetDests(&dests);      /* get the available destination from CUPS */
-
-        for  (i=0; i< num_dests; i++)
-        {
-               if (( pr = (struct printer *)malloc( sizeof( struct printer ))) == NULL ) {
-                       LOG(log_error, logtype_papd, "malloc: %s", strerror(errno) );
-                       exit( 1 );
-               }
-       
-               memcpy( pr, defprinter, sizeof( struct printer ) );
-
-               /* convert from CUPS to local encoding */
-                convert_string_allocate( add_charset(cupsLangEncoding(language)), CH_UNIX, 
-                                         dests[i].name, -1, &pr->p_u_name);
-
-               /* convert CUPS name to Mac charset */
-               if ( convert_to_mac_name ( cupsLangEncoding(language), dests[i].name, name, sizeof(name)) <= 0)
-               {
-                       LOG (log_error, logtype_papd, "Conversion from CUPS to MAC name failed for %s", dests[i].name);
-                       free (pr);
-                       continue;
-               }
-
-               if (( pr->p_name = (char *)malloc( strlen( name ) + 1 )) == NULL ) {
-                       LOG(log_error, logtype_papd, "malloc: %s", strerror(errno) );
-                       exit( 1 );
-               }
-               strcpy( pr->p_name, name );
-
-               /* set printer flags */
-               pr->p_flags &= ~P_PIPED;
-               pr->p_flags |= P_SPOOLED;
-               pr->p_flags |= P_CUPS;
-               pr->p_flags |= P_CUPS_AUTOADDED;
-                       
-               if (( pr->p_printer = (char *)malloc( strlen( dests[i].name ) + 1 )) == NULL ) {
-                       LOG(log_error, logtype_papd, "malloc: %s", strerror(errno) );
-                               exit( 1 );
-               }
-               strcpy( pr->p_printer, dests[i].name );                 
-
-               if ( (p = (char *) cups_get_printer_ppd ( pr->p_printer )) != NULL ) {
-                       if (( pr->p_ppdfile = (char *)malloc( strlen( p ) + 1 )) == NULL ) {
-                               LOG(log_error, logtype_papd, "malloc: %s", strerror(errno) );
-                                       exit( 1 );
-                       }
-                       strcpy( pr->p_ppdfile, p );
-                       pr->p_flags |= P_CUPS_PPD;
-               }
-
-               if ( (ret = cups_check_printer ( pr, printers, 0)) == -1) 
-                       ret = cups_mangle_printer_name ( pr, printers );
-
-               if (ret) {
-                       cups_free_printer (pr);
-                       LOG(log_info, logtype_papd, "Printer %s not added: reason %d", name, ret);
-               }
-               else {
-                       pr->p_next = printers;
-                       printers = pr;
-               }
-       }
-        cupsFreeDests(num_dests, dests);
-        cupsLangFree(language);
-
-       return printers;
-}
-
-
-/*------------------------------------------------------------------------*/
-
-/* cups_mangle_printer_name
- *    Mangles the printer name if two CUPS printer provide the same Chooser Name
- *    Append '#nn' to the chooser name, if it is longer than 28 char we overwrite the last three chars
- * Returns: 0 on Success, 2 on Error
- */
-
-static int cups_mangle_printer_name ( struct printer *pr, struct printer *printers)
-{
-       size_t  count, name_len;
-       char    name[MAXCHOOSERLEN];
-
-       count = 1;
-       name_len = strlen (pr->p_name);
-       strncpy ( name, pr->p_name, MAXCHOOSERLEN-3);
-       
-       /* Reallocate necessary space */
-       (name_len >= MAXCHOOSERLEN-3) ? (name_len = MAXCHOOSERLEN+1) : (name_len = name_len + 4);
-       pr->p_name = (char *) realloc (pr->p_name, name_len );
-               
-       while ( ( cups_check_printer ( pr, printers, 0 )) && count < 100)
-       {
-               memset ( pr->p_name, 0, name_len);
-               strncpy ( pr->p_name, name, MAXCHOOSERLEN-3);
-               sprintf ( pr->p_name, "%s#%2.2u", pr->p_name, count++);
-       }
-
-       if ( count > 99) 
-               return (2);
-       
-       return (0);
-}      
-
-/*------------------------------------------------------------------------*/
-
-/* fallback ASCII conversion */
-
-static size_t
-to_ascii ( char  *inptr, char **outptr)
-{
-       char *out, *osav;
-
-       if ( NULL == (out = (char*) malloc ( strlen ( inptr) + 1 )) ) {
-               LOG(log_error, logtype_papd, "malloc: %s", strerror(errno) );
-               exit (1);
-       }
-
-       osav = out;
-
-       while ( *inptr != '\0' ) {
-               if ( *inptr & 0x80 ) {
-                       *out = '_';
-                       out++;
-                       inptr++;
-               }
-               else
-                       *out++ = *inptr++;
-       }
-       *out = '\0';
-       *outptr = osav;
-       return ( strlen (osav) );
-}
-
-
-/*------------------------------------------------------------------------*/
-
-/* convert_to_mac_name
- *     1) Convert from encoding to MacRoman
- *     2) Shorten to MAXCHOOSERLEN (31)
- *      3) Replace @ and _ as they are illegal
- * Returns: -1 on failure, length of name on success; outpr contains name in MacRoman
- */
-
-static int convert_to_mac_name ( const char * encoding, char * inptr, char * outptr, size_t outlen)
-{
-       char    *outbuf;
-       char    *soptr;
-       size_t  name_len = 0;
-       size_t  i;
-       charset_t chCups;
-
-       /* Change the encoding */
-       if ((charset_t)-1 != (chCups = add_charset(encoding))) {
-               name_len = convert_string_allocate( chCups, CH_MAC, inptr, -1, &outbuf);
-       }
-
-       if (name_len == 0 || name_len == (size_t)-1) {
-               /* charset conversion failed, use ascii fallback */
-               name_len = to_ascii ( inptr, &outbuf );
-       }
-       
-       soptr = outptr;
-
-       for ( i=0; i< name_len && i < outlen-1 ; i++)
-       {
-               if ( outbuf[i] == '_' ) 
-                       *soptr = ' '; /* Replace '_' with a space (just for the looks) */
-               else if ( outbuf[i] == '@' || outbuf[i] == ':' ) 
-                       *soptr = '_'; /* Replace @ and : with '_' as they are illegal chars */
-               else
-                       *soptr = outbuf[i];
-               soptr++;
-       }
-       *soptr = '\0';
-       free (outbuf);
-       return (i);
-}
-
-
-/*------------------------------------------------------------------------*/
-
-/*
- * cups_check_printer:
- * check if a printer with this name already exists.
- * if yes, and replace = 1 the existing printer is replaced with
- * the new one. This allows to overwrite printer settings
- * created by cupsautoadd. It also used by cups_mangle_printer.
- */
-
-int cups_check_printer ( struct printer *pr, struct printer *printers, int replace)
-{
-       struct printer *listptr, *listprev;
-
-       listptr = printers;
-       listprev = NULL;
-
-       while ( listptr != NULL) {
-               if ( strcasecmp (pr->p_name, listptr->p_name) == 0) {
-                       if ( pr->p_flags & P_CUPS_AUTOADDED ) {  /* Check if printer has been autoadded */
-                               if ( listptr->p_flags & P_CUPS_AUTOADDED )
-                                       return (-1);             /* Conflicting Cups Auto Printer (mangling issue?) */
-                               else
-                                       return (1);              /* Never replace a hand edited printer with auto one */
-                       }
-
-                       if ( replace ) {
-                               /* Replace printer */
-                               if ( listprev != NULL) {
-                                       pr->p_next = listptr->p_next;
-                                       listprev->p_next = pr;
-                                       cups_free_printer (listptr);
-                               }
-                               else {
-                                       printers = pr;
-                                       printers->p_next = listptr->p_next;
-                                       cups_free_printer (listptr);
-                               }
-                       }
-                       return (1);  /* Conflicting Printers */
-               }
-               listprev = listptr;
-               listptr = listptr->p_next;
-       }       
-       return (0);     /* No conflict */
-}
-
-
-/*------------------------------------------------------------------------*/
-
-
-void
-cups_free_printer ( struct printer *pr)
-{
-       if ( pr->p_name != NULL)
-               free (pr->p_name);
-       if ( pr->p_printer != NULL)
-               free (pr->p_printer);
-       if ( pr->p_ppdfile != NULL)
-               free (pr->p_ppdfile);
-       
-       /* CUPS autoadded printers share the other informations
-        * so if the printer is autoadded we won't free them.
-        * We might leak some bytes here though.
-        */
-       if ( pr->p_flags & P_CUPS_AUTOADDED ) {
-               free (pr);
-               return;
-       }
-
-       if ( pr->p_operator != NULL )
-               free (pr->p_operator);
-       if ( pr->p_zone != NULL )
-               free (pr->p_zone);
-       if ( pr->p_type != NULL )
-               free (pr->p_type);
-       if ( pr->p_authprintdir != NULL )
-               free (pr->p_authprintdir);
-       
-       free ( pr );
-       return;
-       
-}
-       
-#endif /* HAVE_CUPS*/
diff --git a/etc/papd/print_cups.h b/etc/papd/print_cups.h
deleted file mode 100644 (file)
index dd9e711..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-\r
-#ifndef PAPD_CUPS_H\r
-#define PAPD_CUPS_H 1\r
-\r
-#ifdef HAVE_CUPS\r
-#include <sys/cdefs.h>\r
-\r
-struct cups_status {\r
-       int     pr_status;\r
-       char *  status_message;\r
-};\r
-\r
-int            cups_printername_ok (char * );\r
-const char *   cups_get_printer_ppd ( char * );\r
-int            cups_get_printer_status (struct printer *pr);\r
-int            cups_print_job ( char *, char *, char *, char *, char *);\r
-struct printer * cups_autoadd_printers ( struct printer *, struct printer *);\r
-int            cups_check_printer ( struct printer *, struct printer *, int);\r
-const char     *cups_get_language ( void );\r
-#endif /* HAVE_CUPS */\r
-#endif /* PAPD_CUPS_H */\r
diff --git a/etc/papd/printcap.c b/etc/papd/printcap.c
deleted file mode 100644 (file)
index 9215a11..0000000
+++ /dev/null
@@ -1,528 +0,0 @@
-/*
- * $Id: printcap.c,v 1.12 2009-10-14 02:24:05 didg Exp $
- *
- * Copyright (c) 1990,1994 Regents of The University of Michigan.
- * All Rights Reserved.  See COPYRIGHT.
- *
- * Copyright (c) 1983 Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the University of
- *     California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <ctype.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
-#include <sys/types.h>
-#include <sys/stat.h>
-#ifdef HAVE_FCNTL_H
-#include <fcntl.h>
-#endif /* HAVE_FCNTL_H */
-#include <atalk/paths.h>
-
-#include "printcap.h"
-
-#ifndef BUFSIZ
-#define        BUFSIZ  1024
-#endif /* ! BUFSIZ */
-#define MAXHOP 32      /* max number of tc= indirections */
-
-/*
- * termcap - routines for dealing with the terminal capability data base
- *
- * BUG:                Should use a "last" pointer in tbuf, so that searching
- *             for capabilities alphabetically would not be a n**2/2
- *             process when large numbers of capabilities are given.
- * Note:       If we add a last pointer now we will screw up the
- *             tc capability. We really should compile termcap.
- *
- * Essentially all the work here is scanning and decoding escapes
- * in string capabilities.  We don't use stdio because the editor
- * doesn't, and because living w/o it is not hard.
- */
-
-#define PRINTCAP
-
-#ifdef PRINTCAP
-#define tgetent        pgetent
-#define tskip  pskip
-#define tgetstr        pgetstr
-#define tdecode pdecode
-#define tgetnum        pgetnum
-#define        tgetflag pgetflag
-#define tdecode pdecode
-#define tnchktc        pnchktc
-#define        tnamatch pnamatch
-#define V6
-#endif /* PRINTCAP */
-
-static FILE *pfp = NULL;       /* printcap data base file pointer */
-static char *tbuf;
-static int hopcount;           /* detect infinite loops in termcap, init 0 */
-
-/*
- * Similar to tgetent except it returns the next entry instead of
- * doing a lookup.
- *
- * Added a "cap" parameter, so we can use these calls for printcap
- * and papd.conf.
- */
-int getprent( char *cap, char *bp, int bufsize)
-{
-       register int c, skip = 0, i;
-
-       if (pfp == NULL && (pfp = fopen( cap, "r")) == NULL)
-               return(-1);
-       tbuf = bp;
-       i = 0;
-       for (;;) {
-               switch (c = getc(pfp)) {
-               case EOF:
-                        if (bp != tbuf) {
-                               *bp = '\0';
-                               return(1);
-                       }
-                       fclose(pfp);
-                       pfp = NULL;
-                       return(0);
-               case '\n':
-                       if (bp == tbuf) {
-                               skip = 0;
-                               continue;
-                       }
-                       if (bp[-1] == '\\') {
-                               bp--;
-                               continue;
-                       }
-                       *bp = '\0';
-                       return(1);
-               case '#':
-                       if (bp == tbuf)
-                               skip++;
-               default:
-                       if (skip)
-                               continue;
-                       if (bp >= tbuf+BUFSIZ) {
-                               write(2, "Termcap entry too long\n", 23);
-                               *bp = '\0';
-                               return(1);
-                       }
-                       *bp++ = c;
-                       if (++i >= bufsize) {
-                               write(2, "config file too large\n", 22);
-                               fclose(pfp);
-                               pfp = NULL;
-                               *bp = '\0';
-                               return(1);
-                       }
-               }
-       }
-}
-
-void endprent(void)
-{
-       if (pfp != NULL)
-               fclose(pfp);
-}
-
-/*
- * Get an entry for terminal name in buffer bp,
- * from the termcap file.  Parse is very rudimentary;
- * we just notice escaped newlines.
- *
- * Added a "cap" parameter, so we can use these calls for printcap
- * and papd.conf.
- */
-int tgetent(char *cap, char *bp, char *name)
-{
-       register char *cp;
-       register int c;
-       register int i = 0, cnt = 0;
-       char ibuf[BUFSIZ];
-       int tf;
-       int skip;
-
-       hopcount = 0;
-       tbuf = bp;
-       tf = 0;
-#ifndef V6
-       cp = getenv("TERMCAP");
-       /*
-        * TERMCAP can have one of two things in it. It can be the
-        * name of a file to use instead of /etc/termcap. In this
-        * case it better start with a "/". Or it can be an entry to
-        * use so we don't have to read the file. In this case it
-        * has to already have the newlines crunched out.
-        */
-       if (cp && *cp) {
-               if (*cp!='/') {
-                       cp2 = getenv("TERM");
-                       if (cp2==(char *) 0 || strcmp(name,cp2)==0) {
-                               strcpy(bp,cp);
-                               return(tnchktc(cap));
-                       } else {
-                               tf = open(cap, 0);
-                       }
-               } else
-                       tf = open(cp, 0);
-       }
-       if (tf==0)
-               tf = open(cap, 0);
-#else /* V6 */
-       tf = open(cap, 0);
-#endif /* V6 */
-       if (tf < 0)
-               return (-1);
-       for (;;) {
-               cp = bp;
-               skip = 0;
-               for (;;) {
-                       if (i == cnt) {
-                               cnt = read(tf, ibuf, BUFSIZ);
-                               if (cnt <= 0) {
-                                       close(tf);
-                                       return (0);
-                               }
-                               i = 0;
-                       }
-                       c = ibuf[i++];
-                       if (c == '\n') {
-                               if (!skip && cp > bp && cp[-1] == '\\') {
-                                       cp--;
-                                       continue;
-                               }
-                               skip = 0;
-                               if (cp == bp)
-                                       continue;
-                               else
-                                       break;
-                       }
-                       if (c == '#' && cp == bp)
-                               skip++;
-                       if (skip)
-                               continue;
-                       if (cp >= bp+BUFSIZ) {
-                               write(2,"Termcap entry too long\n", 23);
-                               break;
-                       } else
-                               *cp++ = c;
-               }
-               *cp = 0;
-
-               /*
-                * The real work for the match.
-                */
-               if (tnamatch(name)) {
-                       close(tf);
-                       return(tnchktc(cap));
-               }
-       }
-}
-
-/*
- * tnchktc: check the last entry, see if it's tc=xxx. If so,
- * recursively find xxx and append that entry (minus the names)
- * to take the place of the tc=xxx entry. This allows termcap
- * entries to say "like an HP2621 but doesn't turn on the labels".
- * Note that this works because of the left to right scan.
- *
- * Added a "cap" parameter, so we can use these calls for printcap
- * and papd.conf.
- */
-int tnchktc( char *cap)
-{
-       register char *p, *q;
-       char tcname[16];        /* name of similar terminal */
-       char tcbuf[BUFSIZ];
-       char *holdtbuf = tbuf;
-       int l;
-
-       p = tbuf + strlen(tbuf) - 2;    /* before the last colon */
-       while (*--p != ':')
-               if (p<tbuf) {
-                       write(2, "Bad termcap entry\n", 18);
-                       return (0);
-               }
-       p++;
-       /* p now points to beginning of last field */
-       if (p[0] != 't' || p[1] != 'c')
-               return(1);
-       strcpy(tcname,p+3);
-       q = tcname;
-       while (q && *q != ':')
-               q++;
-       *q = 0;
-       if (++hopcount > MAXHOP) {
-               write(2, "Infinite tc= loop\n", 18);
-               return (0);
-       }
-       if (tgetent( cap, tcbuf, tcname) != 1)
-               return(0);
-       for (q=tcbuf; *q != ':'; q++)
-               ;
-       l = p - holdtbuf + strlen(q);
-       if (l > BUFSIZ) {
-               write(2, "Termcap entry too long\n", 23);
-               q[BUFSIZ - (p-tbuf)] = 0;
-       }
-       strcpy(p, q+1);
-       tbuf = holdtbuf;
-       return(1);
-}
-
-/*
- * Tnamatch deals with name matching.  The first field of the termcap
- * entry is a sequence of names separated by |'s, so we compare
- * against each such name.  The normal : terminator after the last
- * name (before the first field) stops us.
- */
-int tnamatch(char *np)
-{
-       register char *Np, *Bp;
-
-       Bp = tbuf;
-       if (*Bp == '#')
-               return(0);
-       for (;;) {
-               for (Np = np; *Np && *Bp == *Np; Bp++, Np++)
-                       continue;
-               if (*Np == 0 && (*Bp == '|' || *Bp == ':' || *Bp == 0))
-                       return (1);
-               while (*Bp && *Bp != ':' && *Bp != '|')
-                       Bp++;
-               if (*Bp == 0 || *Bp == ':')
-                       return (0);
-               Bp++;
-       }
-}
-
-/*
- * Skip to the next field.  Notice that this is very dumb, not
- * knowing about \: escapes or any such.  If necessary, :'s can be put
- * into the termcap file in octal.
- */
-static char *tskip(char *bp)
-{
-
-       while (*bp && *bp != ':')
-               bp++;
-       while (*bp && *bp == ':')
-               bp++;
-       return (bp);
-}
-
-/*
- * Return the (numeric) option id.
- * Numeric options look like
- *     li#80
- * i.e. the option string is separated from the numeric value by
- * a # character.  If the option is not found we return -1.
- * Note that we handle octal numbers beginning with 0.
- */
-int tgetnum(char *id)
-{
-       register int i, base;
-       register char *bp = tbuf;
-
-       for (;;) {
-               bp = tskip(bp);
-               if (*bp == 0)
-                       return (-1);
-               if (*bp++ != id[0] || *bp == 0 || *bp++ != id[1])
-                       continue;
-               if (*bp == '@')
-                       return(-1);
-               if (*bp != '#')
-                       continue;
-               bp++;
-               base = 10;
-               if (*bp == '0')
-                       base = 8;
-               i = 0;
-               while (isdigit(*bp))
-                       i *= base, i += *bp++ - '0';
-               return (i);
-       }
-}
-
-/*
- * Handle a flag option.
- * Flag options are given "naked", i.e. followed by a : or the end
- * of the buffer.  Return 1 if we find the option, or 0 if it is
- * not given.
- */
-int tgetflag(char *id)
-{
-       register char *bp = tbuf;
-
-       for (;;) {
-               bp = tskip(bp);
-               if (!*bp)
-                       return (0);
-               if (*bp++ == id[0] && *bp != 0 && *bp++ == id[1]) {
-                       if (!*bp || *bp == ':')
-                               return (1);
-                       else if (*bp == '@')
-                               return(0);
-               }
-       }
-}
-
-/*
- * Tdecode does the grung work to decode the
- * string capability escapes.
- */
-static char *
-tdecode(char *str, char **area)
-{
-       register char *cp;
-       register int c;
-       register char *dp;
-       int i;
-
-       cp = *area;
-       while ((c = *str++) && c != ':') {
-               switch (c) {
-
-               case '^':
-                       c = *str++ & 037;
-                       break;
-
-               case '\\':
-                       dp = "E\033^^\\\\::n\nr\rt\tb\bf\f";
-                       c = *str++;
-nextc:
-                       if (*dp++ == c) {
-                               c = *dp++;
-                               break;
-                       }
-                       dp++;
-                       if (*dp)
-                               goto nextc;
-                       if (isdigit(c)) {
-                               c -= '0', i = 2;
-                               do
-                                       c <<= 3, c |= *str++ - '0';
-                               while (--i && isdigit(*str));
-                       }
-                       break;
-               }
-               *cp++ = c;
-       }
-       *cp++ = 0;
-       str = *area;
-       *area = cp;
-       return (str);
-}
-
-/*
- * Get a string valued option.
- * These are given as
- *     cl=^Z
- * Much decoding is done on the strings, and the strings are
- * placed in area, which is a ref parameter which is updated.
- * No checking on area overflow.
- */
-char *
-tgetstr(char *id, char **area)
-{
-       register char *bp = tbuf;
-
-       for (;;) {
-               bp = tskip(bp);
-               if (!*bp)
-                       return (NULL);
-               if (*bp++ != id[0] || *bp == 0 || *bp++ != id[1])
-                       continue;
-               if (*bp == '@')
-                       return(NULL);
-               if (*bp != '=')
-                       continue;
-               bp++;
-               return (tdecode(bp, area));
-       }
-}
-
-static char *
-decodename(char *str, char **area, int bufsize)
-{
-       register char *cp;
-       register int c;
-       register char *dp;
-       int i;
-
-       cp = *area;
-       while ((c = *str++) && --bufsize && c != ':' && c != '|' ) {
-               switch (c) {
-
-               case '^':
-                       c = *str++ & 037;
-                       break;
-
-               case '\\':
-                       dp = "E\033^^\\\\::n\nr\rt\tb\bf\f";
-                       c = *str++;
-nextc:
-                       if (*dp++ == c) {
-                               c = *dp++;
-                               break;
-                       }
-                       dp++;
-                       if (*dp)
-                               goto nextc;
-                       if (isdigit(c)) {
-                               c -= '0', i = 2;
-                               do
-                                       c <<= 3, c |= *str++ - '0';
-                               while (--i && isdigit(*str));
-                       }
-                       break;
-               }
-               *cp++ = c;
-       }
-       *cp++ = 0;
-       str = *area;
-       *area = cp;
-       return (str);
-}
-
-char *
-getpname(char **area, int bufsize)
-{
-       return( decodename( tbuf, area, bufsize));
-}
diff --git a/etc/papd/printcap.h b/etc/papd/printcap.h
deleted file mode 100644 (file)
index d300d45..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * $Id: printcap.h,v 1.5 2009-10-13 22:55:37 didg Exp $
- */
-
-#ifndef PAPD_PRINTCAP_H
-#define PAPD_PRINTCAP_H 1
-
-#include <sys/cdefs.h>
-
-int getprent ( register char *, register char *, register int );
-int pnchktc ( char * );
-int pgetflag ( char * );
-void endprent ( void );
-int pgetent ( char *, char *, char * );
-int pgetnum ( char * );
-int pnamatch ( char * );
-
-#endif /* PAPD_PRINTCAP_H */
diff --git a/etc/papd/printer.h b/etc/papd/printer.h
deleted file mode 100644 (file)
index 7c56273..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * $Id: printer.h,v 1.6 2005-04-28 20:49:49 bfernhomberg Exp $
- *
- * Copyright (c) 1990,1995 Regents of The University of Michigan.
- * All Rights Reserved.  See COPYRIGHT.
- */
-
-struct printer {
-    char               *p_name;
-    char               *p_type;
-    char               *p_zone;
-    char               *p_u_name;
-#ifdef notdef
-    char               *p_fonts;
-    char               *p_psetdir;
-#endif /* notdef */
-    char               *p_ppdfile;
-    char               p_status[255];
-    char               *p_authprintdir;
-    int                        p_flags;
-    struct at_addr      p_addr;
-    union {
-       struct {
-           char                *pr_printer;
-           char                *pr_operator;
-           char                *pr_spool;
-#ifdef ABS_PRINT
-           char                *pr_role;
-           double              pr_balance;
-           int                 pr_srvid;
-#endif /* ABS_PRINT */
-           int                 pr_pagecost;
-           char                *pr_pagecost_msg;
-           char                *pr_lock;
-       } pu_pr;
-       char            *pu_cmd;
-    } p_un;
-    ATP                        p_atp;
-#ifdef HAVE_CUPS
-    char               *p_cupsoptions;
-#endif
-    struct printer     *p_next;
-};
-#define p_cmd          p_un.pu_cmd
-#define p_printer      p_un.pu_pr.pr_printer
-#define p_operator     p_un.pu_pr.pr_operator
-#define p_spool                p_un.pu_pr.pr_spool
-#ifdef ABS_PRINT
-#define p_role         p_un.pu_pr.pr_role
-#define p_balance      p_un.pu_pr.pr_balance
-#define p_srvid                p_un.pu_pr.pr_srvid
-#endif /* ABS_PRINT */
-#define p_pagecost     p_un.pu_pr.pr_pagecost
-#define p_pagecost_msg p_un.pu_pr.pr_pagecost_msg
-#define p_lock         p_un.pu_pr.pr_lock
-
-#define P_PIPED                (1<<0)
-#define P_SPOOLED      (1<<1)
-#define P_REGISTERED   (1<<2)
-#define P_ACCOUNT      (1<<3)
-#define P_KRB          (1<<4)
-#define P_AUTH         (1<<5)
-#define P_AUTH_PSSP    (1<<6)
-#define P_AUTH_CAP     (1<<7)
-#define P_CUPS         (1<<8)
-#define P_CUPS_PPD     (1<<9)
-#define P_CUPS_AUTOADDED (1<<10)
-#define P_FOOMATIC_HACK (1<<11)
-
-extern struct printer  *printer;
diff --git a/etc/papd/queries.c b/etc/papd/queries.c
deleted file mode 100644 (file)
index ef1c5a6..0000000
+++ /dev/null
@@ -1,790 +0,0 @@
-/*
- * $Id: queries.c,v 1.22 2009-10-13 22:55:37 didg Exp $
- *
- * Copyright (c) 1990,1994 Regents of The University of Michigan.
- * All Rights Reserved.  See COPYRIGHT.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <atalk/logger.h>
-#include <sys/param.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <netatalk/at.h>
-#include <atalk/atp.h>
-
-#ifdef KRB
-#ifdef SOLARIS
-#include <kerberos/krb.h>
-#else /* SOLARIS */
-#include <krb.h>
-#endif /* SOLARIS */
-#endif /* KRB */
-
-#include "file.h"
-#include "comment.h"
-#include "printer.h"
-#include "ppd.h"
-#include "lp.h"
-#include "uam_auth.h"
-
-int cq_default( struct papfile *, struct papfile * );
-int cq_k4login( struct papfile *, struct papfile * );
-int cq_uameth( struct papfile *, struct papfile * );
-
-int gq_balance( struct papfile * );
-int gq_pagecost( struct papfile * );
-int gq_true( struct papfile * );
-int gq_rbispoolerid( struct papfile * );
-int gq_rbiuamlist( struct papfile * );
-
-int cq_query( struct papfile *, struct papfile * );
-void cq_font_answer( char *, char *, struct papfile * );
-int cq_font( struct papfile *, struct papfile * );
-int cq_feature( struct papfile *, struct papfile * );
-int cq_printer( struct papfile *, struct papfile * );
-int cq_rmjob( struct papfile *, struct papfile * );
-#ifndef HAVE_CUPS
-int cq_listq( struct papfile *, struct papfile * );
-int cq_rbilogin( struct papfile *, struct papfile * );
-#endif  /* HAVE_CUPS */
-
-
-
-int cq_default( struct papfile *in, struct papfile *out)
-{
-    char               *start, *stop, *p;
-    int                        linelength, crlflength;
-    struct papd_comment        *comment = compeek();
-
-    for (;;) {
-       switch ( markline( in, &start, &linelength, &crlflength )) {
-       case 0 :
-           return( 0 );
-
-       case -1 :
-           return( CH_MORE );
-
-        case -2 :
-            return( CH_ERROR );
-       }
-
-       stop = start+linelength;
-
-       if ( comgetflags() == 0 ) {     /* started */
-           if ( comment->c_end ) {
-               comsetflags( 1 );
-           } else {
-               compop();
-               CONSUME( in, linelength + crlflength );
-               return( CH_DONE );
-           }
-       } else {
-           /* return default */
-           if ( comcmp( start, start+linelength, comment->c_end, 0 ) == 0 ) {
-               for ( p = start; p < stop; p++ ) {
-                   if ( *p == ':' ) {
-                       break;
-                   }
-               }
-               if (p < stop) {
-                   p++;
-                   while ( *p == ' ' ) {
-                       p++;
-                    }
-               }
-
-               append( out, p, stop - p + crlflength );
-               compop();
-               CONSUME( in, linelength + crlflength );
-               return( CH_DONE );
-           }
-       }
-
-       CONSUME( in, linelength + crlflength );
-    }
-}
-
-#ifdef KRB
-char   *LoginOK = "LoginOK\n";
-char   *LoginFailed = "LoginFailed\n";
-
-#define h2b(x) (isdigit((x))?(x)-'0':(isupper((x))?(x)-'A':(x)-'a')+10)
-
-int cq_k4login( struct papfile *in, struct papfile *out)
-{
-    char               *start, *p;
-    int                        linelength, crlflength;
-    unsigned char      *t;
-    struct papd_comment        *comment = compeek();
-    KTEXT_ST           tkt;
-    AUTH_DAT           ad;
-    int                        rc, i;
-
-    switch ( markline( in, &start, &linelength, &crlflength )) {
-    case 0 :
-       return( 0 );
-
-    case -1 :
-       return( CH_MORE );
-
-    case -2 :
-        return( CH_ERROR );
-    }
-
-    p = start + strlen( comment->c_begin );
-    while ( *p == ' ' ) {
-       p++;
-    }
-
-    bzero( &tkt, sizeof( tkt ));
-    stop = start+linelength;
-    /* FIXME */
-    for ( i = 0, t = tkt.dat; p < stop; p += 2, t++, i++ ) {
-       *t = ( h2b( (unsigned char)*p ) << 4 ) +
-               h2b( (unsigned char)*( p + 1 ));
-    }
-    tkt.length = i;
-
-    if (( rc = krb_rd_req( &tkt, "LaserWriter", printer->p_name,
-           0, &ad, "" )) != RD_AP_OK ) {
-       LOG(log_error, logtype_papd, "cq_k4login: %s", krb_err_txt[ rc ] );
-       append( out, LoginFailed, strlen( LoginFailed ));
-       compop();
-       CONSUME( in, linelength + crlflength );
-       return( CH_DONE );
-    }
-    LOG(log_info, logtype_papd, "cq_k4login: %s.%s@%s", ad.pname, ad.pinst,
-           ad.prealm );
-    lp_person( ad.pname );
-    lp_host( ad.prealm );
-
-    append( out, LoginOK, strlen( LoginOK ));
-    compop();
-    CONSUME( in, linelength + crlflength);
-    return( CH_DONE );
-}
-
-char   *uameth = "UMICHKerberosIV\n*\n";
-
-int cq_uameth( struct papfile *in, struct papfile *out)
-{
-    char               *start;
-    int                        linelength, crlflength;
-    struct papd_comment        *c, *comment = compeek();
-
-    for (;;) {
-       switch ( markline( in, &start, &linelength, &crlflength )) {
-       case 0 :
-           return( 0 );
-
-       case -1 :
-           return( CH_MORE );
-
-        case -2 :
-            return( CH_ERROR );
-       }
-
-       if ( comgetflags() == 0 ) {     /* start */
-           if (( printer->p_flags & P_KRB ) == 0 ) {   /* no kerberos */
-               if ( comswitch( queries, cq_default ) < 0 ) {
-                   LOG(log_error, logtype_papd, "cq_uameth: can't find default!" );
-                   exit( 1 );
-               }
-               return( CH_DONE );
-           }
-           comsetflags( 1 );
-       } else {
-           if ( comcmp( start, stop, comment->c_end, 0 ) == 0 ) { /* end */
-               append( out, uameth, strlen( uameth ));
-               compop();
-               return( CH_DONE );
-           }
-       }
-
-       CONSUME( in, linelength + crlflength );
-    }
-}
-#endif /* KRB */
-
-int gq_true( struct papfile *out)
-{
-    if ( printer->p_flags & P_SPOOLED ) {
-       append( out, "true\n", 5 );
-       return( 0 );
-    } else {
-       return( -1 );
-    }
-}
-
-int gq_pagecost( struct papfile *out)
-{
-    char               cost[ 60 ];
-
-    /* check for spooler? XXX */
-    if ( printer->p_pagecost_msg != NULL ) {
-       append( out, printer->p_pagecost_msg,
-               strlen( printer->p_pagecost_msg ));
-    } else if ( printer->p_flags & P_ACCOUNT ) {
-#ifdef ABS_PRINT
-       lp_pagecost();
-#endif /* ABS_PRINT */
-       sprintf( cost, "%d", printer->p_pagecost );
-       append( out, cost, strlen( cost ));
-    } else {
-       return( -1 );
-    }
-    append( out, "\n", 1 );
-    return( 0 );
-}
-
-#ifdef ABS_PRINT
-int gq_balance( struct papfile *out)
-{
-    char               balance[ 60 ];
-
-    if ( lp_pagecost() != 0 ) {
-       return( -1 );
-    }
-    sprintf( balance, "$%1.2f\n", printer->p_balance );
-    append( out, balance, strlen( balance ));
-    return( 0 );
-}
-#endif /* ABS_PRINT */
-
-
-/*
- * Handler for RBISpoolerID
- */
-
-static const char *spoolerid = "(PAPD Spooler) 1.0 (" VERSION ")\n";
-
-int gq_rbispoolerid( struct papfile *out)
-{
-    append( out, spoolerid, strlen( spoolerid ));
-    return(0);
-}
-
-
-
-/*
- * Handler for RBIUAMListQuery
- */
-
-static const char *nouams = "*\n";
-
-int gq_rbiuamlist( struct papfile *out)
-{
-    char uamnames[128] = "\0";
-
-    if (printer->p_flags & P_AUTH_PSSP) {
-       if (getuamnames(UAM_SERVER_PRINTAUTH, uamnames) < 0) {
-           append(out, nouams, strlen(nouams));
-           return(0);
-       } else {
-           append(out, uamnames, strlen(uamnames));
-           return(0);
-       }
-    } else {
-       append(out, nouams, strlen(nouams));
-       return(0);
-    }
-}
-
-
-struct genquery {
-    char       *gq_name;
-    int                (*gq_handler)();
-} genqueries[] = {
-    { "UMICHCostPerPage", gq_pagecost },
-#ifdef notdef
-    { "UMICHUserBalance", gq_balance },
-#endif /* notdef */
-    { "RBISpoolerID",  gq_rbispoolerid },
-    { "RBIUAMListQuery", gq_rbiuamlist },
-    { "ADOIsBinaryOK?", gq_true },
-    { "UMICHListQueue", gq_true },
-    { "UMICHDeleteJob", gq_true },
-    { NULL, NULL },
-};
-
-int cq_query( struct papfile *in, struct papfile *out)
-{
-    char               *start, *stop, *p, *q;
-    int                        linelength, crlflength;
-    struct papd_comment        *comment = compeek();
-    struct genquery    *gq;
-
-
-    for (;;) {
-       switch ( markline( in, &start, &linelength, &crlflength )) {
-       case 0 :
-           return( 0 );
-
-       case -1 :
-           return( CH_MORE );
-
-        case -2 :
-            return( CH_ERROR );
-       }
-
-       stop = start+linelength;
-
-       if ( comgetflags() == 0 ) {     /* started */
-           comsetflags( 1 );
-
-           for ( p = start; p < stop; p++ ) {
-               if ( *p == ':' ) {
-                   break;
-               }
-           }
-
-           if (p < stop) for ( p++; p < stop; p++ ) {
-               if ( *p != ' ' && *p != '\t' ) {
-                   break;
-               }
-           }
-
-           for ( q = p; q < stop; q++ ) {
-               if ( *q == ' ' || *q == '\t' || *q == '\r' || *q == '\n' ) {
-                   break;
-               }
-           }
-
-           for ( gq = genqueries; gq->gq_name; gq++ ) {
-               if (( strlen( gq->gq_name ) == (size_t)(q - p) ) &&
-                       ( strncmp( gq->gq_name, p, q - p ) == 0 )) {
-                   break;
-               }
-           }
-           if ( gq->gq_name == NULL || gq->gq_handler == NULL ||
-                   (gq->gq_handler)( out ) < 0 ) {
-               if ( comswitch( queries, cq_default ) < 0 ) {
-                   LOG(log_error, logtype_papd, "cq_feature: can't find default!" );
-                   exit( 1 );
-               }
-               return( CH_DONE );
-           }
-       } else {
-           if ( comcmp( start, stop, comment->c_end, 0 ) == 0 ) {
-               compop();
-               CONSUME( in, linelength + crlflength );
-               return( CH_DONE );
-           }
-       }
-
-       CONSUME( in, linelength + crlflength );
-    }
-}
-
-void cq_font_answer( char *start, char *stop, struct papfile *out)
-{
-    char               *p, *q, buf[ 256 ];
-    struct ppd_font    *pfo;
-
-    p = start;
-    while ( p < stop ) {
-        unsigned int count = 0;
-       while (( *p == ' ' || *p == '\t' ) && p < stop ) {
-           p++;
-       }
-
-       q = buf;
-       while ( *p != ' ' && *p != '\t' &&
-               *p != '\n' && *p != '\r' && p < stop && count < sizeof(buf)) {
-           *q++ = *p++;
-           count++;
-       }
-
-       if ( q != buf ) {
-           *q = '\0';
-
-           append( out, "/", 1 );
-           append( out, buf, strlen( buf ));
-           append( out, ":", 1 );
-
-           if (( pfo = ppd_font( buf )) == NULL ) {
-               append( out, "No\n", 3 );
-           } else {
-               append( out, "Yes\n", 4 );
-           }
-       }
-    }
-
-    return;
-}
-
-int cq_font(struct papfile *in, struct papfile *out)
-{
-    char               *start, *stop, *p;
-    int                        linelength, crlflength;
-    struct papd_comment        *comment = compeek();
-
-    for (;;) {
-       switch ( markline( in, &start, &linelength, &crlflength )) {
-       case 0 :
-           return( 0 );
-
-       case -1 :
-           return( CH_MORE );
-
-        case -2 :
-            return( CH_ERROR );
-       }
-
-       stop = start + linelength;
-
-       if ( comgetflags() == 0 ) {
-           comsetflags( 1 );
-
-           for ( p = start; p < stop; p++ ) {
-               if ( *p == ':' ) {
-                   break;
-               }
-           }
-           if (p < stop)
-               p++;
-
-           cq_font_answer( p, stop, out );
-       } else {
-           if ( comgetflags() == 1 &&
-                   comcmp( start, stop, comcont, 0 ) == 0 ) {
-               /* continuation */
-
-               for ( p = start; p < stop; p++ ) {
-                   if ( *p == ' ' ) {
-                       break;
-                   }
-               }
-               if (p < stop)
-                   p++;
-
-               cq_font_answer( p, stop, out );
-           } else {
-               comsetflags( 2 );
-               if ( comcmp( start, stop, comment->c_end, 0 ) == 0 ) {
-                   append( out, "*\n", 2 );
-                   compop();
-                   CONSUME( in, linelength + crlflength );
-                   return( CH_DONE );
-               }
-           }
-       }
-
-        CONSUME( in, linelength + crlflength );
-    }
-}
-
-int cq_feature( struct papfile *in, struct papfile *out)
-{
-    char               *start, *stop, *p;
-    int                        linelength, crlflength;
-    struct papd_comment        *comment = compeek();
-    struct ppd_feature *pfe;
-
-    for (;;) {
-       switch ( markline( in, &start, &linelength, &crlflength )) {
-       case 0 :
-           return( 0 );
-
-       case -1 :
-           return( CH_MORE );
-
-        case -2 :
-            return( CH_ERROR );
-       }
-
-       stop = start + linelength;
-
-       if ( comgetflags() == 0 ) {
-           comsetflags( 1 );
-
-           /* parse for feature */
-           for ( p = start; p < stop; p++ ) {
-               if ( *p == ':' ) {
-                   break;
-               }
-           }
-           if (p < stop)
-               p++;
-           while ( *p == ' ' ) {
-               p++;
-           }
-
-           if (( pfe = ppd_feature( p, stop - p )) == NULL ) {
-               if ( comswitch( queries, cq_default ) < 0 ) {
-                   LOG(log_error, logtype_papd, "cq_feature: can't find default!" );
-                   exit( 1 );
-               }
-               return( CH_DONE );
-           }
-
-           append( out, pfe->pd_value, strlen( pfe->pd_value ));
-           append( out, "\r", 1 );
-       } else {
-           if ( comcmp( start, stop, comment->c_end, 0 ) == 0 ) {
-               compop();
-               CONSUME( in, linelength + crlflength );
-               return( CH_DONE );
-           }
-       }
-
-       CONSUME( in, linelength + crlflength );
-    }
-}
-
-static const char      *psver = "*PSVersion\n";
-static const char      *prod = "*Product\n";
-
-int cq_printer(struct papfile *in, struct papfile *out)
-{
-    char               *start, *p;
-    int                        linelength, crlflength;
-    struct papd_comment        *comment = compeek();
-    struct ppd_feature *pdpsver, *pdprod;
-
-    for (;;) {
-       switch ( markline( in, &start, &linelength, &crlflength )) {
-       case 0 :
-           return( 0 );
-
-       case -1 :
-           return( CH_MORE );
-
-        case -2 :
-            return( CH_ERROR );
-       }
-
-       if ( comgetflags() == 0 ) {
-           comsetflags( 1 );
-
-           if (( pdpsver = ppd_feature( psver, strlen( psver ))) == NULL ) {
-               if ( comswitch( queries, cq_default ) < 0 ) {
-                   LOG(log_error, logtype_papd, "cq_printer: can't find default!" );
-                   exit( 1 );
-               }
-               return( CH_DONE );
-           }
-
-           for ( p = pdpsver->pd_value; *p != '\0'; p++ ) {
-               if ( *p == ' ' ) {
-                   break;
-               }
-           }
-           if ( *p == '\0' ) {
-               LOG(log_error, logtype_papd, "cq_printer: can't parse PSVersion!" );
-               if ( comswitch( queries, cq_default ) < 0 ) {
-                   LOG(log_error, logtype_papd, "cq_printer: can't find default!" );
-                   exit( 1 );
-               }
-               return( CH_DONE );
-           }
-
-           if (( pdprod = ppd_feature( prod, strlen( prod ))) == NULL ) {
-               if ( comswitch( queries, cq_default ) < 0 ) {
-                   LOG(log_error, logtype_papd, "cq_printer: can't find default!" );
-                   exit( 1 );
-               }
-               return( CH_DONE );
-           }
-
-           /* revision */
-           append( out, p + 1, strlen( p + 1 ));
-           append( out, "\r", 1 );
-
-           /* version */
-           append( out, pdpsver->pd_value, p - pdpsver->pd_value );
-           append( out, "\r", 1 );
-
-           /* product */
-           append( out, pdprod->pd_value, strlen( pdprod->pd_value ));
-           append( out, "\r", 1 );
-       } else {
-           if ( comcmp( start, start+linelength, comment->c_end, 0 ) == 0 ) {
-               compop();
-               CONSUME( in, linelength + crlflength );
-               return( CH_DONE );
-           }
-       }
-
-       CONSUME( in, linelength + crlflength );
-    }
-}
-
-#ifndef HAVE_CUPS
-
-static const char      *rmjobfailed = "Failed\n";
-static const char      *rmjobok = "Ok\n";
-
-int cq_rmjob( struct papfile *in, struct papfile *out)
-{
-    char               *start, *stop, *p;
-    int                        linelength, crlflength;
-    int                        job;
-
-    switch ( markline( in, &start, &linelength, &crlflength )) {
-    case 0 :
-       return( 0 );
-
-    case -1 :
-       return( CH_MORE );
-
-    case -2 :
-        return( CH_ERROR );
-    }
-
-    stop = start + linelength;
-
-    for ( p = start; p < stop; p++ ) {
-       if ( *p == ' ' || *p == '\t' ) {
-           break;
-       }
-    }
-    for ( ; p < stop; p++ ) {
-       if ( *p != ' ' && *p != '\t' ) {
-           break;
-       }
-    }
-
-    *stop = '\0';
-    if ( p < stop && ( job = atoi( p )) > 0 ) {
-       lp_rmjob( job );
-       append( out, rmjobok, strlen( rmjobok ));
-    } else {
-       append( out, rmjobfailed, strlen( rmjobfailed ));
-    }
-
-    compop();
-    CONSUME( in, linelength + crlflength );
-    return( CH_DONE );
-}
-
-int cq_listq( struct papfile *in, struct papfile *out)
-{
-    char               *start;
-    int                        linelength, crlflength;
-
-    switch ( markline( in, &start, &linelength, &crlflength )) {
-    case 0 :
-       return( 0 );
-
-    case -1 :
-       return( CH_MORE );
-
-    case -2 :
-        return( CH_ERROR );
-    }
-
-    if ( lp_queue( out )) {
-       LOG(log_error, logtype_papd, "cq_listq: lp_queue failed" );
-    }
-
-    compop();
-    CONSUME( in, linelength + crlflength );
-    return( CH_DONE );
-}
-#endif /* HAVE_CUPS */
-
-
-/*
- * Handler for RBILogin
- */
-
-static struct uam_obj *papd_uam = NULL;
-static const char *rbiloginok = "0\r";
-static const char *rbiloginbad = "-1\r";
-static const char *rbiloginerrstr = "%%[Error: SecurityError; \
-SecurityViolation: Unknown user, incorrect password or log on is \
-disabled ]%%\r%%[Flushing: rest of job (to end-of-file) will be \
-ignored ]%%\r";
-
-int cq_rbilogin( struct papfile *in, struct papfile *out)
-{
-    char               *start, *stop, *p, *begin;
-    int                        linelength, crlflength;
-    char               username[UAM_USERNAMELEN + 1] = "\0";
-    struct papd_comment        *comment = compeek();
-    char               uamtype[20];
-
-    for (;;) {
-        switch ( markline( in, &start, &linelength, &crlflength )) {
-        case 0 :
-            return( 0 );
-
-        case -1 :
-            return( CH_MORE );
-
-        case -2 :
-            return( CH_ERROR );
-        }
-
-       stop = start + linelength;
-
-        if ( comgetflags() == 0 ) { /* first line */
-           begin = start + strlen(comment->c_begin);
-           p = begin;
-
-           while (*p != ' ' && p < stop) {
-               p++;
-           }
-
-           memset(uamtype, 0, sizeof(uamtype));
-           if ((size_t)(p -begin) <= sizeof(uamtype) -1) {
-               strncpy(uamtype, begin, p - begin);
-            }
-
-           if ( !*uamtype || (papd_uam = auth_uamfind(UAM_SERVER_PRINTAUTH,
-                               uamtype, strlen(uamtype))) == NULL) {
-               LOG(log_info, logtype_papd, "Could not find uam: %s", uamtype);
-               append(out, rbiloginbad, strlen(rbiloginbad));
-               append(out, rbiloginerrstr, strlen(rbiloginerrstr));
-           } else {
-                if ( (papd_uam->u.uam_printer(p,stop,username,out)) == 0 ) {
-                    lp_person( username );
-                   append(out, rbiloginok, strlen( rbiloginok ));
-                   LOG(log_info, logtype_papd, "RBILogin: Logged in '%s'", username);
-                } else {
-                    append(out, rbiloginbad, strlen( rbiloginbad));
-                    append(out, rbiloginerrstr, strlen(rbiloginerrstr));
-                }
-           }
-            comsetflags( 1 );
-        } else {
-            if ( comcmp( start, stop, comment->c_end, 0 ) == 0 ) {
-                compop();
-                return( CH_DONE );
-            }
-        }
-
-        CONSUME( in, linelength + crlflength );
-    }
-}
-
-
-/*
- * All queries start with %%?Begin and end with %%?End.  Note that the
- * "Begin"/"End" general queries have to be last.
- */
-struct papd_comment    queries[] = {
-#ifdef KRB
-    { "%%Login: UMICHKerberosIV", NULL,                        cq_k4login,     0 },
-    { "%%?BeginUAMethodsQuery",        "%%?EndUAMethodsQuery:", cq_uameth,C_FULL },
-#endif /* KRB */
-#ifndef HAVE_CUPS
-    { "%UMICHListQueue",       NULL,                   cq_listq,  C_FULL },
-    { "%UMICHDeleteJob",       NULL,                   cq_rmjob,       0 },
-#endif /* HAVE_CUPS */
-    { "%%?BeginQuery: RBILogin ", "%%?EndQuery",       cq_rbilogin,    0 },
-    { "%%?BeginQuery",         "%%?EndQuery",          cq_query,       0 },
-    { "%%?BeginFeatureQuery",  "%%?EndFeatureQuery",   cq_feature,     0 },
-    { "%%?BeginFontQuery",     "%%?EndFontQuery",      cq_font,        0 },
-    { "%%?BeginPrinterQuery",  "%%?EndPrinterQuery",   cq_printer,C_FULL },
-    { "%%?Begin",              "%%?End",               cq_default,     0 },
-    { NULL,                    NULL,                   NULL,           0 },
-};
diff --git a/etc/papd/session.c b/etc/papd/session.c
deleted file mode 100644 (file)
index 7067f5f..0000000
+++ /dev/null
@@ -1,313 +0,0 @@
-/*
- * $Id: session.c,v 1.20 2009-10-16 01:10:59 didg Exp $
- *
- * Copyright (c) 1990,1994 Regents of The University of Michigan.
- * All Rights Reserved.  See COPYRIGHT.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#ifdef HAVE_SYS_ERRNO_H
-#include <sys/errno.h>
-#endif /* HAVE_SYS_ERRNO_H */
-#ifdef HAVE_ERRNO_H
-#include <errno.h>
-#endif /* HAVE_ERRNO_H */
-
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <atalk/logger.h>
-#include <sys/time.h>
-#include <sys/uio.h>
-#include <netatalk/endian.h>
-#include <netatalk/at.h>
-#include <atalk/atp.h>
-#include <atalk/pap.h>
-
-#include "file.h"
-#include "lp.h"
-#include "session.h"
-
-int ps(struct papfile *infile, struct papfile *outfile, struct sockaddr_at *sat);
-
-extern unsigned char   connid, quantum, oquantum;
-
-static char            buf[ PAP_MAXQUANTUM ][ 4 + PAP_MAXDATA ];
-static struct iovec    niov[ PAP_MAXQUANTUM ] = {
-    { buf[ 0 ],        0 },
-    { buf[ 1 ],        0 },
-    { buf[ 2 ],        0 },
-    { buf[ 3 ],        0 },
-    { buf[ 4 ],        0 },
-    { buf[ 5 ],        0 },
-    { buf[ 6 ],        0 },
-    { buf[ 7 ],        0 },
-};
-
-/*
- * Accept files until the client closes the connection.
- * Read lines of a file, until the client sends eof, after
- * which we'll send eof also.
- */
-int session(ATP atp, struct sockaddr_at *sat)
-{
-    struct timeval     tv;
-    struct atp_block   atpb;
-    struct sockaddr_at ssat;
-    struct papfile     infile, outfile;
-    fd_set             fds;
-    char               cbuf[ 578 ];
-    int                        i, cc, timeout = 0, readpending = 0;
-    u_int16_t          seq = 0, rseq = 1, netseq;
-    u_char             readport; /* uninitialized, OK 310105 */
-
-    infile.pf_state = PF_BOT;
-    infile.pf_bufsize = 0;
-    infile.pf_datalen = 0;
-    infile.pf_buf = NULL;
-    infile.pf_data = NULL;
-
-    outfile.pf_state = PF_BOT;
-    outfile.pf_bufsize = 0;
-    outfile.pf_datalen = 0;
-    outfile.pf_buf = NULL;
-    outfile.pf_data = NULL;
-
-    /*
-     * Ask for data.
-     */
-    cbuf[ 0 ] = connid;
-    cbuf[ 1 ] = PAP_READ;
-    if (++seq == 0) seq = 1;
-    netseq = htons( seq );
-    memcpy( &cbuf[ 2 ], &netseq, sizeof( netseq ));
-    atpb.atp_saddr = sat;
-    atpb.atp_sreqdata = cbuf;
-    atpb.atp_sreqdlen = 4;             /* bytes in SendData request */
-    atpb.atp_sreqto = 5;               /* retry timer */
-    atpb.atp_sreqtries = -1;           /* infinite retries */
-    if ( atp_sreq( atp, &atpb, oquantum, ATP_XO )) {
-       LOG(log_error, logtype_papd, "atp_sreq: %s", strerror(errno) );
-       return( -1 );
-    }
-
-    for (;;) {
-       /*
-        * Time between tickles.
-        */
-       tv.tv_sec = 60;
-       tv.tv_usec = 0;
-
-       /*
-        * If we don't get anything for a while, time out.
-        */
-       FD_ZERO( &fds );
-       FD_SET( atp_fileno( atp ), &fds );
-
-       do { /* do list until success or an unrecoverable error occurs */
-         if (( cc = select( FD_SETSIZE, &fds, NULL, NULL, &tv )) < 0 )
-             LOG(log_error, logtype_papd, "select: %s", strerror(errno) ); /* log all errors */
-       } while (( cc < 0 ) && (errno == 4));
-
-       if ( cc < 0 ) {
-         LOG(log_error, logtype_papd, "select: Error is unrecoverable" );
-         return( -1 );
-       }
-       if ( cc == 0 ) {
-           if ( timeout++ > 2 ) {
-               LOG(log_error, logtype_papd, "connection timed out" );
-               lp_cancel();
-               return( -1 );
-           }
-
-           /*
-            * Send a tickle.
-            */
-           cbuf[ 0 ] = connid;
-           cbuf[ 1 ] = PAP_TICKLE;
-           cbuf[ 2 ] = cbuf[ 3 ] = 0;
-           atpb.atp_saddr = sat;
-           atpb.atp_sreqdata = cbuf;
-           atpb.atp_sreqdlen = 4;              /* bytes in Tickle request */
-           atpb.atp_sreqto = 0;                /* best effort */
-           atpb.atp_sreqtries = 1;             /* try once */
-           if ( atp_sreq( atp, &atpb, 0, 0 )) {
-               LOG(log_error, logtype_papd, "atp_sreq: %s", strerror(errno) );
-               return( -1 );
-           }
-           continue;
-       } else {
-           timeout = 0;
-       }
-
-       memset( &ssat, 0, sizeof( struct sockaddr_at ));
-       switch( atp_rsel( atp, &ssat, ATP_TRESP | ATP_TREQ )) {
-       case ATP_TREQ :
-           atpb.atp_saddr = &ssat;
-           atpb.atp_rreqdata = cbuf;
-           atpb.atp_rreqdlen = sizeof( cbuf );
-           if ( atp_rreq( atp, &atpb ) < 0 ) {
-               LOG(log_error, logtype_papd, "atp_rreq: %s", strerror(errno) );
-               return( -1 );
-           }
-           /* sanity */
-           if ( (unsigned char)cbuf[ 0 ] != connid ) {
-               LOG(log_error, logtype_papd, "Bad ATP request!" );
-               continue;
-           }
-
-           switch( cbuf[ 1 ] ) {
-           case PAP_READ :
-               /*
-                * Other side is ready for some data.
-                */
-               memcpy( &netseq, &cbuf[ 2 ], sizeof( netseq ));
-               if ( netseq != 0 ) {
-                   if ( rseq != ntohs( netseq )) {
-                       break;
-                   }
-                   if ( rseq++ == 0xffff ) rseq = 1;
-               }
-               readpending = 1;
-               readport = ssat.sat_port;
-               break;
-
-           case PAP_CLOSE :
-               /*
-                * Respond to the close request.
-                * If we're in the middle of a file, clean up.
-                */
-               if (( infile.pf_state & PF_BOT ) ||
-                       ( infile.pf_datalen == 0 &&
-                       ( infile.pf_state & PF_EOF ))) {
-                   lp_print();
-               } else {
-                   lp_cancel();
-               }
-
-               niov[ 0 ].iov_len = 4;
-               ((char *)niov[ 0 ].iov_base)[ 0 ] = connid;
-               ((char *)niov[ 0 ].iov_base)[ 1 ] = PAP_CLOSEREPLY;
-               ((char *)niov[ 0 ].iov_base)[ 2 ] =
-                       ((char *)niov[ 0 ].iov_base)[ 3 ] = 0;
-               atpb.atp_sresiov = niov;
-               atpb.atp_sresiovcnt = 1;
-               if ( atp_sresp( atp, &atpb ) < 0 ) {
-                   LOG(log_error, logtype_papd, "atp_sresp: %s", strerror(errno) );
-                   exit( 1 );
-               }
-               return( 0 );
-               break;
-
-           case PAP_TICKLE :
-               break;
-           default :
-               LOG(log_error, logtype_papd, "Bad PAP request!" );
-           }
-
-           break;
-
-       case ATP_TRESP :
-           atpb.atp_saddr = &ssat;
-           for ( i = 0; i < oquantum; i++ ) {
-               niov[ i ].iov_len = PAP_MAXDATA + 4;
-           }
-           atpb.atp_rresiov = niov;
-           atpb.atp_rresiovcnt = oquantum;
-           if ( atp_rresp( atp, &atpb ) < 0 ) {
-               LOG(log_error, logtype_papd, "atp_rresp: %s", strerror(errno) );
-               return( -1 );
-           }
-
-           /* sanity */
-           if ( ((unsigned char *)niov[ 0 ].iov_base)[ 0 ] != connid ||
-                   ((char *)niov[ 0 ].iov_base)[ 1 ] != PAP_DATA ) {
-               LOG(log_error, logtype_papd, "Bad data response!" );
-               continue;
-           }
-
-           for ( i = 0; i < atpb.atp_rresiovcnt; i++ ) {
-               append( &infile,
-                       (char *)niov[ i ].iov_base + 4, niov[ i ].iov_len - 4 );
-               if (( infile.pf_state & PF_EOF ) == 0 &&
-                       ((char *)niov[ 0 ].iov_base)[ 2 ] ) {
-                   infile.pf_state |= PF_EOF;
-               }
-           }
-
-           /* move data */
-           if ( ps( &infile, &outfile, sat ) < 0 ) {
-               LOG(log_error, logtype_papd, "parse: bad return" );
-               return( -1 );   /* really?  close? */
-           }
-
-           /*
-            * Ask for more data.
-            */
-           cbuf[ 0 ] = connid;
-           cbuf[ 1 ] = PAP_READ;
-           if ( ++seq == 0 ) seq = 1;
-           netseq = htons( seq );
-           memcpy( &cbuf[ 2 ], &netseq, sizeof( netseq ));
-           atpb.atp_saddr = sat;
-           atpb.atp_sreqdata = cbuf;
-           atpb.atp_sreqdlen = 4;              /* bytes in SendData request */
-           atpb.atp_sreqto = 5;                /* retry timer */
-           atpb.atp_sreqtries = -1;            /* infinite retries */
-           if ( atp_sreq( atp, &atpb, oquantum, ATP_XO )) {
-               LOG(log_error, logtype_papd, "atp_sreq: %s", strerror(errno) );
-               return( -1 );
-           }
-           break;
-
-       case 0:
-           break;
-
-       default :
-           LOG(log_error, logtype_papd, "atp_rsel: %s", strerror(errno) );
-           return( -1 );
-       }
-
-       /* send any data that we have */
-       if ( readpending &&
-               ( outfile.pf_datalen || ( outfile.pf_state & PF_EOF ))) {
-           for ( i = 0; i < quantum; i++ ) {
-               ((char *)niov[ i ].iov_base)[ 0 ] = connid;
-               ((char *)niov[ i ].iov_base)[ 1 ] = PAP_DATA;
-               ((char *)niov[ i ].iov_base)[ 2 ] =
-                       ((char *)niov[ i ].iov_base)[ 3 ] = 0;
-
-               if ( outfile.pf_datalen > PAP_MAXDATA  ) {
-                   cc = PAP_MAXDATA;
-               } else {
-                   cc = outfile.pf_datalen;
-                   if ( outfile.pf_state & PF_EOF ) {
-                       ((char *)niov[ 0 ].iov_base)[ 2 ] = 1;  /* eof */
-                       outfile.pf_state = PF_BOT;
-                       infile.pf_state = PF_BOT;
-                   }
-               }
-
-               niov[ i ].iov_len = 4 + cc;
-               memcpy( (char *)niov[ i ].iov_base + 4, outfile.pf_data, cc );
-               CONSUME( &outfile, cc );
-               if ( outfile.pf_datalen == 0 ) {
-                   i++;
-                   break;
-               }
-           }
-           ssat.sat_port = readport;
-           atpb.atp_saddr = &ssat;
-           atpb.atp_sresiov = niov;
-           atpb.atp_sresiovcnt = i;    /* reported by stevebn@pc1.eos.co.uk */
-           if ( atp_sresp( atp, &atpb ) < 0 ) {
-               LOG(log_error, logtype_papd, "atp_sresp: %s", strerror(errno) );
-               return( -1 );
-           }
-           readpending = 0;
-       }
-    }
-}
diff --git a/etc/papd/session.h b/etc/papd/session.h
deleted file mode 100644 (file)
index 86e830f..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-/*
- * $Id: session.h,v 1.2 2001-06-25 20:13:45 rufustfirefly Exp $
- */
-
-#ifndef PAPD_SESSION_H
-#define PAPD_SESSION_H 1
-
-#include <atalk/atp.h>
-
-int session( ATP atp, struct sockaddr_at *sat );
-
-#endif /* PAPD_SESSION_H */
diff --git a/etc/papd/showppd.c b/etc/papd/showppd.c
deleted file mode 100644 (file)
index d023204..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * $Id: showppd.c,v 1.7 2009-10-13 22:55:37 didg Exp $
- *
- * Copyright (c) 1995 Regents of The University of Michigan.
- * All Rights Reserved.  See COPYRIGHT.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <atalk/logger.h>
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/time.h>
-#include <netatalk/at.h>
-#include <atalk/atp.h>
-
-#include "ppd.h"
-
-extern struct ppd_font         *ppd_fonts;
-
-extern struct ppd_feature      ppd_features[];
-
-
-int main(int ac, char **av)
-{
-    struct ppd_feature *pfe;
-    struct ppd_font    *pfo;
-
-    if ( ac != 2 ) {
-       fprintf( stderr, "Usage:\t%s ppdfile\n", av[ 0 ] );
-       exit( 1 );
-    }
-
-    read_ppd( av[ 1 ], 0 );
-    for ( pfo = ppd_fonts; pfo; pfo = pfo->pd_next ) {
-       printf( "Font: %s\n", pfo->pd_font );
-    }
-    for ( pfe = ppd_features; pfe->pd_name; pfe++ ) {
-       printf( "Feature: %s %s\n", pfe->pd_name, (pfe->pd_value)?pfe->pd_value:"NULL" );
-    }
-
-    exit ( 0 );
-}
diff --git a/etc/papd/uam.c b/etc/papd/uam.c
deleted file mode 100644 (file)
index 2962fad..0000000
+++ /dev/null
@@ -1,251 +0,0 @@
-/*
- * $Id: uam.c,v 1.11 2009-10-15 11:39:48 didg Exp $
- *
- * Copyright (c) 1999 Adrian Sun (asun@zoology.washington.edu)
- * All Rights Reserved.  See COPYRIGHT.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-/* STDC check */
-#if STDC_HEADERS
-#include <string.h>
-#else /* STDC_HEADERS */
-#ifndef HAVE_STRCHR
-#define strchr index
-#define strrchr index
-#endif /* HAVE_STRCHR */
-char *strchr (), *strrchr ();
-#ifndef HAVE_MEMCPY
-#define memcpy(d,s,n) bcopy ((s), (d), (n))
-#define memmove(d,s,n) bcopy ((s), (d), (n))
-#endif /* ! HAVE_MEMCPY */
-#endif /* STDC_HEADERS */
-
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
-#include <fcntl.h>
-#include <ctype.h>
-#include <atalk/logger.h>
-#include <sys/param.h>
-#include <sys/time.h>
-
-#include <netatalk/endian.h>
-#include <atalk/asp.h>
-#include <atalk/dsi.h>
-#include <atalk/afp.h>
-#include <atalk/util.h>
-
-#include "uam_auth.h"
-
-/* --- server uam functions -- */
-
-/* uam_load. uams must have a uam_setup function. */
-struct uam_mod *uam_load(const char *path, const char *name)
-{
-  char buf[MAXPATHLEN + 1], *p;
-  struct uam_mod *mod;
-  void *module;
-
-  if ((module = mod_open(path)) == NULL) {
-    LOG(log_error, logtype_papd, "uam_load(%s): failed to load: %s", name, mod_error());
-    return NULL;
-  }
-
-  if ((mod = (struct uam_mod *) malloc(sizeof(struct uam_mod))) == NULL) {
-    LOG(log_error, logtype_papd, "uam_load(%s): malloc failed", name);
-    goto uam_load_fail;
-  }
-
-  strlcpy(buf, name, sizeof(buf));
-  if ((p = strchr(buf, '.')))
-    *p = '\0';
-  if ((mod->uam_fcn = mod_symbol(module, buf)) == NULL) {
-    goto uam_load_err;
-  }
-
-  if (mod->uam_fcn->uam_type != UAM_MODULE_SERVER) {
-    LOG(log_error, logtype_papd, "uam_load(%s): attempted to load a non-server module",
-          name);
-    goto uam_load_err;
-  }
-
-  /* version check would go here */
-
-  if (!mod->uam_fcn->uam_setup || 
-      ((*mod->uam_fcn->uam_setup)(name) < 0)) {
-    LOG(log_error, logtype_papd, "uam_load(%s): uam_setup failed", name);
-    goto uam_load_err;
-  }
-
-  mod->uam_module = module;
-  return mod;
-
-uam_load_err:
-  free(mod);
-uam_load_fail:
-  mod_close(module);
-  return NULL;
-}
-
-/* unload the module. we check for a cleanup function, but we don't
- * die if one doesn't exist. however, things are likely to leak without one.
- */
-void uam_unload(struct uam_mod *mod)
-{
-  if (mod->uam_fcn->uam_cleanup)
-    (*mod->uam_fcn->uam_cleanup)();
-  mod_close(mod->uam_module);
-  free(mod);
-}
-
-/* -- client-side uam functions -- */
-
-/* set up stuff for this uam. */
-int uam_register(const int type, const char *path, const char *name, ...)
-{
-  va_list ap;
-  struct uam_obj *uam;
-  int ret;
-
-  if (!name)
-    return -1;
-
-  /* see if it already exists. */
-  if ((uam = auth_uamfind(type, name, strlen(name)))) {
-    if (strcmp(uam->uam_path, path)) {
-      /* it exists, but it's not the same module. */
-      LOG(log_error, logtype_papd, "uam_register: \"%s\" already loaded by %s",
-            name, path);
-      return -1;
-    }
-    uam->uam_count++;
-    return 0;
-  }
-  
-  /* allocate space for uam */
-  if ((uam = calloc(1, sizeof(struct uam_obj))) == NULL)
-    return -1;
-
-  uam->uam_name = name;
-  uam->uam_path = strdup(path);
-  uam->uam_count++;
-
-  va_start(ap, name);
-  switch (type) {
-  case UAM_SERVER_LOGIN: /* expect three arguments */
-    uam->u.uam_login.login = va_arg(ap, void *);
-    uam->u.uam_login.logincont = va_arg(ap, void *);
-    uam->u.uam_login.logout = va_arg(ap, void *);
-    break;
-  case UAM_SERVER_CHANGEPW: /* one argument */
-    uam->u.uam_changepw = va_arg(ap, void *);
-    break;
-  case UAM_SERVER_PRINTAUTH: /* x arguments */
-    uam->u.uam_printer = va_arg(ap, void *);
-    break;
-  default:
-    break;
-  }
-  va_end(ap);
-
-  /* attach to other uams */
-  ret = auth_register(type, uam);
-  if (ret) {
-    free(uam->uam_path);
-    free(uam);
-  }
-
-  return ret;
-}
-
-void uam_unregister(const int type, const char *name)
-{
-  struct uam_obj *uam;
-
-  if (!name)
-    return;
-
-  uam = auth_uamfind(type, name, strlen(name));
-  if (!uam || --uam->uam_count > 0)
-    return;
-
-  auth_unregister(uam);
-  free(uam->uam_path);
-  free(uam);
-}
-
-/* Crap to support uams which call this afpd function */
-int uam_afpserver_option(void *private _U_, const int what _U_, void *option _U_,
-                         size_t *len _U_)
-{
-       return(0);
-}
-
-/* --- helper functions for plugin uams --- */
-
-struct passwd *uam_getname(void *dummy _U_, char *name, const int len)
-{
-  struct passwd *pwent;
-  char *user;
-  int i;
-
-  if ((pwent = getpwnam(name)))
-    return pwent;
-
-#ifndef NO_REAL_USER_NAME
-  for (i = 0; i < len; i++)
-    name[i] = tolower(name[i]);
-
-  setpwent();
-  while ((pwent = getpwent())) {
-    if ((user = strchr(pwent->pw_gecos, ','))) *user = '\0';
-    user = pwent->pw_gecos;
-
-    /* check against both the gecos and the name fields. the user
-     * might have just used a different capitalization. */
-    if ((strncasecmp(user, name, len) == 0) ||
-        (strncasecmp(pwent->pw_name, name, len) == 0)) {
-      strncpy(name, pwent->pw_name, len);
-      break;
-    }
-  }
-  endpwent();
-#endif /* NO_REAL_USER_NAME */
-
-  /* os x server doesn't keep anything useful if we do getpwent */
-  return pwent ? getpwnam(name) : NULL;
-}
-
-
-int uam_checkuser(const struct passwd *pwd)
-{
-  char *p;
-
-  if (!pwd || !pwd->pw_shell || (*pwd->pw_shell == '\0')) 
-    return -1;
-
-  while ((p = getusershell())) {
-    if ( strcmp( p, pwd->pw_shell ) == 0 ) 
-      break;
-  }
-  endusershell();
-
-#ifndef DISABLE_SHELLCHECK
-  if (!p) {
-    LOG(log_info, logtype_papd, "illegal shell %s for %s",pwd->pw_shell,pwd->pw_name);
-    return -1;
-  }
-#endif /* DISABLE_SHELLCHECK */
-
-  return 0;
-}
-
-
diff --git a/etc/papd/uam_auth.h b/etc/papd/uam_auth.h
deleted file mode 100644 (file)
index 0cc9156..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * $Id: uam_auth.h,v 1.4 2009-10-13 22:55:37 didg Exp $
- *
- * Copyright (c) 1999 Adrian Sun (asun@zoology.washington.edu)
- * All Rights Reserved.  See COPYRIGHT.
- *
- * interface between uam.c and auth.c
- */
-
-#ifndef PAPD_UAM_AUTH_H
-#define PAPD_UAM_AUTH_H 1
-
-#include <sys/cdefs.h>
-#include <pwd.h>
-
-#include <atalk/uam.h>
-
-#include "file.h"
-
-struct uam_mod {
-  void *uam_module;
-  struct uam_export *uam_fcn;
-  struct uam_mod *uam_prev, *uam_next;
-};
-
-struct uam_obj {
-  const char *uam_name; /* authentication method */
-  char *uam_path; /* where it's located */
-  int uam_count;
-  union {
-    struct {
-      int (*login) (void *, struct passwd **, 
-                       char *, int, char *, int *);
-      int (*logincont) (void *, struct passwd **, char *,
-                           int, char *, int *);
-      void (*logout) (void);
-    } uam_login;
-    int (*uam_changepw) (void *, char *, struct passwd *, char *,
-                            int, char *, int *);
-    int (*uam_printer) (char *, char *, char *, struct papfile *);
-  } u;
-  struct uam_obj *uam_prev, *uam_next;
-};
-
-#define uam_attach(a, b) do { \
-    (a)->uam_prev->uam_next = (b); \
-    (b)->uam_prev = (a)->uam_prev; \
-    (b)->uam_next = (a); \
-    (a)->uam_prev = (b); \
-} while (0)                                 
-
-#define uam_detach(a) do { \
-    (a)->uam_prev->uam_next = (a)->uam_next; \
-    (a)->uam_next->uam_prev = (a)->uam_prev; \
-} while (0)
-
-#define UAM_LIST(type) (((type) == UAM_SERVER_LOGIN) ? &uam_login : \
-                (((type) == UAM_SERVER_CHANGEPW) ? &uam_changepw : \
-                (((type) == UAM_SERVER_PRINTAUTH) ? &uam_printer : NULL)))
-
-
-extern struct uam_mod *uam_load (const char *, const char *);
-extern void uam_unload (struct uam_mod *);
-
-/* auth.c */
-int auth_load (const char *, const char *);
-int auth_register (const int, struct uam_obj *);
-#define auth_unregister(a) uam_detach(a)
-struct uam_obj *auth_uamfind (const int, const char *, const int);
-void auth_unload (void);
-int getuamnames (const int, char *);
-
-#endif /* uam_auth.h */
diff --git a/etc/psf/.gitignore b/etc/psf/.gitignore
deleted file mode 100644 (file)
index 5138d27..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-Makefile
-Makefile.in
-psf
-psa
-.deps
-.libs
-.gitignore
-psa.o psf.o
diff --git a/etc/psf/Makefile.am b/etc/psf/Makefile.am
deleted file mode 100644 (file)
index 8cb795a..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-# Makefile.am for etc/psf/
-
-libexec_PROGRAMS = psf psa
-libexec_SCRIPTS = etc2ps.sh
-
-pkgdata_DATA = pagecount.ps
-
-psf_SOURCES = psf.c
-psa_SOURCES = psa.c
-
-AM_CFLAGS = -DZEROWIDTH \
-       -D_PATH_PAP=\"$(bindir)/pap\" \
-       -D_PATH_PSORDER=\"$(bindir)/psorder\" \
-       -D_PATH_PSA=\"$(libexecdir)/psa\" \
-       -D_PATH_PSFILTER=\"$(libexecdir)/etc2ps.sh\" \
-       -D_PATH_PAGECOUNT=\"$(pkgdatadir)/pagecount.ps\"
-
-EXTRA_DIST = $(libexec_SCRIPTS) $(pkgdata_DATA)
-
-# declare links
-psf_LINKS = ofpap ifpap tfpap ifpaprev tfpaprev ofwpap ifwpap \
-        tfwpap ifwpaprev tfwpaprev ofmpap ifmpap tfmpap ifmpaprev \
-        tfmpaprev ofwmpap ifwmpap tfwmpap ifwmpaprev tfwmpaprev
-
-
-#
-# install sections for links
-#
-
-install-exec-hook:
-       @list='$(psf_LINKS)'; for l in $$list; do \
-               rm $(DESTDIR)$(libexecdir)/$$l 2>/dev/null || true; \
-               (cd $(DESTDIR)$(libexecdir) && $(LN_S) psf $$l);  \
-       done
-
-#
-# uninstall sections for links
-#
-
-uninstall-hook:
-       @list='$(psf_LINKS)'; for l in $$list; do \
-               rm -f $(DESTDIR)$(libexecdir)/$$l; \
-       done
-
-#
-# cleanup
-#
-
-CLEANFILES = $(psf_LINKS)
diff --git a/etc/psf/etc2ps.sh b/etc/psf/etc2ps.sh
deleted file mode 100644 (file)
index 3f1637b..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-#!/bin/sh
-#
-# This filter is called by psf to convert "other" formats to PostScript.
-# psf handles text and PostScript native.  "Other" formats, e.g. DVI, C/A/T,
-# need to be converted before the page reverser and the printer can use
-# them.
-#
-# $0 begins with the filter name, e.g. df, tf.  Each format is a separate
-# tag in the case.
-#
-
-DVIPSPATH=/usr/local/tex/bin
-DVIPS=/usr/local/tex/bin/dvips
-DVIPSARGS="-f -q"
-
-TROFF2PS=/usr/local/psroff/troff2/troff2ps
-TROFF2PSARGS="-Z -O-.10"
-
-PATH=/usr/bin:$DVIPSPATH; export PATH
-
-case $1 in
-
-#
-# Use "dvips" by Radical Eye Software to convert TeX DVI files to PostScript.
-# Note that you *must* have METAFONT, etc, in your path.
-#
-df*)
-    if [ -x "$DVIPS" ]; then
-       TEMPFILE=`mktemp -t psfilter.XXXXXX` || exit 1
-       cat > $TEMPFILE
-       $DVIPS $DVIPSARGS < $TEMPFILE
-       rm -f $TEMPFILE
-    else
-       echo "$0: filter dvips uninstalled" 1>&2
-       exit 2
-    fi
-    ;;
-
-#
-# troff2ps is from psroff by Chris Lewis.
-#
-tf*)
-    if [ -x "$TROFF2PS" ]; then
-       exec $TROFF2PS $TROFF2PSARGS
-    else
-       echo "$0: filter troff2ps uninstalled" 1>&2
-       exit 2
-    fi
-    ;;
-
-*)
-    echo "$0: filter $1 unavailable" 1>&2
-    exit 2
-    ;;
-esac
-
-exit 0
diff --git a/etc/psf/pagecount.ps b/etc/psf/pagecount.ps
deleted file mode 100644 (file)
index fe650e1..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-%!PS-Adobe-3.0 Query
-%%?BeginQuery: PageCount
-statusdict begin pagecount (*) print = flush end
-%%?EndQuery: Unknown
-%%EOF
diff --git a/etc/psf/psa.c b/etc/psf/psa.c
deleted file mode 100644 (file)
index 2606a7c..0000000
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * $Id: psa.c,v 1.5 2009-10-13 22:55:37 didg Exp $
- *
- * Copyright (c) 1990,1995 Regents of The University of Michigan.
- * All Rights Reserved. See COPYRIGHT.
- *
- * PostScript Accounting, psa.
- *
- * psa is invoked by psf, as output for a communication program.  The
- * communication program is expected to send a small program before and
- * after each job, which causes the page count to be emitted in a well
- * known format.  psa reads its input, looking for page counts and other
- * interesting data.  Any data that it doesn't understand, it emits to
- * stderr, the lpd log file.  Data that it does understand may be written
- * to a status file or logged.  Once all input has been received, psa
- * subtracts the beginning and end page counts, and log an accounting
- * record in the accounting file.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-int main( int ac, char **av)
-{
-    FILE       *af;
-    char       *acc, *user, *host;
-    char       buf[ 1024 ], *p, *end;
-    int                cc, n, ipc = -1, fpc = -1;
-
-    if ( ac != 4 ) {
-       fprintf( stderr, "Usage:\t%s accounting-file user host\n", av[ 0 ] );
-       exit( 2 );
-    }
-
-    acc = av[ 1 ];
-    user = av[ 2 ];
-    host = av[ 3 ];
-
-    /*
-     * Explain n = !n ...  Is there no beauty in truth?
-     */
-    while (( cc = read( 0, buf, sizeof( buf ))) > 0 ) {
-       if ( ipc < 0 && *buf == '*' ) {
-           /* find initial pagecount */
-           for ( p = buf, end = buf + cc; p < end; p++ ) {
-               if ( *p == '\n' || *p == '\r' ) {
-                   break;
-               }
-           }
-           if ( p == end ) {
-               fprintf( stderr, "Can't find initial page count!\n" );
-               exit( 2 );
-           }
-
-           p++;
-           ipc = atoi( buf + 1 );
-           cc -= ( p - buf );
-           if ( cc != 0 ) {
-               bcopy( p, buf, cc );
-           }
-       } else {
-           /* find final pagecount */
-           for ( p = buf + cc - 1; p >= buf; p-- ) {
-               if ( *p != '\n' && *p != '\r' ) {
-                   break;
-               }
-           }
-           if ( p < buf ) {
-               fprintf( stderr, "Can't find final page count!\n" );
-               exit( 2 );
-           }
-
-           for ( ; p >= buf; p-- ) {
-               if ( *p == '\n' || *p == '\r' ) {
-                   break;
-               }
-           }
-
-           if ( p < buf ) {
-               p = buf;
-           } else {
-               cc -= p - buf;
-               p++;
-           }
-
-           if ( *p == '*' ) {
-               n = atoi( p + 1 );
-#define max(x,y)       ((x)>(y)?(x):(y))
-               fpc = max( n, fpc );
-           }
-       }
-       if ( cc != 0 && write( 2, buf, cc ) != cc ) {
-           fprintf( stderr, "write 1: 2 %p %d\n", buf, cc );
-           perror( "write" );
-           exit( 2 );
-       }
-    }
-    if ( cc < 0 ) {
-       perror( "read" );
-       exit( 2 );
-    }
-
-    if ( ipc < 0 ) {
-       fprintf( stderr, "Didn't find initial page count!\n" );
-       exit( 2 );
-    }
-
-    if ( fpc < 0 ) {
-       fprintf( stderr, "Didn't find final page count!\n" );
-       exit( 2 );
-    }
-
-    /*
-     * Write accounting record.
-     */
-    if (( af = fopen( acc, "a" )) != NULL ) {
-       fprintf( af, "%7.2f\t%s:%s\n", (float)( fpc - ipc ), host, user );
-    } else {
-       perror( acc );
-       exit( 2 );
-    }
-
-    exit( 0 );
-}
diff --git a/etc/psf/psf.c b/etc/psf/psf.c
deleted file mode 100644 (file)
index 535daee..0000000
+++ /dev/null
@@ -1,730 +0,0 @@
-/*
- * $Id: psf.c,v 1.13 2009-10-16 01:50:50 didg Exp $
- *
- * Copyright (c) 1990,1995 Regents of The University of Michigan.
- * All Rights Reserved. See COPYRIGHT.
- *
- * PostScript Filter, psf.
- *
- * Handles both PostScript files and text files.  Files with the
- * '%!' PostScript header are sent directly to the printer,
- * unmodified.  Text files are first converted to PostScript,
- * then sent.  Printers may be directly attached or on an AppleTalk
- * network.  Other media are possible.  Currently, psf invokes
- * pap to send files to AppleTalk-ed printers.  Replace the pap*
- * variables to use another program for communication.  psf only
- * converts plain-text.  If called as "tf" or "df", psf will invoke
- * a troff or dvi to PostScript converter.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#define FUCKED
-
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
-#include <sys/time.h>
-
-/* POSIX.1 sys/wait.h check */
-#include <sys/types.h>
-#ifdef HAVE_SYS_WAIT_H
-#include <sys/wait.h>
-#endif /* HAVE_SYS_WAIT_H */
-#ifndef WEXITSTATUS
-#define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
-#endif /* ! WEXITSTATUS */
-#ifndef WIFEXITED
-#define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
-#endif /* ! WIFEXITED */
-
-#include <sys/file.h>
-#include <syslog.h>
-#include <atalk/paths.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <signal.h>
-#include <errno.h>
-
-/* Forward Declarations */
-int pexecv(char *path, char *argv[]);
-int copyio();
-int textps();
-
-static char            psapath[] = _PATH_PSA;
-static char            *psaargv[] = { "psa", NULL, NULL, NULL, NULL };
-
-/*
- * If we're not doing accounting, we just call pap as below.
- * If we are doing accounting, we call pap twice.  The first time,
- * we call it with "-E" in arg 2, pagecount.ps in arg 3, and "-" in
- * arg 4.  The second time, we call it with "-c" in arg 2, pagecount.ps
- * in arg 3, and 0 in arg 4.
- */
-static char            pappath[] = _PATH_PAP;
-static char            *papargv[] = { "pap", "-sstatus", NULL, NULL, NULL, NULL, NULL, NULL };
-
-static char            revpath[] = _PATH_PSORDER;
-static char            *revargv[] = { "psorder", "-d", NULL };
-
-static char            *filtargv[] = { NULL, NULL, NULL };
-
-static char            inbuf[ 1024 * 8 ];
-static int             inlen;
-
-static int             literal;
-static int             width = 80, length = 66, indent = 0;
-static char            *prog, *name, *host;
-
-static struct papersize {
-    int                width;
-    int                length;
-   float       win;
-    float      lin;
-} papersizes[] = {
-    { 80, 66, 8.5, 11.0 },                     /* US Letter */
-    { 80, 70, 8.27, 11.69 },                   /* A4 */
-};
-
-int main( int ac, char **av)
-{
-    int                        c, rc, children = 0;
-#ifdef FUCKED
-    int                        psafileno = 0, multiconn = 0, waitidle = 0, waitidle2 = 0;
-#endif /* FUCKED */
-    int                        status;
-    extern char                *optarg;
-    extern int         optind, opterr;
-
-    opterr = 0;
-    if (( prog = rindex( av[ 0 ], '/' )) == NULL ) {
-       prog = av[ 0 ];
-    } else {
-       prog++;
-    }
-#ifdef ultrix
-    openlog( prog, LOG_PID );
-#else /* ultrix */
-    openlog( prog, LOG_PID, LOG_LPR );
-#endif /* ultrix */
-
-    while (( c = getopt( ac, av, "P:C:D:F:L:J:x:y:n:h:w:l:i:c" )) != EOF ) {
-       switch ( c ) {
-       case 'n' :
-           name = optarg;
-           break;
-
-       case 'h' :
-           host = optarg;
-           break;
-
-       case 'w' :
-           width = atoi( optarg );
-#ifdef ZEROWIDTH
-           /*
-            * Some version of lpd pass 0 for the page width.
-            */
-           if ( width == 0 ) {
-               width = 80;
-           }
-#endif /* ZEROWIDTH */
-           break;
-
-       case 'l' :
-           length = atoi( optarg );
-           break;
-
-       case 'i' :
-           indent = atoi( optarg );
-           break;
-
-       case 'c' :      /* Print control chars */
-           literal++;
-           break;
-
-       case 'F' :
-       case 'L' :
-       case 'J' :
-       case 'P' :
-       case 'x' :
-       case 'y' :
-           break;
-       
-#ifdef notdef
-       default :
-           syslog( LOG_ERR, "bad option: %c", c );
-           exit( 2 );
-#endif /* notdef */
-       }
-    }
-    if ( ac - optind > 1 ) {
-       syslog( LOG_ERR, "Too many arguments" );
-       exit( 2 );
-    }
-#ifdef FUCKED
-    if ( index( prog, 'w' )) {
-       waitidle++;
-    }
-    if ( index( prog, 'W' )) {
-       waitidle2++;
-    }
-    if ( index( prog, 'm' )) {
-       multiconn++;
-    }
-#endif /* FUCKED */
-
-    syslog( LOG_INFO, "starting for %s", name ? name : "?" );
-
-restart:
-    if (( inlen = read( 0, inbuf, sizeof( inbuf ))) < 0 ) {
-       syslog( LOG_ERR, "read: %s", strerror(errno) );
-       exit( 1 );
-    }
-    if ( inlen == 0 ) {        /* nothing to be done */
-       syslog( LOG_INFO, "done" );
-       exit( 0 );
-    }
-
-    /*
-     * If we've been given an accounting file, start the accounting
-     * process.
-     */
-    if ( optind < ac ) {
-       /* build arguments */
-       psaargv[ 1 ] = av[ optind ];
-       psaargv[ 2 ] = name;
-       psaargv[ 3 ] = host;
-       if (( c = pexecv( psapath, psaargv )) < 0 ) {
-           syslog( LOG_ERR, "%s: %s", psapath, strerror(errno) );
-           exit( 2 );
-       }
-       children++;
-       syslog( LOG_INFO, "accounting with psa[%d]", c );
-    }
-
-    /*
-     * Check prog's name to decide what programs to execute.
-     */
-    if ( strstr( prog, "pap" ) != NULL ) {
-       if ( optind < ac ) {    /* accounting */
-#ifdef FUCKED
-           if ( multiconn ) {
-               psafileno = getdtablesize();
-               psafileno--;
-               dup2( 1, psafileno );
-
-               if ( waitidle2 ) {
-                   papargv[ 2 ] = "-W";
-                   papargv[ 3 ] = "-c";
-                   papargv[ 4 ] = "-E";
-                   papargv[ 5 ] = _PATH_PAGECOUNT;
-                   papargv[ 6 ] = "-";
-                   papargv[ 7 ] = NULL;
-               } else if ( waitidle ) {
-                   papargv[ 2 ] = "-w";
-                   papargv[ 3 ] = "-c";
-                   papargv[ 4 ] = "-E";
-                   papargv[ 5 ] = _PATH_PAGECOUNT;
-                   papargv[ 6 ] = "-";
-                   papargv[ 7 ] = NULL;
-               } else {
-                   papargv[ 2 ] = "-c";
-                   papargv[ 3 ] = "-E";
-                   papargv[ 4 ] = _PATH_PAGECOUNT;
-                   papargv[ 5 ] = "-";
-                   papargv[ 6 ] = NULL;
-               }
-           } else {
-               /*
-                * This is how it should be done.
-                */
-               papargv[ 2 ] = "-c";
-               papargv[ 3 ] = _PATH_PAGECOUNT;
-               papargv[ 4 ] = "-";
-               papargv[ 5 ] = _PATH_PAGECOUNT;
-               papargv[ 6 ] = NULL;
-           }
-#endif /* FUCKED */
-       } else {
-           papargv[ 2 ] = "-c";
-           papargv[ 3 ] = "-E";
-           papargv[ 4 ] = NULL;
-       }
-
-       if (( c = pexecv( pappath, papargv )) < 0 ) {
-           syslog( LOG_ERR, "%s: %s", pappath, strerror(errno) );
-           exit( 2 );
-       }
-       children++;
-       syslog( LOG_INFO, "sending to pap[%d]", c );
-    }
-
-    /*
-     * Might be a good idea to have both a "forw" and a "rev", so that
-     * reversed documents can be reordered for the printing device.
-     */
-    if ( strstr( prog, "rev" ) != NULL ) {
-       if (( c = pexecv( revpath, revargv )) < 0 ) {
-           syslog( LOG_ERR, "%s: %s", revpath, strerror(errno) );
-           exit( 2 );
-       }
-       syslog( LOG_INFO, "sending to rev[%d]", c );
-       children++;
-    }
-
-    /*
-     * Invoke an external (script) filter to produce PostScript from
-     * non-text input.
-     */
-    if ( *prog != 'i' && *prog != 'o' && *( prog + 1 ) == 'f' ) {
-       filtargv[ 0 ] = filtargv[ 1 ] = prog;
-       if (( c = pexecv( _PATH_PSFILTER, filtargv )) < 0 ) {
-           syslog( LOG_ERR, "%s: %s", _PATH_PSFILTER, strerror(errno) );
-           exit( 2 );
-       }
-       syslog( LOG_INFO, "external filter[%d]", c );
-       children++;
-       rc = copyio();          /* external filter */
-    } else {
-       if ( inlen >= 2 && inbuf[ 0 ] == '%' && inbuf[ 1 ] == '!' ) {
-           syslog( LOG_INFO, "PostScript" );
-           rc = copyio();      /* PostScript */
-       } else if ( inlen >= 2 && inbuf[ 0 ] == '\033' && inbuf[ 1 ] == '%' ) {
-           syslog( LOG_INFO, "PostScript w/PJL" );
-           rc = copyio();      /* PostScript */
-       } else {
-           syslog( LOG_INFO, "straight text" );
-           rc = textps();      /* straight text */
-       }
-    }
-
-#ifdef FUCKED
-    if ( strstr( prog, "pap" ) != NULL && optind < ac && multiconn ) {
-       dup2( psafileno, 1 );
-       close( psafileno );
-       papargv[ 2 ] = "-c";
-       if ( waitidle2 ) {
-           papargv[ 3 ] = "-W";
-           papargv[ 4 ] = _PATH_PAGECOUNT;
-           papargv[ 5 ] = NULL;
-       } else if ( waitidle ) {
-           papargv[ 3 ] = "-w";
-           papargv[ 4 ] = _PATH_PAGECOUNT;
-           papargv[ 5 ] = NULL;
-       } else {
-           papargv[ 3 ] = _PATH_PAGECOUNT;
-           papargv[ 4 ] = NULL;
-       }
-
-       if (( c = pexecv( pappath, papargv )) < 0 ) {
-           syslog( LOG_ERR, "%s: %s", pappath, strerror(errno) );
-           exit( 2 );
-       }
-       children++;
-       syslog( LOG_INFO, "pagecount with pap[%d]", c );
-    }
-#endif /* FUCKED */
-
-    if ( children ) {
-       close( 1 );
-    }
-    while ( children ) {
-       if (( c = wait3( &status, 0, NULL )) < 0 ) {
-           syslog( LOG_ERR, "wait3: %s", strerror(errno) );
-           exit( 1 );
-       }
-       if ( WIFEXITED( status )) {
-#ifndef WEXITSTATUS
-#define WEXITSTATUS(x) ((x).w_status)
-#endif /* WEXITSTATUS */
-           if ( WEXITSTATUS( status ) != 0 ) {
-               syslog( LOG_ERR, "%d died with %d", c, WEXITSTATUS( status ));
-               exit( WEXITSTATUS( status ));
-           } else {
-               syslog( LOG_INFO, "%d done", c );
-               children--;
-           }
-       } else {
-           syslog( LOG_ERR, "%d died badly", c );
-           exit( 1 );
-       }
-    }
-
-    if ( rc == 3 ) {
-       syslog( LOG_INFO, "pausing" );
-       kill( getpid(), SIGSTOP );
-       syslog( LOG_INFO, "restarting" );
-       goto restart;
-    }
-
-    syslog( LOG_INFO, "done" );
-    exit( rc );
-}
-
-int copyio(void)
-{
-    /* implement the FSM needed to do the suspend. Note that
-     * the last characters will be \031\001 so don't worry
-     * Fun things: 1. \031\001 should not be written to output device
-     *  2. The \031 can be last char of one read, \001 first of next
-     *      - we need to write \031 if not followed by \001
-     */
-    struct timeval     tv;
-    fd_set             fdset;
-    int                        ctl = 0;
-
-notdone:
-    do {
-       /*
-        * First, \031 and \001 *must* be the last things in the buffer
-        * (\001 can be the first thing in the next buffer).  There's no
-        * need to scan any of the intervening bytes.  Second, if there's
-        * more input, the escape sequence was bogus, and we should keep
-        * reading.
-        */
-       if ( inlen == 1 ) {
-           if ( ctl == 1 ) {
-               if ( inbuf[ 0 ] == '\001' ) {
-                   ctl = 2;
-                   break;
-               }
-               if ( write( 1, "\031", 1 ) != 1 ) {
-                   syslog( LOG_ERR, "write: %s", strerror(errno) );
-                   return( 1 );
-               }
-               ctl = 0;
-           }
-
-           if ( inbuf[ 0 ] == '\031' ) {
-               ctl = 1;
-           }
-
-       } else {
-           if ( ctl == 1 ) {
-               if ( write( 1, "\031", 1 ) != 1 ) {
-                   syslog( LOG_ERR, "write: %s", strerror(errno) );
-                   return( 1 );
-               }
-           }
-           ctl = 0;
-           if ( inbuf[ inlen - 2 ] == '\031' &&
-                   inbuf[ inlen - 1 ] == '\001' ) {
-               ctl = 2;
-           } else if ( inbuf[ inlen - 1 ] == '\031' ) {
-               ctl = 1;
-           }
-       }
-
-       inlen -= ctl;
-       if (( inlen > 0 ) && ( write( 1, inbuf, inlen ) != inlen )) {
-           syslog( LOG_ERR, "write: %s", strerror(errno) );
-           return( 1 );
-       }
-       if ( ctl == 2 ) {
-           break;
-       }
-    } while (( inlen = read( 0, inbuf, sizeof( inbuf ))) > 0 );
-
-    if ( ctl == 2 ) {
-       tv.tv_sec = 2;
-       tv.tv_usec = 0;
-       FD_ZERO( &fdset );
-       FD_SET( 0, &fdset );
-       if ( select( 1, &fdset, NULL, NULL, &tv ) != 0 ) {
-           if (( inlen = read( 0, inbuf, sizeof( inbuf ))) > 0 ) {
-               goto notdone;
-           }
-       }
-    }
-
-    if ( inlen < 0 ) {
-       syslog( LOG_ERR, "read: %s", strerror(errno) );
-       return( 1 );
-    }
-
-    if ( ctl == 1 ) {
-       if ( write( 1, "\031", 1 ) != 1 ) {
-           syslog( LOG_ERR, "write: %s", strerror(errno) );
-           return( 1 );
-       }
-    } else if ( ctl == 2 ) {
-       return( 3 );
-    }
-    return( 0 );
-}
-
-static char            *font = "Courier";
-static int             point = 11;
-
-static char            pspro[] = "\
-/GSV save def                                          % global VM\n\
-/SP {\n\
-       /SV save def                                    % save vmstate\n\
-       dup /H exch def                                 % save font height\n\
-       exch findfont exch scalefont setfont            % select font\n\
-       ( ) stringwidth pop /W exch def                 % save font width\n\
-       0.5 sub 72 mul /CY exch def                     % save start Y\n\
-       pop 0.5 add 72 mul /CX exch def                 % save start X\n\
-       CX CY moveto                                    % make current point\n\
-} bind def\n\
-/S /show load def\n\
-/NL { CX CY H sub dup /CY exch def moveto } bind def\n\
-/CR { CX CY moveto } bind def\n\
-/B { W neg 0 rmoveto}bind def\n\
-/T { W mul 0 rmoveto}bind def\n\
-/EP { SV restore showpage } bind def\n\
-%%EndProlog\n";
-
-int textps(void)
-{
-    struct papersize   papersize;
-    int                        state = 0, line = 0, col = 0, npages = 0, rc;
-    unsigned int       i;
-    char               *p, *end;
-
-#define elements(x)    (sizeof(x)/sizeof((x)[0]))
-    for ( i = 0; i < elements( papersizes ); i++ ) {
-       if ( width == papersizes[ 0 ].width &&
-               length == papersizes[ 0 ].length ) {
-           papersize = papersizes[ i ];
-           break;
-       }
-    }
-    if ( i >= elements( papersizes )) {
-       papersize = papersizes[ 0 ];            /* default */
-    }
-
-#define ST_AVAIL               (1<<0)
-#define ST_CONTROL             (1<<1)
-#define ST_PAGE                        (1<<2)
-    /*
-     * convert text lines to postscript.
-     * A grungy little state machine. If I was more creative, I could
-     * probably think of a better way of doing this...
-     */
-    do {
-       p = inbuf;
-       end = inbuf + inlen;
-       while ( p < end ) {
-           if (( state & ST_PAGE ) == 0 && *p != '\031' && *p != '\001' ) {
-               if ( npages == 0 ) {
-                   printf( "%%!PS-Adobe-2.0\n%%%%Pages: (atend)\n" );
-                   printf( "%%%%DocumentFonts: %s\n", font );
-                   fflush( stdout );
-
-                   /* output postscript prologue: */
-                   if ( write( 1, pspro, sizeof( pspro ) - 1 ) !=
-                           sizeof( pspro ) - 1 ) {
-                       syslog( LOG_ERR, "write prologue: %s", strerror(errno) );
-                       return( 1 );
-                   }
-                   if ( name && host ) {
-                       printf( "statusdict /jobname (%s@%s) put\n", name,
-                               host );
-                   }
-               }
-
-               printf( "%%%%Page: ? %d\n", ++npages );
-               printf( "%d %f %f /%s %d SP\n", indent,
-                       papersize.win, papersize.lin, font, point );
-               state |= ST_PAGE;
-           }
-           if ( state & ST_CONTROL && *p != '\001' ) {
-               /* It is a very bad thing to toss a job because it contains
-                * unprintable characters.  Instead, we will convert them to
-                * question marks.  This is adapted from a solution described
-                * by Werner Eugster <eugster@giub.unibe.ch> on his ApplePrint
-                * webpage (http://www.giub.unibe.ch/~eugster/appleprint.html).
-                *
-                * Note that this is rather ugly code.  The same change is
-                * applied identically at two different locations in this file.
-                * It would be better someday to combine the two.
-                */
-               if ( !literal ) {
-                       fprintf( stderr,
-                               "unprintable character (0x%x) converted to ?!\n",
-                               (unsigned char)*p );
-                       putchar( '?' ); /* Replace unprintable char with a question mark. */
-               } else {
-                       printf( "\\%o", (unsigned char)031 );
-               }
-               state &= ~ST_CONTROL;
-               col++;
-           }
-
-           switch ( *p ) {
-           case '\n' :         /* end of line */
-               if ( state & ST_AVAIL ) {
-                   printf( ")S\n" );
-                   state &= ~ST_AVAIL;
-               }
-               printf( "NL\n" );
-               line++;
-               col = 0;
-               if ( line >= length ) {
-                   printf( "EP\n" );
-                   state &= ~ST_PAGE;
-                   line = 0;
-               }
-               break;
-
-           case '\r' :         /* carriage return (for overtyping) */
-               if ( state & ST_AVAIL ) {
-                   printf( ")S CR\n" );
-                   state &= ~ST_AVAIL;
-               }
-               col = 0;
-               break;
-
-           case '\f' :         /* form feed */
-               if ( state & ST_AVAIL ) {
-                   printf( ")S\n" );
-                   state &= ~ST_AVAIL;
-               }
-               printf( "EP\n" );
-               state &= ~ST_PAGE;
-               line = 0;
-               col = 0;
-               break;
-
-           case '\b' :         /* backspace */
-               /* show line, back up one character */
-               if ( state & ST_AVAIL ) {
-                   printf( ")S\n" );
-                   state &= ~ST_AVAIL;
-               }
-               printf( "B\n" );
-               col--;
-               break;
-
-           case '\t' :         /* tab */
-               if ( state & ST_AVAIL ) {
-                   printf( ")S\n" );
-                   state &= ~ST_AVAIL;
-               }
-               printf( "%d T\n", 8 - ( col % 8 ));
-               col += 8 - ( col % 8 );
-               break;
-
-           /*
-            * beginning of lpr control sequence
-            */
-           case '\031' :
-               state |= ST_CONTROL;
-               break;
-
-           case '\001' :       /* lpr control sequence */
-               if ( state & ST_CONTROL ) {
-                   rc = 3;
-                   goto out;
-               }
-               /* FALLTHROUGH */
-
-           case '\\' :
-           case ')' :
-           case '(' :
-               if (( state & ST_AVAIL ) == 0 ) {
-                   printf( "(" );
-                   state |= ST_AVAIL;
-               }
-               putchar( '\\' );
-               /* FALLTHROUGH */
-
-           default :
-               if (( state & ST_AVAIL ) == 0 ) {
-                   printf( "(" );
-                   state |= ST_AVAIL;
-               }
-               if ( !isascii( *p ) || !isprint( *p )) {
-                   if ( !literal ) {
-                        fprintf( stderr,
-                           "unprintable character (0x%x) converted to ?!\n",
-                           (unsigned char)*p );
-                       putchar( '?' ); /* Replace unprintable char with a question mark. */
-                   } else {
-                       printf( "\\%o", (unsigned char)*p );
-                   }
-               } else {
-                   putchar( *p );
-               }
-               col++;
-               break;
-           }
-       p++;
-       }
-    } while (( inlen = read( 0, inbuf, sizeof( inbuf ))) > 0 );
-    if ( inlen < 0 ) {
-       syslog( LOG_ERR, "read: %s", strerror(errno) );
-       return( 1 );
-    }
-    rc = 0;
-
-out:
-    if ( state & ST_AVAIL ) {
-       printf( ")S\n" );
-       state &= ~ST_AVAIL;
-    }
-
-    if ( state & ST_PAGE ) {
-       printf( "EP\n" );
-       state &= ~ST_PAGE;
-    }
-
-    if ( npages > 0 ) {
-       printf( "%%%%Trailer\nGSV restore\n%%%%Pages: %d\n%%%%EOF\n", npages );
-       fflush( stdout );
-    }
-
-    return( rc );
-}
-
-/*
- * Interface to pipe and exec, for starting children in pipelines.
- *
- * Manipulates file descriptors 0, 1, and 2, such that the new child
- * is reading from the parent's output.
- */
-int pexecv( char *path, char *argv[])
-{
-    int                fd[ 2 ], c;
-
-    if ( pipe( fd ) < 0 ) {
-       return( -1 );
-    }
-
-    switch ( c = fork()) {
-    case -1 :
-       return( -1 );
-       /* NOTREACHED */
-
-    case 0 :
-       if ( close( fd[ 1 ] ) < 0 ) {
-           return( -1 );
-       }
-       if ( dup2( fd[ 0 ], 0 ) < 0 ) {
-           return( -1 );
-       }
-       if ( close( fd[ 0 ] ) < 0 ) {
-           return( -1 );
-       }
-       execv( path, argv );
-       return( -1 );
-       /* NOTREACHED */
-
-    default :
-       if ( close( fd[ 0 ] ) < 0 ) {
-           return( -1 );
-       }
-       if ( dup2( fd[ 1 ], 1 ) < 0 ) {
-           return( -1 );
-       }
-       if ( close( fd[ 1 ] ) < 0 ) {
-           return( -1 );
-       }
-       return( c );
-    }
-}
index dbe304ab9f8668334dc03b1286aa0c9465f7b575..499649e756e84e20151cc604325e1271cf8ca384 100644 (file)
@@ -1,7 +1,5 @@
 # Makefile.am for etc/uams/
 
-SUBDIRS = uams_krb4
-
 #
 # conditionally build some modules
 #
index 4c66a8732771f0a1803e285e0d726a8733ca9e64..0f0c8a535329b579bac63659a88b41194f481b59 100644 (file)
@@ -46,7 +46,7 @@ static gcry_mpi_t p, g, Ra;
 static gcry_mpi_t serverNonce;
 static char *K_MD5hash = NULL;
 static int K_hash_len;
-static u_int16_t ID;
+static uint16_t ID;
 
 /* The initialization vectors for CAST128 are fixed by Apple. */
 static unsigned char dhx_c2siv[] = { 'L', 'W', 'a', 'l', 'l', 'a', 'c', 'e' };
@@ -267,7 +267,7 @@ static int dhx2_setup(void *obj, char *ibuf _U_, size_t ibuflen _U_,
 
     /* Session ID first */
     ID = dhxhash(obj);
-    *(u_int16_t *)rbuf = htons(ID);
+    *(uint16_t *)rbuf = htons(ID);
     rbuf += 2;
     *rbuflen += 2;
 
@@ -281,7 +281,7 @@ static int dhx2_setup(void *obj, char *ibuf _U_, size_t ibuflen _U_,
     *rbuflen += 4;
 
     /* len = length of p = PRIMEBITS/8 */
-    *(u_int16_t *)rbuf = htons((u_int16_t) PRIMEBITS/8);
+    *(uint16_t *)rbuf = htons((uint16_t) PRIMEBITS/8);
     rbuf += 2;
     *rbuflen += 2;
 
@@ -365,7 +365,7 @@ static int pam_login_ext(void *obj, char *uname, struct passwd **uam_pwd,
 {
     char *username;
     size_t len, ulen;
-    u_int16_t  temp16;
+    uint16_t  temp16;
 
     *rbuflen = 0;
 
@@ -488,7 +488,7 @@ static int logincont1(void *obj _U_, char *ibuf, size_t ibuflen, char *rbuf, siz
     /* ---- Start building reply packet ---- */
 
     /* Session ID + 1 first */
-    *(u_int16_t *)rbuf = htons(ID+1);
+    *(uint16_t *)rbuf = htons(ID+1);
     rbuf += 2;
     *rbuflen += 2;
 
@@ -714,11 +714,11 @@ static int pam_logincont(void *obj, struct passwd **uam_pwd,
                          char *ibuf, size_t ibuflen,
                          char *rbuf, size_t *rbuflen)
 {
-    u_int16_t retID;
+    uint16_t retID;
     int ret;
 
     /* check for session id */
-    retID = ntohs(*(u_int16_t *)ibuf);
+    retID = ntohs(*(uint16_t *)ibuf);
     if (retID == ID)
         ret = logincont1(obj, ibuf, ibuflen, rbuf, rbuflen);
     else if (retID == ID+1)
index 1392f0a75edfc2d513a3c65365795625cd0c0fb0..8d31b9f845b3502eb4935d38a0df5cf6635cfac2 100644 (file)
 #include <string.h>
 #include <errno.h>
 #include <pwd.h>
-
-#ifdef HAVE_UNISTD_H
+#include <arpa/inet.h>
 #include <unistd.h>
-#endif
 
 #ifdef HAVE_CRYPT_H
 #include <crypt.h>
 #endif
 
-#ifdef HAVE_SYS_TIME_H
 #include <sys/time.h>
-#endif
-
-#ifdef HAVE_TIME_H
 #include <time.h>
-#endif
 
 #ifdef SHADOWPW
 #include <shadow.h>
@@ -60,7 +53,7 @@ static gcry_mpi_t p, Ra;
 static gcry_mpi_t serverNonce;
 static char *K_MD5hash = NULL;
 static int K_hash_len;
-static u_int16_t ID;
+static uint16_t ID;
 
 /* The initialization vectors for CAST128 are fixed by Apple. */
 static unsigned char dhx_c2siv[] = { 'L', 'W', 'a', 'l', 'l', 'a', 'c', 'e' };
@@ -216,7 +209,7 @@ static int dhx2_setup(void *obj, char *ibuf _U_, size_t ibuflen _U_,
 
     /* Session ID first */
     ID = dhxhash(obj);
-    *(u_int16_t *)rbuf = htons(ID);
+    *(uint16_t *)rbuf = htons(ID);
     rbuf += 2;
     *rbuflen += 2;
 
@@ -230,7 +223,7 @@ static int dhx2_setup(void *obj, char *ibuf _U_, size_t ibuflen _U_,
     *rbuflen += 4;
 
     /* len = length of p = PRIMEBITS/8 */
-    *(u_int16_t *)rbuf = htons((u_int16_t) PRIMEBITS/8);
+    *(uint16_t *)rbuf = htons((uint16_t) PRIMEBITS/8);
     rbuf += 2;
     *rbuflen += 2;
 
@@ -314,7 +307,7 @@ static int passwd_login_ext(void *obj, char *uname, struct passwd **uam_pwd,
 {
     char *username;
     size_t len, ulen;
-    u_int16_t  temp16;
+    uint16_t  temp16;
 
     *rbuflen = 0;
 
@@ -442,7 +435,7 @@ static int logincont1(void *obj _U_, struct passwd **uam_pwd _U_,
     /* ---- Start building reply packet ---- */
 
     /* Session ID + 1 first */
-    *(u_int16_t *)rbuf = htons(ID+1);
+    *(uint16_t *)rbuf = htons(ID+1);
     rbuf += 2;
     *rbuflen += 2;
 
@@ -589,11 +582,11 @@ static int passwd_logincont(void *obj, struct passwd **uam_pwd,
                             char *ibuf, size_t ibuflen,
                             char *rbuf, size_t *rbuflen)
 {
-    u_int16_t retID;
+    uint16_t retID;
     int ret;
 
     /* check for session id */
-    retID = ntohs(*(u_int16_t *)ibuf);
+    retID = ntohs(*(uint16_t *)ibuf);
     if (retID == ID)
         ret = logincont1(obj, uam_pwd, ibuf, ibuflen, rbuf, rbuflen);
     else if (retID == ID+1)
index e9f30dc1cd6e5af77f252f37589aa27ce83ebbb1..7bad2fa0472ef3a833ca6792c28327158014ac3c 100644 (file)
@@ -26,7 +26,7 @@
 #ifdef HAVE_PAM_PAM_APPL_H
 #include <pam/pam_appl.h>
 #endif
-
+#include <arpa/inet.h>
 
 #if defined(GNUTLS_DHX)
 #include <gnutls/openssl.h>
 /* the secret key */
 static CAST_KEY castkey;
 static struct passwd *dhxpwd;
-static u_int8_t randbuf[KEYSIZE];
+static uint8_t randbuf[KEYSIZE];
 
 /* diffie-hellman bits */
 static unsigned char msg2_iv[] = "CJalbert";
 static unsigned char msg3_iv[] = "LWallace";
-static const u_int8_t p[] = {0xBA, 0x28, 0x73, 0xDF, 0xB0, 0x60, 0x57, 0xD4,
+static const uint8_t p[] = {0xBA, 0x28, 0x73, 0xDF, 0xB0, 0x60, 0x57, 0xD4,
                             0x3F, 0x20, 0x24, 0x74, 0x4C, 0xEE, 0xE7, 0x5B};
-static const u_int8_t g = 0x07;
+static const uint8_t g = 0x07;
 
 
 /* Static variables used to communicate between the conversation function
@@ -187,7 +187,7 @@ static struct pam_conv PAM_conversation = {
 static int dhx_setup(void *obj, char *ibuf, size_t ibuflen _U_, 
                     char *rbuf, size_t *rbuflen)
 {
-    u_int16_t sessid;
+    uint16_t sessid;
     size_t i;
     BIGNUM *bn, *gbn, *pbn;
     DH *dh;
@@ -375,8 +375,9 @@ static int pam_login_ext(void *obj, char *uname, struct passwd **uam_pwd,
                     char *rbuf, size_t *rbuflen)
 {
     char *username;
-    int len, ulen;
-    u_int16_t  temp16;
+    int len;
+    size_t ulen;
+    uint16_t  temp16;
 
     *rbuflen = 0;
 
@@ -412,7 +413,7 @@ static int pam_logincont(void *obj, struct passwd **uam_pwd,
 {
     const char *hostname;
     BIGNUM *bn1, *bn2, *bn3;
-    u_int16_t sessid;
+    uint16_t sessid;
     int err, PAM_error;
 
     *rbuflen = 0;
@@ -572,7 +573,7 @@ static int pam_changepw(void *obj, char *username,
     char *hostname;
     pam_handle_t *lpamh;
     uid_t uid;
-    u_int16_t sessid;
+    uint16_t sessid;
     int PAM_error;
 
     if (ibuflen < sizeof(sessid)) {
index 465f28972e6b9eec0ceaf0468f41c9582b25bce6..d390f76b4da29d556fb07bdf559849e3610e9362 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: uams_dhx_passwd.c,v 1.29 2010-03-30 12:44:35 franklahm Exp $
- *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * Copyright (c) 1999 Adrian Sun (asun@u.washington.edu) 
  * All Rights Reserved.  See COPYRIGHT.
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#ifdef HAVE_UNISTD_H
 #include <unistd.h>
-#endif /* HAVE_UNISTD_H */
 #ifdef HAVE_CRYPT_H
 #include <crypt.h>
 #endif /* ! HAVE_CRYPT_H */
-#ifdef HAVE_SYS_TIME_H
 #include <sys/time.h>
-#endif
-#ifdef HAVE_TIME_H
 #include <time.h>
-#endif
 #include <pwd.h>
+#include <arpa/inet.h>
+
 #ifdef SHADOWPW
 #include <shadow.h>
 #endif /* SHADOWPW */
+
 #if defined(GNUTLS_DHX)
 #include <gnutls/openssl.h>
 #elif defined(OPENSSL_DHX)
@@ -59,7 +54,7 @@
 /* the secret key */
 static CAST_KEY castkey;
 static struct passwd *dhxpwd;
-static u_int8_t randbuf[16];
+static uint8_t randbuf[16];
 
 #ifdef TRU64
 #include <sia.h>
@@ -74,14 +69,14 @@ static int pwd_login(void *obj, char *username, int ulen, struct passwd **uam_pw
                        char *rbuf, size_t *rbuflen)
 {
     unsigned char iv[] = "CJalbert";
-    u_int8_t p[] = {0xBA, 0x28, 0x73, 0xDF, 0xB0, 0x60, 0x57, 0xD4,
+    uint8_t p[] = {0xBA, 0x28, 0x73, 0xDF, 0xB0, 0x60, 0x57, 0xD4,
                    0x3F, 0x20, 0x24, 0x74, 0x4C, 0xEE, 0xE7, 0x5B };
-    u_int8_t g = 0x07;
+    uint8_t g = 0x07;
 #ifdef SHADOWPW
     struct spwd *sp;
 #endif /* SHADOWPW */
     BIGNUM *bn, *gbn, *pbn;
-    u_int16_t sessid;
+    uint16_t sessid;
     size_t i;
     DH *dh;
 
@@ -250,7 +245,7 @@ static int passwd_login_ext(void *obj, char *uname, struct passwd **uam_pwd,
 {
     char       *username;
     size_t     len, ulen;
-    u_int16_t  temp16;
+    uint16_t  temp16;
 
     *rbuflen = 0;
     
@@ -280,7 +275,7 @@ static int passwd_logincont(void *obj, struct passwd **uam_pwd,
 #endif /* SHADOWPW */
     unsigned char iv[] = "LWallace";
     BIGNUM *bn1, *bn2, *bn3;
-    u_int16_t sessid;
+    uint16_t sessid;
     char *p;
     int err = AFPERR_NOTAUTH;
 
index 044dd278bac78dea2d88ac3e72e8555ccf440812..da0411f949c4ff3e0483a99df2430f4481813405 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: uams_gss.c,v 1.12 2010-03-30 10:25:49 franklahm Exp $
- *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * Copyright (c) 1999 Adrian Sun (asun@u.washington.edu)
  * Copyright (c) 2003 The Reed Institute
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif /* HAVE_UNISTD_H */
-
-/* STDC check */
-#if STDC_HEADERS
 #include <string.h>
-#else /* STDC_HEADERS */
-#ifndef HAVE_STRCHR
-#define strchr index
-#define strrchr index
-#endif /* HAVE_STRCHR */
-char *strchr (), *strrchr ();
-#ifndef HAVE_MEMCPY
-#define memcpy(d,s,n) bcopy ((s), (d), (n))
-#define memmove(d,s,n) bcopy ((s), (d), (n))
-#endif /* ! HAVE_MEMCPY */
-#endif /* STDC_HEADERS */
-
 #include <errno.h>
+#include <arpa/inet.h>
+
 #include <atalk/logger.h>
 #include <atalk/afp.h>
 #include <atalk/uam.h>
 #include <atalk/util.h>
+#include <atalk/compat.h>
 
 /* Kerberos includes */
 
@@ -107,7 +93,7 @@ static void log_status( char *s, OM_uint32 major_status,
 
 static void log_ctx_flags( OM_uint32 flags )
 {
-#ifdef DEBUG1
+#ifdef DEBUG
     if (flags & GSS_C_DELEG_FLAG)
         LOG(log_debug, logtype_uams, "uams_gss.c :context flag: GSS_C_DELEG_FLAG" );
     if (flags & GSS_C_MUTUAL_FLAG)
@@ -424,7 +410,7 @@ static int do_gss_auth(void *obj, char *ibuf, int ticket_len,
         if (!ret) {
             /* FIXME: Is copying the authenticator really necessary?
                Where is this documented? */
-            u_int16_t auth_len = htons( authenticator_buff.length );
+            uint16_t auth_len = htons( authenticator_buff.length );
 
             /* copy the authenticator length into the reply buffer */
             memcpy( rbuf, &auth_len, sizeof(auth_len) );
@@ -457,7 +443,7 @@ static int gss_login(void *obj, struct passwd **uam_pwd,
                      char *rbuf, size_t *rbuflen)
 {
 
-    u_int16_t  temp16;
+    uint16_t  temp16;
 
     *rbuflen = 0;
 
@@ -475,9 +461,9 @@ static int gss_logincont(void *obj, struct passwd **uam_pwd,
                          char *rbuf, size_t *rbuflen)
 {
     struct passwd *pwd = NULL;
-    u_int16_t login_id;
+    uint16_t login_id;
     char *username;
-    u_int16_t ticket_len;
+    uint16_t ticket_len;
     char *p;
     int rblen;
     size_t userlen;
@@ -486,9 +472,9 @@ static int gss_logincont(void *obj, struct passwd **uam_pwd,
     /* Apple's AFP 3.1 documentation specifies that this command
      * takes the following format:
      * pad (byte)
-     * id returned in LoginExt response (u_int16_t)
+     * id returned in LoginExt response (uint16_t)
      * username (format unspecified) padded, when necessary, to end on an even boundary
-     * ticket length (u_int16_t)
+     * ticket length (uint16_t)
      * ticket
      */
 
@@ -496,14 +482,14 @@ static int gss_logincont(void *obj, struct passwd **uam_pwd,
      * format of this request is as follows:
      * pad (byte) [consumed before login_ext is called]
      * ?? (byte) - always observed to be 0
-     * id returned in LoginExt response (u_int16_t)
+     * id returned in LoginExt response (uint16_t)
      * username, encoding unspecified, null terminated C string,
      *   padded when the terminating null is an even numbered byte.
      *   The packet is formated such that the username begins on an
      *   odd numbered byte. Eg if the username is 3 characters and the
      *   terminating null makes 4, expect to pad the the result.
      *   The encoding of this string is unknown.
-     * ticket length (u_int16_t)
+     * ticket length (uint16_t)
      * ticket
      */
 
@@ -593,7 +579,7 @@ static int gss_login_ext(void *obj, char *uname, struct passwd **uam_pwd,
                          char *ibuf, size_t ibuflen,
                          char *rbuf, size_t *rbuflen)
 {
-    u_int16_t  temp16;
+    uint16_t  temp16;
 
     *rbuflen = 0;
 
index 0b5019e0e7e4d0214cb4db90250553742e138210..00f90ece0972ee01670d5cc1eee55879d6795b35 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 #include <errno.h>
-
-/* STDC check */
-#if STDC_HEADERS
 #include <string.h>
-#else /* STDC_HEADERS */
-#ifndef HAVE_STRCHR
-#define strchr index
-#define strrchr index
-#endif /* HAVE_STRCHR */
-char *strchr (), *strrchr ();
-#ifndef HAVE_MEMCPY
-#define memcpy(d,s,n) bcopy ((s), (d), (n))
-#define memmove(d,s,n) bcopy ((s), (d), (n))
-#endif /* ! HAVE_MEMCPY */
-#endif /* STDC_HEADERS */
-
 #include <pwd.h>
-#include <atalk/logger.h>
 
+#include <atalk/logger.h>
 #include <atalk/afp.h>
 #include <atalk/uam.h>
 #include <atalk/util.h>
+#include <atalk/compat.h>
 
 #ifndef MIN
 #define MIN(a,b) ((a) < (b) ? (a) : (b))
diff --git a/etc/uams/uams_krb4/.gitignore b/etc/uams/uams_krb4/.gitignore
deleted file mode 100644 (file)
index c22a7f2..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-.libs
-.deps
-*.o
-*.so
-*.la
-core
-Makefile.in
-Makefile
-.gitignore
-*.o
diff --git a/etc/uams/uams_krb4/Makefile.am b/etc/uams/uams_krb4/Makefile.am
deleted file mode 100644 (file)
index 219e74b..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-# Makefile.am for etc/uams/uams_krb4/
-
-if USE_KERBEROS
-KERBEROS_MODULE = uams_krb4.la
-else
-KERBEROS_MODULE =
-endif
-
-uams_krb4_la_SOURCES = kuam.c lifetime.c send_to_kdc.c uams_krb4.c
-uams_krb4_la_LDFLAGS = -module -avoid-version
-
-uamsdir = @UAMS_PATH@
-uams_LTLIBRARIES = $(KERBEROS_MODULE)
diff --git a/etc/uams/uams_krb4/kuam.c b/etc/uams/uams_krb4/kuam.c
deleted file mode 100644 (file)
index 3c79064..0000000
+++ /dev/null
@@ -1,218 +0,0 @@
-/*
- * $Id: kuam.c,v 1.4 2001-06-25 20:13:45 rufustfirefly Exp $
- *
- * Copyright (c) 1990,1994 Regents of The University of Michigan.
- * All Rights Reserved.  See COPYRIGHT.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#ifdef UAM_AFSKRB
-
-#include <mit-copyright.h>
-#include <krb.h>
-#include <des.h>
-#include <prot.h>
-
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-
-/* use the bsd time.h struct defs for PC too! */
-#include <sys/time.h>
-#include <sys/types.h>
-
-int     swap_bytes;
-
-/*
- * krb_get_in_tkt() gets a ticket for a given principal to use a given
- * service and stores the returned ticket and session key for future
- * use.
- *
- * The "user", "instance", and "realm" arguments give the identity of
- * the client who will use the ticket.  The "service" and "sinstance"
- * arguments give the identity of the server that the client wishes
- * to use.  (The realm of the server is the same as the Kerberos server
- * to whom the request is sent.)  The "life" argument indicates the
- * desired lifetime of the ticket; the "key_proc" argument is a pointer
- * to the routine used for getting the client's private key to decrypt
- * the reply from Kerberos.  The "decrypt_proc" argument is a pointer
- * to the routine used to decrypt the reply from Kerberos; and "arg"
- * is an argument to be passed on to the "key_proc" routine.
- *
- * If all goes well, krb_get_in_tkt() returns INTK_OK, otherwise it
- * returns an error code:  If an AUTH_MSG_ERR_REPLY packet is returned
- * by Kerberos, then the error code it contains is returned.  Other
- * error codes returned by this routine include INTK_PROT to indicate
- * wrong protocol version, INTK_BADPW to indicate bad password (if
- * decrypted ticket didn't make sense), INTK_ERR if the ticket was for
- * the wrong server or the ticket store couldn't be initialized.
- *
- * The format of the message sent to Kerberos is as follows:
- *
- * Size                        Variable                Field
- * ----                        --------                -----
- *
- * 1 byte              KRB_PROT_VERSION        protocol version number
- * 1 byte              AUTH_MSG_KDC_REQUEST |  message type
- *                     HOST_BYTE_ORDER         local byte order in lsb
- * string              user                    client's name
- * string              instance                client's instance
- * string              realm                   client's realm
- * 4 bytes             tlocal.tv_sec           timestamp in seconds
- * 1 byte              life                    desired lifetime
- * string              service                 service's name
- * string              sinstance               service's instance
- */
-
-kuam_get_in_tkt(user, instance, realm, service, sinstance, life, rpkt )
-    char       *user;
-    char       *instance;
-    char       *realm;
-    char       *service;
-    char       *sinstance;
-    int                life;
-    KTEXT      rpkt;
-{
-    KTEXT_ST pkt_st;
-    KTEXT pkt = &pkt_st;       /* Packet to KDC */
-    KTEXT_ST cip_st;
-    KTEXT cip = &cip_st;       /* Returned Ciphertext */
-    KTEXT_ST tkt_st;
-    KTEXT tkt = &tkt_st;       /* Current ticket */
-    unsigned char *v = pkt->dat; /* Prot vers no */
-    unsigned char *t = (pkt->dat+1); /* Prot msg type */
-    int msg_byte_order;
-    int kerror;
-    struct timeval t_local;
-    u_int32_t rep_err_code;
-
-
-    /* BUILD REQUEST PACKET */
-
-    /* Set up the fixed part of the packet */
-    *v = (unsigned char) KRB_PROT_VERSION;
-    *t = (unsigned char) AUTH_MSG_KDC_REQUEST;
-    *t |= HOST_BYTE_ORDER;
-
-    /* Now for the variable info */
-    (void) strcpy((char *)(pkt->dat+2),user); /* aname */
-    pkt->length = 3 + strlen(user);
-    (void) strcpy((char *)(pkt->dat+pkt->length),
-                 instance);    /* instance */
-    pkt->length += 1 + strlen(instance);
-    (void) strcpy((char *)(pkt->dat+pkt->length),realm); /* realm */
-    pkt->length += 1 + strlen(realm);
-
-    (void) gettimeofday(&t_local,(struct timezone *) 0);
-    /* timestamp */
-    memcpy((pkt->dat+pkt->length), &(t_local.tv_sec), 4);
-    pkt->length += 4;
-
-    *(pkt->dat+(pkt->length)++) = (char) life;
-    (void) strcpy((char *)(pkt->dat+pkt->length),service);
-    pkt->length += 1 + strlen(service);
-    (void) strcpy((char *)(pkt->dat+pkt->length),sinstance);
-    pkt->length += 1 + strlen(sinstance);
-
-    rpkt->length = 0;
-
-    /* SEND THE REQUEST AND RECEIVE THE RETURN PACKET */
-
-    if (kerror = send_to_kdc(pkt, rpkt, realm)) return(kerror);
-
-    /* check packet version of the returned packet */
-    if (pkt_version(rpkt) != KRB_PROT_VERSION)
-        return(INTK_PROT);
-
-    /* Check byte order */
-    msg_byte_order = pkt_msg_type(rpkt) & 1;
-    swap_bytes = 0;
-    if (msg_byte_order != HOST_BYTE_ORDER) {
-        swap_bytes++;
-    }
-
-    switch (pkt_msg_type(rpkt) & ~1) {
-    case AUTH_MSG_KDC_REPLY:
-        break;
-    case AUTH_MSG_ERR_REPLY:
-        memcpy(&rep_err_code,pkt_err_code(rpkt),4);
-        if (swap_bytes) swap_u_long(rep_err_code);
-        return((int)rep_err_code);
-    default:
-        return(INTK_PROT);
-    }
-
-    return( INTK_OK );
-}
-
-kuam_set_in_tkt( user, instance, realm, service, sinstance, ptr)
-    char       *user, *instance, *realm, *service, *sinstance, *ptr;
-{
-    KTEXT_ST           tkt_st;
-    KTEXT              tkt = &tkt_st;
-    struct timeval     t_local;
-    int                        lifetime, kvno, kerror;
-    int32_t            kdc_time;
-    C_Block            ses;
-    char               s_name[ SNAME_SZ ], s_instance[ INST_SZ ];
-    char               rlm[ REALM_SZ ];
-
-    /* extract session key */
-    memcpy(ses, ptr, 8);
-    ptr += 8;
-
-    /* extract server's name */
-    (void) strcpy(s_name,ptr);
-    ptr += strlen(s_name) + 1;
-
-    /* extract server's instance */
-    (void) strcpy(s_instance,ptr);
-    ptr += strlen(s_instance) + 1;
-
-    /* extract server's realm */
-    (void) strcpy(rlm,ptr);
-    ptr += strlen(rlm) + 1;
-
-    /* extract ticket lifetime, server key version, ticket length */
-    /* be sure to avoid sign extension on lifetime! */
-    lifetime = (unsigned char) ptr[0];
-    kvno = (unsigned char) ptr[1];
-    tkt->length = (unsigned char) ptr[2];
-    ptr += 3;
-
-    /* extract ticket itself */
-    memcpy( tkt->dat, ptr, tkt->length);
-    ptr += tkt->length;
-
-    if (strcmp(s_name, service) || strcmp(s_instance, sinstance) ||
-        strcmp(rlm, realm))    /* not what we asked for */
-       return(INTK_ERR);       /* we need a better code here XXX */
-
-    /* check KDC time stamp */
-    memcpy(&kdc_time, ptr, 4); /* Time (coarse) */
-    if (swap_bytes) swap_u_long(kdc_time);
-
-    ptr += 4;
-
-    (void) gettimeofday(&t_local,(struct timezone *) 0);
-    if (abs((int)(t_local.tv_sec - kdc_time)) > CLOCK_SKEW) {
-        return(RD_AP_TIME);            /* XXX should probably be better
-                                          code */
-    }
-
-    /* initialize ticket cache */
-    if (in_tkt(user,instance) != KSUCCESS)
-       return(INTK_ERR);
-
-    /* stash ticket, session key, etc. for future use */
-    if (kerror = save_credentials(s_name, s_instance, rlm, ses,
-                                 lifetime, kvno, tkt, t_local.tv_sec))
-       return(kerror);
-
-    return(INTK_OK);
-}
-
-#endif /* UAM_AFSKRB */
diff --git a/etc/uams/uams_krb4/lifetime.c b/etc/uams/uams_krb4/lifetime.c
deleted file mode 100644 (file)
index 428eac9..0000000
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * $Id: lifetime.c,v 1.3 2001-06-25 20:13:45 rufustfirefly Exp $
- *
- * Ticket lifetime.  This defines the table used to lookup lifetime
- * for the fixed part of rande of the one byte lifetime field.  Values
- * less than 0x80 are intrpreted as the number of 5 minute intervals.
- * Values from 0x80 to 0xBF should be looked up in this table.  The
- * value of 0x80 is the same using both methods: 10 and two-thirds
- * hours .  The lifetime of 0xBF is 30 days.  The intervening values
- * of have a fixed ratio of roughly 1.06914.  The value 0xFF is
- * defined to mean a ticket has no expiration time.  This should be
- * used advisedly since individual servers may impose defacto
- * upperbounds on ticket lifetimes.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <sys/types.h>
-#include <netatalk/endian.h>
-
-#define TKTLIFENUMFIXED 64
-#define TKTLIFEMINFIXED 0x80
-#define TKTLIFEMAXFIXED 0xBF
-#define TKTLIFENOEXPIRE 0xFF
-#define MAXTKTLIFETIME (30*24*3600)    /* 30 days */
-#ifndef NEVERDATE
-#define NEVERDATE ((u_int32_t)-1L)
-#endif /* NEVERDATE */
-
-static int tkt_lifetimes[TKTLIFENUMFIXED] = {
-    38400,                             /* 10.67 hours, 0.44 days */ 
-    41055,                             /* 11.40 hours, 0.48 days */ 
-    43894,                             /* 12.19 hours, 0.51 days */ 
-    46929,                             /* 13.04 hours, 0.54 days */ 
-    50174,                             /* 13.94 hours, 0.58 days */ 
-    53643,                             /* 14.90 hours, 0.62 days */ 
-    57352,                             /* 15.93 hours, 0.66 days */ 
-    61318,                             /* 17.03 hours, 0.71 days */ 
-    65558,                             /* 18.21 hours, 0.76 days */ 
-    70091,                             /* 19.47 hours, 0.81 days */ 
-    74937,                             /* 20.82 hours, 0.87 days */ 
-    80119,                             /* 22.26 hours, 0.93 days */ 
-    85658,                             /* 23.79 hours, 0.99 days */ 
-    91581,                             /* 25.44 hours, 1.06 days */ 
-    97914,                             /* 27.20 hours, 1.13 days */ 
-    104684,                            /* 29.08 hours, 1.21 days */ 
-    111922,                            /* 31.09 hours, 1.30 days */ 
-    119661,                            /* 33.24 hours, 1.38 days */ 
-    127935,                            /* 35.54 hours, 1.48 days */ 
-    136781,                            /* 37.99 hours, 1.58 days */ 
-    146239,                            /* 40.62 hours, 1.69 days */ 
-    156350,                            /* 43.43 hours, 1.81 days */ 
-    167161,                            /* 46.43 hours, 1.93 days */ 
-    178720,                            /* 49.64 hours, 2.07 days */ 
-    191077,                            /* 53.08 hours, 2.21 days */ 
-    204289,                            /* 56.75 hours, 2.36 days */ 
-    218415,                            /* 60.67 hours, 2.53 days */ 
-    233517,                            /* 64.87 hours, 2.70 days */ 
-    249664,                            /* 69.35 hours, 2.89 days */ 
-    266926,                            /* 74.15 hours, 3.09 days */ 
-    285383,                            /* 79.27 hours, 3.30 days */ 
-    305116,                            /* 84.75 hours, 3.53 days */ 
-    326213,                            /* 90.61 hours, 3.78 days */ 
-    348769,                            /* 96.88 hours, 4.04 days */ 
-    372885,                            /* 103.58 hours, 4.32 days */ 
-    398668,                            /* 110.74 hours, 4.61 days */ 
-    426234,                            /* 118.40 hours, 4.93 days */ 
-    455705,                            /* 126.58 hours, 5.27 days */ 
-    487215,                            /* 135.34 hours, 5.64 days */ 
-    520904,                            /* 144.70 hours, 6.03 days */ 
-    556921,                            /* 154.70 hours, 6.45 days */ 
-    595430,                            /* 165.40 hours, 6.89 days */ 
-    636601,                            /* 176.83 hours, 7.37 days */ 
-    680618,                            /* 189.06 hours, 7.88 days */ 
-    727680,                            /* 202.13 hours, 8.42 days */ 
-    777995,                            /* 216.11 hours, 9.00 days */ 
-    831789,                            /* 231.05 hours, 9.63 days */ 
-    889303,                            /* 247.03 hours, 10.29 days */ 
-    950794,                            /* 264.11 hours, 11.00 days */ 
-    1016537,                           /* 282.37 hours, 11.77 days */ 
-    1086825,                           /* 301.90 hours, 12.58 days */ 
-    1161973,                           /* 322.77 hours, 13.45 days */ 
-    1242318,                           /* 345.09 hours, 14.38 days */ 
-    1328218,                           /* 368.95 hours, 15.37 days */ 
-    1420057,                           /* 394.46 hours, 16.44 days */ 
-    1518247,                           /* 421.74 hours, 17.57 days */ 
-    1623226,                           /* 450.90 hours, 18.79 days */ 
-    1735464,                           /* 482.07 hours, 20.09 days */ 
-    1855462,                           /* 515.41 hours, 21.48 days */ 
-    1983758,                           /* 551.04 hours, 22.96 days */ 
-    2120925,                           /* 589.15 hours, 24.55 days */ 
-    2267576,                           /* 629.88 hours, 26.25 days */ 
-    2424367,                           /* 673.44 hours, 28.06 days */ 
-    2592000};                          /* 720.00 hours, 30.00 days */ 
-
-/*
- * krb_life_to_time - takes a start time and a Kerberos standard
- * lifetime char and returns the corresponding end time.  There are
- * four simple cases to be handled.  The first is a life of 0xff,
- * meaning no expiration, and results in an end time of 0xffffffff.
- * The second is when life is less than the values covered by the
- * table.  In this case, the end time is the start time plus the
- * number of 5 minute intervals specified by life.  The third case
- * returns start plus the MAXTKTLIFETIME if life is greater than
- * TKTLIFEMAXFIXED.  The last case, uses the life value (minus
- * TKTLIFEMINFIXED) as an index into the table to extract the lifetime
- * in seconds, which is added to start to produce the end time.
- */
-u_int32_t krb_life_to_time(start, life)
-u_int32_t start;
-int life;
-{
-    life = (unsigned char) life;
-    if (life == TKTLIFENOEXPIRE) return NEVERDATE;
-    if (life < TKTLIFEMINFIXED) return start + life*5*60;
-    if (life > TKTLIFEMAXFIXED) return start + MAXTKTLIFETIME;
-    return start + tkt_lifetimes[life - TKTLIFEMINFIXED];
-}
-
-/*
- * krb_time_to_life - takes start and end times for the ticket and
- * returns a Kerberos standard lifetime char, possibily using the
- * tkt_lifetimes table for lifetimes above 127*5 minutes.  First, the
- * special case of (end == NEVERDATE) is handled to mean no
- * expiration.  Then negative lifetimes and those greater than the
- * maximum ticket lifetime are rejected.  Then lifetimes less than the
- * first table entry are handled by rounding the requested lifetime
- * *up* to the next 5 minute interval.  The final step is to search
- * the table for the smallest entry *greater than or equal* to the
- * requested entry.
- */
-int krb_time_to_life(start, end)
-u_int32_t start;
-u_int32_t end;
-{
-    int32_t lifetime;
-    int i;
-
-    if (end == NEVERDATE) return TKTLIFENOEXPIRE;
-    lifetime = end - start;
-    if (lifetime > MAXTKTLIFETIME || lifetime <= 0) return 0;
-    if (lifetime < tkt_lifetimes[0]) return (lifetime + 5*60 - 1)/(5*60);
-    for (i=0; i<TKTLIFENUMFIXED; i++) {
-       if (lifetime <= tkt_lifetimes[i]) {
-           return i+TKTLIFEMINFIXED;
-       }
-    }
-    return 0;
-}
diff --git a/etc/uams/uams_krb4/send_to_kdc.c b/etc/uams/uams_krb4/send_to_kdc.c
deleted file mode 100644 (file)
index d20856f..0000000
+++ /dev/null
@@ -1,325 +0,0 @@
-/*
- * $Id: send_to_kdc.c,v 1.4 2001-06-25 20:13:45 rufustfirefly Exp $
- * $Author: rufustfirefly $
- *
- * Copyright (c) 1990,1994 Regents of The University of Michigan.
- * All Rights Reserved.  See COPYRIGHT.
- *
- * $Source: /home/ralph/netatalk/rsync/netatalk/etc/uams/uams_krb4/send_to_kdc.c,v $
- *
- * Copyright 1987, 1988 by the Massachusetts Institute of Technology.
- *
- * For copying and distribution information, please see the file
- * <mit-copyright.h>.
- */
-
-#ifndef lint
-static char rcsid_send_to_kdc_c[] =
-"$Id: send_to_kdc.c,v 1.4 2001-06-25 20:13:45 rufustfirefly Exp $";
-#endif /* lint */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#ifdef UAM_AFSKRB
-
-#include <mit-copyright.h>
-
-#include <krb.h>
-#include <prot.h>
-
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#ifdef lint
-#include <sys/uio.h>            /* struct iovec to make lint happy */
-#endif /* lint */
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#include <string.h>
-
-#define S_AD_SZ sizeof(struct sockaddr_in)
-
-extern int krb_debug;
-
-extern char *malloc(), *calloc(), *realloc();
-
-int krb_udp_port = 0;
-
-/* CLIENT_KRB_TIMEOUT indicates the time to wait before
- * retrying a server.  It's defined in "krb.h".
- */
-static struct timeval timeout = { CLIENT_KRB_TIMEOUT, 0};
-static char *prog = "send_to_kdc";
-static send_recv();
-
-/*
- * This file contains two routines, send_to_kdc() and send_recv().
- * send_recv() is a static routine used by send_to_kdc().
- */
-
-/*
- * send_to_kdc() sends a message to the Kerberos authentication
- * server(s) in the given realm and returns the reply message.
- * The "pkt" argument points to the message to be sent to Kerberos;
- * the "rpkt" argument will be filled in with Kerberos' reply.
- * The "realm" argument indicates the realm of the Kerberos server(s)
- * to transact with.  If the realm is null, the local realm is used.
- *
- * If more than one Kerberos server is known for a given realm,
- * different servers will be queried until one of them replies.
- * Several attempts (retries) are made for each server before
- * giving up entirely.
- *
- * If an answer was received from a Kerberos host, KSUCCESS is
- * returned.  The following errors can be returned:
- *
- * SKDC_CANT    - can't get local realm
- *              - can't find "kerberos" in /etc/services database
- *              - can't open socket
- *              - can't bind socket
- *              - all ports in use
- *              - couldn't find any Kerberos host
- *
- * SKDC_RETRY   - couldn't get an answer from any Kerberos server,
- *               after several retries
- */
-
-send_to_kdc(pkt,rpkt,realm)
-    KTEXT pkt;
-    KTEXT rpkt;
-    char *realm;
-{
-    int i, f;
-    int no_host; /* was a kerberos host found? */
-    int retry;
-    int n_hosts;
-    int retval;
-    struct sockaddr_in to;
-    struct hostent *host, *hostlist;
-    char *cp;
-    char krbhst[MAX_HSTNM];
-    char lrealm[REALM_SZ];
-
-    /*
-     * If "realm" is non-null, use that, otherwise get the
-     * local realm.
-     */
-    if (realm)
-       (void) strcpy(lrealm, realm);
-    else
-       if (krb_get_lrealm(lrealm,1)) {
-           if (krb_debug)
-               fprintf(stderr, "%s: can't get local realm\n", prog);
-           return(SKDC_CANT);
-       }
-    if (krb_debug)
-        printf("lrealm is %s\n", lrealm);
-    if (krb_udp_port == 0) {
-        register struct servent *sp;
-        if ((sp = getservbyname("kerberos","udp")) == 0) {
-            if (krb_debug)
-                fprintf(stderr, "%s: Can't get kerberos/udp service\n",
-                        prog);
-            return(SKDC_CANT);
-        }
-        krb_udp_port = sp->s_port;
-        if (krb_debug)
-            printf("krb_udp_port is %d\n", krb_udp_port);
-    }
-    memset(&to, 0, S_AD_SZ);
-    hostlist = (struct hostent *) malloc(sizeof(struct hostent));
-    if (!hostlist)
-        return (/*errno */SKDC_CANT);
-    if ((f = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
-        if (krb_debug)
-            fprintf(stderr,"%s: Can't open socket\n", prog);
-        return(SKDC_CANT);
-    }
-    /* from now on, exit through rtn label for cleanup */
-
-    no_host = 1;
-    /* get an initial allocation */
-    n_hosts = 0;
-    for (i = 1; krb_get_krbhst(krbhst, lrealm, i) == KSUCCESS; ++i) {
-        if (krb_debug) {
-            printf("Getting host entry for %s...",krbhst);
-            (void) fflush(stdout);
-        }
-        host = gethostbyname(krbhst);
-        if (krb_debug) {
-            printf("%s.\n",
-                   host ? "Got it" : "Didn't get it");
-            (void) fflush(stdout);
-        }
-        if (!host)
-            continue;
-        no_host = 0;    /* found at least one */
-        n_hosts++;
-        /* preserve host network address to check later
-         * (would be better to preserve *all* addresses,
-         * take care of that later)
-         */
-        hostlist = (struct hostent *)
-            realloc((char *)hostlist,
-                    (unsigned)
-                    sizeof(struct hostent)*(n_hosts+1));
-        if (!hostlist)
-            return /*errno */SKDC_CANT;
-        memcpy(&hostlist[n_hosts-1], host, sizeof(struct hostent));
-        host = &hostlist[n_hosts-1];
-        cp = malloc((unsigned)host->h_length);
-        if (!cp) {
-            retval = /*errno */SKDC_CANT;
-            goto rtn;
-        }
-        memcpy(cp, host->h_addr, host->h_length);
-/* At least Sun OS version 3.2 (or worse) and Ultrix version 2.2
-   (or worse) only return one name ... */
-#if !(defined(ULTRIX022) || (defined(SunOS) && SunOS < 40))
-        host->h_addr_list = (char **)malloc(sizeof(char *));
-        if (!host->h_addr_list) {
-            retval = /*errno */SKDC_CANT;
-            goto rtn;
-        }
-#endif /* ULTRIX022 || SunOS */
-        host->h_addr = cp;
-        memset(&hostlist[n_hosts], 0, sizeof(struct hostent));
-        to.sin_family = host->h_addrtype;
-        memcpy(&to.sin_addr, host->h_addr, host->h_length);
-        to.sin_port = krb_udp_port;
-        if (send_recv(pkt, rpkt, f, &to, hostlist)) {
-            retval = KSUCCESS;
-            goto rtn;
-        }
-        if (krb_debug) {
-            printf("Timeout, error, or wrong descriptor\n");
-            (void) fflush(stdout);
-        }
-    }
-    if (no_host) {
-       if (krb_debug)
-           fprintf(stderr, "%s: can't find any Kerberos host.\n",
-                   prog);
-        retval = SKDC_CANT;
-        goto rtn;
-    }
-    /* retry each host in sequence */
-    for (retry = 0; retry < CLIENT_KRB_RETRY; ++retry) {
-        for (host = hostlist; host->h_name != (char *)NULL; host++) {
-            to.sin_family = host->h_addrtype;
-            memcpy(&to.sin_addr, host->h_addr, host->h_length);
-            if (send_recv(pkt, rpkt, f, &to, hostlist)) {
-                retval = KSUCCESS;
-                goto rtn;
-            }
-        }
-    }
-    retval = SKDC_RETRY;
-rtn:
-    (void) close(f);
-    if (hostlist) {
-        register struct hostent *hp;
-        for (hp = hostlist; hp->h_name; hp++)
-#if !(defined(ULTRIX022) || (defined(SunOS) && SunOS < 40))
-            if (hp->h_addr_list) {
-#endif /* ULTRIX022 || SunOS */
-                if (hp->h_addr)
-                    free(hp->h_addr);
-#if !(defined(ULTRIX022) || (defined(SunOS) && SunOS < 40))
-                free((char *)hp->h_addr_list);
-            }
-#endif /* ULTRIX022 || SunOS */
-        free((char *)hostlist);
-    }
-    return(retval);
-}
-
-/*
- * try to send out and receive message.
- * return 1 on success, 0 on failure
- */
-
-static send_recv(pkt,rpkt,f,_to,addrs)
-    KTEXT pkt;
-    KTEXT rpkt;
-    int f;
-    struct sockaddr_in *_to;
-    struct hostent *addrs;
-{
-    fd_set readfds;
-    register struct hostent *hp;
-    struct sockaddr_in from;
-    int sin_size, rc;
-    int numsent;
-
-    if (krb_debug) {
-        if (_to->sin_family == AF_INET)
-            printf("Sending message to %s...",
-                   inet_ntoa(_to->sin_addr));
-        else
-            printf("Sending message...");
-        (void) fflush(stdout);
-    }
-    if ((numsent = sendto(f,(char *)(pkt->dat), pkt->length, 0, 
-                         (struct sockaddr *)_to,
-                          S_AD_SZ)) != pkt->length) {
-        if (krb_debug)
-            printf("sent only %d/%d\n",numsent, pkt->length);
-        return 0;
-    }
-    if (krb_debug) {
-        printf("Sent\nWaiting for reply...");
-        (void) fflush(stdout);
-    }
-    FD_ZERO(&readfds);
-    FD_SET(f, &readfds);
-    errno = 0;
-    /* select - either recv is ready, or timeout */
-    /* see if timeout or error or wrong descriptor */
-    if (select(f + 1, &readfds, (fd_set *)0, (fd_set *)0, &timeout) < 1
-        || !FD_ISSET(f, &readfds)) {
-        if (krb_debug) {
-            fprintf(stderr, "select failed: readfds=%x",
-                    readfds);
-            perror("");
-        }
-        return 0;
-    }
-    sin_size = sizeof(from);
-    if (( rc = recvfrom(f, (char *)(rpkt->dat), sizeof(rpkt->dat), 0,
-                (struct sockaddr *)&from, &sin_size)) < 0) {
-        if (krb_debug)
-            perror("recvfrom");
-        return 0;
-    }
-    rpkt->length = rc;
-    if (krb_debug) {
-        printf("received packet from %s\n", inet_ntoa(from.sin_addr));
-        fflush(stdout);
-    }
-    for (hp = addrs; hp->h_name != (char *)NULL; hp++) {
-        if (!memcmp(hp->h_addr, (char *)&from.sin_addr.s_addr,
-                  hp->h_length)) {
-            if (krb_debug) {
-                printf("Received it\n");
-                (void) fflush(stdout);
-            }
-            return 1;
-        }
-        if (krb_debug)
-            fprintf(stderr,
-                    "packet not from %x\n",
-                    hp->h_addr);
-    }
-    if (krb_debug)
-        fprintf(stderr, "%s: received packet from wrong host! (%x)\n",
-                "send_to_kdc(send_rcv)", from.sin_addr.s_addr);
-    return 0;
-}
-
-#endif /* UAM_AFSKRB */
diff --git a/etc/uams/uams_krb4/uams_krb4.c b/etc/uams/uams_krb4/uams_krb4.c
deleted file mode 100644 (file)
index ff7c2c0..0000000
+++ /dev/null
@@ -1,799 +0,0 @@
-/*
- * $Id: uams_krb4.c,v 1.10 2009-10-15 11:39:48 didg Exp $
- *
- * Copyright (c) 1990,1993 Regents of The University of Michigan.
- * All Rights Reserved.  See COPYRIGHT.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#if defined( KRB ) || defined( UAM_AFSKRB )
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
-#ifdef HAVE_FCNTL_H
-#include <fcntl.h>
-#endif /* HAVE_FCNTL_H */
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/stat.h>
-#include <sys/socket.h>
-#include <limits.h>
-
-/* STDC check */
-#if STDC_HEADERS
-#include <string.h>
-#else /* STDC_HEADERS */
-#ifndef HAVE_STRCHR
-#define strchr index
-#define strrchr index
-#endif /* HAVE_STRCHR */
-char *strchr (), *strrchr ();
-#ifndef HAVE_MEMCPY
-#define memcpy(d,s,n) bcopy ((s), (d), (n))
-#define memmove(d,s,n) bcopy ((s), (d), (n))
-#endif /* ! HAVE_MEMCPY */
-#endif /* STDC_HEADERS */
-
-#include <ctype.h>
-#include <pwd.h>
-#include <atalk/logger.h>
-#include <netinet/in.h>
-#include <des.h>
-#include <krb.h>
-#if 0
-#include <prot.h>
-#endif /* 0 */
-
-#include <netatalk/endian.h>
-#include <atalk/afp.h>
-#include <atalk/compat.h>
-#include <atalk/util.h>
-#include <atalk/uam.h>
-
-static C_Block                 seskey;
-static Key_schedule            seskeysched;
-
-static char            realm[ REALM_SZ ];
-
-#ifdef UAM_AFSKRB
-static int             validseskey = 0;
-static int             logged = 0;
-static char            *tktfile;
-static char            instance[ INST_SZ ], name[ ANAME_SZ ];
-#endif /* UAM_AFSKRB */
-
-#ifdef AFS
-#include <afs/stds.h>
-#include <rx/rxkad.h>
-#include <afs/afs.h>
-#include <afs/venus.h>
-#include <afs/afsint.h>
-
-char *ka_LocalCell();
-
-struct ClearToken {
-    int32_t AuthHandle;
-    char HandShakeKey[8];
-    int32_t ViceId;
-    int32_t BeginTimestamp;
-    int32_t EndTimestamp;
-};
-#endif /* AFS */
-
-
-#ifdef KRB
-
-static void lcase( p )
-    char       *p;
-{
-    for (; *p; p++ ) {
-       if ( isupper( *p )) {
-           *p = tolower( *p );
-       }
-    }
-    return;
-}
-
-static void ucase( p )
-    char       *p;
-{
-    for (; *p; p++ ) {
-       if ( islower( *p )) {
-           *p = toupper( *p );
-       }
-    }
-    return;
-}
-
-#define KRB4CMD_HELO   1
-#define KRB4RPL_REALM  2
-#define KRB4WRT_SESS   3
-#define KRB4RPL_DONE   4
-#define KRB4RPL_PRINC  5
-#define KRB4WRT_TOKEN  6
-#define KRB4WRT_SKIP   7
-#define KRB4RPL_DONEMUT        8
-#define KRB4CMD_SESS   9
-#define KRB4CMD_TOKEN  10
-#define KRB4CMD_SKIP   11
-
-static int krb4_login(void *obj, struct passwd **uam_pwd,
-                     char *ibuf, size_t ibuflen,
-                     char *rbuf, size_t *rbuflen )
-{
-    char               *p;
-    char               *username;
-    struct passwd      *pwd;
-    u_int16_t          len;
-    KTEXT_ST           tkt;
-    static AUTH_DAT    ad;
-    int                        rc, proto;
-    size_t             ulen;
-    char               inst[ 40 ], princ[ 40 ];
-
-    if (uam_afpserver_option(obj, UAM_OPTION_USERNAME, &username, &ulen) < 0)
-      return AFPERR_MISC;
-
-    if (uam_afpserver_option(obj, UAM_OPTION_PROTOCOL, &proto, NULL) < 0)
-      return AFPERR_MISC;
-
-    switch( *ibuf ) {
-       case KRB4CMD_SESS:
-           LOG(log_info, logtype_default, "krb4_login: KRB4CMD_SESS" );
-           ++ibuf;
-           p = ibuf;
-           memcpy( &len, p, sizeof( u_int16_t ));
-           tkt.length = ntohs( len );
-           p += sizeof( u_int16_t );
-
-           if ( tkt.length <= 0 || tkt.length > MAX_KTXT_LEN ) {
-               *rbuflen = 0;
-               LOG(log_info, logtype_default, "krb4_login: tkt.length = %d", tkt.length );
-               return( AFPERR_BADUAM );
-           }
-
-           memcpy( tkt.dat, p, tkt.length );
-           p += tkt.length;
-
-           strcpy( inst, "*" );
-
-           switch( proto ) {
-               case AFPPROTO_ASP:
-                   strcpy( princ, "afpserver" );
-                   break;
-               case AFPPROTO_DSI:
-                   strcpy( princ, "rcmd" );
-                   break;
-           }
-
-           if( (rc = krb_rd_req( &tkt, princ, inst, 0, &ad, "" )) 
-               != RD_AP_OK ) {
-               LOG(log_error, logtype_default, 
-                       "krb4_login: krb_rd_req(): %s", krb_err_txt[ rc ] );
-               *rbuflen = 0;
-               return( AFPERR_BADUAM );
-           }
-
-           LOG(log_info, logtype_default, "krb4_login: %s.%s@%s", ad.pname, ad.pinst, 
-               ad.prealm );
-           strcpy( realm, ad.prealm );
-           memcpy( seskey, ad.session, sizeof( C_Block ) );
-           key_sched( (C_Block *)seskey, seskeysched );
-
-           strncpy( username, ad.pname, ulen );
-
-           p = rbuf;
-
-#ifdef AFS
-           *p = KRB4RPL_DONE;  /* XXX */
-           *rbuflen = 1;
-
-           if (( pwd = uam_getname( obj, ad.pname, strlen(ad.pname) )) == NULL ) {
-               return AFPERR_PARAM;
-           }
-/*
-           if (uam_checkuser( pwd ) < 0) {
-               return AFPERR_NOTAUTH;
-           }
-*/
-           *uam_pwd = pwd;
-           return( AFP_OK ); /* Should this be AFPERR_AUTHCONT? */
-#else /* AFS */
-           /* get principals */
-           *p++ = KRB4RPL_PRINC;
-           len = strlen( realm );
-           *p++ = len + 1;
-           *p++ = '@';
-           strcpy( p, realm );
-           p += len + 1;
-           break;
-#endif /* AFS */
-       case KRB4CMD_HELO:
-           p = rbuf;
-           if (krb_get_lrealm( realm, 1 ) != KSUCCESS ) {
-               LOG(log_error, logtype_default, "krb4_login: can't get local realm!" );
-               return( AFPERR_NOTAUTH );
-           }
-           *p++ = KRB4RPL_REALM;
-           *p++ = 1;
-           len = strlen( realm );
-           *p++ = len;
-           strcpy( p, realm );
-           p += len + 1;
-           break;
-
-       default:
-           *rbuflen = 0;
-           LOG(log_info, logtype_default, "krb4_login: bad command %d", *ibuf );
-           return( AFPERR_NOTAUTH );
-    }
-
-#ifdef AFS
-    if ( setpag() < 0 ) {
-       *rbuflen = 0;
-       LOG(log_error, logtype_default, "krb_login: setpag: %s", strerror(errno) );
-       return( AFPERR_BADUAM );
-    }
-#endif /*AFS*/
-
-    *rbuflen = p - rbuf;
-    return( AFPERR_AUTHCONT );
-}
-
-static int krb4_action( void *v1, void *v2, const int i )
-{
-       return i;
-}
-
-/*
-   I have a hunch that problems might arise on platforms 
-   with non-16bit short's and non-32bit int's
-*/
-static int krb4_logincont(void *obj, struct passwd **uam_pwd,
-                         char *ibuf, size_t ibuflen,
-                         char *rbuf, size_t *rbuflen)
-{
-    static struct passwd       *pwd;
-    KTEXT_ST           tkt;
-    static AUTH_DAT    ad;
-    int                        rc;
-    u_int16_t          len;
-    char               *p, *username, *servername;
-    CREDENTIALS                cr;
-#ifdef AFS
-    struct ViceIoctl   vi;
-    struct ClearToken  ct;
-#endif /* AFS */
-    char               buf[ 1024 ];
-    int                        aint, ulen, snlen;
-
-    if (uam_afpserver_option(obj, UAM_OPTION_USERNAME, &username, &ulen) < 0)
-      return AFPERR_MISC;
-
-    if (uam_afpserver_option(obj, UAM_OPTION_HOSTNAME, &servername, &snlen) < 0)
-      return AFPERR_MISC;
-
-    ibuf++;
-    switch ( rc = *ibuf++ ) {
-       case KRB4CMD_TOKEN :
-#ifdef AFS
-           p = buf;
-           memcpy( &len, ibuf, sizeof( u_int16_t ) );
-           ibuf += sizeof( len );
-           len = ntohs( len );
-           aint = len;
-           memcpy( p, &aint, sizeof( int ) );
-           p += sizeof( int );
-           memcpy( p, ibuf, len );
-           pcbc_encrypt( (C_Block *)p, (C_Block *)p, len, seskeysched,
-               seskey, DECRYPT );
-           p += len;
-           ibuf += len;
-
-           memcpy( &len, ibuf, sizeof( u_int16_t ) );
-           ibuf += sizeof( u_int16_t ) );
-           len = ntohs( len );
-
-           if ( len != sizeof( struct ClearToken ) ) {
-               LOG(log_error, logtype_default, "krb4_logincont: token too short" );
-               *rbuflen = 0;
-               return( AFPERR_BADUAM );
-           }
-           memcpy( &ct, ibuf, len );
-
-           pcbc_encrypt( (C_Block *)&ct, (C_Block *)&ct, len, 
-               seskeysched, seskey, DECRYPT );
-
-           aint = sizeof( struct ClearToken );
-           memcpy( p, &aint, sizeof( int ) );
-           p += sizeof( int );
-           memcpy( p, &ct, sizeof( struct ClearToken ) );
-           p += sizeof( struct ClearToken );
-
-           aint = 0;
-           memcpy( p, &aint, sizeof( int ) );
-           p += sizeof( int );
-
-           lcase( realm );
-           strcpy( p, realm );
-           p += strlen( realm ) + 1;
-
-           vi.in = buf;
-           vi.in_size = p - buf;
-           vi.out = buf;
-           vi.out_size = sizeof( buf );
-
-           if ( pioctl( 0, VIOCSETTOK, &vi, 0 ) < 0 ) {
-               LOG(log_error, logtype_default, "krb4_logincont: pioctl: %s", strerror(errno) );
-               *rbuflen = 0;
-               return( AFPERR_BADUAM );
-           }
-           /* FALL THROUGH */
-
-       case KRB4CMD_SKIP:
-           p = rbuf;
-           *p = KRB4RPL_DONE;  /* XXX */
-           *rbuflen = 1;
-
-           if (( pwd = uam_getname( obj, username, strlen(username) ) ) == NULL ) {
-               return( AFPERR_NOTAUTH );
-           }
-/*
-           if (uam_checkuser(pwd) < 0) {
-               return AFPERR_NOTAUTH;
-           }
-*/
-           *uam_pwd = pwd;
-           return( AFP_OK );
-#endif /* AFS */
-       default:
-           /* read in the rest */
-           if (uam_afp_read(obj, rbuf, rbuflen, krb4_action) < 0)
-               return AFPERR_PARAM;
-
-           p = rbuf;
-           switch ( rc = *p++ ) {
-               case KRB4WRT_SESS :
-                   memcpy( &len, p, sizeof( len ));
-                   tkt.length = ntohs( len );
-                   p += sizeof( short );
-
-                   if ( tkt.length <= 0 || tkt.length > MAX_KTXT_LEN ) {
-                       return( AFPERR_BADUAM );
-                   }
-                   memcpy( tkt.dat, p, tkt.length );
-                   p += tkt.length;
-
-                   if (( rc = krb_rd_req( &tkt, "afpserver", servername, 
-                       0, &ad, "" )) != RD_AP_OK ) {
-                       LOG(log_error, logtype_default, "krb4_logincont: krb_rd_req(): %s", krb_err_txt[ rc ] );
-                       return( AFPERR_BADUAM );
-                   }
-
-                   LOG(log_info, logtype_default, "krb4_login: %s.%s@%s", ad.pname, 
-                       ad.pinst, ad.prealm );
-                   memcpy(realm, ad.prealm, sizeof(realm));
-                   memcpy(seskey, ad.session, sizeof( C_Block ));
-                   key_sched((C_Block *) seskey, seskeysched );
-
-                   strncpy(username, ad.pname, ulen);
-
-                   p = rbuf;
-#ifndef AFS
-                   *p = KRB4RPL_DONE;  /* XXX */
-                   *rbuflen = 1;
-
-                   if (( pwd = uam_getname( obj, ad.pname, strlen(ad.pname) )) 
-                       == NULL ) {
-                       return( AFPERR_PARAM );
-                   }
-                   *uam_pwd = pwd;
-                   return AFP_OK;
-#else /* ! AFS */
-                   /* get principals */
-                   *p++ = KRB4RPL_PRINC;
-                   len = strlen( realm );
-                   *p++ = len + 1;
-                   *p++ = '@';
-                   strcpy( p, realm );
-                   p += len + 1;
-                   *rbuflen = p - rbuf;
-                   return( AFPERR_AUTHCONT );
-
-               case KRB4WRT_TOKEN :
-                   memcpy( &len, p, sizeof( len ));
-                   len = ntohs( len );
-                   p += sizeof( len );
-                   memcpy( &cr, p, len );
-
-                   pcbc_encrypt((C_Block *)&cr, (C_Block *)&cr, len, 
-                       seskeysched, seskey, DES_DECRYPT );
-
-                   p = buf;
-                   cr.ticket_st.length = ntohl( cr.ticket_st.length );
-                   memcpy( p, &cr.ticket_st.length, sizeof( int ));
-                   p += sizeof( int );
-                   memcpy( p, cr.ticket_st.dat, cr.ticket_st.length );
-                   p += cr.ticket_st.length;
-
-                   ct.AuthHandle = ntohl( cr.kvno );
-                   memcpy( ct.HandShakeKey, cr.session, sizeof( cr.session ));
-                   ct.ViceId = 0;
-                   ct.BeginTimestamp = ntohl( cr.issue_date );
-                   ct.EndTimestamp = krb_life_to_time( ntohl( cr.issue_date ),
-                   ntohl( cr.lifetime ));
-
-                   aint = sizeof( struct ClearToken );
-                   memcpy( p, &aint, sizeof( int ));
-                   p += sizeof( int );
-                   memcpy( p, &ct, sizeof( struct ClearToken ));
-                   p += sizeof( struct ClearToken );
-
-                   aint = 0;
-                   memcpy( p, &aint, sizeof( int ));
-                   p += sizeof( int );
-
-                   lcase( realm );
-                   strcpy( p, realm );
-                   p += strlen( realm ) + 1;
-
-                   vi.in = buf;
-                   vi.in_size = p - buf;
-                   vi.out = buf;
-                   vi.out_size = sizeof( buf );
-                   if ( pioctl( 0, VIOCSETTOK, &vi, 0 ) < 0 ) {
-                       LOG(log_error, logtype_default, "krb4_logincont: pioctl: %s", strerror(errno) );
-                       return( AFPERR_BADUAM );
-                   }
-                   /* FALL THROUGH */
-
-               case KRB4WRT_SKIP :
-                   p = rbuf;
-                   *p = KRB4RPL_DONE;  /* XXX */
-                   *rbuflen = 1;
-
-                   if (( pwd = uam_getname( obj, ad.pname, strlen(ad.pname) )) 
-                       == NULL ) {
-                       return( AFPERR_PARAM );
-                   }
-                   *uam_pwd = pwd;
-                   return AFP_OK;
-#endif /*AFS*/
-
-               default:
-                   LOG(log_info, logtype_default, "krb4_logincont: bad command %d", rc );
-                   *rbuflen = 0;
-                   return( AFPERR_NOTAUTH );
-                   break;
-           }
-           break;
-    }
-}
-
-#endif /* KRB */
-
-
-#ifdef AFS
-#include <rx/rxkad.h>
-#include <afs/afsint.h>
-
-char *ka_LocalCell();
-
-static void
-addrealm(realm,cells)
-    char *realm;
-       char ***cells;
-{
-    char **ptr;
-       int temp;
-
-       ptr= *cells;
-
-    for(;*ptr != 0 ;ptr++)
-        if(!strcmp(realm,*ptr))
-            return;
-
-       temp=ptr- *cells;
-       *cells=(char**)realloc(*cells,((2+temp)*sizeof(char*)));
-       ptr= *cells+temp;
-
-    *ptr=(char*)malloc(strlen(realm)+1);
-    strcpy(*ptr++,realm);
-       *ptr=0;
-    return;
-}
-
-static int kcheckuser(pwd,passwd)
-       struct passwd *pwd;
-       char *passwd;
-{
-       int32_t code;
-       char *instance="";
-       char realm[MAXKTCREALMLEN];
-       char lorealm[MAXKTCREALMLEN];
-       char *cell;
-       Date lifetime=MAXKTCTICKETLIFETIME;
-       int rval;
-       char **cells=(char **)malloc(sizeof(char*));
-       char *temp;
-       int rc,cellNum;
-       struct ktc_principal serviceName;
-
-       *cells=0;
-
-       code = ka_Init(0);
-
-       {
-               char *temp,*temp1;
-               temp=(char*)malloc(strlen(pwd->pw_dir)+1);
-               strcpy(temp,pwd->pw_dir);
-               temp1=temp;
-               temp=strtok(temp,"/");
-               temp=strtok('\0',"/");
-               ka_CellToRealm(temp,realm,0);
-               addrealm(realm,&cells);
-               free(temp1);
-       }
-
-       setpag();
-       authenticate(cells,pwd->pw_name,passwd);
-       cellNum=0;
-       rc=ktc_ListTokens(cellNum,&cellNum,&serviceName);
-       if(rc)
-               rval=1;
-       else{
-               rval=0;
-       }
-
-       return(rval);
-}
-
-static void authenticate(cells,name,passwd)
-       char **cells;
-       char *name;
-       char *passwd;
-{
-       char **ptr=cells;
-       char *errorstring;
-
-       while(*ptr){
-           ka_UserAuthenticate(name,/*instance*/"",/*cell*/*ptr++,
-                   passwd,/*setpag*/0,&errorstring);
-       }
-}
-#endif /* AFS */
-
-#if defined( UAM_AFSKRB ) && defined( AFS )
-static int afskrb_login(void *obj, struct passwd *uam_pwd,
-                       char *ibuf, size_t ibuflen, 
-                       char *rbuf, size_t *rbuflen )
-{
-    KTEXT_ST   authent, rpkt;
-    CREDENTIALS        cr;
-    char       *p, *q, *username, servername;
-    int                len, rc, whoserealm, ulen, snlen;
-    short      slen;
-
-    *rbuflen = 0;
-    if (uam_afpserver_option(obj, UAM_OPTION_USERNAME, &username, &ulen) < 0)
-      return AFPERR_MISC;
-
-    if (uam_afpserver_option(obj, UAM_OPTION_HOSTNAME, &servername, &snlen ) < 0)
-      return AFPERR_MISC;
-    
-    len = (unsigned char) *ibuf++;
-    ibuf[ len ] = '\0';
-    if (( p = strchr( ibuf, '@' )) != NULL ) {
-       *p++ = '\0';
-       strcpy( realm, p );
-       ucase( realm );
-       whoserealm = 0;
-    } else {
-       if ( krb_get_lrealm( realm, 1 ) != KSUCCESS ) {
-           return AFPERR_BADUAM;
-       }
-       whoserealm = 1;
-    }
-    if (( p = strchr( ibuf, '.' )) != NULL ) {
-       *p++ = '\0';
-       strcpy( instance, p );
-    } else {
-       *instance = '\0';
-    }
-    strcpy( name, ibuf );
-    /*
-     * We don't have the session key, yet. Get one.
-     */
-    p = rbuf;
-    if ( validseskey == 0 ) {
-       if ( setpag() < 0 ) {
-           LOG(log_error, logtype_default, "krb_login: setpag: %s", strerror(errno) );
-           return AFPERR_BADUAM;
-       }
-       krb_set_tkt_string(( tktfile = mktemp( _PATH_AFPTKT )));
-       if (( rc =  krb_get_svc_in_tkt( "afpserver", servername, realm,
-               TICKET_GRANTING_TICKET, realm, 255, KEYFILE )) != INTK_OK ) {
-           LOG(log_error, logtype_default, "krb_login: can't get ticket-granting-ticket" );
-           return (( whoserealm ) ? AFPERR_BADUAM : AFPERR_PARAM );
-       }
-       if ( krb_mk_req( &authent, name, instance, realm, 0 ) != KSUCCESS ) {
-           return ( AFPERR_PARAM );
-       }
-       if ( krb_get_cred( name, instance, realm, &cr ) != KSUCCESS ) {
-           return ( AFPERR_BADUAM );
-       }
-
-       if ( unlink( tktfile ) < 0 ) {
-           LOG(log_error, logtype_default, "krb_login: unlink %s: %s", tktfile, strerror(errno) );
-           return ( AFPERR_BADUAM );
-       }
-
-       memcpy( seskey, cr.session, sizeof( C_Block ));
-       key_sched((C_Block *) seskey, seskeysched );
-       validseskey = 1;
-       strncpy(username, name, ulen);
-
-       memcpy( p, authent.dat, authent.length );
-       p += authent.length;
-    }
-
-    if ( kuam_get_in_tkt( name, instance, realm, TICKET_GRANTING_TICKET,
-           realm, 255, &rpkt ) != INTK_OK ) {
-       return ( AFPERR_PARAM );
-    }
-
-
-    q = (char *)rpkt.dat;
-    *p++ = *q++;
-    *p++ = *q++;
-    while ( *q++ )
-       ;
-    while ( *q++ )
-       ;
-    while ( *q++ )
-       ;
-    q += 10;
-
-    len = strlen( realm );
-    strcpy( p, realm );
-    p += len + 1;
-    memcpy( &slen, q, sizeof( short ));
-    memcpy( p, &slen, sizeof( short ));
-    p += sizeof( short );
-    q += sizeof( short );
-    memcpy( p, q, slen );
-    p += slen;
-
-    *rbuflen = p - rbuf;
-    return( AFPERR_AUTHCONT );
-}
-
-static int afskrb_logincont(void *obj, struct passwd *uam_pwd,
-                           char *ibuf, size_t ibuflen, 
-                           char *rbuf, size_t *rbuflen )
-{
-    CREDENTIALS                cr;
-    struct ViceIoctl   vi;
-    struct ClearToken  ct;
-    struct passwd      *pwd;
-    char               buf[ 1024 ], *p;
-    int                        aint;
-    short              clen;
-
-    *rbuflen = 0;
-    if (uam_afpserver_option(obj, UAM_OPTION_USERNAME, &username, NULL) < 0)
-      return AFPERR_MISC;
-    
-    ibuf += 2;
-    memcpy( &clen, ibuf, sizeof( short ));
-    clen = ntohs( clen );
-    ibuf += sizeof( short );
-
-    pcbc_encrypt((C_Block *)ibuf, (C_Block *)ibuf,
-           clen, seskeysched, seskey, DES_DECRYPT );
-    if ( kuam_set_in_tkt( name, instance, realm, TICKET_GRANTING_TICKET,
-           realm, ibuf ) != INTK_OK ) {
-       return ( AFPERR_PARAM );
-    }
-
-    if ( get_ad_tkt( "afs", "", realm, 255 ) != KSUCCESS ) {
-       return ( AFPERR_PARAM );
-    }
-    if ( krb_get_cred( "afs", "", realm, &cr ) != KSUCCESS ) {
-       return ( AFPERR_PARAM );
-    }
-
-    p = buf;
-    memcpy( p, &cr.ticket_st.length, sizeof( int ));
-    p += sizeof( int );
-    memcpy( p, cr.ticket_st.dat, cr.ticket_st.length );
-    p += cr.ticket_st.length;
-
-    ct.AuthHandle = cr.kvno;
-    memcpy( ct.HandShakeKey, cr.session, sizeof( cr.session ));
-    ct.ViceId = 0;
-    ct.BeginTimestamp = cr.issue_date;
-    /* ct.EndTimestamp = cr.issue_date + ( cr.lifetime * 5 * 60 ); */
-    ct.EndTimestamp = krb_life_to_time( cr.issue_date, cr.lifetime );
-
-    aint = sizeof( struct ClearToken );
-    memcpy( p, &aint, sizeof( int ));
-    p += sizeof( int );
-    memcpy( p, &ct, sizeof( struct ClearToken ));
-    p += sizeof( struct ClearToken );
-
-    aint = 0;
-    memcpy( p, &aint, sizeof( int ));
-    p += sizeof( int );
-
-    lcase( realm );
-    strcpy( p, realm );
-    p += strlen( realm ) + 1;
-
-    vi.in = buf;
-    vi.in_size = p - buf;
-    vi.out = buf;
-    vi.out_size = sizeof( buf );
-    if ( pioctl( 0, VIOCSETTOK, &vi, 0 ) < 0 ) {
-       LOG(log_error, logtype_default, "krb_logincont: pioctl: %s", strerror(errno) );
-       return ( AFPERR_BADUAM );
-    }
-
-    if ( unlink( tktfile ) < 0 ) {
-       LOG(log_error, logtype_default, "krb_logincont: %s: %s", tktfile, strerror(errno) );
-       return ( AFPERR_BADUAM );
-    }
-
-    if (( pwd = uam_getname( obj, username, strlen(username) )) == NULL ) {
-       return ( AFPERR_PARAM );
-    }
-
-    if ( logged == 0 ) {
-       logged = 1;
-       LOG(log_info, logtype_default, "authenticated %s.%s@%s", name, instance, realm );
-       *uam_pwd = pwd;
-       return AFP_OK;
-    }
-    LOG(log_info, logtype_default, "re-authenticated %s.%s@%s", name, instance, realm );
-    return( AFP_OK );
-}
-#endif /* UAM_AFSKRB AFS */
-
-static int uam_setup(const char *path)
-{
-#ifdef KRB
-   uam_register(UAM_SERVER_LOGIN, path, "Kerberos IV", krb4_login, 
-               krb4_logincont, NULL);
-   /* uam_afpserver_action(); */
-#endif /* KRB */
-#ifdef UAM_AFSKRB
-   uam_register(UAM_SERVER_LOGIN, path, "AFS Kerberos", afskrb_login, 
-               afskrb_logincont, NULL);
-   /* uam_afpserver_action(); */
-#endif /* UAM_AFSKRB */
-   return 0;
-}
-
-static void uam_cleanup(void)
-{
-#ifdef KRB
-   /* uam_afpserver_action(); */
-   uam_unregister(UAM_SERVER_LOGIN, "Kerberos IV");
-#endif
-#ifdef UAM_AFSKRB
-   /* uam_afpserver_action(); */
-   uam_unregister(UAM_SERVER_LOGIN, "AFS Kerberos");
-#endif
-}
-
-UAM_MODULE_EXPORT struct uam_export uams_krb4 = {
-  UAM_MODULE_SERVER,
-  UAM_MODULE_VERSION,
-  uam_setup, uam_cleanup
-};
-
-#endif /* KRB or UAM_AFSKRB */
-
index 46ce0d51a43d50d020b5737bb5797f9db2364cc4..6f15ac0a30c660bbdec3939e66b0059e06643f5f 100644 (file)
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif /* HAVE_UNISTD_H */
-
-/* STDC check */
-#if STDC_HEADERS
 #include <string.h>
-#else /* STDC_HEADERS */
-#ifndef HAVE_STRCHR
-#define strchr index
-#define strrchr index
-#endif /* HAVE_STRCHR */
-char *strchr (), *strrchr ();
-#ifndef HAVE_MEMCPY
-#define memcpy(d,s,n) bcopy ((s), (d), (n))
-#define memmove(d,s,n) bcopy ((s), (d), (n))
-#endif /* ! HAVE_MEMCPY */
-#endif /* STDC_HEADERS */
-
-#include <atalk/logger.h>
-
 #ifdef HAVE_SECURITY_PAM_APPL_H
 #include <security/pam_appl.h>
 #endif
 #ifdef HAVE_PAM_PAM_APPL_H
 #include <pam/pam_appl.h>
 #endif
+#include <arpa/inet.h>
 
 #include <atalk/afp.h>
 #include <atalk/uam.h>
 #include <atalk/util.h>
+#include <atalk/logger.h>
+#include <atalk/compat.h>
 
 #define PASSWDLEN 8
 
@@ -253,7 +239,7 @@ static int pam_login_ext(void *obj, char *uname, struct passwd **uam_pwd,
 {
     char *username; 
     size_t  len, ulen;
-    u_int16_t  temp16;
+    uint16_t  temp16;
 
     *rbuflen = 0;
 
index 36d7a387b7ef03ca209cb9e786aeb512ec065585..bec45a360813bd502affc3a9ac5eed8902f6fae3 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: uams_passwd.c,v 1.31 2010-03-30 12:44:35 franklahm Exp $
- *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * Copyright (c) 1999 Adrian Sun (asun@u.washington.edu) 
  * All Rights Reserved.  See COPYRIGHT.
 #include <sys/types.h>
 #include <stdio.h>
 #include <stdlib.h>
-/* STDC check */
-#if STDC_HEADERS
 #include <string.h>
-#else /* STDC_HEADERS */
-#ifndef HAVE_STRCHR
-#define strchr index
-#define strrchr index
-#endif /* HAVE_STRCHR */
-char *strchr (), *strrchr ();
-#ifndef HAVE_MEMCPY
-#define memcpy(d,s,n) bcopy ((s), (d), (n))
-#define memmove(d,s,n) bcopy ((s), (d), (n))
-#endif /* ! HAVE_MEMCPY */
-#endif /* STDC_HEADERS */
-#ifdef HAVE_UNISTD_H
 #include <unistd.h>
-#endif /* HAVE_UNISTD_H */
 #ifdef HAVE_CRYPT_H
 #include <crypt.h>
 #endif /* ! HAVE_CRYPT_H */
 #include <pwd.h>
-#ifdef HAVE_SYS_TIME_H
 #include <sys/time.h>
-#endif
-#ifdef HAVE_TIME_H
 #include <time.h>
-#endif
 #ifdef SHADOWPW
 #include <shadow.h>
 #endif /* SHADOWPW */
+#include <arpa/inet.h>
 
 #include <atalk/afp.h>
 #include <atalk/logger.h>
 #include <atalk/uam.h>
 #include <atalk/util.h>
+#include <atalk/compat.h>
 
 #define PASSWDLEN 8
 
@@ -198,7 +179,7 @@ static int passwd_login_ext(void *obj, char *uname, struct passwd **uam_pwd,
 {
     char       *username;
     size_t     len, ulen;
-    u_int16_t  temp16;
+    uint16_t  temp16;
 
     *rbuflen = 0;
 
index ec6d4095e17db4eea8caf3342e06d9a3cf0e0e4d..9b9c1d801dd57d53c543d8cdc1e11fb555f18f05 100644 (file)
@@ -53,7 +53,7 @@
 /* the secret key */
 static struct passwd *pgppwd;
 static CAST_KEY castkey;
-static u_int8_t randbuf[16];
+static uint8_t randbuf[16];
 
 /* pgp passwd */
 static int pgp_login(void *obj, struct passwd **uam_pwd,
@@ -109,7 +109,7 @@ static int pgp_logincont(void *obj, struct passwd **uam_pwd,
 {
        unsigned char iv[] = "RJscorat";
     BIGNUM *bn1, *bn2, *bn3;
-    u_int16_t sessid;
+    uint16_t sessid;
     char *p;
 
     *rbuflen = 0;
index 3d3a5bb9b72afc9bf267a03bb3682d9288f28d1f..301fdd0ff4cb69d48fe7e1f81d7572a954c7dfea 100644 (file)
 
 #include <stdio.h>
 #include <stdlib.h>
-
-/* STDC check */
-#if STDC_HEADERS
 #include <string.h>
-#else /* STDC_HEADERS */
-#ifndef HAVE_STRCHR
-#define strchr index
-#define strrchr index
-#endif /* HAVE_STRCHR */
-char *strchr (), *strrchr ();
-#ifndef HAVE_MEMCPY
-#define memcpy(d,s,n) bcopy ((s), (d), (n))
-#define memmove(d,s,n) bcopy ((s), (d), (n))
-#endif /* ! HAVE_MEMCPY */
-#endif /* STDC_HEADERS */
-
-#ifdef HAVE_UNISTD_H
 #include <unistd.h>
-#endif /* HAVE_UNISTD_H */
-#ifdef HAVE_FCNTL_H
 #include <fcntl.h>
-#endif /* HAVE_FCNTL_H */
 #include <ctype.h>
 #include <pwd.h>
 #include <sys/stat.h>
 #include <sys/param.h>
+#include <arpa/inet.h>
 
 #include <atalk/logger.h>
-
-#include <netatalk/endian.h>
-
 #include <atalk/afp.h>
 #include <atalk/uam.h>
 
@@ -58,7 +37,7 @@ char *strchr (), *strrchr ();
 static C_Block         seskey;
 static Key_schedule    seskeysched;
 static struct passwd   *randpwd;
-static u_int8_t         randbuf[8];
+static uint8_t         randbuf[8];
 
 /* hash to a 16-bit number. this will generate completely harmless 
  * warnings on 64-bit machines. */
@@ -144,7 +123,7 @@ static int afppasswd(const struct passwd *pwd,
                     unsigned char *passwd, int len, 
                     const int set)
 {
-  u_int8_t key[DES_KEY_SZ*2];
+  uint8_t key[DES_KEY_SZ*2];
   char buf[MAXPATHLEN + 1], *p;
   Key_schedule schedule;
   FILE *fp;
@@ -305,7 +284,7 @@ static int rand_login(void *obj, char *username, int ulen, struct passwd **uam_p
 {
 
   char *passwdfile;
-  u_int16_t sessid;
+  uint16_t sessid;
   size_t len;
   int err;
  
@@ -350,7 +329,7 @@ static int randnum_logincont(void *obj, struct passwd **uam_pwd,
                             char *ibuf, size_t ibuflen _U_, 
                             char *rbuf _U_, size_t *rbuflen)
 {
-  u_int16_t sessid;
+  uint16_t sessid;
 
   *rbuflen = 0;
 
@@ -389,7 +368,7 @@ static int rand2num_logincont(void *obj, struct passwd **uam_pwd,
                              char *ibuf, size_t ibuflen _U_, 
                              char *rbuf, size_t *rbuflen)
 {
-  u_int16_t sessid;
+  uint16_t sessid;
   unsigned int i;
 
   *rbuflen = 0;
@@ -532,7 +511,7 @@ static int randnum_login_ext(void *obj, char *uname, struct passwd **uam_pwd,
 {
     char       *username;
     size_t     len, ulen;
-    u_int16_t  temp16;
+    uint16_t  temp16;
 
     *rbuflen = 0;
 
index 895a5e778b39b68094b7bf7771c67cf63c08dec9..4ee8385436cbec5213219bccb5d72809e7b024c4 100644 (file)
@@ -1,4 +1,4 @@
 Makefile
 Makefile.in
-.gitignore
 *.o
+lockrpc.gen.h
\ No newline at end of file
index 3c1feda3c8dd05e272f84ff377078460e48b8c8f..a8f47137720a29d7eb5539e3df953e2f6ca763d0 100644 (file)
@@ -1,11 +1,42 @@
 # Makefile.am for include/atalk/
 
 atalkincludedir = $(includedir)/atalk
+
 atalkinclude_HEADERS = \
-       adouble.h vfs.h aep.h afp.h asp.h atp.h \
-       cnid.h compat.h ddp.h dsi.h ldapconfig.h list.h logger.h \
-       nbp.h netddp.h pap.h paths.h queue.h rtmp.h server_child.h \
-       server_ipc.h tdb.h uam.h unicode.h util.h uuid.h volinfo.h \
-       zip.h ea.h acl.h unix.h directory.h hash.h volume.h
+       adouble.h \
+       afp.h \
+       vfs.h \
+       cnid.h \
+       logger.h \
+       paths.h \
+       unicode.h \
+       util.h \
+       volinfo.h \
+       ea.h \
+       acl.h \
+       unix.h \
+       volume.h
 
-noinst_HEADERS = cnid_dbd_private.h cnid_private.h bstradd.h bstrlib.h errchk.h ftw.h globals.h fce_api.h standards.h
+noinst_HEADERS = \
+       directory.h \
+       hash.h \
+       zip.h \
+       uuid.h \
+       queue.h \
+       server_child.h \
+       server_ipc.h \
+       tdb.h \
+       uam.h \
+       cnid_dbd_private.h \
+       cnid_private.h \
+       bstradd.h \
+       bstrlib.h \
+       errchk.h \
+       ftw.h \
+       compat.h \
+       dsi.h \
+       ldapconfig.h \
+       list.h \
+       globals.h \
+       fce_api.h \
+       standards.h
index 78a35b02909ecd932bbf86d00cb5d908402e9426..1b1a16fbf0746c5da93fdae7a64795ebbf18a210 100644 (file)
@@ -1,5 +1,4 @@
 /*
- * $Id: adouble.h,v 1.55 2010-03-30 12:55:26 franklahm Exp $
  * Copyright (c) 1990,1991 Regents of The University of Michigan.
  * All Rights Reserved.
  *
 
 #include <atalk/standards.h>
 
+#include <inttypes.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-
-#ifdef HAVE_UNISTD_H
-#undef __USE_MISC
-#define __USE_MISC
 #include <unistd.h>
-#endif
-
-#include <sys/cdefs.h>
-
-#ifdef HAVE_FCNTL_H
 #include <fcntl.h>
-#endif
 
 #include <sys/mman.h>
 
-#ifdef HAVE_SYS_TIME_H
 #include <sys/time.h>
-#endif
-#include <netatalk/endian.h>
 
-/* version info */
-#define AD_VERSION1     0x00010000
-#define SFM_VERSION     AD_VERSION1
+#include <atalk/bstrlib.h>
 
+/* version info */
 #define AD_VERSION2     0x00020000
-#define AD_VERSION2_OSX 0x00020001
-/*
-  #define AD_VERSION1_ADS 0x00010002
-*/
-#define AD_VERSION1_SFM 0x00010003
+#define AD_VERSION_EA   0x00020002
+
+/* default */
 #define AD_VERSION      AD_VERSION2
 
 /*
@@ -75,7 +59,7 @@
  */
 #define ADEID_DFORK         1
 #define ADEID_RFORK         2
-#define ADEID_NAME          3 /* Note: starting with Netatalk 2.1 we do NOT alway set the name */
+#define ADEID_NAME          3
 #define ADEID_COMMENT       4
 #define ADEID_ICONBW        5
 #define ADEID_ICONCOL       6
 #define ADEID_AFPFILEI      14 /* where the rest of the FILEI info goes */
 #define ADEID_DID           15
 
-#if AD_VERSION == AD_VERSION1
-#define ADEID_MAX           16
-#else
 /* netatalk private note fileid reused DID */
 #define ADEID_PRIVDEV       16
 #define ADEID_PRIVINO       17
 #define ADEID_PRIVSYN       18 /* in synch with database */
 #define ADEID_PRIVID        19
-#define ADEID_SFMRESERVE1   20
-#define ADEID_SFMRESERVE2   21
+#define ADEID_MAX           (ADEID_PRIVID + 1)
 
+/* These are the real ids for these entries, as stored in the adouble file */
 #define AD_DEV              0x80444556
 #define AD_INO              0x80494E4F
 #define AD_SYN              0x8053594E
 #define AD_ID               0x8053567E
-#define ADEID_MAX           22
-#endif
 
 /* magic */
 #define AD_APPLESINGLE_MAGIC 0x00051600
 #define AD_APPLEDOUBLE_MAGIC 0x00051607
 #define AD_MAGIC             AD_APPLEDOUBLE_MAGIC
-#define SFM_MAGIC            0x00504641
 
 /* sizes of relevant entry bits */
 #define ADEDLEN_MAGIC       4
 #define ADEDLEN_VERSION     4
 #define ADEDLEN_FILLER      16
 #define ADEDLEN_NENTRIES    2
-
-/* 26 */
-#define AD_HEADER_LEN       (ADEDLEN_MAGIC + ADEDLEN_VERSION + \
-                             ADEDLEN_FILLER + ADEDLEN_NENTRIES)
+#define AD_HEADER_LEN       (ADEDLEN_MAGIC + ADEDLEN_VERSION + ADEDLEN_FILLER + ADEDLEN_NENTRIES)
 #define AD_ENTRY_LEN        12  /* size of a single entry header */
 
-/* v1 field widths */
-#define ADEDLEN_NAME        255
-#define ADEDLEN_COMMENT     200
-#define ADEDLEN_FILEI       16
-#define ADEDLEN_FINDERI     32
-
-/* v2 field widths */
+/* field widths */
+#define ADEDLEN_NAME            255
+#define ADEDLEN_COMMENT         200
+#define ADEDLEN_FILEI           16
+#define ADEDLEN_FINDERI         32
 #define ADEDLEN_FILEDATESI      16
 #define ADEDLEN_SHORTNAME       12 /* length up to 8.3 */
 #define ADEDLEN_AFPFILEI        4
 #define ADEDLEN_PRIVSYN         8
 #define ADEDLEN_PRIVID          4
 
-#define ADEID_NUM_V1            5
 #define ADEID_NUM_V2            13
+#define ADEID_NUM_EA            5
 
-// #define ADEID_NUM_SFM        5
-/* sizeof SFM meta data */
-#define AD_SFM_LEN 60
-
-/* 589 */
-#define AD_DATASZ1      (AD_HEADER_LEN + ADEDLEN_NAME + ADEDLEN_COMMENT + ADEDLEN_FILEI + ADEDLEN_FINDERI + \
-                         (ADEID_NUM_V1 * AD_ENTRY_LEN))
-
-#if AD_DATASZ1 != 589
-#error bad size for AD_DATASZ1
-#endif
-
-#define AD_NEWSZ2       (ADEDLEN_DID + ADEDLEN_AFPFILEI + ADEDLEN_SHORTNAME + ADEDLEN_PRODOSFILEI \
-                         + ADEDLEN_PRIVDEV + ADEDLEN_PRIVINO + ADEDLEN_PRIVSYN + ADEDLEN_PRIVID)
-
-/* 725 */
-#define AD_DATASZ2      (AD_DATASZ1 + AD_NEWSZ2 + ((ADEID_NUM_V2 - ADEID_NUM_V1) * AD_ENTRY_LEN))
-
+#define AD_DATASZ2 (AD_HEADER_LEN + ADEDLEN_NAME + ADEDLEN_COMMENT + ADEDLEN_FILEI + \
+                    ADEDLEN_FINDERI + ADEDLEN_DID + ADEDLEN_AFPFILEI + ADEDLEN_SHORTNAME + \
+                    ADEDLEN_PRODOSFILEI + ADEDLEN_PRIVDEV + ADEDLEN_PRIVINO + \
+                    ADEDLEN_PRIVSYN + ADEDLEN_PRIVID + (ADEID_NUM_V2 * AD_ENTRY_LEN))
 #if AD_DATASZ2 != 741
 #error bad size for AD_DATASZ2
 #endif
 
-#define AD_DATASZ_MAX   1024
-#if AD_VERSION == AD_VERSION1
-#define AD_DATASZ   AD_DATASZ1 /* hold enough for the entries */
-#elif AD_VERSION == AD_VERSION2
-#define AD_DATASZ   AD_DATASZ2
+#define AD_DATASZ_EA (AD_HEADER_LEN + (ADEID_NUM_EA * AD_ENTRY_LEN) + ADEDLEN_FINDERI + \
+                      ADEDLEN_COMMENT + ADEDLEN_FILEDATESI + ADEDLEN_AFPFILEI + ADEDLEN_PRIVID)
+
+#if AD_DATASZ_EA != 342
+#error bad size for AD_DATASZ_EA
 #endif
 
-/*
- * some legacy defines from netatalk-990130
- * (to keep from breaking certain packages)
- *
- */
+#define AD_DATASZ_MAX   1024
 
-#define ADEDOFF_RFORK   589
-#define ADEDOFF_NAME    86
-#define ADEDOFF_COMMENT 341
-#define ADEDOFF_FINDERI 557
-#ifndef ADEDOFF_FILEI
-#define ADEDOFF_FILEI   541
+#if AD_VERSION == AD_VERSION2
+#define AD_DATASZ   AD_DATASZ2
+#elif AD_VERSION == AD_VERSION_EA
+#define AD_DATASZ   AD_DATASZ_EA
 #endif
 
-typedef u_int32_t cnid_t;
+#define RFORK_EA_ALLOCSIZE (128*1024) /* 128k */
 
-/*
- * The header of the AppleDouble Header File looks like this:
- *
- *  NAME            SIZE
- *  ====            ====
- *  Magic           4
- *  Version         4
- *  Home File System    16  (this becomes filler in ad v2)
- *  Number of Entries   2
- *  Entry Descriptors for each entry:
- *      Entry ID    4
- *      Offset      4
- *      Length      4
- */
+typedef uint32_t cnid_t;
 
 struct ad_entry {
-    off_t   ade_off;
+    off_t     ade_off;
     ssize_t   ade_len;
 };
 
@@ -219,75 +159,73 @@ typedef struct adf_lock_t {
 
 struct ad_fd {
     int          adf_fd;        /* -1: invalid, -2: symlink */
-
-#ifndef HAVE_PREAD
-    off_t        adf_off;
-#endif
-
     char         *adf_syml;
     int          adf_flags;
-    int          adf_excl;
     adf_lock_t   *adf_lock;
     int          adf_refcount, adf_lockcount, adf_lockmax;
 };
 
 /* some header protection */
 #define AD_INITED  0xad494e54  /* ad"INT" */
-struct adouble_fops;
+#define AD_CLOSED  0xadc10ced
 
-struct adouble {
-    u_int32_t           ad_magic;
-    u_int32_t           ad_version;
-    char                ad_filler[ 16 ];
-    struct ad_entry     ad_eid[ ADEID_MAX ];
-    struct ad_fd        ad_data_fork, ad_resource_fork, ad_metadata_fork;
-    struct ad_fd        *ad_md; /* either ad_resource or ad_metadata */
-
-    int                 ad_flags;    /* This really stores version info too (AD_VERSION*) */
-    int                 ad_adflags;  /* ad_open flags adflags like ADFLAGS_DIR */
-    unsigned int        ad_inited;
-    int                 ad_options;
-    int                 ad_fileordir;
-    int                 ad_refcount; /* used in afpd/ofork.c */
-    off_t               ad_rlen;     /* ressource fork len with AFP 3.0
-                                        the header parameter size is too small.
-                                     */
-    char                *ad_m_name;   /* mac name for open fork */
-    int                 ad_m_namelen;
-    struct adouble_fops *ad_ops;
-    u_int16_t       ad_open_forks;      /* open forks (by others) */
-
-#ifdef USE_MMAPPED_HEADERS
-    char                *ad_data;
-#else
-    char        ad_data[AD_DATASZ_MAX];
-#endif
-};
+struct adouble;
 
 struct adouble_fops {
-    char *(*ad_path)(const char *, int);
-    int  (*ad_mkrf)(char *);
+    const char *(*ad_path)(const char *, int);
+    int  (*ad_mkrf)(const char *);
     int  (*ad_rebuild_header)(struct adouble *);
-    int  (*ad_check_header)(struct adouble *, struct stat *);
     int  (*ad_header_read)(struct adouble *, struct stat *);
-    int  (*ad_header_upgrade)(struct adouble *, char *);
+    int  (*ad_header_upgrade)(struct adouble *, const char *);
+};
+
+struct adouble {
+    uint32_t            ad_magic;         /* Official adouble magic                   */
+    uint32_t            ad_version;       /* Official adouble version number          */
+    char                ad_filler[16];
+    struct ad_entry     ad_eid[ADEID_MAX];
+    struct ad_fd        ad_data_fork;     /* the data fork                            */
+    struct ad_fd        ad_resource_fork; /* adouble:v2 -> the adouble file           *
+                                           * adouble:ea -> unused                     */
+    struct ad_fd        *ad_rfp;          /* adouble:v2 -> ad_resource_fork           *
+                                           * adouble:ea -> ad_data_fork               */
+    struct ad_fd        *ad_mdp;          /* adouble:v2 -> ad_resource_fork           *
+                                           * adouble:ea -> ad_data_fork               */
+    int                 ad_flags;         /* Our adouble version info (AD_VERSION*)   */
+    int                 ad_adflags;       /* ad_open flags adflags like ADFLAGS_DIR   */
+    uint32_t            ad_inited;
+    int                 ad_options;
+    int                 ad_refcount;       /* multiple forks may open one adouble     */
+    void                *ad_resforkbuf;    /* buffer for AD_VERSION_EA ressource fork */
+    size_t              ad_resforkbufsize; /* size of ad_resforkbuf                   */
+    size_t              ad_maxeafssize;    /* maximum EA size allowed from the fs     */
+    off_t               ad_rlen;           /* ressource fork len with AFP 3.0         *
+                                            * the header parameter size is too small. */
+    char                *ad_m_name;        /* mac name for open fork                  */
+    int                 ad_m_namelen;
+    struct adouble_fops *ad_ops;
+    uint16_t            ad_open_forks;     /* open forks (by others)                  */
+    char                ad_data[AD_DATASZ_MAX];
 };
 
 #define ADFLAGS_DF        (1<<0)
-#define ADFLAGS_HF        (1<<1)
-#define ADFLAGS_DIR       (1<<2)
-/*
-#define ADFLAGS_NOADOUBLE (1<<3)
-*/
-#define ADFLAGS_V1COMPAT  (1<<4)
-#define ADFLAGS_NOHF      (1<<5)  /* not an error if no ressource fork */
-#define ADFLAGS_RDONLY    (1<<6)  /* don't try readwrite */
-#define ADFLAGS_OPENFORKS (1<<7)  /* check for open fork in ad_metadata function */
-#define ADFLAGS_RF        (1<<8)
-#define ADFLAGS_MD        ADFLAGS_HF /* (1<<9) */
-#define ADFLAGS_CREATE    (1<<9)
-
-/* adouble v2 cnid cache */
+#define ADFLAGS_RF        (1<<1)
+#define ADFLAGS_HF        (1<<2)
+#define ADFLAGS_DIR       (1<<3)
+#define ADFLAGS_NOHF      (1<<4)  /* not an error if no ressource fork */
+#define ADFLAGS_CHECK_OF  (1<<6)  /* check for open forks from us and other afpd's */
+#define ADFLAGS_SETSHRMD  (1<<7)  /* setting share mode must be done with excl fcnt lock,
+                                     which implies that the file must be openend rw.
+                                     If it can't be opened rw (eg EPERM or EROFS) it will
+                                     be opened ro and the fcntl locks will be shared, that
+                                     at least prevent other users who have rw access to the
+                                     file from placing excl locks. */
+#define ADFLAGS_RDWR      (1<<8)  /* open read/write */
+#define ADFLAGS_RDONLY    (1<<9)  /* open read only */
+#define ADFLAGS_CREATE    (1<<10)  /* create file, open called with O_CREAT */
+#define ADFLAGS_EXCL      (1<<11)  /* exclusive open, open called with O_EXCL */
+#define ADFLAGS_TRUNC     (1<<12) /* truncate, open called with O_TRUNC */
+
 #define ADVOL_NODEV      (1 << 0)
 #define ADVOL_CACHE      (1 << 1)
 #define ADVOL_UNIXPRIV   (1 << 2) /* adouble unix priv */
@@ -303,39 +241,29 @@ struct adouble_fops {
 #define ADLOCK_FILELOCK (1<<3)
 
 /* we use this so that we can use the same mechanism for both byte
- * locks and file synchronization locks. i do this by co-opting either
- * first bits on 32-bit machines or shifting above the last bit on
- * 64-bit machines. this only matters for the data fork. */
-#if defined(TRY_64BITOFF_T) && (~0UL > 0xFFFFFFFFU)
-/* synchronization locks */
-#define AD_FILELOCK_BASE (0x80000000)
-#else
+ * locks and file synchronization locks. */
 #if _FILE_OFFSET_BITS == 64
-#define AD_FILELOCK_BASE (0x7FFFFFFFFFFFFFFFULL - 9)
+#define AD_FILELOCK_BASE (UINT64_C(0x7FFFFFFFFFFFFFFF) - 9)
 #else
-#define AD_FILELOCK_BASE (0x7FFFFFFF -9)
-#endif
+#define AD_FILELOCK_BASE (UINT32_C(0x7FFFFFFF) - 9)
 #endif
 
-/* FIXME:
- * AD_FILELOCK_BASE case
- */
-#if _FILE_OFFSET_BITS == 64
-#define BYTELOCK_MAX (0x7FFFFFFFFFFFFFFFULL)
-#else
-/* Tru64 is an always-64-bit OS; version 4.0 does not set _FILE_OFFSET_BITS */
-#if defined(TRU64)
-#define BYTELOCK_MAX (0x7FFFFFFFFFFFFFFFULL)
-#else
-#define BYTELOCK_MAX (0x7FFFFFFFU)
-#endif
-#endif
+#define BYTELOCK_MAX (AD_FILELOCK_BASE - 1)
 
+/* datafork and rsrcfork sharemode locks */
 #define AD_FILELOCK_OPEN_WR        (AD_FILELOCK_BASE + 0)
 #define AD_FILELOCK_OPEN_RD        (AD_FILELOCK_BASE + 1)
-#define AD_FILELOCK_DENY_WR        (AD_FILELOCK_BASE + 2)
-#define AD_FILELOCK_DENY_RD        (AD_FILELOCK_BASE + 3)
-#define AD_FILELOCK_OPEN_NONE      (AD_FILELOCK_BASE + 4)
+#define AD_FILELOCK_RSRC_OPEN_WR   (AD_FILELOCK_BASE + 2)
+#define AD_FILELOCK_RSRC_OPEN_RD   (AD_FILELOCK_BASE + 3)
+
+#define AD_FILELOCK_DENY_WR        (AD_FILELOCK_BASE + 4)
+#define AD_FILELOCK_DENY_RD        (AD_FILELOCK_BASE + 5)
+#define AD_FILELOCK_RSRC_DENY_WR   (AD_FILELOCK_BASE + 6)
+#define AD_FILELOCK_RSRC_DENY_RD   (AD_FILELOCK_BASE + 7)
+
+
+#define AD_FILELOCK_OPEN_NONE      (AD_FILELOCK_BASE + 8)
+#define AD_FILELOCK_RSRC_OPEN_NONE (AD_FILELOCK_BASE + 9)
 
 /* time stuff. we overload the bits a little.  */
 #define AD_DATE_CREATE         0
@@ -404,8 +332,8 @@ struct adouble_fops {
 #define AD_AFPFILEI_BLANKACCESS (1 << 2) /* blank access permissions */
 
 #define ad_data_fileno(ad)  ((ad)->ad_data_fork.adf_fd)
-#define ad_reso_fileno(ad)  ((ad)->ad_resource_fork.adf_fd)
-#define ad_meta_fileno(ad)  ((ad)->ad_md->adf_fd)
+#define ad_reso_fileno(ad)  ((ad)->ad_rfp->adf_fd)
+#define ad_meta_fileno(ad)  ((ad)->ad_mdp->adf_fd)
 
 #define ad_getversion(ad)   ((ad)->ad_version)
 
@@ -414,8 +342,12 @@ struct adouble_fops {
 #define ad_getentryoff(ad,eid)     ((ad)->ad_eid[(eid)].ade_off)
 #define ad_entry(ad,eid)           ((caddr_t)(ad)->ad_data + (ad)->ad_eid[(eid)].ade_off)
 
-#define ad_get_HF_flags(ad) ((ad)->ad_resource_fork.adf_flags)
-#define ad_get_MD_flags(ad) ((ad)->ad_md->adf_flags)
+#define ad_get_RF_flags(ad) ((ad)->ad_rfp->adf_flags)
+#define ad_get_MD_flags(ad) ((ad)->ad_mdp->adf_flags)
+
+/* Refcounting open forks using one struct adouble */
+#define ad_ref(ad)   (ad)->ad_refcount++
+#define ad_unref(ad) --((ad)->ad_refcount)
 
 /* ad_flush.c */
 extern int ad_rebuild_adouble_header (struct adouble *);
@@ -425,45 +357,31 @@ extern int ad_flush (struct adouble *);
 extern int ad_close (struct adouble *, int);
 
 /* ad_lock.c */
-extern int ad_fcntl_lock    (struct adouble *, const u_int32_t /*eid*/,
-                                 const int /*type*/, const off_t /*offset*/,
-                                 const off_t /*len*/, const int /*user*/);
-extern void ad_fcntl_unlock (struct adouble *, const int /*user*/);
-extern int ad_fcntl_tmplock (struct adouble *, const u_int32_t /*eid*/,
-                                 const int /*type*/, const off_t /*offset*/,
-                                 const off_t /*len*/, const int /*user*/);
-extern int ad_testlock      (struct adouble * /*adp*/, int /*eid*/, off_t /*off*/);
-
-extern u_int16_t ad_openforks (struct adouble * /*adp*/, u_int16_t);
-extern int ad_excl_lock     (struct adouble * /*adp*/, const u_int32_t /*eid*/);
-
-#define ad_lock ad_fcntl_lock
-#define ad_tmplock ad_fcntl_tmplock
-#define ad_unlock ad_fcntl_unlock
+extern int ad_testlock      (struct adouble *adp, int eid, off_t off);
+extern uint16_t ad_openforks(struct adouble *adp, uint16_t);
+extern int ad_lock(struct adouble *, uint32_t eid, int type, off_t off, off_t len, int user);
+extern void ad_unlock(struct adouble *, int user);
+extern int ad_tmplock(struct adouble *, uint32_t eid, int type, off_t off, off_t len, int user);
 
 /* ad_open.c */
+extern const char *adflags2logstr(int adflags);
 extern int ad_setfuid     (const uid_t );
 extern uid_t ad_getfuid   (void );
 extern char *ad_dir       (const char *);
-extern char *ad_path      (const char *, int);
-extern char *ad_path_osx  (const char *, int);
-extern char *ad_path_ads  (const char *, int);
-extern char *ad_path_sfm  (const char *, int);
+extern const char *ad_path      (const char *, int);
+extern const char *ad_path_ea   (const char *, int);
 extern int ad_mode        (const char *, int);
 extern int ad_mkdir       (const char *, int);
-extern void ad_init       (struct adouble *, int, int );
-extern int ad_open        (const char *, int, int, int, struct adouble *);
-extern int ad_openat      (int dirfd, const char *, int, int, int, struct adouble *);
+struct vol;
+extern void ad_init       (struct adouble *, const struct vol * restrict);
+extern void ad_init_old   (struct adouble *ad, int flags, int options);
+extern int ad_open        (struct adouble *ad, const char *path, int adflags, ...);
+extern int ad_openat      (struct adouble *, int dirfd, const char *path, int adflags, ...);
 extern int ad_refresh     (struct adouble *);
 extern int ad_stat        (const char *, struct stat *);
 extern int ad_metadata    (const char *, int, struct adouble *);
 extern int ad_metadataat  (int, const char *, int, struct adouble *);
 
-#define ad_open_metadata(name, flags, mode, adp)\
-   ad_open(name, ADFLAGS_MD|(flags), O_RDWR |(mode), 0666, (adp))
-
-#define ad_close_metadata(adp) ad_close( (adp), ADFLAGS_MD)
-
 /* build a resource fork mode from the data fork mode:
  * remove X mode and extend header to RW if R or W (W if R for locking),
  */
@@ -489,74 +407,38 @@ static inline mode_t ad_hf_mode (mode_t mode)
     return mode;
 }
 
-/* ad_ea.c */
-ssize_t sys_getxattr (const char *path, const char *name, void *value, size_t size);
-ssize_t sys_lgetxattr (const char *path, const char *name, void *value, size_t size);
-ssize_t sys_fgetxattr (int filedes, const char *name, void *value, size_t size);
-ssize_t sys_listxattr (const char *path, char *list, size_t size);
-ssize_t sys_llistxattr (const char *path, char *list, size_t size);
-ssize_t sys_flistxattr (int filedes, char *list, size_t size);
-int sys_removexattr (const char *path, const char *name);
-int sys_lremovexattr (const char *path, const char *name);
-int sys_fremovexattr (int filedes, const char *name);
-int sys_setxattr (const char *path, const char *name, const void *value, size_t size, int flags);
-int sys_lsetxattr (const char *path, const char *name, const void *value, size_t size, int flags);
-int sys_fsetxattr (int filedes, const char *name, const void *value, size_t size, int flags);
-int sys_copyxattr (const char *src, const char *dst);
-
 /* ad_read.c/ad_write.c */
 extern int     sys_ftruncate(int fd, off_t length);
-
-extern ssize_t ad_read (struct adouble *, const u_int32_t,
-                            const off_t, char *, const size_t);
-extern ssize_t ad_pread (struct ad_fd *, void *, size_t, off_t);
-extern ssize_t ad_write (struct adouble *, const u_int32_t, off_t,
-                             const int, const char *, const size_t);
-extern ssize_t adf_pread  (struct ad_fd *, void *, size_t, off_t);
-extern ssize_t adf_pwrite (struct ad_fd *, const void *, size_t, off_t);
-extern int     ad_dtruncate (struct adouble *, const off_t);
-extern int     ad_rtruncate (struct adouble *, const off_t);
+extern ssize_t ad_read(struct adouble *, uint32_t, off_t, char *, size_t);
+extern ssize_t ad_pread(struct ad_fd *, void *, size_t, off_t);
+extern ssize_t ad_write(struct adouble *, uint32_t, off_t, int, const char *, size_t);
+extern ssize_t adf_pread(struct ad_fd *, void *, size_t, off_t);
+extern ssize_t adf_pwrite(struct ad_fd *, const void *, size_t, off_t);
+extern int     ad_dtruncate(struct adouble *, off_t);
+extern int     ad_rtruncate(struct adouble *, off_t);
 
 /* ad_size.c */
-extern off_t ad_size (const struct adouble *, const u_int32_t );
+extern off_t ad_size (const struct adouble *, uint32_t );
 
 /* ad_mmap.c */
-extern void *ad_mmapread (struct adouble *, const u_int32_t,
-                              const off_t, const size_t);
-extern void *ad_mmapwrite (struct adouble *, const u_int32_t,
-                               const off_t, const int, const size_t);
+extern void *ad_mmapread(struct adouble *, uint32_t, off_t, size_t);
+extern void *ad_mmapwrite(struct adouble *, uint32_t, off_t, int, size_t);
 #define ad_munmap(buf, len)  (munmap((buf), (len)))
 
 /* ad_date.c */
-extern int ad_setdate (struct adouble *, unsigned int, u_int32_t);
-extern int ad_getdate (const struct adouble *, unsigned int, u_int32_t *);
+extern int ad_setdate(struct adouble *, unsigned int, uint32_t);
+extern int ad_getdate(const struct adouble *, unsigned int, uint32_t *);
 
 /* ad_attr.c */
-extern int       ad_setattr (const struct adouble *, const u_int16_t);
-extern int       ad_getattr (const struct adouble *, u_int16_t *);
-
-/* Note: starting with Netatalk 2.1 we do NOT alway set the name */
-extern int       ad_setname (struct adouble *, const char *);
-
-#if AD_VERSION == AD_VERSION2
-extern int       ad_setid (struct adouble *, const dev_t dev,const ino_t ino, const u_int32_t, const u_int32_t, const void *);
-extern u_int32_t ad_getid (struct adouble *, const dev_t, const ino_t, const cnid_t, const void *);
-extern u_int32_t ad_forcegetid (struct adouble *adp);
-#else
-#define ad_setid(a, b, c)
-#endif
+extern int       ad_setattr(const struct adouble *, uint16_t);
+extern int       ad_getattr(const struct adouble *, uint16_t *);
+extern int       ad_setname(struct adouble *, const char *);
+extern int       ad_setid(struct adouble *, dev_t dev, ino_t ino, uint32_t, uint32_t, const void *);
+extern uint32_t  ad_getid(struct adouble *, dev_t, ino_t, cnid_t, const void *);
+extern uint32_t  ad_forcegetid(struct adouble *adp);
 
 #ifdef WITH_SENDFILE
-extern int ad_readfile_init(const struct adouble *ad, 
-                                      const int eid, off_t *off,
-                                      const int end);
+extern int ad_readfile_init(const struct adouble *ad, int eid, off_t *off, int end);
 #endif
 
-#if 0
-#ifdef HAVE_SENDFILE_WRITE
-extern ssize_t ad_writefile (struct adouble *, const int,
-                                 const int, off_t, const int, const size_t);
-#endif /* HAVE_SENDFILE_WRITE */
-#endif /* 0 */
-
 #endif /* _ATALK_ADOUBLE_H */
diff --git a/include/atalk/aep.h b/include/atalk/aep.h
deleted file mode 100644 (file)
index 11176ab..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- * All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software and
- * its documentation for any purpose and without fee is hereby granted,
- * provided that the above copyright notice appears in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation, and that the name of The University
- * of Michigan not be used in advertising or publicity pertaining to
- * distribution of the software without specific, written prior
- * permission. This software is supplied as is without expressed or
- * implied warranties of any kind.
- *
- *     Research Systems Unix Group
- *     The University of Michigan
- *     c/o Mike Clark
- *     535 W. William Street
- *     Ann Arbor, Michigan
- *     +1-313-763-0525
- *     netatalk@itd.umich.edu
- */
-
-#ifndef _ATALK_AEP_H
-#define _ATALK_AEP_H 1
-
-#ifndef NO_DDP
-
-#define AEPOP_REQUEST  1
-#define AEPOP_REPLY    2
-
-#endif  /* NO_DDP */
-#endif
index 303e705047f58fa5b7b88a799222034dcb282670..c81371364cc79f5040b40caaaeb5d21d4b9685ab 100644 (file)
 #ifndef _ATALK_AFP_H
 #define _ATALK_AFP_H 1
 
+#include <stdint.h>
 #include <sys/types.h>
-#include <netatalk/endian.h>
 
-typedef u_int16_t AFPUserBytes;
+typedef uint16_t AFPUserBytes;
 
 /* protocols */
 #define AFPPROTO_ASP           1
diff --git a/include/atalk/asp.h b/include/atalk/asp.h
deleted file mode 100644 (file)
index 3c7252d..0000000
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- * All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software and
- * its documentation for any purpose and without fee is hereby granted,
- * provided that the above copyright notice appears in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation, and that the name of The University
- * of Michigan not be used in advertising or publicity pertaining to
- * distribution of the software without specific, written prior
- * permission. This software is supplied as is without expressed or
- * implied warranties of any kind.
- *
- *     Research Systems Unix Group
- *     The University of Michigan
- *     c/o Mike Clark
- *     535 W. William Street
- *     Ann Arbor, Michigan
- *     +1-313-763-0525
- *     netatalk@itd.umich.edu
- */
-
-#ifndef _ATALK_ASP_H
-#define _ATALK_ASP_H 1
-
-#ifndef NO_DDP
-
-#include <sys/types.h>
-#include <sys/cdefs.h>
-#include <netatalk/endian.h>
-#include <netatalk/at.h>
-#include <atalk/atp.h>
-#include <atalk/afp.h>
-#include <atalk/server_child.h>
-
-#define ASP_HDRSIZ        4
-#define ASP_CMDSIZ        578
-
-#define ASP_MAXPACKETS    8
-#define ASP_CMDMAXSIZ     (ASP_CMDSIZ + ASP_HDRSIZ)
-#define ASP_DATASIZ       (ASP_CMDSIZ*ASP_MAXPACKETS)
-#define ASP_DATAMAXSIZ    ((ASP_CMDSIZ + ASP_HDRSIZ)*ASP_MAXPACKETS)
-
-typedef struct ASP {
-    ATP                        asp_atp;
-    struct sockaddr_at asp_sat;
-    u_int8_t           asp_wss;
-    u_int8_t            asp_sid;
-    union {
-       struct {
-           char                        *as_status;
-           int                         as_slen;
-       }                       asu_status;
-       u_int16_t               asu_seq;
-    }                  asp_u;
-#define asp_status     asp_u.asu_status.as_status
-#define asp_slen       asp_u.asu_status.as_slen
-#define asp_seq                asp_u.asu_seq
-    int                        asp_flags;
-    char               child, inited, *commands;
-    char                cmdbuf[ASP_CMDMAXSIZ];
-    char                data[ASP_DATAMAXSIZ];  
-    size_t             cmdlen, datalen;
-    off_t              read_count, write_count;
-} *ASP;
-
-#define ASPFL_SLS      1
-#define ASPFL_SSS      2
-
-#define ASPFUNC_CLOSE  1
-#define ASPFUNC_CMD    2
-#define ASPFUNC_STAT   3
-#define ASPFUNC_OPEN   4
-#define ASPFUNC_TICKLE 5
-#define ASPFUNC_WRITE  6
-#define ASPFUNC_WRTCONT        7
-#define ASPFUNC_ATTN   8
-
-#define ASPERR_OK      0x0000
-#define ASPERR_BADVERS 0xfbd6
-#define ASPERR_BUFSMALL        0xfbd5
-#define ASPERR_NOSESS  0xfbd4
-#define ASPERR_NOSERV  0xfbd3
-#define ASPERR_PARM    0xfbd2
-#define ASPERR_SERVBUSY        0xfbd1
-#define ASPERR_SESSCLOS        0xfbd0
-#define ASPERR_SIZERR  0xfbcf
-#define ASPERR_TOOMANY 0xfbce
-#define ASPERR_NOACK   0xfbcd
-
-extern ASP asp_init         (ATP);
-extern void asp_setstatus   (ASP, char *, const int);
-extern ASP asp_getsession   (ASP, server_child *, const int);
-extern int asp_close        (ASP);
-extern int asp_shutdown     (ASP);
-extern int asp_attention    (ASP, AFPUserBytes);
-extern int asp_getrequest   (ASP);
-extern int asp_cmdreply     (ASP, int);
-extern int asp_wrtcont      (ASP, char *, size_t *);
-#define asp_wrtreply(a,b)   asp_cmdreply((a), (b))
-extern void asp_kill        (int);
-extern int asp_tickle      (ASP, const u_int8_t, struct sockaddr_at *);
-extern void asp_stop_tickle (void);
-
-#endif  /* NO_DDP */
-#endif
diff --git a/include/atalk/atp.h b/include/atalk/atp.h
deleted file mode 100644 (file)
index 9618e75..0000000
+++ /dev/null
@@ -1,196 +0,0 @@
-/*
- * $Id: atp.h,v 1.5 2009-10-13 22:55:37 didg Exp $
- *
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- * All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software and
- * its documentation for any purpose and without fee is hereby granted,
- * provided that the above copyright notice appears in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation, and that the name of The University
- * of Michigan not be used in advertising or publicity pertaining to
- * distribution of the software without specific, written prior
- * permission. This software is supplied as is without expressed or
- * implied warranties of any kind.
- *
- *     Research Systems Unix Group
- *     The University of Michigan
- *     c/o Mike Clark
- *     535 W. William Street
- *     Ann Arbor, Michigan
- *     +1-313-763-0525
- *     netatalk@itd.umich.edu
- */
-
-#ifndef _ATALK_ATP_H
-#define _ATALK_ATP_H 1
-
-#ifndef NO_DDP
-#include <sys/cdefs.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <netatalk/at.h>
-#include <netatalk/endian.h>
-
-/* ATP packet format
-
- |----------------|
- | link header    |
- |      ...       |
- |----------------|
- | DDP header     |
- |      ...       |
- |   type = 3     |
- |----------------|
- | control info   | --> bits 7,6: function code
- |----------------|            5: XO bit
- | bitmap/seq no. |            4: EOM bit
- |----------------|            3: STS bit
- | TID (MSB)      |        2,1,0: release timer code (ignored under phase I)
- |----------------|
- | TID (LSB)      |
- |----------------|
- | user bytes (4) |
- |----------------|
- | data (0-578)   |
- |      ...       |
- |----------------|
-*/
-struct atphdr {
-    u_int8_t   atphd_ctrlinfo; /* control information */
-    u_int8_t   atphd_bitmap;   /* bitmap or sequence number */
-    u_int16_t  atphd_tid;      /* transaction id. */
-};
-
-/* ATP protocol parameters
-*/
-#define ATP_MAXDATA    (578+4)         /* maximum ATP data size */
-#define ATP_BUFSIZ     587             /* maximum packet size */
-#define ATP_HDRSIZE    5               /* includes DDP type field */
-
-#define ATP_TRELMASK   0x07            /* mask all but TREL */
-#define ATP_RELTIME    30              /* base release timer (in secs) */
-
-#define ATP_TREL30     0x0             /* release time codes */
-#define ATP_TREL1M     0x1             /* these are passed in flags of */
-#define ATP_TREL2M     0x2             /* atp_sreq call, and set in the */
-#define ATP_TREL4M     0x3             /* packet control info. */
-#define ATP_TREL8M     0x4
-
-#define ATP_TRIES_INFINITE     -1      /* for atp_sreq, etc */
-
-struct atpxobuf {
-    u_int16_t          atpxo_tid;
-    struct timeval     atpxo_tv;
-    int                        atpxo_reltime;
-    struct atpbuf      *atpxo_packet[8];
-};
-
-struct atpbuf {
-    struct atpbuf      *atpbuf_next;           /* next buffer in chain */
-    size_t             atpbuf_dlen;            /* data length <= ATP_BUFSIZ */
-    struct sockaddr_at atpbuf_addr;            /* net address sent/recvd */
-    union {
-       char            atpbuf_data[ ATP_BUFSIZ ];      /* the data */
-       struct atpxobuf atpbuf_xo;                      /* for XO requests */
-    } atpbuf_info;
-};
-
-struct atp_handle {
-    int                        atph_socket;            /* ddp socket */
-    struct sockaddr_at atph_saddr;             /* address */
-    u_int16_t          atph_tid;               /* last tid used */
-    u_int16_t          atph_rtid;              /* last received (rreq) */
-    u_int8_t           atph_rxo;               /* XO flag from last rreq */
-    int                        atph_rreltime;          /* release time (secs) */
-    struct atpbuf      *atph_sent;             /* packets we send (XO) */
-    struct atpbuf      *atph_queue;            /* queue of pending packets */
-    int                        atph_reqtries;          /* retry count for request */
-    int                        atph_reqto;             /* retry timeout for request */
-    int                        atph_rrespcount;        /* expected # of responses */
-    u_int8_t           atph_rbitmap;           /* bitmap for request */
-    struct atpbuf      *atph_reqpkt;           /* last request packet */
-    struct timeval     atph_reqtv;             /* when we last sent request */
-    struct atpbuf      *atph_resppkt[8];       /* response to request */
-};
-
-typedef struct atp_handle *ATP;
-
-#define atp_sockaddr( h )      (&(h)->atph_saddr)
-#define atp_fileno(x)          ((x)->atph_socket)
-
-struct sreq_st {
-    char           *atpd_data;         /* request data */
-    int                    atpd_dlen;
-    int                    atpd_tries;         /* max. retry count */
-    int                    atpd_to;            /* retry interval */
-};
-
-struct rres_st {
-    struct iovec    *atpd_iov;         /* for response */
-    int                    atpd_iovcnt;
-};
-
-struct rreq_st {
-    char           *atpd_data;         /* request data */
-    int                    atpd_dlen;
-};
-
-struct sres_st {
-    struct iovec    *atpd_iov;         /* for response */
-    int                    atpd_iovcnt;
-};
-
-struct atp_block {
-    struct sockaddr_at *atp_saddr;             /* from/to address */
-    union {
-       struct sreq_st  sreqdata;
-#define atp_sreqdata   atp_data.sreqdata.atpd_data
-#define atp_sreqdlen   atp_data.sreqdata.atpd_dlen
-#define atp_sreqtries  atp_data.sreqdata.atpd_tries
-#define atp_sreqto     atp_data.sreqdata.atpd_to
-
-       struct rres_st  rresdata;
-#define atp_rresiov    atp_data.rresdata.atpd_iov
-#define atp_rresiovcnt atp_data.rresdata.atpd_iovcnt
-
-       struct rreq_st  rreqdata;
-#define atp_rreqdata   atp_data.rreqdata.atpd_data
-#define atp_rreqdlen   atp_data.rreqdata.atpd_dlen
-
-       struct sres_st  sresdata;
-#define atp_sresiov    atp_data.sresdata.atpd_iov
-#define atp_sresiovcnt atp_data.sresdata.atpd_iovcnt
-    } atp_data;
-    u_int8_t           atp_bitmap;     /* response buffer bitmap */
-};
-
-
-/* flags for ATP options (and control byte)
-*/
-#define ATP_STS                (1<<3)          /* Send Transaction Status */
-#define ATP_EOM                (1<<4)          /* End Of Message */
-#define ATP_XO         (1<<5)          /* eXactly Once mode */
-
-/* function codes
-*/
-#define ATP_FUNCMASK   (3<<6)          /* mask all but function */
-
-#define ATP_TREQ       (1<<6)          /* Trans. REQuest */
-#define ATP_TRESP      (2<<6)          /* Trans. RESPonse */
-#define ATP_TREL       (3<<6)          /* Trans. RELease */
-
-extern ATP             atp_open  (u_int8_t, 
-                                      const struct at_addr *);
-extern int             atp_close (ATP);
-extern int             atp_sreq  (ATP, struct atp_block *, int, 
-                                      u_int8_t);
-extern int             atp_rresp (ATP, struct atp_block *);
-extern int             atp_rsel  (ATP, struct sockaddr_at *, int);
-extern int             atp_rreq  (ATP, struct atp_block *);
-extern int             atp_sresp (ATP, struct atp_block *);
-
-#endif  /* NO_DDP */
-#endif
index d7df70e1d164ddd82c5c61f44f9e07996500607a..2d3aa062b8b601c4ac016e4aa59d5d672e8e05c6 100644 (file)
  * This is instance of CNID database object.
  */
 struct _cnid_db {
-    u_int32_t flags;             /* Flags describing some CNID backend aspects. */
+    uint32_t flags;             /* Flags describing some CNID backend aspects. */
     char *volpath;               /* Volume path this particular CNID db refers to. */
     void *_private;              /* back-end speficic data */
 
-    cnid_t (*cnid_add)         (struct _cnid_db *cdb, const struct stat *st, const cnid_t did,
-                                char *name, const size_t, cnid_t hint);
+    cnid_t (*cnid_add)         (struct _cnid_db *cdb, const struct stat *st, cnid_t did,
+                                const char *name, size_t, cnid_t hint);
     int    (*cnid_delete)      (struct _cnid_db *cdb, cnid_t id);
-    cnid_t (*cnid_get)         (struct _cnid_db *cdb, const cnid_t did, char *name, const  size_t);
-    cnid_t (*cnid_lookup)      (struct _cnid_db *cdb, const struct stat *st, const cnid_t did,
-                                char *name, const size_t);
+    cnid_t (*cnid_get)         (struct _cnid_db *cdb, cnid_t did, const char *name, size_t);
+    cnid_t (*cnid_lookup)      (struct _cnid_db *cdb, const struct stat *st, cnid_t did,
+                                const char *name, size_t);
     cnid_t (*cnid_nextid)      (struct _cnid_db *cdb);
     char * (*cnid_resolve)     (struct _cnid_db *cdb, cnid_t *id, void *buffer, size_t len);
-    int    (*cnid_update)      (struct _cnid_db *cdb, const cnid_t id, const struct stat *st,
-                                const cnid_t did, char *name, const size_t len);
+    int    (*cnid_update)      (struct _cnid_db *cdb, cnid_t id, const struct stat *st,
+                                cnid_t did, const char *name, size_t len);
     void   (*cnid_close)       (struct _cnid_db *cdb);
     int    (*cnid_getstamp)    (struct _cnid_db *cdb, void *buffer, const size_t len);
-    cnid_t (*cnid_rebuild_add) (struct _cnid_db *, const struct stat *, const cnid_t,
-                                char *, const size_t, cnid_t);
-    int    (*cnid_find)        (struct _cnid_db *cdb, char *name, size_t namelen,
+    cnid_t (*cnid_rebuild_add) (struct _cnid_db *, const struct stat *, cnid_t,
+                                const char *, size_t, cnid_t);
+    int    (*cnid_find)        (struct _cnid_db *cdb, const char *name, size_t namelen,
                                 void *buffer, size_t buflen);
 };
 typedef struct _cnid_db cnid_db;
@@ -91,7 +91,7 @@ struct _cnid_module {
     char *name;
     struct list_head db_list;   /* CNID modules are also stored on a bidirectional list. */
     struct _cnid_db *(*cnid_open)(struct cnid_open_args *args);
-    u_int32_t flags;            /* Flags describing some CNID backend aspects. */
+    uint32_t flags;            /* Flags describing some CNID backend aspects. */
 
 };
 typedef struct _cnid_module cnid_module;
index 36dee3d8264890402fa6cc7b0f7d233c08efa706..d7484e42088d7c69ab71326f96d71c1d093bea86 100644 (file)
@@ -43,7 +43,7 @@ struct cnid_dbd_rqst {
     ino_t   ino;
     uint32_t type;
     cnid_t  did;
-    char    *name;
+    const char *name;
     size_t  namelen;
 };
 
@@ -56,7 +56,7 @@ struct cnid_dbd_rply {
 };
 
 typedef struct CNID_private {
-    u_int32_t magic;
+    uint32_t magic;
     char      db_dir[MAXPATHLEN + 1]; /* Database directory without /.AppleDB appended */
     char      *cnidserver;
     char      *cnidport;
index 429955349f74c9ca2572357c68851f5f359c1167..1c217c4ca752d4e34fc5a552c06ff16e9c2514ba 100644 (file)
@@ -6,91 +6,24 @@
  * are checks for EINTR everywhere. 
  */
 
-#include <sys/cdefs.h>
 #include <signal.h>
 
-#ifdef __svr4__
-/*
- * SunOS 5 (solaris) has SA_RESTART, but no SA_INTERRUPT.
- */
-#ifndef SA_INTERRUPT
-#define SA_INTERRUPT   0
-#endif
-
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-extern int flock (int, int);
-extern int inet_aton (const char *, struct in_addr *);
-#else /* __svr4__ */
-
-#ifdef sun
-/*
- * SunOS 4 has SA_INTERRUPT, but no SA_RESTART.
- */
-#ifndef SA_RESTART
-#define SA_RESTART     0
-#endif
-#endif /* sun */
-
-#endif /* __svr4__ */
-
-#ifdef linux
-/*
- * Linux has SA_RESTART, but no SA_INTERRUPT.  Note that the documentation
- * seems to be wrong on several counts.  First, SA_ONESHOT is not the default,
- * and second, SA_RESTART does what you'd expect (the same as svr4) and has
- * nothing to do with SA_ONESHOT.
- */
-#ifndef SA_INTERRUPT
-#define SA_INTERRUPT   0
-#endif /* SA_INTERRUPT */
-#endif /* linux */
-
-#ifdef ultrix 
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-/*
- * Here's the really confusing one...  Under Ultrix, sigaction() works just
- * like sigvec(), except that SV_INTERRUPT is always set.  Hence, there is
- * no SA_INTERRUPT flag.  Unfortunately, there's also no SA_RESTART, so
- * there's no way to suppress the interrupt.  Sigh.
- */
-#ifndef SA_INTERRUPT
-#define SA_INTERRUPT   0
-#endif
-#ifndef SA_RESTART
-#define SA_RESTART     0
-#endif
-
-extern char *strdup (const char *);
-extern int inet_aton (const char *, struct in_addr *);
-#endif /* ultrix */
-
-#ifdef BSD4_4
-#ifndef SA_INTERRUPT
-#define SA_INTERRUPT   0
-#endif
-#endif /* BSD4_4 */
+#include "config.h"
 
 #if defined(ultrix) || defined(_IBMR2) || defined(NEED_GETUSERSHELL)
 extern char *getusershell (void);
 #endif
 
 #if !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF)
-#include <stdio.h>
-#include <stdarg.h>
-#endif
-
-#ifndef HAVE_SNPRINTF
+# include <stdio.h>
+# include <stdarg.h>
+# ifndef HAVE_SNPRINTF
 int snprintf (char *str,size_t count,const char *fmt,...);
-#endif
+# endif
 
-#ifndef HAVE_VSNPRINTF
+# ifndef HAVE_VSNPRINTF
 int vsnprintf(char *str, size_t count, const char *fmt, va_list args);
+# endif
 #endif
 
 /* OpenBSD */
@@ -103,3 +36,25 @@ extern int pselect(int, fd_set * restrict, fd_set * restrict,
                    fd_set * restrict, const struct timespec * restrict,
                    const sigset_t * restrict);
 #endif
+
+#ifndef HAVE_FLOCK
+extern int flock (int, int);
+#endif
+
+#ifndef HAVE_INET_ATON
+struct in_addr;
+extern int inet_aton(const char *, struct in_addr *);
+#endif
+
+#ifndef HAVE_STRNLEN
+extern size_t strnlen(const char *s, size_t n);
+#endif
+
+#ifndef HAVE_STRLCPY
+extern size_t strlcpy (char *, const char *, size_t);
+#endif
+#ifndef HAVE_STRLCAT
+extern size_t strlcat (char *, const char *, size_t);
+#endif
+
diff --git a/include/atalk/ddp.h b/include/atalk/ddp.h
deleted file mode 100644 (file)
index f4ecd55..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- * All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software and
- * its documentation for any purpose and without fee is hereby granted,
- * provided that the above copyright notice appears in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation, and that the name of The University
- * of Michigan not be used in advertising or publicity pertaining to
- * distribution of the software without specific, written prior
- * permission. This software is supplied as is without expressed or
- * implied warranties of any kind.
- *
- *     Research Systems Unix Group
- *     The University of Michigan
- *     c/o Mike Clark
- *     535 W. William Street
- *     Ann Arbor, Michigan
- *     +1-313-763-0525
- *     netatalk@itd.umich.edu
- */
-
-#ifndef _ATALK_DDP_H
-#define _ATALK_DDP_H 1
-
-#ifndef NO_DDP
-
-#define DDPTYPE_RTMPRD 1
-#define DDPTYPE_NBP    2
-#define DDPTYPE_ATP    3
-#define DDPTYPE_AEP    4
-#define DDPTYPE_RTMPR  5
-#define DDPTYPE_ZIP    6
-#define DDPTYPE_ADSP   7
-
-#endif /* NO_DDP */
-#endif
index 801db32643b714a7af010fcee807ff1265b503f7..e474faf59fec95c9b1bdc27e81edaa767a1e54ad 100644 (file)
@@ -24,9 +24,8 @@
 #ifndef ATALK_DIRECTORY_H
 #define ATALK_DIRECTORY_H 1
 
-#include <sys/cdefs.h>
 #include <sys/types.h>
-#include <netatalk/endian.h>
+#include <arpa/inet.h>
 #include <dirent.h>
 #include <stdint.h>
 
index eded2b8f5ad7d5e97980970694f1bf51381d6de8..de7464a593086d4670aff1965c6905ca3d2e5690 100644 (file)
@@ -6,18 +6,16 @@
 #ifndef _ATALK_DSI_H 
 #define _ATALK_DSI_H
 
-#include <sys/cdefs.h>
 #include <sys/types.h>
 #include <sys/time.h>
-#include <signal.h>
 #include <sys/socket.h>
+#include <signal.h>
+#include <arpa/inet.h>
 #include <netinet/in.h>
 
 #include <atalk/afp.h>
 #include <atalk/server_child.h>
 #include <atalk/globals.h>
-#include <netatalk/endian.h>
-
 
 /* What a DSI packet looks like:
  0                               32
@@ -44,12 +42,12 @@ typedef enum {
 
 #define DSI_BLOCKSIZ 16
 struct dsi_block {
-  u_int8_t dsi_flags;       /* packet type: request or reply */
-  u_int8_t dsi_command;     /* command */
-  u_int16_t dsi_requestID;  /* request ID */
-  u_int32_t dsi_code;       /* error code or data offset */
-  u_int32_t dsi_len;        /* total data length */
-  u_int32_t dsi_reserved;   /* reserved field */
+  uint8_t dsi_flags;       /* packet type: request or reply */
+  uint8_t dsi_command;     /* command */
+  uint16_t dsi_requestID;  /* request ID */
+  uint32_t dsi_code;       /* error code or data offset */
+  uint32_t dsi_len;        /* total data length */
+  uint32_t dsi_reserved;   /* reserved field */
 };
 
 #define DSI_CMDSIZ        8192 
@@ -69,10 +67,10 @@ typedef struct DSI {
   int      msg_request;   /* pending message to the client */
   int      down_request;  /* pending SIGUSR1 down in 5 mn */
 
-  u_int32_t attn_quantum, datasize, server_quantum;
-  u_int16_t serverID, clientID;
+  uint32_t attn_quantum, datasize, server_quantum;
+  uint16_t serverID, clientID;
   char      *status;
-  u_int8_t  commands[DSI_CMDSIZ], data[DSI_DATASIZ];
+  uint8_t  commands[DSI_CMDSIZ], data[DSI_DATASIZ];
   size_t statuslen;
   size_t datalen, cmdlen;
   off_t  read_count, write_count;
@@ -166,7 +164,7 @@ extern DSI *dsi_init (const dsi_proto /*protocol*/,
                          const char * /*program*/, 
                          const char * /*host*/, const char * /*address*/,
                          const char * /*port*/, const int /*proxy*/,
-                         const u_int32_t /* server quantum */);
+                         const uint32_t /* server quantum */);
 extern void dsi_setstatus (DSI *, char *, const size_t);
 
 /* in dsi_getsess.c */
index c0165a1a257f210999055d8a271bc81dadf9e2a8..f26e32b288f0171058159a9979f5474465175039 100644 (file)
@@ -1,5 +1,4 @@
 /*
-   $Id: ea.h,v 1.11 2010-03-12 15:16:49 franklahm Exp $
    Copyright (c) 2009 Frank Lahm <franklahm@gmail.com>
 
    This program is free software; you can redistribute it and/or modify
 #include <config.h>
 #endif
 
+#if HAVE_ATTR_XATTR_H
+#include <attr/xattr.h>
+#elif HAVE_SYS_XATTR_H
+#include <sys/xattr.h>
+#endif
+
+#ifdef HAVE_SYS_EA_H
+#include <sys/ea.h>
+#endif
+
+#ifdef HAVE_SYS_EXTATTR_H
+#include <sys/extattr.h>
+#endif
+
 #ifdef HAVE_SOLARIS_ACLS
 #include <sys/acl.h>
 #endif
 
+#ifndef ENOATTR
+#define ENOATTR ENODATA
+#endif
+
 #include <atalk/vfs.h>
 
 /*
@@ -56,6 +73,27 @@ enum {
 #define XATTR_REPLACE 0x2       /* set value, fail if attr does not exist */
 #endif
 
+/* Names for our Extended Attributes adouble data */
+#define AD_EA_META "org.netatalk.Metadata"
+#define AD_EA_RESO "org.netatalk.ResourceFork"
+#define NOT_NETATALK_EA(a) (strcmp((a), AD_EA_META) != 0) && (strcmp((a), AD_EA_RESO) != 0)
+
+/****************************************************************************************
+ * Wrappers for native EA functions taken from Samba
+ ****************************************************************************************/
+ssize_t sys_getxattr (const char *path, const char *name, void *value, size_t size);
+ssize_t sys_lgetxattr (const char *path, const char *name, void *value, size_t size);
+ssize_t sys_fgetxattr (int filedes, const char *name, void *value, size_t size);
+ssize_t sys_listxattr (const char *path, char *list, size_t size);
+ssize_t sys_llistxattr (const char *path, char *list, size_t size);
+ssize_t sys_flistxattr (int filedes, char *list, size_t size);
+int sys_removexattr (const char *path, const char *name);
+int sys_lremovexattr (const char *path, const char *name);
+int sys_fremovexattr (int filedes, const char *name);
+int sys_setxattr (const char *path, const char *name, const void *value, size_t size, int flags);
+int sys_lsetxattr (const char *path, const char *name, const void *value, size_t size, int flags);
+int sys_fsetxattr (int filedes, const char *name, const void *value, size_t size, int flags);
+int sys_copyxattr (const char *src, const char *dst);
 
 /****************************************************************************************
  * Stuff for our implementation of storing EAs in files in .AppleDouble dirs
index 68e68a32f3f403f6dea131dde173883a1dae9d90..b65eeba1e069cd2743c2969ceec5bd5876a8e453 100644 (file)
@@ -7,7 +7,6 @@
 #define AFPD_GLOBALS_H 1
 
 #include <sys/param.h>
-#include <sys/cdefs.h>
 
 #ifdef ADMIN_GRP
 #include <grp.h>
 #define OPTION_NOZEROCONF    (1 << 9)
 #define OPTION_KEEPSESSIONS  (1 << 10) /* preserve sessions across master afpd restart with SIGQUIT */
 
-#ifdef FORCE_UIDGID
-/* set up a structure for this */
-typedef struct uidgidset_t {
-    uid_t uid;
-    gid_t gid;
-} uidgidset;
-#endif /* FORCE_UIDGID */
-
 /* a couple of these options could get stuck in unions to save
  * space. */
 struct afp_volume_name {
@@ -69,12 +60,9 @@ struct afp_options {
     int fce_fmodwait;           /* number of seconds FCE file mod events are put on hold */
     unsigned int tcp_sndbuf, tcp_rcvbuf;
     unsigned char passwdbits, passwdminlen, loginmaxfail;
-    u_int32_t server_quantum;
+    uint32_t server_quantum;
     int dsireadbuf; /* scale factor for sizefof(dsi->buffer) = server_quantum * dsireadbuf */
     char hostname[MAXHOSTNAMELEN + 1], *server, *ipaddr, *port, *configfile;
-#ifndef NO_DDP
-    struct at_addr ddpaddr;
-#endif
     char *uampath, *fqdn;
     char *pidfile;
     char *sigconffile;
@@ -123,10 +111,6 @@ typedef struct _AFPObj {
     struct session_info  sinfo;
     uid_t uid;         /* client running user id */
     int ipc_fd; /* anonymous PF_UNIX socket for IPC with afpd parent */
-#ifdef FORCE_UIDGID
-    int                 force_uid;
-    uidgidset          uidgid;
-#endif
 } AFPObj;
 
 /* typedef for AFP functions handlers */
@@ -163,9 +147,6 @@ extern const char *AfpErr2name(int err);
 /* directory.c */
 extern struct dir rootParent;
 
-#ifndef NO_DDP
-extern void afp_over_asp (AFPObj *);
-#endif /* NO_DDP */
 extern void afp_over_dsi (AFPObj *);
 
 #endif /* globals.h */
diff --git a/include/atalk/nbp.h b/include/atalk/nbp.h
deleted file mode 100644 (file)
index 45bae00..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- * All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software and
- * its documentation for any purpose and without fee is hereby granted,
- * provided that the above copyright notice appears in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation, and that the name of The University
- * of Michigan not be used in advertising or publicity pertaining to
- * distribution of the software without specific, written prior
- * permission. This software is supplied as is without expressed or
- * implied warranties of any kind.
- *
- *     Research Systems Unix Group
- *     The University of Michigan
- *     c/o Mike Clark
- *     535 W. William Street
- *     Ann Arbor, Michigan
- *     +1-313-763-0525
- *     netatalk@itd.umich.edu
- */
-
-#ifndef _ATALK_NBP_H
-#define _ATALK_NBP_H 1
-
-#ifndef NO_DDP
-
-#define NBP_UNRGSTR_4ARGS 1
-#define ATP_OPEN_2ARGS 1
-
-#include <sys/cdefs.h>
-#include <sys/types.h>
-#include <netatalk/at.h>
-#include <netatalk/endian.h>
-
-struct nbphdr {
-#if BYTE_ORDER == BIG_ENDIAN
-    unsigned   nh_op : 4,
-               nh_cnt : 4,
-#else /* BYTE_ORDER != BIG_ENDIAN */
-    unsigned   nh_cnt : 4,
-               nh_op : 4,
-#endif /* BYTE_ORDER */
-               nh_id : 8;
-};
-
-#define SZ_NBPHDR      2
-
-struct nbptuple {
-    u_int16_t   nt_net;
-    u_int8_t    nt_node;
-    u_int8_t    nt_port;
-    u_int8_t    nt_enum;
-};
-#define SZ_NBPTUPLE    5
-
-#define NBPSTRLEN      32
-/*
- * Name Binding Protocol Network Visible Entity
- */
-struct nbpnve {
-    struct sockaddr_at nn_sat;
-    u_char             nn_objlen;
-    char               nn_obj[ NBPSTRLEN ];
-    u_char             nn_typelen;
-    char               nn_type[ NBPSTRLEN ];
-    u_char             nn_zonelen;
-    char               nn_zone[ NBPSTRLEN ];
-};
-
-/*
- * Note that NBPOP_ERROR is not standard. As Apple adds more NBPOPs,
- * we need to check for collisions with our extra values.  */
-#define NBPOP_BRRQ      0x1
-#define NBPOP_LKUP      0x2
-#define NBPOP_LKUPREPLY         0x3
-#define NBPOP_FWD       0x4
-#define NBPOP_RGSTR     0x7
-#define NBPOP_UNRGSTR   0x8
-#define NBPOP_CONFIRM    0x9
-#define NBPOP_OK        0xa  /* NBPOP_STATUS_REPLY */
-#define NBPOP_CLOSE_NOTE 0xb
-
-#define NBPOP_ERROR     0xf
-
-#define NBPMATCH_NOGLOB        (1<<1)
-#define NBPMATCH_NOZONE        (1<<2)
-
-extern int nbp_name (const char *, char **, char **, char **);
-extern int nbp_lookup (const char *, const char *, const char *,
-                          struct nbpnve *, const int, 
-                          const struct at_addr *);
-extern int nbp_rgstr (struct sockaddr_at *, 
-                         const char *, const char *, const char *);
-extern int nbp_unrgstr (const char *, const char *, const char *,
-                           const struct at_addr *);
-
-#endif  /* NO_DDP */
-#endif
diff --git a/include/atalk/netddp.h b/include/atalk/netddp.h
deleted file mode 100644 (file)
index e6bccd4..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * $Id: netddp.h,v 1.4 2009-10-13 22:55:37 didg Exp $
- *
- * Copyright (c) 1999 Adrian Sun (asun@zoology.washington.edu)
- * All Rights Reserved. See COPYRIGHT.
- *
- * this provides a generic interface to the ddp layer. with this, we
- * should be able to interact with any appletalk stack that allows
- * direct access to the ddp layer. right now, only os x server's ddp
- * layer and the generic socket based interfaces are understood.  
- */
-
-#ifndef _ATALK_NETDDP_H
-#define _ATALK_NETDDP_H 1
-
-#ifndef NO_DDP
-
-#include <sys/types.h>
-#include <sys/cdefs.h>
-#include <sys/socket.h>
-#include <netatalk/at.h>
-
-extern int netddp_open   (struct sockaddr_at *, struct sockaddr_at *);
-
-#if !defined(NO_DDP) && defined(MACOSX_SERVER)
-extern int netddp_sendto (int, void *, size_t, unsigned int, 
-                          const struct sockaddr *, unsigned int);
-extern int netddp_recvfrom (int, void *, int, unsigned int, 
-                            struct sockaddr *, unsigned int *);
-#define netddp_close(a)  ddp_close(a)
-#else
-#include <unistd.h>
-#include <sys/types.h>
-
-#define netddp_close(a)  close(a)
-#define netddp_sendto    sendto
-#define netddp_recvfrom  recvfrom
-#endif
-
-#endif  /* NO_DDP */
-#endif /* netddp.h */
-
diff --git a/include/atalk/pap.h b/include/atalk/pap.h
deleted file mode 100644 (file)
index 3d40082..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- * All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software and
- * its documentation for any purpose and without fee is hereby granted,
- * provided that the above copyright notice appears in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation, and that the name of The University
- * of Michigan not be used in advertising or publicity pertaining to
- * distribution of the software without specific, written prior
- * permission. This software is supplied as is without expressed or
- * implied warranties of any kind.
- *
- *     Research Systems Unix Group
- *     The University of Michigan
- *     c/o Mike Clark
- *     535 W. William Street
- *     Ann Arbor, Michigan
- *     +1-313-763-0525
- *     netatalk@itd.umich.edu
- */
-
-#ifndef _ATALK_PAP_H
-#define _ATALK_PAP_H 1
-
-#ifndef NO_DDP
-
-#define PAP_OPEN       1
-#define PAP_OPENREPLY  2
-#define PAP_READ       3
-#define PAP_DATA       4
-#define PAP_TICKLE     5
-#define PAP_CLOSE      6
-#define PAP_CLOSEREPLY 7
-#define PAP_SENDSTATUS 8
-#define PAP_STATUS     9
-
-#define PAP_MAXDATA    512
-#define PAP_MAXQUANTUM 8
-
-#endif  /* NO_DDP */
-#endif
diff --git a/include/atalk/rpc.h b/include/atalk/rpc.h
new file mode 100644 (file)
index 0000000..00a385d
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2011 Frank Lahm
+ * All Rights Reserved.  See COPYRIGHT.
+ */
+
+#ifndef ATALK_RPC_H
+#define ATALK_RPC_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <sys/types.h>
+#include <inttypes.h>
+
+#include <atalk/lockrpc.gen.h>
+
+#include "event2/event.h"
+#include "event2/http.h"
+#include "event2/rpc.h"
+
+struct adouble;
+extern int rpc_init(const char *addr, unsigned short port);
+extern int rpc_lock(struct adouble *, uint32_t eid, int type, off_t off, off_t len, int user);
+extern void rpc_unlock(struct adouble *, int user);
+extern int rpc_tmplock(struct adouble *, uint32_t eid, int type, off_t off, off_t len, int user);
+
+#endif  /* ATALK_RPC_H */
diff --git a/include/atalk/rtmp.h b/include/atalk/rtmp.h
deleted file mode 100644 (file)
index 474bd5a..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- * All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software and
- * its documentation for any purpose and without fee is hereby granted,
- * provided that the above copyright notice appears in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation, and that the name of The University
- * of Michigan not be used in advertising or publicity pertaining to
- * distribution of the software without specific, written prior
- * permission. This software is supplied as is without expressed or
- * implied warranties of any kind.
- *
- *     Research Systems Unix Group
- *     The University of Michigan
- *     c/o Mike Clark
- *     535 W. William Street
- *     Ann Arbor, Michigan
- *     +1-313-763-0525
- *     netatalk@itd.umich.edu
- */
-
-#ifndef _ATALK_RTMP_H
-#define _ATALK_RTMP_H 1
-
-#ifndef NO_DDP
-
-#include <netatalk/endian.h>
-
-#define RTMPROP_REQUEST        1
-
-struct rtmpent {
-    u_int16_t   re_net;
-    u_int8_t    re_hops;
-};
-
-#define RTMPHOPS_MAX   15
-#define RTMPHOPS_POISON        31
-
-struct rtmprdhdr {
-    u_int16_t   rrdh_snet;
-    u_int8_t    rrdh_idlen;
-    u_int8_t    rrdh_id;
-};
-
-#endif  /* NO_DDP */
-#endif
index f548ce4d5ab8a0db8a673403d93d268f6de91189..a86a756895b7e63135cc0cd58be8f13d3bca95c3 100644 (file)
@@ -6,9 +6,8 @@
 #ifndef _ATALK_SERVER_CHILD_H
 #define _ATALK_SERVER_CHILD_H 1
 
-#include <sys/cdefs.h>
 #include <sys/types.h>
-#include <netatalk/endian.h>
+#include <arpa/inet.h>
 
 /* useful stuff for child processes. most of this is hidden in 
  * server_child.c to ease changes in implementation */
@@ -46,7 +45,7 @@ extern void server_child_free (server_child *);
 
 extern void server_child_kill (server_child *, const int, const int);
 extern void server_child_kill_one_by_id (server_child *children, const int forkid, const pid_t pid, const uid_t,
-                                               const u_int32_t len, char *id, u_int32_t boottime);
+                                               const uint32_t len, char *id, uint32_t boottime);
 extern int  server_child_transfer_session(server_child *children, int forkid, pid_t, uid_t, int, uint16_t);
 extern void server_child_setup (server_child *, const int, void (*)(const pid_t));
 extern void server_child_handler (server_child *);
index 6f3b1ff7562786e90a7f4715d1a8349206f32710..789649a1a6ded108932ddd9d90f52b0be10a4b14 100644 (file)
@@ -3,33 +3,40 @@
 
 /* 
    Unix SMB/CIFS implementation.
-   Samba database functions
-   Copyright (C) Andrew Tridgell 1999
+
+   trivial database library
+
+   Copyright (C) Andrew Tridgell 1999-2004
    
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
-   (at your option) any later version.
+     ** NOTE! The following LGPL license applies to the tdb
+     ** library. This does NOT imply that all of Samba is released
+     ** under the LGPL
    
-   This program is distributed in the hope that it will be useful,
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-   
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, see <http://www.gnu.org/licenses/>.
 */
 
 #ifdef  __cplusplus
 extern "C" {
 #endif
 
+#include <sys/types.h>
+#include <signal.h>
 
 /* flags to tdb_store() */
-#define TDB_REPLACE 1
-#define TDB_INSERT 2
-#define TDB_MODIFY 3
+#define TDB_REPLACE 1          /* Unused */
+#define TDB_INSERT 2           /* Don't overwrite an existing entry */
+#define TDB_MODIFY 3           /* Don't create an existing entry    */
 
 /* flags for tdb_open() */
 #define TDB_DEFAULT 0 /* just a readability place holder */
@@ -39,101 +46,127 @@ extern "C" {
 #define TDB_NOMMAP   8 /* don't use mmap */
 #define TDB_CONVERT 16 /* convert endian (internal use) */
 #define TDB_BIGENDIAN 32 /* header is big-endian (internal use) */
-
-#define TDB_ERRCODE(code, ret) ((tdb->ecode = (code)), ret)
+#define TDB_NOSYNC   64 /* don't use synchronous transactions */
+#define TDB_SEQNUM   128 /* maintain a sequence number */
+#define TDB_VOLATILE   256 /* Activate the per-hashchain freelist, default 5 */
+#define TDB_ALLOW_NESTING 512 /* Allow transactions to nest */
+#define TDB_DISALLOW_NESTING 1024 /* Disallow transactions to nest */
 
 /* error codes */
 enum TDB_ERROR {TDB_SUCCESS=0, TDB_ERR_CORRUPT, TDB_ERR_IO, TDB_ERR_LOCK, 
-               TDB_ERR_OOM, TDB_ERR_EXISTS, TDB_ERR_NOEXIST, TDB_ERR_NOLOCK, TDB_ERR_LOCK_TIMEOUT };
+               TDB_ERR_OOM, TDB_ERR_EXISTS, TDB_ERR_NOLOCK, TDB_ERR_LOCK_TIMEOUT,
+               TDB_ERR_NOEXIST, TDB_ERR_EINVAL, TDB_ERR_RDONLY,
+               TDB_ERR_NESTING};
 
-#ifndef u32
-#define u32 unsigned
-#endif
+/* debugging uses one of the following levels */
+enum tdb_debug_level {TDB_DEBUG_FATAL = 0, TDB_DEBUG_ERROR, 
+                     TDB_DEBUG_WARNING, TDB_DEBUG_TRACE};
 
-typedef struct {
-       char *dptr;
+typedef struct TDB_DATA {
+       unsigned char *dptr;
        size_t dsize;
 } TDB_DATA;
 
-typedef u32 tdb_len;
-typedef u32 tdb_off;
+#ifndef PRINTF_ATTRIBUTE
+#if (__GNUC__ >= 3)
+/** Use gcc attribute to check printf fns.  a1 is the 1-based index of
+ * the parameter containing the format, and a2 the index of the first
+ * argument. Note that some gcc 2.x versions don't handle this
+ * properly **/
+#define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2)))
+#else
+#define PRINTF_ATTRIBUTE(a1, a2)
+#endif
+#endif
 
-/* this is stored at the front of every database */
-struct tdb_header {
-       char magic_food[32]; /* for /etc/magic */
-       u32 version; /* version of the code */
-       u32 hash_size; /* number of hash entries */
-       tdb_off rwlocks;
-       tdb_off reserved[31];
-};
+/* this is the context structure that is returned from a db open */
+typedef struct tdb_context TDB_CONTEXT;
 
-struct tdb_lock_type {
-       u32 count;
-       u32 ltype;
-};
+typedef int (*tdb_traverse_func)(struct tdb_context *, TDB_DATA, TDB_DATA, void *);
+typedef void (*tdb_log_func)(struct tdb_context *, enum tdb_debug_level, const char *, ...) PRINTF_ATTRIBUTE(3, 4);
+typedef unsigned int (*tdb_hash_func)(TDB_DATA *key);
 
-struct tdb_traverse_lock {
-       struct tdb_traverse_lock *next;
-       u32 off;
-       u32 hash;
+struct tdb_logging_context {
+        tdb_log_func log_fn;
+        void *log_private;
 };
 
-/* this is the context structure that is returned from a db open */
-typedef struct tdb_context {
-       char *name; /* the name of the database */
-       void *map_ptr; /* where it is currently mapped */
-       int fd; /* open file descriptor for the database */
-       tdb_len map_size; /* how much space has been mapped */
-       int read_only; /* opened read-only */
-       struct tdb_lock_type *locked; /* array of chain locks */
-       enum TDB_ERROR ecode; /* error code for last tdb error */
-       struct tdb_header header; /* a cached copy of the header */
-       u32 flags; /* the flags passed to tdb_open */
-       u32 *lockedkeys; /* array of locked keys: first is #keys */
-       struct tdb_traverse_lock travlocks; /* current traversal locks */
-       struct tdb_context *next; /* all tdbs to avoid multiple opens */
-       dev_t device;   /* uniquely identifies this tdb */
-       ino_t inode;    /* uniquely identifies this tdb */
-       void (*log_fn)(struct tdb_context *tdb, int level, const char *, ...); /* logging function */
-       int open_flags; /* flags used in the open - needed by reopen */
-} TDB_CONTEXT;
-
-typedef int (*tdb_traverse_func)(TDB_CONTEXT *, TDB_DATA, TDB_DATA, void *);
-typedef void (*tdb_log_func)(TDB_CONTEXT *, int , const char *, ...);
-
-TDB_CONTEXT *tdb_open(const char *name, int hash_size, int tdb_flags,
+struct tdb_context *tdb_open(const char *name, int hash_size, int tdb_flags,
                      int open_flags, mode_t mode);
-TDB_CONTEXT *tdb_open_ex(const char *name, int hash_size, int tdb_flags,
+struct tdb_context *tdb_open_ex(const char *name, int hash_size, int tdb_flags,
                         int open_flags, mode_t mode,
-                        tdb_log_func log_fn);
-
-int tdb_reopen(TDB_CONTEXT *tdb);
-int tdb_reopen_all(void);
-void tdb_logging_function(TDB_CONTEXT *tdb, tdb_log_func);
-enum TDB_ERROR tdb_error(TDB_CONTEXT *tdb);
-const char *tdb_errorstr(TDB_CONTEXT *tdb);
-TDB_DATA tdb_fetch(TDB_CONTEXT *tdb, TDB_DATA key);
-int tdb_delete(TDB_CONTEXT *tdb, TDB_DATA key);
-int tdb_store(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, int flag);
-int tdb_append(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA new_dbuf);
-int tdb_close(TDB_CONTEXT *tdb);
-TDB_DATA tdb_firstkey(TDB_CONTEXT *tdb);
-TDB_DATA tdb_nextkey(TDB_CONTEXT *tdb, TDB_DATA key);
-int tdb_traverse(TDB_CONTEXT *tdb, tdb_traverse_func fn, void *state);
-int tdb_exists(TDB_CONTEXT *tdb, TDB_DATA key);
-int tdb_lockkeys(TDB_CONTEXT *tdb, u32 number, TDB_DATA keys[]);
-void tdb_unlockkeys(TDB_CONTEXT *tdb);
-int tdb_lockall(TDB_CONTEXT *tdb);
-void tdb_unlockall(TDB_CONTEXT *tdb);
+                        const struct tdb_logging_context *log_ctx,
+                        tdb_hash_func hash_fn);
+void tdb_set_max_dead(struct tdb_context *tdb, int max_dead);
+
+int tdb_reopen(struct tdb_context *tdb);
+int tdb_reopen_all(int parent_longlived);
+void tdb_set_logging_function(struct tdb_context *tdb, const struct tdb_logging_context *log_ctx);
+enum TDB_ERROR tdb_error(struct tdb_context *tdb);
+const char *tdb_errorstr(struct tdb_context *tdb);
+TDB_DATA tdb_fetch(struct tdb_context *tdb, TDB_DATA key);
+int tdb_parse_record(struct tdb_context *tdb, TDB_DATA key,
+                    int (*parser)(TDB_DATA key, TDB_DATA data,
+                                  void *private_data),
+                    void *private_data);
+int tdb_delete(struct tdb_context *tdb, TDB_DATA key);
+int tdb_store(struct tdb_context *tdb, TDB_DATA key, TDB_DATA dbuf, int flag);
+int tdb_append(struct tdb_context *tdb, TDB_DATA key, TDB_DATA new_dbuf);
+int tdb_close(struct tdb_context *tdb);
+TDB_DATA tdb_firstkey(struct tdb_context *tdb);
+TDB_DATA tdb_nextkey(struct tdb_context *tdb, TDB_DATA key);
+int tdb_traverse(struct tdb_context *tdb, tdb_traverse_func fn, void *);
+int tdb_traverse_read(struct tdb_context *tdb, tdb_traverse_func fn, void *);
+int tdb_exists(struct tdb_context *tdb, TDB_DATA key);
+int tdb_lockall(struct tdb_context *tdb);
+int tdb_lockall_nonblock(struct tdb_context *tdb);
+int tdb_unlockall(struct tdb_context *tdb);
+int tdb_lockall_read(struct tdb_context *tdb);
+int tdb_lockall_read_nonblock(struct tdb_context *tdb);
+int tdb_unlockall_read(struct tdb_context *tdb);
+int tdb_lockall_mark(struct tdb_context *tdb);
+int tdb_lockall_unmark(struct tdb_context *tdb);
+const char *tdb_name(struct tdb_context *tdb);
+int tdb_fd(struct tdb_context *tdb);
+tdb_log_func tdb_log_fn(struct tdb_context *tdb);
+void *tdb_get_logging_private(struct tdb_context *tdb);
+int tdb_transaction_start(struct tdb_context *tdb);
+int tdb_transaction_prepare_commit(struct tdb_context *tdb);
+int tdb_transaction_commit(struct tdb_context *tdb);
+int tdb_transaction_cancel(struct tdb_context *tdb);
+int tdb_transaction_recover(struct tdb_context *tdb);
+int tdb_get_seqnum(struct tdb_context *tdb);
+int tdb_hash_size(struct tdb_context *tdb);
+size_t tdb_map_size(struct tdb_context *tdb);
+int tdb_get_flags(struct tdb_context *tdb);
+void tdb_add_flags(struct tdb_context *tdb, unsigned flag);
+void tdb_remove_flags(struct tdb_context *tdb, unsigned flag);
+void tdb_enable_seqnum(struct tdb_context *tdb);
+void tdb_increment_seqnum_nonblock(struct tdb_context *tdb);
+int tdb_check(struct tdb_context *tdb,
+             int (*check) (TDB_DATA key, TDB_DATA data, void *private_data),
+             void *private_data);
 
 /* Low level locking functions: use with care */
-void tdb_set_lock_alarm(sig_atomic_t *palarm);
-int tdb_chainlock(TDB_CONTEXT *tdb, TDB_DATA key);
-int tdb_chainunlock(TDB_CONTEXT *tdb, TDB_DATA key);
+int tdb_chainlock(struct tdb_context *tdb, TDB_DATA key);
+int tdb_chainlock_nonblock(struct tdb_context *tdb, TDB_DATA key);
+int tdb_chainunlock(struct tdb_context *tdb, TDB_DATA key);
+int tdb_chainlock_read(struct tdb_context *tdb, TDB_DATA key);
+int tdb_chainunlock_read(struct tdb_context *tdb, TDB_DATA key);
+int tdb_chainlock_mark(struct tdb_context *tdb, TDB_DATA key);
+int tdb_chainlock_unmark(struct tdb_context *tdb, TDB_DATA key);
+
+void tdb_setalarm_sigptr(struct tdb_context *tdb, volatile sig_atomic_t *sigptr);
+
+/* wipe and repack */
+int tdb_wipe_all(struct tdb_context *tdb);
+int tdb_repack(struct tdb_context *tdb);
 
 /* Debug functions. Not used in production. */
-void tdb_dump_all(TDB_CONTEXT *tdb);
-int tdb_printfreelist(TDB_CONTEXT *tdb);
+void tdb_dump_all(struct tdb_context *tdb);
+int tdb_printfreelist(struct tdb_context *tdb);
+int tdb_validate_freelist(struct tdb_context *tdb, int *pnum_entries);
+int tdb_freelist_size(struct tdb_context *tdb);
 
 extern TDB_DATA tdb_null;
 
index ba62783aa657aad332875986cbb6854897993c9f..d0499c6fecefa16472bb75d36e95d1400595d7da 100644 (file)
@@ -5,7 +5,6 @@
 #ifndef UAM_H
 #define UAM_H 1
 
-#include <sys/cdefs.h>
 #include <pwd.h>
 #include <stdarg.h>
 
index 325b7ac2bf911275095a0939ce21109f33a953b1..6844073b9fe5b1578e4dd2f2dacb5099adcc07be 100644 (file)
@@ -1,12 +1,11 @@
 #ifndef _ATALK_UNICODE_H
 #define _ATALK_UNICODE_H 1
 
-#include <sys/cdefs.h>
-#include <netatalk/endian.h>
 #include <errno.h>
+#include <stdint.h>
 #include <sys/param.h>
 
-#define ucs2_t u_int16_t
+#define ucs2_t uint16_t
 
 #ifndef MIN
 #define MIN(a,b)     ((a)<(b)?(a):(b))
@@ -80,7 +79,7 @@ struct charset_functions {
                    char **outbuf, size_t *outbytesleft);
     size_t (*push)(void *, char **inbuf, size_t *inbytesleft,
                    char **outbuf, size_t *outbytesleft);
-    u_int32_t flags;
+    uint32_t flags;
     const char *iname;
     struct charset_functions *prev, *next;
 };
@@ -94,9 +93,9 @@ extern int atalk_register_charset (struct charset_functions *);
 
 /* from utf16_case.c */
 extern ucs2_t    toupper_w  (ucs2_t);
-extern u_int32_t toupper_sp (u_int32_t);
+extern uint32_t  toupper_sp (uint32_t);
 extern ucs2_t    tolower_w  (ucs2_t);
-extern u_int32_t tolower_sp (u_int32_t);
+extern uint32_t  tolower_sp (uint32_t);
 
 /* from util_unistr.c */
 extern int      strupper_w (ucs2_t *);
@@ -140,7 +139,7 @@ extern size_t   ucs2_to_charset_allocate (charset_t, char **dest, const ucs2_t *
 extern size_t   utf8_to_charset_allocate (charset_t, char **dest, const char *src);
 extern size_t   ucs2_to_charset (charset_t, const ucs2_t *src, char *dest, size_t);
 
-extern size_t   convert_charset (charset_t, charset_t, charset_t, const char *, size_t, char *, size_t, u_int16_t *);
+extern size_t   convert_charset (charset_t, charset_t, charset_t, const char *, size_t, char *, size_t, uint16_t *);
 
 extern size_t   charset_precompose ( charset_t, char *, size_t, char *, size_t);
 extern size_t   charset_decompose  ( charset_t, char *, size_t, char *, size_t);
index 3a6dd24498bb85e7e66c84800f4edb633ca26aeb..7fbae2dfc07838c91bce2aa1d5975eafcd5b902a 100644 (file)
 #ifndef _ATALK_UTIL_H
 #define _ATALK_UTIL_H 1
 
-#include <sys/cdefs.h>
 #include <sys/types.h>
-#ifdef HAVE_UNISTD_H
+#include <sys/socket.h>
 #include <unistd.h>
-#endif /* HAVE_UNISTD_H */
 #include <poll.h>
-#include <netatalk/at.h>
 
 #include <atalk/unicode.h>
 #include <atalk/bstrlib.h>
 #define AFP_ASSERT(b)
 #endif /* NDEBUG */
 
+#ifndef MIN
+#define MIN(a, b)  ((a) < (b) ? (a) : (b))
+#endif
+
+#ifndef MAX
+#define MAX(a, b)  ((a) > (b) ? (a) : (b))
+#endif
+
 #define STRCMP(a,b,c) (strcmp(a,c) b 0)
+#define ZERO_STRUCT(a) memset(&(a), 0, sizeof(a))
+#define ZERO_STRUCTP(a) memset((a), 0, sizeof(a))
 #ifndef MAX
 #define MAX(a,b) ((a) > (b) ? a : b)
 #endif
@@ -74,9 +81,6 @@ extern void freeifacelist(char **);
 
 #define diatolower(x)     _dialowermap[(unsigned char) (x)]
 #define diatoupper(x)     _diacasemap[(unsigned char) (x)]
-#ifndef NO_DDP
-extern int atalk_aton     (char *, struct at_addr *);
-#endif
 extern void bprint        (char *, int);
 extern int strdiacasecmp  (const char *, const char *);
 extern int strndiacasecmp (const char *, const char *, size_t);
@@ -87,19 +91,6 @@ extern void fault_setup        (void (*fn)(void *));
 extern void netatalk_panic(const char *why);
 #define server_unlock(x)  (unlink(x))
 
-/* strlcpy and strlcat are used by pam modules */
-#ifndef UAM_MODULE_EXPORT
-#define UAM_MODULE_EXPORT 
-#endif
-
-#ifndef HAVE_STRLCPY
-UAM_MODULE_EXPORT size_t strlcpy (char *, const char *, size_t);
-#endif
-#ifndef HAVE_STRLCAT
-UAM_MODULE_EXPORT size_t strlcat (char *, const char *, size_t);
-#endif
-
 #ifndef HAVE_DLFCN_H
 extern void *mod_open    (const char *);
 extern void *mod_symbol  (void *, const char *);
index 93bad6b31df7358b598e6b72003173d2e0136c5a..941930d328d9020491605f81f7d59592952441a9 100644 (file)
@@ -18,7 +18,7 @@
 #define UUID_BINSIZE 16
 #define UUID_STRINGSIZE 36
 
-typedef unsigned char *uuidp_t;
+typedef const unsigned char *uuidp_t;
 typedef unsigned char atalk_uuid_t[UUID_BINSIZE];
 
 typedef enum {UUID_USER   = 1,
@@ -44,11 +44,11 @@ extern char *ldap_uid_attr;
  * Interface
  ********************************************************/
 
-extern int getuuidfromname( const char *name, uuidtype_t type, uuidp_t uuid);
-extern int getnamefromuuid( const uuidp_t uuidp, char **name, uuidtype_t *type);
-
+extern int getuuidfromname( const char *name, uuidtype_t type, unsigned char *uuid);
+extern int getnamefromuuid( const unsigned char *uuid, char **name, uuidtype_t *type);
 extern void localuuid_from_id(unsigned char *buf, uuidtype_t type, unsigned int id);
-extern const char *uuid_bin2string(unsigned char *uuid);
-extern void uuid_string2bin( const char *uuidstring, uuidp_t uuid);
+extern const char *uuid_bin2string(const unsigned char *uuid);
+extern void uuid_string2bin( const char *uuidstring, unsigned char *uuid);
 extern void uuidcache_dump(void);
+
 #endif /* AFP_UUID_H */
index 0f3a4024a6a36faedc4993783a731369e56237b3..51bf30fc90a3a908dbdce8973a40ff86a424a830 100644 (file)
@@ -9,7 +9,7 @@
 #define VOLINFOFILE ".volinfo"
 
 typedef struct {
-    const u_int32_t option;
+    const uint32_t option;
     const char      *name;
 } vol_opt_name_t;
 
@@ -30,7 +30,7 @@ struct volinfo {
     int                 v_adouble;  /* default adouble format */
     int                 v_ad_options;
     int                 v_vfs_ea;
-    char                *(*ad_path)(const char *, int);
+    const char          *(*ad_path)(const char *, int);
     char                *v_dbd_host;
     char                *v_dbd_port;
 };
index af2b411c625ca6b07f8203798d5ccbcd12d36c10..6d651128bd81178b27e3494cf06a416dce021db5 100644 (file)
@@ -7,9 +7,7 @@
 #define ATALK_VOLUME_H 1
 
 #include <stdint.h>
-#include <sys/cdefs.h>
 #include <sys/types.h>
-// #include <netatalk/endian.h>
 
 #include <atalk/unicode.h>
 #include <atalk/cnid.h>
@@ -23,7 +21,7 @@ typedef uint64_t VolSpace;
 
 struct vol {
     struct vol      *v_next;
-    u_int16_t       v_vid;
+    uint16_t        v_vid;
     int             v_flags;
     char            *v_path;
     struct dir      *v_root;
@@ -31,15 +29,15 @@ struct vol {
 
     charset_t       v_volcharset;
     charset_t       v_maccharset;
-    u_int16_t       v_mtou_flags;    /* flags for convert_charset in mtoupath */
-    u_int16_t       v_utom_flags;
+    uint16_t        v_mtou_flags;    /* flags for convert_charset in mtoupath */
+    uint16_t        v_utom_flags;
     long            v_kTextEncoding; /* mac charset encoding in network order
                                       * FIXME: should be a u_int32_t ? */
     size_t          max_filename;
     char            *v_veto;
     int             v_adouble;    /* adouble format: v1, v2, sfm ... */
     int             v_ad_options; /* adouble option NODEV, NOCACHE, etc.. */
-    char            *(*ad_path)(const char *, int);
+    const char      *(*ad_path)(const char *, int);
     struct _cnid_db *v_cdb;
     char            v_stamp[ADEDLEN_PRIVSYN];
     VolSpace        v_limitsize; /* Size limit, if any, in MiB */
@@ -88,10 +86,6 @@ struct vol {
     int             v_root_preexec_close;
     int             v_preexec_close;
     char            *v_uuid;    /* For TimeMachine zeroconf record */
-#ifdef FORCE_UIDGID
-    char            *v_forceuid;
-    char            *v_forcegid;
-#endif
 #ifdef __svr4__
     int         v_qfd;
 #endif /*__svr4__*/
@@ -120,7 +114,6 @@ struct vol {
 #define AFPVOL_USEDOTS   (1 << 11)  /* use real dots */
 #define AFPVOL_LIMITSIZE (1 << 12)  /* limit size for older macs */
 #define AFPVOL_MAPASCII  (1 << 13)  /* map the ascii range as well */
-#define AFPVOL_DROPBOX   (1 << 14)  /* dropkludge dropbox support */
 #define AFPVOL_NOFILEID  (1 << 15)  /* don't advertise createid resolveid and deleteid calls */
 #define AFPVOL_NOSTAT    (1 << 16)  /* advertise the volume even if we can't stat() it
                                      * maybe because it will be mounted later in preexec */
@@ -198,7 +191,8 @@ int wincheck(const struct vol *vol, const char *path);
 
 #define utf8_encoding() (afp_version >= 30)
 
-#define vol_noadouble(vol) (((vol)->v_flags & AFPVOL_NOADOUBLE) ? 1 : 0)
+#define vol_noadouble(vol) ((((vol)->v_flags & AFPVOL_NOADOUBLE) \
+                             || ((vol)->v_adouble & AD_VERSION_EA)) ? 1 : 0)
 #define vol_nodev(vol) (((vol)->v_flags & AFPVOL_NODEV) ? 1 : 0)
 #define vol_unix_priv(vol) (afp_version >= 30 && ((vol)->v_flags & AFPVOL_UNIX_PRIV))
 #define vol_inv_dots(vol) (((vol)->v_flags & AFPVOL_INV_DOTS) ? 1 : 0)
index a241d94cd7c43e88c8ce78511d266e523c3621da..63dcead0f34abbd35907dc0f18565808e33ada24 100644 (file)
@@ -1,6 +1,7 @@
 
 # Makefile.am for libatalk/
 
+# rpc should be first because it generates RPC headers included elsewhere
 SUBDIRS = acl adouble bstring compat cnid dsi tdb util unicode vfs
 
 lib_LTLIBRARIES = libatalk.la
@@ -13,9 +14,9 @@ libatalk_la_LIBADD  = \
        bstring/libbstring.la \
        compat/libcompat.la     \
        dsi/libdsi.la           \
-       util/libutil.la         \
        tdb/libtdb.la       \
        unicode/libunicode.la \
+       util/libutil.la         \
        vfs/libvfs.la
 
 libatalk_la_DEPENDENCIES = \
@@ -24,23 +25,9 @@ libatalk_la_DEPENDENCIES = \
        bstring/libbstring.la \
        compat/libcompat.la     \
        dsi/libdsi.la           \
-       util/libutil.la         \
        tdb/libtdb.la       \
        unicode/libunicode.la \
+       util/libutil.la         \
        vfs/libvfs.la
 
 libatalk_la_LDFLAGS = -static
-
-if USE_APPLETALK
-SUBDIRS +=  asp atp nbp netddp
-libatalk_la_LIBADD += \
-       asp/libasp.la           \
-       atp/libatp.la           \
-       nbp/libnbp.la           \
-       netddp/libnetddp.la
-libatalk_la_DEPENDENCIES += \
-       asp/libasp.la           \
-       atp/libatp.la           \
-       nbp/libnbp.la           \
-       netddp/libnetddp.la
-endif
index 9fe8405ff72a3e9b9e749cbbeb8b97ce5e559d8f..86bc34dcfd59bf4bbb81c9785a072b502fda4e4c 100644 (file)
@@ -30,7 +30,7 @@
 typedef struct cacheduser {
     unsigned long uid;      /* for future use */
     uuidtype_t type;
-    uuidp_t uuid;
+    unsigned char *uuid;
     char *name;
     time_t creationtime;
     struct cacheduser *prev;
@@ -127,7 +127,7 @@ static unsigned char hashuuid(uuidp_t uuid) {
 int add_cachebyname( const char *inname, const uuidp_t inuuid, const uuidtype_t type, const unsigned long uid _U_) {
     int ret = 0;
     char *name = NULL;
-    uuidp_t uuid = NULL;
+    unsigned char *uuid = NULL;
     cacheduser_t *cacheduser = NULL;
     unsigned char hash;
 
@@ -200,7 +200,7 @@ cleanup:
  * @returns       0 on sucess, entry found
  *                -1 no entry found
  */
-int search_cachebyname(const char *name, uuidtype_t *type, uuidp_t uuid) {
+int search_cachebyname( const char *name, uuidtype_t *type, unsigned char *uuid) {
     int ret;
     unsigned char hash;
     cacheduser_t *entry;
@@ -299,7 +299,7 @@ int search_cachebyuuid( uuidp_t uuidp, char **name, uuidtype_t *type) {
 int add_cachebyuuid( uuidp_t inuuid, const char *inname, uuidtype_t type, const unsigned long uid _U_) {
     int ret = 0;
     char *name = NULL;
-    uuidp_t uuid = NULL;
+    unsigned char *uuid = NULL;
     cacheduser_t *cacheduser = NULL;
     cacheduser_t *entry;
     unsigned char hash;
index 252d7da2681742cda7772c43eb793f76204853ab..11731a26c69d5bdeb683be1667a8c2c6bd351e03 100644 (file)
@@ -32,7 +32,7 @@
  * Interface
  ********************************************************/
 
-extern int search_cachebyname( const char *name, uuidtype_t *type, uuidp_t uuid);
+extern int search_cachebyname( const char *name, uuidtype_t *type, unsigned char *uuid);
 extern int add_cachebyname( const char *inname, const uuidp_t inuuid, const uuidtype_t type, const unsigned long uid);
 extern int search_cachebyuuid( uuidp_t uuidp, char **name, uuidtype_t *type);
 extern int add_cachebyuuid( uuidp_t inuuid, const char *inname, uuidtype_t type, const unsigned long uid);
index 7c0cf12e4fec035d9e81808aeeed5d5da49ad8c5..6df8d62b8b9ab0aae0c37adde0d150415a9d198f 100644 (file)
@@ -24,6 +24,7 @@
 #include <sys/types.h>
 #include <pwd.h>
 #include <grp.h>
+#include <arpa/inet.h>
 
 #include <atalk/logger.h>
 #include <atalk/afp.h>
@@ -71,7 +72,7 @@ void localuuid_from_id(unsigned char *buf, uuidtype_t type, unsigned int id)
  * convert ascii string that can include dashes to binary uuid.
  * caller must provide a buffer.
  */
-void uuid_string2bin( const char *uuidstring, uuidp_t uuid) {
+void uuid_string2bin( const char *uuidstring, unsigned char *uuid) {
     int nibble = 1;
     int i = 0;
     unsigned char c, val = 0;
@@ -105,7 +106,7 @@ void uuid_string2bin( const char *uuidstring, uuidp_t uuid) {
  *
  * Returns pointer to static buffer.
  */
-const char *uuid_bin2string(unsigned char *uuid) {
+const char *uuid_bin2string(const unsigned char *uuid) {
     static char uuidstring[UUID_STRINGSIZE + 1];
 
     int i = 0;
@@ -133,7 +134,7 @@ const char *uuid_bin2string(unsigned char *uuid) {
  *   uuid: pointer to uuid_t storage that the caller must provide
  * returns 0 on success !=0 on errror
  */
-int getuuidfromname( const char *name, uuidtype_t type, uuidp_t uuid) {
+int getuuidfromname( const char *name, uuidtype_t type, unsigned char *uuid) {
     int ret = 0;
     uuidtype_t mytype = type;
     char nulluuid[16] = {0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0};
index 8a242c2a87679e775aa3773c3d335f02ad6d49f6..6602926b6328986453cb395bbb9c476bdf582aca 100644 (file)
@@ -5,4 +5,4 @@ noinst_LTLIBRARIES = libadouble.la
 libadouble_la_SOURCES = ad_open.c ad_flush.c ad_read.c ad_write.c ad_size.c \
        ad_mmap.c ad_lock.c ad_date.c ad_attr.c ad_sendfile.c
 
-noinst_HEADERS = ad_private.h
+noinst_HEADERS = ad_lock.h
index 123560b5683b3e4af2729ce02631f238c48ffe4a..e005577f026dd1fc661ef0ded2ef1aedc49bfdbf 100644 (file)
@@ -3,6 +3,7 @@
 #endif /* HAVE_CONFIG_H */
 
 #include <string.h>
+#include <arpa/inet.h>
 #include <atalk/adouble.h>
 
 #define FILEIOFF_ATTR 14
    retrieved from the FinderFlags. This fixes Bug #2802236:
    <https://sourceforge.net/tracker/?func=detail&aid=2802236&group_id=8642&atid=108642>
  */
-int ad_getattr(const struct adouble *ad, u_int16_t *attr)
+int ad_getattr(const struct adouble *ad, uint16_t *attr)
 {
-    u_int16_t fflags;
+    uint16_t fflags;
     *attr = 0;
 
-    if (ad->ad_version == AD_VERSION1) {
-        if (ad_getentryoff(ad, ADEID_FILEI)) {
-            memcpy(attr, ad_entry(ad, ADEID_FILEI) + FILEIOFF_ATTR,
-                   sizeof(u_int16_t));
-        }
-    }
-#if AD_VERSION == AD_VERSION2
-    else if (ad->ad_version == AD_VERSION2) {
+    if (ad->ad_version == AD_VERSION2) {
         if (ad_getentryoff(ad, ADEID_AFPFILEI)) {
             memcpy(attr, ad_entry(ad, ADEID_AFPFILEI) + AFPFILEIOFF_ATTR, 2);
 
@@ -48,9 +42,6 @@ int ad_getattr(const struct adouble *ad, u_int16_t *attr)
             }
         }
     }
-#endif
-    else
-        return -1;
 
     *attr |= htons(ad->ad_open_forks);
 
@@ -58,26 +49,19 @@ int ad_getattr(const struct adouble *ad, u_int16_t *attr)
 }
 
 /* ----------------- */
-int ad_setattr(const struct adouble *ad, const u_int16_t attribute)
+int ad_setattr(const struct adouble *ad, const uint16_t attribute)
 {
     uint16_t fflags;
 
     /* we don't save open forks indicator */
-    u_int16_t attr = attribute & ~htons(ATTRBIT_DOPEN | ATTRBIT_ROPEN);
+    uint16_t attr = attribute & ~htons(ATTRBIT_DOPEN | ATTRBIT_ROPEN);
 
     /* Proactively (10.4 does indeed try to set ATTRBIT_MULTIUSER (=ATTRBIT_EXPFLDR)
        for dirs with SetFile -a M <dir> ) disable all flags not defined for dirs. */
     if (ad->ad_adflags & ADFLAGS_DIR)
         attr &= ~(ATTRBIT_MULTIUSER | ATTRBIT_NOWRITE | ATTRBIT_NOCOPY);
 
-    if (ad->ad_version == AD_VERSION1) {
-        if (ad_getentryoff(ad, ADEID_FILEI)) {
-            memcpy(ad_entry(ad, ADEID_FILEI) + FILEIOFF_ATTR, &attr,
-                   sizeof(attr));
-        }
-    }
-#if AD_VERSION == AD_VERSION2
-    else if (ad->ad_version == AD_VERSION2) {
+    if (ad->ad_version == AD_VERSION2) {
         if (ad_getentryoff(ad, ADEID_AFPFILEI) && ad_getentryoff(ad, ADEID_FINDERI)) {
             memcpy(ad_entry(ad, ADEID_AFPFILEI) + AFPFILEIOFF_ATTR, &attr, sizeof(attr));
             
@@ -98,9 +82,6 @@ int ad_setattr(const struct adouble *ad, const u_int16_t attribute)
             memcpy(ad_entry(ad, ADEID_FINDERI) + FINDERINFO_FRFLAGOFF, &fflags, 2);
         }
     }
-#endif
-    else
-        return -1;
 
     return 0;
 }
@@ -109,8 +90,7 @@ int ad_setattr(const struct adouble *ad, const u_int16_t attribute)
  * save file/folder ID in AppleDoubleV2 netatalk private parameters
  * return 1 if resource fork has been modified
  */
-#if AD_VERSION == AD_VERSION2
-int ad_setid (struct adouble *adp, const dev_t dev, const ino_t ino , const u_int32_t id, const cnid_t did, const void *stamp)
+int ad_setid (struct adouble *adp, const dev_t dev, const ino_t ino , const uint32_t id, const cnid_t did, const void *stamp)
 {
     if ((adp->ad_flags == AD_VERSION2) && (adp->ad_options & ADVOL_CACHE)) {
 
@@ -139,9 +119,9 @@ int ad_setid (struct adouble *adp, const dev_t dev, const ino_t ino , const u_in
 }
 
 /* ----------------------------- */
-u_int32_t ad_getid (struct adouble *adp, const dev_t st_dev, const ino_t st_ino , const cnid_t did, const void *stamp)
+uint32_t ad_getid (struct adouble *adp, const dev_t st_dev, const ino_t st_ino , const cnid_t did, const void *stamp)
 {
-    u_int32_t aint = 0;
+    uint32_t aint = 0;
     dev_t  dev;
     ino_t  ino;
     cnid_t a_did;
@@ -153,7 +133,7 @@ u_int32_t ad_getid (struct adouble *adp, const dev_t st_dev, const ino_t st_ino
      */
     if (adp
         && (adp->ad_options & ADVOL_CACHE)
-        && (adp->ad_md->adf_flags & O_RDWR )
+        && (adp->ad_mdp->adf_flags & O_RDWR )
         && (sizeof(dev_t) == ad_getentrylen(adp, ADEID_PRIVDEV)) /* One check to ensure ALL values are there */
         ) {
         memcpy(&dev, ad_entry(adp, ADEID_PRIVDEV), sizeof(dev_t));
@@ -173,9 +153,9 @@ u_int32_t ad_getid (struct adouble *adp, const dev_t st_dev, const ino_t st_ino
 }
 
 /* ----------------------------- */
-u_int32_t ad_forcegetid (struct adouble *adp)
+uint32_t ad_forcegetid (struct adouble *adp)
 {
-    u_int32_t aint = 0;
+    uint32_t aint = 0;
 
     if (adp && (adp->ad_options & ADVOL_CACHE)) {
         memcpy(&aint, ad_entry(adp, ADEID_PRIVID), sizeof(aint));
@@ -183,7 +163,6 @@ u_int32_t ad_forcegetid (struct adouble *adp)
     }
     return 0;
 }
-#endif
 
 /* -----------------
  * set resource fork filename attribute.
index 132c4f1ae7935b151b68ce34d269f3b91cd68616..304642d55f178b6e33d2ce2c9e1785457d933b18 100644 (file)
@@ -3,65 +3,42 @@
 #endif /* HAVE_CONFIG_H */
 
 #include <string.h>
+#include <arpa/inet.h>
 #include <atalk/adouble.h>
 
-int ad_setdate(struct adouble *ad, 
-              unsigned int dateoff, u_int32_t date)
+int ad_setdate(struct adouble *ad,
+               unsigned int dateoff, uint32_t date)
 {
-  int xlate = (dateoff & AD_DATE_UNIX);
+    int xlate = (dateoff & AD_DATE_UNIX);
 
-  dateoff &= AD_DATE_MASK;
-  if (xlate)
-    date = AD_DATE_FROM_UNIX(date);
+    dateoff &= AD_DATE_MASK;
+    if (xlate)
+        date = AD_DATE_FROM_UNIX(date);
 
-  if (ad->ad_version == AD_VERSION1) {
-
-    if (!ad_getentryoff(ad, ADEID_FILEI))
-        return -1;
-
-    if (dateoff > AD_DATE_BACKUP)
-      return -1;
-    memcpy(ad_entry(ad, ADEID_FILEI) + dateoff, &date, sizeof(date));
-
-  } else if (ad->ad_version == AD_VERSION2) {
     if (!ad_getentryoff(ad, ADEID_FILEDATESI))
         return -1;
-        
+
     if (dateoff > AD_DATE_ACCESS)
         return -1;
     memcpy(ad_entry(ad, ADEID_FILEDATESI) + dateoff, &date, sizeof(date));
 
-  } else 
-    return -1;
-
-  return 0;
+    return 0;
 }
 
 int ad_getdate(const struct adouble *ad,
-              unsigned int dateoff, u_int32_t *date) 
+               unsigned int dateoff, uint32_t *date)
 {
-  int xlate = (dateoff & AD_DATE_UNIX);
-
-  dateoff &= AD_DATE_MASK;
-  if (ad->ad_version == AD_VERSION1) {
-    if (dateoff > AD_DATE_BACKUP)
-      return -1;
-    if (!ad_getentryoff(ad, ADEID_FILEI))
-        return -1;
-    memcpy(date, ad_entry(ad, ADEID_FILEI) + dateoff, sizeof(u_int32_t));
+    int xlate = (dateoff & AD_DATE_UNIX);
 
-  } else if (ad->ad_version == AD_VERSION2) {
+    dateoff &= AD_DATE_MASK;
     if (!ad_getentryoff(ad, ADEID_FILEDATESI))
         return -1;
 
     if (dateoff > AD_DATE_ACCESS)
-      return -1;
-    memcpy(date, ad_entry(ad, ADEID_FILEDATESI) + dateoff, sizeof(u_int32_t));
-
-  } else 
-    return -1;
+        return -1;
+    memcpy(date, ad_entry(ad, ADEID_FILEDATESI) + dateoff, sizeof(uint32_t));
 
-  if (xlate)
-    *date = AD_DATE_TO_UNIX(*date);
-  return 0;
+    if (xlate)
+        *date = AD_DATE_TO_UNIX(*date);
+    return 0;
 }
index 1f4d8b331b4bb92eafcb3a15c4d20dffe28aa6de..f41b10826d730e2e2bffe775d5fba53848c3508c 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 1990,1991 Regents of The University of Michigan.
+ * Copyright (c) 2010      Frank Lahm
  * All Rights Reserved.
  *
  * Permission to use, copy, modify, and distribute this software and
 #endif /* HAVE_CONFIG_H */
 
 #include <string.h>
-#include <atalk/adouble.h>
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <errno.h>
+#include <arpa/inet.h>
 
-#include "ad_private.h"
-#if AD_VERSION == AD_VERSION1
-
-#define EID_DISK(a) (a)
+#include <atalk/adouble.h>
+#include <atalk/ea.h>
+#include <atalk/logger.h>
+#include <atalk/bstrlib.h>
+#include <atalk/bstradd.h>
 
-#else
+#include "ad_lock.h"
 
-static const u_int32_t set_eid[] = {
+static const uint32_t set_eid[] = {
     0,1,2,3,4,5,6,7,8,
     9,10,11,12,13,14,15,
     AD_DEV, AD_INO, AD_SYN, AD_ID
 };
 
 #define EID_DISK(a) (set_eid[a])
-#endif
 
-/* rebuild the adouble header
- * XXX should be in a separate file ?
+/*
+ * Rebuild any header information that might have changed.
  */
 int  ad_rebuild_adouble_header(struct adouble *ad)
 {
-    u_int32_t       eid;
-    u_int32_t       temp;
-
-    u_int16_t       nent;
+    uint32_t       eid;
+    uint32_t       temp;
+    uint16_t       nent;
     char        *buf, *nentp;
+    int             len;
 
-    /*
-     * Rebuild any header information that might have changed.
-     */
     buf = ad->ad_data;
 
     temp = htonl( ad->ad_magic );
@@ -72,7 +69,6 @@ int  ad_rebuild_adouble_header(struct adouble *ad)
     memcpy(buf, &temp, sizeof( temp ));
     buf += sizeof( temp );
 
-    memcpy(buf, ad->ad_filler, sizeof( ad->ad_filler ));
     buf += sizeof( ad->ad_filler );
 
     nentp = buf;
@@ -96,7 +92,21 @@ int  ad_rebuild_adouble_header(struct adouble *ad)
     }
     nent = htons( nent );
     memcpy(nentp, &nent, sizeof( nent ));
-    return ad_getentryoff(ad, ADEID_RFORK);
+
+    switch (ad->ad_flags) {
+    case AD_VERSION2:
+        len = ad_getentryoff(ad, ADEID_RFORK);
+        break;
+    case AD_VERSION_EA:
+        len = AD_DATASZ_EA;
+        break;
+    default:
+        LOG(log_error, logtype_afpd, "Unexpected adouble version");
+        len = 0;
+        break;
+    }
+
+    return len;
 }
 
 /* -------------------
@@ -106,8 +116,8 @@ int  ad_rebuild_adouble_header(struct adouble *ad)
  */
 int ad_copy_header(struct adouble *add, struct adouble *ads)
 {
-    u_int32_t       eid;
-    u_int32_t       len;
+    uint32_t       eid;
+    uint32_t       len;
 
     for ( eid = 0; eid < ADEID_MAX; eid++ ) {
         if ( ads->ad_eid[ eid ].ade_off == 0 ) {
@@ -134,67 +144,67 @@ int ad_copy_header(struct adouble *add, struct adouble *ads)
     return 0;
 }
 
-/* ------------------- */
-int  ad_rebuild_sfm_header(struct adouble *ad)
-{
-    u_int32_t       temp;
-
-    u_int16_t       attr;
-    char        *buf;
-
-    /*
-     * Rebuild any header information that might have changed.
-     */
-    buf = ad->ad_data;
-    /* FIXME */
-/*    temp = htonl( ad->ad_magic ); */
-    temp = ad->ad_magic;
-    memcpy(buf, &temp, sizeof( temp ));
-
-/*    temp = htonl( ad->ad_version ); */
-    temp = ad->ad_version;
-    memcpy(buf +4, &temp, sizeof( temp ));
-
-    /* need to save attrib */
-    if (!ad_getattr(ad, &attr)) {
-        attr &= ~htons(ATTRBIT_DOPEN | ATTRBIT_ROPEN);
-
-        memcpy(buf +48 +4, &attr, sizeof(attr));
-
-    }
-    return AD_SFM_LEN;
-}
-
-
-int ad_flush( struct adouble *ad)
+int ad_flush(struct adouble *ad)
 {
     int len;
+    struct ad_fd *adf;
+
+    switch (ad->ad_flags) {
+    case AD_VERSION2:
+        adf = ad->ad_mdp;
+        break;
+    case AD_VERSION_EA:
+        adf = &ad->ad_data_fork;
+        break;
+    default:
+        LOG(log_error, logtype_afpd, "ad_flush: unexpected adouble version");
+        return -1;
+    }
 
-    if (( ad->ad_md->adf_flags & O_RDWR )) {
-        /* sync our header */
-        if (ad->ad_rlen > 0xffffffff) {
-            ad_setentrylen(ad, ADEID_RFORK, 0xffffffff);
-        }
-        else {
-            ad_setentrylen(ad, ADEID_RFORK, ad->ad_rlen);
+    if ((adf->adf_flags & O_RDWR)) {
+        if (ad_getentryoff(ad, ADEID_RFORK)) {
+            if (ad->ad_rlen > 0xffffffff)
+                ad_setentrylen(ad, ADEID_RFORK, 0xffffffff);
+            else
+                ad_setentrylen(ad, ADEID_RFORK, ad->ad_rlen);
         }
         len = ad->ad_ops->ad_rebuild_header(ad);
 
-        if (adf_pwrite(ad->ad_md, ad->ad_data, len, 0) != len) {
-            if ( errno == 0 ) {
-                errno = EIO;
+        switch (ad->ad_flags) {
+        case AD_VERSION2:
+            if (adf_pwrite(ad->ad_mdp, ad->ad_data, len, 0) != len) {
+                if (errno == 0)
+                    errno = EIO;
+                return( -1 );
+            }
+            break;
+        case AD_VERSION_EA:
+            if (sys_fsetxattr(ad_data_fileno(ad), AD_EA_META, ad->ad_data, AD_DATASZ_EA, 0) != 0) {
+                LOG(log_error, logtype_afpd, "ad_flush: sys_fsetxattr error: %s",
+                    strerror(errno));
+                return -1;
             }
-            return( -1 );
+            break;
+        default:
+            LOG(log_error, logtype_afpd, "ad_flush: unexpected adouble version");
+            return -1;
         }
     }
 
     return( 0 );
 }
 
-/* use refcounts so that we don't have to re-establish fcntl locks. */
-int ad_close( struct adouble *ad, int adflags)
+/*!
+ * Close a struct adouble freeing all resources
+ */
+int ad_close(struct adouble *ad, int adflags)
 {
-    int         err = 0;
+    int err = 0;
+
+    if (ad == NULL)
+        return err;
+
+    LOG(log_debug, logtype_default, "ad_close(%s)", adflags2logstr(adflags));
 
     if ((adflags & ADFLAGS_DF)
         && (ad_data_fileno(ad) >= 0 || ad_data_fileno(ad) == -2) /* -2 means symlink */
@@ -210,34 +220,32 @@ int ad_close( struct adouble *ad, int adflags)
         adf_lock_free(&ad->ad_data_fork);
     }
 
-    if (!( adflags & ADFLAGS_HF )) {
-        return err;
-    }
-
-    /* meta /resource fork */
-
-    if ( ad_meta_fileno(ad) != -1 && !(--ad->ad_md->adf_refcount)) {
-        if ( close( ad_meta_fileno(ad) ) < 0 ) {
-            err = -1;
-        }
-        ad_meta_fileno(ad) = -1;
-        adf_lock_free(ad->ad_md);
-    }
-
-    if (ad->ad_flags != AD_VERSION1_SFM) {
-        return err;
-    }
-
-    if ((adflags & ADFLAGS_DIR)) {
-        return err;
-    }
+    if ((adflags & ADFLAGS_HF)) {
+        switch (ad->ad_flags) {
+        case AD_VERSION2:
+            if ((ad_meta_fileno(ad) != -1) && !(--ad->ad_mdp->adf_refcount)) {
+                if (close( ad_meta_fileno(ad) ) < 0)
+                    err = -1;
+                ad_meta_fileno(ad) = -1;
+                adf_lock_free(ad->ad_mdp);
+            }
+            break;
+
+        case AD_VERSION_EA:
+            if ((ad_data_fileno(ad) >= 0 || ad_data_fileno(ad) == -2) /* -2 means symlink */ 
+                && !(--ad->ad_data_fork.adf_refcount)) {
+                if (close( ad_data_fileno(ad) ) < 0)
+                    err = -1;
+                ad_data_fileno(ad) = -1;
+                adf_lock_free(&ad->ad_data_fork);
+            }
+            break;
 
-    if ( ad_reso_fileno(ad) != -1 && !(--ad->ad_resource_fork.adf_refcount)) {
-        if ( close( ad_reso_fileno(ad) ) < 0 ) {
-            err = -1;
+        default:
+            LOG(log_error, logtype_default, "ad_close: unknown AD version");
+            errno = EIO;
+            return -1;
         }
-        ad_reso_fileno(ad) = -1;
-        adf_lock_free(&ad->ad_resource_fork);
     }
 
     return err;
index e2139e5850b7ed4eacd1dd09dd5f88ce37d31cc5..5d6e4b1a234f1e61e629e81f70d539f75d9ed271 100644 (file)
@@ -2,11 +2,9 @@
  * Copyright (c) 1998,1999 Adrian Sun (asun@zoology.washington.edu)
  * All Rights Reserved. See COPYRIGHT for more information.
  *
- * Byte-range locks. This uses either whole-file flocks to fake byte
- * locks or fcntl-based actual byte locks. Because fcntl locks are
+ * Because fcntl locks are
  * process-oriented, we need to keep around a list of file descriptors
- * that refer to the same file. Currently, this doesn't serialize access 
- * to the locks. as a result, there's the potential for race conditions. 
+ * that refer to the same file.
  *
  * TODO: fix the race when reading/writing.
  *       keep a pool of both locks and reference counters around so that
 
 #include <string.h>
 
-#include "ad_private.h"
-
-/* translate between ADLOCK styles and specific locking mechanisms */
-#define XLATE_FLOCK(type) ((type) == ADLOCK_RD ? LOCK_SH : \
-((type) == ADLOCK_WR ? LOCK_EX : \
- ((type) == ADLOCK_CLR ? LOCK_UN : -1)))
-
-#ifdef DISABLE_LOCKING
-#define fcntl(a, b, c ) (0)
-#endif
+#include "ad_lock.h"
 
 /* ----------------------- */
 static int set_lock(int fd, int cmd,  struct flock *lock)
@@ -68,9 +57,9 @@ static int XLATE_FCNTL_LOCK(int type)
 /* ----------------------- */
 static int OVERLAP(off_t a, off_t alen, off_t b, off_t blen) 
 {
- return (!alen && a <= b) || 
-       (!blen && b <= a) || 
-       ( (a + alen > b) && (b + blen > a) );
   return (!alen && a <= b) || 
+        (!blen && b <= a) || 
+        ( (a + alen > b) && (b + blen > a) );
 }
 
 /* allocation for lock regions. we allocate aggressively and shrink
@@ -85,10 +74,8 @@ static void adf_freelock(struct ad_fd *ad, const int i)
 
     if (--(*lock->refcount) < 1) {
        free(lock->refcount); 
-       if (!ad->adf_excl) {
-           lock->lock.l_type = F_UNLCK;
-           set_lock(ad->adf_fd, F_SETLK, &lock->lock); /* unlock */
-       }
+    lock->lock.l_type = F_UNLCK;
+    set_lock(ad->adf_fd, F_SETLK, &lock->lock); /* unlock */
     }
 
     ad->adf_lockcount--;
@@ -143,24 +130,23 @@ static void adf_unlock(struct ad_fd *ad, const int fork)
 
 /* relock any byte lock that overlaps off/len. unlock everything
  * else. */
-static void adf_relockrange(struct ad_fd *ad, int fd,
-                                      const off_t off, const off_t len)
+static void adf_relockrange(struct ad_fd *ad, int fd, off_t off, off_t len)
 {
     adf_lock_t *lock = ad->adf_lock;
     int i;
     
-    if (!ad->adf_excl) for (i = 0; i < ad->adf_lockcount; i++) {
-      if (OVERLAP(off, len, lock[i].lock.l_start, lock[i].lock.l_len)) 
-       set_lock(fd, F_SETLK, &lock[i].lock);
+    for (i = 0; i < ad->adf_lockcount; i++) {
+        if (OVERLAP(off, len, lock[i].lock.l_start, lock[i].lock.l_len)) 
+            set_lock(fd, F_SETLK, &lock[i].lock);
     }
 }
 
 
 /* find a byte lock that overlaps off/len for a particular open fork */
 static int adf_findlock(struct ad_fd *ad,
-                                  const int fork, const int type,
-                                  const off_t off,
-                                  const off_t len)
+                        const int fork, const int type,
+                        const off_t off,
+                        const off_t len)
 {
   adf_lock_t *lock = ad->adf_lock;
   int i;
@@ -173,28 +159,30 @@ static int adf_findlock(struct ad_fd *ad,
       return i;
     }
   }
-
   return -1;
 }
 
 
 /* search other fork lock lists */
 static int adf_findxlock(struct ad_fd *ad, 
-                                    const int fork, const int type,
-                                    const off_t off,
-                                    const off_t len)
+                         const int fork, const int type,
+                         const off_t off,
+                         const off_t len)
 {
-  adf_lock_t *lock = ad->adf_lock;
-  int i;
+    adf_lock_t *lock = ad->adf_lock;
+    int i;
   
-  for (i = 0; i < ad->adf_lockcount; i++) {
-    if ((((type & ADLOCK_RD) && (lock[i].lock.l_type == F_RDLCK)) ||
-        ((type & ADLOCK_WR) && (lock[i].lock.l_type == F_WRLCK))) &&
-       (lock[i].user != fork) && 
-       OVERLAP(off, len, lock[i].lock.l_start, lock[i].lock.l_len)) 
-           return i;
-  } 
-  return -1;
+    for (i = 0; i < ad->adf_lockcount; i++) {
+        if ((((type & ADLOCK_RD) && (lock[i].lock.l_type == F_RDLCK))
+             ||
+             ((type & ADLOCK_WR) && (lock[i].lock.l_type == F_WRLCK)))
+            &&
+            (lock[i].user != fork)
+            && 
+            OVERLAP(off, len, lock[i].lock.l_start, lock[i].lock.l_len)) 
+            return i;
+    } 
+    return -1;
 }
 
 /* okay, this needs to do the following:
@@ -262,223 +250,73 @@ static off_t hf2off(off_t off)
        return start;
 }
 
-/* ------------------ */
-int ad_fcntl_lock(struct adouble *ad, const u_int32_t eid, const int locktype,
-                 const off_t off, const off_t len, const int fork)
+/* -------------- 
+       translate a resource fork lock to an offset
+*/
+static off_t rf2off(off_t off)
 {
-  struct flock lock;
-  struct ad_fd *adf;
-  adf_lock_t *adflock;
-  int oldlock;
-  int i;
-  int type;  
-
-  lock.l_start = off;
-  type = locktype;
-  if (eid == ADEID_DFORK) {
-    adf = &ad->ad_data_fork;
-    if ((type & ADLOCK_FILELOCK)) {
-        if (ad_meta_fileno(ad) != -1) { /* META */
-            adf = ad->ad_md;
-            lock.l_start = df2off(off);
-        }
-    }
-  } else { /* rfork */
-    if (ad_meta_fileno(ad) == -1 || ad_reso_fileno(ad) == -1) {
-        /* there's no meta data. return a lock error 
-         * otherwise if a second process is able to create it
-         * locks are a mess.
-         */
-        errno = EACCES;
-        return -1;
-    }
-    if (type & ADLOCK_FILELOCK) {
-      adf = ad->ad_md;                 /* either resource or meta data (set in ad_open) */
-      lock.l_start = hf2off(off);
-    }
-    else {
-      /* we really want the resource fork it's a byte lock */
-      adf = &ad->ad_resource_fork;
-      lock.l_start += ad_getentryoff(ad, eid);
-    }
-  }
-  /* NOTE: we can't write lock a read-only file. on those, we just
-    * make sure that we have a read lock set. that way, we at least prevent
-    * someone else from really setting a deny read/write on the file. 
-    */
-  if (!(adf->adf_flags & O_RDWR) && (type & ADLOCK_WR)) {
-      type = (type & ~ADLOCK_WR) | ADLOCK_RD;
-  }
-  
-  lock.l_type = XLATE_FCNTL_LOCK(type & ADLOCK_MASK);
-  lock.l_whence = SEEK_SET;
-  lock.l_len = len;
-
-  /* byte_lock(len=-1) lock whole file */
-  if (len == BYTELOCK_MAX) {
-      lock.l_len -= lock.l_start; /* otherwise  EOVERFLOW error */
-  }
-
-  /* see if it's locked by another fork. 
-   * NOTE: this guarantees that any existing locks must be at most
-   * read locks. we use ADLOCK_WR/RD because F_RD/WRLCK aren't
-   * guaranteed to be ORable. */
-  if (adf_findxlock(adf, fork, ADLOCK_WR | 
-                   ((type & ADLOCK_WR) ? ADLOCK_RD : 0), 
-                   lock.l_start, lock.l_len) > -1) {
-    errno = EACCES;
-    return -1;
-  }
-  
-  /* look for any existing lock that we may have */
-  i = adf_findlock(adf, fork, ADLOCK_RD | ADLOCK_WR, lock.l_start, lock.l_len);
-  adflock = (i < 0) ? NULL : adf->adf_lock + i;
-
-  /* here's what we check for:
-     1) we're trying to re-lock a lock, but we didn't specify an update.
-     2) we're trying to free only part of a lock. 
-     3) we're trying to free a non-existent lock. */
-  if ( (!adflock && (lock.l_type == F_UNLCK))
-       ||
-       (adflock
-        && !(type & ADLOCK_UPGRADE)
-        && ((lock.l_type != F_UNLCK)
-            || (adflock->lock.l_start != lock.l_start)
-            || (adflock->lock.l_len != lock.l_len) ))
-      ) {
-      errno = EINVAL;
-      return -1;
-  }
-
-
-  /* now, update our list of locks */
-  /* clear the lock */
-  if (lock.l_type == F_UNLCK) { 
-    adf_freelock(adf, i);
-    return 0;
-  }
-
-  /* attempt to lock the file. */
-  if (!adf->adf_excl && set_lock(adf->adf_fd, F_SETLK, &lock) < 0) 
-    return -1;
-
-  /* we upgraded this lock. */
-  if (adflock && (type & ADLOCK_UPGRADE)) {
-    memcpy(&adflock->lock, &lock, sizeof(lock));
-    return 0;
-  } 
-
-  /* it wasn't an upgrade */
-  oldlock = -1;
-  if (lock.l_type == F_RDLCK) {
-    oldlock = adf_findxlock(adf, fork, ADLOCK_RD, lock.l_start, lock.l_len);
-  } 
-    
-  /* no more space. this will also happen if lockmax == lockcount == 0 */
-  if (adf->adf_lockmax == adf->adf_lockcount) { 
-    adf_lock_t *tmp = (adf_lock_t *) 
-           realloc(adf->adf_lock, sizeof(adf_lock_t)*
-                   (adf->adf_lockmax + ARRAY_BLOCK_SIZE));
-    if (!tmp)
-      goto fcntl_lock_err;
-    adf->adf_lock = tmp;
-    adf->adf_lockmax += ARRAY_BLOCK_SIZE;
-  } 
-  adflock = adf->adf_lock + adf->adf_lockcount;
-
-  /* fill in fields */
-  memcpy(&adflock->lock, &lock, sizeof(lock));
-  adflock->user = fork;
-  if (oldlock > -1) {
-    adflock->refcount = (adf->adf_lock + oldlock)->refcount;
-  } else if ((adflock->refcount = calloc(1, sizeof(int))) == NULL) {
-    goto fcntl_lock_err;
-  }
-  
-  (*adflock->refcount)++;
-  adf->adf_lockcount++;
-  return 0;
-
-fcntl_lock_err:
-  lock.l_type = F_UNLCK;
-  if (!adf->adf_excl) set_lock(adf->adf_fd, F_SETLK, &lock);
-  return -1;
+    off_t start = off;
+       if (off == AD_FILELOCK_OPEN_WR)
+               start = AD_FILELOCK_RSRC_OPEN_WR;
+       else if (off == AD_FILELOCK_OPEN_RD)
+               start = AD_FILELOCK_RSRC_OPEN_RD;
+    else if (off == AD_FILELOCK_DENY_RD)
+               start = AD_FILELOCK_RSRC_DENY_RD;
+       else if (off == AD_FILELOCK_DENY_WR)
+               start = AD_FILELOCK_RSRC_DENY_WR;
+       else if (off == AD_FILELOCK_OPEN_NONE)
+               start = AD_FILELOCK_RSRC_OPEN_NONE;
+       return start;
 }
 
-/* -------------------------
-   we are using lock as tristate variable
-   
-   we have a lock ==> 1
-   no             ==> 0
-   error          ==> -1
-      
-*/
-static int testlock(struct ad_fd *adf, off_t off, off_t len)
+/*!
+ * Test a lock
+ *
+ * (1) Test against our own locks array
+ * (2) Test fcntl lock, locks from other processes
+ *
+ * @param adf     (r) handle
+ * @param off     (r) offset
+ * @param len     (r) lenght
+ *
+ * @returns           1 if there's an existing lock, 0 if there's no lock,
+ *                    -1 in case any error occured
+ */
+static int testlock(const struct ad_fd *adf, off_t off, off_t len)
 {
-  struct flock lock;
-  adf_lock_t *plock;
-  int i;
+    struct flock lock;
+    adf_lock_t *plock;
+    int i;
 
-  lock.l_start = off;
+    lock.l_start = off;
 
-  plock = adf->adf_lock;
-  lock.l_whence = SEEK_SET;
-  lock.l_len = len;
+    plock = adf->adf_lock;
+    lock.l_whence = SEEK_SET;
+    lock.l_len = len;
 
-  /* Do we have a lock? */
-  for (i = 0; i < adf->adf_lockcount; i++) {
-    if (OVERLAP(lock.l_start, 1, plock[i].lock.l_start, plock[i].lock.l_len)) 
-        return 1;   /* */
-  }
-  /* Does another process have a lock? 
-  */
-  lock.l_type = (adf->adf_flags & O_RDWR) ?F_WRLCK : F_RDLCK;
+    /* (1) Do we have a lock ? */
+    for (i = 0; i < adf->adf_lockcount; i++) {
+        if (OVERLAP(lock.l_start, 1, plock[i].lock.l_start, plock[i].lock.l_len)) 
+            return 1;
+    }
 
-  if (set_lock(adf->adf_fd, F_GETLK, &lock) < 0) {
-      /* is that kind of error possible ?*/
-      return (errno == EACCES || errno == EAGAIN)?1:-1;
-  }
-  
-  if (lock.l_type == F_UNLCK) {
-      return 0;
-  }
-  return 1;
-}
+    /* (2) Does another process have a lock? */
+    lock.l_type = (adf->adf_flags & O_RDWR) ? F_WRLCK : F_RDLCK;
 
-/* --------------- */
-int ad_testlock(struct adouble *ad, int eid, const off_t off)
-{
-  struct ad_fd *adf;
-  off_t      lock_offset;
-
-  lock_offset = off;
-  if (eid == ADEID_DFORK) {
-    adf = &ad->ad_data_fork;
-    if (ad_meta_fileno(ad) != -1) {
-       adf = ad->ad_md;
-       lock_offset = df2off(off);
+    if (set_lock(adf->adf_fd, F_GETLK, &lock) < 0) {
+        /* is that kind of error possible ?*/
+        return (errno == EACCES || errno == EAGAIN) ? 1 : -1;
     }
-  } 
-  else { /* rfork */
-    if (ad_meta_fileno(ad) == -1) {
-        /* there's no resource fork. return no lock */
+  
+    if (lock.l_type == F_UNLCK) {
         return 0;
     }
-    adf = ad->ad_md;
-    lock_offset = hf2off(off);
-  }
-  return testlock(adf, lock_offset, 1);
+    return 1;
 }
 
-/* -------------------------
-   return if a file is open by another process.
-   Optimized for the common case:
-   - there's no locks held by another process (clients)
-   - or we already know the answer and don't need to test.
-*/
-u_int16_t ad_openforks(struct adouble *ad, u_int16_t attrbits)
+static uint16_t ad_openforks_v2(struct adouble *ad, uint16_t attrbits)
 {
-  u_int16_t ret = 0;
+  uint16_t ret = 0;
   struct ad_fd *adf;
   off_t off;
 
@@ -492,7 +330,7 @@ u_int16_t ad_openforks(struct adouble *ad, u_int16_t attrbits)
           /* there's a resource fork test the four bytes for
            * data RW/RD and fork RW/RD locks in one request
           */
-         adf = ad->ad_md;
+         adf = ad->ad_mdp;
          off = LOCK_DATA_WR;
          len = 4;
       }
@@ -510,7 +348,7 @@ u_int16_t ad_openforks(struct adouble *ad, u_int16_t attrbits)
   */
   if (!(attrbits & ATTRBIT_DOPEN)) {
       if (ad_meta_fileno(ad) != -1) {
-         adf = ad->ad_md;
+         adf = ad->ad_mdp;
          off = LOCK_DATA_WR;
       }
       else {
@@ -522,7 +360,7 @@ u_int16_t ad_openforks(struct adouble *ad, u_int16_t attrbits)
 
   if (!(attrbits & ATTRBIT_ROPEN)) {
       if (ad_meta_fileno(ad) != -1) {
-         adf = ad->ad_md;
+         adf = ad->ad_mdp;
           off = LOCK_RSRC_WR;
           ret |= testlock(adf, off, 2) > 0? ATTRBIT_ROPEN : 0;
       }
@@ -531,114 +369,349 @@ u_int16_t ad_openforks(struct adouble *ad, u_int16_t attrbits)
   return ret;
 }
 
-/* -------------------------
-*/
-int ad_fcntl_tmplock(struct adouble *ad, const u_int32_t eid, const int locktype,
-                    const off_t off, const off_t len, const int fork)
+static uint16_t ad_openforks_ea(struct adouble *ad, uint16_t attrbits)
 {
-  struct flock lock;
-  struct ad_fd *adf;
-  int err;
-  int type;  
-
-  lock.l_start = off;
-  type = locktype;
-  if (eid == ADEID_DFORK) {
-    adf = &ad->ad_data_fork;
-  } else {
-    /* FIXME META */
-    adf = &ad->ad_resource_fork;
-    if (adf->adf_fd == -1) {
-        /* there's no resource fork. return success */
-        return 0;
-    }
-    /* if ADLOCK_FILELOCK we want a lock from offset 0
-     * it's used when deleting a file:
-     * in open we put read locks on meta datas
-     * in delete a write locks on the whole file
-     * so if the file is open by somebody else it fails
-    */
-    if (!(type & ADLOCK_FILELOCK))
-        lock.l_start += ad_getentryoff(ad, eid);
-  }
+    uint16_t ret = 0;
+    struct ad_fd *adf;
+    off_t off;
+    off_t len;
 
-  if (!(adf->adf_flags & O_RDWR) && (type & ADLOCK_WR)) {
-      type = (type & ~ADLOCK_WR) | ADLOCK_RD;
-  }
-  
-  lock.l_type = XLATE_FCNTL_LOCK(type & ADLOCK_MASK);
-  lock.l_whence = SEEK_SET;
-  lock.l_len = len;
-
-  /* see if it's locked by another fork. */
-  if (fork && adf_findxlock(adf, fork, ADLOCK_WR | 
-                   ((type & ADLOCK_WR) ? ADLOCK_RD : 0), 
-                   lock.l_start, lock.l_len) > -1) {
-    errno = EACCES;
-    return -1;
+  if (!(attrbits & (ATTRBIT_DOPEN | ATTRBIT_ROPEN))) {
+      /* Test all 4 locks at once */
+      off = AD_FILELOCK_OPEN_WR;
+      len = 4;
+      if (testlock(&ad->ad_data_fork, off, len) == 0)
+          return 0;
   }
 
-  /* okay, we might have ranges byte-locked. we need to make sure that
-   * we restore the appropriate ranges once we're done. so, we check
-   * for overlap on an unlock and relock. 
-   * XXX: in the future, all the byte locks will be sorted and contiguous.
-   *      we just want to upgrade all the locks and then downgrade them
-   *      here. */
-  if (!adf->adf_excl) {
-       err = set_lock(adf->adf_fd, F_SETLK, &lock);
+  /* either there's a lock or we already know one fork is open */
+
+  if (!(attrbits & ATTRBIT_DOPEN)) {
+      off = AD_FILELOCK_OPEN_WR;
+      ret = testlock(&ad->ad_data_fork, off, 2) > 0 ? ATTRBIT_DOPEN : 0;
   }
-  else {
-      err = 0;
+
+  if (!(attrbits & ATTRBIT_ROPEN)) {
+      off = AD_FILELOCK_RSRC_OPEN_WR;
+      ret |= testlock(&ad->ad_data_fork, off, 2) > 0? ATTRBIT_ROPEN : 0;
   }
-  if (!err && (lock.l_type == F_UNLCK))
-    adf_relockrange(adf, adf->adf_fd, lock.l_start, len);
 
-  return err;
+  return ret;
+}
+
+static int ad_testlock_v2(struct adouble *ad, int eid, const off_t off)
+{
+    struct ad_fd *adf;
+    off_t      lock_offset;
+
+    lock_offset = off;
+    if (eid == ADEID_DFORK) {
+        adf = &ad->ad_data_fork;
+        if (ad_meta_fileno(ad) != -1) {
+            adf = ad->ad_mdp;
+            lock_offset = df2off(off);
+        }
+    } else { /* rfork */
+        if (ad_meta_fileno(ad) == -1) {
+            /* there's no resource fork. return no lock */
+            return 0;
+        }
+        adf = ad->ad_mdp;
+        lock_offset = hf2off(off);
+    }
+    return testlock(adf, lock_offset, 1);
+}
+
+static int ad_testlock_ea(struct adouble *ad, int eid, const off_t off)
+{
+    off_t      lock_offset;
+
+    if (eid == ADEID_DFORK) {
+        lock_offset = df2off(off);
+    } else { /* rfork */
+        lock_offset = rf2off(off);
+    }
+    return testlock(&ad->ad_data_fork, lock_offset, 1);
+}
+
+/******************************************************************************
+ * Public functions
+ ******************************************************************************/
+
+int ad_lock(struct adouble *ad, uint32_t eid, int locktype, off_t off, off_t len, int fork)
+{
+    struct flock lock;
+    struct ad_fd *adf;
+    adf_lock_t *adflock;
+    int oldlock;
+    int i;
+    int type;  
+
+    if ((type & ADLOCK_FILELOCK) && (len != 1))
+        /* safety check */
+        return -1;
+
+    lock.l_start = off;
+    type = locktype;
+    if (eid == ADEID_DFORK) {
+        adf = &ad->ad_data_fork;
+        if ((type & ADLOCK_FILELOCK)) {
+            if (ad_meta_fileno(ad) != -1) { /* META */
+                adf = ad->ad_mdp;
+                lock.l_start = df2off(off);
+            }
+        }
+    } else { /* rfork */
+        switch (ad->ad_flags) {
+        case AD_VERSION2:
+            if (ad_meta_fileno(ad) == -1 || ad_reso_fileno(ad) == -1) {
+                /* there's no meta data. return a lock error 
+                 * otherwise if a second process is able to create it
+                 * locks are a mess. */
+                errno = EACCES;
+                return -1;
+            }
+            if (type & ADLOCK_FILELOCK) {
+                adf = ad->ad_mdp;                      /* either resource or meta data (set in ad_open) */
+                lock.l_start = hf2off(off);
+            } else {
+                /* we really want the resource fork it's a byte lock */
+                adf = &ad->ad_resource_fork;
+                lock.l_start += ad_getentryoff(ad, eid);
+            }
+            break;
+
+        case AD_VERSION_EA:
+            if (type & ADLOCK_FILELOCK) {
+                lock.l_start = rf2off(off);
+            } else {
+                /* it's a byterange lock on the rsrcfork -> discard it */
+                return 0;
+            }
+            adf = &ad->ad_data_fork;
+            break;
+
+        default:
+            return -1;
+        }
+    }
+
+    /* NOTE: we can't write lock a read-only file. on those, we just
+     * make sure that we have a read lock set. that way, we at least prevent
+     * someone else from really setting a deny read/write on the file. 
+     */
+    if (!(adf->adf_flags & O_RDWR) && (type & ADLOCK_WR)) {
+        type = (type & ~ADLOCK_WR) | ADLOCK_RD;
+    }
+  
+    lock.l_type = XLATE_FCNTL_LOCK(type & ADLOCK_MASK);
+    lock.l_whence = SEEK_SET;
+    lock.l_len = len;
+
+    /* byte_lock(len=-1) lock whole file */
+    if (len == BYTELOCK_MAX) {
+        lock.l_len -= lock.l_start; /* otherwise  EOVERFLOW error */
+    }
+
+    /* see if it's locked by another fork. 
+     * NOTE: this guarantees that any existing locks must be at most
+     * read locks. we use ADLOCK_WR/RD because F_RD/WRLCK aren't
+     * guaranteed to be ORable. */
+    if (adf_findxlock(adf, fork, ADLOCK_WR | 
+                      ((type & ADLOCK_WR) ? ADLOCK_RD : 0), 
+                      lock.l_start, lock.l_len) > -1) {
+        errno = EACCES;
+        return -1;
+    }
+  
+    /* look for any existing lock that we may have */
+    i = adf_findlock(adf, fork, ADLOCK_RD | ADLOCK_WR, lock.l_start, lock.l_len);
+    adflock = (i < 0) ? NULL : adf->adf_lock + i;
+
+    /* here's what we check for:
+       1) we're trying to re-lock a lock, but we didn't specify an update.
+       2) we're trying to free only part of a lock. 
+       3) we're trying to free a non-existent lock. */
+    if ( (!adflock && (lock.l_type == F_UNLCK))
+         ||
+         (adflock
+          && !(type & ADLOCK_UPGRADE)
+          && ((lock.l_type != F_UNLCK)
+              || (adflock->lock.l_start != lock.l_start)
+              || (adflock->lock.l_len != lock.l_len) ))
+        ) {
+        errno = EINVAL;
+        return -1;
+    }
+
+
+    /* now, update our list of locks */
+    /* clear the lock */
+    if (lock.l_type == F_UNLCK) { 
+        adf_freelock(adf, i);
+        return 0;
+    }
+
+    /* attempt to lock the file. */
+    if (set_lock(adf->adf_fd, F_SETLK, &lock) < 0) 
+        return -1;
+
+    /* we upgraded this lock. */
+    if (adflock && (type & ADLOCK_UPGRADE)) {
+        memcpy(&adflock->lock, &lock, sizeof(lock));
+        return 0;
+    } 
+
+    /* it wasn't an upgrade */
+    oldlock = -1;
+    if (lock.l_type == F_RDLCK) {
+        oldlock = adf_findxlock(adf, fork, ADLOCK_RD, lock.l_start, lock.l_len);
+    } 
+    
+    /* no more space. this will also happen if lockmax == lockcount == 0 */
+    if (adf->adf_lockmax == adf->adf_lockcount) { 
+        adf_lock_t *tmp = (adf_lock_t *) 
+            realloc(adf->adf_lock, sizeof(adf_lock_t)*
+                    (adf->adf_lockmax + ARRAY_BLOCK_SIZE));
+        if (!tmp)
+            goto fcntl_lock_err;
+        adf->adf_lock = tmp;
+        adf->adf_lockmax += ARRAY_BLOCK_SIZE;
+    } 
+    adflock = adf->adf_lock + adf->adf_lockcount;
+
+    /* fill in fields */
+    memcpy(&adflock->lock, &lock, sizeof(lock));
+    adflock->user = fork;
+    if (oldlock > -1) {
+        adflock->refcount = (adf->adf_lock + oldlock)->refcount;
+    } else if ((adflock->refcount = calloc(1, sizeof(int))) == NULL) {
+        goto fcntl_lock_err;
+    }
+  
+    (*adflock->refcount)++;
+    adf->adf_lockcount++;
+    return 0;
+
+fcntl_lock_err:
+    lock.l_type = F_UNLCK;
+    set_lock(adf->adf_fd, F_SETLK, &lock);
+    return -1;
 }
 
 /* -------------------------
-   the fork is opened in Read Write, Deny Read, Deny Write mode
-   lock the whole file once   
 */
-int ad_excl_lock(struct adouble *ad, const u_int32_t eid)
+int ad_tmplock(struct adouble *ad, const uint32_t eid, const int locktype,
+               const off_t off, const off_t len, const int fork)
 {
-  struct ad_fd *adf;
-  struct flock lock;
-  int    err;
-  
-  lock.l_start = 0;
-  lock.l_type = F_WRLCK;
-  lock.l_whence = SEEK_SET;
-  lock.l_len = 0;
-
-  if (eid == ADEID_DFORK) {
-    adf = &ad->ad_data_fork;
-  } else {
-    adf = &ad->ad_resource_fork;
-    lock.l_start = ad_getentryoff(ad, eid);
-  }
+    struct flock lock;
+    struct ad_fd *adf;
+    int err;
+    int type;  
+
+    lock.l_start = off;
+    type = locktype;
+    if (eid == ADEID_DFORK) {
+        adf = &ad->ad_data_fork;
+    } else {
+        /* FIXME META */
+        adf = &ad->ad_resource_fork;
+        if (adf->adf_fd == -1) {
+            /* there's no resource fork. return success */
+            return 0;
+        }
+        /* if ADLOCK_FILELOCK we want a lock from offset 0
+         * it's used when deleting a file:
+         * in open we put read locks on meta datas
+         * in delete a write locks on the whole file
+         * so if the file is open by somebody else it fails
+         */
+        if (!(type & ADLOCK_FILELOCK))
+            lock.l_start += ad_getentryoff(ad, eid);
+    }
+
+    if (!(adf->adf_flags & O_RDWR) && (type & ADLOCK_WR)) {
+        type = (type & ~ADLOCK_WR) | ADLOCK_RD;
+    }
   
-  err = set_lock(adf->adf_fd, F_SETLK, &lock);
-  if (!err)
-      adf->adf_excl = 1;
-  return err;
+    lock.l_type = XLATE_FCNTL_LOCK(type & ADLOCK_MASK);
+    lock.l_whence = SEEK_SET;
+    lock.l_len = len;
+
+    /* see if it's locked by another fork. */
+    if (fork && adf_findxlock(adf, fork,
+                              ADLOCK_WR | ((type & ADLOCK_WR) ? ADLOCK_RD : 0), 
+                              lock.l_start, lock.l_len) > -1) {
+        errno = EACCES;
+        return -1;
+    }
+
+    /* okay, we might have ranges byte-locked. we need to make sure that
+     * we restore the appropriate ranges once we're done. so, we check
+     * for overlap on an unlock and relock. 
+     * XXX: in the future, all the byte locks will be sorted and contiguous.
+     *      we just want to upgrade all the locks and then downgrade them
+     *      here. */
+    err = set_lock(adf->adf_fd, F_SETLK, &lock);
+    if (!err && (lock.l_type == F_UNLCK))
+        adf_relockrange(adf, adf->adf_fd, lock.l_start, len);
+
+    return err;
 }
 
 /* --------------------- */
-void ad_fcntl_unlock(struct adouble *ad, const int fork)
+void ad_unlock(struct adouble *ad, const int fork)
 {
-  if (ad_data_fileno(ad) != -1) {
-    adf_unlock(&ad->ad_data_fork, fork);
-  }
-  if (ad_reso_fileno(ad) != -1) {
-    adf_unlock(&ad->ad_resource_fork, fork);
-  }
+    if (ad_data_fileno(ad) != -1) {
+        adf_unlock(&ad->ad_data_fork, fork);
+    }
+    if (ad_reso_fileno(ad) != -1) {
+        adf_unlock(&ad->ad_resource_fork, fork);
+    }
+}
 
-  if (ad->ad_flags != AD_VERSION1_SFM) {
-    return;
-  }
-  if (ad_meta_fileno(ad) != -1) {
-    adf_unlock(&ad->ad_metadata_fork, fork);
-  }
+/*!
+ * Test for a share mode lock
+ *
+ * @param ad      (rw) handle
+ * @param eid     (r)  datafork or ressource fork
+ * @param off     (r)  sharemode lock to test
+ *
+ * @returns           1 if there's an existing lock, 0 if there's no lock,
+ *                    -1 in case any error occured
+ */
+int ad_testlock(struct adouble *ad, int eid, const off_t off)
+{
+    switch (ad->ad_flags) {
+    case AD_VERSION2:
+        return ad_testlock_v2(ad, eid, off);
+    case AD_VERSION_EA:
+        return ad_testlock_ea(ad, eid, off);
+    default:
+        return -1;
+    }
+}
 
+/*!
+ * Return if a file is open by another process.
+ *
+ * Optimized for the common case:
+ * - there's no locks held by another process (clients)
+ * - or we already know the answer and don't need to test (attrbits)
+ *
+ * @param ad          (rw) handle
+ * @param attrbits    (r)  forks opened by us
+ * @returns                bitflags ATTRBIT_DOPEN | ATTRBIT_ROPEN if
+ *                         other process has fork of file opened 
+ */
+uint16_t ad_openforks(struct adouble *ad, uint16_t attrbits)
+{
+    switch (ad->ad_flags) {
+    case AD_VERSION2:
+        return ad_openforks_v2(ad, attrbits);
+    case AD_VERSION_EA:
+        return ad_openforks_ea(ad, attrbits);
+    default:
+        return -1;
+    }
 }
diff --git a/libatalk/adouble/ad_lock.h b/libatalk/adouble/ad_lock.h
new file mode 100644 (file)
index 0000000..b08807a
--- /dev/null
@@ -0,0 +1,28 @@
+#ifndef LIBATALK_ADOUBLE_AD_PRIVATE_H
+#define LIBATALK_ADOUBLE_AD_PRIVATE_H 1
+
+#include <atalk/adouble.h>
+
+/* this is so that we can keep lists of fds referencing the same file                                                                                                                                                                                                         
+ * around. that way, we can honor locks created by the same process                                                                                                                                                                                                           
+ * with the same file. */
+
+#define adf_lock_init(a) do {   \
+        (a)->adf_lockmax = 0;   \
+        (a)->adf_lockcount = 0; \
+        (a)->adf_lock = NULL;   \
+    } while (0)
+
+#define adf_lock_free(a) do {                                 \
+        int i;                                                \
+        if (!(a)->adf_lock)                                   \
+            break;                                            \
+        for (i = 0; i < (a)->adf_lockcount; i++) {            \
+            adf_lock_t *lock = (a)->adf_lock + i;             \
+            if (--(*lock->refcount) < 1)free(lock->refcount); \
+        }                                                     \
+        free((a)->adf_lock);                                  \
+        adf_lock_init(a);                                     \
+    } while (0)
+
+#endif /* libatalk/adouble/ad_private.h */
index 2cb5c05937f2f6d69470996bea5994eaaf069e2b..a93ab5a502dfa64a7f826160457b4fa61d93b304 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: ad_mmap.c,v 1.6 2008-12-03 18:35:44 didg Exp $
- *
  * ad_mmap provides interfaces to memory mapped files. as this is the
  * case, we don't have to deal w/ temporary buffers such as
  * ad_data. the ad_mmap routines are designed to not interact w/ the
@@ -17,7 +15,7 @@
 #include <atalk/adouble.h>
 #include <string.h>
 
-#include "ad_private.h"
+#include "ad_lock.h"
 
 static void *ad_mmap(const size_t length, const int prot,
                                const int flags, const int fd, 
index 7adb4abda262c7261a8197463d36f9369a2a7426..269ff6669d08c92b2e372901ea34e5cd5a8da929 100644 (file)
@@ -1,6 +1,8 @@
 /*
  * Copyright (c) 1999 Adrian Sun (asun@u.washington.edu)
  * Copyright (c) 1990,1991 Regents of The University of Michigan.
+ * Copyright (c) 2010 Frank Lahm
+ *
  * All Rights Reserved.
  *
  * Permission to use, copy, modify, and distribute this software and
@@ -26,8 +28,6 @@
 /*!
  * @file
  * Part of Netatalk's AppleDouble implementatation
- * @note We don't use inlines because a good compiler should be
- *       able to optimize all the static funcs below.
  * @sa include/atalk/adouble.h
  */
 
 #endif /* HAVE_CONFIG_H */
 
 #include <errno.h>
-
-#include <atalk/adouble.h>
 #include <sys/param.h>
-#include <atalk/logger.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#include <arpa/inet.h>
 
+#include <atalk/logger.h>
+#include <atalk/adouble.h>
 #include <atalk/util.h>
-#include <string.h>
+#include <atalk/ea.h>
+#include <atalk/bstrlib.h>
+#include <atalk/bstradd.h>
+#include <atalk/compat.h>
+#include <atalk/errchk.h>
+#include <atalk/volume.h>
 
-#include "ad_private.h"
-#include <stdlib.h>
+#include "ad_lock.h"
 
 #ifndef MAX
 #define MAX(a, b)  ((a) < (b) ? (b) : (a))
 #endif /* ! MAX */
 
-/*
- * AppleDouble entry default offsets.
- * The layout looks like this:
- *
- * this is the v1 layout:
- *     255         200         16          32          N
- *  |  NAME |    COMMENT    | FILEI |    FINDERI    | RFORK |
- *
- * we need to change it to look like this:
- *
- * v2 layout:
- * field       length (in bytes)
- * NAME        255
- * COMMENT     200
- * FILEDATESI  16     replaces FILEI
- * FINDERI     32
- * DID          4     new
- * AFPFILEI     4     new
- * SHORTNAME   12     8.3 new
- * RFORK        N
- *
- * so, all we need to do is replace FILEI with FILEDATESI, move RFORK,
- * and add in the new fields.
- *
- * NOTE: the HFS module will need similar modifications to interact with
- * afpd correctly.
- */
-
 #define ADEDOFF_MAGIC        (0)
 #define ADEDOFF_VERSION      (ADEDOFF_MAGIC + ADEDLEN_MAGIC)
 #define ADEDOFF_FILLER       (ADEDOFF_VERSION + ADEDLEN_VERSION)
 /* initial lengths of some of the fields */
 #define ADEDLEN_INIT     0
 
-/* make sure we don't redefine ADEDOFF_FILEI */
-#ifdef ADEDOFF_FILEI
-#undef ADEDOFF_FILEI
-#endif /* ADEDOFF_FILEI */
-
-#define ADEDOFF_NAME_V1      (AD_HEADER_LEN + ADEID_NUM_V1*AD_ENTRY_LEN)
-#define ADEDOFF_COMMENT_V1   (ADEDOFF_NAME_V1 + ADEDLEN_NAME)
-#define ADEDOFF_FILEI        (ADEDOFF_COMMENT_V1 + ADEDLEN_COMMENT)
-#define ADEDOFF_FINDERI_V1   (ADEDOFF_FILEI + ADEDLEN_FILEI)
-#define ADEDOFF_RFORK_V1     (ADEDOFF_FINDERI_V1 + ADEDLEN_FINDERI)
-
 /* i stick things in a slightly different order than their eid order in
  * case i ever want to separate RootInfo behaviour from the rest of the
  * stuff. */
+
+/* ad:v2 */
 #define ADEDOFF_NAME_V2      (AD_HEADER_LEN + ADEID_NUM_V2*AD_ENTRY_LEN)
 #define ADEDOFF_COMMENT_V2   (ADEDOFF_NAME_V2 + ADEDLEN_NAME)
 #define ADEDOFF_FILEDATESI   (ADEDOFF_COMMENT_V2 + ADEDLEN_COMMENT)
 #define ADEDOFF_FINDERI_V2   (ADEDOFF_FILEDATESI + ADEDLEN_FILEDATESI)
-#define ADEDOFF_DID      (ADEDOFF_FINDERI_V2 + ADEDLEN_FINDERI)
+#define ADEDOFF_DID          (ADEDOFF_FINDERI_V2 + ADEDLEN_FINDERI)
 #define ADEDOFF_AFPFILEI     (ADEDOFF_DID + ADEDLEN_DID)
 #define ADEDOFF_SHORTNAME    (ADEDOFF_AFPFILEI + ADEDLEN_AFPFILEI)
 #define ADEDOFF_PRODOSFILEI  (ADEDOFF_SHORTNAME + ADEDLEN_SHORTNAME)
 #define ADEDOFF_PRIVINO      (ADEDOFF_PRIVDEV + ADEDLEN_PRIVDEV)
 #define ADEDOFF_PRIVSYN      (ADEDOFF_PRIVINO + ADEDLEN_PRIVINO)
 #define ADEDOFF_PRIVID       (ADEDOFF_PRIVSYN + ADEDLEN_PRIVSYN)
-
 #define ADEDOFF_RFORK_V2     (ADEDOFF_PRIVID + ADEDLEN_PRIVID)
 
-#define ADEID_NUM_OSX        2
-#define ADEDOFF_FINDERI_OSX  (AD_HEADER_LEN + ADEID_NUM_OSX*AD_ENTRY_LEN)
-#define ADEDOFF_RFORK_OSX    (ADEDOFF_FINDERI_OSX + ADEDLEN_FINDERI)
-
-/* we keep local copies of a bunch of stuff so that we can initialize things
- * correctly. */
+/* ad:ea */
+#define ADEDOFF_FINDERI_EA   (AD_HEADER_LEN + ADEID_NUM_EA * AD_ENTRY_LEN)
+#define ADEDOFF_COMMENT_EA   (ADEDOFF_FINDERI_EA + ADEDLEN_FINDERI)
+#define ADEDOFF_FILEDATESI_EA (ADEDOFF_COMMENT_EA + ADEDLEN_COMMENT)
+#define ADEDOFF_AFPFILEI_EA  (ADEDOFF_FILEDATESI_EA + ADEDLEN_FILEDATESI)
 
 /* this is to prevent changing timezones from causing problems with
-   localtime volumes. the screw-up is 30 years. we use a delta of 5
-   years.  */
+   localtime volumes. the screw-up is 30 years. we use a delta of 5 years */
 #define TIMEWARP_DELTA 157680000
 
-
 struct entry {
-    u_int32_t id, offset, len;
+    uint32_t id, offset, len;
+};
+
+/* --------------------------- */
+static uid_t default_uid = -1;
+
+/* Forward declarations */
+static int ad_mkrf(const char *path);
+static int ad_header_read(struct adouble *ad, struct stat *hst);
+static int ad_header_upgrade(struct adouble *ad, const char *name);
+
+static int ad_mkrf_ea(const char *path);
+static int ad_header_read_ea(struct adouble *ad, struct stat *hst);
+static int ad_header_upgrade_ea(struct adouble *ad, const char *name);
+
+static struct adouble_fops ad_adouble = {
+    &ad_path,
+    &ad_mkrf,
+    &ad_rebuild_adouble_header,
+    &ad_header_read,
+    &ad_header_upgrade,
+};
+
+static struct adouble_fops ad_adouble_ea = {
+    &ad_path_ea,
+    &ad_mkrf_ea,
+    &ad_rebuild_adouble_header,
+    &ad_header_read_ea,
+    &ad_header_upgrade_ea,
 };
 
-static const struct entry entry_order1[ADEID_NUM_V1 +1] = {
-    {ADEID_NAME,    ADEDOFF_NAME_V1,    ADEDLEN_INIT},      /* 3 */
-    {ADEID_COMMENT, ADEDOFF_COMMENT_V1, ADEDLEN_INIT},      /* 4 */
-    {ADEID_FILEI,   ADEDOFF_FILEI,      ADEDLEN_FILEI},     /* 7 */
-    {ADEID_FINDERI, ADEDOFF_FINDERI_V1, ADEDLEN_FINDERI},   /* 9 */
-    {ADEID_RFORK,   ADEDOFF_RFORK_V1,   ADEDLEN_INIT},      /* 2 */
+static const struct entry entry_order2[ADEID_NUM_V2 + 1] = {
+    {ADEID_NAME,        ADEDOFF_NAME_V2,     ADEDLEN_INIT},
+    {ADEID_COMMENT,     ADEDOFF_COMMENT_V2,  ADEDLEN_INIT},
+    {ADEID_FILEDATESI,  ADEDOFF_FILEDATESI,  ADEDLEN_FILEDATESI},
+    {ADEID_FINDERI,     ADEDOFF_FINDERI_V2,  ADEDLEN_FINDERI},
+    {ADEID_DID,         ADEDOFF_DID,         ADEDLEN_DID},
+    {ADEID_AFPFILEI,    ADEDOFF_AFPFILEI,    ADEDLEN_AFPFILEI},
+    {ADEID_SHORTNAME,   ADEDOFF_SHORTNAME,   ADEDLEN_INIT},
+    {ADEID_PRODOSFILEI, ADEDOFF_PRODOSFILEI, ADEDLEN_PRODOSFILEI},
+    {ADEID_PRIVDEV,     ADEDOFF_PRIVDEV,     ADEDLEN_INIT},
+    {ADEID_PRIVINO,     ADEDOFF_PRIVINO,     ADEDLEN_INIT},
+    {ADEID_PRIVSYN,     ADEDOFF_PRIVSYN,     ADEDLEN_INIT},
+    {ADEID_PRIVID,      ADEDOFF_PRIVID,      ADEDLEN_INIT},
+    {ADEID_RFORK,       ADEDOFF_RFORK_V2,    ADEDLEN_INIT},
     {0, 0, 0}
 };
 
-#if AD_VERSION == AD_VERSION1
-#define DISK_EID(ad, a) (a)
+/* Using Extended Attributes */
+static const struct entry entry_order_ea[ADEID_NUM_EA + 1] = {
+    {ADEID_FINDERI,    ADEDOFF_FINDERI_EA,    ADEDLEN_FINDERI},
+    {ADEID_COMMENT,    ADEDOFF_COMMENT_EA,    ADEDLEN_INIT},
+    {ADEID_FILEDATESI, ADEDOFF_FILEDATESI_EA, ADEDLEN_FILEDATESI},
+    {ADEID_AFPFILEI,   ADEDOFF_AFPFILEI_EA,   ADEDLEN_AFPFILEI},
+    {0, 0, 0}
+};
 
-#else /* AD_VERSION == AD_VERSION2 */
+#define ADFLAGS2LOGSTRBUFSIZ 128
+const char *adflags2logstr(int adflags)
+{
+    int first = 1;
+    static char buf[ADFLAGS2LOGSTRBUFSIZ];
+
+    buf[0] = 0;
+
+    if (adflags & ADFLAGS_DF) {
+        strlcat(buf, "DF", ADFLAGS2LOGSTRBUFSIZ);
+        first = 0;
+    }
+    if (adflags & ADFLAGS_RF) {
+        if (!first)
+            strlcat(buf, "|", ADFLAGS2LOGSTRBUFSIZ);
+        strlcat(buf, "RF", ADFLAGS2LOGSTRBUFSIZ);
+        first = 0;
+    }
+    if (adflags & ADFLAGS_HF) {
+        if (!first)
+            strlcat(buf, "|", ADFLAGS2LOGSTRBUFSIZ);
+        strlcat(buf, "HF", ADFLAGS2LOGSTRBUFSIZ);
+        first = 0;
+    }
+    if (adflags & ADFLAGS_NOHF) {
+        if (!first)
+            strlcat(buf, "|", ADFLAGS2LOGSTRBUFSIZ);
+        strlcat(buf, "NOHF", ADFLAGS2LOGSTRBUFSIZ);
+        first = 0;
+    }
+    if (adflags & ADFLAGS_DIR) {
+        if (!first)
+            strlcat(buf, "|", ADFLAGS2LOGSTRBUFSIZ);
+        strlcat(buf, "DIR", ADFLAGS2LOGSTRBUFSIZ);
+        first = 0;
+    }
+    if (adflags & ADFLAGS_CHECK_OF) {
+        if (!first)
+            strlcat(buf, "|", ADFLAGS2LOGSTRBUFSIZ);
+        strlcat(buf, "OF", ADFLAGS2LOGSTRBUFSIZ);
+        first = 0;
+    }
+    if (adflags & ADFLAGS_RDWR) {
+        if (!first)
+            strlcat(buf, "|", ADFLAGS2LOGSTRBUFSIZ);
+        strlcat(buf, "O_RDWR", ADFLAGS2LOGSTRBUFSIZ);
+        first = 0;
+    }
+    if (adflags & ADFLAGS_RDONLY) {
+        if (!first)
+            strlcat(buf, "|", ADFLAGS2LOGSTRBUFSIZ);
+        strlcat(buf, "O_RDONLY", ADFLAGS2LOGSTRBUFSIZ);
+        first = 0;
+    }
+    if (adflags & ADFLAGS_CREATE) {
+        if (!first)
+            strlcat(buf, "|", ADFLAGS2LOGSTRBUFSIZ);
+        strlcat(buf, "O_CREAT", ADFLAGS2LOGSTRBUFSIZ);
+        first = 0;
+    }
+    if (adflags & ADFLAGS_EXCL) {
+        if (!first)
+            strlcat(buf, "|", ADFLAGS2LOGSTRBUFSIZ);
+        strlcat(buf, "O_EXCL", ADFLAGS2LOGSTRBUFSIZ);
+        first = 0;
+    }
+    if (adflags & ADFLAGS_TRUNC) {
+        if (!first)
+            strlcat(buf, "|", ADFLAGS2LOGSTRBUFSIZ);
+        strlcat(buf, "O_TRUNC", ADFLAGS2LOGSTRBUFSIZ);
+        first = 0;
+    }
+
+    return buf;
+}
 
-static u_int32_t get_eid(struct adouble *ad, u_int32_t eid)
+static uint32_t get_eid(uint32_t eid)
 {
     if (eid <= 15)
         return eid;
-    if (ad->ad_version == AD_VERSION1)
-        return 0;
     if (eid == AD_DEV)
         return ADEID_PRIVDEV;
     if (eid == AD_INO)
@@ -165,343 +245,78 @@ static u_int32_t get_eid(struct adouble *ad, u_int32_t eid)
     return 0;
 }
 
-#define DISK_EID(ad, a) get_eid(ad, a)
-
-static const struct entry entry_order2[ADEID_NUM_V2 +1] = {
-    {ADEID_NAME, ADEDOFF_NAME_V2, ADEDLEN_INIT},
-    {ADEID_COMMENT, ADEDOFF_COMMENT_V2, ADEDLEN_INIT},
-    {ADEID_FILEDATESI, ADEDOFF_FILEDATESI, ADEDLEN_FILEDATESI},
-    {ADEID_FINDERI, ADEDOFF_FINDERI_V2, ADEDLEN_FINDERI},
-    {ADEID_DID, ADEDOFF_DID, ADEDLEN_DID},
-    {ADEID_AFPFILEI, ADEDOFF_AFPFILEI, ADEDLEN_AFPFILEI},
-    {ADEID_SHORTNAME, ADEDOFF_SHORTNAME, ADEDLEN_INIT},
-    {ADEID_PRODOSFILEI, ADEDOFF_PRODOSFILEI, ADEDLEN_PRODOSFILEI},
-    {ADEID_PRIVDEV,     ADEDOFF_PRIVDEV, ADEDLEN_INIT},
-    {ADEID_PRIVINO,     ADEDOFF_PRIVINO, ADEDLEN_INIT},
-    {ADEID_PRIVSYN,     ADEDOFF_PRIVSYN, ADEDLEN_INIT},
-    {ADEID_PRIVID,     ADEDOFF_PRIVID, ADEDLEN_INIT},
-    {ADEID_RFORK, ADEDOFF_RFORK_V2, ADEDLEN_INIT},
-
-    {0, 0, 0}
-};
-
-/* OS X adouble finder info and resource fork only
- */
-static const struct entry entry_order_osx[ADEID_NUM_OSX +1] = {
-    {ADEID_FINDERI, ADEDOFF_FINDERI_OSX, ADEDLEN_FINDERI},
-    {ADEID_RFORK, ADEDOFF_RFORK_OSX, ADEDLEN_INIT},
-
-    {0, 0, 0}
-};
-
-#define ADEID_NUM_SFM 3
-static const struct entry entry_order_sfm[ADEID_NUM_SFM +1] = {
-    {ADEID_FINDERI,     16,         ADEDLEN_FINDERI},   /* 9 */
-    {ADEID_SFMRESERVE2, 16+32,      6},                 /* 21 */
-    {ADEID_FILEI,       60,         ADEDLEN_FILEI},     /* 7 */
-
-    {0, 0, 0}
-};
-
-#endif /* AD_VERSION == AD_VERSION2 */
-
-#if AD_VERSION == AD_VERSION2
-
-/* update a version 2 adouble resource fork with our private entries */
-static int ad_update(struct adouble *ad, const char *path)
+/* ----------------------------------- */
+static int new_ad_header(const char *path, struct adouble *ad, int adflags)
 {
-    struct stat st;
-    u_int16_t nentries = 0;
-    off_t     off, shiftdata=0;
     const struct entry  *eid;
-    static off_t entry_len[ADEID_MAX];
-    static char  databuf[ADEID_MAX][256], *buf;
-    int fd;
-    int ret = -1;
-
-    /* check to see if we should convert this header. */
-    if (!path || ad->ad_flags != AD_VERSION2)
-        return 0;
-
-    LOG(log_maxdebug, logtype_default, "ad_update: checking whether '%s' needs an upgrade.", path);
-
-    if (!(ad->ad_md->adf_flags & O_RDWR)) {
-        /* we were unable to open the file read write the last time */
-        return 0;
-    }
-
-    if (ad->ad_eid[ADEID_RFORK].ade_off) {
-        shiftdata = ADEDOFF_RFORK_V2 -ad->ad_eid[ADEID_RFORK].ade_off;
-    }
-
-    memcpy(&nentries, ad->ad_data + ADEDOFF_NENTRIES, sizeof( nentries ));
-    nentries = ntohs( nentries );
-
-    if ( shiftdata == 0 && nentries == ADEID_NUM_V2)
-        return 0;
-
-    memset(entry_len, 0, sizeof(entry_len));
-    memset(databuf, 0, sizeof(databuf));
-
-    /* bail if we can't get a lock */
-    if (ad_tmplock(ad, ADEID_RFORK, ADLOCK_WR, 0, 0, 0) < 0)
-        goto bail_err;
-
-    fd = ad->ad_md->adf_fd;
-
-    if (fstat(fd, &st)) {
-        goto bail_lock;
-    }
-
-    if (st.st_size > 0x7fffffff) {
-        LOG(log_debug, logtype_default, "ad_update: file '%s' too big for update.", path);
-        errno = EIO;
-        goto bail_lock;
-    }
-
-    off = ad->ad_eid[ADEID_RFORK].ade_off;
-    if (off > st.st_size) {
-        LOG(log_error, logtype_default, "ad_update: invalid resource fork offset. (off: %u)", off);
-        errno = EIO;
-        goto bail_lock;
-    }
-
-    if (ad->ad_eid[ADEID_RFORK].ade_len > st.st_size - off) {
-        LOG(log_error, logtype_default, "ad_update: invalid resource fork length. (rfork len: %u)", ad->ad_eid[ADEID_RFORK].ade_len);
-        errno = EIO;
-        goto bail_lock;
-    }
-
-    if ((void *) (buf = (char *)
-                  mmap(NULL, st.st_size + shiftdata,
-                       PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) ==
-        MAP_FAILED) {
-        goto bail_lock;
-    }
-
-    /* last place for failure. */
-    if (sys_ftruncate(fd, st.st_size + shiftdata) < 0) {
-        munmap(buf, st.st_size + shiftdata);
-        goto bail_lock;
-    }
+    uint16_t            ashort;
+    struct stat         st;
 
-    /* move the RFORK. this assumes that the RFORK is at the end */
-    if (off) {
-        memmove(buf + ADEDOFF_RFORK_V2, buf + off, ad->ad_eid[ADEID_RFORK].ade_len);
+    ad->ad_magic = AD_MAGIC;
+    ad->ad_version = ad->ad_flags & 0x0f0000;
+    if (!ad->ad_version) {
+        ad->ad_version = AD_VERSION;
     }
 
-    munmap(buf, st.st_size + shiftdata);
 
-    /* now, fix up our copy of the header */
-    memset(ad->ad_filler, 0, sizeof(ad->ad_filler));
+    memset(ad->ad_data, 0, sizeof(ad->ad_data));
 
-    /* save the header entries */
-    eid = entry_order2;
-    while (eid->id) {
-        if( ad->ad_eid[eid->id].ade_off != 0) {
-            if ( eid->id > 2 && ad->ad_eid[eid->id].ade_len < 256)
-                memcpy( databuf[eid->id], ad->ad_data +ad->ad_eid[eid->id].ade_off, ad->ad_eid[eid->id].ade_len);
-            entry_len[eid->id] = ad->ad_eid[eid->id].ade_len;
-        }
-        eid++;
+    if (ad->ad_flags == AD_VERSION2)
+        eid = entry_order2;
+    else if (ad->ad_flags == AD_VERSION_EA)
+        eid = entry_order_ea;
+    else {
+        return -1;
     }
 
-    memset(ad->ad_data + AD_HEADER_LEN, 0, AD_DATASZ - AD_HEADER_LEN);
-
-    /* copy the saved entries to the new header */
-    eid = entry_order2;
     while (eid->id) {
-        if ( eid->id > 2 && entry_len[eid->id] > 0) {
-            memcpy(ad->ad_data+eid->offset, databuf[eid->id], entry_len[eid->id]);
-        }
         ad->ad_eid[eid->id].ade_off = eid->offset;
-        ad->ad_eid[eid->id].ade_len = entry_len[eid->id];
+        ad->ad_eid[eid->id].ade_len = eid->len;
         eid++;
     }
 
-    /* rebuild the header and cleanup */
-    LOG(log_debug, logtype_default, "updated AD2 header %s", path);
-    ad_flush(ad );
-    ret = 0;
-
-bail_lock:
-    ad_tmplock(ad, ADEID_RFORK, ADLOCK_CLR, 0, 0, 0);
-bail_err:
-    return ret;
-}
-
-/* ------------------------------------------
-   FIXME work only if < 2GB
-*/
-static int ad_convert(struct adouble *ad, const char *path)
-{
-    struct stat st;
-    u_int16_t attr;
-    char *buf;
-    int fd, off;
-    int ret = -1;
-    /* use resource fork offset from file */
-    int shiftdata;
-    int toV2;
-    int toV1;
-
-    if (!path) {
-        return 0;
-    }
-
-    if (!(ad->ad_md->adf_flags & ( O_RDWR))) {
-        /* we were unable to open the file read write the last time */
-        return 0;
-    }
-
-    /* check to see if we should convert this header. */
-    toV2 = ad->ad_version == AD_VERSION1 && ad->ad_flags == AD_VERSION2;
-    toV1 = ad->ad_version == AD_VERSION2 && ad->ad_flags == AD_VERSION1;
-
-    if (!toV2 && !toV1)
-        return 0;
-
-    /* convert from v1 to v2. what does this mean?
-     *  1) change FILEI into FILEDATESI
-     *  2) create space for SHORTNAME, AFPFILEI, DID, and PRODOSI
-     *  3) move FILEI attributes into AFPFILEI
-     *  4) initialize ACCESS field of FILEDATESI.
-     *  5) move the resource fork
-     */
-
-    /* bail if we can't get a lock */
-    if (ad_tmplock(ad, ADEID_RFORK, ADLOCK_WR, 0, 0, 0) < 0)
-        goto bail_err;
-
-    /* we reuse fd from the resource fork */
-    fd = ad->ad_md->adf_fd;
-
-    if (ad->ad_eid[ADEID_RFORK].ade_off) {
-        shiftdata = ADEDOFF_RFORK_V2 -ad->ad_eid[ADEID_RFORK].ade_off;
-    }
-    else {
-        shiftdata = ADEDOFF_RFORK_V2 -ADEDOFF_RFORK_V1; /* 136 */
-    }
-
-    if (fstat(fd, &st)) {
-        goto bail_lock;
-    }
-
-    if (st.st_size > 0x7fffffff -shiftdata) {
-        LOG(log_debug, logtype_default, "ad_v1tov2: file too big.");
-        errno = EIO;
-        goto bail_lock;
-    }
-
-    off = ad->ad_eid[ADEID_RFORK].ade_off;
-
-    if (off > st.st_size) {
-        LOG(log_error, logtype_default, "ad_v1tov2: invalid resource fork offset. (off: %u)", off);
-        errno = EIO;
-        goto bail_lock;
-    }
-
-    if (ad->ad_eid[ADEID_RFORK].ade_len > st.st_size - off) {
-        LOG(log_error, logtype_default, "ad_v1tov2: invalid resource fork length. (rfork len: %u)", ad->ad_eid[ADEID_RFORK].ade_len);
-        errno = EIO;
-        goto bail_lock;
-    }
-
-    if ((void *) (buf = (char *)
-                  mmap(NULL, st.st_size + shiftdata,
-                       PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) ==
-        MAP_FAILED) {
-        goto bail_lock;
-    }
-
-    /* last place for failure. */
-
-    if (sys_ftruncate(fd, st.st_size + shiftdata) < 0) {
-        goto bail_lock;
+    /* put something sane in the directory finderinfo */
+    if ((adflags & ADFLAGS_DIR)) {
+        /* set default view */
+        ashort = htons(FINDERINFO_CLOSEDVIEW);
+        memcpy(ad_entry(ad, ADEID_FINDERI) + FINDERINFO_FRVIEWOFF, &ashort, sizeof(ashort));
+    } else {
+        /* set default creator/type fields */
+        memcpy(ad_entry(ad, ADEID_FINDERI) + FINDERINFO_FRTYPEOFF,"\0\0\0\0", 4);
+        memcpy(ad_entry(ad, ADEID_FINDERI) + FINDERINFO_FRCREATOFF,"\0\0\0\0", 4);
     }
 
-    /* move the RFORK. this assumes that the RFORK is at the end */
-    if (off) {
-        memmove(buf + ADEDOFF_RFORK_V2, buf + off, ad->ad_eid[ADEID_RFORK].ade_len);
+    /* make things invisible */
+    if ((ad->ad_options & ADVOL_INVDOTS) && (*path == '.')) {
+        ashort = htons(ATTRBIT_INVISIBLE);
+        ad_setattr(ad, ashort);
+        ashort = htons(FINDERINFO_INVISIBLE);
+        memcpy(ad_entry(ad, ADEID_FINDERI) + FINDERINFO_FRFLAGOFF, &ashort, sizeof(ashort));
     }
 
-    munmap(buf, st.st_size + shiftdata);
-
-    /* now, fix up our copy of the header */
-    memset(ad->ad_filler, 0, sizeof(ad->ad_filler));
-
-    /* replace FILEI with FILEDATESI */
-    ad_getattr(ad, &attr);
-    ad->ad_eid[ADEID_FILEDATESI].ade_off = ADEDOFF_FILEDATESI;
-    ad->ad_eid[ADEID_FILEDATESI].ade_len = ADEDLEN_FILEDATESI;
-    ad->ad_eid[ADEID_FILEI].ade_off = 0;
-    ad->ad_eid[ADEID_FILEI].ade_len = 0;
-
-    /* add in the new entries */
-    ad->ad_eid[ADEID_DID].ade_off = ADEDOFF_DID;
-    ad->ad_eid[ADEID_DID].ade_len = ADEDLEN_DID;
-    ad->ad_eid[ADEID_AFPFILEI].ade_off = ADEDOFF_AFPFILEI;
-    ad->ad_eid[ADEID_AFPFILEI].ade_len = ADEDLEN_AFPFILEI;
-    ad->ad_eid[ADEID_SHORTNAME].ade_off = ADEDOFF_SHORTNAME;
-    ad->ad_eid[ADEID_SHORTNAME].ade_len = ADEDLEN_INIT;
-    ad->ad_eid[ADEID_PRODOSFILEI].ade_off = ADEDOFF_PRODOSFILEI;
-    ad->ad_eid[ADEID_PRODOSFILEI].ade_len = ADEDLEN_PRODOSFILEI;
-
-    ad->ad_eid[ADEID_PRIVDEV].ade_off = ADEDOFF_PRIVDEV;
-    ad->ad_eid[ADEID_PRIVDEV].ade_len = ADEDLEN_INIT;
-    ad->ad_eid[ADEID_PRIVINO].ade_off = ADEDOFF_PRIVINO;
-    ad->ad_eid[ADEID_PRIVINO].ade_len = ADEDLEN_INIT;
-    ad->ad_eid[ADEID_PRIVSYN].ade_off = ADEDOFF_PRIVSYN;
-    ad->ad_eid[ADEID_PRIVSYN].ade_len = ADEDLEN_INIT;
-    ad->ad_eid[ADEID_PRIVID].ade_off  = ADEDOFF_PRIVID;
-    ad->ad_eid[ADEID_PRIVID].ade_len =  ADEDLEN_INIT;
-
-    /* shift the old entries (NAME, COMMENT, FINDERI, RFORK) */
-    ad->ad_eid[ADEID_NAME].ade_off = ADEDOFF_NAME_V2;
-    ad->ad_eid[ADEID_COMMENT].ade_off = ADEDOFF_COMMENT_V2;
-    ad->ad_eid[ADEID_FINDERI].ade_off = ADEDOFF_FINDERI_V2;
-    ad->ad_eid[ADEID_RFORK].ade_off = ADEDOFF_RFORK_V2;
-
-    /* switch to dest version */
-    ad->ad_version = (toV2)?AD_VERSION2:AD_VERSION1;
-
-    /* move our data buffer to make space for the new entries. */
-    memmove(ad->ad_data + ADEDOFF_NAME_V2, ad->ad_data + ADEDOFF_NAME_V1,
-            ADEDOFF_RFORK_V1 - ADEDOFF_NAME_V1);
+    if (lstat(path, &st) < 0)
+        return -1;
 
-    /* now, fill in the space with appropriate stuff. we're
-       operating as a v2 file now. */
+    /* put something sane in the date fields */
+    ad_setdate(ad, AD_DATE_CREATE | AD_DATE_UNIX, st.st_mtime);
+    ad_setdate(ad, AD_DATE_MODIFY | AD_DATE_UNIX, st.st_mtime);
     ad_setdate(ad, AD_DATE_ACCESS | AD_DATE_UNIX, st.st_mtime);
-    memset(ad_entry(ad, ADEID_DID), 0, ADEDLEN_DID);
-    memset(ad_entry(ad, ADEID_AFPFILEI), 0, ADEDLEN_AFPFILEI);
-    ad_setattr(ad, attr);
-    memset(ad_entry(ad, ADEID_SHORTNAME), 0, ADEDLEN_SHORTNAME);
-    memset(ad_entry(ad, ADEID_PRODOSFILEI), 0, ADEDLEN_PRODOSFILEI);
-
-    /* rebuild the header and cleanup */
-    ad_flush(ad );
-    ret = 0;
-
-bail_lock:
-    ad_tmplock(ad, ADEID_RFORK, ADLOCK_CLR, 0, 0, 0);
-bail_err:
-    return ret;
+    ad_setdate(ad, AD_DATE_BACKUP, AD_DATE_START);
+    return 0;
 }
-#endif /* AD_VERSION == AD_VERSION2 */
 
 /* -------------------------------------
    read in the entries
 */
-static void parse_entries(struct adouble *ad, char *buf,
-                          u_int16_t nentries)
+static void parse_entries(struct adouble *ad, char *buf, uint16_t nentries)
 {
-    u_int32_t   eid, len, off;
-    int         warning = 0;
+    uint32_t   eid, len, off;
+    int        warning = 0;
 
     /* now, read in the entry bits */
     for (; nentries > 0; nentries-- ) {
         memcpy(&eid, buf, sizeof( eid ));
-        eid = DISK_EID(ad, ntohl( eid ));
+        eid = get_eid(ntohl(eid));
         buf += sizeof( eid );
         memcpy(&off, buf, sizeof( off ));
         off = ntohl( off );
@@ -511,18 +326,16 @@ static void parse_entries(struct adouble *ad, char *buf,
         buf += sizeof( len );
 
         if (eid && eid < ADEID_MAX && off < sizeof(ad->ad_data) &&
-            (off +len <= sizeof(ad->ad_data) || eid == ADEID_RFORK)) {
+            (off + len <= sizeof(ad->ad_data) || eid == ADEID_RFORK)) {
             ad->ad_eid[ eid ].ade_off = off;
             ad->ad_eid[ eid ].ade_len = len;
         } else if (!warning) {
             warning = 1;
-            LOG(log_debug, logtype_default, "ad_refresh: nentries %hd  eid %d",
-                nentries, eid );
+            LOG(log_warning, logtype_default, "parse_entries: bogus eid: %d", eid);
         }
     }
 }
 
-
 /* this reads enough of the header so that we can figure out all of
  * the entry lengths and offsets. once that's done, we just read/mmap
  * the rest of the header in.
@@ -533,14 +346,13 @@ static void parse_entries(struct adouble *ad, char *buf,
 static int ad_header_read(struct adouble *ad, struct stat *hst)
 {
     char                *buf = ad->ad_data;
-    u_int16_t           nentries;
+    uint16_t            nentries;
     int                 len;
     ssize_t             header_len;
-    static int          warning = 0;
     struct stat         st;
 
     /* read the header */
-    if ((header_len = adf_pread( ad->ad_md, buf, sizeof(ad->ad_data), 0)) < 0) {
+    if ((header_len = adf_pread( ad->ad_mdp, buf, sizeof(ad->ad_data), 0)) < 0) {
         return -1;
     }
     if (header_len < AD_HEADER_LEN) {
@@ -550,42 +362,15 @@ static int ad_header_read(struct adouble *ad, struct stat *hst)
 
     memcpy(&ad->ad_magic, buf, sizeof( ad->ad_magic ));
     memcpy(&ad->ad_version, buf + ADEDOFF_VERSION, sizeof( ad->ad_version ));
+    ad->ad_magic = ntohl( ad->ad_magic );
+    ad->ad_version = ntohl( ad->ad_version );
 
-    /* tag broken v1 headers. just assume they're all right.
-     * we detect two cases: null magic/version
-     *                      byte swapped magic/version
-     * XXX: in the future, you'll need the v1compat flag.
-     * (ad->ad_flags & ADFLAGS_V1COMPAT) */
-    if (!ad->ad_magic && !ad->ad_version) {
-        if (!warning) {
-            LOG(log_debug, logtype_default, "notice: fixing up null v1 magic/version.");
-            warning++;
-        }
-        ad->ad_magic = AD_MAGIC;
-        ad->ad_version = AD_VERSION1;
-
-    } else if (ad->ad_magic == AD_MAGIC && ad->ad_version == AD_VERSION1) {
-        if (!warning) {
-            LOG(log_debug, logtype_default, "notice: fixing up byte-swapped v1 magic/version.");
-            warning++;
-        }
-
-    } else {
-        ad->ad_magic = ntohl( ad->ad_magic );
-        ad->ad_version = ntohl( ad->ad_version );
-    }
-
-    if ((ad->ad_magic != AD_MAGIC) || ((ad->ad_version != AD_VERSION1)
-#if AD_VERSION == AD_VERSION2
-                                       && (ad->ad_version != AD_VERSION2)
-#endif /* AD_VERSION == AD_VERSION2 */
-            )) {
-        LOG(log_debug, logtype_default, "ad_open: can't parse AppleDouble header.");
+    if ((ad->ad_magic != AD_MAGIC) || (ad->ad_version != AD_VERSION2)) {
+        LOG(log_error, logtype_default, "ad_open: can't parse AppleDouble header.");
         errno = EIO;
         return -1;
     }
 
-    memcpy(ad->ad_filler, buf + ADEDOFF_FILLER, sizeof( ad->ad_filler ));
     memcpy(&nentries, buf + ADEDOFF_NENTRIES, sizeof( nentries ));
     nentries = ntohs( nentries );
 
@@ -598,7 +383,7 @@ static int ad_header_read(struct adouble *ad, struct stat *hst)
 
     buf += AD_HEADER_LEN;
     if (len > header_len - AD_HEADER_LEN) {
-        LOG(log_debug, logtype_default, "ad_header_read: can't read entry info.");
+        LOG(log_error, logtype_default, "ad_header_read: can't read entry info.");
         errno = EIO;
         return -1;
     }
@@ -610,337 +395,606 @@ static int ad_header_read(struct adouble *ad, struct stat *hst)
     if (!ad_getentryoff(ad, ADEID_RFORK)
         || (ad_getentryoff(ad, ADEID_RFORK) > sizeof(ad->ad_data))
         ) {
-        LOG(log_debug, logtype_default, "ad_header_read: problem with rfork entry offset.");
+        LOG(log_error, logtype_default, "ad_header_read: problem with rfork entry offset.");
         errno = EIO;
         return -1;
     }
 
     if (ad_getentryoff(ad, ADEID_RFORK) > header_len) {
-        LOG(log_debug, logtype_default, "ad_header_read: can't read in entries.");
+        LOG(log_error, logtype_default, "ad_header_read: can't read in entries.");
         errno = EIO;
         return -1;
     }
 
     if (hst == NULL) {
         hst = &st;
-        if (fstat(ad->ad_md->adf_fd, &st) < 0) {
+        if (fstat(ad->ad_mdp->adf_fd, &st) < 0) {
             return 1; /* fail silently */
         }
     }
-    ad->ad_rlen = hst->st_size - ad_getentryoff(ad, ADEID_RFORK);
 
-    /* fix up broken dates */
-    if (ad->ad_version == AD_VERSION1) {
-        u_int32_t aint;
-
-        /* check to see if the ad date is wrong. just see if we have
-         * a modification date in the future. */
-        if (((ad_getdate(ad, AD_DATE_MODIFY | AD_DATE_UNIX, &aint)) == 0) &&
-            (aint > TIMEWARP_DELTA + hst->st_mtime)) {
-            ad_setdate(ad, AD_DATE_MODIFY | AD_DATE_UNIX, aint - AD_DATE_DELTA);
-            ad_getdate(ad, AD_DATE_CREATE | AD_DATE_UNIX, &aint);
-            ad_setdate(ad, AD_DATE_CREATE | AD_DATE_UNIX, aint - AD_DATE_DELTA);
-            ad_getdate(ad, AD_DATE_BACKUP | AD_DATE_UNIX, &aint);
-            ad_setdate(ad, AD_DATE_BACKUP | AD_DATE_UNIX, aint - AD_DATE_DELTA);
-        }
-    }
+    ad->ad_rlen = hst->st_size - ad_getentryoff(ad, ADEID_RFORK);
 
     return 0;
 }
 
-/* ---------------------------
-   SFM structure
-*/
-#if 0
-typedef struct {
-    byte    afpi_Signature[4];      /* Must be 0x00504641 */
-    byte    afpi_Version[4];        /* Must be 0x00010000 */
-    byte    afpi_Reserved1[4];
-    byte    afpi_BackupTime[4];     /* Backup time for the file/dir */
-    byte    finderinfo[32];         /* Finder info */
-    byte    afpi_ProDosInfo[6];     /* ProDos Info */
-    byte    afpi_Reserved2[6];
-} sfm_info;
-#endif
-
-static int ad_header_sfm_read(struct adouble *ad, struct stat *hst)
+static int ad_header_read_ea(struct adouble *ad, struct stat *hst _U_)
 {
-    char                *buf = ad->ad_data;
-    const struct entry  *eid;
-    ssize_t             header_len;
-    struct stat         st;
+    uint16_t nentries;
+    int      len;
+    ssize_t  header_len;
+    char     *buf = ad->ad_data;
 
     /* read the header */
-    if ((header_len = adf_pread( ad->ad_md, buf, sizeof(ad->ad_data), 0)) < 0) {
+    if ((header_len = sys_fgetxattr(ad_data_fileno(ad), AD_EA_META, ad->ad_data, AD_DATASZ_EA)) < 1) {
+        LOG(log_debug, logtype_default, "ad_header_read_ea: %s (%u)", strerror(errno), errno);
         return -1;
     }
-    if (header_len != AD_SFM_LEN) {
+
+    if (header_len < AD_HEADER_LEN) {
+        LOG(log_error, logtype_default, "ad_header_read_ea: bogus AppleDouble header.");
         errno = EIO;
         return -1;
     }
 
     memcpy(&ad->ad_magic, buf, sizeof( ad->ad_magic ));
-    memcpy(&ad->ad_version, buf + 4, sizeof( ad->ad_version ));
-
-    /* FIXME in the great Microsoft tradition they aren't in network order */
-#if 0
-    if (ad->ad_magic == SFM_MAGIC && ad->ad_version == AD_VERSION1) {
-        static int          warning = 0;
-        if (!warning) {
-            LOG(log_debug, logtype_default, "notice: fixing up byte-swapped v1 magic/version.");
-            warning++;
-        }
+    memcpy(&ad->ad_version, buf + ADEDOFF_VERSION, sizeof( ad->ad_version ));
 
-    } else {
-        ad->ad_magic = ntohl( ad->ad_magic );
-        ad->ad_version = ntohl( ad->ad_version );
-    }
-#endif
-    if ((ad->ad_magic != SFM_MAGIC) || ((ad->ad_version != AD_VERSION1) )) {
+    ad->ad_magic = ntohl( ad->ad_magic );
+    ad->ad_version = ntohl( ad->ad_version );
+
+    if ((ad->ad_magic != AD_MAGIC) || (ad->ad_version != AD_VERSION2)) {
+        LOG(log_error, logtype_default, "ad_header_read_ea: wrong magic or version");
         errno = EIO;
-        LOG(log_debug, logtype_default, "ad_header_sfm_read: can't parse AppleDouble header.");
         return -1;
     }
 
-    /* reinit adouble table */
-    eid = entry_order_sfm;
-    while (eid->id) {
-        ad->ad_eid[eid->id].ade_off = eid->offset;
-        ad->ad_eid[eid->id].ade_len = eid->len;
-        eid++;
-    }
-
-    /* steal some prodos for attribute */
-    {
-
-        u_int16_t attribute;
-        memcpy(&attribute, buf + 48 +4, sizeof(attribute));
-        ad_setattr(ad, attribute );
-    }
+    memcpy(&nentries, buf + ADEDOFF_NENTRIES, sizeof( nentries ));
+    nentries = ntohs( nentries );
 
-    if (ad->ad_resource_fork.adf_fd != -1) {
-        /* we have a resource fork use it rather than the metadata */
-        if (fstat(ad->ad_resource_fork.adf_fd, &st) < 0) {
-            /* XXX set to zero ?
-               ad->ad_rlen =  0;
-            */
-            return 1;
-        }
-        ad->ad_rlen = st.st_size;
-        hst = &st;
-    }
-    else if (hst == NULL) {
-        hst = &st;
-        if (fstat(ad->ad_md->adf_fd, &st) < 0) {
-            return 1; /* fail silently */
-        }
+    /* Protect against bogus nentries */
+    len = nentries * AD_ENTRY_LEN;
+    if (len + AD_HEADER_LEN > sizeof(ad->ad_data))
+        len = sizeof(ad->ad_data) - AD_HEADER_LEN;
+    if (len > header_len - AD_HEADER_LEN) {
+        LOG(log_error, logtype_default, "ad_header_read_ea: can't read entry info.");
+        errno = EIO;
+        return -1;
     }
+    nentries = len / AD_ENTRY_LEN;
 
-    /* fix up broken dates */
-    if (ad->ad_version == AD_VERSION1) {
-        u_int32_t aint;
+    /* Now parse entries */
+    parse_entries(ad, buf + AD_HEADER_LEN, nentries);
+    return 0;
+}
 
-        /* check to see if the ad date is wrong. just see if we have
-         * a modification date in the future. */
-        if (((ad_getdate(ad, AD_DATE_MODIFY | AD_DATE_UNIX, &aint)) == 0) &&
-            (aint > TIMEWARP_DELTA + hst->st_mtime)) {
-            ad_setdate(ad, AD_DATE_MODIFY | AD_DATE_UNIX, aint - AD_DATE_DELTA);
-            ad_getdate(ad, AD_DATE_CREATE | AD_DATE_UNIX, &aint);
-            ad_setdate(ad, AD_DATE_CREATE | AD_DATE_UNIX, aint - AD_DATE_DELTA);
-            ad_getdate(ad, AD_DATE_BACKUP | AD_DATE_UNIX, &aint);
-            ad_setdate(ad, AD_DATE_BACKUP | AD_DATE_UNIX, aint - AD_DATE_DELTA);
-        }
+static int ad_mkrf(const char *path)
+{
+    char *slash;
+    /*
+     * Probably .AppleDouble doesn't exist, try to mkdir it.
+     */
+    if (NULL == ( slash = strrchr( path, '/' )) ) {
+        return -1;
     }
-
+    *slash = '\0';
+    errno = 0;
+    if ( ad_mkdir( path, 0777 ) < 0 ) {
+        return -1;
+    }
+    *slash = '/';
     return 0;
 }
 
-/* ---------------------------------------
- * Put the .AppleDouble where it needs to be:
- *
- *      /   a/.AppleDouble/b
- *  a/b
- *      \   b/.AppleDouble/.Parent
- *
- * FIXME: should do something for pathname > MAXPATHLEN
- */
-char *
-ad_path( const char *path, int adflags)
+static int ad_mkrf_ea(const char *path _U_)
 {
-    static char pathbuf[ MAXPATHLEN + 1];
-    const char *slash;
-    size_t  l ;
+    AFP_PANIC("ad_mkrf_ea: dont use");
+    return 0;
+}
 
-    if ( adflags & ADFLAGS_DIR ) {
-        l = strlcpy( pathbuf, path, sizeof(pathbuf));
+/* ----------------
+   if we are root change path user/ group
+   It can be a native function for BSD cf. FAQ.Q10
+   path:  pathname to chown
+   stbuf: parent directory inode
 
-        if ( l && l < MAXPATHLEN) {
-            pathbuf[l++] = '/';
-        }
-        strlcpy(pathbuf +l, ".AppleDouble/.Parent", sizeof(pathbuf) -l);
-    } else {
-        if (NULL != ( slash = strrchr( path, '/' )) ) {
-            slash++;
-            l = slash - path;
-            /* XXX we must return NULL here and test in the caller */
-            if (l > MAXPATHLEN)
-                l = MAXPATHLEN;
-            memcpy( pathbuf, path, l);
-        } else {
-            l = 0;
-            slash = path;
-        }
-        l += strlcpy( pathbuf +l, ".AppleDouble/", sizeof(pathbuf) -l);
-        strlcpy( pathbuf + l, slash, sizeof(pathbuf) -l);
-    }
+   use fstat and fchown or lchown with linux?
+*/
+#define EMULATE_SUIDDIR
 
-    return( pathbuf );
+static int ad_chown(const char *path, struct stat *stbuf)
+{
+    int ret = 0;
+#ifdef EMULATE_SUIDDIR
+    uid_t id;
+
+    if (default_uid != (uid_t)-1) {
+        /* we are root (admin) */
+        id = (default_uid)?default_uid:stbuf->st_uid;
+        ret = lchown( path, id, stbuf->st_gid );
+    }
+#endif
+    return ret;
 }
 
-/* -------------------- */
-static int ad_mkrf(char *path)
+#define DEFMASK 07700   /* be conservative */
+
+/* ----------------
+   return access right and inode of path parent directory
+*/
+static int ad_mode_st(const char *path, int *mode, struct stat *stbuf)
 {
-    char *slash;
-    /*
-     * Probably .AppleDouble doesn't exist, try to mkdir it.
-     */
-    if (NULL == ( slash = strrchr( path, '/' )) ) {
+    if (*mode == 0) {
         return -1;
     }
-    *slash = '\0';
-    errno = 0;
-    if ( ad_mkdir( path, 0777 ) < 0 ) {
+    if (ad_stat(path, stbuf) != 0) {
+        *mode &= DEFMASK;
         return -1;
     }
-    *slash = '/';
+    *mode &= stbuf->st_mode;
+    return 0;
+}
+
+/* --------------------------- */
+static int ad_header_upgrade(struct adouble *ad _U_, const char *name _U_)
+{
+    return 0;
+}
+
+static int ad_header_upgrade_ea(struct adouble *ad _U_, const char *name _U_)
+{
+    AFP_PANIC("ad_header_upgrade_ea: dont use");
     return 0;
 }
 
-/* ---------------------------------------
- * Put the resource fork where it needs to be:
- * ._name
+/*!
+ * Error handling for adouble header(=metadata) file open error
+ *
+ * We're called because opening ADFLAGS_HF caused an error.
+ * 1. In case ad_open is called with ADFLAGS_NOHF the error is suppressed.
+ * 2. If ad_open was called with ADFLAGS_DF we may have opened the datafork and thus
+ *    ought to close it before returning with an error condition.
  */
-char *
-ad_path_osx(const char *path, int adflags _U_)
+static int ad_error(struct adouble *ad, int adflags)
 {
-    static char pathbuf[ MAXPATHLEN + 1];
-    char    c, *slash, buf[MAXPATHLEN + 1];
+    int err = errno;
+    if ((adflags & ADFLAGS_NOHF)) { /* 1 */
+        /* FIXME double check : set header offset ?*/
+        return 0;
+    }
+    if ((adflags & ADFLAGS_DF)) { /* 2 */
+        ad_close( ad, ADFLAGS_DF );
+        err = errno;
+    }
+    return -1 ;
+}
 
-    if (!strcmp(path,".")) {
-        /* fixme */
-        getcwd(buf, MAXPATHLEN);
+/* Map ADFLAGS to open() flags */
+static int ad2openflags(int adflags)
+{
+    int oflags = 0;
+
+    if (adflags & ADFLAGS_RDWR)
+        oflags |= O_RDWR;
+    if ((adflags & ADFLAGS_RDONLY) && (adflags & ADFLAGS_SETSHRMD))
+        oflags |= O_RDWR;
+    else
+        oflags |= O_RDONLY;
+    if (adflags & ADFLAGS_CREATE)
+        oflags |= O_CREAT;
+    if (adflags & ADFLAGS_EXCL)
+        oflags |= O_EXCL;
+    if (adflags & ADFLAGS_TRUNC)
+        oflags |= O_TRUNC;
+
+    return oflags;
+}
+
+static int ad_open_df(const char *path, int adflags, mode_t mode, struct adouble *ad)
+{
+    struct stat st_dir;
+    int         oflags;
+    mode_t      admode;
+    int         st_invalid = -1;
+    ssize_t     lsz;
+
+    LOG(log_debug, logtype_default, "ad_open_df(\"%s\", %04o)",
+        fullpathname(path), mode);
+
+    if (ad_data_fileno(ad) != -1) {
+        /* the file is already open, but we want write access: */
+        if ((adflags & ADFLAGS_RDWR)
+            /* and it was denied the first time: */
+            && (ad->ad_data_fork.adf_flags & O_RDONLY)) {
+                errno = EACCES;
+                return -1;
+            }
+        /* it's not new anymore */
+        ad->ad_mdp->adf_flags &= ~( O_TRUNC | O_CREAT );
+        ad->ad_data_fork.adf_refcount++;
+        return 0;
     }
-    else {
-        strlcpy(buf, path, MAXPATHLEN +1);
+
+    oflags = O_NOFOLLOW | ad2openflags(adflags);
+
+    admode = mode;
+    if ((adflags & ADFLAGS_CREATE)) {
+        st_invalid = ad_mode_st(path, &admode, &st_dir);
+        if ((ad->ad_options & ADVOL_UNIXPRIV))
+            admode = mode;
     }
-    if (NULL != ( slash = strrchr( buf, '/' )) ) {
-        c = *++slash;
-        *slash = '\0';
-        strlcpy( pathbuf, buf, MAXPATHLEN +1);
-        *slash = c;
+
+    ad->ad_data_fork.adf_fd = open(path, oflags, admode);
+
+    if (ad->ad_data_fork.adf_fd == -1) {
+        switch (errno) {
+        case EACCES:
+        case EPERM:
+        case EROFS:
+            if ((adflags & ADFLAGS_SETSHRMD) && (adflags & ADFLAGS_RDONLY)) {
+                oflags &= ~O_RDWR;
+                oflags |= O_RDONLY;
+                if ((ad->ad_data_fork.adf_fd = open(path, oflags, admode)) == -1)
+                    return -1;
+                break;
+            }
+            return -1;
+        case OPEN_NOFOLLOW_ERRNO:
+            ad->ad_data_fork.adf_syml = malloc(MAXPATHLEN+1);
+            if ((lsz = readlink(path, ad->ad_data_fork.adf_syml, MAXPATHLEN)) <= 0) {
+                free(ad->ad_data_fork.adf_syml);
+                return -1;
+            }
+            ad->ad_data_fork.adf_syml[lsz] = 0;
+            ad->ad_data_fork.adf_fd = -2; /* -2 means its a symlink */
+            break;
+        default:
+            return -1;
+        }
+    }
+
+    if (!st_invalid)
+        ad_chown(path, &st_dir); /* just created, set owner if admin (root) */
+
+    ad->ad_data_fork.adf_flags = oflags;
+    adf_lock_init(&ad->ad_data_fork);
+    ad->ad_data_fork.adf_refcount++;
+
+    return 0;
+}
+
+static int ad_open_hf_v2(const char *path, int adflags, mode_t mode, struct adouble *ad)
+{
+    struct stat st_dir;
+    struct stat st_meta;
+    struct stat *pst = NULL;
+    const char  *ad_p;
+    int         oflags, nocreatflags;
+    mode_t      admode;
+    int         st_invalid = -1;
+
+    if (ad_meta_fileno(ad) != -1) {
+        /* the file is already open, but we want write access: */
+        if ((adflags & ADFLAGS_RDWR) &&
+            /* and it was already denied: */
+            (ad->ad_mdp->adf_flags & O_RDONLY)) {
+            errno = EACCES;
+            return -1;
+        }
+        ad_refresh(ad);
+        /* it's not new anymore */
+        ad->ad_mdp->adf_flags &= ~( O_TRUNC | O_CREAT );
+        ad->ad_mdp->adf_refcount++;
+        return 0;
+    }
+
+    ad_p = ad->ad_ops->ad_path(path, adflags);
+    oflags = O_NOFOLLOW | ad2openflags(adflags);
+    nocreatflags = oflags & ~(O_CREAT | O_EXCL);
+
+    ad->ad_mdp->adf_fd = open(ad_p, nocreatflags);
+
+    if (ad->ad_mdp->adf_fd != -1) {
+        ad->ad_mdp->adf_flags = nocreatflags;
+    } else {
+        switch (errno) {
+        case EACCES:
+        case EPERM:
+        case EROFS:
+            if ((adflags & ADFLAGS_RDONLY) && (adflags & ADFLAGS_SETSHRMD)) {
+                nocreatflags &= ~O_RDWR;
+                nocreatflags |= O_RDONLY;
+                if ((ad->ad_mdp->adf_fd = open(ad_p, nocreatflags)) == -1)
+                    return -1;
+                ad->ad_mdp->adf_flags = nocreatflags;
+                break;
+            }
+            return -1;
+        case ENOENT:
+            if (!(oflags & O_CREAT))
+                return ad_error(ad, adflags);
+            /*
+             * We're expecting to create a new adouble header file here
+             * if ((oflags & O_CREAT) ==> (oflags & O_RDWR)
+             */
+            LOG(log_debug, logtype_default, "ad_open(\"%s\"): creating adouble file",
+                fullpathname(path));
+            admode = mode;
+            errno = 0;
+            st_invalid = ad_mode_st(ad_p, &admode, &st_dir);
+            if ((ad->ad_options & ADVOL_UNIXPRIV))
+                admode = mode;
+            admode = ad_hf_mode(admode);
+            if (errno == ENOENT) {
+                if (ad->ad_ops->ad_mkrf( ad_p) < 0) {
+                    return ad_error(ad, adflags);
+                }
+                admode = mode;
+                st_invalid = ad_mode_st(ad_p, &admode, &st_dir);
+                if ((ad->ad_options & ADVOL_UNIXPRIV))
+                    admode = mode;
+                admode = ad_hf_mode(admode);
+            }
+
+            /* retry with O_CREAT */
+            ad->ad_mdp->adf_fd = open(ad_p, oflags, admode);
+            if ( ad->ad_mdp->adf_fd < 0 )
+                return ad_error(ad, adflags);
+
+            ad->ad_mdp->adf_flags = oflags;
+            /* just created, set owner if admin owner (root) */
+            if (!st_invalid)
+                ad_chown(ad_p, &st_dir);
+            break;
+        default:
+            return -1;
+        }
+    }
+
+    if (!(ad->ad_mdp->adf_flags & O_CREAT)) {
+        /* check for 0 length files, treat them as new. */
+        if (fstat(ad->ad_mdp->adf_fd, &st_meta) == 0) {
+            if (st_meta.st_size == 0)
+                ad->ad_mdp->adf_flags |= O_TRUNC;
+            else
+                /* we have valid data in st_meta stat structure, reused it in ad_header_read */
+                pst = &st_meta;
+        }
+    }
+
+    ad->ad_mdp->adf_refcount = 1;
+    adf_lock_init(ad->ad_mdp);
+
+    if ((ad->ad_mdp->adf_flags & ( O_TRUNC | O_CREAT ))) {
+        /* This is a new adouble header file, create it */
+        if (new_ad_header(path, ad, adflags) < 0) {
+            int err = errno;
+            /* the file is already deleted, perm, whatever, so return an error */
+            ad_close(ad, adflags);
+            errno = err;
+            return -1;
+        }
+        ad_flush(ad);
     } else {
-        pathbuf[ 0 ] = '\0';
-        slash = buf;
+        /* Read the adouble header in and parse it.*/
+        if (ad->ad_ops->ad_header_read( ad , pst) < 0
+            || ad->ad_ops->ad_header_upgrade(ad, ad_p) < 0) {
+            int err = errno;
+            ad_close(ad, adflags);
+            errno = err;
+            return -1;
+        }
     }
-    strlcat( pathbuf, "._", MAXPATHLEN  +1);
-    strlcat( pathbuf, slash, MAXPATHLEN +1);
-    return pathbuf;
+
+    return 0;
 }
-/* -------------------- */
-static int ad_mkrf_osx(char *path _U_)
+
+static int ad_open_hf_ea(const char *path, int adflags, int mode, struct adouble *ad)
 {
+    ssize_t rforklen;
+    int oflags = O_NOFOLLOW;
+
+    LOG(log_error, logtype_default, "ad_open_hf_ea(\"%s\", %04o)", path, mode);
+
+    oflags |= ad2openflags(adflags) & ~(O_CREAT | O_TRUNC);
+
+    if (ad_data_fileno(ad) != -1) {
+        /* the file is already open, but we want write access: */
+        if ((adflags & ADFLAGS_RDWR) &&
+            /* and it was already denied: */
+            (ad->ad_data_fork.adf_flags & O_RDONLY)) {
+            LOG(log_error, logtype_default, "ad_open_hf_ea(%s): rw request for ro file: %s",
+                fullpathname(path), strerror(errno));
+            errno = EACCES;
+            return -1;
+        }
+
+        /* it's not new anymore */
+        ad->ad_mdp->adf_flags &= ~( O_TRUNC | O_CREAT );
+    } else {
+        if ((ad_data_fileno(ad) = open(path, oflags)) == -1)
+            goto error;
+        ad->ad_data_fork.adf_flags = oflags;
+        adf_lock_init(&ad->ad_data_fork);
+    }
+
+    /* Read the adouble header in and parse it.*/
+    if (ad->ad_ops->ad_header_read(ad, NULL) != 0) {
+        LOG(log_error, logtype_default, "ad_open_hf_ea(\"%s\", %04o): ad_header_read: %s", path, mode, strerror(errno));
+
+        if (!(adflags & ADFLAGS_CREATE))
+            goto error;
+        LOG(log_error, logtype_default, "ad_open_hf_ea(\"%s\", %04o): create metadata EA", path, mode);
+
+        /* It doesnt exist, EPERM or another error */
+        if (!(errno == ENOATTR || errno == ENOENT)) {
+            LOG(log_error, logtype_default, "ad_open_hf_ea: unexpected: %s", strerror(errno));
+            goto error;
+        }
+
+        /* Create one */
+        if (new_ad_header(path, ad, adflags) < 0) {
+            LOG(log_error, logtype_default, "ad_open_hf_ea: can't create new header: %s",
+                fullpathname(path));
+            goto error;
+        }
+        ad->ad_mdp->adf_flags |= O_CREAT; /* mark as just created */
+        ad_flush(ad);
+        LOG(log_debug, logtype_default, "ad_open_hf_ea(\"%s\"): created metadata EA", path);
+    }
+
+    ad->ad_data_fork.adf_refcount++;
+
+    if ((rforklen = sys_fgetxattr(ad_data_fileno(ad), AD_EA_RESO, NULL, 0)) > 0)
+        ad->ad_rlen = rforklen;
+
     return 0;
+
+error:
+    if (ad_data_fileno(ad) != -1) {
+        close(ad_data_fileno(ad));
+        ad_data_fileno(ad) = -1;
+    }
+    return ad_error(ad, adflags);
 }
 
-/* ---------------------------------------
+static int ad_open_hf(const char *path, int adflags, int mode, struct adouble *ad)
+{
+    int ret = 0;
+
+    LOG(log_debug, logtype_default, "ad_open_hf(\"%s\", %04o)", path, mode);
+
+    memset(ad->ad_eid, 0, sizeof( ad->ad_eid ));
+    ad->ad_rlen = 0;
+
+    switch (ad->ad_flags) {
+    case AD_VERSION2:
+        ret = ad_open_hf_v2(path, adflags, mode, ad);
+        break;
+    case AD_VERSION_EA:
+        ret = ad_open_hf_ea(path, adflags, mode, ad);
+        break;
+    default:
+        ret = -1;
+        break;
+    }
+
+    return ret;
+}
+
+/*!
+ * Open ressource fork
+ *
+ * Only for adouble:ea, a nullop otherwise because adouble:v2 has the ressource fork as part
+ * of the adouble file which is openend by ADFLAGS_HF.
+ */
+static int ad_open_rf(const char *path, int adflags, int mode, struct adouble *ad)
+{
+    int ret = 0;
+
+    if (ad->ad_flags != AD_VERSION_EA)
+        return 0;
+
+    LOG(log_debug, logtype_default, "ad_open_rf(\"%s\", %04o)",
+        path, mode);
+
+    if ((ad->ad_rlen = sys_fgetxattr(ad_data_fileno(ad), AD_EA_RESO, NULL, 0)) <= 0) {
+        switch (errno) {
+        case ENOATTR:
+            ad->ad_rlen = 0;
+            break;
+        default:
+            LOG(log_warning, logtype_default, "ad_open_rf(\"%s\"): %s",
+                fullpathname(path), strerror(errno));
+            ret = -1;
+            goto exit;
+        }
+    }
+
+    /* Round up and allocate buffer */
+    size_t roundup = ((ad->ad_rlen / RFORK_EA_ALLOCSIZE) + 1) * RFORK_EA_ALLOCSIZE;
+    if ((ad->ad_resforkbuf = malloc(roundup)) == NULL) {
+        ret = -1;
+        goto exit;
+    }
+
+    ad->ad_resforkbufsize = roundup;
+
+    /* Read the EA into the buffer */
+    if (ad->ad_rlen > 0) {
+        if (sys_fgetxattr(ad_data_fileno(ad), AD_EA_RESO, ad->ad_resforkbuf, ad->ad_rlen) == -1) {
+            ret = -1;
+            goto exit;
+        }       
+    }
+
+exit:
+    if (ret != 0) {
+        free(ad->ad_resforkbuf);
+        ad->ad_resforkbuf = NULL;
+        ad->ad_rlen = 0;
+        ad->ad_resforkbufsize = 0;
+    }
+
+    return ret;
+}
+
+/***********************************************************************************
+ * API functions
+ ********************************************************************************* */
+
+const char *ad_path_ea( const char *path, int adflags _U_)
+{
+    return path;
+}
+
+/*
  * Put the .AppleDouble where it needs to be:
  *
- *      /   a/.AppleDouble/b/AFP_AfpInfo
+ *      /   a/.AppleDouble/b
  *  a/b
- *      \   b/.AppleDouble/.Parent/AFP_AfpInfo
+ *      \   b/.AppleDouble/.Parent
  *
+ * FIXME: should do something for pathname > MAXPATHLEN
  */
-char *
-ad_path_sfm( const char *path, int adflags)
+const char *ad_path( const char *path, int adflags)
 {
     static char pathbuf[ MAXPATHLEN + 1];
-    char    c, *slash, buf[MAXPATHLEN + 1];
-    size_t      l;
+    const char *slash;
+    size_t  ;
 
-    l = strlcpy(buf, path, MAXPATHLEN +1);
     if ( adflags & ADFLAGS_DIR ) {
-        strcpy( pathbuf, buf);
-        if ( *buf != '\0' && l < MAXPATHLEN) {
+        l = strlcpy( pathbuf, path, sizeof(pathbuf));
+
+        if ( l && l < MAXPATHLEN) {
             pathbuf[l++] = '/';
-            pathbuf[l] = 0;
         }
-        slash = ".Parent";
+        strlcpy(pathbuf +l, ".AppleDouble/.Parent", sizeof(pathbuf) -l);
     } else {
-        if (NULL != ( slash = strrchr( buf, '/' )) ) {
-            c = *++slash;
-            *slash = '\0';
-            strcpy( pathbuf, buf);
-            *slash = c;
+        if (NULL != ( slash = strrchr( path, '/' )) ) {
+            slash++;
+            l = slash - path;
+            /* XXX we must return NULL here and test in the caller */
+            if (l > MAXPATHLEN)
+                l = MAXPATHLEN;
+            memcpy( pathbuf, path, l);
         } else {
-            pathbuf[ 0 ] = '\0';
-            slash = buf;
+            l = 0;
+            slash = path;
         }
+        l += strlcpy( pathbuf +l, ".AppleDouble/", sizeof(pathbuf) -l);
+        strlcpy( pathbuf + l, slash, sizeof(pathbuf) -l);
     }
-    strlcat( pathbuf, ".AppleDouble/", MAXPATHLEN +1);
-    strlcat( pathbuf, slash, MAXPATHLEN +1);
 
-    if ((adflags == ADFLAGS_RF)) {
-        strlcat( pathbuf, "/AFP_Resource", MAXPATHLEN +1);
-    }
-    else {
-        strlcat( pathbuf, "/AFP_AfpInfo", MAXPATHLEN +1);
-    }
     return( pathbuf );
 }
 
-/* -------------------- */
-static int ad_mkrf_sfm(char *path)
-{
-    char *slash;
-    /*
-     * Probably .AppleDouble doesn't exist, try to mkdir it.
-     */
-    if (NULL == ( slash = strrchr( path, '/' )) ) {
-        return -1;
-    }
-    *slash = 0;
-    errno = 0;
-    if ( ad_mkdir( path, 0777 ) < 0 ) {
-        if ( errno == ENOENT ) {
-            char *slash1;
-
-            if (NULL == ( slash1 = strrchr( path, '/' )) )
-                return -1;
-            errno = 0;
-            *slash1 = 0;
-            if ( ad_mkdir( path, 0777 ) < 0 )
-                return -1;
-            *slash1 = '/';
-            if ( ad_mkdir( path, 0777 ) < 0 )
-                return -1;
-        }
-        else
-            return -1;
-    }
-    *slash = '/';
-    return 0;
-}
-
 /* -------------------------
  * Support inherited protection modes for AppleDouble files.  The supplied
  * mode is ANDed with the parent directory's mask value in lieu of "umask",
  * and that value is returned.
  */
-
-#define DEFMASK 07700   /* be conservative */
-
-char
-*ad_dir(const char *path)
+char *ad_dir(const char *path)
 {
     static char     modebuf[ MAXPATHLEN + 1];
     char        *slash;
@@ -987,540 +1041,176 @@ use_cur:
     return modebuf;
 }
 
-/* ---------------- */
-static uid_t default_uid = -1;
-
 int ad_setfuid(const uid_t id)
 {
     default_uid = id;
     return 0;
 }
 
-/* ---------------- */
-uid_t ad_getfuid(void)
-{
-    return default_uid;
-}
-
-/* ----------------
-   return inode of path parent directory
-*/
-int ad_stat(const char *path, struct stat *stbuf)
-{
-    char                *p;
-
-    p = ad_dir(path);
-    if (!p) {
-        return -1;
-    }
-//FIXME!
-    return lstat( p, stbuf );
-}
-
-/* ----------------
-   if we are root change path user/ group
-   It can be a native function for BSD cf. FAQ.Q10
-   path:  pathname to chown
-   stbuf: parent directory inode
-
-   use fstat and fchown or lchown with linux?
-*/
-#define EMULATE_SUIDDIR
-
-static int ad_chown(const char *path, struct stat *stbuf)
-{
-    int ret = 0;
-#ifdef EMULATE_SUIDDIR
-    uid_t id;
-
-    if (default_uid != (uid_t)-1) {
-        /* we are root (admin) */
-        id = (default_uid)?default_uid:stbuf->st_uid;
-        ret = lchown( path, id, stbuf->st_gid );
-    }
-#endif
-    return ret;
-}
-
-/* ----------------
-   return access right and inode of path parent directory
-*/
-static int ad_mode_st(const char *path, int *mode, struct stat *stbuf)
-{
-    if (*mode == 0) {
-        return -1;
-    }
-    if (ad_stat(path, stbuf) != 0) {
-        *mode &= DEFMASK;
-        return -1;
-    }
-    *mode &= stbuf->st_mode;
-    return 0;
-}
-
-/* ----------------
-   return access right of path parent directory
-*/
-int
-ad_mode( const char *path, int mode)
-{
-    struct stat     stbuf;
-    ad_mode_st(path, &mode, &stbuf);
-    return mode;
-}
-
-/*
- * Use mkdir() with mode bits taken from ad_mode().
- */
-int
-ad_mkdir( const char *path, int mode)
-{
-    int ret;
-    int st_invalid;
-    struct stat stbuf;
-
-    LOG(log_debug, logtype_default, "ad_mkdir(\"%s\", %04o) {cwd: \"%s\"}",
-        path, mode, getcwdpath());
-
-    st_invalid = ad_mode_st(path, &mode, &stbuf);
-    ret = mkdir( path, mode );
-    if (ret || st_invalid)
-        return ret;
-    ad_chown(path, &stbuf);
-
-    return ret;
-}
-
-/* ----------------- */
-static int ad_error(struct adouble *ad, int adflags)
-{
-    int err = errno;
-    if ((adflags & ADFLAGS_NOHF)) {
-        /* FIXME double check : set header offset ?*/
-        return 0;
-    }
-    if ((adflags & ADFLAGS_DF)) {
-        ad_close( ad, ADFLAGS_DF );
-        err = errno;
-    }
-    return -1 ;
-}
-
-static int new_rfork(const char *path, struct adouble *ad, int adflags);
-
-#ifdef  HAVE_PREAD
-#define AD_SET(a)
-#else
-#define AD_SET(a) a = 0
-#endif
-
-/* --------------------------- */
-static int ad_check_size(struct adouble *ad _U_, struct stat *st)
-{
-    if (st->st_size > 0 && st->st_size < AD_DATASZ1)
-        return 1;
-    return 0;
-}
-
-/* --------------------------- */
-static int ad_check_size_sfm(struct adouble *ad _U_, struct stat *st)
-{
-    if (st->st_size > 0 && st->st_size < AD_SFM_LEN)
-        return 1;
-    return 0;
-}
-
-/* --------------------------- */
-static int ad_header_upgrade(struct adouble *ad, char *name)
-{
-#if AD_VERSION == AD_VERSION2
-    int ret;
-    if ( (ret = ad_convert(ad, name)) < 0 || (ret = ad_update(ad, name) < 0)) {
-        return ret;
-    }
-#endif
-    return 0;
-}
-
-/* --------------------------- */
-static int ad_header_upgrade_none(struct adouble *ad _U_, char *name _U_)
+/* ---------------- */
+uid_t ad_getfuid(void)
 {
-    return 0;
+    return default_uid;
 }
 
-/* --------------------------- */
-static struct adouble_fops ad_osx = {
-    &ad_path_osx,
-    &ad_mkrf_osx,
-    &ad_rebuild_adouble_header,
-    &ad_check_size,
+/* ----------------
+   stat path parent directory
+*/
+int ad_stat(const char *path, struct stat *stbuf)
+{
+    char *p;
 
-    &ad_header_read,
-    &ad_header_upgrade,
-};
+    p = ad_dir(path);
+    if (!p)
+        return -1;
+    return lstat( p, stbuf );
+}
 
-static struct adouble_fops ad_sfm = {
-    &ad_path_sfm,
-    &ad_mkrf_sfm,
-    &ad_rebuild_sfm_header,
-    &ad_check_size_sfm,
+/* ----------------
+   return access right of path parent directory
+*/
+int ad_mode( const char *path, int mode)
+{
+    struct stat     stbuf;
+    ad_mode_st(path, &mode, &stbuf);
+    return mode;
+}
 
-    &ad_header_sfm_read,
-    &ad_header_upgrade_none,
-};
+/*
+ * Use mkdir() with mode bits taken from ad_mode().
+ */
+int ad_mkdir( const char *path, int mode)
+{
+    int ret;
+    int st_invalid;
+    struct stat stbuf;
 
-static struct adouble_fops ad_adouble = {
-    &ad_path,
-    &ad_mkrf,
-    &ad_rebuild_adouble_header,
-    &ad_check_size,
+    LOG(log_debug, logtype_default, "ad_mkdir(\"%s\", %04o) {cwd: \"%s\"}",
+        path, mode, getcwdpath());
 
-    &ad_header_read,
-    &ad_header_upgrade,
-};
+    st_invalid = ad_mode_st(path, &mode, &stbuf);
+    ret = mkdir( path, mode );
+    if (ret || st_invalid)
+        return ret;
+    ad_chown(path, &stbuf);
 
+    return ret;
+}
 
-void ad_init(struct adouble *ad, int flags, int options)
+static void ad_init_func(struct adouble *ad)
 {
-    ad->ad_inited = 0;
-    ad->ad_flags = flags;
-    if (flags == AD_VERSION2_OSX) {
-        ad->ad_ops = &ad_osx;
-        ad->ad_md = &ad->ad_resource_fork;
-    }
-    else if (flags == AD_VERSION1_SFM) {
-        ad->ad_ops = &ad_sfm;
-        ad->ad_md = &ad->ad_metadata_fork;
-    }
-    else {
+    switch (ad->ad_flags) {
+    case AD_VERSION2:
         ad->ad_ops = &ad_adouble;
-        ad->ad_md = &ad->ad_resource_fork;
+        ad->ad_rfp = &ad->ad_resource_fork;
+        ad->ad_mdp = &ad->ad_resource_fork;
+        break;
+    case AD_VERSION_EA:
+        ad->ad_ops = &ad_adouble_ea;
+        ad->ad_rfp = &ad->ad_resource_fork;
+        ad->ad_mdp = &ad->ad_resource_fork;
+        break;
+    default:
+        AFP_PANIC("ad_init: unknown AD version");
     }
-    ad->ad_options = options;
 
     ad_data_fileno(ad) = -1;
     ad_reso_fileno(ad) = -1;
     ad_meta_fileno(ad) = -1;
-    /* following can be read even if there's no
-     * meda data.
-     */
     memset(ad->ad_eid, 0, sizeof( ad->ad_eid ));
     ad->ad_rlen = 0;
+    ad->ad_refcount = 1;
+    ad->ad_open_forks = 0;
+    ad->ad_resource_fork.adf_refcount = 0;
+    ad->ad_resforkbuf = NULL;
+    ad->ad_data_fork.adf_refcount = 0;
+    ad->ad_data_fork.adf_syml = 0;
+    ad->ad_inited = 0;
+    return;
+}
+
+void ad_init_old(struct adouble *ad, int flags, int options)
+{
+    ad->ad_flags = flags;
+    ad->ad_options = options;
+    ad_init_func(ad);
+}
+
+void ad_init(struct adouble *ad, const struct vol * restrict vol)
+{
+    ad->ad_flags = vol->v_adouble;
+    ad->ad_options = vol->v_ad_options;
+    ad->ad_maxeafssize = 3500;  /* FIXME: option from vol */
+    ad_init_func(ad);
 }
 
 /*!
  * Open data-, metadata(header)- or ressource fork
  *
+ * ad_open(struct adouble *ad, const char *path, int adflags, int flags)
+ * ad_open(struct adouble *ad, const char *path, int adflags, int flags, mode_t mode)
+ *
  * You must call ad_init() before ad_open, usually you'll just call it like this: \n
  * @code
  *      struct adoube ad;
  *      ad_init(&ad, vol->v_adouble, vol->v_ad_options);
  * @endcode
  *
- * @param path    Path to file or directory
- *
- * @param adflags ADFLAGS_DF: open data file/fork\n
- *                ADFLAGS_HF: open header (metadata) file\n
- *                ADFLAGS_RF: open ressource fork *** FIXME: not used ?! *** \n
- *                ADFLAGS_CREATE: indicate creation\n
- *                ADFLAGS_NOHF: it's not an error if header file couldn't be created\n
- *                ADFLAGS_DIR: if path is a directory you MUST or ADFLAGS_DIR to adflags\n
- *                ADFLAGS_NOADOUBLE: dont create adouble files if not necessary\n
- *                ADFLAGS_RDONLY: open read only\n
- *                ADFLAGS_OPENFORKS: check for open forks from other processes\n
- *                ADFLAGS_MD: alias for ADFLAGS_HF\n
- *                ADFLAGS_V1COMPAT: obsolete
+ * Open a files data fork, metadata fork or ressource fork.
  *
- * @param oflags  flags passed through to open syscall: \n
- *                O_RDONLY: *** FIXME *** \n
- *                O_RDWR: *** FIXME *** \n
- *                O_CREAT: create fork\n
- *                O_EXCL: fail if exists with O_CREAT
+ * @param ad        (rw) pointer to struct adouble
+ * @param path      (r)  Path to file or directory
+ * @param adflags   (r)  ADFLAGS_DF:        open data fork \n
+ *                       ADFLAGS_RF:        open ressource fork \n
+ *                       ADFLAGS_HF:        open header (metadata) file \n
+ *                       ADFLAGS_NOHF:      it's not an error if header file couldn't be created \n
+ *                       ADFLAGS_DIR:       if path is a directory you MUST or ADFLAGS_DIR to adflags \n
+ * The open mode flags (rw vs ro) have to take into account all the following requirements:
+ * - we remember open fds for files because me must avoid a single close releasing fcntl locks for other
+ *   fds of the same file
+ * - a file may be opened first ro, then rw and theres no way to upgrade this -> fork.c always opens rw
+ *                       ADFLAGS_CHECK_OF:  check for open forks from us and other afpd's
+ * @param mode      (r)  mode used with O_CREATE
  *
- * @param mode    passed to open with O_CREAT
- *
- * @param ad      pointer to struct adouble
- *
- * @returns 0 on success
- *
- * @note It's not possible to open the header file O_RDONLY -- the read
- *       will fail and return an error. this refcounts things now.\n
- *       metadata(ressource)-fork only gets created with O_CREAT.
+ * @returns 0 on success, any other value indicates an error
  */
-int ad_open( const char *path, int adflags, int oflags, int mode, struct adouble  *ad)
+int ad_open(struct adouble *ad, const char *path, int adflags, ...)
 {
-    struct stat         st_dir;
-    struct stat         st_meta;
-    struct stat         *pst = NULL;
-    char        *ad_p;
-    int         hoflags, admode;
-    int                 st_invalid = -1;
-    int                 open_df = 0;
+    EC_INIT;
+    va_list args;
+    mode_t mode = 0;
+
+    LOG(log_debug, logtype_default, "ad_open(\"%s\", %s)",
+        fullpathname(path), adflags2logstr(adflags));
 
     if (ad->ad_inited != AD_INITED) {
-        ad->ad_inited = AD_INITED;
-        ad->ad_refcount = 1;
-        ad->ad_open_forks = 0;
         ad->ad_adflags = adflags;
-        ad->ad_resource_fork.adf_refcount = 0;
-        ad->ad_data_fork.adf_refcount = 0;
-        ad->ad_data_fork.adf_syml=0;
-    }
-    else {
+        ad->ad_inited = AD_INITED;
+    } else {
         ad->ad_open_forks = ((ad->ad_data_fork.adf_refcount > 0) ? ATTRBIT_DOPEN : 0);
-        /* XXX not true if we have a meta data fork ? */
-        if ((ad->ad_resource_fork.adf_refcount > ad->ad_data_fork.adf_refcount))
+        if (ad->ad_resource_fork.adf_refcount > 0)
             ad->ad_open_forks |= ATTRBIT_ROPEN;
     }
 
-    if ((adflags & ADFLAGS_DF)) {
-        if (ad_data_fileno(ad) == -1) {
-            hoflags = (oflags & ~(O_RDONLY | O_WRONLY)) | O_RDWR;
-            admode = mode;
-            if ((oflags & O_CREAT)) {
-                st_invalid = ad_mode_st(path, &admode, &st_dir);
-                if ((ad->ad_options & ADVOL_UNIXPRIV)) {
-                    admode = mode;
-                }
-            }
-                
-            ad->ad_data_fork.adf_fd =open( path, hoflags | O_NOFOLLOW, admode );
-            
-            if (ad->ad_data_fork.adf_fd == -1) {
-                if ((errno == EACCES || errno == EROFS) && !(oflags & O_RDWR)) {
-                    hoflags = oflags;
-                    ad->ad_data_fork.adf_fd = open( path, hoflags | O_NOFOLLOW, admode );
-                }
-                if (ad->ad_data_fork.adf_fd == -1 && errno == OPEN_NOFOLLOW_ERRNO) {
-                    int lsz;
-
-                    ad->ad_data_fork.adf_syml = malloc(MAXPATHLEN+1);
-                    lsz = readlink(path, ad->ad_data_fork.adf_syml, MAXPATHLEN);
-                    if (lsz <= 0) {
-                        free(ad->ad_data_fork.adf_syml);
-                        return -1;
-                    }
-                    ad->ad_data_fork.adf_syml[lsz] = 0;
-                    ad->ad_data_fork.adf_fd = -2; /* -2 means its a symlink */
-                }
-            }
-
-            if ( ad->ad_data_fork.adf_fd == -1 )
-                return -1;
-
-            AD_SET(ad->ad_data_fork.adf_off);
-            ad->ad_data_fork.adf_flags = hoflags;
-            if (!st_invalid) {
-                /* just created, set owner if admin (root) */
-                ad_chown(path, &st_dir);
-            }
-            adf_lock_init(&ad->ad_data_fork);
-        }
-        else {
-            /* the file is already open... but */
-            if ((oflags & ( O_RDWR | O_WRONLY)) &&             /* we want write access */
-                !(ad->ad_data_fork.adf_flags & ( O_RDWR | O_WRONLY))) /* and it was denied the first time */
-            {
-                errno = EACCES;
-                return -1;
-            }
-            /* FIXME
-             * for now ad_open is never called with O_TRUNC or O_EXCL if the file is
-             * already open. Should we check for it? ie
-             * O_EXCL --> error
-             * O_TRUNC --> truncate the fork.
-             * idem for ressource fork.
-             */
-        }
-        open_df = ADFLAGS_DF;
-        ad->ad_data_fork.adf_refcount++;
-    }
-
-    if (!(adflags & ADFLAGS_HF))
-        return 0;
-
-    /* ****************************************** */
-
-    if (ad_meta_fileno(ad) != -1) { /* the file is already open */
-        if ((oflags & ( O_RDWR | O_WRONLY)) &&
-            !(ad->ad_md->adf_flags & ( O_RDWR | O_WRONLY))) {
-            if (open_df) {
-                /* don't call with ADFLAGS_HF because we didn't open ressource fork */
-                ad_close( ad, open_df );
-            }
-            errno = EACCES;
-            return -1;
-        }
-        ad_refresh(ad);
-        /* it's not new anymore */
-        ad->ad_md->adf_flags &= ~( O_TRUNC | O_CREAT );
-        ad->ad_md->adf_refcount++;
-        goto sfm;
-    }
-
-    memset(ad->ad_eid, 0, sizeof( ad->ad_eid ));
-    ad->ad_rlen = 0;
-    ad_p = ad->ad_ops->ad_path( path, adflags );
-
-    hoflags = oflags & ~(O_CREAT | O_EXCL);
-    if (!(adflags & ADFLAGS_RDONLY)) {
-        hoflags = (hoflags & ~(O_RDONLY | O_WRONLY)) | O_RDWR;
-    }
-    ad->ad_md->adf_fd = open( ad_p, hoflags | O_NOFOLLOW, 0 );
-    if (ad->ad_md->adf_fd < 0 ) {
-        if ((errno == EACCES || errno == EROFS) && !(oflags & O_RDWR)) {
-            hoflags = oflags & ~(O_CREAT | O_EXCL);
-            ad->ad_md->adf_fd = open( ad_p, hoflags | O_NOFOLLOW, 0 );
-        }
-    }
-
-    if ( ad->ad_md->adf_fd < 0 ) {
-        if (errno == ENOENT && (oflags & O_CREAT) ) {
-            /*
-             * We're expecting to create a new adouble header file,
-             * here.
-             * if ((oflags & O_CREAT) ==> (oflags & O_RDWR)
-             */
-            LOG(log_debug, logtype_default, "ad_open(\"%s\"): {cwd: \"%s\"} creating adouble file",
-                ad_p, getcwdpath());
-            admode = mode;
-            errno = 0;
-            st_invalid = ad_mode_st(ad_p, &admode, &st_dir);
-            if ((ad->ad_options & ADVOL_UNIXPRIV)) {
-                admode = mode;
-            }
-            admode = ad_hf_mode(admode);
-            if ((errno == ENOENT) && (ad->ad_flags != AD_VERSION2_OSX)) {
-                if (ad->ad_ops->ad_mkrf( ad_p) < 0) {
-                    return ad_error(ad, adflags);
-                }
-                admode = mode;
-                st_invalid = ad_mode_st(ad_p, &admode, &st_dir);
-                if ((ad->ad_options & ADVOL_UNIXPRIV)) {
-                    admode = mode;
-                }
-                admode = ad_hf_mode(admode);
-            }
-            /* retry with O_CREAT */
-            ad->ad_md->adf_fd = open( ad_p, oflags,admode );
-            if ( ad->ad_md->adf_fd < 0 ) {
-                return ad_error(ad, adflags);
-            }
-            ad->ad_md->adf_flags = oflags;
-            /* just created, set owner if admin owner (root) */
-            if (!st_invalid) {
-                ad_chown(ad_p, &st_dir);
-            }
-        }
-        else {
-            return ad_error(ad, adflags);
-        }
-    } else {
-        ad->ad_md->adf_flags = hoflags;
-        if (fstat(ad->ad_md->adf_fd, &st_meta) == 0 && st_meta.st_size == 0) {
-            /* for 0 length files, treat them as new. */
-            ad->ad_md->adf_flags |= O_TRUNC;
-        } 
-        else {
-            /* we have valid data in st_meta stat structure, reused it
-               in ad_header_read
-            */
-            pst = &st_meta;
-        }
-    }
-    AD_SET(ad->ad_md->adf_off);
-
-    ad->ad_md->adf_refcount = 1;
-    adf_lock_init(ad->ad_md);
-    if ((ad->ad_md->adf_flags & ( O_TRUNC | O_CREAT ))) {
-        /*
-         * This is a new adouble header file. Initialize the structure,
-         * instead of reading it.
-         */
-        if (new_rfork(path, ad, adflags) < 0) {
-            int err = errno;
-            /* the file is already deleted, perm, whatever, so return an error*/
-            ad_close(ad, adflags);
-            errno = err;
-            return -1;
-        }
-        ad_flush(ad);
-    } else {
-        /* Read the adouble header in and parse it.*/
-        if (ad->ad_ops->ad_header_read( ad , pst) < 0
-            || ad->ad_ops->ad_header_upgrade(ad, ad_p) < 0)
-        {
-            int err = errno;
-
-            ad_close( ad, adflags );
-            errno = err;
-            return -1;
-        }
-    }
-
-    /* ****************************************** */
-    /* open the resource fork if SFM */
-sfm:
-    if (ad->ad_flags != AD_VERSION1_SFM) {
-        return 0;
-    }
-
-    if ((adflags & ADFLAGS_DIR)) {
-        /* no resource fork for directories / volumes XXX it's false! */
-        return 0;
-    }
-
-    /* untrue yet but ad_close will decremente it*/
-    ad->ad_resource_fork.adf_refcount++;
-
-    if (ad_reso_fileno(ad) != -1) { /* the file is already open */
-        if ((oflags & ( O_RDWR | O_WRONLY)) &&
-            !(ad->ad_resource_fork.adf_flags & ( O_RDWR | O_WRONLY))) {
+    va_start(args, adflags);
+    if (adflags & ADFLAGS_CREATE)
+        mode = va_arg(args, mode_t);
+    va_end(args);
 
-            ad_close( ad, open_df | ADFLAGS_HF);
-            errno = EACCES;
-            return -1;
-        }
-        return 0;
+    if (adflags & ADFLAGS_DF) {
+        EC_ZERO( ad_open_df(path, adflags, mode, ad) );
     }
 
-    ad_p = ad->ad_ops->ad_path( path, ADFLAGS_RF );
-
-    admode = mode;
-    st_invalid = ad_mode_st(ad_p, &admode, &st_dir);
-
-    if ((ad->ad_options & ADVOL_UNIXPRIV)) {
-        admode = mode;
+    if (adflags & ADFLAGS_HF) {
+        EC_ZERO( ad_open_hf(path, adflags, mode, ad) );
     }
 
-    hoflags = (oflags & ~(O_RDONLY | O_WRONLY)) | O_RDWR;
-    ad->ad_resource_fork.adf_fd = open( ad_p, hoflags, admode );
-
-    if (ad->ad_resource_fork.adf_fd < 0 ) {
-        if ((errno == EACCES || errno == EROFS) && !(oflags & O_RDWR)) {
-            hoflags = oflags;
-            ad->ad_resource_fork.adf_fd =open( ad_p, hoflags, admode );
-        }
+    if (adflags & ADFLAGS_RF) {
+        EC_ZERO( ad_open_rf(path, adflags, mode, ad) );
     }
 
-    if ( ad->ad_resource_fork.adf_fd < 0) {
-        int err = errno;
-
-        ad_close( ad, adflags );
-        errno = err;
-        return -1;
-    }
-    adf_lock_init(&ad->ad_resource_fork);
-    AD_SET(ad->ad_resource_fork.adf_off);
-    ad->ad_resource_fork.adf_flags = hoflags;
-    if ((oflags & O_CREAT) && !st_invalid) {
-        /* just created, set owner if admin (root) */
-        ad_chown(ad_p, &st_dir);
-    }
-    else if (!fstat(ad->ad_resource_fork.adf_fd, &st_meta)) {
-        ad->ad_rlen = st_meta.st_size;
-    }
-    return 0 ;
+EC_CLEANUP:
+    return ret;
 }
 
 /*!
@@ -1530,29 +1220,18 @@ sfm:
  *
  * @param name  name of file/dir
  * @param flags ADFLAGS_DIR: name is a directory \n
- *              ADFLAGS_CREATE: force creation of header file, but only as user, not as root\n
- *              ADFLAGS_OPENFORKS: test if name is open by another afpd process
+ *              ADFLAGS_CHECK_OF: test if name is open by us or another afpd process
  *
  * @param adp   pointer to struct adouble
- *
- * @note caller MUST pass ADFLAGS_DIR for directories. Whether ADFLAGS_CREATE really creates
- *       a adouble file depends on various other volume options, eg. ADVOL_CACHE
  */
 int ad_metadata(const char *name, int flags, struct adouble *adp)
 {
     uid_t uid;
-    int   ret, err, dir;
-    int   create = O_RDONLY;
+    int   ret, err, oflags;
 
-    dir = flags & ADFLAGS_DIR;
+    oflags = (flags & ADFLAGS_DIR) | ADFLAGS_HF | ADFLAGS_RDONLY;
 
-    /* Check if we shall call ad_open with O_CREAT */
-    if ( (adp->ad_options & ADVOL_CACHE)
-         && ! (adp->ad_options & ADVOL_NOADOUBLE)
-         && (flags & ADFLAGS_CREATE) ) {
-        create = O_CREAT | O_RDWR;
-    }
-    if ((ret = ad_open(name, ADFLAGS_HF | dir, create, 0666, adp)) < 0 && errno == EACCES) {
+    if ((ret = ad_open(adp, name, oflags | ADFLAGS_SETSHRMD)) < 0 && errno == EACCES) {
         uid = geteuid();
         if (seteuid(0)) {
             LOG(log_error, logtype_default, "ad_metadata(%s): seteuid failed %s", name, strerror(errno));
@@ -1560,7 +1239,7 @@ int ad_metadata(const char *name, int flags, struct adouble *adp)
             return -1;
         }
         /* we are root open read only */
-        ret = ad_open(name, ADFLAGS_HF|ADFLAGS_RDONLY| dir, O_RDONLY, 0, adp);
+        ret = ad_open(adp, name, oflags);
         err = errno;
         if ( seteuid(uid) < 0) {
             LOG(log_error, logtype_default, "ad_metadata: can't seteuid back");
@@ -1569,7 +1248,7 @@ int ad_metadata(const char *name, int flags, struct adouble *adp)
         errno = err;
     }
 
-    if (!ret && (ADFLAGS_OPENFORKS & flags)) {
+    if ((ret == 0) && (ADFLAGS_CHECK_OF & flags)) {
         /*
           we need to check if the file is open by another process.
           it's slow so we only do it if we have to:
@@ -1616,116 +1295,56 @@ exit:
 
 }
 
-/* ----------------------------------- */
-static int new_rfork(const char *path, struct adouble *ad, int adflags)
-{
-    const struct entry  *eid;
-    u_int16_t           ashort;
-    struct stat         st;
-
-    ad->ad_magic = AD_MAGIC;
-    ad->ad_version = ad->ad_flags & 0x0f0000;
-    if (!ad->ad_version) {
-        ad->ad_version = AD_VERSION;
-    }
-
-    memset(ad->ad_filler, 0, sizeof( ad->ad_filler ));
-    memset(ad->ad_data, 0, sizeof(ad->ad_data));
-
-#if AD_VERSION == AD_VERSION2
-    if (ad->ad_flags == AD_VERSION2)
-        eid = entry_order2;
-    else if (ad->ad_flags == AD_VERSION2_OSX)
-        eid = entry_order_osx;
-    else  if (ad->ad_flags == AD_VERSION1_SFM) {
-        ad->ad_magic = SFM_MAGIC;
-        eid = entry_order_sfm;
-    }
-    else
-#endif
-        eid = entry_order1;
-
-    while (eid->id) {
-        ad->ad_eid[eid->id].ade_off = eid->offset;
-        ad->ad_eid[eid->id].ade_len = eid->len;
-        eid++;
-    }
-
-    /* put something sane in the directory finderinfo */
-    if ((adflags & ADFLAGS_DIR)) {
-        /* set default view */
-        ashort = htons(FINDERINFO_CLOSEDVIEW);
-        memcpy(ad_entry(ad, ADEID_FINDERI) + FINDERINFO_FRVIEWOFF,
-               &ashort, sizeof(ashort));
-    } else {
-        /* set default creator/type fields */
-        memcpy(ad_entry(ad, ADEID_FINDERI) + FINDERINFO_FRTYPEOFF,"\0\0\0\0", 4);
-        memcpy(ad_entry(ad, ADEID_FINDERI) + FINDERINFO_FRCREATOFF,"\0\0\0\0", 4);
-    }
-
-    /* make things invisible */
-    if ((ad->ad_options & ADVOL_INVDOTS) && !(adflags & ADFLAGS_CREATE) &&
-        (*path == '.') && strcmp(path, ".") && strcmp(path, ".."))
-    {
-        ashort = htons(ATTRBIT_INVISIBLE);
-        ad_setattr(ad, ashort);
-        ashort = htons(FINDERINFO_INVISIBLE);
-        memcpy(ad_entry(ad, ADEID_FINDERI) + FINDERINFO_FRFLAGOFF, &ashort, sizeof(ashort));
-    }
-
-    if (lstat(path, &st) < 0) {
-        return -1;
-    }
-
-    /* put something sane in the date fields */
-    ad_setdate(ad, AD_DATE_CREATE | AD_DATE_UNIX, st.st_mtime);
-    ad_setdate(ad, AD_DATE_MODIFY | AD_DATE_UNIX, st.st_mtime);
-    ad_setdate(ad, AD_DATE_ACCESS | AD_DATE_UNIX, st.st_mtime);
-    ad_setdate(ad, AD_DATE_BACKUP, AD_DATE_START);
-    return 0;
-}
-
-/* to do this with mmap, we need the hfs fs to understand how to mmap
-   header files. */
 int ad_refresh(struct adouble *ad)
 {
 
-    if (ad_meta_fileno(ad) < 0)
+    switch (ad->ad_flags) {
+    case AD_VERSION2:
+        if (ad_meta_fileno(ad) == -1)
+            return -1;
+        return ad->ad_ops->ad_header_read(ad, NULL);
+        break;
+    case AD_VERSION_EA:
+        if (ad_data_fileno(ad) == -1)
+            return -1;
+        return ad->ad_ops->ad_header_read(ad, NULL);
+        break;
+    default:
         return -1;
+        break;
+    }
 
-    return ad->ad_ops->ad_header_read(ad, NULL);
 }
 
-int ad_openat(int dirfd,  /* dir fd openat like */
+int ad_openat(struct adouble  *ad,
+              int dirfd,  /* dir fd openat like */
               const char *path,
-              int adflags,
-              int oflags,
-              int mode,
-              struct adouble  *ad)
+              int adflags, ...)
 {
-    int ret = 0;
+    EC_INIT;
     int cwdfd = -1;
+    va_list args;
+    mode_t mode;
 
     if (dirfd != -1) {
-        if ((cwdfd = open(".", O_RDONLY) == -1) || (fchdir(dirfd) != 0)) {
-            ret = -1;
-            goto exit;
-        }
+        if ((cwdfd = open(".", O_RDONLY) == -1) || (fchdir(dirfd) != 0))
+            EC_FAIL;
     }
 
-    if (ad_open(path, adflags, oflags, mode, ad) < 0) {
-        ret = -1;
-        goto exit;
-    }
+    va_start(args, adflags);
+    if (adflags & ADFLAGS_CREATE)
+        mode = va_arg(args, mode_t);
+    va_end(args);
+
+    EC_NEG1( ad_open(ad, path, adflags, mode) );
 
     if (dirfd != -1) {
         if (fchdir(cwdfd) != 0) {
-            LOG(log_error, logtype_afpd, "ad_openat: cant chdir back, exiting");
-            exit(EXITERR_SYS);
+            AFP_PANIC("ad_openat: cant chdir back");
         }
     }
 
-exit:
+EC_CLEANUP:
     if (cwdfd != -1)
         close(cwdfd);
 
diff --git a/libatalk/adouble/ad_private.h b/libatalk/adouble/ad_private.h
deleted file mode 100644 (file)
index 82a11aa..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * $Id: ad_private.h,v 1.6 2008-12-03 18:35:44 didg Exp $
- */
-
-#ifndef LIBATALK_ADOUBLE_AD_PRIVATE_H
-#define LIBATALK_ADOUBLE_AD_PRIVATE_H 1
-
-#include <atalk/adouble.h>
-
-#ifndef MAP_FAILED
-#define MAP_FAILED ((void *) -1)
-#endif /* ! MAP_FAILED */
-
-/* this is so that we can keep lists of fds referencing the same file
- * around. that way, we can honor locks created by the same process
- * with the same file. */
-
-#define adf_lock_init(a) do { \
-       (a)->adf_lockmax = (a)->adf_lockcount = 0; \
-       (a)->adf_excl = 0;(a)->adf_lock = NULL; \
-} while (0)
-
-#define adf_lock_free(a) do { \
-    int i;\
-       if (!(a)->adf_lock) \
-               break; \
-        for (i = 0; i < (a)->adf_lockcount; i++) {\
-            adf_lock_t *lock = (a)->adf_lock + i;\
-            if (--(*lock->refcount) < 1)free(lock->refcount); \
-        }\
-       free((a)->adf_lock); \
-       adf_lock_init(a); \
-} while (0)
-
-#endif /* libatalk/adouble/ad_private.h */
index 17c2361faa99a775fef26c000bfb1ff82a8b2675..224c72d9fb381fe12470a27117a2aab52117545a 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: ad_read.c,v 1.10 2010-02-10 14:05:37 franklahm Exp $
- *
  * Copyright (c) 1990,1991 Regents of The University of Michigan.
  * All Rights Reserved.
  *
 #include "config.h"
 #endif /* HAVE_CONFIG_H */
 
-#include <atalk/adouble.h>
 #include <string.h>
 #include <sys/param.h>
+#include <errno.h>
+
+#include <atalk/adouble.h>
+#include <atalk/ea.h>
 
 #ifndef MIN
 #define MIN(a,b)    ((a)<(b)?(a):(b))
@@ -59,7 +60,7 @@ ssize_t adf_pread(struct ad_fd *ad_fd, void *buf, size_t count, off_t offset)
 /* XXX: locks have to be checked before each stream of consecutive
  *      ad_reads to prevent a denial in the middle from causing
  *      problems. */
-ssize_t ad_read( struct adouble *ad, const u_int32_t eid, off_t off, char *buf, const size_t buflen)
+ssize_t ad_read( struct adouble *ad, const uint32_t eid, off_t off, char *buf, const size_t buflen)
 {
     ssize_t     cc;
 
@@ -77,31 +78,39 @@ ssize_t ad_read( struct adouble *ad, const u_int32_t eid, off_t off, char *buf,
             cc = adf_pread(&ad->ad_data_fork, buf, buflen, off);
         }
     } else {
-        off_t r_off;
-
-        if ( ad_reso_fileno( ad ) == -1 ) {
-            /* resource fork is not open ( cf etc/afp/fork.c) */
-            return 0;
-        }
-        r_off = ad_getentryoff(ad, eid) + off;
-
-        if (( cc = adf_pread( &ad->ad_resource_fork, buf, buflen, r_off )) < 0 ) {
-            return( -1 );
-        }
-        /*
-         * We've just read in bytes from the disk that we read earlier
-         * into ad_data. If we're going to write this buffer out later,
-         * we need to update ad_data.
-         * FIXME : always false?
-         */
-        if (r_off < ad_getentryoff(ad, ADEID_RFORK)) {
-            if ( ad->ad_resource_fork.adf_flags & O_RDWR ) {
-                memcpy(buf, ad->ad_data + r_off,
-                       MIN(sizeof( ad->ad_data ) - r_off, cc));
-            } else {
-                memcpy(ad->ad_data + r_off, buf,
-                       MIN(sizeof( ad->ad_data ) - r_off, cc));
+        if (ad->ad_flags != AD_VERSION_EA) {
+            off_t r_off;
+            if ( ad_reso_fileno( ad ) == -1 )
+                /* resource fork is not open ( cf etc/afp/fork.c) */
+                return 0;
+            r_off = ad_getentryoff(ad, eid) + off;
+            if (( cc = adf_pread( &ad->ad_resource_fork, buf, buflen, r_off )) < 0 )
+                return( -1 );
+            /*
+             * We've just read in bytes from the disk that we read earlier
+             * into ad_data. If we're going to write this buffer out later,
+             * we need to update ad_data.
+             * FIXME : always false?
+             */
+            if (r_off < ad_getentryoff(ad, ADEID_RFORK)) {
+                if ( ad->ad_resource_fork.adf_flags & O_RDWR ) {
+                    memcpy(buf, ad->ad_data + r_off,
+                           MIN(sizeof( ad->ad_data ) - r_off, cc));
+                } else {
+                    memcpy(ad->ad_data + r_off, buf,
+                           MIN(sizeof( ad->ad_data ) - r_off, cc));
+                }
+            }
+        } else { /* AD_VERSION_EA */
+            if (off > ad->ad_rlen) {
+                errno = ERANGE;
+                return -1;
             }
+            if (ad->ad_rlen == 0)
+                return 0;
+            if ((off + buflen) > ad->ad_rlen)
+                cc = ad->ad_rlen;
+            memcpy(buf, ad->ad_resforkbuf + off, cc);
         }
     }
 
index aabb61ce106eff5f80e69d09ab06149facbfdb51..8c50dcf804cf0f3ea304bc84c55a2d3610cfe579 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: ad_sendfile.c,v 1.11 2010-01-21 14:14:49 didg Exp $
- *
  * Copyright (c) 1999 Adrian Sun (asun@zoology.washington.edu)
  * All rights reserved. See COPYRIGHT.
  *
 #endif /* HAVE_CONFIG_H */
 
 #ifdef WITH_SENDFILE
-
-#include <atalk/adouble.h>
-
 #include <stdio.h>
-
 #include <sys/socket.h>
 #include <sys/uio.h>
-
 #include <errno.h>  
 
+#include <atalk/adouble.h>
 #include <atalk/logger.h>
-#include "ad_private.h"
+
+#include "ad_lock.h"
 
 #if defined(SENDFILE_FLAVOR_LINUX)
 #include <sys/sendfile.h>
index 0b45babdb954f6342721e4ba7093ea598590e6d8..337ff6ed3d5f07075ff286dfa58964488c9158f4 100644 (file)
@@ -15,7 +15,7 @@
 #include <atalk/logger.h>
 #include <atalk/adouble.h>
 
-off_t ad_size(const struct adouble *ad, const u_int32_t eid)
+off_t ad_size(const struct adouble *ad, const uint32_t eid)
 {
   if (eid == ADEID_DFORK) {
     struct stat st;
index 3031f6390ffa6dc485ba49dc10c55feebd849516..dd66796c829a0345e1420d88a206df87b640b9c5 100644 (file)
@@ -7,17 +7,62 @@
 #include "config.h"
 #endif /* HAVE_CONFIG_H */
 
-#include <atalk/adouble.h>
-
+#include <stdlib.h>
 #include <string.h>
 #include <sys/param.h>
 #include <errno.h>
 
+#include <atalk/adouble.h>
+#include <atalk/ea.h>
+#include <atalk/bstrlib.h>
+#include <atalk/bstradd.h>
+#include <atalk/logger.h>
 
 #ifndef MIN
 #define MIN(a,b)       ((a)<(b)?(a):(b))
 #endif /* ! MIN */
 
+static int fsetrsrcea(struct adouble *ad, int fd, const char *eaname, const void *value, size_t size, int flags)
+{
+    if (ad->ad_maxeafssize >= size) {
+        if (sys_fsetxattr(fd, eaname, value, size, 0) == -1)
+            return -1;
+        return 0;
+    }
+
+    /* rsrcfork is larger then maximum EA support by fs so we have to split it */
+    int i;
+    int eas = (size / ad->ad_maxeafssize);
+    size_t remain = size - (eas * ad->ad_maxeafssize);
+    bstring eachunk;
+
+    LOG(log_debug, logtype_default, "fsetrsrcea(\"%s\"): size: %zu, maxea: %zu, eas: %d, remain: %zu",
+        eaname, size, ad->ad_maxeafssize, eas, remain);
+
+    for (i = 0; i < eas; i++) {
+        if ((eachunk = bformat("%s.%d", eaname, i + 1)) == NULL)
+            return -1;
+        if (sys_fsetxattr(fd, bdata(eachunk), value + (i * ad->ad_maxeafssize), ad->ad_maxeafssize, 0) == -1) {
+            LOG(log_error, logtype_default, "fsetrsrcea(\"%s\"): %s", bdata(eachunk), strerror(errno));
+            bdestroy(eachunk);
+            return -1;
+        }
+        bdestroy(eachunk);
+    }
+
+    if ((eachunk = bformat("%s.%d", eaname, i + 1)) == NULL)
+        return -1;
+    if (sys_fsetxattr(fd, bdata(eachunk), value + (i * ad->ad_maxeafssize), remain, 0) == -1) {
+        LOG(log_error, logtype_default, "fsetrsrcea(\"%s\"): %s", bdata(eachunk), strerror(errno));
+        return -1;
+    }
+    bdestroy(eachunk);
+
+    return 0;
+}
+
+
+
 /* XXX: locking has to be checked before each stream of consecutive
  *      ad_writes to prevent a lock in the middle from causing problems. 
  */
@@ -45,10 +90,12 @@ ssize_t adf_pwrite(struct ad_fd *ad_fd, const void *buf, size_t count, off_t off
 }
 
 /* end is always 0 */
-ssize_t ad_write(struct adouble *ad, const u_int32_t eid, off_t off, const int end, const char *buf, const size_t buflen)
+ssize_t ad_write(struct adouble *ad, uint32_t eid, off_t off, int end, const char *buf, size_t buflen)
 {
     struct stat                st;
     ssize_t            cc;
+    size_t roundup;
+    off_t    r_off;
 
     if (ad_data_fileno(ad) == -2) {
         /* It's a symlink */
@@ -57,36 +104,55 @@ ssize_t ad_write(struct adouble *ad, const u_int32_t eid, off_t off, const int e
     }
     
     if ( eid == ADEID_DFORK ) {
-       if ( end ) {
-           if ( fstat( ad_data_fileno(ad), &st ) < 0 ) {
-               return( -1 );
-           }
-           off = st.st_size - off;
-       }
-       cc = adf_pwrite(&ad->ad_data_fork, buf, buflen, off);
-    } else if ( eid == ADEID_RFORK ) {
-        off_t    r_off;
-
-       if ( end ) {
-           if ( fstat( ad_data_fileno(ad), &st ) < 0 ) {
-               return( -1 );
-           }
-           off = st.st_size - off -ad_getentryoff(ad, eid);
-       }
-       r_off = ad_getentryoff(ad, eid) + off;
-       cc = adf_pwrite(&ad->ad_resource_fork, buf, buflen, r_off);
-
-       /* sync up our internal buffer  FIXME always false? */
-       if (r_off < ad_getentryoff(ad, ADEID_RFORK)) {
-           memcpy(ad->ad_data + r_off, buf, MIN(sizeof(ad->ad_data) -r_off, cc));
+        if ( end ) {
+            if ( fstat( ad_data_fileno(ad), &st ) < 0 ) {
+                return( -1 );
+            }
+            off = st.st_size - off;
         }
-        if ( ad->ad_rlen < off + cc ) {
-             ad->ad_rlen = off + cc;
+        cc = adf_pwrite(&ad->ad_data_fork, buf, buflen, off);
+    } else if ( eid == ADEID_RFORK ) {
+        switch (ad->ad_flags) {
+        case AD_VERSION2:
+
+            if ( end ) {
+                if ( fstat( ad_data_fileno(ad), &st ) < 0 )
+                    return( -1 );
+                off = st.st_size - off -ad_getentryoff(ad, eid);
+            }
+            r_off = ad_getentryoff(ad, eid) + off;
+            cc = adf_pwrite(&ad->ad_resource_fork, buf, buflen, r_off);
+
+            /* sync up our internal buffer  FIXME always false? */
+            if (r_off < ad_getentryoff(ad, ADEID_RFORK))
+                memcpy(ad->ad_data + r_off, buf, MIN(sizeof(ad->ad_data) -r_off, cc));
+            if ( ad->ad_rlen < off + cc )
+                ad->ad_rlen = off + cc;
+            break;
+
+        case AD_VERSION_EA:
+            if ((off + buflen) > ad->ad_resforkbufsize) {
+                roundup = (((off + buflen) / RFORK_EA_ALLOCSIZE) + 1) * RFORK_EA_ALLOCSIZE;
+                if ((ad->ad_resforkbuf = realloc(ad->ad_resforkbuf, roundup)) == NULL)
+                    return -1;
+                ad->ad_resforkbufsize = roundup;
+            }
+            memcpy(ad->ad_resforkbuf + off, buf, buflen);
+            if ((off + buflen) > ad->ad_rlen)
+                ad->ad_rlen = off + buflen;
+            
+            if (fsetrsrcea(ad, ad_data_fileno(ad), AD_EA_RESO, ad->ad_resforkbuf, ad->ad_rlen, 0) == -1)
+                return -1;
+            cc = buflen;
+            break;
+
+        default:
+            return -1;
         }
-    }
-    else {
+    } else {
         return -1; /* we don't know how to write if it's not a ressource or data fork */
     }
+
     return( cc );
 }
 
@@ -151,10 +217,10 @@ char            c = 0;
 /* ------------------------ */
 int ad_rtruncate( struct adouble *ad, const off_t size)
 {
-    if ( sys_ftruncate( ad_reso_fileno(ad),
-           size + ad->ad_eid[ ADEID_RFORK ].ade_off ) < 0 ) {
-       return -1;
-    }
+    if (ad->ad_flags != AD_VERSION_EA)
+        if (sys_ftruncate(ad_reso_fileno(ad), size + ad->ad_eid[ ADEID_RFORK ].ade_off ) < 0 )
+            return -1;
+
     ad->ad_rlen = size;    
 
     return 0;
@@ -162,8 +228,8 @@ int ad_rtruncate( struct adouble *ad, const off_t size)
 
 int ad_dtruncate(struct adouble *ad, const off_t size)
 {
-    if (sys_ftruncate(ad_data_fileno(ad), size) < 0) {
-      return -1;
-    }
+    if (sys_ftruncate(ad_data_fileno(ad), size) < 0)
+        return -1;
+
     return 0;
 }
diff --git a/libatalk/asp/.gitignore b/libatalk/asp/.gitignore
deleted file mode 100644 (file)
index 2ff33a9..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-Makefile
-Makefile.in
-*.lo
-*.la
-.deps
-.libs
-.gitignore
-asp_attn.o asp_close.o asp_cmdreply.o asp_getreq.o asp_getsess.o asp_init.o asp_shutdown.o asp_tickle.o asp_write.o
diff --git a/libatalk/asp/Makefile.am b/libatalk/asp/Makefile.am
deleted file mode 100644 (file)
index ae83084..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-# Makefile.am for libatalk/asp/
-
-AM_CFLAGS = -I$(top_srcdir)
-
-noinst_LTLIBRARIES = libasp.la
-
-libasp_la_SOURCES = asp_attn.c asp_close.c asp_cmdreply.c asp_getreq.c asp_getsess.c asp_init.c asp_write.c asp_shutdown.c asp_tickle.c 
-
-noinst_HEADERS = asp_child.h
diff --git a/libatalk/asp/asp_attn.c b/libatalk/asp/asp_attn.c
deleted file mode 100644 (file)
index 1c2a8fa..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * $Id: asp_attn.c,v 1.7 2002-12-04 10:59:37 didg Exp $
- * Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu)
- * All rights reserved. See COPYRIGHT.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <stdio.h>
-#include <string.h>
-#include <atalk/logger.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/uio.h>
-#include <sys/socket.h>
-
-#include <atalk/atp.h>
-#include <atalk/asp.h>
-#include <atalk/afp.h>
-
-/* attentions can get sent at any time. as a consequence, we don't
- * want to touch anything that might be used elsewhere. */
-int asp_attention(ASP asp, AFPUserBytes flags)
-{
-    char cmds[ASP_HDRSIZ], data[ASP_HDRSIZ];
-    struct sockaddr_at  sat;
-    struct atp_block   atpb;
-    struct iovec       iov[ 1 ];
-
-    cmds[0] = ASPFUNC_ATTN;
-    cmds[1] = asp->asp_sid;
-    flags = htons(flags);
-    memcpy(cmds + 2, &flags, sizeof(flags));
-
-    sat = asp->asp_sat;
-    sat.sat_port = asp->asp_wss;
-    atpb.atp_saddr = &sat;
-    atpb.atp_sreqdata = cmds;
-    atpb.atp_sreqdlen = sizeof(cmds);
-    atpb.atp_sreqto = 2;
-    atpb.atp_sreqtries = 5;
-
-    if ( atp_sreq( asp->asp_atp, &atpb, 1, 0 ) < 0 ) {
-       LOG(log_error, logtype_default, "atp_sreq: %s", strerror(errno) );
-       return 0;
-    }
-
-    iov[ 0 ].iov_base = data;
-    iov[ 0 ].iov_len = sizeof( data );
-    atpb.atp_rresiov = iov;
-    atpb.atp_rresiovcnt = sizeof( iov )/sizeof( iov[ 0 ] );
-    if ( atp_rresp( asp->asp_atp, &atpb ) < 0 ) {
-       LOG(log_error, logtype_default, "atp_rresp: %s", strerror(errno) );
-       return 0;
-    }
-
-    return 1;
-}
diff --git a/libatalk/asp/asp_child.h b/libatalk/asp/asp_child.h
deleted file mode 100644 (file)
index 081cd6f..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * $Id: asp_child.h,v 1.2 2001-06-29 14:14:46 rufustfirefly Exp $
- *
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- * All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software and
- * its documentation for any purpose and without fee is hereby granted,
- * provided that the above copyright notice appears in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation, and that the name of The University
- * of Michigan not be used in advertising or publicity pertaining to
- * distribution of the software without specific, written prior
- * permission. This software is supplied as is without expressed or
- * implied warranties of any kind.
- *
- *     Research Systems Unix Group
- *     The University of Michigan
- *     c/o Mike Clark
- *     535 W. William Street
- *     Ann Arbor, Michigan
- *     +1-313-763-0525
- *     netatalk@itd.umich.edu
- */
-
-#ifndef _ASP_CHILD_H
-#define _ASP_CHILD_H 1
-
-struct asp_child {
-    int                        ac_pid;
-    int                        ac_state;
-    struct sockaddr_at ac_sat;
-};
-
-#define ACSTATE_DEAD   0
-#define ACSTATE_OK     1
-#define ACSTATE_BAD    7
-
-#endif /* _ASP_CHILD_H */
diff --git a/libatalk/asp/asp_close.c b/libatalk/asp/asp_close.c
deleted file mode 100644 (file)
index 6187825..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * $Id: asp_close.c,v 1.5 2009-10-13 22:55:37 didg Exp $
- *
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- * All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software and
- * its documentation for any purpose and without fee is hereby granted,
- * provided that the above copyright notice appears in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation, and that the name of The University
- * of Michigan not be used in advertising or publicity pertaining to
- * distribution of the software without specific, written prior
- * permission. This software is supplied as is without expressed or
- * implied warranties of any kind.
- *
- *     Research Systems Unix Group
- *     The University of Michigan
- *     c/o Mike Clark
- *     535 W. William Street
- *     Ann Arbor, Michigan
- *     +1-313-763-0525
- *     netatalk@itd.umich.edu
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/uio.h>
-#include <sys/socket.h>
-
-#include <netatalk/at.h>
-#include <atalk/atp.h>
-#include <atalk/asp.h>
-
-int asp_close(ASP asp)
-{
-    struct atp_block   atpb;
-    struct iovec       iov[ 1 ];
-    int err = 0;
-
-    memset(asp->commands, 0, sizeof(u_int32_t));
-
-    atpb.atp_saddr = &asp->asp_sat;
-    iov[ 0 ].iov_base = asp->commands;
-    iov[ 0 ].iov_len = sizeof(u_int32_t);
-    atpb.atp_sresiov = iov;
-    atpb.atp_sresiovcnt = 1;
-
-    if (atp_sresp( asp->asp_atp, &atpb ) < 0)
-      err = -1;
-
-    if (atp_close( asp->asp_atp ) < 0)
-      err = -1;
-
-    free( asp );
-    return err;
-}
diff --git a/libatalk/asp/asp_cmdreply.c b/libatalk/asp/asp_cmdreply.c
deleted file mode 100644 (file)
index f3a3fd1..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * $Id: asp_cmdreply.c,v 1.5 2009-10-13 22:55:37 didg Exp $
- *
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- * All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software and
- * its documentation for any purpose and without fee is hereby granted,
- * provided that the above copyright notice appears in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation, and that the name of The University
- * of Michigan not be used in advertising or publicity pertaining to
- * distribution of the software without specific, written prior
- * permission. This software is supplied as is without expressed or
- * implied warranties of any kind.
- *
- *     Research Systems Unix Group
- *     The University of Michigan
- *     c/o Mike Clark
- *     535 W. William Street
- *     Ann Arbor, Michigan
- *     +1-313-763-0525
- *     netatalk@itd.umich.edu
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <string.h>
-#include <sys/types.h>
-#include <sys/uio.h>
-#include <sys/socket.h>
-
-#include <atalk/atp.h>
-#include <atalk/asp.h>
-
-#if defined(BSD) || defined(BSD4_3)
-#define memmove(a, b, n)   bcopy((b), (a), (n))
-#endif /* BSD || BSD4_3 */
-
-int asp_cmdreply(ASP asp, int result)
-{
-    struct iovec       iov[ ASP_MAXPACKETS ];
-    struct atp_block   atpb;
-    int                        iovcnt, buflen;
-    char                *buf;
-
-    /* unpack data into a format that atp likes. it needs to get
-     * 4-byte headers prepended before each ASP_CMDSIZ chunk. */
-    buf = (char *) asp->data;
-    buflen = asp->datalen;
-    asp->write_count += buflen;
-    result = htonl(result);
-
-    iovcnt = 0;
-    do {
-       iov[ iovcnt ].iov_base = buf;
-       memmove(buf + ASP_HDRSIZ, buf, buflen);
-
-       if ( iovcnt == 0 ) {
-           memcpy( iov[ iovcnt ].iov_base, &result, ASP_HDRSIZ );
-       } else {
-           memset( iov[ iovcnt ].iov_base, 0, ASP_HDRSIZ );
-       }
-
-       if ( buflen > ASP_CMDSIZ ) {
-         buf += ASP_CMDMAXSIZ;
-         buflen -= ASP_CMDSIZ;
-         iov[ iovcnt ].iov_len = ASP_CMDMAXSIZ;
-       } else {
-         iov[ iovcnt ].iov_len = buflen + ASP_HDRSIZ;
-         buflen = 0;
-       }
-       iovcnt++;
-    } while ( buflen > 0 );
-
-    atpb.atp_saddr = &asp->asp_sat;
-    atpb.atp_sresiov = iov;
-    atpb.atp_sresiovcnt = iovcnt;
-    if ( atp_sresp( asp->asp_atp, &atpb ) < 0 ) {
-       return( -1 );
-    }
-    asp->asp_seq++;
-
-    return( 0 );
-}
diff --git a/libatalk/asp/asp_getreq.c b/libatalk/asp/asp_getreq.c
deleted file mode 100644 (file)
index 211c55d..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * $Id: asp_getreq.c,v 1.3 2001-06-29 14:14:46 rufustfirefly Exp $
- *
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- * All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software and
- * its documentation for any purpose and without fee is hereby granted,
- * provided that the above copyright notice appears in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation, and that the name of The University
- * of Michigan not be used in advertising or publicity pertaining to
- * distribution of the software without specific, written prior
- * permission. This software is supplied as is without expressed or
- * implied warranties of any kind.
- *
- *     Research Systems Unix Group
- *     The University of Michigan
- *     c/o Mike Clark
- *     535 W. William Street
- *     Ann Arbor, Michigan
- *     +1-313-763-0525
- *     netatalk@itd.umich.edu
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <string.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/uio.h>
-#include <netatalk/endian.h>
-#include <netatalk/at.h>
-#include <atalk/atp.h>
-#include <atalk/asp.h>
-
-int asp_getrequest(ASP asp)
-{
-    struct atp_block   atpb;
-    u_int16_t          seq;
-
-    asp->asp_sat.sat_port = ATADDR_ANYPORT;
-    atpb.atp_saddr = &asp->asp_sat;
-    atpb.atp_rreqdata = asp->cmdbuf;
-    atpb.atp_rreqdlen = sizeof(asp->cmdbuf);
-
-    if ( atp_rreq( asp->asp_atp, &atpb ) < 0 ) {
-       return( -1 );
-    }
-
-    asp->cmdlen = atpb.atp_rreqdlen - 4;
-    asp->read_count += asp->cmdlen;
-    memcpy( &seq, asp->cmdbuf + 2, sizeof(seq));
-    seq = ntohs( seq );
-
-    if ((asp->cmdbuf[0] != ASPFUNC_CLOSE) && (seq != asp->asp_seq)) {
-       return( -2 );
-    }
-    if ( asp->cmdbuf[1] != asp->asp_sid ) {
-       return( -3 );
-    }
-
-    return( asp->cmdbuf[0] ); /* the command */
-}
diff --git a/libatalk/asp/asp_getsess.c b/libatalk/asp/asp_getsess.c
deleted file mode 100644 (file)
index 5a1d585..0000000
+++ /dev/null
@@ -1,349 +0,0 @@
-/*
- * $Id: asp_getsess.c,v 1.9 2009-10-13 22:55:37 didg Exp $
- *
- * Copyright (c) 1990,1996 Regents of The University of Michigan.
- * All Rights Reserved.  See COPYRIGHT.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <signal.h>
-
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
-
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/uio.h>
-#include <sys/socket.h>
-#include <sys/param.h>
-#ifdef HAVE_SYS_WAIT_H
-#include <sys/wait.h>
-#endif /* HAVE_SYS_WAIT_H */
-
-#include <netatalk/at.h>
-#include <atalk/logger.h>
-#include <atalk/compat.h>
-#include <atalk/atp.h>
-#include <atalk/asp.h>
-#include <atalk/server_child.h>
-
-#include "asp_child.h"
-
-#ifndef WEXITSTATUS
-#define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
-#endif /* ! WEXITSTATUS */
-#ifndef WIFEXITED
-#define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
-#endif /* ! WIFEXITED */
-
-#ifndef MIN
-#define MIN(a,b)     ((a)<(b)?(a):(b))
-#endif /* ! MIN */
-
-static ASP server_asp;
-static struct server_child *children = NULL;
-static struct asp_child    **asp_ac = NULL;
-
-/* send tickles and check tickle status of connections
- * thoughts on using a hashed list:
- * + child_cleanup, finding slots 
- * - tickle_handler, freeing, tickles 
- * if setup for a large number of connections,
- * + space: if actual connections < potential
- * - space: actual connections ~ potential
- */
-static void tickle_handler(int sig _U_)
-{
-  int sid;
-  
-  /* check status */
-  for (sid = 0; sid < children->nsessions; sid++) {
-    if (asp_ac[sid] == NULL || asp_ac[sid]->ac_state == ACSTATE_DEAD) 
-      continue;
-    
-    if (++asp_ac[sid]->ac_state >= ACSTATE_BAD) {
-      /* kill. if already dead, just continue */
-      if (kill( asp_ac[ sid ]->ac_pid, SIGTERM) == 0)
-       LOG(log_info, logtype_default, "asp_alrm: %d timed out",
-               asp_ac[ sid ]->ac_pid );
-
-      asp_ac[ sid ]->ac_state = ACSTATE_DEAD;
-      continue;
-    }
-
-    /* send off a tickle */
-    asp_tickle(server_asp, sid, &asp_ac[sid]->ac_sat);
-  }
-}
-
-static void child_cleanup(const pid_t pid)
-{
-  int i;
-
-  for (i = 0; i < children->nsessions; i++)
-    if (asp_ac[i] && (asp_ac[i]->ac_pid == pid)) {
-      asp_ac[i]->ac_state = ACSTATE_DEAD;
-      break;
-    }
-}
-
-
-/* kill children */
-void asp_kill(int sig)
-{
-  if (children) 
-    server_child_kill(children, CHILD_ASPFORK, sig);
-}
-
-void asp_stop_tickle(void)
-{
-    if (server_asp && server_asp->inited) {
-       static const struct itimerval timer = {{0, 0}, {0, 0}};
-       
-       setitimer(ITIMER_REAL, &timer, NULL);
-    }
-}
-
-/*
- * This call handles open, tickle, and getstatus requests. On a
- * successful open, it forks a child process. 
- * It returns an ASP to the child and parent and NULL if there is
- * an error.
- */
-static void set_asp_ac(int sid, struct asp_child *tmp);
-
-ASP asp_getsession(ASP asp, server_child *server_children, 
-                  const int tickleval)
-{
-    struct sigaction    action;
-    struct itimerval    timer;
-    struct sockaddr_at  sat;
-    struct atp_block    atpb;
-    ATP                 atp;
-    struct iovec        iov[ 8 ];
-    pid_t               pid;
-    int                 i, iovcnt, sid;
-    u_int16_t           asperr;
-    char                *buf;
-    int                 buflen;
-
-    if (!asp->inited) {
-      if (!(children = server_children))
-       return NULL;
-
-      /* only calloc once */
-      if (!asp_ac && (asp_ac = (struct asp_child **) 
-          calloc(server_children->nsessions, sizeof(struct asp_child *)))
-          == NULL)
-       return NULL;
-
-      server_asp = asp;
-
-      /* install cleanup pointer */
-      server_child_setup(children, CHILD_ASPFORK, child_cleanup);
-
-      /* install tickle handler 
-       * we are the parent process
-       */
-      memset(&action, 0, sizeof(action));
-      action.sa_handler = tickle_handler;
-      sigemptyset(&action.sa_mask);
-      sigaddset(&action.sa_mask, SIGHUP);
-      sigaddset(&action.sa_mask, SIGTERM);
-      sigaddset(&action.sa_mask, SIGCHLD);
-      action.sa_flags = SA_RESTART;
-
-      timer.it_interval.tv_sec = timer.it_value.tv_sec = tickleval;
-      timer.it_interval.tv_usec = timer.it_value.tv_usec = 0;
-      if ((sigaction(SIGALRM, &action, NULL) < 0) ||
-         (setitimer(ITIMER_REAL, &timer, NULL) < 0)) {
-       free(asp_ac);
-       server_asp = NULL;
-       asp_ac = NULL;
-       return NULL;
-      }
-
-      asp->inited = 1;
-    }
-                   
-    memset( &sat, 0, sizeof( struct sockaddr_at ));
-#ifdef BSD4_4
-    sat.sat_len = sizeof( struct sockaddr_at );
-#endif /* BSD4_4 */
-    sat.sat_family = AF_APPLETALK;
-    sat.sat_addr.s_net = ATADDR_ANYNET;
-    sat.sat_addr.s_node = ATADDR_ANYNODE;
-    sat.sat_port = ATADDR_ANYPORT;
-    atpb.atp_saddr = &sat;
-    atpb.atp_rreqdata = asp->cmdbuf;
-    atpb.atp_rreqdlen = sizeof( asp->cmdbuf );
-    while ( atp_rreq( asp->asp_atp, &atpb ) < 0 ) {
-      if ( errno == EINTR || errno == EAGAIN ) {
-       continue;
-      }
-      return( NULL );
-    }
-    
-    switch ( asp->cmdbuf[ 0 ] ) {
-    case ASPFUNC_TICKLE:
-      sid = asp->cmdbuf[1];
-      if ((asp_ac[sid] != NULL) && (asp_ac[sid]->ac_state != ACSTATE_DEAD))
-       asp_ac[sid]->ac_state = ACSTATE_OK;
-      break;
-
-    case ASPFUNC_STAT :
-#ifdef EBUG
-      printf( "asp stat\n" );
-#endif /* EBUG */
-      if ( asp->asp_slen > 0 ) {
-        i = 0;
-        while(atpb.atp_bitmap) {
-            i++;
-            atpb.atp_bitmap >>= 1;
-        }
-
-       /* asp->data is big enough ... */
-        memcpy( asp->data, asp->asp_status, MIN(asp->asp_slen, i*ASP_CMDSIZ));
-       
-        buflen = MIN(asp->asp_slen, i*ASP_CMDSIZ);
-        buf = asp->data;
-        iovcnt = 0;
-
-        /* If status information is too big to fit into the available
-         * ASP packets, we simply send as much as we can.
-         * Older client versions will most likely not be able to use
-         * the additional information anyway, like directory services
-         * or UTF8 server name. A very long fqdn could be a problem,
-         * we could end up with an invalid address list.
-         */
-        do {
-            iov[ iovcnt ].iov_base = buf;
-            memmove(buf + ASP_HDRSIZ, buf, buflen);
-            memset( iov[ iovcnt ].iov_base, 0, ASP_HDRSIZ );
-
-           if ( buflen > ASP_CMDSIZ ) {
-                buf += ASP_CMDMAXSIZ;
-                buflen -= ASP_CMDSIZ;
-                iov[ iovcnt ].iov_len = ASP_CMDMAXSIZ;
-            } else {
-                iov[ iovcnt ].iov_len = buflen + ASP_HDRSIZ;
-                buflen = 0;
-            }
-            iovcnt++;
-        } while ( iovcnt < i && buflen > 0 );
-
-        atpb.atp_sresiovcnt = iovcnt;
-        atpb.atp_sresiov = iov;
-        atp_sresp( asp->asp_atp, &atpb );
-      }
-      break;
-
-    case ASPFUNC_OPEN :
-      if (children->count < children->nsessions) {
-      struct asp_child    *asp_ac_tmp;
-
-       /* find a slot */
-       for (sid = 0; sid < children->nsessions; sid++) {
-         if (asp_ac[sid] == NULL)
-           break;
-
-         if (asp_ac[sid]->ac_state == ACSTATE_DEAD) {
-           free(asp_ac[sid]);
-           asp_ac[sid] = NULL;
-           break;
-         }
-       }
-
-       if ((atp = atp_open(ATADDR_ANYPORT, 
-                           &(atp_sockaddr(asp->asp_atp)->sat_addr))) == NULL) 
-         return NULL;
-
-    int dummy[2];
-       switch ((pid = fork())) {
-       case 0 : /* child */
-         server_reset_signal();
-         /* free/close some things */
-         for (i = 0; i < children->nsessions; i++ ) {
-           if ( asp_ac[i] != NULL )
-             free( asp_ac[i] );
-         }
-         free(asp_ac);
-         
-         server_child_free(children);
-         children = NULL;
-         atp_close(asp->asp_atp);
-
-         asp->child = 1;
-         asp->asp_atp = atp;
-         asp->asp_sat = sat;
-         asp->asp_wss = asp->cmdbuf[1];
-         asp->asp_seq = 0;
-         asp->asp_sid = sid;
-         asp->asp_flags = ASPFL_SSS;
-         return asp;
-         
-       case -1 : /* error */
-         asp->cmdbuf[ 0 ] = 0;
-         asp->cmdbuf[ 1 ] = 0;
-         asperr = ASPERR_SERVBUSY;
-         break;
-         
-       default : /* parent process */
-         /* we need atomic setting or pb with tickle_handler */ 
-      if (server_child_add(children, CHILD_ASPFORK, pid, dummy)) {
-           if ((asp_ac_tmp = malloc(sizeof(struct asp_child))) == NULL) {
-            kill(pid, SIGQUIT); 
-            break;
-        }
-        asp_ac_tmp->ac_pid = pid;
-        asp_ac_tmp->ac_state = ACSTATE_OK;
-        asp_ac_tmp->ac_sat = sat;
-        asp_ac_tmp->ac_sat.sat_port = asp->cmdbuf[1];
-           
-        asp->cmdbuf[0] = atp_sockaddr(atp)->sat_port;
-        asp->cmdbuf[1] = sid;
-        set_asp_ac(sid, asp_ac_tmp);
-        asperr = ASPERR_OK;
-        break;
-      } else {
-           kill(pid, SIGQUIT); 
-           break;
-      }
-         atp_close(atp);
-         break;
-       }
-       
-      } else {
-       asp->cmdbuf[0] = asp->cmdbuf[1] = 0;
-       asperr = ASPERR_SERVBUSY;
-      }
-
-      memcpy( asp->cmdbuf + 2, &asperr, sizeof(asperr));
-      iov[ 0 ].iov_base = asp->cmdbuf;
-      iov[ 0 ].iov_len = 4;
-      atpb.atp_sresiov = iov;
-      atpb.atp_sresiovcnt = 1;
-      atp_sresp( asp->asp_atp, &atpb );
-      break;
-
-    default:
-      LOG(log_info, logtype_default, "ASPUnknown %d", asp->cmdbuf[0]);
-      break;
-    }
-
-    return asp;
-}
-
-/* with fn defined after use, assume it's not optimized by the compiler */
-static void set_asp_ac(int sid, struct asp_child *tmp)
-{
-    asp_ac[sid] = tmp;
-}
diff --git a/libatalk/asp/asp_init.c b/libatalk/asp/asp_init.c
deleted file mode 100644 (file)
index 06e77f0..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * $Id: asp_init.c,v 1.4 2009-10-13 22:55:37 didg Exp $
- *
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- * All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software and
- * its documentation for any purpose and without fee is hereby granted,
- * provided that the above copyright notice appears in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation, and that the name of The University
- * of Michigan not be used in advertising or publicity pertaining to
- * distribution of the software without specific, written prior
- * permission. This software is supplied as is without expressed or
- * implied warranties of any kind.
- *
- *     Research Systems Unix Group
- *     The University of Michigan
- *     c/o Mike Clark
- *     535 W. William Street
- *     Ann Arbor, Michigan
- *     +1-313-763-0525
- *     netatalk@itd.umich.edu
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/uio.h>
-#include <sys/socket.h>
-#include <sys/param.h>
-#include <netatalk/at.h>
-#include <atalk/atp.h>
-#include <atalk/asp.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-ASP asp_init(ATP atp)
-{
-    ASP                asp;
-
-    if (( asp = (struct ASP *)calloc(1, sizeof( struct ASP ))) == NULL ) {
-       return( NULL );
-    }
-
-    asp->asp_atp = atp;
-#ifdef BSD4_4
-    asp->asp_sat.sat_len = sizeof( struct sockaddr_at );
-#endif /* BSD4_4 */
-    asp->asp_sat.sat_family = AF_APPLETALK;
-    asp->asp_sat.sat_addr.s_net = ATADDR_ANYNET;
-    asp->asp_sat.sat_addr.s_node = ATADDR_ANYNODE;
-    asp->asp_sat.sat_port = ATADDR_ANYPORT;
-    asp->asp_status = NULL;
-    asp->asp_slen = 0;
-    asp->asp_sid = 0;
-    asp->asp_flags = ASPFL_SLS;
-    asp->cmdlen = asp->datalen = 0;
-    asp->read_count = asp->write_count = 0;
-    asp->commands = asp->cmdbuf + 4;
-
-    return( asp );
-}
-
-void asp_setstatus(ASP asp, char *status, const int slen)
-{
-    asp->asp_status = status;
-    asp->asp_slen = slen;
-}
diff --git a/libatalk/asp/asp_shutdown.c b/libatalk/asp/asp_shutdown.c
deleted file mode 100644 (file)
index 1f77e1f..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * $Id: asp_shutdown.c,v 1.4 2009-10-13 22:55:37 didg Exp $
- *
- * Copyright (c) 1996 Regents of The University of Michigan.
- * All Rights Reserved.  See COPYRIGHT.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <string.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/uio.h>
-#include <netatalk/endian.h>
-#include <netatalk/at.h>
-#include <atalk/atp.h>
-#include <atalk/asp.h>
-
-int asp_shutdown(ASP asp)
-{
-    struct atp_block   atpb;
-    struct iovec       iov;
-    char               *p;
-    u_int16_t          seq;
-    u_int8_t           oport;
-
-
-    p = asp->commands;
-    *p++ = ASPFUNC_CLOSE;
-    *p++ = asp->asp_sid;
-    seq = 0;
-    memcpy( p, &seq, sizeof(seq));
-    p += sizeof(seq);
-
-    oport = asp->asp_sat.sat_port;
-    atpb.atp_saddr = &asp->asp_sat;
-    atpb.atp_saddr->sat_port = asp->asp_wss;
-    atpb.atp_sreqdata = asp->commands;
-    atpb.atp_sreqdlen = p - asp->commands;
-    atpb.atp_sreqto = 2;
-    atpb.atp_sreqtries = 5;
-
-    if ( atp_sreq( asp->asp_atp, &atpb, 1, ATP_XO ) < 0 ) {
-       asp->asp_sat.sat_port = oport;
-       return( -1 );
-    }
-
-    iov.iov_base = asp->commands;
-    iov.iov_len = ASP_CMDSIZ;
-    atpb.atp_rresiov = &iov;
-    atpb.atp_rresiovcnt = 1;
-
-    if ( atp_rresp( asp->asp_atp, &atpb ) < 0 ) {
-       asp->asp_sat.sat_port = oport;
-       return( -1 );
-    }
-    asp->asp_sat.sat_port = oport;
-
-    return( 0 );
-}
diff --git a/libatalk/asp/asp_tickle.c b/libatalk/asp/asp_tickle.c
deleted file mode 100644 (file)
index c6f3752..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * $Id: asp_tickle.c,v 1.7 2002-12-04 10:59:37 didg Exp $
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <string.h>
-#include <atalk/logger.h>
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif /* HAVE_SYS_TYPES_H */
-#include <errno.h>
-
-#include <sys/socket.h>
-#include <atalk/atp.h>
-#include <atalk/asp.h>
-
-/* send off a tickle */
-int asp_tickle(ASP asp, const u_int8_t sid, struct sockaddr_at *sat)
-{
-  struct atp_block atpb;
-  char buf[ASP_HDRSIZ];
-
-  buf[ 0 ] = ASPFUNC_TICKLE;
-  buf[ 1 ] = sid;
-  buf[ 2 ] = buf[ 3 ] = 0;
-
-  atpb.atp_saddr = sat;
-  atpb.atp_sreqdata = buf;
-  atpb.atp_sreqdlen = sizeof(buf);
-  atpb.atp_sreqto = 0;
-  atpb.atp_sreqtries = 1;
-  if ( atp_sreq( asp->asp_atp, &atpb, 0, 0 ) < 0 ) {
-    LOG(log_error, logtype_default, "atp_sreq: %s", strerror(errno) );
-    return 0;
-  }
-  return 1;
-}
diff --git a/libatalk/asp/asp_write.c b/libatalk/asp/asp_write.c
deleted file mode 100644 (file)
index 2819e31..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * $Id: asp_write.c,v 1.4 2009-10-22 12:35:39 franklahm Exp $
- *
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- * All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software and
- * its documentation for any purpose and without fee is hereby granted,
- * provided that the above copyright notice appears in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation, and that the name of The University
- * of Michigan not be used in advertising or publicity pertaining to
- * distribution of the software without specific, written prior
- * permission. This software is supplied as is without expressed or
- * implied warranties of any kind.
- *
- *     Research Systems Unix Group
- *     The University of Michigan
- *     c/o Mike Clark
- *     535 W. William Street
- *     Ann Arbor, Michigan
- *     +1-313-763-0525
- *     netatalk@itd.umich.edu
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <string.h>
-#include <sys/types.h>
-#include <sys/uio.h>
-#include <netatalk/endian.h>
-#include <netatalk/at.h>
-#include <atalk/atp.h>
-#include <atalk/asp.h>
-
-#if defined(BSD) || defined(BSD4_3)
-#define memmove(a, b, n)   bcopy((b), (a), (n))
-#endif /* BSD || BSD4_3 */
-
-int asp_wrtcont(ASP asp, char *buf, size_t *buflen)
-{
-    struct iovec       iov[ ASP_MAXPACKETS ];
-    struct atp_block   atpb;
-    char               *p;
-    int                        iovcnt = ASP_MAXPACKETS;
-    u_int16_t          blen, seq;
-    u_int8_t           oport;
-
-    p = buf;
-    *p++ = ASPFUNC_WRTCONT;
-    *p++ = asp->asp_sid;
-    seq = htons( asp->asp_seq );
-    memcpy( p, &seq, sizeof(seq));
-    p += sizeof(seq);
-    blen = htons(*buflen);
-    memcpy( p, &blen, sizeof(blen));
-    p += sizeof(blen);
-
-    for ( iovcnt = 0; iovcnt < ASP_MAXPACKETS; iovcnt++ ) {
-        iov[iovcnt].iov_base = buf + iovcnt*ASP_CMDMAXSIZ;
-       iov[ iovcnt ].iov_len = ASP_CMDMAXSIZ;
-    }
-
-    oport = asp->asp_sat.sat_port;
-    atpb.atp_saddr = &asp->asp_sat;
-    atpb.atp_saddr->sat_port = asp->asp_wss;
-    atpb.atp_sreqdata = buf;
-    atpb.atp_sreqdlen = p - buf;
-    atpb.atp_sreqto = 2;
-    atpb.atp_sreqtries = 5;
-
-    if ( atp_sreq( asp->asp_atp, &atpb, iovcnt, ATP_XO ) < 0 ) {
-       asp->asp_sat.sat_port = oport;
-       return( -1 );
-    }
-    asp->write_count += atpb.atp_sreqdlen;
-
-    atpb.atp_rresiov = iov;
-    atpb.atp_rresiovcnt = iovcnt;
-    if ( atp_rresp( asp->asp_atp, &atpb ) < 0 ) {
-       asp->asp_sat.sat_port = oport;
-       return( -1 );
-    }
-
-    asp->asp_sat.sat_port = oport;
-
-    /* get rid of the 4-byte headers */
-    p = buf;
-    for ( iovcnt = 0; iovcnt < atpb.atp_rresiovcnt; iovcnt++ ) {
-       memmove(p, (char *) iov[ iovcnt ].iov_base + ASP_HDRSIZ, 
-               iov[ iovcnt ].iov_len - ASP_HDRSIZ );
-       p += ( iov[ iovcnt ].iov_len - ASP_HDRSIZ );
-    }
-
-    *buflen = p - buf;
-    asp->read_count += *buflen;
-    return 0;
-}
diff --git a/libatalk/atp/.gitignore b/libatalk/atp/.gitignore
deleted file mode 100644 (file)
index d6c38da..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-Makefile
-Makefile.in
-*.lo
-*.la
-.deps
-.libs
-.gitignore
-atp_bufs.o atp_close.o atp_open.o atp_packet.o atp_rreq.o atp_rresp.o atp_rsel.o atp_sreq.o atp_sresp.o
diff --git a/libatalk/atp/Makefile.am b/libatalk/atp/Makefile.am
deleted file mode 100644 (file)
index fe553b0..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-# Makefile.am for libatalk/atp/
-
-noinst_LTLIBRARIES = libatp.la
-
-libatp_la_SOURCES = atp_bufs.c atp_close.c atp_open.c atp_packet.c atp_rreq.c atp_rresp.c atp_rsel.c atp_sreq.c atp_sresp.c 
-
-noinst_HEADERS = atp_internals.h
diff --git a/libatalk/atp/atp_bufs.c b/libatalk/atp/atp_bufs.c
deleted file mode 100644 (file)
index 9c899e2..0000000
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * $Id: atp_bufs.c,v 1.5 2009-10-13 22:55:37 didg Exp $
- *
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- * All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software and
- * its documentation for any purpose and without fee is hereby granted,
- * provided that the above copyright notice appears in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation, and that the name of The University
- * of Michigan not be used in advertising or publicity pertaining to
- * distribution of the software without specific, written prior
- * permission. This software is supplied as is without expressed or
- * implied warranties of any kind.
- *
- *     Research Systems Unix Group
- *     The University of Michigan
- *     c/o Mike Clark
- *     535 W. William Street
- *     Ann Arbor, Michigan
- *     +1-313-763-0525
- *     netatalk@itd.umich.edu
- */
-
-/* 
- * Our own memory maintenance for atp
-*/
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/socket.h>
-
-#include <netatalk/at.h>
-#include <atalk/atp.h>
-#include "atp_internals.h"
-
-#define                        N_MORE_BUFS             10
-
-static struct atpbuf   *free_list = NULL;      /* free buffers */
-
-#ifdef EBUG
-static int             numbufs = 0;
-#endif /* EBUG */
-
-/* only call this when the free_list is empty...
- * N_MORE_BUFS must be >= one
-*/
-static int more_bufs(void)
-{
-    int                        i;
-    char               *mem;
-    struct atpbuf      *bp;
-
-    /* get the whole chunk in one malloc call
-    */
-    if (( mem = malloc( N_MORE_BUFS * sizeof( struct atpbuf ))) == NULL ) {
-       errno = ENOBUFS;
-       return -1;
-    }
-    /* now split into separate bufs
-    */
-    bp = free_list = (struct atpbuf *) mem;
-    for ( i = 1; i < N_MORE_BUFS; ++i ) {
-       bp->atpbuf_next = (struct atpbuf *) ( mem += sizeof( struct atpbuf ));
-       bp = bp->atpbuf_next;
-    }
-    bp->atpbuf_next = NULL;
-
-    return 0;
-}
-
-
-#ifdef EBUG
-void atp_print_bufuse(ATP ah, char *s)
-{
-    struct atpbuf      *bp;
-    int                        i, sentcount, incount, respcount;
-
-    sentcount = 0;
-    for ( bp = ah->atph_sent; bp != NULL; bp = bp->atpbuf_next ) {
-       ++sentcount;
-       for ( i = 0; i < 8; ++i ) {
-           if ( bp->atpbuf_info.atpbuf_xo.atpxo_packet[ i ] != NULL ) {
-               ++sentcount;
-           }
-       }
-    }
-
-    if ( ah->atph_reqpkt != NULL ) {
-       ++sentcount;
-    }
-
-
-    incount = 0;
-    for ( bp = ah->atph_queue; bp != NULL; bp = bp->atpbuf_next, ++incount );
-
-    respcount = 0;
-    for ( i = 0; i < 8; ++i ) {
-        if ( ah->atph_resppkt[ i ] != NULL ) {
-           ++respcount;
-       }
-    }
-
-    printf( "<%d> %s: bufs total %d  sent %d  incoming %d  req %d  resp %d\n",
-       getpid(), s, numbufs, sentcount, incount,
-       ( ah->atph_reqpkt != NULL ) ? 1: 0, respcount );
-}
-#endif /* EBUG */
-
-
-struct atpbuf *atp_alloc_buf(void)
-{
-    struct atpbuf *bp;
-
-    if ( free_list == NULL && more_bufs() ) return NULL;
-
-    bp = free_list;
-    free_list = free_list->atpbuf_next;
-#ifdef EBUG
-    ++numbufs;
-#endif /* EBUG */
-    return bp;
-}
-
-
-int atp_free_buf(struct atpbuf *bp)
-{
-    if ( bp == NULL ) {
-       return -1;
-    }
-    bp->atpbuf_next = free_list;
-    free_list = bp;
-#ifdef EBUG
-    --numbufs;
-#endif /* EBUG */
-    return 0;
-}
-
-
diff --git a/libatalk/atp/atp_close.c b/libatalk/atp/atp_close.c
deleted file mode 100644 (file)
index 4d31b5f..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * $Id: atp_close.c,v 1.5 2009-10-13 22:55:37 didg Exp $
- *
- * Copyright (c) 1990,1997 Regents of The University of Michigan.
- * All Rights Reserved. See COPYRIGHT.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/socket.h>
-
-#include <netatalk/at.h>
-#include <atalk/netddp.h>
-#include <atalk/atp.h>
-#include "atp_internals.h"
-#ifdef EBUG
-#include <stdio.h>
-#endif /* EBUG */
-
-int atp_close(ATP ah)
-{
-    struct atpbuf      *cq;
-    int                        i;
-
-    /* remove from list of open atp sockets & discard queued data
-    */
-#ifdef EBUG
-    print_bufuse( ah, "atp_close");
-#endif /* EBUG */
-
-    while ( ah->atph_queue != NULL ) {
-       cq = ah->atph_queue;
-       ah->atph_queue = cq->atpbuf_next;
-       atp_free_buf( cq );
-    }
-
-    while ( ah->atph_sent != NULL ) {
-       cq = ah->atph_sent;
-       for ( i = 0; i < 8; ++i ) {
-           if ( cq->atpbuf_info.atpbuf_xo.atpxo_packet[ i ] != NULL ) {
-               atp_free_buf( cq->atpbuf_info.atpbuf_xo.atpxo_packet[ i ] );
-           }
-       }
-       ah->atph_sent = cq->atpbuf_next;
-       atp_free_buf( cq );
-    }
-
-    if ( ah->atph_reqpkt != NULL ) {
-       atp_free_buf( ah->atph_reqpkt );
-       ah->atph_reqpkt = NULL;
-    }
-
-    for ( i = 0; i < 8; ++i ) {
-       if ( ah->atph_resppkt[ i ] != NULL ) {
-           atp_free_buf( ah->atph_resppkt[ i ] );
-           ah->atph_resppkt[ i ] = NULL;
-       }
-    }
-
-#ifdef EBUG
-    print_bufuse( ah, "atp_close end");
-#endif /* EBUG */
-
-    i = ah->atph_socket;
-    atp_free_buf( (struct atpbuf *) ah );
-
-    if (netddp_close(i) < 0)
-      return -1;
-
-    return 0;
-}
diff --git a/libatalk/atp/atp_internals.h b/libatalk/atp/atp_internals.h
deleted file mode 100644 (file)
index 51d3b8b..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * $Id: atp_internals.h,v 1.4 2009-10-13 22:55:37 didg Exp $
- *
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- * All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software and
- * its documentation for any purpose and without fee is hereby granted,
- * provided that the above copyright notice appears in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation, and that the name of The University
- * of Michigan not be used in advertising or publicity pertaining to
- * distribution of the software without specific, written prior
- * permission. This software is supplied as is without expressed or
- * implied warranties of any kind.
- *
- *     Research Systems Unix Group
- *     The University of Michigan
- *     c/o Mike Clark
- *     535 W. William Street
- *     Ann Arbor, Michigan
- *     +1-313-763-0525
- *     netatalk@itd.umich.edu
- */
-
-#ifndef ATP_INTERNALS_H
-#define ATP_INTERNALS_H 1
-
-#include <sys/types.h>
-#include <sys/cdefs.h>
-#include <netatalk/at.h>
-#include <netatalk/endian.h>
-#include <atalk/atp.h>
-
-/*
- * masks for matching incoming packets
- */
-#define ATP_FUNCANY    ATP_TREQ | ATP_TRESP | ATP_TREL
-#define ATP_TIDANY     0xffff
-
-/* in atp_bufs.c */
-extern struct atpbuf *atp_alloc_buf (void);
-extern void atp_print_bufuse        (ATP, char *);
-extern int atp_free_buf             (struct atpbuf *);
-
-/* in atp_packet.c */
-extern int at_addr_eq               (struct sockaddr_at *, 
-                                        struct sockaddr_at *);
-extern void atp_build_req_packet    (struct atpbuf *, u_int16_t, 
-                                        u_int8_t, struct atp_block *);
-extern void atp_build_resp_packet   (struct atpbuf *, u_int16_t,
-                                        u_int8_t, struct atp_block *,
-                                        u_int8_t);
-extern int atp_recv_atp             (ATP, struct sockaddr_at *, 
-                                        u_int8_t *, u_int16_t, char *,
-                                        int);
-#ifdef EBUG
-extern void atp_print_addr          (char *, struct sockaddr_at *);
-#endif /* EBUG */
-
-#endif /* ATP_INTERNALS_H */
diff --git a/libatalk/atp/atp_open.c b/libatalk/atp/atp_open.c
deleted file mode 100644 (file)
index 1690752..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * $Id: atp_open.c,v 1.5 2001-08-15 02:17:57 srittau Exp $
- *
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- * All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software and
- * its documentation for any purpose and without fee is hereby granted,
- * provided that the above copyright notice appears in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation, and that the name of The University
- * of Michigan not be used in advertising or publicity pertaining to
- * distribution of the software without specific, written prior
- * permission. This software is supplied as is without expressed or
- * implied warranties of any kind.
- *
- *     Research Systems Unix Group
- *     The University of Michigan
- *     c/o Mike Clark
- *     535 W. William Street
- *     Ann Arbor, Michigan
- *     +1-313-763-0525
- *     netatalk@itd.umich.edu
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/param.h>
-#include <sys/socket.h>
-
-#include <netatalk/at.h>
-#include <netatalk/endian.h>
-
-#include <atalk/netddp.h>
-#include <atalk/ddp.h>
-#include <atalk/atp.h>
-
-#include "atp_internals.h"
-
-ATP atp_open(u_int8_t port, const struct at_addr *saddr)
-{
-    struct sockaddr_at  addr;
-    int                        s;
-    ATP                        atp;
-    struct timeval     tv;
-    int                        pid;
-
-#ifdef DEBUG
-    printf( "<%d> atp_open\n", getpid());
-#endif /* DEBUG */
-
-    memset(&addr, 0, sizeof(addr));
-    addr.sat_port = port;
-    if (saddr) 
-      memcpy(&addr.sat_addr, saddr, sizeof(struct at_addr));
-    if ((s = netddp_open(&addr, NULL)) < 0)
-        return NULL;
-
-    if (( atp = (ATP) atp_alloc_buf()) == NULL ) {
-        netddp_close(s);
-       return NULL;
-    }
-
-    /* initialize the atp handle */
-    memset(atp, 0, sizeof( struct atp_handle ));
-    memcpy(&atp->atph_saddr, &addr, sizeof(addr));
-
-    atp->atph_socket = s;
-    atp->atph_reqto = -1;
-    gettimeofday( &tv, (struct timezone *) 0 );
-    pid = getpid();
-    atp->atph_tid = tv.tv_sec ^ ((( pid << 8 ) & 0xff00 ) | ( pid >> 8 ));
-
-#ifdef EBUG
-srandom( tv.tv_sec );
-#endif /* EBUG */
-
-    return atp;
-}
diff --git a/libatalk/atp/atp_packet.c b/libatalk/atp/atp_packet.c
deleted file mode 100644 (file)
index a7fae01..0000000
+++ /dev/null
@@ -1,327 +0,0 @@
-/*
- * $Id: atp_packet.c,v 1.6 2009-10-13 22:55:37 didg Exp $
- *
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- * All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software and
- * its documentation for any purpose and without fee is hereby granted,
- * provided that the above copyright notice appears in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation, and that the name of The University
- * of Michigan not be used in advertising or publicity pertaining to
- * distribution of the software without specific, written prior
- * permission. This software is supplied as is without expressed or
- * implied warranties of any kind.
- *
- *     Research Systems Unix Group
- *     The University of Michigan
- *     c/o Mike Clark
- *     535 W. William Street
- *     Ann Arbor, Michigan
- *     +1-313-763-0525
- *     netatalk@itd.umich.edu
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <string.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/uio.h>
-#include <sys/param.h>
-#include <netinet/in.h>
-
-#include <netatalk/at.h>
-#include <netatalk/endian.h>
-
-#include <atalk/netddp.h>
-#include <atalk/ddp.h>
-#include <atalk/atp.h>
-#include <atalk/util.h>
-
-#include "atp_internals.h"
-
-/* FIXME/SOCKLEN_T: socklen_t is a unix98 feature. */
-#ifndef SOCKLEN_T
-#define SOCKLEN_T unsigned int
-#endif /* ! SOCKLEN_T */
-
-#ifdef EBUG
-#include <stdio.h>
-
-static void print_func(u_int8_t ctrlinfo)
-{
-    switch ( ctrlinfo & ATP_FUNCMASK ) {
-    case ATP_TREQ:
-       printf( "TREQ" );
-       break;
-    case ATP_TRESP:
-       printf( "TRESP" );
-       break;
-    case ATP_TREL:
-       printf( "ANY/TREL" );
-       break;
-    case ATP_TIDANY:
-       printf( "*" );
-       break;
-    default:
-       printf( "%x", ctrlinfo & ATP_FUNCMASK );
-    }
-}
-
-static void dump_packet(char *buf, int len)
-{
-    int                i;
-
-    for ( i = 0; i < len; ++i ) {
-       printf( "%x-%c ", buf[i], buf[i] );
-    }
-    putchar( '\n' );
-}
-
-void atp_print_addr(char *s, struct sockaddr_at *saddr)
-{
-    printf( "%s ", s );
-    saddr->sat_family == AF_APPLETALK ? printf( "at." ) :
-      printf( "%d.", saddr->sat_family );
-    saddr->sat_addr.s_net == ATADDR_ANYNET ? printf( "*." ) :
-      printf( "%d.", ntohs( saddr->sat_addr.s_net ));
-    saddr->sat_addr.s_node == ATADDR_ANYNODE ? printf( "*." ) :
-      printf( "%d.", saddr->sat_addr.s_node );
-    saddr->sat_port == ATADDR_ANYPORT ? printf( "*" ) :
-      printf( "%d", saddr->sat_port );
-}
-#endif /* EBUG */
-
-
-void atp_build_req_packet( struct atpbuf *pktbuf,
-                          u_int16_t tid,
-                          u_int8_t ctrl,
-                          struct atp_block *atpb )
-{
-    struct atphdr      hdr;
-
-    /* fill in the packet fields
-    */
-    hdr.atphd_ctrlinfo = ctrl;
-    hdr.atphd_bitmap = atpb->atp_bitmap;
-    hdr.atphd_tid = htons( tid );
-    *(pktbuf->atpbuf_info.atpbuf_data) = DDPTYPE_ATP;
-    memcpy(pktbuf->atpbuf_info.atpbuf_data + 1, &hdr, sizeof( struct atphdr ));
-    memcpy(pktbuf->atpbuf_info.atpbuf_data + ATP_HDRSIZE, 
-          atpb->atp_sreqdata, atpb->atp_sreqdlen ); 
-
-    /* set length
-    */
-    pktbuf->atpbuf_dlen = ATP_HDRSIZE + (size_t) atpb->atp_sreqdlen;
-}
-
-void atp_build_resp_packet( struct atpbuf *pktbuf,
-                           u_int16_t tid,
-                           u_int8_t ctrl,
-                           struct atp_block *atpb,
-                           u_int8_t seqnum )
-{
-    struct atphdr      hdr;
-
-    /* fill in the packet fields */
-    *(pktbuf->atpbuf_info.atpbuf_data) = DDPTYPE_ATP;
-    hdr.atphd_ctrlinfo = ctrl;
-    hdr.atphd_bitmap = seqnum;
-    hdr.atphd_tid = htons( tid );
-    memcpy(pktbuf->atpbuf_info.atpbuf_data + 1, &hdr, 
-          sizeof( struct atphdr ));
-    memcpy(pktbuf->atpbuf_info.atpbuf_data + ATP_HDRSIZE,
-         atpb->atp_sresiov[ seqnum ].iov_base,
-         atpb->atp_sresiov[ seqnum ].iov_len ); 
-
-    /* set length
-    */
-    pktbuf->atpbuf_dlen = ATP_HDRSIZE + (size_t) atpb->atp_sresiov[ seqnum ].iov_len;
-}
-
-
-int
-atp_recv_atp( ATP ah,
-             struct sockaddr_at *fromaddr,
-             u_int8_t *func,
-             u_int16_t tid,
-             char *rbuf,
-             int wait )
-{
-/* 
-  Receive a packet from address fromaddr of the correct function type
-  and with the correct tid.  fromaddr = AT_ANY... and function == ATP_TYPEANY
-  and tid == ATP_TIDANY can be used to wildcard match.
-  
-  recv_atp returns the length of the packet received (or -1 if error)
-  The function code for the packet received is returned in *func (ATP_TREQ or
-    ATP_TRESP).
-*/
-    struct atpbuf      *pq, *cq;
-    struct atphdr      ahdr;
-    u_int16_t          rfunc;
-    u_int16_t          rtid;
-    int                        i;
-    int                        dlen = -1;
-    int                        recvlen;
-    struct sockaddr_at faddr;
-    SOCKLEN_T          faddrlen;
-    struct atpbuf      *inbuf;
-
-    tid = htons( tid );
-
-    /* first check the queue
-    */
-#ifdef EBUG
-    atp_print_bufuse( ah, "recv_atp checking queue" );
-#endif /* EBUG */
-    for ( pq = NULL, cq = ah->atph_queue; cq != NULL;
-      pq = cq, cq = cq->atpbuf_next ) {
-       memcpy(&ahdr, cq->atpbuf_info.atpbuf_data + 1, 
-              sizeof( struct atphdr ));
-       rfunc = ahdr.atphd_ctrlinfo & ATP_FUNCMASK;
-#ifdef EBUG
-       printf( "<%d> checking", getpid());
-       printf( " tid=%hu func=", ntohs( ahdr.atphd_tid ));
-       print_func( rfunc );
-       atp_print_addr( " from", &cq->atpbuf_addr );
-       putchar( '\n' );
-#endif /* EBUG */
-       if ((( tid & ahdr.atphd_tid ) == ahdr.atphd_tid ) &&
-           (( *func & rfunc ) == rfunc )
-           && at_addr_eq( fromaddr, &cq->atpbuf_addr )) {
-           break;
-       }
-    }
-    if ( cq != NULL ) {
-       /* we found one in the queue -- copy to rbuf
-       */
-       dlen = (int) cq->atpbuf_dlen;
-       *func = rfunc;
-       memcpy( fromaddr, &cq->atpbuf_addr, sizeof( struct sockaddr_at ));
-       memcpy( rbuf, cq->atpbuf_info.atpbuf_data, cq->atpbuf_dlen );
-
-       /* remove packet from queue and free buffer
-       */
-       if ( pq == NULL ) {
-           ah->atph_queue = NULL;
-       } else {
-           pq->atpbuf_next = cq->atpbuf_next;
-       }
-       atp_free_buf( cq );
-       return( dlen );
-    }
-
-    /* we need to get it the net -- call on ddp to receive a packet
-    */
-#ifdef EBUG
-    printf( "<%d>", getpid());
-    atp_print_addr( " waiting on address", &ah->atph_saddr );
-    printf( "\nfor tid=%hu func=", ntohs( tid ));
-    print_func( *func );
-    atp_print_addr( " from", fromaddr );
-    putchar( '\n' );
-#endif /* EBUG */
-
-    do {
-#ifdef EBUG
-    fflush( stdout );
-#endif /* EBUG */
-       faddrlen = sizeof( struct sockaddr_at );
-       memset( &faddr, 0, sizeof( struct sockaddr_at ));
-
-       if (( recvlen = netddp_recvfrom( ah->atph_socket, rbuf, 
-                                        ATP_BUFSIZ, 0,
-                                        (struct sockaddr *) &faddr,
-                                        &faddrlen )) < 0 ) {
-           return -1;
-       }
-       memcpy( &ahdr, rbuf + 1, sizeof( struct atphdr ));
-       if ( recvlen >= ATP_HDRSIZE && *rbuf == DDPTYPE_ATP) {
-           /* this is a valid ATP packet -- check for a match */
-           rfunc = ahdr.atphd_ctrlinfo & ATP_FUNCMASK;
-           rtid = ahdr.atphd_tid;
-#ifdef EBUG
-           printf( "<%d> got tid=%hu func=", getpid(), ntohs( rtid ));
-           print_func( rfunc );
-           atp_print_addr( " from", &faddr );
-           putchar( '\n' );
-           bprint( rbuf, recvlen );
-#endif /* EBUG */
-           if ( rfunc == ATP_TREL ) {
-               /* remove response from sent list */
-               for ( pq = NULL, cq = ah->atph_sent; cq != NULL;
-                 pq = cq, cq = cq->atpbuf_next ) {
-                   if ( at_addr_eq( &faddr, &cq->atpbuf_addr ) &&
-                     cq->atpbuf_info.atpbuf_xo.atpxo_tid == ntohs( rtid )) 
-                       break;
-               }
-               if ( cq != NULL ) {
-#ifdef EBUG
-       printf( "<%d> releasing transaction %hu\n", getpid(), ntohs( rtid ));
-#endif /* EBUG */
-                   if ( pq == NULL ) {
-                       ah->atph_sent = cq->atpbuf_next;
-                   } else {
-                       pq->atpbuf_next = cq->atpbuf_next;
-                   }
-                   for ( i = 0; i < 8; ++i ) {
-                       if ( cq->atpbuf_info.atpbuf_xo.atpxo_packet[ i ]
-                                   != NULL ) {
-                           atp_free_buf ( cq->atpbuf_info.atpbuf_xo.atpxo_packet[ i ] );
-                       }
-                   }
-                   atp_free_buf( cq );
-               }
-
-           } else if ((( tid & rtid ) == rtid ) &&
-                   (( *func & rfunc ) == rfunc ) &&
-                   at_addr_eq( fromaddr, &faddr )) { /* got what we wanted */
-               *func = rfunc;
-               dlen = recvlen;
-               memcpy( fromaddr, &faddr, sizeof( struct sockaddr_at ));
-
-           } else {
-               /* add packet to incoming queue */
-#ifdef EBUG
-       printf( "<%d> queuing incoming...\n", getpid() );
-#endif /* EBUG */
-               if (( inbuf = atp_alloc_buf()) == NULL ) {
-                   return -1;
-               }
-               memcpy( &inbuf->atpbuf_addr, &faddr, 
-                       sizeof( struct sockaddr_at ));
-               inbuf->atpbuf_next = ah->atph_queue;
-               inbuf->atpbuf_dlen = (size_t) recvlen;
-               memcpy( inbuf->atpbuf_info.atpbuf_data, rbuf, recvlen );
-           }
-       }
-       if ( !wait && dlen < 0 ) {
-           return( 0 );
-       }
-
-    } while ( dlen < 0 );
-
-    return( dlen );
-}
-
-
-int at_addr_eq( 
-    struct sockaddr_at *paddr,         /* primary address */
-    struct sockaddr_at *saddr)         /* secondary address */
-{
-/* compare two atalk addresses -- only check the non-zero fields
-    of paddr against saddr.
-   return zero if not equal, non-zero if equal
-*/
-    return (( paddr->sat_port == ATADDR_ANYPORT || paddr->sat_port == saddr->sat_port )
-       &&  ( paddr->sat_addr.s_net == ATADDR_ANYNET ||
-             paddr->sat_addr.s_net == saddr->sat_addr.s_net )
-       &&  ( paddr->sat_addr.s_node == ATADDR_ANYNODE ||
-             paddr->sat_addr.s_node == saddr->sat_addr.s_node ));
-}
-
diff --git a/libatalk/atp/atp_rreq.c b/libatalk/atp/atp_rreq.c
deleted file mode 100644 (file)
index 6736dbd..0000000
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * $Id: atp_rreq.c,v 1.4 2009-10-13 22:55:37 didg Exp $
- *
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- * All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software and
- * its documentation for any purpose and without fee is hereby granted,
- * provided that the above copyright notice appears in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation, and that the name of The University
- * of Michigan not be used in advertising or publicity pertaining to
- * distribution of the software without specific, written prior
- * permission. This software is supplied as is without expressed or
- * implied warranties of any kind.
- *
- *     Research Systems Unix Group
- *     The University of Michigan
- *     c/o Mike Clark
- *     535 W. William Street
- *     Ann Arbor, Michigan
- *     +1-313-763-0525
- *     netatalk@itd.umich.edu
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <errno.h>
-
-#include <netinet/in.h>
-#include <netatalk/at.h>
-#include <netatalk/endian.h>
-#include <atalk/atp.h>
-
-#include "atp_internals.h"
-
-
-/* wait for a tranasaction service request
-*/
-int atp_rreq(
-    ATP                        ah,             /* open atp handle */
-    struct atp_block   *atpb)          /* parameter block */
-{
-    struct atpbuf      *req_buf;       /* for receiving request packet */
-    struct atphdr      req_hdr;        /* request header overlay */
-    struct sockaddr_at faddr;          /* sender's address */
-    int                        recvlen;        /* length of received packet */
-    u_int16_t          tid;
-    int                        rc;
-    u_int8_t           func;
-
-#ifdef EBUG
-    atp_print_bufuse( ah, "atp_rreq" );
-#endif /* EBUG */
-
-    while (( rc = atp_rsel( ah, atpb->atp_saddr, ATP_TREQ )) == 0 ) {
-       ;
-    }
-
-    if ( rc != ATP_TREQ ) {
-#ifdef EBUG
-       printf( "<%d> atp_rreq: atp_rsel returns err %d\n", getpid(), rc );
-#endif /* EBUG */
-       return( rc );
-    }
-
-    /* allocate a buffer for receiving request
-    */
-    if (( req_buf = atp_alloc_buf()) == NULL ) {
-       return -1;
-    }
-
-    memcpy( &faddr, atpb->atp_saddr, sizeof( struct sockaddr_at ));
-    func = ATP_TREQ;
-    if (( recvlen = atp_recv_atp( ah, &faddr, &func, ATP_TIDANY,
-         req_buf->atpbuf_info.atpbuf_data, 1 )) < 0 ) {
-       atp_free_buf( req_buf );
-       return -1;
-    }
-
-    memcpy( &req_hdr, req_buf->atpbuf_info.atpbuf_data + 1, 
-           sizeof( struct atphdr ));
-    tid = ntohs( req_hdr.atphd_tid );
-
-    ah->atph_rtid = tid;
-    if (( ah->atph_rxo = req_hdr.atphd_ctrlinfo & ATP_XO ) != 0 ) {
-       ah->atph_rreltime = ATP_RELTIME *
-               ( 1 << ( req_hdr.atphd_ctrlinfo & ATP_TRELMASK ));
-    }
-
-    memcpy( atpb->atp_saddr, &faddr, sizeof( struct sockaddr_at ));
-
-    if ( recvlen - ATP_HDRSIZE > atpb->atp_rreqdlen ) {
-       atp_free_buf( req_buf );
-       errno = EMSGSIZE;
-       return -1;
-    }
-
-    atpb->atp_rreqdlen = recvlen - ATP_HDRSIZE;
-    memcpy( atpb->atp_rreqdata, 
-           req_buf->atpbuf_info.atpbuf_data + ATP_HDRSIZE,
-           recvlen - ATP_HDRSIZE );
-    atpb->atp_bitmap = req_hdr.atphd_bitmap;
-    atp_free_buf( req_buf );
-    return( 0 );
-}
diff --git a/libatalk/atp/atp_rresp.c b/libatalk/atp/atp_rresp.c
deleted file mode 100644 (file)
index ac0a146..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * $Id: atp_rresp.c,v 1.6 2009-10-13 22:55:37 didg Exp $
- *
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- * All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software and
- * its documentation for any purpose and without fee is hereby granted,
- * provided that the above copyright notice appears in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation, and that the name of The University
- * of Michigan not be used in advertising or publicity pertaining to
- * distribution of the software without specific, written prior
- * permission. This software is supplied as is without expressed or
- * implied warranties of any kind.
- *
- *     Research Systems Unix Group
- *     The University of Michigan
- *     c/o Mike Clark
- *     535 W. William Street
- *     Ann Arbor, Michigan
- *     +1-313-763-0525
- *     netatalk@itd.umich.edu
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <errno.h>
-#include <sys/uio.h>
-#include <sys/socket.h>
-
-#include <netatalk/at.h>
-#include <atalk/atp.h>
-#include <atalk/util.h>
-
-#ifdef EBUG
-#include <stdio.h>
-#endif /* EBUG */
-
-#include "atp_internals.h"
-
-int
-atp_rresp(
-    ATP                        ah,             /* open atp handle */
-    struct atp_block   *atpb)          /* parameter block */
-{
-    int                i, rc;
-    size_t     len;
-
-#ifdef EBUG
-    atp_print_bufuse( ah, "atp_rresp" );
-#endif /* EBUG */
-    /* check parameters
-    */
-    if ( atpb->atp_rresiovcnt <= 0 || atpb->atp_rresiovcnt > 8 ) {
-       errno = EINVAL;
-       return( -1 );
-    }
-
-    while (( rc = atp_rsel( ah, atpb->atp_saddr, ATP_TRESP )) == 0 ) {
-       ;
-    }
-
-    if ( rc != ATP_TRESP ) {
-       return( rc );
-    }
-
-    for ( i = 0; i < 8; ++i ) {
-       if ( ah->atph_resppkt[ i ] == NULL ) {
-           break;
-       }
-       len = ah->atph_resppkt[ i ]->atpbuf_dlen - ATP_HDRSIZE;
-       if ( i > atpb->atp_rresiovcnt - 1 ||
-               len > atpb->atp_rresiov[ i ].iov_len ) {
-           errno = EMSGSIZE;
-           return( -1 );
-       }
-#ifdef EBUG
-       fprintf( stderr, "atp_rresp copying %ld bytes packet %d\n",
-               len, i );
-       bprint( (char *)ah->atph_resppkt[ i ]->atpbuf_info.atpbuf_data,
-               len + ATP_HDRSIZE );
-#endif /* EBUG */
-       memcpy(atpb->atp_rresiov[ i ].iov_base,
-              ah->atph_resppkt[ i ]->atpbuf_info.atpbuf_data + ATP_HDRSIZE,
-              len );
-       atpb->atp_rresiov[ i ].iov_len = len;
-       atp_free_buf( ah->atph_resppkt[ i ] );
-       ah->atph_resppkt[ i ] = NULL;
-    }
-    atpb->atp_rresiovcnt = i;
-
-    return( 0 );
-}
diff --git a/libatalk/atp/atp_rsel.c b/libatalk/atp/atp_rsel.c
deleted file mode 100644 (file)
index bc6ec56..0000000
+++ /dev/null
@@ -1,360 +0,0 @@
-/*
- * $Id: atp_rsel.c,v 1.6 2009-10-14 01:38:28 didg Exp $
- *
- * Copyright (c) 1990,1997 Regents of The University of Michigan.
- * All Rights Reserved. See COPYRIGHT.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <string.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/uio.h>
-#include <signal.h>
-#include <errno.h>
-
-#include <netatalk/endian.h>
-#include <netatalk/at.h>
-
-#include <atalk/netddp.h>
-#include <atalk/compat.h>
-#include <atalk/atp.h>
-#include <atalk/util.h>
-
-#include "atp_internals.h"
-
-#ifdef DROP_ATPTREL
-static int     release_count = 0;
-#endif /* DROP_ATPTREL */
-
-
-static int
-resend_request(ATP ah)
-{
-    /*
-     * update bitmap and send request packet
-     */
-    struct atphdr      req_hdr;
-
-#ifdef EBUG
-    printf( "\n<%d> resend_request: resending %ld byte request packet",
-           getpid(), ah->atph_reqpkt->atpbuf_dlen );
-    atp_print_addr( " to", &ah->atph_reqpkt->atpbuf_addr );
-    putchar( '\n' );
-    bprint( ah->atph_reqpkt->atpbuf_info.atpbuf_data,
-           ah->atph_reqpkt->atpbuf_dlen );
-#endif /* EBUG */
-
-    memcpy( &req_hdr, ah->atph_reqpkt->atpbuf_info.atpbuf_data + 1, 
-       sizeof( struct atphdr ));
-    req_hdr.atphd_bitmap = ah->atph_rbitmap;
-    memcpy( ah->atph_reqpkt->atpbuf_info.atpbuf_data + 1, &req_hdr, 
-           sizeof( struct atphdr ));
-
-    gettimeofday( &ah->atph_reqtv, (struct timezone *)0 );
-    if ( netddp_sendto( ah->atph_socket,
-           ah->atph_reqpkt->atpbuf_info.atpbuf_data,
-           ah->atph_reqpkt->atpbuf_dlen, 0,
-           (struct sockaddr *) &ah->atph_reqpkt->atpbuf_addr,
-           sizeof( struct sockaddr_at )) != ah->atph_reqpkt->atpbuf_dlen ) {
-       return( -1 );
-    }
-
-    if ( ah->atph_reqtries > 0 ) {
-       --(ah->atph_reqtries);
-    }
-
-    return( 0 );
-}
-
-int
-atp_rsel( 
-    ATP                        ah,             /* open atp handle */
-    struct sockaddr_at *faddr,         /* address to receive from */
-    int                        func)           /* which function(s) to wait for;
-                                          0 means request or response */
-{
-    struct atpbuf      *abuf, *pb, *cb;
-    struct atphdr      req_hdr, resp_hdr;
-    fd_set             fds;
-    int                        i, recvlen, requesting, mask, c;
-    u_int8_t           rfunc;
-    u_int16_t          tid;
-    struct timeval     tv;
-    struct sockaddr_at saddr;
-
-#ifdef EBUG
-    atp_print_bufuse( ah, "atp_rsel at top" );
-#endif /* EBUG */
-    if ( func == 0 ) {
-       func = ATP_FUNCANY;
-    }
-
-    requesting = ( func & ATP_TRESP ) && ah->atph_rrespcount > 0 &&
-       ( ah->atph_reqtries > 0 || ah->atph_reqtries == ATP_TRIES_INFINITE );
-
-    if ( requesting && ah->atph_rbitmap == 0 ) {
-       /*
-        * we already have a complete atp response; just return
-        */
-       return( ATP_TRESP );
-    }
-
-    if (( abuf = atp_alloc_buf()) == NULL ) {
-       return( -1 );
-    }
-
-    if ( requesting ) {
-#ifdef EBUG
-       printf( "<%d> atp_rsel: request pending\n", getpid());
-#endif /* EBUG */
-       gettimeofday( &tv, (struct timezone *)0 );
-       if ( tv.tv_sec - ah->atph_reqtv.tv_sec > ah->atph_reqto ) {
-           if ( resend_request( ah ) < 0 ) {
-               atp_free_buf( abuf );
-               return( -1 );
-           }
-       }
-    }
-
-    for ( ;; ) {
-       rfunc = func;
-       if ( requesting ) {
-           FD_ZERO( &fds );
-           FD_SET( ah->atph_socket, &fds );
-           tv.tv_sec = ah->atph_reqto;
-           tv.tv_usec = 0;
-           if (( c = select( ah->atph_socket + 1, &fds, NULL, NULL,
-                   &tv )) < 0 ) {
-               atp_free_buf( abuf );
-               return( -1 );
-           }
-           if ( c == 0 || FD_ISSET( ah->atph_socket, &fds ) == 0 ) {
-               recvlen = -1;
-               errno = EINTR;
-               goto timeout;
-           }
-       }
-       memcpy( &saddr, faddr, sizeof( struct sockaddr_at ));
-#ifdef EBUG
-       printf( "<%d> atp_rsel calling recv_atp,", getpid());
-       atp_print_addr( " accepting from: ", &saddr );
-       putchar( '\n' );
-#endif /* EBUG */
-       if (( recvlen = atp_recv_atp( ah, &saddr, &rfunc, ATP_TIDANY,
-               abuf->atpbuf_info.atpbuf_data, 0 )) >= 0 ) {
-           break;      /* we received something */
-       }
-
-timeout :
-       if ( !requesting || errno != EINTR ) {
-           break;      /* error */
-       }
-           
-       if ( ah->atph_reqtries <= 0 &&
-               ah->atph_reqtries != ATP_TRIES_INFINITE ) {
-           errno = ETIMEDOUT;
-           break;
-       }
-       
-       if ( resend_request( ah ) < 0 ) {
-           break;      /* error */
-       }
-    }
-
-    if ( recvlen <= 0 ) {      /* error */
-       atp_free_buf( abuf );
-       return( recvlen );
-    }
-
-#ifdef EBUG
-    printf( "<%d> atp_rsel: rcvd %d bytes", getpid(), recvlen );
-    atp_print_addr( " from: ", &saddr );
-    putchar( '\n' );
-    bprint( abuf->atpbuf_info.atpbuf_data, recvlen );
-#endif /* EBUG */
-
-    abuf->atpbuf_dlen = (size_t) recvlen;
-    memcpy( &resp_hdr, abuf->atpbuf_info.atpbuf_data + 1,
-           sizeof( struct atphdr ));
-
-    if ( rfunc == ATP_TREQ ) {
-       /*
-        * we got a request: check to see if it is a duplicate (XO)
-        * while we are at it, we expire old XO responses from sent list
-        */
-       memcpy( &req_hdr, abuf->atpbuf_info.atpbuf_data + 1, 
-               sizeof( struct atphdr ));
-       tid = ntohs( req_hdr.atphd_tid );
-       gettimeofday( &tv, (struct timezone *)0 );
-       for ( pb = NULL, cb = ah->atph_sent; cb != NULL;
-               pb = cb, cb = cb->atpbuf_next ) {
-#ifdef EBUG
-           printf( "<%d>", getpid());
-           atp_print_addr( " examining", &cb->atpbuf_addr );
-           printf( " %hu", cb->atpbuf_info.atpbuf_xo.atpxo_tid );
-           atp_print_addr( " (looking for", &saddr );
-           printf( " %hu)\n", tid );
-#endif /* EBUG */
-           if ( tv.tv_sec - cb->atpbuf_info.atpbuf_xo.atpxo_tv.tv_sec
-                   > cb->atpbuf_info.atpbuf_xo.atpxo_reltime ) {
-               /* discard expired response */
-#ifdef EBUG
-               printf( "<%d> expiring tid %hu\n", getpid(),
-                       cb->atpbuf_info.atpbuf_xo.atpxo_tid );
-#endif /* EBUG */
-               if ( pb == NULL ) {
-                   ah->atph_sent = cb->atpbuf_next;
-               } else {
-                   pb->atpbuf_next = cb->atpbuf_next;
-               }
-
-               for ( i = 0; i < 8; ++i ) {
-                   if ( cb->atpbuf_info.atpbuf_xo.atpxo_packet[ i ]
-                           != NULL ) {
-                       atp_free_buf( cb->atpbuf_info.atpbuf_xo.atpxo_packet[ i ] );
-                   }
-               }
-               atp_free_buf( cb );
-
-               if (( cb = pb ) == NULL )
-                   break;
-
-           } else if ( at_addr_eq( &saddr, &cb->atpbuf_addr )) {
-               if ( cb->atpbuf_info.atpbuf_xo.atpxo_tid == tid ) {
-                   break;
-               }
-           }
-       }
-
-       if ( cb != NULL ) {
-#ifdef EBUG
-           printf( "<%d> duplicate request -- re-sending XO resp\n",
-                   getpid());
-#endif /* EBUG */
-           /* matches an old response -- just re-send and reset expire */
-           cb->atpbuf_info.atpbuf_xo.atpxo_tv = tv;
-           for ( i = 0; i < 8; ++i ) {
-               if ( cb->atpbuf_info.atpbuf_xo.atpxo_packet[i] != NULL &&
-                       req_hdr.atphd_bitmap & ( 1 << i )) {
-                   netddp_sendto( ah->atph_socket,
-                           cb->atpbuf_info.atpbuf_xo.atpxo_packet[i]->atpbuf_info.atpbuf_data,
-                           cb->atpbuf_info.atpbuf_xo.atpxo_packet[i]->atpbuf_dlen,
-                           0, (struct sockaddr *) &saddr, sizeof( struct sockaddr_at));
-               }
-           }
-       }
-
-       if ( cb == NULL ) {
-           /* new request -- queue it and return */
-           memcpy( &abuf->atpbuf_addr, &saddr, sizeof( struct sockaddr_at ));
-           memcpy( faddr, &saddr, sizeof( struct sockaddr_at ));
-           abuf->atpbuf_next = ah->atph_queue;
-           ah->atph_queue = abuf;
-           return( ATP_TREQ );
-       } else {
-           atp_free_buf( abuf );
-           return( 0 );
-       }
-    }
-
-    /*
-     * we got a response: update bitmap
-     */
-    memcpy( &req_hdr, ah->atph_reqpkt->atpbuf_info.atpbuf_data + 1, 
-           sizeof( struct atphdr ));
-    if ( requesting && ah->atph_rbitmap & ( 1<<resp_hdr.atphd_bitmap )
-               && req_hdr.atphd_tid == resp_hdr.atphd_tid ) {
-       ah->atph_rbitmap &= ~( 1<<resp_hdr.atphd_bitmap );
-
-       if ( ah->atph_resppkt[ resp_hdr.atphd_bitmap ] != NULL ) {
-           atp_free_buf( ah->atph_resppkt[ resp_hdr.atphd_bitmap ] );
-       }
-       ah->atph_resppkt[ resp_hdr.atphd_bitmap ] = abuf;
-
-       /* if End Of Message, clear all higher bitmap bits
-       */
-       if ( resp_hdr.atphd_ctrlinfo & ATP_EOM ) {
-#ifdef EBUG
-           printf( "<%d> EOM -- seq num %d  current bitmap %d\n",
-               getpid(), resp_hdr.atphd_bitmap, ah->atph_rbitmap );
-#endif /* EBUG */
-           mask = 1 << resp_hdr.atphd_bitmap;
-           ah->atph_rbitmap &= ( mask | (mask-1) );
-       }
-
-       /* if Send Trans. Status, send updated request
-       */
-       if ( resp_hdr.atphd_ctrlinfo & ATP_STS ) {
-#ifdef EBUG
-           puts( "STS" );
-#endif /* EBUG */
-           req_hdr.atphd_bitmap = ah->atph_rbitmap;
-           memcpy(ah->atph_reqpkt->atpbuf_info.atpbuf_data + 1,
-                  &req_hdr, sizeof( struct atphdr ));
-           if ( netddp_sendto( ah->atph_socket,
-                   ah->atph_reqpkt->atpbuf_info.atpbuf_data,
-                   ah->atph_reqpkt->atpbuf_dlen, 0,
-                   (struct sockaddr *) &ah->atph_reqpkt->atpbuf_addr,
-                   sizeof( struct sockaddr_at )) !=
-                   ah->atph_reqpkt->atpbuf_dlen ) {
-               atp_free_buf( abuf );
-               return( -1 );
-           }
-       }
-    } else {
-       /*
-        * we are not expecting this response -- toss it
-        */
-       atp_free_buf( abuf );
-#ifdef EBUG
-       printf( "atp_rsel: ignoring resp bm=%x tid=%d (expected %x/%d)\n",
-               resp_hdr.atphd_bitmap, ntohs( resp_hdr.atphd_tid ),
-               ah->atph_rbitmap, ah->atph_tid );
-#endif /* EBUG */
-    }
-
-    if ( !ah->atph_rbitmap && ( req_hdr.atphd_ctrlinfo & ATP_XO )) {
-       /*
-        * successful completion - send release
-        * the release consists of DDP type byte + ATP header + 4 user bytes
-        */
-       req_hdr.atphd_ctrlinfo = ATP_TREL;
-       memcpy( ah->atph_reqpkt->atpbuf_info.atpbuf_data + 1, &req_hdr, 
-           sizeof( struct atphdr ));
-       memset( ah->atph_reqpkt->atpbuf_info.atpbuf_data + ATP_HDRSIZE, 0, 4 );
-       ah->atph_reqpkt->atpbuf_dlen = sizeof( struct atphdr ) + ATP_HDRSIZE;
-#ifdef EBUG
-       printf( "<%d> sending TREL", getpid() );
-       bprint( ah->atph_reqpkt->atpbuf_info.atpbuf_data,
-               ah->atph_reqpkt->atpbuf_dlen );
-#endif /* EBUG */
-#ifdef DROP_ATPTREL
-       if (( ++release_count % 10 ) != 0 ) {
-#endif /* DROP_ATPTREL */
-       netddp_sendto( ah->atph_socket, 
-                      ah->atph_reqpkt->atpbuf_info.atpbuf_data,
-                      ah->atph_reqpkt->atpbuf_dlen, 0,
-                      (struct sockaddr *) &ah->atph_reqpkt->atpbuf_addr,
-                      sizeof( struct sockaddr_at));
-#ifdef DROP_ATPTREL
-       }
-#endif /* DROP_ATPTREL */
-    }
-
-    if ( ah->atph_rbitmap != 0 ) {
-       if ( ah->atph_reqtries > 0
-               || ah->atph_reqtries == ATP_TRIES_INFINITE ) {
-           return( 0 );
-       } else {
-           errno = ETIMEDOUT;
-           return( -1 );
-       }
-    }
-
-    memcpy( faddr, &saddr, sizeof( struct sockaddr_at ));
-    return( ATP_TRESP );
-}
diff --git a/libatalk/atp/atp_sreq.c b/libatalk/atp/atp_sreq.c
deleted file mode 100644 (file)
index a34f347..0000000
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * $Id: atp_sreq.c,v 1.5 2002-01-17 06:08:55 srittau Exp $
- *
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- * All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software and
- * its documentation for any purpose and without fee is hereby granted,
- * provided that the above copyright notice appears in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation, and that the name of The University
- * of Michigan not be used in advertising or publicity pertaining to
- * distribution of the software without specific, written prior
- * permission. This software is supplied as is without expressed or
- * implied warranties of any kind.
- *
- *     Research Systems Unix Group
- *     The University of Michigan
- *     c/o Mike Clark
- *     535 W. William Street
- *     Ann Arbor, Michigan
- *     +1-313-763-0525
- *     netatalk@itd.umich.edu
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <errno.h>
-#include <sys/uio.h>
-#include <signal.h>
-
-#include <netinet/in.h>
-#include <netatalk/at.h>
-#include <netatalk/endian.h>
-
-#include <atalk/netddp.h>
-#include <atalk/atp.h>
-#include <atalk/util.h>
-
-#include "atp_internals.h"
-
-/*
- * ah:        open atp handle
- * atpb:      parameter block
- * respcount: buffers available for response
- * flags:     ATP_XO, ATP_TREL
- */
-int
-atp_sreq( ATP ah, struct atp_block *atpb, int respcount, u_int8_t flags )
-{
-    struct atpbuf      *req_buf;
-    int                        i;
-
-#ifdef EBUG
-    atp_print_bufuse( ah, "atp_sreq" );
-#endif /* EBUG */
-
-    /* check parameters
-    */
-    if ( atpb->atp_sreqdlen < 4 || atpb->atp_sreqdlen > ATP_MAXDATA
-           || ( respcount < 0 ) || ( respcount > 8 )
-           || ( atpb->atp_sreqto < 0 ) || (( atpb->atp_sreqtries < 1 )
-           && ( atpb->atp_sreqtries != ATP_TRIES_INFINITE ))) {
-       errno = EINVAL;
-       return -1;
-    }
-    /* clean up any packet fragments left from last request
-    */
-    for ( i = 0; i < 8; ++i ) {
-       if ( ah->atph_resppkt[ i ] != NULL ) {
-           atp_free_buf( ah->atph_resppkt[ i ] );
-           ah->atph_resppkt[ i ] = NULL;
-       }
-    }
-
-    /* generate bitmap, tid and ctrlinfo
-    */
-    atpb->atp_bitmap = ( 1 << respcount ) - 1;
-
-    /* allocate a new buffer and build request packet
-    */
-    if (( req_buf = atp_alloc_buf()) == NULL ) {
-       return( -1 );
-    }
-    atp_build_req_packet( req_buf, ah->atph_tid++, flags | ATP_TREQ, atpb );
-    memcpy( &req_buf->atpbuf_addr, atpb->atp_saddr,
-           sizeof( struct sockaddr_at ));
-
-    /* send the initial request
-    */
-#ifdef EBUG
-    printf( "\n<%d> atp_sreq: sending a %ld byte packet ", getpid(),
-           req_buf->atpbuf_dlen );
-    atp_print_addr( " to", atpb->atp_saddr );
-    putchar( '\n' );
-    bprint( req_buf->atpbuf_info.atpbuf_data, req_buf->atpbuf_dlen );
-#endif /* EBUG */
-
-    gettimeofday( &ah->atph_reqtv, (struct timezone *)0 );
-#ifdef DROPPACKETS
-if (( random() % 3 ) != 2 ) {
-#endif /* DROPPACKETS */
-    if ( netddp_sendto( ah->atph_socket, req_buf->atpbuf_info.atpbuf_data,
-           req_buf->atpbuf_dlen, 0, (struct sockaddr *) atpb->atp_saddr,
-           sizeof( struct sockaddr_at )) != req_buf->atpbuf_dlen ) {
-       atp_free_buf( req_buf );
-       return( -1 );
-    }
-#ifdef DROPPACKETS
-} else printf( "<%d> atp_sreq: dropped request\n", getpid() );
-#endif /* DROPPACKETS */
-
-    if ( atpb->atp_sreqto != 0 ) {
-       if ( ah->atph_reqpkt != NULL ) {
-           atp_free_buf( ah->atph_reqpkt );
-       }
-       ah->atph_reqto = atpb->atp_sreqto;
-       if ( atpb->atp_sreqtries == ATP_TRIES_INFINITE ) {
-           ah->atph_reqtries = ATP_TRIES_INFINITE;
-       } else {
-           /* we already sent one */
-           ah->atph_reqtries = atpb->atp_sreqtries - 1;
-       }
-       ah->atph_reqpkt = req_buf;
-       ah->atph_rbitmap = ( 1 << respcount ) - 1;
-       ah->atph_rrespcount = respcount;
-    } else {
-       atp_free_buf( req_buf );
-       ah->atph_rrespcount = 0;
-    }
-
-    return( 0 );
-}
diff --git a/libatalk/atp/atp_sresp.c b/libatalk/atp/atp_sresp.c
deleted file mode 100644 (file)
index 781760b..0000000
+++ /dev/null
@@ -1,156 +0,0 @@
-/*
- * $Id: atp_sresp.c,v 1.6 2009-10-13 22:55:37 didg Exp $
- *
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- * All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software and
- * its documentation for any purpose and without fee is hereby granted,
- * provided that the above copyright notice appears in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation, and that the name of The University
- * of Michigan not be used in advertising or publicity pertaining to
- * distribution of the software without specific, written prior
- * permission. This software is supplied as is without expressed or
- * implied warranties of any kind.
- *
- *     Research Systems Unix Group
- *     The University of Michigan
- *     c/o Mike Clark
- *     535 W. William Street
- *     Ann Arbor, Michigan
- *     +1-313-763-0525
- *     netatalk@itd.umich.edu
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <errno.h>
-#include <sys/uio.h>
-#include <sys/time.h>
-#include <sys/socket.h>
-
-#include <netatalk/at.h>
-#include <netatalk/endian.h>
-
-#include <atalk/netddp.h>
-#include <atalk/atp.h>
-#include <atalk/util.h>
-
-#include "atp_internals.h"
-
-/* send a transaction response
-*/
-int atp_sresp(
-    ATP                        ah,             /* open atp handle */
-    struct atp_block   *atpb)          /* parameter block */
-{
-    int                        i;
-    u_int8_t           ctrlinfo;
-    struct atpbuf      *resp_buf;
-    struct atpbuf      *save_buf; /* uninitialized, OK 310105 */
-
-#ifdef EBUG
-    atp_print_bufuse( ah, "atp_sresp" );
-#endif /* EBUG */
-
-    /* check parameters
-    */
-    for ( i = atpb->atp_sresiovcnt - 1; i >= 0; --i ) {
-       if ( atpb->atp_sresiov[ i ].iov_len > ATP_MAXDATA ) 
-           break;
-    }
-    if ( i >= 0 || atpb->atp_sresiovcnt < 1 || atpb->atp_sresiovcnt > 8 ) {
-       errno = EINVAL;
-       return -1;
-    }
-
-    /* allocate a new buffer for reponse packet construction
-    */
-    if (( resp_buf = atp_alloc_buf()) == NULL ) {
-       return -1;
-    }
-
-    /* send all the response packets
-     * also need to attach list to ah for dup. detection (if XO)
-    */
-#ifdef EBUG
-    printf( "<%d> preparing to send %s response tid=%hu ", getpid(),
-           ah->atph_rxo ? "XO" : "", ah->atph_rtid );
-    atp_print_addr( " to", atpb->atp_saddr );
-    putchar( '\n' );
-#endif /* EBUG */
-    if ( ah->atph_rxo ) {
-       if (( save_buf = atp_alloc_buf()) == NULL ) {
-           return -1;
-       }
-       for ( i = 0; i < 8;
-               save_buf->atpbuf_info.atpbuf_xo.atpxo_packet[ i++ ] = NULL );
-    }
-    for ( i = 0; i < atpb->atp_sresiovcnt; ++i ) {
-       ctrlinfo = ATP_TRESP;
-#ifdef STS_RESPONSES
-       ctrlinfo |= ATP_STS;
-#endif /* STS_RESPONSES */
-       if ( i == atpb->atp_sresiovcnt-1 ) {
-           ctrlinfo |= ATP_EOM;
-       }
-       atp_build_resp_packet( resp_buf, ah->atph_rtid, ctrlinfo, atpb, i );
-
-       if ( ah->atph_rxo ) {
-           save_buf->atpbuf_info.atpbuf_xo.atpxo_packet[i] = resp_buf;
-       }
-#ifdef DROPPACKETS
-if (( random() % 3 ) != 2 ) {
-#endif /* DROPPACKETS */
-#ifdef EBUG
-printf( "<%d> sending packet tid=%hu serial no.=%d\n", getpid(),
-  ah->atph_rtid, i );
-bprint( resp_buf->atpbuf_info.atpbuf_data, resp_buf->atpbuf_dlen );
-#endif /* EBUG */
-       if ( netddp_sendto( ah->atph_socket, resp_buf->atpbuf_info.atpbuf_data,
-         resp_buf->atpbuf_dlen, 0, (struct sockaddr *) atpb->atp_saddr,
-         sizeof( struct sockaddr_at )) != resp_buf->atpbuf_dlen ) {
-           if ( ah->atph_rxo ) {
-               for ( ; i >= 0; --i ) {
-                   atp_free_buf( save_buf->atpbuf_info.atpbuf_xo.atpxo_packet[ i ] );
-               }
-               atp_free_buf( save_buf );
-           }
-           return -1;
-       }
-#ifdef DROPPACKETS
-} else printf( "<%d> atp_sresp: dropped serial no. %d\n", getpid(),  i );
-#endif /* DROPPACKETS */
-       /* allocate a buffer for next packet (if XO mode)
-       */
-       if ( ah->atph_rxo && ( resp_buf = atp_alloc_buf()) == NULL ) {
-           return -1;
-       }
-    }
-    atp_free_buf( resp_buf );
-    if ( ah->atph_rxo ) {
-       /* record timestamp, tid, release time, and destination address
-       */
-       gettimeofday( &save_buf->atpbuf_info.atpbuf_xo.atpxo_tv,
-               (struct timezone *) 0 );
-       save_buf->atpbuf_info.atpbuf_xo.atpxo_tid = ah->atph_rtid;
-       save_buf->atpbuf_info.atpbuf_xo.atpxo_reltime = ah->atph_rreltime;
-       memcpy( &save_buf->atpbuf_addr, atpb->atp_saddr, 
-               sizeof( struct sockaddr_at ));
-
-       /* add to list of packets we have sent
-       */
-       save_buf->atpbuf_next = ah->atph_sent;
-       ah->atph_sent = save_buf;
-#ifdef EBUG
-printf( "<%d> saved XO response\n", getpid());
-#endif /* EBUG */
-    }
-    return 0;
-}
index 97649a7cb2b589f289a6aa7ea0062670b0b65de7..d6b17278abd378865158d88cfaa9bd2f5c3ff6aa 100644 (file)
@@ -6,12 +6,10 @@
 #ifndef _ATALK_CNID_CDB__H
 #define _ATALK_CNID_CDB__H 1
 
-#include <sys/cdefs.h>
 #include <sys/stat.h>
 #include <unistd.h>
 #include <string.h>
 
-#include <netatalk/endian.h>
 #include <atalk/cnid.h>
 
 /* cnid_open.c */
@@ -22,19 +20,19 @@ extern struct _cnid_db *cnid_cdb_open (struct cnid_open_args *args);
 extern void cnid_cdb_close (struct _cnid_db *);
 
 /* cnid_add.c */
-extern cnid_t cnid_cdb_add (struct _cnid_db *, const struct stat *, const cnid_t,
-                           char *, const size_t, cnid_t);
+extern cnid_t cnid_cdb_add (struct _cnid_db *, const struct stat *, cnid_t,
+                            const char *, size_t, cnid_t);
 extern int cnid_cdb_getstamp (struct _cnid_db *, void *, const size_t );
 
 /* cnid_get.c */
-extern cnid_t cnid_cdb_get (struct _cnid_db *, const cnid_t, char *, const size_t); 
+extern cnid_t cnid_cdb_get (struct _cnid_db *, cnid_t, const char *, size_t); 
 extern char *cnid_cdb_resolve (struct _cnid_db *, cnid_t *, void *, size_t ); 
-extern cnid_t cnid_cdb_lookup (struct _cnid_db *, const struct stat *, const cnid_t,
-                              char *, const size_t);
+extern cnid_t cnid_cdb_lookup (struct _cnid_db *, const struct stat *, cnid_t,
+                               const char *, size_t);
 
 /* cnid_update.c */
-extern int cnid_cdb_update (struct _cnid_db *, const cnid_t, const struct stat *,
-                           const cnid_t, char *, size_t);
+extern int cnid_cdb_update (struct _cnid_db *, cnid_t, const struct stat *,
+                            cnid_t, const char *, size_t);
 
 /* cnid_delete.c */
 extern int cnid_cdb_delete (struct _cnid_db *, const cnid_t);
@@ -46,7 +44,7 @@ extern int cnid_cdb_lock   (void *);
 extern int cnid_cdb_unlock (void *);
 
 extern cnid_t cnid_cdb_rebuild_add (struct _cnid_db *, const struct stat *,
-                const cnid_t, char *, const size_t, cnid_t);
+                                    cnid_t, const char *, size_t, cnid_t);
 
 
 #endif /* include/atalk/cnid_cdb.h */
index 418f68cd647cf1fabf777963ef95b71a96537ad5..a1e69a76ac5446a37afde531b208c9cbdc1a46bf 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: cnid_cdb_add.c,v 1.8 2009-11-20 17:22:11 didg Exp $
- *
  * Copyright (c) 1999. Adrian Sun (asun@zoology.washington.edu)
  * All Rights Reserved. See COPYRIGHT.
  *
 #endif /* HAVE_CONFIG_H */
 
 #ifdef CNID_BACKEND_CDB
+#include <arpa/inet.h>
 #include "cnid_cdb_private.h"
 
-extern int cnid_cdb_update(struct _cnid_db *cdb, const cnid_t id, const struct stat *st,
-                const cnid_t did, char *name, const size_t len);
-
+extern int cnid_cdb_update(struct _cnid_db *cdb, cnid_t id, const struct stat *st,
+                           cnid_t did, const char *name, size_t len);
 
 #define tid    NULL
 
@@ -168,8 +166,7 @@ cleanup:
 
 /* ------------------------ */
 cnid_t cnid_cdb_add(struct _cnid_db *cdb, const struct stat *st,
-                const cnid_t did, char *name, const size_t len,
-                cnid_t hint)
+                    cnid_t did, const char *name, size_t len, cnid_t hint)
 {
     CNID_private *db;
     DBT key, data;
index e95033737544619d8b2a720ff8590884673ce891..1d14640af1fb68c77b2e9903a07385a36e47b619 100644 (file)
@@ -12,6 +12,7 @@
 #endif /* HAVE_CONFIG_H */
 
 #ifdef CNID_BACKEND_CDB
+#include <arpa/inet.h>
 #include "cnid_cdb_private.h"
 
 #define tid    NULL
index 5ae4ea02f0ef29fd6de9971f7e19967f83b111fa..d4e090550eab6f85e3de0aa6671f7aa7d6006453 100644 (file)
@@ -1,7 +1,3 @@
-/*
- * $Id: cnid_cdb_get.c,v 1.5 2009-10-29 13:38:16 didg Exp $
- */
-
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif /* HAVE_CONFIG_H */
@@ -10,8 +6,7 @@
 #include "cnid_cdb_private.h"
 
 /* Return CNID for a given did/name. */
-cnid_t cnid_cdb_get(struct _cnid_db *cdb, const cnid_t did, char *name,
-                const size_t len)
+cnid_t cnid_cdb_get(struct _cnid_db *cdb, cnid_t did, const char *name, size_t len)
 {
     char start[CNID_DID_LEN + MAXPATHLEN + 1], *buf;
     CNID_private *db;
index 07de091067fb3b561925e4003f5f2d3831d353b1..7b2f933c5182b4e1c4d4974f5a46c3bd7aa695ac 100644 (file)
@@ -1,7 +1,3 @@
-/*
- * $Id: cnid_cdb_lookup.c,v 1.6 2009-11-20 17:22:11 didg Exp $
- */
-
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif /* HAVE_CONFIG_H */
@@ -14,8 +10,8 @@
 
 /* This returns the CNID corresponding to a particular file.  It will
  * also fix up the various databases if there's a problem. */
-cnid_t cnid_cdb_lookup(struct _cnid_db *cdb, const struct stat *st, const cnid_t did,
-                   char *name, const size_t len)
+cnid_t cnid_cdb_lookup(struct _cnid_db *cdb, const struct stat *st, cnid_t did,
+                       const char *name, size_t len)
 {
     unsigned char *buf;
     CNID_private *db;
index 10ecc78d8c34efaf51365820954b1ff5d06c0f6a..056420dad099f1123a6e514f98630055d285fa3a 100644 (file)
 
 static char *old_dbfiles[] = {"cnid.db", NULL};
 
-/* -----------------------
- * bandaid for LanTest performance pb. for now not used, cf. ifdef 0 below
-*/
-static int my_yield(void)
-{
-    struct timeval t;
-    int ret;
-
-    t.tv_sec = 0;
-    t.tv_usec = 1000;
-    ret = select(0, NULL, NULL, NULL, &t);
-    return 0;
-}
-
 /* --------------- */
 static int didname(DB *dbp _U_, const DBT *pkey _U_, const DBT *pdata, DBT *skey)
 {
@@ -368,7 +354,6 @@ struct _cnid_db *cnid_cdb_open(struct cnid_open_args *args)
         }
     }
 
-    db_env_set_func_yield(my_yield);
     return cdb;
 
   fail_appinit:
index 1373f5cb01d4f273b46e60d5c95e8922edbfbbc9..ff28be84c9d399e309837bb0257fcf792d67a22c 100644 (file)
@@ -1,7 +1,3 @@
-/*
- * $Id: cnid_cdb_private.h,v 1.7 2009-11-20 17:22:11 didg Exp $
- */
-
 #ifndef LIBATALK_CDB_PRIVATE_H
 #define LIBATALK_CDB_PRIVATE_H 1
 
@@ -9,26 +5,17 @@
 #include "config.h"
 #endif /* HAVE_CONFIG_H */
 
-#include <netatalk/endian.h>
-
-#ifdef HAVE_UNISTD_H
 #include <unistd.h>
-#endif /* HAVE_UNISTD_H */
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
-#ifdef HAVE_FCNTL_H
 #include <fcntl.h>
-#endif /* HAVE_FCNTL_H */
 #include <sys/param.h>
 #include <sys/stat.h>
-#ifdef HAVE_SYS_TIME_H
 #include <sys/time.h>
-#endif /* HAVE_SYS_TIME_H */
-#ifdef HAVE_TIME_H
 #include <time.h>
-#endif
-#include <sys/cdefs.h>
+#include <arpa/inet.h>
+
 #include <db.h>
 
 #include <atalk/logger.h>
index 351f31536073982a4b3f08be5e1b40f61fec8f21..be2db1023692be7e7d966b76e23d1773b37ee1a0 100644 (file)
@@ -73,10 +73,8 @@ cleanup:
     return CNID_INVALID;
 }
 
-/* ------------------------ */
 cnid_t cnid_cdb_rebuild_add(struct _cnid_db *cdb, const struct stat *st,
-                const cnid_t did, char *name, const size_t len, 
-               cnid_t hint)
+                            cnid_t did, const char *name, size_t len, cnid_t hint)
 {
     CNID_private *db;
     DBT key, data;
index f1a4a30dc48b24f6bedbbca48d7d034f81d57615..f7676c840054516c10be062dae3e874719b7e23e 100644 (file)
@@ -1,7 +1,3 @@
-/*
- * $Id: cnid_cdb_update.c,v 1.4 2009-11-20 17:22:11 didg Exp $
- */
-
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif /* HAVE_CONFIG_H */
@@ -14,9 +10,8 @@
 /* cnid_update: takes the given cnid and updates the metadata.  To
  * handle the did/name data, there are a bunch of functions to get
  * and set the various fields. */
-int cnid_cdb_update(struct _cnid_db *cdb, const cnid_t id, const struct stat *st,
-                const cnid_t did, char *name, const size_t len
-                /*, const char *info, const int infolen*/)
+int cnid_cdb_update(struct _cnid_db *cdb, cnid_t id, const struct stat *st,
+                    cnid_t did, const char *name, size_t len)
 {
     unsigned char *buf;
     CNID_private *db;
index 8bb6373ee373e91acd57912a71414b3eebaafc30..0a977e6ae8a5f4f469b48b7b037e1811d370ba76 100644 (file)
@@ -29,6 +29,7 @@
 #include <atalk/list.h>
 #include <atalk/logger.h>
 #include <atalk/util.h>
+#include <atalk/compat.h>
 
 /* List of all registered modules. */
 static struct list_head modules = ATALK_LIST_HEAD_INIT(modules);
@@ -161,7 +162,7 @@ struct _cnid_db *cnid_open(const char *volpath, mode_t mask, char *type, int fla
 }
 
 /* ------------------- */
-static void block_signal( u_int32_t flags)
+static void block_signal(uint32_t flags)
 {
     if ((flags & CNID_FLAG_BLOCK)) {
         pthread_sigmask(SIG_BLOCK, &sigblockset, NULL);
@@ -169,7 +170,7 @@ static void block_signal( u_int32_t flags)
 }
 
 /* ------------------- */
-static void unblock_signal(u_int32_t flags)
+static void unblock_signal(uint32_t flags)
 {
     if ((flags & CNID_FLAG_BLOCK)) {
         pthread_sigmask(SIG_UNBLOCK, &sigblockset, NULL);
@@ -199,7 +200,7 @@ static cnid_t valide(cnid_t id)
 /* Closes CNID database. Currently it's just a wrapper around db->cnid_close(). */
 void cnid_close(struct _cnid_db *db)
 {
-u_int32_t flags;
+    uint32_t flags;
 
     if (NULL == db) {
         LOG(log_error, logtype_afpd, "Error: cnid_close called with NULL argument !");
index 4c45eb1dc9c6a7492a9d50b078dc514bf249b4fb..0d105ea920810801f99ce8d5bfa41c4717bd8197 100644 (file)
 #ifdef CNID_BACKEND_DBD
 
 #include <stdlib.h>
-#ifdef HAVE_SYS_STAT_H
 #include <sys/stat.h>
-#endif /* HAVE_SYS_STAT_H */
-#ifdef HAVE_SYS_UIO_H
 #include <sys/uio.h>
-#endif /* HAVE_SYS_UIO_H */
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif
 #include <sys/time.h>
 #include <sys/un.h>
 #include <sys/socket.h>
@@ -33,8 +26,8 @@
 #include <errno.h>
 #include <netdb.h>
 #include <time.h>
+#include <arpa/inet.h>
 
-#include <netatalk/endian.h>
 #include <atalk/logger.h>
 #include <atalk/adouble.h>
 #include <atalk/cnid.h>
@@ -273,7 +266,7 @@ static int send_packet(CNID_private *db, struct cnid_dbd_rqst *rqst)
     vecs = 1;
 
     if (rqst->namelen) {
-        iov[1].iov_base = rqst->name;
+        iov[1].iov_base = (char *)rqst->name;
         iov[1].iov_len  = rqst->namelen;
         towrite += rqst->namelen;
         vecs++;
@@ -538,8 +531,7 @@ void cnid_dbd_close(struct _cnid_db *cdb)
 
 /* ---------------------- */
 cnid_t cnid_dbd_add(struct _cnid_db *cdb, const struct stat *st,
-                    const cnid_t did, char *name, const size_t len,
-                    cnid_t hint)
+                    cnid_t did, const char *name, size_t len, cnid_t hint)
 {
     CNID_private *db;
     struct cnid_dbd_rqst rqst;
@@ -603,7 +595,7 @@ cnid_t cnid_dbd_add(struct _cnid_db *cdb, const struct stat *st,
 }
 
 /* ---------------------- */
-cnid_t cnid_dbd_get(struct _cnid_db *cdb, const cnid_t did, char *name, const size_t len)
+cnid_t cnid_dbd_get(struct _cnid_db *cdb, cnid_t did, const char *name, size_t len)
 {
     CNID_private *db;
     struct cnid_dbd_rqst rqst;
@@ -729,8 +721,8 @@ int cnid_dbd_getstamp(struct _cnid_db *cdb, void *buffer, const size_t len)
 }
 
 /* ---------------------- */
-cnid_t cnid_dbd_lookup(struct _cnid_db *cdb, const struct stat *st, const cnid_t did,
-                       char *name, const size_t len)
+cnid_t cnid_dbd_lookup(struct _cnid_db *cdb, const struct stat *st, cnid_t did,
+                       const char *name, size_t len)
 {
     CNID_private *db;
     struct cnid_dbd_rqst rqst;
@@ -791,7 +783,7 @@ cnid_t cnid_dbd_lookup(struct _cnid_db *cdb, const struct stat *st, const cnid_t
 }
 
 /* ---------------------- */
-int cnid_dbd_find(struct _cnid_db *cdb, char *name, size_t namelen, void *buffer, size_t buflen)
+int cnid_dbd_find(struct _cnid_db *cdb, const char *name, size_t namelen, void *buffer, size_t buflen)
 {
     CNID_private *db;
     struct cnid_dbd_rqst rqst;
@@ -846,8 +838,8 @@ int cnid_dbd_find(struct _cnid_db *cdb, char *name, size_t namelen, void *buffer
 }
 
 /* ---------------------- */
-int cnid_dbd_update(struct _cnid_db *cdb, const cnid_t id, const struct stat *st,
-                    const cnid_t did, char *name, const size_t len)
+int cnid_dbd_update(struct _cnid_db *cdb, cnid_t id, const struct stat *st,
+                    cnid_t did, const char *name, size_t len)
 {
     CNID_private *db;
     struct cnid_dbd_rqst rqst;
@@ -901,8 +893,7 @@ int cnid_dbd_update(struct _cnid_db *cdb, const cnid_t id, const struct stat *st
 
 /* ---------------------- */
 cnid_t cnid_dbd_rebuild_add(struct _cnid_db *cdb, const struct stat *st,
-                            const cnid_t did, char *name, const size_t len,
-                            cnid_t hint)
+                            cnid_t did, const char *name, size_t len, cnid_t hint)
 {
     CNID_private *db;
     struct cnid_dbd_rqst rqst;
index 1f645908358b442633beae7e730e9789be690975..fdba4c042a62591e3e771ed449ad7de6588986ca 100644 (file)
@@ -8,31 +8,30 @@
 #ifndef _ATALK_CNID_DBD__H
 #define _ATALK_CNID_DBD__H 1
 
-#include <sys/cdefs.h>
 #include <sys/stat.h>
 #include <unistd.h>
 #include <string.h>
+#include <arpa/inet.h>
 
-#include <netatalk/endian.h>
 #include <atalk/cnid.h>
 
 extern struct _cnid_module cnid_dbd_module;
 extern struct _cnid_db *cnid_dbd_open (struct cnid_open_args *args);
 extern void   cnid_dbd_close      (struct _cnid_db *);
-extern cnid_t cnid_dbd_add        (struct _cnid_db *, const struct stat *, const cnid_t,
-                                   char *, const size_t, cnid_t);
-extern cnid_t cnid_dbd_get        (struct _cnid_db *, const cnid_t, char *, const size_t); 
+extern cnid_t cnid_dbd_add        (struct _cnid_db *, const struct stat *, cnid_t,
+                                   const char *, size_t, cnid_t);
+extern cnid_t cnid_dbd_get        (struct _cnid_db *, cnid_t, const char *, size_t); 
 extern char  *cnid_dbd_resolve    (struct _cnid_db *, cnid_t *, void *, size_t ); 
 extern int    cnid_dbd_getstamp   (struct _cnid_db *, void *, const size_t ); 
-extern cnid_t cnid_dbd_lookup     (struct _cnid_db *, const struct stat *, const cnid_t,
-                                   char *, const size_t);
-extern int    cnid_dbd_find       (struct _cnid_db *cdb, char *name, size_t namelen,
+extern cnid_t cnid_dbd_lookup     (struct _cnid_db *, const struct stat *, cnid_t,
+                                   const char *, size_t);
+extern int    cnid_dbd_find       (struct _cnid_db *cdb, const char *name, size_t namelen,
                                    void *buffer, size_t buflen);
-extern int    cnid_dbd_update     (struct _cnid_db *, const cnid_t, const struct stat *,
-                                   const cnid_t, char *, size_t);
+extern int    cnid_dbd_update     (struct _cnid_db *, cnid_t, const struct stat *,
+                                   cnid_t, const char *, size_t);
 extern int    cnid_dbd_delete     (struct _cnid_db *, const cnid_t);
 extern cnid_t cnid_dbd_rebuild_add(struct _cnid_db *, const struct stat *,
-                                   const cnid_t, char *, const size_t, cnid_t);
+                                   cnid_t, const char *, size_t, cnid_t);
 
 /* FIXME: These functions could be static in cnid_dbd.c */
 
index 5502fb60f94c49836b9de1cd62005ebdeec7f841..5903d03fe449da281238818e9501c57e812cf9f1 100644 (file)
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
+#include <arpa/inet.h>
 
 /* ------------------------ */
 cnid_t cnid_last_add(struct _cnid_db *cdb, const struct stat *st,
-                     const cnid_t did _U_, char *name _U_, const size_t len _U_, cnid_t hint _U_)
+                     cnid_t did _U_, const char *name _U_, size_t len _U_, cnid_t hint _U_)
 {
 
     /* FIXME: it relies on fact, that this is never called twice for the same file/dir. */
@@ -86,9 +87,8 @@ int cnid_last_delete(struct _cnid_db *cdb _U_, const cnid_t id _U_)
 }
 
 
-
 /* Return CNID for a given did/name. */
-cnid_t cnid_last_get(struct _cnid_db *cdb _U_, const cnid_t did _U_, char *name _U_, const size_t len _U_)
+cnid_t cnid_last_get(struct _cnid_db *cdb _U_, cnid_t did _U_, const char *name _U_, size_t len _U_)
 {
     /* FIXME: it relies on fact, that this is never called twice for the same file/dir. */
     /* Propably we should look through DID tree. */
@@ -96,10 +96,9 @@ cnid_t cnid_last_get(struct _cnid_db *cdb _U_, const cnid_t did _U_, char *name
 }
 
 
-
 /* */
-cnid_t cnid_last_lookup(struct _cnid_db *cdb _U_, const struct stat *st _U_, const cnid_t did _U_, 
-    char *name _U_, const size_t len _U_)
+cnid_t cnid_last_lookup(struct _cnid_db *cdb _U_, const struct stat *st _U_, cnid_t did _U_, 
+                        const char *name _U_, size_t len _U_)
 {
     /* FIXME: this function doesn't work in [last] scheme ! */
     /* Should be never called or CNID should be somewhat refactored again. */
@@ -175,8 +174,8 @@ char *cnid_last_resolve(struct _cnid_db *cdb _U_, cnid_t * id _U_, void *buffer
 }
 
 
-int cnid_last_update(struct _cnid_db *cdb _U_, const cnid_t id _U_, const struct stat *st _U_,
-                     const cnid_t did  _U_, char *name  _U_, const size_t len _U_)
+int cnid_last_update(struct _cnid_db *cdb _U_, cnid_t id _U_, const struct stat *st _U_,
+                     cnid_t did  _U_, const char *name  _U_, size_t len _U_)
 {
     return 0;
 }
index fdcf32a5cc524fc74e4abba68670d4ef792b20a4..7fce6e7268d04462cd7506d5bc4b8981c4ca48d5 100644 (file)
@@ -1,4 +1,3 @@
-
 /* 
  * interface for database access to cnids. i do it this way to abstract
  * things a bit in case we want to change the underlying implementation.
@@ -7,12 +6,10 @@
 #ifndef _ATALK_CNID_LAST__H
 #define _ATALK_CNID_LAST__H 1
 
-#include <sys/cdefs.h>
 #include <sys/stat.h>
 #include <unistd.h>
 #include <string.h>
 
-#include <netatalk/endian.h>
 #include <atalk/cnid.h>
 
 struct _cnid_last_private {
@@ -22,13 +19,13 @@ struct _cnid_last_private {
 extern struct _cnid_module cnid_last_module;
 extern struct _cnid_db *cnid_last_open (struct cnid_open_args *args);
 extern void cnid_last_close (struct _cnid_db *);
-extern cnid_t cnid_last_add (struct _cnid_db *, const struct stat *, const cnid_t,
-                                 char *, const size_t, cnid_t);
-extern cnid_t cnid_last_get (struct _cnid_db *, const cnid_t, char *, const size_t);
+extern cnid_t cnid_last_add (struct _cnid_db *, const struct stat *, cnid_t,
+                             const char *, size_t, cnid_t);
+extern cnid_t cnid_last_get (struct _cnid_db *, cnid_t, const char *, size_t);
 extern char *cnid_last_resolve (struct _cnid_db *, cnid_t *, void *, size_t);
-extern cnid_t cnid_last_lookup (struct _cnid_db *, const struct stat *, const cnid_t, char *, const size_t);
-extern int cnid_last_update (struct _cnid_db *, const cnid_t, const struct stat *,
-                                 const cnid_t, char *, size_t);
-extern int cnid_last_delete (struct _cnid_db *, const cnid_t);
+extern cnid_t cnid_last_lookup (struct _cnid_db *, const struct stat *, cnid_t, const char *, size_t);
+extern int cnid_last_update (struct _cnid_db *, cnid_t, const struct stat *,
+                             cnid_t, const char *, size_t);
+extern int cnid_last_delete (struct _cnid_db *, cnid_t);
 
 #endif /* include/atalk/cnid_last.h */
index 1f7a08e6336dfb2ad6274dbac77c165c0e9fd11d..64cc214b65902fb13aa439339ab28e52f2444dca 100644 (file)
@@ -6,14 +6,12 @@
 #ifndef _ATALK_CNID_TDB__H
 #define _ATALK_CNID_TDB__H 1
 
-#include <sys/cdefs.h>
 #include <sys/stat.h>
 #include <unistd.h>
 #include <string.h>
-
 #include <sys/param.h>
+#include <arpa/inet.h>
 
-#include <netatalk/endian.h>
 #include <atalk/cnid.h>
 #include <atalk/cnid_private.h>
 #define STANDALONE 1
@@ -53,17 +51,17 @@ extern struct _cnid_db *cnid_tdb_open (struct cnid_open_args *args);
 extern void cnid_tdb_close (struct _cnid_db *);
 
 /* cnid_add.c */
-extern cnid_t cnid_tdb_add (struct _cnid_db *, const struct stat *, const cnid_t,
-                                 char *, const size_t, cnid_t);
+extern cnid_t cnid_tdb_add (struct _cnid_db *, const struct stat *, cnid_t,
+                            const char *, size_t, cnid_t);
 
 /* cnid_get.c */
-extern cnid_t cnid_tdb_get (struct _cnid_db *, const cnid_t, char *, const size_t);
+extern cnid_t cnid_tdb_get (struct _cnid_db *, cnid_t, const char *, size_t);
 extern char *cnid_tdb_resolve (struct _cnid_db *, cnid_t *, void *, size_t);
-extern cnid_t cnid_tdb_lookup (struct _cnid_db *, const struct stat *, const cnid_t, char *, const size_t);
+extern cnid_t cnid_tdb_lookup (struct _cnid_db *, const struct stat *, cnid_t, const char *, size_t);
 
 /* cnid_update.c */
-extern int cnid_tdb_update (struct _cnid_db *, const cnid_t, const struct stat *,
-                                 const cnid_t, char *, size_t);
+extern int cnid_tdb_update (struct _cnid_db *, cnid_t, const struct stat *,
+                            cnid_t, const char *, size_t);
 
 /* cnid_delete.c */
 extern int cnid_tdb_delete (struct _cnid_db *, const cnid_t);
@@ -72,6 +70,6 @@ extern int cnid_tdb_delete (struct _cnid_db *, const cnid_t);
 extern cnid_t cnid_tdb_nextid (struct _cnid_db *);
 
 /* construct db_cnid data. NOTE: this is not re-entrant.  */
-extern unsigned char *make_tdb_data(u_int32_t flags, const struct stat *st, const cnid_t did, const char *name, const size_t len);
+extern unsigned char *make_tdb_data(uint32_t flags, const struct stat *st, const cnid_t did, const char *name, const size_t len);
 
 #endif /* include/atalk/cnid_tdb.h */
index 5758300c2e528c6b8a513b086fb8a4fb4a43e1e9..fcb43fa2f6488d5d725a79ee43cec230571e96a3 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: cnid_tdb_add.c,v 1.4 2009-11-20 17:37:14 didg Exp $
- *
  * Copyright (c) 1999. Adrian Sun (asun@zoology.washington.edu)
  * All Rights Reserved. See COPYRIGHT.
  *
@@ -40,12 +38,12 @@ static void make_devino_data(unsigned char *buf, dev_t dev, ino_t ino)
     buf[CNID_DEV_LEN + CNID_INO_LEN - 8] = ino;    
 }
 
-unsigned char *make_tdb_data(u_int32_t flags, const struct stat *st,const cnid_t did,
+unsigned char *make_tdb_data(uint32_t flags, const struct stat *st,const cnid_t did,
                      const char *name, const size_t len)
 {
     static unsigned char start[CNID_HEADER_LEN + MAXPATHLEN + 1];
     unsigned char *buf = start  +CNID_LEN;
-    u_int32_t i;
+    uint32_t i;
 
     if (len > MAXPATHLEN)
         return NULL;
@@ -154,7 +152,7 @@ cleanup:
 
 /* ------------------------ */
 cnid_t cnid_tdb_add(struct _cnid_db *cdb, const struct stat *st,
-                     const cnid_t did, char *name, const size_t len, cnid_t hint)
+                    cnid_t did, const char *name, size_t len, cnid_t hint)
 {
     const struct stat *lstp;
     cnid_t id;
index 019eea5287567c7a024f2f038f0a7c6f0f4de360..8321d04e868eb20469c061bd08c0057c7dacc7ae 100644 (file)
@@ -1,7 +1,3 @@
-/*
- * $Id: cnid_tdb_get.c,v 1.4 2009-11-20 17:37:14 didg Exp $
- */
-
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -11,7 +7,7 @@
 #include "cnid_tdb.h"
 
 /* Return CNID for a given did/name. */
-cnid_t cnid_tdb_get(struct _cnid_db *cdb, const cnid_t did, char *name, const size_t len)
+cnid_t cnid_tdb_get(struct _cnid_db *cdb, cnid_t did, const char *name, size_t len)
 {
     char start[CNID_DID_LEN + MAXPATHLEN + 1], *buf;
     struct _cnid_tdb_private *db;
index ba47e36837f197c42f6b302f0a22ed78ca68e77c..f095cd54b9c989e186e66360177b0c4bc4f8110a 100644 (file)
@@ -1,7 +1,3 @@
-/*
- * $Id: cnid_tdb_lookup.c,v 1.6 2009-11-21 11:12:49 didg Exp $
- */
-
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -11,7 +7,7 @@
 #include "cnid_tdb.h"
 #include <atalk/logger.h>
 
-cnid_t cnid_tdb_lookup(struct _cnid_db *cdb, const struct stat *st, const cnid_t did, char *name, const size_t len)
+cnid_t cnid_tdb_lookup(struct _cnid_db *cdb, const struct stat *st, cnid_t did, const char *name, size_t len)
 {
     char *buf;
     struct _cnid_tdb_private *db;
@@ -19,9 +15,9 @@ cnid_t cnid_tdb_lookup(struct _cnid_db *cdb, const struct stat *st, const cnid_t
     int devino = 1, didname = 1;
     char dev[CNID_DEV_LEN];
     char ino[CNID_INO_LEN];  
-    u_int32_t type_devino  = (unsigned)-1;
-    u_int32_t type_didname = (unsigned)-1;
-    u_int32_t type;
+    uint32_t type_devino  = (unsigned)-1;
+    uint32_t type_didname = (unsigned)-1;
+    uint32_t type;
     int update = 0;
     cnid_t id_devino = 0, id_didname = 0,id = 0;
 
index d658b94ae25f785399da7175bd3cc67a5f206d69..d02ef0bcc054caa1da65ab3ccfa5f6c5885a8b5a 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: cnid_tdb_open.c,v 1.8 2010-03-31 09:47:32 franklahm Exp $
- *
  * Copyright (c) 1999. Adrian Sun (asun@zoology.washington.edu)
  * All Rights Reserved. See COPYRIGHT.
  *
@@ -131,7 +129,7 @@ struct _cnid_db *cnid_tdb_open(struct cnid_open_args *args)
 
     data = tdb_fetch(db->tdb_didname, key);
     if (!data.dptr) {
-        u_int32_t version = htonl(DBVERSION);
+        uint32_t version = htonl(DBVERSION);
 
         data.dptr = (char *)&version;
         data.dsize = sizeof(version);
index 8c4d35e379dd535b7085719df8c6eb783c719d1e..d367334e06126c8f903fe8bea20d1a0d7efea0b1 100644 (file)
@@ -1,7 +1,3 @@
-/*
- * $Id: cnid_tdb_update.c,v 1.6 2009-11-21 11:12:49 didg Exp $
- */
-
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -11,9 +7,8 @@
 #include "cnid_tdb.h"
 #include <atalk/logger.h>
 
-int cnid_tdb_update(struct _cnid_db *cdb, const cnid_t id, const struct stat *st,
-                     const cnid_t did, char *name, const size_t len
-                     /*, const char *info, const int infolen */ )
+int cnid_tdb_update(struct _cnid_db *cdb, cnid_t id, const struct stat *st,
+                    cnid_t did, const char *name, size_t len)
 {
     struct _cnid_tdb_private *db;
     TDB_DATA key, data, altdata;
index 6540debf33a7eabc8f0816346a1d609e74b0fc4a..ed54763cb6958880c0a39f5c455b485f17f55e10 100644 (file)
@@ -6,10 +6,7 @@ libcompat_la_SOURCES = \
        misc.c \
        mktemp.c        \
        getusershell.c  \
-       strcasecmp.c    \
-       strstr.c        \
-       strdup.c        \
-       inet_aton.c     \
        rquota_xdr.c    \
-       pselect.c       \
-       snprintf.c
+       pselect.c               \
+       strlcpy.c               \
+       misc.c
index aa167222594dc4f087300a4a289fb3bbf7042642..0bd45a7318c871ab34c442ebc8fdaf4cad6c9cc7 100644 (file)
@@ -2,6 +2,8 @@
 #include "config.h"
 #endif /* HAVE_CONFIG_H */
 
+#include <atalk/compat.h>
+
 #if !defined HAVE_DIRFD && defined SOLARIS
 #include <dirent.h>
 int dirfd(DIR *dir)
index d72eaa7dbdb450158dbc39b896f6c3cae9bc67f3..5aa27a42b667718116c966319764e1d8b896ca77 100644 (file)
 */
 #if defined(NEED_RQUOTA) || defined(SOLARIS) || (defined(__GNU_LIBRARY__) && __GNU_LIBRARY__ < 6)
 
+#ifndef u_int
+#define u_int unsigned
+#endif
+
 #include <rpc/rpc.h>
 #include <rpcsvc/rquota.h>
 
diff --git a/libatalk/compat/snprintf.c b/libatalk/compat/snprintf.c
deleted file mode 100644 (file)
index eea7729..0000000
+++ /dev/null
@@ -1,1132 +0,0 @@
-/**************************************************************************
- * Copyright 1994-2000 Patrick Powell, San Diego, CA <papowell@astart.com>
- * 
- * Modified for Netatalk 2002/02/12 Burkhard Schmidt <bs@cpfs.mpg.de>
- **************************************************************************/
-
-/*
-   Overview:
-
-   plp_snprintf( char *buffer, int len, const char *format,...)
-   plp_unsafe_snprintf( char *buffer, int len, const char *format,...)
-     its horribly unsafe companion that does NOT protect you from
-     the printing of evil control characters,  but may be necessary
-     See the man page documentation below
-   
-   This version of snprintf was developed originally for printing
-   on a motley collection of specialized hardware that had NO IO
-   library.  Due to contractual restrictions,  a clean room implementation
-   of the printf() code had to be developed.
-   
-   The method chosen for printf was to be as paranoid as possible,
-   as these platforms had NO memory protection,  and very small
-   address spaces.  This made it possible to try to print
-   very long strings, i.e. - all of memory, very easily.  To guard
-   against this,  all printing was done via a buffer, generous enough
-   to hold strings,  but small enough to protect against overruns,
-   etc.
-   
-   Strangely enough,  this proved to be of immense importance when
-   SPRINTFing to a buffer on a stack...  The rest,  of course,  is
-   well known,  as buffer overruns in the stack are a common way to
-   do horrible things to operating systems, security, etc etc.
-   
-   This version of snprintf is VERY limited by modern standards.
-
-   Revision History:
-   First Released Version - 1994.  This version had NO comments.
-   First Released Version - 1994.  This version had NO comments.
-   Second Major Released Version - Tue May 23 10:43:44 PDT 2000
-    Configuration and other items changed.  Read this doc.
-    Treat this as a new version.
-   
-   COPYRIGHT AND TERMS OF USE:
-   
-   You may use, copy, distribute, or otherwise incorporate this software
-   and documentation into any product or other item,  provided that
-   the copyright in the documentation and source code as well as the
-   source code generated constant strings in the object, executable
-   or other code remain in place and are present in executable modules
-   or objects.
-   
-   You may modify this code as appropriate to your usage; however the
-   modified version must be identified by changing the various source
-   and object code identification strings as is appropriately noted
-   in the source code.
-   
-   The next include line is expected to work in conjunction with the
-   GNU CONFIGURE utility.  You  should define the following macros
-   appropriately:
-   
-   HAVE_STDARG_H - if the <stdargs.h> include file is available
-   HAVE_VARARG_H - if the <varargs.h> include file is available
-   
-   HAVE_STRERROR - if the strerror() routine is available.
-     If it is not available, then examine the lines containing
-     the tests below.  You may need to fiddle with HAVE_SYS_NERR
-   HAVE_SYS_ERRLIST
-   HAVE_DECL_SYS_ERRLIST
-   HAVE_SYS_NERR
-   HAVE_DECL_SYS_NERR
-   
-   HAVE_QUAD_T      - if the quad_t type is defined
-   HAVE_LONG_LONG   - if the long long type is defined
-   HAVE_LONG_DOUBLE - if the long double type is defined
-   
-     If you are using the GNU configure (autoconf) facility, add the
-     following line to the configure.in file, to force checking for the
-     quad_t and long long  data types:
-
-
-       AC_CHECK_FUNCS(strerror);
-       AC_CACHE_CHECK(for errno,
-       ac_cv_errno,
-       [
-       AC_TRY_LINK(,[extern int errno; return (errno);],
-               ac_cv_errno=yes, ac_cv_errno=no)
-       ])
-       if test "$ac_cv_errno" = yes; then
-               AC_DEFINE(HAVE_ERRNO)
-               AC_CACHE_CHECK(for errno declaration,
-               ac_cv_decl_errno,
-               [
-               AC_TRY_COMPILE([
-               #include <stdio.h>
-               #ifdef HAVE_STDLIB_H
-               #include <stdlib.h>
-               #endif
-               #ifdef HAVE_UNISTD_H
-               #include <unistd.h>
-               #endif
-               #ifdef HAVE_ERRNO_H
-               #include <errno.h>
-               ],[return(sys_nerr);],
-                       ac_cv_decl_errno=yes, ac_cv_decl_errno=no)
-               ])
-               if test "$ac_cv_decl_errno" = yes; then
-                       AC_DEFINE(HAVE_DECL_ERRNO)
-               fi;
-       fi
-
-       AC_CACHE_CHECK(for sys_nerr,
-       ac_cv_sys_nerr,
-       [
-       AC_TRY_LINK(,[extern int sys_nerr; return (sys_nerr);],
-               ac_cv_sys_nerr=yes, ac_cv_sys_nerr=no)
-       ])
-       if test "$ac_cv_sys_nerr" = yes; then
-               AC_DEFINE(HAVE_SYS_NERR)
-               AC_CACHE_CHECK(for sys_nerr declaration,
-               ac_cv_decl_sys_nerr,
-               [
-               AC_TRY_COMPILE([
-               #include <stdio.h>
-               #ifdef HAVE_STDLIB_H
-               #include <stdlib.h>
-               #endif
-               #ifdef HAVE_UNISTD_H
-               #include <unistd.h>
-               #endif],[return(sys_nerr);],
-               ac_cv_decl_sys_nerr_def=yes, ac_cv_decl_sys_nerr_def=no)
-               ])
-               if test "$ac_cv_decl_sys_nerr" = yes; then
-                       AC_DEFINE(HAVE_DECL_SYS_NERR)
-               fi
-       fi
-
-
-       AC_CACHE_CHECK(for sys_errlist array,
-       ac_cv_sys_errlist,
-       [AC_TRY_LINK(,[extern char *sys_errlist[];
-               sys_errlist[0];],
-               ac_cv_sys_errlist=yes, ac_cv_sys_errlist=no)
-       ])
-       if test "$ac_cv_sys_errlist" = yes; then
-               AC_DEFINE(HAVE_SYS_ERRLIST)
-               AC_CACHE_CHECK(for sys_errlist declaration,
-               ac_cv_sys_errlist_def,
-               [AC_TRY_COMPILE([
-               #include <stdio.h>
-               #include <errno.h>
-               #ifdef HAVE_STDLIB_H
-               #include <stdlib.h>
-               #endif
-               #ifdef HAVE_UNISTD_H
-               #include <unistd.h>
-               #endif],[char *s = sys_errlist[0]; return(*s);],
-               ac_cv_decl_sys_errlist=yes, ac_cv_decl_sys_errlist=no)
-               ])
-               if test "$ac_cv_decl_sys_errlist" = yes; then
-                       AC_DEFINE(HAVE_DECL_SYS_ERRLIST)
-               fi
-       fi
-
-
-
-       AC_CACHE_CHECK(checking for long long,
-       ac_cv_long_long,
-       [
-       AC_TRY_COMPILE([
-       #include <stdio.h>
-       #include <sys/types.h>
-       ], [printf("%d",sizeof(long long));],
-       ac_cv_long_long=yes, ac_cv_long_long=no)
-       ])
-       if test $ac_cv_long_long = yes; then
-         AC_DEFINE(HAVE_LONG_LONG)
-       fi
-
-       AC_CACHE_CHECK(checking for long double,
-       ac_cv_long_double,
-       [
-       AC_TRY_COMPILE([
-       #include <stdio.h>
-       #include <sys/types.h>
-       ], [printf("%d",sizeof(long double));],
-       ac_cv_long_double=yes, ac_cv_long_double=no)
-       ])
-       if test $ac_cv_long_double = yes; then
-         AC_DEFINE(HAVE_LONG_DOUBLE)
-       fi
-
-       AC_CACHE_CHECK(checking for quad_t,
-       ac_cv_quad_t,
-       [
-       AC_TRY_COMPILE([
-       #include <stdio.h>
-       #include <sys/types.h>
-       ], [printf("%d",sizeof(quad_t));],
-       ac_cv_quad_t=yes, ac_cv_quad_t=no)
-       ])
-       if test $ac_cv_quad_t = yes; then
-         AC_DEFINE(HAVE_QUAD_T)
-       fi
-
-
-
-NAME
-     plp_snprintf, plp_vsnprintf - formatted output conversion
-
-SYNOPSIS
-     #include <stdio.h>
-     #include <stdarg.h>
-
-     int
-     plp_snprintf(const char *format, size_t size, va_list ap);
-     int
-     plp_unsafe_snprintf(const char *format, size_t size, va_list ap);
-
-     AKA snprintf and unsafe_snprintf in the documentation below
-
-     int
-     vsnprintf(char *str, size_t size, const char *format, va_list ap);
-     int
-     unsafe_vsnprintf(char *str, size_t size, const char *format, va_list ap);
-
-     AKA vsnprintf and unsafe_vsnprintf in the documentation below
-
-     (Multithreaded Safe)
-
-DESCRIPTION
-     The printf() family of functions produces output according to
-     a format as described below.  Snprintf(), and vsnprintf()
-     write to the character string str. These functions write the
-     output under the control of a format string that specifies
-     how subsequent arguments (or arguments accessed via the
-     variable-length argument facilities of stdarg(3))  are converted
-     for output.  These functions return the number of characters
-     printed (not including the trailing `\0' used to end output
-     to strings).  Snprintf() and vsnprintf() will write at most
-     size-1 of the characters printed into the output string (the
-     size'th character then gets the terminating `\0'); if the
-     return value is greater than or equal to the size argument,
-     the string was too short and some of the printed characters
-     were discarded.  The size or str may be given as zero to find
-     out how many characters are needed; in this case, the str
-     argument is ignored.
-
-     By default, the snprintf function will not format control
-     characters (except new line and tab) in strings.  This is a
-     safety feature that has proven to be extremely critical when
-     using snprintf for secure applications and when debugging.
-     If you MUST have control characters formatted or printed,
-     then use the unsafe_snprintf() and unsafe_vsnprintf() and on
-     your own head be the consequences.  You have been warned.
-
-     There is one exception to the comments above, and that is
-     the "%c" (character) format.  It brutally assumes that the
-     user will have performed the necessary 'isprint()' or other
-     checks and uses the integer value as a character.
-
-     The format string is composed of zero or more directives:
-     ordinary characters (not %), which are copied unchanged to
-     the output stream; and conversion specifications, each
-     of which results in fetching zero or more subsequent arguments.
-     Each conversion specification is introduced by the character
-     %. The arguments must correspond properly (after type promotion)
-     with the conversion specifier.  After the %, the following
-     appear in sequence:
-
-     o   Zero or more of the following flags:
-
-          -   A zero `0' character specifying zero padding.  For
-            all conversions except n, the converted value is padded
-            on the left with zeros rather than blanks.  If a
-            precision is given with a numeric conversion (d, i,
-            o, u, i, x, and X), the `0' flag is ignored.
-
-       -   A negative field width flag `-' indicates the converted
-            value is to be left adjusted on the field boundary.  Except
-            for n conversions, the converted value is padded on
-            the right with blanks, rather than on the left with
-            blanks or zeros.  A `-' overrides a `0' if both are
-            given.
-
-          -   A space, specifying that a blank should be left before
-            a positive number produced by a signed conversion (d, e, E, f,
-            g, G, or i).
-
-          -   A `+' character specifying that a sign always be placed
-            before a number produced by a signed conversion.  A `+' overrides
-            a space if both are used.
-
-     o   An optional decimal digit string specifying a minimum
-                field width.  If the converted value has fewer
-                characters than the field width, it will be padded
-                with spaces on the left (or right, if the
-                left-adjustment flag has been given) to fill out
-                the field width.
-
-     o   An optional precision, in the form of a period `.' followed
-                by an optional digit string.  If the digit string
-                is omitted, the precision is taken as zero.  This
-                gives the minimum number of digits to appear for
-                d, i, o, u, x, and X conversions, the number of
-                digits to appear after the decimal-point for e,
-                E, and f conversions, the maximum number of
-                significant digits for g and G conversions, or
-                the maximum number of characters to be printed
-                from a string for s conversions.
-
-     o   The optional character h, specifying that a following d,
-                i, o, u, x, or X conversion corresponds to a short
-                int or unsigned short int argument, or that a
-                following n conversion corresponds to a pointer
-                to a short int argument.
-
-     o   The optional character l (ell) specifying that a following
-                d, i, o, u, x, or X conversion applies to a pointer
-                to a long int or unsigned long int argument, or
-                that a following n conversion corresponds to a
-                pointer to a long int argument.
-
-     o   The optional character q, specifying that a following d,
-                i, o, u, x, or X conversion corresponds to a quad_t
-                or u_quad_t argument, or that a following n
-                conversion corresponds to a quad_t argument.
-         This value is always printed in HEX notation.  Tough.
-         quad_t's are an OS system implementation, and should
-         not be allowed.
-
-     o   The character L specifying that a following e, E, f, g,
-                or G conversion corresponds to a long double
-                argument.
-
-     o   A character that specifies the type of conversion to be applied.
-
-
-     A field width or precision, or both, may be indicated by an asterisk `*'
-     instead of a digit string.  In this case, an int argument supplies the
-     field width or precision.  A negative field width is treated as a left
-     adjustment flag followed by a positive field width; a negative precision
-     is treated as though it were missing.
-
-     The conversion specifiers and their meanings are:
-
-     diouxX  The int (or appropriate variant) argument is converted to signed
-                        decimal (d and i), unsigned octal (o), unsigned decimal
-                        (u), or unsigned hexadecimal (x and X) notation.  The
-                        letters abcdef are used for x conversions; the letters
-                        ABCDEF are used for X conversions.  The precision, if
-                        any, gives the minimum number of digits that must
-                        appear; if the converted value requires fewer digits,
-                        it is padded on the left with zeros.
-
-     eE      The double argument is rounded and converted in the style
-             [-]d.ddde+-dd where there is one digit before the decimal-point
-                        character and the number of digits after it is equal
-                        to the precision; if the precision is missing, it is
-                        taken as 6; if the precision is zero, no decimal-point
-                        character appears.  An E conversion uses the letter
-                        E (rather than e) to introduce the exponent.
-                        The exponent always contains at least two digits; if
-                        the value is zero, the exponent is 00.
-
-     f       The double argument is rounded and converted to decimal notation
-             in the style [-]ddd.ddd, where the number of digits after the
-             decimal-point character is equal to the precision specification.
-             If the precision is missing, it is taken as 6; if the precision
-             is explicitly zero, no decimal-point character appears.  If a
-             decimal point appears, at least one digit appears before it.
-
-     g       The double argument is converted in style f or e (or
-                        E for G conversions).  The precision specifies the
-                        number of significant digits.  If the precision is
-                        missing, 6 digits are given; if the precision is zero,
-                        it is treated as 1.  Style e is used if the exponent
-                        from its conversion is less than -4 or greater than
-                        or equal to the precision.  Trailing zeros are removed
-                        from the fractional part of the result; a decimal
-                        point appears only if it is followed by at least one
-                        digit.
-
-     c       The int argument is converted to an unsigned char,
-             and the resulting character is written.
-
-     s       The ``char *'' argument is expected to be a pointer to an array
-                        of character type (pointer to a string).  Characters
-                        from the array are written up to (but not including)
-                        a terminating NUL character; if a precision is
-                        specified, no more than the number specified are
-                        written.  If a precision is given, no null character
-                        need be present; if the precision is not specified,
-                        or is greater than the size of the array, the array
-                        must contain a terminating NUL character.
-
-     %       A `%' is written. No argument is converted. The complete
-             conversion specification is `%%'.
-
-     In no case does a non-existent or small field width cause truncation of a
-     field; if the result of a conversion is wider than the field width, the
-     field is expanded to contain the conversion result.
-
-EXAMPLES
-     To print a date and time in the form `Sunday, July 3, 10:02', where
-     weekday and month are pointers to strings:
-
-           #include <stdio.h>
-           fprintf(stdout, "%s, %s %d, %.2d:%.2d\n",
-                   weekday, month, day, hour, min);
-
-     To print pi to five decimal places:
-
-           #include <math.h>
-           #include <stdio.h>
-           fprintf(stdout, "pi = %.5f\n", 4 * atan(1.0));
-
-     To allocate a 128 byte string and print into it:
-
-           #include <stdio.h>
-           #include <stdlib.h>
-           #include <stdarg.h>
-           char *newfmt(const char *fmt, ...)
-           {
-                           char *p;
-                           va_list ap;
-                           if ((p = malloc(128)) == NULL)
-                                   return (NULL);
-                           va_start(ap, fmt);
-                           (void) vsnprintf(p, 128, fmt, ap);
-                           va_end(ap);
-                           return (p);
-           }
-
-SEE ALSO
-     printf(1),  scanf(3)
-
-STANDARDS
-     Turkey C Standardization and wimpy POSIX folks did not define
-     snprintf or vsnprintf().
-
-BUGS
-     The conversion formats %D, %O, and %U are not standard and are provided
-     only for backward compatibility.  The effect of padding the %p format
-     with zeros (either by the `0' flag or by specifying a precision), and the
-     benign effect (i.e., none) of the `#' flag on %n and %p conversions, as
-     well as other nonsensical combinations such as %Ld, are not standard;
-     such combinations should be avoided.
-
-     The typedef names quad_t and u_quad_t are infelicitous.
-
-*/
-
-
-#include "config.h"
-
-#if !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF)
-
-#include <sys/types.h>
-#include <ctype.h>
-#include <stdlib.h>
-#if defined(HAVE_STRING_H)
-# include <string.h>
-#endif
-#if defined(HAVE_STRINGS_H)
-# include <strings.h>
-#endif
-#include <stdio.h>
-
-/*
- * For testing, define these values
- */
-#if 0
-#define HAVE_STDARG_H 1
-#define TEST 1
-#define HAVE_QUAD_T 1
-#endif
-
-/**** ENDINCLUDE ****/
-
-/*************************************************
- * KEEP THIS STRING - MODIFY AT THE END WITH YOUR REVISIONS
- * i.e. - the LOCAL REVISIONS part is for your use
- *************************************************/
- static char *const _id = "plp_snprintf V98.12.21 Copyright Patrick Powell 1988-2000 "
- "$Id: snprintf.c,v 1.2 2008-11-14 10:29:08 didg Exp $"
- " LOCAL REVISIONS: Modified for Netatalk 2002/02/12 Burkhard Schmidt";
-
-/* varargs declarations: */
-
-# undef HAVE_STDARGS    /* let's hope that works everywhere (mj) */
-# undef VA_LOCAL_DECL
-# undef VA_START
-# undef VA_SHIFT
-# undef VA_END
-
-#if defined(HAVE_STDARG_H)
-# include <stdarg.h>
-# define HAVE_STDARGS    /* let's hope that works everywhere (mj) */
-# define VA_LOCAL_DECL   va_list ap;
-# define VA_START(f)     va_start(ap, f)
-# define VA_SHIFT(v,t) ;       /* no-op for ANSI */
-# define VA_END          va_end(ap)
-#else
-# if defined(HAVE_VARARGS_H)
-#  include <varargs.h>
-#  undef HAVE_STDARGS
-#  define VA_LOCAL_DECL   va_list ap;
-#  define VA_START(f)     va_start(ap)         /* f is ignored! */
-#  define VA_SHIFT(v,t)        v = va_arg(ap,t)
-#  define VA_END               va_end(ap)
-# else
-XX ** NO VARARGS ** XX
-# endif
-#endif
-
-union value {
-#if defined(HAVE_QUAD_T)
-       quad_t qvalue;
-#endif
-#if defined(HAVE_LONG_LONG)
-       long long value;
-#else
-       long value;
-#endif
-       double dvalue;
-};
-
-#undef CVAL 
-#define CVAL(s) (*((unsigned char *)s))
-
-extern int errno;
- static char * plp_Errormsg ( int err, char *buffer );
- static void dopr( int visible_control, char **buffer, int *left,
-       const char *format, va_list args );
- static void fmtstr( int visible_control, char **buffer, int *left,
-       char *value, int ljust, int len, int zpad, int precision );
- static void fmtnum(  char **buffer, int *left,
-       union value *value, int base, int dosign,
-       int ljust, int len, int zpad, int precision );
-#if defined(HAVE_QUAD_T)
- static void fmtquad(  char **buffer, int *left,
-       union value *value, int base, int dosign,
-       int ljust, int len, int zpad, int precision );
-#endif
- static void fmtdouble( char **bufer, int *left,
-       int fmt, double value,
-       int ljust, int len, int zpad, int precision );
- static void dostr(  char **buffer, int *left, char *str );
- static void dopr_outch(  char **buffer, int *left, int c );
-
-int plp_vsnprintf(char *str, size_t count, const char *fmt, va_list args)
-{
-       int left;
-       char *buffer;
-       if( count < 0 ) count = 0;
-       left = count;
-       if( count == 0 ) str = 0;
-       buffer = str;
-       dopr( 1, &buffer, &left, fmt, args );
-       /* fprintf(stderr,"str 0x%x, buffer 0x%x, count %d, left %d\n",
-               (int)str, (int)buffer, count, left ); */
-       if( str && count > 0 ){
-               if( left > 0 ){
-                       str[count-left] = 0;
-               } else {
-                       str[count-1] = 0;
-               }
-       }
-       return(count - left);
-}
-
-int plp_unsafe_vsnprintf(char *str, size_t count, const char *fmt, va_list args)
-{
-       int left;
-       char *buffer;
-       if( count < 0 ) count = 0;
-       left = count;
-       if( count == 0 ) str = 0;
-       buffer = str;
-       dopr( 0, &buffer, &left, fmt, args );
-       /* fprintf(stderr,"str 0x%x, buffer 0x%x, count %d, left %d\n",
-               (int)str, (int)buffer, count, left ); */
-       if( str && count > 0 ){
-               if( left > 0 ){
-                       str[count-left] = 0;
-               } else {
-                       str[count-1] = 0;
-               }
-       }
-       return(count - left);
-}
-
-/* VARARGS3 */
-#ifdef HAVE_STDARGS
-int plp_snprintf (char *str,size_t count,const char *fmt,...)
-#else
-int plp_snprintf (va_alist) va_dcl
-#endif
-{
-#ifndef HAVE_STDARGS
-    char *str;
-       size_t count;
-    char *fmt;
-#endif
-       int n = 0;
-    VA_LOCAL_DECL
-
-    VA_START (fmt);
-    VA_SHIFT (str, char *);
-    VA_SHIFT (count, size_t );
-    VA_SHIFT (fmt, char *);
-    n = plp_vsnprintf ( str, count, fmt, ap);
-    VA_END;
-       return( n );
-}
-
-
-/* VARARGS3 */
-#ifdef HAVE_STDARGS
-int plp_unsafe_snprintf (char *str,size_t count,const char *fmt,...)
-#else
-int plp_unsafe_snprintf (va_alist) va_dcl
-#endif
-{
-#ifndef HAVE_STDARGS
-    char *str;
-       size_t count;
-    char *fmt;
-#endif
-       int n = 0;
-    VA_LOCAL_DECL
-
-    VA_START (fmt);
-    VA_SHIFT (str, char *);
-    VA_SHIFT (count, size_t );
-    VA_SHIFT (fmt, char *);
-    n = plp_unsafe_vsnprintf ( str, count, fmt, ap);
-    VA_END;
-       return( n );
-}
- static void dopr( int visible_control, char **buffer, int *left, const char *format, va_list args )
-{
-       int ch;
-       union value value;
-       int longflag = 0;
-       int quadflag = 0;
-       char *strvalue;
-       int ljust;
-       int len;
-       int zpad;
-       int precision;
-       int set_precision;
-       double dval;
-       int err = errno;
-       int base = 0;
-       int signed_val = 0;
-
-       while( (ch = *format++) ){
-               switch( ch ){
-               case '%':
-                       longflag = quadflag =
-                       ljust = len = zpad = base = signed_val = 0;
-                       precision = -1; set_precision = 0;
-               nextch: 
-                       ch = *format++;
-                       switch( ch ){
-                       case 0:
-                               dostr( buffer, left, "**end of format**" );
-                               return;
-                       case '-': ljust = 1; goto nextch;
-                       case '.': set_precision = 1; precision = 0; goto nextch;
-                       case '*': len = va_arg( args, int ); goto nextch;
-                       case '0': /* set zero padding if len not set */
-                               if(len==0 && set_precision == 0 ) zpad = '0';
-                       case '1': case '2': case '3':
-                       case '4': case '5': case '6':
-                       case '7': case '8': case '9':
-                               if( set_precision ){
-                                       precision = precision*10 + ch - '0';
-                               } else {
-                                       len = len*10 + ch - '0';
-                               }
-                               goto nextch;
-                       case 'l': ++longflag; goto nextch;
-                       case 'q':
-#if !defined( HAVE_QUAD_T )
-                                       dostr( buffer, left, "*no quad_t support *");
-                                       return;
-#endif
-                                       quadflag = 1;
-                                       goto nextch;
-                       case 'u': case 'U':
-                               if( base == 0 ){ base = 10; signed_val = 0; }
-                       case 'o': case 'O':
-                               if( base == 0 ){ base = 8; signed_val = 0; }
-                       case 'd': case 'D':
-                               if( base == 0 ){ base = 10; signed_val = 1; }
-                       case 'x':
-                               if( base == 0 ){ base = 16; signed_val = 0; }
-                       case 'X':
-                               if( base == 0 ){ base = -16; signed_val = 0; }
-#if defined( HAVE_QUAD_T )
-                               if( quadflag ){
-                                       value.qvalue = va_arg( args, quad_t );
-                                       fmtquad( buffer, left,  &value,base,signed_val, ljust, len, zpad, precision );
-                                       break;
-                               } else
-#endif
-                               if( longflag > 1 ){
-#if defined(HAVE_LONG_LONG)
-                                       if( signed_val ){
-                                       value.value = va_arg( args, long long );
-                                       } else {
-                                       value.value = va_arg( args, unsigned long long );
-                                       }
-#else
-                                       if( signed_val ){
-                                       value.value = va_arg( args, long );
-                                       } else {
-                                       value.value = va_arg( args, unsigned long );
-                                       }
-#endif
-                               } else if( longflag ){
-                                       if( signed_val ){
-                                               value.value = va_arg( args, long );
-                                       } else {
-                                               value.value = va_arg( args, unsigned long );
-                                       }
-                               } else {
-                                       if( signed_val ){
-                                               value.value = va_arg( args, int );
-                                       } else {
-                                               value.value = va_arg( args, unsigned int );
-                                       }
-                               }
-                               fmtnum( buffer, left,  &value,base,signed_val, ljust, len, zpad, precision ); break;
-                       case 's':
-                               strvalue = va_arg( args, char *);
-                               fmtstr( visible_control, buffer, left, strvalue,ljust,len, zpad, precision );
-                               break;
-                       case 'c':
-                               ch = va_arg( args, int );
-                               { char b[2];
-                                       b[0] = ch;
-                                       b[1] = 0;
-                                       fmtstr( 0, buffer, left, b,ljust,len, zpad, precision );
-                               }
-                               break;
-                       case 'f': case 'g': case 'e':
-                               dval = va_arg( args, double );
-                               fmtdouble( buffer, left, ch, dval,ljust,len, zpad, precision ); break;
-                       case 'm':
-                               { char shortbuffer[32];
-                               fmtstr( visible_control, buffer, left,
-                                       plp_Errormsg(err, shortbuffer),ljust,len, zpad, precision );
-                               }
-                               break;
-                       case '%': dopr_outch( buffer, left, ch ); continue;
-                       default:
-                               dostr(  buffer, left, "???????" );
-                       }
-                       longflag = 0;
-                       break;
-               default:
-                       dopr_outch( buffer, left, ch );
-                       break;
-               }
-       }
-}
-
-/*
- * Format '%[-]len[.precision]s'
- * -   = left justify (ljust)
- * len = minimum length
- * precision = numbers of chars in string to use
- */
- static void
-fmtstr( int visible_control, char **buffer, int *left,
-        char *value, int ljust, int len, int zpad, int precision )
-{
-       int padlen, strlenv, i, c;      /* amount to pad */
-
-       if( value == 0 ){
-               value = "<NULL>";
-       }
-       /* cheap strlen so you do not have library call */
-       for( strlenv = i = 0; (c=CVAL(value+i)); ++i ){
-               if( visible_control && iscntrl( c ) && c != '\t' && c != '\n' ){
-                       ++strlenv;
-               }
-               ++strlenv;
-       }
-       if( precision > 0 && strlenv > precision ){
-               strlenv = precision;
-       }
-       padlen = len - strlenv;
-       if( padlen < 0 ) padlen = 0;
-       if( ljust ) padlen = -padlen;
-       while( padlen > 0 ) {
-               dopr_outch( buffer, left, ' ' );
-               --padlen;
-       }
-       /* output characters */
-       for( i = 0; i < strlenv && (c = CVAL(value+i)); ++i ){
-               if( visible_control && iscntrl( c ) && c != '\t' && c != '\n' ){
-                       dopr_outch(buffer, left, '^');
-                       c = ('@' | (c & 0x1F));
-               }
-               dopr_outch(buffer, left, c);
-       }
-       while( padlen < 0 ) {
-               dopr_outch( buffer, left, ' ' );
-               ++padlen;
-       }
-}
-
- static void
-fmtnum( char **buffer, int *left,
-       union value *value, int base, int dosign, int ljust,
-       int len, int zpad, int precision )
-{
-       int signvalue = 0;
-#if defined(HAVE_LONG_LONG)
-       unsigned long long uvalue;
-#else
-       unsigned long uvalue;
-#endif
-       char convert[sizeof( union value) * 8 + 16];
-       int place = 0;
-       int padlen = 0; /* amount to pad */
-       int caps = 0;
-
-       /* fprintf(stderr,"value 0x%x, base %d, dosign %d, ljust %d, len %d, zpad %d\n",
-               value, base, dosign, ljust, len, zpad );/ **/
-       uvalue = value->value;
-       if( dosign ){
-               if( value->value < 0 ) {
-                       signvalue = '-';
-                       uvalue = -value->value; 
-               }
-       }
-       if( base < 0 ){
-               caps = 1;
-               base = -base;
-       }
-       do{
-               convert[place++] =
-                       (caps? "0123456789ABCDEF":"0123456789abcdef")
-                        [uvalue % (unsigned)base  ];
-               uvalue = (uvalue / (unsigned)base );
-       }while(uvalue);
-       convert[place] = 0;
-       padlen = len - place;
-       if( padlen < 0 ) padlen = 0;
-       if( ljust ) padlen = -padlen;
-       /* fprintf( stderr, "str '%s', place %d, sign %c, padlen %d\n",
-               convert,place,signvalue,padlen); / **/
-       if( zpad && padlen > 0 ){
-               if( signvalue ){
-                       dopr_outch( buffer, left, signvalue );
-                       --padlen;
-                       signvalue = 0;
-               }
-               while( padlen > 0 ){
-                       dopr_outch( buffer, left, zpad );
-                       --padlen;
-               }
-       }
-       while( padlen > 0 ) {
-               dopr_outch( buffer, left, ' ' );
-               --padlen;
-       }
-       if( signvalue ) dopr_outch( buffer, left, signvalue );
-       while( place > 0 ) dopr_outch( buffer, left, convert[--place] );
-       while( padlen < 0 ){
-               dopr_outch( buffer, left, ' ' );
-               ++padlen;
-       }
-}
-
-#if defined(HAVE_QUAD_T)
-
- static void
-fmtquad( char **buffer, int *left,
-       union value *value, int base, int dosign, int ljust,
-       int len, int zpad, int precision )
-{
-       int signvalue = 0;
-       int place = 0;
-       int padlen = 0; /* amount to pad */
-       int caps = 0;
-       int i, c;
-       union {
-               quad_t qvalue;
-               unsigned char qconvert[sizeof(quad_t)];
-       } vvalue;
-       char convert[2*sizeof(quad_t)+1];
-
-       /* fprintf(stderr,"value 0x%x, base %d, dosign %d, ljust %d, len %d, zpad %d\n",
-               value, base, dosign, ljust, len, zpad );/ **/
-       vvalue.qvalue = value->qvalue;
-
-       if( base < 0 ){
-               caps = 1;
-       }
-
-       for( i = 0; i < sizeof(quad_t); ++i ){
-               c = vvalue.qconvert[i];
-               convert[2*i] = 
-                       (caps? "0123456789ABCDEF":"0123456789abcdef")[ (c >> 4) & 0xF];
-               convert[2*i+1] = 
-                       (caps? "0123456789ABCDEF":"0123456789abcdef")[ c  & 0xF];
-       }
-       convert[2*i] = 0;
-
-       place = strlen(convert);
-       padlen = len - place;
-       if( padlen < 0 ) padlen = 0;
-       if( ljust ) padlen = -padlen;
-       /* fprintf( stderr, "str '%s', place %d, sign %c, padlen %d\n",
-               convert,place,signvalue,padlen); / **/
-       if( zpad && padlen > 0 ){
-               if( signvalue ){
-                       dopr_outch( buffer, left, signvalue );
-                       --padlen;
-                       signvalue = 0;
-               }
-               while( padlen > 0 ){
-                       dopr_outch( buffer, left, zpad );
-                       --padlen;
-               }
-       }
-       while( padlen > 0 ) {
-               dopr_outch( buffer, left, ' ' );
-               --padlen;
-       }
-       if( signvalue ) dopr_outch( buffer, left, signvalue );
-       while( place > 0 ) dopr_outch( buffer, left, convert[--place] );
-       while( padlen < 0 ){
-               dopr_outch( buffer, left, ' ' );
-               ++padlen;
-       }
-}
-
-#endif
-
- static void mystrcat(char *dest, char *src )
-{
-       if( dest && src ){
-               dest += strlen(dest);
-               strcpy(dest,src);
-       }
-}
-
- static void
-fmtdouble( char **buffer, int *left,
-       int fmt, double value, int ljust, int len, int zpad, int precision )
-{
-       char convert[sizeof( union value) * 8 + 16];
-       char formatstr[128];
-
-       /* fprintf(stderr,"len %d, precision %d\n", len, precision ); */
-       if( len > (sizeof(convert) - 20) ){
-               len = sizeof(convert) - 20;
-       }
-       if( precision >= 0 && precision > sizeof(convert) - 20 ){
-               precision = sizeof(convert) - 20;
-       }
-       if( precision >= 0 && precision > len ) precision = len;
-       strcpy( formatstr, "%" );
-       if( ljust ) mystrcat(formatstr, "-" );
-       if( zpad ) mystrcat(formatstr, "0" );
-       if( len ){
-               sprintf( formatstr+strlen(formatstr), "%d", len );
-       }
-       if( precision >= 0 ){
-               sprintf( formatstr+strlen(formatstr), ".%d", precision );
-       }
-       sprintf( formatstr+strlen(formatstr), "%c", fmt );
-       /* this is easier than trying to do the portable dtostr */
-       /* fprintf(stderr,"format string '%s'\n", formatstr); */
-       sprintf( convert, formatstr, value );
-       dostr( buffer, left, convert );
-}
-
- static void dostr( char **buffer, int *left, char *str  )
-{
-       if(str)while(*str) dopr_outch( buffer, left, *str++ );
-}
-
- static void dopr_outch( char **buffer, int *left, int c )
-{
-       if( *left > 0 ){
-               *(*buffer)++ = c;
-       }
-       *left -= 1;
-}
-
-
-/****************************************************************************
- * static char *plp_errormsg( int err )
- *  returns a printable form of the
- *  errormessage corresponding to the valie of err.
- *  This is the poor man's version of sperror(), not available on all systems
- *  Patrick Powell Tue Apr 11 08:05:05 PDT 1995
- ****************************************************************************/
-/****************************************************************************/
-
-#if !defined(HAVE_STRERROR)
-# undef  num_errors
-# if defined(HAVE_SYS_ERRLIST)
-#  if !defined(HAVE_DECL_SYS_ERRLIST)
-     extern const char *const sys_errlist[];
-#  endif
-#  if defined(HAVE_SYS_NERR)
-#   if !defined(HAVE_DECL_SYS_NERR)
-      extern int sys_nerr;
-#   endif
-#   define num_errors    (sys_nerr)
-#  endif
-# endif
-# if !defined(num_errors)
-#   define num_errors   (-1)            /* always use "errno=%d" */
-# endif
-#endif
-
- static char * plp_Errormsg ( int err, char *buffer /* int maxlen = 32 */)
-{
-    char *cp;
-
-#if defined(HAVE_STRERROR)
-       cp = (void *)strerror(err);
-#else
-# if defined(HAVE_SYS_ERRLIST)
-    if (err >= 0 && err < num_errors) {
-               cp = (void *)sys_errlist[err];
-    } else
-# endif
-       {
-               (void) sprintf (buffer, "errno=%d", err);
-               cp = buffer;
-    }
-#endif
-    return (cp);
-}
-
-#if defined(TEST)
-#include <stdio.h>
-int main( void )
-{
-       char buffer[128];
-       char *t;
-       char *test1 = "01234";
-       int n;
-       errno = 1;
-       buffer[0] = 0;
-       n = plp_snprintf( buffer, 0, (t="test")); printf( "[%d] %s = '%s'\n", n, t, buffer );
-       n = plp_snprintf( buffer, sizeof(buffer), (t="errno '%s'")); printf( "[%d] %s = '%s'\n", n, t, buffer, strerror(errno) );
-       n = plp_snprintf( buffer, sizeof(buffer), (t = "%s"), test1 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
-       n = plp_snprintf( buffer, sizeof(buffer), (t = "%12s"), test1 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
-       n = plp_snprintf( buffer, sizeof(buffer), (t = "%-12s"), test1 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
-       n = plp_snprintf( buffer, sizeof(buffer), (t = "%12.2s"), test1 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
-       n = plp_snprintf( buffer, sizeof(buffer), (t = "%-12.2s"), test1 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
-       n = plp_snprintf( buffer, sizeof(buffer), (t = "%g"), 1.25 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
-       n = plp_snprintf( buffer, sizeof(buffer), (t = "%g"), 1.2345 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
-       n = plp_snprintf( buffer, sizeof(buffer), (t = "%12g"), 1.25 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
-       n = plp_snprintf( buffer, sizeof(buffer), (t = "%12.1g"), 1.25 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
-       n = plp_snprintf( buffer, sizeof(buffer), (t = "%12.2g"), 1.25 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
-       n = plp_snprintf( buffer, sizeof(buffer), (t = "%12.3g"), 1.25 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
-       n = plp_snprintf( buffer, sizeof(buffer), (t = "%0*d"), 6, 1 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
-#if defined(HAVE_LONG_LONG)
-       n = plp_snprintf( buffer, sizeof(buffer), (t = "%llx"), 1, 2, 3, 4 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
-       n = plp_snprintf( buffer, sizeof(buffer), (t = "%llx"), (long long)1, (long long)2 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
-       n = plp_snprintf( buffer, sizeof(buffer), (t = "%qx"), 1, 2, 3, 4 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
-       n = plp_snprintf( buffer, sizeof(buffer), (t = "%qx"), (quad_t)1, (quad_t)2 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
-#endif
-       n = plp_snprintf( buffer, sizeof(buffer), (t = "0%x, 0%x"), (char *)(0x01234567), (char *)0, 0, 0, 0); printf( "[%d] %s = '%s'\n", n, t, buffer );
-       n = plp_snprintf( buffer, sizeof(buffer), (t = "0%x, 0%x"), (char *)(0x01234567), (char *)0x89ABCDEF, 0, 0, 0); printf( "[%d] %s = '%s'\n", n, t, buffer );
-       n = plp_snprintf( buffer, sizeof(buffer), (t = "0%x, 0%x"), t, 0, 0, 0, 0); printf( "[%d] %s = '%s'\n", n, t, buffer );
-       n = plp_snprintf( buffer, sizeof(buffer), (t = "%f"), 1.25 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
-       n = plp_snprintf( buffer, sizeof(buffer), (t = "%f"), 1.2345 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
-       n = plp_snprintf( buffer, sizeof(buffer), (t = "%12f"), 1.25 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
-       n = plp_snprintf( buffer, sizeof(buffer), (t = "%12.2f"), 1.25 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
-       n = plp_snprintf( buffer, sizeof(buffer), (t = "%f"), 1.0 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
-       n = plp_snprintf( buffer, sizeof(buffer), (t = "%.0f"), 1.0 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
-       n = plp_snprintf( buffer, sizeof(buffer), (t = "%0.0f"), 1.0 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
-       n = plp_snprintf( buffer, sizeof(buffer), (t = "%1.0f"), 1.0 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
-       n = plp_snprintf( buffer, sizeof(buffer), (t = "%1.5f"), 1.0 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
-       n = plp_snprintf( buffer, sizeof(buffer), (t = "%5.5f"), 1.0 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
-       return(0);
-}
-#endif
-
-#endif /* !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF) */
-
-#ifndef HAVE_VSNPRINTF
-int vsnprintf(char *str, size_t count, const char *fmt, va_list args)
-{
-    int n;
-    
-    n = plp_vsnprintf(str, count, fmt, args);
-    
-    return(n);
-}
-#endif /* ! HAVE_VSNPRINTF */
-
-#ifndef HAVE_SNPRINTF
-#ifdef HAVE_STDARGS
-int snprintf (char *str,size_t count,const char *fmt,...)
-#else
-int snprintf (va_alist) va_dcl
-#endif
-{
-#ifndef HAVE_STDARGS
-    char *str;
-       size_t count;
-    char *fmt;
-#endif
-       int n = 0;
-    VA_LOCAL_DECL
-
-    VA_START (fmt);
-    VA_SHIFT (str, char *);
-    VA_SHIFT (count, size_t );
-    VA_SHIFT (fmt, char *);
-    n = plp_vsnprintf ( str, count, fmt, ap);
-    VA_END;
-       return( n );
-}
-#endif /* ! HAVE_VNSPRINTF */
diff --git a/libatalk/compat/strcasecmp.c b/libatalk/compat/strcasecmp.c
deleted file mode 100644 (file)
index bc8cb57..0000000
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * $Id: strcasecmp.c,v 1.4 2003-02-17 01:51:08 srittau Exp $
- *
- * Copyright (c) 1987 Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms are permitted
- * provided that: (1) source distributions retain this entire copyright
- * notice and comment, and (2) distributions including binaries display
- * the following acknowledgement:  ``This product includes software
- * developed by the University of California, Berkeley and its contributors''
- * in the documentation or other materials provided with the distribution
- * and in all advertising materials mentioning features or use of this
- * software. Neither the name of the University nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-# if defined( ibm032 )
-
-#include <sys/types.h>
-#include <string.h>
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char sccsid[] = "@(#)strcasecmp.c 5.9 (Berkeley) 6/1/90";
-#endif /* LIBC_SCCS and not lint */
-
-/*
- * This array is designed for mapping upper and lower case letter
- * together for a case independent comparison.  The mappings are
- * based upon ascii character sequences.
- */
-static u_char charmap[] = {
-       '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
-       '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
-       '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
-       '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
-       '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
-       '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
-       '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
-       '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
-       '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
-       '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
-       '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
-       '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
-       '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
-       '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
-       '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
-       '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177',
-       '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
-       '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
-       '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
-       '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
-       '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
-       '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
-       '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
-       '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
-       '\300', '\301', '\302', '\303', '\304', '\305', '\306', '\307',
-       '\310', '\311', '\312', '\313', '\314', '\315', '\316', '\317',
-       '\320', '\321', '\322', '\323', '\324', '\325', '\326', '\327',
-       '\330', '\331', '\332', '\333', '\334', '\335', '\336', '\337',
-       '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
-       '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
-       '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
-       '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377',
-};
-
-int
-strcasecmp(s1, s2)
-       char *s1, *s2;
-{
-       register u_char *cm = charmap,
-                       *us1 = (u_char *)s1,
-                       *us2 = (u_char *)s2;
-
-       while (cm[*us1] == cm[*us2++])
-               if (*us1++ == '\0')
-                       return (0);
-       return (cm[*us1] - cm[*--us2]);
-}
-
-int
-strncasecmp(s1, s2, n)
-       char *s1, *s2;
-       register size_t n;
-{
-       if (n != 0) {
-               register u_char *cm = charmap,
-                               *us1 = (u_char *)s1,
-                               *us2 = (u_char *)s2;
-
-               do {
-                       if (cm[*us1] != cm[*us2++])
-                               return (cm[*us1] - cm[*--us2]);
-                       if (*us1++ == '\0')
-                               break;
-               } while (--n != 0);
-       }
-       return (0);
-}
-
-# endif /* ibm032 */
diff --git a/libatalk/compat/strdup.c b/libatalk/compat/strdup.c
deleted file mode 100644 (file)
index 9537a85..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * $Id: strdup.c,v 1.4 2003-02-17 01:51:08 srittau Exp $
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#ifdef ultrix
-char *strdup(const char *string)
-{
-  char *new;
-  
-  if (new = (char *) malloc(strlen(string) + 1))
-    strcpy(new, string);
-
-  return new;
-}
-#endif /* ultrix */
diff --git a/libatalk/compat/strlcpy.c b/libatalk/compat/strlcpy.c
new file mode 100644 (file)
index 0000000..314b039
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+   Copy from samba lib/replace.c
+
+   Unix SMB/CIFS implementation.
+   replacement routines for broken systems
+   Copyright (C) Andrew Tridgell 1992-1998
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+   strlcpy strlcat functions.
+*/
+                          
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <atalk/util.h>
+#include <string.h>
+
+#ifndef HAVE_STRLCPY
+/* like strncpy but does not 0 fill the buffer and always null
+   terminates. bufsize is the size of the destination buffer */
+ size_t strlcpy(char *d, const char *s, size_t bufsize)
+{
+        size_t len = strlen(s);
+        size_t ret = len;
+
+        if (bufsize <= 0) 
+               return 0;
+
+        if (len >= bufsize) 
+               len = bufsize-1;
+
+        memcpy(d, s, len);
+        d[len] = 0;
+        return ret;
+}
+#endif
+#ifndef HAVE_STRLCAT
+/* like strncat but does not 0 fill the buffer and always null
+   terminates. bufsize is the length of the buffer, which should
+   be one more than the maximum resulting string length */
+ size_t strlcat(char *d, const char *s, size_t bufsize)
+{
+        size_t len1 = strlen(d);
+        size_t len2 = strlen(s);
+        size_t ret = len1 + len2;
+
+       if (len1 >= bufsize) {
+               return 0;
+       } 
+        if (len1+len2 >= bufsize) {
+                len2 = bufsize - (len1+1);
+        }
+        if (len2 > 0) {
+                memcpy(d+len1, s, len2);
+                d[len1+len2] = 0;
+        }
+        return ret;
+}
+#endif
diff --git a/libatalk/compat/strstr.c b/libatalk/compat/strstr.c
deleted file mode 100644 (file)
index ae555b4..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * $Id: strstr.c,v 1.4 2003-02-17 01:51:08 srittau Exp $
- *
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the University of
- *     California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)strstr.c   5.2 (Berkeley) 1/26/91";
-#endif /* LIBC_SCCS and not lint */
-
-# if defined(ibm032) || (defined(sun) && defined(i386))
-#ifdef sun
-#define const
-#endif /* sun */
-
-#include <sys/types.h>
-#include <string.h>
-
-/*
- * Find the first occurrence of find in s.
- */
-char *
-strstr(s, find)
-       register const char *s, *find;
-{
-       register char c, sc;
-       register size_t len;
-
-       if ((c = *find++) != 0) {
-               len = strlen(find);
-               do {
-                       do {
-                               if ((sc = *s++) == 0)
-                                       return (0);
-                       } while (sc != c);
-               } while (strncmp(s, find, len) != 0);
-               s--;
-       }
-       return ((char *)s);
-}
-# endif /* ibm03 sun i386 */
index 9aef79b53534aeabd9598c622c001b7b8f4904bc..5a60c24d5c25d30d223b820b3edf496c89009740 100644 (file)
 #include <string.h>
 #include <signal.h>
 #include <sys/types.h>
+#include <arpa/inet.h>
 
 #include <atalk/dsi.h>
 #include <atalk/afp.h>
-#include <netatalk/endian.h>
 
 #ifndef MIN
 #define MIN(a,b) ((a) < (b) ? (a) : (b))
@@ -31,8 +31,8 @@ int dsi_attention(DSI *dsi, AFPUserBytes flags)
 {
   /* header + AFPUserBytes */
   char block[DSI_BLOCKSIZ + sizeof(AFPUserBytes)];
-  u_int32_t len, nlen;
-  u_int16_t id;
+  uint32_t len, nlen;
+  uint16_t id;
 
   if (dsi->flags & DSI_SLEEPING)
       return 1;
index 6362182ba49fe6d259dd67277eb8cc0f7df6b7e3..80bee3fe702a79cfbd18bd7a7ac4bd8539295aaf 100644 (file)
@@ -11,8 +11,9 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <arpa/inet.h>
+
 #include <atalk/dsi.h>
-#include <netatalk/endian.h>
 
 void dsi_close(DSI *dsi)
 {
index 0d7e5f025a7936847046d6dc06a7938ebe6dc847..5b0d627de2c788e7356ffeb50219163d6007cb3c 100644 (file)
@@ -8,9 +8,10 @@
 #endif /* HAVE_CONFIG_H */
 
 #include <stdio.h>
+#include <arpa/inet.h>
+
 #include <atalk/dsi.h>
 #include <atalk/logger.h>
-#include <netatalk/endian.h>
 
 /* this assumes that the reply follows right after the command, saving
  * on a couple assignments. specifically, command, requestID, and
index ea22c2dca5cb096f5846c351913a82fd15ff0964..a50136db6a3d9ec3c4e04ca1f5fe196bd2200a74 100644 (file)
 #include <sys/types.h>
 #include <sys/socket.h>
 
-/* POSIX.1 sys/wait.h check */
 #include <sys/types.h>
-#ifdef HAVE_SYS_WAIT_H
 #include <sys/wait.h>
-#endif /* HAVE_SYS_WAIT_H */
-#ifndef WEXITSTATUS
-#define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
-#endif /* ! WEXITSTATUS */
-#ifndef WIFEXITED
-#define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
-#endif /* ! WIFEXITED */
-
 #include <sys/time.h>
 #include <atalk/logger.h>
 #include <atalk/util.h>
index 33e89fad3eda10c948fa29e5b6a06b5baa5c0df0..aec872ab0c15f1aaea351ddeb9febe44860e9f9a 100644 (file)
@@ -11,9 +11,9 @@
 
 #include <stdio.h>
 #include <string.h>
+#include <arpa/inet.h>
 
 #include <atalk/dsi.h>
-#include <netatalk/endian.h>
 
 /* return the status and then delete the connection. most of the
  * fields are already set. */
index 547eed997ff815c6379c3423a60a22d2e62a43a3..ee75fcc71ebb26be21a7c3ca40241c352a1d2409 100644 (file)
@@ -17,7 +17,7 @@
 
 DSI *dsi_init(const dsi_proto protocol, const char *program, 
              const char *hostname, const char *address,
-             const char *port, const int proxy, const u_int32_t quantum)
+             const char *port, const int proxy, const uint32_t quantum)
 {
     DSI                *dsi;
 
index 2d7fd23b84c947789f060dfe7b89b3e3ab41f398..e074a1120528f5d44392c4c1a99aedb21ea8f160 100644 (file)
@@ -33,7 +33,7 @@ static void dsi_init_buffer(DSI *dsi)
 /* OpenSession. set up the connection */
 void dsi_opensession(DSI *dsi)
 {
-  u_int32_t i = 0; /* this serves double duty. it must be 4-bytes long */
+  uint32_t i = 0; /* this serves double duty. it must be 4-bytes long */
   int offs;
 
   dsi_init_buffer(dsi);
index 8872f8f3cf8b4a5f09972cc764c37974f063a0e7..c953afdc298b0fe1c4f51a7ad202eeeead38ab6a 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: dsi_private.h,v 1.4 2009-11-05 14:38:08 franklahm Exp $
- *
  * Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu)
  * All rights reserved. See COPYRIGHT.
  */
@@ -13,9 +11,8 @@
  * include it.
  */
 
-#include <sys/cdefs.h>
 #include <sys/types.h>
-#include <netatalk/endian.h>
+#include <arpa/inet.h>
 
 extern int dsi_tcp_init (DSI *, const char * /*host*/, 
                             const char * /*address*/,
index 12971511022f00835b61b922871b36bb75fa5789..75dfe9579d1c0923c3818a0b42255386f3e5fdd7 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: dsi_read.c,v 1.7 2009-10-25 06:13:11 didg Exp $
- *
  * Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu)
  * All rights reserved. See COPYRIGHT.
  */
 
 #include <stdio.h>
 #include <string.h>
-#ifdef HAVE_UNISTD_H
 #include <unistd.h>
-#endif /* HAVE_UNISTD_H */
 #include <signal.h>
 #include <sys/types.h>
 #include <sys/time.h>
-#ifdef HAVE_SYS_FILIO_H
-#include <sys/filio.h>
-#endif
 
 #include <atalk/dsi.h>
 #include <atalk/util.h>
index bc84a5fa2bb47849ac5cc2129116e5ad2f137aba..ccb8b76eae25d4dc091448ab8dff81e58ee2039a 100644 (file)
@@ -28,7 +28,6 @@
 
 #include <atalk/logger.h>
 #include <atalk/dsi.h>
-#include <netatalk/endian.h>
 #include <atalk/util.h>
 
 #define min(a,b)  ((a) < (b) ? (a) : (b))
@@ -125,7 +124,7 @@ static int dsi_peek(DSI *dsi)
 /* 
  * Return all bytes up to count from dsi->buffer if there are any buffered there
  */
-static size_t from_buf(DSI *dsi, u_int8_t *buf, size_t count)
+static size_t from_buf(DSI *dsi, uint8_t *buf, size_t count)
 {
     size_t nbe = 0;
 
@@ -160,7 +159,7 @@ static size_t from_buf(DSI *dsi, u_int8_t *buf, size_t count)
  *    Note: this may return fewer bytes then requested in count !!
  * 3. If the buffer was empty, read from the socket.
  */
-static ssize_t buf_read(DSI *dsi, u_int8_t *buf, size_t count)
+static ssize_t buf_read(DSI *dsi, uint8_t *buf, size_t count)
 {
     ssize_t len;
 
@@ -184,7 +183,7 @@ static ssize_t buf_read(DSI *dsi, u_int8_t *buf, size_t count)
  * Get "length" bytes from buffer and/or socket. In order to avoid frequent small reads
  * this tries to read larger chunks (8192 bytes) into a buffer.
  */
-static size_t dsi_buffered_stream_read(DSI *dsi, u_int8_t *data, const size_t length)
+static size_t dsi_buffered_stream_read(DSI *dsi, uint8_t *data, const size_t length)
 {
   size_t len;
   size_t buflen;
@@ -272,7 +271,7 @@ ssize_t dsi_stream_write(DSI *dsi, void *data, const size_t length, int mode)
       return -1;
 
   while (written < length) {
-      len = send(dsi->socket, (u_int8_t *) data + written, length - written, flags);
+      len = send(dsi->socket, (uint8_t *) data + written, length - written, flags);
       if (len >= 0) {
           written += len;
           continue;
@@ -400,7 +399,7 @@ size_t dsi_stream_read(DSI *dsi, void *data, const size_t length)
 
   stored = 0;
   while (stored < length) {
-      len = buf_read(dsi, (u_int8_t *) data + stored, length - stored);
+      len = buf_read(dsi, (uint8_t *) data + stored, length - stored);
       if (len == -1 && (errno == EINTR || errno == EAGAIN)) {
           LOG(log_maxdebug, logtype_dsi, "dsi_stream_read: select read loop");
           continue;
@@ -524,7 +523,7 @@ int dsi_stream_receive(DSI *dsi)
       return 0;
 
   /* read in the header */
-  if (dsi_buffered_stream_read(dsi, (u_int8_t *)block, sizeof(block)) != sizeof(block)) 
+  if (dsi_buffered_stream_read(dsi, (uint8_t *)block, sizeof(block)) != sizeof(block)) 
     return 0;
 
   dsi->header.dsi_flags = block[0];
index 0c60303ecb6159c5310d44d28f59242876e69e2d..c707612607f0d1579e3910f8bc6c4a2faad14cc5 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: dsi_tcp.c,v 1.25 2009-12-08 22:34:37 didg Exp $
- *
  * Copyright (c) 1997, 1998 Adrian Sun (asun@zoology.washington.edu)
  * All rights reserved. See COPYRIGHT.
  *
@@ -17,9 +15,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#ifdef HAVE_UNISTD_H
 #include <unistd.h>
-#endif /* HAVE_UNISTD_H */
 #include <errno.h>
 #ifdef HAVE_NETDB_H
 #include <netdb.h>
 #include <sys/types.h>
 #include <sys/time.h>
 #include <sys/socket.h>
-
-#ifdef HAVE_STDINT_H
 #include <stdint.h>
-#endif /* HAVE_STDINT_H */
 
 #include <sys/ioctl.h>
 #ifdef TRU64
@@ -58,7 +51,7 @@ int deny_severity = log_warning;
 #include <atalk/dsi.h>
 #include <atalk/compat.h>
 #include <atalk/util.h>
-#include <netatalk/endian.h>
+
 #include "dsi_private.h"
 
 #define min(a,b)  ((a) < (b) ? (a) : (b))
@@ -124,7 +117,7 @@ static int dsi_tcp_open(DSI *dsi)
     if (0 == (pid = fork()) ) { /* child */
         static struct itimerval timer = {{0, 0}, {DSI_TCPTIMEOUT, 0}};
         struct sigaction newact, oldact;
-        u_int8_t block[DSI_BLOCKSIZ];
+        uint8_t block[DSI_BLOCKSIZ];
         size_t stored;
 
         /* Immediateyl mark globally that we're a child now */
index 2a996539a968ba0201c8c19d1f62e9a53a8f7c25..40d0c0ad4cb43376dc0421c4b8fd504708fc15e2 100644 (file)
 #include <signal.h>
 
 #include <atalk/dsi.h>
-#include <netatalk/endian.h>
 
 /* server generated tickles. as this is only called by the tickle handler,
  * we don't need to block signals. */
 int dsi_tickle(DSI *dsi)
 {
   char block[DSI_BLOCKSIZ];
-  u_int16_t id;
+  uint16_t id;
   
   if ((dsi->flags & DSI_SLEEPING) || dsi->in_write)
       return 1;
index 79d03caf9491175267e75cd6be1edd55869c9064..3e96489e4fd4b8deea3fe6843c9ea6ccceeb2274 100644 (file)
 
 /* this streams writes */
 #include <stdio.h>
-#ifdef HAVE_UNISTD_H
 #include <unistd.h>
-#endif /* HAVE_UNISTD_H */
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/time.h>
-#ifdef HAVE_FCNTL_H
 #include <fcntl.h>
-#endif /* HAVE_FCNTL_H */
 #include <string.h>
 
 #include <atalk/dsi.h>
-#include <netatalk/endian.h>
 
 #ifndef MIN
 #define MIN(a,b)     ((a) < (b) ? (a) : (b))
diff --git a/libatalk/locking/.gitignore b/libatalk/locking/.gitignore
new file mode 100644 (file)
index 0000000..604ff3c
--- /dev/null
@@ -0,0 +1,7 @@
+Makefile
+Makefile.in
+*.lo
+*.la
+.deps
+.libs
+
diff --git a/libatalk/locking/Makefile.am b/libatalk/locking/Makefile.am
new file mode 100644 (file)
index 0000000..866510c
--- /dev/null
@@ -0,0 +1,4 @@
+# Makefile.am for libatalk/locking/
+
+noinst_LTLIBRARIES = liblocking.la
+liblocking_la_SOURCES = locking.c
diff --git a/libatalk/locking/locking.c b/libatalk/locking/locking.c
new file mode 100644 (file)
index 0000000..db0b513
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2011 Frank Lahm
+ * All Rights Reserved.  See COPYRIGHT.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include <atalk/logger.h>
+#include <atalk/errchk.h>
+#include <atalk/locking.h>
+#include <atalk/cnid.h>
+#include <atalk/paths.h>
+
+/***************************************************************************
+ * structures and defines
+ ***************************************************************************/
+
+#define LOCKTABLE_PATH         "/tmp/netatalk-afp-locks.tdb" 
+
+/* 
+ * Struct for building the the main database of file locks.
+ * vid + cnid build the primary key for database access.
+ */
+typedef struct afp_lock {
+    /* Keys */
+    uint32_t l_vid;
+    cnid_t   l_cnid;
+    uint64_t l_dev;
+    uint64_t l_ino;
+
+    /* pid holding the lock, also secondary key */
+    pid_t    l_pid;
+
+    /* Refcounting access and deny modes */
+    uint16_t l_amode_r;
+    uint16_t l_amode_w;
+    uint16_t l_dmode_r;
+    uint16_t l_dmode_w;
+} afp_lock_t;
+
+#define PACKED_AFP_LOCK_SIZE                 \
+    sizeof(((afp_lock_t *)0)->l_vid) +       \
+    sizeof(((afp_lock_t *)0)->l_cnid) +      \
+    sizeof(((afp_lock_t *)0)->l_dev) +       \
+    sizeof(((afp_lock_t *)0)->l_ino) +       \
+    sizeof(((afp_lock_t *)0)->l_pid) +       \
+    sizeof(((afp_lock_t *)0)->l_amode_r) +   \
+    sizeof(((afp_lock_t *)0)->l_amode_w) +   \
+    sizeof(((afp_lock_t *)0)->l_dmode_r) +   \
+    sizeof(((afp_lock_t *)0)->l_dmode_r)
+
+/***************************************************************************
+ * Data
+ ***************************************************************************/
+
+static struct smbdb_ctx *tdb;
+
+/***************************************************************************
+ * Private functions
+ ***************************************************************************/
+
+/***************************************************************************
+ * Public functions
+ ***************************************************************************/
+
+/*!
+ * Open locktable from path
+ */
+int locktable_init(const char *path)
+{
+    EC_INIT;
+
+//    EC_NULL_LOG(tdb = smb_share_mode_db_open(path));
+
+EC_CLEANUP:
+    EC_EXIT;
+}
+
diff --git a/libatalk/nbp/.gitignore b/libatalk/nbp/.gitignore
deleted file mode 100644 (file)
index aae291d..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-Makefile
-Makefile.in
-*.lo
-*.la
-.deps
-.libs
-.gitignore
-nbp_lkup.o nbp_rgstr.o nbp_unrgstr.o nbp_util.o
diff --git a/libatalk/nbp/Makefile.am b/libatalk/nbp/Makefile.am
deleted file mode 100644 (file)
index 1a6404d..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-# Makefile.am for libatalk/nbp/
-
-noinst_LTLIBRARIES = libnbp.la
-
-libnbp_la_SOURCES = nbp_util.c nbp_lkup.c nbp_rgstr.c nbp_unrgstr.c
-
-noinst_HEADERS = nbp_conf.h
diff --git a/libatalk/nbp/nbp_conf.h b/libatalk/nbp/nbp_conf.h
deleted file mode 100644 (file)
index 66029a6..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * $Id: nbp_conf.h,v 1.3 2009-10-13 22:55:37 didg Exp $
- *
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- * All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software and
- * its documentation for any purpose and without fee is hereby granted,
- * provided that the above copyright notice appears in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation, and that the name of The University
- * of Michigan not be used in advertising or publicity pertaining to
- * distribution of the software without specific, written prior
- * permission. This software is supplied as is without expressed or
- * implied warranties of any kind.
- *
- *     Research Systems Unix Group
- *     The University of Michigan
- *     c/o Mike Clark
- *     535 W. William Street
- *     Ann Arbor, Michigan
- *     +1-313-763-0525
- *     netatalk@itd.umich.edu
- */
-
-#ifndef NBP_CONF_H
-#define NBP_CONF_H 1
-
-#include <sys/cdefs.h>
-#include <atalk/nbp.h>
-
-extern char            nbp_send[ 1024 ];
-extern char            nbp_recv[ 1024 ];
-extern u_char          nbp_port;
-extern unsigned char    nbp_id;
-
-
-int nbp_parse (char *, struct nbpnve *, int);
-int nbp_match (struct nbpnve *, struct nbpnve *, int);
-
-#endif /* NBP_CONF_H */
diff --git a/libatalk/nbp/nbp_lkup.c b/libatalk/nbp/nbp_lkup.c
deleted file mode 100644 (file)
index 6a99126..0000000
+++ /dev/null
@@ -1,224 +0,0 @@
-/*
- * $Id: nbp_lkup.c,v 1.5 2009-10-13 22:55:37 didg Exp $
- *
- * Copyright (c) 1990,1997 Regents of The University of Michigan.
- * All Rights Reserved. See COPYRIGHT.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <string.h>
-#include <errno.h>
-#include <signal.h>
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-
-#include <netatalk/endian.h>
-#include <netatalk/at.h>
-#include <netatalk/ddp.h>
-#include <atalk/compat.h>
-#include <atalk/nbp.h>
-#include <atalk/netddp.h>
-#include <atalk/ddp.h>
-
-#ifdef HAVE_NETDB_H
-#include <netdb.h>
-#endif /* HAVE_NETDB_H */
-
-#include  "nbp_conf.h"
-
-/* FIXME/SOCKLEN_T: socklen_t is a unix98 feature. */
-#ifndef SOCKLEN_T
-#define SOCKLEN_T unsigned int
-#endif /* ! SOCKLEN_T */
-
-int nbp_lookup( const char *obj, const char *type, const char *zone, struct nbpnve *nn,
-    int                        nncnt,
-    const struct at_addr *ataddr)
-{
-    struct sockaddr_at addr, from;
-    struct timeval     tv, tv_begin, tv_end;
-    fd_set             fds;
-    struct nbpnve      nve;
-    struct nbphdr      nh;
-    struct nbptuple    nt;
-    struct servent     *se;
-    char               *data = nbp_send;
-    SOCKLEN_T          namelen;
-    int                        s, cnt, tries, sc, cc, i, c;
-
-    memset(&addr, 0, sizeof(addr));
-    memset(&from, 0, sizeof(from));
-    if (ataddr) 
-      memcpy(&addr.sat_addr, ataddr, sizeof(struct at_addr));
-    if ((s = netddp_open(&addr, &from)) < 0)
-      return -1;
-
-    *data++ = DDPTYPE_NBP;
-#ifdef MACOSX_SERVER
-    nh.nh_op = from.sat_addr.s_node ? NBPOP_BRRQ : NBPOP_LKUP;
-#else /* MACOSX_SERVER */
-    nh.nh_op = NBPOP_BRRQ;
-#endif /* MACOSX_SERVER */
-
-    nh.nh_cnt = 1;
-    nh.nh_id = ++nbp_id;
-    memcpy( data, &nh, SZ_NBPHDR );
-    data += SZ_NBPHDR;
-
-    memset(&nt, 0, sizeof(nt));
-    nt.nt_net = addr.sat_addr.s_net;
-    nt.nt_node = addr.sat_addr.s_node;
-    nt.nt_port = addr.sat_port;
-
-    memcpy( data, &nt, SZ_NBPTUPLE);
-    data += SZ_NBPTUPLE;
-
-    if ( obj ) {
-       if (( cc = strlen( obj )) > NBPSTRLEN ) goto lookup_err;
-       *data++ = cc;
-       memcpy( data, obj, cc );
-       data += cc;
-    } else {
-       *data++ = 1;
-       *data++ = '='; /* match anything */
-    }
-
-    if ( type ) {
-       if (( cc = strlen( type )) > NBPSTRLEN ) goto lookup_err;
-       *data++ = cc;
-       memcpy( data, type, cc );
-       data += cc;
-    } else {
-       *data++ = 1;
-       *data++ = '='; /* match anything */
-    }
-
-    if ( zone ) {
-       if (( cc = strlen( zone )) > NBPSTRLEN ) goto lookup_err;
-       *data++ = cc;
-       memcpy( data, zone, cc );
-       data += cc;
-    } else {
-       *data++ = 1;
-       *data++ = '*'; /* default zone */
-    }
-
-    if ( nbp_port == 0 ) {
-      if (( se = getservbyname( "nbp", "ddp" )) == NULL ) {
-                   nbp_port = 2;
-      } else {
-                   nbp_port = ntohs( se->s_port );
-      }
-    }
-
-#ifdef MACOSX_SERVER
-    if (from.sat_addr.s_node) {
-      memcpy(&addr.sat_addr, &from.sat_addr, sizeof(addr.sat_addr));
-    } else {
-      addr.sat_addr.s_net = ATADDR_ANYNET;
-      addr.sat_addr.s_node = ATADDR_BCAST;
-    }
-#endif /* MACOSX_SERVER */
-    addr.sat_port = nbp_port;
-
-    cnt = 0;
-    tries = 3;
-    sc = data - nbp_send;
-    while ( tries > 0 ) {
-       if ( netddp_sendto( s, nbp_send, sc, 0, (struct sockaddr *)&addr,
-               sizeof( struct sockaddr_at )) < 0 ) {
-           goto lookup_err;
-       }
-
-       tv.tv_sec = 2L;
-       tv.tv_usec = 0;
-
-       for (;;) {
-           FD_ZERO( &fds );
-           FD_SET( s, &fds );
-           if ( gettimeofday( &tv_begin, NULL ) < 0 ) {
-               goto lookup_err;
-           }
-           if (( c = select( s + 1, &fds, NULL, NULL, &tv )) < 0 ) {
-               goto lookup_err;
-           }
-           if ( c == 0 || FD_ISSET( s, &fds ) == 0 ) {
-               break;
-           }
-           if ( gettimeofday( &tv_end, NULL ) < 0 ) {
-               goto lookup_err;
-           }
-           if ( tv_begin.tv_usec > tv_end.tv_sec ) {
-               tv_end.tv_usec += 1000000;
-               tv_end.tv_sec -= 1;
-           }
-           if (( tv.tv_usec -= ( tv_end.tv_usec - tv_begin.tv_usec )) < 0 ) {
-               tv.tv_usec += 1000000;
-               tv.tv_sec -= 1;
-           }
-           if (( tv.tv_sec -= ( tv_end.tv_sec - tv_begin.tv_sec )) < 0 ) {
-               break;
-           }
-
-           namelen = sizeof( struct sockaddr_at );
-           if (( cc = netddp_recvfrom( s, nbp_recv, sizeof( nbp_recv ), 0,
-                   (struct sockaddr *)&from, &namelen )) < 0 ) {
-               goto lookup_err;
-           }
-
-           data = nbp_recv;
-           if ( *data++ != DDPTYPE_NBP ) {
-               continue;
-           }
-           cc--;
-
-           memcpy( &nh, data, SZ_NBPHDR );
-           data += SZ_NBPHDR;
-           if ( nh.nh_op != NBPOP_LKUPREPLY ) {
-               continue;
-           }
-           cc -= SZ_NBPHDR;
-
-           while (( i = nbp_parse( data, &nve, cc )) >= 0 ) {
-               data += cc - i;
-               cc = i;
-               /*
-                * Check to see if nve is already in nn. If not,
-                * put it in, and increment cnt.
-                */
-               for ( i = 0; i < cnt; i++ ) {
-                   if ( nbp_match( &nve, &nn[ i ],
-                           NBPMATCH_NOZONE|NBPMATCH_NOGLOB )) {
-                       break;
-                   }
-               }
-               if ( i == cnt ) {
-                   nn[ cnt++ ] = nve;
-               }
-               if ( cnt == nncnt ) {
-                   tries = 0;
-                   break;
-               }
-           }
-           if ( cnt == nncnt ) {
-               tries = 0;
-               break;
-           }
-       }
-       tries--;
-    }
-
-    netddp_close(s);
-    errno = 0;
-    return( cnt );
-
-lookup_err:
-    netddp_close(s);
-    return -1;
-}
diff --git a/libatalk/nbp/nbp_rgstr.c b/libatalk/nbp/nbp_rgstr.c
deleted file mode 100644 (file)
index d09e866..0000000
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * $Id: nbp_rgstr.c,v 1.6 2009-10-14 02:24:05 didg Exp $
- *
- * Copyright (c) 1990,1993 Regents of The University of Michigan.
- * All Rights Reserved. See COPYRIGHT.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <string.h>
-#include <errno.h>
-#include <signal.h>
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-
-#include <netatalk/at.h>
-#include <netatalk/endian.h>
-#include <atalk/nbp.h>
-#include <atalk/ddp.h>
-#include <atalk/netddp.h>
-
-#ifdef HAVE_NETDB_H
-#include <netdb.h>
-#endif /* HAVE_NETDB_H */
-#include  "nbp_conf.h"
-
-/* FIXME/SOCKLEN_T: socklen_t is a unix98 feature. */
-#ifndef SOCKLEN_T
-#define SOCKLEN_T unsigned int
-#endif /* ! SOCKLEN_T */
-
-int nbp_rgstr( struct sockaddr_at *sat, const char *obj, const char *type, const char *zone)
-{
-    struct sockaddr_at to;
-    struct nbpnve      nn;
-    struct nbphdr      nh;
-    struct nbptuple    nt;
-    struct timeval     timeout;
-    fd_set             readfd;
-    struct servent     *se;
-    char               *data;
-    int                        s, cc;
-    SOCKLEN_T          namelen;
-
-    if ( nbp_lookup( obj, type, zone, &nn, 1, &sat->sat_addr ) > 0 ) {
-        errno = EADDRINUSE;
-       return( -1 );
-    }
-
-    memset(&to, 0, sizeof(to));
-    if ((s = netddp_open(&to, NULL)) < 0)
-        return -1;
-
-    data = nbp_send;
-    *data++ = DDPTYPE_NBP;
-    nh.nh_op = NBPOP_RGSTR;
-    nh.nh_cnt = 1;
-    nh.nh_id = ++nbp_id;
-    memcpy( data, &nh, SZ_NBPHDR );
-    data += SZ_NBPHDR;
-
-    memset(&nt, 0, sizeof(nt));
-    nt.nt_net = sat->sat_addr.s_net;
-    nt.nt_node = sat->sat_addr.s_node;
-    nt.nt_port = sat->sat_port;
-    memcpy( data, &nt, SZ_NBPTUPLE);
-    data += SZ_NBPTUPLE;
-
-    if ( obj ) {
-       if (( cc = strlen( obj )) > NBPSTRLEN ) return( -1 );
-       *data++ = cc;
-       memcpy( data, obj, cc );
-       data += cc;
-    } else {
-       *data++ = 0;
-    }
-
-    if ( type ) {
-       if (( cc = strlen( type )) > NBPSTRLEN ) return( -1 );
-       *data++ = cc;
-       memcpy( data, type, cc );
-       data += cc;
-    } else {
-       *data++ = 0;
-    }
-
-    if ( zone ) {
-       if (( cc = strlen( zone )) > NBPSTRLEN ) return( -1 );
-       *data++ = cc;
-       memcpy( data, zone, cc );
-       data += cc;
-    } else {
-       *data++ = 1;
-       *data++ = '*'; /* default zone */
-    }
-
-    
-    if ( nbp_port == 0 ) {
-       if (( se = getservbyname( "nbp", "ddp" )) == NULL ) {
-           nbp_port = 2;
-       } else {
-           nbp_port = ntohs( se->s_port );
-       }
-    }
-    to.sat_port = nbp_port;
-
-    if ( netddp_sendto( s, nbp_send, data - nbp_send, 0, 
-                       (struct sockaddr *)&to,
-                       sizeof( struct sockaddr_at )) < 0 ) {
-        goto register_err;
-    }
-
-    FD_ZERO( &readfd );
-    FD_SET( s, &readfd );
-    timeout.tv_sec = 2;
-    timeout.tv_usec = 0;
-    if (( cc = select( s + 1, &readfd, NULL, NULL, &timeout )) < 0 ) {
-        goto register_err;
-    }
-    if ( cc == 0 ) {
-       errno = ETIMEDOUT;
-       goto register_err;
-    }
-
-    namelen = sizeof( struct sockaddr_at );
-    if (( cc = netddp_recvfrom( s, nbp_recv, sizeof( nbp_recv ), 0,
-                       (struct sockaddr *)&to, &namelen )) < 0 ) {
-        goto register_err;
-    }
-
-    netddp_close( s );
-
-    data = nbp_recv;
-    if ( *data++ != DDPTYPE_NBP ) {
-       return( -1 );
-    }
-    memcpy( &nh, data, SZ_NBPHDR );
-    if ( nh.nh_op != NBPOP_OK ) {
-        return -1;
-    }
-    return( 0 );
-
-register_err:
-    netddp_close(s);
-    return -1;
-}
diff --git a/libatalk/nbp/nbp_unrgstr.c b/libatalk/nbp/nbp_unrgstr.c
deleted file mode 100644 (file)
index b16497d..0000000
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * $Id: nbp_unrgstr.c,v 1.6 2009-10-14 02:24:05 didg Exp $
- *
- * Copyright (c) 1990,1997 Regents of The University of Michigan.
- * All Rights Reserved. See COPYRIGHT.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <string.h>
-#include <errno.h>
-#include <signal.h>
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-
-#include <netatalk/endian.h>
-#include <netatalk/at.h>
-#include <atalk/nbp.h>
-#include <atalk/netddp.h>
-#include <atalk/ddp.h>
-
-#ifdef HAVE_NETDB_H
-#include <netdb.h>
-#endif /* HAVE_NETDB_H */
-#include  "nbp_conf.h"
-
-/* FIXME/SOCKLEN_T: socklen_t is a unix98 feature. */
-#ifndef SOCKLEN_T
-#define SOCKLEN_T unsigned int
-#endif /* ! SOCKLEN_T */
-
-int nbp_unrgstr(const char *obj,const char *type,const char  *zone, const struct at_addr *addr)
-{
-    struct sockaddr_at to;
-    struct nbphdr      nh;
-    struct timeval     timeout;
-    fd_set             readfd;
-    struct servent     *se;
-    char               *data;
-    int                        s, cc;
-    SOCKLEN_T          namelen;
-
-
-    memset(&to, 0, sizeof(to));
-    if ((s = netddp_open(&to, NULL)) < 0)
-       return -1;
-
-    data = nbp_send;
-    *data++ = DDPTYPE_NBP;
-    nh.nh_op = NBPOP_UNRGSTR;
-    nh.nh_cnt = 1;
-    nh.nh_id = ++nbp_id;
-    memcpy( data, &nh, SZ_NBPHDR );
-    data += SZ_NBPHDR;
-
-    memset(data, 0, SZ_NBPTUPLE);
-    data += SZ_NBPTUPLE;
-
-    if ( obj ) {
-       if (( cc = strlen( obj )) > NBPSTRLEN ) return( -1 );
-       *data++ = cc;
-       memcpy( data, obj, cc );
-       data += cc;
-    } else {
-       *data++ = 0;
-    }
-
-    if ( type ) {
-       if (( cc = strlen( type )) > NBPSTRLEN ) return( -1 );
-       *data++ = cc;
-       memcpy( data, type, cc );
-       data += cc;
-    } else {
-       *data++ = 0;
-    }
-
-    if ( zone ) {
-       if (( cc = strlen( zone )) > NBPSTRLEN ) return( -1 );
-       *data++ = cc;
-       memcpy( data, zone, cc );
-       data += cc;
-    } else {
-       *data++ = 0;
-    }
-
-    memset( &to, 0, sizeof( struct sockaddr_at ));
-    to.sat_family = AF_APPLETALK;
-    if (addr) 
-      memcpy(&to.sat_addr, addr, sizeof(struct at_addr));
-#ifdef BSD4_4
-    to.sat_len = sizeof( struct sockaddr_at );
-#endif /* BSD4_4 */
-
-    if ( nbp_port == 0 ) {
-       if (( se = getservbyname( "nbp", "ddp" )) == NULL ) {
-           nbp_port = 2;
-       } else {
-           nbp_port = ntohs( se->s_port );
-       }
-    }
-    to.sat_port = nbp_port;
-
-    if ( netddp_sendto( s, nbp_send, data - nbp_send, 0,
-                       (struct sockaddr *)&to,
-                       sizeof( struct sockaddr_at )) < 0 ) {
-        goto unregister_err;
-    }
-
-    FD_ZERO( &readfd );
-    FD_SET( s, &readfd );
-    timeout.tv_sec = 2;
-    timeout.tv_usec = 0;
-    if (( cc = select( s + 1, &readfd, NULL, NULL, &timeout )) < 0 ) {
-        goto unregister_err;
-    }
-    if ( cc == 0 ) {
-       errno = ETIMEDOUT;
-        goto unregister_err;
-    }
-
-    namelen = sizeof( struct sockaddr_at );
-    if (( cc = netddp_recvfrom( s, nbp_recv, sizeof( nbp_recv ), 0,
-                       (struct sockaddr *)&to, &namelen )) < 0 ) {
-        goto unregister_err;
-    }
-    netddp_close( s );
-
-    data = nbp_recv;
-    if ( *data++ != DDPTYPE_NBP ) {
-       return( -1 );
-    }
-    memcpy( &nh, data, SZ_NBPHDR );
-    if ( nh.nh_op != NBPOP_OK ) {
-       return( -1 );
-    }
-    return( 0 );
-
-unregister_err:
-    netddp_close(s);
-    return -1;
-}
diff --git a/libatalk/nbp/nbp_util.c b/libatalk/nbp/nbp_util.c
deleted file mode 100644 (file)
index 4cbea4b..0000000
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * $Id: nbp_util.c,v 1.5 2009-10-13 22:55:37 didg Exp $
- *
- * Copyright (c) 1990,1997 Regents of The University of Michigan.
- * All Rights Reserved. See COPYRIGHT.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <string.h>
-#include <signal.h>
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-
-#include <netatalk/endian.h>
-#include <netatalk/at.h>
-
-#include <atalk/nbp.h>
-#include <atalk/ddp.h>
-#include <atalk/util.h>
-
-#ifdef HAVE_NETDB_H
-#include <netdb.h>
-#endif /* HAVE_NETDB_H */
-
-#include  "nbp_conf.h"
-
-char           nbp_send[ 1024 ];
-char           nbp_recv[ 1024 ];
-u_char         nbp_port = 0;
-unsigned char   nbp_id = 0;
-
-int nbp_parse(char *data, struct nbpnve *nn, int len)
-{
-    struct nbptuple    nt;
-
-    memcpy( &nt, data, SZ_NBPTUPLE);
-    data += SZ_NBPTUPLE;
-    len -= SZ_NBPTUPLE;
-    if ( len < 0 ) {
-       return( -1 );
-    }
-
-#ifdef BSD4_4
-    nn->nn_sat.sat_len = sizeof( struct sockaddr_at );
-#endif /* BSD4_4 */
-    nn->nn_sat.sat_family = AF_APPLETALK;
-    nn->nn_sat.sat_addr.s_net = nt.nt_net;
-    nn->nn_sat.sat_addr.s_node = nt.nt_node;
-    nn->nn_sat.sat_port = nt.nt_port;
-
-    nn->nn_objlen = *data++;
-    len -= nn->nn_objlen + 1;
-    if ( len < 0 ) {
-       return( -1 );
-    }
-    if ( nn->nn_objlen > NBPSTRLEN ) {
-       return( -1 );
-    }
-    memcpy( nn->nn_obj, data, nn->nn_objlen );
-    data += nn->nn_objlen;
-
-    nn->nn_typelen = *data++;
-    len -= nn->nn_typelen + 1;
-    if ( len < 0 ) {
-       return( -1 );
-    }
-    if ( nn->nn_typelen > NBPSTRLEN ) {
-       return( 1 );
-    }
-    memcpy( nn->nn_type, data, nn->nn_typelen );
-
-    data += nn->nn_typelen;
-    nn->nn_zonelen = *data++;
-    len -= nn->nn_zonelen + 1;
-    if ( len < 0 ) {
-       return( -1 );
-    }
-    if ( nn->nn_zonelen > NBPSTRLEN ) {
-       return( 1 );
-    }
-    memcpy( nn->nn_zone, data, nn->nn_zonelen );
-
-    return( len );
-}
-
-#define NBPM_OBJ       (1<<1)
-#define NBPM_TYPE      (1<<2)
-#define NBPM_ZONE      (1<<3)
-
-int nbp_match(struct nbpnve *n1, struct nbpnve *n2, int flags)
-{
-    int                        match = 0;
-
-    if ( flags & NBPMATCH_NOZONE ) {
-       match |= NBPM_ZONE;
-    }
-
-    if ( !( flags & NBPMATCH_NOGLOB )) {
-       if ( n1->nn_objlen == 1 && n1->nn_obj[0] == '=' ) {
-           match |= NBPM_OBJ;
-       }
-       if ( n1->nn_typelen == 1 && n1->nn_type[0] == '=' ) {
-           match |= NBPM_TYPE;
-       }
-    }
-
-    if ( !( match & NBPM_OBJ )) {
-       if ( n1->nn_objlen != n2->nn_objlen ||
-               strndiacasecmp( n1->nn_obj, n2->nn_obj, n1->nn_objlen )) {
-           return( 0 );
-       }
-    }
-    if ( !( match & NBPM_TYPE )) {
-       if ( n1->nn_typelen != n2->nn_typelen ||
-               strndiacasecmp( n1->nn_type, n2->nn_type, n1->nn_typelen )) {
-           return( 0 );
-       }
-    }
-    if ( !( match & NBPM_ZONE )) {
-       if ( n1->nn_zonelen != n2->nn_zonelen ||
-               strndiacasecmp( n1->nn_zone, n2->nn_zone, n1->nn_zonelen )) {
-           return( 0 );
-       }
-    }
-
-    return( 1 );
-}
-
-int nbp_name(const char  *name, char **objp,char **typep,char **zonep)
-{
-    static char        buf[ 32 + 1 + 32 + 1 + 32 + 1 ];
-    char       *p;
-
-    if ( name ) {
-       if ( strlen( name ) + 1 > sizeof( buf )) {
-           return( -1 );
-       }
-       strcpy( buf, name );
-
-       if (( p = strrchr( buf, '@' )) != NULL ) {
-           *p++ = '\0';
-           *zonep = p;
-       }
-       if (( p = strrchr( buf, ':' )) != NULL ) {
-           *p++ = '\0';
-           *typep = p;
-       }
-       if ( *buf != '\0' ) {
-           *objp = buf;
-       }
-    }
-
-    return( 0 );
-}
diff --git a/libatalk/netddp/.gitignore b/libatalk/netddp/.gitignore
deleted file mode 100644 (file)
index b8c114c..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-Makefile
-Makefile.in
-*.lo
-*.la
-.deps
-.libs
-.gitignore
-netddp_open.o netddp_recvfrom.o netddp_sendto.o
diff --git a/libatalk/netddp/Makefile.am b/libatalk/netddp/Makefile.am
deleted file mode 100644 (file)
index 9f62087..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-# Makefile.am for libatalk/netddp/
-
-noinst_LTLIBRARIES = libnetddp.la
-
-libnetddp_la_SOURCES = netddp_open.c netddp_sendto.c netddp_recvfrom.c
diff --git a/libatalk/netddp/netddp_open.c b/libatalk/netddp/netddp_open.c
deleted file mode 100644 (file)
index 20ab8ef..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-/* 
- * $Id: netddp_open.c,v 1.9 2005-04-28 20:50:02 bfernhomberg Exp $
- *
- * Copyright (c) 1999 Adrian Sun (asun@zoology.washington.edu)
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- * All Rights Reserved. See COPYRIGHT.
- *
- * open a ddp socket and return the port and address assigned. return
- * various address info if requested as well.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-
-#ifdef MACOSX_SERVER
-#include <netat/appletalk.h>
-#include <netat/ddp.h>
-#endif /* MACOSX_SERVER */
-
-#include <netatalk/at.h>
-#include <atalk/netddp.h>
-
-int netddp_open(struct sockaddr_at *addr, struct sockaddr_at *bridge)
-{
-
-#ifdef NO_DDP
-    return -1;
-#else /* !NO_DDP */
-
-    int s;
-
-#ifdef MACOSX_SERVER
-    at_inet_t address, baddress;
-
-    if ((s = ddp_open(addr ? &addr->sat_port : NULL)) < 0)
-        return -1;
-
-    if (!addr)
-      return s;
-
-    if (rtmp_netinfo(s, &address, &baddress) < 0) {
-        ddp_close(s);
-       return -1;
-    }
-    
-    memcpy(&addr->sat_addr.s_net, &address.net, sizeof(addr->sat_addr.s_net));
-    addr->sat_addr.s_node = address.node;
-    addr->sat_port = address.socket;
-    if (bridge) {
-      memcpy(&bridge->sat_addr.s_net, &baddress.net, 
-            sizeof(bridge->sat_addr.s_net));
-      bridge->sat_addr.s_node = baddress.node;
-      bridge->sat_port = baddress.socket;
-    }
-#else /* MACOSX_SERVER */
-    socklen_t len;
-
-    if ((s = socket( AF_APPLETALK, SOCK_DGRAM, 0 )) < 0) 
-       return -1;
-    
-    if (!addr)
-       return s;
-
-    addr->sat_family = AF_APPLETALK;
-    /* rest of address should be initialized by the caller */
-    if (bind(s, (struct sockaddr *) addr, sizeof( struct sockaddr_at )) < 0 ) {
-        close(s);
-       return -1;
-    }
-
-    /* get the real address from the kernel */
-    len = sizeof( struct sockaddr_at);
-    if ( getsockname( s, (struct sockaddr *) addr, &len ) != 0 ) {
-        close(s);
-       return -1;
-    }
-#endif /* MACOSX_SERVER */
-
-    return s;
-#endif /* NO_DDP */
-}
diff --git a/libatalk/netddp/netddp_recvfrom.c b/libatalk/netddp/netddp_recvfrom.c
deleted file mode 100644 (file)
index 6e7a942..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/* 
- * $Id: netddp_recvfrom.c,v 1.5 2003-02-17 02:02:25 srittau Exp $
- *
- * Copyright (c) 1999 Adrian Sun (asun@zoology.washington.edu)
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- * All Rights Reserved. See COPYRIGHT.
- *
- * receive data.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#ifndef NO_DDP
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/uio.h>
-#include <errno.h>
-
-#ifdef MACOSX_SERVER
-#include <netat/appletalk.h>
-#include <netat/ddp.h>
-#endif /* MACOSX_SERVER */
-
-#include <netatalk/at.h>
-#include <netatalk/endian.h>
-#include <netatalk/ddp.h>
-#include <atalk/netddp.h>
-
-#ifndef MAX
-#define MAX(a, b)  ((a) < (b) ? (b) : (a))
-#endif /* ! MAX */
-
-#ifdef MACOSX_SERVER
-int netddp_recvfrom(int fd, void *buf, int buflen, unsigned int dummy, 
-                    struct sockaddr *addr, unsigned int *addrlen)
-{
-    ssize_t i;
-    struct ddpehdr ddphdr;
-    struct sockaddr_at *sat = (struct sockaddr_at *) addr;
-    struct iovec iov[2];
-
-    iov[0].iov_base = (void *) &ddphdr;
-    iov[0].iov_len = sizeof(ddphdr);
-    iov[1].iov_base = buf;
-    iov[1].iov_len = buflen;
-
-    while ((i = readv(fd, iov, 2)) < 0) {
-      if (errno != EINTR)
-       return -1;
-    }
-
-    if (addr) {
-      sat->sat_addr.s_net = ddphdr.deh_snet;
-      sat->sat_addr.s_node = ddphdr.deh_snode;
-      sat->sat_port = ddphdr.deh_sport;
-    }
-
-    return MAX(0, i - sizeof(ddphdr));
-}
-
-#endif /* os x server */
-#endif /* no ddp */
diff --git a/libatalk/netddp/netddp_sendto.c b/libatalk/netddp/netddp_sendto.c
deleted file mode 100644 (file)
index 407b94d..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-/* 
- * $Id: netddp_sendto.c,v 1.7 2005-04-28 20:50:02 bfernhomberg Exp $
- *
- * Copyright (c) 1999 Adrian Sun (asun@zoology.washington.edu)
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- * All Rights Reserved. See COPYRIGHT.
- *
- * send data.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#ifndef NO_DDP
-#include <string.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/uio.h>
-#include <errno.h>
-
-#ifdef MACOSX_SERVER
-#include <netat/appletalk.h>
-#include <netat/ddp.h>
-#endif /* MACOSX_SERVER */
-
-#include <netatalk/at.h>
-#include <netatalk/endian.h>
-#include <netatalk/ddp.h>
-#include <atalk/netddp.h>
-
-#ifndef MAX
-#define MAX(a, b)  ((a) < (b) ? (b) : (a))
-#endif /* ! MAX */
-
-#ifdef MACOSX_SERVER
-int netddp_sendto(int fd, void *buf, size_t buflen, unsigned int dummy, 
-                 const struct sockaddr *addr, unsigned int addrlen)
-{
-    ssize_t i;
-    struct ddpehdr ddphdr;
-    const struct sockaddr_at *sat = (const struct sockaddr_at *) addr;
-    struct iovec iov[2];
-
-    iov[0].iov_base = (void *) &ddphdr;
-    iov[0].iov_len = sizeof(ddphdr);
-    iov[1].iov_base = buf;
-    iov[1].iov_len = buflen;
-
-    if (!addr)
-      return -1;
-
-    memset(&ddphdr, 0, sizeof(ddphdr));
-    ddphdr.deh_len = htons(sizeof(ddphdr) + (u_int16_t) buflen);
-    ddphdr.deh_dnet = sat->sat_addr.s_net;
-    ddphdr.deh_dnode = sat->sat_addr.s_node;
-    ddphdr.deh_dport = sat->sat_port;
-    while ((i = writev(fd, iov, 2)) < 0) {
-      if (errno != EINTR)
-       return -1;
-    }
-
-    return MAX(0, i - sizeof(ddphdr));
-}
-
-#endif /* os x server */
-#endif /* no ddp */
index e2dc8b278ddf9bb0b8613829b9e9263df9b8d494..874baef6cbdb35f63c63a8c63d5402d14d25a14f 100644 (file)
@@ -1,8 +1,16 @@
 # Makefile.am for libatalk/tdb/
 
 noinst_LTLIBRARIES = libtdb.la
-
-libtdb_la_SOURCES = tdb.c \
-                    spinlock.c \
-                    spinlock.h
+noinst_HEADERS = tdb_private.h
+libtdb_la_SOURCES = check.c \
+       dump.c                  \
+       error.c                 \
+       freelist.c              \
+       freelistcheck.c \
+       io.c                    \
+       lock.c                  \
+       open.c                  \
+       tdb.c                   \
+       transaction.c   \
+       traverse.c
 
diff --git a/libatalk/tdb/check.c b/libatalk/tdb/check.c
new file mode 100644 (file)
index 0000000..f0a15f8
--- /dev/null
@@ -0,0 +1,423 @@
+ /*
+   Unix SMB/CIFS implementation.
+
+   trivial database library
+
+   Copyright (C) Rusty Russell            2009
+
+     ** NOTE! The following LGPL license applies to the tdb
+     ** library. This does NOT imply that all of Samba is released
+     ** under the LGPL
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*/
+#include "tdb_private.h"
+
+/* Since we opened it, these shouldn't fail unless it's recent corruption. */
+static bool tdb_check_header(struct tdb_context *tdb, tdb_off_t *recovery)
+{
+       struct tdb_header hdr;
+
+       if (tdb->methods->tdb_read(tdb, 0, &hdr, sizeof(hdr), DOCONV()) == -1)
+               return false;
+       if (strcmp(hdr.magic_food, TDB_MAGIC_FOOD) != 0)
+               goto corrupt;
+
+       CONVERT(hdr);
+       if (hdr.version != TDB_VERSION)
+               goto corrupt;
+
+       if (hdr.rwlocks != 0)
+               goto corrupt;
+
+       if (hdr.hash_size == 0)
+               goto corrupt;
+
+       if (hdr.hash_size != tdb->header.hash_size)
+               goto corrupt;
+
+       if (hdr.recovery_start != 0 &&
+           hdr.recovery_start < TDB_DATA_START(tdb->header.hash_size))
+               goto corrupt;
+
+       *recovery = hdr.recovery_start;
+       return true;
+
+corrupt:
+       tdb->ecode = TDB_ERR_CORRUPT;
+       TDB_LOG((tdb, TDB_DEBUG_ERROR, "Header is corrupt\n"));
+       return false;
+}
+
+/* Generic record header check. */
+static bool tdb_check_record(struct tdb_context *tdb,
+                            tdb_off_t off,
+                            const struct tdb_record *rec)
+{
+       tdb_off_t tailer;
+
+       /* Check rec->next: 0 or points to record offset, aligned. */
+       if (rec->next > 0 && rec->next < TDB_DATA_START(tdb->header.hash_size)){
+               TDB_LOG((tdb, TDB_DEBUG_ERROR,
+                        "Record offset %d too small next %d\n",
+                        off, rec->next));
+               goto corrupt;
+       }
+       if (rec->next + sizeof(*rec) < rec->next) {
+               TDB_LOG((tdb, TDB_DEBUG_ERROR,
+                        "Record offset %d too large next %d\n",
+                        off, rec->next));
+               goto corrupt;
+       }
+       if ((rec->next % TDB_ALIGNMENT) != 0) {
+               TDB_LOG((tdb, TDB_DEBUG_ERROR,
+                        "Record offset %d misaligned next %d\n",
+                        off, rec->next));
+               goto corrupt;
+       }
+       if (tdb->methods->tdb_oob(tdb, rec->next+sizeof(*rec), 0))
+               goto corrupt;
+
+       /* Check rec_len: similar to rec->next, implies next record. */
+       if ((rec->rec_len % TDB_ALIGNMENT) != 0) {
+               TDB_LOG((tdb, TDB_DEBUG_ERROR,
+                        "Record offset %d misaligned length %d\n",
+                        off, rec->rec_len));
+               goto corrupt;
+       }
+       /* Must fit tailer. */
+       if (rec->rec_len < sizeof(tailer)) {
+               TDB_LOG((tdb, TDB_DEBUG_ERROR,
+                        "Record offset %d too short length %d\n",
+                        off, rec->rec_len));
+               goto corrupt;
+       }
+       /* OOB allows "right at the end" access, so this works for last rec. */
+       if (tdb->methods->tdb_oob(tdb, off+sizeof(*rec)+rec->rec_len, 0))
+               goto corrupt;
+
+       /* Check tailer. */
+       if (tdb_ofs_read(tdb, off+sizeof(*rec)+rec->rec_len-sizeof(tailer),
+                        &tailer) == -1)
+               goto corrupt;
+       if (tailer != sizeof(*rec) + rec->rec_len) {
+               TDB_LOG((tdb, TDB_DEBUG_ERROR,
+                        "Record offset %d invalid tailer\n", off));
+               goto corrupt;
+       }
+
+       return true;
+
+corrupt:
+       tdb->ecode = TDB_ERR_CORRUPT;
+       return false;
+}
+
+/* Grab some bytes: may copy if can't use mmap.
+   Caller has already done bounds check. */
+static TDB_DATA get_bytes(struct tdb_context *tdb,
+                         tdb_off_t off, tdb_len_t len)
+{
+       TDB_DATA d;
+
+       d.dsize = len;
+
+       if (tdb->transaction == NULL && tdb->map_ptr != NULL)
+               d.dptr = (unsigned char *)tdb->map_ptr + off;
+       else
+               d.dptr = tdb_alloc_read(tdb, off, d.dsize);
+       return d;
+}
+
+/* Frees data if we're not able to simply use mmap. */
+static void put_bytes(struct tdb_context *tdb, TDB_DATA d)
+{
+       if (tdb->transaction == NULL && tdb->map_ptr != NULL)
+               return;
+       free(d.dptr);
+}
+
+/* We use the excellent Jenkins lookup3 hash; this is based on hash_word2.
+ * See: http://burtleburtle.net/bob/c/lookup3.c
+ */
+#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
+static void hash(uint32_t key, uint32_t *pc, uint32_t *pb)
+{
+       uint32_t a,b,c;
+
+       /* Set up the internal state */
+       a = b = c = 0xdeadbeef + *pc;
+       c += *pb;
+       a += key;
+       c ^= b; c -= rot(b,14);
+       a ^= c; a -= rot(c,11);
+       b ^= a; b -= rot(a,25);
+       c ^= b; c -= rot(b,16);
+       a ^= c; a -= rot(c,4);
+       b ^= a; b -= rot(a,14);
+       c ^= b; c -= rot(b,24);
+       *pc=c; *pb=b;
+}
+
+/*
+  We want to check that all free records are in the free list
+  (only once), and all free list entries are free records.  Similarly
+  for each hash chain of used records.
+
+  Doing that naively (without walking hash chains, since we want to be
+  linear) means keeping a list of records which have been seen in each
+  hash chain, and another of records pointed to (ie. next pointers
+  from records and the initial hash chain heads).  These two lists
+  should be equal.  This will take 8 bytes per record, and require
+  sorting at the end.
+
+  So instead, we record each offset in a bitmap such a way that
+  recording it twice will cancel out.  Since each offset should appear
+  exactly twice, the bitmap should be zero at the end.
+
+  The approach was inspired by Bloom Filters (see Wikipedia).  For
+  each value, we flip K bits in a bitmap of size N.  The number of
+  distinct arrangements is:
+
+       N! / (K! * (N-K)!)
+
+  Of course, not all arrangements are actually distinct, but testing
+  shows this formula to be close enough.
+
+  So, if K == 8 and N == 256, the probability of two things flipping the same
+  bits is 1 in 409,663,695,276,000.
+
+  Given that ldb uses a hash size of 10000, using 32 bytes per hash chain
+  (320k) seems reasonable.
+*/
+#define NUM_HASHES 8
+#define BITMAP_BITS 256
+
+static void bit_flip(unsigned char bits[], unsigned int idx)
+{
+       bits[idx / CHAR_BIT] ^= (1 << (idx % CHAR_BIT));
+}
+
+/* We record offsets in a bitmap for the particular chain it should be in.  */
+static void record_offset(unsigned char bits[], tdb_off_t off)
+{
+       uint32_t h1 = off, h2 = 0;
+       unsigned int i;
+
+       /* We get two good hash values out of jhash2, so we use both.  Then
+        * we keep going to produce further hash values. */
+       for (i = 0; i < NUM_HASHES / 2; i++) {
+               hash(off, &h1, &h2);
+               bit_flip(bits, h1 % BITMAP_BITS);
+               bit_flip(bits, h2 % BITMAP_BITS);
+               h2++;
+       }
+}
+
+/* Check that an in-use record is valid. */
+static bool tdb_check_used_record(struct tdb_context *tdb,
+                                 tdb_off_t off,
+                                 const struct tdb_record *rec,
+                                 unsigned char **hashes,
+                                 int (*check)(TDB_DATA, TDB_DATA, void *),
+                                 void *private_data)
+{
+       TDB_DATA key, data;
+
+       if (!tdb_check_record(tdb, off, rec))
+               return false;
+
+       /* key + data + tailer must fit in record */
+       if (rec->key_len + rec->data_len + sizeof(tdb_off_t) > rec->rec_len) {
+               TDB_LOG((tdb, TDB_DEBUG_ERROR,
+                        "Record offset %d too short for contents\n", off));
+               return false;
+       }
+
+       key = get_bytes(tdb, off + sizeof(*rec), rec->key_len);
+       if (!key.dptr)
+               return false;
+
+       if (tdb->hash_fn(&key) != rec->full_hash) {
+               TDB_LOG((tdb, TDB_DEBUG_ERROR,
+                        "Record offset %d has incorrect hash\n", off));
+               goto fail_put_key;
+       }
+
+       /* Mark this offset as a known value for this hash bucket. */
+       record_offset(hashes[BUCKET(rec->full_hash)+1], off);
+       /* And similarly if the next pointer is valid. */
+       if (rec->next)
+               record_offset(hashes[BUCKET(rec->full_hash)+1], rec->next);
+
+       /* If they supply a check function and this record isn't dead,
+          get data and feed it. */
+       if (check && rec->magic != TDB_DEAD_MAGIC) {
+               data = get_bytes(tdb, off + sizeof(*rec) + rec->key_len,
+                                rec->data_len);
+               if (!data.dptr)
+                       goto fail_put_key;
+
+               if (check(key, data, private_data) == -1)
+                       goto fail_put_data;
+               put_bytes(tdb, data);
+       }
+
+       put_bytes(tdb, key);
+       return true;
+
+fail_put_data:
+       put_bytes(tdb, data);
+fail_put_key:
+       put_bytes(tdb, key);
+       return false;
+}
+
+/* Check that an unused record is valid. */
+static bool tdb_check_free_record(struct tdb_context *tdb,
+                                 tdb_off_t off,
+                                 const struct tdb_record *rec,
+                                 unsigned char **hashes)
+{
+       if (!tdb_check_record(tdb, off, rec))
+               return false;
+
+       /* Mark this offset as a known value for the free list. */
+       record_offset(hashes[0], off);
+       /* And similarly if the next pointer is valid. */
+       if (rec->next)
+               record_offset(hashes[0], rec->next);
+       return true;
+}
+
+int tdb_check(struct tdb_context *tdb,
+             int (*check)(TDB_DATA key, TDB_DATA data, void *private_data),
+             void *private_data)
+{
+       unsigned int h;
+       unsigned char **hashes;
+       tdb_off_t off, recovery_start;
+       struct tdb_record rec;
+       bool found_recovery = false;
+
+       if (tdb_lockall(tdb) == -1)
+               return -1;
+
+       /* Make sure we know true size of the underlying file. */
+       tdb->methods->tdb_oob(tdb, tdb->map_size + 1, 1);
+
+       /* Header must be OK: also gets us the recovery ptr, if any. */
+       if (!tdb_check_header(tdb, &recovery_start))
+               goto unlock;
+
+       /* We should have the whole header, too. */
+       if (tdb->map_size < TDB_DATA_START(tdb->header.hash_size)) {
+               tdb->ecode = TDB_ERR_CORRUPT;
+               TDB_LOG((tdb, TDB_DEBUG_ERROR, "File too short for hashes\n"));
+               goto unlock;
+       }
+
+       /* One big malloc: pointers then bit arrays. */
+       hashes = (unsigned char **)calloc(
+                       1, sizeof(hashes[0]) * (1+tdb->header.hash_size)
+                       + BITMAP_BITS / CHAR_BIT * (1+tdb->header.hash_size));
+       if (!hashes) {
+               tdb->ecode = TDB_ERR_OOM;
+               goto unlock;
+       }
+
+       /* Initialize pointers */
+       hashes[0] = (unsigned char *)(&hashes[1+tdb->header.hash_size]);
+       for (h = 1; h < 1+tdb->header.hash_size; h++)
+               hashes[h] = hashes[h-1] + BITMAP_BITS / CHAR_BIT;
+
+       /* Freelist and hash headers are all in a row: read them. */
+       for (h = 0; h < 1+tdb->header.hash_size; h++) {
+               if (tdb_ofs_read(tdb, FREELIST_TOP + h*sizeof(tdb_off_t),
+                                &off) == -1)
+                       goto free;
+               if (off)
+                       record_offset(hashes[h], off);
+       }
+
+       /* For each record, read it in and check it's ok. */
+       for (off = TDB_DATA_START(tdb->header.hash_size);
+            off < tdb->map_size;
+            off += sizeof(rec) + rec.rec_len) {
+               if (tdb->methods->tdb_read(tdb, off, &rec, sizeof(rec),
+                                          DOCONV()) == -1)
+                       goto free;
+               switch (rec.magic) {
+               case TDB_MAGIC:
+               case TDB_DEAD_MAGIC:
+                       if (!tdb_check_used_record(tdb, off, &rec, hashes,
+                                                  check, private_data))
+                               goto free;
+                       break;
+               case TDB_FREE_MAGIC:
+                       if (!tdb_check_free_record(tdb, off, &rec, hashes))
+                               goto free;
+                       break;
+               case TDB_RECOVERY_MAGIC:
+               case 0: /* Used for invalid (or in-progress) recovery area. */
+                       if (recovery_start != off) {
+                               TDB_LOG((tdb, TDB_DEBUG_ERROR,
+                                        "Unexpected recovery record at offset %d\n",
+                                        off));
+                               goto free;
+                       }
+                       found_recovery = true;
+                       break;
+               default:
+                       tdb->ecode = TDB_ERR_CORRUPT;
+                       TDB_LOG((tdb, TDB_DEBUG_ERROR,
+                                "Bad magic 0x%x at offset %d\n",
+                                rec.magic, off));
+                       goto free;
+               }
+       }
+
+       /* Now, hashes should all be empty: each record exists and is referred
+        * to by one other. */
+       for (h = 0; h < 1+tdb->header.hash_size; h++) {
+               unsigned int i;
+               for (i = 0; i < BITMAP_BITS / CHAR_BIT; i++) {
+                       if (hashes[h][i] != 0) {
+                               tdb->ecode = TDB_ERR_CORRUPT;
+                               TDB_LOG((tdb, TDB_DEBUG_ERROR,
+                                        "Hashes do not match records\n"));
+                               goto free;
+                       }
+               }
+       }
+
+       /* We must have found recovery area if there was one. */
+       if (recovery_start != 0 && !found_recovery) {
+               TDB_LOG((tdb, TDB_DEBUG_ERROR,
+                        "Expected %s recovery area, got %s\n",
+                        recovery_start ? "a" : "no",
+                        found_recovery ? "one" : "none"));
+               goto free;
+       }
+
+       free(hashes);
+       tdb_unlockall(tdb);
+       return 0;
+
+free:
+       free(hashes);
+unlock:
+       tdb_unlockall(tdb);
+       return -1;
+}
diff --git a/libatalk/tdb/dump.c b/libatalk/tdb/dump.c
new file mode 100644 (file)
index 0000000..bdcbfab
--- /dev/null
@@ -0,0 +1,137 @@
+ /* 
+   Unix SMB/CIFS implementation.
+
+   trivial database library
+
+   Copyright (C) Andrew Tridgell              1999-2005
+   Copyright (C) Paul `Rusty' Russell             2000
+   Copyright (C) Jeremy Allison                           2000-2003
+   
+     ** NOTE! The following LGPL license applies to the tdb
+     ** library. This does NOT imply that all of Samba is released
+     ** under the LGPL
+   
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "tdb_private.h"
+
+static tdb_off_t tdb_dump_record(struct tdb_context *tdb, int hash,
+                                tdb_off_t offset)
+{
+       struct tdb_record rec;
+       tdb_off_t tailer_ofs, tailer;
+
+       if (tdb->methods->tdb_read(tdb, offset, (char *)&rec, 
+                                  sizeof(rec), DOCONV()) == -1) {
+               printf("ERROR: failed to read record at %u\n", offset);
+               return 0;
+       }
+
+       printf(" rec: hash=%d offset=0x%08x next=0x%08x rec_len=%d "
+              "key_len=%d data_len=%d full_hash=0x%x magic=0x%x\n",
+              hash, offset, rec.next, rec.rec_len, rec.key_len, rec.data_len,
+              rec.full_hash, rec.magic);
+
+       tailer_ofs = offset + sizeof(rec) + rec.rec_len - sizeof(tdb_off_t);
+
+       if (tdb_ofs_read(tdb, tailer_ofs, &tailer) == -1) {
+               printf("ERROR: failed to read tailer at %u\n", tailer_ofs);
+               return rec.next;
+       }
+
+       if (tailer != rec.rec_len + sizeof(rec)) {
+               printf("ERROR: tailer does not match record! tailer=%u totalsize=%u\n",
+                               (unsigned int)tailer, (unsigned int)(rec.rec_len + sizeof(rec)));
+       }
+       return rec.next;
+}
+
+static int tdb_dump_chain(struct tdb_context *tdb, int i)
+{
+       tdb_off_t rec_ptr, top;
+
+       top = TDB_HASH_TOP(i);
+
+       if (tdb_lock(tdb, i, F_WRLCK) != 0)
+               return -1;
+
+       if (tdb_ofs_read(tdb, top, &rec_ptr) == -1)
+               return tdb_unlock(tdb, i, F_WRLCK);
+
+       if (rec_ptr)
+               printf("hash=%d\n", i);
+
+       while (rec_ptr) {
+               rec_ptr = tdb_dump_record(tdb, i, rec_ptr);
+       }
+
+       return tdb_unlock(tdb, i, F_WRLCK);
+}
+
+void tdb_dump_all(struct tdb_context *tdb)
+{
+       int i;
+       for (i=0;i<tdb->header.hash_size;i++) {
+               tdb_dump_chain(tdb, i);
+       }
+       printf("freelist:\n");
+       tdb_dump_chain(tdb, -1);
+}
+
+int tdb_printfreelist(struct tdb_context *tdb)
+{
+       int ret;
+       long total_free = 0;
+       tdb_off_t offset, rec_ptr;
+       struct tdb_record rec;
+
+       if ((ret = tdb_lock(tdb, -1, F_WRLCK)) != 0)
+               return ret;
+
+       offset = FREELIST_TOP;
+
+       /* read in the freelist top */
+       if (tdb_ofs_read(tdb, offset, &rec_ptr) == -1) {
+               tdb_unlock(tdb, -1, F_WRLCK);
+               return 0;
+       }
+
+       printf("freelist top=[0x%08x]\n", rec_ptr );
+       while (rec_ptr) {
+               if (tdb->methods->tdb_read(tdb, rec_ptr, (char *)&rec, 
+                                          sizeof(rec), DOCONV()) == -1) {
+                       tdb_unlock(tdb, -1, F_WRLCK);
+                       return -1;
+               }
+
+               if (rec.magic != TDB_FREE_MAGIC) {
+                       printf("bad magic 0x%08x in free list\n", rec.magic);
+                       tdb_unlock(tdb, -1, F_WRLCK);
+                       return -1;
+               }
+
+               printf("entry offset=[0x%08x], rec.rec_len = [0x%08x (%d)] (end = 0x%08x)\n", 
+                      rec_ptr, rec.rec_len, rec.rec_len, rec_ptr + rec.rec_len);
+               total_free += rec.rec_len;
+
+               /* move to the next record */
+               rec_ptr = rec.next;
+       }
+       printf("total rec_len = [0x%08x (%d)]\n", (int)total_free, 
+               (int)total_free);
+
+       return tdb_unlock(tdb, -1, F_WRLCK);
+}
+
diff --git a/libatalk/tdb/error.c b/libatalk/tdb/error.c
new file mode 100644 (file)
index 0000000..195ab23
--- /dev/null
@@ -0,0 +1,57 @@
+ /* 
+   Unix SMB/CIFS implementation.
+
+   trivial database library
+
+   Copyright (C) Andrew Tridgell              1999-2005
+   Copyright (C) Paul `Rusty' Russell             2000
+   Copyright (C) Jeremy Allison                           2000-2003
+   
+     ** NOTE! The following LGPL license applies to the tdb
+     ** library. This does NOT imply that all of Samba is released
+     ** under the LGPL
+   
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "tdb_private.h"
+
+enum TDB_ERROR tdb_error(struct tdb_context *tdb)
+{
+       return tdb->ecode;
+}
+
+static struct tdb_errname {
+       enum TDB_ERROR ecode; const char *estring;
+} emap[] = { {TDB_SUCCESS, "Success"},
+            {TDB_ERR_CORRUPT, "Corrupt database"},
+            {TDB_ERR_IO, "IO Error"},
+            {TDB_ERR_LOCK, "Locking error"},
+            {TDB_ERR_OOM, "Out of memory"},
+            {TDB_ERR_EXISTS, "Record exists"},
+            {TDB_ERR_NOLOCK, "Lock exists on other keys"},
+            {TDB_ERR_EINVAL, "Invalid parameter"},
+            {TDB_ERR_NOEXIST, "Record does not exist"},
+            {TDB_ERR_RDONLY, "write not permitted"} };
+
+/* Error string for the last tdb error */
+const char *tdb_errorstr(struct tdb_context *tdb)
+{
+       uint32_t i;
+       for (i = 0; i < sizeof(emap) / sizeof(struct tdb_errname); i++)
+               if (tdb->ecode == emap[i].ecode)
+                       return emap[i].estring;
+       return "Invalid error code";
+}
+
diff --git a/libatalk/tdb/freelist.c b/libatalk/tdb/freelist.c
new file mode 100644 (file)
index 0000000..8113b54
--- /dev/null
@@ -0,0 +1,386 @@
+ /* 
+   Unix SMB/CIFS implementation.
+
+   trivial database library
+
+   Copyright (C) Andrew Tridgell              1999-2005
+   Copyright (C) Paul `Rusty' Russell             2000
+   Copyright (C) Jeremy Allison                           2000-2003
+   
+     ** NOTE! The following LGPL license applies to the tdb
+     ** library. This does NOT imply that all of Samba is released
+     ** under the LGPL
+   
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "tdb_private.h"
+
+/* 'right' merges can involve O(n^2) cost when combined with a
+   traverse, so they are disabled until we find a way to do them in 
+   O(1) time
+*/
+#define USE_RIGHT_MERGES 0
+
+/* read a freelist record and check for simple errors */
+int tdb_rec_free_read(struct tdb_context *tdb, tdb_off_t off, struct tdb_record *rec)
+{
+       if (tdb->methods->tdb_read(tdb, off, rec, sizeof(*rec),DOCONV()) == -1)
+               return -1;
+
+       if (rec->magic == TDB_MAGIC) {
+               /* this happens when a app is showdown while deleting a record - we should
+                  not completely fail when this happens */
+               TDB_LOG((tdb, TDB_DEBUG_WARNING, "tdb_rec_free_read non-free magic 0x%x at offset=%d - fixing\n", 
+                        rec->magic, off));
+               rec->magic = TDB_FREE_MAGIC;
+               if (tdb->methods->tdb_write(tdb, off, rec, sizeof(*rec)) == -1)
+                       return -1;
+       }
+
+       if (rec->magic != TDB_FREE_MAGIC) {
+               /* Ensure ecode is set for log fn. */
+               tdb->ecode = TDB_ERR_CORRUPT;
+               TDB_LOG((tdb, TDB_DEBUG_WARNING, "tdb_rec_free_read bad magic 0x%x at offset=%d\n", 
+                          rec->magic, off));
+               return -1;
+       }
+       if (tdb->methods->tdb_oob(tdb, rec->next+sizeof(*rec), 0) != 0)
+               return -1;
+       return 0;
+}
+
+
+#if USE_RIGHT_MERGES
+/* Remove an element from the freelist.  Must have alloc lock. */
+static int remove_from_freelist(struct tdb_context *tdb, tdb_off_t off, tdb_off_t next)
+{
+       tdb_off_t last_ptr, i;
+
+       /* read in the freelist top */
+       last_ptr = FREELIST_TOP;
+       while (tdb_ofs_read(tdb, last_ptr, &i) != -1 && i != 0) {
+               if (i == off) {
+                       /* We've found it! */
+                       return tdb_ofs_write(tdb, last_ptr, &next);
+               }
+               /* Follow chain (next offset is at start of record) */
+               last_ptr = i;
+       }
+       tdb->ecode = TDB_ERR_CORRUPT;
+       TDB_LOG((tdb, TDB_DEBUG_FATAL,"remove_from_freelist: not on list at off=%d\n", off));
+       return -1;
+}
+#endif
+
+
+/* update a record tailer (must hold allocation lock) */
+static int update_tailer(struct tdb_context *tdb, tdb_off_t offset,
+                        const struct tdb_record *rec)
+{
+       tdb_off_t totalsize;
+
+       /* Offset of tailer from record header */
+       totalsize = sizeof(*rec) + rec->rec_len;
+       return tdb_ofs_write(tdb, offset + totalsize - sizeof(tdb_off_t),
+                        &totalsize);
+}
+
+/* Add an element into the freelist. Merge adjacent records if
+   neccessary. */
+int tdb_free(struct tdb_context *tdb, tdb_off_t offset, struct tdb_record *rec)
+{
+       /* Allocation and tailer lock */
+       if (tdb_lock(tdb, -1, F_WRLCK) != 0)
+               return -1;
+
+       /* set an initial tailer, so if we fail we don't leave a bogus record */
+       if (update_tailer(tdb, offset, rec) != 0) {
+               TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_free: update_tailer failed!\n"));
+               goto fail;
+       }
+
+#if USE_RIGHT_MERGES
+       /* Look right first (I'm an Australian, dammit) */
+       if (offset + sizeof(*rec) + rec->rec_len + sizeof(*rec) <= tdb->map_size) {
+               tdb_off_t right = offset + sizeof(*rec) + rec->rec_len;
+               struct tdb_record r;
+
+               if (tdb->methods->tdb_read(tdb, right, &r, sizeof(r), DOCONV()) == -1) {
+                       TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_free: right read failed at %u\n", right));
+                       goto left;
+               }
+
+               /* If it's free, expand to include it. */
+               if (r.magic == TDB_FREE_MAGIC) {
+                       if (remove_from_freelist(tdb, right, r.next) == -1) {
+                               TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_free: right free failed at %u\n", right));
+                               goto left;
+                       }
+                       rec->rec_len += sizeof(r) + r.rec_len;
+                       if (update_tailer(tdb, offset, rec) == -1) {
+                               TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_free: update_tailer failed at %u\n", offset));
+                               goto fail;
+                       }
+               }
+       }
+left:
+#endif
+
+       /* Look left */
+       if (offset - sizeof(tdb_off_t) > TDB_DATA_START(tdb->header.hash_size)) {
+               tdb_off_t left = offset - sizeof(tdb_off_t);
+               struct tdb_record l;
+               tdb_off_t leftsize;
+               
+               /* Read in tailer and jump back to header */
+               if (tdb_ofs_read(tdb, left, &leftsize) == -1) {
+                       TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_free: left offset read failed at %u\n", left));
+                       goto update;
+               }
+
+               /* it could be uninitialised data */
+               if (leftsize == 0 || leftsize == TDB_PAD_U32) {
+                       goto update;
+               }
+
+               left = offset - leftsize;
+
+               if (leftsize > offset ||
+                   left < TDB_DATA_START(tdb->header.hash_size)) {
+                       goto update;
+               }
+
+               /* Now read in the left record */
+               if (tdb->methods->tdb_read(tdb, left, &l, sizeof(l), DOCONV()) == -1) {
+                       TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_free: left read failed at %u (%u)\n", left, leftsize));
+                       goto update;
+               }
+
+               /* If it's free, expand to include it. */
+               if (l.magic == TDB_FREE_MAGIC) {
+                       /* we now merge the new record into the left record, rather than the other 
+                          way around. This makes the operation O(1) instead of O(n). This change
+                          prevents traverse from being O(n^2) after a lot of deletes */
+                       l.rec_len += sizeof(*rec) + rec->rec_len;
+                       if (tdb_rec_write(tdb, left, &l) == -1) {
+                               TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_free: update_left failed at %u\n", left));
+                               goto fail;
+                       }
+                       if (update_tailer(tdb, left, &l) == -1) {
+                               TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_free: update_tailer failed at %u\n", offset));
+                               goto fail;
+                       }
+                       tdb_unlock(tdb, -1, F_WRLCK);
+                       return 0;
+               }
+       }
+
+update:
+
+       /* Now, prepend to free list */
+       rec->magic = TDB_FREE_MAGIC;
+
+       if (tdb_ofs_read(tdb, FREELIST_TOP, &rec->next) == -1 ||
+           tdb_rec_write(tdb, offset, rec) == -1 ||
+           tdb_ofs_write(tdb, FREELIST_TOP, &offset) == -1) {
+               TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_free record write failed at offset=%d\n", offset));
+               goto fail;
+       }
+
+       /* And we're done. */
+       tdb_unlock(tdb, -1, F_WRLCK);
+       return 0;
+
+ fail:
+       tdb_unlock(tdb, -1, F_WRLCK);
+       return -1;
+}
+
+
+
+/* 
+   the core of tdb_allocate - called when we have decided which
+   free list entry to use
+
+   Note that we try to allocate by grabbing data from the end of an existing record,
+   not the beginning. This is so the left merge in a free is more likely to be
+   able to free up the record without fragmentation
+ */
+static tdb_off_t tdb_allocate_ofs(struct tdb_context *tdb, 
+                                 tdb_len_t length, tdb_off_t rec_ptr,
+                                 struct tdb_record *rec, tdb_off_t last_ptr)
+{
+#define MIN_REC_SIZE (sizeof(struct tdb_record) + sizeof(tdb_off_t) + 8)
+
+       if (rec->rec_len < length + MIN_REC_SIZE) {
+               /* we have to grab the whole record */
+
+               /* unlink it from the previous record */
+               if (tdb_ofs_write(tdb, last_ptr, &rec->next) == -1) {
+                       return 0;
+               }
+
+               /* mark it not free */
+               rec->magic = TDB_MAGIC;
+               if (tdb_rec_write(tdb, rec_ptr, rec) == -1) {
+                       return 0;
+               }
+               return rec_ptr;
+       }
+
+       /* we're going to just shorten the existing record */
+       rec->rec_len -= (length + sizeof(*rec));
+       if (tdb_rec_write(tdb, rec_ptr, rec) == -1) {
+               return 0;
+       }
+       if (update_tailer(tdb, rec_ptr, rec) == -1) {
+               return 0;
+       }
+
+       /* and setup the new record */
+       rec_ptr += sizeof(*rec) + rec->rec_len; 
+
+       memset(rec, '\0', sizeof(*rec));
+       rec->rec_len = length;
+       rec->magic = TDB_MAGIC;
+
+       if (tdb_rec_write(tdb, rec_ptr, rec) == -1) {
+               return 0;
+       }
+
+       if (update_tailer(tdb, rec_ptr, rec) == -1) {
+               return 0;
+       }
+
+       return rec_ptr;
+}
+
+/* allocate some space from the free list. The offset returned points
+   to a unconnected tdb_record within the database with room for at
+   least length bytes of total data
+
+   0 is returned if the space could not be allocated
+ */
+tdb_off_t tdb_allocate(struct tdb_context *tdb, tdb_len_t length, struct tdb_record *rec)
+{
+       tdb_off_t rec_ptr, last_ptr, newrec_ptr;
+       struct {
+               tdb_off_t rec_ptr, last_ptr;
+               tdb_len_t rec_len;
+       } bestfit;
+       float multiplier = 1.0;
+
+       if (tdb_lock(tdb, -1, F_WRLCK) == -1)
+               return 0;
+
+       /* over-allocate to reduce fragmentation */
+       length *= 1.25;
+
+       /* Extra bytes required for tailer */
+       length += sizeof(tdb_off_t);
+       length = TDB_ALIGN(length, TDB_ALIGNMENT);
+
+ again:
+       last_ptr = FREELIST_TOP;
+
+       /* read in the freelist top */
+       if (tdb_ofs_read(tdb, FREELIST_TOP, &rec_ptr) == -1)
+               goto fail;
+
+       bestfit.rec_ptr = 0;
+       bestfit.last_ptr = 0;
+       bestfit.rec_len = 0;
+
+       /* 
+          this is a best fit allocation strategy. Originally we used
+          a first fit strategy, but it suffered from massive fragmentation
+          issues when faced with a slowly increasing record size.
+        */
+       while (rec_ptr) {
+               if (tdb_rec_free_read(tdb, rec_ptr, rec) == -1) {
+                       goto fail;
+               }
+
+               if (rec->rec_len >= length) {
+                       if (bestfit.rec_ptr == 0 ||
+                           rec->rec_len < bestfit.rec_len) {
+                               bestfit.rec_len = rec->rec_len;
+                               bestfit.rec_ptr = rec_ptr;
+                               bestfit.last_ptr = last_ptr;
+                       }
+               }
+
+               /* move to the next record */
+               last_ptr = rec_ptr;
+               rec_ptr = rec->next;
+
+               /* if we've found a record that is big enough, then
+                  stop searching if its also not too big. The
+                  definition of 'too big' changes as we scan
+                  through */
+               if (bestfit.rec_len > 0 &&
+                   bestfit.rec_len < length * multiplier) {
+                       break;
+               }
+               
+               /* this multiplier means we only extremely rarely
+                  search more than 50 or so records. At 50 records we
+                  accept records up to 11 times larger than what we
+                  want */
+               multiplier *= 1.05;
+       }
+
+       if (bestfit.rec_ptr != 0) {
+               if (tdb_rec_free_read(tdb, bestfit.rec_ptr, rec) == -1) {
+                       goto fail;
+               }
+
+               newrec_ptr = tdb_allocate_ofs(tdb, length, bestfit.rec_ptr, 
+                                             rec, bestfit.last_ptr);
+               tdb_unlock(tdb, -1, F_WRLCK);
+               return newrec_ptr;
+       }
+
+       /* we didn't find enough space. See if we can expand the
+          database and if we can then try again */
+       if (tdb_expand(tdb, length + sizeof(*rec)) == 0)
+               goto again;
+ fail:
+       tdb_unlock(tdb, -1, F_WRLCK);
+       return 0;
+}
+
+
+
+/* 
+   return the size of the freelist - used to decide if we should repack 
+*/
+int tdb_freelist_size(struct tdb_context *tdb)
+{
+       tdb_off_t ptr;
+       int count=0;
+
+       if (tdb_lock(tdb, -1, F_RDLCK) == -1) {
+               return -1;
+       }
+
+       ptr = FREELIST_TOP;
+       while (tdb_ofs_read(tdb, ptr, &ptr) == 0 && ptr != 0) {
+               count++;
+       }
+
+       tdb_unlock(tdb, -1, F_RDLCK);
+       return count;
+}
diff --git a/libatalk/tdb/freelistcheck.c b/libatalk/tdb/freelistcheck.c
new file mode 100644 (file)
index 0000000..8d1ebab
--- /dev/null
@@ -0,0 +1,109 @@
+/*
+   Unix SMB/CIFS implementation.
+
+   trivial database library
+
+   Copyright (C) Jeremy Allison                    2006
+
+     ** NOTE! The following LGPL license applies to the tdb
+     ** library. This does NOT imply that all of Samba is released
+     ** under the LGPL
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "tdb_private.h"
+
+/* Check the freelist is good and contains no loops.
+   Very memory intensive - only do this as a consistency
+   checker. Heh heh - uses an in memory tdb as the storage
+   for the "seen" record list. For some reason this strikes
+   me as extremely clever as I don't have to write another tree
+   data structure implementation :-).
+ */
+
+static int seen_insert(struct tdb_context *mem_tdb, tdb_off_t rec_ptr)
+{
+       TDB_DATA key, data;
+
+       memset(&data, '\0', sizeof(data));
+       key.dptr = (unsigned char *)&rec_ptr;
+       key.dsize = sizeof(rec_ptr);
+       return tdb_store(mem_tdb, key, data, TDB_INSERT);
+}
+
+int tdb_validate_freelist(struct tdb_context *tdb, int *pnum_entries)
+{
+       struct tdb_context *mem_tdb = NULL;
+       struct tdb_record rec;
+       tdb_off_t rec_ptr, last_ptr;
+       int ret = -1;
+
+       *pnum_entries = 0;
+
+       mem_tdb = tdb_open("flval", tdb->header.hash_size,
+                               TDB_INTERNAL, O_RDWR, 0600);
+       if (!mem_tdb) {
+               return -1;
+       }
+
+       if (tdb_lock(tdb, -1, F_WRLCK) == -1) {
+               tdb_close(mem_tdb);
+               return 0;
+       }
+
+       last_ptr = FREELIST_TOP;
+
+       /* Store the FREELIST_TOP record. */
+       if (seen_insert(mem_tdb, last_ptr) == -1) {
+               tdb->ecode = TDB_ERR_CORRUPT;
+               ret = -1;
+               goto fail;
+       }
+
+       /* read in the freelist top */
+       if (tdb_ofs_read(tdb, FREELIST_TOP, &rec_ptr) == -1) {
+               goto fail;
+       }
+
+       while (rec_ptr) {
+
+               /* If we can't store this record (we've seen it
+                  before) then the free list has a loop and must
+                  be corrupt. */
+
+               if (seen_insert(mem_tdb, rec_ptr)) {
+                       tdb->ecode = TDB_ERR_CORRUPT;
+                       ret = -1;
+                       goto fail;
+               }
+
+               if (tdb_rec_free_read(tdb, rec_ptr, &rec) == -1) {
+                       goto fail;
+               }
+
+               /* move to the next record */
+               last_ptr = rec_ptr;
+               rec_ptr = rec.next;
+               *pnum_entries += 1;
+       }
+
+       ret = 0;
+
+  fail:
+
+       tdb_close(mem_tdb);
+       tdb_unlock(tdb, -1, F_WRLCK);
+       return ret;
+}
diff --git a/libatalk/tdb/io.c b/libatalk/tdb/io.c
new file mode 100644 (file)
index 0000000..d549715
--- /dev/null
@@ -0,0 +1,473 @@
+ /* 
+   Unix SMB/CIFS implementation.
+
+   trivial database library
+
+   Copyright (C) Andrew Tridgell              1999-2005
+   Copyright (C) Paul `Rusty' Russell             2000
+   Copyright (C) Jeremy Allison                           2000-2003
+   
+     ** NOTE! The following LGPL license applies to the tdb
+     ** library. This does NOT imply that all of Samba is released
+     ** under the LGPL
+   
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+
+#include "tdb_private.h"
+
+/* check for an out of bounds access - if it is out of bounds then
+   see if the database has been expanded by someone else and expand
+   if necessary 
+   note that "len" is the minimum length needed for the db
+*/
+static int tdb_oob(struct tdb_context *tdb, tdb_off_t len, int probe)
+{
+       struct stat st;
+       if (len <= tdb->map_size)
+               return 0;
+       if (tdb->flags & TDB_INTERNAL) {
+               if (!probe) {
+                       /* Ensure ecode is set for log fn. */
+                       tdb->ecode = TDB_ERR_IO;
+                       TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_oob len %d beyond internal malloc size %d\n",
+                                (int)len, (int)tdb->map_size));
+               }
+               return -1;
+       }
+
+       if (fstat(tdb->fd, &st) == -1) {
+               tdb->ecode = TDB_ERR_IO;
+               return -1;
+       }
+
+       if (st.st_size < (size_t)len) {
+               if (!probe) {
+                       /* Ensure ecode is set for log fn. */
+                       tdb->ecode = TDB_ERR_IO;
+                       TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_oob len %d beyond eof at %d\n",
+                                (int)len, (int)st.st_size));
+               }
+               return -1;
+       }
+
+       /* Unmap, update size, remap */
+       if (tdb_munmap(tdb) == -1) {
+               tdb->ecode = TDB_ERR_IO;
+               return -1;
+       }
+       tdb->map_size = st.st_size;
+       tdb_mmap(tdb);
+       return 0;
+}
+
+/* write a lump of data at a specified offset */
+static int tdb_write(struct tdb_context *tdb, tdb_off_t off, 
+                    const void *buf, tdb_len_t len)
+{
+       if (len == 0) {
+               return 0;
+       }
+
+       if (tdb->read_only || tdb->traverse_read) {
+               tdb->ecode = TDB_ERR_RDONLY;
+               return -1;
+       }
+
+       if (tdb->methods->tdb_oob(tdb, off + len, 0) != 0)
+               return -1;
+
+       if (tdb->map_ptr) {
+               memcpy(off + (char *)tdb->map_ptr, buf, len);
+       } else {
+               ssize_t written = pwrite(tdb->fd, buf, len, off);
+               if ((written != (ssize_t)len) && (written != -1)) {
+                       /* try once more */
+                       tdb->ecode = TDB_ERR_IO;
+                       TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_write: wrote only "
+                                "%d of %d bytes at %d, trying once more\n",
+                                (int)written, len, off));
+                       written = pwrite(tdb->fd, (const char *)buf+written,
+                                        len-written,
+                                        off+written);
+               }
+               if (written == -1) {
+                       /* Ensure ecode is set for log fn. */
+                       tdb->ecode = TDB_ERR_IO;
+                       TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_write failed at %d "
+                                "len=%d (%s)\n", off, len, strerror(errno)));
+                       return -1;
+               } else if (written != (ssize_t)len) {
+                       tdb->ecode = TDB_ERR_IO;
+                       TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_write: failed to "
+                                "write %d bytes at %d in two attempts\n",
+                                len, off));
+                       return -1;
+               }
+       }
+       return 0;
+}
+
+/* Endian conversion: we only ever deal with 4 byte quantities */
+void *tdb_convert(void *buf, uint32_t size)
+{
+       uint32_t i, *p = (uint32_t *)buf;
+       for (i = 0; i < size / 4; i++)
+               p[i] = TDB_BYTEREV(p[i]);
+       return buf;
+}
+
+
+/* read a lump of data at a specified offset, maybe convert */
+static int tdb_read(struct tdb_context *tdb, tdb_off_t off, void *buf, 
+                   tdb_len_t len, int cv)
+{
+       if (tdb->methods->tdb_oob(tdb, off + len, 0) != 0) {
+               return -1;
+       }
+
+       if (tdb->map_ptr) {
+               memcpy(buf, off + (char *)tdb->map_ptr, len);
+       } else {
+               ssize_t ret = pread(tdb->fd, buf, len, off);
+               if (ret != (ssize_t)len) {
+                       /* Ensure ecode is set for log fn. */
+                       tdb->ecode = TDB_ERR_IO;
+                       TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_read failed at %d "
+                                "len=%d ret=%d (%s) map_size=%d\n",
+                                (int)off, (int)len, (int)ret, strerror(errno),
+                                (int)tdb->map_size));
+                       return -1;
+               }
+       }
+       if (cv) {
+               tdb_convert(buf, len);
+       }
+       return 0;
+}
+
+
+
+/*
+  do an unlocked scan of the hash table heads to find the next non-zero head. The value
+  will then be confirmed with the lock held
+*/             
+static void tdb_next_hash_chain(struct tdb_context *tdb, uint32_t *chain)
+{
+       uint32_t h = *chain;
+       if (tdb->map_ptr) {
+               for (;h < tdb->header.hash_size;h++) {
+                       if (0 != *(uint32_t *)(TDB_HASH_TOP(h) + (unsigned char *)tdb->map_ptr)) {
+                               break;
+                       }
+               }
+       } else {
+               uint32_t off=0;
+               for (;h < tdb->header.hash_size;h++) {
+                       if (tdb_ofs_read(tdb, TDB_HASH_TOP(h), &off) != 0 || off != 0) {
+                               break;
+                       }
+               }
+       }
+       (*chain) = h;
+}
+
+
+int tdb_munmap(struct tdb_context *tdb)
+{
+       if (tdb->flags & TDB_INTERNAL)
+               return 0;
+
+#ifdef HAVE_MMAP
+       if (tdb->map_ptr) {
+               int ret;
+
+               ret = munmap(tdb->map_ptr, tdb->map_size);
+               if (ret != 0)
+                       return ret;
+       }
+#endif
+       tdb->map_ptr = NULL;
+       return 0;
+}
+
+void tdb_mmap(struct tdb_context *tdb)
+{
+       if (tdb->flags & TDB_INTERNAL)
+               return;
+
+#ifdef HAVE_MMAP
+       if (!(tdb->flags & TDB_NOMMAP)) {
+               tdb->map_ptr = mmap(NULL, tdb->map_size, 
+                                   PROT_READ|(tdb->read_only? 0:PROT_WRITE), 
+                                   MAP_SHARED|MAP_FILE, tdb->fd, 0);
+
+               /*
+                * NB. When mmap fails it returns MAP_FAILED *NOT* NULL !!!!
+                */
+
+               if (tdb->map_ptr == MAP_FAILED) {
+                       tdb->map_ptr = NULL;
+                       TDB_LOG((tdb, TDB_DEBUG_WARNING, "tdb_mmap failed for size %d (%s)\n", 
+                                tdb->map_size, strerror(errno)));
+               }
+       } else {
+               tdb->map_ptr = NULL;
+       }
+#else
+       tdb->map_ptr = NULL;
+#endif
+}
+
+/* expand a file.  we prefer to use ftruncate, as that is what posix
+  says to use for mmap expansion */
+static int tdb_expand_file(struct tdb_context *tdb, tdb_off_t size, tdb_off_t addition)
+{
+       char buf[8192];
+
+       if (tdb->read_only || tdb->traverse_read) {
+               tdb->ecode = TDB_ERR_RDONLY;
+               return -1;
+       }
+
+       if (ftruncate(tdb->fd, size+addition) == -1) {
+               char b = 0;
+               ssize_t written = pwrite(tdb->fd,  &b, 1, (size+addition) - 1);
+               if (written == 0) {
+                       /* try once more, potentially revealing errno */
+                       written = pwrite(tdb->fd,  &b, 1, (size+addition) - 1);
+               }
+               if (written == 0) {
+                       /* again - give up, guessing errno */
+                       errno = ENOSPC;
+               }
+               if (written != 1) {
+                       TDB_LOG((tdb, TDB_DEBUG_FATAL, "expand_file to %d failed (%s)\n", 
+                                size+addition, strerror(errno)));
+                       return -1;
+               }
+       }
+
+       /* now fill the file with something. This ensures that the
+          file isn't sparse, which would be very bad if we ran out of
+          disk. This must be done with write, not via mmap */
+       memset(buf, TDB_PAD_BYTE, sizeof(buf));
+       while (addition) {
+               size_t n = addition>sizeof(buf)?sizeof(buf):addition;
+               ssize_t written = pwrite(tdb->fd, buf, n, size);
+               if (written == 0) {
+                       /* prevent infinite loops: try _once_ more */
+                       written = pwrite(tdb->fd, buf, n, size);
+               }
+               if (written == 0) {
+                       /* give up, trying to provide a useful errno */
+                       TDB_LOG((tdb, TDB_DEBUG_FATAL, "expand_file write "
+                               "returned 0 twice: giving up!\n"));
+                       errno = ENOSPC;
+                       return -1;
+               } else if (written == -1) {
+                       TDB_LOG((tdb, TDB_DEBUG_FATAL, "expand_file write of "
+                                "%d bytes failed (%s)\n", (int)n,
+                                strerror(errno)));
+                       return -1;
+               } else if (written != n) {
+                       TDB_LOG((tdb, TDB_DEBUG_WARNING, "expand_file: wrote "
+                                "only %d of %d bytes - retrying\n", (int)written,
+                                (int)n));
+               }
+               addition -= written;
+               size += written;
+       }
+       return 0;
+}
+
+
+/* expand the database at least size bytes by expanding the underlying
+   file and doing the mmap again if necessary */
+int tdb_expand(struct tdb_context *tdb, tdb_off_t size)
+{
+       struct tdb_record rec;
+       tdb_off_t offset, new_size;     
+
+       if (tdb_lock(tdb, -1, F_WRLCK) == -1) {
+               TDB_LOG((tdb, TDB_DEBUG_ERROR, "lock failed in tdb_expand\n"));
+               return -1;
+       }
+
+       /* must know about any previous expansions by another process */
+       tdb->methods->tdb_oob(tdb, tdb->map_size + 1, 1);
+
+       /* always make room for at least 100 more records, and at
+           least 25% more space. Round the database up to a multiple
+           of the page size */
+       new_size = MAX(tdb->map_size + size*100, tdb->map_size * 1.25);
+       size = TDB_ALIGN(new_size, tdb->page_size) - tdb->map_size;
+
+       if (!(tdb->flags & TDB_INTERNAL))
+               tdb_munmap(tdb);
+
+       /*
+        * We must ensure the file is unmapped before doing this
+        * to ensure consistency with systems like OpenBSD where
+        * writes and mmaps are not consistent.
+        */
+
+       /* expand the file itself */
+       if (!(tdb->flags & TDB_INTERNAL)) {
+               if (tdb->methods->tdb_expand_file(tdb, tdb->map_size, size) != 0)
+                       goto fail;
+       }
+
+       tdb->map_size += size;
+
+       if (tdb->flags & TDB_INTERNAL) {
+               char *new_map_ptr = (char *)realloc(tdb->map_ptr,
+                                                   tdb->map_size);
+               if (!new_map_ptr) {
+                       tdb->map_size -= size;
+                       goto fail;
+               }
+               tdb->map_ptr = new_map_ptr;
+       } else {
+               /*
+                * We must ensure the file is remapped before adding the space
+                * to ensure consistency with systems like OpenBSD where
+                * writes and mmaps are not consistent.
+                */
+
+               /* We're ok if the mmap fails as we'll fallback to read/write */
+               tdb_mmap(tdb);
+       }
+
+       /* form a new freelist record */
+       memset(&rec,'\0',sizeof(rec));
+       rec.rec_len = size - sizeof(rec);
+
+       /* link it into the free list */
+       offset = tdb->map_size - size;
+       if (tdb_free(tdb, offset, &rec) == -1)
+               goto fail;
+
+       tdb_unlock(tdb, -1, F_WRLCK);
+       return 0;
+ fail:
+       tdb_unlock(tdb, -1, F_WRLCK);
+       return -1;
+}
+
+/* read/write a tdb_off_t */
+int tdb_ofs_read(struct tdb_context *tdb, tdb_off_t offset, tdb_off_t *d)
+{
+       return tdb->methods->tdb_read(tdb, offset, (char*)d, sizeof(*d), DOCONV());
+}
+
+int tdb_ofs_write(struct tdb_context *tdb, tdb_off_t offset, tdb_off_t *d)
+{
+       tdb_off_t off = *d;
+       return tdb->methods->tdb_write(tdb, offset, CONVERT(off), sizeof(*d));
+}
+
+
+/* read a lump of data, allocating the space for it */
+unsigned char *tdb_alloc_read(struct tdb_context *tdb, tdb_off_t offset, tdb_len_t len)
+{
+       unsigned char *buf;
+
+       /* some systems don't like zero length malloc */
+
+       if (!(buf = (unsigned char *)malloc(len ? len : 1))) {
+               /* Ensure ecode is set for log fn. */
+               tdb->ecode = TDB_ERR_OOM;
+               TDB_LOG((tdb, TDB_DEBUG_ERROR,"tdb_alloc_read malloc failed len=%d (%s)\n",
+                          len, strerror(errno)));
+               return NULL;
+       }
+       if (tdb->methods->tdb_read(tdb, offset, buf, len, 0) == -1) {
+               SAFE_FREE(buf);
+               return NULL;
+       }
+       return buf;
+}
+
+/* Give a piece of tdb data to a parser */
+
+int tdb_parse_data(struct tdb_context *tdb, TDB_DATA key,
+                  tdb_off_t offset, tdb_len_t len,
+                  int (*parser)(TDB_DATA key, TDB_DATA data,
+                                void *private_data),
+                  void *private_data)
+{
+       TDB_DATA data;
+       int result;
+
+       data.dsize = len;
+
+       if ((tdb->transaction == NULL) && (tdb->map_ptr != NULL)) {
+               /*
+                * Optimize by avoiding the malloc/memcpy/free, point the
+                * parser directly at the mmap area.
+                */
+               if (tdb->methods->tdb_oob(tdb, offset+len, 0) != 0) {
+                       return -1;
+               }
+               data.dptr = offset + (unsigned char *)tdb->map_ptr;
+               return parser(key, data, private_data);
+       }
+
+       if (!(data.dptr = tdb_alloc_read(tdb, offset, len))) {
+               return -1;
+       }
+
+       result = parser(key, data, private_data);
+       free(data.dptr);
+       return result;
+}
+
+/* read/write a record */
+int tdb_rec_read(struct tdb_context *tdb, tdb_off_t offset, struct tdb_record *rec)
+{
+       if (tdb->methods->tdb_read(tdb, offset, rec, sizeof(*rec),DOCONV()) == -1)
+               return -1;
+       if (TDB_BAD_MAGIC(rec)) {
+               /* Ensure ecode is set for log fn. */
+               tdb->ecode = TDB_ERR_CORRUPT;
+               TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_rec_read bad magic 0x%x at offset=%d\n", rec->magic, offset));
+               return -1;
+       }
+       return tdb->methods->tdb_oob(tdb, rec->next+sizeof(*rec), 0);
+}
+
+int tdb_rec_write(struct tdb_context *tdb, tdb_off_t offset, struct tdb_record *rec)
+{
+       struct tdb_record r = *rec;
+       return tdb->methods->tdb_write(tdb, offset, CONVERT(r), sizeof(r));
+}
+
+static const struct tdb_methods io_methods = {
+       tdb_read,
+       tdb_write,
+       tdb_next_hash_chain,
+       tdb_oob,
+       tdb_expand_file,
+       tdb_brlock
+};
+
+/*
+  initialise the default methods table
+*/
+void tdb_io_init(struct tdb_context *tdb)
+{
+       tdb->methods = &io_methods;
+}
diff --git a/libatalk/tdb/lock.c b/libatalk/tdb/lock.c
new file mode 100644 (file)
index 0000000..0984e51
--- /dev/null
@@ -0,0 +1,592 @@
+ /* 
+   Unix SMB/CIFS implementation.
+
+   trivial database library
+
+   Copyright (C) Andrew Tridgell              1999-2005
+   Copyright (C) Paul `Rusty' Russell             2000
+   Copyright (C) Jeremy Allison                           2000-2003
+   
+     ** NOTE! The following LGPL license applies to the tdb
+     ** library. This does NOT imply that all of Samba is released
+     ** under the LGPL
+   
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "tdb_private.h"
+
+#define TDB_MARK_LOCK 0x80000000
+
+void tdb_setalarm_sigptr(struct tdb_context *tdb, volatile sig_atomic_t *ptr)
+{
+       tdb->interrupt_sig_ptr = ptr;
+}
+
+/* a byte range locking function - return 0 on success
+   this functions locks/unlocks 1 byte at the specified offset.
+
+   On error, errno is also set so that errors are passed back properly
+   through tdb_open(). 
+
+   note that a len of zero means lock to end of file
+*/
+int tdb_brlock(struct tdb_context *tdb, tdb_off_t offset, 
+              int rw_type, int lck_type, int probe, size_t len)
+{
+       struct flock fl;
+       int ret;
+
+       if (tdb->flags & TDB_NOLOCK) {
+               return 0;
+       }
+
+       if ((rw_type == F_WRLCK) && (tdb->read_only || tdb->traverse_read)) {
+               tdb->ecode = TDB_ERR_RDONLY;
+               return -1;
+       }
+
+       fl.l_type = rw_type;
+       fl.l_whence = SEEK_SET;
+       fl.l_start = offset;
+       fl.l_len = len;
+       fl.l_pid = 0;
+
+       do {
+               ret = fcntl(tdb->fd,lck_type,&fl);
+
+               /* Check for a sigalarm break. */
+               if (ret == -1 && errno == EINTR &&
+                               tdb->interrupt_sig_ptr &&
+                               *tdb->interrupt_sig_ptr) {
+                       break;
+               }
+       } while (ret == -1 && errno == EINTR);
+
+       if (ret == -1) {
+               tdb->ecode = TDB_ERR_LOCK;
+               /* Generic lock error. errno set by fcntl.
+                * EAGAIN is an expected return from non-blocking
+                * locks. */
+               if (!probe && lck_type != F_SETLK) {
+                       TDB_LOG((tdb, TDB_DEBUG_TRACE,"tdb_brlock failed (fd=%d) at offset %d rw_type=%d lck_type=%d len=%d\n", 
+                                tdb->fd, offset, rw_type, lck_type, (int)len));
+               }
+               return -1;
+       }
+       return 0;
+}
+
+
+/*
+  upgrade a read lock to a write lock. This needs to be handled in a
+  special way as some OSes (such as solaris) have too conservative
+  deadlock detection and claim a deadlock when progress can be
+  made. For those OSes we may loop for a while.  
+*/
+int tdb_brlock_upgrade(struct tdb_context *tdb, tdb_off_t offset, size_t len)
+{
+       int count = 1000;
+       while (count--) {
+               struct timeval tv;
+               if (tdb_brlock(tdb, offset, F_WRLCK, F_SETLKW, 1, len) == 0) {
+                       return 0;
+               }
+               if (errno != EDEADLK) {
+                       break;
+               }
+               /* sleep for as short a time as we can - more portable than usleep() */
+               tv.tv_sec = 0;
+               tv.tv_usec = 1;
+               select(0, NULL, NULL, NULL, &tv);
+       }
+       TDB_LOG((tdb, TDB_DEBUG_TRACE,"tdb_brlock_upgrade failed at offset %d\n", offset));
+       return -1;
+}
+
+
+/* lock a list in the database. list -1 is the alloc list */
+static int _tdb_lock(struct tdb_context *tdb, int list, int ltype, int op)
+{
+       struct tdb_lock_type *new_lck;
+       int i;
+       bool mark_lock = ((ltype & TDB_MARK_LOCK) == TDB_MARK_LOCK);
+
+       ltype &= ~TDB_MARK_LOCK;
+
+       /* a global lock allows us to avoid per chain locks */
+       if (tdb->global_lock.count && 
+           (ltype == tdb->global_lock.ltype || ltype == F_RDLCK)) {
+               return 0;
+       }
+
+       if (tdb->global_lock.count) {
+               tdb->ecode = TDB_ERR_LOCK;
+               return -1;
+       }
+
+       if (list < -1 || list >= (int)tdb->header.hash_size) {
+               tdb->ecode = TDB_ERR_LOCK;
+               TDB_LOG((tdb, TDB_DEBUG_ERROR,"tdb_lock: invalid list %d for ltype=%d\n", 
+                          list, ltype));
+               return -1;
+       }
+       if (tdb->flags & TDB_NOLOCK)
+               return 0;
+
+       for (i=0; i<tdb->num_lockrecs; i++) {
+               if (tdb->lockrecs[i].list == list) {
+                       if (tdb->lockrecs[i].count == 0) {
+                               /*
+                                * Can't happen, see tdb_unlock(). It should
+                                * be an assert.
+                                */
+                               TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_lock: "
+                                        "lck->count == 0 for list %d", list));
+                       }
+                       /*
+                        * Just increment the in-memory struct, posix locks
+                        * don't stack.
+                        */
+                       tdb->lockrecs[i].count++;
+                       return 0;
+               }
+       }
+
+       new_lck = (struct tdb_lock_type *)realloc(
+               tdb->lockrecs,
+               sizeof(*tdb->lockrecs) * (tdb->num_lockrecs+1));
+       if (new_lck == NULL) {
+               errno = ENOMEM;
+               return -1;
+       }
+       tdb->lockrecs = new_lck;
+
+       /* Since fcntl locks don't nest, we do a lock for the first one,
+          and simply bump the count for future ones */
+       if (!mark_lock &&
+           tdb->methods->tdb_brlock(tdb,FREELIST_TOP+4*list, ltype, op,
+                                    0, 1)) {
+               return -1;
+       }
+
+       tdb->num_locks++;
+
+       tdb->lockrecs[tdb->num_lockrecs].list = list;
+       tdb->lockrecs[tdb->num_lockrecs].count = 1;
+       tdb->lockrecs[tdb->num_lockrecs].ltype = ltype;
+       tdb->num_lockrecs += 1;
+
+       return 0;
+}
+
+/* lock a list in the database. list -1 is the alloc list */
+int tdb_lock(struct tdb_context *tdb, int list, int ltype)
+{
+       int ret;
+       ret = _tdb_lock(tdb, list, ltype, F_SETLKW);
+       if (ret) {
+               TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_lock failed on list %d "
+                        "ltype=%d (%s)\n",  list, ltype, strerror(errno)));
+       }
+       return ret;
+}
+
+/* lock a list in the database. list -1 is the alloc list. non-blocking lock */
+int tdb_lock_nonblock(struct tdb_context *tdb, int list, int ltype)
+{
+       return _tdb_lock(tdb, list, ltype, F_SETLK);
+}
+
+
+/* unlock the database: returns void because it's too late for errors. */
+       /* changed to return int it may be interesting to know there
+          has been an error  --simo */
+int tdb_unlock(struct tdb_context *tdb, int list, int ltype)
+{
+       int ret = -1;
+       int i;
+       struct tdb_lock_type *lck = NULL;
+       bool mark_lock = ((ltype & TDB_MARK_LOCK) == TDB_MARK_LOCK);
+
+       ltype &= ~TDB_MARK_LOCK;
+
+       /* a global lock allows us to avoid per chain locks */
+       if (tdb->global_lock.count && 
+           (ltype == tdb->global_lock.ltype || ltype == F_RDLCK)) {
+               return 0;
+       }
+
+       if (tdb->global_lock.count) {
+               tdb->ecode = TDB_ERR_LOCK;
+               return -1;
+       }
+
+       if (tdb->flags & TDB_NOLOCK)
+               return 0;
+
+       /* Sanity checks */
+       if (list < -1 || list >= (int)tdb->header.hash_size) {
+               TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_unlock: list %d invalid (%d)\n", list, tdb->header.hash_size));
+               return ret;
+       }
+
+       for (i=0; i<tdb->num_lockrecs; i++) {
+               if (tdb->lockrecs[i].list == list) {
+                       lck = &tdb->lockrecs[i];
+                       break;
+               }
+       }
+
+       if ((lck == NULL) || (lck->count == 0)) {
+               TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_unlock: count is 0\n"));
+               return -1;
+       }
+
+       if (lck->count > 1) {
+               lck->count--;
+               return 0;
+       }
+
+       /*
+        * This lock has count==1 left, so we need to unlock it in the
+        * kernel. We don't bother with decrementing the in-memory array
+        * element, we're about to overwrite it with the last array element
+        * anyway.
+        */
+
+       if (mark_lock) {
+               ret = 0;
+       } else {
+               ret = tdb->methods->tdb_brlock(tdb, FREELIST_TOP+4*list, F_UNLCK,
+                                              F_SETLKW, 0, 1);
+       }
+       tdb->num_locks--;
+
+       /*
+        * Shrink the array by overwriting the element just unlocked with the
+        * last array element.
+        */
+
+       if (tdb->num_lockrecs > 1) {
+               *lck = tdb->lockrecs[tdb->num_lockrecs-1];
+       }
+       tdb->num_lockrecs -= 1;
+
+       /*
+        * We don't bother with realloc when the array shrinks, but if we have
+        * a completely idle tdb we should get rid of the locked array.
+        */
+
+       if (tdb->num_lockrecs == 0) {
+               SAFE_FREE(tdb->lockrecs);
+       }
+
+       if (ret)
+               TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_unlock: An error occurred unlocking!\n")); 
+       return ret;
+}
+
+/*
+  get the transaction lock
+ */
+int tdb_transaction_lock(struct tdb_context *tdb, int ltype)
+{
+       if (tdb->global_lock.count) {
+               return 0;
+       }
+       if (tdb->transaction_lock_count > 0) {
+               tdb->transaction_lock_count++;
+               return 0;
+       }
+
+       if (tdb->methods->tdb_brlock(tdb, TRANSACTION_LOCK, ltype, 
+                                    F_SETLKW, 0, 1) == -1) {
+               TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_lock: failed to get transaction lock\n"));
+               tdb->ecode = TDB_ERR_LOCK;
+               return -1;
+       }
+       tdb->transaction_lock_count++;
+       return 0;
+}
+
+/*
+  release the transaction lock
+ */
+int tdb_transaction_unlock(struct tdb_context *tdb)
+{
+       int ret;
+       if (tdb->global_lock.count) {
+               return 0;
+       }
+       if (tdb->transaction_lock_count > 1) {
+               tdb->transaction_lock_count--;
+               return 0;
+       }
+       ret = tdb->methods->tdb_brlock(tdb, TRANSACTION_LOCK, F_UNLCK, F_SETLKW, 0, 1);
+       if (ret == 0) {
+               tdb->transaction_lock_count = 0;
+       }
+       return ret;
+}
+
+
+
+
+/* lock/unlock entire database */
+static int _tdb_lockall(struct tdb_context *tdb, int ltype, int op)
+{
+       bool mark_lock = ((ltype & TDB_MARK_LOCK) == TDB_MARK_LOCK);
+
+       ltype &= ~TDB_MARK_LOCK;
+
+       /* There are no locks on read-only dbs */
+       if (tdb->read_only || tdb->traverse_read) {
+               tdb->ecode = TDB_ERR_LOCK;
+               return -1;
+       }
+
+       if (tdb->global_lock.count && tdb->global_lock.ltype == ltype) {
+               tdb->global_lock.count++;
+               return 0;
+       }
+
+       if (tdb->global_lock.count) {
+               /* a global lock of a different type exists */
+               tdb->ecode = TDB_ERR_LOCK;
+               return -1;
+       }
+       
+       if (tdb->num_locks != 0) {
+               /* can't combine global and chain locks */
+               tdb->ecode = TDB_ERR_LOCK;
+               return -1;
+       }
+
+       if (!mark_lock &&
+           tdb->methods->tdb_brlock(tdb, FREELIST_TOP, ltype, op,
+                                    0, 4*tdb->header.hash_size)) {
+               if (op == F_SETLKW) {
+                       TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_lockall failed (%s)\n", strerror(errno)));
+               }
+               return -1;
+       }
+
+       tdb->global_lock.count = 1;
+       tdb->global_lock.ltype = ltype;
+
+       return 0;
+}
+
+
+
+/* unlock entire db */
+static int _tdb_unlockall(struct tdb_context *tdb, int ltype)
+{
+       bool mark_lock = ((ltype & TDB_MARK_LOCK) == TDB_MARK_LOCK);
+
+       ltype &= ~TDB_MARK_LOCK;
+
+       /* There are no locks on read-only dbs */
+       if (tdb->read_only || tdb->traverse_read) {
+               tdb->ecode = TDB_ERR_LOCK;
+               return -1;
+       }
+
+       if (tdb->global_lock.ltype != ltype || tdb->global_lock.count == 0) {
+               tdb->ecode = TDB_ERR_LOCK;
+               return -1;
+       }
+
+       if (tdb->global_lock.count > 1) {
+               tdb->global_lock.count--;
+               return 0;
+       }
+
+       if (!mark_lock &&
+           tdb->methods->tdb_brlock(tdb, FREELIST_TOP, F_UNLCK, F_SETLKW, 
+                                    0, 4*tdb->header.hash_size)) {
+               TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_unlockall failed (%s)\n", strerror(errno)));
+               return -1;
+       }
+
+       tdb->global_lock.count = 0;
+       tdb->global_lock.ltype = 0;
+
+       return 0;
+}
+
+/* lock entire database with write lock */
+int tdb_lockall(struct tdb_context *tdb)
+{
+       tdb_trace(tdb, "tdb_lockall");
+       return _tdb_lockall(tdb, F_WRLCK, F_SETLKW);
+}
+
+/* lock entire database with write lock - mark only */
+int tdb_lockall_mark(struct tdb_context *tdb)
+{
+       tdb_trace(tdb, "tdb_lockall_mark");
+       return _tdb_lockall(tdb, F_WRLCK | TDB_MARK_LOCK, F_SETLKW);
+}
+
+/* unlock entire database with write lock - unmark only */
+int tdb_lockall_unmark(struct tdb_context *tdb)
+{
+       tdb_trace(tdb, "tdb_lockall_unmark");
+       return _tdb_unlockall(tdb, F_WRLCK | TDB_MARK_LOCK);
+}
+
+/* lock entire database with write lock - nonblocking varient */
+int tdb_lockall_nonblock(struct tdb_context *tdb)
+{
+       int ret = _tdb_lockall(tdb, F_WRLCK, F_SETLK);
+       tdb_trace_ret(tdb, "tdb_lockall_nonblock", ret);
+       return ret;
+}
+
+/* unlock entire database with write lock */
+int tdb_unlockall(struct tdb_context *tdb)
+{
+       tdb_trace(tdb, "tdb_unlockall");
+       return _tdb_unlockall(tdb, F_WRLCK);
+}
+
+/* lock entire database with read lock */
+int tdb_lockall_read(struct tdb_context *tdb)
+{
+       tdb_trace(tdb, "tdb_lockall_read");
+       return _tdb_lockall(tdb, F_RDLCK, F_SETLKW);
+}
+
+/* lock entire database with read lock - nonblock varient */
+int tdb_lockall_read_nonblock(struct tdb_context *tdb)
+{
+       int ret = _tdb_lockall(tdb, F_RDLCK, F_SETLK);
+       tdb_trace_ret(tdb, "tdb_lockall_read_nonblock", ret);
+       return ret;
+}
+
+/* unlock entire database with read lock */
+int tdb_unlockall_read(struct tdb_context *tdb)
+{
+       tdb_trace(tdb, "tdb_unlockall_read");
+       return _tdb_unlockall(tdb, F_RDLCK);
+}
+
+/* lock/unlock one hash chain. This is meant to be used to reduce
+   contention - it cannot guarantee how many records will be locked */
+int tdb_chainlock(struct tdb_context *tdb, TDB_DATA key)
+{
+       int ret = tdb_lock(tdb, BUCKET(tdb->hash_fn(&key)), F_WRLCK);
+       tdb_trace_1rec(tdb, "tdb_chainlock", key);
+       return ret;
+}
+
+/* lock/unlock one hash chain, non-blocking. This is meant to be used
+   to reduce contention - it cannot guarantee how many records will be
+   locked */
+int tdb_chainlock_nonblock(struct tdb_context *tdb, TDB_DATA key)
+{
+       int ret = tdb_lock_nonblock(tdb, BUCKET(tdb->hash_fn(&key)), F_WRLCK);
+       tdb_trace_1rec_ret(tdb, "tdb_chainlock_nonblock", key, ret);
+       return ret;
+}
+
+/* mark a chain as locked without actually locking it. Warning! use with great caution! */
+int tdb_chainlock_mark(struct tdb_context *tdb, TDB_DATA key)
+{
+       int ret = tdb_lock(tdb, BUCKET(tdb->hash_fn(&key)), F_WRLCK | TDB_MARK_LOCK);
+       tdb_trace_1rec(tdb, "tdb_chainlock_mark", key);
+       return ret;
+}
+
+/* unmark a chain as locked without actually locking it. Warning! use with great caution! */
+int tdb_chainlock_unmark(struct tdb_context *tdb, TDB_DATA key)
+{
+       tdb_trace_1rec(tdb, "tdb_chainlock_unmark", key);
+       return tdb_unlock(tdb, BUCKET(tdb->hash_fn(&key)), F_WRLCK | TDB_MARK_LOCK);
+}
+
+int tdb_chainunlock(struct tdb_context *tdb, TDB_DATA key)
+{
+       tdb_trace_1rec(tdb, "tdb_chainunlock", key);
+       return tdb_unlock(tdb, BUCKET(tdb->hash_fn(&key)), F_WRLCK);
+}
+
+int tdb_chainlock_read(struct tdb_context *tdb, TDB_DATA key)
+{
+       int ret;
+       ret = tdb_lock(tdb, BUCKET(tdb->hash_fn(&key)), F_RDLCK);
+       tdb_trace_1rec(tdb, "tdb_chainlock_read", key);
+       return ret;
+}
+
+int tdb_chainunlock_read(struct tdb_context *tdb, TDB_DATA key)
+{
+       tdb_trace_1rec(tdb, "tdb_chainunlock_read", key);
+       return tdb_unlock(tdb, BUCKET(tdb->hash_fn(&key)), F_RDLCK);
+}
+
+
+
+/* record lock stops delete underneath */
+int tdb_lock_record(struct tdb_context *tdb, tdb_off_t off)
+{
+       if (tdb->global_lock.count) {
+               return 0;
+       }
+       return off ? tdb->methods->tdb_brlock(tdb, off, F_RDLCK, F_SETLKW, 0, 1) : 0;
+}
+
+/*
+  Write locks override our own fcntl readlocks, so check it here.
+  Note this is meant to be F_SETLK, *not* F_SETLKW, as it's not
+  an error to fail to get the lock here.
+*/
+int tdb_write_lock_record(struct tdb_context *tdb, tdb_off_t off)
+{
+       struct tdb_traverse_lock *i;
+       for (i = &tdb->travlocks; i; i = i->next)
+               if (i->off == off)
+                       return -1;
+       return tdb->methods->tdb_brlock(tdb, off, F_WRLCK, F_SETLK, 1, 1);
+}
+
+/*
+  Note this is meant to be F_SETLK, *not* F_SETLKW, as it's not
+  an error to fail to get the lock here.
+*/
+int tdb_write_unlock_record(struct tdb_context *tdb, tdb_off_t off)
+{
+       return tdb->methods->tdb_brlock(tdb, off, F_UNLCK, F_SETLK, 0, 1);
+}
+
+/* fcntl locks don't stack: avoid unlocking someone else's */
+int tdb_unlock_record(struct tdb_context *tdb, tdb_off_t off)
+{
+       struct tdb_traverse_lock *i;
+       uint32_t count = 0;
+
+       if (tdb->global_lock.count) {
+               return 0;
+       }
+
+       if (off == 0)
+               return 0;
+       for (i = &tdb->travlocks; i; i = i->next)
+               if (i->off == off)
+                       count++;
+       return (count == 1 ? tdb->methods->tdb_brlock(tdb, off, F_UNLCK, F_SETLKW, 0, 1) : 0);
+}
diff --git a/libatalk/tdb/open.c b/libatalk/tdb/open.c
new file mode 100644 (file)
index 0000000..4d4f95a
--- /dev/null
@@ -0,0 +1,552 @@
+ /* 
+   Unix SMB/CIFS implementation.
+
+   trivial database library
+
+   Copyright (C) Andrew Tridgell              1999-2005
+   Copyright (C) Paul `Rusty' Russell             2000
+   Copyright (C) Jeremy Allison                           2000-2003
+   
+     ** NOTE! The following LGPL license applies to the tdb
+     ** library. This does NOT imply that all of Samba is released
+     ** under the LGPL
+   
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "tdb_private.h"
+
+/* all contexts, to ensure no double-opens (fcntl locks don't nest!) */
+static struct tdb_context *tdbs = NULL;
+
+
+/* This is based on the hash algorithm from gdbm */
+static unsigned int default_tdb_hash(TDB_DATA *key)
+{
+       uint32_t value; /* Used to compute the hash value.  */
+       uint32_t   i;   /* Used to cycle through random values. */
+
+       /* Set the initial value from the key size. */
+       for (value = 0x238F13AF * key->dsize, i=0; i < key->dsize; i++)
+               value = (value + (key->dptr[i] << (i*5 % 24)));
+
+       return (1103515243 * value + 12345);  
+}
+
+
+/* initialise a new database with a specified hash size */
+static int tdb_new_database(struct tdb_context *tdb, int hash_size)
+{
+       struct tdb_header *newdb;
+       size_t size;
+       int ret = -1;
+       ssize_t written;
+
+       /* We make it up in memory, then write it out if not internal */
+       size = sizeof(struct tdb_header) + (hash_size+1)*sizeof(tdb_off_t);
+       if (!(newdb = (struct tdb_header *)calloc(size, 1))) {
+               tdb->ecode = TDB_ERR_OOM;
+               return -1;
+       }
+
+       /* Fill in the header */
+       newdb->version = TDB_VERSION;
+       newdb->hash_size = hash_size;
+       if (tdb->flags & TDB_INTERNAL) {
+               tdb->map_size = size;
+               tdb->map_ptr = (char *)newdb;
+               memcpy(&tdb->header, newdb, sizeof(tdb->header));
+               /* Convert the `ondisk' version if asked. */
+               CONVERT(*newdb);
+               return 0;
+       }
+       if (lseek(tdb->fd, 0, SEEK_SET) == -1)
+               goto fail;
+
+       if (ftruncate(tdb->fd, 0) == -1)
+               goto fail;
+
+       /* This creates an endian-converted header, as if read from disk */
+       CONVERT(*newdb);
+       memcpy(&tdb->header, newdb, sizeof(tdb->header));
+       /* Don't endian-convert the magic food! */
+       memcpy(newdb->magic_food, TDB_MAGIC_FOOD, strlen(TDB_MAGIC_FOOD)+1);
+       /* we still have "ret == -1" here */
+       written = write(tdb->fd, newdb, size);
+       if (written == size) {
+               ret = 0;
+       } else if (written != -1) {
+               /* call write once again, this usually should return -1 and
+                * set errno appropriately */
+               size -= written;
+               written = write(tdb->fd, newdb+written, size);
+               if (written == size) {
+               ret = 0;
+               } else if (written >= 0) {
+                       /* a second incomplete write - we give up.
+                        * guessing the errno... */
+                       errno = ENOSPC;
+               }
+       }
+
+  fail:
+       SAFE_FREE(newdb);
+       return ret;
+}
+
+
+
+static int tdb_already_open(dev_t device,
+                           ino_t ino)
+{
+       struct tdb_context *i;
+       
+       for (i = tdbs; i; i = i->next) {
+               if (i->device == device && i->inode == ino) {
+                       return 1;
+               }
+       }
+
+       return 0;
+}
+
+/* open the database, creating it if necessary 
+
+   The open_flags and mode are passed straight to the open call on the
+   database file. A flags value of O_WRONLY is invalid. The hash size
+   is advisory, use zero for a default value.
+
+   Return is NULL on error, in which case errno is also set.  Don't 
+   try to call tdb_error or tdb_errname, just do strerror(errno).
+
+   @param name may be NULL for internal databases. */
+struct tdb_context *tdb_open(const char *name, int hash_size, int tdb_flags,
+                     int open_flags, mode_t mode)
+{
+       return tdb_open_ex(name, hash_size, tdb_flags, open_flags, mode, NULL, NULL);
+}
+
+/* a default logging function */
+static void null_log_fn(struct tdb_context *tdb, enum tdb_debug_level level, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
+static void null_log_fn(struct tdb_context *tdb, enum tdb_debug_level level, const char *fmt, ...)
+{
+}
+
+
+struct tdb_context *tdb_open_ex(const char *name, int hash_size, int tdb_flags,
+                               int open_flags, mode_t mode,
+                               const struct tdb_logging_context *log_ctx,
+                               tdb_hash_func hash_fn)
+{
+       struct tdb_context *tdb;
+       struct stat st;
+       int rev = 0, locked = 0;
+       unsigned char *vp;
+       uint32_t vertest;
+       unsigned v;
+
+       if (!(tdb = (struct tdb_context *)calloc(1, sizeof *tdb))) {
+               /* Can't log this */
+               errno = ENOMEM;
+               goto fail;
+       }
+       tdb_io_init(tdb);
+       tdb->fd = -1;
+#ifdef TDB_TRACE
+       tdb->tracefd = -1;
+#endif
+       tdb->name = NULL;
+       tdb->map_ptr = NULL;
+       tdb->flags = tdb_flags;
+       tdb->open_flags = open_flags;
+       if (log_ctx) {
+               tdb->log = *log_ctx;
+       } else {
+               tdb->log.log_fn = null_log_fn;
+               tdb->log.log_private = NULL;
+       }
+       tdb->hash_fn = hash_fn ? hash_fn : default_tdb_hash;
+
+       /* cache the page size */
+       tdb->page_size = getpagesize();
+       if (tdb->page_size <= 0) {
+               tdb->page_size = 0x2000;
+       }
+
+       tdb->max_dead_records = (tdb_flags & TDB_VOLATILE) ? 5 : 0;
+
+       if ((open_flags & O_ACCMODE) == O_WRONLY) {
+               TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: can't open tdb %s write-only\n",
+                        name));
+               errno = EINVAL;
+               goto fail;
+       }
+       
+       if (hash_size == 0)
+               hash_size = DEFAULT_HASH_SIZE;
+       if ((open_flags & O_ACCMODE) == O_RDONLY) {
+               tdb->read_only = 1;
+               /* read only databases don't do locking or clear if first */
+               tdb->flags |= TDB_NOLOCK;
+               tdb->flags &= ~TDB_CLEAR_IF_FIRST;
+       }
+
+       if ((tdb->flags & TDB_ALLOW_NESTING) &&
+           (tdb->flags & TDB_DISALLOW_NESTING)) {
+               tdb->ecode = TDB_ERR_NESTING;
+               TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_open_ex: "
+                       "allow_nesting and disallow_nesting are not allowed together!"));
+               errno = EINVAL;
+               goto fail;
+       }
+
+       /*
+        * TDB_ALLOW_NESTING is the default behavior.
+        * Note: this may change in future versions!
+        */
+       if (!(tdb->flags & TDB_DISALLOW_NESTING)) {
+               tdb->flags |= TDB_ALLOW_NESTING;
+       }
+
+       /* internal databases don't mmap or lock, and start off cleared */
+       if (tdb->flags & TDB_INTERNAL) {
+               tdb->flags |= (TDB_NOLOCK | TDB_NOMMAP);
+               tdb->flags &= ~TDB_CLEAR_IF_FIRST;
+               if (tdb_new_database(tdb, hash_size) != 0) {
+                       TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: tdb_new_database failed!"));
+                       goto fail;
+               }
+               goto internal;
+       }
+
+       if ((tdb->fd = open(name, open_flags, mode)) == -1) {
+               TDB_LOG((tdb, TDB_DEBUG_WARNING, "tdb_open_ex: could not open file %s: %s\n",
+                        name, strerror(errno)));
+               goto fail;      /* errno set by open(2) */
+       }
+
+       /* on exec, don't inherit the fd */
+       v = fcntl(tdb->fd, F_GETFD, 0);
+        fcntl(tdb->fd, F_SETFD, v | FD_CLOEXEC);
+
+       /* ensure there is only one process initialising at once */
+       if (tdb->methods->tdb_brlock(tdb, GLOBAL_LOCK, F_WRLCK, F_SETLKW, 0, 1) == -1) {
+               TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: failed to get global lock on %s: %s\n",
+                        name, strerror(errno)));
+               goto fail;      /* errno set by tdb_brlock */
+       }
+
+       /* we need to zero database if we are the only one with it open */
+       if ((tdb_flags & TDB_CLEAR_IF_FIRST) &&
+           (!tdb->read_only) &&
+           (locked = (tdb->methods->tdb_brlock(tdb, ACTIVE_LOCK, F_WRLCK, F_SETLK, 0, 1) == 0))) {
+               open_flags |= O_CREAT;
+               if (ftruncate(tdb->fd, 0) == -1) {
+                       TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_open_ex: "
+                                "failed to truncate %s: %s\n",
+                                name, strerror(errno)));
+                       goto fail; /* errno set by ftruncate */
+               }
+       }
+
+       errno = 0;
+       if (read(tdb->fd, &tdb->header, sizeof(tdb->header)) != sizeof(tdb->header)
+           || strcmp(tdb->header.magic_food, TDB_MAGIC_FOOD) != 0) {
+               if (!(open_flags & O_CREAT) || tdb_new_database(tdb, hash_size) == -1) {
+                       if (errno == 0) {
+                               errno = EIO; /* ie bad format or something */
+                       }
+                       goto fail;
+               }
+               rev = (tdb->flags & TDB_CONVERT);
+       } else if (tdb->header.version != TDB_VERSION
+                  && !(rev = (tdb->header.version==TDB_BYTEREV(TDB_VERSION)))) {
+               /* wrong version */
+               errno = EIO;
+               goto fail;
+       }
+       vp = (unsigned char *)&tdb->header.version;
+       vertest = (((uint32_t)vp[0]) << 24) | (((uint32_t)vp[1]) << 16) |
+                 (((uint32_t)vp[2]) << 8) | (uint32_t)vp[3];
+       tdb->flags |= (vertest==TDB_VERSION) ? TDB_BIGENDIAN : 0;
+       if (!rev)
+               tdb->flags &= ~TDB_CONVERT;
+       else {
+               tdb->flags |= TDB_CONVERT;
+               tdb_convert(&tdb->header, sizeof(tdb->header));
+       }
+       if (fstat(tdb->fd, &st) == -1)
+               goto fail;
+
+       if (tdb->header.rwlocks != 0) {
+               TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: spinlocks no longer supported\n"));
+               goto fail;
+       }
+
+       /* Is it already in the open list?  If so, fail. */
+       if (tdb_already_open(st.st_dev, st.st_ino)) {
+               TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: "
+                        "%s (%d,%d) is already open in this process\n",
+                        name, (int)st.st_dev, (int)st.st_ino));
+               errno = EBUSY;
+               goto fail;
+       }
+
+       if (!(tdb->name = (char *)strdup(name))) {
+               errno = ENOMEM;
+               goto fail;
+       }
+
+       tdb->map_size = st.st_size;
+       tdb->device = st.st_dev;
+       tdb->inode = st.st_ino;
+       tdb_mmap(tdb);
+       if (locked) {
+               if (tdb->methods->tdb_brlock(tdb, ACTIVE_LOCK, F_UNLCK, F_SETLK, 0, 1) == -1) {
+                       TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: "
+                                "failed to take ACTIVE_LOCK on %s: %s\n",
+                                name, strerror(errno)));
+                       goto fail;
+               }
+
+       }
+
+       /* We always need to do this if the CLEAR_IF_FIRST flag is set, even if
+          we didn't get the initial exclusive lock as we need to let all other
+          users know we're using it. */
+
+       if (tdb_flags & TDB_CLEAR_IF_FIRST) {
+               /* leave this lock in place to indicate it's in use */
+               if (tdb->methods->tdb_brlock(tdb, ACTIVE_LOCK, F_RDLCK, F_SETLKW, 0, 1) == -1)
+                       goto fail;
+       }
+
+       /* if needed, run recovery */
+       if (tdb_transaction_recover(tdb) == -1) {
+               goto fail;
+       }
+
+#ifdef TDB_TRACE
+       {
+               char tracefile[strlen(name) + 32];
+
+               snprintf(tracefile, sizeof(tracefile),
+                        "%s.trace.%li", name, (long)getpid());
+               tdb->tracefd = open(tracefile, O_WRONLY|O_CREAT|O_EXCL, 0600);
+               if (tdb->tracefd >= 0) {
+                       tdb_enable_seqnum(tdb);
+                       tdb_trace_open(tdb, "tdb_open", hash_size, tdb_flags,
+                                      open_flags);
+               } else
+                       TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: failed to open trace file %s!\n", tracefile));
+       }
+#endif
+
+ internal:
+       /* Internal (memory-only) databases skip all the code above to
+        * do with disk files, and resume here by releasing their
+        * global lock and hooking into the active list. */
+       if (tdb->methods->tdb_brlock(tdb, GLOBAL_LOCK, F_UNLCK, F_SETLKW, 0, 1) == -1)
+               goto fail;
+       tdb->next = tdbs;
+       tdbs = tdb;
+       return tdb;
+
+ fail:
+       { int save_errno = errno;
+
+       if (!tdb)
+               return NULL;
+
+#ifdef TDB_TRACE
+       close(tdb->tracefd);
+#endif
+       if (tdb->map_ptr) {
+               if (tdb->flags & TDB_INTERNAL)
+                       SAFE_FREE(tdb->map_ptr);
+               else
+                       tdb_munmap(tdb);
+       }
+       SAFE_FREE(tdb->name);
+       if (tdb->fd != -1)
+               if (close(tdb->fd) != 0)
+                       TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: failed to close tdb->fd on error!\n"));
+       SAFE_FREE(tdb);
+       errno = save_errno;
+       return NULL;
+       }
+}
+
+/*
+ * Set the maximum number of dead records per hash chain
+ */
+
+void tdb_set_max_dead(struct tdb_context *tdb, int max_dead)
+{
+       tdb->max_dead_records = max_dead;
+}
+
+/**
+ * Close a database.
+ *
+ * @returns -1 for error; 0 for success.
+ **/
+int tdb_close(struct tdb_context *tdb)
+{
+       struct tdb_context **i;
+       int ret = 0;
+
+       tdb_trace(tdb, "tdb_close");
+       if (tdb->transaction) {
+               _tdb_transaction_cancel(tdb);
+       }
+
+       if (tdb->map_ptr) {
+               if (tdb->flags & TDB_INTERNAL)
+                       SAFE_FREE(tdb->map_ptr);
+               else
+                       tdb_munmap(tdb);
+       }
+       SAFE_FREE(tdb->name);
+       if (tdb->fd != -1) {
+               ret = close(tdb->fd);
+               tdb->fd = -1;
+       }
+       SAFE_FREE(tdb->lockrecs);
+
+       /* Remove from contexts list */
+       for (i = &tdbs; *i; i = &(*i)->next) {
+               if (*i == tdb) {
+                       *i = tdb->next;
+                       break;
+               }
+       }
+
+#ifdef TDB_TRACE
+       close(tdb->tracefd);
+#endif
+       memset(tdb, 0, sizeof(*tdb));
+       SAFE_FREE(tdb);
+
+       return ret;
+}
+
+/* register a loging function */
+void tdb_set_logging_function(struct tdb_context *tdb,
+                              const struct tdb_logging_context *log_ctx)
+{
+        tdb->log = *log_ctx;
+}
+
+void *tdb_get_logging_private(struct tdb_context *tdb)
+{
+       return tdb->log.log_private;
+}
+
+static int tdb_reopen_internal(struct tdb_context *tdb, bool active_lock)
+{
+#if !defined(LIBREPLACE_PREAD_NOT_REPLACED) || \
+       !defined(LIBREPLACE_PWRITE_NOT_REPLACED)
+       struct stat st;
+#endif
+
+       if (tdb->flags & TDB_INTERNAL) {
+               return 0; /* Nothing to do. */
+       }
+
+       if (tdb->num_locks != 0 || tdb->global_lock.count) {
+               TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_reopen: reopen not allowed with locks held\n"));
+               goto fail;
+       }
+
+       if (tdb->transaction != 0) {
+               TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_reopen: reopen not allowed inside a transaction\n"));
+               goto fail;
+       }
+
+/* If we have real pread & pwrite, we can skip reopen. */
+#if !defined(LIBREPLACE_PREAD_NOT_REPLACED) || \
+       !defined(LIBREPLACE_PWRITE_NOT_REPLACED)
+       if (tdb_munmap(tdb) != 0) {
+               TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_reopen: munmap failed (%s)\n", strerror(errno)));
+               goto fail;
+       }
+       if (close(tdb->fd) != 0)
+               TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_reopen: WARNING closing tdb->fd failed!\n"));
+       tdb->fd = open(tdb->name, tdb->open_flags & ~(O_CREAT|O_TRUNC), 0);
+       if (tdb->fd == -1) {
+               TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_reopen: open failed (%s)\n", strerror(errno)));
+               goto fail;
+       }
+       if (fstat(tdb->fd, &st) != 0) {
+               TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_reopen: fstat failed (%s)\n", strerror(errno)));
+               goto fail;
+       }
+       if (st.st_ino != tdb->inode || st.st_dev != tdb->device) {
+               TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_reopen: file dev/inode has changed!\n"));
+               goto fail;
+       }
+       tdb_mmap(tdb);
+#endif /* fake pread or pwrite */
+
+       if (active_lock &&
+           (tdb->methods->tdb_brlock(tdb, ACTIVE_LOCK, F_RDLCK, F_SETLKW, 0, 1) == -1)) {
+               TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_reopen: failed to obtain active lock\n"));
+               goto fail;
+       }
+
+       return 0;
+
+fail:
+       tdb_close(tdb);
+       return -1;
+}
+
+/* reopen a tdb - this can be used after a fork to ensure that we have an independent
+   seek pointer from our parent and to re-establish locks */
+int tdb_reopen(struct tdb_context *tdb)
+{
+       return tdb_reopen_internal(tdb, tdb->flags & TDB_CLEAR_IF_FIRST);
+}
+
+/* reopen all tdb's */
+int tdb_reopen_all(int parent_longlived)
+{
+       struct tdb_context *tdb;
+
+       for (tdb=tdbs; tdb; tdb = tdb->next) {
+               bool active_lock = (tdb->flags & TDB_CLEAR_IF_FIRST);
+
+               /*
+                * If the parent is longlived (ie. a
+                * parent daemon architecture), we know
+                * it will keep it's active lock on a
+                * tdb opened with CLEAR_IF_FIRST. Thus
+                * for child processes we don't have to
+                * add an active lock. This is essential
+                * to improve performance on systems that
+                * keep POSIX locks as a non-scalable data
+                * structure in the kernel.
+                */
+               if (parent_longlived) {
+                       /* Ensure no clear-if-first. */
+                       active_lock = false;
+               }
+
+               if (tdb_reopen_internal(tdb, active_lock) != 0)
+                       return -1;
+       }
+
+       return 0;
+}
diff --git a/libatalk/tdb/spinlock.c b/libatalk/tdb/spinlock.c
deleted file mode 100644 (file)
index 7d20106..0000000
+++ /dev/null
@@ -1,431 +0,0 @@
-/* 
-   Unix SMB/CIFS implementation.
-   Samba database functions
-   Copyright (C) Anton Blanchard                   2001
-   
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
-   (at your option) any later version.
-   
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-   
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
-#define STANDALONE 1
-
-#if HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#if STANDALONE
-#include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <sys/stat.h>
-#include <time.h>
-#include <signal.h>
-#include "spinlock.h"
-
-#define DEBUG
-#else
-#include "includes.h"
-#endif
-
-#ifdef USE_SPINLOCKS
-
-/*
- * ARCH SPECIFIC
- */
-
-#if defined(SPARC_SPINLOCKS)
-
-static inline int __spin_trylock(spinlock_t *lock)
-{
-       unsigned int result;
-
-       asm volatile("ldstub    [%1], %0"
-               : "=r" (result)
-               : "r" (lock)
-               : "memory");
-
-       return (result == 0) ? 0 : EBUSY;
-}
-
-static inline void __spin_unlock(spinlock_t *lock)
-{
-       asm volatile("":::"memory");
-       *lock = 0;
-}
-
-static inline void __spin_lock_init(spinlock_t *lock)
-{
-       *lock = 0;
-}
-
-static inline int __spin_is_locked(spinlock_t *lock)
-{
-       return (*lock != 0);
-}
-
-#elif defined(POWERPC_SPINLOCKS) 
-
-static inline int __spin_trylock(spinlock_t *lock)
-{
-       unsigned int result;
-
-       __asm__ __volatile__(
-"1:    lwarx           %0,0,%1\n\
-       cmpwi           0,%0,0\n\
-       li              %0,0\n\
-       bne-            2f\n\
-       li              %0,1\n\
-       stwcx.          %0,0,%1\n\
-       bne-            1b\n\
-       isync\n\
-2:"    : "=&r"(result)
-       : "r"(lock)
-       : "cr0", "memory");
-
-       return (result == 1) ? 0 : EBUSY;
-}
-
-static inline void __spin_unlock(spinlock_t *lock)
-{
-       asm volatile("eieio":::"memory");
-       *lock = 0;
-}
-
-static inline void __spin_lock_init(spinlock_t *lock)
-{
-       *lock = 0;
-}
-
-static inline int __spin_is_locked(spinlock_t *lock)
-{
-       return (*lock != 0);
-}
-
-#elif defined(INTEL_SPINLOCKS) 
-
-static inline int __spin_trylock(spinlock_t *lock)
-{
-       int oldval;
-
-       asm volatile("xchgl %0,%1"
-               : "=r" (oldval), "=m" (*lock)
-               : "0" (0)
-               : "memory");
-
-       return oldval > 0 ? 0 : EBUSY;
-}
-
-static inline void __spin_unlock(spinlock_t *lock)
-{
-       asm volatile("":::"memory");
-       *lock = 1;
-}
-
-static inline void __spin_lock_init(spinlock_t *lock)
-{
-       *lock = 1;
-}
-
-static inline int __spin_is_locked(spinlock_t *lock)
-{
-       return (*lock != 1);
-}
-
-#elif defined(MIPS_SPINLOCKS) 
-
-static inline unsigned int load_linked(unsigned long addr)
-{
-       unsigned int res;
-
-       __asm__ __volatile__("ll\t%0,(%1)"
-               : "=r" (res)
-               : "r" (addr));
-
-       return res;
-}
-
-static inline unsigned int store_conditional(unsigned long addr, unsigned int value)
-{
-       unsigned int res;
-
-       __asm__ __volatile__("sc\t%0,(%2)"
-               : "=r" (res)
-               : "0" (value), "r" (addr));
-       return res;
-}
-
-static inline int __spin_trylock(spinlock_t *lock)
-{
-       unsigned int mw;
-
-       do {
-               mw = load_linked(lock);
-               if (mw) 
-                       return EBUSY;
-       } while (!store_conditional(lock, 1));
-
-       asm volatile("":::"memory");
-
-       return 0;
-}
-
-static inline void __spin_unlock(spinlock_t *lock)
-{
-       asm volatile("":::"memory");
-       *lock = 0;
-}
-
-static inline void __spin_lock_init(spinlock_t *lock)
-{
-       *lock = 0;
-}
-
-static inline int __spin_is_locked(spinlock_t *lock)
-{
-       return (*lock != 0);
-}
-
-#else
-#error Need to implement spinlock code in spinlock.c
-#endif
-
-/*
- * OS SPECIFIC
- */
-
-static void yield_cpu(void)
-{
-       struct timespec tm;
-
-#ifdef USE_SCHED_YIELD
-       sched_yield();
-#else
-       /* Linux will busy loop for delays < 2ms on real time tasks */
-       tm.tv_sec = 0;
-       tm.tv_nsec = 2000000L + 1;
-       nanosleep(&tm, NULL);
-#endif
-}
-
-static int this_is_smp(void)
-{
-       return 0;
-}
-
-/*
- * GENERIC
- */
-
-static int smp_machine = 0;
-
-static inline void __spin_lock(spinlock_t *lock)
-{
-       int ntries = 0;
-
-       while(__spin_trylock(lock)) {
-               while(__spin_is_locked(lock)) {
-                       if (smp_machine && ntries++ < MAX_BUSY_LOOPS)
-                               continue;
-                       yield_cpu();
-               }
-       }
-}
-
-static void __read_lock(tdb_rwlock_t *rwlock)
-{
-       int ntries = 0;
-
-       while(1) {
-               __spin_lock(&rwlock->lock);
-
-               if (!(rwlock->count & RWLOCK_BIAS)) {
-                       rwlock->count++;
-                       __spin_unlock(&rwlock->lock);
-                       return;
-               }
-       
-               __spin_unlock(&rwlock->lock);
-
-               while(rwlock->count & RWLOCK_BIAS) {
-                       if (smp_machine && ntries++ < MAX_BUSY_LOOPS)
-                               continue;
-                       yield_cpu();
-               }
-       }
-}
-
-static void __write_lock(tdb_rwlock_t *rwlock)
-{
-       int ntries = 0;
-
-       while(1) {
-               __spin_lock(&rwlock->lock);
-
-               if (rwlock->count == 0) {
-                       rwlock->count |= RWLOCK_BIAS;
-                       __spin_unlock(&rwlock->lock);
-                       return;
-               }
-
-               __spin_unlock(&rwlock->lock);
-
-               while(rwlock->count != 0) {
-                       if (smp_machine && ntries++ < MAX_BUSY_LOOPS)
-                               continue;
-                       yield_cpu();
-               }
-       }
-}
-
-static void __write_unlock(tdb_rwlock_t *rwlock)
-{
-       __spin_lock(&rwlock->lock);
-
-#ifdef DEBUG
-       if (!(rwlock->count & RWLOCK_BIAS))
-               fprintf(stderr, "bug: write_unlock\n");
-#endif
-
-       rwlock->count &= ~RWLOCK_BIAS;
-       __spin_unlock(&rwlock->lock);
-}
-
-static void __read_unlock(tdb_rwlock_t *rwlock)
-{
-       __spin_lock(&rwlock->lock);
-
-#ifdef DEBUG
-       if (!rwlock->count)
-               fprintf(stderr, "bug: read_unlock\n");
-
-       if (rwlock->count & RWLOCK_BIAS)
-               fprintf(stderr, "bug: read_unlock\n");
-#endif
-
-       rwlock->count--;
-       __spin_unlock(&rwlock->lock);
-}
-
-/* TDB SPECIFIC */
-
-/* lock a list in the database. list -1 is the alloc list */
-int tdb_spinlock(TDB_CONTEXT *tdb, int list, int rw_type)
-{
-       tdb_rwlock_t *rwlocks;
-
-       if (!tdb->map_ptr) return -1;
-       rwlocks = (tdb_rwlock_t *)((char *)tdb->map_ptr + tdb->header.rwlocks);
-
-       switch(rw_type) {
-       case F_RDLCK:
-               __read_lock(&rwlocks[list+1]);
-               break;
-
-       case F_WRLCK:
-               __write_lock(&rwlocks[list+1]);
-               break;
-
-       default:
-               return TDB_ERRCODE(TDB_ERR_LOCK, -1);
-       }
-       return 0;
-}
-
-/* unlock the database. */
-int tdb_spinunlock(TDB_CONTEXT *tdb, int list, int rw_type)
-{
-       tdb_rwlock_t *rwlocks;
-
-       if (!tdb->map_ptr) return -1;
-       rwlocks = (tdb_rwlock_t *)((char *)tdb->map_ptr + tdb->header.rwlocks);
-
-       switch(rw_type) {
-       case F_RDLCK:
-               __read_unlock(&rwlocks[list+1]);
-               break;
-
-       case F_WRLCK:
-               __write_unlock(&rwlocks[list+1]);
-               break;
-
-       default:
-               return TDB_ERRCODE(TDB_ERR_LOCK, -1);
-       }
-
-       return 0;
-}
-
-int tdb_create_rwlocks(int fd, unsigned int hash_size)
-{
-       unsigned size, i;
-       tdb_rwlock_t *rwlocks;
-
-       size = (hash_size + 1) * sizeof(tdb_rwlock_t);
-       rwlocks = malloc(size);
-       if (!rwlocks)
-               return -1;
-
-       for(i = 0; i < hash_size+1; i++) {
-               __spin_lock_init(&rwlocks[i].lock);
-               rwlocks[i].count = 0;
-       }
-
-       /* Write it out (appending to end) */
-       if (write(fd, rwlocks, size) != size) {
-               free(rwlocks);
-               return -1;
-       }
-       smp_machine = this_is_smp();
-       free(rwlocks);
-       return 0;
-}
-
-int tdb_clear_spinlocks(TDB_CONTEXT *tdb)
-{
-       tdb_rwlock_t *rwlocks;
-       unsigned i;
-
-       if (tdb->header.rwlocks == 0) return 0;
-       if (!tdb->map_ptr) return -1;
-
-       /* We're mmapped here */
-       rwlocks = (tdb_rwlock_t *)((char *)tdb->map_ptr + tdb->header.rwlocks);
-       for(i = 0; i < tdb->header.hash_size+1; i++) {
-               __spin_lock_init(&rwlocks[i].lock);
-               rwlocks[i].count = 0;
-       }
-       return 0;
-}
-#else
-int tdb_create_rwlocks(int fd, unsigned int hash_size) { return 0; }
-int tdb_spinlock(TDB_CONTEXT *tdb, int list, int rw_type) { return -1; }
-int tdb_spinunlock(TDB_CONTEXT *tdb, int list, int rw_type) { return -1; }
-
-/* Non-spinlock version: remove spinlock pointer */
-int tdb_clear_spinlocks(TDB_CONTEXT *tdb)
-{
-       tdb_off off = (tdb_off)((char *)&tdb->header.rwlocks
-                               - (char *)&tdb->header);
-
-       tdb->header.rwlocks = 0;
-       if (lseek(tdb->fd, off, SEEK_SET) != off
-           || write(tdb->fd, (void *)&tdb->header.rwlocks,
-                    sizeof(tdb->header.rwlocks)) 
-           != sizeof(tdb->header.rwlocks))
-               return -1;
-       return 0;
-}
-#endif
diff --git a/libatalk/tdb/spinlock.h b/libatalk/tdb/spinlock.h
deleted file mode 100644 (file)
index 3c5d47a..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-#ifndef __SPINLOCK_H__
-#define __SPINLOCK_H__
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <atalk/tdb.h>
-
-#ifdef USE_SPINLOCKS
-
-#define RWLOCK_BIAS 0x1000UL
-
-/* OS SPECIFIC */
-#define MAX_BUSY_LOOPS 1000
-#undef USE_SCHED_YIELD
-
-/* ARCH SPECIFIC */
-/* We should make sure these are padded to a cache line */
-#if defined(SPARC_SPINLOCKS)
-typedef volatile char spinlock_t;
-#elif defined(POWERPC_SPINLOCKS)
-typedef volatile unsigned long spinlock_t;
-#elif defined(INTEL_SPINLOCKS)
-typedef volatile int spinlock_t;
-#elif defined(MIPS_SPINLOCKS)
-typedef volatile unsigned long spinlock_t;
-#else
-#error Need to implement spinlock code in spinlock.h
-#endif
-
-typedef struct {
-       spinlock_t lock;
-       volatile int count;
-} tdb_rwlock_t;
-
-int tdb_spinlock(TDB_CONTEXT *tdb, int list, int rw_type);
-int tdb_spinunlock(TDB_CONTEXT *tdb, int list, int rw_type);
-int tdb_create_rwlocks(int fd, unsigned int hash_size);
-int tdb_clear_spinlocks(TDB_CONTEXT *tdb);
-
-#else /* !USE_SPINLOCKS */
-#if 0
-#define tdb_create_rwlocks(fd, hash_size) 0
-#define tdb_spinlock(tdb, list, rw_type) (-1)
-#define tdb_spinunlock(tdb, list, rw_type) (-1)
-#else
-int tdb_spinlock(TDB_CONTEXT *tdb, int list, int rw_type);
-int tdb_spinunlock(TDB_CONTEXT *tdb, int list, int rw_type);
-int tdb_create_rwlocks(int fd, unsigned int hash_size);
-#endif
-int tdb_clear_spinlocks(TDB_CONTEXT *tdb);
-#endif
-
-#endif
index f258010100f080c06572b94c19b6552c7033957c..d2688def04743ae4e03cc84489cf251bec30dc8b 100644 (file)
  /* 
    Unix SMB/CIFS implementation.
-   Samba database functions
-   Copyright (C) Andrew Tridgell              1999-2000
-   Copyright (C) Luke Kenneth Casson Leighton      2000
+
+   trivial database library
+
+   Copyright (C) Andrew Tridgell              1999-2005
    Copyright (C) Paul `Rusty' Russell             2000
    Copyright (C) Jeremy Allison                           2000-2003
    
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
-   (at your option) any later version.
-   
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
+     ** NOTE! The following LGPL license applies to the tdb
+     ** library. This does NOT imply that all of Samba is released
+     ** under the LGPL
    
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
-
-#define STANDALONE 1
-
-/* NOTE: If you use tdbs under valgrind, and in particular if you run
- * tdbtorture, you may get spurious "uninitialized value" warnings.  I
- * think this is because valgrind doesn't understand that the mmap'd
- * area may be written to by other processes.  Memory can, from the
- * point of view of the grinded process, spontaneously become
- * initialized.
- *
- * I can think of a few solutions.  [mbp 20030311]
- *
- * 1 - Write suppressions for Valgrind so that it doesn't complain
- * about this.  Probably the most reasonable but people need to
- * remember to use them.
- *
- * 2 - Use IO not mmap when running under valgrind.  Not so nice.
- *
- * 3 - Use the special valgrind macros to mark memory as valid at the
- * right time.  Probably too hard -- the process just doesn't know.
- */ 
-
-#ifdef STANDALONE
-#if HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#define _XOPEN_SOURCE 600
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <string.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <sys/mman.h>
-#include <sys/stat.h>
-#include <signal.h>
-#include "spinlock.h"
-#else
-#include "includes.h"
-#endif
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
 
-#define TDB_MAGIC_FOOD "TDB file\n"
-#define TDB_VERSION (0x26011967 + 6)
-#define TDB_MAGIC (0x26011999U)
-#define TDB_FREE_MAGIC (~TDB_MAGIC)
-#define TDB_DEAD_MAGIC (0xFEE1DEAD)
-#define TDB_ALIGNMENT 4
-#define MIN_REC_SIZE (2*sizeof(struct list_struct) + TDB_ALIGNMENT)
-#define DEFAULT_HASH_SIZE 131
-#define TDB_PAGE_SIZE 0x2000
-#define FREELIST_TOP (sizeof(struct tdb_header))
-#define TDB_ALIGN(x,a) (((x) + (a)-1) & ~((a)-1))
-#define TDB_BYTEREV(x) (((((x)&0xff)<<24)|((x)&0xFF00)<<8)|(((x)>>8)&0xFF00)|((x)>>24))
-#define TDB_DEAD(r) ((r)->magic == TDB_DEAD_MAGIC)
-#define TDB_BAD_MAGIC(r) ((r)->magic != TDB_MAGIC && !TDB_DEAD(r))
-#define TDB_HASH_TOP(hash) (FREELIST_TOP + (BUCKET(hash)+1)*sizeof(tdb_off))
-
-/* NB assumes there is a local variable called "tdb" that is the
- * current context, also takes doubly-parenthesized print-style
- * argument. */
-#define TDB_LOG(x) (tdb->log_fn?((tdb->log_fn x),0) : 0)
-
-/* lock offsets */
-#define GLOBAL_LOCK 0
-#define ACTIVE_LOCK 4
-
-#ifndef MAP_FILE
-#define MAP_FILE 0
-#endif
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
 
-#ifndef MAP_FAILED
-#define MAP_FAILED ((void *)-1)
-#endif
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*/
 
-/* free memory if the pointer is valid and zero the pointer */
-#ifndef SAFE_FREE
-#define SAFE_FREE(x) do { if ((x) != NULL) {free((x)); (x)=NULL;} } while(0)
-#endif
+#include "tdb_private.h"
 
-#define BUCKET(hash) ((hash) % tdb->header.hash_size)
 TDB_DATA tdb_null;
 
-/* all contexts, to ensure no double-opens (fcntl locks don't nest!) */
-static TDB_CONTEXT *tdbs = NULL;
-
-static int tdb_munmap(TDB_CONTEXT *tdb)
-{
-       if (tdb->flags & TDB_INTERNAL)
-               return 0;
-
-#ifdef HAVE_MMAP
-       if (tdb->map_ptr) {
-               int ret = munmap(tdb->map_ptr, tdb->map_size);
-               if (ret != 0)
-                       return ret;
-       }
-#endif
-       tdb->map_ptr = NULL;
-       return 0;
-}
-
-static void tdb_mmap(TDB_CONTEXT *tdb)
+/*
+  non-blocking increment of the tdb sequence number if the tdb has been opened using
+  the TDB_SEQNUM flag
+*/
+void tdb_increment_seqnum_nonblock(struct tdb_context *tdb)
 {
-       if (tdb->flags & TDB_INTERNAL)
+       tdb_off_t seqnum=0;
+       
+       if (!(tdb->flags & TDB_SEQNUM)) {
                return;
-
-#ifdef HAVE_MMAP
-       if (!(tdb->flags & TDB_NOMMAP)) {
-               tdb->map_ptr = mmap(NULL, tdb->map_size, 
-                                   PROT_READ|(tdb->read_only? 0:PROT_WRITE), 
-                                   MAP_SHARED|MAP_FILE, tdb->fd, 0);
-
-               /*
-                * NB. When mmap fails it returns MAP_FAILED *NOT* NULL !!!!
-                */
-
-               if (tdb->map_ptr == MAP_FAILED) {
-                       tdb->map_ptr = NULL;
-                       TDB_LOG((tdb, 2, "tdb_mmap failed for size %d (%s)\n", 
-                                tdb->map_size, strerror(errno)));
-               }
-       } else {
-               tdb->map_ptr = NULL;
        }
-#else
-       tdb->map_ptr = NULL;
-#endif
-}
 
-/* Endian conversion: we only ever deal with 4 byte quantities */
-static void *convert(void *buf, u32 size)
-{
-       u32 i, *p = buf;
-       for (i = 0; i < size / 4; i++)
-               p[i] = TDB_BYTEREV(p[i]);
-       return buf;
-}
-#define DOCONV() (tdb->flags & TDB_CONVERT)
-#define CONVERT(x) (DOCONV() ? convert(&x, sizeof(x)) : &x)
-
-/* the body of the database is made of one list_struct for the free space
-   plus a separate data list for each hash value */
-struct list_struct {
-       tdb_off next; /* offset of the next record in the list */
-       tdb_len rec_len; /* total byte length of record */
-       tdb_len key_len; /* byte length of key */
-       tdb_len data_len; /* byte length of data */
-       u32 full_hash; /* the full 32 bit hash of the key */
-       u32 magic;   /* try to catch errors */
-       /* the following union is implied:
-               union {
-                       char record[rec_len];
-                       struct {
-                               char key[key_len];
-                               char data[data_len];
-                       }
-                       u32 totalsize; (tailer)
-               }
+       /* we ignore errors from this, as we have no sane way of
+          dealing with them.
        */
-};
-
-/***************************************************************
- Allow a caller to set a "alarm" flag that tdb can check to abort
- a blocking lock on SIGALRM.
-***************************************************************/
-
-static sig_atomic_t *palarm_fired;
-
-void tdb_set_lock_alarm(sig_atomic_t *palarm)
-{
-       palarm_fired = palarm;
+       tdb_ofs_read(tdb, TDB_SEQNUM_OFS, &seqnum);
+       seqnum++;
+       tdb_ofs_write(tdb, TDB_SEQNUM_OFS, &seqnum);
 }
 
-/* a byte range locking function - return 0 on success
-   this functions locks/unlocks 1 byte at the specified offset.
-
-   On error, errno is also set so that errors are passed back properly
-   through tdb_open(). */
-static int tdb_brlock(TDB_CONTEXT *tdb, tdb_off offset, 
-                     int rw_type, int lck_type, int probe)
-{
-       struct flock fl;
-       int ret;
-
-       if (tdb->flags & TDB_NOLOCK)
-               return 0;
-       if ((rw_type == F_WRLCK) && (tdb->read_only)) {
-               errno = EACCES;
-               return -1;
-       }
-
-       fl.l_type = rw_type;
-       fl.l_whence = SEEK_SET;
-       fl.l_start = offset;
-       fl.l_len = 1;
-       fl.l_pid = 0;
-
-       do {
-               ret = fcntl(tdb->fd,lck_type,&fl);
-               if (ret == -1 && errno == EINTR && palarm_fired && *palarm_fired)
-                       break;
-       } while (ret == -1 && errno == EINTR);
-
-       if (ret == -1) {
-               if (!probe && lck_type != F_SETLK) {
-                       /* Ensure error code is set for log fun to examine. */
-                       if (errno == EINTR && palarm_fired && *palarm_fired)
-                               tdb->ecode = TDB_ERR_LOCK_TIMEOUT;
-                       else
-                               tdb->ecode = TDB_ERR_LOCK;
-                       TDB_LOG((tdb, 5,"tdb_brlock failed (fd=%d) at offset %d rw_type=%d lck_type=%d\n", 
-                                tdb->fd, offset, rw_type, lck_type));
-               }
-               /* Was it an alarm timeout ? */
-               if (errno == EINTR && palarm_fired && *palarm_fired)
-                       return TDB_ERRCODE(TDB_ERR_LOCK_TIMEOUT, -1);
-               /* Otherwise - generic lock error. */
-               /* errno set by fcntl */
-               return TDB_ERRCODE(TDB_ERR_LOCK, -1);
-       }
-       return 0;
-}
-
-/* lock a list in the database. list -1 is the alloc list */
-static int tdb_lock(TDB_CONTEXT *tdb, int list, int ltype)
-{
-       if (list < -1 || list >= (int)tdb->header.hash_size) {
-               TDB_LOG((tdb, 0,"tdb_lock: invalid list %d for ltype=%d\n", 
-                          list, ltype));
-               return -1;
-       }
-       if (tdb->flags & TDB_NOLOCK)
-               return 0;
-
-       /* Since fcntl locks don't nest, we do a lock for the first one,
-          and simply bump the count for future ones */
-       if (tdb->locked[list+1].count == 0) {
-               if (!tdb->read_only && tdb->header.rwlocks) {
-                       if (tdb_spinlock(tdb, list, ltype)) {
-                               TDB_LOG((tdb, 0, "tdb_lock spinlock failed on list ltype=%d\n", 
-                                          list, ltype));
-                               return -1;
-                       }
-               } else if (tdb_brlock(tdb,FREELIST_TOP+4*list,ltype,F_SETLKW, 0)) {
-                       TDB_LOG((tdb, 0,"tdb_lock failed on list %d ltype=%d (%s)\n", 
-                                          list, ltype, strerror(errno)));
-                       return -1;
-               }
-               tdb->locked[list+1].ltype = ltype;
-       }
-       tdb->locked[list+1].count++;
-       return 0;
-}
-
-/* unlock the database: returns void because it's too late for errors. */
-       /* changed to return int it may be interesting to know there
-          has been an error  --simo */
-static int tdb_unlock(TDB_CONTEXT *tdb, int list, int ltype)
-{
-       int ret = -1;
-
-       if (tdb->flags & TDB_NOLOCK)
-               return 0;
-
-       /* Sanity checks */
-       if (list < -1 || list >= (int)tdb->header.hash_size) {
-               TDB_LOG((tdb, 0, "tdb_unlock: list %d invalid (%d)\n", list, tdb->header.hash_size));
-               return ret;
-       }
-
-       if (tdb->locked[list+1].count==0) {
-               TDB_LOG((tdb, 0, "tdb_unlock: count is 0\n"));
-               return ret;
-       }
-
-       if (tdb->locked[list+1].count == 1) {
-               /* Down to last nested lock: unlock underneath */
-               if (!tdb->read_only && tdb->header.rwlocks) {
-                       ret = tdb_spinunlock(tdb, list, ltype);
-               } else {
-                       ret = tdb_brlock(tdb, FREELIST_TOP+4*list, F_UNLCK, F_SETLKW, 0);
-               }
-       } else {
-               ret = 0;
-       }
-       tdb->locked[list+1].count--;
-
-       if (ret)
-               TDB_LOG((tdb, 0,"tdb_unlock: An error occurred unlocking!\n")); 
-       return ret;
-}
-
-/* This is based on the hash algorithm from gdbm */
-static u32 tdb_hash(TDB_DATA *key)
-{
-       u32 value;      /* Used to compute the hash value.  */
-       u32   i;        /* Used to cycle through random values. */
-
-       /* Set the initial value from the key size. */
-       for (value = 0x238F13AF * key->dsize, i=0; i < key->dsize; i++)
-               value = (value + (key->dptr[i] << (i*5 % 24)));
-
-       return (1103515243 * value + 12345);  
-}
-
-/* check for an out of bounds access - if it is out of bounds then
-   see if the database has been expanded by someone else and expand
-   if necessary 
-   note that "len" is the minimum length needed for the db
+/*
+  increment the tdb sequence number if the tdb has been opened using
+  the TDB_SEQNUM flag
 */
-static int tdb_oob(TDB_CONTEXT *tdb, tdb_off len, int probe)
-{
-       struct stat st;
-       if (len <= tdb->map_size)
-               return 0;
-       if (tdb->flags & TDB_INTERNAL) {
-               if (!probe) {
-                       /* Ensure ecode is set for log fn. */
-                       tdb->ecode = TDB_ERR_IO;
-                       TDB_LOG((tdb, 0,"tdb_oob len %d beyond internal malloc size %d\n",
-                                (int)len, (int)tdb->map_size));
-               }
-               return TDB_ERRCODE(TDB_ERR_IO, -1);
-       }
-
-       if (fstat(tdb->fd, &st) == -1)
-               return TDB_ERRCODE(TDB_ERR_IO, -1);
-
-       if (st.st_size < (size_t)len) {
-               if (!probe) {
-                       /* Ensure ecode is set for log fn. */
-                       tdb->ecode = TDB_ERR_IO;
-                       TDB_LOG((tdb, 0,"tdb_oob len %d beyond eof at %d\n",
-                                (int)len, (int)st.st_size));
-               }
-               return TDB_ERRCODE(TDB_ERR_IO, -1);
-       }
-
-       /* Unmap, update size, remap */
-       if (tdb_munmap(tdb) == -1)
-               return TDB_ERRCODE(TDB_ERR_IO, -1);
-       tdb->map_size = st.st_size;
-       tdb_mmap(tdb);
-       return 0;
-}
-
-/* write a lump of data at a specified offset */
-static int tdb_write(TDB_CONTEXT *tdb, tdb_off off, void *buf, tdb_len len)
-{
-       if (tdb_oob(tdb, off + len, 0) != 0)
-               return -1;
-
-       if (tdb->map_ptr)
-               memcpy(off + (char *)tdb->map_ptr, buf, len);
-#ifdef HAVE_PWRITE
-       else if (pwrite(tdb->fd, buf, len, off) != (ssize_t)len) {
-#else
-       else if (lseek(tdb->fd, off, SEEK_SET) != off
-                || write(tdb->fd, buf, len) != (ssize_t)len) {
-#endif
-               /* Ensure ecode is set for log fn. */
-               tdb->ecode = TDB_ERR_IO;
-               TDB_LOG((tdb, 0,"tdb_write failed at %d len=%d (%s)\n",
-                          off, len, strerror(errno)));
-               return TDB_ERRCODE(TDB_ERR_IO, -1);
-       }
-       return 0;
-}
-
-/* read a lump of data at a specified offset, maybe convert */
-static int tdb_read(TDB_CONTEXT *tdb,tdb_off off,void *buf,tdb_len len,int cv)
-{
-       if (tdb_oob(tdb, off + len, 0) != 0)
-               return -1;
-
-       if (tdb->map_ptr)
-               memcpy(buf, off + (char *)tdb->map_ptr, len);
-#ifdef HAVE_PREAD
-       else if (pread(tdb->fd, buf, len, off) != (ssize_t)len) {
-#else
-       else if (lseek(tdb->fd, off, SEEK_SET) != off
-                || read(tdb->fd, buf, len) != (ssize_t)len) {
-#endif
-               /* Ensure ecode is set for log fn. */
-               tdb->ecode = TDB_ERR_IO;
-               TDB_LOG((tdb, 0,"tdb_read failed at %d len=%d (%s)\n",
-                          off, len, strerror(errno)));
-               return TDB_ERRCODE(TDB_ERR_IO, -1);
-       }
-       if (cv)
-               convert(buf, len);
-       return 0;
-}
-
-/* read a lump of data, allocating the space for it */
-static char *tdb_alloc_read(TDB_CONTEXT *tdb, tdb_off offset, tdb_len len)
-{
-       char *buf;
-
-       if (!(buf = malloc(len))) {
-               /* Ensure ecode is set for log fn. */
-               tdb->ecode = TDB_ERR_OOM;
-               TDB_LOG((tdb, 0,"tdb_alloc_read malloc failed len=%d (%s)\n",
-                          len, strerror(errno)));
-               return TDB_ERRCODE(TDB_ERR_OOM, buf);
-       }
-       if (tdb_read(tdb, offset, buf, len, 0) == -1) {
-               SAFE_FREE(buf);
-               return NULL;
-       }
-       return buf;
-}
-
-/* read/write a tdb_off */
-static int ofs_read(TDB_CONTEXT *tdb, tdb_off offset, tdb_off *d)
-{
-       return tdb_read(tdb, offset, (char*)d, sizeof(*d), DOCONV());
-}
-static int ofs_write(TDB_CONTEXT *tdb, tdb_off offset, tdb_off *d)
-{
-       tdb_off off = *d;
-       return tdb_write(tdb, offset, CONVERT(off), sizeof(*d));
-}
-
-/* read/write a record */
-static int rec_read(TDB_CONTEXT *tdb, tdb_off offset, struct list_struct *rec)
-{
-       if (tdb_read(tdb, offset, rec, sizeof(*rec),DOCONV()) == -1)
-               return -1;
-       if (TDB_BAD_MAGIC(rec)) {
-               /* Ensure ecode is set for log fn. */
-               tdb->ecode = TDB_ERR_CORRUPT;
-               TDB_LOG((tdb, 0,"rec_read bad magic 0x%x at offset=%d\n", rec->magic, offset));
-               return TDB_ERRCODE(TDB_ERR_CORRUPT, -1);
-       }
-       return tdb_oob(tdb, rec->next+sizeof(*rec), 0);
-}
-static int rec_write(TDB_CONTEXT *tdb, tdb_off offset, struct list_struct *rec)
-{
-       struct list_struct r = *rec;
-       return tdb_write(tdb, offset, CONVERT(r), sizeof(r));
-}
-
-/* read a freelist record and check for simple errors */
-static int rec_free_read(TDB_CONTEXT *tdb, tdb_off off, struct list_struct *rec)
-{
-       if (tdb_read(tdb, off, rec, sizeof(*rec),DOCONV()) == -1)
-               return -1;
-
-       if (rec->magic == TDB_MAGIC) {
-               /* this happens when a app is showdown while deleting a record - we should
-                  not completely fail when this happens */
-               TDB_LOG((tdb, 0,"rec_free_read non-free magic at offset=%d - fixing\n", 
-                        rec->magic, off));
-               rec->magic = TDB_FREE_MAGIC;
-               if (tdb_write(tdb, off, rec, sizeof(*rec)) == -1)
-                       return -1;
-       }
-
-       if (rec->magic != TDB_FREE_MAGIC) {
-               /* Ensure ecode is set for log fn. */
-               tdb->ecode = TDB_ERR_CORRUPT;
-               TDB_LOG((tdb, 0,"rec_free_read bad magic 0x%x at offset=%d\n", 
-                          rec->magic, off));
-               return TDB_ERRCODE(TDB_ERR_CORRUPT, -1);
-       }
-       if (tdb_oob(tdb, rec->next+sizeof(*rec), 0) != 0)
-               return -1;
-       return 0;
-}
-
-/* update a record tailer (must hold allocation lock) */
-static int update_tailer(TDB_CONTEXT *tdb, tdb_off offset,
-                        const struct list_struct *rec)
-{
-       tdb_off totalsize;
-
-       /* Offset of tailer from record header */
-       totalsize = sizeof(*rec) + rec->rec_len;
-       return ofs_write(tdb, offset + totalsize - sizeof(tdb_off),
-                        &totalsize);
-}
-
-static tdb_off tdb_dump_record(TDB_CONTEXT *tdb, tdb_off offset)
-{
-       struct list_struct rec;
-       tdb_off tailer_ofs, tailer;
-
-       if (tdb_read(tdb, offset, (char *)&rec, sizeof(rec), DOCONV()) == -1) {
-               printf("ERROR: failed to read record at %u\n", offset);
-               return 0;
-       }
-
-       printf(" rec: offset=%u next=%d rec_len=%d key_len=%d data_len=%d full_hash=0x%x magic=0x%x\n",
-              offset, rec.next, rec.rec_len, rec.key_len, rec.data_len, rec.full_hash, rec.magic);
-
-       tailer_ofs = offset + sizeof(rec) + rec.rec_len - sizeof(tdb_off);
-       if (ofs_read(tdb, tailer_ofs, &tailer) == -1) {
-               printf("ERROR: failed to read tailer at %u\n", tailer_ofs);
-               return rec.next;
-       }
-
-       if (tailer != rec.rec_len + sizeof(rec)) {
-               printf("ERROR: tailer does not match record! tailer=%u totalsize=%u\n",
-                               (unsigned)tailer, (unsigned)(rec.rec_len + sizeof(rec)));
-       }
-       return rec.next;
-}
-
-static int tdb_dump_chain(TDB_CONTEXT *tdb, int i)
-{
-       tdb_off rec_ptr, top;
-
-       top = TDB_HASH_TOP(i);
-
-       if (tdb_lock(tdb, i, F_WRLCK) != 0)
-               return -1;
-
-       if (ofs_read(tdb, top, &rec_ptr) == -1)
-               return tdb_unlock(tdb, i, F_WRLCK);
-
-       if (rec_ptr)
-               printf("hash=%d\n", i);
-
-       while (rec_ptr) {
-               rec_ptr = tdb_dump_record(tdb, rec_ptr);
-       }
-
-       return tdb_unlock(tdb, i, F_WRLCK);
-}
-
-void tdb_dump_all(TDB_CONTEXT *tdb)
-{
-       unsigned int i;
-       for (i=0;i<tdb->header.hash_size;i++) {
-               tdb_dump_chain(tdb, i);
-       }
-       printf("freelist:\n");
-       tdb_dump_chain(tdb, -1);
-}
-
-int tdb_printfreelist(TDB_CONTEXT *tdb)
-{
-       int ret;
-       long total_free = 0;
-       tdb_off offset, rec_ptr;
-       struct list_struct rec;
-
-       if ((ret = tdb_lock(tdb, -1, F_WRLCK)) != 0)
-               return ret;
-
-       offset = FREELIST_TOP;
-
-       /* read in the freelist top */
-       if (ofs_read(tdb, offset, &rec_ptr) == -1) {
-               tdb_unlock(tdb, -1, F_WRLCK);
-               return 0;
-       }
-
-       printf("freelist top=[0x%08x]\n", rec_ptr );
-       while (rec_ptr) {
-               if (tdb_read(tdb, rec_ptr, (char *)&rec, sizeof(rec), DOCONV()) == -1) {
-                       tdb_unlock(tdb, -1, F_WRLCK);
-                       return -1;
-               }
-
-               if (rec.magic != TDB_FREE_MAGIC) {
-                       printf("bad magic 0x%08x in free list\n", rec.magic);
-                       tdb_unlock(tdb, -1, F_WRLCK);
-                       return -1;
-               }
-
-               printf("entry offset=[0x%08x], rec.rec_len = [0x%08x (%d)]\n", rec.next, rec.rec_len, rec.rec_len );
-               total_free += rec.rec_len;
-
-               /* move to the next record */
-               rec_ptr = rec.next;
-       }
-       printf("total rec_len = [0x%08x (%d)]\n", (int)total_free, 
-               (int)total_free);
-
-       return tdb_unlock(tdb, -1, F_WRLCK);
-}
-
-/* Remove an element from the freelist.  Must have alloc lock. */
-static int remove_from_freelist(TDB_CONTEXT *tdb, tdb_off off, tdb_off next)
-{
-       tdb_off last_ptr, i;
-
-       /* read in the freelist top */
-       last_ptr = FREELIST_TOP;
-       while (ofs_read(tdb, last_ptr, &i) != -1 && i != 0) {
-               if (i == off) {
-                       /* We've found it! */
-                       return ofs_write(tdb, last_ptr, &next);
-               }
-               /* Follow chain (next offset is at start of record) */
-               last_ptr = i;
-       }
-       TDB_LOG((tdb, 0,"remove_from_freelist: not on list at off=%d\n", off));
-       return TDB_ERRCODE(TDB_ERR_CORRUPT, -1);
-}
-
-/* Add an element into the freelist. Merge adjacent records if
-   neccessary. */
-static int tdb_free(TDB_CONTEXT *tdb, tdb_off offset, struct list_struct *rec)
-{
-       tdb_off right, left;
-
-       /* Allocation and tailer lock */
-       if (tdb_lock(tdb, -1, F_WRLCK) != 0)
-               return -1;
-
-       /* set an initial tailer, so if we fail we don't leave a bogus record */
-       if (update_tailer(tdb, offset, rec) != 0) {
-               TDB_LOG((tdb, 0, "tdb_free: upfate_tailer failed!\n"));
-               goto fail;
-       }
-
-       /* Look right first (I'm an Australian, dammit) */
-       right = offset + sizeof(*rec) + rec->rec_len;
-       if (right + sizeof(*rec) <= tdb->map_size) {
-               struct list_struct r;
-
-               if (tdb_read(tdb, right, &r, sizeof(r), DOCONV()) == -1) {
-                       TDB_LOG((tdb, 0, "tdb_free: right read failed at %u\n", right));
-                       goto left;
-               }
-
-               /* If it's free, expand to include it. */
-               if (r.magic == TDB_FREE_MAGIC) {
-                       if (remove_from_freelist(tdb, right, r.next) == -1) {
-                               TDB_LOG((tdb, 0, "tdb_free: right free failed at %u\n", right));
-                               goto left;
-                       }
-                       rec->rec_len += sizeof(r) + r.rec_len;
-               }
-       }
-
-left:
-       /* Look left */
-       left = offset - sizeof(tdb_off);
-       if (left > TDB_HASH_TOP(tdb->header.hash_size-1)) {
-               struct list_struct l;
-               tdb_off leftsize;
-
-               /* Read in tailer and jump back to header */
-               if (ofs_read(tdb, left, &leftsize) == -1) {
-                       TDB_LOG((tdb, 0, "tdb_free: left offset read failed at %u\n", left));
-                       goto update;
-               }
-               left = offset - leftsize;
-
-               /* Now read in record */
-               if (tdb_read(tdb, left, &l, sizeof(l), DOCONV()) == -1) {
-                       TDB_LOG((tdb, 0, "tdb_free: left read failed at %u (%u)\n", left, leftsize));
-                       goto update;
-               }
-
-               /* If it's free, expand to include it. */
-               if (l.magic == TDB_FREE_MAGIC) {
-                       if (remove_from_freelist(tdb, left, l.next) == -1) {
-                               TDB_LOG((tdb, 0, "tdb_free: left free failed at %u\n", left));
-                               goto update;
-                       } else {
-                               offset = left;
-                               rec->rec_len += leftsize;
-                       }
-               }
-       }
-
-update:
-       if (update_tailer(tdb, offset, rec) == -1) {
-               TDB_LOG((tdb, 0, "tdb_free: update_tailer failed at %u\n", offset));
-               goto fail;
-       }
-
-       /* Now, prepend to free list */
-       rec->magic = TDB_FREE_MAGIC;
-
-       if (ofs_read(tdb, FREELIST_TOP, &rec->next) == -1 ||
-           rec_write(tdb, offset, rec) == -1 ||
-           ofs_write(tdb, FREELIST_TOP, &offset) == -1) {
-               TDB_LOG((tdb, 0, "tdb_free record write failed at offset=%d\n", offset));
-               goto fail;
-       }
-
-       /* And we're done. */
-       tdb_unlock(tdb, -1, F_WRLCK);
-       return 0;
-
- fail:
-       tdb_unlock(tdb, -1, F_WRLCK);
-       return -1;
-}
-
-
-/* expand a file.  we prefer to use ftruncate, as that is what posix
-  says to use for mmap expansion */
-static int expand_file(TDB_CONTEXT *tdb, tdb_off size, tdb_off addition)
-{
-       char buf[1024];
-#if HAVE_FTRUNCATE_EXTEND
-       if (ftruncate(tdb->fd, size+addition) != 0) {
-               TDB_LOG((tdb, 0, "expand_file ftruncate to %d failed (%s)\n", 
-                          size+addition, strerror(errno)));
-               return -1;
-       }
-#else
-       char b = 0;
-
-#ifdef HAVE_PWRITE
-       if (pwrite(tdb->fd,  &b, 1, (size+addition) - 1) != 1) {
-#else
-       if (lseek(tdb->fd, (size+addition) - 1, SEEK_SET) != (size+addition) - 1 || 
-           write(tdb->fd, &b, 1) != 1) {
-#endif
-               TDB_LOG((tdb, 0, "expand_file to %d failed (%s)\n", 
-                          size+addition, strerror(errno)));
-               return -1;
-       }
-#endif
-
-       /* now fill the file with something. This ensures that the file isn't sparse, which would be
-          very bad if we ran out of disk. This must be done with write, not via mmap */
-       memset(buf, 0x42, sizeof(buf));
-       while (addition) {
-               int n = addition>sizeof(buf)?sizeof(buf):addition;
-#ifdef HAVE_PWRITE
-               int ret = pwrite(tdb->fd, buf, n, size);
-#else
-               int ret;
-               if (lseek(tdb->fd, size, SEEK_SET) != size)
-                       return -1;
-               ret = write(tdb->fd, buf, n);
-#endif
-               if (ret != n) {
-                       TDB_LOG((tdb, 0, "expand_file write of %d failed (%s)\n", 
-                                  n, strerror(errno)));
-                       return -1;
-               }
-               addition -= n;
-               size += n;
-       }
-       return 0;
-}
-
-
-/* expand the database at least size bytes by expanding the underlying
-   file and doing the mmap again if necessary */
-static int tdb_expand(TDB_CONTEXT *tdb, tdb_off size)
+static void tdb_increment_seqnum(struct tdb_context *tdb)
 {
-       struct list_struct rec;
-       tdb_off offset;
-
-       if (tdb_lock(tdb, -1, F_WRLCK) == -1) {
-               TDB_LOG((tdb, 0, "lock failed in tdb_expand\n"));
-               return -1;
-       }
-
-       /* must know about any previous expansions by another process */
-       tdb_oob(tdb, tdb->map_size + 1, 1);
-
-       /* always make room for at least 10 more records, and round
-           the database up to a multiple of TDB_PAGE_SIZE */
-       size = TDB_ALIGN(tdb->map_size + size*10, TDB_PAGE_SIZE) - tdb->map_size;
-
-       if (!(tdb->flags & TDB_INTERNAL))
-               tdb_munmap(tdb);
-
-       /*
-        * We must ensure the file is unmapped before doing this
-        * to ensure consistency with systems like OpenBSD where
-        * writes and mmaps are not consistent.
-        */
-
-       /* expand the file itself */
-       if (!(tdb->flags & TDB_INTERNAL)) {
-               if (expand_file(tdb, tdb->map_size, size) != 0)
-                       goto fail;
+       if (!(tdb->flags & TDB_SEQNUM)) {
+               return;
        }
 
-       tdb->map_size += size;
-
-       if (tdb->flags & TDB_INTERNAL)
-               tdb->map_ptr = realloc(tdb->map_ptr, tdb->map_size);
-       else {
-               /*
-                * We must ensure the file is remapped before adding the space
-                * to ensure consistency with systems like OpenBSD where
-                * writes and mmaps are not consistent.
-                */
-
-               /* We're ok if the mmap fails as we'll fallback to read/write */
-               tdb_mmap(tdb);
+       if (tdb_brlock(tdb, TDB_SEQNUM_OFS, F_WRLCK, F_SETLKW, 1, 1) != 0) {
+               return;
        }
 
-       /* form a new freelist record */
-       memset(&rec,'\0',sizeof(rec));
-       rec.rec_len = size - sizeof(rec);
+       tdb_increment_seqnum_nonblock(tdb);
 
-       /* link it into the free list */
-       offset = tdb->map_size - size;
-       if (tdb_free(tdb, offset, &rec) == -1)
-               goto fail;
-
-       tdb_unlock(tdb, -1, F_WRLCK);
-       return 0;
- fail:
-       tdb_unlock(tdb, -1, F_WRLCK);
-       return -1;
+       tdb_brlock(tdb, TDB_SEQNUM_OFS, F_UNLCK, F_SETLKW, 1, 1);
 }
 
-/* allocate some space from the free list. The offset returned points
-   to a unconnected list_struct within the database with room for at
-   least length bytes of total data
-
-   0 is returned if the space could not be allocated
- */
-static tdb_off tdb_allocate(TDB_CONTEXT *tdb, tdb_len length,
-                           struct list_struct *rec)
+static int tdb_key_compare(TDB_DATA key, TDB_DATA data, void *private_data)
 {
-       tdb_off rec_ptr, last_ptr, newrec_ptr;
-       struct list_struct newrec;
-
-       if (tdb_lock(tdb, -1, F_WRLCK) == -1)
-               return 0;
-
-       /* Extra bytes required for tailer */
-       length += sizeof(tdb_off);
-
- again:
-       last_ptr = FREELIST_TOP;
-
-       /* read in the freelist top */
-       if (ofs_read(tdb, FREELIST_TOP, &rec_ptr) == -1)
-               goto fail;
-
-       /* keep looking until we find a freelist record big enough */
-       while (rec_ptr) {
-               if (rec_free_read(tdb, rec_ptr, rec) == -1)
-                       goto fail;
-
-               if (rec->rec_len >= length) {
-                       /* found it - now possibly split it up  */
-                       if (rec->rec_len > length + MIN_REC_SIZE) {
-                               /* Length of left piece */
-                               length = TDB_ALIGN(length, TDB_ALIGNMENT);
-
-                               /* Right piece to go on free list */
-                               newrec.rec_len = rec->rec_len
-                                       - (sizeof(*rec) + length);
-                               newrec_ptr = rec_ptr + sizeof(*rec) + length;
-
-                               /* And left record is shortened */
-                               rec->rec_len = length;
-                       } else
-                               newrec_ptr = 0;
-
-                       /* Remove allocated record from the free list */
-                       if (ofs_write(tdb, last_ptr, &rec->next) == -1)
-                               goto fail;
-
-                       /* Update header: do this before we drop alloc
-                           lock, otherwise tdb_free() might try to
-                           merge with us, thinking we're free.
-                           (Thanks Jeremy Allison). */
-                       rec->magic = TDB_MAGIC;
-                       if (rec_write(tdb, rec_ptr, rec) == -1)
-                               goto fail;
-
-                       /* Did we create new block? */
-                       if (newrec_ptr) {
-                               /* Update allocated record tailer (we
-                                   shortened it). */
-                               if (update_tailer(tdb, rec_ptr, rec) == -1)
-                                       goto fail;
-
-                               /* Free new record */
-                               if (tdb_free(tdb, newrec_ptr, &newrec) == -1)
-                                       goto fail;
-                       }
-
-                       /* all done - return the new record offset */
-                       tdb_unlock(tdb, -1, F_WRLCK);
-                       return rec_ptr;
-               }
-               /* move to the next record */
-               last_ptr = rec_ptr;
-               rec_ptr = rec->next;
-       }
-       /* we didn't find enough space. See if we can expand the
-          database and if we can then try again */
-       if (tdb_expand(tdb, length + sizeof(*rec)) == 0)
-               goto again;
- fail:
-       tdb_unlock(tdb, -1, F_WRLCK);
-       return 0;
-}
-
-/* initialise a new database with a specified hash size */
-static int tdb_new_database(TDB_CONTEXT *tdb, int hash_size)
-{
-       struct tdb_header *newdb;
-       int size, ret = -1;
-
-       /* We make it up in memory, then write it out if not internal */
-       size = sizeof(struct tdb_header) + (hash_size+1)*sizeof(tdb_off);
-       if (!(newdb = calloc(size, 1)))
-               return TDB_ERRCODE(TDB_ERR_OOM, -1);
-
-       /* Fill in the header */
-       newdb->version = TDB_VERSION;
-       newdb->hash_size = hash_size;
-#ifdef USE_SPINLOCKS
-       newdb->rwlocks = size;
-#endif
-       if (tdb->flags & TDB_INTERNAL) {
-               tdb->map_size = size;
-               tdb->map_ptr = (char *)newdb;
-               memcpy(&tdb->header, newdb, sizeof(tdb->header));
-               /* Convert the `ondisk' version if asked. */
-               CONVERT(*newdb);
-               return 0;
-       }
-       if (lseek(tdb->fd, 0, SEEK_SET) == -1)
-               goto fail;
-
-       if (ftruncate(tdb->fd, 0) == -1)
-               goto fail;
-
-       /* This creates an endian-converted header, as if read from disk */
-       CONVERT(*newdb);
-       memcpy(&tdb->header, newdb, sizeof(tdb->header));
-       /* Don't endian-convert the magic food! */
-       memcpy(newdb->magic_food, TDB_MAGIC_FOOD, strlen(TDB_MAGIC_FOOD)+1);
-       if (write(tdb->fd, newdb, size) != size)
-               ret = -1;
-       else
-               ret = tdb_create_rwlocks(tdb->fd, hash_size);
-
-  fail:
-       SAFE_FREE(newdb);
-       return ret;
+       return memcmp(data.dptr, key.dptr, data.dsize);
 }
 
 /* Returns 0 on fail.  On success, return offset of record, and fills
    in rec */
-static tdb_off tdb_find(TDB_CONTEXT *tdb, TDB_DATA key, u32 hash,
-                       struct list_struct *r)
+static tdb_off_t tdb_find(struct tdb_context *tdb, TDB_DATA key, uint32_t hash,
+                       struct tdb_record *r)
 {
-       tdb_off rec_ptr;
+       tdb_off_t rec_ptr;
        
        /* read in the hash top */
-       if (ofs_read(tdb, TDB_HASH_TOP(hash), &rec_ptr) == -1)
+       if (tdb_ofs_read(tdb, TDB_HASH_TOP(hash), &rec_ptr) == -1)
                return 0;
 
        /* keep looking until we find the right record */
        while (rec_ptr) {
-               if (rec_read(tdb, rec_ptr, r) == -1)
+               if (tdb_rec_read(tdb, rec_ptr, r) == -1)
                        return 0;
 
-               if (!TDB_DEAD(r) && hash==r->full_hash && key.dsize==r->key_len) {
-                       char *k;
-                       /* a very likely hit - read the key */
-                       k = tdb_alloc_read(tdb, rec_ptr + sizeof(*r), 
-                                          r->key_len);
-                       if (!k)
-                               return 0;
-
-                       if (memcmp(key.dptr, k, key.dsize) == 0) {
-                               SAFE_FREE(k);
-                               return rec_ptr;
-                       }
-                       SAFE_FREE(k);
+               if (!TDB_DEAD(r) && hash==r->full_hash
+                   && key.dsize==r->key_len
+                   && tdb_parse_data(tdb, key, rec_ptr + sizeof(*r),
+                                     r->key_len, tdb_key_compare,
+                                     NULL) == 0) {
+                       return rec_ptr;
+               }
+               /* detect tight infinite loop */
+               if (rec_ptr == r->next) {
+                       tdb->ecode = TDB_ERR_CORRUPT;
+                       TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_find: loop detected.\n"));
+                       return 0;
                }
                rec_ptr = r->next;
        }
-       return TDB_ERRCODE(TDB_ERR_NOEXIST, 0);
-}
-
-/* If they do lockkeys, check that this hash is one they locked */
-static int tdb_keylocked(TDB_CONTEXT *tdb, u32 hash)
-{
-       u32 i;
-       if (!tdb->lockedkeys)
-               return 1;
-       for (i = 0; i < tdb->lockedkeys[0]; i++)
-               if (tdb->lockedkeys[i+1] == hash)
-                       return 1;
-       return TDB_ERRCODE(TDB_ERR_NOLOCK, 0);
+       tdb->ecode = TDB_ERR_NOEXIST;
+       return 0;
 }
 
 /* As tdb_find, but if you succeed, keep the lock */
-static tdb_off tdb_find_lock(TDB_CONTEXT *tdb, TDB_DATA key, int locktype,
-                            struct list_struct *rec)
+tdb_off_t tdb_find_lock_hash(struct tdb_context *tdb, TDB_DATA key, uint32_t hash, int locktype,
+                          struct tdb_record *rec)
 {
-       u32 hash, rec_ptr;
+       uint32_t rec_ptr;
 
-       hash = tdb_hash(&key);
-       if (!tdb_keylocked(tdb, hash))
-               return 0;
        if (tdb_lock(tdb, BUCKET(hash), locktype) == -1)
                return 0;
        if (!(rec_ptr = tdb_find(tdb, key, hash, rec)))
@@ -1032,60 +121,54 @@ static tdb_off tdb_find_lock(TDB_CONTEXT *tdb, TDB_DATA key, int locktype,
        return rec_ptr;
 }
 
-enum TDB_ERROR tdb_error(TDB_CONTEXT *tdb)
-{
-       return tdb->ecode;
-}
-
-static struct tdb_errname {
-       enum TDB_ERROR ecode; const char *estring;
-} emap[] = { {TDB_SUCCESS, "Success"},
-            {TDB_ERR_CORRUPT, "Corrupt database"},
-            {TDB_ERR_IO, "IO Error"},
-            {TDB_ERR_LOCK, "Locking error"},
-            {TDB_ERR_OOM, "Out of memory"},
-            {TDB_ERR_EXISTS, "Record exists"},
-            {TDB_ERR_NOLOCK, "Lock exists on other keys"},
-            {TDB_ERR_NOEXIST, "Record does not exist"} };
-
-/* Error string for the last tdb error */
-const char *tdb_errorstr(TDB_CONTEXT *tdb)
-{
-       u32 i;
-       for (i = 0; i < sizeof(emap) / sizeof(struct tdb_errname); i++)
-               if (tdb->ecode == emap[i].ecode)
-                       return emap[i].estring;
-       return "Invalid error code";
-}
+static TDB_DATA _tdb_fetch(struct tdb_context *tdb, TDB_DATA key);
 
 /* update an entry in place - this only works if the new data size
    is <= the old data size and the key exists.
    on failure return -1.
 */
-
-static int tdb_update(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf)
+static int tdb_update_hash(struct tdb_context *tdb, TDB_DATA key, uint32_t hash, TDB_DATA dbuf)
 {
-       struct list_struct rec;
-       tdb_off rec_ptr;
+       struct tdb_record rec;
+       tdb_off_t rec_ptr;
 
        /* find entry */
-       if (!(rec_ptr = tdb_find(tdb, key, tdb_hash(&key), &rec)))
+       if (!(rec_ptr = tdb_find(tdb, key, hash, &rec)))
                return -1;
 
+       /* it could be an exact duplicate of what is there - this is
+        * surprisingly common (eg. with a ldb re-index). */
+       if (rec.key_len == key.dsize && 
+           rec.data_len == dbuf.dsize &&
+           rec.full_hash == hash) {
+               TDB_DATA data = _tdb_fetch(tdb, key);
+               if (data.dsize == dbuf.dsize &&
+                   memcmp(data.dptr, dbuf.dptr, data.dsize) == 0) {
+                       if (data.dptr) {
+                               free(data.dptr);
+                       }
+                       return 0;
+               }
+               if (data.dptr) {
+                       free(data.dptr);
+               }
+       }
+        
+
        /* must be long enough key, data and tailer */
-       if (rec.rec_len < key.dsize + dbuf.dsize + sizeof(tdb_off)) {
+       if (rec.rec_len < key.dsize + dbuf.dsize + sizeof(tdb_off_t)) {
                tdb->ecode = TDB_SUCCESS; /* Not really an error */
                return -1;
        }
 
-       if (tdb_write(tdb, rec_ptr + sizeof(rec) + rec.key_len,
+       if (tdb->methods->tdb_write(tdb, rec_ptr + sizeof(rec) + rec.key_len,
                      dbuf.dptr, dbuf.dsize) == -1)
                return -1;
 
        if (dbuf.dsize != rec.data_len) {
                /* update size */
                rec.data_len = dbuf.dsize;
-               return rec_write(tdb, rec_ptr, &rec);
+               return tdb_rec_write(tdb, rec_ptr, &rec);
        }
  
        return 0;
@@ -1094,116 +177,134 @@ static int tdb_update(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf)
 /* find an entry in the database given a key */
 /* If an entry doesn't exist tdb_err will be set to
  * TDB_ERR_NOEXIST. If a key has no data attached
- * tdb_err will not be set. Both will return a
- * zero pptr and zero dsize.
+ * then the TDB_DATA will have zero length but
+ * a non-zero pointer
  */
-
-TDB_DATA tdb_fetch(TDB_CONTEXT *tdb, TDB_DATA key)
+static TDB_DATA _tdb_fetch(struct tdb_context *tdb, TDB_DATA key)
 {
-       tdb_off rec_ptr;
-       struct list_struct rec;
+       tdb_off_t rec_ptr;
+       struct tdb_record rec;
        TDB_DATA ret;
+       uint32_t hash;
 
        /* find which hash bucket it is in */
-       if (!(rec_ptr = tdb_find_lock(tdb,key,F_RDLCK,&rec)))
+       hash = tdb->hash_fn(&key);
+       if (!(rec_ptr = tdb_find_lock_hash(tdb,key,hash,F_RDLCK,&rec)))
                return tdb_null;
 
-       if (rec.data_len)
-               ret.dptr = tdb_alloc_read(tdb, rec_ptr + sizeof(rec) + rec.key_len,
-                                         rec.data_len);
-       else
-               ret.dptr = NULL;
+       ret.dptr = tdb_alloc_read(tdb, rec_ptr + sizeof(rec) + rec.key_len,
+                                 rec.data_len);
        ret.dsize = rec.data_len;
        tdb_unlock(tdb, BUCKET(rec.full_hash), F_RDLCK);
        return ret;
 }
 
+TDB_DATA tdb_fetch(struct tdb_context *tdb, TDB_DATA key)
+{
+       TDB_DATA ret = _tdb_fetch(tdb, key);
+
+       tdb_trace_1rec_retrec(tdb, "tdb_fetch", key, ret);
+       return ret;
+}
+
+/*
+ * Find an entry in the database and hand the record's data to a parsing
+ * function. The parsing function is executed under the chain read lock, so it
+ * should be fast and should not block on other syscalls.
+ *
+ * DONT CALL OTHER TDB CALLS FROM THE PARSER, THIS MIGHT LEAD TO SEGFAULTS.
+ *
+ * For mmapped tdb's that do not have a transaction open it points the parsing
+ * function directly at the mmap area, it avoids the malloc/memcpy in this
+ * case. If a transaction is open or no mmap is available, it has to do
+ * malloc/read/parse/free.
+ *
+ * This is interesting for all readers of potentially large data structures in
+ * the tdb records, ldb indexes being one example.
+ */
+
+int tdb_parse_record(struct tdb_context *tdb, TDB_DATA key,
+                    int (*parser)(TDB_DATA key, TDB_DATA data,
+                                  void *private_data),
+                    void *private_data)
+{
+       tdb_off_t rec_ptr;
+       struct tdb_record rec;
+       int ret;
+       uint32_t hash;
+
+       /* find which hash bucket it is in */
+       hash = tdb->hash_fn(&key);
+
+       if (!(rec_ptr = tdb_find_lock_hash(tdb,key,hash,F_RDLCK,&rec))) {
+               tdb_trace_1rec_ret(tdb, "tdb_parse_record", key, -1);
+               tdb->ecode = TDB_ERR_NOEXIST;
+               return 0;
+       }
+       tdb_trace_1rec_ret(tdb, "tdb_parse_record", key, 0);
+
+       ret = tdb_parse_data(tdb, key, rec_ptr + sizeof(rec) + rec.key_len,
+                            rec.data_len, parser, private_data);
+
+       tdb_unlock(tdb, BUCKET(rec.full_hash), F_RDLCK);
+
+       return ret;
+}
+
 /* check if an entry in the database exists 
 
    note that 1 is returned if the key is found and 0 is returned if not found
    this doesn't match the conventions in the rest of this module, but is
    compatible with gdbm
 */
-int tdb_exists(TDB_CONTEXT *tdb, TDB_DATA key)
+static int tdb_exists_hash(struct tdb_context *tdb, TDB_DATA key, uint32_t hash)
 {
-       struct list_struct rec;
+       struct tdb_record rec;
        
-       if (tdb_find_lock(tdb, key, F_RDLCK, &rec) == 0)
+       if (tdb_find_lock_hash(tdb, key, hash, F_RDLCK, &rec) == 0)
                return 0;
        tdb_unlock(tdb, BUCKET(rec.full_hash), F_RDLCK);
        return 1;
 }
 
-/* record lock stops delete underneath */
-static int lock_record(TDB_CONTEXT *tdb, tdb_off off)
-{
-       return off ? tdb_brlock(tdb, off, F_RDLCK, F_SETLKW, 0) : 0;
-}
-/*
-  Write locks override our own fcntl readlocks, so check it here.
-  Note this is meant to be F_SETLK, *not* F_SETLKW, as it's not
-  an error to fail to get the lock here.
-*/
-static int write_lock_record(TDB_CONTEXT *tdb, tdb_off off)
-{
-       struct tdb_traverse_lock *i;
-       for (i = &tdb->travlocks; i; i = i->next)
-               if (i->off == off)
-                       return -1;
-       return tdb_brlock(tdb, off, F_WRLCK, F_SETLK, 1);
-}
-
-/*
-  Note this is meant to be F_SETLK, *not* F_SETLKW, as it's not
-  an error to fail to get the lock here.
-*/
-
-static int write_unlock_record(TDB_CONTEXT *tdb, tdb_off off)
+int tdb_exists(struct tdb_context *tdb, TDB_DATA key)
 {
-       return tdb_brlock(tdb, off, F_UNLCK, F_SETLK, 0);
-}
-/* fcntl locks don't stack: avoid unlocking someone else's */
-static int unlock_record(TDB_CONTEXT *tdb, tdb_off off)
-{
-       struct tdb_traverse_lock *i;
-       u32 count = 0;
+       uint32_t hash = tdb->hash_fn(&key);
+       int ret;
 
-       if (off == 0)
-               return 0;
-       for (i = &tdb->travlocks; i; i = i->next)
-               if (i->off == off)
-                       count++;
-       return (count == 1 ? tdb_brlock(tdb, off, F_UNLCK, F_SETLKW, 0) : 0);
+       ret = tdb_exists_hash(tdb, key, hash);
+       tdb_trace_1rec_ret(tdb, "tdb_exists", key, ret);
+       return ret;
 }
 
 /* actually delete an entry in the database given the offset */
-static int do_delete(TDB_CONTEXT *tdb, tdb_off rec_ptr, struct list_struct*rec)
+int tdb_do_delete(struct tdb_context *tdb, tdb_off_t rec_ptr, struct tdb_record *rec)
 {
-       tdb_off last_ptr, i;
-       struct list_struct lastrec;
+       tdb_off_t last_ptr, i;
+       struct tdb_record lastrec;
 
-       if (tdb->read_only) return -1;
+       if (tdb->read_only || tdb->traverse_read) return -1;
 
-       if (write_lock_record(tdb, rec_ptr) == -1) {
+       if (((tdb->traverse_write != 0) && (!TDB_DEAD(rec))) ||
+           tdb_write_lock_record(tdb, rec_ptr) == -1) {
                /* Someone traversing here: mark it as dead */
                rec->magic = TDB_DEAD_MAGIC;
-               return rec_write(tdb, rec_ptr, rec);
+               return tdb_rec_write(tdb, rec_ptr, rec);
        }
-       if (write_unlock_record(tdb, rec_ptr) != 0)
+       if (tdb_write_unlock_record(tdb, rec_ptr) != 0)
                return -1;
 
        /* find previous record in hash chain */
-       if (ofs_read(tdb, TDB_HASH_TOP(rec->full_hash), &i) == -1)
+       if (tdb_ofs_read(tdb, TDB_HASH_TOP(rec->full_hash), &i) == -1)
                return -1;
        for (last_ptr = 0; i != rec_ptr; last_ptr = i, i = lastrec.next)
-               if (rec_read(tdb, i, &lastrec) == -1)
+               if (tdb_rec_read(tdb, i, &lastrec) == -1)
                        return -1;
 
        /* unlink it: next ptr is at start of record. */
        if (last_ptr == 0)
                last_ptr = TDB_HASH_TOP(rec->full_hash);
-       if (ofs_write(tdb, last_ptr, &rec->next) == -1)
+       if (tdb_ofs_write(tdb, last_ptr, &rec->next) == -1)
                return -1;
 
        /* recover the space */
@@ -1212,257 +313,183 @@ static int do_delete(TDB_CONTEXT *tdb, tdb_off rec_ptr, struct list_struct*rec)
        return 0;
 }
 
-/* Uses traverse lock: 0 = finish, -1 = error, other = record offset */
-static int tdb_next_lock(TDB_CONTEXT *tdb, struct tdb_traverse_lock *tlock,
-                        struct list_struct *rec)
+static int tdb_count_dead(struct tdb_context *tdb, uint32_t hash)
 {
-       int want_next = (tlock->off != 0);
-
-       /* No traversal allows if you've called tdb_lockkeys() */
-       if (tdb->lockedkeys)
-               return TDB_ERRCODE(TDB_ERR_NOLOCK, -1);
-
-       /* Lock each chain from the start one. */
-       for (; tlock->hash < tdb->header.hash_size; tlock->hash++) {
-               if (tdb_lock(tdb, tlock->hash, F_WRLCK) == -1)
-                       return -1;
-
-               /* No previous record?  Start at top of chain. */
-               if (!tlock->off) {
-                       if (ofs_read(tdb, TDB_HASH_TOP(tlock->hash),
-                                    &tlock->off) == -1)
-                               goto fail;
-               } else {
-                       /* Otherwise unlock the previous record. */
-                       if (unlock_record(tdb, tlock->off) != 0)
-                               goto fail;
-               }
+       int res = 0;
+       tdb_off_t rec_ptr;
+       struct tdb_record rec;
+       
+       /* read in the hash top */
+       if (tdb_ofs_read(tdb, TDB_HASH_TOP(hash), &rec_ptr) == -1)
+               return 0;
 
-               if (want_next) {
-                       /* We have offset of old record: grab next */
-                       if (rec_read(tdb, tlock->off, rec) == -1)
-                               goto fail;
-                       tlock->off = rec->next;
-               }
+       while (rec_ptr) {
+               if (tdb_rec_read(tdb, rec_ptr, &rec) == -1)
+                       return 0;
 
-               /* Iterate through chain */
-               while( tlock->off) {
-                       tdb_off current;
-                       if (rec_read(tdb, tlock->off, rec) == -1)
-                               goto fail;
-                       if (!TDB_DEAD(rec)) {
-                               /* Woohoo: we found one! */
-                               if (lock_record(tdb, tlock->off) != 0)
-                                       goto fail;
-                               return tlock->off;
-                       }
-                       /* Try to clean dead ones from old traverses */
-                       current = tlock->off;
-                       tlock->off = rec->next;
-                       if (do_delete(tdb, current, rec) != 0)
-                               goto fail;
+               if (rec.magic == TDB_DEAD_MAGIC) {
+                       res += 1;
                }
-               tdb_unlock(tdb, tlock->hash, F_WRLCK);
-               want_next = 0;
+               rec_ptr = rec.next;
        }
-       /* We finished iteration without finding anything */
-       return TDB_ERRCODE(TDB_SUCCESS, 0);
-
- fail:
-       tlock->off = 0;
-       if (tdb_unlock(tdb, tlock->hash, F_WRLCK) != 0)
-               TDB_LOG((tdb, 0, "tdb_next_lock: On error unlock failed!\n"));
-       return -1;
+       return res;
 }
 
-/* traverse the entire database - calling fn(tdb, key, data) on each element.
-   return -1 on error or the record count traversed
-   if fn is NULL then it is not called
-   a non-zero return value from fn() indicates that the traversal should stop
-  */
-int tdb_traverse(TDB_CONTEXT *tdb, tdb_traverse_func fn, void *state)
+/*
+ * Purge all DEAD records from a hash chain
+ */
+static int tdb_purge_dead(struct tdb_context *tdb, uint32_t hash)
 {
-       TDB_DATA key, dbuf;
-       struct list_struct rec;
-       struct tdb_traverse_lock tl = { NULL, 0, 0 };
-       int ret, count = 0;
+       int res = -1;
+       struct tdb_record rec;
+       tdb_off_t rec_ptr;
 
-       /* This was in the initializaton, above, but the IRIX compiler
-        * did not like it.  crh
-        */
-       tl.next = tdb->travlocks.next;
-
-       /* fcntl locks don't stack: beware traverse inside traverse */
-       tdb->travlocks.next = &tl;
-
-       /* tdb_next_lock places locks on the record returned, and its chain */
-       while ((ret = tdb_next_lock(tdb, &tl, &rec)) > 0) {
-               count++;
-               /* now read the full record */
-               key.dptr = tdb_alloc_read(tdb, tl.off + sizeof(rec), 
-                                         rec.key_len + rec.data_len);
-               if (!key.dptr) {
-                       ret = -1;
-                       if (tdb_unlock(tdb, tl.hash, F_WRLCK) != 0)
-                               goto out;
-                       if (unlock_record(tdb, tl.off) != 0)
-                               TDB_LOG((tdb, 0, "tdb_traverse: key.dptr == NULL and unlock_record failed!\n"));
-                       goto out;
-               }
-               key.dsize = rec.key_len;
-               dbuf.dptr = key.dptr + rec.key_len;
-               dbuf.dsize = rec.data_len;
-
-               /* Drop chain lock, call out */
-               if (tdb_unlock(tdb, tl.hash, F_WRLCK) != 0) {
-                       ret = -1;
-                       goto out;
+       if (tdb_lock(tdb, -1, F_WRLCK) == -1) {
+               return -1;
+       }
+       
+       /* read in the hash top */
+       if (tdb_ofs_read(tdb, TDB_HASH_TOP(hash), &rec_ptr) == -1)
+               goto fail;
+
+       while (rec_ptr) {
+               tdb_off_t next;
+
+               if (tdb_rec_read(tdb, rec_ptr, &rec) == -1) {
+                       goto fail;
                }
-               if (fn && fn(tdb, key, dbuf, state)) {
-                       /* They want us to terminate traversal */
-                       ret = count;
-                       if (unlock_record(tdb, tl.off) != 0) {
-                               TDB_LOG((tdb, 0, "tdb_traverse: unlock_record failed!\n"));;
-                               ret = -1;
-                       }
-                       tdb->travlocks.next = tl.next;
-                       SAFE_FREE(key.dptr);
-                       return count;
+
+               next = rec.next;
+
+               if (rec.magic == TDB_DEAD_MAGIC
+                   && tdb_do_delete(tdb, rec_ptr, &rec) == -1) {
+                       goto fail;
                }
-               SAFE_FREE(key.dptr);
+               rec_ptr = next;
        }
-out:
-       tdb->travlocks.next = tl.next;
-       if (ret < 0)
-               return -1;
-       else
-               return count;
+       res = 0;
+ fail:
+       tdb_unlock(tdb, -1, F_WRLCK);
+       return res;
 }
 
-/* find the first entry in the database and return its key */
-TDB_DATA tdb_firstkey(TDB_CONTEXT *tdb)
+/* delete an entry in the database given a key */
+static int tdb_delete_hash(struct tdb_context *tdb, TDB_DATA key, uint32_t hash)
 {
-       TDB_DATA key;
-       struct list_struct rec;
+       tdb_off_t rec_ptr;
+       struct tdb_record rec;
+       int ret;
 
-       /* release any old lock */
-       if (unlock_record(tdb, tdb->travlocks.off) != 0)
-               return tdb_null;
-       tdb->travlocks.off = tdb->travlocks.hash = 0;
+       if (tdb->max_dead_records != 0) {
 
-       if (tdb_next_lock(tdb, &tdb->travlocks, &rec) <= 0)
-               return tdb_null;
-       /* now read the key */
-       key.dsize = rec.key_len;
-       key.dptr =tdb_alloc_read(tdb,tdb->travlocks.off+sizeof(rec),key.dsize);
-       if (tdb_unlock(tdb, BUCKET(tdb->travlocks.hash), F_WRLCK) != 0)
-               TDB_LOG((tdb, 0, "tdb_firstkey: error occurred while tdb_unlocking!\n"));
-       return key;
-}
+               /*
+                * Allow for some dead records per hash chain, mainly for
+                * tdb's with a very high create/delete rate like locking.tdb.
+                */
 
-/* find the next entry in the database, returning its key */
-TDB_DATA tdb_nextkey(TDB_CONTEXT *tdb, TDB_DATA oldkey)
-{
-       u32 oldhash;
-       TDB_DATA key = tdb_null;
-       struct list_struct rec;
-       char *k = NULL;
-
-       /* Is locked key the old key?  If so, traverse will be reliable. */
-       if (tdb->travlocks.off) {
-               if (tdb_lock(tdb,tdb->travlocks.hash,F_WRLCK))
-                       return tdb_null;
-               if (rec_read(tdb, tdb->travlocks.off, &rec) == -1
-                   || !(k = tdb_alloc_read(tdb,tdb->travlocks.off+sizeof(rec),
-                                           rec.key_len))
-                   || memcmp(k, oldkey.dptr, oldkey.dsize) != 0) {
-                       /* No, it wasn't: unlock it and start from scratch */
-                       if (unlock_record(tdb, tdb->travlocks.off) != 0)
-                               return tdb_null;
-                       if (tdb_unlock(tdb, tdb->travlocks.hash, F_WRLCK) != 0)
-                               return tdb_null;
-                       tdb->travlocks.off = 0;
+               if (tdb_lock(tdb, BUCKET(hash), F_WRLCK) == -1)
+                       return -1;
+
+               if (tdb_count_dead(tdb, hash) >= tdb->max_dead_records) {
+                       /*
+                        * Don't let the per-chain freelist grow too large,
+                        * delete all existing dead records
+                        */
+                       tdb_purge_dead(tdb, hash);
+               }
+
+               if (!(rec_ptr = tdb_find(tdb, key, hash, &rec))) {
+                       tdb_unlock(tdb, BUCKET(hash), F_WRLCK);
+                       return -1;
                }
 
-               SAFE_FREE(k);
+               /*
+                * Just mark the record as dead.
+                */
+               rec.magic = TDB_DEAD_MAGIC;
+               ret = tdb_rec_write(tdb, rec_ptr, &rec);
        }
+       else {
+               if (!(rec_ptr = tdb_find_lock_hash(tdb, key, hash, F_WRLCK,
+                                                  &rec)))
+                       return -1;
 
-       if (!tdb->travlocks.off) {
-               /* No previous element: do normal find, and lock record */
-               tdb->travlocks.off = tdb_find_lock(tdb, oldkey, F_WRLCK, &rec);
-               if (!tdb->travlocks.off)
-                       return tdb_null;
-               tdb->travlocks.hash = BUCKET(rec.full_hash);
-               if (lock_record(tdb, tdb->travlocks.off) != 0) {
-                       TDB_LOG((tdb, 0, "tdb_nextkey: lock_record failed (%s)!\n", strerror(errno)));
-                       return tdb_null;
-               }
+               ret = tdb_do_delete(tdb, rec_ptr, &rec);
        }
-       oldhash = tdb->travlocks.hash;
-
-       /* Grab next record: locks chain and returned record,
-          unlocks old record */
-       if (tdb_next_lock(tdb, &tdb->travlocks, &rec) > 0) {
-               key.dsize = rec.key_len;
-               key.dptr = tdb_alloc_read(tdb, tdb->travlocks.off+sizeof(rec),
-                                         key.dsize);
-               /* Unlock the chain of this new record */
-               if (tdb_unlock(tdb, tdb->travlocks.hash, F_WRLCK) != 0)
-                       TDB_LOG((tdb, 0, "tdb_nextkey: WARNING tdb_unlock failed!\n"));
+
+       if (ret == 0) {
+               tdb_increment_seqnum(tdb);
        }
-       /* Unlock the chain of old record */
-       if (tdb_unlock(tdb, BUCKET(oldhash), F_WRLCK) != 0)
-               TDB_LOG((tdb, 0, "tdb_nextkey: WARNING tdb_unlock failed!\n"));
-       return key;
+
+       if (tdb_unlock(tdb, BUCKET(rec.full_hash), F_WRLCK) != 0)
+               TDB_LOG((tdb, TDB_DEBUG_WARNING, "tdb_delete: WARNING tdb_unlock failed!\n"));
+       return ret;
 }
 
-/* delete an entry in the database given a key */
-int tdb_delete(TDB_CONTEXT *tdb, TDB_DATA key)
+int tdb_delete(struct tdb_context *tdb, TDB_DATA key)
 {
-       tdb_off rec_ptr;
-       struct list_struct rec;
+       uint32_t hash = tdb->hash_fn(&key);
        int ret;
 
-       if (!(rec_ptr = tdb_find_lock(tdb, key, F_WRLCK, &rec)))
-               return -1;
-       ret = do_delete(tdb, rec_ptr, &rec);
-       if (tdb_unlock(tdb, BUCKET(rec.full_hash), F_WRLCK) != 0)
-               TDB_LOG((tdb, 0, "tdb_delete: WARNING tdb_unlock failed!\n"));
+       ret = tdb_delete_hash(tdb, key, hash);
+       tdb_trace_1rec_ret(tdb, "tdb_delete", key, ret);
        return ret;
 }
 
-/* store an element in the database, replacing any existing element
-   with the same key 
+/*
+ * See if we have a dead record around with enough space
+ */
+static tdb_off_t tdb_find_dead(struct tdb_context *tdb, uint32_t hash,
+                              struct tdb_record *r, tdb_len_t length)
+{
+       tdb_off_t rec_ptr;
+       
+       /* read in the hash top */
+       if (tdb_ofs_read(tdb, TDB_HASH_TOP(hash), &rec_ptr) == -1)
+               return 0;
+
+       /* keep looking until we find the right record */
+       while (rec_ptr) {
+               if (tdb_rec_read(tdb, rec_ptr, r) == -1)
+                       return 0;
+
+               if (TDB_DEAD(r) && r->rec_len >= length) {
+                       /*
+                        * First fit for simple coding, TODO: change to best
+                        * fit
+                        */
+                       return rec_ptr;
+               }
+               rec_ptr = r->next;
+       }
+       return 0;
+}
 
-   return 0 on success, -1 on failure
-*/
-int tdb_store(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, int flag)
+static int _tdb_store(struct tdb_context *tdb, TDB_DATA key,
+                      TDB_DATA dbuf, int flag, uint32_t hash)
 {
-       struct list_struct rec;
-       u32 hash;
-       tdb_off rec_ptr;
+       struct tdb_record rec;
+       tdb_off_t rec_ptr;
        char *p = NULL;
-       int ret = 0;
-
-       /* find which hash bucket it is in */
-       hash = tdb_hash(&key);
-       if (!tdb_keylocked(tdb, hash))
-               return -1;
-       if (tdb_lock(tdb, BUCKET(hash), F_WRLCK) == -1)
-               return -1;
+       int ret = -1;
 
        /* check for it existing, on insert. */
        if (flag == TDB_INSERT) {
-               if (tdb_exists(tdb, key)) {
+               if (tdb_exists_hash(tdb, key, hash)) {
                        tdb->ecode = TDB_ERR_EXISTS;
                        goto fail;
                }
        } else {
                /* first try in-place update, on modify or replace. */
-               if (tdb_update(tdb, key, dbuf) == 0)
-                       goto out;
-               if (flag == TDB_MODIFY && tdb->ecode == TDB_ERR_NOEXIST)
+               if (tdb_update_hash(tdb, key, hash, dbuf) == 0) {
+                       goto done;
+               }
+               if (tdb->ecode == TDB_ERR_NOEXIST &&
+                   flag == TDB_MODIFY) {
+                       /* if the record doesn't exist and we are in TDB_MODIFY mode then
+                        we should fail the store */
                        goto fail;
+               }
        }
        /* reset the error code potentially set by the tdb_update() */
        tdb->ecode = TDB_SUCCESS;
@@ -1471,7 +498,7 @@ int tdb_store(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, int flag)
            care.  Doing this first reduces fragmentation, and avoids
            coalescing with `allocated' block before it's updated. */
        if (flag != TDB_INSERT)
-               tdb_delete(tdb, key);
+               tdb_delete_hash(tdb, key, hash);
 
        /* Copy key+value *before* allocating free space in case malloc
           fails and we are left with a dead spot in the tdb. */
@@ -1485,14 +512,59 @@ int tdb_store(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, int flag)
        if (dbuf.dsize)
                memcpy(p+key.dsize, dbuf.dptr, dbuf.dsize);
 
-       /* now we're into insert / modify / replace of a record which
-        * we know could not be optimised by an in-place store (for
-        * various reasons).  */
-       if (!(rec_ptr = tdb_allocate(tdb, key.dsize + dbuf.dsize, &rec)))
+       if (tdb->max_dead_records != 0) {
+               /*
+                * Allow for some dead records per hash chain, look if we can
+                * find one that can hold the new record. We need enough space
+                * for key, data and tailer. If we find one, we don't have to
+                * consult the central freelist.
+                */
+               rec_ptr = tdb_find_dead(
+                       tdb, hash, &rec,
+                       key.dsize + dbuf.dsize + sizeof(tdb_off_t));
+
+               if (rec_ptr != 0) {
+                       rec.key_len = key.dsize;
+                       rec.data_len = dbuf.dsize;
+                       rec.full_hash = hash;
+                       rec.magic = TDB_MAGIC;
+                       if (tdb_rec_write(tdb, rec_ptr, &rec) == -1
+                           || tdb->methods->tdb_write(
+                                   tdb, rec_ptr + sizeof(rec),
+                                   p, key.dsize + dbuf.dsize) == -1) {
+                               goto fail;
+                       }
+                       goto done;
+               }
+       }
+
+       /*
+        * We have to allocate some space from the freelist, so this means we
+        * have to lock it. Use the chance to purge all the DEAD records from
+        * the hash chain under the freelist lock.
+        */
+
+       if (tdb_lock(tdb, -1, F_WRLCK) == -1) {
+               goto fail;
+       }
+
+       if ((tdb->max_dead_records != 0)
+           && (tdb_purge_dead(tdb, hash) == -1)) {
+               tdb_unlock(tdb, -1, F_WRLCK);
+               goto fail;
+       }
+
+       /* we have to allocate some space */
+       rec_ptr = tdb_allocate(tdb, key.dsize + dbuf.dsize, &rec);
+
+       tdb_unlock(tdb, -1, F_WRLCK);
+
+       if (rec_ptr == 0) {
                goto fail;
+       }
 
        /* Read hash top into next ptr */
-       if (ofs_read(tdb, TDB_HASH_TOP(hash), &rec.next) == -1)
+       if (tdb_ofs_read(tdb, TDB_HASH_TOP(hash), &rec.next) == -1)
                goto fail;
 
        rec.key_len = key.dsize;
@@ -1501,547 +573,568 @@ int tdb_store(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, int flag)
        rec.magic = TDB_MAGIC;
 
        /* write out and point the top of the hash chain at it */
-       if (rec_write(tdb, rec_ptr, &rec) == -1
-           || tdb_write(tdb, rec_ptr+sizeof(rec), p, key.dsize+dbuf.dsize)==-1
-           || ofs_write(tdb, TDB_HASH_TOP(hash), &rec_ptr) == -1) {
+       if (tdb_rec_write(tdb, rec_ptr, &rec) == -1
+           || tdb->methods->tdb_write(tdb, rec_ptr+sizeof(rec), p, key.dsize+dbuf.dsize)==-1
+           || tdb_ofs_write(tdb, TDB_HASH_TOP(hash), &rec_ptr) == -1) {
                /* Need to tdb_unallocate() here */
                goto fail;
        }
- out:
+
+ done:
+       ret = 0;
+ fail:
+       if (ret == 0) {
+               tdb_increment_seqnum(tdb);
+       }
+
        SAFE_FREE(p); 
-       tdb_unlock(tdb, BUCKET(hash), F_WRLCK);
        return ret;
-fail:
-       ret = -1;
-       goto out;
 }
 
-/* Attempt to append data to an entry in place - this only works if the new data size
-   is <= the old data size and the key exists.
-   on failure return -1. Record must be locked before calling.
+/* store an element in the database, replacing any existing element
+   with the same key
+
+   return 0 on success, -1 on failure
 */
-static int tdb_append_inplace(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA new_dbuf)
+int tdb_store(struct tdb_context *tdb, TDB_DATA key, TDB_DATA dbuf, int flag)
 {
-       struct list_struct rec;
-       tdb_off rec_ptr;
-
-       /* find entry */
-       if (!(rec_ptr = tdb_find(tdb, key, tdb_hash(&key), &rec)))
-               return -1;
-
-       /* Append of 0 is always ok. */
-       if (new_dbuf.dsize == 0)
-               return 0;
+       uint32_t hash;
+       int ret;
 
-       /* must be long enough for key, old data + new data and tailer */
-       if (rec.rec_len < key.dsize + rec.data_len + new_dbuf.dsize + sizeof(tdb_off)) {
-               /* No room. */
-               tdb->ecode = TDB_SUCCESS; /* Not really an error */
+       if (tdb->read_only || tdb->traverse_read) {
+               tdb->ecode = TDB_ERR_RDONLY;
+               tdb_trace_2rec_flag_ret(tdb, "tdb_store", key, dbuf, flag, -1);
                return -1;
        }
 
-       if (tdb_write(tdb, rec_ptr + sizeof(rec) + rec.key_len + rec.data_len,
-                     new_dbuf.dptr, new_dbuf.dsize) == -1)
+       /* find which hash bucket it is in */
+       hash = tdb->hash_fn(&key);
+       if (tdb_lock(tdb, BUCKET(hash), F_WRLCK) == -1)
                return -1;
 
-       /* update size */
-       rec.data_len += new_dbuf.dsize;
-       return rec_write(tdb, rec_ptr, &rec);
+       ret = _tdb_store(tdb, key, dbuf, flag, hash);
+       tdb_trace_2rec_flag_ret(tdb, "tdb_store", key, dbuf, flag, ret);
+       tdb_unlock(tdb, BUCKET(hash), F_WRLCK);
+       return ret;
 }
 
 /* Append to an entry. Create if not exist. */
-
-int tdb_append(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA new_dbuf)
+int tdb_append(struct tdb_context *tdb, TDB_DATA key, TDB_DATA new_dbuf)
 {
-       struct list_struct rec;
-       u32 hash;
-       tdb_off rec_ptr;
-       char *p = NULL;
-       int ret = 0;
-       size_t new_data_size = 0;
+       uint32_t hash;
+       TDB_DATA dbuf;
+       int ret = -1;
 
        /* find which hash bucket it is in */
-       hash = tdb_hash(&key);
-       if (!tdb_keylocked(tdb, hash))
-               return -1;
+       hash = tdb->hash_fn(&key);
        if (tdb_lock(tdb, BUCKET(hash), F_WRLCK) == -1)
                return -1;
 
-       /* first try in-place. */
-       if (tdb_append_inplace(tdb, key, new_dbuf) == 0)
-               goto out;
-
-       /* reset the error code potentially set by the tdb_append_inplace() */
-       tdb->ecode = TDB_SUCCESS;
-
-       /* find entry */
-       if (!(rec_ptr = tdb_find(tdb, key, hash, &rec))) {
-               if (tdb->ecode != TDB_ERR_NOEXIST)
-                       goto fail;
+       dbuf = _tdb_fetch(tdb, key);
 
-               /* Not found - create. */
-
-               ret = tdb_store(tdb, key, new_dbuf, TDB_INSERT);
-               goto out;
+       if (dbuf.dptr == NULL) {
+               dbuf.dptr = (unsigned char *)malloc(new_dbuf.dsize);
+       } else {
+               unsigned int new_len = dbuf.dsize + new_dbuf.dsize;
+               unsigned char *new_dptr;
+
+               /* realloc '0' is special: don't do that. */
+               if (new_len == 0)
+                       new_len = 1;
+               new_dptr = (unsigned char *)realloc(dbuf.dptr, new_len);
+               if (new_dptr == NULL) {
+                       free(dbuf.dptr);
+               }
+               dbuf.dptr = new_dptr;
        }
 
-       new_data_size = rec.data_len + new_dbuf.dsize;
-
-       /* Copy key+old_value+value *before* allocating free space in case malloc
-          fails and we are left with a dead spot in the tdb. */
-
-       if (!(p = (char *)malloc(key.dsize + new_data_size))) {
+       if (dbuf.dptr == NULL) {
                tdb->ecode = TDB_ERR_OOM;
-               goto fail;
+               goto failed;
        }
 
-       /* Copy the key in place. */
-       memcpy(p, key.dptr, key.dsize);
+       memcpy(dbuf.dptr + dbuf.dsize, new_dbuf.dptr, new_dbuf.dsize);
+       dbuf.dsize += new_dbuf.dsize;
 
-       /* Now read the old data into place. */
-       if (rec.data_len &&
-               tdb_read(tdb, rec_ptr + sizeof(rec) + rec.key_len, p + key.dsize, rec.data_len, 0) == -1)
-                       goto fail;
+       ret = _tdb_store(tdb, key, dbuf, 0, hash);
+       tdb_trace_2rec_retrec(tdb, "tdb_append", key, new_dbuf, dbuf);
+       
+failed:
+       tdb_unlock(tdb, BUCKET(hash), F_WRLCK);
+       SAFE_FREE(dbuf.dptr);
+       return ret;
+}
 
-       /* Finally append the new data. */
-       if (new_dbuf.dsize)
-               memcpy(p+key.dsize+rec.data_len, new_dbuf.dptr, new_dbuf.dsize);
 
-       /* delete any existing record - if it doesn't exist we don't
-           care.  Doing this first reduces fragmentation, and avoids
-           coalescing with `allocated' block before it's updated. */
+/*
+  return the name of the current tdb file
+  useful for external logging functions
+*/
+const char *tdb_name(struct tdb_context *tdb)
+{
+       return tdb->name;
+}
 
-       tdb_delete(tdb, key);
+/*
+  return the underlying file descriptor being used by tdb, or -1
+  useful for external routines that want to check the device/inode
+  of the fd
+*/
+int tdb_fd(struct tdb_context *tdb)
+{
+       return tdb->fd;
+}
 
-       if (!(rec_ptr = tdb_allocate(tdb, key.dsize + new_data_size, &rec)))
-               goto fail;
+/*
+  return the current logging function
+  useful for external tdb routines that wish to log tdb errors
+*/
+tdb_log_func tdb_log_fn(struct tdb_context *tdb)
+{
+       return tdb->log.log_fn;
+}
 
-       /* Read hash top into next ptr */
-       if (ofs_read(tdb, TDB_HASH_TOP(hash), &rec.next) == -1)
-               goto fail;
 
-       rec.key_len = key.dsize;
-       rec.data_len = new_data_size;
-       rec.full_hash = hash;
-       rec.magic = TDB_MAGIC;
+/*
+  get the tdb sequence number. Only makes sense if the writers opened
+  with TDB_SEQNUM set. Note that this sequence number will wrap quite
+  quickly, so it should only be used for a 'has something changed'
+  test, not for code that relies on the count of the number of changes
+  made. If you want a counter then use a tdb record.
+
+  The aim of this sequence number is to allow for a very lightweight
+  test of a possible tdb change.
+*/
+int tdb_get_seqnum(struct tdb_context *tdb)
+{
+       tdb_off_t seqnum=0;
 
-       /* write out and point the top of the hash chain at it */
-       if (rec_write(tdb, rec_ptr, &rec) == -1
-           || tdb_write(tdb, rec_ptr+sizeof(rec), p, key.dsize+new_data_size)==-1
-           || ofs_write(tdb, TDB_HASH_TOP(hash), &rec_ptr) == -1) {
-               /* Need to tdb_unallocate() here */
-               goto fail;
-       }
+       tdb_ofs_read(tdb, TDB_SEQNUM_OFS, &seqnum);
+       return seqnum;
+}
 
- out:
-       SAFE_FREE(p); 
-       tdb_unlock(tdb, BUCKET(hash), F_WRLCK);
-       return ret;
+int tdb_hash_size(struct tdb_context *tdb)
+{
+       return tdb->header.hash_size;
+}
 
-fail:
-       ret = -1;
-       goto out;
+size_t tdb_map_size(struct tdb_context *tdb)
+{
+       return tdb->map_size;
 }
 
-static int tdb_already_open(dev_t device,
-                           ino_t ino)
+int tdb_get_flags(struct tdb_context *tdb)
 {
-       TDB_CONTEXT *i;
-       
-       for (i = tdbs; i; i = i->next) {
-               if (i->device == device && i->inode == ino) {
-                       return 1;
-               }
+       return tdb->flags;
+}
+
+void tdb_add_flags(struct tdb_context *tdb, unsigned flags)
+{
+       if ((flags & TDB_ALLOW_NESTING) &&
+           (flags & TDB_DISALLOW_NESTING)) {
+               tdb->ecode = TDB_ERR_NESTING;
+               TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_add_flags: "
+                       "allow_nesting and disallow_nesting are not allowed together!"));
+               return;
        }
 
-       return 0;
+       if (flags & TDB_ALLOW_NESTING) {
+               tdb->flags &= ~TDB_DISALLOW_NESTING;
+       }
+       if (flags & TDB_DISALLOW_NESTING) {
+               tdb->flags &= ~TDB_ALLOW_NESTING;
+       }
+
+       tdb->flags |= flags;
 }
 
-/* open the database, creating it if necessary 
+void tdb_remove_flags(struct tdb_context *tdb, unsigned flags)
+{
+       if ((flags & TDB_ALLOW_NESTING) &&
+           (flags & TDB_DISALLOW_NESTING)) {
+               tdb->ecode = TDB_ERR_NESTING;
+               TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_remove_flags: "
+                       "allow_nesting and disallow_nesting are not allowed together!"));
+               return;
+       }
+
+       if (flags & TDB_ALLOW_NESTING) {
+               tdb->flags |= TDB_DISALLOW_NESTING;
+       }
+       if (flags & TDB_DISALLOW_NESTING) {
+               tdb->flags |= TDB_ALLOW_NESTING;
+       }
 
-   The open_flags and mode are passed straight to the open call on the
-   database file. A flags value of O_WRONLY is invalid. The hash size
-   is advisory, use zero for a default value.
+       tdb->flags &= ~flags;
+}
 
-   Return is NULL on error, in which case errno is also set.  Don't 
-   try to call tdb_error or tdb_errname, just do strerror(errno).
 
-   @param name may be NULL for internal databases. */
-TDB_CONTEXT *tdb_open(const char *name, int hash_size, int tdb_flags,
-                     int open_flags, mode_t mode)
+/*
+  enable sequence number handling on an open tdb
+*/
+void tdb_enable_seqnum(struct tdb_context *tdb)
 {
-       return tdb_open_ex(name, hash_size, tdb_flags, open_flags, mode, NULL);
+       tdb->flags |= TDB_SEQNUM;
 }
 
 
-TDB_CONTEXT *tdb_open_ex(const char *name, int hash_size, int tdb_flags,
-                        int open_flags, mode_t mode,
-                        tdb_log_func log_fn)
+/*
+  add a region of the file to the freelist. Length is the size of the region in bytes, 
+  which includes the free list header that needs to be added
+ */
+static int tdb_free_region(struct tdb_context *tdb, tdb_off_t offset, ssize_t length)
 {
-       TDB_CONTEXT *tdb;
-       struct stat st;
-       int rev = 0, locked;
-       unsigned char *vp;
-       u32 vertest;
-
-       if (!(tdb = calloc(1, sizeof *tdb))) {
-               /* Can't log this */
-               errno = ENOMEM;
-               goto fail;
+       struct tdb_record rec;
+       if (length <= sizeof(rec)) {
+               /* the region is not worth adding */
+               return 0;
        }
-       tdb->fd = -1;
-       tdb->name = NULL;
-       tdb->map_ptr = NULL;
-       tdb->lockedkeys = NULL;
-       tdb->flags = tdb_flags;
-       tdb->open_flags = open_flags;
-       tdb->log_fn = log_fn;
-       
-       if ((open_flags & O_ACCMODE) == O_WRONLY) {
-               TDB_LOG((tdb, 0, "tdb_open_ex: can't open tdb %s write-only\n",
-                        name));
-               errno = EINVAL;
-               goto fail;
+       if (length + offset > tdb->map_size) {
+               TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_free_region: adding region beyond end of file\n"));
+               return -1;              
        }
-       
-       if (hash_size == 0)
-               hash_size = DEFAULT_HASH_SIZE;
-       if ((open_flags & O_ACCMODE) == O_RDONLY) {
-               tdb->read_only = 1;
-               /* read only databases don't do locking or clear if first */
-               tdb->flags |= TDB_NOLOCK;
-               tdb->flags &= ~TDB_CLEAR_IF_FIRST;
+       memset(&rec,'\0',sizeof(rec));
+       rec.rec_len = length - sizeof(rec);
+       if (tdb_free(tdb, offset, &rec) == -1) {
+               TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_free_region: failed to add free record\n"));
+               return -1;
        }
+       return 0;
+}
 
-       /* internal databases don't mmap or lock, and start off cleared */
-       if (tdb->flags & TDB_INTERNAL) {
-               tdb->flags |= (TDB_NOLOCK | TDB_NOMMAP);
-               tdb->flags &= ~TDB_CLEAR_IF_FIRST;
-               if (tdb_new_database(tdb, hash_size) != 0) {
-                       TDB_LOG((tdb, 0, "tdb_open_ex: tdb_new_database failed!"));
-                       goto fail;
-               }
-               goto internal;
+/*
+  wipe the entire database, deleting all records. This can be done
+  very fast by using a global lock. The entire data portion of the
+  file becomes a single entry in the freelist.
+
+  This code carefully steps around the recovery area, leaving it alone
+ */
+int tdb_wipe_all(struct tdb_context *tdb)
+{
+       int i;
+       tdb_off_t offset = 0;
+       ssize_t data_len;
+       tdb_off_t recovery_head;
+       tdb_len_t recovery_size = 0;
+
+       if (tdb_lockall(tdb) != 0) {
+               return -1;
        }
 
-       if ((tdb->fd = open(name, open_flags, mode)) == -1) {
-               TDB_LOG((tdb, 5, "tdb_open_ex: could not open file %s: %s\n",
-                        name, strerror(errno)));
-               goto fail;      /* errno set by open(2) */
+       tdb_trace(tdb, "tdb_wipe_all");
+
+       /* see if the tdb has a recovery area, and remember its size
+          if so. We don't want to lose this as otherwise each
+          tdb_wipe_all() in a transaction will increase the size of
+          the tdb by the size of the recovery area */
+       if (tdb_ofs_read(tdb, TDB_RECOVERY_HEAD, &recovery_head) == -1) {
+               TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_wipe_all: failed to read recovery head\n"));
+               goto failed;
        }
 
-       /* ensure there is only one process initialising at once */
-       if (tdb_brlock(tdb, GLOBAL_LOCK, F_WRLCK, F_SETLKW, 0) == -1) {
-               TDB_LOG((tdb, 0, "tdb_open_ex: failed to get global lock on %s: %s\n",
-                        name, strerror(errno)));
-               goto fail;      /* errno set by tdb_brlock */
+       if (recovery_head != 0) {
+               struct tdb_record rec;
+               if (tdb->methods->tdb_read(tdb, recovery_head, &rec, sizeof(rec), DOCONV()) == -1) {
+                       TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_wipe_all: failed to read recovery record\n"));
+                       return -1;
+               }       
+               recovery_size = rec.rec_len + sizeof(rec);
        }
 
-       /* we need to zero database if we are the only one with it open */
-       if ((locked = (tdb_brlock(tdb, ACTIVE_LOCK, F_WRLCK, F_SETLK, 0) == 0))
-           && (tdb_flags & TDB_CLEAR_IF_FIRST)) {
-               open_flags |= O_CREAT;
-               if (ftruncate(tdb->fd, 0) == -1) {
-                       TDB_LOG((tdb, 0, "tdb_open_ex: "
-                                "failed to truncate %s: %s\n",
-                                name, strerror(errno)));
-                       goto fail; /* errno set by ftruncate */
+       /* wipe the hashes */
+       for (i=0;i<tdb->header.hash_size;i++) {
+               if (tdb_ofs_write(tdb, TDB_HASH_TOP(i), &offset) == -1) {
+                       TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_wipe_all: failed to write hash %d\n", i));
+                       goto failed;
                }
        }
 
-       if (read(tdb->fd, &tdb->header, sizeof(tdb->header)) != sizeof(tdb->header)
-           || strcmp(tdb->header.magic_food, TDB_MAGIC_FOOD) != 0
-           || (tdb->header.version != TDB_VERSION
-               && !(rev = (tdb->header.version==TDB_BYTEREV(TDB_VERSION))))) {
-               /* its not a valid database - possibly initialise it */
-               if (!(open_flags & O_CREAT) || tdb_new_database(tdb, hash_size) == -1) {
-                       errno = EIO; /* ie bad format or something */
-                       goto fail;
-               }
-               rev = (tdb->flags & TDB_CONVERT);
+       /* wipe the freelist */
+       if (tdb_ofs_write(tdb, FREELIST_TOP, &offset) == -1) {
+               TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_wipe_all: failed to write freelist\n"));
+               goto failed;
        }
-       vp = (unsigned char *)&tdb->header.version;
-       vertest = (((u32)vp[0]) << 24) | (((u32)vp[1]) << 16) |
-                 (((u32)vp[2]) << 8) | (u32)vp[3];
-       tdb->flags |= (vertest==TDB_VERSION) ? TDB_BIGENDIAN : 0;
-       if (!rev)
-               tdb->flags &= ~TDB_CONVERT;
-       else {
-               tdb->flags |= TDB_CONVERT;
-               convert(&tdb->header, sizeof(tdb->header));
+
+       /* add all the rest of the file to the freelist, possibly leaving a gap 
+          for the recovery area */
+       if (recovery_size == 0) {
+               /* the simple case - the whole file can be used as a freelist */
+               data_len = (tdb->map_size - TDB_DATA_START(tdb->header.hash_size));
+               if (tdb_free_region(tdb, TDB_DATA_START(tdb->header.hash_size), data_len) != 0) {
+                       goto failed;
+               }
+       } else {
+               /* we need to add two freelist entries - one on either
+                  side of the recovery area 
+
+                  Note that we cannot shift the recovery area during
+                  this operation. Only the transaction.c code may
+                  move the recovery area or we risk subtle data
+                  corruption
+               */
+               data_len = (recovery_head - TDB_DATA_START(tdb->header.hash_size));
+               if (tdb_free_region(tdb, TDB_DATA_START(tdb->header.hash_size), data_len) != 0) {
+                       goto failed;
+               }
+               /* and the 2nd free list entry after the recovery area - if any */
+               data_len = tdb->map_size - (recovery_head+recovery_size);
+               if (tdb_free_region(tdb, recovery_head+recovery_size, data_len) != 0) {
+                       goto failed;
+               }
        }
-       if (fstat(tdb->fd, &st) == -1)
-               goto fail;
 
-       /* Is it already in the open list?  If so, fail. */
-       if (tdb_already_open(st.st_dev, st.st_ino)) {
-               TDB_LOG((tdb, 2, "tdb_open_ex: "
-                        "%s (%d,%d) is already open in this process\n",
-                        name, st.st_dev, st.st_ino));
-               errno = EBUSY;
-               goto fail;
+       if (tdb_unlockall(tdb) != 0) {
+               TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_wipe_all: failed to unlock\n"));
+               goto failed;
        }
 
-       if (!(tdb->name = (char *)strdup(name))) {
-               errno = ENOMEM;
-               goto fail;
+       return 0;
+
+failed:
+       tdb_unlockall(tdb);
+       return -1;
+}
+
+struct traverse_state {
+       bool error;
+       struct tdb_context *dest_db;
+};
+
+/*
+  traverse function for repacking
+ */
+static int repack_traverse(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *private_data)
+{
+       struct traverse_state *state = (struct traverse_state *)private_data;
+       if (tdb_store(state->dest_db, key, data, TDB_INSERT) != 0) {
+               state->error = true;
+               return -1;
        }
+       return 0;
+}
 
-       tdb->map_size = st.st_size;
-       tdb->device = st.st_dev;
-       tdb->inode = st.st_ino;
-       tdb->locked = calloc(tdb->header.hash_size+1, sizeof(tdb->locked[0]));
-       if (!tdb->locked) {
-               TDB_LOG((tdb, 2, "tdb_open_ex: "
-                        "failed to allocate lock structure for %s\n",
-                        name));
-               errno = ENOMEM;
-               goto fail;
+/*
+  repack a tdb
+ */
+int tdb_repack(struct tdb_context *tdb)
+{
+       struct tdb_context *tmp_db;
+       struct traverse_state state;
+
+       tdb_trace(tdb, "tdb_repack");
+
+       if (tdb_transaction_start(tdb) != 0) {
+               TDB_LOG((tdb, TDB_DEBUG_FATAL, __location__ " Failed to start transaction\n"));
+               return -1;
        }
-       tdb_mmap(tdb);
-       if (locked) {
-               if (!tdb->read_only)
-                       if (tdb_clear_spinlocks(tdb) != 0) {
-                               TDB_LOG((tdb, 0, "tdb_open_ex: "
-                               "failed to clear spinlock\n"));
-                               goto fail;
-                       }
-               if (tdb_brlock(tdb, ACTIVE_LOCK, F_UNLCK, F_SETLK, 0) == -1) {
-                       TDB_LOG((tdb, 0, "tdb_open_ex: "
-                                "failed to take ACTIVE_LOCK on %s: %s\n",
-                                name, strerror(errno)));
-                       goto fail;
-               }
+
+       tmp_db = tdb_open("tmpdb", tdb_hash_size(tdb), TDB_INTERNAL, O_RDWR|O_CREAT, 0);
+       if (tmp_db == NULL) {
+               TDB_LOG((tdb, TDB_DEBUG_FATAL, __location__ " Failed to create tmp_db\n"));
+               tdb_transaction_cancel(tdb);
+               return -1;
        }
-       /* leave this lock in place to indicate it's in use */
-       if (tdb_brlock(tdb, ACTIVE_LOCK, F_RDLCK, F_SETLKW, 0) == -1)
-               goto fail;
 
- internal:
-       /* Internal (memory-only) databases skip all the code above to
-        * do with disk files, and resume here by releasing their
-        * global lock and hooking into the active list. */
-       if (tdb_brlock(tdb, GLOBAL_LOCK, F_UNLCK, F_SETLKW, 0) == -1)
-               goto fail;
-       tdb->next = tdbs;
-       tdbs = tdb;
-       return tdb;
+       state.error = false;
+       state.dest_db = tmp_db;
 
- fail:
-       { int save_errno = errno;
+       if (tdb_traverse_read(tdb, repack_traverse, &state) == -1) {
+               TDB_LOG((tdb, TDB_DEBUG_FATAL, __location__ " Failed to traverse copying out\n"));
+               tdb_transaction_cancel(tdb);
+               tdb_close(tmp_db);
+               return -1;              
+       }
 
-       if (!tdb)
-               return NULL;
-       
-       if (tdb->map_ptr) {
-               if (tdb->flags & TDB_INTERNAL)
-                       SAFE_FREE(tdb->map_ptr);
-               else
-                       tdb_munmap(tdb);
+       if (state.error) {
+               TDB_LOG((tdb, TDB_DEBUG_FATAL, __location__ " Error during traversal\n"));
+               tdb_transaction_cancel(tdb);
+               tdb_close(tmp_db);
+               return -1;
        }
-       SAFE_FREE(tdb->name);
-       if (tdb->fd != -1)
-               if (close(tdb->fd) != 0)
-                       TDB_LOG((tdb, 5, "tdb_open_ex: failed to close tdb->fd on error!\n"));
-       SAFE_FREE(tdb->locked);
-       SAFE_FREE(tdb);
-       errno = save_errno;
-       return NULL;
+
+       if (tdb_wipe_all(tdb) != 0) {
+               TDB_LOG((tdb, TDB_DEBUG_FATAL, __location__ " Failed to wipe database\n"));
+               tdb_transaction_cancel(tdb);
+               tdb_close(tmp_db);
+               return -1;
        }
-}
 
-/**
- * Close a database.
- *
- * @returns -1 for error; 0 for success.
- **/
-int tdb_close(TDB_CONTEXT *tdb)
-{
-       TDB_CONTEXT **i;
-       int ret = 0;
-
-       if (tdb->map_ptr) {
-               if (tdb->flags & TDB_INTERNAL)
-                       SAFE_FREE(tdb->map_ptr);
-               else
-                       tdb_munmap(tdb);
+       state.error = false;
+       state.dest_db = tdb;
+
+       if (tdb_traverse_read(tmp_db, repack_traverse, &state) == -1) {
+               TDB_LOG((tdb, TDB_DEBUG_FATAL, __location__ " Failed to traverse copying back\n"));
+               tdb_transaction_cancel(tdb);
+               tdb_close(tmp_db);
+               return -1;              
        }
-       SAFE_FREE(tdb->name);
-       if (tdb->fd != -1)
-               ret = close(tdb->fd);
-       SAFE_FREE(tdb->locked);
-       SAFE_FREE(tdb->lockedkeys);
-
-       /* Remove from contexts list */
-       for (i = &tdbs; *i; i = &(*i)->next) {
-               if (*i == tdb) {
-                       *i = tdb->next;
-                       break;
-               }
+
+       if (state.error) {
+               TDB_LOG((tdb, TDB_DEBUG_FATAL, __location__ " Error during second traversal\n"));
+               tdb_transaction_cancel(tdb);
+               tdb_close(tmp_db);
+               return -1;
        }
 
-       memset(tdb, 0, sizeof(*tdb));
-       SAFE_FREE(tdb);
+       tdb_close(tmp_db);
 
-       return ret;
+       if (tdb_transaction_commit(tdb) != 0) {
+               TDB_LOG((tdb, TDB_DEBUG_FATAL, __location__ " Failed to commit\n"));
+               return -1;
+       }
+
+       return 0;
 }
 
-/* lock/unlock entire database */
-int tdb_lockall(TDB_CONTEXT *tdb)
+#ifdef TDB_TRACE
+static void tdb_trace_write(struct tdb_context *tdb, const char *str)
 {
-       u32 i;
-
-       /* There are no locks on read-only dbs */
-       if (tdb->read_only)
-               return TDB_ERRCODE(TDB_ERR_LOCK, -1);
-       if (tdb->lockedkeys)
-               return TDB_ERRCODE(TDB_ERR_NOLOCK, -1);
-       for (i = 0; i < tdb->header.hash_size; i++) 
-               if (tdb_lock(tdb, i, F_WRLCK))
-                       break;
-
-       /* If error, release locks we have... */
-       if (i < tdb->header.hash_size) {
-               u32 j;
-
-               for ( j = 0; j < i; j++)
-                       tdb_unlock(tdb, j, F_WRLCK);
-               return TDB_ERRCODE(TDB_ERR_NOLOCK, -1);
+       if (write(tdb->tracefd, str, strlen(str)) != strlen(str)) {
+               close(tdb->tracefd);
+               tdb->tracefd = -1;
        }
+}
 
-       return 0;
+static void tdb_trace_start(struct tdb_context *tdb)
+{
+       tdb_off_t seqnum=0;
+       char msg[sizeof(tdb_off_t) * 4 + 1];
+
+       tdb_ofs_read(tdb, TDB_SEQNUM_OFS, &seqnum);
+       snprintf(msg, sizeof(msg), "%u ", seqnum);
+       tdb_trace_write(tdb, msg);
 }
-void tdb_unlockall(TDB_CONTEXT *tdb)
+
+static void tdb_trace_end(struct tdb_context *tdb)
 {
-       u32 i;
-       for (i=0; i < tdb->header.hash_size; i++)
-               tdb_unlock(tdb, i, F_WRLCK);
+       tdb_trace_write(tdb, "\n");
 }
 
-int tdb_lockkeys(TDB_CONTEXT *tdb, u32 number, TDB_DATA keys[])
+static void tdb_trace_end_ret(struct tdb_context *tdb, int ret)
 {
-       u32 i, j, hash;
-
-       /* Can't lock more keys if already locked */
-       if (tdb->lockedkeys)
-               return TDB_ERRCODE(TDB_ERR_NOLOCK, -1);
-       if (!(tdb->lockedkeys = malloc(sizeof(u32) * (number+1))))
-               return TDB_ERRCODE(TDB_ERR_OOM, -1);
-       /* First number in array is # keys */
-       tdb->lockedkeys[0] = number;
-
-       /* Insertion sort by bucket */
-       for (i = 0; i < number; i++) {
-               hash = tdb_hash(&keys[i]);
-               for (j = 0; j < i && BUCKET(tdb->lockedkeys[j+1]) < BUCKET(hash); j++);
-                       memmove(&tdb->lockedkeys[j+2], &tdb->lockedkeys[j+1], sizeof(u32) * (i-j));
-               tdb->lockedkeys[j+1] = hash;
-       }
-       /* Finally, lock in order */
-       for (i = 0; i < number; i++)
-               if (tdb_lock(tdb, i, F_WRLCK))
-                       break;
-
-       /* If error, release locks we have... */
-       if (i < number) {
-               for ( j = 0; j < i; j++)
-                       tdb_unlock(tdb, j, F_WRLCK);
-               SAFE_FREE(tdb->lockedkeys);
-               return TDB_ERRCODE(TDB_ERR_NOLOCK, -1);
-       }
-       return 0;
+       char msg[sizeof(ret) * 4 + 4];
+       snprintf(msg, sizeof(msg), " = %i\n", ret);
+       tdb_trace_write(tdb, msg);
 }
 
-/* Unlock the keys previously locked by tdb_lockkeys() */
-void tdb_unlockkeys(TDB_CONTEXT *tdb)
+static void tdb_trace_record(struct tdb_context *tdb, TDB_DATA rec)
 {
-       u32 i;
-       if (!tdb->lockedkeys)
+       char msg[20 + rec.dsize*2], *p;
+       unsigned int i;
+
+       /* We differentiate zero-length records from non-existent ones. */
+       if (rec.dptr == NULL) {
+               tdb_trace_write(tdb, " NULL");
                return;
-       for (i = 0; i < tdb->lockedkeys[0]; i++)
-               tdb_unlock(tdb, tdb->lockedkeys[i+1], F_WRLCK);
-       SAFE_FREE(tdb->lockedkeys);
+       }
+
+       /* snprintf here is purely cargo-cult programming. */
+       p = msg;
+       p += snprintf(p, sizeof(msg), " %zu:", rec.dsize);
+       for (i = 0; i < rec.dsize; i++)
+               p += snprintf(p, 2, "%02x", rec.dptr[i]);
+
+       tdb_trace_write(tdb, msg);
 }
 
-/* lock/unlock one hash chain. This is meant to be used to reduce
-   contention - it cannot guarantee how many records will be locked */
-int tdb_chainlock(TDB_CONTEXT *tdb, TDB_DATA key)
+void tdb_trace(struct tdb_context *tdb, const char *op)
 {
-       return tdb_lock(tdb, BUCKET(tdb_hash(&key)), F_WRLCK);
+       tdb_trace_start(tdb);
+       tdb_trace_write(tdb, op);
+       tdb_trace_end(tdb);
 }
 
-int tdb_chainunlock(TDB_CONTEXT *tdb, TDB_DATA key)
+void tdb_trace_seqnum(struct tdb_context *tdb, uint32_t seqnum, const char *op)
 {
-       return tdb_unlock(tdb, BUCKET(tdb_hash(&key)), F_WRLCK);
+       char msg[sizeof(tdb_off_t) * 4 + 1];
+
+       snprintf(msg, sizeof(msg), "%u ", seqnum);
+       tdb_trace_write(tdb, msg);
+       tdb_trace_write(tdb, op);
+       tdb_trace_end(tdb);
 }
 
-#if 0
-static int tdb_chainlock_read(TDB_CONTEXT *tdb, TDB_DATA key)
+void tdb_trace_open(struct tdb_context *tdb, const char *op,
+                   unsigned hash_size, unsigned tdb_flags, unsigned open_flags)
 {
-       return tdb_lock(tdb, BUCKET(tdb_hash(&key)), F_RDLCK);
+       char msg[128];
+
+       snprintf(msg, sizeof(msg),
+                "%s %u 0x%x 0x%x", op, hash_size, tdb_flags, open_flags);
+       tdb_trace_start(tdb);
+       tdb_trace_write(tdb, msg);
+       tdb_trace_end(tdb);
 }
-#endif
 
-#if 0
-static int tdb_chainunlock_read(TDB_CONTEXT *tdb, TDB_DATA key)
+void tdb_trace_ret(struct tdb_context *tdb, const char *op, int ret)
 {
-       return tdb_unlock(tdb, BUCKET(tdb_hash(&key)), F_RDLCK);
+       tdb_trace_start(tdb);
+       tdb_trace_write(tdb, op);
+       tdb_trace_end_ret(tdb, ret);
 }
-#endif
 
-/* register a loging function */
-void tdb_logging_function(TDB_CONTEXT *tdb, void (*fn)(TDB_CONTEXT *, int , const char *, ...))
+void tdb_trace_retrec(struct tdb_context *tdb, const char *op, TDB_DATA ret)
 {
-       tdb->log_fn = fn;
+       tdb_trace_start(tdb);
+       tdb_trace_write(tdb, op);
+       tdb_trace_write(tdb, " =");
+       tdb_trace_record(tdb, ret);
+       tdb_trace_end(tdb);
 }
 
-
-/* reopen a tdb - this is used after a fork to ensure that we have an independent
-   seek pointer from our parent and to re-establish locks */
-int tdb_reopen(TDB_CONTEXT *tdb)
+void tdb_trace_1rec(struct tdb_context *tdb, const char *op,
+                   TDB_DATA rec)
 {
-       struct stat st;
-
-       if (tdb_munmap(tdb) != 0) {
-               TDB_LOG((tdb, 0, "tdb_reopen: munmap failed (%s)\n", strerror(errno)));
-               goto fail;
-       }
-       if (close(tdb->fd) != 0)
-               TDB_LOG((tdb, 0, "tdb_reopen: WARNING closing tdb->fd failed!\n"));
-       tdb->fd = open(tdb->name, tdb->open_flags & ~(O_CREAT|O_TRUNC), 0);
-       if (tdb->fd == -1) {
-               TDB_LOG((tdb, 0, "tdb_reopen: open failed (%s)\n", strerror(errno)));
-               goto fail;
-       }
-       if (fstat(tdb->fd, &st) != 0) {
-               TDB_LOG((tdb, 0, "tdb_reopen: fstat failed (%s)\n", strerror(errno)));
-               goto fail;
-       }
-       if (st.st_ino != tdb->inode || st.st_dev != tdb->device) {
-               TDB_LOG((tdb, 0, "tdb_reopen: file dev/inode has changed!\n"));
-               goto fail;
-       }
-       tdb_mmap(tdb);
-       if (tdb_brlock(tdb, ACTIVE_LOCK, F_RDLCK, F_SETLKW, 0) == -1) {
-               TDB_LOG((tdb, 0, "tdb_reopen: failed to obtain active lock\n"));
-               goto fail;
-       }
+       tdb_trace_start(tdb);
+       tdb_trace_write(tdb, op);
+       tdb_trace_record(tdb, rec);
+       tdb_trace_end(tdb);
+}
 
-       return 0;
+void tdb_trace_1rec_ret(struct tdb_context *tdb, const char *op,
+                       TDB_DATA rec, int ret)
+{
+       tdb_trace_start(tdb);
+       tdb_trace_write(tdb, op);
+       tdb_trace_record(tdb, rec);
+       tdb_trace_end_ret(tdb, ret);
+}
 
-fail:
-       tdb_close(tdb);
-       return -1;
+void tdb_trace_1rec_retrec(struct tdb_context *tdb, const char *op,
+                          TDB_DATA rec, TDB_DATA ret)
+{
+       tdb_trace_start(tdb);
+       tdb_trace_write(tdb, op);
+       tdb_trace_record(tdb, rec);
+       tdb_trace_write(tdb, " =");
+       tdb_trace_record(tdb, ret);
+       tdb_trace_end(tdb);
 }
 
-/* reopen all tdb's */
-int tdb_reopen_all(void)
+void tdb_trace_2rec_flag_ret(struct tdb_context *tdb, const char *op,
+                            TDB_DATA rec1, TDB_DATA rec2, unsigned flag,
+                            int ret)
 {
-       TDB_CONTEXT *tdb;
+       char msg[1 + sizeof(ret) * 4];
 
-       for (tdb=tdbs; tdb; tdb = tdb->next) {
-               if (tdb_reopen(tdb) != 0) return -1;
-       }
+       snprintf(msg, sizeof(msg), " %#x", flag);
+       tdb_trace_start(tdb);
+       tdb_trace_write(tdb, op);
+       tdb_trace_record(tdb, rec1);
+       tdb_trace_record(tdb, rec2);
+       tdb_trace_write(tdb, msg);
+       tdb_trace_end_ret(tdb, ret);
+}
 
-       return 0;
+void tdb_trace_2rec_retrec(struct tdb_context *tdb, const char *op,
+                          TDB_DATA rec1, TDB_DATA rec2, TDB_DATA ret)
+{
+       tdb_trace_start(tdb);
+       tdb_trace_write(tdb, op);
+       tdb_trace_record(tdb, rec1);
+       tdb_trace_record(tdb, rec2);
+       tdb_trace_write(tdb, " =");
+       tdb_trace_record(tdb, ret);
+       tdb_trace_end(tdb);
 }
+#endif
diff --git a/libatalk/tdb/tdb_private.h b/libatalk/tdb/tdb_private.h
new file mode 100644 (file)
index 0000000..41389c4
--- /dev/null
@@ -0,0 +1,288 @@
+ /* 
+   Unix SMB/CIFS implementation.
+
+   trivial database library - private includes
+
+   Copyright (C) Andrew Tridgell              2005
+   
+     ** NOTE! The following LGPL license applies to the tdb
+     ** library. This does NOT imply that all of Samba is released
+     ** under the LGPL
+   
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#if 0
+#include "replace.h"
+#include "system/filesys.h"
+#include "system/time.h"
+#include "system/shmem.h"
+#include "system/select.h"
+#include "system/wait.h"
+#include "tdb.h"
+#endif
+
+#include <unistd.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/select.h>
+#include <sys/mman.h>
+#include <sys/time.h>
+#include <time.h>
+#include <utime.h>
+#include <sys/wait.h>
+#include <string.h>
+#include <stdlib.h>
+#include <limits.h>
+#include <stdio.h>
+#include <errno.h>
+#include <sys/param.h>
+
+#ifndef __STRING
+#define __STRING(x)    #x
+#endif
+
+#ifndef __STRINGSTRING
+#define __STRINGSTRING(x) __STRING(x)
+#endif
+
+#ifndef __LINESTR__
+#define __LINESTR__ __STRINGSTRING(__LINE__)
+#endif
+
+#ifndef __location__
+#define __location__ __FILE__ ":" __LINESTR__
+#endif
+
+#include <atalk/util.h>
+#include "atalk/tdb.h"
+
+/* #define TDB_TRACE 1 */
+#ifndef HAVE_GETPAGESIZE
+#define getpagesize() 0x2000
+#endif
+
+typedef uint32_t tdb_len_t;
+typedef uint32_t tdb_off_t;
+
+#ifndef offsetof
+#define offsetof(t,f) ((unsigned int)&((t *)0)->f)
+#endif
+
+#define TDB_MAGIC_FOOD "TDB file\n"
+#define TDB_VERSION (0x26011967 + 6)
+#define TDB_MAGIC (0x26011999U)
+#define TDB_FREE_MAGIC (~TDB_MAGIC)
+#define TDB_DEAD_MAGIC (0xFEE1DEAD)
+#define TDB_RECOVERY_MAGIC (0xf53bc0e7U)
+#define TDB_ALIGNMENT 4
+#define DEFAULT_HASH_SIZE 131
+#define FREELIST_TOP (sizeof(struct tdb_header))
+#define TDB_ALIGN(x,a) (((x) + (a)-1) & ~((a)-1))
+#define TDB_BYTEREV(x) (((((x)&0xff)<<24)|((x)&0xFF00)<<8)|(((x)>>8)&0xFF00)|((x)>>24))
+#define TDB_DEAD(r) ((r)->magic == TDB_DEAD_MAGIC)
+#define TDB_BAD_MAGIC(r) ((r)->magic != TDB_MAGIC && !TDB_DEAD(r))
+#define TDB_HASH_TOP(hash) (FREELIST_TOP + (BUCKET(hash)+1)*sizeof(tdb_off_t))
+#define TDB_HASHTABLE_SIZE(tdb) ((tdb->header.hash_size+1)*sizeof(tdb_off_t))
+#define TDB_DATA_START(hash_size) (TDB_HASH_TOP(hash_size-1) + sizeof(tdb_off_t))
+#define TDB_RECOVERY_HEAD offsetof(struct tdb_header, recovery_start)
+#define TDB_SEQNUM_OFS    offsetof(struct tdb_header, sequence_number)
+#define TDB_PAD_BYTE 0x42
+#define TDB_PAD_U32  0x42424242
+
+/* NB assumes there is a local variable called "tdb" that is the
+ * current context, also takes doubly-parenthesized print-style
+ * argument. */
+#define TDB_LOG(x) tdb->log.log_fn x
+
+#ifdef TDB_TRACE
+void tdb_trace(struct tdb_context *tdb, const char *op);
+void tdb_trace_seqnum(struct tdb_context *tdb, uint32_t seqnum, const char *op);
+void tdb_trace_open(struct tdb_context *tdb, const char *op,
+                   unsigned hash_size, unsigned tdb_flags, unsigned open_flags);
+void tdb_trace_ret(struct tdb_context *tdb, const char *op, int ret);
+void tdb_trace_retrec(struct tdb_context *tdb, const char *op, TDB_DATA ret);
+void tdb_trace_1rec(struct tdb_context *tdb, const char *op,
+                   TDB_DATA rec);
+void tdb_trace_1rec_ret(struct tdb_context *tdb, const char *op,
+                       TDB_DATA rec, int ret);
+void tdb_trace_1rec_retrec(struct tdb_context *tdb, const char *op,
+                          TDB_DATA rec, TDB_DATA ret);
+void tdb_trace_2rec_flag_ret(struct tdb_context *tdb, const char *op,
+                            TDB_DATA rec1, TDB_DATA rec2, unsigned flag,
+                            int ret);
+void tdb_trace_2rec_retrec(struct tdb_context *tdb, const char *op,
+                          TDB_DATA rec1, TDB_DATA rec2, TDB_DATA ret);
+#else
+#define tdb_trace(tdb, op)
+#define tdb_trace_seqnum(tdb, seqnum, op)
+#define tdb_trace_open(tdb, op, hash_size, tdb_flags, open_flags)
+#define tdb_trace_ret(tdb, op, ret)
+#define tdb_trace_retrec(tdb, op, ret)
+#define tdb_trace_1rec(tdb, op, rec)
+#define tdb_trace_1rec_ret(tdb, op, rec, ret)
+#define tdb_trace_1rec_retrec(tdb, op, rec, ret)
+#define tdb_trace_2rec_flag_ret(tdb, op, rec1, rec2, flag, ret)
+#define tdb_trace_2rec_retrec(tdb, op, rec1, rec2, ret)
+#endif /* !TDB_TRACE */
+
+/* lock offsets */
+#define GLOBAL_LOCK      0
+#define ACTIVE_LOCK      4
+#define TRANSACTION_LOCK 8
+
+/* free memory if the pointer is valid and zero the pointer */
+#ifndef SAFE_FREE
+#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); (x)=NULL;} } while(0)
+#endif
+
+#define BUCKET(hash) ((hash) % tdb->header.hash_size)
+
+#define DOCONV() (tdb->flags & TDB_CONVERT)
+#define CONVERT(x) (DOCONV() ? tdb_convert(&x, sizeof(x)) : &x)
+
+
+/* the body of the database is made of one tdb_record for the free space
+   plus a separate data list for each hash value */
+struct tdb_record {
+       tdb_off_t next; /* offset of the next record in the list */
+       tdb_len_t rec_len; /* total byte length of record */
+       tdb_len_t key_len; /* byte length of key */
+       tdb_len_t data_len; /* byte length of data */
+       uint32_t full_hash; /* the full 32 bit hash of the key */
+       uint32_t magic;   /* try to catch errors */
+       /* the following union is implied:
+               union {
+                       char record[rec_len];
+                       struct {
+                               char key[key_len];
+                               char data[data_len];
+                       }
+                       uint32_t totalsize; (tailer)
+               }
+       */
+};
+
+
+/* this is stored at the front of every database */
+struct tdb_header {
+       char magic_food[32]; /* for /etc/magic */
+       uint32_t version; /* version of the code */
+       uint32_t hash_size; /* number of hash entries */
+       tdb_off_t rwlocks; /* obsolete - kept to detect old formats */
+       tdb_off_t recovery_start; /* offset of transaction recovery region */
+       tdb_off_t sequence_number; /* used when TDB_SEQNUM is set */
+       tdb_off_t reserved[29];
+};
+
+struct tdb_lock_type {
+       int list;
+       uint32_t count;
+       uint32_t ltype;
+};
+
+struct tdb_traverse_lock {
+       struct tdb_traverse_lock *next;
+       uint32_t off;
+       uint32_t hash;
+       int lock_rw;
+};
+
+
+struct tdb_methods {
+       int (*tdb_read)(struct tdb_context *, tdb_off_t , void *, tdb_len_t , int );
+       int (*tdb_write)(struct tdb_context *, tdb_off_t, const void *, tdb_len_t);
+       void (*next_hash_chain)(struct tdb_context *, uint32_t *);
+       int (*tdb_oob)(struct tdb_context *, tdb_off_t , int );
+       int (*tdb_expand_file)(struct tdb_context *, tdb_off_t , tdb_off_t );
+       int (*tdb_brlock)(struct tdb_context *, tdb_off_t , int, int, int, size_t);
+};
+
+struct tdb_context {
+       char *name; /* the name of the database */
+       void *map_ptr; /* where it is currently mapped */
+       int fd; /* open file descriptor for the database */
+       tdb_len_t map_size; /* how much space has been mapped */
+       int read_only; /* opened read-only */
+       int traverse_read; /* read-only traversal */
+       int traverse_write; /* read-write traversal */
+       struct tdb_lock_type global_lock;
+       int num_lockrecs;
+       struct tdb_lock_type *lockrecs; /* only real locks, all with count>0 */
+       enum TDB_ERROR ecode; /* error code for last tdb error */
+       struct tdb_header header; /* a cached copy of the header */
+       uint32_t flags; /* the flags passed to tdb_open */
+       struct tdb_traverse_lock travlocks; /* current traversal locks */
+       struct tdb_context *next; /* all tdbs to avoid multiple opens */
+       dev_t device;   /* uniquely identifies this tdb */
+       ino_t inode;    /* uniquely identifies this tdb */
+       struct tdb_logging_context log;
+       unsigned int (*hash_fn)(TDB_DATA *key);
+       int open_flags; /* flags used in the open - needed by reopen */
+       unsigned int num_locks; /* number of chain locks held */
+       const struct tdb_methods *methods;
+       struct tdb_transaction *transaction;
+       int page_size;
+       int max_dead_records;
+       int transaction_lock_count;
+#ifdef TDB_TRACE
+       int tracefd;
+#endif
+       volatile sig_atomic_t *interrupt_sig_ptr;
+};
+
+
+/*
+  internal prototypes
+*/
+int tdb_munmap(struct tdb_context *tdb);
+void tdb_mmap(struct tdb_context *tdb);
+int tdb_lock(struct tdb_context *tdb, int list, int ltype);
+int tdb_lock_nonblock(struct tdb_context *tdb, int list, int ltype);
+int tdb_unlock(struct tdb_context *tdb, int list, int ltype);
+int tdb_brlock(struct tdb_context *tdb, tdb_off_t offset, int rw_type, int lck_type, int probe, size_t len);
+int tdb_transaction_lock(struct tdb_context *tdb, int ltype);
+int tdb_transaction_unlock(struct tdb_context *tdb);
+int tdb_brlock_upgrade(struct tdb_context *tdb, tdb_off_t offset, size_t len);
+int tdb_write_lock_record(struct tdb_context *tdb, tdb_off_t off);
+int tdb_write_unlock_record(struct tdb_context *tdb, tdb_off_t off);
+int tdb_ofs_read(struct tdb_context *tdb, tdb_off_t offset, tdb_off_t *d);
+int tdb_ofs_write(struct tdb_context *tdb, tdb_off_t offset, tdb_off_t *d);
+void *tdb_convert(void *buf, uint32_t size);
+int tdb_free(struct tdb_context *tdb, tdb_off_t offset, struct tdb_record *rec);
+tdb_off_t tdb_allocate(struct tdb_context *tdb, tdb_len_t length, struct tdb_record *rec);
+int tdb_ofs_read(struct tdb_context *tdb, tdb_off_t offset, tdb_off_t *d);
+int tdb_ofs_write(struct tdb_context *tdb, tdb_off_t offset, tdb_off_t *d);
+int tdb_lock_record(struct tdb_context *tdb, tdb_off_t off);
+int tdb_unlock_record(struct tdb_context *tdb, tdb_off_t off);
+int _tdb_transaction_cancel(struct tdb_context *tdb);
+int tdb_rec_read(struct tdb_context *tdb, tdb_off_t offset, struct tdb_record *rec);
+int tdb_rec_write(struct tdb_context *tdb, tdb_off_t offset, struct tdb_record *rec);
+int tdb_do_delete(struct tdb_context *tdb, tdb_off_t rec_ptr, struct tdb_record *rec);
+unsigned char *tdb_alloc_read(struct tdb_context *tdb, tdb_off_t offset, tdb_len_t len);
+int tdb_parse_data(struct tdb_context *tdb, TDB_DATA key,
+                  tdb_off_t offset, tdb_len_t len,
+                  int (*parser)(TDB_DATA key, TDB_DATA data,
+                                void *private_data),
+                  void *private_data);
+tdb_off_t tdb_find_lock_hash(struct tdb_context *tdb, TDB_DATA key, uint32_t hash, int locktype,
+                          struct tdb_record *rec);
+void tdb_io_init(struct tdb_context *tdb);
+int tdb_expand(struct tdb_context *tdb, tdb_off_t size);
+int tdb_rec_free_read(struct tdb_context *tdb, tdb_off_t off,
+                     struct tdb_record *rec);
+
+
diff --git a/libatalk/tdb/transaction.c b/libatalk/tdb/transaction.c
new file mode 100644 (file)
index 0000000..b8988ea
--- /dev/null
@@ -0,0 +1,1236 @@
+ /* 
+   Unix SMB/CIFS implementation.
+
+   trivial database library
+
+   Copyright (C) Andrew Tridgell              2005
+
+     ** NOTE! The following LGPL license applies to the tdb
+     ** library. This does NOT imply that all of Samba is released
+     ** under the LGPL
+   
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "tdb_private.h"
+
+/*
+  transaction design:
+
+  - only allow a single transaction at a time per database. This makes
+    using the transaction API simpler, as otherwise the caller would
+    have to cope with temporary failures in transactions that conflict
+    with other current transactions
+
+  - keep the transaction recovery information in the same file as the
+    database, using a special 'transaction recovery' record pointed at
+    by the header. This removes the need for extra journal files as
+    used by some other databases
+
+  - dynamically allocated the transaction recover record, re-using it
+    for subsequent transactions. If a larger record is needed then
+    tdb_free() the old record to place it on the normal tdb freelist
+    before allocating the new record
+
+  - during transactions, keep a linked list of writes all that have
+    been performed by intercepting all tdb_write() calls. The hooked
+    transaction versions of tdb_read() and tdb_write() check this
+    linked list and try to use the elements of the list in preference
+    to the real database.
+
+  - don't allow any locks to be held when a transaction starts,
+    otherwise we can end up with deadlock (plus lack of lock nesting
+    in posix locks would mean the lock is lost)
+
+  - if the caller gains a lock during the transaction but doesn't
+    release it then fail the commit
+
+  - allow for nested calls to tdb_transaction_start(), re-using the
+    existing transaction record. If the inner transaction is cancelled
+    then a subsequent commit will fail
+  - keep a mirrored copy of the tdb hash chain heads to allow for the
+    fast hash heads scan on traverse, updating the mirrored copy in
+    the transaction version of tdb_write
+
+  - allow callers to mix transaction and non-transaction use of tdb,
+    although once a transaction is started then an exclusive lock is
+    gained until the transaction is committed or cancelled
+
+  - the commit stategy involves first saving away all modified data
+    into a linearised buffer in the transaction recovery area, then
+    marking the transaction recovery area with a magic value to
+    indicate a valid recovery record. In total 4 fsync/msync calls are
+    needed per commit to prevent race conditions. It might be possible
+    to reduce this to 3 or even 2 with some more work.
+
+  - check for a valid recovery record on open of the tdb, while the
+    global lock is held. Automatically recover from the transaction
+    recovery area if needed, then continue with the open as
+    usual. This allows for smooth crash recovery with no administrator
+    intervention.
+
+  - if TDB_NOSYNC is passed to flags in tdb_open then transactions are
+    still available, but no transaction recovery area is used and no
+    fsync/msync calls are made.
+
+  - if TDB_ALLOW_NESTING is passed to flags in tdb open, or added using
+    tdb_add_flags() transaction nesting is enabled.
+    It resets the TDB_DISALLOW_NESTING flag, as both cannot be used together.
+    The default is that transaction nesting is allowed.
+    Note: this default may change in future versions of tdb.
+
+    Beware. when transactions are nested a transaction successfully
+    completed with tdb_transaction_commit() can be silently unrolled later.
+
+  - if TDB_DISALLOW_NESTING is passed to flags in tdb open, or added using
+    tdb_add_flags() transaction nesting is disabled.
+    It resets the TDB_ALLOW_NESTING flag, as both cannot be used together.
+    An attempt create a nested transaction will fail with TDB_ERR_NESTING.
+    The default is that transaction nesting is allowed.
+    Note: this default may change in future versions of tdb.
+*/
+
+
+/*
+  hold the context of any current transaction
+*/
+struct tdb_transaction {
+       /* we keep a mirrored copy of the tdb hash heads here so
+          tdb_next_hash_chain() can operate efficiently */
+       uint32_t *hash_heads;
+
+       /* the original io methods - used to do IOs to the real db */
+       const struct tdb_methods *io_methods;
+
+       /* the list of transaction blocks. When a block is first
+          written to, it gets created in this list */
+       uint8_t **blocks;
+       uint32_t num_blocks;
+       uint32_t block_size;      /* bytes in each block */
+       uint32_t last_block_size; /* number of valid bytes in the last block */
+
+       /* non-zero when an internal transaction error has
+          occurred. All write operations will then fail until the
+          transaction is ended */
+       int transaction_error;
+
+       /* when inside a transaction we need to keep track of any
+          nested tdb_transaction_start() calls, as these are allowed,
+          but don't create a new transaction */
+       int nesting;
+
+       /* set when a prepare has already occurred */
+       bool prepared;
+       tdb_off_t magic_offset;
+
+       /* set when the GLOBAL_LOCK has been taken */
+       bool global_lock_taken;
+
+       /* old file size before transaction */
+       tdb_len_t old_map_size;
+
+       /* we should re-pack on commit */
+       bool need_repack;
+};
+
+
+/*
+  read while in a transaction. We need to check first if the data is in our list
+  of transaction elements, then if not do a real read
+*/
+static int transaction_read(struct tdb_context *tdb, tdb_off_t off, void *buf, 
+                           tdb_len_t len, int cv)
+{
+       uint32_t blk;
+
+       /* break it down into block sized ops */
+       while (len + (off % tdb->transaction->block_size) > tdb->transaction->block_size) {
+               tdb_len_t len2 = tdb->transaction->block_size - (off % tdb->transaction->block_size);
+               if (transaction_read(tdb, off, buf, len2, cv) != 0) {
+                       return -1;
+               }
+               len -= len2;
+               off += len2;
+               buf = (void *)(len2 + (char *)buf);
+       }
+
+       if (len == 0) {
+               return 0;
+       }
+
+       blk = off / tdb->transaction->block_size;
+
+       /* see if we have it in the block list */
+       if (tdb->transaction->num_blocks <= blk ||
+           tdb->transaction->blocks[blk] == NULL) {
+               /* nope, do a real read */
+               if (tdb->transaction->io_methods->tdb_read(tdb, off, buf, len, cv) != 0) {
+                       goto fail;
+               }
+               return 0;
+       }
+
+       /* it is in the block list. Now check for the last block */
+       if (blk == tdb->transaction->num_blocks-1) {
+               if (len > tdb->transaction->last_block_size) {
+                       goto fail;
+               }
+       }
+       
+       /* now copy it out of this block */
+       memcpy(buf, tdb->transaction->blocks[blk] + (off % tdb->transaction->block_size), len);
+       if (cv) {
+               tdb_convert(buf, len);
+       }
+       return 0;
+
+fail:
+       TDB_LOG((tdb, TDB_DEBUG_FATAL, "transaction_read: failed at off=%d len=%d\n", off, len));
+       tdb->ecode = TDB_ERR_IO;
+       tdb->transaction->transaction_error = 1;
+       return -1;
+}
+
+
+/*
+  write while in a transaction
+*/
+static int transaction_write(struct tdb_context *tdb, tdb_off_t off, 
+                            const void *buf, tdb_len_t len)
+{
+       uint32_t blk;
+
+       /* Only a commit is allowed on a prepared transaction */
+       if (tdb->transaction->prepared) {
+               tdb->ecode = TDB_ERR_EINVAL;
+               TDB_LOG((tdb, TDB_DEBUG_FATAL, "transaction_write: transaction already prepared, write not allowed\n"));
+               tdb->transaction->transaction_error = 1;
+               return -1;
+       }
+
+       /* if the write is to a hash head, then update the transaction
+          hash heads */
+       if (len == sizeof(tdb_off_t) && off >= FREELIST_TOP &&
+           off < FREELIST_TOP+TDB_HASHTABLE_SIZE(tdb)) {
+               uint32_t chain = (off-FREELIST_TOP) / sizeof(tdb_off_t);
+               memcpy(&tdb->transaction->hash_heads[chain], buf, len);
+       }
+
+       /* break it up into block sized chunks */
+       while (len + (off % tdb->transaction->block_size) > tdb->transaction->block_size) {
+               tdb_len_t len2 = tdb->transaction->block_size - (off % tdb->transaction->block_size);
+               if (transaction_write(tdb, off, buf, len2) != 0) {
+                       return -1;
+               }
+               len -= len2;
+               off += len2;
+               if (buf != NULL) {
+                       buf = (const void *)(len2 + (const char *)buf);
+               }
+       }
+
+       if (len == 0) {
+               return 0;
+       }
+
+       blk = off / tdb->transaction->block_size;
+       off = off % tdb->transaction->block_size;
+
+       if (tdb->transaction->num_blocks <= blk) {
+               uint8_t **new_blocks;
+               /* expand the blocks array */
+               if (tdb->transaction->blocks == NULL) {
+                       new_blocks = (uint8_t **)malloc(
+                               (blk+1)*sizeof(uint8_t *));
+               } else {
+                       new_blocks = (uint8_t **)realloc(
+                               tdb->transaction->blocks,
+                               (blk+1)*sizeof(uint8_t *));
+               }
+               if (new_blocks == NULL) {
+                       tdb->ecode = TDB_ERR_OOM;
+                       goto fail;
+               }
+               memset(&new_blocks[tdb->transaction->num_blocks], 0, 
+                      (1+(blk - tdb->transaction->num_blocks))*sizeof(uint8_t *));
+               tdb->transaction->blocks = new_blocks;
+               tdb->transaction->num_blocks = blk+1;
+               tdb->transaction->last_block_size = 0;
+       }
+
+       /* allocate and fill a block? */
+       if (tdb->transaction->blocks[blk] == NULL) {
+               tdb->transaction->blocks[blk] = (uint8_t *)calloc(tdb->transaction->block_size, 1);
+               if (tdb->transaction->blocks[blk] == NULL) {
+                       tdb->ecode = TDB_ERR_OOM;
+                       tdb->transaction->transaction_error = 1;
+                       return -1;                      
+               }
+               if (tdb->transaction->old_map_size > blk * tdb->transaction->block_size) {
+                       tdb_len_t len2 = tdb->transaction->block_size;
+                       if (len2 + (blk * tdb->transaction->block_size) > tdb->transaction->old_map_size) {
+                               len2 = tdb->transaction->old_map_size - (blk * tdb->transaction->block_size);
+                       }
+                       if (tdb->transaction->io_methods->tdb_read(tdb, blk * tdb->transaction->block_size, 
+                                                                  tdb->transaction->blocks[blk], 
+                                                                  len2, 0) != 0) {
+                               SAFE_FREE(tdb->transaction->blocks[blk]);                               
+                               tdb->ecode = TDB_ERR_IO;
+                               goto fail;
+                       }
+                       if (blk == tdb->transaction->num_blocks-1) {
+                               tdb->transaction->last_block_size = len2;
+                       }                       
+               }
+       }
+       
+       /* overwrite part of an existing block */
+       if (buf == NULL) {
+               memset(tdb->transaction->blocks[blk] + off, 0, len);
+       } else {
+               memcpy(tdb->transaction->blocks[blk] + off, buf, len);
+       }
+       if (blk == tdb->transaction->num_blocks-1) {
+               if (len + off > tdb->transaction->last_block_size) {
+                       tdb->transaction->last_block_size = len + off;
+               }
+       }
+
+       return 0;
+
+fail:
+       TDB_LOG((tdb, TDB_DEBUG_FATAL, "transaction_write: failed at off=%d len=%d\n", 
+                (blk*tdb->transaction->block_size) + off, len));
+       tdb->transaction->transaction_error = 1;
+       return -1;
+}
+
+
+/*
+  write while in a transaction - this varient never expands the transaction blocks, it only
+  updates existing blocks. This means it cannot change the recovery size
+*/
+static int transaction_write_existing(struct tdb_context *tdb, tdb_off_t off, 
+                                     const void *buf, tdb_len_t len)
+{
+       uint32_t blk;
+
+       /* break it up into block sized chunks */
+       while (len + (off % tdb->transaction->block_size) > tdb->transaction->block_size) {
+               tdb_len_t len2 = tdb->transaction->block_size - (off % tdb->transaction->block_size);
+               if (transaction_write_existing(tdb, off, buf, len2) != 0) {
+                       return -1;
+               }
+               len -= len2;
+               off += len2;
+               if (buf != NULL) {
+                       buf = (const void *)(len2 + (const char *)buf);
+               }
+       }
+
+       if (len == 0) {
+               return 0;
+       }
+
+       blk = off / tdb->transaction->block_size;
+       off = off % tdb->transaction->block_size;
+
+       if (tdb->transaction->num_blocks <= blk ||
+           tdb->transaction->blocks[blk] == NULL) {
+               return 0;
+       }
+
+       if (blk == tdb->transaction->num_blocks-1 &&
+           off + len > tdb->transaction->last_block_size) {
+               if (off >= tdb->transaction->last_block_size) {
+                       return 0;
+               }
+               len = tdb->transaction->last_block_size - off;
+       }
+
+       /* overwrite part of an existing block */
+       memcpy(tdb->transaction->blocks[blk] + off, buf, len);
+
+       return 0;
+}
+
+
+/*
+  accelerated hash chain head search, using the cached hash heads
+*/
+static void transaction_next_hash_chain(struct tdb_context *tdb, uint32_t *chain)
+{
+       uint32_t h = *chain;
+       for (;h < tdb->header.hash_size;h++) {
+               /* the +1 takes account of the freelist */
+               if (0 != tdb->transaction->hash_heads[h+1]) {
+                       break;
+               }
+       }
+       (*chain) = h;
+}
+
+/*
+  out of bounds check during a transaction
+*/
+static int transaction_oob(struct tdb_context *tdb, tdb_off_t len, int probe)
+{
+       if (len <= tdb->map_size) {
+               return 0;
+       }
+       tdb->ecode = TDB_ERR_IO;
+       return -1;
+}
+
+/*
+  transaction version of tdb_expand().
+*/
+static int transaction_expand_file(struct tdb_context *tdb, tdb_off_t size, 
+                                  tdb_off_t addition)
+{
+       /* add a write to the transaction elements, so subsequent
+          reads see the zero data */
+       if (transaction_write(tdb, size, NULL, addition) != 0) {
+               return -1;
+       }
+
+       tdb->transaction->need_repack = true;
+
+       return 0;
+}
+
+/*
+  brlock during a transaction - ignore them
+*/
+static int transaction_brlock(struct tdb_context *tdb, tdb_off_t offset, 
+                             int rw_type, int lck_type, int probe, size_t len)
+{
+       return 0;
+}
+
+static const struct tdb_methods transaction_methods = {
+       transaction_read,
+       transaction_write,
+       transaction_next_hash_chain,
+       transaction_oob,
+       transaction_expand_file,
+       transaction_brlock
+};
+
+
+/*
+  start a tdb transaction. No token is returned, as only a single
+  transaction is allowed to be pending per tdb_context
+*/
+int tdb_transaction_start(struct tdb_context *tdb)
+{
+       /* some sanity checks */
+       if (tdb->read_only || (tdb->flags & TDB_INTERNAL) || tdb->traverse_read) {
+               TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_start: cannot start a transaction on a read-only or internal db\n"));
+               tdb->ecode = TDB_ERR_EINVAL;
+               return -1;
+       }
+
+       /* cope with nested tdb_transaction_start() calls */
+       if (tdb->transaction != NULL) {
+               if (!(tdb->flags & TDB_ALLOW_NESTING)) {
+                       tdb->ecode = TDB_ERR_NESTING;
+                       return -1;
+               }
+               tdb->transaction->nesting++;
+               TDB_LOG((tdb, TDB_DEBUG_TRACE, "tdb_transaction_start: nesting %d\n", 
+                        tdb->transaction->nesting));
+               return 0;
+       }
+
+       if (tdb->num_locks != 0 || tdb->global_lock.count) {
+               /* the caller must not have any locks when starting a
+                  transaction as otherwise we'll be screwed by lack
+                  of nested locks in posix */
+               TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_start: cannot start a transaction with locks held\n"));
+               tdb->ecode = TDB_ERR_LOCK;
+               return -1;
+       }
+
+       if (tdb->travlocks.next != NULL) {
+               /* you cannot use transactions inside a traverse (although you can use
+                  traverse inside a transaction) as otherwise you can end up with
+                  deadlock */
+               TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_start: cannot start a transaction within a traverse\n"));
+               tdb->ecode = TDB_ERR_LOCK;
+               return -1;
+       }
+
+       tdb->transaction = (struct tdb_transaction *)
+               calloc(sizeof(struct tdb_transaction), 1);
+       if (tdb->transaction == NULL) {
+               tdb->ecode = TDB_ERR_OOM;
+               return -1;
+       }
+
+       /* a page at a time seems like a reasonable compromise between compactness and efficiency */
+       tdb->transaction->block_size = tdb->page_size;
+
+       /* get the transaction write lock. This is a blocking lock. As
+          discussed with Volker, there are a number of ways we could
+          make this async, which we will probably do in the future */
+       if (tdb_transaction_lock(tdb, F_WRLCK) == -1) {
+               SAFE_FREE(tdb->transaction->blocks);
+               SAFE_FREE(tdb->transaction);
+               return -1;
+       }
+       
+       /* get a read lock from the freelist to the end of file. This
+          is upgraded to a write lock during the commit */
+       if (tdb_brlock(tdb, FREELIST_TOP, F_RDLCK, F_SETLKW, 0, 0) == -1) {
+               TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_start: failed to get hash locks\n"));
+               tdb->ecode = TDB_ERR_LOCK;
+               goto fail;
+       }
+
+       /* setup a copy of the hash table heads so the hash scan in
+          traverse can be fast */
+       tdb->transaction->hash_heads = (uint32_t *)
+               calloc(tdb->header.hash_size+1, sizeof(uint32_t));
+       if (tdb->transaction->hash_heads == NULL) {
+               tdb->ecode = TDB_ERR_OOM;
+               goto fail;
+       }
+       if (tdb->methods->tdb_read(tdb, FREELIST_TOP, tdb->transaction->hash_heads,
+                                  TDB_HASHTABLE_SIZE(tdb), 0) != 0) {
+               TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_start: failed to read hash heads\n"));
+               tdb->ecode = TDB_ERR_IO;
+               goto fail;
+       }
+
+       /* make sure we know about any file expansions already done by
+          anyone else */
+       tdb->methods->tdb_oob(tdb, tdb->map_size + 1, 1);
+       tdb->transaction->old_map_size = tdb->map_size;
+
+       /* finally hook the io methods, replacing them with
+          transaction specific methods */
+       tdb->transaction->io_methods = tdb->methods;
+       tdb->methods = &transaction_methods;
+
+       /* Trace at the end, so we get sequence number correct. */
+       tdb_trace(tdb, "tdb_transaction_start");
+       return 0;
+       
+fail:
+       tdb_brlock(tdb, FREELIST_TOP, F_UNLCK, F_SETLKW, 0, 0);
+       tdb_transaction_unlock(tdb);
+       SAFE_FREE(tdb->transaction->blocks);
+       SAFE_FREE(tdb->transaction->hash_heads);
+       SAFE_FREE(tdb->transaction);
+       return -1;
+}
+
+
+/*
+  sync to disk
+*/
+static int transaction_sync(struct tdb_context *tdb, tdb_off_t offset, tdb_len_t length)
+{      
+       if (tdb->flags & TDB_NOSYNC) {
+               return 0;
+       }
+
+       if (fsync(tdb->fd) != 0) {
+               tdb->ecode = TDB_ERR_IO;
+               TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction: fsync failed\n"));
+               return -1;
+       }
+#ifdef HAVE_MMAP
+       if (tdb->map_ptr) {
+               tdb_off_t moffset = offset & ~(tdb->page_size-1);
+               if (msync(moffset + (char *)tdb->map_ptr, 
+                         length + (offset - moffset), MS_SYNC) != 0) {
+                       tdb->ecode = TDB_ERR_IO;
+                       TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction: msync failed - %s\n",
+                                strerror(errno)));
+                       return -1;
+               }
+       }
+#endif
+       return 0;
+}
+
+
+int _tdb_transaction_cancel(struct tdb_context *tdb)
+{      
+       int i, ret = 0;
+
+       if (tdb->transaction == NULL) {
+               TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_cancel: no transaction\n"));
+               return -1;
+       }
+
+       if (tdb->transaction->nesting != 0) {
+               tdb->transaction->transaction_error = 1;
+               tdb->transaction->nesting--;
+               return 0;
+       }               
+
+       tdb->map_size = tdb->transaction->old_map_size;
+
+       /* free all the transaction blocks */
+       for (i=0;i<tdb->transaction->num_blocks;i++) {
+               if (tdb->transaction->blocks[i] != NULL) {
+                       free(tdb->transaction->blocks[i]);
+               }
+       }
+       SAFE_FREE(tdb->transaction->blocks);
+
+       if (tdb->transaction->magic_offset) {
+               const struct tdb_methods *methods = tdb->transaction->io_methods;
+               uint32_t zero = 0;
+
+               /* remove the recovery marker */
+               if (methods->tdb_write(tdb, tdb->transaction->magic_offset, &zero, 4) == -1 ||
+               transaction_sync(tdb, tdb->transaction->magic_offset, 4) == -1) {
+                       TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_cancel: failed to remove recovery magic\n"));
+                       ret = -1;
+               }
+       }
+
+       if (tdb->transaction->global_lock_taken) {
+               tdb_brlock(tdb, GLOBAL_LOCK, F_UNLCK, F_SETLKW, 0, 1);
+               tdb->transaction->global_lock_taken = false;
+       }
+
+       /* remove any global lock created during the transaction */
+       if (tdb->global_lock.count != 0) {
+               tdb_brlock(tdb, FREELIST_TOP, F_UNLCK, F_SETLKW, 0, 4*tdb->header.hash_size);
+               tdb->global_lock.count = 0;
+       }
+
+       /* remove any locks created during the transaction */
+       if (tdb->num_locks != 0) {
+               for (i=0;i<tdb->num_lockrecs;i++) {
+                       tdb_brlock(tdb,FREELIST_TOP+4*tdb->lockrecs[i].list,
+                                  F_UNLCK,F_SETLKW, 0, 1);
+               }
+               tdb->num_locks = 0;
+               tdb->num_lockrecs = 0;
+               SAFE_FREE(tdb->lockrecs);
+       }
+
+       /* restore the normal io methods */
+       tdb->methods = tdb->transaction->io_methods;
+
+       tdb_brlock(tdb, FREELIST_TOP, F_UNLCK, F_SETLKW, 0, 0);
+       tdb_transaction_unlock(tdb);
+       SAFE_FREE(tdb->transaction->hash_heads);
+       SAFE_FREE(tdb->transaction);
+       
+       return ret;
+}
+
+/*
+  cancel the current transaction
+*/
+int tdb_transaction_cancel(struct tdb_context *tdb)
+{
+       tdb_trace(tdb, "tdb_transaction_cancel");
+       return _tdb_transaction_cancel(tdb);
+}
+
+/*
+  work out how much space the linearised recovery data will consume
+*/
+static tdb_len_t tdb_recovery_size(struct tdb_context *tdb)
+{
+       tdb_len_t recovery_size = 0;
+       int i;
+
+       recovery_size = sizeof(uint32_t);
+       for (i=0;i<tdb->transaction->num_blocks;i++) {
+               if (i * tdb->transaction->block_size >= tdb->transaction->old_map_size) {
+                       break;
+               }
+               if (tdb->transaction->blocks[i] == NULL) {
+                       continue;
+               }
+               recovery_size += 2*sizeof(tdb_off_t);
+               if (i == tdb->transaction->num_blocks-1) {
+                       recovery_size += tdb->transaction->last_block_size;
+               } else {
+                       recovery_size += tdb->transaction->block_size;
+               }
+       }       
+
+       return recovery_size;
+}
+
+/*
+  allocate the recovery area, or use an existing recovery area if it is
+  large enough
+*/
+static int tdb_recovery_allocate(struct tdb_context *tdb, 
+                                tdb_len_t *recovery_size,
+                                tdb_off_t *recovery_offset,
+                                tdb_len_t *recovery_max_size)
+{
+       struct tdb_record rec;
+       const struct tdb_methods *methods = tdb->transaction->io_methods;
+       tdb_off_t recovery_head;
+
+       if (tdb_ofs_read(tdb, TDB_RECOVERY_HEAD, &recovery_head) == -1) {
+               TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_recovery_allocate: failed to read recovery head\n"));
+               return -1;
+       }
+
+       rec.rec_len = 0;
+
+       if (recovery_head != 0 && 
+           methods->tdb_read(tdb, recovery_head, &rec, sizeof(rec), DOCONV()) == -1) {
+               TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_recovery_allocate: failed to read recovery record\n"));
+               return -1;
+       }
+
+       *recovery_size = tdb_recovery_size(tdb);
+
+       if (recovery_head != 0 && *recovery_size <= rec.rec_len) {
+               /* it fits in the existing area */
+               *recovery_max_size = rec.rec_len;
+               *recovery_offset = recovery_head;
+               return 0;
+       }
+
+       /* we need to free up the old recovery area, then allocate a
+          new one at the end of the file. Note that we cannot use
+          tdb_allocate() to allocate the new one as that might return
+          us an area that is being currently used (as of the start of
+          the transaction) */
+       if (recovery_head != 0) {
+               if (tdb_free(tdb, recovery_head, &rec) == -1) {
+                       TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_recovery_allocate: failed to free previous recovery area\n"));
+                       return -1;
+               }
+       }
+
+       /* the tdb_free() call might have increased the recovery size */
+       *recovery_size = tdb_recovery_size(tdb);
+
+       /* round up to a multiple of page size */
+       *recovery_max_size = TDB_ALIGN(sizeof(rec) + *recovery_size, tdb->page_size) - sizeof(rec);
+       *recovery_offset = tdb->map_size;
+       recovery_head = *recovery_offset;
+
+       if (methods->tdb_expand_file(tdb, tdb->transaction->old_map_size, 
+                                    (tdb->map_size - tdb->transaction->old_map_size) +
+                                    sizeof(rec) + *recovery_max_size) == -1) {
+               TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_recovery_allocate: failed to create recovery area\n"));
+               return -1;
+       }
+
+       /* remap the file (if using mmap) */
+       methods->tdb_oob(tdb, tdb->map_size + 1, 1);
+
+       /* we have to reset the old map size so that we don't try to expand the file
+          again in the transaction commit, which would destroy the recovery area */
+       tdb->transaction->old_map_size = tdb->map_size;
+
+       /* write the recovery header offset and sync - we can sync without a race here
+          as the magic ptr in the recovery record has not been set */
+       CONVERT(recovery_head);
+       if (methods->tdb_write(tdb, TDB_RECOVERY_HEAD, 
+                              &recovery_head, sizeof(tdb_off_t)) == -1) {
+               TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_recovery_allocate: failed to write recovery head\n"));
+               return -1;
+       }
+       if (transaction_write_existing(tdb, TDB_RECOVERY_HEAD, &recovery_head, sizeof(tdb_off_t)) == -1) {
+               TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_recovery_allocate: failed to write recovery head\n"));
+               return -1;
+       }
+
+       return 0;
+}
+
+
+/*
+  setup the recovery data that will be used on a crash during commit
+*/
+static int transaction_setup_recovery(struct tdb_context *tdb, 
+                                     tdb_off_t *magic_offset)
+{
+       tdb_len_t recovery_size;
+       unsigned char *data, *p;
+       const struct tdb_methods *methods = tdb->transaction->io_methods;
+       struct tdb_record *rec;
+       tdb_off_t recovery_offset, recovery_max_size;
+       tdb_off_t old_map_size = tdb->transaction->old_map_size;
+       uint32_t magic, tailer;
+       int i;
+
+       /*
+         check that the recovery area has enough space
+       */
+       if (tdb_recovery_allocate(tdb, &recovery_size, 
+                                 &recovery_offset, &recovery_max_size) == -1) {
+               return -1;
+       }
+
+       data = (unsigned char *)malloc(recovery_size + sizeof(*rec));
+       if (data == NULL) {
+               tdb->ecode = TDB_ERR_OOM;
+               return -1;
+       }
+
+       rec = (struct tdb_record *)data;
+       memset(rec, 0, sizeof(*rec));
+
+       rec->magic    = 0;
+       rec->data_len = recovery_size;
+       rec->rec_len  = recovery_max_size;
+       rec->key_len  = old_map_size;
+       CONVERT(rec);
+
+       /* build the recovery data into a single blob to allow us to do a single
+          large write, which should be more efficient */
+       p = data + sizeof(*rec);
+       for (i=0;i<tdb->transaction->num_blocks;i++) {
+               tdb_off_t offset;
+               tdb_len_t length;
+
+               if (tdb->transaction->blocks[i] == NULL) {
+                       continue;
+               }
+
+               offset = i * tdb->transaction->block_size;
+               length = tdb->transaction->block_size;
+               if (i == tdb->transaction->num_blocks-1) {
+                       length = tdb->transaction->last_block_size;
+               }
+               
+               if (offset >= old_map_size) {
+                       continue;
+               }
+               if (offset + length > tdb->transaction->old_map_size) {
+                       TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_setup_recovery: transaction data over new region boundary\n"));
+                       free(data);
+                       tdb->ecode = TDB_ERR_CORRUPT;
+                       return -1;
+               }
+               memcpy(p, &offset, 4);
+               memcpy(p+4, &length, 4);
+               if (DOCONV()) {
+                       tdb_convert(p, 8);
+               }
+               /* the recovery area contains the old data, not the
+                  new data, so we have to call the original tdb_read
+                  method to get it */
+               if (methods->tdb_read(tdb, offset, p + 8, length, 0) != 0) {
+                       free(data);
+                       tdb->ecode = TDB_ERR_IO;
+                       return -1;
+               }
+               p += 8 + length;
+       }
+
+       /* and the tailer */
+       tailer = sizeof(*rec) + recovery_max_size;
+       memcpy(p, &tailer, 4);
+       CONVERT(p);
+
+       /* write the recovery data to the recovery area */
+       if (methods->tdb_write(tdb, recovery_offset, data, sizeof(*rec) + recovery_size) == -1) {
+               TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_setup_recovery: failed to write recovery data\n"));
+               free(data);
+               tdb->ecode = TDB_ERR_IO;
+               return -1;
+       }
+       if (transaction_write_existing(tdb, recovery_offset, data, sizeof(*rec) + recovery_size) == -1) {
+               TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_setup_recovery: failed to write secondary recovery data\n"));
+               free(data);
+               tdb->ecode = TDB_ERR_IO;
+               return -1;
+       }
+
+       /* as we don't have ordered writes, we have to sync the recovery
+          data before we update the magic to indicate that the recovery
+          data is present */
+       if (transaction_sync(tdb, recovery_offset, sizeof(*rec) + recovery_size) == -1) {
+               free(data);
+               return -1;
+       }
+
+       free(data);
+
+       magic = TDB_RECOVERY_MAGIC;
+       CONVERT(magic);
+
+       *magic_offset = recovery_offset + offsetof(struct tdb_record, magic);
+
+       if (methods->tdb_write(tdb, *magic_offset, &magic, sizeof(magic)) == -1) {
+               TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_setup_recovery: failed to write recovery magic\n"));
+               tdb->ecode = TDB_ERR_IO;
+               return -1;
+       }
+       if (transaction_write_existing(tdb, *magic_offset, &magic, sizeof(magic)) == -1) {
+               TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_setup_recovery: failed to write secondary recovery magic\n"));
+               tdb->ecode = TDB_ERR_IO;
+               return -1;
+       }
+
+       /* ensure the recovery magic marker is on disk */
+       if (transaction_sync(tdb, *magic_offset, sizeof(magic)) == -1) {
+               return -1;
+       }
+
+       return 0;
+}
+
+static int _tdb_transaction_prepare_commit(struct tdb_context *tdb)
+{      
+       const struct tdb_methods *methods;
+
+       if (tdb->transaction == NULL) {
+               TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_prepare_commit: no transaction\n"));
+               return -1;
+       }
+
+       if (tdb->transaction->prepared) {
+               tdb->ecode = TDB_ERR_EINVAL;
+               _tdb_transaction_cancel(tdb);
+               TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_prepare_commit: transaction already prepared\n"));
+               return -1;
+       }
+
+       if (tdb->transaction->transaction_error) {
+               tdb->ecode = TDB_ERR_IO;
+               _tdb_transaction_cancel(tdb);
+               TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_prepare_commit: transaction error pending\n"));
+               return -1;
+       }
+
+
+       if (tdb->transaction->nesting != 0) {
+               return 0;
+       }               
+
+       /* check for a null transaction */
+       if (tdb->transaction->blocks == NULL) {
+               return 0;
+       }
+
+       methods = tdb->transaction->io_methods;
+       
+       /* if there are any locks pending then the caller has not
+          nested their locks properly, so fail the transaction */
+       if (tdb->num_locks || tdb->global_lock.count) {
+               tdb->ecode = TDB_ERR_LOCK;
+               TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_prepare_commit: locks pending on commit\n"));
+               _tdb_transaction_cancel(tdb);
+               return -1;
+       }
+
+       /* upgrade the main transaction lock region to a write lock */
+       if (tdb_brlock_upgrade(tdb, FREELIST_TOP, 0) == -1) {
+               TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_prepare_commit: failed to upgrade hash locks\n"));
+               tdb->ecode = TDB_ERR_LOCK;
+               _tdb_transaction_cancel(tdb);
+               return -1;
+       }
+
+       /* get the global lock - this prevents new users attaching to the database
+          during the commit */
+       if (tdb_brlock(tdb, GLOBAL_LOCK, F_WRLCK, F_SETLKW, 0, 1) == -1) {
+               TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_prepare_commit: failed to get global lock\n"));
+               tdb->ecode = TDB_ERR_LOCK;
+               _tdb_transaction_cancel(tdb);
+               return -1;
+       }
+
+       tdb->transaction->global_lock_taken = true;
+
+       if (!(tdb->flags & TDB_NOSYNC)) {
+               /* write the recovery data to the end of the file */
+               if (transaction_setup_recovery(tdb, &tdb->transaction->magic_offset) == -1) {
+                       TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_prepare_commit: failed to setup recovery data\n"));
+                       _tdb_transaction_cancel(tdb);
+                       return -1;
+               }
+       }
+
+       tdb->transaction->prepared = true;
+
+       /* expand the file to the new size if needed */
+       if (tdb->map_size != tdb->transaction->old_map_size) {
+               if (methods->tdb_expand_file(tdb, tdb->transaction->old_map_size, 
+                                            tdb->map_size - 
+                                            tdb->transaction->old_map_size) == -1) {
+                       tdb->ecode = TDB_ERR_IO;
+                       TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_prepare_commit: expansion failed\n"));
+                       _tdb_transaction_cancel(tdb);
+                       return -1;
+               }
+               tdb->map_size = tdb->transaction->old_map_size;
+               methods->tdb_oob(tdb, tdb->map_size + 1, 1);
+       }
+
+       /* Keep the global lock until the actual commit */
+
+       return 0;
+}
+
+/*
+   prepare to commit the current transaction
+*/
+int tdb_transaction_prepare_commit(struct tdb_context *tdb)
+{      
+       tdb_trace(tdb, "tdb_transaction_prepare_commit");
+       return _tdb_transaction_prepare_commit(tdb);
+}
+
+/*
+  commit the current transaction
+*/
+int tdb_transaction_commit(struct tdb_context *tdb)
+{      
+       const struct tdb_methods *methods;
+       int i;
+       bool need_repack;
+
+       if (tdb->transaction == NULL) {
+               TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_commit: no transaction\n"));
+               return -1;
+       }
+
+       tdb_trace(tdb, "tdb_transaction_commit");
+
+       if (tdb->transaction->transaction_error) {
+               tdb->ecode = TDB_ERR_IO;
+               _tdb_transaction_cancel(tdb);
+               TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_commit: transaction error pending\n"));
+               return -1;
+       }
+
+
+       if (tdb->transaction->nesting != 0) {
+               tdb->transaction->nesting--;
+               return 0;
+       }
+
+       /* check for a null transaction */
+       if (tdb->transaction->blocks == NULL) {
+               _tdb_transaction_cancel(tdb);
+               return 0;
+       }
+
+       if (!tdb->transaction->prepared) {
+               int ret = _tdb_transaction_prepare_commit(tdb);
+               if (ret)
+                       return ret;
+       }
+
+       methods = tdb->transaction->io_methods;
+
+       /* perform all the writes */
+       for (i=0;i<tdb->transaction->num_blocks;i++) {
+               tdb_off_t offset;
+               tdb_len_t length;
+
+               if (tdb->transaction->blocks[i] == NULL) {
+                       continue;
+               }
+
+               offset = i * tdb->transaction->block_size;
+               length = tdb->transaction->block_size;
+               if (i == tdb->transaction->num_blocks-1) {
+                       length = tdb->transaction->last_block_size;
+               }
+
+               if (methods->tdb_write(tdb, offset, tdb->transaction->blocks[i], length) == -1) {
+                       TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_commit: write failed during commit\n"));
+                       
+                       /* we've overwritten part of the data and
+                          possibly expanded the file, so we need to
+                          run the crash recovery code */
+                       tdb->methods = methods;
+                       tdb_transaction_recover(tdb); 
+
+                       _tdb_transaction_cancel(tdb);
+
+                       TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_commit: write failed\n"));
+                       return -1;
+               }
+               SAFE_FREE(tdb->transaction->blocks[i]);
+       } 
+
+       SAFE_FREE(tdb->transaction->blocks);
+       tdb->transaction->num_blocks = 0;
+
+       /* ensure the new data is on disk */
+       if (transaction_sync(tdb, 0, tdb->map_size) == -1) {
+               return -1;
+       }
+
+       /*
+         TODO: maybe write to some dummy hdr field, or write to magic
+         offset without mmap, before the last sync, instead of the
+         utime() call
+       */
+
+       /* on some systems (like Linux 2.6.x) changes via mmap/msync
+          don't change the mtime of the file, this means the file may
+          not be backed up (as tdb rounding to block sizes means that
+          file size changes are quite rare too). The following forces
+          mtime changes when a transaction completes */
+#ifdef HAVE_UTIME
+       utime(tdb->name, NULL);
+#endif
+
+       need_repack = tdb->transaction->need_repack;
+
+       /* use a transaction cancel to free memory and remove the
+          transaction locks */
+       _tdb_transaction_cancel(tdb);
+
+       if (need_repack) {
+               return tdb_repack(tdb);
+       }
+
+       return 0;
+}
+
+
+/*
+  recover from an aborted transaction. Must be called with exclusive
+  database write access already established (including the global
+  lock to prevent new processes attaching)
+*/
+int tdb_transaction_recover(struct tdb_context *tdb)
+{
+       tdb_off_t recovery_head, recovery_eof;
+       unsigned char *data, *p;
+       uint32_t zero = 0;
+       struct tdb_record rec;
+
+       /* find the recovery area */
+       if (tdb_ofs_read(tdb, TDB_RECOVERY_HEAD, &recovery_head) == -1) {
+               TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: failed to read recovery head\n"));
+               tdb->ecode = TDB_ERR_IO;
+               return -1;
+       }
+
+       if (recovery_head == 0) {
+               /* we have never allocated a recovery record */
+               return 0;
+       }
+
+       /* read the recovery record */
+       if (tdb->methods->tdb_read(tdb, recovery_head, &rec, 
+                                  sizeof(rec), DOCONV()) == -1) {
+               TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: failed to read recovery record\n"));           
+               tdb->ecode = TDB_ERR_IO;
+               return -1;
+       }
+
+       if (rec.magic != TDB_RECOVERY_MAGIC) {
+               /* there is no valid recovery data */
+               return 0;
+       }
+
+       if (tdb->read_only) {
+               TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: attempt to recover read only database\n"));
+               tdb->ecode = TDB_ERR_CORRUPT;
+               return -1;
+       }
+
+       recovery_eof = rec.key_len;
+
+       data = (unsigned char *)malloc(rec.data_len);
+       if (data == NULL) {
+               TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: failed to allocate recovery data\n"));         
+               tdb->ecode = TDB_ERR_OOM;
+               return -1;
+       }
+
+       /* read the full recovery data */
+       if (tdb->methods->tdb_read(tdb, recovery_head + sizeof(rec), data,
+                                  rec.data_len, 0) == -1) {
+               TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: failed to read recovery data\n"));             
+               tdb->ecode = TDB_ERR_IO;
+               return -1;
+       }
+
+       /* recover the file data */
+       p = data;
+       while (p+8 < data + rec.data_len) {
+               uint32_t ofs, len;
+               if (DOCONV()) {
+                       tdb_convert(p, 8);
+               }
+               memcpy(&ofs, p, 4);
+               memcpy(&len, p+4, 4);
+
+               if (tdb->methods->tdb_write(tdb, ofs, p+8, len) == -1) {
+                       free(data);
+                       TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: failed to recover %d bytes at offset %d\n", len, ofs));
+                       tdb->ecode = TDB_ERR_IO;
+                       return -1;
+               }
+               p += 8 + len;
+       }
+
+       free(data);
+
+       if (transaction_sync(tdb, 0, tdb->map_size) == -1) {
+               TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: failed to sync recovery\n"));
+               tdb->ecode = TDB_ERR_IO;
+               return -1;
+       }
+
+       /* if the recovery area is after the recovered eof then remove it */
+       if (recovery_eof <= recovery_head) {
+               if (tdb_ofs_write(tdb, TDB_RECOVERY_HEAD, &zero) == -1) {
+                       TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: failed to remove recovery head\n"));
+                       tdb->ecode = TDB_ERR_IO;
+                       return -1;                      
+               }
+       }
+
+       /* remove the recovery magic */
+       if (tdb_ofs_write(tdb, recovery_head + offsetof(struct tdb_record, magic),
+                         &zero) == -1) {
+               TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: failed to remove recovery magic\n"));
+               tdb->ecode = TDB_ERR_IO;
+               return -1;                      
+       }
+       
+       /* reduce the file size to the old size */
+       tdb_munmap(tdb);
+       if (ftruncate(tdb->fd, recovery_eof) != 0) {
+               TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: failed to reduce to recovery size\n"));
+               tdb->ecode = TDB_ERR_IO;
+               return -1;                      
+       }
+       tdb->map_size = recovery_eof;
+       tdb_mmap(tdb);
+
+       if (transaction_sync(tdb, 0, recovery_eof) == -1) {
+               TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: failed to sync2 recovery\n"));
+               tdb->ecode = TDB_ERR_IO;
+               return -1;
+       }
+
+       TDB_LOG((tdb, TDB_DEBUG_TRACE, "tdb_transaction_recover: recovered %d byte database\n", 
+                recovery_eof));
+
+       /* all done */
+       return 0;
+}
diff --git a/libatalk/tdb/traverse.c b/libatalk/tdb/traverse.c
new file mode 100644 (file)
index 0000000..c340dd3
--- /dev/null
@@ -0,0 +1,366 @@
+ /* 
+   Unix SMB/CIFS implementation.
+
+   trivial database library
+
+   Copyright (C) Andrew Tridgell              1999-2005
+   Copyright (C) Paul `Rusty' Russell             2000
+   Copyright (C) Jeremy Allison                           2000-2003
+   
+     ** NOTE! The following LGPL license applies to the tdb
+     ** library. This does NOT imply that all of Samba is released
+     ** under the LGPL
+   
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "tdb_private.h"
+
+#define TDB_NEXT_LOCK_ERR ((tdb_off_t)-1)
+
+/* Uses traverse lock: 0 = finish, TDB_NEXT_LOCK_ERR = error,
+   other = record offset */
+static tdb_off_t tdb_next_lock(struct tdb_context *tdb, struct tdb_traverse_lock *tlock,
+                        struct tdb_record *rec)
+{
+       int want_next = (tlock->off != 0);
+
+       /* Lock each chain from the start one. */
+       for (; tlock->hash < tdb->header.hash_size; tlock->hash++) {
+               if (!tlock->off && tlock->hash != 0) {
+                       /* this is an optimisation for the common case where
+                          the hash chain is empty, which is particularly
+                          common for the use of tdb with ldb, where large
+                          hashes are used. In that case we spend most of our
+                          time in tdb_brlock(), locking empty hash chains.
+                          
+                          To avoid this, we do an unlocked pre-check to see
+                          if the hash chain is empty before starting to look
+                          inside it. If it is empty then we can avoid that
+                          hash chain. If it isn't empty then we can't believe
+                          the value we get back, as we read it without a
+                          lock, so instead we get the lock and re-fetch the
+                          value below.
+                          
+                          Notice that not doing this optimisation on the
+                          first hash chain is critical. We must guarantee
+                          that we have done at least one fcntl lock at the
+                          start of a search to guarantee that memory is
+                          coherent on SMP systems. If records are added by
+                          others during the search then thats OK, and we
+                          could possibly miss those with this trick, but we
+                          could miss them anyway without this trick, so the
+                          semantics don't change.
+                          
+                          With a non-indexed ldb search this trick gains us a
+                          factor of around 80 in speed on a linux 2.6.x
+                          system (testing using ldbtest).
+                       */
+                       tdb->methods->next_hash_chain(tdb, &tlock->hash);
+                       if (tlock->hash == tdb->header.hash_size) {
+                               continue;
+                       }
+               }
+
+               if (tdb_lock(tdb, tlock->hash, tlock->lock_rw) == -1)
+                       return TDB_NEXT_LOCK_ERR;
+
+               /* No previous record?  Start at top of chain. */
+               if (!tlock->off) {
+                       if (tdb_ofs_read(tdb, TDB_HASH_TOP(tlock->hash),
+                                    &tlock->off) == -1)
+                               goto fail;
+               } else {
+                       /* Otherwise unlock the previous record. */
+                       if (tdb_unlock_record(tdb, tlock->off) != 0)
+                               goto fail;
+               }
+
+               if (want_next) {
+                       /* We have offset of old record: grab next */
+                       if (tdb_rec_read(tdb, tlock->off, rec) == -1)
+                               goto fail;
+                       tlock->off = rec->next;
+               }
+
+               /* Iterate through chain */
+               while( tlock->off) {
+                       tdb_off_t current;
+                       if (tdb_rec_read(tdb, tlock->off, rec) == -1)
+                               goto fail;
+
+                       /* Detect infinite loops. From "Shlomi Yaakobovich" <Shlomi@exanet.com>. */
+                       if (tlock->off == rec->next) {
+                               tdb->ecode = TDB_ERR_CORRUPT;
+                               TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_next_lock: loop detected.\n"));
+                               goto fail;
+                       }
+
+                       if (!TDB_DEAD(rec)) {
+                               /* Woohoo: we found one! */
+                               if (tdb_lock_record(tdb, tlock->off) != 0)
+                                       goto fail;
+                               return tlock->off;
+                       }
+
+                       /* Try to clean dead ones from old traverses */
+                       current = tlock->off;
+                       tlock->off = rec->next;
+                       if (!(tdb->read_only || tdb->traverse_read) && 
+                           tdb_do_delete(tdb, current, rec) != 0)
+                               goto fail;
+               }
+               tdb_unlock(tdb, tlock->hash, tlock->lock_rw);
+               want_next = 0;
+       }
+       /* We finished iteration without finding anything */
+       tdb->ecode = TDB_SUCCESS;
+       return 0;
+
+ fail:
+       tlock->off = 0;
+       if (tdb_unlock(tdb, tlock->hash, tlock->lock_rw) != 0)
+               TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_next_lock: On error unlock failed!\n"));
+       return TDB_NEXT_LOCK_ERR;
+}
+
+/* traverse the entire database - calling fn(tdb, key, data) on each element.
+   return -1 on error or the record count traversed
+   if fn is NULL then it is not called
+   a non-zero return value from fn() indicates that the traversal should stop
+  */
+static int tdb_traverse_internal(struct tdb_context *tdb, 
+                                tdb_traverse_func fn, void *private_data,
+                                struct tdb_traverse_lock *tl)
+{
+       TDB_DATA key, dbuf;
+       struct tdb_record rec;
+       int ret = 0, count = 0;
+       tdb_off_t off;
+
+       /* This was in the initializaton, above, but the IRIX compiler
+        * did not like it.  crh
+        */
+       tl->next = tdb->travlocks.next;
+
+       /* fcntl locks don't stack: beware traverse inside traverse */
+       tdb->travlocks.next = tl;
+
+       /* tdb_next_lock places locks on the record returned, and its chain */
+       while ((off = tdb_next_lock(tdb, tl, &rec)) != 0) {
+               if (off == TDB_NEXT_LOCK_ERR) {
+                       ret = -1;
+                       goto out;
+               }
+               count++;
+               /* now read the full record */
+               key.dptr = tdb_alloc_read(tdb, tl->off + sizeof(rec), 
+                                         rec.key_len + rec.data_len);
+               if (!key.dptr) {
+                       ret = -1;
+                       if (tdb_unlock(tdb, tl->hash, tl->lock_rw) != 0)
+                               goto out;
+                       if (tdb_unlock_record(tdb, tl->off) != 0)
+                               TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_traverse: key.dptr == NULL and unlock_record failed!\n"));
+                       goto out;
+               }
+               key.dsize = rec.key_len;
+               dbuf.dptr = key.dptr + rec.key_len;
+               dbuf.dsize = rec.data_len;
+
+               tdb_trace_1rec_retrec(tdb, "traverse", key, dbuf);
+
+               /* Drop chain lock, call out */
+               if (tdb_unlock(tdb, tl->hash, tl->lock_rw) != 0) {
+                       ret = -1;
+                       SAFE_FREE(key.dptr);
+                       goto out;
+               }
+               if (fn && fn(tdb, key, dbuf, private_data)) {
+                       /* They want us to terminate traversal */
+                       tdb_trace_ret(tdb, "tdb_traverse_end", count);
+                       if (tdb_unlock_record(tdb, tl->off) != 0) {
+                               TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_traverse: unlock_record failed!\n"));;
+                               ret = -1;
+                       }
+                       SAFE_FREE(key.dptr);
+                       goto out;
+               }
+               SAFE_FREE(key.dptr);
+       }
+       tdb_trace(tdb, "tdb_traverse_end");
+out:
+       tdb->travlocks.next = tl->next;
+       if (ret < 0)
+               return -1;
+       else
+               return count;
+}
+
+
+/*
+  a write style traverse - temporarily marks the db read only
+*/
+int tdb_traverse_read(struct tdb_context *tdb, 
+                     tdb_traverse_func fn, void *private_data)
+{
+       struct tdb_traverse_lock tl = { NULL, 0, 0, F_RDLCK };
+       int ret;
+
+       /* we need to get a read lock on the transaction lock here to
+          cope with the lock ordering semantics of solaris10 */
+       if (tdb_transaction_lock(tdb, F_RDLCK)) {
+               return -1;
+       }
+
+       tdb->traverse_read++;
+       tdb_trace(tdb, "tdb_traverse_read_start");
+       ret = tdb_traverse_internal(tdb, fn, private_data, &tl);
+       tdb->traverse_read--;
+
+       tdb_transaction_unlock(tdb);
+
+       return ret;
+}
+
+/*
+  a write style traverse - needs to get the transaction lock to
+  prevent deadlocks
+
+  WARNING: The data buffer given to the callback fn does NOT meet the
+  alignment restrictions malloc gives you.
+*/
+int tdb_traverse(struct tdb_context *tdb, 
+                tdb_traverse_func fn, void *private_data)
+{
+       struct tdb_traverse_lock tl = { NULL, 0, 0, F_WRLCK };
+       int ret;
+
+       if (tdb->read_only || tdb->traverse_read) {
+               return tdb_traverse_read(tdb, fn, private_data);
+       }
+
+       if (tdb_transaction_lock(tdb, F_WRLCK)) {
+               return -1;
+       }
+
+       tdb->traverse_write++;
+       tdb_trace(tdb, "tdb_traverse_start");
+       ret = tdb_traverse_internal(tdb, fn, private_data, &tl);
+       tdb->traverse_write--;
+
+       tdb_transaction_unlock(tdb);
+
+       return ret;
+}
+
+
+/* find the first entry in the database and return its key */
+TDB_DATA tdb_firstkey(struct tdb_context *tdb)
+{
+       TDB_DATA key;
+       struct tdb_record rec;
+       tdb_off_t off;
+
+       /* release any old lock */
+       if (tdb_unlock_record(tdb, tdb->travlocks.off) != 0)
+               return tdb_null;
+       tdb->travlocks.off = tdb->travlocks.hash = 0;
+       tdb->travlocks.lock_rw = F_RDLCK;
+
+       /* Grab first record: locks chain and returned record. */
+       off = tdb_next_lock(tdb, &tdb->travlocks, &rec);
+       if (off == 0 || off == TDB_NEXT_LOCK_ERR) {
+               tdb_trace_retrec(tdb, "tdb_firstkey", tdb_null);
+               return tdb_null;
+       }
+       /* now read the key */
+       key.dsize = rec.key_len;
+       key.dptr =tdb_alloc_read(tdb,tdb->travlocks.off+sizeof(rec),key.dsize);
+
+       tdb_trace_retrec(tdb, "tdb_firstkey", key);
+
+       /* Unlock the hash chain of the record we just read. */
+       if (tdb_unlock(tdb, tdb->travlocks.hash, tdb->travlocks.lock_rw) != 0)
+               TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_firstkey: error occurred while tdb_unlocking!\n"));
+       return key;
+}
+
+/* find the next entry in the database, returning its key */
+TDB_DATA tdb_nextkey(struct tdb_context *tdb, TDB_DATA oldkey)
+{
+       uint32_t oldhash;
+       TDB_DATA key = tdb_null;
+       struct tdb_record rec;
+       unsigned char *k = NULL;
+       tdb_off_t off;
+
+       /* Is locked key the old key?  If so, traverse will be reliable. */
+       if (tdb->travlocks.off) {
+               if (tdb_lock(tdb,tdb->travlocks.hash,tdb->travlocks.lock_rw))
+                       return tdb_null;
+               if (tdb_rec_read(tdb, tdb->travlocks.off, &rec) == -1
+                   || !(k = tdb_alloc_read(tdb,tdb->travlocks.off+sizeof(rec),
+                                           rec.key_len))
+                   || memcmp(k, oldkey.dptr, oldkey.dsize) != 0) {
+                       /* No, it wasn't: unlock it and start from scratch */
+                       if (tdb_unlock_record(tdb, tdb->travlocks.off) != 0) {
+                               tdb_trace_1rec_retrec(tdb, "tdb_nextkey",
+                                                     oldkey, tdb_null);
+                               SAFE_FREE(k);
+                               return tdb_null;
+                       }
+                       if (tdb_unlock(tdb, tdb->travlocks.hash, tdb->travlocks.lock_rw) != 0) {
+                               SAFE_FREE(k);
+                               return tdb_null;
+                       }
+                       tdb->travlocks.off = 0;
+               }
+
+               SAFE_FREE(k);
+       }
+
+       if (!tdb->travlocks.off) {
+               /* No previous element: do normal find, and lock record */
+               tdb->travlocks.off = tdb_find_lock_hash(tdb, oldkey, tdb->hash_fn(&oldkey), tdb->travlocks.lock_rw, &rec);
+               if (!tdb->travlocks.off) {
+                       tdb_trace_1rec_retrec(tdb, "tdb_nextkey", oldkey, tdb_null);
+                       return tdb_null;
+               }
+               tdb->travlocks.hash = BUCKET(rec.full_hash);
+               if (tdb_lock_record(tdb, tdb->travlocks.off) != 0) {
+                       TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_nextkey: lock_record failed (%s)!\n", strerror(errno)));
+                       return tdb_null;
+               }
+       }
+       oldhash = tdb->travlocks.hash;
+
+       /* Grab next record: locks chain and returned record,
+          unlocks old record */
+       off = tdb_next_lock(tdb, &tdb->travlocks, &rec);
+       if (off != TDB_NEXT_LOCK_ERR && off != 0) {
+               key.dsize = rec.key_len;
+               key.dptr = tdb_alloc_read(tdb, tdb->travlocks.off+sizeof(rec),
+                                         key.dsize);
+               /* Unlock the chain of this new record */
+               if (tdb_unlock(tdb, tdb->travlocks.hash, tdb->travlocks.lock_rw) != 0)
+                       TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_nextkey: WARNING tdb_unlock failed!\n"));
+       }
+       /* Unlock the chain of old record */
+       if (tdb_unlock(tdb, BUCKET(oldhash), tdb->travlocks.lock_rw) != 0)
+               TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_nextkey: WARNING tdb_unlock failed!\n"));
+       tdb_trace_1rec_retrec(tdb, "tdb_nextkey", oldkey, key);
+       return key;
+}
+
index 3cf3dccf4b84c5a6f10ec5cc8a0095fa29039399..cc9a7f02a12bf580216e05fda91ec0c666b3c5f2 100644 (file)
@@ -20,7 +20,7 @@
 
 #ifndef _BYTEORDER_H
 #define _BYTEORDER_H
-#include <netatalk/endian.h>
+#include <arpa/inet.h>
 
 /*
    This file implements macros for machine independent short and 
@@ -122,8 +122,8 @@ it also defines lots of intermediate macros, just ignore those :-)
 #define SIVALX(buf,pos,val) (SSVALX(buf,pos,val&0xFFFF),SSVALX(buf,pos+2,val>>16))
 #define SVALS(buf,pos) ((int16)SVAL(buf,pos))
 #define IVALS(buf,pos) ((int32_t)IVAL(buf,pos))
-#define SSVAL(buf,pos,val) SSVALX((buf),(pos),((u_int16_t)(val)))
-#define SIVAL(buf,pos,val) SIVALX((buf),(pos),((u_int32_t)(val)))
+#define SSVAL(buf,pos,val) SSVALX((buf),(pos),((uint16_t)(val)))
+#define SIVAL(buf,pos,val) SIVALX((buf),(pos),((uint32_t)(val)))
 #define SSVALS(buf,pos,val) SSVALX((buf),(pos),((int16)(val)))
 #define SIVALS(buf,pos,val) SIVALX((buf),(pos),((int32_t)(val)))
 
@@ -135,8 +135,8 @@ it also defines lots of intermediate macros, just ignore those :-)
 #define SIVALX(buf,pos,val) (SSVALX(buf,pos,val&0xFFFF),SSVALX(buf,pos+2,val>>16))
 #define SVALS(buf,pos) ((int16)SVAL(buf,pos))
 #define IVALS(buf,pos) ((int32_t)IVAL(buf,pos))
-#define SSVAL(buf,pos,val) SSVALX((buf),(pos),((u_int16_t)(val)))
-#define SIVAL(buf,pos,val) SIVALX((buf),(pos),((u_int32_t)(val)))
+#define SSVAL(buf,pos,val) SSVALX((buf),(pos),((uint16_t)(val)))
+#define SIVAL(buf,pos,val) SIVALX((buf),(pos),((uint32_t)(val)))
 #define SSVALS(buf,pos,val) SSVALX((buf),(pos),((int16)(val)))
 #define SIVALS(buf,pos,val) SIVALX((buf),(pos),((int32_t)(val)))
 
@@ -152,18 +152,18 @@ it also defines lots of intermediate macros, just ignore those :-)
 */
 
 /* get single value from an SMB buffer */
-#define SVAL(buf,pos) (*(const u_int16_t *)((const char *)(buf) + (pos)))
-#define SVAL_NC(buf,pos) (*(u_int16_t *)((char *)(buf) + (pos))) /* Non const version of above. */
-#define IVAL(buf,pos) (*(const u_int32_t *)((const char *)(buf) + (pos)))
-#define IVAL_NC(buf,pos) (*(u_int32_t *)((char *)(buf) + (pos))) /* Non const version of above. */
+#define SVAL(buf,pos) (*(const uint16_t *)((const char *)(buf) + (pos)))
+#define SVAL_NC(buf,pos) (*(uint16_t *)((char *)(buf) + (pos))) /* Non const version of above. */
+#define IVAL(buf,pos) (*(const uint32_t *)((const char *)(buf) + (pos)))
+#define IVAL_NC(buf,pos) (*(uint32_t *)((char *)(buf) + (pos))) /* Non const version of above. */
 #define SVALS(buf,pos) (*(const int16_t *)((const char *)(buf) + (pos)))
 #define SVALS_NC(buf,pos) (*(int16 *)((char *)(buf) + (pos))) /* Non const version of above. */
 #define IVALS(buf,pos) (*(const int32_t *)((const char *)(buf) + (pos)))
 #define IVALS_NC(buf,pos) (*(int32_t *)((char *)(buf) + (pos))) /* Non const version of above. */
 
 /* store single value in an SMB buffer */
-#define SSVAL(buf,pos,val) SVAL_NC(buf,pos)=((u_int16_t)(val))
-#define SIVAL(buf,pos,val) IVAL_NC(buf,pos)=((u_int32_t)(val))
+#define SSVAL(buf,pos,val) SVAL_NC(buf,pos)=((uint16_t)(val))
+#define SIVAL(buf,pos,val) IVAL_NC(buf,pos)=((uint32_t)(val))
 #define SSVALS(buf,pos,val) SVALS_NC(buf,pos)=((int16)(val))
 #define SIVALS(buf,pos,val) IVALS_NC(buf,pos)=((int32_t)(val))
 
index 98e8ffccd53b28905f752591777d292725dc7ec8..7859a228ea1f9756b4a6c5fd72dc585eeff1aadf 100644 (file)
 #if HAVE_LANGINFO_H
 #include <langinfo.h>
 #endif
+#include <arpa/inet.h>
 
-#include <netatalk/endian.h>
 #include <atalk/logger.h>
 #include <atalk/unicode.h>
 #include <atalk/util.h>
+#include <atalk/compat.h>
+
 #include "byteorder.h"
 
 
@@ -139,13 +141,11 @@ static const char *charset_name(charset_t ch)
     if (!ret)
         ret = charset_names[ch];
 
-#if defined(HAVE_NL_LANGINFO) && defined(CODESET)
+#if defined(CODESET)
     if (ret && strcasecmp(ret, "LOCALE") == 0) {
         const char *ln = NULL;
 
-#ifdef HAVE_SETLOCALE
         setlocale(LC_ALL, "");
-#endif
         ln = nl_langinfo(CODESET);
         if (ln) {
             /* Check whether the charset name is supported
@@ -768,9 +768,9 @@ char * debug_out ( char * seq, size_t len)
  *      for e.g. HFS cdroms.
  */
 
-static size_t pull_charset_flags (charset_t from_set, charset_t cap_set, const char *src, size_t srclen, char* dest, size_t destlen, u_int16_t *flags)
+static size_t pull_charset_flags (charset_t from_set, charset_t cap_set, const char *src, size_t srclen, char* dest, size_t destlen, uint16_t *flags)
 {
-    const u_int16_t option = (flags ? *flags : 0);
+    const uint16_t option = (flags ? *flags : 0);
     size_t i_len, o_len;
     size_t j = 0;
     const char* inbuf = (const char*)src;
@@ -880,9 +880,9 @@ end:
  */
 
 
-static size_t push_charset_flags (charset_t to_set, charset_t cap_set, char* src, size_t srclen, char* dest, size_t destlen, u_int16_t *flags)
+static size_t push_charset_flags (charset_t to_set, charset_t cap_set, char* src, size_t srclen, char* dest, size_t destlen, uint16_t *flags)
 {
-    const u_int16_t option = (flags ? *flags : 0);
+    const uint16_t option = (flags ? *flags : 0);
     size_t i_len, o_len, i;
     size_t j = 0;
     const char* inbuf = (const char*)src;
@@ -1029,7 +1029,7 @@ end:
  * FIXME the size is a mess we really need a malloc/free logic
  *`dest size must be dest_len +2
  */
-size_t convert_charset ( charset_t from_set, charset_t to_set, charset_t cap_charset, const char *src, size_t src_len, char *dest, size_t dest_len, u_int16_t *flags)
+size_t convert_charset ( charset_t from_set, charset_t to_set, charset_t cap_charset, const char *src, size_t src_len, char *dest, size_t dest_len, uint16_t *flags)
 {
     size_t i_len, o_len;
     ucs2_t *u;
index 29358a8c8da043f5235c0d92e65dc0a702b6d9ba..461af345ff65ae1cd55b0a6b4563495f47c5d912 100644 (file)
@@ -36,14 +36,14 @@ static size_t cjk_iconv(void *cd, char **inbuf, char *end,
   return n;
 }
 
-size_t cjk_generic_push(size_t (*char_func)(u_int8_t*, const ucs2_t*, size_t*),
+size_t cjk_generic_push(size_t (*char_func)(uint8_t*, const ucs2_t*, size_t*),
                        void *cd, char **inbuf, size_t *inbytesleft,
                        char **outbuf, size_t *outbytesleft)
 {
   char *in = *inbuf;
 
   while (*inbytesleft >= sizeof(ucs2_t) && *outbytesleft > 0) {
-    u_int8_t buf[CJK_PUSH_BUFFER];
+    uint8_t buf[CJK_PUSH_BUFFER];
     size_t size = *inbytesleft / sizeof(ucs2_t);
     size_t n = (char_func)(buf, (const ucs2_t*)in, &size);
     if (n == 0) {
@@ -78,7 +78,7 @@ size_t cjk_generic_push(size_t (*char_func)(u_int8_t*, const ucs2_t*, size_t*),
   return 0;
 }
 
-size_t cjk_generic_pull(size_t (*char_func)(ucs2_t*, const u_int8_t*, size_t*),
+size_t cjk_generic_pull(size_t (*char_func)(ucs2_t*, const uint8_t*, size_t*),
                        void *cd, char **inbuf, size_t *inbytesleft,
                        char **outbuf, size_t *outbytesleft)
 {
@@ -87,7 +87,7 @@ size_t cjk_generic_pull(size_t (*char_func)(ucs2_t*, const u_int8_t*, size_t*),
   while (*inbytesleft > 0 && *outbytesleft >= sizeof(ucs2_t)) {
     ucs2_t buf[CJK_PULL_BUFFER];
     size_t size = *inbytesleft;
-    size_t n = (char_func)(buf, (const u_int8_t*)in, &size);
+    size_t n = (char_func)(buf, (const uint8_t*)in, &size);
     if (n == 0) {
       in += size;
       *inbytesleft -= size;
@@ -120,30 +120,30 @@ size_t cjk_generic_pull(size_t (*char_func)(ucs2_t*, const u_int8_t*, size_t*),
   return 0;
 }
 
-size_t cjk_char_push(u_int16_t c, u_int8_t *out)
+size_t cjk_char_push(uint16_t c, uint8_t *out)
 {
   if (!c) return 0;
-  if (c == (u_int16_t)-1) {
+  if (c == (uint16_t)-1) {
     errno = EILSEQ;
     return (size_t)-1;
   }
   if (c <= 0xff) {
-    out[0] = (u_int8_t)c;
+    out[0] = (uint8_t)c;
     return 1;
   }
-  out[0] = (u_int8_t)(c >> 8);
-  out[1] = (u_int8_t)c;
+  out[0] = (uint8_t)(c >> 8);
+  out[1] = (uint8_t)c;
   return 2;
 }
 
-size_t cjk_char_pull(ucs2_t wc, ucs2_t* out, const u_int32_t* compose)
+size_t cjk_char_pull(ucs2_t wc, ucs2_t* out, const uint32_t* compose)
 {
   if (!wc) return 0;
   if ((wc & 0xf000) == 0xe000) {
     ucs2_t buf[CJK_PULL_BUFFER];
     size_t i = sizeof(buf) / sizeof(*buf) - 1;
     do {
-      u_int32_t v = compose[wc & 0xfff];
+      uint32_t v = compose[wc & 0xfff];
       buf[i] = (ucs2_t)v;
       wc = (ucs2_t)(v >> 16);
     } while (--i && (wc & 0xf000) == 0xe000);
@@ -155,12 +155,12 @@ size_t cjk_char_pull(ucs2_t wc, ucs2_t* out, const u_int32_t* compose)
   return 1;
 }
 
-u_int16_t cjk_lookup(u_int16_t c, const cjk_index_t *index, const u_int16_t *charset)
+uint16_t cjk_lookup(uint16_t c, const cjk_index_t *index, const uint16_t *charset)
 {
   while (index->summary && c >= index->range[0]) {
     if (c <= index->range[1]) {
-      const u_int16_t* summary = index->summary[(c - index->range[0]) >> 4];
-      u_int16_t used = 1 << (c & 15);
+      const uint16_t* summary = index->summary[(c - index->range[0]) >> 4];
+      uint16_t used = 1 << (c & 15);
 
       if (summary[0] & used) {
        used = summary[0] & (used - 1);
@@ -175,9 +175,9 @@ u_int16_t cjk_lookup(u_int16_t c, const cjk_index_t *index, const u_int16_t *cha
   return 0;
 }
 
-ucs2_t cjk_compose(ucs2_t base, ucs2_t comb, const u_int32_t* table, size_t size)
+ucs2_t cjk_compose(ucs2_t base, ucs2_t comb, const uint32_t* table, size_t size)
 {
-  u_int32_t v = ((u_int32_t)base << 16) | comb;
+  uint32_t v = ((uint32_t)base << 16) | comb;
   size_t low = 0;
   while (size > low) {
     size_t n = (low + size) / 2;
@@ -191,9 +191,9 @@ ucs2_t cjk_compose(ucs2_t base, ucs2_t comb, const u_int32_t* table, size_t size
   return 0;
 }
 
-ucs2_t cjk_compose_seq(const ucs2_t* in, size_t* len, const u_int32_t* table, size_t size)
+ucs2_t cjk_compose_seq(const ucs2_t* in, size_t* len, const uint32_t* table, size_t size)
 {
-  static u_int8_t sz[] = { 3, 4, 5, 5, 5, 5, 5, 3 };
+  static uint8_t sz[] = { 3, 4, 5, 5, 5, 5, 5, 3 };
   ucs2_t wc = in[0];
   size_t n = sz[wc & 7];
   size_t i = 0;
index 8c6cbaaf20a212e10ecaa9afdb8152982ba1e728..5dab15a6284a6ce323a245594a9498e90e2b2ebf 100644 (file)
 #define CJK_PULL_BUFFER 8
 
 typedef struct {
-  u_int16_t range[2];
-  const u_int16_t (*summary)[2];
+  uint16_t range[2];
+  const uint16_t (*summary)[2];
 } cjk_index_t;
 
-extern size_t cjk_generic_push (size_t (*)(u_int8_t*, const ucs2_t*, size_t*),
+extern size_t cjk_generic_push (size_t (*)(uint8_t*, const ucs2_t*, size_t*),
                                   void*, char**, size_t*, char**, size_t*);
-extern size_t cjk_generic_pull (size_t (*)(ucs2_t*, const u_int8_t*, size_t*),
+extern size_t cjk_generic_pull (size_t (*)(ucs2_t*, const uint8_t*, size_t*),
                                   void*, char**, size_t*, char**, size_t*);
 
-extern size_t cjk_char_push (u_int16_t, u_int8_t*);
-extern size_t cjk_char_pull (ucs2_t, ucs2_t*, const u_int32_t*);
+extern size_t cjk_char_push (uint16_t, uint8_t*);
+extern size_t cjk_char_pull (ucs2_t, ucs2_t*, const uint32_t*);
 
-extern u_int16_t cjk_lookup (u_int16_t, const cjk_index_t*, const u_int16_t*);
-extern ucs2_t cjk_compose (ucs2_t, ucs2_t, const u_int32_t*, size_t);
-extern ucs2_t cjk_compose_seq (const ucs2_t*, size_t*, const u_int32_t*, size_t);
+extern uint16_t cjk_lookup (uint16_t, const cjk_index_t*, const uint16_t*);
+extern ucs2_t cjk_compose (ucs2_t, ucs2_t, const uint32_t*, size_t);
+extern ucs2_t cjk_compose_seq (const ucs2_t*, size_t*, const uint32_t*, size_t);
index 0fc36b758cc544e94d269b34af4e3771b956bea7..7b36997d804a035a4f6b86f1d0686d95df9b6759 100644 (file)
@@ -31,8 +31,8 @@
 #include <unistd.h>
 #include <string.h>
 #include <errno.h>
+#include <arpa/inet.h>
 
-#include <netatalk/endian.h>
 #include <atalk/unicode.h>
 #include <atalk/logger.h>
 
index 3effc6856ca1b076021fd1f6a30226501475ee31..40784be3c5deb0e632cd9200b9936801dc056c0a 100644 (file)
@@ -28,7 +28,8 @@
 #include "config.h"
 #endif /* HAVE_CONFIG_H */
 #include <stdlib.h>
-#include <netatalk/endian.h>
+#include <arpa/inet.h>
+
 #include <atalk/unicode.h>
 
 #include "mac_centraleurope.h"
index f0ad4640af2af16e2b108084b593555aa49229b7..2ff6c2a069aa0f5a535d307d6a22b4c7d5ad37fd 100644 (file)
@@ -43,20 +43,20 @@ struct charset_functions charset_mac_chinese_simp = {
   NULL, NULL
 };
 
-static size_t mac_chinese_simp_char_push(u_int8_t* out, const ucs2_t* in, size_t* size)
+static size_t mac_chinese_simp_char_push(uint8_t* out, const ucs2_t* in, size_t* size)
 {
   ucs2_t wc = in[0];
 
   if (wc <= 0x7f) {
     *size = 1;
-    out[0] = (u_int8_t)wc;
+    out[0] = (uint8_t)wc;
     return 1;
   } else if ((wc & 0xf000) == 0xe000) {
     *size = 1;
     return 0;
   } else if (*size >= 2 && (in[1] & ~15) == 0xf870) {
     ucs2_t comp = cjk_compose(wc, in[1], mac_chinese_simp_compose,
-                             sizeof(mac_chinese_simp_compose) / sizeof(u_int32_t));
+                             sizeof(mac_chinese_simp_compose) / sizeof(uint32_t));
     if (comp) {
       wc = comp;
       *size = 2;
@@ -77,9 +77,9 @@ static size_t mac_chinese_simp_push(void *cd, char **inbuf, size_t *inbytesleft,
                          cd, inbuf, inbytesleft, outbuf, outbytesleft);
 }
 
-static size_t mac_chinese_simp_char_pull(ucs2_t* out, const u_int8_t* in, size_t* size)
+static size_t mac_chinese_simp_char_pull(ucs2_t* out, const uint8_t* in, size_t* size)
 {
-  u_int16_t c = in[0];
+  uint16_t c = in[0];
 
   if (c <= 0x7f) {
     *size = 1;
@@ -87,7 +87,7 @@ static size_t mac_chinese_simp_char_pull(ucs2_t* out, const u_int8_t* in, size_t
     return 1;
   } else if (c >= 0xa1 && c <= 0xfc) {
     if (*size >= 2) {
-      u_int8_t c2 = in[1];
+      uint8_t c2 = in[1];
 
       if (c2 >= 0xa1 && c2 <= 0xfe) {
        *size = 2;
index 9e7d8cea88a922d48b07f5f5f06a297aa0118b72..25216256639c9aad9b53d5c2ebfe33746f856357 100644 (file)
@@ -20,7 +20,7 @@
  * http://www.unicode.org/Public/MAPPINGS/VENDORS/APPLE/
  */
 
-static const u_int16_t mac_chinese_simp_uni2_page00[][2] = {
+static const uint16_t mac_chinese_simp_uni2_page00[][2] = {
   /* 0x00a */ { 0x022d,    0 }, { 0x0080,    5 },
   /* 0x00c */ { 0x0000,    0 }, { 0x0000,    0 }, { 0x0000,    0 }, { 0x0000,    0 },
   /* 0x010 */ { 0x0000,    0 }, { 0x0000,    0 }, { 0x0000,    0 }, { 0x0000,    0 },
@@ -31,42 +31,42 @@ static const u_int16_t mac_chinese_simp_uni2_page00[][2] = {
   /* 0x024 */ { 0x0000,    0 }, { 0x0002,    9 }, { 0x0002,   10 },
 };
 
-static const u_int16_t mac_chinese_simp_uni2_page1e[][2] = {
+static const uint16_t mac_chinese_simp_uni2_page1e[][2] = {
   /* 0x1e3 */ { 0x8000,   11 },
 };
 
-static const u_int16_t mac_chinese_simp_uni2_page20[][2] = {
+static const uint16_t mac_chinese_simp_uni2_page20[][2] = {
   /* 0x201 */ { 0x0070,   12 }, { 0x0040,   15 }, { 0x4000,   16 },
 };
 
-static const u_int16_t mac_chinese_simp_uni2_page21[][2] = {
+static const uint16_t mac_chinese_simp_uni2_page21[][2] = {
   /* 0x212 */ { 0x0004,   17 },
 };
 
-static const u_int16_t mac_chinese_simp_uni2_page22[][2] = {
+static const uint16_t mac_chinese_simp_uni2_page22[][2] = {
   /* 0x22e */ { 0x8000,   18 },
 };
 
-static const u_int16_t mac_chinese_simp_uni2_page30[][2] = {
+static const uint16_t mac_chinese_simp_uni2_page30[][2] = {
   /* 0x301 */ { 0x1000,   19 }, { 0x0000,    0 }, { 0x0000,    0 },
   /* 0x304 */ { 0x0000,    0 }, { 0x0000,    0 }, { 0x0000,    0 }, { 0x0000,    0 },
   /* 0x308 */ { 0x0000,    0 }, { 0x0000,    0 }, { 0x0000,    0 }, { 0x0000,    0 },
   /* 0x30c */ { 0x0000,    0 }, { 0x0000,    0 }, { 0x0000,    0 }, { 0x0800,   20 },
 };
 
-static const u_int16_t mac_chinese_simp_uni2_pagee0[][2] = {
+static const uint16_t mac_chinese_simp_uni2_pagee0[][2] = {
   /* 0xe00 */ { 0x07ff,   21 },
 };
 
-static const u_int16_t mac_chinese_simp_uni2_pagef8[][2] = {
+static const uint16_t mac_chinese_simp_uni2_pagef8[][2] = {
   /* 0xf88 */ { 0x0003,   32 },
 };
 
-static const u_int16_t mac_chinese_simp_uni2_pagefe[][2] = {
+static const uint16_t mac_chinese_simp_uni2_pagefe[][2] = {
   /* 0xfe3 */ { 0xfffa,   34 }, { 0x001f,   48 },
 };
 
-static const u_int16_t mac_chinese_simp_uni2_pageff[][2] = {
+static const uint16_t mac_chinese_simp_uni2_pageff[][2] = {
   /* 0xff5 */ { 0x4000,   53 }, { 0x0000,    0 }, { 0x0000,    0 },
   /* 0xff8 */ { 0x0000,    0 }, { 0x0000,    0 }, { 0x0000,    0 }, { 0x0000,    0 },
   /* 0xffc */ { 0x0000,    0 }, { 0x0000,    0 }, { 0x002b,   54 },
@@ -86,7 +86,7 @@ static const cjk_index_t mac_chinese_simp_uni2_index[] = {
   { { 0, 0 }, NULL }
 };
 
-static const u_int16_t mac_chinese_simp_uni2_charset[] = {
+static const uint16_t mac_chinese_simp_uni2_charset[] = {
   0x00a0, 0xa1e9, 0xa1ea, 0xa3a4, 0x00fd, 0xa1a4, 0xa8bd, 0xa8be,
   0xa8bf, 0xa8bb, 0xa8c0, 0xa8bc, 0xa1aa, 0xffff, 0xa1ac, 0x00ff,
   0xa3fe, 0x00fe, 0xa1ad, 0xa1ab, 0xffff, 0x0080, 0xa6f3, 0xa6db,
@@ -97,26 +97,26 @@ static const u_int16_t mac_chinese_simp_uni2_charset[] = {
   0xffff, 0xffff,
 };
 
-static const u_int16_t mac_chinese_simp_2uni_page00[][2] = {
+static const uint16_t mac_chinese_simp_2uni_page00[][2] = {
   /* 0x008 */ { 0x0007,    0 }, { 0x0000,    0 }, { 0x0001,    3 }, { 0x0000,    0 },
   /* 0x00c */ { 0x0000,    0 }, { 0x0000,    0 }, { 0x0000,    0 }, { 0xe000,    4 },
 };
 
-static const u_int16_t mac_chinese_simp_2uni_pagea1[][2] = {
+static const uint16_t mac_chinese_simp_2uni_pagea1[][2] = {
   /* 0xa1a */ { 0x3c10,    7 }, { 0x0000,    0 },
   /* 0xa1c */ { 0x0000,    0 }, { 0x0000,    0 }, { 0x0600,   12 },
 };
 
-static const u_int16_t mac_chinese_simp_2uni_pagea3[][2] = {
+static const uint16_t mac_chinese_simp_2uni_pagea3[][2] = {
   /* 0xa3a */ { 0x0010,   14 }, { 0x0000,    0 },
   /* 0xa3c */ { 0x0000,    0 }, { 0x0000,    0 }, { 0x0000,    0 }, { 0x4000,   15 },
 };
 
-static const u_int16_t mac_chinese_simp_2uni_pagea6[][2] = {
+static const uint16_t mac_chinese_simp_2uni_pagea6[][2] = {
   /* 0xa6d */ { 0xfe00,   16 }, { 0xffff,   23 }, { 0x003f,   39 },
 };
 
-static const u_int16_t mac_chinese_simp_2uni_pagea8[][2] = {
+static const uint16_t mac_chinese_simp_2uni_pagea8[][2] = {
   /* 0xa8b */ { 0xf800,   45 }, { 0x0001,   50 },
 };
 
@@ -129,7 +129,7 @@ static const cjk_index_t mac_chinese_simp_2uni_index[] = {
   { { 0, 0 }, NULL }
 };
 
-static const u_int16_t mac_chinese_simp_2uni_charset[] = {
+static const uint16_t mac_chinese_simp_2uni_charset[] = {
   0xe000, 0xf880, 0xf881, 0x00a0, 0x00a9, 0x2122, 0x2026, 0x00b7,
   0x2014, 0x301c, 0x2016, 0x22ef, 0x00a2, 0x00a3, 0x00a5, 0x203e,
   0xe007, 0xe003, 0xe002, 0xe008, 0xe009, 0xe006, 0xe00a, 0xfe35,
@@ -139,7 +139,7 @@ static const u_int16_t mac_chinese_simp_2uni_charset[] = {
   0x0148, 0x01f9, 0x0261,
 };
 
-static const u_int32_t mac_chinese_simp_compose[] = {
+static const uint32_t mac_chinese_simp_compose[] = {
   0x00fcf87f, 0x22eff87e, 0x3001f87e, 0x3002f87e,
   0x3016f87e, 0x3017f87e, 0xff01f87e, 0xff0cf87e,
   0xff1af87e, 0xff1bf87e, 0xff1ff87e,
index 7412beeccb421e1e5527a60f518c530cc36176d6..116e8cd5e3f88d905a50ab0c3e1c181ed3048a95 100644 (file)
@@ -43,7 +43,7 @@ struct charset_functions charset_mac_chinese_trad = {
   NULL, NULL
 };
 
-static size_t mac_chinese_trad_char_push(u_int8_t* out, const ucs2_t* in, size_t* size)
+static size_t mac_chinese_trad_char_push(uint8_t* out, const ucs2_t* in, size_t* size)
 {
   ucs2_t wc = in[0];
 
@@ -53,7 +53,7 @@ static size_t mac_chinese_trad_char_push(u_int8_t* out, const ucs2_t* in, size_t
       out[0] = 0x80;
     } else {
       *size = 1;
-      out[0] = (u_int8_t)wc;
+      out[0] = (uint8_t)wc;
     }
     return 1;
   } else if ((wc & 0xf000) == 0xe000) {
@@ -61,7 +61,7 @@ static size_t mac_chinese_trad_char_push(u_int8_t* out, const ucs2_t* in, size_t
     return 0;
   } else if (*size >= 2 && (in[1] & ~15) == 0xf870) {
     ucs2_t comp = cjk_compose(wc, in[1], mac_chinese_trad_compose,
-                             sizeof(mac_chinese_trad_compose) / sizeof(u_int32_t));
+                             sizeof(mac_chinese_trad_compose) / sizeof(uint32_t));
     if (comp) {
       wc = comp;
       *size = 2;
@@ -82,9 +82,9 @@ static size_t mac_chinese_trad_push(void *cd, char **inbuf, size_t *inbytesleft,
                          cd, inbuf, inbytesleft, outbuf, outbytesleft);
 }
 
-static size_t mac_chinese_trad_char_pull(ucs2_t* out, const u_int8_t* in, size_t* size)
+static size_t mac_chinese_trad_char_pull(ucs2_t* out, const uint8_t* in, size_t* size)
 {
-  u_int16_t c = in[0];
+  uint16_t c = in[0];
 
   if (c <= 0x7f) {
     *size = 1;
@@ -92,7 +92,7 @@ static size_t mac_chinese_trad_char_pull(ucs2_t* out, const u_int8_t* in, size_t
     return 1;
   } else if (c >= 0xa1 && c <= 0xfc) {
     if (*size >= 2) {
-      u_int8_t c2 = in[1];
+      uint8_t c2 = in[1];
 
       if ((c2 >= 0x40 && c2 <= 0x7e) || (c2 >= 0xa1 && c2 <= 0xfe)) {
        *size = 2;
index a5c94eb1f6fdc434d8bf2429177b1ad6caf6d286..00e0c518e62ef593a00bb0f3bc117a568003a5ec 100644 (file)
  * http://www.unicode.org/Public/MAPPINGS/VENDORS/APPLE/
  */
 
-static const u_int16_t mac_chinese_trad_uni2_page00[][2] = {
+static const uint16_t mac_chinese_trad_uni2_page00[][2] = {
   /* 0x00a */ { 0x0201,    0 }, { 0x0080,    2 },
 };
 
-static const u_int16_t mac_chinese_trad_uni2_page20[][2] = {
+static const uint16_t mac_chinese_trad_uni2_page20[][2] = {
   /* 0x202 */ { 0x0044,    3 },
 };
 
-static const u_int16_t mac_chinese_trad_uni2_page21[][2] = {
+static const uint16_t mac_chinese_trad_uni2_page21[][2] = {
   /* 0x212 */ { 0x0004,    5 },
 };
 
-static const u_int16_t mac_chinese_trad_uni2_page22[][2] = {
+static const uint16_t mac_chinese_trad_uni2_page22[][2] = {
   /* 0x229 */ { 0x0020,    6 }, { 0x0000,    0 }, { 0x0000,    0 },
   /* 0x22c */ { 0x0000,    0 }, { 0x0000,    0 }, { 0x8000,    7 },
 };
 
-static const u_int16_t mac_chinese_trad_uni2_page25[][2] = {
+static const uint16_t mac_chinese_trad_uni2_page25[][2] = {
   /* 0x259 */ { 0x0020,    8 },
 };
 
-static const u_int16_t mac_chinese_trad_uni2_page26[][2] = {
+static const uint16_t mac_chinese_trad_uni2_page26[][2] = {
   /* 0x264 */ { 0x0002,    9 },
 };
 
-static const u_int16_t mac_chinese_trad_uni2_pagee0[][2] = {
+static const uint16_t mac_chinese_trad_uni2_pagee0[][2] = {
   /* 0xe00 */ { 0xffff,   10 }, { 0x00ff,   26 },
 };
 
-static const u_int16_t mac_chinese_trad_uni2_pagef8[][2] = {
+static const uint16_t mac_chinese_trad_uni2_pagef8[][2] = {
   /* 0xf88 */ { 0x0003,   34 },
 };
 
-static const u_int16_t mac_chinese_trad_uni2_pagefe[][2] = {
+static const uint16_t mac_chinese_trad_uni2_pagefe[][2] = {
   /* 0xfe4 */ { 0x1000,   36 }, { 0x7ef5,   37 },
 };
 
-static const u_int16_t mac_chinese_trad_uni2_pageff[][2] = {
+static const uint16_t mac_chinese_trad_uni2_pageff[][2] = {
   /* 0xff6 */ { 0x0010,   49 },
 };
 
@@ -75,7 +75,7 @@ static const cjk_index_t mac_chinese_trad_uni2_index[] = {
   { { 0, 0 }, NULL }
 };
 
-static const u_int16_t mac_chinese_trad_uni2_charset[] = {
+static const uint16_t mac_chinese_trad_uni2_charset[] = {
   0x00a0, 0x00fd, 0xa145, 0xffff, 0x00ff, 0x00fe, 0xa1f2, 0xa14b,
   0xffff, 0xffff, 0x0080, 0xa1c3, 0xa279, 0xa14e, 0xa1a3, 0xa1a4,
   0xa2cc, 0xa2ce, 0xa1cb, 0xa154, 0xa17d, 0xa17e, 0xa14d, 0xa14f,
@@ -85,12 +85,12 @@ static const u_int16_t mac_chinese_trad_uni2_charset[] = {
   0xffff, 0xffff,
 };
 
-static const u_int16_t mac_chinese_trad_2uni_page00[][2] = {
+static const uint16_t mac_chinese_trad_2uni_page00[][2] = {
   /* 0x008 */ { 0x0007,    0 }, { 0x0000,    0 }, { 0x0001,    3 }, { 0x0000,    0 },
   /* 0x00c */ { 0x0000,    0 }, { 0x0000,    0 }, { 0x0000,    0 }, { 0xe000,    4 },
 };
 
-static const u_int16_t mac_chinese_trad_2uni_pagea1[][2] = {
+static const uint16_t mac_chinese_trad_2uni_pagea1[][2] = {
   /* 0xa14 */ { 0xe820,    7 }, { 0x041f,   12 }, { 0x0000,    0 }, { 0x6000,   18 },
   /* 0xa18 */ { 0x0000,    0 }, { 0x0000,    0 }, { 0x001e,   20 }, { 0x0000,    0 },
   /* 0xa1c */ { 0x0828,   24 }, { 0x0000,    0 }, { 0x0000,    0 }, { 0x4004,   27 },
@@ -106,7 +106,7 @@ static const cjk_index_t mac_chinese_trad_2uni_index[] = {
   { { 0, 0 }, NULL }
 };
 
-static const u_int16_t mac_chinese_trad_2uni_charset[] = {
+static const uint16_t mac_chinese_trad_2uni_charset[] = {
   0xe000, 0xf880, 0xf881, 0x00a0, 0x00a9, 0x2122, 0x2026, 0x00b7,
   0x22ef, 0xe00c, 0xe003, 0xe00d, 0xe00e, 0xe011, 0xe010, 0xe012,
   0xe009, 0xe015, 0xe00a, 0xe00b, 0xe016, 0xe017, 0xe004, 0xe005,
@@ -114,7 +114,7 @@ static const u_int16_t mac_chinese_trad_2uni_charset[] = {
   0xe007,
 };
 
-static const u_int32_t mac_chinese_trad_compose[] = {
+static const uint32_t mac_chinese_trad_compose[] = {
   0x005cf87f, 0x203ef87c, 0x2502f87f, 0x3001f87d,
   0x3014f87f, 0x3015f87f, 0x5341f87f, 0x5345f87f,
   0xfe4bf87c, 0xff01f87d, 0xff08f87f, 0xff09f87f,
index d20a8cec851a0aeb7e60ef3f9165fe4e7753cb60..fde6486130d6ea1b3d8915afa5f30fe0060b1caf 100644 (file)
@@ -28,8 +28,8 @@
 #include "config.h"
 #endif /* HAVE_CONFIG_H */
 #include <stdlib.h> /* for size_t */
+#include <arpa/inet.h>
 
-#include <netatalk/endian.h>
 #include <atalk/unicode.h>
 
 #include "mac_cyrillic.h"
index 933ba3751ae33ccfcc5324700754acb64fa81f42..e48237b68ed066258a2a58912a19255ecd442ba6 100644 (file)
@@ -30,7 +30,8 @@
 #include "config.h"
 #endif /* HAVE_CONFIG_H */
 #include <stdlib.h>
-#include <netatalk/endian.h>
+#include <arpa/inet.h>
+
 #include <atalk/unicode.h>
 
 #include "mac_greek.h"
index 8b7bdca94ddad58f72741a520c841de0744ebcd0..91a022bd330983a0dcb2df6eb5decefba8cbf7c6 100644 (file)
@@ -30,8 +30,8 @@
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
+#include <arpa/inet.h>
 
-#include <netatalk/endian.h>
 #include <atalk/unicode.h>
 #include <atalk/logger.h>
 
index b78ce01416a6453c97761f20c25eafb899387b62..9f32f66246f7fbe0bfcd59dd3d732a853a186a6f 100644 (file)
@@ -43,29 +43,29 @@ struct charset_functions charset_mac_japanese = {
   NULL, NULL
 };
 
-static size_t mac_japanese_char_push(u_int8_t* out, const ucs2_t* in, size_t* size)
+static size_t mac_japanese_char_push(uint8_t* out, const ucs2_t* in, size_t* size)
 {
   ucs2_t wc = in[0];
 
   if (wc <= 0x7f) {
     *size = 1;
-    out[0] = (u_int8_t)(wc == 0x5c ? 0x80 : wc);
+    out[0] = (uint8_t)(wc == 0x5c ? 0x80 : wc);
     return 1;
   } else if ((wc & 0xf000) == 0xe000) { /* user defined */
     *size = 1;
     if (wc > 0xe98b) return 0;
     wc -= 0xe000;
-    out[0] = (u_int8_t)(wc / 188 + 0xf0);
-    out[1] = (u_int8_t)(wc % 188 + 0x40);
+    out[0] = (uint8_t)(wc / 188 + 0xf0);
+    out[1] = (uint8_t)(wc % 188 + 0x40);
     if (out[1] >= 0x7f) ++out[1];
     return 2;
   } else if ((wc & ~7) == 0xf860) {
     wc = cjk_compose_seq(in, size, mac_japanese_compose,
-                        sizeof(mac_japanese_compose) / sizeof(u_int32_t));
+                        sizeof(mac_japanese_compose) / sizeof(uint32_t));
     if (!wc) return (size_t)-1;
   } else if (*size >= 2 && ((in[1] & ~15) == 0xf870 || in[1] == 0x20dd)) {
     ucs2_t comp = cjk_compose(wc, in[1], mac_japanese_compose,
-                             sizeof(mac_japanese_compose) / sizeof(u_int32_t));
+                             sizeof(mac_japanese_compose) / sizeof(uint32_t));
     if (comp) {
       wc = comp;
       *size = 2;
@@ -86,9 +86,9 @@ static size_t mac_japanese_push(void *cd, char **inbuf, size_t *inbytesleft,
                          cd, inbuf, inbytesleft, outbuf, outbytesleft);
 }
 
-static size_t mac_japanese_char_pull(ucs2_t* out, const u_int8_t* in, size_t* size)
+static size_t mac_japanese_char_pull(ucs2_t* out, const uint8_t* in, size_t* size)
 {
-  u_int16_t c = in[0];
+  uint16_t c = in[0];
 
   if (c <= 0x7f) {
     *size = 1;
@@ -96,7 +96,7 @@ static size_t mac_japanese_char_pull(ucs2_t* out, const u_int8_t* in, size_t* si
     return 1;
   } else if ((c >= 0x81 && c <= 0x9f) || (c >= 0xe0 && c <= 0xfc)) {
     if (*size >= 2) {
-      u_int8_t c2 = in[1];
+      uint8_t c2 = in[1];
 
       if ((c2 >= 0x40 && c2 <= 0x7e) || (c2 >= 0x80 && c2 <= 0xfc)) {
        *size = 2;
index b0be8697177e07664a20807321b62a2849ef8a4f..e27e450d7fc2f13357f9c479a7b1880d5a4d194e 100644 (file)
  * http://www.unicode.org/Public/MAPPINGS/VENDORS/APPLE/
  */
 
-static const u_int16_t mac_japanese_uni2_page00[][2] = {
+static const uint16_t mac_japanese_uni2_page00[][2] = {
   /* 0x00a */ { 0x0201,    1 },
 };
 
-static const u_int16_t mac_japanese_uni2_page20[][2] = {
+static const uint16_t mac_japanese_uni2_page20[][2] = {
   /* 0x201 */ { 0x0030,    3 }, { 0x0000,    0 }, { 0x4000,    5 },
   /* 0x204 */ { 0x0000,    0 }, { 0x0000,    0 }, { 0x0000,    0 }, { 0x0000,    0 },
   /* 0x208 */ { 0x0000,    0 }, { 0x0000,    0 }, { 0x0000,    0 }, { 0x0000,    0 },
@@ -38,12 +38,12 @@ static const u_int16_t mac_japanese_uni2_page20[][2] = {
   /* 0x228 */ { 0x0000,    0 }, { 0x0000,    0 }, { 0x0000,    0 }, { 0x8000,   44 },
 };
 
-static const u_int16_t mac_japanese_uni2_page24[][2] = {
+static const uint16_t mac_japanese_uni2_page24[][2] = {
   /* 0x246 */ { 0xffff,   45 }, { 0xffff,   61 },
   /* 0x248 */ { 0xffff,   77 }, { 0xf001,   93 }, { 0xffff,   98 }, { 0x003f,  114 },
 };
 
-static const u_int16_t mac_japanese_uni2_page26[][2] = {
+static const uint16_t mac_japanese_uni2_page26[][2] = {
   /* 0x260 */ { 0x4000,  120 }, { 0xf000,  121 }, { 0x0000,    0 }, { 0x0000,    0 },
   /* 0x264 */ { 0x0000,    0 }, { 0x0000,    0 }, { 0x00ff,  125 }, { 0x0000,    0 },
   /* 0x268 */ { 0x0000,    0 }, { 0x0000,    0 }, { 0x0000,    0 }, { 0x0000,    0 },
@@ -52,14 +52,14 @@ static const u_int16_t mac_japanese_uni2_page26[][2] = {
   /* 0x274 */ { 0x0000,    0 }, { 0x0000,    0 }, { 0x0000,    0 }, { 0x7fc0,  133 },
 };
 
-static const u_int16_t mac_japanese_uni2_page30[][2] = {
+static const uint16_t mac_japanese_uni2_page30[][2] = {
   /* 0x300 */ { 0x0010,  142 }, { 0xa000,  143 }, { 0x0001,  145 }, { 0x0000,    0 },
   /* 0x304 */ { 0x0000,    0 }, { 0x0000,    0 }, { 0x0000,    0 }, { 0x0000,    0 },
   /* 0x308 */ { 0x0000,    0 }, { 0x0010,  146 }, { 0x0000,    0 }, { 0x0000,    0 },
   /* 0x30c */ { 0x0000,    0 }, { 0x0000,    0 }, { 0x0000,    0 }, { 0x0780,  147 },
 };
 
-static const u_int16_t mac_japanese_uni2_page32[][2] = {
+static const uint16_t mac_japanese_uni2_page32[][2] = {
   /* 0x322 */ { 0xfc00,  151 }, { 0xffff,  157 },
   /* 0x324 */ { 0x000d,  173 }, { 0x0000,    0 }, { 0x0000,    0 }, { 0x0000,    0 },
   /* 0x328 */ { 0x0000,    0 }, { 0x6340,  176 }, { 0x03f0,  181 }, { 0x0000,    0 },
@@ -70,12 +70,12 @@ static const u_int16_t mac_japanese_uni2_page32[][2] = {
   /* 0x33c */ { 0x2810,  242 }, { 0x0010,  245 },
 };
 
-static const u_int16_t mac_japanese_uni2_pagee0[][2] = {
+static const uint16_t mac_japanese_uni2_pagee0[][2] = {
   /* 0xe00 */ { 0xffff,  246 }, { 0xffff,  262 }, { 0x0fff,  278 }, { 0x001f,  290 },
   /* 0xe04 */ { 0x7f00,  295 },
 };
 
-static const u_int16_t mac_japanese_uni2_pagefe[][2] = {
+static const uint16_t mac_japanese_uni2_pagefe[][2] = {
   /* 0xfe3 */ { 0xffeb,  302 },
   /* 0xfe4 */ { 0x001f,  316 }, { 0x0000,    0 }, { 0x0000,    0 }, { 0x0000,    0 },
   /* 0xfe8 */ { 0x0000,    0 }, { 0x0000,    0 }, { 0x0000,    0 }, { 0x0000,    0 },
@@ -95,7 +95,7 @@ static const cjk_index_t mac_japanese_uni2_index[] = {
   { { 0, 0 }, NULL }
 };
 
-static const u_int16_t mac_japanese_uni2_charset[] = {
+static const uint16_t mac_japanese_uni2_charset[] = {
   0x0080, 0x00a0, 0x00fd, 0x815c, 0xffff, 0xffff, 0x8656, 0x8650,
   0x869b, 0x869d, 0x00fe, 0x859f, 0x85a0, 0x85a1, 0x85a2, 0x85a3,
   0x85a4, 0x85a5, 0x85a6, 0x85a7, 0x85a8, 0x85a9, 0x85aa, 0x85b3,
@@ -139,16 +139,16 @@ static const u_int16_t mac_japanese_uni2_charset[] = {
   0xeb78, 0x815f,
 };
 
-static const u_int16_t mac_japanese_2uni_page00[][2] = {
+static const uint16_t mac_japanese_2uni_page00[][2] = {
   /* 0x008 */ { 0x0001,    0 }, { 0x0000,    0 }, { 0x0001,    1 }, { 0x0000,    0 },
   /* 0x00c */ { 0x0000,    0 }, { 0x0000,    0 }, { 0x0000,    0 }, { 0xe000,    2 },
 };
 
-static const u_int16_t mac_japanese_2uni_page81[][2] = {
+static const uint16_t mac_japanese_2uni_page81[][2] = {
   /* 0x815 */ { 0x9000,    5 },
 };
 
-static const u_int16_t mac_japanese_2uni_page85[][2] = {
+static const uint16_t mac_japanese_2uni_page85[][2] = {
   /* 0x854 */ { 0xffff,    7 }, { 0xc00f,   23 }, { 0xffff,   29 }, { 0x7003,   45 },
   /* 0x858 */ { 0x003f,   50 }, { 0x87fe,   56 }, { 0x3fff,   67 }, { 0xfff8,   81 },
   /* 0x85c */ { 0x0003,   94 }, { 0xf800,   96 }, { 0xffff,  101 }, { 0x001f,  117 },
@@ -164,7 +164,7 @@ static const u_int16_t mac_japanese_2uni_page85[][2] = {
   /* 0x884 */ { 0x0007,  257 }, { 0x0030,  260 }, { 0x3d00,  262 },
 };
 
-static const u_int16_t mac_japanese_2uni_pageeb[][2] = {
+static const uint16_t mac_japanese_2uni_pageeb[][2] = {
   /* 0xeb4 */ { 0x0006,  267 }, { 0x3803,  269 }, { 0xfe1f,  274 }, { 0x07ff,  286 },
   /* 0xeb8 */ { 0x0002,  297 }, { 0x0000,    0 }, { 0x0000,    0 }, { 0x0000,    0 },
   /* 0xebc */ { 0x0000,    0 }, { 0x0000,    0 }, { 0x0000,    0 }, { 0x0000,    0 },
@@ -185,7 +185,7 @@ static const cjk_index_t mac_japanese_2uni_index[] = {
   { { 0, 0 }, NULL }
 };
 
-static const u_int16_t mac_japanese_2uni_charset[] = {
+static const uint16_t mac_japanese_2uni_charset[] = {
   0x005c, 0x00a0, 0x00a9, 0x2122, 0xe003, 0x2014, 0xff3c, 0x2460,
   0x2461, 0x2462, 0x2463, 0x2464, 0x2465, 0x2466, 0x2467, 0x2468,
   0x2469, 0x246a, 0x246b, 0x246c, 0x246d, 0x246e, 0x246f, 0x2470,
@@ -228,7 +228,7 @@ static const u_int16_t mac_japanese_2uni_charset[] = {
   0xe019, 0xe01a, 0xe01b, 0xe01c, 0xe01d, 0xe01e, 0xe01f, 0xe020,
 };
 
-static const u_int32_t mac_japanese_compose[] = {
+static const uint32_t mac_japanese_compose[] = {
   0x2010f87e, 0x2016f87e, 0x2026f87e, 0x2026f87f,
   0x21e6f87a, 0x21e7f87a, 0x21e8f87a, 0x21e9f87a,
   0x3001f87e, 0x3002f87e, 0x301cf87e, 0x3041f87e,
index a16f4a0359997d8bcc166d9cb2331444f318816e..26f387d78fa9bf8e0845d6d49135c9140c8efad5 100644 (file)
@@ -43,13 +43,13 @@ struct charset_functions charset_mac_korean = {
   NULL, NULL
 };
 
-static size_t mac_korean_char_push(u_int8_t* out, const ucs2_t* in, size_t* size)
+static size_t mac_korean_char_push(uint8_t* out, const ucs2_t* in, size_t* size)
 {
   ucs2_t wc = in[0];
 
   if ((wc & ~7) == 0xf860) {
     wc = cjk_compose_seq(in, size, mac_korean_compose,
-                        sizeof(mac_korean_compose) / sizeof(u_int32_t));
+                        sizeof(mac_korean_compose) / sizeof(uint32_t));
     if (!wc) return (size_t)-1;
   } else if ((wc & 0xf000) == 0xe000) {
     *size = 1;
@@ -62,7 +62,7 @@ static size_t mac_korean_char_push(u_int8_t* out, const ucs2_t* in, size_t* size
           (comb >= 0x0300 && comb <= 0x036f) ||
           (comb >= 0x20d0 && comb <= 0x20ea)) {
       ucs2_t comp = cjk_compose(wc, comb, mac_korean_compose,
-                               sizeof(mac_korean_compose) / sizeof(u_int32_t));
+                               sizeof(mac_korean_compose) / sizeof(uint32_t));
       if (!comp) break;
       wc = comp;
       if (++n == *size) break;
@@ -73,7 +73,7 @@ static size_t mac_korean_char_push(u_int8_t* out, const ucs2_t* in, size_t* size
     *size = 1;
   }
   if (wc <= 0x7f) {
-    out[0] = (u_int8_t)wc;
+    out[0] = (uint8_t)wc;
     return 1;
   }
   return cjk_char_push(cjk_lookup(wc, mac_korean_uni2_index,
@@ -87,9 +87,9 @@ static size_t mac_korean_push(void *cd, char **inbuf, size_t *inbytesleft,
                          cd, inbuf, inbytesleft, outbuf, outbytesleft);
 }
 
-static size_t mac_korean_char_pull(ucs2_t* out, const u_int8_t* in, size_t* size)
+static size_t mac_korean_char_pull(ucs2_t* out, const uint8_t* in, size_t* size)
 {
-  u_int16_t c = in[0];
+  uint16_t c = in[0];
 
   if (c <= 0x7f) {
     *size = 1;
@@ -97,7 +97,7 @@ static size_t mac_korean_char_pull(ucs2_t* out, const u_int8_t* in, size_t* size
     return 1;
   } else if (c >= 0xa1 && c <= 0xfe) {
     if (*size >= 2) {
-      u_int8_t c2 = in[1];
+      uint8_t c2 = in[1];
       if ((c2 >= 0x41 && c2 <= 0x7d) || (c2 >= 0x81 && c2 <= 0xfe)) {
        *size = 2;
        c = (c << 8) + c2;
index 4e990533d266f78ed40190a632a5299d716aa6fb..2febaa28779b7c55d42ed29c13edf207dcc5e306 100644 (file)
  * http://www.unicode.org/Public/MAPPINGS/VENDORS/APPLE/
  */
 
-static const u_int16_t mac_korean_uni2_page00[][2] = {
+static const uint16_t mac_korean_uni2_page00[][2] = {
   /* 0x00a */ { 0x7a2d,    0 }, { 0x0880,    9 },
 };
 
-static const u_int16_t mac_korean_uni2_page02[][2] = {
+static const uint16_t mac_korean_uni2_page02[][2] = {
   /* 0x02b */ { 0x1000,   11 },
   /* 0x02c */ { 0x0000,    0 }, { 0x1001,   12 }, { 0x0000,    0 }, { 0x0000,    0 },
   /* 0x030 */ { 0x0000,    0 }, { 0x0000,    0 }, { 0x0000,    0 }, { 0x0000,    0 },
@@ -33,7 +33,7 @@ static const u_int16_t mac_korean_uni2_page02[][2] = {
   /* 0x03c */ { 0x0000,    0 }, { 0x0020,   14 },
 };
 
-static const u_int16_t mac_korean_uni2_page20[][2] = {
+static const uint16_t mac_korean_uni2_page20[][2] = {
   /* 0x201 */ { 0x8878,   15 }, { 0x0004,   21 }, { 0x5670,   22 },
   /* 0x204 */ { 0x7284,   29 }, { 0x0002,   35 }, { 0x0000,    0 }, { 0x7c00,   36 },
   /* 0x208 */ { 0x0000,    0 }, { 0x0000,    0 }, { 0x1200,   41 }, { 0x0000,    0 },
@@ -49,7 +49,7 @@ static const u_int16_t mac_korean_uni2_page20[][2] = {
   /* 0x230 */ { 0x0040,  118 }, { 0x0010,  119 },
 };
 
-static const u_int16_t mac_korean_uni2_page24[][2] = {
+static const uint16_t mac_korean_uni2_page24[][2] = {
   /* 0x246 */ { 0x8000,  120 }, { 0x000f,  121 },
   /* 0x248 */ { 0x00f8,  125 }, { 0x0000,    0 }, { 0x0000,    0 }, { 0xffc0,  130 },
   /* 0x24c */ { 0xffff,  140 }, { 0x0000,    0 }, { 0xf800,  156 }, { 0x001f,  161 },
@@ -66,7 +66,7 @@ static const u_int16_t mac_korean_uni2_page24[][2] = {
   /* 0x278 */ { 0xfc00,  210 }, { 0x581f,  216 }, { 0x0012,  224 }, { 0x0024,  226 },
 };
 
-static const u_int16_t mac_korean_uni2_page29[][2] = {
+static const uint16_t mac_korean_uni2_page29[][2] = {
   /* 0x293 */ { 0x02f0,  228 },
   /* 0x294 */ { 0x0000,    0 }, { 0x0000,    0 }, { 0x003c,  233 }, { 0x0000,    0 },
   /* 0x298 */ { 0x0062,  237 }, { 0x0180,  240 }, { 0x0008,  242 }, { 0xc000,  243 },
@@ -77,21 +77,21 @@ static const u_int16_t mac_korean_uni2_page29[][2] = {
   /* 0x2ac */ { 0x1860,  253 }, { 0x0000,    0 }, { 0x0100,  257 },
 };
 
-static const u_int16_t mac_korean_uni2_page30[][2] = {
+static const uint16_t mac_korean_uni2_page30[][2] = {
   /* 0x301 */ { 0xd3c4,  258 }, { 0x0001,  266 }, { 0x0040,  267 },
 };
 
-static const u_int16_t mac_korean_uni2_page32[][2] = {
+static const uint16_t mac_korean_uni2_page32[][2] = {
   /* 0x323 */ { 0x0202,  268 },
   /* 0x324 */ { 0x0000,    0 }, { 0x07fe,  270 }, { 0x0000,    0 }, { 0x0000,    0 },
   /* 0x328 */ { 0xfc00,  280 }, { 0x4011,  286 }, { 0x0020,  289 },
 };
 
-static const u_int16_t mac_korean_uni2_page33[][2] = {
+static const uint16_t mac_korean_uni2_page33[][2] = {
   /* 0x33c */ { 0x0800,  290 },
 };
 
-static const u_int16_t mac_korean_uni2_pagee0[][2] = {
+static const uint16_t mac_korean_uni2_pagee0[][2] = {
   /* 0xe00 */ { 0xffff,  291 }, { 0xffff,  307 }, { 0xffff,  323 }, { 0xffff,  339 },
   /* 0xe04 */ { 0xffff,  355 }, { 0xffff,  371 }, { 0xffff,  387 }, { 0xffff,  403 },
   /* 0xe08 */ { 0xffff,  419 }, { 0xffff,  435 }, { 0xffff,  451 }, { 0xffff,  467 },
@@ -111,12 +111,12 @@ static const u_int16_t mac_korean_uni2_pagee0[][2] = {
   /* 0xe40 */ { 0x0000,    0 }, { 0x1ffc, 1126 },
 };
 
-static const u_int16_t mac_korean_uni2_pagef8[][2] = {
+static const uint16_t mac_korean_uni2_pagef8[][2] = {
   /* 0xf80 */ { 0x1fe0, 1137 }, { 0x0000,    0 }, { 0x0000,    0 }, { 0x2000, 1145 },
   /* 0xf84 */ { 0xffff, 1146 },
 };
 
-static const u_int16_t mac_korean_uni2_pagefe[][2] = {
+static const uint16_t mac_korean_uni2_pagefe[][2] = {
   /* 0xfe5 */ { 0x0600, 1162 }, { 0x0000,    0 }, { 0x0000,    0 },
   /* 0xfe8 */ { 0x0000,    0 }, { 0x0000,    0 }, { 0x0000,    0 }, { 0x0000,    0 },
   /* 0xfec */ { 0x0000,    0 }, { 0x0000,    0 }, { 0x0000,    0 }, { 0x0000,    0 },
@@ -141,7 +141,7 @@ static const cjk_index_t mac_korean_uni2_index[] = {
   { { 0, 0 }, NULL }
 };
 
-static const u_int16_t mac_korean_uni2_charset[] = {
+static const uint16_t mac_korean_uni2_charset[] = {
   0x0080, 0xa1cb, 0xa1cc, 0xa1cd, 0x0083, 0xa65c, 0xa1fe, 0xffff,
   0xffff, 0xa1a4, 0xa65d, 0xa198, 0xa2b0, 0xa2a6, 0xa76a, 0xa1a9,
   0xa1aa, 0xffff, 0xa1ab, 0xa170, 0xa16f, 0xa655, 0xa5de, 0xadad,
@@ -291,12 +291,12 @@ static const u_int16_t mac_korean_uni2_charset[] = {
   0xffff, 0xffff,
 };
 
-static const u_int16_t mac_korean_2uni_page00[][2] = {
+static const uint16_t mac_korean_2uni_page00[][2] = {
   /* 0x008 */ { 0x001f,    0 }, { 0x0000,    0 }, { 0x0000,    0 }, { 0x0000,    0 },
   /* 0x00c */ { 0x0000,    0 }, { 0x0000,    0 }, { 0x0000,    0 }, { 0x8000,    5 },
 };
 
-static const u_int16_t mac_korean_2uni_pagea1[][2] = {
+static const uint16_t mac_korean_2uni_pagea1[][2] = {
   /* 0xa14 */ { 0xfffe,    6 }, { 0xffff,   21 }, { 0xffff,   37 }, { 0x3fff,   53 },
   /* 0xa18 */ { 0xfffe,   67 }, { 0xf7ff,   82 }, { 0x2e11,   97 }, { 0x0000,    0 },
   /* 0xa1c */ { 0x3800,  103 }, { 0x0000,    0 }, { 0x3000,  106 }, { 0x4000,  108 },
@@ -355,7 +355,7 @@ static const cjk_index_t mac_korean_2uni_index[] = {
   { { 0, 0 }, NULL }
 };
 
-static const u_int16_t mac_korean_2uni_charset[] = {
+static const uint16_t mac_korean_2uni_charset[] = {
   0x00a0, 0x20a9, 0xe022, 0x00a9, 0xe41c, 0xe02b, 0xe12a, 0xe12e,
   0xe128, 0xe12c, 0xe129, 0xe12d, 0xe130, 0xe132, 0xe125, 0xe126,
   0xe123, 0xe124, 0xfe59, 0xfe5a, 0xe413, 0xe415, 0xe118, 0xe11e,
@@ -503,7 +503,7 @@ static const u_int16_t mac_korean_2uni_charset[] = {
   0x2036, 0xe02e, 0x2035, 0xe02c, 0xe08d, 0xe001,
 };
 
-static const u_int32_t mac_korean_compose[] = {
+static const uint32_t mac_korean_compose[] = {
   0x0021f877, 0x0021f87f, 0x0028f87c, 0x0028f87f,
   0x0029f87c, 0x0029f87f, 0x002af877, 0x002d0308,
   0x003020de, 0x003120de, 0x003220de, 0x003320de,
index e703d2149332fb38b806f5564f17755cb847d1ad..34ccaaf93ee7f0a93d837de63e07ed0a22ee9293 100644 (file)
@@ -29,7 +29,8 @@
 #include "config.h"
 #endif /* HAVE_CONFIG_H */
 #include <stdlib.h>
-#include <netatalk/endian.h>
+#include <arpa/inet.h>
+
 #include <atalk/unicode.h>
 
 #include "mac_roman.h"
index 44b18a13ef3946086f9870f4a38e3332d7a43a7a..619f4b015ea6cbded179e81eb3a65230a3dd53c5 100644 (file)
@@ -28,7 +28,8 @@
 #include "config.h"
 #endif /* HAVE_CONFIG_H */
 #include <stdlib.h>
-#include <netatalk/endian.h>
+#include <arpa/inet.h>
+
 #include <atalk/unicode.h>
 
 #include "mac_turkish.h"
index 17125004d7fde59c4e3d39ff8af39bdd75d8a6e9..7c5eb67e3ce0ddd653696ef014d657d324e07c15 100644 (file)
@@ -39,8 +39,8 @@
 #ifdef HAVE_USABLE_ICONV
 #include <iconv.h>
 #endif
+#include <arpa/inet.h>
 
-#include <netatalk/endian.h>
 #include <atalk/unicode.h>
 #include <atalk/logger.h>
 #include "byteorder.h"
index cc00975ed333c4f6edaede90606ccd6e30f90927..c0a268802e635417397e27e3f3ee882600238d49 100644 (file)
@@ -8,7 +8,7 @@ UnicodeData.txt is got from
 http://www.unicode.org/Public/UNIDATA/UnicodeData.txt
 */
 
-static const u_int16_t upper_table_1[704] = {
+static const uint16_t upper_table_1[704] = {
   0x0000, /*U+0000*/ /**/
   0x0001, /*U+0001*/ /**/
   0x0002, /*U+0002*/ /**/
@@ -715,7 +715,7 @@ static const u_int16_t upper_table_1[704] = {
   0x02BF, /*U+02BF*/ /**/
 };
 
-static const u_int16_t upper_table_2[640] = {
+static const uint16_t upper_table_2[640] = {
   0x0340, /*U+0340*/ /**/
   0x0341, /*U+0341*/ /**/
   0x0342, /*U+0342*/ /**/
@@ -1358,7 +1358,7 @@ static const u_int16_t upper_table_2[640] = {
   0x05BF, /*U+05BF*/ /**/
 };
 
-static const u_int16_t upper_table_3[64] = {
+static const uint16_t upper_table_3[64] = {
   0x1D40, /*U+1D40*/ /**/
   0x1D41, /*U+1D41*/ /**/
   0x1D42, /*U+1D42*/ /**/
@@ -1425,7 +1425,7 @@ static const u_int16_t upper_table_3[64] = {
   0x1D7F, /*U+1D7F*/ /**/
 };
 
-static const u_int16_t upper_table_4[512] = {
+static const uint16_t upper_table_4[512] = {
   0x1E00, /*U+1E00*/ /**/
   0x1E00, /*U+1E01*/ /*LATIN SMALL LETTER A WITH RING BELOW*/
   0x1E02, /*U+1E02*/ /**/
@@ -1940,7 +1940,7 @@ static const u_int16_t upper_table_4[512] = {
   0x1FFF, /*U+1FFF*/ /**/
 };
 
-static const u_int16_t upper_table_5[128] = {
+static const uint16_t upper_table_5[128] = {
   0x2140, /*U+2140*/ /**/
   0x2141, /*U+2141*/ /**/
   0x2142, /*U+2142*/ /**/
@@ -2071,7 +2071,7 @@ static const u_int16_t upper_table_5[128] = {
   0x21BF, /*U+21BF*/ /**/
 };
 
-static const u_int16_t upper_table_6[64] = {
+static const uint16_t upper_table_6[64] = {
   0x24C0, /*U+24C0*/ /**/
   0x24C1, /*U+24C1*/ /**/
   0x24C2, /*U+24C2*/ /**/
@@ -2138,7 +2138,7 @@ static const u_int16_t upper_table_6[64] = {
   0x24FF, /*U+24FF*/ /**/
 };
 
-static const u_int16_t upper_table_7[320] = {
+static const uint16_t upper_table_7[320] = {
   0x2C00, /*U+2C00*/ /**/
   0x2C01, /*U+2C01*/ /**/
   0x2C02, /*U+2C02*/ /**/
@@ -2461,7 +2461,7 @@ static const u_int16_t upper_table_7[320] = {
   0x2D3F, /*U+2D3F*/ /**/
 };
 
-static const u_int16_t upper_table_8[128] = {
+static const uint16_t upper_table_8[128] = {
   0xA640, /*U+A640*/ /**/
   0xA640, /*U+A641*/ /*CYRILLIC SMALL LETTER ZEMLYA*/
   0xA642, /*U+A642*/ /**/
@@ -2592,7 +2592,7 @@ static const u_int16_t upper_table_8[128] = {
   0xA6BF, /*U+A6BF*/ /**/
 };
 
-static const u_int16_t upper_table_9[192] = {
+static const uint16_t upper_table_9[192] = {
   0xA700, /*U+A700*/ /**/
   0xA701, /*U+A701*/ /**/
   0xA702, /*U+A702*/ /**/
@@ -2787,7 +2787,7 @@ static const u_int16_t upper_table_9[192] = {
   0xA7BF, /*U+A7BF*/ /**/
 };
 
-static const u_int16_t upper_table_10[64] = {
+static const uint16_t upper_table_10[64] = {
   0xFF40, /*U+FF40*/ /**/
   0xFF21, /*U+FF41*/ /*FULLWIDTH LATIN SMALL LETTER A*/
   0xFF22, /*U+FF42*/ /*FULLWIDTH LATIN SMALL LETTER B*/
@@ -2854,7 +2854,7 @@ static const u_int16_t upper_table_10[64] = {
   0xFF7F, /*U+FF7F*/ /**/
 };
 
-static const u_int32_t upper_table_sp_1[128] = {
+static const uint32_t upper_table_sp_1[128] = {
   0xD801DC00, /*0xD801DC00*/ /*U+010400*/ /*U+010400*/ /**/
   0xD801DC01, /*0xD801DC01*/ /*U+010401*/ /*U+010401*/ /**/
   0xD801DC02, /*0xD801DC02*/ /*U+010402*/ /*U+010402*/ /**/
@@ -2985,7 +2985,7 @@ static const u_int32_t upper_table_sp_1[128] = {
   0xD801DC7F, /*0xD801DC7F*/ /*U+01047F*/ /*U+01047F*/ /**/
 };
 
-static const u_int16_t lower_table_1[128] = {
+static const uint16_t lower_table_1[128] = {
   0x0000, /*U+0000*/ /**/
   0x0001, /*U+0001*/ /**/
   0x0002, /*U+0002*/ /**/
@@ -3116,7 +3116,7 @@ static const u_int16_t lower_table_1[128] = {
   0x007F, /*U+007F*/ /**/
 };
 
-static const u_int16_t lower_table_2[448] = {
+static const uint16_t lower_table_2[448] = {
   0x00E0, /*U+00C0*/ /*LATIN CAPITAL LETTER A WITH GRAVE*/
   0x00E1, /*U+00C1*/ /*LATIN CAPITAL LETTER A WITH ACUTE*/
   0x00E2, /*U+00C2*/ /*LATIN CAPITAL LETTER A WITH CIRCUMFLEX*/
@@ -3567,7 +3567,7 @@ static const u_int16_t lower_table_2[448] = {
   0x027F, /*U+027F*/ /**/
 };
 
-static const u_int16_t lower_table_3[576] = {
+static const uint16_t lower_table_3[576] = {
   0x0340, /*U+0340*/ /**/
   0x0341, /*U+0341*/ /**/
   0x0342, /*U+0342*/ /**/
@@ -4146,7 +4146,7 @@ static const u_int16_t lower_table_3[576] = {
   0x057F, /*U+057F*/ /**/
 };
 
-static const u_int16_t lower_table_4[128] = {
+static const uint16_t lower_table_4[128] = {
   0x1080, /*U+1080*/ /**/
   0x1081, /*U+1081*/ /**/
   0x1082, /*U+1082*/ /**/
@@ -4277,7 +4277,7 @@ static const u_int16_t lower_table_4[128] = {
   0x10FF, /*U+10FF*/ /**/
 };
 
-static const u_int16_t lower_table_5[512] = {
+static const uint16_t lower_table_5[512] = {
   0x1E01, /*U+1E00*/ /*LATIN CAPITAL LETTER A WITH RING BELOW*/
   0x1E01, /*U+1E01*/ /**/
   0x1E03, /*U+1E02*/ /*LATIN CAPITAL LETTER B WITH DOT ABOVE*/
@@ -4792,7 +4792,7 @@ static const u_int16_t lower_table_5[512] = {
   0x1FFF, /*U+1FFF*/ /**/
 };
 
-static const u_int16_t lower_table_6[192] = {
+static const uint16_t lower_table_6[192] = {
   0x2100, /*U+2100*/ /**/
   0x2101, /*U+2101*/ /**/
   0x2102, /*U+2102*/ /**/
@@ -4987,7 +4987,7 @@ static const u_int16_t lower_table_6[192] = {
   0x21BF, /*U+21BF*/ /**/
 };
 
-static const u_int16_t lower_table_7[128] = {
+static const uint16_t lower_table_7[128] = {
   0x2480, /*U+2480*/ /**/
   0x2481, /*U+2481*/ /**/
   0x2482, /*U+2482*/ /**/
@@ -5118,7 +5118,7 @@ static const u_int16_t lower_table_7[128] = {
   0x24FF, /*U+24FF*/ /**/
 };
 
-static const u_int16_t lower_table_8[256] = {
+static const uint16_t lower_table_8[256] = {
   0x2C30, /*U+2C00*/ /*GLAGOLITIC CAPITAL LETTER AZU*/
   0x2C31, /*U+2C01*/ /*GLAGOLITIC CAPITAL LETTER BUKY*/
   0x2C32, /*U+2C02*/ /*GLAGOLITIC CAPITAL LETTER VEDE*/
@@ -5377,7 +5377,7 @@ static const u_int16_t lower_table_8[256] = {
   0x2CFF, /*U+2CFF*/ /**/
 };
 
-static const u_int16_t lower_table_9[128] = {
+static const uint16_t lower_table_9[128] = {
   0xA641, /*U+A640*/ /*CYRILLIC CAPITAL LETTER ZEMLYA*/
   0xA641, /*U+A641*/ /**/
   0xA643, /*U+A642*/ /*CYRILLIC CAPITAL LETTER DZELO*/
@@ -5508,7 +5508,7 @@ static const u_int16_t lower_table_9[128] = {
   0xA6BF, /*U+A6BF*/ /**/
 };
 
-static const u_int16_t lower_table_10[192] = {
+static const uint16_t lower_table_10[192] = {
   0xA700, /*U+A700*/ /**/
   0xA701, /*U+A701*/ /**/
   0xA702, /*U+A702*/ /**/
@@ -5703,7 +5703,7 @@ static const u_int16_t lower_table_10[192] = {
   0xA7BF, /*U+A7BF*/ /**/
 };
 
-static const u_int16_t lower_table_11[64] = {
+static const uint16_t lower_table_11[64] = {
   0xFF00, /*U+FF00*/ /**/
   0xFF01, /*U+FF01*/ /**/
   0xFF02, /*U+FF02*/ /**/
@@ -5770,7 +5770,7 @@ static const u_int16_t lower_table_11[64] = {
   0xFF3F, /*U+FF3F*/ /**/
 };
 
-static const u_int32_t lower_table_sp_1[64] = {
+static const uint32_t lower_table_sp_1[64] = {
   0xD801DC28, /*0xD801DC00*/ /*U+010428*/ /*U+010400*/ /*DESERET CAPITAL LETTER LONG I*/
   0xD801DC29, /*0xD801DC01*/ /*U+010429*/ /*U+010401*/ /*DESERET CAPITAL LETTER LONG E*/
   0xD801DC2A, /*0xD801DC02*/ /*U+01042A*/ /*U+010402*/ /*DESERET CAPITAL LETTER LONG A*/
index c3146d0c65caed582f04cea18babfe9fc5fcaf22..896a2611e6b4857485b7a5e85b7a2db146ecdc3c 100644 (file)
@@ -29,8 +29,8 @@
 #endif /* HAVE_CONFIG_H */
 #include <stdlib.h>
 #include <errno.h>
+#include <arpa/inet.h>
 
-#include <netatalk/endian.h>
 #include <atalk/unicode.h>
 #include <atalk/logger.h>
 #include <atalk/unicode.h>
index decd8c0a5019980274e81404200f2de0573c0bb9..e5ea4ba0fcea2cd8def574b835432305a0024c50 100644 (file)
@@ -19,8 +19,7 @@
 #include <sys/stat.h>
 #include <atalk/logger.h>
 #include <errno.h>
-
-#include <netatalk/endian.h>
+#include <arpa/inet.h>
 
 #include <atalk/unicode.h>
 #include "precompose.h"
@@ -39,8 +38,8 @@ int strlower_w(ucs2_t *s)
        while (*s) {
                if ((0xD800 <= *s) && (*s < 0xDC00)) {
                        if ((0xDC00 <= s[1]) && (s[1] < 0xE000)) {
-                               u_int32_t s_sp = (u_int32_t)*s << 16 | (u_int32_t)s[1];
-                               u_int32_t v_sp = tolower_sp(s_sp);
+                               uint32_t s_sp = (uint32_t)*s << 16 | (uint32_t)s[1];
+                               uint32_t v_sp = tolower_sp(s_sp);
                                if (v_sp != s_sp) {
                                        *s = v_sp >> 16;
                                        s++;
@@ -73,8 +72,8 @@ int strupper_w(ucs2_t *s)
        while (*s) {
                if ((0xD800 <= *s) && (*s < 0xDC00)) {
                        if ((0xDC00 <= s[1]) && (s[1] < 0xE000)) {
-                               u_int32_t s_sp = (u_int32_t)*s << 16 | (u_int32_t)s[1];
-                               u_int32_t v_sp = toupper_sp(s_sp);
+                               uint32_t s_sp = (uint32_t)*s << 16 | (uint32_t)s[1];
+                               uint32_t v_sp = toupper_sp(s_sp);
                                if (v_sp != s_sp) {
                                        *s = v_sp >> 16;
                                        s++;
@@ -105,7 +104,7 @@ int islower_w(ucs2_t c)
        return ( c == tolower_w(c));
 }
 
-int islower_sp(u_int32_t c_sp)
+int islower_sp(uint32_t c_sp)
 {
        return ( c_sp == tolower_sp(c_sp));
 }
@@ -121,7 +120,7 @@ int isupper_w(ucs2_t c)
        return ( c == toupper_w(c));
 }
 
-int isupper_sp(u_int32_t c_sp)
+int isupper_sp(uint32_t c_sp)
 {
        return ( c_sp == toupper_sp(c_sp));
 }
@@ -188,11 +187,11 @@ ucs2_t *strcasechr_w(const ucs2_t *s, ucs2_t c)
        return NULL;
 }
 
-ucs2_t *strcasechr_sp(const ucs2_t *s, u_int32_t c_sp)
+ucs2_t *strcasechr_sp(const ucs2_t *s, uint32_t c_sp)
 {
        if (*s == 0) return NULL;
        while (s[1] != 0) {
-               if (tolower_sp(c_sp) == tolower_sp((u_int32_t)*s << 16 | (u_int32_t)s[1])) return (ucs2_t *)s;
+               if (tolower_sp(c_sp) == tolower_sp((uint32_t)*s << 16 | (uint32_t)s[1])) return (ucs2_t *)s;
                s++;
        }
 
@@ -292,7 +291,7 @@ int strcasecmp_w(const ucs2_t *a, const ucs2_t *b)
 
        while (*a && *b) {
                if ((0xD800 <= *a) && (*a < 0xDC00)) {
-                       if (ret = tolower_sp((u_int32_t)*a << 16 | (u_int32_t)a[1]) - tolower_sp((u_int32_t)*b << 16 | (u_int32_t)b[1])) return ret;
+                       if (ret = tolower_sp((uint32_t)*a << 16 | (uint32_t)a[1]) - tolower_sp((uint32_t)*b << 16 | (uint32_t)b[1])) return ret;
                        a++;
                        b++;
                        if (!(*a && *b)) return (tolower_w(*a) - tolower_w(*b)); /* avoid buffer over run */
@@ -318,7 +317,7 @@ int strncasecmp_w(const ucs2_t *a, const ucs2_t *b, size_t len)
 
        while ((n < len) && *a && *b) {
                if ((0xD800 <= *a) && (*a < 0xDC00)) {
-                       if (ret = tolower_sp((u_int32_t)*a << 16 | (u_int32_t)a[1]) - tolower_sp((u_int32_t)*b << 16 | (u_int32_t)b[1])) return ret;
+                       if (ret = tolower_sp((uint32_t)*a << 16 | (uint32_t)a[1]) - tolower_sp((uint32_t)*b << 16 | (uint32_t)b[1])) return ret;
                        a++;
                        b++;
                        n++;
@@ -438,7 +437,7 @@ static ucs2_t do_precomposition(unsigned int base, unsigned int comb)
        int min = 0;
        int max = PRECOMP_COUNT - 1;
        int mid;
-       u_int32_t sought = (base << 16) | comb, that;
+       uint32_t sought = (base << 16) | comb, that;
 
        /* binary search */
        while (max >= min) {
@@ -457,17 +456,17 @@ static ucs2_t do_precomposition(unsigned int base, unsigned int comb)
 }
 
 /* ------------------------ */
-static u_int32_t do_precomposition_sp(unsigned int base_sp, unsigned int comb_sp) 
+static uint32_t do_precomposition_sp(unsigned int base_sp, unsigned int comb_sp) 
 {
        int min = 0;
        int max = PRECOMP_SP_COUNT - 1;
        int mid;
-       u_int64_t sought_sp = ((u_int64_t)base_sp << 32) | (u_int64_t)comb_sp, that_sp;
+       uint64_t sought_sp = ((uint64_t)base_sp << 32) | (uint64_t)comb_sp, that_sp;
 
        /* binary search */
        while (max >= min) {
                mid = (min + max) / 2;
-               that_sp = ((u_int64_t)precompositions_sp[mid].base_sp << 32) | ((u_int64_t)precompositions_sp[mid].comb_sp);
+               that_sp = ((uint64_t)precompositions_sp[mid].base_sp << 32) | ((uint64_t)precompositions_sp[mid].comb_sp);
                if (that_sp < sought_sp) {
                        min = mid + 1;
                } else if (that_sp > sought_sp) {
@@ -481,13 +480,13 @@ static u_int32_t do_precomposition_sp(unsigned int base_sp, unsigned int comb_sp
 }
 
 /* -------------------------- */
-static u_int32_t do_decomposition(ucs2_t base) 
+static uint32_t do_decomposition(ucs2_t base) 
 {
        int min = 0;
        int max = DECOMP_COUNT - 1;
        int mid;
-       u_int32_t sought = base;
-       u_int32_t result, that;
+       uint32_t sought = base;
+       uint32_t result, that;
 
        /* binary search */
        while (max >= min) {
@@ -507,14 +506,14 @@ static u_int32_t do_decomposition(ucs2_t base)
 }
 
 /* -------------------------- */
-static u_int64_t do_decomposition_sp(unsigned int base_sp) 
+static uint64_t do_decomposition_sp(unsigned int base_sp) 
 {
        int min = 0;
        int max = DECOMP_SP_COUNT - 1;
        int mid;
-       u_int32_t sought_sp = base_sp;
-       u_int32_t that_sp;
-       u_int64_t result_sp;
+       uint32_t sought_sp = base_sp;
+       uint32_t that_sp;
+       uint64_t result_sp;
 
        /* binary search */
        while (max >= min) {
@@ -525,7 +524,7 @@ static u_int64_t do_decomposition_sp(unsigned int base_sp)
                } else if (that_sp > sought_sp) {
                        max = mid - 1;
                } else {
-                       result_sp = ((u_int64_t)decompositions_sp[mid].base_sp << 32) | ((u_int64_t)decompositions_sp[mid].comb_sp);
+                       result_sp = ((uint64_t)decompositions_sp[mid].base_sp << 32) | ((uint64_t)decompositions_sp[mid].comb_sp);
                        return result_sp;
                }
        }
@@ -552,11 +551,11 @@ size_t precompose_w (ucs2_t *name, size_t inplen, ucs2_t *comp, size_t *outlen)
 {
        size_t i;
        ucs2_t base, comb;
-       u_int32_t base_sp, comb_sp;
+       uint32_t base_sp, comb_sp;
        ucs2_t *in, *out;
        ucs2_t lindex, vindex;
        ucs2_t result;
-       u_int32_t result_sp;
+       uint32_t result_sp;
        size_t o_len = *outlen;
        
        if (!inplen || (inplen & 1) || inplen > o_len)
@@ -605,9 +604,9 @@ size_t precompose_w (ucs2_t *name, size_t inplen, ucs2_t *comp, size_t *outlen)
                /* Binary Search for Surrogate Pair */
                else if ((0xD800 <= base) && (base < 0xDC00)) {
                        if ((0xDC00 <= comb) && (comb < 0xE000) && (i + 6 <= inplen)) {
-                               base_sp = ((u_int32_t)base << 16) | (u_int32_t)comb;
+                               base_sp = ((uint32_t)base << 16) | (uint32_t)comb;
                                do {
-                                       comb_sp = ((u_int32_t)in[1] << 16) | (u_int32_t)in[2];
+                                       comb_sp = ((uint32_t)in[1] << 16) | (uint32_t)in[2];
                                        if (result_sp = do_precomposition_sp(base_sp, comb_sp)) {
                                                base_sp = result_sp;
                                                i += 4;
@@ -664,11 +663,11 @@ size_t decompose_w (ucs2_t *name, size_t inplen, ucs2_t *comp, size_t *outlen)
        size_t i;
        size_t comblen;
        ucs2_t base, comb[COMBBUFLEN];
-       u_int32_t base_sp;
+       uint32_t base_sp;
        ucs2_t sindex, tjamo;
        ucs2_t *in, *out;
        unsigned int result;
-       u_int64_t result_sp;
+       uint64_t result_sp;
        size_t o_len = *outlen;
 
        if (!inplen || (inplen & 1))
@@ -706,7 +705,7 @@ size_t decompose_w (ucs2_t *name, size_t inplen, ucs2_t *comp, size_t *outlen)
                /* Binary Search for Surrogate Pair */
                else if ((0xD800 <= base) && (base < 0xDC00)) {
                        if (i + 2 < inplen) {
-                               base_sp =  ((u_int32_t)base << 16) | (u_int32_t)in[1];
+                               base_sp =  ((uint32_t)base << 16) | (uint32_t)in[1];
                                do {
                                        if ( !(result_sp = do_decomposition_sp(base_sp))) break;
                                        comblen += 2;
index af5d3c9ff6b10515d0aaebc26b6350ea3531c022..17ae747cb9ac45c278996965d57d697f8df91a65 100644 (file)
@@ -1,11 +1,10 @@
 # Makefile.am for libatalk/util/
 
-noinst_LTLIBRARIES = libutil.la
+pkgconfdir = @PKGCONFDIR@
 
-AM_CFLAGS = -I$(top_srcdir)/sys
+noinst_LTLIBRARIES = libutil.la
 
 libutil_la_SOURCES = \
-       atalk_addr.c    \
        bprint.c        \
        cnid.c          \
        fault.c         \
@@ -18,12 +17,12 @@ libutil_la_SOURCES = \
        server_ipc.c    \
        server_lock.c   \
        socket.c        \
-       strcasestr.c    \
        strdicasecmp.c  \
-       strlcpy.c       \
-       volinfo.c \
+       volinfo.c       \
        unix.c
 
+libutil_la_CFLAGS = -D_PATH_AFPDCONF=\"$(pkgconfdir)/afpd.conf\"
+
 if HAVE_ATFUNCS
 libutil_la_SOURCES += ftw.c
 endif
diff --git a/libatalk/util/atalk_addr.c b/libatalk/util/atalk_addr.c
deleted file mode 100644 (file)
index e151441..0000000
+++ /dev/null
@@ -1,118 +0,0 @@
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#ifndef NO_DDP
-
-#include <sys/types.h>
-#include <netatalk/at.h>
-#include <netatalk/endian.h>
-#include <atalk/util.h>
-#include <ctype.h>
-
-/* 
- * Check whether "cp" is a valid ascii representation
- * of an AppleTalk address and convert to a binary address.
- * Examples of accepted forms are (in decimal, net of 4321,
- * node of 65):
- *
- *     4321.65
- *     0x10E1.41
- *     16.225.65
- *     0x10.E1.41
- *
- * If hex is used, and the first digit is one of A-F, the leading
- * 0x is redundant. Returns 1 if the address is valid, 0 if not.
- *
- * Unlike Internet addresses, AppleTalk addresses can have leading
- * 0's. This means that we can't support octal addressing.
- */
-
-int atalk_aton(char *cp, struct at_addr *addr)
-{
-    u_int32_t val, base, n;
-    char c;
-
-    val = 0; base = 10;
-    if ( *cp == '0' && ( *++cp == 'x' || *cp == 'X' )) {
-       base = 16, cp++;
-    }
-    if ( !isdigit( *cp ) && isxdigit( *cp )) {
-       base = 16;
-    }
-
-    for ( n = 0;; n++ ) {
-       while (( c = *cp ) != '\0') {
-           if ( isascii( c ) && isdigit( c )) {
-               val = (val * base) + (c - '0');
-               cp++;
-               continue;
-           }
-
-           if ( base == 16 && isascii( c ) && isxdigit( c )) {
-               val = ( val << 4 ) + ( c + 10 - ( islower( c ) ? 'a' : 'A' ));
-               cp++;
-               continue;
-           }
-           break;
-       }
-
-       if ( c != '.' && c != '\0' ) {
-           return( 0 );
-       }
-
-       switch ( n ) {
-       case 0:
-           if ( addr ) {
-               if ( val > 65535 ) {
-                   return( 0 );
-               }
-               addr->s_net = val;
-           }
-           if ( *cp++ ) {
-               val = 0;
-           } else {
-               break;
-           }
-           continue;
-
-       case 2:
-           if ( addr ) {
-               if ( addr->s_net > 255 ) {
-                   return( 0 );
-               }
-               addr->s_net <<= 8;
-               addr->s_net += addr->s_node;
-           }
-           /*FALLTHROUGH*/
-
-       case 1:
-           if ( addr ) {
-               if ( val > 255 ) {
-                   return( 0 );
-               }
-               addr->s_node = val;
-           }
-           if ( *cp++ ) {
-               val = 0;
-           } else {
-               break;
-           }
-           continue;
-
-       default:
-           return( 0 );
-       }
-       break;
-    }
-
-    if ( n < 1 ) {
-       return( 0 );
-    }
-    if ( addr ) {
-       addr->s_net = htons( addr->s_net );
-    }
-    return (1);
-}
-
-#endif  /* NO_DDP */
index 7841f6a4045566442366271bdb483173eb094a7c..87b5746f091df9dbfde1d3e1687120be332d309e 100644 (file)
@@ -2,7 +2,7 @@
 #include "config.h"
 #endif
 
-#ifdef DEBUG1
+#ifdef DEBUG
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
index 2b9ef64455f403d34201c7936cc43ef6806e63cd..48c4fe058d715c094d9e5a9035866eade4d2bf1d 100644 (file)
@@ -36,7 +36,7 @@
 #include <atalk/logger.h>
 
 #ifndef SIGNAL_CAST
-#define SIGNAL_CAST (RETSIGTYPE (*)(int))
+#define SIGNAL_CAST (void (*)(int))
 #endif
 #ifndef SAFE_FREE /* Oh no this is also defined in tdb.h */
 #define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
@@ -93,6 +93,7 @@ void netatalk_panic(const char *why)
        backtrace_size = backtrace(backtrace_stack,BACKTRACE_STACK_SIZE);
        backtrace_strings = backtrace_symbols(backtrace_stack, backtrace_size);
 
+       LOG(log_severe, logtype_default, "PANIC: %s", why);
        LOG(log_severe, logtype_default, "BACKTRACE: %d stack frames:", backtrace_size);
        
        if (backtrace_strings) {
index 05af80b1d0b35cea7432f9ce38a5c69ec6c2237b..bf79fff7f49e62f63983583aeb0b2b7cb4934d0c 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-
-#ifdef HAVE_STDINT_H
 #include <stdint.h>
-#endif
-
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/ioctl.h>
index 016029f8c4200a34e87896f0eba8460326e02f89..8b27f6f3ef13626f70dfdb8669d4f0363eb01d42 100644 (file)
 
 #include <stdlib.h>
 #include <string.h>
-#ifdef HAVE_UNISTD_H
 #include <unistd.h>
-#endif /* HAVE_UNISTD_H */
 #include <signal.h>
 #include <errno.h>
-
-/* POSIX.1 sys/wait.h check */
 #include <sys/types.h>
-#ifdef HAVE_SYS_WAIT_H
 #include <sys/wait.h>
-#endif /* HAVE_SYS_WAIT_H */
 #include <sys/time.h>
 
 #include <atalk/logger.h>
index e74ce91b1f5a13b1358543e93aa1f21959d84dea..d40e3a49ea4cb07bf1b7984fc418cb5ec11521ee 100644 (file)
@@ -9,9 +9,7 @@
 #endif 
 
 #include <sys/types.h>
-#ifdef HAVE_UNISTD_H
 #include <unistd.h>
-#endif 
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -71,8 +69,8 @@ static int ipc_kill_token(struct ipc_header *ipc, server_child *children)
 /* ----------------- */
 static int ipc_get_session(struct ipc_header *ipc, server_child *children)
 {
-    u_int32_t boottime;
-    u_int32_t idlen;
+    uint32_t boottime;
+    uint32_t idlen;
     char     *clientid, *p;
 
     
@@ -349,4 +347,3 @@ int ipc_child_write(int fd, uint16_t command, int len, void *msg)
 
    return 0;
 }
-
index eaa0c9a7b2c43d4034d4d9f99aaa075618f3c1cf..0251eadaeba94652c2b45474881f648ea1c5dde2 100644 (file)
@@ -37,7 +37,8 @@ pid_t server_lock(char *program, char *pidfile, int debug)
   FILE *pf;
   pid_t pid;
   int mask;
-  
+
+  if ( !debug ) {
   mask = umask(022);
   /* check for pid. this can get fooled by stale pid's. */
   if ((pf = fopen(pidfile, "r"))) {
@@ -60,7 +61,7 @@ pid_t server_lock(char *program, char *pidfile, int debug)
   /*
    * Disassociate from controlling tty.
    */
-  if ( !debug ) {
+
     int                i;
 
     getitimer(ITIMER_PROF, &itimer);
@@ -90,10 +91,11 @@ pid_t server_lock(char *program, char *pidfile, int debug)
       fclose(pf);
       return pid;
     }
-  } 
 
   fprintf(pf, "%d\n", getpid());
   fclose(pf);
+  } 
+
   return 0;
 }
 
diff --git a/libatalk/util/strcasestr.c b/libatalk/util/strcasestr.c
deleted file mode 100644 (file)
index b26c89f..0000000
+++ /dev/null
@@ -1,124 +0,0 @@
-/* Return the offset of one string within another.
-   Copyright (C) 1994, 1996, 1997 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Library General Public License as
-   published by the Free Software Foundation; either version 2 of the
-   License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Library General Public License for more details.
-
-   You should have received a copy of the GNU Library General Public
-   License along with the GNU C Library; see the file COPYING.LIB.  If not,
-   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-   Boston, MA 02111-1307, USA.  */
-
-/*
- * My personal strstr() implementation that beats most other algorithms.
- * Until someone tells me otherwise, I assume that this is the
- * fastest implementation of strstr() in C.
- * I deliberately chose not to comment it.  You should have at least
- * as much fun trying to understand it, as I had to write it :-).
- *
- * Stephen R. van den Berg, berg@pool.informatik.rwth-aachen.de        */
-/* added strcasestr support, davidm@lineo.com */
-
-#if HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#ifndef HAVE_STRCASESTR 
-
-#if  defined HAVE_STRING_H
-# include <string.h>
-#endif
-
-typedef unsigned chartype;
-
-#include <ctype.h>
-#define VAL(x) tolower(x)
-#define FUNC strcasestr
-#undef strcasestr
-
-char * FUNC ( const char *phaystack, const char *pneedle)
-{
-       register const unsigned char *haystack, *needle;
-       register chartype b, c;
-
-       haystack = (const unsigned char *) phaystack;
-       needle = (const unsigned char *) pneedle;
-
-       b = *needle;
-       if (b != '\0') {
-               haystack--;                             /* possible ANSI violation */
-               do {
-                       c = *++haystack;
-                       if (c == '\0')
-                               goto ret0;
-               }
-               while (VAL(c) != VAL(b));
-
-               c = *++needle;
-               if (c == '\0')
-                       goto foundneedle;
-               ++needle;
-               goto jin;
-
-               for (;;) {
-                       register chartype a;
-                       register const unsigned char *rhaystack, *rneedle;
-
-                       do {
-                               a = *++haystack;
-                               if (a == '\0')
-                                       goto ret0;
-                               if (VAL(a) == VAL(b))
-                                       break;
-                               a = *++haystack;
-                               if (a == '\0')
-                                       goto ret0;
-                 shloop:;}
-                       while (VAL(a) != VAL(b));
-
-                 jin:a = *++haystack;
-                       if (a == '\0')
-                               goto ret0;
-
-                       if (VAL(a) != VAL(c))
-                               goto shloop;
-
-                       rhaystack = haystack-- + 1;
-                       rneedle = needle;
-                       a = *rneedle;
-
-                       if (VAL(*rhaystack) == VAL(a))
-                               do {
-                                       if (a == '\0')
-                                               goto foundneedle;
-                                       ++rhaystack;
-                                       a = *++needle;
-                                       if (VAL(*rhaystack) != VAL(a))
-                                               break;
-                                       if (a == '\0')
-                                               goto foundneedle;
-                                       ++rhaystack;
-                                       a = *++needle;
-                               }
-                               while (VAL(*rhaystack) == VAL(a));
-
-                       needle = rneedle;       /* took the register-poor approach */
-
-                       if (a == '\0')
-                               break;
-               }
-       }
-  foundneedle:
-       return (char *) haystack;
-  ret0:
-       return 0;
-}
-#endif
diff --git a/libatalk/util/strlcpy.c b/libatalk/util/strlcpy.c
deleted file mode 100644 (file)
index 314b039..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
-   Copy from samba lib/replace.c
-
-   Unix SMB/CIFS implementation.
-   replacement routines for broken systems
-   Copyright (C) Andrew Tridgell 1992-1998
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
-   (at your option) any later version.
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-   strlcpy strlcat functions.
-*/
-                          
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <atalk/util.h>
-#include <string.h>
-
-#ifndef HAVE_STRLCPY
-/* like strncpy but does not 0 fill the buffer and always null
-   terminates. bufsize is the size of the destination buffer */
- size_t strlcpy(char *d, const char *s, size_t bufsize)
-{
-        size_t len = strlen(s);
-        size_t ret = len;
-
-        if (bufsize <= 0) 
-               return 0;
-
-        if (len >= bufsize) 
-               len = bufsize-1;
-
-        memcpy(d, s, len);
-        d[len] = 0;
-        return ret;
-}
-#endif
-#ifndef HAVE_STRLCAT
-/* like strncat but does not 0 fill the buffer and always null
-   terminates. bufsize is the length of the buffer, which should
-   be one more than the maximum resulting string length */
- size_t strlcat(char *d, const char *s, size_t bufsize)
-{
-        size_t len1 = strlen(d);
-        size_t len2 = strlen(s);
-        size_t ret = len1 + len2;
-
-       if (len1 >= bufsize) {
-               return 0;
-       } 
-        if (len1+len2 >= bufsize) {
-                len2 = bufsize - (len1+1);
-        }
-        if (len2 > 0) {
-                memcpy(d+len1, s, len2);
-                d[len1+len2] = 0;
-        }
-        return ret;
-}
-#endif
index 0e466307bcd30d6ad13ec3af0c8444be0b26bd45..0ac210ec2c8d4e3e1d99ab16a33f7067cfabd24f 100644 (file)
@@ -40,6 +40,7 @@
 #include <atalk/vfs.h>
 #include <atalk/util.h>
 #include <atalk/unix.h>
+#include <atalk/compat.h>
 
 /* close all FDs >= a specified value */
 static void closeall(int fd)
index c6cb1f21b454b1045e13ae5abe87608e337388ff..52360b1ece0330089386c5383f9cc619c74403e3 100644 (file)
 #include <ctype.h>
 #include <errno.h>
 #include <fcntl.h>
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif
-#ifdef STDC_HEADERS
 #include <string.h>
-#endif
 #include <sys/param.h>
 
 #include <atalk/adouble.h>
@@ -41,6 +36,7 @@
 #include <atalk/logger.h>
 #include <atalk/volinfo.h>
 #include <atalk/volume.h>
+#include <atalk/compat.h>
 #ifdef CNID_DB
 #include <atalk/cnid.h>
 #endif /* CNID_DB*/
@@ -55,7 +51,6 @@ static const vol_opt_name_t vol_opt_names[] = {
     {AFPVOL_USEDOTS,    "USEDOTS"},     /* use real dots */
     {AFPVOL_LIMITSIZE,  "LIMITSIZE"},   /* limit size for older macs */
     {AFPVOL_MAPASCII,   "MAPASCII"},    /* map the ascii range as well */
-    {AFPVOL_DROPBOX,    "DROPBOX"},     /* dropkludge dropbox support */
     {AFPVOL_NOFILEID,   "NOFILEID"},    /* don't advertise createid resolveid and deleteid calls */
     {AFPVOL_NOSTAT,     "NOSTAT"},      /* advertise the volume even if we can't stat() it
                                          * maybe because it will be mounted later in preexec */
@@ -300,21 +295,14 @@ static int parseline ( char *buf, struct volinfo *vol)
           strcpy(vol->v_dbpath, value);
         break;
       case ADOUBLE_VER:
-        if (strcasecmp(value, "v1") == 0) {
-            vol->v_adouble = AD_VERSION1;
-            vol->ad_path = ad_path;
-        }
-#if AD_VERSION == AD_VERSION2
-        else if (strcasecmp(value, "v2") == 0) {
+        if (strcasecmp(value, "v2") == 0) {
             vol->ad_path = ad_path;
             vol->v_adouble = AD_VERSION2;
-        }
-        else if (strcasecmp(value, "osx") == 0) {
-            vol->v_adouble = AD_VERSION2_OSX;
-            vol->ad_path = ad_path_osx;
-        }
-#endif
-        else  {
+        } else if (strcasecmp(value, "ea") == 0) {
+            vol->ad_path = ad_path_ea;
+            vol->v_adouble = AD_VERSION_EA;
+        } else {
+
            fprintf (stderr, "unknown adouble version: %s, %s", buf, value);
            return -1;
         }
@@ -536,17 +524,11 @@ int savevolinfo(const struct vol *vol, const char *Cnid_srv, const char *Cnid_po
     strlcat(buf, item, sizeof(buf));
 
     switch (vol->v_adouble) {
-        case AD_VERSION1:
-            strlcat(buf, "ADOUBLE_VER:v1\n", sizeof(buf));
-            break;
         case AD_VERSION2:
             strlcat(buf, "ADOUBLE_VER:v2\n", sizeof(buf));
             break;
-        case AD_VERSION2_OSX:
-            strlcat(buf, "ADOUBLE_VER:osx\n", sizeof(buf));
-            break;
-        case AD_VERSION1_SFM:
-            strlcat(buf, "ADOUBLE_VER:sfm\n", sizeof(buf));
+        case AD_VERSION_EA:
+            strlcat(buf, "ADOUBLE_VER:ea\n", sizeof(buf));
             break;
     }
 
index 9b8d14374c8e4fbb6aeaa86716ce7aff2af73c09..aa62aebffbd591e4a057b23bfe707bfab9eebdb4 100644 (file)
@@ -2,7 +2,7 @@
 
 noinst_LTLIBRARIES = libvfs.la
 
-libvfs_la_SOURCES = vfs.c unix.c ea.c sys_ea.c ea_sys.c
+libvfs_la_SOURCES = vfs.c unix.c ea_ad.c ea_sys.c extattr.c
 
 if HAVE_ACLS
 libvfs_la_SOURCES += acl.c
diff --git a/libatalk/vfs/ea.c b/libatalk/vfs/ea.c
deleted file mode 100644 (file)
index abe266f..0000000
+++ /dev/null
@@ -1,1770 +0,0 @@
-/*
-  Copyright (c) 2009 Frank Lahm <franklahm@gmail.com>
-
-  This program is free software; you can redistribute it and/or modify
-  it under the terms of the GNU General Public License as published by
-  the Free Software Foundation; either version 2 of the License, or
-  (at your option) any later version.
-
-  This program is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-  GNU General Public License for more details.
-*/
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <unistd.h>
-#include <stdint.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <dirent.h>
-
-#include <atalk/adouble.h>
-#include <atalk/ea.h>
-#include <atalk/afp.h>
-#include <atalk/logger.h>
-#include <atalk/volume.h>
-#include <atalk/vfs.h>
-#include <atalk/util.h>
-#include <atalk/unix.h>
-
-/*
- * Store Extended Attributes inside .AppleDouble folders as follows:
- *
- * filename "fileWithEAs" with EAs "testEA1" and "testEA2"
- *
- * - create header with with the format struct adouble_ea_ondisk, the file is written to
- *   ".AppleDouble/fileWithEAs::EA"
- * - store EAs in files "fileWithEAs::EA::testEA1" and "fileWithEAs::EA::testEA2"
- */
-
-/* 
- * Build mode for EA header from file mode
- */
-static inline mode_t ea_header_mode(mode_t mode)
-{
-    /* Same as ad_hf_mode(mode) */
-    mode &= ~(S_IXUSR | S_IXGRP | S_IXOTH);
-    /* Owner must be able to open, read and w-lock it, in order to chmod from eg 0000 -> 0xxxx*/
-    mode |= S_IRUSR | S_IWUSR;
-    return mode;
-}
-
-/* 
- * Build mode for EA file from file mode
- */
-static inline mode_t ea_mode(mode_t mode)
-{
-    /* Same as ad_hf_mode(mode) */
-    mode &= ~(S_IXUSR | S_IXGRP | S_IXOTH);
-    return mode;
-}
-
-/*
-  Taken form afpd/desktop.c
-*/
-static char *mtoupath(const struct vol *vol, const char *mpath)
-{
-    static char  upath[ MAXPATHLEN + 2]; /* for convert_charset dest_len parameter +2 */
-    const char   *m;
-    char         *u;
-    size_t       inplen;
-    size_t       outlen;
-    uint16_t     flags = CONV_ESCAPEHEX | CONV_ALLOW_COLON;
-
-    if (!mpath)
-        return NULL;
-
-    if ( *mpath == '\0' ) {
-        return( "." );
-    }
-
-    m = mpath;
-    u = upath;
-
-    inplen = strlen(m);
-    outlen = MAXPATHLEN;
-
-    if ((size_t)-1 == (outlen = convert_charset(CH_UTF8_MAC,
-                                                vol->v_volcharset,
-                                                vol->v_maccharset,
-                                                m, inplen, u, outlen, &flags)) ) {
-        return NULL;
-    }
-
-    return( upath );
-}
-
-
-/*
- * Function: unpack_header
- *
- * Purpose: unpack and verify header file data buffer at ea->ea_data into struct ea
- *
- * Arguments:
- *
- *    ea      (rw) handle to struct ea
- *
- * Returns: 0 on success, -1 on error
- *
- * Effects:
- *
- * Verifies magic and version.
- */
-static int unpack_header(struct ea * restrict ea)
-{
-    int ret = 0;
-    unsigned int count = 0;
-    uint32_t uint32;
-    char *buf;
-
-    /* Check magic and version */
-    buf = ea->ea_data;
-    if (*(uint32_t *)buf != htonl(EA_MAGIC)) {
-        LOG(log_error, logtype_afpd, "unpack_header: wrong magic 0x%08x", *(uint32_t *)buf);
-        ret = -1;
-        goto exit;
-    }
-    buf += 4;
-    if (*(uint16_t *)buf != htons(EA_VERSION)) {
-        LOG(log_error, logtype_afpd, "unpack_header: wrong version 0x%04x", *(uint16_t *)buf);
-        ret = -1;
-        goto exit;
-    }
-    buf += 2;
-
-    /* Get EA count */
-    ea->ea_count = ntohs(*(uint16_t *)buf);
-    LOG(log_debug, logtype_afpd, "unpack_header: number of EAs: %u", ea->ea_count);
-    buf += 2;
-
-    if (ea->ea_count == 0)
-        return 0;
-
-    /* Allocate storage for the ea_entries array */
-    ea->ea_entries = malloc(sizeof(struct ea_entry) * ea->ea_count);
-    if ( ! ea->ea_entries) {
-        LOG(log_error, logtype_afpd, "unpack_header: OOM");
-        ret = -1;
-        goto exit;
-    }
-
-    buf = ea->ea_data + EA_HEADER_SIZE;
-    while (count < ea->ea_count) {
-        memcpy(&uint32, buf, 4); /* EA size */
-        buf += 4;
-        (*(ea->ea_entries))[count].ea_size = ntohl(uint32);
-        (*(ea->ea_entries))[count].ea_name = strdup(buf);
-        if (! (*(ea->ea_entries))[count].ea_name) {
-            LOG(log_error, logtype_afpd, "unpack_header: OOM");
-            ret = -1;
-            goto exit;
-        }
-        (*(ea->ea_entries))[count].ea_namelen = strlen((*(ea->ea_entries))[count].ea_name);
-        buf += (*(ea->ea_entries))[count].ea_namelen + 1;
-
-        LOG(log_maxdebug, logtype_afpd, "unpack_header: entry no:%u,\"%s\", size: %u, namelen: %u", count,
-            (*(ea->ea_entries))[count].ea_name,
-            (*(ea->ea_entries))[count].ea_size,
-            (*(ea->ea_entries))[count].ea_namelen);
-
-        count++;
-    }
-
-exit:
-    return ret;
-}
-
-/*
- * Function: pack_header
- *
- * Purpose: pack everything from struct ea into buffer at ea->ea_data
- *
- * Arguments:
- *
- *    ea      (rw) handle to struct ea
- *
- * Returns: 0 on success, -1 on error
- *
- * Effects:
- *
- * adjust ea->ea_count in case an ea entry deletetion is detected
- */
-static int pack_header(struct ea * restrict ea)
-{
-    unsigned int count = 0, eacount = 0;
-    uint16_t uint16;
-    uint32_t uint32;
-    size_t bufsize = EA_HEADER_SIZE;
-
-    char *buf = ea->ea_data + EA_HEADER_SIZE;
-
-    LOG(log_debug, logtype_afpd, "pack_header('%s'): ea_count: %u, ea_size: %u",
-        ea->filename, ea->ea_count, ea->ea_size);
-
-    if (ea->ea_count == 0)
-        /* nothing to do, magic, version and count are still valid in buffer */
-        return 0;
-
-    while(count < ea->ea_count) { /* the names */
-        /* Check if its a deleted entry */
-        if ( ! ((*ea->ea_entries)[count].ea_name)) {
-            count++;
-            continue;
-        }
-
-        bufsize += (*(ea->ea_entries))[count].ea_namelen + 1;
-        count++;
-        eacount++;
-    }
-
-    bufsize += (eacount * 4); /* header + ea_size for each EA */
-    if (bufsize > ea->ea_size) {
-        /* we must realloc */
-        if ( ! (buf = realloc(ea->ea_data, bufsize)) ) {
-            LOG(log_error, logtype_afpd, "pack_header: OOM");
-            return -1;
-        }
-        ea->ea_data = buf;
-    }
-    ea->ea_size = bufsize;
-
-    /* copy count */
-    uint16 = htons(eacount);
-    memcpy(ea->ea_data + EA_COUNT_OFF, &uint16, 2);
-
-    count = 0;
-    buf = ea->ea_data + EA_HEADER_SIZE;
-    while (count < ea->ea_count) {
-        /* Check if its a deleted entry */
-        if ( ! ((*ea->ea_entries)[count].ea_name)) {
-            count++;
-            continue;
-        }
-
-        /* First: EA size */
-        uint32 = htonl((*(ea->ea_entries))[count].ea_size);
-        memcpy(buf, &uint32, 4);
-        buf += 4;
-
-        /* Second: EA name as C-string */
-        strcpy(buf, (*(ea->ea_entries))[count].ea_name);
-        buf += (*(ea->ea_entries))[count].ea_namelen + 1;
-
-        LOG(log_maxdebug, logtype_afpd, "pack_header: entry no:%u,\"%s\", size: %u, namelen: %u", count,
-            (*(ea->ea_entries))[count].ea_name,
-            (*(ea->ea_entries))[count].ea_size,
-            (*(ea->ea_entries))[count].ea_namelen);
-
-        count++;
-    }
-
-    ea->ea_count = eacount;
-
-    LOG(log_debug, logtype_afpd, "pack_header('%s'): ea_count: %u, ea_size: %u",
-        ea->filename, ea->ea_count, ea->ea_size);
-    
-    return 0;
-}
-
-/*
- * Function: ea_addentry
- *
- * Purpose: add one EA into ea->ea_entries[]
- *
- * Arguments:
- *
- *    ea            (rw) pointer to struct ea
- *    attruname     (r) name of EA
- *    attrsize      (r) size of ea
- *    bitmap        (r) bitmap from FP func
- *
- * Returns: new number of EA entries, -1 on error
- *
- * Effects:
- *
- * Grow array ea->ea_entries[]. If ea->ea_entries is still NULL, start allocating.
- * Otherwise realloc and put entry at the end. Increments ea->ea_count.
- */
-static int ea_addentry(struct ea * restrict ea,
-                       const char * restrict attruname,
-                       size_t attrsize,
-                       int bitmap)
-{
-    int ea_existed = 0;
-    unsigned int count = 0;
-    void *tmprealloc;
-
-    /* First check if an EA of the requested name already exist */
-    if (ea->ea_count > 0) {
-        while (count < ea->ea_count) {
-            if (strcmp(attruname, (*ea->ea_entries)[count].ea_name) == 0) {
-                ea_existed = 1;
-                LOG(log_debug, logtype_afpd, "ea_addentry('%s', bitmap:0x%x): exists", attruname, bitmap);
-                if (bitmap & kXAttrCreate)
-                    /* its like O_CREAT|O_EXCL -> fail */
-                    return -1;
-                (*(ea->ea_entries))[count].ea_size = attrsize;
-                return 0;
-            }
-            count++;
-        }
-    }
-
-    if ((bitmap & kXAttrReplace) && ! ea_existed)
-        /* replace was requested, but EA didn't exist */
-        return -1;
-
-    if (ea->ea_count == 0) {
-        ea->ea_entries = malloc(sizeof(struct ea_entry));
-        if ( ! ea->ea_entries) {
-            LOG(log_error, logtype_afpd, "ea_addentry: OOM");
-            return -1;
-        }
-    } else if (! ea_existed) {
-        tmprealloc = realloc(ea->ea_entries, sizeof(struct ea_entry) * (ea->ea_count + 1));
-        if ( ! tmprealloc) {
-            LOG(log_error, logtype_afpd, "ea_addentry: OOM");
-            return -1;
-        }
-        ea->ea_entries = tmprealloc;
-    }
-
-    /* We've grown the array, now store the entry */
-    (*(ea->ea_entries))[ea->ea_count].ea_size = attrsize;
-    (*(ea->ea_entries))[ea->ea_count].ea_name = strdup(attruname);
-    if ( ! (*(ea->ea_entries))[ea->ea_count].ea_name) {
-        LOG(log_error, logtype_afpd, "ea_addentry: OOM");
-        goto error;
-    }
-    (*(ea->ea_entries))[ea->ea_count].ea_namelen = strlen(attruname);
-
-    ea->ea_count++;
-    return ea->ea_count;
-
-error:
-    if (ea->ea_count == 0 && ea->ea_entries) {
-        /* We just allocated storage but had an error somewhere -> free storage*/
-        free(ea->ea_entries);
-        ea->ea_entries = NULL;
-    }
-    ea->ea_count = 0;
-    return -1;
-}
-
-/*
- * Function: create_ea_header
- *
- * Purpose: create EA header file, only called from ea_open
- *
- * Arguments:
- *
- *    uname       (r)  filename for which we have to create a header
- *    ea          (rw) ea handle with already allocated storage pointed to
- *                     by ea->ea_data
- *
- * Returns: fd of open header file on success, -1 on error, errno semantics:
- *          EEXIST: open with O_CREAT | O_EXCL failed
- *
- * Effects:
- *
- * Creates EA header file and initialize ea->ea_data buffer.
- * Possibe race condition with other afpd processes:
- * we were called because header file didn't exist in eg. ea_open. We then
- * try to create a file with O_CREAT | O_EXCL, but the whole process in not atomic.
- * What do we do then? Someone else is in the process of creating the header too, but
- * it might not have finished it. That means we cant just open, read and use it!
- * We therefor currently just break with an error.
- * On return the header file is still r/w locked.
- */
-static int create_ea_header(const char * restrict uname,
-                            struct ea * restrict ea)
-{
-    int fd = -1, err = 0;
-    char *ptr;
-
-    if ((fd = open(uname, O_RDWR | O_CREAT | O_EXCL, 0666 & ~ea->vol->v_umask)) == -1) {
-        LOG(log_error, logtype_afpd, "ea_create: open race condition with ea header for file: %s", uname);
-        return -1;
-    }
-
-    /* lock it */
-    if ((write_lock(fd, 0, SEEK_SET, 0)) != 0) {
-        LOG(log_error, logtype_afpd, "ea_create: lock race condition with ea header for file: %s", uname);
-        err = -1;
-        goto exit;
-    }
-
-    /* Now init it */
-    ptr = ea->ea_data;
-    *(uint32_t *)ptr = htonl(EA_MAGIC);
-    ptr += EA_MAGIC_LEN;
-    *(uint16_t *)ptr = htons(EA_VERSION);
-    ptr += EA_VERSION_LEN;
-    *(uint16_t *)ptr = 0;       /* count */
-
-    ea->ea_size = EA_HEADER_SIZE;
-    ea->ea_inited = EA_INITED;
-
-exit:
-    if (err != 0) {
-        close(fd);
-        fd = -1;
-    }
-    return fd;
-}
-
-/*
- * Function: write_ea
- *
- * Purpose: write an EA to disk
- *
- * Arguments:
- *
- *    ea         (r) struct ea handle
- *    attruname  (r) EA name
- *    ibuf       (r) buffer with EA content
- *    attrsize   (r) size of EA
- *
- * Returns: 0 on success, -1 on error
- *
- * Effects:
- *
- * Creates/overwrites EA file.
- *
- */
-static int write_ea(const struct ea * restrict ea,
-                    const char * restrict attruname,
-                    const char * restrict ibuf,
-                    size_t attrsize)
-{
-    int fd = -1, ret = AFP_OK;
-    struct stat st;
-    char *eaname;
-
-    if ((eaname = ea_path(ea, attruname, 1)) == NULL) {
-        LOG(log_error, logtype_afpd, "write_ea('%s'): ea_path error", attruname);
-        return AFPERR_MISC;
-    }
-
-    LOG(log_maxdebug, logtype_afpd, "write_ea('%s')", eaname);
-
-    /* Check if it exists, remove if yes*/
-    if ((stat(eaname, &st)) == 0) {
-        if ((unlink(eaname)) != 0) {
-            if (errno == EACCES)
-                return AFPERR_ACCESS;
-            else
-                return AFPERR_MISC;
-        }
-    }
-
-    if ((fd = open(eaname, O_RDWR | O_CREAT | O_EXCL, 0666 & ~ea->vol->v_umask)) == -1) {
-        LOG(log_error, logtype_afpd, "write_ea: open race condition: %s", eaname);
-        return -1;
-    }
-
-    /* lock it */
-    if ((write_lock(fd, 0, SEEK_SET, 0)) != 0) {
-        LOG(log_error, logtype_afpd, "write_ea: open race condition: %s", eaname);
-        ret = -1;
-        goto exit;
-    }
-
-    if (write(fd, ibuf, attrsize) != (ssize_t)attrsize) {
-        LOG(log_error, logtype_afpd, "write_ea('%s'): write: %s", eaname, strerror(errno));
-        ret = -1;
-        goto exit;
-    }
-
-exit:
-    if (fd != -1)
-        close(fd); /* and unlock */
-    return ret;
-}
-
-/*
- * Function: ea_delentry
- *
- * Purpose: delete one EA from ea->ea_entries[]
- *
- * Arguments:
- *
- *    ea            (rw) pointer to struct ea
- *    attruname     (r) EA name
- *
- * Returns: new number of EA entries, -1 on error
- *
- * Effects:
- *
- * Remove entry from  ea->ea_entries[]. Decrement ea->ea_count.
- * Marks it as unused just by freeing name and setting it to NULL.
- * ea_close and pack_buffer must honor this.
- */
-static int ea_delentry(struct ea * restrict ea, const char * restrict attruname)
-{
-    int ret = 0;
-    unsigned int count = 0;
-
-    if (ea->ea_count == 0) {
-        LOG(log_error, logtype_afpd, "ea_delentry('%s'): illegal ea_count of 0 on deletion",
-            attruname);
-        return -1;
-    }
-
-    while (count < ea->ea_count) {
-        /* search matching EA */
-        if ((*ea->ea_entries)[count].ea_name &&
-            strcmp(attruname, (*ea->ea_entries)[count].ea_name) == 0) {
-            free((*ea->ea_entries)[count].ea_name);
-            (*ea->ea_entries)[count].ea_name = NULL;
-
-            LOG(log_debug, logtype_afpd, "ea_delentry('%s'): deleted no %u/%u",
-                attruname, count + 1, ea->ea_count);
-
-            break;
-        }
-        count++;
-    }
-
-    return ret;
-}
-
-/*
- * Function: delete_ea_file
- *
- * Purpose: delete EA file from disk
- *
- * Arguments:
- *
- *    ea         (r) struct ea handle
- *    attruname  (r) EA name
- *
- * Returns: 0 on success, -1 on error
- */
-static int delete_ea_file(const struct ea * restrict ea, const char *eaname)
-{
-    int ret = 0;
-    char *eafile;
-    struct stat st;
-
-    if ((eafile = ea_path(ea, eaname, 1)) == NULL) {
-        LOG(log_error, logtype_afpd, "delete_ea_file('%s'): ea_path error", eaname);
-        return -1;
-    }
-
-    /* Check if it exists, remove if yes*/
-    if ((stat(eafile, &st)) == 0) {
-        if ((unlink(eafile)) != 0) {
-            LOG(log_error, logtype_afpd, "delete_ea_file('%s'): unlink: %s",
-                eafile, strerror(errno));
-            ret = -1;
-        } else
-            LOG(log_debug, logtype_afpd, "delete_ea_file('%s'): success", eafile);
-    }
-
-    return ret;
-}
-
-/*************************************************************************************
- * ea_path, ea_open and ea_close are only global so that dbd can call them
- *************************************************************************************/
-
-/*
- * Function: ea_path
- *
- * Purpose: return name of ea header filename
- *
- * Arguments:
- *
- *    ea           (r) ea handle
- *    eaname       (r) name of EA or NULL
- *    macname      (r) if != 0 call mtoupath on eaname
- *
- * Returns: pointer to name in static buffer, NULL on error
- *
- * Effects:
- *
- * Calls ad_open, copies buffer, appends "::EA" and if supplied append eanme
- * Files: "file" -> "file/.AppleDouble/file::EA"
- * Dirs: "dir" -> "dir/.AppleDouble/.Parent::EA"
- * "file" with EA "myEA" -> "file/.AppleDouble/file::EA:myEA"
- */
-char *ea_path(const struct ea * restrict ea, const char * restrict eaname, int macname)
-{
-    char *adname;
-    static char pathbuf[MAXPATHLEN + 1];
-
-    /* get name of a adouble file from uname */
-    adname = ea->vol->ad_path(ea->filename, (ea->ea_flags & EA_DIR) ? ADFLAGS_DIR : 0);
-    /* copy it so we can work with it */
-    strlcpy(pathbuf, adname, MAXPATHLEN + 1);
-    /* append "::EA" */
-    strlcat(pathbuf, "::EA", MAXPATHLEN + 1);
-
-    if (eaname) {
-        strlcat(pathbuf, "::", MAXPATHLEN + 1);
-        if (macname)
-            if ((eaname = mtoupath(ea->vol, eaname)) == NULL)
-                return NULL;
-        strlcat(pathbuf, eaname, MAXPATHLEN + 1);
-    }
-
-    return pathbuf;
-}
-
-/*
- * Function: ea_open
- *
- * Purpose: open EA header file, create if it doesnt exits and called with O_CREATE
- *
- * Arguments:
- *
- *    vol         (r) current volume
- *    uname       (r) filename for which we have to open a header
- *    flags       (r) EA_CREATE: create if it doesn't exist (without it won't be created)
- *                    EA_RDONLY: open read only
- *                    EA_RDWR: open read/write
- *                    Eiterh EA_RDONLY or EA_RDWR MUST be requested
- *    ea          (w) pointer to a struct ea that we fill
- *
- * Returns: 0 on success
- *         -1 on misc error with errno = EFAULT
- *         -2 if no EA header exists with errno = ENOENT
- *
- * Effects:
- *
- * opens header file and stores fd in ea->ea_fd. Size of file is put into ea->ea_size.
- * number of EAs is stored in ea->ea_count. flags are remembered in ea->ea_flags.
- * file is either read or write locked depending on the open flags.
- * When you're done with struct ea you must call ea_close on it.
- */
-int ea_open(const struct vol * restrict vol,
-            const char * restrict uname,
-            eaflags_t eaflags,
-            struct ea * restrict ea)
-{
-    int ret = 0;
-    char *eaname;
-    struct stat st;
-
-    /* Enforce usage rules! */
-    if ( ! (eaflags & (EA_RDONLY | EA_RDWR))) {
-        LOG(log_error, logtype_afpd, "ea_open: called without EA_RDONLY | EA_RDWR", uname);
-        return -1;
-    }
-
-    /* Set it all to 0 */
-    memset(ea, 0, sizeof(struct ea));
-
-    ea->vol = vol;              /* ea_close needs it */
-    ea->ea_flags = eaflags;
-    ea->dirfd = -1;             /* no *at (cf openat) semantics by default */
-
-    /* Dont care for errors, eg when removing the file is already gone */
-    if (!stat(uname, &st) && S_ISDIR(st.st_mode))
-        ea->ea_flags |=  EA_DIR;
-
-    if ( ! (ea->filename = strdup(uname))) {
-        LOG(log_error, logtype_afpd, "ea_open: OOM");
-        return -1;
-    }
-
-    eaname = ea_path(ea, NULL, 0);
-    LOG(log_maxdebug, logtype_afpd, "ea_open: ea_path: %s", eaname);
-
-    /* Check if it exists, if not create it if EA_CREATE is in eaflags */
-    if ((stat(eaname, &st)) != 0) {
-        if (errno == ENOENT) {
-
-            /* It doesnt exist */
-
-            if ( ! (eaflags & EA_CREATE)) {
-                /* creation was not requested, so return with error */
-                ret = -2;
-                goto exit;
-            }
-
-            /* Now create a header file */
-
-            /* malloc buffer for minimal on disk data */
-            ea->ea_data = malloc(EA_HEADER_SIZE);
-            if (! ea->ea_data) {
-                LOG(log_error, logtype_afpd, "ea_open: OOM");
-                ret = -1;
-                goto exit;
-            }
-
-            /* create it */
-            ea->ea_fd = create_ea_header(eaname, ea);
-            if (ea->ea_fd == -1) {
-                ret = -1;
-                goto exit;
-            }
-
-            return 0;
-
-        } else {/* errno != ENOENT */
-            ret = -1;
-            goto exit;
-        }
-    }
-
-    /* header file exists, so read and parse it */
-
-    /* malloc buffer where we read disk file into */
-    if (st.st_size < EA_HEADER_SIZE) {
-        LOG(log_error, logtype_afpd, "ea_open('%s'): bogus EA header file", eaname);
-        ret = -1;
-        goto exit;
-    }
-    ea->ea_size = st.st_size;
-    ea->ea_data = malloc(st.st_size);
-    if (! ea->ea_data) {
-        LOG(log_error, logtype_afpd, "ea_open: OOM");
-        ret = -1;
-        goto exit;
-    }
-
-    /* Now lock, open and read header file from disk */
-    if ((ea->ea_fd = open(eaname, (ea->ea_flags & EA_RDWR) ? O_RDWR : O_RDONLY)) == -1) {
-        LOG(log_error, logtype_afpd, "ea_open('%s'): error: %s", eaname, strerror(errno));
-        ret = -1;
-        goto exit;
-    }
-
-    /* lock it */
-    if (ea->ea_flags & EA_RDONLY) {
-        /* read lock */
-        if ((read_lock(ea->ea_fd, 0, SEEK_SET, 0)) != 0) {
-            LOG(log_error, logtype_afpd, "ea_open: lock error on  header: %s", eaname);
-            ret = -1;
-            goto exit;
-        }
-    } else {  /* EA_RDWR */
-        /* write lock */
-        if ((write_lock(ea->ea_fd, 0, SEEK_SET, 0)) != 0) {
-            LOG(log_error, logtype_afpd, "ea_open: lock error on  header: %s", eaname);
-            ret = -1;
-            goto exit;
-        }
-    }
-
-    /* read it */
-    if (read(ea->ea_fd, ea->ea_data, ea->ea_size) != (ssize_t)ea->ea_size) {
-        LOG(log_error, logtype_afpd, "ea_open: short read on header: %s", eaname);
-        ret = -1;
-        goto exit;
-    }
-
-    if ((unpack_header(ea)) != 0) {
-        LOG(log_error, logtype_afpd, "ea_open: error unpacking header for: %s", eaname);
-        ret = -1;
-        goto exit;
-    }
-
-exit:
-    switch (ret) {
-    case 0:
-        ea->ea_inited = EA_INITED;
-        break;
-    case -1:
-        errno = EFAULT; /* force some errno distinguishable from ENOENT */
-        /* fall through */
-    case -2:
-        if (ea->ea_data) {
-            free(ea->ea_data);
-            ea->ea_data = NULL;
-        }
-        if (ea->ea_fd) {
-            close(ea->ea_fd);
-            ea->ea_fd = -1;
-        }
-        break;
-    }
-
-    return ret;
-}
-
-/*
- * Function: ea_openat
- *
- * Purpose: openat like wrapper for ea_open, takes a additional file descriptor
- *
- * Arguments:
- *
- *    vol         (r) current volume
- *    sfd         (r) openat like file descriptor
- *    uname       (r) filename for which we have to open a header
- *    flags       (r) EA_CREATE: create if it doesn't exist (without it won't be created)
- *                    EA_RDONLY: open read only
- *                    EA_RDWR: open read/write
- *                    Eiterh EA_RDONLY or EA_RDWR MUST be requested
- *    ea          (w) pointer to a struct ea that we fill
- *
- * Returns: 0 on success
- *         -1 on misc error with errno = EFAULT
- *         -2 if no EA header exists with errno = ENOENT
- *
- * Effects:
- *
- * opens header file and stores fd in ea->ea_fd. Size of file is put into ea->ea_size.
- * number of EAs is stored in ea->ea_count. flags are remembered in ea->ea_flags.
- * file is either read or write locked depending on the open flags.
- * When you're done with struct ea you must call ea_close on it.
- */
-int ea_openat(const struct vol * restrict vol,
-              int dirfd,
-              const char * restrict uname,
-              eaflags_t eaflags,
-              struct ea * restrict ea)
-{
-    int ret = 0;
-    int cwdfd = -1;
-
-    if (dirfd != -1) {
-        if (((cwdfd = open(".", O_RDONLY)) == -1) || (fchdir(dirfd) != 0)) {
-            ret = -1;
-            goto exit;
-        }
-    }
-
-    ret = ea_open(vol, uname, eaflags, ea);
-    ea->dirfd = dirfd;
-
-    if (dirfd != -1) {
-        if (fchdir(cwdfd) != 0) {
-            LOG(log_error, logtype_afpd, "ea_openat: cant chdir back, exiting");
-            exit(EXITERR_SYS);
-        }
-    }
-
-
-exit:
-    if (cwdfd != -1)
-        close(cwdfd);
-
-    return ret;
-
-}
-
-/*
- * Function: ea_close
- *
- * Purpose: flushes and closes an ea handle
- *
- * Arguments:
- *
- *    ea          (rw) pointer to ea handle
- *
- * Returns: 0 on success, -1 on error
- *
- * Effects:
- *
- * Flushes and then closes and frees all resouces held by ea handle.
- * Pack data in ea into ea_data, then write ea_data to disk
- */
-int ea_close(struct ea * restrict ea)
-{
-    int ret = 0; 
-    unsigned int count = 0;
-    char *eaname;
-    struct stat st;
-
-    LOG(log_debug, logtype_afpd, "ea_close('%s')", ea->filename);
-
-    if (ea->ea_inited != EA_INITED) {
-        LOG(log_warning, logtype_afpd, "ea_close('%s'): non initialized ea", ea->filename);
-        return 0;
-    }
-
-    /* pack header and write it to disk if it was opened EA_RDWR*/
-    if (ea->ea_flags & EA_RDWR) {
-        if ((pack_header(ea)) != 0) {
-            LOG(log_error, logtype_afpd, "ea_close: pack header");
-            ret = -1;
-        } else {
-            if (ea->ea_count == 0) {
-                /* Check if EA header exists and remove it */
-                eaname = ea_path(ea, NULL, 0);
-                if ((lstatat(ea->dirfd, eaname, &st)) == 0) {
-                    if ((netatalk_unlinkat(ea->dirfd, eaname)) != 0) {
-                        LOG(log_error, logtype_afpd, "ea_close('%s'): unlink: %s",
-                            eaname, strerror(errno));
-                        ret = -1;
-                    }
-                    else
-                        LOG(log_debug, logtype_afpd, "ea_close(unlink '%s'): success", eaname);
-                } else {
-                    /* stat error */
-                    if (errno != ENOENT) {
-                        LOG(log_error, logtype_afpd, "ea_close('%s'): stat: %s",
-                            eaname, strerror(errno));
-                        ret = -1;
-                    }
-                }
-            } else { /* ea->ea_count > 0 */
-                if ((lseek(ea->ea_fd, 0, SEEK_SET)) == -1) {
-                    LOG(log_error, logtype_afpd, "ea_close: lseek: %s", strerror(errno));
-                    ret = -1;
-                    goto exit;
-                }
-
-                if ((ftruncate(ea->ea_fd, 0)) == -1) {
-                    LOG(log_error, logtype_afpd, "ea_close: ftruncate: %s", strerror(errno));
-                    ret = -1;
-                    goto exit;
-                }
-
-                if (write(ea->ea_fd, ea->ea_data, ea->ea_size) != (ssize_t)ea->ea_size) {
-                    LOG(log_error, logtype_afpd, "ea_close: write: %s", strerror(errno));
-                    ret = -1;
-                }
-            }
-        }
-    }
-
-exit:
-    /* free names */
-    while(count < ea->ea_count) {
-        if ( (*ea->ea_entries)[count].ea_name ) {
-            free((*ea->ea_entries)[count].ea_name);
-            (*ea->ea_entries)[count].ea_name = NULL;
-        }
-        count++;
-    }
-    ea->ea_count = 0;
-
-    if (ea->filename) {
-        free(ea->filename);
-        ea->filename = NULL;
-    }
-
-    if (ea->ea_entries) {
-        free(ea->ea_entries);
-        ea->ea_entries = NULL;
-    }
-
-    if (ea->ea_data) {
-        free(ea->ea_data);
-        ea->ea_data = NULL;
-    }
-    if (ea->ea_fd != -1) {
-        close(ea->ea_fd);       /* also releases the fcntl lock */
-        ea->ea_fd = -1;
-    }
-
-    return 0;
-}
-
-
-
-/************************************************************************************
- * VFS funcs called from afp_ea* funcs
- ************************************************************************************/
-
-/*
- * Function: get_easize
- *
- * Purpose: get size of an EA
- *
- * Arguments:
- *
- *    vol          (r) current volume
- *    rbuf         (w) DSI reply buffer
- *    rbuflen      (rw) current length of data in reply buffer
- *    uname        (r) filename
- *    oflag        (r) link and create flag
- *    attruname    (r) name of attribute
- *
- * Returns: AFP code: AFP_OK on success or appropiate AFP error code
- *
- * Effects:
- *
- * Copies EA size into rbuf in network order. Increments *rbuflen +4.
- */
-int get_easize(VFS_FUNC_ARGS_EA_GETSIZE)
-{
-    int ret = AFPERR_MISC;
-    unsigned int count = 0;
-    uint32_t uint32;
-    struct ea ea;
-
-    LOG(log_debug, logtype_afpd, "get_easize: file: %s", uname);
-
-    if ((ea_open(vol, uname, EA_RDONLY, &ea)) != 0) {
-        if (errno != ENOENT)
-            LOG(log_error, logtype_afpd, "get_easize: error calling ea_open for file: %s", uname);
-
-        memset(rbuf, 0, 4);
-        *rbuflen += 4;
-        return ret;
-    }
-
-    while (count < ea.ea_count) {
-        if (strcmp(attruname, (*ea.ea_entries)[count].ea_name) == 0) {
-            uint32 = htonl((*ea.ea_entries)[count].ea_size);
-            memcpy(rbuf, &uint32, 4);
-            *rbuflen += 4;
-            ret = AFP_OK;
-
-            LOG(log_debug, logtype_afpd, "get_easize(\"%s\"): size: %u",
-                attruname, (*ea.ea_entries)[count].ea_size);
-            break;
-        }
-        count++;
-    }
-
-    if ((ea_close(&ea)) != 0) {
-        LOG(log_error, logtype_afpd, "get_easize: error closing ea handle for file: %s", uname);
-        return AFPERR_MISC;
-    }
-
-    return ret;
-}
-
-/*
- * Function: get_eacontent
- *
- * Purpose: copy EA into rbuf
- *
- * Arguments:
- *
- *    vol          (r) current volume
- *    rbuf         (w) DSI reply buffer
- *    rbuflen      (rw) current length of data in reply buffer
- *    uname        (r) filename
- *    oflag        (r) link and create flag
- *    attruname    (r) name of attribute
- *    maxreply     (r) maximum EA size as of current specs/real-life
- *
- * Returns: AFP code: AFP_OK on success or appropiate AFP error code
- *
- * Effects:
- *
- * Copies EA into rbuf. Increments *rbuflen accordingly.
- */
-int get_eacontent(VFS_FUNC_ARGS_EA_GETCONTENT)
-{
-    int ret = AFPERR_MISC, fd = -1;
-    unsigned int count = 0;
-    uint32_t uint32;
-    size_t toread;
-    struct ea ea;
-    char *eafile;
-
-    LOG(log_debug, logtype_afpd, "get_eacontent('%s/%s')", uname, attruname);
-
-    if ((ea_open(vol, uname, EA_RDONLY, &ea)) != 0) {
-        if (errno != ENOENT)
-            LOG(log_error, logtype_afpd, "get_eacontent('%s'): ea_open error", uname);
-        memset(rbuf, 0, 4);
-        *rbuflen += 4;
-        return ret;
-    }
-
-    while (count < ea.ea_count) {
-        if (strcmp(attruname, (*ea.ea_entries)[count].ea_name) == 0) {
-            if ( (eafile = ea_path(&ea, attruname, 1)) == NULL) {
-                ret = AFPERR_MISC;
-                break;
-            }
-
-            if ((fd = open(eafile, O_RDONLY)) == -1) {
-                LOG(log_error, logtype_afpd, "get_eacontent('%s'): open error: %s", uname, strerror(errno));
-                ret = AFPERR_MISC;
-                break;
-            }
-
-            /* Check how much the client wants, give him what we think is right */
-            maxreply -= MAX_REPLY_EXTRA_BYTES;
-            if (maxreply > MAX_EA_SIZE)
-                maxreply = MAX_EA_SIZE;
-            toread = (maxreply < (*ea.ea_entries)[count].ea_size) ? maxreply : (*ea.ea_entries)[count].ea_size;
-            LOG(log_debug, logtype_afpd, "get_eacontent('%s'): sending %u bytes", attruname, toread);
-
-            /* Put length of EA data in reply buffer */
-            uint32 = htonl(toread);
-            memcpy(rbuf, &uint32, 4);
-            rbuf += 4;
-            *rbuflen += 4;
-
-            if (read(fd, rbuf, toread) != (ssize_t)toread) {
-                LOG(log_error, logtype_afpd, "get_eacontent('%s/%s'): short read", uname, attruname);
-                close(fd);
-                ret = AFPERR_MISC;
-                break;
-            }
-            *rbuflen += toread;
-            close(fd);
-
-            ret = AFP_OK;
-            break;
-        }
-        count++;
-    }
-
-    if ((ea_close(&ea)) != 0) {
-        LOG(log_error, logtype_afpd, "get_eacontent('%s'): error closing ea handle", uname);
-        return AFPERR_MISC;
-    }
-
-    return ret;
-
-}
-
-/*
- * Function: list_eas
- *
- * Purpose: copy names of EAs into attrnamebuf
- *
- * Arguments:
- *
- *    vol          (r) current volume
- *    attrnamebuf  (w) store names a consecutive C strings here
- *    buflen       (rw) length of names in attrnamebuf
- *    uname        (r) filename
- *    oflag        (r) link and create flag
- *
- * Returns: AFP code: AFP_OK on success or appropiate AFP error code
- *
- * Effects:
- *
- * Copies names of all EAs of uname as consecutive C strings into rbuf.
- * Increments *buflen accordingly.
- */
-int list_eas(VFS_FUNC_ARGS_EA_LIST)
-{
-    unsigned int count = 0;
-    int attrbuflen = *buflen, ret = AFP_OK, len;
-    char *buf = attrnamebuf;
-    struct ea ea;
-
-    LOG(log_debug, logtype_afpd, "list_eas: file: %s", uname);
-
-    if ((ea_open(vol, uname, EA_RDONLY, &ea)) != 0) {
-        if (errno != ENOENT) {
-            LOG(log_error, logtype_afpd, "list_eas: error calling ea_open for file: %s", uname);
-            return AFPERR_MISC;
-        }
-        else
-            return AFP_OK;
-    }
-
-    while (count < ea.ea_count) {
-        /* Convert name to CH_UTF8_MAC and directly store in in the reply buffer */
-        if ( ( len = convert_string(vol->v_volcharset,
-                                    CH_UTF8_MAC, 
-                                    (*ea.ea_entries)[count].ea_name,
-                                    (*ea.ea_entries)[count].ea_namelen,
-                                    buf + attrbuflen,
-                                    255))
-             <= 0 ) {
-            ret = AFPERR_MISC;
-            goto exit;
-        }
-        if (len == 255)
-            /* convert_string didn't 0-terminate */
-            attrnamebuf[attrbuflen + 255] = 0;
-
-        LOG(log_debug7, logtype_afpd, "list_eas(%s): EA: %s",
-            uname, (*ea.ea_entries)[count].ea_name);
-
-        attrbuflen += len + 1;
-        if (attrbuflen > (ATTRNAMEBUFSIZ - 256)) {
-            /* Next EA name could overflow, so bail out with error.
-               FIXME: evantually malloc/memcpy/realloc whatever.
-               Is it worth it ? */
-            LOG(log_warning, logtype_afpd, "list_eas(%s): running out of buffer for EA names", uname);
-            ret = AFPERR_MISC;
-            goto exit;
-        }
-        count++;
-    }
-
-exit:
-    *buflen = attrbuflen;
-
-    if ((ea_close(&ea)) != 0) {
-        LOG(log_error, logtype_afpd, "list_eas: error closing ea handle for file: %s", uname);
-        return AFPERR_MISC;
-    }
-
-    return ret;
-}
-
-/*
- * Function: set_ea
- *
- * Purpose: set a Solaris native EA
- *
- * Arguments:
- *
- *    vol          (r) current volume
- *    uname        (r) filename
- *    attruname    (r) EA name
- *    ibuf         (r) buffer with EA content
- *    attrsize     (r) length EA in ibuf
- *    oflag        (r) link and create flag
- *
- * Returns: AFP code: AFP_OK on success or appropiate AFP error code
- *
- * Effects:
- *
- * Copies names of all EAs of uname as consecutive C strings into rbuf.
- * Increments *rbuflen accordingly.
- */
-int set_ea(VFS_FUNC_ARGS_EA_SET)
-{
-    int ret = AFP_OK;
-    struct ea ea;
-
-    LOG(log_debug, logtype_afpd, "set_ea: file: %s", uname);
-
-    if ((ea_open(vol, uname, EA_CREATE | EA_RDWR, &ea)) != 0) {
-        LOG(log_error, logtype_afpd, "set_ea('%s'): ea_open error", uname);
-        return AFPERR_MISC;
-    }
-
-    if ((ea_addentry(&ea, attruname, attrsize, oflag)) == -1) {
-        LOG(log_error, logtype_afpd, "set_ea('%s'): ea_addentry error", uname);
-        ret = AFPERR_MISC;
-        goto exit;
-    }
-
-    if ((write_ea(&ea, attruname, ibuf, attrsize)) != 0) {
-        LOG(log_error, logtype_afpd, "set_ea('%s'): write_ea error", uname);
-        ret = AFPERR_MISC;
-        goto exit;
-    }
-
-exit:
-    if ((ea_close(&ea)) != 0) {
-        LOG(log_error, logtype_afpd, "set_ea('%s'): ea_close error", uname);
-        ret = AFPERR_MISC;
-        goto exit;
-    }
-
-    return ret;
-}
-
-/*
- * Function: remove_ea
- *
- * Purpose: remove a EA from a file
- *
- * Arguments:
- *
- *    vol          (r) current volume
- *    uname        (r) filename
- *    attruname    (r) EA name
- *    oflag        (r) link and create flag
- *
- * Returns: AFP code: AFP_OK on success or appropiate AFP error code
- *
- * Effects:
- *
- * Removes EA attruname from file uname.
- */
-int remove_ea(VFS_FUNC_ARGS_EA_REMOVE)
-{
-    int ret = AFP_OK;
-    struct ea ea;
-
-    LOG(log_debug, logtype_afpd, "remove_ea('%s/%s')", uname, attruname);
-
-    if ((ea_open(vol, uname, EA_RDWR, &ea)) != 0) {
-        LOG(log_error, logtype_afpd, "remove_ea('%s'): ea_open error", uname);
-        return AFPERR_MISC;
-    }
-
-    if ((ea_delentry(&ea, attruname)) == -1) {
-        LOG(log_error, logtype_afpd, "remove_ea('%s'): ea_delentry error", uname);
-        ret = AFPERR_MISC;
-        goto exit;
-    }
-
-    if ((delete_ea_file(&ea, attruname)) != 0) {
-        LOG(log_error, logtype_afpd, "remove_ea('%s'): delete_ea error", uname);
-        ret = AFPERR_MISC;
-        goto exit;
-    }
-
-exit:
-    if ((ea_close(&ea)) != 0) {
-        LOG(log_error, logtype_afpd, "remove_ea('%s'): ea_close error", uname);
-        ret = AFPERR_MISC;
-        goto exit;
-    }
-
-    return ret;
-}
-
-/******************************************************************************************
- * EA VFS funcs that deal with file/dir cp/mv/rm
- ******************************************************************************************/
-
-int ea_deletefile(VFS_FUNC_ARGS_DELETEFILE)
-{
-    unsigned int count = 0;
-    int ret = AFP_OK;
-    int cwd = -1;
-    struct ea ea;
-
-    LOG(log_debug, logtype_afpd, "ea_deletefile('%s')", file);
-
-    /* Open EA stuff */
-    if ((ea_openat(vol, dirfd, file, EA_RDWR, &ea)) != 0) {
-        if (errno == ENOENT)
-            /* no EA files, nothing to do */
-            return AFP_OK;
-        else {
-            LOG(log_error, logtype_afpd, "ea_deletefile('%s'): error calling ea_open", file);
-            return AFPERR_MISC;
-        }
-    }
-
-    if (dirfd != -1) {
-        if (((cwd = open(".", O_RDONLY)) == -1) || (fchdir(dirfd) != 0)) {
-            ret = AFPERR_MISC;
-            goto exit;
-        }
-    }
-
-    while (count < ea.ea_count) {
-        if ((delete_ea_file(&ea, (*ea.ea_entries)[count].ea_name)) != 0) {
-            ret = AFPERR_MISC;
-            continue;
-        }
-        free((*ea.ea_entries)[count].ea_name);
-        (*ea.ea_entries)[count].ea_name = NULL;
-        count++;
-    }
-
-    /* ea_close removes the EA header file for us because all names are NULL */
-    if ((ea_close(&ea)) != 0) {
-        LOG(log_error, logtype_afpd, "ea_deletefile('%s'): error closing ea handle", file);
-        ret = AFPERR_MISC;
-    }
-
-    if (dirfd != -1 && fchdir(cwd) != 0) {
-        LOG(log_error, logtype_afpd, "ea_deletefile: cant chdir back. exit!");
-        exit(EXITERR_SYS);
-    }
-
-exit:
-    if (cwd != -1)
-        close(cwd);
-
-    return ret;
-}
-
-int ea_renamefile(VFS_FUNC_ARGS_RENAMEFILE)
-{
-    unsigned int count = 0;
-    int    ret = AFP_OK;
-    size_t easize;
-    char   srceapath[ MAXPATHLEN + 1];
-    char   *eapath;
-    char   *eaname;
-    struct ea srcea;
-    struct ea dstea;
-    struct adouble ad;
-
-    LOG(log_debug, logtype_afpd, "ea_renamefile('%s'/'%s')", src, dst);
-            
-
-    /* Open EA stuff */
-    if ((ea_openat(vol, dirfd, src, EA_RDWR, &srcea)) != 0) {
-        if (errno == ENOENT)
-            /* no EA files, nothing to do */
-            return AFP_OK;
-        else {
-            LOG(log_error, logtype_afpd, "ea_renamefile('%s'/'%s'): ea_open error: '%s'", src, dst, src);
-            return AFPERR_MISC;
-        }
-    }
-
-    if ((ea_open(vol, dst, EA_RDWR | EA_CREATE, &dstea)) != 0) {
-        if (errno == ENOENT) {
-            /* Possibly the .AppleDouble folder didn't exist, we create it and try again */
-            ad_init(&ad, vol->v_adouble, vol->v_ad_options); 
-            if ((ad_open(dst, ADFLAGS_HF, O_RDWR | O_CREAT, 0666, &ad)) != 0) {
-                LOG(log_error, logtype_afpd, "ea_renamefile('%s/%s'): ad_open error: '%s'", src, dst, dst);
-                ret = AFPERR_MISC;
-                goto exit;
-            }
-            ad_close(&ad, ADFLAGS_HF);
-            if ((ea_open(vol, dst, EA_RDWR | EA_CREATE, &dstea)) != 0) {
-                ret = AFPERR_MISC;
-                goto exit;
-            }
-        }
-    }
-
-    /* Loop through all EAs: */
-    while (count < srcea.ea_count) {
-        /* Move EA */
-        eaname = (*srcea.ea_entries)[count].ea_name;
-        easize = (*srcea.ea_entries)[count].ea_size;
-
-        /* Build src and dst paths for rename() */
-        if ((eapath = ea_path(&srcea, eaname, 1)) == NULL) {
-            ret = AFPERR_MISC;
-            goto exit;
-        }
-        strcpy(srceapath, eapath);
-        if ((eapath = ea_path(&dstea, eaname, 1)) == NULL) {
-            ret = AFPERR_MISC;
-            goto exit;
-        }
-
-        LOG(log_maxdebug, logtype_afpd, "ea_renamefile('%s/%s'): moving EA '%s' to '%s'",
-            src, dst, srceapath, eapath);
-
-        /* Add EA to dstea */
-        if ((ea_addentry(&dstea, eaname, easize, 0)) == -1) {
-            LOG(log_error, logtype_afpd, "ea_renamefile('%s/%s'): moving EA '%s' to '%s'",
-                src, dst, srceapath, eapath);
-            ret = AFPERR_MISC;
-            goto exit;
-        }
-
-        /* Remove EA entry from srcea */
-        if ((ea_delentry(&srcea, eaname)) == -1) {
-            LOG(log_error, logtype_afpd, "ea_renamefile('%s/%s'): moving EA '%s' to '%s'",
-                src, dst, srceapath, eapath);
-            ea_delentry(&dstea, eaname);
-            ret = AFPERR_MISC;
-            goto exit;
-        }
-
-        /* Now rename the EA */
-        if ((unix_rename(dirfd, srceapath, -1, eapath)) < 0) {
-            LOG(log_error, logtype_afpd, "ea_renamefile('%s/%s'): moving EA '%s' to '%s'",
-                src, dst, srceapath, eapath);
-            ret = AFPERR_MISC;
-            goto exit;
-        }
-
-        count++;
-    }
-
-
-exit:
-    ea_close(&srcea);
-    ea_close(&dstea);
-       return ret;
-}
-
-int ea_copyfile(VFS_FUNC_ARGS_COPYFILE)
-{
-    unsigned int count = 0;
-    int    ret = AFP_OK;
-    size_t easize;
-    char   srceapath[ MAXPATHLEN + 1];
-    char   *eapath;
-    char   *eaname;
-    struct ea srcea;
-    struct ea dstea;
-    struct adouble ad;
-
-    LOG(log_debug, logtype_afpd, "ea_copyfile('%s'/'%s')", src, dst);
-
-    /* Open EA stuff */
-    if ((ea_openat(vol, sfd, src, EA_RDWR, &srcea)) != 0) {
-        if (errno == ENOENT)
-            /* no EA files, nothing to do */
-            return AFP_OK;
-        else {
-            LOG(log_error, logtype_afpd, "ea_copyfile('%s'/'%s'): ea_open error: '%s'", src, dst, src);
-            return AFPERR_MISC;
-        }
-    }
-
-    if ((ea_open(vol, dst, EA_RDWR | EA_CREATE, &dstea)) != 0) {
-        if (errno == ENOENT) {
-            /* Possibly the .AppleDouble folder didn't exist, we create it and try again */
-            ad_init(&ad, vol->v_adouble, vol->v_ad_options); 
-            if ((ad_open(dst, ADFLAGS_HF, O_RDWR | O_CREAT, 0666, &ad)) != 0) {
-                LOG(log_error, logtype_afpd, "ea_copyfile('%s/%s'): ad_open error: '%s'", src, dst, dst);
-                ret = AFPERR_MISC;
-                goto exit;
-            }
-            ad_close(&ad, ADFLAGS_HF);
-            if ((ea_open(vol, dst, EA_RDWR | EA_CREATE, &dstea)) != 0) {
-                ret = AFPERR_MISC;
-                goto exit;
-            }
-        }
-    }
-
-    /* Loop through all EAs: */
-    while (count < srcea.ea_count) {
-        /* Copy EA */
-        eaname = (*srcea.ea_entries)[count].ea_name;
-        easize = (*srcea.ea_entries)[count].ea_size;
-
-        /* Build src and dst paths for copy_file() */
-        if ((eapath = ea_path(&srcea, eaname, 1)) == NULL) {
-            ret = AFPERR_MISC;
-            goto exit;
-        }
-        strcpy(srceapath, eapath);
-        if ((eapath = ea_path(&dstea, eaname, 1)) == NULL) {
-            ret = AFPERR_MISC;
-            goto exit;
-        }
-
-        LOG(log_maxdebug, logtype_afpd, "ea_copyfile('%s/%s'): copying EA '%s' to '%s'",
-            src, dst, srceapath, eapath);
-
-        /* Add EA to dstea */
-        if ((ea_addentry(&dstea, eaname, easize, 0)) == -1) {
-            LOG(log_error, logtype_afpd, "ea_copyfile('%s/%s'): ea_addentry('%s') error",
-                src, dst, eaname);
-            ret = AFPERR_MISC;
-            goto exit;
-        }
-
-        /* Now copy the EA */
-        if ((copy_file(sfd, srceapath, eapath, (0666 & ~vol->v_umask))) < 0) {
-            LOG(log_error, logtype_afpd, "ea_copyfile('%s/%s'): copying EA '%s' to '%s'",
-                src, dst, srceapath, eapath);
-            ret = AFPERR_MISC;
-            goto exit;
-        }
-
-        count++;
-    }
-
-exit:
-    ea_close(&srcea);
-    ea_close(&dstea);
-       return ret;
-}
-
-int ea_chown(VFS_FUNC_ARGS_CHOWN)
-{
-
-    unsigned int count = 0;
-    int ret = AFP_OK;
-    char *eaname;
-    struct ea ea;
-
-    LOG(log_debug, logtype_afpd, "ea_chown('%s')", path);
-    /* Open EA stuff */
-    if ((ea_open(vol, path, EA_RDWR, &ea)) != 0) {
-        if (errno == ENOENT)
-            /* no EA files, nothing to do */
-            return AFP_OK;
-        else {
-            LOG(log_error, logtype_afpd, "ea_chown('%s'): error calling ea_open", path);
-            return AFPERR_MISC;
-        }
-    }
-
-    if ((lchown(ea_path(&ea, NULL, 0), uid, gid)) != 0) {
-        switch (errno) {
-        case EPERM:
-        case EACCES:
-            ret = AFPERR_ACCESS;
-            goto exit;
-        default:
-            ret = AFPERR_MISC;
-            goto exit;
-        }
-    }
-
-    while (count < ea.ea_count) {
-        if ((eaname = ea_path(&ea, (*ea.ea_entries)[count].ea_name, 1)) == NULL) {
-            ret = AFPERR_MISC;
-            goto exit;
-        }
-        if ((lchown(eaname, uid, gid)) != 0) {
-            switch (errno) {
-            case EPERM:
-            case EACCES:
-                ret = AFPERR_ACCESS;
-                goto exit;
-            default:
-                ret = AFPERR_MISC;
-                goto exit;
-            }
-            continue;
-        }
-
-        count++;
-    }
-
-exit:
-    if ((ea_close(&ea)) != 0) {
-        LOG(log_error, logtype_afpd, "ea_chown('%s'): error closing ea handle", path);
-        return AFPERR_MISC;
-    }
-
-    return ret;
-}
-
-int ea_chmod_file(VFS_FUNC_ARGS_SETFILEMODE)
-{
-
-    unsigned int count = 0;
-    int ret = AFP_OK;
-    const char *eaname;
-    struct ea ea;
-
-    LOG(log_debug, logtype_afpd, "ea_chmod_file('%s')", name);
-    /* Open EA stuff */
-    if ((ea_open(vol, name, EA_RDWR, &ea)) != 0) {
-        if (errno == ENOENT)
-            /* no EA files, nothing to do */
-            return AFP_OK;
-        else
-            return AFPERR_MISC;
-    }
-
-    /* Set mode on EA header file */
-    if ((setfilmode(ea_path(&ea, NULL, 0), ea_header_mode(mode), NULL, vol->v_umask)) != 0) {
-        LOG(log_error, logtype_afpd, "ea_chmod_file('%s'): %s", ea_path(&ea, NULL, 0), strerror(errno));
-        switch (errno) {
-        case EPERM:
-        case EACCES:
-            ret = AFPERR_ACCESS;
-            goto exit;
-        default:
-            ret = AFPERR_MISC;
-            goto exit;
-        }
-    }
-
-    /* Set mode on EA files */
-    while (count < ea.ea_count) {
-        if ((eaname = ea_path(&ea, (*ea.ea_entries)[count].ea_name, 1)) == NULL) {
-            ret = AFPERR_MISC;
-            goto exit;
-        }
-        if ((setfilmode(eaname, ea_mode(mode), NULL, vol->v_umask)) != 0) {
-            LOG(log_error, logtype_afpd, "ea_chmod_file('%s'): %s", eaname, strerror(errno));
-            switch (errno) {
-            case EPERM:
-            case EACCES:
-                ret = AFPERR_ACCESS;
-                goto exit;
-            default:
-                ret = AFPERR_MISC;
-                goto exit;
-            }
-            continue;
-        }
-
-        count++;
-    }
-
-exit:
-    if ((ea_close(&ea)) != 0) {
-        LOG(log_error, logtype_afpd, "ea_chmod_file('%s'): error closing ea handle", name);
-        return AFPERR_MISC;
-    }
-
-    return ret;
-}
-
-int ea_chmod_dir(VFS_FUNC_ARGS_SETDIRUNIXMODE)
-{
-
-    int ret = AFP_OK;
-    unsigned int count = 0;
-    uid_t uid;
-    const char *eaname;
-    const char *eaname_safe = NULL;
-    struct ea ea;
-
-    LOG(log_debug, logtype_afpd, "ea_chmod_dir('%s')", name);
-    /* .AppleDouble already might be inaccesible, so we must run as id 0 */
-    uid = geteuid();
-    if (seteuid(0)) {
-        LOG(log_error, logtype_afpd, "ea_chmod_dir('%s'): seteuid: %s", name, strerror(errno));
-        return AFPERR_MISC;
-    }
-
-    /* Open EA stuff */
-    if ((ea_open(vol, name, EA_RDWR, &ea)) != 0) {
-        /* ENOENT --> no EA files, nothing to do */
-        if (errno != ENOENT)
-            ret = AFPERR_MISC;
-        if (seteuid(uid) < 0) {
-            LOG(log_error, logtype_afpd, "can't seteuid back: %s", strerror(errno));
-            exit(EXITERR_SYS);
-        }
-        return ret;
-    }
-
-    /* Set mode on EA header */
-    if ((setfilmode(ea_path(&ea, NULL, 0), ea_header_mode(mode), NULL, vol->v_umask)) != 0) {
-        LOG(log_error, logtype_afpd, "ea_chmod_dir('%s'): %s", ea_path(&ea, NULL, 0), strerror(errno));
-        switch (errno) {
-        case EPERM:
-        case EACCES:
-            ret = AFPERR_ACCESS;
-            goto exit;
-        default:
-            ret = AFPERR_MISC;
-            goto exit;
-        }
-    }
-
-    /* Set mode on EA files */
-    while (count < ea.ea_count) {
-        eaname = (*ea.ea_entries)[count].ea_name;
-        /*
-         * Be careful with EA names from the EA header!
-         * Eg NFS users might have access to them, can inject paths using ../ or /.....
-         * FIXME:
-         * Until the EA code escapes / in EA name requests from the client, these therefor wont work.
-         */
-        if ((eaname_safe = strrchr(eaname, '/'))) {
-            LOG(log_warning, logtype_afpd, "ea_chmod_dir('%s'): contains a slash", eaname);
-            eaname = eaname_safe;
-        }
-        if ((eaname = ea_path(&ea, eaname, 1)) == NULL) {
-            ret = AFPERR_MISC;
-            goto exit;
-        }
-        if ((setfilmode(eaname, ea_mode(mode), NULL, vol->v_umask)) != 0) {
-            LOG(log_error, logtype_afpd, "ea_chmod_dir('%s'): %s", eaname, strerror(errno));
-            switch (errno) {
-            case EPERM:
-            case EACCES:
-                ret = AFPERR_ACCESS;
-                goto exit;
-            default:
-                ret = AFPERR_MISC;
-                goto exit;
-            }
-            continue;
-        }
-
-        count++;
-    }
-
-exit:
-    if (seteuid(uid) < 0) {
-        LOG(log_error, logtype_afpd, "can't seteuid back: %s", strerror(errno));
-        exit(EXITERR_SYS);
-    }
-
-    if ((ea_close(&ea)) != 0) {
-        LOG(log_error, logtype_afpd, "ea_chmod_dir('%s'): error closing ea handle", name);
-        return AFPERR_MISC;
-    }
-
-    return ret;
-}
diff --git a/libatalk/vfs/ea_ad.c b/libatalk/vfs/ea_ad.c
new file mode 100644 (file)
index 0000000..0bee141
--- /dev/null
@@ -0,0 +1,1772 @@
+/*
+  Copyright (c) 2009 Frank Lahm <franklahm@gmail.com>
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 2 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+*/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
+#include <unistd.h>
+#include <stdint.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <dirent.h>
+#include <arpa/inet.h>
+
+#include <atalk/adouble.h>
+#include <atalk/ea.h>
+#include <atalk/afp.h>
+#include <atalk/logger.h>
+#include <atalk/volume.h>
+#include <atalk/vfs.h>
+#include <atalk/util.h>
+#include <atalk/unix.h>
+#include <atalk/compat.h>
+
+/*
+ * Store Extended Attributes inside .AppleDouble folders as follows:
+ *
+ * filename "fileWithEAs" with EAs "testEA1" and "testEA2"
+ *
+ * - create header with with the format struct adouble_ea_ondisk, the file is written to
+ *   ".AppleDouble/fileWithEAs::EA"
+ * - store EAs in files "fileWithEAs::EA::testEA1" and "fileWithEAs::EA::testEA2"
+ */
+
+/* 
+ * Build mode for EA header from file mode
+ */
+static inline mode_t ea_header_mode(mode_t mode)
+{
+    /* Same as ad_hf_mode(mode) */
+    mode &= ~(S_IXUSR | S_IXGRP | S_IXOTH);
+    /* Owner must be able to open, read and w-lock it, in order to chmod from eg 0000 -> 0xxxx*/
+    mode |= S_IRUSR | S_IWUSR;
+    return mode;
+}
+
+/* 
+ * Build mode for EA file from file mode
+ */
+static inline mode_t ea_mode(mode_t mode)
+{
+    /* Same as ad_hf_mode(mode) */
+    mode &= ~(S_IXUSR | S_IXGRP | S_IXOTH);
+    return mode;
+}
+
+/*
+  Taken form afpd/desktop.c
+*/
+static char *mtoupath(const struct vol *vol, const char *mpath)
+{
+    static char  upath[ MAXPATHLEN + 2]; /* for convert_charset dest_len parameter +2 */
+    const char   *m;
+    char         *u;
+    size_t       inplen;
+    size_t       outlen;
+    uint16_t     flags = CONV_ESCAPEHEX | CONV_ALLOW_COLON;
+
+    if (!mpath)
+        return NULL;
+
+    if ( *mpath == '\0' ) {
+        return( "." );
+    }
+
+    m = mpath;
+    u = upath;
+
+    inplen = strlen(m);
+    outlen = MAXPATHLEN;
+
+    if ((size_t)-1 == (outlen = convert_charset(CH_UTF8_MAC,
+                                                vol->v_volcharset,
+                                                vol->v_maccharset,
+                                                m, inplen, u, outlen, &flags)) ) {
+        return NULL;
+    }
+
+    return( upath );
+}
+
+
+/*
+ * Function: unpack_header
+ *
+ * Purpose: unpack and verify header file data buffer at ea->ea_data into struct ea
+ *
+ * Arguments:
+ *
+ *    ea      (rw) handle to struct ea
+ *
+ * Returns: 0 on success, -1 on error
+ *
+ * Effects:
+ *
+ * Verifies magic and version.
+ */
+static int unpack_header(struct ea * restrict ea)
+{
+    int ret = 0;
+    unsigned int count = 0;
+    uint32_t uint32;
+    char *buf;
+
+    /* Check magic and version */
+    buf = ea->ea_data;
+    if (*(uint32_t *)buf != htonl(EA_MAGIC)) {
+        LOG(log_error, logtype_afpd, "unpack_header: wrong magic 0x%08x", *(uint32_t *)buf);
+        ret = -1;
+        goto exit;
+    }
+    buf += 4;
+    if (*(uint16_t *)buf != htons(EA_VERSION)) {
+        LOG(log_error, logtype_afpd, "unpack_header: wrong version 0x%04x", *(uint16_t *)buf);
+        ret = -1;
+        goto exit;
+    }
+    buf += 2;
+
+    /* Get EA count */
+    ea->ea_count = ntohs(*(uint16_t *)buf);
+    LOG(log_debug, logtype_afpd, "unpack_header: number of EAs: %u", ea->ea_count);
+    buf += 2;
+
+    if (ea->ea_count == 0)
+        return 0;
+
+    /* Allocate storage for the ea_entries array */
+    ea->ea_entries = malloc(sizeof(struct ea_entry) * ea->ea_count);
+    if ( ! ea->ea_entries) {
+        LOG(log_error, logtype_afpd, "unpack_header: OOM");
+        ret = -1;
+        goto exit;
+    }
+
+    buf = ea->ea_data + EA_HEADER_SIZE;
+    while (count < ea->ea_count) {
+        memcpy(&uint32, buf, 4); /* EA size */
+        buf += 4;
+        (*(ea->ea_entries))[count].ea_size = ntohl(uint32);
+        (*(ea->ea_entries))[count].ea_name = strdup(buf);
+        if (! (*(ea->ea_entries))[count].ea_name) {
+            LOG(log_error, logtype_afpd, "unpack_header: OOM");
+            ret = -1;
+            goto exit;
+        }
+        (*(ea->ea_entries))[count].ea_namelen = strlen((*(ea->ea_entries))[count].ea_name);
+        buf += (*(ea->ea_entries))[count].ea_namelen + 1;
+
+        LOG(log_maxdebug, logtype_afpd, "unpack_header: entry no:%u,\"%s\", size: %u, namelen: %u", count,
+            (*(ea->ea_entries))[count].ea_name,
+            (*(ea->ea_entries))[count].ea_size,
+            (*(ea->ea_entries))[count].ea_namelen);
+
+        count++;
+    }
+
+exit:
+    return ret;
+}
+
+/*
+ * Function: pack_header
+ *
+ * Purpose: pack everything from struct ea into buffer at ea->ea_data
+ *
+ * Arguments:
+ *
+ *    ea      (rw) handle to struct ea
+ *
+ * Returns: 0 on success, -1 on error
+ *
+ * Effects:
+ *
+ * adjust ea->ea_count in case an ea entry deletetion is detected
+ */
+static int pack_header(struct ea * restrict ea)
+{
+    unsigned int count = 0, eacount = 0;
+    uint16_t uint16;
+    uint32_t uint32;
+    size_t bufsize = EA_HEADER_SIZE;
+
+    char *buf = ea->ea_data + EA_HEADER_SIZE;
+
+    LOG(log_debug, logtype_afpd, "pack_header('%s'): ea_count: %u, ea_size: %u",
+        ea->filename, ea->ea_count, ea->ea_size);
+
+    if (ea->ea_count == 0)
+        /* nothing to do, magic, version and count are still valid in buffer */
+        return 0;
+
+    while(count < ea->ea_count) { /* the names */
+        /* Check if its a deleted entry */
+        if ( ! ((*ea->ea_entries)[count].ea_name)) {
+            count++;
+            continue;
+        }
+
+        bufsize += (*(ea->ea_entries))[count].ea_namelen + 1;
+        count++;
+        eacount++;
+    }
+
+    bufsize += (eacount * 4); /* header + ea_size for each EA */
+    if (bufsize > ea->ea_size) {
+        /* we must realloc */
+        if ( ! (buf = realloc(ea->ea_data, bufsize)) ) {
+            LOG(log_error, logtype_afpd, "pack_header: OOM");
+            return -1;
+        }
+        ea->ea_data = buf;
+    }
+    ea->ea_size = bufsize;
+
+    /* copy count */
+    uint16 = htons(eacount);
+    memcpy(ea->ea_data + EA_COUNT_OFF, &uint16, 2);
+
+    count = 0;
+    buf = ea->ea_data + EA_HEADER_SIZE;
+    while (count < ea->ea_count) {
+        /* Check if its a deleted entry */
+        if ( ! ((*ea->ea_entries)[count].ea_name)) {
+            count++;
+            continue;
+        }
+
+        /* First: EA size */
+        uint32 = htonl((*(ea->ea_entries))[count].ea_size);
+        memcpy(buf, &uint32, 4);
+        buf += 4;
+
+        /* Second: EA name as C-string */
+        strcpy(buf, (*(ea->ea_entries))[count].ea_name);
+        buf += (*(ea->ea_entries))[count].ea_namelen + 1;
+
+        LOG(log_maxdebug, logtype_afpd, "pack_header: entry no:%u,\"%s\", size: %u, namelen: %u", count,
+            (*(ea->ea_entries))[count].ea_name,
+            (*(ea->ea_entries))[count].ea_size,
+            (*(ea->ea_entries))[count].ea_namelen);
+
+        count++;
+    }
+
+    ea->ea_count = eacount;
+
+    LOG(log_debug, logtype_afpd, "pack_header('%s'): ea_count: %u, ea_size: %u",
+        ea->filename, ea->ea_count, ea->ea_size);
+    
+    return 0;
+}
+
+/*
+ * Function: ea_addentry
+ *
+ * Purpose: add one EA into ea->ea_entries[]
+ *
+ * Arguments:
+ *
+ *    ea            (rw) pointer to struct ea
+ *    attruname     (r) name of EA
+ *    attrsize      (r) size of ea
+ *    bitmap        (r) bitmap from FP func
+ *
+ * Returns: new number of EA entries, -1 on error
+ *
+ * Effects:
+ *
+ * Grow array ea->ea_entries[]. If ea->ea_entries is still NULL, start allocating.
+ * Otherwise realloc and put entry at the end. Increments ea->ea_count.
+ */
+static int ea_addentry(struct ea * restrict ea,
+                       const char * restrict attruname,
+                       size_t attrsize,
+                       int bitmap)
+{
+    int ea_existed = 0;
+    unsigned int count = 0;
+    void *tmprealloc;
+
+    /* First check if an EA of the requested name already exist */
+    if (ea->ea_count > 0) {
+        while (count < ea->ea_count) {
+            if (strcmp(attruname, (*ea->ea_entries)[count].ea_name) == 0) {
+                ea_existed = 1;
+                LOG(log_debug, logtype_afpd, "ea_addentry('%s', bitmap:0x%x): exists", attruname, bitmap);
+                if (bitmap & kXAttrCreate)
+                    /* its like O_CREAT|O_EXCL -> fail */
+                    return -1;
+                (*(ea->ea_entries))[count].ea_size = attrsize;
+                return 0;
+            }
+            count++;
+        }
+    }
+
+    if ((bitmap & kXAttrReplace) && ! ea_existed)
+        /* replace was requested, but EA didn't exist */
+        return -1;
+
+    if (ea->ea_count == 0) {
+        ea->ea_entries = malloc(sizeof(struct ea_entry));
+        if ( ! ea->ea_entries) {
+            LOG(log_error, logtype_afpd, "ea_addentry: OOM");
+            return -1;
+        }
+    } else if (! ea_existed) {
+        tmprealloc = realloc(ea->ea_entries, sizeof(struct ea_entry) * (ea->ea_count + 1));
+        if ( ! tmprealloc) {
+            LOG(log_error, logtype_afpd, "ea_addentry: OOM");
+            return -1;
+        }
+        ea->ea_entries = tmprealloc;
+    }
+
+    /* We've grown the array, now store the entry */
+    (*(ea->ea_entries))[ea->ea_count].ea_size = attrsize;
+    (*(ea->ea_entries))[ea->ea_count].ea_name = strdup(attruname);
+    if ( ! (*(ea->ea_entries))[ea->ea_count].ea_name) {
+        LOG(log_error, logtype_afpd, "ea_addentry: OOM");
+        goto error;
+    }
+    (*(ea->ea_entries))[ea->ea_count].ea_namelen = strlen(attruname);
+
+    ea->ea_count++;
+    return ea->ea_count;
+
+error:
+    if (ea->ea_count == 0 && ea->ea_entries) {
+        /* We just allocated storage but had an error somewhere -> free storage*/
+        free(ea->ea_entries);
+        ea->ea_entries = NULL;
+    }
+    ea->ea_count = 0;
+    return -1;
+}
+
+/*
+ * Function: create_ea_header
+ *
+ * Purpose: create EA header file, only called from ea_open
+ *
+ * Arguments:
+ *
+ *    uname       (r)  filename for which we have to create a header
+ *    ea          (rw) ea handle with already allocated storage pointed to
+ *                     by ea->ea_data
+ *
+ * Returns: fd of open header file on success, -1 on error, errno semantics:
+ *          EEXIST: open with O_CREAT | O_EXCL failed
+ *
+ * Effects:
+ *
+ * Creates EA header file and initialize ea->ea_data buffer.
+ * Possibe race condition with other afpd processes:
+ * we were called because header file didn't exist in eg. ea_open. We then
+ * try to create a file with O_CREAT | O_EXCL, but the whole process in not atomic.
+ * What do we do then? Someone else is in the process of creating the header too, but
+ * it might not have finished it. That means we cant just open, read and use it!
+ * We therefor currently just break with an error.
+ * On return the header file is still r/w locked.
+ */
+static int create_ea_header(const char * restrict uname,
+                            struct ea * restrict ea)
+{
+    int fd = -1, err = 0;
+    char *ptr;
+
+    if ((fd = open(uname, O_RDWR | O_CREAT | O_EXCL, 0666 & ~ea->vol->v_umask)) == -1) {
+        LOG(log_error, logtype_afpd, "ea_create: open race condition with ea header for file: %s", uname);
+        return -1;
+    }
+
+    /* lock it */
+    if ((write_lock(fd, 0, SEEK_SET, 0)) != 0) {
+        LOG(log_error, logtype_afpd, "ea_create: lock race condition with ea header for file: %s", uname);
+        err = -1;
+        goto exit;
+    }
+
+    /* Now init it */
+    ptr = ea->ea_data;
+    *(uint32_t *)ptr = htonl(EA_MAGIC);
+    ptr += EA_MAGIC_LEN;
+    *(uint16_t *)ptr = htons(EA_VERSION);
+    ptr += EA_VERSION_LEN;
+    *(uint16_t *)ptr = 0;       /* count */
+
+    ea->ea_size = EA_HEADER_SIZE;
+    ea->ea_inited = EA_INITED;
+
+exit:
+    if (err != 0) {
+        close(fd);
+        fd = -1;
+    }
+    return fd;
+}
+
+/*
+ * Function: write_ea
+ *
+ * Purpose: write an EA to disk
+ *
+ * Arguments:
+ *
+ *    ea         (r) struct ea handle
+ *    attruname  (r) EA name
+ *    ibuf       (r) buffer with EA content
+ *    attrsize   (r) size of EA
+ *
+ * Returns: 0 on success, -1 on error
+ *
+ * Effects:
+ *
+ * Creates/overwrites EA file.
+ *
+ */
+static int write_ea(const struct ea * restrict ea,
+                    const char * restrict attruname,
+                    const char * restrict ibuf,
+                    size_t attrsize)
+{
+    int fd = -1, ret = AFP_OK;
+    struct stat st;
+    char *eaname;
+
+    if ((eaname = ea_path(ea, attruname, 1)) == NULL) {
+        LOG(log_error, logtype_afpd, "write_ea('%s'): ea_path error", attruname);
+        return AFPERR_MISC;
+    }
+
+    LOG(log_maxdebug, logtype_afpd, "write_ea('%s')", eaname);
+
+    /* Check if it exists, remove if yes*/
+    if ((stat(eaname, &st)) == 0) {
+        if ((unlink(eaname)) != 0) {
+            if (errno == EACCES)
+                return AFPERR_ACCESS;
+            else
+                return AFPERR_MISC;
+        }
+    }
+
+    if ((fd = open(eaname, O_RDWR | O_CREAT | O_EXCL, 0666 & ~ea->vol->v_umask)) == -1) {
+        LOG(log_error, logtype_afpd, "write_ea: open race condition: %s", eaname);
+        return -1;
+    }
+
+    /* lock it */
+    if ((write_lock(fd, 0, SEEK_SET, 0)) != 0) {
+        LOG(log_error, logtype_afpd, "write_ea: open race condition: %s", eaname);
+        ret = -1;
+        goto exit;
+    }
+
+    if (write(fd, ibuf, attrsize) != (ssize_t)attrsize) {
+        LOG(log_error, logtype_afpd, "write_ea('%s'): write: %s", eaname, strerror(errno));
+        ret = -1;
+        goto exit;
+    }
+
+exit:
+    if (fd != -1)
+        close(fd); /* and unlock */
+    return ret;
+}
+
+/*
+ * Function: ea_delentry
+ *
+ * Purpose: delete one EA from ea->ea_entries[]
+ *
+ * Arguments:
+ *
+ *    ea            (rw) pointer to struct ea
+ *    attruname     (r) EA name
+ *
+ * Returns: new number of EA entries, -1 on error
+ *
+ * Effects:
+ *
+ * Remove entry from  ea->ea_entries[]. Decrement ea->ea_count.
+ * Marks it as unused just by freeing name and setting it to NULL.
+ * ea_close and pack_buffer must honor this.
+ */
+static int ea_delentry(struct ea * restrict ea, const char * restrict attruname)
+{
+    int ret = 0;
+    unsigned int count = 0;
+
+    if (ea->ea_count == 0) {
+        LOG(log_error, logtype_afpd, "ea_delentry('%s'): illegal ea_count of 0 on deletion",
+            attruname);
+        return -1;
+    }
+
+    while (count < ea->ea_count) {
+        /* search matching EA */
+        if ((*ea->ea_entries)[count].ea_name &&
+            strcmp(attruname, (*ea->ea_entries)[count].ea_name) == 0) {
+            free((*ea->ea_entries)[count].ea_name);
+            (*ea->ea_entries)[count].ea_name = NULL;
+
+            LOG(log_debug, logtype_afpd, "ea_delentry('%s'): deleted no %u/%u",
+                attruname, count + 1, ea->ea_count);
+
+            break;
+        }
+        count++;
+    }
+
+    return ret;
+}
+
+/*
+ * Function: delete_ea_file
+ *
+ * Purpose: delete EA file from disk
+ *
+ * Arguments:
+ *
+ *    ea         (r) struct ea handle
+ *    attruname  (r) EA name
+ *
+ * Returns: 0 on success, -1 on error
+ */
+static int delete_ea_file(const struct ea * restrict ea, const char *eaname)
+{
+    int ret = 0;
+    char *eafile;
+    struct stat st;
+
+    if ((eafile = ea_path(ea, eaname, 1)) == NULL) {
+        LOG(log_error, logtype_afpd, "delete_ea_file('%s'): ea_path error", eaname);
+        return -1;
+    }
+
+    /* Check if it exists, remove if yes*/
+    if ((stat(eafile, &st)) == 0) {
+        if ((unlink(eafile)) != 0) {
+            LOG(log_error, logtype_afpd, "delete_ea_file('%s'): unlink: %s",
+                eafile, strerror(errno));
+            ret = -1;
+        } else
+            LOG(log_debug, logtype_afpd, "delete_ea_file('%s'): success", eafile);
+    }
+
+    return ret;
+}
+
+/*************************************************************************************
+ * ea_path, ea_open and ea_close are only global so that dbd can call them
+ *************************************************************************************/
+
+/*
+ * Function: ea_path
+ *
+ * Purpose: return name of ea header filename
+ *
+ * Arguments:
+ *
+ *    ea           (r) ea handle
+ *    eaname       (r) name of EA or NULL
+ *    macname      (r) if != 0 call mtoupath on eaname
+ *
+ * Returns: pointer to name in static buffer, NULL on error
+ *
+ * Effects:
+ *
+ * Calls ad_open, copies buffer, appends "::EA" and if supplied append eanme
+ * Files: "file" -> "file/.AppleDouble/file::EA"
+ * Dirs: "dir" -> "dir/.AppleDouble/.Parent::EA"
+ * "file" with EA "myEA" -> "file/.AppleDouble/file::EA:myEA"
+ */
+char *ea_path(const struct ea * restrict ea, const char * restrict eaname, int macname)
+{
+    const char *adname;
+    static char pathbuf[MAXPATHLEN + 1];
+
+    /* get name of a adouble file from uname */
+    adname = ea->vol->ad_path(ea->filename, (ea->ea_flags & EA_DIR) ? ADFLAGS_DIR : 0);
+    /* copy it so we can work with it */
+    strlcpy(pathbuf, adname, MAXPATHLEN + 1);
+    /* append "::EA" */
+    strlcat(pathbuf, "::EA", MAXPATHLEN + 1);
+
+    if (eaname) {
+        strlcat(pathbuf, "::", MAXPATHLEN + 1);
+        if (macname)
+            if ((eaname = mtoupath(ea->vol, eaname)) == NULL)
+                return NULL;
+        strlcat(pathbuf, eaname, MAXPATHLEN + 1);
+    }
+
+    return pathbuf;
+}
+
+/*
+ * Function: ea_open
+ *
+ * Purpose: open EA header file, create if it doesnt exits and called with O_CREATE
+ *
+ * Arguments:
+ *
+ *    vol         (r) current volume
+ *    uname       (r) filename for which we have to open a header
+ *    flags       (r) EA_CREATE: create if it doesn't exist (without it won't be created)
+ *                    EA_RDONLY: open read only
+ *                    EA_RDWR: open read/write
+ *                    Eiterh EA_RDONLY or EA_RDWR MUST be requested
+ *    ea          (w) pointer to a struct ea that we fill
+ *
+ * Returns: 0 on success
+ *         -1 on misc error with errno = EFAULT
+ *         -2 if no EA header exists with errno = ENOENT
+ *
+ * Effects:
+ *
+ * opens header file and stores fd in ea->ea_fd. Size of file is put into ea->ea_size.
+ * number of EAs is stored in ea->ea_count. flags are remembered in ea->ea_flags.
+ * file is either read or write locked depending on the open flags.
+ * When you're done with struct ea you must call ea_close on it.
+ */
+int ea_open(const struct vol * restrict vol,
+            const char * restrict uname,
+            eaflags_t eaflags,
+            struct ea * restrict ea)
+{
+    int ret = 0;
+    char *eaname;
+    struct stat st;
+
+    /* Enforce usage rules! */
+    if ( ! (eaflags & (EA_RDONLY | EA_RDWR))) {
+        LOG(log_error, logtype_afpd, "ea_open: called without EA_RDONLY | EA_RDWR", uname);
+        return -1;
+    }
+
+    /* Set it all to 0 */
+    memset(ea, 0, sizeof(struct ea));
+
+    ea->vol = vol;              /* ea_close needs it */
+    ea->ea_flags = eaflags;
+    ea->dirfd = -1;             /* no *at (cf openat) semantics by default */
+
+    /* Dont care for errors, eg when removing the file is already gone */
+    if (!stat(uname, &st) && S_ISDIR(st.st_mode))
+        ea->ea_flags |=  EA_DIR;
+
+    if ( ! (ea->filename = strdup(uname))) {
+        LOG(log_error, logtype_afpd, "ea_open: OOM");
+        return -1;
+    }
+
+    eaname = ea_path(ea, NULL, 0);
+    LOG(log_maxdebug, logtype_afpd, "ea_open: ea_path: %s", eaname);
+
+    /* Check if it exists, if not create it if EA_CREATE is in eaflags */
+    if ((stat(eaname, &st)) != 0) {
+        if (errno == ENOENT) {
+
+            /* It doesnt exist */
+
+            if ( ! (eaflags & EA_CREATE)) {
+                /* creation was not requested, so return with error */
+                ret = -2;
+                goto exit;
+            }
+
+            /* Now create a header file */
+
+            /* malloc buffer for minimal on disk data */
+            ea->ea_data = malloc(EA_HEADER_SIZE);
+            if (! ea->ea_data) {
+                LOG(log_error, logtype_afpd, "ea_open: OOM");
+                ret = -1;
+                goto exit;
+            }
+
+            /* create it */
+            ea->ea_fd = create_ea_header(eaname, ea);
+            if (ea->ea_fd == -1) {
+                ret = -1;
+                goto exit;
+            }
+
+            return 0;
+
+        } else {/* errno != ENOENT */
+            ret = -1;
+            goto exit;
+        }
+    }
+
+    /* header file exists, so read and parse it */
+
+    /* malloc buffer where we read disk file into */
+    if (st.st_size < EA_HEADER_SIZE) {
+        LOG(log_error, logtype_afpd, "ea_open('%s'): bogus EA header file", eaname);
+        ret = -1;
+        goto exit;
+    }
+    ea->ea_size = st.st_size;
+    ea->ea_data = malloc(st.st_size);
+    if (! ea->ea_data) {
+        LOG(log_error, logtype_afpd, "ea_open: OOM");
+        ret = -1;
+        goto exit;
+    }
+
+    /* Now lock, open and read header file from disk */
+    if ((ea->ea_fd = open(eaname, (ea->ea_flags & EA_RDWR) ? O_RDWR : O_RDONLY)) == -1) {
+        LOG(log_error, logtype_afpd, "ea_open('%s'): error: %s", eaname, strerror(errno));
+        ret = -1;
+        goto exit;
+    }
+
+    /* lock it */
+    if (ea->ea_flags & EA_RDONLY) {
+        /* read lock */
+        if ((read_lock(ea->ea_fd, 0, SEEK_SET, 0)) != 0) {
+            LOG(log_error, logtype_afpd, "ea_open: lock error on  header: %s", eaname);
+            ret = -1;
+            goto exit;
+        }
+    } else {  /* EA_RDWR */
+        /* write lock */
+        if ((write_lock(ea->ea_fd, 0, SEEK_SET, 0)) != 0) {
+            LOG(log_error, logtype_afpd, "ea_open: lock error on  header: %s", eaname);
+            ret = -1;
+            goto exit;
+        }
+    }
+
+    /* read it */
+    if (read(ea->ea_fd, ea->ea_data, ea->ea_size) != (ssize_t)ea->ea_size) {
+        LOG(log_error, logtype_afpd, "ea_open: short read on header: %s", eaname);
+        ret = -1;
+        goto exit;
+    }
+
+    if ((unpack_header(ea)) != 0) {
+        LOG(log_error, logtype_afpd, "ea_open: error unpacking header for: %s", eaname);
+        ret = -1;
+        goto exit;
+    }
+
+exit:
+    switch (ret) {
+    case 0:
+        ea->ea_inited = EA_INITED;
+        break;
+    case -1:
+        errno = EFAULT; /* force some errno distinguishable from ENOENT */
+        /* fall through */
+    case -2:
+        if (ea->ea_data) {
+            free(ea->ea_data);
+            ea->ea_data = NULL;
+        }
+        if (ea->ea_fd) {
+            close(ea->ea_fd);
+            ea->ea_fd = -1;
+        }
+        break;
+    }
+
+    return ret;
+}
+
+/*
+ * Function: ea_openat
+ *
+ * Purpose: openat like wrapper for ea_open, takes a additional file descriptor
+ *
+ * Arguments:
+ *
+ *    vol         (r) current volume
+ *    sfd         (r) openat like file descriptor
+ *    uname       (r) filename for which we have to open a header
+ *    flags       (r) EA_CREATE: create if it doesn't exist (without it won't be created)
+ *                    EA_RDONLY: open read only
+ *                    EA_RDWR: open read/write
+ *                    Eiterh EA_RDONLY or EA_RDWR MUST be requested
+ *    ea          (w) pointer to a struct ea that we fill
+ *
+ * Returns: 0 on success
+ *         -1 on misc error with errno = EFAULT
+ *         -2 if no EA header exists with errno = ENOENT
+ *
+ * Effects:
+ *
+ * opens header file and stores fd in ea->ea_fd. Size of file is put into ea->ea_size.
+ * number of EAs is stored in ea->ea_count. flags are remembered in ea->ea_flags.
+ * file is either read or write locked depending on the open flags.
+ * When you're done with struct ea you must call ea_close on it.
+ */
+int ea_openat(const struct vol * restrict vol,
+              int dirfd,
+              const char * restrict uname,
+              eaflags_t eaflags,
+              struct ea * restrict ea)
+{
+    int ret = 0;
+    int cwdfd = -1;
+
+    if (dirfd != -1) {
+        if (((cwdfd = open(".", O_RDONLY)) == -1) || (fchdir(dirfd) != 0)) {
+            ret = -1;
+            goto exit;
+        }
+    }
+
+    ret = ea_open(vol, uname, eaflags, ea);
+    ea->dirfd = dirfd;
+
+    if (dirfd != -1) {
+        if (fchdir(cwdfd) != 0) {
+            LOG(log_error, logtype_afpd, "ea_openat: cant chdir back, exiting");
+            exit(EXITERR_SYS);
+        }
+    }
+
+
+exit:
+    if (cwdfd != -1)
+        close(cwdfd);
+
+    return ret;
+
+}
+
+/*
+ * Function: ea_close
+ *
+ * Purpose: flushes and closes an ea handle
+ *
+ * Arguments:
+ *
+ *    ea          (rw) pointer to ea handle
+ *
+ * Returns: 0 on success, -1 on error
+ *
+ * Effects:
+ *
+ * Flushes and then closes and frees all resouces held by ea handle.
+ * Pack data in ea into ea_data, then write ea_data to disk
+ */
+int ea_close(struct ea * restrict ea)
+{
+    int ret = 0; 
+    unsigned int count = 0;
+    char *eaname;
+    struct stat st;
+
+    LOG(log_debug, logtype_afpd, "ea_close('%s')", ea->filename);
+
+    if (ea->ea_inited != EA_INITED) {
+        LOG(log_warning, logtype_afpd, "ea_close('%s'): non initialized ea", ea->filename);
+        return 0;
+    }
+
+    /* pack header and write it to disk if it was opened EA_RDWR*/
+    if (ea->ea_flags & EA_RDWR) {
+        if ((pack_header(ea)) != 0) {
+            LOG(log_error, logtype_afpd, "ea_close: pack header");
+            ret = -1;
+        } else {
+            if (ea->ea_count == 0) {
+                /* Check if EA header exists and remove it */
+                eaname = ea_path(ea, NULL, 0);
+                if ((lstatat(ea->dirfd, eaname, &st)) == 0) {
+                    if ((netatalk_unlinkat(ea->dirfd, eaname)) != 0) {
+                        LOG(log_error, logtype_afpd, "ea_close('%s'): unlink: %s",
+                            eaname, strerror(errno));
+                        ret = -1;
+                    }
+                    else
+                        LOG(log_debug, logtype_afpd, "ea_close(unlink '%s'): success", eaname);
+                } else {
+                    /* stat error */
+                    if (errno != ENOENT) {
+                        LOG(log_error, logtype_afpd, "ea_close('%s'): stat: %s",
+                            eaname, strerror(errno));
+                        ret = -1;
+                    }
+                }
+            } else { /* ea->ea_count > 0 */
+                if ((lseek(ea->ea_fd, 0, SEEK_SET)) == -1) {
+                    LOG(log_error, logtype_afpd, "ea_close: lseek: %s", strerror(errno));
+                    ret = -1;
+                    goto exit;
+                }
+
+                if ((ftruncate(ea->ea_fd, 0)) == -1) {
+                    LOG(log_error, logtype_afpd, "ea_close: ftruncate: %s", strerror(errno));
+                    ret = -1;
+                    goto exit;
+                }
+
+                if (write(ea->ea_fd, ea->ea_data, ea->ea_size) != (ssize_t)ea->ea_size) {
+                    LOG(log_error, logtype_afpd, "ea_close: write: %s", strerror(errno));
+                    ret = -1;
+                }
+            }
+        }
+    }
+
+exit:
+    /* free names */
+    while(count < ea->ea_count) {
+        if ( (*ea->ea_entries)[count].ea_name ) {
+            free((*ea->ea_entries)[count].ea_name);
+            (*ea->ea_entries)[count].ea_name = NULL;
+        }
+        count++;
+    }
+    ea->ea_count = 0;
+
+    if (ea->filename) {
+        free(ea->filename);
+        ea->filename = NULL;
+    }
+
+    if (ea->ea_entries) {
+        free(ea->ea_entries);
+        ea->ea_entries = NULL;
+    }
+
+    if (ea->ea_data) {
+        free(ea->ea_data);
+        ea->ea_data = NULL;
+    }
+    if (ea->ea_fd != -1) {
+        close(ea->ea_fd);       /* also releases the fcntl lock */
+        ea->ea_fd = -1;
+    }
+
+    return 0;
+}
+
+
+
+/************************************************************************************
+ * VFS funcs called from afp_ea* funcs
+ ************************************************************************************/
+
+/*
+ * Function: get_easize
+ *
+ * Purpose: get size of an EA
+ *
+ * Arguments:
+ *
+ *    vol          (r) current volume
+ *    rbuf         (w) DSI reply buffer
+ *    rbuflen      (rw) current length of data in reply buffer
+ *    uname        (r) filename
+ *    oflag        (r) link and create flag
+ *    attruname    (r) name of attribute
+ *
+ * Returns: AFP code: AFP_OK on success or appropiate AFP error code
+ *
+ * Effects:
+ *
+ * Copies EA size into rbuf in network order. Increments *rbuflen +4.
+ */
+int get_easize(VFS_FUNC_ARGS_EA_GETSIZE)
+{
+    int ret = AFPERR_MISC;
+    unsigned int count = 0;
+    uint32_t uint32;
+    struct ea ea;
+
+    LOG(log_debug, logtype_afpd, "get_easize: file: %s", uname);
+
+    if ((ea_open(vol, uname, EA_RDONLY, &ea)) != 0) {
+        if (errno != ENOENT)
+            LOG(log_error, logtype_afpd, "get_easize: error calling ea_open for file: %s", uname);
+
+        memset(rbuf, 0, 4);
+        *rbuflen += 4;
+        return ret;
+    }
+
+    while (count < ea.ea_count) {
+        if (strcmp(attruname, (*ea.ea_entries)[count].ea_name) == 0) {
+            uint32 = htonl((*ea.ea_entries)[count].ea_size);
+            memcpy(rbuf, &uint32, 4);
+            *rbuflen += 4;
+            ret = AFP_OK;
+
+            LOG(log_debug, logtype_afpd, "get_easize(\"%s\"): size: %u",
+                attruname, (*ea.ea_entries)[count].ea_size);
+            break;
+        }
+        count++;
+    }
+
+    if ((ea_close(&ea)) != 0) {
+        LOG(log_error, logtype_afpd, "get_easize: error closing ea handle for file: %s", uname);
+        return AFPERR_MISC;
+    }
+
+    return ret;
+}
+
+/*
+ * Function: get_eacontent
+ *
+ * Purpose: copy EA into rbuf
+ *
+ * Arguments:
+ *
+ *    vol          (r) current volume
+ *    rbuf         (w) DSI reply buffer
+ *    rbuflen      (rw) current length of data in reply buffer
+ *    uname        (r) filename
+ *    oflag        (r) link and create flag
+ *    attruname    (r) name of attribute
+ *    maxreply     (r) maximum EA size as of current specs/real-life
+ *
+ * Returns: AFP code: AFP_OK on success or appropiate AFP error code
+ *
+ * Effects:
+ *
+ * Copies EA into rbuf. Increments *rbuflen accordingly.
+ */
+int get_eacontent(VFS_FUNC_ARGS_EA_GETCONTENT)
+{
+    int ret = AFPERR_MISC, fd = -1;
+    unsigned int count = 0;
+    uint32_t uint32;
+    size_t toread;
+    struct ea ea;
+    char *eafile;
+
+    LOG(log_debug, logtype_afpd, "get_eacontent('%s/%s')", uname, attruname);
+
+    if ((ea_open(vol, uname, EA_RDONLY, &ea)) != 0) {
+        if (errno != ENOENT)
+            LOG(log_error, logtype_afpd, "get_eacontent('%s'): ea_open error", uname);
+        memset(rbuf, 0, 4);
+        *rbuflen += 4;
+        return ret;
+    }
+
+    while (count < ea.ea_count) {
+        if (strcmp(attruname, (*ea.ea_entries)[count].ea_name) == 0) {
+            if ( (eafile = ea_path(&ea, attruname, 1)) == NULL) {
+                ret = AFPERR_MISC;
+                break;
+            }
+
+            if ((fd = open(eafile, O_RDONLY)) == -1) {
+                LOG(log_error, logtype_afpd, "get_eacontent('%s'): open error: %s", uname, strerror(errno));
+                ret = AFPERR_MISC;
+                break;
+            }
+
+            /* Check how much the client wants, give him what we think is right */
+            maxreply -= MAX_REPLY_EXTRA_BYTES;
+            if (maxreply > MAX_EA_SIZE)
+                maxreply = MAX_EA_SIZE;
+            toread = (maxreply < (*ea.ea_entries)[count].ea_size) ? maxreply : (*ea.ea_entries)[count].ea_size;
+            LOG(log_debug, logtype_afpd, "get_eacontent('%s'): sending %u bytes", attruname, toread);
+
+            /* Put length of EA data in reply buffer */
+            uint32 = htonl(toread);
+            memcpy(rbuf, &uint32, 4);
+            rbuf += 4;
+            *rbuflen += 4;
+
+            if (read(fd, rbuf, toread) != (ssize_t)toread) {
+                LOG(log_error, logtype_afpd, "get_eacontent('%s/%s'): short read", uname, attruname);
+                close(fd);
+                ret = AFPERR_MISC;
+                break;
+            }
+            *rbuflen += toread;
+            close(fd);
+
+            ret = AFP_OK;
+            break;
+        }
+        count++;
+    }
+
+    if ((ea_close(&ea)) != 0) {
+        LOG(log_error, logtype_afpd, "get_eacontent('%s'): error closing ea handle", uname);
+        return AFPERR_MISC;
+    }
+
+    return ret;
+
+}
+
+/*
+ * Function: list_eas
+ *
+ * Purpose: copy names of EAs into attrnamebuf
+ *
+ * Arguments:
+ *
+ *    vol          (r) current volume
+ *    attrnamebuf  (w) store names a consecutive C strings here
+ *    buflen       (rw) length of names in attrnamebuf
+ *    uname        (r) filename
+ *    oflag        (r) link and create flag
+ *
+ * Returns: AFP code: AFP_OK on success or appropiate AFP error code
+ *
+ * Effects:
+ *
+ * Copies names of all EAs of uname as consecutive C strings into rbuf.
+ * Increments *buflen accordingly.
+ */
+int list_eas(VFS_FUNC_ARGS_EA_LIST)
+{
+    unsigned int count = 0;
+    int attrbuflen = *buflen, ret = AFP_OK, len;
+    char *buf = attrnamebuf;
+    struct ea ea;
+
+    LOG(log_debug, logtype_afpd, "list_eas: file: %s", uname);
+
+    if ((ea_open(vol, uname, EA_RDONLY, &ea)) != 0) {
+        if (errno != ENOENT) {
+            LOG(log_error, logtype_afpd, "list_eas: error calling ea_open for file: %s", uname);
+            return AFPERR_MISC;
+        }
+        else
+            return AFP_OK;
+    }
+
+    while (count < ea.ea_count) {
+        /* Convert name to CH_UTF8_MAC and directly store in in the reply buffer */
+        if ( ( len = convert_string(vol->v_volcharset,
+                                    CH_UTF8_MAC, 
+                                    (*ea.ea_entries)[count].ea_name,
+                                    (*ea.ea_entries)[count].ea_namelen,
+                                    buf + attrbuflen,
+                                    255))
+             <= 0 ) {
+            ret = AFPERR_MISC;
+            goto exit;
+        }
+        if (len == 255)
+            /* convert_string didn't 0-terminate */
+            attrnamebuf[attrbuflen + 255] = 0;
+
+        LOG(log_debug7, logtype_afpd, "list_eas(%s): EA: %s",
+            uname, (*ea.ea_entries)[count].ea_name);
+
+        attrbuflen += len + 1;
+        if (attrbuflen > (ATTRNAMEBUFSIZ - 256)) {
+            /* Next EA name could overflow, so bail out with error.
+               FIXME: evantually malloc/memcpy/realloc whatever.
+               Is it worth it ? */
+            LOG(log_warning, logtype_afpd, "list_eas(%s): running out of buffer for EA names", uname);
+            ret = AFPERR_MISC;
+            goto exit;
+        }
+        count++;
+    }
+
+exit:
+    *buflen = attrbuflen;
+
+    if ((ea_close(&ea)) != 0) {
+        LOG(log_error, logtype_afpd, "list_eas: error closing ea handle for file: %s", uname);
+        return AFPERR_MISC;
+    }
+
+    return ret;
+}
+
+/*
+ * Function: set_ea
+ *
+ * Purpose: set a Solaris native EA
+ *
+ * Arguments:
+ *
+ *    vol          (r) current volume
+ *    uname        (r) filename
+ *    attruname    (r) EA name
+ *    ibuf         (r) buffer with EA content
+ *    attrsize     (r) length EA in ibuf
+ *    oflag        (r) link and create flag
+ *
+ * Returns: AFP code: AFP_OK on success or appropiate AFP error code
+ *
+ * Effects:
+ *
+ * Copies names of all EAs of uname as consecutive C strings into rbuf.
+ * Increments *rbuflen accordingly.
+ */
+int set_ea(VFS_FUNC_ARGS_EA_SET)
+{
+    int ret = AFP_OK;
+    struct ea ea;
+
+    LOG(log_debug, logtype_afpd, "set_ea: file: %s", uname);
+
+    if ((ea_open(vol, uname, EA_CREATE | EA_RDWR, &ea)) != 0) {
+        LOG(log_error, logtype_afpd, "set_ea('%s'): ea_open error", uname);
+        return AFPERR_MISC;
+    }
+
+    if ((ea_addentry(&ea, attruname, attrsize, oflag)) == -1) {
+        LOG(log_error, logtype_afpd, "set_ea('%s'): ea_addentry error", uname);
+        ret = AFPERR_MISC;
+        goto exit;
+    }
+
+    if ((write_ea(&ea, attruname, ibuf, attrsize)) != 0) {
+        LOG(log_error, logtype_afpd, "set_ea('%s'): write_ea error", uname);
+        ret = AFPERR_MISC;
+        goto exit;
+    }
+
+exit:
+    if ((ea_close(&ea)) != 0) {
+        LOG(log_error, logtype_afpd, "set_ea('%s'): ea_close error", uname);
+        ret = AFPERR_MISC;
+        goto exit;
+    }
+
+    return ret;
+}
+
+/*
+ * Function: remove_ea
+ *
+ * Purpose: remove a EA from a file
+ *
+ * Arguments:
+ *
+ *    vol          (r) current volume
+ *    uname        (r) filename
+ *    attruname    (r) EA name
+ *    oflag        (r) link and create flag
+ *
+ * Returns: AFP code: AFP_OK on success or appropiate AFP error code
+ *
+ * Effects:
+ *
+ * Removes EA attruname from file uname.
+ */
+int remove_ea(VFS_FUNC_ARGS_EA_REMOVE)
+{
+    int ret = AFP_OK;
+    struct ea ea;
+
+    LOG(log_debug, logtype_afpd, "remove_ea('%s/%s')", uname, attruname);
+
+    if ((ea_open(vol, uname, EA_RDWR, &ea)) != 0) {
+        LOG(log_error, logtype_afpd, "remove_ea('%s'): ea_open error", uname);
+        return AFPERR_MISC;
+    }
+
+    if ((ea_delentry(&ea, attruname)) == -1) {
+        LOG(log_error, logtype_afpd, "remove_ea('%s'): ea_delentry error", uname);
+        ret = AFPERR_MISC;
+        goto exit;
+    }
+
+    if ((delete_ea_file(&ea, attruname)) != 0) {
+        LOG(log_error, logtype_afpd, "remove_ea('%s'): delete_ea error", uname);
+        ret = AFPERR_MISC;
+        goto exit;
+    }
+
+exit:
+    if ((ea_close(&ea)) != 0) {
+        LOG(log_error, logtype_afpd, "remove_ea('%s'): ea_close error", uname);
+        ret = AFPERR_MISC;
+        goto exit;
+    }
+
+    return ret;
+}
+
+/******************************************************************************************
+ * EA VFS funcs that deal with file/dir cp/mv/rm
+ ******************************************************************************************/
+
+int ea_deletefile(VFS_FUNC_ARGS_DELETEFILE)
+{
+    unsigned int count = 0;
+    int ret = AFP_OK;
+    int cwd = -1;
+    struct ea ea;
+
+    LOG(log_debug, logtype_afpd, "ea_deletefile('%s')", file);
+
+    /* Open EA stuff */
+    if ((ea_openat(vol, dirfd, file, EA_RDWR, &ea)) != 0) {
+        if (errno == ENOENT)
+            /* no EA files, nothing to do */
+            return AFP_OK;
+        else {
+            LOG(log_error, logtype_afpd, "ea_deletefile('%s'): error calling ea_open", file);
+            return AFPERR_MISC;
+        }
+    }
+
+    if (dirfd != -1) {
+        if (((cwd = open(".", O_RDONLY)) == -1) || (fchdir(dirfd) != 0)) {
+            ret = AFPERR_MISC;
+            goto exit;
+        }
+    }
+
+    while (count < ea.ea_count) {
+        if ((delete_ea_file(&ea, (*ea.ea_entries)[count].ea_name)) != 0) {
+            ret = AFPERR_MISC;
+            continue;
+        }
+        free((*ea.ea_entries)[count].ea_name);
+        (*ea.ea_entries)[count].ea_name = NULL;
+        count++;
+    }
+
+    /* ea_close removes the EA header file for us because all names are NULL */
+    if ((ea_close(&ea)) != 0) {
+        LOG(log_error, logtype_afpd, "ea_deletefile('%s'): error closing ea handle", file);
+        ret = AFPERR_MISC;
+    }
+
+    if (dirfd != -1 && fchdir(cwd) != 0) {
+        LOG(log_error, logtype_afpd, "ea_deletefile: cant chdir back. exit!");
+        exit(EXITERR_SYS);
+    }
+
+exit:
+    if (cwd != -1)
+        close(cwd);
+
+    return ret;
+}
+
+int ea_renamefile(VFS_FUNC_ARGS_RENAMEFILE)
+{
+    unsigned int count = 0;
+    int    ret = AFP_OK;
+    size_t easize;
+    char   srceapath[ MAXPATHLEN + 1];
+    char   *eapath;
+    char   *eaname;
+    struct ea srcea;
+    struct ea dstea;
+    struct adouble ad;
+
+    LOG(log_debug, logtype_afpd, "ea_renamefile('%s'/'%s')", src, dst);
+            
+
+    /* Open EA stuff */
+    if ((ea_openat(vol, dirfd, src, EA_RDWR, &srcea)) != 0) {
+        if (errno == ENOENT)
+            /* no EA files, nothing to do */
+            return AFP_OK;
+        else {
+            LOG(log_error, logtype_afpd, "ea_renamefile('%s'/'%s'): ea_open error: '%s'", src, dst, src);
+            return AFPERR_MISC;
+        }
+    }
+
+    if ((ea_open(vol, dst, EA_RDWR | EA_CREATE, &dstea)) != 0) {
+        if (errno == ENOENT) {
+            /* Possibly the .AppleDouble folder didn't exist, we create it and try again */
+            ad_init(&ad, vol); 
+            if ((ad_open(&ad, dst, ADFLAGS_HF | ADFLAGS_RDWR | ADFLAGS_CREATE, 0666)) != 0) {
+                LOG(log_error, logtype_afpd, "ea_renamefile('%s/%s'): ad_open error: '%s'", src, dst, dst);
+                ret = AFPERR_MISC;
+                goto exit;
+            }
+            ad_close(&ad, ADFLAGS_HF);
+            if ((ea_open(vol, dst, EA_RDWR | EA_CREATE, &dstea)) != 0) {
+                ret = AFPERR_MISC;
+                goto exit;
+            }
+        }
+    }
+
+    /* Loop through all EAs: */
+    while (count < srcea.ea_count) {
+        /* Move EA */
+        eaname = (*srcea.ea_entries)[count].ea_name;
+        easize = (*srcea.ea_entries)[count].ea_size;
+
+        /* Build src and dst paths for rename() */
+        if ((eapath = ea_path(&srcea, eaname, 1)) == NULL) {
+            ret = AFPERR_MISC;
+            goto exit;
+        }
+        strcpy(srceapath, eapath);
+        if ((eapath = ea_path(&dstea, eaname, 1)) == NULL) {
+            ret = AFPERR_MISC;
+            goto exit;
+        }
+
+        LOG(log_maxdebug, logtype_afpd, "ea_renamefile('%s/%s'): moving EA '%s' to '%s'",
+            src, dst, srceapath, eapath);
+
+        /* Add EA to dstea */
+        if ((ea_addentry(&dstea, eaname, easize, 0)) == -1) {
+            LOG(log_error, logtype_afpd, "ea_renamefile('%s/%s'): moving EA '%s' to '%s'",
+                src, dst, srceapath, eapath);
+            ret = AFPERR_MISC;
+            goto exit;
+        }
+
+        /* Remove EA entry from srcea */
+        if ((ea_delentry(&srcea, eaname)) == -1) {
+            LOG(log_error, logtype_afpd, "ea_renamefile('%s/%s'): moving EA '%s' to '%s'",
+                src, dst, srceapath, eapath);
+            ea_delentry(&dstea, eaname);
+            ret = AFPERR_MISC;
+            goto exit;
+        }
+
+        /* Now rename the EA */
+        if ((unix_rename(dirfd, srceapath, -1, eapath)) < 0) {
+            LOG(log_error, logtype_afpd, "ea_renamefile('%s/%s'): moving EA '%s' to '%s'",
+                src, dst, srceapath, eapath);
+            ret = AFPERR_MISC;
+            goto exit;
+        }
+
+        count++;
+    }
+
+
+exit:
+    ea_close(&srcea);
+    ea_close(&dstea);
+       return ret;
+}
+
+int ea_copyfile(VFS_FUNC_ARGS_COPYFILE)
+{
+    unsigned int count = 0;
+    int    ret = AFP_OK;
+    size_t easize;
+    char   srceapath[ MAXPATHLEN + 1];
+    char   *eapath;
+    char   *eaname;
+    struct ea srcea;
+    struct ea dstea;
+    struct adouble ad;
+
+    LOG(log_debug, logtype_afpd, "ea_copyfile('%s'/'%s')", src, dst);
+
+    /* Open EA stuff */
+    if ((ea_openat(vol, sfd, src, EA_RDWR, &srcea)) != 0) {
+        if (errno == ENOENT)
+            /* no EA files, nothing to do */
+            return AFP_OK;
+        else {
+            LOG(log_error, logtype_afpd, "ea_copyfile('%s'/'%s'): ea_open error: '%s'", src, dst, src);
+            return AFPERR_MISC;
+        }
+    }
+
+    if ((ea_open(vol, dst, EA_RDWR | EA_CREATE, &dstea)) != 0) {
+        if (errno == ENOENT) {
+            /* Possibly the .AppleDouble folder didn't exist, we create it and try again */
+            ad_init(&ad, vol);
+            if ((ad_open(&ad, dst, ADFLAGS_HF | ADFLAGS_RDWR | ADFLAGS_CREATE, 0666)) != 0) {
+                LOG(log_error, logtype_afpd, "ea_copyfile('%s/%s'): ad_open error: '%s'", src, dst, dst);
+                ret = AFPERR_MISC;
+                goto exit;
+            }
+            ad_close(&ad, ADFLAGS_HF);
+            if ((ea_open(vol, dst, EA_RDWR | EA_CREATE, &dstea)) != 0) {
+                ret = AFPERR_MISC;
+                goto exit;
+            }
+        }
+    }
+
+    /* Loop through all EAs: */
+    while (count < srcea.ea_count) {
+        /* Copy EA */
+        eaname = (*srcea.ea_entries)[count].ea_name;
+        easize = (*srcea.ea_entries)[count].ea_size;
+
+        /* Build src and dst paths for copy_file() */
+        if ((eapath = ea_path(&srcea, eaname, 1)) == NULL) {
+            ret = AFPERR_MISC;
+            goto exit;
+        }
+        strcpy(srceapath, eapath);
+        if ((eapath = ea_path(&dstea, eaname, 1)) == NULL) {
+            ret = AFPERR_MISC;
+            goto exit;
+        }
+
+        LOG(log_maxdebug, logtype_afpd, "ea_copyfile('%s/%s'): copying EA '%s' to '%s'",
+            src, dst, srceapath, eapath);
+
+        /* Add EA to dstea */
+        if ((ea_addentry(&dstea, eaname, easize, 0)) == -1) {
+            LOG(log_error, logtype_afpd, "ea_copyfile('%s/%s'): ea_addentry('%s') error",
+                src, dst, eaname);
+            ret = AFPERR_MISC;
+            goto exit;
+        }
+
+        /* Now copy the EA */
+        if ((copy_file(sfd, srceapath, eapath, (0666 & ~vol->v_umask))) < 0) {
+            LOG(log_error, logtype_afpd, "ea_copyfile('%s/%s'): copying EA '%s' to '%s'",
+                src, dst, srceapath, eapath);
+            ret = AFPERR_MISC;
+            goto exit;
+        }
+
+        count++;
+    }
+
+exit:
+    ea_close(&srcea);
+    ea_close(&dstea);
+       return ret;
+}
+
+int ea_chown(VFS_FUNC_ARGS_CHOWN)
+{
+
+    unsigned int count = 0;
+    int ret = AFP_OK;
+    char *eaname;
+    struct ea ea;
+
+    LOG(log_debug, logtype_afpd, "ea_chown('%s')", path);
+    /* Open EA stuff */
+    if ((ea_open(vol, path, EA_RDWR, &ea)) != 0) {
+        if (errno == ENOENT)
+            /* no EA files, nothing to do */
+            return AFP_OK;
+        else {
+            LOG(log_error, logtype_afpd, "ea_chown('%s'): error calling ea_open", path);
+            return AFPERR_MISC;
+        }
+    }
+
+    if ((lchown(ea_path(&ea, NULL, 0), uid, gid)) != 0) {
+        switch (errno) {
+        case EPERM:
+        case EACCES:
+            ret = AFPERR_ACCESS;
+            goto exit;
+        default:
+            ret = AFPERR_MISC;
+            goto exit;
+        }
+    }
+
+    while (count < ea.ea_count) {
+        if ((eaname = ea_path(&ea, (*ea.ea_entries)[count].ea_name, 1)) == NULL) {
+            ret = AFPERR_MISC;
+            goto exit;
+        }
+        if ((lchown(eaname, uid, gid)) != 0) {
+            switch (errno) {
+            case EPERM:
+            case EACCES:
+                ret = AFPERR_ACCESS;
+                goto exit;
+            default:
+                ret = AFPERR_MISC;
+                goto exit;
+            }
+            continue;
+        }
+
+        count++;
+    }
+
+exit:
+    if ((ea_close(&ea)) != 0) {
+        LOG(log_error, logtype_afpd, "ea_chown('%s'): error closing ea handle", path);
+        return AFPERR_MISC;
+    }
+
+    return ret;
+}
+
+int ea_chmod_file(VFS_FUNC_ARGS_SETFILEMODE)
+{
+
+    unsigned int count = 0;
+    int ret = AFP_OK;
+    const char *eaname;
+    struct ea ea;
+
+    LOG(log_debug, logtype_afpd, "ea_chmod_file('%s')", name);
+    /* Open EA stuff */
+    if ((ea_open(vol, name, EA_RDWR, &ea)) != 0) {
+        if (errno == ENOENT)
+            /* no EA files, nothing to do */
+            return AFP_OK;
+        else
+            return AFPERR_MISC;
+    }
+
+    /* Set mode on EA header file */
+    if ((setfilmode(ea_path(&ea, NULL, 0), ea_header_mode(mode), NULL, vol->v_umask)) != 0) {
+        LOG(log_error, logtype_afpd, "ea_chmod_file('%s'): %s", ea_path(&ea, NULL, 0), strerror(errno));
+        switch (errno) {
+        case EPERM:
+        case EACCES:
+            ret = AFPERR_ACCESS;
+            goto exit;
+        default:
+            ret = AFPERR_MISC;
+            goto exit;
+        }
+    }
+
+    /* Set mode on EA files */
+    while (count < ea.ea_count) {
+        if ((eaname = ea_path(&ea, (*ea.ea_entries)[count].ea_name, 1)) == NULL) {
+            ret = AFPERR_MISC;
+            goto exit;
+        }
+        if ((setfilmode(eaname, ea_mode(mode), NULL, vol->v_umask)) != 0) {
+            LOG(log_error, logtype_afpd, "ea_chmod_file('%s'): %s", eaname, strerror(errno));
+            switch (errno) {
+            case EPERM:
+            case EACCES:
+                ret = AFPERR_ACCESS;
+                goto exit;
+            default:
+                ret = AFPERR_MISC;
+                goto exit;
+            }
+            continue;
+        }
+
+        count++;
+    }
+
+exit:
+    if ((ea_close(&ea)) != 0) {
+        LOG(log_error, logtype_afpd, "ea_chmod_file('%s'): error closing ea handle", name);
+        return AFPERR_MISC;
+    }
+
+    return ret;
+}
+
+int ea_chmod_dir(VFS_FUNC_ARGS_SETDIRUNIXMODE)
+{
+
+    int ret = AFP_OK;
+    unsigned int count = 0;
+    uid_t uid;
+    const char *eaname;
+    const char *eaname_safe = NULL;
+    struct ea ea;
+
+    LOG(log_debug, logtype_afpd, "ea_chmod_dir('%s')", name);
+    /* .AppleDouble already might be inaccesible, so we must run as id 0 */
+    uid = geteuid();
+    if (seteuid(0)) {
+        LOG(log_error, logtype_afpd, "ea_chmod_dir('%s'): seteuid: %s", name, strerror(errno));
+        return AFPERR_MISC;
+    }
+
+    /* Open EA stuff */
+    if ((ea_open(vol, name, EA_RDWR, &ea)) != 0) {
+        /* ENOENT --> no EA files, nothing to do */
+        if (errno != ENOENT)
+            ret = AFPERR_MISC;
+        if (seteuid(uid) < 0) {
+            LOG(log_error, logtype_afpd, "can't seteuid back: %s", strerror(errno));
+            exit(EXITERR_SYS);
+        }
+        return ret;
+    }
+
+    /* Set mode on EA header */
+    if ((setfilmode(ea_path(&ea, NULL, 0), ea_header_mode(mode), NULL, vol->v_umask)) != 0) {
+        LOG(log_error, logtype_afpd, "ea_chmod_dir('%s'): %s", ea_path(&ea, NULL, 0), strerror(errno));
+        switch (errno) {
+        case EPERM:
+        case EACCES:
+            ret = AFPERR_ACCESS;
+            goto exit;
+        default:
+            ret = AFPERR_MISC;
+            goto exit;
+        }
+    }
+
+    /* Set mode on EA files */
+    while (count < ea.ea_count) {
+        eaname = (*ea.ea_entries)[count].ea_name;
+        /*
+         * Be careful with EA names from the EA header!
+         * Eg NFS users might have access to them, can inject paths using ../ or /.....
+         * FIXME:
+         * Until the EA code escapes / in EA name requests from the client, these therefor wont work.
+         */
+        if ((eaname_safe = strrchr(eaname, '/'))) {
+            LOG(log_warning, logtype_afpd, "ea_chmod_dir('%s'): contains a slash", eaname);
+            eaname = eaname_safe;
+        }
+        if ((eaname = ea_path(&ea, eaname, 1)) == NULL) {
+            ret = AFPERR_MISC;
+            goto exit;
+        }
+        if ((setfilmode(eaname, ea_mode(mode), NULL, vol->v_umask)) != 0) {
+            LOG(log_error, logtype_afpd, "ea_chmod_dir('%s'): %s", eaname, strerror(errno));
+            switch (errno) {
+            case EPERM:
+            case EACCES:
+                ret = AFPERR_ACCESS;
+                goto exit;
+            default:
+                ret = AFPERR_MISC;
+                goto exit;
+            }
+            continue;
+        }
+
+        count++;
+    }
+
+exit:
+    if (seteuid(uid) < 0) {
+        LOG(log_error, logtype_afpd, "can't seteuid back: %s", strerror(errno));
+        exit(EXITERR_SYS);
+    }
+
+    if ((ea_close(&ea)) != 0) {
+        LOG(log_error, logtype_afpd, "ea_chmod_dir('%s'): error closing ea handle", name);
+        return AFPERR_MISC;
+    }
+
+    return ret;
+}
index 77ab783b04c8d3546f20ecb66e5d6335e387ae82..5b210d81de9042d9227bbd793d7dce0de9e07eb1 100644 (file)
@@ -1,5 +1,4 @@
 /*
-  $Id: ea_sys.c,v 1.8 2010-04-13 08:05:06 franklahm Exp $
   Copyright (c) 2009 Frank Lahm <franklahm@gmail.com>
 
   This program is free software; you can redistribute it and/or modify
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <dirent.h>
-
-#if HAVE_ATTR_XATTR_H
-#include <attr/xattr.h>
-#elif HAVE_SYS_XATTR_H
-#include <sys/xattr.h>
-#endif
-
-#ifdef HAVE_SYS_EA_H
-#include <sys/ea.h>
-#endif
-
-#ifdef HAVE_SYS_EXTATTR_H
-#include <sys/extattr.h>
-#endif
+#include <arpa/inet.h>
 
 #include <atalk/adouble.h>
 #include <atalk/ea.h>
 #include <atalk/unix.h>
 #include <atalk/compat.h>
 
-#ifndef ENOATTR
-#define ENOATTR ENODATA
-#endif
-
-
 /**********************************************************************************
  * EA VFS funcs for storing EAs in nativa filesystem EAs
  **********************************************************************************/
@@ -215,6 +196,8 @@ int sys_get_eacontent(VFS_FUNC_ARGS_EA_GETCONTENT)
  *
  * Copies names of all EAs of uname as consecutive C strings into rbuf.
  * Increments *rbuflen accordingly.
+ * We hide the adouble:ea extended attributes here, but we currently
+ * allow reading, writing and deleteting them.
  */
 int sys_list_eas(VFS_FUNC_ARGS_EA_LIST)
 {
@@ -253,26 +236,27 @@ int sys_list_eas(VFS_FUNC_ARGS_EA_LIST)
     ptr = buf;
     while (ret > 0)  {
         len = strlen(ptr);
+        if (NOT_NETATALK_EA(ptr)) {
+            /* Convert name to CH_UTF8_MAC and directly store in in the reply buffer */
+            if ( 0 >= ( nlen = convert_string(vol->v_volcharset, CH_UTF8_MAC, ptr, len, attrnamebuf + attrbuflen, 256)) ) {
+                ret = AFPERR_MISC;
+                goto exit;
+            }
 
-        /* Convert name to CH_UTF8_MAC and directly store in in the reply buffer */
-        if ( 0 >= ( nlen = convert_string(vol->v_volcharset, CH_UTF8_MAC, ptr, len, attrnamebuf + attrbuflen, 256)) ) {
-            ret = AFPERR_MISC;
-            goto exit;
-        }
-
-        LOG(log_debug7, logtype_afpd, "sys_list_extattr(%s): attribute: %s", uname, ptr);
+            LOG(log_debug7, logtype_afpd, "sys_list_extattr(%s): attribute: %s", uname, ptr);
 
-        attrbuflen += nlen + 1;
-        if (attrbuflen > (ATTRNAMEBUFSIZ - 256)) {
-            /* Next EA name could overflow, so bail out with error.
-               FIXME: evantually malloc/memcpy/realloc whatever.
-               Is it worth it ? */
-            LOG(log_warning, logtype_afpd, "sys_list_extattr(%s): running out of buffer for EA names", uname);
-            ret = AFPERR_MISC;
-            goto exit;
+            attrbuflen += nlen + 1;
+            if (attrbuflen > (ATTRNAMEBUFSIZ - 256)) {
+                /* Next EA name could overflow, so bail out with error.
+                   FIXME: evantually malloc/memcpy/realloc whatever.
+                   Is it worth it ? */
+                LOG(log_warning, logtype_afpd, "sys_list_extattr(%s): running out of buffer for EA names", uname);
+                ret = AFPERR_MISC;
+                goto exit;
+            }
         }
-        ret -= len +1;
-        ptr += len +1;
+        ret -= len + 1;
+        ptr += len + 1;
     }
 
     ret = AFP_OK;
diff --git a/libatalk/vfs/extattr.c b/libatalk/vfs/extattr.c
new file mode 100644 (file)
index 0000000..bdae873
--- /dev/null
@@ -0,0 +1,876 @@
+/* 
+   Unix SMB/CIFS implementation.
+   Samba system utilities
+   Copyright (C) Andrew Tridgell 1992-1998
+   Copyright (C) Jeremy Allison  1998-2005
+   Copyright (C) Timur Bakeyev        2005
+   Copyright (C) Bjoern Jacke    2006-2007
+   
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   
+   sys_copyxattr modified from LGPL2.1 libattr copyright
+   Copyright (C) 2001-2002 Silicon Graphics, Inc.  All Rights Reserved.
+   Copyright (C) 2001 Andreas Gruenbacher.
+      
+   Samba 3.0.28, modified for netatalk.
+*/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <errno.h>
+
+#if HAVE_ATTR_XATTR_H
+#include <attr/xattr.h>
+#elif HAVE_SYS_XATTR_H
+#include <sys/xattr.h>
+#endif
+
+#ifdef HAVE_SYS_EA_H
+#include <sys/ea.h>
+#endif
+
+#ifdef HAVE_ATTROPEN
+
+#include <dirent.h>
+#endif
+
+#ifdef HAVE_SYS_EXTATTR_H
+#include <sys/extattr.h>
+#endif
+
+#include <atalk/adouble.h>
+#include <atalk/util.h>
+#include <atalk/logger.h>
+#include <atalk/ea.h>
+#include <atalk/compat.h>
+
+/******** Solaris EA helper function prototypes ********/
+#ifdef HAVE_ATTROPEN
+#define SOLARIS_ATTRMODE S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP
+static int solaris_write_xattr(int attrfd, const char *value, size_t size);
+static ssize_t solaris_read_xattr(int attrfd, void *value, size_t size);
+static ssize_t solaris_list_xattr(int attrdirfd, char *list, size_t size);
+static int solaris_unlinkat(int attrdirfd, const char *name);
+static int solaris_attropen(const char *path, const char *attrpath, int oflag, mode_t mode);
+static int solaris_openat(int fildes, const char *path, int oflag, mode_t mode);
+#endif
+
+/**************************************************************************
+ Wrappers for extented attribute calls. Based on the Linux package with
+ support for IRIX and (Net|Free)BSD also. Expand as other systems have them.
+****************************************************************************/
+static char attr_name[256 +5] = "user.";
+
+static const char *prefix(const char *uname)
+{
+#if defined(HAVE_ATTROPEN)
+       return uname;
+#else
+       strlcpy(attr_name +5, uname, 256);
+       return attr_name;
+#endif
+}
+
+ssize_t sys_getxattr (const char *path, const char *uname, void *value, size_t size)
+{
+       const char *name = prefix(uname);
+
+#if defined(HAVE_GETXATTR)
+#ifndef XATTR_ADD_OPT
+       return getxattr(path, name, value, size);
+#else
+       int options = 0;
+       return getxattr(path, name, value, size, 0, options);
+#endif
+#elif defined(HAVE_GETEA)
+       return getea(path, name, value, size);
+#elif defined(HAVE_EXTATTR_GET_FILE)
+       ssize_t retval;
+       /*
+        * The BSD implementation has a nasty habit of silently truncating
+        * the returned value to the size of the buffer, so we have to check
+        * that the buffer is large enough to fit the returned value.
+        */
+       if((retval = extattr_get_file(path, EXTATTR_NAMESPACE_USER, uname, NULL, 0)) >= 0) {
+        if (size == 0)
+            /* size == 0 means only return size */
+            return retval;
+               if (retval > size) {
+                       errno = ERANGE;
+                       return -1;
+               }
+               if ((retval = extattr_get_file(path, EXTATTR_NAMESPACE_USER, uname, value, size)) >= 0)
+                       return retval;
+       }
+
+       LOG(log_maxdebug, logtype_default, "sys_getxattr: extattr_get_file() failed with: %s\n", strerror(errno));
+       return -1;
+#elif defined(HAVE_ATTR_GET)
+       int retval, flags = 0;
+       int valuelength = (int)size;
+       char *attrname = strchr(name,'.') + 1;
+       
+       if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;
+
+       retval = attr_get(path, attrname, (char *)value, &valuelength, flags);
+
+       return retval ? retval : valuelength;
+#elif defined(HAVE_ATTROPEN)
+       ssize_t ret = -1;
+       int attrfd = solaris_attropen(path, name, O_RDONLY, 0);
+       if (attrfd >= 0) {
+               ret = solaris_read_xattr(attrfd, value, size);
+               close(attrfd);
+       }
+       return ret;
+#else
+       errno = ENOSYS;
+       return -1;
+#endif
+}
+
+ssize_t sys_fgetxattr (int filedes, const char *uname, void *value, size_t size)
+{
+    const char *name = prefix(uname);
+
+#if defined(HAVE_FGETXATTR)
+#ifndef XATTR_ADD_OPT
+    return fgetxattr(filedes, name, value, size);
+#else
+    int options = 0;
+    return fgetxattr(filedes, name, value, size, 0, options);
+#endif
+#elif defined(HAVE_FGETEA)
+    return fgetea(filedes, name, value, size);
+#elif defined(HAVE_EXTATTR_GET_FD)
+    char *s;
+    ssize_t retval;
+    int attrnamespace = (strncmp(name, "system", 6) == 0) ? 
+        EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER;
+    const char *attrname = ((s=strchr_m(name, '.')) == NULL) ? name : s + 1;
+
+    if((retval=extattr_get_fd(filedes, attrnamespace, attrname, NULL, 0)) >= 0) {
+        if(retval > size) {
+            errno = ERANGE;
+            return -1;
+        }
+        if((retval=extattr_get_fd(filedes, attrnamespace, attrname, value, size)) >= 0)
+            return retval;
+    }
+
+    LOG(log_debug, logtype_default, "sys_fgetxattr: extattr_get_fd(): %s",
+        strerror(errno)));
+    return -1;
+#elif defined(HAVE_ATTR_GETF)
+    int retval, flags = 0;
+    int valuelength = (int)size;
+    char *attrname = strchr(name,'.') + 1;
+
+    if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;
+
+    retval = attr_getf(filedes, attrname, (char *)value, &valuelength, flags);
+
+    return retval ? retval : valuelength;
+#elif defined(HAVE_ATTROPEN)
+    ssize_t ret = -1;
+    int attrfd = solaris_openat(filedes, name, O_RDONLY|O_XATTR, 0);
+    if (attrfd >= 0) {
+        ret = solaris_read_xattr(attrfd, value, size);
+        close(attrfd);
+    }
+    return ret;
+#else
+    errno = ENOSYS;
+    return -1;
+#endif
+}
+
+ssize_t sys_lgetxattr (const char *path, const char *uname, void *value, size_t size)
+{
+       const char *name = prefix(uname);
+
+#if defined(HAVE_LGETXATTR)
+       return lgetxattr(path, name, value, size);
+#elif defined(HAVE_GETXATTR) && defined(XATTR_ADD_OPT)
+       int options = XATTR_NOFOLLOW;
+       return getxattr(path, name, value, size, 0, options);
+#elif defined(HAVE_LGETEA)
+       return lgetea(path, name, value, size);
+#elif defined(HAVE_EXTATTR_GET_LINK)
+       ssize_t retval;
+       if((retval=extattr_get_link(path, EXTATTR_NAMESPACE_USER, uname, NULL, 0)) >= 0) {
+               if(retval > size) {
+                       errno = ERANGE;
+                       return -1;
+               }
+               if((retval=extattr_get_link(path, EXTATTR_NAMESPACE_USER, uname, value, size)) >= 0)
+                       return retval;
+       }
+       
+       LOG(log_maxdebug, logtype_default, "sys_lgetxattr: extattr_get_link() failed with: %s\n", strerror(errno));
+       return -1;
+#elif defined(HAVE_ATTR_GET)
+       int retval, flags = ATTR_DONTFOLLOW;
+       int valuelength = (int)size;
+       char *attrname = strchr(name,'.') + 1;
+       
+       if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;
+
+       retval = attr_get(path, attrname, (char *)value, &valuelength, flags);
+
+       return retval ? retval : valuelength;
+#elif defined(HAVE_ATTROPEN)
+       ssize_t ret = -1;
+       int attrfd = solaris_attropen(path, name, O_RDONLY|AT_SYMLINK_NOFOLLOW, 0);
+       if (attrfd >= 0) {
+               ret = solaris_read_xattr(attrfd, value, size);
+               close(attrfd);
+       }
+       return ret;
+#else
+       errno = ENOSYS;
+       return -1;
+#endif
+}
+
+#if defined(HAVE_EXTATTR_LIST_FILE)
+
+#define EXTATTR_PREFIX(s)      (s), (sizeof((s))-1)
+
+static struct {
+        int space;
+       const char *name;
+       size_t len;
+} 
+extattr[] = {
+       { EXTATTR_NAMESPACE_SYSTEM, EXTATTR_PREFIX("") },
+        { EXTATTR_NAMESPACE_USER, EXTATTR_PREFIX("") },
+};
+
+typedef union {
+       const char *path;
+       int filedes;
+} extattr_arg;
+
+static ssize_t bsd_attr_list (int type, extattr_arg arg, char *list, size_t size)
+{
+       ssize_t list_size;
+       int i, len;
+
+    switch(type) {
+#if defined(HAVE_EXTATTR_LIST_FILE)
+    case 0:
+        list_size = extattr_list_file(arg.path, EXTATTR_NAMESPACE_USER, list, size);
+        break;
+#endif
+#if defined(HAVE_EXTATTR_LIST_LINK)
+    case 1:
+        list_size = extattr_list_link(arg.path, EXTATTR_NAMESPACE_USER, list, size);
+        break;
+#endif
+#if defined(HAVE_EXTATTR_LIST_FD)
+    case 2:
+        list_size = extattr_list_fd(arg.filedes, EXTATTR_NAMESPACE_USER, list, size);
+        break;
+#endif
+    default:
+        errno = ENOSYS;
+        return -1;
+    }
+
+    /* Some error happend. Errno should be set by the previous call */
+    if(list_size < 0)
+        return -1;
+
+    /* No attributes */
+    if(list_size == 0)
+        return 0;
+
+    /* XXX: Call with an empty buffer may be used to calculate
+       necessary buffer size. Unfortunately, we can't say, how
+       many attributes were returned, so here is the potential
+       problem with the emulation.
+    */
+    if(list == NULL)
+        return list_size;
+
+    /* Buffer is too small to fit the results */
+    if(list_size > size) {
+        errno = ERANGE;
+        return -1;
+    }
+
+    /* Convert from pascal strings to C strings */
+    len = list[0];
+    memmove(list, list + 1, list_size);
+
+    for(i = len; i < list_size; ) {
+        LOG(log_maxdebug, logtype_afpd, "len: %d, i: %d", len, i);
+
+        len = list[i];
+        list[i] = '\0';
+        i += len + 1;
+    }
+
+       return list_size;
+}
+
+#endif
+
+#if defined(HAVE_ATTR_LIST) && defined(HAVE_SYS_ATTRIBUTES_H)
+static char attr_buffer[ATTR_MAX_VALUELEN];
+
+static ssize_t irix_attr_list(const char *path, int filedes, char *list, size_t size, int flags)
+{
+       int retval = 0, index;
+       attrlist_cursor_t *cursor = 0;
+       int total_size = 0;
+       attrlist_t * al = (attrlist_t *)attr_buffer;
+       attrlist_ent_t *ae;
+       size_t ent_size, left = size;
+       char *bp = list;
+
+       while (True) {
+           if (filedes)
+               retval = attr_listf(filedes, attr_buffer, ATTR_MAX_VALUELEN, flags, cursor);
+           else
+               retval = attr_list(path, attr_buffer, ATTR_MAX_VALUELEN, flags, cursor);
+           if (retval) break;
+           for (index = 0; index < al->al_count; index++) {
+               ae = ATTR_ENTRY(attr_buffer, index);
+               ent_size = strlen(ae->a_name) + sizeof("user.");
+               if (left >= ent_size) {
+                   strncpy(bp, "user.", sizeof("user."));
+                   strncat(bp, ae->a_name, ent_size - sizeof("user."));
+                   bp += ent_size;
+                   left -= ent_size;
+               } else if (size) {
+                   errno = ERANGE;
+                   retval = -1;
+                   break;
+               }
+               total_size += ent_size;
+           }
+           if (al->al_more == 0) break;
+       }
+       if (retval == 0) {
+           flags |= ATTR_ROOT;
+           cursor = 0;
+           while (True) {
+               if (filedes)
+                   retval = attr_listf(filedes, attr_buffer, ATTR_MAX_VALUELEN, flags, cursor);
+               else
+                   retval = attr_list(path, attr_buffer, ATTR_MAX_VALUELEN, flags, cursor);
+               if (retval) break;
+               for (index = 0; index < al->al_count; index++) {
+                   ae = ATTR_ENTRY(attr_buffer, index);
+                   ent_size = strlen(ae->a_name) + sizeof("system.");
+                   if (left >= ent_size) {
+                       strncpy(bp, "system.", sizeof("system."));
+                       strncat(bp, ae->a_name, ent_size - sizeof("system."));
+                       bp += ent_size;
+                       left -= ent_size;
+                   } else if (size) {
+                       errno = ERANGE;
+                       retval = -1;
+                       break;
+                   }
+                   total_size += ent_size;
+               }
+               if (al->al_more == 0) break;
+           }
+       }
+       return (ssize_t)(retval ? retval : total_size);
+}
+
+#endif
+
+#if defined(HAVE_LISTXATTR)
+static ssize_t remove_user(ssize_t ret, char *list, size_t size)
+{
+       size_t len;
+       char *ptr;
+       char *ptr1;
+       ssize_t ptrsize;
+       
+       if (ret <= 0 || size == 0)
+               return ret;
+       ptrsize = ret;
+       ptr = ptr1 = list;
+       while (ptrsize > 0) {
+               len = strlen(ptr1) +1;
+               ptrsize -= len;
+               if (strncmp(ptr1, "user.",5)) {
+                       ptr1 += len;
+                       continue;
+               }
+               memmove(ptr, ptr1 +5, len -5);
+               ptr += len -5;
+               ptr1 += len;
+       }
+       return ptr -list;
+}
+#endif
+
+ssize_t sys_listxattr (const char *path, char *list, size_t size)
+{
+#if defined(HAVE_LISTXATTR)
+       ssize_t ret;
+
+#ifndef XATTR_ADD_OPT
+       ret = listxattr(path, list, size);
+#else
+       int options = 0;
+       ret = listxattr(path, list, size, options);
+#endif
+       return remove_user(ret, list, size);
+
+#elif defined(HAVE_LISTEA)
+       return listea(path, list, size);
+#elif defined(HAVE_EXTATTR_LIST_FILE)
+       extattr_arg arg;
+       arg.path = path;
+       return bsd_attr_list(0, arg, list, size);
+#elif defined(HAVE_ATTR_LIST) && defined(HAVE_SYS_ATTRIBUTES_H)
+       return irix_attr_list(path, 0, list, size, 0);
+#elif defined(HAVE_ATTROPEN)
+       ssize_t ret = -1;
+       int attrdirfd = solaris_attropen(path, ".", O_RDONLY, 0);
+       if (attrdirfd >= 0) {
+               ret = solaris_list_xattr(attrdirfd, list, size);
+               close(attrdirfd);
+       }
+       return ret;
+#else
+       errno = ENOSYS;
+       return -1;
+#endif
+}
+
+ssize_t sys_llistxattr (const char *path, char *list, size_t size)
+{
+#if defined(HAVE_LLISTXATTR)
+       ssize_t ret;
+
+       ret = llistxattr(path, list, size);
+       return remove_user(ret, list, size);
+#elif defined(HAVE_LISTXATTR) && defined(XATTR_ADD_OPT)
+       ssize_t ret;
+       int options = XATTR_NOFOLLOW;
+
+       ret = listxattr(path, list, size, options);
+       return remove_user(ret, list, size);
+
+#elif defined(HAVE_LLISTEA)
+       return llistea(path, list, size);
+#elif defined(HAVE_EXTATTR_LIST_LINK)
+       extattr_arg arg;
+       arg.path = path;
+       return bsd_attr_list(1, arg, list, size);
+#elif defined(HAVE_ATTR_LIST) && defined(HAVE_SYS_ATTRIBUTES_H)
+       return irix_attr_list(path, 0, list, size, ATTR_DONTFOLLOW);
+#elif defined(HAVE_ATTROPEN)
+       ssize_t ret = -1;
+       int attrdirfd = solaris_attropen(path, ".", O_RDONLY|AT_SYMLINK_NOFOLLOW, 0);
+       if (attrdirfd >= 0) {
+               ret = solaris_list_xattr(attrdirfd, list, size);
+               close(attrdirfd);
+       }
+       return ret;
+#else
+       errno = ENOSYS;
+       return -1;
+#endif
+}
+
+int sys_removexattr (const char *path, const char *uname)
+{
+       const char *name = prefix(uname);
+#if defined(HAVE_REMOVEXATTR)
+#ifndef XATTR_ADD_OPT
+       return removexattr(path, name);
+#else
+       int options = 0;
+       return removexattr(path, name, options);
+#endif
+#elif defined(HAVE_REMOVEEA)
+       return removeea(path, name);
+#elif defined(HAVE_EXTATTR_DELETE_FILE)
+       return extattr_delete_file(path, EXTATTR_NAMESPACE_USER, uname);
+#elif defined(HAVE_ATTR_REMOVE)
+       int flags = 0;
+       char *attrname = strchr(name,'.') + 1;
+       
+       if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;
+
+       return attr_remove(path, attrname, flags);
+#elif defined(HAVE_ATTROPEN)
+       int ret = -1;
+       int attrdirfd = solaris_attropen(path, ".", O_RDONLY, 0);
+       if (attrdirfd >= 0) {
+               ret = solaris_unlinkat(attrdirfd, name);
+               close(attrdirfd);
+       }
+       return ret;
+#else
+       errno = ENOSYS;
+       return -1;
+#endif
+}
+
+int sys_lremovexattr (const char *path, const char *uname)
+{
+       const char *name = prefix(uname);
+#if defined(HAVE_LREMOVEXATTR)
+       return lremovexattr(path, name);
+#elif defined(HAVE_REMOVEXATTR) && defined(XATTR_ADD_OPT)
+       int options = XATTR_NOFOLLOW;
+       return removexattr(path, name, options);
+#elif defined(HAVE_LREMOVEEA)
+       return lremoveea(path, name);
+#elif defined(HAVE_EXTATTR_DELETE_LINK)
+       return extattr_delete_link(path, EXTATTR_NAMESPACE_USER, uname);
+#elif defined(HAVE_ATTR_REMOVE)
+       int flags = ATTR_DONTFOLLOW;
+       char *attrname = strchr(name,'.') + 1;
+       
+       if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;
+
+       return attr_remove(path, attrname, flags);
+#elif defined(HAVE_ATTROPEN)
+       int ret = -1;
+       int attrdirfd = solaris_attropen(path, ".", O_RDONLY|AT_SYMLINK_NOFOLLOW, 0);
+       if (attrdirfd >= 0) {
+               ret = solaris_unlinkat(attrdirfd, name);
+               close(attrdirfd);
+       }
+       return ret;
+#else
+       errno = ENOSYS;
+       return -1;
+#endif
+}
+
+int sys_setxattr (const char *path, const char *uname, const void *value, size_t size, int flags)
+{
+       const char *name = prefix(uname);
+#if defined(HAVE_SETXATTR)
+#ifndef XATTR_ADD_OPT
+       return setxattr(path, name, value, size, flags);
+#else
+       int options = 0;
+       return setxattr(path, name, value, size, 0, options);
+#endif
+#elif defined(HAVE_SETEA)
+       return setea(path, name, value, size, flags);
+#elif defined(HAVE_EXTATTR_SET_FILE)
+       int retval = 0;
+       if (flags) {
+               /* Check attribute existence */
+               retval = extattr_get_file(path, EXTATTR_NAMESPACE_USER, uname, NULL, 0);
+               if (retval < 0) {
+                       /* REPLACE attribute, that doesn't exist */
+                       if (flags & XATTR_REPLACE && errno == ENOATTR) {
+                               errno = ENOATTR;
+                               return -1;
+                       }
+                       /* Ignore other errors */
+               }
+               else {
+                       /* CREATE attribute, that already exists */
+                       if (flags & XATTR_CREATE) {
+                               errno = EEXIST;
+                               return -1;
+                       }
+               }
+       }
+       retval = extattr_set_file(path, EXTATTR_NAMESPACE_USER, uname, value, size);
+       return (retval < 0) ? -1 : 0;
+#elif defined(HAVE_ATTR_SET)
+       int myflags = 0;
+       char *attrname = strchr(name,'.') + 1;
+       
+       if (strncmp(name, "system", 6) == 0) myflags |= ATTR_ROOT;
+       if (flags & XATTR_CREATE) myflags |= ATTR_CREATE;
+       if (flags & XATTR_REPLACE) myflags |= ATTR_REPLACE;
+
+       return attr_set(path, attrname, (const char *)value, size, myflags);
+#elif defined(HAVE_ATTROPEN)
+       int ret = -1;
+       int myflags = O_RDWR;
+       int attrfd;
+       if (flags & XATTR_CREATE) myflags |= O_EXCL;
+       if (!(flags & XATTR_REPLACE)) myflags |= O_CREAT;
+       attrfd = solaris_attropen(path, name, myflags, (mode_t) SOLARIS_ATTRMODE);
+       if (attrfd >= 0) {
+               ret = solaris_write_xattr(attrfd, value, size);
+               close(attrfd);
+       }
+       return ret;
+#else
+       errno = ENOSYS;
+       return -1;
+#endif
+}
+
+int sys_fsetxattr (int filedes, const char *uname, const void *value, size_t size, int flags)
+{
+    const char *name = prefix(uname);
+
+#if defined(HAVE_FSETXATTR)
+#ifndef XATTR_ADD_OPT
+    return fsetxattr(filedes, name, value, size, flags);
+#else
+    int options = 0;
+    return fsetxattr(filedes, name, value, size, 0, options);
+#endif
+#elif defined(HAVE_FSETEA)
+    return fsetea(filedes, name, value, size, flags);
+#elif defined(HAVE_EXTATTR_SET_FD)
+    char *s;
+    int retval = 0;
+    int attrnamespace = (strncmp(name, "system", 6) == 0) ? 
+        EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER;
+    const char *attrname = ((s=strchr_m(name, '.')) == NULL) ? name : s + 1;
+    if (flags) {
+        /* Check attribute existence */
+        retval = extattr_get_fd(filedes, attrnamespace, attrname, NULL, 0);
+        if (retval < 0) {
+            /* REPLACE attribute, that doesn't exist */
+            if (flags & XATTR_REPLACE && errno == ENOATTR) {
+                errno = ENOATTR;
+                return -1;
+            }
+            /* Ignore other errors */
+        }
+        else {
+            log_error, logtype_default            /* CREATE attribute, that already exists */
+            if (flags & XATTR_CREATE) {
+                errno = EEXIST;
+                return -1;
+            }
+        }
+    }
+    retval = extattr_set_fd(filedes, attrnamespace, attrname, value, size);
+    return (retval < 0) ? -1 : 0;
+#elif defined(HAVE_ATTR_SETF)
+    int myflags = 0;
+    char *attrname = strchr(name,'.') + 1;
+
+    if (strncmp(name, "system", 6) == 0) myflags |= ATTR_ROOT;
+    if (flags & XATTR_CREATE) myflags |= ATTR_CREATE;
+    if (flags & XATTR_REPLACE) myflags |= ATTR_REPLACE;
+
+    return attr_setf(filedes, attrname, (const char *)value, size, myflags);
+#elif defined(HAVE_ATTROPEN)
+    int ret = -1;
+    int myflags = O_RDWR | O_XATTR;
+    int attrfd;
+    if (flags & XATTR_CREATE) myflags |= O_EXCL;
+    if (!(flags & XATTR_REPLACE)) myflags |= O_CREAT;
+    attrfd = solaris_openat(filedes, name, myflags, (mode_t) SOLARIS_ATTRMODE);
+    if (attrfd >= 0) {
+        ret = solaris_write_xattr(attrfd, value, size);
+        close(attrfd);
+    }
+    return ret;
+#else
+    errno = ENOSYS;
+    return -1;
+#endif
+}
+
+int sys_lsetxattr (const char *path, const char *uname, const void *value, size_t size, int flags)
+{
+       const char *name = prefix(uname);
+#if defined(HAVE_LSETXATTR)
+       return lsetxattr(path, name, value, size, flags);
+#elif defined(HAVE_SETXATTR) && defined(XATTR_ADD_OPT)
+       int options = XATTR_NOFOLLOW;
+       return setxattr(path, name, value, size, 0, options);
+#elif defined(LSETEA)
+       return lsetea(path, name, value, size, flags);
+#elif defined(HAVE_EXTATTR_SET_LINK)
+       int retval = 0;
+       if (flags) {
+               /* Check attribute existence */
+               retval = extattr_get_link(path, EXTATTR_NAMESPACE_USER, uname, NULL, 0);
+               if (retval < 0) {
+                       /* REPLACE attribute, that doesn't exist */
+                       if (flags & XATTR_REPLACE && errno == ENOATTR) {
+                               errno = ENOATTR;
+                               return -1;
+                       }
+                       /* Ignore other errors */
+               }
+               else {
+                       /* CREATE attribute, that already exists */
+                       if (flags & XATTR_CREATE) {
+                               errno = EEXIST;
+                               return -1;
+                       }
+               }
+       }
+
+       retval = extattr_set_link(path, EXTATTR_NAMESPACE_USER, uname, value, size);
+       return (retval < 0) ? -1 : 0;
+#elif defined(HAVE_ATTR_SET)
+       int myflags = ATTR_DONTFOLLOW;
+       char *attrname = strchr(name,'.') + 1;
+       
+       if (strncmp(name, "system", 6) == 0) myflags |= ATTR_ROOT;
+       if (flags & XATTR_CREATE) myflags |= ATTR_CREATE;
+       if (flags & XATTR_REPLACE) myflags |= ATTR_REPLACE;
+
+       return attr_set(path, attrname, (const char *)value, size, myflags);
+#elif defined(HAVE_ATTROPEN)
+       int ret = -1;
+       int myflags = O_RDWR | AT_SYMLINK_NOFOLLOW;
+       int attrfd;
+       if (flags & XATTR_CREATE) myflags |= O_EXCL;
+       if (!(flags & XATTR_REPLACE)) myflags |= O_CREAT;
+       attrfd = solaris_attropen(path, name, myflags, (mode_t) SOLARIS_ATTRMODE);
+       if (attrfd >= 0) {
+               ret = solaris_write_xattr(attrfd, value, size);
+               close(attrfd);
+       }
+       return ret;
+#else
+       errno = ENOSYS;
+       return -1;
+#endif
+}
+
+/**************************************************************************
+ helper functions for Solaris' EA support
+****************************************************************************/
+#ifdef HAVE_ATTROPEN
+static ssize_t solaris_read_xattr(int attrfd, void *value, size_t size)
+{
+       struct stat sbuf;
+
+       if (fstat(attrfd, &sbuf) == -1) {
+               return -1;
+       }
+
+       /* This is to return the current size of the named extended attribute */
+       if (size == 0) {
+               return sbuf.st_size;
+       }
+
+       /* check size and read xattr */
+       if (sbuf.st_size > size) {
+               return -1;
+       }
+
+       return read(attrfd, value, sbuf.st_size);
+}
+
+static ssize_t solaris_list_xattr(int attrdirfd, char *list, size_t size)
+{
+       ssize_t len = 0;
+       DIR *dirp;
+       struct dirent *de;
+       int newfd = dup(attrdirfd);
+       /* CAUTION: The originating file descriptor should not be
+                   used again following the call to fdopendir().
+                   For that reason we dup() the file descriptor
+                   here to make things more clear. */
+       dirp = fdopendir(newfd);
+
+       while ((de = readdir(dirp))) {
+               size_t listlen;
+               if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..") ||
+                    !strcmp(de->d_name, "SUNWattr_ro") || !strcmp(de->d_name, "SUNWattr_rw")) 
+               {
+                       /* we don't want "." and ".." here: */
+                       LOG(log_maxdebug, logtype_default, "skipped EA %s\n",de->d_name);
+                       continue;
+               }
+
+               listlen = strlen(de->d_name);
+               if (size == 0) {
+                       /* return the current size of the list of extended attribute names*/
+                       len += listlen + 1;
+               } else {
+                       /* check size and copy entry + nul into list. */
+                       if ((len + listlen + 1) > size) {
+                               errno = ERANGE;
+                               len = -1;
+                               break;
+                       } else {
+                               strcpy(list + len, de->d_name);
+                               len += listlen;
+                               list[len] = '\0';
+                               ++len;
+                       }
+               }
+       }
+
+       if (closedir(dirp) == -1) {
+               LOG(log_error, logtype_default, "closedir dirp: %s",strerror(errno));
+               return -1;
+       }
+       return len;
+}
+
+static int solaris_unlinkat(int attrdirfd, const char *name)
+{
+       if (unlinkat(attrdirfd, name, 0) == -1) {
+               return -1;
+       }
+       return 0;
+}
+
+static int solaris_attropen(const char *path, const char *attrpath, int oflag, mode_t mode)
+{
+       int filedes = attropen(path, attrpath, oflag, mode);
+       if (filedes == -1) {
+        if (errno != ENOENT)
+            LOG(log_error, logtype_default, "attropen(\"%s\", ea:'%s'): %s",
+                path, attrpath, strerror(errno));
+        errno = ENOATTR;
+       }
+       return filedes;
+}
+
+static int solaris_openat(int fildes, const char *path, int oflag, mode_t mode)
+{
+       int filedes = openat(fildes, path, oflag, mode);
+       if (filedes == -1) {
+               LOG(log_error, logtype_default, "openat(\"%s\"): %s",
+            path, strerror(errno));
+       }
+       return filedes;
+}
+
+static int solaris_write_xattr(int attrfd, const char *value, size_t size)
+{
+       if ((ftruncate(attrfd, 0) == 0) && (write(attrfd, value, size) == size)) {
+               return 0;
+       } else {
+               LOG(log_error, logtype_default, "solaris_write_xattr: %s",
+            strerror(errno));
+               return -1;
+       }
+}
+
+#endif /*HAVE_ATTROPEN*/
+
diff --git a/libatalk/vfs/sys_ea.c b/libatalk/vfs/sys_ea.c
deleted file mode 100644 (file)
index 3db20b2..0000000
+++ /dev/null
@@ -1,758 +0,0 @@
-/* 
-   Unix SMB/CIFS implementation.
-   Samba system utilities
-   Copyright (C) Andrew Tridgell 1992-1998
-   Copyright (C) Jeremy Allison  1998-2005
-   Copyright (C) Timur Bakeyev        2005
-   Copyright (C) Bjoern Jacke    2006-2007
-   
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
-   (at your option) any later version.
-   
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-   
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-   
-   sys_copyxattr modified from LGPL2.1 libattr copyright
-   Copyright (C) 2001-2002 Silicon Graphics, Inc.  All Rights Reserved.
-   Copyright (C) 2001 Andreas Gruenbacher.
-      
-   Samba 3.0.28, modified for netatalk.
-   $Id: sys_ea.c,v 1.6 2009-12-04 10:26:10 franklahm Exp $
-   
-*/
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <errno.h>
-
-#if HAVE_ATTR_XATTR_H
-#include <attr/xattr.h>
-#elif HAVE_SYS_XATTR_H
-#include <sys/xattr.h>
-#endif
-
-#ifdef HAVE_SYS_EA_H
-#include <sys/ea.h>
-#endif
-
-#ifdef HAVE_ATTROPEN
-
-#include <dirent.h>
-#endif
-
-#ifdef HAVE_SYS_EXTATTR_H
-#include <sys/extattr.h>
-#endif
-
-#include <atalk/adouble.h>
-#include <atalk/util.h>
-#include <atalk/logger.h>
-#include <atalk/ea.h>
-
-#ifndef ENOATTR
-#define ENOATTR ENODATA
-#endif
-
-/******** Solaris EA helper function prototypes ********/
-#ifdef HAVE_ATTROPEN
-#define SOLARIS_ATTRMODE S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP
-static int solaris_write_xattr(int attrfd, const char *value, size_t size);
-static ssize_t solaris_read_xattr(int attrfd, void *value, size_t size);
-static ssize_t solaris_list_xattr(int attrdirfd, char *list, size_t size);
-static int solaris_unlinkat(int attrdirfd, const char *name);
-static int solaris_attropen(const char *path, const char *attrpath, int oflag, mode_t mode);
-static int solaris_openat(int fildes, const char *path, int oflag, mode_t mode);
-#endif
-
-/**************************************************************************
- Wrappers for extented attribute calls. Based on the Linux package with
- support for IRIX and (Net|Free)BSD also. Expand as other systems have them.
-****************************************************************************/
-static char attr_name[256 +5] = "user.";
-
-static const char *prefix(const char *uname)
-{
-#if defined(HAVE_ATTROPEN)
-       return uname;
-#else
-       strlcpy(attr_name +5, uname, 256);
-       return attr_name;
-#endif
-}
-
-ssize_t sys_getxattr (const char *path, const char *uname, void *value, size_t size)
-{
-       const char *name = prefix(uname);
-
-#if defined(HAVE_GETXATTR)
-#ifndef XATTR_ADD_OPT
-       return getxattr(path, name, value, size);
-#else
-       int options = 0;
-       return getxattr(path, name, value, size, 0, options);
-#endif
-#elif defined(HAVE_GETEA)
-       return getea(path, name, value, size);
-#elif defined(HAVE_EXTATTR_GET_FILE)
-       ssize_t retval;
-       /*
-        * The BSD implementation has a nasty habit of silently truncating
-        * the returned value to the size of the buffer, so we have to check
-        * that the buffer is large enough to fit the returned value.
-        */
-       if((retval = extattr_get_file(path, EXTATTR_NAMESPACE_USER, uname, NULL, 0)) >= 0) {
-        if (size == 0)
-            /* size == 0 means only return size */
-            return retval;
-               if (retval > size) {
-                       errno = ERANGE;
-                       return -1;
-               }
-               if ((retval = extattr_get_file(path, EXTATTR_NAMESPACE_USER, uname, value, size)) >= 0)
-                       return retval;
-       }
-
-       LOG(log_maxdebug, logtype_default, "sys_getxattr: extattr_get_file() failed with: %s\n", strerror(errno));
-       return -1;
-#elif defined(HAVE_ATTR_GET)
-       int retval, flags = 0;
-       int valuelength = (int)size;
-       char *attrname = strchr(name,'.') + 1;
-       
-       if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;
-
-       retval = attr_get(path, attrname, (char *)value, &valuelength, flags);
-
-       return retval ? retval : valuelength;
-#elif defined(HAVE_ATTROPEN)
-       ssize_t ret = -1;
-       int attrfd = solaris_attropen(path, name, O_RDONLY, 0);
-       if (attrfd >= 0) {
-               ret = solaris_read_xattr(attrfd, value, size);
-               close(attrfd);
-       }
-       return ret;
-#else
-       errno = ENOSYS;
-       return -1;
-#endif
-}
-
-ssize_t sys_lgetxattr (const char *path, const char *uname, void *value, size_t size)
-{
-       const char *name = prefix(uname);
-
-#if defined(HAVE_LGETXATTR)
-       return lgetxattr(path, name, value, size);
-#elif defined(HAVE_GETXATTR) && defined(XATTR_ADD_OPT)
-       int options = XATTR_NOFOLLOW;
-       return getxattr(path, name, value, size, 0, options);
-#elif defined(HAVE_LGETEA)
-       return lgetea(path, name, value, size);
-#elif defined(HAVE_EXTATTR_GET_LINK)
-       ssize_t retval;
-       if((retval=extattr_get_link(path, EXTATTR_NAMESPACE_USER, uname, NULL, 0)) >= 0) {
-               if(retval > size) {
-                       errno = ERANGE;
-                       return -1;
-               }
-               if((retval=extattr_get_link(path, EXTATTR_NAMESPACE_USER, uname, value, size)) >= 0)
-                       return retval;
-       }
-       
-       LOG(log_maxdebug, logtype_default, "sys_lgetxattr: extattr_get_link() failed with: %s\n", strerror(errno));
-       return -1;
-#elif defined(HAVE_ATTR_GET)
-       int retval, flags = ATTR_DONTFOLLOW;
-       int valuelength = (int)size;
-       char *attrname = strchr(name,'.') + 1;
-       
-       if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;
-
-       retval = attr_get(path, attrname, (char *)value, &valuelength, flags);
-
-       return retval ? retval : valuelength;
-#elif defined(HAVE_ATTROPEN)
-       ssize_t ret = -1;
-       int attrfd = solaris_attropen(path, name, O_RDONLY|AT_SYMLINK_NOFOLLOW, 0);
-       if (attrfd >= 0) {
-               ret = solaris_read_xattr(attrfd, value, size);
-               close(attrfd);
-       }
-       return ret;
-#else
-       errno = ENOSYS;
-       return -1;
-#endif
-}
-
-#if defined(HAVE_EXTATTR_LIST_FILE)
-
-#define EXTATTR_PREFIX(s)      (s), (sizeof((s))-1)
-
-static struct {
-        int space;
-       const char *name;
-       size_t len;
-} 
-extattr[] = {
-       { EXTATTR_NAMESPACE_SYSTEM, EXTATTR_PREFIX("") },
-        { EXTATTR_NAMESPACE_USER, EXTATTR_PREFIX("") },
-};
-
-typedef union {
-       const char *path;
-       int filedes;
-} extattr_arg;
-
-static ssize_t bsd_attr_list (int type, extattr_arg arg, char *list, size_t size)
-{
-       ssize_t list_size;
-       int i, len;
-
-    switch(type) {
-#if defined(HAVE_EXTATTR_LIST_FILE)
-    case 0:
-        list_size = extattr_list_file(arg.path, EXTATTR_NAMESPACE_USER, list, size);
-        break;
-#endif
-#if defined(HAVE_EXTATTR_LIST_LINK)
-    case 1:
-        list_size = extattr_list_link(arg.path, EXTATTR_NAMESPACE_USER, list, size);
-        break;
-#endif
-#if defined(HAVE_EXTATTR_LIST_FD)
-    case 2:
-        list_size = extattr_list_fd(arg.filedes, EXTATTR_NAMESPACE_USER, list, size);
-        break;
-#endif
-    default:
-        errno = ENOSYS;
-        return -1;
-    }
-
-    /* Some error happend. Errno should be set by the previous call */
-    if(list_size < 0)
-        return -1;
-
-    /* No attributes */
-    if(list_size == 0)
-        return 0;
-
-    /* XXX: Call with an empty buffer may be used to calculate
-       necessary buffer size. Unfortunately, we can't say, how
-       many attributes were returned, so here is the potential
-       problem with the emulation.
-    */
-    if(list == NULL)
-        return list_size;
-
-    /* Buffer is too small to fit the results */
-    if(list_size > size) {
-        errno = ERANGE;
-        return -1;
-    }
-
-    /* Convert from pascal strings to C strings */
-    len = list[0];
-    memmove(list, list + 1, list_size);
-
-    for(i = len; i < list_size; ) {
-        LOG(log_maxdebug, logtype_afpd, "len: %d, i: %d", len, i);
-
-        len = list[i];
-        list[i] = '\0';
-        i += len + 1;
-    }
-
-       return list_size;
-}
-
-#endif
-
-#if defined(HAVE_ATTR_LIST) && defined(HAVE_SYS_ATTRIBUTES_H)
-static char attr_buffer[ATTR_MAX_VALUELEN];
-
-static ssize_t irix_attr_list(const char *path, int filedes, char *list, size_t size, int flags)
-{
-       int retval = 0, index;
-       attrlist_cursor_t *cursor = 0;
-       int total_size = 0;
-       attrlist_t * al = (attrlist_t *)attr_buffer;
-       attrlist_ent_t *ae;
-       size_t ent_size, left = size;
-       char *bp = list;
-
-       while (True) {
-           if (filedes)
-               retval = attr_listf(filedes, attr_buffer, ATTR_MAX_VALUELEN, flags, cursor);
-           else
-               retval = attr_list(path, attr_buffer, ATTR_MAX_VALUELEN, flags, cursor);
-           if (retval) break;
-           for (index = 0; index < al->al_count; index++) {
-               ae = ATTR_ENTRY(attr_buffer, index);
-               ent_size = strlen(ae->a_name) + sizeof("user.");
-               if (left >= ent_size) {
-                   strncpy(bp, "user.", sizeof("user."));
-                   strncat(bp, ae->a_name, ent_size - sizeof("user."));
-                   bp += ent_size;
-                   left -= ent_size;
-               } else if (size) {
-                   errno = ERANGE;
-                   retval = -1;
-                   break;
-               }
-               total_size += ent_size;
-           }
-           if (al->al_more == 0) break;
-       }
-       if (retval == 0) {
-           flags |= ATTR_ROOT;
-           cursor = 0;
-           while (True) {
-               if (filedes)
-                   retval = attr_listf(filedes, attr_buffer, ATTR_MAX_VALUELEN, flags, cursor);
-               else
-                   retval = attr_list(path, attr_buffer, ATTR_MAX_VALUELEN, flags, cursor);
-               if (retval) break;
-               for (index = 0; index < al->al_count; index++) {
-                   ae = ATTR_ENTRY(attr_buffer, index);
-                   ent_size = strlen(ae->a_name) + sizeof("system.");
-                   if (left >= ent_size) {
-                       strncpy(bp, "system.", sizeof("system."));
-                       strncat(bp, ae->a_name, ent_size - sizeof("system."));
-                       bp += ent_size;
-                       left -= ent_size;
-                   } else if (size) {
-                       errno = ERANGE;
-                       retval = -1;
-                       break;
-                   }
-                   total_size += ent_size;
-               }
-               if (al->al_more == 0) break;
-           }
-       }
-       return (ssize_t)(retval ? retval : total_size);
-}
-
-#endif
-
-#if defined(HAVE_LISTXATTR)
-static ssize_t remove_user(ssize_t ret, char *list, size_t size)
-{
-       size_t len;
-       char *ptr;
-       char *ptr1;
-       ssize_t ptrsize;
-       
-       if (ret <= 0 || size == 0)
-               return ret;
-       ptrsize = ret;
-       ptr = ptr1 = list;
-       while (ptrsize > 0) {
-               len = strlen(ptr1) +1;
-               ptrsize -= len;
-               if (strncmp(ptr1, "user.",5)) {
-                       ptr1 += len;
-                       continue;
-               }
-               memmove(ptr, ptr1 +5, len -5);
-               ptr += len -5;
-               ptr1 += len;
-       }
-       return ptr -list;
-}
-#endif
-
-ssize_t sys_listxattr (const char *path, char *list, size_t size)
-{
-#if defined(HAVE_LISTXATTR)
-       ssize_t ret;
-
-#ifndef XATTR_ADD_OPT
-       ret = listxattr(path, list, size);
-#else
-       int options = 0;
-       ret = listxattr(path, list, size, options);
-#endif
-       return remove_user(ret, list, size);
-
-#elif defined(HAVE_LISTEA)
-       return listea(path, list, size);
-#elif defined(HAVE_EXTATTR_LIST_FILE)
-       extattr_arg arg;
-       arg.path = path;
-       return bsd_attr_list(0, arg, list, size);
-#elif defined(HAVE_ATTR_LIST) && defined(HAVE_SYS_ATTRIBUTES_H)
-       return irix_attr_list(path, 0, list, size, 0);
-#elif defined(HAVE_ATTROPEN)
-       ssize_t ret = -1;
-       int attrdirfd = solaris_attropen(path, ".", O_RDONLY, 0);
-       if (attrdirfd >= 0) {
-               ret = solaris_list_xattr(attrdirfd, list, size);
-               close(attrdirfd);
-       }
-       return ret;
-#else
-       errno = ENOSYS;
-       return -1;
-#endif
-}
-
-ssize_t sys_llistxattr (const char *path, char *list, size_t size)
-{
-#if defined(HAVE_LLISTXATTR)
-       ssize_t ret;
-
-       ret = llistxattr(path, list, size);
-       return remove_user(ret, list, size);
-#elif defined(HAVE_LISTXATTR) && defined(XATTR_ADD_OPT)
-       ssize_t ret;
-       int options = XATTR_NOFOLLOW;
-
-       ret = listxattr(path, list, size, options);
-       return remove_user(ret, list, size);
-
-#elif defined(HAVE_LLISTEA)
-       return llistea(path, list, size);
-#elif defined(HAVE_EXTATTR_LIST_LINK)
-       extattr_arg arg;
-       arg.path = path;
-       return bsd_attr_list(1, arg, list, size);
-#elif defined(HAVE_ATTR_LIST) && defined(HAVE_SYS_ATTRIBUTES_H)
-       return irix_attr_list(path, 0, list, size, ATTR_DONTFOLLOW);
-#elif defined(HAVE_ATTROPEN)
-       ssize_t ret = -1;
-       int attrdirfd = solaris_attropen(path, ".", O_RDONLY|AT_SYMLINK_NOFOLLOW, 0);
-       if (attrdirfd >= 0) {
-               ret = solaris_list_xattr(attrdirfd, list, size);
-               close(attrdirfd);
-       }
-       return ret;
-#else
-       errno = ENOSYS;
-       return -1;
-#endif
-}
-
-int sys_removexattr (const char *path, const char *uname)
-{
-       const char *name = prefix(uname);
-#if defined(HAVE_REMOVEXATTR)
-#ifndef XATTR_ADD_OPT
-       return removexattr(path, name);
-#else
-       int options = 0;
-       return removexattr(path, name, options);
-#endif
-#elif defined(HAVE_REMOVEEA)
-       return removeea(path, name);
-#elif defined(HAVE_EXTATTR_DELETE_FILE)
-       return extattr_delete_file(path, EXTATTR_NAMESPACE_USER, uname);
-#elif defined(HAVE_ATTR_REMOVE)
-       int flags = 0;
-       char *attrname = strchr(name,'.') + 1;
-       
-       if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;
-
-       return attr_remove(path, attrname, flags);
-#elif defined(HAVE_ATTROPEN)
-       int ret = -1;
-       int attrdirfd = solaris_attropen(path, ".", O_RDONLY, 0);
-       if (attrdirfd >= 0) {
-               ret = solaris_unlinkat(attrdirfd, name);
-               close(attrdirfd);
-       }
-       return ret;
-#else
-       errno = ENOSYS;
-       return -1;
-#endif
-}
-
-int sys_lremovexattr (const char *path, const char *uname)
-{
-       const char *name = prefix(uname);
-#if defined(HAVE_LREMOVEXATTR)
-       return lremovexattr(path, name);
-#elif defined(HAVE_REMOVEXATTR) && defined(XATTR_ADD_OPT)
-       int options = XATTR_NOFOLLOW;
-       return removexattr(path, name, options);
-#elif defined(HAVE_LREMOVEEA)
-       return lremoveea(path, name);
-#elif defined(HAVE_EXTATTR_DELETE_LINK)
-       return extattr_delete_link(path, EXTATTR_NAMESPACE_USER, uname);
-#elif defined(HAVE_ATTR_REMOVE)
-       int flags = ATTR_DONTFOLLOW;
-       char *attrname = strchr(name,'.') + 1;
-       
-       if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;
-
-       return attr_remove(path, attrname, flags);
-#elif defined(HAVE_ATTROPEN)
-       int ret = -1;
-       int attrdirfd = solaris_attropen(path, ".", O_RDONLY|AT_SYMLINK_NOFOLLOW, 0);
-       if (attrdirfd >= 0) {
-               ret = solaris_unlinkat(attrdirfd, name);
-               close(attrdirfd);
-       }
-       return ret;
-#else
-       errno = ENOSYS;
-       return -1;
-#endif
-}
-
-int sys_setxattr (const char *path, const char *uname, const void *value, size_t size, int flags)
-{
-       const char *name = prefix(uname);
-#if defined(HAVE_SETXATTR)
-#ifndef XATTR_ADD_OPT
-       return setxattr(path, name, value, size, flags);
-#else
-       int options = 0;
-       return setxattr(path, name, value, size, 0, options);
-#endif
-#elif defined(HAVE_SETEA)
-       return setea(path, name, value, size, flags);
-#elif defined(HAVE_EXTATTR_SET_FILE)
-       int retval = 0;
-       if (flags) {
-               /* Check attribute existence */
-               retval = extattr_get_file(path, EXTATTR_NAMESPACE_USER, uname, NULL, 0);
-               if (retval < 0) {
-                       /* REPLACE attribute, that doesn't exist */
-                       if (flags & XATTR_REPLACE && errno == ENOATTR) {
-                               errno = ENOATTR;
-                               return -1;
-                       }
-                       /* Ignore other errors */
-               }
-               else {
-                       /* CREATE attribute, that already exists */
-                       if (flags & XATTR_CREATE) {
-                               errno = EEXIST;
-                               return -1;
-                       }
-               }
-       }
-       retval = extattr_set_file(path, EXTATTR_NAMESPACE_USER, uname, value, size);
-       return (retval < 0) ? -1 : 0;
-#elif defined(HAVE_ATTR_SET)
-       int myflags = 0;
-       char *attrname = strchr(name,'.') + 1;
-       
-       if (strncmp(name, "system", 6) == 0) myflags |= ATTR_ROOT;
-       if (flags & XATTR_CREATE) myflags |= ATTR_CREATE;
-       if (flags & XATTR_REPLACE) myflags |= ATTR_REPLACE;
-
-       return attr_set(path, attrname, (const char *)value, size, myflags);
-#elif defined(HAVE_ATTROPEN)
-       int ret = -1;
-       int myflags = O_RDWR;
-       int attrfd;
-       if (flags & XATTR_CREATE) myflags |= O_EXCL;
-       if (!(flags & XATTR_REPLACE)) myflags |= O_CREAT;
-       attrfd = solaris_attropen(path, name, myflags, (mode_t) SOLARIS_ATTRMODE);
-       if (attrfd >= 0) {
-               ret = solaris_write_xattr(attrfd, value, size);
-               close(attrfd);
-       }
-       return ret;
-#else
-       errno = ENOSYS;
-       return -1;
-#endif
-}
-
-int sys_lsetxattr (const char *path, const char *uname, const void *value, size_t size, int flags)
-{
-       const char *name = prefix(uname);
-#if defined(HAVE_LSETXATTR)
-       return lsetxattr(path, name, value, size, flags);
-#elif defined(HAVE_SETXATTR) && defined(XATTR_ADD_OPT)
-       int options = XATTR_NOFOLLOW;
-       return setxattr(path, name, value, size, 0, options);
-#elif defined(LSETEA)
-       return lsetea(path, name, value, size, flags);
-#elif defined(HAVE_EXTATTR_SET_LINK)
-       int retval = 0;
-       if (flags) {
-               /* Check attribute existence */
-               retval = extattr_get_link(path, EXTATTR_NAMESPACE_USER, uname, NULL, 0);
-               if (retval < 0) {
-                       /* REPLACE attribute, that doesn't exist */
-                       if (flags & XATTR_REPLACE && errno == ENOATTR) {
-                               errno = ENOATTR;
-                               return -1;
-                       }
-                       /* Ignore other errors */
-               }
-               else {
-                       /* CREATE attribute, that already exists */
-                       if (flags & XATTR_CREATE) {
-                               errno = EEXIST;
-                               return -1;
-                       }
-               }
-       }
-
-       retval = extattr_set_link(path, EXTATTR_NAMESPACE_USER, uname, value, size);
-       return (retval < 0) ? -1 : 0;
-#elif defined(HAVE_ATTR_SET)
-       int myflags = ATTR_DONTFOLLOW;
-       char *attrname = strchr(name,'.') + 1;
-       
-       if (strncmp(name, "system", 6) == 0) myflags |= ATTR_ROOT;
-       if (flags & XATTR_CREATE) myflags |= ATTR_CREATE;
-       if (flags & XATTR_REPLACE) myflags |= ATTR_REPLACE;
-
-       return attr_set(path, attrname, (const char *)value, size, myflags);
-#elif defined(HAVE_ATTROPEN)
-       int ret = -1;
-       int myflags = O_RDWR | AT_SYMLINK_NOFOLLOW;
-       int attrfd;
-       if (flags & XATTR_CREATE) myflags |= O_EXCL;
-       if (!(flags & XATTR_REPLACE)) myflags |= O_CREAT;
-       attrfd = solaris_attropen(path, name, myflags, (mode_t) SOLARIS_ATTRMODE);
-       if (attrfd >= 0) {
-               ret = solaris_write_xattr(attrfd, value, size);
-               close(attrfd);
-       }
-       return ret;
-#else
-       errno = ENOSYS;
-       return -1;
-#endif
-}
-
-/**************************************************************************
- helper functions for Solaris' EA support
-****************************************************************************/
-#ifdef HAVE_ATTROPEN
-static ssize_t solaris_read_xattr(int attrfd, void *value, size_t size)
-{
-       struct stat sbuf;
-
-       if (fstat(attrfd, &sbuf) == -1) {
-               return -1;
-       }
-
-       /* This is to return the current size of the named extended attribute */
-       if (size == 0) {
-               return sbuf.st_size;
-       }
-
-       /* check size and read xattr */
-       if (sbuf.st_size > size) {
-               return -1;
-       }
-
-       return read(attrfd, value, sbuf.st_size);
-}
-
-static ssize_t solaris_list_xattr(int attrdirfd, char *list, size_t size)
-{
-       ssize_t len = 0;
-       DIR *dirp;
-       struct dirent *de;
-       int newfd = dup(attrdirfd);
-       /* CAUTION: The originating file descriptor should not be
-                   used again following the call to fdopendir().
-                   For that reason we dup() the file descriptor
-                   here to make things more clear. */
-       dirp = fdopendir(newfd);
-
-       while ((de = readdir(dirp))) {
-               size_t listlen;
-               if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..") ||
-                    !strcmp(de->d_name, "SUNWattr_ro") || !strcmp(de->d_name, "SUNWattr_rw")) 
-               {
-                       /* we don't want "." and ".." here: */
-                       LOG(log_maxdebug, logtype_default, "skipped EA %s\n",de->d_name);
-                       continue;
-               }
-
-               listlen = strlen(de->d_name);
-               if (size == 0) {
-                       /* return the current size of the list of extended attribute names*/
-                       len += listlen + 1;
-               } else {
-                       /* check size and copy entry + nul into list. */
-                       if ((len + listlen + 1) > size) {
-                               errno = ERANGE;
-                               len = -1;
-                               break;
-                       } else {
-                               strcpy(list + len, de->d_name);
-                               len += listlen;
-                               list[len] = '\0';
-                               ++len;
-                       }
-               }
-       }
-
-       if (closedir(dirp) == -1) {
-               LOG(log_error, logtype_default, "closedir dirp: %s",strerror(errno));
-               return -1;
-       }
-       return len;
-}
-
-static int solaris_unlinkat(int attrdirfd, const char *name)
-{
-       if (unlinkat(attrdirfd, name, 0) == -1) {
-               return -1;
-       }
-       return 0;
-}
-
-static int solaris_attropen(const char *path, const char *attrpath, int oflag, mode_t mode)
-{
-       int filedes = attropen(path, attrpath, oflag, mode);
-       if (filedes == -1) {
-        if (errno != ENOENT)
-            LOG(log_error, logtype_default, "attropen(\"%s\", ea:'%s'): %s",
-                path, attrpath, strerror(errno));
-        errno = ENOATTR;
-       }
-       return filedes;
-}
-
-static int solaris_openat(int fildes, const char *path, int oflag, mode_t mode)
-{
-       int filedes = openat(fildes, path, oflag, mode);
-       if (filedes == -1) {
-               LOG(log_error, logtype_default, "openat(\"%s\"): %s",
-            path, strerror(errno));
-       }
-       return filedes;
-}
-
-static int solaris_write_xattr(int attrfd, const char *value, size_t size)
-{
-       if ((ftruncate(attrfd, 0) == 0) && (write(attrfd, value, size) == size)) {
-               return 0;
-       } else {
-               LOG(log_error, logtype_default, "solaris_write_xattr: %s",
-            strerror(errno));
-               return -1;
-       }
-}
-
-#endif /*HAVE_ATTROPEN*/
-
index ffb524b825d88e7b2444a8e5cf742eaf4d5834d6..14a0f1647dec29ad31974533de1561c8bc9242c7 100644 (file)
@@ -22,6 +22,7 @@
 #include <atalk/logger.h>
 #include <atalk/unix.h>
 #include <atalk/acl.h>
+#include <atalk/compat.h>
 
 /* -----------------------------
    a dropbox is a folder where w is set but not r eg:
@@ -32,29 +33,6 @@ int stickydirmode(const char *name, const mode_t mode, const int dropbox, const
 {
     int retval = 0;
 
-#ifdef DROPKLUDGE
-    /* Turn on the sticky bit if this is a drop box, also turn off the setgid bit */
-    if ((dropbox & AFPVOL_DROPBOX)) {
-        int uid;
-
-        if ( ( (mode & S_IWOTH) && !(mode & S_IROTH)) ||
-             ( (mode & S_IWGRP) && !(mode & S_IRGRP)) )
-        {
-            uid=geteuid();
-            if ( seteuid(0) < 0) {
-                LOG(log_error, logtype_afpd, "stickydirmode: unable to seteuid root: %s", strerror(errno));
-            }
-            if ( (retval=chmod_acl( name, ( (DIRBITS | mode | S_ISVTX) & ~v_umask) )) < 0) {
-                LOG(log_error, logtype_afpd, "stickydirmode: chmod \"%s\": %s", fullpathname(name), strerror(errno) );
-            } else {
-                LOG(log_debug, logtype_afpd, "stickydirmode: chmod \"%s\": %s", fullpathname(name), strerror(retval) );
-            }
-            seteuid(uid);
-            return retval;
-        }
-    }
-#endif /* DROPKLUDGE */
-
     /*
      *  Ignore EPERM errors:  We may be dealing with a directory that is
      *  group writable, in which case chmod will fail.
index 0999b878a8c37c800660e3ffb6945893e78623fe..24aa7f63f161155433c4d044811adcf4b4a17880 100644 (file)
@@ -42,6 +42,7 @@
 #include <atalk/errchk.h>
 #include <atalk/bstrlib.h>
 #include <atalk/bstradd.h>
+#include <atalk/compat.h>
 
 struct perm {
     uid_t uid;
@@ -114,7 +115,7 @@ static int validupath_adouble(VFS_FUNC_ARGS_VALIDUPATH)
 static int RF_chown_adouble(VFS_FUNC_ARGS_CHOWN)
 {
     struct stat st;
-    char        *ad_p;
+    const char *ad_p;
 
     ad_p = vol->ad_path(path, ADFLAGS_HF );
 
@@ -173,7 +174,7 @@ static int RF_setfilmode_adouble(VFS_FUNC_ARGS_SETFILEMODE)
 /* ----------------- */
 static int RF_setdirunixmode_adouble(VFS_FUNC_ARGS_SETDIRUNIXMODE)
 {
-    char *adouble = vol->ad_path(name, ADFLAGS_DIR );
+    const char *adouble = vol->ad_path(name, ADFLAGS_DIR );
     int  dropbox = vol->v_flags;
 
     if (dir_rx_set(mode)) {
@@ -214,8 +215,8 @@ static int RF_setdirmode_adouble(VFS_FUNC_ARGS_SETDIRMODE)
 {
     int   dropbox = vol->v_flags;
     mode_t hf_mode = ad_hf_mode(mode);
-    char  *adouble = vol->ad_path(name, ADFLAGS_DIR );
-    char  *adouble_p = ad_dir(adouble);
+    const char  *adouble = vol->ad_path(name, ADFLAGS_DIR );
+    const char  *adouble_p = ad_dir(adouble);
 
     if (dir_rx_set(mode)) {
         if (stickydirmode(ad_dir(adouble), DIRBITS | mode, dropbox, vol->v_umask) < 0) 
@@ -307,8 +308,8 @@ static int RF_renamefile_adouble(VFS_FUNC_ARGS_RENAMEFILE)
              * create .AppleDouble if the file is already opened, so we
              * use a diff one, it's not a pb,ie it's not the same file, yet.
              */
-            ad_init(&ad, vol->v_adouble, vol->v_ad_options); 
-            if (!ad_open(dst, ADFLAGS_HF, O_RDWR | O_CREAT, 0666, &ad)) {
+            ad_init(&ad, vol); 
+            if (ad_open(&ad, dst, ADFLAGS_HF | ADFLAGS_RDWR | ADFLAGS_CREATE, 0666) == 0) {
                ad_close(&ad, ADFLAGS_HF);
                if (!unix_rename(dirfd, adsrc, -1, vol->ad_path(dst, 0 )) ) 
                    err = 0;
@@ -493,368 +494,71 @@ EC_CLEANUP:
 }
 #endif
 
-/*********************************************************************************
- * sfm adouble format
- *********************************************************************************/
-static int ads_chown_loop(struct dirent *de _U_, char *name, void *data, int flag _U_, mode_t v_umask _U_)
-{
-    struct perm   *owner  = data;
-    
-    if (chown( name , owner->uid, owner->gid ) < 0) {
-        return -1;
-    }
-    return 0;
-}
-
-static int RF_chown_ads(VFS_FUNC_ARGS_CHOWN)
-{
-    struct        stat st;
-    char          *ad_p;
-    struct perm   owner;
-    
-    owner.uid = uid;
-    owner.gid = gid;
-
-
-    ad_p = ad_dir(vol->ad_path(path, ADFLAGS_HF ));
-
-    if ( stat( ad_p, &st ) < 0 ) {
-       /* ignore */
-        return 0;
-    }
-    
-    if (chown( ad_p, uid, gid ) < 0) {
-       return -1;
-    }
-    return for_each_adouble("chown_ads", ad_p, ads_chown_loop, &owner, 1, vol->v_umask);
-}
-
-/* --------------------------------- */
-static int deletecurdir_ads1_loop(struct dirent *de _U_, char *name, void *data _U_, int flag _U_, mode_t v_umask _U_)
-{
-    return netatalk_unlink(name);
-}
-
-static int ads_delete_rf(char *name)
-{
-    int err;
-
-    if ((err = for_each_adouble("deletecurdir", name, deletecurdir_ads1_loop, NULL, 1, 0))) 
-        return err;
-    /* FIXME 
-     * it's a problem for a nfs mounted folder, there's .nfsxxx around
-     * for linux the following line solve it.
-     * but it could fail if rm .nfsxxx  create a new .nfsyyy :(
-    */
-    if ((err = for_each_adouble("deletecurdir", name, deletecurdir_ads1_loop, NULL, 1, 0))) 
-        return err;
-    return netatalk_rmdir(-1, name);
-}
-
-static int deletecurdir_ads_loop(struct dirent *de, char *name, void *data _U_, int flag _U_, mode_t v_umask _U_)
-{
-    struct stat st;
-    
-    /* bail if the file exists in the current directory.
-     * note: this will not fail with dangling symlinks */
-    
-    if (stat(de->d_name, &st) == 0) {
-        return AFPERR_DIRNEMPT;
-    }
-    return ads_delete_rf(name);
-}
-
-static int RF_deletecurdir_ads(VFS_FUNC_ARGS_DELETECURDIR)
-{
-    int err;
-
-    /* delete stray .AppleDouble files. this happens to get .Parent files as well. */
-    if ((err = for_each_adouble("deletecurdir", ".AppleDouble", deletecurdir_ads_loop, NULL, 1, 0))) 
-        return err;
-
-    return netatalk_rmdir(-1, ".AppleDouble" );
-}
-
-/* ------------------- */
-struct set_mode {
-    mode_t mode;
-    struct stat *st;
-};
-
-static int ads_setfilmode_loop(struct dirent *de _U_, char *name, void *data, int flag _U_, mode_t v_umask)
+/*************************************************************************
+ * EA adouble format 
+ ************************************************************************/
+static int validupath_ea(VFS_FUNC_ARGS_VALIDUPATH)
 {
-    struct set_mode *param = data;
-
-    return setfilmode(name, param->mode, param->st, v_umask);
-}
+    return 1;
+}             
 
-static int ads_setfilmode(const char * name, mode_t mode, struct stat *st, mode_t v_umask)
+/* ----------------- */
+static int RF_chown_ea(VFS_FUNC_ARGS_CHOWN)
 {
-    mode_t file_mode = ad_hf_mode(mode);
-    mode_t dir_mode = file_mode;
-    struct set_mode param;
-
-    if ((dir_mode & (S_IRUSR | S_IWUSR )))
-        dir_mode |= S_IXUSR;
-    if ((dir_mode & (S_IRGRP | S_IWGRP )))
-        dir_mode |= S_IXGRP;
-    if ((dir_mode & (S_IROTH | S_IWOTH )))
-        dir_mode |= S_IXOTH;
-
-       /* change folder */
-       dir_mode |= DIRBITS;
-    if (dir_rx_set(dir_mode)) {
-        if (chmod_acl( name,  dir_mode ) < 0)
-            return -1;
-    }
-    param.st = st;
-    param.mode = file_mode;
-    if (for_each_adouble("setfilmode_ads", name, ads_setfilmode_loop, &param, 0, v_umask) < 0)
-        return -1;
-
-    if (!dir_rx_set(dir_mode)) {
-        if (chmod_acl( name,  dir_mode ) < 0)
-            return -1;
-    }
-
     return 0;
 }
 
-static int RF_setfilmode_ads(VFS_FUNC_ARGS_SETFILEMODE)
+/* ---------------- */
+static int RF_renamedir_ea(VFS_FUNC_ARGS_RENAMEDIR)
 {
-    return ads_setfilmode(ad_dir(vol->ad_path(name, ADFLAGS_HF )), mode, st, vol->v_umask);
+    return 0;
 }
 
-/* ------------------- */
-static int RF_setdirunixmode_ads(VFS_FUNC_ARGS_SETDIRUNIXMODE)
+/* ---------------- */
+static int RF_deletecurdir_ea(VFS_FUNC_ARGS_DELETECURDIR)
 {
-    char *adouble = vol->ad_path(name, ADFLAGS_DIR );
-    char   ad_p[ MAXPATHLEN + 1];
-    int dropbox = vol->v_flags;
-
-    strlcpy(ad_p,ad_dir(adouble), MAXPATHLEN + 1);
-
-    if (dir_rx_set(mode)) {
-
-        /* .AppleDouble */
-        if (stickydirmode(ad_dir(ad_p), DIRBITS | mode, dropbox, vol->v_umask) < 0) 
-            return -1;
-
-        /* .AppleDouble/.Parent */
-        if (stickydirmode(ad_p, DIRBITS | mode, dropbox, vol->v_umask) < 0) 
-            return -1;
-    }
-
-    if (ads_setfilmode(ad_dir(vol->ad_path(name, ADFLAGS_DIR)), mode, st, vol->v_umask) < 0)
-        return -1;
-
-    if (!dir_rx_set(mode)) {
-        if (stickydirmode(ad_p, DIRBITS | mode, dropbox, vol->v_umask) < 0) 
-            return  -1 ;
-        if (stickydirmode(ad_dir(ad_p), DIRBITS | mode, dropbox, vol->v_umask) < 0) 
-            return -1;
-    }
     return 0;
 }
 
-/* ------------------- */
-struct dir_mode {
-    mode_t mode;
-    int    dropbox;
-};
-
-static int setdirmode_ads_loop(struct dirent *de _U_, char *name, void *data, int flag, mode_t v_umask)
+/* ---------------- */
+static int RF_setdirunixmode_ea(VFS_FUNC_ARGS_SETDIRUNIXMODE)
 {
-
-    struct dir_mode *param = data;
-    int    ret = 0; /* 0 ignore error, -1 */
-
-    if (dir_rx_set(param->mode)) {
-        if (stickydirmode(name, DIRBITS | param->mode, param->dropbox, v_umask) < 0) {
-            if (flag) {
-                return 0;
-            }
-            return ret;
-        }
-    }
-    if (ads_setfilmode(name, param->mode, NULL, v_umask) < 0)
-        return ret;
-
-    if (!dir_rx_set(param->mode)) {
-        if (stickydirmode(name, DIRBITS | param->mode, param->dropbox, v_umask) < 0) {
-            if (flag) {
-                return 0;
-            }
-            return ret;
-        }
-    }
     return 0;
 }
 
-static int RF_setdirmode_ads(VFS_FUNC_ARGS_SETDIRMODE)
+static int RF_setfilmode_ea(VFS_FUNC_ARGS_SETFILEMODE)
 {
-    char *adouble = vol->ad_path(name, ADFLAGS_DIR );
-    char   ad_p[ MAXPATHLEN + 1];
-    struct dir_mode param;
-
-    param.mode = mode;
-    param.dropbox = vol->v_flags;
-
-    strlcpy(ad_p,ad_dir(adouble), sizeof(ad_p));
-
-    if (dir_rx_set(mode)) {
-        /* .AppleDouble */
-        if (stickydirmode(ad_dir(ad_p), DIRBITS | mode, param.dropbox, vol->v_umask) < 0) 
-            return -1;
-    }
-
-    if (for_each_adouble("setdirmode_ads", ad_dir(ad_p), setdirmode_ads_loop, &param, vol_noadouble(vol), vol->v_umask))
-        return -1;
-
-    if (!dir_rx_set(mode)) {
-        if (stickydirmode(ad_dir(ad_p), DIRBITS | mode, param.dropbox, vol->v_umask) < 0 ) 
-            return -1;
-    }
     return 0;
 }
 
-/* ------------------- */
-static int setdirowner_ads1_loop(struct dirent *de _U_, char *name, void *data, int flag _U_, mode_t v_umask _U_)
+/* ---------------- */
+static int RF_setdirmode_ea(VFS_FUNC_ARGS_SETDIRMODE)
 {
-    struct perm   *owner  = data;
-
-    if ( chown( name, owner->uid, owner->gid ) < 0 && errno != EPERM ) {
-         LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
-                owner->uid, owner->gid, fullpathname(name), strerror(errno) );
-         /* return ( -1 ); Sometimes this is okay */
-    }
     return 0;
 }
 
-static int setdirowner_ads_loop(struct dirent *de _U_, char *name, void *data, int flag, mode_t v_umask _U_)
+/* ---------------- */
+static int RF_setdirowner_ea(VFS_FUNC_ARGS_SETDIROWNER)
 {
-    struct perm   *owner  = data;
-
-    if (for_each_adouble("setdirowner", name, setdirowner_ads1_loop, data, flag, 0) < 0)
-        return -1;
-
-    if ( chown( name, owner->uid, owner->gid ) < 0 && errno != EPERM ) {
-         LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
-                owner->uid, owner->gid, fullpathname(name), strerror(errno) );
-         /* return ( -1 ); Sometimes this is okay */
-    }
-    return 0;
+       return 0;
 }
 
-static int RF_setdirowner_ads(VFS_FUNC_ARGS_SETDIROWNER)
+static int RF_deletefile_ea(VFS_FUNC_ARGS_DELETEFILE)
 {
-    int           noadouble = vol_noadouble(vol);
-    char          adouble_p[ MAXPATHLEN + 1];
-    struct stat   st;
-    struct perm   owner;
-    
-    owner.uid = uid;
-    owner.gid = gid;
-
-    strlcpy(adouble_p, ad_dir(vol->ad_path(name, ADFLAGS_DIR )), sizeof(adouble_p));
-
-    if (for_each_adouble("setdirowner", ad_dir(adouble_p), setdirowner_ads_loop, &owner, noadouble, 0)) 
-        return -1;
-
-    /*
-     * We cheat: we know that chown doesn't do anything.
-     */
-    if ( stat( ".AppleDouble", &st ) < 0) {
-        if (errno == ENOENT && noadouble)
-            return 0;
-        LOG(log_error, logtype_afpd, "setdirowner: stat %s: %s", fullpathname(".AppleDouble"), strerror(errno) );
-        return -1;
-    }
-    if ( gid && gid != st.st_gid && chown( ".AppleDouble", uid, gid ) < 0 && errno != EPERM ) {
-        LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
-            uid, gid,fullpathname(".AppleDouble"), strerror(errno) );
-        /* return ( -1 ); Sometimes this is okay */
-    }
     return 0;
 }
-
-/* ------------------- */
-static int RF_deletefile_ads(VFS_FUNC_ARGS_DELETEFILE)
+static int RF_copyfile_ea(VFS_FUNC_ARGS_COPYFILE)
 {
-    int ret = 0;
-    int cwd = -1;
-    char *ad_p;
-
-    ad_p = ad_dir(vol->ad_path(file, ADFLAGS_HF ));
-
-    if (dirfd != -1) {
-        if (((cwd = open(".", O_RDONLY)) == -1) || (fchdir(dirfd) != 0)) {
-            ret = AFPERR_MISC;
-            goto exit;
-        }
-    }
-
-    ret = ads_delete_rf(ad_p);
-
-    if (dirfd != -1 && fchdir(cwd) != 0) {
-        LOG(log_error, logtype_afpd, "RF_deletefile_ads: cant chdir back. exit!");
-        exit(EXITERR_SYS);
-    }
-
-exit:
-    if (cwd != -1)
-        close(cwd);
-
-    return ret;
+    return 0;
 }
 
-/* --------------------------- */
-static int RF_renamefile_ads(VFS_FUNC_ARGS_RENAMEFILE)
+/* ---------------- */
+static int RF_renamefile_ea(VFS_FUNC_ARGS_RENAMEFILE)
 {
-    char  adsrc[ MAXPATHLEN + 1];
-    int   err = 0;
-
-    strcpy( adsrc, ad_dir(vol->ad_path(src, 0 )));
-    if (unix_rename(dirfd, adsrc, -1, ad_dir(vol->ad_path(dst, 0 ))) < 0) {
-        struct stat st;
-
-        err = errno;
-        if (errno == ENOENT) {
-               struct adouble    ad;
-
-            if (lstatat(dirfd, adsrc, &st)) /* source has no ressource fork, */
-                return 0;
-            
-            /* We are here  because :
-             * -there's no dest folder. 
-             * -there's no .AppleDouble in the dest folder.
-             * if we use the struct adouble passed in parameter it will not
-             * create .AppleDouble if the file is already opened, so we
-             * use a diff one, it's not a pb,ie it's not the same file, yet.
-             */
-            ad_init(&ad, vol->v_adouble, vol->v_ad_options); 
-            if (!ad_open(dst, ADFLAGS_HF, O_RDWR | O_CREAT, 0666, &ad)) {
-               ad_close(&ad, ADFLAGS_HF);
-
-               /* We must delete it */
-               RF_deletefile_ads(vol, -1, dst );
-               if (!unix_rename(dirfd, adsrc, -1, ad_dir(vol->ad_path(dst, 0 ))) ) 
-                   err = 0;
-                else 
-                   err = errno;
-            }
-            else { /* it's something else, bail out */
-                   err = errno;
-               }
-           }
-       }
-       if (err) {
-               errno = err;
-               return -1;
-       }
-       return 0;
+    return 0;
 }
 
+#if 0
 /*************************************************************************
  * osx adouble format 
  ************************************************************************/
@@ -915,6 +619,7 @@ static int RF_renamefile_osx(VFS_FUNC_ARGS_RENAMEFILE)
     }
     return 0;
 }
+#endif
 
 /********************************************************************************************
  * VFS chaining
@@ -1003,10 +708,10 @@ static struct vfs_ops vfs_master_funcs = {
 };
 
 /* 
- * Primary adouble modules: default, osx, sfm
+ * Primary adouble modules: v2, ea
  */
 
-static struct vfs_ops netatalk_adouble = {
+static struct vfs_ops netatalk_adouble_v2 = {
     /* vfs_validupath:    */ validupath_adouble,
     /* vfs_chown:         */ RF_chown_adouble,
     /* vfs_renamedir:     */ RF_renamedir_adouble,
@@ -1021,34 +726,18 @@ static struct vfs_ops netatalk_adouble = {
     NULL
 };
 
-static struct vfs_ops netatalk_adouble_osx = {
-    /* vfs_validupath:    */ validupath_osx,
-    /* vfs_chown:         */ RF_chown_adouble,
-    /* vfs_renamedir:     */ RF_renamedir_osx,
-    /* vfs_deletecurdir:  */ RF_deletecurdir_osx,
-    /* vfs_setfilmode:    */ RF_setfilmode_adouble,
-    /* vfs_setdirmode:    */ RF_setdirmode_osx,
-    /* vfs_setdirunixmode:*/ RF_setdirunixmode_osx,
-    /* vfs_setdirowner:   */ RF_setdirowner_osx,
-    /* vfs_deletefile:    */ RF_deletefile_adouble,
-    /* vfs_renamefile:    */ RF_renamefile_osx,
-    /* vfs_copyfile:      */ NULL,
-    NULL
-};
-
-/* samba sfm format. ad_path shouldn't be set her */
-static struct vfs_ops netatalk_adouble_sfm = {
-    /* vfs_validupath:    */ validupath_adouble,
-    /* vfs_chown:         */ RF_chown_ads,
-    /* vfs_renamedir:     */ RF_renamedir_adouble,
-    /* vfs_deletecurdir:  */ RF_deletecurdir_ads,
-    /* vfs_setfilmode:    */ RF_setfilmode_ads,
-    /* vfs_setdirmode:    */ RF_setdirmode_ads,
-    /* vfs_setdirunixmode:*/ RF_setdirunixmode_ads,
-    /* vfs_setdirowner:   */ RF_setdirowner_ads,
-    /* vfs_deletefile:    */ RF_deletefile_ads,
-    /* vfs_renamefile:    */ RF_renamefile_ads,
-    /* vfs_copyfile:      */ NULL,
+static struct vfs_ops netatalk_adouble_ea = {
+    /* vfs_validupath:    */ validupath_ea,
+    /* vfs_chown:         */ RF_chown_ea,
+    /* vfs_renamedir:     */ RF_renamedir_ea,
+    /* vfs_deletecurdir:  */ RF_deletecurdir_ea,
+    /* vfs_setfilmode:    */ RF_setfilmode_ea,
+    /* vfs_setdirmode:    */ RF_setdirmode_ea,
+    /* vfs_setdirunixmode:*/ RF_setdirunixmode_ea,
+    /* vfs_setdirowner:   */ RF_setdirowner_ea,
+    /* vfs_deletefile:    */ RF_deletefile_ea,
+    /* vfs_renamefile:    */ RF_renamefile_ea,
+    /* vfs_copyfile:      */ RF_copyfile_ea,
     NULL
 };
 
@@ -1150,17 +839,12 @@ void initvol_vfs(struct vol *vol)
     vol->vfs = &vfs_master_funcs;
 
     /* Default adouble stuff */
-    if (vol->v_adouble == AD_VERSION2_OSX) {
-        vol->vfs_modules[0] = &netatalk_adouble_osx;
-        vol->ad_path = ad_path_osx;
-    }
-    else if (vol->v_adouble == AD_VERSION1_SFM) {
-        vol->vfs_modules[0] = &netatalk_adouble_sfm;
-        vol->ad_path = ad_path_sfm;
-    }
-    else {
-        vol->vfs_modules[0] = &netatalk_adouble;
+    if (vol->v_adouble == AD_VERSION2) {
+        vol->vfs_modules[0] = &netatalk_adouble_v2;
         vol->ad_path = ad_path;
+    } else {
+        vol->vfs_modules[0] = &netatalk_adouble_ea;
+        vol->ad_path = ad_path_ea;
     }
 
     /* Extended Attributes */
index 38f728711e1af493bac5da84b21f51ed472a92dd..1bad3027eb7113fb7a18fd559db97cd3e7395a09 100644 (file)
@@ -2,18 +2,17 @@ EXTRA_DIST = \
        afs-check.m4            \
        cnid-backend.m4         \
        config-checks.m4        \
-       cups.m4                 \
        db3-check.m4            \
        grep-check.m4           \
        gssapi-check.m4         \
        iconv.m4                \
        largefile-check.m4      \
        libgcrypt.m4            \
+       netatalk.m4                     \
        pam-check.m4            \
        perl-check.m4           \
        ps-check.m4             \
        quota-check.m4          \
-       snprintf-check.m4       \
        srvloc.m4               \
        ssl-check.m4            \
        summary.m4              \
index 2b74b8cf8246d56a25b95c157aa5d915bed57052..799cfa2649e6fefab6fd3ffe3fdfc0c9a1a19571 100644 (file)
@@ -1,7 +1,7 @@
 dnl $Id: afs-check.m4,v 1.4 2005-08-11 20:15:35 didg Exp $
 dnl Autoconf macro to check whether AFS support should be enabled
 
-AC_DEFUN([NETATALK_AFS_CHECK], [
+AC_DEFUN([AC_NETATALK_AFS_CHECK], [
        AFS_LIBS=
        AFS_CFLAGS=
 
index eb4cf882efe7fe8ceaec72e974149fbaa3e835c3..1627fd1ddc8750e1b6e194f9ac17bd9d505a3d06 100644 (file)
@@ -1,7 +1,7 @@
 dnl $Id: config-checks.m4,v 1.6 2005-04-28 20:50:05 bfernhomberg Exp $
 dnl Autoconf macro to set the configuration directories.
 
-AC_DEFUN([NETATALK_CONFIG_DIRS], [
+AC_DEFUN([AC_NETATALK_CONFIG_DIRS], [
        PKGCONFDIR="${sysconfdir}/netatalk"
 
        AC_ARG_WITH(pkgconfdir,
diff --git a/macros/cups.m4 b/macros/cups.m4
deleted file mode 100644 (file)
index 5507aa4..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-dnl $Id: cups.m4,v 1.3 2010-04-12 14:28:47 franklahm Exp $
-dnl Autoconf macros to check for CUPS
-
-AC_DEFUN([NETATALK_AC_CUPS], [
-
-       dnl Don't use spool unless it's needed
-       spool_required=no
-       netatalk_cv_use_cups=no
-
-       AC_ARG_ENABLE(cups,
-       [  --enable-cups           Turn on CUPS support (default=auto)])
-
-       if test x$enable_cups != xno; then
-               AC_PATH_PROG(CUPS_CONFIG, cups-config)
-
-               if test "x$CUPS_CONFIG" != x; then
-                       AC_DEFINE(HAVE_CUPS, 1, [Define to enable CUPS Support])
-                       CUPS_CFLAGS="`$CUPS_CONFIG --cflags`"
-                       CUPS_LDFLAGS="`$CUPS_CONFIG --ldflags`"
-                       CUPS_LIBS="`$CUPS_CONFIG --libs`"
-                       CUPS_VERSION="`$CUPS_CONFIG --version`"
-                       AC_DEFINE_UNQUOTED(CUPS_API_VERSION, "`$CUPS_CONFIG --api-version`", [CUPS API Version])
-                       AC_SUBST(CUPS_CFLAGS)
-                       AC_SUBST(CUPS_LDFLAGS)
-                       AC_SUBST(CUPS_LIBS)
-       
-                       AC_MSG_CHECKING([CUPS version])
-                       AC_MSG_RESULT([$CUPS_VERSION])
-                       netatalk_cv_use_cups=yes
-       
-                       if test x"$netatalk_cv_HAVE_USABLE_ICONV" = x"no" ; then
-                               AC_WARN([*** Warning: iconv not found on your system, using simple ascii mapping***])
-                       fi
-                       spool_required="yes"
-               elif test x"$enable_cups" = "xyes"; then
-                       AC_MSG_ERROR([*** CUPS not found. You might need to specify the path to cups-config ***])
-               fi
-       fi
-
-       AC_MSG_CHECKING([whether CUPS support can be enabled])
-       AC_MSG_RESULT([$netatalk_cv_use_cups])
-
-
-       AC_ARG_WITH(spooldir,
-               [  --with-spooldir=PATH     path for spooldir used for CUPS support (LOCALSTATEDIR/spool/netatalk)],[
-
-               if test "$withval" = "no"; then
-                      if test x"$spool_required" = x"yes"; then
-                              AC_MSG_ERROR([*** CUPS support requires a spooldir ***])
-                      else
-                              AC_DEFINE(DISABLE_SPOOL, 1, [Define to enable spooldir support])
-                              AC_MSG_RESULT([spool disabled])
-                               fi
-               elif test "$withval" != "yes"; then
-                       SPOOLDIR="$withval"
-                       AC_MSG_RESULT([spooldir set to $withval])
-               else
-                       SPOOLDIR="${localstatedir}/spool/netatalk"
-                       AC_MSG_RESULT([spool set to default])
-               fi
-       ],[
-               SPOOLDIR="${localstatedir}/spool/netatalk"
-       ])
-
-       AM_CONDITIONAL(USE_SPOOLDIR, test x"$spool_required" = x"yes")
-       AC_SUBST(SPOOLDIR)
-])
index 2cc59cbbb6200f40785c98d22d2c1df944dc1050..902220befa3581e0a1d6a9dea9bc4a850e4ea599 100644 (file)
@@ -1,4 +1,3 @@
-dnl $Id: db3-check.m4,v 1.23 2010-04-12 14:28:48 franklahm Exp $
 dnl Autoconf macros to check for the Berkeley DB library
 
 dnl -- check header for minimum version and return version in
@@ -83,7 +82,8 @@ AC_DEFUN([NETATALK_BDB_TRY_LINK],[
 ])
 
 dnl -- This is called from configure
-AC_DEFUN([AC_PATH_BDB],[
+AC_DEFUN([AC_NETATALK_PATH_BDB],[
+if test "x$bdb_required" = "xyes"; then
     trybdbdir=""
     dobdbsearch=yes
     bdb_search_dirs="/usr/local /usr"
@@ -206,6 +206,7 @@ AC_DEFUN([AC_PATH_BDB],[
         ifelse([$1], , :, [$1])
     else
         ifelse([$2], , :, [$2])     
+               AC_MSG_ERROR([Berkeley DB library required but not found!])
     fi
 
     CFLAGS_REMOVE_USR_INCLUDE(BDB_CFLAGS)
@@ -214,6 +215,7 @@ AC_DEFUN([AC_PATH_BDB],[
     AC_SUBST(BDB_LIBS)
     AC_SUBST(BDB_BIN)
     AC_SUBST(BDB_PATH)
+fi
 ])
 
 
index 38d90d12c761a79ae7bb10f67020edb29034af4e..f604c9d6e690f4b99866bffd204bd2209da7550b 100644 (file)
@@ -28,10 +28,10 @@ AC_DEFUN([NETATALK_GSSAPI_CHECK],
          # Do no harm to the values of CFLAGS and LIBS while testing for
          # Kerberos support.
 
-               ac_save_CFLAGS=$CFLAGS
-               ac_save_CPPFLAGS=$CPPFLAGS
-               ac_save_LDFLAGS=$LDFLAGS
-               ac_save_LIBS=$LIBS
+               save_CFLAGS=$CFLAGS
+               save_CPPFLAGS=$CPPFLAGS
+               save_LDFLAGS=$LDFLAGS
+               save_LIBS=$LIBS
 
        if test x$FOUND_GSSAPI = x"no"; then
          #################################################
@@ -39,15 +39,15 @@ AC_DEFUN([NETATALK_GSSAPI_CHECK],
          AC_PATH_PROG(KRB5_CONFIG, krb5-config)
          AC_MSG_CHECKING(for working krb5-config)
          if test -x "$KRB5_CONFIG"; then
-           ac_save_CFLAGS=$CFLAGS
+           save_CFLAGS=$CFLAGS
            CFLAGS="";export CFLAGS
-           ac_save_LDFLAGS=$LDFLAGS
+           save_LDFLAGS=$LDFLAGS
            LDFLAGS="";export LDFLAGS
            GSSAPI_LIBS="`$KRB5_CONFIG --libs gssapi`"
            GSSAPI_CFLAGS="`$KRB5_CONFIG --cflags | sed s/@INCLUDE_des@//`"
            GSSAPI_CPPFLAGS="`$KRB5_CONFIG --cflags | sed s/@INCLUDE_des@//`"
-           CFLAGS=$ac_save_CFLAGS;export CFLAGS
-           LDFLAGS=$ac_save_LDFLAGS;export LDFLAGS
+           CFLAGS=$save_CFLAGS;export CFLAGS
+           LDFLAGS=$save_LDFLAGS;export LDFLAGS
            FOUND_GSSAPI=yes
            AC_MSG_RESULT(yes)
          else
@@ -136,10 +136,10 @@ AC_DEFUN([NETATALK_GSSAPI_CHECK],
                GSSAPI_LIBS=""
        fi
 
-        LIBS="$ac_save_LIBS"
-        CFLAGS="$ac_save_CFLAGS"
-        LDFLAGS="$ac_save_LDFLAGS"
-        CPPFLAGS="$ac_save_CPPFLAGS"
+        LIBS="$save_LIBS"
+        CFLAGS="$save_CFLAGS"
+        LDFLAGS="$save_LDFLAGS"
+        CPPFLAGS="$save_CPPFLAGS"
        fi
 
         if test x"$ac_cv_func_gss_acquire_cred" = x"yes"; then
@@ -151,5 +151,6 @@ AC_DEFUN([NETATALK_GSSAPI_CHECK],
 
        AC_SUBST(GSSAPI_LIBS)
        AC_SUBST(GSSAPI_CFLAGS)
+       AC_SUBST(GSSAPI_LDFLAGS)
 
 ])
index 77e0e6bbfe9906f8eab1640a00ac2ad7af5dc56c..4805662d7e3933d04aa648c41cc0d322691e7a23 100644 (file)
@@ -1,4 +1,4 @@
-AC_DEFUN([AC_CHECK_ICONV],
+AC_DEFUN([AC_NETATALK_CHECK_ICONV],
 [
 
 dnl    #################################################
index 957275e2fe5c4703e7c50aed5c18c4f8d246f56c..21b323ec0f23a3d53254daf35117976d16355037 100644 (file)
@@ -8,7 +8,7 @@ dnl version of libgcrypt is at least 1.2.5 *and* the API number is 1.  Using
 dnl this features allows to prevent build against newer versions of libgcrypt
 dnl with a changed API.
 dnl
-AC_DEFUN([AM_PATH_LIBGCRYPT],
+AC_DEFUN([AC_NETATALK_PATH_LIBGCRYPT],
 [ AC_ARG_WITH(libgcrypt-dir,
             AC_HELP_STRING([--with-libgcrypt-dir=PATH],
                            [path where LIBGCRYPT is installed (optional). 
@@ -107,6 +107,11 @@ fi
   if test $ok = yes; then
     LIBGCRYPT_CFLAGS=`$LIBGCRYPT_CONFIG --cflags`
     LIBGCRYPT_LIBS=`$LIBGCRYPT_CONFIG --libs`
+    neta_cv_compile_dhx2=yes
+    neta_cv_have_libgcrypt=yes
+       AC_MSG_NOTICE([Enabling DHX2 UAM])
+       AC_DEFINE(HAVE_LIBGCRYPT, 1, [Define if the DHX2 modules should be built with libgcrypt])
+       AC_DEFINE(UAM_DHX2, 1, [Define if the DHX2 UAM modules should be compiled])
     ifelse([$2], , :, [$2])
   else
     LIBGCRYPT_CFLAGS=""
diff --git a/macros/netatalk.m4 b/macros/netatalk.m4
new file mode 100644 (file)
index 0000000..4b13617
--- /dev/null
@@ -0,0 +1,835 @@
+dnl Kitchen sink for configuration macros
+
+dnl Check for optional admin group support
+AC_DEFUN([AC_NETATALK_ADMIN_GROUP], [
+    netatalk_cv_admin_group=yes
+    AC_MSG_CHECKING([for administrative group support])
+    AC_ARG_ENABLE(admin-group,
+           [  --disable-admin-group   disable admin group],[
+            if test x"$enableval" = x"no"; then
+                        AC_DEFINE(ADMIN_GRP, 0, [Define if the admin group should be enabled])
+                        netatalk_cv_admin_group=no
+                        AC_MSG_RESULT([no])
+               else
+                        AC_DEFINE(ADMIN_GRP, 1, [Define if the admin group should be enabled])
+                        AC_MSG_RESULT([yes])
+            fi],[
+               AC_DEFINE(ADMIN_GRP, 1, [Define if the admin group should be enabled])
+               AC_MSG_RESULT([yes])
+       ])
+])
+
+dnl Check for optional cracklib support
+AC_DEFUN([AC_NETATALK_CRACKLIB], [
+netatalk_cv_with_cracklib=no
+AC_ARG_WITH(cracklib,
+       [  --with-cracklib=DICT    enable/set location of cracklib dictionary],[
+       if test "x$withval" != "xno" ; then
+               cracklib="$withval"
+               AC_CHECK_LIB(crack, main, [
+                       AC_DEFINE(USE_CRACKLIB, 1, [Define if cracklib should be used])
+                       LIBS="$LIBS -lcrack"
+                       if test "$cracklib" = "yes"; then
+                               cracklib="/usr/$atalk_libname/cracklib_dict"
+                       fi
+                       AC_DEFINE_UNQUOTED(_PATH_CRACKLIB, "$cracklib",
+                               [path to cracklib dictionary])
+                       AC_MSG_RESULT([setting cracklib dictionary to $cracklib])
+                       netatalk_cv_with_cracklib=yes
+                       ],[
+                       AC_MSG_ERROR([cracklib not found!])
+                       ]
+               )
+       fi
+       ]
+)
+AC_MSG_CHECKING([for cracklib support])
+AC_MSG_RESULT([$netatalk_cv_with_cracklib])
+])
+
+dnl Check whether to enable debug code
+AC_DEFUN([AC_NETATALK_DEBUG], [
+AC_MSG_CHECKING([whether to enable verbose debug code])
+AC_ARG_ENABLE(debug,
+       [  --enable-debug          enable verbose debug code],[
+       if test "$enableval" != "no"; then
+               if test "$enableval" = "yes"; then
+                       AC_DEFINE(DEBUG, 1, [Define if verbose debugging information should be included])
+               else
+                       AC_DEFINE_UNQUOTED(DEBUG, $enableval, [Define if verbose debugging information should be included])
+               fi 
+               AC_MSG_RESULT([yes])
+       else
+               AC_MSG_RESULT([no])
+        AC_DEFINE(NDEBUG, 1, [Disable assertions])
+       fi
+       ],[
+               AC_MSG_RESULT([no])
+        AC_DEFINE(NDEBUG, 1, [Disable assertions])
+       ]
+)
+])
+
+dnl Check whethe to disable tickle SIGALARM stuff, which eases debugging
+AC_DEFUN([AC_NETATALK_DEBUGGING], [
+AC_MSG_CHECKING([whether to enable debugging with debuggers])
+AC_ARG_ENABLE(debugging,
+       [  --enable-debugging      disable SIGALRM timers and DSI tickles (eg for debugging with gdb/dbx/...)],[
+       if test "$enableval" != "no"; then
+               if test "$enableval" = "yes"; then
+                       AC_DEFINE(DEBUGGING, 1, [Define if you want to disable SIGALRM timers and DSI tickles])
+               else
+                       AC_DEFINE_UNQUOTED(DEBUGGING, $enableval, [Define if you want to disable SIGALRM timers and DSI tickles])
+               fi 
+               AC_MSG_RESULT([yes])
+       else
+               AC_MSG_RESULT([no])
+       fi
+       ],[
+               AC_MSG_RESULT([no])
+       ]
+)
+
+])
+
+dnl Check for optional shadow password support
+AC_DEFUN([AC_NETATALK_SHADOW], [
+netatalk_cv_use_shadowpw=no
+AC_ARG_WITH(shadow,
+       [  --with-shadow           enable shadow password support [[auto]]],
+       [netatalk_cv_use_shadowpw="$withval"],
+       [netatalk_cv_use_shadowpw=auto]
+)
+
+if test "x$netatalk_cv_use_shadowpw" != "xno"; then
+    AC_CHECK_HEADER([shadow.h])
+    if test x"$ac_cv_header_shadow_h" = x"yes"; then
+       netatalk_cv_use_shadowpw=yes
+       AC_DEFINE(SHADOWPW, 1, [Define if shadow passwords should be used])
+    else 
+      if test "x$shadowpw" = "xyes"; then
+        AC_MSG_ERROR([shadow support not available])
+      else
+               netatalk_cv_use_shadowpw=no
+      fi
+    fi 
+fi
+
+AC_MSG_CHECKING([whether shadow support should be enabled])
+if test "x$netatalk_cv_use_shadowpw" = "xyes"; then
+       AC_MSG_RESULT([yes])
+else
+       AC_MSG_RESULT([no])
+fi
+])
+
+dnl Check for optional valid-shell-check support
+AC_DEFUN([AC_NETATALK_SHELL_CHECK], [
+netatalk_cv_use_shellcheck=yes
+AC_MSG_CHECKING([whether checking for a valid shell should be enabled])
+AC_ARG_ENABLE(shell-check,
+       [  --disable-shell-check   disable checking for a valid shell],[
+       if test "$enableval" = "no"; then 
+               AC_DEFINE(DISABLE_SHELLCHECK, 1, [Define if shell check should be disabled])
+               AC_MSG_RESULT([no])
+               netatalk_cv_use_shellcheck=no
+       else
+               AC_MSG_RESULT([yes])
+       fi
+       ],[
+               AC_MSG_RESULT([yes])
+       ]
+)
+])
+
+dnl Check for optional sysv initscript install
+AC_DEFUN([AC_NETATALK_SYSV_STYLE], [
+    AC_ARG_WITH(sysv-style,
+                [  --with-sysv-style       use OS specific sysv config [[redhat-sysv|redhat-systemd|suse-sysv|suse-systemd|gentoo|netbsd|debian|systemd]]],
+                sysv_style="$withval", sysv_style=none
+    )
+    case "$sysv_style" in 
+    "redhat")
+           AC_MSG_ERROR([--enable-redhat is obsoleted. Use --enable-redhat-sysv or --enable-redhat-systemd.])
+        ;;
+    "redhat-sysv")
+           AC_MSG_RESULT([enabling redhat-style sysv (upstart) configuration])
+           ;;
+    "redhat-systemd")
+           AC_MSG_RESULT([enabling redhat-style systemd support])
+           ;;
+    "suse")
+           AC_MSG_RESULT([--enable-suse is obsoleted. Use --enable-suse-sysv or --enable-suse-systemd])
+        ;;
+    "suse-sysv")
+           AC_MSG_RESULT([enabling suse-style sysv configuration])
+           ;;
+    "suse-systemd")
+           AC_MSG_RESULT([enabling suse-style systemd support (>=openSUSE12.1)])
+           ;;
+    "gentoo")
+           AC_MSG_RESULT([enabling gentoo-style sysv support])
+        ;;
+    "netbsd")
+           AC_MSG_RESULT([enabling netbsd-style sysv support])
+        ;;
+    "debian")
+           AC_MSG_RESULT([enabling debian-style sysv support])
+        ;;
+    "systemd")
+           AC_MSG_RESULT([use general systemd configuration])
+        ;;
+    *)
+           AC_MSG_RESULT([disabling sysv support])
+        ;;
+    esac
+    AM_CONDITIONAL(USE_NETBSD, test x$sysv_style = xnetbsd)
+    AM_CONDITIONAL(USE_REDHAT_SYSV, test x$sysv_style = xredhat-sysv)
+    AM_CONDITIONAL(USE_SUSE_SYSV, test x$sysv_style = xsuse-sysv)
+    AM_CONDITIONAL(USE_SHADOWPW, test x$shadowpw = xyes)
+    AM_CONDITIONAL(USE_TRU64, test x$sysv_style = xtru64)
+    AM_CONDITIONAL(USE_SOLARIS, test x$sysv_style = xsolaris)
+    AM_CONDITIONAL(USE_GENTOO, test x$sysv_style = xgentoo)
+    AM_CONDITIONAL(USE_DEBIAN, test x$sysv_style = xdebian)
+    AM_CONDITIONAL(USE_SYSTEMD, test x$sysv_style = xsystemd || test x$sysv_style = xredhat-systemd || test x$sysv_style = xsuse-systemd)
+    AM_CONDITIONAL(USE_UNDEF, test x$sysv_style = xnone)
+
+])
+
+dnl OS specific configuration
+AC_DEFUN([AC_NETATALK_OS_SPECIFIC], [
+case "$host_os" in
+       *aix*)                          this_os=aix ;;
+       *freebsd*)                      this_os=freebsd ;;
+       *hpux11*)                       this_os=hpux11 ;;
+       *irix*)                         this_os=irix ;;
+       *linux*)                        this_os=linux ;;
+       *osx*)                          this_os=macosx ;;
+       *darwin*)                       this_os=macosx ;;
+       *netbsd*)                       this_os=netbsd ;;
+       *openbsd*)                      this_os=openbsd ;;
+       *osf*)                          this_os=tru64 ;;
+       *solaris*)                      this_os=solaris ;;
+esac
+
+case "$host_cpu" in
+       i386|i486|i586|i686|k7)         this_cpu=x86 ;;
+       alpha)                                          this_cpu=alpha ;;
+       mips)                                           this_cpu=mips ;;
+       powerpc|ppc)                            this_cpu=ppc ;;
+esac
+
+dnl --------------------- GNU source
+case "$this_os" in
+       linux)  AC_DEFINE(_GNU_SOURCE, 1, [Whether to use GNU libc extensions])
+        ;;
+     kfreebsd-gnu) AC_DEFINE(_GNU_SOURCE, 1, [Whether to use GNU libc extensions])
+        ;;
+esac
+
+dnl --------------------- operating system specific flags (port from sys/*)
+
+dnl ----- FreeBSD specific -----
+if test x"$this_os" = "xfreebsd"; then 
+       AC_MSG_RESULT([ * FreeBSD specific configuration])
+       AC_DEFINE(BSD4_4, 1, [BSD compatiblity macro])
+       AC_DEFINE(FREEBSD, 1, [Define if OS is FreeBSD])
+    AC_DEFINE(OPEN_NOFOLLOW_ERRNO, EMLINK, errno returned by open with O_NOFOLLOW)
+fi
+
+dnl ----- GNU/kFreeBSD specific -----
+if test x"$this_os" = "xkfreebsd-gnu"; then 
+       AC_MSG_RESULT([ * GNU/kFreeBSD specific configuration])
+       AC_DEFINE(BSD4_4, 1, [BSD compatiblity macro])
+       AC_DEFINE(FREEBSD, 1, [Define if OS is FreeBSD])
+    AC_DEFINE(OPEN_NOFOLLOW_ERRNO, EMLINK, errno returned by open with O_NOFOLLOW)
+fi
+
+dnl ----- Linux specific -----
+if test x"$this_os" = "xlinux"; then 
+       AC_MSG_RESULT([ * Linux specific configuration])
+       
+       dnl ----- check if we need the quotactl wrapper
+    AC_CHECK_HEADERS(linux/dqblk_xfs.h,,
+               [AC_CHECK_HEADERS(linux/xqm.h linux/xfs_fs.h)
+               AC_CHECK_HEADERS(xfs/libxfs.h xfs/xqm.h xfs/xfs_fs.h)]
+       )
+
+
+       dnl ----- as far as I can tell, dbtob always does the wrong thing
+       dnl ----- on every single version of linux I've ever played with.
+       dnl ----- see etc/afpd/quota.c
+       AC_DEFINE(HAVE_BROKEN_DBTOB, 1, [Define if dbtob is broken])
+
+       need_dash_r=no
+fi
+
+dnl ----- NetBSD specific -----
+if test x"$this_os" = "xnetbsd"; then 
+       AC_MSG_RESULT([ * NetBSD specific configuration])
+       AC_DEFINE(BSD4_4, 1, [BSD compatiblity macro])
+       AC_DEFINE(NETBSD, 1, [Define if OS is NetBSD])
+    AC_DEFINE(OPEN_NOFOLLOW_ERRNO, EFTYPE, errno returned by open with O_NOFOLLOW)
+
+       CFLAGS="-I\$(top_srcdir)/sys/netbsd $CFLAGS"
+       need_dash_r=yes 
+
+       dnl ----- NetBSD does not have crypt.h, uses unistd.h -----
+       AC_DEFINE(UAM_DHX, 1, [Define if the DHX UAM modules should be compiled])
+fi
+
+dnl ----- OpenBSD specific -----
+if test x"$this_os" = "xopenbsd"; then 
+       AC_MSG_RESULT([ * OpenBSD specific configuration])
+    AC_DEFINE(BSD4_4, 1, [BSD compatiblity macro])
+       dnl ----- OpenBSD does not have crypt.h, uses unistd.h -----
+       AC_DEFINE(UAM_DHX, 1, [Define if the DHX UAM modules should be compiled])
+fi
+
+dnl ----- Solaris specific -----
+if test x"$this_os" = "xsolaris"; then 
+       AC_MSG_RESULT([ * Solaris specific configuration])
+       AC_DEFINE(__svr4__, 1, [Solaris compatibility macro])
+       AC_DEFINE(_ISOC9X_SOURCE, 1, [Compatibility macro])
+       AC_DEFINE(NO_STRUCT_TM_GMTOFF, 1, [Define if the gmtoff member of struct tm is not available])
+       AC_DEFINE(SOLARIS, 1, [Solaris compatibility macro])
+    AC_DEFINE(_XOPEN_SOURCE, 600, [Solaris compilation environment])
+    AC_DEFINE(__EXTENSIONS__,  1, [Solaris compilation environment])
+       CFLAGS="-I\$(top_srcdir)/sys/generic $CFLAGS"
+       need_dash_r=yes
+       sysv_style=solaris
+
+       solaris_module=no
+       AC_MSG_CHECKING([if we can build Solaris kernel module])
+       if test -x /usr/ccs/bin/ld && test x"$netatalk_cv_ddp_enabled" = x"yes" ; then
+               solaris_module=yes
+       fi
+       AC_MSG_RESULT([$solaris_module])
+
+       COMPILE_64BIT_KMODULE=no
+       KCFLAGS=""
+       KLDFLAGS=""
+       COMPILE_KERNEL_GCC=no
+
+       if test "$solaris_module" = "yes"; then
+          dnl Solaris kernel module stuff
+           AC_MSG_CHECKING([if we have to build a 64bit kernel module])
+
+          # check for isainfo, if not found it has to be a 32 bit kernel (<=2.6)       
+          if test -x /usr/bin/isainfo; then
+               # check for 64 bit platform
+               if isainfo -kv | grep '^64-bit'; then
+                       COMPILE_64BIT_KMODULE=yes
+               fi
+          fi
+
+          AC_MSG_RESULT([$COMPILE_64BIT_KMODULE])
+
+          if test "${GCC}" = yes; then
+               COMPILE_KERNEL_GCC=yes
+               if test "$COMPILE_64BIT_KMODULE" = yes; then
+               
+                        AC_MSG_CHECKING([if we can build a 64bit kernel module])
+                       
+                        case `$CC --version 2>/dev/null` in
+                       [[12]].* | 3.0.*)
+                               COMPILE_64BIT_KMODULE=no
+                               COMPILE_KERNEL_GCC=no   
+                               solaris_module=no;;
+                       *)
+                               # use for 64 bit
+                               KCFLAGS="-m64"
+                               #KLDFLAGS="-melf64_sparc"
+                               KLDFLAGS="-64";;
+                       esac    
+                       
+                       AC_MSG_RESULT([$COMPILE_64BIT_KMODULE])
+                       
+               else
+                       KCFLAGS=""
+                       KLDFLAGS=""
+               fi
+               KCFLAGS="$KCFLAGS -D_KERNEL -Wall -Wstrict-prototypes"
+           else
+               if test "$COMPILE_64BIT_KMODULE" = yes; then
+                # use Sun CC (for a 64-bit kernel, uncomment " -xarch=v9 -xregs=no%appl ")
+                       KCFLAGS="-xarch=v9 -xregs=no%appl"
+                       KLDFLAGS="-64"
+               else
+                       KCFLAGS=""
+                       KLDFLAGS=""
+               fi
+               KCFLAGS="-D_KERNEL $KCFLAGS -mno-app-regs -munaligned-doubles -fpcc-struct-return"
+          fi
+
+           AC_CACHE_CHECK([for timeout_id_t],netatalk_cv_HAVE_TIMEOUT_ID_T,[
+           AC_TRY_LINK([\
+#include <sys/stream.h>
+#include <sys/ddi.h>],
+[\
+timeout_id_t dummy;
+],
+netatalk_cv_HAVE_TIMEOUT_ID_T=yes,netatalk_cv_HAVE_TIMEOUT_ID_T=no,netatalk_cv_HAVE_TIMEOUT_ID_T=cross)])
+
+          AC_DEFINE(HAVE_TIMEOUT_ID_T, test x"$netatalk_cv_HAVE_TIMEOUT_ID" = x"yes", [define for timeout_id_t])
+       fi
+
+       AC_SUBST(COMPILE_KERNEL_GCC)
+       AC_SUBST(COMPILE_64BIT_KMODULE)
+       AC_SUBST(KCFLAGS)
+       AC_SUBST(KLDFLAGS)
+fi
+
+])
+
+dnl Check for building PGP UAM module
+AC_DEFUN([AC_NETATALK_PGP_UAM], [
+AC_MSG_CHECKING([whether the PGP UAM should be build])
+AC_ARG_ENABLE(pgp-uam,
+       [  --enable-pgp-uam        enable build of PGP UAM module],[
+       if test "$enableval" = "yes"; then 
+               if test "x$neta_cv_have_openssl" = "xyes"; then 
+                       AC_DEFINE(UAM_PGP, 1, [Define if the PGP UAM module should be compiled])
+                       compile_pgp=yes
+                       AC_MSG_RESULT([yes])
+               else
+                       AC_MSG_RESULT([no])
+               fi
+       fi
+       ],[
+               AC_MSG_RESULT([no])
+       ]
+)
+])
+
+dnl Check for building Kerberos V UAM module
+AC_DEFUN([AC_NETATALK_KRB5_UAM], [
+netatalk_cv_build_krb5_uam=no
+AC_ARG_ENABLE(krbV-uam,
+       [  --enable-krbV-uam       enable build of Kerberos V UAM module],
+       [
+               if test x"$enableval" = x"yes"; then
+                       NETATALK_GSSAPI_CHECK([
+                               netatalk_cv_build_krb5_uam=yes
+                       ],[
+                               AC_MSG_ERROR([need GSSAPI to build Kerberos V UAM])
+                       ])
+               fi
+       ]
+       
+)
+
+AC_MSG_CHECKING([whether Kerberos V UAM should be build])
+if test x"$netatalk_cv_build_krb5_uam" = x"yes"; then
+       AC_MSG_RESULT([yes])
+else
+       AC_MSG_RESULT([no])
+fi
+AM_CONDITIONAL(USE_GSSAPI, test x"$netatalk_cv_build_krb5_uam" = x"yes")
+])
+
+dnl Check for overwrite the config files or not
+AC_DEFUN([AC_NETATALK_OVERWRITE_CONFIG], [
+AC_MSG_CHECKING([whether configuration files should be overwritten])
+AC_ARG_ENABLE(overwrite,
+       [  --enable-overwrite      overwrite configuration files during installation],
+       [OVERWRITE_CONFIG="${enable_overwrite}"],
+       [OVERWRITE_CONFIG="no"]
+)
+AC_MSG_RESULT([$OVERWRITE_CONFIG])
+AC_SUBST(OVERWRITE_CONFIG)
+])
+
+dnl Check for LDAP support, for client-side ACL visibility
+AC_DEFUN([AC_NETATALK_LDAP], [
+AC_MSG_CHECKING(for LDAP (necessary for client-side ACL visibility))
+AC_ARG_WITH(ldap,
+    [AS_HELP_STRING([--with-ldap],
+        [LDAP support (default=auto)])],
+    [ case "$withval" in
+      yes|no)
+          with_ldap="$withval"
+                 ;;
+      *)
+          with_ldap=auto
+          ;;
+      esac ])
+AC_MSG_RESULT($with_ldap)
+
+if test x"$with_ldap" != x"no" ; then
+       AC_CHECK_HEADER([ldap.h], with_ldap=yes,
+        [ if test x"$with_ldap" = x"yes" ; then
+            AC_MSG_ERROR([Missing LDAP headers])
+        fi
+               with_ldap=no
+        ])
+       AC_CHECK_LIB(ldap, ldap_init, with_ldap=yes,
+        [ if test x"$with_ldap" = x"yes" ; then
+            AC_MSG_ERROR([Missing LDAP library])
+        fi
+               with_ldap=no
+        ])
+fi
+
+if test x"$with_ldap" = x"yes"; then
+       AC_DEFINE(HAVE_LDAP,1,[Whether LDAP is available])
+fi
+])
+
+dnl Check for ACL support
+AC_DEFUN([AC_NETATALK_ACL], [
+AC_MSG_CHECKING(whether to support ACLs)
+AC_ARG_WITH(acls,
+    [AS_HELP_STRING([--with-acls],
+        [Include ACL support (default=auto)])],
+    [ case "$withval" in
+      yes|no)
+          with_acl_support="$withval"
+                 ;;
+      *)
+          with_acl_support=auto
+          ;;
+      esac ],
+    [with_acl_support=auto])
+AC_MSG_RESULT($with_acl_support)
+
+if test x"$with_acl_support" = x"no"; then
+       AC_MSG_RESULT(Disabling ACL support)
+       AC_DEFINE(HAVE_NO_ACLS,1,[Whether no ACLs support should be built in])
+else
+    with_acl_support=yes
+fi
+
+if test x"$with_acl_support" = x"yes" ; then
+       AC_MSG_NOTICE(checking whether ACL support is available:)
+       case "$host_os" in
+       *sysv5*)
+               AC_MSG_NOTICE(Using UnixWare ACLs)
+               AC_DEFINE(HAVE_UNIXWARE_ACLS,1,[Whether UnixWare ACLs are available])
+               ;;
+       *solaris*)
+               AC_MSG_NOTICE(Using solaris ACLs)
+               AC_DEFINE(HAVE_SOLARIS_ACLS,1,[Whether solaris ACLs are available])
+               ACL_LIBS="$ACL_LIBS -lsec"
+               ;;
+       *hpux*)
+               AC_MSG_NOTICE(Using HPUX ACLs)
+               AC_DEFINE(HAVE_HPUX_ACLS,1,[Whether HPUX ACLs are available])
+               ;;
+       *irix*)
+               AC_MSG_NOTICE(Using IRIX ACLs)
+               AC_DEFINE(HAVE_IRIX_ACLS,1,[Whether IRIX ACLs are available])
+               ;;
+       *aix*)
+               AC_MSG_NOTICE(Using AIX ACLs)
+               AC_DEFINE(HAVE_AIX_ACLS,1,[Whether AIX ACLs are available])
+               ;;
+       *osf*)
+               AC_MSG_NOTICE(Using Tru64 ACLs)
+               AC_DEFINE(HAVE_TRU64_ACLS,1,[Whether Tru64 ACLs are available])
+               ACL_LIBS="$ACL_LIBS -lpacl"
+               ;;
+       *darwin*)
+               AC_MSG_NOTICE(ACLs on Darwin currently not supported)
+               AC_DEFINE(HAVE_NO_ACLS,1,[Whether no ACLs support is available])
+               ;;
+       *)
+               AC_CHECK_LIB(acl,acl_get_file,[ACL_LIBS="$ACL_LIBS -lacl"])
+               case "$host_os" in
+               *linux*)
+                       AC_CHECK_LIB(attr,getxattr,[ACL_LIBS="$ACL_LIBS -lattr"])
+                       ;;
+               esac
+               AC_CACHE_CHECK([for POSIX ACL support],netatalk_cv_HAVE_POSIX_ACLS,[
+                       acl_LIBS=$LIBS
+                       LIBS="$LIBS $ACL_LIBS"
+                       AC_TRY_LINK([
+                               #include <sys/types.h>
+                               #include <sys/acl.h>
+                       ],[
+                               acl_t acl;
+                               int entry_id;
+                               acl_entry_t *entry_p;
+                               return acl_get_entry(acl, entry_id, entry_p);
+                       ],
+                       [netatalk_cv_HAVE_POSIX_ACLS=yes],
+                       [netatalk_cv_HAVE_POSIX_ACLS=no
+                with_acl_support=no])
+                       LIBS=$acl_LIBS
+               ])
+               if test x"$netatalk_cv_HAVE_POSIX_ACLS" = x"yes"; then
+                       AC_MSG_NOTICE(Using POSIX ACLs)
+                       AC_DEFINE(HAVE_POSIX_ACLS,1,[Whether POSIX ACLs are available])
+                       AC_CACHE_CHECK([for acl_get_perm_np],netatalk_cv_HAVE_ACL_GET_PERM_NP,[
+                               acl_LIBS=$LIBS
+                               LIBS="$LIBS $ACL_LIBS"
+                               AC_TRY_LINK([
+                                       #include <sys/types.h>
+                                       #include <sys/acl.h>
+                               ],[
+                                       acl_permset_t permset_d;
+                                       acl_perm_t perm;
+                                       return acl_get_perm_np(permset_d, perm);
+                               ],
+                               [netatalk_cv_HAVE_ACL_GET_PERM_NP=yes],
+                               [netatalk_cv_HAVE_ACL_GET_PERM_NP=no])
+                               LIBS=$acl_LIBS
+                       ])
+                       if test x"$netatalk_cv_HAVE_ACL_GET_PERM_NP" = x"yes"; then
+                               AC_DEFINE(HAVE_ACL_GET_PERM_NP,1,[Whether acl_get_perm_np() is available])
+                       fi
+
+
+                       AC_CACHE_CHECK([for acl_from_mode], netatalk_cv_HAVE_ACL_FROM_MODE,[
+                               acl_LIBS=$LIBS
+                               LIBS="$LIBS $ACL_LIBS"
+                AC_CHECK_FUNCS(acl_from_mode,
+                               [netatalk_cv_HAVE_ACL_FROM_MODE=yes],
+                               [netatalk_cv_HAVE_ACL_FROM_MODE=no])
+                               LIBS=$acl_LIBS
+                       ])
+                       if test x"netatalk_cv_HAVE_ACL_FROM_MODE" = x"yes"; then
+                               AC_DEFINE(HAVE_ACL_FROM_MODE,1,[Whether acl_from_mode() is available])
+                       fi
+
+               else
+                       AC_MSG_NOTICE(ACL support is not avaliable)
+                       AC_DEFINE(HAVE_NO_ACLS,1,[Whether no ACLs support is available])
+               fi
+               ;;
+    esac
+fi
+
+if test x"$with_acl_support" = x"yes" ; then
+   AC_CHECK_HEADERS([acl/libacl.h])
+    AC_DEFINE(HAVE_ACLS,1,[Whether ACLs support is available])
+    AC_SUBST(ACL_LIBS)
+fi
+])
+
+dnl Check for Extended Attributes support
+AC_DEFUN([AC_NETATALK_EXTENDED_ATTRIBUTES], [
+neta_cv_eas="ad"
+neta_cv_eas_sys_found=no
+neta_cv_eas_sys_not_found=no
+
+AC_CHECK_HEADERS(sys/attributes.h attr/xattr.h sys/xattr.h sys/extattr.h sys/uio.h sys/ea.h)
+
+case "$this_os" in
+
+  *osf*)
+       AC_SEARCH_LIBS(getproplist, [proplist])
+       AC_CHECK_FUNCS([getproplist fgetproplist setproplist fsetproplist],
+                   [neta_cv_eas_sys_found=yes],
+                   [neta_cv_eas_sys_not_found=yes])
+       AC_CHECK_FUNCS([delproplist fdelproplist add_proplist_entry get_proplist_entry],,
+                   [neta_cv_eas_sys_not_found=yes])
+       AC_CHECK_FUNCS([sizeof_proplist_entry],,
+                   [neta_cv_eas_sys_not_found=yes])
+  ;;
+
+  *solaris*)
+       AC_CHECK_FUNCS([attropen],
+                   [neta_cv_eas_sys_found=yes],
+                   [neta_cv_eas_sys_not_found=yes])
+  ;;
+
+  'freebsd')
+    AC_CHECK_FUNCS([extattr_delete_fd extattr_delete_file extattr_delete_link],
+                   [neta_cv_eas_sys_found=yes],
+                   [neta_cv_eas_sys_not_found=yes])
+    AC_CHECK_FUNCS([extattr_get_fd extattr_get_file extattr_get_link],,
+                   [neta_cv_eas_sys_not_found=yes])
+    AC_CHECK_FUNCS([extattr_list_fd extattr_list_file extattr_list_link],,
+                   [neta_cv_eas_sys_not_found=yes])
+    AC_CHECK_FUNCS([extattr_set_fd extattr_set_file extattr_set_link],,
+                   [neta_cv_eas_sys_not_found=yes])
+  ;;
+
+  *freebsd4* | *dragonfly* )
+    AC_DEFINE(BROKEN_EXTATTR, 1, [Does extattr API work])
+  ;;
+
+  *)
+       AC_SEARCH_LIBS(getxattr, [attr])
+
+    if test "x$neta_cv_eas_sys_found" != "xyes" ; then
+       AC_CHECK_FUNCS([getxattr lgetxattr fgetxattr listxattr llistxattr],
+                      [neta_cv_eas_sys_found=yes],
+                      [neta_cv_eas_sys_not_found=yes])
+          AC_CHECK_FUNCS([flistxattr removexattr lremovexattr fremovexattr],,
+                      [neta_cv_eas_sys_not_found=yes])
+          AC_CHECK_FUNCS([setxattr lsetxattr fsetxattr],,
+                      [neta_cv_eas_sys_not_found=yes])
+    fi
+
+    if test "x$neta_cv_eas_sys_found" != "xyes" ; then
+          AC_CHECK_FUNCS([getea fgetea lgetea listea flistea llistea],
+                      [neta_cv_eas_sys_found=yes],
+                      [neta_cv_eas_sys_not_found=yes])
+          AC_CHECK_FUNCS([removeea fremoveea lremoveea setea fsetea lsetea],,
+                      [neta_cv_eas_sys_not_found=yes])
+    fi
+
+    if test "x$neta_cv_eas_sys_found" != "xyes" ; then
+          AC_CHECK_FUNCS([attr_get attr_list attr_set attr_remove],,
+                      [neta_cv_eas_sys_not_found=yes])
+       AC_CHECK_FUNCS([attr_getf attr_listf attr_setf attr_removef],,
+                      [neta_cv_eas_sys_not_found=yes])
+    fi
+  ;;
+esac
+
+# Do xattr functions take additional options like on Darwin?
+if test x"$ac_cv_func_getxattr" = x"yes" ; then
+       AC_CACHE_CHECK([whether xattr interface takes additional options], smb_attr_cv_xattr_add_opt, [
+               old_LIBS=$LIBS
+               LIBS="$LIBS $ACL_LIBS"
+               AC_TRY_COMPILE([
+                       #include <sys/types.h>
+                       #if HAVE_ATTR_XATTR_H
+                       #include <attr/xattr.h>
+                       #elif HAVE_SYS_XATTR_H
+                       #include <sys/xattr.h>
+                       #endif
+               ],[
+                       getxattr(0, 0, 0, 0, 0, 0);
+               ],
+               [smb_attr_cv_xattr_add_opt=yes],
+               [smb_attr_cv_xattr_add_opt=no;LIBS=$old_LIBS])
+       ])
+       if test x"$smb_attr_cv_xattr_add_opt" = x"yes"; then
+               AC_DEFINE(XATTR_ADD_OPT, 1, [xattr functions have additional options])
+       fi
+fi
+
+if test "x$neta_cv_eas_sys_found" = "xyes" ; then
+   if test "x$neta_cv_eas_sys_not_found" != "xyes" ; then
+      neta_cv_eas="$neta_cv_eas | sys"
+   fi
+fi
+AC_DEFINE_UNQUOTED(EA_MODULES,["$neta_cv_eas"],[Available Extended Attributes modules])
+])
+
+dnl Check for libsmbsharemodes from Samba for Samba/Netatalk access/deny/share modes interop
+dnl Defines "neta_cv_have_smbshmd" to "yes" or "no"
+dnl AC_SUBST's "SMB_SHAREMODES_CFLAGS" and "SMB_SHAREMODES_LDFLAGS"
+dnl AM_CONDITIONAL's "USE_SMB_SHAREMODES"
+AC_DEFUN([AC_NETATALK_SMB_SHAREMODES], [
+    neta_cv_have_smbshmd=no
+    AC_ARG_WITH(smbsharemodes-lib,
+                [  --with-smbsharemodes-lib=PATH        PATH to libsmbsharemodes lib from Samba],
+                [SMB_SHAREMODES_LDFLAGS="-L$withval -lsmbsharemodes"]
+    )
+    AC_ARG_WITH(smbsharemodes-include,
+                [  --with-smbsharemodes-include=PATH    PATH to libsmbsharemodes header from Samba],
+                [SMB_SHAREMODES_CFLAGS="-I$withval"]
+    )
+    AC_ARG_WITH(smbsharemodes,
+                [AS_HELP_STRING([--with-smbsharemodes],[Samba interop (default is yes)])],
+                [use_smbsharemodes=$withval],
+                [use_smbsharemodes=yes]
+    )
+
+    if test x"$use_smbsharemodes" = x"yes" ; then
+        AC_MSG_CHECKING([whether to enable Samba/Netatalk access/deny/share-modes interop])
+
+        saved_CFLAGS="$CFLAGS"
+        saved_LDFLAGS="$LDFLAGS"
+        CFLAGS="$SMB_SHAREMODES_CFLAGS $CFLAGS"
+        LDFLAGS="$SMB_SHAREMODES_LDFLAGS $LDFLAGS"
+
+        AC_LINK_IFELSE(
+            [#include <unistd.h>
+             #include <stdio.h>
+             #include <sys/time.h>
+             #include <time.h>
+             #include <stdint.h>
+             /* From messages.h */
+             struct server_id {
+                 pid_t pid;
+             };
+             #include "smb_share_modes.h"
+             int main(void) { (void)smb_share_mode_db_open(""); return 0;}],
+            [neta_cv_have_smbshmd=yes]
+        )
+
+        AC_MSG_RESULT($neta_cv_have_smbshmd)
+        AC_SUBST(SMB_SHAREMODES_CFLAGS, [$SMB_SHAREMODES_CFLAGS])
+        AC_SUBST(SMB_SHAREMODES_LDFLAGS, [$SMB_SHAREMODES_LDFLAGS])
+        CFLAGS="$saved_CFLAGS"
+        LDFLAGS="$saved_LDFLAGS"
+    fi
+
+    AM_CONDITIONAL(USE_SMB_SHAREMODES, test x"$neta_cv_have_smbshmd" = x"yes")
+])
+
+dnl ------ Check for sendfile() --------
+AC_DEFUN([AC_NETATALK_SENDFILE], [
+netatalk_cv_search_sendfile=yes
+AC_ARG_ENABLE(sendfile,
+    [  --disable-sendfile       disable sendfile syscall],
+    [if test x"$enableval" = x"no"; then
+            netatalk_cv_search_sendfile=no
+        fi]
+)
+
+if test x"$netatalk_cv_search_sendfile" = x"yes"; then
+   case "$host_os" in
+   *linux*)
+        AC_DEFINE(SENDFILE_FLAVOR_LINUX,1,[Whether linux sendfile() API is available])
+        AC_CHECK_FUNC([sendfile], [netatalk_cv_HAVE_SENDFILE=yes])
+        ;;
+
+    *solaris*)
+        AC_DEFINE(SENDFILE_FLAVOR_SOLARIS, 1, [Solaris sendfile()])
+        AC_SEARCH_LIBS(sendfile, sendfile)
+        AC_CHECK_FUNC([sendfile], [netatalk_cv_HAVE_SENDFILE=yes])
+        ;;
+
+    *freebsd*)
+        AC_DEFINE(SENDFILE_FLAVOR_BSD, 1, [Define if the sendfile() function uses BSD semantics])
+        AC_CHECK_FUNC([sendfile], [netatalk_cv_HAVE_SENDFILE=yes])
+        ;;
+
+    *)
+        ;;
+
+    esac
+
+    if test x"$netatalk_cv_HAVE_SENDFILE" = x"yes"; then
+        AC_DEFINE(WITH_SENDFILE,1,[Whether sendfile() should be used])
+    fi
+fi
+])
+
+dnl --------------------- Check if realpath() takes NULL
+AC_DEFUN([AC_NETATALK_REALPATH], [
+AC_CACHE_CHECK([if the realpath function allows a NULL argument],
+    neta_cv_REALPATH_TAKES_NULL, [
+        AC_TRY_RUN([
+            #include <stdio.h>
+            #include <limits.h>
+            #include <signal.h>
+
+            void exit_on_core(int ignored) {
+                 exit(1);
+            }
+
+            main() {
+                char *newpath;
+                signal(SIGSEGV, exit_on_core);
+                newpath = realpath("/tmp", NULL);
+                exit((newpath != NULL) ? 0 : 1);
+            }],
+            neta_cv_REALPATH_TAKES_NULL=yes,
+            neta_cv_REALPATH_TAKES_NULL=no,
+            neta_cv_REALPATH_TAKES_NULL=cross
+        )
+    ]
+)
+
+if test x"$neta_cv_REALPATH_TAKES_NULL" = x"yes"; then
+    AC_DEFINE(REALPATH_TAKES_NULL,1,[Whether the realpath function allows NULL])
+fi
+])
\ No newline at end of file
index e5663db347fb0f5e3b08884791014305e5c3dbc4..6bc40cbad841562161bf2c1a6a1f3cd776cdb5e4 100644 (file)
@@ -1,7 +1,8 @@
 dnl $Id: pam-check.m4,v 1.6 2010-01-11 13:06:02 franklahm Exp $
 dnl PAM finding macro
 
-AC_DEFUN([AC_PATH_PAM], [
+AC_DEFUN([AC_NETATALK_PATH_PAM], [
+    netatalk_cv_use_pam=no
        AC_ARG_WITH(pam, [  --with-pam[[=PATH]]       specify path to PAM installation [[auto]]],
                [
                        require_pam="yes"
@@ -125,6 +126,10 @@ AC_DEFUN([AC_PATH_PAM], [
        else
                AC_MSG_RESULT([yes])
                ifelse([$1], , :, [$1])
+        use_pam_so=yes
+           compile_pam=yes
+           netatalk_cv_use_pam=yes
+           AC_DEFINE(USE_PAM, 1, [Define to enable PAM support])
        fi
 
     LIB_REMOVE_USR_LIB(PAM_LIBS)
index 44e89bc966840548c411952f21f3286d8ead543c..b7e0c3a213f659dfd041eb04be39cc672c061a17 100644 (file)
@@ -2,7 +2,7 @@ dnl $Id: quota-check.m4,v 1.6 2005-07-20 23:58:21 didg Exp $
 dnl Autoconf macro to check for quota support
 dnl FIXME: This is in now way complete.
 
-AC_DEFUN([AC_CHECK_QUOTA], [
+AC_DEFUN([AC_NETATALK_CHECK_QUOTA], [
        AC_ARG_ENABLE(quota,
        [  --enable-quota           Turn on quota support (default=auto)])
 
diff --git a/macros/snprintf-check.m4 b/macros/snprintf-check.m4
deleted file mode 100644 (file)
index bee8ad7..0000000
+++ /dev/null
@@ -1,132 +0,0 @@
-dnl Check for (v)snprintf functions
-
-AC_DEFUN([NETATALK_SNPRINTF_CHECK], [
-       AC_CHECK_FUNCS(snprintf vsnprintf)
-
-       AC_CHECK_HEADERS(stdarg.h varargs.h)
-
-       AC_CHECK_FUNCS(strerror)
-       AC_CACHE_CHECK(for errno,
-       ac_cv_errno,
-       [
-       AC_TRY_LINK(,[extern int errno; return (errno);],
-               ac_cv_errno=yes, ac_cv_errno=no)
-       ])
-       if test "$ac_cv_errno" = yes; then
-               AC_DEFINE(HAVE_ERRNO, 1, [Define if errno declaration exists])
-               AC_CACHE_CHECK(for errno declaration,
-               ac_cv_decl_errno,
-               [
-               AC_TRY_COMPILE([
-               #include <stdio.h>
-               #ifdef HAVE_STDLIB_H
-               #include <stdlib.h>
-               #endif
-               #ifdef HAVE_UNISTD_H
-               #include <unistd.h>
-               #endif
-               #ifdef HAVE_ERRNO_H
-               #include <errno.h>
-               #endif
-               ],[return(sys_nerr);],
-                       ac_cv_decl_errno=yes, ac_cv_decl_errno=no)
-               ])
-               if test "$ac_cv_decl_errno" = yes; then
-                       AC_DEFINE(HAVE_DECL_ERRNO, 1, [Define if errno declaration exists])
-               fi;
-       fi
-
-       AC_CACHE_CHECK(for sys_nerr,
-       ac_cv_sys_nerr,
-       [
-       AC_TRY_LINK(,[extern int sys_nerr; return (sys_nerr);],
-               ac_cv_sys_nerr=yes, ac_cv_sys_nerr=no)
-       ])
-       if test "$ac_cv_sys_nerr" = yes; then
-               AC_DEFINE(HAVE_SYS_NERR, 1, [Define if sys_nerr declaration exists])
-               AC_CACHE_CHECK(for sys_nerr declaration,
-               ac_cv_decl_sys_nerr,
-               [
-               AC_TRY_COMPILE([
-               #include <stdio.h>
-               #ifdef HAVE_STDLIB_H
-               #include <stdlib.h>
-               #endif
-               #ifdef HAVE_UNISTD_H
-               #include <unistd.h>
-               #endif],[return(sys_nerr);],
-               ac_cv_decl_sys_nerr_def=yes, ac_cv_decl_sys_nerr_def=no)
-               ])
-               if test "$ac_cv_decl_sys_nerr" = yes; then
-                       AC_DEFINE(HAVE_DECL_SYS_NERR, 1, [Define if sys_nerr declaration exists])
-               fi
-       fi
-
-
-       AC_CACHE_CHECK(for sys_errlist array,
-       ac_cv_sys_errlist,
-       [AC_TRY_LINK(,[extern char *sys_errlist[];
-               sys_errlist[0];],
-               ac_cv_sys_errlist=yes, ac_cv_sys_errlist=no)
-       ])
-       if test "$ac_cv_sys_errlist" = yes; then
-               AC_DEFINE(HAVE_SYS_ERRLIST, 1, [Define if sys_errlist declaration exists])
-               AC_CACHE_CHECK(for sys_errlist declaration,
-               ac_cv_sys_errlist_def,
-               [AC_TRY_COMPILE([
-               #include <stdio.h>
-               #include <errno.h>
-               #ifdef HAVE_STDLIB_H
-               #include <stdlib.h>
-               #endif
-               #ifdef HAVE_UNISTD_H
-               #include <unistd.h>
-               #endif],[char *s = sys_errlist[0]; return(*s);],
-               ac_cv_decl_sys_errlist=yes, ac_cv_decl_sys_errlist=no)
-               ])
-               if test "$ac_cv_decl_sys_errlist" = yes; then
-                       AC_DEFINE(HAVE_DECL_SYS_ERRLIST, 1, [Define if sys_errlist declaration exists])
-               fi
-       fi
-
-
-
-       AC_CACHE_CHECK(for long long,
-       ac_cv_long_long,
-       [
-       AC_TRY_COMPILE([
-       #include <stdio.h>
-       #include <sys/types.h>
-       ], [printf("%d",sizeof(long long));],
-       ac_cv_long_long=yes, ac_cv_long_long=no)
-       ])
-       if test $ac_cv_long_long = yes; then
-         AC_DEFINE(HAVE_LONG_LONG, 1, [Define if long long is a valid data type])
-       fi
-
-       AC_CACHE_CHECK(for long double,
-       ac_cv_long_double,
-       [
-       AC_TRY_COMPILE([
-       #include <stdio.h>
-       #include <sys/types.h>
-       ], [printf("%d",sizeof(long double));],
-       ac_cv_long_double=yes, ac_cv_long_double=no)
-       ])
-       if test $ac_cv_long_double = yes; then
-         AC_DEFINE(HAVE_LONG_DOUBLE, 1, [Define if long double is a valid data type])
-       fi
-
-       AC_CACHE_CHECK(for quad_t,
-       ac_cv_quad_t,
-       [
-       AC_TRY_COMPILE([
-       #include <stdio.h>
-       #include <sys/types.h>
-       ], [printf("%d",sizeof(quad_t));],
-       ac_cv_quad_t=yes, ac_cv_quad_t=no)
-       ])
-       if test $ac_cv_quad_t = yes; then
-         AC_DEFINE(HAVE_QUAD_T, 1, [Define if quad_t is a valid data type])
-       fi
-])
index 4fe3fe2a3e0b751178aab601c53228751a14f1f9..99f24f4b99ea2190701e4299b42b06c166269235 100644 (file)
@@ -1,8 +1,6 @@
 dnl Check for optional server location protocol support (used by MacOS X)
 
-dnl $Id: srvloc.m4,v 1.10 2009-12-13 11:58:30 franklahm Exp $
-
-AC_DEFUN([NETATALK_SRVLOC], [
+AC_DEFUN([AC_NETATALK_SRVLOC], [
 
        SLP_LIBS=""
        SLP_CFLAGS=""
index 9de28019fb5b7473da1091e19ff72bf54135694c..8d9c1b6c66650e5ca8f8f337057b8a229c69cccc 100644 (file)
@@ -1,7 +1,7 @@
 dnl $Id: ssl-check.m4,v 1.14 2008-11-22 12:07:26 didg Exp $
 dnl Autoconf macro to check for SSL or OpenSSL
 
-AC_DEFUN([AC_CRYPT], [
+AC_DEFUN([AC_NETATALK_CRYPT], [
 
        saveLIBS=$LIBS
        LIBS=""
@@ -17,7 +17,7 @@ AC_DEFUN([AC_CRYPT], [
 ])
 
 
-AC_DEFUN([AC_PATH_SSL], [
+AC_DEFUN([AC_NETATALK_PATH_SSL], [
        AC_ARG_WITH(ssl-dir, [  --with-ssl-dir=PATH     specify path to OpenSSL installation (must contain
                           lib and include dirs)],
                [
index 4c87d8965b712029721b90777dac39676108fd84..39d69cdceb12f5f5f1cb690133934191d6899252 100644 (file)
@@ -11,8 +11,8 @@ AC_DEFUN([AC_NETATALK_CONFIG_SUMMARY], [
                AC_MSG_RESULT([         none])
        fi
        AC_MSG_RESULT([    AFP:])
-       AC_MSG_RESULT([         Large file support (>2GB) for AFP3: $wx_largefile])
        AC_MSG_RESULT([         Extended Attributes: $neta_cv_eas])
+       AC_MSG_RESULT([         ACL support: $with_acl_support])
        AC_MSG_RESULT([    CNID:])
        AC_MSG_RESULT([         backends: $compiled_backends])
        AC_MSG_RESULT([    UAMS:])
@@ -35,20 +35,12 @@ AC_DEFUN([AC_NETATALK_CONFIG_SUMMARY], [
        if test x"$netatalk_cv_build_krb5_uam" = x"yes"; then
                AC_MSG_RESULT([         Kerberos V])
        fi
-       if test x"$compile_kerberos" = x"yes"; then
-               AC_MSG_RESULT([         Kerberos IV])
-       fi
        if test x"$compile_pgp" = x"yes"; then
                AC_MSG_RESULT([         PGP])
        fi
        AC_MSG_RESULT([         clrtxt  ($uams_using_options)])
        AC_MSG_RESULT([         guest])
        AC_MSG_RESULT([    Options:])
-       AC_MSG_RESULT([         DDP (AppleTalk) support: $netatalk_cv_ddp_enabled])
-       if test "x$netatalk_cv_ddp_enabled" = "xyes"; then
-               AC_MSG_RESULT([         CUPS support:            $netatalk_cv_use_cups])
-               AC_MSG_RESULT([         Apple 2 boot support:    $compile_a2boot])
-       fi
        AC_MSG_RESULT([         SLP support:             $netatalk_cv_srvloc])
        AC_MSG_RESULT([         Zeroconf support:        $netatalk_cv_zeroconf])
        AC_MSG_RESULT([         tcp wrapper support:     $netatalk_cv_tcpwrap])
@@ -59,8 +51,7 @@ dnl   fi
        AC_MSG_RESULT([         admin group support:     $netatalk_cv_admin_group])
        AC_MSG_RESULT([         valid shell check:       $netatalk_cv_use_shellcheck])
        AC_MSG_RESULT([         cracklib support:        $netatalk_cv_with_cracklib])
-       AC_MSG_RESULT([         dropbox kludge:          $netatalk_cv_dropkludge])
-       AC_MSG_RESULT([         force volume uid/gid:    $netatalk_cv_force_uidgid])
+       AC_MSG_RESULT([         Samba sharemode interop: $neta_cv_have_smbshmd])
        AC_MSG_RESULT([         ACL support:             $with_acl_support])
        AC_MSG_RESULT([         LDAP support:            $with_ldap])
        if test x"$use_pam_so" = x"yes" -a x"$netatalk_cv_install_pam" = x"no"; then
index d770f049d1ea58ef1a0ed7e1481aae68bc562648..55b0f8c179428c464634cd6f5aa601b6f6521a9f 100644 (file)
@@ -1,6 +1,6 @@
 dnl $Id: tcp-wrappers.m4,v 1.4 2008-08-11 20:44:03 didg Exp $
 
-AC_DEFUN([NETATALK_TCP_WRAPPERS], [
+AC_DEFUN([AC_NETATALK_TCP_WRAPPERS], [
        check=maybe
        AC_ARG_ENABLE(tcp-wrappers,
                [  --disable-tcp-wrappers  disable TCP wrappers support],
index ec722c1e4b1f0d574678d7d8dc1258877742c1d0..029990dc98ebacdef3a1c3f1107f0ee409c208d4 100644 (file)
@@ -1,7 +1,7 @@
 dnl $Id: webmin.m4,v 1.1 2009-10-22 08:36:30 franklahm Exp $
 dnl Autoconf macro to install webmin + netatalk webmin module
 
-AC_DEFUN([NETATALK_WEBMIN],[
+AC_DEFUN([AC_NETATALK_WEBMIN],[
     AC_ARG_WITH(webmin,
         [  --with-webmin=PATH      path where webmin is installed [[$PKGCONFDIR/webmin]]],
         if test "x$withval" = "xyes"; then
index 788a193038fb217369d203bf581febb6766c4d11..0209dc0936e303cbd6c08dfef646a665f98a00d4 100644 (file)
@@ -1,6 +1,6 @@
 dnl Check for optional Zeroconf support
 
-AC_DEFUN([NETATALK_ZEROCONF], [
+AC_DEFUN([AC_NETATALK_ZEROCONF], [
        ZEROCONF_LIBS=""
        ZEROCONF_CFLAGS=""
        found_zeroconf=no
index d98062fb471b84aa39d7365a27fbdeb924b055a7..adca7de8a56d0cc9b27832b0b1f37fa9623b167e 100644 (file)
@@ -1,3 +1,3 @@
 # Makefile.am for man/
 
-SUBDIRS = man1 man3 man4 man5 man8
+SUBDIRS = man1 man5 man8
index 36c6810abb59cca20565cc8ab1d97a75e1ed9ed9..52564afb6b3916de3408767103322e32e2a10ca5 100644 (file)
@@ -14,32 +14,12 @@ SUFFIXES= .tmpl .
 
 GENERATED_MANS = uniconv.1 asip-status.pl.1 afpldaptest.1
 TEMPLATE_FILES = uniconv.1.tmpl asip-status.pl.1.tmpl afpldaptest.1.tmpl
+
 NONGENERATED_MANS      =       ad.1 \
                                afppasswd.1 \
                                apple_dump.1 \
                                dbd.1 \
-                               hqx2bin.1 \
-                               macbinary.1 \
-                               macusers.1 \
-                               megatron.1 \
-                               netatalk-config.1 \
-                               single2bin.1 \
-                               unbin.1 \
-                               unhex.1 \
-                               unsingle.1
-ATALK_MANS = aecho.1 \
-                               getzones.1 \
-                               nbp.1 \
-                               nbplkup.1 \
-                               nbprgstr.1 \
-                               nbpunrgstr.1 \
-                               pap.1 \
-                               papstatus.1 \
-                               psorder.1
-
-if USE_APPLETALK
-NONGENERATED_MANS += $(ATALK_MANS)
-endif
+                               netatalk-config.1
 
 man_MANS = $(GENERATED_MANS) $(NONGENERATED_MANS)
 CLEANFILES = $(GENERATED_MANS)
diff --git a/man/man1/aecho.1 b/man/man1/aecho.1
deleted file mode 100644 (file)
index 3dfad5f..0000000
+++ /dev/null
@@ -1,90 +0,0 @@
-'\" t
-.\"     Title: aecho
-.\"    Author: [FIXME: author] [see http://docbook.sf.net/el/author]
-.\" Generator: DocBook XSL Stylesheets v1.75.2 <http://docbook.sf.net/>
-.\"      Date: 17 Dec 1991
-.\"    Manual: Netatalk 2.2
-.\"    Source: Netatalk 2.2
-.\"  Language: English
-.\"
-.TH "AECHO" "1" "17 Dec 1991" "Netatalk 2.2" "Netatalk 2.2"
-.\" -----------------------------------------------------------------
-.\" * set default formatting
-.\" -----------------------------------------------------------------
-.\" disable hyphenation
-.nh
-.\" disable justification (adjust text to left margin only)
-.ad l
-.\" -----------------------------------------------------------------
-.\" * MAIN CONTENT STARTS HERE *
-.\" -----------------------------------------------------------------
-.SH "NAME"
-aecho \- send AppleTalk Echo Protocol packets to network hosts
-.SH "SYNOPSIS"
-.PP
-\fBaecho\fR\fB\fR\fB\fR
-[
-\fB\-c\fR\fI count\fR
-] (
-\fBaddress\fR
-|
-\fBnbpname\fR
-)
-.SH "DESCRIPTION"
-.PP
-\fBaecho\fR
-repeatedly sends an Apple Echo Protocol (AEP) packet to the host specified by the given AppleTalk
-\fBaddress\fR
-or
-\fBnbpname\fR
-and reports whether a reply was received\&. Requests are sent at the rate of one per second\&.
-.PP
-\fBaddress\fR
-is parsed by
-\fBatalk_aton\fR(3)\&.
-\fBnbpname\fR
-is parsed by
-\fBnbp_name\fR(3)\&. The nbp type defaults to `\fBWorkstation\fR\'\&.
-.PP
-When
-\fBaecho\fR
-is terminated, it reports the number of packets sent, the number of responses received, and the percentage of packets lost\&. If any responses were received, the minimum, average, and maximum round trip times are reported\&.
-.SH "EXAMPLE"
-.PP
-Check to see if a particular host is up and responding to AEP packets:
-.sp
-.if n \{\
-.RS 4
-.\}
-.nf
-example% \fBaecho bloodsport
-\fR\fB11 bytes from 8195\&.13: aep_seq=0\&. time=10\&. ms
-11 bytes from 8195\&.13: aep_seq=1\&. time=10\&. ms
-11 bytes from 8195\&.13: aep_seq=2\&. time=10\&. ms
-11 bytes from 8195\&.13: aep_seq=3\&. time=10\&. ms
-11 bytes from 8195\&.13: aep_seq=4\&. time=10\&. ms
-11 bytes from 8195\&.13: aep_seq=5\&. time=9\&. ms\fR\fB
-\fR\fB\fB^C\fR\fR\fB
-\fR\fB\-\-\-\-8195\&.13 AEP Statistics\-\-\-\-
-6 packets sent, 6 packets received, 0% packet loss
-round\-trip (ms)  min/avg/max = 9/9/10
-\fR
-.fi
-.if n \{\
-.RE
-.\}
-.SH "OPTIONS"
-.PP
-\fB\-c\fR\fI count\fR
-.RS 4
-Stop after
-\fIcount\fR
-packets\&.
-.RE
-.SH "SEE ALSO"
-.PP
-\fBping\fR(1),
-\fBatalk_aton\fR(3),
-\fBnbp_name\fR(3),
-\fBaep\fR(4),
-\fBatalkd\fR(8)\&.
diff --git a/man/man1/getzones.1 b/man/man1/getzones.1
deleted file mode 100644 (file)
index 861ca78..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-'\" t
-.\"     Title: getzones
-.\"    Author: [FIXME: author] [see http://docbook.sf.net/el/author]
-.\" Generator: DocBook XSL Stylesheets v1.75.2 <http://docbook.sf.net/>
-.\"      Date: 17 Dec 1991
-.\"    Manual: Netatalk 2.2
-.\"    Source: Netatalk 2.2
-.\"  Language: English
-.\"
-.TH "GETZONES" "1" "17 Dec 1991" "Netatalk 2.2" "Netatalk 2.2"
-.\" -----------------------------------------------------------------
-.\" * set default formatting
-.\" -----------------------------------------------------------------
-.\" disable hyphenation
-.nh
-.\" disable justification (adjust text to left margin only)
-.ad l
-.\" -----------------------------------------------------------------
-.\" * MAIN CONTENT STARTS HERE *
-.\" -----------------------------------------------------------------
-.SH "NAME"
-getzones \- list AppleTalk zone names
-.SH "SYNOPSIS"
-.HP \w'\fBgetzones\fR\fB\fR\ 'u
-\fBgetzones\fR\fB\fR [\-m | \-l] [\fIaddress\fR]
-.SH "DESCRIPTION"
-.PP
-\fBGetzones\fR
-is used to obtain a list of AppleTalk zone names using the Zone Information Protocol (ZIP)\&. It sends a GetZoneList request to an AppleTalk router\&. By default, it sends the request to the locally running
-\fBatalkd\fR(8)\&.
-.SH "OPTIONS"
-.PP
-\fB\-m\fR
-.RS 4
-List the name of the local zone only; this is accomplished by sending a ZIP GetMyZone request\&.
-.RE
-.PP
-\fB\-l\fR
-.RS 4
-List the local zones; this is accomplished by sending a GetLocalZones request\&.
-.RE
-.PP
-\fIaddress\fR
-.RS 4
-Contact the AppleTalk router at
-\fIaddress\&.\fR
-\fIaddress\fR
-is parsed by
-\fBatalk_aton\fR(3)\&.
-.RE
-.SH "SEE ALSO"
-.PP
-\fBatalk_aton\fR(3),
-\fBatalkd\fR(8)\&.
diff --git a/man/man1/nbp.1 b/man/man1/nbp.1
deleted file mode 100644 (file)
index 0958b99..0000000
+++ /dev/null
@@ -1,104 +0,0 @@
-'\" t
-.\"     Title: nbp
-.\"    Author: [FIXME: author] [see http://docbook.sf.net/el/author]
-.\" Generator: DocBook XSL Stylesheets v1.75.2 <http://docbook.sf.net/>
-.\"      Date: 24 June 2004
-.\"    Manual: Netatalk 2.2
-.\"    Source: Netatalk 2.2
-.\"  Language: English
-.\"
-.TH "NBP" "1" "24 June 2004" "Netatalk 2.2" "Netatalk 2.2"
-.\" -----------------------------------------------------------------
-.\" * set default formatting
-.\" -----------------------------------------------------------------
-.\" disable hyphenation
-.nh
-.\" disable justification (adjust text to left margin only)
-.ad l
-.\" -----------------------------------------------------------------
-.\" * MAIN CONTENT STARTS HERE *
-.\" -----------------------------------------------------------------
-.SH "NAME"
-nbp, nbplkup, nbprgstr, nbpunrgstr \- access NBP database
-.SH "SYNOPSIS"
-.HP \w'\fBnbplkup\fR\fB\fR\fB\fR\fB\ \fR\ 'u
-\fBnbplkup\fR\fB\fR\fB\fR\fB \fR [\-r\ \fImaxresponses\fR] [\-A\ \fIaddress\fR] [\-m\ \fImaccodepage\fR] \fInbpname\fR
-.HP \w'\fBnbprgstr\fR\fB\fR\fB\ \fR\ 'u
-\fBnbprgstr\fR\fB\fR\fB \fR [\-A\ \fIaddress\fR] [\-p\ \fIport\fR] [\-m\ \fImaccodepage\fR] \fInbpname\fR
-.HP \w'\fBnbpunrgstr\fR\fB\fR\fB\ \fR\ 'u
-\fBnbpunrgstr\fR\fB\fR\fB \fR [\-A\ \fIaddress\fR] [\-m\ \fImaccodepage\fR] \fInbpname\fR
-.SH "DESCRIPTION"
-.PP
-\fBnbprgstr\fR
-registers
-\fInbpname\fR
-with
-\fBatalkd\fR(8), at the given
-\fIport\fR\&.
-\fBnbpunrgstr\fR
-informs
-\fBatalkd\fR
-that
-\fInbpname\fR
-is no longer to be advertised\&.
-.PP
-\fBnbplkup\fR
-displays up to
-\fImaxresponses\fR
-(default 1000) entities registered on the AppleTalk internet\&.
-\fI\fInbpname\fR\fR
-is parsed by
-\fBnbp_name\fR(3)\&. An `\fB=\fR\' for the
-\fIobject\fR
-or
-\fItype\fR
-matches anything, and an `\fB*\fR\' for
-\fIzone\fR
-means the local zone\&. The default values are taken from the
-\fBNBPLKUP\fR
-environment variable, parsed as an
-\fInbpname\fR\&.
-.SH "ENVIRONMENT VARIABLES"
-.PP
-NBPLKUP
-.RS 4
-default nbpname for nbplkup
-.RE
-.PP
-ATALK_MAC_CHARSET
-.RS 4
-the codepage used by the clients on the Appletalk network
-.RE
-.PP
-ATALK_UNIX_CHARSET
-.RS 4
-the codepage used to display extended characters on this shell\&.
-.RE
-.SH "EXAMPLE"
-.PP
-Find all devices of type
-\fBLaserWriter\fR
-in the local zone\&.
-.sp
-.if n \{\
-.RS 4
-.\}
-.nf
-example% \fBnbplkup :LaserWriter\fR
-               Petoskey:LaserWriter        7942\&.129:218
-             Gloucester:LaserWriter        8200\&.188:186
-                 Rahway:LaserWriter        7942\&.2:138
-             517 Center:LaserWriter        7942\&.2:132
-                  ionia:LaserWriter        7942\&.2:136
-     Evil DEC from Hell:LaserWriter        7942\&.2:130
-              Hamtramck:LaserWriter        7942\&.2:134
-         Iron Mountain :LaserWriter        7942\&.128:250
-example%
-.fi
-.if n \{\
-.RE
-.\}
-.SH "SEE ALSO"
-.PP
-\fBnbp_name\fR(3),
-\fBatalkd\fR(8)\&.
diff --git a/man/man1/nbplkup.1 b/man/man1/nbplkup.1
deleted file mode 100644 (file)
index ac41808..0000000
+++ /dev/null
@@ -1 +0,0 @@
-.so man1/nbp.1
diff --git a/man/man1/nbprgstr.1 b/man/man1/nbprgstr.1
deleted file mode 100644 (file)
index ac41808..0000000
+++ /dev/null
@@ -1 +0,0 @@
-.so man1/nbp.1
diff --git a/man/man1/nbpunrgstr.1 b/man/man1/nbpunrgstr.1
deleted file mode 100644 (file)
index ac41808..0000000
+++ /dev/null
@@ -1 +0,0 @@
-.so man1/nbp.1
diff --git a/man/man1/pap.1 b/man/man1/pap.1
deleted file mode 100644 (file)
index bc33328..0000000
+++ /dev/null
@@ -1,150 +0,0 @@
-'\" t
-.\"     Title: pap
-.\"    Author: [FIXME: author] [see http://docbook.sf.net/el/author]
-.\" Generator: DocBook XSL Stylesheets v1.75.2 <http://docbook.sf.net/>
-.\"      Date: 6 May 2002
-.\"    Manual: Netatalk 2.2
-.\"    Source: Netatalk 2.2
-.\"  Language: English
-.\"
-.TH "PAP" "1" "6 May 2002" "Netatalk 2.2" "Netatalk 2.2"
-.\" -----------------------------------------------------------------
-.\" * set default formatting
-.\" -----------------------------------------------------------------
-.\" disable hyphenation
-.nh
-.\" disable justification (adjust text to left margin only)
-.ad l
-.\" -----------------------------------------------------------------
-.\" * MAIN CONTENT STARTS HERE *
-.\" -----------------------------------------------------------------
-.SH "NAME"
-pap \- client interface to remote printers using Printer Access Protocol
-.SH "SYNOPSIS"
-.HP \w'\fBpap\fR\fB\fR\ 'u
-\fBpap\fR\fB\fR [\-A\ \fIaddress\fR] [\-c] [\-d] [\-e] [\-E] [\-p\ \fInbpname\fR] [\-s\ \fIstatusfile\fR] [\-w] [\-W] [\fIFILES\fR]
-.SH "DESCRIPTION"
-.PP
-\fBpap\fR
-is used to connect and send files to an AppleTalk connected printer using the Apple Printer Access Protocol (PAP)\&. When
-\fBpap\fR
-starts execution, it tries to open a session with the printer using PAP, and then downloads the
-\fIfiles\fR
-to the printer\&.
-.PP
-If no
-\fIfiles\fR
-are given on the command line,
-\fBpap\fR
-begins reading from standard input\&.
-.PP
-If no printer is specified on the command line,
-\fBpap\fR
-looks for a file called
-\fB\&.paprc\fR
-in the current working directory and reads it to obtain the
-\fInbpname\fR
-of a printer\&. Blank lines and lines that begin with a `\fB#\fR\' are ignored\&.
-\fItype\fR
-and
-\fIzone\fR
-default to
-\fBLaserWriter\fR
-and the zone of the local host, respectively\&.
-.PP
-Note that
-\fBpap\fR
-is designed to be useful as a communication filter for sending
-\fBlpd\fR(8)
-spooled print jobs to AppleTalk connected printers\&. See
-\fBpsf\fR(8)
-for hints on how to use it this way\&.
-.SH "OPTIONS"
-.PP
-\fB\-A \fR\fIaddress\fR
-.RS 4
-Connect to the printer with Appletalk address
-\fIaddress\fR
-and do not consult the
-\fB\&.paprc\fR
-file to find a printer name\&. See
-\fBatalk_aton\fR(3)
-for the syntax of
-\fIaddress\fR\&.
-.RE
-.PP
-\fB\-c\fR
-.RS 4
-Take cuts\&. The PAP protocol specified a simple queuing procedure, such that the clients tell the printer how long they have been waiting to print\&. This option causes
-\fBpap\fR
-to lie about how long it has been waiting\&.
-.RE
-.PP
-\fB\-d\fR
-.RS 4
-Enable debug output\&.
-.RE
-.PP
-\fB\-e\fR
-.RS 4
-Send any message from the printer to stderr instead of stdout\&.
-\fBpsf\fR(8)
-invokes
-\fBpap\fR
-with this option\&.
-.RE
-.PP
-\fB\-E\fR
-.RS 4
-Don\'t wait for EOF from the printer\&. This option is useful for printers which don\'t implement PAP correctly\&. In a correct implementation, the client side should wait for the printer to return EOF before closing the connection\&. Some clients don\'t wait, and hence some printers have related bugs in their implementation\&.
-.RE
-.PP
-\fB\-p\fR \fInbpname\fR
-.RS 4
-Connect to the printer named
-\fInbpname\fR
-and do not consult the
-\fB\&.paprc\fR
-file to find a printer name\&. See
-\fBnbp_name\fR(3)
-for the syntax of
-\fInbpname\fR\&.
-.RE
-.PP
-\fB\-s\fR \fIstatusfile\fR
-.RS 4
-Update the file called
-\fIstatusfile\fR
-to contain the most recent status message from the printer\&.
-\fBpap\fR
-gets the status from the printer when it is waiting for the printer to process input\&. The
-\fIstatusfile\fR
-will contain a single line terminated with a newline\&. This is useful when
-\fBpap\fR
-is invoked by
-\fBpsf\fR(8)
-within
-\fBlpd\fR\'s spool directory\&.
-.RE
-.PP
-\fB\-w\fR
-.RS 4
-Wait for the printer status to contain the word "waiting" before sending the job\&. This is to defeat printer\-side spool available on HP IV and V printers\&.
-.RE
-.PP
-\fB\-W\fR
-.RS 4
-Wait for the printer status to contain the word "idle" before sending the job\&. This is to defeat printer\-side spool available on HP IV and V printers\&.
-.RE
-.SH "FILES"
-.PP
-\fB\&.paprc\fR
-.RS 4
-file read to obtain printer name if not specified on command line
-.RE
-.SH "SEE ALSO"
-.PP
-\fBnbp_name\fR(3),
-\fBatalk_aton\fR(3),
-\fBlpd\fR(8),
-\fBpsf\fR(8)\&.
diff --git a/man/man1/papstatus.1 b/man/man1/papstatus.1
deleted file mode 100644 (file)
index 631797d..0000000
+++ /dev/null
@@ -1 +0,0 @@
-.so man1/pap.1
diff --git a/man/man1/psorder.1 b/man/man1/psorder.1
deleted file mode 100644 (file)
index 724fe55..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-'\" t
-.\"     Title: psorder
-.\"    Author: [FIXME: author] [see http://docbook.sf.net/el/author]
-.\" Generator: DocBook XSL Stylesheets v1.75.2 <http://docbook.sf.net/>
-.\"      Date: 17 Dec 1991
-.\"    Manual: Netatalk 2.2
-.\"    Source: Netatalk 2.2
-.\"  Language: English
-.\"
-.TH "PSORDER" "1" "17 Dec 1991" "Netatalk 2.2" "Netatalk 2.2"
-.\" -----------------------------------------------------------------
-.\" * set default formatting
-.\" -----------------------------------------------------------------
-.\" disable hyphenation
-.nh
-.\" disable justification (adjust text to left margin only)
-.ad l
-.\" -----------------------------------------------------------------
-.\" * MAIN CONTENT STARTS HERE *
-.\" -----------------------------------------------------------------
-.SH "NAME"
-psorder \- PostScript pageorder filter
-.SH "SYNOPSIS"
-.HP \w'\fBpsorder\fR\fB\fR\ 'u
-\fBpsorder\fR\fB\fR [\-duf] \fIsourcefile\fR
-.SH "DESCRIPTION"
-.PP
-\fBpsorder\fR
-is a filter that re\-orders the pages of a PostScript document\&. The result is written to the standard output\&. By default, documents are processed into ascending order (the lowest numbered page is printed first)\&. Some PostScript documents specify that the order of their pages should never be changed; the default action of
-\fBpsorder\fR
-is to follow this specification\&.
-.PP
-If no source file is given, or if
-\fIsourcefile\fR
-is `\fB\-\fR\',
-\fBpsorder\fR
-reads from the standard input file\&.
-.SH "OPTIONS"
-.PP
-\fB\-d\fR
-.RS 4
-Re\-order the pages of the document in downward or descending order\&. This is typically used to change the order of a document to be printed by a printer that stacks pages face\-up, such as an Apple LaserWriter or LaserWriter Plus\&.
-.RE
-.PP
-\fB\-u\fR
-.RS 4
-Specifies forward order, and is the default\&. It is used to try and ensure the correct ordering when a document will be printed by a printer that stacks the pages face\-down\&.
-.RE
-.PP
-\fB\-f\fR
-.RS 4
-Force
-\fBpsorder\fR
-to re\-order the pages, even if the document claims that its page order is not to be trifled with\&. This option should only be used experimentally, as it may cause documents to print incorrectly\&.
-.RE
-.SH "SEE ALSO"
-.PP
-\fBpsf\fR(8),
-\fBlpr\fR(1)\&.
diff --git a/man/man3/.gitignore b/man/man3/.gitignore
deleted file mode 100644 (file)
index 895a5e7..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-Makefile
-Makefile.in
-.gitignore
-*.o
diff --git a/man/man3/Makefile.am b/man/man3/Makefile.am
deleted file mode 100644 (file)
index 198f977..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-# Makefile.am for man/man3
-
-ATALK_MANS = atalk_aton.3 nbp_name.3
-
-if USE_APPLETALK
-man_MANS = $(ATALK_MANS)
-endif
-
-EXTRA_DIST = $(ATALK_MANS)
diff --git a/man/man3/atalk_aton.3 b/man/man3/atalk_aton.3
deleted file mode 100644 (file)
index d4f5d94..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-'\" t
-.\"     Title: atalk_aton
-.\"    Author: [FIXME: author] [see http://docbook.sf.net/el/author]
-.\" Generator: DocBook XSL Stylesheets v1.75.2 <http://docbook.sf.net/>
-.\"      Date: 12 Jan 1994
-.\"    Manual: Netatalk 2.2
-.\"    Source: Netatalk 2.2
-.\"  Language: English
-.\"
-.TH "ATALK_ATON" "3" "12 Jan 1994" "Netatalk 2.2" "Netatalk 2.2"
-.\" -----------------------------------------------------------------
-.\" * set default formatting
-.\" -----------------------------------------------------------------
-.\" disable hyphenation
-.nh
-.\" disable justification (adjust text to left margin only)
-.ad l
-.\" -----------------------------------------------------------------
-.\" * MAIN CONTENT STARTS HERE *
-.\" -----------------------------------------------------------------
-.SH "NAME"
-atalk_aton \- AppleTalk address parsing
-.SH "SYNOPSIS"
-.sp
-.ft B
-.nf
-#include <sys/types\&.h>
-#include <netatalk/at\&.h>
-.fi
-.ft
-.HP \w'atalk_aton('u
-.BI "atalk_aton(char\ *\ " "cp" ", struct\ at_addr\ *\ " "ata" ");"
-.SH "DESCRIPTION"
-.PP
-The
-\fBatalk_aton()\fR
-routine converts an ASCII representation of an AppleTalk address to a format appropriate for system calls\&. Acceptable ASCII representations include both hex and base 10, in triples or doubles\&. For instance, the address `0x1f6b\&.77\' has a network part of `8043\' and a node part of `119\'\&. This same address could be written `8043\&.119\', `31\&.107\&.119\', or `0x1f\&.6b\&.77\'\&. If the address is in hex and the first digit is one of `A\-F\', a leading `0x\' is redundant\&.
-.SH "SEE ALSO"
-.PP
-\fBatalk\fR(4)\&.
diff --git a/man/man3/nbp_name.3 b/man/man3/nbp_name.3
deleted file mode 100644 (file)
index 6791f4a..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-'\" t
-.\"     Title: nbp_name
-.\"    Author: [FIXME: author] [see http://docbook.sf.net/el/author]
-.\" Generator: DocBook XSL Stylesheets v1.75.2 <http://docbook.sf.net/>
-.\"      Date: 12 Jan 1994
-.\"    Manual: Netatalk 2.2
-.\"    Source: Netatalk 2.2
-.\"  Language: English
-.\"
-.TH "NBP_NAME" "3" "12 Jan 1994" "Netatalk 2.2" "Netatalk 2.2"
-.\" -----------------------------------------------------------------
-.\" * set default formatting
-.\" -----------------------------------------------------------------
-.\" disable hyphenation
-.nh
-.\" disable justification (adjust text to left margin only)
-.ad l
-.\" -----------------------------------------------------------------
-.\" * MAIN CONTENT STARTS HERE *
-.\" -----------------------------------------------------------------
-.SH "NAME"
-nbp_name \- NBP name parsing
-.SH "SYNOPSIS"
-.HP \w'int\ nbp_name('u
-.BI "int nbp_name(char\ *" "name" ", char\ **" "obj" ", char\ **" "type" ", char\ **" "zone" ");"
-.SH "DESCRIPTION"
-.PP
-\fBnbp_name()\fR
-parses user supplied names into their component object, type, and zone\&.
-\fBobj\fR,
-\fBtype\fR, and
-\fIzone\fR
-should be passed by reference, and should point to the caller\'s default values\&.
-\fBnbp_name()\fR
-will change the pointers to the parsed\-out values\&.
-\fBname\fR
-is of the form
-\fIobject\fR\fB:\fR\fItype\fR\fB@\fR\fIzone\fR, where each of
-\fIobject\fR,
-\fB:\fR\fItype\fR\fB,\fR
-and
-\fB@\fR\fIzone\fR
-replace
-\fBobj\fR,
-\fBtype\fR, and
-\fBzone,\fR
-respectively\&.
-\fItype\fR
-must be proceeded by `\fB:\fR\', and
-\fIzone\fR
-must be preceded by `\fB@\fR\'\&.
-.SH "EXAMPLE"
-.PP
-The argument of
-\fBafpd\fR(8)\'s
-\fB\-n\fR
-option is parsed with
-\fBnbp_name()\fR\&. The default value of
-\fBobj\fR
-is the first component of the machine\'s hostname (as returned by
-\fBgethostbyname\fR(3))\&. The default value of
-\fBtype\fR
-is ``AFPServer\'\', and of
-\fIzone\fR
-is ``*\'\', the default zone\&. To cause
-\fBafpd\fR
-to register itself in some zone other than the default, one would invoke it as
-.sp
-.if n \{\
-.RS 4
-.\}
-.nf
-afpd \-n @some\-other\-zone
-.fi
-.if n \{\
-.RE
-.\}
-.PP
-\fBobj\fR
-and
-\fBtype\fR
-would retain their default values\&.
-.SH "BUGS"
-.PP
-\fBobj\fR,
-\fBtype\fR, and
-\fIzone\fR
-return pointers into static area which may be over\-written on each call\&.
diff --git a/man/man4/.gitignore b/man/man4/.gitignore
deleted file mode 100644 (file)
index 895a5e7..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-Makefile
-Makefile.in
-.gitignore
-*.o
diff --git a/man/man4/Makefile.am b/man/man4/Makefile.am
deleted file mode 100644 (file)
index d0295d4..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-# Makefile.am for man/man4/
-
-ATALK_MANS = atalk.4
-
-if USE_APPLETALK
-man_MANS = $(ATALK_MANS)
-endif
-
-EXTRA_DIST = $(ATALK_MANS)
diff --git a/man/man4/atalk.4 b/man/man4/atalk.4
deleted file mode 100644 (file)
index 356b93e..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-'\" t
-.\"     Title: atalk
-.\"    Author: [FIXME: author] [see http://docbook.sf.net/el/author]
-.\" Generator: DocBook XSL Stylesheets v1.75.2 <http://docbook.sf.net/>
-.\"      Date: 17 Dec 1991
-.\"    Manual: Netatalk 2.2
-.\"    Source: Netatalk 2.2
-.\"  Language: English
-.\"
-.TH "ATALK" "4" "17 Dec 1991" "Netatalk 2.2" "Netatalk 2.2"
-.\" -----------------------------------------------------------------
-.\" * set default formatting
-.\" -----------------------------------------------------------------
-.\" disable hyphenation
-.nh
-.\" disable justification (adjust text to left margin only)
-.ad l
-.\" -----------------------------------------------------------------
-.\" * MAIN CONTENT STARTS HERE *
-.\" -----------------------------------------------------------------
-.SH "NAME"
-atalk \- AppleTalk protocol family
-.SH "SYNOPSIS"
-.sp
-.ft B
-.nf
-#include <sys/types\&.h>
-#include <netatalk/at\&.h>
-.fi
-.ft
-.SH "DESCRIPTION"
-.PP
-The AppleTalk protocol family is a collection of protocols layered above the Datagram Delivery Protocol (DDP), and using AppleTalk address format\&. The AppleTalk family may provide SOCK_STREAM (ADSP), SOCK_DGRAM (DDP), SOCK_RDM (ATP), and SOCK_SEQPACKET (ASP)\&. Currently, only DDP is implemented in the kernel; ATP and ASP are implemented in user level libraries; and ADSP is planned\&.
-.SH "ADDRESSING"
-.PP
-AppleTalk addresses are three byte quantities, stored in network byte order\&. The include file <\fBnetatalk/at\&.h\fR> defines the AppleTalk address format\&.
-.PP
-Sockets in the AppleTalk protocol family use the following address structure:
-.sp
-.if n \{\
-.RS 4
-.\}
-.nf
-struct sockaddr_at {
-    short sat_family;
-    u_char sat_port;
-    struct at_addr sat_addr;
-    char sat_zero[ 8 ];
-};
-.fi
-.if n \{\
-.RE
-.\}
-.PP
-The port of a socket may be set with
-\fBbind\fR(2)\&. The node for
-\fBbind\fR
-must always be
-\fBATADDR_ANYNODE\fR: ``this node\&.\'\' The net may be
-\fBATADDR_ANYNET\fR
-or
-\fBATADDR_LATENET\fR\&.
-\fBATADDR_ANYNET\fR
-coresponds to the machine\'s ``primary\'\' address (the first configured)\&.
-\fBATADDR_LATENET\fR
-causes the address in outgoing packets to be determined when a packet is sent, i\&.e\&. determined late\&.
-\fBATADDR_LATENET\fR
-is equivalent to opening one socket for each network interface\&. The port of a socket and either the primary address or
-\fBATADDR_LATENET\fR
-are returned with
-\fBgetsockname\fR(2)\&.
-.SH "SEE ALSO"
-.PP
-\fBbind\fR(2),
-\fBgetsockname\fR(2),
-\fBatalkd\fR(8)\&.
index a382039eeae6ebfa7475aba6bb89d57ab5039139..2f7ec5b6cc091822761943fd771a8a71d2714f61 100644 (file)
@@ -27,17 +27,10 @@ TEMPLATE_FILES = AppleVolumes.default.5.tmpl \
        afp_signature.conf.5.tmpl \
        afp_voluuid.conf.5.tmpl
 
-ATALK_MANS = atalkd.conf.5.tmpl papd.conf.5.tmpl
-
-if USE_APPLETALK
-GENERATED_MANS += atalkd.conf.5 papd.conf.5
-TEMPLATE_FILES += $(ATALK_MANS)
-endif
-
 NONGENERATED_MANS = AppleVolumes.5 AppleVolumes.system.5
 
 man_MANS = $(GENERATED_MANS) $(NONGENERATED_MANS)
 
 CLEANFILES = $(GENERATED_MANS)
 
-EXTRA_DIST = $(TEMPLATE_FILES) $(NONGENERATED_MANS) $(ATALK_MANS)
+EXTRA_DIST = $(TEMPLATE_FILES) $(NONGENERATED_MANS)
diff --git a/man/man5/atalkd.conf.5.tmpl b/man/man5/atalkd.conf.5.tmpl
deleted file mode 100644 (file)
index ed51c8c..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-'\" t
-.\"     Title: atalkd.conf
-.\"    Author: [FIXME: author] [see http://docbook.sf.net/el/author]
-.\" Generator: DocBook XSL Stylesheets v1.75.2 <http://docbook.sf.net/>
-.\"      Date: 22 September 2000
-.\"    Manual: Netatalk 2.2
-.\"    Source: Netatalk 2.2
-.\"  Language: English
-.\"
-.TH "ATALKD\&.CONF" "5" "22 September 2000" "Netatalk 2.2" "Netatalk 2.2"
-.\" -----------------------------------------------------------------
-.\" * set default formatting
-.\" -----------------------------------------------------------------
-.\" disable hyphenation
-.nh
-.\" disable justification (adjust text to left margin only)
-.ad l
-.\" -----------------------------------------------------------------
-.\" * MAIN CONTENT STARTS HERE *
-.\" -----------------------------------------------------------------
-.SH "NAME"
-atalkd.conf \- Configuration file used by atalkd(8) to determine the interfaces used by the master Netatalk daemon
-.SH "DESCRIPTION"
-.PP
-\fB:ETCDIR:/atalkd\&.conf\fR
-is the configuration file used by atalkd to configure the Appletalk interfaces and their behavior
-.PP
-Any line not prefixed with
-\fB#\fR
-is interpreted\&. The configuration lines are composed like:
-.PP
-\fIInterface\fR
-\fB[\fR
-\fIoptions\fR
-\fB]\fR
-.PP
-The simplest case is to have either no atalkd\&.conf, or to have one that has no active lines\&. In this case, atalkd should auto\-discover the local interfaces on the machine\&. Please note that you cannot split lines\&.
-.PP
-The interface is the network interface that this to work over, such as
-\fBeth0\fR
-for Linux, or
-\fBle0\fR
-for Sun\&.
-.PP
-The possible options and their meanings are:
-.PP
-\fB\-addr \fR\fB\fInet\&.node\fR\fR
-.RS 4
-Allows specification of the net and node numbers for this interface, specified in Appletalk numbering format (example:
-\fB\-addr 66\&.6\fR)\&.
-.RE
-.PP
-\fB\-dontroute\fR
-.RS 4
-Disables Appletalk routing\&. It is the opposite of
-\fB\-router\fR\&.
-.RE
-.PP
-\fB\-net first[\-last]\fR
-.RS 4
-Allows the available net to be set, optionally as a range\&.
-.RE
-.PP
-\fB\-noallmulti\fR (linux only)
-.RS 4
-On linux the interfaces, atalkd uses, are set to ALLMULTI by default caused by countless NICs having problems without being forced into this mode (some even don\'t work with allmulti set)\&. In case, you\'ve a NIC known to support multicasts properly, you might want to set this option causing less packets to be processed
-.RE
-.PP
-\fB\-phase ( 1 | 2 )\fR
-.RS 4
-Specifies the Appletalk phase that this interface is to use (either Phase 1 or Phase 2)\&.
-.RE
-.PP
-\fB\-router\fR
-.RS 4
-Like
-\fB\-seed\fR, but allows single interface routing\&. It is the opposite of
-\fB\-dontroute\fR\&.
-.RE
-.PP
-\fB\-seed\fR
-.RS 4
-The seed option only works if you have multiple interfaces\&. It also causes all missing arguments to be automagically configured from the network\&.
-.RE
-.PP
-\fB\-zone \fR\fB\fIzonename\fR\fR
-.RS 4
-Specifies a specific zone that this interface should appear on (example:
-\fB\-zone "Parking Lot"\fR)\&. Please note that zones with spaces and other special characters should be enclosed in parentheses\&.
-.RE
-.SH "SEE ALSO"
-.PP
-\fBatalkd\fR(8)
diff --git a/man/man5/papd.conf.5.tmpl b/man/man5/papd.conf.5.tmpl
deleted file mode 100644 (file)
index caf5f60..0000000
+++ /dev/null
@@ -1,209 +0,0 @@
-'\" t
-.\"     Title: papd.conf
-.\"    Author: [FIXME: author] [see http://docbook.sf.net/el/author]
-.\" Generator: DocBook XSL Stylesheets v1.75.2 <http://docbook.sf.net/>
-.\"      Date: 06 Sep 2004
-.\"    Manual: Netatalk 2.2
-.\"    Source: Netatalk 2.2
-.\"  Language: English
-.\"
-.TH "PAPD\&.CONF" "5" "06 Sep 2004" "Netatalk 2.2" "Netatalk 2.2"
-.\" -----------------------------------------------------------------
-.\" * set default formatting
-.\" -----------------------------------------------------------------
-.\" disable hyphenation
-.nh
-.\" disable justification (adjust text to left margin only)
-.ad l
-.\" -----------------------------------------------------------------
-.\" * MAIN CONTENT STARTS HERE *
-.\" -----------------------------------------------------------------
-.SH "NAME"
-papd.conf \- Configuration file used by papd(8) to determine the configuration of printers used by the Netatalk printing daemon
-.SH "DESCRIPTION"
-.PP
-\fB:ETCDIR:/papd\&.conf\fR
-is the configuration file used by papd to configure the printing services offered by netatalk\&. Please note that papd must be enabled in
-\fB:ETCDIR:/netatalk\&.conf\fR
-for this to take any effect\&.
-\fBpapd\fR
-shares the same defaults as lpd on many systems, but not Solaris\&.
-.PP
-Any line not prefixed with
-\fB#\fR
-is interpreted\&. The configuration lines are composed like:
-.PP
-\fIprintername:[options]\fR
-.PP
-On systems running a System V printing system the simplest case is to have either no papd\&.conf, or to have one that has no active lines\&. In this case, atalkd should auto\-discover the local printers on the machine\&. Please note that you can split lines by using
-\fB\e\efR\&.\fR
-.PP
-printername may be just a name (\fBPrinter 1\fR), or it may be a full name in nbp_name format (\fBPrinter 1:LaserWriter@My Zone\fR)\&.
-.PP
-Systems using a BSD printing system should make use of a pipe to the printing command in question within the
-\fBpr\fR
-option (eg\&.
-\fBpr=|/usr/bin/lpr\fR)\&.
-.PP
-When CUPS support is compiled in, then
-\fBcupsautoadd \fR
-as the first entry in papd\&.conf will automagically share all CUPS printers by papd utilizing the PPDs assigned in CUPS (customizable \-\- see below)\&. This can be overwritten for individal printers by subsequently adding individual entries using the CUPS queue name as
-\fBpr \fR
-entry\&. Note: CUPS support is mutually exclusive with System V support described above\&.
-.PP
-The possible options are colon delimited (\fB:\fR), and lines must be terminated with colons\&. The possible options and flags are:
-.PP
-\fBam=(uams list)\fR
-.RS 4
-The
-\fBam\fR
-option allows specific UAMs to be specified for a particular printer\&. It has no effect if the
-\fBau\fR
-flag is not present or if papd authentication was not built into netatalk\&. Note: possible values are
-\fBuams_guest\&.so\fR
-and
-\fB uams_clrtxt\&.so\fR
-only\&. The first method requires a valid username, but no password\&. The second requires both a valid username and the correct password\&.
-.RE
-.PP
-\fBau\fR
-.RS 4
-If present, this flag enables authentication for the printer\&. Please note that papd authentication must be built into netatalk for this to take effect\&.
-.RE
-.PP
-\fBco=(CUPS options)\fR
-.RS 4
-The
-\fBco\fR
-option allows options to be passed through to CUPS (eg\&.
-\fBco="protocol=TBCP" \fR
-or
-\fBco="raw"\fR)\&.
-.RE
-.PP
-\fBcupsautoadd[:type][@zone]\fR
-.RS 4
-If used as the first entry in papd\&.conf this will share all CUPS printers via papd\&. type/zone settings as well as other parameters assigned to this special printer share will apply to all CUPS printers\&. Unless the
-\fBpd\fR
-option is set, the CUPS PPDs will be used\&. To overwrite these global settings for individual printers simply add them subsequently to papd\&.conf and assign different settings\&.
-.RE
-.PP
-\fBfo\fR
-.RS 4
-If present, this flag enables a hack to translate line endings originating from pre Mac OS X LaserWriter drivers to let
-\fBfoomatic\-rip\fR
-recognize foomatic PPD options set in the printer dialog\&. Attention: Use with caution since this might corrupt binary print jobs!
-.RE
-.PP
-\fBop=(operator)\fR
-.RS 4
-This specifies the operator name, for lpd spooling\&.
-.RE
-.PP
-\fBpa=(appletalk address)\fR
-.RS 4
-Allows specification of Appletalk addresses\&. Usually not needed\&.
-.RE
-.PP
-\fBpd=(path to ppd file)\fR
-.RS 4
-Specifies a particular PPD (printer description file) to associate with the selected printer\&.
-.RE
-.PP
-\fBpr=(lpd/CUPS printer name or pipe command)\fR
-.RS 4
-Sets the
-\fBlpd\fR
-or
-\fBCUPS\fR
-printer that this is spooled to\&.
-.RE
-.SH "EXAMPLES"
-.PP
-Unless CUPS support has been compiled in (which is default from Netatalk 2\&.0 on) one simply defines the lpd queue in question by setting the
-\fBpr\fR
-parameter to the queue name, in the following example "ps"\&. If no
-\fBpr\fR
-parameter is set, the default printer will be used\&.
-.PP
-\fBExample.\ \&papd.conf System V printing system examples\fR
-.PP
-The first spooler is known by the AppleTalk name Mac Printer Spooler, and uses a PPD file located in
-/usr/share/lib/ppd\&. In addition, the user mcs will be the owner of all jobs that are spooled\&. The second spooler is known as HP Printer and all options are the default\&.
-.sp
-.if n \{\
-.RS 4
-.\}
-.nf
-Mac Printer Spooler:\e
-   :pr=ps:\e
-   :pd=/usr/share/lib/ppd/HPLJ_4M\&.PPD:\e
-   :op=mcs:
-
-HP Printer:\e
-   :
-.fi
-.if n \{\
-.RE
-.\}
-
-.PP
-An alternative to the technique outlined above is to direct papd\'s output via a pipe into another program\&. Using this mechanism almost all printing systems can be driven\&.
-.PP
-\fBExample.\ \&papd.conf examples using pipes\fR
-.PP
-The first spooler is known as HP 8100\&. It pipes the print job to
-\fB/usr/bin/lpr\fR
-for printing\&. PSSP authenticated printing is enabled, as is CAP\-style authenticated printing\&. Both methods support guest and cleartext authentication as specified by the \'\fBam\fR\' option\&. The PPD used is
-/etc/atalk/ppds/hp8100\&.ppd\&.
-.sp
-.if n \{\
-.RS 4
-.\}
-.nf
-HP 8100:\e
-   :pr=|/usr/bin/lpr \-Plp:\e
-   :sp:\e
-   :ca=/tmp/print:\e
-   :am=uams_guest\&.so,uams_pam\&.so:\e
-   :pd=/etc/atalk/ppds/hp8100\&.ppd:
-      
-.fi
-.if n \{\
-.RE
-.\}
-.sp
-
-.PP
-Starting with Netatalk 2\&.0 direct CUPS integration is available\&. In this case, defining only a queue name as
-\fBpr\fR
-parameter won\'t invoke the SysV lpd daemon but uses CUPS instead\&. Unless a specific PPD has been assigned using the
-\fBpd\fR
-switch, the PPD configured in CUPS will be used by
-\fBpapd\fR, too\&.
-.PP
-There exists one special share named "cupsautoadd"\&. If this is present as the first entry then all available CUPS queues will be served automagically using the parameters assigned to this global share\&. But subsequent printer definitions can be used to override these global settings for individual spoolers\&.
-.PP
-\fBExample.\ \&papd.conf CUPS examples\fR
-.PP
-The first entry sets up automatic sharing of all CUPS printers\&. All those shares appear in the zone "1st floor" and since no additional settings have been made, they use the CUPS printer name as NBP name and use the PPD configured in CUPS\&. The second entry defines different settings for one single CUPS printer\&. It\'s NBP name is differing from the printer\'s name and the registration happens in another zone\&.
-.sp
-.if n \{\
-.RS 4
-.\}
-.nf
-cupsautoadd@1st floor:op=root:
-
-Boss\' LaserWriter@2nd floor:\e
-   :pr=laserwriter\-chief:
-.fi
-.if n \{\
-.RE
-.\}
-
-.SH "SEE ALSO"
-.PP
-\fBpapd\fR(8),
-\fBatalkd.conf\fR(5),
-\fBlpd\fR(8),
-\fBlpoptions\fR(8)
index 26273d4378663bcbdaabe2e167fffd4a085cd202..8749bccedb8a5c17189eb7f77d6f5a17b98e98c2 100644 (file)
@@ -13,18 +13,11 @@ SUFFIXES = .tmpl .
            -e s@:NETATALK_VERSION:@${NETATALK_VERSION}@ \
            <$< >$@
 
-NONGENERATED_MANS = timelord.8
 GENERATED_MANS    = afpd.8 cnid_dbd.8 cnid_metad.8
 TEMPLATE_FILES    = afpd.8.tmpl cnid_dbd.8.tmpl cnid_metad.8.tmpl
-ATALK_MANS        = atalkd.8.tmpl papd.8.tmpl papstatus.8.tmpl psf.8.tmpl
 
-if USE_APPLETALK
-GENERATED_MANS += atalkd.8 papd.8 papstatus.8 psf.8
-TEMPLATE_FILES += $(ATALK_MANS)
-endif
-
-man_MANS = $(GENERATED_MANS) $(NONGENERATED_MANS)
+man_MANS = $(GENERATED_MANS)
 
 CLEANFILES = $(GENERATED_MANS)
 
-EXTRA_DIST = $(TEMPLATE_FILES) $(NONGENERATED_MANS) $(ATALK_MANS)
+EXTRA_DIST = $(TEMPLATE_FILES)
diff --git a/man/man8/atalkd.8.tmpl b/man/man8/atalkd.8.tmpl
deleted file mode 100644 (file)
index 819e388..0000000
+++ /dev/null
@@ -1,109 +0,0 @@
-'\" t
-.\"     Title: atalkd
-.\"    Author: [FIXME: author] [see http://docbook.sf.net/el/author]
-.\" Generator: DocBook XSL Stylesheets v1.75.2 <http://docbook.sf.net/>
-.\"      Date: 06 Sep 2004
-.\"    Manual: Netatalk 2.2
-.\"    Source: Netatalk 2.2
-.\"  Language: English
-.\"
-.TH "ATALKD" "8" "06 Sep 2004" "Netatalk 2.2" "Netatalk 2.2"
-.\" -----------------------------------------------------------------
-.\" * set default formatting
-.\" -----------------------------------------------------------------
-.\" disable hyphenation
-.nh
-.\" disable justification (adjust text to left margin only)
-.ad l
-.\" -----------------------------------------------------------------
-.\" * MAIN CONTENT STARTS HERE *
-.\" -----------------------------------------------------------------
-.SH "NAME"
-atalkd \- AppleTalk RTMP, NBP, ZIP, and AEP manager
-.SH "SYNOPSIS"
-.HP \w'\fBatalkd\fR\fB\fR\fB\fR\fB\fR\fB\fR\fB\fR\fB\fR\ 'u
-\fBatalkd\fR\fB\fR\fB\fR\fB\fR\fB\fR\fB\fR\fB\fR [\-f\ \fIconfigfile\fR] [\-1] [\-2]
-.SH "DESCRIPTION"
-.PP
-\fBatalkd\fR
-is responsible for all user level AppleTalk network management\&. This includes routing, name registration and lookup, zone lookup, and the AppleTalk Echo Protocol (similar to
-\fBping\fR(8))\&.
-\fBatalkd\fR
-is typically started at boot time, out of
-/etc/rc\&. It first reads from its configuration file,
-:ETCDIR:/atalkd\&.conf\&. If there is no configuration file,
-\fBatalkd\fR
-will attempt to configure all available interfaces and will create a configuration file\&. The file consists of a series of interfaces, one per line\&. Lines with `#\' in the first column are ignored, as are blank lines\&. The syntax is
-.PP
-\fIinterface\fR
-[
-\fB\-seed\fR
-] [
-\fB\-phase\fR
-\fInumber\fR
-] [
-\fB\-net\fR
-\fInet\-range\fR
-] [
-\fB\-addr\fR
-\fIaddress\fR
-] [
-\fB\-zone\fR
-\fIzonename\fR
-] \&.\&.\&.
-.PP
-Note that all fields except the interface are optional\&. The loopback interface is configured automatically\&. If
-\fB\-seed\fR
-is specified, all other fields must be present\&. Also,
-\fBatalkd\fR
-will exit during bootstrap\%ping, if a router disagrees with its seed information\&. If
-\fB\-seed\fR
-is not given, all other information may be overriden during auto\-configuration\&. If no
-\fB\-phase\fR
-option is given, the default phase as given on the command line is used (the default is 2)\&. If
-\fB\-addr\fR
-is given and
-\fB\-net\fR
-is not, a net\-range of one is assumed\&.
-.PP
-The first \-zone directive for each interface is the ``default\'\' zone\&. Under Phase 1, there is only one zone\&. Under Phase 2, all routers on the network are configured with the default zone and must agree\&.
-\fBatalkd\fR
-maps ``*\'\' to the default zone of the first interface\&. Note: The default zone for a machine is determined by the configuration of the local routers; to appear in a non\-default zone, each service, e\&.g\&.
-\fBafpd\fR, must individually specify the desired zone\&. See also
-\fBnbp_name\fR(3)\&.
-.SH "ROUTING"
-.PP
-If you are connecting a netatalk router to an existing AppleTalk internet, you should first contact your local network administrators to obtain appropriate network addresses\&.
-.PP
-\fBatalkd\fR
-can provide routing between interfaces by configuring multiple interfaces\&. Each interface must be assigned a unique net\-range
-between 1 and 65279 (0 and 65535 are illegal, and addresses between 65280 and 65534 are reserved for startup)\&. It is best to choose the smallest useful net\-range, i\&.e\&. if you have three machines on an Ethernet, don\'t chose a net\-range of 1000\-2000\&. Each net\-range may have an arbitrary list of zones associated with it\&.
-.SH "EXAMPLES"
-.PP
-Below is an example configuration file for a sun4/40\&. The machine has two interfaces, ``le0\'\' and ``le1\'\'\&. The ``le0\'\' interface is configured automatically from other routers on the network\&. The machine is the only router for the ``le1\'\' interface\&.
-.PP
-.if n \{\
-.RS 4
-.\}
-.nf
-   le0
-   le1 \-seed \-net 9461\-9471 \-zone netatalk \-zone Argus
-.fi
-.if n \{\
-.RE
-.\}
-.sp
-\fBatalkd\fR
-automatically acts as a router if there is more than one interface\&.
-.SH "FILES"
-.PP
-:ETCDIR:/atalkd\&.conf
-configuration file
-.SH "BUGS"
-.PP
-On some systems,
-\fBatalkd\fR
-can not be restarted\&.
-.SH "SEE ALSO"
-.PP
-\fBatalkd.conf\fR(5)
diff --git a/man/man8/papd.8.tmpl b/man/man8/papd.8.tmpl
deleted file mode 100644 (file)
index c48cf80..0000000
+++ /dev/null
@@ -1,276 +0,0 @@
-'\" t
-.\"     Title: papd
-.\"    Author: [FIXME: author] [see http://docbook.sf.net/el/author]
-.\" Generator: DocBook XSL Stylesheets v1.75.2 <http://docbook.sf.net/>
-.\"      Date: 06 September 2004
-.\"    Manual: Netatalk 2.2
-.\"    Source: Netatalk 2.2
-.\"  Language: English
-.\"
-.TH "PAPD" "8" "06 September 2004" "Netatalk 2.2" "Netatalk 2.2"
-.\" -----------------------------------------------------------------
-.\" * set default formatting
-.\" -----------------------------------------------------------------
-.\" disable hyphenation
-.nh
-.\" disable justification (adjust text to left margin only)
-.ad l
-.\" -----------------------------------------------------------------
-.\" * MAIN CONTENT STARTS HERE *
-.\" -----------------------------------------------------------------
-.SH "NAME"
-papd \- AppleTalk print server daemon
-.SH "SYNOPSIS"
-.HP \w'\fBpapd\fR\fB\fR\fB\fR\ 'u
-\fBpapd\fR\fB\fR\fB\fR [\-d] [\-f\ configfile] [\-p\ printcap]
-.SH "DESCRIPTION"
-.PP
-\fBpapd\fR
-is the AppleTalk printer daemon\&. This daemon accepts print jobs from AppleTalk clients (typically Macintosh computers) using the Printer Access Protocol (PAP)\&. When used with System V printing systems,
-\fBpapd\fR
-spools jobs directly into an
-\fBlpd\fR(8)
-spool directory and wakes up
-\fBlpd\fR
-after accepting a job from the network to have it re\-examine the appropriate spool directory\&. The actual printing and spooling is handled entirely by
-\fBlpd\fR\&.
-.PP
-\fBpapd\fR
-can also pipe the print job to an external program for processing, and this is the preferred method on systems not using CUPS to avoid compatibility problems with all the flavours of
-\fBlpd\fR
-in use\&.
-.PP
-As of version 2\&.0, CUPS is also supported\&. Simply using
-\fBcupsautoadd\fR
-as first papd\&.conf entry will share all CUPS printers automagically using the PPD files configured in CUPS\&. It ist still possible to overwrite these defaults by individually define printer shares\&. See
-\fBpapd.conf\fR(5)
-for details\&.
-.PP
-\fBpapd\fR
-is typically started at boot time, out of system init scripts\&. It first reads from its configuration file,
-:ETCDIR:/papd\&.conf\&. The file is in the same format as
-/etc/printcap\&. See
-\fBprintcap\fR(5)
-for details\&. The name of the entry is registered with NBP\&.
-.PP
-The following options are supported:
-.TS
-tab(:);
-cB cB cB nB.
-T{
-Name
-T}:T{
-Type
-T}:T{
-Default
-T}:T{
-Description
-T}
-.T&
-c l l l
-c l l l
-c l l l
-c l l l
-c l l l
-c l l l
-c l l l
-c l l l
-c l l l
-c l l l.
-T{
-pd
-T}:T{
-str
-T}:T{
-\'\&.ppd\'
-T}:T{
-Pathname to PPD file
-T}
-T{
-pr
-T}:T{
-str
-T}:T{
-\'lp\'
-T}:T{
-LPD or CUPS printer name (or pipe to a print
-              command)
-T}
-T{
-op
-T}:T{
-str
-T}:T{
-\'operator\'
-T}:T{
-Operator name for LPD spooling
-T}
-T{
-au
-T}:T{
-bool
-T}:T{
-false
-T}:T{
-Whether to do authenticated printing or not
-T}
-T{
-ca
-T}:T{
-str
-T}:T{
-NULL
-T}:T{
-Pathname used for CAP\-style authentification
-T}
-T{
-sp
-T}:T{
-bool
-T}:T{
-false
-T}:T{
-PSSP\-style authetication
-T}
-T{
-am
-T}:T{
-str
-T}:T{
-NULL
-T}:T{
-UAMS to use for authentication
-T}
-T{
-pa
-T}:T{
-str
-T}:T{
-NULL
-T}:T{
-Printer\'s AppleTalk address
-T}
-T{
-co
-T}:T{
-str
-T}:T{
-NULL
-T}:T{
-CUPS options as supplied to the \fBlp\fR(1) command with "\-o"
-T}
-T{
-fo
-T}:T{
-bool
-T}:T{
-false
-T}:T{
-adjust lineending for foomatic\-rip
-T}
-.TE
-.sp 1
-If no configuration file is given, the hostname of the machine is used as the NBP name and all options take their default value\&.
-.SH "OPTIONS"
-.PP
-\-d
-.RS 4
-Do not fork or disassociate from the terminal\&. Write some debugging information to stderr\&.
-.RE
-.PP
-\-f \fIconfigfile\fR
-.RS 4
-Consult
-\fIconfigfile\fR
-instead of
-:ETCDIR:/papd\&.conf
-for the configuration information\&.
-.RE
-.PP
-\-p \fIprintcap\fR
-.RS 4
-Consult
-\fIprintcap\fR
-instead of
-/etc/printcap
-for LPD configuration information\&.
-.RE
-.SH "NOTES"
-.PP
-PSSP
-(Print Server Security Protocol) is an authentication protocol
-carried out through postscript printer queries to the print server\&. Using PSSP requires LaserWriter 8\&.6\&.1 or greater on the client mac\&. The user will be prompted to enter their username and password before they print\&. It may be necessary to re\-setup the printer on each client the first time PSSP is enabled, so that the client can figure out that authentication is required to print\&. You can enable PSSP on a per\-printer basis\&. PSSP is the recommended method of authenticating printers as it is more robust than CAP\-style authentication, described below\&.
-.PP
-CAP\-style authentication
-gets its name from the method the CAP (Columbia APpletalk) package used to authenticate its mac clients\' printing\&. This method requires that a user login to a file share before they print\&.
-\fBafpd\fR
-records the username in a temporary file named after the client\'s Appletalk address, and it deletes the temporary file when the user disconnects\&. Therefore CAP style authentification will
-\fInot\fR
-work for clients connected to
-\fBafpd\fR
-via TCP/IP\&.
-\fBpapd\fR
-gets the username from the file with the same Appletalk address as the machine connecting to it\&. CAP\-style authentication will work with any mac client\&. If both CAP and PSSP are enabled for a particular printer, CAP will be tried first, then
-\fBpapd\fR
-will fall back to PSSP\&.
-.PP
-The list of UAMs to use for authentication (specified with the \'am\' option) applies to all printers\&. It is not possible to define different authentication methods on each printer\&. You can specify the list of UAMS multiple times, but only the last setting will be used\&. Currently only uams_guest\&.so and uams_clrtxt\&.so are supported as printer authentication methods\&. The guest method requires a valid username, but not a password\&. The Cleartext UAM requires both a valid username and the correct password\&.
-.if n \{\
-.sp
-.\}
-.RS 4
-.it 1 an-trap
-.nr an-no-space-flag 1
-.nr an-break-flag 1
-.br
-.ps +1
-\fBNote\fR
-.ps -1
-.br
-.PP
-As of this writing, Mac OS X makes no use of PSSP authentication any longer\&. CAP\-style authentication normally won\'t be an option, too caused by the use of AFP over TCP these days\&.
-.sp .5v
-.RE
-.PP
-.SH "FILES"
-.PP
-:ETCDIR:/papd\&.conf
-.RS 4
-Default configuration file\&.
-.RE
-.PP
-/etc/printcap
-.RS 4
-Printer capabilities database\&.
-.RE
-.PP
-\&.ppd
-.RS 4
-PostScript Printer Description file\&. papd answers configuration and font queries from printing clients by consulting the configured PPD file\&. Such files are available for download from Adobe, Inc\&. (\m[blue]\fBhttp://www\&.adobe\&.com/support/downloads/main\&.htm\fR\m[]\&\s-2\u[1]\d\s+2), or from the printer\'s manufacturer\&. If no PPD file is configured, papd will return the default answer, possibly causing the client to send excessively large jobs\&.
-.RE
-.SH "CAVEATS"
-.PP
-\fBpapd\fR
-accepts characters with the high bit set (a full 8\-bits) from the clients, but some PostScript printers (including Apple Computer\'s LaserWriter family) only accept 7\-bit characters on their serial interface by default\&. The same applies for some printers when they\'re accessed via TCP/IP methods (remote LPR or socket)\&. You will need to configure your printer to accept a full 8 bits or take special precautions and convert the printjob\'s encoding (eg\&. by using
-\fBco="protocol=BCP"\fR
-when using CUPS 1\&.1\&.19 or above)\&.
-.PP
-When printing clients run MacOS 10\&.2 or above, take care that PPDs do not make use of
-\fB*cupsFilter:\fR
-comments unless the appropriate filters are installed at the client\'s side, too (remember: Starting with 10\&.2 Apple chose to integrate CUPS into MacOS X)\&. For in\-depth information on how CUPS uses PPDs see chapter 3\&.4 in
-\m[blue]\fBhttp://tinyurl\&.com/zbxn\fR\m[]\&\s-2\u[2]\d\s+2)\&.
-.SH "SEE ALSO"
-.PP
-\fBlpr\fR(1),\fBlprm\fR(1),\fBprintcap\fR(5),\fBlpc\fR(8),\fBlpd\fR(8),
-\fBlp\fR(1)\&.
-.SH "NOTES"
-.IP " 1." 4
-http://www.adobe.com/support/downloads/main.htm
-.RS 4
-\%http://www.adobe.com/support/downloads/main.html#Printer
-.RE
-.IP " 2." 4
-http://tinyurl.com/zbxn
-.RS 4
-\%http://tinyurl.com/zbxn
-.RE
diff --git a/man/man8/papstatus.8.tmpl b/man/man8/papstatus.8.tmpl
deleted file mode 100644 (file)
index d0bc11d..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-'\" t
-.\"     Title: papstatus
-.\"    Author: [FIXME: author] [see http://docbook.sf.net/el/author]
-.\" Generator: DocBook XSL Stylesheets v1.75.2 <http://docbook.sf.net/>
-.\"      Date: 17 Dec 1991
-.\"    Manual: Netatalk 2.2
-.\"    Source: Netatalk 2.2
-.\"  Language: English
-.\"
-.TH "PAPSTATUS" "8" "17 Dec 1991" "Netatalk 2.2" "Netatalk 2.2"
-.\" -----------------------------------------------------------------
-.\" * set default formatting
-.\" -----------------------------------------------------------------
-.\" disable hyphenation
-.nh
-.\" disable justification (adjust text to left margin only)
-.ad l
-.\" -----------------------------------------------------------------
-.\" * MAIN CONTENT STARTS HERE *
-.\" -----------------------------------------------------------------
-.SH "NAME"
-papstatus \- get the status of an AppleTalk\-connected printer
-.SH "SYNOPSIS"
-.HP \w'\fB:SBINDIR:/papstatus\fR\fB\fR\ 'u
-\fB:SBINDIR:/papstatus\fR\fB\fR [\-d] [\-p\ \fIprinter\fR] [\fIretrytime\fR]
-.SH "DESCRIPTION"
-.PP
-\fBpapstatus\fR
-is used to obtain the current status message from an AppleTalk connected printer\&. It uses the Printer Access Protocol (PAP) to obtain the status information\&.
-.PP
-If no printer is specified on the command line,
-\fBpapstatus\fR
-looks for a file called
-\fB\&.paprc\fR
-in the current directory and reads it to obtain the name of a printer\&. The
-\fB\&.paprc\fR
-file should contain a single line of the form
-\fIobject\fR\fB:\fR\fItype\fR\fB@\fR\fIzone\fR
-where each of
-\fIobject\fR,
-\fB:\fR\fItype\fR\fB,\fR
-and
-\fB@\fR\fIzone\fR
-are optional\&.
-\fItype\fR
-and
-\fIzone\fR
-must be proceeded by `\fB:\fR\' and `\fB@\fR\' respectively\&. Blank lines and lines the begin with a `\fB#\fR\' are ignored\&.
-\fItype\fR
-and
-\fIzone\fR
-default to
-\fBLaserWriter\fR
-and the zone of the local host, respectively\&.
-.SH "OPTIONS"
-.PP
-\fB\-d\fR
-.RS 4
-Turns on a debugging mode that prints some extra information to standard error\&.
-.RE
-.PP
-\fB\-p\fR \fIprinter\fR
-.RS 4
-Get status from
-\fIprinter\fR
-(do not consult any
-\fB\&.paprc\fR
-files to find a printer name)\&. The syntax for
-\fIprinter\fR
-is the same as discussed above for the
-\fB\&.paprc\fR
-file\&.
-.RE
-.PP
-\fIretrytime\fR
-.RS 4
-Normally,
-\fBpapstatus\fR
-only gets the status from the printer once\&. If
-\fIretrytime\fR
-is specified, the status is obtained repeatedly, with a sleep of
-\fIretrytime\fR
-seconds between inquiring the printer\&.
-.RE
-.SH "FILES"
-.PP
-\fB\&.paprc\fR
-.RS 4
-file that contains printer name
-.RE
-.SH "SEE ALSO"
-.PP
-\fBnbp\fR(1),
-\fBpap\fR(1)
diff --git a/man/man8/psf.8.tmpl b/man/man8/psf.8.tmpl
deleted file mode 100644 (file)
index ed9f59e..0000000
+++ /dev/null
@@ -1,115 +0,0 @@
-'\" t
-.\"     Title: psf
-.\"    Author: [FIXME: author] [see http://docbook.sf.net/el/author]
-.\" Generator: DocBook XSL Stylesheets v1.75.2 <http://docbook.sf.net/>
-.\"      Date: 17 Dec 1991
-.\"    Manual: Netatalk 2.2
-.\"    Source: Netatalk 2.2
-.\"  Language: English
-.\"
-.TH "PSF" "8" "17 Dec 1991" "Netatalk 2.2" "Netatalk 2.2"
-.\" -----------------------------------------------------------------
-.\" * set default formatting
-.\" -----------------------------------------------------------------
-.\" disable hyphenation
-.nh
-.\" disable justification (adjust text to left margin only)
-.ad l
-.\" -----------------------------------------------------------------
-.\" * MAIN CONTENT STARTS HERE *
-.\" -----------------------------------------------------------------
-.SH "NAME"
-psf \- PostScript filter
-.SH "SYNOPSIS"
-.HP \w'\fBpsf\fR\fB\fR\ 'u
-\fBpsf\fR\fB\fR [\-n\ \fIname\fR] [\-h\ \fIhost\fR] [\-w\ \fIwidth\fR] [\-l\ \fIlength\fR] [\-i\ \fIindent\fR] [\-c]
-.SH "DESCRIPTION"
-.PP
-\fBpsf\fR
-is an
-\fBlpd\fR
-filter for PostScript printing\&.
-\fBpsf\fR
-interprets the name it was called with to determine what filters to invoke\&. First, if the string ``pap\'\' appears anywhere in the name,
-\fBpsf\fR
-invokes
-\fBpap\fR
-to talk to a printer via AppleTalk\&. Next, if the string ``rev\'\' appears,
-\fBpsf\fR
-invokes
-\fBpsorder\fR
-to reverse the pages of the job\&. Finally, if
-\fBpsf\fR
-was called with a filter\'s name as the leading string, it invokes that filter\&. If there is no filter to run,
-\fBpsf\fR
-examines the magic number of the input, and if the input is not PostScript, converts it to PostScript\&.
-.SH "KLUDGE"
-.PP
-In the default configuration,
-\fBpsf\fR
-supports two kludges\&. The first causes
-\fBpsf\fR
-to check its name for the letter `m\'\&. If this letter is found and accounting is turned on,
-\fBpsf\fR
-calls
-\fBpap\fR
-twice, once to get an initial page count and to print the job, and another time to get a final page count\&. This is a work\-around for bugs in a variety of PAP implementions that cause printers to never properly close the PAP output file\&. A notable example is any printer by Hewlett\-Packard\&.
-.PP
-The second kludge causes
-\fBpsf\fR
-to examine its name for the letter `w\'\&. If this letter is found and accounting is turned on,
-\fBpsf\fR
-calls
-\fBpap\fR
-with the
-\fB\-w\fR
-flag\&. This flag causes
-\fBpap\fR
-to wait until the printer\'s status contains the string `idle\'\&. Once this string is found, the job is printed as normal\&. This kludge is a work\-around for printers, notably Hewlett\-Packard\'s LaserJet IV, which will report a page count while a previous jobs is still printing\&.
-.SH "EXAMPLE"
-.PP
-The sample
-\fBprintcap\fR
-entry below invokes
-\fBpsf\fR
-to print text files, PostScript files,
-\fBtroff\fR\'s C/A/T output, and
-\fBTeX\fR\'s DVI output, to an AppleTalk connected LaserWriter Plus\&. Since the LaserWriter Plus stacks pages in descending order, we reverse the pages and print the burst page last\&.
-.sp
-.if n \{\
-.RS 4
-.\}
-.nf
-laser|lp|LaserWriter Plus on AppleTalk:\e
-    :sd=/usr/spool/lpd/laser:\e
-    :lp=/usr/spool/lpd/laser/null:\e
-    :lf=/var/adm/lpd\-errs:pw#80:hl:\e
-    :of=:LIBEXECDIR:/ofpap:\e
-    :if=:LIBEXECDIR:/ifpaprev:\e
-    :tf=:LIBEXECDIR:/tfpaprev:\e
-    :df=:LIBEXECDIR:/dfpaprev:
-.fi
-.if n \{\
-.RE
-.\}
-.PP
-Note that if the host in question spools to more than one AppleTalk printer,
-/dev/null
-should not be used for the
-\fBlp\fR
-capability\&. Instead, a null device should be created with
-\fBmknod\fR
-for each printer, as has been done above\&.
-.PP
-Finally, there is a file in the spool directory,
-/var/spool/lpd/laser, called
-\fB\&.paprc\fR, which
-\fBpap\fR
-reads for the AppleTalk name of the printer\&.
-.SH "SEE ALSO"
-.PP
-\fBpsorder\fR(1),
-\fBprintcap\fR(5),
-\fBlpd\fR(1),
-\fBmknod\fR(1),
-\fBpap\fR(1)\&.
diff --git a/man/man8/timelord.8 b/man/man8/timelord.8
deleted file mode 100644 (file)
index 1496486..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-'\" t
-.\"     Title: timelord
-.\"    Author: [FIXME: author] [see http://docbook.sf.net/el/author]
-.\" Generator: DocBook XSL Stylesheets v1.75.2 <http://docbook.sf.net/>
-.\"      Date: 27 Jun 2001
-.\"    Manual: The Netatalk Project
-.\"    Source: Netatalk 2.2
-.\"  Language: English
-.\"
-.TH "TIMELORD" "8" "27 Jun 2001" "Netatalk 2.2" "The Netatalk Project"
-.\" -----------------------------------------------------------------
-.\" * set default formatting
-.\" -----------------------------------------------------------------
-.\" disable hyphenation
-.nh
-.\" disable justification (adjust text to left margin only)
-.ad l
-.\" -----------------------------------------------------------------
-.\" * MAIN CONTENT STARTS HERE *
-.\" -----------------------------------------------------------------
-.SH "NAME"
-timelord \- Macintosh time server daemon
-.SH "SYNOPSIS"
-.SH "SYNTAX"
-.PP
-timelord [\-d] [\-n
-\fIfilename\fR]
-.SH "DESCRIPTION"
-.PP
-\fBtimelord\fR
-is a simple time server for Macintosh computers that use the
-\fBtardis\fR
-client\&.
-.SH "OPTIONS"
-.PP
-\fB\-d\fR
-.RS 4
-Debug mode, i\&.e\&. don\'t disassociate from controlling TTY\&.
-.RE
-.PP
-\fB\-n\fR \fInbpname\fR
-.RS 4
-Register this server as
-\fInbpname\fR\&. This defaults to the hostname\&.
-.RE
diff --git a/sys/.gitignore b/sys/.gitignore
deleted file mode 100644 (file)
index 895a5e7..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-Makefile
-Makefile.in
-.gitignore
-*.o
diff --git a/sys/Makefile.am b/sys/Makefile.am
deleted file mode 100644 (file)
index 4472c8f..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-# Makefile.am for sys/
-
-SUBDIRS = netatalk generic solaris netbsd sunos ultrix
diff --git a/sys/generic/.gitignore b/sys/generic/.gitignore
deleted file mode 100644 (file)
index 895a5e7..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-Makefile
-Makefile.in
-.gitignore
-*.o
diff --git a/sys/generic/Makefile.am b/sys/generic/Makefile.am
deleted file mode 100644 (file)
index 081839c..0000000
+++ /dev/null
@@ -1 +0,0 @@
-SUBDIRS = sys
diff --git a/sys/generic/sys/.gitignore b/sys/generic/sys/.gitignore
deleted file mode 100644 (file)
index 895a5e7..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-Makefile
-Makefile.in
-.gitignore
-*.o
diff --git a/sys/generic/sys/Makefile.am b/sys/generic/sys/Makefile.am
deleted file mode 100644 (file)
index 187947d..0000000
+++ /dev/null
@@ -1 +0,0 @@
-EXTRA_DIST = cdefs.h
diff --git a/sys/generic/sys/cdefs.h b/sys/generic/sys/cdefs.h
deleted file mode 100644 (file)
index c24481c..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-/*
- * $Id: cdefs.h,v 1.4 2001-08-15 15:29:14 srittau Exp $
- */
-
-#ifndef _SYS_CDEFS_H
-#define _SYS_CDEFS_H 1
-
-#if defined(__STDC__) || defined(__DECC)
-/* Note that there must be exactly one space between __P(args) and args,
- * otherwise DEC C chokes.
- */
-#define __P(args) args
-#else /* __STDC__ */
-#define __P(args)    ()
-#endif /* __STDC__ */
-
-#endif /* sys/cdefs.h */
diff --git a/sys/netatalk/.gitignore b/sys/netatalk/.gitignore
deleted file mode 100644 (file)
index 895a5e7..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-Makefile
-Makefile.in
-.gitignore
-*.o
diff --git a/sys/netatalk/Makefile.am b/sys/netatalk/Makefile.am
deleted file mode 100644 (file)
index 14eeab7..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-# Makefile.am for sys/netatalk/
-
-pkginclude_HEADERS = aarp.h at.h at_var.h ddp.h ddp_var.h endian.h phase2.h
-
-SOURCES = aarp.c at_control.c at_proto.c ddp_input.c ddp_output.c ddp_usrreq.c
-
-EXTRA_DIST = $(SOURCES)
diff --git a/sys/netatalk/aarp.c b/sys/netatalk/aarp.c
deleted file mode 100644 (file)
index ee18845..0000000
+++ /dev/null
@@ -1,802 +0,0 @@
-/*
- * $Id: aarp.c,v 1.3 2002-01-03 17:49:39 sibaz Exp $
- *
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- * All Rights Reserved.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <syslog.h>
-#include <sys/param.h>
-#include <sys/mbuf.h>
-#include <sys/time.h>
-#ifndef _IBMR2
-#include <sys/kernel.h>
-#endif /* _IBMR2 */
-#include <net/if.h>
-#include <net/route.h>
-#include <net/af.h>
-#include <netinet/in.h>
-#undef s_net
-#include <netinet/if_ether.h>
-#ifdef _IBMR2
-#include <netinet/in_netarp.h>
-#include <net/spl.h>
-#include <sys/errno.h>
-#include <sys/err_rec.h>
-#endif /* _IBMR2 */
-
-#include "at.h"
-#include "at_var.h"
-#include "aarp.h"
-#include "ddp_var.h"
-#include "endian.h"
-#include "phase2.h"
-
-#ifdef GATEWAY
-#define AARPTAB_BSIZ   16
-#define AARPTAB_NB     37
-#else /* GATEWAY */
-#define AARPTAB_BSIZ   9
-#define AARPTAB_NB     19
-#endif /* GATEWAY */
-#define AARPTAB_SIZE   (AARPTAB_BSIZ * AARPTAB_NB)
-struct aarptab         aarptab[AARPTAB_SIZE];
-int                    aarptab_size = AARPTAB_SIZE;
-
-#define AARPTAB_HASH(a) \
-    ((((a).s_net << 8 ) + (a).s_node ) % AARPTAB_NB )
-
-#define AARPTAB_LOOK(aat,addr) { \
-    int                n; \
-    aat = &aarptab[ AARPTAB_HASH(addr) * AARPTAB_BSIZ ]; \
-    for ( n = 0; n < AARPTAB_BSIZ; n++, aat++ ) \
-       if ( aat->aat_ataddr.s_net == (addr).s_net && \
-            aat->aat_ataddr.s_node == (addr).s_node ) \
-           break; \
-       if ( n >= AARPTAB_BSIZ ) \
-           aat = 0; \
-}
-
-#define AARPT_AGE      (60 * 1)
-#define AARPT_KILLC    20
-#define AARPT_KILLI    3
-
-#ifdef sun
-extern struct ether_addr       etherbroadcastaddr;
-#else /* sun */
-extern u_char                  etherbroadcastaddr[6];
-#endif /* sun */
-
-u_char atmulticastaddr[ 6 ] = {
-    0x09, 0x00, 0x07, 0xff, 0xff, 0xff,
-};
-
-u_char at_org_code[ 3 ] = {
-    0x08, 0x00, 0x07,
-};
-u_char aarp_org_code[ 3 ] = {
-    0x00, 0x00, 0x00,
-};
-
-aarptimer()
-{
-    struct aarptab     *aat;
-    int                        i, s;
-
-    timeout( aarptimer, (caddr_t)0, AARPT_AGE * hz );
-    aat = aarptab;
-    for ( i = 0; i < AARPTAB_SIZE; i++, aat++ ) {
-       if ( aat->aat_flags == 0 || ( aat->aat_flags & ATF_PERM ))
-           continue;
-       if ( ++aat->aat_timer < (( aat->aat_flags & ATF_COM ) ?
-               AARPT_KILLC : AARPT_KILLI ))
-           continue;
-       s = splimp();
-       aarptfree( aat );
-       splx( s );
-    }
-}
-
-struct ifaddr *
-at_ifawithnet( sat, ifa )
-    struct sockaddr_at *sat;
-    struct ifaddr      *ifa;
-{
-    struct at_ifaddr   *aa;
-
-    for (; ifa; ifa = ifa->ifa_next ) {
-#ifdef BSD4_4
-       if ( ifa->ifa_addr->sa_family != AF_APPLETALK ) {
-           continue;
-       }
-       if ( satosat( ifa->ifa_addr )->sat_addr.s_net ==
-               sat->sat_addr.s_net ) {
-           break;
-       }
-#else /* BSD4_4 */
-       if ( ifa->ifa_addr.sa_family != AF_APPLETALK ) {
-           continue;
-       }
-       aa = (struct at_ifaddr *)ifa;
-       if ( ntohs( sat->sat_addr.s_net ) >= ntohs( aa->aa_firstnet ) &&
-               ntohs( sat->sat_addr.s_net ) <= ntohs( aa->aa_lastnet )) {
-           break;
-       }
-#endif /* BSD4_4 */
-    }
-    return( ifa );
-}
-
-aarpwhohas( ac, sat )
-    struct arpcom      *ac;
-    struct sockaddr_at *sat;
-{
-    struct mbuf                *m;
-    struct ether_header        *eh;
-    struct ether_aarp  *ea;
-    struct at_ifaddr   *aa;
-    struct llc         *llc;
-    struct sockaddr    sa;
-
-#ifdef BSD4_4
-    if (( m = m_gethdr( M_DONTWAIT, MT_DATA )) == NULL ) {
-       return;
-    }
-    m->m_len = sizeof( *ea );
-    m->m_pkthdr.len = sizeof( *ea );
-    MH_ALIGN( m, sizeof( *ea ));
-#else /* BSD4_4 */
-    if (( m = m_get( M_DONTWAIT, MT_DATA )) == NULL ) {
-       return;
-    }
-    m->m_len = sizeof( *ea );
-    m->m_off = MMAXOFF - sizeof( *ea );
-#endif /* BSD4_4 */
-
-    ea = mtod( m, struct ether_aarp *);
-    bzero((caddr_t)ea, sizeof( *ea ));
-
-    ea->aarp_hrd = htons( AARPHRD_ETHER );
-    ea->aarp_pro = htons( ETHERTYPE_AT );
-    ea->aarp_hln = sizeof( ea->aarp_sha );
-    ea->aarp_pln = sizeof( ea->aarp_spu );
-    ea->aarp_op = htons( AARPOP_REQUEST );
-#ifdef sun
-    bcopy((caddr_t)&ac->ac_enaddr, (caddr_t)ea->aarp_sha,
-           sizeof( ea->aarp_sha ));
-#else /* sun */
-    bcopy((caddr_t)ac->ac_enaddr, (caddr_t)ea->aarp_sha,
-           sizeof( ea->aarp_sha ));
-#endif /* sun */
-
-    /*
-     * We need to check whether the output ethernet type should
-     * be phase 1 or 2. We have the interface that we'll be sending
-     * the aarp out. We need to find an AppleTalk network on that
-     * interface with the same address as we're looking for. If the
-     * net is phase 2, generate an 802.2 and SNAP header.
-     */
-    if (( aa = (struct at_ifaddr *)at_ifawithnet( sat, ac->ac_if.if_addrlist ))
-           == NULL ) {
-       m_freem( m );
-       return;
-    }
-
-    eh = (struct ether_header *)sa.sa_data;
-
-    if ( aa->aa_flags & AFA_PHASE2 ) {
-#ifdef sun
-       bcopy((caddr_t)atmulticastaddr, (caddr_t)&eh->ether_dhost,
-               sizeof( eh->ether_dhost ));
-#else /* sun */
-       bcopy((caddr_t)atmulticastaddr, (caddr_t)eh->ether_dhost,
-               sizeof( eh->ether_dhost ));
-#endif /* sun */
-#if defined( sun ) && defined( i386 )
-       eh->ether_type = htons( sizeof( struct llc ) +
-               sizeof( struct ether_aarp ));
-#else /* sun && i386 */
-       eh->ether_type = sizeof( struct llc ) + sizeof( struct ether_aarp );
-#endif /* sun && i386 */
-#ifdef BSD4_4
-       M_PREPEND( m, sizeof( struct llc ), M_WAIT );
-#else /* BSD4_4 */
-       m->m_len += sizeof( struct llc );
-       m->m_off -= sizeof( struct llc );
-#endif /* BSD4_4 */
-       llc = mtod( m, struct llc *);
-       llc->llc_dsap = llc->llc_ssap = LLC_SNAP_LSAP;
-       llc->llc_control = LLC_UI;
-       bcopy( aarp_org_code, llc->llc_org_code, sizeof( aarp_org_code ));
-       llc->llc_ether_type = htons( ETHERTYPE_AARP );
-
-       
-       bcopy( &AA_SAT( aa )->sat_addr.s_net, ea->aarp_spnet,
-               sizeof( ea->aarp_spnet ));
-       ea->aarp_spnode = AA_SAT( aa )->sat_addr.s_node;
-       bcopy( &sat->sat_addr.s_net, ea->aarp_tpnet,
-               sizeof( ea->aarp_tpnet ));
-       ea->aarp_tpnode = sat->sat_addr.s_node;
-    } else {
-#ifdef sun
-       bcopy((caddr_t)&etherbroadcastaddr, (caddr_t)&eh->ether_dhost,
-               sizeof( eh->ether_dhost ));
-#else /* sun */
-       bcopy((caddr_t)etherbroadcastaddr, (caddr_t)eh->ether_dhost,
-               sizeof( eh->ether_dhost ));
-#endif /* sun */
-#if defined( sun ) && defined( i386 )
-       eh->ether_type = htons( ETHERTYPE_AARP );
-#else /* sun && i386 */
-       eh->ether_type = ETHERTYPE_AARP;
-#endif /* sun && i386 */
-
-       ea->aarp_spa = AA_SAT( aa )->sat_addr.s_node;
-       ea->aarp_tpa = sat->sat_addr.s_node;
-    }
-
-#ifdef BSD4_4
-    sa.sa_len = sizeof( struct sockaddr );
-#endif /* BSD4_4 */
-    sa.sa_family = AF_UNSPEC;
-    (*ac->ac_if.if_output)(&ac->ac_if, m, &sa );
-}
-
-aarpresolve( ac, m, destsat, desten )
-    struct arpcom      *ac;
-    struct mbuf                *m;
-    struct sockaddr_at *destsat;
-#ifdef sun
-    struct ether_addr  *desten;
-#else /* sun */
-    u_char             *desten;
-#endif /* sun */
-{
-    struct at_ifaddr   *aa;
-    struct ifaddr      ifa;
-    struct aarptab     *aat;
-    int                        s;
-
-    if ( at_broadcast( destsat )) {
-       if (( aa = (struct at_ifaddr *)at_ifawithnet( destsat,
-               ((struct ifnet *)ac)->if_addrlist )) == NULL ) {
-           m_freem( m );
-           return( 0 );
-       }
-       if ( aa->aa_flags & AFA_PHASE2 ) {
-           bcopy( (caddr_t)atmulticastaddr, (caddr_t)desten,
-                   sizeof( atmulticastaddr ));
-       } else {
-#ifdef sun
-           bcopy( (caddr_t)&etherbroadcastaddr, (caddr_t)desten,
-                   sizeof( etherbroadcastaddr ));
-#else /* sun */
-           bcopy( (caddr_t)etherbroadcastaddr, (caddr_t)desten,
-                   sizeof( etherbroadcastaddr ));
-#endif /* sun */
-       }
-       return( 1 );
-    }
-
-    s = splimp();
-    AARPTAB_LOOK( aat, destsat->sat_addr );
-    if ( aat == 0 ) {                  /* No entry */
-       aat = aarptnew( &destsat->sat_addr );
-       if ( aat == 0 ) {
-           panic( "aarpresolve: no free entry" );
-       }
-       aat->aat_hold = m;
-       aarpwhohas( ac, destsat );
-       splx( s );
-       return( 0 );
-    }
-    /* found an entry */
-    aat->aat_timer = 0;
-    if ( aat->aat_flags & ATF_COM ) {  /* entry is COMplete */
-       bcopy( (caddr_t)aat->aat_enaddr, (caddr_t)desten,
-               sizeof( aat->aat_enaddr ));
-       splx( s );
-       return( 1 );
-    }
-    /* entry has not completed */
-    if ( aat->aat_hold ) {
-       m_freem( aat->aat_hold );
-    }
-    aat->aat_hold = m;
-    aarpwhohas( ac, destsat );
-    splx( s );
-    return( 0 );
-}
-
-aarpinput( ac, m )
-    struct arpcom      *ac;
-    struct mbuf                *m;
-{
-    struct arphdr      *ar;
-
-    if ( ac->ac_if.if_flags & IFF_NOARP )
-       goto out;
-
-#ifndef BSD4_4
-    IF_ADJ( m );
-#endif /* BSD4_4 */
-
-    if ( m->m_len < sizeof( struct arphdr )) {
-       goto out;
-    }
-
-    ar = mtod( m, struct arphdr *);
-    if ( ntohs( ar->ar_hrd ) != AARPHRD_ETHER ) {
-       goto out;
-    }
-    
-    if ( m->m_len < sizeof( struct arphdr ) + 2 * ar->ar_hln +
-           2 * ar->ar_pln ) {
-       goto out;
-    }
-    
-    switch( ntohs( ar->ar_pro )) {
-    case ETHERTYPE_AT :
-       at_aarpinput( ac, m );
-       return;
-
-    default:
-       break;
-    }
-
-out:
-    m_freem( m );
-}
-
-
-at_aarpinput( ac, m )
-    struct arpcom      *ac;
-    struct mbuf                *m;
-{
-    struct mbuf                *m0;
-    struct ether_aarp  *ea;
-    struct at_ifaddr   *aa;
-    struct aarptab     *aat;
-    struct ether_header        *eh;
-    struct llc         *llc;
-    struct sockaddr_at sat;
-    struct sockaddr    sa;
-    struct at_addr     spa, tpa, ma;
-    int                        op, s;
-    u_short            net;
-
-    ea = mtod( m, struct ether_aarp *);
-
-    /* Check to see if from my hardware address */
-#ifdef sun
-    if ( !bcmp(( caddr_t )ea->aarp_sha, ( caddr_t )&ac->ac_enaddr,
-           sizeof( ac->ac_enaddr ))) {
-       m_freem( m );
-       return;
-    }
-#else /* sun */
-    if ( !bcmp(( caddr_t )ea->aarp_sha, ( caddr_t )ac->ac_enaddr,
-           sizeof( ac->ac_enaddr ))) {
-       m_freem( m );
-       return;
-    }
-#endif /* sun */
-
-    /*
-     * Check if from broadcast address.  This could be a more robust
-     * check, since we could look for multicasts.
-     */
-#ifdef sun
-    if ( !bcmp(( caddr_t )ea->aarp_sha, ( caddr_t )&etherbroadcastaddr,
-           sizeof( etherbroadcastaddr ))) {
-       log( LOG_ERR, "aarp: source is broadcast!\n" );
-       m_freem( m );
-       return;
-    }
-#else /* sun */
-    if ( !bcmp(( caddr_t )ea->aarp_sha, ( caddr_t )etherbroadcastaddr,
-           sizeof( etherbroadcastaddr ))) {
-#ifndef _IBMR2
-#ifdef ultrix
-       mprintf( LOG_ERR,
-#else /* ultrix */
-       log( LOG_ERR,
-#endif /* ultrix */
-               "aarp: source is broadcast!\n" );
-#endif /* ! _IBMR2 */
-       m_freem( m );
-       return;
-    }
-#endif /* sun */
-
-    op = ntohs( ea->aarp_op );
-    bcopy( ea->aarp_tpnet, &net, sizeof( net ));
-
-    if ( net != 0 ) {
-       sat.sat_family = AF_APPLETALK;
-       sat.sat_addr.s_net = net;
-       if (( aa = (struct at_ifaddr *)at_ifawithnet( &sat,
-               ac->ac_if.if_addrlist )) == NULL ) {
-           m_freem( m );
-           return;
-       }
-       bcopy( ea->aarp_spnet, &spa.s_net, sizeof( spa.s_net ));
-       bcopy( ea->aarp_tpnet, &tpa.s_net, sizeof( tpa.s_net ));
-    } else {
-       /*
-        * Since we don't know the net, we just look for the first
-        * phase 1 address on the interface.
-        */
-       for ( aa = (struct at_ifaddr *)ac->ac_if.if_addrlist; aa;
-               aa = (struct at_ifaddr *)aa->aa_ifa.ifa_next ) {
-           if ( AA_SAT( aa )->sat_family == AF_APPLETALK &&
-                   ( aa->aa_flags & AFA_PHASE2 ) == 0 ) {
-               break;
-           }
-       }
-       if ( aa == NULL ) {
-           m_freem( m );
-           return;
-       }
-       tpa.s_net = spa.s_net = AA_SAT( aa )->sat_addr.s_net;
-    }
-
-    spa.s_node = ea->aarp_spnode;
-    tpa.s_node = ea->aarp_tpnode;
-    ma.s_net = AA_SAT( aa )->sat_addr.s_net;
-    ma.s_node = AA_SAT( aa )->sat_addr.s_node;
-
-    /*
-     * This looks like it's from us.
-     */
-    if ( spa.s_net == ma.s_net && spa.s_node == ma.s_node ) {
-       if ( aa->aa_flags & AFA_PROBING ) {
-           /*
-            * We're probing, someone either responded to our probe, or
-            * probed for the same address we'd like to use. Change the
-            * address we're probing for.
-            */
-           untimeout( aarpprobe, ac );
-           wakeup( aa );
-           m_freem( m );
-           return;
-       } else if ( op != AARPOP_PROBE ) {
-           /*
-            * This is not a probe, and we're not probing. This means
-            * that someone's saying they have the same source address
-            * as the one we're using. Get upset...
-            */
-#ifndef _IBMR2
-#ifdef ultrix
-           mprintf( LOG_ERR,
-#else /* ultrix */
-           log( LOG_ERR,
-#endif /* ultrix */
-                   "aarp: duplicate AT address!! %x:%x:%x:%x:%x:%x\n",
-                   ea->aarp_sha[ 0 ], ea->aarp_sha[ 1 ], ea->aarp_sha[ 2 ],
-                   ea->aarp_sha[ 3 ], ea->aarp_sha[ 4 ], ea->aarp_sha[ 5 ]);
-#endif /* ! _IBMR2 */
-           m_freem( m );
-           return;
-       }
-    }
-
-    AARPTAB_LOOK( aat, spa );
-    if ( aat ) {
-       if ( op == AARPOP_PROBE ) {
-           /*
-            * Someone's probing for spa, dealocate the one we've got,
-            * so that if the prober keeps the address, we'll be able
-            * to arp for him.
-            */
-           aarptfree( aat );
-           m_freem( m );
-           return;
-       }
-
-       bcopy(( caddr_t )ea->aarp_sha, ( caddr_t )aat->aat_enaddr,
-               sizeof( ea->aarp_sha ));
-       aat->aat_flags |= ATF_COM;
-       if ( aat->aat_hold ) {
-#ifdef _IBMR2
-           /*
-            * Like in ddp_output(), we can't rely on the if_output
-            * routine to resolve AF_APPLETALK addresses, on the rs6k.
-            * So, we fill the destination ethernet address here.
-            *
-            * This should really be replaced with something like
-            * rsif_output(). XXX Will have to be for phase 2.
-            */
-            /* XXX maybe fill in the rest of the frame header */
-           sat.sat_family = AF_UNSPEC;
-           bcopy( aat->aat_enaddr, (*(struct sockaddr *)&sat).sa_data,
-                   sizeof( aat->aat_enaddr ));
-#else /* _IBMR2 */
-           sat.sat_family = AF_APPLETALK;
-           sat.sat_addr = spa;
-#endif /* _IBMR2 */
-           (*ac->ac_if.if_output)( &ac->ac_if, aat->aat_hold,
-                   (struct sockaddr *)&sat );
-           aat->aat_hold = 0;
-       }
-    }
-
-    if ( aat == 0 && tpa.s_net == ma.s_net && tpa.s_node == ma.s_node
-           && op != AARPOP_PROBE ) {
-       if ( aat = aarptnew( &spa )) {
-           bcopy(( caddr_t )ea->aarp_sha, ( caddr_t )aat->aat_enaddr,
-                   sizeof( ea->aarp_sha ));
-           aat->aat_flags |= ATF_COM;
-       }
-    }
-
-    /*
-     * Don't respond to responses, and never respond if we're
-     * still probing.
-     */
-    if ( tpa.s_net != ma.s_net || tpa.s_node != ma.s_node ||
-           op == AARPOP_RESPONSE || ( aa->aa_flags & AFA_PROBING )) {
-       m_freem( m );
-       return;
-    }
-
-    bcopy(( caddr_t )ea->aarp_sha, ( caddr_t )ea->aarp_tha,
-           sizeof( ea->aarp_sha ));
-#ifdef sun
-    bcopy(( caddr_t )&ac->ac_enaddr, ( caddr_t )ea->aarp_sha,
-           sizeof( ea->aarp_sha ));
-#else /* sun */
-    bcopy(( caddr_t )ac->ac_enaddr, ( caddr_t )ea->aarp_sha,
-           sizeof( ea->aarp_sha ));
-#endif /* sun */
-
-    eh = (struct ether_header *)sa.sa_data;
-#ifdef sun
-    bcopy(( caddr_t )ea->aarp_tha, ( caddr_t )&eh->ether_dhost,
-           sizeof( eh->ether_dhost ));
-#else /* sun */
-    bcopy(( caddr_t )ea->aarp_tha, ( caddr_t )eh->ether_dhost,
-           sizeof( eh->ether_dhost ));
-#endif /* sun */
-
-    if ( aa->aa_flags & AFA_PHASE2 ) {
-#if defined( sun ) && defined( i386 )
-       eh->ether_type = htons( sizeof( struct llc ) +
-               sizeof( struct ether_aarp ));
-#else /* sun && i386 */
-       eh->ether_type = sizeof( struct llc ) + sizeof( struct ether_aarp );
-#endif /* sun && i386 */
-#ifdef BSD4_4
-       M_PREPEND( m, sizeof( struct llc ), M_DONTWAIT );
-       if ( m == NULL ) {
-           m_freem( m );
-           return;
-       }
-#else /* BSD4_4 */
-       MGET( m0, M_DONTWAIT, MT_HEADER );
-       if ( m0 == NULL ) {
-           m_freem( m );
-           return;
-       }
-       m0->m_next = m;
-       m = m0;
-       m->m_off = MMAXOFF - sizeof( struct llc );
-       m->m_len = sizeof ( struct llc );
-#endif /* BSD4_4 */
-       llc = mtod( m, struct llc *);
-       llc->llc_dsap = llc->llc_ssap = LLC_SNAP_LSAP;
-       llc->llc_control = LLC_UI;
-       bcopy( aarp_org_code, llc->llc_org_code, sizeof( aarp_org_code ));
-       llc->llc_ether_type = htons( ETHERTYPE_AARP );
-
-       bcopy( ea->aarp_spnet, ea->aarp_tpnet, sizeof( ea->aarp_tpnet ));
-       bcopy( &ma.s_net, ea->aarp_spnet, sizeof( ea->aarp_spnet ));
-    } else {
-#if defined( sun ) && defined( i386 )
-       eh->ether_type = htons( ETHERTYPE_AARP );
-#else /* sun && i386 */
-       eh->ether_type = ETHERTYPE_AARP;
-#endif /* sun && i386 */
-    }
-
-    ea->aarp_tpnode = ea->aarp_spnode;
-    ea->aarp_spnode = ma.s_node;
-    ea->aarp_op = htons( AARPOP_RESPONSE );
-
-#ifdef BSD4_4
-    sa.sa_len = sizeof( struct sockaddr );
-#endif /* BSD4_4 */
-    sa.sa_family = AF_UNSPEC;
-    (*ac->ac_if.if_output)( &ac->ac_if, m, &sa );
-    return;
-}
-
-aarptfree( aat )
-    struct aarptab     *aat;
-{
-
-    if ( aat->aat_hold )
-       m_freem( aat->aat_hold );
-    aat->aat_hold = 0;
-    aat->aat_timer = aat->aat_flags = 0;
-    aat->aat_ataddr.s_net = 0;
-    aat->aat_ataddr.s_node = 0;
-}
-
-    struct aarptab *
-aarptnew( addr )
-    struct at_addr     *addr;
-{
-    int                        n;
-    int                        oldest = -1;
-    struct aarptab     *aat, *aato = NULL;
-    static int         first = 1;
-
-    if ( first ) {
-       first = 0;
-       timeout( aarptimer, (caddr_t)0, hz );
-    }
-    aat = &aarptab[ AARPTAB_HASH( *addr ) * AARPTAB_BSIZ ];
-    for ( n = 0; n < AARPTAB_BSIZ; n++, aat++ ) {
-       if ( aat->aat_flags == 0 )
-           goto out;
-       if ( aat->aat_flags & ATF_PERM )
-           continue;
-       if ((int) aat->aat_timer > oldest ) {
-           oldest = aat->aat_timer;
-           aato = aat;
-       }
-    }
-    if ( aato == NULL )
-       return( NULL );
-    aat = aato;
-    aarptfree( aat );
-out:
-    aat->aat_ataddr = *addr;
-    aat->aat_flags = ATF_INUSE;
-    return( aat );
-}
-
-aarpprobe( ac )
-    struct arpcom      *ac;
-{
-    struct mbuf                *m;
-    struct ether_header        *eh;
-    struct ether_aarp  *ea;
-    struct at_ifaddr   *aa;
-    struct llc         *llc;
-    struct sockaddr    sa;
-
-    /*
-     * We need to check whether the output ethernet type should
-     * be phase 1 or 2. We have the interface that we'll be sending
-     * the aarp out. We need to find an AppleTalk network on that
-     * interface with the same address as we're looking for. If the
-     * net is phase 2, generate an 802.2 and SNAP header.
-     */
-    for ( aa = (struct at_ifaddr *)ac->ac_if.if_addrlist; aa;
-           aa = (struct at_ifaddr *)aa->aa_ifa.ifa_next ) {
-       if ( AA_SAT( aa )->sat_family == AF_APPLETALK &&
-               ( aa->aa_flags & AFA_PROBING )) {
-           break;
-       }
-    }
-    if ( aa == NULL ) {                /* serious error XXX */
-       printf( "aarpprobe why did this happen?!\n" );
-       return;
-    }
-
-    if ( aa->aa_probcnt <= 0 ) {
-       aa->aa_flags &= ~AFA_PROBING;
-       wakeup( aa );
-       return;
-    } else {
-       timeout( aarpprobe, (caddr_t)ac, hz / 5 );
-    }
-
-#ifdef BSD4_4
-    if (( m = m_gethdr( M_DONTWAIT, MT_DATA )) == NULL ) {
-       return;
-    }
-    m->m_len = sizeof( *ea );
-    m->m_pkthdr.len = sizeof( *ea );
-    MH_ALIGN( m, sizeof( *ea ));
-#else /* BSD4_4 */
-    if (( m = m_get( M_DONTWAIT, MT_DATA )) == NULL ) {
-       return;
-    }
-    m->m_len = sizeof( *ea );
-    m->m_off = MMAXOFF - sizeof( *ea );
-#endif /* BSD4_4 */
-
-    ea = mtod( m, struct ether_aarp *);
-    bzero((caddr_t)ea, sizeof( *ea ));
-
-    ea->aarp_hrd = htons( AARPHRD_ETHER );
-    ea->aarp_pro = htons( ETHERTYPE_AT );
-    ea->aarp_hln = sizeof( ea->aarp_sha );
-    ea->aarp_pln = sizeof( ea->aarp_spu );
-    ea->aarp_op = htons( AARPOP_PROBE );
-#ifdef sun
-    bcopy((caddr_t)&ac->ac_enaddr, (caddr_t)ea->aarp_sha,
-           sizeof( ea->aarp_sha ));
-#else /* sun */
-    bcopy((caddr_t)ac->ac_enaddr, (caddr_t)ea->aarp_sha,
-           sizeof( ea->aarp_sha ));
-#endif /* sun */
-
-    eh = (struct ether_header *)sa.sa_data;
-
-    if ( aa->aa_flags & AFA_PHASE2 ) {
-#ifdef sun
-       bcopy((caddr_t)atmulticastaddr, (caddr_t)&eh->ether_dhost,
-               sizeof( eh->ether_dhost ));
-#else /* sun */
-       bcopy((caddr_t)atmulticastaddr, (caddr_t)eh->ether_dhost,
-               sizeof( eh->ether_dhost ));
-#endif /* sun */
-#if defined( sun ) && defined( i386 )
-       eh->ether_type = htons( sizeof( struct llc ) +
-               sizeof( struct ether_aarp ));
-#else /* sun && i386 */
-       eh->ether_type = sizeof( struct llc ) + sizeof( struct ether_aarp );
-#endif /* sun && i386 */
-#ifdef BSD4_4
-       M_PREPEND( m, sizeof( struct llc ), M_WAIT );
-#else /* BSD4_4 */
-       m->m_len += sizeof( struct llc );
-       m->m_off -= sizeof( struct llc );
-#endif /* BSD4_4 */
-       llc = mtod( m, struct llc *);
-       llc->llc_dsap = llc->llc_ssap = LLC_SNAP_LSAP;
-       llc->llc_control = LLC_UI;
-       bcopy( aarp_org_code, llc->llc_org_code, sizeof( aarp_org_code ));
-       llc->llc_ether_type = htons( ETHERTYPE_AARP );
-
-       bcopy( &AA_SAT( aa )->sat_addr.s_net, ea->aarp_spnet,
-               sizeof( ea->aarp_spnet ));
-       bcopy( &AA_SAT( aa )->sat_addr.s_net, ea->aarp_tpnet,
-               sizeof( ea->aarp_tpnet ));
-       ea->aarp_spnode = ea->aarp_tpnode = AA_SAT( aa )->sat_addr.s_node;
-    } else {
-#ifdef sun
-       bcopy((caddr_t)&etherbroadcastaddr, (caddr_t)&eh->ether_dhost,
-               sizeof( eh->ether_dhost ));
-#else /* sun */
-       bcopy((caddr_t)etherbroadcastaddr, (caddr_t)eh->ether_dhost,
-               sizeof( eh->ether_dhost ));
-#endif /* sun */
-#if defined( sun ) && defined( i386 )
-       eh->ether_type = htons( ETHERTYPE_AARP );
-#else /* sun && i386 */
-       eh->ether_type = ETHERTYPE_AARP;
-#endif /* sun && i386 */
-       ea->aarp_spa = ea->aarp_tpa = AA_SAT( aa )->sat_addr.s_node;
-    }
-
-#ifdef BSD4_4
-    sa.sa_len = sizeof( struct sockaddr );
-#endif /* BSD4_4 */
-    sa.sa_family = AF_UNSPEC;
-    (*ac->ac_if.if_output)(&ac->ac_if, m, &sa );
-    aa->aa_probcnt--;
-}
-
-aarp_clean()
-{
-    struct aarptab     *aat;
-    int                        i;
-
-    untimeout( aarptimer, 0 );
-    for ( i = 0, aat = aarptab; i < AARPTAB_SIZE; i++, aat++ ) {
-       if ( aat->aat_hold ) {
-           m_freem( aat->aat_hold );
-       }
-    }
-}
diff --git a/sys/netatalk/aarp.h b/sys/netatalk/aarp.h
deleted file mode 100644 (file)
index a391aae..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * $Id: aarp.h,v 1.2 2001-06-29 14:14:47 rufustfirefly Exp $
- *
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- * All Rights Reserved.
- *
- * This structure is used for both phase 1 and 2. Under phase 1
- * the net is not filled in. It is in phase 2. In both cases, the
- * hardware address length is (for some unknown reason) 4. If
- * anyone at Apple could program their way out of paper bag, it
- * would be 1 and 3 respectively for phase 1 and 2.
- */
-
-#ifndef _AARP_H
-#define _AARP_H 1
-
-union aapa {
-    u_char             ap_pa[4];
-    struct ap_node {
-       u_char          an_zero;
-       u_char          an_net[2];
-       u_char          an_node;
-    } ap_node;
-};
-
-struct ether_aarp {
-    struct arphdr      eaa_hdr;
-    u_char             aarp_sha[6];
-    union aapa         aarp_spu;
-    u_char             aarp_tha[6];
-    union aapa         aarp_tpu;
-};
-#define aarp_hrd       eaa_hdr.ar_hrd
-#define aarp_pro       eaa_hdr.ar_pro
-#define aarp_hln       eaa_hdr.ar_hln
-#define aarp_pln       eaa_hdr.ar_pln
-#define aarp_op                eaa_hdr.ar_op
-#define aarp_spa       aarp_spu.ap_node.an_node
-#define aarp_tpa       aarp_tpu.ap_node.an_node
-#define aarp_spnet     aarp_spu.ap_node.an_net
-#define aarp_tpnet     aarp_tpu.ap_node.an_net
-#define aarp_spnode    aarp_spu.ap_node.an_node
-#define aarp_tpnode    aarp_tpu.ap_node.an_node
-
-struct aarptab {
-    struct at_addr     aat_ataddr;
-    u_char             aat_enaddr[ 6 ];
-    u_char             aat_timer;
-    u_char             aat_flags;
-    struct mbuf                *aat_hold;
-};
-
-#define AARPHRD_ETHER  0x0001
-
-#define AARPOP_REQUEST 0x01
-#define AARPOP_RESPONSE        0x02
-#define AARPOP_PROBE   0x03
-
-#ifdef KERNEL
-struct aarptab         *aarptnew();
-int                    aarpprobe();
-#endif /* KERNEL */
-
-#endif /* _AARP_H */
diff --git a/sys/netatalk/at.h b/sys/netatalk/at.h
deleted file mode 100644 (file)
index f544c40..0000000
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- *
- * All Rights Reserved.  See COPYRIGHT.
- */
-
-#ifndef __AT_HEADER__
-#define __AT_HEADER__
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#ifndef NO_DDP
-
-#if defined(linux) /* pull in the linux header */
-#include <sys/socket.h>
-#include <asm/types.h>
-#include <linux/atalk.h>
-
-#ifdef HAVE_ATALK_ADDR
-#define at_addr atalk_addr
-#define netrange atalk_netrange
-#endif /* HAVE_ATALK_ADDR */
-
-#else /* linux */
-
-#include <sys/types.h>
-#include <netinet/in.h> /* so that we can deal with sun's s_net #define */
-
-#ifdef MACOSX_SERVER
-#include <netat/appletalk.h>
-#endif /* MACOSX_SERVER */
-
-/*
- * Supported protocols
- */
-#ifdef ATPROTO_DDP
-#undef ATPROTO_DDP
-#endif /* ATPROTO_DDP */
-#define ATPROTO_DDP    0
-#define ATPROTO_AARP   254
-
-/*
- * Ethernet types, for DIX.
- * These should really be in some global header file, but we can't
- * count on them being there, and it's annoying to patch system files.
- */
-#ifndef ETHERTYPE_AT
-#define ETHERTYPE_AT   0x809B          /* AppleTalk protocol */
-#endif
-#ifndef ETHERTYPE_AARP
-#define ETHERTYPE_AARP 0x80F3          /* AppleTalk ARP */
-#endif
-
-#define DDP_MAXSZ      587
-
-/*
- * If ATPORT_FIRST <= Port < ATPORT_RESERVED,
- * Port was created by a privileged process.
- * If ATPORT_RESERVED <= Port < ATPORT_LAST,
- * Port was not necessarily created by a
- * privileged process.
- */
-#define ATPORT_FIRST   1
-#define ATPORT_RESERVED        128
-#define ATPORT_LAST    254 /* 254 is reserved on ether/tokentalk networks */
-
-/*
- * AppleTalk address.
- */
-#ifndef MACOSX_SERVER
-struct at_addr {
-#ifdef s_net
-#undef s_net
-#endif /* s_net */
-    u_short    s_net;
-    u_char     s_node;
-};
-#endif /* MACOSX_SERVER */
-
-#define ATADDR_ANYNET  (u_short)0x0000
-#define ATADDR_ANYNODE (u_char)0x00
-#define ATADDR_ANYPORT (u_char)0x00
-#define ATADDR_BCAST   (u_char)0xff            /* There is no BCAST for NET */
-
-/*
- * Socket address, AppleTalk style.  We keep magic information in the 
- * zero bytes.  There are three types, NONE, CONFIG which has the phase
- * and a net range, and IFACE which has the network address of an
- * interface.  IFACE may be filled in by the client, and is filled in
- * by the kernel.
- */
-#ifndef MACOSX_SERVER
-struct sockaddr_at {
-#ifdef BSD4_4
-    u_char             sat_len;
-    u_char             sat_family;
-#else /* BSD4_4 */
-    short              sat_family;
-#endif /* BSD4_4 */
-    u_char             sat_port;
-    struct at_addr     sat_addr;
-#ifdef notdef
-    struct {
-       u_char          sh_type;
-# define SATHINT_NONE  0
-# define SATHINT_CONFIG        1
-# define SATHINT_IFACE 2
-       union {
-           char                su_zero[ 7 ];   /* XXX check size */
-           struct {
-               u_char          sr_phase;
-               u_short         sr_firstnet, sr_lastnet;
-           } su_range;
-           u_short             su_interface;
-       } sh_un;
-    } sat_hints;
-#else /* notdef */
-    char               sat_zero[ 8 ];
-#endif /* notdef */
-};
-#endif /* MACOSX_SERVER */
-
-struct netrange {
-    u_char             nr_phase;
-    u_short            nr_firstnet;
-    u_short            nr_lastnet;
-};
-
-#ifdef KERNEL
-extern struct domain   atalkdomain;
-extern struct protosw  atalksw[];
-#endif /* KERNEL */
-
-#endif /* linux */
-#endif /* NO_DDP */
-#endif /* __AT_HEADER__ */
-
diff --git a/sys/netatalk/at_control.c b/sys/netatalk/at_control.c
deleted file mode 100644 (file)
index 3cc3a1e..0000000
+++ /dev/null
@@ -1,586 +0,0 @@
-/*
- * $Id: at_control.c,v 1.2 2001-06-29 14:14:47 rufustfirefly Exp $
- *
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- * All Rights Reserved.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#ifdef ibm032
-#include <sys/dir.h>
-#endif /* ibm032 */
-#include <sys/user.h>
-#include <sys/types.h>
-#include <sys/errno.h>
-#include <sys/ioctl.h>
-#include <sys/mbuf.h>
-#ifndef _IBMR2
-#include <sys/kernel.h>
-#endif /* ! _IBMR2 */
-#include <sys/socket.h>
-#include <sys/socketvar.h>
-#include <net/if.h>
-#include <net/af.h>
-#include <net/route.h>
-#include <netinet/in.h>
-#undef s_net
-#include <netinet/if_ether.h>
-#ifdef _IBMR2
-#include <net/spl.h>
-#endif /* _IBMR2 */
-
-#include "at.h"
-#include "at_var.h"
-#include "aarp.h"
-#include "phase2.h"
-
-#ifdef BSD4_4
-# define sateqaddr(a,b)        ((a)->sat_len == (b)->sat_len && \
-                   (a)->sat_family == (b)->sat_family && \
-                   (a)->sat_addr.s_net == (b)->sat_addr.s_net && \
-                   (a)->sat_addr.s_node == (b)->sat_addr.s_node )
-#else /* BSD4_4 */
-atalk_hash( sat, hp )
-    struct sockaddr_at *sat;
-    struct afhash      *hp;
-{
-    hp->afh_nethash = sat->sat_addr.s_net;
-    hp->afh_hosthash = ( sat->sat_addr.s_net << 8 ) +
-           sat->sat_addr.s_node;
-}
-
-/*
- * Note the magic to get ifa_ifwithnet() to work without adding an
- * ifaddr entry for each net in our local range.
- */
-atalk_netmatch( sat1, sat2 )
-    struct sockaddr_at *sat1, *sat2;
-{
-    struct at_ifaddr   *aa;
-
-    for ( aa = at_ifaddr; aa; aa = aa->aa_next ) {
-       if ( AA_SAT( aa ) == sat1 ) {
-           break;
-       }
-    }
-    if ( aa ) {
-       return( ntohs( aa->aa_firstnet ) <= ntohs( sat2->sat_addr.s_net ) &&
-               ntohs( aa->aa_lastnet ) >= ntohs( sat2->sat_addr.s_net ));
-    }
-    return( sat1->sat_addr.s_net == sat2->sat_addr.s_net );
-}
-#endif /* BSD4_4 */
-
-at_control( cmd, data, ifp )
-    int                        cmd;
-    caddr_t            data;
-    struct ifnet       *ifp;
-{
-    struct ifreq       *ifr = (struct ifreq *)data;
-    struct sockaddr_at *sat;
-    struct netrange    *nr;
-#ifdef BSD4_4
-    struct at_aliasreq *ifra = (struct at_aliasreq *)data;
-    struct at_ifaddr   *aa0;
-#endif /* BSD4_4 */
-    struct at_ifaddr   *aa = 0;
-    struct mbuf                *m;
-    struct ifaddr      *ifa;
-
-    if ( ifp ) {
-       for ( aa = at_ifaddr; aa; aa = aa->aa_next ) {
-           if ( aa->aa_ifp == ifp ) break;
-       }
-    }
-
-    switch ( cmd ) {
-#ifdef BSD4_4
-    case SIOCAIFADDR:
-    case SIOCDIFADDR:
-       if ( ifra->ifra_addr.sat_family == AF_APPLETALK ) {
-           for ( ; aa; aa = aa->aa_next ) {
-               if ( aa->aa_ifp == ifp &&
-                       sateqaddr( &aa->aa_addr, &ifra->ifra_addr )) {
-                   break;
-               }
-           }
-       }
-       if ( cmd == SIOCDIFADDR && aa == 0 ) {
-           return( EADDRNOTAVAIL );
-       }
-       /*FALLTHROUGH*/
-#endif /* BSD4_4 */
-
-    case SIOCSIFADDR:
-#ifdef BSD4_4
-       /*
-        * What a great idea this is: Let's reverse the meaning of
-        * the return...
-        */
-       if ( suser( u.u_cred, &u.u_acflag )) {
-           return( EPERM );
-       }
-#else /* BSD4_4 */
-       if ( !suser()) {
-           return( EPERM );
-       }
-#endif /* BSD4_4 */
-
-       sat = satosat( &ifr->ifr_addr );
-       nr = (struct netrange *)sat->sat_zero;
-       if ( nr->nr_phase == 1 ) {
-           for ( ; aa; aa = aa->aa_next ) {
-               if ( aa->aa_ifp == ifp &&
-                       ( aa->aa_flags & AFA_PHASE2 ) == 0 ) {
-                   break;
-               }
-           }
-       } else {                /* default to phase 2 */
-           for ( ; aa; aa = aa->aa_next ) {
-               if ( aa->aa_ifp == ifp && ( aa->aa_flags & AFA_PHASE2 )) {
-                   break;
-               }
-           }
-       }
-
-       if ( ifp == 0 )
-           panic( "at_control" );
-
-       if ( aa == (struct at_ifaddr *) 0 ) {
-           m = m_getclr( M_WAIT, MT_IFADDR );
-           if ( m == (struct mbuf *)NULL ) {
-               return( ENOBUFS );
-           }
-
-           if (( aa = at_ifaddr ) != NULL ) {
-               /*
-                * Don't let the loopback be first, since the first
-                * address is the machine's default address for
-                * binding.
-                */
-               if ( at_ifaddr->aa_ifp->if_flags & IFF_LOOPBACK ) {
-                   aa = mtod( m, struct at_ifaddr *);
-                   aa->aa_next = at_ifaddr;
-                   at_ifaddr = aa;
-               } else {
-                   for ( ; aa->aa_next; aa = aa->aa_next )
-                       ;
-                   aa->aa_next = mtod( m, struct at_ifaddr *);
-               }
-           } else {
-               at_ifaddr = mtod( m, struct at_ifaddr *);
-           }
-
-           aa = mtod( m, struct at_ifaddr *);
-
-           if (( ifa = ifp->if_addrlist ) != NULL ) {
-               for ( ; ifa->ifa_next; ifa = ifa->ifa_next )
-                   ;
-               ifa->ifa_next = (struct ifaddr *)aa;
-           } else {
-               ifp->if_addrlist = (struct ifaddr *)aa;
-           }
-
-#ifdef BSD4_4
-           aa->aa_ifa.ifa_addr = (struct sockaddr *)&aa->aa_addr;
-           aa->aa_ifa.ifa_dstaddr = (struct sockaddr *)&aa->aa_addr;
-           aa->aa_ifa.ifa_netmask = (struct sockaddr *)&aa->aa_netmask;
-#endif /* BSD4_4 */
-
-           /*
-            * Set/clear the phase 2 bit.
-            */
-           if ( nr->nr_phase == 1 ) {
-               aa->aa_flags &= ~AFA_PHASE2;
-           } else {
-               aa->aa_flags |= AFA_PHASE2;
-           }
-           aa->aa_ifp = ifp;
-       } else {
-           at_scrub( ifp, aa );
-       }
-       break;
-
-    case SIOCGIFADDR :
-       sat = satosat( &ifr->ifr_addr );
-       nr = (struct netrange *)sat->sat_zero;
-       if ( nr->nr_phase == 1 ) {
-           for ( ; aa; aa = aa->aa_next ) {
-               if ( aa->aa_ifp == ifp &&
-                       ( aa->aa_flags & AFA_PHASE2 ) == 0 ) {
-                   break;
-               }
-           }
-       } else {                /* default to phase 2 */
-           for ( ; aa; aa = aa->aa_next ) {
-               if ( aa->aa_ifp == ifp && ( aa->aa_flags & AFA_PHASE2 )) {
-                   break;
-               }
-           }
-       }
-
-       if ( aa == (struct at_ifaddr *) 0 )
-           return( EADDRNOTAVAIL );
-       break;
-    }
-
-    switch ( cmd ) {
-    case SIOCGIFADDR:
-#ifdef BSD4_4
-       *(struct sockaddr_at *)&ifr->ifr_addr = aa->aa_addr;
-#else /* BSD4_4 */
-       ifr->ifr_addr = aa->aa_addr;
-#endif /* BSD4_4 */
-       break;
-
-    case SIOCSIFADDR:
-       return( at_ifinit( ifp, aa, (struct sockaddr_at *)&ifr->ifr_addr ));
-
-#ifdef BSD4_4
-    case SIOCAIFADDR:
-       if ( sateqaddr( &ifra->ifra_addr, &aa->aa_addr )) {
-           return( 0 );
-       }
-       return( at_ifinit( ifp, aa, (struct sockaddr_at *)&ifr->ifr_addr ));
-
-    case SIOCDIFADDR:
-       at_scrub( ifp, aa );
-       if (( ifa = ifp->if_addrlist ) == (struct ifaddr *)aa ) {
-           ifp->if_addrlist = ifa->ifa_next;
-       } else {
-           while ( ifa->ifa_next && ( ifa->ifa_next != (struct ifaddr *)aa )) {
-               ifa = ifa->ifa_next;
-           }
-           if ( ifa->ifa_next ) {
-               ifa->ifa_next = ((struct ifaddr *)aa)->ifa_next;
-           } else {
-               panic( "at_control" );
-           }
-       }
-
-       aa0 = aa;
-       if ( aa0 == ( aa = at_ifaddr )) {
-           at_ifaddr = aa->aa_next;
-       } else {
-           while ( aa->aa_next && ( aa->aa_next != aa0 )) {
-               aa = aa->aa_next;
-           }
-           if ( aa->aa_next ) {
-               aa->aa_next = aa0->aa_next;
-           } else {
-               panic( "at_control" );
-           }
-       }
-       m_free( dtom( aa0 ));
-       break;
-#endif /* BSD4_4 */
-
-    default:
-       if ( ifp == 0 || ifp->if_ioctl == 0 )
-           return( EOPNOTSUPP );
-       return( (*ifp->if_ioctl)( ifp, cmd, data ));
-    }
-    return( 0 );
-}
-
-at_scrub( ifp, aa )
-    struct ifnet       *ifp;
-    struct at_ifaddr   *aa;
-{
-#ifndef BSD4_4
-    struct sockaddr_at netsat;
-    int                        error;
-    u_short            net;
-#endif /* ! BSD4_4 */
-
-    if ( aa->aa_flags & AFA_ROUTE ) {
-#ifdef BSD4_4
-       if (( error = rtinit( &(aa->aa_ifa), RTM_DELETE,
-               ( ifp->if_flags & IFF_LOOPBACK ) ? RTF_HOST : 0 )) != 0 ) {
-           return( error );
-       }
-       aa->aa_ifa.ifa_flags &= ~IFA_ROUTE;
-#else /* BSD4_4 */
-       if ( ifp->if_flags & IFF_LOOPBACK ) {
-           rtinit( &aa->aa_addr, &aa->aa_addr, SIOCDELRT, RTF_HOST );
-       } else {
-           bzero( &netsat, sizeof( struct sockaddr_at ));
-           netsat.sat_family = AF_APPLETALK;
-           netsat.sat_addr.s_node = ATADDR_ANYNODE;
-
-           /*
-            * If the range is the full 0-fffe range, just use
-            * the default route.
-            */
-           if ( aa->aa_firstnet == htons( 0x0000 ) &&
-                   aa->aa_lastnet == htons( 0xfffe )) {
-               netsat.sat_addr.s_net = 0;
-               rtinit((struct sockaddr *)&netsat, &aa->aa_addr,
-                       (int)SIOCDELRT, 0 );
-           } else {
-               for ( net = ntohs( aa->aa_firstnet );
-                       net <= ntohs( aa->aa_lastnet ); net++ ) {
-                   netsat.sat_addr.s_net = htons( net );
-                   rtinit((struct sockaddr *)&netsat, &aa->aa_addr,
-                           (int)SIOCDELRT, 0 );
-               }
-           }
-       }
-#endif /* BSD4_4 */
-       aa->aa_flags &= ~AFA_ROUTE;
-    }
-    return( 0 );
-}
-
-extern struct timeval  time;
-
-at_ifinit( ifp, aa, sat )
-    struct ifnet       *ifp;
-    struct at_ifaddr   *aa;
-    struct sockaddr_at *sat;
-{
-    struct netrange    nr, onr;
-#ifdef BSD4_4
-    struct sockaddr_at oldaddr;
-#else /* BSD4_4 */
-    struct sockaddr    oldaddr;
-#endif /* BSD4_4 */
-    struct sockaddr_at netaddr;
-    int                        s = splimp(), error = 0, i, j, netinc, nodeinc, nnets;
-    u_short            net;
-
-    oldaddr = aa->aa_addr;
-    bzero( AA_SAT( aa ), sizeof( struct sockaddr_at ));
-    bcopy( sat->sat_zero, &nr, sizeof( struct netrange ));
-    nnets = ntohs( nr.nr_lastnet ) - ntohs( nr.nr_firstnet ) + 1;
-
-    onr.nr_firstnet = aa->aa_firstnet;
-    onr.nr_lastnet = aa->aa_lastnet;
-    aa->aa_firstnet = nr.nr_firstnet;
-    aa->aa_lastnet = nr.nr_lastnet;
-
-    /*
-     * We could eliminate the need for a second phase 1 probe (post
-     * autoconf) if we check whether we're resetting the node. Note
-     * that phase 1 probes use only nodes, not net.node pairs.  Under
-     * phase 2, both the net and node must be the same.
-     */
-    if ( ifp->if_flags & IFF_LOOPBACK ) {
-#ifdef BSD4_4
-       AA_SAT( aa )->sat_len = sat->sat_len;
-#endif /* BSD4_4 */
-       AA_SAT( aa )->sat_family = AF_APPLETALK;
-       AA_SAT( aa )->sat_addr.s_net = sat->sat_addr.s_net;
-       AA_SAT( aa )->sat_addr.s_node = sat->sat_addr.s_node;
-    } else {
-       aa->aa_flags |= AFA_PROBING;
-       AA_SAT( aa )->sat_family = AF_APPLETALK;
-       if ( aa->aa_flags & AFA_PHASE2 ) {
-           if ( sat->sat_addr.s_net == ATADDR_ANYNET ) {
-               if ( nnets != 1 ) {
-                   net = ntohs( nr.nr_firstnet ) + time.tv_sec % ( nnets - 1 );
-               } else {
-                   net = ntohs( nr.nr_firstnet );
-               }
-           } else {
-               if ( ntohs( sat->sat_addr.s_net ) < ntohs( nr.nr_firstnet ) ||
-                       ntohs( sat->sat_addr.s_net ) > ntohs( nr.nr_lastnet )) {
-                   aa->aa_addr = oldaddr;
-                   aa->aa_firstnet = onr.nr_firstnet;
-                   aa->aa_lastnet = onr.nr_lastnet;
-                   return( EINVAL );
-               }
-               net = ntohs( sat->sat_addr.s_net );
-           }
-       } else {
-           net = ntohs( sat->sat_addr.s_net );
-       }
-
-       if ( sat->sat_addr.s_node == ATADDR_ANYNODE ) {
-           AA_SAT( aa )->sat_addr.s_node = time.tv_sec;
-       } else {
-           AA_SAT( aa )->sat_addr.s_node = sat->sat_addr.s_node;
-       }
-
-       for ( i = nnets, netinc = 1; i > 0; net = ntohs( nr.nr_firstnet ) +
-               (( net - ntohs( nr.nr_firstnet ) + netinc ) % nnets ), i-- ) {
-           AA_SAT( aa )->sat_addr.s_net = htons( net );
-
-           for ( j = 0, nodeinc = time.tv_sec | 1; j < 256;
-                   j++, AA_SAT( aa )->sat_addr.s_node += nodeinc ) {
-               if ( AA_SAT( aa )->sat_addr.s_node > 253 ||
-                       AA_SAT( aa )->sat_addr.s_node < 1 ) {
-                   continue;
-               }
-               aa->aa_probcnt = 10;
-               timeout( aarpprobe, (caddr_t)ifp, hz / 5 );
-               splx( s );
-               if ( sleep( aa, PSLEP|PCATCH )) {
-                   printf( "at_ifinit why did this happen?!\n" );
-                   aa->aa_addr = oldaddr;
-                   aa->aa_firstnet = onr.nr_firstnet;
-                   aa->aa_lastnet = onr.nr_lastnet;
-                   return( EINTR );
-               }
-               s = splimp();
-               if (( aa->aa_flags & AFA_PROBING ) == 0 ) {
-                   break;
-               }
-           }
-           if (( aa->aa_flags & AFA_PROBING ) == 0 ) {
-               break;
-           }
-           /* reset node for next network */
-           AA_SAT( aa )->sat_addr.s_node = time.tv_sec;
-       }
-
-       if ( aa->aa_flags & AFA_PROBING ) {
-           aa->aa_addr = oldaddr;
-           aa->aa_firstnet = onr.nr_firstnet;
-           aa->aa_lastnet = onr.nr_lastnet;
-           splx( s );
-           return( EADDRINUSE );
-       }
-    }
-
-    if ( ifp->if_ioctl &&
-           ( error = (*ifp->if_ioctl)( ifp, SIOCSIFADDR, aa ))) {
-       splx( s );
-       aa->aa_addr = oldaddr;
-       aa->aa_firstnet = onr.nr_firstnet;
-       aa->aa_lastnet = onr.nr_lastnet;
-       return( error );
-    }
-
-#ifdef BSD4_4
-    aa->aa_netmask.sat_len = 6;
-    aa->aa_netmask.sat_family = AF_APPLETALK;
-    aa->aa_netmask.sat_addr.s_net = 0xffff;
-    aa->aa_netmask.sat_addr.s_node = 0;
-#endif /* BSD4_4 */
-
-    if ( ifp->if_flags & IFF_LOOPBACK ) {
-#ifndef BSD4_4
-       rtinit( &aa->aa_addr, &aa->aa_addr, (int)SIOCADDRT,
-               RTF_HOST|RTF_UP );
-#else /* ! BSD4_4 */
-       error = rtinit( &(aa->aa_ifa), (int)RTM_ADD, RTF_HOST|RTF_UP );
-#endif /* ! BSD4_4 */
-    } else {
-#ifndef BSD4_4
-       /*
-        * rtrequest looks for point-to-point links first. The
-        * broadaddr is in the same spot as the destaddr. So, if
-        * ATADDR_ANYNET is 0, and we don't fill in the broadaddr, we
-        * get 0.0 routed out the ether interface.  So, initialize the
-        * broadaddr, even tho we don't use it.
-        *
-        * We *could* use the broadaddr field to reduce some of the
-        * sockaddr_at overloading that we've done.  E.g. Just send
-        * to INTERFACE-NET.255, and have the kernel reroute that
-        * to broadaddr, which would be 0.255 for phase 2 interfaces,
-        * and IFACE-NET.255 for phase 1 interfaces.
-        */
-       ((struct sockaddr_at *)&aa->aa_broadaddr)->sat_addr.s_net =
-               sat->sat_addr.s_net;
-       ((struct sockaddr_at *)&aa->aa_broadaddr)->sat_addr.s_node =
-               ATADDR_BCAST;
-
-       bzero( &netaddr, sizeof( struct sockaddr_at ));
-       netaddr.sat_family = AF_APPLETALK;
-       netaddr.sat_addr.s_node = ATADDR_ANYNODE;
-       if (( aa->aa_flags & AFA_PHASE2 ) == 0 ) {
-           netaddr.sat_addr.s_net = AA_SAT( aa )->sat_addr.s_net;
-           rtinit((struct sockaddr *)&netaddr, &aa->aa_addr,
-                   (int)SIOCADDRT, RTF_UP );
-       } else {
-           /*
-            * If the range is the full 0-fffe range, just use
-            * the default route.
-            */
-           if ( aa->aa_firstnet == htons( 0x0000 ) &&
-                   aa->aa_lastnet == htons( 0xfffe )) {
-               netaddr.sat_addr.s_net = 0;
-               rtinit((struct sockaddr *)&netaddr, &aa->aa_addr,
-                       (int)SIOCADDRT, RTF_UP );
-           } else {
-               for ( net = ntohs( aa->aa_firstnet );
-                       net <= ntohs( aa->aa_lastnet ); net++ ) {
-                   netaddr.sat_addr.s_net = htons( net );
-                   rtinit((struct sockaddr *)&netaddr, &aa->aa_addr,
-                           (int)SIOCADDRT, RTF_UP );
-               }
-           }
-       }
-#else /* ! BSD4_4 */
-       error = rtinit( &(aa->aa_ifa), (int)RTM_ADD, RTF_UP );
-#endif /* ! BSD4_4 */
-    }
-    if ( error ) {
-       aa->aa_addr = oldaddr;
-       aa->aa_firstnet = onr.nr_firstnet;
-       aa->aa_lastnet = onr.nr_lastnet;
-       splx( s );
-       return( error );
-    }
-
-#ifdef BSD4_4
-    aa->aa_ifa.ifa_flags |= IFA_ROUTE;
-#endif /* BSD4_4 */
-    aa->aa_flags |= AFA_ROUTE;
-    splx( s );
-    return( 0 );
-}
-
-at_broadcast( sat )
-    struct sockaddr_at *sat;
-{
-    struct at_ifaddr   *aa;
-
-    if ( sat->sat_addr.s_node != ATADDR_BCAST ) {
-       return( 0 );
-    }
-    if ( sat->sat_addr.s_net == 0 ) {
-       return( 1 );
-    } else {
-       for ( aa = at_ifaddr; aa; aa = aa->aa_next ) {
-           if (( aa->aa_ifp->if_flags & IFF_BROADCAST ) &&
-                ( ntohs( sat->sat_addr.s_net ) >= ntohs( aa->aa_firstnet ) &&
-                ntohs( sat->sat_addr.s_net ) <= ntohs( aa->aa_lastnet ))) {
-               return( 1 );
-           }
-       }
-    }
-    return( 0 );
-}
-
-aa_clean()
-{
-    struct at_ifaddr   *aa;
-    struct ifaddr      *ifa;
-    struct ifnet       *ifp;
-
-    while ( aa = at_ifaddr ) {
-       ifp = aa->aa_ifp;
-       at_scrub( ifp, aa );
-       at_ifaddr = aa->aa_next;
-       if (( ifa = ifp->if_addrlist ) == (struct ifaddr *)aa ) {
-           ifp->if_addrlist = ifa->ifa_next;
-       } else {
-           while ( ifa->ifa_next &&
-                   ( ifa->ifa_next != (struct ifaddr *)aa )) {
-               ifa = ifa->ifa_next;
-           }
-           if ( ifa->ifa_next ) {
-               ifa->ifa_next = ((struct ifaddr *)aa)->ifa_next;
-           } else {
-               panic( "at_entry" );
-           }
-       }
-    }
-}
diff --git a/sys/netatalk/at_proto.c b/sys/netatalk/at_proto.c
deleted file mode 100644 (file)
index 21aa36a..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * $Id: at_proto.c,v 1.2 2001-06-29 14:14:47 rufustfirefly Exp $
- *
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- *
- * All Rights Reserved.  See COPYRIGHT.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <sys/protosw.h>
-#include <sys/domain.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-
-#include "at.h"
-
-extern int             ddp_usrreq();
-extern int             ddp_output();
-extern int             ddp_init();
-
-#ifdef ultrix
-extern int             ddp_ifoutput();
-extern int             ddp_ifinput();
-extern int             ddp_ifioctl();
-#endif /* ultrix */
-
-struct protosw         atalksw[] = {
-    {
-       /* Identifiers */
-       SOCK_DGRAM,     &atalkdomain,   ATPROTO_DDP,    PR_ATOMIC|PR_ADDR,
-       /*
-        * protocol-protocol interface.
-        * fields are pr_input, pr_output, pr_ctlinput, and pr_ctloutput.
-        * pr_input can be called from the udp protocol stack for iptalk
-        * packets bound for a local socket.
-        * pr_output can be used by higher level appletalk protocols, should
-        * they be included in the kernel.
-        */
-       0,              ddp_output,     0,              0,
-       /* socket-protocol interface. */
-       ddp_usrreq,
-       /* utility routines. */
-       ddp_init,       0,              0,              0,
-#ifdef ultrix
-       /* interface hooks */
-       ddp_ifoutput,   ddp_ifinput,    ddp_ifioctl,    0,
-#endif /* ultrix */
-    },
-};
-
-struct domain          atalkdomain = {
-    AF_APPLETALK,      "appletalk",    0,      0,      0,      atalksw,
-    &atalksw[ sizeof( atalksw ) / sizeof( atalksw[ 0 ] ) ]
-};
diff --git a/sys/netatalk/at_var.h b/sys/netatalk/at_var.h
deleted file mode 100644 (file)
index 87fe44a..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * $Id: at_var.h,v 1.2 2001-06-29 14:14:47 rufustfirefly Exp $
- *
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- *
- * All Rights Reserved.  See COPYRIGHT.
- */
-
-#ifndef _ATVAR_H
-#define _ATVAR_H 1
-
-/*
- * For phase2, we need to keep not only our address on an interface,
- * but also the legal networks on the interface.
- */
-struct at_ifaddr {
-    struct ifaddr      aa_ifa;
-# define aa_ifp                        aa_ifa.ifa_ifp
-#ifdef BSD4_4
-    struct sockaddr_at aa_addr;
-    struct sockaddr_at aa_broadaddr;
-    struct sockaddr_at aa_netmask;
-#else /* BSD4_4 */
-# define aa_addr               aa_ifa.ifa_addr
-# define aa_broadaddr          aa_ifa.ifa_broadaddr
-# define aa_dstaddr            aa_ifa.ifa_dstaddr
-#endif /* BSD4_4 */
-    int                        aa_flags;
-    u_short            aa_firstnet, aa_lastnet;
-    int                        aa_probcnt;
-    struct at_ifaddr   *aa_next;
-};
-
-#ifdef BSD4_4
-struct at_aliasreq {
-       char    ifra_name[IFNAMSIZ];            /* if name, e.g. "en0" */
-       struct  sockaddr_at ifra_addr;
-       struct  sockaddr_at ifra_broadaddr;
-#define ifra_dstaddr ifra_broadaddr
-       struct  sockaddr_at ifra_mask;
-};
-#endif /* BSD4_4 */
-
-#define AA_SAT(aa) \
-    ((struct sockaddr_at *)&((struct at_ifaddr *)(aa))->aa_addr)
-#define satosat(sa)    ((struct sockaddr_at *)(sa))
-
-#define AFA_ROUTE      0x0001
-#define AFA_PROBING    0x0002
-#define AFA_PHASE2     0x0004
-
-#ifdef KERNEL
-struct at_ifaddr       *at_ifaddr;
-struct ifqueue         atintrq1, atintrq2;
-int                    atdebug;
-#endif /* KERNEL */
-
-#endif /* _ATVAR_H */
diff --git a/sys/netatalk/ddp.h b/sys/netatalk/ddp.h
deleted file mode 100644 (file)
index 4388386..0000000
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * $Id: ddp.h,v 1.2 2001-06-29 14:14:47 rufustfirefly Exp $
- *
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- * All Rights Reserved. See COPYRIGHT.
- *
- */
-
-/*
- * <-1byte(8bits) ->
- * +---------------+
- * | 0 | hopc  |len|
- * +---------------+
- * | len (cont)    |
- * +---------------+
- * |               |
- * +- DDP csum    -+
- * |               |
- * +---------------+
- * |               |
- * +- Dest NET    -+
- * |               |
- * +---------------+
- * |               |
- * +- Src NET     -+
- * |               |
- * +---------------+
- * | Dest NODE     |
- * +---------------+
- * | Src NODE      |
- * +---------------+
- * | Dest PORT     |
- * +---------------+
- * | Src PORT      |
- * +---------------+
- *
- * On Apples, there is also a ddp_type field, after src_port. However,
- * under this unix implementation, user level processes need to be able
- * to set the ddp_type. In later revisions, the ddp_type may only be
- * available in a raw_appletalk interface.
- */
-
-#ifndef _NETATALK_DDP_H
-#define _NETATALK_DDP_H 1
-
-#include <netatalk/endian.h>
-
-struct elaphdr {
-    u_char     el_dnode;
-    u_char     el_snode;
-    u_char     el_type;
-};
-
-#define        SZ_ELAPHDR      3
-
-#define ELAP_DDPSHORT  0x01
-#define ELAP_DDPEXTEND 0x02
-
-/*
- * Extended DDP header. Includes sickness for dealing with arbitrary
- * bitfields on a little-endian arch.
- */
-struct ddpehdr {
-    union {
-       struct {
-#if BYTE_ORDER == BIG_ENDIAN
-    unsigned           dub_pad:2;
-    unsigned           dub_hops:4;
-    unsigned           dub_len:10;
-    unsigned           dub_sum:16;
-#else /* BYTE_ORDER == BIG_ENDIAN */
-#if BYTE_ORDER == LITTLE_ENDIAN
-    unsigned           dub_sum:16;
-    unsigned           dub_len:10;
-    unsigned           dub_hops:4;
-    unsigned           dub_pad:2;
-#else /* BYTE_ORDER == LITTLE_ENDIAN */
-    OOPS!
-#endif /* BYTE_ORDER == LITTLE_ENDIAN */
-#endif /* BYTE_ORDER == BIG_ENDIAN */
-       } du_bits;
-       unsigned        du_bytes;
-    } deh_u;
-#define deh_pad                deh_u.du_bits.dub_pad
-#define deh_hops       deh_u.du_bits.dub_hops
-#define deh_len                deh_u.du_bits.dub_len
-#define deh_sum                deh_u.du_bits.dub_sum
-#define deh_bytes      deh_u.du_bytes
-    u_short            deh_dnet;
-    u_short            deh_snet;
-    u_char             deh_dnode;
-    u_char             deh_snode;
-    u_char             deh_dport;
-    u_char             deh_sport;
-};
-
-#define SZ_DDPEHDR      12
-
-#define DDP_MAXHOPS    15
-
-struct ddpshdr {
-    union {
-       struct {
-#if BYTE_ORDER == BIG_ENDIAN
-    unsigned           dub_pad:6;
-    unsigned           dub_len:10;
-    unsigned           dub_dport:8;
-    unsigned           dub_sport:8;
-#endif /* BYTE_ORDER == BIG_ENDIAN */
-#if BYTE_ORDER == LITTLE_ENDIAN
-    unsigned           dub_sport:8;
-    unsigned           dub_dport:8;
-    unsigned           dub_len:10;
-    unsigned           dub_pad:6;
-#endif /* BYTE_ORDER == LITTLE_ENDIAN */
-       } du_bits;
-       unsigned        du_bytes;
-    } dsh_u;
-#define dsh_pad                dsh_u.du_bits.dub_pad
-#define dsh_len                dsh_u.du_bits.dub_len
-#define dsh_dport      dsh_u.du_bits.dub_dport
-#define dsh_sport      dsh_u.du_bits.dub_sport
-#define dsh_bytes      dsh_u.du_bytes
-};
-#define SZ_DDPSHDR      4
-
-#endif /* netatalk/ddp.h */
diff --git a/sys/netatalk/ddp_input.c b/sys/netatalk/ddp_input.c
deleted file mode 100644 (file)
index 74501f9..0000000
+++ /dev/null
@@ -1,407 +0,0 @@
-/*
- * $Id: ddp_input.c,v 1.4 2002-01-04 04:45:48 sibaz Exp $
- *
- * Copyright (c) 1990,1994 Regents of The University of Michigan.
- * All Rights Reserved.  See COPYRIGHT.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/mbuf.h>
-#include <sys/socket.h>
-#include <sys/socketvar.h>
-#include <atalk/logger.h>
-#include <net/if.h>
-#include <net/route.h>
-#ifdef _IBMR2
-#include <net/spl.h>
-#endif /* _IBMR2 */
-
-#include "at.h"
-#include "at_var.h"
-#include "endian.h"
-#include "ddp.h"
-#include "ddp_var.h"
-
-int            ddp_forward = 1;
-int            ddp_firewall = 0;
-extern int     ddp_cksum;
-extern u_short at_cksum();
-
-/*
- * Could probably merge these two code segments a little better...
- */
-atintr()
-{
-    struct elaphdr     *elhp, elh;
-    struct ifnet       *ifp;
-    struct mbuf                *m;
-    struct at_ifaddr   *aa;
-    int                        s;
-
-    for (;;) {
-#ifndef _IBMR2
-       s = splimp();
-#endif /* ! _IBMR2 */
-
-#ifdef BSD4_4
-       IF_DEQUEUE( &atintrq2, m );
-#else /* BSD4_4 */
-       IF_DEQUEUEIF( &atintrq2, m, ifp );
-#endif /* BSD4_4 */
-
-#ifndef _IBMR2
-       splx( s );
-#endif /* ! _IBMR2 */
-
-       if ( m == 0 ) {                 /* no more queued packets */
-           break;
-       }
-
-#ifdef BSD4_4
-       ifp = m->m_pkthdr.rcvif;
-#endif /* BSD4_4 */
-       for ( aa = at_ifaddr; aa; aa = aa->aa_next ) {
-           if ( aa->aa_ifp == ifp && ( aa->aa_flags & AFA_PHASE2 )) {
-               break;
-           }
-       }
-       if ( aa == NULL ) {             /* ifp not an appletalk interface */
-           m_freem( m );
-           continue;
-       }
-
-       ddp_input( m, ifp, (struct elaphdr *)NULL, 2 );
-    }
-
-    for (;;) {
-#ifndef _IBMR2
-       s = splimp();
-#endif /* ! _IBMR2 */
-
-#ifdef BSD4_4
-       IF_DEQUEUE( &atintrq1, m );
-#else /* BSD4_4 */
-       IF_DEQUEUEIF( &atintrq1, m, ifp );
-#endif /* BSD4_4 */
-
-#ifndef _IBMR2
-       splx( s );
-#endif /* ! _IBMR2 */
-
-       if ( m == 0 ) {                 /* no more queued packets */
-           break;
-       }
-
-#ifdef BSD4_4
-       ifp = m->m_pkthdr.rcvif;
-#endif /* BSD4_4 */
-       for ( aa = at_ifaddr; aa; aa = aa->aa_next ) {
-           if ( aa->aa_ifp == ifp && ( aa->aa_flags & AFA_PHASE2 ) == 0 ) {
-               break;
-           }
-       }
-       if ( aa == NULL ) {             /* ifp not an appletalk interface */
-           m_freem( m );
-           continue;
-       }
-
-       if ( m->m_len < SZ_ELAPHDR &&
-               (( m = m_pullup( m, SZ_ELAPHDR )) == 0 )) {
-           ddpstat.ddps_tooshort++;
-           continue;
-       }
-
-       elhp = mtod( m, struct elaphdr *);
-       m_adj( m, SZ_ELAPHDR );
-
-       if ( elhp->el_type == ELAP_DDPEXTEND ) {
-           ddp_input( m, ifp, (struct elaphdr *)NULL, 1 );
-       } else {
-           bcopy((caddr_t)elhp, (caddr_t)&elh, SZ_ELAPHDR );
-           ddp_input( m, ifp, &elh, 1 );
-       }
-    }
-    return;
-}
-
-struct route   forwro;
-
-ddp_input( m, ifp, elh, phase )
-    struct mbuf                *m;
-    struct ifnet       *ifp;
-    struct elaphdr     *elh;
-    int                        phase;
-{
-    struct sockaddr_at from, to;
-    struct ddpshdr     *dsh, ddps;
-    struct at_ifaddr   *aa;
-    struct ddpehdr     *deh, ddpe;
-#ifndef BSD4_4
-    struct mbuf                *mp;
-#endif /* BSD4_4 */
-    struct ddpcb       *ddp;
-    int                        dlen, mlen;
-    u_short            cksum;
-
-    bzero( (caddr_t)&from, sizeof( struct sockaddr_at ));
-    if ( elh ) {
-       ddpstat.ddps_short++;
-
-       if ( m->m_len < sizeof( struct ddpshdr ) &&
-               (( m = m_pullup( m, sizeof( struct ddpshdr ))) == 0 )) {
-           ddpstat.ddps_tooshort++;
-           return;
-       }
-
-       dsh = mtod( m, struct ddpshdr *);
-       bcopy( (caddr_t)dsh, (caddr_t)&ddps, sizeof( struct ddpshdr ));
-       ddps.dsh_bytes = ntohl( ddps.dsh_bytes );
-       dlen = ddps.dsh_len;
-
-       to.sat_addr.s_net = 0;
-       to.sat_addr.s_node = elh->el_dnode;
-       to.sat_port = ddps.dsh_dport;
-       from.sat_addr.s_net = 0;
-       from.sat_addr.s_node = elh->el_snode;
-       from.sat_port = ddps.dsh_sport;
-
-       for ( aa = at_ifaddr; aa; aa = aa->aa_next ) {
-           if ( aa->aa_ifp == ifp && ( aa->aa_flags & AFA_PHASE2 ) == 0 &&
-                   ( AA_SAT( aa )->sat_addr.s_node == to.sat_addr.s_node ||
-                   to.sat_addr.s_node == ATADDR_BCAST )) {
-               break;
-           }
-       }
-       if ( aa == NULL ) {
-           m_freem( m );
-           return;
-       }
-    } else {
-       ddpstat.ddps_long++;
-
-       if ( m->m_len < sizeof( struct ddpehdr ) &&
-               (( m = m_pullup( m, sizeof( struct ddpehdr ))) == 0 )) {
-           ddpstat.ddps_tooshort++;
-           return;
-       }
-
-       deh = mtod( m, struct ddpehdr *);
-       bcopy( (caddr_t)deh, (caddr_t)&ddpe, sizeof( struct ddpehdr ));
-       ddpe.deh_bytes = ntohl( ddpe.deh_bytes );
-       dlen = ddpe.deh_len;
-
-       if (( cksum = ddpe.deh_sum ) == 0 ) {
-           ddpstat.ddps_nosum++;
-       }
-
-       from.sat_addr.s_net = ddpe.deh_snet;
-       from.sat_addr.s_node = ddpe.deh_snode;
-       from.sat_port = ddpe.deh_sport;
-       to.sat_addr.s_net = ddpe.deh_dnet;
-       to.sat_addr.s_node = ddpe.deh_dnode;
-       to.sat_port = ddpe.deh_dport;
-
-       if ( to.sat_addr.s_net == 0 ) {
-           for ( aa = at_ifaddr; aa; aa = aa->aa_next ) {
-               if ( phase == 1 && ( aa->aa_flags & AFA_PHASE2 )) {
-                   continue;
-               }
-               if ( phase == 2 && ( aa->aa_flags & AFA_PHASE2 ) == 0 ) {
-                   continue;
-               }
-               if ( aa->aa_ifp == ifp &&
-                       ( AA_SAT( aa )->sat_addr.s_node == to.sat_addr.s_node ||
-                       to.sat_addr.s_node == ATADDR_BCAST ||
-                       ( ifp->if_flags & IFF_LOOPBACK ))) {
-                   break;
-               }
-           }
-       } else {
-           for ( aa = at_ifaddr; aa; aa = aa->aa_next ) {
-               if ( to.sat_addr.s_net == aa->aa_firstnet &&
-                       to.sat_addr.s_node == 0 ) {
-                   break;
-               }
-               if (( ntohs( to.sat_addr.s_net ) < ntohs( aa->aa_firstnet ) ||
-                       ntohs( to.sat_addr.s_net ) > ntohs( aa->aa_lastnet )) &&
-                       ( ntohs( to.sat_addr.s_net ) < 0xff00 ||
-                       ntohs( to.sat_addr.s_net ) > 0xfffe)) {
-                   continue;
-               }
-               if ( to.sat_addr.s_node != AA_SAT( aa )->sat_addr.s_node &&
-                       to.sat_addr.s_node != ATADDR_BCAST ) {
-                   continue;
-               }
-               break;
-           }
-       }
-    }
-
-    /*
-     * Adjust the length, removing any padding that may have been added
-     * at a link layer.  We do this before we attempt to forward a packet,
-     * possibly on a different media.
-     */
-#ifdef BSD4_4
-    mlen = m->m_pkthdr.len;
-#else /* BSD4_4 */
-    for ( mlen = 0, mp = m; mp; mp = mp->m_next ) {
-       mlen += mp->m_len;
-    }
-#endif /* BSD4_4 */
-    if ( mlen < dlen ) {
-       ddpstat.ddps_toosmall++;
-       m_freem( m );
-       return;
-    }
-    if ( mlen > dlen ) {
-       m_adj( m, dlen - mlen );
-    }
-
-    /*
-     * XXX Should we deliver broadcasts locally, also, or rely on the
-     * link layer to give us a copy?  For the moment, the latter.
-     */
-    if ( aa == NULL || ( to.sat_addr.s_node == ATADDR_BCAST &&
-           aa->aa_ifp != ifp && ( ifp->if_flags & IFF_LOOPBACK ) == 0 )) {
-       if ( ddp_forward == 0 ) {
-           m_freem( m );
-           return;
-       }
-       if ( forwro.ro_rt && ( satosat( &forwro.ro_dst )->sat_addr.s_net !=
-               to.sat_addr.s_net ||
-               satosat( &forwro.ro_dst )->sat_addr.s_node !=
-               to.sat_addr.s_node )) {
-#ifdef ultrix
-           rtfree( forwro.ro_rt );
-#else /* ultrix */
-           RTFREE( forwro.ro_rt );
-#endif /* ultrix */
-           forwro.ro_rt = (struct rtentry *)0;
-       }
-       if ( forwro.ro_rt == (struct rtentry *)0 ||
-            forwro.ro_rt->rt_ifp == (struct ifnet *)0 ) {
-#ifdef BSD4_4
-           forwro.ro_dst.sa_len = sizeof( struct sockaddr_at );
-#endif /* BSD4_4 */
-           forwro.ro_dst.sa_family = AF_APPLETALK;
-           satosat( &forwro.ro_dst )->sat_addr.s_net = to.sat_addr.s_net;
-           satosat( &forwro.ro_dst )->sat_addr.s_node = to.sat_addr.s_node;
-           rtalloc( &forwro );
-       }
-
-       if ( to.sat_addr.s_net != satosat( &forwro.ro_dst )->sat_addr.s_net &&
-               ddpe.deh_hops == DDP_MAXHOPS ) {
-           m_freem( m );
-           return;
-       }
-
-       if ( ddp_firewall &&
-               ( forwro.ro_rt == NULL || ( forwro.ro_rt->rt_ifp != ifp &&
-               forwro.ro_rt->rt_ifp != at_ifaddr->aa_ifp ))) {
-           m_freem( m );
-           return;
-       }
-
-       ddpe.deh_hops++;
-       ddpe.deh_bytes = htonl( ddpe.deh_bytes );
-       bcopy( (caddr_t)&ddpe, (caddr_t)deh, sizeof( u_short ));
-       if ( ddp_route( m, &forwro )) {
-           ddpstat.ddps_cantforward++;
-       } else {
-           ddpstat.ddps_forward++;
-       }
-       return;
-    }
-
-#ifdef BSD4_4
-    from.sat_len = sizeof( struct sockaddr_at );
-#endif /* BSD4_4 */
-    from.sat_family = AF_APPLETALK;
-
-    if ( elh ) {
-       m_adj( m, sizeof( struct ddpshdr ));
-    } else {
-       if ( ddp_cksum && cksum && cksum != at_cksum( m, sizeof( int ))) {
-           ddpstat.ddps_badsum++;
-           m_freem( m );
-           return;
-       }
-       m_adj( m, sizeof( struct ddpehdr ));
-    }
-
-    if (( ddp = ddp_search( &from, &to, aa )) == NULL ) {
-       m_freem( m );
-       return;
-    }
-
-    if ( sbappendaddr( &ddp->ddp_socket->so_rcv, (struct sockaddr *)&from,
-           m, (struct mbuf *)0 ) == 0 ) {
-       ddpstat.ddps_nosockspace++;
-       m_freem( m );
-       return;
-    }
-    sorwakeup( ddp->ddp_socket );
-}
-
-m_printm( m )
-    struct mbuf        *m;
-{
-    for (; m; m = m->m_next ) {
-       bprint( mtod( m, char * ), m->m_len );
-    }
-}
-
-#define BPXLEN 48
-#define BPALEN 16
-#include <ctype.h>
-char   hexdig[] = "0123456789ABCDEF";
-
-bprint( data, len )
-    char       *data;
-    int                len;
-{
-    char       xout[ BPXLEN ], aout[ BPALEN ];
-    int                i = 0;
-
-    bzero( xout, BPXLEN );
-    bzero( aout, BPALEN );
-
-    for ( ;; ) {
-       if ( len < 1 ) {
-           if ( i != 0 ) {
-               printf( "%s\t%s\n", xout, aout );
-           }
-           printf( "%s\n", "(end)" );
-           break;
-       }
-
-       xout[ (i*3) ] = hexdig[ ( *data & 0xf0 ) >> 4 ];
-       xout[ (i*3) + 1 ] = hexdig[ *data & 0x0f ];
-
-       if ( (u_char)*data < 0x7f && (u_char)*data > 0x20 ) {
-           aout[ i ] = *data;
-       } else {
-           aout[ i ] = '.';
-       }
-
-       xout[ (i*3) + 2 ] = ' ';
-
-       i++;
-       len--;
-       data++;
-
-       if ( i > BPALEN - 2 ) {
-           printf( "%s\t%s\n", xout, aout );
-           bzero( xout, BPXLEN );
-           bzero( aout, BPALEN );
-           i = 0;
-           continue;
-       }
-    }
-}
diff --git a/sys/netatalk/ddp_output.c b/sys/netatalk/ddp_output.c
deleted file mode 100644 (file)
index 75fe9cb..0000000
+++ /dev/null
@@ -1,267 +0,0 @@
-/*
- * $Id: ddp_output.c,v 1.4 2002-01-04 04:45:49 sibaz Exp $
- *
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- * All Rights Reserved. See COPYRIGHT.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/mbuf.h>
-#include <sys/socket.h>
-#include <sys/errno.h>
-#include <atalk/logger.h>
-
-#include <net/if.h>
-#include <net/route.h>
-
-#include <netinet/in.h>
-#undef s_net
-#include <netinet/if_ether.h>
-
-#include "at.h"
-#include "at_var.h"
-#include "endian.h"
-#include "ddp.h"
-#include "ddp_var.h"
-
-u_short        at_cksum();
-int    ddp_cksum = 1;
-
-ddp_output( ddp, m )
-    struct ddpcb       *ddp;
-    struct mbuf                *m;
-{
-#ifndef BSD4_4
-    struct mbuf                *m0;
-    int                        len;
-#endif /* ! BSD4_4 */
-    struct ifnet       *ifp;
-    struct at_ifaddr   *aa = NULL;
-    struct ddpehdr     *deh;
-    u_short            net;
-
-#ifdef BSD4_4
-    M_PREPEND( m, sizeof( struct ddpehdr ), M_WAIT );
-#else /* BSD4_4 */
-    for ( len = 0, m0 = m; m; m = m->m_next ) {
-       len += m->m_len;
-    }
-    MGET( m, M_WAIT, MT_HEADER );
-    if ( m == 0 ) {
-       m_freem( m0 );
-       return( ENOBUFS );
-    }
-    m->m_next = m0;
-#endif /* BSD4_4 */
-
-#ifndef BSD4_4
-# define align(a)      (((a)+3)&0xfc)
-    m->m_off = MMINOFF + align( SZ_ELAPHDR );
-    m->m_len = sizeof( struct ddpehdr );
-#endif /* ! BSD4_4 */
-
-    deh = mtod( m, struct ddpehdr *);
-    deh->deh_pad = 0;
-    deh->deh_hops = 0;
-
-#ifdef BSD4_4
-    deh->deh_len = m->m_pkthdr.len;
-#else /* BSD4_4 */
-    deh->deh_len = len + sizeof( struct ddpehdr );
-#endif /* BSD4_4 */
-
-    deh->deh_dnet = ddp->ddp_fsat.sat_addr.s_net;
-    deh->deh_dnode = ddp->ddp_fsat.sat_addr.s_node;
-    deh->deh_dport = ddp->ddp_fsat.sat_port;
-    deh->deh_snet = ddp->ddp_lsat.sat_addr.s_net;
-    deh->deh_snode = ddp->ddp_lsat.sat_addr.s_node;
-    deh->deh_sport = ddp->ddp_lsat.sat_port;
-
-    /*
-     * The checksum calculation is done after all of the other bytes have
-     * been filled in.
-     */
-    if ( ddp_cksum ) {
-       deh->deh_sum = at_cksum( m, sizeof( int ));
-    } else {
-       deh->deh_sum = 0;
-    }
-    deh->deh_bytes = htonl( deh->deh_bytes );
-
-    return( ddp_route( m, &ddp->ddp_route ));
-}
-
-    u_short
-at_cksum( m, skip )
-    struct mbuf        *m;
-    int                skip;
-{
-    u_char     *data, *end;
-    u_int32_t  cksum = 0;
-
-    for (; m; m = m->m_next ) {
-       for ( data = mtod( m, u_char * ), end = data + m->m_len; data < end;
-               data++ ) {
-           if ( skip ) {
-               skip--;
-               continue;
-           }
-           cksum = ( cksum + *data ) << 1;
-           if ( cksum & 0x00010000 ) {
-               cksum++;
-           }
-           cksum &= 0x0000ffff;
-       }
-    }
-
-    if ( cksum == 0 ) {
-       cksum = 0x0000ffff;
-    }
-    return( (u_short)cksum );
-}
-
-ddp_route( m, ro )
-    struct mbuf                *m;
-    struct route       *ro;
-{
-    struct sockaddr_at gate;
-    struct elaphdr     *elh;
-    struct mbuf                *m0;
-    struct at_ifaddr   *aa = NULL;
-    struct ifnet       *ifp;
-    int                        mlen;
-    u_short            net;
-
-    if ( ro->ro_rt && ( ifp = ro->ro_rt->rt_ifp )) {
-#ifdef BSD4_4
-       net = satosat( ro->ro_rt->rt_gateway )->sat_addr.s_net;
-#else /* BSD4_4 */
-       net = satosat( &ro->ro_rt->rt_gateway )->sat_addr.s_net;
-#endif /* BSD4_4 */
-       for ( aa = at_ifaddr; aa; aa = aa->aa_next ) {
-           if ( aa->aa_ifp == ifp &&
-                   ntohs( net ) >= ntohs( aa->aa_firstnet ) &&
-                   ntohs( net ) <= ntohs( aa->aa_lastnet )) {
-               break;
-           }
-       }
-    }
-    if ( aa == NULL ) {
-       m_freem( m );
-       return( EINVAL );
-    }
-
-    /*
-     * There are several places in the kernel where data is added to
-     * an mbuf without ensuring that the mbuf pointer is aligned.
-     * This is bad for transition routing, since phase 1 and phase 2
-     * packets end up poorly aligned due to the three byte elap header.
-     */
-    if ( aa->aa_flags & AFA_PHASE2 ) {
-       for ( mlen = 0, m0 = m; m0; m0 = m0->m_next ) {
-           mlen += m0->m_len;
-       }
-       if (( m = m_pullup( m, MIN( MLEN, mlen ))) == 0 ) {
-           return( ENOBUFS );
-       }
-    } else {
-# ifdef notdef
-#ifdef BSD4_4
-       M_PREPEND( m, SZ_ELAPHDR, M_DONTWAIT );
-       if ( m == NULL ) {
-           return( ENOBUFS );
-       }
-#else /* BSD4_4 */
-       m->m_off -= SZ_ELAPHDR;
-       m->m_len += SZ_ELAPHDR;
-#endif /* BSD4_4 */
-# endif /* notdef */
-
-       MGET( m0, M_WAIT, MT_HEADER );
-       if ( m0 == 0 ) {
-           m_freem( m );
-           return( ENOBUFS );
-       }
-       m0->m_next = m;
-       m0->m_off = MMINOFF + align( sizeof( struct ether_header ));
-       m0->m_len = SZ_ELAPHDR;
-       m = m0;
-
-       elh = mtod( m, struct elaphdr *);
-       elh->el_snode = satosat( &aa->aa_addr )->sat_addr.s_node;
-       elh->el_type = ELAP_DDPEXTEND;
-       if ( ntohs( satosat( &ro->ro_dst )->sat_addr.s_net ) >=
-               ntohs( aa->aa_firstnet ) &&
-               ntohs( satosat( &ro->ro_dst )->sat_addr.s_net ) <=
-               ntohs( aa->aa_lastnet )) {
-           elh->el_dnode = satosat( &ro->ro_dst )->sat_addr.s_node;
-       } else {
-#ifdef BSD4_4
-           elh->el_dnode = satosat( ro->ro_rt->rt_gateway )->sat_addr.s_node;
-#else /* BSD4_4 */
-           elh->el_dnode = satosat( &ro->ro_rt->rt_gateway )->sat_addr.s_node;
-#endif /* BSD4_4 */
-       }
-    }
-
-    if ( ntohs( satosat( &ro->ro_dst )->sat_addr.s_net ) >=
-           ntohs( aa->aa_firstnet ) &&
-           ntohs( satosat( &ro->ro_dst )->sat_addr.s_net ) <=
-           ntohs( aa->aa_lastnet )) {
-       gate = *satosat( &ro->ro_dst );
-    } else {
-#ifdef BSD4_4
-       gate = *satosat( ro->ro_rt->rt_gateway );
-#else /* BSD4_4 */
-       gate = *satosat( &ro->ro_rt->rt_gateway );
-#endif /* BSD4_4 */
-    }
-    ro->ro_rt->rt_use++;
-
-#ifdef ultrix
-    /*
-     * SAIEW: We can't make changes to net/if_loop.c, so we don't route
-     * further than this: if it's going to go through the lookback,
-     * short-circuit to ddp_input(). Who needs queuing?
-     *
-     * Note: Passing NULL for the elaphdr is cool, since we'll only ever
-     * try to send long form ddp throught the loopback.
-     */
-    if ( ifp->if_flags & IFF_LOOPBACK ) {
-#ifdef notdef
-       m->m_off += SZ_ELAPHDR;
-       m->m_len -= SZ_ELAPHDR;
-#endif /* notdef */
-       ddp_input( m, ifp, (struct elaphdr *)NULL, 2 );
-       return( 0 );
-    }
-#endif /* ultrix */
-
-#ifdef _IBMR2
-    /*
-     * We can't make changes to the interface routines on RS6ks, and
-     * they don't provide hooks for if_output, so we just resolve
-     * our address here, and pass the packet as a raw ethernet packet.
-     * This doesn't work particularly well, if we aren't *on* ethernet,
-     * but it's ok for the moment.
-     */
-    if ( ! ( ifp->if_flags & IFF_LOOPBACK )) {
-       struct ether_header     eh;
-
-       if ( !aarpresolve(( struct arpcom *)ifp, m,
-               &gate, eh.ether_dhost )) {
-           return( 0 );
-       }
-       eh.ether_type = htons( ETHERTYPE_AT );
-       gate.sat_family = AF_UNSPEC;
-       bcopy( &eh, (*(struct sockaddr *)&gate).sa_data,
-               sizeof( (*(struct sockaddr *)&gate).sa_data ));
-    }
-#endif /* _IBMR2 */
-    return((*ifp->if_output)( ifp, m, &gate ));
-}
diff --git a/sys/netatalk/ddp_usrreq.c b/sys/netatalk/ddp_usrreq.c
deleted file mode 100644 (file)
index 50c0202..0000000
+++ /dev/null
@@ -1,536 +0,0 @@
-/*
- * $Id: ddp_usrreq.c,v 1.2 2001-06-29 14:14:47 rufustfirefly Exp $
- *
- * Copyright (c) 1990,1994 Regents of The University of Michigan.
- * All Rights Reserved.  See COPYRIGHT.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <sys/errno.h>
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/systm.h>
-#ifdef ibm032
-#include <sys/dir.h>
-#endif /* ibm032 */
-#include <sys/user.h>
-#include <sys/mbuf.h>
-#include <sys/ioctl.h>
-#include <sys/socket.h>
-#include <sys/socketvar.h>
-#include <sys/protosw.h>
-#include <net/if.h>
-#include <net/route.h>
-#ifdef _IBMR2
-#include <net/spl.h>
-#endif /* _IBMR2 */
-
-#include "at.h"
-#include "at_var.h"
-#include "ddp_var.h"
-#include "endian.h"
-
-struct ddpcb   *ddpcb = NULL;
-u_int32_t              ddp_sendspace = DDP_MAXSZ; /* Max ddp size + 1 (ddp_type) */
-u_int32_t              ddp_recvspace = 10 * ( 587 + sizeof( struct sockaddr_at ));
-
-/*ARGSUSED*/
-ddp_usrreq( so, req, m, addr, rights )
-    struct socket      *so;
-    int                        req;
-    struct mbuf                *m, *addr, *rights;
-{
-    struct ddpcb       *ddp;
-    int                        error = 0;
-
-    ddp = sotoddpcb( so );
-
-    if ( req == PRU_CONTROL ) {
-       return( at_control( (int) m, (caddr_t) addr,
-               (struct ifnet *) rights ));
-    }
-
-    if ( rights && rights->m_len ) {
-       error = EINVAL;
-       goto release;
-    }
-
-    if ( ddp == NULL && req != PRU_ATTACH ) {
-       error = EINVAL;
-       goto release;
-    }
-
-    switch ( req ) {
-    case PRU_ATTACH :
-       if ( ddp != NULL ) {
-           error = EINVAL;
-           break;
-       }
-       if (( error = at_pcballoc( so )) != 0 ) {
-           break;
-       }
-       error = soreserve( so, ddp_sendspace, ddp_recvspace );
-       break;
-
-    case PRU_DETACH :
-       at_pcbdetach( so, ddp );
-       break;
-
-    case PRU_BIND :
-       error = at_pcbsetaddr( ddp, addr );
-       break;
-    
-    case PRU_SOCKADDR :
-       at_sockaddr( ddp, addr );
-       break;
-
-    case PRU_CONNECT:
-       if ( ddp->ddp_fsat.sat_port != ATADDR_ANYPORT ) {
-           error = EISCONN;
-           break;
-       }
-
-       error = at_pcbconnect( ddp, addr );
-       if ( error == 0 )
-           soisconnected( so );
-       break;
-
-    case PRU_DISCONNECT:
-       if ( ddp->ddp_fsat.sat_addr.s_node == ATADDR_ANYNODE ) {
-           error = ENOTCONN;
-           break;
-       }
-       at_pcbdisconnect( ddp );
-       soisdisconnected( so );
-       break;
-
-    case PRU_SHUTDOWN:
-       socantsendmore( so );
-       break;
-
-    case PRU_SEND: {
-       int     s;
-
-       if ( addr ) {
-           if ( ddp->ddp_fsat.sat_port != ATADDR_ANYPORT ) {
-               error = EISCONN;
-               break;
-           }
-
-           s = splnet();
-           error = at_pcbconnect( ddp, addr );
-           if ( error ) {
-               splx( s );
-               break;
-           }
-       } else {
-           if ( ddp->ddp_fsat.sat_port == ATADDR_ANYPORT ) {
-               error = ENOTCONN;
-               break;
-           }
-       }
-
-       error = ddp_output( ddp, m );
-       m = NULL;
-       if ( addr ) {
-           at_pcbdisconnect( ddp );
-           splx( s );
-       }
-       }
-       break;
-
-    case PRU_ABORT:
-       soisdisconnected( so );
-       at_pcbdetach( so, ddp );
-       break;
-
-    case PRU_LISTEN:
-    case PRU_CONNECT2:
-    case PRU_ACCEPT:
-    case PRU_SENDOOB:
-    case PRU_FASTTIMO:
-    case PRU_SLOWTIMO:
-    case PRU_PROTORCV:
-    case PRU_PROTOSEND:
-       error = EOPNOTSUPP;
-       break;
-
-    case PRU_RCVD:
-    case PRU_RCVOOB:
-       /*
-        * Don't mfree. Good architecture...
-        */
-       return( EOPNOTSUPP );
-
-    case PRU_SENSE:
-       /*
-        * 1. Don't return block size.
-        * 2. Don't mfree.
-        */
-       return( 0 );
-
-    default:
-       error = EOPNOTSUPP;
-    }
-
-release:
-    if ( m != NULL ) {
-       m_freem( m );
-    }
-    return( error );
-}
-
-at_sockaddr( ddp, addr )
-    struct ddpcb       *ddp;
-    struct mbuf                *addr;
-{
-    struct sockaddr_at *sat;
-
-    addr->m_len = sizeof( struct sockaddr_at );
-    sat = mtod( addr, struct sockaddr_at *);
-    *sat = ddp->ddp_lsat;
-}
-
-at_pcbsetaddr( ddp, addr )
-    struct ddpcb       *ddp;
-    struct mbuf                *addr;
-{
-    struct sockaddr_at lsat, *sat;
-    struct at_ifaddr   *aa;
-    struct ddpcb       *ddpp;
-
-    if ( ddp->ddp_lsat.sat_port != ATADDR_ANYPORT ) { /* shouldn't be bound */
-       return( EINVAL );
-    }
-
-    if ( addr != 0 ) {                 /* validate passed address */
-       sat = mtod( addr, struct sockaddr_at *);
-       if ( addr->m_len != sizeof( *sat )) {
-           return( EINVAL );
-       }
-       if ( sat->sat_family != AF_APPLETALK ) {
-           return( EAFNOSUPPORT );
-       }
-
-       if ( sat->sat_addr.s_node != ATADDR_ANYNODE ||
-               sat->sat_addr.s_net != ATADDR_ANYNET ) {
-           for ( aa = at_ifaddr; aa; aa = aa->aa_next ) {
-               if (( sat->sat_addr.s_net == AA_SAT( aa )->sat_addr.s_net ) &&
-                ( sat->sat_addr.s_node == AA_SAT( aa )->sat_addr.s_node )) {
-                   break;
-               }
-           }
-           if ( !aa ) {
-               return( EADDRNOTAVAIL );
-           }
-       }
-
-       if ( sat->sat_port != ATADDR_ANYPORT ) {
-           if ( sat->sat_port < ATPORT_FIRST ||
-                   sat->sat_port >= ATPORT_LAST ) {
-               return( EINVAL );
-           }
-#ifdef BSD4_4
-           if ( sat->sat_port < ATPORT_RESERVED &&
-                   suser( u.u_cred, &u.u_acflag )) {
-               return( EACCES );
-           }
-#else /* BSD4_4 */
-           if ( sat->sat_port < ATPORT_RESERVED && ( !suser())) {
-               return( EACCES );
-           }
-#endif /* BSD4_4 */
-       }
-    } else {
-       bzero( (caddr_t)&lsat, sizeof( struct sockaddr_at ));
-       lsat.sat_family = AF_APPLETALK;
-       sat = &lsat;
-    }
-
-    if ( sat->sat_addr.s_node == ATADDR_ANYNODE &&
-           sat->sat_addr.s_net == ATADDR_ANYNET ) {
-       if ( at_ifaddr == NULL ) {
-           return( EADDRNOTAVAIL );
-       }
-       sat->sat_addr = AA_SAT( at_ifaddr )->sat_addr;
-    }
-    ddp->ddp_lsat = *sat;
-
-    /*
-     * Choose port.
-     */
-    if ( sat->sat_port == ATADDR_ANYPORT ) {
-       for ( sat->sat_port = ATPORT_RESERVED;
-               sat->sat_port < ATPORT_LAST; sat->sat_port++ ) {
-           if ( ddp_ports[ sat->sat_port - 1 ] == 0 ) {
-               break;
-           }
-       }
-       if ( sat->sat_port == ATPORT_LAST ) {
-           return( EADDRNOTAVAIL );
-       }
-       ddp->ddp_lsat.sat_port = sat->sat_port;
-       ddp_ports[ sat->sat_port - 1 ] = ddp;
-    } else {
-       for ( ddpp = ddp_ports[ sat->sat_port - 1 ]; ddpp;
-               ddpp = ddpp->ddp_pnext ) {
-           if ( ddpp->ddp_lsat.sat_addr.s_net == sat->sat_addr.s_net &&
-                   ddpp->ddp_lsat.sat_addr.s_node == sat->sat_addr.s_node ) {
-               break;
-           }
-       }
-       if ( ddpp != NULL ) {
-           return( EADDRINUSE );
-       }
-       ddp->ddp_pnext = ddp_ports[ sat->sat_port - 1 ];
-       ddp_ports[ sat->sat_port - 1 ] = ddp;
-       if ( ddp->ddp_pnext ) {
-           ddp->ddp_pnext->ddp_pprev = ddp;
-       }
-    }
-
-    return( 0 );
-}
-
-at_pcbconnect( ddp, addr )
-    struct ddpcb       *ddp;
-    struct mbuf                *addr;
-{
-    struct sockaddr_at *sat = mtod( addr, struct sockaddr_at *);
-    struct route       *ro;
-    struct at_ifaddr   *aa = 0;
-    struct ifnet       *ifp;
-    u_short            hintnet = 0, net;
-
-    if ( addr->m_len != sizeof( *sat ))
-       return( EINVAL );
-    if ( sat->sat_family != AF_APPLETALK ) {
-       return( EAFNOSUPPORT );
-    }
-
-    /*
-     * Under phase 2, network 0 means "the network".  We take "the
-     * network" to mean the network the control block is bound to.
-     * If the control block is not bound, there is an error.
-     */
-    if ( sat->sat_addr.s_net == 0 && sat->sat_addr.s_node != ATADDR_ANYNODE ) {
-       if ( ddp->ddp_lsat.sat_port == ATADDR_ANYPORT ) {
-           return( EADDRNOTAVAIL );
-       }
-       hintnet = ddp->ddp_lsat.sat_addr.s_net;
-    }
-
-    ro = &ddp->ddp_route;
-    /*
-     * If we've got an old route for this pcb, check that it is valid.
-     * If we've changed our address, we may have an old "good looking"
-     * route here.  Attempt to detect it.
-     */
-    if ( ro->ro_rt ) {
-       if ( hintnet ) {
-           net = hintnet;
-       } else {
-           net = sat->sat_addr.s_net;
-       }
-       aa = 0;
-       if ( ifp = ro->ro_rt->rt_ifp ) {
-           for ( aa = at_ifaddr; aa; aa = aa->aa_next ) {
-               if ( aa->aa_ifp == ifp &&
-                       ntohs( net ) >= ntohs( aa->aa_firstnet ) &&
-                       ntohs( net ) <= ntohs( aa->aa_lastnet )) {
-                   break;
-               }
-           }
-       }
-       if ( aa == NULL || ( satosat( &ro->ro_dst )->sat_addr.s_net !=
-               ( hintnet ? hintnet : sat->sat_addr.s_net ) ||
-               satosat( &ro->ro_dst )->sat_addr.s_node !=
-               sat->sat_addr.s_node )) {
-#ifdef ultrix
-           rtfree( ro->ro_rt );
-#else /* ultrix */
-           RTFREE( ro->ro_rt );
-#endif /* ultrix */
-           ro->ro_rt = (struct rtentry *)0;
-       }
-    }
-
-    /*
-     * If we've got no route for this interface, try to find one.
-     */
-    if ( ro->ro_rt == (struct rtentry *)0 ||
-        ro->ro_rt->rt_ifp == (struct ifnet *)0 ) {
-#ifdef BSD4_4
-       ro->ro_dst.sa_len = sizeof( struct sockaddr_at );
-#endif /* BSD4_4 */
-       ro->ro_dst.sa_family = AF_APPLETALK;
-       if ( hintnet != 0 ) {
-           satosat( &ro->ro_dst )->sat_addr.s_net = hintnet;
-       } else {
-           satosat( &ro->ro_dst )->sat_addr.s_net = sat->sat_addr.s_net;
-       }
-       satosat( &ro->ro_dst )->sat_addr.s_node = sat->sat_addr.s_node;
-       rtalloc( ro );
-    }
-
-    /*
-     * Make sure any route that we have has a valid interface.
-     */
-    aa = 0;
-    if ( ro->ro_rt && ( ifp = ro->ro_rt->rt_ifp )) {
-       for ( aa = at_ifaddr; aa; aa = aa->aa_next ) {
-           if ( aa->aa_ifp == ifp ) {
-               break;
-           }
-       }
-    }
-    if ( aa == 0 ) {
-       return( ENETUNREACH );
-    }
-
-    ddp->ddp_fsat = *sat;
-    if ( ddp->ddp_lsat.sat_port == ATADDR_ANYPORT ) {
-       return( at_pcbsetaddr( ddp, (struct mbuf *)0 ));
-    }
-    return( 0 );
-}
-
-at_pcbdisconnect( ddp )
-    struct ddpcb       *ddp;
-{
-    ddp->ddp_fsat.sat_addr.s_net = ATADDR_ANYNET;
-    ddp->ddp_fsat.sat_addr.s_node = ATADDR_ANYNODE;
-    ddp->ddp_fsat.sat_port = ATADDR_ANYPORT;
-}
-
-at_pcballoc( so )
-    struct socket      *so;
-{
-    struct ddpcb       *ddp;
-    struct mbuf                *m;
-
-    m = m_getclr( M_WAIT, MT_PCB );
-    ddp = mtod( m, struct ddpcb * );
-    ddp->ddp_lsat.sat_port = ATADDR_ANYPORT;
-
-    ddp->ddp_next = ddpcb;
-    ddp->ddp_prev = NULL;
-    ddp->ddp_pprev = NULL;
-    ddp->ddp_pnext = NULL;
-    if ( ddpcb ) {
-       ddpcb->ddp_prev = ddp;
-    }
-    ddpcb = ddp;
-
-    ddp->ddp_socket = so;
-    so->so_pcb = (caddr_t)ddp;
-    return( 0 );
-}
-
-at_pcbdetach( so, ddp )
-    struct socket      *so;
-    struct ddpcb       *ddp;
-{
-    soisdisconnected( so );
-    so->so_pcb = 0;
-    sofree( so );
-
-    /* remove ddp from ddp_ports list */
-    if ( ddp->ddp_lsat.sat_port != ATADDR_ANYPORT &&
-           ddp_ports[ ddp->ddp_lsat.sat_port - 1 ] != NULL ) {
-       if ( ddp->ddp_pprev != NULL ) {
-           ddp->ddp_pprev->ddp_pnext = ddp->ddp_pnext;
-       } else {
-           ddp_ports[ ddp->ddp_lsat.sat_port - 1 ] = ddp->ddp_pnext;
-       }
-       if ( ddp->ddp_pnext != NULL ) {
-           ddp->ddp_pnext->ddp_pprev = ddp->ddp_pprev;
-       }
-    }
-
-    if ( ddp->ddp_route.ro_rt ) {
-       rtfree( ddp->ddp_route.ro_rt );
-    }
-
-    if ( ddp->ddp_prev ) {
-       ddp->ddp_prev->ddp_next = ddp->ddp_next;
-    } else {
-       ddpcb = ddp->ddp_next;
-    }
-    if ( ddp->ddp_next ) {
-       ddp->ddp_next->ddp_prev = ddp->ddp_prev;
-    }
-
-    (void) m_free( dtom( ddp ));
-}
-
-/*
- * For the moment, this just find the pcb with the correct local address.
- * In the future, this will actually do some real searching, so we can use
- * the sender's address to do de-multiplexing on a single port to many
- * sockets (pcbs).
- */
-    struct ddpcb *
-ddp_search( from, to, aa )
-    struct sockaddr_at *from, *to;
-    struct at_ifaddr   *aa;
-{
-    struct ddpcb       *ddp;
-
-    /*
-     * Check for bad ports.
-     */
-    if ( to->sat_port < ATPORT_FIRST || to->sat_port >= ATPORT_LAST ) {
-       return( NULL );
-    }
-
-    /*
-     * Make sure the local address matches the sent address.  What about
-     * the interface?
-     */
-    for ( ddp = ddp_ports[ to->sat_port - 1 ]; ddp; ddp = ddp->ddp_pnext ) {
-       /* XXX should we handle 0.YY? */
-
-       /* XXXX.YY to socket on destination interface */
-       if ( to->sat_addr.s_net == ddp->ddp_lsat.sat_addr.s_net &&
-               to->sat_addr.s_node == ddp->ddp_lsat.sat_addr.s_node ) {
-           break;
-       }
-
-       /* 0.255 to socket on receiving interface */
-       if ( to->sat_addr.s_node == ATADDR_BCAST && ( to->sat_addr.s_net == 0 ||
-               to->sat_addr.s_net == ddp->ddp_lsat.sat_addr.s_net ) &&
-               ddp->ddp_lsat.sat_addr.s_net == AA_SAT( aa )->sat_addr.s_net ) {
-           break;
-       }
-
-       /* XXXX.0 to socket on destination interface */
-       if ( to->sat_addr.s_net == aa->aa_firstnet &&
-               to->sat_addr.s_node == 0 &&
-               ntohs( ddp->ddp_lsat.sat_addr.s_net ) >=
-               ntohs( aa->aa_firstnet ) &&
-               ntohs( ddp->ddp_lsat.sat_addr.s_net ) <=
-               ntohs( aa->aa_lastnet )) {
-           break;
-       }
-    }
-    return( ddp );
-}
-
-ddp_init()
-{
-    atintrq1.ifq_maxlen = IFQ_MAXLEN;
-    atintrq2.ifq_maxlen = IFQ_MAXLEN;
-}
-
-ddp_clean()
-{
-    struct ddpcb       *ddp;
-
-    for ( ddp = ddpcb; ddp; ddp = ddp->ddp_next ) {
-       at_pcbdetach( ddp->ddp_socket, ddp );
-    }
-}
diff --git a/sys/netatalk/ddp_var.h b/sys/netatalk/ddp_var.h
deleted file mode 100644 (file)
index 42654a2..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * $Id: ddp_var.h,v 1.2 2001-06-29 14:14:47 rufustfirefly Exp $
- *
- * Copyright (c) 1990,1994 Regents of The University of Michigan.
- * All Rights Reserved.  See COPYRIGHT.
- */
-
-#ifndef _NETATALK_DDP_VAR_H
-#define _NETATALK_DDP_VAR_H 1
-
-#include <netatalk/endian.h>
-
-struct ddpcb {
-    struct sockaddr_at ddp_fsat, ddp_lsat;
-    struct route       ddp_route;
-    struct socket      *ddp_socket;
-    struct ddpcb       *ddp_prev, *ddp_next;
-    struct ddpcb       *ddp_pprev, *ddp_pnext;
-};
-
-#define sotoddpcb(so)  ((struct ddpcb *)(so)->so_pcb)
-
-struct ddpstat {
-    u_int32_t  ddps_short;             /* short header packets received */
-    u_int32_t  ddps_long;              /* long header packets received */
-    u_int32_t  ddps_nosum;             /* no checksum */
-    u_int32_t  ddps_badsum;            /* bad checksum */
-    u_int32_t  ddps_tooshort;          /* packet too short */
-    u_int32_t  ddps_toosmall;          /* not enough data */
-    u_int32_t  ddps_forward;           /* packets forwarded */
-    u_int32_t  ddps_encap;             /* packets encapsulated */
-    u_int32_t  ddps_cantforward;       /* packets rcvd for unreachable dest */
-    u_int32_t  ddps_nosockspace;       /* no space in sockbuf for packet */
-};
-
-#ifdef KERNEL
-struct ddpcb           *ddp_ports[ ATPORT_LAST ];
-struct ddpcb           *ddpcb;
-struct ddpstat         ddpstat;
-struct ddpcb           *ddp_search();
-#endif /* KERNEL */
-
-#endif /* netatalk/ddp_var.h */
diff --git a/sys/netatalk/endian.h b/sys/netatalk/endian.h
deleted file mode 100644 (file)
index a216e60..0000000
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * $Id: endian.h,v 1.9 2009-01-06 20:05:00 morgana Exp $
- *
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- * All Rights Reserved. See COPYRIGHT.
- *
- * This file handles both byte ordering and integer sizes.
- */
-
-#ifndef _ATALK_ENDIAN_H_
-#define _ATALK_ENDIAN_H_
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <sys/types.h>
-#include <netinet/in.h>
-
-#ifdef _IBMR2
-#include <sys/machine.h>
-#endif /*_IBMR2*/
-
-#ifdef _ISOC9X_SOURCE
-#include <inttypes.h>
-#ifndef __BIT_TYPES_DEFINED__
-#define __BIT_TYPES_DEFINED__
-typedef uint8_t        u_int8_t;
-typedef uint16_t       u_int16_t;
-typedef uint32_t       u_int32_t;
-typedef uint64_t       u_int64_t;
-#endif /* ! __BIT_TYPES_DEFINED__ */
-#else
-
-/* handle sunos and solaris */
-#ifdef sun
-#ifdef BSD4_3
-#include <sys/bitypes.h>
-#else /* BSD4_3 */
-/* solaris and sunos don't consistently define u_int*_t. */
-typedef unsigned char      u_int8_t;
-typedef unsigned short     u_int16_t;
-typedef unsigned int       u_int32_t;
-typedef int                int32_t;
-#endif /* BSD4_3 */
-
-typedef unsigned long long u_int64_t;
-
-#ifndef _SSIZE_T
-#define _SSIZE_T
-typedef int ssize_t;
-#endif /* ssize_t */
-
-#else /* sun */
-
-/* luckily ultrix is dead. as a result, we know what the sizes of
- * various types are forever. this makes some assumptions about integer
- * sizes. */
-#if defined (ultrix) || defined(HAVE_32BIT_LONGS) || defined(HAVE_64BIT_LONGS)
-#ifndef __BIT_TYPES_DEFINED__
-#define __BIT_TYPES_DEFINED__
-typedef unsigned char  u_int8_t;
-typedef unsigned short u_int16_t;
-typedef unsigned int   u_int32_t;
-typedef int            int32_t;
-#endif
-#endif /* ultrix || HAVE_32BIT_LONGS || HAVE_64BIT_LONGS */
-
-#ifdef ultrix
-typedef int            ssize_t;
-#endif /* ultrix */
-
-#ifdef HAVE_64BIT_LONGS
-typedef unsigned long u_int64_t;
-#else /* HAVE_64BIT_LONGS */
-/* check for long long support. currently, i assume that if 64-bit
- * ints exist that their made available via long long */
-#ifdef linux
-#include <endian.h> /* i think this is here for libc4 */
-#else /* linux */
-#if defined(HAVE_32BIT_LONGS) && !(defined(BSD4_4) || \
-                                 defined(NO_LARGE_VOL_SUPPORT))
-typedef unsigned long long  u_int64_t;
-#endif /* HAVE_32BIT_LONGS || !BSD4_4 || NO_LARGE_VOL_SUPPORT */
-#endif /* linux */
-#endif /* HAVE_64BIT_LONGS */
-#endif /* sun */
-#endif /* ISOC9X */
-
-# ifndef BYTE_ORDER
-#define LITTLE_ENDIAN  1234
-#define BIG_ENDIAN     4321
-#define PDP_ENDIAN     3412
-
-
-#if defined(WORDS_BIGENDIAN) || defined(_BIG_ENDIAN)
-#define BYTE_ORDER     BIG_ENDIAN
-#else
-#define BYTE_ORDER     LITTLE_ENDIAN
-#endif /* WORDS_BIGENDIAN */
-
-# ifndef ntohl
-# if defined( sun ) || defined( ultrix ) || defined( _IBMR2 )
-#if BYTE_ORDER == BIG_ENDIAN
-#define ntohl(x)       (x)
-#define ntohs(x)       (x)
-#define htonl(x)       (x)
-#define htons(x)       (x)
-
-#else /* BYTE_ORDER == BIG_ENDIAN */
-#if defined( mips ) && defined( KERNEL )
-#define        ntohl(x)        nuxi_l(x)
-#define        ntohs(x)        nuxi_s(x)
-#define        htonl(x)        nuxi_l(x)
-#define        htons(x)        nuxi_s(x)
-
-#else /* mips && KERNEL */
-
-#if !( defined( sun ) && ( defined( i386 ) || defined(__x86_64) ) )
-unsigned short ntohs(), htons();
-unsigned int  ntohl(), htonl();
-#endif /* ! ( sun && i386 ) */
-
-#endif /* mips && KERNEL */
-#endif /* BYTE_ORDER == BIGENDIAN*/
-# endif /* sun ultrix _IBMR2 */
-# endif /* ntohl */
-#endif /* BYTE_ORDER */
-
-#endif /* _ATALK_ENDIAN_H_ */
-
diff --git a/sys/netatalk/phase2.h b/sys/netatalk/phase2.h
deleted file mode 100644 (file)
index ec9735b..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * $Id: phase2.h,v 1.2 2001-06-29 14:14:47 rufustfirefly Exp $
- *
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- * All Rights Reserved.
- */
-
-# if defined( ultrix ) || defined( BSD4_4 )
-#include <net/if_llc.h>
-# else /* ultrix || BSD4_4 */
-
-#if defined( sun ) && !defined( __svr4__ )
-#include <net/if_ieee802.h>
-#endif /* sun && !__svr4__ */
-
-/*
- * Copyright (c) 1988 Regents of the University of California.
- * All rights reserved.
- *
- *      @(#)if_llc.h   7.2 (Berkeley) 6/28/90
- */
-
-/*
- * IEEE 802.2 Link Level Control headers, for use in conjunction with
- * 802.{3,4,5} media access control methods.
- *
- * Headers here do not use bit fields due to shortcommings in many
- * compilers.
- */
-
-struct llc {
-       u_char  llc_dsap;
-       u_char  llc_ssap;
-       union {
-           struct {
-               u_char control;
-               u_char format_id;
-               u_char class;
-               u_char window_x2;
-           } type_u;
-           struct {
-               u_char num_snd_x2;
-               u_char num_rcv_x2;
-           } type_i;
-           struct {
-               u_char control;
-               u_char num_rcv_x2;
-           } type_s;
-           struct {
-               u_char control;
-               u_char org_code[3];
-               u_short ether_type;
-           } type_snap;
-       } llc_un;
-};
-#define llc_control llc_un.type_u.control
-#define llc_fid llc_un.type_u.format_id
-#define llc_class llc_un.type_u.class
-#define llc_window llc_un.type_u.window_x2
-#define llc_org_code llc_un.type_snap.org_code
-#define llc_ether_type llc_un.type_snap.ether_type
-
-#define LLC_UI         0x3
-#define LLC_UI_P       0x13
-#define LLC_XID                0xaf
-#define LLC_XID_P      0xbf
-#define LLC_TEST       0xe3
-#define LLC_TEST_P     0xf3
-
-#define LLC_ISO_LSAP   0xfe
-#define LLC_SNAP_LSAP  0xaa
-
-# endif /* ultrix && BSD4_4 */
-
-#if defined( sun ) || defined( ibm032 )
-#define SIOCPHASE1     _IOW(i, 100, struct ifreq)      /* AppleTalk phase 1 */
-#define SIOCPHASE2     _IOW(i, 101, struct ifreq)      /* AppleTalk phase 2 */
-#endif /* sun || ibm032 */
-
-#if defined( ultrix ) || defined( BSD4_4 ) || defined( _IBMR2 )
-#define SIOCPHASE1     _IOW('i', 100, struct ifreq)    /* AppleTalk phase 1 */
-#define SIOCPHASE2     _IOW('i', 101, struct ifreq)    /* AppleTalk phase 2 */
-#endif /* ultrix || BSD4_4 || _IBMR2 */
diff --git a/sys/netbsd/.gitignore b/sys/netbsd/.gitignore
deleted file mode 100644 (file)
index 895a5e7..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-Makefile
-Makefile.in
-.gitignore
-*.o
diff --git a/sys/netbsd/Makefile.am b/sys/netbsd/Makefile.am
deleted file mode 100644 (file)
index 454fafe..0000000
+++ /dev/null
@@ -1 +0,0 @@
-SUBDIRS = netatalk
diff --git a/sys/netbsd/netatalk/.gitignore b/sys/netbsd/netatalk/.gitignore
deleted file mode 100644 (file)
index 895a5e7..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-Makefile
-Makefile.in
-.gitignore
-*.o
diff --git a/sys/netbsd/netatalk/Makefile.am b/sys/netbsd/netatalk/Makefile.am
deleted file mode 100644 (file)
index f4ec9dc..0000000
+++ /dev/null
@@ -1 +0,0 @@
-EXTRA_DIST = endian.h
diff --git a/sys/netbsd/netatalk/endian.h b/sys/netbsd/netatalk/endian.h
deleted file mode 100644 (file)
index a1957e2..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-
-/*
- * netatalk/endian.h
- *
- * This file is a dummy replacement for endian.h. NetBSD includes
- * machine/endian.h in sys/types.h, and it was decided that a
- * second include file was not needed. This file is included to
- * make all the source code compile correctly.
- */
diff --git a/sys/solaris/.gitignore b/sys/solaris/.gitignore
deleted file mode 100644 (file)
index 2f9b1d7..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-Makefile
-ddp
-.gitignore
-*.o
diff --git a/sys/solaris/Makefile.in b/sys/solaris/Makefile.in
deleted file mode 100644 (file)
index 9f6c89a..0000000
+++ /dev/null
@@ -1,166 +0,0 @@
-# Solaris specific defines, passed to subdirectories.
-# To use Sun CC, uncomment the CC and KFLAGS variables.
-#
-# $Id: Makefile.in,v 1.6 2009-11-25 14:58:26 franklahm Exp $
-# This Makefile.in is not automake generated
-# copy and paste from automake Makefile.in
-srcdir = @srcdir@
-top_srcdir = @top_srcdir@
-VPATH = @srcdir@
-# end copy and paste
-
-CC     = @CC@
-# LD hardcoded to sun ld, GNU ld has been reported to cause some trouble with 64 bit
-LD     = /usr/ccs/bin/ld
-
-INSTALL = @INSTALL@
-GREP=@GREP@
-
-
-# -D_ISOC9X_SOURCE is handled by OSVERSION. basically, it's not needed
-# with 2.5.1.
-DEFS=  -D__svr4__ -DSOLARIS -I../../sys/generic \
-       -I.. @DEFS@
-
-# Variables
-KCFLAGS=@KCFLAGS@
-KLDFLAGS=@KLDFLAGS@
-COMPILE_KERNEL_GCC=@COMPILE_KERNEL_GCC@
-SPARC64=@COMPILE_64BIT_KMODULE@
-SOLARIS_MODULE_FALSE=@SOLARIS_MODULE_FALSE@
-SOLARIS_MODULE_TRUE=@SOLARIS_MODULE_TRUE@
-USE_SOLARIS_TRUE=@USE_SOLARIS_TRUE@
-USE_SOLARIS_FALSE=@USE_SOLARIS_FALSE@
-
-OPTOPTS=
-
-# Local build stuff.
-
-SRC= linkage.c tpi.c dlpi.c ioc.c if.c aarp.c ddp.c sock.c rt.c
-OBJ= linkage.o tpi.o dlpi.o ioc.o if.o aarp.o ddp.o sock.o rt.o
-HEADERS= if.h ioc.h rt.h sock.h
-EXTRA_DIST= ddp.conf Makefile.in $(SRC) $(HEADERS)
-DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
-
-INCPATH=       -I../../include -I../netatalk -I../..
-CFLAGS=        ${DEFS} ${OPTOPTS} ${INCPATH} ${KCFLAGS}
-
-# Not building on Solaris
-@USE_SOLARIS_FALSE@all:
-
-# No Solaris kernel module build
-@USE_SOLARIS_TRUE@@SOLARIS_MODULE_FALSE@all:
-@USE_SOLARIS_TRUE@@SOLARIS_MODULE_FALSE@       @echo
-@USE_SOLARIS_TRUE@@SOLARIS_MODULE_FALSE@       @echo "Solaris kernel module cannot be build"
-@SOLARIS_MODULE_FALSE@install:
-@SOLARIS_MODULE_FALSE@
-@SOLARIS_MODULE_FALSE@uninstall:
-
-# Build Solaris kernel module
-@SOLARIS_MODULE_TRUE@all :     kernel
-
-@SOLARIS_MODULE_TRUE@kernel: ddp 
-
-@SOLARIS_MODULE_TRUE@FRC: 
-
-@SOLARIS_MODULE_TRUE@ddp :     ${OBJ}
-@SOLARIS_MODULE_TRUE@  ${LD} ${KLDFLAGS} -r -o ddp ${OBJ}
-
-@SOLARIS_MODULE_TRUE@linkage.o : linkage.c
-@SOLARIS_MODULE_TRUE@  ${CC} ${CFLAGS} -DVERSION=\"`cat ../../VERSION`\" -c linkage.c
-
-@SOLARIS_MODULE_TRUE@kuninstall : FRC
-@SOLARIS_MODULE_TRUE@  @if [ x"${SPARC64}" = x"yes" ] ; then \
-@SOLARIS_MODULE_TRUE@          ${RM} /usr/kernel/drv/sparcv9/ddp; \
-@SOLARIS_MODULE_TRUE@          ${RM} /usr/kernel/strmod/sparcv9/ddp; \
-@SOLARIS_MODULE_TRUE@  else \
-@SOLARIS_MODULE_TRUE@          ${RM} /usr/kernel/drv/ddp; \
-@SOLARIS_MODULE_TRUE@          ${RM} /usr/kernel/strmod/ddp; \
-@SOLARIS_MODULE_TRUE@  fi
-@SOLARIS_MODULE_TRUE@  ${RM} /usr/kernel/drv/ddp.conf
-@SOLARIS_MODULE_TRUE@  -rem_drv ddp
-@SOLARIS_MODULE_TRUE@  sync;sync;sync
-
-@SOLARIS_MODULE_TRUE@kinstall : kernel kuninstall
-@SOLARIS_MODULE_TRUE@  @if [ x"${SPARC64}" = x"yes" ]; then \
-@SOLARIS_MODULE_TRUE@          ${INSTALL} -o root -g sys -c ddp /usr/kernel/drv/sparcv9/ddp; \
-@SOLARIS_MODULE_TRUE@          ln /usr/kernel/drv/sparcv9/ddp /usr/kernel/strmod/sparcv9/ddp; \
-@SOLARIS_MODULE_TRUE@  else \
-@SOLARIS_MODULE_TRUE@          ${INSTALL} -o root -g sys -c ddp /usr/kernel/drv/ddp; \
-@SOLARIS_MODULE_TRUE@          ln /usr/kernel/drv/ddp /usr/kernel/strmod/ddp; \
-@SOLARIS_MODULE_TRUE@  fi
-@SOLARIS_MODULE_TRUE@  ${INSTALL} -o root -g sys -c ddp.conf /usr/kernel/drv/ddp.conf
-@SOLARIS_MODULE_TRUE@  add_drv -m '* 0666 root sys' ddp
-@SOLARIS_MODULE_TRUE@  sync;sync;sync
-@SOLARIS_MODULE_TRUE@  @if ${GREP} 'ddp' /etc/netconfig; then \
-@SOLARIS_MODULE_TRUE@            echo "netconfig already contains a ddp module, skipping"; \
-@SOLARIS_MODULE_TRUE@        else \
-@SOLARIS_MODULE_TRUE@            echo "adding ddp module to netconfig"; \
-@SOLARIS_MODULE_TRUE@            echo "ddp        tpi_clts      -    appletalk ddp   /dev/ddp        -" >> /etc/netconfig; \
-@SOLARIS_MODULE_TRUE@  fi
-@SOLARIS_MODULE_TRUE@  @echo "Installed Solaris kernel module"
-
-
-@SOLARIS_MODULE_TRUE@install:
-@SOLARIS_MODULE_TRUE@  @echo
-@SOLARIS_MODULE_TRUE@  @echo "To install the Solaris kernel module type 'make kinstall' as root user"
-
-@SOLARIS_MODULE_TRUE@uninstall:
-@SOLARIS_MODULE_TRUE@  @echo
-@SOLARIS_MODULE_TRUE@  @echo "To uninstall the Solaris kernel module type 'make kuninstall' as root user"
-
-# copy and paste from automake Makefile.in
-distdir : $(DISTFILES)
-       @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
-       topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
-       list='$(DISTFILES)'; for file in $$list; do \
-         case $$file in \
-           $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
-           $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
-         esac; \
-         if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
-         dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
-         if test "$$dir" != "$$file" && test "$$dir" != "."; then \
-           dir="/$$dir"; \
-           $(mkdir_p) "$(distdir)$$dir"; \
-         else \
-           dir=''; \
-         fi; \
-         if test -d $$d/$$file; then \
-           if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
-             cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
-           fi; \
-           cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
-         else \
-           test -f $(distdir)/$$file \
-           || cp -p $$d/$$file $(distdir)/$$file \
-           || exit 1; \
-         fi; \
-       done
-# end copy and paste
-
-clean : sysclean
-
-klean sysclean :
-       rm -f a.out core* *.o *.bak *[Ee]rrs tags
-       rm -f ddp
-
-distclean: clean
-        -rm -f Makefile
-
-maintainer-clean: distclean
-
-depend :
-
-check:
-
-tags:
-
-dvi:
-
-installcheck:
-
-install-exec:
-
-# DO NOT DELETE THIS LINE
-
diff --git a/sys/solaris/aarp.c b/sys/solaris/aarp.c
deleted file mode 100644 (file)
index ea3cf67..0000000
+++ /dev/null
@@ -1,356 +0,0 @@
-/*
- * $Id: aarp.c,v 1.4 2005-04-28 20:50:07 bfernhomberg Exp $
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/byteorder.h>
-#include <sys/errno.h>
-#include <sys/stream.h>
-#include <sys/ethernet.h>
-#include <sys/kmem.h>
-#include <sys/cmn_err.h>
-#include <sys/ddi.h>
-#include <netinet/arp.h>
-#include <net/if.h>
-
-#ifdef STDC_HEADERS
-#include <strings.h>
-#else
-#include <string.h>
-#endif
-
-#include <netatalk/at.h>
-#include <netatalk/aarp.h>
-#include <netatalk/phase2.h>
-
-#include "if.h"
-
-struct aarplist {
-    struct aarplist    *aal_next, *aal_prev;
-    struct at_addr     aal_addr;
-    u_char             aal_hwaddr[ ETHERADDRL ];
-    u_char             aal_age;
-    u_char             aal_flags;
-    mblk_t             *aal_m;
-};
-
-    struct aarplist *
-aarp_find( struct atif_data *aid, ushort net, unchar node )
-{
-    struct aarplist    *aal;
-
-    for ( aal = aid->aid_aarplist; aal != NULL; aal = aal->aal_next ) {
-       if ( aal->aal_addr.s_net == net && aal->aal_addr.s_node == node ) {
-           break;
-       }
-    }
-    return( aal );
-}
-
-    struct aarplist *
-aarp_alloc( struct atif_data *aid, ushort net, unchar node )
-{
-    struct aarplist    *aal;
-
-    for ( aal = aid->aid_aarplist; aal != NULL; aal = aal->aal_next ) {
-       if ( aal->aal_addr.s_net == net && aal->aal_addr.s_node == node ) {
-           return( aal );
-       }
-    }
-
-    if ( aid->aid_aarpflist == NULL ) {
-        if (( aal = (struct aarplist *)kmem_alloc( sizeof( struct aarplist ),
-                KM_NOSLEEP )) == NULL ) {
-            return( NULL );
-        }
-    } else {
-       aal = aid->aid_aarpflist;
-       aid->aid_aarpflist = aal->aal_next;
-       if ( aid->aid_aarpflist != NULL ) {
-           aid->aid_aarpflist->aal_prev = NULL;
-       }
-    }
-
-    aal->aal_addr.s_net = net;
-    aal->aal_addr.s_node = node;
-    bzero( aal->aal_hwaddr, sizeof( aal->aal_hwaddr ));
-    aal->aal_age = 0;
-    aal->aal_flags = 0;
-    aal->aal_m = NULL;
-
-    aal->aal_next = aid->aid_aarplist;
-    aal->aal_prev = NULL;
-    if ( aid->aid_aarplist != NULL ) {
-       aid->aid_aarplist->aal_prev = aal;
-    }
-    aid->aid_aarplist = aal;
-
-    return( aal );
-}
-
-/*
- * Move entry to free list.
- */
-    void
-aarp_free( struct atif_data *aid, struct aarplist *aal )
-{
-    if ( aal->aal_next != NULL ) {
-       aal->aal_next->aal_prev = aal->aal_prev;
-    }
-    if ( aal->aal_prev != NULL ) {
-       aal->aal_prev->aal_next = aal->aal_next;
-    }
-    if ( aid->aid_aarplist == aal ) {
-       aid->aid_aarplist = aal->aal_next;
-    }
-
-    if ( aal->aal_m != NULL ) {
-       freemsg( aal->aal_m );
-       aal->aal_m = NULL;
-    }
-
-    aal->aal_prev = NULL;
-    aal->aal_next = aid->aid_aarpflist;
-    if ( aid->aid_aarpflist != NULL ) {
-       aid->aid_aarpflist->aal_prev = aal;
-    }
-    aid->aid_aarpflist = aal;
-    return;
-}
-
-    void
-aarp_timeout( void *ptr )
-{
-    struct atif_data   *aid = (struct atif_data *) ptr;
-    struct aarplist    *aal, *p;
-
-    aid->aid_aarptimeo = qtimeout( aid->aid_q, aarp_timeout,
-           (caddr_t)aid, 60 * hz );
-    for ( aal = aid->aid_aarplist; aal != NULL; aal = p ) {
-       p = aal->aal_next;
-       if ( ++aal->aal_age < (( aal->aal_flags ) ? 5 : 3 )) {
-           continue;
-       }
-       aarp_free( aid, aal );
-    }
-    return;
-}
-
-    void
-aarp_init( struct atif_data *aid )
-{
-    aid->aid_aarptimeo = qtimeout( aid->aid_q, aarp_timeout,
-           (caddr_t)aid, 60 * hz );
-    return;
-}
-
-    void
-aarp_clean( struct atif_data *aid )
-{
-    struct aarplist *aal, *p;
-
-    if ( aid->aid_aarptimeo != 0 ) {
-       quntimeout( aid->aid_q, aid->aid_aarptimeo );
-       aid->aid_aarptimeo = 0;
-    }
-
-    for ( aal = aid->aid_aarplist; aal != NULL; aal = p ) {
-       p = aal->aal_next;
-       if ( aal->aal_m != NULL ) {
-           freemsg( aal->aal_m );
-           aal->aal_m = NULL;
-       }
-       kmem_free( aal, sizeof( struct aarplist ));
-    }
-    aid->aid_aarplist = NULL;
-
-    for ( aal = aid->aid_aarpflist; aal != NULL; aal = p ) {
-       p = aal->aal_next;
-       if ( aal->aal_m != NULL ) {
-           freemsg( aal->aal_m );
-           aal->aal_m = NULL;
-       }
-       kmem_free( aal, sizeof( struct aarplist ));
-    }
-    aid->aid_aarpflist = NULL;
-
-    return;
-}
-
-    int
-aarp_rput( queue_t *q, mblk_t *m )
-{
-    struct atif_data   *aid = (struct atif_data *)q->q_ptr;
-    struct ether_aarp  *ea;
-    struct aarplist    *aal;
-    ushort             tpnet, spnet, op;
-
-    if ( m->b_wptr - m->b_rptr < sizeof( struct ether_aarp )) {
-       cmn_err( CE_NOTE, "aarp_rput short packet\n" );
-       goto done;
-    }
-
-    ea = (struct ether_aarp *)m->b_rptr;
-
-    if ( ea->aarp_hrd != htons( AARPHRD_ETHER ) ||
-           ea->aarp_pro != htons( ETHERTYPE_AT ) ||
-           ea->aarp_hln != sizeof( ea->aarp_sha ) ||
-           ea->aarp_pln != sizeof( ea->aarp_spu )) {
-       cmn_err( CE_NOTE, "aarp_rput bad constants\n" );
-       goto done;
-    }
-
-    if ( bcmp( ea->aarp_sha, aid->aid_hwaddr, sizeof( ea->aarp_sha )) == 0 ) {
-       goto done;
-    }
-
-    op = ntohs( ea->aarp_op );
-    bcopy( ea->aarp_tpnet, &tpnet, sizeof( tpnet ));
-    bcopy( ea->aarp_spnet, &spnet, sizeof( spnet ));
-
-    if ( aid->aid_flags & AIDF_PROBING ) {
-       if ( tpnet == aid->aid_sat.sat_addr.s_net &&
-               ea->aarp_tpnode == aid->aid_sat.sat_addr.s_node ) {
-           aid->aid_flags &= ~AIDF_PROBING;
-           aid->aid_flags |= AIDF_PROBEFAILED;
-           cmn_err( CE_NOTE, "aarp_rput probe collision %s\n", aid->aid_name );
-       }
-    } else {
-       if ( tpnet == aid->aid_sat.sat_addr.s_net &&
-               ea->aarp_tpnode == aid->aid_sat.sat_addr.s_node ) {
-           switch ( op ) {
-           case AARPOP_REQUEST :
-               aal = aarp_alloc( aid, spnet, ea->aarp_spnode );
-               bcopy( ea->aarp_sha, aal->aal_hwaddr, sizeof( ea->aarp_sha ));
-               aal->aal_age = 0;
-               aal->aal_flags = 1;             /* complete */
-           case AARPOP_PROBE :
-               aarp_send( aid, AARPOP_RESPONSE, ea->aarp_sha,
-                       spnet, ea->aarp_spnode );
-               break;
-
-           case AARPOP_RESPONSE :
-               if (( aal =
-                       aarp_find( aid, spnet, ea->aarp_spnode )) == NULL ) {
-                   break;
-               }
-               bcopy( ea->aarp_sha, aal->aal_hwaddr, sizeof( ea->aarp_sha ));
-               aal->aal_age = 0;
-               aal->aal_flags = 1;             /* complete */
-               if ( aal->aal_m != NULL ) {
-                   dl_unitdata_req( WR( q ), aal->aal_m, ETHERTYPE_AT,
-                           aal->aal_hwaddr );
-                   aal->aal_m = NULL;
-               }
-               break;
-
-           default :
-               cmn_err( CE_NOTE, "aarp_rput bad op %X\n", op );
-               break;
-           }
-       } else {
-           switch ( op ) {
-           case AARPOP_REQUEST :
-               break;
-           case AARPOP_PROBE :
-               if (( aal =
-                       aarp_find( aid, spnet, ea->aarp_spnode )) != NULL ) {
-                   aarp_free( aid, aal );
-               }
-               break;
-
-           case AARPOP_RESPONSE :
-               cmn_err( CE_NOTE, "aarp_rput someone using our address\n" );
-               break;
-
-           default :
-               cmn_err( CE_NOTE, "aarp_rput bad op %X\n", op );
-               break;
-           }
-       }
-    }
-
-done :
-    freemsg( m );
-    return( 0 );
-}
-
-    void
-aarp_send( struct atif_data *aid, int op, caddr_t hwaddr,
-       ushort net, unchar node )
-{
-    mblk_t             *m;
-    struct ether_aarp  *ea;
-
-    if (( m = allocb( sizeof( struct ether_aarp ), BPRI_HI )) == NULL ) {
-       return;
-    }
-    m->b_wptr = m->b_rptr + sizeof( struct ether_aarp );
-    ea = (struct ether_aarp *)m->b_rptr;
-    bzero( (caddr_t)ea, sizeof( struct ether_aarp ));
-
-    ea->aarp_hrd = htons( AARPHRD_ETHER );
-    ea->aarp_pro = htons( ETHERTYPE_AT );
-    ea->aarp_hln = sizeof( ea->aarp_sha );
-    ea->aarp_pln = sizeof( ea->aarp_spu );
-    ea->aarp_op = htons( op );
-    bcopy( aid->aid_hwaddr, ea->aarp_sha, sizeof( ea->aarp_sha ));
-
-    if ( hwaddr == NULL ) {
-       bzero( ea->aarp_tha, sizeof( ea->aarp_tha ));
-    } else {
-       bcopy( hwaddr, ea->aarp_tha, sizeof( ea->aarp_tha ));
-    }
-
-    ea->aarp_tpnode = node;
-    bcopy( &aid->aid_sat.sat_addr.s_net, ea->aarp_spnet,
-           sizeof( ea->aarp_spnet ));
-    bcopy( &net, ea->aarp_tpnet, sizeof( ea->aarp_tpnet ));
-    ea->aarp_spnode = aid->aid_sat.sat_addr.s_node;
-    ea->aarp_tpnode = node;
-
-    if ( hwaddr == NULL ) {
-       dl_unitdata_req( WR( aid->aid_q ), m, ETHERTYPE_AARP,
-               at_multicastaddr );
-    } else {
-       dl_unitdata_req( WR( aid->aid_q ), m, ETHERTYPE_AARP, hwaddr );
-    }
-    return;
-}
-
-    int
-aarp_resolve( struct atif_data *aid, mblk_t *m, struct sockaddr_at *sat )
-{
-    struct aarplist    *aal;
-
-    if ( sat->sat_addr.s_node == ATADDR_BCAST ) {
-       dl_unitdata_req( WR( aid->aid_q ), m, ETHERTYPE_AT, at_multicastaddr );
-       return( 0 );
-    }
-
-    if (( aal = aarp_alloc( aid, sat->sat_addr.s_net, sat->sat_addr.s_node )) ==
-           NULL ) {
-       freemsg( m );
-       return( ENOMEM );
-    }
-    aal->aal_age = 0;
-
-    if ( aal->aal_flags ) {    /* complete */
-       dl_unitdata_req( WR( aid->aid_q ), m, ETHERTYPE_AT, aal->aal_hwaddr );
-    } else {
-       /* send aarp request */
-       if ( aal->aal_m != NULL ) {
-           freemsg( aal->aal_m );
-       }
-       /* either freed above, in timeout, or sent in aarp_rput() */
-       aal->aal_m = m; 
-       aarp_send( aid, AARPOP_REQUEST, NULL,
-               sat->sat_addr.s_net, sat->sat_addr.s_node );
-    }
-    return( 0 );
-}
diff --git a/sys/solaris/ddp.c b/sys/solaris/ddp.c
deleted file mode 100644 (file)
index 526c5f8..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * $Id: ddp.c,v 1.3 2002-01-17 06:13:02 srittau Exp $
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <sys/types.h>
-#include <sys/stream.h>
-#include <sys/cmn_err.h>
-#include <sys/socket.h>
-#include <sys/errno.h>
-#include <sys/tihdr.h>
-#include <sys/ddi.h>
-#include <sys/ethernet.h>
-#include <net/if.h>
-
-#ifdef STDC_HEADERS
-#include <strings.h>
-#else
-#include <string.h>
-#endif
-
-#include <netatalk/endian.h>
-#include <netatalk/ddp.h>
-#include <netatalk/at.h>
-
-#include "if.h"
-#include "sock.h"
-
-    int
-ddp_rput( struct atif_data *aid, mblk_t *m )
-{
-    struct atif_data   *daid;
-    struct ddpehdr     *deh;
-    struct sockaddr_at sat;
-    struct sock_data   *sd;
-
-    if ( m->b_wptr - m->b_rptr < sizeof( struct ddpehdr )) {
-       cmn_err( CE_NOTE, "ddp_rput short packet\n" );
-       freemsg( m );
-       return( EINVAL );
-    }
-
-    deh = (struct ddpehdr *)m->b_rptr;
-
-    sat.sat_addr.s_net = deh->deh_dnet;
-    sat.sat_addr.s_node = deh->deh_dnode;
-    sat.sat_port = deh->deh_dport;
-
-    if (( daid = if_dest( aid, &sat )) != NULL ) {
-       if (( sd = sock_dest( daid, &sat )) != NULL ) {
-           if ( sd->sd_state != TS_IDLE ) {
-               freemsg( m );
-               return( EHOSTDOWN );
-           }
-           bzero( (caddr_t)&sat, sizeof( struct sockaddr_at ));
-           sat.sat_family = AF_APPLETALK;
-           sat.sat_addr.s_net = deh->deh_snet;
-           sat.sat_addr.s_node = deh->deh_snode;
-           sat.sat_port = deh->deh_sport;
-           adjmsg( m, sizeof( struct ddpehdr ));
-           t_unitdata_ind( WR( sd->sd_q ), m, &sat );
-       } else {
-           /* toss it */
-           freemsg( m );
-           return( EHOSTDOWN );
-       }
-    } else {
-       /* route it */
-       freemsg( m );
-       return( ENETUNREACH );
-    }
-    return( 0 );
-}
diff --git a/sys/solaris/ddp.conf b/sys/solaris/ddp.conf
deleted file mode 100644 (file)
index e0257ad..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-#
-# Netatalk driver's configuration file
-#
-
-name="ddp" parent="pseudo" instance=0;
diff --git a/sys/solaris/dlpi.c b/sys/solaris/dlpi.c
deleted file mode 100644 (file)
index 2be6de3..0000000
+++ /dev/null
@@ -1,478 +0,0 @@
-/* $Id: dlpi.c,v 1.2 2002-01-17 06:13:02 srittau Exp $
- */
-
-#include <config.h>
-
-#include <sys/types.h>
-#include <sys/kmem.h>
-#include <sys/stream.h>
-#include <sys/conf.h>
-#include <sys/modctl.h>
-#include <sys/cmn_err.h>
-#include <sys/ddi.h>
-#include <sys/socket.h>
-#include <sys/sockio.h>
-#include <sys/dlpi.h>
-#include <sys/ethernet.h>
-#include <sys/byteorder.h>
-#include <sys/sunddi.h>
-#include <net/if.h>
-#include <errno.h>
-
-#include <netatalk/phase2.h>
-#include <netatalk/at.h>
-
-#include "ioc.h"
-#include "if.h"
-
-u_char at_multicastaddr[ ETHERADDRL ] = {
-    0x09, 0x00, 0x07, 0xff, 0xff, 0xff,
-};
-u_char at_org_code[ 3 ] = {
-    0x08, 0x00, 0x07,
-};
-u_char aarp_org_code[ 3 ] = {
-    0x00, 0x00, 0x00,
-};
-
-    static int
-dlpi_open( queue_t *q, dev_t *dev, int oflag, int sflag, cred_t *cred )
-{
-    struct atif_data   *aid;
-    int                        err = 0;
-
-    if (( err = drv_priv( cred )) != 0 ) {
-       return( err );
-    }
-    if (( aid = if_alloc( q )) == NULL ) {
-       return( ENOMEM );
-    }
-    q->q_ptr = (void *)aid;
-
-    qprocson( q );
-    return( err );
-}
-
-    static int
-dlpi_close( queue_t *q, int oflag, cred_t *cred )
-{
-    struct atif_data   *aid = (struct atif_data *)q->q_ptr;
-
-    qprocsoff( q );
-    if_free( aid );
-    return( 0 );
-}
-
-    static int
-dl_bind_req( queue_t *q, ulong sap )
-{
-    union DL_primitives        *dl;
-    mblk_t             *m;
-
-    if (( m = allocb( DL_BIND_REQ_SIZE, BPRI_HI )) == NULL ) {
-       return( ENOMEM );
-    }
-    m->b_wptr = m->b_rptr + DL_BIND_REQ_SIZE;
-    m->b_datap->db_type = M_PROTO;
-
-    dl = (union DL_primitives *)m->b_rptr;
-    dl->dl_primitive = DL_BIND_REQ;
-    dl->bind_req.dl_sap = sap;
-    dl->bind_req.dl_max_conind = 0;
-    dl->bind_req.dl_service_mode = DL_CLDLS;
-    dl->bind_req.dl_conn_mgmt = 0;
-    dl->bind_req.dl_xidtest_flg = 0;   /* XXX */
-    putnext( q, m );
-    return( 0 );
-}
-
-    static int
-dl_attach_req( queue_t *q, ulong ppa )
-{
-    union DL_primitives        *dl;
-    mblk_t             *m;
-
-    if (( m = allocb( DL_ATTACH_REQ_SIZE, BPRI_HI )) == NULL ) {
-       return( ENOMEM );
-    }
-    m->b_wptr = m->b_rptr + DL_ATTACH_REQ_SIZE;
-    m->b_datap->db_type = M_PROTO;
-
-    dl = (union DL_primitives *)m->b_rptr;
-    dl->dl_primitive = DL_ATTACH_REQ;
-    dl->attach_req.dl_ppa = ppa;
-    putnext( q, m );
-    return( 0 );
-}
-
-    int
-dl_enabmulti_req( queue_t *q, caddr_t addr )
-{
-    union DL_primitives        *dl;
-    mblk_t             *m;
-
-    if (( m = allocb( DL_ENABMULTI_REQ_SIZE + ETHERADDRL, BPRI_HI )) == NULL ) {
-       return( ENOMEM );
-    }
-    m->b_wptr = m->b_rptr + DL_ENABMULTI_REQ_SIZE;
-    m->b_datap->db_type = M_PROTO;
-
-    dl = (union DL_primitives *)m->b_rptr;
-    dl->dl_primitive = DL_ENABMULTI_REQ;
-    dl->enabmulti_req.dl_addr_length = ETHERADDRL;
-    dl->enabmulti_req.dl_addr_offset = m->b_wptr - m->b_rptr;
-    bcopy( addr, m->b_wptr, ETHERADDRL );
-    m->b_wptr += ETHERADDRL;
-    putnext( q, m );
-    return( 0 );
-}
-
-    int
-dl_unitdata_req( queue_t *q, mblk_t *m0, ushort type, caddr_t addr )
-{
-    union DL_primitives        *dl;
-    struct llc         *llc;
-    mblk_t             *m1, *m;
-    ushort              len;
-
-    /* len = msgdsize( m0 ) + sizeof( struct llc ); */
-
-    if (( m1 = allocb( sizeof( struct llc ), BPRI_HI )) == NULL ) {
-       cmn_err( CE_NOTE, "dl_unitdate_req NOMEM 1\n" );
-       return( ENOMEM );
-    }
-    m1->b_wptr = m1->b_rptr + sizeof( struct llc );
-    m1->b_datap->db_type = M_DATA;
-    llc = (struct llc *)m1->b_rptr;
-
-    llc->llc_dsap = llc->llc_ssap = LLC_SNAP_LSAP;
-    llc->llc_control = LLC_UI;
-    if ( type == ETHERTYPE_AARP ) {
-       bcopy( aarp_org_code, llc->llc_org_code, sizeof( aarp_org_code ));
-    } else if ( type == ETHERTYPE_AT ) {
-       bcopy( at_org_code, llc->llc_org_code, sizeof( aarp_org_code ));
-    } else {
-       cmn_err( CE_NOTE, "dl_unitdate_req type %X\n", type );
-       return( EINVAL );
-    }
-    llc->llc_ether_type = htons( type );
-    linkb( m1, m0 );
-
-    if (( m = allocb( DL_UNITDATA_REQ_SIZE + ETHERADDRL + sizeof( ushort ),
-                     BPRI_HI )) == NULL ) {
-       cmn_err( CE_NOTE, "dl_unitdate_req NOMEM 2\n" );
-       return( ENOMEM );
-    }
-    m->b_wptr = m->b_rptr + DL_UNITDATA_REQ_SIZE;
-    m->b_datap->db_type = M_PROTO;
-    linkb( m, m1 );
-
-    dl = (union DL_primitives *)m->b_rptr;
-    dl->dl_primitive = DL_UNITDATA_REQ;
-    dl->unitdata_req.dl_dest_addr_length = ETHERADDRL + sizeof ( ushort );
-    dl->unitdata_req.dl_dest_addr_offset = m->b_wptr - m->b_rptr;
-
-    bcopy(addr, m->b_wptr, ETHERADDRL );
-    m->b_wptr += ETHERADDRL;
-    len = 0;
-    bcopy( &len, m->b_wptr, sizeof( ushort ));
-    m->b_wptr += sizeof( ushort );
-    putnext( q, m );
-    return( 0 );
-}
-
-    static int
-dlpi_rput( queue_t *q, mblk_t *m )
-{
-    struct atif_data   *aid = (struct atif_data *)q->q_ptr;
-    union DL_primitives        *dl;
-    mblk_t             *m0;
-    struct llc         *llc;
-
-    switch ( m->b_datap->db_type ) {
-    case M_IOCNAK :
-       putnext( q, m );
-       return( 0 );
-
-    case M_PCPROTO :
-    case M_PROTO :
-       if ( m->b_wptr - m->b_rptr < sizeof( dl->dl_primitive )) {
-           break;
-       }
-       dl = (union DL_primitives *)m->b_rptr;
-       switch ( dl->dl_primitive ) {
-       case DL_UNITDATA_IND :
-           if ( m->b_wptr - m->b_rptr < sizeof( DL_UNITDATA_IND_SIZE )) {
-               break;
-           }
-           if (( m0 = unlinkb( m )) == NULL ) {
-               break;
-           }
-           if ( m0->b_wptr - m0->b_rptr < sizeof( struct llc )) {
-               freemsg( m0 );
-               break;
-           }
-           llc = (struct llc *)m0->b_rptr;
-           if ( llc->llc_dsap != LLC_SNAP_LSAP ||
-                   llc->llc_ssap != LLC_SNAP_LSAP ||
-                   llc->llc_control != LLC_UI ) {
-               freemsg( m0 );
-               break;
-           }
-
-           if ( bcmp( llc->llc_org_code, at_org_code,
-                   sizeof( at_org_code )) == 0 &&
-                   ntohs( llc->llc_ether_type ) == ETHERTYPE_AT ) {
-               adjmsg( m0, sizeof( struct llc ));
-               ddp_rput( aid, m0 );
-           } else if ( bcmp( llc->llc_org_code, aarp_org_code,
-                   sizeof( aarp_org_code )) == 0 &&
-                   ntohs( llc->llc_ether_type ) == ETHERTYPE_AARP ) {
-               adjmsg( m0, sizeof( struct llc ));
-               aarp_rput( q, m0 );
-           } else {
-               freemsg( m0 );
-           }
-           break;
-
-       case DL_OK_ACK :
-           if ( m->b_wptr - m->b_rptr < sizeof( DL_OK_ACK_SIZE )) {
-               break;
-           }
-           switch ( dl->ok_ack.dl_correct_primitive ) {
-           case DL_ATTACH_REQ :
-               if ( aid->aid_state != DL_ATTACH_PENDING ) {
-                   cmn_err( CE_NOTE, "dlpi_rput DL_OK_ACK attach state %d\n",
-                           aid->aid_state );
-                   break;
-               }
-               if ( aid->aid_c.c_type != IF_UNITSEL ) {
-                   cmn_err( CE_NOTE, "dlpi_rput DL_OK_ACK attach context %x\n",
-                           aid->aid_c.c_type );
-                   break;
-               }
-
-               if ( WR(q)->q_next == NULL || WR(q)->q_next->q_qinfo == NULL ||
-                       WR(q)->q_next->q_qinfo->qi_minfo == NULL ||
-                       WR(q)->q_next->q_qinfo->qi_minfo->mi_idname == NULL ) {
-                   cmn_err( CE_NOTE, "dlpi_rput can't get interface name\n" );
-                   break;
-               }
-
-               if_name( aid, WR(q)->q_next->q_qinfo->qi_minfo->mi_idname,
-                       aid->aid_c.c_u.u_unit.uu_ppa );
-
-               aid->aid_state = DL_BIND_PENDING;
-
-#ifdef i386
-               /*
-                * As of Solaris 7 (nice name), the i386 arch needs to be
-                * bound as 0 to receive 802 frames.  However, in the same
-                * OS, Sparcs must be bound as ETHERMTU (or at least not 0)
-                * to receive the same frames.  A bug?  In the Solaris 7
-                * (nice name) kernel?
-                */
-               dl_bind_req( WR( q ), 0 );
-#else /* i386 */
-               dl_bind_req( WR( q ), ETHERMTU );
-#endif /* i386 */
-               break;
-
-           case DL_ENABMULTI_REQ :
-               if ( aid->aid_c.c_type != SIOCADDMULTI ) {
-                   cmn_err( CE_NOTE,
-                           "dlpi_rput DL_OK_ACK enabmulti context %x\n",
-                           aid->aid_c.c_type );
-                   break;
-               }
-
-               ioc_ok_ack( aid->aid_c.c_u.u_multi.um_q,
-                       aid->aid_c.c_u.u_multi.um_m, 0 );
-               aid->aid_c.c_type = 0;
-               aid->aid_c.c_u.u_multi.um_q = NULL;
-               aid->aid_c.c_u.u_multi.um_m = 0;
-               break;
-
-           default :
-               cmn_err( CE_CONT, "!dlpi_rput DL_OK_ACK unhandled %d\n",
-                       dl->ok_ack.dl_correct_primitive );
-               break;
-           }
-           break;
-
-       case DL_BIND_ACK :
-           if ( m->b_wptr - m->b_rptr < sizeof( DL_BIND_ACK_SIZE )) {
-               break;
-           }
-           if ( aid->aid_state != DL_BIND_PENDING ) {
-               break;
-           }
-           if ( aid->aid_c.c_type != IF_UNITSEL ) {
-               break;
-           }
-           bcopy( m->b_rptr + dl->bind_ack.dl_addr_offset, aid->aid_hwaddr, 
-                   dl->bind_ack.dl_addr_length );
-           aid->aid_state = DL_IDLE;
-           ioc_ok_ack( WR(q), aid->aid_c.c_u.u_unit.uu_m, 0 );
-           aid->aid_c.c_type = 0;
-           aid->aid_c.c_u.u_unit.uu_m = NULL;
-           aid->aid_c.c_u.u_unit.uu_ppa = 0;
-           break;
-
-       case DL_ERROR_ACK :
-           if ( m->b_wptr - m->b_rptr < sizeof( DL_ERROR_ACK_SIZE )) {
-               break;
-           }
-
-           switch ( aid->aid_c.c_type ) {
-           case IF_UNITSEL :
-               if ( dl->error_ack.dl_errno == DL_SYSERR ) {
-                   ioc_error_ack( WR(q), aid->aid_c.c_u.u_unit.uu_m,
-                           dl->error_ack.dl_unix_errno );
-               } else {
-                   cmn_err( CE_CONT, "dlpi_rput DL_ERROR_ACK 0x%x\n",
-                           dl->error_ack.dl_errno );
-                   ioc_error_ack( WR(q), aid->aid_c.c_u.u_unit.uu_m, EINVAL );
-               }
-               aid->aid_c.c_type = 0;
-               aid->aid_c.c_u.u_unit.uu_m = NULL;
-               aid->aid_c.c_u.u_unit.uu_ppa = 0;
-               break;
-
-           default :
-               cmn_err( CE_NOTE, "dlpi_rput DL_ERROR_ACK unhandled %d %d %d\n",
-                       dl->error_ack.dl_error_primitive,
-                       dl->error_ack.dl_errno, dl->error_ack.dl_unix_errno );
-               break;
-           }
-           break;
-
-       default :
-           cmn_err( CE_NOTE, "dlpi_rput M_PCPROTO 0x%x\n", dl->dl_primitive );
-           break;
-       }
-       break;
-
-    default :
-       cmn_err( CE_NOTE, "dlpi_rput 0x%X\n", m->b_datap->db_type );
-       break;
-    }
-
-    freemsg( m );
-    return( 0 );
-}
-
-    static int
-dlpi_wput( queue_t *q, mblk_t *m )
-{
-    struct atif_data           *aid = (struct atif_data *)RD(q)->q_ptr;
-    struct iocblk              *ioc;
-    int                                rc;
-
-    switch ( m->b_datap->db_type ) {
-    case M_IOCTL :
-       if ( m->b_wptr - m->b_rptr < sizeof( struct iocblk )) {
-           freemsg( m );
-           break;
-       }
-       ioc = (struct iocblk *)m->b_rptr;
-       switch ( ioc->ioc_cmd ) {
-       case IF_UNITSEL :
-           if ( ioc->ioc_count != TRANSPARENT ) {
-               cmn_err( CE_NOTE, "dlpi_wput IF_UNITSEL non-TRANSPARENT\n" );
-               ioc_error_ack( q, m, EINVAL );
-               break;
-           }
-           if ( m->b_cont == NULL ) {
-               cmn_err( CE_NOTE, "dlpi_wput IF_UNITSEL no arg\n" );
-               ioc_error_ack( q, m, EINVAL );
-               break;
-           }
-           if ( aid->aid_state != DL_UNATTACHED ) {
-               cmn_err( CE_NOTE, "dlpi_wput IF_UNITSEL already attached\n" );
-               ioc_error_ack( q, m, EINVAL );
-               break;
-           }
-           if ( aid->aid_c.c_type != 0 ) {
-               cmn_err( CE_NOTE, "dlpi_wput IF_UNITSEL context %x\n",
-                       aid->aid_c.c_type );
-               ioc_error_ack( q, m, EINVAL );
-               break;
-           }
-
-           aid->aid_state = DL_ATTACH_PENDING;
-           aid->aid_c.c_type = IF_UNITSEL;
-           aid->aid_c.c_u.u_unit.uu_m = m;
-           aid->aid_c.c_u.u_unit.uu_ppa = *(ulong *)m->b_cont->b_rptr;
-           if (( rc = dl_attach_req( q, aid->aid_c.c_u.u_unit.uu_ppa )) < 0 ) {
-               ioc_error_ack( q, m, rc );
-               break;
-           }
-           break;
-
-       default :
-           cmn_err( CE_NOTE, "dlpi_wput M_IOCTL 0x%X\n", ioc->ioc_cmd );
-           putnext( q, m );
-           break;
-       }
-       break;
-
-    default :
-       cmn_err( CE_NOTE, "dlpi_wput 0x%X\n", m->b_datap->db_type );
-       freemsg( m );
-       break;
-    }
-
-    return( 0 );
-}
-
-static struct module_info      dlpi_info = {
-    0,
-    "ddp",
-    0,
-    1500,
-    3000,
-    64
-};
-
-static struct qinit            dlpi_rinit = {
-    dlpi_rput,         /* qi_putp */
-    NULL,              /* qi_srvp */
-    dlpi_open,         /* qi_qopen */
-    dlpi_close,                /* qi_qclose */
-    NULL,
-    &dlpi_info,                /* qi_minfo */
-    NULL,
-};
-
-static struct qinit            dlpi_winit = {
-    dlpi_wput,         /* qi_putp */
-    NULL,              /* qi_srvp */
-    NULL,              /* qi_qopen */
-    NULL,              /* qi_qclose */
-    NULL,
-    &dlpi_info,                /* qi_minfo */
-    NULL,
-};
-
-static struct streamtab                dlpi_stream = {
-    &dlpi_rinit,
-    &dlpi_winit,
-    NULL,
-    NULL
-};
-
-static struct fmodsw           dlpi_fmodsw = {
-    "ddp",
-    &dlpi_stream,
-    D_NEW | D_MP | D_MTPERMOD
-};
-
-/*
- * DDP Streams module.  This module is pushed on DLPI drivers by atalkd.
- */
-struct modlstrmod              dlpi_lstrmod = {
-    &mod_strmodops,
-    "DDP Streams module",
-    &dlpi_fmodsw,
-};
diff --git a/sys/solaris/if.c b/sys/solaris/if.c
deleted file mode 100644 (file)
index 7e0918f..0000000
+++ /dev/null
@@ -1,382 +0,0 @@
-/* $Id: if.c,v 1.3 2005-04-28 20:50:07 bfernhomberg Exp $
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/sockio.h>
-#include <sys/stream.h>
-#include <sys/kmem.h>
-#include <sys/dlpi.h>
-#include <sys/cmn_err.h>
-#include <sys/errno.h>
-#include <sys/byteorder.h>
-#include <sys/ethernet.h>
-#include <sys/ddi.h>
-#include <net/if.h>
-#include <netinet/arp.h>
-
-#ifdef STDC_HEADERS
-#include <strings.h>
-#else
-#include <string.h>
-#endif
-
-#include <netatalk/at.h>
-#include <netatalk/aarp.h>
-
-#include "if.h"
-#include "rt.h"
-#include "ioc.h"
-
-static struct atif_data        *interfaces = NULL;
-
-    struct atif_data *
-if_primary()
-{
-    return( interfaces );
-}
-
-    struct atif_data *
-if_alloc( queue_t *q )
-{
-    struct atif_data   *aid;
-
-    if (( aid = kmem_zalloc( sizeof( struct atif_data ), KM_SLEEP )) == NULL ) {
-       return( NULL );
-    }
-    aid->aid_q = q;
-    aid->aid_state = DL_UNATTACHED;
-
-    return( aid );
-}
-
-/*
- * Name an interface, insert it in our list of interfaces.  If this is the
- * first interface, create the loopback interface.  If it's not the first
- * interfaces, keep the first interface the same, i.e. the first configured
- * interface should be the primary interface.
- */
-    int
-if_name( struct atif_data *aid, char *name, ulong ppa )
-{
-    sprintf( aid->aid_name, "%s%ld", name, ppa );
-
-    if ( interfaces == NULL ) {                /* create fake loopback */
-       if (( interfaces = if_alloc( NULL )) == NULL ) {
-           return( ENOMEM );
-       }
-       strcpy( interfaces->aid_name, "lo0" );
-       interfaces->aid_state = DL_IDLE;
-       bzero( interfaces->aid_hwaddr, sizeof( interfaces->aid_hwaddr ));
-       interfaces->aid_flags = AIDF_LOOPBACK;
-       interfaces->aid_c.c_type = 0;
-
-       aid->aid_next = interfaces;
-       aid->aid_next->aid_prev = aid;
-       interfaces = aid;
-    } else {
-       aid->aid_next = interfaces->aid_next;
-       aid->aid_prev = interfaces;
-       aid->aid_next->aid_prev = aid;
-       interfaces->aid_next = aid;
-    }
-
-    aarp_init( aid );
-    return( 0 );
-}
-
-    void
-if_free( struct atif_data *aid )
-{
-    if ( aid->aid_c.c_type != 0 ) {
-       cmn_err( CE_NOTE, "if_free context %x\n", aid->aid_c.c_type );
-       return;
-    }
-
-    aarp_clean( aid );
-
-    if ( aid->aid_next != NULL ) {
-       aid->aid_next->aid_prev = aid->aid_prev;
-    }
-    if ( aid->aid_prev != NULL ) {
-       aid->aid_prev->aid_next = aid->aid_next;
-    }
-    if ( aid == interfaces ) {
-       interfaces = aid->aid_next;
-    }
-    kmem_free( aid, sizeof( struct atif_data ));
-
-    if ( interfaces != NULL && interfaces->aid_next == NULL ) {
-       kmem_free( interfaces, sizeof( struct atif_data ));
-       interfaces = NULL;
-    }
-    return;
-}
-
-    int
-if_getaddr( char *name, struct sockaddr_at *sat )
-{
-    struct atif_data   *aid;
-
-    for ( aid = interfaces; aid != NULL; aid = aid->aid_next ) {
-       if ( strcmp( name, aid->aid_name ) == 0 ) {
-           break;
-       }
-    }
-    if ( aid == NULL ) {
-       return( EADDRNOTAVAIL );
-    }
-
-    bcopy( &aid->aid_sat, sat, sizeof( struct sockaddr_at ));
-    return( 0 );
-}
-
-    int
-if_addmulti( queue_t *q, mblk_t *m, char *name, struct sockaddr *sa )
-{
-    struct atif_data   *aid;
-
-    for ( aid = interfaces; aid != NULL; aid = aid->aid_next ) {
-       if ( strcmp( name, aid->aid_name ) == 0 ) {
-           break;
-       }
-    }
-    if ( aid == NULL ) {
-       return( EADDRNOTAVAIL );
-    }
-
-    if ( aid->aid_c.c_type != 0 ) {
-       cmn_err( CE_NOTE, "if_addmulti context %x\n", aid->aid_c.c_type );
-       return( EINVAL );
-    }
-
-    aid->aid_c.c_type = SIOCADDMULTI;
-    aid->aid_c.c_u.u_multi.um_q = q;
-    aid->aid_c.c_u.u_multi.um_m = m;
-    dl_enabmulti_req( WR( aid->aid_q ), sa->sa_data );
-
-    return( 0 );
-}
-
-    void
-if_pickaddr( void *ptr )
-{
-    struct atif_data *aid = (struct atif_data*) ptr;
-
-    if ( aid->aid_c.c_type != SIOCSIFADDR ) {
-       cmn_err( CE_NOTE, "if_pickaddr context %x\n", aid->aid_c.c_type );
-       return;
-    }
-
-    if ( aid->aid_flags & AIDF_PROBEFAILED ) {
-       aid->aid_flags &= ~AIDF_PROBEFAILED;
-       /* choose new address */
-       for (;;) {
-           if ( aid->aid_c.c_u.u_addr.ua_nodecnt == 0 ) {
-               /* if we've exausted all addresses, fail */
-               if ( aid->aid_c.c_u.u_addr.ua_netcnt == 0 ) {
-                   ioc_error_ack( aid->aid_c.c_u.u_addr.ua_q,
-                           aid->aid_c.c_u.u_addr.ua_m, EADDRINUSE );
-                   aid->aid_c.c_type = 0;
-                   aid->aid_c.c_u.u_addr.ua_q = NULL;
-                   aid->aid_c.c_u.u_addr.ua_m = NULL;
-                   aid->aid_c.c_u.u_addr.ua_probecnt = 0;
-                   aid->aid_c.c_u.u_addr.ua_netcnt = 0;
-                   aid->aid_c.c_u.u_addr.ua_nodecnt = 0;
-               } else {
-                   aid->aid_c.c_u.u_addr.ua_nodecnt = 256;
-                   aid->aid_c.c_u.u_addr.ua_netcnt--;
-                   if ( ntohs(aid->aid_sat.sat_addr.s_net) >
-                           ntohs(aid->aid_nr.nr_lastnet) ) {
-                       aid->aid_sat.sat_addr.s_net = aid->aid_nr.nr_firstnet;
-                   } else
-                     aid->aid_sat.sat_addr.s_net = 
-                       htons(ntohs(aid->aid_sat.sat_addr.s_net) + 1);
-               }
-           } else {
-               aid->aid_sat.sat_addr.s_node++;
-               aid->aid_c.c_u.u_addr.ua_nodecnt--;
-               if ( aid->aid_sat.sat_addr.s_node == 0 || 
-                       aid->aid_sat.sat_addr.s_node == 255 || 
-                       aid->aid_sat.sat_addr.s_node == 254 ) {
-                   continue;
-               }
-               break;
-           }
-       }
-    }
-    if ( aid->aid_c.c_u.u_addr.ua_probecnt-- <= 0 ) {
-       aid->aid_flags &= ~AIDF_PROBING;
-       /* worked, send ioctl reponse */
-       ioc_ok_ack( aid->aid_c.c_u.u_addr.ua_q, aid->aid_c.c_u.u_addr.ua_m, 0 );
-       aid->aid_c.c_type = 0;
-       aid->aid_c.c_u.u_addr.ua_q = NULL;
-       aid->aid_c.c_u.u_addr.ua_m = NULL;
-       aid->aid_c.c_u.u_addr.ua_probecnt = 0;
-       aid->aid_c.c_u.u_addr.ua_netcnt = 0;
-       aid->aid_c.c_u.u_addr.ua_nodecnt = 0;
-       return;
-    }
-
-    aarp_send( aid, AARPOP_PROBE, NULL,
-           aid->aid_sat.sat_addr.s_net, aid->aid_sat.sat_addr.s_node );
-    qtimeout( aid->aid_q, if_pickaddr, (caddr_t)aid, hz / 5 );
-}
-
-    int
-if_setaddr( queue_t *q, mblk_t *m, char *name, struct sockaddr_at *sat )
-{
-    struct atif_data   *aid;
-    struct netrange    nr;
-    ulong              time;
-
-    for ( aid = interfaces; aid != NULL; aid = aid->aid_next ) {
-       if ( strcmp( name, aid->aid_name ) == 0 ) {
-           break;
-       }
-    }
-    if ( aid == NULL ) {
-       return( EADDRNOTAVAIL );
-    }
-
-    if ( aid->aid_c.c_type != 0 ) {
-       cmn_err( CE_NOTE, "if_setaddr context %x\n", aid->aid_c.c_type );
-       return( EINVAL );
-    }
-
-    bcopy( sat->sat_zero, &nr, sizeof( struct netrange ));
-
-    if ( aid->aid_flags & AIDF_LOOPBACK ) {
-       aid->aid_sat = *sat;
-       aid->aid_nr = nr;
-
-       /* routes? */
-
-       ioc_ok_ack( q, m, 0 );
-       return( 0 );
-    }
-
-    drv_getparm( TIME, &time );
-    if ( sat->sat_addr.s_net == ATADDR_ANYNET ) {
-       if ( nr.nr_lastnet == nr.nr_firstnet ) {
-           sat->sat_addr.s_net = nr.nr_firstnet;
-       } else {
-           sat->sat_addr.s_net = htons(ntohs(nr.nr_firstnet) + time %
-                   (ntohs(nr.nr_lastnet) - ntohs(nr.nr_firstnet)));
-       }
-    } else {
-       if ( ntohs( sat->sat_addr.s_net ) < ntohs( nr.nr_firstnet ) ||
-               ntohs( sat->sat_addr.s_net ) > ntohs( nr.nr_lastnet )) {
-           return( EINVAL );
-       }
-    }
-
-    if ( sat->sat_addr.s_node == ATADDR_ANYNODE ) {
-       sat->sat_addr.s_node = time;
-    }
-
-    aid->aid_flags |= AIDF_PROBING;
-    aid->aid_sat = *sat;
-    aid->aid_nr = nr;
-
-    aid->aid_c.c_type = SIOCSIFADDR;
-    aid->aid_c.c_u.u_addr.ua_q = q;
-    aid->aid_c.c_u.u_addr.ua_m = m;
-    aid->aid_c.c_u.u_addr.ua_probecnt = 10;
-    aid->aid_c.c_u.u_addr.ua_netcnt = ntohs(nr.nr_lastnet) - 
-      ntohs(nr.nr_firstnet);
-    aid->aid_c.c_u.u_addr.ua_nodecnt = 256;
-    qtimeout( aid->aid_q, if_pickaddr, (caddr_t)aid, 0 );
-    return( 0 );
-}
-
-/*
- * These three routines are all a big mess...
- */
-    struct atif_data *
-if_dest( struct atif_data *aid, struct sockaddr_at *sat )
-{
-    struct atif_data   *dest;
-
-    for ( dest = interfaces; dest != NULL; dest = dest->aid_next ) {
-       if ((( sat->sat_addr.s_net == 0 && aid == dest ) ||
-               ( ntohs(sat->sat_addr.s_net) >= 
-                 ntohs(dest->aid_nr.nr_firstnet) &&
-               ntohs(sat->sat_addr.s_net) <= 
-                 ntohs(dest->aid_nr.nr_lastnet) )) &&
-               ( sat->sat_addr.s_node == dest->aid_sat.sat_addr.s_node ||
-               sat->sat_addr.s_node == ATADDR_BCAST )) {
-           break;
-       }
-    }
-    if ( dest == NULL ) {
-       return( NULL );
-    }
-    return( dest );
-}
-
-    struct atif_data *
-if_withaddr( struct sockaddr_at *sat )
-{
-    struct atif_data   *dest;
-
-    for ( dest = interfaces; dest != NULL; dest = dest->aid_next ) {
-       if ( sat->sat_addr.s_net == dest->aid_sat.sat_addr.s_net &&
-               sat->sat_addr.s_node == dest->aid_sat.sat_addr.s_node ) {
-           break;
-       }
-    }
-    return( dest );
-}
-
-    struct atif_data *
-if_withnet( struct sockaddr_at *sat )
-{
-    struct atif_data   *dest;
-
-    for ( dest = interfaces; dest != NULL; dest = dest->aid_next ) {
-       if ( ntohs(sat->sat_addr.s_net) >= ntohs(dest->aid_nr.nr_firstnet) &&
-               ntohs(sat->sat_addr.s_net) <= ntohs(dest->aid_nr.nr_lastnet)) {
-           break;
-       }
-    }
-    return( dest );
-}
-
-    int
-if_route( struct atif_data *aid, mblk_t *m, struct sockaddr_at *sat )
-{
-    struct sockaddr_at gate;
-
-    if ( sat->sat_addr.s_net == 0 ) {
-       if ( sat->sat_addr.s_node == 0 ) {
-           aid = if_withaddr( sat );
-       }
-       if ( aid == NULL ) {
-           freemsg( m );
-           return( ENETUNREACH );
-       }
-       gate = *sat;
-    } else {
-       if ( rt_gate( sat, &gate ) < 0 ) {      /* no route */
-           gate = *sat;
-       }
-       if (( aid = if_withaddr( &gate )) == NULL ) {
-           if (( aid = if_withnet( &gate )) == NULL ) {
-               freemsg( m );
-               return( ENETUNREACH );
-           }
-       }
-    }
-
-    if ( aid->aid_flags & AIDF_LOOPBACK ) {
-       return( ddp_rput( aid, m ));
-    } else {
-       /* the aarp layer is expected to send broadcast packets appropriately */
-       return( aarp_resolve( aid, m, &gate ));
-    }
-}
diff --git a/sys/solaris/if.h b/sys/solaris/if.h
deleted file mode 100644 (file)
index 0348d10..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-struct atif_data {
-    struct atif_data   *aid_next, *aid_prev;
-    char               aid_name[ IFNAMSIZ ];
-    unchar             aid_hwaddr[ ETHERADDRL ];
-    queue_t            *aid_q;                         /* RD() side */
-    int                        aid_state;
-    int                        aid_flags;
-    struct sockaddr_at aid_sat;
-    struct netrange    aid_nr;
-    struct aarplist    *aid_aarplist, *aid_aarpflist;
-    /* solaris 7 wants timeout_id_t, but solaris 2.6 doesn't have that.
-     * so, we compromise with an unsigned long as we know that's big
-     * enough to hold a pointer. */
-#ifdef HAVE_TIMEOUT_ID_T
-    timeout_id_t       aid_aarptimeo;
-#else
-    unsigned long      aid_aarptimeo;
-#endif
-    /*
-     * A little bit of cleverness, to overcome the inability of
-     * streams to sleep.  The type of context must be checked before
-     * the data is accessed.  The atif_data can't be freed if the
-     * type is non-zero.
-     */
-    struct {
-       int             c_type;                 /* ioctl command */
-       union {
-           struct {                            /* unit select */
-               mblk_t          *uu_m;
-               ulong           uu_ppa;
-           }           u_unit;
-           struct {                            /* set addr */
-               mblk_t          *ua_m;
-               queue_t         *ua_q;
-               int             ua_probecnt;
-               int             ua_netcnt;
-               int             ua_nodecnt;
-           }           u_addr;
-           struct {                            /* add multi */
-               mblk_t          *um_m;
-               queue_t         *um_q;
-           }           u_multi;
-       }               c_u;
-    }                  aid_c;
-};
-
-#define AIDF_LOOPBACK  (1<<0)
-#define AIDF_PROBING   (1<<1)
-#define AIDF_PROBEFAILED       (1<<2)
-
-extern u_char  at_multicastaddr[ ETHERADDRL ];
-extern u_char  at_org_code[ 3 ];
-extern u_char  aarp_org_code[ 3 ];
-
-int                    if_setaddr( queue_t *, mblk_t *, char *,
-                               struct sockaddr_at * );
-int                    if_getaddr(  char *, struct sockaddr_at * );
-int                    if_addmulti( queue_t *, mblk_t *, char *,
-                               struct sockaddr * );
-
-struct atif_data       *if_alloc( queue_t * );
-void                   if_free( struct atif_data * );
-int                    if_name( struct atif_data *, char *, ulong );
-int                    if_attach( struct atif_data *, char * );
-struct atif_data       *if_primary( void );
-struct atif_data       *if_dest( struct atif_data *, struct sockaddr_at * );
-struct atif_data       *if_withaddr( struct sockaddr_at * );
-struct atif_data       *if_withnet( struct sockaddr_at * );
-int                    if_route( struct atif_data *, mblk_t *,
-                               struct sockaddr_at * );
-
-int                    dl_unitdata_req( queue_t *, mblk_t *, ushort, caddr_t );
-int                    dl_enabmulti_req( queue_t *, caddr_t );
-void                   aarp_send( struct atif_data *, int, caddr_t,
-                               ushort, unchar );
-int                    aarp_rput( queue_t *, mblk_t * );
-int                    aarp_resolve( struct atif_data *, mblk_t *,
-                               struct sockaddr_at *);
-void                   aarp_init( struct atif_data * );
-void                   aarp_clean( struct atif_data * );
-int                    ddp_rput( struct atif_data *, mblk_t * );
diff --git a/sys/solaris/ioc.c b/sys/solaris/ioc.c
deleted file mode 100644 (file)
index 4a53f9a..0000000
+++ /dev/null
@@ -1,137 +0,0 @@
-/* $Id: ioc.c,v 1.3 2005-04-28 20:50:07 bfernhomberg Exp $
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <sys/types.h>
-#include <sys/stream.h>
-#include <sys/cmn_err.h>
-
-#ifdef STDC_HEADERS
-#include <strings.h>
-#else
-#include <string.h>
-#endif
-
-#include "ioc.h"
-
-    void
-ioc_ok_ack( queue_t *q, mblk_t *m, int rval )
-{
-    struct iocblk      *ioc;
-    mblk_t             *m0;
-
-    if (( m0 = unlinkb( m )) != NULL ) {
-       freemsg( m0 );
-    }
-
-    if ( m->b_wptr - m->b_rptr < sizeof( struct iocblk )) {
-       cmn_err( CE_CONT, "ioc_ok_ack too small\n" );
-       freemsg( m );
-       return;
-    }
-    m->b_datap->db_type = M_IOCACK;
-    m->b_wptr = m->b_rptr + sizeof( struct iocblk );
-    ioc = (struct iocblk *)m->b_rptr;
-    ioc->ioc_error = 0;
-    ioc->ioc_count = 0;
-    ioc->ioc_rval = rval;
-    qreply( q, m );
-    return;
-}
-
-    void
-ioc_error_ack( queue_t *q, mblk_t *m, int errno )
-{
-    struct iocblk      *ioc;
-    mblk_t             *m0;
-
-    if (( m0 = unlinkb( m )) != NULL ) {
-       freemsg( m0 );
-    }
-
-    if ( m->b_wptr - m->b_rptr < sizeof( struct iocblk )) {
-       cmn_err( CE_CONT, "ioc_error_ack too small\n" );
-       freemsg( m );
-       return;
-    }
-    m->b_datap->db_type = M_IOCNAK;
-    m->b_wptr = m->b_rptr + sizeof( struct iocblk );
-    ioc = (struct iocblk *)m->b_rptr;
-    ioc->ioc_error = errno;
-    ioc->ioc_count = 0;
-    ioc->ioc_rval = -1;
-    qreply( q, m );
-    return;
-}
-
-    void
-ioc_copyin( queue_t *q, mblk_t *m, mblk_t *private, caddr_t addr, uint size )
-{
-    struct copyreq     *cq;
-    mblk_t             *m0;
-
-    if (( m0 = unlinkb( m )) != NULL ) {
-       freemsg( m0 );
-    }
-
-#ifdef notdef
-    /* supposedly this will fit anyway */
-    if ( m->b_wptr - m->b_rptr < sizeof( struct copyreq )) {
-       cmn_err( CE_CONT, "ioc_copyin too small\n" );
-       freemsg( m );
-       return;
-    }
-#endif /* notdef */
-    m->b_datap->db_type = M_COPYIN;
-    m->b_wptr = m->b_rptr + sizeof( struct copyreq );
-    cq = (struct copyreq *)m->b_rptr;
-    cq->cq_addr = addr;
-    cq->cq_size = size;
-    cq->cq_flag = 0;
-    cq->cq_private = private;
-    qreply( q, m );
-    return;
-}
-
-    void
-ioc_copyout( queue_t *q, mblk_t *m, mblk_t *private, caddr_t data,
-       caddr_t addr, uint size )
-{
-    struct copyreq     *cq;
-    mblk_t             *m0;
-
-    if (( m0 = unlinkb( m )) != NULL ) {
-       freemsg( m0 );
-    }
-
-#ifdef notdef
-    /* supposedly this will fit anyway */
-    if ( m->b_wptr - m->b_rptr < sizeof( struct copyreq )) {
-       cmn_err( CE_CONT, "ioc_copyout too small\n" );
-       freemsg( m );
-       return;
-    }
-#endif /* notdef */
-    if (( m0 = allocb( size, BPRI_MED )) == NULL ) {
-       cmn_err( CE_CONT, "ioc_copyout nomem\n" );
-       freemsg( m );
-       return;
-    }
-    m0->b_wptr = m0->b_rptr + size;
-    bcopy( data, m0->b_rptr, size );
-    linkb( m, m0 );
-
-    m->b_datap->db_type = M_COPYOUT;
-    m->b_wptr = m->b_rptr + sizeof( struct copyreq );
-    cq = (struct copyreq *)m->b_rptr;
-    cq->cq_addr = addr;
-    cq->cq_size = size;
-    cq->cq_flag = 0;
-    cq->cq_private = private;
-
-    qreply( q, m );
-    return;
-}
diff --git a/sys/solaris/ioc.h b/sys/solaris/ioc.h
deleted file mode 100644 (file)
index 4b1424a..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-void ioc_ok_ack( queue_t *, mblk_t *, int );
-void ioc_error_ack( queue_t *, mblk_t *, int );
-void ioc_copyin( queue_t *, mblk_t *, mblk_t *, caddr_t, uint );
-void ioc_copyout( queue_t *, mblk_t *, mblk_t *, caddr_t, caddr_t, uint );
diff --git a/sys/solaris/linkage.c b/sys/solaris/linkage.c
deleted file mode 100644 (file)
index 7917607..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Linkage information.  Mostly this is Solaris specific, but not all.
- * Code to do real work is in other files, this file just has the crap
- * to get the real code loaded and called.
- */
-
-#include <sys/types.h>
-#include <sys/modctl.h>
-#include <sys/cmn_err.h>
-
-char   *netatalk_version = VERSION;
-
-extern struct modldrv tpi_ldrv;
-extern struct modldrv dlpi_lstrmod;
-
-static struct modlinkage       ddp_linkage = {
-    MODREV_1,
-    {
-       (void *)&tpi_ldrv,
-       (void *)&dlpi_lstrmod,
-       NULL,
-    }
-};
-
-/*
- * While these are code, they're mostly related to linkage, so
- * we leave them here.
- */
-    int
-_init( void )
-{
-    cmn_err( CE_CONT, "?netatalk %s\n", netatalk_version );
-    return( mod_install( &ddp_linkage ));
-}
-
-    int
- _info( struct modinfo *modinfop )
-{
-    return( mod_info( &ddp_linkage, modinfop ));
-}
-
-    int
-_fini( void )
-{
-    return( mod_remove( &ddp_linkage ));
-}
diff --git a/sys/solaris/rt.c b/sys/solaris/rt.c
deleted file mode 100644 (file)
index 95bd1e2..0000000
+++ /dev/null
@@ -1,125 +0,0 @@
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <sys/cmn_err.h>
-#include <sys/kmem.h>
-#include <net/route.h>
-#include <netatalk/at.h>
-#include <errno.h>
-
-#include "rt.h"
-
-struct rtab {
-    struct rtab                *r_next, *r_prev;
-    struct sockaddr_at r_dst;
-    struct sockaddr_at r_gate;
-};
-
-static struct rtab     *rt_net = NULL;
-static struct rtab     *rt_host = NULL;
-
-    int
-rt_add( struct sockaddr_at *dst, struct sockaddr_at *gate, int flags )
-{
-    struct rtab                *r;
-    struct rtab                *rtab;
-
-    if ( flags & RTF_HOST ) {
-       rtab = rt_host;
-    } else {
-       rtab = rt_net;
-    }
-    for ( r = rtab; r != NULL; r = r->r_next ) {
-       if (( r->r_dst.sat_addr.s_net == dst->sat_addr.s_net ) &&
-               (( flags & RTF_HOST ) ?
-               r->r_dst.sat_addr.s_node == dst->sat_addr.s_node : 1 )) {
-           return( EEXIST );
-       }
-    }
-
-    if (( r = kmem_alloc( sizeof( struct rtab ), KM_NOSLEEP )) == NULL ) {
-       return( ENOMEM );
-    }
-    r->r_dst = *dst;
-    r->r_gate = *gate;
-
-    r->r_prev = NULL;
-    r->r_next = rtab;
-    if ( rtab != NULL ) {
-       rtab->r_prev = r;
-    }
-    if ( flags & RTF_HOST ) {
-       rt_host = r;
-    } else {
-       rt_net = r;
-    }
-    return( 0 );
-}
-
-    int
-rt_del( struct sockaddr_at *dst, struct sockaddr_at *gate, int flags )
-{
-    struct rtab                *r;
-    struct rtab                *rtab;
-
-    if ( flags & RTF_HOST ) {
-       rtab = rt_host;
-    } else {
-       rtab = rt_net;
-    }
-    for ( r = rtab; r != NULL; r = r->r_next ) {
-       if (( r->r_dst.sat_addr.s_net == dst->sat_addr.s_net ) &&
-               (( flags & RTF_HOST ) ?
-               r->r_dst.sat_addr.s_node == dst->sat_addr.s_node : 1 )) {
-           break;
-       }
-    }
-    if ( r == NULL ) {
-       return( ESRCH );
-    }
-
-    if ( r == rtab ) {
-       if ( flags & RTF_HOST ) {
-           rt_host = r->r_next;
-       } else {
-           rt_net = r->r_next;
-       }
-    }
-    if ( r->r_next != NULL ) {
-       r->r_next->r_prev = r->r_prev;
-    }
-    if ( r->r_prev != NULL ) {
-       r->r_prev->r_next = r->r_next;
-    }
-    kmem_free( r, sizeof( struct rtab ));
-    return( 0 );
-}
-
-    int
-rt_gate( struct sockaddr_at *dst, struct sockaddr_at *gate )
-{
-    struct rtab                *r;
-
-    for ( r = rt_host; r != NULL; r = r->r_next ) {
-       if ( r->r_dst.sat_addr.s_net == dst->sat_addr.s_net &&
-               r->r_dst.sat_addr.s_node == dst->sat_addr.s_node ) {
-           break;
-       }
-    }
-    if ( r != NULL ) {
-       *gate = r->r_gate;
-       return( 0 );
-    }
-
-    for ( r = rt_net; r != NULL; r = r->r_next ) {
-       if ( r->r_dst.sat_addr.s_net == dst->sat_addr.s_net ) {
-           break;
-       }
-    }
-    if ( r == NULL ) {
-       return( -1 );
-    }
-
-    *gate = r->r_gate;
-    return( 0 );
-}
diff --git a/sys/solaris/rt.h b/sys/solaris/rt.h
deleted file mode 100644 (file)
index ef7e17f..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-int    rt_add( struct sockaddr_at *, struct sockaddr_at *, int );
-int    rt_del( struct sockaddr_at *, struct sockaddr_at *, int );
-int    rt_gate( struct sockaddr_at *, struct sockaddr_at * );
diff --git a/sys/solaris/sock.c b/sys/solaris/sock.c
deleted file mode 100644 (file)
index 0a3fb79..0000000
+++ /dev/null
@@ -1,137 +0,0 @@
-/* $Id: sock.c,v 1.2 2002-01-17 07:11:13 srittau Exp $
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include <sys/types.h>
-#include <sys/stream.h>
-#include <sys/socket.h>
-#include <sys/errno.h>
-#include <sys/kmem.h>
-#include <sys/cmn_err.h>
-#include <sys/tihdr.h>
-#include <sys/ethernet.h>
-#include <net/if.h>
-
-#ifdef STDC_HEADERS
-#include <strings.h>
-#else
-#include <string.h>
-#endif
-
-#include <netatalk/at.h>
-
-#include "if.h"
-#include "sock.h"
-
-static struct sock_data        *sockets = NULL;
-
-    struct sock_data *
-sock_alloc( queue_t *q )
-{
-    struct sock_data   *sd;
-
-    if (( sd = kmem_alloc( sizeof( struct sock_data ), KM_SLEEP )) == NULL ) {
-       return( NULL );
-    }
-    sd->sd_state = TS_UNBND;
-    sd->sd_q = q;
-    sd->sd_next = sd->sd_prev = NULL;
-    bzero( (caddr_t)&sd->sd_sat, sizeof( struct sockaddr_at ));
-
-    sd->sd_next = sockets;
-    if ( sockets != NULL ) {
-       sockets->sd_prev = sd;
-    }
-    sockets = sd;
-
-    return( sd );
-}
-
-    void
-sock_free( struct sock_data *sd )
-{
-    if ( sd == sockets ) {
-       sockets = sd->sd_next;
-    }
-    if ( sd->sd_next != NULL ) {
-       sd->sd_next->sd_prev = sd->sd_prev;
-    }
-    if ( sd->sd_prev != NULL ) {
-       sd->sd_prev->sd_next = sd->sd_next;
-    }
-    kmem_free( sd, sizeof( struct sock_data ));
-    return;
-}
-
-    struct sock_data *
-sock_dest( struct atif_data *aid, struct sockaddr_at *sat )
-{
-    struct sock_data   *sd;
-
-    for ( sd = sockets; sd != NULL; sd = sd->sd_next ) {
-       if ( sat->sat_port == sd->sd_sat.sat_port &&
-               /* huh? */
-               aid->aid_sat.sat_addr.s_net == sd->sd_sat.sat_addr.s_net &&
-               ( sat->sat_addr.s_node == sd->sd_sat.sat_addr.s_node ||
-               sat->sat_addr.s_node == ATADDR_BCAST )) {
-           break;
-       }
-    }
-    return( sd );
-}
-
-/*
- * This is a change in semantics.  The port must be ATADDR_ANYPORT for
- * ATADDR_ANYNET/NODE to not mean the loopback.
- */
-    int
-sock_bind( struct sock_data *sd, struct sockaddr_at *sat )
-{
-    struct atif_data   *paid;
-    struct sock_data   *psd;
-    struct sockaddr_at psat;
-    u_short            port;
-
-    psat = *sat;
-    if ( psat.sat_family != AF_APPLETALK ) {
-       cmn_err( CE_CONT, "sock_bind non-AppleTalk\n" );
-       return( EPROTOTYPE );
-    }
-
-    if ( psat.sat_port == ATADDR_ANYPORT ) {
-       if ( psat.sat_addr.s_net == ATADDR_ANYNET &&
-               psat.sat_addr.s_node == ATADDR_ANYNODE ) {
-           /* chose primary interface */
-           if (( paid = if_primary()) == NULL ) {
-               return( EADDRNOTAVAIL );
-           }
-           psat.sat_addr.s_net = paid->aid_sat.sat_addr.s_net;
-           psat.sat_addr.s_node = paid->aid_sat.sat_addr.s_node;
-       }
-
-       /* pick unused port */
-       for ( port = ATPORT_RESERVED; port < ATPORT_LAST; port++ ) {
-           for ( psd = sockets; psd != NULL; psd = psd->sd_next ) {
-               if ( port == psd->sd_sat.sat_port &&
-                       psat.sat_addr.s_net == psd->sd_sat.sat_addr.s_net &&
-                       psat.sat_addr.s_node == psd->sd_sat.sat_addr.s_node ) {
-                   break;
-               }
-           }
-           if ( psd == NULL ) {
-               break;
-           }
-       }
-       if ( psd != NULL ) {
-           return( EADDRINUSE );
-       }
-       psat.sat_port = port;
-    }
-
-    sd->sd_sat = psat;
-    sd->sd_state = TS_IDLE;
-    return( 0 );
-}
diff --git a/sys/solaris/sock.h b/sys/solaris/sock.h
deleted file mode 100644 (file)
index 2397bd7..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-struct sock_data {
-    struct sock_data   *sd_next, *sd_prev;
-    int                        sd_state;
-    queue_t            *sd_q;
-    struct sockaddr_at sd_sat;
-};
-
-struct sock_data       *sock_alloc( queue_t * );
-void                   sock_free( struct sock_data * );
-struct sock_data       *sock_dest( struct atif_data *, struct sockaddr_at * );
-int                    sock_bind( struct sock_data *, struct sockaddr_at * );
-void           t_unitdata_ind( queue_t *, mblk_t *, struct sockaddr_at * );
diff --git a/sys/solaris/tpi.c b/sys/solaris/tpi.c
deleted file mode 100644 (file)
index 0bf89ed..0000000
+++ /dev/null
@@ -1,728 +0,0 @@
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-#include <sys/types.h>
-#include <sys/kmem.h>
-#include <sys/conf.h>
-#include <sys/stream.h>
-#include <sys/devops.h>
-#include <sys/modctl.h>
-#include <sys/ddi.h>
-#include <sys/stat.h>
-#include <sys/sockio.h>
-#include <sys/socket.h>
-#include <sys/tihdr.h>
-#include <sys/tiuser.h>
-#include <sys/timod.h>
-#include <sys/sunddi.h>
-#include <sys/ethernet.h>
-#include <net/if.h>
-#include <net/route.h>
-#include <errno.h>
-
-#include <netatalk/endian.h>
-#include <netatalk/at.h>
-#include <netatalk/ddp.h>
-
-#include "ioc.h"
-#include "if.h"
-#include "sock.h"
-#include "rt.h"
-
-    static int
-tpi_getinfo( dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **resultp )
-{
-    *resultp = NULL;
-    return( DDI_FAILURE );
-}
-
-/* Solaris 10 removed DDI_IDENTIFIED and replaced "identify" with "nulldev" */
-#ifdef DDI_IDENTIFIED
-    static int
-tpi_identify( dev_info_t *dip )
-{
-    char *tmp;
-
-    /* don't use strcmp under Solaris 9, problem loading kernel module */
-    tmp = ddi_get_name( dip );
-    if ((tmp[0]== 'd') && (tmp[1]=='d') && (tmp[2]=='p') && tmp[3]==0) {
-       return( DDI_IDENTIFIED );
-    } else {
-       return( DDI_NOT_IDENTIFIED );
-    }
-}
-#endif /* DDI_IDENTIFIED */
-
-    static int
-tpi_attach( dev_info_t *dip, ddi_attach_cmd_t cmd )
-{
-    int                rc;
-
-    if ( cmd != DDI_ATTACH ) {
-       return( DDI_FAILURE );
-    }
-
-    if (( rc = ddi_create_minor_node( dip, "ddp", S_IFCHR, 0, DDI_PSEUDO,
-           CLONE_DEV )) != DDI_SUCCESS ) {
-       /* undo anything */
-    }
-    return( rc );
-}
-
-    static int
-tpi_detach( dev_info_t *dip, ddi_detach_cmd_t cmd )
-{
-    if ( cmd != DDI_DETACH ) {
-       return( DDI_FAILURE );
-    }
-
-    ddi_remove_minor_node( dip, "ddp" );
-
-    return( DDI_SUCCESS );
-}
-
-    static int
-tpi_open( queue_t *q, dev_t *dev, int oflag, int sflag, cred_t *cred )
-{
-    static minor_t     minor = 1;
-
-    if ( sflag != CLONEOPEN ) {
-       return( EINVAL );
-    }
-    if (( q->q_ptr = (void *)sock_alloc( q )) == NULL ) {
-       return( ENOMEM );
-    }
-
-    *dev = makedevice( getmajor( *dev ), minor++ );
-    qprocson( q );
-    return( 0 );
-}
-
-    static int
-tpi_close( queue_t *q, int oflag, cred_t *cred )
-{
-    struct sock_data   *sd = (struct sock_data *)q->q_ptr;
-
-    qprocsoff( q );
-    sock_free( sd );
-    return( 0 );
-}
-
-    static int
-tpi_rput( queue_t *q,  mblk_t *m )
-{
-    cmn_err( CE_NOTE, "tpi_rput dp_type = 0x%X\n", m->b_datap->db_type );
-    freemsg( m );
-    return( 0 );
-}
-
-    void
-t_bind_ack( queue_t *q, struct sockaddr_at *sat )
-{
-    mblk_t             *m;
-    struct T_bind_ack  *t;
-
-    if (( m = allocb( sizeof( struct T_bind_ack ) +
-           sizeof( struct sockaddr_at ), BPRI_HI )) == NULL ) {
-       return;
-    }
-    m->b_wptr = m->b_rptr + sizeof( struct T_bind_ack );
-    m->b_datap->db_type = M_PCPROTO;
-
-    t = (struct T_bind_ack *)m->b_rptr;
-    t->PRIM_type = T_BIND_ACK;
-    t->ADDR_length = sizeof( struct sockaddr_at );
-    t->ADDR_offset = m->b_wptr - m->b_rptr;
-    t->CONIND_number = 0;
-
-    bcopy( (caddr_t)sat, m->b_wptr, sizeof( struct sockaddr_at ));
-    m->b_wptr += sizeof( struct sockaddr_at );
-
-    qreply( q, m );
-    return;
-}
-
-    void
-t_ok_ack( queue_t *q, long prim )
-{
-    mblk_t             *m;
-    struct T_ok_ack    *t;
-
-
-    if (( m = allocb( sizeof( struct T_ok_ack ), BPRI_HI )) == NULL ) {
-       return;
-    }
-    m->b_wptr = m->b_rptr + sizeof( struct T_ok_ack );
-    m->b_datap->db_type = M_PCPROTO;
-
-    t = (struct T_ok_ack *)m->b_rptr;
-    t->PRIM_type = T_OK_ACK;
-    t->CORRECT_prim = prim;
-    qreply( q, m );
-    return;
-}
-
-    void
-t_error_ack( queue_t *q, long prim, long terror, long uerror )
-{
-    mblk_t             *m;
-    struct T_error_ack *t;
-
-
-    if (( m = allocb( sizeof( struct T_error_ack ), BPRI_HI )) == NULL ) {
-       return;
-    }
-    m->b_wptr = m->b_rptr + sizeof( struct T_error_ack );
-    m->b_datap->db_type = M_PCPROTO;
-
-    t = (struct T_error_ack *)m->b_rptr;
-    t->PRIM_type = T_ERROR_ACK;
-    t->ERROR_prim = prim;
-    t->TLI_error = terror;
-    t->UNIX_error = uerror;
-    qreply( q, m );
-    return;
-}
-
-    void
-t_info_ack( queue_t *q, long state )
-{
-    mblk_t             *m;
-    struct T_info_ack  *t;
-
-
-    if (( m = allocb( sizeof( struct T_info_ack ), BPRI_HI )) == NULL ) {
-       return;
-    }
-    m->b_wptr = m->b_rptr + sizeof( struct T_info_ack );
-    m->b_datap->db_type = M_PCPROTO;
-
-    t = (struct T_info_ack *)m->b_rptr;
-    t->PRIM_type = T_INFO_ACK;
-    t->TSDU_size = 586;
-    t->ETSDU_size = -2;
-    t->CDATA_size = -2;
-    t->DDATA_size = -2;
-    t->ADDR_size = sizeof( struct sockaddr_at );
-    t->OPT_size = 64;
-    t->TIDU_size = 1024;
-    t->SERV_type = T_CLTS;
-    t->CURRENT_state = state;
-    t->PROVIDER_flag = 0;
-    qreply( q, m );
-    return;
-}
-
-    void
-t_unitdata_ind( queue_t *q, mblk_t *m0, struct sockaddr_at *sat )
-{
-    mblk_t                     *m;
-    struct T_unitdata_ind      *t;
-
-    if (( m = allocb( sizeof( struct T_unitdata_ind ) +
-           sizeof( struct sockaddr_at ), BPRI_HI )) == NULL ) {
-       return;
-    }
-    m->b_wptr = m->b_rptr + sizeof( struct T_unitdata_ind );
-    m->b_datap->db_type = M_PROTO;
-
-    t = (struct T_unitdata_ind *)m->b_rptr;
-    t->PRIM_type = T_UNITDATA_IND;
-    t->SRC_length = sizeof( struct sockaddr_at );
-    t->SRC_offset = m->b_wptr - m->b_rptr;
-    bcopy( (caddr_t)sat, m->b_wptr, sizeof( struct sockaddr_at ));
-    m->b_wptr += sizeof( struct sockaddr_at );
-    t->OPT_length = 0;
-    t->OPT_offset = 0;
-    linkb( m, m0 );
-
-    qreply( q, m );
-    return;
-}
-
-struct ioc_state {
-    int                is_state;
-    int                is_count;
-    caddr_t    is_addr;
-};
-
-    static int
-tpi_wput( queue_t *q,  mblk_t *m )
-{
-    struct sock_data   *sd = (struct sock_data *)RD(q)->q_ptr;
-    union T_primitives *tl;
-    struct iocblk      *ioc;
-    struct copyresp    *cp;
-    struct ioc_state   *is;
-    struct ddpehdr     *deh;
-    mblk_t             *m0;
-    struct sockaddr_at sat;
-    struct netbuf      nb;
-    struct rtentry     rt;
-    struct ifreq       ifr;
-    int                        err;
-
-    switch ( m->b_datap->db_type ) {
-    case M_PCPROTO :
-    case M_PROTO :
-       if ( m->b_wptr - m->b_rptr < sizeof( tl->type )) {
-           freemsg( m );
-           break;
-       }
-       tl = (union T_primitives *)m->b_rptr;
-       switch ( tl->type ) {
-       case T_INFO_REQ :
-           t_info_ack( q, sd->sd_state );
-           freemsg( m );
-           break;
-
-       case T_UNBIND_REQ :
-           if ( m->b_wptr - m->b_rptr < sizeof( struct T_unbind_req )) {
-               freemsg( m );
-               break;
-           }
-           if ( sd->sd_state != TS_IDLE ) {
-               t_error_ack( q, T_BIND_REQ, TOUTSTATE, 0 );
-               freemsg( m );
-               break;
-           }
-           bzero( (caddr_t)&sd->sd_sat, sizeof( struct sockaddr_at ));
-           sd->sd_state = TS_UNBND;
-           t_ok_ack( q, T_UNBIND_REQ );
-           break;
-
-       case T_BIND_REQ :
-           if ( m->b_wptr - m->b_rptr < sizeof( struct T_bind_req )) {
-               freemsg( m );
-               break;
-           }
-           if ( sd->sd_state != TS_UNBND ) {
-               t_error_ack( q, T_BIND_REQ, TOUTSTATE, 0 );
-               freemsg( m );
-               break;
-           }
-
-           if ( tl->bind_req.ADDR_length == 0 ) {
-               bzero( (caddr_t)&sat, sizeof( struct sockaddr_at ));
-               sat.sat_family = AF_APPLETALK;
-           } else {
-               if ( tl->bind_req.ADDR_length != sizeof( struct sockaddr ) ||
-                       m->b_wptr - m->b_rptr <
-                       tl->bind_req.ADDR_offset + tl->bind_req.ADDR_length ) {
-                   cmn_err( CE_CONT, "tpi_wput T_BIND_REQ wierd\n" );
-                   freemsg( m );
-                   break;
-               }
-               sat = *(struct sockaddr_at *)(m->b_rptr +
-                       tl->bind_req.ADDR_offset );
-           }
-
-           if (( err = sock_bind( sd, &sat )) != 0 ) {
-               t_error_ack( q, T_BIND_REQ, TSYSERR, err );
-           } else {
-               /* seems like we must return the requested address */
-               t_bind_ack( q, &sat );
-           }
-           freemsg( m );
-           break;
-
-       case T_UNITDATA_REQ :
-           if ( m->b_wptr - m->b_rptr < sizeof( struct T_unitdata_req )) {
-               freemsg( m );
-               break;
-           }
-           if ( sd->sd_state != TS_IDLE ) {
-               cmn_err( CE_NOTE, "tpi_wput unitdata on unbound socket\n" );
-               t_error_ack( q, T_UNITDATA_REQ, TOUTSTATE, 0 );
-               freemsg( m );
-               break;
-           }
-           if ( tl->unitdata_req.DEST_length != sizeof( struct sockaddr )) {
-               cmn_err( CE_NOTE, "tpi_wput T_UNITDATA_REQ %d\n",
-                       tl->unitdata_req.DEST_length );
-               freemsg( m );
-               break;
-           }
-
-#ifdef notdef
-           /*
-            * Sometimes, the socket layer gives us crap...  Sound like a bug?
-            */
-           if ( m->b_rptr + tl->unitdata_req.DEST_offset +
-                   tl->unitdata_req.DEST_length > m->b_wptr ) {
-cmn_err( CE_CONT, "tpi_wput T_UNITDATA_REQ mblk size %X %X\n", m->b_rptr + tl->unitdata_req.DEST_offset + tl->unitdata_req.DEST_length, m->b_wptr );
-               freemsg( m );
-               break;
-           }
-#endif /* notdef */
-
-           sat = *(struct sockaddr_at *)(m->b_rptr +
-                   tl->unitdata_req.DEST_offset );
-           if ( sat.sat_family != AF_APPLETALK ) {
-               cmn_err( CE_CONT, "tpi_wput non-AppleTalk\n" );
-               freemsg( m );
-               break;
-           }
-
-           if ( m->b_wptr - m->b_rptr < sizeof( struct ddpehdr )) {
-               cmn_err( CE_CONT, "tpi_wput m too short\n" );
-               freemsg( m );
-               break;
-           }
-           m->b_wptr = m->b_rptr + sizeof( struct ddpehdr );
-           m->b_datap->db_type = M_DATA;
-           deh = (struct ddpehdr *)m->b_rptr;
-           deh->deh_pad = 0;
-           deh->deh_hops = 0;
-           deh->deh_len = msgdsize( m );
-
-           deh->deh_dnet = sat.sat_addr.s_net;
-           deh->deh_dnode = sat.sat_addr.s_node;
-           deh->deh_dport = sat.sat_port;
-
-           deh->deh_snet = sd->sd_sat.sat_addr.s_net;
-           deh->deh_snode = sd->sd_sat.sat_addr.s_node;
-           deh->deh_sport = sd->sd_sat.sat_port;
-
-           deh->deh_sum = 0;                   /* XXX */
-           deh->deh_bytes = htonl( deh->deh_bytes );
-           return( if_route( if_withaddr( &sd->sd_sat ), m, &sat ));
-
-       default :
-           /* cmn_err( CE_NOTE, "tpi_wput M_PCPROTO 0x%X\n", tl->type ); */
-           t_error_ack( q, tl->type, TNOTSUPPORT, 0 );
-           freemsg( m );
-           break;
-       }
-       break;
-
-    case M_IOCTL :
-       if ( m->b_wptr - m->b_rptr < sizeof( struct iocblk )) {
-           freemsg( m );
-           break;
-       }
-       ioc = (struct iocblk *)m->b_rptr;
-       if ( ioc->ioc_count != TRANSPARENT ) {
-           cmn_err( CE_CONT, "tpi_wput non-TRANSPARENT %X\n", ioc->ioc_cmd );
-           ioc_error_ack( q, m, EINVAL );
-           break;
-       }
-       if ( m->b_cont == NULL ) {
-           cmn_err( CE_CONT, "tpi_wput M_IOCTL no arg\n" );
-           ioc_error_ack( q, m, EINVAL );
-           break;
-       }
-
-       /* de-allocated after M_IOCDATA processing */
-       if (( m0 = allocb( sizeof( struct ioc_state ), BPRI_HI )) == NULL ) {
-           cmn_err( CE_CONT, "tpi_wput m0 no mem\n" );
-           ioc_error_ack( q, m, EINVAL );
-           break;
-       }
-       m0->b_wptr = m->b_rptr + sizeof( struct ioc_state );
-       is = (struct ioc_state *)m0->b_rptr;
-
-       switch ( ioc->ioc_cmd ) {
-       case SIOCADDRT :
-       case SIOCDELRT :
-           if (( err = drv_priv( ioc->ioc_cr )) != 0 ) {
-               ioc_error_ack( q, m, err );
-               break;
-           }
-           is->is_state = M_COPYIN;
-           is->is_addr = *(caddr_t *)m->b_cont->b_rptr;
-           ioc_copyin( q, m, m0, is->is_addr, sizeof( struct rtentry ));
-           break;
-
-       case SIOCADDMULTI :
-       case SIOCSIFADDR :
-           if (( err = drv_priv( ioc->ioc_cr )) != 0 ) {
-               ioc_error_ack( q, m, err );
-               break;
-           }
-
-       case SIOCGIFADDR :
-           is->is_state = M_COPYIN;
-           is->is_addr = *(caddr_t *)m->b_cont->b_rptr;
-           ioc_copyin( q, m, m0, is->is_addr, sizeof( struct ifreq ));
-           break;
-
-       case TI_GETMYNAME :
-           is->is_state = M_COPYIN;
-           is->is_addr = *(caddr_t *)m->b_cont->b_rptr;
-           ioc_copyin( q, m, m0, is->is_addr, sizeof( struct netbuf ));
-           break;
-
-       default :
-           ioc_error_ack( q, m, EINVAL );
-           break;
-       }
-       break;
-
-    case M_IOCDATA :
-       if ( m->b_wptr - m->b_rptr < sizeof( struct copyresp )) {
-           freemsg( m );
-           break;
-       }
-       cp = (struct copyresp *)m->b_rptr;
-       if ( cp->cp_rval != 0 ) {
-           cmn_err( CE_CONT, "tpi_wput IOCDATA failed %s\n", cp->cp_rval );
-           freemsg( m );
-           break;
-       }
-
-       if (( m0 = cp->cp_private ) == NULL ) {
-           cmn_err( CE_CONT, "tpi_wput IOCDATA no state\n" );
-           ioc_error_ack( q, m, EINVAL );
-           break;
-       }
-       if ( m0->b_wptr - m0->b_rptr < sizeof( struct ioc_state )) {
-           cmn_err( CE_CONT, "tpi_wput IOCDATA private too short\n" );
-           ioc_error_ack( q, m, EINVAL );
-           break;
-       }
-       is = (struct ioc_state *)m0->b_rptr;
-
-       switch ( cp->cp_cmd ) {
-       case TI_GETMYNAME :
-           switch ( is->is_state ) {
-           case M_COPYIN :
-               if ( m->b_cont == NULL ) {
-                   cmn_err( CE_CONT, "tpi_wput TI_GETMYNAME COPYIN no arg\n" );
-                   ioc_error_ack( q, m, EINVAL );
-                   break;
-               }
-               nb = *(struct netbuf *)m->b_cont->b_rptr;
-               nb.len = sizeof( struct sockaddr_at );
-               /* copy out netbuf */
-               is->is_state = M_COPYOUT;
-               is->is_count = 1;
-               ioc_copyout( q, m, m0, (caddr_t)&nb, is->is_addr,
-                       sizeof( struct netbuf ));
-               is->is_addr = nb.buf;
-               return( 0 );
-
-           case M_COPYOUT :
-               switch ( is->is_count ) {
-               case 1 :
-                   /* copy out address to nb.buf */
-                   is->is_state = M_COPYOUT;
-                   is->is_count = 2;
-                   ioc_copyout( q, m, m0, (caddr_t)&sd->sd_sat, is->is_addr,
-                           sizeof( struct sockaddr_at ));
-                   return( 0 );
-
-               case 2 :
-                   ioc_ok_ack( q, m, 0 );
-                   break;
-
-               default :
-                   cmn_err( CE_NOTE, "tpi_wput TI_GETMYNAME count %d\n",
-                           is->is_count );
-                   ioc_error_ack( q, m, EINVAL );
-                   break;
-               }
-               break;
-
-           default :
-               cmn_err( CE_NOTE, "tpi_wput TI_GETMYNAME state %d\n",
-                       is->is_state );
-               ioc_error_ack( q, m, EINVAL );
-               break;
-           }
-           break;
-
-       case SIOCADDRT :        /* manipulate routing table */
-       case SIOCDELRT :
-           if (( err = drv_priv( cp->cp_cr )) != 0 ) {
-               ioc_error_ack( q, m, err );
-               break;
-           }
-           if ( is->is_state != M_COPYIN ) {
-               cmn_err( CE_CONT, "tpi_wput SIOC(ADD|DEL)RT bad state\n" );
-               freemsg( m );
-               break;
-           }
-
-           rt = *(struct rtentry *)m->b_cont->b_rptr;
-
-           if ( cp->cp_cmd == SIOCADDRT ) {
-               err = rt_add( (struct sockaddr_at *)&rt.rt_dst,
-                       (struct sockaddr_at *)&rt.rt_gateway, rt.rt_flags );
-           } else if ( cp->cp_cmd == SIOCDELRT ) {
-               err = rt_del( (struct sockaddr_at *)&rt.rt_dst,
-                       (struct sockaddr_at *)&rt.rt_gateway, rt.rt_flags );
-           } else {
-               cmn_err( CE_CONT, "tpi_wput SIOC(ADD|DEL)RT bad cmd\n" );
-               freemsg( m );
-               break;
-           }
-           if ( err != 0 ) {
-               ioc_error_ack( q, m, err );
-           } else {
-               ioc_ok_ack( q, m, 0 );
-           }
-           break;
-
-       /*
-        * These both require lower messages to be sent.
-        */
-       case SIOCADDMULTI :
-       case SIOCSIFADDR :
-           if (( err = drv_priv( cp->cp_cr )) != 0 ) {
-               ioc_error_ack( q, m, err );
-               break;
-           }
-           if ( is->is_state != M_COPYIN ) {
-               cmn_err( CE_CONT, "tpi_wput SIOCSIFADDR bad state\n" );
-               freemsg( m );
-               break;
-           }
-
-           ifr = *(struct ifreq *)m->b_cont->b_rptr;
-
-           /* initiate command, pass q and m (current context to be saved */
-           if ( cp->cp_cmd == SIOCSIFADDR ) {
-               err = if_setaddr( q, m, ifr.ifr_name,
-                       (struct sockaddr_at *)&ifr.ifr_addr );
-           } else {
-               err = if_addmulti( q, m, ifr.ifr_name, &ifr.ifr_addr );
-           }
-           if ( err != 0 ) {
-               ioc_error_ack( q, m, err );
-               break;
-           }
-           break;
-
-       case SIOCGIFADDR :      /* get interface address */
-           switch ( is->is_state ) {
-           case M_COPYOUT :
-               /* ack the original ioctl */
-               ioc_ok_ack( q, m, 0 );
-               break;
-
-           case M_COPYIN :
-               if ( m->b_cont == NULL ) {
-                   cmn_err( CE_CONT, "tpi_wput SIOCGIFADDR COPYIN no arg\n" );
-                   ioc_error_ack( q, m, EINVAL );
-                   break;
-               }
-
-               /* size??? */
-               ifr = *(struct ifreq *)m->b_cont->b_rptr;
-               if (( err = if_getaddr( ifr.ifr_name,
-                       (struct sockaddr_at *)&ifr.ifr_addr )) != 0 ) {
-                   ioc_error_ack( q, m, err );
-               }
-               is->is_state = M_COPYOUT;
-               ioc_copyout( q, m, m0, (caddr_t)&ifr, is->is_addr,
-                       sizeof( struct ifreq ));
-               return( 0 );    /* avoid freemsg( m0 ) below */
-
-           default :
-               cmn_err( CE_CONT, "tpi_wput SIOCGIFADDR bad state\n" );
-               freemsg( m );
-               break;
-           }
-           break;
-
-       default :
-           cmn_err( CE_NOTE, "tpi_wput M_IOCDATA 0x%X\n", cp->cp_cmd );
-           ioc_error_ack( q, m, EINVAL );
-           break;
-       }
-       freemsg( m0 );
-       break;
-
-    default :
-       cmn_err( CE_NOTE, "!tpi_wput dp_type = 0x%X\n", m->b_datap->db_type );
-       freemsg( m );
-       break;
-    }
-
-    return( 0 );
-}
-
-static struct module_info      tpi_info = {
-    0,                 /* XXX */
-    "ddp",
-    0,
-    1500,
-    3000,
-    64
-};
-
-static struct qinit            tpi_rinit = {
-    tpi_rput,                  /* qi_putp */
-    NULL,                      /* qi_srvp */
-    tpi_open,                  /* qi_qopen */
-    tpi_close,                 /* qi_qclose */
-    NULL,
-    &tpi_info,                 /* qi_minfo */
-    NULL,
-};
-
-static struct qinit            tpi_winit = {
-    tpi_wput,                  /* qi_putp */
-    NULL,
-    NULL,
-    NULL,
-    NULL,
-    &tpi_info,
-    NULL,
-};
-
-static struct streamtab                tpi_stream = {
-    &tpi_rinit,
-    &tpi_winit,
-    NULL,
-    NULL
-};
-
-static struct cb_ops           tpi_cbops = {
-    nulldev,           /* cb_open */
-    nulldev,           /* cb_close */
-    nodev,
-    nodev,
-    nodev,
-    nodev,
-    nodev,
-    nodev,
-    nodev,
-    nodev,
-    nodev,
-    nochpoll,
-    ddi_prop_op,
-    &tpi_stream,
-    D_NEW | D_MP | D_MTPERMOD, /* cb_flag */
-    CB_REV,            /* cb_rev */
-    nodev,             /* cb_aread */
-    nodev,             /* cb_awrite */
-};
-
-static struct dev_ops          tpi_devops = {
-    DEVO_REV,
-    0,
-    tpi_getinfo,
-#ifdef DDI_IDENTIFIED
-    tpi_identify,
-#else
-    nulldev,
-#endif
-    nulldev,
-    tpi_attach,
-    tpi_detach,
-    nodev,
-    &tpi_cbops,
-    (struct bus_ops *)NULL,
-    NULL,
-};
-
-/*
- * DDP Streams device.  This device is opened by socket().
- */
-struct modldrv                 tpi_ldrv = {
-    &mod_driverops,
-    "DDP Streams device",
-    &tpi_devops,
-};
diff --git a/sys/sunos/.gitignore b/sys/sunos/.gitignore
deleted file mode 100644 (file)
index 895a5e7..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-Makefile
-Makefile.in
-.gitignore
-*.o
diff --git a/sys/sunos/Makefile.am b/sys/sunos/Makefile.am
deleted file mode 100644 (file)
index ad9b76c..0000000
+++ /dev/null
@@ -1 +0,0 @@
-EXTRA_DIST = Makefile.kernel at_sun.c
diff --git a/sys/sunos/Makefile.kernel b/sys/sunos/Makefile.kernel
deleted file mode 100644 (file)
index e489af1..0000000
+++ /dev/null
@@ -1,148 +0,0 @@
-# Sun specific defines, passed to subdirectories.
-DEFS= -DBSD4_3 -DUSE_OLD_RQUOTA -DUSE_UFS_QUOTA_H -DUSE_MNTENT_H \
-       -DDLSYM_PREPEND_UNDERSCORE
-OPTOPTS=       -O
-CC=    gcc
-INSTALL=       install
-# use -lbind instead of -lresolv if you're using BIND >= 8.x
-AFPLIBS=-lresolv
-ADDLIBS=
-
-#CSHAREDFLAGS=   -pic
-CSHAREDFLAGS=   -fPIC
-
-#LDFLAGS_EXPORT=
-LDSHARED=      ld
-LDSHAREDFLAGS=  -assert pure-text
-LIBSHARED=      -ldl
-
-
-# source for kernel module
-SRC=   at_sun.c aarp.c at_control.c at_proto.c ddp_input.c ddp_output.c \
-       ddp_usrreq.c
-OBJ=   at_sun.o aarp.o at_control.o at_proto.o ddp_input.o ddp_output.o \
-       ddp_usrreq.o
-
-INCPATH = -I../../include -I../netatalk
-CFLAGS=        ${DEFS} ${OPTOPTS} ${INCPATH}
-
-ALL=   ../../libatalk ../../include ../../bin ../../etc ../../man
-
-all:   kernel ${ALL}
-
-kernel : netatalk.o
-
-netatalk.o:    ${OBJ}
-       ${LD} -r -o netatalk.o ${OBJ}
-
-at_sun.o:      at_sun.c
-       ${CC} ${CFLAGS} -DKERNEL -D`arch -k` -c at_sun.c
-
-aarp.o:        ../netatalk/aarp.c
-       ${CC} ${CFLAGS} -DKERNEL -D`arch -k` -c ../netatalk/aarp.c
-
-at_control.o:  ../netatalk/at_control.c
-       ${CC} ${CFLAGS} -DKERNEL -D`arch -k` -c ../netatalk/at_control.c
-
-at_proto.o:    ../netatalk/at_proto.c
-       ${CC} ${CFLAGS} -DKERNEL -D`arch -k` -c ../netatalk/at_proto.c
-
-ddp_input.o:   ../netatalk/ddp_input.c
-       ${CC} ${CFLAGS} -DKERNEL -D`arch -k` -c ../netatalk/ddp_input.c
-
-ddp_output.o:  ../netatalk/ddp_output.c
-       ${CC} ${CFLAGS} -DKERNEL -D`arch -k` -c ../netatalk/ddp_output.c
-
-ddp_usrreq.o:  ../netatalk/ddp_usrreq.c
-       ${CC} ${CFLAGS} -DKERNEL -D`arch -k` -c ../netatalk/ddp_usrreq.c
-
-../../bin ../../etc:   ../../libatalk
-
-${ALL}:        FRC
-       cd $@; ${MAKE} ${MFLAGS} CC="${CC}" \
-           ADDLIBS="${ADDLIBS}" DEFS="${DEFS}" OPTOPTS="${OPTOPTS}" \
-           SBINDIR="${SBINDIR}" BINDIR="${BINDIR}" RESDIR="${RESDIR}" \
-           ETCDIR="${ETCDIR}" LIBDIR="${LIBDIR}" INCDIR="${INCDIR}" \
-           AFPLIBS="${AFPLIBS}" LDSHARED="${LDSHARED}" \
-           LDFLAGS_EXPORT="${LDFLAGS_EXPORT}" \
-           LDSHAREDFLAGS="${LDSHAREDFLAGS}" CSHAREDFLAGS="${CSHAREDFLAGS}" \
-           LIBSHARED="${LIBSHARED}" \
-           all
-
-FRC:
-
-kinstall :     kernel
-       -mkdir ${DESTDIR}
-       -mkdir ${ETCDIR}
-       ${INSTALL} -c netatalk.o ${ETCDIR}
-
-install :      kinstall
-       -mkdir ${DESTDIR}
-       -mkdir ${SBINDIR}
-       -mkdir ${BINDIR}
-       -mkdir ${ETCDIR}
-       -mkdir ${LIBDIR}
-       for i in ${ALL}; \
-           do (cd $$i; ${MAKE} ${MFLAGS} CC="${CC}" \
-               ADDLIBS="${ADDLIBS}" DEFS="${DEFS}" OPTOPTS="${OPTOPTS}" \
-               SBINDIR="${SBINDIR}" BINDIR="${BINDIR}" RESDIR="${RESDIR}" \
-               ETCDIR="${ETCDIR}" LIBDIR="${LIBDIR}" INCDIR="${INCDIR}" \
-               DESTDIR="${DESTDIR}" MANDIR="${MANDIR}" AFPLIBS="${AFPLIBS}" \
-               AFSDIR="${AFSDIR}" KRBDIR="${KRBDIR}" \
-               LDSHARED="${LDSHARED}" LDFLAGS_EXPORT="${LDFLAGS_EXPORT}" \
-               LDSHAREDFLAGS="${LDSHAREDFLAGS}" \
-               CSHAREDFLAGS="${CSHAREDFLAGS}" LIBSHARED="${LIBSHARED}" \
-               INSTALL="${INSTALL}" $@); \
-       done
-       rm -f ${ETCDIR}/rc.atalk
-       sed -e s@:DESTDIR:@${DESTDIR}@ -e s@:SBINDIR:@${SBINDIR}@ \
-               -e s@:BINDIR:@${BINDIR}@ -e s@:RESDIR:@${RESDIR}@ \
-               -e s@:ETCDIR:@${ETCDIR}@ -e s@:LIBDIR:@${LIBDIR}@ \
-               -e s@:INCDIR:@${INCDIR}@ -e 's@^##@@' \
-           < ../../distrib/initscripts/rc.atalk.bsd > ${ETCDIR}/rc.atalk
-       if [ -f ${ETCDIR}/afpd.conf ]; then \
-               echo "Retaining old afpd.conf file.";  \
-       else \
-               sed -e s@:DESTDIR:@${DESTDIR}@ -e s@:SBINDIR:@${SBINDIR}@ \
-                       -e s@:BINDIR:@${BINDIR}@ -e s@:RESDIR:@${RESDIR}@ \
-                       -e s@:ETCDIR:@${ETCDIR}@ -e s@:LIBDIR:@${LIBDIR}@ \
-                       -e s@:INCDIR:@${INCDIR}@ \
-                       < ../../config/afpd.conf > ${ETCDIR}/afpd.conf; \
-       fi
-       @echo
-       @echo "Install is done.  Don't forget to add lines from"
-       @echo "services.atalk to /etc/services and to call rc.atalk"
-       @echo "in /etc/rc.  See README and README.SUN for more"
-       @echo "information."
-
-clean : sysclean
-       for i in ${ALL}; \
-           do (cd $$i; ${MAKE} ${MFLAGS} clean); \
-       done
-
-sysclean :
-       rm -f a.out core* *.o *.bak *[Ee]rrs tags
-       rm -f netatalk.o
-
-depend :
-       for i in ${ALL}; \
-           do (cd $$i; ${MAKE} ${MFLAGS} DEFS=${DEFS} depend); \
-       done
-       for i in ${SRC} ; do \
-           ${CC} -M ${DEFS} ${INCPATH} $$i | \
-           awk ' { if ($$1 != prev) { print rec; rec = $$0; prev = $$1; } \
-               else { if (length(rec $$2) > 78) { print rec; rec = $$0; } \
-               else rec = rec " " $$2 } } \
-               END { print rec } ' >> makedep; done
-       sed -n '1,/^# DO NOT DELETE THIS LINE/p' Makefile > Makefile.tmp
-       cat makedep >> Makefile.tmp
-       rm makedep
-       echo '# DEPENDENCIES MUST END AT END OF FILE' >> Makefile.tmp
-       echo '# IF YOU PUT STUFF HERE IT WILL GO AWAY' >> Makefile.tmp
-       echo '# see make depend above' >> Makefile.tmp
-       rm -f Makefile.bak
-       cp Makefile Makefile.bak
-       mv Makefile.tmp Makefile
-
-# DO NOT DELETE THIS LINE
-
diff --git a/sys/sunos/at_sun.c b/sys/sunos/at_sun.c
deleted file mode 100644 (file)
index 1cfc020..0000000
+++ /dev/null
@@ -1,378 +0,0 @@
-/*
- * $Id: at_sun.c,v 1.2 2001-08-06 13:39:30 rufustfirefly Exp $
- */
-
-#include <sys/param.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/mbuf.h>
-#include <sys/protosw.h>
-#include <sys/domain.h>
-#include <sys/errno.h>
-
-#include <net/if_arp.h>
-#include <net/if.h>
-#include <net/route.h>
-#include <net/af.h>
-#include <net/netisr.h>
-
-#include <sun/vddrv.h>
-
-#include <netinet/in.h>
-#undef s_net
-#include <netinet/if_ether.h>
-
-#include <netatalk/at.h>
-#include <netatalk/at_var.h>
-#include <netatalk/ddp_var.h>
-#include <netatalk/phase2.h>
-
-struct vdlat {
-    int                vda_magic;
-    char       *vda_name;
-}      atvdl = {
-    VDMAGIC_USER, "netatalk"
-};
-
-struct ifqueue *atef_input();
-int            atef_output();
-extern int     atintr();
-
-extern u_char  aarp_org_code[ 3 ];
-extern u_char  at_org_code[ 3 ];
-
-/*
- * Entries in this table are inserted into the ether_families linked
- * list at the beginnning. As such, they will be searched by the input
- * and output routines opposite to the order here.
- *
- * In order to do both phase 1 and phase 2 during output, we have a
- * special entry (the AF_APPLETALK entry) whose ethertype field is
- * changed by the output function, to reflect the actual link layer
- * to be used. This ether_family entry is never seen during Ethernet
- * input, since the earlier entry captures all packets (it is seen
- * during loopback input, in that the input function is called directly
- * on loopback output).
- */
-struct ether_family    ether_atalk[] = {
-    {
-       AF_APPLETALK,   0,      /* Changed by atef_output() */
-       atef_input,     atef_output,    atintr,
-    },
-    {
-       0,              ETHERTYPE_AARP,
-       atef_input,     0,              0,
-    },
-    {
-       0,              ETHERTYPE_AT,
-       atef_input,     0,              atintr,
-    },
-    {
-       0,              EF_8023_TYPE,
-       atef_input,     0,              atintr,
-    },
-};
-int    ether_atalkN = sizeof( ether_atalk ) / sizeof( ether_atalk[ 0 ] );
-
-extern struct ether_family     *ether_families;
-
-extern int                     atalk_hash(), atalk_netmatch();
-extern int                     null_hash(), null_netmatch();
-
-xxxinit( cmd, vdd, vdi, vds )
-    unsigned int       cmd;
-    struct vddrv       *vdd;
-    addr_t             vdi;
-    struct vdstat      *vds;
-{
-    struct ether_family        *ef;
-    struct domain      *dom;
-    struct protosw     *pr;
-    int                        i;
-
-    switch( cmd ) {
-       case VDLOAD :
-           vdd->vdd_vdtab = (struct vdlinkage *)&atvdl;
-
-           /*
-            * Register with the network-interface layer (ethernet).
-            */
-           for ( i = 0; i < ether_atalkN; i++ ) {
-               ether_register( &ether_atalk[ i ] );
-           }
-
-           /*
-            * Register with the socket layer.
-            */
-           atalkdomain.dom_next = domains;
-           domains = &atalkdomain;
-           if ( atalkdomain.dom_init ) {
-               (*atalkdomain.dom_init)();
-           }
-           for ( pr = atalkdomain.dom_protosw;
-                   pr < atalkdomain.dom_protoswNPROTOSW; pr++ ) {
-               if ( pr->pr_init ) {
-                   (*pr->pr_init)();
-               }
-           }
-
-           /*
-            * Cobble ourselves into the routing table.
-            */
-           afswitch[ AF_APPLETALK ].af_hash = atalk_hash;
-           afswitch[ AF_APPLETALK ].af_netmatch = atalk_netmatch;
-           return( 0 );
-
-       case VDUNLOAD :
-           /*
-            * Make sure that there are no open appletalk sockets.
-            */
-           if ( ddpcb != NULL ) {
-               return( EMFILE );
-           }
-
-           /*
-            * There is no ether_unregister(), so we'll have to do it
-            * our selves...
-            */
-           for ( i = 0; i < ether_atalkN; i++ ) {
-               if ( ether_families == &ether_atalk[ i ] ) {
-                   ether_families = ether_families->ef_next;
-                   continue;
-               } else {
-                   for ( ef = ether_families; ef->ef_next; ef = ef->ef_next ) {
-                       if ( ef->ef_next == &ether_atalk[ i ] ) {
-                           ef->ef_next = ef->ef_next->ef_next;
-                           break;
-                       }
-                   }
-               }
-           }
-
-           /*
-            * Remove aarp timers and held packets.
-            */
-           aarp_clean();
-
-           /*
-            * Remove AppleTalk interface addresses.
-            */
-           aa_clean();
-
-           /*
-            * Remove our routines from the routing table.
-            */
-           afswitch[ AF_APPLETALK ].af_hash = null_hash;
-           afswitch[ AF_APPLETALK ].af_netmatch = null_netmatch;
-
-           /*
-            * Remove atalkdomain from the domains list.
-            * Unlikely, but someone may have registered after us.
-            */
-           if ( domains == &atalkdomain ) {
-               domains = domains->dom_next;
-           } else {
-               for ( dom = domains; dom->dom_next; dom = dom->dom_next ) {
-                   if ( dom->dom_next == &atalkdomain ) {
-                       dom->dom_next = dom->dom_next->dom_next;
-                       break;
-                   }
-               }
-           }
-           return( 0 );
-
-       case VDSTAT :
-           return( 0 );
-       default :
-           return( EIO );
-    }
-}
-
-/*
- * Input routine for netatalk on suns.  There are five possible
- * packets.  First, packets received on the loopback interface
- * are immediately sent to the phase 1 interrupt queue (this will
- * have to change if we ever do a phase 2 only version).  Second,
- * IEEE802 packet are sent to either the aarpinput() routine or
- * the phase 2 interrupt queue.  Finally, DIX packets are sent
- * to either aarpinput() or the phase 1 interrupt queue.
- */
-    struct ifqueue *
-atef_input( ifp, m, header )
-    struct ifnet       *ifp;
-    struct mbuf                *m;
-    struct ether_header        *header;
-{
-    struct llc         llc;
-    struct mbuf                *n = 0;
-
-    /*
-     * Check first for LOOPBACK flag, since loopback code passes NULL for
-     * the header.
-     */
-    if ( ifp->if_flags & IFF_LOOPBACK ) {
-       return( &atintrq2 );
-    }
-
-    /*
-     * Before SunOS 4.1, the ether_type was passed as is from the
-     * packet.  After SunOS 4.1, the ether_type is swapped in
-     * do_protocol(), before the ether_family routines are called.
-     */
-#if defined( sun ) && defined( i386 )
-    header->ether_type = ntohs( header->ether_type );
-#endif /* sun i386 */
-
-    if ( header->ether_type <= ETHERMTU ) {    /* IEEE802 */
-       /*
-        * We need to remove the interface pointer from the beginning of this
-        * packet.  We can't always use IF_ADJ(), since it can (and will,
-        * very often) MFREE() the first mbuf in our chain.  If IF_ADJ()
-        * would free the first mbuf, we just advance our pointer to the
-        * next mbuf.  Since our calling routine passes m by value, we're
-        * not actually losing m.  Later, we don't need to put the interface
-        * pointer back on, since the caller still has it in its copy of m.
-        */
-       if ( m->m_len == sizeof( struct ifnet * )) {
-           n = m;
-           m = m->m_next;
-       } else {
-           IF_ADJ( m );
-       }
-
-       /*
-        * We can't call m_pullup(), since we need to preserve
-        * the value of m.
-        */
-       if ( m->m_len < sizeof( struct llc )) {
-printf( "atef_input size llc\n" );
-           ( n ) ? m_freem( n ) : m_freem( m );
-           return( 0 );
-       }
-       bcopy( mtod( m, caddr_t ), &llc, sizeof( struct llc ));
-       if ( llc.llc_dsap != LLC_SNAP_LSAP || llc.llc_ssap != LLC_SNAP_LSAP ||
-               llc.llc_control != LLC_UI ) {
-           ( n ) ? m_freem( n ) : m_freem( m );
-           return( 0 );
-       }
-
-       /*
-        * See IF_ADJ() above.  Here we prepend ifp to the mbuf chain.  If we
-        * didn't remove it earlier, we don't replace it here.
-        */
-       if ( n ) {
-           m_adj( m, sizeof( struct llc ));
-       } else {
-           m_adj( m, sizeof( struct llc ) - sizeof( struct ifnet *));
-           if ( m->m_len < sizeof( struct ifnet * )) {
-printf( "atef_input too small!\n" );
-               m_freem( m );
-               return( 0 );
-           }
-           *mtod( m, struct ifnet ** ) = ifp;
-       }
-
-       if ( ntohs( llc.llc_ether_type ) == ETHERTYPE_AT &&
-               bcmp( llc.llc_org_code, at_org_code,
-               sizeof( at_org_code )) == 0 ) {
-           return( &atintrq2 );
-       }
-
-       /* do we really want to pass m, here?  what happened to n? XXX */
-       if ( ntohs( llc.llc_ether_type ) == ETHERTYPE_AARP &&
-               bcmp( llc.llc_org_code, aarp_org_code,
-               sizeof( aarp_org_code )) == 0 ) {
-           aarpinput( ifp, n ? n : m );
-           return( 0 );
-       }
-
-    } else {                                   /* DIX */
-       switch ( header->ether_type ) {
-       case ETHERTYPE_AT :
-           return( &atintrq1 );
-
-       case ETHERTYPE_AARP :
-           aarpinput( ifp, m );
-           return( 0 );
-       }
-    }
-
-    ( n ) ? m_freem( n ) : m_freem( m );
-    return( 0 );
-}
-
-/*
- * If the destination is on a 802.3 wire, do phase 2 encapsulation,
- * adding the 802.2 and SNAP headers.  Always fill in the edst with the
- * ethernet address of the destination.
- */
-atef_output( dst, m, ifp, edst )
-    struct sockaddr_at *dst;
-    struct mbuf                *m;
-    struct ifnet       *ifp;
-    struct ether_addr  *edst;
-{
-    struct at_ifaddr   *aa;
-    struct mbuf                *m0;
-    struct llc         llc;
-    int                        s;
-
-    s = splimp();
-    if ( !aarpresolve( ifp, m, dst, edst )) {
-       (void) splx( s );
-       return( 1 );
-    }
-    (void) splx( s );
-
-    /*
-     * ifaddr is the first thing in at_ifaddr
-     */
-    if (( aa = (struct at_ifaddr *)at_ifawithnet( dst, ifp->if_addrlist ))
-           == 0 ) {
-       m_freem( m );
-       return( 1 );
-    }
-
-    /*
-     * In the phase 2 case, we need to prepend an mbuf for the llc header.
-     * Since we must preserve the value of m, which is passed to us by
-     * value, we m_copy() the first mbuf, and use it for our llc header.
-     *
-     * We could worry about leaving space for the ether header, but
-     * since we'll have to go through all sorts of hoops, including a
-     * possibly large copy, there's really no sense.
-     */
-    if ( aa->aa_flags & AFA_PHASE2 ) {
-       if ( M_HASCL( m ) || m->m_off - MMINOFF < sizeof( struct llc )) {
-           if (( m0 = m_copy( m, 0, m->m_len )) == 0 ) {
-               m_freem( m );
-               return( 1 );
-           }
-           if ( M_HASCL( m )) {        /* m is a cluster */
-               int s = splimp();
-
-               mclput( m );
-               splx( s );
-           }
-
-           m0->m_next = m->m_next;
-           m->m_next = m0;
-           m->m_off = MMAXOFF - sizeof( struct llc );
-           m->m_len = sizeof( struct llc );
-       } else {
-           m->m_off -= sizeof( struct llc );
-           m->m_len += sizeof( struct llc );
-       }
-
-       llc.llc_dsap = llc.llc_ssap = LLC_SNAP_LSAP;
-       llc.llc_control = LLC_UI;
-       bcopy( at_org_code, llc.llc_org_code, sizeof( at_org_code ));
-       llc.llc_ether_type = htons( ETHERTYPE_AT );
-       bcopy( &llc, mtod( m, caddr_t ), sizeof( struct llc ));
-       ether_atalk[ 0 ].ef_ethertype = EF_8023_TYPE;
-       return( 0 );
-    } else {
-       ether_atalk[ 0 ].ef_ethertype = ETHERTYPE_AT;
-       return( 0 );
-    }
-}
diff --git a/sys/ultrix/.gitignore b/sys/ultrix/.gitignore
deleted file mode 100644 (file)
index 895a5e7..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-Makefile
-Makefile.in
-.gitignore
-*.o
diff --git a/sys/ultrix/Makefile.am b/sys/ultrix/Makefile.am
deleted file mode 100644 (file)
index 9906f2c..0000000
+++ /dev/null
@@ -1 +0,0 @@
-EXTRA_DIST = Makefile.kernel at_ultrix.c kpatch-4.1 kpatch-4.2
diff --git a/sys/ultrix/Makefile.kernel b/sys/ultrix/Makefile.kernel
deleted file mode 100644 (file)
index e3aa638..0000000
+++ /dev/null
@@ -1,143 +0,0 @@
-# Ultrix specific defines, passed to subdirectories.
-# i believe that the current setup will break with this.
-#DEFS=
-DEFS=-I../../sys/generic -DUSE_OLD_RQUOTA
-OPTOPTS=
-#CC=   cc 
-CC = gcc 
-CSHAREDFLAGS=   -fPIC
-LDSHARED=      gcc
-LDSHAREDFLAGS=  -shared
-LDFLAGS_EXPORT=-rdynamic
-
-INSTALL=       install
-
-LIBSHARED=      -ldl
-AFPLIBS= 
-ADDLIBS=
-
-INCPATH = -I../../include -I../netatalk
-CFLAGS=        ${DEFS} ${OPTOPTS} ${INCPATH}
-
-ALL=   ../../libatalk ../../include ../../bin ../../etc ../../man
-
-oops:
-       @echo "Read README again.  Don't type 'make' here."
-       @exit 1
-
-all:    ${ALL}
-
-../../bin ../../etc:   ../../libatalk
-
-${ALL}:        FRC
-       cd $@; ${MAKE} ${MFLAGS} CC="${CC}" \
-           ADDLIBS="${ADDLIBS}" DEFS="${DEFS}" OPTOPTS="${OPTOPTS}" \
-           SBINDIR="${SBINDIR}" BINDIR="${BINDIR}" RESDIR="${RESDIR}" \
-           ETCDIR="${ETCDIR}" LIBDIR="${LIBDIR}" INCDIR="${INCDIR}" \
-           DESTDIR="${DESTDIR}" AFSDIR="${AFSDIR}" KRBDIR="${KRBDIR}" \
-           AFPLIBS="${AFPLIBS}" LDSHARED="${LDSHARED}" \
-           LDFLAGS_EXPORT="${LDFLAGS_EXPORT}" \
-           LDSHAREDFLAGS="${LDSHAREDFLAGS}" CSHAREDFLAGS="${CSHAREDFLAGS}" \
-           LIBSHARED="${LIBSHARED}" \
-           all
-
-FRC: kpatch-4.3 kpatch-4.4
-
-kpatch-4.3:
-       -ln -s kpatch-4.2 kpatch-4.3
-kpatch-4.4:
-       -ln -s kpatch-4.2 kpatch-4.4
-
-install :
-       -mkdir ${DESTDIR}
-       for i in ${ALL}; \
-           do (cd $$i; ${MAKE} ${MFLAGS} CC="${CC}" \
-               ADDLIBS="${ADDLIBS}" DEFS="${DEFS}" OPTOPTS="${OPTOPTS}" \
-               SBINDIR="${SBINDIR}" BINDIR="${BINDIR}" RESDIR="${RESDIR}" \
-               ETCDIR="${ETCDIR}" LIBDIR="${LIBDIR}" INCDIR="${INCDIR}" \
-               DESTDIR="${DESTDIR}" MANDIR="${MANDIR}" \
-               AFSDIR="${AFSDIR}" KRBDIR="${KRBDIR}" AFPLIBS="${AFPLIBS}" \
-               LDSHARED="${LDSHARED}" LDFLAGS_EXPORT="${LDFLAGS_EXPORT}" \
-               LDSHAREDFLAGS="${LDSHAREDFLAGS}" \
-               CSHAREDFLAGS="${CSHAREDFLAGS}" LIBSHARED="${LIBSHARED}" \
-               INSTALL="${INSTALL}" $@); \
-       done
-       rm -f ${ETCDIR}/rc.atalk
-       sed -e s@:DESTDIR:@${DESTDIR}@ -e s@:SBINDIR:@${SBINDIR}@ \
-               -e s@:BINDIR:@${BINDIR}@ -e s@:RESDIR:@${RESDIR}@ \
-               -e s@:ETCDIR:@${ETCDIR}@ -e s@:LIBDIR:@${LIBDIR}@ \
-               -e s@:INCDIR:@${INCDIR}@ \
-           < ../../distrib/initscripts/rc.atalk.bsd > ${ETCDIR}/rc.atalk
-       @echo
-       @echo "Install is done.  Don't forget to add lines from"
-       @echo "services.atalk to /etc/services and to call rc.atalk
-       @echo "in /etc/rc.  Next, install the kernel patches."
-       @echo "See README.ULTRIX for more information."
-
-kpatch :
-       @echo "WARNING!!!  This patches your kernel!!!"
-       @echo -n "(hit control-c with in 10 seconds, to stop)"
-       @sleep 10
-       @echo
-       @echo
-       @if grep -s -w atalk /sys/conf/files; then \
-           echo "You already have a version of netatalk installed."; \
-           echo "You will have to remove this old version.  See"; \
-           echo "README.ULTRIX for specific instructions."; \
-           exit 1; \
-       else \
-           case `/bin/uname -r` in \
-               4.1) echo -n "Applying 4.1 patches..."; \
-                   patch -s -d /sys -p0 < kpatch-4.1;  \
-                   echo " done."; \
-                   ;; \
-               4.2|4.3|4.4) echo -n "Applying 4.2/4.3/4.4 patches..."; \
-                   patch -s -d /sys -p0 < kpatch-4.2;  \
-                   echo " done."; \
-                   ;; \
-               *) echo "Unknown release of Ultrix"; exit 1; \
-                   ;; \
-           esac; \
-       fi
-       @echo
-       @echo "Next, install the netatalk kernel files.  See README.ULTRIX"
-       @echo "for specific instructions."
-
-kinstall :
-       @echo "Copying netatalk to kernel building area..."
-       -mkdir /sys/net/netatalk
-       cp ../netatalk/*.[ch] *.[ch] /sys/net/netatalk
-       @echo "Done."
-       @echo
-       @echo "Next, make a new kernel.  See README.ULTRIX"
-       @echo "for specific instructions."
-
-clean :
-       for i in ${ALL}; \
-           do (cd $$i; ${MAKE} ${MFLAGS} clean); \
-       done
-
-sysclean :
-
-depend :
-       for i in ${ALL}; \
-           do (cd $$i; ${MAKE} ${MFLAGS} DEFS="${DEFS}" depend); \
-       done
-       for i in ${SRC} ; do \
-           ${CC} -M ${DEFS} ${INCPATH} $$i | \
-           awk ' { if ($$1 != prev) { print rec; rec = $$0; prev = $$1; } \
-               else { if (length(rec $$2) > 78) { print rec; rec = $$0; } \
-               else rec = rec " " $$2 } } \
-               END { print rec } ' >> makedep; done
-       sed -n '1,/^# DO NOT DELETE THIS LINE/p' Makefile > Makefile.tmp
-       cat makedep >> Makefile.tmp
-       rm makedep
-       echo '# DEPENDENCIES MUST END AT END OF FILE' >> Makefile.tmp
-       echo '# IF YOU PUT STUFF HERE IT WILL GO AWAY' >> Makefile.tmp
-       echo '# see make depend above' >> Makefile.tmp
-       rm -f Makefile.bak
-       cp Makefile Makefile.bak
-       mv Makefile.tmp Makefile
-
-# DO NOT DELETE THIS LINE
-
diff --git a/sys/ultrix/at_ultrix.c b/sys/ultrix/at_ultrix.c
deleted file mode 100644 (file)
index e53fb39..0000000
+++ /dev/null
@@ -1,211 +0,0 @@
-/*
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
- * All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software and
- * its documentation for any purpose and without fee is hereby granted,
- * provided that the above copyright notice appears in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation, and that the name of The University
- * of Michigan not be used in advertising or publicity pertaining to
- * distribution of the software without specific, written prior
- * permission. This software is supplied as is without expressed or
- * implied warranties of any kind.
- *
- *     Research Systems Unix Group
- *     The University of Michigan
- *     c/o Mike Clark
- *     535 W. William Street
- *     Ann Arbor, Michigan
- *     +1-313-763-0525
- *     netatalk@itd.umich.edu
- */
-
-#include <sys/types.h>
-#include <sys/mbuf.h>
-#include <sys/socket.h>
-#include <sys/protosw.h>
-#include <sys/ioctl.h>
-#include <sys/errno.h>
-#include <net/if.h>
-#include <net/if_llc.h>
-#include <net/if_to_proto.h>
-#include <net/netisr.h>
-#include <netinet/in.h>
-#undef s_net
-#include <netinet/if_ether.h>
-
-#include "at.h"
-#include "at_var.h"
-
-extern u_char  at_org_code[ 3 ];
-extern u_char  aarp_org_code[ 3 ];
-
-/*
- * This is the magic input routine, for all AppleTalk related packets.
- * It will pick up *all* packets received, on all interfaces, apparently.
- * If it turns out that receiving all packets in this fashion causes
- * DLI to not receive packets what it should, we may need to call DLI
- * directly from within the AppleTalk input routines.  Ick.
- */
-struct mbuf *
-ddp_ifinput( m, ifp, inq, eh )
-    struct mbuf                *m;
-    struct ifnet       *ifp;
-    struct ifqueue     **inq;
-    struct ether_header        *eh;
-{
-    struct llc         llc;
-    struct if_family   *ifam;
-
-    switch ( eh->ether_type ) {
-    case ETHERTYPE_AT :
-       *inq = &atintrq1;
-       smp_lock( &(*inq)->lk_ifqueue, LK_RETRY );
-       schednetisr( NETISR_AT );
-       return( m );
-
-    case ETHERTYPE_AARP :
-       aarpinput( ifp, m );
-       return( 0 );
-
-    default :
-       if ( eh->ether_type <= ETHERMTU ) {             /* ieee802 */
-           if ( m->m_len < sizeof( struct llc )) {
-               break;
-           }
-
-           bcopy( mtod( m, caddr_t ), &llc, sizeof( struct llc ));
-           if ( llc.llc_dsap != LLC_SNAP_LSAP ||
-                   llc.llc_ssap != LLC_SNAP_LSAP ||
-                   llc.llc_control != LLC_UI ) {
-               break;
-           }
-
-           if ( bcmp( llc.llc_org_code, at_org_code,
-                   sizeof( at_org_code )) == 0 &&
-                   ntohs( llc.llc_ether_type ) == ETHERTYPE_AT ) {
-               m_adj( m, sizeof( struct llc ));
-               *inq = &atintrq2;
-               smp_lock( &(*inq)->lk_ifqueue, LK_RETRY );
-               schednetisr( NETISR_AT );
-               return( m );
-           }
-
-           if ( bcmp( llc.llc_org_code, aarp_org_code,
-                   sizeof( aarp_org_code )) == 0 &&
-                   ntohs( llc.llc_ether_type ) == ETHERTYPE_AARP ) {
-               m_adj( m, sizeof( struct llc ));
-               aarpinput( ifp, m );
-               return( 0 );
-           }
-       }
-    }
-
-    /*
-     * Check is anyone else wants this packet.
-     */
-    for ( ifam = if_family; ifam->domain != -1; ifam++ ) {
-       if (( eh->ether_type == ifam->if_type || ifam->if_type == -1 ) &&
-               ifam->prswitch &&
-               ifam->prswitch->pr_ifinput != (int (*)())ddp_ifinput ) {
-           break;
-       }
-    }
-    if ( ifam->domain != -1 && ifam->prswitch->pr_ifinput ) {
-       return( (struct mbuf *)(*ifam->prswitch->pr_ifinput)( m, ifp,
-               inq, eh ));
-    }
-
-    m_freem( m );
-    return( 0 );
-}
-
-/*
- * Fill in type and odst. odst is the media output address, i.e.
- * the MAC layer address. Type is the MAC type. Should be 0 to
- * indicate IEEE addressing.
- *
- * Stupidly enough, there's no way to say "can't send this now."
- * So, we just let the first packet go into the air. Not much
- * else to be done, except maybe bitch at DEC. Note: we're not
- * passing the mbuf to aarpresolve() -- that way it doesn't get
- * mfree-ed twice.
- */
-ddp_ifoutput( ifp, m, dst, type, odst )
-    struct ifnet       *ifp;
-    struct mbuf                *m;
-    struct sockaddr_at *dst;
-    short              *type;
-    char               *odst;
-{
-    struct at_ifaddr   *aa;
-    struct llc         *llc;
-    struct mbuf                *m0;
-
-    if ( !aarpresolve( ifp, 0, dst, odst )) {
-       *type = 0xffff;
-       return( 0 );
-    }
-
-    if (( aa = (struct at_ifaddr *)at_ifawithnet( dst, ifp->if_addrlist ))
-           == 0 ) {
-       *type = 0xffff;
-       return( 0 );
-    }
-
-    if ( aa->aa_flags & AFA_PHASE2 ) {
-       /*
-        * This code needs to be modeled after the similar code in
-        * at_sun.c -- you can't just MGET() and bcopy(), since we might be
-        * dealing with mbufs which are really pages.
-        */
-       MGET( m0, M_WAIT, MT_HEADER );
-       if ( m0 == 0 ) {
-           *type = 0xffff;
-           return( 0 );
-       }
-       m0->m_next = m->m_next;
-       m0->m_off = m->m_off;
-       m0->m_len = m->m_len;
-       bcopy( mtod( m, caddr_t ), mtod( m0, caddr_t ), m->m_len );
-       m->m_next = m0;
-       m->m_off = MMINOFF;
-       m->m_len = sizeof( struct llc );
-
-       llc = mtod( m, struct llc *);
-       llc->llc_dsap = llc->llc_ssap = LLC_SNAP_LSAP;
-       llc->llc_control = LLC_UI;
-       bcopy( at_org_code, llc->llc_org_code, sizeof( at_org_code ));
-       llc->llc_ether_type = htons( ETHERTYPE_AT );
-
-       /*
-        * Set the type to be the length of the packet, instead of 0.
-        * Ultrix used to put the length in the packet when we set type
-        * to 0, however, now we do it ourselves.
-        */
-       for ( *type = 0; m; m = m->m_next ) {
-           *type += m->m_len;
-       }
-    } else {
-       *type = ETHERTYPE_AT;
-    }
-
-    return( 1 );
-}
-
-ddp_ifioctl( ifp, cmd, data )
-    struct ifnet       *ifp;
-    int                        cmd;
-    caddr_t            data;
-{
-    switch( cmd ) {
-    case SIOCSIFADDR :
-       aarpwhohas((struct arpcom *)ifp,
-               &AA_SAT((struct ifaddr *)data)->sat_addr );
-       break;
-    default :
-       return( EINVAL );
-    }
-    return( 0 );
-}
diff --git a/sys/ultrix/kpatch-4.1 b/sys/ultrix/kpatch-4.1
deleted file mode 100644 (file)
index 8a30e43..0000000
+++ /dev/null
@@ -1,151 +0,0 @@
-*** ../sys.old/conf/files      Fri Jul  6 10:19:49 1990
---- ./conf/files       Thu Mar 12 17:33:58 1992
-***************
-*** 75,80 ****
---- 75,87 ----
-  net/netinet/tcp_timer.c      optional inet Binary
-  net/netinet/tcp_usrreq.c     optional inet Binary
-  net/netinet/udp_usrreq.c     optional inet Binary
-+ net/netatalk/aarp.c  optional atalk
-+ net/netatalk/at_control.c    optional atalk
-+ net/netatalk/at_proto.c      optional atalk
-+ net/netatalk/at_ultrix.c     optional atalk
-+ net/netatalk/ddp_input.c     optional atalk
-+ net/netatalk/ddp_output.c    optional atalk
-+ net/netatalk/ddp_usrreq.c    optional atalk
-  net/netbsc/bsc_pcb.c optional bsc Binary
-  net/netbsc/bsc_proto.c       optional bsc 
-  net/netbsc/bsc_states.c      optional bsc Binary
-*** ../sys.old/data/af_data.c  Fri Jul  6 09:40:50 1990
---- ./data/af_data.c   Thu Mar 12 17:34:03 1992
-***************
-*** 69,74 ****
---- 69,82 ----
-  #define AFNS AFNULL
-  #endif NS
-  
-+ #ifdef ATALK
-+ extern int atalk_hash(), atalk_netmatch();
-+ #define AFATALK \
-+      { atalk_hash,   atalk_netmatch }
-+ #else
-+ #define AFATALK      AFNULL
-+ #endif
-+ 
-  #ifdef BINARY
-  
-  extern       struct afswitch afswitch[];
-***************
-*** 78,83 ****
-  struct afswitch afswitch[AF_MAX] = {
-       AFNULL, AFNULL, AFINET, AFINET, AFPUP,
-       AFNULL, AFNS,   AFNULL, AFNULL, AFNULL,
-!      AFNULL
-  };
-  #endif
---- 86,92 ----
-  struct afswitch afswitch[AF_MAX] = {
-       AFNULL, AFNULL, AFINET, AFINET, AFPUP,
-       AFNULL, AFNS,   AFNULL, AFNULL, AFNULL,
-!      AFNULL, AFNULL, AFNULL, AFNULL, AFNULL,
-!      AFNULL, AFATALK, AFNULL, AFNULL, AFNULL,
-  };
-  #endif
-*** ../sys.old/data/if_to_proto_data.c Fri Jul  6 09:40:26 1990
---- ./data/if_to_proto_data.c  Thu Jun  3 11:53:44 1993
-***************
-*** 135,140 ****
---- 135,156 ----
-          { ETHERTYPE_RC,         AF_DLI,         0,              0 }
-  #endif
-  
-+ /*
-+  * Hook for netatalk.  We receive all packets.  If we're not interested
-+  * in the packet, we do a normal search on if_family for someone else
-+  * who might want the packet.
-+  * (Not yet. XXX)
-+  */
-+ #ifdef ATALK
-+ #include "atalk.h"
-+ #undef s_net
-+ #include "../net/netatalk/at.h"
-+ #define ETHER_ATALK \
-+      { -1,                   AF_APPLETALK,   ATPROTO_DDP,    0 }
-+ #else ATALK
-+ #define ETHER_ATALK  IFNULL
-+ #endif ATALK
-+ 
-  #ifdef       BINARY
-  
-  extern struct if_family if_family[];
-***************
-*** 145,151 ****
-  
-  struct if_family if_family[] = {
-!      ETHER_DECNET,   ETHER_LAT,      ETHER_APPLE, ETHER_APPLEARP,
-       ETHER_NS,       ETHER_DLI,      IFEND
-  };
-  
-  #endif
---- 162,168 ----
-  
-  struct if_family if_family[] = {
-!      ETHER_ATALK,    ETHER_DECNET,   ETHER_LAT,      ETHER_APPLE, ETHER_APPLEARP,
-       ETHER_NS,       ETHER_DLI,      IFEND
-  };
-  
-  #endif
-*** ../sys.old/data/uipc_domain_data.c Fri Jul  6 09:40:44 1990
---- ./data/uipc_domain_data.c  Thu Mar 12 17:38:18 1992
-***************
-*** 107,112 ****
---- 107,116 ----
-       ADDDOMAIN(ccitt);
-  #endif CCITT
-  #endif
-+ #ifdef ATALK
-+ #include "atalk.h"
-+      ADDDOMAIN(atalk);
-+ #endif ATALK
-  
-       for (dp = domains; dp; dp = dp->dom_next)
-               for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
-*** ../sys.old/net/net/conf_net.c      Fri Jul  6 10:03:25 1990
---- ./net/net/conf_net.c       Thu Mar 12 17:39:11 1992
-***************
-*** 236,241 ****
---- 236,245 ----
-  extern int ddpintr();
-  #endif
-  
-+ #ifdef ATALK
-+ extern int atintr();
-+ #endif
-+ 
-  #include "../net/net/netisr.h" 
-  /*
-   * table of interrupt vectors - scanned in locore when sofware 
-***************
-*** 280,285 ****
---- 284,292 ----
-  #ifdef OSI
-          {NETISR_OSI,osiintr},
-  #endif OSI
-+ #ifdef ATALK
-+      {NETISR_AT,atintr},
-+ #endif ATALK
-       {-1     ,0}
-  };
-  
-*** ../sys.old/net/net/netisr.h        Fri Jul  6 10:03:28 1990
---- ./net/net/netisr.h Thu Mar 12 17:39:45 1992
-***************
-*** 66,71 ****
---- 66,72 ----
-  #define NETISR_DLI   13              /* same as AF_DLI */
-  #define NETISR_LAT   14              /* same as AF_LAT */
-  #define NETISR_BSC   15              /* same as AF_BSC */
-+ #define NETISR_AT    16              /* same as AF_APPLETALK */
-  #define NETISR_OSI      19              /* same as AF_OSI */
-  
-  #define      schednetisr(anisr)      { set_bit_atomic(anisr,&netisr); setsoftnet(); }
diff --git a/sys/ultrix/kpatch-4.2 b/sys/ultrix/kpatch-4.2
deleted file mode 100644 (file)
index 0c8fa8e..0000000
+++ /dev/null
@@ -1,143 +0,0 @@
-*** ../sys.old/conf/files      Wed Jun 19 14:23:30 1991
---- ./conf/files       Fri Mar  6 18:06:45 1992
-***************
-*** 75,80 ****
---- 75,87 ----
-  net/netinet/tcp_timer.c      optional inet Binary
-  net/netinet/tcp_usrreq.c     optional inet Binary
-  net/netinet/udp_usrreq.c     optional inet Binary
-+ net/netatalk/aarp.c  optional atalk
-+ net/netatalk/at_control.c    optional atalk
-+ net/netatalk/at_proto.c      optional atalk
-+ net/netatalk/at_ultrix.c     optional atalk
-+ net/netatalk/ddp_input.c     optional atalk
-+ net/netatalk/ddp_output.c    optional atalk
-+ net/netatalk/ddp_usrreq.c    optional atalk
-  net/netbsc/bsc_pcb.c optional bsc Binary
-  net/netbsc/bsc_proto.c       optional bsc 
-  net/netbsc/bsc_states.c      optional bsc Binary
-*** ../sys.old/data/af_data.c  Mon Apr 29 15:45:53 1991
---- ./data/af_data.c   Sun Mar  8 22:25:15 1992
-***************
-*** 69,74 ****
---- 69,82 ----
-  #define AFNS AFNULL
-  #endif NS
-  
-+ #ifdef ATALK
-+ extern int atalk_hash(), atalk_netmatch();
-+ #define AFATALK \
-+      { atalk_hash,   atalk_netmatch }
-+ #else
-+ #define AFATALK      AFNULL
-+ #endif
-+ 
-  #ifdef BINARY
-  
-  extern       struct afswitch afswitch[];
-***************
-*** 78,83 ****
-  struct afswitch afswitch[AF_MAX] = {
-       AFNULL, AFNULL, AFINET, AFINET, AFPUP,
-       AFNULL, AFNS,   AFNULL, AFNULL, AFNULL,
-!      AFNULL
-  };
-  #endif
---- 86,92 ----
-  struct afswitch afswitch[AF_MAX] = {
-       AFNULL, AFNULL, AFINET, AFINET, AFPUP,
-       AFNULL, AFNS,   AFNULL, AFNULL, AFNULL,
-!      AFNULL, AFNULL, AFNULL, AFNULL, AFNULL,
-!      AFNULL, AFATALK, AFNULL, AFNULL, AFNULL,
-  };
-  #endif
-*** ../sys.old/data/if_to_proto_data.c Mon Apr 29 15:46:34 1991
---- ./data/if_to_proto_data.c  Thu Jun  3 11:53:44 1993
-***************
-*** 125,130 ****
---- 125,143 ----
-          { ETHERTYPE_RC,         AF_DLI,         0,              0 }
-  #endif
-  
-+ /*
-+  * Hook for netatalk.  We receive all packets.  If we're not interested
-+  * in the packet, we do a normal search on if_family for someone else
-+  * who might want the packet.
-+  */
-+ #ifdef ATALK
-+ #include "atalk.h"
-+ #undef s_net
-+ #include "../net/netatalk/at.h"
-+ #define ETHER_ATALK \
-+      { -1,                   AF_APPLETALK,   ATPROTO_DDP,    0 }
-+ #endif ATALK
-+ 
-  #ifdef       BINARY
-  
-  extern struct if_family if_family[];
-***************
-*** 134,139 ****
---- 148,156 ----
-  /* INET specific stuff is kept in drivers for now */
-  
-  struct if_family if_family[] = {
-+ #ifdef ETHER_ATALK
-+      ETHER_ATALK,
-+ #endif
-  #ifdef ETHER_DECNET
-       ETHER_DECNET,
-  #endif
-*** ../sys.old/data/uipc_domain_data.c Mon Apr 29 15:47:08 1991
---- ./data/uipc_domain_data.c  Mon Mar  2 15:24:28 1992
-***************
-*** 123,128 ****
---- 123,132 ----
-       ADDDOMAIN(x25);
-  #endif XXXVNATV
-  #endif X25_DONE
-+ #ifdef ATALK
-+ #include "atalk.h"
-+      ADDDOMAIN(atalk);
-+ #endif ATALK
-  
-  #endif
-  
-*** ../sys.old/net/net/conf_net.c      Mon Apr 29 16:16:23 1991
---- ./net/net/conf_net.c       Sun Mar  8 22:28:32 1992
-***************
-*** 233,238 ****
---- 233,242 ----
-  extern int ddpintr();
-  #endif
-  
-+ #ifdef ATALK
-+ extern int atintr();
-+ #endif
-+ 
-  #include "../net/net/netisr.h" 
-  /*
-   * table of interrupt vectors - scanned in locore when sofware 
-***************
-*** 272,277 ****
---- 276,284 ----
-  #if NLAT == 1
-       {NETISR_LAT,latintr},
-  #endif /* NLAT */
-+ #ifdef ATALK
-+      {NETISR_AT,atintr},
-+ #endif ATALK
-  #ifdef APPLETALK
-       {NETISR_DDP,ddpintr},
-  #endif APPLETALK
-*** ../sys.old/net/net/netisr.h        Mon Apr 29 16:16:21 1991
---- ./net/net/netisr.h Sun Mar  8 22:29:04 1992
-***************
-*** 72,77 ****
---- 72,78 ----
-  #define NETISR_DLI   13              /* same as AF_DLI */
-  #define NETISR_LAT   14              /* same as AF_LAT */
-  #define NETISR_BSC   15              /* same as AF_BSC */
-+ #define NETISR_AT    16              /* same as AF_APPLETALK */
-  #define NETISR_DLO      19              /* same as AF_OSI */
-  
-  #define      schednetisr(anisr)      { set_bit_atomic(anisr,&netisr); setsoftnet(); }