/*
- * $Id: volume.c,v 1.51.2.7.2.30 2004-05-11 08:30:07 didg Exp $
+ * $Id: volume.c,v 1.51.2.7.2.33.2.10 2005-09-28 09:53:47 didg Exp $
*
* Copyright (c) 1990,1993 Regents of The University of Michigan.
* All Rights Reserved. See COPYRIGHT.
#define VOLOPT_FORCEUID 19 /* force uid for username x */
#define VOLOPT_FORCEGID 20 /* force gid for group x */
#define VOLOPT_UMASK 21
+#define VOLOPT_DFLTPERM 22
#else
#define VOLOPT_UMASK 19
+#define VOLOPT_DFLTPERM 20
#endif /* FORCE_UIDGID */
-#define VOLOPT_MAX (VOLOPT_UMASK +1)
+#define VOLOPT_MAX (VOLOPT_DFLTPERM +1)
#define VOLOPT_NUM (VOLOPT_MAX + 1)
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}};
+typedef struct _volopt_name {
+ const u_int32_t option;
+ const char *name;
+} _vol_opt_name;
+
+static const _vol_opt_name vol_opt_names[] = {
+ {AFPVOL_A2VOL, "PRODOS"}, /* prodos volume */
+ {AFPVOL_CRLF, "CRLF"}, /* cr/lf translation */
+ {AFPVOL_NOADOUBLE, "NOADOUBLE"}, /* don't create .AppleDouble by default */
+ {AFPVOL_RO, "READONLY"}, /* read-only volume */
+ {AFPVOL_MSWINDOWS, "MSWINDOWS"}, /* deal with ms-windows yuckiness. this is going away. */
+ {AFPVOL_NOHEX, "NOHEX"}, /* don't do :hex translation */
+ {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 */
+ {AFPVOL_UNIX_PRIV, "UNIXPRIV"}, /* support unix privileges */
+ {AFPVOL_NODEV, "NODEV"}, /* always use 0 for device number in cnid calls */
+ {0, NULL}
+};
+
+static const _vol_opt_name vol_opt_casefold[] = {
+ {AFPVOL_MTOUUPPER, "MTOULOWER"},
+ {AFPVOL_MTOULOWER, "MTOULOWER"},
+ {AFPVOL_UTOMUPPER, "UTOMUPPER"},
+ {AFPVOL_UTOMLOWER, "UTOMLOWER"},
+ {0, NULL}
+};
+
static void handle_special_folders (const struct vol *);
+static int savevoloptions (const struct vol *);
static __inline__ void volfree(struct vol_option *options,
const struct vol_option *save)
return ret;
/* first part of the path. just forward to the next variable. */
- len = MIN(p - src, destlen);
+ len = MIN((size_t)(p - src), destlen);
if (len > 0) {
destlen -= len;
dest += len;
/* stuff up to next $ */
src = p + 2;
p = strchr(src, '$');
- len = p ? MIN(p - src, destlen) : destlen;
+ len = p ? MIN((size_t)(p - src), destlen) : destlen;
if (len > 0) {
strncpy(dest, src, len);
dest += len;
options[VOLOPT_FLAGS].i_value |= AFPVOL_UNIX_PRIV;
else if (strcasecmp(p, "nodev") == 0)
options[VOLOPT_FLAGS].i_value |= AFPVOL_NODEV;
+ else if (strcasecmp(p, "cachecnid") == 0)
+ options[VOLOPT_FLAGS].i_value |= AFPVOL_CACHE;
p = strtok(NULL, ",");
}
setoption(options, save, VOLOPT_DBPATH, val);
} else if (optionok(tmp, "umask:", val)) {
- options[VOLOPT_UMASK].i_value = (int)strtol(val, (char **)NULL, 8);
+ options[VOLOPT_UMASK].i_value = (int)strtol(val +1, NULL, 8);
+ } else if (optionok(tmp, "perm:", val)) {
+ options[VOLOPT_DFLTPERM].i_value = (int)strtol(val+1, NULL, 8);
} else if (optionok(tmp, "mapchars:",val)) {
setoption(options, save, VOLOPT_MAPCHARS, val);
}
/* ----------------- */
-static int validupath_osx(const struct vol *vol, const char *name)
+static int validupath_osx(const struct vol *vol _U_, const char *name)
{
return strncasecmp(name,".Apple", 6) && strncasecmp(name,"._", 2);
}
/* shift in some flags */
volume->v_flags = options[VOLOPT_FLAGS].i_value;
+ volume->v_ad_options = 0;
+ if ((volume->v_flags & AFPVOL_NODEV))
+ volume->v_ad_options |= ADVOL_NODEV;
+ if ((volume->v_flags & AFPVOL_CACHE))
+ volume->v_ad_options |= ADVOL_CACHE;
+ if ((volume->v_flags & AFPVOL_UNIX_PRIV))
+ volume->v_ad_options |= ADVOL_UNIXPRIV;
+
if (options[VOLOPT_PASSWORD].c_value)
volume->v_password = strdup(options[VOLOPT_PASSWORD].c_value);
if (options[VOLOPT_UMASK].i_value)
volume->v_umask = (mode_t)options[VOLOPT_UMASK].i_value;
+ if (options[VOLOPT_DFLTPERM].i_value)
+ volume->v_perm = (mode_t)options[VOLOPT_DFLTPERM].i_value;
+
if (options[VOLOPT_ADOUBLE].i_value)
volume->v_adouble = options[VOLOPT_ADOUBLE].i_value;
else
volume->v_adouble = AD_VERSION;
- initvoladouble(volume);
#ifdef FORCE_UIDGID
if (options[VOLOPT_FORCEUID].c_value) {
volume->v_forceuid = strdup(options[VOLOPT_FORCEUID].c_value);
}
}
+ initvoladouble(volume);
volume->v_next = Volumes;
Volumes = volume;
return 0;
}
if (Extmap_cnt) {
qsort(Extmap, Extmap_cnt, sizeof(struct extmap), extmap_cmp);
- Defextmap = Extmap;
+ if (*Extmap->em_ext == 0) {
+ /* the first line is really "." the default entry,
+ * we remove the leading '.' in setextmap
+ */
+ Defextmap = Extmap;
+ }
}
}
* For MacOS8.x support we need to create the
* .Parent file here if it doesn't exist. */
- ad_init(&ad, vol->v_adouble);
+ ad_init(&ad, vol->v_adouble, vol->v_ad_options);
if ( ad_open( vol->v_path, vol_noadouble(vol) |
ADFLAGS_HF|ADFLAGS_DIR, O_RDWR | O_CREAT,
0666, &ad) < 0 ) {
if ( nameoff ) {
ashort = htons( data - buf );
memcpy(nameoff, &ashort, sizeof( ashort ));
- aint = ucs2_to_charset( (utf8_encoding()?CH_UTF8_MAC:vol->v_maccharset), vol->v_name, data+1, 255);
+ /* name is always in mac charset, FIXME mangle if length > 27 char */
+ aint = ucs2_to_charset( vol->v_maccharset, vol->v_name, data+1, 255);
if ( aint <= 0 ) {
*buflen = 0;
return AFPERR_MISC;
}
/* ------------------------- */
-int static stat_vol(u_int16_t bitmap, struct vol *vol, char *rbuf, int *rbuflen)
+static int stat_vol(u_int16_t bitmap, struct vol *vol, char *rbuf, int *rbuflen)
{
struct stat st;
int buflen, ret;
/* ------------------------------- */
int afp_getsrvrparms(obj, ibuf, ibuflen, rbuf, rbuflen )
AFPObj *obj;
-char *ibuf, *rbuf;
-int ibuflen, *rbuflen;
+char *ibuf _U_, *rbuf;
+int ibuflen _U_, *rbuflen;
{
struct timeval tv;
struct stat st;
data = rbuf + 5;
for ( vcnt = 0, volume = Volumes; volume; volume = volume->v_next ) {
if (!(volume->v_flags & AFPVOL_NOSTAT)) {
+ struct maccess ma;
+
if ( stat( volume->v_path, &st ) < 0 ) {
LOG(log_info, logtype_afpd, "afp_getsrvrparms(%s): stat: %s",
volume->v_path, strerror(errno) );
if (!S_ISDIR(st.st_mode)) {
continue; /* not a dir */
}
+ accessmode(volume->v_path, &ma, NULL, &st);
+ if ((ma.ma_user & (AR_UREAD | AR_USEARCH)) != (AR_UREAD | AR_USEARCH)) {
+ continue; /* no r-x access */
+ }
}
if (volume->v_hide) {
continue; /* config file changed but the volume was mounted */
int afp_openvol(obj, ibuf, ibuflen, rbuf, rbuflen )
AFPObj *obj;
char *ibuf, *rbuf;
-int ibuflen, *rbuflen;
+int ibuflen _U_, *rbuflen;
{
struct stat st;
char *volname;
ret = stat_vol(bitmap, volume, rbuf, rbuflen);
if (ret == AFP_OK) {
- handle_special_folders( volume );
+ if (!(volume->v_flags & AFPVOL_RO)) {
+ handle_special_folders( volume );
+ savevoloptions( volume);
+ }
/*
* If you mount a volume twice, the second time the trash appears on
LOG (log_error, logtype_afpd,
"afp_openvol(%s): Fatal error: Unable to get stamp value from CNID backend",
volume->v_path);
+ ret = AFPERR_MISC;
goto openvol_err;
}
}
struct vol *ovol;
curdir = NULL;
for ( ovol = Volumes; ovol; ovol = ovol->v_next ) {
- if ( ovol->v_flags & AFPVOL_OPEN ) {
+ if ( (ovol->v_flags & AFPVOL_OPEN) ) {
ovol->v_flags &= ~AFPVOL_OPEN;
closevol(ovol);
}
/* ------------------------- */
int afp_closevol(obj, ibuf, ibuflen, rbuf, rbuflen )
-AFPObj *obj;
-char *ibuf, *rbuf;
-int ibuflen, *rbuflen;
+AFPObj *obj _U_;
+char *ibuf, *rbuf _U_;
+int ibuflen _U_, *rbuflen;
{
struct vol *vol, *ovol;
u_int16_t vid;
vol->v_flags &= ~AFPVOL_OPEN;
for ( ovol = Volumes; ovol; ovol = ovol->v_next ) {
- if ( ovol->v_flags & AFPVOL_OPEN ) {
+ if ( (ovol->v_flags & AFPVOL_OPEN) ) {
break;
}
}
/* ------------------------- */
int afp_getvolparams(obj, ibuf, ibuflen, rbuf, rbuflen )
-AFPObj *obj;
+AFPObj *obj _U_;
char *ibuf, *rbuf;
-int ibuflen, *rbuflen;
+int ibuflen _U_, *rbuflen;
{
struct vol *vol;
u_int16_t vid, bitmap;
/* ------------------------- */
int afp_setvolparams(obj, ibuf, ibuflen, rbuf, rbuflen )
-AFPObj *obj;
-char *ibuf, *rbuf;
-int ibuflen, *rbuflen;
+AFPObj *obj _U_;
+char *ibuf, *rbuf _U_;
+int ibuflen _U_, *rbuflen;
{
struct adouble ad;
struct vol *vol;
return( AFPERR_PARAM );
}
- if (vol->v_flags & AFPVOL_RO)
+ if ((vol->v_flags & AFPVOL_RO))
return AFPERR_VLOCK;
/* we can only set the backup date. */
if (bitmap != (1 << VOLPBIT_BDATE))
return AFPERR_BITMAP;
- ad_init(&ad, vol->v_adouble);
+ 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 (errno == EROFS)
if ( !ret && folder->hide) {
/* Hide it */
- ad_init(&ad, vol->v_adouble);
+ ad_init(&ad, vol->v_adouble, vol->v_ad_options);
if (ad_open( p, vol_noadouble(vol) | ADFLAGS_HF|ADFLAGS_DIR,
O_RDWR|O_CREAT, 0666, &ad) < 0) {
free (p);
{
const _special_folder *p = &special_folders[0];
- if (vol->v_flags & AFPVOL_RO)
+ if ((vol->v_flags & AFPVOL_RO))
return;
for (; p->name != NULL; p++) {
}
}
+/*
+ * Save the volume options to a file, used by
+ * shell utilities.
+ * Writing the file everytime a volume is opened is
+ * unnecessary, but it shouldn't hurt much.
+ */
+static int savevoloptions (const struct vol *vol)
+{
+ char buf[16348];
+ char item[MAXPATHLEN];
+ int fd;
+ int ret = 0;
+ struct flock lock;
+ const _vol_opt_name *op = &vol_opt_names[0];
+ const _vol_opt_name *cf = &vol_opt_casefold[0];
+
+ strlcpy (item, vol->v_path, sizeof(item));
+ strlcat (item, "/.AppleDesktop/", sizeof(item));
+ strlcat (item, VOLINFOFILE, sizeof(item));
+
+ if ((fd = open( item, O_RDWR | O_CREAT , 0666)) <0 ) {
+ LOG(log_debug, logtype_afpd,"Error opening %s: %s", item, strerror(errno));
+ return (-1);
+ }
+
+ /* try to get a lock */
+ lock.l_start = 0;
+ lock.l_whence = SEEK_SET;
+ lock.l_len = 0;
+ lock.l_type = F_WRLCK;
+
+ if (fcntl(fd, F_SETLK, &lock) < 0) {
+ if (errno == EACCES || errno == EAGAIN) {
+ /* ignore, other process already writing the file */
+ return 0;
+ } else {
+ LOG(log_error, logtype_cnid, "savevoloptions: cannot get lock: %s", strerror(errno));
+ return (-1);
+ }
+ }
+
+ /* write volume options */
+ snprintf(buf, sizeof(buf), "MAC_CHARSET:%s\n", vol->v_maccodepage);
+ snprintf(item, sizeof(item), "VOL_CHARSET:%s\n", vol->v_volcodepage);
+ 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;
+ }
+
+ strlcat(buf, "CNIDBACKEND:", sizeof(buf));
+ strlcat(buf, vol->v_cnidscheme, sizeof(buf));
+ strlcat(buf, "\n", sizeof(buf));
+
+ strlcat(buf, "CNIDDBDHOST:", sizeof(buf));
+ strlcat(buf, Cnid_srv, sizeof(buf));
+ strlcat(buf, "\n", sizeof(buf));
+
+ snprintf(item, sizeof(item), "CNIDDBDPORT:%u\n", Cnid_port);
+ strlcat(buf, item, sizeof(buf));
+
+ strcpy(item, "CNID_DBPATH:");
+ if (vol->v_dbpath)
+ strlcat(item, vol->v_dbpath, sizeof(item));
+ else
+ strlcat(item, vol->v_path, sizeof(item));
+ strlcat(item, "\n", sizeof(item));
+ strlcat(buf, item, sizeof(buf));
+
+ /* volume flags */
+ strcpy(item, "VOLUME_OPTS:");
+ for (;op->name; op++) {
+ if ( (vol->v_flags & op->option) ) {
+ strlcat(item, op->name, sizeof(item));
+ strlcat(item, " ", sizeof(item));
+ }
+ }
+ strlcat(item, "\n", sizeof(item));
+ strlcat(buf, item, sizeof(buf));
+
+ /* casefold flags */
+ strcpy(item, "VOLCASEFOLD:");
+ for (;cf->name; cf++) {
+ if ( (vol->v_casefold & cf->option) ) {
+ strlcat(item, cf->name, sizeof(item));
+ strlcat(item, " ", sizeof(item));
+ }
+ }
+ strlcat(item, "\n", sizeof(item));
+ strlcat(buf, item, sizeof(buf));
+
+ if (strlen(buf) >= sizeof(buf)-1)
+ LOG(log_debug, logtype_afpd,"Error writing .volinfo file: buffer too small, %s", buf);
+
+
+ if (write( fd, buf, strlen(buf)) < 0) {
+ LOG(log_debug, logtype_afpd,"Error writing .volinfo file: %s", strerror(errno));
+ goto done;
+ }
+ ftruncate(fd, strlen(buf));
+
+done:
+ lock.l_type = F_UNLCK;
+ fcntl(fd, F_SETLK, &lock);
+ close (fd);
+ return ret;
+}