]> arthur.barton.de Git - netatalk.git/commitdiff
Allow opening symlinks r/w, but don't actually allow writing. Fixes test426
authorfranklahm <franklahm>
Tue, 30 Mar 2010 12:55:26 +0000 (12:55 +0000)
committerfranklahm <franklahm>
Tue, 30 Mar 2010 12:55:26 +0000 (12:55 +0000)
etc/afpd/afp_dsi.c
etc/afpd/fork.c
include/atalk/adouble.h
libatalk/adouble/ad_flush.c
libatalk/adouble/ad_lock.c
libatalk/adouble/ad_open.c
libatalk/adouble/ad_write.c

index 7edb2e98740e650438f0132ba2e05c140940a6de..a3d40ded6ec3d8969d21d9706df1b9b29d0a6c09 100644 (file)
@@ -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 */
index f1d2aa9d5f95ed57c92d484c5ffe992fa2353a6f..b9d03507e6b249e427dab70e8a6b6643388d3092 100644 (file)
@@ -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 );
index aaf21227954e45068f97404d4ede1d41c55ccca5..b47464ef55106142e3443e29b21ee1b7a08c87f7 100644 (file)
@@ -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;
index 3569e8695633e805d16c7aff6efd264f5e3eabe5..5d99227a6fec5b6835319dc2bf81544c08756816 100644 (file)
@@ -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);
index fce2c2d02b77ee2e4ae6c5f07abe84c241417255..d5b58f8c954bd52ea1be7d5e90e4c84ccedab5b3 100644 (file)
@@ -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;
index b4e7c3a58cad0c8d92d547bc635a8ed92ce86db5..bc3bc3b0a039d6b70709bd6e2541b6475da9631f 100644 (file)
@@ -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);
index db542cb126f8bba07904c415e1f99478c5877ca9..35ebc222675f33787ca59ced3e7214ab9624db6c 100644 (file)
@@ -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 ) {