]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/file.c
cnid_t is a unsigned variable, Joe! Thanks to Didier for pointing this out.
[netatalk.git] / etc / afpd / file.c
index de4ee8a15c35b4edfb8f62035f083b1cca9d9633..494bae014d54a3ab6726c6b76b933e11f46110e8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: file.c,v 1.30 2001-12-03 05:03:38 jmarcus Exp $
+ * $Id: file.c,v 1.39 2002-02-02 19:11:33 jmarcus Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -38,7 +38,7 @@ char *strchr (), *strrchr ();
 #include <sys/mman.h>
 #include <errno.h>
 
-#include <sys/syslog.h>
+#include <atalk/logger.h>
 #include <sys/types.h>
 #include <sys/time.h>
 #include <sys/param.h>
@@ -89,11 +89,11 @@ char *strchr (), *strrchr ();
  */
 
 const u_char ufinderi[] = {
-    'T', 'E', 'X', 'T', 'U', 'N', 'I', 'X',
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0
-};
+                              'T', 'E', 'X', 'T', 'U', 'N', 'I', 'X',
+                              0, 0, 0, 0, 0, 0, 0, 0,
+                              0, 0, 0, 0, 0, 0, 0, 0,
+                              0, 0, 0, 0, 0, 0, 0, 0
+                          };
 
 int getfilparams(struct vol *vol,
                  u_int16_t bitmap,
@@ -115,7 +115,7 @@ int getfilparams(struct vol *vol,
     u_char              achar, fdType[4];
 
 #ifdef DEBUG
-    syslog(LOG_INFO, "begin getfilparams:");
+    LOG(log_info, logtype_default, "begin getfilparams:");
 #endif /* DEBUG */
 
     upath = mtoupath(vol, path);
@@ -129,7 +129,7 @@ int getfilparams(struct vol *vol,
     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: %s", strerror(errno) );
+        LOG(log_error, logtype_default, "getfilparams fstat: %s", strerror(errno) );
     }
 
     data = buf;
@@ -224,6 +224,19 @@ int getfilparams(struct vol *vol,
 #ifdef CNID_DB
             aint = cnid_add(vol->v_db, st, dir->d_did, upath,
                             strlen(upath), aint);
+            /* Throw errors if cnid_add fails. */
+            if (aint == CNID_INVALID) {
+                switch (errno) {
+                case CNID_ERR_PARAM:
+                    LOG(log_error, logtype_default, "getfilparams: Incorrect parameters passed to cnid_add");
+                    return(AFPERR_PARAM);
+                case CNID_ERR_PATH:
+                    return(AFPERR_PARAM);
+                case CNID_ERR_DB:
+                case CNID_ERR_MAX:
+                    return(AFPERR_MISC);
+                }
+            }
 #endif /* CNID_DB */
 
             if (aint == 0) {
@@ -357,7 +370,7 @@ int getfilparams(struct vol *vol,
     *buflen = data - buf;
 
 #ifdef DEBUG
-    syslog(LOG_INFO, "end getfilparams:");
+    LOG(log_info, logtype_default, "end getfilparams:");
 #endif /* DEBUG */
 
     return( AFP_OK );
@@ -381,7 +394,7 @@ int         ibuflen, *rbuflen;
 #endif /* FORCE_UIDGID */
 
 #ifdef DEBUG
-    syslog(LOG_INFO, "begin afp_createfile:");
+    LOG(log_info, logtype_default, "begin afp_createfile:");
 #endif /* DEBUG */
 
     *rbuflen = 0;
@@ -409,8 +422,7 @@ int         ibuflen, *rbuflen;
         return( AFPERR_NOOBJ );
     }
 
-    if ((vol->v_flags & AFPVOL_MSWINDOWS) &&
-            strpbrk(path, MSWINDOWS_BADCHARS))
+    if (!wincheck(vol, path))
         return AFPERR_PARAM;
 
     upath = mtoupath(vol, path);
@@ -496,7 +508,7 @@ createfile_done:
     setvoltime(obj, vol );
 
 #ifdef DEBUG
-    syslog(LOG_INFO, "end afp_createfile");
+    LOG(log_info, logtype_default, "end afp_createfile");
 #endif /* DEBUG */
 
 #ifdef FORCE_UIDGID
@@ -519,7 +531,7 @@ int         ibuflen, *rbuflen;
     u_int16_t  vid, bitmap;
 
 #ifdef DEBUG
-    syslog(LOG_INFO, "begin afp_setfilparams:");
+    LOG(log_info, logtype_default, "begin afp_setfilparams:");
 #endif /* DEBUG */
 
     *rbuflen = 0;
@@ -557,7 +569,7 @@ int         ibuflen, *rbuflen;
     }
 
 #ifdef DEBUG
-    syslog(LOG_INFO, "end afp_setfilparams:");
+    LOG(log_info, logtype_default, "end afp_setfilparams:");
 #endif /* DEBUG */
 
     return( rc );
@@ -584,7 +596,7 @@ int setfilparams(struct vol *vol,
 #endif /* FORCE_UIDGID */
 
 #ifdef DEBUG
-    syslog(LOG_INFO, "begin setfilparams:");
+    LOG(log_info, logtype_default, "begin setfilparams:");
 #endif /* DEBUG */
 
     upath = mtoupath(vol, path);
@@ -732,7 +744,7 @@ setfilparam_done:
     }
 
 #ifdef DEBUG
-    syslog(LOG_INFO, "end setfilparams:");
+    LOG(log_info, logtype_default, "end setfilparams:");
 #endif /* DEBUG */
 
     return err;
@@ -762,7 +774,7 @@ const int         noadouble;
     /* existence check moved to afp_moveandrename */
 
 #ifdef DEBUG
-    syslog (LOG_INFO, "begin renamefile:");
+    LOG(log_info, logtype_default, "begin renamefile:");
 #endif /* DEBUG */
 
     if ( rename( src, dst ) < 0 ) {
@@ -833,7 +845,7 @@ rename_retry:
     ad_close( &ad, ADFLAGS_HF );
 
 #ifdef DEBUG
-    syslog (LOG_INFO, "end renamefile:");
+    LOG(log_info, logtype_default, "end renamefile:");
 #endif /* DEBUG */
 
     return( AFP_OK );
@@ -852,7 +864,7 @@ int         ibuflen, *rbuflen;
     u_int16_t  svid, dvid;
 
 #ifdef DEBUG
-    syslog (LOG_INFO, "begin afp_copyfile:");
+    LOG(log_info, logtype_default, "begin afp_copyfile:");
 #endif /* DEBUG */
 
     *rbuflen = 0;
@@ -936,7 +948,7 @@ int         ibuflen, *rbuflen;
 #endif /* DROPKLUDGE */
 
 #ifdef DEBUG
-    syslog (LOG_INFO, "end afp_copyfile:");
+    LOG(log_info, logtype_default, "end afp_copyfile:");
 #endif /* DEBUG */
 
     return( retvalue );
@@ -949,7 +961,7 @@ static __inline__ int copy_all(const int dfd, const void *buf,
     ssize_t cc;
 
 #ifdef DEBUG
-    syslog(LOG_INFO, "begin copy_all:");
+    LOG(log_info, logtype_default, "begin copy_all:");
 #endif /* DEBUG */
 
     while (buflen > 0) {
@@ -971,7 +983,7 @@ static __inline__ int copy_all(const int dfd, const void *buf,
     }
 
 #ifdef DEBUG
-    syslog(LOG_INFO, "end copy_all:");
+    LOG(log_info, logtype_default, "end copy_all:");
 #endif /* DEBUG */
 
     return AFP_OK;
@@ -990,7 +1002,7 @@ const int   noadouble;
     ssize_t             cc;
 
 #ifdef DEBUG
-    syslog(LOG_INFO, "begin copyfile:");
+    LOG(log_info, logtype_default, "begin copyfile:");
 #endif /* DEBUG */
 
     if (newname) {
@@ -1151,7 +1163,7 @@ copydata_done:
     }
 
 #ifdef DEBUG
-    syslog(LOG_INFO, "end copyfile:");
+    LOG(log_info, logtype_default, "end copyfile:");
 #endif /* DEBUG */
 
     return( AFP_OK );
@@ -1167,7 +1179,7 @@ char              *file;
     int                        openmode = O_RDWR;
 
 #ifdef DEBUG
-    syslog(LOG_INFO, "begin deletefile:");
+    LOG(log_info, logtype_default, "begin deletefile:");
 #endif /* DEBUG */
 
     while(1) {
@@ -1273,7 +1285,7 @@ delete_unlock:
     ad_close( &ad, adflags );
 
 #ifdef DEBUG
-    syslog(LOG_INFO, "end deletefile:");
+    LOG(log_info, logtype_default, "end deletefile:");
 #endif /* DEBUG */
 
     return err;
@@ -1297,7 +1309,7 @@ int               ibuflen, *rbuflen;
     u_short            vid;
 
 #ifdef DEBUG
-    syslog(LOG_INFO, "begin afp_createid:");
+    LOG(log_info, logtype_default, "begin afp_createid:");
 #endif /* DEBUG */
 
     *rbuflen = 0;
@@ -1355,14 +1367,14 @@ int             ibuflen, *rbuflen;
     }
 #endif /* AD_VERSION > AD_VERSION1 */
 
-    if (id = cnid_add(vol->v_db, &st, did, upath, len, id)) {
+    if (id = cnid_add(vol->v_db, &st, did, upath, len, id) != CNID_INVALID) {
         memcpy(rbuf, &id, sizeof(id));
         *rbuflen = sizeof(id);
         return AFP_OK;
     }
 
 #ifdef DEBUG
-    syslog(LOG_INFO, "ending afp_createid...:");
+    LOG(log_info, logtype_default, "ending afp_createid...:");
 #endif /* DEBUG */
 
     switch (errno) {
@@ -1374,7 +1386,7 @@ int               ibuflen, *rbuflen;
         return AFPERR_ACCESS;
         break;
     default:
-        syslog(LOG_ERR, "afp_createid: cnid_add: %m");
+        LOG(log_error, logtype_default, "afp_createid: cnid_add: %s", strerror(errno));
         return AFPERR_PARAM;
     }
 }
@@ -1394,7 +1406,7 @@ int               ibuflen, *rbuflen;
     u_int16_t          vid, bitmap;
 
 #ifdef DEBUG
-    syslog(LOG_INFO, "begin afp_resolveid:");
+    LOG(log_info, logtype_default, "begin afp_resolveid:");
 #endif /* DEBUG */
 
     *rbuflen = 0;
@@ -1445,7 +1457,7 @@ int               ibuflen, *rbuflen;
     memcpy(rbuf, ibuf, sizeof(bitmap));
 
 #ifdef DEBUG
-    syslog(LOG_INFO, "end afp_resolveid:");
+    LOG(log_info, logtype_default, "end afp_resolveid:");
 #endif /* DEBUG */
 
     return AFP_OK;
@@ -1465,7 +1477,7 @@ int               ibuflen, *rbuflen;
     u_short            vid;
 
 #ifdef DEBUG
-    syslog(LOG_INFO, "begin afp_deleteid:");
+    LOG(log_info, logtype_default, "begin afp_deleteid:");
 #endif /* DEBUG */
 
     *rbuflen = 0;
@@ -1524,7 +1536,7 @@ int               ibuflen, *rbuflen;
     }
 
 #ifdef DEBUG
-    syslog(LOG_INFO, "end afp_deleteid:");
+    LOG(log_info, logtype_default, "end afp_deleteid:");
 #endif /* DEBUG */
 
     return err;
@@ -1551,7 +1563,7 @@ int               ibuflen, *rbuflen;
     u_int16_t          vid;
 
 #ifdef DEBUG
-    syslog(LOG_INFO, "begin afp_exchangefiles:");
+    LOG(log_info, logtype_default, "begin afp_exchangefiles:");
 #endif /* DEBUG */
 
     *rbuflen = 0;
@@ -1680,6 +1692,7 @@ int               ibuflen, *rbuflen;
         case EPERM:
         case EACCES:
             err = AFPERR_ACCESS;
+            break;
         default:
             err = AFPERR_PARAM;
         }
@@ -1692,6 +1705,7 @@ int               ibuflen, *rbuflen;
         case EPERM:
         case EACCES:
             err = AFPERR_ACCESS;
+            break;
         default:
             err = AFPERR_PARAM;
         }
@@ -1703,7 +1717,7 @@ int               ibuflen, *rbuflen;
 #endif /* CNID_DB */
 
 #ifdef DEBUG
-    syslog(LOG_INFO, "ending afp_exchangefiles:");
+    LOG(log_info, logtype_default, "ending afp_exchangefiles:");
 #endif /* DEBUG */
 
     return AFP_OK;