summaryrefslogtreecommitdiff
path: root/network/trans/WFPSampler/lib/HelperFunctions_FwpmEngine.cpp
blob: 4ea15a8a8fb26b60c247a182fbfe0ae88d3052cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
////////////////////////////////////////////////////////////////////////////////////////////////////
//
//   Copyright (c) 2012 Microsoft Corporation.  All Rights Reserved.
//
//   Module Name:
//      HelperFunctions_FwpmEngine.cpp
//
//   Abstract:
//      This module contains functions which assist in actions pertaining to BFE engine objects.
//
//   Naming Convention:
//
//      <Scope><Module><Object><Action><Modifier>
//  
//      i.e.
//
//       <Scope>
//          {
//                       - Function is likely visible to other modules.
//          }
//       <Module>
//          {
//            Hlpr       - Function is from HelperFunctions_* Modules.
//          }
//       <Object>
//          {
//            FwpmEngine - Function pertains to BFE engine objects.
//          }
//       <Action>
//          {
//            Close      - Function destroys a handle.
//            Open       - Function creates a handle.
//          }
//       <Modifier>
//          {
//          }
//
//   Private Functions:
//
//   Public Functions:
//      HlprFwpmEngineClose(),
//      HlprFwpmEngineOpen()
//
//   Author:
//      Dusty Harper      (DHarper)
//
//   Revision History:
//
//      [ Month ][Day] [Year] - [Revision]-[ Comments ]
//      May       01,   2010  -     1.0   -  Creation
//
////////////////////////////////////////////////////////////////////////////////////////////////////

#include "HelperFunctions_Include.h" /// .

/**
 @helper_function="HlprFwpmEngineOpen"
 
   Purpose:  Wrapper for the FwpmEngineClose API.                                               <br>
                                                                                                <br>
   Notes:                                                                                       <br>
                                                                                                <br>
   MSDN_Ref: HTTP://MSDN.Microsoft.com/En-US/Library/AA364034.aspx                              <br>
*/
_When_(return == NO_ERROR, _At_(*pEngineHandle, _Post_ _Null_))
_Success_(return == NO_ERROR)
UINT32 HlprFwpmEngineClose(_Inout_ HANDLE* pEngineHandle)
{
   ASSERT(pEngineHandle);

   UINT32 status = NO_ERROR;

   if(*pEngineHandle)
   {
      status = FwpmEngineClose(*pEngineHandle);
      if(status != NO_ERROR)
      {
         HlprLogError(L"HlprFwpmEngineClose : FwpmEngineClose() [status: %#x]",
                      status);

         HLPR_BAIL;
      }

      *pEngineHandle = 0;
   }

   HLPR_BAIL_LABEL:

   return status;
}

/**
 @helper_function="HlprFwpmEngineOpen"
 
   Purpose:  Wrapper for the FwpmEngineOpen API.                                                <br>
                                                                                                <br>
   Notes:                                                                                       <br>
                                                                                                <br>
   MSDN_Ref: HTTP://MSDN.Microsoft.com/En-US/Library/AA364040.aspx                              <br>
*/
_At_(*pEngineHandle, _Pre_ _Null_)
_When_(return != NO_ERROR, _At_(*pEngineHandle, _Post_ _Null_))
_When_(return == NO_ERROR, _At_(*pEngineHandle, _Post_ _Notnull_))
_Success_(return == NO_ERROR)
UINT32 HlprFwpmEngineOpen(_Out_ HANDLE* pEngineHandle,
                          _In_ const UINT32 sessionFlags) /* FWPM_SESSION_FLAG_NONDYNAMIC */
{
   ASSERT(pEngineHandle);

   UINT32       status  = NO_ERROR;
   FWPM_SESSION session = {0};

   session.displayData.name = L"WFPSampler's User Mode Session";
   session.flags            = sessionFlags;

   status = FwpmEngineOpen(0,
                           RPC_C_AUTHN_WINNT,
                           0,
                           &session,
                           pEngineHandle);
   if(status != NO_ERROR)
      HlprLogError(L"HlprFwpmEngineOpen : FwpmEngineOpen() [status: %#x]",
                   status);

   return status;
}