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.

378 lines
13 KiB

  1. <%@ Language=VBScript %>
  2. <% Option Explicit %>
  3. <%
  4. '-------------------------------------------------------------------------
  5. ' user_delete.asp : Deletes the specified user
  6. '
  7. ' Copyright (c) Microsoft Corporation. All rights reserved.
  8. '
  9. ' Date Description
  10. ' 15-jan-01 Creation date
  11. '-------------------------------------------------------------------------
  12. %>
  13. <!-- #include virtual="/admin/inc_framework.asp" -->
  14. <%
  15. '-------------------------------------------------------------------------
  16. ' Global Variables
  17. '-------------------------------------------------------------------------
  18. Dim rc 'framework variables
  19. Dim page 'framework variables
  20. Dim G_strUserName 'To save logged-in client user
  21. '-------------------------------------------------------------------------
  22. ' Global Form Variables
  23. '-------------------------------------------------------------------------
  24. 'Dim F_strUsername 'To save the user name got from the prevoius selected form
  25. '-------------------------------------------------------------------------
  26. 'Start of localization content
  27. '-------------------------------------------------------------------------
  28. Dim L_PAGETITLE
  29. 'Dim L_DELETETHEUSERMESSAGE
  30. Dim L_NOTE
  31. Dim L_NOTEBODY
  32. Dim L_COULDNOTDELETEUSER_ERRORMESSAGE
  33. Dim L_COULDNOTDELETEBUILTINACCOUNTS_ERRORMESSAGE
  34. Dim L_USERNOTFOUND_ERRORMESSAGE
  35. Dim L_CANNOTDELETETHEUSERMESSAGE
  36. Dim L_UNABLETOGETSERVERVARIABLES
  37. Dim L_COMPUTERNAME_ERRORMESSAGE
  38. Const N_COULDNOTDELETEBUILTINACCOUNTS_ERRNO =&H8007055B
  39. L_PAGETITLE = objLocMgr.GetString("usermsg.dll","&H4030003B", varReplacementStrings)
  40. 'L_DELETETHEUSERMESSAGE = objLocMgr.GetString("usermsg.dll","&H4030003C", varReplacementStrings)
  41. L_NOTE = objLocMgr.GetString("usermsg.dll","&H4030003D", varReplacementStrings)
  42. L_NOTEBODY = objLocMgr.GetString("usermsg.dll","&H4030003E", varReplacementStrings)
  43. L_COULDNOTDELETEUSER_ERRORMESSAGE = objLocMgr.GetString("usermsg.dll","&HC030003F", varReplacementStrings)
  44. L_COULDNOTDELETEBUILTINACCOUNTS_ERRORMESSAGE = objLocMgr.GetString("usermsg.dll","&HC0300040", varReplacementStrings)
  45. L_USERNOTFOUND_ERRORMESSAGE = objLocMgr.GetString("usermsg.dll","&HC0300041", varReplacementStrings)
  46. L_CANNOTDELETETHEUSERMESSAGE = objLocMgr.GetString("usermsg.dll","&HC0300042", varReplacementStrings)
  47. L_UNABLETOGETSERVERVARIABLES = objLocMgr.GetString("usermsg.dll","&H40300043", varReplacementStrings)
  48. L_COMPUTERNAME_ERRORMESSAGE = objLocMgr.GetString("usermsg.dll","&HC0300044", varReplacementStrings)
  49. '-----------------------------------------------------------------------------------
  50. 'END of localization content
  51. '-----------------------------------------------------------------------------------
  52. ' Create a Property Page
  53. rc = SA_CreatePage( L_PAGETITLE, "", PT_PROPERTY, page )
  54. ' Serve the page
  55. rc = SA_ShowPage( page )
  56. '-------------------------------------------------------------------------
  57. 'Function: OnInitPage()
  58. 'Description: Called to signal first time processing for this page.
  59. ' Use this method to do first time initialization tasks
  60. 'Input Variables: PageIn,EventArg
  61. 'Output Variables: PageIn,EventArg
  62. 'Returns: True/False
  63. 'Global Variables: IN:G_strUserName
  64. '-------------------------------------------------------------------------
  65. Public Function OnInitPage(ByRef PageIn, ByRef EventArg)
  66. SA_TraceOut "TEMPLATE_PROPERTY", "OnInitPage"
  67. 'Fucntion call to Get the logged in username
  68. G_strUserName=GetUsername()
  69. OnInitPage = TRUE
  70. End Function
  71. '-------------------------------------------------------------------------
  72. 'Function: OnServePropertyPage()
  73. 'Description: Called when the page needs to be served.Use this
  74. ' method to serve content
  75. 'Input Variables: PageIn,EventArg
  76. 'Output Variables: PageIn,EventArg
  77. 'Returns: True/False
  78. 'Global Variables: L_(*)
  79. ' G_strUserName
  80. ' F_strUsername
  81. '-------------------------------------------------------------------------
  82. Public Function OnServePropertyPage(ByRef PageIn, ByRef EventArg)
  83. SA_TraceOut "TEMPLATE_PROPERTY", "OnServePropertyPage"
  84. ' Emit Functions required by Web Framework
  85. Call ServeCommonJavaScript()
  86. Response.Write "<TABLE VALIGN=middle ALIGN=left BORDER=0 CELLSPACING=0 CELLPADDING=2 class='TasksBody'>"
  87. Dim itemCount
  88. Dim itemKey
  89. Dim bHave
  90. Dim x
  91. Dim sessionItem
  92. Dim arrStrings(1)
  93. Dim strParam
  94. Dim strDeleteMsg
  95. bHave = false
  96. itemCount = OTS_GetTableSelectionCount("")
  97. For x = 1 to itemCount
  98. If ( OTS_GetTableSelection("", x, itemKey) ) Then
  99. Response.Write "<TR>"
  100. If VerifyUserAccount(itemKey) Then
  101. bHave = true
  102. arrStrings(0) = itemKey
  103. strParam = arrStrings
  104. strDeleteMsg = SA_GetLocString("usermsg.dll","&H4030003C", strParam)
  105. Response.Write "<TD>" & strDeleteMsg & "</TD>"
  106. Else
  107. Response.Write "<TD>" & L_CANNOTDELETETHEUSERMESSAGE & "</TD>"
  108. End If
  109. Response.Write "</TR>"
  110. End If
  111. sessionItem = "Item" + CStr(x)
  112. Session(sessionItem) = itemKey
  113. Next
  114. If bHave=true Then
  115. %>
  116. <TR>
  117. <TD colspan=2>
  118. &nbsp
  119. </TD>
  120. </TD>
  121. <TR>
  122. <TD>
  123. <B><%=L_NOTE%></B>
  124. </TD>
  125. </TR>
  126. <TR>
  127. <TD width="590" height="20">
  128. <%=L_NOTEBODY%>
  129. </TD>
  130. </TR>
  131. <%End If%>
  132. </TABLE>
  133. <input type=hidden name="hdnLoggedInUserName" value="<%=Server.HTMLEncode(G_strUserName)%>">
  134. <%
  135. OnServePropertyPage = TRUE
  136. End Function
  137. '-------------------------------------------------------------------------
  138. 'Function: OnPostBackPage()
  139. 'Description: Called to signal that the page has been posted-back.
  140. 'Input Variables: PageIn,EventArg
  141. 'Output Variables: PageIn,EventArg
  142. 'Returns: True/False
  143. 'Global Variables: None
  144. '-------------------------------------------------------------------------
  145. Public Function OnPostBackPage(ByRef PageIn, ByRef EventArg)
  146. OnPostBackPage = TRUE
  147. End Function
  148. '-------------------------------------------------------------------------
  149. 'Function: OnSubmitPage()
  150. 'Description: Called when the page has been submitted for processing.
  151. ' Use this method to process the submit request.
  152. 'Input Variables: PageIn,EventArg
  153. 'Output Variables: PageIn,EventArg
  154. 'Returns: True/False
  155. 'Global Variables: None
  156. '-------------------------------------------------------------------------
  157. Public Function OnSubmitPage(ByRef PageIn, ByRef EventArg)
  158. SA_TraceOut "TEMPLATE_PROPERTY", "OnSubmitPage"
  159. OnSubmitPage= DeleteUser()
  160. End Function
  161. '-------------------------------------------------------------------------
  162. 'Function: OnClosePagee()
  163. 'Description: Called when the page has been submitted for processing.
  164. ' Use this method to process the submit request.
  165. 'Input Variables: PageIn,EventArg
  166. 'Output Variables: PageIn,EventArg
  167. 'Returns: True/False
  168. 'Global Variables: None
  169. '-------------------------------------------------------------------------
  170. Public Function OnClosePage(ByRef PageIn, ByRef EventArg)
  171. SA_TraceOut "TEMPLATE_PROPERTY", "OnClosePage"
  172. OnClosePage = TRUE
  173. End Function
  174. '-------------------------------------------------------------------------
  175. 'Function name: DeleteUser()
  176. 'Description: Serves in Updating users list
  177. 'Input Variables: None
  178. 'Output Variables: True or false
  179. 'Returns: ( True / Flase )
  180. ' True: If suceeds in updating the list
  181. ' False:If fails in updating the list
  182. 'Global Variables: In:L_USERNOTFOUND_ERRORMESSAGE
  183. ' In:L_COULDNOTDELETEUSER_ERRORMESSAGE
  184. ' In:L_COULDNOTDELETEBUILTINACCOUNTS_ERRORMESSAGE
  185. '
  186. 'This function updates Serves in Updating users lists by deleting selected user
  187. '
  188. 'If an error occurs, in getting the users list calls ServeFailurePage with
  189. 'the error string L_USERNOTFOUND_ERRORMESSAGE
  190. '
  191. 'If an error occurs, in deleting the built-in account calls SetErrMsg with
  192. 'the error string L_COULDNOTDELETEBUILTINACCOUNTS_ERRORMESSAGE
  193. '
  194. 'If an error occurs, in deleting the user, calls SetErrMsg with
  195. 'the error string L_COULDNOTDELETEUSER_ERRORMESSAGE
  196. '-------------------------------------------------------------------------
  197. Function DeleteUser
  198. Err.Clear
  199. On Error Resume Next
  200. Dim nretval
  201. Dim strComputerName
  202. Dim objUser
  203. Dim objComputer
  204. DeleteUser = FALSE
  205. 'Gets the ComputerName from the system
  206. strComputerName = GetComputerName()
  207. 'Gets the UserNameObject from the system
  208. Set objComputer = GetObject("WinNT://" & strComputerName & ",computer")
  209. If Err.number <> 0 Then
  210. ServeFailurePage L_COMPUTERNAME_ERRORMESSAGE,1
  211. Exit Function
  212. End If
  213. Dim x
  214. Dim itemCount
  215. Dim itemKey
  216. Dim sessionItem
  217. itemCount = OTS_GetTableSelectionCount("")
  218. For x = 1 to itemCount
  219. If ( OTS_GetTableSelection("", x, itemKey) ) Then
  220. 'Checking for the existence of the user
  221. Set objUser = objComputer.GetObject("User",itemKey)
  222. If Err.number <> 0 Then
  223. SetErrMsg L_USERNOTFOUND_ERRORMESSAGE
  224. Exit Function
  225. End If
  226. 'deletes the Username from the System
  227. nretval = objComputer.Delete("User" , itemKey)
  228. If Err.Number <> 0 Then
  229. If Err.Number = N_COULDNOTDELETEBUILTINACCOUNTS_ERRNO Then
  230. SetErrMsg L_COULDNOTDELETEBUILTINACCOUNTS_ERRORMESSAGE & "(" & itemKey & ")"
  231. Else
  232. SetErrMsg L_COULDNOTDELETEUSER_ERRORMESSAGE & "(" & itemKey & ")"
  233. End IF
  234. Exit Function
  235. End If
  236. End If
  237. sessionItem = "Item" + CStr(x)
  238. Session(sessionItem) = itemKey
  239. Next
  240. Set objUser= Nothing
  241. Set objComputer =Nothing
  242. DeleteUser = TRUE
  243. End function
  244. '-------------------------------------------------------------------------
  245. 'Function name: GetUsername()
  246. 'Description: Serves in getting the logged-in client user
  247. 'Input Variables: None
  248. 'Output Variables: None
  249. 'Returns: string -Either Logged in username or null
  250. 'Global Variables: In:L_UNABLETOGETSERVERVARIABLES
  251. 'If an error occurs, in getting ServerVariables calls SetErrMsg with
  252. 'the error string L_UNABLETOGETSERVERVARIABLES
  253. '-------------------------------------------------------------------------
  254. Function GetUsername()
  255. Err.Clear
  256. On Error Resume Next
  257. Dim strDomainUserName
  258. Dim strUserName
  259. strDomainUserName = Request.ServerVariables("REMOTE_USER")
  260. If Err.Number <> 0 Then
  261. SetErrMsg L_UNABLETOGETSERVERVARIABLES
  262. GetUsername = ""
  263. End if
  264. If InStr(strDomainUserName, "\") Then
  265. strUserName = Split(strDomainUserName,"\")
  266. GetUsername = strUserName(1)
  267. Else
  268. GetUsername = strDomainUserName
  269. End If
  270. End Function
  271. '-------------------------------------------------------------------------
  272. 'Function name: VerifyUserAccount()
  273. 'Description: Serves in verifying the logged-in client user
  274. 'Input Variables: None
  275. 'Output Variables: True or false
  276. 'Returns: ( True / Flase )
  277. ' True: If selected user is logged-in client user
  278. ' False:If selected user is not logged-in client user
  279. 'Global Variables: In:F_strUsername - selected user for deletion
  280. ' In:G_strUserName - logged-in client user
  281. 'This function Serves in verifying the logged-in client user
  282. 'by comparing it with the selected user for deletion
  283. '
  284. '-------------------------------------------------------------------------
  285. Function VerifyUserAccount(strUserName)
  286. 'verifying the logged-in client user
  287. If strUserName=G_strUserName then
  288. VerifyUserAccount=false
  289. else
  290. VerifyUserAccount=true
  291. end if
  292. End function
  293. '-------------------------------------------------------------------------
  294. 'Function: ServeCommonJavaScript
  295. 'Description: Serves in initialiging the values,setting the form
  296. ' data and validating the form values
  297. 'Input Variables: None
  298. 'Output Variables: None
  299. 'Returns: None
  300. 'Global Variables: None
  301. '-------------------------------------------------------------------------
  302. Function ServeCommonJavaScript()
  303. %>
  304. <script language="JavaScript" src="<%=m_VirtualRoot%>inc_global.js">
  305. </script>
  306. <script language="JavaScript">
  307. // Init Function
  308. function Init()
  309. {
  310. SetPageChanged(false);
  311. }
  312. // ValidatePage Function
  313. // Returns: True if the page is OK, false if error(s) exist.
  314. function ValidatePage()
  315. {
  316. return true;
  317. }
  318. // SetData Function
  319. // This function must be included or a javascript runtime error will occur.
  320. function SetData()
  321. {
  322. }
  323. </script>
  324. <%
  325. End Function
  326. %>