Leaked source code of windows server 2003
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.

238 lines
6.5 KiB

  1. #include "item.h"
  2. #include <stdio.h>
  3. BOOL DataToString(LPBYTE pb, DWORD cb, LPSTR *szData)
  4. {
  5. LPSTR szTmp = NULL;
  6. CHAR szNum[5];
  7. szTmp = (LPSTR) malloc(cb*2 + 1);
  8. if (szTmp != NULL) {
  9. szTmp[0] = '\0';
  10. for (;cb > 0;cb -= 1, pb += 1) {
  11. sprintf(szNum,"%02hX", *pb);
  12. strcat(szTmp, szNum);
  13. }
  14. }
  15. *szData = szTmp;
  16. return TRUE;
  17. }
  18. BOOL StringToData(LPSTR szData, LPBYTE *pb, DWORD *cb)
  19. {
  20. LPBYTE pbData = NULL;
  21. LPBYTE pbTemp = NULL;
  22. DWORD cbData = 0;
  23. CHAR szNum[5];
  24. *cb = 0;
  25. if ((szData != NULL) && (strlen(szData) > 0)) {
  26. cbData = strlen(szData)/2;
  27. AssertSz(((strlen(szData) % 2) == 0), "Not in even bytes. ignoring last character");
  28. pbData = (LPBYTE) malloc(cbData + 3);
  29. if (pbData != NULL) {
  30. pbTemp = pbData;
  31. for (;strlen(szData) > 1;szData += 2, pbTemp += 1) {
  32. sscanf(szData,"%2X", pbTemp);
  33. }
  34. *cb = cbData;
  35. }
  36. }
  37. *pb = pbData;
  38. return TRUE;
  39. }
  40. BOOL AuthAttribCreateDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  41. {
  42. DWORD cb;
  43. LPBYTE pb;
  44. LPSTR szOID;
  45. LPSTR szASN;
  46. static CSignData * psd = NULL;
  47. CHAR rgchOID[256];
  48. switch (message) {
  49. case WM_INITDIALOG:
  50. psd = (CSignData *) lParam;
  51. szOID = psd->GetAuthAttribOID();
  52. if (szOID != NULL) {
  53. SetDlgItemText(hwnd, IDC_BA_OID, szOID);
  54. psd->GetAuthAttribData(&pb, &cb);
  55. if ((cb > 0) && (pb != NULL)) {
  56. DataToString(pb,cb,&szASN);
  57. if (szASN != NULL) {
  58. SetDlgItemText(hwnd, IDC_BA_ASN, szASN);
  59. free(szASN);
  60. }
  61. }
  62. }
  63. break;
  64. case WM_COMMAND:
  65. switch(wParam) {
  66. case IDOK:
  67. GetDlgItemText(hwnd, IDC_BA_OID,
  68. rgchOID, sizeof(rgchOID));
  69. if (rgchOID[0] != '\0') {
  70. psd->SetAuthAttribOID(rgchOID);
  71. }
  72. else {
  73. psd->SetAuthAttribOID(NULL);
  74. }
  75. cb = SendDlgItemMessage(hwnd, IDC_BA_ASN, WM_GETTEXTLENGTH,0,0);
  76. szASN = (LPSTR) malloc(cb+1);
  77. if (szASN != NULL) {
  78. GetDlgItemText(hwnd, IDC_BA_ASN, szASN, cb+1);
  79. StringToData(szASN, &pb, &cb);
  80. psd->SetAuthAttribData(pb, cb);
  81. }
  82. //
  83. case IDCANCEL:
  84. EndDialog(hwnd, wParam);
  85. break;
  86. default:
  87. return FALSE;
  88. }
  89. break;
  90. default:
  91. return FALSE;
  92. }
  93. return TRUE;
  94. }
  95. BOOL UnAuthAttribCreateDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  96. {
  97. DWORD cb;
  98. LPBYTE pb;
  99. LPSTR szOID;
  100. LPSTR szASN;
  101. static CSignData * psd = NULL;
  102. CHAR rgchOID[256];
  103. switch (message) {
  104. case WM_INITDIALOG:
  105. psd = (CSignData *) lParam;
  106. szOID = psd->GetUnAuthAttribOID();
  107. if (szOID != NULL) {
  108. SetDlgItemText(hwnd, IDC_BA_OID, szOID);
  109. psd->GetUnAuthAttribData(&pb, &cb);
  110. if ((cb > 0) && (pb != NULL)) {
  111. DataToString(pb,cb,&szASN);
  112. if (szASN != NULL) {
  113. SetDlgItemText(hwnd, IDC_BA_ASN, szASN);
  114. free(szASN);
  115. }
  116. }
  117. }
  118. break;
  119. case WM_COMMAND:
  120. switch(wParam) {
  121. case IDOK:
  122. GetDlgItemText(hwnd, IDC_BA_OID,
  123. rgchOID, sizeof(rgchOID));
  124. if (rgchOID[0] != '\0') {
  125. psd->SetUnAuthAttribOID(rgchOID);
  126. }
  127. else {
  128. psd->SetUnAuthAttribOID(NULL);
  129. }
  130. cb = SendDlgItemMessage(hwnd, IDC_BA_ASN, WM_GETTEXTLENGTH,0,0);
  131. szASN = (LPSTR) malloc(cb+1);
  132. if (szASN != NULL) {
  133. GetDlgItemText(hwnd, IDC_BA_ASN, szASN, cb+1);
  134. StringToData(szASN, &pb, &cb);
  135. psd->SetUnAuthAttribData(pb, cb);
  136. }
  137. //
  138. case IDCANCEL:
  139. EndDialog(hwnd, wParam);
  140. break;
  141. default:
  142. return FALSE;
  143. }
  144. break;
  145. default:
  146. return FALSE;
  147. }
  148. return TRUE;
  149. }
  150. BOOL UnProtAttribCreateDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  151. {
  152. DWORD cb;
  153. LPBYTE pb;
  154. LPSTR szOID;
  155. LPSTR szASN;
  156. static CEnvData * ped = NULL;
  157. CHAR rgchOID[256];
  158. switch (message) {
  159. case WM_INITDIALOG:
  160. ped = (CEnvData *) lParam;
  161. szOID = ped->GetUnProtAttribOID();
  162. if (szOID != NULL) {
  163. SetDlgItemText(hwnd, IDC_BA_OID, szOID);
  164. ped->GetUnProtAttribData(&pb, &cb);
  165. if ((cb > 0) && (pb != NULL)) {
  166. DataToString(pb,cb,&szASN);
  167. if (szASN != NULL) {
  168. SetDlgItemText(hwnd, IDC_BA_ASN, szASN);
  169. free(szASN);
  170. }
  171. }
  172. }
  173. break;
  174. case WM_COMMAND:
  175. switch(wParam) {
  176. case IDOK:
  177. GetDlgItemText(hwnd, IDC_BA_OID,
  178. rgchOID, sizeof(rgchOID));
  179. if (rgchOID[0] != '\0') {
  180. ped->SetUnProtAttribOID(rgchOID);
  181. }
  182. else {
  183. ped->SetUnProtAttribOID(NULL);
  184. }
  185. cb = SendDlgItemMessage(hwnd, IDC_BA_ASN, WM_GETTEXTLENGTH,0,0);
  186. szASN = (LPSTR) malloc(cb+1);
  187. if (szASN != NULL) {
  188. GetDlgItemText(hwnd, IDC_BA_ASN, szASN, cb+1);
  189. StringToData(szASN, &pb, &cb);
  190. ped->SetUnProtAttribData(pb, cb);
  191. }
  192. //
  193. case IDCANCEL:
  194. EndDialog(hwnd, wParam);
  195. break;
  196. default:
  197. return FALSE;
  198. }
  199. break;
  200. default:
  201. return FALSE;
  202. }
  203. return TRUE;
  204. }