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
23 /* (c) Copyright 1997 The Open Group */
25 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
26 * (c) Copyright 1993, 1994 International Business Machines Corp. *
27 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
28 * (c) Copyright 1993, 1994 Novell, Inc. *
31 * xdm - display manager daemon
33 * $TOG: policy.c /main/6 1997/03/14 13:45:03 barstow $
35 * Copyright 1988 Massachusetts Institute of Technology
37 * Permission to use, copy, modify, and distribute this software and its
38 * documentation for any purpose and without fee is hereby granted, provided
39 * that the above copyright notice appear in all copies and that both that
40 * copyright notice and this permission notice appear in supporting
41 * documentation, and that the name of M.I.T. not be used in advertising or
42 * publicity pertaining to distribution of the software without specific,
43 * written prior permission. M.I.T. makes no representations about the
44 * suitability of this software for any purpose. It is provided "as is"
45 * without express or implied warranty.
47 * Author: Keith Packard, MIT X Consortium
51 * policy.c. Implement site-dependent policy for XDMCP connections
56 static ARRAY8 noAuthentication = { (CARD16) 0, (CARD8Ptr) 0 };
57 static ARRAY8 loopbackAddress = { (CARD16) 0, (CARD8Ptr) 0 };
59 typedef struct _XdmAuth {
60 ARRAY8 authentication;
62 } XdmAuthRec, *XdmAuthPtr;
66 { {(CARD16) 20, (CARD8 *) "XDM-AUTHENTICATION-1"},
67 {(CARD16) 19, (CARD8 *) "XDM-AUTHORIZATION-1"},
70 { {(CARD16) 0, (CARD8 *) 0},
71 {(CARD16) 0, (CARD8 *) 0},
75 #define NumAuth (sizeof auth / sizeof auth[0])
79 /***************************************************************************
81 * Local procedure declarations
83 ***************************************************************************/
85 static char * WillingMsg( void ) ;
88 /******** End Local Function Declarations ********/
95 ChooseAuthentication( ARRAYofARRAY8Ptr authenticationNames )
99 for (i = 0; i < authenticationNames->length; i++)
100 for (j = 0; j < NumAuth; j++)
101 if (XdmcpARRAY8Equal (&authenticationNames->data[i],
102 &auth[j].authentication))
103 return &authenticationNames->data[i];
104 return &noAuthentication;
108 CheckAuthentication( struct protoDisplay *pdpy, ARRAY8Ptr displayID,
109 ARRAY8Ptr name, ARRAY8Ptr data )
112 if (name->length && !strncmp (name->data, "XDM-AUTHENTICATION-1", 20))
113 return XdmCheckAuthentication (pdpy, displayID, name, data);
119 SelectAuthorizationTypeIndex( ARRAY8Ptr authenticationName,
120 ARRAYofARRAY8Ptr authorizationNames )
124 for (j = 0; j < NumAuth; j++)
125 if (XdmcpARRAY8Equal (authenticationName,
126 &auth[j].authentication))
130 for (i = 0; i < authorizationNames->length; i++)
131 if (XdmcpARRAY8Equal (&authorizationNames->data[i],
132 &auth[j].authorization))
135 for (i = 0; i < authorizationNames->length; i++)
136 if (ValidAuthorization (authorizationNames->data[i].length,
137 (char *) authorizationNames->data[i].data))
144 Willing( struct sockaddr *addr, int addrlen, ARRAY8Ptr authenticationName,
151 #if NeedWidePrototypes
154 CARD16 connectionType,
155 #endif /* NeedWidePrototypes */
156 ARRAY8Ptr authenticationName,
160 static char statusBuf[256];
163 extern char *localHostname ();
165 ret = AcceptableDisplayAddress (addr, connectionType, type);
167 sprintf (statusBuf, "Display not authorized to connect");
169 sprintf (statusBuf, "%s", WillingMsg());
171 sprintf (statusBuf, "host %s", localHostname());
174 status->length = strlen (statusBuf);
175 status->data = (CARD8Ptr) malloc (status->length);
179 bcopy (statusBuf, (char *)status->data, status->length);
184 Accept( struct sockaddr *from, int fromlen,
185 #if NeedWidePrototypes
188 CARD16 displayNumber )
189 #endif /* NeedWidePrototypes */
195 SelectConnectionTypeIndex( ARRAY16Ptr connectionTypes,
196 ARRAYofARRAY8Ptr connectionAddresses )
202 * the current selection policy is to use the first connection address
203 * that is not the loopback address...
207 * initialize loopback address array if not already done so...
210 if (loopbackAddress.length == 0 &&
211 XdmcpAllocARRAY8 (&loopbackAddress, 4) ) {
213 loopbackAddress.data[0] = 127;
214 loopbackAddress.data[1] = 0;
215 loopbackAddress.data[2] = 0;
216 loopbackAddress.data[3] = 1;
219 for (i = 0; i < connectionAddresses->length; i++) {
220 if (!XdmcpARRAY8Equal (&connectionAddresses->data[i],
231 /***************************************************************************
235 * Generate a message for the "Willing" status field.
237 ***************************************************************************/
239 # define LINEBUFSIZE 32
244 static char retbuf[LINEBUFSIZE];
245 char tmpbuf[LINEBUFSIZE * 8];
247 char tmpfilename[L_tmpnam + 1];
251 /* Return selected part from an 'uptime' to Server */
252 /* for use in hosts status field when XDMCP broadcast is used */
253 /* (useful for selecting host to be managed by) */
255 strcpy(retbuf, "Willing to Manage");
257 strcpy(tmpbuf,"uptime | ");
258 strcat(tmpbuf,"awk '{printf(\"%s %-.5s load: %.3s, %.3s, %.3s\",$(NF-6),$(NF-5),$(NF-2),$(NF-1),$NF)}'");
259 strcat(tmpbuf," > ");
261 if ( tmpnam(tmpfilename) != (char *)NULL ) {
263 strcat(tmpbuf,tmpfilename);
267 if ((f = fopen(tmpfilename,"r")) != (FILE *) NULL) {
268 fgets(tmpbuf,LINEBUFSIZE,f);
269 if ( (cp = strchr(tmpbuf,'\n')) != NULL)
272 if (strlen(tmpbuf) > 10) /* seems reasonable? */
273 strcpy(retbuf, tmpbuf);