2
0

CmdProcess.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  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: CmdProcess.c /main/8 1998/04/09 17:47:13 mgreess $ */
  24. /***************************************************************************
  25. *
  26. * File: CmdProcess.c
  27. * Description: Miscellaneous functions for the command execution system
  28. * Language: C
  29. *
  30. ** (c) Copyright 1993, 1994 Hewlett-Packard Company
  31. ** (c) Copyright 1993, 1994 International Business Machines Corp.
  32. ** (c) Copyright 1993, 1994 Sun Microsystems, Inc.
  33. ** (c) Copyright 1993, 1994 Novell, Inc.
  34. ***************************************************************************/
  35. #include "CmdInvP.h"
  36. #include <X11/Xproto.h>
  37. #include <Dt/CommandM.h>
  38. #include <Dt/DtNlUtils.h>
  39. #include <Dt/ActionUtilP.h>
  40. #include "myassertP.h"
  41. #if defined(sun)
  42. #include <limits.h>
  43. #endif
  44. #if defined(__hpux)
  45. #include <sys/getaccess.h>
  46. #endif
  47. #include <sys/socket.h>
  48. #include <netdb.h>
  49. #include <netinet/in.h>
  50. #include <Tt/tt_c.h>
  51. /*
  52. * Global variables:
  53. */
  54. Cmd_Resources cmd_Resources = { 0 };
  55. Cmd_Globals cmd_Globals = { 0 };
  56. /******** Static Function Declarations ********/
  57. static char *_GetRemoteTerminalsResource (
  58. Display *display,
  59. char *appClass,
  60. char *appName);
  61. static void GetRemoteTerminalsResource (
  62. Display *display,
  63. char *appClass,
  64. char *appName);
  65. static void GetLocalTerminalResource (
  66. Display *display,
  67. char *appClass,
  68. char *appName);
  69. static void GetWaitTimeResource (
  70. Display *display,
  71. char *appClass,
  72. char *appName);
  73. static void GetDtexecPath (
  74. Display *display,
  75. char *appClass,
  76. char *appName);
  77. static void GetExecutionHostLoggingResource (
  78. Display *display,
  79. char *appClass,
  80. char *appName);
  81. static char *GetRemoteTerminal(
  82. char *host);
  83. /******** End Static Function Declarations ********/
  84. /******************************************************************************
  85. *
  86. * _GetRemoteTerminalsResource - gets the value of the "remoteTerminals"
  87. * resource.
  88. *
  89. * PARAMETERS:
  90. *
  91. * Display *display; The connection to the X server.
  92. *
  93. * char *appClass; The client's application class.
  94. *
  95. * char *appName; The client's application name.
  96. *
  97. * RETURNS: a pointer to the "remoteTerminals" resource or NULL if the
  98. * resource is not defined.
  99. *
  100. * NOTES: The space for the returned string is "malloc'ed". The calling
  101. * function should free the string.
  102. *
  103. *****************************************************************************/
  104. static char
  105. *_GetRemoteTerminalsResource (
  106. Display *display,
  107. char *appClass,
  108. char *appName)
  109. {
  110. XrmValue resource_value;
  111. XrmDatabase db;
  112. char *rep_type;
  113. char *name;
  114. char *class;
  115. char *terminals = NULL;
  116. name = XtMalloc (strlen (DtREMOTE_TERMINALS_NAME) + strlen (appName) + 4);
  117. sprintf (name, "%s*%s", appName, DtREMOTE_TERMINALS_NAME);
  118. class = XtMalloc (strlen (DtREMOTE_TERMINALS_CLASS) + strlen (appClass) + 4);
  119. sprintf (class, "%s*%s", appClass, DtREMOTE_TERMINALS_CLASS);
  120. db = XtDatabase (display);
  121. if (XrmGetResource (db, name, class, &rep_type, &resource_value))
  122. terminals = (char *) XtNewString (resource_value.addr);
  123. XtFree (name);
  124. XtFree (class);
  125. return (terminals);
  126. }
  127. /******************************************************************************
  128. *
  129. * GetRemoteTerminalsResource - initializes the "remoteTerminals" resource.
  130. *
  131. * PARAMETERS:
  132. *
  133. * Display *display; The connection to the X server.
  134. *
  135. * char *appClass; The client's application class.
  136. *
  137. * char *appName; The client's application name.
  138. *
  139. * MODIFIED:
  140. *
  141. * char *cmd_Resources.remoteTerminals; - Set to the list of remote
  142. * terminals.
  143. *
  144. * char *cmd_Resources.remoteHosts; - Set to the list of remote hosts..
  145. *
  146. *****************************************************************************/
  147. static void
  148. GetRemoteTerminalsResource (
  149. Display *display,
  150. char *appClass,
  151. char *appName)
  152. {
  153. int num, j;
  154. char *terminals;
  155. char *pch, *host;
  156. if ((terminals = _GetRemoteTerminalsResource (display, appClass, appName))
  157. == NULL) {
  158. /*
  159. * The resource was not specified, and no defaults are set.
  160. */
  161. cmd_Resources.remoteHosts = (char **) NULL;
  162. cmd_Resources.remoteTerminals = (char **) NULL;
  163. return;
  164. }
  165. /*
  166. * Find out how many terminals are specified by counting the number of
  167. * colons.
  168. */
  169. for (pch=terminals, num=0; pch != NULL ; ) {
  170. if ((pch = DtStrchr (pch, ':')) != NULL) {
  171. /*
  172. * Move past the ':'.
  173. */
  174. pch++;
  175. num++;
  176. }
  177. }
  178. if (num == 0) {
  179. /*
  180. * No "host:/terminal" pairs were found.
  181. */
  182. cmd_Resources.remoteHosts = (char **) NULL;
  183. cmd_Resources.remoteTerminals = (char **) NULL;
  184. return;
  185. }
  186. /*
  187. * Create space for the pointers to the hosts and terminals and
  188. * make room for a NULL terminator.
  189. *
  190. * Note that the host names and terminal names are "vectorized" in
  191. * place by replacing the ':' and ',' characters with '\0'.
  192. */
  193. cmd_Resources.remoteHosts = (char **) XtMalloc (num * sizeof(char *));
  194. cmd_Resources.remoteTerminals = (char **) XtMalloc (num * sizeof(char *));
  195. for (pch=terminals, j=0; j < num && pch != NULL && *pch != '\0'; j++)
  196. {
  197. host = pch;
  198. if ((pch = DtStrchr (pch, ':')) == NULL)
  199. break;
  200. /*
  201. * Null terminate the host and then move past the ':'.
  202. */
  203. *pch = '\0';
  204. pch++;
  205. if (*pch == '\0')
  206. /*
  207. * Found a host but nothing followed it.
  208. */
  209. break;
  210. cmd_Resources.remoteHosts[j] = host;
  211. cmd_Resources.remoteTerminals[j] = pch;
  212. /*
  213. * Find the end of this entry and skip past it.
  214. */
  215. if ((pch = DtStrchr (pch, ',')) == NULL) {
  216. /*
  217. * This is the last pair, advance "j" and break the loop.
  218. */
  219. j++;
  220. break;
  221. }
  222. /*
  223. * End the terminal name.
  224. */
  225. *pch = '\0';
  226. pch++;
  227. }
  228. /*
  229. * NULL terminate the arrays.
  230. */
  231. cmd_Resources.remoteHosts[j] = (char *) NULL;
  232. cmd_Resources.remoteTerminals[j] = (char *) NULL;
  233. }
  234. /******************************************************************************
  235. *
  236. * GetLocalTerminalResource - initializes the "localTerminal resource.
  237. *
  238. * PARAMETERS:
  239. *
  240. * Display *display; The connection to the X server.
  241. *
  242. * char *appClass; The client's application class.
  243. *
  244. * char *appName; The client's application name.
  245. *
  246. * MODIFIED:
  247. *
  248. * char *cmd_Resources.localTerminal; - Set to the "localTerminal"
  249. * or to DtDEFUALT_TERMINAL.
  250. *
  251. * Boolean cmd_Globals.terminal_ok; - Set to True if "localTerminal"
  252. * is executable and has the correct
  253. * permissions; False otherwise.
  254. *
  255. *****************************************************************************/
  256. static void
  257. GetLocalTerminalResource (
  258. Display *display,
  259. char *appClass,
  260. char *appName)
  261. {
  262. XrmValue resource_value;
  263. char *rep_type;
  264. char *name;
  265. char *class;
  266. XrmDatabase db = XtDatabase (display);
  267. name = XtMalloc (strlen (DtLOCAL_TERMINAL_NAME) + strlen (appName) + 4);
  268. sprintf (name, "%s*%s", appName, DtLOCAL_TERMINAL_NAME);
  269. class = XtMalloc (strlen (DtLOCAL_TERMINAL_CLASS) + strlen (appClass) + 4);
  270. sprintf (class, "%s*%s", appClass, DtLOCAL_TERMINAL_CLASS);
  271. if (XrmGetResource (db, name, class, &rep_type, &resource_value))
  272. cmd_Resources.localTerminal = (char *) XtNewString (resource_value.addr);
  273. else
  274. cmd_Resources.localTerminal = XtNewString (DtTERMINAL_DEFAULT);
  275. /*
  276. * Check to see if the execvp will potentially fail because the
  277. * localTerminal is not accessable or it it is not executable. If not,
  278. * log an error message.
  279. */
  280. cmd_Globals.terminal_ok = True;
  281. if (!(_DtCmdCheckForExecutable (cmd_Resources.localTerminal))) {
  282. char *errorMessage = XtMalloc(MAX_BUF_SIZE);
  283. cmd_Globals.terminal_ok = False;
  284. if (errorMessage)
  285. {
  286. (void) sprintf (errorMessage,
  287. cmd_Globals.error_terminal,
  288. cmd_Resources.localTerminal);
  289. _DtCmdLogErrorMessage (errorMessage);
  290. XtFree(errorMessage);
  291. }
  292. }
  293. XtFree (name);
  294. XtFree (class);
  295. }
  296. /******************************************************************************
  297. *
  298. * GetWaitTimeResource - initializes the "waitTime" resource.
  299. *
  300. * PARAMETERS:
  301. *
  302. * Display *display; The connection to the X server.
  303. *
  304. * char *appClass; The client's application class.
  305. *
  306. * char *appName; The client's application name.
  307. *
  308. * MODIFIED:
  309. *
  310. * char *cmd_Resources.waitTime; - Set to the "waitTime" resource
  311. * or "True" by default.
  312. *
  313. *****************************************************************************/
  314. static void
  315. GetWaitTimeResource (
  316. Display *display,
  317. char *appClass,
  318. char *appName)
  319. {
  320. XrmValue resource_value;
  321. char *rep_type;
  322. char *name;
  323. char *class;
  324. XrmDatabase db= XtDatabase (display);
  325. cmd_Resources.waitTime = DtWAIT_TIME_DEFAULT;
  326. name = XtMalloc (strlen (DtWAIT_TIME_NAME) + strlen (appName) + 4);
  327. sprintf (name, "%s*%s", appName, DtWAIT_TIME_NAME);
  328. class = XtMalloc (strlen (DtWAIT_TIME_CLASS) + strlen (appClass) + 4);
  329. sprintf (class, "%s*%s", appClass, DtWAIT_TIME_CLASS);
  330. if (XrmGetResource (db, name, class, &rep_type, &resource_value)) {
  331. cmd_Resources.waitTime = atoi (resource_value.addr);
  332. if (cmd_Resources.waitTime < 0)
  333. cmd_Resources.waitTime = DtWAIT_TIME_DEFAULT;
  334. }
  335. XtFree (name);
  336. XtFree (class);
  337. }
  338. /******************************************************************************
  339. *
  340. * GetDtexecPath - initializes the "dtexecPath" resource.
  341. *
  342. * PARAMETERS:
  343. *
  344. * Display *display; The connection to the X server.
  345. *
  346. * char *appClass; The client's application class.
  347. *
  348. * char *appName; The client's application name.
  349. *
  350. * MODIFIED:
  351. *
  352. * char *cmd_Resources.dtexecPath; - Set to the "dtexecPath" resource
  353. * or to DtCMD_INV_SUB_PROCESS.
  354. *
  355. *****************************************************************************/
  356. static void
  357. GetDtexecPath (
  358. Display *display,
  359. char *appClass,
  360. char *appName)
  361. {
  362. XrmValue resource_value;
  363. char *rep_type;
  364. char errorMessage [MAX_BUF_SIZE];
  365. char *name;
  366. char *class;
  367. XrmDatabase db = XtDatabase (display);
  368. name = XtMalloc (strlen (DtDTEXEC_PATH_NAME) + strlen (appName) + 4);
  369. sprintf (name, "%s*%s", appName, DtDTEXEC_PATH_NAME);
  370. class = XtMalloc (strlen (DtDTEXEC_PATH_CLASS) + strlen (appClass) + 4);
  371. sprintf (class, "%s*%s", appClass, DtDTEXEC_PATH_CLASS);
  372. if (XrmGetResource (db, name, class, &rep_type, &resource_value))
  373. cmd_Resources.dtexecPath = (char *) XtNewString (resource_value.addr);
  374. else
  375. cmd_Resources.dtexecPath = XtNewString (DtCMD_INV_SUB_PROCESS);
  376. /*
  377. * Check to see if the execvp will potentially fail because the
  378. * subprocess is not accessable or it it is not executable. If not,
  379. * log an error message.
  380. */
  381. cmd_Globals.subprocess_ok = True;
  382. if (!(_DtCmdCheckForExecutable (cmd_Resources.dtexecPath))) {
  383. char *errorMessage = XtMalloc(MAX_BUF_SIZE);
  384. cmd_Globals.subprocess_ok = False;
  385. if (errorMessage)
  386. {
  387. (void) sprintf (errorMessage,
  388. cmd_Globals.error_subprocess,
  389. cmd_Resources.dtexecPath);
  390. _DtCmdLogErrorMessage (errorMessage);
  391. XtFree(errorMessage);
  392. }
  393. }
  394. XtFree (name);
  395. XtFree (class);
  396. }
  397. /******************************************************************************
  398. *
  399. * GetExecutionHostLoggingResources - initializes the "executionHostLogging"
  400. *
  401. *
  402. * PARAMETERS:
  403. *
  404. * Display *display; The connection to the X server.
  405. *
  406. * char *appClass; The client's application class.
  407. *
  408. * char *appName; The client's application name.
  409. *
  410. * MODIFIED:
  411. *
  412. * char *cmd_Resources.executionHostLogging;
  413. *
  414. * - Set to the "executionHostLogging" resource or "False" by default.
  415. *
  416. *****************************************************************************/
  417. static void
  418. GetExecutionHostLoggingResource (
  419. Display *display,
  420. char *appClass,
  421. char *appName)
  422. {
  423. XrmValue resource_value;
  424. char *rep_type;
  425. char *name;
  426. char *class;
  427. XrmDatabase db= XtDatabase (display);
  428. cmd_Resources.executionHostLogging = False;
  429. name = XtMalloc (strlen (DtEXECUTION_HOST_LOGGING_NAME) +
  430. strlen (appName) + 4);
  431. sprintf (name, "%s*%s", appName, DtEXECUTION_HOST_LOGGING_NAME);
  432. class = XtMalloc (strlen (DtEXECUTION_HOST_LOGGING_CLASS) +
  433. strlen (appClass) + 4);
  434. sprintf (class, "%s*%s", appClass, DtEXECUTION_HOST_LOGGING_CLASS);
  435. if (XrmGetResource (db, name, class, &rep_type, &resource_value)) {
  436. if (((strcmp (resource_value.addr, "True")) == 0) ||
  437. ((strcmp (resource_value.addr, "true")) == 0) ||
  438. ((strcmp (resource_value.addr, "TRUE")) == 0))
  439. cmd_Resources.executionHostLogging = True;
  440. else if (((strcmp (resource_value.addr, "False")) == 0) ||
  441. ((strcmp (resource_value.addr, "false")) == 0) ||
  442. ((strcmp (resource_value.addr, "FALSE")) == 0))
  443. cmd_Resources.executionHostLogging = False;
  444. }
  445. XtFree (name);
  446. XtFree (class);
  447. }
  448. /******************************************************************************
  449. *
  450. * GetRemoteTerminal - takes a host name "host" and searches the list of remote
  451. * host:terminal pairs for "host" and if found, returns the corresponding
  452. * terminal emulator.
  453. *
  454. * PARAMETERS:
  455. *
  456. * char *host; - Name of the host to use as the key to find
  457. * the terminal emulator name.
  458. *
  459. * RETURNS: If "host" is found, the corresponding terminal emulator is
  460. * returned, otherwise "NULL" is returned.
  461. *
  462. *****************************************************************************/
  463. static char *
  464. GetRemoteTerminal(
  465. char *host )
  466. {
  467. int i;
  468. if (cmd_Resources.remoteHosts == NULL)
  469. return (NULL);
  470. for (i=0; cmd_Resources.remoteHosts[i] != NULL; i++) {
  471. if ((strcmp (host, cmd_Resources.remoteHosts[i])) == 0)
  472. return (cmd_Resources.remoteTerminals[i]);
  473. }
  474. return (NULL);
  475. }
  476. /******************************************************************************
  477. *
  478. * _DtCmdCreateTerminalCommand - takes a windowType, execString
  479. * and execParms and creates an appropriate command to execute.
  480. *
  481. * Note that if valid execParms are found, they are simply added
  482. * to the execution string, before the "-e" option.
  483. *
  484. * PARAMETERS:
  485. *
  486. * char **theCommand; - The command line to be expanded and returned.
  487. * int windowType; - The request number (window number).
  488. * char *execString; - The execution string to be expanded.
  489. * char *execParms; - The execution parameters.
  490. * char *procId - tooltalk procId for dtexec
  491. * char *tmpFiles - string containing tmp file args for dtexec
  492. *
  493. * MODIFIED:
  494. *
  495. * char ** theCommand; - Contains the completed execution string.
  496. *
  497. *****************************************************************************/
  498. void
  499. _DtCmdCreateTerminalCommand(
  500. char **theCommand,
  501. int windowType,
  502. char *execString,
  503. char *execParms,
  504. char *execHost,
  505. char *procId,
  506. char *tmpFiles)
  507. {
  508. char *pGeom = NULL;
  509. char *pName = NULL;
  510. char *pTitle = NULL;
  511. char options[MAX_BUF_SIZE];
  512. char *defaultTerminal;
  513. strcpy(options,execParms);
  514. /*
  515. * Get the name of the terminal emulator to use.
  516. */
  517. if ((defaultTerminal = GetRemoteTerminal (execHost)) == NULL)
  518. defaultTerminal = cmd_Resources.localTerminal;
  519. /*
  520. * Create space for the expanded command line.
  521. */
  522. *theCommand = (char *) XtMalloc ( strlen (defaultTerminal)
  523. + strlen(options)
  524. + strlen(cmd_Resources.dtexecPath)
  525. + strlen(" -open ") + 4 /* max waitTime len */
  526. + strlen(" -ttprocid ") + strlen(_DtActNULL_GUARD(procId))
  527. + strlen(_DtActNULL_GUARD(tmpFiles))
  528. + strlen(execString) + 9 /* 2 quotes, "-e", 7 blanks, null */ );
  529. if (windowType == TERMINAL) {
  530. (void) sprintf (*theCommand, "%s %s -e %s -open %d -ttprocid '%s' %s %s",
  531. defaultTerminal, options, cmd_Resources.dtexecPath,
  532. cmd_Resources.waitTime,
  533. _DtActNULL_GUARD(procId),
  534. _DtActNULL_GUARD(tmpFiles),
  535. execString);
  536. }
  537. else {
  538. (void) sprintf (*theCommand, "%s %s -e %s -open -1 -ttprocid '%s' %s %s",
  539. defaultTerminal, options, cmd_Resources.dtexecPath,
  540. _DtActNULL_GUARD(procId),
  541. _DtActNULL_GUARD(tmpFiles),
  542. execString);
  543. }
  544. }
  545. /******************************************************************************
  546. *
  547. * _DtCmdCheckForExecutable - checks "fileName" to see if it is executable
  548. * by the user.
  549. *
  550. * PARAMETERES:
  551. *
  552. * char *fileName; - The name of the file to check.
  553. *
  554. * RETURNS: "True" if the file is access'able && executable, "False" otherwise.
  555. *
  556. *****************************************************************************/
  557. Boolean
  558. _DtCmdCheckForExecutable(
  559. char *fileName )
  560. {
  561. char **ppch;
  562. int access;
  563. /* First check to see if the fileName contains the complete path
  564. * and is access'able.
  565. */
  566. switch (access = _DtExecuteAccess(fileName))
  567. {
  568. /* execution access allowed for this process */
  569. case 1: return True;
  570. break;
  571. /* file found -- not executable by this process */
  572. case 0: return False;
  573. break;
  574. /* file not found -- yet */
  575. case -1: /* fall through */
  576. default:
  577. break;
  578. }
  579. /* Append fileName to each entry in "cmd_Globals.path_list" and then see
  580. * if that is accessable.
  581. */
  582. for (ppch = cmd_Globals.path_list; *ppch != NULL; ppch++)
  583. {
  584. char *longName = XtMalloc(MAXPATHLEN);
  585. if (longName)
  586. {
  587. (void) sprintf (longName, "%s/%s", *ppch, fileName);
  588. switch (access = _DtExecuteAccess(longName))
  589. {
  590. /* execution access allowed for this process */
  591. case 1: return True;
  592. break;
  593. /* file found -- not executable by this process */
  594. case 0: return False;
  595. break;
  596. /* file not found -- yet */
  597. case -1: /* fall through */
  598. default:
  599. break;
  600. }
  601. XtFree(longName);
  602. }
  603. }
  604. return (False);
  605. }
  606. /******************************************************************************
  607. *
  608. * _DtCmdValidDir - takes the client host, context directory and a context host
  609. * and checks to see if the directory is valid.
  610. *
  611. * PARAMETERS:
  612. *
  613. * char *clientHost; - Host where the client is running.
  614. *
  615. * char *contextDir; - Directory to "chdir" to.
  616. *
  617. * char *contextHost; - Host where 'contextDir' resides.
  618. *
  619. * NOTES:
  620. *
  621. * If the context directory is NULL, "chdir" is not run and "True" is
  622. * returned.
  623. *
  624. * RETURNS: "True" if "chdir" succeeds and "False" otherwise.
  625. *
  626. *****************************************************************************/
  627. Boolean
  628. _DtCmdValidDir(
  629. char *clientHost,
  630. char *contextDir,
  631. char *contextHost )
  632. {
  633. int retValue = 0;
  634. if (contextDir == NULL)
  635. /*
  636. * Stay in the same directory.
  637. */
  638. return (True);
  639. if (contextHost == NULL)
  640. /*
  641. * Change to 'contextDir'.
  642. */
  643. retValue = chdir (contextDir);
  644. else if (_DtIsSameHost (clientHost, contextHost))
  645. /*
  646. * Just change to 'contextDir'.
  647. */
  648. retValue = chdir (contextDir);
  649. else {
  650. /*
  651. * Need to create a pathname for the directory.
  652. */
  653. char *netfile;
  654. char *path;
  655. char *errorMessage = XtMalloc(MAX_BUF_SIZE);
  656. /* Old syntax should no longer appear in contextHost/Dir */
  657. myassert( *contextHost != '*' && *contextDir != '*' );
  658. netfile = (char *) tt_host_file_netfile (contextHost, contextDir);
  659. if (tt_pointer_error (netfile) != TT_OK) {
  660. (void) sprintf (errorMessage, cmd_Globals.error_directory_name_map,
  661. contextDir, contextHost,
  662. tt_status_message (tt_pointer_error(netfile)));
  663. _DtCmdLogErrorMessage (errorMessage);
  664. return (False);
  665. }
  666. path = (char *) tt_netfile_file (netfile);
  667. tt_free (netfile);
  668. if (tt_pointer_error (path) != TT_OK) {
  669. (void) sprintf (errorMessage, cmd_Globals.error_directory_name_map,
  670. contextDir, contextHost,
  671. tt_status_message (tt_pointer_error(path)));
  672. _DtCmdLogErrorMessage (errorMessage);
  673. return (False);
  674. }
  675. retValue = chdir (path);
  676. tt_free (path);
  677. if (errorMessage) XtFree(errorMessage);
  678. }
  679. if (retValue == -1)
  680. return (False);
  681. else
  682. return (True);
  683. }
  684. /******************************************************************************
  685. *
  686. * _DtCmdGetResources - initializes the Command Invoker's resources.
  687. *
  688. * PARAMETERS:
  689. *
  690. * Display *display; The connection to the X server.
  691. *
  692. * char *appClass; The client's application class.
  693. *
  694. *****************************************************************************/
  695. void
  696. _DtCmdGetResources (
  697. Display *display)
  698. {
  699. char *appClass = NULL;
  700. char *appName = NULL;
  701. /*
  702. * Determine the name and class for this client.
  703. */
  704. XtGetApplicationNameAndClass (display, &appName, &appClass);
  705. GetLocalTerminalResource (display, appClass, appName);
  706. GetRemoteTerminalsResource (display, appClass, appName);
  707. GetWaitTimeResource (display, appClass, appName);
  708. GetDtexecPath (display, appClass, appName);
  709. GetExecutionHostLoggingResource (display, appClass, appName);
  710. }