Edgewall Software
Modify

Opened 17 years ago

Closed 16 years ago

Last modified 16 years ago

#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)

mod_auth_sspi-1.0.4-2.2.2.zip (38.7 KB ) - added by anonymous 17 years ago.

Download all attachments as: .zip

Change History (8)

by anonymous, 17 years ago

comment:1 by Emmanuel Blot, 17 years ago

Component: generaltrac-admin
Owner: changed from Jonas Borgström to Christopher Lenz

comment:2 by anonymous, 17 years ago

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).

comment:3 by anonymous, 16 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.

comment:4 by Christian Boos, 16 years ago

Keywords: backslash added
Milestone: 0.11.1
Owner: changed from Christopher Lenz to Christian Boos
Status: newassigned

#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  
    115115                else:
    116116                    encoding = locale.getpreferredencoding() # sys.argv
    117117                line = to_unicode(line, encoding)
    118             line = line.replace('\\', '\\\\')
     118            if self.interactive:
     119                line = line.replace('\\', '\\\\')
    119120            rv = cmd.Cmd.onecmd(self, line) or 0
    120121        except SystemExit:
    121122            raise

comment:5 by Christian Boos, 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)

in reply to:  4 comment:6 by Christian Boos, 16 years ago

Resolution: fixed
Status: assignedclosed

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.

in reply to:  3 comment:7 by Vineet Reynolds, 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.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Christian Boos.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Christian Boos to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.