]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/file.c
"veto files" patch (Edmund Lam)
[netatalk.git] / etc / afpd / file.c
index 898f89e053432d88e95afb18436b9927ff0e6257..a2afbab4c90fa0448d0ff60138b053e6501bbba0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: file.c,v 1.22 2001-06-20 18:33:04 rufustfirefly Exp $
+ * $Id: file.c,v 1.28 2001-09-04 13:52:45 rufustfirefly Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -33,8 +33,9 @@
 #include <atalk/adouble.h>
 #include <atalk/afp.h>
 #include <atalk/util.h>
+#ifdef CNID_DB
 #include <atalk/cnid.h>
-
+#endif /* CNID_DB */
 #include "directory.h"
 #include "desktop.h"
 #include "volume.h"
@@ -49,6 +50,7 @@
 #endif /* DID_MTAB */
 
 #ifdef FORCE_UIDGID
+#warning UIDGID
 #include "uid.h"
 #endif /* FORCE_UIDGID */
 
@@ -58,7 +60,7 @@
  * files:
  * ioFlFndrInfo  16      ->       type    4  type field
  *                             creator    4  creator field
- *                               flags    2  finder flags: 
+ *                               flags    2  finder flags:
  *                                          alias, bundle, etc.
  *                            location    4  location in window
  *                              folder    2  window that contains file
@@ -78,14 +80,10 @@ const u_char ufinderi[] = {
     0, 0, 0, 0, 0, 0, 0, 0
 };
 
-int getfilparams(vol, bitmap, path, dir, st, buf, buflen )
-    struct vol  *vol;
-    u_int16_t  bitmap;
-    char       *path;
-    struct dir *dir;
-    struct stat        *st;
-    char       *buf;
-    int                *buflen;
+int getfilparams(struct vol *vol,
+                u_int16_t bitmap,
+                char *path, struct dir *dir, struct stat *st,
+                char *buf, int *buflen )
 {
 #ifndef USE_LASTDID
     struct stat                hst, lst, *lstp;
@@ -96,7 +94,8 @@ int getfilparams(vol, bitmap, path, dir, st, buf, buflen )
     struct ofork        *of;
     struct extmap      *em;
     char               *data, *nameoff = NULL, *upath;
-    int                        bit = 0, isad = 1, aint;
+    int                        bit = 0, isad = 1;
+    u_int32_t          aint;
     u_int16_t          ashort;
     u_char              achar, fdType[4];
 
@@ -115,7 +114,7 @@ int getfilparams(vol, bitmap, path, dir, st, buf, buflen )
     if ( ad_open( upath, ADFLAGS_HF, O_RDONLY, 0, adp) < 0 ) {
        isad = 0;
     } else if ( fstat( ad_hfileno( adp ), &hst ) < 0 ) {
-           syslog( LOG_ERR, "getfilparams fstat: %m" );
+           syslog( LOG_ERR, "getfilparams fstat: %s", strerror(errno) );
     }
 
     data = buf;
@@ -138,8 +137,8 @@ int getfilparams(vol, bitmap, path, dir, st, buf, buflen )
            break;
 
        case FILPBIT_PDID :
-           memcpy(data, &dir->d_did, sizeof( int ));
-           data += sizeof( int );
+           memcpy(data, &dir->d_did, sizeof( u_int32_t ));
+           data += sizeof( u_int32_t );
            break;
 
        case FILPBIT_CDATE :
@@ -200,16 +199,19 @@ int getfilparams(vol, bitmap, path, dir, st, buf, buflen )
            break;
 
        case FILPBIT_FNUM :
+               aint = 0;
 #if AD_VERSION > AD_VERSION1
-         /* use the CNID database if we're using AD v2 */
-           if (isad)
-             memcpy(&aint, ad_entry(adp, ADEID_DID), sizeof(aint));
-           else
-             aint = 0;
-
-           if (!(aint = cnid_add(vol->v_db, st, dir->d_did, upath, 
-                                 strlen(upath), aint))) {
+        /* look in AD v2 header */
+        if (isad)
+                       memcpy(&aint, ad_entry(adp, ADEID_DID), sizeof(aint));
 #endif /* AD_VERSION > AD_VERSION1 */
+
+#ifdef CNID_DB
+        aint = cnid_add(vol->v_db, st, dir->d_did, upath,
+                                                       strlen(upath), aint);
+#endif /* CNID_DB */
+
+               if (aint == 0) {
            /*
             * What a fucking mess.  First thing:  DID and FNUMs are
             * in the same space for purposes of enumerate (and several
@@ -226,7 +228,7 @@ int getfilparams(vol, bitmap, path, dir, st, buf, buflen )
             * new algorithm:
             * due to complaints over did's being non-persistent,
             * here's the current hack to provide semi-persistent
-            * did's: 
+            * did's:
             *      1) we reserve the first bit for file ids.
             *      2) the next 7 bits are for the device.
             *      3) the remaining 24 bits are for the inode.
@@ -246,11 +248,9 @@ int getfilparams(vol, bitmap, path, dir, st, buf, buflen )
              aint = htonl(CNID(lstp, 1));
 #endif /* DID_MTAB */
 #endif /* USE_LASTDID */
+       }
 
-#if AD_VERSION > AD_VERSION1
-           }
-#endif /* AD_VERSION > AD_VERSION1 */
-           memcpy(data, &aint, sizeof( aint ));
+               memcpy(data, &aint, sizeof( aint ));
            data += sizeof( aint );
            break;
 
@@ -309,7 +309,7 @@ int getfilparams(vol, bitmap, path, dir, st, buf, buflen )
              achar = '\x00';
              ashort = 0x0000;
            }
