Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

351 lines
10 KiB

  1. #include "main.h"
  2. #include <ndsapi32.h>
  3. #include <nds32.h>
  4. #include <ndsattr.h>
  5. #include <ndssntx.h>
  6. DWORD NWAPICheckSchemaExtension(
  7. PWSTR szServer,
  8. PWSTR szContext,
  9. PWSTR szUser,
  10. PWSTR szPasswd,
  11. BOOL *pfExtended
  12. )
  13. {
  14. DWORD dwStatus = NO_ERROR;
  15. HANDLE hAttrOperationData = NULL;
  16. HANDLE hTree = NULL;
  17. DWORD dwNumEntries = 0L;
  18. DWORD dwInfoType;
  19. LPNDS_ATTR_DEF lpAttrDef = NULL;
  20. DWORD WinError = 0;
  21. BOOL fSchemaExtended = FALSE;
  22. DWORD dwSize;
  23. PWSTR pszUserName = NULL;
  24. PWSTR pszServerName = NULL;
  25. if (!(szServer && pfExtended)) {
  26. ERR(("Invalid parameters.\n"));
  27. WinError = ERROR_INVALID_PARAMETER;
  28. BAIL();
  29. }
  30. dwSize = (wcslen((PWSTR)g_szServerPrefix) + wcslen(szServer) + 1) * sizeof(WCHAR);
  31. pszServerName = (PWSTR)MemAlloc(dwSize);
  32. if (pszServerName== NULL) {
  33. WinError = ERROR_NO_SYSTEM_RESOURCES;
  34. BAIL();
  35. }
  36. wcscpy(pszServerName,(PWSTR)g_szServerPrefix);
  37. wcscat(pszServerName,szServer);
  38. if (szContext) {
  39. dwSize = wcslen(szContext) + wcslen(szUser) + wcslen((PWSTR)g_szDot) + 1;
  40. dwSize *= sizeof(WCHAR);
  41. pszUserName = (PWSTR)MemAlloc(dwSize);
  42. if (pszUserName == NULL) {
  43. WinError = ERROR_NO_SYSTEM_RESOURCES;
  44. BAIL();
  45. }
  46. wcscpy(pszUserName,szUser);
  47. wcscat(pszUserName,g_szDot);
  48. wcscat(pszUserName,szContext);
  49. }
  50. dwStatus = NwNdsOpenObject(pszServerName,
  51. pszUserName,
  52. szPasswd,
  53. &hTree,
  54. NULL,
  55. NULL,
  56. NULL,
  57. NULL,
  58. NULL);
  59. if ( dwStatus ) {
  60. WinError = GetLastError();
  61. ERR(( "Error: NwNdsOpenObject returned dwStatus 0x%.8X\n", dwStatus));
  62. ERR(( "Error: GetLastError returned: 0x%.8X\n\n",WinError));
  63. BAIL();
  64. }
  65. dwStatus = NwNdsCreateBuffer(
  66. NDS_SCHEMA_READ_ATTR_DEF,
  67. &hAttrOperationData
  68. );
  69. if ( dwStatus ) {
  70. WinError = GetLastError();
  71. ERR(( "Error: NwNdsOpenObject returned dwStatus 0x%.8X\n", dwStatus));
  72. ERR(( "Error: GetLastError returned: 0x%.8X\n\n",WinError));
  73. BAIL();
  74. }
  75. dwStatus = NwNdsPutInBuffer(
  76. (PWSTR)g_szAttributeName,
  77. 0,
  78. NULL,
  79. 0,
  80. 0,
  81. hAttrOperationData
  82. );
  83. if ( dwStatus ) {
  84. WinError = GetLastError();
  85. ERR(( "Error: NwNdsOpenObject returned dwStatus 0x%.8X\n", dwStatus));
  86. ERR(( "Error: GetLastError returned: 0x%.8X\n\n",WinError));
  87. BAIL();
  88. }
  89. dwStatus = NwNdsReadAttrDef(
  90. hTree,
  91. NDS_INFO_NAMES_DEFS,
  92. & hAttrOperationData
  93. );
  94. if (dwStatus == NDS_ERR_NO_SUCH_ATTRIBUTE) {
  95. dwStatus = 0;
  96. goto error;
  97. }
  98. else if ( dwStatus ) {
  99. WinError = GetLastError();
  100. ERR(( "Error: NwNdsOpenObject returned dwStatus 0x%.8X\n", dwStatus));
  101. ERR(( "Error: GetLastError returned: 0x%.8X\n\n",WinError));
  102. BAIL();
  103. }
  104. dwStatus = NwNdsGetAttrDefListFromBuffer(
  105. hAttrOperationData,
  106. & dwNumEntries,
  107. & dwInfoType,
  108. (void **)& lpAttrDef
  109. );
  110. if ( dwStatus ) {
  111. WinError = GetLastError();
  112. ERR(( "Error: NwNdsOpenObject returned dwStatus 0x%.8X\n", dwStatus));
  113. ERR(( "Error: GetLastError returned: 0x%.8X\n\n",WinError));
  114. BAIL();
  115. }
  116. if (dwNumEntries == 1 && dwInfoType == 1) {
  117. if (wcscmp(lpAttrDef->szAttributeName,g_szAttributeName) == 0) {
  118. fSchemaExtended = TRUE;
  119. }
  120. DEBUGOUT(("Successfully retrieved information off GSNW/CSNW.\n"));
  121. }
  122. error:
  123. *pfExtended = fSchemaExtended;
  124. if (dwStatus && dwStatus != -1) {
  125. SelectivePrint(MSG_NETWARE_ERROR,dwStatus);
  126. }
  127. if(hTree){
  128. dwStatus = NwNdsCloseObject(hTree);
  129. }
  130. if(hAttrOperationData){
  131. dwStatus = NwNdsFreeBuffer(hAttrOperationData);
  132. }
  133. if (pszUserName)
  134. MemFree(pszUserName);
  135. if (pszServerName)
  136. MemFree(pszServerName);
  137. return WinError;
  138. }
  139. DWORD NWAPIExtendSchema(
  140. PWSTR szServer,
  141. PWSTR szContext,
  142. PWSTR szUser,
  143. PWSTR szPasswd
  144. )
  145. {
  146. DWORD dwSyntaxId;
  147. DWORD dwMinValue = 0;
  148. DWORD dwMaxValue = -1;
  149. ASN1_ID asn1Id;
  150. DWORD dwStatus = NO_ERROR;
  151. HANDLE hTree;
  152. HANDLE hClasses = NULL;
  153. DWORD WinError = NO_ERROR;
  154. DWORD dwSize;
  155. PWSTR pszUserName = NULL;
  156. PWSTR pszServerName = NULL;
  157. if (!(szServer)) {
  158. ERR(("Invalid parameters.\n"));
  159. WinError = ERROR_INVALID_PARAMETER;
  160. BAIL();
  161. }
  162. dwSize = (wcslen((PWSTR)g_szServerPrefix) + wcslen(szServer) + 1) * sizeof(WCHAR);
  163. pszServerName = (PWSTR)MemAlloc(dwSize);
  164. if (pszServerName== NULL) {
  165. WinError = ERROR_NO_SYSTEM_RESOURCES;
  166. BAIL();
  167. }
  168. wcscpy(pszServerName,(PWSTR)g_szServerPrefix);
  169. wcscat(pszServerName,szServer);
  170. if (szContext) {
  171. dwSize = wcslen(szContext) + wcslen(szUser) + wcslen((PWSTR)g_szDot) + 1;
  172. dwSize *= sizeof(WCHAR);
  173. pszUserName = (PWSTR)MemAlloc(dwSize);
  174. if (pszUserName == NULL) {
  175. WinError = ERROR_NO_SYSTEM_RESOURCES;
  176. BAIL();
  177. }
  178. wcscpy(pszUserName,szUser);
  179. wcscat(pszUserName,g_szDot);
  180. wcscat(pszUserName,szContext);
  181. }
  182. asn1Id.length = 32;
  183. memset(asn1Id.data,0,32);
  184. memcpy(asn1Id.data,g_pbASN,g_dwASN);
  185. dwStatus = NwNdsOpenObject(pszServerName,
  186. pszUserName,
  187. szPasswd,
  188. &hTree,
  189. NULL,
  190. NULL,
  191. NULL,
  192. NULL,
  193. NULL );
  194. if (dwStatus) {
  195. WinError = GetLastError();
  196. ERR(( "\nError: NwNdsOpenObject returned dwStatus 0x%.8X\n", dwStatus ));
  197. ERR(( "Error: GetLastError returned: 0x%.8X\n\n",WinError));
  198. BAIL();
  199. }
  200. dwStatus = NwNdsDefineAttribute(hTree,
  201. (PWSTR)g_szAttributeName,
  202. NDS_SINGLE_VALUED_ATTR,
  203. NDS_SYNTAX_ID_9,
  204. dwMinValue,
  205. dwMaxValue,
  206. asn1Id );
  207. if ( dwStatus ) {
  208. if (dwStatus == NDS_ERR_ATTRIBUTE_ALREADY_EXISTS) {
  209. DEBUGOUT(("The attribute exists already!\n"));
  210. dwStatus = 0;
  211. WinError = 1;
  212. BAIL();
  213. }
  214. WinError = GetLastError();
  215. ERR(( "\nError: NwNdsDefineAttribute returned dwStatus 0x%.8X\n", dwStatus ));
  216. ERR(( "Error: GetLastError returned: 0x%.8X\n\n",WinError));
  217. BAIL();
  218. }
  219. dwStatus = NwNdsAddAttributeToClass(hTree,
  220. (PWSTR)g_szClass,
  221. (PWSTR)g_szAttributeName);
  222. if ( dwStatus ) {
  223. WinError = GetLastError();
  224. ERR(( "\nError: NwNdsAddAttributeToClass returned dwStatus 0x%.8X\n", dwStatus ));
  225. ERR(( "Error: GetLastError returned: 0x%.8X\n\n",WinError));
  226. BAIL();
  227. }
  228. error:
  229. if(hTree)
  230. dwStatus = NwNdsCloseObject(hTree);
  231. if (pszUserName)
  232. MemFree(pszUserName);
  233. if (pszServerName)
  234. MemFree(pszServerName);
  235. if (dwStatus && dwStatus != -1) {
  236. SelectivePrint(MSG_NETWARE_ERROR,dwStatus);
  237. }
  238. return WinError;
  239. }
  240. DWORD NWAPIUnextendSchema(
  241. PWSTR szServer,
  242. PWSTR szContext,
  243. PWSTR szUser,
  244. PWSTR szPasswd
  245. )
  246. {
  247. DWORD dwStatus = NO_ERROR;
  248. HANDLE hTree = NULL;
  249. DWORD dwSize;
  250. PWSTR pszUserName = NULL;
  251. PWSTR pszServerName = NULL;
  252. DWORD WinError = NO_ERROR;
  253. if (!(szServer && szContext && szUser && szPasswd)) {
  254. ERR(("Invalid parameters.\n"));
  255. WinError = ERROR_INVALID_PARAMETER;
  256. BAIL();
  257. }
  258. dwSize = wcslen(szContext) + wcslen(szUser) + wcslen((PWSTR)g_szDot) + 1;
  259. dwSize *= sizeof(WCHAR);
  260. pszUserName = (PWSTR)MemAlloc(dwSize);
  261. if (pszUserName == NULL) {
  262. WinError = ERROR_NO_SYSTEM_RESOURCES;
  263. BAIL();
  264. }
  265. wcscpy(pszUserName,szUser);
  266. wcscat(pszUserName,g_szDot);
  267. wcscat(pszUserName,szContext);
  268. dwSize = (wcslen((PWSTR)g_szServerPrefix) + wcslen(szServer) + 1) * sizeof(WCHAR);
  269. pszServerName = (PWSTR)MemAlloc(dwSize);
  270. if (pszServerName== NULL) {
  271. WinError = ERROR_NO_SYSTEM_RESOURCES;
  272. BAIL();
  273. }
  274. wcscpy(pszServerName,(PWSTR)g_szServerPrefix);
  275. wcscat(pszServerName,szServer);
  276. dwStatus = NwNdsOpenObject( pszServerName,
  277. pszUserName,
  278. szPasswd,
  279. &hTree,
  280. NULL,
  281. NULL,
  282. NULL,
  283. NULL,
  284. NULL );
  285. if (dwStatus) {
  286. WinError = GetLastError();
  287. ERR(( "\nError: NwNdsOpenObject returned dwStatus 0x%.8X\n", dwStatus ));
  288. ERR(( "Error: GetLastError returned: 0x%.8X\n\n",WinError));
  289. BAIL();
  290. }
  291. dwStatus = NwNdsDeleteAttrDef( hTree,
  292. (PWSTR)g_szAttributeName );
  293. if (dwStatus) {
  294. WinError = GetLastError();
  295. ERR(( "\nError: NwNdsDeleteAttrDef returned dwStatus 0x%.8X\n", dwStatus ));
  296. ERR(( "Error: GetLastError returned: 0x%.8X\n\n",WinError));
  297. BAIL();
  298. }
  299. error:
  300. if(hTree)
  301. dwStatus = NwNdsCloseObject(hTree);
  302. if (pszUserName)
  303. MemFree(pszUserName);
  304. if (pszServerName)
  305. MemFree(pszServerName);
  306. return WinError;
  307. }