[PC-BSD Commits] r7038 - pcbsd-projects/txt-sysinstall
svn at pcbsd.org
svn at pcbsd.org
Sat Jun 26 18:38:59 PDT 2010
Author: johnh
Date: 2010-06-26 18:38:59 -0700 (Sat, 26 Jun 2010)
New Revision: 7038
Modified:
pcbsd-projects/txt-sysinstall/Makefile
pcbsd-projects/txt-sysinstall/TODO
pcbsd-projects/txt-sysinstall/components.c
pcbsd-projects/txt-sysinstall/disksel.c
pcbsd-projects/txt-sysinstall/install.c
pcbsd-projects/txt-sysinstall/label.c
pcbsd-projects/txt-sysinstall/mainmenu.c
pcbsd-projects/txt-sysinstall/medium.c
pcbsd-projects/txt-sysinstall/netif.c
pcbsd-projects/txt-sysinstall/partsel.c
pcbsd-projects/txt-sysinstall/rootpass.c
pcbsd-projects/txt-sysinstall/txt-sysinstall.h
pcbsd-projects/txt-sysinstall/tzone.c
pcbsd-projects/txt-sysinstall/useradd.c
pcbsd-projects/txt-sysinstall/util.c
Log:
Various updates from the TODO file. Still needs work!
Modified: pcbsd-projects/txt-sysinstall/Makefile
===================================================================
--- pcbsd-projects/txt-sysinstall/Makefile 2010-06-26 09:02:18 UTC (rev 7037)
+++ pcbsd-projects/txt-sysinstall/Makefile 2010-06-27 01:38:59 UTC (rev 7038)
@@ -4,7 +4,7 @@
SRCS= main.c mainmenu.c disksel.c partsel.c useradd.c netif.c rootpass.c
SRCS+= tzone.c components.c util.c install.c medium.c label.c
-CFLAGS+= -ggdb -DDEBUG
+CFLAGS+= -ggdb -DDEBUG -D__PCBSD__
WARNS= 3
Modified: pcbsd-projects/txt-sysinstall/TODO
===================================================================
--- pcbsd-projects/txt-sysinstall/TODO 2010-06-26 09:02:18 UTC (rev 7037)
+++ pcbsd-projects/txt-sysinstall/TODO 2010-06-27 01:38:59 UTC (rev 7038)
@@ -1,3 +1,15 @@
-- implement bsd label setup correct
-- fix next / back menu handling
-- fix component selection
+* test install dvd
+* test install pc-bsd
+* support other packageTypes
+* add support for selecting components
+* add support for labeling the disk
+* support upgrade mode
+* when installing via FTP, add a list of mirrors and let the user select one
+* add a inputbox to let the user type an URL when installing via FTP
+* replace all the remaining menu setup with the DMENU() macro
+* probably make the DMENU() macro accessible via txt-sysinstall.h
+* use or develop a library to support i18n
+* expand libdialog to support password entries (entries with star characters instead of the real characters)
+* test the code with ndialog and think about using ndialog instead (we can import ndialog into freebsd)
+* play with style.rc ;-)
+* fix next / back menu handling
Modified: pcbsd-projects/txt-sysinstall/components.c
===================================================================
--- pcbsd-projects/txt-sysinstall/components.c 2010-06-26 09:02:18 UTC (rev 7037)
+++ pcbsd-projects/txt-sysinstall/components.c 2010-06-27 01:38:59 UTC (rev 7038)
@@ -33,9 +33,14 @@
#include "txt-sysinstall.h"
-#define MAXCOMP 10
+#define MAXCOMP 50
#define MODULE "Components selection"
+struct component {
+ char *name;
+ int selected;
+};
+
static int
type_fire(dialogMenuItem *self)
{
@@ -48,31 +53,54 @@
return (0);
}
-static void
-component_selected(dialogMenuItem *self, int a)
+static int
+component_checked(dialogMenuItem *self)
{
+ struct component *c = self->data;
+ if (c->selected)
+ return (TRUE);
+
+ return (FALSE);
}
+static int
+component_fire(dialogMenuItem *self)
+{
+ if (self->data) {
+ struct component *c = self->data;
+ c->selected = !c->selected;
+ return (DITEM_SUCCESS);
+ }
+
+ return (DITEM_FAILURE);
+}
+
void
dialog_components(void)
{
char *token;
char *buf;
+ char *ptr;
+ char compstr[2048];
dialogMenuItem *menus;
+ struct component *components;
+ int status;
int i;
- buf = run_pcsysinstall("list-components", NULL);
- menus = malloc(sizeof(*menus)*MAXCOMP);
- memset(menus, 0, sizeof(*menus)*MAXCOMP);
- menus[0].prompt = " Next ";
- menus[1].prompt = " Back ";
- menus[2].prompt = "PC-BSD";
- menus[2].title = "";
- menus[2].fire = type_fire;
- menus[3].prompt = "FreeBSD";
- menus[3].title = "";
- menus[3].fire = type_fire;
+ buf = safe_malloc(BUFSZ+1);
+ status = run_pcsysinstall(buf, BUFSZ, "list-components", NULL);
+ menus = safe_malloc(sizeof(*menus)*MAXCOMP);
+
+ bzero(compstr, sizeof(compstr));
+ components = safe_malloc(sizeof(*components)*MAXCOMP);
+
+ i = 0;
+ DMENUF(&menus[i++], "Next", NULL, NULL);
+ DMENUF(&menus[i++], "Back", NULL, NULL);
+ DMENUF(&menus[i++], "PC-BSD", "", type_fire);
+ DMENUF(&menus[i++], "FreeBSD", "", type_fire);
+
screen_clear(MODULE);
dialog_menu(MODULE, "Please select the system to install:",
9, 40, 2, -2, menus+2, "", NULL, NULL);
@@ -82,21 +110,48 @@
i < MAXCOMP) {
char *key, *value;
+
key = strsep(&token, ":");
value = strsep(&token, ":");
value++;
- if (!strcmp(key, "name"))
+
+ if (!strcmp(key, "name")) {
menus[i].prompt = value;
+ components[i].name = value;
+ }
+
if (!strcmp(key, "desc")) {
menus[i].title = value;
- menus[i].selected = component_selected;
+ menus[i].fire = component_fire;
+ menus[i].checked = component_checked;
+ menus[i].data = &components[i];
i++;
}
}
- screen_clear(MODULE);
- dialog_checklist(MODULE,
- "Please select the components you want to install:",
- 17, 60, 10, -i+2, menus+2, "");
+
+ if (i > 2) {
+ screen_clear(MODULE);
+ dialog_checklist(MODULE,
+ "Please select the components you want to install:",
+ 17, 60, 10, -i+2, menus+2, "");
+
+ ptr = &compstr[0];
+ for (i = 0;i < MAXCOMP;i++) {
+ if (components[i].selected) {
+ if (compstr[0] == 0) {
+ ptr = strcat(ptr, components[i].name);
+
+ } else {
+ ptr = strcat(ptr, ",");
+ ptr = strcat(ptr, components[i].name);
+ }
+ }
+ }
+
+ if (ptr[0] != 0)
+ appendconfig("installComponents", compstr);
+ }
+
free(buf);
free(menus);
Modified: pcbsd-projects/txt-sysinstall/disksel.c
===================================================================
--- pcbsd-projects/txt-sysinstall/disksel.c 2010-06-26 09:02:18 UTC (rev 7037)
+++ pcbsd-projects/txt-sysinstall/disksel.c 2010-06-27 01:38:59 UTC (rev 7038)
@@ -39,7 +39,6 @@
static int
disk_fire(dialogMenuItem *self)
{
-
appendconfig("disk0", self->prompt);
dialog_partsel(self->prompt, self->title);
@@ -52,14 +51,17 @@
char *buf;
char *token;
dialogMenuItem *menus;
+ int status;
int i;
- buf = run_pcsysinstall("disk-list", NULL);
- menus = malloc(sizeof(*menus)*MAXDISKS+3);
- memset(menus, 0, sizeof(*menus)*MAXDISKS+3);
+ buf = safe_malloc(BUFSZ+1);
+ status = run_pcsysinstall(buf, BUFSZ, "disk-list", NULL);
+ menus = safe_malloc(sizeof(*menus)*MAXDISKS+3);
- menus[0].prompt = " Next ";
- menus[1].prompt = " Back ";
+ i = 0;
+ DMENUF(&menus[i++], "Next", NULL, NULL);
+ DMENUF(&menus[i++], "Back", NULL, NULL);
+
i = 2;
while ((token = strsep(&buf, "\n")) != NULL && strlen(token) > 0 &&
i < MAXDISKS+2) {
@@ -74,17 +76,20 @@
menus[i].fire = disk_fire;
i++;
}
+
#ifdef DEBUG
menus[i].prompt = "md0";
menus[i].title = "";
menus[i].fire = disk_fire;
i++;
#endif
+
screen_clear(MODULE);
- dialog_menu("Destination disk",
+ dialog_menu(MODULE,
"Please select the disk on which you want to install "
"or upgrade\nPC-BSD or FreeBSD:",
7+i-2, 70, i-2, -i+2, menus+2, "", NULL, NULL);
+
free(menus);
free(buf);
}
Modified: pcbsd-projects/txt-sysinstall/install.c
===================================================================
--- pcbsd-projects/txt-sysinstall/install.c 2010-06-26 09:02:18 UTC (rev 7037)
+++ pcbsd-projects/txt-sysinstall/install.c 2010-06-27 01:38:59 UTC (rev 7038)
@@ -113,6 +113,7 @@
if (dialog_yesno(MODULE, "Do you want to start the installation?",
5, 60))
return;
+
dialog_busy(5, 60, "Initializing installation...");
if (pipe(fd) < 0) {
Modified: pcbsd-projects/txt-sysinstall/label.c
===================================================================
--- pcbsd-projects/txt-sysinstall/label.c 2010-06-26 09:02:18 UTC (rev 7037)
+++ pcbsd-projects/txt-sysinstall/label.c 2010-06-27 01:38:59 UTC (rev 7038)
@@ -42,9 +42,11 @@
int i;
char *buf;
int swap;
+ int status;
dialogMenuItem *menus;
- buf = run_pcsysinstall("sys-mem", NULL);
+ buf = safe_malloc(BUFSZ+1);
+ status = run_pcsysinstall(buf, BUFSZ, "sys-mem", NULL);
swap = atoi(buf) * 2;
free(buf);
@@ -65,25 +67,18 @@
dialog_useradd();
return;
}
- menus = malloc(sizeof(*menus)*MAXLABELS+2);
- memset(menus, 0, sizeof(*menus)*MAXLABELS+2);
+
+ menus = safe_malloc(sizeof(*menus)*MAXLABELS+2);
+
i = 0;
-#define DMENU(p, t, f) do { \
- menus[i].prompt = p; \
- menus[i].title = t; \
- menus[i].fire = f; \
- i++; \
-} while(0)
-
- DMENU(" Next ", NULL, NULL);
- DMENU(" Back ", NULL, NULL);
- DMENU("-", "", NULL);
- DMENU("/ \t1GB", "UFS+S", NULL);
- DMENU("SWAP\t2GB", "SWAP", NULL);
- DMENU("/usr\t4GB", "UFS+S", NULL);
- DMENU("-", "", NULL);
- DMENU("Add a new BSD partition", "", NULL);
-#undef DMENU
+ DMENUF(&menus[i++], "Next", NULL, NULL);
+ DMENUF(&menus[i++], "Back", NULL, NULL);
+ DMENUF(&menus[i++], "-", "", NULL);
+ DMENUF(&menus[i++], "/ \t1GB", "UFS+S", NULL);
+ DMENUF(&menus[i++], "SWAP\t2GB", "SWAP", NULL);
+ DMENUF(&menus[i++], "/usr\t4GB", "UFS+S", NULL);
+ DMENUF(&menus[i++], "-", "", NULL);
+ DMENUF(&menus[i++], "Add a new BSD partition", "", NULL);
screen_clear(MODULE);
dialog_menu(MODULE, "BSD partitions:", 19, 70, 12, -i+2,
Modified: pcbsd-projects/txt-sysinstall/mainmenu.c
===================================================================
--- pcbsd-projects/txt-sysinstall/mainmenu.c 2010-06-26 09:02:18 UTC (rev 7037)
+++ pcbsd-projects/txt-sysinstall/mainmenu.c 2010-06-27 01:38:59 UTC (rev 7038)
@@ -36,11 +36,24 @@
#include "txt-sysinstall.h"
#define MODULE "Main Menu"
+#define MAXLABELS 8
static int
-install_fire(dialogMenuItem *self)
+next_fire(dialogMenuItem *self)
{
+ dialog_disksel();
+ return (0);
+}
+static int
+exit_fire(dialogMenuItem *self)
+{
+ exit(0);
+}
+
+static int
+install_fire(dialogMenuItem *self)
+{
appendconfig("installMode", "fresh");
dialog_disksel();
@@ -84,35 +97,20 @@
void
sysinstall(void)
{
- dialogMenuItem menus[] = {
- {
- .prompt = " Next "
- },
- {
- .prompt = " Exit ",
- },
- {
- .prompt = "Install",
- .title = "Install PC-BSD or FreeBSD",
- .fire = install_fire
- },
- {
- .prompt = "Upgrade",
- .title = "Upgrade PC-BSD or FreeBSD",
- .fire = upgrade_fire
- },
- {
- .prompt = "Configure Network",
- .title = "Setup network interfaces",
- .fire = netif_fire
- },
- {
- .prompt = "Shell",
- .title = "Run tcsh",
- .fire = shell_fire
- }
- };
+ int i;
+ dialogMenuItem *menus;
+ dialog_clear();
+ end_dialog();
+ i = 0;
+ menus = safe_malloc(sizeof(*menus)*MAXLABELS+2);
+ DMENUF(&menus[i++], "Next", NULL, next_fire);
+ DMENUF(&menus[i++], "Exit", NULL, exit_fire);
+ DMENUF(&menus[i++], "Install", "Install PC-BSD or FreeBSD", install_fire);
+ DMENUF(&menus[i++], "Upgrade", "Upgrade PC-BSD or FreeBSD", upgrade_fire);
+ DMENUF(&menus[i++], "Configure Network", "Setup network interfaces", netif_fire);
+ DMENUF(&menus[i++], "Shell", "Run tcsh", shell_fire);
+
for (;;) {
screen_clear(MODULE);
if (dialog_menu("Welcome to PC-BSD install",
@@ -122,5 +120,6 @@
NULL, NULL))
return;
}
-}
+ free(menus);
+}
Modified: pcbsd-projects/txt-sysinstall/medium.c
===================================================================
--- pcbsd-projects/txt-sysinstall/medium.c 2010-06-26 09:02:18 UTC (rev 7037)
+++ pcbsd-projects/txt-sysinstall/medium.c 2010-06-27 01:38:59 UTC (rev 7038)
@@ -61,25 +61,18 @@
int i;
i = 0;
-#define DMENU(p, t, f, d) do { \
- menus[i].prompt = p; \
- menus[i].title = t; \
- menus[i].fire = f; \
- menus[i].data = d; \
- i++; \
-} while (0)
- memset(menus, 0, sizeof(menus));
- DMENU(" Next ", NULL, NULL, NULL);
- DMENU(" Back ", NULL, NULL, NULL);
- DMENU("DVD", "Search the install archives on a DVD", medium_fire,
- "dvd");
- DMENU("USB", "Search the install archives on a USB drive",
+ bzero(menus, sizeof(menus));
+
+ DMENUF(&menus[i++], "Next", NULL, NULL);
+ DMENUF(&menus[i++], "Back", NULL, NULL);
+ DMENUFD(&menus[i++], "DVD", "Search the install archives on a DVD",
+ medium_fire, "dvd");
+ DMENUFD(&menus[i++], "USB", "Search the install archives on a USB drive",
medium_fire, "usb");
- DMENU("FTP/HTTP", "Fetch and install the archives from a server",
+ DMENUFD(&menus[i++], "FTP/HTTP", "Fetch and install the archives from a server",
medium_fire, "ftp");
- DMENU("rsync", "Pull the system data from a ssh + rsync server",
+ DMENUFD(&menus[i++], "rsync", "Pull the system data from a ssh + rsync server",
medium_fire, "rsync");
-#undef DMENU
screen_clear(MODULE);
dialog_menu(MODULE, "Please select the install medium:",
Modified: pcbsd-projects/txt-sysinstall/netif.c
===================================================================
--- pcbsd-projects/txt-sysinstall/netif.c 2010-06-26 09:02:18 UTC (rev 7037)
+++ pcbsd-projects/txt-sysinstall/netif.c 2010-06-27 01:38:59 UTC (rev 7038)
@@ -86,11 +86,12 @@
char *token;
char *buf;
dialogMenuItem *menus;
+ int status;
int i = 0;
- buf = run_pcsysinstall("detect-nics", NULL);
- menus = malloc(sizeof(*menus)*MAXNETIFS);
- memset(menus, 0, sizeof(*menus)*MAXNETIFS);
+ buf = safe_malloc(BUFSZ+1);
+ status = run_pcsysinstall(buf, BUFSZ, "detect-nics", NULL);
+ menus = safe_malloc(sizeof(*menus)*MAXNETIFS);
while ((token = strsep(&buf, "\n")) != NULL && strlen(token) > 0 &&
i < MAXNETIFS) {
Modified: pcbsd-projects/txt-sysinstall/partsel.c
===================================================================
--- pcbsd-projects/txt-sysinstall/partsel.c 2010-06-26 09:02:18 UTC (rev 7037)
+++ pcbsd-projects/txt-sysinstall/partsel.c 2010-06-27 01:38:59 UTC (rev 7038)
@@ -69,6 +69,7 @@
int i;
char strfreemb[6];
int freemb;
+ int status;
char *format;
char prompt[1024];
int bootloader;
@@ -76,16 +77,17 @@
screen_clear(MODULE);
dialog_busy(5, 60, "Reading partition list...");
- buf = run_pcsysinstall("disk-part", disk);
+ buf = safe_malloc(BUFSZ+1);
+ status = run_pcsysinstall(buf, BUFSZ, "disk-part", disk);
if (!strncmp(buf, "Error", 5)) {
free(buf);
return;
}
- menus = malloc(sizeof(*menus)*MAXPARTS+4);
- memset(menus, 0, sizeof(*menus)*MAXPARTS+4);
- menus[0].prompt = " Next ";
- menus[1].prompt = " Back ";
+ menus = safe_malloc(sizeof(*menus)*MAXPARTS+4);
+
+ menus[0].prompt = "Next";
+ menus[1].prompt = "Back";
i = 2;
while ((token = strsep(&buf, "\n")) != NULL && strlen(token) > 0 &&
i < MAXPARTS-1) {
@@ -109,17 +111,13 @@
i++;
}
}
- /* XXX ugly */
- menus[i].prompt = __DECONST(char *, disk);
- menus[i].title = "Use entire disk";
- menus[i].aux = USEALL;
- menus[i].fire = part_fire;
- i++;
- menus[i].prompt = __DECONST(char *, disk);
- menus[i].title = "Create a new partition using free space";
- menus[i].aux = USENEW;
- menus[i].fire = part_fire;
- i++;
+
+ DMENU(&menus[i++], __DECONST(char *, disk), "Use entire disk",
+ NULL, NULL, part_fire, NULL, USEALL);
+ DMENU(&menus[i++], __DECONST(char *, disk),
+ "Create a new partition using free space",
+ NULL, NULL, part_fire, NULL, USENEW);
+
screen_clear(MODULE);
snprintf(prompt, sizeof(prompt), "The disk %s <%s>\n"
"is formatted using %s and has %s free\n\n"
Modified: pcbsd-projects/txt-sysinstall/rootpass.c
===================================================================
--- pcbsd-projects/txt-sysinstall/rootpass.c 2010-06-26 09:02:18 UTC (rev 7037)
+++ pcbsd-projects/txt-sysinstall/rootpass.c 2010-06-27 01:38:59 UTC (rev 7038)
@@ -36,22 +36,37 @@
#define MODULE "Root password"
+
void
dialog_rootpass(void)
{
- char rootPass[64];
+ int loop;
+ char rootPass1[64];
+ char rootPass2[64];
screen_clear(MODULE);
dialog_notify("You will be prompted to setup your root account "
"password.\n\nThe root account is a special account that has "
"access to\nall system resources.");
- memset(rootPass, 0, sizeof(rootPass));
- screen_clear(MODULE);
- dialog_inputbox(MODULE, "Please type the root password:", 8, 60,
- rootPass);
+ loop = 1;
+ while (loop) {
+ bzero(rootPass1, sizeof(rootPass1));
+ bzero(rootPass2, sizeof(rootPass2));
+ screen_clear(MODULE);
- appendconfig("rootPass", rootPass);
+ DialogInputAttrs |= DITEM_NO_ECHO;
+ dialog_inputbox(MODULE, "Please type the root password:",
+ 8, 60, rootPass1);
+ dialog_inputbox(MODULE, "Please confirm the root password:",
+ 8, 60, rootPass2);
+ DialogInputAttrs &= ~DITEM_NO_ECHO;
+ if (strncmp(rootPass1, rootPass2, sizeof(rootPass1)) == 0)
+ loop = 0;
+ }
+
+ appendconfig("rootPass", rootPass2);
+
dialog_tzone();
}
Modified: pcbsd-projects/txt-sysinstall/txt-sysinstall.h
===================================================================
--- pcbsd-projects/txt-sysinstall/txt-sysinstall.h 2010-06-26 09:02:18 UTC (rev 7037)
+++ pcbsd-projects/txt-sysinstall/txt-sysinstall.h 2010-06-27 01:38:59 UTC (rev 7038)
@@ -24,9 +24,34 @@
* SUCH DAMAGE.
*/
+#ifdef __PCBSD__
+#define OSNAME "PC-BSD"
+#else
+#define OSNAME "FreeBSD"
+#endif
+
#define SCRIPTS_PATH "./"
-#define PCSYSINSTALL "../../pc-sysinstall/pc-sysinstall"
+#define PCSYSINSTALL "/pc-sysinstall"
+#define BUFSZ 1024*1024
+
+#define DMENU(m, p, t, c, s, f, d, a) do { \
+ dialogMenuItem *mptr = m; \
+ mptr->prompt = p; \
+ mptr->title = t; \
+ mptr->checked = c; \
+ mptr->selected = s; \
+ mptr->fire = f; \
+ mptr->data = d; \
+ mptr->aux = a; \
+} while (0)
+
+#define DMENUF(m, p, t, f) \
+ DMENU(m, p, t, NULL, NULL, f, NULL, 0)
+
+#define DMENUFD(m, p, t, f, d) \
+ DMENU(m, p, t, NULL, NULL, f, d, 0)
+
/* dialogs */
void sysinstall(void);
void dialog_disksel(void);
@@ -43,6 +68,8 @@
/* utility functions */
void screen_clear(const char *);
-char * run_pcsysinstall(const char *, const char *);
+int empty(const char *);
+void * safe_malloc(size_t);
+size_t safe_strlen(const char *);
+int run_pcsysinstall(char *, size_t, const char *, const char *);
void appendconfig(const char *, const char *);
-
Modified: pcbsd-projects/txt-sysinstall/tzone.c
===================================================================
--- pcbsd-projects/txt-sysinstall/tzone.c 2010-06-26 09:02:18 UTC (rev 7037)
+++ pcbsd-projects/txt-sysinstall/tzone.c 2010-06-27 01:38:59 UTC (rev 7038)
@@ -59,21 +59,28 @@
char *token;
char *buf;
dialogMenuItem *menus;
+ int status;
int i = 0;
int ntp;
screen_clear(MODULE);
dialog_busy(5, 60, "Reading the list of timezones. Please wait.");
- buf = run_pcsysinstall("list-tzones", NULL);
- menus = malloc(sizeof(*menus)*MAXTZONES);
- memset(menus, 0, sizeof(*menus)*MAXTZONES);
+ buf = safe_malloc(BUFSZ+1);
+ status = run_pcsysinstall(buf, BUFSZ, "list-tzones", NULL);
+ menus = safe_malloc(sizeof(*menus)*MAXTZONES);
+
while ((token = strsep(&buf, "\n")) != NULL && strlen(token) > 0 &&
i < MAXTZONES) {
+
+ DMENUF(&menus[i++], strsep(&token, "/"), token, tzone_fire);
+
+/*
menus[i].prompt = strsep(&token, "/");
menus[i].title = token;
menus[i].fire = tzone_fire;
i++;
+*/
}
screen_clear(MODULE);
dialog_menu("Timezone selection",
Modified: pcbsd-projects/txt-sysinstall/useradd.c
===================================================================
--- pcbsd-projects/txt-sysinstall/useradd.c 2010-06-26 09:02:18 UTC (rev 7037)
+++ pcbsd-projects/txt-sysinstall/useradd.c 2010-06-27 01:38:59 UTC (rev 7038)
@@ -27,6 +27,7 @@
*/
#include <dialog.h>
+#include <stdlib.h>
#include <string.h>
#include "txt-sysinstall.h"
@@ -39,7 +40,6 @@
static int
shell_fire(dialogMenuItem *self)
{
-
snprintf(shellPath, sizeof(shellPath), "/bin/%s", self->prompt);
return (0);
@@ -48,8 +48,11 @@
void
dialog_useradd(void)
{
- unsigned char username[64], realname[64], password[64];
+ unsigned char username[64], realname[64];
+ unsigned char password1[64];
+ unsigned char password2[64];
unsigned char prompt[1024];
+ int loop;
int add;
dialogMenuItem shells[] = {
@@ -63,36 +66,50 @@
.fire = shell_fire },
};
- memset(username, 0, sizeof(username));
- memset(realname, 0, sizeof(realname));
- memset(password, 0, sizeof(password));
+ bzero(username, sizeof(username));
+ bzero(realname, sizeof(realname));
+ bzero(password1, sizeof(password1));
+ bzero(password2, sizeof(password2));
+
useradd_restart:
screen_clear(MODULE);
- dialog_inputbox("Add user", "Please insert the desired username:",
- 8, 60, username);
- dialog_inputbox("Add user", "Please insert the real name:",
- 8, 60, realname);
- dialog_inputbox("Add user", "Please type the password for this user:",
- 8, 60, password);
- dialog_menu("Add user", "Please select the shell for this user:",
- 11, 60, 4, -4, shells, NULL, NULL, NULL);
+ if (dialog_inputbox("Add user", "Please insert the desired username:",
+ 8, 60, username) == 0 && !empty(username)) {
+ dialog_inputbox("Add user", "Please insert the real name:",
+ 8, 60, realname);
- snprintf(prompt, sizeof(prompt), "Is the following information "
- "correct?\n\n"
- "Username:\t%s\nReal name:\t%s\nShell:\t%s\n",
- username, realname, shellPath);
- screen_clear(MODULE);
- add = dialog_yesno("Add user", prompt, 10, 60);
- if (add == FALSE) {
- appendconfig("userName", username);
- appendconfig("userComment", realname);
- appendconfig("userPass", password);
- appendconfig("userGroups", "wheel,operator");
- appendconfig("autoLoginUser", username);
- appendconfig("userShell", shellPath);
- appendconfig("commitUser", NULL);
- } else {
- goto useradd_restart;
+ loop = 1;
+ while (loop) {
+ DialogInputAttrs |= DITEM_NO_ECHO;
+ dialog_inputbox("Add user", "Please type the password for this user:",
+ 8, 60, password1);
+ dialog_inputbox("Add user", "Please confirm the password for this user:",
+ 8, 60, password2);
+ DialogInputAttrs &= ~DITEM_NO_ECHO;
+ if (strncmp(password1, password2, sizeof(password2)) == 0)
+ loop = 0;
+ }
+
+ dialog_menu("Add user", "Please select the shell for this user:",
+ 11, 60, 4, -4, shells, NULL, NULL, NULL);
+
+ snprintf(prompt, sizeof(prompt), "Is the following information "
+ "correct?\n\n"
+ "Username:\t%s\nReal name:\t%s\nShell:\t%s\n",
+ username, realname, shellPath);
+ screen_clear(MODULE);
+ add = dialog_yesno("Add user", prompt, 10, 60);
+ if (add == FALSE) {
+ appendconfig("userName", username);
+ appendconfig("userComment", realname);
+ appendconfig("userPass", password2);
+ appendconfig("userGroups", "wheel,operator");
+ appendconfig("autoLoginUser", username);
+ appendconfig("userShell", shellPath);
+ appendconfig("commitUser", NULL);
+ } else {
+ goto useradd_restart;
+ }
}
dialog_rootpass();
Modified: pcbsd-projects/txt-sysinstall/util.c
===================================================================
--- pcbsd-projects/txt-sysinstall/util.c 2010-06-26 09:02:18 UTC (rev 7037)
+++ pcbsd-projects/txt-sysinstall/util.c 2010-06-27 01:38:59 UTC (rev 7038)
@@ -26,15 +26,16 @@
* $Id$
*/
+#include <sys/types.h>
+#include <sys/wait.h>
#include <err.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <dialog.h>
+#include <ctype.h>
#include <curses.h>
-#include <sys/types.h>
-#include <sys/wait.h>
#include "txt-sysinstall.h"
@@ -43,30 +44,64 @@
{
dialog_clear();
- mvprintw(0, 0, "PC-BSD installer >> %s", module);
+ mvprintw(0, 0, "%s installer >> %s", OSNAME, module);
}
+int
+empty(const char *str)
+{
+ int res = 1;
+
+ if (str == NULL || str[0] == 0)
+ return (res);
+
+ while (*str != 0) {
+ if (!isspace(*str) && !iscntrl(*str))
+ return (0);
+ str++;
+ }
+
+ return (res);
+}
+
+void *
+safe_malloc(size_t size)
+{
+ void *ptr;
+
+ if ((ptr = malloc(size)) == NULL)
+ err(1, "malloc failed!");
+
+ bzero(ptr, size);
+ return (ptr);
+}
+
+size_t
+safe_strlen(const char *str)
+{
+ size_t len = 0;
+
+ if (str != NULL && str[0] != 0)
+ len = strlen(str);
+
+ return (len);
+}
+
/*
* Run pc-sysinstall with the specified cmd. If the function
* returns non-NULL, it's up to the caller to free the buf.
*/
-char *
-run_pcsysinstall(const char *cmd1, const char *cmd2)
+int
+run_pcsysinstall(char *buf, size_t size, const char *cmd1, const char *cmd2)
{
-#define BUFSZ 1024 * 1024
int fd[2];
- char *buf;
ssize_t len;
int status;
- buf = malloc(BUFSZ+1);
- if (!buf)
- return (NULL);
- memset(buf, 0, BUFSZ);
- if (pipe(fd) < 0) {
- free(buf);
- return (NULL);
- }
+ status = 0;
+ if (pipe(fd) < 0)
+ return (-1);
+
switch (fork()) {
case 0:
close(fd[1]);
@@ -74,30 +109,31 @@
close(fd[0]);
execl(PCSYSINSTALL, "pc-sysinstall", cmd1, cmd2, NULL);
_exit(1);
+
case -1:
close(fd[0]);
close(fd[1]);
- free(buf);
- return (NULL);
+ return (-1);
+
default:
wait(&status);
if (status != 0) {
end_dialog();
close(fd[0]);
close(fd[1]);
- free(buf);
errx(1, "pc-sysinstall not found");
}
}
- if ((len = read(fd[1], buf, BUFSZ)) < 0) {
+
+ if ((len = read(fd[1], buf, size)) < 0) {
close(fd[0]);
close(fd[1]);
- free(buf);
- return (NULL);
+ return (-1);
}
+
close(fd[0]);
close(fd[1]);
- return (buf);
+ return (status);
}
void
More information about the Commits
mailing list