def AddUser(username, password=None, labels=None, token=None):
 token = data_store.GetDefaultToken(token)
 user_urn = ('aff4:/users/%s' % username)
 try:
  if aff4.FACTORY.Open(user_urn, users.GRRUser, token=token):
   raise UserError(('Cannot add user %s: User already exists.' % username))
 except aff4.InstantiationError:
  pass
 fd = aff4.FACTORY.Create(user_urn, users.GRRUser, mode='rw', token=token)
 if (password is None):
  password = getpass.getpass(prompt=("Please enter password for user '%s': " % username))
 fd.SetPassword(password)
 if labels:
  fd.AddLabels(owner='GRR', *set(labels))
 fd.Close()
 EPrint(('Added user %s.' % username))
 events.Events.PublishEvent('Audit', events.AuditEvent(user=token.username, action='USER_ADD', urn=user_urn), token=token)

def AddUser ( username , password = None , labels = None , token = None ) : token = data_store . GetDefaultToken ( token ) user_urn = ( 'aff4:/users/%s' % username ) try : if aff4 . FACTORY . Open ( user_urn , users . GRRUser , token = token ) : raise UserError ( ( 'Cannot add user %s: User already exists.' % username ) ) except aff4 . InstantiationError : pass fd = aff4 . FACTORY . Create ( user_urn , users . GRRUser , mode = 'rw' , token = token ) if ( password is None ) : password = getpass . getpass ( prompt = ( "Please enter password for user '%s': " % username ) ) fd . SetPassword ( password ) if labels : fd . AddLabels ( owner = 'GRR' , * set ( labels ) ) fd . Close ( ) EPrint ( ( 'Added user %s.' % username ) ) events . Events . PublishEvent ( 'Audit' , events . AuditEvent ( user = token . username , action = 'USER_ADD' , urn = user_urn ) , token = token )
implementation of the add_user command .