mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-07-31 00:03:07 +03:00
examples: Avoid unused parameter warnings and reformat
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
This commit is contained in:
@ -81,7 +81,10 @@ static struct cleanup_node_struct *cleanup_stack = NULL;
|
|||||||
|
|
||||||
static void _close_socket(struct event_fd_data_struct event_fd_data);
|
static void _close_socket(struct event_fd_data_struct event_fd_data);
|
||||||
|
|
||||||
static void cleanup_push(struct cleanup_node_struct** head_ref, struct event_fd_data_struct *new_data) {
|
static void
|
||||||
|
cleanup_push(struct cleanup_node_struct** head_ref,
|
||||||
|
struct event_fd_data_struct *new_data)
|
||||||
|
{
|
||||||
// Allocate memory for node
|
// Allocate memory for node
|
||||||
struct cleanup_node_struct *new_node = malloc(sizeof *new_node);
|
struct cleanup_node_struct *new_node = malloc(sizeof *new_node);
|
||||||
|
|
||||||
@ -94,7 +97,9 @@ static void cleanup_push(struct cleanup_node_struct** head_ref, struct event_fd_
|
|||||||
(*head_ref) = new_node;
|
(*head_ref) = new_node;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void do_cleanup(struct cleanup_node_struct **head_ref) {
|
static void
|
||||||
|
do_cleanup(struct cleanup_node_struct **head_ref)
|
||||||
|
{
|
||||||
struct cleanup_node_struct *current = (*head_ref);
|
struct cleanup_node_struct *current = (*head_ref);
|
||||||
struct cleanup_node_struct *previous = NULL, *gone = NULL;
|
struct cleanup_node_struct *previous = NULL, *gone = NULL;
|
||||||
|
|
||||||
@ -133,16 +138,22 @@ static void do_cleanup(struct cleanup_node_struct **head_ref) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int auth_password(ssh_session session, const char *user,
|
static int
|
||||||
const char *password, void *userdata) {
|
auth_password(ssh_session session,
|
||||||
(void)userdata;
|
const char *user,
|
||||||
_ssh_log(SSH_LOG_PROTOCOL, "=== auth_password", "Authenticating user %s pwd %s",user, password);
|
const char *password,
|
||||||
if (strcmp(user,USER) == 0 && strcmp(password, PASSWORD) == 0){
|
UNUSED_PARAM(void *userdata))
|
||||||
|
{
|
||||||
|
_ssh_log(SSH_LOG_PROTOCOL,
|
||||||
|
"=== auth_password", "Authenticating user %s pwd %s",
|
||||||
|
user,
|
||||||
|
password);
|
||||||
|
if (strcmp(user, USER) == 0 && strcmp(password, PASSWORD) == 0) {
|
||||||
authenticated = true;
|
authenticated = true;
|
||||||
printf("Authenticated\n");
|
printf("Authenticated\n");
|
||||||
return SSH_AUTH_SUCCESS;
|
return SSH_AUTH_SUCCESS;
|
||||||
}
|
}
|
||||||
if (tries >= 3){
|
if (tries >= 3) {
|
||||||
printf("Too many authentication tries\n");
|
printf("Too many authentication tries\n");
|
||||||
ssh_disconnect(session);
|
ssh_disconnect(session);
|
||||||
error_set = true;
|
error_set = true;
|
||||||
@ -152,25 +163,34 @@ static int auth_password(ssh_session session, const char *user,
|
|||||||
return SSH_AUTH_DENIED;
|
return SSH_AUTH_DENIED;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int auth_gssapi_mic(ssh_session session, const char *user, const char *principal, void *userdata) {
|
static int
|
||||||
|
auth_gssapi_mic(ssh_session session,
|
||||||
|
const char *user,
|
||||||
|
const char *principal,
|
||||||
|
UNUSED_PARAM(void *userdata))
|
||||||
|
{
|
||||||
ssh_gssapi_creds creds = ssh_gssapi_get_creds(session);
|
ssh_gssapi_creds creds = ssh_gssapi_get_creds(session);
|
||||||
(void)userdata;
|
printf("Authenticating user %s with gssapi principal %s\n",
|
||||||
printf("Authenticating user %s with gssapi principal %s\n", user, principal);
|
user, principal);
|
||||||
if (creds != NULL)
|
if (creds != NULL) {
|
||||||
printf("Received some gssapi credentials\n");
|
printf("Received some gssapi credentials\n");
|
||||||
else
|
} else {
|
||||||
printf("Not received any forwardable creds\n");
|
printf("Not received any forwardable creds\n");
|
||||||
|
}
|
||||||
printf("authenticated\n");
|
printf("authenticated\n");
|
||||||
authenticated = true;
|
authenticated = true;
|
||||||
return SSH_AUTH_SUCCESS;
|
return SSH_AUTH_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int subsystem_request(ssh_session session, ssh_channel channel, const char *subsystem, void *userdata) {
|
static int
|
||||||
(void)session;
|
subsystem_request(UNUSED_PARAM(ssh_session session),
|
||||||
(void)channel;
|
UNUSED_PARAM(ssh_channel channel),
|
||||||
//(void)subsystem;
|
const char *subsystem,
|
||||||
(void)userdata;
|
UNUSED_PARAM(void *userdata))
|
||||||
_ssh_log(SSH_LOG_PROTOCOL, "=== subsystem_request", "Channel subsystem reqeuest: %s", subsystem);
|
{
|
||||||
|
_ssh_log(SSH_LOG_PROTOCOL,
|
||||||
|
"=== subsystem_request", "Channel subsystem reqeuest: %s",
|
||||||
|
subsystem);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,9 +198,10 @@ struct ssh_channel_callbacks_struct channel_cb = {
|
|||||||
.channel_subsystem_request_function = subsystem_request
|
.channel_subsystem_request_function = subsystem_request
|
||||||
};
|
};
|
||||||
|
|
||||||
static ssh_channel new_session_channel(ssh_session session, void *userdata) {
|
static ssh_channel
|
||||||
(void)session;
|
new_session_channel(UNUSED_PARAM(ssh_session session),
|
||||||
(void)userdata;
|
UNUSED_PARAM(void *userdata))
|
||||||
|
{
|
||||||
_ssh_log(SSH_LOG_PROTOCOL, "=== subsystem_request", "Session channel request");
|
_ssh_log(SSH_LOG_PROTOCOL, "=== subsystem_request", "Session channel request");
|
||||||
/* For TCP forward only there seems to be no need for a session channel */
|
/* For TCP forward only there seems to be no need for a session channel */
|
||||||
/*if(chan != NULL)
|
/*if(chan != NULL)
|
||||||
@ -193,18 +214,25 @@ static ssh_channel new_session_channel(ssh_session session, void *userdata) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void stack_socket_close(UNUSED_PARAM(ssh_session session),
|
static void
|
||||||
struct event_fd_data_struct *event_fd_data)
|
stack_socket_close(UNUSED_PARAM(ssh_session session),
|
||||||
|
struct event_fd_data_struct *event_fd_data)
|
||||||
{
|
{
|
||||||
if (event_fd_data->stacked != 1) {
|
if (event_fd_data->stacked != 1) {
|
||||||
_ssh_log(SSH_LOG_FUNCTIONS, "=== stack_socket_close", "Closing fd = %d sockets_cnt = %d", *event_fd_data->p_fd, sockets_cnt);
|
_ssh_log(SSH_LOG_FUNCTIONS, "=== stack_socket_close",
|
||||||
|
"Closing fd = %d sockets_cnt = %d", *event_fd_data->p_fd,
|
||||||
|
sockets_cnt);
|
||||||
event_fd_data->stacked = 1;
|
event_fd_data->stacked = 1;
|
||||||
cleanup_push(&cleanup_stack, event_fd_data);
|
cleanup_push(&cleanup_stack, event_fd_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _close_socket(struct event_fd_data_struct event_fd_data) {
|
static void
|
||||||
_ssh_log(SSH_LOG_FUNCTIONS, "=== close_socket", "Closing fd = %d sockets_cnt = %d", *event_fd_data.p_fd, sockets_cnt);
|
_close_socket(struct event_fd_data_struct event_fd_data)
|
||||||
|
{
|
||||||
|
_ssh_log(SSH_LOG_FUNCTIONS, "=== close_socket",
|
||||||
|
"Closing fd = %d sockets_cnt = %d", *event_fd_data.p_fd,
|
||||||
|
sockets_cnt);
|
||||||
ssh_event_remove_fd(mainloop, *event_fd_data.p_fd);
|
ssh_event_remove_fd(mainloop, *event_fd_data.p_fd);
|
||||||
sockets_cnt--;
|
sockets_cnt--;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@ -215,23 +243,31 @@ static void _close_socket(struct event_fd_data_struct event_fd_data) {
|
|||||||
(*event_fd_data.p_fd) = SSH_INVALID_SOCKET;
|
(*event_fd_data.p_fd) = SSH_INVALID_SOCKET;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int service_request(ssh_session session, const char *service, void *userdata) {
|
static int
|
||||||
(void)session;
|
service_request(UNUSED_PARAM(ssh_session session),
|
||||||
//(void)service;
|
const char *service,
|
||||||
(void)userdata;
|
UNUSED_PARAM(void *userdata))
|
||||||
|
{
|
||||||
_ssh_log(SSH_LOG_PROTOCOL, "=== service_request", "Service request: %s", service);
|
_ssh_log(SSH_LOG_PROTOCOL, "=== service_request", "Service request: %s", service);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void global_request(ssh_session session, ssh_message message, void *userdata) {
|
static void
|
||||||
(void)session;
|
global_request(UNUSED_PARAM(ssh_session session),
|
||||||
(void)userdata;
|
ssh_message message,
|
||||||
_ssh_log(SSH_LOG_PROTOCOL, "=== global_request", "Global request, message type: %d", ssh_message_type(message));
|
UNUSED_PARAM(void *userdata))
|
||||||
|
{
|
||||||
|
_ssh_log(SSH_LOG_PROTOCOL,
|
||||||
|
"=== global_request", "Global request, message type: %d",
|
||||||
|
ssh_message_type(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void my_channel_close_function(ssh_session session, ssh_channel channel, void *userdata) {
|
static void
|
||||||
|
my_channel_close_function(ssh_session session,
|
||||||
|
UNUSED_PARAM(ssh_channel channel),
|
||||||
|
void *userdata)
|
||||||
|
{
|
||||||
struct event_fd_data_struct *event_fd_data = (struct event_fd_data_struct *)userdata;
|
struct event_fd_data_struct *event_fd_data = (struct event_fd_data_struct *)userdata;
|
||||||
(void)session;
|
|
||||||
|
|
||||||
_ssh_log(SSH_LOG_PROTOCOL,
|
_ssh_log(SSH_LOG_PROTOCOL,
|
||||||
"=== my_channel_close_function",
|
"=== my_channel_close_function",
|
||||||
@ -240,9 +276,12 @@ static void my_channel_close_function(ssh_session session, ssh_channel channel,
|
|||||||
stack_socket_close(session, event_fd_data);
|
stack_socket_close(session, event_fd_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void my_channel_eof_function(ssh_session session, ssh_channel channel, void *userdata) {
|
static void
|
||||||
|
my_channel_eof_function(ssh_session session,
|
||||||
|
UNUSED_PARAM(ssh_channel channel),
|
||||||
|
void *userdata)
|
||||||
|
{
|
||||||
struct event_fd_data_struct *event_fd_data = (struct event_fd_data_struct *)userdata;
|
struct event_fd_data_struct *event_fd_data = (struct event_fd_data_struct *)userdata;
|
||||||
(void)session;
|
|
||||||
|
|
||||||
_ssh_log(SSH_LOG_PROTOCOL,
|
_ssh_log(SSH_LOG_PROTOCOL,
|
||||||
"=== my_channel_eof_function",
|
"=== my_channel_eof_function",
|
||||||
@ -252,9 +291,13 @@ static void my_channel_eof_function(ssh_session session, ssh_channel channel, vo
|
|||||||
stack_socket_close(session, event_fd_data);
|
stack_socket_close(session, event_fd_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void my_channel_exit_status_function(ssh_session session, ssh_channel channel, int exit_status, void *userdata) {
|
static void
|
||||||
|
my_channel_exit_status_function(UNUSED_PARAM(ssh_session session),
|
||||||
|
UNUSED_PARAM(ssh_channel channel),
|
||||||
|
int exit_status,
|
||||||
|
void *userdata)
|
||||||
|
{
|
||||||
struct event_fd_data_struct *event_fd_data = (struct event_fd_data_struct *)userdata;
|
struct event_fd_data_struct *event_fd_data = (struct event_fd_data_struct *)userdata;
|
||||||
(void)session;
|
|
||||||
|
|
||||||
_ssh_log(SSH_LOG_PROTOCOL,
|
_ssh_log(SSH_LOG_PROTOCOL,
|
||||||
"=== my_channel_exit_status_function",
|
"=== my_channel_exit_status_function",
|
||||||
@ -262,12 +305,13 @@ static void my_channel_exit_status_function(ssh_session session, ssh_channel cha
|
|||||||
exit_status, *event_fd_data->p_fd);
|
exit_status, *event_fd_data->p_fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int my_channel_data_function(ssh_session session,
|
static int
|
||||||
ssh_channel channel,
|
my_channel_data_function(ssh_session session,
|
||||||
void *data,
|
UNUSED_PARAM(ssh_channel channel),
|
||||||
uint32_t len,
|
void *data,
|
||||||
UNUSED_PARAM(int is_stderr),
|
uint32_t len,
|
||||||
void *userdata)
|
UNUSED_PARAM(int is_stderr),
|
||||||
|
void *userdata)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
struct event_fd_data_struct *event_fd_data = (struct event_fd_data_struct *)userdata;
|
struct event_fd_data_struct *event_fd_data = (struct event_fd_data_struct *)userdata;
|
||||||
@ -285,7 +329,9 @@ static int my_channel_data_function(ssh_session session,
|
|||||||
i = send(*event_fd_data->p_fd, data, len, 0);
|
i = send(*event_fd_data->p_fd, data, len, 0);
|
||||||
}
|
}
|
||||||
if (i < 0) {
|
if (i < 0) {
|
||||||
_ssh_log(SSH_LOG_WARNING, "=== my_channel_data_function", "Writing to tcp socket %d: %s", *event_fd_data->p_fd, strerror(errno));
|
_ssh_log(SSH_LOG_WARNING, "=== my_channel_data_function",
|
||||||
|
"Writing to tcp socket %d: %s", *event_fd_data->p_fd,
|
||||||
|
strerror(errno));
|
||||||
stack_socket_close(session, event_fd_data);
|
stack_socket_close(session, event_fd_data);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -294,9 +340,10 @@ static int my_channel_data_function(ssh_session session,
|
|||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int my_fd_data_function(UNUSED_PARAM(socket_t fd),
|
static int
|
||||||
int revents,
|
my_fd_data_function(UNUSED_PARAM(socket_t fd),
|
||||||
void *userdata)
|
int revents,
|
||||||
|
void *userdata)
|
||||||
{
|
{
|
||||||
struct event_fd_data_struct *event_fd_data = (struct event_fd_data_struct *)userdata;
|
struct event_fd_data_struct *event_fd_data = (struct event_fd_data_struct *)userdata;
|
||||||
ssh_channel channel = event_fd_data->channel;
|
ssh_channel channel = event_fd_data->channel;
|
||||||
@ -389,7 +436,9 @@ static int my_fd_data_function(UNUSED_PARAM(socket_t fd),
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int open_tcp_socket(ssh_message msg) {
|
static int
|
||||||
|
open_tcp_socket(ssh_message msg)
|
||||||
|
{
|
||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
int forwardsock = -1;
|
int forwardsock = -1;
|
||||||
struct hostent *host;
|
struct hostent *host;
|
||||||
@ -430,17 +479,20 @@ static int open_tcp_socket(ssh_message msg) {
|
|||||||
return forwardsock;
|
return forwardsock;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int message_callback(ssh_session session, ssh_message message, void *userdata) {
|
static int
|
||||||
|
message_callback(UNUSED_PARAM(ssh_session session),
|
||||||
|
ssh_message message,
|
||||||
|
UNUSED_PARAM(void *userdata))
|
||||||
|
{
|
||||||
ssh_channel channel;
|
ssh_channel channel;
|
||||||
int socket_fd, *pFd;
|
int socket_fd, *pFd;
|
||||||
struct ssh_channel_callbacks_struct *cb_chan;
|
struct ssh_channel_callbacks_struct *cb_chan;
|
||||||
struct event_fd_data_struct *event_fd_data;
|
struct event_fd_data_struct *event_fd_data;
|
||||||
(void)session;
|
|
||||||
(void)message;
|
|
||||||
(void)userdata;
|
|
||||||
|
|
||||||
_ssh_log(SSH_LOG_PACKET, "=== message_callback", "Message type: %d", ssh_message_type(message));
|
_ssh_log(SSH_LOG_PACKET, "=== message_callback", "Message type: %d",
|
||||||
_ssh_log(SSH_LOG_PACKET, "=== message_callback", "Message Subtype: %d", ssh_message_subtype(message));
|
ssh_message_type(message));
|
||||||
|
_ssh_log(SSH_LOG_PACKET, "=== message_callback", "Message Subtype: %d",
|
||||||
|
ssh_message_subtype(message));
|
||||||
if (ssh_message_type(message) == SSH_REQUEST_CHANNEL_OPEN) {
|
if (ssh_message_type(message) == SSH_REQUEST_CHANNEL_OPEN) {
|
||||||
_ssh_log(SSH_LOG_PROTOCOL, "=== message_callback", "channel_request_open");
|
_ssh_log(SSH_LOG_PROTOCOL, "=== message_callback", "channel_request_open");
|
||||||
|
|
||||||
@ -544,7 +596,9 @@ static struct argp_option options[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* Parse a single option. */
|
/* Parse a single option. */
|
||||||
static error_t parse_opt (int key, char *arg, struct argp_state *state) {
|
static error_t
|
||||||
|
parse_opt (int key, char *arg, struct argp_state *state)
|
||||||
|
{
|
||||||
/* Get the input argument from argp_parse, which we
|
/* Get the input argument from argp_parse, which we
|
||||||
* know is a pointer to our arguments structure.
|
* know is a pointer to our arguments structure.
|
||||||
*/
|
*/
|
||||||
@ -590,7 +644,9 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state) {
|
|||||||
static struct argp argp = {options, parse_opt, args_doc, doc, NULL, NULL, NULL};
|
static struct argp argp = {options, parse_opt, args_doc, doc, NULL, NULL, NULL};
|
||||||
#endif /* HAVE_ARGP_H */
|
#endif /* HAVE_ARGP_H */
|
||||||
|
|
||||||
int main(int argc, char **argv){
|
int
|
||||||
|
main(int argc, char **argv)
|
||||||
|
{
|
||||||
ssh_session session;
|
ssh_session session;
|
||||||
ssh_bind sshbind;
|
ssh_bind sshbind;
|
||||||
struct ssh_server_callbacks_struct cb = {
|
struct ssh_server_callbacks_struct cb = {
|
||||||
|
Reference in New Issue
Block a user