Users, groups from active directory with utf-8 charset

Hi all, Im totally new here.

Here is step-by-step reproduction of a bug I’ve encountered after installation of rockstor:

  1. Enable samba
  2. Join domain controller by Win2008R2 which has groups/users with cyrillic names
  3. Wait for a while.
  4. Check users/group or try to set permission to a share.
  5. Thats it! You’ll receive two types of errors: “ascii codec cant decode” or just “not found” page.

after 2 days (yeah, im not great in python rly) of reversing I’ve found the way to fix it. The problem was in system calls:

/opt/rockstor/src/rockstor/system/ get_users
import chardet

def get_users(min_uid=5000, uname=None):
    users = {}
    for u in pwd.getpwall():
        charset = chardet.detect( u.pw_name ) # fix
        uname = u.pw_name.decode( charset['encoding'] ); # fix
        users[uname] = (u.pw_uid, u.pw_gid,) # fix
    return users

/opt/rockstor/src/rockstor/system/ get_groups

def get_groups(*gids):
    groups = {}
    if (len(gids) > 0):
        for g in gids:
            entry = grp.getgrgid(g)
            charset = chardet.detect( entry.gr_name ) # fix
            gr_name = entry.gr_name.decode( charset['encoding'] ) # fix
            groups[gr_name] = entry.gr_gid # fix
        for g in grp.getgrall():
            charset = chardet.detect( g.gr_name ) # fix
            gr_name = g.gr_name.decode( charset['encoding'] ) # fix
            groups[gr_name] = g.gr_gid # fix
    return groups

/opt/rockstor/src/rockstor/storageadmin/models/ groupname

import chardet

def groupname(self, *args, **kwargs):
    if ( is not None):
    if (self.gid is not None):
        groupname = grp.getgrgid(self.gid).gr_name # fixed
        charset = chardet.detect( groupname ) # fixed
        groupname = groupname.decode( charset['encoding'] ) #fixed
        return groupname # fixed
    return None

Notice, that we use here “chardet” package of python.
I think it would be useful to community. Possible there is better solution.
Hope next release will be cured of this problem:slight_smile:


@demount Welcome to the Rockstor community. This is a great find; would you consider doing a pull request with these modifications as this will definitely help with getting them included in what will now be a testing release, given a new stable release has just gone out. Please see the [Developers]
( section of the Contributing to Rockstor - Overview in the official docs. I know it can be a pain to prepare such things but it really would be better for review purposes and the like, plus the project gets another official contributor and it’s easier to keep track of attribution and the like. No worries otherwise and thanks for sharing you fix.

In my experience there is always a better solution but it’s a great deal easier to see once there is ‘a’ solution.

Thanks again for chipping in with this and do link back to this forum thread if you end up making a pull request as that may help cut down on repeating yourself, or just cut and paste and link back anyway.

1 Like