Added pctlauth.

This commit is contained in:
yellows8 2019-03-31 22:01:48 -04:00
parent 9bbcee9bcf
commit 7b25d55342
No known key found for this signature in database
GPG Key ID: 0AF90DA3F1E60E43
3 changed files with 132 additions and 0 deletions

View File

@ -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"

View File

@ -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);

View File

@ -0,0 +1,74 @@
#include <string.h>
#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);
}