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.

193 lines
5.3 KiB

  1. <%' CODEPAGE=65001 'UTF-8%>
  2. <%' certsrck.inc - (CERT)srv web - (S)cript: (R)equest-(C)ooc(K)ie management
  3. ' Copyright (C) Microsoft Corporation, 1998 - 1999 %>
  4. <%
  5. ' Format of our cookie:
  6. ' '[' <ReqID> ',' <TargetStoreFlags> ',' <SaveCert> ',' <FriendlyType> ']'...
  7. Const FIELD_REQID=0
  8. Const FIELD_TARGETSTOREFLAGS=1
  9. Const FIELD_SAVECERT=2
  10. Const FIELD_FRIENDLYTYPE=3
  11. Const NUM_FIELDS=4
  12. Const REQUEST_COOKIE_NAME="Requests"
  13. Dim nReqId
  14. ' Look up the requests in the cookie, and return an array of 'request' arrays
  15. ' The returned requests are all encoded using Server.HTMLEncode. Thus, the
  16. ' text may have been altered for browser display against CSS attacks.
  17. Function GetRequests(bEncodeRequests)
  18. ' Get the cookie
  19. Dim sRequests
  20. sRequests=Request.Cookies(REQUEST_COOKIE_NAME)
  21. ' If the cookie was never set, return an empty array
  22. If ""=sRequests Then
  23. GetRequests=Null
  24. Exit Function
  25. End If
  26. ' If we requested that the requests be encoded, do so now:
  27. If True=bEncodeRequests Then
  28. sRequests = Server.HTMLEncode(sRequests)
  29. End If
  30. Dim nRequests
  31. Dim rgRequests()
  32. nRequests=0
  33. ' Loop through all the requests in the string
  34. Dim nSplitIndex
  35. Do
  36. ' Find the next request
  37. nSplitIndex=InStr(sRequests,"]")
  38. If 0=nSplitIndex Then
  39. Exit Do
  40. End If
  41. ' Split this Request off the string
  42. Dim sElem
  43. sElem=Mid(sRequests, 2, nSplitIndex-2)
  44. sRequests=Mid(sRequests, nSplitIndex+1)
  45. ' Spit this request apart
  46. Dim rgElem
  47. rgElem=Split(sElem, ",")
  48. ' Safety check
  49. If NUM_FIELDS-1<>UBound(rgElem) Then
  50. ' Cookie is corrupt
  51. nRequests=0
  52. Exit Do
  53. End If
  54. ' Add this array to our array of requests
  55. ReDim Preserve rgRequests(nRequests)
  56. rgRequests(nRequests)=rgElem
  57. nRequests=nRequests+1
  58. ' safety check for testing
  59. 'If nRequests>25 Then
  60. ' Err.Raise 6
  61. 'End If
  62. Loop ' End string-parsing loop
  63. ' if there was an error parsing the cookie, just assume it was empty.
  64. If 0=nRequests Then
  65. GetRequests=Null
  66. Else
  67. GetRequests=rgRequests
  68. End If
  69. End Function
  70. ' Combine a requests-array into a single string and set it as a cookie
  71. Sub PutRequests(rgRequests)
  72. Dim sCookie, sRequests, nIndex
  73. sRequests=""
  74. ' check for the empty list
  75. If IsNull(rgRequests) Then
  76. ' the list is empty
  77. ' do nothing
  78. sRequests="-" ' Lynx won't set an empty cookie, so set an invalid one
  79. Else
  80. ' the list is not empty
  81. ' build a string for each request and concatenate to make cookie
  82. For nIndex=0 To UBound(rgRequests)
  83. sRequests=sRequests & "[" & _
  84. rgRequests(nIndex)(FIELD_REQID) & "," & _
  85. rgRequests(nIndex)(FIELD_TARGETSTOREFLAGS) & "," & _
  86. rgRequests(nIndex)(FIELD_SAVECERT) & "," & _
  87. rgRequests(nIndex)(FIELD_FRIENDLYTYPE) & "]"
  88. Next
  89. End If
  90. ' Set the cookie
  91. Response.Cookies(REQUEST_COOKIE_NAME)=sRequests
  92. ' Set the expiration date
  93. Response.Cookies(REQUEST_COOKIE_NAME).Expires=Now+nPendingTimeoutDays
  94. ' Set the path
  95. Response.Cookies(REQUEST_COOKIE_NAME).Path="/certsrv"
  96. End Sub
  97. ' Remove a given request from the requests cookie
  98. Sub RemoveReq(nReqID)
  99. ' get the array of requests
  100. Dim rgRequests
  101. rgRequests=GetRequests(False)
  102. ' if the cookie is empty, just ignore
  103. If IsNull(rgRequests) Then
  104. Exit Sub
  105. End If
  106. ' find the request
  107. Dim nIndex
  108. Dim nFoundIndex
  109. nFoundIndex=-1
  110. For nIndex=0 To UBound(rgRequests)
  111. If nReqID=rgRequests(nIndex)(FIELD_REQID) Then
  112. nFoundIndex=nIndex
  113. Exit For
  114. End If
  115. Next
  116. If -1=nFoundIndex Then
  117. ' request not found, probably a reload and it was deleted already
  118. ' do nothing
  119. Else
  120. ' remove the request:
  121. If 0=UBound(rgRequests) Then
  122. ' this is the last request
  123. ' removing it leaves an empty list
  124. rgRequests=Null
  125. Else
  126. ' Not the last request, so shuffle down
  127. ' (this is not the most efficient, but it keeps the requests in order)
  128. For nIndex=nFoundIndex To UBound(rgRequests)-1
  129. rgRequests(nIndex)=rgRequests(nIndex+1)
  130. Next
  131. ' shrink the array
  132. ReDim Preserve rgRequests(UBound(rgRequests)-1)
  133. End If
  134. ' set the cookie
  135. PutRequests rgRequests
  136. End If
  137. End Sub
  138. ' Add the current request to the request cookie
  139. Sub AddRequest
  140. ' build a request object for this request
  141. Dim rgNewReq(3) 'NUM_FIELDS-1
  142. nReqId=ICertRequest.GetRequestId()
  143. rgNewReq(FIELD_REQID)=nReqId
  144. rgNewReq(FIELD_TARGETSTOREFLAGS)=Request.Form("TargetStoreFlags")
  145. rgNewReq(FIELD_SAVECERT)=Request.Form("SaveCert")
  146. rgNewReq(FIELD_FRIENDLYTYPE)=Request.Form("FriendlyType")
  147. ' prevent special split characters from being placed in the string
  148. ' by converting them to spaces
  149. rgNewReq(FIELD_FRIENDLYTYPE)=Replace(rgNewReq(FIELD_FRIENDLYTYPE), ",", " ")
  150. rgNewReq(FIELD_FRIENDLYTYPE)=Replace(rgNewReq(FIELD_FRIENDLYTYPE), "]", " ")
  151. ' add it to the list
  152. Dim rgRequests
  153. rgRequests=GetRequests(False)
  154. If IsNull(rgRequests) Then
  155. ' cookie has never been set
  156. ReDim rgRequests(0)
  157. Else
  158. ' save old requests in cookie
  159. ReDim Preserve rgRequests(UBound(rgRequests)+1)
  160. End If
  161. rgRequests(UBound(rgRequests))=rgNewReq
  162. PutRequests rgRequests
  163. End Sub
  164. %>