SmLock.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $XConsortium: SmLock.c /main/8 1996/10/30 11:13:55 drk $ */
  24. /* *
  25. * (c) Copyright 1993, 1994 Hewlett-Packard Company *
  26. * (c) Copyright 1993, 1994 International Business Machines Corp. *
  27. * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
  28. * (c) Copyright 1993, 1994 Novell, Inc. *
  29. */
  30. /*************************************<+>*************************************
  31. *****************************************************************************
  32. **
  33. ** File: SmLock.c
  34. **
  35. ** Project: HP DT Session Manager (dtsession)
  36. **
  37. ** Description:
  38. ** -----------
  39. ** In charge of locking and unlocking the display in response from
  40. ** the front panel to so.
  41. **
  42. **
  43. **
  44. *******************************************************************
  45. ** (c) Copyright Hewlett-Packard Company, 1990. All rights are
  46. ** reserved. Copying or other reproduction of this program
  47. ** except for archival purposes is prohibited without prior
  48. ** written consent of Hewlett-Packard Company.
  49. ********************************************************************
  50. **
  51. **
  52. **
  53. *****************************************************************************
  54. *************************************<+>*************************************/
  55. #include <stdio.h>
  56. #include <errno.h>
  57. #include <pwd.h>
  58. #include <string.h>
  59. #include <fcntl.h>
  60. #ifdef SIA
  61. #include <sia.h>
  62. #endif
  63. #ifdef USE_HP_SPECIFIC_XLIB
  64. #include <X11/XHPlib.h>
  65. #endif /* USE_HP_SPECIFIC_XLIB */
  66. #include <X11/Intrinsic.h>
  67. #include <Xm/Xm.h>
  68. #include <Dt/UserMsg.h>
  69. #include <Dt/Indicator.h>
  70. #include <Tt/tttk.h>
  71. #ifdef SVR4
  72. # include <shadow.h>
  73. #endif
  74. #if defined(__linux__)
  75. # include <shadow.h>
  76. #endif
  77. #if defined(CSRG_BASED)
  78. #include <sys/types.h>
  79. #include <pwd.h>
  80. #endif
  81. #ifdef HAS_PAM_LIBRARY
  82. #include <security/pam_appl.h>
  83. #include <Dt/SvcPam.h>
  84. #endif
  85. #include "Sm.h"
  86. #include "SmGlobals.h"
  87. #include "SmUI.h"
  88. #include "SmError.h"
  89. #include "SmLock.h"
  90. #include "SmScreen.h"
  91. /*
  92. * Variables global to this module only
  93. */
  94. /*
  95. * Global timer value
  96. */
  97. static XtIntervalId timerId, lockTimeId, lockDelayId, cycleId, flash_id;
  98. /*
  99. * Global grab widget
  100. */
  101. static Widget grabWidget;
  102. /*
  103. * Lock dialog visibility
  104. */
  105. static Boolean lockDlgVisible;
  106. #ifdef LOCK_SERVER_ACCESS
  107. /*
  108. * Server Access Control Information
  109. */
  110. static Boolean RestrictingAccess = False;
  111. static XHostAddress *hostList;
  112. static Bool hostListActive;
  113. static int hostListLen;
  114. #endif
  115. /*
  116. * Local Functions
  117. */
  118. static void FinishLocking(Widget, XtPointer, XEvent *, Boolean *);
  119. static void RecolorCursor( void ) ;
  120. static void EventDetected( Widget, XtPointer, XEvent *, Boolean *) ;
  121. static void CheckString( char *, int ) ;
  122. static Boolean CheckPassword( char * ) ;
  123. #if defined (_AIX) && defined (_POWER)
  124. static Boolean Authenticate( char *, uid_t, char * ) ;
  125. #else
  126. #define Authenticate(A,B,C) localAuthenticate(A,B,C)
  127. #endif
  128. static Boolean localAuthenticate( char *, uid_t, char * ) ;
  129. static void UnlockDisplay( Boolean, Boolean ) ;
  130. static void TakeDownLogin( XtPointer, XtIntervalId * ) ;
  131. static void PutUpLogin( Boolean, Boolean ) ;
  132. static void LockAttemptFailed( XtPointer, XtIntervalId *) ;
  133. static void RequirePassword( XtPointer, XtIntervalId *) ;
  134. static void CycleSaver( XtPointer, XtIntervalId *) ;
  135. static void BlinkCaret( XtPointer, XtIntervalId *) ;
  136. #if defined(__linux__)
  137. /* #define JET_AUTHDEBUG */
  138. /* Test for re-auth ability - see if we can re-authenticate via pwd,
  139. * shadow, or NIS
  140. */
  141. static Boolean CanReAuthenticate(char *name, uid_t uid, char *passwd,
  142. struct passwd **pwent, struct spwd **spent)
  143. {
  144. if (!pwent)
  145. return False;
  146. *pwent = (name == NULL) ? getpwuid(uid) : getpwnam(name);
  147. if (!*pwent)
  148. return False;
  149. *spent = getspnam((*pwent)->pw_name);
  150. #ifdef JET_AUTHDEBUG
  151. fprintf(stderr, "CanReAuthenticate(): uid: %d name: '%s' errno %d %s %s %s\n",
  152. uid,
  153. (name) ? name : "NULL",
  154. errno,
  155. (*pwent) ? "PWENT" : "NULL",
  156. (*spent) ? "SPENT" : "NULL",
  157. (name) ? name : "NULL");
  158. #endif
  159. /* some checking for aging stuff on RedPhat */
  160. if (*pwent && (*pwent)->pw_passwd)
  161. {
  162. char *loc;
  163. if ((loc = strchr((*pwent)->pw_passwd, ',')) != NULL)
  164. *loc = '\0';
  165. #ifdef JET_AUTHDEBUG
  166. fprintf(stderr, "CanReAuthenticate(): pw: '%s'\n",
  167. (*pwent)->pw_passwd);
  168. #endif
  169. }
  170. if (*spent && (*spent)->sp_pwdp)
  171. {
  172. char *loc;
  173. if ((loc = strchr((*spent)->sp_pwdp, ',')) != NULL)
  174. *loc = '\0';
  175. }
  176. if (*pwent == NULL)
  177. { /* if we can't get this, we're screwed. */
  178. #ifdef JET_AUTHDEBUG
  179. fprintf(stderr, "CanReAuthenticate(): PWENT == NULL - FALSE\n");
  180. #endif
  181. return False;
  182. }
  183. if ((*pwent)->pw_passwd == NULL)
  184. {
  185. #ifdef JET_AUTHDEBUG
  186. fprintf(stderr, "CanReAuthenticate(): (*pwent)->pw_passwd == NULL - FALSE\n");
  187. #endif
  188. return False;
  189. }
  190. /* ok, now we have the prequisite data, look first to see if the
  191. * passwd field is larger than 1 char - implying NIS, or a shadowed
  192. * system. if not look for *spent being non-NULL
  193. */
  194. if (*spent == NULL)
  195. { /* if it's null, lets check for the NIS case */
  196. if (strlen((*pwent)->pw_passwd) <= 1)
  197. {
  198. #ifdef JET_AUTHDEBUG
  199. fprintf(stderr, "strlen((*pwent)->pw_passwd) <= 1\n");
  200. #endif
  201. return False; /* not NIS */
  202. }
  203. }
  204. /* supposedly we have valid data */
  205. #ifdef JET_AUTHDEBUG
  206. fprintf(stderr, "CanReAuthenticate(): TRUE\n");
  207. #endif
  208. return True;
  209. }
  210. #endif /* linux */
  211. /*************************************<->*************************************
  212. *
  213. * LockDisplay ()
  214. *
  215. *
  216. * Description:
  217. * -----------
  218. * Calls the routines that are in charge of locking the display.
  219. *
  220. *
  221. * Inputs:
  222. * ------
  223. * lockNow - request to lock the display immediately
  224. *
  225. * Outputs:
  226. * -------
  227. *
  228. * Comments:
  229. * --------
  230. *
  231. *************************************<->***********************************/
  232. /*
  233. * Place holders for the lock position
  234. */
  235. static Position visibleY;
  236. static Position hiddenY;
  237. void
  238. LockDisplay(
  239. Boolean lockNow)
  240. {
  241. register int i;
  242. int screenNum;
  243. Widget parent = NULL, lockDlg;
  244. XColor xcolors[2];
  245. struct passwd *pw;
  246. Boolean secure;
  247. int lockDelay;
  248. int rc;
  249. timerId = lockTimeId = lockDelayId = cycleId = flash_id = (XtIntervalId)0;
  250. /*
  251. * coverScreen
  252. * 0 - screen will not be covered, nor will external screen saver run
  253. * 1 - screen will be covered, external screen saver may be run
  254. *
  255. * lockDelay
  256. * -1 = no password required to unlock display
  257. * 0 = password always required to unlock display
  258. * N = password required to unlock display after N seconds
  259. */
  260. if (smSaverRes.saverTimeout == 0)
  261. {
  262. smGD.coverScreen = 0;
  263. lockDelay = 0;
  264. }
  265. else if (lockNow || smSaverRes.lockTimeout > 0)
  266. {
  267. smGD.coverScreen = 1;
  268. if (lockNow)
  269. lockDelay = 0;
  270. else if (smSaverRes.lockTimeout == 0)
  271. lockDelay = -1;
  272. else if (smSaverRes.lockTimeout <= smSaverRes.saverTimeout)
  273. lockDelay = 0;
  274. else
  275. lockDelay = smSaverRes.lockTimeout - smSaverRes.saverTimeout;
  276. }
  277. else
  278. {
  279. smGD.coverScreen = 1;
  280. lockDelay = -1;
  281. }
  282. /*
  283. * Before anything is done make sure we can unlock if we lock.
  284. */
  285. if (localAuthenticate(NULL, getuid(), NULL) == False)
  286. {
  287. Tt_message msg;
  288. PrintError(DtError, smNLS.trustedSystemErrorString);
  289. XBell(smGD.display, 100);
  290. /*
  291. * Tell the Workspace Manager to quit blinking
  292. */
  293. msg = tttk_message_create( 0, TT_NOTICE, TT_SESSION, 0,
  294. "DtActivity_Began", 0 );
  295. tt_message_send( msg );
  296. tt_message_destroy( msg );
  297. SetSystemReady();
  298. return;
  299. }
  300. if(((smDD.lockCoverDialog == NULL) && (smGD.coverScreen == True)) ||
  301. ((smDD.lockDialog == NULL) && (smGD.coverScreen == False)))
  302. {
  303. /*
  304. * Set up the grab widget in here
  305. */
  306. grabWidget = NULL;
  307. /*
  308. * If the user has specified cover - create the cover dialog
  309. */
  310. screenNum = DefaultScreen(smGD.display);
  311. if(smGD.coverScreen == True)
  312. {
  313. for(i = (smGD.numSavedScreens - 1);i >= 0;i--)
  314. {
  315. if(i == screenNum)
  316. {
  317. smDD.coverDialog[i] = CreateCoverDialog(i, True);
  318. parent = smDD.coverDrawing[i];
  319. }
  320. else
  321. {
  322. smDD.coverDialog[i] = CreateCoverDialog(i, False);
  323. }
  324. }
  325. smDD.lockCoverDialog = CreateLockDialogWithCover(parent);
  326. }
  327. /*
  328. * Create the lock dialog if the user has specified that
  329. */
  330. if((smDD.lockDialog == NULL) && (smGD.coverScreen == False))
  331. {
  332. smDD.lockDialog = CreateLockDialog();
  333. /*
  334. * Get colors for the password cursor
  335. */
  336. i = 0;
  337. XtSetArg(uiArgs[i], XmNtopShadowColor, &(xcolors[0]));i++;
  338. XtSetArg(uiArgs[i], XmNbottomShadowColor, &(xcolors[1]));i++;
  339. XtGetValues(smDD.lockDialog, uiArgs, i);
  340. smGD.backgroundPix = xcolors[0].pixel;
  341. smGD.foregroundPix = xcolors[1].pixel;
  342. if (smGD.backgroundPix == smGD.foregroundPix)
  343. {
  344. smGD.backgroundPix = smGD.whitePixel;
  345. smGD.foregroundPix = smGD.blackPixel;
  346. }
  347. }
  348. }
  349. /*
  350. * Wait for a visibility event to occur on the window so that
  351. * we can grab it
  352. */
  353. if(smGD.coverScreen == True)
  354. {
  355. smGD.lockCursor = smGD.blankCursor;
  356. grabWidget = smDD.coverDialog[0];
  357. lockDlg = smDD.lockCoverDialog;
  358. lockDlgVisible = False; /* mappedWhenManaged False */
  359. }
  360. else
  361. {
  362. smGD.lockCursor = smGD.padlockCursor;
  363. grabWidget = smDD.lockDialog;
  364. lockDlg = smDD.lockDialog;
  365. visibleY = hiddenY = -1;
  366. }
  367. /*
  368. * Note: grabWidget must be mapped in order to grab it. This means
  369. * that if coverScreen is True, smDD.coverDialog[0] must be mapped
  370. * immediately and if coverScreen is False, smDD.lockDialog must be
  371. * mapped immediately. Also, if a grabWidget is unmapped, the grab
  372. * is lost. Ah X.
  373. */
  374. XtAddEventHandler(grabWidget, VisibilityChangeMask,
  375. False, FinishLocking, NULL);
  376. XtManageChild(lockDlg);
  377. if(smGD.coverScreen == True) {
  378. flash_id = XtAppAddTimeOut(smGD.appCon,
  379. 1000, BlinkCaret,smDD.indLabel[1]);
  380. }
  381. else{
  382. flash_id = XtAppAddTimeOut(smGD.appCon,
  383. 1000, BlinkCaret,smDD.indLabel[0]);
  384. }
  385. if (lockDelay > 0)
  386. {
  387. /*
  388. * Wait for 'lockDelay' seconds before requiring a password.
  389. */
  390. lockDelayId = XtAppAddTimeOut(smGD.appCon,
  391. lockDelay*1000, RequirePassword, NULL);
  392. }
  393. else if (lockDelay == 0)
  394. {
  395. /*
  396. * Immediately require a password to unlock the display.
  397. */
  398. smGD.lockedState = LOCKED;
  399. PutUpLogin(True, False); /* map, but don't set timeout */
  400. }
  401. if (smGD.coverScreen == True && smSaverRes.cycleTimeout > 0)
  402. {
  403. /*
  404. * Cycle to next saver in 'cycleTimeout' seconds.
  405. */
  406. cycleId = XtAppAddTimeOut(smGD.appCon,
  407. smSaverRes.cycleTimeout*1000, CycleSaver, NULL);
  408. }
  409. if(smGD.coverScreen == True)
  410. {
  411. for(i = (smGD.numSavedScreens - 1);i >= 0;i--)
  412. {
  413. XtPopup(smDD.coverDialog[i], XtGrabNone);
  414. }
  415. }
  416. /*
  417. * Add an event handler for when the keyboard and pointer are grabbed
  418. */
  419. XtAddEventHandler(grabWidget,
  420. (KeyPressMask | ButtonPressMask | PointerMotionMask),
  421. False, EventDetected, NULL);
  422. /** wait 90 seconds for lock dialog to come up **/
  423. lockTimeId = XtAppAddTimeOut(smGD.appCon,
  424. 90000, LockAttemptFailed, lockDlg);
  425. return;
  426. }
  427. /*************************************<->*************************************
  428. *
  429. * FinishLocking ()
  430. *
  431. *
  432. * Description:
  433. * -----------
  434. * After the lock dialog is up - do the grab and lock the display
  435. *
  436. *
  437. * Inputs:
  438. * ------
  439. *
  440. * Outputs:
  441. * -------
  442. *
  443. * Comments:
  444. * --------
  445. *
  446. *************************************<->***********************************/
  447. static void
  448. FinishLocking(Widget wid,
  449. XtPointer ptr,
  450. XEvent *ev,
  451. Boolean *bl)
  452. {
  453. int i,j;
  454. Boolean kbdGrabbed, pointerGrabbed;
  455. int rc;
  456. if (lockTimeId == (XtIntervalId)0)
  457. return;
  458. XtRemoveTimeOut(lockTimeId);
  459. lockTimeId = (XtIntervalId)0;
  460. XtRemoveEventHandler(wid, VisibilityChangeMask,
  461. False, FinishLocking, NULL);
  462. XSync(smGD.display, 0);
  463. i = 0;
  464. XtSetArg(uiArgs[i], XmNy, &visibleY);i++;
  465. XtGetValues(wid, uiArgs, i);
  466. hiddenY = (Position) DisplayHeight(smGD.display, smGD.screen) + 15;
  467. /*
  468. * Color the cursor for this color scheme
  469. */
  470. RecolorCursor();
  471. XSync(smGD.display, 0);
  472. /*
  473. * grab control of the keyboard for the entire display
  474. */
  475. rc = XtGrabKeyboard(grabWidget, False,
  476. GrabModeAsync, GrabModeAsync,
  477. CurrentTime);
  478. kbdGrabbed = (rc == GrabSuccess);
  479. #ifdef USE_HP_SPECIFIC_XLIB
  480. XHPDisableReset(smGD.display);
  481. #endif /* USE_HP_SPECIFIC_XLIB */
  482. #if defined (AIXV3) && !defined(_POWER)
  483. if(smGD.secureSystem)
  484. {
  485. SM_SETEUID(smGD.unLockUID);
  486. AixEnableHftRing(0);
  487. SM_SETEUID(smGD.runningUID);
  488. }
  489. #endif
  490. pointerGrabbed = (XtGrabPointer(grabWidget, False,
  491. ButtonPressMask|PointerMotionMask,
  492. GrabModeAsync, GrabModeAsync,
  493. None, smGD.lockCursor, CurrentTime)
  494. == GrabSuccess);
  495. {
  496. pointerGrabbed = (XtGrabPointer(grabWidget, False,
  497. ButtonPressMask|PointerMotionMask,
  498. GrabModeAsync, GrabModeAsync,
  499. None, smGD.lockCursor, CurrentTime)
  500. == GrabSuccess);
  501. }
  502. /*
  503. * If the grab failed - try 3 more times and give up
  504. */
  505. if((kbdGrabbed == False) || (pointerGrabbed == False))
  506. {
  507. for(j = 0;(j < 3) && ((pointerGrabbed == False) ||
  508. (kbdGrabbed == False));j++)
  509. {
  510. /*
  511. * If a grab fails try one more time and then give up
  512. */
  513. if(kbdGrabbed == False)
  514. {
  515. sleep(1);
  516. kbdGrabbed = (XtGrabKeyboard(grabWidget, False,
  517. GrabModeAsync, GrabModeAsync,
  518. CurrentTime) == GrabSuccess);
  519. }
  520. if(pointerGrabbed == False)
  521. {
  522. sleep(1);
  523. pointerGrabbed = (XtGrabPointer(grabWidget, False,
  524. ButtonPressMask |
  525. PointerMotionMask,
  526. GrabModeAsync,
  527. GrabModeAsync,
  528. None, smGD.lockCursor,
  529. CurrentTime)
  530. == GrabSuccess);
  531. }
  532. }
  533. }
  534. /*
  535. * Set status variable to lock if the lock has succeeded
  536. */
  537. if((pointerGrabbed != True) || (kbdGrabbed != True))
  538. {
  539. PrintError(DtError, smNLS.cantLockErrorString);
  540. smGD.lockedState = UNLOCKED;
  541. UnlockDisplay(pointerGrabbed, kbdGrabbed);
  542. }
  543. else
  544. {
  545. #ifdef LOCK_SERVER_ACCESS
  546. /*
  547. * Wipe & enable X server access control list
  548. */
  549. hostList = XListHosts(smGD.display,
  550. &hostListLen, (Bool *) &hostListActive);
  551. XRemoveHosts(smGD.display, hostList, hostListLen);
  552. XEnableAccessControl(smGD.display);
  553. RestrictingAccess = True;
  554. #endif
  555. PutUpLogin(False, True); /* already mapped, but set timeout */
  556. /*
  557. * Start external screen saver.
  558. */
  559. if (smGD.coverScreen)
  560. {
  561. StartScreenSaver();
  562. }
  563. }
  564. return;
  565. }
  566. /*************************************<->*************************************
  567. *
  568. * CreateLockCursor ()
  569. *
  570. *
  571. * Description:
  572. * -----------
  573. * Creates a padlock cursor if the user has specified lock. Creates a
  574. * blank cursor if the user has specified cover. Both are specified in the
  575. * users resource file.
  576. *
  577. *
  578. *
  579. * Inputs:
  580. * ------
  581. * buttonForm = widget from which cursor gets its color
  582. * smGD.coverScreen = (global) cover screen or put up a padlock
  583. *
  584. *
  585. * Outputs:
  586. * -------
  587. * smGD.lockCursor = (global) cursor when lock is active (blank or padlock)
  588. *
  589. * Comments:
  590. * --------
  591. *
  592. *************************************<->***********************************/
  593. #define lock_m_hot_x 16
  594. #define lock_m_hot_y 16
  595. #define lock_m_bm_width 32
  596. #define lock_m_bm_height 32
  597. static unsigned char lock_m_bm_bits[] = {
  598. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x0f, 0x00,
  599. 0x00, 0xfc, 0x9f, 0x00, 0x00, 0x0e, 0x90, 0x01, 0x00, 0x06, 0x80, 0x01,
  600. 0x00, 0x06, 0x80, 0x01, 0x00, 0x06, 0x80, 0x01, 0x00, 0x06, 0x80, 0x01,
  601. 0x00, 0x06, 0x80, 0x01, 0x00, 0x06, 0x80, 0x01, 0x00, 0x06, 0x80, 0x01,
  602. 0x00, 0x06, 0x80, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x0c,
  603. 0x80, 0xaa, 0xaa, 0x0e, 0x00, 0x55, 0x55, 0x0f, 0x80, 0xaa, 0xaa, 0x0e,
  604. 0x00, 0x55, 0x55, 0x0f, 0x80, 0xaa, 0xaa, 0x0e, 0x00, 0x55, 0x55, 0x0f,
  605. 0x80, 0xaa, 0xaa, 0x0e, 0x00, 0x55, 0x55, 0x0f, 0x80, 0xaa, 0xaa, 0x0e,
  606. 0x00, 0x55, 0x55, 0x0f, 0x80, 0xaa, 0xaa, 0x0e, 0x00, 0x55, 0x55, 0x0f,
  607. 0x80, 0xaa, 0xaa, 0x0e, 0x00, 0x55, 0x55, 0x0f, 0x80, 0xaa, 0xaa, 0x0e,
  608. 0xc0, 0xff, 0xff, 0x0f, 0xe0, 0xff, 0xff, 0x0f};
  609. #define lock_m_m_bm_width 32
  610. #define lock_m_m_bm_height 32
  611. static unsigned char lock_m_m_bm_bits[] = {
  612. 0x00, 0xf8, 0x1f, 0x00, 0x00, 0xfe, 0x7f, 0x00, 0x00, 0xff, 0xff, 0x00,
  613. 0x00, 0xff, 0xff, 0x00, 0x80, 0x0f, 0xf0, 0x01, 0x80, 0x07, 0xe0, 0x01,
  614. 0x80, 0x07, 0xe0, 0x01, 0x80, 0x07, 0xe0, 0x01, 0x80, 0x07, 0xe0, 0x01,
  615. 0x80, 0x07, 0xe0, 0x01, 0x80, 0x07, 0xe0, 0x01, 0x80, 0x07, 0xe0, 0x01,
  616. 0x80, 0x07, 0xe0, 0x01, 0xf0, 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0x0f,
  617. 0xf0, 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0x0f,
  618. 0xf0, 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0x0f,
  619. 0xf0, 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0x0f,
  620. 0xf0, 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0x0f,
  621. 0xf0, 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0x0f,
  622. 0xf0, 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0x0f};
  623. #define lock_s_hot_x 7
  624. #define lock_s_hot_y 8
  625. #define lock_s_bm_width 13
  626. #define lock_s_bm_height 16
  627. static unsigned char lock_s_bm_bits[] = {
  628. 0x00, 0x02, 0x00, 0x04, 0xf0, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
  629. 0x00, 0x00, 0xa8, 0x1a, 0x54, 0x1d, 0xa8, 0x1a, 0x54, 0x1d, 0xa8, 0x1a,
  630. 0x54, 0x1d, 0xa8, 0x1a, 0x54, 0x1d, 0xfe, 0x1f};
  631. #define lock_s_m_bm_width 13
  632. #define lock_s_m_bm_height 16
  633. static unsigned char lock_s_m_bm_bits[] = {
  634. 0xf8, 0x03, 0xfc, 0x07, 0xfe, 0x0f, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e,
  635. 0xff, 0x1f, 0xff, 0x1f, 0xff, 0x1f, 0xff, 0x1f, 0xff, 0x1f, 0xff, 0x1f,
  636. 0xff, 0x1f, 0xff, 0x1f, 0xff, 0x1f, 0xff, 0x1f};
  637. void
  638. CreateLockCursor( void )
  639. {
  640. Pixmap source, mask;
  641. Colormap cmap = XDefaultColormap(smGD.display, smGD.screen);
  642. XColor xcolors[2];
  643. char noCursorBits = 0x1;
  644. if(InitCursorInfo() == False)
  645. {
  646. /*
  647. * Create the SMALL padlock cursor
  648. */
  649. source = XCreateBitmapFromData(smGD.display,
  650. XRootWindow(smGD.display,
  651. smGD.screen),
  652. (char *) lock_s_bm_bits,
  653. lock_s_bm_width,
  654. lock_s_bm_height);
  655. mask = XCreateBitmapFromData(smGD.display,
  656. XRootWindow(smGD.display,
  657. smGD.screen),
  658. (char *) lock_s_m_bm_bits,
  659. lock_s_m_bm_width,
  660. lock_s_m_bm_height);
  661. /* translate the Pixels into XColors */
  662. xcolors[0].pixel = smGD.blackPixel;
  663. xcolors[1].pixel = smGD.whitePixel;
  664. XQueryColors(smGD.display, cmap, xcolors, 2);
  665. /* create the padlock cursor */
  666. smGD.padlockCursor = XCreatePixmapCursor(smGD.display, source, mask,
  667. &(xcolors[0]), &(xcolors[1]),
  668. lock_s_hot_x,
  669. lock_s_hot_y);
  670. XFreePixmap(smGD.display, source);
  671. XFreePixmap(smGD.display, mask);
  672. }
  673. else
  674. {
  675. /*
  676. * Create the LARGE padlock cursor
  677. */
  678. source = XCreateBitmapFromData(smGD.display,
  679. XRootWindow(smGD.display,
  680. smGD.screen),
  681. (char *) lock_m_bm_bits,
  682. lock_m_bm_width,
  683. lock_m_bm_height);
  684. mask = XCreateBitmapFromData(smGD.display,
  685. XRootWindow(smGD.display,
  686. smGD.screen),
  687. (char *) lock_m_m_bm_bits,
  688. lock_m_m_bm_width,
  689. lock_m_m_bm_height);
  690. /* translate the Pixels into XColors */
  691. xcolors[0].pixel = smGD.blackPixel;
  692. xcolors[1].pixel = smGD.whitePixel;
  693. XQueryColors(smGD.display, cmap, xcolors, 2);
  694. /* create the padlock cursor */
  695. smGD.padlockCursor = XCreatePixmapCursor(smGD.display, source, mask,
  696. &(xcolors[0]), &(xcolors[1]),
  697. lock_m_hot_x,
  698. lock_m_hot_y);
  699. XFreePixmap(smGD.display, source);
  700. XFreePixmap(smGD.display, mask);
  701. }
  702. /*
  703. *
  704. * create the blank cursor
  705. */
  706. source = XCreateBitmapFromData(smGD.display,
  707. XRootWindow(smGD.display, smGD.screen),
  708. &noCursorBits, 1, 1);
  709. xcolors[0].pixel = smGD.blackPixel;
  710. XQueryColor(smGD.display, cmap, &(xcolors[0]));
  711. smGD.blankCursor = XCreatePixmapCursor(smGD.display, source, source,
  712. &(xcolors[0]), &(xcolors[0]),
  713. 0, 0);
  714. XFreePixmap(smGD.display, source);
  715. }
  716. /*************************************<->*************************************
  717. *
  718. * RecolorCursor ()
  719. *
  720. *
  721. * Description:
  722. * -----------
  723. * Recolors the padlock cursor to be the current color scheme. This has
  724. * to be done because XCreatePixmapCursor allocates colors instead of jusst
  725. * using a pixel value.
  726. *
  727. *
  728. *
  729. * Inputs:
  730. * ------
  731. * smGD.backgroundPix = Pixel value to use for background color
  732. * smGD.foregroundPix = Pixel value to use for foreground color
  733. *
  734. *
  735. * Outputs:
  736. * -------
  737. * smGD.lockCursor = (global) cursor when lock is active (padlock)
  738. *
  739. * Comments:
  740. * --------
  741. *
  742. *************************************<->***********************************/
  743. static void
  744. RecolorCursor( void )
  745. {
  746. Colormap cmap = XDefaultColormap(smGD.display, smGD.screen);
  747. XColor xcolors[2];
  748. /*
  749. * translate the Pixels into XColors
  750. */
  751. xcolors[0].pixel = smGD.foregroundPix;
  752. xcolors[1].pixel = smGD.backgroundPix;
  753. XQueryColors(smGD.display, cmap, xcolors, 2);
  754. /*
  755. * recolor the padlock cursor
  756. */
  757. XRecolorCursor(smGD.display, smGD.lockCursor, &(xcolors[0]),
  758. &(xcolors[1]));
  759. }
  760. /*************************************<->*************************************
  761. *
  762. * EventDetected (w, client_data, event)
  763. *
  764. *
  765. * Description:
  766. * -----------
  767. * Callback routine that detects an event when the display is locked.
  768. * If it's a correct password, it unlocks the display. Otherwise, it
  769. * just displays status. The event is detected by the popup login dialog.
  770. *
  771. *
  772. * Inputs:
  773. * ------
  774. * w = widget where event occurred
  775. * client_data = client specific data sent to callback
  776. * event = event that triggered callback
  777. *
  778. *
  779. * Outputs:
  780. * -------
  781. *
  782. * Comments:
  783. * --------
  784. *
  785. *************************************<->***********************************/
  786. static void
  787. EventDetected(
  788. Widget w,
  789. XtPointer client_data,
  790. XEvent *ev,
  791. Boolean *bl)
  792. {
  793. char str[256];
  794. int len;
  795. XKeyEvent *event = (XKeyEvent *) ev;
  796. if (smGD.lockedState == LOCKED)
  797. {
  798. if (lockDlgVisible == False)
  799. {
  800. /*
  801. * Anytime input is received - show the passwd dialog and
  802. * discard event. This is so a keypress event that causes
  803. * the passwd dialog to appear will not be used in the password.
  804. * CMVC 612.
  805. */
  806. PutUpLogin(True, True); /* map, and reset timeout */
  807. return;
  808. }
  809. PutUpLogin(False, True); /* already mapped, but reset timeout */
  810. }
  811. else
  812. {
  813. UnlockDisplay(True, True);
  814. return;
  815. }
  816. /*
  817. * If the detected event is anything but a keypress, processing is
  818. * complete after refreshing the status string.
  819. */
  820. if (event->type != KeyPress)
  821. return;
  822. /*
  823. * If XLookupString() returns anything (which it won't in the case of, say,
  824. * pressing the shift key or an arrow key), process it.
  825. */
  826. #ifdef USE_HP_SPECIFIC_XLIB
  827. if (len = XHPConvertLookup(event, str, sizeof(str), NULL, NULL,
  828. XHPGetEurasianCvt(smGD.display)))
  829. #else /* USE_HP_SPECIFIC_XLIB */
  830. if (len = XLookupString (event, str, sizeof(str), NULL, NULL))
  831. #endif /* USE_HP_SPECIFIC_XLIB */
  832. {
  833. if (smGD.lockedState == LOCKED)
  834. CheckString(str, len);
  835. }
  836. }
  837. /*************************************<->*************************************
  838. *
  839. * CheckString (s, i)
  840. *
  841. *
  842. * Description:
  843. * -----------
  844. * Check string entered by user. If it is a valid password, call routine to
  845. * unlock the display. Otherwise, just keep track of what we have until
  846. * the password is valid
  847. *
  848. *
  849. * Inputs:
  850. * ------
  851. * s = string passed in for checking
  852. * i = length of string
  853. *
  854. *
  855. * Outputs:
  856. * -------
  857. *
  858. * Comments:
  859. * --------
  860. *
  861. *************************************<->***********************************/
  862. static void
  863. CheckString(
  864. register char *s,
  865. register int i )
  866. {
  867. /* maximum supported length of password */
  868. #if defined(SIA)
  869. #define MAX_PASSWORD_LENGTH SIAMXPASSWORD
  870. #else
  871. /* seems to be reasonable maximal length */
  872. #define MAX_PASSWORD_LENGTH 65535
  873. #endif
  874. /* step when allocating/extending buffer */
  875. #define BUF_ALLOC_LEN 64
  876. /*
  877. * password rules:
  878. * - If pw_length > MAX_PASSWORD_LENGTH, we've gone over the limit and won't
  879. * accept any more.
  880. * - An ESC kills the line.
  881. */
  882. static char *passwd = NULL; /* password space */
  883. static int pw_buf_length = 0; /* length of allocated password buffer */
  884. static int pw_length = 0; /* password length */
  885. char * tmpptr;
  886. if (s == NULL)
  887. {
  888. /*
  889. * Clear password.
  890. */
  891. pw_length = 0;
  892. return;
  893. }
  894. for (; i>0; s++,i--)
  895. {
  896. /* extend buffer by BUF_ALLOC_LEN bytes if needed*/
  897. #ifdef JET_AUTHDEBUG
  898. fprintf(stderr, "CheckString: pw_length=%d\n",pw_length);
  899. #endif
  900. if (pw_length == pw_buf_length)
  901. {
  902. tmpptr = SM_REALLOC(passwd, pw_buf_length + BUF_ALLOC_LEN);
  903. if (!tmpptr) {
  904. PrintErrnoError(DtError, smNLS.cantMallocErrorString);
  905. return;
  906. }
  907. pw_buf_length += BUF_ALLOC_LEN;
  908. passwd = tmpptr;
  909. }
  910. switch(*s)
  911. {
  912. case '\010':
  913. if (pw_length)
  914. pw_length--; /* back up one character */
  915. break;
  916. case '':
  917. pw_length = 0; /* kill the character string */
  918. break;
  919. case '\n':
  920. case '\r':
  921. if (pw_length > MAX_PASSWORD_LENGTH)
  922. {
  923. pw_length = MAX_PASSWORD_LENGTH;
  924. }
  925. passwd[pw_length] = '\0'; /* terminate string */
  926. pw_length = 0; /* reset length */
  927. if (CheckPassword(passwd))
  928. {
  929. UpdatePasswdField(0);
  930. UnlockDisplay(True, True);
  931. return;
  932. }
  933. XBell(smGD.display, 100); /* wrong, laserbreath */
  934. break;
  935. default:
  936. if (pw_length < MAX_PASSWORD_LENGTH)
  937. {
  938. passwd[pw_length++] = *s; /* store character */
  939. }
  940. break;
  941. }
  942. }
  943. UpdatePasswdField(pw_length > MAX_PASSWORD_LENGTH ? MAX_PASSWORD_LENGTH : pw_length);
  944. }
  945. /*************************************<->*************************************
  946. *
  947. * CheckPassword (passwd)
  948. *
  949. *
  950. * Description:
  951. * -----------
  952. * Check the password to see if it is the user's, roots, or one of the
  953. * users specified in the host string
  954. *
  955. *
  956. * Inputs:
  957. * ------
  958. * passwd = password passed in
  959. *
  960. *
  961. * Outputs:
  962. * -------
  963. * True if it is a valid password, false otherwise.
  964. *
  965. * Comments:
  966. * --------
  967. *
  968. *************************************<->***********************************/
  969. static Boolean
  970. CheckPassword(
  971. char *passwd )
  972. {
  973. char *p, *q;
  974. char *keyholderbuf;
  975. if (Authenticate(NULL, getuid(), passwd) == True)
  976. {
  977. return(True); /* user password ok */
  978. }
  979. if (Authenticate(NULL, 0, passwd) == True)
  980. {
  981. return(True); /* root password ok */
  982. }
  983. /* check passwords of users specified as keyholders */
  984. if (smGD.keyholders == NULL)
  985. {
  986. return(False); /* no keyholders */
  987. }
  988. /* since strtok() is destructive, copy the keyholders string */
  989. keyholderbuf = (char *) SM_MALLOC(strlen(smGD.keyholders)+1);
  990. if(keyholderbuf == NULL)
  991. {
  992. PrintErrnoError(DtError, smNLS.cantMallocErrorString);
  993. return(False); /* no memory */
  994. }
  995. strcpy(keyholderbuf, smGD.keyholders);
  996. for (p = keyholderbuf; (q = strtok(p, ", \t")) != NULL; p = NULL)
  997. {
  998. if (Authenticate(q, -1, passwd) == True)
  999. {
  1000. SM_FREE(keyholderbuf);
  1001. return(True); /* keyholder password ok */
  1002. }
  1003. }
  1004. SM_FREE(keyholderbuf);
  1005. return(False); /* no matches */
  1006. }
  1007. /*************************************<->*************************************
  1008. *
  1009. * UnlockDisplay ()
  1010. *
  1011. *
  1012. * Description:
  1013. * -----------
  1014. * If the user has entered a correct password, unlock the display and
  1015. * uncover the root window.
  1016. *
  1017. *
  1018. * Inputs:
  1019. * ------
  1020. * pointerGrabbed - Boolean tells if pointer is currently grabbed
  1021. * kbdGrabbed - Boolean tells if keyboard is currently grabbed
  1022. *
  1023. *
  1024. * Outputs:
  1025. * -------
  1026. *
  1027. *
  1028. * Comments:
  1029. * --------
  1030. *
  1031. *************************************<->***********************************/
  1032. static void
  1033. UnlockDisplay(
  1034. Boolean pointerGrabbed,
  1035. Boolean kbdGrabbed)
  1036. {
  1037. int i;
  1038. Tt_message msg;
  1039. #ifdef LOCK_SERVER_ACCESS
  1040. /*
  1041. * Restore X server access state
  1042. */
  1043. if (RestrictingAccess) {
  1044. XAddHosts(smGD.display, hostList, hostListLen);
  1045. if (!hostListActive) XDisableAccessControl(smGD.display);
  1046. RestrictingAccess = False;
  1047. XFree((void *) hostList);
  1048. }
  1049. #endif
  1050. /*
  1051. * Stop external screen saver.
  1052. */
  1053. StopScreenSaver();
  1054. /*
  1055. * Remove the event handler to grab the events
  1056. */
  1057. XtRemoveEventHandler(grabWidget,
  1058. (KeyPressMask | ButtonPressMask | PointerMotionMask),
  1059. False, EventDetected, NULL);
  1060. /*
  1061. * Turn off alarms
  1062. */
  1063. if(lockDelayId != (XtIntervalId)0)
  1064. {
  1065. XtRemoveTimeOut(lockDelayId);
  1066. }
  1067. if(cycleId != (XtIntervalId)0)
  1068. {
  1069. XtRemoveTimeOut(cycleId);
  1070. }
  1071. if(timerId != (XtIntervalId)0)
  1072. {
  1073. XtRemoveTimeOut(timerId);
  1074. }
  1075. if(flash_id != (XtIntervalId)0)
  1076. {
  1077. XtRemoveTimeOut(flash_id);
  1078. }
  1079. if(pointerGrabbed == True)
  1080. {
  1081. XtUngrabPointer(grabWidget, CurrentTime);
  1082. }
  1083. if(kbdGrabbed == True)
  1084. {
  1085. XtUngrabKeyboard(grabWidget, CurrentTime);
  1086. }
  1087. #ifdef USE_HP_SPECIFIC_XLIB
  1088. XHPEnableReset(smGD.display);
  1089. #endif /* USE_HP_SPECIFIC_XLIB */
  1090. #if defined (AIXV3) && !defined(_POWER)
  1091. if(smGD.secureSystem)
  1092. {
  1093. SM_SETEUID(smGD.unLockUID);
  1094. AixEnableHftRing(1);
  1095. SM_SETEUID(smGD.runningUID);
  1096. }
  1097. #endif
  1098. XSync(smGD.display, 0);
  1099. /*
  1100. * Unmanage session lock dialogs. If LOCKDLG_PERSIST is undefined,
  1101. * destroy them. This is so the passwd dialog icon colors get freed
  1102. * since currently it uses a lot of colors.
  1103. */
  1104. if(smGD.coverScreen == False)
  1105. {
  1106. #if defined (LOCKDLG_PERSIST)
  1107. if (XtIsManaged(smDD.lockDialog))
  1108. {
  1109. XtUnmanageChild(smDD.lockDialog);
  1110. }
  1111. #else
  1112. XtDestroyWidget(smDD.lockDialog);
  1113. smDD.lockDialog = NULL;
  1114. #endif
  1115. }
  1116. else
  1117. {
  1118. #if defined (LOCKDLG_PERSIST)
  1119. if(!XtIsManaged(smDD.lockCoverDialog))
  1120. {
  1121. XtManageChild(smDD.lockCoverDialog);
  1122. }
  1123. for(i = (smGD.numSavedScreens - 1);i >= 0;i--)
  1124. {
  1125. XtPopdown(smDD.coverDialog[i]);
  1126. }
  1127. #else
  1128. for(i = (smGD.numSavedScreens - 1);i >= 0;i--)
  1129. {
  1130. XtDestroyWidget(smDD.coverDialog[i]);
  1131. smDD.coverDialog[i] = NULL;
  1132. }
  1133. smDD.lockCoverDialog = NULL;
  1134. #endif
  1135. }
  1136. smGD.lockedState = UNLOCKED;
  1137. XSync(smGD.display, 0);
  1138. /*
  1139. * Tell the Workspace Manager to unlock the display (depress the lock
  1140. * button)
  1141. if(smGD.bmsDead == False)
  1142. {
  1143. msg = tttk_message_create(0, TT_REQUEST, TT_SESSION, 0,
  1144. "Display_Unlock", 0);
  1145. tt_message_send(msg);
  1146. tt_message_destroy(msg);
  1147. }
  1148. */
  1149. SetSystemReady();
  1150. }
  1151. static Position visibleY = -1;
  1152. static Position hiddenY = -1;
  1153. /*************************************<->*************************************
  1154. *
  1155. * TakeDownLogin ()
  1156. *
  1157. *
  1158. * Description:
  1159. * -----------
  1160. * When a timeout occurs - take down the login screen by unmanaging it.
  1161. *
  1162. *
  1163. * Inputs:
  1164. * ------
  1165. *
  1166. *
  1167. * Outputs:
  1168. * -------
  1169. *
  1170. *
  1171. * Comments:
  1172. * --------
  1173. *
  1174. *************************************<->***********************************/
  1175. static void
  1176. TakeDownLogin(
  1177. XtPointer client_data,
  1178. XtIntervalId *id )
  1179. {
  1180. if (lockDlgVisible == True)
  1181. {
  1182. if (smGD.coverScreen == True)
  1183. {
  1184. XtUnmapWidget(smDD.lockCoverDialog);
  1185. }
  1186. else
  1187. {
  1188. if (hiddenY > -1)
  1189. {
  1190. int i = 0;
  1191. XtSetArg(uiArgs[i], XmNy, hiddenY);i++;
  1192. XtSetValues(smDD.lockDialog, uiArgs, i);
  1193. }
  1194. }
  1195. timerId = (XtIntervalId)0;
  1196. /*
  1197. * Clear partially entered password if any.
  1198. */
  1199. CheckString(NULL, 0);
  1200. lockDlgVisible = False;
  1201. XSync(smGD.display, 0);
  1202. }
  1203. }
  1204. /*************************************<->*************************************
  1205. *
  1206. * PutUpLogin ()
  1207. *
  1208. *
  1209. * Description:
  1210. * -----------
  1211. * Redisplays the cover and the login when necessary.
  1212. *
  1213. *
  1214. * Inputs:
  1215. * ------
  1216. *
  1217. *
  1218. * Outputs:
  1219. * -------
  1220. *
  1221. *
  1222. * Comments:
  1223. * --------
  1224. *
  1225. *************************************<->***********************************/
  1226. static void
  1227. PutUpLogin(
  1228. Boolean map,
  1229. Boolean timeout )
  1230. {
  1231. if (map == True && lockDlgVisible == False)
  1232. {
  1233. if (smGD.coverScreen == True)
  1234. {
  1235. XtMapWidget(smDD.lockCoverDialog);
  1236. }
  1237. else
  1238. {
  1239. if (visibleY > -1)
  1240. {
  1241. int i = 0;
  1242. XtSetArg(uiArgs[i], XmNy, visibleY);i++;
  1243. XtSetValues(smDD.lockDialog, uiArgs, i);
  1244. }
  1245. }
  1246. lockDlgVisible = True;
  1247. }
  1248. if (timeout == True)
  1249. {
  1250. if(timerId != (XtIntervalId)0)
  1251. {
  1252. XtRemoveTimeOut(timerId);
  1253. }
  1254. if(smRes.alarmTime > 0)
  1255. {
  1256. timerId = XtAppAddTimeOut(smGD.appCon,
  1257. (smRes.alarmTime * 1000),
  1258. TakeDownLogin,NULL);
  1259. }
  1260. }
  1261. XSync(smGD.display, 0);
  1262. }
  1263. /*************************************<->*************************************
  1264. *
  1265. * LockAttemptFailed ()
  1266. *
  1267. *
  1268. * Description:
  1269. * -----------
  1270. * Timed out trying to get a visibilitynotify on the lock
  1271. *
  1272. *
  1273. * Inputs:
  1274. * ------
  1275. *
  1276. *
  1277. * Outputs:
  1278. * -------
  1279. *
  1280. *
  1281. * Comments:
  1282. * --------
  1283. *
  1284. *************************************<->***********************************/
  1285. static void
  1286. LockAttemptFailed(XtPointer ptr,
  1287. XtIntervalId *invId)
  1288. {
  1289. Widget lockWid = (Widget) ptr;
  1290. PrintError(DtError, smNLS.cantLockErrorString);
  1291. smGD.lockedState = UNLOCKED;
  1292. XtRemoveEventHandler(lockWid, VisibilityChangeMask,
  1293. False, FinishLocking, NULL);
  1294. UnlockDisplay(False, False);
  1295. XSync(smGD.display, 0);
  1296. }
  1297. /*************************************<->*************************************
  1298. *
  1299. * RequirePassword ()
  1300. *
  1301. *
  1302. * Description:
  1303. * -----------
  1304. * Callback indicating a password is now required to unlock display.
  1305. *
  1306. *
  1307. * Inputs:
  1308. * ------
  1309. *
  1310. *
  1311. * Outputs:
  1312. * -------
  1313. *
  1314. *
  1315. * Comments:
  1316. * --------
  1317. *
  1318. *************************************<->***********************************/
  1319. static void
  1320. RequirePassword(XtPointer ptr,
  1321. XtIntervalId *invId)
  1322. {
  1323. smGD.lockedState = LOCKED;
  1324. }
  1325. /*************************************<->*************************************
  1326. *
  1327. * BlinkCaret ()
  1328. *
  1329. *
  1330. * Description:
  1331. * -----------
  1332. * blinks the caret in the password field
  1333. *
  1334. *
  1335. * Inputs:
  1336. * ------
  1337. *
  1338. *
  1339. * Outputs:
  1340. * -------
  1341. *
  1342. *
  1343. * Comments:
  1344. * --------
  1345. *
  1346. *************************************<->***********************************/
  1347. static void
  1348. BlinkCaret(XtPointer ptr,
  1349. XtIntervalId *invId)
  1350. {
  1351. static int flag = 1;
  1352. XmString tmpString;
  1353. int i;
  1354. /*
  1355. * Blink cursor to show the focus ..
  1356. */
  1357. if(flag){
  1358. tmpString = XmStringCreateLocalized (" " );
  1359. i = 0;
  1360. XtSetArg(uiArgs[i], XmNlabelString, tmpString); i++;
  1361. XtSetValues(ptr, uiArgs, i);
  1362. flag = 0;
  1363. }
  1364. else{
  1365. tmpString = XmStringCreateLocalized ("|");
  1366. i = 0;
  1367. XtSetArg(uiArgs[i], XmNlabelString, tmpString); i++;
  1368. XtSetValues(ptr, uiArgs, i);
  1369. flag = 1;
  1370. }
  1371. XmStringFree(tmpString);
  1372. flash_id = XtAppAddTimeOut(smGD.appCon, 1000,
  1373. BlinkCaret, ptr);
  1374. }
  1375. /*************************************<->*************************************
  1376. *
  1377. * CycleSaver ()
  1378. *
  1379. *
  1380. * Description:
  1381. * -----------
  1382. * Callback indicating we should cycle to next screen saver
  1383. *
  1384. *
  1385. * Inputs:
  1386. * ------
  1387. *
  1388. *
  1389. * Outputs:
  1390. * -------
  1391. *
  1392. *
  1393. * Comments:
  1394. * --------
  1395. *
  1396. *************************************<->***********************************/
  1397. static void
  1398. CycleSaver(XtPointer ptr,
  1399. XtIntervalId *invId)
  1400. {
  1401. /*
  1402. * Stop running screen saver, start a new one and reset timer.
  1403. */
  1404. StopScreenSaver();
  1405. StartScreenSaver();
  1406. cycleId = XtAppAddTimeOut(smGD.appCon, smSaverRes.cycleTimeout*1000,
  1407. CycleSaver, NULL);
  1408. }
  1409. /*************************************<->*************************************
  1410. *
  1411. * localAuthenticate (name, uid, passwd)
  1412. *
  1413. *
  1414. * Description:
  1415. * -----------
  1416. *
  1417. *
  1418. * Inputs:
  1419. * ------
  1420. *
  1421. *
  1422. * Outputs:
  1423. * -------
  1424. *
  1425. * Comments:
  1426. * --------
  1427. *
  1428. *************************************<->***********************************/
  1429. static Boolean
  1430. localAuthenticate(
  1431. char *name,
  1432. uid_t uid,
  1433. char *passwd )
  1434. #if defined(HAS_PAM_LIBRARY)
  1435. {
  1436. char *service;
  1437. struct passwd *pwent;
  1438. if (!(name && name[0])) name = NULL;
  1439. if (uid < 0) uid = 0;
  1440. if (!(name || passwd)) return True;
  1441. if (!passwd) return False;
  1442. if (!(pwent = name ? getpwnam(name) : getpwuid(uid))) return False;
  1443. endpwent();
  1444. if (!(service = strrchr(smGD.programName, '/'))) return False;
  1445. return _DtSvcPamAuthenticate(service + 1, pwent->pw_name, NULL, passwd) ==
  1446. PAM_SUCCESS;
  1447. }
  1448. #elif defined(SIA)
  1449. {
  1450. char *Argv[2] = { "dtsession", NULL };
  1451. SIAENTITY *se = NULL;
  1452. int code;
  1453. char * pw_name;
  1454. uid_t real_uid;
  1455. real_uid = getuid();
  1456. if (-1 == seteuid(0))
  1457. return FALSE;
  1458. if (passwd == NULL)
  1459. {
  1460. /*
  1461. * Caller just checking if it is possible to access
  1462. * password file (ie is dtsession suid bit set properly).
  1463. */
  1464. seteuid(real_uid);
  1465. return TRUE;
  1466. }
  1467. if (name && name[0])
  1468. pw_name = name;
  1469. else if (uid == 0)
  1470. pw_name = "root";
  1471. else
  1472. pw_name = getlogin();
  1473. if ( sia_ses_init(&se, 1, Argv, (char *)NULL,
  1474. pw_name, NULL, 0 /* don't collect info */,
  1475. NULL) != SIASUCCESS)
  1476. {
  1477. seteuid(real_uid);
  1478. return FALSE;
  1479. }
  1480. se->password = (char *)malloc(strlen(passwd) + 1);
  1481. if ( se->password == (char *)NULL )
  1482. {
  1483. sia_ses_release(&se);
  1484. seteuid(real_uid);
  1485. return FALSE;
  1486. }
  1487. strcpy(se->password, passwd);
  1488. code = sia_ses_reauthent (NULL, se);
  1489. sia_ses_release(&se);
  1490. seteuid(real_uid);
  1491. if ( code == SIASUCCESS )
  1492. return TRUE;
  1493. else
  1494. return FALSE;
  1495. }
  1496. #elif defined(__linux__)
  1497. {
  1498. struct passwd *pwent = NULL;
  1499. char *p, *q;
  1500. char *crypt();
  1501. Boolean rc = True;
  1502. Boolean done = False;
  1503. struct spwd *sp = NULL;
  1504. if(smGD.secureSystem)
  1505. {
  1506. SM_SETEUID(smGD.unLockUID);
  1507. }
  1508. /*
  1509. * Get password entry for 'name' or 'uid'.
  1510. */
  1511. if (CanReAuthenticate(name, uid, passwd, &pwent, &sp) == False)
  1512. {
  1513. /*
  1514. * Can't get entry.
  1515. */
  1516. rc = False;
  1517. done = True;
  1518. }
  1519. if(smGD.secureSystem)
  1520. {
  1521. SM_SETEUID(smGD.runningUID);
  1522. }
  1523. if (done == False)
  1524. {
  1525. if (pwent->pw_passwd == NULL || pwent->pw_passwd[0] == '*')
  1526. {
  1527. /* check sp */
  1528. if (sp == NULL || sp->sp_pwdp == NULL)
  1529. {
  1530. /*
  1531. * Could not read password.
  1532. */
  1533. rc = False;
  1534. done = True;
  1535. }
  1536. }
  1537. }
  1538. if (done == False)
  1539. {
  1540. if (passwd == NULL)
  1541. {
  1542. /*
  1543. * Caller just checking if it is possible to access
  1544. * password file (ie is dtsession suid bit set properly).
  1545. */
  1546. rc = True;
  1547. done = True;
  1548. }
  1549. }
  1550. if (done == False)
  1551. {
  1552. /*
  1553. * Check password.
  1554. */
  1555. if (sp != NULL && !strcmp(sp->sp_pwdp, crypt(passwd,sp->sp_pwdp)))
  1556. { /* a shadow match */
  1557. rc = True;
  1558. done = True;
  1559. }
  1560. else if (pwent != NULL &&
  1561. !strcmp(pwent->pw_passwd, crypt(passwd, pwent->pw_passwd)))
  1562. { /* passwd match */
  1563. rc = True;
  1564. done = True;
  1565. }
  1566. else
  1567. { /* failure dude! */
  1568. rc = False;
  1569. done = True;
  1570. }
  1571. }
  1572. endpwent();
  1573. endspent();
  1574. return(rc);
  1575. }
  1576. #else
  1577. {
  1578. register struct passwd *pwent;
  1579. char *p, *q;
  1580. char *crypt();
  1581. Boolean rc = True;
  1582. Boolean done = False;
  1583. #ifdef SVR4
  1584. struct spwd *sp=NULL;
  1585. #endif
  1586. if(smGD.secureSystem)
  1587. {
  1588. SM_SETEUID(smGD.unLockUID);
  1589. }
  1590. #ifdef SVR4
  1591. /*
  1592. * Get shadow password entry for 'name' or 'uid'.
  1593. */
  1594. if (name == NULL)
  1595. {
  1596. pwent = getpwuid(uid);
  1597. if (pwent != NULL)
  1598. {
  1599. name = pwent->pw_name;
  1600. }
  1601. }
  1602. if (name == NULL ||
  1603. (sp = getspnam(name)) == NULL
  1604. )
  1605. {
  1606. /*
  1607. * Can't get entry.
  1608. */
  1609. rc = False;
  1610. done = True;
  1611. }
  1612. #else /* SVR4 */
  1613. /*
  1614. * Get password entry for 'name' or 'uid'.
  1615. */
  1616. #if defined(__OpenBSD__)
  1617. if ((pwent = (name == NULL ?
  1618. getpwuid_shadow(uid) : getpwnam_shadow(name))) == NULL)
  1619. #else
  1620. if ((pwent = (name == NULL ? getpwuid(uid) : getpwnam(name))) == NULL)
  1621. #endif
  1622. {
  1623. /*
  1624. * Can't get entry.
  1625. */
  1626. rc = False;
  1627. done = True;
  1628. }
  1629. #endif /* SVR4 */
  1630. if(smGD.secureSystem)
  1631. {
  1632. SM_SETEUID(smGD.runningUID);
  1633. }
  1634. if (done == False)
  1635. {
  1636. if (
  1637. pwent->pw_passwd == NULL
  1638. || pwent->pw_passwd[0] == '*'
  1639. #ifdef SVR4
  1640. || sp == NULL
  1641. #endif
  1642. )
  1643. {
  1644. /*
  1645. * Could not read password.
  1646. */
  1647. rc = False;
  1648. done = True;
  1649. }
  1650. }
  1651. if (done == False)
  1652. {
  1653. if (passwd == NULL)
  1654. {
  1655. /*
  1656. * Caller just checking if it is possible to access
  1657. * password file (ie is dtsession suid bit set properly).
  1658. */
  1659. rc = True;
  1660. done = True;
  1661. }
  1662. }
  1663. if (done == False)
  1664. {
  1665. /*
  1666. * Check password.
  1667. */
  1668. #ifdef SVR4
  1669. if (strcmp(crypt(passwd,sp->sp_pwdp),sp->sp_pwdp) != 0)
  1670. #else
  1671. if (strcmp(pwent->pw_passwd, crypt(passwd, pwent->pw_passwd)) != 0)
  1672. #endif
  1673. {
  1674. /*
  1675. * Password incorrect.
  1676. */
  1677. rc = False;
  1678. done = True;
  1679. }
  1680. }
  1681. endpwent();
  1682. #ifdef SVR4
  1683. endspent();
  1684. #endif
  1685. return(rc);
  1686. }
  1687. #endif /* SIA */
  1688. /*************************************<->*************************************
  1689. *
  1690. * Authenticate (name, uid, passwd)
  1691. *
  1692. *
  1693. * Description:
  1694. * -----------
  1695. *
  1696. *
  1697. * Inputs:
  1698. * ------
  1699. *
  1700. *
  1701. * Outputs:
  1702. * -------
  1703. *
  1704. * Comments:
  1705. * --------
  1706. *
  1707. *************************************<->***********************************/
  1708. #if defined (_AIX) && defined(_POWER)
  1709. static Boolean
  1710. Authenticate(
  1711. char *name,
  1712. uid_t uid,
  1713. char *passwd )
  1714. {
  1715. register struct passwd *pwent;
  1716. char *p, *q;
  1717. char *crypt();
  1718. Boolean rc = True;
  1719. Boolean done = False;
  1720. int arc;
  1721. int reenter;
  1722. char *newname = NULL;
  1723. char *msg;
  1724. if(smGD.secureSystem)
  1725. {
  1726. SM_SETEUID(smGD.unLockUID);
  1727. }
  1728. /*
  1729. * Map uid to name.
  1730. */
  1731. if (name == NULL)
  1732. {
  1733. pwent = getpwuid(uid);
  1734. if (pwent != NULL)
  1735. {
  1736. name = newname = strdup(pwent->pw_name);
  1737. }
  1738. endpwent();
  1739. }
  1740. /*
  1741. * Authenticate user. Note: normally, we should check 'reenter' to
  1742. * see if the user has another challenge. Since the dtsession screen
  1743. * lock i/f does not yet have the support, our policy is to let the
  1744. * user back in if they pass the first (password) challenge.
  1745. */
  1746. arc = authenticate(name, passwd, &reenter, &msg);
  1747. if(smGD.secureSystem)
  1748. {
  1749. SM_SETEUID(smGD.runningUID);
  1750. }
  1751. if (msg) free(msg);
  1752. if (newname) free(newname);
  1753. return(arc == 0 ? True : False);
  1754. }
  1755. #endif /* _AIX && _POWER */