2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
24 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
25 * (c) Copyright 1993, 1994 International Business Machines Corp. *
26 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
27 * (c) Copyright 1993, 1994 Novell, Inc. *
30 * xdm - display manager daemon
32 * $XConsortium: file.c /main/4 1995/10/27 16:13:19 rswiston $
34 * Copyright 1988 Massachusetts Institute of Technology
36 * Permission to use, copy, modify, and distribute this software and its
37 * documentation for any purpose and without fee is hereby granted, provided
38 * that the above copyright notice appear in all copies and that both that
39 * copyright notice and this permission notice appear in supporting
40 * documentation, and that the name of M.I.T. not be used in advertising or
41 * publicity pertaining to distribution of the software without specific,
42 * written prior permission. M.I.T. makes no representations about the
43 * suitability of this software for any purpose. It is provided "as is"
44 * without express or implied warranty.
46 * Author: Keith Packard, MIT X Consortium
59 # include <sys/socket.h>
60 # include <netinet/in.h>
65 /***************************************************************************
67 * Local procedure declarations
69 ***************************************************************************/
71 static int DisplayTypeMatch( DisplayType d1, DisplayType d2) ;
72 static void freeArgs( char **args) ;
73 static void freeSomeArgs( char **args, int n) ;
74 static DisplayType parseDisplayType( char *string, int *usedDefaultType, int *parse_uid) ;
75 static char ** splitIntoWords( char *s) ;
76 static char ** copyArgs( char **args) ;
81 /***************************************************************************
85 ***************************************************************************/
88 DisplayTypeMatch( DisplayType d1, DisplayType d2 )
90 return d1.location == d2.location &&
91 d1.lifetime == d2.lifetime &&
92 d1.origin == d2.origin;
96 freeArgs( char **args )
100 for (a = args; *a; a++)
102 free ((char *) args);
106 splitIntoWords( char *s )
108 char **args, **newargs;
116 while (*s && isspace (*s))
118 if (!*s || *s == '#')
121 while (*s && *s != '#' && !isspace (*s))
125 args = (char **) malloc (2 * sizeof (char *));
131 newargs = (char **) realloc ((char *) args,
132 (nargs+2)*sizeof (char *));
140 args[nargs] = malloc (s - wordStart + 1);
146 strncpy (args[nargs], wordStart, s - wordStart);
147 args[nargs][s-wordStart] = '\0';
155 copyArgs( char **args )
157 char **a, **new, **n;
159 for (a = args; *a; a++)
161 new = (char **) malloc ((a - args + 1) * sizeof (char *));
172 freeSomeArgs( char **args, int n )
179 free ((char *) args);
183 ParseDisplay( char *source,
184 DisplayType *acceptableTypes,
186 struct passwd *puser)
188 char **args, **argv, **a;
189 char *name = NULL, *class, *type;
193 DisplayType displayType;
195 char *device=NULL; /* ITE device associated with display */
198 args = splitIntoWords (source);
203 LogError(ReadCatalog(MC_LOG_SET,MC_LOG_MISS_NAME,MC_DEF_LOG_MISS_NAME));
207 name = strdup(args[0]);
210 LogError(ReadCatalog(MC_LOG_SET,MC_LOG_MISS_TYPE,MC_DEF_LOG_MISS_TYPE),
218 * strip off display device if found in second field...
221 if ( (device = strchr(args[1],'@')) != NULL) {
226 displayType = parseDisplayType (args[1], &usedDefaultType, &parse_uid);
232 * check for special syntax "*" and expand to host name.
233 * if hostname cannot be found in a database, assume invalid and
236 if ( strcmp(name, "*") == 0) {
238 struct hostent *hostent;
240 memset(tname, 0, 128);
241 gethostname(tname, 128 - 1);
242 if ( (hostent = gethostbyname(tname)) == NULL ) {
244 ReadCatalog(MC_LOG_SET,MC_LOG_INV_HOSTNM,MC_DEF_LOG_INV_HOSTNM),
249 strncat(tname, ":0", 128 - 1);
252 name = strdup(tname);
256 * extended syntax; if the second argument doesn't
257 * exactly match a legal display type and the third
258 * argument does, use the second argument as the
259 * display class string
261 if (usedDefaultType && args[2])
265 * strip off display device if found in third field...
268 if ( device == NULL && (device = strchr(args[2],'@')) != NULL) {
273 displayType = parseDisplayType (args[2], &usedDefaultType, &parse_uid);
274 if (!usedDefaultType)
282 * extended syntax; if the display type argument was
283 * "local_uid", then next argument is pseudo user id
284 * under which the local Xserver is to be run.
289 Debug("Xservers 'local_uid' pseudo user = %s\n", *argv);
291 if ( (p = getpwnam (*argv)) != NULL) {
294 Debug("Could not get password entry for user name '%s'\n", *argv);
295 Debug("Using default pseudo user = %s\n", puser->pw_name);
300 Debug("Default pseudo user = %s\n", puser->pw_name);
303 while (numAcceptable)
305 if (DisplayTypeMatch (*acceptableTypes, displayType))
312 LogError(ReadCatalog(
313 MC_LOG_SET,MC_LOG_BAD_DPYTYPE,MC_DEF_LOG_BAD_DPYTYPE),
319 * see if this display is already being managed...
322 d = FindDisplayByName (name);
326 if (class && strcmp (d->class, class))
330 newclass = malloc ((unsigned) (strlen (class) + 1));
334 strcpy (newclass, class);
338 Debug ("Found existing display: %s %s %s", d->name, d->class ? d->class : "", type);
343 d = NewDisplay (name, class);
344 Debug ("Found new display: %s %s %s", d->name, d->class ? d->class : "", type);
346 d->displayType = displayType;
347 d->argv = copyArgs (argv);
348 for (a = d->argv; a && *a; a++)
353 * add device to display information...
356 if ( device != NULL && strlen(device) != 0 ) {
357 if (d->gettyLine != NULL)
360 d->gettyLine = strdup(device);
365 (strcmp(d->gettyLine, "None") == 0 ||
366 strcmp(d->gettyLine, "none") == 0 ) ) {
368 strcpy(d->gettyLine,"??");
372 freeSomeArgs (args, argv - args);
378 static struct displayMatch {
382 "local", { Local, Permanent, FromFile },
383 "local_uid", { Local, Permanent, FromFile },
384 "foreign", { Foreign, Permanent, FromFile },
385 0, { Local, Permanent, FromFile },
389 parseDisplayType( char *string, int *usedDefaultType, int *parse_uid )
391 struct displayMatch *d;
395 for (d = displayTypes; d->name; d++) {
396 if (strcmp(d->name, string) == 0)
398 if (strcmp(d->name, "local_uid") == 0) {
401 *usedDefaultType = 0;
406 *usedDefaultType = 1;