00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00025 #include "NameServer_i.h"
00026
00027 #include <fstream.h>
00028
00029 using namespace fbfs;
00030 using namespace utils;
00031
00032 fbfs::NameServer_i::NameServer_i(Prefs &p, const CORBA::ORB_ptr &o) : prefs(p), orb(o) {
00033 string rulefile = p.get("rulefile","nameserver-rules");
00034
00035 ifstream::ifstream s;
00036 s.open(rulefile.c_str());
00037 char buf[80];
00038 while(!s.eof()) {
00039 s.getline(buf,80);
00040 string s(buf);
00041 if(s.find("#")==0 || s.length() < 3)
00042 continue;
00043 int level = 0;
00044 while(s[level++]==' ');
00045 level--;
00046 string line = s.substr(level,s.length()-level);
00047 int i;
00048 i = line.find(" ");
00049 string command = line.substr(0,i);
00050 line = line.substr(i+1,line.length()-i-1);
00051 i = line.find(" ");
00052 string arg = line.substr(0,i);
00053
00054 Rule r(level, command, arg);
00055 rules.push_back(r);
00056 };
00057 };
00058
00059 char *fbfs::NameServer_i::lookup(const Security &cert, const Obj_id &id)
00060 throw(NotFound, SecurityException, InternalError) {
00061 string name(id.name);
00062 string result;
00063 int level = 0;
00064 bool go_deeper = true;
00065 bool exit_now = false;
00066 vector<Rule>::iterator i;
00067 for(i=rules.begin(); i != rules.end(); i++) {
00068 if(i->level <= level || go_deeper) {
00069 level = i->level;
00070 switch( i->eval(name, result, orb) ) {
00071 case Rule::FALSE:
00072 go_deeper = false;
00073 break;
00074 case Rule::TRUE:
00075 go_deeper = true;
00076 break;
00077 case Rule::OK:
00078 return CORBA::string_dup(result.c_str());
00079 break;
00080 case Rule::NOTFOUND:
00081 throw NotFound();
00082 };
00083 };
00084 if(exit_now)
00085 break;
00086 };
00087 throw NotFound();
00088 };