static int do_test (int argc, char *argv[]) { int result = 0; utmpname (name); result |= do_init (); result |= do_check (); result |= simulate_login ("tty1", "erwin"); result |= do_check (); result |= simulate_login ("ttyp1", "paul"); result |= do_check (); result |= simulate_logout ("tty2"); result |= do_check (); result |= simulate_logout ("ttyp0"); result |= do_check (); result |= simulate_login ("ttyp2", "richard"); result |= do_check (); result |= check_login ("tty1"); result |= check_logout ("ttyp0"); result |= check_id ("p1"); result |= check_id ("2"); result |= check_id ("si"); result |= check_type (BOOT_TIME); result |= check_type (RUN_LVL); return result; }
unit_type::unit_type(const config &cfg, const std::string & parent_id) : cfg_(cfg), unit_cfg_(), built_unit_cfg_(false), id_(cfg_.has_attribute("id") ? cfg_["id"].str() : parent_id), debug_id_(), base_id_(!parent_id.empty() ? parent_id : id_), type_name_(cfg_["name"].t_str()), description_(), hitpoints_(0), hp_bar_scaling_(0.0), xp_bar_scaling_(0.0), level_(0), recall_cost_(), movement_(0), vision_(-1), jamming_(0), max_attacks_(0), cost_(0), usage_(), undead_variation_(), image_(cfg_["image"].str()), icon_(), small_profile_(), profile_(), flag_rgb_(cfg_["flag_rgb"].str()), num_traits_(0), gender_types_(), variations_(), default_variation_(cfg_["variation"]), variation_name_(cfg_["variation_name"].t_str()), race_(&unit_race::null_race), alpha_(ftofxp(1.0)), abilities_(), adv_abilities_(), ability_tooltips_(), adv_ability_tooltips_(), zoc_(false), hide_help_(false), do_not_list_(cfg_["do_not_list"].to_bool(false)), advances_to_(), experience_needed_(0), in_advancefrom_(false), alignment_(unit_type::ALIGNMENT::NEUTRAL), movement_type_(), possible_traits_(), genders_(), animations_(), build_status_(NOT_BUILT) { check_id(id_); check_id(base_id_); gender_types_[0] = nullptr; gender_types_[1] = nullptr; }
static VALUE inst_put_obj(VALUE self, VALUE arg, const char *field) { struct ngraph_instance *inst1, *inst2; ngraph_value str; char buf[128]; const char *name, *ptr; int *ids; struct objlist *obj; switch (TYPE(arg)) { case T_NIL: ptr = NULL; break; case T_STRING: ptr = StringValueCStr(arg); obj = ngraph_get_object_instances_by_str(ptr, NULL, &ids); if (obj == NULL) { rb_raise(rb_eArgError, "%s#%s: illegal instance representation (%s).", rb_obj_classname(self), field, ptr); } ngraph_free(ids); break; default: if (! rb_obj_is_kind_of(arg, NgraphClass)) { rb_raise(rb_eArgError, "%s#%s: illegal type of the argument (%s).", rb_obj_classname(self), field, rb_obj_classname(arg)); } inst2 = check_id(arg); if (inst2 == NULL) { return Qnil; } name = ngraph_get_object_name(inst2->obj); #if 0 snprintf(buf, sizeof(buf), "%s:%d", name, inst2->id); #else snprintf(buf, sizeof(buf), "%s:^%d", name, inst2->oid); /* shoud instance be tighten? */ #endif ptr = buf; } inst1 = check_id(self); if (inst1 == NULL) { return Qnil; } str.str = ptr; inst1->rcode = ngraph_object_put(inst1->obj, field, inst1->id, &str); if (inst1->rcode < 0) { return Qnil; } return arg; }
bool req_key_h(connection_t *c) { char from_name[MAX_STRING_SIZE]; char to_name[MAX_STRING_SIZE]; node_t *from, *to; if(sscanf(c->buffer, "%*d " MAX_STRING " " MAX_STRING, from_name, to_name) != 2) { logger(LOG_ERR, "Got bad %s from %s (%s)", "REQ_KEY", c->name, c->hostname); return false; } if(!check_id(from_name) || !check_id(to_name)) { logger(LOG_ERR, "Got bad %s from %s (%s): %s", "REQ_KEY", c->name, c->hostname, "invalid name"); return false; } from = lookup_node(from_name); if(!from) { logger(LOG_ERR, "Got %s from %s (%s) origin %s which does not exist in our connection list", "REQ_KEY", c->name, c->hostname, from_name); return true; } to = lookup_node(to_name); if(!to) { logger(LOG_ERR, "Got %s from %s (%s) destination %s which does not exist in our connection list", "REQ_KEY", c->name, c->hostname, to_name); return true; } /* Check if this key request is for us */ if(to == myself) { /* Yes, send our own key back */ if (!send_ans_key(from)) return false; } else { if(tunnelserver) return true; if(!to->status.reachable) { logger(LOG_WARNING, "Got %s from %s (%s) destination %s which is not reachable", "REQ_KEY", c->name, c->hostname, to_name); return true; } send_request(to->nexthop->connection, "%s", c->buffer); } return true; }
void load_all_nodes(meshlink_handle_t *mesh) { DIR *dir; struct dirent *ent; char dname[PATH_MAX]; snprintf(dname,PATH_MAX, "%s" SLASH "hosts", mesh->confbase); dir = opendir(dname); if(!dir) { logger(mesh, MESHLINK_ERROR, "Could not open %s: %s", dname, strerror(errno)); return; } while((ent = readdir(dir))) { if(!check_id(ent->d_name)) continue; node_t *n = lookup_node(mesh, ent->d_name); if(n) continue; n = new_node(); n->name = xstrdup(ent->d_name); node_read_devclass(mesh, n); node_add(mesh, n); } closedir(dir); }
void server(struct sockaddr_un *sun) { int s, fd; struct sockaddr_storage client_addr; socklen_t client_len; char *problem; s = socket(AF_UNIX, SOCK_STREAM, 0); if (s == -1) err(1, "Bad socket"); if (bind(s, (struct sockaddr *)sun, sizeof(*sun)) != 0) err(1, "bind"); if (listen(s, 5) != 0) { unlink(path); rmdir(dir); err(1, "listen"); } fd = accept(s, (struct sockaddr *)&client_addr, &client_len); if (fd == -1) { unlink(path); rmdir(dir); err(1, "accept"); } problem = check_id(fd); if (problem) { unlink(path); rmdir(dir); errx(1, problem); } unlink(path); rmdir(dir); }
void client(struct sockaddr_un *sun) { int s; int i; int r; char *problem; s = socket(AF_UNIX, SOCK_STREAM, 0); if (s == -1) err(1, "Bad socket"); /* XXX make sure the server started alright */ for (i = 0; i < 10; i++) { r = connect(s, (struct sockaddr *)sun, sizeof(*sun)); if (r == 0) { problem = check_id(s); if (problem) errx(1, problem); exit(0); } sleep(5); } errx(1, "Could not connect after 10 tries"); }
int cmdScanSensor(CLISESSION *pSession, int argc, char **argv, void *pHandler) { EUI64 id; int idx=0; int major=0, minor=0, build=0; if (!Confirm(pSession, MSG_DEFAULT)) return CLIERR_OK; CIF4Invoke invoke("127.0.0.1", m_nLocalAgentPort, 50*60); if(check_id(NULL, argv[idx])) { // EUI64 ID StrToEUI64(argv[idx], &id); invoke.AddParamFormat("4.3.1", VARSMI_EUI64, (void *)&id, sizeof(EUI64)); }else { // Parser invoke.AddParam("1.11", argv[idx]); } idx ++; if(argc > 1) { major = minor = 0; sscanf(argv[idx],"%d.%d", &major, &minor); invoke.AddParam("1.5",(WORD) (((major & 0xff) << 8) + (minor & 0xff))); idx++; } if(argc > 2) { build = (int) strtol(argv[idx],(char **)NULL,10); invoke.AddParam("1.5",(WORD)build); idx++; } if (!CLIAPI_Command(pSession, invoke.GetHandle(), "102.35")) return CLIERR_OK; return CLIERR_OK; }
static VALUE create_obj_arg(VALUE args) { int i, n; VALUE arg, str, uniq_args; struct ngraph_instance *inst; struct objlist *obj = NULL; const char *name; uniq_args = rb_funcall(args, Uniq, 0); n = RARRAY_LEN(uniq_args); str = rb_str_new2(""); for (i = 0; i < n; i++) { arg = rb_ary_entry(uniq_args, i); if (! rb_obj_is_kind_of(arg, NgraphClass)) { return Qnil; } inst = check_id(arg); if (inst == NULL) { return Qnil; } if (obj == NULL) { obj = inst->obj; name = ngraph_get_object_name(inst->obj); rb_str_cat2(str, name); } else if (obj != inst->obj) { return Qnil; } rb_str_catf(str, "%c%d", (i) ? ',' : ':', inst->id); } return str; }
bool Button::xml_start(const QString & qName, const QXmlAttributes & atts) { //printf("Procesando botón %s\n",qName.toLocal8Bit().data() ); //mButton *w=(mButton *)widget; if(qName=="button" && check_id(atts) ) { //QString icon=atts.value("icon"); //if(!title.isEmpty()) widget->setWindowTitle ( atts.value("title") ); widget_properties(atts,this); return true; } else if(qName=="text") { return true; } else if(qName=="icon") { return true; } else if(qName=="signal") { QString signal=atts.value("name"); if(signal=="clicked") QObject::connect((mButton*)widget, SIGNAL(clicked()), (mButton*)widget, SLOT(clicked_cb()) ); return true; } return false; }
static VALUE ruby_ngraph_exec_loginshell(VALUE module, VALUE cmd, VALUE nobj) { int r; size_t len; const char *str; char *loginshell; static struct ngraph_instance *inst; if (! rb_obj_is_kind_of(nobj, NgraphClass)) { rb_raise(rb_eArgError, "%s: illegal type of the argument (%s).", rb_obj_classname(module), rb_obj_classname(nobj)); } if (NIL_P(cmd)) { loginshell = NULL; } else { str = StringValueCStr(cmd); len = strlen(str) + 1; loginshell = ALLOCA_N(char, len); if (loginshell == NULL) { rb_raise(rb_eSysStackError, "%s: cannot allocate enough memory.", rb_obj_classname(module)); } strcpy(loginshell, str); } inst = check_id(nobj); r = ngraph_exec_loginshell(loginshell, inst->obj, inst->id); return INT2FIX(r); }
static VALUE inst_get_sarray(VALUE self, const char *field) { struct ngraph_instance *inst; ngraph_returned_value cary; ngraph_arg carg; VALUE ary; int i; inst = check_id(self); if (inst == NULL) { return Qnil; } carg.num = 0; inst->rcode = ngraph_object_get(inst->obj, field, inst->id, &carg, &cary); if (inst->rcode < 0) { return Qnil; } ary = rb_ary_new2(cary.ary.num); for (i = 0; i < cary.ary.num; i++) { rb_ary_store(ary, i, tainted_utf8_str_new(cary.ary.data.sa[i])); } return ary; }
struct ocmem_buf *ocmem_allocate(int client_id, unsigned long size) { bool can_block = false; bool can_wait = true; if (!check_id(client_id)) { pr_err("ocmem: Invalid client id: %d\n", client_id); return NULL; } if (size < OCMEM_MIN_ALLOC) { pr_err("ocmem: requested size %lx must be at least %x\n", size, OCMEM_MIN_ALLOC); return NULL; } if (!IS_ALIGNED(size, OCMEM_MIN_ALIGN)) { pr_err("ocmem: Invalid alignment, size must be %x aligned\n", OCMEM_MIN_ALIGN); return NULL; } return __ocmem_allocate_range(client_id, size, size, size, can_block, can_wait); }
struct ocmem_buf *ocmem_allocate_nb(int client_id, unsigned long size) { bool can_block = true; bool can_wait = false; if (!check_id(client_id)) { pr_err("ocmem: Invalid client id: %d\n", client_id); return NULL; } /* Asynchronous API requires notifier registration */ if (!check_notifier(client_id)) { pr_err("ocmem: No notifier registered for client %d\n", client_id); return NULL; } if (size < OCMEM_MIN_ALLOC) { pr_err("ocmem: requested size %lx must be at least %x\n", size, OCMEM_MIN_ALLOC); return NULL; } if (!IS_ALIGNED(size, OCMEM_MIN_ALIGN)) { pr_err("ocmem: Invalid alignment, args must be %x aligned\n", OCMEM_MIN_ALIGN); return NULL; } return __ocmem_allocate_range(client_id, 0, size, size, can_block, can_wait); }
int check_idparser(CLISESSION *pSession, char *pszValue) { int ret = check_id(pSession, pszValue); if(!ret) ret = check_string(pSession, pszValue); return ret; }
int check_allid(CLISESSION *pSession, char *pszValue) { // 'all' Check if (strcmp(pszValue, "all") == 0) return 1; return check_id(pSession, pszValue); }
unsigned long get_max_quota(int client_id) { if (!check_id(client_id)) { pr_err("ocmem: Invalid client id: %d\n", client_id); return 0x0; } return process_quota(client_id); }
/* Read Subnets from all host config files */ void load_all_subnets(void) { DIR *dir; struct dirent *ent; char *dname; char *fname; avl_tree_t *config_tree; config_t *cfg; subnet_t *s, *s2; node_t *n; bool result; xasprintf(&dname, "%s/hosts", confbase); dir = opendir(dname); if(!dir) { logger(LOG_ERR, "Could not open %s: %s", dname, strerror(errno)); free(dname); return; } while((ent = readdir(dir))) { if(!check_id(ent->d_name)) continue; n = lookup_node(ent->d_name); #ifdef _DIRENT_HAVE_D_TYPE //if(ent->d_type != DT_REG) // continue; #endif xasprintf(&fname, "%s/hosts/%s", confbase, ent->d_name); init_configuration(&config_tree); result = read_config_file(config_tree, fname); free(fname); if(!result) continue; if(!n) { n = new_node(); n->name = xstrdup(ent->d_name); node_add(n); } for(cfg = lookup_config(config_tree, "Subnet"); cfg; cfg = lookup_config_next(config_tree, cfg)) { if(!get_config_subnet(cfg, &s)) continue; if((s2 = lookup_subnet(n, s))) { s2->expires = -1; } else { subnet_add(n, s); } } exit_configuration(&config_tree); } closedir(dir); }
expr_rec process_id(void) { expr_rec t; /*Declare ID and built a corresponding semantic record*/ check_id(token_buffer); t.kind = IDEXPR; strcpy(t.name, token_buffer); return t; }
char *get_temp(void) { /*max temporary allocated so far*/ static int max_temp = 0; static char tempname[MAXIDLEN]; max_temp++; sprintf(tempname,"Temp&%d",max_temp); check_id(tempname); return tempname; }
static VALUE ngraph_inst_method_rcode(VALUE klass) { struct ngraph_instance *inst; inst = check_id(klass); if (inst == NULL) { return Qnil; } return INT2FIX(inst->rcode); }
int check_notifier(int id) { int ret = 0; if (!check_id(id)) return 0; mutex_lock(&nc_lock); ret = notifiers[id].listeners; mutex_unlock(&nc_lock); return ret; }
static int check_inst_args(VALUE self, VALUE arg, const char *field, struct ngraph_instance **inst1, struct ngraph_instance **inst2) { *inst1 = check_id(self); if (*inst1 == NULL) { return 1; } if (! rb_obj_is_kind_of(arg, NgraphClass)) { rb_raise(rb_eArgError, "%s#%s: illegal type of the argument (%s).", rb_obj_classname(self), field, rb_obj_classname(arg)); } *inst2 = check_id(arg); if (*inst2 == NULL) { return 1; } if ((*inst1)->obj != (*inst2)->obj) { rb_raise(rb_eArgError, "%s#%s: illegal type of the argument (%s).", rb_obj_classname(self), field, rb_obj_classname(arg)); } return 0; }
static VALUE ngraph_inst_method_move_last(VALUE klass) { struct ngraph_instance *inst; inst = check_id(klass); if (inst == NULL) { return Qnil; } inst->id = ngraph_object_move_last(inst->obj, inst->id); return klass; }
int ocmem_free(int client_id, struct ocmem_buf *buffer) { if (!check_id(client_id)) { pr_err("ocmem: Invalid client id: %d\n", client_id); return -EINVAL; } if (!buffer) { pr_err("ocmem: Invalid buffer\n"); return -EINVAL; } return __ocmem_free(client_id, buffer); }
void wi_bwmrestore(char *url, int len, char *boundary) { char *buf; const char *error; int ok; int n; char tmp[64]; check_id(url); tmp[0] = 0; buf = NULL; error = "Error reading file"; ok = 0; if (!skip_header(&len)) { goto ERROR; } if ((len < 64) || (len > 10240)) { goto ERROR; } if ((buf = malloc(len)) == NULL) { error = "Not enough memory"; goto ERROR; } n = web_read(buf, len); len -= n; sprintf(tmp, "%s.new", hfn); if (f_write(tmp, buf, n, 0, 0600) != n) { unlink(tmp); error = "Error writing temporary file"; goto ERROR; } f_write("/var/tmp/rstats-load", NULL, 0, 0, 0600); killall("rstats", SIGHUP); sleep(1); error = NULL; rboot = 1; // used as "ok" ERROR: free(buf); web_eat(len); if (error != NULL) resmsg_set(error); }
char *get_name(meshlink_handle_t *mesh) { char *name = NULL; get_config_string(lookup_config(mesh->config, "Name"), &name); if(!name) return NULL; if(!check_id(name)) { logger(mesh, MESHLINK_ERROR, "Invalid name for mesh->self!"); free(name); return NULL; } return name; }
static VALUE inst_put_sarray(VALUE self, VALUE arg, const char *field) { struct ngraph_instance *inst; ngraph_value ary; int num, i; VALUE str, tmpstr; inst = check_id(self); if (inst == NULL) { return Qnil; } if (NIL_P(arg)) { num = 0; } else { if (!RB_TYPE_P(arg, T_ARRAY)) { rb_raise(rb_eArgError, "%s#%s: the argument must be an Array", rb_obj_classname(self), field); } num = RARRAY_LEN(arg); } ary.ary = NULL; if (num > 0) { ary.ary = rb_alloc_tmp_buffer(&tmpstr, sizeof(*ary.ary) + sizeof(ngraph_value) * num); ary.ary->num = num; if (ary.ary) { for (i = 0; i < num; i++) { str = rb_ary_entry(arg, i); ary.ary->ary[i].str = StringValueCStr(str); } } } inst->rcode = ngraph_object_put(inst->obj, field, inst->id, &ary); if (ary.ary) { rb_free_tmp_buffer(&tmpstr); } if (inst->rcode < 0) { return Qnil; } return arg; }
static VALUE ngraph_inst_method_del(VALUE self) { int id; struct ngraph_instance *inst; inst = check_id(self); if (inst == NULL) { return Qnil; } id = inst->id; inst->id = -1; ngraph_object_del(inst->obj, id); return INT2FIX(id); }
static VALUE ngraph_inst_method_to_str(VALUE klass) { struct ngraph_instance *inst; const char *name; VALUE rstr; inst = check_id(klass); if (inst == NULL) { return Qnil; } name = ngraph_get_object_name(inst->obj); rstr = rb_sprintf("%s:%d", name, inst->id); return rstr; }