DatabaseProcApplicationCreatedLinks
sybsystemprocssp_helpapptrace  14 déc. 14Defects Propagation Dependencies

1     
2     
3     /*
4     ** Messages for sp_helpapptrace
5     **
6     ** 17260, "Can't run %1! from within a transaction."
7     **
8     */
9     
10    create or replace procedure sp_helpapptrace as
11    
12        declare @low int
13        declare @high int
14        declare @spidlow int
15        declare @spidhigh int
16        declare @dummy int
17        declare @sa_role int /* has sa role */
18        declare @sso_role int /* has sso role */
19        declare @nullarg varchar(1)
20        declare @gp_enabled int
21        declare @status1 int
22        declare @status2 int
23    
24    
25        select @status1 = 1
26        select @status1 = 2
27    
28    
29        /* Dont allow sp_helpapptrace to run with in a transaction */
30        if @@trancount > 0
31        begin
32            /*
33            ** 17260, "Can't run %1! from within a transaction."
34            */
35            raiserror 17260, "sp_helpapptrace"
36            return (1)
37        end
38        else
39        begin
40            set transaction isolation level 1
41            set chained off
42        end
43    
44        /*
45        **  If granular permissions is not enabled then,
46        **  only accounts with SA or SSO role can execute it.
47        **  If granular permissions is enabled then
48        **  users with 'manage server' permission can execute it.
49        */
50        select @nullarg = NULL
51        execute @status1 = sp_aux_checkroleperm "sso_role",
52            "manage server", @nullarg, @gp_enabled output
53        if (@status1 != 0)
54        begin
55            if (@gp_enabled = 0)
56            begin
57                execute @status2 = sp_aux_checkroleperm "sa_role",
58                    @nullarg, @nullarg, @gp_enabled output
59                if (@status2 != 0)
60                begin
61                    /* 
62                    ** proc_role() will raise permission errors
63                    ** and send audit records to the audit trail.
64                    */
65                    select @dummy = proc_role("sa_role")
66                    select @dummy = proc_role("sso_role")
67                    return (1)
68                end
69            end
70            else
71            begin
72                /* 
73                ** Call proc_auditperm here to do auditing and error 
74                ** message. 
75                */
76                select @dummy = proc_auditperm("manage server",
77                        @status1)
78                return (1)
79            end
80        end
81    
82        /* 
83        ** Send apropriate audit records, already determined user has one
84        ** of the roles or the permission. 
85        */
86        if (@gp_enabled = 0)
87        begin
88            if (@status1 = 0)
89                select @dummy = proc_role("sso_role")
90    
91            if (@status2 = 0)
92                select @dummy = proc_role("sa_role")
93        end
94        else
95        begin
96            select @dummy = proc_auditperm("manage server",
97                    @status1)
98        end
99    
100       select @low = @@minsuid, @high = @@maxsuid,
101           @spidlow = @@minspid, @spidhigh = @@maxspid
102   
103       /*
104       ** Find all the sessions currently being traced.
105       */
106   
107       select traced = spid
108       into #table1
109       from master..sysprocesses
110       where suid >= @low and suid <= @high
111           and spid >= @spidlow and spid <= @spidhigh
112           and (convert(int, pssinfo(spid, "tracefile_is_set")) != 0)
113   
114       /*
115       ** Find all the spids and the spids that they are tracing. 
116       ** Note that if the tracer spid has exited then there will be no entry
117       ** for that spid.
118       */
119   
120       select tracer = spid, tracee = convert(int, pssinfo(spid, "trace_spid"))
121       into #table2
122       from master..sysprocesses
123       where suid >= @low and suid <= @high
124           and spid >= @spidlow and spid <= @spidhigh
125   
126       /*
127       ** Now combine the above two tables using LEFT OUTER JOIN. This will
128       ** ensure that there is an entry for even those spids whose tracers
129       ** have exited. Additionally also get the paths of the tracefile for
130       ** traced spids.
131       */
132   
133       select traced_spid = convert(char(10), traced),
134           tracer_spid = isnull(convert(char(10), tracer), 'exited'),
135           trace_file = pssinfo(traced, "trace_fname")
136       into #helpapptrace_result
137       from #table1, #table2
138       where traced *= tracee
139   
140       exec sp_autoformat @fulltabname = #helpapptrace_result,
141           @selectlist = "traced_spid, tracer_spid, trace_file",
142           @orderby = "order by traced_spid"
143   
144       drop table #table1
145       drop table #table2
146       drop table #helpapptrace_result
147   
148       return (0)
149   


