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.

1700 lines
49 KiB

  1. <%
  2. '
  3. ' Copyright (c) Microsoft Corporation. All rights reserved.
  4. '
  5. '-------------------------------------------------------------------------
  6. '
  7. ' Declare and implement the public functions of NFS services
  8. '
  9. '-------------------------------------------------------------------------
  10. Const CONST_SUCCESS = 0
  11. Const CONST_UNSPECIFIED_ERROR = 100
  12. Const CONST_GROUP_EXISTS = 1
  13. Const CONST_GROUP_NOT_EXISTS = 2
  14. Const CONST_INVALID_MEMBER = 3
  15. Const CONST_INVALID_GROUP = 4
  16. Const CONST_MEMBER_EXISTS = 5
  17. Const CONST_MEMBER_NOT_EXISTS = 6
  18. Const CONST_NO_CLIENT_GROUPS = 7
  19. Const CONST_INVALID_MACHINE = 8
  20. Const CONST_NO_MEMBERS = 9
  21. Const CONST_MAX_MSGS = 9
  22. Const CONST_READ = 1
  23. Const CONST_LIST_GROUPS = "The following are the client groups"
  24. Const CONST_LIST_MEMBERS = "The following are the members in the client group"
  25. Dim g_strGroups
  26. Dim g_strMemberAtFault
  27. Dim g_strMembers
  28. Dim g_arrOutputMsgs()
  29. ReDim g_arrOutputMsgs(CONST_MAX_MSGS,2)
  30. g_arrOutputMsgs(0,0) = "Client group already exists. Specify a new client group name ."
  31. g_arrOutputMsgs(0,1) = CONST_GROUP_EXISTS
  32. g_arrOutputMsgs(1,0) = "Invalid client group. Specify a valid client group."
  33. g_arrOutputMsgs(1,1) = CONST_INVALID_GROUP
  34. g_arrOutputMsgs(2,0) = "There are no client groups"
  35. g_arrOutputMsgs(2,1) = CONST_NO_CLIENT_GROUPS
  36. g_arrOutputMsgs(3,0) = "is already present in"
  37. g_arrOutputMsgs(3,1) = CONST_MEMBER_EXISTS
  38. g_arrOutputMsgs(4,0) = "is not a valid machine"
  39. g_arrOutputMsgs(4,1) = CONST_INVALID_MACHINE
  40. g_arrOutputMsgs(5,0) = "is not a member of the group"
  41. g_arrOutputMsgs(5,1) = CONST_INVALID_MEMBER
  42. g_arrOutputMsgs(6,0) = "Invalid client group. Specify a valid client group."
  43. g_arrOutputMsgs(6,1) = CONST_INVALID_GROUP
  44. g_arrOutputMsgs(7,0) = "There are no members in the client group"
  45. g_arrOutputMsgs(7,1) = CONST_NO_MEMBERS
  46. g_arrOutputMsgs(8,0) = "is not a member of the group"
  47. g_arrOutputMsgs(8,1) = CONST_MEMBER_NOT_EXISTS
  48. '**********
  49. 'If you add more message make sure to change CONST_MAX_MSGS
  50. '**********
  51. '-------------------------------------------------------------------------
  52. 'Function name: isServiceStarted
  53. 'Description: Check whether the service is started ot not
  54. 'Input Variables: None
  55. 'Output Variables: None
  56. 'Returns: True if service is started else false
  57. 'Global Variables: In:L_SERVICEINFO_ERRORMESSAGE
  58. '--------------------------------------------------------------------------
  59. Function isServiceStarted(strService)
  60. On Error Resume Next
  61. Err.Clear
  62. Dim objService
  63. Dim objConn
  64. Dim objCollection
  65. isServiceStarted = False
  66. 'get the server connection
  67. Set objConn = GetWMIConnection("Default")
  68. 'query for the service
  69. Set objCollection = objConn.ExecQuery( _
  70. "Select * from win32_Service where name='"&strService&"'")
  71. If Err.Number <> 0 Then
  72. SA_ServeFailurePage L_SERVICEINFO_ERRORMESSAGE
  73. isServiceStarted = False
  74. Exit Function
  75. End If
  76. For Each objService In objCollection
  77. 'check whether the service is running
  78. If objService.State <> "Running" Then
  79. isServiceStarted = False
  80. Exit Function
  81. Else
  82. isServiceStarted = True
  83. Exit Function
  84. End if
  85. Next
  86. Set objCollection = Nothing
  87. Set objService = Nothing
  88. Set objConn = Nothing
  89. End Function
  90. '-------------------------------------------------------------------------
  91. 'Function name: VBaddMinimumColumnGap
  92. 'Description: add coloum Gap
  93. 'Input Variables: None
  94. 'Output Variables: None
  95. 'Returns: string
  96. 'Global Variables: NONE
  97. '--------------------------------------------------------------------------
  98. Function VBaddMinimumColumnGap(inputString, STR_CONTD, toWidth)
  99. On Error Resume Next
  100. Err.Clear
  101. Dim INT_MIN_COL_GAP
  102. Dim STR_SPACE
  103. Dim MIN_COL_GAP
  104. Dim i
  105. INT_MIN_COL_GAP = Len(STR_CONTD) + 1
  106. STR_SPACE = "&nbsp;"
  107. MIN_COL_GAP = ""
  108. If Len(inputString) >= toWidth Then
  109. MIN_COL_GAP = STR_SPACE
  110. Else
  111. For i = 1 To INT_MIN_COL_GAP
  112. MIN_COL_GAP = MIN_COL_GAP & STR_SPACE
  113. Next
  114. End If
  115. VBaddMinimumColumnGap = MIN_COL_GAP
  116. End Function
  117. '-------------------------------------------------------------------------
  118. 'Function name: VBpackString
  119. 'Description: Packing string
  120. 'Input Variables: None
  121. 'Output Variables: None
  122. 'Returns: packed string
  123. 'Global Variables: NONE
  124. '--------------------------------------------------------------------------
  125. Function VBpackString(inputString, STR_CONTD, toWidth, blnPadGap,blnDontPad)
  126. On Error Resume Next
  127. Err.Clear
  128. Dim returnString
  129. Dim STR_SPACE
  130. Dim intPaddingLength
  131. Dim strPadAfterCol
  132. Dim i
  133. strPadAfterCol = ""
  134. returnString = inputString
  135. STR_SPACE = "&nbsp;"
  136. intPaddingLength = 0
  137. If CBool(blnPadGap) Then
  138. strPadAfterCol = VBaddMinimumColumnGap(inputString, STR_CONTD, toWidth)
  139. End If
  140. If Len(inputString) <= toWidth Then
  141. if not Cbool(blnDontPad) then
  142. intPaddingLength = toWidth - Len(inputString)
  143. returnString = Server.HTMLEncode(returnString)
  144. For i = 1 To intPaddingLength
  145. returnString = returnString & STR_SPACE
  146. Next
  147. end if
  148. Else
  149. returnString = Left(inputString,toWidth)
  150. returnString = Server.HTMLEncode(returnString) & STR_CONTD
  151. End If
  152. VBpackString = returnString & strPadAfterCol
  153. End Function
  154. '-------------------------------------------------------------------------
  155. ' Function name: SortStringArray(strArray)
  156. ' Description: Used to sort a strArray
  157. ' Input Variables: None
  158. ' Output Variables: None
  159. ' Returns: Sorted string
  160. ' Global Variables: None
  161. '-------------------------------------------------------------------------
  162. Function VBSortStringArray(strArray)
  163. On Error Resume Next
  164. Err.Clear
  165. Dim i, j
  166. Dim nString
  167. Dim strTmpArray
  168. Dim strSwap
  169. strTmpArray = split(strArray,"#",-1,0)
  170. nString = Ubound(strTmpArray)
  171. 'Begin to sort the array
  172. For i=0 to (nString-1)
  173. For j=i+1 to nString
  174. If StrComp(strTmpArray(i),strTmpArray(j),0) > 0 Then
  175. strSwap = strTmpArray(i)
  176. strTmpArray(i) = strTmpArray(j)
  177. strTmpArray(j) = strSwap
  178. End if
  179. Next
  180. Next
  181. VBSortStringArray = strTmpArray
  182. End Function
  183. '-------------------------------------------------------------------------
  184. ' Function name: VBFormatStringToColumns
  185. ' Description: Format five string to List's Colum
  186. ' Input Variables: None
  187. ' Output Variables: None
  188. ' Returns: Sorted string
  189. ' Global Variables: None
  190. '-------------------------------------------------------------------------
  191. Function VBFormatStringToColumns(str_WINGROUP, str_UNIXDOMAIN, _
  192. str_UNIXGROUP, str_GID, str_PRIMARY)
  193. On Error Resume Next
  194. Err.Clear
  195. Const WIDTH_WINGROUP = 20
  196. Const WIDTH_UNIX_DOMAIN = 13
  197. Const WIDTH_UNIX_GROUP = 13
  198. Const WIDTH_GID = 4
  199. Const WIDTH_ISPRIMARY = 8
  200. Const STR_CONTD = "..."
  201. Const PAD_GAP_AFTER_COL = 1
  202. Const DONOT_PAD_AFTER_COL = 0
  203. Dim strTextToreturn
  204. strTextToreturn = ""
  205. strTextToreturn = strTextToreturn & VBpackString(str_WINGROUP, _
  206. STR_CONTD, WIDTH_WINGROUP,PAD_GAP_AFTER_COL,False)
  207. strTextToreturn = strTextToreturn & VBpackString(str_UNIXDOMAIN, _
  208. STR_CONTD, WIDTH_UNIX_DOMAIN,PAD_GAP_AFTER_COL,False)
  209. strTextToreturn = strTextToreturn & VBpackString(str_UNIXGROUP, _
  210. STR_CONTD, WIDTH_UNIX_GROUP,PAD_GAP_AFTER_COL,False)
  211. strTextToreturn = strTextToreturn & VBpackString(str_GID, _
  212. STR_CONTD, WIDTH_GID,PAD_GAP_AFTER_COL,False)
  213. strTextToreturn = strTextToreturn & VBpackString(str_PRIMARY, _
  214. STR_CONTD, WIDTH_ISPRIMARY,DONOT_PAD_AFTER_COL,True)
  215. VBFormatStringToColumns = strTextToreturn
  216. End Function
  217. '-------------------------------------------------------------------------
  218. 'Function name: NFS_GetSFUVersion
  219. 'Description: Gets the version of SFU installed on the local
  220. ' machine.
  221. 'Input Variables: None
  222. 'Output Variables: None
  223. 'Returns: String: "2.0", "2.1", "2.2", "3", or "0" for
  224. ' unknown.
  225. 'Global Variables: In: G_HKEY_LOCAL_MACHINE
  226. '
  227. '--------------------------------------------------------------------------
  228. Function NFS_GetSFUVersion
  229. Dim oRegistry
  230. Set oRegistry = RegConnection()
  231. Dim strVersion
  232. strVersion = GetRegKeyValue(oRegistry, _
  233. "SOFTWARE\Microsoft\Services For Unix", _
  234. "Version", _
  235. 2) ' String type.
  236. If (Left(strVersion, 1) = "5") Then
  237. ' Version 2.x
  238. Select Case (Left(strVersion, 11))
  239. Case "5.2000.0328"
  240. NFS_GetSFUVersion = "2.0"
  241. Case "5.3000.1313"
  242. NFS_GetSFUVersion = "2.1"
  243. Case "5.3000.2071"
  244. NFS_GetSFUVersion = "2.2"
  245. Case Else
  246. NFS_GetSFUVersion = "2.2"
  247. End Select
  248. Else
  249. ' Version 3.x
  250. NFS_GetSFUVersion = "3"
  251. End If
  252. End Function
  253. '-------------------------------------------------------------------------
  254. 'Function name: NFS_GetSFUConnection
  255. 'Description: Gets the Mapper details from the WMI object
  256. 'Input Variables: None
  257. 'Output Variables: None
  258. 'Returns: True if no error else False
  259. 'Global Variables: In:L_SERVERCONNECTIONFAIL_ERRO
  260. '
  261. '--------------------------------------------------------------------------
  262. Function NFS_GetSFUConnection
  263. On Error Resume Next
  264. Err.Clear
  265. Dim objSfuAdmin
  266. Set objSfuAdmin = GetWMIConnection("root\SFUADMIN")
  267. If Err.number <> 0 Then
  268. SA_ServeFailurePage L_SERVERCONNECTIONFAIL_ERRORMESSAGE
  269. Else
  270. Set NFS_GetSFUConnection = objSfuAdmin
  271. End If
  272. End Function
  273. '-------------------------------------------------------------------------
  274. 'Function name: NFS_GetUserMappings
  275. 'Description: Gets the user Mappers from the WMI object
  276. 'Input Variables: None
  277. 'Output Variables: None
  278. 'Returns: user mappings
  279. 'Global Variables: None
  280. '
  281. '--------------------------------------------------------------------------
  282. Function NFS_GetUserMappings(objSFUService)
  283. Err.Clear
  284. On Error Resume Next
  285. If (NFS_GetSFUVersion() < "2.2") Then
  286. Dim objUserMaps
  287. 'Get the Settings object
  288. Set objUserMaps = objSFUService.get("Mapper_Settings.KeyName='CurrentVersion'")
  289. If Err.number <> 0 Then
  290. SA_ServeFailurePage L_SETTINGSRETRIEVFAILED_ERRORMESSAGE
  291. Exit Function
  292. End if
  293. If isnull(objUserMaps.AdvancedUserMaps) Then
  294. NFS_GetUserMappings = ""
  295. Else
  296. NFS_GetUserMappings = join(objUserMaps.AdvancedUserMaps,"#")
  297. End If
  298. If Err.number <> 0 Then
  299. SA_ServeFailurePage L_SETTINGSRETRIEVFAILED_ERRORMESSAGE
  300. exit function
  301. End if
  302. Set objUserMaps = Nothing
  303. Else
  304. Dim oMapper
  305. Set oMapper = Server.CreateObject(SFU_ADMIN_MAPPER_WRAPPER)
  306. oMapper.Mode = 17 ' ENUM_ADVANCEDUSERMAPSFROMREGISTRY
  307. Dim strMaps
  308. strMaps = oMapper.ReadAdvancedMaps("localhost", 0) ' User maps
  309. If (CInt(oMapper.LastError) <> 0) Then
  310. SA_ServeFailurePage L_SETTINGSRETRIEVFAILED_ERRORMESSAGE
  311. Exit Function
  312. End If
  313. ' Cut off the trailing nulls.
  314. strMaps = Left(strMaps, InStr(strMaps, chr(0) & chr(0)) - 1)
  315. Dim rgMaps
  316. rgMaps = Split(strMaps, chr(0))
  317. If (UBound(rgMaps) >= 0) Then
  318. NFS_GetUserMappings = Join(rgMaps, "#")
  319. Else
  320. NFS_GetUserMappings = ""
  321. End If
  322. set oMapper = nothing
  323. End If
  324. End function
  325. '-------------------------------------------------------------------------
  326. 'Function name: NFS_GetGroupMappings
  327. 'Description: Gets the group Mappers from the WMI object
  328. 'Input Variables: None
  329. 'Output Variables: None
  330. 'Returns: group mappings
  331. 'Global Variables: None
  332. '
  333. '--------------------------------------------------------------------------
  334. Function NFS_GetGroupMappings(objSFUService)
  335. Err.Clear
  336. On Error Resume Next
  337. If (NFS_GetSFUVersion() < "2.2") Then
  338. Dim objGroupMaps
  339. 'get the setting object
  340. Set objGroupMaps = objSFUService.get("Mapper_Settings.KeyName='CurrentVersion'")
  341. If Err.number <> 0 Then
  342. SA_ServeFailurePage L_SETTINGSRETRIEVFAILED_ERRORMESSAGE
  343. Exit Function
  344. End if
  345. If isnull(objGroupMaps.AdvancedGroupMaps) Then
  346. NFS_GetGroupMappings = ""
  347. Else
  348. NFS_GetGroupMappings = join(objGroupMaps.AdvancedGroupMaps,"#")
  349. End If
  350. If Err.number <> 0 Then
  351. SA_ServeFailurePage L_SETTINGSRETRIEVFAILED_ERRORMESSAGE
  352. exit function
  353. End if
  354. Set objGroupMaps = Nothing
  355. Else
  356. Dim oMapper
  357. Set oMapper = Server.CreateObject(SFU_ADMIN_MAPPER_WRAPPER)
  358. oMapper.Mode = 18 ' ENUM_ADVANCEDGROUPMAPSFROMREGISTRY
  359. Dim strMaps
  360. strMaps = oMapper.ReadAdvancedMaps("localhost", 1) ' Group maps
  361. If (CInt(oMapper.LastError) <> 0) Then
  362. SA_ServeFailurePage L_SETTINGSRETRIEVFAILED_ERRORMESSAGE
  363. Exit Function
  364. End If
  365. ' Cut off the trailing nulls.
  366. strMaps = Left(strMaps, InStr(strMaps, chr(0) & chr(0)) - 1)
  367. Dim rgMaps
  368. rgMaps = Split(strMaps, chr(0))
  369. If (UBound(rgMaps) >= 0) Then
  370. NFS_GetGroupMappings = Join(rgMaps, "#")
  371. Else
  372. NFS_GetGroupMappings = ""
  373. End If
  374. set oMapper = nothing
  375. End If
  376. End function
  377. '-------------------------------------------------------------------------
  378. 'Function name: NFS_SetUserMappings
  379. 'Description: set the user Mappers from the WMI object
  380. 'Input Variables: None
  381. 'Output Variables: None
  382. 'Returns: True if no error else False
  383. 'Global Variables: None
  384. '
  385. '--------------------------------------------------------------------------
  386. Function NFS_SetUserMappings(objNFSService, arrUserMaps)
  387. Err.Clear
  388. On Error Resume Next
  389. NFS_SetUserMappings = False
  390. If (NFS_GetSFUVersion() < "2.2") Then
  391. Dim objUserMaps
  392. 'get the setting object
  393. Set objUserMaps = objNFSService.get("Mapper_Settings.KeyName='CurrentVersion'")
  394. If Err.number <> 0 Then
  395. SA_ServeFailurePage L_SETTINGSRETRIEVFAILED_ERRORMESSAGE
  396. Exit Function
  397. End if
  398. If (UBound(arrUserMaps) = -1) Then
  399. ReDim arrUserMaps(0)
  400. arrUserMaps(0) = ""
  401. End If
  402. objUserMaps.AdvancedUserMaps = arrUserMaps
  403. objUserMaps.put_()
  404. If Err.number <> 0 Then
  405. SetErrMsg L_UPDATEFAILED_ERRORMESSAGE
  406. exit function
  407. End if
  408. 'toggle read config
  409. If not NFS_ToggleReadConfig(objNFSService) Then
  410. SetErrMsg L_UPDATEFAILED_ERRORMESSAGE
  411. Exit Function
  412. End If
  413. NFS_SetUserMappings = True
  414. Set objUserMaps = Nothing
  415. Else
  416. Dim oMapper
  417. ' Create a map object used to write to the map. Notice it's different from
  418. ' the one read the map.
  419. Set oMapper = Server.CreateObject(SFU_ADMIN_MAPPER_WRAPPER)
  420. ' Manipulate the arrUserMaps
  421. Dim strUserMaps
  422. Dim strTmp
  423. Dim iSize
  424. strTmp = Join(arrUserMaps, chr(0))
  425. strUserMaps = strTmp & chr(0) & chr(0)
  426. iSize = len(strUserMaps) * 2
  427. Call oMapper.WriteAdvancedMaps("localhost", 0, strUserMaps, iSize) '0 is user map
  428. If (CInt(oMapper.LastError) <> 0) Then
  429. SA_ServeFailurePage L_SETTINGSRETRIEVFAILED_ERRORMESSAGE
  430. Exit Function
  431. End If
  432. If Err.number <> 0 Then
  433. SetErrMsg L_UPDATEFAILED_ERRORMESSAGE
  434. exit function
  435. End if
  436. 'toggle read config
  437. If not NFS_ToggleReadConfig(objNFSService) Then
  438. SetErrMsg L_UPDATEFAILED_ERRORMESSAGE
  439. Exit Function
  440. End If
  441. NFS_SetUserMappings = True
  442. Set oMapper = Nothing
  443. End If
  444. End function
  445. '-------------------------------------------------------------------------
  446. 'Function name: NFS_SetGroupMappings
  447. 'Description: set the group Mappers from the WMI object
  448. 'Input Variables: None
  449. 'Output Variables: None
  450. 'Returns: True if no error else False
  451. 'Global Variables: None
  452. '
  453. '--------------------------------------------------------------------------
  454. Function NFS_SetGroupMappings(objNFSService, arrGroupMaps)
  455. Err.Clear
  456. On Error Resume Next
  457. NFS_SetGroupMappings = False
  458. If (NFS_GetSFUVersion() < "2.2") Then
  459. Dim objGroupMaps
  460. 'get the setting object
  461. Set objGroupMaps = objNFSService.get("Mapper_Settings.KeyName='CurrentVersion'")
  462. If Err.number <> 0 Then
  463. SA_ServeFailurePage L_SETTINGSRETRIEVFAILED_ERRORMESSAGE
  464. Exit Function
  465. End if
  466. If (UBound(arrGroupMaps) = -1) Then
  467. ReDim arrGroupMaps(0)
  468. arrGroupMaps(0) = ""
  469. End If
  470. objGroupMaps.AdvancedGroupMaps = arrGroupMaps
  471. objGroupMaps.put_()
  472. If Err.number <> 0 Then
  473. SetErrMsg L_UPDATEFAILED_ERRORMESSAGE
  474. exit function
  475. End if
  476. 'toggle read config
  477. If not NFS_ToggleReadConfig(objNFSService) Then
  478. SetErrMsg L_UPDATEFAILED_ERRORMESSAGE
  479. Exit Function
  480. End If
  481. NFS_SetGroupMappings = True
  482. Set objGroupMaps = Nothing
  483. Else
  484. Dim oMapper
  485. ' Create a map object used to write to the map. Notice it's different from
  486. ' the one read the map.
  487. Set oMapper = Server.CreateObject(SFU_ADMIN_MAPPER_WRAPPER)
  488. ' Manipulate the arrUserMaps
  489. Dim strGroupMaps
  490. Dim strTmp
  491. Dim iSize
  492. strTmp = Join(arrGroupMaps, chr(0))
  493. strGroupMaps = strTmp & chr(0) & chr(0)
  494. iSize = len(strGroupMaps) * 2
  495. Call oMapper.WriteAdvancedMaps("localhost", 1, strGroupMaps, iSize) '1 is group map
  496. If (CInt(oMapper.LastError) <> 0) Then
  497. SA_ServeFailurePage L_SETTINGSRETRIEVFAILED_ERRORMESSAGE
  498. Exit Function
  499. End If
  500. If Err.number <> 0 Then
  501. SetErrMsg L_UPDATEFAILED_ERRORMESSAGE
  502. exit function
  503. End if
  504. 'toggle read config
  505. If not NFS_ToggleReadConfig(objNFSService) Then
  506. SetErrMsg L_UPDATEFAILED_ERRORMESSAGE
  507. Exit Function
  508. End If
  509. NFS_SetGroupMappings = True
  510. Set oMapper = Nothing
  511. End If
  512. End function
  513. '-------------------------------------------------------------------------
  514. 'Function name: NFS_ToggleReadConfig
  515. 'Description: the operation will cause the effect of config
  516. 'Input Variables: None
  517. 'Output Variables: None
  518. 'Returns: BOOL
  519. 'Global Variables: None
  520. '--------------------------------------------------------------------------
  521. Function NFS_ToggleReadConfig(objSFUService)
  522. on error resume next
  523. Err.Clear
  524. Dim objMapServerReg
  525. NFS_ToggleReadConfig = False
  526. 'Get the Settings object
  527. Set objMapServerReg = objSFUService.get("MapServer_Reg.KeyName='ReadConfig'")
  528. If Err.number <> 0 Then
  529. Call SA_TRACEOUT("inc_NFSSvc.asp","Toggle read faild")
  530. Exit Function
  531. End if
  532. 'Toggle the readconfig value
  533. If objMapServerReg.ReadConfig = "0" Then
  534. objMapServerReg.ReadConfig = "1"
  535. Else
  536. objMapServerReg.ReadConfig = "0"
  537. End If
  538. objMapServerReg.put_()
  539. 'Error handling
  540. If Err.number <> 0 Then
  541. Call SA_TRACEOUT("inc_NFSSvc.asp","Toggle read faild")
  542. Exit Function
  543. End If
  544. NFS_ToggleReadConfig = True
  545. Set objMapServerReg = Nothing
  546. End Function
  547. '-------------------------------------------------------------------------
  548. 'Function name: NFS_GetGroupIDs
  549. 'Description: Gets the Group IDs for the given user
  550. 'Input Variables: strGroupDet,strUser,strOuput
  551. 'Output Variables: None
  552. 'Returns: True/False
  553. 'Global Variables: IN:L_INVALIDFILEFORMATFORGROUP_ERRORMESSAGE
  554. '--------------------------------------------------------------------------
  555. Function NFS_GetGroupIDs(strGroupDet,strUser,strOuput)
  556. On Error Resume Next
  557. Err.Clear
  558. NFS_GetGroupIDs = False
  559. Dim arrGroups,strGID
  560. Dim strGrp,strUsr
  561. Dim arrStr1,arrStr2
  562. 'split the string at the newline char
  563. arrGroups = split(strGroupDet,chr(13)+chr(10))
  564. strGID =""
  565. For Each strGrp In arrGroups
  566. If strGrp <> "" Then
  567. 'split at ":" to get the users of the group
  568. arrStr1 = split(strGrp,":")
  569. 'check for the file format
  570. If Ubound(arrStr1) < 3 Then
  571. setErrMsg L_INVALIDFILEFORMATFORGROUP_ERRORMESSAGE
  572. Exit Function
  573. End If
  574. 'check for different users in the group
  575. arrStr2 = split(arrStr1(Ubound(arrStr1)),",")
  576. For Each strUsr In arrStr2
  577. If ucase(strUsr) = ucase(strUser) Then
  578. strGID = strGID +":" +arrStr1(Ubound(arrStr1)-1)
  579. End If
  580. Next
  581. ' go to next user
  582. End If
  583. Next
  584. 'go to next group
  585. strOuput = strGID
  586. NFS_GetGroupIDs = true
  587. End Function
  588. '-------------------------------------------------------------------------
  589. 'Function name: NFS_ReadUsersFromFile
  590. 'Description: read user account from user passwd file
  591. 'Input Variables: None
  592. 'Output Variables: None
  593. 'Returns: An string include all user account info
  594. 'Global Variables: None
  595. '--------------------------------------------------------------------------
  596. Function NFS_ReadUsersFromFile(userFile,groupFile)
  597. On Error Resume Next
  598. Err.clear
  599. Dim objFSO
  600. Dim objUserFile
  601. Dim objGroupFile
  602. Dim strGroupDet
  603. Dim strGID,strOutput,strTemp,arrValue
  604. Const ForReading = 1
  605. NFS_ReadUsersFromFile = ""
  606. Set objFSO = Server.CreateObject("Scripting.FileSystemobject")
  607. If Trim(userFile) = "" Or (Not objFSO.FileExists(userFile)) Then
  608. setErrMsg L_PASSWORDFILEMISSING_ERRORMESSAGE
  609. Exit Function
  610. End If
  611. If Trim(groupFile) = "" Or (Not objFSO.FileExists(groupFile)) Then
  612. setErrMsg L_GROUPFILEMISSING_ERRORMESSAGE
  613. Exit Function
  614. End If
  615. 'open the group file
  616. Set objGroupFile =objFSO.OpenTextFile(groupFile, ForReading)
  617. If Err <> 0 Then
  618. setErrMsg L_GROUPFILEOPEN_ERRORMESSAGE
  619. Exit Function
  620. End If
  621. 'read all its contents in to a string & close the file
  622. strGroupDet = objGroupFile.readAll()
  623. objGroupFile.Close
  624. 'open the password file
  625. Set objUserFile = objFSO.OpenTextFile(userFile,ForReading)
  626. If Err <> 0 Then
  627. setErrMsg L_PASSWORDFILEOPEN_ERRORMESSAGE
  628. Exit Function
  629. End If
  630. strOutput =""
  631. 'read till the end of file
  632. While Not objUserFile.atendofstream
  633. strTemp = objUserFile.readline()
  634. arrValue = split(strTemp,":")
  635. 'check for the format
  636. If Ubound(arrValue) < 6 Then
  637. setErrMsg L_INVALIDFILEFORMATFORPSWD_ERRORMESSAGE
  638. Exit Function
  639. End If
  640. 'get group id for the user
  641. If NFS_GetGroupIDs(strGroupDet,arrValue(0),strGID) then
  642. strOutput = strOutput & arrValue(0) &":"& arrValue(1)& _
  643. ":" & arrValue(2) & ":" & arrValue(3) & ":" & _
  644. strGID + "#" 'used by option
  645. else
  646. setErrMsg L_INVALIDFILEFORMATFORGROUP_ERRORMESSAGE
  647. exit Function
  648. end if
  649. wend
  650. 'close the file
  651. objUserFile.Close
  652. NFS_ReadUsersFromFile = Left(strOutput,len(strOutput)-1)
  653. Set objFSO = Nothing
  654. End Function
  655. '-------------------------------------------------------------------------
  656. 'Function name: NFS_ReadGroupsFromFile
  657. 'Description: read group account from user group file
  658. 'Input Variables: None
  659. 'Output Variables: None
  660. 'Returns: An string include all user account info
  661. 'Global Variables: None
  662. '--------------------------------------------------------------------------
  663. Function NFS_ReadGroupsFromFile(groupFile)
  664. On Error Resume Next
  665. Err.Clear
  666. Dim objFSO ' the file system object
  667. Dim objGroupFile ' the file to be read
  668. Dim strTemp ' temporary variable
  669. Dim arrValue ' to store the split string
  670. Dim strOutput ' the final output to print
  671. Const ForReading = 1
  672. NFS_ReadGroupsFromFile = ""
  673. Set objFSO = Server.CreateObject(FILE_SYSTEM_OBJECT)
  674. ' check if file is existing
  675. If Trim(groupFile) = "" OR (NOT objFSO.FileExists(groupFile)) Then
  676. SetErrMsg L_GROUPFILEMISSING_ERRORMESSAGE
  677. Exit Function
  678. End If
  679. Set objGroupFile = objFSO.OpenTextFile(groupFile,ForReading)
  680. If Err.number <> 0 Then
  681. SetErrMsg L_GROUPFILEOPEN_ERRORMESSAGE
  682. Exit Function
  683. End If
  684. strOutput =""
  685. 'read till the end of file
  686. While NOT objGroupFile.atendofstream
  687. strTemp = objGroupFile.readline()
  688. If strTemp <> "" Then
  689. arrValue = split(strTemp,":")
  690. 'check for the format
  691. If Ubound(arrValue) < 3 Then
  692. SetErrMsg L_INVALIDFILEFORMATFORGROUP_ERRORMESSAGE
  693. Exit Function
  694. End If
  695. ' prepare the options...
  696. strOutput = strOutput & arrValue(0) & ":" & arrValue(2) & "#"
  697. End If
  698. Wend
  699. 'end for the file end
  700. 'close file
  701. objGroupFile.close
  702. NFS_ReadGroupsFromFile = Left(strOutput,len(strOutput)-1)
  703. Set objGroupFile = Nothing
  704. Set objFSO = Nothing
  705. End Function
  706. '-------------------------------------------------------------------------
  707. 'Function name: NFS_GetNTDomainUsers
  708. 'Description: Function for to get the Users of the domain
  709. 'Input Variables: strDomain
  710. 'Output Variables: None
  711. 'Returns: True if service is started else false
  712. 'Global Variables: None
  713. '--------------------------------------------------------------------------
  714. Function NFS_GetNTDomainUsers(strDomain)
  715. On Error Resume Next
  716. Err.Clear
  717. Dim objNISMapper ' the mapper object
  718. Dim nObjCount ' number of groups in the domain
  719. Dim nIndex ' used in the loop
  720. Dim strOutput
  721. Const ENUM_NTUSERS = 1
  722. NFS_GetNTDomainUsers = ""
  723. Set objNISMapper = Server.CreateObject(SFU_ADMIN_MAPPER_WRAPPER)
  724. objNISMapper.NTDomain = strDomain
  725. objNISMapper.LoadNTUserListAsync
  726. ' Wait infinitely until the process of getting the users list is done.
  727. do while objNISMapper.done = 0
  728. loop
  729. ' enum NT users
  730. objNISMapper.Mode = ENUM_NTUSERS
  731. objNISMapper.moveFirst()
  732. nObjCount = objNISMapper.EnumCount
  733. strOutput = ""
  734. ' add new elements
  735. For nIndex = 0 To nObjCount-1
  736. ' get rid of the "None" group that we get on every NT box
  737. If LCase(objNISMapper.EnumValue) = "none" Then
  738. objNISMapper.moveNext()
  739. Else
  740. strOutput = strOutput + strDomain & ":" & objNISMapper.EnumValue & _
  741. "#"
  742. objNISMapper.moveNext()
  743. End If
  744. Next
  745. NFS_GetNTDomainUsers = Left(strOutput,len(strOutput)-1)
  746. Set objNISMapper = Nothing
  747. End Function
  748. '-------------------------------------------------------------------------
  749. 'Function name: NFS_GetNTDomainGroups
  750. 'Description: Function for to get the Groups of the domain
  751. 'Input Variables: strDomain
  752. 'Output Variables: None
  753. 'Returns: True if service is started else false
  754. 'Global Variables: None
  755. '--------------------------------------------------------------------------
  756. Function NFS_GetNTDomainGroups(strDomain)
  757. On Error Resume Next
  758. Err.Clear
  759. Dim objMapper ' the mapper object
  760. Dim nObjCount ' number of groups in the domain
  761. Dim nIndex ' used in the loop
  762. Dim strOutput
  763. NFS_GetNTDomainGroups = ""
  764. Set objMapper = Server.CreateObject(SFU_ADMIN_MAPPER_WRAPPER)
  765. objMapper.NTDomain = strDomain
  766. objMapper.LoadNTGroupListAsync()
  767. If Err.number <> 0 Then
  768. SA_ServeFailurePage L_CREATEOBJECTFAILED_ERRORMESSAGE
  769. End If
  770. ' sleeping for a while till it Load the groups
  771. Do While objMapper.Done = 0
  772. Loop
  773. ' enum NT groups
  774. objMapper.Mode = ENUM_NTGROUPS
  775. objMapper.moveFirst()
  776. nObjCount = objMapper.EnumCount
  777. strOutput = ""
  778. ' add new elements
  779. For nIndex = 0 To nObjCount-1
  780. ' get rid of the "None" group that we get on every NT box
  781. If LCase(objMapper.EnumValue) = "none" Then
  782. objMapper.moveNext()
  783. Else
  784. strOutput = strOutput & strDomain & ":" & objMapper.EnumValue & "#"
  785. objMapper.moveNext()
  786. End If
  787. Next
  788. NFS_GetNTDomainGroups = Left(strOutput,len(strOutput)-1)
  789. Set objMapper = Nothing
  790. End Function
  791. '-------------------------------------------------------------------------
  792. 'Function name: NFS_GetNISDomainUsers
  793. 'Description: Function for Getting NIS DOmain Users
  794. 'Input Variables: strNISDomainName, strNISServer
  795. 'Output Variables: None
  796. 'Returns: Displays the Users in the list box
  797. 'Global Variables: In:L_CREATEOBJECTFAILED_ERRORMESSAGE
  798. ' In:L_NISDOMAINDOESNOTEXIST_ERRORMESSAGE
  799. '--------------------------------------------------------------------------
  800. Function NFS_GetNISDomainUsers(strNISDomainName, strNISServer)
  801. on error resume next
  802. Err.Clear
  803. Dim objNISMapper
  804. Dim intCount
  805. Dim inttmp
  806. Dim LastError
  807. Dim strOutput
  808. Const ENUM_NISUSER =3
  809. NFS_GetNISDomainUsers = ""
  810. ' first validate the NIS domain
  811. If NOT isValidNISServer(strNISDomainName,strNISServer,LastError) Then
  812. SetErrMsg L_NISDOMAINDOESNOTEXIST_ERRORMESSAGE
  813. Exit Function
  814. End If
  815. 'Get the instance of the Mapper Class
  816. Set objNISMapper = server.CreateObject(SFU_ADMIN_MAPPER_WRAPPER)
  817. 'If any Error in creating the Object
  818. If Err.number <> 0 Then
  819. SA_ServeFailurePage L_CREATEOBJECTFAILED_ERRORMESSAGE
  820. Exit Function
  821. End If
  822. ' Set the NIS domain & Server properties for the object
  823. objNISMapper.NisDomain = strNISDomainName
  824. objNISMapper.NisServer = strNISServer
  825. ' Call the function to get the NIS users from the NIS Server
  826. objNISMapper.LoadNisUserListAsync
  827. ' Wait infinitely until the process of getting the users list is done.
  828. do while objNISMapper.done = 0
  829. loop
  830. ' Check if the Mapper has given some error
  831. If cstr(objNISMapper.lastError) <> "0" Then
  832. SetErrMsg L_NISDOMAINDOESNOTEXIST_ERRORMESSAGE
  833. Exit Function
  834. End If
  835. 'Set the mode to the to the NIS user
  836. objNISMapper.mode = ENUM_NISUSER
  837. 'Go to the first NIS user in the array
  838. objNISMapper.movefirst
  839. 'Get the count of the users
  840. intCount = objNISMapper.enumcount
  841. strOutput = ""
  842. For inttmp = 0 to intCount
  843. strOutput = strOutput & objNISMapper.EnumValue&"#"
  844. objNISMapper.moveNext
  845. Next
  846. 'End for the loop to display of NIS users
  847. NFS_GetNISDomainUsers = Left(strOutput,len(strOutput)-1)
  848. Set objNISMapper = nothing
  849. End Function
  850. '-------------------------------------------------------------------------
  851. 'Function name: NFS_GetNISDomainGroups
  852. 'Description: Function for Getting NIS DOmain Users
  853. 'Input Variables: strNISDomainName, strNISServer
  854. 'Output Variables: None
  855. 'Returns: Displays the Users in the list box
  856. 'Global Variables: In:L_CREATEOBJECTFAILED_ERRORMESSAGE
  857. ' In:L_NISDOMAINDOESNOTEXIST_ERRORMESSAGE
  858. '--------------------------------------------------------------------------
  859. Function NFS_GetNISDomainGroups(strNISDomainName, strNISServer)
  860. on error resume next
  861. Err.Clear
  862. Dim objNISMapper
  863. Dim intCount
  864. Dim inttmp
  865. Dim LastError
  866. Dim strOutput
  867. Const ENUM_NISGROUPS = 4
  868. NFS_GetNISDomainGroups = ""
  869. ' first validate the NIS domain
  870. If NOT isValidNISServer(strNISDomainName,strNISServer,LastError) Then
  871. SetErrMsg L_NISDOMAINDOESNOTEXIST_ERRORMESSAGE
  872. Exit Function
  873. End If
  874. 'Get the instance of the Mapper Class
  875. Set objNISMapper = server.CreateObject(SFU_ADMIN_MAPPER_WRAPPER)
  876. 'If any Error in creating the Object
  877. If Err.number <> 0 Then
  878. SA_ServeFailurePage L_CREATEOBJECTFAILED_ERRORMESSAGE
  879. Exit Function
  880. End If
  881. ' Set the NIS domain & Server properties for the object
  882. objNISMapper.NisDomain = strNISDomainName
  883. objNISMapper.NisServer = strNISServer
  884. ' Call the function to get the NIS groups from the NIS Server
  885. objNISMapper.LoadNisGroupListAsync
  886. ' Wait infinitely until the process of getting the users list is done.
  887. Do While objNISMapper.done = 0
  888. Loop
  889. ' Check if the Mapper has given some error
  890. If cstr(objNISMapper.lastError) <> "0" Then
  891. SetErrMsg L_NISDOMAINDOESNOTEXIST_ERRORMESSAGE
  892. Exit Function
  893. End If
  894. 'Set the mode to the to the NIS group
  895. objNISMapper.mode = ENUM_NISGROUPS
  896. 'Go to the first NIS user in the array
  897. objNISMapper.movefirst
  898. 'get the count of the users
  899. intCount = objNISMapper.enumcount
  900. strOutput = ""
  901. For inttmp = 0 to intCount
  902. strOutput = strOutput&objNISMapper.EnumValue&"#"
  903. objNISMapper.moveNext
  904. Next
  905. ' clean up
  906. NFS_GetNISDomainGroups = Left(strOutput,len(strOutput)-1)
  907. Set objNISMapper = Nothing
  908. End Function
  909. '-------------------------------------------------------------------------
  910. 'Function name: NFS_CreateGroup
  911. 'Description: Create a new NFS Client group
  912. 'Input Variables: strGroupName
  913. 'Output Variables: None
  914. 'Returns: CONST_SUCESS for Sucess
  915. ' CONST_GROUP_EXISTS for Exists
  916. ' CONST_UNSPECIFIED_ERROR for Unspecified Error
  917. 'Global Variables: None
  918. '
  919. '--------------------------------------------------------------------------
  920. Function NFS_CreateGroup( strGroupName )
  921. 'On Error Resume Next
  922. Dim nRetValue
  923. nRetValue = NFSClientGroupsAtCmdLine ( "creategroup " & chr(34) & strGroupName & chr(34) )
  924. NFS_CreateGroup = nRetValue
  925. End Function
  926. '-------------------------------------------------------------------------
  927. 'Function name: NFS_DeleteGroup
  928. 'Description: Delete NFS Client group
  929. 'Input Variables: strGroupName
  930. 'Output Variables: None
  931. 'Returns: CONST_SUCESS for Sucess
  932. ' CONST_NOT_EXISTS for Not Exists
  933. ' CONST_UNSPECIFIED_ERROR for Unspecified Error
  934. 'Global Variables: None
  935. '
  936. '--------------------------------------------------------------------------
  937. Function NFS_DeleteGroup( strGroupName )
  938. 'On Error Resume Next
  939. Dim nRetValue
  940. nRetValue = NFSClientGroupsAtCmdLine ( "deletegroup " & chr(34) & strGroupName & chr(34) )
  941. NFS_DeleteGroup = nRetValue
  942. End Function
  943. '-------------------------------------------------------------------------
  944. 'Function name: NFS_EnumGroups
  945. 'Description: Enumerate existing NFS groups in system
  946. 'Input Variables: None
  947. 'Output Variables: None
  948. 'Returns: CONST_SUCESS for Sucess
  949. ' CONST_NOT_EXISTS for Not Exists
  950. ' CONST_UNSPECIFIED_ERROR for Unspecified Error
  951. 'Global Variables: None
  952. '
  953. '--------------------------------------------------------------------------
  954. Function NFS_EnumGroups( )
  955. 'On Error Resume Next
  956. Dim nRetValue
  957. NFS_EnumGroups = ""
  958. nRetValue = NFSClientGroupsAtCmdLine ( "listgroups " )
  959. If nRetValue = CONST_NO_CLIENT_GROUPS Then
  960. NFS_EnumGroups = ""
  961. End If
  962. ' chr(1) delimeted
  963. NFS_EnumGroups = g_strGroups
  964. 'NFS_EnumGroups = nRetValue
  965. End Function
  966. '-------------------------------------------------------------------------
  967. 'Function name: NFS_ListMembersInGroup
  968. 'Description: List members in NFS group
  969. 'Input Variables: IN: strGroupName
  970. 'Output Variables: None
  971. 'Returns: CONST_SUCCESS for Sucess
  972. ' CONST_MEMBER_EXISTS for Already Exists
  973. ' CONST_INVALID_MEMBER for Not a Valid Member
  974. ' CONST_INVALID_GROUP for Not a Valid Group
  975. ' CONST_UNSPECIFIED_ERROR for Unspecified Error
  976. 'Global Variables: None
  977. '
  978. '--------------------------------------------------------------------------
  979. Function NFS_ListMembersInGroup( strGroupName )
  980. 'On Error Resume Next
  981. Dim nRetValue
  982. nRetValue = NFSClientGroupsAtCmdLine ( "listmembers " & chr(34) & strGroupName & chr(34) )
  983. If nRetValue = CONST_NO_MEMBERS Then
  984. NFS_ListMembersInGroup = ""
  985. End If
  986. if nRetValue = CONST_SUCCESS Then
  987. NFS_ListMembersInGroup = g_strMembers
  988. End If
  989. End Function
  990. '-------------------------------------------------------------------------
  991. 'Function name: NFS_IsValidGroup
  992. 'Description: Check if the group is Valid
  993. 'Input Variables: IN: strGroupName
  994. 'Output Variables: None
  995. 'Returns: CONST_SUCCESS for Sucess
  996. ' CONST_MEMBER_EXISTS for Already Exists
  997. ' CONST_INVALID_MEMBER for Not a Valid Member
  998. ' CONST_INVALID_GROUP for Not a Valid Group
  999. ' CONST_UNSPECIFIED_ERROR for Unspecified Error
  1000. 'Global Variables: None
  1001. '
  1002. '--------------------------------------------------------------------------
  1003. Function NFS_IsValidGroup( strGroupName )
  1004. 'On Error Resume Next
  1005. Dim nRetValue
  1006. nRetValue = NFSClientGroupsAtCmdLine ( "listmembers " & chr(34) & strGroupName & chr(34) )
  1007. If nRetValue = CONST_NO_MEMBERS Then
  1008. nRetValue = CONST_SUCCESS
  1009. End If
  1010. NFS_IsValidGroup = nRetValue
  1011. End Function
  1012. '-------------------------------------------------------------------------
  1013. 'Function name: NFS_AddMembersToGroup
  1014. 'Description: Add a list of comma delimeted members to NFS client
  1015. ' Group
  1016. 'Input Variables: IN: strGroupName
  1017. ' IN: strMembers
  1018. 'Output Variables: None
  1019. 'Returns: CONST_SUCCESS for Sucess
  1020. ' CONST_MEMBER_EXISTS for Already Exists
  1021. ' CONST_INVALID_MEMBER for Not a Valid Member
  1022. ' CONST_INVALID_GROUP for Not a Valid Group
  1023. ' CONST_UNSPECIFIED_ERROR for Unspecified Error
  1024. 'Global Variables: None
  1025. '
  1026. '--------------------------------------------------------------------------
  1027. Function NFS_AddMembersToGroup( strGroupName, strMembersToAdd )
  1028. 'On Error Resume Next
  1029. Dim nRetValue
  1030. nRetValue = NFSClientGroupsAtCmdLine ( "addmembers " & chr(34) & strGroupName & chr(34) & " " & strMembersToAdd )
  1031. NFS_AddMembersToGroup = nRetValue
  1032. End Function
  1033. '-------------------------------------------------------------------------
  1034. 'Function name: NFS_DeleteMembersFromGroup
  1035. 'Description: Remove members from NFS client group
  1036. ' Group
  1037. 'Input Variables: IN: strGroupName
  1038. ' IN: strMembers
  1039. 'Output Variables: None
  1040. 'Returns: CONST_SUCCESS for Sucess
  1041. ' CONST_EXISTS for Already Exists
  1042. ' CONST_INVALID_MEMBER for Not a Valid Member
  1043. ' CONST_INVALID_GROUP for Not a Valid Group
  1044. ' CONST_UNSPECIFIED_ERROR for Unspecified Error
  1045. 'Global Variables: None
  1046. '
  1047. '--------------------------------------------------------------------------
  1048. Function NFS_DeleteMembersFromGroup( strGroupName, strMembersToDelete )
  1049. 'On Error Resume Next
  1050. Dim nRetValue
  1051. nRetValue = NFSClientGroupsAtCmdLine ( "deletemembers " & chr(34) & strGroupName & chr(34) & " " & strMembersToDelete )
  1052. NFS_DeleteMembersFromGroup = nRetValue
  1053. End Function
  1054. '-------------------------------------------------------------------------
  1055. ' Function name: LaunchProcess
  1056. ' Description: Setting the launch process
  1057. ' Input Variables: strCommand,strCurDir
  1058. ' Output Variables: None
  1059. ' Returns: TRUE/FALSE on Success/Failure
  1060. ' Global Variables: None
  1061. '-------------------------------------------------------------------------
  1062. Function LaunchProcess(strCommand, strCurDir)
  1063. Err.Clear
  1064. On error Resume Next
  1065. Dim objProcess
  1066. Dim objService,objClass,objProc,objProcStartup
  1067. Dim objCollection
  1068. Dim nretval
  1069. Dim nPID
  1070. Dim i
  1071. Dim strHandle
  1072. strHandle = ""
  1073. LaunchProcess = True
  1074. nretval = 0
  1075. Set objService=getWMIConnection(CONST_WMI_WIN32_NAMESPACE)
  1076. Set objClass = objService.Get("Win32_ProcessStartup")
  1077. Set objProcStartup = objClass.SpawnInstance_()
  1078. objProcStartup.ShowWindow = 2
  1079. Set objProc = objService.Get("Win32_Process")
  1080. nretval = objProc.Create(strCommand, strCurDir, objProcStartup,nPID)
  1081. Set objProcess = CreateObject("COMhelper.SystemSetting")
  1082. Set objCollection = objService.ExecQuery( _
  1083. "Select * from win32_Process where ProcessId="&nPID )
  1084. ' Check for existence of ProcessID, otherwise Sleep until the process exits
  1085. Do While objCollection.Count > 0
  1086. ' Sleep for 2 Sec
  1087. Call objProcess.Sleep ( 2000 )
  1088. Set objCollection = objService.ExecQuery( _
  1089. "Select * from win32_Process where ProcessId="&nPID )
  1090. Loop
  1091. If Err.number <> 0 Then
  1092. nretval=-1
  1093. LaunchProcess = nretval
  1094. Exit function
  1095. End If
  1096. LaunchProcess = nretval
  1097. 'clean up
  1098. Set objProc = Nothing
  1099. Set objProcStartup = Nothing
  1100. Set objClass = Nothing
  1101. Set objService = Nothing
  1102. Set objProcess = Nothing
  1103. Set objCollection = Nothing
  1104. If Err.number <> 0 Then
  1105. LaunchProcess = False
  1106. End If
  1107. End Function
  1108. '-------------------------------------------------------------------------
  1109. ' Function name: NFSClientGroupsAtCmdLine
  1110. ' Description: Creation/Deletion of Shares thru Cmd line
  1111. ' Input Variables: strCommand, strShareType
  1112. ' Output Variables: None
  1113. ' Returns: TRUE/FALSE on success/Failure
  1114. ' Global Variables: None
  1115. ' Forming the Command Line command and launching the command line utility
  1116. ' for NFS, APPLETALK and NETWARE Shares
  1117. '-------------------------------------------------------------------------
  1118. Function NFSClientGroupsAtCmdLine(strCommand)
  1119. 'Err.clear
  1120. 'On Error Resume Next
  1121. Dim strCurDir
  1122. Dim objFso
  1123. Dim strFilePath
  1124. Dim retVal
  1125. 'initialize
  1126. strCurDir=GetNFSAdminPath()
  1127. strFilePath = GetSystemDrive & "\nfsadmin.txt"
  1128. strCommand = "cmd.exe /c " & "nfsadmin.exe server " & strCommand & " > " & strFilePath
  1129. If Not LaunchProcess(strCommand, strCurDir)Then
  1130. NFSClientGroupsAtCmdLine = CONST_UNSPECIFIED_ERROR
  1131. End If
  1132. ' processs
  1133. retVal = ParseOutputFromCmd( strFilePath )
  1134. NFSClientGroupsAtCmdLine = retVal
  1135. End Function
  1136. '-------------------------------------------------------------------------
  1137. 'Function: GetNFSAdminPath()
  1138. 'Description: To get the path for
  1139. 'Input Variables: None
  1140. 'Output Variables: None
  1141. 'Returns: Operating system path
  1142. 'Global Variables: None
  1143. '-------------------------------------------------------------------------
  1144. Function GetNFSAdminPath()
  1145. On Error Resume Next
  1146. Err.Clear
  1147. Dim objOS 'Create instance of Win32_OperatingSystem
  1148. Dim objOSInstance
  1149. Dim strSystemPath 'OS path
  1150. Dim objConnection 'Connection to WMI
  1151. Dim strQuery 'Query string
  1152. strQuery = "Select * from Win32_OperatingSystem"
  1153. 'Connection to WMI
  1154. set objConnection = getWMIConnection(CONST_WMI_WIN32_NAMESPACE)
  1155. 'Error message incase faield to connect to WMI
  1156. If Err.number<>0 then
  1157. Call SA_ServeFailurePageEx(L_FAILEDTOGETWMICONNECTION_ERRORMESSAGE,mstrReturnURL)
  1158. GetNFSAdminPath=""
  1159. Exit Function
  1160. End if
  1161. 'Execute Query
  1162. Set objOS = objConnection.ExecQuery(strQuery)
  1163. 'Get OS installed path
  1164. For Each objOSInstance in objOS
  1165. strSystemPath = objOSInstance.SystemDirectory
  1166. Next
  1167. Set objOS = Nothing
  1168. Set objOSInstance = Nothing
  1169. Set objConnection = Nothing
  1170. GetNFSAdminPath = strSystemPath
  1171. End Function
  1172. '-------------------------------------------------------------------------
  1173. 'Function name: HandleError
  1174. 'Description: Set the appropriate error message.
  1175. 'Input Variables: IN: nRetValue
  1176. 'Output Variables: None
  1177. 'Returns: None
  1178. '-------------------------------------------------------------------------
  1179. Function HandleError( nRetValue )
  1180. Dim aRepStrings(1)
  1181. aRepStrings(0) = g_strMemberAtFault
  1182. HandleError = False
  1183. Select Case nRetValue
  1184. Case CONST_SUCCESS
  1185. HandleError = True
  1186. Case CONST_UNSPECIFIED_ERROR
  1187. SA_SetErrMsg( L_UNSPECIFIED_ERROR)
  1188. Case CONST_GROUP_EXISTS
  1189. SA_SetErrMsg( L_GROUPEXISTS_ERRORMESSAGE )
  1190. Case CONST_GROUP_NOT_EXISTS
  1191. SA_SetErrMsg( L_GROUPNOTEXISTS_ERRORMESSAGE )
  1192. Case CONST_INVALID_MEMBER
  1193. Call SA_SetErrMsg(SA_GetLocString(LOC_FILE, "C0370082", aRepStrings))
  1194. Case CONST_INVALID_GROUP
  1195. Call SA_SetErrMsg(SA_GetLocString(LOC_FILE, "C0370091", aRepStrings))
  1196. Case CONST_MEMBER_EXISTS
  1197. Call SA_SetErrMsg(SA_GetLocString(LOC_FILE, "C0370092", aRepStrings))
  1198. Case CONST_MEMBER_NOT_EXISTS
  1199. Call SA_SetErrMsg(SA_GetLocString(LOC_FILE, "C0370093", aRepStrings))
  1200. Case CONST_INVALID_MACHINE
  1201. Call SA_SetErrMsg(SA_GetLocString(LOC_FILE, "C0370142", aRepStrings))
  1202. Case CONST_NO_CLIENT_GROUPS
  1203. SA_SetErrMsg( L_NO_CLIENT_GROUPS)
  1204. Case CONST_NO_MEMBERS
  1205. SA_SetErrMsg( L_NO_MEMBERS )
  1206. Case else
  1207. SA_SetErrMsg( L_UNSPECIFIED_ERROR )
  1208. End Select
  1209. End Function
  1210. '-------------------------------------------------------------------------
  1211. 'Function name: GetSystemDrive
  1212. 'Description: Returns the windows boot drive
  1213. 'Input Variables: None
  1214. 'Output Variables: STRING Example: "C:" or "D:"
  1215. 'Returns: None
  1216. '-------------------------------------------------------------------------
  1217. Function GetSystemDrive
  1218. Dim objFso
  1219. Set objFso = Server.CreateObject("Scripting.FileSystemObject")
  1220. GetSystemDrive = objFso.GetSpecialFolder(0).Drive
  1221. End Function
  1222. '-------------------------------------------------------------------------
  1223. 'Function name: DeleteTemporaryFile
  1224. 'Description: Deletes Temporary file that was created to capture output
  1225. ' from nfsadmin cmd line tool.
  1226. 'Input Variables: IN: STRING strFilePath
  1227. 'Output Variables: None
  1228. 'Returns: None
  1229. '-------------------------------------------------------------------------
  1230. Sub DeleteTemporaryFile( strFilePath )
  1231. Dim objFso
  1232. Set objFso = Server.CreateObject("Scripting.FileSystemObject")
  1233. objFso.DeleteFile( strFilePath )
  1234. End Sub
  1235. '-------------------------------------------------------------------------
  1236. 'Function name: ParseOutputFromCmd
  1237. 'Description: This function parses the text returned from nfsadmin
  1238. ' cmd line tool.
  1239. 'Input Variables: IN: STRING strFilePath
  1240. 'Output Variables: None
  1241. 'Returns: None
  1242. '-------------------------------------------------------------------------
  1243. Function ParseOutputFromCmd( strFilePath )
  1244. Err.Clear
  1245. On Error Resume Next
  1246. Dim objFso
  1247. Dim objFile
  1248. Dim strLine
  1249. Dim iErrMsg
  1250. Dim arrMember
  1251. Dim nMemberFault
  1252. ParseOutputFromCmd = CONST_SUCCESS
  1253. Set objFso = Server.CreateObject("Scripting.FileSystemObject")
  1254. Set objFile = objFso.OpenTextFile(strFilePath)
  1255. Do While Not objFile.AtEndofStream
  1256. strLine = ""
  1257. strLine = objFile.ReadLine
  1258. If strLine <> "" Then
  1259. If Instr( 1, strLine, CONST_LIST_MEMBERS, 0 ) > 0 Then
  1260. Call ParseListMembers( objFile, strLine )
  1261. End If
  1262. If strLine = CONST_LIST_GROUPS Then
  1263. Call ParseListGroup( objFile, strLine )
  1264. Else
  1265. For iErrMsg = 0 to CONST_MAX_MSGS - 1
  1266. If Instr( 1, strLine, g_arrOutputMsgs( iErrMsg, 0 ), 0 ) > 0 Then
  1267. Call ParseAndPickFirstError( strLine, iErrMsg )
  1268. ParseOutputFromCmd = g_arrOutputMsgs( iErrMsg, 1 )
  1269. 'Close and Delete
  1270. objFile.close
  1271. objFso.DeleteFile( strFilePath )
  1272. Exit Function
  1273. End if
  1274. Next
  1275. End If
  1276. End If
  1277. Loop
  1278. 'close the file
  1279. objFile.close
  1280. objFso.DeleteFile( strFilePath )
  1281. Set objFile = Nothing
  1282. Set objFso = Nothing
  1283. End Function
  1284. '-------------------------------------------------------------------------
  1285. 'Function name: ParseListGroup
  1286. 'Description:
  1287. 'Input Variables: IN:
  1288. 'Output Variables: None
  1289. 'Returns: None
  1290. '-------------------------------------------------------------------------
  1291. Sub ParseListGroup( objFile, strLine )
  1292. g_strGroups = ""
  1293. Do While Not objFile.AtEndofStream
  1294. strLine = objFile.ReadLine
  1295. g_strGroups = g_strGroups + strLine + chr(1)
  1296. Loop
  1297. End Sub
  1298. '-------------------------------------------------------------------------
  1299. 'Function name: ParseListMembers
  1300. 'Description:
  1301. 'Input Variables: IN:
  1302. 'Output Variables: None
  1303. 'Returns: None
  1304. '-------------------------------------------------------------------------
  1305. Sub ParseListMembers( objFile, strLine )
  1306. g_strMembers = ""
  1307. Do While Not objFile.AtEndofStream
  1308. strLine = objFile.ReadLine
  1309. if strLine <> "" Then
  1310. g_strMembers = g_strMembers + strLine + ","
  1311. End If
  1312. Loop
  1313. End Sub
  1314. '-------------------------------------------------------------------------
  1315. 'Function name: ParseAndPickFirstError
  1316. 'Description:
  1317. 'Input Variables: IN:
  1318. 'Output Variables: None
  1319. 'Returns: None
  1320. '-------------------------------------------------------------------------
  1321. Sub ParseAndPickFirstError( strLine, iErrMsg )
  1322. Dim nMemberFault
  1323. Dim arrMember
  1324. nMemberFault = g_arrOutputMsgs( iErrMsg, 1 )
  1325. If ( (nMemberFault = CONST_MEMBER_EXISTS ) Or _
  1326. (nMemberFault = CONST_INVALID_MACHINE )Or _
  1327. ( nMemberFault = CONST_INVALID_MEMBER ) Or _
  1328. ( nMemberFault = CONST_INVALID_GROUP ) Or _
  1329. ( nMemberFault = CONST_MEMBER_NOT_EXISTS ) ) Then
  1330. arrMember = split( strLine, " " )
  1331. g_strMemberAtFault = arrMember(0)
  1332. End If
  1333. End Sub
  1334. %>