static void grub_crypto_autoload (const char *name) { struct load_spec *cur; grub_dl_t mod; static int depth = 0; /* Some bufio of filesystems may want some crypto modules. It may result in infinite recursion. Hence this check. */ if (depth) return; depth++; for (cur = crypto_specs; cur; cur = cur->next) if (grub_strcasecmp (name, cur->name) == 0) { mod = grub_dl_load (cur->modname); if (mod) grub_dl_ref (mod); grub_errno = GRUB_ERR_NONE; } depth--; }
/* Parse a test expression starting from *argn. */ static int test_parse (char **args, int *argn, int argc) { int ret = 0, discard = 0, invert = 0; int file_exists; struct grub_dirhook_info file_info; auto void update_val (int val); auto void get_fileinfo (char *pathname); /* Take care of discarding and inverting. */ void update_val (int val) { if (! discard) ret = invert ? ! val : val; invert = discard = 0; } /* Check if file exists and fetch its information. */ void get_fileinfo (char *path) { char *filename, *pathname; char *device_name; grub_fs_t fs; grub_device_t dev; /* A hook for iterating directories. */ auto int find_file (const char *cur_filename, const struct grub_dirhook_info *info); int find_file (const char *cur_filename, const struct grub_dirhook_info *info) { if ((info->case_insensitive ? grub_strcasecmp (cur_filename, filename) : grub_strcmp (cur_filename, filename)) == 0) { file_info = *info; file_exists = 1; return 1; } return 0; } file_exists = 0; device_name = grub_file_get_device_name (path); dev = grub_device_open (device_name); if (! dev) { grub_free (device_name); return; } fs = grub_fs_probe (dev); if (! fs) { grub_free (device_name); grub_device_close (dev); return; } pathname = grub_strchr (path, ')'); if (! pathname) pathname = path; else pathname++; /* Remove trailing '/'. */ while (*pathname && pathname[grub_strlen (pathname) - 1] == '/') pathname[grub_strlen (pathname) - 1] = 0; /* Split into path and filename. */ filename = grub_strrchr (pathname, '/'); if (! filename) { path = grub_strdup ("/"); filename = pathname; } else { filename++; path = grub_strdup (pathname); path[filename - pathname] = 0; } /* It's the whole device. */ if (! *pathname) { file_exists = 1; grub_memset (&file_info, 0, sizeof (file_info)); /* Root is always a directory. */ file_info.dir = 1; /* Fetch writing time. */ file_info.mtimeset = 0; if (fs->mtime) { if (! fs->mtime (dev, &file_info.mtime)) file_info.mtimeset = 1; grub_errno = GRUB_ERR_NONE; } } else (fs->dir) (dev, path, find_file); grub_device_close (dev); grub_free (path); grub_free (device_name); }
/* Helper for FUNC_NAME. */ static int iterate_device (const char *name, void *data) { struct search_ctx *ctx = data; int found = 0; /* Skip floppy drives when requested. */ if (ctx->no_floppy && name[0] == 'f' && name[1] == 'd' && name[2] >= '0' && name[2] <= '9') return 0; #ifdef DO_SEARCH_FS_UUID #define compare_fn grub_strcasecmp #else #define compare_fn grub_strcmp #endif #ifdef DO_SEARCH_FILE { char *buf; grub_file_t file; buf = grub_xasprintf ("(%s)%s", name, ctx->key); if (! buf) return 1; grub_file_filter_disable_compression (); file = grub_file_open (buf); if (file) { found = 1; grub_file_close (file); } grub_free (buf); } #elif defined(DO_SEARCH_PART_UUID) { grub_device_t dev; char *quid; dev = grub_device_open (name); if (dev) { if (grub_gpt_part_uuid (dev, &quid) == GRUB_ERR_NONE) { if (grub_strcasecmp (quid, ctx->key) == 0) found = 1; grub_free (quid); } grub_device_close (dev); } } #elif defined(DO_SEARCH_PART_LABEL) { grub_device_t dev; char *quid; dev = grub_device_open (name); if (dev) { if (grub_gpt_part_label (dev, &quid) == GRUB_ERR_NONE) { if (grub_strcmp (quid, ctx->key) == 0) found = 1; grub_free (quid); } grub_device_close (dev); } } #else { /* SEARCH_FS_UUID or SEARCH_LABEL */ grub_device_t dev; grub_fs_t fs; char *quid; dev = grub_device_open (name); if (dev) { fs = grub_fs_probe (dev); #ifdef DO_SEARCH_FS_UUID #define read_fn uuid #else #define read_fn label #endif if (fs && fs->read_fn) { fs->read_fn (dev, &quid); if (grub_errno == GRUB_ERR_NONE && quid) { if (compare_fn (quid, ctx->key) == 0) found = 1; grub_free (quid); } } grub_device_close (dev); } } #endif if (!ctx->is_cache && found && ctx->count == 0) { struct cache_entry *cache_ent; cache_ent = grub_malloc (sizeof (*cache_ent)); if (cache_ent) { cache_ent->key = grub_strdup (ctx->key); cache_ent->value = grub_strdup (name); if (cache_ent->value && cache_ent->key) { cache_ent->next = cache; cache = cache_ent; } else { grub_free (cache_ent->value); grub_free (cache_ent->key); grub_free (cache_ent); grub_errno = GRUB_ERR_NONE; } } else grub_errno = GRUB_ERR_NONE; } if (found) { ctx->count++; if (ctx->var) grub_env_set (ctx->var, name); else grub_printf (" %s", name); } grub_errno = GRUB_ERR_NONE; return (found && ctx->var); }
int registerCharacterSet (const char *charset) { return grub_strcasecmp(charset, "UTF-8") == 0; }