Skip to content

Commit

Permalink
BannedEapiCommand: add some extra user/group commands
Browse files Browse the repository at this point in the history
Add some commands which should never be called in ebuild to the banned
list.

Signed-off-by: Arthur Zamarin <[email protected]>
  • Loading branch information
arthurzam committed Oct 5, 2023
1 parent a19030f commit 348ad0a
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/pkgcheck/checks/codingstyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@ class BadCommandsCheck(Check):
_source = sources.EbuildParseRepoSource
known_results = frozenset({DeprecatedEapiCommand, BannedEapiCommand, BannedPhaseCall})

extra_banned_commands = frozenset(
{
# commands that modify user/group databases, not portable
"gpasswd",
"groupadd",
"groupdel",
"groupmod",
"useradd",
"userdel",
"usermod",
}
)

def feed(self, pkg):
for func_node, _ in bash.func_query.captures(pkg.tree.root_node):
for node, _ in bash.cmd_query.captures(func_node):
Expand All @@ -100,6 +113,10 @@ def feed(self, pkg):
yield BannedEapiCommand(
name, line=call, lineno=lineno + 1, eapi=pkg.eapi, pkg=pkg
)
elif name in self.extra_banned_commands:
yield BannedEapiCommand(
name, line=call, lineno=lineno + 1, eapi=pkg.eapi, pkg=pkg
)


class EendMissingArg(results.LineResult, results.Warning):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{"__class__": "BannedEapiCommand", "category": "BadCommandsCheck", "package": "BannedEapiCommand", "version": "0", "line": "dohtml doc/*", "lineno": 9, "command": "dohtml", "eapi": "7"}
{"__class__": "BannedEapiCommand", "category": "BadCommandsCheck", "package": "BannedEapiCommand", "version": "1", "line": "has_version --host-root stub/stub1", "lineno": 9, "command": "has_version --host-root", "eapi": "7"}
{"__class__": "BannedEapiCommand", "category": "BadCommandsCheck", "package": "BannedEapiCommand", "version": "1", "line": "best_version --host-root stub/stub1:2", "lineno": 12, "command": "best_version --host-root", "eapi": "7"}
{"__class__": "BannedEapiCommand", "category": "BadCommandsCheck", "package": "BannedEapiCommand", "version": "2", "line": "usermod -s /bin/bash uucp", "lineno": 9, "command": "usermod", "eapi": "6"}
{"__class__": "BannedEapiCommand", "category": "BadCommandsCheck", "package": "BannedEapiCommand", "version": "2", "line": "usermod -s /bin/false uucp", "lineno": 13, "command": "usermod", "eapi": "6"}
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,18 @@ diff -Naur standalone/BadCommandsCheck/BannedEapiCommand/BannedEapiCommand-1.ebu
- H=$(best_version --host-root stub/stub1:2)
+ H=$(best_version -b stub/stub1:2)
}
diff -Naur standalone/BadCommandsCheck/BannedEapiCommand/BannedEapiCommand-2.ebuild fixed/BadCommandsCheck/BannedEapiCommand/BannedEapiCommand-2.ebuild
--- standalone/BadCommandsCheck/BannedEapiCommand/BannedEapiCommand-2.ebuild
+++ fixed/BadCommandsCheck/BannedEapiCommand/BannedEapiCommand-2.ebuild
@@ -4,11 +4,3 @@ DESCRIPTION="Ebuild using banned commands"
HOMEPAGE="https://github.com/pkgcore/pkgcheck"
SLOT="0"
LICENSE="BSD"
-
-pkg_preinst() {
- usermod -s /bin/bash uucp || die
-}
-
-pkg_postrm() {
- usermod -s /bin/false uucp || die
-}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
EAPI=6

DESCRIPTION="Ebuild using banned commands"
HOMEPAGE="https://github.com/pkgcore/pkgcheck"
SLOT="0"
LICENSE="BSD"

pkg_preinst() {
usermod -s /bin/bash uucp || die
}

pkg_postrm() {
usermod -s /bin/false uucp || die
}

0 comments on commit 348ad0a

Please sign in to comment.