From fa49fe87ad4968bc6f29d61006a51292f02230f9 Mon Sep 17 00:00:00 2001
From: rswindell <>
Date: Wed, 9 Aug 2017 20:18:41 +0000
Subject: [PATCH] bbs.check_syspass() now accepts an optional 'sys_pw'
 argument. If supplied, password is not prompted for, otherwise, the behavior
 is the same as before (the SY: prompt is displayed and the system password
 must be entered by the user).

---
 src/sbbs3/js_bbs.cpp | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/sbbs3/js_bbs.cpp b/src/sbbs3/js_bbs.cpp
index 4d0825387e..3d4007b6ca 100644
--- a/src/sbbs3/js_bbs.cpp
+++ b/src/sbbs3/js_bbs.cpp
@@ -1195,7 +1195,9 @@ js_user_event(JSContext *cx, uintN argc, jsval *arglist)
 static JSBool
 js_chksyspass(JSContext *cx, uintN argc, jsval *arglist)
 {
+	jsval *argv = JS_ARGV(cx, arglist);
 	sbbs_t*		sbbs;
+	char*		sys_pw = NULL;
 	jsrefcount	rc;
 
 	JS_SET_RVAL(cx, arglist, JSVAL_VOID);
@@ -1203,8 +1205,13 @@ js_chksyspass(JSContext *cx, uintN argc, jsval *arglist)
 	if((sbbs=js_GetPrivate(cx, JS_THIS_OBJECT(cx, arglist)))==NULL)
 		return(JS_FALSE);
 
+	if (argc) {
+		JSString* str = JS_ValueToString(cx, argv[0]);
+		JSSTRING_TO_ASTRING(cx, str, sys_pw, sizeof(sbbs->cfg.sys_pass)+2, NULL);
+	}
+
 	rc=JS_SUSPENDREQUEST(cx);
-	JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(sbbs->chksyspass()));
+	JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(sbbs->chksyspass(sys_pw)));
 	JS_RESUMEREQUEST(cx, rc);
 	return(JS_TRUE);
 }
@@ -3785,8 +3792,8 @@ static jsSyncMethodSpec js_bbs_functions[] = {
 	,316
 	},		
 	/* security */
-	{"check_syspass",	js_chksyspass,		0,	JSTYPE_BOOLEAN,	JSDOCSTR("")
-	,JSDOCSTR("prompt for and verify system password")
+	{"check_syspass",	js_chksyspass,		0,	JSTYPE_BOOLEAN,	JSDOCSTR("[sys_pw]")
+	,JSDOCSTR("verify system password, prompting for the password if not passed as an argument")
 	,310
 	},
 	{"good_password",	js_chkpass,			1,	JSTYPE_STRING,	JSDOCSTR("password")
-- 
GitLab