Compiling C program remotely on a raspi server running lighttpd: run with user path

135 Views Asked by At

I have been working on a very basic web front-end to gcc on a raspberry pi server running debian 7.6. The end result is that you can compile a single-file C program that you enter into an HTML form served by the Pi, and it posts the C code to the server via ajax and a bash cgi script on the server decodes the html, writes the file to something like main.c, then compiles it. As the user, you get the results of your compilation (either the errors, or a message that it successfully compiled). That's it so far.

I was getting this error when attempting to compile a file remotely:

Error: gcc: error trying to exec 'cc1': execvp: No such file or directory

I don't get this warning when I send the same c file's text to the cgi manually by piping it in via stdin (which is how the post data is retrieved in the remote method), so I assume it has something to do with the server path and whom the server is running the script as, which I think is www-data in this case (my lighttpd.conf file has 'www-data' as the server username and groupname). When I run /usr/bin/env in the cgi script, the path does not include the location of cc1 that find returned.

My solution was to put the location of the cc1 utility that gcc uses in the cgi script itself:

PATH=$PATH:/usr/lib/gcc/arm-linux-gnueabihf/4.6
export PATH

This works, but I am certain that what I'm doing here is not the proper way to go about this and that it would not suffice in a public-facing context. My question is:

What is a better way of allowing remote users to run cgi scripts with the proper paths in place (e.g. so I don't have to put the path of a binary that's not in the www-data user's path in the file)

I'm pretty new to web-server admin and managing cgi scripts: I don't know what I don't know.

0

There are 0 best solutions below