Sunspot Home. . . . . . Joggler menu

Running lighttpd as root in Ubuntu
-more notes for next time. . . .

This link
:-
http://trevelyn.com/?p=99
showed why I could not run my c code and apps in the Ubuntu Joggler from a web page.

The web server lighttpd that you download for Ubuntu has been castrated - it refuses to run as root.
Good for general security but not if the browser is to run an i2c network in a private LAN and speak temperatures etc.

The link shows how to compile lighttpd and remove the code that stops it running as root

This is my backup - many thanks to Trevelyn

backup of . . . . . http://trevelyn.com/?p=99


-the lighttpd that comes with Ubuntu will not start as the user “root.” In fact, it will fail with the message:

"I will not set uid to 0\n"

This is from 4 if statements in simple C code. All you have to do is re-compile the server after commenting out or removing the if statement lines. Root, or UID0 is needed to do networking tasks and kill processes and such right from your web browser. Let’s edit that code!

The live CD has all of the caches aptitude crap removed for space, so we have to update our database for apt-get repositories:

apt-get update

Let’s remove the old version of lighttpd and all of it’s config files, etc:

/etc/init.d/lighttpd stop && apt-get purge lighttpd && rm -rf /etc/lighttpd

Now, you need two dependencies for building the source code yourself:

apt-get install libbz2-dev libpcre++-dev dpkg-dev zlib1g-dev <-- see below §

Now let’s get the source and put it into a clean directory:

mkdir /devel && cd /devel && apt-get source lighttpd
cd Lighttpd-*
cd src

Change the * to whatever version you end up getting. Now that we are in the src directory, let’s search the source codes for the string “I will not”:

grep 'I will not' *
which yields (at the time of this writing):

server.c: "I will not set uid to 0\n");
server.c: "I will not set gid to 0\n");
spawn-fcgi.c: "I will not set uid to 0\n");
spawn-fcgi.c: "I will not set gid to 0\n");

Now, just edit those two files and comment out the if statements. You can even just simply change them like so:

if (pwd->pw_uid == 0) {
fprintf(stderr, "%s.%d: %s\n",
__FILE__, __LINE__,
"I will set uid to 0, because you are God.\n");
#return -1;
}

cd back into the main source directory and run

./configure && make && make install

Now you should be able to simply run the executable and specify the config file. You may need to copy the config files and init.d files to the right spots, as make install doesn’t really do much. all of these config files that you need are right in the debian folder that is created when you run make in the Lighttpd source directory. Try testing out the new server with the user root:

/usr/sbin/lighttpd -f /devel/Light*/debian/lighttpd.conf

run ps aux and see root is running the new server!

(I just deleted the if statements)

But :-

§ On first trying to compile I got
configure: error: zlib-headers and/or libs where not found, install them or build with --without-zlib

After much Googling I found this to fix it (why is it never easy?)

apt-get install zlib1g-dev
and I needed

apt-get install dpkg-dev

The files created by the compile are not in the correct places in the Ubuntu file structure.
So I saved the file lighttpd
(it is found in usr/local/sbin)
and did :-

apt-get install lighttpd

This does all the detailed work and creates a running web server
I then put the hacked saved file into /usr/sbin to replace the castrated default one

Then in
/etc/lighttpd/lighttpd.conf - - - - (a copy is here
)

I modified the user id

## change uid to <uid> (default: don't care)
#server.username = "www-data"
server.username = "root"

## change uid to <uid> (default: don't care)
#server.groupname = "www-data"
server.groupname = "root"


then

lighty-enable-mod cgi
/etc/init.d/lighttpd force-reload

So now I can run the i2c bus, Sox, flite etc from a link in a browser window!

Sunspot Home . . . . . . . Joggler menu