Mercurial > hg
comparison mercurial/ui.py @ 3013:494521a3f142
Only read .hg/hgrc files from trusted users/groups
The list of trusted users and groups is specified in the [trusted]
section of a hgrc; the current user is always trusted; "*" can be
used to trust all users/groups.
Global hgrc files are always read.
On Windows (and other systems that don't have the pwd and grp modules),
all .hg/hgrc files are read.
author | Alexis S. L. Carvalho <alexis@cecm.usp.br> |
---|---|
date | Tue, 22 Aug 2006 20:45:03 -0300 |
parents | 731f6b3d27c2 |
children | 01454af644b8 c27d1e1798a3 |
comparison
equal
deleted
inserted
replaced
3012:abcd6ae3cf5a | 3013:494521a3f142 |
---|---|
17 self.overlay = {} | 17 self.overlay = {} |
18 if parentui is None: | 18 if parentui is None: |
19 # this is the parent of all ui children | 19 # this is the parent of all ui children |
20 self.parentui = None | 20 self.parentui = None |
21 self.readhooks = list(readhooks) | 21 self.readhooks = list(readhooks) |
22 self.trusted_users = {} | |
23 self.trusted_groups = {} | |
22 self.cdata = ConfigParser.SafeConfigParser() | 24 self.cdata = ConfigParser.SafeConfigParser() |
23 self.readconfig(util.rcpath()) | 25 self.readconfig(util.rcpath()) |
24 | 26 |
25 self.quiet = self.configbool("ui", "quiet") | 27 self.quiet = self.configbool("ui", "quiet") |
26 self.verbose = self.configbool("ui", "verbose") | 28 self.verbose = self.configbool("ui", "verbose") |
35 self.revlogopts = self.configrevlog() | 37 self.revlogopts = self.configrevlog() |
36 else: | 38 else: |
37 # parentui may point to an ui object which is already a child | 39 # parentui may point to an ui object which is already a child |
38 self.parentui = parentui.parentui or parentui | 40 self.parentui = parentui.parentui or parentui |
39 self.readhooks = list(parentui.readhooks or readhooks) | 41 self.readhooks = list(parentui.readhooks or readhooks) |
42 self.trusted_users = parentui.trusted_users.copy() | |
43 self.trusted_groups = parentui.trusted_groups.copy() | |
40 parent_cdata = self.parentui.cdata | 44 parent_cdata = self.parentui.cdata |
41 self.cdata = ConfigParser.SafeConfigParser(parent_cdata.defaults()) | 45 self.cdata = ConfigParser.SafeConfigParser(parent_cdata.defaults()) |
42 # make interpolation work | 46 # make interpolation work |
43 for section in parent_cdata.sections(): | 47 for section in parent_cdata.sections(): |
44 self.cdata.add_section(section) | 48 self.cdata.add_section(section) |
70 def readconfig(self, fn, root=None): | 74 def readconfig(self, fn, root=None): |
71 if isinstance(fn, basestring): | 75 if isinstance(fn, basestring): |
72 fn = [fn] | 76 fn = [fn] |
73 for f in fn: | 77 for f in fn: |
74 try: | 78 try: |
75 self.cdata.read(f) | 79 fp = open(f) |
80 except IOError: | |
81 continue | |
82 if ((self.trusted_users or self.trusted_groups) and | |
83 '*' not in self.trusted_users and | |
84 '*' not in self.trusted_groups): | |
85 st = util.fstat(fp) | |
86 user = util.username(st.st_uid) | |
87 group = util.groupname(st.st_gid) | |
88 if (user not in self.trusted_users and | |
89 group not in self.trusted_groups): | |
90 self.warn(_('not reading file %s from untrusted ' | |
91 'user %s, group %s\n') % (f, user, group)) | |
92 continue | |
93 try: | |
94 self.cdata.readfp(fp, f) | |
76 except ConfigParser.ParsingError, inst: | 95 except ConfigParser.ParsingError, inst: |
77 raise util.Abort(_("Failed to parse %s\n%s") % (f, inst)) | 96 raise util.Abort(_("Failed to parse %s\n%s") % (f, inst)) |
78 # translate paths relative to root (or home) into absolute paths | 97 # translate paths relative to root (or home) into absolute paths |
79 if root is None: | 98 if root is None: |
80 root = os.path.expanduser('~') | 99 root = os.path.expanduser('~') |
81 for name, path in self.configitems("paths"): | 100 for name, path in self.configitems("paths"): |
82 if path and "://" not in path and not os.path.isabs(path): | 101 if path and "://" not in path and not os.path.isabs(path): |
83 self.cdata.set("paths", name, os.path.join(root, path)) | 102 self.cdata.set("paths", name, os.path.join(root, path)) |
103 user = util.username() | |
104 if user is not None: | |
105 self.trusted_users[user] = 1 | |
106 for user in self.configlist('trusted', 'users'): | |
107 self.trusted_users[user] = 1 | |
108 for group in self.configlist('trusted', 'groups'): | |
109 self.trusted_groups[group] = 1 | |
84 for hook in self.readhooks: | 110 for hook in self.readhooks: |
85 hook(self) | 111 hook(self) |
86 | 112 |
87 def setconfig(self, section, name, val): | 113 def setconfig(self, section, name, val): |
88 self.overlay[(section, name)] = val | 114 self.overlay[(section, name)] = val |