-           
+
            *data++ = achar;
            *data++ = 0;
            memcpy(data, &ashort, sizeof( ashort ));
@@ -406,6 +406,10 @@ int afp_createfile(obj, ibuf, ibuflen, rbuf, rbuflen )
     if (!validupath(vol, upath))
       return AFPERR_EXIST;
 
+    /* check for vetoed filenames */
+    if (veto_file(vol->v_veto, upath))
+        return AFPERR_EXIST;
+
     if ((of = of_findname(vol, curdir, path))) {
       adp = of->of_ad;
     } else {
@@ -461,7 +465,7 @@ int afp_createfile(obj, ibuf, ibuflen, rbuf, rbuflen )
     }
 
     ad_setentrylen( adp, ADEID_NAME, strlen( path ));
-    memcpy(ad_entry( adp, ADEID_NAME ), path, 
+    memcpy(ad_entry( adp, ADEID_NAME ), path,
           ad_getentrylen( adp, ADEID_NAME ));
     ad_flush( adp, ADFLAGS_DF|ADFLAGS_HF );
     ad_close( adp, ADFLAGS_DF|ADFLAGS_HF );
@@ -545,10 +549,8 @@ int afp_setfilparams(obj, ibuf, ibuflen, rbuf, rbuflen )
 }
 
 
