<?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; Sécurité</title>
	<atom:link href="https://blog.developpez.com/elsuket/pcategory/securite/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>Reprendre le contrôle d&#8217;une instance SQL Server lorsqu&#8217;on a perdu le mot de passe de la connexion sa ou lorsque tous les DBAs en ont perdu l&#8217;accès</title>
		<link>https://blog.developpez.com/elsuket/p12007/moteur-de-base-de-donnees-sql-server/reprendre-le-controle-dune-instance-sql-server-lorsquon-a-perdu-le-mot-de-passe-de-la-connexion-sa-ou-lorsque-tous-les-dbas-en-ont-perdu-lacces</link>
		<comments>https://blog.developpez.com/elsuket/p12007/moteur-de-base-de-donnees-sql-server/reprendre-le-controle-dune-instance-sql-server-lorsquon-a-perdu-le-mot-de-passe-de-la-connexion-sa-ou-lorsque-tous-les-dbas-en-ont-perdu-lacces#comments</comments>
		<pubDate>Fri, 31 May 2013 00:36:28 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[Sécurité]]></category>
		<category><![CDATA[Utilitaires]]></category>
		<category><![CDATA[instance]]></category>
		<category><![CDATA[mot de passe]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[sa]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=524</guid>
		<description><![CDATA[Comment faire lorsqu&#8217;on a perdu le mot de passe de la connexion sa pour se connecter à l&#8217;instance ? Ou comment est-il possible de prendre le contrôle d&#8217;une instance SQL Server installée par une personne avec son propre compte, et &#8230; <a href="https://blog.developpez.com/elsuket/p12007/moteur-de-base-de-donnees-sql-server/reprendre-le-controle-dune-instance-sql-server-lorsquon-a-perdu-le-mot-de-passe-de-la-connexion-sa-ou-lorsque-tous-les-dbas-en-ont-perdu-lacces">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Comment faire lorsqu&rsquo;on a perdu le mot de passe de la connexion sa pour se connecter à l&rsquo;instance ?<br />
Ou comment est-il possible de prendre le contrôle d&rsquo;une instance SQL Server installée par une personne avec son propre compte, et qui a quitté l&rsquo;entreprise depuis une durée plus grande que celle de l&rsquo;expiration des mots de passe ?<br />
<span id="more-524"></span><br />
Il est pour cela nécessaire d&rsquo;avoir accès à la machine avec un compte d’administrateur local : en effet dans ce cas, le démarrage en mode mono-utilisateur d&rsquo;une instance de SQL Server autorise l&rsquo;accès à un tel compte. Cela permet donc de créer une nouvelle connexion, à laquelle on octroie le privilège et sésame d&rsquo;appartenance au rôle fixe de serveur <em>sysadmin</em>.</p>
<p>Voyons tout d&rsquo;abord quelles sont les connexions qui disposent du privilège d&rsquo;appartenance au rôle <em>sysadmin</em>. La requête suivante liste l&rsquo;ensemble des connexions inscrites aux rôles d&rsquo;instance :</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 /></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; SPR.<span style="color: #202020;">name</span> <span style="color: #0000FF;">AS</span> server_role_name<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , SPM.<span style="color: #202020;">name</span> <span style="color: #0000FF;">AS</span> server_role_member_name<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , SPR.<span style="color: #202020;">type_desc</span><br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">server_role_members</span> <span style="color: #0000FF;">AS</span> SRM<br />
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">server_principals</span> <span style="color: #0000FF;">AS</span> SPR<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> SRM.<span style="color: #202020;">role_principal_id</span> <span style="color: #808080;">=</span> SPR.<span style="color: #202020;">principal_id</span><br />
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">server_principals</span> <span style="color: #0000FF;">AS</span> SPM<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> SRM.<span style="color: #202020;">member_principal_id</span> <span style="color: #808080;">=</span> SPM.<span style="color: #202020;">principal_id</span></div></td></tr></tbody></table></div>
<p><img src="http://img689.imageshack.us/img689/5329/restartsqlserversingleu.png" alt="" /></p>
<p>La connexion <em>ELSUKET8\Nicolas</em> est celle d&rsquo;administrateur local de mon PC : je la supprime :</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 /></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;">DROP</span> LOG<span style="color: #808080;">IN</span> <span style="color: #808080;">&#91;</span>ELSUKET8\Nicolas<span style="color: #808080;">&#93;</span></div></td></tr></tbody></table></div>
<p>A l&rsquo;ouverture d&rsquo;une nouvelle fenêtre de requête, nous obtenons bien l&rsquo;erreur :</p>
<p><img src="http://img836.imageshack.us/img836/5329/restartsqlserversingleu.png" alt="" /></p>
<p>Rendons-nous maintenant dans le <a href="http://blog.developpez.com/elsuket/p7723/moteur-de-base-de-donnees-sql-server/configurer_les_protocoles_de_connexion_a">gestionnaire de configuration de SQL Server</a>. Si l&rsquo;instance est sous SQL Server 2012 et que l&rsquo;on souhaite ouvrir cette console à partir d&rsquo;une fenêtre de ligne de commandes, il faudra saisir <em>SQLServerManager11.msc</em>. Une fois la console ouverte, on peut double-cliquer sur SQL Server Services dans l&rsquo;un des deux panneaux, et on obtient la liste des services SQL Server installés :</p>
<p><img src="http://img248.imageshack.us/img248/5329/restartsqlserversingleu.png" alt="" /></p>
<p>Un clic-droit sur le service SQL Server nous permet d&rsquo;accéder, en outre, aux paramètres de démarrage du service. Sous SQL Server 2005 et 2008, ils se trouvent dans l&rsquo;onglet <em>Avancé</em>, mais sous SQL Server 2012, l&rsquo;onglet <em>Paramètres de démarrage</em> a fait son apparition :</p>
<p><img src="http://img22.imageshack.us/img22/5329/restartsqlserversingleu.png" alt="" /></p>
<p>Nous ajoutons ici le paramètre l&rsquo;option <em>-m</em>, qui permet de démarrer une instance en mode mono-utilisateur. Sous SQL Server 2005 et 2008, dans l&rsquo;onglet <em>Avancé</em>, il est nécessaire de placer le curseur à la fin de la chaîne du paramètre <em>Paramètres de démarrage</em>, et d&rsquo;ajouter <em>;-m</em> après la fin de cette chaîne. Une fois fait, nous sommes avertis qu&rsquo;il est évidemment nécessaire de redémarrer le service :</p>
<p><img src="http://img545.imageshack.us/img545/5329/restartsqlserversingleu.png" alt="" /></p>
<p>On peut redémarrer le service toujours à partir de la même console, par un clic-droit sur le service. Une fois fait, nous démarrons SQL Server Management Studio (SSMS) <strong>en tant qu&rsquo;administrateur</strong>. Cette option est accessible par un simple clic-droit sur le raccourci. Attention : comme nous sommes en mode mono-utilisateur, il n&rsquo;est pas possible d&rsquo;ouvrir une connexion pour l&rsquo;explorateur d&rsquo;objets. Donc si l&rsquo;on ne ferme pas la connexion de ce dernier (par clic-droit sur le nom de l&rsquo;instance dans celui-ci), il est impossible d&rsquo;ouvrir une fenêtre de requête.</p>
<p>Nous nous octroyons maintenant le droit de connexion et d&rsquo;appartenance au rôle de serveur <em>sysadmin</em> :</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;">CREATE</span> LOG<span style="color: #808080;">IN</span> <span style="color: #808080;">&#91;</span>ELSUKET8\ElSuket<span style="color: #808080;">&#93;</span><br />
<span style="color: #0000FF;">FROM</span> W<span style="color: #808080;">IN</span>DOWS<br />
GO<br />
<br />
<span style="color: #008080;">-- SQL Server 2012</span><br />
<span style="color: #0000FF;">ALTER</span> SERVER <span style="color: #0000FF;">ROLE</span> sysadmin <span style="color: #0000FF;">ADD</span> MEMBER <span style="color: #808080;">&#91;</span>ELSUKET8\ElSuket<span style="color: #808080;">&#93;</span><br />
<br />
<span style="color: #008080;">-- SQL Server 2000, 2005 et 2008</span><br />
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">sp_addsrvrolemember</span> <span style="color: #FF0000;">'ELSUKET8\ElSuket'</span>, <span style="color: #FF0000;">'sysadmin'</span></div></td></tr></tbody></table></div>
<p>Nous devons maintenant retourner dans la console de configuration des services de SQL Server, retirer le paramètre -m, et redémarrer à nouveau le service, de sorte que l&rsquo;instance soit de nouveau accessible par plusieurs connexions. Une fois fait, on peut démarrer SSMS normalement (i.e. pas en tant qu&rsquo;administrateur), et nous pouvons de nouveau accéder à l&rsquo;instance SQL Server :</p>
<p><img src="http://img835.imageshack.us/img835/5329/restartsqlserversingleu.png" alt="" /></p>
<p><img src="http://img12.imageshack.us/img12/5913/iconarrowp.gif" alt="" /> <strong>Changer le mot de passe de la connexion <em>sa</em></strong></p>
<p>Cela se fait de la même façon, en suivant les étapes suivantes :</p>
<p>1. Ajouter le paramètre -m aux paramètres de démarrage du service SQL Server, puis redémarrer le service;<br />
2. Se connecter à l&rsquo;instance SQL Server avec SSMS en tant qu’administrateur;<br />
3. Changer le mot de passe de la connexion <em>sa</em> avec l&rsquo;instruction suivante :</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 /></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;">ALTER</span> LOG<span style="color: #808080;">IN</span> sa <span style="color: #0000FF;">WITH</span> PASSW<span style="color: #808080;">OR</span>D <span style="color: #808080;">=</span> <span style="color: #FF0000;">'unMotDePasseRobuste'</span></div></td></tr></tbody></table></div>
<p>4. Supprimer le paramètre -m des paramètres de démarrage du service SQL Server, puis redémarrer le service une nouvelle fois;<br />
5. Se connecter normalement avec SSMS, le nom de connexion <em>sa</em> et le nouveau mot de passe.</p>
<p><img src="http://img12.imageshack.us/img12/5913/iconarrowp.gif" alt="" /> <strong>Effectuer ces mêmes opérations en ligne de commande avec l&rsquo;utilitaire SQLCMD</strong></p>
<p>Il est pour cela nécessaire d&rsquo;ouvrir un fenêtre de lignes de commande en tant qu&rsquo;administrateur. On peut tout simplement créer une raccourci qui pointe sur <em>cmd</em>, puis par clic-droit sur celui-ci, choisir de mode :</p>
<p><img src="http://img689.imageshack.us/img689/5316/restartsqlserversingleux.png" alt="" /></p>
<p>Une fois fait, on démarre l&rsquo;utilitaire en lignes de commande SQLCMD très simplement :</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 /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">sqlcmd <span style="color: #808080;">-</span>S <span style="color: #808080;">&#91;</span>uneInstance<span style="color: #808080;">&#93;</span></div></td></tr></tbody></table></div>
<p><img src="http://img823.imageshack.us/img823/5329/restartsqlserversingleu.png" alt="" /></p>
<p>Puis, par exemple, changer le mot de passe de la connexion <em>sa</em> :</p>
<p><img src="http://img577.imageshack.us/img577/5329/restartsqlserversingleu.png" alt="" /></p>
<p>Après chaque ligne de code tapée sous SQLCMD, si l&rsquo;on appuie sur <em>Entrée</em>, la commande n&rsquo;est pas exécutée : il faut pour cela utiliser la marqueur de fin de lot GO (qui n&rsquo;est pas une instruction SQL ou T-SQL !). Enfin, pour sortir de l&rsquo;utilitaire SQLCMD, il suffit de taper <em>exit</em>.</p>
<p>Bonne récupération d&rsquo;accès à tous !</p>
<p>ElSüket.</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Les posters des permissions pour SQL Server 2008 R2, 2012 et Azure</title>
		<link>https://blog.developpez.com/elsuket/p11954/securite/les-posters-des-permissions-pour-sql-server-2008-r2-2012-et-azure</link>
		<comments>https://blog.developpez.com/elsuket/p11954/securite/les-posters-des-permissions-pour-sql-server-2008-r2-2012-et-azure#comments</comments>
		<pubDate>Tue, 07 May 2013 05:44:33 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Sécurité]]></category>
		<category><![CDATA[SQL Server 2012]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=362</guid>
		<description><![CDATA[Si l&#8217;on est un peu perdu dans les privilèges que l&#8217;on peut octroyer à des utilisateurs ou des connexions (logins), ou que l&#8217;on souhaite tout simplement explorer les possibilités offertes par les entités de sécurité, on peut télécharger des posters &#8230; <a href="https://blog.developpez.com/elsuket/p11954/securite/les-posters-des-permissions-pour-sql-server-2008-r2-2012-et-azure">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Si l&rsquo;on est un peu perdu dans les privilèges que l&rsquo;on peut octroyer à des utilisateurs ou des connexions (logins), ou que l&rsquo;on souhaite tout simplement explorer les possibilités offertes par les entités de sécurité, on peut <a href="http://social.technet.microsoft.com/wiki/contents/articles/11842.sql-server-database-engine-permission-posters.aspx">télécharger</a> des posters qui les présentent sous forme de groupes : serveur, base de données, ou pour chaque fonctionnalité du moteur de base de données.</p>
<p>Bon octroi de privilèges !</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>
		<item>
		<title>Les posters des privilèges et permissions sous SQL Server 2008 R2, SQL Server 2012 et SQL Azure</title>
		<link>https://blog.developpez.com/elsuket/p11155/securite/poster_privilege_sql_server</link>
		<comments>https://blog.developpez.com/elsuket/p11155/securite/poster_privilege_sql_server#comments</comments>
		<pubDate>Tue, 17 Jul 2012 21:29:45 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Sécurité]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Voici un lien intéressant qui offre pour chaque version de SQL Server, une vue d&#8217;ensemble des privilèges et permissions que l&#8217;on peut octroyer à un utilisateur ou une connexion, quelle que soit l&#8217;entité. Bonne lecture ! ElSüket]]></description>
				<content:encoded><![CDATA[<p>Voici un lien intéressant qui offre pour chaque version de SQL Server, une vue d&rsquo;ensemble des privilèges et permissions que l&rsquo;on peut octroyer à un utilisateur ou une connexion, quelle que soit l&rsquo;entité.</p>
<p>Bonne <a href="http://social.technet.microsoft.com/wiki/contents/articles/11842.sql-server-database-engine-permission-posters.aspx">lecture</a> !</p>
<p>ElSüket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Lister quelques propriétés des logins</title>
		<link>https://blog.developpez.com/elsuket/p8617/t-sql/lister_quelques_proprietes_des_logins</link>
		<comments>https://blog.developpez.com/elsuket/p8617/t-sql/lister_quelques_proprietes_des_logins#comments</comments>
		<pubDate>Thu, 11 Feb 2010 03:01:37 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Sécurité]]></category>
		<category><![CDATA[T-SQL]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Voici une petite requête qui retourne quelques propriétés pour tous les logins d&#8217;un instance SQL Server, avec la prochaine date d&#8217;expiration des mots de passe &#8230; 123456789101112131415161718192021222324252627------------------------------- -- 22/01/2010 - Nicolas SOUQUET ------------------------------- WITH &#160; LOGIN_PROPERTIES AS &#160; ( &#160; &#8230; <a href="https://blog.developpez.com/elsuket/p8617/t-sql/lister_quelques_proprietes_des_logins">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Voici une petite requête qui retourne quelques propriétés pour tous les logins d&rsquo;un instance SQL Server, avec la prochaine date d&rsquo;expiration des mots de passe &#8230;<br />
<span id="more-147"></span></p>
<div class="codecolorer-container text 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 /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">------------------------------- <br />
-- 22/01/2010 - Nicolas SOUQUET <br />
------------------------------- <br />
WITH <br />
&nbsp; LOGIN_PROPERTIES AS <br />
&nbsp; ( <br />
&nbsp; &nbsp; SELECT SP.name <br />
&nbsp; &nbsp; &nbsp; , SP.type_desc <br />
&nbsp; &nbsp; &nbsp; , SP.is_disabled <br />
&nbsp; &nbsp; &nbsp; , SP.create_date <br />
&nbsp; &nbsp; &nbsp; , SP.modify_date <br />
&nbsp; &nbsp; &nbsp; , SP.default_database_name AS default_db <br />
&nbsp; &nbsp; &nbsp; , SP.default_language_name AS default_lang <br />
&nbsp; &nbsp; &nbsp; , CAST(LOGINPROPERTY(SP.name, 'PasswordLAstSetTime') AS DATETIME) AS password_last_set_time <br />
&nbsp; &nbsp; &nbsp; , CAST(LOGINPROPERTY(SP.name, 'DaysUntilExpiration') AS DATETIME) AS days_until_expiration <br />
&nbsp; &nbsp; FROM sys.server_principals AS SP <br />
&nbsp; ) <br />
SELECT name <br />
&nbsp; , type_desc <br />
&nbsp; , is_disabled <br />
&nbsp; , create_date <br />
&nbsp; , modify_date <br />
&nbsp; , default_db <br />
&nbsp; , default_lang <br />
&nbsp; , password_last_set_time <br />
&nbsp; , DATEADD(day, -DATEDIFF(day, password_last_set_time, GETDATE()), GETDATE()) + days_until_expiration AS password_expiry_date <br />
FROM LOGIN_PROPERTIES</div></td></tr></tbody></table></div>
<p>Bonne sécurisation !</p>
<p>ElSuket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Empêcher un utilisateur de consulter le code source d&#8217;un objet de base de données (procédure stockée, fonction, trigger, vue, &#8230;)</title>
		<link>https://blog.developpez.com/elsuket/p8437/snippets/empecher_un_utilisateur_de_consulter_le</link>
		<comments>https://blog.developpez.com/elsuket/p8437/snippets/empecher_un_utilisateur_de_consulter_le#comments</comments>
		<pubDate>Mon, 07 Dec 2009 20:58:33 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Sécurité]]></category>
		<category><![CDATA[Snippets]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[On demande parfois comment on peut crypter le code d&#8217;un objet de base de données (procédure stockée, trigger, fonction, vue, &#8230;) afin qu&#8217;un utilisateur ou qu&#8217;un groupe d&#8217;utilisateurs ne puisse pas en consulter le code. Or il faut bien se &#8230; <a href="https://blog.developpez.com/elsuket/p8437/snippets/empecher_un_utilisateur_de_consulter_le">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>On demande parfois comment on peut crypter le code d&rsquo;un objet de base de données (procédure stockée, trigger, fonction, vue, &#8230;) afin qu&rsquo;un utilisateur ou qu&rsquo;un groupe d&rsquo;utilisateurs ne puisse pas en consulter le code.</p>
<p>Or il faut bien se rappeler que le cryptage d&rsquo;un objet de base de données implique que celui-ci soit décrypté lors de chacune de ses exécutions, ce qui peut infliger au serveur de base de données une consommation de ressources élevée, peu souhaitable dans un environnement OLTP ou pour un serveur OLAP fortement sollicité.</p>
<p>Une alternative bien simple existe pourtant : le refus d&rsquo;autorisation.<br />
Voyons comment l&rsquo;utiliser &#8230;<br />
<span id="more-148"></span><br />
Nous allons créer une connexion et un utilisateur TOTO, et lui refuser le droit de voir la définition d&rsquo;une procédure stockée.<br />
Je me limite ici au cas d&rsquo;une procédure stockée, mais le squelette est le même pour tout autre objet de base de données.<br />
Si nous exécutons le script suivant, dans une session sous le login sa (connexion super-admnistrateur par défaut d&rsquo;une instance SQL Server ) :</p>
<div class="codecolorer-container text 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 /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">-- Crée une connexion d'identifiant TOTO <br />
CREATE LOGIN TOTO <br />
WITH PASSWORD = '***' <br />
GO <br />
&nbsp;<br />
-- Change de contexte de base de données <br />
USE ELSUKET <br />
GO <br />
&nbsp;<br />
-- Crée un utilisateur de base de données <br />
CREATE USER TOTO <br />
FOR LOGIN TOTO <br />
GO <br />
&nbsp;<br />
-- Une petite procédure <br />
CREATE PROCEDURE PsTestDroits <br />
AS <br />
BEGIN <br />
&nbsp; SELECT 1 <br />
END <br />
GO <br />
&nbsp;<br />
-- Refuse l'autorisation du vue de la définition à l'utilisateur TOTO <br />
-- de la base de données ELSUKET <br />
DENY VIEW DEFINITION <br />
ON PsTestDroits TO TOTO</div></td></tr></tbody></table></div>
<p>Nous voyons, dans l&rsquo;explorateur d&rsquo;objet de <em>SQL Server Management Studio</em>:</p>
<p><img src="http://blog.developpez.com/media/denyViewDefinition1.png" width="304" height="811" alt="" /></p>
<p>Connectons nous maintenant comme le ferait l&rsquo;utilisateur TOTO :</p>
<p><img src="http://blog.developpez.com/media/denyViewDefinition2.png" width="218" height="232" alt="" /></p>
<p><img src="http://blog.developpez.com/media/denyViewDefinition3.png" width="416" height="315" alt="" /></p>
<p>La nouvelle connexion s&rsquo;ouvre dans l&rsquo;explorateur d&rsquo;objets avec le contexte de navigation dans la base de données de TOTO : on ne peut pas voir la procédure stockée PsTestDroits :</p>
<p><img src="http://blog.developpez.com/media/denyViewDefinition4.png" width="310" height="258" alt="" /></p>
<p>ElSuket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lister les permissions dont un utilisateur dispose sous SQL Server 2005 et 2008 : la fonction fn_my_permission</title>
		<link>https://blog.developpez.com/elsuket/p8027/securite/lister_les_permissions_dont_un_utilisate</link>
		<comments>https://blog.developpez.com/elsuket/p8027/securite/lister_les_permissions_dont_un_utilisate#comments</comments>
		<pubDate>Sun, 06 Sep 2009 09:09:23 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Sécurité]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[La gestion des droits sous SQL Server étant complexe, puisqu&#8217;on peut octroyer des droits au niveau de l&#8217;instance et au niveau de la base de données, il est moins simple d&#8217;obtenir la liste complète des droits octroyés à un utilisateur, &#8230; <a href="https://blog.developpez.com/elsuket/p8027/securite/lister_les_permissions_dont_un_utilisate">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>La gestion des droits sous SQL Server étant complexe, puisqu&rsquo;on peut octroyer des droits au niveau de l&rsquo;instance et au niveau de la base de données, il est moins simple d&rsquo;obtenir la liste complète des droits octroyés à un utilisateur, ou de connaître la liste des droits qu&rsquo;on nous a octroyés.<br />
Voyons comment obtenir cette liste de façon simple, avec la fonction fn_my_permission</p>
<p><span id="more-146"></span></p>
<p>Pour obtenir la liste complète des droits qui me sont octroyés, il me suffit d&rsquo;exécuter :</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">SELECT * <br />
FROM fn_my_permissions(NULL, NULL)</div></td></tr></tbody></table></div>
<p>Le premier paramètre de cette fonction correspond à l&rsquo;objet sur lequel on cherche les droits octroyés, tandis que le second correspond au type de l&rsquo;objet (&lsquo;OBJECT&rsquo;, &lsquo;DATABASE&rsquo;, &lsquo;LOGIN&rsquo;, &lsquo;SCHEMA&rsquo;, &lsquo;SERVER, &lsquo;USER&rsquo;, &#8230;).</p>
<p>Si l&rsquo;on souhaite voir le résultat filtré, on peut par exemple écrire :</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">SELECT entity_name, &nbsp;permission_name <br />
FROM fn_my_permissions(NULL, 'SERVER')</div></td></tr></tbody></table></div>
<p>Supposons que nous sommes administrateur d&rsquo;une instance, et que nous venons d&rsquo;octroyer des droits à un utilisateur de base de données.<br />
Sans avoir à ouvrir une nouvelle session en spécifiant le login de l&rsquo;utilisateur et son mot de passe, on peut lister ses droits :</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 />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">USE maBD <br />
GO <br />
&nbsp;<br />
EXECUTE AS USER = 'monUtilisateur'; <br />
SELECT * <br />
FROM fn_my_permissions(NULL, 'OBJECT') <br />
&nbsp;<br />
REVERT <br />
GO</div></td></tr></tbody></table></div>
<p>ElSuket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Différence entre LOGIN et USER, entre connexion et utilisateur</title>
		<link>https://blog.developpez.com/elsuket/p7848/t-sql/difference_entre_login_et_user_entre_con</link>
		<comments>https://blog.developpez.com/elsuket/p7848/t-sql/difference_entre_login_et_user_entre_con#comments</comments>
		<pubDate>Mon, 06 Jul 2009 20:25:01 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Sécurité]]></category>
		<category><![CDATA[SQL Server Management Studio]]></category>
		<category><![CDATA[T-SQL]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Quelle est la différence entre une connexion, ou LOGIN, et un utilisateur de base de données ? Une connexion, ou login, permet d&#8217;accéder à une instance de SQL Server, mais c&#8217;est tout. Une instance de SQL Server pouvant héberger plusieurs &#8230; <a href="https://blog.developpez.com/elsuket/p7848/t-sql/difference_entre_login_et_user_entre_con">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Quelle est la différence entre une connexion, ou LOGIN, et un utilisateur de base de données ?</p>
<p><span id="more-145"></span></p>
<p><strong>Une connexion, ou login,</strong> permet d&rsquo;accéder à une instance de SQL Server, mais c&rsquo;est tout.<br />
Une instance de SQL Server pouvant héberger plusieurs bases de données utilisateur, nous ne souhaitons peut-être pas que tous les utilisateurs aient accès à toutes les bases de données d&rsquo;une instance, et de la même façon.<br />
On peut aussi créer une connexion à un utilisateur pour qu&rsquo;il puisse seulement effectuer des sauvegardes de base de données</p>
<p><strong>A toute connexion|login, peut correspondre un utilisateur de base de données.</strong><br />
L&rsquo;utilisateur de base de données est alors &laquo;&nbsp;mappé&nbsp;&raquo; sur une connexion, qui le donne le droit de naviguer dans 0 à autant de bases de données que l&rsquo;instance en héberge.<br />
Un administrateur ou les personnes à qui l&rsquo;administrateur en a délégué le droit peuvent accorder des droits d&rsquo;accès et des privilèges.</p>
<p><strong>Un droit d&rsquo;accès</strong> permet à un utilisateur de naviguer dans une base de données suivant des privilèges que l&rsquo;administrateur lui a octroyés.<br />
<strong>Un privilège</strong> permet de limiter l&rsquo;accès aux données, par exemple en refusant le droit de SELECT sur la colonne salaire de la table des employés aux utilisateurs employés.</p>
<p>On peut encore gérer plus globalement au niveau de la base de données ou de l&rsquo;instance les accès aux données en créant des rôles : on affecte ainsi au rôle des droits d&rsquo;accès et des privilèges, et lors de l&rsquo;arrivée d&rsquo;un nouvel utilisateur, il nous suffit de l&rsquo;ajouter au rôle de base de données.</p>
<p><strong>Pour créer une connexion :</strong></p>
<p><code class="codecolorer text default"><span class="text">CREATE LOGIN monLogin WITH PASSWORD = 'monMotDePasse'</span></code></p>
<p><strong>Pour permettre la navigation dans la base de données :</strong></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 />3<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">USE maBD <br />
GO <br />
CREATE USER monUtilisateur FOR LOGIN monLogin</div></td></tr></tbody></table></div>
<p><strong>On peut créer de plusieurs façon un rôle :</strong></p>
<p>=> Soit par &laquo;&nbsp;recopie&nbsp;&raquo; des drois d&rsquo;un utilisateur :</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 />3<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">USE maBD; <br />
CREATE ROLE monRole AUTHORIZATION unUtilsateur; <br />
GO</div></td></tr></tbody></table></div>
<p>=> Soit par recopie d&rsquo;un rôle de base de données existant :</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 />3<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">USE maBD; <br />
CREATE ROLE monRole AUTHORIZATION db_securityadmin; <br />
GO</div></td></tr></tbody></table></div>
<p>Pour gérer les privilèges, on peut voir la documentation des instructions <a href="http://msdn.microsoft.com/fr-fr/library/ms187965%28SQL.90%29.aspx">GRANT</a>, <a href="http://msdn.microsoft.com/fr-fr/library/ms187728.aspx">REVOKE</a> et <a href="http://msdn.microsoft.com/fr-fr/library/ms188338.aspx">DENY</a></p>
<p><strong>On peut également réaliser tout cela à l&rsquo;aide de <em>SQL Server Management Studio :</em></strong></p>
<p>&#8211; Pour la création de la connexion, ouvrez la node &laquo;&nbsp;Sécurité&nbsp;&raquo; de votre instance, puis faites un clic-droit sur la node &laquo;&nbsp;Connexions&nbsp;&raquo;, et choisissez &laquo;&nbsp;Nouvelle connexion&nbsp;&raquo;</p>
<p><img src="http://blog.developpez.com/media/login.PNG" width="390" height="274" alt="" /></p>
<p><img src="http://blog.developpez.com/media/login2.PNG" width="704" height="632" alt="" /></p>
<p>&#8211; Pour la création de l&rsquo;utilisateur, après avoir ouvert la node possédant le nom de la base de données en question, ouvrez la node &laquo;&nbsp;Sécurité&nbsp;&raquo;, puis cliquez-droit sur la node &laquo;&nbsp;Utilisateurs&nbsp;&raquo; en choisissant &laquo;&nbsp;Nouvel utilisateur&nbsp;&raquo;</p>
<p><img src="http://blog.developpez.com/media/user.PNG" width="389" height="518" alt="" /></p>
<p><img src="http://blog.developpez.com/media/user2.PNG" width="704" height="771" alt="" /></p>
<p>Un peu de lecture par <a href="http://sqlpro.developpez.com/cours/sqlaz/dcl/">ici</a> et <a href="http://sqlpro.developpez.com/cours/sqlserver/securisation/">ici</a>, par SQLPro <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
<p>ElSuket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
