EmergencyAdmin.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. EmAdmin 1.0
  3. This NLM can be used in case of NDS admin loss or to
  4. recover access to an hidden OrgUnit.
  5. Run it on an Netware server holding a master or R/W replica
  6. of the [Root] partition (or other target OrgUnit you want
  7. unlock access to)
  8. If the user specified does not exist, it will be created
  9. with no password. The user will be given [SI] rights to
  10. the target OrgUnit.
  11. This source code has been made public to prevent you from using
  12. an unknown/untrusted NLM (and to pay $$ for less than 20 Netware
  13. lib C calls !)
  14. It will compile under Metrowerks CodeWarrior (+Netware SDK).
  15. Use it at your own risk. I cannot be held responsible for anything
  16. bad that could appening.
  17. Use it with hobjloc.nlm to find and unlock stealth/hidden OrgUnit.
  18. (see http://www.novell.com/coolsolutions/freetools.html).
  19. This is freeware GPL (see http://www.gnu.org/copyleft/gpl.html)
  20. CopyLeft - Jean-Francois.Burdet@adm.unige.ch - july 2000
  21. */
  22. #include <stdlib.h>
  23. #include <stdio.h>
  24. #include <nwdsapi.h>
  25. NWDSContextHandle context;
  26. NWDSCCODE ccode;
  27. nstr8 userName[256];
  28. nstr8 targetOu[256];
  29. Object_ACL_T ACLRec;
  30. Buf_T *dsBuf = NULL;
  31. void releaseRessources() {
  32. printf("Freeing ressources. \n");
  33. NWDSFreeBuf(dsBuf);
  34. NWDSLogout(context);
  35. NWDSFreeContext(context);
  36. }
  37. void chkErr(NWDSCCODE c, pnstr err) {
  38. if (c) {
  39. printf("Error %s, ccode = %d\n", err, c);
  40. releaseRessources();
  41. printf("exiting !\n");
  42. exit(-1);
  43. }
  44. }
  45. void main(int argc, char *argv[]) {
  46. printf("EmAdmin 1.0\n");
  47. printf("NDS Emergency Admin User creation.\n");
  48. printf("Run this nlm on a [Root] (or other target OrgUnit\n");
  49. printf("you want unlock access to) master/rw replica holding server\n");
  50. printf("** Use it at your own risk **\n");
  51. printf("Freeware GPL - jean-francois.burdet@adm.unige.ch - july 2000 \n\n");
  52. printf("Enter a user name \n(enter 'stop' to quit) \n(Example : .newadmin.org) : \n=>");
  53. scanf("%s",userName);
  54. if ((strcmp("stop", userName)==0) || (strcmp("", userName))==0) {
  55. printf("Exiting on user request ... \n");
  56. exit(0);
  57. }
  58. printf("Enter a target OrgUnit\n(enter 'stop' to quit) \n(Example : [Root]) : \n(Example : .MyOrg)\n=>");
  59. scanf("%s",targetOu);
  60. if ((strcmp("stop", targetOu)==0) || (strcmp("", targetOu))==0) {
  61. printf("Exiting on user request ... \n");
  62. exit(0);
  63. }
  64. printf("Now trying to create %s with [SI] rigths to %s\n", userName, targetOu);
  65. printf("Init access to NDS ... ");
  66. chkErr(NWDSCreateContextHandle(&context),"NWDSCreateContext");
  67. chkErr(NWDSLoginAsServer(context), "NWDSLoginAsServer");
  68. chkErr(NWDSSetContext(context, DCK_NAME_CONTEXT, "[Root]"), "NWDSSetContext");
  69. chkErr(NWDSAllocBuf (DEFAULT_MESSAGE_LEN, &dsBuf), "NWDSAllocBuf");
  70. chkErr(NWDSInitBuf (context, DSV_ADD_ENTRY, dsBuf), "NWDSInitBuf");
  71. chkErr(NWDSPutAttrName (context, dsBuf, "Object Class"),"NWDSPutAttrName ""Object Class""");
  72. chkErr(NWDSPutAttrVal(context,dsBuf,SYN_CLASS_NAME,"User"),"NWDSPutAttrVal ""Object Class""");
  73. chkErr(NWDSPutAttrName (context, dsBuf, "Surname"),"NWDSPutAttrName ""Surname""");
  74. chkErr(NWDSPutAttrVal(context,dsBuf,SYN_CI_STRING,"Emergency Admin"),"NWDSPutAttrVal ""Emergency Admin""");
  75. printf("ok. \n");
  76. printf("Creating user object ... ");
  77. ccode = NWDSAddObject (context, userName, NULL, 0, dsBuf);
  78. if (ccode == -606) {
  79. printf("\n -> User already exists : assigning trustee anyway ... \n");
  80. } else {
  81. chkErr(ccode , "NWDSAddObject"); printf("ok. \n");
  82. printf("Assigning empty password ... ");
  83. chkErr(NWDSGenerateObjectKeyPair(context,userName,"",0), "NWDSGenerateObjectKeyPair");
  84. printf("ok.\n");
  85. }
  86. NWDSFreeBuf(dsBuf);
  87. printf("Assigning trustee to %s ... ", targetOu);
  88. chkErr( NWDSAllocBuf(DEFAULT_MESSAGE_LEN, &dsBuf), "NWDSAllocBuf");
  89. chkErr( NWDSInitBuf(context, DSV_MODIFY_ENTRY, dsBuf), "NWDSInitBuf");
  90. chkErr( NWDSPutChange(context,dsBuf,DS_ADD_VALUE,"ACL"), "NWDSPutChange");
  91. ACLRec.protectedAttrName = "[Entry Rights]";
  92. ACLRec.subjectName = userName;
  93. ACLRec.privileges = DS_ENTRY_SUPERVISOR & (~DS_ENTRY_INHERIT_CTL);
  94. chkErr( NWDSPutAttrVal(context,dsBuf,SYN_OBJECT_ACL,(void *)&ACLRec), "NWDSPutAttVal");
  95. ccode = NWDSModifyObject(context,targetOu, NULL, 0, dsBuf);
  96. if (ccode == -614) {
  97. printf("\n -> Trustee assignment already exist\n");
  98. } else {
  99. chkErr(ccode , "NWDSModifyObject");
  100. printf("ok. \n");
  101. printf("=> full success.\n");
  102. }
  103. releaseRessources();
  104. printf("Exiting.\n");
  105. exit(0);
  106. }