DatabaseProcApplicationCreatedLinks
sybsystemprocssp_listener  14 déc. 14Defects Propagation Dependencies

1     
2     
3     /*
4     ** Messages for "sp_listener"
5     **
6     ** 17260, "Can't run %1! from within a transaction."
7     ** 19862, "Invalid input: Server name '%1!' matches the remote instance." 
8     ** 18899, "Invalid value supplied to parameter %1!."
9     ** 17325, "The length of input parameter '%1!' is longer than the permissible %2! characters."
10    */
11    
12    /*
13    **	sp_listener cmd, addr, eng
14    **
15    ** This stored procedure is the interface to the
16    ** Dynamic Listener Daemon functionality. It allows
17    ** the sa to start, stop, suspend, resume, reserve,
18    ** network listeners on selected ports and engines.
19    ** The command will execute atomically unless the command
20    ** is reserve or the engine parameter has been specified
21    ** via the keyword remaining.
22    **
23    ** Parameters:
24    **	cmd can be any of the following:
25    **		"start", "stop", "suspend", "resume", "status",
26    **		"reserve", "activate", "unreserve"
27    **	addr can be the name of the running ASE server
28    **		or a "proto:host:port" combination.
29    **		length of addr is at the most MAXDLADDR
30    **
31    **	eng can be any list of engines including ranges such
32    **		as "1-3,5,7,10-12", or the word "remaining"
33    **
34    ** Return Value:
35    **	0 in case of success, 1 in case of error
36    */
37    create or replace procedure sp_listener
38        @cmd varchar(30) = null,
39        @addr varchar(612) = null,
40        @eng varchar(30) = null
41    as
42        declare @nullarg char(1)
43        declare @dummy int
44        declare @status int
45        declare @gp_enabled int
46    
47    
48        if @@trancount > 0
49        begin
50            /* 17260, "Can't run %1! from within a transaction." */
51            raiserror 17260, "sp_listener"
52            return (1)
53        end
54        else
55        begin
56            set chained off
57        end
58    
59        set transaction isolation level 1
60        set nocount on
61    
62        /* 
63        ** If granular permissions is not enabled then sa_role is required.
64        ** If granular permissions is enabled then the permission 'manage server' is
65        ** required.  proc_role and proc_auditperm will also do auditing
66        ** if required. Both will also print error message if required.
67        */
68    
69        select @nullarg = NULL
70        execute @status = sp_aux_checkroleperm "sa_role", "manage server",
71            @nullarg, @gp_enabled output
72    
73        /* For Auditing */
74        if (@gp_enabled = 0)
75        begin
76            if (proc_role("sa_role") = 0)
77                return (1)
78        end
79        else
80        begin
81            select @dummy = proc_auditperm("manage server", @status)
82        end
83    
84        if (@status != 0)
85            return (1)
86    
87        /* Restrict listener command to local instance */
88        if (@@clustermode = "shared disk cluster"
89                and (instance_id(@addr) is not NULL)
90                and (instance_id(@addr) != instance_id()))
91        begin
92            /* 19862, "Invalid input: Server name '%1!' matches the remote instance." */
93            raiserror 19862, @addr
94            return (1)
95        end
96    
97        if (@cmd in ("start", "stop", "suspend", "resume", "status"))
98        begin
99            if (char_length(@addr) > 611)
100           begin
101               /*
102               ** 17325, "The length of input parameter '%1!' is longer than the permissible %2! characters."
103               */
104               raiserror 17325, @addr, 611
105               return (1)
106           end
107           dbcc listener(@cmd, @addr, @eng)
108           if (@@error != 0)
109           begin
110               return (1)
111           end
112       end
113       else
114       begin
115           print "Usage: sp_listener command [,'protocol:machine:port'[,engine]] "
116           print "sp_listener commands:"
117           print "start"
118           print "stop"
119           print "suspend"
120           print "resume"
121           print "status"
122           print "help"
123           print "The type of protocol can be one of the following: "
124           print "tcp, tli, ssltcp, ssltli, winsock, sslnlwnsck, sslwinsock"
125           print "IPV6 addresses should be enclosed in brackets, for ex 'tcp:[2001:ec8:4008:1::123]:80'"
126           print "Note: 'engine' parameter is valid only in process kernel mode"
127       end
128       return (0)
129   
130   


exec sp_procxmode 'sp_listener', 'AnyMode'
go

Grant Execute on sp_listener to public
go
DEFECTS
 MGTP 3 Grant to public sybsystemprocs..sp_listener  
 MUCO 3 Useless Code Useless Brackets 52
 MUCO 3 Useless Code Useless Brackets 74
 MUCO 3 Useless Code Useless Brackets 76
 MUCO 3 Useless Code Useless Brackets 77
 MUCO 3 Useless Code Useless Brackets 84
 MUCO 3 Useless Code Useless Brackets 85
 MUCO 3 Useless Code Useless Brackets 88
 MUCO 3 Useless Code Useless Brackets 94
 MUCO 3 Useless Code Useless Brackets 97
 MUCO 3 Useless Code Useless Brackets 99
 MUCO 3 Useless Code Useless Brackets 105
 MUCO 3 Useless Code Useless Brackets 108
 MUCO 3 Useless Code Useless Brackets 110
 MUCO 3 Useless Code Useless Brackets 128
 QISO 3 Set isolation level 59
 VNRD 3 Variable is not read @dummy 81
 MTR1 2 Metrics: Comments Ratio Comments: 48% 37
 MTR2 2 Metrics: Cyclomatic Complexity Cyclo: 7 = 11dec - 6exi + 2 37
 MTR3 2 Metrics: Query Complexity Complexity: 52 37

DEPENDENCIES
PROCS AND TABLES USED
calls proc sybsystemprocs..sp_aux_checkroleperm  
   reads table master..syscurconfigs (1)  
   reads table master..sysconfigures (1)