You are not logged in.

#1 2016-12-18 15:44:06

kde35
Member
Registered: 2015-04-13
Posts: 74

"locate" not working because of permission problem? [Solved]

Hi, on one of the machines running archlinux, I have run into this problem.  I can use "locate" command as root,
but not as a normal user.

$ locate uid
locate: can not stat () `/var/lib/mlocate/mlocate.db': Permission denied

As a matter of fact, if I check the permission, I see

 ls -l /var/lib/
...
drwxr-x--- 2 root locate 4096 14 déc.   2014 locate
...
drwxr-x--- 2 root locate 4096 18 déc.  11:51 mlocate

And, the normal user account doesn't belong to the "locate" group.  However,  the situation is exactly same on the
other machine where the command works perfectly fine.  Any idea on what is wrong?

(Edited after the comment of x33a)

Last edited by kde35 (2016-12-18 17:06:20)

Offline

#2 2016-12-18 15:59:28

x33a
Forum Fellow
Registered: 2009-08-15
Posts: 4,587

Re: "locate" not working because of permission problem? [Solved]

I don't see the mlocate directory in your ls output. It says locate.

Offline

#3 2016-12-18 16:08:25

kde35
Member
Registered: 2015-04-13
Posts: 74

Re: "locate" not working because of permission problem? [Solved]

oops...  I copy-pasted a wrong line.  The post is now corrected.

Offline

#4 2016-12-18 16:18:36

x33a
Forum Fellow
Registered: 2009-08-15
Posts: 4,587

Re: "locate" not working because of permission problem? [Solved]

Well I can't say why it works on your other machines, but as you can see here: https://git.archlinux.org/svntogit/pack … es/mlocate

It is specifically supposed to be accessible to only root and members of the locate group. So, just add your user to the locate group and it should work.

Offline

#5 2016-12-18 16:21:28

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 79,182

Re: "locate" not working because of permission problem? [Solved]

No idea about the actual cause for the setup, but "stat `which locate`" - it should be root:locate and have the suid  bit set, ie. be "2755"
This explains why locate can access the file.

Offline

#6 2016-12-18 16:47:00

kde35
Member
Registered: 2015-04-13
Posts: 74

Re: "locate" not working because of permission problem? [Solved]

x33a wrote:

Well I can't say why it works on your other machines, but as you can see here: https://git.archlinux.org/svntogit/pack … es/mlocate

It is specifically supposed to be accessible to only root and members of the locate group. So, just add your user to the locate group and it should work.

Thank you very much.  Well, I am sure that this should work and will work, but I would rather have a "clean" solution.  That is, if I add another user tomorrow, then I still will remember that I will have to put him in the locate group, but if I add another user in several months, chances are that I won't remember it.  So if you don't mind, I still don't consider the problem as solved.

Offline

#7 2016-12-18 16:56:57

ayekat
Member
Registered: 2011-01-17
Posts: 1,634

Re: "locate" not working because of permission problem? [Solved]

kde35 wrote:

Well, I am sure that this should work and will work, but I would rather have a "clean" solution.  That is, if I add another user tomorrow, then I still will remember that I will have to put him in the locate group, but if I add another user in several months, chances are that I won't remember it.

But what would be the cleanest solution according to you? The mlocate database is accessible to all users in the `locate` group, so users need to be in the `locate` group in order to use the `locate` command. This seems pretty clean to me (in fact, it seems the cleanest to me). It's like adding users to the `wheel` group to give them permission to run `sudo`.

If you want all users to have access to the database by default, make the directory 755 (and probably the database file 644). Although pacman will complain about mismatching permissions on that directory, you will at least know why.

--edit--
Although, if the setgid bit is set on the executable, it should work for all users anyway, so the problem must lie somewhere else... I'm sorry for the noise.

Last edited by ayekat (2016-12-18 17:07:57)


pkgs │ hacks │ cfg │ blag

Offline

#8 2016-12-18 16:57:27

kde35
Member
Registered: 2015-04-13
Posts: 74

Re: "locate" not working because of permission problem? [Solved]

seth wrote:

No idea about the actual cause for the setup, but "stat `which locate`" - it should be root:locate and have the suid  bit set, ie. be "2755"
This explains why locate can access the file.

Yes, I do get

 ls -l /usr/bin/locate
-rwxr-sr-x 1 root locate 39520 14 déc.   2014 /usr/bin/locate

So, maybe I get the permission problem because suid is not working?  This would explain why I have the other problem.

Offline

#9 2016-12-18 17:07:52

kde35
Member
Registered: 2015-04-13
Posts: 74

Re: "locate" not working because of permission problem? [Solved]

kde35 wrote:
seth wrote:

No idea about the actual cause for the setup, but "stat `which locate`" - it should be root:locate and have the suid  bit set, ie. be "2755"
This explains why locate can access the file.

Yes, I do get

 ls -l /usr/bin/locate
-rwxr-sr-x 1 root locate 39520 14 déc.   2014 /usr/bin/locate

So, maybe I get the permission problem because suid is not working?  This would explain why I have the other problem.

As a matter of fact this was the case as I posted in the other thread.  Thank you very much all.

Offline

Board footer

Powered by FluxBB