]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/fork.c
Merge master
[netatalk.git] / etc / afpd / fork.c
index 2887f93e332767983bd43a5e2f92cb9e9c62d325..8092fd398d8b423723f785402748258ec98b2f3b 100644 (file)
@@ -208,9 +208,7 @@ static int fork_setmode(struct adouble *adp, int eid, int access, int ofrefnum)
                 return ret;
         }
     }
-    if ( access == (OPENACC_WR | OPENACC_RD | OPENACC_DWR | OPENACC_DRD)) {
-        return ad_excl_lock(adp, eid);
-    }
+
     return 0;
 }
 
@@ -267,10 +265,8 @@ int afp_openfork(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, si
         return  AFPERR_BADTYPE;
     }
 
-    LOG(log_debug, logtype_afpd,
-        "afp_openfork(\"%s\", %s)",
-        abspath(s_path->u_name),
-        (fork & OPENFORK_RSCS) ? "OPENFORK_RSCS" : "OPENFORK_DATA");
+    LOG(log_debug, logtype_afpd, "afp_openfork(\"%s\", %s)",
+        fullpathname(s_path->u_name), (fork & OPENFORK_RSCS) ? "RSRC" : "DATA");
 
     /* stat() data fork st is set because it's not a dir */
     switch ( s_path->st_errno ) {
@@ -325,7 +321,8 @@ int afp_openfork(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, si
     ret = AFPERR_NOOBJ;
     if (access & OPENACC_WR) {
         /* try opening in read-write mode */
-        if (ad_open(ofork->of_ad, upath, adflags, O_RDWR, O_RDWR) < 0) {
+        if (ad_open(ofork->of_ad, upath,
+                    adflags | ADFLAGS_RDWR | ADFLAGS_SETSHRMD) < 0) {
             switch ( errno ) {
             case EROFS:
                 ret = AFPERR_VLOCK;
@@ -335,14 +332,16 @@ int afp_openfork(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, si
             case ENOENT:
                 if (fork == OPENFORK_DATA) {
                     /* try to open only the data fork */
-                    if (ad_open(ofork->of_ad, upath, ADFLAGS_DF, O_RDWR) < 0) {
+                    if (ad_open(ofork->of_ad, upath,
+                                ADFLAGS_DF | ADFLAGS_RDWR | ADFLAGS_SETSHRMD) < 0) {
                         goto openfork_err;
                     }
                     adflags = ADFLAGS_DF;
                 } else {
                     /* here's the deal. we only try to create the resource
                      * fork if the user wants to open it for write acess. */
-                    if (ad_open(ofork->of_ad, upath, adflags, O_RDWR | O_CREAT, 0666, O_RDWR | O_CREAT, 0666) < 0)
+                    if (ad_open(ofork->of_ad, upath,
+                                adflags | ADFLAGS_RDWR | ADFLAGS_SETSHRMD | ADFLAGS_CREATE, 0666) < 0)
                         goto openfork_err;
                     ofork->of_flags |= AFPFORK_OPEN;
                 }
@@ -370,17 +369,18 @@ int afp_openfork(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, si
     } else {
         /* try opening in read-only mode */
         ret = AFPERR_NOOBJ;
-        if (ad_open(ofork->of_ad, upath, adflags, O_RDONLY, O_RDONLY) < 0) {
+        /* we need w access for setting deny mode fcntl excl lock */
+        if (ad_open(ofork->of_ad, upath, adflags | ADFLAGS_RDONLY | ADFLAGS_SETSHRMD) < 0) {
             switch ( errno ) {
             case EROFS:
                 ret = AFPERR_VLOCK;
+                goto openfork_err;
             case EACCES:
                 goto openfork_err;
-                break;
             case ENOENT:
                 /* see if client asked for a read only data fork */
                 if (fork == OPENFORK_DATA) {
-                    if (ad_open(ofork->of_ad, upath, ADFLAGS_DF, O_RDONLY) < 0) {
+                    if (ad_open(ofork->of_ad, upath, ADFLAGS_DF | ADFLAGS_RDONLY | ADFLAGS_SETSHRMD) < 0) {
                         goto openfork_err;
                     }
                     adflags = ADFLAGS_DF;
@@ -405,7 +405,7 @@ int afp_openfork(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, si
                 break;
             default:
                 LOG(log_error, logtype_afpd, "afp_openfork(\"%s\"): %s",
-                    abspath(s_path->m_name), strerror(errno) );
+                    fullpathname(s_path->m_name), strerror(errno) );
                 goto openfork_err;
                 break;
             }
@@ -451,7 +451,9 @@ int afp_openfork(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, si
      */
 
     /* don't try to lock non-existent rforks. */
-    if ((eid == ADEID_DFORK) || (ad_meta_fileno(ofork->of_ad) != -1)) { /* META */
+    if ((eid == ADEID_DFORK)
+        || (ad_meta_fileno(ofork->of_ad) != -1)
+        || (vol->v_adouble & AD_VERSION_EA)) { /* META */
 
         ret = fork_setmode(ofork->of_ad, eid, access, ofrefnum);
         /* can we access the fork? */
@@ -834,9 +836,8 @@ static int read_fork(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, si
     reqcount = get_off_t(&ibuf, is64);
 
     LOG(log_debug, logtype_afpd,
-         "afp_read(\"%s\", off: %" PRIu64 ", size: %" PRIu64 ", fork: %s)",
-         cfrombstr(ofork->of_ad->ad_fullpath), offset, reqcount,
-         (ofork->of_flags & AFPFORK_DATA) ? "d" : "r");
+        "afp_read(off: %" PRIu64 ", size: %" PRIu64 ", fork: %s)", offset, reqcount,
+        (ofork->of_flags & AFPFORK_DATA) ? "d" : "r");
 
     if (is64) {
         nlmask = nlchar = 0;
@@ -879,14 +880,10 @@ static int read_fork(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, si
         goto afp_read_err;
     }
 
-<<<<<<< HEAD
-#define min(a,b)    ((a)<(b)?(a):(b))
-    *rbuflen = min( reqcount, *rbuflen );
-=======
     *rbuflen = MIN(reqcount, *rbuflen);
     LOG(log_debug, logtype_afpd, "afp_read(name: \"%s\", offset: %jd, reqcount: %jd): reading %jd bytes from file",
         of_name(ofork), (intmax_t)offset, (intmax_t)reqcount, (intmax_t)*rbuflen);
->>>>>>> netafp/master
+
     err = read_file(ofork, eid, offset, nlmask, nlchar, rbuf, rbuflen, xlate);
     if (err < 0)
         goto afp_read_done;
@@ -1017,9 +1014,7 @@ int afp_flushfork(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf _U
         return( AFPERR_PARAM );
     }
 
-    LOG(log_debug, logtype_afpd,
-        "afp_flushfork(\"%s\", fork: %s)",
-        cfrombstr(ofork->of_ad->ad_fullpath),
+    LOG(log_debug, logtype_afpd, "afp_flushfork(fork: %s)",
         (ofork->of_flags & AFPFORK_DATA) ? "d" : "r");
 
     if ( flushfork( ofork ) < 0 ) {
@@ -1051,9 +1046,7 @@ int afp_syncfork(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf _U_
         return( AFPERR_PARAM );
     }
 
-    LOG(log_debug, logtype_afpd,
-        "afp_syncfork(\"%s\", fork: %s)",
-        cfrombstr(ofork->of_ad->ad_fullpath),
+    LOG(log_debug, logtype_afpd, "afp_syncfork(fork: %s)",
         (ofork->of_flags & AFPFORK_DATA) ? "d" : "r");
 
     if ( flushfork( ofork ) < 0 ) {
@@ -1120,9 +1113,7 @@ int afp_closefork(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf _U
         return( AFPERR_PARAM );
     }
 
-    LOG(log_debug, logtype_afpd,
-        "afp_closefork(\"%s\", fork: %s)",
-        cfrombstr(ofork->of_ad->ad_fullpath),
+    LOG(log_debug, logtype_afpd, "afp_closefork(fork: %s)",
         (ofork->of_flags & AFPFORK_DATA) ? "d" : "r");
 
     if ( of_closefork( ofork ) < 0 ) {
@@ -1178,17 +1169,10 @@ static ssize_t write_file(struct ofork *ofork, int eid,
  * in reqcount et al. */
 static int write_fork(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbuflen, int is64)
 {
-<<<<<<< HEAD
     struct ofork    *ofork;
-    off_t               offset, saveoff, reqcount;
+    off_t               offset, saveoff, reqcount, oldsize, newsize;
     int             endflag, eid, xlate = 0, err = AFP_OK;
     uint16_t       ofrefnum;
-=======
-    struct ofork       *ofork;
-    off_t           offset, saveoff, reqcount, oldsize, newsize;
-    int                        endflag, eid, xlate = 0, err = AFP_OK;
-    u_int16_t          ofrefnum;
->>>>>>> netafp/master
     ssize_t             cc;
 
     /* figure out parameters */
@@ -1207,10 +1191,8 @@ static int write_fork(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, s
         goto afp_write_err;
     }
 
-    LOG(log_debug, logtype_afpd,
-        "afp_write(\"%s\", off: %" PRIu64 ", size: %" PRIu64 ", fork: %s)",
-        cfrombstr(ofork->of_ad->ad_fullpath), offset, reqcount,
-        (ofork->of_flags & AFPFORK_DATA) ? "d" : "r");
+    LOG(log_debug, logtype_afpd, "afp_write(off: %" PRIu64 ", size: %" PRIu64 ", fork: %s)",
+        offset, reqcount, (ofork->of_flags & AFPFORK_DATA) ? "d" : "r");
 
     if ((ofork->of_flags & AFPFORK_ACCWR) == 0) {
         err = AFPERR_ACCESS;