Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Query to find user who last modified user roles/access? Expand / Collapse
Author
Message
Posted Friday, December 6, 2013 9:57 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, September 3, 2014 8:35 AM
Points: 8, Visits: 14
Hello all-

I was recommended to this site for all the wealth of knowledge and I was hoping ya'll could assist me with this. I am new to the DBA world (only 2 months in) and have been granted the power of the "accidental DBA" you could say.

I would like to know if there is a way to find out who changed a users roles/access WITHOUT using the audit function. For example, if a user account was created and given SA access then changed to read only, how can I find out who made that change? I tried searching for an answer, but kept getting no results. I'm thinking this may tie into the sys.sysusers view?

Any help would be very much appreciated and I apologize if I seem to be too noobish.

Post #1520655
Posted Friday, December 6, 2013 10:25 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 1:30 PM
Points: 12,895, Visits: 32,089
DBANoobie (12/6/2013)
Hello all-

I was recommended to this site for all the wealth of knowledge and I was hoping ya'll could assist me with this. I am new to the DBA world (only 2 months in) and have been granted the power of the "accidental DBA" you could say.

I would like to know if there is a way to find out who changed a users roles/access WITHOUT using the audit function. For example, if a user account was created and given SA access then changed to read only, how can I find out who made that change? I tried searching for an answer, but kept getting no results. I'm thinking this may tie into the sys.sysusers view?

Any help would be very much appreciated and I apologize if I seem to be too noobish.


not possible, sorry; changes to data are not tracked; after the fact, there's basically no way to get the information.

I don't want to get your hopes up, because it's difficult, and probably not worth your time digging into it.

you can find out WHEN something occurred, but not by WHO; whodunnit information is never tracked in the log.

there is the possibility of reading When it occurred, and infer who did it(maybe) in the transaction log. (whether yourself via sys.fn_dblog() or via a third party tool)

That's only possible if:

1. the database in question is in FULL recovery mode
2. A FULL BACKUP has been taken prior to the event in question.

I've got a query to read the log for specific table objects, but never for a role or user.

just looking at the code, i don't see how to modify it for trying to track changes to roles; i'd think that since sys.roles, sys.users are system views, it will be exceptionally difficult, if not impossible.


SELECT
[PAGE ID],
[Slot ID],
[AllocUnitId],
[Transaction ID],
[RowLog Contents 0],
[RowLog Contents 1],
[RowLog Contents 3],
[RowLog Contents 4],
[Log Record]
FROM sys.fn_dblog(NULL, NULL)
WHERE AllocUnitId IN (SELECT
[Allocation_unit_id]
FROM sys.allocation_units allocunits
INNER JOIN sys.partitions partitions
ON ( allocunits.type IN ( 1, 3 )
AND partitions.hobt_id = allocunits.container_id )
OR ( allocunits.type = 2
AND partitions.partition_id = allocunits.container_id )
WHERE object_id = object_ID('' + 'dbo.GMACTDISASTER' + ''))
AND Operation IN ( 'LOP_MODIFY_ROW', 'LOP_MODIFY_COLUMNS' )
AND [Context] IN ( 'LCX_HEAP', 'LCX_CLUSTERED' )




Lowell

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1520663
Posted Friday, December 6, 2013 10:51 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Monday, September 15, 2014 8:17 AM
Points: 283, Visits: 1,116
I think OP is asking if there is a way of looking back at changes made to logins.

If so, and you have the default trace running, it can be done as long as the change wasn't too long ago.

I use this:

use master;
set nocount on;

declare @path nvarchar(500)
if HAS_PERMS_BY_NAME(NULL, NULL, 'ALTER TRACE') = 1
select @path = convert(nvarchar(500), value)
from ::fn_trace_getinfo(0) i
join sys.traces t on t.id = i.traceid
where t.is_default = 1 and i.property = 2;

if @path is not null
begin
select @path = reverse(substring(reverse(@path), charindex('\', reverse(@path)), 500)) + N'log.trc'
select last_occurrence, name + isnull(' (' + subclass_name + ')', '') EventName,
DatabaseName, LoginName, RoleName, TargetUserName, TargetLoginName, SessionLoginName, TextData, num_occurrences
from (
select e.name,
v.subclass_name,
df.ApplicationName,
df.DatabaseName,
df.LoginName,
df.RoleName,
df.TargetUserName,
df.TargetLoginName,
df.SessionLoginName,
convert(nvarchar(255), df.TextData) TextData,
max(df.StartTime) last_occurrence,
count(*) num_occurrences
from ::fn_trace_gettable(convert(nvarchar(255), @path), 0) df
join sys.trace_events e ON df.EventClass = e.trace_event_id
left join sys.trace_subclass_values v on v.trace_event_id = e.trace_event_id and v.subclass_value = df.EventSubClass
where e.category_id = 8
and e.trace_event_id <> 175
group by e.name, v.subclass_name, df.ApplicationName, df.DatabaseName, df.LoginName, df.RoleName, df.TargetUserName, df.TargetLoginName, df.SessionLoginName, convert(nvarchar(255), df.TextData)) x
order by last_occurrence desc
end

Hope this helps.



Check Your SQL Servers Quickly and Easily
www.sqlcopilot.com
Post #1520676
Posted Friday, December 6, 2013 12:47 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, September 3, 2014 8:35 AM
Points: 8, Visits: 14
Thank you for the replies.

I did some more brainstorming and researching and read about creating triggers. I'm new to this, so I have no knowledge of creating triggers, but would it be possible to create a trigger to e-mail me when an update was made and by whom?

Ex:

- A user updates a user account role
- Trigger to send an e-mail to me of the information of who did the update, to which account, and when it was modified
- The trigger would be kicked off from sys.sysusers when it was updated

I hope that makes sense.
Post #1520716
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse