Home » RDBMS Server » Networking and Gateways » descriptor not valid
descriptor not valid [message #325469] Fri, 06 June 2008 05:06 Go to next message
amrlekid
Messages: 18
Registered: May 2008
Junior Member
I use Oracle 9i database on Win XP.

in order to call a shel cmd from PLSQL, I've resumed the folling STEPS:

STEP 1: Create an OSCommand Java Class ( ==> Successfully )
STEP 2: Create a Wrapper Function ( ==> Successfully )
STEP 3: I run the pack dbms_java to grant necessary privs to user SYS ( ==> Successfully )
STEP 4: connect to sqlplus using SYS user and run the code bellow :

SQL> Declare
2 x Varchar2(2000);
3 Begin
4 x := OSCommand_Run('dir c:\a*.*');
5 DBMS_OUTPUT.Put_Line(x);
6 End;
7 /
Descripteur non valide


PL/SQL procedure successfully completed.

SQL>




QUESTION:
=========
I'm upset, because I don't have the list of files and directories existing in my hard drive C:\.
I don't know how to change and correct the "listener.ora" and "tnsnames.ora" !
What have I missed ? why does not this work ?
.. Thankful for any help.


Re: descriptor not valid [message #325487 is a reply to message #325469] Fri, 06 June 2008 06:06 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Quote:
connect to sqlplus using SYS user

Very bad

Post the code but before please read OraFAQ Forum Guide, especially "How to format your post?" section.
Make sure that lines of code do not exceed 80 characters when you format.
Indent the code (See SQL Formatter).
Use the "Preview Message" button to verify.
Also always post your Oracle version (4 decimals).

Regards
Michel
Re: descriptor not valid [message #325536 is a reply to message #325487] Fri, 06 June 2008 09:21 Go to previous messageGo to next message
amrlekid
Messages: 18
Registered: May 2008
Junior Member
Quote:
connect to sqlplus using SYS user



STEP 4:

D:\scripts>
D:\scripts>sqlplus /nolog

SQL*Plus: Release 9.2.0.1.0 - Production on Ve Jun 6 15:20:05 2008

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

SQL> conn / as sysdba
Connected.
SQL>
Re: descriptor not valid [message #325538 is a reply to message #325469] Fri, 06 June 2008 09:28 Go to previous messageGo to next message
amrlekid
Messages: 18
Registered: May 2008
Junior Member
STEP 5:

SQL> show echo
echo OFF
SQL> set echo on
SQL> @java\test
SQL> Set Serverout On
SQL> set termout on
SQL>
SQL> Declare
2 x Varchar2(2000);
3 Begin
4 x := OSCommand_Run('dir c:\a*.*');
5 DBMS_OUTPUT.Put_Line(x);
6 End;
7 /
Descripteur non valide


ProcÚdure PL/SQL terminÚe avec succÞs.

SQL>
Re: descriptor not valid [message #325562 is a reply to message #325538] Fri, 06 June 2008 10:19 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Michel Cadot wrote on Fri, 06 June 2008 13:06
Quote:
connect to sqlplus using SYS user

Very bad

Post the code (of called procedure) but before please read OraFAQ Forum Guide, especially "How to format your post?" section.
Make sure that lines of code do not exceed 80 characters when you format.
Indent the code (See SQL Formatter).
Use the "Preview Message" button to verify.Also always post your Oracle version (4 decimals).

Regards
Michel

Re: descriptor not valid [message #325570 is a reply to message #325562] Fri, 06 June 2008 10:32 Go to previous messageGo to next message
amrlekid
Messages: 18
Registered: May 2008
Junior Member
I use Oracle 9i2010 database on Win XP.

in order to call a shel cmd from PLSQL, I've resumed the folling STEPS:

STEP 1: Create an OSCommand Java Class. See code below:

SQL> -- Create the OSCommand Java Class using the following statement:
SQL>
SQL> CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "OSCommand" AS import java.io.*;
2 public class OSCommand
3 {
4 public static String Run(String Command)
5 {
6 try
7 {
8 Runtime.getRuntime().exec(Command);
9 return("0");
10 }
11 catch (Exception e)
12 {
13 System.out.println("Error running command: " + Command +
14 "\n" + e.getMessage());
15 return(e.getMessage());
16 }
17 }
18 }
19 /

Java crÚÚ.

SQL>
Re: descriptor not valid [message #325571 is a reply to message #325469] Fri, 06 June 2008 10:33 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
http://www.orafaq.com/forum/t/88153/0/
Please read & follow posting guidelines as stated in URL above

What you are attempting to implement is a HUGE security hole through which any could abuse any database on this system!

[Updated on: Fri, 06 June 2008 10:34] by Moderator

Report message to a moderator

Re: descriptor not valid [message #325572 is a reply to message #325570] Fri, 06 June 2008 10:34 Go to previous messageGo to next message
amrlekid
Messages: 18
Registered: May 2008
Junior Member
STEP 2: Create a Wrapper Function. See code below:

SQL> -- Create the following Wrapper Function using the following statement:
SQL>
SQL> CREATE or REPLACE FUNCTION OSCommand_Run(Command IN STRING)
2 RETURN VARCHAR2 IS
3 LANGUAGE JAVA
4 NAME 'OSCommand.Run(java.lang.String) return int';
5 /

Fonction crÚÚe.

SQL>
SQL>
Re: descriptor not valid [message #325574 is a reply to message #325469] Fri, 06 June 2008 10:36 Go to previous messageGo to next message
amrlekid
Messages: 18
Registered: May 2008
Junior Member
STEP 3: I run the pack dbms_java to grant necessary privs to user SYS .

See below:


SQL> -- Grant permission to SYS to be able to use java proc created Smile
SQL>
SQL> Execute dbms_java.grant_permission( 'SYS', 'SYS:java.io.FilePermission', '<<ALL FILES>>', 'execute');

ProcÚdure PL/SQL terminÚe avec succÞs.

SQL> execute dbms_java.grant_permission( 'SYS', 'SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '*' );

ProcÚdure PL/SQL terminÚe avec succÞs.

SQL> execute dbms_java.grant_permission( 'SYS', 'SYS:java.lang.RuntimePermission', 'readFileDescriptor', '*' );

ProcÚdure PL/SQL terminÚe avec succÞs.

SQL> Commit;

Validation effectuÚe.

SQL>
SQL>



Re: descriptor not valid [message #325575 is a reply to message #325469] Fri, 06 June 2008 10:37 Go to previous messageGo to next message
amrlekid
Messages: 18
Registered: May 2008
Junior Member
STEP 4:

SQL>
SQL> conn / as sysdba
ConnectÚ.
SQL>
SQL> Set Serverout On
SQL> set termout on
SQL>
SQL> Declare
2 x Varchar2(2000);
3 Begin
4 x := OSCommand_Run('dir c:\a*.*');
5 DBMS_OUTPUT.Put_Line(x);
6 End;
7 /
Descripteur non valide


ProcÚdure PL/SQL terminÚe avec succÞs.

SQL>
SQL>
Re: descriptor not valid [message #325576 is a reply to message #325469] Fri, 06 June 2008 10:38 Go to previous messageGo to next message
amrlekid
Messages: 18
Registered: May 2008
Junior Member
QUESTION:
=========
I'm upset, because I don't have the list of files and directories existing in my hard drive C:\.
I don't know how to change and correct the "listener.ora" and "tnsnames.ora" !
What have I missed ? why does not this work ?
.. Thankful for any help.


Re: descriptor not valid [message #325577 is a reply to message #325469] Fri, 06 June 2008 10:44 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>I'm upset, because I don't have the list of files and directories existing in my hard drive C:\.
You have unrealistic expectations.
The code is launching a new thread at the Operating System level to execute the DIR command.
This thread has NO mechanism for returning the output from the DIR to the session which invoked it.

>I don't know how to change and correct the "listener.ora" and "tnsnames.ora" !
Use the editor of your choosing.
What do these files have to do with the Java code?

Re: descriptor not valid [message #325579 is a reply to message #325576] Fri, 06 June 2008 10:49 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
QUESTIONS
=========
Why don't you follow the advice?
Why don't you try to format your post?
Why don't you use the preview button?
Why don't you use code tags?
Why don't you read the forum guide?

Regards
Michel
Re: descriptor not valid [message #325583 is a reply to message #325577] Fri, 06 June 2008 10:52 Go to previous messageGo to next message
amrlekid
Messages: 18
Registered: May 2008
Junior Member
I meant the following:
May be I should modify "Listener.ora" OR "tnsnames.ora"!!
.. Still I don't know exactly what new statements should be implemented in these 2 files!


..Anyway .
What Solution do you suggest to solve this problem?
Thanks.
Re: descriptor not valid [message #325585 is a reply to message #325469] Fri, 06 June 2008 10:54 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>What Solution do you suggest to solve this problem?
Problem?
What problem?
I do not see any problem.
Re: descriptor not valid [message #325626 is a reply to message #325469] Fri, 06 June 2008 17:26 Go to previous message
amrlekid
Messages: 18
Registered: May 2008
Junior Member
you are not kidding !!
Previous Topic: Problem in starting Listener
Next Topic: TNS Listner
Goto Forum:
  


Current Time: Fri Apr 19 19:49:38 CDT 2024