|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
Patch ssh2_agent_authentication for ssh2 Bug #60522Patch version 2012-05-25 09:46 UTC Return to Bug #60522 | Download this patchThis patch renders other patches obsolete Obsolete patches: Patch Revisions:Developer: casper@bcx.nl
diff --git a/ssh2-0.11.3/config.m4 b/ssh2-0.11.3/config.m4
index 462e7a2..9ec40b2 100644
--- a/ssh2-0.11.3/config.m4
+++ b/ssh2-0.11.3/config.m4
@@ -74,6 +74,15 @@ if test "$PHP_SSH2" != "no"; then
],[
-L$SSH2_DIR/lib -lm
])
+
+ PHP_CHECK_LIBRARY($LIBNAME,libssh2_agent_init,
+ [
+ AC_DEFINE(PHP_SSH2_AGENT_AUTH, 1, [Have libssh2 with ssh-agent support])
+ ],[
+ AC_MSG_WARN([libssh2 <= 1.2.3, ssh-agent subsystem support not enabled])
+ ],[
+ -L$SSH2_DIR/lib -lm
+ ])
PHP_SUBST(SSH2_SHARED_LIBADD)
diff --git a/ssh2-0.11.3/ssh2.c b/ssh2-0.11.3/ssh2.c
index 504a054..9482718 100644
--- a/ssh2-0.11.3/ssh2.c
+++ b/ssh2-0.11.3/ssh2.c
@@ -1104,6 +1104,85 @@ PHP_FUNCTION(ssh2_publickey_list)
/* }}} */
#endif /* PHP_SSH2_PUBLICKEY_SUBSYSTEM */
+#ifdef PHP_SSH2_AGENT_AUTH
+/* {{{ proto array ssh2_auth_agent(resource session, string username)
+Authenticate using the ssh agent */
+PHP_FUNCTION(ssh2_auth_agent)
+{
+ zval *zsession;
+ char *username;
+ int username_len;
+
+ LIBSSH2_SESSION *session;
+ char *userauthlist;
+ LIBSSH2_AGENT *agent = NULL;
+ int rc;
+ struct libssh2_agent_publickey *identity, *prev_identity = NULL;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &zsession, &username, &username_len) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ ZEND_FETCH_RESOURCE(session, LIBSSH2_SESSION*, &zsession, -1, PHP_SSH2_SESSION_RES_NAME, le_ssh2_session);
+
+ /* check what authentication methods are available */
+ userauthlist = libssh2_userauth_list(session, username, username_len);
+
+ if (strstr(userauthlist, "publickey") == NULL) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "\"publickey\" authentication is not supported");
+ RETURN_FALSE;
+ }
+
+ /* Connect to the ssh-agent */
+ agent = libssh2_agent_init(session);
+
+ if (!agent) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failure initializing ssh-agent support");
+ RETURN_FALSE;
+ }
+
+ if (libssh2_agent_connect(agent)) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failure connecting to ssh-agent");
+ libssh2_agent_free(agent);
+ RETURN_FALSE;
+ }
+
+ if (libssh2_agent_list_identities(agent)) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failure requesting identities to ssh-agent");
+ libssh2_agent_disconnect(agent);
+ libssh2_agent_free(agent);
+ RETURN_FALSE;
+ }
+
+ while (1) {
+ rc = libssh2_agent_get_identity(agent, &identity, prev_identity);
+
+ if (rc == 1) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't continue authentication");
+ libssh2_agent_disconnect(agent);
+ libssh2_agent_free(agent);
+ RETURN_FALSE;
+ }
+
+ if (rc < 0) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failure obtaining identity from ssh-agent support");
+ libssh2_agent_disconnect(agent);
+ libssh2_agent_free(agent);
+ RETURN_FALSE;
+ }
+
+ if (!libssh2_agent_userauth(agent, username, identity)) {
+ libssh2_agent_disconnect(agent);
+ libssh2_agent_free(agent);
+ RETURN_TRUE;
+ }
+ prev_identity = identity;
+ }
+}
+/* }}} */
+#endif /* PHP_SSH2_AGENT_AUTH */
+
+
/* ***********************
* Module Housekeeping *
*********************** */
@@ -1305,6 +1384,10 @@ zend_function_entry ssh2_functions[] = {
PHP_FE(ssh2_publickey_list, NULL)
#endif
+#ifdef PHP_SSH2_AGENT_AUTH
+ PHP_FE(ssh2_auth_agent, NULL)
+#endif
+
{NULL, NULL, NULL}
};
/* }}} */
|
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 19:00:01 2025 UTC |