* NEW: afpd: Per volume "login message", NetAFP bug ID #18
* NEW: afpd: Cross-platform locking (share modes) on Solaris and derivates
with Solaris CIFS/SMB server. Uses new Solaris fcntl F_SHARE share
- reservation locking primitives.
+ reservation locking primitives. Enabled by default, set global
+ "solaris share reservations" option to false to disable it.
* NEW: ad: ad set subcommand for changing Mac metadata on the server
* UPD: unix charset is UTF8 by default
vol charset is same value as unix charset by default
}
}
- close_all_vol();
+ close_all_vol(obj);
if (obj->logout)
(*obj->logout)();
DSI *dsi = (DSI *)(obj->dsi);
LOG(log_note, logtype_afpd, "AFP logout by %s", obj->username);
- of_close_all_forks();
- close_all_vol();
+ of_close_all_forks(obj);
+ close_all_vol(obj);
dsi->flags = DSI_AFP_LOGGED_OUT;
*rbuflen = 0;
return AFP_OK;
return 0;
}
-static int fork_setmode(struct adouble *adp, int eid, int access, int ofrefnum)
+static int fork_setmode(const AFPObj *obj, struct adouble *adp, int eid, int access, int ofrefnum)
{
int ret;
int readset;
#ifdef HAVE_FSHARE_T
fshare_t shmd;
- shmd.f_access = (access & OPENACC_RD ? F_RDACC : 0) | (access & OPENACC_WR ? F_WRACC : 0);
- if (shmd.f_access == 0)
- /* we must give an access mode, otherwise fcntl will complain */
- shmd.f_access = F_RDACC;
- shmd.f_deny = (access & OPENACC_DRD ? F_RDDNY : F_NODNY) | (access & OPENACC_DWR) ? F_WRDNY : 0;
- shmd.f_id = ofrefnum;
+ if (obj->options.flags & OPTION_SHARE_RESERV) {
+ shmd.f_access = (access & OPENACC_RD ? F_RDACC : 0) | (access & OPENACC_WR ? F_WRACC : 0);
+ if (shmd.f_access == 0)
+ /* we must give an access mode, otherwise fcntl will complain */
+ shmd.f_access = F_RDACC;
+ shmd.f_deny = (access & OPENACC_DRD ? F_RDDNY : F_NODNY) | (access & OPENACC_DWR) ? F_WRDNY : 0;
+ shmd.f_id = ofrefnum;
- int fd = (eid == ADEID_DFORK) ? ad_data_fileno(adp) : ad_reso_fileno(adp);
+ int fd = (eid == ADEID_DFORK) ? ad_data_fileno(adp) : ad_reso_fileno(adp);
- if (fd != -1 && fd != -2 && fcntl(fd, F_SHARE, &shmd) != 0) {
- LOG(log_debug, logtype_afpd, "fork_setmode: fcntl: %s", strerror(errno));
- errno = EACCES;
- return -1;
+ if (fd != -1 && fd != -2 && fcntl(fd, F_SHARE, &shmd) != 0) {
+ LOG(log_debug, logtype_afpd, "fork_setmode: fcntl: %s", strerror(errno));
+ errno = EACCES;
+ return -1;
+ }
}
-
#endif
+
if (! (access & (OPENACC_WR | OPENACC_RD | OPENACC_DWR | OPENACC_DRD))) {
return ad_lock(adp, eid, ADLOCK_RD | ADLOCK_FILELOCK, AD_FILELOCK_OPEN_NONE, 1, ofrefnum);
}
ad_getattr(ofork->of_ad, &bshort);
if ((bshort & htons(ATTRBIT_NOWRITE)) && (access & OPENACC_WR)) {
ad_close( ofork->of_ad, adflags | ADFLAGS_SETSHRMD);
- of_dealloc( ofork );
+ of_dealloc(obj, ofork );
ofrefnum = 0;
memcpy(rbuf, &ofrefnum, sizeof(ofrefnum));
return(AFPERR_OLOCK);
if ((eid == ADEID_DFORK)
|| (ad_reso_fileno(ofork->of_ad) != -1)
|| (ofork->of_ad->ad_vers == AD_VERSION_EA)) {
- ret = fork_setmode(ofork->of_ad, eid, access, ofrefnum);
+ ret = fork_setmode(obj, ofork->of_ad, eid, access, ofrefnum);
/* can we access the fork? */
if (ret < 0) {
ofork->of_flags |= AFPFORK_ERROR;
ret = errno;
ad_close( ofork->of_ad, adflags | ADFLAGS_SETSHRMD);
- of_dealloc( ofork );
+ of_dealloc(obj, ofork );
switch (ret) {
case EAGAIN: /* return data anyway */
case EACCES:
return( AFP_OK );
openfork_err:
- of_dealloc( ofork );
+ of_dealloc(obj, ofork);
if (errno == EACCES)
return (access & OPENACC_WR) ? AFPERR_LOCK : AFPERR_ACCESS;
return ret;
return( err );
}
-int afp_closefork(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen)
+int afp_closefork(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen)
{
struct ofork *ofork;
uint16_t ofrefnum;
LOG(log_debug, logtype_afpd, "afp_closefork(fork: %s)",
(ofork->of_flags & AFPFORK_DATA) ? "d" : "r");
-#ifdef HAVE_FSHARE_T
- fshare_t shmd;
- shmd.f_id = ofork->of_refnum;
- if (AD_DATA_OPEN(ofork->of_ad))
- fcntl(ad_data_fileno(ofork->of_ad), F_UNSHARE, &shmd);
- if (AD_RSRC_OPEN(ofork->of_ad))
- fcntl(ad_reso_fileno(ofork->of_ad), F_UNSHARE, &shmd);
-#endif
-
- if ( of_closefork( ofork ) < 0 ) {
+ if (of_closefork(obj, ofork) < 0 ) {
LOG(log_error, logtype_afpd, "afp_closefork(%s): of_closefork: %s", of_name(ofork), strerror(errno) );
return( AFPERR_PARAM );
}
char *, uint16_t *, const int,
struct adouble *,
struct stat *);
-extern void of_dealloc (struct ofork *);
+extern void of_dealloc (const AFPObj *obj, struct ofork *);
extern struct ofork *of_find (const uint16_t);
extern struct ofork *of_findname (struct path *);
extern int of_rename (const struct vol *,
extern int of_flush (const struct vol *);
extern int of_stat (struct path *);
extern int of_statdir (struct vol *vol, struct path *);
-extern int of_closefork (struct ofork *ofork);
-extern void of_closevol (const struct vol *vol);
-extern void of_close_all_forks(void);
+extern int of_closefork (const AFPObj *obj, struct ofork *ofork);
+extern void of_closevol (const AFPObj *obj, const struct vol *vol);
+extern void of_close_all_forks(const AFPObj *obj);
extern struct adouble *of_ad (const struct vol *, struct path *, struct adouble *);
#ifdef HAVE_ATFUNCS
}
#endif
-void of_dealloc( struct ofork *of)
+void of_dealloc(const AFPObj *obj, struct ofork *of)
{
if (!oforks)
return;
free( of->of_ad);
} else {/* someone's still using it. just free this user's locks */
ad_unlock(of->of_ad, of->of_refnum, of->of_flags & AFPFORK_ERROR ? 0 : 1);
+#ifdef HAVE_FSHARE_T
+ if (obj->options.flags & OPTION_SHARE_RESERV) {
+ fshare_t shmd;
+ shmd.f_id = of->of_refnum;
+ if (AD_DATA_OPEN(of->of_ad))
+ fcntl(ad_data_fileno(of->of_ad), F_UNSHARE, &shmd);
+ if (AD_RSRC_OPEN(of->of_ad))
+ fcntl(ad_reso_fileno(of->of_ad), F_UNSHARE, &shmd);
+ }
+#endif
}
free( of );
}
/* --------------------------- */
-int of_closefork(struct ofork *ofork)
+int of_closefork(const AFPObj *obj, struct ofork *ofork)
{
struct timeval tv;
int adflags = 0;
fce_register_file_modification(ofork);
}
+ of_dealloc(obj, ofork);
+
ret = 0;
if ( ad_close( ofork->of_ad, adflags | ADFLAGS_SETSHRMD) < 0 ) {
ret = -1;
}
- of_dealloc( ofork );
return ret;
}
/* ----------------------
close all forks for a volume
*/
-void of_closevol(const struct vol *vol)
+void of_closevol(const AFPObj *obj, const struct vol *vol)
{
int refnum;
for ( refnum = 0; refnum < nforks; refnum++ ) {
if (oforks[ refnum ] != NULL && oforks[refnum]->of_vol == vol) {
- if (of_closefork( oforks[ refnum ]) < 0 ) {
+ if (of_closefork(obj, oforks[ refnum ]) < 0 ) {
LOG(log_error, logtype_afpd, "of_closevol: %s", strerror(errno) );
}
}
/* ----------------------
close all forks for a volume
*/
-void of_close_all_forks(void)
+void of_close_all_forks(const AFPObj *obj)
{
int refnum;
for ( refnum = 0; refnum < nforks; refnum++ ) {
if (oforks[ refnum ] != NULL) {
- if (of_closefork( oforks[ refnum ]) < 0 ) {
+ if (of_closefork(obj, oforks[ refnum ]) < 0 ) {
LOG(log_error, logtype_afpd, "of_close_all_forks: %s", strerror(errno) );
}
}
}
}
- char *msg;
+ const char *msg;
if ((msg = iniparser_getstring(obj->iniconfig, volume->v_configname, "login message", NULL)) != NULL)
setmessage(msg);
return ret;
}
-void closevol(struct vol *vol)
+void closevol(const AFPObj *obj, struct vol *vol)
{
if (!vol)
return;
vol->v_flags &= ~AFPVOL_OPEN;
- of_closevol(vol);
+ of_closevol(obj, vol);
dir_free( vol->v_root );
vol->v_root = NULL;
}
/* ------------------------- */
-void close_all_vol(void)
+void close_all_vol(const AFPObj *obj)
{
struct vol *ovol;
curdir = NULL;
for ( ovol = getvolumes(); ovol; ovol = ovol->v_next ) {
if ( (ovol->v_flags & AFPVOL_OPEN) ) {
ovol->v_flags &= ~AFPVOL_OPEN;
- closevol(ovol);
+ closevol(obj, ovol);
}
}
}
/* ------------------------- */
-int afp_closevol(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen)
+int afp_closevol(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen)
{
struct vol *vol;
uint16_t vid;
(void)chdir("/");
curdir = NULL;
- closevol(vol);
+ closevol(obj, vol);
return( AFP_OK );
}
int afp_closevol (AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen);
/* netatalk functions */
-extern void close_all_vol(void);
-extern void closevol(struct vol *vol);
+extern void close_all_vol(const AFPObj *obj);
+extern void closevol(const AFPObj *obj, struct vol *vol);
#endif
#define OPTION_ACL2MACCESS (1 << 8)
#define OPTION_NOZEROCONF (1 << 9)
#define OPTION_KEEPSESSIONS (1 << 10) /* preserve sessions across master afpd restart with SIGQUIT */
+#define OPTION_SHARE_RESERV (1 << 11) /* whether to use Solaris fcntl F_SHARE locks */
#define PASSWD_NONE 0
#define PASSWD_SET (1 << 0)
extern int afp_config_parse(AFPObj *obj, char *processname);
extern int load_charset(struct vol *vol);
-extern int load_volumes(AFPObj *obj, void (*delvol_fn)(struct vol *));
+extern int load_volumes(AFPObj *obj, void (*delvol_fn)(const AFPObj *obj, struct vol *));
extern void unload_volumes(AFPObj *obj);
extern struct vol *getvolumes(void);
extern struct vol *getvolbyvid(const uint16_t);
* @param obj (r) handle
* @param delvol_fn (r) callback called for deleted volumes
*/
-int load_volumes(AFPObj *obj, void (*delvol_fn)(struct vol *))
+int load_volumes(AFPObj *obj, void (*delvol_fn)(const AFPObj *obj, struct vol *))
{
EC_INIT;
int fd = -1;
if (vol->v_deleted) {
LOG(log_debug, logtype_afpd, "load_volumes: deleted: %s", vol->v_localname);
if (delvol_fn)
- delvol_fn(vol);
+ delvol_fn(obj, vol);
vol = Volumes;
}
}
options->flags &= ~OPTION_SERVERNOTIF;
if (!iniparser_getboolean(config, INISEC_GLOBAL, "use sendfile", 1))
options->flags |= OPTION_NOSENDFILE;
+ if (iniparser_getboolean(config, INISEC_GLOBAL, "solaris share reservations", 1))
+ options->flags |= OPTION_SHARE_RESERV;
if (!iniparser_getboolean(config, INISEC_GLOBAL, "save password", 1))
options->passwdbits |= PASSWD_NOSAVE;
if (iniparser_getboolean(config, INISEC_GLOBAL, "set password", 0))