You are not logged in.

#26 2018-01-27 20:58:34

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

Re: permissions getting changed on a spare drive's mount point [solved]

seth wrote:

ME is required for sure

;-)

Online

#27 2018-01-27 22:13:47

loqs
Member
Registered: 2014-03-06
Posts: 19,089

Re: permissions getting changed on a spare drive's mount point [solved]

#!/usr/bin/python3

import os,subprocess

pid = os.getpid()

while pid > 1:
  cmdpath = "/proc/"+str(pid)+"/cmdline"
  with open(cmdpath) as f:
    line = f.readline()
    line = " ".join(line.split('\0'))
    subprocess.run(["logger","sudo trace",line])
  pidpath = "/proc/"+str(pid)+"/status"
  try:
    with open(pidpath) as f:
      for line in f:
        if line.startswith("PPid"):
          skip , ppid = line.split()
          pid = int(ppid)
          break
  except:
    pass
os.execvp("/usr/bin/sudo.bin",sys.argv)

In case it is needed to go any deeper
edit:
missed the call to the real sudo

Last edited by loqs (2018-01-27 22:44:29)

Offline

#28 2018-01-27 22:19:18

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,525
Website

Re: permissions getting changed on a spare drive's mount point [solved]

Python could do,  but there was a needless subshell (and useless cat) in the original script that was causing the trouble.  `logger` will read from stdin:

logger < /proc/$$/cmdline
logger < /proc/$PPID/cmdline

You might also want to add a useful tag, e.g.:

logger -t sudo-debug < /proc/$$/cmdline

Or for the full process tree without python:

#!/bin/sh

pid=$$
while [ $pid -gt 0 ]; do
	logger -t sudo-debug < /proc/$pid/cmdline
	pid=$(sed -n 's/PPid:\t*//p' /proc/$pid/status)
done

exec /usr/bin/sudo.bin "$@"

Last edited by Trilby (2018-01-27 22:54:35)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#29 2018-01-27 22:44:03

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,734
Website

Re: permissions getting changed on a spare drive's mount point [solved]

Thanks Trilby.  The problem with the while loop code is that sudo never completes the command...  for example, `sudo su` returns to the shell.  Perhaps append the exec line from the first script.

Last edited by graysky (2018-01-27 22:46:59)

Offline

#30 2018-01-27 22:50:04

loqs
Member
Registered: 2014-03-06
Posts: 19,089

Re: permissions getting changed on a spare drive's mount point [solved]

Yes Trilby's command and my last one before revision both just parse the process tree.

Offline

#31 2018-01-27 22:54:16

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,525
Website

Re: permissions getting changed on a spare drive's mount point [solved]

Yup, I editted to indicate the actual command needs to follow at the end.  And also to rewrite it as I was horribly annoyed that I had to rely on a bashism ... until I realized it didn't matter if the sed command was in a subshell.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#32 2018-01-28 18:50:39

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,734
Website

Re: permissions getting changed on a spare drive's mount point [solved]

Thanks for the help so far... now that I have the logger script in place, of course, I am not seeing the error.  I'll post back when I eventually do.

Offline

#33 2018-01-29 20:35:49

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,734
Website

Re: permissions getting changed on a spare drive's mount point [solved]

Just happened... guess I need the more advanced code:

Jan 29 15:33:40 radio sudo-debug[1545]: /bin/bash
Jan 29 15:33:40 radio sudo-debug[1546]: /bin/bash
Jan 29 15:33:40 radio sudo[1544]:  graysky : TTY=pts/1 ; PWD=/home/graysky ; USER=root ; COMMAND=/bin/chown -R graysky:users /incoming/
Jan 29 15:33:40 radio sudo.bin[1544]: pam_unix(sudo:session): session opened for user root by (uid=0)
Jan 29 15:33:40 radio sudo.bin[1544]: pam_unix(sudo:session): session closed for user root

Last edited by graysky (2018-01-29 20:35:59)

Offline

#34 2018-01-29 21:13:52

R00KIE
Forum Fellow
From: Between a computer and a chair
Registered: 2008-09-14
Posts: 4,734

Re: permissions getting changed on a spare drive's mount point [solved]

Can you correlate the logged time to something you were doing around that time? You should have been asked for your password if you have set sudo to always ask for a password.

You could install psmisc and log the output of pstree for each sudo invocation, it might help to figure out from where sudo is being called. You might want to add a few options such as -a to get the full command line as this should help identify the offending sudo call.


R00KIE
Tm90aGluZyB0byBzZWUgaGVyZSwgbW92ZSBhbG9uZy4K

Offline

#35 2018-01-29 21:51:26

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,734
Website

Re: permissions getting changed on a spare drive's mount point [solved]

@ROOKIE - Doing too many things at that time.  I am using the 2nd script now which I probably should have done in the first place.  Let's see...

Offline

#36 2018-01-29 22:28:18

loqs
Member
Registered: 2014-03-06
Posts: 19,089

Re: permissions getting changed on a spare drive's mount point [solved]

From the output produced so far "TTY=pts/1" etc looks like it was triggered from something started in a terminal window.

Offline

#37 2018-01-31 00:26:23

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,734
Website

Re: permissions getting changed on a spare drive's mount point [solved]

Finally, something to go on:

