]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/directory.c
don't store in struct volume pointers to charset function table, we only need texten...
[netatalk.git] / etc / afpd / directory.c
index 148ec2179782e386d086aac4b763f909d9c0f6d3..cd64283f43aea797385df38722f6ee1a9d7e8be2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: directory.c,v 1.106 2009-10-13 22:55:36 didg Exp $
+ * $Id: directory.c,v 1.116 2009-10-29 11:35:58 didg Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -31,7 +31,6 @@ char *strchr (), *strrchr ();
 #endif
 #include <stdio.h>
 #include <stdlib.h>
-#include <dirent.h>
 
 #include <grp.h>
 #include <pwd.h>
@@ -46,6 +45,7 @@ char *strchr (), *strrchr ();
 #include <atalk/cnid.h>
 #include <atalk/logger.h>
 #include <atalk/uuid.h>
+#include <atalk/unix.h>
 
 #include "directory.h"
 #include "desktop.h"
@@ -167,7 +167,7 @@ struct dir *dir = NULL;
  * and we are really bad in this case.
  */
 struct dir *
-            dirlookup( const struct vol *vol, u_int32_t did)
+            dirlookup( struct vol *vol, u_int32_t did)
 {
     struct dir   *ret;
     char        *upath;
@@ -622,7 +622,7 @@ caseenumerate(const struct vol *vol, struct path *path, struct dir *dir)
 
 
     /* LOG(log_debug, logtype_afpd, "caseenumerate: for %s", path->u_name); */
-    if ((size_t) -1 == convert_string(vol->v_volcharset, CH_UCS2, path->u_name, strlen(path->u_name), u2_path, sizeof(u2_path)) ) 
+    if ((size_t) -1 == convert_string(vol->v_volcharset, CH_UCS2, path->u_name, -1, u2_path, sizeof(u2_path)) ) 
         LOG(log_debug, logtype_afpd, "caseenumerate: conversion failed for %s", path->u_name);
 
     /*LOG(log_debug, logtype_afpd, "caseenumerate: dir: %s, path: %s", dir->d_u_name, path->u_name); */
@@ -631,7 +631,7 @@ caseenumerate(const struct vol *vol, struct path *path, struct dir *dir)
         if (NULL == check_dirent(vol, de->d_name))
             continue;
 
-        if ((size_t) -1 == convert_string(vol->v_volcharset, CH_UCS2, de->d_name, strlen(de->d_name), u2_dename, sizeof(u2_dename)) )
+        if ((size_t) -1 == convert_string(vol->v_volcharset, CH_UCS2, de->d_name, -1, u2_dename, sizeof(u2_dename)) )
             continue;
 
         if (strcasecmp_w( u2_path, u2_dename) == 0) {
@@ -954,9 +954,9 @@ struct dir *
         LOG(log_error, logtype_afpd, "adddir: malloc: %s", strerror(errno) );
         return NULL;
     }
-    if ((size_t)-1 == convert_string_allocate((utf8_encoding())?CH_UTF8_MAC:vol->v_maccharset, CH_UCS2, path->m_name, strlen(path->m_name), &cdir->d_m_name_ucs2)) {
-       LOG(log_error, logtype_afpd, "Couldn't set UCS2 name for %s", name);
-       cdir->d_m_name_ucs2 = NULL;
+    if ((size_t)-1 == convert_string_allocate((utf8_encoding())?CH_UTF8_MAC:vol->v_maccharset, CH_UCS2, path->m_name, -1, (char **)&cdir->d_m_name_ucs2)) {
+        LOG(log_error, logtype_afpd, "Couldn't set UCS2 name for %s", name);
+        cdir->d_m_name_ucs2 = NULL;
     }
 
     cdir->d_did = id;
@@ -1073,8 +1073,8 @@ const struct dir *k = key;
        0x69232f74U, 0xfead7bb3U, 0xe9089ab6U, 0xf012f6aeU,
     };
 
-    const unsigned char *str = k->d_u_name;
-    hash_val_t acc = 0;
+    const unsigned char *str = (unsigned char *)(k->d_u_name);
+    hash_val_t acc = k->d_parent->d_did;
 
     while (*str) {
        acc ^= randbox[(*str + acc) & 0xf];
@@ -1184,7 +1184,7 @@ static struct path *invalidate (const struct vol *vol, struct dir *dir, struct p
                  
 */
 struct path *
-cname(const struct vol *vol, struct dir *dir, char **cpath)
+cname(struct vol *vol, struct dir *dir, char **cpath)
 {
     struct dir            *cdir, *scdir=NULL;
     static char                   path[ MAXPATHLEN + 1];
@@ -1335,7 +1335,7 @@ cname(const struct vol *vol, struct dir *dir, char **cpath)
             scdir = NULL;
            if ( cdir && (vol->v_flags & AFPVOL_CASEINSEN) &&
                     (size_t)-1 != convert_string_allocate(((ret.m_type == 3)?CH_UTF8_MAC:vol->v_maccharset), 
-                                                          CH_UCS2, path, strlen(path), (char **)&tmpname) )
+                                                          CH_UCS2, path, -1, (char **)&tmpname) )
             {
                 while (cdir) {
                     if (!cdir->d_m_name_ucs2) {
@@ -1530,7 +1530,7 @@ void setdiroffcnt(struct dir *dir, struct stat *st,  u_int32_t count)
  * is our cached offspring count valid?
 */
 
-int diroffcnt(struct dir *dir, struct stat *st)
+static int diroffcnt(struct dir *dir, struct stat *st)
 {
     return st->st_ctime == dir->ctime;
 }
@@ -1558,7 +1558,7 @@ static int invisible_dots(const struct vol *vol, const char *name)
 int getdirparams(const struct vol *vol,
                  u_int16_t bitmap, struct path *s_path,
                  struct dir *dir, 
-                 char *buf, int *buflen )
+                 char *buf, size_t *buflen )
 {
     struct maccess     ma;
     struct adouble     ad;
@@ -1797,7 +1797,7 @@ int path_error(struct path *path, int error)
 }
 
 /* ----------------------------- */
-int afp_setdirparams(AFPObj *obj, char *ibuf, int ibuflen _U_, char *rbuf _U_, int *rbuflen)
+int afp_setdirparams(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen)
 {
     struct vol *vol;
     struct dir *dir;
@@ -2215,7 +2215,7 @@ setdirparam_done:
     return err;
 }
 
-int afp_syncdir(AFPObj *obj _U_, char *ibuf, int ibuflen _U_, char *rbuf _U_, int *rbuflen)
+int afp_syncdir(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen)
 {
 #ifdef HAVE_DIRFD
     DIR                  *dp;
@@ -2305,7 +2305,7 @@ int afp_syncdir(AFPObj *obj _U_, char *ibuf, int ibuflen _U_, char *rbuf _U_, in
     return ( AFP_OK );
 }
 
-int afp_createdir(AFPObj *obj, char *ibuf, int ibuflen _U_, char *rbuf, int *rbuflen)
+int afp_createdir(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbuflen)
 {
     struct adouble     ad;
     struct vol         *vol;
@@ -2430,7 +2430,7 @@ int renamedir(const struct vol *vol, char *src, char *dst,
         }
     }
 
-    vol->vfs->rf_renamedir(vol, src, dst);
+    vol->vfs->vfs_renamedir(vol, src, dst);
 
     len = strlen( newname );
     /* rename() succeeded so we need to update our tree even if we can't open
@@ -2474,7 +2474,7 @@ int renamedir(const struct vol *vol, char *src, char *dst,
        free(dir->d_m_name_ucs2);
 
     dir->d_m_name_ucs2 = NULL;
-    if ((size_t)-1 == convert_string_allocate((utf8_encoding())?CH_UTF8_MAC:vol->v_maccharset, CH_UCS2, dir->d_m_name, strlen(dir->d_m_name), (char**)&dir->d_m_name_ucs2))
+    if ((size_t)-1 == convert_string_allocate((utf8_encoding())?CH_UTF8_MAC:vol->v_maccharset, CH_UCS2, dir->d_m_name, -1, (char**)&dir->d_m_name_ucs2))
         dir->d_m_name_ucs2 = NULL;
 
     if (( parent = dir->d_parent ) == NULL ) {
@@ -2518,7 +2518,7 @@ int deletecurdir(const struct vol *vol)
             return  AFPERR_OLOCK;
         }
     }
-    err = vol->vfs->rf_deletecurdir(vol);
+    err = vol->vfs->vfs_deletecurdir(vol);
     if (err) {
         return err;
     }
@@ -2565,7 +2565,7 @@ delete_done:
     return err;
 }
 
-int afp_mapid(AFPObj *obj, char *ibuf, int ibuflen _U_, char *rbuf, int *rbuflen)
+int afp_mapid(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbuflen)
 {
     struct passwd      *pw;
     struct group       *gr;
@@ -2573,8 +2573,7 @@ int afp_mapid(AFPObj *obj, char *ibuf, int ibuflen _U_, char *rbuf, int *rbuflen
     u_int32_t           id;
     int                        len, sfunc;
     int         utf8 = 0;
-    uuidtype_t          type;
-
+    
     ibuf++;
     sfunc = (unsigned char) *ibuf++;
     *rbuflen = 0;
@@ -2597,7 +2596,7 @@ int afp_mapid(AFPObj *obj, char *ibuf, int ibuflen _U_, char *rbuf, int *rbuflen
                 return( AFPERR_NOITEM );
             }
            len = convert_string_allocate( obj->options.unixcharset, ((!utf8)?obj->options.maccharset:CH_UTF8_MAC),
-                                            pw->pw_name, strlen(pw->pw_name), &name);
+                                            pw->pw_name, -1, &name);
        } else {
            len = 0;
            name = NULL;
@@ -2612,7 +2611,7 @@ int afp_mapid(AFPObj *obj, char *ibuf, int ibuflen _U_, char *rbuf, int *rbuflen
                 return( AFPERR_NOITEM );
             }
            len = convert_string_allocate( obj->options.unixcharset, (!utf8)?obj->options.maccharset:CH_UTF8_MAC,
-                                            gr->gr_name, strlen(gr->gr_name), &name);
+                                            gr->gr_name, -1, &name);
        } else {
            len = 0;
            name = NULL;
@@ -2678,7 +2677,7 @@ int afp_mapid(AFPObj *obj, char *ibuf, int ibuflen _U_, char *rbuf, int *rbuflen
     return( AFP_OK );
 }
 
-int afp_mapname(AFPObj *obj _U_, char *ibuf, int ibuflen _U_, char *rbuf, int *rbuflen)
+int afp_mapname(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbuflen)
 {
     struct passwd      *pw;
     struct group       *gr;
@@ -2770,7 +2769,7 @@ int afp_mapname(AFPObj *obj _U_, char *ibuf, int ibuflen _U_, char *rbuf, int *r
 /* ------------------------------------
   variable DID support 
 */
-int afp_closedir(AFPObj *obj _U_, char *ibuf _U_, int ibuflen _U_, char *rbuf _U_, int *rbuflen)
+int afp_closedir(AFPObj *obj _U_, char *ibuf _U_, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen)
 {
 #if 0
     struct vol   *vol;
@@ -2806,7 +2805,7 @@ int afp_closedir(AFPObj *obj _U_, char *ibuf _U_, int ibuflen _U_, char *rbuf _U
 /* did creation gets done automatically 
  * there's a pb again with case but move it to cname
 */
-int afp_opendir(AFPObj *obj _U_, char *ibuf, int ibuflen  _U_, char *rbuf, int *rbuflen)
+int afp_opendir(AFPObj *obj _U_, char *ibuf, size_t ibuflen  _U_, char *rbuf, size_t *rbuflen)
 {
     struct vol         *vol;
     struct dir         *parentdir;