From 7b25d553423387823a2f3eb1461d361148be4fa5 Mon Sep 17 00:00:00 2001 From: yellows8 Date: Sun, 31 Mar 2019 22:01:48 -0400 Subject: [PATCH] Added pctlauth. --- nx/include/switch.h | 1 + nx/include/switch/applets/pctlauth.h | 57 +++++++++++++++++++++ nx/source/applets/pctlauth.c | 74 ++++++++++++++++++++++++++++ 3 files changed, 132 insertions(+) create mode 100644 nx/include/switch/applets/pctlauth.h create mode 100644 nx/source/applets/pctlauth.c diff --git a/nx/include/switch.h b/nx/include/switch.h index 538684f3..4b671d13 100644 --- a/nx/include/switch.h +++ b/nx/include/switch.h @@ -106,6 +106,7 @@ extern "C" { #include "switch/audio/driver.h" #include "switch/applets/libapplet.h" +#include "switch/applets/pctlauth.h" #include "switch/applets/error.h" #include "switch/applets/swkbd.h" #include "switch/applets/web.h" diff --git a/nx/include/switch/applets/pctlauth.h b/nx/include/switch/applets/pctlauth.h new file mode 100644 index 00000000..593d6c41 --- /dev/null +++ b/nx/include/switch/applets/pctlauth.h @@ -0,0 +1,57 @@ +/** + * @file pctlauth.h + * @brief Wrapper for using the Parental Controls authentication LibraryApplet. This applet is used by qlaunch. + * @author yellows8 + * @copyright libnx Authors + */ +#pragma once +#include "../types.h" + +/// Type values for PctlAuthArg::type. +typedef enum { + PctlAuthType_Show = 0, ///< ShowParentalAuthentication + PctlAuthType_RegisterPasscode = 1, ///< RegisterParentalPasscode + PctlAuthType_ChangePasscode = 2, ///< ChangeParentalPasscode +} PctlAuthType; + +/// Input arg storage for the applet. +typedef struct { + u32 unk_x0; ///< Always set to 0 by the user-process. + PctlAuthType type; ///< \ref PctlAuthType + u8 arg0; ///< Arg0 + u8 arg1; ///< Arg1 + u8 arg2; ///< Arg2 + u8 pad; ///< Padding +} PctlAuthArg; + +/** + * @brief Launches the applet. + * @note Should not be used if a PIN is not already registered. + * @param flag Input flag. false = temporarily disable Parental Controls. true = validate the input PIN. + */ +Result pctlauthShow(bool flag); + +/** + * @brief Launches the applet. Only available with [4.0.0+]. + * @param arg0 Value for PctlAuthArg.arg0. + * @param arg1 Value for PctlAuthArg.arg1. + * @param arg2 Value for PctlAuthArg.arg2. + */ +Result pctlauthShowEx(u8 arg0, u8 arg1, u8 arg2); + +/** + * @brief Just calls: pctlauthShowEx(1, 0, 1). + */ +Result pctlauthShowForConfiguration(void); + +/** + * @brief Launches the applet for registering the Parental Controls PIN. + */ +Result pctlauthRegisterPasscode(void); + +/** + * @brief Launches the applet for changing the Parental Controls PIN. + * @note Should not be used if a PIN is not already registered. + */ +Result pctlauthChangePasscode(void); + diff --git a/nx/source/applets/pctlauth.c b/nx/source/applets/pctlauth.c new file mode 100644 index 00000000..bf29ae70 --- /dev/null +++ b/nx/source/applets/pctlauth.c @@ -0,0 +1,74 @@ +#include +#include "types.h" +#include "result.h" +#include "services/applet.h" +#include "applets/libapplet.h" +#include "applets/pctlauth.h" +#include "runtime/hosversion.h" + +static Result _pctlauthShow(PctlAuthArg* arg) { + Result rc=0; + Result tmpres=0; + size_t out_reply_size=0; + u32 ver=1; + LibAppletArgs commonargs; + + if (hosversionAtLeast(4,0,0)) ver=2; + libappletArgsCreate(&commonargs, ver); + + rc = libappletLaunch(AppletId_auth, &commonargs, arg, sizeof(*arg), &tmpres, sizeof(tmpres), &out_reply_size); + if (R_SUCCEEDED(rc)) { + if (out_reply_size != sizeof(tmpres)) rc = MAKERESULT(Module_Libnx, LibnxError_LibAppletBadExit); + if (R_SUCCEEDED(rc)) rc = tmpres; + } + + return rc; +} + +Result pctlauthShow(bool flag) { + PctlAuthArg arg; + + memset(&arg, 0, sizeof(arg)); + arg.type = PctlAuthType_Show; + arg.arg0 = flag!=0; + + return _pctlauthShow(&arg); +} + +Result pctlauthShowEx(u8 arg0, u8 arg1, u8 arg2) { + PctlAuthArg arg; + + if (hosversionBefore(4,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + memset(&arg, 0, sizeof(arg)); + arg.type = PctlAuthType_Show; + arg.arg0 = arg0; + arg.arg1 = arg1; + arg.arg2 = arg2; + + return _pctlauthShow(&arg); +} + +Result pctlauthShowForConfiguration(void) { + return pctlauthShowEx(1, 0, 1); +} + +Result pctlauthRegisterPasscode(void) { + PctlAuthArg arg; + + memset(&arg, 0, sizeof(arg)); + arg.type = PctlAuthType_RegisterPasscode; + + return _pctlauthShow(&arg); +} + +Result pctlauthChangePasscode(void) { + PctlAuthArg arg; + + memset(&arg, 0, sizeof(arg)); + arg.type = PctlAuthType_ChangePasscode; + + return _pctlauthShow(&arg); +} + +