-
Notifications
You must be signed in to change notification settings - Fork 162
Migrate to callback-based authentication for libssh 0.12 #622
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
base: devel
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,6 +42,7 @@ | |
| #include "session_p.h" | ||
| #include "session_server.h" | ||
| #include "session_server_ch.h" | ||
| #include "session_server_ssh_wrapper.h" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this probably doesn't compile with |
||
|
|
||
| #ifdef NC_ENABLED_SSH_TLS | ||
|
|
||
|
|
@@ -2294,6 +2295,34 @@ nc_server_send_reply_io(struct nc_session *session, int io_timeout, const struct | |
| return ret; | ||
| } | ||
|
|
||
| #ifdef NC_ENABLED_SSH_TLS | ||
| /** | ||
| * @brief Scan the session ring for a newly established NETCONF SSH channel. | ||
| * | ||
| * @param[in] session Session whose SSH channel ring to scan. | ||
| * @return Pointer to the new starting NETCONF session if found, NULL otherwise. | ||
| */ | ||
| static struct nc_session * | ||
| nc_ps_ssh_find_new_channel(struct nc_session *session) | ||
|
Comment on lines
+2305
to
+2306
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider returning |
||
| { | ||
| struct nc_session *new; | ||
|
|
||
| if (!session->ti.libssh.next) { | ||
| return NULL; | ||
| } | ||
|
|
||
| for (new = session->ti.libssh.next; new != session; new = new->ti.libssh.next) { | ||
| if ((new->status == NC_STATUS_STARTING) && new->ti.libssh.channel && | ||
| (new->flags & NC_SESSION_SSH_SUBSYS_NETCONF)) { | ||
| return new; | ||
| } | ||
| } | ||
|
|
||
| return NULL; | ||
| } | ||
|
|
||
| #endif /* NC_ENABLED_SSH_TLS */ | ||
|
|
||
| /** | ||
| * @brief Poll a session from pspoll acquiring IO lock as needed. | ||
| * Session must be running and session RPC lock held! | ||
|
|
@@ -2317,8 +2346,9 @@ nc_ps_poll_session_io(struct nc_session *session, int io_timeout, time_t now_mon | |
| uint16_t idle_timeout; | ||
|
|
||
| #ifdef NC_ENABLED_SSH_TLS | ||
| #if !LIBSSH_0_12 | ||
| ssh_message ssh_msg; | ||
| struct nc_session *new; | ||
| #endif | ||
| #endif /* NC_ENABLED_SSH_TLS */ | ||
|
|
||
| /* check timeout first */ | ||
|
|
@@ -2341,36 +2371,33 @@ nc_ps_poll_session_io(struct nc_session *session, int io_timeout, time_t now_mon | |
| switch (session->ti_type) { | ||
| #ifdef NC_ENABLED_SSH_TLS | ||
| case NC_TI_SSH: | ||
| #if LIBSSH_0_12 | ||
| if (nc_ps_ssh_find_new_channel(session)) { | ||
| ret = NC_PSPOLL_SSH_CHANNEL; | ||
| break; | ||
| } | ||
| #else | ||
| ssh_msg = ssh_message_get(session->ti.libssh.session); | ||
| if (ssh_msg) { | ||
| if (nc_session_ssh_msg(session, NULL, ssh_msg, NULL)) { | ||
| ssh_message_reply_default(ssh_msg); | ||
| } | ||
| if (session->ti.libssh.next) { | ||
| for (new = session->ti.libssh.next; new != session; new = new->ti.libssh.next) { | ||
| if ((new->status == NC_STATUS_STARTING) && new->ti.libssh.channel && | ||
| (new->flags & NC_SESSION_SSH_SUBSYS_NETCONF)) { | ||
| /* new NETCONF SSH channel */ | ||
| ret = NC_PSPOLL_SSH_CHANNEL; | ||
| break; | ||
| } | ||
| } | ||
| if (new != session) { | ||
| ssh_message_free(ssh_msg); | ||
| break; | ||
| } | ||
| if (nc_ps_ssh_find_new_channel(session)) { | ||
| ret = NC_PSPOLL_SSH_CHANNEL; | ||
| ssh_message_free(ssh_msg); | ||
| break; | ||
| } | ||
| if (!ret) { | ||
| /* just some SSH message */ | ||
| ret = NC_PSPOLL_SSH_MSG; | ||
| } | ||
| ssh_message_free(ssh_msg); | ||
|
|
||
| /* break because 1) we don't want to return anything here ORred with NC_PSPOLL_RPC | ||
| * and 2) we don't want to delay openning a new channel by waiting for a RPC to get processed | ||
| * and 2) we don't want to delay opening a new channel by waiting for a RPC to get processed | ||
| */ | ||
| break; | ||
| } | ||
| #endif | ||
|
|
||
| r = ssh_channel_poll_timeout(session->ti.libssh.channel, 0, 0); | ||
| if (r == SSH_EOF) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move
nc_server_ssh_cb_data_free()to afterssh_free()so the callback structures remain valid for the entire session lifetime as libssh requires.