root/masterdriverz/use-expand/pkgcore/os_data.py @ ferringb%2540gentoo.org-20061020104228-0229f730f121f926

Revision ferringb%2540gentoo.org-20061020104228-0229f730f121f926, 2.2 kB (checked in by Brian Harring <ferringb@…>, 2 years ago)

track portage user's groups for spawning, bug 137610

Line 
1# Copyright: 2005 Gentoo Foundation
2# License: GPL2
3
4"""
5Avoid using- os data- root uid/gid, pkgcore uid/gid, etc.
6
7This will be killed off and bound into configuration subsystem at some point
8"""
9
10import os, pwd, grp
11
12ostype = os.uname()[0]
13
14if ostype == "Linux":
15    userland = "GNU"
16    xargs = os.environ["XARGS"] = "xargs -r"
17    lchown = os.lchown
18elif ostype == "Darwin":
19    userland = "Darwin"
20    xargs = os.environ["XARGS"] = "xargs"
21    def lchown(*pos_args, **key_args):
22        pass
23elif ostype in ["FreeBSD", "OpenBSD", "NetBSD"]:
24    userland = "BSD"
25    xargs = os.environ["XARGS"] = "xargs"
26    lchown = os.lchown
27else:
28    raise Exception("Operating system unsupported, '%s'" % ostype)
29
30
31#os.environ["USERLAND"] = userland
32
33#Secpass will be set to 1 if the user is root or in the portage group.
34secpass = 0
35
36uid = os.getuid()
37# hard coding sucks.
38root_uid = 0
39root_gid = wheelgid = 0
40
41if uid == 0:
42    secpass = 2
43try:
44    wheelgid = grp.getgrnam("wheel").gr_gid
45    if (not secpass) and (wheelgid in os.getgroups()):
46        secpass = 1
47except KeyError:
48    print "portage initialization: your system doesn't have a 'wheel' group."
49    print ("Please fix this as it is a normal system requirement. "
50           "'wheel' is GID 10")
51    print "'emerge baselayout' and an 'etc-update' should remedy this problem."
52
53#Discover the uid and gid of the portage user/group
54try:
55    portage_uid = pwd.getpwnam("portage").pw_uid
56    portage_gid = grp.getgrnam("portage").gr_gid
57    portage_user_groups = tuple(x.gr_name for x in grp.getgrall()
58       if 'portage' in x.gr_mem)
59
60    if (secpass == 0):
61        secpass = 1
62except KeyError:
63    portage_uid = 0
64    portage_gid = wheelgid
65    portage_user_groups = []
66    print
67    print "'portage' user or group missing. Please update baselayout"
68    print "and merge portage user(250) and group(250) into your passwd"
69    print "and group files. Non-root compilation is disabled until then."
70    print "Also note that non-root/wheel users will need to be added to"
71    print "the portage group to do portage commands.\n"
72    print "For the defaults, line 1 goes into passwd, and 2 into group."
73    print "portage:x:250:250:portage:/var/tmp/portage:/bin/false"
74    print "portage::250:portage"
Note: See TracBrowser for help on using the browser.