Re: Baked-in paths

2010-03-15 Thread Reuben Thomas
On 15 March 2010 01:30, Bob Friesenhahn bfrie...@simple.dallas.tx.us wrote:
 On Sun, 14 Mar 2010, Reuben Thomas wrote:

 I imagine this question has been asked before, but searching the
 archives, the net and the manual didn't help me with the following:

 I have a C program which loads some scripts at runtime. These are
 stored in datadir (e.g. /usr/local/share/prog). But I also want to be
 able to run the program from its build directory.

 At the moment I bake in the relevant path; I imagine that for make
 install I have to rebuild the binary, baking in the installation
 path, having baked the build directory path in a normal make.

 Is there a recommended way to deal with this situation?

 I use environment variables to tell the test programs where the source
 directory is.

This does indeed sound like a security weakness.

  If the test programs are executed via a test script, then the
 test script can format program arguments appropriately.

There are no program arguments for this case, because the scripts are
part of the program: the program is written partly in C, partly in
Lua.

  If you also test
 using your main installable program, you need to take care that any embedded
 environment variables don't cause a security problem.

That is why I was asking whether automake would let me make make
install build another version with a different path baked in.

It is sounding as though the answer is no, in which case I may just
end up baking the Lua into the C program, since that is
straightforward, but it does seem to be a weakness of the autotools
for this case.

-- 
http://rrt.sc3d.org




Re: Baked-in paths

2010-03-15 Thread Steffen Dettmer
On Sun, Mar 14, 2010 at 11:29 PM, Reuben Thomas r...@sc3d.org wrote:
 I have a C program which loads some scripts at runtime. These are
 stored in datadir (e.g. /usr/local/share/prog). But I also want to be
 able to run the program from its build directory.

We have some similar situations but failed to find one solution
working well in all cases.
For unit tests, we sometimes (run-time) re-configure the test
object. This might be as simple as:

  static const char *configPath_ = /usr/local/share/prog;
  const char *getConfigPath(void) { return configPath_); }
  void setTestConfigPath(void) { configPath_ = .; }

If the application has something like:

int main(int argc, char *argv[]) { return appXyzMain(argc, argv); }

the test can call appXyzMain with an argv containing `--data-dir=.' option.

Then there are cases where it seems suited to have a list of
directories where to search:

  const char *paths[] { ./tests/, /usr/local/share/, /usr/share };

Some tools (helper scripts) even `guess' if they run from a
sandbox (e.g. by looking if a file Makefile exists in same
directory or compare $argv[0] with @prefix@, but all this seems
to be tricky and surely not portable).

oki,

Steffen




Re: Baked-in paths

2010-03-15 Thread John Calcote

Hi Reuben,

On 3/14/2010 4:29 PM, Reuben Thomas wrote:

I imagine this question has been asked before, but searching the
archives, the net and the manual didn't help me with the following:

I have a C program which loads some scripts at runtime. These are
stored in datadir (e.g. /usr/local/share/prog). But I also want to be
able to run the program from its build directory.

At the moment I bake in the relevant path; I imagine that for make
install I have to rebuild the binary, baking in the installation
path, having baked the build directory path in a normal make.

Is there a recommended way to deal with this situation?

   


The software packages I've worked on have all been complex enough to 
warrant a configuration file in the system config directory (/etc, 
whatever), which is locked down by virtue of its location. Since only 
the administrator can change the contents of a file in $(sysconfdir), 
it's not a security issue.


But what this does allow me to do is generate an installed configuration 
file with reasonable default paths derived from $(prefix) variables. At 
the same time, I bake default paths into the application, which are also 
derived from $(prefix) variables and passed on the compiler command 
line. This allows me to run without a config file, as long as the app is 
properly installed. Finally, the key benefit is that I can run my 
program in test mode by supplying an appropriate config file on the 
command line (./program -c testconfig.ini).


I love the flexibility this system provides, and I don't see any 
security issues with it, unless your program must be run as root in 
order to do what it needs to do. In that case, it's not safe to execute 
it during make check anyway. But it can be executed during make 
installcheck.


John





Baked-in paths

2010-03-14 Thread Reuben Thomas
I imagine this question has been asked before, but searching the
archives, the net and the manual didn't help me with the following:

I have a C program which loads some scripts at runtime. These are
stored in datadir (e.g. /usr/local/share/prog). But I also want to be
able to run the program from its build directory.

At the moment I bake in the relevant path; I imagine that for make
install I have to rebuild the binary, baking in the installation
path, having baked the build directory path in a normal make.

Is there a recommended way to deal with this situation?

-- 
http://rrt.sc3d.org




Re: Baked-in paths

2010-03-14 Thread Martin Kalbfuß
Am Sonntag, den 14.03.2010, 22:29 + schrieb Reuben Thomas:
 I imagine this question has been asked before, but searching the
 archives, the net and the manual didn't help me with the following:
 
 I have a C program which loads some scripts at runtime. These are
 stored in datadir (e.g. /usr/local/share/prog). But I also want to be
 able to run the program from its build directory.
 
 At the moment I bake in the relevant path; I imagine that for make
 install I have to rebuild the binary, baking in the installation
 path, having baked the build directory path in a normal make.
 
 Is there a recommended way to deal with this situation?
 

set the install prefix to a sub directory of your build directory, This
way you can test your application, using the datadir path, without
installing it into the system.