From 296eb8dfd48fb30bbc4b2371c3e1dabefe9d833d Mon Sep 17 00:00:00 2001 From: franklahm Date: Tue, 30 Mar 2010 12:55:26 +0000 Subject: [PATCH] Allow opening symlinks r/w, but don't actually allow writing. Fixes test426 --- etc/afpd/afp_dsi.c | 9 ++++++++- etc/afpd/fork.c | 4 +++- include/atalk/adouble.h | 4 ++-- libatalk/adouble/ad_flush.c | 18 +++++++++--------- libatalk/adouble/ad_lock.c | 6 +++--- libatalk/adouble/ad_open.c | 16 ++++++---------- libatalk/adouble/ad_write.c | 8 +++++++- 7 files changed, 38 insertions(+), 27 deletions(-) diff --git a/etc/afpd/afp_dsi.c b/etc/afpd/afp_dsi.c index 7edb2e98..a3d40ded 100644 --- a/etc/afpd/afp_dsi.c +++ b/etc/afpd/afp_dsi.c @@ -1,5 +1,5 @@ /* - * $Id: afp_dsi.c,v 1.52 2010-03-08 19:49:59 franklahm Exp $ + * $Id: afp_dsi.c,v 1.53 2010-03-30 12:55:26 franklahm Exp $ * * Copyright (c) 1999 Adrian Sun (asun@zoology.washington.edu) * Copyright (c) 1990,1993 Regents of The University of Michigan. @@ -471,9 +471,16 @@ void afp_over_dsi(AFPObj *obj) if ( afp_switch[ function ] != NULL ) { dsi->datalen = DSI_DATASIZ; child.flags |= CHILD_RUNNING; + + LOG(log_debug, logtype_afpd, "<== Start AFP command: %s", AfpNum2name(function)); + err = (*afp_switch[function])(obj, (char *)&dsi->commands, dsi->cmdlen, (char *)&dsi->data, &dsi->datalen); + + LOG(log_debug, logtype_afpd, "==> Finished AFP command: %s -> %s", + AfpNum2name(function), AfpErr2name(err)); + child.flags &= ~CHILD_RUNNING; #ifdef FORCE_UIDGID /* bring everything back to old euid, egid */ diff --git a/etc/afpd/fork.c b/etc/afpd/fork.c index f1d2aa9d..b9d03507 100644 --- a/etc/afpd/fork.c +++ b/etc/afpd/fork.c @@ -1,5 +1,5 @@ /* - * $Id: fork.c,v 1.72 2010-02-26 12:31:02 didg Exp $ + * $Id: fork.c,v 1.73 2010-03-30 12:55:26 franklahm Exp $ * * Copyright (c) 1990,1993 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -1163,6 +1163,8 @@ static ssize_t write_file(struct ofork *ofork, int eid, case EFBIG : case ENOSPC : return( AFPERR_DFULL ); + case EACCES: + return AFPERR_ACCESS; default : LOG(log_error, logtype_afpd, "afp_write(%s): ad_write: %s", of_name(ofork), strerror(errno) ); return( AFPERR_PARAM ); diff --git a/include/atalk/adouble.h b/include/atalk/adouble.h index aaf21227..b47464ef 100644 --- a/include/atalk/adouble.h +++ b/include/atalk/adouble.h @@ -1,5 +1,5 @@ /* - * $Id: adouble.h,v 1.54 2010-03-12 15:16:49 franklahm Exp $ + * $Id: adouble.h,v 1.55 2010-03-30 12:55:26 franklahm Exp $ * Copyright (c) 1990,1991 Regents of The University of Michigan. * All Rights Reserved. * @@ -243,7 +243,7 @@ typedef struct adf_lock_t { } adf_lock_t; struct ad_fd { - int adf_fd; + int adf_fd; /* -1: invalid, -2: symlink */ #ifndef HAVE_PREAD off_t adf_off; diff --git a/libatalk/adouble/ad_flush.c b/libatalk/adouble/ad_flush.c index 3569e869..5d99227a 100644 --- a/libatalk/adouble/ad_flush.c +++ b/libatalk/adouble/ad_flush.c @@ -1,5 +1,5 @@ /* - * $Id: ad_flush.c,v 1.13 2010-02-10 14:05:37 franklahm Exp $ + * $Id: ad_flush.c,v 1.14 2010-03-30 12:55:26 franklahm Exp $ * * Copyright (c) 1990,1991 Regents of The University of Michigan. * All Rights Reserved. @@ -198,15 +198,15 @@ int ad_close( struct adouble *ad, int adflags) { int err = 0; - if (( adflags & ADFLAGS_DF ) && ad_data_fileno(ad) != -1 && - !(--ad->ad_data_fork.adf_refcount)) { - if (ad->ad_data_fork.adf_syml!=0){ + if ((adflags & ADFLAGS_DF) + && ad_data_fileno(ad) >= 0 + && --ad->ad_data_fork.adf_refcount == 0) { + if (ad->ad_data_fork.adf_syml !=0) { free(ad->ad_data_fork.adf_syml); - ad->ad_data_fork.adf_syml=0; - }else{ - if ( close( ad_data_fileno(ad) ) < 0 ) { - err = -1; - } + ad->ad_data_fork.adf_syml = 0; + } else { + if ( close( ad_data_fileno(ad) ) < 0 ) + err = -1; } ad_data_fileno(ad) = -1; adf_lock_free(&ad->ad_data_fork); diff --git a/libatalk/adouble/ad_lock.c b/libatalk/adouble/ad_lock.c index fce2c2d0..d5b58f8c 100644 --- a/libatalk/adouble/ad_lock.c +++ b/libatalk/adouble/ad_lock.c @@ -1,5 +1,5 @@ /* - * $Id: ad_lock.c,v 1.19 2010-02-26 12:57:50 didg Exp $ + * $Id: ad_lock.c,v 1.20 2010-03-30 12:55:26 franklahm Exp $ * * Copyright (c) 1998,1999 Adrian Sun (asun@zoology.washington.edu) * All Rights Reserved. See COPYRIGHT for more information. @@ -42,8 +42,8 @@ /* ----------------------- */ static int set_lock(int fd, int cmd, struct flock *lock) { - if (!fd) { - /* We assign fd = 0 for symlinks -> do nothing */ + if (fd == -2) { + /* We assign fd = -2 for symlinks -> do nothing */ if (cmd == F_GETLK) lock->l_type = F_UNLCK; return 0; diff --git a/libatalk/adouble/ad_open.c b/libatalk/adouble/ad_open.c index b4e7c3a5..bc3bc3b0 100644 --- a/libatalk/adouble/ad_open.c +++ b/libatalk/adouble/ad_open.c @@ -1,5 +1,5 @@ /* - * $Id: ad_open.c,v 1.72 2010-03-12 15:16:49 franklahm Exp $ + * $Id: ad_open.c,v 1.73 2010-03-30 12:55:26 franklahm Exp $ * * Copyright (c) 1999 Adrian Sun (asun@u.washington.edu) * Copyright (c) 1990,1991 Regents of The University of Michigan. @@ -1287,31 +1287,27 @@ int ad_open( const char *path, int adflags, int oflags, int mode, struct adouble ad->ad_data_fork.adf_fd =open( path, hoflags | O_NOFOLLOW, admode ); - if (ad->ad_data_fork.adf_fd < 0 ) { + if (ad->ad_data_fork.adf_fd == -1) { if ((errno == EACCES || errno == EROFS) && !(oflags & O_RDWR)) { hoflags = oflags; ad->ad_data_fork.adf_fd = open( path, hoflags | O_NOFOLLOW, admode ); } - if (ad->ad_data_fork.adf_fd < 0 && errno == ELOOP) { + if (ad->ad_data_fork.adf_fd == -1 && errno == ELOOP) { int lsz; - if (oflags != O_RDONLY) - return -1; - ad->ad_data_fork.adf_syml = malloc(PATH_MAX+1); lsz = readlink(path, ad->ad_data_fork.adf_syml, PATH_MAX); if (lsz <= 0) { free(ad->ad_data_fork.adf_syml); return -1; } - ad->ad_data_fork.adf_syml[lsz]=0; + ad->ad_data_fork.adf_syml[lsz] = 0; ad->ad_data_fork.adf_syml = realloc(ad->ad_data_fork.adf_syml,lsz+1); - // XX - ad->ad_data_fork.adf_fd = 0; + ad->ad_data_fork.adf_fd = -2; /* -2 means its a symlink */ } } - if ( ad->ad_data_fork.adf_fd < 0) + if ( ad->ad_data_fork.adf_fd == -1 ) return -1; AD_SET(ad->ad_data_fork.adf_off); diff --git a/libatalk/adouble/ad_write.c b/libatalk/adouble/ad_write.c index db542cb1..35ebc222 100644 --- a/libatalk/adouble/ad_write.c +++ b/libatalk/adouble/ad_write.c @@ -1,5 +1,5 @@ /* - * $Id: ad_write.c,v 1.10 2009-10-13 22:55:37 didg Exp $ + * $Id: ad_write.c,v 1.11 2010-03-30 12:55:26 franklahm Exp $ * * Copyright (c) 1990,1995 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -51,6 +51,12 @@ ssize_t ad_write(struct adouble *ad, const u_int32_t eid, off_t off, const int e { struct stat st; ssize_t cc; + + if (ad_data_fileno(ad) == -2) { + /* It's a symlink */ + errno = EACCES; + return -1; + } if ( eid == ADEID_DFORK ) { if ( end ) { -- 2.39.2