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 */
219 # ifdef sun /* default language under Solaris */
220 # define DEF_LANG "C"
224 #ifndef DEF_LANG /* set LANG to NULL if not already defined */
234 "servers", "Servers", DM_STRING, &servers,
236 "requestPort", "RequestPort", DM_INT, (char **) &request_port,
238 "debugLevel", "DebugLevel", DM_INT, (char **) &debugLevel,
240 "errorLogFile", "ErrorLogFile", DM_STRING, &errorLogFile,
242 "errorLogSize", "ErrorLogSize", DM_INT, (char **) &errorLogSize,
244 "daemonMode", "DaemonMode", DM_BOOL, (char **) &daemonMode,
246 "quiet", "quiet", DM_BOOL, (char **) &quiet,
248 "pidFile", "PidFile", DM_STRING, &pidFile,
250 "lockPidFile", "LockPidFile", DM_BOOL, (char **) &lockPidFile,
252 "authDir", "AuthDir", DM_STRING, &authDir,
254 "autoRescan", "AutoRescan", DM_BOOL, (char **) &autoRescan,
256 "removeDomainname","RemoveDomainname",DM_BOOL, (char **) &removeDomainname,
258 "keyFile", "KeyFile", DM_STRING, &keyFile,
260 "accessFile", "AccessFile", DM_STRING, &accessFile,
262 /* exportList env var resource RK 08.17.93 */
263 "exportList", "ExportList", DM_ARGV, (char **) &exportList,
265 "timeZone", "TimeZone", DM_STRING, &timeZone,
267 "fontPathHead", "FontPathHead", DM_STRING, &fpHead,
269 "fontPathTail", "FontPathTail", DM_STRING, &fpTail,
271 "sysParmsFile", "SysParmsFile", DM_STRING, &sysParmsFile,
273 "wakeupInterval","WakeupInterval",DM_INT, (char **) &wakeupInterval,
275 "langListTimeout","langListTimeout",DM_INT, (char **) &langListTimeout,
277 #ifdef DEF_NETWORK_DEV
278 "networkDevice","NetworkDevice",DM_STRING, &networkDev,
283 # define NUM_DM_RESOURCES (sizeof DmResources / sizeof DmResources[0])
285 # define boffset(f) ((char *) &(((struct display *) 0)->f) - (char *) 0)
287 struct displayResources {
292 } DisplayResources[] = {
296 * resources for managing the server...
299 "serverAttempts","ServerAttempts", DM_INT, boffset(serverAttempts),
301 "openDelay", "OpenDelay", DM_INT, boffset(openDelay),
303 "openRepeat", "OpenRepeat", DM_INT, boffset(openRepeat),
305 "openTimeout", "OpenTimeout", DM_INT, boffset(openTimeout),
307 "startAttempts","StartAttempts",DM_INT, boffset(startAttempts),
309 "pingInterval", "PingInterval", DM_INT, boffset(pingInterval),
311 "pingTimeout", "PingTimeout", DM_INT, boffset(pingTimeout),
313 "terminateServer","TerminateServer",DM_BOOL, boffset(terminateServer),
315 "grabServer", "GrabServer", DM_BOOL, boffset(grabServer),
317 "grabTimeout", "GrabTimeout", DM_INT, boffset(grabTimeout),
319 "resetSignal", "Signal", DM_INT, boffset(resetSignal),
321 "termSignal", "Signal", DM_INT, boffset(termSignal),
323 "resetForAuth", "ResetForAuth", DM_BOOL, boffset(resetForAuth),
325 "authorize", "Authorize", DM_BOOL, boffset(authorize),
327 "authName", "AuthName", DM_ARGV, boffset(authNames),
329 "authFile", "AuthFile", DM_STRING, boffset(authFile),
332 "gettyLine", "GettyLine", DM_STRING, boffset(gettyLine),
334 "gettySpeed", "GettySpeed", DM_STRING, boffset(gettySpeed),
338 * resources which control the session behavior...
341 "resources", "Resources", DM_STRING, boffset(resources),
343 "xrdb", "Xrdb", DM_STRING, boffset(xrdb),
345 "cpp", "Cpp", DM_STRING, boffset(cpp),
347 "setup", "Setup", DM_STRING, boffset(setup),
349 "startup", "Startup", DM_STRING, boffset(startup),
351 "reset", "Reset", DM_STRING, boffset(reset),
353 "session", "Session", DM_STRING, boffset(session),
355 "userPath", "Path", DM_STRING, boffset(userPath),
357 "systemPath", "Path", DM_STRING, boffset(systemPath),
359 "systemShell", "Shell", DM_STRING, boffset(systemShell),
361 "failsafeClient","FailsafeClient", DM_STRING, boffset(failsafeClient),
363 "userAuthDir", "UserAuthDir", DM_STRING, boffset(userAuthDir),
365 "chooser", "Chooser", DM_STRING, boffset(chooser),
367 "language", "Language", DM_STRING, boffset(language),
369 "languageList", "LanguageList", DM_STRING, boffset(langList),
371 "environment", "Environment", DM_STRING, boffset(environStr),
373 "dtlite", "Dtlite", DM_BOOL, boffset(dtlite),
375 "xdmMode", "XdmMode", DM_BOOL, boffset(xdmMode),
377 "authenticationName","AuthenticationName", DM_STRING, boffset(verifyName),
379 "pmSearchPath", "PmSearchPath", DM_STRING, boffset(pmSearchPath),
381 "bmSearchPath", "bmSearchPath", DM_STRING, boffset(bmSearchPath),
385 # define NUM_DISPLAY_RESOURCES (sizeof DisplayResources/sizeof DisplayResources[0])
387 XrmDatabase DmResourceDB;
390 GetResource( char *name, char *class, int valueType, char **valuep,
391 char *default_value )
395 char *string, *new_string;
401 if (DmResourceDB && XrmGetResource (DmResourceDB,
411 string = default_value;
412 len = strlen (string);
419 Debug ("%s/%s value %*.*s\n", name, class, len, len, string);
423 * check if new resource is the same as old...
426 if (valueType == DM_STRING && *valuep) {
427 if (string != NULL && strlen (*valuep) == len && !strncmp (*valuep, string, len))
439 new_string = malloc ((unsigned) (len+1));
442 ReadCatalog(MC_LOG_SET,MC_LOG_GET_RSC,MC_DEF_LOG_GET_RSC));
445 strncpy (new_string, string, len);
446 new_string[len] = '\0';
447 *(valuep) = new_string;
451 strncpy (str_buf, string, sizeof (str_buf));
452 str_buf[sizeof (str_buf)-1] = '\0';
453 *((int *) valuep) = atoi (str_buf);
456 strncpy (str_buf, string, sizeof (str_buf));
457 str_buf[sizeof (str_buf)-1] = '\0';
458 XmuCopyISOLatin1Lowered (str_buf, str_buf);
459 if (!strcmp (str_buf, "true") ||
460 !strcmp (str_buf, "on") ||
461 !strcmp (str_buf, "yes"))
462 *((int *) valuep) = 1;
463 else if (!strcmp (str_buf, "false") ||
464 !strcmp (str_buf, "off") ||
465 !strcmp (str_buf, "no"))
466 *((int *) valuep) = 0;
469 *((char ***) valuep) = parseArgs ((char **) 0, string);
477 XrmOptionDescRec configTable [] = {
478 {"-server", NULL, XrmoptionSkipArg, (caddr_t) NULL },
479 {"-udpPort", NULL, XrmoptionSkipArg, (caddr_t) NULL },
480 {"-error", NULL, XrmoptionSkipArg, (caddr_t) NULL },
481 {"-resources", NULL, XrmoptionSkipArg, (caddr_t) NULL },
482 {"-session", NULL, XrmoptionSkipArg, (caddr_t) NULL },
483 {"-debug", NULL, XrmoptionSkipArg, (caddr_t) NULL },
484 {"-xrm", NULL, XrmoptionSkipArg, (caddr_t) NULL },
485 {"-config", ".configFile", XrmoptionSepArg, (caddr_t) NULL }
488 XrmOptionDescRec optionTable [] = {
489 {"-server", ".servers", XrmoptionSepArg, (caddr_t) NULL },
490 {"-udpPort", ".requestPort", XrmoptionSepArg, (caddr_t) NULL },
491 {"-error", ".errorLogFile", XrmoptionSepArg, (caddr_t) NULL },
492 {"-resources", "*resources", XrmoptionSepArg, (caddr_t) NULL },
493 {"-session", "*session", XrmoptionSepArg, (caddr_t) NULL },
494 {"-debug", "*debugLevel", XrmoptionSepArg, (caddr_t) NULL },
495 {"-xrm", NULL, XrmoptionResArg, (caddr_t) NULL },
496 {"-daemon", ".daemonMode", XrmoptionNoArg, "true" },
497 {"-nodaemon", ".daemonMode", XrmoptionNoArg, "false" },
498 {"-quiet", ".quiet", XrmoptionNoArg, "true" }
501 static int originalArgc;
502 static char **originalArgv;
505 InitResources( int argc, char **argv )
514 ReinitResources( void )
520 char * configFileName;
524 argv = (char **) malloc ((originalArgc + 1) * sizeof (char *));
527 ReadCatalog(MC_LOG_SET,MC_LOG_NO_SPACE,MC_DEF_LOG_NO_SPACE));
528 for (argc = 0; argc < originalArgc; argc++)
529 argv[argc] = originalArgv[argc];
532 XrmDestroyDatabase (DmResourceDB);
533 DmResourceDB = XrmGetStringDatabase ("");
534 /* pre-parse the command line to get the -config option, if any */
535 XrmParseCommand (&DmResourceDB, configTable,
536 sizeof (configTable) / sizeof (configTable[0]),
537 "Dtlogin", &argc, argv);
539 configFileName = qualifyWithFirst(DEF_XDM_CONFIG,
540 CDE_CONFIGURATION_TOP "/config:"
541 CDE_INSTALLATION_TOP "/config");
543 GetResource ("Dtlogin.configFile", "Dtlogin.ConfigFile",
544 DM_STRING, &config, configFileName);
546 free(configFileName);
550 newDB = XrmGetFileDatabase ( config );
555 XrmDestroyDatabase (DmResourceDB);
556 DmResourceDB = newDB;
558 else if (argc != originalArgc)
560 ReadCatalog(MC_LOG_SET,MC_LOG_NO_OPENCFG,MC_DEF_LOG_NO_OPENCFG),
566 * scan the resource database to set the application name...
570 XrmParseCommand (&DmResourceDB, optionTable,
571 sizeof (optionTable) / sizeof (optionTable[0]),
572 AppName, &argc, argv);
575 * test to see if the session variable is set.
576 * for enabling the toggle in the options menu, if it is set..
578 if((XrmGetResource (DmResourceDB, "Dtlogin*session", "Dtlogin*Session", &type, &value)) == True)
583 LogError(ReadCatalog(MC_LOG_SET,MC_LOG_EXTRA_ARG,MC_DEF_LOG_EXTRA_ARG));
584 for (a = argv + 1; *a; a++)
585 LogError ((unsigned char *)" \"%s\"", *a);
586 LogError ((unsigned char *)"\n");
592 LoadDMResources( void )
595 char name[1024], class[1024];
598 if (servers) {free(servers); servers=NULL;}
599 if (keyFile) {free(keyFile); keyFile=NULL;}
600 if (accessFile) {free(accessFile); accessFile=NULL;}
602 for (i = 0; i < NUM_DM_RESOURCES; i++) {
603 sprintf (name, "%s.%s", AppName, DmResources[i].name);
604 sprintf (class, "%s.%s", AppName, DmResources[i].class);
605 GetResource (name, class, DmResources[i].type,
606 (char **) DmResources[i].dm_value,
607 DmResources[i].default_value);
610 servers = getFullFileName(servers, 1, NULL);
611 keyFile = getFullFileName(keyFile, 0, NULL);
612 accessFile = getFullFileName(accessFile, 0, NULL);
614 /* set a TZ default */
615 if (timeZone == NULL || strlen(timeZone) == 0)
618 * dynamically determine the timeZone resource default value...
620 GetSysParms(&timeZone,0,0);
626 CleanUpName( char *src, char *dst, int len )
646 LoadDisplayResources( struct display *d )
649 char name[1024], class[1024];
650 char dpyName[512], dpyClass[512];
653 Debug("Loading display resources for %s\n", d->name);
655 if (d->resources) {free(d->resources); d->resources=NULL;}
656 if (d->setup) {free(d->setup); d->setup=NULL;}
657 if (d->startup) {free(d->startup); d->startup=NULL;}
658 if (d->reset) {free(d->reset); d->reset=NULL;}
659 if (d->session) {free(d->session); d->session=NULL;}
660 if (d->failsafeClient) {free(d->failsafeClient); d->failsafeClient=NULL;}
662 CleanUpName (d->name, dpyName, sizeof (dpyName));
663 CleanUpName (d->class ? d->class : d->name, dpyClass, sizeof (dpyClass));
665 if((lang = getenv("LANG")) != NULL)
666 for (i = NUM_DISPLAY_RESOURCES - 1; i >= 0; i--) {
667 if(strcmp(DisplayResources[i].name,"language") == 0){
668 DisplayResources[i].default_value = lang;
674 for (i = 0; i < NUM_DISPLAY_RESOURCES; i++) {
675 sprintf (name, "%s.%s.%s", AppName,
676 dpyName, DisplayResources[i].name);
677 sprintf (class, "%s.%s.%s", AppName,
678 dpyClass, DisplayResources[i].class);
679 GetResource (name, class, DisplayResources[i].type,
680 (char **) (((char *) d) + DisplayResources[i].offset), DisplayResources[i].default_value);
684 if(d->language == NULL || strlen(d->language) == 0)
685 SetDefaultLanguage(d);
688 d->resources = getFullFileName(d->resources, 2, d->language);
689 d->setup = getFullFileName(d->setup, 0, NULL);
690 d->startup = getFullFileName(d->startup, 0, NULL);
691 d->reset = getFullFileName(d->reset, 0, NULL);
692 d->session = getFullFileName(d->session, 0, NULL);
693 d->failsafeClient = getFullFileName(d->failsafeClient, 0, NULL);
699 /***************************************************************************
703 * Probe the resource database to see whether the config file is using
704 * "Dtlogin" or "DisplayManager" as the application name.
706 * If it cannot be determined, "Dtlogin" is used.
707 ***************************************************************************/
713 char name[1024], class[1024];
717 for (i = 0; i < NUM_DM_RESOURCES; i++) {
720 * try "Dtlogin" (default) ...
723 sprintf (name, "%s.%s", DTLOGIN, DmResources[i].name);
724 sprintf (class, "%s.%s", DTLOGIN, DmResources[i].class);
726 if (DmResourceDB && XrmGetResource (DmResourceDB, name, class,
729 strcpy(AppName, DTLOGIN);
735 * try "DisplayManager" ...
738 sprintf (name, "%s.%s", DISPLAYMANAGER, DmResources[i].name);
739 sprintf (class, "%s.%s", DISPLAYMANAGER, DmResources[i].class);
741 if (DmResourceDB && XrmGetResource (DmResourceDB, name, class,
744 strcpy(AppName, DISPLAYMANAGER);
752 /***************************************************************************
756 * Try to produce a fully qualified file name by prepending
757 * /etc/dt/config or /usr/dt/config to a resource file name.
758 * There are 2 special cases: servers - which can be a command, and
759 * resources - which can an imbeded %L.
760 ***************************************************************************/
761 extern char *_ExpandLang( char *string, char *lang );
764 getFullFileName(char *name, int special, char *lang)
772 /** if the file already starts with a '/' **/
773 /** then just return a copy of it **/
774 if (name[0] == '/') {
775 if ((newname = (char *)malloc((strlen(name)+1)*sizeof(char))) == NULL) {
778 strcpy(newname, name);
784 /*********************/
785 case 0: /** no special case **/
786 /*********************/
787 newname = qualifyWithFirst(name,
788 CDE_CONFIGURATION_TOP "/config:"
789 CDE_INSTALLATION_TOP "/config");
792 /***************************************/
793 case 1: /** special handling for servers file **/
794 /***************************************/
795 if (strchr(name, ':') != NULL) {
796 /** This is probably a command and not a file name **/
797 /** so just return a copy of it. **/
798 if ((newname = (char *)malloc((strlen(name)+1)*sizeof(char)))
802 strcpy(newname, name);
806 newname = qualifyWithFirst(name,
807 CDE_CONFIGURATION_TOP "/config:"
808 CDE_INSTALLATION_TOP "/config");
812 /********************************************/
813 case 2: /** special handling for d->resources file **/
814 /********************************************/
815 if (strchr(name, '%') == NULL) {
816 /** no special processing needed **/
817 newname = qualifyWithFirst(name,
818 CDE_CONFIGURATION_TOP "/config:"
819 CDE_INSTALLATION_TOP "/config");
826 /** need to remember the %L **/
829 langString = _ExpandLang(name, lang);
830 if ( (tempName = qualifyWithFirst(langString,
831 CDE_CONFIGURATION_TOP "/config:"
832 CDE_INSTALLATION_TOP "/config") )
835 langString = _ExpandLang(name, "C");
836 if ( (tempName = qualifyWithFirst(langString,
837 CDE_CONFIGURATION_TOP "/config:"
838 CDE_INSTALLATION_TOP "/config") )
844 /** We have a fully qualified and expanded file name **/
845 /** but we need to return a fully qualified but NOT **/
846 /** expanded file name. **/
847 tempLen = strlen(tempName) - strlen(langString)
849 if ((newname = (char *)malloc(tempLen * sizeof(char))) == NULL){
853 tempLen = strlen(tempName) - strlen(langString);
854 strncpy(newname, tempName, tempLen);
855 strcpy(newname+tempLen, name);
863 /* special is of an unknown value */