Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Screensaver config #808

Open
outpaddling opened this issue Feb 9, 2022 · 26 comments
Open

Screensaver config #808

outpaddling opened this issue Feb 9, 2022 · 26 comments

Comments

@outpaddling
Copy link
Contributor

With 1.6.2, xscreensaver is no longer needed.

However:

  1. There does not appear to be a way to configure the new screensaver via Lumina settings.
  2. The right-click menu on the desktop still refers to xscreensaver. If xscreensaver is removed via "pkg remove -f", the menu item is still there but has no effect.
    screensaver-settings
@q5sys
Copy link
Member

q5sys commented Feb 9, 2022

Thats because xscreensaver is the only screensaver Lumina can use right now.
The menu is not coded to use alternative screensavers. What other options are there?

@outpaddling
Copy link
Contributor Author

outpaddling commented Feb 9, 2022

If you remove xscreensaver (using pkg remove -f on FreeBSD, because it's currently a dependency of the port), then lock the screen via the "Leave" menu, the alternate screensaver starts and functions perfectly. It also starts on its own after sufficient idle time.
lock
vbox-locked

Even if xscreensaver is installed and running, the other screensaver still starts first. There are no other screensaver apps installed as far as I can tell, so I thought this was part of Lumina. Maybe part of Xorg?

FreeBSD coral.acadix  bacon ~ 1005: pkg info|grep -i saver
libXScrnSaver-1.2.3_2          The XScrnSaver library

@q5sys
Copy link
Member

q5sys commented Feb 9, 2022

xscreensaver was technically never a "hard requirement" by lumina... It was a soft requirement because virtually no one wants a system without a screensaver.
i wonder if that libxscrnsaver is a part of the FreeBSD Base system.
I dont recall it being installed on my Slackware systems.

@outpaddling
Copy link
Contributor Author

libXScrnSaver is a dependency of the x11/xorg-libraries port, so it's basic to every FreeBSD desktop installation.
Interesting that you were not aware of this change. I assumed it was an improvement to Lumina, since there had been talk about eliminating xscreensaver with the 2.0 release. The new screensaver appeared with the upgrade from 1.6.0 to 1.6.2. Possibly in 1.6.1 as well, but I only ran it very briefly. Can you be sure this was not due to changes to Lumina? Seems unlikely to be a coincidence, since I'm not seeing any changes to the xorg-libraries or libXScrnSaver ports in the last couple years.

@outpaddling
Copy link
Contributor Author

outpaddling commented Feb 9, 2022

Here is what I see if I ssh into a machine with the screensaver running:
screensaver-top
Without the screensaver running, lumina-desktop uses < 3% CPU most of the time.
I also ran a "ps ax" with and without the screensaver running. There were no differences, so lumina-desktop is not running an external command for this.

@q5sys
Copy link
Member

q5sys commented Feb 9, 2022

The planned removal of xscreensaver was due to Kens plans for the Native Lumina Window Manager. We were going to have our own screensaver that was baked right into the desktop session, to eliminate the security issues of it being a separate process that's running.
But since the Window Manager isnt complete yet... obviously that's not available... or at least shouldnt be.

Keep in mind that the move from 1.6.0 to 1.6.1 included about a year and a half of small changes in the master branch after Jan 31, 2020 when 1.6.0 was released. I think the xscreensaver one was something that happened in that time. During those 20 months, Ken and I were mostly the only ones using the updated code in master, since all the distros were operating off the 1.6.0 release tag.
A lot took place in our lives and the project in those 20 months and there's a lot that simply drifted from memory. The checkpass binary being another example of that. This was probably a small change Ken made in that time period that either he forgot to tell me because it seemed so trivial at the time or he told me and I forgot... because it seemed so trivial at the time.

@outpaddling
Copy link
Contributor Author

No worries, just trying to help home in on the cause. I'm very happy to see development resumed and will do my best to provide detailed information on the issues I encounter.

@outpaddling
Copy link
Contributor Author

I see there's some screensaver code in the lumina sources:

<<<ROOT@moray.acadix>>> /usr/ports/x11/lumina-core 1021 # find work/lumina-1.6.2/ -name '*screensaver*'
work/lumina-1.6.2/icon-theme/material-design-dark/applications/preferences-desktop-screensaver.svg
work/lumina-1.6.2/icon-theme/material-design-light/applications/preferences-desktop-screensaver.svg
work/lumina-1.6.2/src-qt5/core/lumina-desktop-unified/defaults/desktop/screensaver.conf
work/lumina-1.6.2/src-qt5/core/lumina-desktop-unified/extrafiles/screensavers
work/lumina-1.6.2/src-qt5/core/lumina-desktop-unified/src-screensaver
work/lumina-1.6.2/src-qt5/core/lumina-desktop-unified/src-screensaver/screensaver.pri
work/lumina-1.6.2/src-qt5/core/lumina-desktop/extrafiles/screensavers
work/lumina-1.6.2/src-qt5/core/lumina-desktop/src-screensaver
work/lumina-1.6.2/src-qt5/core/lumina-desktop/src-screensaver/screensaver.pri
work/lumina-1.6.2/src-qt5/src-cpp/plugins-screensaver.cpp
work/lumina-1.6.2/src-qt5/src-cpp/plugins-screensaver.h

Might there be a simple way to disable the new screensaver until it's fully integrated? We could just patch the FreeBSD port and keep the xscreensaver dependency for now if a new release is not coming soon.

@outpaddling
Copy link
Contributor Author

outpaddling commented Feb 23, 2022

I see a bunch of commits by Ken in April 2020, after the 1.6.0 release.

The first couple of them:

commit bf545b933bcb59a695702ecfcc7b1fa5f07fa557
Author: Ken Moore <moorekou@gmail.com>
Date:   Fri Apr 24 17:53:28 2020 -0400

    Initial merge of the screensaver into the main lumina-desktop builds

commit 297bf0a1bd4c38dff059d3aa131426d4337f3af1
Author: Ken Moore <moorekou@gmail.com>
Date:   Fri Apr 24 17:50:05 2020 -0400

    Disable xscreensaver from auto-start.
    Enable lumina-checkpass

The question now is how to configure it. There does not appear to be an interface in Settings.
The default screensaver uses 400% CPU at times and I would really like to change it to blank screen only and put the monitor to sleep if possible.
Or just disable it and use xscreensaver for now.

@q5sys
Copy link
Member

q5sys commented Feb 23, 2022 via email

@outpaddling
Copy link
Contributor Author

Sounds good. Can you provide some guidance on how we might patch it out in the current version? We can just hack the FreeBSD port until the next release.

@q5sys
Copy link
Member

q5sys commented Feb 23, 2022 via email

@outpaddling
Copy link
Contributor Author

So, there appears to be an identical copy under lumina-desktop:

<<<ROOT@moray.acadix>>> /usr/ports/wip/lumina-core 1007 # find work/ -name '*saver*'
work/lumina-1.6.2/icon-theme/material-design-dark/applications/preferences-desktop-screensaver.svg
work/lumina-1.6.2/icon-theme/material-design-light/applications/preferences-desktop-screensaver.svg
work/lumina-1.6.2/src-qt5/core/lumina-desktop-unified/defaults/desktop/screensaver.conf
work/lumina-1.6.2/src-qt5/core/lumina-desktop-unified/extrafiles/screensavers
work/lumina-1.6.2/src-qt5/core/lumina-desktop-unified/src-screensaver
work/lumina-1.6.2/src-qt5/core/lumina-desktop-unified/src-screensaver/screensaver.pri
work/lumina-1.6.2/src-qt5/core/lumina-desktop/extrafiles/screensavers
work/lumina-1.6.2/src-qt5/core/lumina-desktop/src-screensaver
work/lumina-1.6.2/src-qt5/core/lumina-desktop/src-screensaver/screensaver.pri
work/lumina-1.6.2/src-qt5/src-cpp/plugins-screensaver.cpp
work/lumina-1.6.2/src-qt5/src-cpp/plugins-screensaver.h
<<<ROOT@moray.acadix>>> /usr/ports/wip/lumina-core 1008 # ls work/lumina-1.6.2/src-qt5/core/lumina-desktop-unified/src-screensaver
LLockScreen.cpp   LScreenSaver.cpp  SSBaseWidget.h
LLockScreen.h     LScreenSaver.h    animations/
LLockScreen.ui    SSBaseWidget.cpp  screensaver.pri
<<<ROOT@moray.acadix>>> /usr/ports/wip/lumina-core 1009 # ls work/lumina-1.6.2/src-qt5/core/lumina-desktop/src-screensaver/
LLockScreen.cpp   LScreenSaver.cpp  SSBaseWidget.h
LLockScreen.h     LScreenSaver.h    animations/
LLockScreen.ui    SSBaseWidget.cpp  screensaver.pri

I'll first try commenting out the "include(src-screensaver/screensaver.pri)" in src-qt5/core/lumina-desktop/lumina-desktop.pro and if that works, give it a good testing period.

@outpaddling
Copy link
Contributor Author

Not so simple...
The LScreenSaver class is integrated into LSession.cpp, LSession.h, and SystemWindow.cpp. I was able to build after commenting out all the references in these 3 files, but then xscreensaver doesn't work either.
Funny thing is, both screensavers launch without these patches.
I wonder if it would be a better use of time to move forward and finish the integration of LScreenSaver than to try and roll this back. It seems to work fine, except for the inability to configure it and maybe lack of a blank screen / power saver option.

@q5sys
Copy link
Member

q5sys commented Feb 24, 2022

LScreenSaver needs lumina-checkpass to work, and it doesn't. You can unlock the desktop by simply hitting enter... which doesn't make for a very good screensaver lock.
But if we can get that functioning properly, then I'm fine with making this the default and having xscreensaver as the optional screensaver.
Edit:
All you should need to do to disable the Lscreensaver should be to comment out https://github.com/lumina-desktop/lumina/blob/master/src-qt5/core/lumina-desktop/LSession.cpp#L240 - L242
"Should" being the key word there. lol

@outpaddling
Copy link
Contributor Author

Oh yeah, I see that it ignores the password now. ;-) If rolling back to xscreensaver is easier, that would be fine as well. I see some of xscreensaver code commented out in 1.6.2, so maybe that just needs to be restored along with disabling LScreensaver.

