]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/filedir.c
better error code for calls on a not existing file
[netatalk.git] / etc / afpd / filedir.c
index 281887c54a3834a5dcc20bfd934958e621c0a68f..d2400262db06a3ce4ea8d83e913b9bfcef1b6036 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: filedir.c,v 1.40 2003-01-24 07:08:43 didg Exp $
+ * $Id: filedir.c,v 1.45 2003-04-20 06:53:40 didg Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -178,7 +178,7 @@ int         ibuflen, *rbuflen;
     ibuf += sizeof( dbitmap );
 
     if (NULL == ( s_path = cname( vol, dir, &ibuf )) ) {
-        return afp_errno;
+        return get_afp_errno(AFPERR_NOOBJ); 
     }
 
     st   = &s_path->st;
@@ -197,7 +197,7 @@ int         ibuflen, *rbuflen;
     buflen = 0;
     if (S_ISDIR(st->st_mode)) {
         if (dbitmap) {
-            dir = dirsearch_byname(curdir, s_path->u_name);
+            dir = s_path->dir;
             if (!dir) 
                 return AFPERR_NOOBJ;
 
@@ -209,8 +209,8 @@ int         ibuflen, *rbuflen;
         /* this is a directory */
         *(rbuf + 2 * sizeof( u_int16_t )) = (char) FILDIRBIT_ISDIR;
     } else {
-        if (fbitmap && ret = getfilparams(vol, fbitmap, s_path, curdir, 
-                                            rbuf + 3 * sizeof( u_int16_t ), &buflen )) != AFP_OK ) {
+        if (fbitmap && AFP_OK != (ret = getfilparams(vol, fbitmap, s_path, curdir, 
+                                            rbuf + 3 * sizeof( u_int16_t ), &buflen )) ) {
             return( ret );
         }
         /* this is a file */
@@ -263,7 +263,7 @@ int         ibuflen, *rbuflen;
     memcpy( &did, ibuf, sizeof( did));
     ibuf += sizeof( did);
 
-    if (( dir = dirlookup( vol, did )) == NULL ) {
+    if (NULL == ( dir = dirlookup( vol, did )) ) {
        return afp_errno;    
     }
 
@@ -271,8 +271,8 @@ int         ibuflen, *rbuflen;
     bitmap = ntohs( bitmap );
     ibuf += sizeof( bitmap );
 
-    if (( path = cname( vol, dir, &ibuf )) == NULL ) {
-       return afp_errno;    
+    if (NULL == ( path = cname( vol, dir, &ibuf ))) {
+        return get_afp_errno(AFPERR_NOOBJ); 
     }
 
     st   = &path->st;
@@ -361,7 +361,10 @@ int         isdir;
     
     if (!isdir) {
 #ifdef CNID_DB
-        p = mtoupath(vol, oldname);
+        p = mtoupath(vol, oldname, utf8_encoding());
+        if (!p) { 
+            return AFPERR_PARAM; /* can't convert */
+        }
         id = cnid_get(vol->v_db, sdir->d_did, p, strlen(p));
 #endif /* CNID_DB */
         p = ctoupath( vol, sdir, oldname );
@@ -400,7 +403,9 @@ int         isdir;
             return(AFPERR_OLOCK);
     }
 
-    upath = mtoupath(vol, newname);
+    if (NULL == (upath = mtoupath(vol, newname, utf8_encoding()))){ 
+        return AFPERR_PARAM;
+    }
     path.u_name = upath;
     st = &path.st;    
     if (0 != (rc = check_name(vol, upath))) {
@@ -484,8 +489,8 @@ int         ibuflen, *rbuflen;
     }
 
     /* source pathname */
-    if (( path = cname( vol, sdir, &ibuf )) == NULL ) {
-       return afp_errno;    
+    if (NULL == ( path = cname( vol, sdir, &ibuf )) ) {
+        return get_afp_errno(AFPERR_NOOBJ); 
     }
 
     sdir = curdir;
@@ -495,12 +500,8 @@ int                ibuflen, *rbuflen;
     if ( *path->m_name != '\0' ) {
         strcpy(oldname, path->m_name); /* an extra copy for of_rename */
         if (isdir) {
-            /* curdir parent dir, need to move sdir back 
-             * FIXME search by unix name or mac name?
-            */
-            sdir = dirsearch_byname(curdir, path->u_name);
-            if (!sdir)
-                return AFPERR_NOOBJ;           
+            /* curdir parent dir, need to move sdir back */
+            sdir = path->dir;
         }
     }
     else {
@@ -572,24 +573,21 @@ int               ibuflen, *rbuflen;
     }
 
     if (NULL == ( s_path = cname( vol, dir, &ibuf )) ) {
-        return afp_errno;
+        return get_afp_errno(AFPERR_NOOBJ); 
     }
 
     upath = s_path->u_name;
     if ( path_isadir( s_path) ) {
        if (*s_path->m_name != '\0') {
-           rc = AFPERR_ACCESS; 
+           rc = AFPERR_ACCESS;
        }
        else {
             rc = deletecurdir( vol, obj->oldtmp, AFPOBJ_TMPSIZ);
         }
     } else if (of_findname(s_path)) {
         rc = AFPERR_BUSY;
-    } else if (AFP_OK == (rc = deletefile( upath, 1))) {
-#ifdef CNID_DB /* get rid of entry */
-        cnid_t id = cnid_get(vol->v_db, curdir->d_did, upath, strlen(upath));
-        cnid_delete(vol->v_db, id);
-#endif /* CNID_DB */
+    } else {
+        rc = deletefile(vol, upath, 1);
     }
     if ( rc == AFP_OK ) {
        curdir->offcnt--;
@@ -612,6 +610,9 @@ char        *u;
     char       *p;
     int                len;
 
+    if (u == NULL)
+        return NULL;
+        
     p = path + sizeof( path ) - 1;
     *p = '\0';
     len = strlen( u );
@@ -646,7 +647,7 @@ const struct vol    *vol;
 struct dir     *dir;
 char   *name;
 {
-    return absupath(vol, dir, mtoupath(vol, name));
+    return absupath(vol, dir, mtoupath(vol, name, utf8_encoding()));
 }
 
 /* ------------------------- */
@@ -688,7 +689,7 @@ int         ibuflen, *rbuflen;
     memcpy( &did, ibuf, sizeof( did ));
     ibuf += sizeof( int );
     if (NULL == ( sdir = dirlookup( vol, did )) ) {
-        return( AFPERR_PARAM );
+        return afp_errno; /* was AFPERR_PARAM */
     }
 
     memcpy( &did, ibuf, sizeof( did ));
@@ -696,7 +697,7 @@ int         ibuflen, *rbuflen;
 
     /* source pathname */
     if (NULL == ( path = cname( vol, sdir, &ibuf )) ) {
-        return afp_errno;
+        return get_afp_errno(AFPERR_NOOBJ); 
     }
 
     sdir = curdir;
@@ -706,9 +707,7 @@ int         ibuflen, *rbuflen;
     isdir = path_isadir(path);
     if ( *path->m_name != '\0' ) {
         if (isdir) {
-            sdir = dirsearch_byname(curdir, path->u_name);
-            if (!sdir)
-                return AFPERR_NOOBJ;           
+            sdir = path->dir;
        }
         strcpy(oldname, path->m_name); /* an extra copy for of_rename */
     } else {
@@ -717,13 +716,13 @@ int               ibuflen, *rbuflen;
 
     /* get the destination directory */
     if (NULL == ( ddir = dirlookup( vol, did )) ) {
-        return( AFPERR_PARAM );
+        return afp_errno; /*  was AFPERR_PARAM */
     }
     if (( path = cname( vol, ddir, &ibuf )) == NULL ) {
         return( AFPERR_NOOBJ );
     }
     if ( *path->m_name != '\0' ) {
-        return (path_isadir(path))?afp_errno:AFPERR_BADTYPE;
+        return path_error(path, AFPERR_NOOBJ);
     }
 
     /* one more place where we know about path type */
@@ -738,8 +737,11 @@ int                ibuflen, *rbuflen;
     rc = moveandrename(vol, sdir, oldname, newname, isdir);
 
     if ( rc == AFP_OK ) {
-        char *upath = mtoupath(vol, newname);
-
+        char *upath = mtoupath(vol, newname, utf8_encoding());
+        
+        if (NULL == upath) {
+            return AFPERR_PARAM;
+        }
         curdir->offcnt++;
         sdir->offcnt--;
 #ifdef DROPKLUDGE