On 03/02/2011 02:11 PM, Alexander Lamaison wrote:
Anyway, I hope I could provide a patch soon.
Great :)
I'm not really used to provide patches, and i'm working on AIX also, so the way of doing a patch is somewhat different :)
File provided is from a "diff -c".

I added :
- A little section to skip '@' begining lines instead of handling them as an hostname. - Some lines to really remove ending '\n' directly when reading lines from knownhosts file. - A section to handle correctly multiple hostnames, aliases, IP addr on the same line in knownhosts file.

Hope it will be OK for you.

Thanks
Pierre-yves
*** knownhost.c	Wed Mar  2 16:00:13 2011
--- knownhost_patched.c	Wed Mar  2 15:59:41 2011
***************
*** 582,587 ****
--- 582,588 ----
  {
      const char *p;
      const char *orig = host;
+     const char *sechost = NULL;
      const char *salt = NULL;
      const char *comment = NULL;
      size_t commentlen = 0;
***************
*** 722,738 ****
      }
  
      if(sep) {
!         /* The second host after the comma, add this first. Copy it to the
!            temp buffer and zero terminate */
!         memcpy(hostbuf, sep, seplen);
!         hostbuf[seplen]=0;
  
!         rc = knownhost_add(hosts, hostbuf, salt, key, keylen,
!                            comment, commentlen,
!                            type | LIBSSH2_KNOWNHOST_KEYENC_BASE64,
!                            NULL);
!         if(rc)
!             return rc;
      }
  
      if (!salt)
--- 723,761 ----
      }
  
      if(sep) {
!         /* The other host names after the comma, add this first. Copy it 
!          * to the temp buffer and zero terminate */
!         size_t sechost_len;
!          
!         sechost = sep;
!         while ((sechost = memchr(sep, ',', seplen)) != NULL) {
!             sechost_len = sechost-sep+1;
!             memcpy(hostbuf, sep, sechost_len );
!             hostbuf[sechost_len-1] = 0;
!             rc = knownhost_add(hosts, hostbuf, salt, key, keylen,     
!                                 comment, commentlen,                   
!                                 type | LIBSSH2_KNOWNHOST_KEYENC_BASE64,
!                                 NULL);                                 
!             
!             if(rc)
!                 return rc;
  
!             sep = sechost +1;
!             seplen -= sechost_len;
!         }
!         if (sep && seplen>0) {
!             memcpy(hostbuf, sep,seplen);
!             hostbuf[seplen]=0;
!             rc = knownhost_add(hosts, hostbuf, salt, key, keylen,      
!                                 comment, commentlen,                   
!                                 type | LIBSSH2_KNOWNHOST_KEYENC_BASE64,
!                                 NULL);                                 
!                                                                        
!            if(rc)                                                     
!                return rc;                                             
! 
!         }
!         
      }
  
      if (!salt)
***************
*** 793,799 ****
                                "store");
  
      cp = line;
! 
      /* skip leading whitespaces */
      while(len && ((*cp==' ') || (*cp == '\t'))) {
          cp++;
--- 816,826 ----
                                "store");
  
      cp = line;
!     
!     /* Markers handle is not implemented yet */
!     if (*cp == '@')
!         return LIBSSH2_ERROR_NONE;
!     
      /* skip leading whitespaces */
      while(len && ((*cp==' ') || (*cp == '\t'))) {
          cp++;
***************
*** 829,844 ****
      keyp = cp; /* the key starts here */
      keylen = len;
  
-     /* check if the line (key) ends with a newline and if so kill it */
-     while(len && *cp && (*cp != '\n')) {
-         cp++;
-         len--;
-     }
- 
-     /* zero terminate where the newline is */
-     if(*cp == '\n')
-         keylen--; /* don't include this in the count */
- 
      /* deal with this one host+key line */
      rc = hostline(hosts, hostp, hostlen, keyp, keylen);
      if(rc)
--- 856,861 ----
***************
*** 863,868 ****
--- 880,886 ----
      FILE *file;
      int num = 0;
      char buf[2048];
+     char *lastnewline;
  
      if(type != LIBSSH2_KNOWNHOST_FILE_OPENSSH)
          return _libssh2_error(hosts->session,
***************
*** 873,878 ****
--- 891,902 ----
      file = fopen(filename, "r");
      if(file) {
          while(fgets(buf, sizeof(buf), file)) {
+             /* Search for an ending newline*/
+             lastnewline = strrchr(buf,'\n');
+             /* Replace it by a \0 if it exists */
+             if (lastnewline != NULL)
+                 *lastnewline = '\0';
+ 
              if(libssh2_knownhost_readline(hosts, buf, strlen(buf), type))
                  break;
              num++;
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel

Reply via email to