int ed_init(Context_t* ctx) { CmdHook_t *hooks; int i; /* logging*/ log_add(LL_ERROR, "error.log"); log_add(LL_DEBUG, "debug.log"); /* screen */ ctx->scr = ncs_new(); ncs_init(ctx->scr); /* buffer */ ctx->c_buffer = buf_new("scratch.txt"); ctx->cmd_buffer = buf_new("cmdbuf.txt"); /* main context */ ed_set_mode(ctx, ED_HOTKEY_MODE); ed_load_cmd_cfg(ctx, "cmds.txt"); hooks = cmdlib_get_lib(); i = 0; while (hooks[i].type != CMD_COUNT) { ed_bind_cmd_hook(ctx, hooks[i].type, hooks[i].cmd_hook_cb); i++; } return 0; }
int pgp_rkeylist(REMAILER remailer[], int keyid[], int n) /* Step through all remailers and get keyid */ { BUFFER *userid; BUFFER *id; int i, err; userid = buf_new(); id = buf_new(); for (i = 1; i < n; i++) { buf_clear(userid); buf_setf(userid, "<%s>", remailer[i].addr); keyid[i]=0; if (remailer[i].flags.pgp) { buf_clear(id); err = pgpdb_getkey(PK_VERIFY, PGP_ANY, NULL, NULL, NULL, NULL, userid, NULL, id, NULL, NULL); if (id->length == 8) { /* printf("%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x %s\n", id->data[0], id->data[1], id->data[2], id->data[3], id->data[4], id->data[5], id->data[6], id->data[7], id->data[8], remailer[i].addr); */ keyid[i] = (((((id->data[4] << 8) + id->data[5]) << 8) + id->data[6]) << 8) + id->data[7]; } } } buf_free(userid); return (0); }
static struct stream * stream_new(stream_readfn_t *readfn, stream_writefn_t *writefn, stream_closefn_t *closefn) { struct stream *stream; stream = xmalloc(sizeof(struct stream)); if (readfn == NULL && writefn == NULL) { errno = EINVAL; return (NULL); } if (readfn != NULL) stream->rdbuf = buf_new(STREAM_BUFSIZ); else stream->rdbuf = NULL; if (writefn != NULL) stream->wrbuf = buf_new(STREAM_BUFSIZ); else stream->wrbuf = NULL; stream->cookie = NULL; stream->fd = -1; stream->buf = 0; stream->readfn = readfn; stream->writefn = writefn; stream->closefn = closefn; stream->filter = stream_filter_lookup(STREAM_FILTER_NULL); stream->fdata = NULL; stream->eof = 0; return (stream); }
int gs_init() { int i=0; mGs = (struct gs_t *)MALLOC(sizeof(*mGs)); memset(mGs, 0, sizeof(*mGs)); mGs->mEp = epoll_create(1024); if (0 >= mGs->mEp) { fprintf(stderr, "create epoll fail\n"); exit(0); } mGs->mSon = 65535; mGs->mSos = (struct so_t **)MALLOC(mGs->mSon * sizeof(struct so_t *)); for (i=0; i<mGs->mSon; ++i) { struct so_t *so = (struct so_t *)MALLOC(sizeof(*so)); memset(so, 0, sizeof(*so)); so->mId = i; so->mLock = lock_new(); so->mRLock = lock_new(); so->mWLock = lock_new(); so->mELock = lock_new(); so->mRBuf = buf_new(); so->mWBuf = buf_new(); mGs->mSos[i] = so; } mGs->mQLock = lock_new(); return 0; }
int v2_merge(BUFFER *mid) { char fname[PATHMAX], line[LINELEN]; BUFFER *temp, *msg; FILE *l, *f; int i, numpackets; struct stat sb; long d; int n; int err = -1; temp = buf_new(); msg = buf_new(); pool_packetfile(fname, mid, 0); l = fopen(fname, "a+"); if (l != NULL) lock(l); pool_packetfile(fname, mid, 1); f = fopen(fname, "rb"); if (f == NULL) goto end; fscanf(f, "%32s %ld %d %d\n", line, &d, &i, &numpackets); fclose(f); /* do we have all packets? */ for (i = 1; i <= numpackets; i++) { pool_packetfile(fname, mid, i); if (stat(fname, &sb) != 0) goto end; } errlog(LOG, "Reassembling multipart message.\n"); for (i = 1; i <= numpackets; i++) { pool_packetfile(fname, mid, i); f = fopen(fname, "rb"); if (f == NULL) goto end; fscanf(f, "%32s %ld %d %d\n", line, &d, &n, &n); buf_clear(temp); buf_read(temp, f); v2body_setlen(temp); buf_append(msg, temp->data + 4, temp->length - 4); fclose(f); unlink(fname); } err = v2body(msg); end: if (l != NULL) fclose(l); pool_packetfile(fname, mid, 0); unlink(fname); buf_free(temp); buf_free(msg); return (err); }
buf_t* buf_read(FILE *f) { const int sigsize = 8; wint_t wc; uint8_t y; int ret; buf_t *b; wchar_t wcswap[sigsize]; uint8_t yswap[2]; int i; /* read sig bytes or first sigsize chars */ for(i = 0; i < sigsize; i++) { wc = getwc(f); EXIT_FERROR(f); if(wc == WEOF) { b = buf_new(false); EXIT_NULL(b); buf_push_nwchar(b, wcswap, i); return b; } wcswap[i] = (wchar_t)wc; } /* check for sig to determine if 8xp */ if( !wcsncmp(wcswap, L"**TI83F*", sigsize) ) { b = buf_new(true); } else { b = buf_new(false); } /* not 8xp, so just read the rest */ if( !b->is_8xp) { buf_push_nwchar(b, wcswap, sigsize); while( (wc = getwc(f)) != WEOF) { buf_push_wchar(b, (wchar_t)wc); } return b; } /* discard remainder of header */ for(i = sigsize; i < HEADER_SIZE; i++) { ret = fread(&y, sizeof(uint8_t), 1, f); EXIT_FERROR(f); /* EOF this early means malformed 8xp */ if(ret <= 0) { printf("\e[1mtok8x:\e[0m" "\e[1;31merror:\e[0m %s\n", "malformed .8xp input" ); exit(EIO); } }
int mix_dearmor(BUFFER *in, BUFFER *out) { BUFFER *line, *md; int tempbuf = 0; int err = 0; line = buf_new(); md = buf_new(); if (in == out) { tempbuf = 1; out = buf_new(); } do { err = buf_getline(in, line); if (err == -1) goto end; } while (!bufeq(line, begin_remailer)); do { /* skip lines before message digest */ if (buf_getline(in, md) == -1) break; } while (strlen(md->data) != 24); decode(in, out); err = buf_getline(in, line); if (err != 0 || !bufeq(line, end_remailer)) err = -1; else { digest_md5(out, line); encode(line, 0); if (!buf_eq(md, line)) err = -1; if (out->length != 20480) err = -1; } end: if (err == -1) errlog(NOTICE, "Malformatted message.\n"); if (tempbuf) { buf_move(in, out); buf_free(out); } buf_free(line); buf_free(md); return (err); }
int pgp_latestkeys(BUFFER* outtxt, int algo) /* returns our latest key from pgpkey.txt in the buffer outtxt * with pgp key header, ascii armored * * Can probably be extended to do this for all keys if we pass * the keyring file and the userid * * IN: algo: PGP_ANY, PGP_ES_RSA, PGP_E_ELG, PGP_S_DSA * OUT: outtxt */ { int err = -1; long expires_found = 0, expires; BUFFER *key, *userid, *tmptxt; KEYRING *keys; key = buf_new(); userid = buf_new(); buf_sets(userid, REMAILERNAME); tmptxt = buf_new(); keys = pgpdb_open(PGPKEY, NULL, 0, PGP_TYPE_PUBLIC); if (keys != NULL) { while (pgpdb_getnext(keys, key, NULL, userid) != -1) { buf_clear(tmptxt); if (pgp_makekeyheader(PGP_PUBKEY, key, tmptxt, NULL, algo) == 0) { buf_rewind(key); pgp_getkey(PK_VERIFY, algo, NULL, NULL, &expires, key, NULL, NULL, NULL, NULL); if (expires == 0 || (expires_found <= expires)) { err = 0; buf_clear(outtxt); buf_appends(outtxt, "Type Bits/KeyID Date User ID\n"); buf_cat(outtxt, tmptxt); buf_nl(outtxt); pgp_armor(key, PGP_ARMOR_KEY); buf_cat(outtxt, key); buf_nl(outtxt); expires_found = expires; } } } pgpdb_close(keys); } buf_free(key); buf_free(userid); buf_free(tmptxt); return (err); }
static int pgp_readkeyring(BUFFER *keys, char *filename) { FILE *keyfile; BUFFER *armored, *line, *tmp; int err = -1; if ((keyfile = mix_openfile(filename, "rb")) == NULL) return (err); armored = buf_new(); buf_read(armored, keyfile); fclose(keyfile); if (pgp_ispacket(armored)) { err = 0; buf_move(keys, armored); } else { line = buf_new(); tmp = buf_new(); while (1) { do if (buf_getline(armored, line) == -1) { goto end_greedy_dearmor; } while (!bufleft(line, begin_pgp)) ; buf_clear(tmp); buf_cat(tmp, line); buf_appends(tmp, "\n"); do { if (buf_getline(armored, line) == -1) { goto end_greedy_dearmor; } buf_cat(tmp, line); buf_appends(tmp, "\n"); } while (!bufleft(line, end_pgp)) ; if (pgp_dearmor(tmp, tmp) == 0) { err = ARMORED; buf_cat(keys, tmp); } } end_greedy_dearmor: buf_free(line); buf_free(tmp); } buf_free(armored); return (err); }
/* returns success or failure */ static int readhostkey(const char * filename, sign_key * hostkey, int type) { int ret = DROPBEAR_FAILURE; int i; buffer *buf; buf = buf_new(2000); if (buf_readfile(buf, filename) == DROPBEAR_FAILURE) { goto out; } buf_setpos(buf, 0); if (buf_get_priv_key(buf, hostkey, type) == DROPBEAR_FAILURE) { goto out; } ret = DROPBEAR_SUCCESS; out: if (ret == DROPBEAR_FAILURE) { for (i = 0; sshhostkey[i].name != NULL; i++) { if (sshhostkey[i].val == type) { sshhostkey[i].usable = 0; break; } } fprintf(stderr, "Failed reading '%s', disabling %s\n", filename, type == DROPBEAR_SIGNKEY_DSS ? "DSS" : "RSA"); } buf_burn(buf); buf_free(buf); return ret; }
static void test_proto_control0(void *arg) { (void)arg; buf_t *buf = buf_new(); /* The only remaining function for the v0 control protocol is the function that detects whether the user has stumbled across an old controller that's using it. The format was: u16 length; u16 command; u8 body[length]; */ /* Empty buffer -- nothing to do. */ tt_int_op(0, OP_EQ, peek_buf_has_control0_command(buf)); /* 3 chars in buf -- can't tell */ buf_add(buf, "AUT", 3); tt_int_op(0, OP_EQ, peek_buf_has_control0_command(buf)); /* command in buf -- easy to tell */ buf_add(buf, "HENTICATE ", 10); tt_int_op(0, OP_EQ, peek_buf_has_control0_command(buf)); /* Control0 command header in buf: make sure we detect it. */ buf_clear(buf); buf_add(buf, "\x09\x05" "\x00\x05" "blah", 8); tt_int_op(1, OP_EQ, peek_buf_has_control0_command(buf)); done: buf_free(buf); }
static int http_reply (RESTSESSION * r, int status, struct buf * response) { struct buf *b; int ret; char respcode[100]; char content_len[256]; b = buf_new (); sprintf (respcode, "HTTP/1.1 %03d\r\n", status); buf_append_data (b, respcode, strlen (respcode)); buf_append_data (b, content_type, strlen (content_type)); buf_append_data (b, connection_close, strlen (connection_close)); sprintf (content_len, "Content-Length: %d\r\n", response->len); buf_append_data (b, content_len, strlen (content_len)); buf_append_data (b, "\r\n", 2); buf_append_data (b, response->ptr, response->len); ret = 0; if (send (r->socket, b->ptr, b->len, 0) != b->len) ret = -1; buf_free (b); buf_free (response); http_cleanup (r); return ret; }
static void auth_generate_auth_hmac(struct login_ctx *l) { struct buf* buf = buf_new(); buf_append_data(buf, l->client_parameters->ptr, l->client_parameters->len); buf_append_data(buf, l->server_parameters->ptr, l->server_parameters->len); buf_append_u8(buf, 0); /* random data length */ buf_append_u8(buf, 0); /* unknown */ buf_append_u16(buf, 8); /* puzzle solution length */ buf_append_u32(buf, 0); /* unknown */ /* <-- random data would go here */ buf_append_data(buf, l->puzzle_solution, 8); #ifdef DEBUG_LOGIN hexdump8x32 ("auth_generate_auth_hmac, HMAC message", buf->ptr, buf->len); hexdump8x32 ("auth_generate_auth_hmac, HMAC key", l->key_hmac, sizeof (l->key_hmac)); #endif sha1_hmac(l->key_hmac, sizeof(l->key_hmac), buf->ptr, buf->len, l->auth_hmac); #ifdef DEBUG_LOGIN hexdump8x32 ("auth_generate_auth_hmac, HMAC digest", l->auth_hmac, sizeof(l->auth_hmac)); #endif buf_free(buf); }
int gw_browse (SPOTIFYSESSION * s, unsigned char kind, char *id_as_hex, int num_ids) { DECOMPRESSCTX *dctx; unsigned char id[16*num_ids]; hex_ascii_to_bytes (id_as_hex, id, 16*num_ids); dctx = (DECOMPRESSCTX *) malloc (sizeof (DECOMPRESSCTX)); dctx->z.zalloc = Z_NULL; dctx->z.zfree = Z_NULL; dctx->z.opaque = Z_NULL; dctx->z.avail_in = 0; dctx->z.next_in = Z_NULL; if (inflateInit2 (&dctx->z, -MAX_WBITS) != Z_OK) { free (dctx); return -1; } dctx->decompression_done = 0; dctx->b = buf_new(); s->output = dctx; s->output_len = 0; return cmd_browse (s->session, kind, id, num_ids, gw_browse_result_callback, (void *) s); }
void auth_generate_auth_hmac (SESSION * session, unsigned char *auth_hmac, unsigned int mac_len) { (void)mac_len; struct buf* buf = buf_new(); buf_append_data(buf, session->init_client_packet->ptr, session->init_client_packet->len); buf_append_data(buf, session->init_server_packet->ptr, session->init_server_packet->len); buf_append_u8(buf, 0); /* random data length */ buf_append_u8(buf, 0); /* unknown */ buf_append_u16(buf, 8); /* puzzle solution length */ buf_append_u32(buf, 0); /* unknown */ /* <-- random data would go here */ buf_append_data(buf, session->puzzle_solution, 8); #ifdef DEBUG_LOGIN hexdump8x32 ("auth_generate_auth_hmac, HMAC message", buf->ptr, buf->len); hexdump8x32 ("auth_generate_auth_hmac, HMAC key", session->key_hmac, sizeof (session->key_hmac)); #endif sha1_hmac ( session->key_hmac, sizeof (session->key_hmac), buf->ptr, buf->len, auth_hmac); #ifdef DEBUG_LOGIN hexdump8x32 ("auth_generate_auth_hmac, HMAC digest", auth_hmac, mac_len); #endif buf_free(buf); }
static int textio_new(Value *vret, Value *v, RefNode *node) { RefTextIO *tio; RefCharset *cs = Value_vp(v[2]); Ref *r = ref_new(fs->cls_textio); *vret = vp_Value(r); tio = buf_new(NULL, sizeof(RefTextIO)); r->v[INDEX_TEXTIO_TEXTIO] = vp_Value(tio); r->v[INDEX_TEXTIO_STREAM] = Value_cp(v[1]); tio->in.ic = (void*)-1; tio->out.ic = (void*)-1; tio->cs = cs; tio->trans = FALSE; if (fg->stk_top > v + 3 && Value_bool(v[3])) { tio->trans = TRUE; } if (fg->stk_top > v + 4) { r->v[INDEX_TEXTIO_NEWLINE] = Value_cp(v[4]); } return TRUE; }
/* returns success or failure, and the keytype in *type. If we want * to restrict the type, type can contain a type to return */ int readhostkey(const char * filename, sign_key * hostkey, int *type) { int ret = DROPBEAR_FAILURE; buffer *buf; buf = buf_new(MAX_PRIVKEY_SIZE); if (buf_readfile(buf, filename) == DROPBEAR_FAILURE) { goto out; } buf_setpos(buf, 0); addrandom(buf_getptr(buf, buf->len), buf->len); if (buf_get_priv_key(buf, hostkey, type) == DROPBEAR_FAILURE) { goto out; } ret = DROPBEAR_SUCCESS; out: buf_burn(buf); buf_free(buf); return ret; }
int send_client_auth (SESSION * session) { int ret; struct buf* buf = buf_new(); buf_append_data(buf, session->auth_hmac, 20); buf_append_u8(buf, 0); /* random data length */ buf_append_u8(buf, 0); /* unknown */ buf_append_u16(buf, 8); /* puzzle solution length */ buf_append_u32(buf, 0); /* <-- random data would go here */ buf_append_data (buf, session->puzzle_solution, 8); #ifdef DEBUG_LOGIN hexdump8x32 ("send_client_auth, second client packet", buf->ptr, buf->len); #endif ret = send(session->ap_sock, buf->ptr, buf->len, 0); if (ret <= 0) { DSFYDEBUG("send_client_auth(): connection lost\n"); buf_free(buf); return -1; } else if (ret != buf->len) { DSFYDEBUG("send_client_auth(): only wrote %d of %d bytes\n", ret, buf->len); buf_free(buf); return -1; } buf_free(buf); return 0; }
static int http_reply_need_auth (RESTSESSION * r) { struct buf *b; int ret; char buf[256]; b = buf_new(); strcpy (buf, "HTTP/1.1 401\r\n"); buf_append_data (b, buf, strlen (buf)); strcpy (buf, "WWW-Authenticate: Basic realm=\"Spotify\"\r\n"); buf_append_data (b, buf, strlen (buf)); buf_append_data (b, content_type, strlen (content_type)); buf_append_data (b, connection_close, strlen (connection_close)); strcpy (buf, "Content-Length: 0\r\n"); buf_append_data (b, buf, strlen (buf)); buf_append_data (b, "\r\n", 2); ret = 0; if (send (r->socket, b->ptr, b->len, 0) != b->len) ret = -1; buf_free (b); http_cleanup (r); return ret; }
/* * Send header information which includes current working direcotry, * command line arguments, and CLASSPATH environment variable * to the server. */ void send_header(int fd, int argc, char** argv, char* authtoken) { char path_buffer[MAXPATHLEN]; buf read_buf = buf_new(BUFFER_SIZE, NULL); int i; // send current working directory. buf_printf(&read_buf, "%s: ", HEADER_KEY_CURRENT_WORKING_DIR); char* cwd = getcwd(path_buffer, MAXPATHLEN); if (cwd == NULL) { perror("ERROR: getcwd"); exit(1); } buf_add(&read_buf, cwd); buf_add(&read_buf, "\n"); buf_printf(&read_buf, "%s: %s\n", HEADER_KEY_AUTHTOKEN, authtoken); // send command line arguments. char *encoded_ptr, *encoded_work; for (i = 1; i < argc; i++) { if (argv[i] != NULL) { // base64 encoded data is less "(original size) * 1.5 + 5" as much as raw data // "+5" is a extra space for '=' padding and NULL as the end of string encoded_ptr = malloc(sizeof(char) * strlen(argv[i]) * 1.5 + 5); if (encoded_ptr == NULL) { perror("ERROR: failed to malloc"); exit(1); } encoded_work = encoded_ptr; // copy for free base64_encode(encoded_work, (unsigned char*) argv[i]); buf_printf(&read_buf, "%s: %s\n", HEADER_KEY_ARG, encoded_work); free(encoded_ptr); } } // send envvars. if (client_option.env_include_mask != NULL) { make_env_headers(&read_buf, environ, client_option.env_include_mask, client_option.env_exclude_mask); } char* cp = getenv("CLASSPATH"); if (cp != NULL) { buf_printf(&read_buf, "%s: %s\n", HEADER_KEY_CP, cp); } buf_printf(&read_buf, "\n"); read_buf.size--; /* remove trailing '\0' */ #ifdef WINDOWS send(fd, read_buf.buffer, read_buf.size, 0); #else write(fd, read_buf.buffer, read_buf.size); #endif buf_delete(&read_buf); }
/** Create and return a new buf with default chunk capacity <b>size</b>. */ buf_t * buf_new_with_capacity(size_t size) { buf_t *b = buf_new(); b->default_chunk_size = buf_preferred_chunk_size(size); return b; }
/** * 複製 */ int map_dup(Value *vret, Value *v, RefNode *node) { RefMap *src = Value_vp(*v); RefNode *type = FUNC_VP(node); int i; int max = src->entry_num; RefMap *dst = buf_new(type, sizeof(RefMap)); *vret = vp_Value(dst); dst->count = src->count; dst->entry_num = max; dst->entry = malloc(sizeof(HashValueEntry*) * max); for (i = 0; i < max; i++) { HashValueEntry *hsrc = src->entry[i]; HashValueEntry **hdst = &dst->entry[i]; for (; hsrc != NULL; hsrc = hsrc->next) { HashValueEntry *he = malloc(sizeof(HashValueEntry)); he->key = Value_cp(hsrc->key); he->val = Value_cp(hsrc->val); he->hash = hsrc->hash; *hdst = he; hdst = &he->next; } *hdst = NULL; } return TRUE; }
static void test_buffers_tls_read_mocked(void *arg) { uint8_t *mem; buf_t *buf; (void)arg; mem = tor_malloc(64*1024); crypto_rand((char*)mem, 64*1024); tls_read_ptr = mem; n_remaining = 64*1024; MOCK(tor_tls_read, mock_tls_read); buf = buf_new(); next_reply_val[0] = 1024; tt_int_op(128, ==, read_to_buf_tls(NULL, 128, buf)); next_reply_val[0] = 5000; next_reply_val[1] = 5000; tt_int_op(6000, ==, read_to_buf_tls(NULL, 6000, buf)); done: UNMOCK(tor_tls_read); tor_free(mem); buf_free(buf); }
int read_and_exec(int socket) { struct buf_t* buf = buf_new(8049); int pos = buf_readuntil(socket, buf, '\n'); if (pos == -2) return 0; char* buffer = buf->data; buffer[pos] = '\0'; struct execargs_t* arguments[1024]; int k = 0; while (1) { char delim; int argc = count_words(buffer, '|'); if (argc == 0) break; char* argv[argc]; int shift; int i = 0; for (i = 0; i < argc; i++) { delim = '|'; argv[i] = get_word(buffer, &delim, &shift); buffer += shift; } arguments[k] = (struct execargs_t*) malloc(sizeof(struct execargs_t)); *arguments[k] = new_args(argc, argv); shift = get_delim(buffer, '|'); buffer+=shift; k++; } buf->size -= (buffer - (char*) buf->data + 1); runpiped(arguments, k, socket); buf_free(buf); return 0; }
static void flacdec_read_vorbis_comment(BitstreamReader *comment, unsigned channel_count, int *channel_mask) { struct bs_buffer *line = buf_new(); unsigned line_len; unsigned total_lines; const char mask_prefix[] = "WAVEFORMATEXTENSIBLE_CHANNEL_MASK="; if (!setjmp(*br_try(comment))) { /*skip over vendor string*/ line_len = comment->read(comment, 32); comment->skip_bytes(comment, line_len); /*walk through all entries in the comment*/ for (total_lines = comment->read(comment, 32); total_lines > 0; total_lines--) { const char *s; /*populate entry one character at a time (this avoids allocating a big chunk of space if the length field is something way too large)*/ buf_reset(line); for (line_len = comment->read(comment, 32); line_len > 0; line_len--) { buf_putc( toupper((int)comment->read(comment, 8)), line); } buf_putc(0, line); /*NULL terminator*/ s = (const char *)buf_window_start(line); /*if line starts with mask prefix*/ if (strstr(s, mask_prefix) == s) { /*convert rest of line to base-16 integer*/ unsigned mask = (unsigned)strtoul( s + strlen(mask_prefix), NULL, 16); /*and populate mask field if its number of channel bits matches the stream's channel count*/ if (channel_bits(mask) == channel_count) { *channel_mask = mask; } } } br_etry(comment); } else { /*read error in VORBIS_COMMENT (probably invalid length field somewhere)*/ br_etry(comment); } buf_close(line); }
int send_client_initial_packet (SESSION * session) { int ret; unsigned int len_idx; struct buf* b = buf_new(); buf_append_u16 (b, 3); /* protocol version */ len_idx = b->len; buf_append_u16(b, 0); /* packet length - updated later */ buf_append_u32(b, 0x00000300); /* unknown */ buf_append_u32(b, 0x00030c00); /* unknown */ buf_append_u32(b, session->client_revision); buf_append_u32(b, 0); /* unknown */ buf_append_u32(b, 0x01000000); /* unknown */ buf_append_data(b, session->client_id, 4); buf_append_u32(b, 0); /* unknown */ buf_append_data (b, session->client_random_16, 16); buf_append_data (b, session->my_pub_key, 96); BN_bn2bin (session->rsa->n, session->rsa_pub_exp); buf_append_data (b, session->rsa_pub_exp, sizeof(session->rsa_pub_exp)); buf_append_u8 (b, 0); /* length of random data */ buf_append_u8 (b, session->username_len); buf_append_u16(b, 0x0100); /* unknown */ /* <-- random data would go here */ buf_append_data (b, (unsigned char *) session->username, session->username_len); buf_append_u8 (b, 0x40); /* unknown */ /* * Update length bytes * */ b->ptr[len_idx] = (b->len >> 8) & 0xff; b->ptr[len_idx+1] = b->len & 0xff; #ifdef DEBUG_LOGIN hexdump8x32 ("initial client packet", b->ptr, b->len); #endif ret = send (session->ap_sock, b->ptr, b->len, 0); if (ret <= 0) { DSFYDEBUG("connection lost\n"); buf_free(b); return -1; } else if (ret != b->len) { DSFYDEBUG("only wrote %d of %d bytes\n", ret, b->len); buf_free(b); return -1; } /* save initial server packet for auth hmac generation */ session->init_client_packet = b; return 0; }
void test_offs_ncopy_extend() { buf b = buf_new(3, NULL); buf_offs_ncopy(&b, 0, "abcd", 4); assert(memcmp(b.buffer, "abcd", 4) == 0); assert(b.size == 4); assert(b.buffer_size == 6); buf_delete(&b); }
/* * 0 1 2 3 4 * ? a b c \0 */ void test_offs_ncopy5() { buf b = buf_new(10, NULL); buf_offs_ncopy(&b, 1, "abcd", 3); assert(memcmp(b.buffer+1, "abc\0", 3) == 0); /* extra \0 added */ assert(b.buffer_size == 10); assert(b.size == 4); buf_delete(&b); }
/* * 0 1 2 3 4 5 6 * ? ? a b c d \0 */ void test_offs_ncopy6() { buf b = buf_new(10, NULL); buf_offs_ncopy(&b, 2, "abcd", 5); assert(memcmp(b.buffer+2, "abcd\0", 5) == 0); assert(b.buffer_size == 10); assert(b.size == 7); buf_delete(&b); }
void test_offs_ncopy3() { buf b = buf_new(3, NULL); buf_offs_ncopy(&b, 0, "abc", 3); assert(memcmp(b.buffer, "abc\0", 4) == 0); assert(b.buffer_size == 3); /* auto extended */ assert(b.size == 3); /* still size == 3 (a,b,c) */ buf_delete(&b); }