2 * Copyright (c)2004 The DragonFly Project. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
11 * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
16 * Neither the name of the DragonFly Project nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
31 * OF THE POSSIBILITY OF SUCH DAMAGE.
36 * Configuration functions for installer.
37 * This includes both Configure the LiveCD Environment, and
38 * Configure an Installed System (there is considerable overlap.)
39 * $Id: fn_configure.c,v 1.82 2005/03/25 05:24:00 cpressey Exp $
43 #include <sys/types.h>
58 #define _(String) gettext (String)
60 #define _(String) (String)
63 #include "libaura/mem.h"
64 #include "libaura/dict.h"
65 #include "libaura/fspred.h"
67 #include "libdfui/dfui.h"
68 #include "libdfui/system.h"
70 #include "libinstaller/commands.h"
71 #include "libinstaller/confed.h"
72 #include "libinstaller/diskutil.h"
73 #include "libinstaller/functions.h"
74 #include "libinstaller/package.h"
75 #include "libinstaller/uiutil.h"
79 #include "pathnames.h"
81 static const char *yes_to_y(const char *);
82 static char *convert_tmpfs_options(char *);
84 /** CONFIGURE FUNCTIONS **/
86 #define PW_NOT_ALLOWED ":;,`~!@#$%^&*()+={}[]\\|/?<>'\" "
87 #define GECOS_NOT_ALLOWED ":,\\\""
88 #define FILENAME_NOT_ALLOWED ":;`~!#$^&*()={}[]\\|?<>'\" "
89 #define MEMBERSHIPS_NOT_ALLOWED ":;`~!@#$%^&*()+={}[]\\|/?<>'\" "
92 fn_add_user(struct i_fn_args *a)
94 struct dfui_dataset *ds, *new_ds;
96 struct dfui_response *r;
97 struct commands *cmds;
99 const char *username, *home, *passwd_1, *passwd_2, *gecos;
100 const char *shell, *uid, *group, *groups;
103 f = dfui_form_create(
106 _("Here you can add a user to an installed system.\n\n"
107 "You can leave the Home Directory, User ID, and Login Group "
108 "fields empty if you want these items to be automatically "
109 "allocated by the system.\n\n"
110 "Note: this user's password will appear in the install log. "
111 "If this is a problem, please add the user manually after "
112 "rebooting into the installed system instead."),
114 "f", "username", _("Username"),
115 _("Enter the username the user will log in as"), "",
116 "f", "gecos", _("Real Name"),
117 _("Enter the real name (or GECOS field) of this user"), "",
118 "f", "passwd_1", _("Password"),
119 _("Enter the user's password (will not be displayed)"), "",
120 "p", "obscured", "true",
121 "f", "passwd_2", _("Password (Again)"),
122 _("Re-enter the user's password to confirm"), "",
123 "p", "obscured", "true",
124 "f", "shell", _("Shell"),
125 _("Enter the full path to the user's shell program"), "",
126 "f", "home", _("Home Directory"),
127 _("Enter the full path to the user's home directory, or leave blank"), "",
128 "f", "uid", _("User ID"),
129 _("Enter this account's numeric user id, or leave blank"), "",
130 "f", "group", _("Login Group"),
131 _("Enter the primary group for this account, or leave blank"), "",
132 "f", "groups", _("Other Group Memberships"),
133 _("Enter a comma-separated list of other groups "
134 "that this user should belong to"), "",
135 "a", "ok", _("Accept and Add"), "", "",
136 "a", "cancel", _("Return to Configure Menu"), "", "",
137 "p", "accelerator", "ESC",
141 ds = dfui_dataset_new();
142 dfui_dataset_celldata_add(ds, "username", "");
143 dfui_dataset_celldata_add(ds, "gecos", "");
144 dfui_dataset_celldata_add(ds, "passwd_1", "");
145 dfui_dataset_celldata_add(ds, "passwd_2", "");
146 dfui_dataset_celldata_add(ds, "shell", "/bin/tcsh");
147 dfui_dataset_celldata_add(ds, "home", "");
148 dfui_dataset_celldata_add(ds, "uid", "");
149 dfui_dataset_celldata_add(ds, "group", "");
150 dfui_dataset_celldata_add(ds, "groups", "");
151 dfui_form_dataset_add(f, ds);
154 if (!dfui_be_present(a->c, f, &r))
157 if (strcmp(dfui_response_get_action_id(r), "cancel") == 0) {
159 dfui_response_free(r);
163 new_ds = dfui_dataset_dup(dfui_response_dataset_get_first(r));
164 dfui_form_datasets_free(f);
165 dfui_form_dataset_add(f, new_ds);
167 /* Fetch form field values. */
169 username = dfui_dataset_get_value(new_ds, "username");
170 home = dfui_dataset_get_value(new_ds, "home");
171 gecos = dfui_dataset_get_value(new_ds, "gecos");
172 shell = dfui_dataset_get_value(new_ds, "shell");
173 passwd_1 = dfui_dataset_get_value(new_ds, "passwd_1");
174 passwd_2 = dfui_dataset_get_value(new_ds, "passwd_2");
175 uid = dfui_dataset_get_value(new_ds, "uid");
176 group = dfui_dataset_get_value(new_ds, "group");
177 groups = dfui_dataset_get_value(new_ds, "groups");
179 if (strlen(username) == 0) {
180 inform(a->c, _("You must enter a username."));
182 } else if (strcmp(passwd_1, passwd_2) != 0) {
183 /* Passwords don't match; tell the user. */
184 inform(a->c, _("The passwords do not match."));
186 } else if (!assert_clean(a->c, _("Username"), username, PW_NOT_ALLOWED) ||
187 !assert_clean(a->c, _("Real Name"), gecos, GECOS_NOT_ALLOWED) ||
188 !assert_clean(a->c, _("Password"), passwd_1, PW_NOT_ALLOWED) ||
189 !assert_clean(a->c, _("Shell"), shell, FILENAME_NOT_ALLOWED) ||
190 !assert_clean(a->c, _("Home Directory"), home, FILENAME_NOT_ALLOWED) ||
191 !assert_clean(a->c, _("User ID"), uid, PW_NOT_ALLOWED) ||
192 !assert_clean(a->c, _("Login Group"), group, PW_NOT_ALLOWED) ||
193 !assert_clean(a->c, _("Group Memberships"), groups, MEMBERSHIPS_NOT_ALLOWED)) {
195 } else if (!is_program("%s%s", a->os_root, shell) &&
196 strcmp(shell, "/nonexistent") != 0) {
197 inform(a->c, _("Chosen shell does not exist on the system."));
200 cmds = commands_new();
202 command_add(cmds, "%s%s %smnt/ /%s useradd "
203 "'%s' %s%s %s%s -c \"%s\" %s%s -s %s %s%s %s",
204 a->os_root, cmd_name(a, "CHROOT"),
205 a->os_root, cmd_name(a, "PW"),
207 strlen(uid) == 0 ? "" : "-u ", uid,
208 strlen(group) == 0 ? "" : "-g ", group,
210 strlen(home) == 0 ? "" : "-d ", home,
212 strlen(groups) == 0 ? "" : "-G ", groups,
213 (strlen(home) == 0 || !is_dir(home)) ?
214 "-m -k /usr/share/skel" : "");
216 cmd = command_add(cmds, "%s%s '%s' | "
217 "%s%s %smnt/ /%s usermod '%s' -h 0",
218 a->os_root, cmd_name(a, "ECHO"),
220 a->os_root, cmd_name(a, "CHROOT"),
221 a->os_root, cmd_name(a, "PW"),
223 command_set_desc(cmd, _("Setting password..."));
225 if (commands_execute(a, cmds)) {
226 inform(a->c, _("User `%s' was added."), username);
229 inform(a->c, _("User was not successfully added."));
236 dfui_response_free(r);
243 fn_root_passwd(struct i_fn_args *a)
245 struct dfui_dataset *ds, *new_ds;
247 struct dfui_response *r;
248 struct commands *cmds;
250 const char *root_passwd_1, *root_passwd_2;
253 f = dfui_form_create(
255 _("Set Root Password"),
256 _("Here you can set the super-user (root) password.\n\n"
257 "Note: root's new password will appear in the install log. "
258 "If this is a problem, please set root's password manually "
259 "after rebooting into the installed system instead."),
262 "f", "root_passwd_1", _("Root password"),
263 _("Enter the root password you would like to use"), "",
264 "p", "obscured", "true",
265 "f", "root_passwd_2", _("Root password again"),
266 _("Enter the root password again to confirm"), "",
267 "p", "obscured", "true",
269 "a", "ok", _("Accept and Set Password"), "", "",
270 "a", "cancel", _("Return to Configure Menu"), "", "",
271 "p", "accelerator", "ESC",
276 ds = dfui_dataset_new();
277 dfui_dataset_celldata_add(ds, "root_passwd_1", "");
278 dfui_dataset_celldata_add(ds, "root_passwd_2", "");
279 dfui_form_dataset_add(f, ds);
282 if (!dfui_be_present(a->c, f, &r))
285 if (strcmp(dfui_response_get_action_id(r), "ok") == 0) {
286 new_ds = dfui_dataset_dup(dfui_response_dataset_get_first(r));
287 dfui_form_datasets_free(f);
288 dfui_form_dataset_add(f, new_ds);
291 * Fetch form field values.
294 root_passwd_1 = dfui_dataset_get_value(new_ds, "root_passwd_1");
295 root_passwd_2 = dfui_dataset_get_value(new_ds, "root_passwd_2");
297 if (!assert_clean(a->c, _("Root password"), root_passwd_1, PW_NOT_ALLOWED)) {
299 } else if (strlen(root_passwd_1) == 0 && strlen(root_passwd_2) == 0) {
301 } else if (strcmp(root_passwd_1, root_passwd_2) == 0) {
303 * Passwords match, so set the root password.
305 cmds = commands_new();
306 cmd = command_add(cmds, "%s%s '%s' | "
307 "%s%s %smnt/ /%s usermod root -h 0",
308 a->os_root, cmd_name(a, "ECHO"),
310 a->os_root, cmd_name(a, "CHROOT"),
311 a->os_root, cmd_name(a, "PW"));
312 command_set_desc(cmd, _("Setting password..."));
313 if (commands_execute(a, cmds)) {
314 inform(a->c, _("The root password has been changed."));
317 inform(a->c, _("An error occurred when "
318 "setting the root password."));
324 * Passwords don't match - tell the user, let them try again.
326 inform(a->c, _("The passwords do not match."));
336 dfui_response_free(r);
343 fn_get_passphrase(struct i_fn_args *a)
345 struct dfui_dataset *ds, *new_ds;
347 struct dfui_response *r;
348 const char *passphrase_1, *passphrase_2;
352 f = dfui_form_create(
354 _("Set Passphrase For Encryption"),
355 _("Please specify the passphrase to be used for the encrypted "
357 "Please note that in the LiveCD environment the keymap is set to "
359 "If you prefer a different keymap for entering the passphrase "
360 "here, you will need to set it manually using kbdcontrol(1)."),
363 "f", "passphrase_1", _("Passphrase"),
364 _("Enter the passphrase you would like to use for encryption"), "",
365 "p", "obscured", "true",
366 "f", "passphrase_2", _("Passphrase again"),
367 _("Enter the passphrase again to confirm"), "",
368 "p", "obscured", "true",
370 "a", "ok", _("Accept and Set Passphrase"), "", "",
371 "p", "accelerator", "ESC",
376 ds = dfui_dataset_new();
377 dfui_dataset_celldata_add(ds, "passphrase_1", "");
378 dfui_dataset_celldata_add(ds, "passphrase_2", "");
379 dfui_form_dataset_add(f, ds);
382 if (!dfui_be_present(a->c, f, &r))
385 if (strcmp(dfui_response_get_action_id(r), "ok") == 0) {
386 new_ds = dfui_dataset_dup(dfui_response_dataset_get_first(r));
387 dfui_form_datasets_free(f);
388 dfui_form_dataset_add(f, new_ds);
391 * Fetch form field values.
394 passphrase_1 = dfui_dataset_get_value(new_ds, "passphrase_1");
395 passphrase_2 = dfui_dataset_get_value(new_ds, "passphrase_2");
397 if (strlen(passphrase_1) == 0 && strlen(passphrase_2) == 0) {
399 } else if (strcmp(passphrase_1, passphrase_2) == 0) {
401 * Passphrases match, write it out.
403 fd = open("/tmp/t1", O_RDWR | O_CREAT | O_TRUNC,
406 write(fd, passphrase_1, strlen(passphrase_1));
410 inform(a->c, _("write() error"));
415 * Passphrases don't match, tell the user,
416 * let them try again.
418 inform(a->c, _("The passphrases do not match."));
423 dfui_response_free(r);
430 fn_install_packages(struct i_fn_args *a)
433 struct commands *cmds;
434 struct dfui_celldata *cd;
435 struct dfui_dataset *ds;
436 struct dfui_field *fi;
438 struct dfui_response *r;
441 char msg_buf[1][1024];
442 struct aura_dict *seen;
444 snprintf(msg_buf[0], sizeof(msg_buf[0]),
445 _("Select optional software packages that you want "
446 "installed on this system. This form lists only the "
447 "software packages installed on the LiveCD; thousands "
448 "more are available via the internet once %s "
450 OPERATING_SYSTEM_NAME);
452 f = dfui_form_create(
454 _("Install Packages"),
458 "p", "special", "dfinstaller_install_packages",
463 ds = dfui_dataset_new();
464 snprintf(command, 256, "ls %svar/db/pkg", a->os_root);
465 if ((pfp = popen(command, "r")) != NULL) {
466 while (fgets(pkg_name, 255, pfp) != NULL) {
467 while (strlen(pkg_name) > 0 &&
468 isspace(pkg_name[strlen(pkg_name) - 1])) {
469 pkg_name[strlen(pkg_name) - 1] = '\0';
471 fi = dfui_form_field_add(f, pkg_name,
472 dfui_info_new(pkg_name, "", ""));
473 dfui_field_property_set(fi, "control", "checkbox");
474 dfui_dataset_celldata_add(ds,
479 dfui_form_dataset_add(f, ds);
481 dfui_form_action_add(f, "ok",
482 dfui_info_new(_("Accept and Install"), "", ""));
483 dfui_form_action_add(f, "cancel",
484 dfui_info_new(_("Return to Configure Menu"), "", ""));
486 if (!dfui_be_present(a->c, f, &r))
489 if (strcmp(dfui_response_get_action_id(r), "ok") == 0) {
490 cmds = commands_new();
491 seen = aura_dict_new(23, AURA_DICT_HASH);
493 cd = dfui_dataset_celldata_get_first(dfui_response_dataset_get_first(r));
496 strlcpy(pkg_name, dfui_celldata_get_field_id(cd), 256);
497 if (!strcasecmp(dfui_celldata_get_value(cd), "Y")) {
498 if (!pkg_copy(a, cmds, pkg_name, seen)) {
499 inform(a->c, _("Couldn't install package `%s'."), pkg_name);
503 cd = dfui_celldata_get_next(cd);
506 if (!commands_execute(a, cmds)) {
507 inform(a->c, _("Packages were not fully installed."));
509 inform(a->c, _("Packages were successfully installed!"));
512 aura_dict_free(seen);
517 dfui_response_free(r);
521 fn_remove_packages(struct i_fn_args *a)
524 struct commands *cmds;
525 struct dfui_celldata *cd;
526 struct dfui_dataset *ds;
527 struct dfui_field *fi;
529 struct dfui_response *r;
532 struct aura_dict *seen;
534 f = dfui_form_create(
536 _("Remove Packages"),
537 _("Select the installed software packages that you want "
538 "removed from this system."),
541 "p", "special", "dfinstaller_remove_packages",
546 ds = dfui_dataset_new();
547 snprintf(command, 256, "ls %smnt/var/db/pkg", a->os_root);
548 if ((pfp = popen(command, "r")) != NULL) {
549 while (fgets(pkg_name, 255, pfp)) {
550 pkg_name[strlen(pkg_name) - 1] = '\0';
551 fi = dfui_form_field_add(f, pkg_name,
552 dfui_info_new(pkg_name, "", ""));
553 dfui_field_property_set(fi, "control", "checkbox");
554 dfui_dataset_celldata_add(ds,
559 dfui_form_dataset_add(f, ds);
561 dfui_form_action_add(f, "ok",
562 dfui_info_new(_("Accept and Remove"), "", ""));
563 dfui_form_action_add(f, "cancel",
564 dfui_info_new(_("Return to Configure Menu"), "", ""));
566 if (!dfui_be_present(a->c, f, &r))
569 if (strcmp(dfui_response_get_action_id(r), "ok") == 0) {
570 cmds = commands_new();
571 seen = aura_dict_new(23, AURA_DICT_HASH);
573 cd = dfui_dataset_celldata_get_first(dfui_response_dataset_get_first(r));
576 strlcpy(pkg_name, dfui_celldata_get_field_id(cd), 256);
577 if (!strcasecmp(dfui_celldata_get_value(cd), "Y")) {
578 if (!pkg_remove(a, cmds, pkg_name, seen)) {
579 inform(a->c, _("Couldn't remove package `%s'."), pkg_name);
583 cd = dfui_celldata_get_next(cd);
586 if (!commands_execute(a, cmds)) {
587 inform(a->c, _("Packages were not fully removed."));
589 inform(a->c, _("Packages were successfully removed."));
592 aura_dict_free(seen);
597 dfui_response_free(r);
600 /** LIVECD UTILITIES FUNCTIONS **/
603 * String returned by this function must be deallocated by the caller.
606 fn_select_file(const char *title, const char *desc, const char *help, const char *cancel,
607 const char *dir, const char *ext, const struct i_fn_args *a)
611 struct dfui_action *k;
612 struct dfui_response *r;
615 struct aura_dict *dict;
619 f = dfui_form_create(
626 dict = aura_dict_new(1, AURA_DICT_SORTED_LIST);
628 while ((de = readdir(d)) != NULL) {
629 if (strcmp(de->d_name, ".") == 0 ||
630 strcmp(de->d_name, "..") == 0 ||
631 strstr(de->d_name, ext) == NULL)
633 aura_dict_store(dict, de->d_name, strlen(de->d_name) + 1, "", 1);
637 aura_dict_rewind(dict);
638 while (!aura_dict_eof(dict)) {
639 aura_dict_get_current_key(dict, (void **)&rk, &rk_len),
640 dfui_form_action_add(f, rk,
641 dfui_info_new(rk, "", ""));
642 aura_dict_next(dict);
644 aura_dict_free(dict);
646 k = dfui_form_action_add(f, "cancel",
647 dfui_info_new(cancel, "", ""));
648 dfui_action_property_set(k, "accelerator", "ESC");
650 if (!dfui_be_present(a->c, f, &r))
653 s = aura_strdup(dfui_response_get_action_id(r));
656 dfui_response_free(r);
662 fn_set_kbdmap(struct i_fn_args *a)
664 struct commands *cmds;
666 char filename[256], keymapname[256];
668 s = fn_select_file(_("Select Keyboard Map"),
669 _("Select a keyboard map appropriate to your keyboard layout."),
670 "", _("Return to Utilities Menu"), "/usr/share/syscons/keymaps",
673 if (strcmp(s, "cancel") != 0) {
674 cmds = commands_new();
675 command_add(cmds, "%s%s -l "
676 "/usr/share/syscons/keymaps/%s < /dev/ttyv0",
677 a->os_root, cmd_name(a, "KBDCONTROL"),
679 if (commands_execute(a, cmds)) {
680 snprintf(filename, 256, "/usr/share/syscons/keymaps/%s", s);
681 snprintf(keymapname, 256, filename_noext(basename(filename)));
682 config_var_set(rc_conf, "keymap", keymapname);
684 inform(a->c, _("Keyboard map not successfully set."));
693 fn_set_vidfont(struct i_fn_args *a)
695 struct commands *cmds;
697 char filename[256], variable[256], fontname[256];
701 s = fn_select_file(_("Select Console Font"),
702 _("Select a font appropriate to your video monitor and language."),
703 "", _("Return to Utilities Menu"), "/usr/share/syscons/fonts",
706 if (strcmp(s, "cancel") != 0) {
707 cmds = commands_new();
708 command_add(cmds, "%s%s -f "
709 "/usr/share/syscons/fonts/%s < /dev/ttyv0",
710 a->os_root, cmd_name(a, "VIDCONTROL"),
712 if (commands_execute(a, cmds)) {
713 if (strstr(s, "8x16") != NULL)
715 else if (strstr(s, "8x14") != NULL)
720 snprintf(variable, 256, "font8x%d", by);
721 snprintf(filename, 256, "/usr/share/syscons/fonts/%s", s);
722 snprintf(fontname, 256, filename_noext(basename(filename)));
723 config_var_set(rc_conf, variable, fontname);
726 inform(a->c, _("Video font not successfully set."));
735 fn_set_scrnmap(struct i_fn_args *a)
737 struct commands *cmds;
739 char filename[256], scrnmapname[256];
741 s = fn_select_file(_("Select Screen Map"),
742 _("Select a mapping for translating characters as they appear "
743 "on your video console screen."),
744 "", _("Return to Utilities Menu"), "/usr/share/syscons/scrnmaps",
747 if (strcmp(s, "cancel") != 0) {
748 cmds = commands_new();
749 command_add(cmds, "%s%s -l "
750 "/usr/share/syscons/scrnmaps/%s < /dev/ttyv0",
751 a->os_root, cmd_name(a, "VIDCONTROL"),
753 if (commands_execute(a, cmds)) {
754 snprintf(filename, 256, "/usr/share/syscons/scrnmaps/%s", s);
755 snprintf(scrnmapname, 256, filename_noext(basename(filename)));
756 config_var_set(rc_conf, "scrnmap", scrnmapname);
758 inform(a->c, _("Video font not successfully set."));
766 fn_set_timezone(struct i_fn_args *a)
768 struct commands *cmds;
770 char current_path[256], selection[256], temp[256];
774 result = dfui_be_present_dialog(a->c, _("Local or UTC (Greenwich Mean Time) clock"),
776 _("Is this machine's CMOS clock set to UTC?\n\n"
777 "If it is set to local time, or you don't know, please choose NO here!"));
781 cmds = commands_new();
784 command_add(cmds, "%s%s -f %s%setc/wall_cmos_clock",
785 a->os_root, cmd_name(a, "RM"),
786 a->os_root, a->cfg_root);
789 command_add(cmds, "%s%s %s%setc/wall_cmos_clock",
790 a->os_root, cmd_name(a, "TOUCH"),
791 a->os_root, a->cfg_root);
794 commands_execute(a, cmds);
796 snprintf(current_path, 256, "%s%susr/share/zoneinfo",
797 a->os_root, a->cfg_root);
798 while (!found_file) {
801 s = fn_select_file(_("Select Time Zone"),
802 _("Select a Time Zone appropriate to your physical location."),
803 "", _("Return to Utilities Menu"), current_path,
805 if (is_dir("%s/%s", current_path, s)) {
806 snprintf(temp, 256, "%s/%s", current_path, s);
807 strlcpy(current_path, temp, 256);
809 if (is_file("%s/%s", current_path, s)) {
810 snprintf(selection, 256, "%s/%s", current_path, s);
813 if (strcmp(s, "cancel") == 0) {
814 strlcpy(selection, "cancel", 256);
821 if (strcmp(selection, "cancel") != 0) {
822 command_add(cmds, "%s%s %s %s%setc/localtime",
823 a->os_root, cmd_name(a, "CP"),
825 a->os_root, a->cfg_root);
826 if (commands_execute(a, cmds))
827 inform(a->c, _("The Time Zone has been set to %s."), selection);
833 fn_assign_datetime(struct i_fn_args *a)
835 struct commands *cmds;
836 struct dfui_dataset *ds, *new_ds;
838 struct dfui_response *r;
841 int year, month, dayofmonth, hour, minutes;
846 tp = localtime(&now);
848 f = dfui_form_create(
851 _("Enter the date-time in your timezone."),
854 "f", "year", _("Enter year"),
855 _("Enter the current year (e.g. `2004')"), "",
856 "f", "month", _("Month"),
857 _("Enter the current month (e.g. `07')"), "",
858 "f", "dayofmonth", "dayofmonth",
859 _("Enter the current day of month (e.g. `30')"), "",
861 _("Enter the current hour (e.g. `07')"), "",
862 "f", "minutes", "minutes",
863 _("Enter the current minutes (e.g. `59')"), "",
865 "a", "ok", _("OK"), "", "",
866 "a", "cancel", _("Cancel"), "", "",
867 "p", "accelerator", "ESC",
872 ds = dfui_dataset_new();
873 snprintf(temp, 256, "%i", (tp->tm_year+1900));
874 dfui_dataset_celldata_add(ds, "year", temp);
875 snprintf(temp, 256, "%i", (tp->tm_mon+1));
876 dfui_dataset_celldata_add(ds, "month", temp);
877 snprintf(temp, 256, "%i", tp->tm_mday);
878 dfui_dataset_celldata_add(ds, "dayofmonth", temp);
879 snprintf(temp, 256, "%i", tp->tm_hour);
880 dfui_dataset_celldata_add(ds, "hour", temp);
881 snprintf(temp, 256, "%i", tp->tm_min);
882 dfui_dataset_celldata_add(ds, "minutes", temp);
883 dfui_form_dataset_add(f, ds);
885 if (!dfui_be_present(a->c, f, &r))
888 if (strcmp(dfui_response_get_action_id(r), "ok") == 0) {
889 new_ds = dfui_response_dataset_get_first(r);
891 if ((year = atoi(dfui_dataset_get_value(new_ds, "year"))) <= 0)
893 month = atoi(dfui_dataset_get_value(new_ds, "month"));
894 if (month < 1 || month > 12)
896 dayofmonth = atoi(dfui_dataset_get_value(new_ds, "dayofmonth"));
897 if (dayofmonth < 1 || dayofmonth > 31)
899 hour = atoi(dfui_dataset_get_value(new_ds, "hour"));
900 if (hour < 0 || hour > 23)
902 minutes = atoi(dfui_dataset_get_value(new_ds, "minutes"));
903 if (minutes < 0 || minutes > 59)
907 cmds = commands_new();
908 command_add(cmds, "%s%s -n %04d%02d%02d%02d%02d",
909 a->os_root, cmd_name(a, "DATE"),
910 year, month, dayofmonth, hour, minutes);
911 if (commands_execute(a, cmds)) {
912 inform(a->c, _("The date and time have been set."));
916 inform(a->c, _("Please enter numbers within acceptable ranges "
917 "for year, month, day of month, hour, and minute."));
923 fn_assign_hostname_domain(struct i_fn_args *a)
926 struct dfui_response *r;
927 struct dfui_dataset *ds, *new_ds;
928 struct config_vars *resolv_conf;
929 const char *domain, *hostname;
932 f = dfui_form_create(
933 "set_hostname_domain",
934 _("Set Hostname/Domain"),
935 _("Please enter this machine's hostname and domain name."),
938 "f", "hostname", _("Hostname"),
939 _("Enter the Hostname (e.g. `machine')"), "",
940 "f", "domain", _("Domain"),
941 _("Enter the Domain Name (e.g. `network.lan')"), "",
943 "a", "ok", _("OK"), "", "",
944 "a", "cancel", _("Cancel"), "", "",
945 "p", "accelerator", "ESC",
950 ds = dfui_dataset_new();
951 dfui_dataset_celldata_add(ds, "hostname", "");
952 dfui_dataset_celldata_add(ds, "domain", "");
953 dfui_form_dataset_add(f, ds);
955 if (!dfui_be_present(a->c, f, &r))
958 if (strcmp(dfui_response_get_action_id(r), "ok") == 0) {
959 new_ds = dfui_response_dataset_get_first(r);
961 hostname = dfui_dataset_get_value(new_ds, "hostname");
962 domain = dfui_dataset_get_value(new_ds, "domain");
963 if (strlen(domain) == 0)
964 asprintf(&fqdn, "%s", hostname);
966 asprintf(&fqdn, "%s.%s", hostname, domain);
968 resolv_conf = config_vars_new();
970 config_var_set(rc_conf, "hostname", fqdn);
971 config_var_set(resolv_conf, "search", domain);
972 config_vars_write(resolv_conf, CONFIG_TYPE_RESOLV,
973 "%s%setc/resolv.conf", a->os_root, a->cfg_root);
975 config_vars_free(resolv_conf);
981 dfui_response_free(r);
985 fn_assign_ip(struct i_fn_args *a)
988 struct commands *cmds;
990 struct config_vars *resolv_conf;
991 struct dfui_dataset *ds, *new_ds;
993 struct dfui_action *k;
994 struct dfui_response *r;
995 const char *domain, *hostname;
996 const char *interface_ip, *interface_netmask, *defaultrouter, *dns_resolver;
997 char *string, *string1;
1001 int write_config = 0;
1004 * Get interface list.
1006 p = popen("/sbin/ifconfig -l", "r");
1007 /* XXX it's possible (though extremely unlikely) this will fail. */
1008 while (fgets(line, 255, p) != NULL)
1009 line[strlen(line) - 1] = '\0';
1013 f = dfui_form_create(
1015 _("Assign IP Address"),
1016 _("Please select which interface you would like to configure:"),
1018 "p", "role", "menu",
1022 /* Loop through array. */
1023 word = strtok(line, " \t");
1024 while (word != NULL) {
1025 dfui_form_action_add(f, word,
1026 dfui_info_new(word, "", ""));
1027 word = strtok(NULL, " ");
1030 k = dfui_form_action_add(f, "cancel",
1031 dfui_info_new("Cancel", "", ""));
1032 dfui_action_property_set(k, "accelerator", "ESC");
1034 if (!dfui_be_present(a->c, f, &r))
1037 if (strcmp(dfui_response_get_action_id(r), "cancel") == 0) {
1039 dfui_response_free(r);
1043 strlcpy(interface, dfui_response_get_action_id(r), 256);
1045 resolv_conf = config_vars_new();
1047 switch (dfui_be_present_dialog(a->c, _("Use DHCP?"),
1048 _("Use DHCP|Configure Manually"),
1049 _("DHCP allows the interface to automatically obtain "
1050 "an IP address from a nearby DHCP server.\n\n"
1051 "Would you like to enable DHCP for %s?"), interface)) {
1053 asprintf(&string, "ifconfig_%s", interface);
1055 cmds = commands_new();
1056 cmd = command_add(cmds, "%s%s dhclient",
1057 a->os_root, cmd_name(a, "KILLALL"));
1058 command_set_failure_mode(cmd, COMMAND_FAILURE_IGNORE);
1059 command_add(cmds, "%s%s %s",
1060 a->os_root, cmd_name(a, "DHCLIENT"),
1062 if (commands_execute(a, cmds)) {
1064 show_ifconfig(a->c, interface);
1067 switch (dfui_be_present_dialog(a->c, _("DHCP Failure"),
1069 _("Warning: could not enable dhclient for %s.\n\n"
1070 "Write the corresponding settings to rc.conf "
1071 "anyway?"), interface)) {
1082 commands_free(cmds);
1083 config_var_set(rc_conf, string, "DHCP");
1088 dfui_response_free(r);
1089 f = dfui_form_create(
1091 _("Assign IP Address"),
1092 _("Configuring Interface:"),
1095 "f", "interface_ip", _("IP Address"),
1096 _("Enter the IP Address you would like to use"), "",
1097 "f", "interface_netmask", _("Netmask"),
1098 _("Enter the netmask of the IP address"), "",
1099 "f", "defaultrouter", _("Default Router"),
1100 _("Enter the IP address of the default router"), "",
1101 "f", "dns_resolver", _("Primary DNS Server"),
1102 _("Enter the IP address of primary DNS Server"), "",
1103 "f", "hostname", _("Hostname"),
1104 _("Enter the Hostname"), "",
1105 "f", "domain", _("Domain"),
1106 _("Enter the Domain Name"), "",
1108 "a", "ok", _("Configure Interface"),
1110 "a", "cancel", _("Return to Utilities Menu"),
1112 "p", "accelerator", "ESC",
1117 ds = dfui_dataset_new();
1118 dfui_dataset_celldata_add(ds, "interface_netmask", "");
1119 dfui_dataset_celldata_add(ds, "defaultrouter", "");
1120 dfui_dataset_celldata_add(ds, "dns_resolver", "");
1121 dfui_dataset_celldata_add(ds, "hostname", "");
1122 dfui_dataset_celldata_add(ds, "domain", "");
1123 dfui_dataset_celldata_add(ds, "interface_ip", "");
1124 dfui_form_dataset_add(f, ds);
1126 if (!dfui_be_present(a->c, f, &r))
1129 if (strcmp(dfui_response_get_action_id(r), "ok") == 0) {
1130 new_ds = dfui_response_dataset_get_first(r);
1132 interface_ip = dfui_dataset_get_value(new_ds, "interface_ip");
1133 interface_netmask = dfui_dataset_get_value(new_ds, "interface_netmask");
1134 defaultrouter = dfui_dataset_get_value(new_ds, "defaultrouter");
1135 dns_resolver = dfui_dataset_get_value(new_ds, "dns_resolver");
1136 hostname = dfui_dataset_get_value(new_ds, "hostname");
1137 domain = dfui_dataset_get_value(new_ds, "domain");
1139 asprintf(&string, "ifconfig_%s", interface);
1140 asprintf(&string1, "inet %s netmask %s",
1141 interface_ip, interface_netmask);
1143 cmds = commands_new();
1144 command_add(cmds, "%s%s %s %s netmask %s",
1145 a->os_root, cmd_name(a, "IFCONFIG"),
1146 interface, interface_ip, interface_netmask);
1147 command_add(cmds, "%s%s add default %s",
1148 a->os_root, cmd_name(a, "ROUTE"),
1151 if (commands_execute(a, cmds)) {
1153 show_ifconfig(a->c, interface);
1156 switch (dfui_be_present_dialog(a->c,
1157 _("ifconfig Failure"),
1159 _("Warning: could not assign IP address "
1160 "or default gateway.\n\n"
1161 "Write the corresponding settings to "
1162 "rc.conf anyway?"))) {
1173 commands_free(cmds);
1175 config_var_set(rc_conf, string, string1);
1176 config_var_set(rc_conf, "defaultrouter", defaultrouter);
1181 asprintf(&string, "%s.%s", hostname, domain);
1182 config_var_set(rc_conf, "hostname", string);
1185 config_var_set(resolv_conf, "search", domain);
1186 config_var_set(resolv_conf, "nameserver", dns_resolver);
1195 * Save out changes to /etc/rc.conf and /etc/resolv.conf.
1197 config_vars_write(resolv_conf, CONFIG_TYPE_RESOLV,
1198 "%s%setc/resolv.conf", a->os_root, a->cfg_root);
1201 config_vars_free(resolv_conf);
1204 dfui_response_free(r);
1208 yes_to_y(const char *value)
1210 return(strcasecmp(value, "YES") == 0 ? "Y" : "N");
1214 fn_select_services(struct i_fn_args *a)
1216 struct dfui_dataset *ds;
1217 struct dfui_form *f;
1218 struct dfui_response *r;
1220 if (!config_vars_read(a, rc_conf, CONFIG_TYPE_SH, "%s%setc/rc.conf",
1221 a->os_root, a->cfg_root)) {
1222 inform(a->c, _("Couldn't read %s%setc/rc.conf."),
1223 a->os_root, a->cfg_root);
1228 f = dfui_form_create(
1230 _("Select Services"),
1231 _("Please select which services you would like started at boot time."),
1234 "f", "syslogd", "syslogd",
1235 _("System Logging Daemon"), "",
1236 "p", "control", "checkbox",
1237 "f", "inetd", "inetd",
1238 _("Internet Super-Server"), "",
1239 "p", "control", "checkbox",
1240 "f", "named", "named",
1241 _("BIND Name Server"), "",
1242 "p", "control", "checkbox",
1243 "f", "ntpd", "ntpd",
1244 _("Network Time Protocol Daemon"), "",
1245 "p", "control", "checkbox",
1246 "f", "sshd", "sshd",
1247 _("Secure Shell Daemon"), "",
1248 "p", "control", "checkbox",
1250 "a", "ok", _("Enable/Disable Services"),
1252 "a", "cancel", _("Return to Utilities Menu"),
1254 "p", "accelerator", "ESC",
1259 ds = dfui_dataset_new();
1260 dfui_dataset_celldata_add(ds, "syslogd",
1261 yes_to_y(config_var_get(rc_conf, "syslogd_enable")));
1262 dfui_dataset_celldata_add(ds, "inetd",
1263 yes_to_y(config_var_get(rc_conf, "inetd_enable")));
1264 dfui_dataset_celldata_add(ds, "named",
1265 yes_to_y(config_var_get(rc_conf, "named_enable")));
1266 dfui_dataset_celldata_add(ds, "ntpd",
1267 yes_to_y(config_var_get(rc_conf, "ntpd_enable")));
1268 dfui_dataset_celldata_add(ds, "sshd",
1269 yes_to_y(config_var_get(rc_conf, "sshd_enable")));
1270 dfui_form_dataset_add(f, ds);
1272 if (!dfui_be_present(a->c, f, &r))
1275 if (strcmp(dfui_response_get_action_id(r), "cancel") == 0) {
1277 dfui_response_free(r);
1282 dfui_response_free(r);
1285 /*** NON-fn_ FUNCTIONS ***/
1288 * Caller is responsible for deallocation.
1291 convert_tmpfs_options(char *line)
1293 char *result, *word;
1296 result = malloc(256);
1299 for (; (word = strsep(&line, ",")) != NULL; ) {
1300 if (word[0] == '-') {
1302 * Don't bother trying to honour the -C
1303 * option, since we can't copy files from
1304 * the right place anyway.
1306 if (strcmp(word, "-C") != 0) {
1307 for (i = 0; word[i] != '\0'; i++) {
1311 strlcat(result, word, 256);
1312 strlcat(result, " ", 256);
1321 * Uses ss->selected_{disk,slice} as the target system.
1324 mount_target_system(struct i_fn_args *a)
1326 FILE *crypttab, *fstab;
1327 struct commands *cmds;
1328 struct command *cmd;
1329 struct subpartition *a_subpart;
1330 char name[256], device[256], mtpt[256], fstype[256], options[256];
1331 char *filename, line[256];
1332 const char *try_mtpt[5] = {"/var", "/tmp", "/usr", "/home", NULL};
1333 char *word, *cvtoptions;
1337 * Mount subpartitions from this installation if they are
1338 * not already mounted. Tricky, as we need to honour the
1339 * installation's loader.conf and fstab.
1341 cmds = commands_new();
1344 * First, unmount anything already mounted on /mnt.
1346 unmount_all_under(a, cmds, "%smnt", a->os_root);
1349 * Reset and clear out subpartitions so that system
1350 * can make a "dummy" subpart.
1352 subpartitions_free(storage_get_selected_slice(a->s));
1355 * Create a temporary dummy subpartition - that we
1359 a_subpart = subpartition_new_ufs(storage_get_selected_slice(a->s),
1360 "/dummy", 0, 0, 0, 0, 0, 0);
1363 * Mount the target's / and read its /etc/fstab.
1365 if (use_hammer == 0) {
1366 command_add(cmds, "%s%s %sdev/%s %s%s",
1367 a->os_root, cmd_name(a, "MOUNT"),
1369 subpartition_get_device_name(a_subpart),
1370 a->os_root, a->cfg_root);
1371 cmd = command_add(cmds,
1373 "%s%s \"^[^#]\" %s%s/etc/crypttab >%st2",
1374 a->os_root, cmd_name(a, "RM"), a->tmp,
1375 a->os_root, cmd_name(a, "GREP"),
1376 a->os_root, a->cfg_root, a->tmp);
1377 command_set_failure_mode(cmd, COMMAND_FAILURE_IGNORE);
1379 command_add(cmds, "%s%s %sdev/%s %sboot",
1380 a->os_root, cmd_name(a, "MOUNT"),
1382 subpartition_get_device_name(a_subpart),
1384 cmd = command_add(cmds,
1386 "%s%s \"^vfs\\.root\\.realroot=\" %sboot/loader.conf >%st2",
1387 a->os_root, cmd_name(a, "RM"), a->tmp,
1388 a->os_root, cmd_name(a, "GREP"),
1389 a->os_root, a->tmp);
1390 command_set_failure_mode(cmd, COMMAND_FAILURE_IGNORE);
1392 if (!commands_execute(a, cmds)) {
1393 commands_free(cmds);
1396 commands_free(cmds);
1397 cmds = commands_new();
1400 struct stat sb = { .st_size = 0 };
1401 stat("/tmp/t2", &sb);
1402 if (sb.st_size > 0) {
1403 command_add(cmds, "%s%s %sboot",
1404 a->os_root, cmd_name(a, "UMOUNT"),
1406 fn_get_passphrase(a);
1408 "%s%s -d /tmp/t1 luksOpen %sdev/`%s%s \"^vfs\\.root\\.realroot=\" %st2 |"
1409 "%s%s -Fhammer: '{print $2;}' |"
1410 "%s%s -F: '{print $1;}'` root",
1411 a->os_root, cmd_name(a, "CRYPTSETUP"),
1413 a->os_root, cmd_name(a, "GREP"),
1415 a->os_root, cmd_name(a, "AWK"),
1416 a->os_root, cmd_name(a, "AWK"));
1418 "%s%s %sdev/mapper/root %s%s",
1419 a->os_root, cmd_name(a, "MOUNT_HAMMER"),
1421 a->os_root, a->cfg_root);
1424 "%s%s %sdev/`%s%s \"^vfs\\.root\\.mountfrom\" %sboot/loader.conf |"
1425 "%s%s -Fhammer: '{print $2;}' |"
1426 "%s%s 's/\"//'` %s%s",
1427 a->os_root, cmd_name(a, "MOUNT_HAMMER"),
1429 a->os_root, cmd_name(a, "GREP"),
1431 a->os_root, cmd_name(a, "AWK"),
1432 a->os_root, cmd_name(a, "SED"),
1433 a->os_root, a->cfg_root);
1434 command_add(cmds, "%s%s %sboot",
1435 a->os_root, cmd_name(a, "UMOUNT"),
1439 if (!commands_execute(a, cmds)) {
1440 commands_free(cmds);
1443 commands_free(cmds);
1444 cmds = commands_new();
1447 * Get rid of the dummy subpartition.
1449 subpartitions_free(storage_get_selected_slice(a->s));
1452 * See if an /etc/crypttab exists.
1454 asprintf(&filename, "%s%s/etc/crypttab", a->os_root, a->cfg_root);
1455 crypttab = fopen(filename, "r");
1457 if (crypttab != NULL) {
1459 fn_get_passphrase(a);
1460 while (fgets(line, 256, crypttab) != NULL) {
1462 * Parse the crypttab line.
1464 if (first_non_space_char_is(line, '#'))
1466 if ((word = strtok(line, " \t")) == NULL)
1468 strlcpy(name, word, 256);
1469 if (strcmp(name, "swap") == 0)
1471 if ((word = strtok(NULL, " \t")) == NULL)
1473 strlcpy(device, word, 256);
1476 "%s%s -d /tmp/t1 luksOpen %s %s",
1477 a->os_root, cmd_name(a, "CRYPTSETUP"),
1484 if (!commands_execute(a, cmds)) {
1485 commands_free(cmds);
1488 commands_free(cmds);
1490 asprintf(&filename, "%s%s/etc/fstab", a->os_root, a->cfg_root);
1491 fstab = fopen(filename, "r");
1493 if (fstab == NULL) {
1494 inform(a->c, _("Filesystem table on installed system could not be read."));
1495 cmds = commands_new();
1496 command_add(cmds, "%s%s %s%s",
1497 a->os_root, cmd_name(a, "UMOUNT"),
1498 a->os_root, a->cfg_root);
1499 if (!commands_execute(a, cmds)) {
1500 inform(a->c, _("Warning: Installed system was not properly unmounted."));
1502 commands_free(cmds);
1506 cmds = commands_new();
1508 while (fgets(line, 256, fstab) != NULL) {
1510 * Parse the fstab line.
1512 if (first_non_space_char_is(line, '#'))
1514 if ((word = strtok(line, " \t")) == NULL)
1516 strlcpy(device, word, 256);
1517 if ((word = strtok(NULL, " \t")) == NULL)
1519 strlcpy(mtpt, word, 256);
1520 if ((word = strtok(NULL, " \t")) == NULL)
1522 strlcpy(fstype, word, 256);
1523 if ((word = strtok(NULL, " \t")) == NULL)
1525 strlcpy(options, word, 256);
1528 * Now, if the mountpoint has /usr, /var, /tmp, or /home
1529 * as a prefix, mount it under a->cfg_root.
1531 for (i = 0; try_mtpt[i] != NULL; i++) {
1532 if (strstr(mtpt, try_mtpt[i]) == mtpt) {
1534 * Don't mount it if it's optional.
1536 if (strstr(options, "noauto") != NULL)
1540 * Don't mount it if device doesn't start
1541 * with /dev/ or /pfs and it isn't 'tmpfs'.
1543 if (strstr(device, "/dev/") != NULL &&
1544 strstr(device, "/pfs/") != NULL &&
1545 strcmp(device, "tmpfs") != 0)
1549 * If the device is 'tmpfs', mount_tmpfs it instead.
1551 if (strcmp(device, "tmpfs") == 0) {
1552 cvtoptions = convert_tmpfs_options(options);
1554 "%s%s %s tmpfs %s%s%s",
1555 a->os_root, cmd_name(a, "MOUNT_TMPFS"),
1556 cvtoptions, a->os_root, a->cfg_root, mtpt);
1559 if (use_hammer == 0) {
1561 "%s%s -o %s %s%s %s%s%s",
1562 a->os_root, cmd_name(a, "MOUNT"),
1564 a->os_root, device, a->os_root,
1568 "%s%s -o %s %s%s%s %s%s%s",
1569 a->os_root, cmd_name(a, "MOUNT_NULL"),
1571 a->os_root, a->cfg_root, device,
1572 a->os_root, a->cfg_root, mtpt);
1580 if (!commands_execute(a, cmds)) {
1581 commands_free(cmds);
1584 commands_free(cmds);