Skip to content

Commit

Permalink
Merge pull request #1928 from phillxnet/1927_remove_--stdin_option_us…
Browse files Browse the repository at this point in the history
…e_for_passwd

remove --stdin option use for passwd. Fixes #1927
  • Loading branch information
schakrava authored May 30, 2018
2 parents 5a15dbe + 1e4b949 commit 46f48dd
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/rockstor/system/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
from shutil import move
from tempfile import mkstemp
import chardet
import random
import string
import crypt

import logging
logger = logging.getLogger(__name__)
Expand All @@ -36,7 +39,6 @@
GROUPADD = '/usr/sbin/groupadd'
USERDEL = '/usr/sbin/userdel'
GROUPDEL = '/usr/sbin/groupdel'
PASSWD = '/usr/bin/passwd'
USERMOD = '/usr/sbin/usermod'
SMBPASSWD = '/usr/bin/smbpasswd'
CHOWN = '/usr/bin/chown'
Expand Down Expand Up @@ -128,14 +130,22 @@ def get_epasswd(username):


def usermod(username, passwd):
cmd = [PASSWD, '--stdin', username]
# TODO: 'salt = crypt.mksalt()' # Python 3.3 onwards provides system best.
# Salt starting "$6$" & of 19 chars signifies SHA-512 current system best.
# Salt must contain only [./a-zA-Z0-9] chars (bar first 3 if len > 2)
salt_header = '$6$' # SHA-512
rnd = random.SystemRandom()
salt = ''.join([rnd.choice(string.ascii_letters + string.digits + './')
for _ in range(16)])
crypted_passwd = crypt.crypt(passwd.encode('utf8'), salt_header + salt)
cmd = [USERMOD, '-p', crypted_passwd, username]
p = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stdin=subprocess.PIPE)
out, err = p.communicate(input=passwd.encode('utf8'))
out, err = p.communicate(input=None)
rc = p.returncode
if (rc != 0):
if rc != 0:
raise CommandException(cmd, out, err, rc)
return (out, err, rc)
return out, err, rc


def smbpasswd(username, passwd):
Expand Down

0 comments on commit 46f48dd

Please sign in to comment.