#5787 closed defect (fixed)
Erroneous parsing of command line arguments in trac-admin
Reported by: | anonymous | Owned by: | Christian Boos |
---|---|---|---|
Priority: | normal | Milestone: | 0.11.1 |
Component: | admin/console | Version: | devel |
Severity: | normal | Keywords: | backslash |
Cc: | Branch: | ||
Release Notes: | |||
API Changes: | |||
Internal Changes: |
Description
When adding permissions to an environment by means of the command line (rather than interactive mode), for example:
trac-admin C:\path\to\env permission add DOMAIN\user TRAC_ADMIN
The permission is added, but with a double backslash between the username and domain. The domain has to be specified because of the use of the Apache SSPI (mod_auth_sspi) module which gives us Windows Domain authentication, which we definitely need. This problem does not occur when going into interactive admin mode:
trac-admin C:\path\to\env
and then entering the permission add command:
permission add DOMAIN\user TRAC_ADMIN
This wouldn't be an issue if it weren't for the following: the interactive mode can't (AFAIK) be accessed from the command line, hence isn't accessible from a batch file. I use a batch file to create an environment and it would save loads of time if I could set the permissions correctly for each environment from that same batch file. I can imagine mine isn't the only scenario where this matters.
Attachments (1)
Change History (8)
by , 17 years ago
Attachment: | mod_auth_sspi-1.0.4-2.2.2.zip added |
---|
comment:1 by , 17 years ago
Component: | general → trac-admin |
---|---|
Owner: | changed from | to
comment:2 by , 17 years ago
follow-up: 7 comment:3 by , 17 years ago
Hi.
Just been fouled by this.
Try :
permission add DOMAIN\user
permission add "DOMAIN\user"
permission add 'DOMAIN\user'
permission add DOMAIN
user
Depending on your OS, shell and options one of this should work.
Use
permission list
to verify what realy got to da DB. Thats what you should see on the
logged in
on top of the page.
follow-up: 6 comment:4 by , 16 years ago
Keywords: | backslash added |
---|---|
Milestone: | → 0.11.1 |
Owner: | changed from | to
Status: | new → assigned |
#7457 was closed as duplicate. #5334 is also related, but less closely as it doesn't talk about permissions but simply about '\' in paths.
The escaping has been added in r3513, but I think that's appropriate only for the interactive mode. On the command line, there shouldn't be such escaping, otherwise there's no way to specify only one backslash.
Please try out the following patch:
-
trac/admin/console.py
diff --git a/trac/admin/console.py b/trac/admin/console.py
a b 115 115 else: 116 116 encoding = locale.getpreferredencoding() # sys.argv 117 117 line = to_unicode(line, encoding) 118 line = line.replace('\\', '\\\\') 118 if self.interactive: 119 line = line.replace('\\', '\\\\') 119 120 rv = cmd.Cmd.onecmd(self, line) or 0 120 121 except SystemExit: 121 122 raise
comment:5 by , 16 years ago
Note that with the above, I can do either of:
$ # bash $ trac-admin env add version \\ $ trac-admin env add version '\' $ trac-admin env [env]> add version \
and
> :: cmd.exe > trac-admin env add version \ > trac-admin env [env]> add version \
(from cmd.exe) with success, but nevertheless I get a failure for the corresponding unit-test, so I guess the test needs to be fixed somehow:
$ PYTHONPATH=. python25 trac/admin/tests/__init__.py E......................................................................... ====================================================================== ERROR: test_backslash_use_ok (trac.admin.tests.console.TracadminTestCase) ---------------------------------------------------------------------- Traceback (most recent call last): File "C:\Workspace\src\trac\repos\0.11-stable\trac\admin\tests\console.py", line 983, in test_backslash_use_ok self._execute('version add \\') File "C:\Workspace\src\trac\repos\0.11-stable\trac\admin\tests\console.py", line 119, in _execute retval = self._admin.onecmd(cmd) File "C:\Workspace\src\trac\repos\0.11-stable\trac\admin\console.py", line 120, in onecmd rv = cmd.Cmd.onecmd(self, line) or 0 File "C:\Program Files\ActiveState\Python-2.5\lib\cmd.py", line 219, in onecmd return func(arg) File "C:\Workspace\src\trac\repos\0.11-stable\trac\admin\console.py", line 1087, in do_version arg = self.arg_tokenize(line) File "C:\Workspace\src\trac\repos\0.11-stable\trac\admin\console.py", line 203, in arg_tokenize for token in shlex.split(argstr.encode('utf-8'))] or [''] File "C:\Program Files\ActiveState\Python-2.5\lib\shlex.py", line 279, in split return list(lex) File "C:\Program Files\ActiveState\Python-2.5\lib\shlex.py", line 269, in next token = self.get_token() File "C:\Program Files\ActiveState\Python-2.5\lib\shlex.py", line 96, in get_token raw = self.read_token() File "C:\Program Files\ActiveState\Python-2.5\lib\shlex.py", line 191, in read_token raise ValueError, "No escaped character" ValueError: No escaped character ---------------------------------------------------------------------- Ran 74 tests in 8.547s FAILED (errors=1)
comment:6 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Patch applied in r7393.
On the command line, there shouldn't be such escaping,
… because it's already done elsewhere in the code in this case (source:trunk/scripts/trac_admin.py@133#L572).
Adjusting the unit-test and fixed other small issues in previous commits in r7394.
comment:7 by , 16 years ago
Replying to anonymous:
Hi.
Just been fouled by this.
Try :
permission add DOMAIN\user
permission add "DOMAIN\user"
permission add 'DOMAIN\user'
permission add DOMAIN
user
Depending on your OS, shell and options one of this should work. Use
permission list
to verify what realy got to da DB. Thats what you should see on the
logged in
on top of the page.
Just been bitten by the same issue in 0.10.4. Thanks for mentioning the workaround.
I might add that this is probably a Windows-related issue (original submitter speaking here). The thing runs at my work under Windows 2003 Server (standard edition) SP2. I can't imagine that would be the only platform it wouldn't work on however.
Perhaps it's also a suggestion to include mod_auth_sspi as a recommendation in the installation instructions for Apache etc, because not only has it saved my ass from entering some 17 users manually with all their passwords (not all of which I even know) into a passwd file somewhere but I feel this module will work some real magic in any environment where everyone working with Trac and SVN is in the same Windows Domain (right about all software companies like mine, for example). I'd be more than willing to contribute some documentation on how to implement it, contact me at mels [@t] ml-webdesign [d0t] nl> or reply to this ticket (I check my mail more often than this ticket of course).