]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/appl.c
remove compiler warnings
[netatalk.git] / etc / afpd / appl.c
index 4859cabcc20529e70aa4c076664cbec4634594cd..3189ab5fa8f81a9bb8ff37e12a88b1b10fb0b41e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: appl.c,v 1.4 2001-12-03 05:03:38 jmarcus Exp $
+ * $Id: appl.c,v 1.16 2008-12-03 18:35:44 didg Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
-#ifdef HAVE_FCNTL_H
-#include <fcntl.h>
-#endif /* HAVE_FCNTL_H */
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
-#include <sys/types.h>
-#include <sys/stat.h>
+
 #include <sys/param.h>
-#include <sys/syslog.h>
+#include <atalk/logger.h>
 #include <errno.h>
 
-#include <netatalk/endian.h>
 #include <atalk/adouble.h>
 #include <atalk/afp.h>
 
@@ -35,9 +27,9 @@
 #include "file.h"
 #include "desktop.h"
 
-static struct savedt   sa = { { 0, 0, 0, 0 }, -1, 0 };
+static struct savedt   sa = { { 0, 0, 0, 0 }, -1, 0, 0};
 
-static __inline__ int pathcmp( p, plen, q, qlen )
+static int pathcmp( p, plen, q, qlen )
 char   *p;
 int    plen;
 char   *q;
@@ -49,6 +41,8 @@ int   qlen;
 static int applopen( vol, creator, flags, mode )
 struct vol     *vol;
 u_char creator[ 4 ];
+int flags;
+int mode;
 {
     char       *dtf, *adt, *adts;
 
@@ -134,7 +128,8 @@ u_short     mplen;
  * but uses upaths instead of mac format paths.
  *
  * The new way: dir and path refer to an app, path is a mac format
- * pathname.  makemacpath() builds a cname.
+ * pathname.  makemacpath() builds a cname. (zero is a path separator
+ * and it's not \0 terminated).
  *
  * See afp_getappl() for the backward compatiblity code.
  */
@@ -149,11 +144,15 @@ char      *path;
 
     p = mpath + mpathlen;
     p -= strlen( path );
-    strncpy( p, path, strlen( path ));
+    memcpy( p, path, strlen( path )); 
 
     while ( dir->d_parent != NULL ) {
-        p -= strlen( dir->d_name ) + 1;
-        strcpy( p, dir->d_name );
+        p -= strlen( dir->d_m_name ) + 1;
+        if (p < mpath) {
+            /* FIXME: pathname too long */
+            return NULL;
+        }
+        strcpy( p, dir->d_m_name );
         dir = dir->d_parent;
     }
     return( p );
@@ -161,16 +160,17 @@ char      *path;
 
 
 int afp_addappl(obj, ibuf, ibuflen, rbuf, rbuflen )
-AFPObj      *obj;
-char   *ibuf, *rbuf;
-int            ibuflen, *rbuflen;
+AFPObj  *obj;
+char   *ibuf, *rbuf _U_;
+int    ibuflen _U_, *rbuflen;
 {
     struct vol         *vol;
     struct dir         *dir;
     int                        tfd, cc;
     u_int32_t           did;
     u_int16_t          vid, mplen;
-    char               *path, *dtf, *p, *mp;
+    struct path         *path;
+    char                *dtf, *p, *mp;
     u_char             creator[ 4 ];
     u_char             appltag[ 4 ];
     char               *mpath, *tempfile;
@@ -180,14 +180,14 @@ int               ibuflen, *rbuflen;
 
     memcpy( &vid, ibuf, sizeof( vid ));
     ibuf += sizeof( vid );
-    if (( vol = getvolbyvid( vid )) == NULL ) {
+    if (NULL == ( vol = getvolbyvid( vid ))) {
         return( AFPERR_PARAM );
     }
 
     memcpy( &did, ibuf, sizeof( did ));
     ibuf += sizeof( did );
-    if (( dir = dirsearch( vol, did )) == NULL ) {
-        return( AFPERR_NOOBJ );
+    if (NULL == ( dir = dirlookup( vol, did )) ) {
+        return afp_errno;
     }
 
     memcpy( creator, ibuf, sizeof( creator ));
@@ -196,10 +196,10 @@ int               ibuflen, *rbuflen;
     memcpy( appltag, ibuf, sizeof( appltag ));
     ibuf += sizeof( appltag );
 
-    if (( path = cname( vol, dir, &ibuf )) == NULL ) {
-        return( AFPERR_NOOBJ );
+    if (NULL == ( path = cname( vol, dir, &ibuf )) ) {
+        return get_afp_errno(AFPERR_PARAM);
     }
-    if ( *path == '\0' ) {
+    if ( path_isadir(path) ) {
         return( AFPERR_BADTYPE );
     }
 
@@ -216,7 +216,10 @@ int                ibuflen, *rbuflen;
         return( AFPERR_PARAM );
     }
     mpath = obj->newtmp;
-    mp = makemacpath( mpath, AFPOBJ_TMPSIZ, curdir, path );
+    mp = makemacpath( mpath, AFPOBJ_TMPSIZ, curdir, path->m_name );
+    if (!mp) {
+        return AFPERR_PARAM;
+    }
     mplen =  mpath + AFPOBJ_TMPSIZ - mp;
 
     /* write the new appl entry at start of temporary file */
@@ -247,16 +250,17 @@ int               ibuflen, *rbuflen;
 }
 
 int afp_rmvappl(obj, ibuf, ibuflen, rbuf, rbuflen )
-AFPObj      *obj;
-char   *ibuf, *rbuf;
-int            ibuflen, *rbuflen;
+AFPObj  *obj;
+char   *ibuf, *rbuf _U_;
+int    ibuflen _U_, *rbuflen;
 {
     struct vol         *vol;
     struct dir         *dir;
     int                        tfd, cc;
     u_int32_t           did;
     u_int16_t          vid, mplen;
-    char               *path, *dtf, *mp;
+    struct path        *path;
+    char                *dtf, *mp;
     u_char             creator[ 4 ];
     char                *tempfile, *mpath;
 
@@ -265,23 +269,23 @@ int               ibuflen, *rbuflen;
 
     memcpy( &vid, ibuf, sizeof( vid ));
     ibuf += sizeof( vid );
-    if (( vol = getvolbyvid( vid )) == NULL ) {
+    if (NULL == ( vol = getvolbyvid( vid ))) {
         return( AFPERR_PARAM );
     }
 
     memcpy( &did, ibuf, sizeof( did ));
     ibuf += sizeof( did );
-    if (( dir = dirsearch( vol, did )) == NULL ) {
-        return( AFPERR_NOOBJ );
+    if (NULL == ( dir = dirlookup( vol, did )) ) {
+        return afp_errno;
     }
 
     memcpy( creator, ibuf, sizeof( creator ));
     ibuf += sizeof( creator );
 
-    if (( path = cname( vol, dir, &ibuf )) == NULL ) {
-        return( AFPERR_NOOBJ );
+    if (NULL == ( path = cname( vol, dir, &ibuf )) ) {
+        return get_afp_errno(AFPERR_PARAM);
     }
-    if ( *path == '.' ) {
+    if ( path_isadir(path) ) {
         return( AFPERR_BADTYPE );
     }
 
@@ -298,7 +302,11 @@ int                ibuflen, *rbuflen;
         return( AFPERR_PARAM );
     }
     mpath = obj->newtmp;
-    mp = makemacpath( mpath, AFPOBJ_TMPSIZ, curdir, path );
+    mp = makemacpath( mpath, AFPOBJ_TMPSIZ, curdir, path->m_name );
+    if (!mp) {
+        return AFPERR_PARAM ;
+    }
+
     mplen =  mpath + AFPOBJ_TMPSIZ - mp;
     cc = copyapplfile( sa.sdt_fd, tfd, mp, mplen );
     close( tfd );
@@ -316,11 +324,10 @@ int               ibuflen, *rbuflen;
 }
 
 int afp_getappl(obj, ibuf, ibuflen, rbuf, rbuflen )
-AFPObj      *obj;
+AFPObj  *obj;
 char   *ibuf, *rbuf;
-int            ibuflen, *rbuflen;
+int    ibuflen _U_, *rbuflen;
 {
-    struct stat                st;
     struct vol         *vol;
     char               *p, *q;
     int                        cc, buflen;
@@ -328,12 +335,13 @@ int               ibuflen, *rbuflen;
     u_char             creator[ 4 ];
     u_char             appltag[ 4 ];
     char                *buf, *cbuf;
-
+    struct path         *path;
+    
     ibuf += 2;
 
     memcpy( &vid, ibuf, sizeof( vid ));
     ibuf += sizeof( vid );
-    if (( vol = getvolbyvid( vid )) == NULL ) {
+    if (NULL == ( vol = getvolbyvid( vid )) ) {
         *rbuflen = 0;
         return( AFPERR_PARAM );
     }
@@ -434,17 +442,17 @@ int               ibuflen, *rbuflen;
     memcpy( q, p, len );
     q = cbuf;
 
-    if (( p = cname( vol, vol->v_dir, &q )) == NULL ) {
+    if (( path = cname( vol, vol->v_dir, &q )) == NULL ) {
         *rbuflen = 0;
         return( AFPERR_NOITEM );
     }
 
-    if ( stat( mtoupath(vol, p), &st ) < 0 ) {
+    if ( path_isadir(path) || path->st_errno ) {
         *rbuflen = 0;
         return( AFPERR_NOITEM );
     }
     buflen = *rbuflen - sizeof( bitmap ) - sizeof( appltag );
-    if ( getfilparams(vol, bitmap, p, curdir, &st, rbuf + sizeof( bitmap ) +
+    if ( getfilparams(vol, bitmap, path, curdir, rbuf + sizeof( bitmap ) +
                       sizeof( appltag ), &buflen ) != AFP_OK ) {
         *rbuflen = 0;
         return( AFPERR_BITMAP );