changeset 739:ba82724da370

2006-5-14 Brian Masney <masneyb@gftp.org> * lib/fsplib/fsplib.c lib/fsplib/fsplib.h - updated with FSPLIB 0.8
author masneyb
date Sun, 14 May 2006 16:40:53 +0000
parents 4029ab7f13e4
children 6968041e4b82
files ChangeLog lib/fsplib/fsplib.c lib/fsplib/fsplib.h
diffstat 3 files changed, 46 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun May 14 16:29:00 2006 +0000
+++ b/ChangeLog	Sun May 14 16:40:53 2006 +0000
@@ -1,4 +1,6 @@
 2006-5-14 Brian Masney <masneyb@gftp.org>
+	* lib/fsplib/fsplib.c lib/fsplib/fsplib.h - updated with FSPLIB 0.8
+
 	* lib/fsplib/lock.c lib/pty.c - compile fixes under NetBSD 
 	(from Matthias Scheler tron@zhadum.de>) (closes #168984)
 
@@ -3336,7 +3338,7 @@
 
 	* cvsclean - added this script
 
-	* *.[ch] - added $Id: ChangeLog,v 1.419 2006/05/14 16:28:59 masneyb Exp $ tags
+	* *.[ch] - added $Id: ChangeLog,v 1.420 2006/05/14 16:40:53 masneyb Exp $ tags
 
 	* debian/* - updated files from Debian maintainer
 
--- a/lib/fsplib/fsplib.c	Sun May 14 16:29:00 2006 +0000
+++ b/lib/fsplib/fsplib.c	Sun May 14 16:40:53 2006 +0000
@@ -26,7 +26,7 @@
 #include <dirent.h>
 
 #ifdef HAVE_STDINT_H
-# include <stdint.h>
+#include <stdint.h>
 #endif
 
 #include "fsplib.h"
@@ -87,12 +87,6 @@
        return -1;
    }
 
-   if(in.cmd != command)
-   {
-       errno = ENOMSG;
-       return -1;
-   }
-
    errno = 0;
    return  0;
 }
@@ -250,8 +244,12 @@
     /* get the next key */
     p->key = client_get_key((FSP_LOCK *)s->lock);
 
+    retry = random() & 0xfff8;
+    if (s->seq == retry)
+	s->seq ^= 0x1080;
+    else
+	s->seq = retry;	
     dupes = retry = 0;
-    s->seq = (s-> seq + 0x08) & 0xfff8;
     t_delay = 0;
     /* compute initial delay here */
     /* we are using hardcoded value for now */
@@ -363,6 +361,22 @@
                 continue;
             }
 
+            /* check command code */
+	    if( (rpkt->cmd != p->cmd) && (rpkt->cmd != FSP_CC_ERR))
+	    {
+		dupes++;
+		continue;
+	    }
+
+            /* check correct filepos */
+	    if( (rpkt->pos != p->pos) && ( p->cmd == FSP_CC_GET_DIR ||
+		p->cmd == FSP_CC_GET_FILE || p->cmd == FSP_CC_UP_LOAD ||
+		p->cmd == FSP_CC_GRAB_FILE || p->cmd == FSP_CC_INFO) )
+	    {
+		dupes++;
+		continue;
+	    }
+
             /* now we have a correct packet */
 
             /* compute rtt delay */
@@ -460,7 +474,7 @@
     s->fd=fd;
     s->timeout=300000; /* 5 minutes */
     s->maxdelay=60000; /* 1 minute  */
-    s->seq=random();
+    s->seq=random() & 0xfff8;
     if ( password ) 
         s->password = strdup(password);
     return s;
@@ -524,7 +538,7 @@
             pos = -1;
             break;
         }
-        if ( in.cmd != FSP_CC_GET_DIR )
+        if ( in.cmd == FSP_CC_ERR )
         {
             /* bad reply from the server */
             pos = -1;
@@ -569,6 +583,7 @@
                 free(dir->data);
             free(dir);
         }
+	errno = EPERM;
         return NULL;
     }
 
@@ -576,7 +591,8 @@
     dir->blocksize=blocksize;
     dir->dirname=strdup(dirname);
     dir->datasize=pos;
-
+    
+    errno = 0;
     return dir;
 }
 
@@ -623,7 +639,7 @@
 
     if (fentry.namlen > MAXNAMLEN)
     {
-	entry->d_name[MAXNAMLEN + 1 ] = '\0';
+	entry->d_name[MAXNAMLEN] = '\0';
 #ifdef HAVE_DIRENT_NAMLEN
 	entry->d_namlen = MAXNAMLEN;
     } else
@@ -689,7 +705,7 @@
        /* skip file date and file size */
        dir->dirpos += 9;
        /* read file name */
-       entry->name[255 + 1] = '\0';
+       entry->name[255] = '\0';
        strncpy(entry->name,(char *)( dir->data + dir->dirpos ),MAXNAMLEN);
        namelen = strlen( (char *) dir->data+dir->dirpos);
        /* skip over file name */
@@ -850,7 +866,7 @@
 	         file->err=1;
 		 return done/size;
 	    }
-	    if(file->in.cmd != FSP_CC_GET_FILE)
+	    if(file->in.cmd == FSP_CC_ERR)
 	    {
 		errno = EIO;
 		file->err=1;
@@ -916,7 +932,7 @@
 	         file->err=1;
 		 return done/size;
 	    }
-	    if(file->in.cmd != FSP_CC_UP_LOAD)
+	    if(file->in.cmd == FSP_CC_ERR)
 	    {
 		errno = EIO;
 		file->err=1;
@@ -985,7 +1001,7 @@
 	 file->err=1;
 	 return -1;
     }
-    if(file->in.cmd != FSP_CC_UP_LOAD)
+    if(file->in.cmd == FSP_CC_ERR)
     {
 	errno = EIO;
 	file->err=1;
@@ -1140,7 +1156,7 @@
 		rc=-1;
 	    } else
 	    {
-		if(in.cmd != FSP_CC_INSTALL)
+		if(in.cmd == FSP_CC_ERR)
 		{
 		    rc=-1;
 		    errno = EPERM;
@@ -1164,7 +1180,12 @@
    if(fsp_transaction(s,&out,&in))
        return -1;
 
-   if(in.cmd != FSP_CC_GET_PRO || in.pos != FSP_PRO_BYTES)
+   if(in.cmd == FSP_CC_ERR)
+   {
+       errno = ENOENT;
+       return -1;
+   }
+   if(in.pos != FSP_PRO_BYTES)
    {
        errno = ENOMSG;
        return -1;
@@ -1190,7 +1211,7 @@
    if(fsp_transaction(s,&out,&in))
        return -1;
 
-   if(in.cmd != FSP_CC_STAT)
+   if(in.cmd == FSP_CC_ERR)
    {
        errno = ENOTSUP;
        return -1;
@@ -1272,7 +1293,7 @@
    if(fsp_transaction(s,&out,&in))
        return -1;
 
-   if(in.cmd != FSP_CC_RENAME)
+   if(in.cmd == FSP_CC_ERR)
    {
        errno = EPERM;
        return -1;
--- a/lib/fsplib/fsplib.h	Sun May 14 16:29:00 2006 +0000
+++ b/lib/fsplib/fsplib.h	Sun May 14 16:40:53 2006 +0000
@@ -1,6 +1,8 @@
 #ifndef _FSPLIB_H
 #define _FSPLIB_H 1
 #include <time.h>
+#include <dirent.h>
+#include <sys/stat.h>
 /* The FSP v2 protocol support library - public interface */
 
 /*