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 librararies 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;
82 char **exportList; /* List of all export env vars */
89 #ifdef DEF_NETWORK_DEV
97 * Dtlogin will accept both Dtlogin and XDM resources. The string variable
98 * "AppName" contains the proper application name to use in looking up
102 # define DISPLAYMANAGER "DisplayManager"
103 # define DTLOGIN "Dtlogin"
105 static char AppName[16] = DTLOGIN;
114 # define DEF_XDM_CONFIG CDE_INSTALLATION_TOP "/lib/X11/Dtlogin/Xconfig"
115 # define DEF_AUTH_DIR CDE_INSTALLATION_TOP "/lib/X11/Dtlogin"
116 # define DEF_KEY_FILE CDE_INSTALLATION_TOP "/lib/X11/Dtlogin/Xkeys"
121 * the following constants are supposed to be set in the makefile from
122 * parameters set util/imake.includes/site.def (or *.macros in that directory
123 * if it is server-specific). DO NOT CHANGE THESE DEFINITIONS!
125 #ifndef DEF_SERVER_LINE
127 #define DEF_SERVER_LINE ":0 local /usr/openwin/bin/X :0"
129 #define DEF_SERVER_LINE ":0 local /usr/bin/X11/X :0"
134 #define XRDB_PROGRAM "/usr/openwin/bin/xrdb"
136 #define XRDB_PROGRAM "/usr/bin/X11/xrdb"
140 #define DEF_SESSION CDE_INSTALLATION_TOP "/bin/Xsession"
143 #ifndef DEF_USER_PATH
145 # define DEF_USER_PATH "/usr/openwin/bin:/bin:/usr/bin:/usr/contrib/bin:/usr/local/bin:."
147 # define DEF_USER_PATH "/usr/bin/X11:/bin:/usr/bin:/usr/contrib/bin:/usr/local/bin"
151 #ifndef DEF_SYSTEM_PATH
153 # define DEF_SYSTEM_PATH "/usr/openwin/bin:/etc:/bin:/usr/bin"
155 # define DEF_SYSTEM_PATH "/usr/bin/X11:/etc:/bin:/usr/bin"
159 #ifndef DEF_SYSTEM_SHELL
160 #define DEF_SYSTEM_SHELL "/bin/sh"
163 #ifndef DEF_FAILSAFE_CLIENT
165 #define DEF_FAILSAFE_CLIENT "/usr/openwin/bin/xterm"
167 #define DEF_FAILSAFE_CLIENT "/usr/bin/X11/xterm"
171 #ifndef DEF_XDM_CONFIG
172 #define DEF_XDM_CONFIG "Xconfig"
176 #define DEF_CHOOSER CDE_INSTALLATION_TOP "/bin/chooser"
180 #define CPP_PROGRAM "/lib/cpp"
182 #ifndef DEF_XDM_AUTH_GEN
183 #define DEF_XDM_AUTH_GEN CDE_CONFIGURATION_TOP "/xdmauthgen"
185 #ifndef DEF_AUTH_NAME
186 #define DEF_AUTH_NAME "MIT-MAGIC-COOKIE-1"
189 #define DEF_AUTH_DIR CDE_CONFIGURATION_TOP
191 #ifndef DEF_USER_AUTH_DIR
192 #define DEF_USER_AUTH_DIR "/tmp"
195 #define DEF_KEY_FILE CDE_CONFIGURATION_TOP "/Xkeys"
197 #ifndef DEF_ACCESS_FILE
198 #define DEF_ACCESS_FILE ""
201 #define DEF_TIMEZONE "MST7MDT"
203 #ifndef DEF_SYS_PARMS_FILE
204 # if defined( __hpux )
205 # define DEF_SYS_PARMS_FILE "/etc/src.sh"
207 # define DEF_SYS_PARMS_FILE "/etc/TIMEZONE"
210 #define DEF_UDP_PORT "177" /* registered XDMCP port, don't change */
213 # ifdef sun /* need to set the environment for Sun OpenWindows */
214 # define DEF_ENV "OPENWINHOME=/usr/openwin"
220 #ifndef DEF_LANG /* LANG default settings for various architectures */
222 # define DEF_LANG "C"
225 # define DEF_LANG "C"
228 # define DEF_LANG "en_US.88591"
230 # ifdef sun /* default language under Solaris */
231 # define DEF_LANG "C"
235 #ifndef DEF_LANG /* set LANG to NULL if not already defined */
245 "servers", "Servers", DM_STRING, &servers,
247 "requestPort", "RequestPort", DM_INT, (char **) &request_port,
249 "debugLevel", "DebugLevel", DM_INT, (char **) &debugLevel,
251 "errorLogFile", "ErrorLogFile", DM_STRING, &errorLogFile,
253 "errorLogSize", "ErrorLogSize", DM_INT, (char **) &errorLogSize,
255 "daemonMode", "DaemonMode", DM_BOOL, (char **) &daemonMode,
257 "pidFile", "PidFile", DM_STRING, &pidFile,
259 "lockPidFile", "LockPidFile", DM_BOOL, (char **) &lockPidFile,
261 "authDir", "AuthDir", DM_STRING, &authDir,
263 "autoRescan", "AutoRescan", DM_BOOL, (char **) &autoRescan,
265 "removeDomainname","RemoveDomainname",DM_BOOL, (char **) &removeDomainname,
267 "keyFile", "KeyFile", DM_STRING, &keyFile,
269 "accessFile", "AccessFile", DM_STRING, &accessFile,
271 /* exportList env var resource RK 08.17.93 */
272 "exportList", "ExportList", DM_ARGV, (char **) &exportList,
274 "timeZone", "TimeZone", DM_STRING, &timeZone,
276 "fontPathHead", "FontPathHead", DM_STRING, &fpHead,
278 "fontPathTail", "FontPathTail", DM_STRING, &fpTail,
280 "sysParmsFile", "SysParmsFile", DM_STRING, &sysParmsFile,
282 "wakeupInterval","WakeupInterval",DM_INT, (char **) &wakeupInterval,
284 "langListTimeout","langListTimeout",DM_INT, (char **) &langListTimeout,
286 #ifdef DEF_NETWORK_DEV
287 "networkDevice","NetworkDevice",DM_STRING, &networkDev,
291 "ignoreLocales", "IgnoreLocales", DM_STRING, &ignoreLocales,
296 # define NUM_DM_RESOURCES (sizeof DmResources / sizeof DmResources[0])
298 # define boffset(f) ((char *) &(((struct display *) 0)->f) - (char *) 0)
300 struct displayResources {
305 } DisplayResources[] = {
309 * resources for managing the server...
312 "serverAttempts","ServerAttempts", DM_INT, boffset(serverAttempts),
314 "openDelay", "OpenDelay", DM_INT, boffset(openDelay),
316 "openRepeat", "OpenRepeat", DM_INT, boffset(openRepeat),
318 "openTimeout", "OpenTimeout", DM_INT, boffset(openTimeout),
320 "startAttempts","StartAttempts",DM_INT, boffset(startAttempts),
322 "pingInterval", "PingInterval", DM_INT, boffset(pingInterval),
324 "pingTimeout", "PingTimeout", DM_INT, boffset(pingTimeout),
326 "terminateServer","TerminateServer",DM_BOOL, boffset(terminateServer),
328 "grabServer", "GrabServer", DM_BOOL, boffset(grabServer),
330 "grabTimeout", "GrabTimeout", DM_INT, boffset(grabTimeout),
332 "resetSignal", "Signal", DM_INT, boffset(resetSignal),
334 "termSignal", "Signal", DM_INT, boffset(termSignal),
336 "resetForAuth", "ResetForAuth", DM_BOOL, boffset(resetForAuth),
338 "authorize", "Authorize", DM_BOOL, boffset(authorize),
340 "authName", "AuthName", DM_ARGV, boffset(authNames),
342 "authFile", "AuthFile", DM_STRING, boffset(authFile),
345 "gettyLine", "GettyLine", DM_STRING, boffset(gettyLine),
347 "gettySpeed", "GettySpeed", DM_STRING, boffset(gettySpeed),
351 * resources which control the session behavior...
354 "resources", "Resources", DM_STRING, boffset(resources),
356 "xrdb", "Xrdb", DM_STRING, boffset(xrdb),
358 "cpp", "Cpp", DM_STRING, boffset(cpp),
360 "setup", "Setup", DM_STRING, boffset(setup),
362 "startup", "Startup", DM_STRING, boffset(startup),
364 "reset", "Reset", DM_STRING, boffset(reset),
366 "session", "Session", DM_STRING, boffset(session),
368 "userPath", "Path", DM_STRING, boffset(userPath),
370 "systemPath", "Path", DM_STRING, boffset(systemPath),
372 "systemShell", "Shell", DM_STRING, boffset(systemShell),
374 "failsafeClient","FailsafeClient", DM_STRING, boffset(failsafeClient),
376 "userAuthDir", "UserAuthDir", DM_STRING, boffset(userAuthDir),
378 "chooser", "Chooser", DM_STRING, boffset(chooser),
380 "language", "Language", DM_STRING, boffset(language),
382 "languageList", "LanguageList", DM_STRING, boffset(langList),
384 "environment", "Environment", DM_STRING, boffset(environStr),
386 "dtlite", "Dtlite", DM_BOOL, boffset(dtlite),
388 "xdmMode", "XdmMode", DM_BOOL, boffset(xdmMode),
390 "authenticationName","AuthenticationName", DM_STRING, boffset(verifyName),
392 "pmSearchPath", "PmSearchPath", DM_STRING, boffset(pmSearchPath),
394 "bmSearchPath", "bmSearchPath", DM_STRING, boffset(bmSearchPath),
398 # define NUM_DISPLAY_RESOURCES (sizeof DisplayResources/sizeof DisplayResources[0])
400 XrmDatabase DmResourceDB;
403 GetResource( char *name, char *class, int valueType, char **valuep,
404 char *default_value )
408 char *string, *new_string;
413 if (DmResourceDB && XrmGetResource (DmResourceDB,
422 string = default_value;
423 len = (string == NULL ? 0 : strlen (string));
426 Debug ("%s/%s value %*.*s\n", name, class, len, len, string);
430 * check if new resource is the same as old...
433 if (valueType == DM_STRING && *valuep) {
434 if (string != NULL && strlen (*valuep) == len && !strncmp (*valuep, string, len))
446 new_string = malloc ((unsigned) (len+1));
449 ReadCatalog(MC_LOG_SET,MC_LOG_GET_RSC,MC_DEF_LOG_GET_RSC));
452 strncpy (new_string, string, len);
453 new_string[len] = '\0';
454 *(valuep) = new_string;
458 strncpy (str_buf, string, sizeof (str_buf));
459 str_buf[sizeof (str_buf)-1] = '\0';
460 *((int *) valuep) = atoi (str_buf);
463 strncpy (str_buf, string, sizeof (str_buf));
464 str_buf[sizeof (str_buf)-1] = '\0';
465 XmuCopyISOLatin1Lowered (str_buf, str_buf);
466 if (!strcmp (str_buf, "true") ||
467 !strcmp (str_buf, "on") ||
468 !strcmp (str_buf, "yes"))
469 *((int *) valuep) = 1;
470 else if (!strcmp (str_buf, "false") ||
471 !strcmp (str_buf, "off") ||
472 !strcmp (str_buf, "no"))
473 *((int *) valuep) = 0;
476 *((char ***) valuep) = parseArgs ((char **) 0, string);
482 XrmOptionDescRec configTable [] = {
483 {"-server", NULL, XrmoptionSkipArg, (caddr_t) NULL },
484 {"-udpPort", NULL, XrmoptionSkipArg, (caddr_t) NULL },
485 {"-error", NULL, XrmoptionSkipArg, (caddr_t) NULL },
486 {"-resources", NULL, XrmoptionSkipArg, (caddr_t) NULL },
487 {"-session", NULL, XrmoptionSkipArg, (caddr_t) NULL },
488 {"-debug", NULL, XrmoptionSkipArg, (caddr_t) NULL },
489 {"-xrm", NULL, XrmoptionSkipArg, (caddr_t) NULL },
490 {"-config", ".configFile", XrmoptionSepArg, (caddr_t) NULL }
493 XrmOptionDescRec optionTable [] = {
494 {"-server", ".servers", XrmoptionSepArg, (caddr_t) NULL },
495 {"-udpPort", ".requestPort", XrmoptionSepArg, (caddr_t) NULL },
496 {"-error", ".errorLogFile", XrmoptionSepArg, (caddr_t) NULL },
497 {"-resources", "*resources", XrmoptionSepArg, (caddr_t) NULL },
498 {"-session", "*session", XrmoptionSepArg, (caddr_t) NULL },
499 {"-debug", "*debugLevel", XrmoptionSepArg, (caddr_t) NULL },
500 {"-xrm", NULL, XrmoptionResArg, (caddr_t) NULL },
501 {"-daemon", ".daemonMode", XrmoptionNoArg, "true" },
502 {"-nodaemon", ".daemonMode", XrmoptionNoArg, "false" }
505 static int originalArgc;
506 static char **originalArgv;
509 InitResources( int argc, char **argv )
518 ReinitResources( void )
524 char * configFileName;
528 argv = (char **) malloc ((originalArgc + 1) * sizeof (char *));
531 ReadCatalog(MC_LOG_SET,MC_LOG_NO_SPACE,MC_DEF_LOG_NO_SPACE));
532 for (argc = 0; argc < originalArgc; argc++)
533 argv[argc] = originalArgv[argc];
536 XrmDestroyDatabase (DmResourceDB);
537 DmResourceDB = XrmGetStringDatabase ("");
538 /* pre-parse the command line to get the -config option, if any */
539 XrmParseCommand (&DmResourceDB, configTable,
540 sizeof (configTable) / sizeof (configTable[0]),
541 "Dtlogin", &argc, argv);
543 configFileName = qualifyWithFirst(DEF_XDM_CONFIG,
544 CDE_CONFIGURATION_TOP "/config:"
545 CDE_INSTALLATION_TOP "/config");
547 GetResource ("Dtlogin.configFile", "Dtlogin.ConfigFile",
548 DM_STRING, &config, configFileName);
550 free(configFileName);
554 newDB = XrmGetFileDatabase ( config );
559 XrmDestroyDatabase (DmResourceDB);
560 DmResourceDB = newDB;
562 else if (argc != originalArgc)
564 ReadCatalog(MC_LOG_SET,MC_LOG_NO_OPENCFG,MC_DEF_LOG_NO_OPENCFG),
570 * scan the resource database to set the application name...
574 XrmParseCommand (&DmResourceDB, optionTable,
575 sizeof (optionTable) / sizeof (optionTable[0]),
576 AppName, &argc, argv);
579 * test to see if the session variable is set.
580 * for enabling the toggle in the options menu, if it is set..
582 if((XrmGetResource (DmResourceDB, "Dtlogin*session", "Dtlogin*Session", &type, &value)) == True)
587 LogError(ReadCatalog(MC_LOG_SET,MC_LOG_EXTRA_ARG,MC_DEF_LOG_EXTRA_ARG));
588 for (a = argv + 1; *a; a++)
589 LogError ((unsigned char *)" \"%s\"", *a);
590 LogError ((unsigned char *)"\n");
596 LoadDMResources( void )
599 char name[1024], class[1024];
602 if (servers) {free(servers); servers=NULL;}
603 if (keyFile) {free(keyFile); keyFile=NULL;}
604 if (accessFile) {free(accessFile); accessFile=NULL;}
606 for (i = 0; i < NUM_DM_RESOURCES; i++) {
607 sprintf (name, "%s.%s", AppName, DmResources[i].name);
608 sprintf (class, "%s.%s", AppName, DmResources[i].class);
609 GetResource (name, class, DmResources[i].type,
610 (char **) DmResources[i].dm_value,
611 DmResources[i].default_value);
614 servers = getFullFileName(servers, 1, NULL);
615 keyFile = getFullFileName(keyFile, 0, NULL);
616 accessFile = getFullFileName(accessFile, 0, NULL);
618 #ifndef __apollo /* set a TZ default for all OS except Domain */
619 if (timeZone == NULL || strlen(timeZone) == 0)
622 * dynamically determine the timeZone resource default value...
624 GetSysParms(&timeZone,0,0);
631 CleanUpName( char *src, char *dst, int len )
651 LoadDisplayResources( struct display *d )
654 char name[1024], class[1024];
655 char dpyName[512], dpyClass[512];
658 Debug("Loading display resources for %s\n", d->name);
660 if (d->resources) {free(d->resources); d->resources=NULL;}
661 if (d->setup) {free(d->setup); d->setup=NULL;}
662 if (d->startup) {free(d->startup); d->startup=NULL;}
663 if (d->reset) {free(d->reset); d->reset=NULL;}
664 if (d->session) {free(d->session); d->session=NULL;}
665 if (d->failsafeClient) {free(d->failsafeClient); d->failsafeClient=NULL;}
667 CleanUpName (d->name, dpyName, sizeof (dpyName));
668 CleanUpName (d->class ? d->class : d->name, dpyClass, sizeof (dpyClass));
670 if((lang = getenv("LANG")) != NULL)
671 for (i = NUM_DISPLAY_RESOURCES - 1; i >= 0; i--) {
672 if(strcmp(DisplayResources[i].name,"language") == 0){
673 DisplayResources[i].default_value = lang;
679 for (i = 0; i < NUM_DISPLAY_RESOURCES; i++) {
680 sprintf (name, "%s.%s.%s", AppName,
681 dpyName, DisplayResources[i].name);
682 sprintf (class, "%s.%s.%s", AppName,
683 dpyClass, DisplayResources[i].class);
684 GetResource (name, class, DisplayResources[i].type,
685 (char **) (((char *) d) + DisplayResources[i].offset), DisplayResources[i].default_value);
689 if(d->language == NULL || strlen(d->language) == 0)
690 SetDefaultLanguage(d);
693 d->resources = getFullFileName(d->resources, 2, d->language);
694 d->setup = getFullFileName(d->setup, 0, NULL);
695 d->startup = getFullFileName(d->startup, 0, NULL);
696 d->reset = getFullFileName(d->reset, 0, NULL);
697 d->session = getFullFileName(d->session, 0, NULL);
698 d->failsafeClient = getFullFileName(d->failsafeClient, 0, NULL);
704 /***************************************************************************
708 * Probe the resource database to see whether the config file is using
709 * "Dtlogin" or "DisplayManager" as the application name.
711 * If it cannot be determined, "Dtlogin" is used.
712 ***************************************************************************/
718 char name[1024], class[1024];
722 for (i = 0; i < NUM_DM_RESOURCES; i++) {
725 * try "Dtlogin" (default) ...
728 sprintf (name, "%s.%s", DTLOGIN, DmResources[i].name);
729 sprintf (class, "%s.%s", DTLOGIN, DmResources[i].class);
731 if (DmResourceDB && XrmGetResource (DmResourceDB, name, class,
734 strcpy(AppName, DTLOGIN);
740 * try "DisplayManager" ...
743 sprintf (name, "%s.%s", DISPLAYMANAGER, DmResources[i].name);
744 sprintf (class, "%s.%s", DISPLAYMANAGER, DmResources[i].class);
746 if (DmResourceDB && XrmGetResource (DmResourceDB, name, class,
749 strcpy(AppName, DISPLAYMANAGER);
757 /***************************************************************************
761 * Try to produce a fully qualified file name by prepending
762 * /etc/dt/config or /usr/dt/config to a resource file name.
763 * There are 2 special cases: servers - which can be a command, and
764 * resources - which can an imbeded %L.
765 ***************************************************************************/
766 extern char *_ExpandLang( char *string, char *lang );
769 getFullFileName(char *name, int special, char *lang)
777 /** if the file already starts with a '/' **/
778 /** then just return a copy of it **/
779 if (name[0] == '/') {
780 if ((newname = (char *)malloc((strlen(name)+1)*sizeof(char))) == NULL) {
783 strcpy(newname, name);
789 /*********************/
790 case 0: /** no special case **/
791 /*********************/
792 newname = qualifyWithFirst(name,
793 CDE_CONFIGURATION_TOP "/config:"
794 CDE_INSTALLATION_TOP "/config");
797 /***************************************/
798 case 1: /** special handling for servers file **/
799 /***************************************/
800 if (strchr(name, ':') != NULL) {
801 /** This is probably a command and not a file name **/
802 /** so just return a copy of it. **/
803 if ((newname = (char *)malloc((strlen(name)+1)*sizeof(char)))
807 strcpy(newname, name);
811 newname = qualifyWithFirst(name,
812 CDE_CONFIGURATION_TOP "/config:"
813 CDE_INSTALLATION_TOP "/config");
817 /********************************************/
818 case 2: /** special handling for d->resources file **/
819 /********************************************/
820 if (strchr(name, '%') == NULL) {
821 /** no special processing needed **/
822 newname = qualifyWithFirst(name,
823 CDE_CONFIGURATION_TOP "/config:"
824 CDE_INSTALLATION_TOP "/config");
831 /** need to remember the %L **/
834 langString = _ExpandLang(name, lang);
835 if ( (tempName = qualifyWithFirst(langString,
836 CDE_CONFIGURATION_TOP "/config:"
837 CDE_INSTALLATION_TOP "/config") )
840 langString = _ExpandLang(name, "C");
841 if ( (tempName = qualifyWithFirst(langString,
842 CDE_CONFIGURATION_TOP "/config:"
843 CDE_INSTALLATION_TOP "/config") )
849 /** We have a fully qualified and expanded file name **/
850 /** but we need to return a fully qualified but NOT **/
851 /** expanded file name. **/
852 tempLen = strlen(tempName) - strlen(langString)
854 if ((newname = (char *)malloc(tempLen * sizeof(char))) == NULL){
858 tempLen = strlen(tempName) - strlen(langString);
859 strncpy(newname, tempName, tempLen);
860 strcpy(newname+tempLen, name);