[GRASS-dev] Re: [GRASS-user] shared access to mapsets

[CC'd to grass-dev]

Duncan Golicher wrote:

Can anyone answer a very simple question. I am running grass6.1 under
Cygwin with all my data on an external hard drive. I recently installed
grass on a new PC. I now can't enter any of the mapsets I created on the
first machine from the second and can only get read access to them from
new mapsets. I have a different username on the second PC so I obviously
don't have permissions. What I can't find out, after Googling and
searching the list, are the steps I should take to change the
permissions, or perhaps the username in cygwin, so I can just share the
database between the two machines.

Apart from any access controls implemented by the OS, GRASS itself
won't let you select a mapset as the current mapset unless you are the
owner of the mapset directory.

[This check is disabled on the native Windows version, as the
functions which it uses aren't present there.]

Note to developers: I'm starting to think that we should seriously
reconsider this restriction. Now that the .gislock file is in the
mapset directory rather than the home directory, is there any point in
having this check?

In general, to change the owner of a file under Windows XP Pro (I
don't know if XP Home is any different), perform the following
(excessively complex) sequence of steps:

[The process is complicated by the fact that even an administrator
cannot "give away" files; you have to permit the intended recipient to
take ownership, then have the recipient actually take ownership of the
files.]

+ Log in using either the account which owns the file or an account
with administrator privileges.

+ In Explorer, choose the "Folder Options ..." item from the "Tools"
menu.

+ Select the "View" tab in the Folder Options dialog.

+ Uncheck the "Use simple file sharing (Recommended)" option.

+ Click "OK".

+ In Explorer, select the file or directory whose ownership you wish
to change.

+ Select the "Properties" option from either the "File" menu or the
context menu (or Alt+Enter).

+ Select the "Security" tab (this tab is only available once you have
disabled simple file sharing as directed above).

+ Click the "Advanced" button.

+ The "Permissions" tab should be selected.

+ Click the "Add..." button.

+ Enter the name of the user to whom you wish to transfer ownership.

+ Press OK.

+ Check the box in the "Take Ownership" row and the "Allow" column.

+ Press OK.

+ Check the "Replace permission entries ..." option.

+ Press OK.

+ Press OK (for the Properties dialog).

+ Log in as the user to whom you wish to transfer ownership.

+ Disable simple file sharing as directed above (this is a per-user
setting).

+ Select the mapset directory in Explorer.

+ Select the "Properties" option from either the "File" menu or the
context menu.

+ Select the "Security" tab.

+ Click the "Advanced" button.

+ Select the "Owner" tab.

+ Select your name from the list.

+ Check the "Replace owner on subcontainers and objects" option.

+ Press OK.

+ Press OK (for the Properties dialog).

Optional: once you've changed the owner, you can remove the "take
ownership" permission entry. Also, you can re-enable simple file
sharing if desired; this will hide the Security tab in the Properties
dialog.

Tip: to save having to switch between your normal account and an
administrative account, create a shortcut to "C:\WINDOWS\explorer.exe"
with the "Run with different credentials" option enabled (click the
"Advanced" button in the shortcut's properties dialog). This lets you
do file management using an administrative account without having to
switch between logins. A few things don't quite work, e.g.
notifications (you have to manually refresh the view with F5 whenever
you change something).

--
Glynn Clements <glynn@gclements.plus.com>

Duncan Golicher wrote:

After going through all the steps I was still locked out! I got the
message that I am currently running GRASS in selected mapset, concurrent
use not allowed.

That specific error means that there is a .gislock file in the mapset
directory. This file is supposed to be removed when you end the GRASS
session, but if the session is terminated abnormally (e.g. system
crash), the file can be left behind. In that case, you need to delete
the .gislock file manually.

You may also get the error if the $GISBASE/etc/lock program is
missing, or if it fails for some other reason. In that situation, you
could just remove the check from the Init.sh script.

I then had some trouble resetting everything to get
back in on the old machine. There must be a simpler solution! (?)

If you want to switch ownership regularly, giving both users the "take
ownership" permission should make it relatively painless to change
ownership. Most of the steps I listed should only be required the
first time.

There might be a way to persuade Cygwin to treat both accounts as
equivalent. Look in Cygwin's /etc/passwd file; if it has entries for
both usernames, using the same UID (third field) for both may solve
the problem (GRASS compares the st_uid field returned from stat() with
the result of getuid() and geteuid()). Also, the presence or "ntsec"
or "nontsec" in the value of the CYGWIN environment variable may have
an effect.

Note that the idea of making new locations is fine, but I have the
data on an external hard drive that I just want to move between two
PCs. Any further suggestions would be very welcome.

If you are willing to compile GRASS yourself from source code, you can
just delete the relevant lines from G__mapset_permissions() and
G__mapset_permissions2() (at the bottom of lib/gis/mapset_msc.c).

Alternatively, you can just use two mapsets, one for each username.
You can use g.mapsets to add additional mapsets to the search path,
which will allow you to access files from either mapset by name
(without having to use the map@mapset syntax).

That isn't ideal, as you won't be able to use g.remove, g.rename or
g.copy on maps which aren't in the current mapset. Also, if you try to
"replace" a map which is in the "other" mapset by creating a new map
with the same name, it will work in the sense that the new map will
"mask" the old one, but if you switch PCs (and mapsets) then the old
map will mask the new one.

--
Glynn Clements <glynn@gclements.plus.com>