[elbe-devel] [PATCH v2 8/8] commands: add passwd sub-command
Holger Dengler
holger at hdengler.de
Thu Jun 16 12:10:14 CEST 2022
Add sub-command to hash a plain-text password. The output format is
compatible with shadow (5) and can be used in the "passwd_hashed"
element in Elbe XMLs.
Signed-off-by: Holger Dengler <holger at hdengler.de>
---
elbepack/commands/passwd.py | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
create mode 100644 elbepack/commands/passwd.py
diff --git a/elbepack/commands/passwd.py b/elbepack/commands/passwd.py
new file mode 100644
index 000000000..80322ec04
--- /dev/null
+++ b/elbepack/commands/passwd.py
@@ -0,0 +1,21 @@
+# ELBE - Debian Based Embedded Rootfilesystem Builder
+# Copyright 2022 Linutronix GmbH
+# Author: Holger Dengler <holger at hdengler.de>
+#
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+import sys
+from optparse import OptionParser
+from crypt import crypt, METHOD_SHA512
+
+
+def run_command(argv):
+ oparser = OptionParser(usage="usage: %prog passwd <plain-text-password>")
+ (_, args) = oparser.parse_args(argv)
+
+ if len(args) != 1:
+ print("Wrong number of arguments", file=sys.stderr)
+ oparser.print_help()
+ sys.exit(20)
+
+ print('%s' % crypt(args[0], METHOD_SHA512))
--
2.36.1
More information about the elbe-devel
mailing list