@outpaddling
Copy link
Contributor Author

FYI, I took a crack at rolling back to xscreensaver and failed. It appears that the xscreensaver code was commented out in some places and completely removed in others. I think we would have to review past commits to see what was removed and there could still be other issues. So based on my limited understanding of the code, I'd be inclined to move forward with LScreensaver. Be reminded that I don't know the code well at all, so my impression that moving forward will be easier could be wrong. Even so, I think it would be a better use of precious man-hours.

@outpaddling
Copy link
Contributor Author

I think the only urgent problem in terms of moving forward with LScreensaver is password validation. If we have a working screensaver that actually requires a password to unlock the console, then at least it's usable and secure. Then there would be little reason to consider rolling back to xscreensaver.
Integrating LScreensaver into the settings menu is very important, of course, but not as critical.
Do you have a general idea what remains to get password authentication working?

@outpaddling
Copy link
Contributor Author

outpaddling commented Mar 3, 2022

The code for validating passwords to unlock the screen was already there, but disabled. It just needed a few fixes to get it working. I also cleaned up a bit to improve readability and eliminate a dangerous atoi() call. I commented out the chmod 4555 for lumina-checkpass since it wasn't working, and this needs to be done via pkg-plist in FreeBSD ports anyway.

--- core.pro.orig       2022-03-03 00:56:25 UTC
+++ core.pro
@@ -10,8 +10,8 @@ SUBDIRS+= lumina-desktop \
        lumina-info \
        lumina-pingcursor \
        $${PWD}/../../icon-theme \
