Wht * node_init(size_t n, char *name) { Wht *W; size_t i; W = (Wht *) i_malloc(sizeof(Wht)); W->N = (1 << n); W->n = n; W->apply = null_apply; W->error_msg = NULL; W->left = W->N; W->right = 1; W->parent = NULL; W->children = NULL; W->to_string = NULL; W->rule = rule_init(name); for (i = 0; i < MAX_ATTRIBUTES; i++) W->attr[i] = UNSET_ATTRIBUTE; for (i = 0; i < MAX_ATTRIBUTES; i++) { W->provides[i] = false; W->requires[i] = false; } return W; }
static void index_cache_register_defaults(struct mailbox *box) { struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box); const struct mail_storage_settings *set = box->storage->set; struct mail_cache *cache = box->cache; ibox->cache_fields = i_malloc(sizeof(global_cache_fields)); memcpy(ibox->cache_fields, global_cache_fields, sizeof(global_cache_fields)); mail_cache_register_fields(cache, ibox->cache_fields, MAIL_INDEX_CACHE_FIELD_COUNT); if (strcmp(set->mail_never_cache_fields, "*") == 0) { /* all caching disabled for now */ box->mail_cache_disabled = TRUE; return; } set_cache_decisions(cache, "mail_cache_fields", set->mail_cache_fields, MAIL_CACHE_DECISION_TEMP); set_cache_decisions(cache, "mail_always_cache_fields", set->mail_always_cache_fields, MAIL_CACHE_DECISION_YES | MAIL_CACHE_DECISION_FORCED); set_cache_decisions(cache, "mail_never_cache_fields", set->mail_never_cache_fields, MAIL_CACHE_DECISION_NO | MAIL_CACHE_DECISION_FORCED); }
int mail_session_connect_parse(const char *const *args, const char **error_r) { struct mail_session *session; const char *session_id; pid_t pid; struct ip_addr ip; unsigned int i; /* <session id> <username> <service> <pid> [key=value ..] */ if (str_array_length(args) < 4) { *error_r = "CONNECT: Too few parameters"; return -1; } session_id = args[0]; if (str_to_pid(args[3], &pid) < 0) { *error_r = t_strdup_printf("CONNECT: Invalid pid %s for session ID %s", args[3], session_id); return -1; } session = hash_table_lookup(mail_sessions_hash, session_id); if (session != NULL) { *error_r = t_strdup_printf( "CONNECT: Duplicate session ID %s for user %s service %s", session_id, args[1], args[2]); return -1; } session = i_malloc(sizeof(struct mail_session) + stats_alloc_size()); session->stats = (void *)(session + 1); session->refcount = 1; /* unrefed at disconnect */ session->id = i_strdup(session_id); session->service = str_table_ref(services, args[2]); session->pid = pid; session->last_update = ioloop_timeval; session->to_idle = timeout_add(MAIL_SESSION_IDLE_TIMEOUT_MSECS, mail_session_idle_timeout, session); session->user = mail_user_login(args[1]); for (i = 3; args[i] != NULL; i++) { if (strncmp(args[i], "rip=", 4) == 0 && net_addr2ip(args[i] + 4, &ip) == 0) session->ip = mail_ip_login(&ip); } hash_table_insert(mail_sessions_hash, session->id, session); DLLIST_PREPEND_FULL(&stable_mail_sessions, session, stable_prev, stable_next); DLLIST2_APPEND_FULL(&mail_sessions_head, &mail_sessions_tail, session, sorted_prev, sorted_next); DLLIST_PREPEND_FULL(&session->user->sessions, session, user_prev, user_next); mail_user_ref(session->user); if (session->ip != NULL) { DLLIST_PREPEND_FULL(&session->ip->sessions, session, ip_prev, ip_next); mail_ip_ref(session->ip); } global_memory_alloc(mail_session_memsize(session)); return 0; }
char * params_to_string(Wht *W) { /** * \todo Use i_itoa to calculate DIGIT_SIZE */ const size_t DIGIT_SIZE = 32; size_t bufsize, n; int i; char *buf; char tmp[DIGIT_SIZE]; n = W->rule->n; bufsize = DIGIT_SIZE*n + (n-1) + 1; /* n DIGITS + (n-1) COMMAS + '\0' */ buf = i_malloc(sizeof(char) * bufsize); buf[0] = '\0'; for (i = 0; i < n; i++) { snprintf(tmp, DIGIT_SIZE, "%d", W->rule->params[i]); strncat(buf, tmp, strlen(tmp)); if (i != n - 1) strncat(buf, ",", 1); } return buf; }
void ICVM_X11TransConvertAddress(void){ Xtransaddr *ma; void *m; int family; int addrlen; family=RDs32(rSTKs32(0),0); addrlen=RDs32(rSTKs32(1),0); m=(void *)RDs32(rSTKs32(2),0); R_R0=-1; ma=(Xtransaddr *)malloc(addrlen); if(ma==0){ R_ERRNO1=ICVM_ENOMEM; return; } memcpy(ma,m,addrlen); i_free(m); R_R0=_X11TransConvertAddress(&family,&addrlen,&ma); icvm_SetErr(); if(R_R0==-1 || ma==0) icvm_SetErr(); WDs32(rSTKs32(0),family,0); WDs32(rSTKs32(1),addrlen,0); m=i_malloc(addrlen); if(m) memcpy(m,ma,addrlen); else R_ERRNO1=ICVM_ENOMEM; free(ma); WDs32(rSTKs32(2),m,0); }
/** \todo Fix memory leak @ name_to_string:151 */ char * name_to_string(Wht *W) { char *buf, *tmp; size_t len; len = strlen(W->rule->name) + 1; buf = i_malloc(sizeof(char) * len); snprintf(buf, len, "%s", W->rule->name); if (W->rule != NULL && W->rule->n > 0) { tmp = params_to_string(W); len += strlen(tmp) + 3; /* ( .. ) \0 */ buf = realloc(buf, sizeof(char) * len); strncat(buf,"(",1); strncat(buf, tmp, strlen(tmp) + 1); strncat(buf,")",1); i_free(tmp); } if (W->children == NULL) { tmp = i_itoa(W->n); len += strlen(tmp) + 3; /* ( .. ) \0 */ buf = realloc(buf, sizeof(char) * len); strncat(buf,"[",1); strncat(buf, tmp, strlen(tmp) + 1); strncat(buf,"]",1); i_free(tmp); } return buf; }
struct stats_dist *stats_dist_init_with_size(unsigned int sample_count) { i_assert(sample_count > 0); struct stats_dist *stats = i_malloc(sizeof(struct stats_dist) + sizeof(uint64_t) * sample_count); stats->sample_count = sample_count; return stats; }
void ICVM_IceTransGetMyNetworkId(void){ char *t=0; char *s=_IceTransGetMyNetworkId((ciptr)rSTKs32(0)); if(s){ t=i_malloc(strlen(s)+1); if(t) strcpy(t,s); free(s); } R_R0=(s32) t; icvm_SetErr(); }
void mail_index_set_ext_init_data(struct mail_index *index, uint32_t ext_id, const void *data, size_t size) { const struct mail_index_registered_ext *rext; i_assert(index->ext_hdr_init_data == NULL || index->ext_hdr_init_id == ext_id); rext = array_idx(&index->extensions, ext_id); i_assert(rext->hdr_size == size); index->ext_hdr_init_id = ext_id; i_free(index->ext_hdr_init_data); index->ext_hdr_init_data = i_malloc(size); memcpy(index->ext_hdr_init_data, data, size); }
static const struct mail_index_record * tview_apply_flag_updates(struct mail_index_view_transaction *tview, struct mail_index_map *map, const struct mail_index_record *rec, uint32_t seq) { struct mail_index_transaction *t = tview->t; const struct mail_index_flag_update *updates; struct mail_index_record *trec; unsigned int idx, count; /* see if there are any flag updates */ if (seq < t->min_flagupdate_seq || seq > t->max_flagupdate_seq || !array_is_created(&t->updates)) return rec; updates = array_get(&t->updates, &count); idx = mail_index_transaction_get_flag_update_pos(t, 0, count, seq); if (seq < updates[idx].uid1 || seq > updates[idx].uid2) return rec; /* yes, we have flag updates. since we can't modify rec directly and we want to be able to handle multiple mail_index_lookup() calls without the second one overriding the first one's data, we'll create a records array and return data from there. it's also possible that the record size increases, so we potentially have to create multiple arrays. they all get eventually freed when the view gets freed. */ if (map->hdr.record_size > tview->record_size) { if (!array_is_created(&tview->all_recs)) i_array_init(&tview->all_recs, 4); tview->recs_count = t->first_new_seq; tview->record_size = I_MAX(map->hdr.record_size, tview->view.map->hdr.record_size); tview->recs = i_malloc(tview->record_size * tview->recs_count); array_append(&tview->all_recs, &tview->recs, 1); } i_assert(tview->recs_count == t->first_new_seq); i_assert(seq > 0 && seq <= tview->recs_count); trec = PTR_OFFSET(tview->recs, (seq-1) * tview->record_size); memcpy(trec, rec, map->hdr.record_size); trec->flags |= updates[idx].add_flags; trec->flags &= ~updates[idx].remove_flags; return trec; }
/** * \todo Investigate the stability of calculation method */ static void apply_direct(Wht *W, long S, size_t D, wht_value *x) { long N = W->N; int n = W->n; wht_value *y = (wht_value *) i_malloc(N * sizeof(wht_value)); long i, j; /* Matrix multiplication, result is in y */ for (i = 0; i < N; i++) { y[i] = 0; for (j = 0; j < N; j++) y[i] += wht_entry(n, i+1, j+1) * x[j*S]; } /* Copy y to x with stride S */ for (i = 0; i < N; i++) x[i*S] = y[i]; i_free(y); }
struct mail_user *mail_user_login(const char *username) { struct mail_user *user; const char *domain; user = hash_table_lookup(mail_users_hash, username); if (user != NULL) { user->num_logins++; mail_user_refresh(user, NULL); mail_domain_login(user->domain); return user; } domain = strchr(username, '@'); if (domain != NULL) domain++; else domain = ""; user = i_malloc(sizeof(struct mail_user) + stats_alloc_size()); user->stats = (void *)(user + 1); user->name = i_strdup(username); user->reset_timestamp = ioloop_time; user->domain = mail_domain_login_create(domain); hash_table_insert(mail_users_hash, user->name, user); DLLIST_PREPEND_FULL(&stable_mail_users, user, stable_prev, stable_next); DLLIST2_APPEND_FULL(&mail_users_head, &mail_users_tail, user, sorted_prev, sorted_next); DLLIST_PREPEND_FULL(&user->domain->users, user, domain_prev, domain_next); mail_domain_ref(user->domain); user->num_logins++; user->last_update = ioloop_timeval; global_memory_alloc(mail_user_memsize(user)); return user; }
static bool generate_dh_parameters(int bitsize, int fd, const char *fname) { DH *dh = DH_generate_parameters(bitsize, DH_GENERATOR, NULL, NULL); unsigned char *buf, *p; int len; if (dh == NULL) return FALSE; len = i2d_DHparams(dh, NULL); if (len < 0) i_fatal("i2d_DHparams() failed: %s", ssl_last_error()); buf = p = i_malloc(len); len = i2d_DHparams(dh, &p); if (write_full(fd, &bitsize, sizeof(bitsize)) < 0 || write_full(fd, &len, sizeof(len)) < 0 || write_full(fd, buf, len) < 0) i_fatal("write_full() failed for file %s: %m", fname); i_free(buf); return TRUE; }
static struct mail_command * mail_command_add(struct mail_session *session, const char *name, const char *args) { struct mail_command *cmd; cmd = i_malloc(MALLOC_ADD(sizeof(struct mail_command), stats_alloc_size())); cmd->stats = (void *)(cmd + 1); cmd->refcount = 1; /* unrefed at "done" */ cmd->session = session; cmd->name = i_strdup(name); cmd->args = i_strdup(args); cmd->last_update = ioloop_timeval; DLLIST2_APPEND_FULL(&stable_mail_commands_head, &stable_mail_commands_tail, cmd, stable_prev, stable_next); DLLIST_PREPEND_FULL(&session->commands, cmd, session_prev, session_next); mail_session_ref(cmd->session); global_memory_alloc(mail_command_memsize(cmd)); return cmd; }
void ICVM_XimXTransGetMyAddr(void){ Xtransaddr *ma; void *m; int family; int addrlen; R_R0=_XimXTransGetMyAddr( (char *)rSTKs32(0), &family,&addrlen,&ma ); icvm_SetErr(); if(R_R0==-1 || ma==0) return; WDs32(rSTKs32(1),family,0); WDs32(rSTKs32(2),addrlen,0); m=i_malloc(addrlen); if(m) memcpy(m,ma,addrlen); else R_ERRNO1=ICVM_ENOMEM; free(ma); WDs32(rSTKs32(3),m,0); }
AdditionSettingsWidget* AdditionSettingsWidget_ctor(ModbusParams* mb) { Point pt; Size s; AdditionSettingsWidget* obj = (AdditionSettingsWidget*) i_malloc(sizeof(AdditionSettingsWidget)); obj->widget = Widget_ctor(); obj->widget->parent = obj; obj->perCicle = TextBox_ctor(); obj->perCalib = TextBox_ctor(); obj->maxError = TextBox_ctor(); obj->startCalib = Button_ctor(); obj->autoCalibState = CheckBox_ctor(); obj->params = mb; obj->_AdditionSettingsWidget = &_dstr_AdditionSettingsWidget; pt = GetPoint(380, 240, 0); s = GetSize(160, 170); obj->widget->mainForm->base->SetBounds(obj->widget->mainForm->base, &pt, &s); obj->widget->mainForm->Caption = "Addition settings"; obj->widget->mainForm->closeBtn->eventClick.Method = &closeBtn_Click; /* Controls */ obj->perCicle->base->Location = GetPoint(10, 35, 0); obj->perCicle->base->ParentLocation = obj->widget->mainForm->base->Location; obj->perCicle->base->Size = GetSize(50, obj->perCicle->base->Size.Height); obj->perCicle->base->Visible = true; obj->perCicle->base->Enable = true; obj->perCicle->parent = obj; obj->perCalib->base->Location = GetPoint(10, 70, 0); obj->perCalib->base->ParentLocation = obj->widget->mainForm->base->Location; obj->perCalib->base->Size = GetSize(50, obj->perCalib->base->Size.Height); obj->perCalib->base->Visible = true; obj->perCalib->base->Enable = true; obj->perCalib->parent = obj; obj->maxError->base->Location = GetPoint(10, 105, 0); obj->maxError->base->ParentLocation = obj->widget->mainForm->base->Location; obj->maxError->base->Size = GetSize(50, obj->maxError->base->Size.Height); obj->maxError->base->Visible = true; obj->maxError->base->Enable = true; obj->maxError->parent = obj; obj->startCalib->base->Location = GetPoint(70, 35, 0); obj->startCalib->base->ParentLocation = obj->widget->mainForm->base->Location; obj->startCalib->base->Size = GetSize(60, obj->startCalib->base->Size.Height); obj->startCalib->base->Visible = true; obj->startCalib->base->Enable = true; obj->startCalib->Caption = "Start"; obj->startCalib->parent = obj; obj->startCalib->eventClick.Method = &startCalib_Click; obj->autoCalibState->base->Location = GetPoint(10, 140, 0); obj->autoCalibState->base->ParentLocation = obj->widget->mainForm->base->Location; obj->autoCalibState->base->Visible = true; obj->autoCalibState->base->Enable = true; obj->autoCalibState->Caption = "Autocalib"; obj->autoCalibState->parent = obj; obj->autoCalibState->eventClick.Method = &autoCalib_Click; obj->widget->AddControl(obj->widget, obj->perCalib->base); obj->widget->AddControl(obj->widget, obj->perCicle->base); obj->widget->AddControl(obj->widget, obj->maxError->base); obj->widget->AddControl(obj->widget, obj->startCalib->base); obj->widget->AddControl(obj->widget, obj->autoCalibState->base); obj->mbUpdate.Method = &mbUpdateFunc; RelocateElements(obj->widget->mainForm); return obj; }
static int uidlist_write_array(struct ostream *output, const uint32_t *uid_list, unsigned int uid_count, uint32_t packed_flags, uint32_t offset, bool write_size, uint32_t *size_r) { uint8_t *uidbuf, *bufp, sizebuf[SQUAT_PACK_MAX_SIZE], *sizebufp; uint8_t listbuf[SQUAT_PACK_MAX_SIZE], *listbufp = listbuf; uint32_t uid, uid2, prev, base_uid, size_value; unsigned int i, bitmask_len, uid_list_len; unsigned int idx, max_idx, mask; bool datastack; int num; if ((packed_flags & UIDLIST_PACKED_FLAG_BEGINS_WITH_POINTER) != 0) squat_pack_num(&listbufp, offset); /* @UNSAFE */ base_uid = uid_list[0] & ~UID_LIST_MASK_RANGE; datastack = uid_count < 1024*8/SQUAT_PACK_MAX_SIZE; if (datastack) uidbuf = t_malloc_no0(SQUAT_PACK_MAX_SIZE * uid_count); else uidbuf = i_malloc(SQUAT_PACK_MAX_SIZE * uid_count); bufp = uidbuf; squat_pack_num(&bufp, base_uid); bitmask_len = (uid_list[uid_count-1] - base_uid + 7) / 8 + (bufp - uidbuf); if (bitmask_len < uid_count) { bitmask_build: i_assert(bitmask_len < SQUAT_PACK_MAX_SIZE*uid_count); memset(bufp, 0, bitmask_len - (bufp - uidbuf)); if ((uid_list[0] & UID_LIST_MASK_RANGE) == 0) { i = 1; uid = i == uid_count ? 0 : uid_list[i]; } else { i = 0; uid = uid_list[0] + 1; } base_uid++; for (; i < uid_count; i++) { i_assert((uid & ~UID_LIST_MASK_RANGE) >= base_uid); if ((uid & UID_LIST_MASK_RANGE) == 0) { uid -= base_uid; uid2 = uid; } else { uid &= ~UID_LIST_MASK_RANGE; uid -= base_uid; uid2 = uid_list[i+1] - base_uid; i++; } if (uid2 - uid < 3*8) { for (; uid <= uid2; uid++) bufp[uid / 8] |= 1 << (uid % 8); } else { /* first byte */ idx = uid / 8; num = uid % 8; if (num != 0) { uid += 8 - num; for (mask = 0; num < 8; num++) mask |= 1 << num; bufp[idx++] |= mask; } /* middle bytes */ num = uid2 % 8; max_idx = idx + (uid2 - num - uid)/8; for (; idx < max_idx; idx++, uid += 8) bufp[idx] = 0xff; /* last byte */ for (mask = 0; num >= 0; num--) mask |= 1 << num; bufp[idx] |= mask; } uid = i+1 == uid_count ? 0 : uid_list[i+1]; } uid_list_len = bitmask_len; packed_flags |= UIDLIST_PACKED_FLAG_BITMASK; } else { bufp = uidbuf; prev = 0; for (i = 0; i < uid_count; i++) { uid = uid_list[i]; if (unlikely((uid & ~UID_LIST_MASK_RANGE) < prev)) { if (!datastack) i_free(uidbuf); return -1; } if ((uid & UID_LIST_MASK_RANGE) == 0) { squat_pack_num(&bufp, (uid - prev) << 1); prev = uid + 1; } else { uid &= ~UID_LIST_MASK_RANGE; squat_pack_num(&bufp, 1 | (uid - prev) << 1); squat_pack_num(&bufp, uid_list[i+1] - uid - 1); prev = uid_list[i+1] + 1; i++; } } uid_list_len = bufp - uidbuf; if (uid_list_len > bitmask_len) { bufp = uidbuf; squat_pack_num(&bufp, base_uid); goto bitmask_build; } } size_value = ((uid_list_len + (listbufp - listbuf)) << 2) | packed_flags; if (write_size) { sizebufp = sizebuf; squat_pack_num(&sizebufp, size_value); o_stream_nsend(output, sizebuf, sizebufp - sizebuf); } o_stream_nsend(output, listbuf, listbufp - listbuf); o_stream_nsend(output, uidbuf, uid_list_len); if (!datastack) i_free(uidbuf); *size_r = size_value; return 0; }
struct mail_search_sort_program * index_sort_program_init(struct mailbox_transaction_context *t, const enum mail_sort_type *sort_program) { struct mail_search_sort_program *program; unsigned int i; if (sort_program == NULL || sort_program[0] == MAIL_SORT_END) return NULL; /* we support internal sorting by the primary condition */ program = i_new(struct mail_search_sort_program, 1); program->t = t; program->temp_mail = mail_alloc(t, 0, NULL); for (i = 0; i < MAX_SORT_PROGRAM_SIZE; i++) { program->sort_program[i] = sort_program[i]; if (sort_program[i] == MAIL_SORT_END) break; } if (i == MAX_SORT_PROGRAM_SIZE) i_panic("index_sort_program_init(): Invalid sort program"); switch (program->sort_program[0] & MAIL_SORT_MASK) { case MAIL_SORT_ARRIVAL: case MAIL_SORT_DATE: { ARRAY_TYPE(mail_sort_node_date) *nodes; nodes = i_malloc(sizeof(*nodes)); i_array_init(nodes, 128); if ((program->sort_program[0] & MAIL_SORT_MASK) == MAIL_SORT_ARRIVAL) program->sort_list_add = index_sort_list_add_arrival; else program->sort_list_add = index_sort_list_add_date; program->sort_list_finish = index_sort_list_finish_date; program->context = nodes; break; } case MAIL_SORT_SIZE: { ARRAY_TYPE(mail_sort_node_size) *nodes; nodes = i_malloc(sizeof(*nodes)); i_array_init(nodes, 128); program->sort_list_add = index_sort_list_add_size; program->sort_list_finish = index_sort_list_finish_size; program->context = nodes; break; } case MAIL_SORT_CC: case MAIL_SORT_FROM: case MAIL_SORT_SUBJECT: case MAIL_SORT_TO: case MAIL_SORT_DISPLAYFROM: case MAIL_SORT_DISPLAYTO: program->sort_list_add = index_sort_list_add_string; program->sort_list_finish = index_sort_list_finish_string; index_sort_list_init_string(program); break; case MAIL_SORT_RELEVANCY: { ARRAY_TYPE(mail_sort_node_float) *nodes; nodes = i_malloc(sizeof(*nodes)); i_array_init(nodes, 128); program->sort_list_add = index_sort_list_add_relevancy; program->sort_list_finish = index_sort_list_finish_float; program->context = nodes; break; } case MAIL_SORT_POP3_ORDER: { ARRAY_TYPE(mail_sort_node_size) *nodes; nodes = i_malloc(sizeof(*nodes)); i_array_init(nodes, 128); program->sort_list_add = index_sort_list_add_pop3_order; program->sort_list_finish = index_sort_list_finish_size; program->context = nodes; break; } default: i_unreached(); } return program; }
O_Object* O_Object_ctor(void) { O_Object* o_obj = (O_Object*)(i_malloc(sizeof(O_Object))); return o_obj; }
static int i_stream_decrypt_header_contents(struct decrypt_istream *stream, const unsigned char *data, size_t size) { const unsigned char *end = data + size; bool failed = FALSE; /* read cipher OID */ const char *calg; if (!i_stream_decrypt_der(&data, end, &calg)) return 0; if (calg == NULL || !dcrypt_ctx_sym_create(calg, DCRYPT_MODE_DECRYPT, &(stream->ctx_sym), NULL)) { io_stream_set_error(&stream->istream.iostream, "Decryption error: unsupported/invalid cipher: %s", calg); return -1; } /* read MAC oid (MAC is used for PBKDF2 and key data digest, too) */ const char *malg; if (!i_stream_decrypt_der(&data, end, &malg)) return 0; if (malg == NULL || !dcrypt_ctx_hmac_create(malg, &(stream->ctx_mac), NULL)) { io_stream_set_error(&stream->istream.iostream, "Decryption error: unsupported/invalid MAC algorithm: %s", malg); return -1; } /* read rounds (for PBKDF2) */ uint32_t rounds; if (!get_msb32(&data, end, &rounds)) return 0; /* read key data length */ uint32_t kdlen; if (!get_msb32(&data, end, &kdlen)) return 0; size_t tagsize; if ((stream->flags & IO_STREAM_ENC_INTEGRITY_HMAC) == IO_STREAM_ENC_INTEGRITY_HMAC) { tagsize = IOSTREAM_TAG_SIZE; } else if ((stream->flags & IO_STREAM_ENC_INTEGRITY_AEAD) == IO_STREAM_ENC_INTEGRITY_AEAD) { tagsize = IOSTREAM_TAG_SIZE; } else { tagsize = 0; } /* how much key data we should be getting */ size_t kl = dcrypt_ctx_sym_get_key_length(stream->ctx_sym) + dcrypt_ctx_sym_get_iv_length(stream->ctx_sym) + tagsize; buffer_t *keydata = buffer_create_dynamic(pool_datastack_create(), kl); /* try to decrypt the keydata with a private key */ int ret; if ((ret = i_stream_decrypt_key(stream, malg, rounds, data, end, keydata, kl)) <= 0) return ret; /* oh, it worked! */ const unsigned char *ptr = keydata->data; if (keydata->used != kl) { /* but returned wrong amount of data */ io_stream_set_error(&stream->istream.iostream, "Key decryption error: Key data length mismatch"); return -1; } /* prime contexts */ dcrypt_ctx_sym_set_key(stream->ctx_sym, ptr, dcrypt_ctx_sym_get_key_length(stream->ctx_sym)); ptr += dcrypt_ctx_sym_get_key_length(stream->ctx_sym); dcrypt_ctx_sym_set_iv(stream->ctx_sym, ptr, dcrypt_ctx_sym_get_iv_length(stream->ctx_sym)); stream->iv = i_malloc(dcrypt_ctx_sym_get_iv_length(stream->ctx_sym)); memcpy(stream->iv, ptr, dcrypt_ctx_sym_get_iv_length(stream->ctx_sym)); ptr += dcrypt_ctx_sym_get_iv_length(stream->ctx_sym); /* based on the chosen MAC, initialize HMAC or AEAD */ if ((stream->flags & IO_STREAM_ENC_INTEGRITY_HMAC) == IO_STREAM_ENC_INTEGRITY_HMAC) { const char *error; dcrypt_ctx_hmac_set_key(stream->ctx_mac, ptr, tagsize); if (!dcrypt_ctx_hmac_init(stream->ctx_mac, &error)) { io_stream_set_error(&stream->istream.iostream, "MAC error: %s", error); stream->istream.istream.stream_errno = EINVAL; failed = TRUE; } stream->ftr = dcrypt_ctx_hmac_get_digest_length(stream->ctx_mac); stream->use_mac = TRUE; } else if ((stream->flags & IO_STREAM_ENC_INTEGRITY_AEAD) == IO_STREAM_ENC_INTEGRITY_AEAD) { dcrypt_ctx_sym_set_aad(stream->ctx_sym, ptr, tagsize); stream->ftr = tagsize; stream->use_mac = TRUE; } else { stream->use_mac = FALSE; } /* destroy private key data */ safe_memset(buffer_get_modifiable_data(keydata, 0), 0, keydata->used); buffer_set_used_size(keydata, 0); return failed ? -1 : 1; }
int main( int argc, char **argv) { char fname[256]; char nom[256]; struct image *nf; Fort_int lfmt[9]; unsigned char *buf , *buf2; int sb = 0, i, j,z; struct pt_x* pt; struct pt_x *res; struct pt_x * tabPt_x; char reponse; float hr , hs; hr = 20; hs = 20; /* Initialisation */ inr_init( argc, argv, version, usage, detail); /* Lecture des options */ infileopt( fname); igetopt1("-hs", "%f", &hs); igetopt1("-hr", "%f", &hr); igetopt1("-max","%d", &max); igetopt1("-v","%d",&VOSIN); igetopt1("-n","%d",&noyau); igetopt1("-m","%d",&mode); igetopt1("-d","%d",&debug); outfileopt(nom); /*affichage the options */ fprintf(stderr, "=============OPTIONS===========\n"); fprintf(stderr, "hr = %f hs = %f\n",hr,hs); fprintf(stderr, "Voisnage = %d\n",VOSIN); if(noyau == 1){ fprintf(stderr, "Noyau = gaussian\n"); }else{ fprintf(stderr, "Noyau = epankovic\n"); } if(mode == 1){ fprintf(stderr, "Mode = segmentation\n"); }else{ fprintf(stderr, "Mode = debruit\n"); } printf("Image src = %s\n",fname); printf("Image target = %s\n",nom); printf("Mode debug = %d\n",debug); fprintf(stderr, "===============================\n"); fprintf(stderr, "would you like to continue the execution with current options ? (y,n)\n"); scanf("%c",&reponse); if(reponse!='y'){ return 0; } fprintf(stderr, "Start of execution\n"); /* Ouverture et lecture des images */ nf = image_(fname, "e", "", lfmt); /* verification du format */ if(TYPE == FIXE && BSIZE==1){ /* allocation memoire adequat */ buf = (unsigned char*)i_malloc( NDIMX * NDIMY* NDIMV *sizeof(unsigned char)); /* cree tableau de pt_x */ tabPt_x = malloc(NDIMX* NDIMY* NDIMV *sizeof(pt_x)); /* lecture image */ c_lect( nf, NDIMY, buf); }else{ imerror( 6, "codage non conforme\n"); } /* Remplir de Struct Special */ if(NDIMV == 1){ remplir_basic(buf,tabPt_x,NDIMX,NDIMY); } if(NDIMV == 3){ remplir_rgb(buf,tabPt_x,NDIMX,NDIMY); } /* Traitement */ /*debruit*/ buf2 = (unsigned char*)i_malloc( NDIMX * NDIMY*NDIMV*sizeof(unsigned char)); if(mode == 0){ if(NDIMV == 1){ debruit_basic(tabPt_x,buf2,hs,hr,1,NDIMX,NDIMY); }else{ debruit_rgb(tabPt_x,buf2,hs,hr,1,NDIMX,NDIMY); } }else{ segmentation(tabPt_x , buf2 , hs , hr , 0.1 , NDIMX, NDIMY); } /*sauvgarde*/ printf("sortir \n"); nf = c_image(nom,"c","",lfmt); c_ecr(nf,DIMY,buf2); /* fermeture image */ fermnf_( &nf); //free(&his); i_Free((void*)&buf); i_Free((void*)&buf2); return 0; }
static int call_dspam(const char *signature, enum classification wanted) { pid_t pid; const char *class_arg; const char *sign_arg; int pipes[2]; sign_arg = t_strconcat("--signature=", signature, NULL); switch (wanted) { case CLASS_NOTSPAM: class_arg = t_strconcat("--class=", "innocent", NULL); break; case CLASS_SPAM: class_arg = t_strconcat("--class=", "spam", NULL); break; } /* * For dspam stderr; dspam seems to not always exit with a * non-zero exit code on errors so we treat it as an error * if it logged anything to stderr. */ if (pipe(pipes) < 0) return -1; pid = fork(); if (pid < 0) return -1; if (pid) { int status; char buf[1025]; int readsize; bool error = FALSE; close(pipes[1]); do { readsize = read(pipes[0], buf, sizeof(buf) - 1); if (readsize < 0) { readsize = -1; if (errno == EINTR) readsize = -2; } /* * readsize > 0 means that we read a message from * dspam, -1 means we failed to read for some odd * reason */ if (readsize > 0 || readsize == -1) error = TRUE; if (readsize > 0) { buf[readsize] = '\0'; debug("dspam error: %s\n", buf); } } while (readsize == -2 || readsize > 0); /* * Wait for dspam, should return instantly since we've * already waited above (waiting for stderr to close) */ waitpid(pid, &status, 0); if (!WIFEXITED(status)) error = TRUE; close(pipes[0]); if (error) return 1; return WEXITSTATUS(status); } else { int fd = open("/dev/null", O_RDONLY); char **argv; /* 4 fixed args, extra args, terminating NULL */ int sz = sizeof(char *) * (4 + extra_args_num + 1); int i; argv = i_malloc(sz); memset(argv, 0, sz); close(0); close(1); close(2); /* see above */ close(pipes[0]); if (dup2(pipes[1], 2) != 2) exit(1); if (dup2(pipes[1], 1) != 1) exit(1); close(pipes[1]); if (dup2(fd, 0) != 0) exit(1); close(fd); argv[0] = (char *)dspam_binary; argv[1] = "--source=error"; argv[2] = (char *)class_arg; argv[3] = (char *)sign_arg; for (i = 0; i < extra_args_num; i++) argv[i + 4] = (char *)extra_args[i]; /* * not good with stderr debuggin since we then write to * stderr which our parent takes as a bug */ debugv_not_stderr(argv); execv(dspam_binary, argv); debug("executing %s failed: %d (uid=%d, gid=%d)", dspam_binary, errno, getuid(), getgid()); /* fall through if dspam can't be found */ exit(127); /* not reached */ return -1; } }
ChannelPanelMenu* ChannelPanelMenu_ctor(ModbusParams* mb) { uint16_t i; Point p; Size s; ChannelPanelMenu* obj = (ChannelPanelMenu*) i_malloc(sizeof(ChannelPanelMenu)); obj->panel = FullPanel_ctor(); obj->panel->parent = obj; obj->params = mb; obj->_ChannelPanelMenu = &_dstr_ChannelPanelMenu; obj->panel->mainForm->closeBtn->eventClick.Method = &closeBtn_Click; // Controls for(i = 0; i < 16;i++) { uint16_t a; a = i % 8; s = GetSize(50, 50); p = GetPoint(40 + a*(s.Width + 15), (i / 8)*(s.Height + 15) + 100, 0); obj->chlsRb[i] = Radiobutton_ctor(); obj->chlsRb[i]->base->SetBounds(obj->chlsRb[i]->base, &p, &s); obj->chlsRb[i]->base->ParentLocation = obj->panel->mainForm->base->Location; obj->chlsRb[i]->eventClick.Method = &chnlsRb_Click; obj->chlsRb[i]->ID = i; if (i < 8) obj->chlsRb[i]->base->StyleCtrl.ColorDown = GetColorRGB(0, 0xc0, 0); else obj->chlsRb[i]->base->StyleCtrl.ColorDown = GetColorRGB(0xf0, 0, 0); obj->chlsRb[i]->parent = obj; obj->panel->AddControl(obj->panel, obj->chlsRb[i]->base); } for(i = 0; i < 12; i++) { s = GetSize(30, 30); p = GetPoint(600, i * (s.Height + 5) + 50, 0); obj->chBoxFlagsError[i] = CheckBox_ctor(); obj->chBoxFlagsError[i]->base->SetBounds(obj->chBoxFlagsError[i]->base, &p, &s); obj->chBoxFlagsError[i]->base->ParentLocation = obj->panel->mainForm->base->Location; obj->chBoxFlagsError[i]->ID = i; obj->chBoxFlagsError[i]->base->StyleCtrl.ColorDown = GetColorRGB(0xf0, 0, 0); obj->chBoxFlagsError[i]->parent = obj; obj->panel->AddControl(obj->panel, obj->chBoxFlagsError[i]->base); } obj->chBoxFlagsError[0]->Caption = "Voltage small"; obj->chBoxFlagsError[1]->Caption = "Temperature max"; obj->chBoxFlagsError[2]->Caption = "sensor density error"; obj->chBoxFlagsError[3]->Caption = "sensor dp"; obj->chBoxFlagsError[4]->Caption = "dp filt max"; obj->chBoxFlagsError[5]->Caption = "error density"; obj->chBoxFlagsError[6]->Caption = "Voltage max"; obj->chBoxFlagsError[7]->Caption = "calc val != mes value"; obj->chBoxFlagsError[8]->Caption = "input d min"; obj->chBoxFlagsError[9]->Caption = "error input sensor"; obj->chBoxFlagsError[10]->Caption = "bypass"; obj->chBoxFlagsError[11]->Caption = "avar on filt"; obj->textBoxPeriodCicle = TextBox_ctor(); s = GetSize(100, 40); p = GetPoint(450, s.Height + 200, 0); obj->textBoxPeriodCicle->base->SetBounds(obj->textBoxPeriodCicle->base, &p, &s); obj->textBoxPeriodCicle->base->ParentLocation = obj->panel->mainForm->base->Location; obj->textBoxPeriodCicle->parent = obj; obj->textBoxPeriodCicle->eventClick.Method = &textBoxPeriodCicle_Click; obj->panel->AddControl(obj->panel, obj->textBoxPeriodCicle->base); obj->textBoxPeriodCalib = TextBox_ctor(); s = GetSize(100, 40); p = GetPoint(450, s.Height + 260, 0); obj->textBoxPeriodCalib->base->SetBounds(obj->textBoxPeriodCalib->base, &p, &s); obj->textBoxPeriodCalib->base->ParentLocation = obj->panel->mainForm->base->Location; obj->textBoxPeriodCalib->parent = obj; obj->textBoxPeriodCalib->eventClick.Method = &textBoxPeriodCalib_Click; obj->panel->AddControl(obj->panel, obj->textBoxPeriodCalib->base); obj->textBoxMaxError = TextBox_ctor(); s = GetSize(100, 40); p = GetPoint(450, s.Height + 320, 0); obj->textBoxMaxError->base->SetBounds(obj->textBoxMaxError->base, &p, &s); obj->textBoxMaxError->base->ParentLocation = obj->panel->mainForm->base->Location; obj->textBoxMaxError->parent = obj; obj->textBoxMaxError->eventClick.Method = &textBoxMaxError_Click; obj->panel->AddControl(obj->panel, obj->textBoxMaxError->base); obj->mbUpdate.Method = &mbUpdateFunc; obj->panel->Draw = &_draw; RelocateElements(obj->panel->mainForm); return obj; }