December 6, 2013 at 9:57 am
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.
December 6, 2013 at 10:25 am
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
December 6, 2013 at 10:51 am
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.
December 6, 2013 at 12:47 pm
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.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply