1 package body DBMS_JVM_EXP_PERMS as
2 EXP_END CONSTANT PLS_INTEGER := 999999;
3 EXP_START CONSTANT PLS_INTEGER := 0;
4 cursor policy_q is select kind, grantee, type_schema,type_name,
5 name,action, enabled from dba_java_policy where
6 enabled='ENABLED';
7 zone PLS_INTEGER := EXP_START;
8
9
10 function grant_sysprivs_exp(version IN varchar2,
11 new_block OUT PLS_INTEGER
12 ) return varchar2 as
13
14 comm_str varchar2(4000);
15 Begin
16 -- Check version is >= 10.2
17 if version < '10.02.00.00.00' then
18 return '';
19 end if;
20
21 sys.dbms_zhelp_ir.check_sys_priv(DBMS_ZHELP_IR.KZSSTA);
22
23 <<exp_done>>
24 if zone = EXP_END then
25 zone := EXP_START;
26 if policy_q%ISOPEN = TRUE then
27 close policy_q;
28 end if;
29 return '';
30 end if;
31
32 comm_str := export_perms(zone, new_block);
33
34 if comm_str is null then
35 zone := EXP_END;
36 goto exp_done;
37 else
38 zone := zone + 1;
39 return comm_str;
40 end if;
41 exception
42 when others then
43 zone := EXP_START;
44 raise;
45 end grant_sysprivs_exp;
46
47 function create_exp(objid IN number,
48 version in varchar2,
49 new_block OUT PLS_INTEGER) return varchar2 as
50 Begin
51 return '';
52 end create_exp;
53
54 function grant_exp (objid IN NUMBER,
55 isdba IN PLS_INTEGER,
56 grantor OUT VARCHAR2,
57 version IN VARCHAR2,
58 new_block OUT PLS_INTEGER) RETURN varchar2 as
59 Begin
60 return '';
61 end grant_exp;
62
63 function audit_exp (objid IN NUMBER,
64 version IN VARCHAR2,
65 new_block OUT PLS_INTEGER) RETURN varchar2 as
66 Begin
67 return '';
68 end audit_exp;
69
70 function audit_sysprivs_exp (version IN VARCHAR2,
71 new_block OUT PLS_INTEGER ) RETURN varchar2 as
72 Begin
73 return '';
74 end audit_sysprivs_exp;
75
76 function drop_exp (objid IN NUMBER,
77 version IN VARCHAR2,
78 new_block OUT PLS_INTEGER) RETURN varchar2 as
79 Begin
80 return '';
81 end drop_exp;
82
83 -- uses the temp_java_perms table built by the first part of import
84 -- and adds permissions and policy permissions as necessary.
85 procedure import_jvm_perms(pcol temp_java_policy) as
86
87 row_count number;
88
89 key number;
90
91 POLICYPERM CONSTANT varchar2(50) :=
92 'oracle.aurora.rdbms.security.PolicyTablePermission';
93
94 class varchar2(500);
95
96 action varchar2(200);
97
98 pol_seq number;
99 run_seq number;
100
101 Begin
102 -- we need to disable the RESTRICTion on RuntimePermission#LoadLibrary
103 select seq into pol_seq from dba_java_policy
104 where kind = 'RESTRICT' and type_schema='SYS'
105 and type_name = POLICYPERM and
106 name = '0:java.lang.RuntimePermission#loadLibrary.*';
107
108 if(pol_seq != 0) then
109 dbms_java.disable_permission(pol_seq);
110 end if;
111
112 select seq into run_seq from dba_java_policy
113 where kind = 'RESTRICT' and type_schema='SYS'
114 and type_name = 'java.lang.RuntimePermission' and
115 name = 'loadLibrary.*';
116
117 if(run_seq != 0) then
118 dbms_java.disable_permission(run_seq);
119 end if;
120
121
122 -- This is the main loop that goes through each record
123 -- and check the target dba_java_policy table to see if there is
124 -- a like permission there already. If not then the permission
125 -- is created.
126
127 for i in pcol.FIRST .. pcol.LAST
128 loop
129 -- Check if permission is already in dba_java_policy
130 select count(*) into row_count from dba_java_policy d where
131 pcol(i).kind = d.kind and
132 pcol(i).grantee = d.grantee and
133 pcol(i).type_schema = d.type_schema and
134 pcol(i).type_name = d.type_name and
135 (pcol(i).name = d.name or (pcol(i).name is null and d.name is null)
136 or ((d.name ='*' or d.name is null) and pcol(i).name != null)) and
137 (pcol(i).action = d.action or (pcol(i).action is null and
138 d.action is null) or ((d.action = '*' or d.action is null) and
139 pcol(i).action != null));
140 -- If this is non-zero then we must grant or restrict
141 if row_count = 0 then
142 -- GRANT
143 if pcol(i).kind = 'GRANT' then
144 -- Policy Permissions are handled differently
145 if pcol(i).type_name = POLICYPERM then
146 if(instr(pcol(i).name,'0',1,1) = 0) then
147 class := pcol(i).name;
148 action := '';
149 else
150 class := substr(pcol(i).name,3,instr(pcol(i).name,'#',1,1)-3);
151 action := substr(pcol(i).name,instr(pcol(i).name,'#',1,1)+1);
152 end if;
153 dbms_java.grant_policy_permission(pcol(i).grantee,
154 pcol(i).type_schema, class, action, key);
155 else -- regular grants
156 dbms_java.grant_permission(pcol(i).grantee,
157 pcol(i).type_schema||':'||pcol(i).type_name,
158 pcol(i).name, pcol(i).action,key);
159 end if;
160 else -- RESTRICT
161 if pcol(i).type_name = POLICYPERM then
162 dbms_java.restrict_permission(pcol(i).grantee,
163 pcol(i).type_schema||':'||POLICYPERM, pcol(i).name,'',key);
164 else
165 dbms_java.restrict_permission(pcol(i).grantee,
166 pcol(i).type_schema||':'||pcol(i).type_name,
167 pcol(i).name, pcol(i).action,key);
168 end if;
169 end if;
170 if pcol(i).enabled = 'DISABLE' then
171 dbms_java.disable_permission(key);
172 end if;
173 else
174 goto end_loop;
175 end if;
176 <<end_loop>>
177 null;
178 end loop;
179
180 -- reenable the RESTRICTions
181 if( pol_seq != 0) then
182 dbms_java.enable_permission(pol_seq);
183 end if;
184 if(run_seq != 0) then
185 dbms_java.enable_permission(run_seq);
186 end if;
187 exception
188 WHEN OTHERS THEN
189 raise;
190 end import_jvm_perms;
191
192 function export_perms(state IN OUT PLS_INTEGER, new_block OUT PLS_INTEGER)
193 return varchar2 as
194
195 kind varchar2(8);
196 grantee varchar2(30);
197 type_schema varchar2(30);
198 type_name varchar2(4000);
199 name varchar2(4000);
200 action varchar2(4000);
201 enabled varchar2(8);
202
203 Begin
204 -- open the dba_java_policy cursor and return temp tale creation
205 IF policy_q%ISOPEN = FALSE and state = 0 THEN
206 open policy_q;
207 new_block := 0;
208 return 'execute immediate (''CREATE TABLE TEMP_JAVA_PRIVS' ||
209 ' AS SELECT KIND, GRANTEE, TYPE_SCHEMA, TYPE_NAME,' ||
210 ' NAME, ACTION, ENABLED FROM DBA_JAVA_POLICY WHERE ROWNUM > 1'');';
211 end if;
212 -- Process the insert commands for import.
213 if policy_q%ISOPEN = TRUE then
214 Fetch policy_q into kind, grantee, type_schema,
215 type_name, name, action, enabled;
216 if policy_q%NOTFOUND OR policy_q%NOTFOUND IS NULL THEN
217 close policy_q;
218 state := EXP_END -1;
219 else
220 -- process each row and right the inserts
221 if state = 1 then
222 new_block := 1;
223 else
224 new_block := 0;
225 end if;
226 return 'INSERT INTO TEMP_JAVA_PRIVS VALUES(''' || kind || ''',''' ||
227 grantee || ''',''' || type_schema || ''',''' || type_name ||
228 ''',''' || name || ''',''' || action || ''',''' ||
229 enabled || ''');';
230 end if;
231 end if;
232 if state = EXP_END-1 then
233 new_block :=1;
234 return
235 'DECLARE
236 TJP DBMS_JVM_EXP_PERMS.TEMP_JAVA_POLICY;
237 CURSOR C1 IS SELECT KIND,GRANTEE,TYPE_SCHEMA,TYPE_NAME,
238 NAME,ACTION,ENABLED FROM TEMP_JAVA_PRIVS;
239 BEGIN
240 OPEN C1;
241 FETCH C1 BULK COLLECT INTO TJP;
242 CLOSE C1;
243 DBMS_JVM_EXP_PERMS.IMPORT_JVM_PERMS(TJP);
244 EXECUTE IMMEDIATE(''DROP TABLE TEMP_JAVA_PRIVS'');
245 END;';
246 end if;
247 -- export is done
248 return '';
249 end export_perms;
250
251 end DBMS_JVM_EXP_PERMS;