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.

349 lines
7.5 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. Abstract:
  5. This module provides error logging routines needed for the entire
  6. WINS. See header file winsevt.h for the
  7. macros which use the functions in this module.
  8. Functions:
  9. Portability:
  10. The current implementation of the module is not portable.
  11. Author:
  12. Pradeep Bahl (PradeepB) Dec-1992
  13. Revision History:
  14. Modification date Person Description of modification
  15. ----------------- ------- ----------------------------
  16. --*/
  17. #include <stdio.h>
  18. #include <stdarg.h>
  19. #include <time.h>
  20. #include "wins.h"
  21. #ifdef DBGSVC
  22. #include "nms.h"
  23. #endif
  24. #include "winsevt.h"
  25. #include "winscnf.h"
  26. #include "winsmsc.h"
  27. /*
  28. * Local Macro Declarations
  29. */
  30. #if 0
  31. /*
  32. * get_month_m:
  33. *
  34. * This macro converts a numerical month (0-11) to a month string
  35. * abbreviation.
  36. *
  37. * NOTE: This macro must *NOT* be called with an expression as an argument.
  38. * If this is done, then you will get the expression
  39. * evaluated 11 times
  40. * (probably not desired).
  41. */
  42. #define get_month_m(month_int) \
  43. (((month_int) == 0) ? "JAN" : \
  44. ((month_int) == 1) ? "FEB" : \
  45. ((month_int) == 2) ? "MAR" : \
  46. ((month_int) == 3) ? "APR" : \
  47. ((month_int) == 4) ? "MAY" : \
  48. ((month_int) == 5) ? "JUN" : \
  49. ((month_int) == 6) ? "JUL" : \
  50. ((month_int) == 7) ? "AUG" : \
  51. ((month_int) == 8) ? "SEP" : \
  52. ((month_int) == 9) ? "OCT" : \
  53. ((month_int) == 10) ? "NOV" : "DEC" \
  54. )
  55. #endif
  56. /*
  57. * Local Typedef Declarations
  58. */
  59. /*
  60. * Global Variable Definitions
  61. */
  62. /*
  63. * Local Variable Definitions
  64. */
  65. /*
  66. * Local Function Prototype Declarations
  67. */
  68. /* prototypes for functions local to this module go here */
  69. /*
  70. * Function Name:
  71. * extern WinsEvtLogEvt
  72. *
  73. * Function Description:
  74. * This is funtion that logs all errors from the WINS process. It should
  75. * only be "called" using the WINSEVT_ macros, except within
  76. * this module.
  77. *
  78. * Arguments:
  79. * IN StatusCode - integer containing the status code of the
  80. * error to be printed.
  81. *
  82. * Return value:
  83. * None.
  84. *
  85. * Error Handling:
  86. * None.
  87. *
  88. * Extern Variables used:
  89. * None.
  90. *
  91. * Side Effects:
  92. * None.
  93. *
  94. * Comments:
  95. * Make sure that printf is thread-renetrant.
  96. *
  97. */
  98. VOID
  99. WinsEvtLogEvt
  100. (
  101. LONG BinaryData,
  102. WORD EvtTyp,
  103. DWORD EvtId,
  104. LPTSTR pFileStr,
  105. DWORD LineNumber,
  106. PWINSEVT_STRS_T pStr
  107. )
  108. {
  109. BOOL fRet = TRUE;
  110. DWORD Error;
  111. DWORD NoOfBytes;
  112. WORD BinData[4];
  113. BinData[0] = (WORD)(LineNumber & 0xFFFF);
  114. BinData[1] = (WORD)(LineNumber >> 16);
  115. BinData[2] = (WORD)(BinaryData & 0xFFFF); //lower word first
  116. BinData[3] = (WORD)(BinaryData >> 16); //then higher word
  117. try {
  118. NoOfBytes = sizeof(BinData);
  119. fRet = ReportEvent(
  120. WinsCnf.LogHdl,
  121. (WORD)EvtTyp,
  122. (WORD)0, //category zero
  123. EvtId,
  124. NULL, //no user SID
  125. (WORD)(pStr != NULL ? pStr->NoOfStrs : 0),//no of strings
  126. NoOfBytes, //no of bytes in binary data
  127. pStr != NULL ? (LPCTSTR *)(pStr->pStr) : (LPCTSTR *)NULL,//address of string arr
  128. BinData //address of data
  129. );
  130. if (!fRet)
  131. {
  132. Error = GetLastError();
  133. DBGPRINT1(
  134. ERR,
  135. "WinsEvtLogEvt: ReportEvent returned error = (%d)",
  136. Error
  137. );
  138. }
  139. }
  140. except(EXCEPTION_EXECUTE_HANDLER) {
  141. DBGPRINT1(EXC, "WinsEvtLogEvt: Report Event generated the exception (%x). Check if you have the right access. You should have power user access on this machine\n", GetExceptionCode());
  142. }
  143. return;
  144. }
  145. VOID
  146. WinsEvtLogDetEvt(
  147. BOOL fInfo,
  148. DWORD EvtId,
  149. LPTSTR pFileName,
  150. DWORD LineNumber,
  151. LPSTR pFormat,
  152. ...
  153. )
  154. {
  155. LPBYTE pFmt = pFormat;
  156. DWORD NoOfStr = 0;
  157. DWORD NoOfW = 0;
  158. DWORD Data[30];
  159. LPWSTR ppwStr[10];
  160. WCHAR wStr[10][80];
  161. BOOL fRet = TRUE;
  162. DWORD Error;
  163. DWORD ArrIndex = 0;
  164. va_list ap;
  165. if (!WinsCnf.LogDetailedEvts)
  166. return;
  167. DBGENTER("WinsEvtLogDetEvt\n");
  168. try {
  169. va_start(ap, pFormat);
  170. Data[NoOfW++] = LineNumber;
  171. if (pFileName != (LPTSTR)NULL)
  172. {
  173. ppwStr[NoOfStr++] = pFileName;
  174. }
  175. for (; *pFmt; pFmt++)
  176. {
  177. switch(*pFmt)
  178. {
  179. case('d'):
  180. Data[NoOfW++] = (DWORD)va_arg(ap, long);
  181. break;
  182. case('s'):
  183. WinsMscConvertAsciiStringToUnicode(
  184. va_arg(ap, char *),
  185. (LPBYTE)wStr[ArrIndex], 80);
  186. ppwStr[NoOfStr++] = wStr[ArrIndex++];
  187. break;
  188. case('u'):
  189. ppwStr[NoOfStr++] = va_arg(ap, short *);
  190. break;
  191. default:
  192. break;
  193. }
  194. }
  195. ppwStr[NoOfStr] = (LPWSTR)NULL;
  196. fRet = ReportEvent(
  197. WinsCnf.LogHdl,
  198. (WORD)(fInfo ? EVENTLOG_INFORMATION_TYPE : EVENTLOG_ERROR_TYPE),
  199. (WORD)0, //category zero
  200. EvtId,
  201. NULL, //no user SID
  202. (WORD)NoOfStr, //no of strings
  203. NoOfW * sizeof(DWORD), //no of bytes in binary data
  204. NoOfStr != 0 ? (LPCTSTR *)ppwStr : (LPCTSTR *)NULL,//address of string arr
  205. Data //address of data
  206. );
  207. if (!fRet)
  208. {
  209. Error = GetLastError();
  210. DBGPRINT1(
  211. ERR,
  212. "WinsEvtLogDetEvt: ReportEvent returned error = (%d)",
  213. Error
  214. );
  215. }
  216. va_end(ap);
  217. } // end of try
  218. except(EXCEPTION_EXECUTE_HANDLER) {
  219. DBGPRINT1(EXC, "WinsLogDetEvt: Report Event generated the exception (%x). Check if you have the right access. You should have power user access on this machine\n", GetExceptionCode());
  220. }
  221. DBGLEAVE("WinsEvtLogDetEvt\n");
  222. return;
  223. }
  224. VOID
  225. WinsLogAdminEvent(
  226. IN DWORD EventId,
  227. IN DWORD StrArgs,
  228. IN ...
  229. )
  230. /*++
  231. Routine Description:
  232. This routine is called to log admin triggerd events.
  233. Arguments:
  234. EventId - The id of the event to be logged.
  235. StrArgs - No of additional args.
  236. Return Value:
  237. None
  238. Comments:
  239. This routine must be called fromt he RPC API processing code only.
  240. None
  241. --*/
  242. {
  243. RPC_STATUS RpcStatus;
  244. TCHAR UserNameBuf[MAX_PATH+1];
  245. DWORD Size;
  246. WINSEVT_STRS_T EvtStr;
  247. va_list ap;
  248. DWORD i;
  249. // first impersonate the client.
  250. RpcStatus = RpcImpersonateClient( NULL );
  251. if (RPC_S_OK != RpcStatus) {
  252. DBGPRINT1(ERR, "WinsLogAdminEvent: Could not impersonate client (Error = %ld)\n", RpcStatus);
  253. return;
  254. }
  255. if (!GetUserName(UserNameBuf,&Size)) {
  256. DBGPRINT1(ERR, "WinsLogAdminEvent: Could not get user name (Error = %ld)\n", GetLastError());
  257. goto Cleanup;
  258. }
  259. EvtStr.NoOfStrs = 1;
  260. EvtStr.pStr[0] = UserNameBuf;
  261. ASSERT( StrArgs < MAX_NO_STRINGS );
  262. va_start(ap,StrArgs);
  263. for(i=1;i<= StrArgs && i<= MAX_NO_STRINGS; i++) {
  264. EvtStr.pStr[i] = va_arg(ap, LPTSTR);
  265. EvtStr.NoOfStrs++;
  266. }
  267. va_end(ap);
  268. WINSEVT_LOG_INFO_STR_M(EventId, &EvtStr);
  269. Cleanup:
  270. RpcStatus = RpcRevertToSelf();
  271. if (RPC_S_OK != RpcStatus) {
  272. ASSERT( FALSE );
  273. }
  274. return;
  275. }
  276.