-       lumina-theme-engine 
-#      lumina-checkpass
+       lumina-theme-engine \
+       lumina-checkpass
 #      lumina-desktop-unified
 
 #Also install any special menu scripts
--- lumina-checkpass/lumina-checkpass.pro.orig  2021-12-26 02:33:45 UTC
+++ lumina-checkpass/lumina-checkpass.pro
@@ -13,6 +13,7 @@ LIBS     += -lpam
 SOURCES += main.c
 
 perms.path = $$DESTDIR$${PREFIX}/sbin
-perms.extra = "chmod 4555 $$DESTDIR$${PREFIX}/sbin/lumina-checkpass"
+# FIXME: This does not work: DESTDIR is blank
+# perms.extra = "chmod 4555 $$DESTDIR$${PREFIX}/sbin/lumina-checkpass"
 
 INSTALLS += target perms
--- lumina-checkpass/main.c.orig        2021-12-26 02:33:45 UTC
+++ lumina-checkpass/main.c
@@ -18,11 +18,14 @@
 #include <stdio.h>     // Usage output
 #include <pwd.h>               // User DB information
 #include <string.h>
+#include <sysexits.h>
 
 //PAM/security libraries
 #include <sys/types.h>
 #include <security/pam_appl.h>
 
+#define        AUTH_FAILED     1
+
 //Found this little snippet from SDDM - nice alternative to using the entire openpam library from FreeBSD
 static int PAM_conv(
        int num_msg,
@@ -30,18 +33,19 @@ static int PAM_conv(
        struct pam_response **resp,
        void *ctx)
 {
-       return 0;
+       return PAM_SUCCESS;
 }
 //-----
 
 
 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");
+    fputs("lumina-checkpass: Simple user-level check for password validity (for screen unlockers and such).", stderr);
+    fputs("Usage:", stderr);
+    //fputs("  lumina-checkpass <password>", stderr);
+    fputs("  lumina-checkpass -fd <file descriptor>", stderr);
+    fputs("  lumina-checkpass -f <file path>", stderr);
+    fputs("Returns: 0 for a valid password, 1 for invalid", stderr);
+    exit(AUTH_FAILED); // FIXME: Switch to EX_USAGE, or do callers depend on 1?
 }
 
 int main(int argc, char** argv){
@@ -49,13 +53,20 @@ int main(int argc, char** argv){
   if(argc!=3){
     //Invalid inputs - show the help text
     showUsage();
-    return 1;
   }
-  char*pass = 0;
+  char *pass = NULL;
   if(argc==3 && 0==strcmp(argv[1],"-fd") ){
-    FILE *fp = fdopen(atoi(argv[2]), "r");
+    // This replaces dangerous atoi(), which does no validation
+    char *end;
+    int fd = strtol(argv[2], &end, 10);
+    if ( *end != '\0' )
+    {
+      fprintf(stderr, "Invalid file descriptor: %s\n", argv[2]);
+      showUsage();
+    }
+    FILE *fp = fdopen(fd, "r");
     size_t len;
-    if(fp!=0){
+    if(fp!=NULL){
       ssize_t slen = getline(&pass, &len, fp);
       if(pass[slen-1]=='\n'){ pass[slen-1] = '\0'; }
     }
@@ -63,26 +74,25 @@ int main(int argc, char** argv){
   }else if(argc==3 && 0==strcmp(argv[1],"-f") ){
     FILE *fp = fopen(argv[2], "r");
     size_t len;
-    if(fp!=0){
+    if(fp!=NULL){
       ssize_t slen = getline(&pass, &len, fp);
       if(pass[slen-1]=='\n'){ pass[slen-1] = '\0'; }
     }else{
-      puts("[ERROR] Unknown option provided");
-      puts("----------------");
+      fputs("[ERROR] Unknown option provided", stderr);
+      fputs("----------------", stderr);
       showUsage();
-      return 1;
     }
     fclose(fp);
   }
-  if(pass == 0){ puts("Could not read password!!"); return 1; } //error in reading password
+  if(pass == NULL){ fputs("Could not read password!!", stderr); return AUTH_FAILED; } //error in reading password
   //puts("Read Password:");
   //puts(pass);
   //Validate current user (make sure current UID matches the logged-in user,
   char* cUser = getlogin();
-  struct passwd *pwd = 0;
+  struct passwd *pwd = NULL;
   pwd = getpwnam(cUser);
-  if(pwd==0){ return 1; } //Login user could not be found in the database? (should never happen)
-  if( getuid() != pwd->pw_uid ){ return 1; } //Current UID does not match currently logged-in user UID
+  if(pwd==NULL){ return AUTH_FAILED; } //Login user could not be found in the database? (should never happen)
+  if( getuid() != pwd->pw_uid ){ return AUTH_FAILED; } //Current UID does not match currently logged-in user UID
   //Create the non-interactive PAM structures
   pam_handle_t *pamh;
   struct pam_conv pamc = { &PAM_conv, 0 };
@@ -92,15 +102,15 @@ int main(int argc, char** argv){
 #else
     int ret = pam_start( "system-auth", cUser, &pamc, &pamh);
 #endif
-    if(ret != PAM_SUCCESS){ puts("Could not initialize PAM"); return 1; } //could not init PAM
+    if(ret != PAM_SUCCESS){ fputs("Could not initialize PAM", stderr); return AUTH_FAILED; } //could not init PAM
     //char* cPassword = argv[1];
     ret = pam_set_item(pamh, PAM_AUTHTOK, pass);
-    if(ret != PAM_SUCCESS){ puts("Could not set conversation structure"); }
+    if(ret != PAM_SUCCESS){ fputs("Could not set conversation structure", stderr); }
     //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
     //Stop the PAM instance
     pam_end(pamh,ret);
   //return verification result
-  return ((ret==PAM_SUCCESS) ? 0 : 1);
+  return ret == PAM_SUCCESS ? EX_OK : AUTH_FAILED;
 }

@q5sys
Copy link
Member

q5sys commented Mar 3, 2022 via email

@outpaddling
Copy link
Contributor Author

outpaddling commented Mar 3, 2022

Seems to work fine for me since I worked around the lumina-checkpass.pro issue and set the SUID via pkg-plist. The main problem was that $$DESTDIR came out blank, so the chmod didn't work. I'll report back if I encounter any problems.

Also, it seems that the screensaver starts out in active mode, but drops to blank screen at some point later, so energy usage is not much of an issue. Given that, integrating LScreensaver into settings is even less urgent than I originally thought.

@q5sys
Copy link
Member

q5sys commented Mar 14, 2022

I ran into a problem with this patch working, but that may have been a result of something on that system. I've been needing to do a clean nuke&pave of it anyway. So once I get that system re-installed I'll try your patch again.
Before I merge it in, I need to make sure the changes work on both Linux and BSD. I dont see why they wouldn't... but until I can get it to work on the linux side I dont want to merge that into the version branch.

@outpaddling
Copy link
Contributor Author

Certainly you'll want to test it thoroughly before merging. I haven't had any problems with it, but if there's one thing I've learned from decades of coding, it's that testing on one platform is never sufficient, no matter how small the change. I test all my own code on FreeBSD, Mac, Linux, and NetBSD, though I don't have the means to do that with Lumina patches.

Maybe also figure out why DESTDIR is blank, though solving that won't be useful for FreeBSD, since the ports system doesn't allow upstream build systems to set SUID anyway.

@Clockwork6400
Copy link
Contributor

Already suggested throwing out the screensaver and screen blocker from lumina? I'm not sure that they are needed, especially without the ability to configure and disable.

@outpaddling
Copy link
Contributor Author

The Lumina screensaver actually works better than xscreensaver. The only issue is not having a configuration interface, which I don't think will be difficult to fix.

@outpaddling
Copy link
Contributor Author

outpaddling commented Jan 9, 2023

Starting this summer I should have more time to dig into Lumina issues and learn what's necessary to patch up some of the issues.

One thing that would be valuable in the short term would be a blank-screen only option. Since the existing screensavers use a lot of CPU time, I would like to patch the Lumina FreeBSD port to just blank the screen instead. I know very little about QT programming at the moment, though. Anyone know how to create a blank screen option in the JSON/QML files? Here's an example of one of the existing screensavers:

https://github.com/lumina-desktop/lumina/blob/master/src-qt5/core/lumina-desktop/extrafiles/screensavers/Fireflies.json

https://github.com/lumina-desktop/lumina/blob/master/src-qt5/core/lumina-desktop/extrafiles/screensavers/qml_scripts/Fireflies.qml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants