Skip to content

Commit db8a137

Browse files
committed
add a session_locking option in tlog-rec-session.conf
defaults to true, preserving previous behaviour, only one tlog session will be recorded at a time per session ID. setting to false disables this locking, multiple recordings can be made simultaneously.
1 parent 3897015 commit db8a137

File tree

4 files changed

+54
-2
lines changed

4 files changed

+54
-2
lines changed

lib/tlitest/config.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
DEFAULT_TLOG_REC_SESSION_SHELL = "/bin/bash"
2020
DEFAULT_TLOG_REC_SESSION_NOTICE = "ATTENTION: Your session is being recorded!"
2121
DEFAULT_TLOG_REC_SESSION_WRITER = "journal"
22+
DEFAULT_TLOG_REC_SESSION_SESSION_LOCKING = True
2223

2324
DEFAULT_TLOG_PLAY_READER = "file"
2425
DEFAULT_TLOG_PLAY_PERSIST = False
@@ -184,7 +185,8 @@ def generate_config(self, filename):
184185

185186
class TlogRecSessionConfig(TlogRecConfig):
186187
"""TlogPlaySession configuration class, child of TlogRecConfig"""
187-
def __init__(self, shell=DEFAULT_TLOG_REC_SESSION_SHELL,
188+
def __init__(self, session_locking = DEFAULT_TLOG_REC_SESSION_SESSION_LOCKING,
189+
shell=DEFAULT_TLOG_REC_SESSION_SHELL,
188190
notice=DEFAULT_TLOG_REC_SESSION_NOTICE,
189191
latency=DEFAULT_TLOG_REC_LATENCY,
190192
payload=DEFAULT_TLOG_REC_PAYLOAD,
@@ -201,6 +203,7 @@ def __init__(self, shell=DEFAULT_TLOG_REC_SESSION_SHELL,
201203
syslog_priority=DEFAULT_TLOG_REC_SYSLOG_PRIORITY):
202204
self.shell = shell
203205
self.notice = notice
206+
self.session_locking = session_locking
204207
super().__init__(latency, payload, log_input, log_output, log_window,
205208
limit_rate, limit_burst, limit_action,
206209
writer, file_writer_path, journal_priority,
@@ -212,6 +215,7 @@ def _setup_base_session_config(self):
212215
tlog_rec_session_config = {
213216
"shell": self.shell,
214217
"notice": self.notice,
218+
"session_locking": self.session_locking
215219
}
216220

217221
return tlog_rec_session_config

lib/tlitest/test_tlog_rec_session.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,42 @@ class TestTlogRecSession:
2929
os.chmod(tempdir, stat.S_IRWXU + stat.S_IRWXG + stat.S_IRWXO +
3030
stat.S_ISUID + stat.S_ISGID + stat.S_ISVTX)
3131

32+
@pytest.mark.tier1
33+
def test_session_record_to_file_locking_enabled(self):
34+
"""
35+
Check multiple recordings in a session only records one at a time (default)
36+
"""
37+
myname = inspect.stack()[0][3]
38+
logfile = mklogfile(self.tempdir)
39+
sessionclass = TlogRecSessionConfig(writer="file", file_writer_path=logfile)
40+
sessionclass.generate_config(SYSTEM_TLOG_REC_SESSION_CONF)
41+
shell = ssh_pexpect(self.user, 'Secret123', 'localhost')
42+
shell.sendline('echo {}_shell0'.format(myname))
43+
shell.sendline('stty -echo')
44+
shell.sendline("tlog-rec-session -c 'echo {}_nested_session' >/dev/null".format(myname))
45+
shell.sendline('exit')
46+
check_recording(shell, "{}_shell0".format(myname), logfile)
47+
check_recording_missing(shell, "{}_nested_session".format(myname), logfile)
48+
shell.close()
49+
50+
@pytest.mark.tier1
51+
def test_session_record_to_file_locking_disabled(self):
52+
"""
53+
Check multiple recordings in a session works in tlog-rec-session with locking-enabled setting
54+
"""
55+
myname = inspect.stack()[0][3]
56+
logfile = mklogfile(self.tempdir)
57+
sessionclass = TlogRecSessionConfig(writer="file", file_writer_path=logfile, session_locking=False)
58+
sessionclass.generate_config(SYSTEM_TLOG_REC_SESSION_CONF)
59+
shell = ssh_pexpect(self.user, 'Secret123', 'localhost')
60+
shell.sendline('echo {}_shell0'.format(myname))
61+
shell.sendline('stty -echo')
62+
shell.sendline("tlog-rec-session -c 'echo {}_nested_session' >/dev/null".format(myname))
63+
shell.sendline('exit')
64+
check_recording(shell, "{}_shell0".format(myname))
65+
check_recording(shell, "{}_nested_session".format(myname))
66+
shell.close()
67+
3268
@pytest.mark.tier1
3369
def test_session_record_to_file(self):
3470
"""

lib/tlog/rec.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1126,6 +1126,7 @@ tlog_rec(struct tlog_errs **perrs, uid_t euid, gid_t egid,
11261126
clockid_t clock_id;
11271127
unsigned int session_id;
11281128
bool lock_acquired = false;
1129+
bool session_locking = true;
11291130
struct json_object *obj;
11301131
int64_t num;
11311132
unsigned int latency;
@@ -1144,6 +1145,11 @@ tlog_rec(struct tlog_errs **perrs, uid_t euid, gid_t egid,
11441145
}
11451146
}
11461147

1148+
/* Check for the session_locking flag */
1149+
if (json_object_object_get_ex(conf, "session_locking", &obj)) {
1150+
session_locking = json_object_get_boolean(obj);
1151+
}
1152+
11471153
/* Check for the version flag */
11481154
if (json_object_object_get_ex(conf, "version", &obj)) {
11491155
if (json_object_get_boolean(obj)) {
@@ -1198,7 +1204,7 @@ tlog_rec(struct tlog_errs **perrs, uid_t euid, gid_t egid,
11981204
TLOG_ERRS_RAISECS(grc, "Failed retrieving session ID");
11991205
}
12001206

1201-
if (opts & TLOG_REC_OPT_LOCK_SESS) {
1207+
if (opts & TLOG_REC_OPT_LOCK_SESS && session_locking) {
12021208
/* Attempt to lock the session */
12031209
grc = tlog_session_lock(perrs, session_id, euid, egid, &lock_acquired);
12041210
if (grc != TLOG_RC_OK) {

m4/tlog/rec_session_conf_schema.m4

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ M4_PARAM(`', `shell', `file-env',
3030
`SHELL is the ', `The ',
3131
`M4_LINES(`path to the shell executable which should be spawned.')')m4_dnl
3232
m4_dnl
33+
M4_PARAM(`', `session_locking', `file-env',
34+
`M4_TYPE_BOOL(true)', true,
35+
`n', `true', `Enable locking by session ID',
36+
`If specified, ', `If true ',
37+
`M4_LINES(`locking by session ID is enabled.')')m4_dnl
38+
m4_dnl
3339
M4_PARAM(`', `login', `name-',
3440
`M4_TYPE_BOOL()', false,
3541
`l', `', `Make the shell a login shell',

0 commit comments

Comments
 (0)