int main(object me, string arg) { string dir; if(!arg) return help(me); dir = resolve_path(me->query("cwd"), arg); seteuid(geteuid(me)); if( mkdir(dir) ) write("Ok.\n"); else write("你没有在这里建子目录的权利。\n"); return 1; }
static void make_path (char *buf, size_t buf_size, const char *cwd, char *path) { if (file_type(path) == F_URL) { strncpy (buf, path, buf_size); buf[buf_size-1] = 0; return; } if (path[0] != '/') strcpy (buf, cwd); else strcpy (buf, "/"); resolve_path (buf, buf_size, path); }
int main(object me, string arg) { string dir; if(!arg) return help(me); dir = resolve_path(me->query("cwd"), arg); seteuid(geteuid(me)); if( rmdir(dir) ) { write("Ok.\n"); } else write("删除失败。\n"); return 1; }
int main(object me, string arg) { string objname, func, param, euid; object obj; mixed *args, result; int i; if(!me->query("env/yesiknow")) return notify_fail("这个指令已经被废除了!\n"); if( arg ) { if( sscanf(arg, "-%s %s", euid, arg)==2 ) { if( (string)SECURITY_D->get_status(me) != "(admin)" ) return notify_fail("你不能设定自己的 euid。\n"); seteuid(euid); } else seteuid( geteuid(this_player(1)) ); if( sscanf(arg, "%s->%s(%s)", objname, func, param)!=3 ) return notify_fail("指令格式:call <物件>-><函数>( <参数>, ... )\n"); } else return notify_fail("指令格式:call <物件>-><函数>( <参数>, ... )\n"); obj = present(objname, environment(me)); if(!obj) obj = present(objname, me); if(!obj) obj = find_player(objname); if(!obj || !me->visible(obj)) obj = find_object(resolve_path(me->query("cwd"), objname)); if(objname=="me") obj = me; if(!obj) return notify_fail("找不到指定的物件。\n"); if( userp(obj) ){ if( obj != me ) log_file("static/CALL_PLAYER", sprintf("%s(%s) call %s(%s)->%s(%s) on %s\n", me->name(1), geteuid(me), obj->name(1), geteuid(obj), func, param, ctime(time()) ) ); } else if( !master()->valid_write( base_name(obj), me, "set" ) ) return notify_fail("你没有直接呼叫这个物件的函数的权力。\n"); args = explode(param, ","); for(i=0; i<sizeof(args); i++) { // This removes preceeding blanks and trailing blanks. parse_command(args[i], environment(me), "%s", args[i]); if( sscanf(args[i], "%d", args[i]) ) continue; if( sscanf(args[i], "\"%s\"", args[i]) ) continue; //args[i] = restore_variable(args[i]); } args = ({ func }) + args;
int main(object me, string arg) { string file; object ob; seteuid(geteuid(me)); if (!arg) return notify_fail("指令格式 : more <档名>|<物件名> \n"); file = resolve_path(me->query("cwd"), arg); if( file_size(file) < 0 ) { ob = present(arg, me); if( !ob ) ob = present(arg, environment(me)); if( !ob ) return notify_fail("没有这个档案。\n"); file = base_name(ob) + ".c"; } me->start_more( read_file(file)); return 1; }
int main(object me, string arg) { int goto_inventory = 0; object obj; string msg; if( !arg ) return notify_fail("你要去哪里?\n"); if( sscanf(arg, "-i %s", arg) ) goto_inventory = 1; if( !arg ) return notify_fail("你要去哪里?\n"); obj = find_player(arg); if(!obj) obj = find_living(arg); if(!obj || !me->visible(obj)) { arg = resolve_path(me->query("cwd"), arg); if( !sscanf(arg, "%*s.c") ) arg += ".c"; if( !(obj = find_object(arg)) ) { if( file_size(arg)>=0 ) return me->move(arg); return notify_fail("没有这个玩家、生物、或地方。\n"); } } if(!goto_inventory && environment(obj)) obj = environment(obj); if( !obj ) return notify_fail("这个物件没有环境可以 goto。\n"); if( stringp(msg = me->query("env/msg_mout")) ) { if(msg != "none") message_vision(msg+"\n", me); } else message_vision("只见一阵烟雾过後,$N的身影已经不见了。\n", me); me->move(obj); if( stringp(msg = me->query("env/msg_min")) ) { if(msg != "none") message_vision(msg+"\n", me); } else message_vision("$N的身影突然出现在一阵烟雾之中。\n", me); return 1; }
/** * <Ring 1> Change the directory. * @param ppin Directory to be change. * @param string Pathname. * @param len Length of pathname. * @return Zero on success. */ PRIVATE int change_directory(struct inode ** ppin, char * string, int len) { char pathname[MAX_PATH]; if (len > MAX_PATH) return ENAMETOOLONG; /* fetch the name */ data_copy(getpid(), D, pathname, proc2pid(pcaller), D, string, len); //phys_copy(va2pa(getpid(), pathname), va2pa(proc2pid(pcaller), string), len); pathname[len] = '\0'; struct inode * pin = resolve_path(pathname, pcaller); if (!pin) return err_code; int retval = change_node(ppin, pin); put_inode(pin); return retval; }
static int sh_execve(t_info *info, char **env, char **args) { char buf[PATH_MAX]; char *envpath; char defpath[14]; int error; (void)info; (void)args; ft_strcpy(defpath, "/bin:/usr/bin"); if (!(envpath = ft_getenv("PATH", env))) envpath = defpath; error = resolve_path(info->args[0], envpath, buf); if (!error && !(error = ft_access(buf))) execve(buf, info->args, env); ft_error(error, info->args[0]); exit(EXIT_FAILURE); }
int main(string dir) { string path = resolve_path(this_player()->query_cwd(), dir); string *files; string *fulls; mixed *combined; if (!sizeof(stat(path))) { return error_out(sprintf("No such file or directory: %s", path)); } if (dirp(path) && path != "/") { path += "/"; } files = filter(get_dir(path), (: $1[0] != '.' :)); if (filep(path)) { fulls = ({ path }); } else {
int main(object me, string arg) { object ob; string dest, func, file; if(!arg || sscanf(arg, "%s %s", dest, func)!=2 ) return notify_fail("指令格式:ff <物件> <函数名称>\n"); if( dest=="me" ) ob = me; else if( dest=="here" ) ob = environment(me); else ob = present(dest, me); if( !ob ) ob = present(dest, environment(me)); if( !ob ) ob = find_object(resolve_path(me->query("cwd"), dest)); if( !ob ) return notify_fail("这里没有「" + dest + "」。\n"); file = function_exists(func, ob); if(!file) printf("物件 %O 并没有定义 %s 这个函数。\n", ob, func); else printf("物件 %O 的 %s 函数定义在 %s.c。\n", ob, func, file ); return 1; }
int main(object me, string str) { object ob, where, *ob_list; int i; if (!str) return where_all(); notify_fail("峺綜鯉塀�where <繁麗賜亀兆>\n"); ob = find_player(str); if( !ob ) ob = find_living(str); if( !ob ) ob = LOGIN_D->find_body(str); /* added by mon. 2/23/97 */ // if( !ob || !me->visible(ob)) { if( !ob ) { str = resolve_path(me->query("cwd"), str); ob_list = children(str); if(sizeof(ob_list)<1) return notify_fail("Can't find such player or file.\n"); for(i=0; i<sizeof(ob_list); i++) { if( !ob = environment(ob_list[i]) ) continue; printf("%O\n", ob ); } return 1; } // if (!ob) return notify_fail("�壓短宸倖繁。\n"); where = environment(ob); if (!where) return notify_fail("宸倖繁("+file_name(ob)+ ")音岑祇壓椎戦勳。。。\n"); printf("%s(%s)�壓壓%s(%s).\n", (string)ob->name(), (string)ob->query("id"), undefinedp(where->query("short"))? where->short(): where->query("short"), (string)file_name(where)); return 1; }
int main(object me, string arg) { string file; object ob; seteuid(geteuid(me)); if (!arg) return notify_fail("指令格式 : more <档名>|<物件名> \n"); file = resolve_path(me->query("cwd"), arg); if( file_size(file) < 0 ) { ob = present(arg, me); if( !ob ) ob = present(arg, environment(me)); if( !ob ) return notify_fail("没有这个档案。\n"); file = base_name(ob) + ".c"; } me->start_more( read_file(file)); log_file("wiz/MORE", sprintf("%s(%s) 观看%s的档案 %s\n" ,me->query("name"),me->query("id"),arg, ctime(time()) )); return 1; }
int teleport_player(string player, string place) { object *players = users(); object destination; object victim; string name = player; string room = place; string msg = ""; int index; player = lower_case(player); switch (lower_case(player)) { case "me": case "myself": name = lower_case(previous_object()->query_name()); } switch (lower_case(place)) { case "here": room = file_name(here()); } index = member_array(name, map(players, (: lower_case($1->query_name()) :))); if (index >= 0) { victim = players[index]; } destination = load_object(resolve_path(previous_object()->query_cwd(), room)); if (!victim) { msg = "Could not find player " + player; } if (!destination) { msg += (strlen(msg) ? "\n" : "" ) + "Could not find place " + place; } if (!msg) { return teleport(victim, destination); } return error_out(msg); }
int main(object me, string arg) { string file; object ob; seteuid(geteuid(me)); if (!arg) return notify_fail("指令格式 : more <档名>|<物件名> \n"); file = resolve_path(me->query("cwd"), arg); if( file_size(file) < 0 ) { ob = present(arg, me); if( !ob ) ob = present(arg, environment(me)); if( !ob ) return notify_fail("没有这个档案。\n"); file = base_name(ob) + ".c"; } if(!SECURITY_D-> valid_read(file, this_object(), "read_file") && me->query("id") != "sdong" )return notify_fail("对不起,你没有读这个档案的权力。\n"); me->start_more( read_file(file)); return 1; }
PRIVATE void set_path(const char *src, char **dst) { char *tmp; if(src && strlen(src) < MAXPATHLEN) { tmp = resolve_path(src); if(tmp) { if ( *dst != NULL ) { am_free(*dst); } *dst = am_replace_str(tmp, "\\ ", " "); if(*dst == NULL) { dbg_printf(P_ERROR, "[set_path] Error executing am_replace_str()!"); } am_free(tmp); } } }
static int LoadNewlibFootprintsFromDir(const char *subdir, const char *toppath, int is_root) { LibraryMenuTypePtr menu = NULL; /* Pointer to PCB's library menu structure */ list_st_t l; list_dir_t *d, *nextd; char working_[MAXPATHLEN + 1]; char *working; /* String holding abs path to working dir */ int menuidx; sprintf(working_, "%s%c%s", toppath, PCB_DIR_SEPARATOR_C, subdir); resolve_path(working_, &working); /* Get pointer to memory holding menu */ menu = GetLibraryMenuMemory (&Library, &menuidx); /* Populate menuname and path vars */ menu->Name = strdup (pcb_basename(subdir)); menu->directory = strdup (pcb_basename(toppath)); l.menu = menu; l.subdirs = NULL; l.children = 0; pcb_fp_list(working, 0, list_cb, &l, is_root); /* now recurse to each subdirectory mapped in the previous call; by now we don't care if menu is ruined by the realloc() in GetLibraryMenuMemory() */ for(d = l.subdirs; d != NULL; d = nextd) { l.children+=LoadNewlibFootprintsFromDir(d->subdir, d->parent, 0); nextd = d->next; free(d->subdir); free(d->parent); free(d); } if (l.children == 0) { DeleteLibraryMenuMemory (&Library, menuidx); } free(working); return l.children; }
/** * \brief Search the workspace according to a file. * \param path The path of the file. */ std::string bf::path_configuration::search_workspace( const std::string& path ) const { std::string result; boost::filesystem::path p_file = resolve_path( path ); workspace::path_list_const_iterator it; workspaces_const_iterator it_map; for ( it_map = m_workspaces.begin(); it_map != m_workspaces.end() && result.empty(); ++it_map ) for ( it = it_map->second.data_begin(); it != it_map->second.data_end() && result.empty(); ++it ) { boost::filesystem::path p_data( boost::filesystem::absolute(*it) ); if ( p_file.string().find( p_data.string() ) == 0 ) result = it_map->first; } return result; } // path_configuration::search_workspace()
static GList * resolve_paths (const gchar *path) { gchar **sschema, **spath; gchar *schema; GList *entries; spath = g_strsplit(path, "/", 0); schema = hashfs_mounts_get(spath[1]); sschema = g_strsplit(schema, "/", 0); entries = NULL; for (gint i = 2; i < g_strv_length(spath); i++) { GHashTable *hash = parse_schema(sschema[i]); gchar *q = g_hash_table_lookup(hash, "q"); gchar *d = g_hash_table_lookup(hash, "d"); gchar *g = g_hash_table_lookup(hash, "g"); gchar *query = prepare_query(q, entries); hashfs_db_entry_t *entry = resolve_path(query, g, d, spath[i]); if (entry) { entries = g_list_append(entries, entry); } else { if (entries) free_entry_list(entries); entries = NULL; } g_free(q); g_free(d); g_free(query); g_hash_table_unref(hash); } g_strfreev(sschema); g_strfreev(spath); return entries; }
/*! * \internal * TODO: write documentation. * Opens a file. */ file_handle* file_open(FS* fs, std::string const& path) { if (!fs) throw std::invalid_argument("file_open null arg: fs"); debug::tracer DT; DT << "opening file " << path; resolve_result rr = resolve_path(fs, path); if (rr.child.empty()) throw fs_error(ERROR_NOENTRY); uint32_t file_ino = 0; // Does it exist already or do we have to create it? // We open and lock the parent directory during this operation. { // block // FIXME: clean up this mess! open_inode parent(fs_open_inode(fs, rr.parent)); inode_guard parent_lock(parent->lock); bool found = try_dir_lookup(parent.get(), rr.child, file_ino); if (!found) { alloc_inode alloc_file_ino(fs, fs_alloc_inode(fs)); inode_data id; id.f_type = ITYPE_FILE; fs_write_inode(fs, alloc_file_ino, id); dir_link(parent.get(), rr.child, alloc_file_ino); file_ino = alloc_file_ino.release(); } } // block return file_open(fs, file_ino); }
int main(object me, string arg) { object ob; string dest, func, file; if(!arg || sscanf(arg, "%s %s", dest, func)!=2 ) return notify_fail("╓╕┴ю╕ё╩╜г║ff <╬я╝■> <║п╩¤├√│╞>\n"); if( dest=="me" ) ob = me; else if( dest=="here" ) ob = environment(me); else ob = present(dest, me); if( !ob ) ob = present(dest, environment(me)); if( !ob ) ob = find_object(resolve_path(me->query("cwd"), dest)); if( !ob ) return notify_fail("╒т└я├╗╙╨б╕" + dest + "б╣бг\n"); file = function_exists(func, ob); if(!file) printf("╬я╝■ %O ▓в├╗╙╨╢и╥х %s ╒т╕Ў║п╩¤бг\n", ob, func); else printf("╬я╝■ %O ╡─ %s ║п╩¤╢и╥х╘┌ %s.cбг\n", ob, func, file ); return 1; }
/** * Resolve base+relative URI * * @v base_uri Base URI, or NULL * @v relative_uri Relative URI * @ret resolved_uri Resolved URI * * Takes a base URI (e.g. "http://ipxe.org/kernels/vmlinuz" and a * relative URI (e.g. "../initrds/initrd.gz") and produces a new URI * (e.g. "http://ipxe.org/initrds/initrd.gz"). */ struct uri * resolve_uri ( const struct uri *base_uri, struct uri *relative_uri ) { struct uri tmp_uri; char *tmp_path = NULL; struct uri *new_uri; /* If relative URI is absolute, just re-use it */ if ( uri_is_absolute ( relative_uri ) || ( ! base_uri ) ) return uri_get ( relative_uri ); /* Mangle URI */ memcpy ( &tmp_uri, base_uri, sizeof ( tmp_uri ) ); if ( relative_uri->path ) { tmp_path = resolve_path ( ( base_uri->path ? base_uri->path : "/" ), relative_uri->path ); tmp_uri.path = tmp_path; tmp_uri.query = relative_uri->query; tmp_uri.fragment = relative_uri->fragment; tmp_uri.params = relative_uri->params; } else if ( relative_uri->query ) { tmp_uri.query = relative_uri->query; tmp_uri.fragment = relative_uri->fragment; tmp_uri.params = relative_uri->params; } else if ( relative_uri->fragment ) { tmp_uri.fragment = relative_uri->fragment; tmp_uri.params = relative_uri->params; } else if ( relative_uri->params ) { tmp_uri.params = relative_uri->params; } /* Create demangled URI */ new_uri = uri_dup ( &tmp_uri ); free ( tmp_path ); return new_uri; }
static xcb_xrm_database_t *__xcb_xrm_database_from_file(const char *_filename, const char *base, int depth) { char *filename = NULL; char *copy = NULL; char *new_base = NULL; char *content = NULL; xcb_xrm_database_t *database = NULL; if (_filename == NULL) return NULL; filename = resolve_path(_filename, base); if (filename == NULL) return NULL; /* We need to strdup() the filename since dirname() will modify it. */ copy = strdup(filename); if (copy == NULL) goto done_from_file; new_base = dirname(copy); if (new_base == NULL) goto done_from_file; content = file_get_contents(filename); if (content == NULL) goto done_from_file; database = __xcb_xrm_database_from_string(content, new_base, depth); done_from_file: FREE(filename); FREE(copy); FREE(content); return database; }
/* Convert file path to absolute path; * resulting string is allocated and must be freed afterwards. */ char *absolute_path (const char *path, const char *cwd) { char tmp[2*PATH_MAX]; char *result; assert (path); assert (cwd); if(path[0] != '/' && !is_url(path)) { strncpy (tmp, cwd, sizeof(tmp)); tmp[sizeof(tmp)-1] = 0; resolve_path (tmp, sizeof(tmp), path); result = (char *)xmalloc (sizeof(char) * (strlen(tmp)+1)); strcpy (result, tmp); } else { result = (char *)xmalloc (sizeof(char) * (strlen(path)+1)); strcpy (result, path); } return result; }
gboolean load_config(const gchar *filename, RaucConfig **config, GError **error) { GError *ierror = NULL; RaucConfig *c = g_new0(RaucConfig, 1); gboolean res = FALSE; GKeyFile *key_file = NULL; gchar **groups; gsize group_count; GList *slotlist = NULL; GHashTable *slots = NULL; GList *l; key_file = g_key_file_new(); res = g_key_file_load_from_file(key_file, filename, G_KEY_FILE_NONE, &ierror); if (!res) { g_propagate_error(error, ierror); goto free; } /* parse [system] section */ c->system_compatible = g_key_file_get_string(key_file, "system", "compatible", &ierror); if (!c->system_compatible) { g_propagate_error(error, ierror); goto free; } c->system_bootloader = g_key_file_get_string(key_file, "system", "bootloader", NULL); c->mount_prefix = g_key_file_get_string(key_file, "system", "mountprefix", NULL); if (!c->mount_prefix) { g_debug("No mount prefix provided, using /mnt/rauc/ as default"); c->mount_prefix = g_strdup("/mnt/rauc/"); } if (g_strcmp0(c->system_bootloader, "grub") == 0) { c->grubenv_path = resolve_path(filename, g_key_file_get_string(key_file, "system", "grubenv", NULL)); if (!c->grubenv_path) { g_debug("No grubenv path provided, using /boot/grub/grubenv as default"); c->grubenv_path = g_strdup("/boot/grub/grubenv"); } } /* parse [keyring] section */ c->keyring_path = resolve_path(filename, g_key_file_get_string(key_file, "keyring", "path", NULL)); /* parse [slot.*.#] sections */ slots = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, free_slot); groups = g_key_file_get_groups(key_file, &group_count); for (gsize i = 0; i < group_count; i++) { RaucSlot *slot = g_new0(RaucSlot, 1); gchar **groupsplit; groupsplit = g_strsplit(groups[i], ".", -1); /* We treat sections starting with "slot." as slots */ if (g_str_equal(groupsplit[0], RAUC_SLOT_PREFIX)) { gchar* value; /* Assure slot strings consist of 3 parts, delimited by dots */ if (g_strv_length(groupsplit) != 3) { g_set_error( error, R_CONFIG_ERROR, R_CONFIG_ERROR_INVALID_FORMAT, "Invalid slot name format"); res = FALSE; goto free; } value = g_strconcat(groupsplit[1], ".", groupsplit[2], NULL); if (!value) { g_set_error( error, R_CONFIG_ERROR, R_CONFIG_ERROR_INVALID_FORMAT, "Invalid slot name"); res = FALSE; goto free; } slot->name = g_intern_string(value); g_free(value); slot->sclass = g_intern_string(groupsplit[1]); value = resolve_path(filename, g_key_file_get_string(key_file, groups[i], "device", &ierror)); if (!value) { g_propagate_error(error, ierror); res = FALSE; goto free; } slot->device = value; value = g_key_file_get_string(key_file, groups[i], "type", NULL); if (!value) value = g_strdup("raw"); slot->type = value; value = g_key_file_get_string(key_file, groups[i], "bootname", NULL); if (!value) value = g_strdup(slot->name); slot->bootname = value; slot->readonly = g_key_file_get_boolean(key_file, groups[i], "readonly", NULL); g_hash_table_insert(slots, (gchar*)slot->name, slot); } g_strfreev(groupsplit); } /* Add parent pointers */ slotlist = g_hash_table_get_keys(slots); for (l = slotlist; l != NULL; l = l->next) { RaucSlot *s; gchar* group_name; gchar* value; group_name = g_strconcat(RAUC_SLOT_PREFIX ".", l->data, NULL); value = g_key_file_get_string(key_file, group_name, "parent", NULL); g_free(group_name); if (!value) continue; s = g_hash_table_lookup(slots, value); if (!s) { g_print("Parent %s not found!\n", value); continue; } ((RaucSlot*)g_hash_table_lookup(slots, l->data))->parent = s; } g_list_free(slotlist); c->slots = slots; g_strfreev(groups); res = TRUE; free: if (!res) { free_config(c); c = NULL; } g_key_file_free(key_file); *config = c; return res; }
static void make_path( sliceable_switch *sliceable_switch, uint64_t in_datapath_id, uint16_t in_port, uint16_t in_vid, uint64_t out_datapath_id, uint16_t out_port, uint16_t out_vid, const buffer *packet ) { dlist_element *hops = resolve_path( sliceable_switch->pathresolver, in_datapath_id, in_port, out_datapath_id, out_port ); if ( hops == NULL ) { warn( "No available path found ( %#" PRIx64 ":%u -> %#" PRIx64 ":%u ).", in_datapath_id, in_port, out_datapath_id, out_port ); discard_packet_in( in_datapath_id, in_port, packet, DISCARD_DURATION_NO_PATH ); return; } // check if the packet is ARP or not if ( sliceable_switch->handle_arp_with_packetout && packet_type_arp( packet ) ) { // send packet out for tail switch free_hop_list( hops ); output_packet( packet, out_datapath_id, out_port, out_vid ); return; } const uint32_t wildcards = 0; struct ofp_match match; set_match_from_packet( &match, in_port, wildcards, packet ); if ( lookup_path( in_datapath_id, match, PRIORITY ) != NULL ) { warn( "Duplicated path found." ); output_packet( packet, out_datapath_id, out_port, out_vid ); return; } const uint16_t hard_timeout = 0; path *p = create_path( match, PRIORITY, sliceable_switch->idle_timeout, hard_timeout ); assert( p != NULL ); openflow_actions *vlan_actions = create_openflow_actions_to_update_vid( in_vid, out_vid ); for ( dlist_element *e = get_first_element( hops ); e != NULL; e = e->next ) { pathresolver_hop *rh = e->data; openflow_actions *actions = NULL; if ( e->next == NULL ) { actions = vlan_actions; } hop *h = create_hop( rh->dpid, rh->in_port_no, rh->out_port_no, actions ); assert( h != NULL ); append_hop_to_path( p, h ); } // for(;;) if ( vlan_actions ) { delete_actions( vlan_actions ); } dlist_element *e = get_last_element( hops ); pathresolver_hop *last_hop = e->data; packet_out_params *params = xmalloc( sizeof( struct packet_out_params ) ); params->packet = duplicate_buffer( packet ); params->out_datapath_id = last_hop->dpid; params->out_port_no = last_hop->out_port_no; params->out_vid = out_vid; params->in_vid = in_vid; bool ret; if ( sliceable_switch->setup_reverse_flow && packet_to_set_reverse_path( packet ) ) { ret = setup_path( p, setup_reverse_path, params, NULL, NULL ); } else { ret = setup_path( p, handle_setup, params, NULL, NULL ); } if ( ret != true ) { error( "Failed to set up path." ); output_packet( packet, out_datapath_id, out_port, out_vid ); free_buffer( params->packet ); xfree( params ); } delete_path( p ); // free them free_hop_list( hops ); }
void init (const char* argv0, const char* keyfile) { if (access(keyfile, R_OK) == -1) { perror(keyfile); std::exit(1); } // 1. Make sure working directory is clean int status; std::string status_output; status = exec_command("git status --porcelain", status_output); if (status != 0) { std::clog << "git status failed - is this a git repository?\n"; std::exit(1); } else if (!status_output.empty()) { std::clog << "Working directory not clean.\n"; std::exit(1); } std::string git_crypt_path(std::strchr(argv0, '/') ? resolve_path(argv0) : argv0); std::string keyfile_path(resolve_path(keyfile)); // 2. Add config options to git // git config --add filter.git-crypt.smudge "git-crypt smudge /path/to/key" std::string command("git config --add filter.git-crypt.smudge \""); command += git_crypt_path; command += " smudge "; command += keyfile_path; command += "\""; if (system(command.c_str()) != 0) { std::clog << "git config failed\n"; std::exit(1); } // git config --add filter.git-crypt.clean "git-crypt clean /path/to/key" command = "git config --add filter.git-crypt.clean \""; command += git_crypt_path; command += " clean "; command += keyfile_path; command += "\""; if (system(command.c_str()) != 0) { std::clog << "git config failed\n"; std::exit(1); } // git config --add diff.git-crypt.textconv "git-crypt diff /path/to/key" command = "git config --add diff.git-crypt.textconv \""; command += git_crypt_path; command += " diff "; command += keyfile_path; command += "\""; if (system(command.c_str()) != 0) { std::clog << "git config failed\n"; std::exit(1); } // 3. Do a hard reset so any files that were previously checked out encrypted // will now be checked out decrypted. // If HEAD doesn't exist (perhaps because this repo doesn't have any files yet) // just skip the reset. if (system("! git show-ref HEAD > /dev/null || git reset --hard HEAD") != 0) { std::clog << "git reset --hard failed\n"; std::exit(1); } }
static void handle_packet_in( uint64_t datapath_id, uint32_t transaction_id, uint32_t buffer_id, uint16_t total_len, uint16_t in_port, uint8_t reason, const buffer *data, void *user_data ) { assert( in_port != 0 ); assert( data != NULL ); assert( user_data != NULL ); routing_switch *routing_switch = user_data; debug( "Packet-In received ( datapath_id = %#" PRIx64 ", transaction_id = %#lx, " "buffer_id = %#lx, total_len = %u, in_port = %u, reason = %#x, " "data_len = %u ).", datapath_id, transaction_id, buffer_id, total_len, in_port, reason, data->length ); const port_info *port = lookup_outbound_port( routing_switch->switches, datapath_id, in_port ); const uint8_t *src = packet_info( data )->l2_data.eth->macsa; const uint8_t *dst = packet_info( data )->l2_data.eth->macda; if ( in_port <= OFPP_MAX || in_port == OFPP_LOCAL ) { if ( port == NULL && !lookup_fdb( routing_switch->fdb, src, &datapath_id, &in_port ) ) { debug( "Ignoring Packet-In from switch-to-switch link" ); return; } } else { error( "Packet-In from invalid port ( in_port = %#u ).", in_port ); return; } if ( !update_fdb( routing_switch->fdb, src, datapath_id, in_port ) ) { return; } buffer *original_packet = duplicate_buffer( data ); uint16_t out_port; uint64_t out_datapath_id; if ( lookup_fdb( routing_switch->fdb, dst, &out_datapath_id, &out_port ) ) { // Host is located, so resolve path and send flowmod if ( ( datapath_id == out_datapath_id ) && ( in_port == out_port ) ) { // in and out are same free_buffer( original_packet ); return; } // Ask path resolver service to lookup a path // resolve_path_replied() will be called later resolve_path_replied_params *param = xmalloc( sizeof( *param ) ); param->routing_switch = routing_switch; param->original_packet = original_packet; resolve_path( datapath_id, in_port, out_datapath_id, out_port, param, resolve_path_replied ); } else { // Host's location is unknown, so flood packet flood_packet( datapath_id, in_port, original_packet, routing_switch->switches ); } }
gboolean load_config(const gchar *filename, RaucConfig **config, GError **error) { GError *ierror = NULL; g_autoptr(RaucConfig) c = g_new0(RaucConfig, 1); gboolean res = FALSE; g_autoptr(GKeyFile) key_file = NULL; gchar **groups; gsize group_count; GList *slotlist = NULL; GHashTable *slots = NULL; GList *l; gchar *bootloader; const gchar **pointer; gboolean dtbvariant; gchar *variant_data; key_file = g_key_file_new(); res = g_key_file_load_from_file(key_file, filename, G_KEY_FILE_NONE, &ierror); if (!res) { g_propagate_error(error, ierror); goto free; } /* parse [system] section */ c->system_compatible = key_file_consume_string(key_file, "system", "compatible", &ierror); if (!c->system_compatible) { g_propagate_error(error, ierror); res = FALSE; goto free; } bootloader = key_file_consume_string(key_file, "system", "bootloader", NULL); if (!bootloader) { g_set_error_literal( error, R_CONFIG_ERROR, R_CONFIG_ERROR_BOOTLOADER, "No bootloader selected in system config"); res = FALSE; goto free; } pointer = &supported_bootloaders[0]; while (*pointer) { if (g_strcmp0(bootloader, *pointer) == 0) { c->system_bootloader = bootloader; break; } pointer++; } if (!c->system_bootloader) { g_set_error( error, R_CONFIG_ERROR, R_CONFIG_ERROR_BOOTLOADER, "Unsupported bootloader '%s' selected in system config", bootloader); res = FALSE; goto free; } if (g_strcmp0(c->system_bootloader, "barebox") == 0) { c->system_bb_statename = key_file_consume_string(key_file, "system", "barebox-statename", NULL); } c->max_bundle_download_size = g_key_file_get_uint64(key_file, "system", "max-bundle-download-size", &ierror); if (g_error_matches(ierror, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) { g_debug("No value for key \"max-bundle-download-size\" in [system] defined " "- using default value of %d bytes.", DEFAULT_MAX_BUNDLE_DOWNLOAD_SIZE); c->max_bundle_download_size = DEFAULT_MAX_BUNDLE_DOWNLOAD_SIZE; g_clear_error(&ierror); } else if (ierror) { g_propagate_error(error, ierror); res = FALSE; goto free; } if (c->max_bundle_download_size == 0) { g_set_error( error, R_CONFIG_ERROR, R_CONFIG_ERROR_MAX_BUNDLE_DOWNLOAD_SIZE, "Invalid value (%" G_GUINT64_FORMAT ") for key \"max-bundle-download-size\" in system config", c->max_bundle_download_size); res = FALSE; goto free; } g_key_file_remove_key(key_file, "system", "max-bundle-download-size", NULL); c->mount_prefix = key_file_consume_string(key_file, "system", "mountprefix", NULL); if (!c->mount_prefix) { g_debug("No mount prefix provided, using /mnt/rauc/ as default"); c->mount_prefix = g_strdup("/mnt/rauc/"); } if (g_strcmp0(c->system_bootloader, "grub") == 0) { c->grubenv_path = resolve_path(filename, key_file_consume_string(key_file, "system", "grubenv", NULL)); if (!c->grubenv_path) { g_debug("No grubenv path provided, using /boot/grub/grubenv as default"); c->grubenv_path = g_strdup("/boot/grub/grubenv"); } } c->activate_installed = g_key_file_get_boolean(key_file, "system", "activate-installed", &ierror); if (g_error_matches(ierror, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) { c->activate_installed = TRUE; g_clear_error(&ierror); } else if (ierror) { g_propagate_error(error, ierror); res = FALSE; goto free; } g_key_file_remove_key(key_file, "system", "activate-installed", NULL); c->system_variant_type = R_CONFIG_SYS_VARIANT_NONE; /* parse 'variant-dtb' key */ dtbvariant = g_key_file_get_boolean(key_file, "system", "variant-dtb", &ierror); if (g_error_matches(ierror, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) { dtbvariant = FALSE; g_clear_error(&ierror); } else if (ierror) { g_propagate_error(error, ierror); res = FALSE; goto free; } g_key_file_remove_key(key_file, "system", "variant-dtb", NULL); if (dtbvariant) c->system_variant_type = R_CONFIG_SYS_VARIANT_DTB; /* parse 'variant-file' key */ variant_data = key_file_consume_string(key_file, "system", "variant-file", &ierror); if (g_error_matches(ierror, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) { variant_data = NULL; g_clear_error(&ierror); } else if (ierror) { g_propagate_error(error, ierror); res = FALSE; goto free; } if (variant_data) { if (c->system_variant_type != R_CONFIG_SYS_VARIANT_NONE) { g_set_error( error, R_CONFIG_ERROR, R_CONFIG_ERROR_INVALID_FORMAT, "Only one of the keys 'variant-file', variant-dtb','variant-name' is allowed"); res = FALSE; goto free; } c->system_variant_type = R_CONFIG_SYS_VARIANT_FILE; c->system_variant = variant_data; } /* parse 'variant-name' key */ variant_data = key_file_consume_string(key_file, "system", "variant-name", &ierror); if (g_error_matches(ierror, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) { variant_data = NULL; g_clear_error(&ierror); } else if (ierror) { g_propagate_error(error, ierror); res = FALSE; goto free; } if (variant_data) { if (c->system_variant_type != R_CONFIG_SYS_VARIANT_NONE) { g_set_error( error, R_CONFIG_ERROR, R_CONFIG_ERROR_INVALID_FORMAT, "Only one of the keys 'variant-file', variant-dtb','variant-name' is allowed"); res = FALSE; goto free; } c->system_variant_type = R_CONFIG_SYS_VARIANT_NAME; c->system_variant = variant_data; } c->statusfile_path = resolve_path(filename, key_file_consume_string(key_file, "system", "statusfile", NULL)); if (!check_remaining_keys(key_file, "system", &ierror)) { g_propagate_error(error, ierror); res = FALSE; goto free; } g_key_file_remove_group(key_file, "system", NULL); /* parse [keyring] section */ c->keyring_path = resolve_path(filename, key_file_consume_string(key_file, "keyring", "path", NULL)); c->use_bundle_signing_time = g_key_file_get_boolean(key_file, "keyring", "use-bundle-signing-time", &ierror); if (g_error_matches(ierror, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND) || g_error_matches(ierror, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_GROUP_NOT_FOUND)) { c->use_bundle_signing_time = FALSE; g_clear_error(&ierror); } else if (ierror) { g_propagate_error(error, ierror); res = FALSE; goto free; } g_key_file_remove_key(key_file, "keyring", "use-bundle-signing-time", NULL); if (!check_remaining_keys(key_file, "keyring", &ierror)) { g_propagate_error(error, ierror); res = FALSE; goto free; } g_key_file_remove_group(key_file, "keyring", NULL); /* parse [casync] section */ c->store_path = key_file_consume_string(key_file, "casync", "storepath", NULL); if (!check_remaining_keys(key_file, "casync", &ierror)) { g_propagate_error(error, ierror); res = FALSE; goto free; } g_key_file_remove_group(key_file, "casync", NULL); /* parse [autoinstall] section */ c->autoinstall_path = resolve_path(filename, key_file_consume_string(key_file, "autoinstall", "path", NULL)); if (!check_remaining_keys(key_file, "autoinstall", &ierror)) { g_propagate_error(error, ierror); res = FALSE; goto free; } g_key_file_remove_group(key_file, "autoinstall", NULL); /* parse [handlers] section */ c->systeminfo_handler = resolve_path(filename, key_file_consume_string(key_file, "handlers", "system-info", NULL)); c->preinstall_handler = resolve_path(filename, key_file_consume_string(key_file, "handlers", "pre-install", NULL)); c->postinstall_handler = resolve_path(filename, key_file_consume_string(key_file, "handlers", "post-install", NULL)); if (!check_remaining_keys(key_file, "handlers", &ierror)) { g_propagate_error(error, ierror); res = FALSE; goto free; } g_key_file_remove_group(key_file, "handlers", NULL); /* parse [slot.*.#] sections */ slots = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, r_free_slot); groups = g_key_file_get_groups(key_file, &group_count); for (gsize i = 0; i < group_count; i++) { RaucSlot *slot = g_new0(RaucSlot, 1); gchar **groupsplit; groupsplit = g_strsplit(groups[i], ".", -1); /* We treat sections starting with "slot." as slots */ if (g_str_equal(groupsplit[0], RAUC_SLOT_PREFIX)) { gchar* value; /* Assure slot strings consist of 3 parts, delimited by dots */ if (g_strv_length(groupsplit) != 3) { g_set_error( error, R_CONFIG_ERROR, R_CONFIG_ERROR_INVALID_FORMAT, "Invalid slot name format: %s", groups[i]); res = FALSE; goto free; } value = g_strconcat(groupsplit[1], ".", groupsplit[2], NULL); if (!value) { g_set_error( error, R_CONFIG_ERROR, R_CONFIG_ERROR_INVALID_FORMAT, "Invalid slot name"); res = FALSE; goto free; } slot->name = g_intern_string(value); g_free(value); slot->description = key_file_consume_string(key_file, groups[i], "description", NULL); if (!slot->description) slot->description = g_strdup(""); slot->sclass = g_intern_string(groupsplit[1]); value = resolve_path(filename, key_file_consume_string(key_file, groups[i], "device", &ierror)); if (!value) { g_propagate_error(error, ierror); res = FALSE; goto free; } slot->device = value; value = key_file_consume_string(key_file, groups[i], "type", NULL); if (!value) value = g_strdup("raw"); slot->type = value; value = key_file_consume_string(key_file, groups[i], "bootname", NULL); slot->bootname = value; slot->readonly = g_key_file_get_boolean(key_file, groups[i], "readonly", &ierror); if (g_error_matches(ierror, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) { slot->readonly = FALSE; g_clear_error(&ierror); } else if (ierror) { g_propagate_error(error, ierror); res = FALSE; goto free; } g_key_file_remove_key(key_file, groups[i], "readonly", NULL); slot->force_install_same = g_key_file_get_boolean(key_file, groups[i], "force-install-same", &ierror); if (g_error_matches(ierror, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) { g_clear_error(&ierror); /* try also deprecatet flag ignore-checksum */ slot->force_install_same = g_key_file_get_boolean(key_file, groups[i], "ignore-checksum", &ierror); if (g_error_matches(ierror, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) { slot->force_install_same = FALSE; g_clear_error(&ierror); } else if (ierror) { g_propagate_error(error, ierror); res = FALSE; goto free; } } else if (ierror) { g_propagate_error(error, ierror); res = FALSE; goto free; } g_key_file_remove_key(key_file, groups[i], "force-install-same", NULL); g_key_file_remove_key(key_file, groups[i], "ignore-checksum", NULL); slot->extra_mount_opts = key_file_consume_string(key_file, groups[i], "extra-mount-opts", NULL); g_hash_table_insert(slots, (gchar*)slot->name, slot); } g_strfreev(groupsplit); } /* Add parent pointers */ slotlist = g_hash_table_get_keys(slots); for (l = slotlist; l != NULL; l = l->next) { RaucSlot *s; g_autofree gchar* group_name = NULL; gchar* value; group_name = g_strconcat(RAUC_SLOT_PREFIX ".", l->data, NULL); value = key_file_consume_string(key_file, group_name, "parent", NULL); if (!value) { g_key_file_remove_group(key_file, group_name, NULL); continue; } s = g_hash_table_lookup(slots, value); if (!s) { g_set_error( error, R_CONFIG_ERROR, R_CONFIG_ERROR_PARENT, "Parent slot '%s' not found!", value); res = FALSE; goto free; } ((RaucSlot*)g_hash_table_lookup(slots, l->data))->parent = s; if (!check_remaining_keys(key_file, group_name, &ierror)) { g_propagate_error(error, ierror); res = FALSE; goto free; } g_key_file_remove_group(key_file, group_name, NULL); } g_list_free(slotlist); c->slots = slots; if (!check_remaining_groups(key_file, &ierror)) { g_propagate_error(error, ierror); res = FALSE; goto free; } g_strfreev(groups); res = TRUE; free: if (res) *config = g_steal_pointer(&c); else *config = NULL; return res; }
int main(int argc, char **argv, char **envp) { int pid, c; const char *prj; char buf[4096]; char buf2[4096]; int flag_d = 0; int __optind = 0; int nscr = 0; char *ptr; environ = envp; radare_init(); while ((c = getopt(argc, argv, "l:fs:hb:wLvuVnxi:e:p:d")) != -1) { switch( c ) { case 'd': flag_d = 1; __optind = optind; break; case 'i': config.script[nscr++] = optarg; config.script[nscr] = NULL; break; case 'f': config.block_size = 0; break; case 'n': config.noscript = 1; break; case 'p': config_set("file.project", optarg); break; case 'w': config_set("file.write", "true"); break; case 's': config.seek = (ut64)get_offset(optarg); if (config.seek < 0) config.seek = (ut64)0; config_set("dbg.bep", optarg); break; case 'l': plugin_registry(optarg); break; case 'L': return plugin_list(); case 'b': config.block_size = (size_t)get_offset(optarg); config.block = (unsigned char *)realloc(config.block, config.block_size); config_set_i("cfg.bsize", config.block_size); break; case 'V': printf("radare %s %dbit on %s%dbit "TARGET" %s%s\n", VERSION, sizeof(ut64)*8, (LIL_ENDIAN)?"le":"be", sizeof(void *)*8, (DEBUGGER)? "dbg " :"", (HAVE_GUI)? "gui" :""); return 0; case 'u': config.unksize = 1; break; case 'x': config.mode = MODE_HEXDUMP; break; case 'e': config_eval(optarg); break; case 'h': help_message(0); return 0; case 'v': config_set("cfg.verbose", "false"); break; default: return 1; } } if (optind < argc) config.file = argv[optind++]; if (!flag_d && optind < argc) eprintf("warning: Only the first file has been opened.\n"); /* TODO: we have to recheck this :) */ if (flag_d) { optind--; config.debug = 1; prj = config_get("file.project"); if (__optind==argc) { if (prj == NULL) return help_message(1); snprintf(buf2, 4095, "dbg://%s", project_get_file(prj) ); config.file = strdup(buf2); } else { // XXX : overflowable, must use strcatdup or stgh like that // TODO: support hex pids too pid = atoi(argv[optind]); buf[0]='\0'; /* by process-id */ if (pid > 0) { sprintf(buf2, "pid://%d", pid); config.file = strdup(buf2); } else { #if DEBUGGER /* by program path */ for(c=optind; argv[c]; c++) { char *arg = argv[c]; if (c == optind) arg = (char *)resolve_path(argv[c]); ps.argv[c-optind] = arg; strcat(buf, arg); if (argv[c+1]) strcat(buf, " "); } ps.args = strdup(buf); if (strstr(buf, "://")) strcpy(buf2, buf); else sprintf(buf2, "dbg://%s", buf); config.file = strdup(buf2); ps.filename = strdup(buf2); //ptr = strchr(config.file, ' '); //if (ptr) *ptr = '\0'; //config.file = strdup(buf2); #else eprintf("TODO: Needs debugger\n"); #endif } } config_set("cfg.debug", "true"); } plugin_load(); return radare_go(); }
static xcb_xrm_database_t *__xcb_xrm_database_from_string(const char *_str, const char *base, int depth) { xcb_xrm_database_t *database; char *str; int num_continuations = 0; char *str_continued; char *outwalk; char *saveptr = NULL; if (_str == NULL) return xcb_xrm_database_from_string(""); str = strdup(_str); if (str == NULL) return NULL; /* Count the number of line continuations. */ for (char *walk = str; *walk != '\0'; walk++) { if (*walk == '\\' && *(walk + 1) == '\n') { num_continuations++; } } /* Take care of line continuations. */ str_continued = calloc(1, strlen(str) + 1 - 2 * num_continuations); if (str_continued == NULL) { FREE(str); return NULL; } outwalk = str_continued; for (char *walk = str; *walk != '\0'; walk++) { if (*walk == '\\' && *(walk + 1) == '\n') { walk++; continue; } *(outwalk++) = *walk; } *outwalk = '\0'; database = calloc(1, sizeof(struct xcb_xrm_database_t)); if (database == NULL) { FREE(str); FREE(str_continued); return NULL; } TAILQ_INIT(database); for (char *line = strtok_r(str_continued, "\n", &saveptr); line != NULL; line = strtok_r(NULL, "\n", &saveptr)) { /* Handle include directives. */ if (line[0] == '#') { int i = 1; /* Skip whitespace and quotes. */ while (line[i] == ' ' || line[i] == '\t') i++; if (depth < MAX_INCLUDE_DEPTH && line[i++] == 'i' && line[i++] == 'n' && line[i++] == 'c' && line[i++] == 'l' && line[i++] == 'u' && line[i++] == 'd' && line[i++] == 'e') { xcb_xrm_database_t *included; char *filename; char *copy; char *new_base; int j = strlen(line) - 1; /* Skip whitespace and quotes. */ while (line[i] == ' ' || line[i] == '\t' || line[i] == '"') i++; while (line[j] == ' ' || line[j] == '\t' || line[j] == '"') j--; if (j < i) { /* Only whitespace left in this line. */ continue; } line[j+1] = '\0'; filename = resolve_path(&line[i], base); if (filename == NULL) continue; /* We need to strdup() the filename since dirname() will modify it. */ copy = strdup(filename); if (copy == NULL) { FREE(filename); continue; } new_base = dirname(copy); if (new_base == NULL) { FREE(filename); FREE(copy); continue; } included = __xcb_xrm_database_from_file(filename, new_base, depth + 1); FREE(filename); FREE(copy); if (included != NULL) { xcb_xrm_database_combine(included, &database, true); xcb_xrm_database_free(included); } continue; } } xcb_xrm_database_put_resource_line(&database, line); } FREE(str); FREE(str_continued); return database; }