void Greeter::gplugReturnBinary( const char *data ) { if (data) { unsigned const char *up = (unsigned const char *)data; int len = up[3] | (up[2] << 8) | (up[1] << 16) | (up[0] << 24); if (!len) GSendArr( 4, data ); else GSendArr( len, data ); } else GSendArr( 0, 0 ); }
static void ReadAccessFile( const char *fname ) { HostEntry *hostList, **hostPtr = &hostList; AliasEntry *aliasList, **aliasPtr = &aliasList; AclEntry *acList, **acPtr = &acList, *acl; ListenEntry *listenList, **listenPtr = &listenList; char *displayOrAlias, *hostOrAlias; File file; int nHosts, nAliases, nAcls, nListens, nChars, error, bad; int i, len; nHosts = nAliases = nAcls = nListens = nChars = error = 0; if (!readFile( &file, fname, "XDMCP access control" )) goto sendacl; while ((displayOrAlias = ReadWord( &file, &len, FALSE ))) { if (*displayOrAlias == ALIAS_CHARACTER) { if (!(*aliasPtr = (AliasEntry *)Malloc( sizeof(AliasEntry)))) { error = 1; break; } (*aliasPtr)->name = displayOrAlias + 1; nChars += len; (*aliasPtr)->hosts = nHosts; (*aliasPtr)->pHosts = hostPtr; (*aliasPtr)->nhosts = 0; (*aliasPtr)->hasBad = 0; while ((hostOrAlias = ReadWord( &file, &len, TRUE ))) { if (ParseHost( &nHosts, &hostPtr, &nChars, hostOrAlias, len, PARSE_NO_BCAST )) (*aliasPtr)->nhosts++; else (*aliasPtr)->hasBad = 1; } aliasPtr = &(*aliasPtr)->next; nAliases++; } else if (!strcmp( displayOrAlias, LISTEN_STRING )) { if (!(*listenPtr = (ListenEntry *)Malloc( sizeof(ListenEntry)))) { error = 1; break; } (*listenPtr)->iface = nHosts; if (!(hostOrAlias = ReadWord( &file, &len, TRUE )) || !strcmp( hostOrAlias, WILDCARD_STRING ) || !ParseHost( &nHosts, &hostPtr, &nChars, hostOrAlias, len, PARSE_NO_BCAST|PARSE_NO_PAT|PARSE_NO_ALIAS )) { (*listenPtr)->iface = -1; } (*listenPtr)->mcasts = nHosts; (*listenPtr)->nmcasts = 0; while ((hostOrAlias = ReadWord( &file, &len, TRUE ))) { if (ParseHost( &nHosts, &hostPtr, &nChars, hostOrAlias, len, PARSE_NO_BCAST|PARSE_NO_PAT|PARSE_NO_ALIAS )) (*listenPtr)->nmcasts++; } listenPtr = &(*listenPtr)->next; nListens++; } else { if (!(*acPtr = (AclEntry *)Malloc( sizeof(AclEntry)))) { error = 1; break; } (*acPtr)->flags = 0; if (*displayOrAlias == NEGATE_CHARACTER) { (*acPtr)->flags |= a_notAllowed; displayOrAlias++; } else if (*displayOrAlias == EQUAL_CHARACTER) displayOrAlias++; (*acPtr)->entries = nHosts; (*acPtr)->pEntries = hostPtr; (*acPtr)->nentries = 1; if (!ParseHost( &nHosts, &hostPtr, &nChars, displayOrAlias, len, PARSE_NO_BCAST )) { bad = 1; if ((*acPtr)->flags & a_notAllowed) { LogError( "XDMCP ACL: unresolved host in denying rule\n" ); error = 1; } } else bad = 0; (*acPtr)->hosts = nHosts; (*acPtr)->pHosts = hostPtr; (*acPtr)->nhosts = 0; while ((hostOrAlias = ReadWord( &file, &len, TRUE ))) { if (!strcmp( hostOrAlias, CHOOSER_STRING )) (*acPtr)->flags |= a_useChooser; else if (!strcmp( hostOrAlias, NOBROADCAST_STRING )) (*acPtr)->flags |= a_notBroadcast; else { if (ParseHost( &nHosts, &hostPtr, &nChars, hostOrAlias, len, PARSE_NO_PAT )) (*acPtr)->nhosts++; } } if (!bad) { acPtr = &(*acPtr)->next; nAcls++; } } } if (!nListens) { if (!(*listenPtr = (ListenEntry *)Malloc( sizeof(ListenEntry)))) error = 1; else { (*listenPtr)->iface = -1; (*listenPtr)->mcasts = nHosts; (*listenPtr)->nmcasts = 0; #if defined(IPv6) && defined(AF_INET6) && defined(XDM_DEFAULT_MCAST_ADDR6) if (ParseHost( &nHosts, &hostPtr, &nChars, XDM_DEFAULT_MCAST_ADDR6, sizeof(XDM_DEFAULT_MCAST_ADDR6)-1, PARSE_ALL )) (*listenPtr)->nmcasts++; #endif nListens++; } } for (acl = acList, i = 0; i < nAcls; i++, acl = acl->next) if (checkHostlist( acl->pEntries, acl->nentries, aliasList, nAliases, 0, (acl->flags & a_notAllowed) ? CHECK_NOT : 0 ) || checkHostlist( acl->pHosts, acl->nhosts, aliasList, nAliases, 0, CHECK_NO_PAT )) error = 1; if (error) { nHosts = nAliases = nAcls = nListens = nChars = 0; sendacl: LogError( "No XDMCP requests will be granted\n" ); } GSendInt( nHosts ); GSendInt( nListens ); GSendInt( nAliases ); GSendInt( nAcls ); GSendInt( nChars ); for (i = 0; i < nHosts; i++, hostList = hostList->next) { GSendInt( hostList->type ); switch (hostList->type) { case HOST_ALIAS: GSendStr( hostList->entry.aliasPattern ); break; case HOST_PATTERN: GSendStr( hostList->entry.hostPattern ); break; case HOST_ADDRESS: GSendArr( hostList->entry.displayAddress.hostAddrLen, hostList->entry.displayAddress.hostAddress ); GSendInt( hostList->entry.displayAddress.connectionType ); break; } } for (i = 0; i < nListens; i++, listenList = listenList->next) { GSendInt( listenList->iface ); GSendInt( listenList->mcasts ); GSendInt( listenList->nmcasts ); } for (i = 0; i < nAliases; i++, aliasList = aliasList->next) { GSendStr( aliasList->name ); GSendInt( aliasList->hosts ); GSendInt( aliasList->nhosts ); } for (i = 0; i < nAcls; i++, acList = acList->next) { GSendInt( acList->entries ); GSendInt( acList->nentries ); GSendInt( acList->hosts ); GSendInt( acList->nhosts ); GSendInt( acList->flags ); } }