Jan 30 17:27:51 radio sudo-debugmore[18133]: /bin/bash
Jan 30 17:27:51 radio sudo-debugmore[18135]: /bin/bash
Jan 30 17:27:51 radio sudo-debugmore[18137]: -zsh
Jan 30 17:27:51 radio sudo-debugmore[18139]: xfce4-terminal
Jan 30 17:27:51 radio sudo-debugmore[18141]: xfsettingsd
Jan 30 17:27:51 radio sudo-debugmore[18143]: /sbin/init
Jan 30 17:27:51 radio sudo[18132]:  graysky : TTY=pts/2 ; PWD=/home/graysky ; USER=root ; COMMAND=/bin/chown -R graysky:users /incoming/
Jan 30 17:27:51 radio sudo.bin[18132]: pam_unix(sudo:session): session opened for user root by (uid=0)
Jan 30 17:27:51 radio sudo.bin[18132]: pam_unix(sudo:session): session closed for user root

... still no idea wtf is calling the chown.

Last edited by graysky (2018-01-31 00:27:20)

Offline

#38 2018-01-31 00:41:42

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,525
Website

Re: permissions getting changed on a spare drive's mount point [solved]

Can we assume you did in fact have a xcfe4-terminal window open around that time?

Do you run zsh as your interactive shell?  If so, it would seem a bash script was run from that shell that included the sudo chmod command.  It should be in your zsh history.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#39 2018-01-31 07:21:10

B1omman
Member
Registered: 2016-02-16
Posts: 36

Re: permissions getting changed on a spare drive's mount point [solved]

This is just gonna be some speculations since I don't use, nor have I previously used Xfce, but what about Thunar? Thunar interfaces some settings for auto-mounting and bookmarks etc (~/.gtk-bookmarks or something) which could be checked by xfsettingsd? Then if Xfce want's to have it's known location back, it would need to have the permissions changed as to not exceed the context it was spawned in (graysky:users)? I guess this bookmark/path/whatever it can be would be located in some .desktop-file or some xml-file with Thunar settings.

Sorry if this is completely insane and just waste of time, I don't use a DE myself since they are so magic...

Offline

#40 2018-01-31 12:52:17

R00KIE
Forum Fellow
From: Between a computer and a chair
Registered: 2008-09-14
Posts: 4,734

Re: permissions getting changed on a spare drive's mount point [solved]

The two bashes make me suspect it is a script (or a subshell?) called from another script which was executed with sudo. The xfsettingsd - xfce4-terminal is normal I believe, if you setup a keyboard shortcut to run xfce4-terminal it will show up like that.


R00KIE
Tm90aGluZyB0byBzZWUgaGVyZSwgbW92ZSBhbG9uZy4K

Offline

#41 2018-01-31 13:04:06

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,525
Website

Re: permissions getting changed on a spare drive's mount point [solved]

Rookie, the first bash is our replacement /usr/bin/sudo itself.  So the actual chain is:

xfsettingsd -> xfcr4-terminal -> zsh -> bash -> /usr/bin/sudo

So from an interactive zsh session a script was run (with a bash or sh shebang) and that script included the sudo command.

As any command that was directly typed into an interactive terminal really should be obvious (unless someone else sits at the keyboard while Greysky is away for coffee) then I'd actually revise my previous suspicion that the command must be in the zsh history.  I suspect it may actually shell script called from zsh's startup files.  The diagnostics for this are relatively simple: 1) do the symptoms occur whenever a xcf4-terminal is launched, 2) are the symptoms prevented by using a clean zsh config and/or using a different shell.

Last edited by Trilby (2018-01-31 13:08:48)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#42 2018-01-31 17:11:25

B1omman
Member
Registered: 2016-02-16
Posts: 36

Re: permissions getting changed on a spare drive's mount point [solved]

Trilby wrote:

xfsettingsd -> xfcr4-terminal -> zsh -> bash -> /usr/bin/sudo

So from an interactive zsh session a script was run (with a bash or sh shebang) and that script included the sudo command.

This is not far from what I tried to communicate, any settings daemon wouldn't need to be active until called upon, i.e. when launching the xfce4-terminal, then while/after setting up the shell it would read a change in the dev-tree and run the specified mount. However, some status script or prompt-blingbling would probably be the culprit...

Offline

#43 2018-01-31 17:35:19

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,525
Website

Re: permissions getting changed on a spare drive's mount point [solved]

I doubt it B1omman, as the process change shows it was in a terminal in which zsh was running, and within that a bash shell ran the command with 'sudo'.

Processes spawned from a bound key may also have xfsettingsd as a parent, but not a gui terminal.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#44 2018-01-31 18:09:51

B1omman
Member
Registered: 2016-02-16
Posts: 36

Re: permissions getting changed on a spare drive's mount point [solved]

Trilby wrote:

I don't believe in Magic.

I see...

Jokes aside, you are making sense and I share your doubt. Just hoping for some magic some time so I can feel okay with that I had an empty file named NULL and owned by root:root in my $HOME without being able to find out why for 3 years until I did a fresh install 3 weeks ago on a new disk. Nothing were creating it, but it appeared anyways at random times no matter how many times I deleted it. I gave up.

Offline

#45 2018-01-31 20:27:59

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,734
Website

Re: permissions getting changed on a spare drive's mount point [solved]

Mystery solved... I tracked it down to a call of chown in a backup script I manually call to sync files to my NAS for backup... I defined the sync target with a variable there which is why when I greped for 'incoming', the script did match, but I didn't put 2 and 2 together at the time <<head smack>>.

I knew this was going to end in pilot error; thanks to all for the discussion and the code snips.

Offline

Board footer

Powered by FluxBB