ws_accessService.cpp 128 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #pragma warning (disable : 4786)
  14. #include <stdlib.h>
  15. #include "ws_accessService.hpp"
  16. #include "exception_util.hpp"
  17. #include "dasess.hpp"
  18. #include <set>
  19. #define MSG_SEC_MANAGER_IS_NULL "Security manager is not found. Please check if the system authentication is set up correctly"
  20. #define MAX_USERS_DISPLAY 400
  21. #define MAX_RESOURCES_DISPLAY 3000
  22. static const long MAXXLSTRANSFER = 5000000;
  23. void checkUser(IEspContext& context)
  24. {
  25. CLdapSecManager* secmgr = dynamic_cast<CLdapSecManager*>(context.querySecManager());
  26. if(secmgr == NULL)
  27. throw MakeStringException(ECLWATCH_INVALID_SEC_MANAGER, MSG_SEC_MANAGER_IS_NULL);
  28. if(!secmgr->isSuperUser(context.queryUser()))
  29. throw MakeStringException(ECLWATCH_ADMIN_ACCESS_DENIED, "Access denied, administrators only.");
  30. }
  31. void Cws_accessEx::init(IPropertyTree *cfg, const char *process, const char *service)
  32. {
  33. if(cfg == NULL)
  34. throw MakeStringException(-1, "can't initialize Cws_accessEx, cfg is NULL");
  35. StringBuffer xpath;
  36. xpath.appendf("Software/EspProcess[@name=\"%s\"]/EspService[@name=\"%s\"]", process, service);
  37. IPropertyTree* servicecfg = cfg->getPropTree(xpath.str());
  38. if(servicecfg == NULL)
  39. {
  40. WARNLOG(-1, "config not found for service %s/%s",process, service);
  41. return;
  42. }
  43. m_servicecfg.setown(servicecfg);
  44. /* Config is like -
  45. <Modules basedn="ou=le,ou=ecl,dc=le">
  46. <Eclserver name="eclserver" basedn="ou=le,ou=ecl,dc=le" templateName="repository.newmoduletemplate"/>
  47. </Modules>
  48. <Files basedn="ou=Files,ou=ecl"/>
  49. <Resources>
  50. <Binding name="EspBinding" service="espsmc" port="8010" basedn="ou=SMC,ou=EspServices,ou=ecl" workunitsBasedn="ou=workunits,ou=ecl"/>
  51. </Resources>
  52. */
  53. Owned<IPropertyTreeIterator> eclservers = m_servicecfg->getElements("Modules/Eclserver");
  54. for (eclservers->first(); eclservers->isValid(); eclservers->next())
  55. {
  56. const char *templatename = eclservers->query().queryProp("@templateName");
  57. const char* basedn = eclservers->query().queryProp("@basedn");
  58. if(basedn && *basedn)
  59. {
  60. StringBuffer name, head;
  61. const char* eclservername = eclservers->query().queryProp("@name");
  62. name.append("Repository Modules for ").append(eclservername);
  63. Owned<IEspDnStruct> onedn = createDnStruct();
  64. onedn->setBasedn(basedn);
  65. onedn->setName(name.str());
  66. onedn->setRtype("module");
  67. onedn->setRtitle("Module");
  68. if(templatename != NULL)
  69. {
  70. onedn->setTemplatename(templatename);
  71. }
  72. m_rawbasedns.append(*onedn.getLink());
  73. }
  74. }
  75. const char* modules_basedn = m_servicecfg->queryProp("Modules/@basedn");
  76. if(modules_basedn && *modules_basedn)
  77. {
  78. Owned<IEspDnStruct> onedn = createDnStruct();
  79. onedn->setBasedn(modules_basedn);
  80. onedn->setName("Repository Modules");
  81. onedn->setRtype("module");
  82. onedn->setRtitle("Module");
  83. m_rawbasedns.append(*onedn.getLink());
  84. }
  85. const char* files_basedn = m_servicecfg->queryProp("Files/@basedn");
  86. if(files_basedn && *files_basedn)
  87. {
  88. Owned<IEspDnStruct> onedn = createDnStruct();
  89. onedn->setBasedn(files_basedn);
  90. onedn->setName("File Scopes");
  91. onedn->setRtype("file");
  92. m_rawbasedns.append(*onedn.getLink());
  93. onedn->setRtitle("FileScope");
  94. }
  95. StringBuffer workunits_basedn;
  96. Owned<IPropertyTreeIterator> bindings = m_servicecfg->getElements("Resources/Binding");
  97. for (bindings->first(); bindings->isValid(); bindings->next())
  98. {
  99. const char *service = bindings->query().queryProp("@service");
  100. const char* basedn = bindings->query().queryProp("@basedn");
  101. if(workunits_basedn.length() == 0)
  102. {
  103. const char* wubasedn = bindings->query().queryProp("@workunitsBasedn");
  104. if(wubasedn != NULL)
  105. workunits_basedn.append(wubasedn);
  106. }
  107. if(basedn && *basedn)
  108. {
  109. StringBuffer name, head;
  110. name.append("Esp Features for ");
  111. const char* bptr = basedn;
  112. while(*bptr != '\0' && *bptr != '=')
  113. bptr++;
  114. if(*bptr != '\0')
  115. bptr++;
  116. const char* colon = strstr(bptr, ",");
  117. if(colon == NULL)
  118. head.append(bptr);
  119. else
  120. head.append(colon - bptr, bptr);
  121. if(stricmp(head.str(), "WsAttributesAccess") == 0)
  122. continue;
  123. Owned<IEspDnStruct> onedn = createDnStruct();
  124. onedn->setBasedn(basedn);
  125. name.append(head.str());
  126. onedn->setName(name.str());
  127. onedn->setRtype("service");
  128. head.append(" Feature");
  129. onedn->setRtitle(head.str());
  130. m_rawbasedns.append(*onedn.getLink());
  131. }
  132. }
  133. if(workunits_basedn.length() > 0)
  134. {
  135. Owned<IEspDnStruct> onedn = createDnStruct();
  136. onedn->setBasedn(workunits_basedn.str());
  137. onedn->setName("Workunit Scopes");
  138. onedn->setRtype("workunit");
  139. onedn->setRtitle("WorkunitScope");
  140. m_rawbasedns.append(*onedn.getLink());
  141. }
  142. }
  143. void Cws_accessEx::setBasedns(IEspContext &context)
  144. {
  145. CLdapSecManager* secmgr = (CLdapSecManager*)(context.querySecManager());
  146. if(secmgr == NULL)
  147. throw MakeStringException(ECLWATCH_INVALID_SEC_MANAGER, MSG_SEC_MANAGER_IS_NULL);
  148. set<string> alreadythere;
  149. ForEachItemInRev(x, m_rawbasedns)
  150. {
  151. IEspDnStruct* basedn = &(m_rawbasedns.popGet());
  152. const char* tname = basedn->getTemplatename();
  153. StringBuffer nbasedn;
  154. secmgr->normalizeDn(basedn->getBasedn(), nbasedn);
  155. if(alreadythere.find(nbasedn.str()) == alreadythere.end())
  156. {
  157. alreadythere.insert(nbasedn.str());
  158. Owned<IEspDnStruct> onedn = createDnStruct();
  159. onedn->setBasedn(nbasedn.str());
  160. onedn->setName(basedn->getName());
  161. onedn->setRtype(basedn->getRtype());
  162. onedn->setRtitle(basedn->getRtitle());
  163. if(tname != NULL && *tname != '\0')
  164. onedn->setTemplatename(tname);
  165. m_basedns.append(*onedn.getLink());
  166. }
  167. else
  168. {
  169. ForEachItemIn(y, m_basedns)
  170. {
  171. IEspDnStruct* curbasedn = &(m_basedns.item(y));
  172. if(stricmp(curbasedn->getBasedn(), nbasedn.str()) == 0)
  173. {
  174. const char* curtname = curbasedn->getTemplatename();
  175. if((curtname == NULL || *curtname == '\0') && (tname != NULL && *tname != '\0'))
  176. curbasedn->setTemplatename(tname);
  177. break;
  178. }
  179. }
  180. }
  181. }
  182. return;
  183. }
  184. bool Cws_accessEx::getNewFileScopePermissions(ISecManager* secmgr, IEspResourceAddRequest &req, StringBuffer& existingResource, StringArray& newResources)
  185. {
  186. if (!secmgr)
  187. return false;
  188. const char* name0 = req.getName();
  189. if (!name0 || !*name0)
  190. return false;
  191. char* pStr0 = (char*) name0;
  192. while (pStr0[0] == ':') //in case of some ':' by mistake
  193. pStr0++;
  194. if (pStr0[0] == 0)
  195. return false;
  196. StringBuffer lastFileScope;
  197. char* pStr = strstr(pStr0, "::");
  198. while (pStr)
  199. {
  200. char fileScope[10240];
  201. strncpy(fileScope, pStr0, pStr-pStr0);
  202. fileScope[pStr-pStr0] = 0;
  203. if (lastFileScope.length() < 1)
  204. lastFileScope.append(fileScope);
  205. else
  206. lastFileScope.appendf("::%s", fileScope);
  207. newResources.append(lastFileScope.str());
  208. pStr0 = pStr+2;
  209. while (pStr0[0] == ':') //in case of more than two ':' by mistake
  210. pStr0++;
  211. if (pStr0[0] == 0)
  212. break;
  213. pStr = strstr(pStr0, "::");
  214. }
  215. if (pStr0[0] != 0)
  216. {
  217. if (lastFileScope.length() < 1)
  218. lastFileScope.append(pStr0);
  219. else
  220. lastFileScope.appendf("::%s", pStr0);
  221. newResources.append(lastFileScope.str());
  222. }
  223. CLdapSecManager* ldapsecmgr = (CLdapSecManager*)secmgr;
  224. while (newResources.ordinality())
  225. {
  226. StringBuffer namebuf = newResources.item(0);
  227. try
  228. {
  229. IArrayOf<CPermission> permissions;
  230. ldapsecmgr->getPermissionsArray(req.getBasedn(), str2type(req.getRtype()), namebuf.str(), permissions);
  231. if (!permissions.ordinality())
  232. {
  233. break;
  234. }
  235. }
  236. catch(IException* e) //exception may be thrown when no permission for the resource
  237. {
  238. e->Release();
  239. break;
  240. }
  241. existingResource.clear().append(namebuf);
  242. newResources.remove(0);
  243. }
  244. return true;
  245. }
  246. bool Cws_accessEx::setNewFileScopePermissions(ISecManager* secmgr, IEspResourceAddRequest &req, StringBuffer& existingResource, StringArray& newResources)
  247. {
  248. if (!secmgr || !newResources.ordinality())
  249. {
  250. return false;
  251. }
  252. const char* basedn = req.getBasedn();
  253. if (!basedn || !*basedn)
  254. {
  255. return false;
  256. }
  257. StringBuffer basednBuf;
  258. basednBuf.append(basedn);
  259. if (existingResource.length() < 1)
  260. {
  261. existingResource.append("files");
  262. const char* comma = strchr(basedn, ',');
  263. const char* eqsign = strchr(basedn, '=');
  264. if(eqsign && comma && (strlen(comma) > 1))
  265. {
  266. basednBuf.clear().append(comma + 1);
  267. }
  268. }
  269. IArrayOf<CPermission> requiredPermissions;
  270. CLdapSecManager* ldapsecmgr = (CLdapSecManager*)secmgr;
  271. ldapsecmgr->getPermissionsArray(basednBuf, str2type(req.getRtype()), existingResource.str(), requiredPermissions);
  272. if (!requiredPermissions.ordinality())
  273. {
  274. return false;
  275. }
  276. ForEachItemIn(x, requiredPermissions)
  277. {
  278. CPermission& perm = requiredPermissions.item(x);
  279. int accType = perm.getAccount_type(); //0-individual, 1 - group
  280. const char* actname = perm.getAccount_name();
  281. if (!actname || !*actname)
  282. continue;
  283. CPermissionAction paction;
  284. paction.m_basedn.append(req.getBasedn());
  285. paction.m_rtype = str2type(req.getRtype());
  286. paction.m_account_type = (ACT_TYPE)accType;
  287. paction.m_account_name.append(actname);
  288. paction.m_allows = perm.getAllows();
  289. paction.m_denies = perm.getDenies();
  290. if ((accType != GROUP_ACT) || ((stricmp(actname, "Administrators") != 0) && (stricmp(actname, "Authenticated Users") != 0)))
  291. {
  292. paction.m_action.append("add");
  293. }
  294. else
  295. {
  296. paction.m_action.append("update");
  297. }
  298. ForEachItemIn(y, newResources)
  299. {
  300. StringBuffer namebuf = newResources.item(y);
  301. paction.m_rname.clear().append(namebuf.str());
  302. ldapsecmgr->changePermission(paction);
  303. }
  304. }
  305. return true;
  306. }
  307. bool Cws_accessEx::onUsers(IEspContext &context, IEspUserRequest &req, IEspUserResponse &resp)
  308. {
  309. try
  310. {
  311. CLdapSecManager* secmgr = dynamic_cast<CLdapSecManager*>(context.querySecManager());
  312. double version = context.getClientVersion();
  313. if (version > 1.03)
  314. {
  315. if(secmgr == NULL)
  316. {
  317. resp.setNoSecMngr(true);
  318. return true;
  319. }
  320. }
  321. else
  322. {
  323. if(secmgr == NULL)
  324. throw MakeStringException(ECLWATCH_INVALID_SEC_MANAGER, MSG_SEC_MANAGER_IS_NULL);
  325. }
  326. checkUser(context);
  327. const char* searchstr = req.getSearchinput();
  328. int numusers = secmgr->countUsers(searchstr, MAX_USERS_DISPLAY);
  329. if(numusers == -1)
  330. {
  331. resp.setToomany(true);
  332. return true;
  333. }
  334. resp.setToomany(false);
  335. /*
  336. LdapServerType servertype = secmgr->getLdapServerType();
  337. if(servertype != ACTIVE_DIRECTORY)
  338. resp.setPosixok(true);
  339. else
  340. resp.setPosixok(false);
  341. */
  342. resp.setPosixok(false);
  343. IArrayOf<IEspUserInfo> espusers;
  344. IUserArray users;
  345. secmgr->searchUsers(searchstr, users);
  346. ForEachItemIn(x, users)
  347. {
  348. ISecUser* usr = &users.item(x);
  349. if(usr)
  350. {
  351. Owned<IEspUserInfo> oneusr = createUserInfo();
  352. oneusr->setUsername(usr->getName());
  353. oneusr->setFullname(usr->getFullName());
  354. double version = context.getClientVersion();
  355. if (version >= 1.07)
  356. {
  357. StringBuffer sb;
  358. switch (usr->getPasswordDaysRemaining())//-1 if expired, -2 if never expires
  359. {
  360. case -1:
  361. sb.set("Expired");
  362. break;
  363. case -2:
  364. sb.set("Never");
  365. break;
  366. default:
  367. {
  368. CDateTime dt;
  369. usr->getPasswordExpiration(dt);
  370. dt.getDateString(sb);
  371. break;
  372. }
  373. }
  374. oneusr->setPasswordexpiration(sb.str());
  375. }
  376. espusers.append(*oneusr.getLink());
  377. }
  378. }
  379. resp.setUsers(espusers);
  380. }
  381. catch(IException* e)
  382. {
  383. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  384. }
  385. return true;
  386. }
  387. bool Cws_accessEx::onUserEdit(IEspContext &context, IEspUserEditRequest &req, IEspUserEditResponse &resp)
  388. {
  389. try
  390. {
  391. checkUser(context);
  392. ISecManager* secmgr = context.querySecManager();
  393. if(secmgr == NULL)
  394. throw MakeStringException(ECLWATCH_INVALID_SEC_MANAGER, MSG_SEC_MANAGER_IS_NULL);
  395. CLdapSecManager* ldapsecmgr = (CLdapSecManager*)secmgr;
  396. resp.setUsername(req.getUsername());
  397. StringArray groupnames;
  398. ldapsecmgr->getGroups(req.getUsername(), groupnames);
  399. IArrayOf<IEspGroupInfo> groups;
  400. for(unsigned i = 0; i < groupnames.length(); i++)
  401. {
  402. const char* grpname = groupnames.item(i);
  403. if(grpname == NULL || grpname[0] == '\0')
  404. continue;
  405. Owned<IEspGroupInfo> onegrp = createGroupInfo();
  406. onegrp->setName(grpname);
  407. groups.append(*onegrp.getLink());
  408. }
  409. resp.setGroups(groups);
  410. }
  411. catch(IException* e)
  412. {
  413. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  414. }
  415. return true;
  416. }
  417. bool Cws_accessEx::onUserGroupEditInput(IEspContext &context, IEspUserGroupEditInputRequest &req, IEspUserGroupEditInputResponse &resp)
  418. {
  419. try
  420. {
  421. checkUser(context);
  422. ISecManager* secmgr = context.querySecManager();
  423. if(secmgr == NULL)
  424. throw MakeStringException(ECLWATCH_INVALID_SEC_MANAGER, MSG_SEC_MANAGER_IS_NULL);
  425. CLdapSecManager* ldapsecmgr = (CLdapSecManager*)secmgr;
  426. resp.setUsername(req.getUsername());
  427. set<string> ogrps;
  428. ogrps.insert("Authenticated Users");
  429. StringArray grps;
  430. ldapsecmgr->getGroups(req.getUsername(), grps);
  431. unsigned i = 0;
  432. for(i = 0; i < grps.length(); i++)
  433. {
  434. const char* grp = grps.item(i);
  435. if(grp != NULL && *grp != '\0')
  436. {
  437. ogrps.insert(grp);
  438. }
  439. }
  440. StringArray groupnames;
  441. ldapsecmgr->getAllGroups(groupnames);
  442. IArrayOf<IEspGroupInfo> groups;
  443. for(i = 0; i < groupnames.length(); i++)
  444. {
  445. const char* grpname = groupnames.item(i);
  446. if(grpname == NULL || grpname[0] == '\0')
  447. continue;
  448. if(ogrps.find(grpname) == ogrps.end())
  449. {
  450. Owned<IEspGroupInfo> onegrp = createGroupInfo();
  451. onegrp->setName(grpname);
  452. groups.append(*onegrp.getLink());
  453. }
  454. }
  455. resp.setGroups(groups);
  456. }
  457. catch(IException* e)
  458. {
  459. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  460. }
  461. return true;
  462. }
  463. bool Cws_accessEx::onUserGroupEdit(IEspContext &context, IEspUserGroupEditRequest &req, IEspUserGroupEditResponse &resp)
  464. {
  465. try
  466. {
  467. checkUser(context);
  468. CLdapSecManager* secmgr = (CLdapSecManager*)(context.querySecManager());
  469. if(secmgr == NULL)
  470. throw MakeStringException(ECLWATCH_INVALID_SEC_MANAGER, MSG_SEC_MANAGER_IS_NULL);
  471. const char* username = req.getUsername();
  472. if(username == NULL || *username == '\0')
  473. {
  474. resp.setRetcode(-1);
  475. resp.setRetmsg("username can't be empty");
  476. return false;
  477. }
  478. StringArray& groupnames = req.getGroupnames();
  479. try
  480. {
  481. for(unsigned i = 0; i < groupnames.length(); i++)
  482. {
  483. const char* grpname = groupnames.item(i);
  484. if(grpname == NULL || *grpname == '\0')
  485. continue;
  486. secmgr->changeUserGroup(req.getAction(), username, grpname);
  487. }
  488. }
  489. catch(IException* e)
  490. {
  491. StringBuffer errmsg;
  492. e->errorMessage(errmsg);
  493. DBGLOG("error changing user's group membership: %s", errmsg.str());
  494. resp.setRetcode(e->errorCode());
  495. resp.setRetmsg(errmsg.str());
  496. return false;
  497. }
  498. resp.setRetcode(0);
  499. resp.setUsername(username);
  500. resp.setAction(req.getAction());
  501. if(stricmp(req.getAction(), "add") == 0)
  502. resp.setRetmsg("user successfully added to groups");
  503. else
  504. resp.setRetmsg("user successfully deleted from groups");
  505. }
  506. catch(IException* e)
  507. {
  508. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  509. }
  510. return true;
  511. }
  512. bool Cws_accessEx::onGroups(IEspContext &context, IEspGroupRequest &req, IEspGroupResponse &resp)
  513. {
  514. try
  515. {
  516. CLdapSecManager* secmgr0 = dynamic_cast<CLdapSecManager*>(context.querySecManager());
  517. double version = context.getClientVersion();
  518. if (version > 1.03)
  519. {
  520. if(secmgr0 == NULL)
  521. {
  522. //throw MakeStringException(-1, "SecManager is NULL, please check if the binding's authentication is set up correctly");
  523. resp.setNoSecMngr(true);
  524. return true;
  525. }
  526. }
  527. checkUser(context);
  528. StringArray groupnames;
  529. ISecManager* secmgr = context.querySecManager();
  530. if(secmgr == NULL)
  531. throw MakeStringException(ECLWATCH_INVALID_SEC_MANAGER, MSG_SEC_MANAGER_IS_NULL);
  532. secmgr->getAllGroups(groupnames);
  533. ///groupnames.append("Administrators");
  534. ///groupnames.append("Full_Access_TestingOnly");
  535. //groupnames.kill();
  536. if (groupnames.length() > 0)
  537. {
  538. IArrayOf<IEspGroupInfo> groups;
  539. for(unsigned i = 0; i < groupnames.length(); i++)
  540. {
  541. const char* grpname = groupnames.item(i);
  542. //if(grpname == NULL || grpname[0] == '\0' || stricmp(grpname, "Authenticated Users") == 0)
  543. if(grpname == NULL || grpname[0] == '\0')
  544. continue;
  545. Owned<IEspGroupInfo> onegrp = createGroupInfo();
  546. onegrp->setName(grpname);
  547. groups.append(*onegrp.getLink());
  548. }
  549. resp.setGroups(groups);
  550. }
  551. /*
  552. IArrayOf<IEspGroupInfo> groups;
  553. Owned<IEspGroupInfo> onegrp = createGroupInfo();
  554. onegrp->setName("grpname");
  555. groups.append(*onegrp.getLink());
  556. resp.setGroups(groups);
  557. */
  558. }
  559. catch(IException* e)
  560. {
  561. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  562. }
  563. return true;
  564. }
  565. bool Cws_accessEx::onAddUser(IEspContext &context, IEspAddUserRequest &req, IEspAddUserResponse &resp)
  566. {
  567. try
  568. {
  569. checkUser(context);
  570. ISecManager* secmgr = context.querySecManager();
  571. if(secmgr == NULL)
  572. throw MakeStringException(ECLWATCH_INVALID_SEC_MANAGER, MSG_SEC_MANAGER_IS_NULL);
  573. const char* username = req.getUsername();
  574. if(username == NULL || *username == '\0')
  575. {
  576. resp.setRetcode(-1);
  577. resp.setRetmsg("username can't be empty");
  578. return false;
  579. }
  580. if(strchr(username, ' '))
  581. {
  582. resp.setRetcode(-1);
  583. resp.setRetmsg("Username can't contain spaces");
  584. return false;
  585. }
  586. CLdapSecManager* secmgr0 = (CLdapSecManager*)secmgr;
  587. if((secmgr0->getLdapServerType() == ACTIVE_DIRECTORY) && (strlen(username) > 20))
  588. {
  589. resp.setRetcode(-1);
  590. resp.setRetmsg("Username can't be more than 20 characters.");
  591. return false;
  592. }
  593. const char* pass1 = req.getPassword1();
  594. const char* pass2 = req.getPassword2();
  595. if(pass1 == NULL || pass2 == NULL || *pass1 == '\0' || *pass2 == '\0' || strcmp(pass1, pass2) != 0)
  596. {
  597. resp.setRetcode(-1);
  598. resp.setRetmsg("password and retype can't be empty and must match.");
  599. return false;
  600. }
  601. Owned<ISecUser> user = secmgr->createUser(username);
  602. ISecCredentials& cred = user->credentials();
  603. const char* firstname = req.getFirstname();
  604. const char* lastname = req.getLastname();
  605. if(firstname != NULL)
  606. user->setFirstName(firstname);
  607. if(lastname != NULL)
  608. user->setLastName(lastname);
  609. if(pass1 != NULL)
  610. cred.setPassword(pass1);
  611. try
  612. {
  613. secmgr->addUser(*user.get());
  614. }
  615. catch(IException* e)
  616. {
  617. resp.setRetcode(-1);
  618. StringBuffer errmsg;
  619. resp.setRetmsg(e->errorMessage(errmsg).str());
  620. return false;
  621. }
  622. resp.setRetcode(0);
  623. resp.setRetmsg("User successfully added");
  624. }
  625. catch(IException* e)
  626. {
  627. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  628. }
  629. return true;
  630. }
  631. bool Cws_accessEx::onUserAction(IEspContext &context, IEspUserActionRequest &req, IEspUserActionResponse &resp)
  632. {
  633. try
  634. {
  635. checkUser(context);
  636. CLdapSecManager* secmgr = (CLdapSecManager*)(context.querySecManager());
  637. if(secmgr == NULL)
  638. throw MakeStringException(ECLWATCH_INVALID_SEC_MANAGER, MSG_SEC_MANAGER_IS_NULL);
  639. const char* action = req.getActionType();
  640. if (!action || !*action)
  641. throw MakeStringException(ECLWATCH_INVALID_ACTION, "Action not specified.");
  642. if (!stricmp(action, "delete"))
  643. {
  644. StringArray& usernames = req.getUsernames();
  645. for(unsigned i = 0; i < usernames.length(); i++)
  646. {
  647. const char* username = usernames.item(i);
  648. Owned<ISecUser> user = secmgr->createUser(username);
  649. secmgr->deleteUser(user.get());
  650. }
  651. }
  652. else if (!stricmp(action, "export"))
  653. {
  654. StringBuffer users;
  655. StringArray& usernames = req.getUsernames();
  656. for(unsigned i = 0; i < usernames.length(); i++)
  657. {
  658. const char* username = usernames.item(i);
  659. if (i > 0)
  660. users.appendf("&usernames_i%d=%s", i+1, username);
  661. else
  662. users.append(username);
  663. }
  664. resp.setRedirectUrl(StringBuffer("/ws_access/UserAccountExport?usernames_i1=").append(users).str());
  665. }
  666. resp.setAction(action);
  667. }
  668. catch(IException* e)
  669. {
  670. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  671. }
  672. return true;
  673. }
  674. bool Cws_accessEx::onGroupAdd(IEspContext &context, IEspGroupAddRequest &req, IEspGroupAddResponse &resp)
  675. {
  676. try
  677. {
  678. checkUser(context);
  679. CLdapSecManager* secmgr = (CLdapSecManager*)(context.querySecManager());
  680. if(secmgr == NULL)
  681. throw MakeStringException(ECLWATCH_INVALID_SEC_MANAGER, MSG_SEC_MANAGER_IS_NULL);
  682. const char* groupname = req.getGroupname();
  683. if(groupname == NULL || *groupname == '\0')
  684. {
  685. resp.setRetcode(-1);
  686. resp.setRetmsg("Group name can't be empty");
  687. return false;
  688. }
  689. resp.setGroupname(groupname);
  690. try
  691. {
  692. secmgr->addGroup(groupname);
  693. }
  694. catch(IException* e)
  695. {
  696. StringBuffer emsg;
  697. e->errorMessage(emsg);
  698. resp.setRetcode(e->errorCode());
  699. resp.setRetmsg(emsg.str());
  700. return false;
  701. }
  702. catch(...)
  703. {
  704. resp.setRetcode(-1);
  705. resp.setRetmsg("Unknown error");
  706. return false;
  707. }
  708. resp.setRetcode(0);
  709. }
  710. catch(IException* e)
  711. {
  712. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  713. }
  714. return true;
  715. }
  716. bool Cws_accessEx::onGroupAction(IEspContext &context, IEspGroupActionRequest &req, IEspGroupActionResponse &resp)
  717. {
  718. try
  719. {
  720. checkUser(context);
  721. CLdapSecManager* secmgr = (CLdapSecManager*)(context.querySecManager());
  722. if(secmgr == NULL)
  723. throw MakeStringException(ECLWATCH_INVALID_SEC_MANAGER, MSG_SEC_MANAGER_IS_NULL);
  724. const char* action = req.getActionType();
  725. if (!action || !*action)
  726. throw MakeStringException(ECLWATCH_INVALID_ACTION, "Action not specified.");
  727. if (!stricmp(action, "export"))
  728. {
  729. StringBuffer groups;
  730. StringArray& groupnames = req.getGroupnames();
  731. for(unsigned i = 0; i < groupnames.length(); i++)
  732. {
  733. const char* group = groupnames.item(i);
  734. if (i > 0)
  735. groups.appendf("&groupnames_i%d=%s", i+1, group);
  736. else
  737. groups.append(group);
  738. }
  739. resp.setRedirectUrl(StringBuffer("/ws_access/UserAccountExport?groupnames_i1=").append(groups).str());
  740. }
  741. else if (!stricmp(action, "delete"))
  742. {
  743. CLdapSecManager* ldapsecmgr = (CLdapSecManager*)secmgr;
  744. StringArray& groupnames = req.getGroupnames();
  745. IArrayOf<IEspAccountPermission> accountPermissions;
  746. double version = context.getClientVersion();
  747. if (version > 1.01)
  748. {
  749. bool bDeletePermission = false;
  750. if(!req.getDeletePermission_isNull())
  751. bDeletePermission = req.getDeletePermission();
  752. if(m_basedns.length() == 0)
  753. {
  754. setBasedns(context);
  755. }
  756. ForEachItemIn(y, m_basedns)
  757. {
  758. IEspDnStruct* curbasedn = &(m_basedns.item(y));
  759. const char *aBasedn = curbasedn->getBasedn();
  760. const char *aRtype = curbasedn->getRtype();
  761. if (!aBasedn || !*aBasedn ||!aRtype || !*aRtype)
  762. continue;
  763. SecResourceType rtype = str2type(aRtype);
  764. IArrayOf<IEspResource> ResourceArray;
  765. if(rtype == RT_WORKUNIT_SCOPE)
  766. {
  767. StringBuffer deft_basedn, deft_name;
  768. const char* comma = strchr(aBasedn, ',');
  769. const char* eqsign = strchr(aBasedn, '=');
  770. if(eqsign != NULL)
  771. {
  772. if(comma == NULL)
  773. deft_name.append(eqsign+1);
  774. else
  775. {
  776. deft_name.append(comma - eqsign - 1, eqsign+1);
  777. deft_basedn.append(comma + 1);
  778. }
  779. }
  780. if (deft_name.length() > 0)
  781. {
  782. Owned<IEspResource> oneresource = createResource();
  783. oneresource->setName(deft_name);
  784. oneresource->setDescription(deft_basedn);
  785. ResourceArray.append(*oneresource.getLink());
  786. }
  787. }
  788. IArrayOf<ISecResource> resources;
  789. if(secmgr->getResources(rtype, aBasedn, resources))
  790. {
  791. ForEachItemIn(y1, resources)
  792. {
  793. ISecResource& r = resources.item(y1);
  794. const char* rname = r.getName();
  795. if(rname == NULL || *rname == '\0')
  796. continue;
  797. Owned<IEspResource> oneresource = createResource();
  798. oneresource->setName(rname);
  799. oneresource->setDescription(aBasedn);
  800. ResourceArray.append(*oneresource.getLink());
  801. }
  802. }
  803. ForEachItemIn(y2, ResourceArray)
  804. {
  805. IEspResource& r = ResourceArray.item(y2);
  806. const char* rname = r.getName();
  807. const char* bnname = r.getDescription();
  808. if(rname == NULL || *rname == '\0')
  809. continue;
  810. StringBuffer namebuf(rname);
  811. //const char* prefix = req.getPrefix();
  812. //if(prefix && *prefix)
  813. // namebuf.insert(0, prefix);
  814. try
  815. {
  816. IArrayOf<CPermission> permissions;
  817. ldapsecmgr->getPermissionsArray(bnname, rtype, namebuf.str(), permissions);
  818. ForEachItemIn(x, permissions)
  819. {
  820. CPermission& perm = permissions.item(x);
  821. const char* actname = perm.getAccount_name();
  822. int accountType = perm.getAccount_type(); //0-individual, 1 - group
  823. //if ((bGroupAccount && accountType < 1) || (!bGroupAccount && accountType > 0))
  824. if (accountType < 1 || !actname || !*actname) //Support Group only
  825. continue;
  826. ForEachItemIn(x1, groupnames)
  827. {
  828. const char* groupname = groupnames.item(x1);
  829. if (groupname && !strcmp(actname, groupname))
  830. {
  831. ///bDeletePermission = true;
  832. if (!bDeletePermission)
  833. {
  834. Owned<IEspAccountPermission> onepermission = createAccountPermission();
  835. onepermission->setBasedn(bnname);
  836. onepermission->setRType(aRtype);
  837. onepermission->setResourceName(namebuf.str());
  838. onepermission->setPermissionName(groupname);
  839. accountPermissions.append(*onepermission.getLink());
  840. }
  841. else
  842. {
  843. CPermissionAction paction;
  844. paction.m_basedn.append(bnname);
  845. paction.m_rtype = rtype;
  846. paction.m_rname.append(namebuf.str());
  847. paction.m_account_name.append(actname);
  848. paction.m_account_type = (ACT_TYPE) accountType;
  849. paction.m_allows = perm.getAllows();
  850. paction.m_denies = perm.getDenies();
  851. paction.m_action.append("delete");
  852. if(!ldapsecmgr->changePermission(paction))
  853. {
  854. resp.setRetcode(-1);
  855. resp.setRetmsg("Unknown error");
  856. return false;
  857. }
  858. }
  859. break;
  860. }
  861. }
  862. }
  863. }
  864. catch(IException* e)
  865. {
  866. e->Release();
  867. }
  868. }
  869. }
  870. }
  871. try
  872. {
  873. if (accountPermissions.length() < 1)
  874. {
  875. ForEachItemIn(x1, groupnames)
  876. {
  877. const char* groupname = groupnames.item(x1);
  878. secmgr->deleteGroup(groupname);
  879. }
  880. }
  881. else
  882. {
  883. StringBuffer groupnamestr;
  884. groupnamestr.append("DeletePermission=1");
  885. ForEachItemIn(x1, groupnames)
  886. {
  887. const char* groupname = groupnames.item(x1);
  888. groupnamestr.appendf("&groupnames_i%d=%s", x1+1, groupname);
  889. }
  890. resp.setPermissions(accountPermissions);
  891. resp.setGroupnames(groupnamestr.str());
  892. resp.setRetcode(0);
  893. }
  894. }
  895. catch(IException* e)
  896. {
  897. StringBuffer emsg;
  898. e->errorMessage(emsg);
  899. resp.setRetcode(e->errorCode());
  900. resp.setRetmsg(emsg.str());
  901. return false;
  902. }
  903. catch(...)
  904. {
  905. resp.setRetcode(-1);
  906. resp.setRetmsg("Unknown error");
  907. return false;
  908. }
  909. }
  910. resp.setRetcode(0);
  911. }
  912. catch(IException* e)
  913. {
  914. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  915. }
  916. return true;
  917. }
  918. bool Cws_accessEx::onGroupEdit(IEspContext &context, IEspGroupEditRequest &req, IEspGroupEditResponse &resp)
  919. {
  920. try
  921. {
  922. checkUser(context);
  923. ISecManager* secmgr = context.querySecManager();
  924. if(secmgr == NULL)
  925. throw MakeStringException(ECLWATCH_INVALID_SEC_MANAGER, MSG_SEC_MANAGER_IS_NULL);
  926. CLdapSecManager* ldapsecmgr = (CLdapSecManager*)secmgr;
  927. resp.setGroupname(req.getGroupname());
  928. StringArray usernames;
  929. ldapsecmgr->getGroupMembers(req.getGroupname(), usernames);
  930. IArrayOf<IEspUserInfo> users;
  931. unsigned i = 0;
  932. for(i = 0; i < usernames.length(); i++)
  933. {
  934. const char* usrname = usernames.item(i);
  935. if(usrname == NULL || usrname[0] == '\0')
  936. continue;
  937. ///////////////////////////////////////BUG#41536///////////////
  938. bool bFound = false;
  939. IUserArray usersInBaseDN;
  940. ldapsecmgr->searchUsers(usrname, usersInBaseDN);
  941. ForEachItemIn(x, usersInBaseDN)
  942. {
  943. ISecUser* usr = &usersInBaseDN.item(x);
  944. if(usr)
  945. {
  946. const char* usrname = usr->getName();
  947. if(usrname == NULL || usrname[0] == '\0')
  948. continue;
  949. bFound = true;
  950. break;
  951. }
  952. }
  953. if (!bFound)
  954. continue;
  955. //////////////////////////////////////////////////////////////
  956. Owned<IEspUserInfo> oneusr = createUserInfo();
  957. oneusr->setUsername(usrname);
  958. users.append(*oneusr.getLink());
  959. }
  960. resp.setUsers(users);
  961. }
  962. catch(IException* e)
  963. {
  964. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  965. }
  966. return true;
  967. }
  968. bool Cws_accessEx::onGroupMemberEditInput(IEspContext &context, IEspGroupMemberEditInputRequest &req, IEspGroupMemberEditInputResponse &resp)
  969. {
  970. try
  971. {
  972. checkUser(context);
  973. CLdapSecManager* secmgr = (CLdapSecManager*)context.querySecManager();
  974. if(secmgr == NULL)
  975. throw MakeStringException(ECLWATCH_INVALID_SEC_MANAGER, MSG_SEC_MANAGER_IS_NULL);
  976. CLdapSecManager* ldapsecmgr = (CLdapSecManager*)secmgr;
  977. resp.setGroupname(req.getGroupname());
  978. set<string> ousrs;
  979. StringArray ousernames;
  980. ldapsecmgr->getGroupMembers(req.getGroupname(), ousernames);
  981. unsigned i = 0;
  982. for(i = 0; i < ousernames.length(); i++)
  983. {
  984. const char* username = ousernames.item(i);
  985. if(username != NULL && *username != '\0')
  986. {
  987. ousrs.insert(username);
  988. }
  989. }
  990. const char* searchstr = req.getSearchinput();
  991. int numusers = secmgr->countUsers(searchstr, MAX_USERS_DISPLAY+ousernames.ordinality());
  992. if(numusers == -1)
  993. {
  994. resp.setToomany(true);
  995. return true;
  996. }
  997. resp.setToomany(false);
  998. IArrayOf<IEspUserInfo> espusers;
  999. IUserArray users;
  1000. secmgr->searchUsers(searchstr, users);
  1001. ForEachItemIn(x, users)
  1002. {
  1003. ISecUser* usr = &users.item(x);
  1004. if(usr)
  1005. {
  1006. const char* usrname = usr->getName();
  1007. if(usrname == NULL || usrname[0] == '\0')
  1008. continue;
  1009. if(ousrs.find(usrname) == ousrs.end())
  1010. {
  1011. Owned<IEspUserInfo> oneusr = createUserInfo();
  1012. oneusr->setUsername(usr->getName());
  1013. espusers.append(*oneusr.getLink());
  1014. }
  1015. }
  1016. }
  1017. resp.setUsers(espusers);
  1018. }
  1019. catch(IException* e)
  1020. {
  1021. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  1022. }
  1023. return true;
  1024. }
  1025. bool Cws_accessEx::onGroupMemberEdit(IEspContext &context, IEspGroupMemberEditRequest &req, IEspGroupMemberEditResponse &resp)
  1026. {
  1027. try
  1028. {
  1029. checkUser(context);
  1030. CLdapSecManager* secmgr = (CLdapSecManager*)(context.querySecManager());
  1031. if(secmgr == NULL)
  1032. throw MakeStringException(ECLWATCH_INVALID_SEC_MANAGER, MSG_SEC_MANAGER_IS_NULL);
  1033. const char* groupname = req.getGroupname();
  1034. if(groupname == NULL || *groupname == '\0')
  1035. {
  1036. resp.setRetcode(-1);
  1037. resp.setRetmsg("group can't be empty");
  1038. return false;
  1039. }
  1040. ///////////////////////////////////////BUG#41536///////////////
  1041. StringArray existing_usernames;
  1042. if (!stricmp(req.getAction(), "add"))
  1043. secmgr->getGroupMembers(groupname, existing_usernames);
  1044. //////////////////////////////////////////////////////
  1045. StringArray& usernames = req.getUsernames();
  1046. try
  1047. {
  1048. for(unsigned i = 0; i < usernames.length(); i++)
  1049. {
  1050. const char* usrname = usernames.item(i);
  1051. if(usrname == NULL || *usrname == '\0')
  1052. continue;
  1053. ///////////////////////////////////////BUG#41536///////////////
  1054. bool bFound = false;
  1055. if (existing_usernames.length() > 0)
  1056. {
  1057. for(unsigned i = 0; i < existing_usernames.length(); i++)
  1058. {
  1059. const char* existing_usrname = existing_usernames.item(i);
  1060. if(existing_usrname == NULL || existing_usrname[0] == '\0')
  1061. continue;
  1062. if (!strcmp(usrname, existing_usrname))
  1063. {
  1064. bFound = true;
  1065. break;
  1066. }
  1067. }
  1068. }
  1069. if (!bFound)
  1070. //////////////////////////////////////////////////////
  1071. secmgr->changeUserGroup(req.getAction(), usrname, groupname);
  1072. }
  1073. }
  1074. catch(IException* e)
  1075. {
  1076. StringBuffer errmsg;
  1077. e->errorMessage(errmsg);
  1078. DBGLOG("error changing user's group membership: %s", errmsg.str());
  1079. resp.setRetcode(e->errorCode());
  1080. resp.setRetmsg(errmsg.str());
  1081. return false;
  1082. }
  1083. resp.setRetcode(0);
  1084. resp.setGroupname(groupname);
  1085. resp.setAction(req.getAction());
  1086. if(stricmp(req.getAction(), "add") == 0)
  1087. resp.setRetmsg("members successfully added to group");
  1088. else
  1089. resp.setRetmsg("members successfully deleted from group");
  1090. }
  1091. catch(IException* e)
  1092. {
  1093. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  1094. }
  1095. return true;
  1096. }
  1097. bool Cws_accessEx::onPermissions(IEspContext &context, IEspBasednsRequest &req, IEspBasednsResponse &resp)
  1098. {
  1099. try
  1100. {
  1101. CLdapSecManager* secmgr = dynamic_cast<CLdapSecManager*>(context.querySecManager());
  1102. double version = context.getClientVersion();
  1103. if (version > 1.03)
  1104. {
  1105. if(secmgr == NULL)
  1106. {
  1107. resp.setNoSecMngr(true);
  1108. return true;
  1109. }
  1110. }
  1111. else
  1112. {
  1113. if(secmgr == NULL)
  1114. throw MakeStringException(ECLWATCH_INVALID_SEC_MANAGER, MSG_SEC_MANAGER_IS_NULL);
  1115. }
  1116. checkUser(context);
  1117. if(m_basedns.length() == 0)
  1118. {
  1119. setBasedns(context);
  1120. }
  1121. resp.setBasedns(m_basedns);
  1122. }
  1123. catch(IException* e)
  1124. {
  1125. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  1126. }
  1127. return true;
  1128. }
  1129. bool Cws_accessEx::onResources(IEspContext &context, IEspResourcesRequest &req, IEspResourcesResponse &resp)
  1130. {
  1131. try
  1132. {
  1133. checkUser(context);
  1134. CLdapSecManager* secmgr = (CLdapSecManager*)context.querySecManager();
  1135. if(secmgr == NULL)
  1136. throw MakeStringException(ECLWATCH_INVALID_SEC_MANAGER, MSG_SEC_MANAGER_IS_NULL);
  1137. double version = context.getClientVersion();
  1138. const char* filterInput = req.getSearchinput();
  1139. const char* basedn = req.getBasedn();
  1140. const char* rtypestr = req.getRtype();
  1141. const char* moduletemplate = NULL;
  1142. ForEachItemIn(x, m_basedns)
  1143. {
  1144. IEspDnStruct* curbasedn = &(m_basedns.item(x));
  1145. if(stricmp(curbasedn->getBasedn(), basedn) == 0)
  1146. {
  1147. moduletemplate = curbasedn->getTemplatename();
  1148. }
  1149. }
  1150. resp.setBasedn(basedn);
  1151. resp.setRtype(rtypestr);
  1152. resp.setRtitle(req.getRtitle());
  1153. SecResourceType rtype = str2type(rtypestr);
  1154. if(rtype == RT_FILE_SCOPE || rtype == RT_WORKUNIT_SCOPE)
  1155. {
  1156. StringBuffer deft_basedn, deft_name;
  1157. const char* comma = strchr(basedn, ',');
  1158. const char* eqsign = strchr(basedn, '=');
  1159. if(eqsign != NULL)
  1160. {
  1161. if(comma == NULL)
  1162. deft_name.append(eqsign+1);
  1163. else
  1164. {
  1165. deft_name.append(comma - eqsign - 1, eqsign+1);
  1166. deft_basedn.append(comma + 1);
  1167. }
  1168. resp.setDefault_basedn(deft_basedn.str());
  1169. resp.setDefault_name(deft_name.str());
  1170. }
  1171. }
  1172. IArrayOf<IEspResource> rarray;
  1173. IArrayOf<ISecResource> resources;
  1174. const char* prefix = req.getPrefix();
  1175. int prefixlen = 0;
  1176. if(prefix && *prefix)
  1177. {
  1178. prefixlen = strlen(prefix);
  1179. resp.setPrefix(prefix);
  1180. }
  1181. if (version > 1.04)
  1182. {
  1183. int numResources = -1;
  1184. if (req.getRtitle() && !stricmp(req.getRtitle(), "CodeGenerator Permission"))
  1185. numResources = secmgr->countResources(basedn, prefix, MAX_RESOURCES_DISPLAY);
  1186. else
  1187. numResources = secmgr->countResources(basedn, filterInput, MAX_RESOURCES_DISPLAY);
  1188. if(numResources == -1)
  1189. {
  1190. resp.setToomany(true);
  1191. return true;
  1192. }
  1193. else
  1194. {
  1195. resp.setToomany(false);
  1196. }
  1197. }
  1198. if ((!filterInput || !*filterInput) && req.getRtitle() && !stricmp(req.getRtitle(), "CodeGenerator Permission"))
  1199. {
  1200. if(!secmgr->getResourcesEx(rtype, basedn, prefix, resources))
  1201. return false;
  1202. }
  1203. else
  1204. {
  1205. if(!secmgr->getResourcesEx(rtype, basedn, filterInput, resources))
  1206. return false;
  1207. }
  1208. ILdapConfig* cfg = secmgr->queryConfig();
  1209. for(unsigned i = 0; i < resources.length(); i++)
  1210. {
  1211. ISecResource& r = resources.item(i);
  1212. Owned<IEspResource> oneresource = createResource();
  1213. oneresource->setIsSpecial(false);
  1214. const char* rname = r.getName();
  1215. if(rname == NULL || *rname == '\0')
  1216. continue;
  1217. if(prefix && *prefix)
  1218. {
  1219. if(strncmp(prefix, rname, prefixlen) != 0)
  1220. continue;
  1221. else
  1222. rname += prefixlen;
  1223. }
  1224. if(rtype == RT_MODULE)
  1225. {
  1226. if(stricmp(rname, "repository") != 0)
  1227. {
  1228. if(moduletemplate != NULL && stricmp(rname, moduletemplate) == 0)
  1229. oneresource->setIsSpecial(true);
  1230. if(Utils::strncasecmp(rname, "repository.", 11) == 0)
  1231. rname = rname + 11;
  1232. else
  1233. continue;
  1234. }
  1235. else
  1236. {
  1237. oneresource->setIsSpecial(true);
  1238. }
  1239. }
  1240. else if(rtype == RT_FILE_SCOPE && stricmp(rname, "file") == 0)
  1241. {
  1242. //oneresource->setIsSpecial(true); //33067
  1243. continue;
  1244. }
  1245. oneresource->setName(rname);
  1246. oneresource->setDescription(r.getDescription());
  1247. rarray.append(*oneresource.getLink());
  1248. }
  1249. if (version >= 1.08)
  1250. {
  1251. Owned<IUserDescriptor> userdesc;
  1252. userdesc.setown(createUserDescriptor());
  1253. userdesc->set(context.queryUserId(), context.queryPassword());
  1254. int retCode;
  1255. StringBuffer retMsg;
  1256. bool isEnabled = querySessionManager().queryScopeScansEnabled(userdesc, &retCode, retMsg);
  1257. if (retCode != 0)
  1258. DBGLOG("Error %d querying scope scan status : %s", retCode, retMsg.str());
  1259. resp.updateScopeScansStatus().setIsEnabled(isEnabled);
  1260. resp.updateScopeScansStatus().setRetcode(retCode);
  1261. resp.updateScopeScansStatus().setRetmsg(retMsg.str());
  1262. }
  1263. resp.setResources(rarray);
  1264. }
  1265. catch(IException* e)
  1266. {
  1267. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  1268. }
  1269. return true;
  1270. }
  1271. bool Cws_accessEx::onResourceAddInput(IEspContext &context, IEspResourceAddInputRequest &req, IEspResourceAddInputResponse &resp)
  1272. {
  1273. try
  1274. {
  1275. checkUser(context);
  1276. resp.setBasedn(req.getBasedn());
  1277. resp.setRtype(req.getRtype());
  1278. resp.setRtitle(req.getRtitle());
  1279. resp.setPrefix(req.getPrefix());
  1280. }
  1281. catch(IException* e)
  1282. {
  1283. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  1284. }
  1285. return true;
  1286. }
  1287. SecResourceType Cws_accessEx::str2type(const char* rtstr)
  1288. {
  1289. if(rtstr == NULL || *rtstr == '\0')
  1290. return RT_DEFAULT;
  1291. else if(stricmp(rtstr, "module") == 0)
  1292. return RT_MODULE;
  1293. else if(stricmp(rtstr, "service") == 0)
  1294. return RT_SERVICE;
  1295. else if(stricmp(rtstr, "file") == 0)
  1296. return RT_FILE_SCOPE;
  1297. else if(stricmp(rtstr, "workunit") == 0)
  1298. return RT_WORKUNIT_SCOPE;
  1299. else
  1300. return RT_DEFAULT;
  1301. }
  1302. bool Cws_accessEx::onResourceAdd(IEspContext &context, IEspResourceAddRequest &req, IEspResourceAddResponse &resp)
  1303. {
  1304. try
  1305. {
  1306. checkUser(context);
  1307. ISecManager* secmgr = context.querySecManager();
  1308. if(secmgr == NULL)
  1309. throw MakeStringException(ECLWATCH_INVALID_SEC_MANAGER, MSG_SEC_MANAGER_IS_NULL);
  1310. resp.setBasedn(req.getBasedn());
  1311. resp.setRtype(req.getRtype());
  1312. resp.setRtitle(req.getRtitle());
  1313. resp.setPrefix(req.getPrefix());
  1314. StringBuffer lastResource;
  1315. StringArray newResources;
  1316. if(str2type(req.getRtype()) == RT_FILE_SCOPE)
  1317. {
  1318. getNewFileScopePermissions(secmgr, req, lastResource, newResources);
  1319. }
  1320. SecResourceType rtype = str2type(req.getRtype());
  1321. try
  1322. {
  1323. ISecUser* usr = NULL;
  1324. Owned<ISecResourceList> rlist = secmgr->createResourceList("ws_access");
  1325. const char* name = req.getName();
  1326. if(name == NULL || *name == '\0')
  1327. {
  1328. resp.setRetcode(-1);
  1329. StringBuffer errmsg;
  1330. errmsg.append(req.getRtitle()).append(" name can't be empty");
  1331. resp.setRetmsg(errmsg.str());
  1332. return false;
  1333. }
  1334. if(strchr(name, '\\') != NULL || strchr(name, '/') != NULL)
  1335. {
  1336. resp.setRetcode(-1);
  1337. StringBuffer errmsg;
  1338. errmsg.append(" you can't have '\\' or '/' in the name");
  1339. resp.setRetmsg(errmsg.str());
  1340. return false;
  1341. }
  1342. const char* ptr = strchr(name, ':');
  1343. while(ptr != NULL)
  1344. {
  1345. if(*(ptr+1) != ':')
  1346. throw MakeStringException(ECLWATCH_SINGLE_COLON_NOT_ALLOWED, "Single colon is not allowed in scope names. Please use double colon");
  1347. ptr = strchr(ptr+2, ':');
  1348. }
  1349. StringBuffer namebuf(name);
  1350. if(rtype == RT_MODULE && stricmp(name, "repository") != 0 && Utils::strncasecmp(name, "repository.", 11) != 0)
  1351. namebuf.insert(0, "repository.");
  1352. const char* prefix = req.getPrefix();
  1353. if(prefix && *prefix)
  1354. namebuf.insert(0, prefix);
  1355. ISecResource* r = rlist->addResource(namebuf.str());
  1356. r->setDescription(req.getDescription());
  1357. secmgr->addResourcesEx(rtype, *usr, rlist, PT_DEFAULT, req.getBasedn());
  1358. if(str2type(req.getRtype()) == RT_FILE_SCOPE && newResources.ordinality())
  1359. {
  1360. setNewFileScopePermissions(secmgr, req, lastResource, newResources);
  1361. StringBuffer retmsg;
  1362. ForEachItemIn(y, newResources)
  1363. {
  1364. StringBuffer namebuf = newResources.item(y);
  1365. if (retmsg.length() < 1)
  1366. retmsg.append(namebuf);
  1367. else
  1368. retmsg.appendf(", %s", namebuf.str());
  1369. }
  1370. resp.setRetmsg(retmsg.str());
  1371. }
  1372. }
  1373. catch(IException* e)
  1374. {
  1375. StringBuffer emsg;
  1376. e->errorMessage(emsg);
  1377. resp.setRetcode(e->errorCode());
  1378. resp.setRetmsg(emsg.str());
  1379. return false;
  1380. }
  1381. catch(...)
  1382. {
  1383. resp.setRetcode(-1);
  1384. resp.setRetmsg("unknown error");
  1385. return false;
  1386. }
  1387. resp.setRetcode(0);
  1388. }
  1389. catch(IException* e)
  1390. {
  1391. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  1392. }
  1393. return true;
  1394. }
  1395. bool Cws_accessEx::onResourceDelete(IEspContext &context, IEspResourceDeleteRequest &req, IEspResourceDeleteResponse &resp)
  1396. {
  1397. try
  1398. {
  1399. checkUser(context);
  1400. CLdapSecManager* secmgr = (CLdapSecManager*)(context.querySecManager());
  1401. if(secmgr == NULL)
  1402. throw MakeStringException(ECLWATCH_INVALID_SEC_MANAGER, MSG_SEC_MANAGER_IS_NULL);
  1403. StringArray& names = req.getNames();
  1404. int doUpdate = req.getDoUpdate();
  1405. if (doUpdate)
  1406. {
  1407. const char* basedn = req.getBasedn();
  1408. const char* rtype = req.getRtype();
  1409. const char* rtitle = req.getRtitle();
  1410. const char* prefix = req.getPrefix();
  1411. StringBuffer url("/ws_access/PermissionsResetInput");
  1412. url.appendf("?basedn=%s", basedn);
  1413. url.appendf("&rtype=%s", rtype);
  1414. url.appendf("&rtitle=%s", rtitle);
  1415. url.appendf("&prefix=%s", prefix);
  1416. if (names.length() < 1)
  1417. throw MakeStringException(ECLWATCH_INVALID_RESOURCE_NAME, "Please select a resource name.");
  1418. for(unsigned i = 0; i < names.length(); i++)
  1419. {
  1420. const char* name = names.item(i);
  1421. if(name == NULL || *name == '\0')
  1422. continue;
  1423. url.appendf("&names_i%d=%s", i, name);
  1424. }
  1425. resp.setRedirectUrl(url);
  1426. return true;
  1427. }
  1428. resp.setBasedn(req.getBasedn());
  1429. resp.setRtype(req.getRtype());
  1430. resp.setRtitle(req.getRtitle());
  1431. resp.setPrefix(req.getPrefix());
  1432. SecResourceType rtype = str2type(req.getRtype());
  1433. try
  1434. {
  1435. for(unsigned i = 0; i < names.length(); i++)
  1436. {
  1437. const char* name = names.item(i);
  1438. if(name == NULL || *name == '\0')
  1439. continue;
  1440. StringBuffer namebuf(name);
  1441. if(rtype == RT_MODULE && stricmp(name, "repository") != 0 && Utils::strncasecmp(name, "repository.", 11) != 0)
  1442. namebuf.insert(0, "repository.");
  1443. const char* prefix = req.getPrefix();
  1444. if(prefix && *prefix)
  1445. namebuf.insert(0, prefix);
  1446. secmgr->deleteResource(rtype, namebuf.str(), req.getBasedn());
  1447. }
  1448. }
  1449. catch(IException* e)
  1450. {
  1451. StringBuffer emsg;
  1452. e->errorMessage(emsg);
  1453. resp.setRetcode(e->errorCode());
  1454. resp.setRetmsg(emsg.str());
  1455. return false;
  1456. }
  1457. catch(...)
  1458. {
  1459. resp.setRetcode(-1);
  1460. resp.setRetmsg("Unknown error");
  1461. return false;
  1462. }
  1463. resp.setRetcode(0);
  1464. }
  1465. catch(IException* e)
  1466. {
  1467. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  1468. }
  1469. return true;
  1470. }
  1471. bool Cws_accessEx::onResourcePermissions(IEspContext &context, IEspResourcePermissionsRequest &req, IEspResourcePermissionsResponse &resp)
  1472. {
  1473. try
  1474. {
  1475. checkUser(context);
  1476. ISecManager* secmgr = context.querySecManager();
  1477. if(secmgr == NULL)
  1478. throw MakeStringException(ECLWATCH_INVALID_SEC_MANAGER, MSG_SEC_MANAGER_IS_NULL);
  1479. CLdapSecManager* ldapsecmgr = (CLdapSecManager*)secmgr;
  1480. const char* name = req.getName();
  1481. StringBuffer namebuf(name);
  1482. if(str2type(req.getRtype()) == RT_MODULE && stricmp(name, "repository") != 0 && Utils::strncasecmp(name, "repository.", 11) != 0)
  1483. namebuf.insert(0, "repository.");
  1484. const char* prefix = req.getPrefix();
  1485. if(prefix && *prefix)
  1486. namebuf.insert(0, prefix);
  1487. IArrayOf<CPermission> permissions;
  1488. ldapsecmgr->getPermissionsArray(req.getBasedn(), str2type(req.getRtype()), namebuf.str(), permissions);
  1489. IArrayOf<IEspResourcePermission> parray;
  1490. ForEachItemIn(x, permissions)
  1491. {
  1492. CPermission& perm = permissions.item(x);
  1493. Owned<IEspResourcePermission> onepermission = createResourcePermission();
  1494. const char* actname = perm.getAccount_name();
  1495. if(actname != NULL && *actname != '\0')
  1496. {
  1497. StringBuffer escapedname;
  1498. int i = 0;
  1499. char c;
  1500. while((c = actname[i++]) != '\0')
  1501. {
  1502. if(c == '\'')
  1503. escapedname.append('\\').append('\'');
  1504. else
  1505. escapedname.append(c);
  1506. }
  1507. onepermission->setAccount_name(actname);
  1508. onepermission->setEscaped_account_name(escapedname.str());
  1509. }
  1510. onepermission->setAccount_type(perm.getAccount_type());
  1511. int allows = perm.getAllows();
  1512. int denies = perm.getDenies();
  1513. if((allows & NewSecAccess_Access) == NewSecAccess_Access)
  1514. onepermission->setAllow_access(true);
  1515. if((allows & NewSecAccess_Read) == NewSecAccess_Read)
  1516. onepermission->setAllow_read(true);
  1517. if((allows & NewSecAccess_Write) == NewSecAccess_Write)
  1518. onepermission->setAllow_write(true);
  1519. if((allows & NewSecAccess_Full) == NewSecAccess_Full)
  1520. onepermission->setAllow_full(true);
  1521. if((denies & NewSecAccess_Access) == NewSecAccess_Access)
  1522. onepermission->setDeny_access(true);
  1523. if((denies & NewSecAccess_Read) == NewSecAccess_Read)
  1524. onepermission->setDeny_read(true);
  1525. if((denies & NewSecAccess_Write) == NewSecAccess_Write)
  1526. onepermission->setDeny_write(true);
  1527. if((denies & NewSecAccess_Full) == NewSecAccess_Full)
  1528. onepermission->setDeny_full(true);
  1529. parray.append(*onepermission.getLink());
  1530. }
  1531. resp.setBasedn(req.getBasedn());
  1532. resp.setRtype(req.getRtype());
  1533. resp.setRtitle(req.getRtitle());
  1534. resp.setName(req.getName());
  1535. resp.setPrefix(req.getPrefix());
  1536. resp.setPermissions(parray);
  1537. }
  1538. catch(IException* e)
  1539. {
  1540. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  1541. }
  1542. return true;
  1543. }
  1544. bool Cws_accessEx::onPermissionAddInput(IEspContext &context, IEspPermissionAddRequest &req, IEspPermissionAddResponse &resp)
  1545. {
  1546. try
  1547. {
  1548. checkUser(context);
  1549. resp.setBasedn(req.getBasedn());
  1550. resp.setRname(req.getRname());
  1551. resp.setRtype(req.getRtype());
  1552. resp.setRtitle(req.getRtitle());
  1553. resp.setPrefix(req.getPrefix());
  1554. double version = context.getClientVersion();
  1555. if (version < 1.01)
  1556. {
  1557. return permissionAddInputOnResource(context, req, resp);
  1558. }
  1559. else
  1560. {
  1561. const char* accountName = req.getAccountName();
  1562. if (!accountName || !*accountName)
  1563. {
  1564. return permissionAddInputOnResource(context, req, resp);
  1565. }
  1566. else
  1567. {
  1568. return permissionAddInputOnAccount(context, accountName, req, resp);
  1569. }
  1570. }
  1571. }
  1572. catch(IException* e)
  1573. {
  1574. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  1575. }
  1576. return true;
  1577. }
  1578. bool Cws_accessEx::onPermissionsResetInput(IEspContext &context, IEspPermissionsResetInputRequest &req, IEspPermissionsResetInputResponse &resp)
  1579. {
  1580. try
  1581. {
  1582. checkUser(context);
  1583. resp.setBasedn(req.getBasedn());
  1584. //resp.setRname(req.getRname());
  1585. resp.setRname("Test");
  1586. resp.setRtype(req.getRtype());
  1587. resp.setRtitle(req.getRtitle());
  1588. resp.setPrefix(req.getPrefix());
  1589. StringArray& names = req.getNames();
  1590. if (names.length() < 1)
  1591. throw MakeStringException(ECLWATCH_INVALID_PERMISSION_NAME, "Please select a permission.");
  1592. StringBuffer nameList; //For forwarding to Submit page
  1593. StringArray names1;
  1594. ForEachItemIn(k, names)
  1595. {
  1596. const char* name1 = names.item(k);
  1597. nameList.appendf("%s,", name1);
  1598. names1.append(name1);
  1599. }
  1600. resp.setResourceList(nameList.str());
  1601. resp.setResources(names);
  1602. CLdapSecManager* secmgr = (CLdapSecManager*)context.querySecManager();
  1603. if(secmgr == NULL)
  1604. throw MakeStringException(ECLWATCH_INVALID_SEC_MANAGER, MSG_SEC_MANAGER_IS_NULL);
  1605. int numusers = secmgr->countUsers("", MAX_USERS_DISPLAY);
  1606. if(numusers == -1)
  1607. {
  1608. resp.setToomany(true);
  1609. }
  1610. else
  1611. {
  1612. resp.setToomany(false);
  1613. IArrayOf<IEspUserInfo> espusers;
  1614. IUserArray users;
  1615. secmgr->getAllUsers(users);
  1616. ForEachItemIn(x, users)
  1617. {
  1618. CLdapSecUser* usr = dynamic_cast<CLdapSecUser*>(&users.item(x));
  1619. if(usr)
  1620. {
  1621. Owned<IEspUserInfo> oneusr = createUserInfo();
  1622. oneusr->setUsername(usr->getName());
  1623. oneusr->setFullname(usr->getFullName());
  1624. espusers.append(*oneusr.getLink());
  1625. }
  1626. }
  1627. resp.setUsers(espusers);
  1628. }
  1629. IArrayOf<IEspGroupInfo> groups;
  1630. if(secmgr->getLdapServerType() != ACTIVE_DIRECTORY)
  1631. {
  1632. Owned<IEspGroupInfo> onegrp = createGroupInfo();
  1633. onegrp->setName("anyone");
  1634. groups.append(*onegrp.getLink());
  1635. }
  1636. StringArray grpnames;
  1637. secmgr->getAllGroups(grpnames);
  1638. for(unsigned i = 0; i < grpnames.length(); i++)
  1639. {
  1640. const char* grpname = grpnames.item(i);
  1641. if(grpname == NULL || *grpname == '\0')
  1642. continue;
  1643. Owned<IEspGroupInfo> onegrp = createGroupInfo();
  1644. onegrp->setName(grpname);
  1645. groups.append(*onegrp.getLink());
  1646. }
  1647. resp.setGroups(groups);
  1648. }
  1649. catch(IException* e)
  1650. {
  1651. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  1652. }
  1653. return true;
  1654. }
  1655. bool Cws_accessEx::onClearPermissionsCache(IEspContext &context, IEspClearPermissionsCacheRequest &req, IEspClearPermissionsCacheResponse &resp)
  1656. {
  1657. ISecManager* secmgr = context.querySecManager();
  1658. if(secmgr == NULL)
  1659. throw MakeStringException(ECLWATCH_INVALID_SEC_MANAGER, MSG_SEC_MANAGER_IS_NULL);
  1660. //Clear local cache
  1661. Owned<ISecUser> user = secmgr->createUser(context.queryUserId());
  1662. ISecCredentials& cred = user->credentials();
  1663. cred.setPassword(context.queryPassword());
  1664. bool ok = secmgr->clearPermissionsCache(*user);
  1665. //Request DALI to clear its cache
  1666. if (ok)
  1667. {
  1668. Owned<IUserDescriptor> userdesc;
  1669. userdesc.setown(createUserDescriptor());
  1670. userdesc->set(context.queryUserId(), context.queryPassword());
  1671. ok = querySessionManager().clearPermissionsCache(userdesc);
  1672. }
  1673. resp.setRetcode(ok ? 0 : -1);
  1674. return true;
  1675. }
  1676. bool Cws_accessEx::onQueryScopeScansEnabled(IEspContext &context, IEspQueryScopeScansEnabledRequest &req, IEspQueryScopeScansEnabledResponse &resp)
  1677. {
  1678. ISecManager* secmgr = context.querySecManager();
  1679. if(secmgr == NULL)
  1680. throw MakeStringException(ECLWATCH_INVALID_SEC_MANAGER, MSG_SEC_MANAGER_IS_NULL);
  1681. Owned<IUserDescriptor> userdesc;
  1682. userdesc.setown(createUserDescriptor());
  1683. userdesc->set(context.queryUserId(), context.queryPassword());
  1684. int retCode;
  1685. StringBuffer retMsg;
  1686. bool isEnabled = querySessionManager().queryScopeScansEnabled(userdesc, &retCode, retMsg);
  1687. if (retCode != 0)
  1688. throw MakeStringException(ECLWATCH_OLD_CLIENT_VERSION, "Error %d querying scope scan status : %s", retCode, retMsg.str());
  1689. resp.updateScopeScansStatus().setIsEnabled(isEnabled);
  1690. resp.updateScopeScansStatus().setRetcode(retCode);
  1691. resp.updateScopeScansStatus().setRetmsg(retMsg.str());
  1692. return true;
  1693. }
  1694. bool Cws_accessEx::onEnableScopeScans(IEspContext &context, IEspEnableScopeScansRequest &req, IEspEnableScopeScansResponse &resp)
  1695. {
  1696. StringBuffer retMsg;
  1697. int rc = enableDisableScopeScans(context, true, retMsg);
  1698. resp.updateScopeScansStatus().setIsEnabled(rc == 0);
  1699. resp.updateScopeScansStatus().setRetcode(rc);
  1700. resp.updateScopeScansStatus().setRetmsg(retMsg.str());
  1701. return true;
  1702. }
  1703. bool Cws_accessEx::onDisableScopeScans(IEspContext &context, IEspDisableScopeScansRequest &req, IEspDisableScopeScansResponse &resp)
  1704. {
  1705. StringBuffer retMsg;
  1706. int rc = enableDisableScopeScans(context, false, retMsg);
  1707. resp.updateScopeScansStatus().setIsEnabled(rc != 0);
  1708. resp.updateScopeScansStatus().setRetcode(rc);
  1709. resp.updateScopeScansStatus().setRetmsg(retMsg.str());
  1710. return true;
  1711. }
  1712. int Cws_accessEx::enableDisableScopeScans(IEspContext &context, bool doEnable, StringBuffer &retMsg)
  1713. {
  1714. ISecManager* secmgr = context.querySecManager();
  1715. if(secmgr == NULL)
  1716. throw MakeStringException(ECLWATCH_INVALID_SEC_MANAGER, MSG_SEC_MANAGER_IS_NULL);
  1717. Owned<IUserDescriptor> userdesc;
  1718. userdesc.setown(createUserDescriptor());
  1719. userdesc->set(context.queryUserId(), context.queryPassword());
  1720. int retCode;
  1721. bool rc = querySessionManager().enableScopeScans(userdesc, doEnable, &retCode, retMsg);
  1722. if (!rc || retCode != 0)
  1723. DBGLOG("Error %d enabling Scope Scans : %s", retCode, retMsg.str());
  1724. return retCode;
  1725. }
  1726. bool Cws_accessEx::permissionsReset(CLdapSecManager* ldapsecmgr, const char* basedn, const char* rtype0, const char* prefix,
  1727. const char* resourceName, ACT_TYPE accountType, const char* accountName,
  1728. bool allow_access, bool allow_read, bool allow_write, bool allow_full,
  1729. bool deny_access, bool deny_read, bool deny_write, bool deny_full)
  1730. {
  1731. CPermissionAction paction;
  1732. paction.m_basedn.append(basedn);
  1733. //const char* name = req.getRname();
  1734. StringBuffer namebuf(resourceName);
  1735. SecResourceType rtype = str2type(rtype0);
  1736. if(rtype == RT_MODULE && stricmp(resourceName, "repository") != 0 && Utils::strncasecmp(resourceName, "repository.", 11) != 0)
  1737. namebuf.insert(0, "repository.");
  1738. if(prefix && *prefix)
  1739. namebuf.insert(0, prefix);
  1740. paction.m_rname.append(namebuf.str());
  1741. paction.m_rtype = str2type(rtype0);
  1742. paction.m_allows = 0;
  1743. paction.m_denies = 0;
  1744. if(allow_full)
  1745. paction.m_allows |= NewSecAccess_Full;
  1746. if(allow_read)
  1747. paction.m_allows |= NewSecAccess_Read;
  1748. if(allow_write)
  1749. paction.m_allows |= NewSecAccess_Write;
  1750. if(allow_access)
  1751. paction.m_allows |= NewSecAccess_Access;
  1752. if(deny_full)
  1753. paction.m_denies |= NewSecAccess_Full;
  1754. if(deny_read)
  1755. paction.m_denies |= NewSecAccess_Read;
  1756. if(deny_write)
  1757. paction.m_denies |= NewSecAccess_Write;
  1758. if(deny_access)
  1759. paction.m_denies |= NewSecAccess_Access;
  1760. paction.m_action.append("update");
  1761. paction.m_account_type = accountType;
  1762. paction.m_account_name.append(accountName);
  1763. bool ret = ldapsecmgr->changePermission(paction);
  1764. return ret;
  1765. }
  1766. bool Cws_accessEx::onPermissionsReset(IEspContext &context, IEspPermissionsResetRequest &req, IEspPermissionsResetResponse &resp)
  1767. {
  1768. try
  1769. {
  1770. checkUser(context);
  1771. resp.setBasedn(req.getBasedn());
  1772. resp.setRname(req.getRname());
  1773. resp.setRtype(req.getRtype());
  1774. resp.setRtitle(req.getRtitle());
  1775. resp.setPrefix(req.getPrefix());
  1776. ISecManager* secmgr = context.querySecManager();
  1777. if(secmgr == NULL)
  1778. throw MakeStringException(ECLWATCH_INVALID_SEC_MANAGER, MSG_SEC_MANAGER_IS_NULL);
  1779. CLdapSecManager* ldapsecmgr = (CLdapSecManager*)secmgr;
  1780. const char* users = req.getUserarray();
  1781. const char* groups = req.getGrouparray();
  1782. if ((!users || !*users) && (!groups || !*groups))
  1783. throw MakeStringException(ECLWATCH_INVALID_ACCOUNT_NAME, "A user or group must be specified.");
  1784. StringArray& resources = req.getNames();
  1785. if (resources.length() < 1)
  1786. throw MakeStringException(ECLWATCH_INVALID_RESOURCE_NAME, "A resource name must be specified.");
  1787. StringArray userAccounts, groupAccounts;
  1788. if (users && *users)
  1789. {
  1790. char* pTr = (char*) users;
  1791. while (pTr)
  1792. {
  1793. char* ppTr = strchr(pTr, ',');
  1794. if (!ppTr)
  1795. break;
  1796. if (ppTr - pTr > 1)
  1797. {
  1798. char userName[255];
  1799. strncpy(userName, pTr, ppTr - pTr);
  1800. userName[ppTr - pTr] = 0;
  1801. userAccounts.append(userName);
  1802. }
  1803. pTr = ppTr+1;
  1804. }
  1805. }
  1806. if (groups && *groups)
  1807. {
  1808. char* pTr = (char*) groups;
  1809. while (pTr)
  1810. {
  1811. char* ppTr = strchr(pTr, ',');
  1812. if (!ppTr)
  1813. break;
  1814. if (ppTr - pTr > 1)
  1815. {
  1816. char userName[255];
  1817. strncpy(userName, pTr, ppTr - pTr);
  1818. userName[ppTr - pTr] = 0;
  1819. groupAccounts.append(userName);
  1820. }
  1821. pTr = ppTr+1;
  1822. }
  1823. }
  1824. if (userAccounts.length() < 1 && groupAccounts.length() < 1)
  1825. throw MakeStringException(ECLWATCH_INVALID_ACCOUNT_NAME, "A user or group must be specified.");
  1826. for(unsigned i = 0; i < resources.length(); i++)
  1827. {
  1828. const char* name = resources.item(i);
  1829. if (!name || !*name)
  1830. continue;
  1831. bool ret = true;
  1832. StringBuffer retmsg;
  1833. try
  1834. {
  1835. if (userAccounts.length() > 0)
  1836. {
  1837. for(unsigned j = 0; j < userAccounts.length(); j++)
  1838. {
  1839. const char* name0 = userAccounts.item(j);
  1840. if (!name0 || !*name0)
  1841. continue;
  1842. ret = permissionsReset(ldapsecmgr, req.getBasedn(), req.getRtype(), req.getPrefix(), name, USER_ACT, name0,
  1843. req.getAllow_access(), req.getAllow_read(), req.getAllow_write(), req.getAllow_full(),
  1844. req.getDeny_access(), req.getDeny_read(), req.getDeny_write(), req.getDeny_full());
  1845. if(!ret)
  1846. {
  1847. resp.setRetcode(-1);
  1848. resp.setRetmsg("Unknown error");
  1849. return false;
  1850. }
  1851. }
  1852. }
  1853. if (groupAccounts.length() > 0)
  1854. {
  1855. for(unsigned j = 0; j < groupAccounts.length(); j++)
  1856. {
  1857. const char* name0 = groupAccounts.item(j);
  1858. if (!name0 || !*name0)
  1859. continue;
  1860. ret = permissionsReset(ldapsecmgr, req.getBasedn(), req.getRtype(), req.getPrefix(), name, GROUP_ACT, name0,
  1861. req.getAllow_access(), req.getAllow_read(), req.getAllow_write(), req.getAllow_full(),
  1862. req.getDeny_access(), req.getDeny_read(), req.getDeny_write(), req.getDeny_full());
  1863. if(!ret)
  1864. {
  1865. resp.setRetcode(-1);
  1866. resp.setRetmsg("Unknown error");
  1867. return false;
  1868. }
  1869. }
  1870. }
  1871. }
  1872. catch(IException* e)
  1873. {
  1874. resp.setRetcode(e->errorCode());
  1875. e->errorMessage(retmsg);
  1876. resp.setRetmsg(retmsg.str());
  1877. return false;
  1878. }
  1879. }
  1880. resp.setRetcode(0);
  1881. }
  1882. catch(IException* e)
  1883. {
  1884. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  1885. }
  1886. return true;
  1887. }
  1888. //For every resources inside a baseDN, if there is no permission for this account, add the baseDN name to the basednNames list
  1889. void Cws_accessEx::getBaseDNsForAddingPermssionToAccount(CLdapSecManager* secmgr, const char* prefix, const char* accountName,
  1890. int accountType, StringArray& basednNames)
  1891. {
  1892. if(secmgr == NULL)
  1893. throw MakeStringException(ECLWATCH_INVALID_SEC_MANAGER, MSG_SEC_MANAGER_IS_NULL);
  1894. ForEachItemIn(i, m_basedns)
  1895. {
  1896. IEspDnStruct* curbasedn = &(m_basedns.item(i));
  1897. const char *basednName = curbasedn->getName();
  1898. if (!basednName || !*basednName)
  1899. continue;
  1900. const char *basedn = curbasedn->getBasedn();
  1901. const char *rtypestr = curbasedn->getRtype();
  1902. if (!basedn || !*basedn || !rtypestr || !*rtypestr)
  1903. continue;
  1904. IArrayOf<ISecResource> resources;
  1905. SecResourceType rtype = str2type(rtypestr);
  1906. if(!secmgr->getResources(rtype, basedn, resources))
  1907. continue;
  1908. ForEachItemIn(j, resources)
  1909. {
  1910. ISecResource& r = resources.item(j);
  1911. const char* rname = r.getName();
  1912. if(!rname || !*rname)
  1913. continue;
  1914. if(prefix && *prefix)
  1915. {
  1916. int prefixlen = strlen(prefix);
  1917. if(strncmp(prefix, rname, prefixlen) == 0)
  1918. rname += prefixlen;
  1919. }
  1920. StringBuffer namebuf(rname);
  1921. if((rtype == RT_MODULE) && !strieq(rname, "repository") && Utils::strncasecmp(rname, "repository.", 11) != 0)
  1922. namebuf.insert(0, "repository.");
  1923. if(prefix && *prefix)
  1924. namebuf.insert(0, prefix);
  1925. try
  1926. {
  1927. IArrayOf<CPermission> permissions;
  1928. secmgr->getPermissionsArray(basedn, rtype, namebuf.str(), permissions);
  1929. bool foundPermissionInThisAccount = false;
  1930. ForEachItemIn(k, permissions)
  1931. {
  1932. CPermission& perm = permissions.item(k);
  1933. if ((accountType == perm.getAccount_type()) && perm.getAccount_name() && streq(perm.getAccount_name(), accountName))
  1934. {
  1935. foundPermissionInThisAccount = true;
  1936. break;
  1937. }
  1938. }
  1939. if (!foundPermissionInThisAccount)
  1940. {
  1941. basednNames.append(basednName);
  1942. break;
  1943. }
  1944. }
  1945. catch(IException* e) //exception may be thrown when no permission for the resource
  1946. {
  1947. e->Release();
  1948. break;
  1949. }
  1950. }
  1951. }
  1952. return;
  1953. }
  1954. bool Cws_accessEx::permissionAddInputOnResource(IEspContext &context, IEspPermissionAddRequest &req, IEspPermissionAddResponse &resp)
  1955. {
  1956. CLdapSecManager* secmgr = (CLdapSecManager*)context.querySecManager();
  1957. if(secmgr == NULL)
  1958. throw MakeStringException(ECLWATCH_INVALID_SEC_MANAGER, MSG_SEC_MANAGER_IS_NULL);
  1959. int numusers = secmgr->countUsers("", MAX_USERS_DISPLAY);
  1960. if(numusers == -1)
  1961. {
  1962. resp.setToomany(true);
  1963. }
  1964. else
  1965. {
  1966. resp.setToomany(false);
  1967. IArrayOf<IEspUserInfo> espusers;
  1968. IUserArray users;
  1969. secmgr->getAllUsers(users);
  1970. ForEachItemIn(x, users)
  1971. {
  1972. CLdapSecUser* usr = dynamic_cast<CLdapSecUser*>(&users.item(x));
  1973. if(usr)
  1974. {
  1975. Owned<IEspUserInfo> oneusr = createUserInfo();
  1976. oneusr->setUsername(usr->getName());
  1977. oneusr->setFullname(usr->getFullName());
  1978. espusers.append(*oneusr.getLink());
  1979. }
  1980. }
  1981. resp.setUsers(espusers);
  1982. }
  1983. IArrayOf<IEspGroupInfo> groups;
  1984. if(secmgr->getLdapServerType() != ACTIVE_DIRECTORY)
  1985. {
  1986. Owned<IEspGroupInfo> onegrp = createGroupInfo();
  1987. onegrp->setName("anyone");
  1988. groups.append(*onegrp.getLink());
  1989. }
  1990. StringArray grpnames;
  1991. secmgr->getAllGroups(grpnames);
  1992. for(unsigned i = 0; i < grpnames.length(); i++)
  1993. {
  1994. const char* grpname = grpnames.item(i);
  1995. if(grpname == NULL || *grpname == '\0')
  1996. continue;
  1997. Owned<IEspGroupInfo> onegrp = createGroupInfo();
  1998. onegrp->setName(grpname);
  1999. groups.append(*onegrp.getLink());
  2000. }
  2001. resp.setGroups(groups);
  2002. return true;
  2003. }
  2004. bool Cws_accessEx::permissionAddInputOnAccount(IEspContext &context, const char* accountName, IEspPermissionAddRequest &req, IEspPermissionAddResponse &resp)
  2005. {
  2006. CLdapSecManager* secmgr = (CLdapSecManager*)context.querySecManager();
  2007. if(secmgr == NULL)
  2008. throw MakeStringException(ECLWATCH_INVALID_SEC_MANAGER, MSG_SEC_MANAGER_IS_NULL);
  2009. resp.setBasednName(req.getBasednName());
  2010. resp.setAccountName(req.getAccountName());
  2011. resp.setAccountType(req.getAccountType());
  2012. const char* prefix = req.getPrefix();
  2013. const char* basednName = req.getBasednName();
  2014. int accountType = req.getAccountType();
  2015. if (basednName && *basednName)
  2016. {
  2017. ForEachItemIn(y, m_basedns)
  2018. {
  2019. IEspDnStruct* curbasedn = &(m_basedns.item(y));
  2020. const char *aName = curbasedn->getName();
  2021. if (!aName || stricmp(basednName, aName))
  2022. continue;
  2023. const char *basedn = curbasedn->getBasedn();
  2024. const char *rtypestr = curbasedn->getRtype();
  2025. if (!basedn || !*basedn || !rtypestr || !*rtypestr)
  2026. continue;
  2027. IArrayOf<ISecResource> resources;
  2028. SecResourceType rtype = str2type(rtypestr);
  2029. if(secmgr->getResources(rtype, basedn, resources))
  2030. {
  2031. StringArray resourcenames;
  2032. for(unsigned i = 0; i < resources.length(); i++)
  2033. {
  2034. ISecResource& r = resources.item(i);
  2035. const char* rname = r.getName();
  2036. if(rname == NULL || *rname == '\0')
  2037. continue;
  2038. if(prefix && *prefix)
  2039. {
  2040. int prefixlen = strlen(prefix);
  2041. if(strncmp(prefix, rname, prefixlen) == 0)
  2042. rname += prefixlen;
  2043. }
  2044. if((rtype == RT_MODULE) && stricmp(rname, "repository"))
  2045. {
  2046. if(Utils::strncasecmp(rname, "repository.", 11) == 0)
  2047. rname = rname + 11;
  2048. else
  2049. continue;
  2050. }
  2051. StringBuffer namebuf(rname);
  2052. if((rtype == RT_MODULE) && stricmp(rname, "repository") != 0 && Utils::strncasecmp(rname, "repository.", 11) != 0)
  2053. namebuf.insert(0, "repository.");
  2054. if(prefix && *prefix)
  2055. namebuf.insert(0, prefix);
  2056. try
  2057. {
  2058. IArrayOf<CPermission> permissions;
  2059. secmgr->getPermissionsArray(basedn, rtype, namebuf.str(), permissions);
  2060. bool found = false;
  2061. ForEachItemIn(x, permissions)
  2062. {
  2063. CPermission& perm = permissions.item(x);
  2064. const char* actname = perm.getAccount_name();
  2065. int accType = perm.getAccount_type(); //0-individual, 1 - group
  2066. if ((accountType == accType) && actname && !strcmp(actname, accountName))
  2067. {
  2068. found = true;
  2069. break;
  2070. }
  2071. }
  2072. if (!found)
  2073. resourcenames.append(rname);
  2074. }
  2075. catch(IException* e) //exception may be thrown when no permission for the resource
  2076. {
  2077. e->Release();
  2078. break;
  2079. }
  2080. }
  2081. if (resourcenames.length() > 0)
  2082. resp.setResources(resourcenames);
  2083. }
  2084. }
  2085. }
  2086. return true;
  2087. }
  2088. bool Cws_accessEx::onPermissionAction(IEspContext &context, IEspPermissionActionRequest &req, IEspPermissionActionResponse &resp)
  2089. {
  2090. try
  2091. {
  2092. checkUser(context);
  2093. resp.setBasedn(req.getBasedn());
  2094. resp.setRname(req.getRname());
  2095. resp.setRtype(req.getRtype());
  2096. resp.setRtitle(req.getRtitle());
  2097. resp.setPrefix(req.getPrefix());
  2098. ISecManager* secmgr = context.querySecManager();
  2099. if(secmgr == NULL)
  2100. throw MakeStringException(ECLWATCH_INVALID_SEC_MANAGER, MSG_SEC_MANAGER_IS_NULL);
  2101. CLdapSecManager* ldapsecmgr = (CLdapSecManager*)secmgr;
  2102. CPermissionAction paction;
  2103. paction.m_basedn.append(req.getBasedn());
  2104. const char* name = req.getRname();
  2105. StringBuffer namebuf(name);
  2106. SecResourceType rtype = str2type(req.getRtype());
  2107. if(rtype == RT_MODULE && stricmp(name, "repository") != 0 && Utils::strncasecmp(name, "repository.", 11) != 0)
  2108. namebuf.insert(0, "repository.");
  2109. const char* prefix = req.getPrefix();
  2110. if(prefix && *prefix)
  2111. namebuf.insert(0, prefix);
  2112. double version = context.getClientVersion();
  2113. paction.m_rname.append(namebuf.str());
  2114. paction.m_rtype = str2type(req.getRtype());
  2115. paction.m_account_type = (ACT_TYPE)req.getAccount_type();
  2116. if(stricmp(req.getAction(), "add") == 0)
  2117. {
  2118. StringBuffer basednNameStr, resourceNameStr;
  2119. if (version >= 1.01)
  2120. {
  2121. const char* basedn_name = req.getBasednName();
  2122. const char* resource_name = req.getResourceName();
  2123. if (basedn_name && *basedn_name)
  2124. basednNameStr.append(basedn_name);
  2125. if (resource_name && *resource_name)
  2126. resourceNameStr.append(resource_name);
  2127. }
  2128. const char* user = req.getUser();
  2129. const char* grp = req.getGroup();
  2130. if(user != NULL && *user != '\0')
  2131. {
  2132. paction.m_account_name.append(user);
  2133. paction.m_account_type = USER_ACT;
  2134. }
  2135. else if(grp != NULL && *grp != '\0')
  2136. {
  2137. paction.m_account_name.append(grp);
  2138. // anyone is actually treated as a virtual "user" by sun and open ldap.
  2139. if((ldapsecmgr->getLdapServerType() != ACTIVE_DIRECTORY) && (stricmp(grp, "anyone") == 0))
  2140. paction.m_account_type = USER_ACT;
  2141. else
  2142. paction.m_account_type = GROUP_ACT;
  2143. }
  2144. else if((basednNameStr.length() > 0) && (resourceNameStr.length() > 0))
  2145. {
  2146. const char* account_name = req.getAccount_name();
  2147. if (!account_name || !*account_name)
  2148. {
  2149. resp.setRetcode(-1);
  2150. resp.setRetmsg("Please input or select user/group");
  2151. return false;
  2152. }
  2153. paction.m_account_name.clear().append(account_name);
  2154. ForEachItemIn(y, m_basedns)
  2155. {
  2156. IEspDnStruct* curbasedn = &(m_basedns.item(y));
  2157. const char *aName = curbasedn->getName();
  2158. if (!aName || stricmp(basednNameStr.str(), aName))
  2159. continue;
  2160. const char *basedn = curbasedn->getBasedn();
  2161. const char *rtypestr = curbasedn->getRtype();
  2162. if (!basedn || !*basedn || !rtypestr || !*rtypestr)
  2163. continue;
  2164. StringBuffer namebuf(resourceNameStr);
  2165. SecResourceType rtype = str2type(rtypestr);
  2166. if(rtype == RT_MODULE && stricmp(namebuf.str(), "codegenerator.cpp") && stricmp(namebuf.str(), "repository") != 0 && Utils::strncasecmp(namebuf.str(), "repository.", 11) != 0)
  2167. namebuf.insert(0, "repository.");
  2168. if(prefix && *prefix)
  2169. namebuf.insert(0, prefix);
  2170. paction.m_basedn.clear().append(basedn);
  2171. paction.m_rname.clear().append(namebuf.str());
  2172. paction.m_rtype = rtype;
  2173. break;
  2174. }
  2175. resp.setAccountName(account_name);
  2176. if (req.getAccount_type() < 1)
  2177. resp.setIsGroup(false);
  2178. else
  2179. resp.setIsGroup(true);
  2180. }
  2181. else
  2182. {
  2183. resp.setRetcode(-1);
  2184. resp.setRetmsg("Please input or select user/group");
  2185. return false;
  2186. }
  2187. }
  2188. else
  2189. {
  2190. paction.m_account_name.append(req.getAccount_name());
  2191. if (version >= 1.01)
  2192. {
  2193. resp.setAccountName(req.getAccount_name());
  2194. if (req.getAccount_type() < 1)
  2195. resp.setIsGroup(false);
  2196. else
  2197. resp.setIsGroup(true);
  2198. }
  2199. }
  2200. paction.m_allows = 0;
  2201. paction.m_denies = 0;
  2202. if(req.getAllow_full())
  2203. paction.m_allows |= NewSecAccess_Full;
  2204. if(req.getAllow_read())
  2205. paction.m_allows |= NewSecAccess_Read;
  2206. if(req.getAllow_write())
  2207. paction.m_allows |= NewSecAccess_Write;
  2208. if(req.getAllow_access())
  2209. paction.m_allows |= NewSecAccess_Access;
  2210. if(req.getDeny_full())
  2211. paction.m_denies |= NewSecAccess_Full;
  2212. if(req.getDeny_read())
  2213. paction.m_denies |= NewSecAccess_Read;
  2214. if(req.getDeny_write())
  2215. paction.m_denies |= NewSecAccess_Write;
  2216. if(req.getDeny_access())
  2217. paction.m_denies |= NewSecAccess_Access;
  2218. paction.m_action.append(req.getAction());
  2219. bool ret = true;
  2220. StringBuffer retmsg;
  2221. try
  2222. {
  2223. ret = ldapsecmgr->changePermission(paction);
  2224. }
  2225. catch(IException* e)
  2226. {
  2227. resp.setRetcode(e->errorCode());
  2228. e->errorMessage(retmsg);
  2229. resp.setRetmsg(retmsg.str());
  2230. return false;
  2231. }
  2232. if(!ret)
  2233. {
  2234. resp.setRetcode(-1);
  2235. resp.setRetmsg("Unknown error");
  2236. return false;
  2237. }
  2238. resp.setRetcode(0);
  2239. }
  2240. catch(IException* e)
  2241. {
  2242. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  2243. }
  2244. return true;
  2245. }
  2246. bool Cws_accessEx::onUserResetPassInput(IEspContext &context, IEspUserResetPassInputRequest &req, IEspUserResetPassInputResponse &resp)
  2247. {
  2248. try
  2249. {
  2250. checkUser(context);
  2251. resp.setUsername(req.getUsername());
  2252. }
  2253. catch(IException* e)
  2254. {
  2255. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  2256. }
  2257. return true;
  2258. }
  2259. bool Cws_accessEx::onUserResetPass(IEspContext &context, IEspUserResetPassRequest &req, IEspUserResetPassResponse &resp)
  2260. {
  2261. try
  2262. {
  2263. checkUser(context);
  2264. resp.setUsername(req.getUsername());
  2265. ISecManager* secmgr = context.querySecManager();
  2266. if(secmgr == NULL)
  2267. throw MakeStringException(ECLWATCH_INVALID_SEC_MANAGER, MSG_SEC_MANAGER_IS_NULL);
  2268. CLdapSecManager* ldapsecmgr = (CLdapSecManager*)secmgr;
  2269. const char* username = req.getUsername();
  2270. if(username == NULL)
  2271. {
  2272. resp.setRetcode(-1);
  2273. resp.setRetmsg("username can't be empty");
  2274. return false;
  2275. }
  2276. const char* newpass1 = req.getNewPassword();
  2277. const char* newpass2 = req.getNewPasswordRetype();
  2278. if(newpass1 == NULL || newpass2 == NULL || *newpass1 == '\0' || *newpass2 == '\0' || strcmp(newpass1, newpass2) != 0)
  2279. {
  2280. resp.setRetcode(-1);
  2281. resp.setRetmsg("new password and retype can't be empty and must match");
  2282. return false;
  2283. }
  2284. bool ret = ldapsecmgr->updateUserPassword(username, req.getNewPassword());
  2285. if(ret)
  2286. {
  2287. resp.setRetcode(0);
  2288. resp.setRetmsg("");
  2289. return false;
  2290. }
  2291. else
  2292. {
  2293. resp.setRetcode(-1);
  2294. }
  2295. }
  2296. catch(IException* e)
  2297. {
  2298. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  2299. }
  2300. return true;
  2301. }
  2302. bool Cws_accessEx::onUserPosix(IEspContext &context, IEspUserPosixRequest &req, IEspUserPosixResponse &resp)
  2303. {
  2304. try
  2305. {
  2306. checkUser(context);
  2307. CLdapSecManager* secmgr = (CLdapSecManager*)context.querySecManager();
  2308. if(secmgr == NULL)
  2309. throw MakeStringException(ECLWATCH_INVALID_SEC_MANAGER, MSG_SEC_MANAGER_IS_NULL);
  2310. const char* username = req.getUsername();
  2311. if(username == NULL || *username == '\0')
  2312. {
  2313. resp.setRetcode(-1);
  2314. resp.setRetmsg("username can't be empty");
  2315. return false;
  2316. }
  2317. bool enable = req.getPosixenabled();
  2318. Owned<CLdapSecUser> user = (CLdapSecUser*)secmgr->createUser(username);
  2319. if(enable)
  2320. {
  2321. const char* gidnumber = req.getGidnumber();
  2322. const char* uidnumber = req.getUidnumber();
  2323. const char* homedirectory = req.getHomedirectory();
  2324. const char* loginshell = req.getLoginshell();
  2325. if(!gidnumber || !*gidnumber || !uidnumber || !*uidnumber || !homedirectory || !*homedirectory)
  2326. {
  2327. resp.setRetcode(-1);
  2328. resp.setRetmsg("gidnumber, uidnumber and homedirectory are required.");
  2329. return false;
  2330. }
  2331. unsigned i;
  2332. for(i = 0; i < strlen(gidnumber); i++)
  2333. {
  2334. if(!isdigit(gidnumber[i]))
  2335. throw MakeStringException(ECLWATCH_ID_MUST_BE_ALL_DIGITS, "Group ID Number should be all digits");
  2336. }
  2337. for(i = 0; i < strlen(uidnumber); i++)
  2338. {
  2339. if(!isdigit(uidnumber[i]))
  2340. throw MakeStringException(ECLWATCH_ID_MUST_BE_ALL_DIGITS, "User ID Number should be all digits");
  2341. }
  2342. user->setGidnumber(gidnumber);
  2343. user->setUidnumber(uidnumber);
  2344. user->setHomedirectory(homedirectory);
  2345. user->setLoginshell(loginshell);
  2346. }
  2347. try
  2348. {
  2349. secmgr->updateUser(enable?"posixenable":"posixdisable", *user.get());
  2350. }
  2351. catch(IException* e)
  2352. {
  2353. resp.setRetcode(-1);
  2354. StringBuffer errmsg;
  2355. resp.setRetmsg(e->errorMessage(errmsg).str());
  2356. return false;
  2357. }
  2358. resp.setUsername(username);
  2359. resp.setRetcode(0);
  2360. resp.setRetmsg("User's posix account info has been successfully updated");
  2361. }
  2362. catch(IException* e)
  2363. {
  2364. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  2365. }
  2366. return true;
  2367. }
  2368. bool Cws_accessEx::onUserPosixInput(IEspContext &context, IEspUserPosixInputRequest &req, IEspUserPosixInputResponse &resp)
  2369. {
  2370. try
  2371. {
  2372. checkUser(context);
  2373. CLdapSecManager* secmgr = (CLdapSecManager*)context.querySecManager();
  2374. if(secmgr == NULL)
  2375. throw MakeStringException(ECLWATCH_INVALID_SEC_MANAGER, MSG_SEC_MANAGER_IS_NULL);
  2376. const char* username = req.getUsername();
  2377. if(username == NULL || *username == '\0')
  2378. {
  2379. throw MakeStringException(ECLWATCH_INVALID_ACCOUNT_NAME, "Please specify a username.");
  2380. }
  2381. Owned<CLdapSecUser> user = (CLdapSecUser*)secmgr->createUser(username);
  2382. secmgr->getUserInfo(*user.get());
  2383. resp.setUsername(username);
  2384. resp.setPosixenabled(user->getPosixenabled());
  2385. if(user->getGidnumber())
  2386. resp.setGidnumber(user->getGidnumber());
  2387. if(user->getUidnumber())
  2388. resp.setUidnumber(user->getUidnumber());
  2389. if(user->getHomedirectory())
  2390. resp.setHomedirectory(user->getHomedirectory());
  2391. if(user->getLoginshell())
  2392. resp.setLoginshell(user->getLoginshell());
  2393. }
  2394. catch(IException* e)
  2395. {
  2396. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  2397. }
  2398. return true;
  2399. }
  2400. bool Cws_accessEx::onUserInfoEdit(IEspContext &context, IEspUserInfoEditRequest &req, IEspUserInfoEditResponse &resp)
  2401. {
  2402. try
  2403. {
  2404. checkUser(context);
  2405. CLdapSecManager* secmgr = (CLdapSecManager*)context.querySecManager();
  2406. if(secmgr == NULL)
  2407. throw MakeStringException(ECLWATCH_INVALID_SEC_MANAGER, MSG_SEC_MANAGER_IS_NULL);
  2408. const char* username = req.getUsername();
  2409. if(username == NULL || *username == '\0')
  2410. {
  2411. resp.setRetcode(-1);
  2412. resp.setRetmsg("username can't be empty");
  2413. return false;
  2414. }
  2415. const char* firstname = req.getFirstname();
  2416. const char* lastname = req.getLastname();
  2417. if((!firstname || !*firstname) && (!lastname || !*lastname))
  2418. {
  2419. resp.setRetcode(-1);
  2420. resp.setRetmsg("Please specify both firstname and lastname");
  2421. return false;
  2422. }
  2423. Owned<CLdapSecUser> user = (CLdapSecUser*)secmgr->createUser(username);
  2424. user->setFirstName(firstname);
  2425. user->setLastName(lastname);
  2426. try
  2427. {
  2428. secmgr->updateUser("names", *user.get());
  2429. }
  2430. catch(IException* e)
  2431. {
  2432. resp.setRetcode(-1);
  2433. StringBuffer errmsg;
  2434. resp.setRetmsg(e->errorMessage(errmsg).str());
  2435. return false;
  2436. }
  2437. resp.setUsername(username);
  2438. resp.setRetcode(0);
  2439. resp.setRetmsg("User's account info has been successfully updated");
  2440. }
  2441. catch(IException* e)
  2442. {
  2443. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  2444. }
  2445. return true;
  2446. }
  2447. bool Cws_accessEx::onUserInfoEditInput(IEspContext &context, IEspUserInfoEditInputRequest &req, IEspUserInfoEditInputResponse &resp)
  2448. {
  2449. try
  2450. {
  2451. checkUser(context);
  2452. CLdapSecManager* secmgr = (CLdapSecManager*)context.querySecManager();
  2453. if(secmgr == NULL)
  2454. throw MakeStringException(ECLWATCH_INVALID_SEC_MANAGER, MSG_SEC_MANAGER_IS_NULL);
  2455. const char* username = req.getUsername();
  2456. if(username == NULL || *username == '\0')
  2457. {
  2458. throw MakeStringException(ECLWATCH_INVALID_ACCOUNT_NAME, "Please specify a username.");
  2459. }
  2460. Owned<CLdapSecUser> user = (CLdapSecUser*)secmgr->createUser(username);
  2461. secmgr->getUserInfo(*user.get());
  2462. resp.setUsername(username);
  2463. resp.setFirstname(user->getFirstName());
  2464. resp.setLastname(user->getLastName());
  2465. }
  2466. catch(IException* e)
  2467. {
  2468. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  2469. }
  2470. return true;
  2471. }
  2472. bool Cws_accessEx::onUserSudoersInput(IEspContext &context, IEspUserSudoersInputRequest &req, IEspUserSudoersInputResponse &resp)
  2473. {
  2474. try
  2475. {
  2476. checkUser(context);
  2477. CLdapSecManager* secmgr = (CLdapSecManager*)context.querySecManager();
  2478. if(secmgr == NULL)
  2479. throw MakeStringException(ECLWATCH_INVALID_SEC_MANAGER, MSG_SEC_MANAGER_IS_NULL);
  2480. const char* username = req.getUsername();
  2481. if(username == NULL || *username == '\0')
  2482. {
  2483. throw MakeStringException(ECLWATCH_INVALID_ACCOUNT_NAME, "Please specify a username.");
  2484. }
  2485. Owned<CLdapSecUser> user = (CLdapSecUser*)secmgr->createUser(username);
  2486. secmgr->getUserInfo(*user.get(), "sudoers");
  2487. resp.setUsername(username);
  2488. resp.setInsudoers(user->getInSudoers());
  2489. if(user->getInSudoers())
  2490. {
  2491. resp.setSudoHost(user->getSudoHost());
  2492. resp.setSudoCommand(user->getSudoCommand());
  2493. resp.setSudoOption(user->getSudoOption());
  2494. }
  2495. else
  2496. {
  2497. resp.setSudoHost("ALL");
  2498. resp.setSudoCommand("ALL");
  2499. resp.setSudoOption("!authenticate");
  2500. }
  2501. }
  2502. catch(IException* e)
  2503. {
  2504. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  2505. }
  2506. return true;
  2507. }
  2508. bool Cws_accessEx::onUserSudoers(IEspContext &context, IEspUserSudoersRequest &req, IEspUserSudoersResponse &resp)
  2509. {
  2510. try
  2511. {
  2512. checkUser(context);
  2513. CLdapSecManager* secmgr = (CLdapSecManager*)context.querySecManager();
  2514. if(secmgr == NULL)
  2515. throw MakeStringException(ECLWATCH_INVALID_SEC_MANAGER, MSG_SEC_MANAGER_IS_NULL);
  2516. const char* username = req.getUsername();
  2517. if(username == NULL || *username == '\0')
  2518. {
  2519. resp.setRetcode(-1);
  2520. resp.setRetmsg("username can't be empty");
  2521. return false;
  2522. }
  2523. resp.setUsername(username);
  2524. Owned<CLdapSecUser> user = (CLdapSecUser*)secmgr->createUser(username);
  2525. const char* action = req.getAction();
  2526. if(!action || !*action)
  2527. {
  2528. resp.setRetcode(-1);
  2529. resp.setRetmsg("Action can't be empty");
  2530. return false;
  2531. }
  2532. user->setSudoHost(req.getSudoHost());
  2533. user->setSudoCommand(req.getSudoCommand());
  2534. user->setSudoOption(req.getSudoOption());
  2535. bool ok = false;
  2536. StringBuffer retmsg;
  2537. try
  2538. {
  2539. if(stricmp(action, "add") == 0)
  2540. ok = secmgr->updateUser("sudoersadd", *user.get());
  2541. else if(stricmp(action, "delete") == 0)
  2542. ok = secmgr->updateUser("sudoersdelete", *user.get());
  2543. else if(stricmp(action, "update") == 0)
  2544. ok = secmgr->updateUser("sudoersupdate", *user.get());
  2545. }
  2546. catch(IException* e)
  2547. {
  2548. ok = false;
  2549. e->errorMessage(retmsg);
  2550. e->Release();
  2551. }
  2552. catch(...)
  2553. {
  2554. ok = false;
  2555. retmsg.append("unknown exception");
  2556. }
  2557. if(!ok)
  2558. {
  2559. resp.setRetcode(-1);
  2560. resp.setRetmsg(retmsg.str());
  2561. }
  2562. else
  2563. {
  2564. resp.setRetcode(0);
  2565. resp.setRetmsg("succeeded.");
  2566. }
  2567. }
  2568. catch(IException* e)
  2569. {
  2570. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  2571. }
  2572. return true;
  2573. }
  2574. bool Cws_accessEx::onAccountPermissions(IEspContext &context, IEspAccountPermissionsRequest &req, IEspAccountPermissionsResponse &resp)
  2575. {
  2576. try
  2577. {
  2578. checkUser(context);
  2579. double version = context.getClientVersion();
  2580. ISecManager* secmgr = context.querySecManager();
  2581. if(secmgr == NULL)
  2582. throw MakeStringException(ECLWATCH_INVALID_SEC_MANAGER, MSG_SEC_MANAGER_IS_NULL);
  2583. const char* username = req.getAccountName();
  2584. if(username == NULL || *username == '\0')
  2585. {
  2586. throw MakeStringException(ECLWATCH_INVALID_ACCOUNT_NAME, "Please specify an account name.");
  2587. }
  2588. bool bGroupAccount = req.getIsGroup();
  2589. bool bIncludeGroup = req.getIncludeGroup();
  2590. if(m_basedns.length() == 0)
  2591. {
  2592. setBasedns(context);
  2593. }
  2594. CLdapSecManager* ldapsecmgr = (CLdapSecManager*)secmgr;
  2595. StringArray groupnames;
  2596. if (version > 1.02 && !bGroupAccount && bIncludeGroup)
  2597. {
  2598. ldapsecmgr->getGroups(username, groupnames);
  2599. }
  2600. groupnames.append("Authenticated Users");
  2601. groupnames.append("everyone");
  2602. IArrayOf<IEspAccountPermission> accountPermissions;
  2603. bool bAuthUsersPerm = false;
  2604. Owned<IEspGroupAccountPermission> grouppermission1 = createGroupAccountPermission();
  2605. grouppermission1->setGroupName("Authenticated Users");
  2606. if (version > 1.05)
  2607. {
  2608. StringArray basednNames;
  2609. getBaseDNsForAddingPermssionToAccount(ldapsecmgr, NULL, "Authenticated Users", 1, basednNames);
  2610. if (basednNames.length() > 0)
  2611. grouppermission1->setBasednNames(basednNames);
  2612. }
  2613. IArrayOf<IConstAccountPermission>& authUsersPermissions = grouppermission1->getPermissions();
  2614. bool bEveryonePerm = false;
  2615. Owned<IEspGroupAccountPermission> grouppermission2 = createGroupAccountPermission();
  2616. grouppermission2->setGroupName("Everyone");
  2617. if (version > 1.05)
  2618. {
  2619. StringArray basednNames;
  2620. getBaseDNsForAddingPermssionToAccount(ldapsecmgr, NULL, "Everyone", 1, basednNames);
  2621. if (basednNames.length() > 0)
  2622. grouppermission2->setBasednNames(basednNames);
  2623. }
  2624. IArrayOf<IConstAccountPermission>& everyonePermissions = grouppermission2->getPermissions();
  2625. IArrayOf<IEspGroupAccountPermission> groupAccountPermissions;
  2626. StringBuffer moduleBasedn; //To be used by the Permission: codegenerator.cpp
  2627. ForEachItemIn(y1, m_basedns)
  2628. {
  2629. IEspDnStruct* curbasedn = &(m_basedns.item(y1));
  2630. const char *aName = curbasedn->getName();
  2631. const char *aBasedn = curbasedn->getBasedn();
  2632. const char *aRtype = curbasedn->getRtype();
  2633. const char *aRtitle = curbasedn->getRtitle();
  2634. if (!aName || !*aName ||!aBasedn || !*aBasedn ||!aRtype || !*aRtype ||!aRtitle || !*aRtitle)
  2635. continue;
  2636. SecResourceType rtype = str2type(aRtype);
  2637. if (rtype == RT_MODULE)
  2638. {
  2639. moduleBasedn.append(aBasedn);
  2640. break;
  2641. }
  2642. }
  2643. ForEachItemIn(y, m_basedns)
  2644. {
  2645. IEspDnStruct* curbasedn = &(m_basedns.item(y));
  2646. const char *aName = curbasedn->getName();
  2647. const char *aBasedn = curbasedn->getBasedn();
  2648. const char *aRtype = curbasedn->getRtype();
  2649. const char *aRtitle = curbasedn->getRtitle();
  2650. if (!aName || !*aName ||!aBasedn || !*aBasedn ||!aRtype || !*aRtype ||!aRtitle || !*aRtitle)
  2651. continue;
  2652. SecResourceType rtype = str2type(aRtype);
  2653. IArrayOf<IEspResource> ResourceArray;
  2654. //if(rtype == RT_FILE_SCOPE || rtype == RT_WORKUNIT_SCOPE)
  2655. if(rtype == RT_WORKUNIT_SCOPE)
  2656. {
  2657. StringBuffer deft_basedn, deft_name;
  2658. const char* comma = strchr(aBasedn, ',');
  2659. const char* eqsign = strchr(aBasedn, '=');
  2660. if(eqsign != NULL)
  2661. {
  2662. if(comma == NULL)
  2663. deft_name.append(eqsign+1);
  2664. else
  2665. {
  2666. deft_name.append(comma - eqsign - 1, eqsign+1);
  2667. deft_basedn.append(comma + 1);
  2668. }
  2669. }
  2670. if (deft_name.length() > 0)
  2671. {
  2672. Owned<IEspResource> oneresource = createResource();
  2673. oneresource->setName(deft_name);
  2674. oneresource->setDescription(deft_basedn);
  2675. ResourceArray.append(*oneresource.getLink());
  2676. }
  2677. }
  2678. IArrayOf<ISecResource> resources;
  2679. if(secmgr->getResources(rtype, aBasedn, resources))
  2680. {
  2681. ForEachItemIn(y1, resources)
  2682. {
  2683. ISecResource& r = resources.item(y1);
  2684. const char* rname = r.getName();
  2685. if(rname == NULL || *rname == '\0')
  2686. continue;
  2687. //permission codegenerator.cpp is saved as a service permission (not a module permission)
  2688. //when it is added for a user
  2689. if ((rtype == RT_MODULE) && (!stricmp(rname, "codegenerator.cpp")))
  2690. continue;
  2691. if((rtype == RT_MODULE) && Utils::strncasecmp(rname, "repository", 10))
  2692. {
  2693. continue;
  2694. }
  2695. Owned<IEspResource> oneresource = createResource();
  2696. oneresource->setName(rname);
  2697. oneresource->setDescription(aBasedn);
  2698. ResourceArray.append(*oneresource.getLink());
  2699. }
  2700. }
  2701. if(rtype == RT_SERVICE && moduleBasedn.length() > 0)
  2702. { //permission codegenerator.cpp is saved as a service permission when it is added for a user
  2703. Owned<IEspResource> oneresource = createResource();
  2704. oneresource->setName("codegenerator.cpp");
  2705. oneresource->setDescription(moduleBasedn.str());
  2706. ResourceArray.append(*oneresource.getLink());
  2707. moduleBasedn.clear();
  2708. }
  2709. ForEachItemIn(y2, ResourceArray)
  2710. {
  2711. IEspResource& r = ResourceArray.item(y2);
  2712. const char* rname = r.getName();
  2713. const char* dnname = r.getDescription();
  2714. if(rname == NULL || *rname == '\0')
  2715. continue;
  2716. StringBuffer namebuf(rname);
  2717. //const char* prefix = req.getPrefix();
  2718. //if(prefix && *prefix)
  2719. // namebuf.insert(0, prefix);
  2720. try
  2721. {
  2722. IArrayOf<CPermission> permissions;
  2723. ldapsecmgr->getPermissionsArray(dnname, rtype, namebuf.str(), permissions);
  2724. ForEachItemIn(x, permissions)
  2725. {
  2726. CPermission& perm = permissions.item(x);
  2727. int accountType = perm.getAccount_type(); //0-individual, 1 - group
  2728. if (bGroupAccount && accountType < 1)
  2729. continue;
  2730. if (!bGroupAccount && (accountType > 0) && (groupnames.length() < 1))
  2731. continue;
  2732. StringBuffer escapedname;
  2733. const char* actname = perm.getAccount_name();
  2734. if ((!bGroupAccount && accountType < 1) || (bGroupAccount && accountType > 0))
  2735. {
  2736. if(!actname || strcmp(actname, username))
  2737. continue;
  2738. }
  2739. else if (version > 1.02)
  2740. {
  2741. if(!actname || groupnames.length() < 1)
  2742. continue;
  2743. bool bFound = false;
  2744. for(unsigned i = 0; i < groupnames.length(); i++)
  2745. {
  2746. const char* group = groupnames.item(i);
  2747. if (!group || strcmp(actname, group))
  2748. continue;
  2749. bFound = true;
  2750. break;
  2751. }
  2752. if (!bFound)
  2753. continue;
  2754. }
  2755. Owned<IEspAccountPermission> onepermission = createAccountPermission();
  2756. onepermission->setBasedn(dnname);
  2757. onepermission->setRType(aRtype);
  2758. onepermission->setResourceName(aRtitle);
  2759. onepermission->setPermissionName(namebuf.str());
  2760. int allows = perm.getAllows();
  2761. int denies = perm.getDenies();
  2762. if((allows & NewSecAccess_Access) == NewSecAccess_Access)
  2763. onepermission->setAllow_access(true);
  2764. if((allows & NewSecAccess_Read) == NewSecAccess_Read)
  2765. onepermission->setAllow_read(true);
  2766. if((allows & NewSecAccess_Write) == NewSecAccess_Write)
  2767. onepermission->setAllow_write(true);
  2768. if((allows & NewSecAccess_Full) == NewSecAccess_Full)
  2769. onepermission->setAllow_full(true);
  2770. if((denies & NewSecAccess_Access) == NewSecAccess_Access)
  2771. onepermission->setDeny_access(true);
  2772. if((denies & NewSecAccess_Read) == NewSecAccess_Read)
  2773. onepermission->setDeny_read(true);
  2774. if((denies & NewSecAccess_Write) == NewSecAccess_Write)
  2775. onepermission->setDeny_write(true);
  2776. if((denies & NewSecAccess_Full) == NewSecAccess_Full)
  2777. onepermission->setDeny_full(true);
  2778. if ((!bGroupAccount && accountType < 1) || (bGroupAccount && accountType > 0))
  2779. accountPermissions.append(*onepermission.getLink());
  2780. else if (version > 1.02)
  2781. {
  2782. if (!strcmp(actname, "Authenticated Users"))
  2783. {
  2784. authUsersPermissions.append(*onepermission.getLink());
  2785. bAuthUsersPerm = true;
  2786. }
  2787. else if (!strcmp(actname, "everyone"))
  2788. {
  2789. everyonePermissions.append(*onepermission.getLink());
  2790. bEveryonePerm = true;
  2791. }
  2792. else
  2793. {
  2794. bool bFound = false;
  2795. ForEachItemIn(k, groupAccountPermissions)
  2796. {
  2797. IEspGroupAccountPermission& grouppermission0 = groupAccountPermissions.item(k);
  2798. const char* g_name = grouppermission0.getGroupName();
  2799. if (!g_name || strcmp(actname, g_name))
  2800. continue;
  2801. IArrayOf<IConstAccountPermission>& g_permission = grouppermission0.getPermissions();
  2802. g_permission.append(*onepermission.getLink());
  2803. bFound = true;
  2804. break;
  2805. }
  2806. if (!bFound)
  2807. {
  2808. Owned<IEspGroupAccountPermission> grouppermission = createGroupAccountPermission();
  2809. grouppermission->setGroupName(actname);
  2810. if (version > 1.05)
  2811. {
  2812. StringArray basednNames;
  2813. getBaseDNsForAddingPermssionToAccount(ldapsecmgr, NULL, actname, 1, basednNames);
  2814. if (basednNames.length() > 0)
  2815. grouppermission->setBasednNames(basednNames);
  2816. }
  2817. IArrayOf<IConstAccountPermission>& g_permission = grouppermission->getPermissions();
  2818. g_permission.append(*onepermission.getLink());
  2819. groupAccountPermissions.append(*grouppermission.getLink());
  2820. }
  2821. }
  2822. }
  2823. }
  2824. }
  2825. catch(IException* e) //exception may be thrown when no permission for the resource
  2826. {
  2827. e->Release();
  2828. }
  2829. }
  2830. }
  2831. StringArray basednNames;
  2832. getBaseDNsForAddingPermssionToAccount(ldapsecmgr, NULL, username, bGroupAccount? 1:0, basednNames);
  2833. if (basednNames.length() > 0)
  2834. {
  2835. resp.setBasednNames(basednNames);
  2836. }
  2837. if (accountPermissions.length() > 0)
  2838. {
  2839. resp.setPermissions(accountPermissions);
  2840. }
  2841. if (version > 1.02)
  2842. {
  2843. if (bAuthUsersPerm)
  2844. {
  2845. groupAccountPermissions.append(*grouppermission1.getLink());
  2846. }
  2847. if (bEveryonePerm)
  2848. {
  2849. groupAccountPermissions.append(*grouppermission2.getLink());
  2850. }
  2851. if (groupAccountPermissions.length() > 0)
  2852. {
  2853. resp.setGroupPermissions(groupAccountPermissions);
  2854. }
  2855. }
  2856. resp.setAccountName(req.getAccountName());
  2857. resp.setIsGroup(req.getIsGroup());
  2858. }
  2859. catch(IException* e)
  2860. {
  2861. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  2862. }
  2863. return true;
  2864. }
  2865. bool Cws_accessEx::onFilePermission(IEspContext &context, IEspFilePermissionRequest &req, IEspFilePermissionResponse &resp)
  2866. {
  2867. try
  2868. {
  2869. CLdapSecManager* secmgr = dynamic_cast<CLdapSecManager*>(context.querySecManager());
  2870. double version = context.getClientVersion();
  2871. if (version > 1.03)
  2872. {
  2873. if(secmgr == NULL)
  2874. {
  2875. resp.setNoSecMngr(true);
  2876. return true;
  2877. }
  2878. }
  2879. else
  2880. {
  2881. if(secmgr == NULL)
  2882. throw MakeStringException(ECLWATCH_INVALID_SEC_MANAGER, MSG_SEC_MANAGER_IS_NULL);
  2883. }
  2884. checkUser(context);
  2885. //Get all users for input form
  2886. int numusers = secmgr->countUsers("", MAX_USERS_DISPLAY);
  2887. if(numusers == -1)
  2888. {
  2889. resp.setToomany(true);
  2890. }
  2891. else
  2892. {
  2893. resp.setToomany(false);
  2894. IArrayOf<IEspUserInfo> espusers;
  2895. IUserArray users;
  2896. secmgr->getAllUsers(users);
  2897. ForEachItemIn(x, users)
  2898. {
  2899. CLdapSecUser* usr = dynamic_cast<CLdapSecUser*>(&users.item(x));
  2900. if(usr)
  2901. {
  2902. Owned<IEspUserInfo> oneusr = createUserInfo();
  2903. oneusr->setUsername(usr->getName());
  2904. oneusr->setFullname(usr->getFullName());
  2905. espusers.append(*oneusr.getLink());
  2906. }
  2907. }
  2908. resp.setUsers(espusers);
  2909. }
  2910. //Get all groups for input form
  2911. StringArray groupnames;
  2912. secmgr->getAllGroups(groupnames);
  2913. ///groupnames.append("Authenticated Users");
  2914. ///groupnames.append("Administrators");
  2915. if (groupnames.length() > 0)
  2916. {
  2917. IArrayOf<IEspGroupInfo> groups;
  2918. for(unsigned i = 0; i < groupnames.length(); i++)
  2919. {
  2920. const char* grpname = groupnames.item(i);
  2921. if(grpname == NULL || grpname[0] == '\0')
  2922. continue;
  2923. Owned<IEspGroupInfo> onegrp = createGroupInfo();
  2924. onegrp->setName(grpname);
  2925. groups.append(*onegrp.getLink());
  2926. }
  2927. resp.setGroups(groups);
  2928. }
  2929. const char* fileName = req.getFileName();
  2930. const char* userName = req.getUserName();
  2931. const char* groupName = req.getGroupName();
  2932. if (!fileName || !*fileName)
  2933. return true; //no file name is set when the input form is launched first time
  2934. if ((!groupName || !*groupName) && (!userName || !*userName))
  2935. throw MakeStringException(ECLWATCH_INVALID_ACCOUNT_NAME, "Either user name or group name has to be specified.");
  2936. int access = -1;
  2937. if (userName && *userName) //for user
  2938. {
  2939. resp.setFileName(fileName);
  2940. resp.setUserName(userName);
  2941. ISecUser* sec_user = secmgr->findUser(userName);
  2942. if (sec_user)
  2943. {
  2944. StringBuffer accessStr;
  2945. access = secmgr->authorizeEx(RT_FILE_SCOPE, *sec_user, fileName, false);
  2946. switch (access)
  2947. {
  2948. case SecAccess_Full:
  2949. resp.setUserPermission("Full Access Permission");
  2950. break;
  2951. case SecAccess_Write:
  2952. resp.setUserPermission("Write Access Permission");
  2953. break;
  2954. case SecAccess_Read:
  2955. resp.setUserPermission("Read Access Permission");
  2956. break;
  2957. case SecAccess_Access:
  2958. resp.setUserPermission("Access Permission");
  2959. break;
  2960. case SecAccess_None:
  2961. resp.setUserPermission("None Access Permission");
  2962. break;
  2963. default:
  2964. resp.setUserPermission("Permission Unknown");
  2965. break;
  2966. }
  2967. }
  2968. }
  2969. else //for group
  2970. {
  2971. resp.setFileName(fileName);
  2972. resp.setGroupName(groupName);
  2973. if(m_basedns.length() == 0) //basedns may never be set
  2974. {
  2975. setBasedns(context);
  2976. }
  2977. //Find out the basedn for RT_FILE_SCOPE
  2978. CLdapSecManager* ldapsecmgr = (CLdapSecManager*)secmgr;
  2979. StringBuffer basednStr;
  2980. ForEachItemIn(y, m_basedns)
  2981. {
  2982. IEspDnStruct* curbasedn = &(m_basedns.item(y));
  2983. const char *aBasedn = curbasedn->getBasedn();
  2984. const char *aRtype = curbasedn->getRtype();
  2985. if (!aBasedn || !*aBasedn || !aRtype || !*aRtype)
  2986. continue;
  2987. SecResourceType rtype = str2type(aRtype);
  2988. if (rtype != RT_FILE_SCOPE)
  2989. continue;
  2990. basednStr.append(aBasedn);
  2991. }
  2992. char* pStr0 = (char*) fileName;
  2993. while (pStr0[0] == ':') //in case of some ':' by mistake
  2994. pStr0++;
  2995. //Check the permissin for the file and the group
  2996. if (*pStr0 && basednStr.length() > 0)
  2997. {
  2998. StringBuffer lastFileScope;
  2999. StringArray scopes;
  3000. char* pStr = strstr(pStr0, "::");
  3001. while (pStr)
  3002. {
  3003. char fileScope[10240];
  3004. strncpy(fileScope, pStr0, pStr-pStr0);
  3005. fileScope[pStr-pStr0] = 0;
  3006. if (lastFileScope.length() < 1)
  3007. lastFileScope.append(fileScope);
  3008. else
  3009. lastFileScope.appendf("::%s", fileScope);
  3010. scopes.add(lastFileScope.str(), 0);
  3011. pStr0 = pStr+2;
  3012. while (pStr0[0] == ':') //in case of more than two ':' by mistake
  3013. pStr0++;
  3014. if (pStr0[0] == 0)
  3015. break;
  3016. pStr = strstr(pStr0, "::");
  3017. }
  3018. if (pStr0[0] != 0)
  3019. {
  3020. if (lastFileScope.length() < 1)
  3021. lastFileScope.append(pStr0);
  3022. else
  3023. lastFileScope.appendf("::%s", pStr0);
  3024. scopes.add(lastFileScope.str(), 0);
  3025. }
  3026. access = 0;
  3027. ForEachItemIn(y, scopes)
  3028. {
  3029. StringBuffer namebuf = scopes.item(y);
  3030. try
  3031. {
  3032. IArrayOf<CPermission> permissions;
  3033. ldapsecmgr->getPermissionsArray(basednStr.str(), RT_FILE_SCOPE, namebuf.str(), permissions);
  3034. ForEachItemIn(x, permissions)
  3035. {
  3036. CPermission& perm = permissions.item(x);
  3037. int accountType = perm.getAccount_type(); //0-individual, 1 - group
  3038. if (accountType < 1)
  3039. continue;
  3040. const char* actname = perm.getAccount_name();
  3041. if(!actname || strcmp(actname, groupName))
  3042. continue;
  3043. int allows = perm.getAllows();
  3044. int denies = perm.getDenies();
  3045. access = allows & (~denies);
  3046. break;
  3047. }
  3048. }
  3049. catch(IException* e) //exception may be thrown when no permission for the resource
  3050. {
  3051. e->Release();
  3052. }
  3053. if (access != 0)
  3054. break;
  3055. }
  3056. }
  3057. //Convert permission type to display string
  3058. if((access & NewSecAccess_Full) == NewSecAccess_Full)
  3059. resp.setUserPermission("Full Access Permission");
  3060. else if((access & NewSecAccess_Write) == NewSecAccess_Write)
  3061. resp.setUserPermission("Write Access Permission");
  3062. else if((access & NewSecAccess_Read) == NewSecAccess_Read)
  3063. resp.setUserPermission("Read Access Permission");
  3064. else if((access & NewSecAccess_Access) == NewSecAccess_Access)
  3065. resp.setUserPermission("Access Permission");
  3066. else if (access == 0)
  3067. resp.setUserPermission("None Access Permission");
  3068. else
  3069. resp.setUserPermission("Permission Unknown");
  3070. }
  3071. }
  3072. catch(IException* e)
  3073. {
  3074. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  3075. }
  3076. return true;
  3077. }
  3078. bool Cws_accessEx::onUserAccountExport(IEspContext &context, IEspUserAccountExportRequest &req, IEspUserAccountExportResponse &resp)
  3079. {
  3080. try
  3081. {
  3082. CLdapSecManager* secmgr = dynamic_cast<CLdapSecManager*>(context.querySecManager());
  3083. if(secmgr == NULL)
  3084. {
  3085. throw MakeStringException(ECLWATCH_INVALID_SEC_MANAGER, MSG_SEC_MANAGER_IS_NULL);
  3086. }
  3087. CLdapSecManager* ldapsecmgr = (CLdapSecManager*)secmgr;
  3088. checkUser(context);
  3089. StringBuffer xls;
  3090. xls.append("<html xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">");
  3091. xls.append("<head>");
  3092. xls.append("<META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">");
  3093. xls.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">");
  3094. xls.append("<title>User Account Information</title>");
  3095. xls.append("</head>");
  3096. xls.append("<body>");
  3097. xls.append("<table xmlns:msxsl=\"urn:schemas-microsoft-com:xslt\" cellspacing=\"0\" frame=\"box\" rules=\"all\">");
  3098. xls.append("<thead>");
  3099. xls.append("<tr valign=\"bottom\">");
  3100. xls.append("<th>Login Name</th>");
  3101. xls.append("<th>First Name</th>");
  3102. xls.append("<th>Last Name</th>");
  3103. xls.append("<th>Group Name</th>");
  3104. xls.append("</tr>");
  3105. StringArray& usernames = req.getUsernames();
  3106. StringArray& groupnames = req.getGroupnames();
  3107. if (usernames.length() > 0)
  3108. {
  3109. for(unsigned i = 0; i < usernames.length(); i++)
  3110. {
  3111. const char* username = usernames.item(i);
  3112. if (!username || !*username)
  3113. continue;
  3114. Owned<CLdapSecUser> user = (CLdapSecUser*)secmgr->createUser(username);
  3115. secmgr->getUserInfo(*user.get());
  3116. const char* firstname = user->getFirstName();
  3117. const char* lastname = user->getLastName();
  3118. StringArray groupnames1;
  3119. ldapsecmgr->getGroups(username, groupnames1);
  3120. ///groupnames1.append("TestGroup1");
  3121. ///groupnames1.append("TestGroup2");
  3122. if (groupnames1.length() < 1)
  3123. {
  3124. xls.append("<tr>");
  3125. xls.appendf("<td>%s</td>", username);
  3126. if (!firstname || !*firstname)
  3127. xls.append("<td></td>");
  3128. else
  3129. xls.appendf("<td>%s</td>", firstname);
  3130. if (!lastname || !*lastname)
  3131. xls.append("<td></td>");
  3132. else
  3133. xls.appendf("<td>%s</td>", lastname);
  3134. xls.append("<td></td>");
  3135. xls.append("</tr>");
  3136. }
  3137. else
  3138. {
  3139. for(unsigned i = 0; i < groupnames1.length(); i++)
  3140. {
  3141. const char* grpname = groupnames1.item(i);
  3142. if(grpname == NULL || grpname[0] == '\0')
  3143. continue;
  3144. xls.append("<tr>");
  3145. xls.appendf("<td>%s</td>", username);
  3146. if (!firstname || !*firstname)
  3147. xls.append("<td></td>");
  3148. else
  3149. xls.appendf("<td>%s</td>", firstname);
  3150. if (!lastname || !*lastname)
  3151. xls.append("<td></td>");
  3152. else
  3153. xls.appendf("<td>%s</td>", lastname);
  3154. xls.appendf("<td>%s</td>", grpname);
  3155. xls.append("</tr>");
  3156. }
  3157. }
  3158. }
  3159. }
  3160. else if (groupnames.length() > 0)
  3161. {
  3162. for(unsigned i = 0; i < groupnames.length(); i++)
  3163. {
  3164. const char* groupname = groupnames.item(i);
  3165. if (!groupname || !*groupname)
  3166. continue;
  3167. StringArray usernames1;
  3168. ldapsecmgr->getGroupMembers(groupname, usernames1);
  3169. ///usernames1.append("_clo");
  3170. ///usernames1.append("_rkc");
  3171. for(unsigned j = 0; j < usernames1.length(); j++)
  3172. {
  3173. const char* usrname = usernames1.item(j);
  3174. if(usrname == NULL || usrname[0] == '\0')
  3175. continue;
  3176. Owned<CLdapSecUser> user = (CLdapSecUser*)secmgr->createUser(usrname);
  3177. secmgr->getUserInfo(*user.get());
  3178. const char* firstname = user->getFirstName();
  3179. const char* lastname = user->getLastName();
  3180. xls.append("<tr>");
  3181. xls.appendf("<td>%s</td>", usrname);
  3182. if (!firstname || !*firstname)
  3183. xls.append("<td></td>");
  3184. else
  3185. xls.appendf("<td>%s</td>", firstname);
  3186. if (!lastname || !*lastname)
  3187. xls.append("<td></td>");
  3188. else
  3189. xls.appendf("<td>%s</td>", lastname);
  3190. xls.appendf("<td>%s</td>", groupname);
  3191. xls.append("</tr>");
  3192. }
  3193. }
  3194. }
  3195. xls.append("</thead>");
  3196. xls.append("</table>");
  3197. xls.append("</body>");
  3198. xls.append("</html>");
  3199. MemoryBuffer buff;
  3200. buff.setBuffer(xls.length(), (void*)xls.str());
  3201. resp.setResult(buff);
  3202. resp.setResult_mimetype("application/vnd.ms-excel");
  3203. }
  3204. catch(IException* e)
  3205. {
  3206. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  3207. }
  3208. return true;
  3209. }
  3210. int Cws_accessSoapBindingEx::onGetForm(IEspContext &context, CHttpRequest* request, CHttpResponse* response, const char *service, const char *method)
  3211. {
  3212. try
  3213. {
  3214. if(stricmp(method,"SecurityNotEnabled")==0)
  3215. {
  3216. StringBuffer page;
  3217. page.append(
  3218. "<html>"
  3219. "<head>"
  3220. "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />"
  3221. "<link rel=\"stylesheet\" type=\"text/css\" href=\"/esp/files/default.css\"/>"
  3222. "<link rel=\"stylesheet\" type=\"text/css\" href=\"/esp/files/yui/build/fonts/fonts-min.css\" />"
  3223. "<title>Security Not Enabled</title>"
  3224. "</head>"
  3225. "<body>"
  3226. "<p style=\"text-align:centre;\">In order to use this feature, authentication should be enabled.");
  3227. page.append("</p></body>"
  3228. "</html>");
  3229. response->setContent(page.str());
  3230. response->setContentType("text/html");
  3231. response->send();
  3232. return 0;
  3233. }
  3234. else if(stricmp(method,"FirefoxNotSupport")==0)
  3235. {
  3236. StringBuffer page;
  3237. page.append(
  3238. "<html>"
  3239. "<head>"
  3240. "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />"
  3241. "<link rel=\"stylesheet\" type=\"text/css\" href=\"/esp/files/default.css\"/>"
  3242. "<link rel=\"stylesheet\" type=\"text/css\" href=\"/esp/files/yui/build/fonts/fonts-min.css\" />"
  3243. "<title>Firefox Not Support</title>"
  3244. "</head>"
  3245. "<body>"
  3246. "<p style=\"text-align:centre;\">This feature is not supported under Firefox.");
  3247. page.append("</p></body>"
  3248. "</html>");
  3249. response->setContent(page.str());
  3250. response->setContentType("text/html");
  3251. response->send();
  3252. return 0;
  3253. }
  3254. }
  3255. catch(IException* e)
  3256. {
  3257. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  3258. }
  3259. return onGetForm(context, request, response, service, method);
  3260. }