Showing posts with label pullthis. Show all posts
Showing posts with label pullthis. Show all posts

Thursday, March 22, 2012

Create a database login in the default domain

I'm trying to create a login in the default domain. I know I can pull
this information from xp_loginconfig, but don't see how I can use it in
the context of sp_grantlogin.

For example, pull the domain the user is currently logged in on and
insert it into the sp_grantlogin script. Has anyone ever done this in
the past?"Aaron" <aaronakzin@.yahoo.com> wrote in message
news:1104954562.282980.203900@.z14g2000cwz.googlegr oups.com...
> I'm trying to create a login in the default domain. I know I can pull
> this information from xp_loginconfig, but don't see how I can use it in
> the context of sp_grantlogin.
> For example, pull the domain the user is currently logged in on and
> insert it into the sp_grantlogin script. Has anyone ever done this in
> the past?

First of all, I strongly suggest that you consider adding domain accounts to
a domain group, and then just grant login to the group - that's much easier
to manage (and it's the MS recommended way to implement security).

I'm not sure I really understood your question - do you mean that given the
Windows domain account name 'Someone', you want to find the default domain
name from xp_loginconfig (let's call it SOMEDOMAIN), and then grant login to
'SOMEDOMAIN\Someone'? If so, see the (untested) code below.

If I misunderstood you, you might want to give a specific example of what
you're trying to do.

Simon

create proc dbo.GrantLogin
@.Account sysname
as
begin
declare @.Domain sysname,
@.Login sysname

create table #t
(Attrib sysname, Val sysname)

insert into #t exec master..xp_loginconfig

select @.Domain = Val
from #t
where Attrib = 'default domain'

set @.Login = @.Domain + '\' + @.Account

exec sp_grantlogin @.Login
end|||Great, this seems perfect. Thanks for your help.