diff --git a/kcheckpass/kcheckpass.c b/kcheckpass/kcheckpass.c index 5cb95da51..f45a6352d 100644 --- a/kcheckpass/kcheckpass.c +++ b/kcheckpass/kcheckpass.c @@ -1,248 +1,248 @@ /***************************************************************** * * kcheckpass - Simple password checker * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * * kcheckpass is a simple password checker. Just invoke and * send it the password on stdin. * * If the password was accepted, the program exits with 0; * if it was rejected, it exits with 1. Any other exit * code signals an error. * * It's hopefully simple enough to allow it to be setuid * root. * * Compile with -DHAVE_VSYSLOG if you have vsyslog(). * Compile with -DHAVE_PAM if you have a PAM system, * and link with -lpam -ldl. * Compile with -DHAVE_SHADOW if you have a shadow * password system. * * Copyright (C) 1998, Caldera, Inc. * Released under the GNU General Public License * * Olaf Kirch General Framework and PAM support * Christian Esken Shadow and /etc/passwd support * * Other parts were taken from kscreensaver's passwd.cpp. * *****************************************************************/ #include "kcheckpass.h" #include #include #include #include #include #include #include #ifndef __FreeBSD__ #include #endif #include #include #include /* Define this if you want kcheckpass to accept options * (They don't do anything useful right now) */ #undef ACCEPT_OPTIONS /***************************************************************** * Set to 1 if stdin is a tty *****************************************************************/ static int havetty = 0; #ifdef ACCEPT_OPTIONS static int debug = 0; #endif /***************************************************************** * Output a message to syslog (and to stderr as well, if available) *****************************************************************/ void message(const char *fmt, ...) { va_list ap; va_start(ap, fmt); if (havetty) { vfprintf(stderr, fmt, ap); } else { #ifndef HAVE_VSYSLOG char buffer[1024]; /* Not sure what's less portable -- vsyslog or * vsnprintf :-/ */ #ifdef HAVE_VSNPRINTF vsnprintf(buffer, sizeof(buffer), fmt, ap); #else vsprintf(buffer, fmt, ap); #endif syslog(LOG_NOTICE, buffer); #else vsyslog(LOG_NOTICE, fmt, ap); #endif } } /***************************************************************** * Usage message *****************************************************************/ static void usage(int exitval) { - message("usage: kcheckpass %s\n" + message("usage: kde1-kcheckpass %s\n" " Obtains the password from standard input and checks it\n" " against that of the invoking user.\n" " Exit codes:\n" " 0 success\n" " 1 invalid password\n" " 2 cannot read password database\n" " Anything else tells you something's badly hosed.\n", #ifdef ACCEPT_OPTIONS " [-dh]" #else "" #endif ); exit(exitval); } /***************************************************************** * Main program *****************************************************************/ int main(int argc, char **argv) { char *login, passbuffer[1024], *passwd; struct passwd *pw; int status, c; uid_t uid; int passlen; - openlog("kcheckpass", LOG_PID, LOG_AUTH); + openlog("kde1-kcheckpass", LOG_PID, LOG_AUTH); #ifdef HAVE_OSF_C2_PASSWD initialize_osf_security(argc, argv); #endif /* Make sure stdout/stderr are open */ for (c = 1; c <= 2; c++) { if (fcntl(c, F_GETFL) == -1) { int nfd; if ((nfd = open("/dev/null", O_WRONLY)) < 0) { message("cannot open /dev/null: %s\n", strerror(errno)); exit(10); } if (c != nfd) { dup2(nfd, c); close(nfd); } } } havetty = isatty(0); #ifndef ACCEPT_OPTIONS if (argc != 1) usage(10); #else while ((c = getopt(argc, argv, "d")) != -1) { switch (c) { case 'd': debug = 1; break; case 'h': usage(0); default: message("Unknown option %c\n", c); usage(10); } } #endif uid = getuid(); if (!(pw = getpwuid(uid))) { message("Unknown user (uid %d)\n", uid); exit(10); } if ((login = strdup(pw->pw_name)) == NULL) { message("Out of memory on strdup'ing user name \"%.100s\"\n", pw->pw_name); exit(10); } /* If we have a tty, use getpass. * Otherwise, just snarf the password from stdin (we don't * want getpass to blurt anything to stderr). */ passwd = 0; if (havetty) { passwd = getpass("Password: "); passlen = strlen(passwd); } else { passlen = read(0, passbuffer, sizeof(passbuffer)-1); if (passlen >= 0) { passbuffer[passlen] = '\0'; if (passlen >= 1 && passbuffer[passlen-1] == '\n') passbuffer[--passlen] = '\0'; passwd = passbuffer; } } if (passwd == 0) { message("Can't read password: %s\n", strerror(errno)); exit(10); } /* Now do the fandango */ status = authenticate(login, passwd); /* Clear password buffer */ memset(passbuffer, 0, sizeof(passbuffer)); if ( status == 0 ) { /* failure */ if ( passlen > 0 ) { /* Only write to logfile, if a password was entered. Otherwise the logfile will clutter up with irrelevant messages. */ time_t now = time(NULL); message("authentication failure for user %s [uid %d]\n", login, uid); do { sleep (1); /* <<< Security: Don't undermine the shadow system */ } while (time(NULL) < now + 1); exit(1); } else exit(1); } if ( status == 2 ) { /* Cannot read password database (e.g. not SUID on shadow systems) */ exit(2); } exit(0); } /***************************************************************** The real authentication methods are in separate source files. Look in checkpass_*.cpp *****************************************************************/ diff --git a/kscreensaver/main.cpp b/kscreensaver/main.cpp index 69a1e02e2..10d966e0a 100644 --- a/kscreensaver/main.cpp +++ b/kscreensaver/main.cpp @@ -1,699 +1,699 @@ //----------------------------------------------------------------------------- // // Screen savers for KDE // // Copyright (c) Martin R. Jones 1996 // #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "xautolock.h" #include "saver.h" #include "main.h" #include "main.moc" #include KLocale *glocale; extern "C" { extern void startScreenSaver( Drawable d ); extern void stopScreenSaver(); extern int setupScreenSaver(); extern const char *getScreenSaverName(); extern void exposeScreenSaver( int x, int y, int width, int height ); } extern void initPasswd(); int mode = MODE_NONE; static bool lock = false, passOk = false; static bool canGetPasswd; static bool lockOnce = false; static bool only1Time = false; static int xs_timeout, xs_interval, xs_prefer_blanking, xs_allow_exposures; static QString pidFile; static KPasswordDlg *passDlg = NULL; static QWidget *saverWidget = NULL; static int desktopWidth = 0, desktopHeight = 0; extern char *ProgramName; extern Bool allowroot; static bool grabInput( QWidget *w ); static void releaseInput(); static void destroySaverWindow( QWidget *w ); static void lockNow( int ); static void cleanup( int ); static void catchSignals(); static void usage( char *name ); ssApp *globalKapp; //---------------------------------------------------------------------------- ssApp::ssApp( int &argc, char **argv ) : KApplication( argc, argv ) { KConfig kssConfig( kapp->kde_configdir() + "/kssrc", kapp->localconfigdir() + "/kssrc" ); kssConfig.setGroup( "kss" ); stars = kssConfig.readBoolEntry( "PasswordAsStars", true ); } bool ssApp::x11EventFilter( XEvent *event ) { if ( passDlg ) // pass key presses to password dialog { if ( event->type == KeyPress ) { XKeyEvent *xke = (XKeyEvent *) event; int key = 0; KeySym keysym = 0; XComposeStatus compose; char buffer[2] = ""; XLookupString( xke, buffer, 1, &keysym, &compose ); switch ( keysym ) { case XK_BackSpace: key = Key_Backspace; break; case XK_Return: key = Key_Return; break; case XK_Escape: key = Key_Escape; break; } if ( buffer[0] != '\0' || key != 0 ) { QKeyEvent qke( Event_KeyPress, key, buffer[0], 0 ); passDlg->keyPressed( &qke ); } return TRUE; } return FALSE; } if ( mode == MODE_INSTALL || mode == MODE_TEST ) { if ( (event->type == KeyPress || event->type == ButtonPress || event->type == MotionNotify ) && !passDlg ) { if ( !canGetPasswd || (!lock && !lockOnce) ) qApp->exit_loop(); else { passDlg = new KPasswordDlg( saverWidget, stars ); connect(passDlg, SIGNAL(passOk()), SLOT(slotPassOk())); connect(passDlg, SIGNAL(passCancel()), SLOT(slotPassCancel())); passDlg->move( (desktopWidth - passDlg->width())/2, (desktopHeight - passDlg->height())/2 ); passDlg->show(); } return TRUE; } else if ( event->type == VisibilityNotify ) { if ( event->xvisibility.state != VisibilityUnobscured) { if ( !passDlg ) { saverWidget->raise(); QApplication::flushX(); } } } else if ( event->type == ConfigureNotify ) { if ( !passDlg ) { saverWidget->raise(); QApplication::flushX(); } } else if ( event->type == Expose ) { if (!passDlg) { exposeScreenSaver( event->xexpose.x, event->xexpose.y, event->xexpose.width, event->xexpose.height ); } } } return FALSE; } void ssApp::slotPassOk() { passOk = TRUE; passDlg->hide(); QApplication::flushX(); delete passDlg; passDlg = NULL; qApp->exit_loop(); QApplication::flushX(); } void ssApp::slotPassCancel() { passOk = FALSE; passDlg->hide(); QApplication::flushX(); delete passDlg; passDlg = NULL; grabInput( saverWidget ); QApplication::flushX(); } //---------------------------------------------------------------------------- static bool grabInput( QWidget *w) { int rv = XGrabKeyboard( qt_xdisplay(), QApplication::desktop()->winId(), True, GrabModeAsync, GrabModeAsync, CurrentTime ); if (rv == AlreadyGrabbed) { return false; } rv = XGrabPointer( qt_xdisplay(), QApplication::desktop()->winId(), True, ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask | PointerMotionHintMask | Button1MotionMask | Button2MotionMask | Button3MotionMask | Button4MotionMask | Button5MotionMask | ButtonMotionMask | KeymapStateMask, GrabModeAsync, GrabModeAsync, None, w->cursor().handle(), CurrentTime ); if (rv == AlreadyGrabbed) { return false; } return true; } static void releaseInput() { XUngrabKeyboard( qt_xdisplay(), CurrentTime ); XUngrabPointer( qt_xdisplay(), CurrentTime ); } static QWidget *createSaverWindow() { QWidget *w; // WStyle_Customize sets override_redirect w = new QWidget( NULL, "", WStyle_Customize | WStyle_NoBorder ); /* set NoBackground so that the saver can capture the current * screen state if necessary */ w->setBackgroundMode( QWidget::NoBackground ); XSetWindowAttributes attr; attr.event_mask = KeyPressMask | ButtonPressMask | MotionNotify | VisibilityChangeMask | ExposureMask; // | StructureNotifyMask; XChangeWindowAttributes(qt_xdisplay(), w->winId(), CWEventMask, &attr); QBitmap bm( 1, 1, TRUE ); QCursor c( bm, bm ); w->setCursor( c ); if (grabInput( w ) == false) { // The grab failed - we can't save the window now. destroySaverWindow(w); w = 0; } return w; } static void destroySaverWindow( QWidget *w ) { releaseInput(); delete w; } //---------------------------------------------------------------------------- static QString lockName(QString s) { // note that changes in the pidFile name have also to be done // in kdebase/kcontrol/display/scrnsave.cpp QString name = getenv( "HOME" ); name += "/.kss-" + s + ".pid."; char ksshostname[200]; gethostname(ksshostname, 200); name += ksshostname; return name; } static int getLock(QString type) { QString lockFile = lockName(type); int pid = -1; FILE *fp; if ( (fp = fopen( lockFile, "r" ) ) != NULL ) { fscanf( fp, "%d", &pid ); fclose( fp ); } return pid; } static void killProcess(int pid) { if ( pid != getpid() && pid > 1 ) { if( kill( pid, SIGTERM ) == 0 ) sleep(1); } } static void setLock(QString type) { FILE *fp; pidFile = lockName(type); int pid = getLock( type ); killProcess( pid ); if ( (fp = fopen( pidFile, "w" ) ) != NULL ) { // on some systems it's long, on some int, so a cast may help fprintf( fp, "%ld\n", static_cast(getpid()) ); fclose( fp ); } } -/* Verify, if kcheckpass is able to verify passwords. +/* Verify, if kde1-kcheckpass is able to verify passwords. * I cannot use KProcess here, as it needs ProcessEvents */ static bool canReadPasswdDatabase() { KProcess chkpass; QString kcp_binName = ""; kcp_binName += KApplication::kde_bindir(); - kcp_binName += "/kcheckpass"; + kcp_binName += "/kde1-kcheckpass"; chkpass.clearArguments(); chkpass << kcp_binName; bool ret = chkpass.start(KProcess::DontCare, KProcess::Stdin); if (ret == false) return false; chkpass.closeStdin(); int timeout = 1000; while ( timeout != 0 ) { if (! chkpass.isRunning() ) break; else { globalKapp->processEvents(); timeout--; usleep(10000); } } int canRead = ( chkpass.normalExit() && (chkpass.exitStatus() != 2) ); return canRead; } //---------------------------------------------------------------------------- int main( int argc, char *argv[] ) { srand( getpid() ); /* seed the random generator */ // drop root privileges temporarily #ifdef HAVE_SETEUID seteuid(getuid()); #else setreuid(-1, getuid()); #endif // HAVE_SETEUID Window saveWin = 0; int timeout = 600; ProgramName = argv[0]; ssApp a( argc, argv ); globalKapp = &a; glocale = new KLocale("klock"); if ( argc == 1 ) usage( argv[0] ); enum parameter_code { install, setup, preview, inroot, test, delay, arg_lock, corners, descr, arg_nice, help, allow_root, unknown } parameter; char *strings[] = { "-install", "-setup", "-preview", "-inroot", "-test", "-delay", "-lock", "-corners", "-desc", "-nice", "--help", "-allow-root", 0 }; int i = 1; while ( i < argc) { parameter = unknown; for ( int p = 0 ; strings[p]; p++) if ( !strcmp( argv[i], strings[p]) ) { parameter = static_cast(p); break; } /* if it's the last one, check if we expect a value: */ if( i >= (argc-1) ) { switch (parameter) { case preview: case delay: case corners: case arg_nice: usage( argv[0] ); // won't return break; default: break; } } switch (parameter) { case install: mode = MODE_INSTALL; break; case setup: mode = MODE_SETUP; break; case preview: mode = MODE_PREVIEW; saveWin = atol( argv[++i] ); break; case inroot: mode = MODE_PREVIEW; saveWin = kapp->desktop()->winId(); break; case test: mode = MODE_TEST; break; case delay: timeout = atoi( argv[++i] ) * 60; if( timeout == 0 ) only1Time = true; else if( timeout < 60 ) timeout = 60; break; case arg_lock: lock = TRUE; break; case corners: setCorners( argv[++i] ); break; case descr: printf( "%s\n", getScreenSaverName() ); exit( 0 ); case arg_nice: #ifdef HAVE_NICE nice( atoi( argv[++i] ) ); #else warning(glocale->translate( "Option %s is not support on " "this plattform!"), strings[arg_nice]); #endif break; case allow_root: allowroot = 1; break; case help: usage( argv[0] ); break; default: // unknown debug("unknown parameter"); break; } i++; } // regain root privileges #ifdef HAVE_SETEUID seteuid(0); #else setreuid(-1, 0); #endif // HAVE_SETEUID initPasswd(); // ... and drop them again before doing anything important setuid(getuid()); // now check, if I can verify passwords (might be a problem // only with shadow passwords, due to missing SUID on - // kcheckpass program. + // kde1-kcheckpass program. #ifdef HAVE_SHADOW canGetPasswd = canReadPasswdDatabase(); #else canGetPasswd = true; #endif // Get the size of the desktop XWindowAttributes attr; if (XGetWindowAttributes(qt_xdisplay(), RootWindow(qt_xdisplay(), qt_xscreen()), &attr) == 0) { debug("Failed getting Root window size"); } else { desktopWidth = attr.width; desktopHeight = attr.height; } catchSignals(); if ( mode == MODE_INSTALL ) { if (!canGetPasswd && lock) { QString tmp = glocale->translate( "Warning: You won't be able to lock the screen!\n\n" "Your system uses shadow passwords.\n" "Please contact your system administrator.\n" - "Tell him that you need suid for the kcheckpass program!"); + "Tell him that you need suid for the kde1-kcheckpass program!"); KMsgBox::message(NULL, glocale->translate("Shadow Passwords"), tmp, KMsgBox::EXCLAMATION); } setLock("install"); XGetScreenSaver( qt_xdisplay(), &xs_timeout, &xs_interval, &xs_prefer_blanking, &xs_allow_exposures ); XSetScreenSaver( qt_xdisplay(), 0, xs_interval, xs_prefer_blanking, xs_allow_exposures ); initAutoLock(); while ( 1 ) { if ( waitTimeout( timeout ) == FORCE_LOCK ) lockOnce = TRUE; // if another saver is in test-mode, kill it killProcess(getLock("test")); saverWidget = createSaverWindow(); if (saverWidget) { saverWidget->setFixedSize(desktopWidth, desktopHeight); saverWidget->move( 0, 0 ); saverWidget->show(); saverWidget->raise(); QApplication::flushX(); saveWin = saverWidget->winId(); startScreenSaver( saveWin ); a.enter_loop(); stopScreenSaver(); destroySaverWindow( saverWidget ); lockOnce = FALSE; if( only1Time ) break; } } cleanupAutoLock(); } else if ( mode == MODE_TEST ) { if( lock ) { fprintf(stderr, glocale->translate( "\nplease don't use -test together with -lock.\n" "use klock instead.\n\n") ); exit(1); } setLock("test"); saverWidget = createSaverWindow(); if (saverWidget) { saverWidget->setFixedSize(desktopWidth, desktopHeight); saverWidget->move( 0, 0 ); saverWidget->show(); saverWidget->raise(); QApplication::flushX(); saveWin = saverWidget->winId(); startScreenSaver( saveWin ); a.enter_loop(); stopScreenSaver(); destroySaverWindow( saverWidget ); } } else if ( mode == MODE_PREVIEW ) { char mode[32]; sprintf(mode, "preview%ld", (unsigned long) saveWin); setLock(mode); startScreenSaver( saveWin ); a.exec(); } else if ( mode == MODE_SETUP ) { setupScreenSaver(); } else usage( argv[0] ); if ( !pidFile.isEmpty() ) { remove( pidFile ); } return 0; } //---------------------------------------------------------------------------- void catchSignals() { // SIGUSR1 forces a lock signal(SIGUSR1, lockNow); // These signals are captured to clean-up before exiting signal(SIGINT, cleanup); /* Interrupt */ signal(SIGTERM, cleanup); /* Terminate */ signal(SIGABRT, cleanup); signal(SIGALRM, cleanup); signal(SIGFPE, cleanup); signal(SIGILL, cleanup); signal(SIGPIPE, cleanup); signal(SIGQUIT, cleanup); signal(SIGSEGV, cleanup); #ifdef SIGBUS signal(SIGBUS, cleanup); #endif #ifdef SIGEMT signal(SIGEMT, cleanup); #endif #ifdef SIGPOLL signal(SIGPOLL, cleanup); #endif #ifdef SIGSYS signal(SIGSYS, cleanup); #endif #ifdef SIGTRAP signal(SIGTRAP, cleanup); #endif #ifdef SIGVTALRM signal(SIGVTALRM, cleanup); #endif #ifdef SIGXCPU signal(SIGXCPU, cleanup); #endif #ifdef SIGXFSZ signal(SIGXFSZ, cleanup); #endif } static void lockNow( int ) { forceTimeout(); // SIGUSR1 forces a lock signal(SIGUSR1, lockNow); } static void cleanup( int id ) { if ( !pidFile.isEmpty() ) { remove( pidFile ); } if ( mode == MODE_INSTALL ) { if (id != SIGPIPE) { XSetScreenSaver( qt_xdisplay(), xs_timeout, xs_interval, xs_prefer_blanking, xs_allow_exposures ); cleanupAutoLock(); } } exit(1); } void usage( char *name ) { printf( glocale->translate( "Usage: %s -install|-setup|-test|-desc|-preview wid|-inroot\n"\ " [-corners xxxx] [-delay num] [-lock] [-allow-root] [-nice num]\n"), name ); printf( glocale->translate( " -corners xxxx Placing cursor in corner performs action:\n"\ " x = i no action (ignore)\n"\ " x = s save screen\n"\ " x = l lock screen\n"\ " order: top-left, top-right, bottom-left, bottom-right\n"\ " -delay num Amount of idle time before screen saver\n"\ " starts (default 10min)\n"\ " -desc Print the screen saver's description to stdout\n"\ " -install Install screen saver\n"\ " -lock Require password to stop screen saver\n"\ " -allow-root Accept root password to unlock\n"\ " -nice num Run with specified nice value\n\n"\ " -preview wid Run in the specified XWindow\n"\ " -inroot Run in the root window\n"\ " -setup Setup screen saver\n"\ " -test Invoke the screen saver immediately\n")); exit(1); } diff --git a/kscreensaver/saver.cpp b/kscreensaver/saver.cpp index f2bdcbf0a..adf1a3f6d 100644 --- a/kscreensaver/saver.cpp +++ b/kscreensaver/saver.cpp @@ -1,245 +1,245 @@ #include #include #include #include #include #include // ssApp #include // for kde_bindir() #include #include #include #include #include #include #include "config.h" #include "saver.h" #include "saver.moc" #define MAX_PASSWORD_LENGTH 20 extern KLocale *glocale; extern ssApp *globalKapp; int checkPasswd(char *); /* * Fetch current user id, and return "Firstname Lastname (username)" */ static QString currentUser(void) { struct passwd *current = getpwuid(getuid()); QString fullname(current->pw_gecos); if (fullname.find(',') != -1) /* Remove everything from and including first comma */ fullname.resize(fullname.find(',')+1); QString username(current->pw_name); return fullname + " (" + username + ")"; } static QString passwordQuery(bool name) { QString retval(""); if (name) { retval = currentUser() + "\n"; } return retval + glocale->translate("Enter Password"); } kScreenSaver::kScreenSaver( Drawable drawable ) : QObject() { Window root; int ai; unsigned int au; d = drawable; gc = XCreateGC( qt_xdisplay(), d, 0, 0); XGetGeometry( qt_xdisplay(), drawable, &root, &ai, &ai, &width, &height, &au, &au ); } kScreenSaver::~kScreenSaver() { XFreeGC( qt_xdisplay(), gc ); } void kScreenSaver::expose( int x, int y, int width, int height ) { XSetForeground(qt_xdisplay(), gc, BlackPixel(qt_xdisplay(), qt_xscreen())); XFillRectangle(qt_xdisplay(), d, gc, x, y, width, height); } //----------------------------------------------------------------------------- KPasswordDlg::KPasswordDlg( QWidget *parent, bool s ) : QWidget( parent ) { setCursor( arrowCursor ); stars = s; password = ""; QFont font( "helvetica", 18 ); QFontMetrics fm(font); QString query = passwordQuery(TRUE); /* Two lines of text */ int qwidth = fm.width((const char *)query); int qheight = fm.height(); QFrame *frame = new QFrame( this ); frame->setFrameStyle( QFrame::Panel | QFrame::Raised ); frame->setLineWidth( 2 ); frame->setGeometry( 0, 0, qwidth + 2*20, qheight * 3 + 2 * 20 ); KApplication::getKApplication()->getCharsets()->setQFont(font); label = new QLabel( query, frame ); label->setFont( font ); label->setGeometry( 20, 20, qwidth, qheight * 2 ); label->setAlignment( AlignCenter ); font.setPointSize( 16 ); KApplication::getKApplication()->getCharsets()->setQFont(font); entry = new QLabel( "", frame ); entry->setFont( font ); entry->setGeometry( 20, 20 + qheight * 2, qwidth, qheight ); resize( qwidth + 2*20, qheight * 3 + 2*20 ); connect( &timer, SIGNAL( timeout() ), SLOT( timeout() ) ); timerMode = 0; timer.start( 10000, TRUE ); if( stars ) { blinkTimer = new QTimer( this, "blink" ); connect( blinkTimer, SIGNAL( timeout() ), SLOT( blinkTimeout() ) ); blinkTimer->start( 300 ); blink = false; } } void KPasswordDlg::showStars() { QString s; s.fill( '*', password.length() ); if( blink ) s += "_"; entry->setText( s ); } void KPasswordDlg::keyPressed( QKeyEvent *e ) { static bool waitForAuthentication = false; if (!waitForAuthentication) { switch ( e->key() ) { case Key_Backspace: { int len = password.length(); if ( len ) { password.truncate( len - 1 ); if( stars ) showStars(); } } break; case Key_Return: timer.stop(); waitForAuthentication = true; if ( tryPassword() ) emit passOk(); else { label->setText( glocale->translate("Failed") ); password = ""; timerMode = 1; timer.start( 1500, TRUE ); } waitForAuthentication = false; break; case Key_Escape: emit passCancel(); break; default: if ( password.length() < MAX_PASSWORD_LENGTH ) { password += (char)e->ascii(); if( stars ) showStars(); timer.changeInterval( 10000 ); } } } } int KPasswordDlg::tryPassword() { #if defined HAVE_ETCPASSWD || defined HAVE_SHADOW || defined HAVE_PAM if( stars ) blinkTimer->stop(); KProcess chkpass; QString kcp_binName = ""; kcp_binName += KApplication::kde_bindir(); - kcp_binName += "/kcheckpass"; + kcp_binName += "/kde1-kcheckpass"; chkpass.clearArguments(); chkpass << kcp_binName; bool ret = chkpass.start(KProcess::DontCare, KProcess::Stdin); if (ret == false) { if( stars ) blinkTimer->start( 300 ); return 2; } chkpass.writeStdin(password.data(),password.length()); // write Password to stdin chkpass.closeStdin(); // eof int timeout = 1000; while ( timeout != 0 ) { if (! chkpass.isRunning() ) break; else { globalKapp->processEvents(); timeout--; usleep(10000); } } int rc = ( chkpass.normalExit() && (chkpass.exitStatus() == 0) ); if( stars ) blinkTimer->start( 300 ); return rc; #else int e = checkPasswd(password.data()); return e; #endif } void KPasswordDlg::timeout() { if ( timerMode ) { label->setText( passwordQuery(TRUE) ); if( stars ) showStars(); timerMode = 0; timer.start( 5000, TRUE ); } else emit passCancel(); } void KPasswordDlg::blinkTimeout() { blink = !blink; showStars(); }