/* $XConsortium: policy.c,v 1.12 94/04/17 20:03:41 hersh Exp $ */ /* $XFree86: xc/programs/xdm/policy.c,v 3.1.2.2 1999/11/18 15:37:36 hohndel Exp $ */ /* Copyright (c) 1988 X Consortium Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Except as contained in this notice, the name of the X Consortium shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from the X Consortium. */ /* * xdm - display manager daemon * Author: Keith Packard, MIT X Consortium * * policy.c. Implement site-dependent policy for XDMCP connections */ # include "dm.h" #ifdef XDMCP # include #ifndef MINIX # ifndef Lynx # include # else # include # endif #ifdef AF_INET # include #endif #endif #include static ARRAY8 noAuthentication = { (CARD16) 0, (CARD8Ptr) 0 }; typedef struct _XdmAuth { ARRAY8 authentication; ARRAY8 authorization; } XdmAuthRec, *XdmAuthPtr; static XdmAuthRec auth[] = { #ifdef HASXDMAUTH { {(CARD16) 20, (CARD8 *) "XDM-AUTHENTICATION-1"}, {(CARD16) 19, (CARD8 *) "XDM-AUTHORIZATION-1"}, }, #endif { {(CARD16) 0, (CARD8 *) 0}, {(CARD16) 0, (CARD8 *) 0}, } }; #define NumAuth (sizeof auth / sizeof auth[0]) ARRAY8Ptr ChooseAuthentication (authenticationNames) ARRAYofARRAY8Ptr authenticationNames; { int i, j; for (i = 0; i < (int)authenticationNames->length; i++) for (j = 0; j < NumAuth; j++) if (XdmcpARRAY8Equal (&authenticationNames->data[i], &auth[j].authentication)) return &authenticationNames->data[i]; return &noAuthentication; } CheckAuthentication (pdpy, displayID, name, data) struct protoDisplay *pdpy; ARRAY8Ptr displayID, name, data; { #ifdef HASXDMAUTH if (name->length && !strncmp ((char *)name->data, "XDM-AUTHENTICATION-1", 20)) return XdmCheckAuthentication (pdpy, displayID, name, data); #endif return TRUE; } int SelectAuthorizationTypeIndex (authenticationName, authorizationNames) ARRAY8Ptr authenticationName; ARRAYofARRAY8Ptr authorizationNames; { int i, j; for (j = 0; j < NumAuth; j++) if (XdmcpARRAY8Equal (authenticationName, &auth[j].authentication)) break; if (j < NumAuth) { for (i = 0; i < (int)authorizationNames->length; i++) if (XdmcpARRAY8Equal (&authorizationNames->data[i], &auth[j].authorization)) return i; } for (i = 0; i < (int)authorizationNames->length; i++) if (ValidAuthorization (authorizationNames->data[i].length, (char *) authorizationNames->data[i].data)) return i; return -1; } /* * From Debain changes: * Find out the system load, and fill in either: * "Available (load x.xx)" * or * "Willing to manage" * if finding the load turns out to be impossible */ static void avail_msg(char *statusBuf) { const char *err = "Willing to manage"; #ifdef __linux__ FILE *lavg; char buf[5]; lavg = fopen("/proc/loadavg", "r"); if (lavg == NULL) { sprintf(statusBuf, err); return; } if (fread(buf, sizeof(char), 4, lavg) != 4) { fclose(lavg); sprintf(statusBuf, err); return; } buf[4] = '\0'; sprintf(statusBuf, "Available (load: %s)", buf); fclose(lavg); return; #else /* __linux__ */ #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) double lavg; if (getloadavg(&lavg, 1) == 1) { sprintf(statusBuf, "Available (load: %.2f)", lavg); return; } #endif /* __FreeBSD__ || __NetBSD__ || __OpenBSD__ */ strcpy(statusBuf, err); return; #endif /* __linux__ */ } /*ARGSUSED*/ int Willing (addr, connectionType, authenticationName, status, type) ARRAY8Ptr addr; CARD16 connectionType; ARRAY8Ptr authenticationName; ARRAY8Ptr status; xdmOpCode type; { char statusBuf[256]; int ret; ret = AcceptableDisplayAddress (addr, connectionType, type); if (!ret) sprintf (statusBuf, "Display not authorized to connect"); else avail_msg (statusBuf); status->length = strlen (statusBuf); status->data = (CARD8Ptr) malloc (status->length); if (!status->data) status->length = 0; else memmove( status->data, statusBuf, status->length); return ret; } /*ARGSUSED*/ ARRAY8Ptr Accept (from, fromlen, displayNumber) struct sockaddr *from; int fromlen; CARD16 displayNumber; { return 0; } /*ARGSUSED*/ int SelectConnectionTypeIndex (connectionTypes, connectionAddresses) ARRAY16Ptr connectionTypes; ARRAYofARRAY8Ptr connectionAddresses; { return 0; } #endif /* XDMCP */