[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Problem with ssh_pki_import_pubkey_file function
[Thread Prev] | [Thread Next]
- Subject: Problem with ssh_pki_import_pubkey_file function
- From: Игорь Коваленко <igor.a.kovalenko@xxxxxxxxx>
- Reply-to: libssh@xxxxxxxxxx
- Date: Thu, 9 Jul 2015 13:03:04 +0300
- To: libssh@xxxxxxxxxx
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(stdio%2Ffopen);k(fopen);k(DevLang-C%2B%2B);k(TargetOS-Windows)&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?
Re: Problem with ssh_pki_import_pubkey_file function | Aris Adamantiadis <aris@xxxxxxxxxxxx> |