-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsudosh-ls
More file actions
executable file
·59 lines (47 loc) · 1.92 KB
/
Copy pathsudosh-ls
File metadata and controls
executable file
·59 lines (47 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
# matt.pestle@nesi.org.nz
# April 2025
# Show a listing of any impersonation sessions that have
# been done of someone impersonating the calling user.
# This is a wrapper around sudosh-replay that allows
# all users to see their own impersonation sessions.
# In its original form, sudosh-replay needs to be run by root,
# and this relaxes that restriction by filtering out the calling
# user's session into a directory by itself, and then calling
# sudosh-replay on that directory.
# Otherwise sudosh-replay will crash on the first session that
# it can't read (presumably because it's trying to read the
# recording to see who did it, how long it is, etc.)
TMPDIR=${TMPDIR:=/tmp}
SUDOSH_LOGDIR=/var/log/sudosh
BIN_DIR=$(dirname `readlink -f $0`)
[[ -d "$SUDOSH_LOGDIR" ]] || {
echo "setup error - sudosh logdir does not exist"
exit 1
}
ME=$(id -gn)
MYDIR=$TMPDIR/sudosh_$ME
# Start with a clean slate:
[[ -d "$MYDIR" ]] && /bin/rm -rf "$MYDIR"
# Create a directory with symlinks of only the calling user's files
umask 0077
mkdir "$MYDIR" || exit 1
cd $MYDIR || exit 1
find -L $SUDOSH_LOGDIR -user "$ME" -exec ln -s {} . \; || exit 1
NUM_RECORDINGS=$($BIN_DIR/sudosh-replay -d "$MYDIR" 2>/dev/null | wc -l)
((NUM_RECORDINGS==0)) && {
echo "No available impersonation sessions for user $ME"
exit 0
}
# Get the header and the most recently ID (last column of the last line)
# In this incarnation of sudosh-replay, the header and info messages get
# pushed to stderr, and the session info lines to stdout, hence:
$BIN_DIR/sudosh-replay -d "$MYDIR" 2>&1 | head -2
LAST_ID=$($BIN_DIR/sudosh-replay -d "$MYDIR" 2>/dev/null | tail -1 | awk '{print $NF}')
# And now suppress the header and info message
# and just get the session lines coming to stdout
$BIN_DIR/sudosh-replay -d "$MYDIR" 2>/dev/null
echo
echo "Usage: sudosh-replay ID [MULTIPLIER] [MAXWAIT]"
echo "See 'sudosh-replay -h' for more help."
echo "Example: sudosh-replay $LAST_ID 1 2"