1 /* $TOG: resource.c /main/7 1997/03/14 13:45:09 barstow $ */
2 /* (c) Copyright 1997 The Open Group */
4 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
5 * (c) Copyright 1993, 1994 International Business Machines Corp. *
6 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
7 * (c) Copyright 1993, 1994 Novell, Inc. *
10 * xdm - display manager daemon
12 * Copyright 1988 Massachusetts Institute of Technology
14 * Permission to use, copy, modify, and distribute this software and its
15 * documentation for any purpose and without fee is hereby granted, provided
16 * that the above copyright notice appear in all copies and that both that
17 * copyright notice and this permission notice appear in supporting
18 * documentation, and that the name of M.I.T. not be used in advertising or
19 * publicity pertaining to distribution of the software without specific,
20 * written prior permission. M.I.T. makes no representations about the
21 * suitability of this software for any purpose. It is provided "as is"
22 * without express or implied warranty.
24 * Author: Keith Packard, MIT X Consortium
33 # include <X11/Xresource.h>
34 # include <X11/Xmu/CharSet.h>
38 void CleanUpName( char *src, char *dst, int len) ;
39 static char * getFullFileName(char *name, int special, char * lang);
40 extern char * qualifyWithFirst(char *, char *);
42 /* XtOffset() hack for ibmrt BandAidCompiler */
44 int session_set = False;
60 char **exportList; /* List of all export env vars */
67 #ifdef DEF_NETWORK_DEV
75 * Dtlogin will accept both Dtlogin and XDM resources. The string variable
76 * "AppName" contains the proper application name to use in looking up
80 # define DISPLAYMANAGER "DisplayManager"
81 # define DTLOGIN "Dtlogin"
83 static char AppName[16] = DTLOGIN;
92 # define DEF_XDM_CONFIG CDE_INSTALLATION_TOP "/lib/X11/Dtlogin/Xconfig"
93 # define DEF_AUTH_DIR CDE_INSTALLATION_TOP "/lib/X11/Dtlogin"
94 # define DEF_KEY_FILE CDE_INSTALLATION_TOP "/lib/X11/Dtlogin/Xkeys"
99 * the following constants are supposed to be set in the makefile from
100 * parameters set util/imake.includes/site.def (or *.macros in that directory
101 * if it is server-specific). DO NOT CHANGE THESE DEFINITIONS!
103 #ifndef DEF_SERVER_LINE
105 #define DEF_SERVER_LINE ":0 local /usr/openwin/bin/X :0"
107 #define DEF_SERVER_LINE ":0 local /usr/bin/X11/X :0"
112 #define XRDB_PROGRAM "/usr/openwin/bin/xrdb"
114 #define XRDB_PROGRAM "/usr/bin/X11/xrdb"
118 #define DEF_SESSION CDE_INSTALLATION_TOP "/bin/Xsession"
121 #ifndef DEF_USER_PATH
123 # define DEF_USER_PATH "/usr/openwin/bin:/bin:/usr/bin:/usr/contrib/bin:/usr/local/bin:."
125 # define DEF_USER_PATH "/usr/bin/X11:/bin:/usr/bin:/usr/contrib/bin:/usr/local/bin"
129 #ifndef DEF_SYSTEM_PATH
131 # define DEF_SYSTEM_PATH "/usr/openwin/bin:/etc:/bin:/usr/bin"
133 # define DEF_SYSTEM_PATH "/usr/bin/X11:/etc:/bin:/usr/bin"
137 #ifndef DEF_SYSTEM_SHELL
138 #define DEF_SYSTEM_SHELL "/bin/sh"
141 #ifndef DEF_FAILSAFE_CLIENT
143 #define DEF_FAILSAFE_CLIENT "/usr/openwin/bin/xterm"
145 #define DEF_FAILSAFE_CLIENT "/usr/bin/X11/xterm"
149 #ifndef DEF_XDM_CONFIG
150 #define DEF_XDM_CONFIG "Xconfig"
154 #define DEF_CHOOSER CDE_INSTALLATION_TOP "/bin/chooser"
158 #define CPP_PROGRAM "/lib/cpp"
160 #ifndef DEF_XDM_AUTH_GEN
161 #define DEF_XDM_AUTH_GEN CDE_CONFIGURATION_TOP "/xdmauthgen"
163 #ifndef DEF_AUTH_NAME
164 #define DEF_AUTH_NAME "MIT-MAGIC-COOKIE-1"
167 #define DEF_AUTH_DIR CDE_CONFIGURATION_TOP
169 #ifndef DEF_USER_AUTH_DIR
170 #define DEF_USER_AUTH_DIR "/tmp"
173 #define DEF_KEY_FILE CDE_CONFIGURATION_TOP "/Xkeys"
175 #ifndef DEF_ACCESS_FILE
176 #define DEF_ACCESS_FILE ""
179 #define DEF_TIMEZONE "MST7MDT"
181 #ifndef DEF_SYS_PARMS_FILE
182 # if defined( __hpux )
183 # define DEF_SYS_PARMS_FILE "/etc/src.sh"
185 # define DEF_SYS_PARMS_FILE "/etc/TIMEZONE"
188 #define DEF_UDP_PORT "177" /* registered XDMCP port, don't change */
191 # ifdef sun /* need to set the environment for Sun OpenWindows */
192 # define DEF_ENV "OPENWINHOME=/usr/openwin"
198 #ifndef DEF_LANG /* LANG default settings for various architectures */
200 # define DEF_LANG "C"
203 # define DEF_LANG "C"
206 # define DEF_LANG "en_US.88591"
208 # ifdef sun /* default language under Solaris */
209 # define DEF_LANG "C"
213 #ifndef DEF_LANG /* set LANG to NULL if not already defined */
223 "servers", "Servers", DM_STRING, &servers,
225 "requestPort", "RequestPort", DM_INT, (char **) &request_port,
227 "debugLevel", "DebugLevel", DM_INT, (char **) &debugLevel,
229 "errorLogFile", "ErrorLogFile", DM_STRING, &errorLogFile,
231 "errorLogSize", "ErrorLogSize", DM_INT, (char **) &errorLogSize,
233 "daemonMode", "DaemonMode", DM_BOOL, (char **) &daemonMode,
235 "pidFile", "PidFile", DM_STRING, &pidFile,
237 "lockPidFile", "LockPidFile", DM_BOOL, (char **) &lockPidFile,
239 "authDir", "AuthDir", DM_STRING, &authDir,
241 "autoRescan", "AutoRescan", DM_BOOL, (char **) &autoRescan,
243 "removeDomainname","RemoveDomainname",DM_BOOL, (char **) &removeDomainname,
245 "keyFile", "KeyFile", DM_STRING, &keyFile,
247 "accessFile", "AccessFile", DM_STRING, &accessFile,
249 /* exportList env var resource RK 08.17.93 */
250 "exportList", "ExportList", DM_ARGV, (char **) &exportList,
252 "timeZone", "TimeZone", DM_STRING, &timeZone,
254 "fontPathHead", "FontPathHead", DM_STRING, &fpHead,
256 "fontPathTail", "FontPathTail", DM_STRING, &fpTail,
258 "sysParmsFile", "SysParmsFile", DM_STRING, &sysParmsFile,
260 "wakeupInterval","WakeupInterval",DM_INT, (char **) &wakeupInterval,
262 "langListTimeout","langListTimeout",DM_INT, (char **) &langListTimeout,
264 #ifdef DEF_NETWORK_DEV
265 "networkDevice","NetworkDevice",DM_STRING, &networkDev,
269 "ignoreLocales", "IgnoreLocales", DM_STRING, &ignoreLocales,
274 # define NUM_DM_RESOURCES (sizeof DmResources / sizeof DmResources[0])
276 # define boffset(f) ((char *) &(((struct display *) 0)->f) - (char *) 0)
278 struct displayResources {
283 } DisplayResources[] = {
287 * resources for managing the server...
290 "serverAttempts","ServerAttempts", DM_INT, boffset(serverAttempts),
292 "openDelay", "OpenDelay", DM_INT, boffset(openDelay),
294 "openRepeat", "OpenRepeat", DM_INT, boffset(openRepeat),
296 "openTimeout", "OpenTimeout", DM_INT, boffset(openTimeout),
298 "startAttempts","StartAttempts",DM_INT, boffset(startAttempts),
300 "pingInterval", "PingInterval", DM_INT, boffset(pingInterval),
302 "pingTimeout", "PingTimeout", DM_INT, boffset(pingTimeout),
304 "terminateServer","TerminateServer",DM_BOOL, boffset(terminateServer),
306 "grabServer", "GrabServer", DM_BOOL, boffset(grabServer),
308 "grabTimeout", "GrabTimeout", DM_INT, boffset(grabTimeout),
310 "resetSignal", "Signal", DM_INT, boffset(resetSignal),
312 "termSignal", "Signal", DM_INT, boffset(termSignal),
314 "resetForAuth", "ResetForAuth", DM_BOOL, boffset(resetForAuth),
316 "authorize", "Authorize", DM_BOOL, boffset(authorize),
318 "authName", "AuthName", DM_ARGV, boffset(authNames),
320 "authFile", "AuthFile", DM_STRING, boffset(authFile),
323 "gettyLine", "GettyLine", DM_STRING, boffset(gettyLine),
325 "gettySpeed", "GettySpeed", DM_STRING, boffset(gettySpeed),
329 * resources which control the session behavior...
332 "resources", "Resources", DM_STRING, boffset(resources),
334 "xrdb", "Xrdb", DM_STRING, boffset(xrdb),
336 "cpp", "Cpp", DM_STRING, boffset(cpp),
338 "setup", "Setup", DM_STRING, boffset(setup),
340 "startup", "Startup", DM_STRING, boffset(startup),
342 "reset", "Reset", DM_STRING, boffset(reset),
344 "session", "Session", DM_STRING, boffset(session),
346 "userPath", "Path", DM_STRING, boffset(userPath),
348 "systemPath", "Path", DM_STRING, boffset(systemPath),
350 "systemShell", "Shell", DM_STRING, boffset(systemShell),
352 "failsafeClient","FailsafeClient", DM_STRING, boffset(failsafeClient),
354 "userAuthDir", "UserAuthDir", DM_STRING, boffset(userAuthDir),
356 "chooser", "Chooser", DM_STRING, boffset(chooser),
358 "language", "Language", DM_STRING, boffset(language),
360 "languageList", "LanguageList", DM_STRING, boffset(langList),
362 "environment", "Environment", DM_STRING, boffset(environStr),
364 "dtlite", "Dtlite", DM_BOOL, boffset(dtlite),
366 "xdmMode", "XdmMode", DM_BOOL, boffset(xdmMode),
368 "authenticationName","AuthenticationName", DM_STRING, boffset(verifyName),
370 "pmSearchPath", "PmSearchPath", DM_STRING, boffset(pmSearchPath),
372 "bmSearchPath", "bmSearchPath", DM_STRING, boffset(bmSearchPath),
376 # define NUM_DISPLAY_RESOURCES (sizeof DisplayResources/sizeof DisplayResources[0])
378 XrmDatabase DmResourceDB;
381 GetResource( char *name, char *class, int valueType, char **valuep,
382 char *default_value )
386 char *string, *new_string;
391 if (DmResourceDB && XrmGetResource (DmResourceDB,
400 string = default_value;
401 len = (string == NULL ? 0 : strlen (string));
404 Debug ("%s/%s value %*.*s\n", name, class, len, len, string);
408 * check if new resource is the same as old...
411 if (valueType == DM_STRING && *valuep) {
412 if (string != NULL && strlen (*valuep) == len && !strncmp (*valuep, string, len))
424 new_string = malloc ((unsigned) (len+1));
427 ReadCatalog(MC_LOG_SET,MC_LOG_GET_RSC,MC_DEF_LOG_GET_RSC));
430 strncpy (new_string, string, len);
431 new_string[len] = '\0';
432 *(valuep) = new_string;
436 strncpy (str_buf, string, sizeof (str_buf));
437 str_buf[sizeof (str_buf)-1] = '\0';
438 *((int *) valuep) = atoi (str_buf);
441 strncpy (str_buf, string, sizeof (str_buf));
442 str_buf[sizeof (str_buf)-1] = '\0';
443 XmuCopyISOLatin1Lowered (str_buf, str_buf);
444 if (!strcmp (str_buf, "true") ||
445 !strcmp (str_buf, "on") ||
446 !strcmp (str_buf, "yes"))
447 *((int *) valuep) = 1;
448 else if (!strcmp (str_buf, "false") ||
449 !strcmp (str_buf, "off") ||
450 !strcmp (str_buf, "no"))
451 *((int *) valuep) = 0;
454 *((char ***) valuep) = parseArgs ((char **) 0, string);
460 XrmOptionDescRec configTable [] = {
461 {"-server", NULL, XrmoptionSkipArg, (caddr_t) NULL },
462 {"-udpPort", NULL, XrmoptionSkipArg, (caddr_t) NULL },
463 {"-error", NULL, XrmoptionSkipArg, (caddr_t) NULL },
464 {"-resources", NULL, XrmoptionSkipArg, (caddr_t) NULL },
465 {"-session", NULL, XrmoptionSkipArg, (caddr_t) NULL },
466 {"-debug", NULL, XrmoptionSkipArg, (caddr_t) NULL },
467 {"-xrm", NULL, XrmoptionSkipArg, (caddr_t) NULL },
468 {"-config", ".configFile", XrmoptionSepArg, (caddr_t) NULL }
471 XrmOptionDescRec optionTable [] = {
472 {"-server", ".servers", XrmoptionSepArg, (caddr_t) NULL },
473 {"-udpPort", ".requestPort", XrmoptionSepArg, (caddr_t) NULL },
474 {"-error", ".errorLogFile", XrmoptionSepArg, (caddr_t) NULL },
475 {"-resources", "*resources", XrmoptionSepArg, (caddr_t) NULL },
476 {"-session", "*session", XrmoptionSepArg, (caddr_t) NULL },
477 {"-debug", "*debugLevel", XrmoptionSepArg, (caddr_t) NULL },
478 {"-xrm", NULL, XrmoptionResArg, (caddr_t) NULL },
479 {"-daemon", ".daemonMode", XrmoptionNoArg, "true" },
480 {"-nodaemon", ".daemonMode", XrmoptionNoArg, "false" }
483 static int originalArgc;
484 static char **originalArgv;
487 InitResources( int argc, char **argv )
496 ReinitResources( void )
502 char * configFileName;
506 argv = (char **) malloc ((originalArgc + 1) * sizeof (char *));
509 ReadCatalog(MC_LOG_SET,MC_LOG_NO_SPACE,MC_DEF_LOG_NO_SPACE));
510 for (argc = 0; argc < originalArgc; argc++)
511 argv[argc] = originalArgv[argc];
514 XrmDestroyDatabase (DmResourceDB);
515 DmResourceDB = XrmGetStringDatabase ("");
516 /* pre-parse the command line to get the -config option, if any */
517 XrmParseCommand (&DmResourceDB, configTable,
518 sizeof (configTable) / sizeof (configTable[0]),
519 "Dtlogin", &argc, argv);
521 configFileName = qualifyWithFirst(DEF_XDM_CONFIG,
522 CDE_CONFIGURATION_TOP "/config:"
523 CDE_INSTALLATION_TOP "/config");
525 GetResource ("Dtlogin.configFile", "Dtlogin.ConfigFile",
526 DM_STRING, &config, configFileName);
528 free(configFileName);
532 newDB = XrmGetFileDatabase ( config );
537 XrmDestroyDatabase (DmResourceDB);
538 DmResourceDB = newDB;
540 else if (argc != originalArgc)
542 ReadCatalog(MC_LOG_SET,MC_LOG_NO_OPENCFG,MC_DEF_LOG_NO_OPENCFG),
548 * scan the resource database to set the application name...
552 XrmParseCommand (&DmResourceDB, optionTable,
553 sizeof (optionTable) / sizeof (optionTable[0]),
554 AppName, &argc, argv);
557 * test to see if the session variable is set.
558 * for enabling the toggle in the options menu, if it is set..
560 if((XrmGetResource (DmResourceDB, "Dtlogin*session", "Dtlogin*Session", &type, &value)) == True)
565 LogError(ReadCatalog(MC_LOG_SET,MC_LOG_EXTRA_ARG,MC_DEF_LOG_EXTRA_ARG));
566 for (a = argv + 1; *a; a++)
567 LogError ((unsigned char *)" \"%s\"", *a);
568 LogError ((unsigned char *)"\n");
574 LoadDMResources( void )
577 char name[1024], class[1024];
580 if (servers) {free(servers); servers=NULL;}
581 if (keyFile) {free(keyFile); keyFile=NULL;}
582 if (accessFile) {free(accessFile); accessFile=NULL;}
584 for (i = 0; i < NUM_DM_RESOURCES; i++) {
585 sprintf (name, "%s.%s", AppName, DmResources[i].name);
586 sprintf (class, "%s.%s", AppName, DmResources[i].class);
587 GetResource (name, class, DmResources[i].type,
588 (char **) DmResources[i].dm_value,
589 DmResources[i].default_value);
592 servers = getFullFileName(servers, 1, NULL);
593 keyFile = getFullFileName(keyFile, 0, NULL);
594 accessFile = getFullFileName(accessFile, 0, NULL);
596 #ifndef __apollo /* set a TZ default for all OS except Domain */
597 if (timeZone == NULL || strlen(timeZone) == 0)
600 * dynamically determine the timeZone resource default value...
602 GetSysParms(&timeZone,0,0);
609 CleanUpName( char *src, char *dst, int len )
629 LoadDisplayResources( struct display *d )
632 char name[1024], class[1024];
633 char dpyName[512], dpyClass[512];
636 Debug("Loading display resources for %s\n", d->name);
638 if (d->resources) {free(d->resources); d->resources=NULL;}
639 if (d->setup) {free(d->setup); d->setup=NULL;}
640 if (d->startup) {free(d->startup); d->startup=NULL;}
641 if (d->reset) {free(d->reset); d->reset=NULL;}
642 if (d->session) {free(d->session); d->session=NULL;}
643 if (d->failsafeClient) {free(d->failsafeClient); d->failsafeClient=NULL;}
645 CleanUpName (d->name, dpyName, sizeof (dpyName));
646 CleanUpName (d->class ? d->class : d->name, dpyClass, sizeof (dpyClass));
648 if((lang = getenv("LANG")) != NULL)
649 for (i = NUM_DISPLAY_RESOURCES - 1; i >= 0; i--) {
650 if(strcmp(DisplayResources[i].name,"language") == 0){
651 DisplayResources[i].default_value = lang;
657 for (i = 0; i < NUM_DISPLAY_RESOURCES; i++) {
658 sprintf (name, "%s.%s.%s", AppName,
659 dpyName, DisplayResources[i].name);
660 sprintf (class, "%s.%s.%s", AppName,
661 dpyClass, DisplayResources[i].class);
662 GetResource (name, class, DisplayResources[i].type,
663 (char **) (((char *) d) + DisplayResources[i].offset), DisplayResources[i].default_value);
667 if(d->language == NULL || strlen(d->language) == 0)
668 SetDefaultLanguage(d);
671 d->resources = getFullFileName(d->resources, 2, d->language);
672 d->setup = getFullFileName(d->setup, 0, NULL);
673 d->startup = getFullFileName(d->startup, 0, NULL);
674 d->reset = getFullFileName(d->reset, 0, NULL);
675 d->session = getFullFileName(d->session, 0, NULL);
676 d->failsafeClient = getFullFileName(d->failsafeClient, 0, NULL);
682 /***************************************************************************
686 * Probe the resource database to see whether the config file is using
687 * "Dtlogin" or "DisplayManager" as the application name.
689 * If it cannot be determined, "Dtlogin" is used.
690 ***************************************************************************/
696 char name[1024], class[1024];
700 for (i = 0; i < NUM_DM_RESOURCES; i++) {
703 * try "Dtlogin" (default) ...
706 sprintf (name, "%s.%s", DTLOGIN, DmResources[i].name);
707 sprintf (class, "%s.%s", DTLOGIN, DmResources[i].class);
709 if (DmResourceDB && XrmGetResource (DmResourceDB, name, class,
712 strcpy(AppName, DTLOGIN);
718 * try "DisplayManager" ...
721 sprintf (name, "%s.%s", DISPLAYMANAGER, DmResources[i].name);
722 sprintf (class, "%s.%s", DISPLAYMANAGER, DmResources[i].class);
724 if (DmResourceDB && XrmGetResource (DmResourceDB, name, class,
727 strcpy(AppName, DISPLAYMANAGER);
735 /***************************************************************************
739 * Try to produce a fully qualified file name by prepending
740 * /etc/dt/config or /usr/dt/config to a resource file name.
741 * There are 2 special cases: servers - which can be a command, and
742 * resources - which can an imbeded %L.
743 ***************************************************************************/
744 extern char *_ExpandLang( char *string, char *lang );
747 getFullFileName(char *name, int special, char *lang)
755 /** if the file already starts with a '/' **/
756 /** then just return a copy of it **/
757 if (name[0] == '/') {
758 if ((newname = (char *)malloc((strlen(name)+1)*sizeof(char))) == NULL) {
761 strcpy(newname, name);
767 /*********************/
768 case 0: /** no special case **/
769 /*********************/
770 newname = qualifyWithFirst(name,
771 CDE_CONFIGURATION_TOP "/config:"
772 CDE_INSTALLATION_TOP "/config");
775 /***************************************/
776 case 1: /** special handling for servers file **/
777 /***************************************/
778 if (strchr(name, ':') != NULL) {
779 /** This is probably a command and not a file name **/
780 /** so just return a copy of it. **/
781 if ((newname = (char *)malloc((strlen(name)+1)*sizeof(char)))
785 strcpy(newname, name);
789 newname = qualifyWithFirst(name,
790 CDE_CONFIGURATION_TOP "/config:"
791 CDE_INSTALLATION_TOP "/config");
795 /********************************************/
796 case 2: /** special handling for d->resources file **/
797 /********************************************/
798 if (strchr(name, '%') == NULL) {
799 /** no special processing needed **/
800 newname = qualifyWithFirst(name,
801 CDE_CONFIGURATION_TOP "/config:"
802 CDE_INSTALLATION_TOP "/config");
809 /** need to remember the %L **/
812 langString = _ExpandLang(name, lang);
813 if ( (tempName = qualifyWithFirst(langString,
814 CDE_CONFIGURATION_TOP "/config:"
815 CDE_INSTALLATION_TOP "/config") )
818 langString = _ExpandLang(name, "C");
819 if ( (tempName = qualifyWithFirst(langString,
820 CDE_CONFIGURATION_TOP "/config:"
821 CDE_INSTALLATION_TOP "/config") )
827 /** We have a fully qualified and expanded file name **/
828 /** but we need to return a fully qualified but NOT **/
829 /** expanded file name. **/
830 tempLen = strlen(tempName) - strlen(langString)
832 if ((newname = (char *)malloc(tempLen * sizeof(char))) == NULL){
836 tempLen = strlen(tempName) - strlen(langString);
837 strncpy(newname, tempName, tempLen);
838 strcpy(newname+tempLen, name);