|
36 | 36 |
|
37 | 37 | import os |
38 | 38 | import platform |
| 39 | +import re |
39 | 40 | import subprocess |
40 | 41 | import sys |
41 | 42 | import time |
@@ -72,6 +73,8 @@ def __init__(self): |
72 | 73 | # special case to make all following args belong to the passed in command and not to this program |
73 | 74 | #self._CLI__parser.disable_interspersed_args() |
74 | 75 | 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('^\*+$') |
75 | 78 |
|
76 | 79 | def timeout_handler(self, signum, frame): # pylint: disable=unused-argument |
77 | 80 | for child in psutil.Process().children(): |
@@ -151,22 +154,32 @@ def mac_getent_passwd_user(self, user): |
151 | 154 | (output, returncode) = self.cmd(command) |
152 | 155 | user = password = uid = gid = name = homedir = shell = '' |
153 | 156 | #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): |
155 | 159 | tokens = line.split() |
156 | | - if len(tokens) < 2: |
| 160 | + if len(tokens) < 1: |
157 | 161 | continue |
158 | 162 | field = tokens[0] |
159 | | - value = tokens[1] |
| 163 | + if len(tokens) < 2: |
| 164 | + value = '' |
| 165 | + else: |
| 166 | + value = tokens[1] |
160 | 167 | if field == 'RecordName:': |
161 | 168 | user = value |
162 | 169 | elif field == 'Password:': |
163 | 170 | password = value |
| 171 | + if self.star_regex.match(password): |
| 172 | + password = 'x' |
164 | 173 | elif field == 'UniqueID:': |
165 | 174 | uid = value |
166 | 175 | elif field == 'PrimaryGroupID:': |
167 | 176 | gid = value |
168 | 177 | elif field == 'RealName:': |
169 | 178 | 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 |
170 | 183 | elif field == 'NFSHomeDirectory:': |
171 | 184 | homedir = value |
172 | 185 | elif field == 'UserShell:': |
@@ -225,6 +238,8 @@ def mac_getent_group_name(self, group): |
225 | 238 | gid = value |
226 | 239 | elif field == 'Password:': |
227 | 240 | password = value |
| 241 | + if self.star_regex.match(password): |
| 242 | + password = 'x' |
228 | 243 | elif field == 'RealName:': |
229 | 244 | name = value |
230 | 245 | if not value and len(output) > index + 1 and output[index+1].startswith(' '): |
|
0 commit comments