vgcallback.c 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948
  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. /* $TOG: vgcallback.c /main/16 1998/11/02 18:34:55 mgreess $ */
  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: vgcallback.c
  34. **
  35. ** Project: HP Visual User Environment (DT)
  36. **
  37. ** Description: Callback routines Dtgreet application.
  38. **
  39. ** These routines handle the callbacks from the widgets.
  40. **
  41. **
  42. ** (c) Copyright 1987, 1988, 1989 by Hewlett-Packard Company
  43. **
  44. **
  45. **
  46. ****************************************************************************
  47. ************************************<+>*************************************/
  48. /***************************************************************************
  49. *
  50. * Includes
  51. *
  52. ***************************************************************************/
  53. #include <stdio.h>
  54. #include <unistd.h>
  55. #include <setjmp.h>
  56. #include <signal.h>
  57. #include <sys/signal.h>
  58. #include <sys/param.h>
  59. #include <Xm/Xm.h>
  60. #include <Xm/MessageB.h>
  61. #include <Xm/TextF.h>
  62. #include <Xm/TextFP.h>
  63. #include <Xm/PushBG.h>
  64. #include <Xm/ToggleBG.h>
  65. #include <Dt/IconFile.h>
  66. #include <Dt/Icon.h>
  67. #include <pwd.h>
  68. #ifdef AUDIT
  69. # include <sys/audit.h>
  70. #endif
  71. /* necessary for bzero */
  72. #ifdef SVR4
  73. #include <X11/Xfuncs.h>
  74. #endif
  75. #include "vg.h"
  76. #include "vgmsg.h"
  77. /***************************************************************************
  78. *
  79. * External declarations
  80. *
  81. ***************************************************************************/
  82. extern LogoInfo logoInfo; /* information about the logo */
  83. /***************************************************************************
  84. *
  85. * Procedure declarations
  86. *
  87. ***************************************************************************/
  88. static void CenterForm( Widget w1, Widget w2);
  89. static void PingLost( void ) ;
  90. static SIGVAL PingBlocked( int arg ) ;
  91. static void ProcessTraversal( Widget w, int direction) ;
  92. static void _DtShowDialog(DialogType dtype, XmString msg);
  93. static void TellRequester(char * buf, size_t nbytes);
  94. # ifdef BLS
  95. static void PromptSensitivityLevel(void); /* prompt for B1 Sen. Level */
  96. int VerifySensitivityLevel(void); /* verify B1 Sensitivity Level */
  97. # endif
  98. static int session_selected = False;
  99. static Widget default_dt = NULL;
  100. /***************************************************************************
  101. *
  102. * Global variables
  103. *
  104. ***************************************************************************/
  105. Widget focusWidget = NULL;
  106. char *userName = "\0";
  107. struct passwd *user_p;
  108. #ifdef BLS
  109. static int normalPasswordWidget = True;
  110. char *sensitivityLevel = NULL;
  111. #endif
  112. #ifndef SVR4
  113. long groups[NGROUPS];
  114. #endif
  115. #ifdef SIA
  116. #include <alloca.h>
  117. SiaFormInfo siaFormInfo;
  118. XmString multiline_xmstring(char *text)
  119. {
  120. char *start, *end;
  121. Boolean done;
  122. XmString string = NULL;
  123. XmString tmp_string;
  124. XmString separator = NULL;
  125. char *buffer;
  126. if (!text) return (NULL);
  127. buffer = alloca(strlen((const char *)text) + 1);
  128. start = text;
  129. done = FALSE;
  130. while ( ! done) /* loop thu local copy */
  131. { /* looking for \n */
  132. end = start;
  133. while ((*end != '\0') && (*end != '\n')) end++;
  134. if (*end == '\0')
  135. done = TRUE; /* we are at the end */
  136. /* Don't convert empty string unless it's an initial newline. */
  137. if ((start != end) || (start == text))
  138. {
  139. strncpy(buffer, start, end - start);
  140. buffer[end - start] = '\0';
  141. if (!string)
  142. string = XmStringCreate(buffer, XmFONTLIST_DEFAULT_TAG);
  143. else
  144. {
  145. tmp_string = XmStringCreate(buffer, XmFONTLIST_DEFAULT_TAG);
  146. string = XmStringConcat(string, tmp_string);
  147. XmStringFree(tmp_string);
  148. }
  149. }
  150. /* Make a separator if this isn't the last segment. */
  151. if (!done)
  152. {
  153. if (!separator)
  154. separator = XmStringSeparatorCreate();
  155. string = XmStringConcat(string, separator);
  156. start = ++end; /* start at next char */
  157. }
  158. }
  159. if (separator)
  160. XmStringFree(separator);
  161. return (string);
  162. }
  163. #endif /* SIA */
  164. /***************************************************************************
  165. *
  166. * CenterForm
  167. *
  168. * Utility function to center one form horizontally within another.
  169. ***************************************************************************/
  170. static void
  171. CenterForm( Widget w1, Widget w2 )
  172. {
  173. Dimension width;
  174. int i, width1, width2;
  175. XtSetArg(argt[0], XmNwidth, &width);
  176. XtGetValues(w1, argt, 1);
  177. width1 = (int)width;
  178. XtSetArg(argt[0], XmNwidth, &width);
  179. XtGetValues(w2, argt, 1);
  180. width2 = (int)width;
  181. i = 0;
  182. XtSetArg(argt[i], XmNleftAttachment, XmATTACH_FORM ); i++;
  183. XtSetArg(argt[i], XmNleftOffset, (width1 - width2) / 2 ); i++;
  184. XtSetValues(w2, argt, i);
  185. }
  186. /***************************************************************************
  187. *
  188. * CleanupAndExit
  189. *
  190. * close things down gracefully and exit
  191. ***************************************************************************/
  192. void
  193. CleanupAndExit( Widget w, int exit_code )
  194. {
  195. int i;
  196. Boolean toggleon; /* status of session toggle buttons */
  197. #ifdef VG_TRACE
  198. vg_TRACE_EXECUTION("main: entered CleanupAndExit ...");
  199. #endif /* VG_TRACE */
  200. if (w != NULL)
  201. XtDestroyWidget(w);
  202. /*
  203. * if user is logging in, set type of session desired. No more than
  204. * one session type can be selected at a time (if any) ...
  205. */
  206. if ( exit_code == NOTIFY_OK ) {
  207. XtSetArg(argt[0], XmNset, &toggleon );
  208. XtGetValues(options_failsafe, argt, 1);
  209. if ( toggleon ) exit_code = NOTIFY_FAILSAFE;
  210. XtGetValues(options_dtlite, argt, 1);
  211. if ( toggleon ) exit_code = NOTIFY_DTLITE;
  212. XtGetValues(options_dt, argt, 1);
  213. if ( toggleon ) exit_code = NOTIFY_DT;
  214. if(options_last_dt != NULL) {
  215. XtGetValues(options_last_dt, argt, 1);
  216. if ( toggleon ) exit_code = NOTIFY_LAST_DT;
  217. }
  218. for(i = 0; i < appInfo.altDts ; ++i) {
  219. if(alt_dts[i] != NULL) {
  220. XtGetValues(alt_dts[i], argt, 1);
  221. if ( toggleon ) exit_code = NOTIFY_ALT_DTS + i + 1; /* alt desktops start at 1 */
  222. }
  223. }
  224. }
  225. if (!session_selected)
  226. exit_code = NOTIFY_OK;
  227. CloseCatalog();
  228. ChangeBell("on");
  229. UnsecureDisplay();
  230. XSync (dpyinfo.dpy, 0);
  231. XtCloseDisplay(dpyinfo.dpy);
  232. exit (exit_code);
  233. }
  234. /***************************************************************************
  235. *
  236. * ClearDtlabel
  237. *
  238. ***************************************************************************/
  239. static void
  240. ClearDtlabel(void)
  241. {
  242. int i;
  243. XmString xms;
  244. #ifdef VG_TRACE
  245. vg_TRACE_EXECUTION("ClearDtlabel: entered ...");
  246. #endif /* VG_TRACE */
  247. i = 0;
  248. xms = XmStringCreateLocalized(" ");
  249. XtSetArg(argt[i], XmNlabelString, xms); i++;
  250. XtSetValues(dt_label, argt, i);
  251. XmStringFree(xms);
  252. }
  253. /***************************************************************************
  254. *
  255. * ClearDtlabel
  256. *
  257. ***************************************************************************/
  258. static void
  259. ClearDtButtons(void)
  260. {
  261. int i;
  262. /*
  263. * Clear Dt toggles...
  264. */
  265. XtSetArg(argt[0], XmNset, False);
  266. for (i=0; i<appInfo.altDts; ++i)
  267. if (alt_dts[i] != NULL)
  268. XtSetValues(alt_dts[i], argt, 1);
  269. if (options_failsafe) XtSetValues(options_failsafe, argt, 1);
  270. if (options_dtlite) XtSetValues(options_dtlite, argt, 1);
  271. if (options_dt) XtSetValues(options_dt, argt, 1);
  272. if (options_last_dt) XtSetValues(options_last_dt, argt, 1);
  273. }
  274. /***************************************************************************
  275. *
  276. * RespondClearCB
  277. *
  278. * clear name/password text fields
  279. ***************************************************************************/
  280. void
  281. RespondClearCB( Widget w, XtPointer client, XtPointer call )
  282. {
  283. char buf[REQUEST_LIM_MAXLEN];
  284. ResponseClear *r = (ResponseClear *)buf;
  285. #ifdef VG_TRACE
  286. vg_TRACE_EXECUTION("main: entered RespondClearCB ...");
  287. #endif /* VG_TRACE */
  288. ClearDtlabel();
  289. ClearDtButtons();
  290. SetDefaultDt(NULL);
  291. r->hdr.opcode = REQUEST_OP_CLEAR;
  292. r->hdr.reserved = 0;
  293. r->hdr.length = sizeof(*r);
  294. TellRequester(buf, (size_t) r->hdr.length);
  295. }
  296. /***************************************************************************
  297. *
  298. * CopyrightCB
  299. *
  300. * move the highlight back to login or password fields AFTER the copyright
  301. * dialog is unposted.
  302. *
  303. ***************************************************************************/
  304. void
  305. CopyrightCB( Widget w, XtPointer client_data, XtPointer call_data )
  306. {
  307. #ifdef VG_TRACE
  308. vg_TRACE_EXECUTION("main: entered CopyrightCB ...");
  309. #endif /* VG_TRACE */
  310. if ( focusWidget != NULL)
  311. ProcessTraversal(focusWidget, XmTRAVERSE_CURRENT);
  312. }
  313. /***************************************************************************
  314. *
  315. * EditPasswdCB
  316. *
  317. * implement no-echo and no-cursor motion of the password
  318. ***************************************************************************/
  319. void
  320. EditPasswdCB(Widget w, XtPointer client, XtPointer call_data)
  321. {
  322. LoginTextPtr textdata;
  323. XmTextVerifyPtr cbs = (XmTextVerifyPtr) call_data;
  324. int i;
  325. static char buffer[MAXPATHLEN];
  326. char *s, *t;
  327. #ifdef VG_TRACE
  328. vg_TRACE_EXECUTION("main: entered EditPasswdCB ...");
  329. vg_TRACE_EXECUTION(
  330. "currInsert=%d newInsert=%d startPos=%d endPos=%d\n",
  331. cbs->currInsert,cbs->newInsert,cbs->startPos, cbs->endPos);
  332. if (cbs->text->ptr) vg_TRACE_EXECUTION("text->ptr=%s\n", cbs->text->ptr);
  333. vg_TRACE_EXECUTION("noechobuf=%s\n", textdata->noechobuf);
  334. #endif /* VG_TRACE */
  335. textdata = GetLoginTextPtr(w);
  336. if (NULL == textdata || textdata->bEcho) return;
  337. if (cbs->reason == XmCR_MOVING_INSERT_CURSOR) return;
  338. for (i=0, s=buffer, t=textdata->noechobuf;
  339. (*t && i<cbs->startPos);
  340. i++, s++, t++)
  341. *s = *t;
  342. if (cbs->text->ptr)
  343. {
  344. snprintf(s, sizeof(buffer) - (s - buffer), "%s", cbs->text->ptr);
  345. s += cbs->text->length;
  346. }
  347. else
  348. *s = '\0';
  349. if (strlen(textdata->noechobuf) >= cbs->endPos)
  350. {
  351. t = textdata->noechobuf+cbs->endPos;
  352. if (strlen(t))
  353. strcpy(s, t);
  354. }
  355. strcpy(textdata->noechobuf, buffer);
  356. if (cbs->text->ptr)
  357. for (i=0, s=cbs->text->ptr; i<cbs->text->length; i++, s++)
  358. *s = '*';
  359. #ifdef VG_TRACE
  360. vg_TRACE_EXECUTION("textdata->noechobuf=%s\n", textdata->noechobuf);
  361. #endif
  362. }
  363. /***************************************************************************
  364. *
  365. * FakeFocusIn
  366. *
  367. * simulate a FocusIn event to the login_shell in order to turn on
  368. * traversal. There is a bug in the Toolkit that is normally masked by
  369. * the window manager. Since we have no window manager, we need to simulate
  370. * the FocusIn event it sends to the application.
  371. *
  372. * Also force the initial focus to the login_text widget.
  373. ***************************************************************************/
  374. void
  375. FakeFocusIn( Widget focus_widget, XtPointer client_data, XEvent *eventprm,
  376. Boolean *continue_to_dispatch )
  377. {
  378. XEvent event;
  379. XEvent * eventPtr = &event;
  380. #ifdef VG_TRACE
  381. vg_TRACE_EXECUTION("main: entered FakeFocusIn ...");
  382. #endif /* VG_TRACE */
  383. /*
  384. * set the input focus to the login text widget...
  385. */
  386. XSetInputFocus( XtDisplay(focus_widget),
  387. XtWindow(focus_widget),
  388. RevertToNone,
  389. CurrentTime);
  390. /*
  391. * create a synthetic focus-in event.
  392. *
  393. * Note: The above call to XSetInputFocus() was not originally included
  394. * in this routine. A bug fix to Motif made it necessary to add
  395. * the call. The synthetic focus-in event is probably now
  396. * unnecessary but is left in for caution's sake. (12/08/92)
  397. */
  398. /* focus_widget = login_shell; */
  399. eventPtr->type = FocusIn;
  400. eventPtr->xfocus.serial = LastKnownRequestProcessed(XtDisplay(focus_widget));
  401. eventPtr->xfocus.send_event = True;
  402. eventPtr->xfocus.display = XtDisplay(focus_widget);
  403. eventPtr->xfocus.window = XtWindow(focus_widget);
  404. eventPtr->xfocus.mode = NotifyNormal;
  405. eventPtr->xfocus.detail = NotifyAncestor;
  406. XtDispatchEvent (eventPtr);
  407. ProcessTraversal(focus_widget, XmTRAVERSE_CURRENT);
  408. XtRemoveEventHandler(focus_widget, ExposureMask, FALSE,
  409. FakeFocusIn, NULL);
  410. }
  411. /***************************************************************************
  412. *
  413. * LayoutCB
  414. *
  415. * do final layout adjustments right before windows are mapped. This is
  416. * necessary because the size of managers (Forms, etc) is not known until
  417. * their window has been created (XtRealize). We want to make adjustments
  418. * before the windows become visible
  419. *
  420. * 1. squeeze dialog width to fit on screen.
  421. * 2. increase dialog height if widgets overlap.
  422. * 3. center the main matte horizontally and vertically
  423. * 4. position the pushbuttons
  424. * 5. position the copyright
  425. *
  426. ***************************************************************************/
  427. void
  428. LayoutCB( Widget w, XtPointer client_data, XtPointer call_data )
  429. {
  430. int i, j;
  431. Dimension width, height; /* size values returned by XtGetValues */
  432. Dimension shadowThickness;/* size values returned by XtGetValues */
  433. Position x, y; /* position values returned by XtGetValues */
  434. int dpwidth, dpheight; /* JET - display w/h set according to */
  435. int xorg, yorg; /* xinerama usage */
  436. struct { /* position, size of widgets (pixels) */
  437. int x, y;
  438. int width;
  439. int height;
  440. } mw, pw; /* matte, logo, drop shadow, login matte
  441. and greeting widgets */
  442. int width1, width2; /* general width variable */
  443. int height1; /* general height variable */
  444. Position x1, y1; /* general position variables */
  445. int offsety; /* general offset variable */
  446. int shadow_offsetx; /* offset for drop shadow (pixels) */
  447. int shadow_offsety; /* offset for drop shadow (pixels) */
  448. int spacing; /* spacing between login & matte bottoms */
  449. Widget buttons[4]; /* pushbutton widgets */
  450. XtWidgetGeometry geometry; /* geometry of a widget */
  451. int max_width; /* maximum width of a set of widgets */
  452. int origin; /* horizontal origin for button placement */
  453. int space; /* total available space left between buttons */
  454. int overlap; /* possible widget overlap */
  455. #ifdef VG_TRACE
  456. vg_TRACE_EXECUTION("main: entered LayoutCB ...");
  457. #endif /* VG_TRACE */
  458. #ifdef USE_XINERAMA
  459. /* get info on the prefered screen */
  460. if (!_DtXineramaGetScreen(dpyinfo.DtXineramaInfo,
  461. appInfo.xineramaPreferredScreen,
  462. &dpwidth, &dpheight, &xorg, &yorg))
  463. { /* no joy here either - setup for normal */
  464. dpwidth = dpyinfo.width;
  465. dpheight = dpyinfo.height;
  466. xorg = yorg = 0;
  467. }
  468. #else /* no Xinerama */
  469. dpwidth = dpyinfo.width;
  470. dpheight = dpyinfo.height;
  471. xorg = yorg = 0;
  472. #endif
  473. /*
  474. * - squeeze dialog to fit onto screen (if necessary)
  475. */
  476. i = 0;
  477. XtSetArg(argt[i], XmNwidth, &width ); i++;
  478. XtGetValues(matte, argt, i);
  479. mw.width = ToPixel(matte, XmHORIZONTAL, (int)width );
  480. #define HMARGIN 4 /* min sum horizontal margin of matte */
  481. if (mw.width+HMARGIN > dpwidth)
  482. {
  483. int delta = mw.width + HMARGIN - dpwidth;
  484. /*
  485. * Matte width greater than screen so shrink matteFrame
  486. * and matte1 width to compensate.
  487. */
  488. i=0;
  489. XtSetArg(argt[i], XmNwidth, &width ); i++;
  490. XtGetValues(matteFrame, argt, i);
  491. width1 = ToPixel(matteFrame, XmHORIZONTAL, (int)width );
  492. width1 -= delta;
  493. width1 = FromPixel(matteFrame, XmHORIZONTAL, width1 );
  494. i=0;
  495. XtSetArg(argt[i], XmNwidth, width1 ); i++;
  496. XtSetValues(matteFrame, argt, i);
  497. width1 = dpwidth - HMARGIN;
  498. mw.width = FromPixel(matte, XmHORIZONTAL, width1 );
  499. i=0;
  500. XtSetArg(argt[i], XmNwidth, mw.width ); i++;
  501. XtSetValues(matte, argt, i);
  502. }
  503. /*
  504. * - Make sure the login widgets don't overlap.
  505. */
  506. if (login_form) {
  507. i = 0;
  508. XtSetArg(argt[i], XmNy, &y ); i++;
  509. XtSetArg(argt[i], XmNheight, &height ); i++;
  510. XtGetValues(greeting, argt, i);
  511. i = 0;
  512. XtSetArg(argt[i], XmNy, &y1 ); i++;
  513. XtGetValues(login_form, argt, i);
  514. overlap = y + height - y1;
  515. if (overlap > -10) {
  516. i = 0;
  517. XtSetArg(argt[i], XmNbottomAttachment, XmATTACH_WIDGET); i++;
  518. XtSetArg(argt[i], XmNbottomWidget, login_form); i++;
  519. XtSetArg(argt[i], XmNbottomOffset, 10); i++;
  520. XtSetValues(greeting, argt, i);
  521. }
  522. }
  523. /*
  524. * - center the main matte horizontally and vertically...
  525. */
  526. i = 0;
  527. XtSetArg(argt[i], XmNx, &x ); i++;
  528. XtSetArg(argt[i], XmNy, &y ); i++;
  529. XtSetArg(argt[i], XmNwidth, &width ); i++;
  530. XtSetArg(argt[i], XmNheight, &height ); i++;
  531. XtSetArg(argt[i], XmNshadowThickness, &shadowThickness ); i++;
  532. XtGetValues(matte, argt, i);
  533. mw.width = ToPixel(matte, XmHORIZONTAL, (int)width );
  534. mw.height = ToPixel(matte, XmVERTICAL, (int)height );
  535. mw.x = ( x > 0 ? ToPixel(matte, XmHORIZONTAL, (int) x)
  536. : (dpwidth - mw.width)/2 );
  537. mw.y = ( y > 0 ? ToPixel(matte, XmVERTICAL, (int) y)
  538. : (dpheight - mw.height)/2 );
  539. if ( mw.x < 0 ) mw.x = 0;
  540. if ( mw.y < 0 ) mw.y = 0;
  541. x1 = FromPixel(matte, XmHORIZONTAL, mw.x );
  542. y1 = FromPixel(matte, XmVERTICAL, mw.y );
  543. x1 += xorg; /* JET - adjust for xinerama */
  544. y1 += yorg;
  545. i = 0;
  546. XtSetArg(argt[i], XmNx, x1 ); i++;
  547. XtSetArg(argt[i], XmNy, y1 ); i++;
  548. XtSetValues(matte, argt, i);
  549. /*
  550. * space the buttons horizontally. Start at the center of the matte
  551. * and allow them to grow towards the edges...
  552. */
  553. i = 0;
  554. XtSetArg(argt[i], XmNwidth, &width ); i++;
  555. XtGetValues(matte1, argt, i);
  556. max_width = width;
  557. i = 0;
  558. XtSetArg(argt[i], XmNwidth, &width ); i++;
  559. XtGetValues(clear_button, argt, i);
  560. space = max_width - 4*width;
  561. spacing = space/4;
  562. if (spacing < 12) spacing = 12;
  563. i = 0;
  564. XtSetArg(argt[i], XmNleftAttachment, XmATTACH_FORM); i++;
  565. XtSetArg(argt[i], XmNleftOffset, spacing/2); i++;
  566. XtSetValues(ok_button, argt, i);
  567. i = 0;
  568. XtSetArg(argt[i], XmNleftAttachment, XmATTACH_WIDGET ); i++;
  569. XtSetArg(argt[i], XmNleftWidget, ok_button); i++;
  570. XtSetArg(argt[i], XmNleftOffset, spacing); i++;
  571. XtSetValues(clear_button, argt, i);
  572. i = 0;
  573. XtSetArg(argt[i], XmNleftAttachment, XmATTACH_WIDGET ); i++;
  574. XtSetArg(argt[i], XmNleftWidget, clear_button); i++;
  575. XtSetArg(argt[i], XmNleftOffset, spacing); i++;
  576. XtSetValues(options_button, argt, i);
  577. i = 0;
  578. XtSetArg(argt[i], XmNleftAttachment, XmATTACH_WIDGET ); i++;
  579. XtSetArg(argt[i], XmNleftWidget, options_button); i++;
  580. XtSetArg(argt[i], XmNleftOffset, spacing); i++;
  581. XtSetValues(help_button, argt, i);
  582. /*
  583. * - adjust the copyright vertically to align top with login_matte...
  584. */
  585. if (copyright_msg) {
  586. XtQueryGeometry(copyright_msg, NULL, &geometry);
  587. i = 0;
  588. XtSetArg(argt[i], XmNshadowThickness, &width ); i++;
  589. XtGetValues(copyright_msg, argt, i);
  590. width1 = ToPixel(copyright_msg, XmHORIZONTAL, width);
  591. width1 = (dpwidth - (int) geometry.width - 2 * width1)/2;
  592. x1 = FromPixel(copyright_msg, XmHORIZONTAL, width1);
  593. y1 = FromPixel(copyright_msg, XmVERTICAL, mw.y);
  594. i = 0;
  595. XtSetArg(argt[i], XmNdefaultPosition, False ); i++;
  596. XtSetArg(argt[i], XmNx, x1 ); i++;
  597. XtSetArg(argt[i], XmNy, y1 ); i++;
  598. XtSetValues(copyright_msg, argt, i);
  599. }
  600. }
  601. /***************************************************************************
  602. *
  603. * MenuItemCB
  604. *
  605. * callback for options menu items
  606. ***************************************************************************/
  607. void
  608. MenuItemCB( Widget w, XtPointer client_data, XtPointer call_data )
  609. {
  610. int i;
  611. char *logoFile;
  612. char *logoName;
  613. char *temp_p;
  614. char temp[MAXPATHLEN];
  615. #ifdef VG_TRACE
  616. vg_TRACE_EXECUTION("main: entered MenuItemCB ...");
  617. #endif /* VG_TRACE */
  618. session_selected = True;
  619. switch ( (long) client_data) {
  620. case OB_RESTART_SERVER:
  621. CleanupAndExit(NULL, NOTIFY_RESTART);
  622. break;
  623. case OB_NO_WINDOWS:
  624. CleanupAndExit(NULL, NOTIFY_NO_WINDOWS);
  625. break;
  626. case OB_COPYRIGHT:
  627. _DtShowDialog(copyright, NULL);
  628. break;
  629. case OB_ALT_DTS:
  630. case OB_FAILSAFE:
  631. case OB_DTLITE:
  632. case OB_DT:
  633. case OB_LAST_DT:
  634. /*
  635. * set the label on the dt_label widget..
  636. */
  637. if(w != options_last_dt) {
  638. XtSetArg(argt[0], XmNlabelString, &xmstr);
  639. XtGetValues(w, argt, 1);
  640. XtSetArg(argt[0], XmNlabelString, xmstr);
  641. XtSetValues(dt_label, argt, 1);
  642. }
  643. else
  644. ClearDtlabel();
  645. i = 0;
  646. XtSetArg(argt[i], XmNuserData, &logoFile ); i++;
  647. XtGetValues(w, argt, i);
  648. /*
  649. * remove trailing spaces
  650. */
  651. if(strchr(logoFile,' '))
  652. temp_p = strtok(logoFile," ");
  653. else
  654. temp_p = logoFile;
  655. logoName = _DtGetIconFileName(DefaultScreenOfDisplay(dpyinfo.dpy),
  656. temp_p, NULL, NULL, 0);
  657. if (logoName == NULL) {
  658. LogError(
  659. ReadCatalog(MC_LOG_SET,MC_LOG_NO_LOGOBIT,MC_DEF_LOG_NO_LOGOBIT),
  660. logoFile);
  661. logoFile = NULL;
  662. }
  663. i = 0;
  664. XtSetArg(argt[i], XmNimageName, logoName); i++;
  665. XtSetValues(logo_pixmap, argt, i);
  666. /*
  667. * Clear Dt toggles...
  668. */
  669. ClearDtButtons();
  670. /*
  671. * set the selected toggle button...
  672. */
  673. XtSetArg(argt[0], XmNset, True);
  674. XtSetValues(w, argt, 1);
  675. SetDefaultDt(w);
  676. /*
  677. * return focus to name/password widgets...
  678. */
  679. if ( focusWidget != NULL)
  680. ProcessTraversal(focusWidget, XmTRAVERSE_CURRENT);
  681. break;
  682. }
  683. }
  684. /***************************************************************************
  685. *
  686. * OptionsUnmapCB
  687. *
  688. * callback when options menu unmaps
  689. ***************************************************************************/
  690. void
  691. OptionsUnmapCB( Widget wd, XtPointer client_data, XtPointer call_data )
  692. {
  693. int i;
  694. Dimension width, height;
  695. Widget w;
  696. XEvent event;
  697. #ifdef VG_TRACE
  698. vg_TRACE_EXECUTION("main: entered OptionsUnmapCB ...");
  699. #endif /* VG_TRACE */
  700. /*
  701. * simulate an exposure event over the Options pushbutton to make sure
  702. * the pushbutton elevates. (there is a bug in the toolkit where this
  703. * doesn't always happen on some servers)...
  704. */
  705. w = options_button;
  706. i = 0;
  707. XtSetArg(argt[i], XmNwidth, &width ); i++;
  708. XtSetArg(argt[i], XmNheight, &height ); i++;
  709. XtGetValues(w, argt, i);
  710. event.type = Expose;
  711. event.xexpose.serial = LastKnownRequestProcessed(XtDisplay(w));
  712. event.xexpose.send_event = True;
  713. event.xexpose.display = XtDisplay(w);
  714. event.xexpose.window = XtWindow(w);
  715. event.xexpose.x = 0;
  716. event.xexpose.y = 0;
  717. event.xexpose.width = 1; /* one pixel seems to be good enough, */
  718. event.xexpose.height = 1; /* but time will tell... */
  719. #if 0
  720. event.xexpose.width = ToPixel(matte, XmHORIZONTAL, (int)width );
  721. event.xexpose.height = ToPixel(matte, XmVERTICAL, (int)height );
  722. #endif
  723. event.xexpose.count = 0;
  724. XtDispatchEvent (&event);
  725. }
  726. /***************************************************************************
  727. *
  728. * PingServerCB
  729. *
  730. * Ping the server occasionally with an Xsync to see if it is still there.
  731. * We do this here rather than in dtlogin since dtgreet has the server
  732. * grabbed.
  733. *
  734. ***************************************************************************/
  735. static jmp_buf pingTime;
  736. static int serverDead = FALSE;
  737. static int pingInterval = 0; /* ping interval (sec.) */
  738. static int pingTimeout; /* ping timeout (sec.) */
  739. static void
  740. PingLost( void )
  741. {
  742. serverDead = TRUE;
  743. longjmp (pingTime, 1);
  744. }
  745. static SIGVAL
  746. PingBlocked( int arg )
  747. {
  748. serverDead = TRUE;
  749. longjmp (pingTime, 1);
  750. }
  751. int
  752. PingServer( void )
  753. {
  754. int (*oldError)();
  755. SIGVAL (*oldSig)();
  756. int oldAlarm;
  757. oldError = XSetIOErrorHandler ((XIOErrorHandler)PingLost);
  758. oldAlarm = alarm (0);
  759. oldSig = signal (SIGALRM, PingBlocked);
  760. alarm (pingTimeout * 60);
  761. if (!setjmp (pingTime))
  762. {
  763. XSync (dpyinfo.dpy, 0);
  764. }
  765. else
  766. {
  767. if ( serverDead ) {
  768. LogError(ReadCatalog(
  769. MC_LOG_SET,MC_LOG_DEADSRV,MC_DEF_LOG_DEADSRV),
  770. dpyinfo.name);
  771. alarm (0);
  772. signal (SIGALRM, SIG_DFL);
  773. XSetIOErrorHandler (oldError);
  774. return 0;
  775. }
  776. }
  777. alarm (0);
  778. signal (SIGALRM, oldSig);
  779. alarm (oldAlarm);
  780. XSetIOErrorHandler (oldError);
  781. return 1;
  782. }
  783. void
  784. PingServerCB( XtPointer call_data, XtIntervalId *id )
  785. {
  786. char *t;
  787. /*
  788. * get ping values from the environment...
  789. */
  790. if ( pingInterval == 0 ) {
  791. pingInterval = ((t = (char *)getenv(PINGINTERVAL)) == NULL ? 0 : atoi(t));
  792. pingTimeout = ((t = (char *)getenv(PINGTIMEOUT)) == NULL ? 0 : atoi(t));
  793. }
  794. /*
  795. * ping the server. If successful, set a timer for the next ping,
  796. * otherwise cleanup and exit...
  797. */
  798. if ( pingInterval != 0 ) {
  799. if (PingServer())
  800. XtAddTimeOut((unsigned long) pingInterval * 60 * 1000,
  801. PingServerCB, NULL);
  802. else
  803. exit(NOTIFY_RESTART);
  804. }
  805. }
  806. /***************************************************************************
  807. *
  808. * PostMenuCB
  809. *
  810. * post the option_button pop-up menu
  811. ***************************************************************************/
  812. void
  813. PostMenuCB( Widget w, XtPointer client_data, XtPointer call_data )
  814. {
  815. XmAnyCallbackStruct *p;
  816. p = (XmAnyCallbackStruct *) call_data;
  817. #ifdef VG_TRACE
  818. vg_TRACE_EXECUTION("main: entered PostMenuCB ...");
  819. #endif /* VG_TRACE */
  820. /*
  821. * make options menus if they don't yet exist...
  822. */
  823. if (options_menu == NULL)
  824. MakeOptionsMenu();
  825. /*
  826. * post menu...
  827. */
  828. if (p->reason == XmCR_ARM &&
  829. p->event->type == ButtonPress) {
  830. XmMenuPosition(options_menu, p->event);
  831. XtManageChild(options_menu);
  832. }
  833. }
  834. /***************************************************************************
  835. *
  836. * ProcessTraversal
  837. *
  838. * move the input focus
  839. ***************************************************************************/
  840. static void
  841. ProcessTraversal( Widget w, int direction )
  842. {
  843. int i;
  844. #ifdef VG_TRACE
  845. vg_TRACE_EXECUTION("main: entered ProcessTraversal ...");
  846. #endif /* VG_TRACE */
  847. i = XmProcessTraversal(w, direction);
  848. #ifndef __hpux
  849. /*
  850. * Versions of Motif other than HP do not support the XmfocusCallback
  851. * on the TextField widget. We simulate it here by manually invoking the
  852. * callback routine...
  853. */
  854. TextFocusCB(w, NULL, NULL);
  855. #endif
  856. }
  857. /***************************************************************************
  858. *
  859. * RefreshEH
  860. *
  861. * cause the entire screen to refresh via exposure events
  862. ***************************************************************************/
  863. void
  864. RefreshEH( Widget w, XtPointer client_data, XEvent *event,
  865. Boolean *continue_to_dispatch )
  866. {
  867. Window cover;
  868. #ifdef VG_TRACE
  869. vg_TRACE_EXECUTION("main: entered RefreshEH ...");
  870. #endif /* VG_TRACE */
  871. /*
  872. * map/unmap a window that covers the entire screen. The resultant
  873. * exposure events will refresh the screen. Note, the default
  874. * background pixmap is NONE.
  875. */
  876. cover = XCreateWindow ( dpyinfo.dpy, /* display */
  877. dpyinfo.root, /* root window ID */
  878. 0, /* x origin */
  879. 0, /* y origin */
  880. dpyinfo.width, /* width */
  881. dpyinfo.height, /* height */
  882. 0, /* border width */
  883. 0, /* depth */
  884. InputOutput, /* class */
  885. CopyFromParent, /* visual */
  886. 0, /* value mask */
  887. (XSetWindowAttributes *)NULL); /* attributes */
  888. XMapWindow(dpyinfo.dpy, cover);
  889. XDestroyWindow(dpyinfo.dpy, cover);
  890. XFlush(dpyinfo.dpy);
  891. }
  892. /***************************************************************************
  893. *
  894. * RequestCB
  895. *
  896. * Accept a request from client
  897. ***************************************************************************/
  898. void
  899. RequestCB(
  900. XtPointer client_data,
  901. int *source,
  902. XtInputId *id)
  903. {
  904. char buf[512];
  905. int count;
  906. int remainder;
  907. RequestHeader *phdr = (RequestHeader *)buf;
  908. #ifdef VG_TRACE
  909. vg_TRACE_EXECUTION("main: entered RequestCB ...");
  910. #endif /* VG_TRACE */
  911. /*
  912. * There's a request in the pipe. Read the header.
  913. */
  914. count = read(0, buf, sizeof(*phdr));
  915. if (count != sizeof(*phdr))
  916. {
  917. return;
  918. }
  919. /*
  920. * Calculate amount of data after header.
  921. */
  922. remainder = phdr->length - sizeof(*phdr);
  923. if (remainder > 0)
  924. {
  925. /*
  926. * Read remainder of request.
  927. */
  928. count = read(0, buf+sizeof(*phdr), remainder);
  929. }
  930. /*
  931. * Initiate response to request.
  932. */
  933. switch(phdr->opcode)
  934. {
  935. case REQUEST_OP_EXIT:
  936. #ifdef VG_TRACE
  937. vg_TRACE_EXECUTION("main: got REQUEST_OP_EXIT ...");
  938. #endif /* VG_TRACE */
  939. RespondExitCB(NULL, NULL, NULL);
  940. break;
  941. case REQUEST_OP_MESSAGE:
  942. {
  943. RequestMessage *r = (RequestMessage *)phdr;
  944. XmString string;
  945. #ifdef VG_TRACE
  946. vg_TRACE_EXECUTION("main: got REQUEST_OP_MESSAGE ...");
  947. #endif /* VG_TRACE */
  948. if (r->idMC)
  949. {
  950. FILE *fp;
  951. /*
  952. * Caller passed in MC_* message id.
  953. */
  954. if (r->idMC == MC_NO_LOGIN &&
  955. (fp = fopen(NO_LOGIN_FILE,"r")) != NULL)
  956. {
  957. /*
  958. * For MC_NO_LOGIN read message from file.
  959. */
  960. char buffer[256];
  961. int j;
  962. string = NULL;
  963. while (fgets(buffer, 256, fp) != NULL)
  964. {
  965. j = strlen(buffer);
  966. if ( buffer[j-1] == '\n' ) buffer[j-1] = '\0';
  967. string = XmStringConcat(xmstr,
  968. XmStringCreate(buffer,
  969. XmFONTLIST_DEFAULT_TAG));
  970. string = XmStringConcat(xmstr, XmStringSeparatorCreate());
  971. }
  972. fclose(fp);
  973. }
  974. else
  975. {
  976. /*
  977. * Read message from message catalog.
  978. */
  979. string = ReadCatalogXms(MC_ERROR_SET, r->idMC, buf+r->offMessage);
  980. }
  981. }
  982. else
  983. {
  984. /*
  985. * Generate message from provided string.
  986. */
  987. #ifdef SIA
  988. string = multiline_xmstring(buf+r->offMessage);
  989. #else
  990. string = XmStringCreate(buf+r->offMessage,XmFONTLIST_DEFAULT_TAG);
  991. #endif
  992. }
  993. _DtShowDialog(error, string);
  994. XmStringFree(string);
  995. }
  996. break;
  997. case REQUEST_OP_HOSTNAME:
  998. #ifdef VG_TRACE
  999. vg_TRACE_EXECUTION("main: got REQUEST_OP_HOSTNAME ...");
  1000. #endif /* VG_TRACE */
  1001. _DtShowDialog(hostname, NULL);
  1002. break;
  1003. case REQUEST_OP_EXPASSWORD:
  1004. #ifdef VG_TRACE
  1005. vg_TRACE_EXECUTION("main: got REQUEST_OP_EXPASSWORD ...");
  1006. #endif /* VG_TRACE */
  1007. _DtShowDialog(expassword, NULL);
  1008. break;
  1009. case REQUEST_OP_CHPASS:
  1010. #ifdef VG_TRACE
  1011. vg_TRACE_EXECUTION("main: got REQUEST_OP_CHPASS ...");
  1012. #endif /* VG_TRACE */
  1013. break;
  1014. case REQUEST_OP_CHALLENGE:
  1015. {
  1016. RequestChallenge *r = (RequestChallenge *)phdr;
  1017. XmString string;
  1018. int i;
  1019. LoginTextPtr textdata;
  1020. Boolean change;
  1021. #ifdef VG_TRACE
  1022. vg_TRACE_EXECUTION("main: got REQUEST_OP_CHALLENGE ...");
  1023. #endif /* VG_TRACE */
  1024. textdata = GetLoginTextPtr(login_text);
  1025. change = (textdata->bEcho != r->bEcho);
  1026. XtUnmapWidget(textdata->text[textdata->bEcho]);
  1027. textdata->bEcho = r->bEcho;
  1028. textdata->noechobuf[0] = '\0';
  1029. XtAddEventHandler(textdata->text[textdata->bEcho], ExposureMask, False,
  1030. FakeFocusIn, NULL);
  1031. XtMapWidget(textdata->text[textdata->bEcho]);
  1032. XtPopup(login_shell, XtGrabNone);
  1033. XGrabKeyboard (dpyinfo.dpy, XtWindow (textdata->text[textdata->bEcho]),
  1034. False, GrabModeAsync, GrabModeAsync, CurrentTime);
  1035. XmTextFieldSetString(
  1036. textdata->text[textdata->bEcho],
  1037. r->offUserNameSeed ? buf+r->offUserNameSeed : "");
  1038. XmTextFieldSetSelection (
  1039. textdata->text[1],
  1040. 0, XmTextFieldGetLastPosition(textdata->text[1]),
  1041. CurrentTime );
  1042. if (r->idMC)
  1043. {
  1044. /*
  1045. * Read message from message catalog.
  1046. */
  1047. string = ReadCatalogXms(MC_LABEL_SET, r->idMC, buf+r->offChallenge);
  1048. }
  1049. else
  1050. {
  1051. /*
  1052. * Generate message from provided string.
  1053. */
  1054. string = XmStringCreate(buf+r->offChallenge,XmFONTLIST_DEFAULT_TAG);
  1055. }
  1056. i = 0;
  1057. XtSetArg(argt[i], XmNlabelString, string ); i++;
  1058. XtSetValues(login_label, argt, i);
  1059. XmStringFree(string);
  1060. if (change)
  1061. {
  1062. char buf[256];
  1063. i = 0;
  1064. if (textdata->bEcho)
  1065. {
  1066. XtSetArg(argt[i], XmNlabelString, textdata->onGreeting ); i++;
  1067. }
  1068. else
  1069. {
  1070. sprintf(buf, textdata->offGreetingFormat,
  1071. textdata->offGreetingUname);
  1072. string = XmStringCreate(buf, XmFONTLIST_DEFAULT_TAG);
  1073. XtSetArg(argt[i], XmNlabelString, string ); i++;
  1074. free(textdata->offGreetingUname);
  1075. }
  1076. XtSetValues(greeting, argt, i);
  1077. /* set the dt_label with the session that is enabled */
  1078. SetDtLabelAndIcon();
  1079. }
  1080. XtSetSensitive(ok_button, True);
  1081. XtSetSensitive(clear_button, True);
  1082. XtSetSensitive(options_button, True);
  1083. XtSetSensitive(help_button, True);
  1084. XUngrabKeyboard(dpyinfo.dpy,CurrentTime);
  1085. }
  1086. break;
  1087. #ifdef SIA
  1088. case REQUEST_OP_FORM:
  1089. {
  1090. RequestForm *r = (RequestForm *)buf;
  1091. int i;
  1092. char *prompt_ptr;
  1093. #ifdef VG_TRACE
  1094. vg_TRACE_EXECUTION("main: got REQUEST_OP_FORM ...");
  1095. #endif /* VG_TRACE */
  1096. siaFormInfo.num_prompts = r->num_prompts;
  1097. siaFormInfo.rendition = r->rendition;
  1098. siaFormInfo.title = XtMalloc(strlen(buf + r->offTitle));
  1099. strcpy(siaFormInfo.title, buf + r->offTitle);
  1100. prompt_ptr = buf + r->offPrompts;
  1101. for (i=0; i < siaFormInfo.num_prompts; i++)
  1102. {
  1103. siaFormInfo.visible[i] = r->visible[i];
  1104. siaFormInfo.prompts[i] = XtMalloc(strlen(prompt_ptr));
  1105. siaFormInfo.answers[i] = NULL;
  1106. strcpy(siaFormInfo.prompts[i], prompt_ptr);
  1107. prompt_ptr += strlen(prompt_ptr) + 1;
  1108. }
  1109. /*
  1110. * Create Widgets:
  1111. * Form
  1112. * Title
  1113. * prompt labels and answer text fields for each prompt
  1114. * OK button
  1115. * Add callbacks as needed. If not visible don't echo.
  1116. * On OK callback, collect info and send it. Destroy widgets.
  1117. */
  1118. SiaForm(&siaFormInfo);
  1119. }
  1120. break;
  1121. #endif /* SIA */
  1122. }
  1123. #if 0
  1124. {
  1125. /*
  1126. * Send immediate response to debug.
  1127. */
  1128. char outbuf[512];
  1129. char *p;
  1130. ResponseDebug *rdebug = (ResponseDebug *)outbuf;
  1131. rdebug->hdr.opcode = REQUEST_OP_DEBUG;
  1132. rdebug->hdr.reserved = 0;
  1133. rdebug->offString = sizeof(*rdebug);
  1134. p = ((char *)(rdebug)) + rdebug->offString;
  1135. strcpy(p, "This is my debug string");
  1136. rdebug->hdr.length = sizeof(*rdebug) + strlen(p) + 1;
  1137. TellRequester(outbuf, (size_t) rdebug->hdr.length);
  1138. }
  1139. #endif
  1140. }
  1141. /***************************************************************************
  1142. *
  1143. * RespondExitCB
  1144. *
  1145. * Respond to an exit request from client
  1146. ***************************************************************************/
  1147. void
  1148. RespondExitCB(
  1149. Widget w,
  1150. XtPointer client,
  1151. XtPointer call)
  1152. {
  1153. char buf[REQUEST_LIM_MAXLEN];
  1154. ResponseExit *r = (ResponseExit *)buf;
  1155. #ifdef VG_TRACE
  1156. vg_TRACE_EXECUTION("main: entered RespondExitCB ...");
  1157. #endif /* VG_TRACE */
  1158. r->hdr.opcode = REQUEST_OP_EXIT;
  1159. r->hdr.reserved = 0;
  1160. r->hdr.length = sizeof(*r);
  1161. TellRequester(buf, (size_t) r->hdr.length);
  1162. CleanupAndExit(NULL, NOTIFY_OK);
  1163. }
  1164. /***************************************************************************
  1165. *
  1166. * RespondLangCB
  1167. *
  1168. * Respond to a lang item selection from user
  1169. ***************************************************************************/
  1170. int amChooser = 0;
  1171. int orig_argc;
  1172. char **orig_argv;
  1173. void
  1174. RespondLangCB( Widget w, XtPointer client, XtPointer call)
  1175. {
  1176. XtSetArg(argt[0], XmNset, True);
  1177. XtSetValues(w, argt, 1);
  1178. #ifdef VG_TRACE
  1179. vg_TRACE_EXECUTION("main: entered RespondLangCB ...");
  1180. #endif /* VG_TRACE */
  1181. if (amChooser) {
  1182. /** this is probably not the ideal way to do this **/
  1183. /** but it does work ok. **/
  1184. /** notice the related code in chooser.c at the **/
  1185. /** beginning of main. **/
  1186. char buff[128];
  1187. if (XmToggleButtonGadgetGetState(w)) {
  1188. snprintf(buff, sizeof(buff), "LANG=%s", (char *) client);
  1189. putenv(buff);
  1190. execv(orig_argv[0], orig_argv);
  1191. }
  1192. } else {
  1193. char buf[REQUEST_LIM_MAXLEN];
  1194. ResponseLang *r = (ResponseLang *)buf;
  1195. char *p;
  1196. r->hdr.opcode = REQUEST_OP_LANG;
  1197. r->hdr.reserved = 0;
  1198. r->offLang = sizeof(*r);
  1199. p = ((char *)(r)) + r->offLang;
  1200. strcpy(p, XmToggleButtonGadgetGetState(w) ? client : "default");
  1201. r->hdr.length = sizeof(*r) + strlen(p) + 1;
  1202. TellRequester(buf, (size_t) r->hdr.length);
  1203. CleanupAndExit(NULL, NOTIFY_LANG_CHANGE);
  1204. }
  1205. }
  1206. /***************************************************************************
  1207. *
  1208. * RespondChallengeCB
  1209. *
  1210. * Respond to a challenge request from client
  1211. ***************************************************************************/
  1212. void
  1213. RespondChallengeCB(
  1214. Widget w,
  1215. XtPointer client,
  1216. XtPointer call)
  1217. {
  1218. char buf[REQUEST_LIM_MAXLEN];
  1219. ResponseChallenge *r = (ResponseChallenge *)buf;
  1220. char *value;
  1221. char *p;
  1222. LoginTextPtr textdata;
  1223. #ifdef VG_TRACE
  1224. vg_TRACE_EXECUTION("main: entered RespondChallengeCB ...");
  1225. #endif /* VG_TRACE */
  1226. XtSetSensitive(ok_button, False);
  1227. XtSetSensitive(clear_button, False);
  1228. XtSetSensitive(options_button, False);
  1229. XtSetSensitive(help_button, False);
  1230. textdata = GetLoginTextPtr(login_text);
  1231. /*
  1232. * Get username and password. Username is obtained from widget
  1233. * while password is stored in global buffer.
  1234. */
  1235. if (textdata->bEcho)
  1236. {
  1237. value = XmTextFieldGetString(login_text);
  1238. textdata->offGreetingUname = strdup(value);
  1239. userName = strdup(value);
  1240. if (strlen(textdata->offGreetingUname) > (size_t) 16)
  1241. {
  1242. textdata->offGreetingUname[16] = '\0';
  1243. userName[16] = '\0';
  1244. }
  1245. }
  1246. else
  1247. {
  1248. value = textdata->noechobuf;
  1249. }
  1250. r->hdr.opcode = REQUEST_OP_CHALLENGE;
  1251. r->hdr.reserved = 0;
  1252. r->offResponse = sizeof(*r);
  1253. p = buf + r->offResponse;
  1254. strcpy(p, value);
  1255. r->hdr.length = r->offResponse + strlen(p) + 1;
  1256. if (textdata->bEcho)
  1257. {
  1258. XtFree(value);
  1259. XmTextFieldSetString(login_text, "");
  1260. }
  1261. else
  1262. {
  1263. /*
  1264. * Clean password memory to foil snoopers.
  1265. */
  1266. bzero(textdata->noechobuf, strlen(textdata->noechobuf));
  1267. }
  1268. TellRequester(buf, (size_t) r->hdr.length);
  1269. }
  1270. /***************************************************************************
  1271. *
  1272. * RespondDialogCB
  1273. *
  1274. * Respond to a request that displayed a dialog
  1275. ***************************************************************************/
  1276. void
  1277. RespondDialogCB(
  1278. Widget w,
  1279. XtPointer client,
  1280. XtPointer call_data)
  1281. {
  1282. char buf[REQUEST_LIM_MAXLEN];
  1283. XmAnyCallbackStruct *reason = (XmAnyCallbackStruct *)call_data;
  1284. #ifdef VG_TRACE
  1285. vg_TRACE_EXECUTION("main: entered RespondDialogCB ...");
  1286. #endif /* VG_TRACE */
  1287. if (w == error_message)
  1288. {
  1289. ResponseMessage *r= (ResponseMessage *)buf;
  1290. r->hdr.opcode = REQUEST_OP_MESSAGE;
  1291. r->hdr.reserved = 0;
  1292. r->hdr.length = sizeof(*r);
  1293. TellRequester(buf, (size_t) r->hdr.length);
  1294. }
  1295. else if (w == passwd_message)
  1296. {
  1297. if (reason->reason == XmCR_OK)
  1298. {
  1299. CleanupAndExit(w, NOTIFY_PASSWD_EXPIRED);
  1300. }
  1301. else
  1302. {
  1303. ResponseExpassword *r= (ResponseExpassword *)buf;
  1304. r->hdr.opcode = REQUEST_OP_EXPASSWORD;
  1305. r->hdr.reserved = 0;
  1306. r->hdr.length = sizeof(*r);
  1307. TellRequester(buf, (size_t) r->hdr.length);
  1308. }
  1309. }
  1310. else if (w == hostname_message)
  1311. {
  1312. if (reason->reason == XmCR_OK)
  1313. {
  1314. CleanupAndExit(w, NOTIFY_OK);
  1315. }
  1316. else
  1317. {
  1318. CleanupAndExit(w, NOTIFY_NO_WINDOWS);
  1319. }
  1320. }
  1321. }
  1322. /***************************************************************************
  1323. *
  1324. * SetDefaultDt
  1325. *
  1326. * save the default dt widget.
  1327. **************************************************************************/
  1328. void
  1329. SetDefaultDt(Widget w)
  1330. {
  1331. default_dt = w;
  1332. }
  1333. /***************************************************************************
  1334. *
  1335. * SetDtLabelAndIcon
  1336. *
  1337. * label to display in the dt_label widget and
  1338. * the logo to display in logo_pixmap
  1339. **************************************************************************/
  1340. void
  1341. SetDtLabelAndIcon(void)
  1342. {
  1343. static XmString blanks = NULL;
  1344. int i;
  1345. char *logoFile;
  1346. char *logoName;
  1347. char *temp_p;
  1348. #ifdef VG_TRACE
  1349. vg_TRACE_EXECUTION("main: entered SetDtLabelAndIcon ...");
  1350. #endif /* VG_TRACE */
  1351. if (NULL == blanks)
  1352. blanks = XmStringCreateLocalized(" ");
  1353. /*
  1354. * if user is logging in, set dt_label desired. No more than
  1355. * one desktop can be selected at a time ...
  1356. */
  1357. i = 0;
  1358. XtSetArg(argt[0], XmNset, FALSE); i++;
  1359. XtSetValues(options_failsafe, argt, i);
  1360. XtSetValues(options_dtlite, argt, i);
  1361. XtSetValues(options_dt, argt, i);
  1362. if (options_last_dt != NULL)
  1363. XtSetValues(options_last_dt, argt, i);
  1364. for(i = 0; i<appInfo.altDts ; ++i)
  1365. if(alt_dts[i] != NULL)
  1366. XtSetValues(alt_dts[i], argt, i);
  1367. if (NULL != default_dt) {
  1368. i = 0;
  1369. XtSetArg(argt[i], XmNset, True); i++;
  1370. XtSetValues(default_dt, argt, i);
  1371. if(default_dt == options_last_dt)
  1372. xmstr = blanks;
  1373. else
  1374. {
  1375. i = 0;
  1376. XtSetArg(argt[i], XmNlabelString, &xmstr); i++;
  1377. XtGetValues(default_dt, argt, i);
  1378. }
  1379. i = 0;
  1380. XtSetArg(argt[i], XmNuserData, &logoFile); i++;
  1381. XtGetValues(default_dt, argt, i);
  1382. }
  1383. else {
  1384. xmstr = blanks;
  1385. logoFile = logoInfo.bitmapFile;
  1386. }
  1387. #ifdef FIX_FOR_DEFECT_CDExc19307
  1388. /*
  1389. * This code causes the Session toggle buttons to be reset
  1390. * to the default setting when the user commits a typing error.
  1391. * NOT very user friendly.
  1392. *
  1393. * As for setting the defaults after the user is done entering
  1394. * the we could do the same thing by passing in an argument. For
  1395. * now, I'm not convinced that it is required.
  1396. */
  1397. /*
  1398. * to set the defaults after the user is done
  1399. * entering the login ..
  1400. */
  1401. if (strcmp(userName,"\0") != 0)
  1402. strcpy(userName,"\0");
  1403. #endif
  1404. i = 0;
  1405. XtSetArg(argt[i], XmNlabelString, xmstr); i++;
  1406. XtSetValues(dt_label, argt, i);
  1407. /*
  1408. * remove trailing spaces
  1409. */
  1410. if(strchr(logoFile,' '))
  1411. temp_p = strtok(logoFile," ");
  1412. else
  1413. temp_p = logoFile;
  1414. logoName = _DtGetIconFileName(
  1415. DefaultScreenOfDisplay(dpyinfo.dpy),
  1416. temp_p, NULL, NULL, 0);
  1417. if (logoName == NULL) {
  1418. LogError(
  1419. ReadCatalog(MC_LOG_SET,MC_LOG_NO_LOGOBIT,MC_DEF_LOG_NO_LOGOBIT),
  1420. logoFile);
  1421. logoFile = NULL;
  1422. }
  1423. i = 0;
  1424. XtSetArg(argt[i], XmNimageName, logoName); i++;
  1425. XtSetValues(logo_pixmap, argt, i);
  1426. }
  1427. /***************************************************************************
  1428. *
  1429. * _DtShowDialog
  1430. *
  1431. * display a dialog message box
  1432. ***************************************************************************/
  1433. static void
  1434. _DtShowDialog( DialogType dtype, XmString msg)
  1435. {
  1436. Widget *w;
  1437. #ifdef VG_TRACE
  1438. vg_TRACE_EXECUTION("main: entered _DtShowDialog ...");
  1439. #endif /* VG_TRACE */
  1440. switch (dtype) {
  1441. case copyright: w = &copyright_msg; break;
  1442. case error: w = &error_message; break;
  1443. case expassword: w = &passwd_message; break;
  1444. case help: w = &help_message; break;
  1445. case hostname: w = &hostname_message; break;
  1446. case help_chooser: w = &help_message; break;
  1447. }
  1448. if (*w == NULL)
  1449. {
  1450. MakeDialog(dtype);
  1451. }
  1452. if ( msg != NULL ) {
  1453. XtSetArg(argt[0], XmNmessageString, msg );
  1454. XtSetValues(*w, argt, 1);
  1455. }
  1456. XtManageChild(*w);
  1457. XSetInputFocus(XtDisplay(*w), XtWindow(*w),
  1458. RevertToPointerRoot, CurrentTime);
  1459. }
  1460. /***************************************************************************
  1461. *
  1462. * ShowDialogCB
  1463. *
  1464. * callback to display a dialog message box
  1465. ***************************************************************************/
  1466. void
  1467. ShowDialogCB( Widget w, XtPointer dialog, XtPointer call_data )
  1468. {
  1469. _DtShowDialog( (DialogType) dialog, NULL);
  1470. }
  1471. /***************************************************************************
  1472. *
  1473. * TextFocusCB
  1474. *
  1475. * set focusWidget global variable when focus changes
  1476. ***************************************************************************/
  1477. void
  1478. TextFocusCB( Widget w, XtPointer client_data, XtPointer call_data )
  1479. {
  1480. if ( w == login_text )
  1481. focusWidget = w;
  1482. }
  1483. /***************************************************************************
  1484. *
  1485. * GetLoginTextPtr
  1486. *
  1487. * Return login text widget instance data
  1488. ***************************************************************************/
  1489. LoginTextPtr
  1490. GetLoginTextPtr( Widget w )
  1491. {
  1492. LoginTextPtr textdata;
  1493. int i;
  1494. i = 0;
  1495. XtSetArg(argt[i], XmNuserData, &textdata ); i++;
  1496. XtGetValues(w, argt, i);
  1497. return(textdata);
  1498. }
  1499. #ifdef BLS
  1500. /***************************************************************************
  1501. *
  1502. * PromptSensitivityLevel
  1503. *
  1504. * Prompt for B1 Sensitivity Level. The password widget set is reused for
  1505. * this purpose rather than creating another complete widget set. It already
  1506. * has most of the proper size and alignment specifications needed. Using
  1507. * the password set also allows the B1 code changes to be more localized.
  1508. *
  1509. ***************************************************************************/
  1510. static void
  1511. PromptSensitivityLevel( void)
  1512. {
  1513. Dimension width;
  1514. int i, width1, width2;
  1515. /*
  1516. * Use the password widget set to prompt for the B1 Sensitivity Level.
  1517. * Remember to put it back to normal if the user presses [Clear].
  1518. */
  1519. normalPasswordWidget = False;
  1520. XtRemoveAllCallbacks(_text, XmNmodifyVerifyCallback);
  1521. XmTextFieldSetString(_text,"");
  1522. /*
  1523. * Change the label and resize the password form...
  1524. */
  1525. i = 0;
  1526. XtSetArg(argt[i], XmNresizable, True ); i++;
  1527. XtSetArg(argt[i], XmNresizePolicy, XmRESIZE_ANY ); i++;
  1528. XtSetValues(_form, argt, i);
  1529. i = 0;
  1530. xmstr = ReadCatalogXms(MC_LABEL_SET, -1, "Sensitivity Level:");
  1531. XtSetArg(argt[i], XmNrecomputeSize, True ); i++;
  1532. XtSetArg(argt[i], XmNlabelString, xmstr ); i++;
  1533. XtSetValues(_label, argt, i);
  1534. XmStringFree(xmstr);
  1535. /*
  1536. * Center the form horizontally in the login_matte...
  1537. *
  1538. */
  1539. CenterForm(matte1, _form);
  1540. ProcessTraversal(_text, XmTRAVERSE_CURRENT);
  1541. }
  1542. #endif /* BLS */
  1543. static void
  1544. TellRequester(char * buf, size_t nbytes)
  1545. {
  1546. #ifdef VG_TRACE
  1547. vg_TRACE_EXECUTION("main: entered TellRequester ...");
  1548. #endif /* VG_TRACE */
  1549. if(-1 == write(1, buf, nbytes)) {
  1550. perror(strerror(errno));
  1551. }
  1552. }