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