Skip to content

Commit 1c6d155

Browse files
committed
updated getent.py
1 parent 83f8736 commit 1c6d155

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

getent.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
import os
3838
import platform
39+
import re
3940
import subprocess
4041
import sys
4142
import time
@@ -72,6 +73,8 @@ def __init__(self):
7273
# special case to make all following args belong to the passed in command and not to this program
7374
#self._CLI__parser.disable_interspersed_args()
7475
self._CLI__parser.set_usage('{prog} [options] <command> <args> ...'.format(prog=self._prog))
76+
# for Mac to convert to 'x' same as Linux
77+
self.star_regex = re.compile('^\*+$')
7578

7679
def timeout_handler(self, signum, frame): # pylint: disable=unused-argument
7780
for child in psutil.Process().children():
@@ -151,22 +154,32 @@ def mac_getent_passwd_user(self, user):
151154
(output, returncode) = self.cmd(command)
152155
user = password = uid = gid = name = homedir = shell = ''
153156
#log.info('parsing output for passwd conversion')
154-
for line in output.split('\n'):
157+
output = output.split('\n')
158+
for (index, line) in enumerate(output):
155159
tokens = line.split()
156-
if len(tokens) < 2:
160+
if len(tokens) < 1:
157161
continue
158162
field = tokens[0]
159-
value = tokens[1]
163+
if len(tokens) < 2:
164+
value = ''
165+
else:
166+
value = tokens[1]
160167
if field == 'RecordName:':
161168
user = value
162169
elif field == 'Password:':
163170
password = value
171+
if self.star_regex.match(password):
172+
password = 'x'
164173
elif field == 'UniqueID:':
165174
uid = value
166175
elif field == 'PrimaryGroupID:':
167176
gid = value
168177
elif field == 'RealName:':
169178
name = value
179+
if not value and len(output) > index + 1 and output[index+1].startswith(' '):
180+
name = output[index+1].strip()
181+
elif not name and field == 'RecordName:':
182+
name = value
170183
elif field == 'NFSHomeDirectory:':
171184
homedir = value
172185
elif field == 'UserShell:':
@@ -225,6 +238,8 @@ def mac_getent_group_name(self, group):
225238
gid = value
226239
elif field == 'Password:':
227240
password = value
241+
if self.star_regex.match(password):
242+
password = 'x'
228243
elif field == 'RealName:':
229244
name = value
230245
if not value and len(output) > index + 1 and output[index+1].startswith(' '):

0 commit comments

Comments
 (0)