bool CPeerBase::Accept(socket_t fd_accept) { struct sockaddr_in peer; if ((m_fd = socket_accept(fd_accept, &peer)) == INVALID_SOCKET) { Destroy(); return false; } //socket_block(m_fd); socket_sndbuf(m_fd, 233016); socket_rcvbuf(m_fd, 233016); strlcpymt(m_host, inet_ntoa(peer.sin_addr), sizeof(m_host)); m_outBuffer = buffer_new(DEFAULT_PACKET_BUFFER_SIZE); m_inBuffer = buffer_new(MAX_INPUT_LEN); if (!m_outBuffer || !m_inBuffer) { Destroy(); return false; } fdwatch_add_fd(m_fdWatcher, m_fd, this, FDW_READ, false); OnAccept(); sys_log(0, "ACCEPT FROM %s", inet_ntoa(peer.sin_addr)); return true; }
connection *connection_new(enum connection_status status, int fd) { // Allocate memory connection *c = xmalloc(sizeof(connection)); // Get connection timestamp struct timeval connecttime; gettimeofday(&connecttime, NULL); // Fill in fields c->status = status; c->version = CONNECTION_VERSION_1_2; c->error = 0; c->fd = fd; c->inheartbeat = 0; c->outheartbeat = 0; c->readtime = connecttime; c->writetime = connecttime; c->inbuffer = buffer_new(4096); c->outbuffer = buffer_new(4096); c->frameparser = frameparser_new(); c->frameserializer = frameserializer_new(); return c; }
int main(int argc, char **argv, const char *ZEBRA_VTYSH_PATH) { struct buffer *b1, *b2; int n; char junk[3]; char c = 'a'; memory_init(); if ((argc != 2) || (sscanf(argv[1], "%d%1s", &n, junk) != 1)) { fprintf(stderr, "Usage: %s <number of chars to simulate>\n", *argv); return 1; } b1 = buffer_new(0); b2 = buffer_new(1024); while (n-- > 0) { buffer_put(b1, &c, 1); buffer_put(b2, &c, 1); if (c++ == 'z') c = 'a'; buffer_reset(b1); buffer_reset(b2); } buffer_free(b1); buffer_free(b2); return 0; }
TEST(Buffer, UTF8) { buffer * buf, * utf8; unsigned char* copy; size_t len; buf = buffer_new(1); buffer_append_string(buf, "诶"); EXPECT_EQ(buf->size, 5); EXPECT_EQ(buf->used, 3); len = buf->used; copy = (unsigned char*) malloc(len + 1); memcpy( copy, buf->data, len); copy[len] = '\0'; buffer_destroy(buf); buf = buffer_new(len); buffer_append_data(buf, copy, len); utf8 = buffer_to_buffer_utf8(buf); buffer_destroy(buf); EXPECT_EQ(utf8->used, len * 2); buf = buffer_utf8_to_buffer(utf8); EXPECT_EQ(buf->used, len); EXPECT_TRUE(strcmp((char*)buf->data, (char*)copy) == 0); EXPECT_EQ(buf->size, 4); EXPECT_EQ(buf->used, 3); buffer_destroy(buf); buffer_destroy(utf8); free(copy); }
struct fast_session *fast_session_new(struct fast_session_cfg *cfg) { struct fast_session *self = calloc(1, sizeof *self); struct stat statbuf; if (!self) return NULL; self->rx_buffer = buffer_new(FAST_RECV_BUFFER_SIZE); if (!self->rx_buffer) { fast_session_free(self); return NULL; } self->tx_message_buffer = buffer_new(FAST_TX_BUFFER_SIZE); if (!self->tx_message_buffer) { fast_session_free(self); return NULL; } self->tx_pmap_buffer = buffer_new(FAST_TX_BUFFER_SIZE); if (!self->tx_pmap_buffer) { fast_session_free(self); return NULL; } self->rx_messages = fast_message_new(FAST_TEMPLATE_MAX_NUMBER); if (!self->rx_messages) { fast_session_free(self); return NULL; } if (cfg->preamble_bytes > FAST_PREAMBLE_MAX_BYTES) { fast_session_free(self); return NULL; } else self->preamble.nr_bytes = cfg->preamble_bytes; if (fstat(cfg->sockfd, &statbuf)) return NULL; if (!S_ISSOCK(statbuf.st_mode)) { self->send = xwritev0; self->recv = buffer_nread0; } else { self->send = sendmsg; self->recv = buffer_recv; } self->sockfd = cfg->sockfd; self->reset = cfg->reset; self->rx_message = NULL; self->last_tid = 0; self->nr_messages = 0; return self; }
tcp_connection_t* tcp_connection_new ( loop_t *loop, int fd, on_data_f datacb, on_close_f closecb, void* userdata, const inetaddr_t *peer_addr ) { tcp_connection_t *connection; struct sockaddr_in addr; socklen_t addr_len; struct linger linger_info; int flag; if (NULL == loop || fd < 0 || NULL == datacb || NULL == closecb || NULL == peer_addr) { log_error("tcp_connection_new: bad loop(%p) or bad fd(%d) or bad datacb(%p) or bad closecb(%p) or bad peer_addr(%p)", loop, fd, datacb, closecb, peer_addr); return NULL; } connection = (tcp_connection_t*)malloc(sizeof(*connection)); memset(connection, 0, sizeof(*connection)); flag = 1; setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &flag, sizeof(flag)); memset(&linger_info, 0, sizeof(linger_info)); linger_info.l_onoff = 1; linger_info.l_linger = 3; setsockopt(fd, SOL_SOCKET, SO_LINGER, &linger_info, sizeof(linger_info)); connection->loop = loop; connection->fd = fd; connection->datacb = datacb; connection->closecb = closecb; connection->userdata = userdata; connection->channel = channel_new(fd, loop, connection_onevent, connection); connection->in_buffer = buffer_new(4096); connection->out_buffer = buffer_new(4096); connection->is_in_callback = 0; connection->is_alive = 1; connection->is_connected = 1; connection->need_closed_after_sent_done = 0; connection->peer_addr = *peer_addr; memset(&addr, 0, sizeof(addr)); addr_len = sizeof(addr); getsockname(fd, (struct sockaddr*)&addr, &addr_len); inetaddr_init(&connection->local_addr, &addr); channel_setevent(connection->channel, EPOLLIN); return connection; }
/* Define procedures cadr, caddr, etc. */ static void define_pair_procedures(env_hashtable *env) { buffer *a = buffer_new(""), *b = buffer_new("x"); define_recursive(a, b, 0, env); buffer_free(a); buffer_free(b); }
VOID tunet_init() { main_socket_buffer = buffer_new(1024); keepalive_socket_buffer = buffer_new(1024); logout_socket_buffer = buffer_new(1024); thread_tunet = NULL; keepalive_timeout = os_tick_new(5 * 60 * 1000, FALSE); tunet_state = TUNET_STATE_NONE; }
bool DESC::Setup(LPFDWATCH _fdw, socket_t _fd, const struct sockaddr_in & c_rSockAddr, DWORD _handle, DWORD _handshake) { m_lpFdw = _fdw; m_sock = _fd; m_stHost = inet_ntoa(c_rSockAddr.sin_addr); m_wPort = c_rSockAddr.sin_port; m_dwHandle = _handle; //if (LC_IsEurope() == true || LC_IsNewCIBN()) // m_lpOutputBuffer = buffer_new(DEFAULT_PACKET_BUFFER_SIZE * 2); //else //NOTE: 이걸 나라별로 다르게 잡아야할 이유가 있나? m_lpOutputBuffer = buffer_new(DEFAULT_PACKET_BUFFER_SIZE * 2); m_iMinInputBufferLen = MAX_INPUT_LEN >> 1; m_lpInputBuffer = buffer_new(MAX_INPUT_LEN); m_SockAddr = c_rSockAddr; fdwatch_add_fd(m_lpFdw, m_sock, this, FDW_READ, false); // Ping Event desc_event_info* info = AllocEventInfo<desc_event_info>(); info->desc = this; assert(m_pkPingEvent == NULL); m_pkPingEvent = event_create(ping_event, info, ping_event_second_cycle); #ifndef _IMPROVED_PACKET_ENCRYPTION_ if (LC_IsEurope()) { thecore_memcpy(m_adwEncryptionKey, "1234abcd5678efgh", sizeof(DWORD) * 4); thecore_memcpy(m_adwDecryptionKey, "1234abcd5678efgh", sizeof(DWORD) * 4); } else { thecore_memcpy(m_adwEncryptionKey, "testtesttesttest", sizeof(DWORD) * 4); thecore_memcpy(m_adwDecryptionKey, "testtesttesttest", sizeof(DWORD) * 4); } #endif // _IMPROVED_PACKET_ENCRYPTION_ // Set Phase to handshake SetPhase(PHASE_HANDSHAKE); StartHandshake(_handshake); sys_log(0, "SYSTEM: new connection from [%s] fd: %d handshake %u output input_len %d, ptr %p", m_stHost.c_str(), m_sock, m_dwHandshake, buffer_size(m_lpInputBuffer), this); Log("SYSTEM: new connection from [%s] fd: %d handshake %u ptr %p", m_stHost.c_str(), m_sock, m_dwHandshake, this); return true; }
void ape_array_add_n(ape_array_t *array, const char *key, int klen, const char *value, int vlen) { buffer *k, *v; k = buffer_new(klen+1); v = buffer_new(vlen+1); buffer_append_string_n(k, key, klen); buffer_append_string_n(v, value, vlen); ape_array_add_b(array, k, v); }
Buffer *pcp_keyblob(void *k, int type) { if(type == PCP_KEY_TYPE_PUBLIC) { Buffer *b = buffer_new(PCP_RAW_PUBKEYSIZE, "bp"); pcp_pubkeyblob(b, (pcp_pubkey_t *)k); return b; } else { Buffer *b = buffer_new(PCP_RAW_KEYSIZE, "bs"); pcp_seckeyblob(b, (pcp_key_t *)k); return b; } }
CcnetPacketIO* ccnet_packet_io_new (evutil_socket_t fd) { CcnetPacketIO *io; io = g_malloc (sizeof(CcnetPacketIO)); io->fd = fd; io->buffer = buffer_new (); io->in_buf = buffer_new (); return io; }
int handle_connect_addr(struct ludis_handle *h, const struct net_addr addr) { int fd; if ((fd = fd_connect_addr(addr)) < 0) return fd; h->fd = fd; h->rb = buffer_new(0); h->wb = buffer_new(0); return LUDIS_OK; }
int handle_connect_gai(struct ludis_handle *h, int family, const char *host, int port, struct net_addr *addr) { int fd; if ((fd = fd_connect_gai(family, host, port, addr)) < 0) return fd; h->fd = fd; h->rb = buffer_new(0); h->wb = buffer_new(0); return LUDIS_OK; }
BUFFER *buffer_append(BUFFER *buf, BYTE *newdata, INT len) { BYTE *p; INT newlen; if (len <= 0) return buf; if (!buf) buf = buffer_new(len); if (len + buf->len > buf->allocated_len) { newlen = (len + buf->len) * 3 / 2 + 1; p = (BYTE *)os_new(CHAR, newlen); buf->allocated_len = newlen; memcpy(p, buf->data, buf->len); } else { p = buf->data; } memcpy(p + buf->len, newdata, len); if (buf->data != p) { os_free(buf->data); buf->data = p; } buf->len += len; return buf; }
BUFFER *buffer_clear(BUFFER *buf) { if(!buf)return buffer_new(4096); buf->len = 0; memset(buf->data, 0, buf->allocated_len); return buf; }
/* this is a public key in openssh's format */ static STRING *make_rsa1_string(STRING *e, STRING *n){ BUFFER *buffer = NULL; STRING *rsa = NULL; STRING *ret = NULL; buffer = buffer_new(); rsa = string_from_char("ssh-rsa1"); if (buffer_add_ssh_string(buffer, rsa) < 0) { goto error; } if (buffer_add_ssh_string(buffer, e) < 0) { goto error; } if (buffer_add_ssh_string(buffer, n) < 0) { goto error; } ret = string_new(buffer_get_len(buffer)); if (ret == NULL) { goto error; } string_fill(ret, buffer_get(buffer), buffer_get_len(buffer)); error: buffer_free(buffer); string_free(rsa); return ret; }
void test_boe_replay_complete(void) { struct boe_message *msg = (void *) recv_buffer; struct buffer *buf; int fd; buf = buffer_new(1024); fd = open(DATA_PATH "replay-complete-message.bin", O_RDONLY); fail_if(fd < 0); fail_if(buffer_xread(buf, fd) < 0); fail_if(boe_message_decode(buf, msg, BOE_MAX_MESSAGE_LEN) < 0); assert_int_equals(BOE_MAGIC, msg->header.StartOfMessage); assert_int_equals(8, msg->header.MessageLength); assert_int_equals(ReplayComplete, msg->header.MessageType); assert_int_equals(0, msg->header.MatchingUnit); assert_int_equals(0, msg->header.SequenceNumber); buffer_delete(buf); fail_if(close(fd) < 0); }
static buffer_t * buffer_new_read(const void *data, zip_uint64_t length, int free_data) { buffer_t *buffer; if ((buffer = buffer_new(length)) == NULL) { return NULL; } buffer->size = length; if (length > 0) { if ((buffer->fragments = malloc(sizeof(*(buffer->fragments)))) == NULL) { buffer_free(buffer); return NULL; } buffer->fragments_capacity = 1; buffer->nfragments = 1; buffer->fragments[0] = (zip_uint8_t *)data; buffer->free_data = free_data; } return buffer; }
/** * @brief Request a subsystem (for example "sftp"). * * @param channel The channel to send the request. * * @param system The subsystem to request (for example "sftp"). * * @return SSH_SUCCESS on success, SSH_ERROR on error. * * @warning You normally don't have to call it for sftp, see sftp_new(). */ int channel_request_subsystem(CHANNEL *channel, const char *sys) { BUFFER *buffer = NULL; STRING *subsystem = NULL; int rc = SSH_ERROR; buffer = buffer_new(); if (buffer == NULL) { goto error; } subsystem = string_from_char(sys); if (subsystem == NULL) { goto error; } if (buffer_add_ssh_string(buffer, subsystem) < 0) { goto error; } rc = channel_request(channel, "subsystem", buffer, 1); error: buffer_free(buffer); string_free(subsystem); return rc; }
/** * @brief Change the size of the terminal associated to a channel. * * @param channel The channel to change the size. * * @param cols The new number of columns. * * @param rows The new number of rows. * * @warning Do not call it from a signal handler if you are not * sure any other libssh function using the same channel/session * is running at same time (not 100% threadsafe). */ int channel_change_pty_size(CHANNEL *channel, int cols, int rows) { SSH_SESSION *session = channel->session; BUFFER *buffer = NULL; int rc = SSH_ERROR; enter_function(); #ifdef HAVE_SSH1 if (channel->version == 1) { rc = channel_change_pty_size1(channel,cols,rows); leave_function(); return rc; } #endif buffer = buffer_new(); if (buffer == NULL) { goto error; } if (buffer_add_u32(buffer, htonl(cols)) < 0 || buffer_add_u32(buffer, htonl(rows)) < 0 || buffer_add_u32(buffer, 0) < 0 || buffer_add_u32(buffer, 0) < 0) { goto error; } rc = channel_request(channel, "window-change", buffer, 0); error: buffer_free(buffer); leave_function(); return rc; }
static PyObject* _cbson_get_more_message(PyObject* self, PyObject* args) { /* NOTE just using a random number as the request_id */ int request_id = rand(); char* collection_name = NULL; int collection_name_length; int num_to_return; long long cursor_id; buffer_t buffer; int length_location, message_length; PyObject* result; if (!PyArg_ParseTuple(args, "et#iL", "utf-8", &collection_name, &collection_name_length, &num_to_return, &cursor_id)) { return NULL; } buffer = buffer_new(); if (!buffer) { PyErr_NoMemory(); PyMem_Free(collection_name); return NULL; } // save space for message length length_location = buffer_save_space(buffer, 4); if (length_location == -1) { PyMem_Free(collection_name); PyErr_NoMemory(); return NULL; } if (!buffer_write_bytes(buffer, (const char*)&request_id, 4) || !buffer_write_bytes(buffer, "\x00\x00\x00\x00" "\xd5\x07\x00\x00" "\x00\x00\x00\x00", 12) || !buffer_write_bytes(buffer, collection_name, collection_name_length + 1) || !buffer_write_bytes(buffer, (const char*)&num_to_return, 4) || !buffer_write_bytes(buffer, (const char*)&cursor_id, 8)) { buffer_free(buffer); PyMem_Free(collection_name); return NULL; } PyMem_Free(collection_name); message_length = buffer_get_position(buffer) - length_location; memcpy(buffer_get_buffer(buffer) + length_location, &message_length, 4); /* objectify buffer */ result = Py_BuildValue("i" BYTES_FORMAT_STRING, request_id, buffer_get_buffer(buffer), buffer_get_position(buffer)); buffer_free(buffer); return result; }
/** * prepare the blocks and map them * @param inode inode * @param page page pointer * @param from start offset within page * @param to last offset within page * @param get_block get_block funciton * @return return 0 on success, errno on failure */ int rfs_block_prepare_write(struct inode * inode, struct page * page, unsigned from, unsigned to, get_block_t *get_block) { struct buffer_head *bh, *head; unsigned long block; unsigned block_start, block_end, blocksize, bbits; int err = 0; char *kaddr = kmap(page); bbits = inode->i_blkbits; blocksize = 1 << bbits; if (!page->buffers) create_empty_buffers(page, inode->i_dev, blocksize); head = page->buffers; block = page->index << (PAGE_CACHE_SHIFT - bbits); /* start block # */ /* we allocate buffers and map them */ for(bh = head, block_start = 0; bh != head || !block_start; block++, block_start = block_end + 1, bh = bh->b_this_page) { if (!bh) { err = -EIO; RFS_BUG("can't get buffer head\n"); goto out; } block_end = block_start + blocksize - 1; if (block_end < from) { continue; } else if (block_start > to) { break; } clear_bit(BH_New, &bh->b_state); /* map new buffer if necessary*/ if (!buffer_mapped(bh) || (inode->i_size <= (block<<(inode->i_sb->s_blocksize_bits)))) { err = get_block(inode, block, bh, 1); if (err) { DEBUG(DL1, "no block\n"); goto out; } if (buffer_new(bh) && block_end > to) { memset(kaddr+to+1, 0, block_end-to); continue; } } if (!buffer_uptodate(bh) && (block_start < from || block_end > to)) { ll_rw_block(READ, 1, &bh); wait_on_buffer(bh); if (!buffer_uptodate(bh)) { err = -EIO; goto out; } } } out: flush_dcache_page(page); kunmap_atomic(kaddr, KM_USER0); return err; }
/* convert locale alias to canonical name using LOCALE_ALIAS_FILE (presumably /usr/share/locale/locale.alias) and return it Returned string should be freed by caller. FIXME: this function can get easily confused by lines longer than BUFSIZE (but the worst thing that can happen is we return wrong locale name) the locale.alias format is nowhere described, so we assume every line consists of alias (row 1), some whitespace and canonical name */ static char* locale_alias_convert(const char *locname) { #ifdef HAVE_LOCALE_ALIAS File *fla; /* locale.alias file */ Buffer *buf; char *s,*p,*q; size_t n; #endif /* HAVE_LOCALE_ALIAS */ if (!locname) return NULL; /* Catch the special language name `none' */ if (strcmp(locname, "none") == 0) return enca_strdup("__"); #ifdef HAVE_LOCALE_ALIAS /* try to read locale.alias */ buf = buffer_new(0); fla = file_new(LOCALE_ALIAS_PATH, buf); if (file_open(fla, "r") != 0) { if (options.verbosity_level) { fprintf(stderr, "Cannot find locale.alias file.\n" "This build of enca probably has been configured for " "quite a different system\n"); } file_free(fla); buffer_free(buf); return enca_strdup(locname); } /* scan locale.alias somewhat crude now */ n = strlen(locname); p = NULL; s = (char*)buf->data; /* alias */ while (file_getline(fla) != NULL) { if (strncmp(s, locname, n) == 0 && (isspace(s[n]) || (s[n] == ':' && isspace(s[n+1])))) { p = s + n; /* skip any amount of whitespace */ while (isspace(*p)) p++; q = p; /* anything up to next whitespace is the canonical locale name */ while (*q != '\0' && !isspace(*q)) q++; *q = '\0'; p = enca_strdup(p); break; } } file_close(fla); file_free(fla); buffer_free(buf); return p != NULL ? p : static_iso639_alias_convert(locname); #else /* HAVE_LOCALE_ALIAS */ return static_iso639_alias_convert(locname); #endif /* HAVE_LOCALE_ALIAS */ }
static buffer_t * buffer_from_file(const char *fname, int flags, zip_error_t *error) { buffer_t *buffer; FILE *f; if ((buffer = buffer_new()) == NULL) { zip_error_set(error, ZIP_ER_MEMORY, 0); return NULL; } if ((flags & ZIP_TRUNCATE) == 0) { if ((f = fopen(fname, "rb")) == NULL) { if (!(errno == ENOENT && (flags & ZIP_CREATE))) { buffer_free(buffer); return NULL; } } else { if (buffer_read_file(buffer, f, error) < 0) { buffer_free(buffer); fclose(f); return NULL; } fclose(f); } } return buffer; }
/** * @brief Run a shell command without an interactive shell. * * This is similar to 'sh -c command'. * * @param channel The channel to execute the command. * * @param cmd The command to execute * (e.g. "ls ~/ -al | grep -i reports"). * * @return SSH_SUCCESS on success, SSH_ERROR on error. * * @see channel_request_shell() */ int channel_request_exec(CHANNEL *channel, const char *cmd) { BUFFER *buffer = NULL; STRING *command = NULL; int rc = SSH_ERROR; #ifdef HAVE_SSH1 if (channel->version == 1) { return channel_request_exec1(channel, cmd); } #endif buffer = buffer_new(); if (buffer == NULL) { goto error; } command = string_from_char(cmd); if (command == NULL) { goto error; } if (buffer_add_ssh_string(buffer, command) < 0) { goto error; } rc = channel_request(channel, "exec", buffer, 1); error: buffer_free(buffer); string_free(command); return rc; }
/* FIXME: * Rly need to return char ptr? * Remember that octstring is not NULL terminated! */ void octstr_init(octstr_t *octstr) { assert(octstr != NULL); octstr->buf = buffer_new(); }
char * http_encode_uri(const char *uri, size_t len, int space_as_plus) { struct buffer *buf = buffer_new(); if (buf == NULL) return (NULL); const char *p, *end; char *result; if (len >= 0) end = uri+len; else end = uri+strlen(uri); for (p = uri; p < end; p++) { if (CHAR_IS_UNRESERVED(*p)) { buffer_add(buf, p, 1); } else if (*p == ' ' && space_as_plus) { buffer_add(buf, "+", 1); } else { buffer_add_printf(buf, "%%%02X", (unsigned char)(*p)); } } buffer_add(buf, "", 1); /* NUL-terminator. */ result = malloc(buf->len); if (!result) return NULL; buffer_remove(buf, result, buf->len); buffer_free(buf); return (result); }
PUBLIC_KEY *publickey_from_string(SSH_SESSION *session, STRING *pubkey_s){ BUFFER *tmpbuf=buffer_new(); STRING *type_s; char *type; buffer_add_data(tmpbuf,pubkey_s->string,string_len(pubkey_s)); type_s=buffer_get_ssh_string(tmpbuf); if(!type_s){ buffer_free(tmpbuf); ssh_set_error(session,SSH_FATAL,"Invalid public key format"); return NULL; } type=string_to_char(type_s); free(type_s); if(!strcmp(type,"ssh-dss")){ free(type); return publickey_make_dss(session, tmpbuf); } if(!strcmp(type,"ssh-rsa")){ free(type); return publickey_make_rsa(session, tmpbuf,"ssh-rsa"); } if(!strcmp(type,"ssh-rsa1")){ free(type); return publickey_make_rsa(session, tmpbuf,"ssh-rsa1"); } ssh_set_error(session,SSH_FATAL,"unknown public key protocol %s",type); buffer_free(tmpbuf); free(type); return NULL; }
/* * This function concats in a buffer the values needed to do a signature * verification. */ ssh_buffer ssh_userauth_build_digest(ssh_session session, ssh_message msg, char *service) { /* The value of 'signature' is a signature by the corresponding private key over the following data, in the following order: string session identifier byte SSH_MSG_USERAUTH_REQUEST string user name string service name string "publickey" boolean TRUE string public key algorithm name string public key to be used for authentication */ struct ssh_crypto_struct *crypto = session->current_crypto ? session->current_crypto : session->next_crypto; ssh_buffer buffer = NULL; ssh_string session_id = NULL; uint8_t type = SSH2_MSG_USERAUTH_REQUEST; ssh_string username = string_from_char(msg->auth_request.username); ssh_string servicename = string_from_char(service); ssh_string method = string_from_char("publickey"); uint8_t has_sign = 1; ssh_string algo = string_from_char(msg->auth_request.public_key->type_c); ssh_string publickey = publickey_to_string(msg->auth_request.public_key); buffer = buffer_new(); if (buffer == NULL) { goto error; } session_id = string_new(SHA_DIGEST_LEN); if (session_id == NULL) { buffer_free(buffer); buffer = NULL; goto error; } string_fill(session_id, crypto->session_id, SHA_DIGEST_LEN); if(buffer_add_ssh_string(buffer, session_id) < 0 || buffer_add_u8(buffer, type) < 0 || buffer_add_ssh_string(buffer, username) < 0 || buffer_add_ssh_string(buffer, servicename) < 0 || buffer_add_ssh_string(buffer, method) < 0 || buffer_add_u8(buffer, has_sign) < 0 || buffer_add_ssh_string(buffer, algo) < 0 || buffer_add_ssh_string(buffer, publickey) < 0) { buffer_free(buffer); buffer = NULL; goto error; } error: if(session_id) string_free(session_id); if(username) string_free(username); if(servicename) string_free(servicename); if(method) string_free(method); if(algo) string_free(algo); if(publickey) string_free(publickey); return buffer; }