Mercurial > public > mercurial-scm > hg
comparison mercurial/ui.py @ 8141:e40b629bedd1
ui: cleanup _is_trusted a bit
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Thu, 23 Apr 2009 15:40:10 -0500 |
parents | 7c47ac9620a8 |
children | 912bfef12ba6 |
comparison
equal
deleted
inserted
replaced
8140:7c47ac9620a8 | 8141:e40b629bedd1 |
---|---|
35 self.trusted_users = {} | 35 self.trusted_users = {} |
36 self.trusted_groups = {} | 36 self.trusted_groups = {} |
37 self.overlay = util.configparser() | 37 self.overlay = util.configparser() |
38 self.cdata = util.configparser() | 38 self.cdata = util.configparser() |
39 self.ucdata = util.configparser() | 39 self.ucdata = util.configparser() |
40 | |
40 # we always trust global config files | 41 # we always trust global config files |
41 self.readconfig(util.rcpath(), assumetrusted=True) | 42 self.readconfig(util.rcpath(), assumetrusted=True) |
42 else: | 43 else: |
43 # parentui may point to an ui object which is already a child | 44 # parentui may point to an ui object which is already a child |
44 self.parentui = parentui.parentui or parentui | 45 self.parentui = parentui.parentui or parentui |
61 ui._isatty = sys.stdin.isatty() | 62 ui._isatty = sys.stdin.isatty() |
62 except AttributeError: # not a real file object | 63 except AttributeError: # not a real file object |
63 ui._isatty = False | 64 ui._isatty = False |
64 return ui._isatty | 65 return ui._isatty |
65 | 66 |
66 def _is_trusted(self, fp, f, warn=True): | 67 def _is_trusted(self, fp, f): |
67 st = util.fstat(fp) | 68 st = util.fstat(fp) |
68 if util.isowner(fp, st): | 69 if util.isowner(fp, st): |
69 return True | 70 return True |
71 | |
70 tusers = self.trusted_users | 72 tusers = self.trusted_users |
71 tgroups = self.trusted_groups | 73 tgroups = self.trusted_groups |
72 if not tusers: | 74 if '*' in tusers or '*' in tgroups: |
73 user = util.username() | 75 return True |
74 if user is not None: | 76 |
75 self.trusted_users[user] = 1 | 77 user = util.username(st.st_uid) |
76 self.fixconfig(section='trusted') | 78 group = util.groupname(st.st_gid) |
77 if (tusers or tgroups) and '*' not in tusers and '*' not in tgroups: | 79 if user in tusers or group in tgroups or user == util.username(): |
78 user = util.username(st.st_uid) | 80 return True |
79 group = util.groupname(st.st_gid) | 81 |
80 if user not in tusers and group not in tgroups: | 82 if self.report_untrusted: |
81 if warn and self.report_untrusted: | 83 self.warn(_('Not trusting file %s from untrusted ' |
82 self.warn(_('Not trusting file %s from untrusted ' | 84 'user %s, group %s\n') % (f, user, group)) |
83 'user %s, group %s\n') % (f, user, group)) | 85 return False |
84 return False | |
85 return True | |
86 | 86 |
87 def readconfig(self, fn, root=None, assumetrusted=False): | 87 def readconfig(self, fn, root=None, assumetrusted=False): |
88 cdata = util.configparser() | 88 cdata = util.configparser() |
89 | 89 |
90 if isinstance(fn, basestring): | 90 if isinstance(fn, basestring): |
173 self.interactive = self.configbool("ui", "interactive", | 173 self.interactive = self.configbool("ui", "interactive", |
174 self.isatty()) | 174 self.isatty()) |
175 self.traceback = self.configbool('ui', 'traceback', False) | 175 self.traceback = self.configbool('ui', 'traceback', False) |
176 | 176 |
177 # update trust information | 177 # update trust information |
178 if (section is None or section == 'trusted') and self.trusted_users: | 178 if section is None or section == 'trusted': |
179 for user in self.configlist('trusted', 'users'): | 179 for user in self.configlist('trusted', 'users'): |
180 self.trusted_users[user] = 1 | 180 self.trusted_users[user] = 1 |
181 for group in self.configlist('trusted', 'groups'): | 181 for group in self.configlist('trusted', 'groups'): |
182 self.trusted_groups[group] = 1 | 182 self.trusted_groups[group] = 1 |
183 | 183 |