int ForEachMatchingIndirectHost ( ARRAY8Ptr clientAddress, CARD16 connectionType, ChooserFunc function, char *closure) { int haveLocalhost = 0; DisplayEntry *d; char *clientName = NULL; for (d = database; d; d = d->next) { switch (d->type) { case DISPLAY_ALIAS: case DISPLAY_LISTEN: continue; case DISPLAY_PATTERN: if (!clientName) clientName = NetworkAddressToHostname (connectionType, clientAddress); if (!patternMatch (clientName, d->entry.displayPattern)) continue; break; case DISPLAY_ADDRESS: if (d->entry.displayAddress.connectionType != connectionType || !XdmcpARRAY8Equal (&d->entry.displayAddress.clientAddress, clientAddress)) { continue; } break; } if (!d->hosts) continue; if (d->notAllowed) break; if (d->chooser) { ARRAY8Ptr choice; choice = IndirectChoice (clientAddress, connectionType); if (!choice || XdmcpARRAY8Equal (getLocalAddress(), choice)) haveLocalhost = 1; else (*function) (connectionType, choice, closure); } else if (scanHostlist (d->hosts, clientAddress, connectionType, function, closure, 0, FALSE)) { haveLocalhost = 1; } break; } free (clientName); return haveLocalhost; }
void ForEachChooserHost ( ARRAY8Ptr clientAddress, CARD16 connectionType, ChooserFunc function, char *closure) { int haveLocalhost = 0; DisplayEntry *d; char *clientName = NULL; for (d = database; d; d = d->next) { switch (d->type) { case DISPLAY_ALIAS: continue; case DISPLAY_PATTERN: if (!clientName) clientName = NetworkAddressToHostname (connectionType, clientAddress); if (!patternMatch (clientName, d->entry.displayPattern)) continue; break; case DISPLAY_ADDRESS: if (d->entry.displayAddress.connectionType != connectionType || !XdmcpARRAY8Equal (&d->entry.displayAddress.clientAddress, clientAddress)) { continue; } break; } if (!d->hosts) continue; if (d->notAllowed) break; if (!d->chooser) break; if (scanHostlist (d->hosts, clientAddress, connectionType, function, closure, 0, TRUE)) { haveLocalhost = 1; } break; } if (clientName) free (clientName); if (haveLocalhost) (*function) (connectionType, getLocalAddress(), closure); }
int UseChooser ( ARRAY8Ptr clientAddress, CARD16 connectionType) { DisplayEntry *d; char *clientName = NULL; for (d = database; d; d = d->next) { switch (d->type) { case DISPLAY_ALIAS: continue; case DISPLAY_PATTERN: if (!clientName) clientName = NetworkAddressToHostname (connectionType, clientAddress); if (!patternMatch (clientName, d->entry.displayPattern)) continue; break; case DISPLAY_ADDRESS: if (d->entry.displayAddress.connectionType != connectionType || !XdmcpARRAY8Equal (&d->entry.displayAddress.clientAddress, clientAddress)) { continue; } break; } if (!d->hosts) continue; if (d->notAllowed) break; if (d->chooser && !IndirectChoice (clientAddress, connectionType)) { if (clientName) free (clientName); return 1; } break; } if (clientName) free (clientName); return 0; }
int AcceptableDisplayAddress ( ARRAY8Ptr clientAddress, CARD16 connectionType, xdmOpCode type) { DisplayEntry *d; char *clientName = NULL; if (!*accessFile) return 1; if (type == INDIRECT_QUERY) return 1; for (d = database; d; d = d->next) { if (d->hosts) continue; switch (d->type) { case DISPLAY_ALIAS: case DISPLAY_LISTEN: continue; case DISPLAY_PATTERN: if (!clientName) clientName = NetworkAddressToHostname (connectionType, clientAddress); if (!patternMatch (clientName, d->entry.displayPattern)) continue; break; case DISPLAY_ADDRESS: if (d->entry.displayAddress.connectionType != connectionType || !XdmcpARRAY8Equal (&d->entry.displayAddress.clientAddress, clientAddress)) { continue; } break; } break; } free (clientName); return (d != 0) && (d->notAllowed == 0) && (type == BROADCAST_QUERY ? d->notBroadcast == 0 : 1); }
static void manage(struct sockaddr *from, int fromlen, int length, int fd) { CARD32 sessionID; CARD16 displayNumber; ARRAY8 displayClass; int expectlen; struct protoDisplay *pdpy; struct display *d; char *name = NULL; char *class2 = NULL; XdmcpNetaddr from_save; ARRAY8 clientAddress, clientPort; CARD16 connectionType; Debug("<manage> %d\n", length); displayClass.data = 0; displayClass.length = 0; if(XdmcpReadCARD32(&buffer, &sessionID) && XdmcpReadCARD16(&buffer, &displayNumber) && XdmcpReadARRAY8(&buffer, &displayClass)) { expectlen = 4 + /* session ID */ 2 + /* displayNumber */ 2 + displayClass.length; /* displayClass */ if(expectlen != length) { Debug("<manage> length error got %d expect %d\n", length, expectlen); goto abort; } pdpy = FindProtoDisplay((XdmcpNetaddr)from, fromlen, displayNumber); Debug("<manage> session ID %ld, pdpy %p\n", (long)sessionID, pdpy); if(!pdpy || pdpy->sessionID != sessionID) { /* * We may have already started a session for this display * but it hasn't seen the response in the form of an * XOpenDisplay() yet. So check if it is in the list of active * displays, and if so check that the session id's match. * If all this is true, then we have a duplicate request that * can be ignored. */ if(!pdpy && (d = FindDisplayByAddress((XdmcpNetaddr)from, fromlen, displayNumber)) && d->sessionID == sessionID) { Debug("manage: got duplicate pkt, ignoring\n"); goto abort; } Debug("session ID %ld refused\n", (long)sessionID); if(pdpy) Debug("existing session ID %ld\n", (long)pdpy->sessionID); send_refuse(from, fromlen, sessionID, fd); } else { name = NetworkAddressToName(pdpy->connectionType, &pdpy->connectionAddress, from, pdpy->displayNumber); if(!name) { Debug("could not compute display name\n"); send_failed(from, fromlen, "(no name)", sessionID, "out of memory", fd); goto abort; } Debug("computed display name: %s\n", name); if((d = FindDisplayByName(name))) { Debug("terminating active session for %s\n", d->name); StopDisplay(d); } if(displayClass.length) { if(!StrNDup(&class2, (char *)displayClass.data, displayClass.length)) { send_failed(from, fromlen, name, sessionID, "out of memory", fd); goto abort; } } if(!(from_save = (XdmcpNetaddr)Malloc(fromlen))) { send_failed(from, fromlen, name, sessionID, "out of memory", fd); goto abort; } memmove(from_save, from, fromlen); if(!(d = NewDisplay(name))) { free((char *)from_save); send_failed(from, fromlen, name, sessionID, "out of memory", fd); goto abort; } d->class2 = class2; class2 = 0; d->displayType = dForeign | dTransient | dFromXDMCP; d->sessionID = pdpy->sessionID; d->from.data = (unsigned char *)from_save; d->from.length = fromlen; d->displayNumber = pdpy->displayNumber; ClientAddress(from, &clientAddress, &clientPort, &connectionType); d->useChooser = 0; d->xdmcpFd = fd; if(IsIndirectClient(&clientAddress, connectionType)) { Debug("IsIndirectClient\n"); ForgetIndirectClient(&clientAddress, connectionType); if(UseChooser(&clientAddress, connectionType)) { d->useChooser = 1; Debug("use chooser for %s\n", d->name); } } d->clientAddr = clientAddress; d->connectionType = connectionType; d->remoteHost = NetworkAddressToHostname(pdpy->connectionType, &pdpy->connectionAddress); XdmcpDisposeARRAY8(&clientPort); if(pdpy->fileAuthorization) { d->authorizations = (Xauth **)Malloc(sizeof(Xauth *)); if(!d->authorizations) { free((char *)from_save); free((char *)d); send_failed(from, fromlen, name, sessionID, "out of memory", fd); goto abort; } d->authorizations[0] = pdpy->fileAuthorization; d->authNum = 1; pdpy->fileAuthorization = 0; } DisposeProtoDisplay(pdpy); Debug("starting display %s,%s\n", d->name, d->class2); if(LoadDisplayResources(d) < 0) { LogError( "Unable to read configuration for display %s; " "stopping it.\n", d->name); StopDisplay(d); } else StartDisplay(d); CloseGetter(); } } abort: XdmcpDisposeARRAY8(&displayClass); if(name) free((char *)name); if(class2) free((char *)class2); }