/* command.c - support basic command */ /* * VAS_EBOOT -- GRand Unified Bootloader * Copyright (C) 2009 Free Software Foundation, Inc. * * VAS_EBOOT is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * VAS_EBOOT is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with VAS_EBOOT. If not, see . */ #include #include #include VasEBoot_command_t VasEBoot_command_list; VasEBoot_command_t VasEBoot_register_command_prio (const char *name, VasEBoot_command_func_t func, const char *summary, const char *description, int prio) { VasEBoot_command_t cmd; int inactive = 0; VasEBoot_command_t *p, q; cmd = (VasEBoot_command_t) VasEBoot_zalloc (sizeof (*cmd)); if (! cmd) return 0; cmd->name = name; cmd->func = func; cmd->summary = (summary) ? summary : ""; cmd->description = description; cmd->flags = 0; cmd->prio = prio; for (p = &VasEBoot_command_list, q = *p; q; p = &(q->next), q = q->next) { int r; r = VasEBoot_strcmp (cmd->name, q->name); if (r < 0) break; if (r > 0) continue; if (cmd->prio >= (q->prio & VAS_EBOOT_COMMAND_PRIO_MASK)) { q->prio &= ~VAS_EBOOT_COMMAND_FLAG_ACTIVE; break; } inactive = 1; } *p = cmd; cmd->next = q; if (q) q->prev = &cmd->next; cmd->prev = p; if (! inactive) cmd->prio |= VAS_EBOOT_COMMAND_FLAG_ACTIVE; return cmd; } static VasEBoot_err_t VasEBoot_cmd_lockdown (VasEBoot_command_t cmd __attribute__ ((unused)), int argc __attribute__ ((unused)), char **argv __attribute__ ((unused))) { return VasEBoot_error (VAS_EBOOT_ERR_ACCESS_DENIED, N_("%s: the command is not allowed when lockdown is enforced"), cmd->name); } VasEBoot_command_t VasEBoot_register_command_lockdown (const char *name, VasEBoot_command_func_t func, const char *summary, const char *description) { if (VasEBoot_is_lockdown () == VAS_EBOOT_LOCKDOWN_ENABLED) func = VasEBoot_cmd_lockdown; return VasEBoot_register_command_prio (name, func, summary, description, 0); } void VasEBoot_unregister_command (VasEBoot_command_t cmd) { if (cmd == NULL) return; if ((cmd->prio & VAS_EBOOT_COMMAND_FLAG_ACTIVE) && (cmd->next)) cmd->next->prio |= VAS_EBOOT_COMMAND_FLAG_ACTIVE; VasEBoot_list_remove (VAS_EBOOT_AS_LIST (cmd)); VasEBoot_free (cmd); }