DatabaseProcApplicationCreatedLinks
sybsystemprocssp_autoconnect  31 Aug 14Defects 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 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    
26            set nocount on
27    
28            /*
29            ** Check server name.
30            */
31            if not exists (select * from master.dbo.sysservers
32                    where srvname = @server)
33            begin
34                /*
35                ** 18307, "Server name '%1!' does not exist in sysservers."
36                */
37                raiserror 18307, @server
38                return (1)
39            end
40    
41            /*
42            ** Establish login name.  Only the 'sa' can do this for others.
43            */
44            if @loginame is NULL
45                select @loginame = suser_name()
46    
47            /*
48            ** Check login name.
49            */
50            if not exists (select * from master.dbo.syslogins
51                    where name = @loginame and
52                        ((status & 512) != 512)) /* not LOGIN PROFILE */
53            begin
54                /*
55                ** 18314, "Login '%1!' does not exist in syslogins table." 
56                */
57                raiserror 18314, @loginame
58                return (1)
59            end
60    
61            /*
62            ** Check permission to perform operation.  You must be 'sa' to
63            ** modify someone else's autoconnect capabilities.
64            */
65            if suser_id() != 1 and suser_name() != @loginame
66    
67            begin
68                /*
69                ** 18315, "Only the 'sa' can modify another's autoconnect capability."
70                */
71                raiserror 18315
72                return (1)
73            end
74    
75            /*
76            ** check true/false, and set the login status flag accordingly.
77            */
78            select @truefalse = lower(@truefalse)
79            select @flag = 16
80            if @truefalse = "true"
81            begin
82                update master.dbo.syslogins
83                set status = status | @flag,
84                    srvname = @server
85                where name = @loginame
86                /*
87                **  18316, "Autoconnect ON for user '%1!', server '%2!'."
88                */
89                exec sp_getmessage 18316, @msg output
90                print @msg, @loginame, @server
91    
92            end
93            else if @truefalse = "false"
94            begin
95                update master.dbo.syslogins
96                set status = status & ~ @flag,
97                    srvname = NULL
98                where name = @loginame
99                /*
100               **  18317, "Autoconnect OFF for user '%1!', server '%2!'."
101               */
102               exec sp_getmessage 18317, @msg output
103               print @msg, @loginame, @server
104   
105           end
106           else
107           begin
108               /*
109               **  18318, "Unrecognized flag '%1!'; must be either 'true' or 'false'."  	
110               */
111               raiserror 18318, @truefalse
112               return (1)
113           end
114   
115   
116           return (0)
117       end
118   


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) 84
 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 82
 MNER 3 No Error Check should check return value of exec 89
 MNER 3 No Error Check should check @@error after update 95
 MNER 3 No Error Check should check return value of exec 102
 MUCO 3 Useless Code Useless Begin-End Pair 21
 MUCO 3 Useless Code Useless Brackets 38
 MUCO 3 Useless Code Useless Brackets 58
 MUCO 3 Useless Code Useless Brackets 72
 MUCO 3 Useless Code Useless Brackets 112
 MUCO 3 Useless Code Useless Brackets 116
 MUOT 3 Updates outside transaction 95
 MSUB 2 Subquery Marker 31
 MSUB 2 Subquery Marker 50
 MTR1 2 Metrics: Comments Ratio Comments: 47% 17
 MTR2 2 Metrics: Cyclomatic Complexity Cyclo: 5 = 8dec - 5exi + 2 17
 MTR3 2 Metrics: Query Complexity Complexity: 43 17

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