2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2013 Free Software Foundation, Inc.
5 * GRUB is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * GRUB is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
19 #include <grub/types.h>
20 #include <grub/misc.h>
21 #include <grub/extcmd.h>
25 #include <grub/file.h>
26 #include <grub/normal.h>
27 #include <grub/script_sh.h>
28 #include <grub/i18n.h>
29 #include <grub/term.h>
30 #include <grub/syslinux_parse.h>
31 #include <grub/crypto.h>
32 #include <grub/auth.h>
33 #include <grub/disk.h>
34 #include <grub/partition.h>
36 GRUB_MOD_LICENSE ("GPLv3+");
38 /* Helper for syslinux_file. */
40 syslinux_file_getline (char **line
, int cont
__attribute__ ((unused
)),
41 void *data
__attribute__ ((unused
)))
47 static const struct grub_arg_option options
[] =
50 N_("root directory of the syslinux disk [default=/]."),
51 N_("DIR"), ARG_TYPE_STRING
},
53 N_("current directory of syslinux [default is parent directory of input file]."),
54 N_("DIR"), ARG_TYPE_STRING
},
55 {"isolinux", 'i', 0, N_("assume input is an isolinux configuration file."), 0, 0},
56 {"pxelinux", 'p', 0, N_("assume input is a pxelinux configuration file."), 0, 0},
57 {"syslinux", 's', 0, N_("assume input is a syslinux configuration file."), 0, 0},
71 syslinux_file (grub_extcmd_context_t ctxt
, const char *filename
)
74 const char *root
= ctxt
->state
[OPTION_ROOT
].set
? ctxt
->state
[OPTION_ROOT
].arg
: "/";
75 const char *cwd
= ctxt
->state
[OPTION_CWD
].set
? ctxt
->state
[OPTION_CWD
].arg
: NULL
;
76 grub_syslinux_flavour_t flav
= GRUB_SYSLINUX_UNKNOWN
;
80 if (ctxt
->state
[OPTION_ISOLINUX
].set
)
81 flav
= GRUB_SYSLINUX_ISOLINUX
;
82 if (ctxt
->state
[OPTION_PXELINUX
].set
)
83 flav
= GRUB_SYSLINUX_PXELINUX
;
84 if (ctxt
->state
[OPTION_SYSLINUX
].set
)
85 flav
= GRUB_SYSLINUX_SYSLINUX
;
90 cwdf
= grub_strdup (filename
);
93 p
= grub_strrchr (cwdf
, '/');
107 grub_dprintf ("syslinux",
108 "transforming syslinux config %s, root = %s, cwd = %s\n",
109 filename
, root
, cwd
);
111 result
= grub_syslinux_config_file (root
, root
, cwd
, cwd
, filename
, flav
);
115 grub_dprintf ("syslinux", "syslinux config transformed\n");
117 menu
= grub_env_get_menu ();
120 menu
= grub_zalloc (sizeof (*menu
));
127 grub_env_set_menu (menu
);
130 grub_normal_parse_line (result
, syslinux_file_getline
, NULL
);
135 return GRUB_ERR_NONE
;
139 grub_cmd_syslinux_source (grub_extcmd_context_t ctxt
,
140 int argc
, char **args
)
142 int new_env
, extractor
;
146 return grub_error (GRUB_ERR_BAD_ARGUMENT
, N_("filename expected"));
148 extractor
= (ctxt
->extcmd
->cmd
->name
[0] == 'e');
149 new_env
= (ctxt
->extcmd
->cmd
->name
[extractor
? (sizeof ("extract_syslinux_entries_") - 1)
150 : (sizeof ("syslinux_") - 1)] == 'c');
155 if (new_env
&& !extractor
)
156 grub_env_context_open ();
158 grub_env_extractor_open (!new_env
);
160 ret
= syslinux_file (ctxt
, args
[0]);
165 menu
= grub_env_get_menu ();
166 if (menu
&& menu
->size
)
167 grub_show_menu (menu
, 1, 0);
169 grub_env_context_close ();
172 grub_env_extractor_close (!new_env
);
178 static grub_extcmd_t cmd_source
, cmd_configfile
;
179 static grub_extcmd_t cmd_source_extract
, cmd_configfile_extract
;
181 GRUB_MOD_INIT(syslinuxcfg
)
184 = grub_register_extcmd ("syslinux_source",
185 grub_cmd_syslinux_source
, 0,
187 /* TRANSLATORS: "syslinux config" means
188 "config as used by syslinux". */
189 N_("Execute syslinux config in same context"),
192 = grub_register_extcmd ("syslinux_configfile",
193 grub_cmd_syslinux_source
, 0,
195 N_("Execute syslinux config in new context"),
198 = grub_register_extcmd ("extract_syslinux_entries_source",
199 grub_cmd_syslinux_source
, 0,
201 N_("Execute syslinux config in same context taking only menu entries"),
203 cmd_configfile_extract
204 = grub_register_extcmd ("extract_syslinux_entries_configfile",
205 grub_cmd_syslinux_source
, 0,
207 N_("Execute syslinux config in new context taking only menu entries"),
211 GRUB_MOD_FINI(syslinuxcfg
)
213 grub_unregister_extcmd (cmd_source
);
214 grub_unregister_extcmd (cmd_configfile
);
215 grub_unregister_extcmd (cmd_source_extract
);
216 grub_unregister_extcmd (cmd_configfile_extract
);