DatabaseProcApplicationCreatedLinks
sybsystemprocssp_autoconnect  14 déc. 14Defects Propagation Dependencies

1     
2     /* Sccsid = "%Z% generic/sproc/src/%M% %I% %G%" */
3     
4     /*
5     ** Omni only
6     **
7     ** Messages for "sp_autoconnect"	18314
8     ** 
9     ** 18307, "Server name '%1!' does not exist in sysservers."
10    ** 18314, "Login '%1!' does not exist in syslogins table."
11    ** 18315, "Only the 'sa' can modify another's autoconnect capability."
12    ** 18316, "Autoconnect ON for user '%1!', server '%2!'."
13    ** 18317, "Autoconnect OFF for user '%1!' server '%2!'."
14    ** 18318, "Unrecognized flag '%1!'; must be either 'true' or 'false'."
15    */
16    
17    create or replace procedure sp_autoconnect
18        @server varchar(92), /* remote server name */
19        @truefalse varchar(10), /* enable/disable autoconnect */
20        @loginame varchar(30) = NULL /* login name to enable/disable */
21    as begin
22    
23            declare @flag int,
24                @msg varchar(1024),
25                @nullarg char(1),
26                @status int,
27                @dummy int,
28                @sa_id int,
29                @gp_enabled int
30    
31    
32            select @sa_id = 1
33            select @status = 1
34    
35            set nocount on
36    
37            /*
38            ** Check server name.
39            */
40            if not exists (select * from master.dbo.sysservers
41                    where srvname = @server)
42            begin
43                /*
44                ** 18307, "Server name '%1!' does not exist in sysservers."
45                */
46                raiserror 18307, @server
47                return (1)
48            end
49    
50            /*
51            ** Establish login name.  Only the 'sa' can do this for others.
52            */
53            if @loginame is NULL
54                select @loginame = suser_name()
55    
56            /*
57            ** Check login name.
58            */
59            if not exists (select * from master.dbo.syslogins
60                    where name = @loginame and
61                        ((status & 512) != 512)) /* not LOGIN PROFILE */
62            begin
63                /*
64                ** 18314, "Login '%1!' does not exist in syslogins table." 
65                */
66                raiserror 18314, @loginame
67                return (1)
68            end
69    
70            /*
71            ** Check permission to perform operation.  You must be 'sa' to
72            ** modify someone else's autoconnect capabilities.
73            */
74    
75            if user_name() != @loginame
76            begin -- {
77                select @nullarg = NULL
78                /* Checking to see if user has sa_role or "manage any login. */
79                execute @status = sp_aux_checkroleperm "sa_role",
80                    "manage any login", @nullarg, @gp_enabled output
81    
82                if (@gp_enabled = 0)
83                begin
84                    if (proc_role("sa_role") = 0)
85                        return 1
86                end
87                else
88                begin
89                    select @dummy = proc_auditperm("manage any login",
90                            @status)
91                end
92                if (@status > 0)
93                    return (1)
94            end -- }
95    
96            /*
97            ** check true/false, and set the login status flag accordingly.
98            */
99            select @truefalse = lower(@truefalse)
100           select @flag = 16
101           if @truefalse = "true"
102           begin
103               update master.dbo.syslogins
104               set status = status | @flag,
105                   srvname = @server
106               where name = @loginame
107               /*
108               **  18316, "Autoconnect ON for user '%1!', server '%2!'."
109               */
110               exec sp_getmessage 18316, @msg output
111               print @msg, @loginame, @server
112   
113           end
114           else if @truefalse = "false"
115           begin
116               update master.dbo.syslogins
117               set status = status & ~ @flag,
118                   srvname = NULL
119               where name = @loginame
120               /*
121               **  18317, "Autoconnect OFF for user '%1!', server '%2!'."
122               */
123               exec sp_getmessage 18317, @msg output
124               print @msg, @loginame, @server
125   
126           end
127           else
128           begin
129               /*
130               **  18318, "Unrecognized flag '%1!'; must be either 'true' or 'false'."  	
131               */
132               raiserror 18318, @truefalse
133               return (1)
134           end
135   
136   
137           return (0)
138       end
139   


exec sp_procxmode 'sp_autoconnect', 'AnyMode'
go

Grant Execute on sp_autoconnect to public
go
DEFECTS
 MTYP 4 Assignment type mismatch srvname: varchar(30) = varchar(92) 105
 MGTP 3 Grant to public master..syslogins  
 MGTP 3 Grant to public master..sysservers  
 MGTP 3 Grant to public sybsystemprocs..sp_autoconnect  
 MNER 3 No Error Check should check @@error after update 103
 MNER 3 No Error Check should check return value of exec 110
 MNER 3 No Error Check should check @@error after update 116
 MNER 3 No Error Check should check return value of exec 123
 MUCO 3 Useless Code Useless Begin-End Pair 21
 MUCO 3 Useless Code Useless Brackets 47
 MUCO 3 Useless Code Useless Brackets 67
 MUCO 3 Useless Code Useless Brackets 82
 MUCO 3 Useless Code Useless Brackets 84
 MUCO 3 Useless Code Useless Brackets 92
 MUCO 3 Useless Code Useless Brackets 93
 MUCO 3 Useless Code Useless Brackets 133
 MUCO 3 Useless Code Useless Brackets 137
 MUOT 3 Updates outside transaction 116
 VNRD 3 Variable is not read @sa_id 32
 VNRD 3 Variable is not read @dummy 89
 MSUB 2 Subquery Marker 40
 MSUB 2 Subquery Marker 59
 MTR1 2 Metrics: Comments Ratio Comments: 43% 17
 MTR2 2 Metrics: Cyclomatic Complexity Cyclo: 7 = 11dec - 6exi + 2 17
 MTR3 2 Metrics: Query Complexity Complexity: 53 17

DATA PROPAGATION detailed
ColumnWritten To
@serversyslogins.srvname  

DEPENDENCIES
PROCS AND TABLES USED
read_writes table master..syslogins (1)  
calls proc sybsystemprocs..sp_aux_checkroleperm  
   reads table master..syscurconfigs (1)  
   reads table master..sysconfigures (1)  
calls proc sybsystemprocs..sp_getmessage  
   reads table master..syslanguages (1)  
   reads table sybsystemprocs..sysusermessages  
   calls proc sybsystemprocs..sp_validlang  
      reads table master..syslanguages (1)  
   reads table master..sysmessages (1)  
reads table master..sysservers (1)