use non-blocking IO and select instead.
* FIX: cnid_dbd: Solaris 10 compatibilty fix: don't use SO_SNDTIMEO/SO_RCVTIMEO,
use non-blocking IO and select instead.
-* REM: afile/apple_cm/apple_mv/apple_rm: use ad
+* REM: afile/achfile/apple_cm/apple_mv/apple_rm: use ad
Changes in 2.1.4
================
# Makefile.am for bin/
-SUBDIRS = ad adv1tov2 afile afppasswd cnid megatron uniconv misc
+SUBDIRS = ad adv1tov2 afppasswd cnid megatron uniconv misc
if USE_APPLETALK
SUBDIRS += aecho getzones nbp pap psorder
+++ /dev/null
-# Makefile.am for bin/afile/
-
-INCLUDES = -I$(top_srcdir)/include -I$(top_srcdir)/sys
-
-bin_PROGRAMS = achfile
-
-achfile_SOURCES = achfile.c common.c common.h
+++ /dev/null
-/*
- * $Id: achfile.c,v 1.7 2009-10-14 01:38:28 didg Exp $
- *
- afile - determine the MacOS creator/type of files
-
- Copyright (C) 2001 Sebastian Rittau.
- All rights reserved.
-
- This file may be distributed and/or modfied under the terms of the
- following license:
-
- 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. Neither the name of the author 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 AUTHOR 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 AUTHOR 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 <stdio.h>
-#include <string.h>
-#include <errno.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#ifdef HAVE_FCNTL_H
-#include <fcntl.h>
-#endif /* HAVE_FCNTL_H */
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
-
-#include <atalk/adouble.h>
-
-#include "common.h"
-
-/* Global Variables */
-static const char *type = NULL;
-static const char *creator = NULL;
-
-
-/* Print usage information. */
-static void usage(char *prog)
-{
- fprintf(stderr, "Usage: %s [-t TYPE] [-c CREATOR] FILE ...\n", prog);
-}
-
-/* Print extensive help. */
-static void help(char *prog)
-{
- usage(prog);
- fprintf(stderr,
- "\n"
- "Change the MacOS creator/type of FILEs.\n"
- "\n"
- " -t, --type=TYPE choose type\n"
- " -c, --creator=CREATOR choose creator\n"
- " -h, --help show this help and exit\n"
- " -v, --version show version information and exit\n");
-}
-
-/* Print the version. */
-static void version(void)
-{
- fprintf(stderr, "achfile (netatalk " VERSION ")\n");
-}
-
-/* Argument Handling
- * known options: -t, -c, -h, -v
- * known long options: --help, --version
- */
-#define OPTSTRING "t:c:hv-:"
-static const char *get_long_arg(int argc, char *argv[], const char *arg, const char *oa) {
- switch (*oa) {
- case '=':
- return &oa[1];
- case '\0':
- if (optind == argc) {
- fprintf(stderr, "%s: option \'%s\' requires an argument\n", argv[0], arg);
- return NULL;
- }
- return argv[optind++];
- default:
- fprintf(stderr, "%s: unrecognized option \'%s\'\n", argv[0], arg);
- usage(argv[0]);
- return NULL;
- }
-}
-
-static int parse_args(int argc, char *argv[])
-{
- int c;
- const char *longarg;
-
- /* iterate through the command line */
- while ((c = getopt(argc, argv, OPTSTRING)) != -1) {
- switch (c) {
- case 'h':
- help(argv[0]);
- exit(0);
- case 'v':
- version();
- exit(0);
- case 't':
- type = optarg;
- break;
- case 'c':
- creator = optarg;
- break;
- case '-':
- if (strcmp(optarg, "help") == 0) {
- help(argv[0]);
- exit(0);
- }
- if (strcmp(optarg, "version") == 0) {
- version();
- exit(0);
- }
- if (strncmp(optarg, "type", 4) == 0) {
- longarg = get_long_arg(argc, argv, "type", &optarg[4]);
- if (!longarg)
- return -1;
- type = longarg;
- } else if (strncmp(optarg, "creator", 7) == 0) {
- longarg = get_long_arg(argc, argv, "creator", &optarg[7]);
- if (!longarg)
- return -1;
- creator = longarg;
- }
- break;
- default:
- usage(argv[0]);
- return -1;
- }
- }
-
- /* At least one file argument is required. */
- if (argc == optind) {
- usage(argv[0]);
- return -1;
- }
-
- /* Either type or creator is required. */
- if (!type && !creator) {
- fprintf(stderr, "achfile: either type or creator must be specified\n");
- return -1;
- }
-
- /* Type and creator must be exactly four characters long. */
- if ((type && strlen(type) != 4) || (creator && strlen(creator) != 4)) {
- fprintf(stderr, "achfile: type and creator must be four character IDs\n");
- return -1;
- }
-
- return 0;
-}
-
-
-/* Change the owner/creator of each file specified on the command line. */
-static int handle_file(const char *filename)
-{
- int fd;
- struct stat statbuf;
- char *adname;
- ssize_t sz;
- char buf[AD_DATASZ];
- struct adouble *ad = (struct adouble *) &buf;
-
- if (stat(filename, &statbuf) == -1) {
- fprintf(stderr, "achfile:%s: %s\n", filename, strerror(errno));
- return -1;
- }
-
- adname = dataname_to_adname(filename);
- fd = open(adname, O_RDWR, 0);
- if (fd == -1) {
- if (errno == ENOENT)
- fprintf(stderr, "achfile:%s: no resource fork\n", filename);
- else
- fprintf(stderr, "achfile:%s: %s\n", adname, strerror(errno));
- free(adname);
- return -1;
- }
- sz = read(fd, buf, AD_DATASZ);
- if (sz == -1) {
- fprintf(stderr, "achfile:%s: %s\n", adname, strerror(errno));
- free(adname);
- close(fd);
- return -1;
- } else if (sz < AD_DATASZ) {
- fprintf(stderr, "achfile:%s: corrupt resource fork\n", filename);
- free(adname);
- close(fd);
- return -1;
- }
- if ( ntohl(ad->ad_magic) != AD_MAGIC) {
- fprintf(stderr, "achfile:%s: corrupt resource fork\n", filename);
- free(adname);
- close(fd);
- return -1;
- }
-
- /* Change Type */
- if (type) {
- buf[ADEDOFF_FINDERI + 0] = type[0];
- buf[ADEDOFF_FINDERI + 1] = type[1];
- buf[ADEDOFF_FINDERI + 2] = type[2];
- buf[ADEDOFF_FINDERI + 3] = type[3];
- }
-
- /* Change Creator */
- if (creator) {
- buf[ADEDOFF_FINDERI + 4] = creator[0];
- buf[ADEDOFF_FINDERI + 5] = creator[1];
- buf[ADEDOFF_FINDERI + 6] = creator[2];
- buf[ADEDOFF_FINDERI + 7] = creator[3];
- }
-
- /* Write file back to disk. */
- if (lseek(fd, 0, SEEK_SET) == -1) {
- fprintf(stderr, "achfile:%s: %s\n", adname, strerror(errno));
- free(adname);
- close(fd);
- return -1;
- }
- if (write(fd, &buf, AD_DATASZ) < AD_DATASZ) {
- fprintf(stderr, "achfile:%s: %s\n", adname, strerror(errno));
- free(adname);
- close(fd);
- return -1;
- }
-
- /* Clean Up */
- free(adname);
- close(fd);
-
- return 0;
-}
-
-
-int main(int argc, char *argv[])
-{
- /* argument handling */
- if (parse_args(argc, argv) == -1)
- return 1;
-
- while (optind < argc)
- handle_file(argv[optind++]);
-
- return 0;
-}
+++ /dev/null
-/*
- * $Id: common.c,v 1.3 2001-06-29 14:14:46 rufustfirefly Exp $
- *
- common functions, defines, and structures for afile, achfile, and acleandir
-
- Copyright (C) 2001 Sebastian Rittau.
- All rights reserved.
-
- This file may be distributed and/or modfied under the terms of the
- following license:
-
- 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. Neither the name of the author 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 AUTHOR 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 AUTHOR 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 <stdlib.h>
-#include <string.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#ifdef HAVE_FCNTL_H
-#include <fcntl.h>
-#endif /* HAVE_FCNTL_H */
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
-
-#include <atalk/adouble.h>
-#include <netatalk/endian.h>
-
-#include "common.h"
-
-
-#define AD_PREFIX ".AppleDouble/"
-#define PARENT_PREFIX "../"
-
-
-char *dataname_to_adname(const char *dataname)
-{
- const char *filepart;
- char *adname;
- size_t adlen = strlen(AD_PREFIX);
- size_t dirlen;
-
- /* Construct the AppleDouble file name from data fork file name. */
- adname = calloc(adlen + strlen(dataname) + 1, sizeof(char));
- filepart = rindex(dataname, '/');
- if (filepart == NULL) {
- /* Filename doesn't contain a path. */
- strcpy(adname, AD_PREFIX);
- strcpy(adname + adlen, dataname);
- } else {
- /* Filename does contain a path. */
- dirlen = (size_t) (filepart - dataname);
- strncpy(adname, dataname, dirlen + 1);
- strcpy(adname + dirlen + 1, AD_PREFIX);
- strcpy(adname + dirlen + adlen + 1, filepart + 1);
- }
-
- return adname;
-}
-
-char *adname_to_dataname(const char *adname)
-{
- const char *filepart;
- char *dataname;
- size_t plen = strlen(PARENT_PREFIX);
- size_t dirlen;
-
- /* Construct the data file name from the AppleDouble file name. */
- dataname = calloc(strlen(adname) + plen + 1, sizeof(char));
- filepart = rindex(adname, '/');
- if (filepart == NULL) {
- strcpy(dataname, PARENT_PREFIX);
- strcpy(dataname + plen, adname);
- } else {
- dirlen = (size_t) (filepart - adname);
- strncpy(dataname, adname, dirlen + 1);
- strcpy(dataname + dirlen + 1, PARENT_PREFIX);
- strcpy(dataname + dirlen + plen + 1, filepart + 1);
- }
-
- return dataname;
-}
-
-
-#define FLAG_NONE 0x0000
-#define FLAG_AD 0x0001
-#define FLAG_DIR 0x0002
-
-
-struct AFile *afile_new(const char *filename)
-{
- struct stat fdstat;
- char adbuf[AD_DATASZ];
- ssize_t sz;
- struct stat statbuf;
-
- struct AFile *afile = (struct AFile *) calloc(sizeof(struct AFile), 1);
- afile->filename = filename;
- afile->fd = open(filename, O_RDONLY);
- afile->flags = FLAG_NONE;
-
- /* Try to open file. */
- if (afile->fd == -1) {
- free(afile);
- return NULL;
- }
-
- fstat(afile->fd, &statbuf);
- afile->mode = statbuf.st_mode;
-
- /* Try to determine if this file is a regular file, a directory, or
- * something else.
- */
- fstat(afile->fd, &fdstat);
- if (S_ISREG(fdstat.st_mode)) { /* it is a regular file */
- /* Check if the opened file is the resource fork. */
- sz = read(afile->fd, adbuf, AD_DATASZ);
- if (sz >= 0) {
- /* If we can't read a whole AppleDouble header, this can't be a valid
- * AppleDouble file.
- */
- if (sz == AD_DATASZ) {
- /* ... but as we could, maybe this is. Now if only the magic number
- * would be correct ...
- */
- if (ntohl(((unsigned int *) adbuf)[0]) == AD_MAGIC)
- /* Great! It obviously is a AppleDouble file. */
- afile->flags |= FLAG_AD;
- afile->creator[0] = adbuf[ADEDOFF_FINDERI + 0];
- afile->creator[1] = adbuf[ADEDOFF_FINDERI + 1];
- afile->creator[2] = adbuf[ADEDOFF_FINDERI + 2];
- afile->creator[3] = adbuf[ADEDOFF_FINDERI + 3];
- afile->type [0] = adbuf[ADEDOFF_FINDERI + 4];
- afile->type [1] = adbuf[ADEDOFF_FINDERI + 5];
- afile->type [2] = adbuf[ADEDOFF_FINDERI + 6];
- afile->type [3] = adbuf[ADEDOFF_FINDERI + 7];
- }
-
- } else {
- afile_delete(afile);
- return NULL;
- }
-
- } else if (S_ISDIR(fdstat.st_mode)) /* it is a directory */
- afile->flags |= FLAG_DIR;
- else { /* it is neither */
- afile_delete(afile);
- return NULL;
- }
-
- return afile;
-}
-
-
-void afile_delete(struct AFile *afile)
-{
- close(afile->fd);
- free(afile);
-}
-
-
-const char *afile_filename(struct AFile *afile)
-{
- return afile->filename;
-}
-
-int afile_is_ad(struct AFile *afile)
-{
- return afile->flags & FLAG_AD;
-}
-
-int afile_is_dir(struct AFile *afile)
-{
- return afile->flags & FLAG_DIR;
-}
-
-mode_t afile_mode(struct AFile *afile)
-{
- return afile->mode;
-}
-
-const char *afile_creator(const struct AFile *afile)
-{
- return afile->creator;
-}
-
-const char *afile_type(const struct AFile *afile)
-{
- return afile->type;
-}
+++ /dev/null
-/*
- * $Id: common.h,v 1.2 2001-06-29 14:14:46 rufustfirefly Exp $
- *
- common functions, defines, and structures for afile, achfile, and acleandir
-
- Copyright (C) 2001 Sebastian Rittau.
- All rights reserved.
-
- This file may be distributed and/or modfied under the terms of the
- following license:
-
- 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. Neither the name of the author 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 AUTHOR 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 AUTHOR 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.
-*/
-
-#include <stdlib.h>
-
-
-char *dataname_to_adname(const char *dataname);
-char *adname_to_dataname(const char *adname);
-
-/* Class for handling data and AppleDouble files. Don't access directly.
- * Instead, use the methods provided below.
- */
-struct AFile {
- const char *filename;
- int fd;
- mode_t mode;
- unsigned short flags;
- char creator[4], type[4];
-};
-
-
-/* Constructor */
-struct AFile *afile_new(const char *filename);
-/* Destructor */
-void afile_delete(struct AFile *afile);
-/* Accessor Methods */
-const char *afile_filename(struct AFile *afile);
-int afile_is_ad(struct AFile *afile);
-int afile_is_dir(struct AFile *afile);
-mode_t afile_mode(struct AFile *afile);
-/* The following two methods are only valid if afile_is_ad yields true. */
-const char *afile_creator(const struct AFile *afile);
-const char *afile_type(const struct AFile *afile);
bin/ad/Makefile
bin/adv1tov2/Makefile
bin/aecho/Makefile
- bin/afile/Makefile
bin/afppasswd/Makefile
bin/cnid/Makefile
bin/cnid/cnid2_create
GENERATED_MANS = uniconv.1 asip-status.pl.1
TEMPLATE_FILES = uniconv.1.tmpl asip-status.pl.1.tmpl
-NONGENERATED_MANS = achfile.1 \
- ad.1 \
+NONGENERATED_MANS = ad.1 \
afppasswd.1 \
apple_dump.1 \
dbd.1 \
+++ /dev/null
-'\" t
-.\" Title: achfile
-.\" Author: [FIXME: author] [see http://docbook.sf.net/el/author]
-.\" Generator: DocBook XSL Stylesheets v1.75.2 <http://docbook.sf.net/>
-.\" Date: 26 Feb 1998
-.\" Manual: Netatalk 2.1
-.\" Source: Netatalk 2.1
-.\" Language: English
-.\"
-.TH "ACHFILE" "1" "26 Feb 1998" "Netatalk 2.1" "Netatalk 2.1"
-.\" -----------------------------------------------------------------
-.\" * set default formatting
-.\" -----------------------------------------------------------------
-.\" disable hyphenation
-.nh
-.\" disable justification (adjust text to left margin only)
-.ad l
-.\" -----------------------------------------------------------------
-.\" * MAIN CONTENT STARTS HERE *
-.\" -----------------------------------------------------------------
-.SH "NAME"
-achfile \- change type and/or creator of Apple Macintosh files (netatalk format)
-.SH "SYNOPSIS"
-.HP \w'\fBachfile\fR\fB\fR\ 'u
-\fBachfile\fR\fB\fR [\-t\ \fItype\fR] [\-c\ \fIcreator\fR] \fIfile\fR...
-.SH "DESCRIPTION"
-.PP
-\fBachfile\fR
-changes the Macintosh type and/or creator of the
-\fIfile\fR
-arguments which have a corresponding \&.AppleDouble file\&.
-.SH "OPTIONS"
-.PP
-\fB\-t\fR
-\fItype\fR
-change the type\&.
-.PP
-\fB\-c\fR
-\fIcreator\fR
-change the creator\&.
-.SH "DIAGNOSTICS"
-.PP
-returns exit status 0 if all files changed successfully
-.SH "SEE ALSO"
-.PP
-\fBafile\fR(1),
-\fBafpd\fR(8)