From 49c8122d8fcf09f75e68dbda665ca12a9ef28fd7 Mon Sep 17 00:00:00 2001 From: Brad Schoening Date: Wed, 9 Apr 2025 17:28:14 -0400 Subject: [PATCH] Avoid CQLSH throwing an exception loading .cqlshrc on non-supported platforms While we do not support Windows as such (at least on server), reviewers evaluated that this might be fixed as the gains (Windows users using CQLSH to connect to Cassandra running on supported platforms) are justified. patch by Brad Schoening; reviewed by Brandon Williams, Josh McKenzie for CASSANDRA-20478 --- CHANGES.txt | 1 + pylib/cqlshlib/util.py | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index 8c64d012f0..4aaed8bdb9 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 5.0.5 + * Avoid CQLSH throwing an exception loading .cqlshrc on non-supported platforms (CASSANDRA-20478) * Relax validation of snapshot name as a part of SSTable files path validation (CASSANDRA-20649) * Optimize initial skipping logic for SAI queries on large partitions (CASSANDRA-20191) * Fix reading mmapped trie-index exceeding 2GiB (CASSANDRA-20351) diff --git a/pylib/cqlshlib/util.py b/pylib/cqlshlib/util.py index 144586aae0..90d95b9afe 100644 --- a/pylib/cqlshlib/util.py +++ b/pylib/cqlshlib/util.py @@ -117,12 +117,15 @@ def trim_if_present(s, prefix): def is_file_secure(filename): try: st = os.stat(filename) + uid = os.getuid() except OSError as e: if e.errno != errno.ENOENT: raise # the file doesn't exist, the security of it is irrelevant return True - uid = os.getuid() + except AttributeError as e: + # not-Unix os + return True # Skip enforcing the file owner and UID matching for the root user (uid == 0). # This is to allow "sudo cqlsh" to work with user owned credentials file.