CmdProcess.c 22 KB

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