Subject: bin/24647: add confirmation to submit forms in sushi(8)
To: None <gnats-bugs@gnats.NetBSD.org>
From: Peter Postma <peter@pointless.nl>
List: netbsd-bugs
Date: 03/02/2004 21:54:05
>Number:         24647
>Category:       bin
>Synopsis:       add confirmation to submit forms in sushi(8)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Tue Mar 02 20:55:00 UTC 2004
>Closed-Date:
>Last-Modified:
>Originator:     Peter Postma
>Release:        NetBSD 1.6ZK
>Organization:
>Environment:
System: NetBSD mercury.pointless.nl 1.6ZK NetBSD 1.6ZK (mercury) #25: Mon Feb 23 15:42:28 CET 2004 root@mercury.pointless.nl:/usr/obj/sys/arch/sparc64/compile/mercury sparc64
Architecture: sparc64
Machine: sparc64
>Description:
	sushi(8) does not give a confirmation in forms when enter is pressed,
	the form is submitted directly and files get overwritten.
	this can be annoying if enter was pressed by accident.
>How-To-Repeat:
	start sushi. goto "Network related configuration" ->
	"Modify the hosts file" -> "Add an IPv4 host entry".
	typ something and press enter.
>Fix:

Index: scanform.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/sushi/scanform.c,v
retrieving revision 1.31
diff -u -r1.31 scanform.c
--- scanform.c	12 Nov 2003 13:31:08 -0000	1.31
+++ scanform.c	2 Mar 2004 20:42:25 -0000
@@ -551,10 +551,12 @@
 	case QUIT:
 		/* do something useful */
 		if (form_driver(form, REQ_VALIDATION) == E_OK) {
-			if (process_form(form, path) == 0)
+			if ((i = process_form(form, path)) == 0)
 				return TRUE;
+			else if (i == -1)
+				return 0;
 			else
-				return(2); /* special meaning */
+				return 2; /* special meaning */
 		}
 		/* NOTREACHED */
 		break;
@@ -850,11 +852,24 @@
 	int fc, lcnt, i, j;
 	FIELD **f;
 	char **args, **nargs;
+	CDKLABEL *label;
+	char *msg[1];
+	int key;
 
 	/* handle the preform somewhere else */
 	if (strcmp("pre", form_userptr(form)) == 0)
 		return(process_preform(form, path));
 
+	*msg = " Are you sure? (Y/n) ";
+	label = newCDKLabel(cdkscreen, CENTER, CENTER, msg, 1, TRUE, FALSE);
+	activateCDKLabel(label, NULL);
+	key = waitCDKLabel(label, 0);
+	destroyCDKLabel(label);
+	touchwin(stdscr);
+	wrefresh(stdscr);
+	if (key != KEY_ENTER && key != 121 && key != 89) /* enter, y, Y */
+		return -1;
+
 	if (lang_id == NULL) {
 		snprintf(file, sizeof(file), "%s/%s", path, EXECFILE);
 		snprintf(file2, sizeof(file2), "%s/%s", path, SCRIPTFILE);
>Release-Note:
>Audit-Trail:
>Unformatted: