Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_MSaddlogin_implicit_ntlogin

  No additional text.


Syntax

-- NOTE: FOR INTERNAL SECURITY USE ONLY!
--      DO NOT DOCUMENT OR USE!

create procedure sys.sp_MSaddlogin_implicit_ntlogin
    @loginame		sysname
AS

	declare @default_lang sysname
	declare @exec_stmt nvarchar(4000)

    -- NO-OP IF LOGIN ALREADY EXISTS 
	-- if suser_sid(@loginame) is null

	if not exists(select * from master.dbo.syslogins where loginname = @loginame)
	begin

        -- MUST BE NT NAME 
        if (charindex('\', @loginame) = 0)
            return (1)

	    declare	@newsid	varbinary(85)

        -- OBTAIN NT SID FOR THIS LOGIN (SET STATUS BITS) 
	    select @newsid = get_sid('\U'+@loginame)	    -- NT user
	    if (@newsid IS Null)
	    begin
            select @newsid = get_sid('\G'+@loginame)  -- NT group
	        if (@newsid IS Null)
		        return (1)
	    end
		
		-- FAIL IF SID ALREADY IN SYSLOGINS
		if exists(select * from master.dbo.syslogins where sid = @newsid)
			return (1)

		set @exec_stmt = 'create login ' + quotename(@loginame) + ' from windows'

		exec (@exec_stmt)

		if @@error <> 0	-- failed
			return (1)	-- Caller will rollback transaction
		
		declare @accessstate char(1)
		select @accessstate = state from sys.server_permissions where
					class = 100 AND grantee_principal_id = suser_id(@loginame) AND
					type = 'COSQ' AND grantor_principal_id = 1			
		
		if @accessstate = 'G'
		begin
			-- REVOKE ACCESS 
			EXEC %%LocalLogin(Name = @loginame).SetAccess(HasAccess = 0)
		end
    end

    -- RETURN SUCCESS 
    return (0) -- sp_MSaddlogin_implicit_ntlogin

 
Last revision 2008RTM
See also

  sp_addlinkedsrvlogin (Procedure)
sp_addsrvrolemember (Procedure)
sp_defaultdb (Procedure)
sp_defaultlanguage (Procedure)
sp_denylogin (Procedure)
sp_grantlogin (Procedure)
       



News

  Query a named instance
Sybase+ASE+silent+install
SQL 2008 R2
Deprecated procedures in SQL2008
Reporting Services item-level role definitions
Create all your missing indexes
Converting datetime field
Start MSSQL Server Profiler at time
Replicating MSSQL Server views
Exploring Microsoft Sharepoint
The OLE DB provider "SQLNCLI10" for linked server indicates.
Mobile solar charger
Oracle to SQL Server replication
Cannot insert the value NULL into column
Undocumented Microsoft SQL Server 2008
VMware
Zoekmachine optimalisatie
SQL Servers hidden objects
FckEditor
Flash in Ajax
De hype die AJAX heet
Barcode scannen
MySQL; Gratis, makkelijk en snel!
PHP
sIFR; de combinatie tussen HTML en Flash