<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Le Blog SQL Server d&#039;ElSüket &#187; connexion</title>
	<atom:link href="https://blog.developpez.com/elsuket/ptag/connexion/feed" rel="self" type="application/rss+xml" />
	<link>https://blog.developpez.com/elsuket</link>
	<description>Nicolas Souquet - Expert SQL Server</description>
	<lastBuildDate>Mon, 05 Apr 2021 07:32:41 +0000</lastBuildDate>
	<language>fr-FR</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.42</generator>
	<item>
		<title>Scripter les connexions, rôles et utilisateurs avec leurs privilèges sous SQL Server 2005 et suivants</title>
		<link>https://blog.developpez.com/elsuket/p11945/securite/scripter-les-connexions-roles-et-utilisateurs-avec-leurs-privileges-sous-sql-server-2005-et-suivants</link>
		<comments>https://blog.developpez.com/elsuket/p11945/securite/scripter-les-connexions-roles-et-utilisateurs-avec-leurs-privileges-sous-sql-server-2005-et-suivants#comments</comments>
		<pubDate>Mon, 29 Apr 2013 23:19:52 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Sécurité]]></category>
		<category><![CDATA[connection]]></category>
		<category><![CDATA[connexion]]></category>
		<category><![CDATA[login]]></category>
		<category><![CDATA[scripter]]></category>
		<category><![CDATA[transfert]]></category>
		<category><![CDATA[user]]></category>
		<category><![CDATA[utilisateur]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=231</guid>
		<description><![CDATA[La procédure que Microsoft fournit pour transférer les connexions d&#8217;une instance de SQL Server à l&#8217;autre s&#8217;applique très bien à SQL Server 2000, qui a près de 13 ans ! Pourtant, avec les possibilités de transtypage ajoutées aux versions suivantes &#8230; <a href="https://blog.developpez.com/elsuket/p11945/securite/scripter-les-connexions-roles-et-utilisateurs-avec-leurs-privileges-sous-sql-server-2005-et-suivants">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>La procédure que <a href="http://support.microsoft.com/kb/918992?wa=wsignin1.0">Microsoft</a> fournit pour transférer les connexions d&rsquo;une instance de SQL Server à l&rsquo;autre s&rsquo;applique très bien à SQL Server 2000, qui a près de 13 ans ! Pourtant, avec les possibilités de transtypage ajoutées aux versions suivantes de SQL Server, une requête suffit pour générer le script de création des logins.<br />
En sus, je vous donne les requêtes nécessaires à la génération des rôles, des utilisateurs, et de leurs privilèges respectifs.<br />
<span id="more-231"></span></p>
<p>Voici donc la requête qui permet de scripter les connexions :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; <span style="color: #FF0000;">'CREATE LOGIN ['</span> <span style="color: #808080;">+</span> name <span style="color: #808080;">+</span> <span style="color: #FF0000;">'] FROM WINDOWS'</span> <span style="color: #0000FF;">AS</span> sql_statement<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; sys.<span style="color: #202020;">server_principals</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHERE</span> &nbsp; type_desc <span style="color: #808080;">IN</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'WINDOWS_LOGIN'</span>, <span style="color: #FF0000;">'WINDOWS_GROUP'</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> &nbsp; &nbsp; is_disabled <span style="color: #808080;">=</span> <span style="color: #000;">0</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> &nbsp; &nbsp; name <span style="color: #808080;">NOT</span> <span style="color: #808080;">IN</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'NT AUTHORITY\SYSTEM'</span>, <span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> &nbsp; &nbsp; name <span style="color: #808080;">NOT</span> <span style="color: #808080;">LIKE</span> <span style="color: #FF0000;">'%sqlserveragent%'</span><br />
<span style="color: #0000FF;">UNION</span> <span style="color: #808080;">ALL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; <span style="color: #FF0000;">'CREATE LOGIN '</span> <span style="color: #808080;">+</span> name<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #FF0000;">' WITH PASSWORD = '</span> <span style="color: #808080;">+</span> <span style="color: #0000FF;">CONVERT</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">max</span><span style="color: #808080;">&#41;</span>, password_hash, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">' HASHED'</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #FF0000;">', SID = '</span> <span style="color: #808080;">+</span> <span style="color: #0000FF;">CONVERT</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">max</span><span style="color: #808080;">&#41;</span>, sid, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">AS</span> sql_statement<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; sys.<span style="color: #202020;">sql_logins</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHERE</span> &nbsp; type_desc <span style="color: #808080;">IN</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'WINDOWS_LOGIN'</span>, <span style="color: #FF0000;">'SQL_LOGIN'</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> &nbsp; &nbsp; is_disabled <span style="color: #808080;">=</span> <span style="color: #000;">0</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> &nbsp; &nbsp; name <span style="color: #808080;">NOT</span> <span style="color: #808080;">IN</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'sa'</span>, <span style="color: #FF0000;">'NT AUTHORITY\SYSTEM'</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">ORDER</span> &nbsp; <span style="color: #0000FF;">BY</span> sql_statement</div></td></tr></tbody></table></div>
<p>Ci-dessous, la requête qui scripte les rôles de base de données :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">SELECT</span>&nbsp; <span style="color: #FF0000;">'CREATE ROLE ['</span> <span style="color: #808080;">+</span> name <span style="color: #808080;">+</span> <span style="color: #FF0000;">'] AUTHORIZATION dbo'</span> <span style="color: #0000FF;">AS</span> create_role_statement<br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; sys.<span style="color: #202020;">database_principals</span><br />
<span style="color: #0000FF;">WHERE</span> &nbsp; type_desc <span style="color: #808080;">=</span> <span style="color: #FF0000;">'DATABASE_ROLE'</span><br />
<span style="color: #808080;">AND</span> &nbsp; &nbsp; name <span style="color: #808080;">NOT</span> <span style="color: #808080;">LIKE</span> <span style="color: #FF0000;">'MS%'</span> <span style="color: #0000FF;">COLLATE</span> SQL_Latin1_General_CP1_CS_AS<br />
<span style="color: #808080;">AND</span> &nbsp; &nbsp; name <span style="color: #808080;">NOT</span> <span style="color: #808080;">IN</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'public'</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #808080;">AND</span> &nbsp; &nbsp; is_fixed_role <span style="color: #808080;">=</span> <span style="color: #000;">0</span><br />
<span style="color: #0000FF;">ORDER</span> &nbsp; <span style="color: #0000FF;">BY</span> name</div></td></tr></tbody></table></div>
<p>Puis les utilisateurs de base de données :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">SELECT</span>&nbsp; <span style="color: #FF0000;">'CREATE USER ['</span> <span style="color: #808080;">+</span> name <span style="color: #808080;">+</span> <span style="color: #FF0000;">'] FOR LOGIN ['</span> <span style="color: #808080;">+</span> name &nbsp;<span style="color: #808080;">+</span> <span style="color: #FF0000;">']'</span> <span style="color: #0000FF;">AS</span> create_user_statement<br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; sys.<span style="color: #202020;">database_principals</span><br />
<span style="color: #0000FF;">WHERE</span> &nbsp; type_desc <span style="color: #808080;">IN</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'SQL_USER'</span>, <span style="color: #FF0000;">'WINDOWS_USER'</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #808080;">AND</span> &nbsp; &nbsp; name <span style="color: #808080;">NOT</span> <span style="color: #808080;">IN</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'dbo'</span>, <span style="color: #FF0000;">'guest'</span>, <span style="color: #FF0000;">'sys'</span>, <span style="color: #FF0000;">'INFORMATION_SCHEMA'</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">ORDER</span> &nbsp; <span style="color: #0000FF;">BY</span> name</div></td></tr></tbody></table></div>
<p>Et enfin l&rsquo;appartenance des utilisateurs aux rôles, pour SQL Server 2005 et 2008 :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF0000;">'EXEC sp_addrolemember '</span><span style="color: #FF0000;">''</span> <span style="color: #808080;">+</span> R.<span style="color: #202020;">name</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">''</span><span style="color: #FF0000;">', '</span><span style="color: #FF0000;">''</span> <span style="color: #808080;">+</span> M.<span style="color: #202020;">name</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">''</span><span style="color: #FF0000;">''</span> <span style="color: #0000FF;">AS</span> role_members_statement<br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">database_role_members</span> <span style="color: #0000FF;">AS</span> RM<br />
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">database_principals</span> <span style="color: #0000FF;">AS</span> R<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> R.<span style="color: #202020;">principal_id</span> <span style="color: #808080;">=</span> RM.<span style="color: #202020;">role_principal_id</span><br />
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">database_principals</span> <span style="color: #0000FF;">AS</span> M<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> M.<span style="color: #202020;">principal_id</span> <span style="color: #808080;">=</span> RM.<span style="color: #202020;">member_principal_id</span><br />
<span style="color: #0000FF;">WHERE</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; R.<span style="color: #202020;">name</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">LIKE</span> <span style="color: #FF0000;">'MS%'</span> <span style="color: #0000FF;">COLLATE</span> SQL_Latin1_General_CP1_CS_AS<br />
<span style="color: #808080;">AND</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; M.<span style="color: #202020;">name</span> &nbsp;<span style="color: #FF0000;">'dbo'</span><br />
<span style="color: #0000FF;">ORDER</span> <span style="color: #0000FF;">BY</span>&nbsp; &nbsp; &nbsp; &nbsp; role_members_statement</div></td></tr></tbody></table></div>
<p>Et pour SQL Server 2012 :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">SELECT</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #FF0000;">'ALTER ROLE '</span> <span style="color: #808080;">+</span> R.<span style="color: #202020;">name</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">' ADD MEMBER '</span> <span style="color: #808080;">+</span> M.<span style="color: #202020;">name</span> <span style="color: #0000FF;">AS</span> role_members_statement<br />
<span style="color: #0000FF;">FROM</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sys.<span style="color: #202020;">database_role_members</span> <span style="color: #0000FF;">AS</span> RM<br />
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span> &nbsp; &nbsp; &nbsp;sys.<span style="color: #202020;">database_principals</span> <span style="color: #0000FF;">AS</span> R<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> R.<span style="color: #202020;">principal_id</span> <span style="color: #808080;">=</span> RM.<span style="color: #202020;">role_principal_id</span><br />
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span> &nbsp; &nbsp; &nbsp;sys.<span style="color: #202020;">database_principals</span> <span style="color: #0000FF;">AS</span> M<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> M.<span style="color: #202020;">principal_id</span> <span style="color: #808080;">=</span> RM.<span style="color: #202020;">member_principal_id</span><br />
<span style="color: #0000FF;">WHERE</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; R.<span style="color: #202020;">name</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">LIKE</span> <span style="color: #FF0000;">'MS%'</span> <span style="color: #0000FF;">COLLATE</span> SQL_Latin1_General_CP1_CS_AS<br />
<span style="color: #808080;">AND</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; M.<span style="color: #202020;">name</span> &nbsp;<span style="color: #FF0000;">'dbo'</span><br />
<span style="color: #0000FF;">ORDER</span> <span style="color: #0000FF;">BY</span> &nbsp; &nbsp; &nbsp; &nbsp;role_members_statement</div></td></tr></tbody></table></div>
<p>Il nous faut enfin les privilèges des rôles :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">;<span style="color: #0000FF;">WITH</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; CTE <span style="color: #0000FF;">AS</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; R.<span style="color: #202020;">name</span> <span style="color: #0000FF;">AS</span> role_name<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , G.<span style="color: #202020;">permission_name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #0000FF;">CASE</span> G.<span style="color: #0000FF;">class</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> <span style="color: #000;">1</span> <span style="color: #0000FF;">THEN</span> O.<span style="color: #202020;">name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> <span style="color: #000;">3</span> <span style="color: #0000FF;">THEN</span> S.<span style="color: #202020;">name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> <span style="color: #000;">0</span> <span style="color: #0000FF;">THEN</span> <span style="color: #FF00FF;">DB_NAME</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">END</span> <span style="color: #0000FF;">AS</span> <span style="color: #FF00FF;">object_name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #0000FF;">CASE</span> G.<span style="color: #0000FF;">class</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> <span style="color: #000;">1</span> <span style="color: #0000FF;">THEN</span> O.<span style="color: #202020;">type_desc</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> <span style="color: #000;">3</span> <span style="color: #0000FF;">THEN</span> <span style="color: #FF0000;">'SCHEMA'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> <span style="color: #000;">0</span> <span style="color: #0000FF;">THEN</span> <span style="color: #FF0000;">'DATABASE'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">END</span> <span style="color: #0000FF;">AS</span> object_type_desc<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">database_principals</span> <span style="color: #0000FF;">AS</span> R<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">database_permissions</span> <span style="color: #0000FF;">AS</span> G<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> G.<span style="color: #202020;">grantee_principal_id</span> <span style="color: #808080;">=</span> R.<span style="color: #202020;">principal_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">JOIN</span> &nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">schemas</span> <span style="color: #0000FF;">AS</span> S<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> G.<span style="color: #202020;">major_id</span> <span style="color: #808080;">=</span> S.<span style="color: #202020;">schema_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">JOIN</span> &nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">objects</span> <span style="color: #0000FF;">AS</span> O<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> G.<span style="color: #202020;">major_id</span> <span style="color: #808080;">=</span> O.<span style="color: #FF00FF;">object_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHERE</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; R.<span style="color: #202020;">name</span> &nbsp;<span style="color: #FF0000;">'public'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; G.<span style="color: #202020;">permission_name</span> &nbsp;<span style="color: #FF0000;">'CONNECT'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">--ORDER BY&nbsp; &nbsp; &nbsp; R.name, object_name, G.permission_name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">SELECT</span>&nbsp; <span style="color: #FF0000;">'GRANT '</span> <span style="color: #0000FF;">COLLATE</span> database_default <span style="color: #808080;">+</span> permission_name<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #FF0000;">' ON '</span> <span style="color: #808080;">+</span> <span style="color: #0000FF;">CASE</span> <span style="color: #0000FF;">WHEN</span> <span style="color: #FF00FF;">object_name</span> <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span> <span style="color: #0000FF;">THEN</span> <span style="color: #FF0000;">'SCHEMA::dbo TO ['</span> <span style="color: #0000FF;">ELSE</span> <span style="color: #FF00FF;">object_name</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">' TO ['</span> <span style="color: #0000FF;">END</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> role_name <span style="color: #808080;">+</span> <span style="color: #FF0000;">']'</span> <span style="color: #0000FF;">AS</span> role_grant_statement<br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; CTE</div></td></tr></tbody></table></div>
<p>Et nous terminons avec les privilèges des utilisateurs :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">;<span style="color: #0000FF;">WITH</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; CTE <span style="color: #0000FF;">AS</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DB_USER.<span style="color: #202020;">name</span> <span style="color: #0000FF;">AS</span> <span style="color: #FF00FF;">user_name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , DB_GRANT.<span style="color: #202020;">class_desc</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , DB_GRANT.<span style="color: #202020;">state_desc</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , DB_GRANT.<span style="color: #202020;">permission_name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #0000FF;">CASE</span> DB_GRANT.<span style="color: #202020;">class_desc</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> <span style="color: #FF0000;">'OBJECT_OR_COLUMN'</span> <span style="color: #0000FF;">THEN</span> O.<span style="color: #202020;">name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> <span style="color: #FF0000;">'SCHEMA'</span> <span style="color: #0000FF;">THEN</span> S.<span style="color: #202020;">name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> <span style="color: #FF0000;">'TYPE'</span> <span style="color: #0000FF;">THEN</span> TY.<span style="color: #202020;">name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ELSE</span> O.<span style="color: #202020;">name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">END</span> <span style="color: #0000FF;">AS</span> <span style="color: #FF00FF;">object_name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , O.<span style="color: #202020;">type_desc</span> <span style="color: #0000FF;">AS</span> DB_object_type<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">database_permissions</span> <span style="color: #0000FF;">AS</span> DB_GRANT<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">database_principals</span> <span style="color: #0000FF;">AS</span> DB_USER<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> DB_GRANT.<span style="color: #202020;">grantee_principal_id</span> <span style="color: #808080;">=</span> DB_USER.<span style="color: #202020;">principal_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">JOIN</span> &nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">objects</span> <span style="color: #0000FF;">AS</span> O<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> O.<span style="color: #FF00FF;">object_id</span> <span style="color: #808080;">=</span> DB_GRANT.<span style="color: #202020;">major_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">JOIN</span> &nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">types</span> <span style="color: #0000FF;">AS</span> TY<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> TY.<span style="color: #202020;">user_type_id</span> <span style="color: #808080;">=</span> DB_GRANT.<span style="color: #202020;">major_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">JOIN</span> &nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">schemas</span> <span style="color: #0000FF;">AS</span> S<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> S.<span style="color: #202020;">schema_id</span> <span style="color: #808080;">=</span> DB_GRANT.<span style="color: #202020;">major_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHERE</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DB_USER.<span style="color: #202020;">name</span> &nbsp;<span style="color: #FF0000;">'public'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DB_GRANT.<span style="color: #202020;">permission_name</span> &nbsp;<span style="color: #FF0000;">'CONNECT'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">SELECT</span>&nbsp; state_desc <span style="color: #0000FF;">COLLATE</span> database_default <span style="color: #808080;">+</span> <span style="color: #FF0000;">' '</span> <span style="color: #808080;">+</span> permission_name<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #0000FF;">CASE</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> <span style="color: #FF00FF;">object_name</span> <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span> <span style="color: #0000FF;">THEN</span> <span style="color: #FF0000;">''</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ELSE</span> <span style="color: #FF0000;">' ON '</span> <span style="color: #808080;">+</span> <span style="color: #FF00FF;">object_name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">END</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">' TO ['</span> <span style="color: #808080;">+</span> <span style="color: #FF00FF;">user_name</span> &nbsp;<span style="color: #808080;">+</span> <span style="color: #FF0000;">']'</span> <span style="color: #0000FF;">AS</span> create_user_statement<br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; CTE<br />
<span style="color: #0000FF;">ORDER</span> &nbsp; <span style="color: #0000FF;">BY</span> create_user_statement</div></td></tr></tbody></table></div>
<p>Bon transfert d&rsquo;entités de sécurité !</p>
<p>ElSüket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Que faire avec l&#8217;erreur 18486 : Login failed for user &#8216;unLogin&#8217; because the account is currently locked out</title>
		<link>https://blog.developpez.com/elsuket/p11379/securite/que-faire-avec-lerreur-18486-login-failed-for-user-unlogin-because-the-account-is-currently-locked-out</link>
		<comments>https://blog.developpez.com/elsuket/p11379/securite/que-faire-avec-lerreur-18486-login-failed-for-user-unlogin-because-the-account-is-currently-locked-out#comments</comments>
		<pubDate>Tue, 02 Oct 2012 09:11:10 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Sécurité]]></category>
		<category><![CDATA[18486]]></category>
		<category><![CDATA[connexion]]></category>
		<category><![CDATA[failed]]></category>
		<category><![CDATA[locked out]]></category>
		<category><![CDATA[login]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=173</guid>
		<description><![CDATA[Voici comment se dépatouiller de cette erreur, qui peut se produire lorsque : &#8211; le nombre de tentatives de connexion avec un mot de passe incorrect a dépassé &#8211; et que le nom de connexion est paramétré pour vérifier que &#8230; <a href="https://blog.developpez.com/elsuket/p11379/securite/que-faire-avec-lerreur-18486-login-failed-for-user-unlogin-because-the-account-is-currently-locked-out">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Voici comment se dépatouiller de cette erreur, qui peut se produire lorsque :</p>
<p>&#8211; le nombre de tentatives de connexion avec un mot de passe incorrect a dépassé<br />
&#8211; et que le nom de connexion est paramétré pour vérifier que les stratégies de mot de passe Windows de l&rsquo;ordinateur sur lequel l&rsquo;instance SQL Server s&rsquo;exécute</p>
<p><span id="more-173"></span></p>
<p>On peut se rendre compte de cette erreur en lisant les journaux de SQL Server, doit depuis l&rsquo;Explorateur d&rsquo;Objets de SQL Server Management Studio, soit en exécutant :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">EXEC xp_readerrorlog 0, 1, 'locked out', NULL, '20121002', '20121003'</div></td></tr></tbody></table></div>
<p>Pour s&rsquo;extraire de cette situation, on peut tout simplement changer le mot de passe; il est de toute façon nécessaire d&rsquo;adjoindre l&rsquo;option UNLOCK à l&rsquo;instruction ALTER LOGIN.<br />
En effet, ceci peut par exemple se produire après une attaque à force brute dans le but de révéler le mot de passe d&rsquo;une connexion.</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">ALTER &nbsp; LOGIN [uneConnexion]<br />
WITH&nbsp; &nbsp; PASSWORD = 'unMotDePasse' UNLOCK</div></td></tr></tbody></table></div>
<p>@++ <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
<p>ElSüket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
