[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problem with ssh_pki_import_pubkey_file function


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)
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!
        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
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 functionAris Adamantiadis <aris@xxxxxxxxxxxx>
Archive administrator: postmaster@lists.cynapses.org