Thursday, July 26, 2012

Building mod_auth_memcookie on Fedora

Installing mod_auth_memcache on Fedora can be painful and time consuming.  Hopefully the following tips can save you some time.

EDIT:  Changed the broken CVS links with the current SVN links

Some packages you need for the build


  • httpd_devel - This includes /usr/sbin/apxs.  Note there is no /usr/sbin/apxs2 that is originally used by the Makefile.
  • gcc - C compiler used by apxs.

Don't install the dependencies from the Fedora repository (libmemcache, libevent and memcached)

You may be tempted to install libmemcache, libevent or memcached from the Fedora repository.  Don't.  If you do, you run into all sorts of compile errors.  For example libmemcache includes a string.h that overrides the default string.h and breaks everything.  It seems unnecessary to go through the pain to fix it if you can avoid it all together.

Follow the instructions on http://authmemcookie.sourceforge.net/ and build all dependencies from source.  All of them build quickly and install into /usr/local.

Makefile parameters for mod_authmemcookie

After you have built and installed all the dependencies, use the following parameters in the Makefile:
MY_APXS=/usr/sbin/apxs
MY_LDFLAGS=-lmemcache -L/usr/local/lib
MY_CFLAGS=-I/usr/local/include

Patch libmemcache

After you have built and installed all the packages you run into the following message if you try and load the module into Apache:
  Cannot load /etc/httpd/modules/mod_auth_memcookie.so into server: /usr/local/lib/libmemcache.so.0: undefined symbol: mcm_buf_len
While you were building libmemcache you may have seen the following warnings:
 ../include/memcache/buffer.h:73:16: warning: inline function 'mcm_buf_remain_off' declared but never defined [enabled by default] ../include/memcache/buffer.h:72:16: warning: inline function 'mcm_buf_remain' declared but never defined [enabled by default] ../include/memcache/buffer.h:66:19: warning: inline function 'mcm_buf_len' declared but never defined [enabled by default] ../include/memcache/buffer.h:73:16: warning: inline function 'mcm_buf_remain_off' declared but never defined [enabled by default] ../include/memcache/buffer.h:72:16: warning: inline function 'mcm_buf_remain' declared but never defined [enabled by default] ../include/memcache/buffer.h:66:19: warning: inline function 'mcm_buf_len' declared but never defined [enabled by default]
There are posts that proposes a patch for the issue, but I couldn't find one where the links where still working.  Luckily this bug was fixed in BSD Linux, but it is hard to track down.

The links related to this bug are:
http://www.freebsd.org/cgi/query-pr.cgi?pr=143004
http://svnweb.freebsd.org/ports/head/databases/libmemcache/files/patch-fix-inline?revision=248965&view=markup

To apply the patch:
  • go the the libmemcache directory, example: cd $HOME/libmemcache-1.4.0.rc2
  • wget 'http://svnweb.freebsd.org/ports/head/databases/libmemcache/files/patch-fix-inline?revision=248965&view=co' -O libcache.patch
  • patch -p0 < libcache.patch
Now build and install libmemcache again and all should be working.

This was tested on Fedora 16 and Fedora 17, but it seems like the bug has been with us for a while, so it may apply to other versions and distro's.

Thursday, July 29, 2010

How to install TightVNC Server on Ubuntu

The TightVNC server provided by the universe repository of Ubuntu doesn't work well in a xdmcp/gnome environment.

The server frequently crashes (segfaults), keyboard mappings are broken and X forwarding doesn't work out of the box. To let the server crash on Ubuntu 10.04 you had to open a few applications and eventually it would crash when opening or closing an application. Using Ubuntu 9.10 it would always crash when having two apps open like firefox and open office.

Alternative
If you aren't tied to TightVNC, I would suggest using the vnc4server package that doesn't seem to suffer the same issues. I did find it slightly slower and I couldn't run a 8 bit environment effectively. It lost too much information in 8 bit to be usable. When using vnc4server I would suggest a minimum colour depth of 15 bit.

Compile and install the new version of TightVNC from source
The stability is fixed in TightVNC server 1.3.10. The version 1.3.9 currently included in Ubuntu doesn't work.


Unzip the archive and review the README file on how to compile the source. I had to install the following dependencies to build the source:
  • xorg-dev
  • libjpeg62-dev
  • zlib1g-dev
  • xmkmf
It is important to note that you do need to build the viewer and other libraries before going into the XVnc folder and building it.

After the build was successful, use the vncinstall script to copy the required binaries. I installed to /usr/local/bin and had to create the /usr/local/man/man1 directory for the man pages to be copied successfully.

Update alternatives
Since you installed the binaries manually you have to set up the alternatives for XVnc to point to your new libraries.

I always forget the syntax, so here it is for a quick reference:
update-alternatives --install /usr/bin/Xvnc Xvnc /usr/local/bin/Xvnc 80
where /usr/local/bin/Xvnc is your newly built tightvnc viewer.

Make sure your new installation is selected by executing "update-alternatives --config Xvnc"

Configure xdmcp in gdm.
/etc/gdm/custom.conf was missing from my installation and xdmcp wasn't enabled.

Create a /etc/gdm/custom.conf file and add the following content:
[daemon]
Uqser=gdm
Group=gdm


[security]
DisallowTCP=true

[xdmcp]
Enable=true
DisplaysPerHost=2
HonorIndirect=false
MaxPending=4
MaxSessions=16
MaxWait=30
MaxWaitIndirect=30
PingIntervalSeconds=60
Port=177

[greeter]

[chooser]
Multicast=false

[debug]
Enable=true
Setup TightVNC
While setting up VNC it is important to note that your newly built TightVNC server tries to fetch X fonts from a different location to what Ubuntu uses. When you configure the service you have to append the following to the Xvnc command:
-fp /usr/share/fonts/X11/misc/,/usr/share/fonts/X11/Type1/,/usr/share/fonts/X11/75dpi/,/usr/
share/fonts/X11/100dpi/

A service entry will then look something like this:
service vnc-1024x768x8-tightvnc
{
protocol = tcp
socket_type = stream
wait = no
user = nobody
server = /usr/bin/Xvnc
server_args = -inetd -query localhost -once -geometry 1024x768 -depth 8 -fp /usr/share/fonts/X11/misc/,/usr/share/fonts/X11/Type1/,/usr/share/fonts/X11/75dpi/,/usr/share/fonts/X11/100dpi/
}

Follow the instructions on: http://linuxreviews.org/howtos/xvnc, skipping the sections on how to install TightVNC and remember to add the font path (-fp) section from above to the server_args.

Test the server
At this point the server should be up and running and you should be able to connect to the server. If you can't, verify that the font path is correct in your service setup. If TightVNC can't find the font, the server closes the connection without a warning or message. Also check your firewall to see if it is blocking the connection.

At this point X forwarding won't work and your keyboard mappings may be stuffed in gnome.

Keyboard mapping fix
This issue only appears to be affecting gnome. I couldn't find a fix, but there is a workaround where you tell gnome to not do any keyboard mappings.

Add the following line to /etc/gdm/Xsession:
export XKL_XMODMAP_DISABLE=1
and restart the gdm service. The gdm service now uses upstart, so type "restart gdm" to restart it. That line is executed every time a X session starts for a user logging in using gdm.

Enabling X forwarding

Add the following line to /etc/gdm/Xsession:
xhost +localhost
That allows anybody logged into the machine access the the local X server. Have a look at http://www.leidinger.net/X/xhost.html for more details.


Your server should be up and running with no crashing, no keyboard issues and with X forwarding enabled.

I hope you found this post useful and saved some time trying to get TightVNC to work properly.

Until later,
Pieter