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; }
/* * calls the given function for each valid indirect entry. Returns True if * the local host exists on any of the lists, else False */ int forEachMatchingIndirectHost(ARRAY8Ptr clientAddress, ARRAY8Ptr clientPort, CARD16 connectionType, ChooserFunc function, char *closure) { AclEntry *e; int haveLocalhost = False; e = matchAclEntry(clientAddress, connectionType, False); if (e && !(e->flags & a_notAllowed)) { if (e->flags & a_useChooser) { ARRAY8Ptr choice; choice = indirectChoice(clientAddress, clientPort, connectionType); if (!choice || XdmcpARRAY8Equal(getLocalAddress(), choice)) /* If nothing was chosen yet, we want to pop up the chooser. * If we were chosen, we want to pop up the greeter. */ haveLocalhost = True; else /* If something else was chosen, we forward the query to * the chosen host. */ (*function)(connectionType, choice, closure); } else /* Just forward the query to each listed host. */ scanHostlist(e->hosts, e->nhosts, clientAddress, connectionType, function, closure, False, &haveLocalhost); } return haveLocalhost; }
ARRAY8Ptr IndirectChoice ( ARRAY8Ptr clientAddress, CARD16 connectionType) { ChoicePtr c, next, prev; long now; now = time (0); prev = 0; for (c = choices; c; c = next) { next = c->next; if (now - c->time > 15) { Debug ("Timeout choice\n"); if (prev) prev->next = next; else choices = next; XdmcpDisposeARRAY8 (&c->client); XdmcpDisposeARRAY8 (&c->choice); free ((char *) c); } else { if (XdmcpARRAY8Equal (clientAddress, &c->client) && connectionType == c->connectionType) return &c->choice; prev = c; } } return 0; }
static int XdmcpCheckAuthentication (ARRAY8Ptr Name, ARRAY8Ptr Data, int packet_type) { return (XdmcpARRAY8Equal (Name, AuthenticationName) && (AuthenticationName->length == 0 || (*AuthenticationFuncs->Validator) (AuthenticationData, Data, packet_type))); }
static int RegisterIndirectChoice ( ARRAY8Ptr clientAddress, CARD16 connectionType, ARRAY8Ptr choice) { ChoicePtr c; int insert; int found; Debug ("Got indirect choice back (%s)\n", Print8Address(clientAddress)); for (c = choices; c; c = c->next) { if (XdmcpARRAY8Equal (clientAddress, &c->client) && connectionType == c->connectionType) { found = 1; break; } } if (!found) return 0; insert = 0; if (!c) { c = (ChoicePtr) malloc (sizeof (ChoiceRec)); insert = 1; if (!c) return 0; c->connectionType = connectionType; if (!XdmcpCopyARRAY8 (clientAddress, &c->client)) { free ((char *) c); return 0; } } else { XdmcpDisposeARRAY8 (&c->choice); } if (!XdmcpCopyARRAY8 (choice, &c->choice)) { XdmcpDisposeARRAY8 (&c->client); free ((char *) c); return 0; } if (insert) { c->next = choices; choices = c; } c->time = time (0); Debug("choice=(%s)\n", Print8Address(choice)); return 1; }
ARRAY8Ptr ChooseAuthentication(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; }
IsIndirectClient ( ARRAY8Ptr clientAddress, CARD16 connectionType) { IndirectUsersPtr i; for (i = indirectUsers; i; i = i->next) if (XdmcpARRAY8Equal (clientAddress, &i->client) && connectionType == i->connectionType) return 1; return 0; }
static void XdmcpSetAuthentication(const ARRAY8Ptr name) { int i; for (i = 0; i < AuthenticationNames.length; i++) if (XdmcpARRAY8Equal(&AuthenticationNames.data[i], name)) { AuthenticationName = &AuthenticationNames.data[i]; AuthenticationData = &AuthenticationDatas.data[i]; AuthenticationFuncs = &AuthenticationFuncsList[i]; break; } }
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); }
static int scanHostlist ( HostEntry *h, ARRAY8Ptr clientAddress, CARD16 connectionType, ChooserFunc function, char *closure, int depth, int broadcast) { int haveLocalhost = 0; for (; h; h = h->next) { switch (h->type) { case HOST_ALIAS: if (indirectAlias (h->entry.aliasName, clientAddress, connectionType, function, closure, depth, broadcast)) haveLocalhost = 1; break; case HOST_ADDRESS: if (XdmcpARRAY8Equal (getLocalAddress(), &h->entry.hostAddress)) haveLocalhost = 1; else if (function) (*function) (connectionType, &h->entry.hostAddress, closure); break; case HOST_BROADCAST: if (broadcast) { ARRAY8 temp; if (function) { temp.data = (BYTE *) BROADCAST_STRING; temp.length = strlen ((char *)temp.data); (*function) (connectionType, &temp, closure); } } break; } } return haveLocalhost; }
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); }
RememberIndirectClient ( ARRAY8Ptr clientAddress, CARD16 connectionType) { IndirectUsersPtr i; for (i = indirectUsers; i; i = i->next) if (XdmcpARRAY8Equal (clientAddress, &i->client) && connectionType == i->connectionType) return 1; i = (IndirectUsersPtr) malloc (sizeof (IndirectUsersRec)); if (!XdmcpCopyARRAY8 (clientAddress, &i->client)) { free ((char *) i); return 0; } i->connectionType = connectionType; i->next = indirectUsers; indirectUsers = i; return 1; }
static int scanEntrylist(int fh, int nh, ARRAY8Ptr clientAddress, CARD16 connectionType, char **clientName) { HostEntry *h; AliasEntry *a; int na; for (h = accData->hostList + fh; nh; nh--, h++) { switch (h->type) { case HOST_ALIAS: for (a = accData->aliasList, na = accData->nAliases; na; na--, a++) if (patternMatch(a->name, h->entry.aliasPattern)) if (scanEntrylist(a->hosts, a->nhosts, clientAddress, connectionType, clientName)) return True; break; case HOST_PATTERN: if (!*clientName) *clientName = networkAddressToHostname(connectionType, clientAddress); if (patternMatch(*clientName, h->entry.hostPattern)) return True; break; case HOST_ADDRESS: if (h->entry.displayAddress.connectionType == connectionType && XdmcpARRAY8Equal(&h->entry.displayAddress.hostAddress, clientAddress)) return True; break; default: break; } } return False; }
ForgetIndirectClient ( ARRAY8Ptr clientAddress, CARD16 connectionType) { IndirectUsersPtr i, prev; prev = 0; for (i = indirectUsers; i; i = i->next) { if (XdmcpARRAY8Equal (clientAddress, &i->client) && connectionType == i->connectionType) { if (prev) prev->next = i->next; else indirectUsers = i->next; XdmcpDisposeARRAY8 (&i->client); free ((char *) i); break; } prev = i; } }
static void scanHostlist(int fh, int nh, ARRAY8Ptr clientAddress, CARD16 connectionType, ChooserFunc function, char *closure, int broadcast, int *haveLocalhost) { HostEntry *h; AliasEntry *a; int na; for (h = accData->hostList + fh; nh; nh--, h++) { switch (h->type) { case HOST_ALIAS: for (a = accData->aliasList, na = accData->nAliases; na; na--, a++) if (patternMatch(a->name, h->entry.aliasPattern)) /* XXX originally swapped, no wildcards in alias name matching */ scanHostlist(a->hosts, a->nhosts, clientAddress, connectionType, function, closure, broadcast, haveLocalhost); break; case HOST_ADDRESS: if (haveLocalhost && XdmcpARRAY8Equal(getLocalAddress(), &h->entry.displayAddress.hostAddress)) *haveLocalhost = True; else if (function) (*function)(connectionType, &h->entry.displayAddress.hostAddress, closure); break; case HOST_BROADCAST: if (broadcast && function) (*function)(FamilyBroadcast, 0, closure); break; default: break; } } }