/*
- * $Id: volume.c,v 1.86 2009-04-28 13:01:24 franklahm Exp $
+ * $Id: volume.c,v 1.96 2009-10-27 23:35:17 didg Exp $
*
* Copyright (c) 1990,1993 Regents of The University of Michigan.
* All Rights Reserved. See COPYRIGHT.
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
-#include <dirent.h>
#include <pwd.h>
#include <grp.h>
#include <utime.h>
#include "unix.h"
#include "mangle.h"
#include "fork.h"
+#include "hash.h"
+#include "afp_vfs.h"
extern int afprun(int root, char *cmd, int *outfd);
#define VOLOPT_DPERM 24 /* dperm default directories perms */
#define VOLOPT_FPERM 25 /* fperm default files perms */
#define VOLOPT_DFLTPERM 26 /* perm */
+#define VOLOPT_EA_VFS 27 /* Extended Attributes vfs indirection */
#define VOLOPT_MAX (VOLOPT_DFLTPERM +1)
#define VOLPASSLEN 8
#define VOLOPT_DEFAULT ":DEFAULT:"
#define VOLOPT_DEFAULT_LEN 9
- struct vol_option {
- char *c_value;
- int i_value;
- };
+
+struct vol_option {
+ char *c_value;
+ int i_value;
+};
typedef struct _special_folder {
const char *name;
{AFPVOL_NODEV, "NODEV"}, /* always use 0 for device number in cnid calls */
{AFPVOL_CASEINSEN, "CASEINSENSITIVE"}, /* volume is case insensitive */
{AFPVOL_EILSEQ, "ILLEGALSEQ"}, /* encode illegal sequence */
- {AFPVOL_CACHE, "CACHEID"}, /* Use adouble v2 CNID caching, default don't use it */
- {AFPVOL_EXT_ATTRS, "EXT_ATTRS"}, /* Vol supports Extened Attributes */
+ {AFPVOL_CACHE, "CACHEID"}, /* Use adouble v2 CNID caching. Default: yes */
{AFPVOL_ACLS, "ACLS"}, /* Vol supports ACLs */
+ {AFPVOL_TM, "TM"}, /* Set "kSupportsTMLockSteal" is volume attributes */
{0, NULL}
};
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, "ads") == 0)
- options[VOLOPT_ADOUBLE].i_value = AD_VERSION1_ADS;
else if (strcasecmp(val + 1, "sfm") == 0)
options[VOLOPT_ADOUBLE].i_value = AD_VERSION1_SFM;
#endif
options[VOLOPT_ROOTPREEXEC].i_value = 1;
else if (strcasecmp(p, "upriv") == 0)
options[VOLOPT_FLAGS].i_value |= AFPVOL_UNIX_PRIV;
- else if (strcasecmp(p, "extattrs") == 0)
- options[VOLOPT_FLAGS].i_value |= AFPVOL_EXT_ATTRS;
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_CASEINSEN;
else if (strcasecmp(p, "illegalseq") == 0)
options[VOLOPT_FLAGS].i_value |= AFPVOL_EILSEQ;
- else if (strcasecmp(p, "cachecnid") == 0)
- options[VOLOPT_FLAGS].i_value |= AFPVOL_CACHE;
+ else if (strcasecmp(p, "nocnidcache") == 0)
+ options[VOLOPT_FLAGS].i_value &= ~AFPVOL_CACHE;
+ else if (strcasecmp(p, "tm") == 0)
+ options[VOLOPT_FLAGS].i_value |= AFPVOL_TM;
p = strtok(NULL, ",");
}
} else if (optionok(tmp, "denied_hosts:", val)) {
setoption(options, save, VOLOPT_DENIED_HOSTS, val);
+ } else if (optionok(tmp, "ea:", val)) {
+ if (strcasecmp(val + 1, "ad") == 0) /* the default anyway */
+ options[VOLOPT_EA_VFS].i_value = AFPVOL_EA_AD;
+ else if (strcasecmp(val + 1, "solaris") == 0)
+ options[VOLOPT_EA_VFS].i_value = AFPVOL_EA_SOLARIS;
+
} else {
/* ignore unknown options */
LOG(log_debug, logtype_afpd, "ignoring unknown volume option: %s", tmp);
/* os X start at 1 and use network order ie. 1 2 3 */
volume->v_vid = ++lastvid;
volume->v_vid = htons(volume->v_vid);
+ volume->v_vfs_ea = AFPVOL_EA_AD;
/* handle options */
if (options) {
/* shift in some flags */
volume->v_flags = options[VOLOPT_FLAGS].i_value;
+
+ if (options[VOLOPT_EA_VFS].i_value != AFPVOL_EA_AD)
+ volume->v_vfs_ea = options[VOLOPT_EA_VFS].i_value;
volume->v_ad_options = 0;
if ((volume->v_flags & AFPVOL_NODEV))
}
/* ---------------- */
-static char *myfgets( buf, size, fp )
-char *buf;
-int size;
-FILE *fp;
+static char *myfgets( char *buf, int size, FILE *fp)
{
char *p;
int c;
#endif
-static int accessvol(args, name)
-const char *args;
-const char *name;
+static int accessvol(const char *args, const char *name)
{
char buf[MAXPATHLEN + 1], *p;
struct group *gr;
return 0;
}
-static int hostaccessvol(type, volname, args, obj)
-int type;
-char *volname;
-const char *args;
-const AFPObj *obj;
+static int hostaccessvol(int type, char *volname, const char *args, const AFPObj *obj)
{
char buf[MAXPATHLEN + 1], *p, *b;
DSI *dsi = obj->handle;
return 0;
}
-static void setextmap( ext, type, creator, user)
-char *ext, *type, *creator;
-int user;
+static void setextmap(char *ext, char *type, char *creator, int user)
{
struct extmap *em;
int cnt;
* [codepage:<file>] [casefold:<num>]
* <extension> TYPE [CREATOR]
*/
-static int readvolfile(obj, p1, p2, user, pwent)
-AFPObj *obj;
-struct afp_volume_name *p1;
-char *p2;
-int user;
-struct passwd *pwent;
+static int readvolfile(AFPObj *obj, struct afp_volume_name *p1, char *p2, int user, struct passwd *pwent)
{
FILE *fp;
char path[ MAXPATHLEN + 1], tmp[ MAXPATHLEN + 1],
}
memset(save_options, 0, sizeof(save_options));
+
+ /* Enable some default options for all volumes */
+ save_options[VOLOPT_FLAGS].i_value |= AFPVOL_CACHE;
+
while ( myfgets( buf, sizeof( buf ), fp ) != NULL ) {
initline( strlen( buf ), buf );
parseline( sizeof( path ) - 1, path );
}
}
-static int getvolspace( vol, bfree, btotal, xbfree, xbtotal, bsize )
-struct vol *vol;
-u_int32_t *bfree, *btotal, *bsize;
-VolSpace *xbfree, *xbtotal;
+static int getvolspace(struct vol *vol,
+ u_int32_t *bfree, u_int32_t *btotal,
+ VolSpace *xbfree, VolSpace *xbtotal, u_int32_t *bsize)
{
int spaceflag, rc;
u_int32_t maxsize;
}
/* ----------------------- */
-static int getvolparams( bitmap, vol, st, buf, buflen )
-u_int16_t bitmap;
-struct vol *vol;
-struct stat *st;
-char *buf;
-int *buflen;
+static int getvolparams( u_int16_t bitmap, struct vol *vol, struct stat *st, char *buf, size_t *buflen)
{
struct adouble ad;
int bit = 0, isad = 1;
ashort |= VOLPBIT_ATTR_RO;
}
ashort |= VOLPBIT_ATTR_CATSEARCH;
+ ashort |= VOLPBIT_ATTR_EXT_ATTRS;
if (afp_version >= 30) {
ashort |= VOLPBIT_ATTR_UTF8;
- if (vol->v_flags & AFPVOL_UNIX_PRIV)
- ashort |= VOLPBIT_ATTR_UNIXPRIV;
+ if (vol->v_flags & AFPVOL_UNIX_PRIV)
+ ashort |= VOLPBIT_ATTR_UNIXPRIV;
+ if (vol->v_flags & AFPVOL_TM)
+ ashort |= VOLPBIT_ATTR_TM;
}
if (afp_version >= 32) {
- if (vol->v_flags & AFPVOL_EXT_ATTRS)
- ashort |= VOLPBIT_ATTR_EXT_ATTRS;
if (vol->v_flags & AFPVOL_ACLS)
- ashort |= VOLPBIT_ATTR_ACLS;
+ ashort |= VOLPBIT_ATTR_ACLS;
}
ashort = htons(ashort);
memcpy(data, &ashort, sizeof( ashort ));
}
/* ------------------------- */
-static int 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, size_t *rbuflen)
{
struct stat st;
- int buflen, ret;
+ int ret;
+ size_t buflen;
if ( stat( vol->v_path, &st ) < 0 ) {
*rbuflen = 0;
}
/* ------------------------------- */
-int afp_getsrvrparms(obj, ibuf, ibuflen, rbuf, rbuflen )
-AFPObj *obj;
-char *ibuf _U_, *rbuf;
-int ibuflen _U_, *rbuflen;
+int afp_getsrvrparms(AFPObj *obj, char *ibuf _U_, size_t ibuflen _U_, char *rbuf, size_t *rbuflen)
{
struct timeval tv;
struct stat st;
*rbuflen = data - rbuf;
data = rbuf;
- if ( gettimeofday( &tv, 0 ) < 0 ) {
+ if ( gettimeofday( &tv, NULL ) < 0 ) {
LOG(log_error, logtype_afpd, "afp_getsrvrparms(%s): gettimeofday: %s", volume->v_path, strerror(errno) );
*rbuflen = 0;
return AFPERR_PARAM;
/* -------------------------
* we are the user here
*/
-int afp_openvol(obj, ibuf, ibuflen, rbuf, rbuflen )
-AFPObj *obj;
-char *ibuf, *rbuf;
-int ibuflen _U_, *rbuflen;
+int afp_openvol(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbuflen)
{
struct stat st;
char *volname;
curdir = volume->v_dir;
if (volume->v_cnidscheme == NULL) {
volume->v_cnidscheme = strdup(DEFAULT_CNID_SCHEME);
- LOG(log_warning, logtype_afpd, "Warning: No CNID scheme for volume %s. Using default.",
- volume->v_path);
+ LOG(log_info, logtype_afpd, "Volume %s use CNID scheme %s.", volume->v_path, volume->v_cnidscheme);
}
if (volume->v_dbpath)
volume->v_cdb = cnid_open (volume->v_dbpath, volume->v_umask, volume->v_cnidscheme, (volume->v_flags & AFPVOL_NODEV));
}
/* ------------------------- */
-int afp_closevol(obj, ibuf, ibuflen, rbuf, rbuflen )
-AFPObj *obj _U_;
-char *ibuf, *rbuf _U_;
-int ibuflen _U_, *rbuflen;
+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;
/* --------------------------
poll if a volume is changed by other processes.
+ return
+ 0 no attention msg sent
+ 1 attention msg sent
+ -1 error (socket closed)
+
+ Note: if attention return -1 no packet has been
+ sent because the buffer is full, we don't care
+ either there's no reader or there's a lot of
+ traffic and another pollvoltime will follow
*/
-int pollvoltime(obj)
-AFPObj *obj;
+int pollvoltime(AFPObj *obj)
+
{
struct vol *vol;
struct timeval tv;
if (!(afp_version > 21 && obj->options.server_notif))
return 0;
- if ( gettimeofday( &tv, 0 ) < 0 )
+ if ( gettimeofday( &tv, NULL ) < 0 )
return 0;
for ( vol = Volumes; vol; vol = vol->v_next ) {
}
/* ------------------------- */
-void setvoltime(obj, vol )
-AFPObj *obj;
-struct vol *vol;
+void setvoltime(AFPObj *obj, struct vol *vol)
{
struct timeval tv;
* the afpd processes would come closer)
* [RS] */
- if ( gettimeofday( &tv, 0 ) < 0 ) {
+ if ( gettimeofday( &tv, NULL ) < 0 ) {
LOG(log_error, logtype_afpd, "setvoltime(%s): gettimeofday: %s", vol->v_path, strerror(errno) );
return;
}
/* a little granularity */
if (vol->v_mtime < tv.tv_sec) {
vol->v_mtime = tv.tv_sec;
- /* or finder doesn't update free space */
+ /* or finder doesn't update free space
+ * XXX is it still true with newer OSX?
+ */
if (afp_version > 21 && obj->options.server_notif) {
obj->attention(obj->handle, AFPATTN_NOTIFY | AFPATTN_VOLCHANGED);
}
}
/* ------------------------- */
-int afp_getvolparams(obj, ibuf, ibuflen, rbuf, rbuflen )
-AFPObj *obj _U_;
-char *ibuf, *rbuf;
-int ibuflen _U_, *rbuflen;
+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;
}
/* ------------------------- */
-int afp_setvolparams(obj, ibuf, ibuflen, rbuf, rbuflen )
-AFPObj *obj _U_;
-char *ibuf, *rbuf _U_;
-int ibuflen _U_, *rbuflen;
+int afp_setvolparams(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen)
{
struct adouble ad;
struct vol *vol;
case AD_VERSION2_OSX:
strlcat(buf, "ADOUBLE_VER:osx\n", sizeof(buf));
break;
- case AD_VERSION1_ADS:
- strlcat(buf, "ADOUBLE_VER:ads\n", sizeof(buf));
- break;
case AD_VERSION1_SFM:
strlcat(buf, "ADOUBLE_VER:sfm\n", sizeof(buf));
break;