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
39 #include "dm_socket.h"
41 static ARRAY8 noAuthentication
= { (CARD16
)0, (CARD8Ptr
) 0 };
43 typedef struct _XdmAuth
{
44 ARRAY8 authentication
;
46 } XdmAuthRec
, *XdmAuthPtr
;
48 static XdmAuthRec auth
[] = {
50 { {(CARD16
)20, (CARD8
*)"XDM-AUTHENTICATION-1"},
51 {(CARD16
)19, (CARD8
*)"XDM-AUTHORIZATION-1"},
54 { {(CARD16
)0, (CARD8
*)0},
55 {(CARD16
)0, (CARD8
*)0},
59 #define NumAuth as(auth)
62 chooseAuthentication( ARRAYofARRAY8Ptr authenticationNames
)
66 for (i
= 0; i
< (int)authenticationNames
->length
; i
++)
67 for (j
= 0; j
< NumAuth
; j
++)
68 if (XdmcpARRAY8Equal( &authenticationNames
->data
[i
],
69 &auth
[j
].authentication
))
70 return &authenticationNames
->data
[i
];
71 return &noAuthentication
;
75 checkAuthentication( struct protoDisplay
*pdpy ATTR_UNUSED
,
76 ARRAY8Ptr displayID ATTR_UNUSED
,
77 ARRAY8Ptr name ATTR_UNUSED
,
78 ARRAY8Ptr data ATTR_UNUSED
)
81 if (name
->length
&& !memcmp( (char *)name
->data
, "XDM-AUTHENTICATION-1", 20 ))
82 return xdmcheckAuthentication( pdpy
, displayID
, name
, data
);
88 selectAuthorizationTypeIndex( ARRAY8Ptr authenticationName
,
89 ARRAYofARRAY8Ptr authorizationNames
)
93 for (j
= 0; j
< NumAuth
; j
++)
94 if (XdmcpARRAY8Equal( authenticationName
,
95 &auth
[j
].authentication
))
98 for (i
= 0; i
< (int)authorizationNames
->length
; i
++)
99 if (XdmcpARRAY8Equal( &authorizationNames
->data
[i
],
100 &auth
[j
].authorization
))
102 for (i
= 0; i
< (int)authorizationNames
->length
; i
++)
103 if (validAuthorization( authorizationNames
->data
[i
].length
,
104 (char *)authorizationNames
->data
[i
].data
))
110 /*#define WILLING_INTERNAL*/
112 #ifdef WILLING_INTERNAL
113 /* Report the loadavg to chooser. Nice feature ...
115 * Wed Mar 10 1999 -- Steffen Hansen
118 willingMsg( char *mbuf
)
123 const char *fail_msg
= "Willing to manage";
129 fd
= open( "/proc/loadavg", O_RDONLY
);
131 sprintf( mbuf
, fail_msg
);
133 } else if (read( fd
, buf
, 100 ) < 4) {
135 sprintf( mbuf
, fail_msg
);
140 sscanf( buf
, "%f %f %f", &load
[0], &load
[1], &load
[2] );
141 sprintf( mbuf
, "Available (load: %0.2f, %0.2f, %0.2f)",
142 load
[0], load
[1], load
[2] );
146 if (!(f
= fopen( "/proc/cpuinfo", "r" )))
149 while (fGets( buf
, sizeof(buf
), f
) != -1) {
151 if (sscanf( buf
, "cpu MHz : %f", &m
)) {
161 sprintf( buf
, " %d*%0.0f MHz", numcpu
, mhz
);
163 sprintf( buf
, " %0.0f MHz", mhz
);
165 strncat( mbuf
, buf
, 256 );
169 #elif HAVE_GETLOADAVG /* !__linux__ */
171 # warning This code is untested...
174 getloadavg( load
, 3 );
175 sprintf( mbuf
, "Available (load: %0.2f, %0.2f, %0.2f)", load
[0],
177 #else /* !__linux__ && !GETLOADAVG */
178 strcpy( mbuf
, "Willing to manage" );
185 isWilling( ARRAY8Ptr addr
, CARD16 connectionType
,
186 ARRAY8Ptr authenticationName ATTR_UNUSED
,
187 ARRAY8Ptr status
, xdmOpCode type
)
191 static time_t lastscan
;
193 if (autoRescan
&& lastscan
+ 15 < now
) {
195 scanAccessDatabase( False
);
197 ret
= acceptableDisplayAddress( addr
, connectionType
, type
);
199 sprintf( statusBuf
, "Display not authorized to connect" );
204 if ((fd
= popen( willing
, "r" ))) {
206 if ((len
= fGets( statusBuf
, sizeof(statusBuf
), fd
)) != -1) {
212 if (feof( fd
) || errno
!= EINTR
)
218 sprintf( statusBuf
, "Willing, but %.*s failed",
219 (int)(sizeof(statusBuf
) - 21), willing
);
221 #ifdef WILLING_INTERNAL
222 willingMsg( statusBuf
);
224 strcpy( statusBuf
, "Willing to manage" );
227 status
->length
= strlen( statusBuf
);
228 status
->data
= (CARD8Ptr
) Malloc( status
->length
);
232 memmove( status
->data
, statusBuf
, status
->length
);
238 isAccepting( struct sockaddr
*from ATTR_UNUSED
, int fromlen ATTR_UNUSED
,
239 CARD16 displayNumber ATTR_UNUSED
)
246 selectConnectionTypeIndex( ARRAY16Ptr connectionTypes
,
247 ARRAYofARRAY8Ptr connectionAddresses ATTR_UNUSED
)
252 * Select one supported connection type
255 for (i
= 0; i
< connectionTypes
->length
; i
++) {
256 switch (connectionTypes
->data
[i
]) {
260 # if defined(IPv6) && defined(AF_INET6)
261 case FamilyInternet6
:
264 #if defined(DNETCONN)
266 #endif /* DNETCONN */