Database | Proc | Application | Created | Links |
sybsystemprocs | sp_clearpsexe ![]() | ![]() | 31 Aug 14 | Defects Dependencies |
1 2 /* Sccsid = "%Z% generic/sproc/%M% %I% %G% */ 3 4 /* 5 ** Messages for "sp_clearpsexe" 6 ** 17260, "Can't run %1! from within a transaction." 7 ** 18262, "A non-SA user can not modify attributes of another task." 8 ** 18263, "A non-SA user can only modify its priority value." 9 ** 18265, "No specification for the specified process exists." 10 ** 18266, "'%1!' is not a valid execution attribute" 11 ** 18267, "Failed to clear value of attribute '%1!' for spid '%2!'. Check 12 ** server errorlog for any additional information." 13 */ 14 15 create procedure sp_clearpsexe 16 @spid int, /* name of class */ 17 @exeattr varchar(12) /* name of execution attribute */ 18 as 19 20 declare @attrib_id int, 21 @user_id int, 22 @action int, 23 @my_suid int, 24 @object_type varchar(2), 25 @dummy int, 26 @loc int, 27 @role int, 28 @kernel_mode varchar(15), 29 @attr_val varchar(255) 30 31 select @kernel_mode = @@kernelmode 32 select @action = 3 33 select @user_id = NULL /* Id of user from Syslogins table */ 34 35 /* 36 ** IF we're in a transaction, disallow this since it might make recovery 37 ** impossible. 38 */ 39 IF @@trancount > 0 40 BEGIN 41 /* 42 ** 17260, "Can't run %1! from within a transaction." 43 */ 44 raiserror 17260, "sp_clearpsexe" 45 return (1) 46 END 47 ELSE 48 BEGIN 49 /* Use TSQL mode of unchained transactions */ 50 set chained off 51 END 52 53 /* Dont do "Dirty Reads" */ 54 set transaction isolation level 1 55 56 57 /* Find out if the caller has sa_role. Note that 'sa_role' 58 ** string may be embedded in a user defined role name and 59 ** users with these roles should be checked for permissions. 60 */ 61 select @role = 1 62 select @loc = charindex("sa_role", show_role()) 63 IF (@loc > 0) 64 BEGIN 65 IF (@loc != 1) 66 BEGIN 67 /* check for space just before 'sa_role' string */ 68 IF (ascii(substring(show_role(), (@loc - 1), 8)) != 32) 69 select @role = 0 70 END 71 72 /* check if role string ends in space */ 73 IF ((@role = 1) AND 74 (char_length(substring(show_role(), @loc, 75 (char_length(show_role()) - (@loc - 1)))) != 7) AND 76 (ascii(substring(show_role(), (@loc + 7), 1)) != 32)) 77 78 select @role = 0 79 END 80 ELSE 81 select @role = 0 82 83 84 /* check that user has sa role or modifying self */ 85 IF (@role = 0) 86 BEGIN 87 select @my_suid = (select suid from master..sysprocesses 88 where spid = @spid) 89 IF (@my_suid != suser_id()) 90 BEGIN 91 /* 92 ** 18262, "A non-SA user can not modify attributes of another 93 ** process." 94 */ 95 raiserror 18262 96 return (1) 97 END 98 ELSE IF @exeattr != "priority" 99 BEGIN 100 /* 101 ** 18263, "A non-SA user can only modify its priority value" 102 */ 103 raiserror 18263 104 return (1) 105 END 106 END 107 ELSE 108 /* validate that this guy is really the sa */ 109 IF (proc_role("sa_role") = 0) 110 return 1 111 112 /* check that @exeattr value specified is valid */ 113 IF ((@exeattr != 'priority') 114 and (@exeattr != 'timeslice') 115 and (((@kernel_mode = 'process') AND (@exeattr != 'enginegroup')) 116 OR ((@kernel_mode = 'threaded') AND (@exeattr != 'threadpool')))) 117 BEGIN 118 /* 119 ** 18266, "'%1!' is not a valid execution attribute" 120 */ 121 raiserror 18266, @exeattr 122 return (1) 123 END 124 125 126 127 /* Check that an entry exists in the sysattributes table */ 128 select @attr_val = (select char_value from master..sysattributes where 129 (class = 6 AND 130 attribute = 3 AND 131 object_type = "PS" AND 132 object_info1 = @spid AND 133 object_cinfo = @exeattr)) 134 IF (@attr_val is NULL) 135 BEGIN 136 /* 137 ** 18265, "No specification for the specified process exists." 138 */ 139 raiserror 18265 140 return (1) 141 END 142 143 /* Now hook up with Sysattributes Table */ 144 145 select @attrib_id = 3 146 select @object_type = "PS" 147 BEGIN 148 delete master..sysattributes 149 where class = 6 AND 150 attribute = 3 AND 151 object_type = "PS" AND 152 object_info1 = @spid AND 153 object_cinfo = @exeattr 154 155 IF attrib_notify(6, @attrib_id, @object_type, NULL, @spid, 156 NULL, NULL, @exeattr, NULL, NULL, 157 NULL, NULL, "", @action) = 0 158 BEGIN 159 insert master..sysattributes 160 (class, attribute, object_type, object_info1, object_cinfo, 161 char_value) 162 values (6, 3, 'PS', @spid, @exeattr, @attr_val) 163 164 /* 165 ** 18267, "Failed to clear value of attribute '%1!' for 166 ** spid '%2!'. Check server errorlog for any 167 ** additional information." 168 */ 169 raiserror 18267, @exeattr, @spid 170 return (1) 171 END 172 END 173 return (0) 174
exec sp_procxmode 'sp_clearpsexe', 'AnyMode' go Grant Execute on sp_clearpsexe to public go
DEFECTS | |
![]() | 157 |
![]() | master..sysattributes |
![]() | 31 |
![]() | 88 |
![]() | 129 |
![]() | 130 |
![]() | 149 |
![]() | 150 |
![]() | master..sysprocesses |
![]() | |
![]() | |
![]() | |
![]() | 148 |
![]() | 159 |
![]() | 45 |
![]() | 63 |
![]() | 65 |
![]() | 68 |
![]() | 73 |
![]() | 85 |
![]() | 89 |
![]() | 96 |
![]() | 104 |
![]() | 109 |
![]() | 113 |
![]() | 122 |
![]() | 129 |
![]() | 134 |
![]() | 140 |
![]() | 147 |
![]() | 170 |
![]() | 173 |
![]() | 159 |
![]() | 54 |
![]() | 160 |
![]() (class, attribute, object_type, object, object_info1, object_info2, object_info3, object_cinfo) Intersection: {object_info1, object_type, object_cinfo, attribute, class} | 129 |
![]() (class, attribute, object_type, object, object_info1, object_info2, object_info3, object_cinfo) Intersection: {object_info1, object_type, object_cinfo, attribute, class} | 149 |
![]() | 33 |
![]() | 25 |
![]() | 87 |
![]() | 128 |
![]() | 15 |
![]() | 15 |
![]() | 15 |
DEPENDENCIES |
PROCS AND TABLES USED read_writes table master..sysattributes (1) ![]() reads table master..sysprocesses (1) ![]() |