3
Copyright 1988, 1998 The Open Group
4
Copyright 2001 Oswald Buddenhagen <ossi@kde.org>
6
Permission to use, copy, modify, distribute, and sell this software and its
7
documentation for any purpose is hereby granted without fee, provided that
8
the above copyright notice appear in all copies and that both that
9
copyright notice and this permission notice appear in supporting
12
The above copyright notice and this permission notice shall be included
13
in all copies or substantial portions of the Software.
15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21
OTHER DEALINGS IN THE SOFTWARE.
23
Except as contained in this notice, the name of a copyright holder shall
24
not be used in advertising or otherwise to promote the sale, use or
25
other dealings in this Software without prior written authorization
26
from the copyright holder.
31
* xdm - display manager daemon
32
* Author: Keith Packard, MIT X Consortium
34
* policy.c. Implement site-dependent policy for XDMCP connections
43
#include "dm_socket.h"
45
static ARRAY8 noAuthentication = { (CARD16)0, (CARD8Ptr) 0 };
47
typedef struct _XdmAuth {
48
ARRAY8 authentication;
50
} XdmAuthRec, *XdmAuthPtr;
52
static XdmAuthRec auth[] = {
54
{ {(CARD16)20, (CARD8 *)"XDM-AUTHENTICATION-1"},
55
{(CARD16)19, (CARD8 *)"XDM-AUTHORIZATION-1"},
58
{ {(CARD16)0, (CARD8 *)0},
59
{(CARD16)0, (CARD8 *)0},
63
#define NumAuth as(auth)
66
ChooseAuthentication( ARRAYofARRAY8Ptr authenticationNames )
70
for (i = 0; i < (int)authenticationNames->length; i++)
71
for (j = 0; j < NumAuth; j++)
72
if (XdmcpARRAY8Equal( &authenticationNames->data[i],
73
&auth[j].authentication ))
74
return &authenticationNames->data[i];
75
return &noAuthentication;
80
struct protoDisplay *pdpy ATTR_UNUSED,
81
ARRAY8Ptr displayID ATTR_UNUSED,
82
ARRAY8Ptr name ATTR_UNUSED,
83
ARRAY8Ptr data ATTR_UNUSED )
86
if (name->length && !memcmp( (char *)name->data, "XDM-AUTHENTICATION-1", 20 ))
87
return XdmCheckAuthentication( pdpy, displayID, name, data );
93
SelectAuthorizationTypeIndex( ARRAY8Ptr authenticationName,
94
ARRAYofARRAY8Ptr authorizationNames )
98
for (j = 0; j < NumAuth; j++)
99
if (XdmcpARRAY8Equal( authenticationName,
100
&auth[j].authentication ))
103
for (i = 0; i < (int)authorizationNames->length; i++)
104
if (XdmcpARRAY8Equal( &authorizationNames->data[i],
105
&auth[j].authorization ))
107
for (i = 0; i < (int)authorizationNames->length; i++)
108
if (ValidAuthorization( authorizationNames->data[i].length,
109
(char *)authorizationNames->data[i].data ))
115
/*#define WILLING_INTERNAL*/
117
#ifdef WILLING_INTERNAL
118
/* Report the loadavg to chooser. Nice feature ...
120
* Wed Mar 10 1999 -- Steffen Hansen
123
Willing_msg( char *mbuf )
128
const char *fail_msg = "Willing to manage";
134
fd = open( "/proc/loadavg", O_RDONLY );
136
sprintf( mbuf, fail_msg );
138
} else if (read( fd, buf, 100 ) < 4) {
140
sprintf( mbuf, fail_msg );
145
sscanf( buf, "%f %f %f", &load[0], &load[1], &load[2] );
146
sprintf( mbuf, "Available (load: %0.2f, %0.2f, %0.2f)",
147
load[0], load[1], load[2] );
151
if (!(f = fopen( "/proc/cpuinfo", "r" )))
154
while (fGets( buf, sizeof(buf), f ) != -1) {
156
if (sscanf( buf, "cpu MHz : %f", &m )) {
166
sprintf( buf, " %d*%0.0f MHz", numcpu, mhz );
168
sprintf( buf, " %0.0f MHz", mhz );
170
strncat( mbuf, buf, 256 );
174
#elif HAVE_GETLOADAVG /* !__linux__ */
176
# warning This code is untested...
179
getloadavg( load, 3 );
180
sprintf( mbuf, "Available (load: %0.2f, %0.2f, %0.2f)", load[0],
182
#else /* !__linux__ && !GETLOADAVG */
183
strcpy( mbuf, "Willing to manage" );
190
Willing( ARRAY8Ptr addr, CARD16 connectionType,
191
ARRAY8Ptr authenticationName ATTR_UNUSED,
192
ARRAY8Ptr status, xdmOpCode type )
196
static time_t lastscan;
198
if (autoRescan && lastscan + 15 < now) {
200
ScanAccessDatabase( FALSE );
202
ret = AcceptableDisplayAddress( addr, connectionType, type );
204
sprintf( statusBuf, "Display not authorized to connect" );
209
if ((fd = popen( willing, "r" ))) {
211
if ((len = fGets( statusBuf, sizeof(statusBuf), fd )) != -1) {
217
if (feof( fd ) || errno != EINTR)
223
sprintf( statusBuf, "Willing, but %.*s failed",
224
sizeof(statusBuf) - 21, willing );
226
#ifdef WILLING_INTERNAL
227
Willing_msg( statusBuf );
229
strcpy( statusBuf, "Willing to manage" );
232
status->length = strlen( statusBuf );
233
status->data = (CARD8Ptr) Malloc( status->length );
237
memmove( status->data, statusBuf, status->length );
243
Accept( struct sockaddr *from ATTR_UNUSED, int fromlen ATTR_UNUSED,
244
CARD16 displayNumber ATTR_UNUSED )
251
SelectConnectionTypeIndex( ARRAY16Ptr connectionTypes,
252
ARRAYofARRAY8Ptr connectionAddresses ATTR_UNUSED )
257
* Select one supported connection type
260
for (i = 0; i < connectionTypes->length; i++) {
261
switch (connectionTypes->data[i]) {
265
# if defined(IPv6) && defined(AF_INET6)
266
case FamilyInternet6:
269
#if defined(DNETCONN)
271
#endif /* DNETCONN */