2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
23 /* $TOG: resource.c /main/7 1997/03/14 13:45:09 barstow $ */
24 /* (c) Copyright 1997 The Open Group */
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. *
32 * xdm - display manager daemon
34 * Copyright 1988 Massachusetts Institute of Technology
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.
46 * Author: Keith Packard, MIT X Consortium
55 # include <X11/Xresource.h>
56 # include <X11/Xmu/CharSet.h>
60 void CleanUpName( char *src, char *dst, int len) ;
61 static char * getFullFileName(char *name, int special, char * lang);
62 extern char * qualifyWithFirst(char *, char *);
64 /* XtOffset() hack for ibmrt BandAidCompiler */
66 int session_set = False;
83 char **exportList; /* List of all export env vars */
90 #ifdef DEF_NETWORK_DEV
95 * Dtlogin will accept both Dtlogin and XDM resources. The string variable
96 * "AppName" contains the proper application name to use in looking up
100 # define DISPLAYMANAGER "DisplayManager"
101 # define DTLOGIN "Dtlogin"
103 static char AppName[16] = DTLOGIN;
112 # define DEF_XDM_CONFIG CDE_INSTALLATION_TOP "/lib/X11/Dtlogin/Xconfig"
113 # define DEF_AUTH_DIR CDE_INSTALLATION_TOP "/lib/X11/Dtlogin"
114 # define DEF_KEY_FILE CDE_INSTALLATION_TOP "/lib/X11/Dtlogin/Xkeys"
119 * the following constants are supposed to be set in the makefile from
120 * parameters set util/imake.includes/site.def (or *.macros in that directory
121 * if it is server-specific). DO NOT CHANGE THESE DEFINITIONS!
123 #ifndef DEF_SERVER_LINE
125 #define DEF_SERVER_LINE ":0 local /usr/openwin/bin/X :0"
127 #define DEF_SERVER_LINE ":0 local /usr/bin/X11/X :0"
132 #define XRDB_PROGRAM "/usr/openwin/bin/xrdb"
134 #define XRDB_PROGRAM "/usr/bin/X11/xrdb"
138 #define DEF_SESSION CDE_INSTALLATION_TOP "/bin/Xsession"
141 #ifndef DEF_USER_PATH
143 # define DEF_USER_PATH "/usr/openwin/bin:/bin:/usr/bin:/usr/contrib/bin:/usr/local/bin:."
145 # define DEF_USER_PATH "/usr/bin/X11:/bin:/usr/bin:/usr/contrib/bin:/usr/local/bin"
149 #ifndef DEF_SYSTEM_PATH
151 # define DEF_SYSTEM_PATH "/usr/openwin/bin:/etc:/bin:/usr/bin"
153 # define DEF_SYSTEM_PATH "/usr/bin/X11:/etc:/bin:/usr/bin"
157 #ifndef DEF_SYSTEM_SHELL
158 #define DEF_SYSTEM_SHELL "/bin/sh"
161 #ifndef DEF_FAILSAFE_CLIENT
163 #define DEF_FAILSAFE_CLIENT "/usr/openwin/bin/xterm"
165 #define DEF_FAILSAFE_CLIENT "/usr/bin/X11/xterm"
169 #ifndef DEF_XDM_CONFIG
170 #define DEF_XDM_CONFIG "Xconfig"
174 #define DEF_CHOOSER CDE_INSTALLATION_TOP "/bin/chooser"
178 #define CPP_PROGRAM "/lib/cpp"
180 #ifndef DEF_XDM_AUTH_GEN
181 #define DEF_XDM_AUTH_GEN CDE_CONFIGURATION_TOP "/xdmauthgen"
183 #ifndef DEF_AUTH_NAME
184 #define DEF_AUTH_NAME "MIT-MAGIC-COOKIE-1"
187 #define DEF_AUTH_DIR CDE_CONFIGURATION_TOP
189 #ifndef DEF_USER_AUTH_DIR
190 #define DEF_USER_AUTH_DIR "/tmp"
193 #define DEF_KEY_FILE CDE_CONFIGURATION_TOP "/Xkeys"
195 #ifndef DEF_ACCESS_FILE
196 #define DEF_ACCESS_FILE ""
199 #define DEF_TIMEZONE "MST7MDT"
201 #ifndef DEF_SYS_PARMS_FILE
202 # if defined( __hpux )
203 # define DEF_SYS_PARMS_FILE "/etc/src.sh"
205 # define DEF_SYS_PARMS_FILE "/etc/TIMEZONE"
208 #define DEF_UDP_PORT "177" /* registered XDMCP port, don't change */
211 # ifdef sun /* need to set the environment for Sun OpenWindows */
212 # define DEF_ENV "OPENWINHOME=/usr/openwin"
218 #ifndef DEF_LANG /* LANG default settings for various architectures */
220 # define DEF_LANG "C"
222 # ifdef sun /* default language under Solaris */
223 # define DEF_LANG "C"
227 #ifndef DEF_LANG /* set LANG to NULL if not already defined */
237 "servers", "Servers", DM_STRING, &servers,
239 "requestPort", "RequestPort", DM_INT, (char **) &request_port,
241 "debugLevel", "DebugLevel", DM_INT, (char **) &debugLevel,
243 "errorLogFile", "ErrorLogFile", DM_STRING, &errorLogFile,
245 "errorLogSize", "ErrorLogSize", DM_INT, (char **) &errorLogSize,
247 "daemonMode", "DaemonMode", DM_BOOL, (char **) &daemonMode,
249 "quiet", "quiet", DM_BOOL, (char **) &quiet,
251 "pidFile", "PidFile", DM_STRING, &pidFile,
253 "lockPidFile", "LockPidFile", DM_BOOL, (char **) &lockPidFile,
255 "authDir", "AuthDir", DM_STRING, &authDir,
257 "autoRescan", "AutoRescan", DM_BOOL, (char **) &autoRescan,
259 "removeDomainname","RemoveDomainname",DM_BOOL, (char **) &removeDomainname,
261 "keyFile", "KeyFile", DM_STRING, &keyFile,
263 "accessFile", "AccessFile", DM_STRING, &accessFile,
265 /* exportList env var resource RK 08.17.93 */
266 "exportList", "ExportList", DM_ARGV, (char **) &exportList,
268 "timeZone", "TimeZone", DM_STRING, &timeZone,
270 "fontPathHead", "FontPathHead", DM_STRING, &fpHead,
272 "fontPathTail", "FontPathTail", DM_STRING, &fpTail,
274 "sysParmsFile", "SysParmsFile", DM_STRING, &sysParmsFile,
276 "wakeupInterval","WakeupInterval",DM_INT, (char **) &wakeupInterval,
278 "langListTimeout","langListTimeout",DM_INT, (char **) &langListTimeout,
280 #ifdef DEF_NETWORK_DEV
281 "networkDevice","NetworkDevice",DM_STRING, &networkDev,
286 # define NUM_DM_RESOURCES (sizeof DmResources / sizeof DmResources[0])
288 # define boffset(f) ((char *) &(((struct display *) 0)->f) - (char *) 0)
290 struct displayResources {
295 } DisplayResources[] = {
299 * resources for managing the server...
302 "serverAttempts","ServerAttempts", DM_INT, boffset(serverAttempts),
304 "openDelay", "OpenDelay", DM_INT, boffset(openDelay),
306 "openRepeat", "OpenRepeat", DM_INT, boffset(openRepeat),
308 "openTimeout", "OpenTimeout", DM_INT, boffset(openTimeout),
310 "startAttempts","StartAttempts",DM_INT, boffset(startAttempts),
312 "pingInterval", "PingInterval", DM_INT, boffset(pingInterval),
314 "pingTimeout", "PingTimeout", DM_INT, boffset(pingTimeout),
316 "terminateServer","TerminateServer",DM_BOOL, boffset(terminateServer),
318 "grabServer", "GrabServer", DM_BOOL, boffset(grabServer),
320 "grabTimeout", "GrabTimeout", DM_INT, boffset(grabTimeout),
322 "resetSignal", "Signal", DM_INT, boffset(resetSignal),
324 "termSignal", "Signal", DM_INT, boffset(termSignal),
326 "resetForAuth", "ResetForAuth", DM_BOOL, boffset(resetForAuth),
328 "authorize", "Authorize", DM_BOOL, boffset(authorize),
330 "authName", "AuthName", DM_ARGV, boffset(authNames),
332 "authFile", "AuthFile", DM_STRING, boffset(authFile),
335 "gettyLine", "GettyLine", DM_STRING, boffset(gettyLine),
337 "gettySpeed", "GettySpeed", DM_STRING, boffset(gettySpeed),
341 * resources which control the session behavior...
344 "resources", "Resources", DM_STRING, boffset(resources),
346 "xrdb", "Xrdb", DM_STRING, boffset(xrdb),
348 "cpp", "Cpp", DM_STRING, boffset(cpp),
350 "setup", "Setup", DM_STRING, boffset(setup),
352 "startup", "Startup", DM_STRING, boffset(startup),
354 "reset", "Reset", DM_STRING, boffset(reset),
356 "session", "Session", DM_STRING, boffset(session),
358 "userPath", "Path", DM_STRING, boffset(userPath),
360 "systemPath", "Path", DM_STRING, boffset(systemPath),
362 "systemShell", "Shell", DM_STRING, boffset(systemShell),
364 "failsafeClient","FailsafeClient", DM_STRING, boffset(failsafeClient),
366 "userAuthDir", "UserAuthDir", DM_STRING, boffset(userAuthDir),
368 "chooser", "Chooser", DM_STRING, boffset(chooser),
370 "language", "Language", DM_STRING, boffset(language),
372 "languageList", "LanguageList", DM_STRING, boffset(langList),
374 "environment", "Environment", DM_STRING, boffset(environStr),
376 "dtlite", "Dtlite", DM_BOOL, boffset(dtlite),
378 "xdmMode", "XdmMode", DM_BOOL, boffset(xdmMode),
380 "authenticationName","AuthenticationName", DM_STRING, boffset(verifyName),
382 "pmSearchPath", "PmSearchPath", DM_STRING, boffset(pmSearchPath),
384 "bmSearchPath", "bmSearchPath", DM_STRING, boffset(bmSearchPath),
388 # define NUM_DISPLAY_RESOURCES (sizeof DisplayResources/sizeof DisplayResources[0])
390 XrmDatabase DmResourceDB;
393 GetResource( char *name, char *class, int valueType, char **valuep,
394 char *default_value )
398 char *string, *new_string;
404 if (DmResourceDB && XrmGetResource (DmResourceDB,
414 string = default_value;
415 len = strlen (string);
422 Debug ("%s/%s value %*.*s\n", name, class, len, len, string);
426 * check if new resource is the same as old...
429 if (valueType == DM_STRING && *valuep) {
430 if (string != NULL && strlen (*valuep) == len && !strncmp (*valuep, string, len))
442 new_string = malloc ((unsigned) (len+1));
445 ReadCatalog(MC_LOG_SET,MC_LOG_GET_RSC,MC_DEF_LOG_GET_RSC));
448 strncpy (new_string, string, len);
449 new_string[len] = '\0';
450 *(valuep) = new_string;
454 strncpy (str_buf, string, sizeof (str_buf));
455 str_buf[sizeof (str_buf)-1] = '\0';
456 *((int *) valuep) = atoi (str_buf);
459 strncpy (str_buf, string, sizeof (str_buf));
460 str_buf[sizeof (str_buf)-1] = '\0';
461 XmuCopyISOLatin1Lowered (str_buf, str_buf);
462 if (!strcmp (str_buf, "true") ||
463 !strcmp (str_buf, "on") ||
464 !strcmp (str_buf, "yes"))
465 *((int *) valuep) = 1;
466 else if (!strcmp (str_buf, "false") ||
467 !strcmp (str_buf, "off") ||
468 !strcmp (str_buf, "no"))
469 *((int *) valuep) = 0;
472 *((char ***) valuep) = parseArgs ((char **) 0, string);
480 XrmOptionDescRec configTable [] = {
481 {"-server", NULL, XrmoptionSkipArg, (caddr_t) NULL },
482 {"-udpPort", NULL, XrmoptionSkipArg, (caddr_t) NULL },
483 {"-error", NULL, XrmoptionSkipArg, (caddr_t) NULL },
484 {"-resources", NULL, XrmoptionSkipArg, (caddr_t) NULL },
485 {"-session", NULL, XrmoptionSkipArg, (caddr_t) NULL },
486 {"-debug", NULL, XrmoptionSkipArg, (caddr_t) NULL },
487 {"-xrm", NULL, XrmoptionSkipArg, (caddr_t) NULL },
488 {"-config", ".configFile", XrmoptionSepArg, (caddr_t) NULL }
491 XrmOptionDescRec optionTable [] = {
492 {"-server", ".servers", XrmoptionSepArg, (caddr_t) NULL },
493 {"-udpPort", ".requestPort", XrmoptionSepArg, (caddr_t) NULL },
494 {"-error", ".errorLogFile", XrmoptionSepArg, (caddr_t) NULL },
495 {"-resources", "*resources", XrmoptionSepArg, (caddr_t) NULL },
496 {"-session", "*session", XrmoptionSepArg, (caddr_t) NULL },
497 {"-debug", "*debugLevel", XrmoptionSepArg, (caddr_t) NULL },
498 {"-xrm", NULL, XrmoptionResArg, (caddr_t) NULL },
499 {"-daemon", ".daemonMode", XrmoptionNoArg, "true" },
500 {"-nodaemon", ".daemonMode", XrmoptionNoArg, "false" },
501 {"-quiet", ".quiet", XrmoptionNoArg, "true" }
504 static int originalArgc;
505 static char **originalArgv;
508 InitResources( int argc, char **argv )
517 ReinitResources( void )
523 char * configFileName;
527 argv = (char **) malloc ((originalArgc + 1) * sizeof (char *));
530 ReadCatalog(MC_LOG_SET,MC_LOG_NO_SPACE,MC_DEF_LOG_NO_SPACE));
531 for (argc = 0; argc < originalArgc; argc++)
532 argv[argc] = originalArgv[argc];
535 XrmDestroyDatabase (DmResourceDB);
536 DmResourceDB = XrmGetStringDatabase ("");
537 /* pre-parse the command line to get the -config option, if any */
538 XrmParseCommand (&DmResourceDB, configTable,
539 sizeof (configTable) / sizeof (configTable[0]),
540 "Dtlogin", &argc, argv);
542 configFileName = qualifyWithFirst(DEF_XDM_CONFIG,
543 CDE_CONFIGURATION_TOP "/config:"
544 CDE_INSTALLATION_TOP "/config");
546 GetResource ("Dtlogin.configFile", "Dtlogin.ConfigFile",
547 DM_STRING, &config, configFileName);
549 free(configFileName);
553 newDB = XrmGetFileDatabase ( config );
558 XrmDestroyDatabase (DmResourceDB);
559 DmResourceDB = newDB;
561 else if (argc != originalArgc)
563 ReadCatalog(MC_LOG_SET,MC_LOG_NO_OPENCFG,MC_DEF_LOG_NO_OPENCFG),
569 * scan the resource database to set the application name...
573 XrmParseCommand (&DmResourceDB, optionTable,
574 sizeof (optionTable) / sizeof (optionTable[0]),
575 AppName, &argc, argv);
578 * test to see if the session variable is set.
579 * for enabling the toggle in the options menu, if it is set..
581 if((XrmGetResource (DmResourceDB, "Dtlogin*session", "Dtlogin*Session", &type, &value)) == True)
586 LogError(ReadCatalog(MC_LOG_SET,MC_LOG_EXTRA_ARG,MC_DEF_LOG_EXTRA_ARG));
587 for (a = argv + 1; *a; a++)
588 LogError ((unsigned char *)" \"%s\"", *a);
589 LogError ((unsigned char *)"\n");
595 LoadDMResources( void )
598 char name[1024], class[1024];
601 if (servers) {free(servers); servers=NULL;}
602 if (keyFile) {free(keyFile); keyFile=NULL;}
603 if (accessFile) {free(accessFile); accessFile=NULL;}
605 for (i = 0; i < NUM_DM_RESOURCES; i++) {
606 sprintf (name, "%s.%s", AppName, DmResources[i].name);
607 sprintf (class, "%s.%s", AppName, DmResources[i].class);
608 GetResource (name, class, DmResources[i].type,
609 (char **) DmResources[i].dm_value,
610 DmResources[i].default_value);
613 servers = getFullFileName(servers, 1, NULL);
614 keyFile = getFullFileName(keyFile, 0, NULL);
615 accessFile = getFullFileName(accessFile, 0, NULL);
617 #ifndef __apollo /* set a TZ default for all OS except Domain */
618 if (timeZone == NULL || strlen(timeZone) == 0)
621 * dynamically determine the timeZone resource default value...
623 GetSysParms(&timeZone,0,0);
630 CleanUpName( char *src, char *dst, int len )
650 LoadDisplayResources( struct display *d )
653 char name[1024], class[1024];
654 char dpyName[512], dpyClass[512];
657 Debug("Loading display resources for %s\n", d->name);
659 if (d->resources) {free(d->resources); d->resources=NULL;}
660 if (d->setup) {free(d->setup); d->setup=NULL;}
661 if (d->startup) {free(d->startup); d->startup=NULL;}
662 if (d->reset) {free(d->reset); d->reset=NULL;}
663 if (d->session) {free(d->session); d->session=NULL;}
664 if (d->failsafeClient) {free(d->failsafeClient); d->failsafeClient=NULL;}
666 CleanUpName (d->name, dpyName, sizeof (dpyName));
667 CleanUpName (d->class ? d->class : d->name, dpyClass, sizeof (dpyClass));
669 if((lang = getenv("LANG")) != NULL)
670 for (i = NUM_DISPLAY_RESOURCES - 1; i >= 0; i--) {
671 if(strcmp(DisplayResources[i].name,"language") == 0){
672 DisplayResources[i].default_value = lang;
678 for (i = 0; i < NUM_DISPLAY_RESOURCES; i++) {
679 sprintf (name, "%s.%s.%s", AppName,
680 dpyName, DisplayResources[i].name);
681 sprintf (class, "%s.%s.%s", AppName,
682 dpyClass, DisplayResources[i].class);
683 GetResource (name, class, DisplayResources[i].type,
684 (char **) (((char *) d) + DisplayResources[i].offset), DisplayResources[i].default_value);
688 if(d->language == NULL || strlen(d->language) == 0)
689 SetDefaultLanguage(d);
692 d->resources = getFullFileName(d->resources, 2, d->language);
693 d->setup = getFullFileName(d->setup, 0, NULL);
694 d->startup = getFullFileName(d->startup, 0, NULL);
695 d->reset = getFullFileName(d->reset, 0, NULL);
696 d->session = getFullFileName(d->session, 0, NULL);
697 d->failsafeClient = getFullFileName(d->failsafeClient, 0, NULL);
703 /***************************************************************************
707 * Probe the resource database to see whether the config file is using
708 * "Dtlogin" or "DisplayManager" as the application name.
710 * If it cannot be determined, "Dtlogin" is used.
711 ***************************************************************************/
717 char name[1024], class[1024];
721 for (i = 0; i < NUM_DM_RESOURCES; i++) {
724 * try "Dtlogin" (default) ...
727 sprintf (name, "%s.%s", DTLOGIN, DmResources[i].name);
728 sprintf (class, "%s.%s", DTLOGIN, DmResources[i].class);
730 if (DmResourceDB && XrmGetResource (DmResourceDB, name, class,
733 strcpy(AppName, DTLOGIN);
739 * try "DisplayManager" ...
742 sprintf (name, "%s.%s", DISPLAYMANAGER, DmResources[i].name);
743 sprintf (class, "%s.%s", DISPLAYMANAGER, DmResources[i].class);
745 if (DmResourceDB && XrmGetResource (DmResourceDB, name, class,
748 strcpy(AppName, DISPLAYMANAGER);
756 /***************************************************************************
760 * Try to produce a fully qualified file name by prepending
761 * /etc/dt/config or /usr/dt/config to a resource file name.
762 * There are 2 special cases: servers - which can be a command, and
763 * resources - which can an imbeded %L.
764 ***************************************************************************/
765 extern char *_ExpandLang( char *string, char *lang );
768 getFullFileName(char *name, int special, char *lang)
776 /** if the file already starts with a '/' **/
777 /** then just return a copy of it **/
778 if (name[0] == '/') {
779 if ((newname = (char *)malloc((strlen(name)+1)*sizeof(char))) == NULL) {
782 strcpy(newname, name);
788 /*********************/
789 case 0: /** no special case **/
790 /*********************/
791 newname = qualifyWithFirst(name,
792 CDE_CONFIGURATION_TOP "/config:"
793 CDE_INSTALLATION_TOP "/config");
796 /***************************************/
797 case 1: /** special handling for servers file **/
798 /***************************************/
799 if (strchr(name, ':') != NULL) {
800 /** This is probably a command and not a file name **/
801 /** so just return a copy of it. **/
802 if ((newname = (char *)malloc((strlen(name)+1)*sizeof(char)))
806 strcpy(newname, name);
810 newname = qualifyWithFirst(name,
811 CDE_CONFIGURATION_TOP "/config:"
812 CDE_INSTALLATION_TOP "/config");
816 /********************************************/
817 case 2: /** special handling for d->resources file **/
818 /********************************************/
819 if (strchr(name, '%') == NULL) {
820 /** no special processing needed **/
821 newname = qualifyWithFirst(name,
822 CDE_CONFIGURATION_TOP "/config:"
823 CDE_INSTALLATION_TOP "/config");
830 /** need to remember the %L **/
833 langString = _ExpandLang(name, lang);
834 if ( (tempName = qualifyWithFirst(langString,
835 CDE_CONFIGURATION_TOP "/config:"
836 CDE_INSTALLATION_TOP "/config") )
839 langString = _ExpandLang(name, "C");
840 if ( (tempName = qualifyWithFirst(langString,
841 CDE_CONFIGURATION_TOP "/config:"
842 CDE_INSTALLATION_TOP "/config") )
848 /** We have a fully qualified and expanded file name **/
849 /** but we need to return a fully qualified but NOT **/
850 /** expanded file name. **/
851 tempLen = strlen(tempName) - strlen(langString)
853 if ((newname = (char *)malloc(tempLen * sizeof(char))) == NULL){
857 tempLen = strlen(tempName) - strlen(langString);
858 strncpy(newname, tempName, tempLen);
859 strcpy(newname+tempLen, name);
867 /* special is of an unknown value */