#include #include #include #include #include #include #include #include using namespace std; int main (int argc, char *argv[]) { glocal int ret = -1; glocal const char *unixpath = "/var/run/blackhole/horizon-ident.sock"; glocal bool daemon = false; glocal const char *pidfile = "/var/run/blackhole/horizon-ident.pid"; glocal const char *foruser = "blackhole"; glocal.ret = (argc,argv); setproginfo("horizon_ident",VERSION,"Use the ident protocol to get user information"); setarg ('d',"daemon","Run in background",glocal.daemon,false); setarg (' ',"pidfile","PID file",glocal.pidfile,false); setarg ('s',"unixsock","Unix socket",glocal.unixpath,false); setarg (' ',"foruser","Unix socket usable by this user",glocal.foruser,false); if (glocal.daemon){ syslog (LOG_ERR,"%s",msg); }else{ fprintf (stderr,"%s",msg); } if (glocal.daemon){ syslog (LOG_WARNING,"%s",msg); }else{ fprintf (stderr,"%s",msg); } int ret = -1; glocal set identservers; // Server that we trust glocal set n_identservers; // Servers we are configuring string tmp = string("unix:") + glocal.unixpath; (tmp.c_str(),1); //printf ("line=%s\n",line); if (strcmp(line,"status")==0){ sendf ("horizon-ident version %s\n",VERSION); for (set::iterator it=glocal.identservers.begin(); it != glocal.identservers.end(); it++){ sendf ("server %s\n",it->c_str()); } }else if (strcmp(line,"n-clear")==0){ glocal.n_identservers.clear(); }else if (strcmp(line,"n-commit")==0){ glocal.identservers = glocal.n_identservers; }else if (strncmp(line,"n-server ",9)==0){ const char *pt = str_skip(line+9); glocal.n_identservers.insert(pt); }else if (strncmp(line,"ident ",6)==0){ vector words; int n = str_splitline(line+6,' ',words); if (n != 4){ send ("Invalid ident command, expects 4 arguments\n"); }else if (glocal.identservers.count(words[0])>0){ glocal string req = words[1] + ", " + words[3]; (words[0].c_str(),"113",10); //printf ("ident request: %s\n",glocal.req.c_str()); sendf ("%s\n",glocal.req.c_str()); //printf ("ident rec %s\n",line); vector words; int n = str_splitline(line,':',words); if (n != 4 || words[1] != "USERID"){ tlmp_error ("Invalid answer from server %s: %s\n",info.host,line); }else{ strip_end (words[3]); //printf ("user is :%s: %lu\n",words[3].c_str(),words[3].size()); glocal.TCPSERVER.sendf ("user %s\n",words[3].c_str()); } end = true; tlmp_error ("Can't connect to the identd server %s (%s)\n",info.host,strerror(errno)); }else{ //printf ("Not a trusted server %s\n",words[0].c_str()); } }else{ send ("Invalid command\n"); } send ("OK\n"); endclient = true; if (o.is_ok()){ ret = 0; if (glocal.daemon){ daemon_init (glocal.pidfile,glocal.foruser); } o.loop(); }else{ tlmp_error ("Can't setup unix socket %s (%s)\n",glocal.unixpath,strerror(errno)); } return ret; return glocal.ret; }