Boolean ssh_server_update_transport_params(SshConfig config, SshTransportParams params) { char *hlp; if (config->ciphers != NULL) { hlp = ssh_cipher_list_canonialize(config->ciphers); if (hlp) { ssh_xfree(params->ciphers_c_to_s); params->ciphers_c_to_s = ssh_xstrdup(hlp); ssh_xfree(params->ciphers_s_to_c); params->ciphers_s_to_c = ssh_xstrdup(hlp); ssh_xfree(hlp); } } hlp = ssh_public_key_list_canonialize(params->host_key_algorithms); ssh_xfree(params->host_key_algorithms); params->host_key_algorithms = hlp; hlp = ssh_hash_list_canonialize(params->hash_algorithms); ssh_xfree(params->hash_algorithms); params->hash_algorithms = hlp; return TRUE; }
void ssh_local_destroy_listener(SshLocalListener listener) { ssh_io_unregister_fd(listener->sock, FALSE); close(listener->sock); ssh_xfree(listener->path); ssh_xfree(listener); }
static Boolean authentication_handler(SshHttpServerContext ctx, SshHttpServerConnection conn, SshStream stream, void *context) { SshHttpAuthentication auth; char *name; char *password; auth = ssh_http_server_get_proxy_authentication(conn, &name, &password); switch (auth) { case SSH_HTTP_AUTHENTICATION_NONE: break; case SSH_HTTP_AUTHENTICATION_BASIC: fprintf(stderr, "%s: authentication: name=%s, password=%s\n", program, name, password); ssh_xfree(name); ssh_xfree(password); /* Allow access. */ return FALSE; break; } /* Deny access. */ ssh_http_server_error_proxy_authentication_required(conn, "WWW Proxy"); ssh_stream_destroy(stream); return TRUE; }
void ssh_channel_dtcp_destroy(void *context) { SshChannelTypeTcpDirect ct = (SshChannelTypeTcpDirect)context; SshLocalTcpForward local_fwd, local_next; /* Destroy all existing channels. XXX not implemented. */ /* Free local forwarding records. */ for (local_fwd = ct->local_forwards; local_fwd; local_fwd = local_next) { local_next = local_fwd->next; if (local_fwd->listener) ssh_tcp_destroy_listener(local_fwd->listener); ssh_xfree(local_fwd->connect_to_host); ssh_xfree(local_fwd->connect_to_port); memset(local_fwd, 'F', sizeof(*local_fwd)); ssh_xfree(local_fwd); } /* Destroy the channel type context. */ memset(ct, 'F', sizeof(*ct)); ssh_xfree(ct); }
void ssh_channel_ftcp_open_connected(SshIpError error, SshStream stream, void *context) { SshChannelTcpFwdConnect c = (SshChannelTcpFwdConnect)context; if (error != SSH_IP_OK) { ssh_warning("Connecting to %s:%s failed (remote forward, port %s)", c->fwd->connect_to_host, c->fwd->connect_to_port, c->fwd->port); (*c->completion)(SSH_OPEN_CONNECT_FAILED, NULL, FALSE, FALSE, 0, NULL, 0, NULL, NULL, NULL, c->completion_context); memset(c, 'F', sizeof(*c)); ssh_xfree(c); return; } /* Record that we now have a new channel. */ ssh_common_new_channel(c->fwd->common); /* Call the completion procedure to indicate that we are done. */ (*c->completion)(SSH_OPEN_OK, stream, TRUE, TRUE, SSH_TCPIP_WINDOW, NULL, 0, NULL, ssh_channel_tcp_connection_destroy, (void *)c->fwd->common, c->completion_context); memset(c, 'F', sizeof(*c)); ssh_xfree(c); }
void ssh_channel_dtcp_connected(SshIpError error, SshStream stream, void *context) { SshDirectTcp tcp = (SshDirectTcp)context; SSH_DEBUG(5, ("direct connected: %d", (int)error)); /* Check result. */ if (error != SSH_IP_OK) { /* Connection failed. */ (*tcp->completion)(SSH_OPEN_CONNECT_FAILED, NULL, FALSE, FALSE, 0, NULL, 0, NULL, NULL, NULL, tcp->completion_context); memset(tcp, 'F', sizeof(*tcp)); ssh_xfree(tcp); return; } /* Record that we have a new channel. */ ssh_common_new_channel(tcp->common); /* Connection was successful. Establish the channel. */ (*tcp->completion)(SSH_OPEN_OK, stream, TRUE, TRUE, SSH_TCPIP_WINDOW, NULL, 0, NULL, ssh_channel_tcp_connection_destroy, (void *)tcp->common, tcp->completion_context); memset(tcp, 'F', sizeof(*tcp)); ssh_xfree(tcp); }
static Boolean hex_string_to_data(char *str, unsigned char **data, size_t *data_len) { size_t str_len, buf_len; unsigned char *buf; int i, ch, cl; str_len = strlen(str); if ((str_len == 0) || ((str_len % 2) != 0)) return FALSE; buf_len = str_len / 2; buf = ssh_xmalloc(buf_len); for (i = 0; i < buf_len; i++) { ch = hex_char_to_int(str[i * 2]); cl = hex_char_to_int(str[(i * 2) + 1]); if ((ch >= 0) && (cl >= 0)) { buf[i] = (unsigned char)(ch * 16 + cl); } else { ssh_xfree(buf); return FALSE; } } if (data) *data = buf; else ssh_xfree(buf); if (data_len) *data_len = buf_len; return TRUE; }
void ssh_channel_open_ssh1_agent_connected(SshStream stream, void *context) { SshAgentConnection a = (SshAgentConnection)context; SshBuffer buffer; unsigned char *cp; if (stream == NULL) { SSH_DEBUG(1, ("Connecting to the real agent failed.")); (*a->completion)(SSH_OPEN_CONNECT_FAILED, NULL, FALSE, FALSE, 0, NULL, 0, NULL, NULL, NULL, a->context); ssh_xfree(a); return; } SSH_DEBUG(5, ("connection to real agent established")); /* Increment the number of channels. */ ssh_common_new_channel(a->common); if (a->common->config->ssh_agent_compat == SSH_AGENT_COMPAT_SSH2) { /* We are required to send a FORWARDING_NOTIFY to the agent to inform it that the connection is actually forwarded. Format that packet now. */ ssh_buffer_init(&buffer); ssh_encode_buffer(&buffer, SSH_FORMAT_DATA, "1234", (size_t)4, SSH_FORMAT_CHAR, (unsigned int) SSH_AGENT_FORWARDING_NOTICE, SSH_FORMAT_UINT32_STR, a->common->server_host_name, strlen(a->common->server_host_name), SSH_FORMAT_UINT32_STR, a->common->remote_ip, strlen(a->common->remote_ip), SSH_FORMAT_UINT32, (SshUInt32) atol(a->common->remote_port), SSH_FORMAT_END); cp = ssh_buffer_ptr(&buffer); SSH_PUT_32BIT(cp, ssh_buffer_len(&buffer) - 4); /* Write the buffer to the channel. This is a kludge; this assumes that we can always write this much to the internal buffers. */ if (ssh_stream_write(stream, ssh_buffer_ptr(&buffer), ssh_buffer_len(&buffer)) != ssh_buffer_len(&buffer)) ssh_fatal("ssh_channel_open_agent_connected: kludge failed"); ssh_buffer_uninit(&buffer); } /* Create the channel. */ (*a->completion)(SSH_OPEN_OK, stream, TRUE, TRUE, AGENT_WINDOW_SIZE, NULL, 0, NULL, ssh_channel_ssh1_agent_connection_destroy, (void *)a->common, a->context); ssh_xfree(a); }
void ssh_mutex_destroy(SshMutex mutex) { if (mutex->locked) ssh_fatal("Tried to destroy locked mutex %s", mutex->name); DeleteCriticalSection(&mutex->critical); if (mutex->name) ssh_xfree(mutex->name); ssh_xfree(mutex); }
Boolean ssh_channel_tcp_forward_cancel(const char *type, const unsigned char *data, size_t len, void *context) { SshCommon common = (SshCommon)context; char *address_to_bind; SshUInt32 port; char port_string[20]; SshRemoteTcpForward fwd, *fwdp; SshChannelTypeTcpForward ct; SSH_DEBUG(5, ("remote TCP/IP cancel request received")); ct = ssh_channel_ftcp_ct(common); /* Don't allow a server to send remote forwarding requests to the client. */ if (common->client) { ssh_warning("Remote TCP/IP forwarding cancel from server denied."); return FALSE; } /* Parse the request. */ if (ssh_decode_array(data, len, SSH_FORMAT_UINT32_STR, &address_to_bind, NULL, SSH_FORMAT_UINT32, &port, SSH_FORMAT_END) != len) { SSH_DEBUG(0, ("bad data")); return FALSE; } /* Convert port number to a string. */ snprintf(port_string, sizeof(port_string), "%ld", (unsigned long) port); for (fwdp = &ct->remote_forwards; *fwdp; fwdp = &fwd->next) { fwd = *fwdp; if (strcmp(port_string, fwd->port) == 0 && strcmp(address_to_bind, fwd->address_to_bind) == 0) { ssh_tcp_destroy_listener(fwd->listener); ssh_xfree(fwd->address_to_bind); ssh_xfree(fwd->port); *fwdp = fwd->next; ssh_xfree(fwd); ssh_xfree(address_to_bind); return TRUE; } } SSH_DEBUG(1, ("port %s address_to_bind %s not found", port_string, address_to_bind)); ssh_xfree(address_to_bind); return FALSE; }
void ssh_server_destroy(SshServer server) { /* Cancel grace timeout. */ ssh_cancel_timeouts(ssh_login_grace_time_exceeded, SSH_ALL_CONTEXTS); ssh_common_destroy(server->common); ssh_xfree(server->compat_flags); ssh_server_authentication_uninitialize(server->methods); memset(server, 'F', sizeof(*server)); ssh_xfree(server); }
void ssh_free_varsvals(int n, char **vars, char **vals) { int i; for (i = 0; i < n; i++) { ssh_xfree(vars[i]); ssh_xfree(vals[i]); } ssh_xfree(vars); ssh_xfree(vals); }
void ssh_transport_destroy_params(SshTransportParams params) { ssh_xfree(params->kex_algorithms); ssh_xfree(params->host_key_algorithms); ssh_xfree(params->hash_algorithms); ssh_xfree(params->compressions_c_to_s); ssh_xfree(params->compressions_s_to_c); ssh_xfree(params->ciphers_c_to_s); ssh_xfree(params->ciphers_s_to_c); ssh_xfree(params->macs_c_to_s); ssh_xfree(params->macs_s_to_c); ssh_xfree(params); }
Boolean ssh_user_free(SshUser uc, Boolean undo) { /* XXX undoing kerberos / secure rpc state. */ ssh_xfree(uc->name); ssh_xfree(uc->dir); ssh_xfree(uc->shell); if (uc->correct_encrypted_passwd) ssh_xfree(uc->correct_encrypted_passwd); memset(uc, 'F', sizeof(*uc)); ssh_xfree(uc); return TRUE; }
static void free_virtual_adapter_op(SshInterceptor interceptor, SshInterceptorVirtualAdapterOp op) { SshInterceptorVirtualAdapterOp op_ptr, prev; ssh_mutex_lock(interceptor->mutex); /* Remove the operation from the list of pending operations. */ for (prev = NULL, op_ptr = interceptor->virtual_adapter_operations; op_ptr && op_ptr != op; prev = op_ptr, op_ptr = op_ptr->next) ; if (op_ptr != NULL) { if (prev) prev->next = op_ptr->next; else interceptor->virtual_adapter_operations = op_ptr->next; } ssh_mutex_unlock(interceptor->mutex); ssh_xfree(op); }
void test_functions(int foo, ...) { va_list va; unsigned char *cp; ssh_buffer_clear(buffer); ssh_buffer_clear(buffer); va_start(va, foo); if (ssh_encode_buffer_va(buffer, va) != 2) ssh_fatal("test_functions: ssh_encode_buffer_va error"); va_end(va); if (memcmp(ssh_buffer_ptr(buffer), "\100\103", 2) != 0) ssh_fatal("test_functions: ssh_encode_buffer_va data error"); va_start(va, foo); if (ssh_encode_array_alloc_va(NULL, va) != 2) ssh_fatal("test_function: ssh_encode_array_alloc_va NULL error"); va_end(va); va_start(va, foo); if (ssh_encode_array_alloc_va(&cp, va) != 2) ssh_fatal("test_functions: ssh_encode_array_alloc_va error"); va_end(va); if (memcmp(cp, "\100\103", 2) != 0) ssh_fatal("test_functions: ssh_encode_array_alloc_va data error"); ssh_xfree(cp); }
void ssh_virtual_adapter_detach_all(SshInterceptor interceptor) { ssh_mutex_lock(interceptor->mutex); /* Remove all active virtual adapters. */ while (interceptor->virtual_adapters) { SshInterceptorVirtualAdapter va; va = interceptor->virtual_adapters; interceptor->virtual_adapters = va->next; /* Call destruction callback */ if (va->detach_cb) (*va->detach_cb)(va->adapter_context); ssh_xfree(va); } ssh_mutex_unlock(interceptor->mutex); SSH_DEBUG(SSH_D_NICETOKNOW, ("sending detach all request to forwarder.")); /* Send a message to the engine. */ ssh_usermode_interceptor_send_encode( interceptor, SSH_ENGINE_IPM_FORWARDER_VIRTUAL_ADAPTER_DETACH_ALL, SSH_FORMAT_END); }
static void test_ek_add(SshExternalKeyTestCtx ctx) { SshExternalKey externalkey; SshUInt32 num_providers; int i; SshEkProvider provider_array; const char *accelerator_name = NULL; const char *short_name; externalkey = ssh_ek_allocate(); ctx->externalkey = externalkey; /* Register authentication and notify callbacks. */ ssh_ek_register_notify(externalkey, ssh_externalkey_notify_cb, ctx); ssh_ek_register_authentication_callback(externalkey, ssh_externalkey_authentication_cb, ctx); ssh_ek_add_provider(externalkey, "soft-accelerator", accelerator_init_str, NULL, SSH_EK_PROVIDER_FLAG_KEY_ACCELERATOR, NULL); /* Get the information about installed providers. */ ssh_ek_get_providers(externalkey, &provider_array, &num_providers); /* get all know providers. */ for (i = 0; i < num_providers; i++) { short_name = (provider_array[i]).short_name; /* Test if we have accelerators. */ if ((provider_array[i]).provider_flags & SSH_EK_PROVIDER_FLAG_KEY_ACCELERATOR) accelerator_name = short_name; } ssh_xfree(provider_array); if (accelerator_name) { /* Try_Number to get an accelerated key from an crypto accelerator. */ ssh_ek_generate_accelerated_public_key(externalkey, accelerator_name, ctx->pub_key, get_accelerated_pub_key_cb, ctx); ssh_ek_generate_accelerated_private_key(externalkey, accelerator_name, ctx->prv_key, get_acc_prv_key_cb, ctx); } }
void ssh_channel_ssh1_agent_session_destroy(void *session_placeholder) { SshChannelSsh1AgentSession session = (SshChannelSsh1AgentSession)session_placeholder; /* Free the session context. */ ssh_xfree(session); }
Boolean ssh_channel_start_local_tcp_forward(SshCommon common, const char *address_to_bind, const char *port, const char *connect_to_host, const char *connect_to_port) { SshLocalTcpForward fwd; SshChannelTypeTcpDirect ct; long portnumber; SshUser user; SSH_DEBUG(5, ("requesting local forwarding for port %s to %s:%s", port, connect_to_host, connect_to_port)); portnumber = atol(port); user = ssh_user_initialize(NULL, FALSE); /* If user is not logged in as a privileged user, don't allow forwarding of privileged ports. */ if (portnumber < 1024) { if (ssh_user_uid(user)) { ssh_warning("Tried to forward " \ "privileged port %d as an ordinary user.", portnumber); return FALSE; } } if (portnumber >= 65536) { ssh_warning("Tried to forward " \ "port above 65535 (%d).", portnumber); return FALSE; } ct = ssh_channel_dtcp_ct(common); fwd = ssh_xcalloc(1, sizeof(*fwd)); fwd->common = common; fwd->listener = ssh_tcp_make_listener(address_to_bind, port, ssh_channel_dtcp_incoming_connection, (void *)fwd); if (!fwd->listener) { SSH_DEBUG(5, ("creating listener failed")); ssh_xfree(fwd); return FALSE; } fwd->port = ssh_xstrdup(port); fwd->connect_to_host = ssh_xstrdup(connect_to_host); fwd->connect_to_port = ssh_xstrdup(connect_to_port); fwd->next = ct->local_forwards; ct->local_forwards = fwd; return TRUE; }
void close_display() { XFreeModifiermap(modifiers); XUnloadFont(display, font); ssh_xfree(led_state); XCloseDisplay(display); }
void wrapper_va_receive(void *context) { SshReceiveVaContext ctx = (SshReceiveVaContext) context; const unsigned char *data = ctx->data; size_t len = ctx->len; SshInterceptor interceptor = ssh_usermode_interceptor; SSH_ASSERT_THREAD(); switch (ctx->type) { case SSH_ENGINE_IPM_FORWARDER_VIRTUAL_ADAPTER_STATUS_CB: receive_virtual_adapter_status_cb(interceptor, data, len); break; case SSH_ENGINE_IPM_FORWARDER_VIRTUAL_ADAPTER_PACKET_CB: receive_virtual_adapter_packet_cb(interceptor, data, len); break; default: SSH_DEBUG(SSH_D_ERROR, ("unknown packet type %d from kernel", (int) ctx->type)); break; } ssh_xfree(ctx); }
void ssh_buffer_free(SshBuffer *buffer) { SSH_ASSERT(buffer); if (!buffer->dynamic) ssh_fatal("ssh_buffer_free given a buffer which was not dynamically allocated."); ssh_buffer_uninit(buffer); ssh_xfree(buffer); }
void print_int(char *str, SshInt *op) { char *mstr; mstr = ssh_mp_get_str(NULL, 10, op); printf("%s %s\n", str, mstr); ssh_xfree(mstr); }
void update_algs(SshTransportParams params, const char *algs) { char *copy; char *cp, **dest; int i; if (algs == NULL) return; copy = ssh_xstrdup(algs); for (i = 0, cp = strtok(copy, ":"); cp; i++, cp = strtok(NULL, ":")) { switch (i) { case 0: /* c_to_s_cipher */ dest = ¶ms->ciphers_c_to_s; break; case 1: /* s_to_c_cipher */ dest = ¶ms->ciphers_s_to_c; break; case 2: /* c_to_s_mac */ dest = ¶ms->macs_c_to_s; break; case 3: /* s_to_c_mac */ dest = ¶ms->macs_s_to_c; break; case 4: /* c_to_s_compression */ dest = ¶ms->compressions_c_to_s; break; case 5: /* s_to_c_compression */ dest = ¶ms->compressions_s_to_c; break; default: dest = NULL; /* to avoid compiler warning... */ ssh_fatal("too many algorithms: %s", cp); } #ifdef DEBUG ssh_debug("alg: %s\n", cp); #endif if (*dest) ssh_xfree(*dest); *dest = ssh_xstrdup(cp); } ssh_xfree(copy); }
void signer_free_context(SshSigner signer) { static Boolean destroyed = FALSE; if (destroyed) return; destroyed = TRUE; SSH_DEBUG(3, ("Destroying SshSigner-struct...")); ssh_packet_wrapper_destroy(signer->wrapper); ssh_xfree(signer->packet_payload); ssh_random_free(signer->random_state); ssh_config_free(signer->config); ssh_user_free(signer->effective_user_data, FALSE); ssh_xfree(signer); SSH_DEBUG(3, ("done.")); }
void store_delimited_strings(SshBuffer *packet, const char *arg) { char *copy, *part; copy = ssh_xstrdup(arg); for (part = strtok(copy, ":"); part; part = strtok(NULL, ":")) buffer_put_uint32_string(packet, part, strlen(part)); ssh_xfree(copy); }
Boolean ssh2_key_blob_encode(unsigned long magic, const char *subject, const char *comment, const unsigned char *key, size_t keylen, unsigned char **encoded, size_t *encoded_len) { SshBufferStruct buffer; char *base64; unsigned int key_index; /* Translate to index. */ switch (magic) { case SSH_KEY_MAGIC_PUBLIC: key_index = 0; break; case SSH_KEY_MAGIC_PRIVATE: key_index = 1; break; case SSH_KEY_MAGIC_PRIVATE_ENCRYPTED: key_index = 2; break; default: return FALSE; } ssh_buffer_init(&buffer); /* Add the head for the key. */ ssh_key_blob_dump_line_str(&buffer, ssh2_pk_format_name_list[key_index].head); ssh_key_blob_dump_lf(&buffer); /* Handle key words. */ if (subject) { ssh_key_blob_dump_line_str(&buffer, "Subject: "); ssh_key_blob_dump_line_str(&buffer, subject); ssh_key_blob_dump_lf(&buffer); } if (comment) { ssh_key_blob_dump_line_str(&buffer, "Comment: "); ssh_key_blob_dump_quoted_str(&buffer, 9, comment); ssh_key_blob_dump_lf(&buffer); } /* Now add the base64 formatted stuff. */ base64 = (char *)ssh_buf_to_base64(key, keylen); ssh_key_blob_dump_str(&buffer, base64); ssh_key_blob_dump_lf(&buffer); ssh_xfree(base64); /* Add the tail for the key. */ ssh_key_blob_dump_line_str(&buffer, ssh2_pk_format_name_list[key_index].tail); ssh_key_blob_dump_lf(&buffer); *encoded_len = ssh_buffer_len(&buffer); *encoded = ssh_xmemdup(ssh_buffer_ptr(&buffer), ssh_buffer_len(&buffer)); ssh_buffer_uninit(&buffer); return TRUE; }
static void req_finish(void *context) { ProxyRequest *req = context; /* The ssh_copy_stream() destroys the streams. */ ssh_http_client_uninit(req->client); ssh_xfree(req); }
void copy_reader(SshStreamNotification op, void *context) { unsigned char *buf; int len; if (op != SSH_STREAM_INPUT_AVAILABLE) return; buf = ssh_xmalloc(T_STREAMPAIR_BIG_BUF_LEN); for (;;) { len = ssh_stream_read(ts2, buf, T_STREAMPAIR_BIG_BUF_LEN); if (len == 0) { ssh_stream_destroy(ts2); ts2 = NULL; destroy_count++; ssh_xfree(buf); return; /* EOF received */ } if (len < 0) { ssh_xfree(buf); return; } ssh_buffer_append(received_data, buf, len); if (break_test && ssh_rand() % 10 == 0) { ssh_stream_destroy(ts2); ts2 = NULL; destroy_count++; ssh_xfree(buf); return; } if (!reader_sent_eof && ssh_rand() % 10 == 0) { ssh_stream_output_eof(ts2); reader_sent_eof = TRUE; } } /*NOTREACHED*/ }