exec sp_procxmode 'sp_helpapptrace', 'AnyMode'
go

Grant Execute on sp_helpapptrace to public
go
DEFECTS
 MUSP 4 Unquoted String Parameter sybsystemprocs..sp_autoformat: @fulltabname 140
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 111
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 124
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 138
 TNOI 4 Table with no index master..sysprocesses master..sysprocesses
 MGTP 3 Grant to public master..sysprocesses  
 MGTP 3 Grant to public sybsystemprocs..sp_helpapptrace  
 MNER 3 No Error Check should check @@error after select into 107
 MNER 3 No Error Check should check @@error after select into 120
 MNER 3 No Error Check should check @@error after select into 133
 MNER 3 No Error Check should check return value of exec 140
 MUCO 3 Useless Code Useless Brackets 36
 MUCO 3 Useless Code Useless Brackets 53
 MUCO 3 Useless Code Useless Brackets 55
 MUCO 3 Useless Code Useless Brackets 59
 MUCO 3 Useless Code Useless Brackets 67
 MUCO 3 Useless Code Useless Brackets 78
 MUCO 3 Useless Code Useless Brackets 86
 MUCO 3 Useless Code Useless Brackets 88
 MUCO 3 Useless Code Useless Brackets 91
 MUCO 3 Useless Code Useless Brackets 148
 QISO 3 Set isolation level 40
 QJWT 3 Join or Sarg Without Index on temp table 138
 QNAO 3 Not using ANSI Outer Join 137
 QNUA 3 Should use Alias: Column traced should use alias #table1 133
 QNUA 3 Should use Alias: Column tracer should use alias #table2 134
 QNUA 3 Should use Alias: Column traced should use alias #table1 135
 QNUA 3 Should use Alias: Table #table1 137
 QNUA 3 Should use Alias: Table #table2 137
 QNUA 3 Should use Alias: Column traced should use alias #table1 138
 QNUA 3 Should use Alias: Column tracee should use alias #table2 138
 VNRD 3 Variable is not read @dummy 96
 VUNU 3 Variable is not used @sa_role 17
 VUNU 3 Variable is not used @sso_role 18
 MTR1 2 Metrics: Comments Ratio Comments: 33% 10
 MTR2 2 Metrics: Cyclomatic Complexity Cyclo: 13 = 15dec - 4exi + 2 10
 MTR3 2 Metrics: Query Complexity Complexity: 69 10

DEPENDENCIES
PROCS AND TABLES USED
calls proc sybsystemprocs..sp_aux_checkroleperm  
   reads table master..sysconfigures (1)  
   reads table master..syscurconfigs (1)  
reads table master..sysprocesses (1)  
read_writes table tempdb..#table1 (1) 
read_writes table tempdb..#table2 (1) 
calls proc sybsystemprocs..sp_autoformat  
   writes table sybsystemprocs..sp_autoformat_rset_002 
   reads table tempdb..systypes (1)  
   writes table sybsystemprocs..sp_autoformat_rset_004 
   calls proc sybsystemprocs..sp_autoformat  
   writes table sybsystemprocs..sp_autoformat_rset_003 
   reads table tempdb..syscolumns (1)  
   writes table sybsystemprocs..sp_autoformat_rset_001 
   reads table master..syscolumns (1)  
   read_writes table tempdb..#colinfo_af (1) 
   calls proc sybsystemprocs..sp_namecrack  
   writes table sybsystemprocs..sp_autoformat_rset_005 
   reads table master..systypes (1)  
writes table tempdb..#helpapptrace_result (1)