ws_accessService.cpp 128 KB

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