On 03/03/2011 03:04 PM, Alexander Lamaison wrote:
On 2 March 2011 15:22, Pierre-Yves Fontaniere<[email protected]> wrote:
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".
The best way to provide the patch is using git diff. This preserves
the log and authorship information in a way that can simply be
comitted as-is.
Failing that, please provide the patch from `diff -u`. Context diffs
can be hard to read for humans.
Yep I know, but there's no option -u in "AIX genuine diff" and AIX patch
doesn't work with unified context patch... I will install GNU diff and
patch tools . :)
I attached a diff -u patch to this mail
- Some lines to really remove ending '\n' directly when reading lines from
knownhosts file.
Can you explain a bit more about this? What was the code doing wrong before?
In fact, the code wasn't doing something wrong. But when i was
debugging, i saw (with simple printf) keys with leading '\n'. So I
thought first the problem was here. I saw later that was not the case
but even if i know that there's no use of function like strlen in the
code, i prefer having a '\n' leading free and zero terminated string.
libssh2_knownhost_readfile is the only place where we use something else
than const char *. So this is the place to format every line and have
zero terminated string without leading '\n'.
I used strrchr which take the buffer from the end and doesn't browse all
the key from the beginning (like it is done later in
libssh2_knownhost_readline).
I let you decide if it is an interesting modification or not. :)
- A section to handle correctly multiple hostnames, aliases, IP addr on the
same line in knownhosts file.
For my testing, can you send me an example of what one of these AIX
entries with multiple aliases contains?
This is not specific to AIX :) we use this kind of knownhosts entries on
Linux, Solaris and AIX.
Entry like :
ccsmurf,ccsvli05,ccsvli05.in2p3.fr,ccsmurf.in2p3.fr,134.158.104.140
ssh-rsa
AAAAB3NzaC1yc2EAAAABIwAAAIEAq1iiPKlBbyw3I+wC76ugwt7DGnseVNjzjZf8y7vO+2oiuBkRMdoqh9K3oHzkiloTeAHOZH4V89nUt/WLTqKG4j4/sSwaCD9gRKwFS4me/Pnvi8zqwmF8YrLwQdTGtDZo2iz0Dt4KqAE6fQ9mQ/iTlJMFUKOed8luDDfX6Ba0lBE=
Pierre-yves
--- knownhost.c 2011-03-03 16:15:33 +0100
+++ knownhost_patched.c 2011-03-02 15:59:41 +0100
@@ -582,6 +582,7 @@
{
const char *p;
const char *orig = host;
+ const char *sechost = NULL;
const char *salt = NULL;
const char *comment = NULL;
size_t commentlen = 0;
@@ -722,17 +723,39 @@
}
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;
+ /* 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,7 +816,11 @@
"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,16 +856,6 @@
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)
@@ -863,6 +880,7 @@
FILE *file;
int num = 0;
char buf[2048];
+ char *lastnewline;
if(type != LIBSSH2_KNOWNHOST_FILE_OPENSSH)
return _libssh2_error(hosts->session,
@@ -873,6 +891,12 @@
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