/**$Id:roxen.pike,v1.3291999/10/0623:07:36grubbaExp$**TheRoxenChallengermainpr
ogram.**PerHedbor,HenrikGrubbström,PontusHagland,DavidHedborandothers.*///ABSa
ndsuicidesystemscontributedfreelybyFrancescoChemolliconstantcvs_version="$Id:r
oxen.pike,v1.3291999/10/0623:07:36grubbaExp$";objectbackend_thread;objectargca
che;//Someheaderfiles#defineIN_ROXEN#includeroxen.h#includeconfig.h#includemod
ule.h#includevariables.h#includestat.h//Inheritsinherit"global_variables";inhe
rit"hosts";inherit"disk_cache";inherit"language";inherit"supports";/**Versioni
nformation*/constant__roxen_version__="1.4";constant__roxen_build__="0";#ifdef
__NT__stringreal_version="RoxenChallenger/"+__roxen_version__+"."+__roxen_buil
d__+"NT";#elsestringreal_version="RoxenChallenger/"+__roxen_version__+"."+__ro
xen_build__;#endif//Prototypesforotherpartsofroxen.classRequestID{objectconf;/
/ReallyConfiguration,butthat'ssortofrecursive.inttime;stringraw_url;intdo_not_
disconnect;mapping(string:string)variables;mapping(string:mixed)misc;mapping(s
tring:string)cookies;mapping(string:string)request_headers;multiset(string)pre
state;multiset(string)config;multiset(string)supports;multiset(string)pragma;a
rray(string)client;array(string)referer;Stdio.Filemy_fd;stringprot;stringclien
tprot;stringmethod;stringrealfile;stringvirtfile;stringrest_query;stringraw;st
ringquery;stringnot_query;stringextra_extension;stringdata;stringleftovers;arr
ay(int|string)auth;stringrawauth;stringrealauth;stringsince;stringremoteaddr;s
tringhost;voidcreate(object|voidmaster_request_id);voidsend(string|objectwhat,
int|voidlen);stringscan_for_query(stringin);voidend(string|voids,int|voidkeepi
t);voidready_to_receive();voidsend_result(mapping|voidresult);RequestIDclone_m
e();};stringfilename(objecto){returnsearch(master()-programs,object_program(o)
);}#ifdefTHREADS//ThismutexisusedbyPrivsobjecteuid_egid_lock=Thread.Mutex();#e
ndif/*THREADS*//**Theprivilegechanger.**Basedonprivs.pike,v1.36.*/intprivs_lev
el;staticclassPrivs{#ifefun(seteuid)intsaved_uid;intsaved_gid;intnew_uid;intne
w_gid;#defineLOGP(variablesvariables-auditGLOBVAR(audit))#ifconstant(geteuid)c
onstant(getegid)constant(seteuid)constant(setegid)#defineHAVE_EFFECTIVE_USER#e
ndifstaticprivatestring_getcwd(){if(catch{return(getcwd());}){return("Unknownd
irectory(nox-bitoncurrentdirectory?)");}}staticprivatestringdbt(arrayt){if(!ar
rayp(t)||(sizeof(t)2))return"";return(((t[0]||"Unknownprogram")-(_getcwd()+"/"
))-"base_server/")+":"+t[1]+"\n";}#ifdefTHREADSstaticmixedmutex_key;//Onlyonet
hreadmaymodifytheeuid/egidatatime.staticobjectthreads_disabled;#endif/*THREADS
*/intp_level;voidcreate(stringreason,int|string|voiduid,int|string|voidgid){#i
fdefPRIVS_DEBUGwerror(sprintf("Privs(%O,%O,%O)\n""privs_level:%O\n",reason,uid
,gid,privs_level));#endif/*PRIVS_DEBUG*/#ifdefHAVE_EFFECTIVE_USERarrayu;#ifdef
THREADSif(euid_egid_lock){catch{mutex_key=euid_egid_lock-lock();};}threads_dis
abled=_disable_threads();#endif/*THREADS*/p_level=privs_level++;if(getuid())re
turn;/*Needstobeheresinceroot-priviligesmaybeneededto*usegetpw{uid,nam}.*/save
d_uid=geteuid();saved_gid=getegid();seteuid(0);/*Astringofdigits?*/if(stringp(
uid)(replace(uid,"0123456789"/"",({""})*10)==""))uid=(int)uid;if(stringp(gid)(