screensaver: allow using the system password to unlock
This replaces the non-functioning "Network password" option that was never implemented. Change-Id: I9b7362f4e05d7f1a4be321e1a9aade62559794d2 Reviewed-on: https://review.haiku-os.org/c/haiku/+/9009 Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
committed by
waddlesplash
parent
8a1adae8b3
commit
c10ecdf570
@@ -56,9 +56,9 @@ public:
|
|||||||
bigtime_t PasswordTime() const { return fPasswordTime; }
|
bigtime_t PasswordTime() const { return fPasswordTime; }
|
||||||
const char* Password() { return fPassword.String(); }
|
const char* Password() { return fPassword.String(); }
|
||||||
const char* LockMethod() { return fLockMethod.String(); }
|
const char* LockMethod() { return fLockMethod.String(); }
|
||||||
bool IsNetworkPassword()
|
bool UseSystemPassword()
|
||||||
{ return strcmp(fLockMethod.String(), "custom")
|
{ return strcmp(fLockMethod.String(), "system")
|
||||||
!= 0; }
|
== 0; }
|
||||||
|
|
||||||
const char* ModuleName() { return fModuleName.String(); }
|
const char* ModuleName() { return fModuleName.String(); }
|
||||||
status_t GetModuleState(const char* name,
|
status_t GetModuleState(const char* name,
|
||||||
@@ -84,7 +84,7 @@ public:
|
|||||||
{ fPasswordTime = time; }
|
{ fPasswordTime = time; }
|
||||||
void SetPassword(const char* password)
|
void SetPassword(const char* password)
|
||||||
{ fPassword = password; }
|
{ fPassword = password; }
|
||||||
// Cannot set network password from here.
|
// Cannot set system password from here.
|
||||||
void SetLockMethod(const char* method)
|
void SetLockMethod(const char* method)
|
||||||
{ fLockMethod = method; }
|
{ fLockMethod = method; }
|
||||||
void SetModuleName(const char* name)
|
void SetModuleName(const char* name)
|
||||||
|
|||||||
@@ -224,7 +224,9 @@ ScreenBlanker::MessageReceived(BMessage* message)
|
|||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
case kMsgUnlock:
|
case kMsgUnlock:
|
||||||
{
|
{
|
||||||
if (strcmp(fSettings.Password(), crypt(fPasswordWindow->Password(),
|
// if the user has no password then just exit on any input
|
||||||
|
if (fSettings.Password()[0] != '\0'
|
||||||
|
&& strcmp(fSettings.Password(), crypt(fPasswordWindow->Password(),
|
||||||
fSettings.Password())) != 0) {
|
fSettings.Password())) != 0) {
|
||||||
beep();
|
beep();
|
||||||
fPasswordWindow->SetPassword("");
|
fPasswordWindow->SetPassword("");
|
||||||
|
|||||||
@@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
#include "ScreenSaverSettings.h"
|
#include "ScreenSaverSettings.h"
|
||||||
|
|
||||||
|
#include <pwd.h>
|
||||||
|
#include <shadow.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <Debug.h>
|
#include <Debug.h>
|
||||||
@@ -87,8 +89,20 @@ ScreenSaverSettings::Load()
|
|||||||
if (fSettings.FindString("modulename", &string) == B_OK)
|
if (fSettings.FindString("modulename", &string) == B_OK)
|
||||||
fModuleName = string;
|
fModuleName = string;
|
||||||
|
|
||||||
if (IsNetworkPassword()) {
|
if (!UseSystemPassword())
|
||||||
// TODO: this does not work yet
|
return true;
|
||||||
|
|
||||||
|
char* username = getlogin();
|
||||||
|
if (username == NULL)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
struct spwd *shadowpwd = getspnam(username);
|
||||||
|
if (shadowpwd != NULL) {
|
||||||
|
fPassword = shadowpwd->sp_pwdp;
|
||||||
|
} else {
|
||||||
|
struct passwd *pwd = getpwnam(username);
|
||||||
|
if (pwd != NULL)
|
||||||
|
fPassword = pwd->pw_passwd;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -160,7 +174,7 @@ ScreenSaverSettings::Message()
|
|||||||
if (fSettings.ReplaceString("lockmethod", fLockMethod) != B_OK)
|
if (fSettings.ReplaceString("lockmethod", fLockMethod) != B_OK)
|
||||||
fSettings.AddString("lockmethod", fLockMethod);
|
fSettings.AddString("lockmethod", fLockMethod);
|
||||||
|
|
||||||
const char* password = IsNetworkPassword() ? "" : fPassword.String();
|
const char* password = UseSystemPassword() ? "" : fPassword.String();
|
||||||
if (fSettings.ReplaceString("lockpassword", password) != B_OK)
|
if (fSettings.ReplaceString("lockpassword", password) != B_OK)
|
||||||
fSettings.AddString("lockpassword", password);
|
fSettings.AddString("lockpassword", password);
|
||||||
|
|
||||||
|
|||||||
@@ -60,13 +60,13 @@ PasswordWindow::_Setup()
|
|||||||
topView->SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
|
topView->SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
|
||||||
topView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED));
|
topView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED));
|
||||||
|
|
||||||
BBox* networkBox = new BBox("networkBox");
|
BBox* systemBox = new BBox("systemBox");
|
||||||
networkBox->SetBorder(B_NO_BORDER);
|
systemBox->SetBorder(B_NO_BORDER);
|
||||||
|
|
||||||
fUseNetwork = new BRadioButton("useNetwork",
|
fUseSystem = new BRadioButton("useSystem",
|
||||||
B_TRANSLATE("Use network password"),
|
B_TRANSLATE("Use system password"),
|
||||||
new BMessage(kMsgPasswordTypeChanged));
|
new BMessage(kMsgPasswordTypeChanged));
|
||||||
networkBox->SetLabel(fUseNetwork);
|
systemBox->SetLabel(fUseSystem);
|
||||||
|
|
||||||
BBox* customBox = new BBox("customBox");
|
BBox* customBox = new BBox("customBox");
|
||||||
|
|
||||||
@@ -114,7 +114,7 @@ PasswordWindow::_Setup()
|
|||||||
|
|
||||||
BLayoutBuilder::Group<>(topView, B_VERTICAL, 0)
|
BLayoutBuilder::Group<>(topView, B_VERTICAL, 0)
|
||||||
.SetInsets(B_USE_DEFAULT_SPACING)
|
.SetInsets(B_USE_DEFAULT_SPACING)
|
||||||
.Add(networkBox)
|
.Add(systemBox)
|
||||||
.Add(customBox)
|
.Add(customBox)
|
||||||
.AddStrut(B_USE_DEFAULT_SPACING)
|
.AddStrut(B_USE_DEFAULT_SPACING)
|
||||||
.AddGroup(B_HORIZONTAL)
|
.AddGroup(B_HORIZONTAL)
|
||||||
@@ -134,14 +134,14 @@ PasswordWindow::_Setup()
|
|||||||
void
|
void
|
||||||
PasswordWindow::Update()
|
PasswordWindow::Update()
|
||||||
{
|
{
|
||||||
if (fSettings.IsNetworkPassword())
|
if (fSettings.UseSystemPassword())
|
||||||
fUseNetwork->SetValue(B_CONTROL_ON);
|
fUseSystem->SetValue(B_CONTROL_ON);
|
||||||
else
|
else
|
||||||
fUseCustom->SetValue(B_CONTROL_ON);
|
fUseCustom->SetValue(B_CONTROL_ON);
|
||||||
|
|
||||||
bool useNetPassword = (fUseCustom->Value() > 0);
|
bool useSysPassword = (fUseCustom->Value() > 0);
|
||||||
fConfirmControl->SetEnabled(useNetPassword);
|
fConfirmControl->SetEnabled(useSysPassword);
|
||||||
fPasswordControl->SetEnabled(useNetPassword);
|
fPasswordControl->SetEnabled(useSysPassword);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -150,7 +150,7 @@ PasswordWindow::MessageReceived(BMessage* message)
|
|||||||
{
|
{
|
||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
case kMsgDone:
|
case kMsgDone:
|
||||||
fSettings.SetLockMethod(fUseCustom->Value() ? "custom" : "network");
|
fSettings.SetLockMethod(fUseCustom->Value() ? "custom" : "system");
|
||||||
if (fUseCustom->Value()) {
|
if (fUseCustom->Value()) {
|
||||||
if (strcmp(fPasswordControl->Text(), fConfirmControl->Text())
|
if (strcmp(fPasswordControl->Text(), fConfirmControl->Text())
|
||||||
!= 0) {
|
!= 0) {
|
||||||
@@ -178,7 +178,7 @@ PasswordWindow::MessageReceived(BMessage* message)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case kMsgPasswordTypeChanged:
|
case kMsgPasswordTypeChanged:
|
||||||
fSettings.SetLockMethod(fUseCustom->Value() > 0 ? "custom" : "network");
|
fSettings.SetLockMethod(fUseCustom->Value() > 0 ? "custom" : "system");
|
||||||
Update();
|
Update();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ private:
|
|||||||
void _Setup();
|
void _Setup();
|
||||||
|
|
||||||
BRadioButton* fUseCustom;
|
BRadioButton* fUseCustom;
|
||||||
BRadioButton* fUseNetwork;
|
BRadioButton* fUseSystem;
|
||||||
BTextControl* fConfirmControl;
|
BTextControl* fConfirmControl;
|
||||||
BTextControl* fPasswordControl;
|
BTextControl* fPasswordControl;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user