+void yf::AuthSimple::check_targets(mp::Package & package) const
+{
+ Z_InitRequest *initReq = package.request().get()->u.z3950->u.initRequest;
+
+ std::string password;
+ std::string user = get_user(initReq, password);
+ std::list<std::string> authorisedTargets = m_p->targetsByUser[user];
+
+ std::list<std::string> targets;
+ Z_OtherInformation **otherInfo = &initReq->otherInfo;
+ mp::util::remove_vhost_otherinfo(otherInfo, targets);
+
+ // Check each of the targets specified in the otherInfo package
+ std::list<std::string>::iterator i;
+
+ i = targets.begin();
+ while (i != targets.end()) {
+ if (contains(authorisedTargets, *i) ||
+ contains(authorisedTargets, "*")) {
+ i++;
+ } else {
+ if (!m_p->discardUnauthorisedTargets)
+ return reject_init(package,
+ YAZ_BIB1_ACCESS_TO_SPECIFIED_DATABASE_DENIED, i->c_str());
+ i = targets.erase(i);
+ }
+ }
+
+ if (targets.size() == 0)
+ return reject_init(package,
+ YAZ_BIB1_ACCESS_TO_SPECIFIED_DATABASE_DENIED,
+ // ### It would be better to use the Z-db name
+ "all databases");
+ mp::odr odr;
+ mp::util::set_vhost_otherinfo(otherInfo, odr, targets);
+ package.move();
+}
+