@@ -428,55 +428,38 @@ class Users(FactBase):
428428
429429 command = '''
430430 for i in `cat /etc/passwd | cut -d: -f1`; do
431- ID=`id $i`;
432- META=`cat /etc/passwd | grep ^$i: | cut -d: -f5-7`;
433- echo "$ID $META";
431+ ENTRY=`grep ^$i: /etc/passwd`;
432+ echo "$ENTRY|`id -gn $i`|`id -Gn $i`";
434433 done
435434 ''' .strip ()
436435
437436 default = dict
438437
439- regex = r'^uid=([0-9]+)\(([a-zA-Z0-9_\.\-]+)\) gid=([0-9]+)\(([a-zA-Z0-9_\.\-]+)\) groups=([a-zA-Z0-9_\.\-,\(\)\s]+) (.*)$' # noqa
440- group_regex = r'^[0-9]+\(([a-zA-Z0-9_\.\-]+)\)$'
441-
442438 def process (self , output ):
443439 users = {}
440+
444441 for line in output :
445- matches = re . match ( self . regex , line )
442+ entry , group , user_groups = line . split ( '|' )
446443
447- if matches :
444+ if entry :
448445 # Parse out the comment/home/shell
449- comment_home_shell = matches .group (6 ).split (':' )
450- comment = comment_home_shell [0 ] or None
451- home = comment_home_shell [1 ] or None
452- shell = comment_home_shell [2 ] or None
446+ entries = entry .split (':' )
453447
454- # Main user group, uid & gid
455- uid = int (matches .group (1 ))
456- gid = int (matches .group (3 ))
457- group = matches .group (4 )
458-
459- # Parse the groups
448+ # Parse groups
460449 groups = []
461- for group_matches in matches .group (5 ).split (',' ):
462- name = re .match (self .group_regex , group_matches .strip ())
463- if name :
464- name = name .group (1 )
465- else :
466- continue # pragma: no cover
467-
450+ for group_name in user_groups .split (' ' ):
468451 # We only want secondary groups here
469- if name != group :
470- groups .append (name )
452+ if group_name and group_name != group :
453+ groups .append (group_name )
471454
472- users [matches .group (2 )] = {
455+ users [entries [0 ]] = {
456+ 'home' : entries [5 ] or None ,
457+ 'comment' : entries [4 ] or None ,
458+ 'shell' : entries [6 ] or None ,
473459 'group' : group ,
474460 'groups' : groups ,
475- 'comment' : comment ,
476- 'home' : home ,
477- 'shell' : shell ,
478- 'uid' : uid ,
479- 'gid' : gid ,
461+ 'uid' : int (entries [2 ]),
462+ 'gid' : int (entries [3 ]),
480463 }
481464
482465 return users
0 commit comments