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;
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);
485 XrmOptionDescRec configTable [] = {
486 {"-server", NULL, XrmoptionSkipArg, (caddr_t) NULL },
487 {"-udpPort", NULL, XrmoptionSkipArg, (caddr_t) NULL },
488 {"-error", NULL, XrmoptionSkipArg, (caddr_t) NULL },
489 {"-resources", NULL, XrmoptionSkipArg, (caddr_t) NULL },
490 {"-session", NULL, XrmoptionSkipArg, (caddr_t) NULL },
491 {"-debug", NULL, XrmoptionSkipArg, (caddr_t) NULL },
492 {"-xrm", NULL, XrmoptionSkipArg, (caddr_t) NULL },
493 {"-config", ".configFile", XrmoptionSepArg, (caddr_t) NULL }
496 XrmOptionDescRec optionTable [] = {
497 {"-server", ".servers", XrmoptionSepArg, (caddr_t) NULL },
498 {"-udpPort", ".requestPort", XrmoptionSepArg, (caddr_t) NULL },
499 {"-error", ".errorLogFile", XrmoptionSepArg, (caddr_t) NULL },
500 {"-resources", "*resources", XrmoptionSepArg, (caddr_t) NULL },
501 {"-session", "*session", XrmoptionSepArg, (caddr_t) NULL },
502 {"-debug", "*debugLevel", XrmoptionSepArg, (caddr_t) NULL },
503 {"-xrm", NULL, XrmoptionResArg, (caddr_t) NULL },
504 {"-daemon", ".daemonMode", XrmoptionNoArg, "true" },
505 {"-nodaemon", ".daemonMode", XrmoptionNoArg, "false" },
506 {"-quiet", ".quiet", XrmoptionNoArg, "true" }
509 static int originalArgc;
510 static char **originalArgv;
513 InitResources( int argc, char **argv )
522 ReinitResources( void )
528 char * configFileName;
532 argv = (char **) malloc ((originalArgc + 1) * sizeof (char *));
535 ReadCatalog(MC_LOG_SET,MC_LOG_NO_SPACE,MC_DEF_LOG_NO_SPACE));
536 for (argc = 0; argc < originalArgc; argc++)
537 argv[argc] = originalArgv[argc];
540 XrmDestroyDatabase (DmResourceDB);
541 DmResourceDB = XrmGetStringDatabase ("");
542 /* pre-parse the command line to get the -config option, if any */
543 XrmParseCommand (&DmResourceDB, configTable,
544 sizeof (configTable) / sizeof (configTable[0]),
545 "Dtlogin", &argc, argv);
547 configFileName = qualifyWithFirst(DEF_XDM_CONFIG,
548 CDE_CONFIGURATION_TOP "/config:"
549 CDE_INSTALLATION_TOP "/config");
551 GetResource ("Dtlogin.configFile", "Dtlogin.ConfigFile",
552 DM_STRING, &config, configFileName);
554 free(configFileName);
558 newDB = XrmGetFileDatabase ( config );
563 XrmDestroyDatabase (DmResourceDB);
564 DmResourceDB = newDB;
566 else if (argc != originalArgc)
568 ReadCatalog(MC_LOG_SET,MC_LOG_NO_OPENCFG,MC_DEF_LOG_NO_OPENCFG),
574 * scan the resource database to set the application name...
578 XrmParseCommand (&DmResourceDB, optionTable,
579 sizeof (optionTable) / sizeof (optionTable[0]),
580 AppName, &argc, argv);
583 * test to see if the session variable is set.
584 * for enabling the toggle in the options menu, if it is set..
586 if((XrmGetResource (DmResourceDB, "Dtlogin*session", "Dtlogin*Session", &type, &value)) == True)
591 LogError(ReadCatalog(MC_LOG_SET,MC_LOG_EXTRA_ARG,MC_DEF_LOG_EXTRA_ARG));
592 for (a = argv + 1; *a; a++)
593 LogError ((unsigned char *)" \"%s\"", *a);
594 LogError ((unsigned char *)"\n");
600 LoadDMResources( void )
603 char name[1024], class[1024];
606 if (servers) {free(servers); servers=NULL;}
607 if (keyFile) {free(keyFile); keyFile=NULL;}
608 if (accessFile) {free(accessFile); accessFile=NULL;}
610 for (i = 0; i < NUM_DM_RESOURCES; i++) {
611 sprintf (name, "%s.%s", AppName, DmResources[i].name);
612 sprintf (class, "%s.%s", AppName, DmResources[i].class);
613 GetResource (name, class, DmResources[i].type,
614 (char **) DmResources[i].dm_value,
615 DmResources[i].default_value);
618 servers = getFullFileName(servers, 1, NULL);
619 keyFile = getFullFileName(keyFile, 0, NULL);
620 accessFile = getFullFileName(accessFile, 0, NULL);
622 #ifndef __apollo /* set a TZ default for all OS except Domain */
623 if (timeZone == NULL || strlen(timeZone) == 0)
626 * dynamically determine the timeZone resource default value...
628 GetSysParms(&timeZone,0,0);
635 CleanUpName( char *src, char *dst, int len )
655 LoadDisplayResources( struct display *d )
658 char name[1024], class[1024];
659 char dpyName[512], dpyClass[512];
662 Debug("Loading display resources for %s\n", d->name);
664 if (d->resources) {free(d->resources); d->resources=NULL;}
665 if (d->setup) {free(d->setup); d->setup=NULL;}
666 if (d->startup) {free(d->startup); d->startup=NULL;}
667 if (d->reset) {free(d->reset); d->reset=NULL;}
668 if (d->session) {free(d->session); d->session=NULL;}
669 if (d->failsafeClient) {free(d->failsafeClient); d->failsafeClient=NULL;}
671 CleanUpName (d->name, dpyName, sizeof (dpyName));
672 CleanUpName (d->class ? d->class : d->name, dpyClass, sizeof (dpyClass));
674 if((lang = getenv("LANG")) != NULL)
675 for (i = NUM_DISPLAY_RESOURCES - 1; i >= 0; i--) {
676 if(strcmp(DisplayResources[i].name,"language") == 0){
677 DisplayResources[i].default_value = lang;
683 for (i = 0; i < NUM_DISPLAY_RESOURCES; i++) {
684 sprintf (name, "%s.%s.%s", AppName,
685 dpyName, DisplayResources[i].name);
686 sprintf (class, "%s.%s.%s", AppName,
687 dpyClass, DisplayResources[i].class);
688 GetResource (name, class, DisplayResources[i].type,
689 (char **) (((char *) d) + DisplayResources[i].offset), DisplayResources[i].default_value);
693 if(d->language == NULL || strlen(d->language) == 0)
694 SetDefaultLanguage(d);
697 d->resources = getFullFileName(d->resources, 2, d->language);
698 d->setup = getFullFileName(d->setup, 0, NULL);
699 d->startup = getFullFileName(d->startup, 0, NULL);
700 d->reset = getFullFileName(d->reset, 0, NULL);
701 d->session = getFullFileName(d->session, 0, NULL);
702 d->failsafeClient = getFullFileName(d->failsafeClient, 0, NULL);
708 /***************************************************************************
712 * Probe the resource database to see whether the config file is using
713 * "Dtlogin" or "DisplayManager" as the application name.
715 * If it cannot be determined, "Dtlogin" is used.
716 ***************************************************************************/
722 char name[1024], class[1024];
726 for (i = 0; i < NUM_DM_RESOURCES; i++) {
729 * try "Dtlogin" (default) ...
732 sprintf (name, "%s.%s", DTLOGIN, DmResources[i].name);
733 sprintf (class, "%s.%s", DTLOGIN, DmResources[i].class);
735 if (DmResourceDB && XrmGetResource (DmResourceDB, name, class,
738 strcpy(AppName, DTLOGIN);
744 * try "DisplayManager" ...
747 sprintf (name, "%s.%s", DISPLAYMANAGER, DmResources[i].name);
748 sprintf (class, "%s.%s", DISPLAYMANAGER, DmResources[i].class);
750 if (DmResourceDB && XrmGetResource (DmResourceDB, name, class,
753 strcpy(AppName, DISPLAYMANAGER);
761 /***************************************************************************
765 * Try to produce a fully qualified file name by prepending
766 * /etc/dt/config or /usr/dt/config to a resource file name.
767 * There are 2 special cases: servers - which can be a command, and
768 * resources - which can an imbeded %L.
769 ***************************************************************************/
770 extern char *_ExpandLang( char *string, char *lang );
773 getFullFileName(char *name, int special, char *lang)
781 /** if the file already starts with a '/' **/
782 /** then just return a copy of it **/
783 if (name[0] == '/') {
784 if ((newname = (char *)malloc((strlen(name)+1)*sizeof(char))) == NULL) {
787 strcpy(newname, name);
793 /*********************/
794 case 0: /** no special case **/
795 /*********************/
796 newname = qualifyWithFirst(name,
797 CDE_CONFIGURATION_TOP "/config:"
798 CDE_INSTALLATION_TOP "/config");
801 /***************************************/
802 case 1: /** special handling for servers file **/
803 /***************************************/
804 if (strchr(name, ':') != NULL) {
805 /** This is probably a command and not a file name **/
806 /** so just return a copy of it. **/
807 if ((newname = (char *)malloc((strlen(name)+1)*sizeof(char)))
811 strcpy(newname, name);
815 newname = qualifyWithFirst(name,
816 CDE_CONFIGURATION_TOP "/config:"
817 CDE_INSTALLATION_TOP "/config");
821 /********************************************/
822 case 2: /** special handling for d->resources file **/
823 /********************************************/
824 if (strchr(name, '%') == NULL) {
825 /** no special processing needed **/
826 newname = qualifyWithFirst(name,
827 CDE_CONFIGURATION_TOP "/config:"
828 CDE_INSTALLATION_TOP "/config");
835 /** need to remember the %L **/
838 langString = _ExpandLang(name, lang);
839 if ( (tempName = qualifyWithFirst(langString,
840 CDE_CONFIGURATION_TOP "/config:"
841 CDE_INSTALLATION_TOP "/config") )
844 langString = _ExpandLang(name, "C");
845 if ( (tempName = qualifyWithFirst(langString,
846 CDE_CONFIGURATION_TOP "/config:"
847 CDE_INSTALLATION_TOP "/config") )
853 /** We have a fully qualified and expanded file name **/
854 /** but we need to return a fully qualified but NOT **/
855 /** expanded file name. **/
856 tempLen = strlen(tempName) - strlen(langString)
858 if ((newname = (char *)malloc(tempLen * sizeof(char))) == NULL){
862 tempLen = strlen(tempName) - strlen(langString);
863 strncpy(newname, tempName, tempLen);
864 strcpy(newname+tempLen, name);