Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning ssh2_auth_pubkey_file #53

Open
shopblocks opened this issue Mar 7, 2016 · 4 comments
Open

Warning ssh2_auth_pubkey_file #53

shopblocks opened this issue Mar 7, 2016 · 4 comments

Comments

@shopblocks
Copy link

When trying to connect to a user that doesn't exist, there is an exception thrown, but also a warning is thrown. This warning cannot be suppressed or hidden on our end (due to it being part of the package).

Can this warning be suppressed on https://github.com/Herzult/php-ssh/blob/master/src/Ssh/Authentication/PublicKeyFile.php#L40

@h4cc
Copy link
Collaborator

h4cc commented Mar 8, 2016

Thanks @shopblocks , the function does trigger a undocumented E_WARNING in case of a problem:

/* {{{ proto bool ssh2_auth_pubkey_file(resource session, string username, string pubkeyfile, string privkeyfile[, string passphrase])
 * Authenticate using a public key
 */
PHP_FUNCTION(ssh2_auth_pubkey_file)
{
    LIBSSH2_SESSION *session;
    zval *zsession;
    char *username, *pubkey, *privkey, *passphrase = NULL;
    int username_len, pubkey_len, privkey_len, passphrase_len;
    char *newpath;
    struct passwd *pws;

    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsss|s", &zsession,   &username, &username_len,
                                                                                &pubkey, &pubkey_len,
                                                                                &privkey, &privkey_len,
                                                                                &passphrase, &passphrase_len) == FAILURE) {
        return;
    }

    if (SSH2_OPENBASEDIR_CHECKPATH(pubkey) || SSH2_OPENBASEDIR_CHECKPATH(privkey)) {
        RETURN_FALSE;
    }

    SSH2_FETCH_NONAUTHENTICATED_SESSION(session, zsession);

    // Explode '~/paths' stopgap fix because libssh2 does not accept tilde for homedir
    // This should be ifdef'ed when a fix is available to support older libssh2 versions
    pws = getpwuid(geteuid());
    if (pubkey_len >= 2 && *pubkey == '~' && *(pubkey+1) == '/') {
        newpath = emalloc(strlen(pws->pw_dir) + strlen(pubkey));
        strcpy(newpath, pws->pw_dir);
        strcat(newpath, pubkey+1);
        efree(pubkey);
        pubkey = newpath;
    }
    if (privkey_len >= 2 && *privkey == '~' && *(privkey+1) == '/') {
        newpath = emalloc(strlen(pws->pw_dir) + strlen(privkey));
        strcpy(newpath, pws->pw_dir);
        strcat(newpath, privkey+1);
        efree(privkey);
        privkey = newpath;
    }

    /* TODO: Support passphrase callback */
    if (libssh2_userauth_publickey_fromfile_ex(session, username, username_len, pubkey, privkey, passphrase)) {
        char *buf;
        int len;
        libssh2_session_last_error(session, &buf, &len, 0);
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "Authentication failed for %s using public key: %s", username, buf);
        RETURN_FALSE;
    }

    RETURN_TRUE;
}
/* }}} */

We could fix this using the silencing Operator like @ssh2_auth_pubkey_file(...).

@Herzult Will we fix it that way?

@shopblocks
Copy link
Author

Bug report filed on PHP to document this: https://bugs.php.net/bug.php?id=71738

@shopblocks
Copy link
Author

Any update on this?

Jean85 added a commit to Jean85/php-ssh that referenced this issue May 20, 2016
Silencing warning when also having an exception when using ssh2_auth_pubkey_file() on PublicKeyFile::authenticate
@Jean85
Copy link
Contributor

Jean85 commented May 20, 2016

I opened a PR: #54

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants