LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 10-02-2016, 10:33 PM   #16
mfoley
Senior Member
 
Registered: Oct 2008
Location: Columbus, Ohio USA
Distribution: Slackware
Posts: 2,555

Original Poster
Rep: Reputation: 177Reputation: 177

More experimentation woes ... As I mentioned earlier, my custom kcheckpass script is called with arguments "-m -S 14". if I run ./kcheckpass -h on the real program I get:
Code:
usage: kcheckpass {-h|[-c caller] [-m method] [-U username|-S handle]}
  options:
    -h           this help message
    -U username  authenticate the specified user instead of current user
    -S handle    operate in binary server mode on file descriptor handle
    -c caller    the calling application, effectively the PAM service basename
    -m method    use the specified authentication method (default: "classic")
  exit codes:
    0 success
    1 invalid password
    2 cannot read password database
    Anything else tells you something's badly hosed.
I thought this might be a bit of a breakthrough since I am being passed "-S 14" and therefore perhaps am being delivered the password in descriptor 14. So I tried:
Code:
echo fd $fd >>/tmp/kcheckpass.out
read -t 20 -u 14 pw
echo pw "$pw" >>/tmp/kcheckpass.out
But again, nothing. It hangs (actually, times out in 20 seconds). Is it possible I'm not doing this right for operating "in binary server mode on file descriptor handle"? If I could just read the password ... !
 
Old 10-03-2016, 03:22 AM   #17
mfoley
Senior Member
 
Registered: Oct 2008
Location: Columbus, Ohio USA
Distribution: Slackware
Posts: 2,555

Original Poster
Rep: Reputation: 177Reputation: 177
OK, I've come up with a solution!!! As I mentioned before, kcheckpass is passed the args "-m -S 14" on the command line. I downloaded the kde-workspace-4.11.22 sources for 14.2 and examined kcheckpass.c to see what it does with this file descriptor. It turns out that whatever program launches it (presumably kscreenlocker_greet) first expects to receive some info on fd 14 before it will cough up the password entered by the user. What it expects is a binary '2' followed by a binary '0'. Here's why (if you care).

kcheckpass calls Authenticate((method, login, *(*conv) (ConvRequest, const char *)). Depending on how kcheckpass.c is compiled/linked, that function will be in checkpass_etcpasswd.c, checkpass_pam.c, checkpass_shadow.c and a couple of others.

Using the non-PAM checkpass_etcpasswd.c as an example, Authenticate() in that program will call kcheckpass.c:conv_server (ConvRequest what, const char *prompt) ... where ConvRequest (type of request) = ConvGetHidden = 2, and prompt is passed as zero value (i.e. no prompt).

conv_server() will write the ConvRequest (int 2) as binary int to the specified file descriptor, followed by the binary int length of the prompt (zero). In other words, it writes an int 2 followed by an int 0 to the file descriptor (which always happens to be 14 in my testing).

conv_server() will then read from the file descriptor the binary length of the password string, then it will read the string value itself. The real kcheckpass continues to perform the validation.

Here's my bash replacement for kcheckpass (I've renamed the real one to kcheckpass.kde):
Code:
#!/bin/bash

# Determine if the user is a domain user or local user

x=`wbinfo -u | grep $USER`

# If a local user, run the standard kcheckpass

if [ -z "$x" ]
then
    `dirname $0`/kcheckpass.kde $*
    rc=$?
    exit $rc
fi

# get the file descriptor for retrieving the password
# This will be a command line argument "-S <fd>"

while [ 1 == 1 ]
do
  if [ -z "$1" ]        # no more args, bad!
  then
      exit 4
  fi

  x=`echo $1 | cut -c1-2`

  if [ "$x" = "-S" ]    # found the file descriptor parameter
  then
      fd="$2"
      break
  fi

  shift
done

# Now, get password entered by user

passwd=`$(dirname $0)/getkcheckPW $fd`

# Authenticate
ntlm_auth --username="$USER" --password="$passwd"
rc=$?

exit $rc
That script should be fairly self-explanatory. The only real wrinkle is that binary data is exchanged on the file descriptor which is a bit tricky in a shell script. I tried `echo 2000000000000000 | xxd -r -p >&14` and had limited success. Perhaps some shell guru out there can do better?

In the meantime, I did it rather simply in C.
getkcheckPW.c:
Code:
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>

main(int argc, char *argv[])
{
    int fd;                     /* file descriptor */
    int convGetHidden = 2;      /* code give to (presumably) kscreenlocker_greet for type of Request */
    int cnt;
    int l;                      /* length of password */
    char passwd[80];            /* buffer to hold returned password */

    if (argc < 2) exit(-1);     /* expecting file descriptor as arg */
    fd = atoi(argv[1]);

    write(fd, &convGetHidden, sizeof(convGetHidden));   /* conv_server type of Request */

    /* kcheckpass.c sends a prompt of zero length for convGetHidden */
    cnt = 0;
    write(fd, &cnt, sizeof(cnt));

    cnt = read(fd, &l, sizeof(l));      /* Get length of entered password */
    cnt = read(fd, passwd, l);          /* Get password */
    printf("%s\n", passwd);
    exit(0);
}
This solution lets me change out the one kcheckpass command without having to rebuild KDE for PAM; which lets me keep slackpkg blacklisting to a minimum. Of course, it could be convincingly argued that this scrpt and C program are possibly MORE complex that rebuilding KDE! For now, I'll continue testing this solution and play around with KDE rebuilding later.

Ivandi, if you've got some ideas on my possible foreground/background issue so I can see the lightdm login screen, I'd much rather go that route and have change basically nothing.

Last edited by mfoley; 10-03-2016 at 10:22 AM.
 
  


Reply

Tags
desktop access, kde, locking



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
kde desktop lock screen sachin.davra Linux - Newbie 3 01-21-2014 08:49 AM
Disable lock session (lock screen) when switch user in KDE 4.x Murz Linux - Desktop 4 12-01-2010 08:28 AM
cant find a minimized window on the task bar on mandriva KDE desktop salomeq Linux - Desktop 4 08-28-2010 10:16 AM
[SOLVED] How to find and display the kernel version booted into, with the KDE 4.3.5 desktop? james2b Linux - Newbie 6 03-23-2010 02:45 PM
KDE Control Module - Can't find a player to hear sounds texarse Mandriva 1 01-22-2004 06:43 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 07:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration