Pam_preprofile 1.1, a swiss army knife for PAM

Pam preprofile is a PAM module that ensures that some program or script is run each time a user logs into the computer. It’s suited for network administrators when they can’t rely on a particular shell to execute the user’s .profile, .bash_profile, .bashrc or similar… because sometimes the user home directory doesn’t even exist yet.

There are already many PAM modules out there, each one suited to a particular need (mounting shares, creating tmp dirs, etc.), but the real advantage of pam_preprofile is its versatility. Pam_preprofile can be used to satisfy any need not being implemented by any existing PAM module at this time but which can be written as a script by the system admin.

The configuration is simple. Just install the module at /lib/security/ and add this line at the end of /etc/pam.d/common-session:

session required pam_preprofile.so /tmp/myprogram.sh /usr/doc

That will call /tmp/myprogram.sh every time the user starts a session (logs into the desktop), passing it a “/usr/doc” parameter, plus an extra parameter with the username being authenticated.

In the previous version of the module, the script was executed always at the session stage. It was very helpful to create the user account. But some weeks ago, a network administrator presented me a scenario where he needed to execute the script each time the system asked the user for a password (that is, at “auth” stage), because the user info could have been updated meanwhile and some local configuration should be updated based on that.

I then improved the module and the new 1.1 version is out. It allow scripts to be executed in the PAM stage you want (account, auth, password and session), not only at the “session” stage allowed by the previous version.

Are you a network administrator? You can download it from:

http://community.igalia.com/twiki/bin/view/Corunix/ProjectDownloadStable

I’ve a landline phone number in USA

I know, I know… having a landline phone number in USA isn’t uncommon if you live there. But the fact is that I don’t live there.

The phone number is offered for free by IpKall and it’s binded to my Gizmo SIP account (VoIP). That way, when you call that number, and if I’m logged into my Gizmo account, I can receive your call. Moreover, if you’ve a Skype account it should be cheap for you to call me. Yes, you’ve catched it: it’s the perfect and cheap (but not free) SIP-Skype bridge.

In fact, I’m thinking to bind the number to the SIP account of the PolyCom we’ve in the office. That way, we could set up a multiconference among some Skype users and the PolyCom.

P.S.: I’m not showing here the real phone number nor the Gizmo account for privacy reasons. If you’d like to know them, just contact me.

A safe upgrade to Diablo

At the end, Maemo Diablo release for N810 is out. But if you have valuable information, programs or configuration on it maybe you’re worried about what you’ll loose in a reflashing. In fact, if you’ve done the upgrade yet you’ll notice that the main part of the apps from Extras repository are missing in Diablo for the moment. Fortunately, there’s a way to install the apps from the old Chinook repository.

Here are six simple steps to perform the upgrade process and restore all your current applications:

  1. Backup your /home/user to a safe place by hand. Standard backup tool won’t
    backup every file you’ve at home and maybe you could need them later…
  2. Do a backup using the backup tool.
  3. Reflash the device with the new image using the flasher tool according to the reflashing instructions
  4. Restore the backup. Some old apps will remain grayshaded because the backup
    tool can’t find them in the now current Diablo repository.
  5. Open Application Manager. Menu, tools, application catalog. Maemo Extras,
    edit. Distribution: chinook, uncheck the “disabled” checkbox, Accept. Close.
  6. Menu, tools, restore applications. Accept.

That’s all. Enjoy your updated device!

How to send SMS in Linux using Skype

Skype for Linux doesn’t support SMS sending from the user interface. But that functionality is in fact implemented in the library and external apps can use it via the public API. I’ve found a working example of that nice feature. Just do these simple steps:

  1. Download Skype4Py from here, uncompress it and install it typing sudo python setup.py install
  2. Download Skype tools 0.11 from here and uncompress it
  3. Open your Skype client and prepare for the authorization dialog that will appear when you execute the next step
  4. Enter into the previous directory and send the SMS: ./send_sms.py +34123123456 My test sms

If the message takes too much to be sent, stop the app (CTRL+C), delete the authorization using the Skype options dialog, and try again. Third and next times worked fine for me.

Shishen Sho Mahjongg 0.3 released

Version 0.3 of Shishen Sho Mahjongg has just been released. The main improvements since 0.2 are: Gravity, hints, undo history, time counter and speed improvements.

