summaryrefslogtreecommitdiffstats
path: root/meta/lib/oe
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2017-05-12 12:05:41 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-05-16 14:08:28 +0100
commita11e87f179409d7f8581db73f636190e428ae849 (patch)
treeae1266ac8c6779f4b0977e2d4370f8344c9966d8 /meta/lib/oe
parente4e8435886653789c93c95b99080d6c07ef78cbb (diff)
downloadpoky-a11e87f179409d7f8581db73f636190e428ae849.tar.gz
useradd: Create lib/oe/useradd function library
The code in useradd-staticids is generally useful for user addition functionality but is not reusable in its current form. Refactor the code into a set of library functions. (From OE-Core rev: a638ef304b1f1acb4c88f4f90b1ef22526cb8d2f) Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oe')
-rw-r--r--meta/lib/oe/useradd.py68
1 files changed, 68 insertions, 0 deletions
diff --git a/meta/lib/oe/useradd.py b/meta/lib/oe/useradd.py
new file mode 100644
index 0000000000..179ac76b5e
--- /dev/null
+++ b/meta/lib/oe/useradd.py
@@ -0,0 +1,68 @@
1import argparse
2import re
3
4class myArgumentParser(argparse.ArgumentParser):
5 def _print_message(self, message, file=None):
6 bb.warn("%s - %s: %s" % (d.getVar('PN'), pkg, message))
7
8 # This should never be called...
9 def exit(self, status=0, message=None):
10 message = message or ("%s - %s: useradd.bbclass: Argument parsing exited" % (d.getVar('PN'), pkg))
11 error(message)
12
13 def error(self, message):
14 raise bb.build.FuncFailed(message)
15
16def split_commands(params):
17 params = re.split('''[ \t]*;[ \t]*(?=(?:[^'"]|'[^']*'|"[^"]*")*$)''', params.strip())
18 # Remove any empty items
19 return [x for x in params if x]
20
21def split_args(params):
22 params = re.split('''[ \t]+(?=(?:[^'"]|'[^']*'|"[^"]*")*$)''', params.strip())
23 # Remove any empty items
24 return [x for x in params if x]
25
26def build_useradd_parser():
27 # The following comes from --help on useradd from shadow
28 parser = myArgumentParser(prog='useradd')
29 parser.add_argument("-b", "--base-dir", metavar="BASE_DIR", help="base directory for the home directory of the new account")
30 parser.add_argument("-c", "--comment", metavar="COMMENT", help="GECOS field of the new account")
31 parser.add_argument("-d", "--home-dir", metavar="HOME_DIR", help="home directory of the new account")
32 parser.add_argument("-D", "--defaults", help="print or change default useradd configuration", action="store_true")
33 parser.add_argument("-e", "--expiredate", metavar="EXPIRE_DATE", help="expiration date of the new account")
34 parser.add_argument("-f", "--inactive", metavar="INACTIVE", help="password inactivity period of the new account")
35 parser.add_argument("-g", "--gid", metavar="GROUP", help="name or ID of the primary group of the new account")
36 parser.add_argument("-G", "--groups", metavar="GROUPS", help="list of supplementary groups of the new account")
37 parser.add_argument("-k", "--skel", metavar="SKEL_DIR", help="use this alternative skeleton directory")
38 parser.add_argument("-K", "--key", metavar="KEY=VALUE", help="override /etc/login.defs defaults")
39 parser.add_argument("-l", "--no-log-init", help="do not add the user to the lastlog and faillog databases", action="store_true")
40 parser.add_argument("-m", "--create-home", help="create the user's home directory", action="store_const", const=True)
41 parser.add_argument("-M", "--no-create-home", dest="create_home", help="do not create the user's home directory", action="store_const", const=False)
42 parser.add_argument("-N", "--no-user-group", dest="user_group", help="do not create a group with the same name as the user", action="store_const", const=False)
43 parser.add_argument("-o", "--non-unique", help="allow to create users with duplicate (non-unique UID)", action="store_true")
44 parser.add_argument("-p", "--password", metavar="PASSWORD", help="encrypted password of the new account")
45 parser.add_argument("-P", "--clear-password", metavar="CLEAR_PASSWORD", help="use this clear password for the new account")
46 parser.add_argument("-R", "--root", metavar="CHROOT_DIR", help="directory to chroot into")
47 parser.add_argument("-r", "--system", help="create a system account", action="store_true")
48 parser.add_argument("-s", "--shell", metavar="SHELL", help="login shell of the new account")
49 parser.add_argument("-u", "--uid", metavar="UID", help="user ID of the new account")
50 parser.add_argument("-U", "--user-group", help="create a group with the same name as the user", action="store_const", const=True)
51 parser.add_argument("LOGIN", help="Login name of the new user")
52
53 return parser
54
55def build_groupadd_parser():
56 # The following comes from --help on groupadd from shadow
57 parser = myArgumentParser(prog='groupadd')
58 parser.add_argument("-f", "--force", help="exit successfully if the group already exists, and cancel -g if the GID is already used", action="store_true")
59 parser.add_argument("-g", "--gid", metavar="GID", help="use GID for the new group")
60 parser.add_argument("-K", "--key", metavar="KEY=VALUE", help="override /etc/login.defs defaults")
61 parser.add_argument("-o", "--non-unique", help="allow to create groups with duplicate (non-unique) GID", action="store_true")
62 parser.add_argument("-p", "--password", metavar="PASSWORD", help="use this encrypted password for the new group")
63 parser.add_argument("-P", "--clear-password", metavar="CLEAR_PASSWORD", help="use this clear password for the new group")
64 parser.add_argument("-R", "--root", metavar="CHROOT_DIR", help="directory to chroot into")
65 parser.add_argument("-r", "--system", help="create a system account", action="store_true")
66 parser.add_argument("GROUP", help="Group name of the new group")
67
68 return parser