void TestSceneGraph() { auto t1 = SceneGraph<int>(); t1.insert(nullptr, 0); t1.insert(nullptr, (const int)1); auto n3 = t1.emplace(nullptr, 1729); auto n1 = t1.find(0); t1.find(1); t1.emplace(n3, 1); t1.emplace(n3, 2); t1.emplace(n1, 1); t1.emplace(n1, 2); auto n4 = t1.emplace(n1, 3); t1.insert(n4, 0); t1.insert(n4, 1); t1.insert(n4, 3); t1.insert(n4, 4); t1.find(1); t1.find(42); t1.find_child(n3, 2); t1.find_child(n1, 0); std::vector<SceneNode<int>*> nodes; t1.find_all_cached(0, std::equal_to<>(), nodes); nodes.clear(); t1.find_all_children(n1, 0, std::equal_to<>()); nodes.clear(); n3 = t1.parent_to(n4, n3); t1.remove(t1.find(1729), false); t1.remove(n1); }
void scenenode::remove_child(int id) { scenenode *n=find_child(id); if (n!=NULL) { m_children.remove(n); } }
void profile_ops_start(nialptr entr) { struct node *childnode; childnode = current_node->children[find_child(current_node, entr)]; set_start_time(childnode, profile_time()); current_node = childnode; }
void tree_node::add_node(INT l, INT depth, INT *path, INT i_data, BYTE *c_data, INT verbose_level) { INT i, idx; INT f_v = (verbose_level >= 1); INT f_vv = (verbose_level >= 2); if (f_v) { cout << "tree_node::add_node: depth=" << depth << " : "; INT_vec_print(cout, path, l); cout << endl; } if (l == 0) { if (f_vv) { cout << "add_node(): node of length 0" << endl; } init(0, NULL, FALSE, 0, TRUE, i_data, c_data, verbose_level); return; } idx = find_child(path[depth]); if (f_vv) { cout << "add_node(): find_child for " << path[depth] << " returns " << idx << endl; } if (idx == -1) { tree_node **new_children = new ptree_node[nb_children + 1]; for (i = 0; i < nb_children; i++) { new_children[i] = children[i]; } new_children[nb_children] = new tree_node; if (nb_children) delete [] children; children = new_children; nb_children++; if (f_vv) { cout << "nb_children increased to " << nb_children << endl; } if (l == depth + 1) { if (f_vv) { cout << "initializing terminal node" << endl; } children[nb_children - 1]->init(depth + 1, this, TRUE, path[depth], TRUE, i_data, c_data, verbose_level); return; } else { if (f_vv) { cout << "initializing intermediate node" << endl; } children[nb_children - 1]->init(depth + 1, this, TRUE, path[depth], FALSE, 0, NULL, verbose_level); idx = nb_children - 1; } } if (f_vv) { cout << "searching deeper" << endl; } children[idx]->add_node(l, depth + 1, path, i_data, c_data, verbose_level); }
path composite_box_rep::find_box_path (SI x, SI y, SI delta, bool force) { int m= find_child (x, y, delta, force); if (m==-1) return box_rep::find_box_path (x, y, delta, force); else { SI xx= x- sx(m), yy= y- sy(m); SI dd= delta + get_delta (xx, bs[m]->x1, bs[m]->x2); return path (m, bs[m]->find_box_path (xx, yy, dd, force)); } }
void rdp_connect(GtkButton *connect, gpointer erdp) { /*get the string info*/ GtkEntry *rip = (GtkEntry *) find_child(erdp, "address"); GtkEntry *ruser = (GtkEntry *) find_child(erdp, "user"); GtkEntry *rpass = (GtkEntry *) find_child(erdp, "pass"); /*format my strings correctly*/ char *fip = malloc(strlen("/v:")+strlen(gtk_entry_get_text(rip))+1); fip = g_strconcat("/v:", gtk_entry_get_text(rip), NULL); char *fuser = malloc(strlen("/u:")+strlen(gtk_entry_get_text(ruser))+1); fuser = g_strconcat("/u:", gtk_entry_get_text(ruser), NULL); char *fpass = malloc(strlen("/p:")+strlen(gtk_entry_get_text(rpass))+1); fpass = g_strconcat("/p:", gtk_entry_get_text(rpass), NULL); /*and call xfreerdp*/ g_printf("Calling xfreerdp with arguments: %s %s %s\n", fip, fuser, fpass); execl("/usr/bin/xfreerdp", "/cert-ignore", fip, fuser, fpass, NULL); /*code never gets here*/ return; }
/** * find_child - locates child node * @list: linked List nodes * @child: string to match from parents path * Description: Recurses linked list to find a matching Ntree node */ NTree *find_child(List *list, char *child) { if (!list || !list->node) return NULL; if (!list->node->str || !child) return NULL; if (strcmp(list->node->str, child) == 0) return list->node; return find_child(list->next, child); }
void composite_box_rep::loci (SI x, SI y, SI delta, list<string>& ids, rectangles& rs) { int m= find_child (x, y, delta, true); if (m == -1) box_rep::loci (x, y, delta, ids, rs); else { bs[m]->loci (x- sx(m), y- sy(m), delta + get_delta (x, x1, x2), ids, rs); rs= translate (rs, sx(m), sy(m)); } }
int main( int argc, char **argv ) { node *root = node_create(0,0); int i,slen = strlen(str)-1; for ( i=0;i<slen;i++ ) { node *v = node_create(i,1); if ( find_child(root,str[i])==NULL ) node_add_child( root, v ); else node_dispose( v ); } for ( i=0;i<slen;i++ ) { node *v = find_child(root,str[i]); if ( v == NULL ) printf("couldn't find %c\n",str[i]); } node_dispose( root ); }
// --protocol.print void protocol_print_filter(pid_t pid) { EUID_ASSERT(); (void) pid; #ifdef SYS_socket // if the pid is that of a firejail process, use the pid of the first child process EUID_ROOT(); char *comm = pid_proc_comm(pid); EUID_USER(); if (comm) { if (strcmp(comm, "firejail") == 0) { pid_t child; if (find_child(pid, &child) == 0) { pid = child; } } free(comm); } // check privileges for non-root users uid_t uid = getuid(); if (uid != 0) { uid_t sandbox_uid = pid_get_uid(pid); if (uid != sandbox_uid) { fprintf(stderr, "Error: permission denied.\n"); exit(1); } } // find the seccomp filter EUID_ROOT(); char *fname; if (asprintf(&fname, "/proc/%d/root%s", pid, RUN_PROTOCOL_CFG) == -1) errExit("asprintf"); struct stat s; if (stat(fname, &s) == -1) { printf("Cannot access seccomp filter.\n"); exit(1); } // read and print the filter protocol_filter_load(fname); free(fname); if (cfg.protocol) printf("%s\n", cfg.protocol); exit(0); #else fprintf(stderr, "Warning: --protocol not supported on this platform\n"); return; #endif }
void *trie_search(TrieNode *parent, const char *key) { TrieNode *child; if(*key) { child = find_child(parent, *key); if(child) { return trie_search(child, ++key); } else { return NULL; } } else { return parent->value; } }
int dictionary_delete(struct dictionary *dict, const wchar_t *word) { if (dict == NULL || word == NULL) return 0; if (dictionary_find(dict, word)) { struct dictionary *found = NULL; find_child(dict, &found, *word); delete_helper(found, NULL, word); return 1; } return 0; }
void seccomp_print_filter(pid_t pid) { // if the pid is that of a firejail process, use the pid of the first child process char *comm = pid_proc_comm(pid); if (comm) { // remove \n char *ptr = strchr(comm, '\n'); if (ptr) *ptr = '\0'; if (strcmp(comm, "firejail") == 0) { pid_t child; if (find_child(pid, &child) == 0) { pid = child; } } free(comm); } // check privileges for non-root users uid_t uid = getuid(); if (uid != 0) { struct stat s; char *dir; if (asprintf(&dir, "/proc/%u/ns", pid) == -1) errExit("asprintf"); if (stat(dir, &s) < 0) errExit("stat"); if (s.st_uid != uid) { printf("Error: permission denied.\n"); exit(1); } } // find the seccomp filter char *fname; if (asprintf(&fname, "/proc/%d/root/tmp/firejail/mnt/seccomp", pid) == -1) errExit("asprintf"); struct stat s; if (stat(fname, &s) == -1) { printf("Cannot access seccomp filter.\n"); exit(1); } // read and print the filter read_seccomp_file(fname); drop_privs(1); filter_debug(); exit(0); }
path composite_box_rep::find_box_path (SI x, SI y, SI delta, bool force, bool& found) { int i, n= subnr(), m= find_child (x, y, delta, force); if (m != -1) for (i=0; i<=n; i++) { int c= (m+i) % n; SI xx= x- sx(c), yy= y- sy(c); SI dd= delta + get_delta (xx, bs[c]->x1, bs[c]->x2); path r= path (c, bs[c]->find_box_path (xx, yy, dd, force, found)); if (found || i == n) return r; } return box_rep::find_box_path (x, y, delta, force, found); }
/** * Record the position where the latest suffix was inserted * @param p the position of j..i-1. * @param i the desired index of the extra char */ static void update_old_beta( pos *p, int i ) { if ( node_end(p->v,e) > p->loc ) { old_beta.v = p->v; old_beta.loc = p->loc+1; } else { node *u = find_child( p->v, str[i] ); old_beta.v = u; old_beta.loc = node_start( u ); } }
void seccomp_print_filter(pid_t pid) { EUID_ASSERT(); // if the pid is that of a firejail process, use the pid of the first child process char *comm = pid_proc_comm(pid); if (comm) { // remove \n char *ptr = strchr(comm, '\n'); if (ptr) *ptr = '\0'; if (strcmp(comm, "firejail") == 0) { pid_t child; if (find_child(pid, &child) == 0) { pid = child; } } free(comm); } // check privileges for non-root users uid_t uid = getuid(); if (uid != 0) { uid_t sandbox_uid = pid_get_uid(pid); if (uid != sandbox_uid) { fprintf(stderr, "Error: permission denied.\n"); exit(1); } } // find the seccomp filter EUID_ROOT(); char *fname; if (asprintf(&fname, "/proc/%d/root%s", pid, RUN_SECCOMP_CFG) == -1) errExit("asprintf"); struct stat s; if (stat(fname, &s) == -1) { printf("Cannot access seccomp filter.\n"); exit(1); } // read and print the filter read_seccomp_file(fname); drop_privs(1); filter_debug(); free(fname); exit(0); }
/// Descend into the path specified by \p arr, and add a new child there. /// Should be used only by Fl_Tree's internals. /// Adds the item based on the value of prefs.sortorder(). /// Fl_Tree_Item *Fl_Tree_Item::add(const Fl_Tree_Prefs &prefs, char **arr) { int t = find_child(*arr); Fl_Tree_Item *item; if ( t == -1 ) { item = (Fl_Tree_Item*)add(prefs, *arr); } else { item = (Fl_Tree_Item*)child(t); } if ( *(arr+1) ) { // descend? return(item->add(prefs, arr+1)); } else { return(item); // end? done } }
int dictionary_insert(struct dictionary *dict, const wchar_t *word) { assert(dict != NULL); struct dictionary *node = NULL; /* Pierwsze slowo */ if (dict->children_size == 0) { for(node = dict; *word; node = *node->children) { put_child(node, create_node(*word)); word++; } put_child(node, create_node(NULL_MARKER)); return 1; } node = dict; struct dictionary *found = NULL; while (find_child(node, &found, *word) && *word) { node = found; word++; } if (*word == L'\0') { if (find_child(node, &found, NULL_MARKER)) return 0; put_child(node, create_node(NULL_MARKER)); } else { struct dictionary *tmp = create_node(*word); put_child(node, tmp); dictionary_insert(tmp, ++word); } return 1; }
void asmcheck_do_sou(struct tdesc *tdp, struct node *np) { struct mlist *mlp; struct child *chp; char *format; if (np->format != NULL) { char *upper = uc(np->format); printf("! struct/union %s size 0x%x\n", upper, tdp->size); #if 0 /* { FIXME: */ { int l; if ((np->format2 != NULL) && (l = stabs_log2(tdp->size)) != -1) { printf("#define\t%s 0x%x\n", np->format2, l); } } #endif /* } */ free(upper); } /* * Run thru all the fields of a struct and print them out */ for (mlp = tdp->data.members.forw; mlp != NULL; mlp = mlp->next) { /* * If there's a child list, only print those members. */ if (np->child != NULL) { if (mlp->name == NULL) continue; chp = find_child(np, mlp->name); if (chp == NULL) continue; format = uc(chp->format); } else { format = NULL; } if (mlp->fdesc == NULL) continue; switch_on_type(mlp, mlp->fdesc, format, 0); if (format != NULL) free(format); } }
/** * Iterates through the entries pairs in the map, * invoking a callback for each that matches a given prefix. * The call back gets a key, value for each and returns an integer stop value. * If the callback returns non-zero, then the iteration stops. * @arg t The tree to iterate over * @arg prefix The prefix of keys to read * @arg prefix_len The length of the prefix * @arg cb The callback function to invoke * @arg data Opaque handle passed to the callback * @return 0 on success, or the return of the callback. */ int art_iter_prefix(art_tree *t, const unsigned char *key, int key_len, art_callback cb, void *data) { art_node **child; art_node *n = t->root; int prefix_len, depth = 0; while (n) { // Might be a leaf if (IS_LEAF(n)) { n = (art_node*)LEAF_RAW(n); // Check if the expanded path matches if (!leaf_prefix_matches((art_leaf*)n, key, key_len)) { art_leaf *l = (art_leaf*)n; return cb(data, (const unsigned char*)l->key, l->key_len, l->value); } return 0; } // If the depth matches the prefix, we need to handle this node if (depth == key_len) { art_leaf *l = minimum(n); if (!leaf_prefix_matches(l, key, key_len)) return recursive_iter(n, cb, data); return 0; } // Bail if the prefix does not match if (n->partial_len) { prefix_len = prefix_mismatch(n, key, key_len, depth); // If there is no match, search is terminated if (!prefix_len) return 0; // If we've matched the prefix, iterate on this node else if (depth + prefix_len == key_len) { return recursive_iter(n, cb, data); } // if there is a full match, go deeper depth = depth + n->partial_len; } // Recursively search child = find_child(n, key[depth]); n = (child) ? *child : NULL; depth++; } return 0; }
string AgentPNS::move_stats(vector<Move> moves) const { string s = ""; const Node * node = & root; for(vector<Move>::iterator m = moves.begin(); node && m != moves.end(); ++m) node = find_child(node, *m); if(node){ Node * child = node->children.begin(), * childend = node->children.end(); for( ; child != childend; child++) if(child->move != M_NONE) s += child->to_s() + "\n"; } return s; }
vector<Move> AgentPNS::get_pv() const { vector<Move> pv; const Node * n = & root; char turn = rootboard.toplay(); while(n && !n->children.empty()){ Move m = return_move(n, turn); pv.push_back(m); n = find_child(n, m); turn = 3 - turn; } if(pv.size() == 0) pv.push_back(Move(M_RESIGN)); return pv; }
bool ACPI::append(const char *sig, const char *extra, const uint32_t extra_len) { // check if enough space to append acpi_sdt *table = find_child(sig, rsdt, 4); if (!table || slack(table) < extra_len) return 0; memcpy((char *)table + table->len, extra, extra_len); table->len += extra_len; table->checksum += checksum((const char *)table, table->len); if (options->debug.acpi) dump(table, 0); return 1; }
void cpu(pid_t pid) { if (getuid() == 0) firemon_drop_privs(); pid_read(pid); // print processes int i; for (i = 0; i < max_pids; i++) { if (pids[i].level == 1) { pid_print_list(i, 0); int child = find_child(i); if (child != -1) print_cpu(child); } } }
void cpu(void) { if (getuid() == 0) firemon_drop_privs(); pid_read(0); // include all processes // print processes int i; for (i = 0; i < MAX_PIDS; i++) { if (pids[i].level == 1) { pid_print_list(i, 0); int child = find_child(i); if (child != -1) print_cpu(child); } } }
void seccomp_print_filter(pid_t pid) { // if the pid is that of a firejail process, use the pid of the first child process char *comm = pid_proc_comm(pid); if (comm) { // remove \n char *ptr = strchr(comm, '\n'); if (ptr) *ptr = '\0'; if (strcmp(comm, "firejail") == 0) { pid_t child; if (find_child(pid, &child) == 0) { pid = child; } } free(comm); } // check privileges for non-root users uid_t uid = getuid(); if (uid != 0) { uid_t sandbox_uid = pid_get_uid(pid); if (uid != sandbox_uid) { exechelp_logerrv("firejail", FIREJAIL_ERROR, "Error: permission denied to print seccomp filters (sandbox belongs to a different user).\n"); exit(1); } } // find the seccomp filter char *fname; if (asprintf(&fname, "/proc/%d/root/tmp/firejail/mnt/seccomp", pid) == -1) errExit("asprintf"); struct stat s; if (stat(fname, &s) == -1) { exechelp_logerrv("firejail", FIREJAIL_ERROR, "Error: Cannot access seccomp filter.\n"); exit(1); } // read and print the filter read_seccomp_file(fname); drop_privs(1); filter_debug(); exit(0); }
void seccomp_print_filter(pid_t pid) { EUID_ASSERT(); // if the pid is that of a firejail process, use the pid of the first child process EUID_ROOT(); char *comm = pid_proc_comm(pid); EUID_USER(); if (comm) { if (strcmp(comm, "firejail") == 0) { pid_t child; if (find_child(pid, &child) == 0) { pid = child; } } free(comm); } // check privileges for non-root users uid_t uid = getuid(); if (uid != 0) { uid_t sandbox_uid = pid_get_uid(pid); if (uid != sandbox_uid) { fprintf(stderr, "Error: permission denied.\n"); exit(1); } } // find the seccomp filter EUID_ROOT(); char *fname; if (asprintf(&fname, "/proc/%d/root%s", pid, RUN_SECCOMP_CFG) == -1) errExit("asprintf"); struct stat s; if (stat(fname, &s) == -1) { printf("Cannot access seccomp filter.\n"); exit(1); } // read and print the filter - run this as root, the user doesn't have access sbox_run(SBOX_ROOT | SBOX_SECCOMP, 3, PATH_FSECCOMP, "print", fname); free(fname); exit(0); }
void seccomp(pid_t pid) { if (getuid() == 0) firemon_drop_privs(); pid_read(pid); // include all processes // print processes int i; for (i = 0; i < max_pids; i++) { if (pids[i].level == 1) { pid_print_list(i, 0); int child = find_child(i); if (child != -1) print_seccomp(child); } } printf("\n"); }
/** * path_exists - Checks if path exists * @tree: NTree structure * @path: Array of strings to check path * Description: Checks path in array again existing NTree structure */ int path_exists(NTree *tree, char **path) { int i; if (!tree || !path || !path[0]) return 0; for (i = 0; path[i]; i++) { if (i == 0 && strcmp(tree->str, path[i])) tree = NULL; else if (i != 0) tree = find_child(tree->children, path[i]); if (!tree) return 0; } return 1; }
void caps_print_filter(pid_t pid) { // if the pid is that of a firejail process, use the pid of the first child process char *comm = pid_proc_comm(pid); if (comm) { // remove \n char *ptr = strchr(comm, '\n'); if (ptr) *ptr = '\0'; if (strcmp(comm, "firejail") == 0) { pid_t child; if (find_child(pid, &child) == 0) { pid = child; } } free(comm); } // check privileges for non-root users uid_t uid = getuid(); if (uid != 0) { struct stat s; char *dir; if (asprintf(&dir, "/proc/%u/ns", pid) == -1) errExit("asprintf"); if (stat(dir, &s) < 0) errExit("stat"); if (s.st_uid != uid) { printf("Error: permission denied.\n"); exit(1); } } uint64_t caps = extract_caps(pid); drop_privs(1); int i; uint64_t mask; int elems = sizeof(capslist) / sizeof(capslist[0]); for (i = 0, mask = 1; i < elems; i++, mask <<= 1) { printf("%-18.18s - %s\n", capslist[i].name, (mask & caps)? "enabled": "disabled"); } exit(0); }