sunnuntai 14. maaliskuuta 2010

Authenticated smtp using postfix

I was in a need of virtual email hosting platform, something simple I thought. MySQL for users, postfix for MTA, courier for imap, basic stuff. I have setup similar environment few times already. But the thing that has always bothered me is that I have always failed to configure SASL smtp properly. I have usually tried to fix it few times. But then after a while of going nowhere I have decided to quit. Today I decided once again that I need it, and this time I have even made some progress.

First I somehow found that I need to enable smtps from master.cf:

smtps inet n - n - - smtpd

Logically I then decided to add "smtpd_tls_wrappermode = yes" into main.cf. After this everything seemed working. I configured thunderbird to use ssl imap and SSL SMTP on port 465 and tried sending mail and fetching my (ahem old) emails. All was nice! I even decided to send an email to my client confirming that everything is now working and we can start creating accounts.

After this I decided okay, let's test that everything does really work. First receiving emails.. I logged in into my gmail and sent a test email. Of course it didn't come through..

Log showed me this:
 
Mar 14 21:33:07 [postfix/smtpd] sql_select option missing
Mar 14 21:33:07 [postfix/smtpd] auxpropfunc error no mechanism available_
Mar 14 21:33:07 [postfix/smtpd] initializing the server-side TLS engine
Mar 14 21:33:07 [postfix/smtpd] connect from mail-ww0-f54.google.com[74.125.82.54]
Mar 14 21:33:07 [postfix/smtpd] setting up TLS connection from mail-ww0-f54.google.com[74.125.82.54]
Mar 14 21:33:07 [postfix/smtpd] mail-ww0-f54.google.com[74.125.82.54]: TLS cipher list "ALL:!EXPORT:!LOW:+RC4:@STRENGTH"
Mar 14 21:33:07 [postfix/smtpd] SSL_accept:before/accept initialization
Mar 14 21:33:07 [postfix/smtpd] read from 080C7C18 [080D2A48] (11 bytes => -1 (0xFFFFFFFF))
Mar 14 21:36:15 [postfix/smtpd] SSL_accept error from mail-wy0-f173.google.com[74.125.82.173]: -1
Mar 14 21:36:15 [postfix/smtpd] lost connection after CONNECT from mail-wy0-f173.google.com[74.125.82.173]
Mar 14 21:36:15 [postfix/smtpd] disconnect from mail-wy0-f173.google.com[74.125.82.173]


I then fiddled with all the configurations, disabling stuff, modifying stuff, removing stuff, adding stuff. But alas once again it was evident that SASL had bitten me.. I googled and googled but I found nothing relevant. But then (from totally unrelated issue) someone suggested this: "openssl s_client -connect HOSTNAME:25 -starttls smtp" which then failed to connect. And the issue was clear at last. Postfix was serving ssl connections in port 25. Incoming mails were totally blocked. Of course now everything was easy...

I removed this "smtpd_tls_wrappermode = yes" into main.cf and put it into master.cf like so

smtps inet n - n - - smtpd -o smtpd_tls_wrappermode=yes

And now it seems everything is working perfectly. Next time this should be easy(tm). Now just the last few modifications to the configuration (should not break anything) and I'm done!

keskiviikko 6. tammikuuta 2010

Booting ubuntu on nokia n900

Ubuntu booting on Nokia N900

Ubuntu booting for the first time on N900. Nothing works, can't login or anything.

lauantai 2. tammikuuta 2010

Switching Nokia N900 into portrait mode

Currently there is no xrandr software installed on the Maemo plattform. But xrandr library is there so all you need is a little bit of python to take advantage of it. This is slightly based on https://launchpad.net/python-xrandr . If your python software needs xrandr support on N900 I think that library might be handy.

Anyways this is the code I used:


from ctypes import *
import os
import sys
from pprint import pprint

xlib = cdll.LoadLibrary("libX11.so.6")
rr = cdll.LoadLibrary("libXrandr.so.2")


display = xlib.XOpenDisplay(os.getenv("DISPLAY"))
screen = xlib.XDefaultScreen(display)
root = xlib.XDefaultRootWindow(display, screen)

class XRRScreenConfiguration(Structure):
pass
gsi = rr.XRRGetScreenInfo
gsi.restype = POINTER(XRRScreenConfiguration)
config = gsi(display, root)

current_time = c_ulong()
rr.XRRTimes.restpye = c_ulong
timestamp = rr.XRRTimes(display, screen, byref(current_time))

xccr = rr.XRRConfigCurrentRate
xccr.restype = c_int
rate = xccr(config)

rotation = c_ushort()
size = rr.XRRConfigCurrentConfiguration(config, byref(rotation))


rr.XRRSetScreenConfigAndRate(display,config,root,size,int(sys.argv[1]),rate,timestamp)

So copy that into something like rotate.py and run it like this
  • for portrait mode "python rotate.py 2"
  • for landscape mode "python rotate.py 1"
Portrait mode support is currently lacking but it might have its uses. For example browser currently supports it quite nicely. In the end, I think my Nokia N900 will still be mostly in landscape orientation. Anyways this has been a nice learning experience about python, n900 and xrandr.


Updated daemon version


This will rotate the screen automatically

from ctypes import *
import os
import sys
import time
from math import atan2
from pprint import pprint

xlib = cdll.LoadLibrary("libX11.so.6")
rr = cdll.LoadLibrary("libXrandr.so.2")

def get_rotation():
f = open("/sys/class/i2c-adapter/i2c-3/3-001d/coord", 'r' )
coords = [int(w) for w in f.readline().split()]
f.close()
return coords

print get_rotation()

def rotate(angle):
rr.XRRSetScreenConfigAndRate(display,config,root,size,angle,rate,timestamp)

display = xlib.XOpenDisplay(os.getenv("DISPLAY"))
screen = xlib.XDefaultScreen(display)
root = xlib.XDefaultRootWindow(display, screen)

class XRRScreenConfiguration(Structure):
pass

gsi = rr.XRRGetScreenInfo
gsi.restype = POINTER(XRRScreenConfiguration)
config = gsi(display, root)

current_time = c_ulong()
rr.XRRTimes.restpye = c_ulong
timestamp = rr.XRRTimes(display, screen, byref(current_time))

xccr = rr.XRRConfigCurrentRate
xccr.restype = c_int
rate = xccr(config)

rotation = c_ushort()
size = rr.XRRConfigCurrentConfiguration(config, byref(rotation))

while True:
[x,y,z] = get_rotation()
print x,y,z
if y < -500:
rotate(1)
elif y > 500:
rotate(4)

elif x < -500:
rotate(2)
elif x > 500:
rotate(8)

time.sleep(1)


This also has a bug that will reboot the phone in some situations. Probably related to software that will handle screen rotation also..

Hello world!

So after many many years, I have now bitten the bullet and started blogging. Reason for this is that I just want to get better with my written English. Another and maybe the main point is that I really need a place to publish my computer findings. One of the reasons for choosing blogger and not hosting my own was that I'm hoping that this will somehow affect search-engine visibility.