-int setfilparams(vol, path, bitmap, buf )
-    struct vol  *vol;
-    char       *path, *buf;
-    u_int16_t  bitmap;
+int setfilparams(struct vol *vol,
+                char *path, u_int16_t bitmap, char *buf )
 {
     struct adouble     ad, *adp;
     struct ofork        *of;
@@ -641,7 +643,7 @@ int setfilparams(vol, path, bitmap, buf )
 
        case FILPBIT_FINFO :
            if ((memcmp( ad_entry( adp, ADEID_FINDERI ), ufinderi, 8 ) == 0)
-               && (em = getextmap( path )) && 
+               && (em = getextmap( path )) &&
                (memcmp(buf, em->em_type, sizeof( em->em_type )) == 0) &&
                (memcmp(buf + 4, em->em_creator,
                        sizeof( em->em_creator )) == 0)) {
@@ -1024,7 +1026,7 @@ int copyfile(src, dst, newname, noadouble )
 #endif /* SENDFILE_FLAVOR_LINUX */
        while (1) {
          if ((cc = read(sfd, filebuf, sizeof(filebuf))) < 0) {
-           if (errno == EINTR) 
+           if (errno == EINTR)
              continue;
            err = AFPERR_PARAM;
            break;
@@ -1109,7 +1111,7 @@ copydata_done:
       unlink(dst);
       return err;
     }
-    
+
     if (newname) {
       memset(&ad, 0, sizeof(ad));
       if ( ad_open( dst, noadouble | ADFLAGS_HF, O_RDWR|O_CREAT,
@@ -1263,7 +1265,7 @@ delete_unlock:
 }
 
 
-#if AD_VERSION > AD_VERSION1
+#ifdef CNID_DB
 /* return a file id */
 int afp_createid(obj, ibuf, ibuflen, rbuf, rbuflen )
     AFPObj      *obj;
@@ -1282,7 +1284,7 @@ int afp_createid(obj, ibuf, ibuflen, rbuf, rbuflen )
 #ifdef DEBUG
     syslog(LOG_INFO, "begin afp_createid:");
 #endif /* DEBUG */
-    
+
     *rbuflen = 0;
     ibuf += 2;
 
@@ -1330,13 +1332,13 @@ int afp_createid(obj, ibuf, ibuflen, rbuf, rbuflen )
       return AFPERR_EXISTID;
     }
 
+#if AD_VERSION > AD_VERSION1
     memset(&ad, 0, sizeof(ad));
-    if (ad_open( upath, ADFLAGS_HF, O_RDONLY, 0, &ad ) < 0)
-      id = 0;
-    else {
+    if (ad_open( upath, ADFLAGS_HF, O_RDONLY, 0, &ad ) >= 0) {
       memcpy(&id, ad_entry(&ad, ADEID_DID), sizeof(id));
       ad_close(&ad, ADFLAGS_HF);
     }
+#endif /* AD_VERSION > AD_VERSION1 */
 
     if (id = cnid_add(vol->v_db, &st, did, upath, len, id)) {
       memcpy(rbuf, &id, sizeof(id));
@@ -1379,7 +1381,7 @@ int afp_resolveid(obj, ibuf, ibuflen, rbuf, rbuflen )
 #ifdef DEBUG
     syslog(LOG_INFO, "begin afp_resolveid:");
 #endif /* DEBUG */
-    
+
     *rbuflen = 0;
     ibuf += 2;
 
@@ -1430,7 +1432,7 @@ int afp_resolveid(obj, ibuf, ibuflen, rbuf, rbuflen )
 #ifdef DEBUG
     syslog(LOG_INFO, "end afp_resolveid:");
 #endif /* DEBUG */
-    
+
     return AFP_OK;
 }
 
@@ -1512,7 +1514,7 @@ int afp_deleteid(obj, ibuf, ibuflen, rbuf, rbuflen )
 
     return err;
 }
-#endif /* AD_VERSION > AD_VERSION1 */
+#endif /* CNID_DB */
 
 #define APPLETEMP ".AppleTempXXXXXX"
 
@@ -1527,10 +1529,10 @@ int afp_exchangefiles(obj, ibuf, ibuflen, rbuf, rbuflen )
     char               *spath, temp[17], *path, *p;
     char                *supath, *upath;
     int                 err;
-#if AD_VERSION > AD_VERSION1
+#ifdef CNID_DB
     int                 slen, dlen;
-#endif /* AD_VERSION > AD_VERSION1 */
-    cnid_t             sid, did;
+#endif /* CNID_DB */
+    u_int32_t          sid, did;
     u_int16_t          vid;
 
 #ifdef DEBUG
@@ -1592,10 +1594,10 @@ int afp_exchangefiles(obj, ibuf, ibuflen, rbuf, rbuflen )
 
     /* look for the source cnid. if it doesn't exist, don't worry about
      * it. */
-#if AD_VERSION > AD_VERSION1
-    sid = cnid_lookup(vol->v_db, &srcst, sdir->d_did, supath, 
+#ifdef CNID_DB
+    sid = cnid_lookup(vol->v_db, &srcst, sdir->d_did, supath,
                      slen = strlen(supath));
-#endif /* AD_VERSION > AD_VERSION1 */
+#endif /* CNID_DB */
 
     if (( dir = dirsearch( vol, did )) == NULL ) {
        return( AFPERR_PARAM );
@@ -1627,13 +1629,13 @@ int afp_exchangefiles(obj, ibuf, ibuflen, rbuf, rbuflen )
       }
     }
 
-#if AD_VERSION > AD_VERSION1
+#ifdef CNID_DB
     /* look for destination id. */
-    did = cnid_lookup(vol->v_db, &destst, curdir->d_did, upath, 
+    did = cnid_lookup(vol->v_db, &destst, curdir->d_did, upath,
                      dlen = strlen(upath));
-#endif /* AD_VERSION > AD_VERSION1 */
+#endif /* CNID_DB */
 
-    /* construct a temp name. 
+    /* construct a temp name.
      * NOTE: the temp file will be in the dest file's directory. it
      * will also be inaccessible from AFP. */
     memcpy(temp, APPLETEMP, sizeof(APPLETEMP));
@@ -1646,7 +1648,7 @@ int afp_exchangefiles(obj, ibuf, ibuflen, rbuf, rbuflen )
     of_rename(vol, sdir, spath, curdir, temp);
 
     /* rename destination to source */
-    if ((err = renamefile(path, p, spath, vol_noadouble(vol))) < 0) 
+    if ((err = renamefile(path, p, spath, vol_noadouble(vol))) < 0)
       goto err_src_to_tmp;
     of_rename(vol, curdir, path, sdir, spath);
 
@@ -1655,9 +1657,9 @@ int afp_exchangefiles(obj, ibuf, ibuflen, rbuf, rbuflen )
       goto err_dest_to_src;
     of_rename(vol, curdir, temp, curdir, path);
     
-#if AD_VERSION > AD_VERSION1
+#ifdef CNID_DB
     /* id's need switching. src -> dest and dest -> src. */
-    if (sid && (cnid_update(vol->v_db, sid, &destst, curdir->d_did, 
+    if (sid && (cnid_update(vol->v_db, sid, &destst, curdir->d_did,
                            upath, dlen) < 0)) {
       switch (errno) {
       case EPERM:
@@ -1683,7 +1685,7 @@ int afp_exchangefiles(obj, ibuf, ibuflen, rbuf, rbuflen )
        cnid_update(vol->v_db, sid, &srcst, sdir->d_did, supath, slen);
       goto err_temp_to_dest;
     }
-#endif /* AD_VERSION > AD_VERSION1 */
+#endif /* CNID_DB */
 
 #ifdef DEBUG
     syslog(LOG_INFO, "ending afp_exchangefiles:");
@@ -1692,7 +1694,7 @@ int afp_exchangefiles(obj, ibuf, ibuflen, rbuf, rbuflen )
     return AFP_OK;
 
 
-    /* all this stuff is so that we can unwind a failed operation 
+    /* all this stuff is so that we can unwind a failed operation
      * properly. */
 err_temp_to_dest:
     /* rename dest to temp */