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 librararies 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, *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));
210 LogError(ReadCatalog(MC_LOG_SET,MC_LOG_MISS_TYPE,MC_DEF_LOG_MISS_TYPE),
217 * strip off display device if found in second field...
220 if ( (device = strchr(args[1],'@')) != NULL) {
225 displayType = parseDisplayType (args[1], &usedDefaultType, &parse_uid);
231 * check for special syntax "*" and expand to host name.
232 * if hostname cannot be found in a database, assume invalid and
235 if ( strcmp(name, "*") == 0) {
237 struct hostent *hostent;
240 gethostname(tname, sizeof(tname));
241 if ( (hostent = gethostbyname(tname)) == NULL ) {
243 ReadCatalog(MC_LOG_SET,MC_LOG_INV_HOSTNM,MC_DEF_LOG_INV_HOSTNM),
249 strcpy(tname,hostent->h_name);
258 * extended syntax; if the second argument doesn't
259 * exactly match a legal display type and the third
260 * argument does, use the second argument as the
261 * display class string
263 if (usedDefaultType && args[2])
267 * strip off display device if found in third field...
270 if ( device == NULL && (device = strchr(args[2],'@')) != NULL) {
275 displayType = parseDisplayType (args[2], &usedDefaultType, &parse_uid);
276 if (!usedDefaultType)
284 * extended syntax; if the display type argument was
285 * "local_uid", then next argument is pseudo user id
286 * under which the local Xserver is to be run.
291 Debug("Xservers 'local_uid' pseudo user = %s\n", *argv);
293 if ( (p = getpwnam (*argv)) != NULL) {
296 Debug("Could not get password entry for user name '%s'\n", *argv);
297 Debug("Using default pseudo user = %s\n", puser->pw_name);
302 Debug("Default pseudo user = %s\n", puser->pw_name);
305 while (numAcceptable)
307 if (DisplayTypeMatch (*acceptableTypes, displayType))
314 LogError(ReadCatalog(
315 MC_LOG_SET,MC_LOG_BAD_DPYTYPE,MC_DEF_LOG_BAD_DPYTYPE),
321 * see if this display is already being managed...
324 d = FindDisplayByName (name);
328 if (class && strcmp (d->class, class))
332 newclass = malloc ((unsigned) (strlen (class) + 1));
336 strcpy (newclass, class);
340 Debug ("Found existing display: %s %s %s", d->name, d->class ? d->class : "", type);
345 d = NewDisplay (name, class);
346 Debug ("Found new display: %s %s %s", d->name, d->class ? d->class : "", type);
348 d->displayType = displayType;
349 d->argv = copyArgs (argv);
350 for (a = d->argv; a && *a; a++)
355 * add device to display information...
358 if ( device != NULL && strlen(device) != 0 ) {
359 if (d->gettyLine != NULL)
362 d->gettyLine = strdup(device);
367 (strcmp(d->gettyLine, "None") == 0 ||
368 strcmp(d->gettyLine, "none") == 0 ) ) {
370 strcpy(d->gettyLine,"??");
374 freeSomeArgs (args, argv - args);
377 static struct displayMatch {
381 "local", { Local, Permanent, FromFile },
382 "local_uid", { Local, Permanent, FromFile },
383 "foreign", { Foreign, Permanent, FromFile },
384 0, { Local, Permanent, FromFile },
388 parseDisplayType( char *string, int *usedDefaultType, int *parse_uid )
390 struct displayMatch *d;
394 for (d = displayTypes; d->name; d++) {
395 if (strcmp(d->name, string) == 0)
397 if (strcmp(d->name, "local_uid") == 0) {
400 *usedDefaultType = 0;
405 *usedDefaultType = 1;