#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>
#include <arpa/inet.h>
-#include <uuid/uuid.h>
-
-#include <atalk/asp.h>
#include <atalk/dsi.h>
#include <atalk/adouble.h>
#include <atalk/afp.h>
#include <atalk/volinfo.h>
#include <atalk/logger.h>
#include <atalk/vfs.h>
+#include <atalk/uuid.h>
#include <atalk/ea.h>
+
#ifdef CNID_DB
#include <atalk/cnid.h>
#endif /* CNID_DB*/
#include "mangle.h"
#include "fork.h"
#include "hash.h"
+#include "acls.h"
extern int afprun(int root, char *cmd, int *outfd);
#define UUID_PRINTABLE_STRING_LENGTH 37
#endif
+/* Globals */
+struct vol *current_vol; /* last volume from getvolbyvid() */
+
static struct vol *Volumes = NULL;
static u_int16_t lastvid = 0;
static char *Trash = "\02\024Network Trash Folder";
#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
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 */
int afpmaster = 0;
int xlatevolname = 0;
- if (! ((DSI *)obj->handle)->child)
+ if (parent_or_child == 0)
afpmaster = 1;
if (path && !volname)
} else if (is_var(p, "$c")) {
if (afpmaster && xlatevolname)
return NULL;
- 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;
-
- } else 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;
} else if (is_var(p, "$i")) {
if (afpmaster && xlatevolname)
return NULL;
- 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;
-
- } else 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;
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;
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)
options[VOLOPT_ROOTPREEXEC].i_value = 1;
else if (strcasecmp(p, "upriv") == 0)
options[VOLOPT_FLAGS].i_value |= AFPVOL_UNIX_PRIV;
- else if (strcasecmp(p, "acls") == 0)
- options[VOLOPT_FLAGS].i_value |= AFPVOL_ACLS;
else if (strcasecmp(p, "nodev") == 0)
options[VOLOPT_FLAGS].i_value |= AFPVOL_NODEV;
else if (strcasecmp(p, "caseinsensitive") == 0)
options[VOLOPT_FLAGS].i_value &= ~AFPVOL_CACHE;
else if (strcasecmp(p, "tm") == 0)
options[VOLOPT_FLAGS].i_value |= AFPVOL_TM;
+ else if (strcasecmp(p, "searchdb") == 0)
+ options[VOLOPT_FLAGS].i_value |= AFPVOL_SEARCHDB;
/* Found this in branch dir-rewrite, maybe we want to use it sometimes */
#if 0
else if (strcasecmp(p, "cdrom") == 0)
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);
char suffix[6]; /* max is #FFFF */
u_int16_t flags;
+ LOG(log_debug, logtype_afpd, "createvol: Volume '%s'", name);
+
if ( name == NULL || *name == '\0' ) {
if ((name = strrchr( path, '/' )) == NULL) {
return -1; /* Obviously not a fully qualified path */
if ( 0 >= ( u8mvlen = convert_string(CH_UTF8_MAC, CH_UCS2, tmpname, tmpvlen, u8mtmpname, AFPVOL_U8MNAMELEN*2)) )
return -1;
- LOG(log_debug, logtype_afpd, "createvol: Volume '%s' -> UTF8-MAC Name: '%s'", name, tmpname);
+ LOG(log_maxdebug, logtype_afpd, "createvol: Volume '%s' -> UTF8-MAC Name: '%s'", name, tmpname);
/* Maccharset Volume Name */
/* Firsty convert name from unixcharset to maccharset */
if ( 0 >= ( macvlen = convert_string(obj->options.maccharset, CH_UCS2, tmpname, tmpvlen, mactmpname, AFPVOL_U8MNAMELEN*2)) )
return -1;
- LOG(log_debug, logtype_afpd, "createvol: Volume '%s' -> Longname: '%s'", name, tmpname);
+ LOG(log_maxdebug, logtype_afpd, "createvol: Volume '%s' -> Longname: '%s'", name, tmpname);
/* check duplicate */
for ( volume = Volumes; volume; volume = volume->v_next ) {
/* os X start at 1 and use network order ie. 1 2 3 */
volume->v_vid = ++lastvid;
volume->v_vid = htons(volume->v_vid);
+#ifdef HAVE_ACLS
+ if (check_vol_acl_support(volume))
+ volume->v_flags |= AFPVOL_ACLS
+;
+#endif
/* handle options */
if (options) {
- /* should we casefold? */
volume->v_casefold = options[VOLOPT_CASEFOLD].i_value;
-
- /* shift in some flags */
- volume->v_flags = options[VOLOPT_FLAGS].i_value;
+ volume->v_flags |= options[VOLOPT_FLAGS].i_value;
if (options[VOLOPT_EA_VFS].i_value)
volume->v_vfs_ea = options[VOLOPT_EA_VFS].i_value;
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);
if (volume->v_flags & AFPVOL_TM) {
char *uuid = get_uuid(obj, volume->v_localname);
if (!uuid) {
- LOG(log_error, logtype_afpd, "Volume '%s': couldn't get UUID, disabling TM support",
+ LOG(log_error, logtype_afpd, "Volume '%s': couldn't get UUID",
volume->v_localname);
- volume->v_flags &= ~AFPVOL_TM;
} else {
volume->v_uuid = uuid;
LOG(log_debug, logtype_afpd, "Volume '%s': UUID '%s'",
obj->options.umask);
save_options[VOLOPT_UMASK].i_value = obj->options.umask;
+ LOG(log_debug, logtype_afpd, "readvolfile: \"%s\"", path);
+
while ( myfgets( buf, sizeof( buf ), fp ) != NULL ) {
initline( strlen( buf ), buf );
parseline( sizeof( path ) - 1, path );
volset(options, save_options, volname, sizeof(volname) - 1, tmp);
}
- /* check allow/deny lists:
+ /* check allow/deny lists (if not afpd master loading volumes for Zeroconf reg.):
allow -> either no list (-1), or in list (1)
deny -> either no list (-1), or not in list (0) */
- if (accessvol(options[VOLOPT_ALLOW].c_value, obj->username) &&
- (accessvol(options[VOLOPT_DENY].c_value, obj->username) < 1) &&
- hostaccessvol(VOLOPT_ALLOWED_HOSTS, volname, options[VOLOPT_ALLOWED_HOSTS].c_value, obj) &&
- (hostaccessvol(VOLOPT_DENIED_HOSTS, volname, options[VOLOPT_DENIED_HOSTS].c_value, obj) < 1)) {
+ if (parent_or_child == 0
+ ||
+ (accessvol(options[VOLOPT_ALLOW].c_value, obj->username) &&
+ (accessvol(options[VOLOPT_DENY].c_value, obj->username) < 1) &&
+ hostaccessvol(VOLOPT_ALLOWED_HOSTS, volname, options[VOLOPT_ALLOWED_HOSTS].c_value, obj) &&
+ (hostaccessvol(VOLOPT_DENIED_HOSTS, volname, options[VOLOPT_DENIED_HOSTS].c_value, obj) < 1))) {
/* handle read-only behaviour. semantics:
* 1) neither the rolist nor the rwlist exist -> rw
* 2) rolist exists -> ro if user is in it.
* 3) rwlist exists -> ro unless user is in it. */
- if (((options[VOLOPT_FLAGS].i_value & AFPVOL_RO) == 0) &&
- ((accessvol(options[VOLOPT_ROLIST].c_value,
- obj->username) == 1) ||
- !accessvol(options[VOLOPT_RWLIST].c_value,
- obj->username)))
+ if (parent_or_child == 1
+ &&
+ ((options[VOLOPT_FLAGS].i_value & AFPVOL_RO) == 0)
+ &&
+ ((accessvol(options[VOLOPT_ROLIST].c_value, obj->username) == 1) ||
+ !accessvol(options[VOLOPT_RWLIST].c_value, obj->username)))
options[VOLOPT_FLAGS].i_value |= AFPVOL_RO;
/* do variable substitution for volname */
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);
}
* .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 ) {
+ if (ad_open(&ad, vol->v_path, ADFLAGS_HF | ADFLAGS_DIR, O_RDWR | O_CREAT, 0666) != 0 ) {
isad = 0;
vol->v_ctime = AD_DATE_FROM_UNIX(st->st_mtime);
#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 */
free_volumes();
}
- if (! ((DSI *)obj->handle)->child) {
+ if (parent_or_child == 0) {
LOG(log_debug, logtype_afpd, "load_volumes: AFP MASTER");
} else {
LOG(log_debug, logtype_afpd, "load_volumes: user: %s", obj->username);
}
#endif
- volume->v_cdb = cnid_open(volume->v_dbpath ? volume->v_dbpath : volume->v_path,
+ volume->v_cdb = cnid_open(volume->v_path,
volume->v_umask,
volume->v_cnidscheme,
flags,
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);
}
}
}
-#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 );
volume,
DIRDID_ROOT_PARENT,
DIRDID_ROOT,
- bfromcstr(volume->v_path))
+ bfromcstr(volume->v_path),
+ st.st_ctime)
) == NULL) {
free(vol_mname);
LOG(log_error, logtype_afpd, "afp_openvol(%s): malloc: %s", volume->v_path, strerror(errno) );
goto openvol_err;
}
free(vol_mname);
-
volume->v_root = dir;
curdir = dir;
}
deletevol(vol);
+ current_vol = NULL;
return( AFP_OK );
}
return( NULL );
}
-#ifdef FORCE_UIDGID
- set_uidgid ( vol );
-#endif /* FORCE_UIDGID */
+ current_vol = vol;
return( vol );
}
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 ) {
+ if ( ad_open(&ad, vol->v_path, ADFLAGS_HF|ADFLAGS_DIR, O_RDWR) < 0 ) {
if (errno == EROFS)
return AFPERR_VLOCK;
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);
+ if (ad_open(&ad, p, ADFLAGS_HF | ADFLAGS_DIR, O_RDWR | O_CREAT, 0666) != 0) {
+ free(p);
free(q);
return (-1);
}
*/
char *get_uuid(const AFPObj *obj, const char *volname)
{
- struct stat st;
-
- char *usersign;
- int fd, i;
- struct stat tmpstat;
char *volname_conf;
- int header = 0;
char buf[1024], uuid[UUID_PRINTABLE_STRING_LENGTH], *p;
- FILE *fp, *randomp;
- size_t len;
+ FILE *fp;
+ struct stat tmpstat;
+ int fd;
if ((fp = fopen(obj->options.uuidconf, "r")) != NULL) { /* read open? */
/* scan in the conf file */
p++;
if (sscanf(p, "%36s", uuid) == 1 ) {
+ for (int i=0; uuid[i]; i++)
+ uuid[i] = toupper(uuid[i]);
LOG(log_debug, logtype_afpd, "get_uuid('%s'): UUID: '%s'", volname, uuid);
fclose(fp);
return strdup(uuid);
fclose(fp);
/* not found or no file, reopen in append mode */
- if ((fp = fopen(obj->options.uuidconf, "a+")) == NULL) {
+
+ if (stat(obj->options.uuidconf, &tmpstat)) { /* no file */
+ if (( fd = creat(obj->options.uuidconf, 0644 )) < 0 ) {
+ LOG(log_error, logtype_atalkd, "ERROR: Cannot create %s (%s).",
+ obj->options.uuidconf, strerror(errno));
+ return NULL;
+ }
+ if (( fp = fdopen( fd, "w" )) == NULL ) {
+ LOG(log_error, logtype_atalkd, "ERROR: Cannot fdopen %s (%s).",
+ obj->options.uuidconf, strerror(errno));
+ close(fd);
+ return NULL;
+ }
+ } else if ((fp = fopen(obj->options.uuidconf, "a+")) == NULL) { /* not found */
LOG(log_error, logtype_afpd, "Cannot create or append to %s (%s).",
obj->options.uuidconf, strerror(errno));
return NULL;
fseek(fp, 0L, SEEK_END);
if(ftell(fp) == 0) { /* size = 0 */
fprintf(fp, "# DON'T TOUCH NOR COPY THOUGHTLESSLY!\n");
- fprintf(fp, "# This file is auto-generated by afpd.\n");
- fprintf(fp, "# \n");
- fprintf(fp, "# This file stores UUIDs for all volumes, either auto-generated ones\n");
- fprintf(fp, "# or the value from AppleVolumes.default:uuid\n");
- fprintf(fp, "# \n");
- fprintf(fp, "# If both values differ, the one from AppleVolumes.default is used.\n\n");
+ fprintf(fp, "# This file is auto-generated by afpd\n");
+ fprintf(fp, "# and stores UUIDs for TM volumes.\n\n");
} else {
fseek(fp, -1L, SEEK_END);
if(fgetc(fp) != '\n') fputc('\n', fp); /* last char is \n? */
}
/* generate uuid and write to file */
- uuid_t id;
- uuid_generate(id);
- uuid_unparse(id, uuid);
- LOG(log_debug, logtype_afpd, "get_uuid('%s'): generated UUID '%s'", volname, uuid);
+ atalk_uuid_t id;
+ const char *cp;
+ randombytes((void *)id, 16);
+ cp = uuid_bin2string(id);
+
+ LOG(log_debug, logtype_afpd, "get_uuid('%s'): generated UUID '%s'", volname, cp);
- fprintf(fp, "\"%s\"\t%36s\n", volname, uuid);
+ fprintf(fp, "\"%s\"\t%36s\n", volname, cp);
fclose(fp);
return strdup(uuid);