SmLock.c 44 KB

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