<div class="content" name="R_DhcpV4SetPolicy" uuid="c5ca9a61-44c6-4214-9b3c-170f08895fcc"><p>The <b>R_DhcpV4SetPolicy</b> method modifies the specified
DHCPv4 policy.</p><dl>
<dd>
<div><pre> DWORD R_DhcpV4SetPolicy(
   [in, unique, string] DHCP_SRV_HANDLE ServerIpAddress,
   [in] DWORD FieldsModified,
   [in] BOOL ServerPolicy,
   [in] DHCP_IP_ADDRESS SubnetAddress,
   [in, unique, string] LPWSTR PolicyName,
   [in] LPDHCP_POLICY Policy
 );
</pre></div>
</dd></dl><p><b>ServerIpAddress: </b>The IP address/host name of
the DHCP server. This parameter is unused.</p><p><b>FieldsModified: </b>This is of type <a href="../ms-dtyp/262627d8-3418-4627-9218-4ffe110850b2" data-linktype="relative-path">DWORD</a>
and contains the bit mask that specifies the fields to be modified as specified
in the <b>DHCP_POLICY_FIELDS_TO_UPDATE</b> enumeration (section <a href="49abe631-1c6b-4711-8337-b4b2bdf90b00" data-linktype="relative-path">2.2.1.1.21</a>).</p><p><b>ServerPolicy: </b>This is of type <a href="../ms-dtyp/9d81be47-232e-42cf-8f0d-7a3b29bf2eb2" data-linktype="relative-path">BOOL</a> and
specifies whether the server <a href="a9d6a415-4de6-4058-befe-ca2e42764485#gt_52323544-69e0-4172-8921-2711cbda988e" data-linktype="relative-path">policy</a>
or <a href="a9d6a415-4de6-4058-befe-ca2e42764485#gt_128cd76b-eecb-41e6-96f7-f73c2bf9235a" data-linktype="relative-path">scope</a> policy is being
modified.</p><p><b>SubnetAddress: </b>This is of type <b>DHCP_IP_ADDRESS</b>
data type (section <a href="5122557b-b85d-4982-8ffb-98d8d934e353" data-linktype="relative-path">2.2.1.2.1</a>)
and identifies the IPv4 subnet from which the policy is being modified.</p><p><b>PolicyName: </b>A pointer to a null-terminated
Unicode string that contains the name of the policy requested.</p><p><b>Policy: </b>This is a pointer to a type
DHCP_POLICY structure (section <a href="77e79969-cedf-4aa9-9059-6223ba815f30" data-linktype="relative-path">2.2.1.2.110</a>) that contains
the policy data to be modified.</p><p><b>Return Values: </b>A 32-bit unsigned integer value
that indicates return status. A return value of ERROR_SUCCESS (0x00000000)
indicates that the operation was completed successfully. Otherwise, it contains
a Win32 error code, as specified in <a href="../ms-erref/1bc92ddf-b79e-413c-bbaa-99a5281a6c90" data-linktype="relative-path">[MS-ERREF]</a>.
This error code value can correspond to a DHCP-specific failure, which takes a
value between 20000 and 20099, or to any generic failure.</p><dl>
<dd>
<table><thead>
  <tr>
   <th>
   <p>Return value/code</p>
   </th>
   <th>
   <p>Description</p>
   </th>
  </tr>
 </thead><tbody><tr>
  <td>0x00000000 ERROR_SUCCESS</td>
  <td>The call was successful.</td>
 </tr><tr>
  <td>0x00004E25 ERROR_DHCP_SUBNET_NOT_PRESENT</td>
  <td>The specified IPv4 subnet does not exist.</td>
 </tr><tr>
  <td>0x00004E8C ERROR_DHCP_RANGE_INVALID_IN_SERVER_POLICY</td>
  <td>A policy range has been specified for a server level policy.</td>
 </tr><tr>
  <td>0x00004E8D ERROR_DHCP_INVALID_POLICY_EXPRESSION</td>
  <td>The specified conditions or expressions of the policy are invalid.</td>
 </tr><tr>
  <td>0x00004E8B ERROR_DHCP_POLICY_RANGE_BAD</td>
  <td>The specified policy range is not contained within the IP address range of the scope, or the specified policy range is invalid.</td>
 </tr><tr>
  <td>0x00004E89 ERROR_DHCP_POLICY_NOT_FOUND</td>
  <td>The specified policy name does not exist at the specified level (server or scope).</td>
 </tr><tr>
  <td>0x00004E8A ERROR_DHCP_POLICY_RANGE_EXISTS</td>
  <td>The specified policy range overlaps the policy ranges of an existing policy at the specified scope.</td>
 </tr><tr>
  <td>0x00004E8E ERROR_DHCP_INVALID_PROCESSING_ORDER</td>
  <td>The specified processing order is greater than the maximum processing order of the existing policies at the specified level (server or scope).</td>
 </tr><tr>
  <td>0x00004E4C ERROR_DHCP_CLASS_NOT_FOUND</td>
  <td>The vendor class or user class reference in the conditions of the policy does not exist.</td>
 </tr><tr>
  <td>0x00004EA9 ERROR_DHCP_POLICY_EDIT_FQDN_UNSUPPORTED</td>
  <td>A FQDN-based condition is being added to a policy that has ranges or options configured.</td>
 </tr></tbody></table>
