Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtlogin / resource.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
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
22  */
23 /* $TOG: resource.c /main/7 1997/03/14 13:45:09 barstow $ */
24 /* (c) Copyright 1997 The Open Group */
25 /*                                                                      *
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.                                *
30  */
31 /*
32  * xdm - display manager daemon
33  *
34  * Copyright 1988 Massachusetts Institute of Technology
35  *
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.
45  *
46  * Author:  Keith Packard, MIT X Consortium
47  */
48
49 /*
50  * resource.c
51  */
52
53 # include "dm.h"
54 # include "vgmsg.h"
55 # include <X11/Xresource.h>
56 # include <X11/Xmu/CharSet.h>
57 # include <string.h>
58
59
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 *);
63
64 /* XtOffset() hack for ibmrt BandAidCompiler */
65
66 int session_set = False;
67 char    *config;
68
69 char    *servers;
70 int     request_port;
71 int     debugLevel;
72 char    *errorLogFile;
73 int     errorLogSize;
74 int     daemonMode;
75 char    *pidFile;
76 int     lockPidFile;
77 char    *authDir;
78 int     autoRescan;
79 int     removeDomainname;
80 char    *keyFile;
81 char    *accessFile;
82 char    **exportList;    /* List of all export env vars */
83 char    *sysParmsFile;
84 char    *timeZone;
85 char    *fpHead = NULL;
86 char    *fpTail = NULL;
87 int     wakeupInterval;
88 int     langListTimeout;
89 #ifdef DEF_NETWORK_DEV
90 char    *networkDev;
91 #endif
92 #if defined(__osf__)
93 char    *ignoreLocales;
94 #endif
95
96 /*
97  * Dtlogin will accept both Dtlogin and XDM resources. The string variable
98  * "AppName" contains the proper application name to use in looking up
99  * resources.
100  */
101
102 # define DISPLAYMANAGER     "DisplayManager"
103 # define DTLOGIN            "Dtlogin"
104
105 static  char    AppName[16] = DTLOGIN;
106
107
108 # define DM_STRING      0
109 # define DM_INT         1
110 # define DM_BOOL        2
111 # define DM_ARGV        3
112
113 #ifdef BLS
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"
117 #endif
118
119
120 /*
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!
124  */
125 #ifndef DEF_SERVER_LINE 
126 #  ifdef sun 
127 #define DEF_SERVER_LINE ":0 local /usr/openwin/bin/X :0"
128 #  else
129 #define DEF_SERVER_LINE ":0 local /usr/bin/X11/X :0"
130 #  endif /* sun */
131 #endif
132 #ifndef XRDB_PROGRAM
133 #  ifdef sun 
134 #define XRDB_PROGRAM "/usr/openwin/bin/xrdb"
135 #  else
136 #define XRDB_PROGRAM "/usr/bin/X11/xrdb"
137 #  endif /* sun */
138 #endif
139 #ifndef DEF_SESSION
140 #define DEF_SESSION CDE_INSTALLATION_TOP "/bin/Xsession"
141 #endif
142
143 #ifndef DEF_USER_PATH
144 #  ifdef sun 
145 #    define DEF_USER_PATH "/usr/openwin/bin:/bin:/usr/bin:/usr/contrib/bin:/usr/local/bin:."
146 #  else
147 #    define DEF_USER_PATH "/usr/bin/X11:/bin:/usr/bin:/usr/contrib/bin:/usr/local/bin"
148 #  endif /* sun */
149 #endif
150
151 #ifndef DEF_SYSTEM_PATH
152 #  ifdef sun 
153 #    define DEF_SYSTEM_PATH "/usr/openwin/bin:/etc:/bin:/usr/bin"
154 #  else
155 #    define DEF_SYSTEM_PATH "/usr/bin/X11:/etc:/bin:/usr/bin"
156 #  endif /* sun */
157 #endif
158
159 #ifndef DEF_SYSTEM_SHELL
160 #define DEF_SYSTEM_SHELL "/bin/sh"
161 #endif
162
163 #ifndef DEF_FAILSAFE_CLIENT
164 #  ifdef sun 
165 #define DEF_FAILSAFE_CLIENT "/usr/openwin/bin/xterm"
166 #  else
167 #define DEF_FAILSAFE_CLIENT "/usr/bin/X11/xterm"
168 #  endif /* sun */
169 #endif
170
171 #ifndef DEF_XDM_CONFIG
172 #define DEF_XDM_CONFIG "Xconfig"
173 #endif
174
175 #ifndef DEF_CHOOSER
176 #define DEF_CHOOSER CDE_INSTALLATION_TOP "/bin/chooser"
177 #endif
178
179 #ifndef CPP_PROGRAM
180 #define CPP_PROGRAM "/lib/cpp"
181 #endif
182 #ifndef DEF_XDM_AUTH_GEN
183 #define DEF_XDM_AUTH_GEN CDE_CONFIGURATION_TOP "/xdmauthgen"
184 #endif
185 #ifndef DEF_AUTH_NAME
186 #define DEF_AUTH_NAME   "MIT-MAGIC-COOKIE-1"
187 #endif
188 #ifndef DEF_AUTH_DIR
189 #define DEF_AUTH_DIR CDE_CONFIGURATION_TOP
190 #endif
191 #ifndef DEF_USER_AUTH_DIR
192 #define DEF_USER_AUTH_DIR       "/tmp"
193 #endif
194 #ifndef DEF_KEY_FILE
195 #define DEF_KEY_FILE    CDE_CONFIGURATION_TOP "/Xkeys"
196 #endif
197 #ifndef DEF_ACCESS_FILE
198 #define DEF_ACCESS_FILE ""
199 #endif
200 #ifndef DEF_TIMEZONE
201 #define DEF_TIMEZONE    "MST7MDT"
202 #endif
203 #ifndef DEF_SYS_PARMS_FILE
204 #  if defined( __hpux )
205 #    define DEF_SYS_PARMS_FILE  "/etc/src.sh"
206 #  else
207 #    define DEF_SYS_PARMS_FILE  "/etc/TIMEZONE"
208 #  endif
209 #endif
210 #define DEF_UDP_PORT    "177"       /* registered XDMCP port, don't change */
211
212 #ifndef DEF_ENV
213 #  ifdef sun    /* need to set the environment for Sun OpenWindows */
214 #    define DEF_ENV     "OPENWINHOME=/usr/openwin"
215 #  else
216 #    define DEF_ENV     ""
217 #  endif
218 #endif
219
220 #ifndef DEF_LANG        /* LANG default settings for various architectures */
221 #  ifdef __apollo
222 #    define DEF_LANG    "C"
223 #  endif
224 #  ifdef __osf__
225 #    define DEF_LANG    "C"
226 #  endif
227 #  ifdef __hp_osf
228 #    define DEF_LANG    "en_US.88591"
229 #  endif
230 #  ifdef sun    /* default language under Solaris */
231 #    define DEF_LANG    "C" 
232 #  endif
233 #endif
234
235 #ifndef DEF_LANG        /* set LANG to NULL if not already defined         */
236 #define DEF_LANG        ""
237 #endif
238
239 struct dmResources {
240         char    *name, *class;
241         int     type;
242         char    **dm_value;
243         char    *default_value;
244 } DmResources[] = {
245 "servers",      "Servers",      DM_STRING,      &servers,
246                                 DEF_SERVER_LINE,
247 "requestPort",  "RequestPort",  DM_INT,         (char **) &request_port,
248                                 DEF_UDP_PORT,
249 "debugLevel",   "DebugLevel",   DM_INT,         (char **) &debugLevel,
250                                 "0",
251 "errorLogFile", "ErrorLogFile", DM_STRING,      &errorLogFile,
252                                 "",
253 "errorLogSize", "ErrorLogSize", DM_INT,         (char **) &errorLogSize,
254                                 "50",
255 "daemonMode",   "DaemonMode",   DM_BOOL,        (char **) &daemonMode,
256                                 "false",
257 "pidFile",      "PidFile",      DM_STRING,      &pidFile,
258                                 "",
259 "lockPidFile",  "LockPidFile",  DM_BOOL,        (char **) &lockPidFile,
260                                 "true",
261 "authDir",      "AuthDir",      DM_STRING,      &authDir,
262                                 DEF_AUTH_DIR,
263 "autoRescan",   "AutoRescan",   DM_BOOL,        (char **) &autoRescan,
264                                 "true",
265 "removeDomainname","RemoveDomainname",DM_BOOL,  (char **) &removeDomainname,
266                                 "true",
267 "keyFile",      "KeyFile",      DM_STRING,      &keyFile,
268                                 DEF_KEY_FILE,
269 "accessFile",   "AccessFile",   DM_STRING,      &accessFile,
270                                 DEF_ACCESS_FILE,
271 /* exportList env var resource    RK   08.17.93  */
272 "exportList",   "ExportList",   DM_ARGV,        (char **) &exportList,
273                                 "",
274 "timeZone",     "TimeZone",     DM_STRING,      &timeZone,
275                                 "",
276 "fontPathHead", "FontPathHead", DM_STRING,      &fpHead,
277                                 "",
278 "fontPathTail", "FontPathTail", DM_STRING,      &fpTail,
279                                 "",
280 "sysParmsFile", "SysParmsFile", DM_STRING,      &sysParmsFile,
281                                 DEF_SYS_PARMS_FILE,
282 "wakeupInterval","WakeupInterval",DM_INT,       (char **) &wakeupInterval,
283                                 "10",
284 "langListTimeout","langListTimeout",DM_INT,     (char **) &langListTimeout,
285                                 "30",
286 #ifdef DEF_NETWORK_DEV
287 "networkDevice","NetworkDevice",DM_STRING,      &networkDev,
288                                 DEF_NETWORK_DEV,
289 #endif
290 #if defined(__osf__)
291 "ignoreLocales", "IgnoreLocales", DM_STRING,    &ignoreLocales,
292                                 "",
293 #endif
294 };
295
296 # define NUM_DM_RESOURCES       (sizeof DmResources / sizeof DmResources[0])
297
298 # define boffset(f)     ((char *) &(((struct display *) 0)->f) - (char *) 0)
299
300 struct displayResources {
301         char    *name, *class;
302         int     type;
303         int     offset;
304         char    *default_value;
305 } DisplayResources[] = {
306
307
308 /* 
309  * resources for managing the server...
310  */
311  
312 "serverAttempts","ServerAttempts", DM_INT,      boffset(serverAttempts),
313                                 "1",
314 "openDelay",    "OpenDelay",    DM_INT,         boffset(openDelay),
315                                 "5",
316 "openRepeat",   "OpenRepeat",   DM_INT,         boffset(openRepeat),
317                                 "5",
318 "openTimeout",  "OpenTimeout",  DM_INT,         boffset(openTimeout),
319                                 "30",
320 "startAttempts","StartAttempts",DM_INT,         boffset(startAttempts),
321                                 "4",
322 "pingInterval", "PingInterval", DM_INT,         boffset(pingInterval),
323                                 "5",
324 "pingTimeout",  "PingTimeout",  DM_INT,         boffset(pingTimeout),
325                                 "5",
326 "terminateServer","TerminateServer",DM_BOOL,    boffset(terminateServer),
327                                 "false",
328 "grabServer",   "GrabServer",   DM_BOOL,        boffset(grabServer),
329                                 "true",
330 "grabTimeout",  "GrabTimeout",  DM_INT,         boffset(grabTimeout),
331                                 "3",
332 "resetSignal",  "Signal",       DM_INT,         boffset(resetSignal),
333                                 "1",    /* SIGHUP */
334 "termSignal",   "Signal",       DM_INT,         boffset(termSignal),
335                                 "15",   /* SIGTERM */
336 "resetForAuth", "ResetForAuth", DM_BOOL,        boffset(resetForAuth),
337                                 "false",
338 "authorize",    "Authorize",    DM_BOOL,        boffset(authorize),
339                                 "true",
340 "authName",     "AuthName",     DM_ARGV,        boffset(authNames),
341                                 DEF_AUTH_NAME,
342 "authFile",     "AuthFile",     DM_STRING,      boffset(authFile),
343                                 "",
344 #if 0
345 "gettyLine",    "GettyLine",    DM_STRING,      boffset(gettyLine),
346                                 "",
347 "gettySpeed",   "GettySpeed",   DM_STRING,      boffset(gettySpeed),
348                                 "9600",
349 #endif
350 /*
351  *  resources which control the session behavior...
352  */
353
354 "resources",    "Resources",    DM_STRING,      boffset(resources),
355                                 "",
356 "xrdb",         "Xrdb",         DM_STRING,      boffset(xrdb),
357                                 XRDB_PROGRAM,
358 "cpp",          "Cpp",          DM_STRING,      boffset(cpp),
359                                 CPP_PROGRAM,
360 "setup",        "Setup",        DM_STRING,      boffset(setup),
361                                 "",
362 "startup",      "Startup",      DM_STRING,      boffset(startup),
363                                 "",
364 "reset",        "Reset",        DM_STRING,      boffset(reset),
365                                 "",
366 "session",      "Session",      DM_STRING,      boffset(session),
367                                 DEF_SESSION,
368 "userPath",     "Path",         DM_STRING,      boffset(userPath),
369                                 DEF_USER_PATH,
370 "systemPath",   "Path",         DM_STRING,      boffset(systemPath),
371                                 DEF_SYSTEM_PATH,
372 "systemShell",  "Shell",        DM_STRING,      boffset(systemShell),
373                                 DEF_SYSTEM_SHELL,
374 "failsafeClient","FailsafeClient",      DM_STRING,      boffset(failsafeClient),
375                                 DEF_FAILSAFE_CLIENT,
376 "userAuthDir",  "UserAuthDir",  DM_STRING,      boffset(userAuthDir),
377                                 DEF_AUTH_DIR,
378 "chooser",      "Chooser",      DM_STRING,      boffset(chooser),
379                                 DEF_CHOOSER,
380 "language",     "Language",     DM_STRING,      boffset(language),
381                                 DEF_LANG,
382 "languageList", "LanguageList", DM_STRING,      boffset(langList),
383                                 "",
384 "environment",  "Environment",  DM_STRING,      boffset(environStr),
385                                 DEF_ENV,
386 "dtlite",       "Dtlite",       DM_BOOL,        boffset(dtlite),
387                                 "false",
388 "xdmMode",      "XdmMode",      DM_BOOL,        boffset(xdmMode),
389                                 "false",
390 "authenticationName","AuthenticationName", DM_STRING,   boffset(verifyName),
391                                 "",
392 "pmSearchPath", "PmSearchPath", DM_STRING,      boffset(pmSearchPath),
393                                 DEF_PM_SEARCH_PATH,
394 "bmSearchPath", "bmSearchPath", DM_STRING,      boffset(bmSearchPath), 
395                                 DEF_BM_SEARCH_PATH,
396 };
397
398 # define NUM_DISPLAY_RESOURCES  (sizeof DisplayResources/sizeof DisplayResources[0])
399
400 XrmDatabase     DmResourceDB;
401
402 int 
403 GetResource( char *name, char *class, int valueType, char **valuep,
404              char *default_value )
405 {
406     char        *type;
407     XrmValue    value;
408     char        *string, *new_string;
409     char        str_buf[50];
410     int len;
411
412
413     if (DmResourceDB && XrmGetResource (DmResourceDB,
414         name, class,
415         &type, &value))
416     {
417         string = value.addr;
418         len = value.size;
419     }
420     else
421     {
422         string = default_value;
423         len = (string == NULL ? 0 : strlen (string));
424     }
425
426     Debug ("%s/%s value %*.*s\n", name, class, len, len, string);
427
428
429     /*
430      *  check if new resource is the same as old...
431      */
432      
433      if (valueType == DM_STRING && *valuep) {
434         if (string != NULL && strlen (*valuep) == len && !strncmp (*valuep, string, len))
435             return;
436         else {
437             free (*valuep);
438             *(valuep) = NULL;
439         }
440      }
441  
442
443     switch (valueType) {
444     case DM_STRING:
445         if ( len > 0 ) {
446             new_string = malloc ((unsigned) (len+1));
447             if (!new_string) {
448                 LogOutOfMem(
449                   ReadCatalog(MC_LOG_SET,MC_LOG_GET_RSC,MC_DEF_LOG_GET_RSC));
450                 return;
451             }
452             strncpy (new_string, string, len);
453             new_string[len] = '\0';
454             *(valuep) = new_string;
455         }
456         break;
457     case DM_INT:
458         strncpy (str_buf, string, sizeof (str_buf));
459         str_buf[sizeof (str_buf)-1] = '\0';
460         *((int *) valuep) = atoi (str_buf);
461         break;
462     case DM_BOOL:
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;
474         break;
475     case DM_ARGV:
476         *((char ***) valuep) = parseArgs ((char **) 0, string);
477         break;
478
479     }
480 }
481
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 }
491 };
492
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"        }
503 };
504
505 static int      originalArgc;
506 static char     **originalArgv;
507
508 void 
509 InitResources( int argc, char **argv )
510 {
511         XrmInitialize ();
512         originalArgc = argc;
513         originalArgv = argv;
514         ReinitResources ();
515 }
516
517 void 
518 ReinitResources( void )
519 {
520     int argc;
521     char        **a;
522     char        **argv;
523     XrmDatabase newDB;
524     char * configFileName;
525     char        *type;
526     XrmValue    value;
527
528     argv = (char **) malloc ((originalArgc + 1) * sizeof (char *));
529     if (!argv)
530         LogOutOfMem(
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];
534     argv[argc] = 0;
535     if (DmResourceDB)
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);
542     
543     configFileName = qualifyWithFirst(DEF_XDM_CONFIG,
544                                       CDE_CONFIGURATION_TOP "/config:"
545                                       CDE_INSTALLATION_TOP "/config");
546
547     GetResource ("Dtlogin.configFile", "Dtlogin.ConfigFile",
548                  DM_STRING, &config, configFileName);
549
550     free(configFileName);
551
552
553     
554     newDB = XrmGetFileDatabase ( config );
555     if (newDB)
556     {
557
558         if (DmResourceDB)
559             XrmDestroyDatabase (DmResourceDB);
560         DmResourceDB = newDB;
561     }
562     else if (argc != originalArgc)
563         LogError(
564                 ReadCatalog(MC_LOG_SET,MC_LOG_NO_OPENCFG,MC_DEF_LOG_NO_OPENCFG),
565                 config );
566
567
568
569     /*
570      *  scan the resource database to set the application name...
571      */
572     SetAppName();       
573      
574     XrmParseCommand (&DmResourceDB, optionTable,
575                      sizeof (optionTable) / sizeof (optionTable[0]),
576                      AppName, &argc, argv);
577
578      /* 
579       * test to see if the session variable is set.
580       * for enabling the toggle in the options menu, if it is set..
581       */
582     if((XrmGetResource (DmResourceDB, "Dtlogin*session", "Dtlogin*Session", &type, &value)) == True)
583         session_set = True;
584
585     if (argc > 1)
586     {
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");
591     }
592     free (argv);
593 }
594
595 void 
596 LoadDMResources( void )
597 {
598         int     i;
599         char    name[1024], class[1024];
600         FILE    *fp;
601
602         if (servers) {free(servers); servers=NULL;}
603         if (keyFile) {free(keyFile); keyFile=NULL;}
604         if (accessFile) {free(accessFile); accessFile=NULL;}
605
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);
612         }
613
614         servers = getFullFileName(servers, 1, NULL);
615         keyFile = getFullFileName(keyFile, 0, NULL);
616         accessFile = getFullFileName(accessFile, 0, NULL);
617
618 #ifndef __apollo        /* set a TZ default for all OS except Domain */
619         if (timeZone == NULL || strlen(timeZone) == 0)
620         {
621          /*
622           *  dynamically determine the timeZone resource default value...
623           */
624           GetSysParms(&timeZone,0,0);
625         }
626 #endif
627
628 }
629
630 void
631 CleanUpName( char *src, char *dst, int len )
632 {
633     while (*src) {
634         if (--len <= 0)
635                 break;
636         switch (*src)
637         {
638         case ':':
639         case '.':
640             *dst++ = '_';
641             break;
642         default:
643             *dst++ = *src;
644         }
645         ++src;
646     }
647     *dst = '\0';
648 }
649
650 void
651 LoadDisplayResources( struct display *d )
652 {
653         int     i;
654         char    name[1024], class[1024];
655         char    dpyName[512], dpyClass[512];
656         char    *lang;
657
658         Debug("Loading display resources for %s\n", d->name);
659         
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;}
666
667         CleanUpName (d->name, dpyName, sizeof (dpyName));
668         CleanUpName (d->class ? d->class : d->name, dpyClass, sizeof (dpyClass));
669
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;
674                   break;
675                 }
676            }
677
678
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);
686         }
687
688 #ifdef _AIX
689     if(d->language == NULL || strlen(d->language) == 0)
690         SetDefaultLanguage(d);
691 #endif /* _AIX */
692
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);
699
700 }
701
702
703         
704 /***************************************************************************
705  *
706  *  SetAppName
707  *
708  *  Probe the resource database to see whether the config file is using
709  *  "Dtlogin" or "DisplayManager" as the application name.
710  *
711  *  If it cannot be determined, "Dtlogin" is used.
712  ***************************************************************************/
713
714 void
715 SetAppName( void )
716 {
717     int         i;
718     char        name[1024], class[1024];
719     char        *type;
720     XrmValue    value;
721
722     for (i = 0; i < NUM_DM_RESOURCES; i++) {
723
724         /*
725          *  try "Dtlogin" (default) ...
726          */
727
728         sprintf (name, "%s.%s", DTLOGIN, DmResources[i].name);
729         sprintf (class, "%s.%s", DTLOGIN, DmResources[i].class);
730
731         if (DmResourceDB && XrmGetResource (DmResourceDB, name, class,
732             &type, &value)) {
733
734             strcpy(AppName, DTLOGIN);
735             break;
736         }
737
738
739         /*
740          *  try "DisplayManager" ...
741          */
742
743         sprintf (name, "%s.%s", DISPLAYMANAGER, DmResources[i].name);
744         sprintf (class, "%s.%s", DISPLAYMANAGER, DmResources[i].class);
745
746         if (DmResourceDB && XrmGetResource (DmResourceDB, name, class,
747             &type, &value)) {
748
749             strcpy(AppName, DISPLAYMANAGER);
750             break;
751         }
752         
753     }
754 }
755
756
757 /***************************************************************************
758  *
759  *  getFullFileName
760  *
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 );
767
768 static char *
769 getFullFileName(char *name, int special, char *lang)
770 {
771
772 char * newname;
773
774     if (name == NULL)
775         return(NULL);
776
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) {
781             return (NULL);
782         } else {
783             strcpy(newname, name);
784             return(newname);
785         }
786     }
787
788     switch (special) {
789                  /*********************/
790         case 0:  /** no special case **/
791                  /*********************/
792             newname = qualifyWithFirst(name,
793                                        CDE_CONFIGURATION_TOP "/config:"
794                                        CDE_INSTALLATION_TOP "/config");
795             return (newname);
796
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)))
804                     == NULL) {
805                     return (NULL);
806                 } else {
807                     strcpy(newname, name);
808                     return(newname);
809                 }
810             } else {
811                 newname = qualifyWithFirst(name,
812                                            CDE_CONFIGURATION_TOP "/config:"
813                                            CDE_INSTALLATION_TOP "/config");
814                 return (newname);
815             }
816
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");
825                 return (newname);
826             } else {
827                 char *langString;
828                 char *tempName;
829                 int tempLen;
830
831                 /** need to remember the %L **/
832                 if (lang == NULL)
833                     lang = "C";
834                 langString = _ExpandLang(name, lang);
835                 if ( (tempName = qualifyWithFirst(langString,
836                                            CDE_CONFIGURATION_TOP "/config:"
837                                            CDE_INSTALLATION_TOP "/config") )
838                     == NULL) {
839                     free(langString);
840                     langString = _ExpandLang(name, "C");
841                     if ( (tempName = qualifyWithFirst(langString,
842                                            CDE_CONFIGURATION_TOP "/config:"
843                                            CDE_INSTALLATION_TOP "/config") )
844                         == NULL) {
845                         free(langString);
846                         return(NULL);
847                     }
848                 }
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)
853                              + strlen(name) + 1;
854                 if ((newname = (char *)malloc(tempLen * sizeof(char))) == NULL){
855                     free(langString);
856                     return(tempName);
857                 } else {
858                     tempLen = strlen(tempName) - strlen(langString);
859                     strncpy(newname, tempName, tempLen);
860                     strcpy(newname+tempLen, name);
861                     free (langString);
862                     return(newname);
863                 }
864             }
865     }
866 }
867