You can download the game and know more about it visiting the project page at Maemo Garage.

Enjoy it!

Click here to install this application

28/05/2008 UPDATE: Now the application is also available in Maemo Extras repository and listed in Maemo Downloads with its own green “click to install” icon 🙂

Shishen Sho Mahjongg 0.2 released

Last month I published Shishen Sho Mahjongg for Gtk and Maemo, a board game similar to Mahjongg where the goal is to remove all the tile pairs and two tiles can be removed if a line with a maximum of three segments can be drawn between them.

Today I’m announcing version 0.2. The main improvements since 0.1.1 are Hildon integration (fullscreen, embedded menu, notifications) through conditional compilation and drawing of matching path when two pieces are matched.

You can download the game and know more about the project following these links:

Feel free to send me your comments, suggestions or patches over the original Vala sources.

Thank you! 🙂

Setting up Vala on Maemo and CPP integration

Until now, when I wanted to build some Vala source code for the Maemo platform I generated C code using the i386 Vala compiler and then builded the executable inside the scratchbox using gcc. That was fine until I wanted to use Hildon features (not available for i386). I definitely needed the Vala compiler running on the scratchbox.

This weekend I’ve put myself on the way and managed to compile Vala 0.3.2 on the scratchbox for the CHINOOK_ARMEL target. The process was much simpler than I expected and consisted of these few steps:

  1. Log into the scratchbox and choose CHINOOK_ARMEL
  2. Download the compiler from http://live.gnome.org/Vala/Release (I tried version 0.3.2)
  3. Untar it: tar jxvf vala-0.3.2.tar.bz2
  4. Enter the vala-0.3.2 directory and configure the package for ARMEL cross compiling: ./configure --host=armel
  5. Compile and install: make; make install

Alternately, to build for target CHINOOK_X86, repeat the previous steps but logged into the CHINOOK_X86 target. In step 3, issue ./configure without arguments instead.

That’s it. You have now the Vala compiler ready to be used. But if you want to develop a multiplatform project, you’ll need to avoid compilation of the Hildon related code when not building for Maemo target. The best way I found to do that was to use CPP as a preprocessor to allow me to use #ifdef’s in the code.

This is a simple way to use CPP to preprocess a single file:

cpp -P -Dsymbol1 -Dsymbol2 ... source.vala destination.vala

But I’ve managed to tweak my compilation script to preprocess all the files, write the result to a directory called CPP and finally compiling the result. Here’s the source:

# File compile.sh
export DEFINE=""
export APPNAME="myapp"
export PACKAGES="--thread --pkg gtk+-2.0 --pkg gdk-2.0 --pkg libglade-2.0 --pkg gmodule-2.0"

# Perform preprocessing and output to CPP directory
# Arguments to this script are "defined" and passed to CPP
for i in $@
do
 DEFINE="$DEFINE -D$i"
 case $i in
  MAEMO)
   PACKAGES="$PACKAGES --pkg hildon-1"
   ;;
 esac
done
if [ ! -d CPP ]; then mkdir CPP; fi
for f in *.vala; do cpp -P $DEFINE $f CPP/$f; done
valac $PACKAGES CPP/*.vala -o $APPNAME -X -g -X "-Wl,--export-dynamic -rdynamic"`
rm -rf CPP

The compile.sh script can be used by passing it the symbol set that should be defined. For instance, ./compile.sh MAEMO DEV would define both MAEMO and DEV symbols. Note that with this approach you should check the source files in the CPP directory when errors happen, because the line numbers referenced by the Vala compiler will be related to them and not to the original files.

I think this approach will be useful for other programmers too, so I’ve contributed it to the Vala FAQ (Does Vala have a preprocessor?).

Shishen Sho Mahjongg for Gtk and Maemo

Shishen Sho Mahjongg is a board game similar to Mahjongg. The goal is to remove all the tile pairs. Two tiles can be removed if a line with a maximum of three segments can be drawn between them.

Both the idea and the tile images were taken from kshishen (Shishen Sho 1.5.1), from the package kdegames, which is (C) 1997, Mario Weilguni and distributed under GPL license.

My girlfriend and me are fans of kshishen, so I needed to make a Maemo version to let her play on the N810 internet tablet, free my laptop and let me work on it. O:-)

The game is written in Vala and licensed under the GPL. Vala is a programming language that produces C/GObject source code which can also be compiled independently without the need of the original Vala compiler. Currently, two platforms are supported for the game: i386 (a desktop distribution, eg: Ubuntu Feisty), and also Maemo platform (armel).

21/04/2008 UPDATE: New version 0.1.1 available. Features improved compilation scripts, improved debian package structure and proper installation support from Maemo application manager.

Feel free to send me your comments, suggestions or patches over the original Vala sources. I hope you enjoy the game as much as I enjoyed writing it. 😀

Trying out Android

Android emulator
These weeks I’ve proposed myself to have a look at Google’s Android and try to learn how to write applications on it.

I went to the Android main page and, from there, I followed the “getting started” stuff to download the SDK, Eclipse and started to understand the framework.

The framework is a bit different from what I’m used to. The applications have 4 building blocks:

  • Activity: Tasks that the application performs (from the user point of view). For example, manage a collection of text notes. Activities can also request “intents”, that is, use the system to locate a component that can manage the action that the app wants to be done. For example, edit a single note. Intents are a clever way to reuse functionality.
  • Intent receiver: These are methods to attend external events asynchronously.
  • Service: Functionality provided to another applications by running code in the background.
  • Contend provider: A standard way to provide data to other applications.

Android features nice pieces of code, like SQLite database. The intended way of working relies heavily on XML config files, which make easier to build user interfaces and makes me remember the way UIs are done on other frameworks (I’ve heard that Glade uses XML files too).

My wish about Android would be to develop “Caterpillar”, a robotized (this is, for Android) version of Berto’s Vagalume. But for that there’s still a long way to go through.

At this moment, I’ve already created the “Hello Android” app and I’m following the tutorial. I’ve just completed exercise 2 this night. As I advance more, I’ll update this post to let you know about my progress.

UPDATE: 26/01/2008

The three exercises of the tutorial plus the extra credit one are now completed. The next step will be to have a look to common Android tasks and to continue learning from there. I’d also like to try DroidDraw for GUI designing.

UPDATE: 30/01/2008

I’ve started to write Caterpillar. An early version of the GUI was designed using DroidDraw (see the previous update) and fine tuned by hand. Fortunately, DroidDraw lets you not only export, but also import a layout text description.

The very first task I tried was to try to play an arbitrary MP3 file. I looked into the media APIs and tried some methods to load the test sound (as a raw resource, as an external URL and as a local file), but didn’t succeed. At first I thought that the emulator hadn’t the audio enabled, but after adding the “-useaudio” option, that shown not to be the problem.

Then I found this post (spanish) and this other that gave me some hints. At this moment I know that the sound system works, because I can hear the system sound when raising up the volume, but my media player instance is still null, despite I’m using an MP3 lesser than 1 MB in size. Yeah, the emulator has a 1 MB limitation on that. :-/

UPDATE: 03/02/2008

On this Google groups thread there are people saying that Android has problems playing MP3 from online streams, because it pretends to copy the whole stream to disk (SD card or whatever) and then play it. The problem has been reported to the Android bug tracking system.

UPDATE: 02/03/2008

After a month of silence I have to say that I’ve continued my work on Caterpillar in my spare time. Having a look to the Vagalume source code and doing some tests with Firefox and wget, I’ve developed the session management and playlist fetching and parsing code, so I can end up with a bunch of tracks and all the required information about them: title, author, album, picture, audio file URL…

I’ve decided to overcome the limitations of the Android media player by downloading the tracks one by one and feeding them to the media player as local files, erasing them when the media player has finished playing each one. It’s a bit weird solution but is the only one I’ve found.

The TrackDownloader, as I’ve named it, is created by the controller, which registers itself as an observer. When the downloader has got enough data, it notifies the controller, which starts up the media player. In the meanwhile, the downloader keeps downloading in the background and, when the transfer is about to finish, notifies the controller about that, just to spawn another TrackDownloader for the next track. When the track has definitely ended, the controller dismisses it and it’s erased from disk to save space. I haven’t tested the TrackDownloader for the moment, only coded it.

I’ll keep hacking. Stay tuned!