Sonar “Close Connection” warning workaround.

Tuesday 2009-10-06

When you use Spring and Ibatis and SQLTemplates, you could have code in your project which looks somewhat like this:

Connection connection = DataSourceUtils.getConnection(getDataSource());
...<do connection stuff here>...
DataSourceUtils.releaseConnection(connection, getDataSource());

Sonar will report that you did not close the connection, while in fact, Spring did that for you. You can not just add a “connection.close()” to the code because the whole point of calling “releaseConnection()” is to have Spring handle all the smart stuff on committing, closing, and returning the connection to the pool if needed.

In our company, not closing the connection is a major blocking violation (and it should be). But in this case, there is no way to make the Jedi wave to Sonar, telling it that “this code will do just fine”. So I added the following trick, albeit a bit dirty:

if (connection.isClosed()){
   // This code is only here to keep Sonar from
   // warning us that the connection is not
   // closed. Please note: Do not just close an
   // unclosed connection, Spring should handle
   // connection closing and returning to the pool.
   connection.close();
}

Use it to your advantage, but use this responsibly. If you see any problems in my solution, or if there is a better way to do this I’d be happy to hear about it.


Block Luntbuild 1.5.1 Anonymous Access

Tuesday 2007-11-13

If you are using luntbuild for your continuous integration builds at work, you probably want to remove anonymous user access. In stead of adding that feature to the administrator “Properties” page where I’d expect it, you have to hack the Spring configuration in the webapps directory of luntbuild. Sigh. Here we go:

Read the rest of this entry »


Phrack still in ASCII

Saturday 2007-08-04

It is a long time since I read this stuff, but I stumbled upon a paper discussing the non-executable stack on OSX (a trick to prevent buffer/stack overflow exploits). Ah, the good old days. And with all this markup, it’s good to see that Phrack magazine stuck to their format. It’s still the same as over 20 years ago… Well written articles, focussed on correctness and content, for the coders out there who are not afraid experimenting with some assembly. The amount of (nightly) hours that go into the research and proof of these articles are unbelievable, and it shows. Read the rest of this entry »


The Digital Revolution

Friday 2007-05-04

Nice example of digital revolution and power to the people can be found at http://blog.outer-court.com/archive/2007-05-02-n67.html. Let’s hope manufacturers understand that people don’t want to pay for crippled content.

Digital copies where copyright is removed are actually better than their DRM protected originals, which makes good willing people move to pirated content, like I stated earlier. The important sentence here being “If I buy a DVD, I have to watch a few minutes of copyrights notices and commercials, without being able to skip them. If I rip it, and re-write it, these notices are gone…”.

Viva la Revolution!


Lost Oracle SYS and SYSTEM password?

Tuesday 2007-01-16

If your administration is as good as anybodies, you are bound to loose the not-so-frequently used password for the SYS and SYSTEM users of oracle. Here are a few ways I found to re-set those passwords:

Method 1: SQLPLUS (Tested on AIX Oracle 9.2.0.1.0)

Log into the database server as a user belonging to ‘dba’ [unix ] or ‘ora_dba’ [windows ] group , typically ‘oracle’, or an administrator on your windos machine. You are able to log into Oracle as SYS user, and change the SYSTEM password by doing the following:

$ sqlplus "/ as sysdba"
SQL*Plus: Release 9.2.0.1.0 - Production on Mon Apr 5 15:32:09 2004

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

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production

SQL> show user

USER is "SYS"

SQL> passw system
Changing password for system
New password:
Retype new password:
Password changed
SQL> quit

Next, we need to change the password of SYS:

$ sqlplus "/ as system"
SQL*Plus: Release 9.2.0.1.0 - Production on Mon Apr 5 15:36:45 2004

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

SP2-0306: Invalid option.
Usage: CONN[ECT] [logon] [AS {SYSDBA|SYSOPER}]
where <logon>  ::= <username>[/<password>][@<connect_string>] | /
Enter user-name: system
Enter password:

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production

SQL> passw sys
Changing password for sys
New password:
Retype new password:
Password changed
SQL> quit

You should now be able to log on the SYS and SYSTEM users, with the passwords you just typed in.

Method 2: Creating pwd file (Tested on Windows Oracle 8.1.7)

  1. Stop the Oracle service of the instance you want to change the passwords of.
  2. Find the PWD###.ora file for this instance, this is usuallly located atC:\oracle\ora81\database\, where ### is the SID of your database.
  3. rename the PWD###.ora file to PWD###.ora.bak for obvious safety reasons.
  4. Create a new pwd file by issuing the command:
    orapwd
    file=C:\oracle\ora81\database\PWD###.ora password=XXXXX
    where ### is the SID and XXXXX is the password you would like to use for the SYS and INTERNAL accounts.
  5. Start the Oracle service for the instance you just fixed. You should be able to get in with the SYS user and change other passwords from there.