0

I've seen people suggest /var/lib but that doesn't work on my system. Every sub-directory of /var is read-only except for /var/lock and /var/log.

Do I just need to write a Linux shell script to grant superuser access? Or is there a Java based solution?

/bin and /usr are both system file directories, so I don't want (nor can I) store files there.

As long as the application needs only to operate within the user I can use:

System.getProperty("user.home") + File.separator + ".appname"'

for the data directory.

But what about persistent system-wide data? Where does that go?

Extra Note: I have this problem with MacOS too. I can use /user/Library/Application Support for user-specific data but I have no way to access global directories.

Second Note: I am aware of and have used the Preferences API. I'm looking for a way to store data excluding that.

bgroenks
  • 1,859
  • 5
  • 34
  • 63
  • What kind of global application data is it? – LtWorf Nov 22 '12 at 21:21
  • Usually, `/var/lib` is used for that. Are you sure you don't have access there? – onon15 Nov 22 '12 at 21:31
  • Why do you need to modify system data as a normal user? – Ignacio Vazquez-Abrams Nov 22 '12 at 22:53
  • I don't need to modify system data, just store non-user specific data for the application. I do not have write access to /var/lib on Linux Mint 13 (MATE). – bgroenks Nov 24 '12 at 20:50
  • What kind of data? Have you seen http://stackoverflow.com/questions/2272639/storing-non-user-specific-application-data-on-mac-linux-permissions?rq=1 and http://stackoverflow.com/questions/1510104/where-to-store-application-data-non-user-specific-on-linux?rq=1 ? – BoppreH Nov 26 '12 at 01:59
  • java is not going to give you a way to work around OS security. if you want to share information between users, you need to find a place to write that information which is _writable from all users_. – jtahlborn Nov 26 '12 at 02:32
  • So essentially... I can't use any of the root folders without root access from installation? Is there a shared/public users directory? – bgroenks Nov 26 '12 at 02:47
  • probably the only folder in the average unix-ish OS which is world writable is `/tmp`. – jtahlborn Nov 26 '12 at 03:15
  • what do you have against the Preferences API? – jtahlborn Nov 26 '12 at 03:15

2 Answers2

1

What is normally done is the application is installed using the system's packaging tools. But you could write your own installer script as well. During the installation process, run as root, a new group may be created, and a new directory under /var/lib is created owned by that group. For example, the locate command does this:

$ ls -l /usr/bin/locate
-rwx--s--x 1 root locate 42032 Nov 17 19:33 /usr/bin/locate

And it's data dir:

drwxr-x--- 2 root locate 4096 Nov 15  2010 /var/lib/slocate

The locate command uses setgid feature to set its own process group ID to locate, that gives it permission to read the /var/lib/slocate subdirectory.

In your case you (your installer) would set write permissions as well so the app can write data there on the users behalf.

Keith
  • 42,110
  • 11
  • 57
  • 76
0

From what I gather the /var/lib/ directory is the correct place to put things. You need to be root when accessing those directories.

You could try using the http://www.freedesktop.org/wiki/Software/polkit toolkit to elevate privileges in linux. (it's free software.)

Something like http://www.amug.org/~glguerin/sw/#authkit might help on a mac.

On Linux you could also have a routine that runs the installation part with gksudo. Or uses the commands mentioned here. https://stackoverflow.com/a/690491/1790338

Hope this helps somewhat.

Community
  • 1
  • 1