+void mp::filter::AuthSimple::config_userRegister(std::string filename)
+{
+ FILE *fp = fopen(filename.c_str(), "r");
+ if (fp == 0)
+ die("can't open auth_simple user-register '" + filename + "': " +
+ strerror(errno));
+
+ char buf[1000];
+ while (fgets(buf, sizeof buf, fp))
+ {
+ if (*buf == '\n' || *buf == '#')
+ continue;
+ buf[strlen(buf)-1] = 0;
+ char *passwdp = strchr(buf, ':');
+ if (passwdp == 0)
+ die("auth_simple user-register '" + filename + "': " +
+ "no password on line: '" + buf + "'");
+ *passwdp++ = 0;
+ char *databasesp = strchr(passwdp, ':');
+ if (databasesp == 0)
+ die("auth_simple user-register '" + filename + "': " +
+ "no databases on line: '" + buf + ":" + passwdp + "'");
+ *databasesp++ = 0;
+ yf::AuthSimple::Rep::PasswordAndDBs tmp(passwdp);
+ split_db(tmp.dbs, databasesp);
+ m_p->userRegister[buf] = tmp;
+
+ if (0)
+ { // debugging
+ printf("Added user '%s' -> password '%s'\n", buf, passwdp);
+ std::list<std::string>::const_iterator i;
+ for (i = tmp.dbs.begin(); i != tmp.dbs.end(); i++)
+ printf("db '%s'\n", (*i).c_str());
+ }
+ }
+ fclose(fp);
+}
+
+
+// I feel a little bad about the duplication of code between this and
+// config_userRegister(). But not bad enough to refactor.
+//
+void mp::filter::AuthSimple::config_targetRegister(std::string filename)
+{
+ FILE *fp = fopen(filename.c_str(), "r");
+ if (fp == 0)
+ die("can't open auth_simple target-register '" + filename + "': " +
+ strerror(errno));
+
+ char buf[1000];
+ while (fgets(buf, sizeof buf, fp)) {
+ if (*buf == '\n' || *buf == '#')
+ continue;
+ buf[strlen(buf)-1] = 0;
+ char *targetsp = strchr(buf, ':');
+ if (targetsp == 0)
+ die("auth_simple target-register '" + filename + "': " +
+ "no targets on line: '" + buf + "'");
+ *targetsp++ = 0;
+ std::list<std::string> tmp;
+ split_db(tmp, targetsp);
+ m_p->targetsByUser[buf] = tmp;
+
+ if (0) { // debugging
+ printf("Added user '%s' with targets:\n", buf);
+ std::list<std::string>::const_iterator i;
+ for (i = tmp.begin(); i != tmp.end(); i++) {
+ printf("\t%s\n", (*i).c_str());
+ }
+ }
+ }
+}
+
+
+void yf::AuthSimple::process(mp::Package &package) const
+{
+ Z_GDU *gdu = package.request().get();
+
+ if (!gdu || gdu->which != Z_GDU_Z3950) {
+ // Pass on the package -- This means that authentication is
+ // waived, which may not be the correct thing for non-Z APDUs
+ // as it means that SRW sessions don't demand authentication
+ return package.move();
+ }
+
+ if (m_p->got_userRegister) {
+ switch (gdu->u.z3950->which) {
+ case Z_APDU_initRequest: return process_init(package);
+ case Z_APDU_searchRequest: return process_search(package);
+ case Z_APDU_scanRequest: return process_scan(package);
+ // In theory, we should check database authorisation for
+ // extended services, too (A) the proxy currently does not
+ // implement XS and turns off its negotiation bit; (B) it
+ // would be insanely complex to do as the top-level XS request
+ // structure does not carry a database name, but it is buried
+ // down in some of the possible EXTERNALs used as
+ // taskSpecificParameters; and (C) since many extended
+ // services modify the database, we'd need to more exotic
+ // authorisation database than we want to support.
+ default: break;
+ }
+ }
+
+ if (m_p->got_targetRegister && gdu->u.z3950->which == Z_APDU_initRequest)
+ return check_targets(package);