static int mod_bootstrap(void *instance, CONF_SECTION *conf) { rlm_unbound_t *inst = instance; inst->name = cf_section_name2(conf); if (!inst->name) inst->name = cf_section_name1(conf); if (inst->timeout > 10000) { cf_log_err(conf, "timeout must be 0 to 10000"); return -1; } MEM(inst->xlat_a_name = talloc_typed_asprintf(inst, "%s-a", inst->name)); MEM(inst->xlat_aaaa_name = talloc_typed_asprintf(inst, "%s-aaaa", inst->name)); MEM(inst->xlat_ptr_name = talloc_typed_asprintf(inst, "%s-ptr", inst->name)); if (xlat_register(inst, inst->xlat_a_name, xlat_a, NULL, NULL, 0, XLAT_DEFAULT_BUF_LEN, false) || xlat_register(inst, inst->xlat_aaaa_name, xlat_aaaa, NULL, NULL, 0, XLAT_DEFAULT_BUF_LEN, false) || xlat_register(inst, inst->xlat_ptr_name, xlat_ptr, NULL, NULL, 0, XLAT_DEFAULT_BUF_LEN, false)) { cf_log_err(conf, "Failed registering xlats"); return -1; } return 0; }
/** Create thread-specific connections and buffers * * @param[in] conf section containing the configuration of this module instance. * @param[in] instance of rlm_logtee_t. * @param[in] el The event list serviced by this thread. * @param[in] thread specific data. * @return * - 0 on success. * - -1 on failure. */ static int mod_thread_instantiate(UNUSED CONF_SECTION const *conf, void *instance, fr_event_list_t *el, void *thread) { rlm_logtee_t *inst = talloc_get_type_abort(instance, rlm_logtee_t); rlm_logtee_thread_t *t = talloc_get_type_abort(thread, rlm_logtee_thread_t); MEM(t->fring = fr_fring_alloc(t, inst->buffer_depth, false)); t->inst = inst; t->el = el; /* * Pre-allocate temporary attributes */ MEM(t->msg_pool = talloc_pool(t, 1024)); MEM(t->msg = fr_pair_afrom_da(t->msg_pool, attr_log_message)); MEM(t->type = fr_pair_afrom_da(t, attr_log_type)); MEM(t->lvl = fr_pair_afrom_da(t, attr_log_level)); /* * This opens the outbound connection */ t->conn = fr_connection_alloc(t, el, &inst->connection_timeout, &inst->reconnection_delay, _logtee_conn_init, _logtee_conn_open, _logtee_conn_close, inst->name, t); if (t->conn == NULL) return -1; fr_connection_signal_init(t->conn); return 0; }
int solve(){ //Init MEM(lx, 0); MEM(ly, 0); MEM(left, 0); for (int i = 1; i <= sv; i ++) for (int j = 1; j <= tv; j ++) lx[i] = max(lx[i], w[i][j]); //Main for (int i = 1; i <= sv; i ++){ for (int j = 1; j <= tv; j ++) slack[j] = oo; while(1){ MEM(S, false); MEM(T, false); if (cross_path(i)){ break; } else{ int d = oo; for (int j = 1; j <= tv; j ++) if (!T[j]) d = min(d, slack[j]); for (int j = 1; j <= sv; j ++) if (S[j]) lx[j] -= d; for (int j = 1; j <= tv; j ++){ if (T[j]) ly[j] += d; else slack[j] -= d; //匈牙利树中T集点ly不变,S集点lx减小,更新slack值 } } } } int res = 0; for(int i = 1; i <= sv; i ++) res += lx[i]; for(int i = 1; i <= tv; i ++) res += ly[i]; return res; }
void mrc_dump_process() { /* generate instruction into uncacheable memory (else we would have to flush I and D caches) */ void *alloc_buf = malloc(32); void *func_buf = UNCACHEABLE(alloc_buf); unsigned int addr_func = (unsigned int)UNCACHEABLE(func_buf); unsigned int (*func)() = (unsigned int (*)())addr_func; /* build MRC instruction */ unsigned int instr = 0xEE100010; instr |= (mrc_op1<<21); instr |= (mrc_crn<<16); instr |= (0<<12); instr |= (mrc_cp<<8); instr |= (mrc_op2<<5); instr |= mrc_crm; /* write along with RET */ MEM(addr_func) = instr; MEM(addr_func + 4) = 0xE1A0F00E; /* call generated code */ mrc_value = func(); free(alloc_buf); }
void NameList::grow() { int newmax=max+GRANULARITY; names=(char**)realloc(names, newmax*sizeof(char*)); MEM(names); touched=(bool*)realloc(touched, newmax*sizeof(bool)); MEM(touched); max=newmax; }
void LookupGrid::doneSizing(void) { rvfloat size_x1, size_x2, size_z1, size_z2; int i; size_x1 = (xhi-xlo)/60.0; size_z1= (zhi-zlo)/60.0; size_x2 = size_z2 = 500.0; data.raster_size=rint((size_x1+ size_x2+ size_z1+ size_z2) / 4.0); data.x0 = xlo; data.z0 = zlo; data.x_size = ceil((xhi-xlo)/data.raster_size); data.z_size = ceil((zhi-zlo)/data.raster_size); xsz=(int)data.x_size; zsz=(int)data.z_size; ichains=new IndexChain*[zsz*xsz]; MEM(ichains); for(i=0;i<zsz*xsz;i++) { ichains[i]=new IndexChain; MEM(ichains[i]); }; lprintf(3,"LookupGrid: bounds are X(%g..%g), Z(%g..%g)\n",xlo,xhi,zlo,zhi); lprintf(3,"LookupGrid: created %dx%d grid\n",xsz,zsz); lprintf(3,"LookupGrid: origin (%g,%g), raster_size %g\n",data.x0,data.z0,data.raster_size); }
int main(int argc, char **argv) { int i; unsigned long t; setvbuf(stdout, (char *) NULL, _IOLBF, 0); if (argc != 2 && argc != 3) { fprintf(stderr, "syntax: %s input_file [-r]\n", argv[0]); return 1; } if (*argv[1] == '-') { fprintf(stderr, "syntax: %s input_file [-r]\n", argv[0]); return 1; } if ((FP = fopen(argv[1], "r")) == NULL) { fprintf(stderr, "%s: cannot open input file %s\n", argv[0], argv[1]); return 1; } if (argc == 3) { if (strcmp(argv[2], "-r") == 0) { Redir = (char *) RedirPrefix; fprintf(stdout, "%s\n", argv[0]); } else { fprintf(stderr, "syntax: %s input_file [-r]\n", argv[0]); return 1; } } memset(Mem, 0, MEMSIZE * sizeof(unsigned)); for (i = PCINIT; !feof(FP); i += 4) { if (fgets(Buf, BUFSIZE, FP) == NULL) { if (feof(FP)) break; fprintf(stderr, "%s: file %s reading error\n", argv[0], argv[1]); return 1; } if (sscanf(Buf, "%lx", &t) != 1) { fprintf(stderr, "%s: file %s error in line %d, continue...\n", argv[0], argv[1], i - PCINIT + 1); MEM(i) = 0; } else { MEM(i) = strtoul(Buf, (char **) NULL, 16); } } Loop(); fclose(FP); return 0; }
void uemd_em_init(void) { MEM(0x2003c050)=0x9; //DDR PHY ODT ON ddr_init(DMC0_APB_BASE); MEM(0x2003c064)=0x9; //DDR PHY ODT ON ddr_init(DMC1_APB_BASE); }
void qfio_read(char* buf, int num) // read "num" bytes from QEMU FIO buffer, into "buf" { MEM(REG_FIO_BUFFER_SEEK) = 0; for (int i = 0; i < num; i++) { buf[i] = MEM(REG_FIO_BUFFER); } }
/* * Convert a buffer to a CSV entry */ static rlm_csv_entry_t *file2csv(CONF_SECTION *conf, rlm_csv_t *inst, int lineno, char *buffer) { rlm_csv_entry_t *e; int i; char *p, *q; MEM(e = (rlm_csv_entry_t *)talloc_zero_array(inst->tree, uint8_t, sizeof(*e) + inst->used_fields + sizeof(e->data[0]))); talloc_set_type(e, rlm_csv_entry_t); for (p = buffer, i = 0; p != NULL; p = q, i++) { if (!buf2entry(inst, p, &q)) { cf_log_err(conf, "Malformed entry in file %s line %d", inst->filename, lineno); return NULL; } if (q) *(q++) = '\0'; if (i >= inst->num_fields) { cf_log_err(conf, "Too many fields at file %s line %d", inst->filename, lineno); return NULL; } /* * This is the key field. */ if (i == inst->key_field) { e->key = talloc_typed_strdup(e, p); continue; } /* * This field is unused. Ignore it. */ if (inst->field_offsets[i] < 0) continue; MEM(e->data[inst->field_offsets[i]] = talloc_typed_strdup(e, p)); } if (i < inst->num_fields) { cf_log_err(conf, "Too few fields at file %s line %d (%d < %d)", inst->filename, lineno, i, inst->num_fields); return NULL; } /* * FIXME: Allow duplicate keys later. */ if (!rbtree_insert(inst->tree, e)) { cf_log_err(conf, "Failed inserting entry for filename %s line %d: duplicate entry", inst->filename, lineno); return NULL; } return e; }
int debug_console_getc(void) { char c; // Wait until the serial RX buffer is not empty while (MEM(SERIAL_BASE + SERIAL_FLAG_REGISTER) & (SERIAL_RX_BUFFER_EMPTY)) ; c = 0xFF & MEM(SERIAL_BASE); return c; }
int debug_console_getc(void) { char c; // Wait until the serial RX buffer is not empty while(!MEM(DEBUG_CONSOLE_SERIAL_BASE + SERIAL_FLAG_REGISTER) & SERIAL_RX_READY) ; c = 0xFF & MEM(DEBUG_CONSOLE_SERIAL_BASE); return c; }
int compute_keys(UNUSED REQUEST *request, pwd_session_t *session, uint8_t *peer_confirm, uint8_t *msk, uint8_t *emsk) { HMAC_CTX *hmac_ctx; uint8_t mk[SHA256_DIGEST_LENGTH], *cruft; uint8_t session_id[SHA256_DIGEST_LENGTH + 1]; uint8_t msk_emsk[128]; /* 64 each */ int offset; MEM(cruft = talloc_array(session, uint8_t, BN_num_bytes(session->prime))); MEM(hmac_ctx = HMAC_CTX_new()); /* * first compute the session-id = TypeCode | H(ciphersuite | scal_p | * scal_s) */ session_id[0] = FR_EAP_METHOD_PWD; HMAC_Init_ex(hmac_ctx, allzero, SHA256_DIGEST_LENGTH, EVP_sha256(), NULL); HMAC_Update(hmac_ctx, (uint8_t *)&session->ciphersuite, sizeof(session->ciphersuite)); offset = BN_num_bytes(session->order) - BN_num_bytes(session->peer_scalar); memset(cruft, 0, BN_num_bytes(session->prime)); BN_bn2bin(session->peer_scalar, cruft + offset); HMAC_Update(hmac_ctx, cruft, BN_num_bytes(session->order)); offset = BN_num_bytes(session->order) - BN_num_bytes(session->my_scalar); memset(cruft, 0, BN_num_bytes(session->prime)); BN_bn2bin(session->my_scalar, cruft + offset); HMAC_Update(hmac_ctx, cruft, BN_num_bytes(session->order)); pwd_hmac_final(hmac_ctx, (uint8_t *)&session_id[1]); /* then compute MK = H(k | commit-peer | commit-server) */ HMAC_Init_ex(hmac_ctx, allzero, SHA256_DIGEST_LENGTH, EVP_sha256(), NULL); memset(cruft, 0, BN_num_bytes(session->prime)); offset = BN_num_bytes(session->prime) - BN_num_bytes(session->k); BN_bn2bin(session->k, cruft + offset); HMAC_Update(hmac_ctx, cruft, BN_num_bytes(session->prime)); HMAC_Update(hmac_ctx, peer_confirm, SHA256_DIGEST_LENGTH); HMAC_Update(hmac_ctx, session->my_confirm, SHA256_DIGEST_LENGTH); pwd_hmac_final(hmac_ctx, mk); /* stretch the mk with the session-id to get MSK | EMSK */ eap_pwd_kdf(mk, SHA256_DIGEST_LENGTH, (char const *)session_id, SHA256_DIGEST_LENGTH + 1, msk_emsk, 1024); /* it's bits, ((64 + 64) * 8) */ memcpy(msk, msk_emsk, 64); memcpy(emsk, msk_emsk + 64, 64); HMAC_CTX_free(hmac_ctx); talloc_free(cruft); return 0; }
/* * Compare prefix/suffix. * * If they compare: * - if FR_STRIP_USER_NAME is present in check_list, * strip the username of prefix/suffix. * - if FR_STRIP_USER_NAME is not present in check_list, * add a FR_STRIPPED_USER_NAME to the request. */ static int prefix_suffix_cmp(UNUSED void *instance, REQUEST *request, VALUE_PAIR *req, VALUE_PAIR *check, VALUE_PAIR *check_list, UNUSED VALUE_PAIR **reply_list) { VALUE_PAIR *vp; char const *name; char rest[FR_MAX_STRING_LEN]; int len, namelen; int ret = -1; if (!request || !request->username) return -1; VP_VERIFY(check); name = request->username->vp_strvalue; RDEBUG3("Comparing name \"%s\" and check value \"%s\"", name, check->vp_strvalue); len = strlen(check->vp_strvalue); if (check->da == attr_prefix) { ret = strncmp(name, check->vp_strvalue, len); if (ret == 0) strlcpy(rest, name + len, sizeof(rest)); } else if (check->da == attr_suffix) { namelen = strlen(name); if (namelen >= len) { ret = strcmp(name + namelen - len, check->vp_strvalue); if (ret == 0) strlcpy(rest, name, namelen - len + 1); } } if (ret != 0) return ret; /* * If Strip-User-Name == No, then don't do any more. */ vp = fr_pair_find_by_da(check_list, attr_strip_user_name, TAG_ANY); if (vp && !vp->vp_uint32) return ret; /* * See where to put the stripped user name. */ vp = fr_pair_find_by_da(check_list, attr_stripped_user_name, TAG_ANY); if (!vp) { /* * If "request" is NULL, then the memory will be * lost! */ MEM(vp = fr_pair_afrom_da(request->packet, attr_stripped_user_name)); fr_pair_add(&req, vp); request->username = vp; } fr_pair_value_strcpy(vp, rest); return ret; }
int main(int argc, char **argv) { AppOptions appopt; appopt.cmd=CmdVis; appopt.parse(argc, argv); msglevel=appopt.msglevel; appopt.welcome(); if(appopt.listsyntax_only) { dump_visfile_syntax(); } else if(appopt.listobj_only) { ASEParser p(appopt.ase_name); p.parse(NULL, NULL, NULL); } else { ASEMeshList *meshes=new ASEMeshList(); MEM(meshes); ASEParser p(appopt.ase_name); p.parse(meshes, NULL, appopt.names); BoxList *b=meshes->createBoxes(appopt.list_name, /*vis=*/true); b->write_vis(appopt.out_name, appopt.safety_dist, 0.0); delete b; appopt.warn_untouched(); delete meshes; } return 0; }
/** Add a module failure message VALUE_PAIR to the request * * @param[in] request The current request. * @param[in] msg with printf style substitution tokens. * @param[in] ap Substitution arguments. */ void vlog_module_failure_msg(REQUEST *request, char const *msg, va_list ap) { char *p; VALUE_PAIR *vp; va_list aq; if (!msg || !request || !request->packet) return; rad_assert(attr_module_failure_message); /* * If we don't copy the original ap we get a segfault from vasprintf. This is apparently * due to ap sometimes being implemented with a stack offset which is invalidated if * ap is passed into another function. See here: * http://julipedia.meroh.net/2011/09/using-vacopy-to-safely-pass-ap.html * * I don't buy that explanation, but doing a va_copy here does prevent SEGVs seen when * running unit tests which generate errors under CI. */ va_copy(aq, ap); p = fr_vasprintf(request, msg, aq); va_end(aq); MEM(pair_add_request(&vp, attr_module_failure_message) >= 0); if (request->module && (request->module[0] != '\0')) { fr_pair_value_snprintf(vp, "%s: %s", request->module, p); } else { fr_pair_value_snprintf(vp, "%s", p); } talloc_free(p); }
static int arp_socket_decode(UNUSED rad_listen_t *listener, REQUEST *request) { int i; uint8_t const *p = request->packet->data, *end = p + request->packet->data_len; fr_cursor_t cursor; fr_cursor_init(&cursor, &request->packet->vps); for (i = 0; header_names[i].name != NULL; i++) { ssize_t ret; size_t len; fr_dict_attr_t const *da; VALUE_PAIR *vp = NULL; len = header_names[i].len; if (!fr_cond_assert((size_t)(end - p) < len)) return -1; /* Should have been detected in socket_recv */ da = fr_dict_attr_by_name(dict_arp, header_names[i].name); if (!da) return 0; MEM(vp = fr_pair_afrom_da(request->packet, da)); ret = fr_value_box_from_network(vp, &vp->data, da->type, da, p, len, true); if (ret <= 0) { fr_pair_to_unknown(vp); fr_pair_value_memcpy(vp, p, len); } DEBUG2("&%pP", vp); fr_cursor_insert(&cursor, vp); } return 0; }
/** Extract a named subcapture value from the request * * @note This is the PCRE variant of the function. * * @param[in] ctx To allocate subcapture buffer in. * @param[out] out Where to write the subcapture string. * @param[in] request to extract. * @param[in] name of subcapture. * @return * - 0 on success. * - -1 on notfound. */ int regex_request_to_sub_named(TALLOC_CTX *ctx, char **out, REQUEST *request, char const *name) { fr_regcapture_t *rc; char const *p; int ret; rc = request_data_reference(request, request, REQUEST_DATA_REGEX); if (!rc) { RDEBUG4("No subcapture data found"); *out = NULL; return 1; } ret = pcre_get_named_substring(rc->preg->compiled, rc->regmatch->subject, (int *)rc->regmatch->match_data, (int)rc->regmatch->used, name, &p); switch (ret) { case PCRE_ERROR_NOMEMORY: MEM(NULL); /* * We can't really fall through, but GCC 7.3 is * too stupid to realise that we can never get * here despite _fr_exit_now being marked as * NEVER_RETURNS. * * If we did anything else, compilers and static * analysis tools would probably complain about * code that could never be executed *sigh*. */ /* FALL-THROUGH */ /* * Not finding a substring is fine */ case PCRE_ERROR_NOSUBSTRING: RDEBUG4("No named capture group \"%s\"", name); *out = NULL; return -1; default: if (ret < 0) { *out = NULL; return -1; } /* * Check libpcre really is using our overloaded * memory allocation and freeing talloc wrappers. */ talloc_set_type(p, char); talloc_steal(ctx, p); RDEBUG4("Found \"%s\": %pV (%zu)", name, fr_box_strvalue_buffer(p), talloc_array_length(p) - 1); memcpy(out, &p, sizeof(*out)); break; } return 0; }
/** Add a module failure message VALUE_PAIR to the request */ void vmodule_failure_msg(REQUEST *request, char const *fmt, va_list ap) { char *p; VALUE_PAIR *vp; va_list aq; if (!fmt || !request->packet) { return; } /* * If we don't copy the original ap we get a segfault from vasprintf. This is apparently * due to ap sometimes being implemented with a stack offset which is invalidated if * ap is passed into another function. See here: * http://julipedia.meroh.net/2011/09/using-vacopy-to-safely-pass-ap.html * * I don't buy that explanation, but doing a va_copy here does prevent SEGVs seen when * running unit tests which generate errors under CI. */ va_copy(aq, ap); p = talloc_vasprintf(request, fmt, aq); va_end(aq); MEM(vp = pairmake_packet("Module-Failure-Message", NULL, T_OP_ADD)); if (request->module && (request->module[0] != '\0')) { pairsprintf(vp, "%s: %s", request->module, p); } else { pairsprintf(vp, "%s", p); } talloc_free(p); }
/** Handle a network control message callback for a new "watch directory" * * @param[in] ctx the network * @param[in] data the message * @param[in] data_size size of the data * @param[in] now the current time */ static void fr_network_directory_callback(void *ctx, void const *data, size_t data_size, UNUSED fr_time_t now) { int num_messages; fr_network_t *nr = ctx; fr_network_socket_t *s; fr_app_io_t const *app_io; fr_event_vnode_func_t funcs = { .extend = fr_network_vnode_extend }; rad_assert(data_size == sizeof(s->listen)); if (data_size != sizeof(s->listen)) return; s = talloc_zero(nr, fr_network_socket_t); rad_assert(s != NULL); s->nr = nr; memcpy(&s->listen, data, sizeof(s->listen)); s->number = nr->num_sockets++; MEM(s->waiting = fr_heap_create(s, waiting_cmp, fr_channel_data_t, channel.heap_id)); talloc_set_destructor(s, _network_socket_free); /* * Allocate the ring buffer for messages and packets. */ num_messages = s->listen->num_messages; if (num_messages < 8) num_messages = 8; s->ms = fr_message_set_create(s, num_messages, sizeof(fr_channel_data_t), s->listen->default_message_size * s->listen->num_messages); if (!s->ms) { fr_log(nr->log, L_ERR, "Failed creating message buffers for directory IO: %s", fr_strerror()); talloc_free(s); return; } app_io = s->listen->app_io; if (app_io->event_list_set) app_io->event_list_set(s->listen->app_io_instance, nr->el, nr); rad_assert(app_io->fd); s->fd = app_io->fd(s->listen->app_io_instance); s->filter = FR_EVENT_FILTER_VNODE; if (fr_event_filter_insert(nr, nr->el, s->fd, s->filter, &funcs, app_io->error ? fr_network_error : NULL, s) < 0) { PERROR("Failed adding new socket to event loop"); talloc_free(s); return; } (void) rbtree_insert(nr->sockets, s); (void) rbtree_insert(nr->sockets_by_num, s); DEBUG3("Using new socket with FD %d", s->fd); }
/** Do any RADIUS-layer fixups for proxying. * */ static void radius_fixups(rlm_radius_t *inst, REQUEST *request) { VALUE_PAIR *vp; /* * Check for proxy loops. */ if (RDEBUG_ENABLED) { fr_cursor_t cursor; for (vp = fr_cursor_iter_by_da_init(&cursor, &request->packet->vps, attr_proxy_state); vp; vp = fr_cursor_next(&cursor)) { if (vp->vp_length != 4) continue; if (memcmp(&inst->proxy_state, vp->vp_octets, 4) == 0) { RWARN("Possible proxy loop - please check server configuration."); break; } } } if (request->packet->code != FR_CODE_ACCESS_REQUEST) return; if (fr_pair_find_by_da(request->packet->vps, attr_chap_password, TAG_ANY) && !fr_pair_find_by_da(request->packet->vps, attr_chap_challenge, TAG_ANY)) { MEM(pair_add_request(&vp, attr_chap_challenge) >= 0); fr_pair_value_memcpy(vp, request->packet->vector, sizeof(request->packet->vector)); } }
static rlm_rcode_t CC_HINT(nonnull) mod_authorize(void *instance, UNUSED void *thread, REQUEST *request) { rlm_chap_t *inst = instance; VALUE_PAIR *vp; if (!fr_pair_find_by_da(request->packet->vps, attr_chap_password, TAG_ANY)) return RLM_MODULE_NOOP; /* * Create the CHAP-Challenge if it wasn't already in the packet. * * This is so that the rest of the code does not need to * understand CHAP. */ vp = fr_pair_find_by_da(request->packet->vps, attr_chap_challenge, TAG_ANY); if (!vp) { RDEBUG2("Creating CHAP-Challenge from the request authenticator"); MEM(vp = fr_pair_afrom_da(request->packet, attr_chap_challenge)); fr_pair_value_memcpy(vp, request->packet->vector, sizeof(request->packet->vector)); fr_pair_add(&request->packet->vps, vp); } if (!module_section_type_set(request, attr_auth_type, inst->auth_type)) return RLM_MODULE_NOOP; return RLM_MODULE_OK; }
int main(int argc, const char * argv[]) { List *cmnds = NULL; char *string = NULL; int quit = 0; ErrorCode errorCode = ERRORCODE_NO_ERROR, endOfFile = ERRORCODE_NO_ERROR; CATCH_ERROR(InitInput(&string), errHandler); // allocating input string MEM(string, initialError); // checking if allocation was successful, otherwise quiting while (endOfFile == ERRORCODE_NO_ERROR && quit != 1) // ends on <quit> command { ReleaseList(&cmnds); // releasing list of tokens endOfFile = ReadStringFromStream(stdin, &string); // reading string of unknown length CATCH_ERROR(Tokenize(string, &cmnds), errHandler); // creating a list of tokens from input string CATCH_ERROR(Route(cmnds, &quit), errHandler); // trying to find a matching method errHandler: PrintErrorFeedback(errorCode); // on error printing feedback info and continuing main loop } ReleaseList(&cmnds); // after escaping while ReleaseInput(string); return 0; initialError: return 1; }
/** Create thread instances where needed * * @param[in] ctx to allocate thread instance data in. * @param[in] inst to allocate thread-instance data for. * @return * - 0 on success. The node/thread specific data will be inserted * into xlat_thread_inst_tree. * - -1 on failure. */ static xlat_thread_inst_t *xlat_thread_inst_alloc(TALLOC_CTX *ctx, xlat_inst_t *inst) { xlat_thread_inst_t *thread_inst = NULL; (void)talloc_get_type_abort(inst, xlat_inst_t); #ifdef HAVE_TALLOC_POOLED_OBJECT if (inst->node->xlat->thread_inst_size) { MEM(thread_inst = talloc_pooled_object(ctx, xlat_thread_inst_t, 1, inst->node->xlat->thread_inst_size)); memset(thread_inst, 0, sizeof(*thread_inst)); } else #endif MEM(thread_inst = talloc_zero(ctx, xlat_thread_inst_t)); #ifdef HAVE_TALLOC_POOLED_OBJECT }
/* * Run the time-domain reflectometer... */ static void run_tdr(struct ie_softc *sc, volatile struct ie_tdr_cmd *cmd) { int result; cmd->com.ie_cmd_status = 0; cmd->com.ie_cmd_cmd = IE_CMD_TDR | IE_CMD_LAST; cmd->com.ie_cmd_link = 0xffff; cmd->ie_tdr_time = 0; sc->scb->ie_command_list = MK_16(MEM(sc), cmd); cmd->ie_tdr_time = 0; if (command_and_wait(sc, IE_CU_START, cmd, IE_STAT_COMPL)) result = 0x2000; else result = cmd->ie_tdr_time; ie_ack(sc, IE_ST_WHENCE); if (result & IE_TDR_SUCCESS) return; if (result & IE_TDR_XCVR) { printf("ie%d: transceiver problem\n", sc->unit); } else if (result & IE_TDR_OPEN) { printf("ie%d: TDR detected an open %d clocks away\n", sc->unit, result & IE_TDR_TIME); } else if (result & IE_TDR_SHORT) { printf("ie%d: TDR detected a short %d clocks away\n", sc->unit, result & IE_TDR_TIME); } else { printf("ie%d: TDR returned unknown status %x\n", sc->unit, result); } }
Bivec new_bivec(int small, int large) { MEM(Bivec, vec, (Bivec) malloc(sizeof(struct bivec))); MEM(,vec->small, (double *) calloc(small, sizeof(double))); MEM(,vec->large, (double *) calloc(large, sizeof(double))); return vec; }
/* * Allocates and return a new Tau */ Tau new_Tau() { MEM(Tau, tau, (Tau) malloc(sizeof(struct tau))); tau->last = tau->item = NULL; tau->L = 0; return tau; }
static int _map_proc_client_get_vp(TALLOC_CTX *ctx, VALUE_PAIR **out, REQUEST *request, vp_map_t const *map, void *uctx) { client_get_vp_ctx_t *client = uctx; VALUE_PAIR *head = NULL, *vp; fr_cursor_t cursor; fr_dict_attr_t const *da; CONF_PAIR const *cp; rad_assert(ctx != NULL); fr_cursor_init(&cursor, &head); /* * FIXME: allow multiple entries. */ if (map->lhs->type == TMPL_TYPE_ATTR) { da = map->lhs->tmpl_da; } else { char *attr; if (tmpl_aexpand(ctx, &attr, request, map->lhs, NULL, NULL) <= 0) { RWDEBUG("Failed expanding string"); return -1; } da = fr_dict_attr_by_name(request->dict, attr); if (!da) { RWDEBUG("No such attribute '%s'", attr); return -1; } talloc_free(attr); } for (cp = client->cp; cp; cp = cf_pair_find_next(client->cs, cp, client->field)) { char const *value = cf_pair_value(cp); MEM(vp = fr_pair_afrom_da(ctx, da)); if (fr_pair_value_from_str(vp, value, talloc_array_length(value) - 1, '\0', false) < 0) { RWDEBUG("Failed parsing value \"%pV\" for attribute %s: %s", fr_box_strvalue(value), map->lhs->tmpl_da->name, fr_strerror()); fr_pair_list_free(&head); talloc_free(vp); return -1; } vp->op = map->op; fr_cursor_append(&cursor, vp); if (map->op != T_OP_ADD) break; /* Create multiple attribute for multiple CONF_PAIRs */ } *out = head; return 0; }
/** Process an entry modification operation * * @note This is a callback for the sync_demux function. * * @param[in] conn the sync belongs to. * @param[in] config of the sync that received an entry. * @param[in] sync_id of the sync that received an entry. * @param[in] phase Refresh phase the sync is currently in. * @param[in] uuid of the entry. * @param[in] msg containing the entry. * @param[in] state The type of modification we need to perform to our * representation of the entry. * @param[in] user_ctx The listener. * @return * - 0 on success. * - -1 on failure. */ static int _proto_ldap_entry(fr_ldap_connection_t *conn, sync_config_t const *config, int sync_id, UNUSED sync_phases_t phase, uint8_t const uuid[SYNC_UUID_LENGTH], LDAPMessage *msg, sync_states_t state, void *user_ctx) { rad_listen_t *listen = talloc_get_type_abort(user_ctx, rad_listen_t); proto_ldap_inst_t *inst = talloc_get_type_abort(listen->data, proto_ldap_inst_t); fr_ldap_map_exp_t expanded; REQUEST *request; request = proto_ldap_request_setup(listen, inst, sync_id); if (!request) return -1; proto_ldap_attributes_add(request, config); request->packet->code = state; /* * Add the entry DN and attributes */ if (msg) { char *entry_dn; VALUE_PAIR *vp; entry_dn = ldap_get_dn(conn->handle, msg); MEM(pair_update_request(&vp, attr_ldap_sync_entry_dn) >= 0); ldap_memfree(entry_dn); MEM(pair_update_request(&vp, attr_ldap_sync_entry_uuid) >= 0); fr_pair_value_memcpy(vp, uuid, SYNC_UUID_LENGTH); } /* * Apply the attribute map */ if (fr_ldap_map_expand(&expanded, request, config->entry_map) < 0) { error: talloc_free(request); return -1; } if (fr_ldap_map_do(request, conn, NULL, &expanded, msg) < 0) goto error; // request_enqueue(request); return 0; }
/* * instantiates a new Tau_item */ Tau_item new_tau_item(char* string, double prob) { MEM(Tau_item, tau_item, (Tau_item) malloc(sizeof(struct tau_item))); tau_item->string = string; tau_item->probability = prob; tau_item->next = NULL; return tau_item; }