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.

613 lines
14 KiB

  1. -- Script: uddi.net.admin.sql
  2. -- Author: [email protected]
  3. -- Description: Administrative stored procedures
  4. -- Note: This file is best viewed and edited with a tab width of 2.
  5. -- =============================================
  6. -- Section: Publisher administration
  7. -- =============================================
  8. -- =============================================
  9. -- Name: ADM_findPublisher
  10. -- =============================================
  11. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ADM_findPublisher' AND type = 'P')
  12. DROP PROCEDURE ADM_findPublisher
  13. GO
  14. CREATE PROCEDURE ADM_findPublisher
  15. @email nvarchar(450) = NULL,
  16. @name nvarchar(450) = NULL,
  17. @companyName nvarchar(100) = NULL
  18. WITH ENCRYPTION
  19. AS
  20. BEGIN
  21. DECLARE
  22. @RC int,
  23. @error int,
  24. @context nvarchar(4000),
  25. @contextID uniqueidentifier,
  26. @rows int
  27. SET @contextID = NEWID()
  28. -- Check parameters
  29. IF (@email IS NULL) AND (@name IS NULL) AND (@companyName IS NULL)
  30. BEGIN
  31. SET @error=50009 -- E_parmError
  32. SET @context='At least one non-null parameter must be supplied.'
  33. GOTO errorLabel
  34. END
  35. IF @email IS NOT NULL
  36. BEGIN
  37. EXEC @RC=net_find_publisher_email @contextID, @email, @rows OUTPUT
  38. IF @RC<>0
  39. BEGIN
  40. SET @error=50006 -- E_subProcFailure
  41. SET @context=''
  42. GOTO errorLabel
  43. END
  44. IF @rows = 0
  45. BEGIN
  46. EXEC @RC=net_find_publisher_cleanup @contextID
  47. IF @RC<>0
  48. BEGIN
  49. SET @error=50006 -- E_subProcFailure
  50. SET @context=''
  51. GOTO errorLabel
  52. END
  53. RETURN 0
  54. END
  55. END
  56. IF @name IS NOT NULL
  57. BEGIN
  58. EXEC @RC=net_find_publisher_name @contextID, @name, @rows OUTPUT
  59. IF @RC<>0
  60. BEGIN
  61. SET @error=50006 -- E_subProcFailure
  62. SET @context=''
  63. GOTO errorLabel
  64. END
  65. IF @rows = 0
  66. BEGIN
  67. EXEC @RC=net_find_publisher_cleanup @contextID
  68. IF @RC<>0
  69. BEGIN
  70. SET @error=50006 -- E_subProcFailure
  71. SET @context=''
  72. GOTO errorLabel
  73. END
  74. RETURN 0
  75. END
  76. END
  77. IF @companyName IS NOT NULL
  78. BEGIN
  79. EXEC @RC=net_find_publisher_companyName @contextID, @companyName, @rows OUTPUT
  80. IF @RC<>0
  81. BEGIN
  82. SET @error=50006 -- E_subProcFailure
  83. SET @context=''
  84. GOTO errorLabel
  85. END
  86. IF @rows = 0
  87. BEGIN
  88. EXEC @RC=net_find_publisher_cleanup @contextID
  89. IF @RC<>0
  90. BEGIN
  91. SET @error=50006 -- E_subProcFailure
  92. SET @context=''
  93. GOTO errorLabel
  94. END
  95. RETURN 0
  96. END
  97. END
  98. EXEC @RC=net_find_publisher_commit @contextID = @contextID, @sortByNameAsc = 1, @sortByEmailAsc = 0, @sortByCompanyNameAsc = 0
  99. IF @RC<>0
  100. BEGIN
  101. SET @error=50006 -- E_subProcFailure
  102. SET @context=''
  103. GOTO errorLabel
  104. END
  105. RETURN 0
  106. errorLabel:
  107. RAISERROR (@error, 16, 1, @context)
  108. RETURN 1
  109. END -- ADM_findPublisher
  110. GO
  111. -- =============================================
  112. -- Name: ADM_setPublisherTier
  113. -- =============================================
  114. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ADM_setPublisherTier' AND type = 'P')
  115. DROP PROCEDURE ADM_setPublisherTier
  116. GO
  117. CREATE PROCEDURE ADM_setPublisherTier
  118. @PUID nvarchar(450),
  119. @tier nvarchar(256)
  120. WITH ENCRYPTION
  121. AS
  122. BEGIN
  123. DECLARE
  124. @publisherID bigint,
  125. @tModelLimit int,
  126. @businessLimit int,
  127. @serviceLimit int,
  128. @bindingLimit int,
  129. @assertionLimit int,
  130. @error int,
  131. @context nvarchar(4000)
  132. SET @publisherID = dbo.publisherID(@PUID)
  133. -- Validate publisherID
  134. IF (@publisherID IS NULL)
  135. BEGIN
  136. SET @error = 60150 -- E_unknownUer
  137. SET @context = 'Unknown publisher.'
  138. GOTO errorLabel
  139. END
  140. -- Validate tier parameter
  141. IF @tier NOT IN ('1','2','unlimited')
  142. BEGIN
  143. SET @error = 50009 -- E_parmError
  144. SET @context = 'Invalid tier specified.'
  145. GOTO errorLabel
  146. END
  147. IF @tier = '1'
  148. BEGIN
  149. SET @tModelLimit=100
  150. SET @businessLimit=1
  151. SET @serviceLimit=4
  152. SET @bindingLimit=2
  153. SET @assertionLimit=10
  154. END
  155. ELSE
  156. BEGIN
  157. IF (@tier = '2') OR (@tier = 'unlimited')
  158. BEGIN
  159. SET @tModelLimit=NULL
  160. SET @businessLimit=NULL
  161. SET @serviceLimit=NULL
  162. SET @bindingLimit=NULL
  163. SET @assertionLimit=NULL
  164. END
  165. END
  166. UPDATE
  167. [UDO_publishers]
  168. SET
  169. [tModelLimit] = @tModelLimit,
  170. [businessLimit] = @businessLimit,
  171. [serviceLimit] = @serviceLimit,
  172. [bindingLimit] = @bindingLimit,
  173. [assertionLimit] = @assertionLimit
  174. WHERE
  175. ([publisherID] = @publisherID)
  176. RETURN 0
  177. errorLabel:
  178. RAISERROR (@error, 16, 1, @context)
  179. RETURN 1
  180. END -- ADM_setPublisherTier
  181. GO
  182. -- =============================================
  183. -- Name: ADM_removePublisher
  184. -- =============================================
  185. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ADM_removePublisher' AND type = 'P')
  186. DROP PROCEDURE ADM_removePublisher
  187. GO
  188. CREATE PROCEDURE ADM_removePublisher
  189. @PUID nvarchar(450)
  190. WITH ENCRYPTION
  191. AS
  192. BEGIN
  193. DECLARE
  194. @publisherID bigint,
  195. @error int,
  196. @context nvarchar(4000)
  197. SET @publisherID = dbo.publisherID(@PUID)
  198. -- Validate publisherID
  199. IF (@publisherID IS NULL)
  200. BEGIN
  201. SET @error = 60150 -- E_unknownUser
  202. SET @context = 'Invalid publisherID.'
  203. GOTO errorLabel
  204. END
  205. DELETE FROM
  206. [UDO_publishers]
  207. WHERE
  208. ([publisherID] = @publisherID)
  209. RETURN 0
  210. errorLabel:
  211. RAISERROR (@error, 16, 1, @context)
  212. RETURN 1
  213. END
  214. GO
  215. -- =============================================
  216. -- Name: ADM_setPublisherStatus
  217. -- =============================================
  218. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ADM_setPublisherStatus' AND type = 'P')
  219. DROP PROCEDURE ADM_setPublisherStatus
  220. GO
  221. CREATE PROCEDURE ADM_setPublisherStatus
  222. @PUID nvarchar(450),
  223. @publisherStatus nvarchar(256)
  224. WITH ENCRYPTION
  225. AS
  226. BEGIN
  227. DECLARE
  228. @publisherID bigint,
  229. @publisherStatusID tinyint,
  230. @error int,
  231. @context nvarchar(4000)
  232. SET @publisherID = dbo.publisherID(@PUID)
  233. -- Validate publisherID
  234. IF (@publisherID IS NULL)
  235. BEGIN
  236. SET @error = 60150 -- E_unknownUser
  237. SET @context = 'Unknown publisherID.'
  238. GOTO errorLabel
  239. END
  240. -- Validate publisherStatus
  241. SET @publisherStatusID = dbo.publisherStatusID(@publisherStatus)
  242. IF @publisherStatusID IS NULL
  243. BEGIN
  244. SET @error = 50009 -- E_parmError
  245. SET @context = 'Unknown publisher status ''' + @publisherStatus + ''''
  246. GOTO errorLabel
  247. END
  248. UPDATE
  249. [UDO_publishers]
  250. SET
  251. [publisherStatusID] = @publisherStatusID
  252. WHERE
  253. ([publisherID] = @publisherID)
  254. RETURN 0
  255. errorLabel:
  256. RAISERROR (@error, 16, 1, @context)
  257. RETURN 1
  258. END -- ADM_setPublisherStatus
  259. GO
  260. -- =============================================
  261. -- Section: Miscellaneous
  262. -- =============================================
  263. -- =============================================
  264. -- Name: ADM_execResetKeyImmediate
  265. -- =============================================
  266. IF EXISTS (SELECT name FROM sysobjects WHERE name = N'ADM_execResetKeyImmediate' AND type = 'P')
  267. DROP PROCEDURE ADM_execResetKeyImmediate
  268. GO
  269. CREATE PROCEDURE ADM_execResetKeyImmediate
  270. @keyLastResetDate nvarchar(4000) = NULL OUTPUT
  271. WITH ENCRYPTION
  272. AS
  273. BEGIN
  274. DECLARE
  275. @error int,
  276. @context nvarchar(4000),
  277. @RC int,
  278. @oldKeyLastResetDate varchar(8000)
  279. -- Get the original last reset date. We need this value to compare against our new one as an additional check
  280. -- to make sure we successfully generated a new key.
  281. SET @oldKeyLastResetDate = ISNULL(dbo.configValue('Security.KeyLastResetDate'),'Monday, January 01, 0001 12:00:00 AM') -- DateTime.MinValue
  282. -- Run extended stored proc to update security key. The new values will be put into the config table.
  283. EXEC @RC=master.dbo.xp_reset_key
  284. -- Make sure we ran successfully.
  285. IF @RC <> 0
  286. BEGIN
  287. SET @error = 50006 -- E_subProcFailure
  288. SET @context = ''
  289. GOTO errorLabel
  290. END
  291. -- The key generation implementation in the extended stored proc is synchronous, so we should have a new
  292. -- key value at this point.
  293. SET @keyLastResetDate = dbo.configValue('Security.KeyLastResetDate')
  294. -- Make sure the date is different.
  295. IF @keyLastResetDate = @oldKeyLastResetDate
  296. BEGIN
  297. GOTO errorLabel
  298. END
  299. -- Success.
  300. RETURN 0
  301. errorLabel:
  302. RETURN 1
  303. END -- ADM_execResetKeyImmediate
  304. GO
  305. -- =============================================
  306. -- Name: ADM_addServiceAccount
  307. -- =============================================
  308. IF EXISTS (SELECT name FROM sysobjects WHERE name = N'ADM_addServiceAccount' AND type = 'P')
  309. DROP PROCEDURE ADM_addServiceAccount
  310. GO
  311. CREATE PROCEDURE ADM_addServiceAccount
  312. @accountName nvarchar(128)
  313. WITH ENCRYPTION
  314. AS
  315. BEGIN
  316. DECLARE
  317. @error int,
  318. @context nvarchar(4000),
  319. @RC int,
  320. @SID varbinary(85),
  321. @isDbo bit
  322. -- Grant database server access to security account
  323. EXEC @RC=sp_grantlogin @accountName
  324. IF @RC <> 0
  325. BEGIN
  326. SET @error = 50006 -- E_subProcFailure
  327. SET @context = ''
  328. GOTO errorLabel
  329. END
  330. SET @SID = SUSER_SID(@accountName)
  331. -- Determine if user is dbo
  332. SET @isDbo = 0
  333. IF EXISTS( SELECT * FROM [sysusers] WHERE [name] = 'dbo' AND [sid] = @SID )
  334. SET @isDbo = 1
  335. -- Grant database access to security account
  336. IF ( (@isDbo = 0) AND ( NOT EXISTS ( SELECT * FROM [sysusers] WHERE [sid] = @SID ) ) )
  337. BEGIN
  338. EXEC @RC=sp_grantdbaccess @accountName
  339. IF @RC <> 0
  340. BEGIN
  341. SET @error = 50006 -- E_subProcFailure
  342. SET @context = ''
  343. GOTO errorLabel
  344. END
  345. END
  346. -- Add security account to UDDIService role
  347. IF ( (@isDbo = 0) AND ( EXISTS ( SELECT * FROM [sysusers] WHERE [sid] = @SID ) ) )
  348. BEGIN
  349. EXEC @RC=sp_addrolemember 'UDDIService', @accountName
  350. IF @RC <> 0
  351. BEGIN
  352. SET @error = 50006 -- E_subProcFailure
  353. SET @context = ''
  354. GOTO errorLabel
  355. END
  356. END
  357. -- Add security account to sysadmin server role
  358. -- EXEC @RC=sp_addsrvrolemember @accountName, 'sysadmin'
  359. --IF @RC <> 0
  360. --BEGIN
  361. --SET @error = 50006 -- E_subProcFailure
  362. --SET @context = ''
  363. --GOTO errorLabel
  364. --END
  365. RETURN 0
  366. errorLabel:
  367. RAISERROR (@error, 16, 1, @context)
  368. RETURN 1
  369. END -- ADM_addServiceAccount
  370. GO
  371. -- =============================================
  372. -- Name: ADM_setAdminAccount
  373. -- =============================================
  374. IF EXISTS (SELECT name FROM sysobjects WHERE name = N'ADM_setAdminAccount' AND type = 'P')
  375. DROP PROCEDURE ADM_setAdminAccount
  376. GO
  377. CREATE PROCEDURE ADM_setAdminAccount
  378. @accountName nvarchar(128)
  379. WITH ENCRYPTION
  380. AS
  381. BEGIN
  382. DECLARE
  383. @error int,
  384. @context nvarchar(4000),
  385. @RC int,
  386. @SID varbinary(85),
  387. @isDbo bit,
  388. @tmpString nvarchar(128),
  389. @prevAccountName sysname,
  390. @prevAccountSID varbinary(85)
  391. -- Grant database server access to security account
  392. EXEC @RC=sp_grantlogin @accountName
  393. IF @RC <> 0
  394. BEGIN
  395. SET @error = 50006 -- E_subProcFailure
  396. SET @context = ''
  397. GOTO errorLabel
  398. END
  399. SET @SID = SUSER_SID(@accountName)
  400. -- Determine if user is dbo
  401. SET @isDbo = 0
  402. IF EXISTS( SELECT * FROM [sysusers] WHERE [name] = 'dbo' AND [sid] = @SID )
  403. SET @isDbo = 1
  404. -- Grant database access to security account
  405. IF ( (@isDbo = 0) AND ( NOT EXISTS ( SELECT * FROM [sysusers] WHERE [sid] = @SID ) ) )
  406. BEGIN
  407. EXEC @RC=sp_grantdbaccess @accountName
  408. IF @RC <> 0
  409. BEGIN
  410. SET @error = 50006 -- E_subProcFailure
  411. SET @context = ''
  412. GOTO errorLabel
  413. END
  414. END
  415. -- Add security account to UDDIService role
  416. IF ( (@isDbo = 0) AND ( EXISTS ( SELECT * FROM [sysusers] WHERE [sid] = @SID ) ) )
  417. BEGIN
  418. EXEC @RC=sp_addrolemember 'UDDIAdmin', @accountName
  419. IF @RC <> 0
  420. BEGIN
  421. SET @error = 50006 -- E_subProcFailure
  422. SET @context = ''
  423. GOTO errorLabel
  424. END
  425. END
  426. -- Get the previous account
  427. CREATE TABLE #tempTable(
  428. [dbRole] sysname,
  429. [memberName] sysname,
  430. [memberSID] varbinary(85))
  431. INSERT #tempTable EXEC sp_helprolemember 'UDDIAdmin'
  432. SELECT
  433. @prevAccountName = [memberName],
  434. @prevAccountSID = [memberSID]
  435. FROM
  436. #tempTable
  437. WHERE
  438. [memberName] <> @accountName
  439. -- Revoke database access from old account
  440. IF (@prevAccountName IS NOT NULL) OR (@prevAccountSID IS NOT NULL)
  441. BEGIN
  442. EXEC @RC=sp_revokedbaccess @prevAccountName
  443. IF @RC <> 0
  444. BEGIN
  445. SET @error = 50006 -- E_subProcFailure
  446. SET @context = ''
  447. GOTO errorLabel
  448. END
  449. END
  450. -- Add security account to sysadmin server role
  451. --EXEC @RC=sp_addsrvrolemember @accountName, 'sysadmin'
  452. --
  453. --IF @RC <> 0
  454. --BEGIN
  455. --SET @error = 50006 -- E_subProcFailure
  456. --SET @context = ''
  457. --GOTO errorLabel
  458. --END
  459. RETURN 0
  460. errorLabel:
  461. RAISERROR (@error, 16, 1, @context)
  462. RETURN 1
  463. END -- ADM_setAdminAccount
  464. GO
  465. -- =============================================
  466. -- Section: AD publication
  467. -- =============================================
  468. -- =============================================
  469. -- Name: net_businessEntity_bindingTemplates_get
  470. -- =============================================
  471. IF EXISTS (SELECT name FROM sysobjects WHERE name = N'net_businessEntity_bindingTemplates_get' AND type = 'P')
  472. DROP PROCEDURE net_businessEntity_bindingTemplates_get
  473. GO
  474. CREATE PROCEDURE net_businessEntity_bindingTemplates_get
  475. @businessKey uniqueidentifier
  476. WITH ENCRYPTION
  477. AS
  478. BEGIN
  479. DECLARE
  480. @error int,
  481. @context nvarchar(4000),
  482. @businessID bigint
  483. SET @businessID = dbo.businessID(@businessKey)
  484. IF @businessID IS NULL
  485. BEGIN
  486. SET @error = 60210
  487. SET @context = 'businessKey=' + dbo.UUIDSTR(@businessKey)
  488. GOTO errorLabel
  489. END
  490. SELECT
  491. BT.[bindingKey],
  492. BS.[serviceKey],
  493. UT.[URLType],
  494. BT.[accessPoint],
  495. BT.[hostingRedirector]
  496. FROM
  497. [UDC_bindingTemplates] BT
  498. JOIN [UDC_URLTypes] UT ON BT.[URLTypeID] = UT.[URLTypeID]
  499. JOIN [UDC_businessServices] BS ON BT.[serviceID] = BS.[serviceID]
  500. WHERE
  501. (BS.[businessID] = @businessID)
  502. RETURN 0
  503. errorLabel:
  504. RAISERROR (@error, 16, 1, @context)
  505. RETURN 1
  506. END -- net_businessEntity_bindingTemplates_get
  507. GO