12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988 |
- /*
- * CDE - Common Desktop Environment
- *
- * Copyright (c) 1993-2012, The Open Group. All rights reserved.
- *
- * These libraries and programs are free software; you can
- * redistribute them and/or modify them under the terms of the GNU
- * Lesser General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * These libraries and programs are distributed in the hope that
- * they will be useful, but WITHOUT ANY WARRANTY; without even the
- * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU Lesser General Public License for more
- * details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with these libraries and programs; if not, write
- * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
- * Floor, Boston, MA 02110-1301 USA
- */
- /* $XConsortium: SmLock.c /main/8 1996/10/30 11:13:55 drk $ */
- /* *
- * (c) Copyright 1993, 1994 Hewlett-Packard Company *
- * (c) Copyright 1993, 1994 International Business Machines Corp. *
- * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
- * (c) Copyright 1993, 1994 Novell, Inc. *
- */
- /*************************************<+>*************************************
- *****************************************************************************
- **
- ** File: SmLock.c
- **
- ** Project: HP DT Session Manager (dtsession)
- **
- ** Description:
- ** -----------
- ** In charge of locking and unlocking the display in response from
- ** the front panel to so.
- **
- **
- **
- *******************************************************************
- ** (c) Copyright Hewlett-Packard Company, 1990. All rights are
- ** reserved. Copying or other reproduction of this program
- ** except for archival purposes is prohibited without prior
- ** written consent of Hewlett-Packard Company.
- ********************************************************************
- **
- **
- **
- *****************************************************************************
- *************************************<+>*************************************/
- #include <stdio.h>
- #include <errno.h>
- #include <pwd.h>
- #include <string.h>
- #include <fcntl.h>
- #ifdef SIA
- #include <sia.h>
- #endif
-
- #ifdef USE_HP_SPECIFIC_XLIB
- #include <X11/XHPlib.h>
- #endif /* USE_HP_SPECIFIC_XLIB */
- #include <X11/Intrinsic.h>
- #include <Xm/Xm.h>
- #include <Dt/UserMsg.h>
- #include <Dt/Indicator.h>
- #include <Tt/tttk.h>
- #ifdef SVR4
- # include <shadow.h>
- #endif
- #if defined(__linux__)
- # include <shadow.h>
- #endif
- #if defined(CSRG_BASED)
- #include <sys/types.h>
- #include <pwd.h>
- #endif
- #ifdef HAS_PAM_LIBRARY
- #include <security/pam_appl.h>
- #include <Dt/SvcPam.h>
- #endif
- #include "Sm.h"
- #include "SmGlobals.h"
- #include "SmUI.h"
- #include "SmError.h"
- #include "SmLock.h"
- #include "SmScreen.h"
- /*
- * Variables global to this module only
- */
- /*
- * Global timer value
- */
- static XtIntervalId timerId, lockTimeId, lockDelayId, cycleId, flash_id;
- /*
- * Global grab widget
- */
- static Widget grabWidget;
- /*
- * Lock dialog visibility
- */
- static Boolean lockDlgVisible;
- #ifdef LOCK_SERVER_ACCESS
- /*
- * Server Access Control Information
- */
- static Boolean RestrictingAccess = False;
- static XHostAddress *hostList;
- static Bool hostListActive;
- static int hostListLen;
- #endif
- /*
- * Local Functions
- */
- static void FinishLocking(Widget, XtPointer, XEvent *, Boolean *);
- static void RecolorCursor( void ) ;
- static void EventDetected( Widget, XtPointer, XEvent *, Boolean *) ;
- static void CheckString( char *, int ) ;
- static Boolean CheckPassword( char * ) ;
- #if defined (_AIX) && defined (_POWER)
- static Boolean Authenticate( char *, uid_t, char * ) ;
- #else
- #define Authenticate(A,B,C) localAuthenticate(A,B,C)
- #endif
- static Boolean localAuthenticate( char *, uid_t, char * ) ;
- static void UnlockDisplay( Boolean, Boolean ) ;
- static void TakeDownLogin( XtPointer, XtIntervalId * ) ;
- static void PutUpLogin( Boolean, Boolean ) ;
- static void LockAttemptFailed( XtPointer, XtIntervalId *) ;
- static void RequirePassword( XtPointer, XtIntervalId *) ;
- static void CycleSaver( XtPointer, XtIntervalId *) ;
- static void BlinkCaret( XtPointer, XtIntervalId *) ;
- #if defined(__linux__)
- /* #define JET_AUTHDEBUG */
- /* Test for re-auth ability - see if we can re-authenticate via pwd,
- * shadow, or NIS
- */
- static Boolean CanReAuthenticate(char *name, uid_t uid, char *passwd,
- struct passwd **pwent, struct spwd **spent)
- {
- if (!pwent)
- return False;
- *pwent = (name == NULL) ? getpwuid(uid) : getpwnam(name);
- if (!*pwent)
- return False;
- *spent = getspnam((*pwent)->pw_name);
- #ifdef JET_AUTHDEBUG
- fprintf(stderr, "CanReAuthenticate(): uid: %d name: '%s' errno %d %s %s %s\n",
- uid,
- (name) ? name : "NULL",
- errno,
- (*pwent) ? "PWENT" : "NULL",
- (*spent) ? "SPENT" : "NULL",
- (name) ? name : "NULL");
- #endif
- /* some checking for aging stuff on RedPhat */
- if (*pwent && (*pwent)->pw_passwd)
- {
- char *loc;
- if ((loc = strchr((*pwent)->pw_passwd, ',')) != NULL)
- *loc = '\0';
- #ifdef JET_AUTHDEBUG
- fprintf(stderr, "CanReAuthenticate(): pw: '%s'\n",
- (*pwent)->pw_passwd);
- #endif
- }
- if (*spent && (*spent)->sp_pwdp)
- {
- char *loc;
- if ((loc = strchr((*spent)->sp_pwdp, ',')) != NULL)
- *loc = '\0';
- }
- if (*pwent == NULL)
- { /* if we can't get this, we're screwed. */
- #ifdef JET_AUTHDEBUG
- fprintf(stderr, "CanReAuthenticate(): PWENT == NULL - FALSE\n");
- #endif
- return False;
- }
- if ((*pwent)->pw_passwd == NULL)
- {
- #ifdef JET_AUTHDEBUG
- fprintf(stderr, "CanReAuthenticate(): (*pwent)->pw_passwd == NULL - FALSE\n");
- #endif
- return False;
- }
- /* ok, now we have the prequisite data, look first to see if the
- * passwd field is larger than 1 char - implying NIS, or a shadowed
- * system. if not look for *spent being non-NULL
- */
- if (*spent == NULL)
- { /* if it's null, lets check for the NIS case */
- if (strlen((*pwent)->pw_passwd) <= 1)
- {
- #ifdef JET_AUTHDEBUG
- fprintf(stderr, "strlen((*pwent)->pw_passwd) <= 1\n");
- #endif
- return False; /* not NIS */
- }
- }
- /* supposedly we have valid data */
- #ifdef JET_AUTHDEBUG
- fprintf(stderr, "CanReAuthenticate(): TRUE\n");
- #endif
- return True;
- }
- #endif /* linux */
- /*************************************<->*************************************
- *
- * LockDisplay ()
- *
- *
- * Description:
- * -----------
- * Calls the routines that are in charge of locking the display.
- *
- *
- * Inputs:
- * ------
- * lockNow - request to lock the display immediately
- *
- * Outputs:
- * -------
- *
- * Comments:
- * --------
- *
- *************************************<->***********************************/
- /*
- * Place holders for the lock position
- */
- static Position visibleY;
- static Position hiddenY;
- void
- LockDisplay(
- Boolean lockNow)
- {
- register int i;
- int screenNum;
- Widget parent = NULL, lockDlg;
- XColor xcolors[2];
- struct passwd *pw;
- Boolean secure;
- int lockDelay;
- int rc;
- timerId = lockTimeId = lockDelayId = cycleId = flash_id = (XtIntervalId)0;
- /*
- * coverScreen
- * 0 - screen will not be covered, nor will external screen saver run
- * 1 - screen will be covered, external screen saver may be run
- *
- * lockDelay
- * -1 = no password required to unlock display
- * 0 = password always required to unlock display
- * N = password required to unlock display after N seconds
- */
- if (smSaverRes.saverTimeout == 0)
- {
- smGD.coverScreen = 0;
- lockDelay = 0;
- }
- else if (lockNow || smSaverRes.lockTimeout > 0)
- {
- smGD.coverScreen = 1;
- if (lockNow)
- lockDelay = 0;
- else if (smSaverRes.lockTimeout == 0)
- lockDelay = -1;
- else if (smSaverRes.lockTimeout <= smSaverRes.saverTimeout)
- lockDelay = 0;
- else
- lockDelay = smSaverRes.lockTimeout - smSaverRes.saverTimeout;
- }
- else
- {
- smGD.coverScreen = 1;
- lockDelay = -1;
- }
- /*
- * Before anything is done make sure we can unlock if we lock.
- */
- if (localAuthenticate(NULL, getuid(), NULL) == False)
- {
- Tt_message msg;
- PrintError(DtError, smNLS.trustedSystemErrorString);
- XBell(smGD.display, 100);
-
- /*
- * Tell the Workspace Manager to quit blinking
- */
- msg = tttk_message_create( 0, TT_NOTICE, TT_SESSION, 0,
- "DtActivity_Began", 0 );
- tt_message_send( msg );
- tt_message_destroy( msg );
- SetSystemReady();
- return;
- }
-
- if(((smDD.lockCoverDialog == NULL) && (smGD.coverScreen == True)) ||
- ((smDD.lockDialog == NULL) && (smGD.coverScreen == False)))
- {
- /*
- * Set up the grab widget in here
- */
- grabWidget = NULL;
- /*
- * If the user has specified cover - create the cover dialog
- */
- screenNum = DefaultScreen(smGD.display);
- if(smGD.coverScreen == True)
- {
- for(i = (smGD.numSavedScreens - 1);i >= 0;i--)
- {
- if(i == screenNum)
- {
- smDD.coverDialog[i] = CreateCoverDialog(i, True);
- parent = smDD.coverDrawing[i];
- }
- else
- {
- smDD.coverDialog[i] = CreateCoverDialog(i, False);
- }
- }
- smDD.lockCoverDialog = CreateLockDialogWithCover(parent);
- }
-
- /*
- * Create the lock dialog if the user has specified that
- */
- if((smDD.lockDialog == NULL) && (smGD.coverScreen == False))
- {
- smDD.lockDialog = CreateLockDialog();
- /*
- * Get colors for the password cursor
- */
- i = 0;
- XtSetArg(uiArgs[i], XmNtopShadowColor, &(xcolors[0]));i++;
- XtSetArg(uiArgs[i], XmNbottomShadowColor, &(xcolors[1]));i++;
- XtGetValues(smDD.lockDialog, uiArgs, i);
- smGD.backgroundPix = xcolors[0].pixel;
- smGD.foregroundPix = xcolors[1].pixel;
- if (smGD.backgroundPix == smGD.foregroundPix)
- {
- smGD.backgroundPix = smGD.whitePixel;
- smGD.foregroundPix = smGD.blackPixel;
- }
- }
- }
- /*
- * Wait for a visibility event to occur on the window so that
- * we can grab it
- */
- if(smGD.coverScreen == True)
- {
- smGD.lockCursor = smGD.blankCursor;
- grabWidget = smDD.coverDialog[0];
- lockDlg = smDD.lockCoverDialog;
- lockDlgVisible = False; /* mappedWhenManaged False */
- }
- else
- {
- smGD.lockCursor = smGD.padlockCursor;
- grabWidget = smDD.lockDialog;
- lockDlg = smDD.lockDialog;
- visibleY = hiddenY = -1;
- }
- /*
- * Note: grabWidget must be mapped in order to grab it. This means
- * that if coverScreen is True, smDD.coverDialog[0] must be mapped
- * immediately and if coverScreen is False, smDD.lockDialog must be
- * mapped immediately. Also, if a grabWidget is unmapped, the grab
- * is lost. Ah X.
- */
- XtAddEventHandler(grabWidget, VisibilityChangeMask,
- False, FinishLocking, NULL);
- XtManageChild(lockDlg);
- if(smGD.coverScreen == True) {
- flash_id = XtAppAddTimeOut(smGD.appCon,
- 1000, BlinkCaret,smDD.indLabel[1]);
- }
- else{
- flash_id = XtAppAddTimeOut(smGD.appCon,
- 1000, BlinkCaret,smDD.indLabel[0]);
- }
- if (lockDelay > 0)
- {
- /*
- * Wait for 'lockDelay' seconds before requiring a password.
- */
- lockDelayId = XtAppAddTimeOut(smGD.appCon,
- lockDelay*1000, RequirePassword, NULL);
-
- }
- else if (lockDelay == 0)
- {
- /*
- * Immediately require a password to unlock the display.
- */
- smGD.lockedState = LOCKED;
- PutUpLogin(True, False); /* map, but don't set timeout */
- }
- if (smGD.coverScreen == True && smSaverRes.cycleTimeout > 0)
- {
- /*
- * Cycle to next saver in 'cycleTimeout' seconds.
- */
- cycleId = XtAppAddTimeOut(smGD.appCon,
- smSaverRes.cycleTimeout*1000, CycleSaver, NULL);
- }
-
- if(smGD.coverScreen == True)
- {
- for(i = (smGD.numSavedScreens - 1);i >= 0;i--)
- {
- XtPopup(smDD.coverDialog[i], XtGrabNone);
- }
- }
- /*
- * Add an event handler for when the keyboard and pointer are grabbed
- */
- XtAddEventHandler(grabWidget,
- (KeyPressMask | ButtonPressMask | PointerMotionMask),
- False, EventDetected, NULL);
- /** wait 90 seconds for lock dialog to come up **/
- lockTimeId = XtAppAddTimeOut(smGD.appCon,
- 90000, LockAttemptFailed, lockDlg);
- return;
- }
- /*************************************<->*************************************
- *
- * FinishLocking ()
- *
- *
- * Description:
- * -----------
- * After the lock dialog is up - do the grab and lock the display
- *
- *
- * Inputs:
- * ------
- *
- * Outputs:
- * -------
- *
- * Comments:
- * --------
- *
- *************************************<->***********************************/
- static void
- FinishLocking(Widget wid,
- XtPointer ptr,
- XEvent *ev,
- Boolean *bl)
- {
- int i,j;
- Boolean kbdGrabbed, pointerGrabbed;
- int rc;
- if (lockTimeId == (XtIntervalId)0)
- return;
- XtRemoveTimeOut(lockTimeId);
- lockTimeId = (XtIntervalId)0;
- XtRemoveEventHandler(wid, VisibilityChangeMask,
- False, FinishLocking, NULL);
- XSync(smGD.display, 0);
- i = 0;
- XtSetArg(uiArgs[i], XmNy, &visibleY);i++;
- XtGetValues(wid, uiArgs, i);
- hiddenY = (Position) DisplayHeight(smGD.display, smGD.screen) + 15;
- /*
- * Color the cursor for this color scheme
- */
- RecolorCursor();
- XSync(smGD.display, 0);
- /*
- * grab control of the keyboard for the entire display
- */
- rc = XtGrabKeyboard(grabWidget, False,
- GrabModeAsync, GrabModeAsync,
- CurrentTime);
- kbdGrabbed = (rc == GrabSuccess);
- #ifdef USE_HP_SPECIFIC_XLIB
- XHPDisableReset(smGD.display);
- #endif /* USE_HP_SPECIFIC_XLIB */
- #if defined (AIXV3) && !defined(_POWER)
- if(smGD.secureSystem)
- {
- SM_SETEUID(smGD.unLockUID);
- AixEnableHftRing(0);
- SM_SETEUID(smGD.runningUID);
- }
- #endif
- pointerGrabbed = (XtGrabPointer(grabWidget, False,
- ButtonPressMask|PointerMotionMask,
- GrabModeAsync, GrabModeAsync,
- None, smGD.lockCursor, CurrentTime)
- == GrabSuccess);
- {
- pointerGrabbed = (XtGrabPointer(grabWidget, False,
- ButtonPressMask|PointerMotionMask,
- GrabModeAsync, GrabModeAsync,
- None, smGD.lockCursor, CurrentTime)
- == GrabSuccess);
- }
- /*
- * If the grab failed - try 3 more times and give up
- */
- if((kbdGrabbed == False) || (pointerGrabbed == False))
- {
- for(j = 0;(j < 3) && ((pointerGrabbed == False) ||
- (kbdGrabbed == False));j++)
- {
- /*
- * If a grab fails try one more time and then give up
- */
- if(kbdGrabbed == False)
- {
- sleep(1);
- kbdGrabbed = (XtGrabKeyboard(grabWidget, False,
- GrabModeAsync, GrabModeAsync,
- CurrentTime) == GrabSuccess);
- }
- if(pointerGrabbed == False)
- {
- sleep(1);
- pointerGrabbed = (XtGrabPointer(grabWidget, False,
- ButtonPressMask |
- PointerMotionMask,
- GrabModeAsync,
- GrabModeAsync,
- None, smGD.lockCursor,
- CurrentTime)
- == GrabSuccess);
- }
- }
- }
- /*
- * Set status variable to lock if the lock has succeeded
- */
- if((pointerGrabbed != True) || (kbdGrabbed != True))
- {
- PrintError(DtError, smNLS.cantLockErrorString);
- smGD.lockedState = UNLOCKED;
- UnlockDisplay(pointerGrabbed, kbdGrabbed);
- }
- else
- {
- #ifdef LOCK_SERVER_ACCESS
- /*
- * Wipe & enable X server access control list
- */
- hostList = XListHosts(smGD.display,
- &hostListLen, (Bool *) &hostListActive);
- XRemoveHosts(smGD.display, hostList, hostListLen);
- XEnableAccessControl(smGD.display);
- RestrictingAccess = True;
- #endif
-
- PutUpLogin(False, True); /* already mapped, but set timeout */
- /*
- * Start external screen saver.
- */
- if (smGD.coverScreen)
- {
- StartScreenSaver();
- }
- }
- return;
- }
- /*************************************<->*************************************
- *
- * CreateLockCursor ()
- *
- *
- * Description:
- * -----------
- * Creates a padlock cursor if the user has specified lock. Creates a
- * blank cursor if the user has specified cover. Both are specified in the
- * users resource file.
- *
- *
- *
- * Inputs:
- * ------
- * buttonForm = widget from which cursor gets its color
- * smGD.coverScreen = (global) cover screen or put up a padlock
-
- *
- *
- * Outputs:
- * -------
- * smGD.lockCursor = (global) cursor when lock is active (blank or padlock)
- *
- * Comments:
- * --------
- *
- *************************************<->***********************************/
- #define lock_m_hot_x 16
- #define lock_m_hot_y 16
- #define lock_m_bm_width 32
- #define lock_m_bm_height 32
- static unsigned char lock_m_bm_bits[] = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x0f, 0x00,
- 0x00, 0xfc, 0x9f, 0x00, 0x00, 0x0e, 0x90, 0x01, 0x00, 0x06, 0x80, 0x01,
- 0x00, 0x06, 0x80, 0x01, 0x00, 0x06, 0x80, 0x01, 0x00, 0x06, 0x80, 0x01,
- 0x00, 0x06, 0x80, 0x01, 0x00, 0x06, 0x80, 0x01, 0x00, 0x06, 0x80, 0x01,
- 0x00, 0x06, 0x80, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x0c,
- 0x80, 0xaa, 0xaa, 0x0e, 0x00, 0x55, 0x55, 0x0f, 0x80, 0xaa, 0xaa, 0x0e,
- 0x00, 0x55, 0x55, 0x0f, 0x80, 0xaa, 0xaa, 0x0e, 0x00, 0x55, 0x55, 0x0f,
- 0x80, 0xaa, 0xaa, 0x0e, 0x00, 0x55, 0x55, 0x0f, 0x80, 0xaa, 0xaa, 0x0e,
- 0x00, 0x55, 0x55, 0x0f, 0x80, 0xaa, 0xaa, 0x0e, 0x00, 0x55, 0x55, 0x0f,
- 0x80, 0xaa, 0xaa, 0x0e, 0x00, 0x55, 0x55, 0x0f, 0x80, 0xaa, 0xaa, 0x0e,
- 0xc0, 0xff, 0xff, 0x0f, 0xe0, 0xff, 0xff, 0x0f};
- #define lock_m_m_bm_width 32
- #define lock_m_m_bm_height 32
- static unsigned char lock_m_m_bm_bits[] = {
- 0x00, 0xf8, 0x1f, 0x00, 0x00, 0xfe, 0x7f, 0x00, 0x00, 0xff, 0xff, 0x00,
- 0x00, 0xff, 0xff, 0x00, 0x80, 0x0f, 0xf0, 0x01, 0x80, 0x07, 0xe0, 0x01,
- 0x80, 0x07, 0xe0, 0x01, 0x80, 0x07, 0xe0, 0x01, 0x80, 0x07, 0xe0, 0x01,
- 0x80, 0x07, 0xe0, 0x01, 0x80, 0x07, 0xe0, 0x01, 0x80, 0x07, 0xe0, 0x01,
- 0x80, 0x07, 0xe0, 0x01, 0xf0, 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0x0f,
- 0xf0, 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0x0f,
- 0xf0, 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0x0f,
- 0xf0, 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0x0f,
- 0xf0, 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0x0f,
- 0xf0, 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0x0f,
- 0xf0, 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0x0f};
- #define lock_s_hot_x 7
- #define lock_s_hot_y 8
- #define lock_s_bm_width 13
- #define lock_s_bm_height 16
- static unsigned char lock_s_bm_bits[] = {
- 0x00, 0x02, 0x00, 0x04, 0xf0, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
- 0x00, 0x00, 0xa8, 0x1a, 0x54, 0x1d, 0xa8, 0x1a, 0x54, 0x1d, 0xa8, 0x1a,
- 0x54, 0x1d, 0xa8, 0x1a, 0x54, 0x1d, 0xfe, 0x1f};
- #define lock_s_m_bm_width 13
- #define lock_s_m_bm_height 16
- static unsigned char lock_s_m_bm_bits[] = {
- 0xf8, 0x03, 0xfc, 0x07, 0xfe, 0x0f, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e,
- 0xff, 0x1f, 0xff, 0x1f, 0xff, 0x1f, 0xff, 0x1f, 0xff, 0x1f, 0xff, 0x1f,
- 0xff, 0x1f, 0xff, 0x1f, 0xff, 0x1f, 0xff, 0x1f};
- void
- CreateLockCursor( void )
- {
- Pixmap source, mask;
- Colormap cmap = XDefaultColormap(smGD.display, smGD.screen);
- XColor xcolors[2];
- char noCursorBits = 0x1;
- if(InitCursorInfo() == False)
- {
- /*
- * Create the SMALL padlock cursor
- */
- source = XCreateBitmapFromData(smGD.display,
- XRootWindow(smGD.display,
- smGD.screen),
- (char *) lock_s_bm_bits,
- lock_s_bm_width,
- lock_s_bm_height);
- mask = XCreateBitmapFromData(smGD.display,
- XRootWindow(smGD.display,
- smGD.screen),
- (char *) lock_s_m_bm_bits,
- lock_s_m_bm_width,
- lock_s_m_bm_height);
- /* translate the Pixels into XColors */
- xcolors[0].pixel = smGD.blackPixel;
- xcolors[1].pixel = smGD.whitePixel;
- XQueryColors(smGD.display, cmap, xcolors, 2);
- /* create the padlock cursor */
- smGD.padlockCursor = XCreatePixmapCursor(smGD.display, source, mask,
- &(xcolors[0]), &(xcolors[1]),
- lock_s_hot_x,
- lock_s_hot_y);
- XFreePixmap(smGD.display, source);
- XFreePixmap(smGD.display, mask);
- }
- else
- {
- /*
- * Create the LARGE padlock cursor
- */
- source = XCreateBitmapFromData(smGD.display,
- XRootWindow(smGD.display,
- smGD.screen),
- (char *) lock_m_bm_bits,
- lock_m_bm_width,
- lock_m_bm_height);
- mask = XCreateBitmapFromData(smGD.display,
- XRootWindow(smGD.display,
- smGD.screen),
- (char *) lock_m_m_bm_bits,
- lock_m_m_bm_width,
- lock_m_m_bm_height);
- /* translate the Pixels into XColors */
- xcolors[0].pixel = smGD.blackPixel;
- xcolors[1].pixel = smGD.whitePixel;
- XQueryColors(smGD.display, cmap, xcolors, 2);
- /* create the padlock cursor */
- smGD.padlockCursor = XCreatePixmapCursor(smGD.display, source, mask,
- &(xcolors[0]), &(xcolors[1]),
- lock_m_hot_x,
- lock_m_hot_y);
- XFreePixmap(smGD.display, source);
- XFreePixmap(smGD.display, mask);
- }
- /*
- *
- * create the blank cursor
- */
- source = XCreateBitmapFromData(smGD.display,
- XRootWindow(smGD.display, smGD.screen),
- &noCursorBits, 1, 1);
- xcolors[0].pixel = smGD.blackPixel;
- XQueryColor(smGD.display, cmap, &(xcolors[0]));
- smGD.blankCursor = XCreatePixmapCursor(smGD.display, source, source,
- &(xcolors[0]), &(xcolors[0]),
- 0, 0);
- XFreePixmap(smGD.display, source);
- }
- /*************************************<->*************************************
- *
- * RecolorCursor ()
- *
- *
- * Description:
- * -----------
- * Recolors the padlock cursor to be the current color scheme. This has
- * to be done because XCreatePixmapCursor allocates colors instead of jusst
- * using a pixel value.
- *
- *
- *
- * Inputs:
- * ------
- * smGD.backgroundPix = Pixel value to use for background color
- * smGD.foregroundPix = Pixel value to use for foreground color
- *
- *
- * Outputs:
- * -------
- * smGD.lockCursor = (global) cursor when lock is active (padlock)
- *
- * Comments:
- * --------
- *
- *************************************<->***********************************/
- static void
- RecolorCursor( void )
- {
- Colormap cmap = XDefaultColormap(smGD.display, smGD.screen);
- XColor xcolors[2];
- /*
- * translate the Pixels into XColors
- */
- xcolors[0].pixel = smGD.foregroundPix;
- xcolors[1].pixel = smGD.backgroundPix;
- XQueryColors(smGD.display, cmap, xcolors, 2);
- /*
- * recolor the padlock cursor
- */
- XRecolorCursor(smGD.display, smGD.lockCursor, &(xcolors[0]),
- &(xcolors[1]));
- }
- /*************************************<->*************************************
- *
- * EventDetected (w, client_data, event)
- *
- *
- * Description:
- * -----------
- * Callback routine that detects an event when the display is locked.
- * If it's a correct password, it unlocks the display. Otherwise, it
- * just displays status. The event is detected by the popup login dialog.
- *
- *
- * Inputs:
- * ------
- * w = widget where event occurred
- * client_data = client specific data sent to callback
- * event = event that triggered callback
- *
- *
- * Outputs:
- * -------
- *
- * Comments:
- * --------
- *
- *************************************<->***********************************/
- static void
- EventDetected(
- Widget w,
- XtPointer client_data,
- XEvent *ev,
- Boolean *bl)
- {
- char str[256];
- int len;
- XKeyEvent *event = (XKeyEvent *) ev;
-
- if (smGD.lockedState == LOCKED)
- {
- if (lockDlgVisible == False)
- {
- /*
- * Anytime input is received - show the passwd dialog and
- * discard event. This is so a keypress event that causes
- * the passwd dialog to appear will not be used in the password.
- * CMVC 612.
- */
- PutUpLogin(True, True); /* map, and reset timeout */
- return;
- }
- PutUpLogin(False, True); /* already mapped, but reset timeout */
- }
- else
- {
- UnlockDisplay(True, True);
- return;
- }
- /*
- * If the detected event is anything but a keypress, processing is
- * complete after refreshing the status string.
- */
- if (event->type != KeyPress)
- return;
- /*
- * If XLookupString() returns anything (which it won't in the case of, say,
- * pressing the shift key or an arrow key), process it.
- */
- #ifdef USE_HP_SPECIFIC_XLIB
- if (len = XHPConvertLookup(event, str, sizeof(str), NULL, NULL,
- XHPGetEurasianCvt(smGD.display)))
- #else /* USE_HP_SPECIFIC_XLIB */
- if (len = XLookupString (event, str, sizeof(str), NULL, NULL))
- #endif /* USE_HP_SPECIFIC_XLIB */
- {
- if (smGD.lockedState == LOCKED)
- CheckString(str, len);
- }
- }
- /*************************************<->*************************************
- *
- * CheckString (s, i)
- *
- *
- * Description:
- * -----------
- * Check string entered by user. If it is a valid password, call routine to
- * unlock the display. Otherwise, just keep track of what we have until
- * the password is valid
- *
- *
- * Inputs:
- * ------
- * s = string passed in for checking
- * i = length of string
- *
- *
- * Outputs:
- * -------
- *
- * Comments:
- * --------
- *
- *************************************<->***********************************/
- static void
- CheckString(
- register char *s,
- register int i )
- {
- /* maximum supported length of password */
- #if defined(SIA)
- #define MAX_PASSWORD_LENGTH SIAMXPASSWORD
- #else
- /* seems to be reasonable maximal length */
- #define MAX_PASSWORD_LENGTH 65535
- #endif
- /* step when allocating/extending buffer */
- #define BUF_ALLOC_LEN 64
- /*
- * password rules:
- * - If pw_length > MAX_PASSWORD_LENGTH, we've gone over the limit and won't
- * accept any more.
- * - An ESC kills the line.
- */
- static char *passwd = NULL; /* password space */
- static int pw_buf_length = 0; /* length of allocated password buffer */
- static int pw_length = 0; /* password length */
- char * tmpptr;
- if (s == NULL)
- {
- /*
- * Clear password.
- */
- pw_length = 0;
- return;
- }
- for (; i>0; s++,i--)
- {
- /* extend buffer by BUF_ALLOC_LEN bytes if needed*/
- #ifdef JET_AUTHDEBUG
- fprintf(stderr, "CheckString: pw_length=%d\n",pw_length);
- #endif
- if (pw_length == pw_buf_length)
- {
- tmpptr = SM_REALLOC(passwd, pw_buf_length + BUF_ALLOC_LEN);
- if (!tmpptr) {
- PrintErrnoError(DtError, smNLS.cantMallocErrorString);
- return;
- }
- pw_buf_length += BUF_ALLOC_LEN;
- passwd = tmpptr;
- }
- switch(*s)
- {
- case '\010':
- if (pw_length)
- pw_length--; /* back up one character */
- break;
-
- case '':
- pw_length = 0; /* kill the character string */
- break;
- case '\n':
- case '\r':
- if (pw_length > MAX_PASSWORD_LENGTH)
- {
- pw_length = MAX_PASSWORD_LENGTH;
- }
- passwd[pw_length] = '\0'; /* terminate string */
- pw_length = 0; /* reset length */
- if (CheckPassword(passwd))
- {
- UpdatePasswdField(0);
- UnlockDisplay(True, True);
- return;
- }
- XBell(smGD.display, 100); /* wrong, laserbreath */
- break;
- default:
- if (pw_length < MAX_PASSWORD_LENGTH)
- {
- passwd[pw_length++] = *s; /* store character */
- }
- break;
- }
- }
- UpdatePasswdField(pw_length > MAX_PASSWORD_LENGTH ? MAX_PASSWORD_LENGTH : pw_length);
- }
- /*************************************<->*************************************
- *
- * CheckPassword (passwd)
- *
- *
- * Description:
- * -----------
- * Check the password to see if it is the user's, roots, or one of the
- * users specified in the host string
- *
- *
- * Inputs:
- * ------
- * passwd = password passed in
- *
- *
- * Outputs:
- * -------
- * True if it is a valid password, false otherwise.
- *
- * Comments:
- * --------
- *
- *************************************<->***********************************/
- static Boolean
- CheckPassword(
- char *passwd )
- {
- char *p, *q;
- char *keyholderbuf;
- if (Authenticate(NULL, getuid(), passwd) == True)
- {
- return(True); /* user password ok */
- }
- if (Authenticate(NULL, 0, passwd) == True)
- {
- return(True); /* root password ok */
- }
- /* check passwords of users specified as keyholders */
- if (smGD.keyholders == NULL)
- {
- return(False); /* no keyholders */
- }
- /* since strtok() is destructive, copy the keyholders string */
- keyholderbuf = (char *) SM_MALLOC(strlen(smGD.keyholders)+1);
- if(keyholderbuf == NULL)
- {
- PrintErrnoError(DtError, smNLS.cantMallocErrorString);
- return(False); /* no memory */
- }
-
- strcpy(keyholderbuf, smGD.keyholders);
- for (p = keyholderbuf; (q = strtok(p, ", \t")) != NULL; p = NULL)
- {
- if (Authenticate(q, -1, passwd) == True)
- {
- SM_FREE(keyholderbuf);
- return(True); /* keyholder password ok */
- }
- }
- SM_FREE(keyholderbuf);
- return(False); /* no matches */
- }
- /*************************************<->*************************************
- *
- * UnlockDisplay ()
- *
- *
- * Description:
- * -----------
- * If the user has entered a correct password, unlock the display and
- * uncover the root window.
- *
- *
- * Inputs:
- * ------
- * pointerGrabbed - Boolean tells if pointer is currently grabbed
- * kbdGrabbed - Boolean tells if keyboard is currently grabbed
- *
- *
- * Outputs:
- * -------
- *
- *
- * Comments:
- * --------
- *
- *************************************<->***********************************/
- static void
- UnlockDisplay(
- Boolean pointerGrabbed,
- Boolean kbdGrabbed)
- {
- int i;
- Tt_message msg;
- #ifdef LOCK_SERVER_ACCESS
- /*
- * Restore X server access state
- */
- if (RestrictingAccess) {
- XAddHosts(smGD.display, hostList, hostListLen);
- if (!hostListActive) XDisableAccessControl(smGD.display);
- RestrictingAccess = False;
- XFree((void *) hostList);
- }
- #endif
- /*
- * Stop external screen saver.
- */
- StopScreenSaver();
- /*
- * Remove the event handler to grab the events
- */
- XtRemoveEventHandler(grabWidget,
- (KeyPressMask | ButtonPressMask | PointerMotionMask),
- False, EventDetected, NULL);
- /*
- * Turn off alarms
- */
- if(lockDelayId != (XtIntervalId)0)
- {
- XtRemoveTimeOut(lockDelayId);
- }
- if(cycleId != (XtIntervalId)0)
- {
- XtRemoveTimeOut(cycleId);
- }
- if(timerId != (XtIntervalId)0)
- {
- XtRemoveTimeOut(timerId);
- }
- if(flash_id != (XtIntervalId)0)
- {
- XtRemoveTimeOut(flash_id);
- }
- if(pointerGrabbed == True)
- {
- XtUngrabPointer(grabWidget, CurrentTime);
- }
- if(kbdGrabbed == True)
- {
- XtUngrabKeyboard(grabWidget, CurrentTime);
- }
-
- #ifdef USE_HP_SPECIFIC_XLIB
- XHPEnableReset(smGD.display);
- #endif /* USE_HP_SPECIFIC_XLIB */
- #if defined (AIXV3) && !defined(_POWER)
- if(smGD.secureSystem)
- {
- SM_SETEUID(smGD.unLockUID);
- AixEnableHftRing(1);
- SM_SETEUID(smGD.runningUID);
- }
- #endif
- XSync(smGD.display, 0);
- /*
- * Unmanage session lock dialogs. If LOCKDLG_PERSIST is undefined,
- * destroy them. This is so the passwd dialog icon colors get freed
- * since currently it uses a lot of colors.
- */
- if(smGD.coverScreen == False)
- {
- #if defined (LOCKDLG_PERSIST)
- if (XtIsManaged(smDD.lockDialog))
- {
- XtUnmanageChild(smDD.lockDialog);
- }
- #else
- XtDestroyWidget(smDD.lockDialog);
- smDD.lockDialog = NULL;
- #endif
- }
- else
- {
- #if defined (LOCKDLG_PERSIST)
- if(!XtIsManaged(smDD.lockCoverDialog))
- {
- XtManageChild(smDD.lockCoverDialog);
- }
-
- for(i = (smGD.numSavedScreens - 1);i >= 0;i--)
- {
- XtPopdown(smDD.coverDialog[i]);
- }
- #else
- for(i = (smGD.numSavedScreens - 1);i >= 0;i--)
- {
- XtDestroyWidget(smDD.coverDialog[i]);
- smDD.coverDialog[i] = NULL;
- }
- smDD.lockCoverDialog = NULL;
- #endif
- }
- smGD.lockedState = UNLOCKED;
- XSync(smGD.display, 0);
- /*
- * Tell the Workspace Manager to unlock the display (depress the lock
- * button)
- if(smGD.bmsDead == False)
- {
- msg = tttk_message_create(0, TT_REQUEST, TT_SESSION, 0,
- "Display_Unlock", 0);
- tt_message_send(msg);
- tt_message_destroy(msg);
- }
- */
- SetSystemReady();
-
- }
- static Position visibleY = -1;
- static Position hiddenY = -1;
- /*************************************<->*************************************
- *
- * TakeDownLogin ()
- *
- *
- * Description:
- * -----------
- * When a timeout occurs - take down the login screen by unmanaging it.
- *
- *
- * Inputs:
- * ------
- *
- *
- * Outputs:
- * -------
- *
- *
- * Comments:
- * --------
- *
- *************************************<->***********************************/
- static void
- TakeDownLogin(
- XtPointer client_data,
- XtIntervalId *id )
- {
- if (lockDlgVisible == True)
- {
- if (smGD.coverScreen == True)
- {
- XtUnmapWidget(smDD.lockCoverDialog);
- }
- else
- {
- if (hiddenY > -1)
- {
- int i = 0;
- XtSetArg(uiArgs[i], XmNy, hiddenY);i++;
- XtSetValues(smDD.lockDialog, uiArgs, i);
- }
- }
-
- timerId = (XtIntervalId)0;
- /*
- * Clear partially entered password if any.
- */
- CheckString(NULL, 0);
- lockDlgVisible = False;
- XSync(smGD.display, 0);
- }
- }
- /*************************************<->*************************************
- *
- * PutUpLogin ()
- *
- *
- * Description:
- * -----------
- * Redisplays the cover and the login when necessary.
- *
- *
- * Inputs:
- * ------
- *
- *
- * Outputs:
- * -------
- *
- *
- * Comments:
- * --------
- *
- *************************************<->***********************************/
- static void
- PutUpLogin(
- Boolean map,
- Boolean timeout )
- {
- if (map == True && lockDlgVisible == False)
- {
- if (smGD.coverScreen == True)
- {
- XtMapWidget(smDD.lockCoverDialog);
- }
- else
- {
- if (visibleY > -1)
- {
- int i = 0;
- XtSetArg(uiArgs[i], XmNy, visibleY);i++;
- XtSetValues(smDD.lockDialog, uiArgs, i);
- }
- }
- lockDlgVisible = True;
- }
- if (timeout == True)
- {
- if(timerId != (XtIntervalId)0)
- {
- XtRemoveTimeOut(timerId);
- }
-
- if(smRes.alarmTime > 0)
- {
- timerId = XtAppAddTimeOut(smGD.appCon,
- (smRes.alarmTime * 1000),
- TakeDownLogin,NULL);
- }
- }
- XSync(smGD.display, 0);
- }
- /*************************************<->*************************************
- *
- * LockAttemptFailed ()
- *
- *
- * Description:
- * -----------
- * Timed out trying to get a visibilitynotify on the lock
- *
- *
- * Inputs:
- * ------
- *
- *
- * Outputs:
- * -------
- *
- *
- * Comments:
- * --------
- *
- *************************************<->***********************************/
- static void
- LockAttemptFailed(XtPointer ptr,
- XtIntervalId *invId)
- {
- Widget lockWid = (Widget) ptr;
-
- PrintError(DtError, smNLS.cantLockErrorString);
- smGD.lockedState = UNLOCKED;
- XtRemoveEventHandler(lockWid, VisibilityChangeMask,
- False, FinishLocking, NULL);
- UnlockDisplay(False, False);
- XSync(smGD.display, 0);
- }
- /*************************************<->*************************************
- *
- * RequirePassword ()
- *
- *
- * Description:
- * -----------
- * Callback indicating a password is now required to unlock display.
- *
- *
- * Inputs:
- * ------
- *
- *
- * Outputs:
- * -------
- *
- *
- * Comments:
- * --------
- *
- *************************************<->***********************************/
- static void
- RequirePassword(XtPointer ptr,
- XtIntervalId *invId)
- {
- smGD.lockedState = LOCKED;
- }
- /*************************************<->*************************************
- *
- * BlinkCaret ()
- *
- *
- * Description:
- * -----------
- * blinks the caret in the password field
- *
- *
- * Inputs:
- * ------
- *
- *
- * Outputs:
- * -------
- *
- *
- * Comments:
- * --------
- *
- *************************************<->***********************************/
- static void
- BlinkCaret(XtPointer ptr,
- XtIntervalId *invId)
- {
- static int flag = 1;
- XmString tmpString;
- int i;
-
- /*
- * Blink cursor to show the focus ..
- */
- if(flag){
- tmpString = XmStringCreateLocalized (" " );
- i = 0;
- XtSetArg(uiArgs[i], XmNlabelString, tmpString); i++;
- XtSetValues(ptr, uiArgs, i);
- flag = 0;
- }
- else{
- tmpString = XmStringCreateLocalized ("|");
- i = 0;
- XtSetArg(uiArgs[i], XmNlabelString, tmpString); i++;
- XtSetValues(ptr, uiArgs, i);
- flag = 1;
- }
-
- XmStringFree(tmpString);
- flash_id = XtAppAddTimeOut(smGD.appCon, 1000,
- BlinkCaret, ptr);
- }
- /*************************************<->*************************************
- *
- * CycleSaver ()
- *
- *
- * Description:
- * -----------
- * Callback indicating we should cycle to next screen saver
- *
- *
- * Inputs:
- * ------
- *
- *
- * Outputs:
- * -------
- *
- *
- * Comments:
- * --------
- *
- *************************************<->***********************************/
- static void
- CycleSaver(XtPointer ptr,
- XtIntervalId *invId)
- {
- /*
- * Stop running screen saver, start a new one and reset timer.
- */
- StopScreenSaver();
- StartScreenSaver();
- cycleId = XtAppAddTimeOut(smGD.appCon, smSaverRes.cycleTimeout*1000,
- CycleSaver, NULL);
- }
- /*************************************<->*************************************
- *
- * localAuthenticate (name, uid, passwd)
- *
- *
- * Description:
- * -----------
- *
- *
- * Inputs:
- * ------
- *
- *
- * Outputs:
- * -------
- *
- * Comments:
- * --------
- *
- *************************************<->***********************************/
- static Boolean
- localAuthenticate(
- char *name,
- uid_t uid,
- char *passwd )
- #if defined(HAS_PAM_LIBRARY)
- {
- char *service;
- struct passwd *pwent;
- if (!(name && name[0])) name = NULL;
- if (uid < 0) uid = 0;
- if (!(name || passwd)) return True;
- if (!passwd) return False;
- if (!(pwent = name ? getpwnam(name) : getpwuid(uid))) return False;
- endpwent();
- if (!(service = strrchr(smGD.programName, '/'))) return False;
- return _DtSvcPamAuthenticate(service + 1, pwent->pw_name, NULL, passwd) ==
- PAM_SUCCESS;
- }
- #elif defined(SIA)
- {
- char *Argv[2] = { "dtsession", NULL };
- SIAENTITY *se = NULL;
- int code;
- char * pw_name;
- uid_t real_uid;
- real_uid = getuid();
- if (-1 == seteuid(0))
- return FALSE;
- if (passwd == NULL)
- {
- /*
- * Caller just checking if it is possible to access
- * password file (ie is dtsession suid bit set properly).
- */
- seteuid(real_uid);
- return TRUE;
- }
- if (name && name[0])
- pw_name = name;
- else if (uid == 0)
- pw_name = "root";
- else
- pw_name = getlogin();
- if ( sia_ses_init(&se, 1, Argv, (char *)NULL,
- pw_name, NULL, 0 /* don't collect info */,
- NULL) != SIASUCCESS)
- {
- seteuid(real_uid);
- return FALSE;
- }
-
- se->password = (char *)malloc(strlen(passwd) + 1);
- if ( se->password == (char *)NULL )
- {
- sia_ses_release(&se);
- seteuid(real_uid);
- return FALSE;
- }
- strcpy(se->password, passwd);
- code = sia_ses_reauthent (NULL, se);
- sia_ses_release(&se);
- seteuid(real_uid);
- if ( code == SIASUCCESS )
- return TRUE;
- else
- return FALSE;
- }
-
- #elif defined(__linux__)
- {
- struct passwd *pwent = NULL;
- char *p, *q;
- char *crypt();
- Boolean rc = True;
- Boolean done = False;
- struct spwd *sp = NULL;
- if(smGD.secureSystem)
- {
- SM_SETEUID(smGD.unLockUID);
- }
- /*
- * Get password entry for 'name' or 'uid'.
- */
- if (CanReAuthenticate(name, uid, passwd, &pwent, &sp) == False)
- {
- /*
- * Can't get entry.
- */
- rc = False;
- done = True;
- }
- if(smGD.secureSystem)
- {
- SM_SETEUID(smGD.runningUID);
- }
- if (done == False)
- {
- if (pwent->pw_passwd == NULL || pwent->pw_passwd[0] == '*')
- {
- /* check sp */
- if (sp == NULL || sp->sp_pwdp == NULL)
- {
- /*
- * Could not read password.
- */
- rc = False;
- done = True;
- }
- }
- }
- if (done == False)
- {
- if (passwd == NULL)
- {
- /*
- * Caller just checking if it is possible to access
- * password file (ie is dtsession suid bit set properly).
- */
- rc = True;
- done = True;
- }
- }
- if (done == False)
- {
- /*
- * Check password.
- */
- if (sp != NULL && !strcmp(sp->sp_pwdp, crypt(passwd,sp->sp_pwdp)))
- { /* a shadow match */
- rc = True;
- done = True;
- }
- else if (pwent != NULL &&
- !strcmp(pwent->pw_passwd, crypt(passwd, pwent->pw_passwd)))
- { /* passwd match */
- rc = True;
- done = True;
- }
- else
- { /* failure dude! */
- rc = False;
- done = True;
- }
- }
- endpwent();
- endspent();
- return(rc);
- }
- #else
- {
- register struct passwd *pwent;
- char *p, *q;
- char *crypt();
- Boolean rc = True;
- Boolean done = False;
- #ifdef SVR4
- struct spwd *sp=NULL;
- #endif
- if(smGD.secureSystem)
- {
- SM_SETEUID(smGD.unLockUID);
- }
- #ifdef SVR4
- /*
- * Get shadow password entry for 'name' or 'uid'.
- */
- if (name == NULL)
- {
- pwent = getpwuid(uid);
- if (pwent != NULL)
- {
- name = pwent->pw_name;
- }
- }
- if (name == NULL ||
- (sp = getspnam(name)) == NULL
- )
- {
- /*
- * Can't get entry.
- */
- rc = False;
- done = True;
- }
- #else /* SVR4 */
- /*
- * Get password entry for 'name' or 'uid'.
- */
- #if defined(__OpenBSD__)
- if ((pwent = (name == NULL ?
- getpwuid_shadow(uid) : getpwnam_shadow(name))) == NULL)
- #else
- if ((pwent = (name == NULL ? getpwuid(uid) : getpwnam(name))) == NULL)
- #endif
- {
- /*
- * Can't get entry.
- */
- rc = False;
- done = True;
- }
- #endif /* SVR4 */
- if(smGD.secureSystem)
- {
- SM_SETEUID(smGD.runningUID);
- }
- if (done == False)
- {
- if (
- pwent->pw_passwd == NULL
- || pwent->pw_passwd[0] == '*'
- #ifdef SVR4
- || sp == NULL
- #endif
- )
- {
- /*
- * Could not read password.
- */
- rc = False;
- done = True;
- }
- }
- if (done == False)
- {
- if (passwd == NULL)
- {
- /*
- * Caller just checking if it is possible to access
- * password file (ie is dtsession suid bit set properly).
- */
- rc = True;
- done = True;
- }
- }
- if (done == False)
- {
- /*
- * Check password.
- */
- #ifdef SVR4
- if (strcmp(crypt(passwd,sp->sp_pwdp),sp->sp_pwdp) != 0)
- #else
- if (strcmp(pwent->pw_passwd, crypt(passwd, pwent->pw_passwd)) != 0)
- #endif
- {
- /*
- * Password incorrect.
- */
- rc = False;
- done = True;
- }
- }
- endpwent();
- #ifdef SVR4
- endspent();
- #endif
- return(rc);
- }
- #endif /* SIA */
- /*************************************<->*************************************
- *
- * Authenticate (name, uid, passwd)
- *
- *
- * Description:
- * -----------
- *
- *
- * Inputs:
- * ------
- *
- *
- * Outputs:
- * -------
- *
- * Comments:
- * --------
- *
- *************************************<->***********************************/
- #if defined (_AIX) && defined(_POWER)
- static Boolean
- Authenticate(
- char *name,
- uid_t uid,
- char *passwd )
- {
- register struct passwd *pwent;
- char *p, *q;
- char *crypt();
- Boolean rc = True;
- Boolean done = False;
- int arc;
- int reenter;
- char *newname = NULL;
- char *msg;
- if(smGD.secureSystem)
- {
- SM_SETEUID(smGD.unLockUID);
- }
- /*
- * Map uid to name.
- */
- if (name == NULL)
- {
- pwent = getpwuid(uid);
- if (pwent != NULL)
- {
- name = newname = strdup(pwent->pw_name);
- }
- endpwent();
- }
-
- /*
- * Authenticate user. Note: normally, we should check 'reenter' to
- * see if the user has another challenge. Since the dtsession screen
- * lock i/f does not yet have the support, our policy is to let the
- * user back in if they pass the first (password) challenge.
- */
- arc = authenticate(name, passwd, &reenter, &msg);
- if(smGD.secureSystem)
- {
- SM_SETEUID(smGD.runningUID);
- }
- if (msg) free(msg);
- if (newname) free(newname);
- return(arc == 0 ? True : False);
- }
- #endif /* _AIX && _POWER */
|