remove OSF1 support
[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 __apollo
220 #    define DEF_LANG    "C"
221 #  endif
222 #  ifdef sun    /* default language under Solaris */
223 #    define DEF_LANG    "C" 
224 #  endif
225 #endif
226
227 #ifndef DEF_LANG        /* set LANG to NULL if not already defined         */
228 #define DEF_LANG        ""
229 #endif
230
231 struct dmResources {
232         char    *name, *class;
233         int     type;
234         char    **dm_value;
235         char    *default_value;
236 } DmResources[] = {
237 "servers",      "Servers",      DM_STRING,      &servers,
238                                 DEF_SERVER_LINE,
239 "requestPort",  "RequestPort",  DM_INT,         (char **) &request_port,
240                                 DEF_UDP_PORT,
241 "debugLevel",   "DebugLevel",   DM_INT,         (char **) &debugLevel,
242                                 "0",
243 "errorLogFile", "ErrorLogFile", DM_STRING,      &errorLogFile,
244                                 "",
245 "errorLogSize", "ErrorLogSize", DM_INT,         (char **) &errorLogSize,
246                                 "50",
247 "daemonMode",   "DaemonMode",   DM_BOOL,        (char **) &daemonMode,
248                                 "false",
249 "quiet",        "quiet",        DM_BOOL,        (char **) &quiet,
250                                 "false",
251 "pidFile",      "PidFile",      DM_STRING,      &pidFile,
252                                 "",
253 "lockPidFile",  "LockPidFile",  DM_BOOL,        (char **) &lockPidFile,
254                                 "true",
255 "authDir",      "AuthDir",      DM_STRING,      &authDir,
256                                 DEF_AUTH_DIR,
257 "autoRescan",   "AutoRescan",   DM_BOOL,        (char **) &autoRescan,
258                                 "true",
259 "removeDomainname","RemoveDomainname",DM_BOOL,  (char **) &removeDomainname,
260                                 "true",
261 "keyFile",      "KeyFile",      DM_STRING,      &keyFile,
262                                 DEF_KEY_FILE,
263 "accessFile",   "AccessFile",   DM_STRING,      &accessFile,
264                                 DEF_ACCESS_FILE,
265 /* exportList env var resource    RK   08.17.93  */
266 "exportList",   "ExportList",   DM_ARGV,        (char **) &exportList,
267                                 "",
268 "timeZone",     "TimeZone",     DM_STRING,      &timeZone,
269                                 "",
270 "fontPathHead", "FontPathHead", DM_STRING,      &fpHead,
271                                 "",
272 "fontPathTail", "FontPathTail", DM_STRING,      &fpTail,
273                                 "",
274 "sysParmsFile", "SysParmsFile", DM_STRING,      &sysParmsFile,
275                                 DEF_SYS_PARMS_FILE,
276 "wakeupInterval","WakeupInterval",DM_INT,       (char **) &wakeupInterval,
277                                 "10",
278 "langListTimeout","langListTimeout",DM_INT,     (char **) &langListTimeout,
279                                 "30",
280 #ifdef DEF_NETWORK_DEV
281 "networkDevice","NetworkDevice",DM_STRING,      &networkDev,
282                                 DEF_NETWORK_DEV,
283 #endif
284 };
285
286 # define NUM_DM_RESOURCES       (sizeof DmResources / sizeof DmResources[0])
287
288 # define boffset(f)     ((char *) &(((struct display *) 0)->f) - (char *) 0)
289
290 struct displayResources {
291         char    *name, *class;
292         int     type;
293         int     offset;
294         char    *default_value;
295 } DisplayResources[] = {
296
297
298 /* 
299  * resources for managing the server...
300  */
301  
302 "serverAttempts","ServerAttempts", DM_INT,      boffset(serverAttempts),
303                                 "1",
304 "openDelay",    "OpenDelay",    DM_INT,         boffset(openDelay),
305                                 "5",
306 "openRepeat",   "OpenRepeat",   DM_INT,         boffset(openRepeat),
307                                 "5",
308 "openTimeout",  "OpenTimeout",  DM_INT,         boffset(openTimeout),
309                                 "30",
310 "startAttempts","StartAttempts",DM_INT,         boffset(startAttempts),
311                                 "4",
312 "pingInterval", "PingInterval", DM_INT,         boffset(pingInterval),
313                                 "5",
314 "pingTimeout",  "PingTimeout",  DM_INT,         boffset(pingTimeout),
315                                 "5",
316 "terminateServer","TerminateServer",DM_BOOL,    boffset(terminateServer),
317                                 "false",
318 "grabServer",   "GrabServer",   DM_BOOL,        boffset(grabServer),
319                                 "true",
320 "grabTimeout",  "GrabTimeout",  DM_INT,         boffset(grabTimeout),
321                                 "3",
322 "resetSignal",  "Signal",       DM_INT,         boffset(resetSignal),
323                                 "1",    /* SIGHUP */
324 "termSignal",   "Signal",       DM_INT,         boffset(termSignal),
325                                 "15",   /* SIGTERM */
326 "resetForAuth", "ResetForAuth", DM_BOOL,        boffset(resetForAuth),
327                                 "false",
328 "authorize",    "Authorize",    DM_BOOL,        boffset(authorize),
329                                 "true",
330 "authName",     "AuthName",     DM_ARGV,        boffset(authNames),
331                                 DEF_AUTH_NAME,
332 "authFile",     "AuthFile",     DM_STRING,      boffset(authFile),
333                                 "",
334 #if 0
335 "gettyLine",    "GettyLine",    DM_STRING,      boffset(gettyLine),
336                                 "",
337 "gettySpeed",   "GettySpeed",   DM_STRING,      boffset(gettySpeed),
338                                 "9600",
339 #endif
340 /*
341  *  resources which control the session behavior...
342  */
343
344 "resources",    "Resources",    DM_STRING,      boffset(resources),
345                                 "",
346 "xrdb",         "Xrdb",         DM_STRING,      boffset(xrdb),
347                                 XRDB_PROGRAM,
348 "cpp",          "Cpp",          DM_STRING,      boffset(cpp),
349                                 CPP_PROGRAM,
350 "setup",        "Setup",        DM_STRING,      boffset(setup),
351                                 "",
352 "startup",      "Startup",      DM_STRING,      boffset(startup),
353                                 "",
354 "reset",        "Reset",        DM_STRING,      boffset(reset),
355                                 "",
356 "session",      "Session",      DM_STRING,      boffset(session),
357                                 DEF_SESSION,
358 "userPath",     "Path",         DM_STRING,      boffset(userPath),
359                                 DEF_USER_PATH,
360 "systemPath",   "Path",         DM_STRING,      boffset(systemPath),
361                                 DEF_SYSTEM_PATH,
362 "systemShell",  "Shell",        DM_STRING,      boffset(systemShell),
363                                 DEF_SYSTEM_SHELL,
364 "failsafeClient","FailsafeClient",      DM_STRING,      boffset(failsafeClient),
365                                 DEF_FAILSAFE_CLIENT,
366 "userAuthDir",  "UserAuthDir",  DM_STRING,      boffset(userAuthDir),
367                                 DEF_AUTH_DIR,
368 "chooser",      "Chooser",      DM_STRING,      boffset(chooser),
369                                 DEF_CHOOSER,
370 "language",     "Language",     DM_STRING,      boffset(language),
371                                 DEF_LANG,
372 "languageList", "LanguageList", DM_STRING,      boffset(langList),
373                                 "",
374 "environment",  "Environment",  DM_STRING,      boffset(environStr),
375                                 DEF_ENV,
376 "dtlite",       "Dtlite",       DM_BOOL,        boffset(dtlite),
377                                 "false",
378 "xdmMode",      "XdmMode",      DM_BOOL,        boffset(xdmMode),
379                                 "false",
380 "authenticationName","AuthenticationName", DM_STRING,   boffset(verifyName),
381                                 "",
382 "pmSearchPath", "PmSearchPath", DM_STRING,      boffset(pmSearchPath),
383                                 DEF_PM_SEARCH_PATH,
384 "bmSearchPath", "bmSearchPath", DM_STRING,      boffset(bmSearchPath), 
385                                 DEF_BM_SEARCH_PATH,
386 };
387
388 # define NUM_DISPLAY_RESOURCES  (sizeof DisplayResources/sizeof DisplayResources[0])
389
390 XrmDatabase     DmResourceDB;
391
392 int 
393 GetResource( char *name, char *class, int valueType, char **valuep,
394              char *default_value )
395 {
396     char        *type;
397     XrmValue    value;
398     char        *string, *new_string;
399     char        empty[] = "";
400     char        str_buf[50];
401     int len;
402
403
404     if (DmResourceDB && XrmGetResource (DmResourceDB,
405         name, class,
406         &type, &value))
407     {
408         string = value.addr;
409         len = value.size;
410     }
411     else
412     {
413         if(default_value) {
414                 string = default_value;
415                 len = strlen (string);
416         } else {
417                 string = empty;
418                 len = 0;
419         }
420     }
421
422     Debug ("%s/%s value %*.*s\n", name, class, len, len, string);
423
424
425     /*
426      *  check if new resource is the same as old...
427      */
428      
429      if (valueType == DM_STRING && *valuep) {
430         if (string != NULL && strlen (*valuep) == len && !strncmp (*valuep, string, len))
431             return 0;
432         else {
433             free (*valuep);
434             *(valuep) = NULL;
435         }
436      }
437  
438
439     switch (valueType) {
440     case DM_STRING:
441         if ( len > 0 ) {
442             new_string = malloc ((unsigned) (len+1));
443             if (!new_string) {
444                 LogOutOfMem(
445                   ReadCatalog(MC_LOG_SET,MC_LOG_GET_RSC,MC_DEF_LOG_GET_RSC));
446                 return 0;
447             }
448             strncpy (new_string, string, len);
449             new_string[len] = '\0';
450             *(valuep) = new_string;
451         }
452         break;
453     case DM_INT:
454         strncpy (str_buf, string, sizeof (str_buf));
455         str_buf[sizeof (str_buf)-1] = '\0';
456         *((int *) valuep) = atoi (str_buf);
457         break;
458     case DM_BOOL:
459         strncpy (str_buf, string, sizeof (str_buf));
460         str_buf[sizeof (str_buf)-1] = '\0';
461         XmuCopyISOLatin1Lowered (str_buf, str_buf);
462         if (!strcmp (str_buf, "true") ||
463             !strcmp (str_buf, "on") ||
464             !strcmp (str_buf, "yes"))
465                 *((int *) valuep) = 1;
466         else if (!strcmp (str_buf, "false") ||
467                  !strcmp (str_buf, "off") ||
468                  !strcmp (str_buf, "no"))
469                 *((int *) valuep) = 0;
470         break;
471     case DM_ARGV:
472         *((char ***) valuep) = parseArgs ((char **) 0, string);
473         break;
474
475     }
476
477     return 1;
478 }
479
480 XrmOptionDescRec configTable [] = {
481 {"-server",     NULL,                   XrmoptionSkipArg,       (caddr_t) NULL },
482 {"-udpPort",    NULL,                   XrmoptionSkipArg,       (caddr_t) NULL },
483 {"-error",      NULL,                   XrmoptionSkipArg,       (caddr_t) NULL },
484 {"-resources",  NULL,                   XrmoptionSkipArg,       (caddr_t) NULL },
485 {"-session",    NULL,                   XrmoptionSkipArg,       (caddr_t) NULL },
486 {"-debug",      NULL,                   XrmoptionSkipArg,       (caddr_t) NULL },
487 {"-xrm",        NULL,                   XrmoptionSkipArg,       (caddr_t) NULL },
488 {"-config",     ".configFile",          XrmoptionSepArg,        (caddr_t) NULL }
489 };
490
491 XrmOptionDescRec optionTable [] = {
492 {"-server",     ".servers",             XrmoptionSepArg,        (caddr_t) NULL },
493 {"-udpPort",    ".requestPort",         XrmoptionSepArg,        (caddr_t) NULL },
494 {"-error",      ".errorLogFile",        XrmoptionSepArg,        (caddr_t) NULL },
495 {"-resources",  "*resources",           XrmoptionSepArg,        (caddr_t) NULL },
496 {"-session",    "*session",             XrmoptionSepArg,        (caddr_t) NULL },
497 {"-debug",      "*debugLevel",          XrmoptionSepArg,        (caddr_t) NULL },
498 {"-xrm",        NULL,                   XrmoptionResArg,        (caddr_t) NULL },
499 {"-daemon",     ".daemonMode",          XrmoptionNoArg,         "true"         },
500 {"-nodaemon",   ".daemonMode",          XrmoptionNoArg,         "false"        },
501 {"-quiet",      ".quiet",               XrmoptionNoArg,         "true"        }
502 };
503
504 static int      originalArgc;
505 static char     **originalArgv;
506
507 void 
508 InitResources( int argc, char **argv )
509 {
510         XrmInitialize ();
511         originalArgc = argc;
512         originalArgv = argv;
513         ReinitResources ();
514 }
515
516 void 
517 ReinitResources( void )
518 {
519     int argc;
520     char        **a;
521     char        **argv;
522     XrmDatabase newDB;
523     char * configFileName;
524     char        *type;
525     XrmValue    value;
526
527     argv = (char **) malloc ((originalArgc + 1) * sizeof (char *));
528     if (!argv)
529         LogOutOfMem(
530                 ReadCatalog(MC_LOG_SET,MC_LOG_NO_SPACE,MC_DEF_LOG_NO_SPACE));
531     for (argc = 0; argc < originalArgc; argc++)
532         argv[argc] = originalArgv[argc];
533     argv[argc] = 0;
534     if (DmResourceDB)
535         XrmDestroyDatabase (DmResourceDB);
536     DmResourceDB = XrmGetStringDatabase ("");
537     /* pre-parse the command line to get the -config option, if any */
538     XrmParseCommand (&DmResourceDB, configTable,
539                      sizeof (configTable) / sizeof (configTable[0]),
540                      "Dtlogin", &argc, argv);
541     
542     configFileName = qualifyWithFirst(DEF_XDM_CONFIG,
543                                       CDE_CONFIGURATION_TOP "/config:"
544                                       CDE_INSTALLATION_TOP "/config");
545
546     GetResource ("Dtlogin.configFile", "Dtlogin.ConfigFile",
547                  DM_STRING, &config, configFileName);
548
549     free(configFileName);
550
551
552     
553     newDB = XrmGetFileDatabase ( config );
554     if (newDB)
555     {
556
557         if (DmResourceDB)
558             XrmDestroyDatabase (DmResourceDB);
559         DmResourceDB = newDB;
560     }
561     else if (argc != originalArgc)
562         LogError(
563                 ReadCatalog(MC_LOG_SET,MC_LOG_NO_OPENCFG,MC_DEF_LOG_NO_OPENCFG),
564                 config );
565
566
567
568     /*
569      *  scan the resource database to set the application name...
570      */
571     SetAppName();       
572      
573     XrmParseCommand (&DmResourceDB, optionTable,
574                      sizeof (optionTable) / sizeof (optionTable[0]),
575                      AppName, &argc, argv);
576
577      /* 
578       * test to see if the session variable is set.
579       * for enabling the toggle in the options menu, if it is set..
580       */
581     if((XrmGetResource (DmResourceDB, "Dtlogin*session", "Dtlogin*Session", &type, &value)) == True)
582         session_set = True;
583
584     if (argc > 1)
585     {
586         LogError(ReadCatalog(MC_LOG_SET,MC_LOG_EXTRA_ARG,MC_DEF_LOG_EXTRA_ARG));
587         for (a = argv + 1; *a; a++)
588                 LogError ((unsigned char *)" \"%s\"", *a);
589         LogError ((unsigned char *)"\n");
590     }
591     free (argv);
592 }
593
594 void 
595 LoadDMResources( void )
596 {
597         int     i;
598         char    name[1024], class[1024];
599         FILE    *fp;
600
601         if (servers) {free(servers); servers=NULL;}
602         if (keyFile) {free(keyFile); keyFile=NULL;}
603         if (accessFile) {free(accessFile); accessFile=NULL;}
604
605         for (i = 0; i < NUM_DM_RESOURCES; i++) {
606                 sprintf (name, "%s.%s", AppName, DmResources[i].name);
607                 sprintf (class, "%s.%s", AppName, DmResources[i].class);
608                 GetResource (name, class, DmResources[i].type,
609                               (char **) DmResources[i].dm_value,
610                               DmResources[i].default_value);
611         }
612
613         servers = getFullFileName(servers, 1, NULL);
614         keyFile = getFullFileName(keyFile, 0, NULL);
615         accessFile = getFullFileName(accessFile, 0, NULL);
616
617 #ifndef __apollo        /* set a TZ default for all OS except Domain */
618         if (timeZone == NULL || strlen(timeZone) == 0)
619         {
620          /*
621           *  dynamically determine the timeZone resource default value...
622           */
623           GetSysParms(&timeZone,0,0);
624         }
625 #endif
626
627 }
628
629 void
630 CleanUpName( char *src, char *dst, int len )
631 {
632     while (*src) {
633         if (--len <= 0)
634                 break;
635         switch (*src)
636         {
637         case ':':
638         case '.':
639             *dst++ = '_';
640             break;
641         default:
642             *dst++ = *src;
643         }
644         ++src;
645     }
646     *dst = '\0';
647 }
648
649 void
650 LoadDisplayResources( struct display *d )
651 {
652         int     i;
653         char    name[1024], class[1024];
654         char    dpyName[512], dpyClass[512];
655         char    *lang;
656
657         Debug("Loading display resources for %s\n", d->name);
658         
659         if (d->resources) {free(d->resources); d->resources=NULL;}
660         if (d->setup)     {free(d->setup); d->setup=NULL;}
661         if (d->startup)   {free(d->startup); d->startup=NULL;}
662         if (d->reset)     {free(d->reset); d->reset=NULL;}
663         if (d->session)   {free(d->session); d->session=NULL;}
664         if (d->failsafeClient) {free(d->failsafeClient); d->failsafeClient=NULL;}
665
666         CleanUpName (d->name, dpyName, sizeof (dpyName));
667         CleanUpName (d->class ? d->class : d->name, dpyClass, sizeof (dpyClass));
668
669         if((lang = getenv("LANG")) != NULL)
670            for (i = NUM_DISPLAY_RESOURCES - 1; i >= 0; i--)  {
671                 if(strcmp(DisplayResources[i].name,"language") == 0){
672                   DisplayResources[i].default_value = lang;
673                   break;
674                 }
675            }
676
677
678         for (i = 0; i < NUM_DISPLAY_RESOURCES; i++) {
679                 sprintf (name, "%s.%s.%s", AppName,
680                         dpyName, DisplayResources[i].name);
681                 sprintf (class, "%s.%s.%s", AppName,
682                         dpyClass, DisplayResources[i].class);
683                 GetResource (name, class, DisplayResources[i].type,
684                               (char **) (((char *) d) + DisplayResources[i].offset), DisplayResources[i].default_value);
685         }
686
687 #ifdef _AIX
688     if(d->language == NULL || strlen(d->language) == 0)
689         SetDefaultLanguage(d);
690 #endif /* _AIX */
691
692         d->resources = getFullFileName(d->resources, 2, d->language);
693         d->setup = getFullFileName(d->setup, 0, NULL);
694         d->startup = getFullFileName(d->startup, 0, NULL);
695         d->reset = getFullFileName(d->reset, 0, NULL);
696         d->session = getFullFileName(d->session, 0, NULL);
697         d->failsafeClient = getFullFileName(d->failsafeClient, 0, NULL);
698
699 }
700
701
702         
703 /***************************************************************************
704  *
705  *  SetAppName
706  *
707  *  Probe the resource database to see whether the config file is using
708  *  "Dtlogin" or "DisplayManager" as the application name.
709  *
710  *  If it cannot be determined, "Dtlogin" is used.
711  ***************************************************************************/
712
713 void
714 SetAppName( void )
715 {
716     int         i;
717     char        name[1024], class[1024];
718     char        *type;
719     XrmValue    value;
720
721     for (i = 0; i < NUM_DM_RESOURCES; i++) {
722
723         /*
724          *  try "Dtlogin" (default) ...
725          */
726
727         sprintf (name, "%s.%s", DTLOGIN, DmResources[i].name);
728         sprintf (class, "%s.%s", DTLOGIN, DmResources[i].class);
729
730         if (DmResourceDB && XrmGetResource (DmResourceDB, name, class,
731             &type, &value)) {
732
733             strcpy(AppName, DTLOGIN);
734             break;
735         }
736
737
738         /*
739          *  try "DisplayManager" ...
740          */
741
742         sprintf (name, "%s.%s", DISPLAYMANAGER, DmResources[i].name);
743         sprintf (class, "%s.%s", DISPLAYMANAGER, DmResources[i].class);
744
745         if (DmResourceDB && XrmGetResource (DmResourceDB, name, class,
746             &type, &value)) {
747
748             strcpy(AppName, DISPLAYMANAGER);
749             break;
750         }
751         
752     }
753 }
754
755
756 /***************************************************************************
757  *
758  *  getFullFileName
759  *
760  * Try to produce a fully qualified file name by prepending
761  * /etc/dt/config or /usr/dt/config to a resource file name.
762  * There are 2 special cases:  servers - which can be a command, and
763  *                             resources - which can an imbeded %L.
764  ***************************************************************************/
765 extern char *_ExpandLang( char *string, char *lang );
766
767 static char *
768 getFullFileName(char *name, int special, char *lang)
769 {
770
771 char * newname;
772
773     if (name == NULL)
774         return(NULL);
775
776     /** if the file already starts with a '/' **/
777     /** then just return a copy of it         **/
778     if (name[0] == '/') {
779         if ((newname = (char *)malloc((strlen(name)+1)*sizeof(char))) == NULL) {
780             return (NULL);
781         } else {
782             strcpy(newname, name);
783             return(newname);
784         }
785     }
786
787     switch (special) {
788                  /*********************/
789         case 0:  /** no special case **/
790                  /*********************/
791             newname = qualifyWithFirst(name,
792                                        CDE_CONFIGURATION_TOP "/config:"
793                                        CDE_INSTALLATION_TOP "/config");
794             return (newname);
795
796                  /***************************************/
797         case 1:  /** special handling for servers file **/
798                  /***************************************/
799             if (strchr(name, ':') != NULL) {
800                 /** This is probably a command and not a file name **/
801                 /** so just return a copy of it.                   **/
802                 if ((newname = (char *)malloc((strlen(name)+1)*sizeof(char)))
803                     == NULL) {
804                     return (NULL);
805                 } else {
806                     strcpy(newname, name);
807                     return(newname);
808                 }
809             } else {
810                 newname = qualifyWithFirst(name,
811                                            CDE_CONFIGURATION_TOP "/config:"
812                                            CDE_INSTALLATION_TOP "/config");
813                 return (newname);
814             }
815
816                  /********************************************/
817         case 2:  /** special handling for d->resources file **/
818                  /********************************************/
819             if (strchr(name, '%') == NULL) {
820                 /** no special processing needed **/
821                 newname = qualifyWithFirst(name,
822                                            CDE_CONFIGURATION_TOP "/config:"
823                                            CDE_INSTALLATION_TOP "/config");
824                 return (newname);
825             } else {
826                 char *langString;
827                 char *tempName;
828                 int tempLen;
829
830                 /** need to remember the %L **/
831                 if (lang == NULL)
832                     lang = "C";
833                 langString = _ExpandLang(name, lang);
834                 if ( (tempName = qualifyWithFirst(langString,
835                                            CDE_CONFIGURATION_TOP "/config:"
836                                            CDE_INSTALLATION_TOP "/config") )
837                     == NULL) {
838                     free(langString);
839                     langString = _ExpandLang(name, "C");
840                     if ( (tempName = qualifyWithFirst(langString,
841                                            CDE_CONFIGURATION_TOP "/config:"
842                                            CDE_INSTALLATION_TOP "/config") )
843                         == NULL) {
844                         free(langString);
845                         return(NULL);
846                     }
847                 }
848                 /** We have a fully qualified and expanded file name **/
849                 /** but we need to return a fully qualified but NOT  **/
850                 /** expanded file name.                              **/
851                 tempLen = strlen(tempName) - strlen(langString)
852                              + strlen(name) + 1;
853                 if ((newname = (char *)malloc(tempLen * sizeof(char))) == NULL){
854                     free(langString);
855                     return(tempName);
856                 } else {
857                     tempLen = strlen(tempName) - strlen(langString);
858                     strncpy(newname, tempName, tempLen);
859                     strcpy(newname+tempLen, name);
860                     free (langString);
861                     free (tempName);
862                     return(newname);
863                 }
864             }
865
866         default:
867           /* special is of an unknown value */
868           return(NULL);
869     }
870 }
871