aboutsummaryrefslogtreecommitdiff
path: root/src-qt5
diff options
context:
space:
mode:
authorKen Moore <ken@ixsystems.com>2017-10-11 14:46:54 -0400
committerKen Moore <ken@ixsystems.com>2017-10-11 14:46:54 -0400
commit2cedaf2c2ac9e4b4e3078c5a6f04ba5fc3f4f5b3 (patch)
tree4781e84e186f9fcc445a6f4d75e6fb44721e9385 /src-qt5
parentA bit more cleanup for the screensaver system. (diff)
downloadlumina-2cedaf2c2ac9e4b4e3078c5a6f04ba5fc3f4f5b3.tar.gz
lumina-2cedaf2c2ac9e4b4e3078c5a6f04ba5fc3f4f5b3.tar.bz2
lumina-2cedaf2c2ac9e4b4e3078c5a6f04ba5fc3f4f5b3.zip
Update lumina-checkpass with 2 additional options:
1. "-fd <file descriptor>" pass in a file descriptor (such as 0 for standard input) to read password 2. "-f <file path>" pass in a file path to read the password Then update lumina-desktop-unified to use the "-f" version with a QTemporaryFile. I was trying to get it to use the "-fd" version, but the file descriptor I am getting from the QTemporaryFile does not seem to work properly - still need to track this down a bit more later but the -f option works fine for now.
Diffstat (limited to 'src-qt5')
-rw-r--r--src-qt5/core/lumina-checkpass/main.c39
-rw-r--r--src-qt5/core/lumina-desktop-unified/global-includes.h1
-rw-r--r--src-qt5/core/lumina-desktop-unified/src-screensaver/LLockScreen.cpp13
3 files changed, 47 insertions, 6 deletions
diff --git a/src-qt5/core/lumina-checkpass/main.c b/src-qt5/core/lumina-checkpass/main.c
index e12e7c78..481cce33 100644
--- a/src-qt5/core/lumina-checkpass/main.c
+++ b/src-qt5/core/lumina-checkpass/main.c
@@ -14,23 +14,52 @@
//===========================================
//Standard C libary
#include <unistd.h> // Standard C
+#include <stdlib.h>
#include <stdio.h> // Usage output
#include <pwd.h> // User DB information
+#include <string.h>
//PAM/security libraries
#include <sys/types.h>
#include <security/pam_appl.h>
#include <security/openpam.h>
+void showUsage(){
+ puts("lumina-checkpass: Simple user-level check for password validity (for screen unlockers and such).");
+ puts("Usage:");
+ puts(" lumina-checkpass <password>");
+ puts(" lumina-checkpass -fd <file descriptor>");
+ puts(" lumina-checkpass -f <file path>");
+ puts("Returns: 0 for a valid password, 1 for invalid");
+}
+
int main(int argc, char** argv){
//Check the inputs
- if(argc!=2){
+ if(argc<2){
//Invalid inputs - show the help text
- puts("lumina-checkpass: Simple user-level check for password validity (for screen unlockers and such).");
- puts("Usage: lumina-checkpass <password>");
- puts("Returns: 0 for a valid password, 1 for invalid");
+ showUsage();
return 1;
}
+ char*pass = 0;
+ if(argc==2){ pass = argv[1]; }
+ else if(argc==3 && 0==strcmp(argv[1],"-fd") ){
+ FILE *fp = fdopen(atoi(argv[2]), "r");
+ size_t len;
+ if(fp!=0){
+ ssize_t slen = getline(&pass, &len, fp);
+ if(pass[slen-1]=='\n'){ pass[slen-1] = '\0'; }
+ }
+ fclose(fp);
+ }else if(argc==3 && 0==strcmp(argv[1],"-f") ){
+ FILE *fp = fopen(argv[2], "r");
+ size_t len;
+ if(fp!=0){
+ ssize_t slen = getline(&pass, &len, fp);
+ if(pass[slen-1]=='\n'){ pass[slen-1] = '\0'; }
+ }
+ fclose(fp);
+ }
+ if(pass == 0){ puts("Could not read password!!"); return 1; } //error in reading password
//Validate current user (make sure current UID matches the logged-in user,
char* cUser = getlogin();
struct passwd *pwd = 0;
@@ -44,7 +73,7 @@ int main(int argc, char** argv){
int ret = pam_start( "system", cUser, &pamc, &pamh);
if(ret != PAM_SUCCESS){ return 1; } //could not init PAM
//char* cPassword = argv[1];
- ret = pam_set_item(pamh, PAM_AUTHTOK, argv[1]);
+ ret = pam_set_item(pamh, PAM_AUTHTOK, pass);
//Authenticate with PAM
ret = pam_authenticate(pamh,0); //this can be true without verifying password if pam_self.so is used in the auth procedures (common)
if( ret == PAM_SUCCESS ){ ret = pam_acct_mgmt(pamh,0); } //Check for valid, unexpired account and verify access restrictions
diff --git a/src-qt5/core/lumina-desktop-unified/global-includes.h b/src-qt5/core/lumina-desktop-unified/global-includes.h
index ba1beb06..ae57ac08 100644
--- a/src-qt5/core/lumina-desktop-unified/global-includes.h
+++ b/src-qt5/core/lumina-desktop-unified/global-includes.h
@@ -19,6 +19,7 @@
#include <QMouseEvent>
#include <QAction>
#include <QPoint>
+#include <QTemporaryFile>
#include <QFile>
#include <QDir>
#include <QString>
diff --git a/src-qt5/core/lumina-desktop-unified/src-screensaver/LLockScreen.cpp b/src-qt5/core/lumina-desktop-unified/src-screensaver/LLockScreen.cpp
index 0ff70142..b791ffd2 100644
--- a/src-qt5/core/lumina-desktop-unified/src-screensaver/LLockScreen.cpp
+++ b/src-qt5/core/lumina-desktop-unified/src-screensaver/LLockScreen.cpp
@@ -77,7 +77,18 @@ void LLockScreen::TryUnlock(){
this->setEnabled(false);
QString pass = ui->line_password->text();
ui->line_password->clear();
- bool ok = (LUtils::runCmd("lumina-checkpass", QStringList() << pass) == 0);
+ //Create a temporary file for the password, then pass that file descriptor to lumina-checkpass
+ QTemporaryFile *TF = new QTemporaryFile(".XXXXXXXXXX");
+ TF->setAutoRemove(true);
+ bool ok = false;
+ if( TF->open() ){
+ QTextStream in(TF);
+ in << pass;
+ in.flush(); //make sure we push it to the file **right now** since we need to keep the file open
+ ok = (LUtils::runCmd("lumina-checkpass", QStringList() << "-f" << TF->fileName() ) == 0);
+ TF->close();
+ }
+ delete TF;
if(ok){
emit ScreenUnlocked();
this->setEnabled(true);
bgstack15