</dd></dl><p>The opnum field value for this method is 110.</p><p>When processing this call, the DHCP server MUST do the
following:</p><ul><li><p><span><span> 
</span></span>If the <i>ServerPolicy</i> parameter is TRUE and the <i>SubnetAddress</i>
parameter is not NULL, return ERROR_INVALID_PARAMETER.</p>
</li><li><p><span><span> 
</span></span>If the <i>ServerPolicy</i> parameter is FALSE and the <i>SubnetAddress</i>
parameter is NULL, return ERROR_INVALID_PARAMETER.</p>
</li><li><p><span><span> 
</span></span>If the <i>PolicyName</i> parameter is NULL or if the <i>Policy</i>
parameter is NULL, return ERROR_INVALID_PARAMETER.</p>
</li><li><p><span><span> 
</span></span>Validate whether this method is authorized for write/read access
as specified in section <a href="38840bd0-0a5a-47ed-bc69-0dd870d33aec" data-linktype="relative-path">3.5.5</a>.
If not, return ERROR_ACCESS_DENIED.</p>
</li><li><p><span><span> 
</span></span>If the <i>ServerPolicy</i> parameter is TRUE, retrieve the <b>DHCPv4ServerPolicyList</b>
ADM element and get the <b>DHCPv4Policy</b> ADM element from the <b>DHCPv4ServerPolicyList</b>
ADM element for the specified <i>PolicyName</i> parameter. If there is no
policy with the specified name, return ERROR_DHCP_POLICY_NOT_FOUND.</p>
</li><li><p><span><span> 
</span></span>If the <i>ServerPolicy</i> parameter is FALSE, retrieve the <b>DHCPv4ScopesList</b>
ADM element and get the <b>DHCPv4Scope</b> ADM element from the <b>DHCPv4ScopesList</b>
ADM element where the <b>SubnetAddress</b> ADM element member in the <b>DHCPv4Scope</b>
ADM element matches the specified <i>SubnetAddress</i> parameter. If there is
no <b>DHCPv4Scope</b> ADM element that has the specified <i>SubnetAddress</i> parameter
value, return <b>ERROR_DHCP_SUBNET_NOT_PRESENT</b>. Retrieve the <b>DHCPv4Scope.DHCPv4ScopePolicyList</b>
ADM element, and get the <b>DHCPv4Policy</b> ADM element from the <b>DHCPv4Scope.DHCPv4ScopePolicyList</b>
ADM element that has the same name as the specified <i>PolicyName</i>
parameter. If there is no policy with the specified name, return
ERROR_DHCP_POLICY_NOT_FOUND.</p>
</li><li><p><span><span> 
</span></span>If the DhcpUpdatePolicyRanges enumeration value bit in the <i>FieldsModified</i>
parameter is set:</p>
<ul><li><p><span><span>  </span></span>If
the <b>Ranges</b> member inside the <i>Policy</i> parameter is NULL, return
ERROR_INVALID_PARAMETER.</p>
</li><li><p><span><span>  </span></span>If
the <i>ServerPolicy</i> parameter is TRUE and the <b>NumElements</b> member in
the <b>Ranges</b> member of the <i>Policy</i> parameter is not 0, return
ERROR_DHCP_RANGE_INVALID_IN_SERVER_POLICY.</p>
</li><li><p><span><span>  </span></span>If
the <b>StartAddress</b> member of any of the <b>Ranges</b> members in the <i>pPolicy</i>
parameter is greater than the <b>EndAddress</b> member, return
ERROR_DHCP_POLICY_RANGE_BAD.</p>
</li><li><p><span><span>  </span></span>If
any of the <b>Ranges</b> member array element addresses in the <i>pPolicy</i>
parameter overlaps any other <b>Ranges</b> member array element addresses in
the <i>pPolicy</i> parameter, return ERROR_DHCP_POLICY_RANGE_BAD.</p>
</li><li><p><span><span>  </span></span>If
the updated policy contains a <b>Conditions</b> member that includes a
condition where the <b>Type</b> is set to the value DhcpAttrFqdn or
DhcpAttrFqdnSingleLabel as defined in the <a href="f05fc88f-3ac7-4c44-9998-40e4acaeb776" data-linktype="relative-path">DHCP_POL_ATTR_TYPE (section 2.2.1.1.23)</a>
enumeration, and the <b>NumElements</b> member of the <b>Ranges</b> member is
not 0, return ERROR_DHCP_POLICY_EDIT_FQDN_UNSUPPORTED.<a id="Appendix_A_Target_80"></a><a aria-label="Product behavior note 80" href="afab0546-79ae-4764-8dab-27a85cca5145#Appendix_A_80" data-linktype="relative-path">&lt;80&gt;</a></p>
</li><li><p><span><span>  </span></span>Retrieve
the <b>DHCPv4Scope.DHCPv4IPRangesList</b> ADM element. Check whether the <b>Ranges</b>
member specified is within at least one of the <b>DHCPv4IPRange</b> ADM
elements in the <b>DHCPv4Scope.DHCPv4IPRangesList</b> ADM element. Return
ERROR_DHCP_POLICY_RANGE_BAD if this check fails.</p>
</li><li><p><span><span>  </span></span>Retrieve
the <b>DHCPv4Policy.Policy.Ranges</b> ADM element. Check whether the <b>Range</b>
elements in the <b>Ranges</b> member specified in the <i>Policy</i> parameter
overlap any of the <b>Range</b> ADM elements in the <b>DHCPv4Policy.Policy.Ranges</b>
ADM element. Return ERROR_DHCP_POLICY_RANGE_EXISTS if the check succeeds.</p>
</li><li><p><span><span>  </span></span>If
the DhcpUpdatePolicyExpr enumeration value bit in the <i>FieldsModified</i>
parameter is set:</p>
<ul><li><p><span><span> 
</span></span>If the <b>Expressions</b> member or <b>Conditions</b> member of
the <i>Policy</i> parameter is NULL or the <b>NumElements</b> member in the <b>Expressions</b>
member or in the <b>Conditions</b> member are 0, return
ERROR_DHCP_INVALID_POLICY_EXPRESSION.</p>
</li><li><p><span><span> 
</span></span>If the Conditions member includes a condition where the <b>Type</b>
is set to the value DhcpAttrFqdn or DhcpAttrFqdnSingleLabel as defined in the <b>DHCP_POL_ATTR_TYPE</b>
enumeration, the updated policy MUST be validated to ensure that it does not
contain any ranges or any options apart from the options that specify DNS
settings (81) and lease time (51). If the validation fails, return
ERROR_DHCP_POLICY_EDIT_FQDN_UNSUPPORTED.<a id="Appendix_A_Target_81"></a><a aria-label="Product behavior note 81" href="afab0546-79ae-4764-8dab-27a85cca5145#Appendix_A_81" data-linktype="relative-path">&lt;81&gt;</a></p>
</li><li><p><span><span> 
</span></span>For each <a href="a9d6a415-4de6-4058-befe-ca2e42764485#gt_9a1c3bd3-d971-482a-adfe-6f41e427b95f" data-linktype="relative-path">condition</a>
element in the <b>Conditions</b> member in the <i>Policy</i> parameter:<a id="Appendix_A_Target_82"></a><a aria-label="Product behavior note 82" href="afab0546-79ae-4764-8dab-27a85cca5145#Appendix_A_82" data-linktype="relative-path">&lt;82&gt;</a></p>
<ul><li><p><span><span> 
</span></span>If the <b>ParentExpr</b> member in the <b>Conditions</b> member
is greater than the <b>NumElements</b> member in the <b>Expressions</b> member</p>
</li><li><p><span><span> 
</span></span>If the <b>Type</b> member is not one of the values defined for
the <b>DHCP_POL_ATTR_TYPE</b> enumeration</p>
</li><li><p><span><span> 
</span></span>If the <b>Type</b> member is not set to the DhcpAttrOption or
DhcpAttrSubOption value of the <b>DHCP_POL_ATTR_TYPE</b> enumeration, and the
values for both the <b>OptionID</b> and <b>SubOptionID</b> members are not 0</p>
</li><li><p><span><span> 
</span></span>If the <b>Type</b> member is not set to the DhcpAttrOption value
of the <b>DHCP_POL_ATTR_TYPE</b> enumeration; the OptionID member is not equal
to the vendor class identifier option (60), user class identifier option (77),
client identifier option (61), or <a href="a9d6a415-4de6-4058-befe-ca2e42764485#gt_53cb4370-b090-46e0-9039-939f04c90aa0" data-linktype="relative-path">relay agent information option</a>
(82); or the SubOptionID member is not equal to 0</p>
</li><li><p><span><span> 
</span></span>If the <b>Type</b> member is not set to the DhcpAttrSubOption
value of the <b>DHCP_POL_ATTR_TYPE</b> enumeration, the <b>OptionID</b> member
is not equal to the relay agent information option (82), or the <b>SubOptionID</b>
member is not equal to the agent circuit ID suboption (2), agent remote ID
suboption (2), or subscriber ID suboption</p>
</li><li><p><span><span> 
</span></span>If the <b>Type</b> member is set to the DhcpAttrHWAddr value of
the <b>DHCP_POL_ATTR_TYPE</b> enumeration, and the <b>Operator</b> member is
set to the DhcpCompEqual or DhcpCompNotEqual value of the <a href="92e62ae9-0aae-4c67-b742-17524afe79d7" data-linktype="relative-path">DHCP_POL_COMPARATOR (section 2.2.1.1.22)</a>
enumeration, and the <b>ValueLength</b> member is not equal to 6</p>
</li><li><p><span><span> 
</span></span>If the Type member is set to the DhcpAttrHWAddr value of the <b>DHCP_POL_ATTR_TYPE</b>
enumeration, and the Operator member is set to the DhcpCompBeginsWith,
DhcpCompNotBeginWith, DhcpCompEndsWith, or DhcpCompNotEndWith value of the <b>DHCP_POL_COMPARATOR</b>
enumeration, and the <b>ValueLength</b> member is equal to or greater than 6<a id="Appendix_A_Target_83"></a><a aria-label="Product behavior note 83" href="afab0546-79ae-4764-8dab-27a85cca5145#Appendix_A_83" data-linktype="relative-path">&lt;83&gt;</a></p>
</li><li><p><span><span> 
</span></span>If there are other <b>Conditions</b> member array elements with
the <b>ParentExpr</b> member having the same condition, and if</p>
<ul><li><p><span><span> 
</span></span>The <b>OptionID</b> member is the relay agent information option
(82)</p>
</li><li><p><span><span> 
</span></span>The <b>OptionID</b> member or <b>SubOptionID</b> member or <b>Type</b>
member or <b>VendorName</b> member is different for the conditions</p>
</li><li><p><span><span> 
</span></span>If the Operator member for the condition is set to the
DhcpCompEqual value of the <b>DHCP_POL_COMPARATOR</b> enumeration, the <b>Operator</b>
member of all other conditions (with the same ParentExpr member) is not set to
the DhcpCompEqual, DhcpCompBeginsWith, or DhpcCompEndsWith value of the <b>DHCP_POL_COMPARATOR</b>
enumeration<a id="Appendix_A_Target_84"></a><a aria-label="Product behavior note 84" href="afab0546-79ae-4764-8dab-27a85cca5145#Appendix_A_84" data-linktype="relative-path">&lt;84&gt;</a></p>
</li><li><p><span><span> 
</span></span>If the <b>Operator</b> member for the condition is set to the
DhcpCompNotEqual value of the <b>DHCP_POL_COMPARATOR</b> enumeration, the <b>Operator</b>
member of all other conditions (with the same <b>ParentExpr</b> member) is not
set to the DhcpCompNotEqual, DhcpCompNotBeginWith, or DhcpCompNotEndWith value
of the <b>DHCP_POL_COMPARATOR</b> enumeration<a id="Appendix_A_Target_85"></a><a aria-label="Product behavior note 85" href="afab0546-79ae-4764-8dab-27a85cca5145#Appendix_A_85" data-linktype="relative-path">&lt;85&gt;</a></p>
<p>For
each expression element in the <b>Expressions</b> member:</p>
</li><li><p><span><span> 
</span></span>If there are no other expression elements or condition elements
that have the index of this expression element in their <b>ParentExpr</b>
member</p>
</li><li><p><span><span> 
</span></span>If the <b>Operator</b> member of an expression element is not the
DhcpLogicalAnd enumeration value or DhcpLogicalOr enumeration value</p>
</li><li><p><span><span> 
</span></span>If the <b>ParentExpr</b> member value is not 0</p>
<p>If the <a href="a9d6a415-4de6-4058-befe-ca2e42764485#gt_6d43b116-acad-45af-aea5-a8e7240a1106" data-linktype="relative-path">expression</a> element is not
the first element in the array and if the <b>Operator</b> member of the
expression is not the DhcpLogicalAnd enumeration value</p>
<p>Return
ERROR_DHCP_INVALID_POLICY_EXPRESSION.</p>
</li></ul></li></ul></li></ul></li></ul></li><li><p><span><span> 
</span></span>If the DhcpUpdatePolicyOrder enumeration value bit in the <i>FieldsModified</i>
parameter is set, if <a href="a9d6a415-4de6-4058-befe-ca2e42764485#gt_3b199f35-b0f3-4897-83a6-e7fec0ee7fea" data-linktype="relative-path">scope
level policy</a> is being modified, get the maximum <b>ProcessingOrder</b> ADM
element of all the <b>DHCPv4Policy</b> ADM elements in the <b>DHCPv4Scope.DHCPv4ScopePolicyList</b>
ADM element. If the <b>ProcessingOrder</b> member in the <i>Policy</i>
parameter is greater than the maximum <b>ProcessingOrder</b> ADM element plus
1, return ERROR_DHCP_INVALID_PROCESSING_ORDER. Perform the same step for <b>DHCPv4ServerPolicyList</b>
if server level policy is being modified.</p>
</li><li><p><span><span> 
</span></span>If the DhcpUpdatePolicyName enumeration value bit in the <i>FieldsModified</i>
parameter is set, and if the <i>PolicyName</i> parameter is NULL, return
ERROR_INVALID_PARAMETER.</p>
</li><li><p><span><span> 
</span></span>Update the server or scope level <b>DHCPv4Policy</b> ADM element
retrieved earlier according to the following:</p>
<ul><li><p><span><span>  </span></span>If
the DhcpUpdatePolicyName enumeration value is set in the <i>FieldsModified</i>
parameter, update the name of the policy in the <b>DHCPv4Policy.Policy.PolicyName</b>
ADM element.</p>
</li><li><p><span><span>  </span></span>If
the DhcpUpdatePolicyOrder enumeration value is set in the <i>FieldsModified</i>
parameter, update the processing order of the policy in the <b>DHCPv4Policy.Policy.ProcessingOrder</b>
ADM element.</p>
</li><li><p><span><span>  </span></span>If
the DhcpUpdatePolicyExpr enumeration value is set in the <i>FieldsModified</i>
parameter:</p>
<ul><li><p><span><span> 
</span></span>Update the policy expressions in the <b>DHCPv4Policy.Expressions</b>
ADM element and the policy conditions in the <b>DHCPv4Policy.Conditions</b> ADM
element.</p>
</li><li><p><span><span> 
</span></span>If the <i>Policy</i> parameter contains only one condition record
with the <b>Operator</b> member set to DhcpCompEqual, iterate over the global
ADM element <b>DHCPv4ClassDefList</b> and retrieve a <b>DHCPv4ClassDef</b> ADM
object whose <b>DHCPv4ClassDef.IsVendor</b> is FALSE and whose <b>DHCPv4ClassDef.ClassData</b>
is the same as the <b>Value</b> member of that condition. If such a <b>DHCPv4ClassDef</b>
object exists, set the object&#39;s <b>DHCPv4Policy.ClassName</b> value to the <b>DHCPv4ClassDef.ClassName</b>
of the retrieved user class. Otherwise, set <b>DHCPv4Policy.ClassName</b> to
NULL.</p>
</li></ul></li><li><p><span><span>  </span></span>If
the DhcpUpdatePolicyRanges enumeration value is set in the <i>FieldsModified</i>
parameter, update the IP ranges of the policy in the <b>DHCPv4Policy.Policy.Ranges</b>
ADM element.</p>
</li><li><p><span><span>  </span></span>If
the DhcpUpdatePolicyStatus enumeration value is set in the <i>FieldsModified</i>
parameter, update the state (enabled/disabled) of the policy in <b>DHCPv4Policy.Policy.Enabled</b>.</p>
</li></ul></li><li><p><span><span> 
</span></span>If the <i>FieldsModified</i> parameter is set to any value other
than DhcpUpdatePolicyName, DhcpUpdatePolicyOrder, DhcpUpdatePolicyExpr,
DhcpUpdatePolicyRanges, DhcpUpdatePolicyDescr, or DhcpUpdatePolicyStatus, as
defined in the DHCP_POLICY_FIELDS_TO_UPDATE (section 2.2.1.1.21)
enumeration, return ERROR_INVALID_PARAMETER.</p>
</li><li><p><span><span> 
</span></span>Return ERROR_SUCCESS.</p>
</li></ul><p><b>Exceptions Thrown:</b> No exceptions are thrown beyond
those thrown by the underlying RPC protocol <a href="../ms-rpce/290c38b1-92fe-4229-91e6-4fc376610c15" data-linktype="relative-path">[MS-RPCE]</a>.</p></div>