Thursday, March 30, 2006

Hunting down invalid signatures

I have spent the last few days trying to hunt down an archive problem in a notes mail file. In doing this, I wrote a small lotusscript button to verify signatures that I can share here.

This could be written in the C API. However, keeping it in a button makes it easy to email out to users for them to test.

Const MAXUSERNAME =256
Declare Function NSFNoteVerifySignature Lib "nnotes.dll" Alias "NSFNoteVerifySignature" ( Byval hNote As Long, Byval null1 As Long, Byval null2 As Long, Byval retSigner As String, Byval retCertifier As String) As Integer
Declare Function NSFNoteUnsign Lib "nnotes.dll" Alias "NSFNoteUnsign" ( Byval hNote As Long) As Integer
Const NOERROR = 0
Const PKG_NSF = 512
Const ERR_NOTE_NOT_SIGNED = PKG_NSF+89 'Document is not signed
Const ERR_NOTE_INVSIG2 = PKG_NSF+91 'Document has been modified or corrupted since signed! (data)

Sub Click(Source As Button)
Dim ses As New NotesSession, irc As Integer
Dim retSigner As String, retCertifier As String
Dim doc As notesdocument, vw As NotesView
Dim db As notesdatabase
Dim dc As notesdocumentcollection
Dim fileNum%
Dim i As Integer, count As Integer

Set vw = ses.currentdatabase.views(0)
Set db = ses.currentdatabase

fileNum% = Freefile
Open "c:\temp\signatures.txt" For Output As fileNum%


Set dc = db.GetProfileDocCollection()
Set doc = dc.GetFirstDocument
count = dc.Count
i = 1
Print "Check profile Notes: " &Cstr(count)
While Not doc Is Nothing
Call fix_signature(doc, fileNum, i, count)
i = i + 1
Set doc = dc.GetNextDocument(doc)
Wend

Set dc = db.AllDocuments
Set doc = dc.GetFirstDocument
count = dc.Count
i = 1
Print "Check data Notes: " &Cstr(count)
While Not doc Is Nothing
Call fix_signature(doc, fileNum, i, count)
i = i + 1
Set doc = dc.GetNextDocument(doc)
Wend

Close fileNum%
End Sub

Sub fix_signature(doc As notesdocument, fileNum%, i, count)
Dim textline As String
retSigner = String$(MAXUSERNAME ,Chr(0))
retCertifier = String$(MAXUSERNAME ,Chr(0))

irc%= NSFNoteVerifySignature (doc.handle, 0, 0, retSigner, retCertifier)
Print Cstr(i) &"/" &Str(count)
If irc% = NOERROR Then
textline = "SIGNED: " &Cstr(doc.NoteID) &" " &Left(retSigner, Instr(retSigner,Chr(0))-1)
Write #fileNum%, textline
Elseif irc% = ERR_NOTE_NOT_SIGNED Then
textline = "NO SIGNATURE: " &Cstr(doc.NoteID)
Write #fileNum%, textline
Elseif irc% = ERR_NOTE_INVSIG2 Then
textline = "INVALID_SIGNATURE: " &Cstr(doc.NoteID)
irc% = NSFNoteUnsign(doc.handle)
If (irc% = NO_ERROR) Then
Call doc.Save(True, False)
textline = "REMOVED SIGNATURE: " &Cstr(doc.NoteID)
Else
textline = "COULD NOT REMOVE SIGNATURE: " &Cstr(doc.NoteID)
End If
Write #fileNum%, textline
Else
textline = "ERR: " &Cstr(irc%) &" " &Cstr(doc.NoteID)
Write #fileNum%, textline
End If
End Sub

Friday, March 17, 2006

Updated Full Text Wiki for Ruby on Rails

I have been playing with Ruby on Rails for a while now and started to use it with MySql's full text searching abilities.
I added some code to a search library on the Ruby on Rails wiki - hope it helps others in the space
see: http://wiki.rubyonrails.org/rails/pages/TextSearch

Tuesday, March 14, 2006

FastCGI failing on Fedora with Ruby on Rails

After battling with all the FAQ and wikis getting FastCGI to work with Apache, I found the last problem. FastCGI spawns temporary files in your /etc/httpd/log/fastcgi/dynamic directory (unless you override this in your http.conf file).

I was still getting these errors:

[Mon Mar 13 17:03:08 2006] [crit] (13)Permission denied: FastCGI: can't create (dynamic) server "/var/www/html/test.rails/public/dispatch.fcgi": bind() failed [/tmp/fastcgi/dynamic/a452aa13feeda365028a2d43d1b2ce13]

It turned out that my problem was SELinux getting in the way. It really locks down what the apache user can do (which is probably a really good thing). However, for fastcgi it was locked down a little too much. I intend to now fight a little with SELinux to see if I can get it to play nice.

If you want to temporarily disable it, you can run this command:

echo "0" >/selinux/enforce

you can echo a "1" to turn it back on.

Thursday, March 09, 2006

Looking forward to some Sun

We are in London now until the 21st when we go back to Concord and had a good week of rain and clouds. It is really amazing how a little bit of sun goes a long way in the winter. Coming from Brisbane, you really took the sun for granted where here and in Concord you notice it and try to make the most of it. All said, I could really use a few sunny days here in London and hope for the best.