/*
- * $Id: volume.c,v 1.51.2.7.2.32 2004-07-11 02:17:51 bfernhomberg 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)
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;
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++) {
/* volume flags */
strcpy(item, "VOLUME_OPTS:");
for (;op->name; op++) {
- if ( vol->v_flags & op->option ) {
+ if ( (vol->v_flags & op->option) ) {
strlcat(item, op->name, sizeof(item));
strlcat(item, " ", sizeof(item));
}
/* casefold flags */
strcpy(item, "VOLCASEFOLD:");
for (;cf->name; cf++) {
- if ( vol->v_casefold & cf->option ) {
+ if ( (vol->v_casefold & cf->option) ) {
strlcat(item, cf->name, sizeof(item));
strlcat(item, " ", sizeof(item));
}