Merge lp:~parthm/bzr/2.0_376388_dot_bazaar_ownership into lp:bzr/2.0
- 2.0_376388_dot_bazaar_ownership
- Merge into 2.0
Status: | Rejected |
---|---|
Rejected by: | Martin Pool |
Proposed branch: | lp:~parthm/bzr/2.0_376388_dot_bazaar_ownership |
Merge into: | lp:bzr/2.0 |
Diff against target: |
124 lines (+56/-3) 4 files modified
NEWS (+5/-0) bzrlib/config.py (+4/-2) bzrlib/osutils.py (+42/-0) bzrlib/trace.py (+5/-1) |
To merge this branch: | bzr merge lp:~parthm/bzr/2.0_376388_dot_bazaar_ownership |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Martin Pool | Needs Fixing | ||
Review via email: mp+19593@code.launchpad.net |
Commit message
Description of the change
Parth Malwankar (parthm) wrote : | # |
Martin Pool (mbp) wrote : | # |
Having a special case for /dev/null and NUL is a bit gross and probably unnecessary.
I think we should set the permissions only when the files are first created; changing the perms on existing files is more dangerous and more likely to cause nasty surprises.
I think we should catch errors in doing the chmod and turn them into user warnings to avoid bzr crashing entirely if you do have a strange situation.
I'd like to see the 'create a thing inheriting permissions' factored out; probably you need a variation for mkdir and for making a file.
Once that is split out, the cleanest way to test it is probably to monkeypatch os.chmod and then run that function. You can use overrideAttr to do this.
Martin Pool (mbp) wrote : | # |
An interesting followon from this would be that we could also do this when creating a .bzr directory.
Also, you should perhaps do the chown and chgrp separately, as the chown may fail when the chgrp can succeed. (Common for non-root users.)
I think overall this is a reasonable change though it might be considered a bit magical.
Martin Pool (mbp) wrote : | # |
btw I don't think this is appropriate for 2.0: it's not a severe bug and there is some risk of it having surprising fallout. trunk only.
Parth Malwankar (parthm) wrote : | # |
> Having a special case for /dev/null and NUL is a bit gross and probably
> unnecessary.
>
> I think we should set the permissions only when the files are first created;
> changing the perms on existing files is more dangerous and more likely to
> cause nasty surprises.
>
> I think we should catch errors in doing the chmod and turn them into user
> warnings to avoid bzr crashing entirely if you do have a strange situation.
>
> I'd like to see the 'create a thing inheriting permissions' factored out;
> probably you need a variation for mkdir and for making a file.
>
> Once that is split out, the cleanest way to test it is probably to monkeypatch
> os.chmod and then run that function. You can use overrideAttr to do this.
Thanks for your comments Martin. I have updated the patch.
Parth Malwankar (parthm) wrote : | # |
> An interesting followon from this would be that we could also do this when
> creating a .bzr directory.
>
> Also, you should perhaps do the chown and chgrp separately, as the chown may
> fail when the chgrp can succeed. (Common for non-root users.)
>
> I think overall this is a reasonable change though it might be considered a
> bit magical.
Filed bug #524306 to track this.
Parth Malwankar (parthm) wrote : | # |
> btw I don't think this is appropriate for 2.0: it's not a severe bug and there
> is some risk of it having surprising fallout. trunk only.
I have proposed a merge based of trunk due to the above and also because overrideAttr was not available in the 2.0 line.
Please consider this mp obsolte.
The new merge proposal is https:/
Parth Malwankar (parthm) wrote : | # |
Does launchpad have a way of setting this as obsolete?
John A Meinel (jameinel) wrote : | # |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Parth Malwankar wrote:
> Does launchpad have a way of setting this as obsolete?
>
Change the setting to Rejected.
John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://
iEYEARECAAYFAkt
ZmsAoNWf7m3aOVK
=WOeF
-----END PGP SIGNATURE-----
Preview Diff
1 | === modified file 'NEWS' | |||
2 | --- NEWS 2010-02-18 05:38:14 +0000 | |||
3 | +++ NEWS 2010-02-19 05:13:17 +0000 | |||
4 | @@ -25,6 +25,11 @@ | |||
5 | 25 | ``UnboundLocalError``. | 25 | ``UnboundLocalError``. |
6 | 26 | (Andrew Bennetts, #423563) | 26 | (Andrew Bennetts, #423563) |
7 | 27 | 27 | ||
8 | 28 | * ``.bazaar``, ``.bazaar/bazaar.conf`` and ``.bzr.log`` inherit user and | ||
9 | 29 | group ownership from the containing directory. This allow bzr to work | ||
10 | 30 | better with sudo. | ||
11 | 31 | (Parth Malwankar, #376388) | ||
12 | 32 | |||
13 | 28 | Documentation | 33 | Documentation |
14 | 29 | ************* | 34 | ************* |
15 | 30 | 35 | ||
16 | 31 | 36 | ||
17 | === modified file 'bzrlib/config.py' | |||
18 | --- bzrlib/config.py 2009-08-20 04:53:23 +0000 | |||
19 | +++ bzrlib/config.py 2010-02-19 05:13:17 +0000 | |||
20 | @@ -473,7 +473,9 @@ | |||
21 | 473 | self._write_config_file() | 473 | self._write_config_file() |
22 | 474 | 474 | ||
23 | 475 | def _write_config_file(self): | 475 | def _write_config_file(self): |
25 | 476 | f = open(self._get_filename(), 'wb') | 476 | path = self._get_filename() |
26 | 477 | parent = osutils.parent_dir(path) | ||
27 | 478 | f = osutils.open(path, 'wb', ownership_src = parent) | ||
28 | 477 | self._get_parser().write(f) | 479 | self._get_parser().write(f) |
29 | 478 | f.close() | 480 | f.close() |
30 | 479 | 481 | ||
31 | @@ -769,7 +771,7 @@ | |||
32 | 769 | trace.mutter('creating config parent directory: %r', parent_dir) | 771 | trace.mutter('creating config parent directory: %r', parent_dir) |
33 | 770 | os.mkdir(parent_dir) | 772 | os.mkdir(parent_dir) |
34 | 771 | trace.mutter('creating config directory: %r', path) | 773 | trace.mutter('creating config directory: %r', path) |
36 | 772 | os.mkdir(path) | 774 | osutils.mkdir(path, ownership_src = osutils.parent_dir(path)) |
37 | 773 | 775 | ||
38 | 774 | 776 | ||
39 | 775 | def config_dir(): | 777 | def config_dir(): |
40 | 776 | 778 | ||
41 | === modified file 'bzrlib/osutils.py' | |||
42 | --- bzrlib/osutils.py 2009-10-08 03:55:30 +0000 | |||
43 | +++ bzrlib/osutils.py 2010-02-19 05:13:17 +0000 | |||
44 | @@ -49,7 +49,9 @@ | |||
45 | 49 | cache_utf8, | 49 | cache_utf8, |
46 | 50 | errors, | 50 | errors, |
47 | 51 | win32utils, | 51 | win32utils, |
48 | 52 | trace, | ||
49 | 52 | ) | 53 | ) |
50 | 54 | |||
51 | 53 | """) | 55 | """) |
52 | 54 | 56 | ||
53 | 55 | # sha and md5 modules are deprecated in python2.6 but hashlib is available as | 57 | # sha and md5 modules are deprecated in python2.6 but hashlib is available as |
54 | @@ -1590,6 +1592,46 @@ | |||
55 | 1590 | real_handlers[kind](abspath, relpath) | 1592 | real_handlers[kind](abspath, relpath) |
56 | 1591 | 1593 | ||
57 | 1592 | 1594 | ||
58 | 1595 | def parent_dir(path): | ||
59 | 1596 | """same as os.path.dirname but returns '.' instead of '' | ||
60 | 1597 | for paths that just have a filename in it e.g. 'foo'""" | ||
61 | 1598 | pdir = os.path.dirname(path) | ||
62 | 1599 | if pdir == '': | ||
63 | 1600 | pdir = '.' | ||
64 | 1601 | return pdir | ||
65 | 1602 | |||
66 | 1603 | |||
67 | 1604 | def copy_ownership(dst, src): | ||
68 | 1605 | """copy user and group ownership from own_src file/dir to dst file/dir. | ||
69 | 1606 | If own_src is None, the containing directory is used as source.""" | ||
70 | 1607 | if os.name != 'posix': | ||
71 | 1608 | return False | ||
72 | 1609 | try: | ||
73 | 1610 | s = os.stat(src) | ||
74 | 1611 | os.chown(dst, s.st_uid, s.st_gid) | ||
75 | 1612 | except OSError, e: | ||
76 | 1613 | trace.warning("IOError: %s\nUnable to copy ownership from '%s' to '%s'" % (e, src, dst)) | ||
77 | 1614 | return True | ||
78 | 1615 | |||
79 | 1616 | |||
80 | 1617 | def mkdir(path, ownership_src=None): | ||
81 | 1618 | """creates the directory 'path'. If ownership_src is given, copies (chown) | ||
82 | 1619 | usr/grp ownership from 'ownership_src' to 'path'""" | ||
83 | 1620 | os.mkdir(path) | ||
84 | 1621 | if ownership_src != None: | ||
85 | 1622 | copy_ownership(path, ownership_src) | ||
86 | 1623 | |||
87 | 1624 | def open(filename, mode='r', bufsize=-1, ownership_src=None): | ||
88 | 1625 | """This function wraps the python builtin open. filename, mode and bufsize | ||
89 | 1626 | parameters behave the same as the builtin open[1]. | ||
90 | 1627 | [1] http://python.org/doc/2.6.4/library/functions.html#open""" | ||
91 | 1628 | import __builtin__ | ||
92 | 1629 | f = __builtin__.open(filename, mode, bufsize) | ||
93 | 1630 | if ownership_src != None: | ||
94 | 1631 | copy_ownership(filename, ownership_src) | ||
95 | 1632 | return f | ||
96 | 1633 | |||
97 | 1634 | |||
98 | 1593 | def path_prefix_key(path): | 1635 | def path_prefix_key(path): |
99 | 1594 | """Generate a prefix-order path key for path. | 1636 | """Generate a prefix-order path key for path. |
100 | 1595 | 1637 | ||
101 | 1596 | 1638 | ||
102 | === modified file 'bzrlib/trace.py' | |||
103 | --- bzrlib/trace.py 2010-01-06 17:46:15 +0000 | |||
104 | +++ bzrlib/trace.py 2010-02-19 05:13:17 +0000 | |||
105 | @@ -228,14 +228,18 @@ | |||
106 | 228 | _bzr_log_filename = _get_bzr_log_filename() | 228 | _bzr_log_filename = _get_bzr_log_filename() |
107 | 229 | _rollover_trace_maybe(_bzr_log_filename) | 229 | _rollover_trace_maybe(_bzr_log_filename) |
108 | 230 | try: | 230 | try: |
110 | 231 | bzr_log_file = open(_bzr_log_filename, 'at', 1) # line buffered | 231 | buffering = 1 # line buffered |
111 | 232 | ownership_src = osutils.parent_dir(_bzr_log_filename) | ||
112 | 233 | bzr_log_file = osutils.open(_bzr_log_filename, 'at', buffering, ownership_src) | ||
113 | 232 | # bzr_log_file.tell() on windows always return 0 until some writing done | 234 | # bzr_log_file.tell() on windows always return 0 until some writing done |
114 | 233 | bzr_log_file.write('\n') | 235 | bzr_log_file.write('\n') |
115 | 234 | if bzr_log_file.tell() <= 2: | 236 | if bzr_log_file.tell() <= 2: |
116 | 235 | bzr_log_file.write("this is a debug log for diagnosing/reporting problems in bzr\n") | 237 | bzr_log_file.write("this is a debug log for diagnosing/reporting problems in bzr\n") |
117 | 236 | bzr_log_file.write("you can delete or truncate this file, or include sections in\n") | 238 | bzr_log_file.write("you can delete or truncate this file, or include sections in\n") |
118 | 237 | bzr_log_file.write("bug reports to https://bugs.launchpad.net/bzr/+filebug\n\n") | 239 | bzr_log_file.write("bug reports to https://bugs.launchpad.net/bzr/+filebug\n\n") |
119 | 240 | |||
120 | 238 | return bzr_log_file | 241 | return bzr_log_file |
121 | 242 | |||
122 | 239 | except IOError, e: | 243 | except IOError, e: |
123 | 240 | # If we are failing to open the log, then most likely logging has not | 244 | # If we are failing to open the log, then most likely logging has not |
124 | 241 | # been set up yet. So we just write to stderr rather than using | 245 | # been set up yet. So we just write to stderr rather than using |
This patch fixes bug #376388
It ensure that .bazaar, .bazaar/bazaar.conf and .bzr.log when created
by bzr run under sudo, have the same usr/grp ownership as the containing
folder and not root.
copy_ownership(src, dst) function copies user and group ownership
from src to dst. copy_ownership does nothing on windows.
This function is used during creation of .bazaar, .bazaar/bazaar.conf
and .bzr.log.
.bzr.log location of /dev/null and NUL are ignored.
This was tested by creating a user 'sandbox' and running
'sudo bzr whoami a@b'. The latter creates the above files with
the correct ownership.
I am not sure what would be a good way to write a automated test case
for this. Any ideas/suggestion are welcome. I would be happy to
implement them.
Below is the log of the manual test run:
sandbox@ parthm- laptop: ~$ ls -la .bazaar .bzr.log .bazaar/bazaar.conf bazaar. conf: No such file or directory
ls: cannot access .bazaar: No such file or directory
ls: cannot access .bzr.log: No such file or directory
ls: cannot access .bazaar/
sandbox@ parthm- laptop: ~$ sudo /storage/ parth/src/ bzr.dev/ 2.0_376388_ dot_bazaar_ ownership/ bzr whoami a@b
[sudo] password for sandbox:
sandbox@ parthm- laptop: ~$ ls -la .bazaar .bzr.log .bazaar/ bazaar. conf-rw- r--r-- 1 sandbox sandbox 22 2010-02-18 18:13 .bazaar/bazaar.conf
-rw-r--r-- 1 sandbox sandbox 727 2010-02-18 18:13 .bzr.log
.bazaar: parthm- laptop: ~$
total 12
drwxr-xr-x 2 sandbox sandbox 4096 2010-02-18 18:13 .
drwxr-xr-x 4 sandbox sandbox 4096 2010-02-18 18:13 ..
-rw-r--r-- 1 sandbox sandbox 22 2010-02-18 18:13 bazaar.conf
sandbox@