resource.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868
  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: resource.c /main/7 1997/03/14 13:45:09 barstow $ */
  24. /* (c) Copyright 1997 The Open Group */
  25. /* *
  26. * (c) Copyright 1993, 1994 Hewlett-Packard Company *
  27. * (c) Copyright 1993, 1994 International Business Machines Corp. *
  28. * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
  29. * (c) Copyright 1993, 1994 Novell, Inc. *
  30. */
  31. /*
  32. * xdm - display manager daemon
  33. *
  34. * Copyright 1988 Massachusetts Institute of Technology
  35. *
  36. * Permission to use, copy, modify, and distribute this software and its
  37. * documentation for any purpose and without fee is hereby granted, provided
  38. * that the above copyright notice appear in all copies and that both that
  39. * copyright notice and this permission notice appear in supporting
  40. * documentation, and that the name of M.I.T. not be used in advertising or
  41. * publicity pertaining to distribution of the software without specific,
  42. * written prior permission. M.I.T. makes no representations about the
  43. * suitability of this software for any purpose. It is provided "as is"
  44. * without express or implied warranty.
  45. *
  46. * Author: Keith Packard, MIT X Consortium
  47. */
  48. /*
  49. * resource.c
  50. */
  51. # include "dm.h"
  52. # include "vgmsg.h"
  53. # include <X11/Xresource.h>
  54. # include <X11/Xmu/CharSet.h>
  55. # include <string.h>
  56. void CleanUpName( char *src, char *dst, int len) ;
  57. static char * getFullFileName(char *name, int special, char * lang);
  58. extern char * qualifyWithFirst(char *, char *);
  59. void GetSysParms(char **tzpp, char **fhpp, char **ftpp); // fontpath.c
  60. /* XtOffset() hack for ibmrt BandAidCompiler */
  61. int session_set = False;
  62. char *config;
  63. char *servers;
  64. int request_port;
  65. int debugLevel;
  66. char *errorLogFile;
  67. int errorLogSize;
  68. int daemonMode;
  69. int quiet;
  70. char *pidFile;
  71. int lockPidFile;
  72. char *authDir;
  73. int autoRescan;
  74. int removeDomainname;
  75. char *keyFile;
  76. char *accessFile;
  77. char **exportList; /* List of all export env vars */
  78. char *sysParmsFile;
  79. char *timeZone;
  80. char *fpHead = NULL;
  81. char *fpTail = NULL;
  82. int wakeupInterval;
  83. int langListTimeout;
  84. #ifdef DEF_NETWORK_DEV
  85. char *networkDev;
  86. #endif
  87. /*
  88. * Dtlogin will accept both Dtlogin and XDM resources. The string variable
  89. * "AppName" contains the proper application name to use in looking up
  90. * resources.
  91. */
  92. # define DISPLAYMANAGER "DisplayManager"
  93. # define DTLOGIN "Dtlogin"
  94. static char AppName[16] = DTLOGIN;
  95. # define DM_STRING 0
  96. # define DM_INT 1
  97. # define DM_BOOL 2
  98. # define DM_ARGV 3
  99. /*
  100. * the following constants are supposed to be set in the makefile from
  101. * parameters set util/imake.includes/site.def (or *.macros in that directory
  102. * if it is server-specific). DO NOT CHANGE THESE DEFINITIONS!
  103. */
  104. #ifndef DEF_SERVER_LINE
  105. # ifdef sun
  106. #define DEF_SERVER_LINE ":0 local /usr/openwin/bin/X :0"
  107. # else
  108. #define DEF_SERVER_LINE ":0 local /usr/bin/X11/X :0"
  109. # endif /* sun */
  110. #endif
  111. #ifndef XRDB_PROGRAM
  112. # ifdef sun
  113. #define XRDB_PROGRAM "/usr/openwin/bin/xrdb"
  114. # else
  115. #define XRDB_PROGRAM "/usr/bin/X11/xrdb"
  116. # endif /* sun */
  117. #endif
  118. #ifndef DEF_SESSION
  119. #define DEF_SESSION CDE_INSTALLATION_TOP "/bin/Xsession"
  120. #endif
  121. #ifndef DEF_USER_PATH
  122. # ifdef sun
  123. # define DEF_USER_PATH "/usr/openwin/bin:/bin:/usr/bin:/usr/contrib/bin:/usr/local/bin:."
  124. # else
  125. # define DEF_USER_PATH "/usr/bin/X11:/bin:/usr/bin:/usr/contrib/bin:/usr/local/bin"
  126. # endif /* sun */
  127. #endif
  128. #ifndef DEF_SYSTEM_PATH
  129. # ifdef sun
  130. # define DEF_SYSTEM_PATH "/usr/openwin/bin:/etc:/bin:/usr/bin"
  131. # else
  132. # define DEF_SYSTEM_PATH "/usr/bin/X11:/etc:/bin:/usr/bin"
  133. # endif /* sun */
  134. #endif
  135. #ifndef DEF_SYSTEM_SHELL
  136. #define DEF_SYSTEM_SHELL "/bin/sh"
  137. #endif
  138. #ifndef DEF_FAILSAFE_CLIENT
  139. # ifdef sun
  140. #define DEF_FAILSAFE_CLIENT "/usr/openwin/bin/xterm"
  141. # else
  142. #define DEF_FAILSAFE_CLIENT "/usr/bin/X11/xterm"
  143. # endif /* sun */
  144. #endif
  145. #ifndef DEF_XDM_CONFIG
  146. #define DEF_XDM_CONFIG "Xconfig"
  147. #endif
  148. #ifndef DEF_CHOOSER
  149. #define DEF_CHOOSER CDE_INSTALLATION_TOP "/bin/chooser"
  150. #endif
  151. #ifndef CPP_PROGRAM
  152. #define CPP_PROGRAM "/lib/cpp"
  153. #endif
  154. #ifndef DEF_XDM_AUTH_GEN
  155. #define DEF_XDM_AUTH_GEN CDE_CONFIGURATION_TOP "/xdmauthgen"
  156. #endif
  157. #ifndef DEF_AUTH_NAME
  158. #define DEF_AUTH_NAME "MIT-MAGIC-COOKIE-1"
  159. #endif
  160. #ifndef DEF_AUTH_DIR
  161. #define DEF_AUTH_DIR CDE_CONFIGURATION_TOP
  162. #endif
  163. #ifndef DEF_USER_AUTH_DIR
  164. #define DEF_USER_AUTH_DIR "/tmp"
  165. #endif
  166. #ifndef DEF_KEY_FILE
  167. #define DEF_KEY_FILE CDE_CONFIGURATION_TOP "/Xkeys"
  168. #endif
  169. #ifndef DEF_ACCESS_FILE
  170. #define DEF_ACCESS_FILE ""
  171. #endif
  172. #ifndef DEF_TIMEZONE
  173. #define DEF_TIMEZONE "MST7MDT"
  174. #endif
  175. #ifndef DEF_SYS_PARMS_FILE
  176. # define DEF_SYS_PARMS_FILE "/etc/TIMEZONE"
  177. #endif
  178. #define DEF_UDP_PORT "177" /* registered XDMCP port, don't change */
  179. #ifndef DEF_ENV
  180. # ifdef sun /* need to set the environment for Sun OpenWindows */
  181. # define DEF_ENV "OPENWINHOME=/usr/openwin"
  182. # else
  183. # define DEF_ENV ""
  184. # endif
  185. #endif
  186. #ifndef DEF_LANG /* LANG default settings for various architectures */
  187. # ifdef sun /* default language under Solaris */
  188. # define DEF_LANG "C"
  189. # endif
  190. #endif
  191. #ifndef DEF_LANG /* set LANG to NULL if not already defined */
  192. #define DEF_LANG ""
  193. #endif
  194. struct dmResources {
  195. char *name, *class;
  196. int type;
  197. char **dm_value;
  198. char *default_value;
  199. } DmResources[] = {
  200. "servers", "Servers", DM_STRING, &servers,
  201. DEF_SERVER_LINE,
  202. "requestPort", "RequestPort", DM_INT, (char **) &request_port,
  203. DEF_UDP_PORT,
  204. "debugLevel", "DebugLevel", DM_INT, (char **) &debugLevel,
  205. "0",
  206. "errorLogFile", "ErrorLogFile", DM_STRING, &errorLogFile,
  207. "",
  208. "errorLogSize", "ErrorLogSize", DM_INT, (char **) &errorLogSize,
  209. "50",
  210. "daemonMode", "DaemonMode", DM_BOOL, (char **) &daemonMode,
  211. "false",
  212. "quiet", "quiet", DM_BOOL, (char **) &quiet,
  213. "false",
  214. "pidFile", "PidFile", DM_STRING, &pidFile,
  215. "",
  216. "lockPidFile", "LockPidFile", DM_BOOL, (char **) &lockPidFile,
  217. "true",
  218. "authDir", "AuthDir", DM_STRING, &authDir,
  219. DEF_AUTH_DIR,
  220. "autoRescan", "AutoRescan", DM_BOOL, (char **) &autoRescan,
  221. "true",
  222. "removeDomainname","RemoveDomainname",DM_BOOL, (char **) &removeDomainname,
  223. "true",
  224. "keyFile", "KeyFile", DM_STRING, &keyFile,
  225. DEF_KEY_FILE,
  226. "accessFile", "AccessFile", DM_STRING, &accessFile,
  227. DEF_ACCESS_FILE,
  228. /* exportList env var resource RK 08.17.93 */
  229. "exportList", "ExportList", DM_ARGV, (char **) &exportList,
  230. "",
  231. "timeZone", "TimeZone", DM_STRING, &timeZone,
  232. "",
  233. "fontPathHead", "FontPathHead", DM_STRING, &fpHead,
  234. "",
  235. "fontPathTail", "FontPathTail", DM_STRING, &fpTail,
  236. "",
  237. "sysParmsFile", "SysParmsFile", DM_STRING, &sysParmsFile,
  238. DEF_SYS_PARMS_FILE,
  239. "wakeupInterval","WakeupInterval",DM_INT, (char **) &wakeupInterval,
  240. "10",
  241. "langListTimeout","langListTimeout",DM_INT, (char **) &langListTimeout,
  242. "30",
  243. #ifdef DEF_NETWORK_DEV
  244. "networkDevice","NetworkDevice",DM_STRING, &networkDev,
  245. DEF_NETWORK_DEV,
  246. #endif
  247. };
  248. # define NUM_DM_RESOURCES (sizeof DmResources / sizeof DmResources[0])
  249. # define boffset(f) ((char *) &(((struct display *) 0)->f) - (char *) 0)
  250. struct displayResources {
  251. char *name, *class;
  252. int type;
  253. int offset;
  254. char *default_value;
  255. } DisplayResources[] = {
  256. /*
  257. * resources for managing the server...
  258. */
  259. "serverAttempts","ServerAttempts", DM_INT, boffset(serverAttempts),
  260. "1",
  261. "openDelay", "OpenDelay", DM_INT, boffset(openDelay),
  262. "5",
  263. "openRepeat", "OpenRepeat", DM_INT, boffset(openRepeat),
  264. "5",
  265. "openTimeout", "OpenTimeout", DM_INT, boffset(openTimeout),
  266. "30",
  267. "startAttempts","StartAttempts",DM_INT, boffset(startAttempts),
  268. "4",
  269. "pingInterval", "PingInterval", DM_INT, boffset(pingInterval),
  270. "5",
  271. "pingTimeout", "PingTimeout", DM_INT, boffset(pingTimeout),
  272. "5",
  273. "terminateServer","TerminateServer",DM_BOOL, boffset(terminateServer),
  274. "false",
  275. "grabServer", "GrabServer", DM_BOOL, boffset(grabServer),
  276. "true",
  277. "grabTimeout", "GrabTimeout", DM_INT, boffset(grabTimeout),
  278. "3",
  279. "resetSignal", "Signal", DM_INT, boffset(resetSignal),
  280. "1", /* SIGHUP */
  281. "termSignal", "Signal", DM_INT, boffset(termSignal),
  282. "15", /* SIGTERM */
  283. "resetForAuth", "ResetForAuth", DM_BOOL, boffset(resetForAuth),
  284. "false",
  285. "authorize", "Authorize", DM_BOOL, boffset(authorize),
  286. "true",
  287. "authName", "AuthName", DM_ARGV, boffset(authNames),
  288. DEF_AUTH_NAME,
  289. "authFile", "AuthFile", DM_STRING, boffset(authFile),
  290. "",
  291. #if 0
  292. "gettyLine", "GettyLine", DM_STRING, boffset(gettyLine),
  293. "",
  294. "gettySpeed", "GettySpeed", DM_STRING, boffset(gettySpeed),
  295. "9600",
  296. #endif
  297. /*
  298. * resources which control the session behavior...
  299. */
  300. "resources", "Resources", DM_STRING, boffset(resources),
  301. "",
  302. "xrdb", "Xrdb", DM_STRING, boffset(xrdb),
  303. XRDB_PROGRAM,
  304. "cpp", "Cpp", DM_STRING, boffset(cpp),
  305. CPP_PROGRAM,
  306. "setup", "Setup", DM_STRING, boffset(setup),
  307. "",
  308. "startup", "Startup", DM_STRING, boffset(startup),
  309. "",
  310. "reset", "Reset", DM_STRING, boffset(reset),
  311. "",
  312. "session", "Session", DM_STRING, boffset(session),
  313. DEF_SESSION,
  314. "userPath", "Path", DM_STRING, boffset(userPath),
  315. DEF_USER_PATH,
  316. "systemPath", "Path", DM_STRING, boffset(systemPath),
  317. DEF_SYSTEM_PATH,
  318. "systemShell", "Shell", DM_STRING, boffset(systemShell),
  319. DEF_SYSTEM_SHELL,
  320. "failsafeClient","FailsafeClient", DM_STRING, boffset(failsafeClient),
  321. DEF_FAILSAFE_CLIENT,
  322. "userAuthDir", "UserAuthDir", DM_STRING, boffset(userAuthDir),
  323. DEF_AUTH_DIR,
  324. "chooser", "Chooser", DM_STRING, boffset(chooser),
  325. DEF_CHOOSER,
  326. "language", "Language", DM_STRING, boffset(language),
  327. DEF_LANG,
  328. "languageList", "LanguageList", DM_STRING, boffset(langList),
  329. "",
  330. "environment", "Environment", DM_STRING, boffset(environStr),
  331. DEF_ENV,
  332. "dtlite", "Dtlite", DM_BOOL, boffset(dtlite),
  333. "false",
  334. "xdmMode", "XdmMode", DM_BOOL, boffset(xdmMode),
  335. "false",
  336. "authenticationName","AuthenticationName", DM_STRING, boffset(verifyName),
  337. "",
  338. "pmSearchPath", "PmSearchPath", DM_STRING, boffset(pmSearchPath),
  339. DEF_PM_SEARCH_PATH,
  340. "bmSearchPath", "bmSearchPath", DM_STRING, boffset(bmSearchPath),
  341. DEF_BM_SEARCH_PATH,
  342. };
  343. # define NUM_DISPLAY_RESOURCES (sizeof DisplayResources/sizeof DisplayResources[0])
  344. XrmDatabase DmResourceDB;
  345. int
  346. GetResource( char *name, char *class, int valueType, char **valuep,
  347. char *default_value )
  348. {
  349. char *type;
  350. XrmValue value;
  351. char *string, *new_string;
  352. char empty[] = "";
  353. char str_buf[50];
  354. int len;
  355. if (DmResourceDB && XrmGetResource (DmResourceDB,
  356. name, class,
  357. &type, &value))
  358. {
  359. string = value.addr;
  360. len = value.size;
  361. }
  362. else
  363. {
  364. if(default_value) {
  365. string = default_value;
  366. len = strlen (string);
  367. } else {
  368. string = empty;
  369. len = 0;
  370. }
  371. }
  372. Debug ("%s/%s value %*.*s\n", name, class, len, len, string);
  373. /*
  374. * check if new resource is the same as old...
  375. */
  376. if (valueType == DM_STRING && *valuep) {
  377. if (string != NULL && strlen (*valuep) == len && !strncmp (*valuep, string, len))
  378. return 0;
  379. else {
  380. free (*valuep);
  381. *(valuep) = NULL;
  382. }
  383. }
  384. switch (valueType) {
  385. case DM_STRING:
  386. if ( len > 0 ) {
  387. new_string = malloc ((unsigned) (len+1));
  388. if (!new_string) {
  389. LogOutOfMem(
  390. ReadCatalog(MC_LOG_SET,MC_LOG_GET_RSC,MC_DEF_LOG_GET_RSC));
  391. return 0;
  392. }
  393. strncpy (new_string, string, len);
  394. new_string[len] = '\0';
  395. *(valuep) = new_string;
  396. }
  397. break;
  398. case DM_INT:
  399. strncpy (str_buf, string, sizeof (str_buf));
  400. str_buf[sizeof (str_buf)-1] = '\0';
  401. *((int *) valuep) = atoi (str_buf);
  402. break;
  403. case DM_BOOL:
  404. strncpy (str_buf, string, sizeof (str_buf));
  405. str_buf[sizeof (str_buf)-1] = '\0';
  406. XmuCopyISOLatin1Lowered (str_buf, str_buf);
  407. if (!strcmp (str_buf, "true") ||
  408. !strcmp (str_buf, "on") ||
  409. !strcmp (str_buf, "yes"))
  410. *((int *) valuep) = 1;
  411. else if (!strcmp (str_buf, "false") ||
  412. !strcmp (str_buf, "off") ||
  413. !strcmp (str_buf, "no"))
  414. *((int *) valuep) = 0;
  415. break;
  416. case DM_ARGV:
  417. *((char ***) valuep) = parseArgs ((char **) 0, string);
  418. break;
  419. }
  420. return 1;
  421. }
  422. XrmOptionDescRec configTable [] = {
  423. {"-server", NULL, XrmoptionSkipArg, (caddr_t) NULL },
  424. {"-udpPort", NULL, XrmoptionSkipArg, (caddr_t) NULL },
  425. {"-error", NULL, XrmoptionSkipArg, (caddr_t) NULL },
  426. {"-resources", NULL, XrmoptionSkipArg, (caddr_t) NULL },
  427. {"-session", NULL, XrmoptionSkipArg, (caddr_t) NULL },
  428. {"-debug", NULL, XrmoptionSkipArg, (caddr_t) NULL },
  429. {"-xrm", NULL, XrmoptionSkipArg, (caddr_t) NULL },
  430. {"-config", ".configFile", XrmoptionSepArg, (caddr_t) NULL }
  431. };
  432. XrmOptionDescRec optionTable [] = {
  433. {"-server", ".servers", XrmoptionSepArg, (caddr_t) NULL },
  434. {"-udpPort", ".requestPort", XrmoptionSepArg, (caddr_t) NULL },
  435. {"-error", ".errorLogFile", XrmoptionSepArg, (caddr_t) NULL },
  436. {"-resources", "*resources", XrmoptionSepArg, (caddr_t) NULL },
  437. {"-session", "*session", XrmoptionSepArg, (caddr_t) NULL },
  438. {"-debug", "*debugLevel", XrmoptionSepArg, (caddr_t) NULL },
  439. {"-xrm", NULL, XrmoptionResArg, (caddr_t) NULL },
  440. {"-daemon", ".daemonMode", XrmoptionNoArg, "true" },
  441. {"-nodaemon", ".daemonMode", XrmoptionNoArg, "false" },
  442. {"-quiet", ".quiet", XrmoptionNoArg, "true" }
  443. };
  444. static int originalArgc;
  445. static char **originalArgv;
  446. void
  447. InitResources( int argc, char **argv )
  448. {
  449. XrmInitialize ();
  450. originalArgc = argc;
  451. originalArgv = argv;
  452. ReinitResources ();
  453. }
  454. void
  455. ReinitResources( void )
  456. {
  457. int argc;
  458. char **a;
  459. char **argv;
  460. XrmDatabase newDB;
  461. char * configFileName;
  462. char *type;
  463. XrmValue value;
  464. argv = (char **) malloc ((originalArgc + 1) * sizeof (char *));
  465. if (!argv)
  466. LogOutOfMem(
  467. ReadCatalog(MC_LOG_SET,MC_LOG_NO_SPACE,MC_DEF_LOG_NO_SPACE));
  468. for (argc = 0; argc < originalArgc; argc++)
  469. argv[argc] = originalArgv[argc];
  470. argv[argc] = 0;
  471. if (DmResourceDB)
  472. XrmDestroyDatabase (DmResourceDB);
  473. DmResourceDB = XrmGetStringDatabase ("");
  474. /* pre-parse the command line to get the -config option, if any */
  475. XrmParseCommand (&DmResourceDB, configTable,
  476. sizeof (configTable) / sizeof (configTable[0]),
  477. "Dtlogin", &argc, argv);
  478. configFileName = qualifyWithFirst(DEF_XDM_CONFIG,
  479. CDE_CONFIGURATION_TOP "/config:"
  480. CDE_INSTALLATION_TOP "/config");
  481. GetResource ("Dtlogin.configFile", "Dtlogin.ConfigFile",
  482. DM_STRING, &config, configFileName);
  483. free(configFileName);
  484. newDB = XrmGetFileDatabase ( config );
  485. if (newDB)
  486. {
  487. if (DmResourceDB)
  488. XrmDestroyDatabase (DmResourceDB);
  489. DmResourceDB = newDB;
  490. }
  491. else if (argc != originalArgc)
  492. LogError(
  493. ReadCatalog(MC_LOG_SET,MC_LOG_NO_OPENCFG,MC_DEF_LOG_NO_OPENCFG),
  494. config );
  495. /*
  496. * scan the resource database to set the application name...
  497. */
  498. SetAppName();
  499. XrmParseCommand (&DmResourceDB, optionTable,
  500. sizeof (optionTable) / sizeof (optionTable[0]),
  501. AppName, &argc, argv);
  502. /*
  503. * test to see if the session variable is set.
  504. * for enabling the toggle in the options menu, if it is set..
  505. */
  506. if((XrmGetResource (DmResourceDB, "Dtlogin*session", "Dtlogin*Session", &type, &value)) == True)
  507. session_set = True;
  508. if (argc > 1)
  509. {
  510. LogError(ReadCatalog(MC_LOG_SET,MC_LOG_EXTRA_ARG,MC_DEF_LOG_EXTRA_ARG));
  511. for (a = argv + 1; *a; a++)
  512. LogError ((unsigned char *)" \"%s\"", *a);
  513. LogError ((unsigned char *)"\n");
  514. }
  515. free (argv);
  516. }
  517. void
  518. LoadDMResources( void )
  519. {
  520. int i;
  521. char name[1024], class[1024];
  522. FILE *fp;
  523. if (servers) {free(servers); servers=NULL;}
  524. if (keyFile) {free(keyFile); keyFile=NULL;}
  525. if (accessFile) {free(accessFile); accessFile=NULL;}
  526. for (i = 0; i < NUM_DM_RESOURCES; i++) {
  527. sprintf (name, "%s.%s", AppName, DmResources[i].name);
  528. sprintf (class, "%s.%s", AppName, DmResources[i].class);
  529. GetResource (name, class, DmResources[i].type,
  530. (char **) DmResources[i].dm_value,
  531. DmResources[i].default_value);
  532. }
  533. servers = getFullFileName(servers, 1, NULL);
  534. keyFile = getFullFileName(keyFile, 0, NULL);
  535. accessFile = getFullFileName(accessFile, 0, NULL);
  536. /* set a TZ default */
  537. if (timeZone == NULL || strlen(timeZone) == 0)
  538. {
  539. /*
  540. * dynamically determine the timeZone resource default value...
  541. */
  542. GetSysParms(&timeZone,0,0);
  543. }
  544. }
  545. void
  546. CleanUpName( char *src, char *dst, int len )
  547. {
  548. while (*src) {
  549. if (--len <= 0)
  550. break;
  551. switch (*src)
  552. {
  553. case ':':
  554. case '.':
  555. *dst++ = '_';
  556. break;
  557. default:
  558. *dst++ = *src;
  559. }
  560. ++src;
  561. }
  562. *dst = '\0';
  563. }
  564. void
  565. LoadDisplayResources( struct display *d )
  566. {
  567. int i;
  568. char name[1024], class[1024];
  569. char dpyName[512], dpyClass[512];
  570. char *lang;
  571. Debug("Loading display resources for %s\n", d->name);
  572. if (d->resources) {free(d->resources); d->resources=NULL;}
  573. if (d->setup) {free(d->setup); d->setup=NULL;}
  574. if (d->startup) {free(d->startup); d->startup=NULL;}
  575. if (d->reset) {free(d->reset); d->reset=NULL;}
  576. if (d->session) {free(d->session); d->session=NULL;}
  577. if (d->failsafeClient) {free(d->failsafeClient); d->failsafeClient=NULL;}
  578. CleanUpName (d->name, dpyName, sizeof (dpyName));
  579. CleanUpName (d->class ? d->class : d->name, dpyClass, sizeof (dpyClass));
  580. if((lang = getenv("LANG")) != NULL)
  581. for (i = NUM_DISPLAY_RESOURCES - 1; i >= 0; i--) {
  582. if(strcmp(DisplayResources[i].name,"language") == 0){
  583. DisplayResources[i].default_value = lang;
  584. break;
  585. }
  586. }
  587. lang = d->language;
  588. d->language = NULL;
  589. for (i = 0; i < NUM_DISPLAY_RESOURCES; i++) {
  590. sprintf (name, "%s.%s.%s", AppName,
  591. dpyName, DisplayResources[i].name);
  592. sprintf (class, "%s.%s.%s", AppName,
  593. dpyClass, DisplayResources[i].class);
  594. GetResource (name, class, DisplayResources[i].type,
  595. (char **) (((char *) d) + DisplayResources[i].offset), DisplayResources[i].default_value);
  596. }
  597. if (!strlen(lang) && d->language && strlen(d->language))
  598. *(strncpy(lang, d->language, LANGUAGESIZE) + LANGUAGESIZE) =
  599. '\0';
  600. free(d->language);
  601. d->language = lang;
  602. #ifdef _AIX
  603. if(d->language == NULL || strlen(d->language) == 0)
  604. SetDefaultLanguage(d);
  605. #endif /* _AIX */
  606. d->resources = getFullFileName(d->resources, 2, d->language);
  607. d->setup = getFullFileName(d->setup, 0, NULL);
  608. d->startup = getFullFileName(d->startup, 0, NULL);
  609. d->reset = getFullFileName(d->reset, 0, NULL);
  610. d->session = getFullFileName(d->session, 0, NULL);
  611. d->failsafeClient = getFullFileName(d->failsafeClient, 0, NULL);
  612. }
  613. /***************************************************************************
  614. *
  615. * SetAppName
  616. *
  617. * Probe the resource database to see whether the config file is using
  618. * "Dtlogin" or "DisplayManager" as the application name.
  619. *
  620. * If it cannot be determined, "Dtlogin" is used.
  621. ***************************************************************************/
  622. void
  623. SetAppName( void )
  624. {
  625. int i;
  626. char name[1024], class[1024];
  627. char *type;
  628. XrmValue value;
  629. for (i = 0; i < NUM_DM_RESOURCES; i++) {
  630. /*
  631. * try "Dtlogin" (default) ...
  632. */
  633. sprintf (name, "%s.%s", DTLOGIN, DmResources[i].name);
  634. sprintf (class, "%s.%s", DTLOGIN, DmResources[i].class);
  635. if (DmResourceDB && XrmGetResource (DmResourceDB, name, class,
  636. &type, &value)) {
  637. strcpy(AppName, DTLOGIN);
  638. break;
  639. }
  640. /*
  641. * try "DisplayManager" ...
  642. */
  643. sprintf (name, "%s.%s", DISPLAYMANAGER, DmResources[i].name);
  644. sprintf (class, "%s.%s", DISPLAYMANAGER, DmResources[i].class);
  645. if (DmResourceDB && XrmGetResource (DmResourceDB, name, class,
  646. &type, &value)) {
  647. strcpy(AppName, DISPLAYMANAGER);
  648. break;
  649. }
  650. }
  651. }
  652. /***************************************************************************
  653. *
  654. * getFullFileName
  655. *
  656. * Try to produce a fully qualified file name by prepending
  657. * /etc/dt/config or /usr/dt/config to a resource file name.
  658. * There are 2 special cases: servers - which can be a command, and
  659. * resources - which can an imbeded %L.
  660. ***************************************************************************/
  661. extern char *_ExpandLang( char *string, char *lang );
  662. static char *
  663. getFullFileName(char *name, int special, char *lang)
  664. {
  665. char * newname;
  666. if (name == NULL)
  667. return(NULL);
  668. /** if the file already starts with a '/' **/
  669. /** then just return a copy of it **/
  670. if (name[0] == '/') {
  671. if ((newname = (char *)malloc((strlen(name)+1)*sizeof(char))) == NULL) {
  672. return (NULL);
  673. } else {
  674. strcpy(newname, name);
  675. return(newname);
  676. }
  677. }
  678. switch (special) {
  679. /*********************/
  680. case 0: /** no special case **/
  681. /*********************/
  682. newname = qualifyWithFirst(name,
  683. CDE_CONFIGURATION_TOP "/config:"
  684. CDE_INSTALLATION_TOP "/config");
  685. return (newname);
  686. /***************************************/
  687. case 1: /** special handling for servers file **/
  688. /***************************************/
  689. if (strchr(name, ':') != NULL) {
  690. /** This is probably a command and not a file name **/
  691. /** so just return a copy of it. **/
  692. if ((newname = (char *)malloc((strlen(name)+1)*sizeof(char)))
  693. == NULL) {
  694. return (NULL);
  695. } else {
  696. strcpy(newname, name);
  697. return(newname);
  698. }
  699. } else {
  700. newname = qualifyWithFirst(name,
  701. CDE_CONFIGURATION_TOP "/config:"
  702. CDE_INSTALLATION_TOP "/config");
  703. return (newname);
  704. }
  705. /********************************************/
  706. case 2: /** special handling for d->resources file **/
  707. /********************************************/
  708. if (strchr(name, '%') == NULL) {
  709. /** no special processing needed **/
  710. newname = qualifyWithFirst(name,
  711. CDE_CONFIGURATION_TOP "/config:"
  712. CDE_INSTALLATION_TOP "/config");
  713. return (newname);
  714. } else {
  715. char *langString;
  716. char *tempName;
  717. int tempLen;
  718. /** need to remember the %L **/
  719. if (lang == NULL)
  720. lang = "C";
  721. langString = _ExpandLang(name, lang);
  722. if ( (tempName = qualifyWithFirst(langString,
  723. CDE_CONFIGURATION_TOP "/config:"
  724. CDE_INSTALLATION_TOP "/config") )
  725. == NULL) {
  726. free(langString);
  727. langString = _ExpandLang(name, "C");
  728. if ( (tempName = qualifyWithFirst(langString,
  729. CDE_CONFIGURATION_TOP "/config:"
  730. CDE_INSTALLATION_TOP "/config") )
  731. == NULL) {
  732. free(langString);
  733. return(NULL);
  734. }
  735. }
  736. /** We have a fully qualified and expanded file name **/
  737. /** but we need to return a fully qualified but NOT **/
  738. /** expanded file name. **/
  739. tempLen = strlen(tempName) - strlen(langString)
  740. + strlen(name) + 1;
  741. if ((newname = (char *)malloc(tempLen * sizeof(char))) == NULL){
  742. free(langString);
  743. return(tempName);
  744. } else {
  745. tempLen = strlen(tempName) - strlen(langString);
  746. strncpy(newname, tempName, tempLen);
  747. strcpy(newname+tempLen, name);
  748. free (langString);
  749. free (tempName);
  750. return(newname);
  751. }
  752. }
  753. default:
  754. /* special is of an unknown value */
  755. return(NULL);
  756. }
  757. }