Hi Игорь,

You are right. I'll search for other places that do the same. We're not
very windows minded and often miss these kind of portability quircks.

Aris

Le 09/07/15 12:03, Игорь Коваленко a écrit :
> Hello!
>
> I'm trying to create a libssh server with public key authentication
> and I've got an error in ssh_pki_import_pubkey_file function during
> handling SSH_REQUEST_AUTH (see mark // <-- on a line below)
> pki.c:
> int ssh_pki_import_pubkey_file(const char *filename, ssh_key *pkey)
> {
>     file = fopen(filename, "r");
>     ...
>     rc = fstat(fileno(file), &sb);
>     ...
>     size = fread(key_buf, 1, sb.st_size, file);
>
>     if (size != sb.st_size) {   // <--- error is here - different sizes!
>         SAFE_FREE(key_buf);
>         ssh_pki_log("Error reading %s: %s", filename, strerror(errno));
>         return SSH_ERROR;
>     }
>     ...
> }
> If I change fopen's mode to "rb" then ssh_pki_import_pubkey_file call
> will be successful.
> I'm using VisualStudio 2013
> The public key file was generated with ssh-keygen.exe.
> It seems that with "r" mode file is opened in text mode by default and
> according to MSDN  (here
> <https://msdn.microsoft.com/query/dev12.query?appId=Dev12IDEF1&l=EN-US&k=k%28stdio%2Ffopen%29;k%28fopen%29;k%28DevLang-C%2B%2B%29;k%28TargetOS-Windows%29&rd=true>)
> in such a case some translations are performed during read operation.
> Would not it be better for compatibility issues to use fopen with "rb"
> mode?

Reply via email to