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
98 * Dtlogin will accept both Dtlogin and XDM resources. The string variable
99 * "AppName" contains the proper application name to use in looking up
103 # define DISPLAYMANAGER "DisplayManager"
104 # define DTLOGIN "Dtlogin"
106 static char AppName[16] = DTLOGIN;
115 # define DEF_XDM_CONFIG CDE_INSTALLATION_TOP "/lib/X11/Dtlogin/Xconfig"
116 # define DEF_AUTH_DIR CDE_INSTALLATION_TOP "/lib/X11/Dtlogin"
117 # define DEF_KEY_FILE CDE_INSTALLATION_TOP "/lib/X11/Dtlogin/Xkeys"
122 * the following constants are supposed to be set in the makefile from
123 * parameters set util/imake.includes/site.def (or *.macros in that directory
124 * if it is server-specific). DO NOT CHANGE THESE DEFINITIONS!
126 #ifndef DEF_SERVER_LINE
128 #define DEF_SERVER_LINE ":0 local /usr/openwin/bin/X :0"
130 #define DEF_SERVER_LINE ":0 local /usr/bin/X11/X :0"
135 #define XRDB_PROGRAM "/usr/openwin/bin/xrdb"
137 #define XRDB_PROGRAM "/usr/bin/X11/xrdb"
141 #define DEF_SESSION CDE_INSTALLATION_TOP "/bin/Xsession"
144 #ifndef DEF_USER_PATH
146 # define DEF_USER_PATH "/usr/openwin/bin:/bin:/usr/bin:/usr/contrib/bin:/usr/local/bin:."
148 # define DEF_USER_PATH "/usr/bin/X11:/bin:/usr/bin:/usr/contrib/bin:/usr/local/bin"
152 #ifndef DEF_SYSTEM_PATH
154 # define DEF_SYSTEM_PATH "/usr/openwin/bin:/etc:/bin:/usr/bin"
156 # define DEF_SYSTEM_PATH "/usr/bin/X11:/etc:/bin:/usr/bin"
160 #ifndef DEF_SYSTEM_SHELL
161 #define DEF_SYSTEM_SHELL "/bin/sh"
164 #ifndef DEF_FAILSAFE_CLIENT
166 #define DEF_FAILSAFE_CLIENT "/usr/openwin/bin/xterm"
168 #define DEF_FAILSAFE_CLIENT "/usr/bin/X11/xterm"
172 #ifndef DEF_XDM_CONFIG
173 #define DEF_XDM_CONFIG "Xconfig"
177 #define DEF_CHOOSER CDE_INSTALLATION_TOP "/bin/chooser"
181 #define CPP_PROGRAM "/lib/cpp"
183 #ifndef DEF_XDM_AUTH_GEN
184 #define DEF_XDM_AUTH_GEN CDE_CONFIGURATION_TOP "/xdmauthgen"
186 #ifndef DEF_AUTH_NAME
187 #define DEF_AUTH_NAME "MIT-MAGIC-COOKIE-1"
190 #define DEF_AUTH_DIR CDE_CONFIGURATION_TOP
192 #ifndef DEF_USER_AUTH_DIR
193 #define DEF_USER_AUTH_DIR "/tmp"
196 #define DEF_KEY_FILE CDE_CONFIGURATION_TOP "/Xkeys"
198 #ifndef DEF_ACCESS_FILE
199 #define DEF_ACCESS_FILE ""
202 #define DEF_TIMEZONE "MST7MDT"
204 #ifndef DEF_SYS_PARMS_FILE
205 # if defined( __hpux )
206 # define DEF_SYS_PARMS_FILE "/etc/src.sh"
208 # define DEF_SYS_PARMS_FILE "/etc/TIMEZONE"
211 #define DEF_UDP_PORT "177" /* registered XDMCP port, don't change */
214 # ifdef sun /* need to set the environment for Sun OpenWindows */
215 # define DEF_ENV "OPENWINHOME=/usr/openwin"
221 #ifndef DEF_LANG /* LANG default settings for various architectures */
223 # define DEF_LANG "C"
226 # define DEF_LANG "C"
229 # define DEF_LANG "en_US.88591"
231 # ifdef sun /* default language under Solaris */
232 # define DEF_LANG "C"
236 #ifndef DEF_LANG /* set LANG to NULL if not already defined */
246 "servers", "Servers", DM_STRING, &servers,
248 "requestPort", "RequestPort", DM_INT, (char **) &request_port,
250 "debugLevel", "DebugLevel", DM_INT, (char **) &debugLevel,
252 "errorLogFile", "ErrorLogFile", DM_STRING, &errorLogFile,
254 "errorLogSize", "ErrorLogSize", DM_INT, (char **) &errorLogSize,
256 "daemonMode", "DaemonMode", DM_BOOL, (char **) &daemonMode,
258 "quiet", "quiet", DM_BOOL, (char **) &quiet,
260 "pidFile", "PidFile", DM_STRING, &pidFile,
262 "lockPidFile", "LockPidFile", DM_BOOL, (char **) &lockPidFile,
264 "authDir", "AuthDir", DM_STRING, &authDir,
266 "autoRescan", "AutoRescan", DM_BOOL, (char **) &autoRescan,
268 "removeDomainname","RemoveDomainname",DM_BOOL, (char **) &removeDomainname,
270 "keyFile", "KeyFile", DM_STRING, &keyFile,
272 "accessFile", "AccessFile", DM_STRING, &accessFile,
274 /* exportList env var resource RK 08.17.93 */
275 "exportList", "ExportList", DM_ARGV, (char **) &exportList,
277 "timeZone", "TimeZone", DM_STRING, &timeZone,
279 "fontPathHead", "FontPathHead", DM_STRING, &fpHead,
281 "fontPathTail", "FontPathTail", DM_STRING, &fpTail,
283 "sysParmsFile", "SysParmsFile", DM_STRING, &sysParmsFile,
285 "wakeupInterval","WakeupInterval",DM_INT, (char **) &wakeupInterval,
287 "langListTimeout","langListTimeout",DM_INT, (char **) &langListTimeout,
289 #ifdef DEF_NETWORK_DEV
290 "networkDevice","NetworkDevice",DM_STRING, &networkDev,
294 "ignoreLocales", "IgnoreLocales", DM_STRING, &ignoreLocales,
299 # define NUM_DM_RESOURCES (sizeof DmResources / sizeof DmResources[0])
301 # define boffset(f) ((char *) &(((struct display *) 0)->f) - (char *) 0)
303 struct displayResources {
308 } DisplayResources[] = {
312 * resources for managing the server...
315 "serverAttempts","ServerAttempts", DM_INT, boffset(serverAttempts),
317 "openDelay", "OpenDelay", DM_INT, boffset(openDelay),
319 "openRepeat", "OpenRepeat", DM_INT, boffset(openRepeat),
321 "openTimeout", "OpenTimeout", DM_INT, boffset(openTimeout),
323 "startAttempts","StartAttempts",DM_INT, boffset(startAttempts),
325 "pingInterval", "PingInterval", DM_INT, boffset(pingInterval),
327 "pingTimeout", "PingTimeout", DM_INT, boffset(pingTimeout),
329 "terminateServer","TerminateServer",DM_BOOL, boffset(terminateServer),
331 "grabServer", "GrabServer", DM_BOOL, boffset(grabServer),
333 "grabTimeout", "GrabTimeout", DM_INT, boffset(grabTimeout),
335 "resetSignal", "Signal", DM_INT, boffset(resetSignal),
337 "termSignal", "Signal", DM_INT, boffset(termSignal),
339 "resetForAuth", "ResetForAuth", DM_BOOL, boffset(resetForAuth),
341 "authorize", "Authorize", DM_BOOL, boffset(authorize),
343 "authName", "AuthName", DM_ARGV, boffset(authNames),
345 "authFile", "AuthFile", DM_STRING, boffset(authFile),
348 "gettyLine", "GettyLine", DM_STRING, boffset(gettyLine),
350 "gettySpeed", "GettySpeed", DM_STRING, boffset(gettySpeed),
354 * resources which control the session behavior...
357 "resources", "Resources", DM_STRING, boffset(resources),
359 "xrdb", "Xrdb", DM_STRING, boffset(xrdb),
361 "cpp", "Cpp", DM_STRING, boffset(cpp),
363 "setup", "Setup", DM_STRING, boffset(setup),
365 "startup", "Startup", DM_STRING, boffset(startup),
367 "reset", "Reset", DM_STRING, boffset(reset),
369 "session", "Session", DM_STRING, boffset(session),
371 "userPath", "Path", DM_STRING, boffset(userPath),
373 "systemPath", "Path", DM_STRING, boffset(systemPath),
375 "systemShell", "Shell", DM_STRING, boffset(systemShell),
377 "failsafeClient","FailsafeClient", DM_STRING, boffset(failsafeClient),
379 "userAuthDir", "UserAuthDir", DM_STRING, boffset(userAuthDir),
381 "chooser", "Chooser", DM_STRING, boffset(chooser),
383 "language", "Language", DM_STRING, boffset(language),
385 "languageList", "LanguageList", DM_STRING, boffset(langList),
387 "environment", "Environment", DM_STRING, boffset(environStr),
389 "dtlite", "Dtlite", DM_BOOL, boffset(dtlite),
391 "xdmMode", "XdmMode", DM_BOOL, boffset(xdmMode),
393 "authenticationName","AuthenticationName", DM_STRING, boffset(verifyName),
395 "pmSearchPath", "PmSearchPath", DM_STRING, boffset(pmSearchPath),
397 "bmSearchPath", "bmSearchPath", DM_STRING, boffset(bmSearchPath),
401 # define NUM_DISPLAY_RESOURCES (sizeof DisplayResources/sizeof DisplayResources[0])
403 XrmDatabase DmResourceDB;
406 GetResource( char *name, char *class, int valueType, char **valuep,
407 char *default_value )
411 char *string, *new_string;
416 if (DmResourceDB && XrmGetResource (DmResourceDB,
425 string = default_value;
426 len = (string == NULL ? 0 : strlen (string));
429 Debug ("%s/%s value %*.*s\n", name, class, len, len, string);
433 * check if new resource is the same as old...
436 if (valueType == DM_STRING && *valuep) {
437 if (string != NULL && strlen (*valuep) == len && !strncmp (*valuep, string, len))
449 new_string = malloc ((unsigned) (len+1));
452 ReadCatalog(MC_LOG_SET,MC_LOG_GET_RSC,MC_DEF_LOG_GET_RSC));
455 strncpy (new_string, string, len);
456 new_string[len] = '\0';
457 *(valuep) = new_string;
461 strncpy (str_buf, string, sizeof (str_buf));
462 str_buf[sizeof (str_buf)-1] = '\0';
463 *((int *) valuep) = atoi (str_buf);
466 strncpy (str_buf, string, sizeof (str_buf));
467 str_buf[sizeof (str_buf)-1] = '\0';
468 XmuCopyISOLatin1Lowered (str_buf, str_buf);
469 if (!strcmp (str_buf, "true") ||
470 !strcmp (str_buf, "on") ||
471 !strcmp (str_buf, "yes"))
472 *((int *) valuep) = 1;
473 else if (!strcmp (str_buf, "false") ||
474 !strcmp (str_buf, "off") ||
475 !strcmp (str_buf, "no"))
476 *((int *) valuep) = 0;
479 *((char ***) valuep) = parseArgs ((char **) 0, string);
487 XrmOptionDescRec configTable [] = {
488 {"-server", NULL, XrmoptionSkipArg, (caddr_t) NULL },
489 {"-udpPort", NULL, XrmoptionSkipArg, (caddr_t) NULL },
490 {"-error", NULL, XrmoptionSkipArg, (caddr_t) NULL },
491 {"-resources", NULL, XrmoptionSkipArg, (caddr_t) NULL },
492 {"-session", NULL, XrmoptionSkipArg, (caddr_t) NULL },
493 {"-debug", NULL, XrmoptionSkipArg, (caddr_t) NULL },
494 {"-xrm", NULL, XrmoptionSkipArg, (caddr_t) NULL },
495 {"-config", ".configFile", XrmoptionSepArg, (caddr_t) NULL }
498 XrmOptionDescRec optionTable [] = {
499 {"-server", ".servers", XrmoptionSepArg, (caddr_t) NULL },
500 {"-udpPort", ".requestPort", XrmoptionSepArg, (caddr_t) NULL },
501 {"-error", ".errorLogFile", XrmoptionSepArg, (caddr_t) NULL },
502 {"-resources", "*resources", XrmoptionSepArg, (caddr_t) NULL },
503 {"-session", "*session", XrmoptionSepArg, (caddr_t) NULL },
504 {"-debug", "*debugLevel", XrmoptionSepArg, (caddr_t) NULL },
505 {"-xrm", NULL, XrmoptionResArg, (caddr_t) NULL },
506 {"-daemon", ".daemonMode", XrmoptionNoArg, "true" },
507 {"-nodaemon", ".daemonMode", XrmoptionNoArg, "false" },
508 {"-quiet", ".quiet", XrmoptionNoArg, "true" }
511 static int originalArgc;
512 static char **originalArgv;
515 InitResources( int argc, char **argv )
524 ReinitResources( void )
530 char * configFileName;
534 argv = (char **) malloc ((originalArgc + 1) * sizeof (char *));
537 ReadCatalog(MC_LOG_SET,MC_LOG_NO_SPACE,MC_DEF_LOG_NO_SPACE));
538 for (argc = 0; argc < originalArgc; argc++)
539 argv[argc] = originalArgv[argc];
542 XrmDestroyDatabase (DmResourceDB);
543 DmResourceDB = XrmGetStringDatabase ("");
544 /* pre-parse the command line to get the -config option, if any */
545 XrmParseCommand (&DmResourceDB, configTable,
546 sizeof (configTable) / sizeof (configTable[0]),
547 "Dtlogin", &argc, argv);
549 configFileName = qualifyWithFirst(DEF_XDM_CONFIG,
550 CDE_CONFIGURATION_TOP "/config:"
551 CDE_INSTALLATION_TOP "/config");
553 GetResource ("Dtlogin.configFile", "Dtlogin.ConfigFile",
554 DM_STRING, &config, configFileName);
556 free(configFileName);
560 newDB = XrmGetFileDatabase ( config );
565 XrmDestroyDatabase (DmResourceDB);
566 DmResourceDB = newDB;
568 else if (argc != originalArgc)
570 ReadCatalog(MC_LOG_SET,MC_LOG_NO_OPENCFG,MC_DEF_LOG_NO_OPENCFG),
576 * scan the resource database to set the application name...
580 XrmParseCommand (&DmResourceDB, optionTable,
581 sizeof (optionTable) / sizeof (optionTable[0]),
582 AppName, &argc, argv);
585 * test to see if the session variable is set.
586 * for enabling the toggle in the options menu, if it is set..
588 if((XrmGetResource (DmResourceDB, "Dtlogin*session", "Dtlogin*Session", &type, &value)) == True)
593 LogError(ReadCatalog(MC_LOG_SET,MC_LOG_EXTRA_ARG,MC_DEF_LOG_EXTRA_ARG));
594 for (a = argv + 1; *a; a++)
595 LogError ((unsigned char *)" \"%s\"", *a);
596 LogError ((unsigned char *)"\n");
602 LoadDMResources( void )
605 char name[1024], class[1024];
608 if (servers) {free(servers); servers=NULL;}
609 if (keyFile) {free(keyFile); keyFile=NULL;}
610 if (accessFile) {free(accessFile); accessFile=NULL;}
612 for (i = 0; i < NUM_DM_RESOURCES; i++) {
613 sprintf (name, "%s.%s", AppName, DmResources[i].name);
614 sprintf (class, "%s.%s", AppName, DmResources[i].class);
615 GetResource (name, class, DmResources[i].type,
616 (char **) DmResources[i].dm_value,
617 DmResources[i].default_value);
620 servers = getFullFileName(servers, 1, NULL);
621 keyFile = getFullFileName(keyFile, 0, NULL);
622 accessFile = getFullFileName(accessFile, 0, NULL);
624 #ifndef __apollo /* set a TZ default for all OS except Domain */
625 if (timeZone == NULL || strlen(timeZone) == 0)
628 * dynamically determine the timeZone resource default value...
630 GetSysParms(&timeZone,0,0);
637 CleanUpName( char *src, char *dst, int len )
657 LoadDisplayResources( struct display *d )
660 char name[1024], class[1024];
661 char dpyName[512], dpyClass[512];
664 Debug("Loading display resources for %s\n", d->name);
666 if (d->resources) {free(d->resources); d->resources=NULL;}
667 if (d->setup) {free(d->setup); d->setup=NULL;}
668 if (d->startup) {free(d->startup); d->startup=NULL;}
669 if (d->reset) {free(d->reset); d->reset=NULL;}
670 if (d->session) {free(d->session); d->session=NULL;}
671 if (d->failsafeClient) {free(d->failsafeClient); d->failsafeClient=NULL;}
673 CleanUpName (d->name, dpyName, sizeof (dpyName));
674 CleanUpName (d->class ? d->class : d->name, dpyClass, sizeof (dpyClass));
676 if((lang = getenv("LANG")) != NULL)
677 for (i = NUM_DISPLAY_RESOURCES - 1; i >= 0; i--) {
678 if(strcmp(DisplayResources[i].name,"language") == 0){
679 DisplayResources[i].default_value = lang;
685 for (i = 0; i < NUM_DISPLAY_RESOURCES; i++) {
686 sprintf (name, "%s.%s.%s", AppName,
687 dpyName, DisplayResources[i].name);
688 sprintf (class, "%s.%s.%s", AppName,
689 dpyClass, DisplayResources[i].class);
690 GetResource (name, class, DisplayResources[i].type,
691 (char **) (((char *) d) + DisplayResources[i].offset), DisplayResources[i].default_value);
695 if(d->language == NULL || strlen(d->language) == 0)
696 SetDefaultLanguage(d);
699 d->resources = getFullFileName(d->resources, 2, d->language);
700 d->setup = getFullFileName(d->setup, 0, NULL);
701 d->startup = getFullFileName(d->startup, 0, NULL);
702 d->reset = getFullFileName(d->reset, 0, NULL);
703 d->session = getFullFileName(d->session, 0, NULL);
704 d->failsafeClient = getFullFileName(d->failsafeClient, 0, NULL);
710 /***************************************************************************
714 * Probe the resource database to see whether the config file is using
715 * "Dtlogin" or "DisplayManager" as the application name.
717 * If it cannot be determined, "Dtlogin" is used.
718 ***************************************************************************/
724 char name[1024], class[1024];
728 for (i = 0; i < NUM_DM_RESOURCES; i++) {
731 * try "Dtlogin" (default) ...
734 sprintf (name, "%s.%s", DTLOGIN, DmResources[i].name);
735 sprintf (class, "%s.%s", DTLOGIN, DmResources[i].class);
737 if (DmResourceDB && XrmGetResource (DmResourceDB, name, class,
740 strcpy(AppName, DTLOGIN);
746 * try "DisplayManager" ...
749 sprintf (name, "%s.%s", DISPLAYMANAGER, DmResources[i].name);
750 sprintf (class, "%s.%s", DISPLAYMANAGER, DmResources[i].class);
752 if (DmResourceDB && XrmGetResource (DmResourceDB, name, class,
755 strcpy(AppName, DISPLAYMANAGER);
763 /***************************************************************************
767 * Try to produce a fully qualified file name by prepending
768 * /etc/dt/config or /usr/dt/config to a resource file name.
769 * There are 2 special cases: servers - which can be a command, and
770 * resources - which can an imbeded %L.
771 ***************************************************************************/
772 extern char *_ExpandLang( char *string, char *lang );
775 getFullFileName(char *name, int special, char *lang)
783 /** if the file already starts with a '/' **/
784 /** then just return a copy of it **/
785 if (name[0] == '/') {
786 if ((newname = (char *)malloc((strlen(name)+1)*sizeof(char))) == NULL) {
789 strcpy(newname, name);
795 /*********************/
796 case 0: /** no special case **/
797 /*********************/
798 newname = qualifyWithFirst(name,
799 CDE_CONFIGURATION_TOP "/config:"
800 CDE_INSTALLATION_TOP "/config");
803 /***************************************/
804 case 1: /** special handling for servers file **/
805 /***************************************/
806 if (strchr(name, ':') != NULL) {
807 /** This is probably a command and not a file name **/
808 /** so just return a copy of it. **/
809 if ((newname = (char *)malloc((strlen(name)+1)*sizeof(char)))
813 strcpy(newname, name);
817 newname = qualifyWithFirst(name,
818 CDE_CONFIGURATION_TOP "/config:"
819 CDE_INSTALLATION_TOP "/config");
823 /********************************************/
824 case 2: /** special handling for d->resources file **/
825 /********************************************/
826 if (strchr(name, '%') == NULL) {
827 /** no special processing needed **/
828 newname = qualifyWithFirst(name,
829 CDE_CONFIGURATION_TOP "/config:"
830 CDE_INSTALLATION_TOP "/config");
837 /** need to remember the %L **/
840 langString = _ExpandLang(name, lang);
841 if ( (tempName = qualifyWithFirst(langString,
842 CDE_CONFIGURATION_TOP "/config:"
843 CDE_INSTALLATION_TOP "/config") )
846 langString = _ExpandLang(name, "C");
847 if ( (tempName = qualifyWithFirst(langString,
848 CDE_CONFIGURATION_TOP "/config:"
849 CDE_INSTALLATION_TOP "/config") )
855 /** We have a fully qualified and expanded file name **/
856 /** but we need to return a fully qualified but NOT **/
857 /** expanded file name. **/
858 tempLen = strlen(tempName) - strlen(langString)
860 if ((newname = (char *)malloc(tempLen * sizeof(char))) == NULL){
864 tempLen = strlen(tempName) - strlen(langString);
865 strncpy(newname, tempName, tempLen);
866 strcpy(newname+tempLen, name);
874 /* special is of an unknown value */