From 8173e5df2d0e8dac48f26882ff16979d0da325b5 Mon Sep 17 00:00:00 2001 From: Alexander Bokovoy Date: Aug 09 2023 16:31:03 +0000 Subject: ipa-epn: don't use too general exception When modifying ipa-epn code, a warning was issued: -------------- Python 3.11.4 (main, Jun 7 2023, 00:00:00) [GCC 13.1.1 20230511 (Red Hat 13.1.1-2)] ************* Module ipaclient.install.ipa_epn ipaclient/install/ipa_epn.py:89: [W0719(broad-exception-raised), drop_privileges] Raising too general exception: Exception) -------------- Use 'RequiresRoot' exception class and clarify the message: ipalib.errors.RequiresRoot: Cannot drop privileges! Related: https://pagure.io/freeipa/issue/9425 Signed-off-by: Alexander Bokovoy Reviewed-By: Florence Blanc-Renaud --- diff --git a/ipaclient/install/ipa_epn.py b/ipaclient/install/ipa_epn.py index 7c6afbc..8798558 100644 --- a/ipaclient/install/ipa_epn.py +++ b/ipaclient/install/ipa_epn.py @@ -86,7 +86,7 @@ def drop_privileges(new_username="daemon", new_groupname="daemon"): os.setuid(grp.getgrnam(new_groupname).gr_gid) if os.getuid() == 0: - raise Exception() + raise errors.RequiresRoot("Cannot drop privileges!") logger.debug( "Dropped privileges to user=%s, group=%s",