Esempio n. 1
0
def _modify(options, parser):
    # Set parser options 
    parser.add_argument( "user_email"
                       , action = "store"
                       , help   = "User's mail address."
                       )
    parser.add_argument( "-p", "--password"
                       , action = "store"
                       , help   = "Specify password."
                       )
    parser.add_argument( "-m", "--md5"
                       , action  = "store_true"
                       , default = False
                       , help    = "Use MD5 hash function (default = SHA-1)."
                       )
    parser.add_argument( "-L", "--lock"
                       , action  = "store_true"
                       , default = False
                       , help    = "Lock a user's account."
                       )
    parser.add_argument( "-U", "--unlock"
                       , action  = "store_true"
                       , default = False
                       , help    = "Unock a user's account."
                       )
    parser.add_argument( "-s", "--sn"
                       , action = "store"
                       , help   = "Specify sn."
                       )
    parser.add_argument( "-g", "--given-name"
                       , action = "store"
                       , help   = "Specify given_name."
                       )
    parser.add_argument(       "--assign-administrator"
                       , action  = "store_true"
                       , default = False
                       , help    = "Assign administrator to user."
                       )
    parser.add_argument(       "--demote-administrator"
                       , action  = "store_true"
                       , default = False
                       , help    = "Demote user from administrator to general user."
                       )
    parser.add_argument(       "--change-password-at-next-login"
                       , action  = "store_true"
                       , default = False
                       , help    = "User must change password at next login."
                       )
    parser.add_argument(       "--no-change-password-at-next-login"
                       , action  = "store_true"
                       , default = False
                       , help    = "User do not have to change password at next login."
                       )

    # Get options
    namespace = parser.parse_args(options)

    # Check hash function name
    if namespace.md5:
        hash_function_name = "MD5"
    else:
        hash_function_name = "SHA-1"
    hash_password = _func.getHashedPassword(namespace.password, hash_function_name)

    # Check lock/unlock
    suspended = _func.getTrueOrFalse(namespace.lock, namespace.unlock)
    if suspended == False:
        return False

    # Check assign admin/non-admin
    is_admin = _func.getTrueOrFalse( namespace.assign_administrator
                                   , namespace.demote_administrator
                                   )
    if is_admin == False:
        return False

    # Check must change password or not
    is_change_password = _func.getTrueOrFalse( namespace.change_password_at_next_login
                                             , namespace.no_change_password_at_next_login
                                             )
    if is_change_password == False:
        return False

    # Get auth token
    auth_token = _func.getAuthTokenByLogin(namespace.admin_name, namespace.domain)

    # Operation
    return _func.operate( USER2.updateUser
                        , namespace.user_email.lower()
                        , parser.prog
                        , namespace.result_file
                               , namespace.domain
                               , auth_token
                               , namespace.user_email.lower()   # user
                               , hash_password                  # password
                               , namespace.sn                   # sn
                               , namespace.given_name           # given name
                               , hash_function_name             # function name
                               , suspended                      # suspended
                               , is_admin                       # assign admin?
                               , is_change_password             # no change?
                        )
Esempio n. 2
0
def _modify(options, parser):
    # Set parser options 
    parser.add_argument( "user_name"
                       , action = "store"
                       , help   = "User name."
                       )
    parser.add_argument( "-p", "--password"
                       , action = "store"
                       , help   = "Specify password."
                       )
    parser.add_argument( "-m", "--md5"
                       , action  = "store_true"
                       , default = False
                       , help    = "Use MD5 hash function (default = SHA-1)."
                       )
    parser.add_argument( "-L", "--lock"
                       , action  = "store_true"
                       , default = False
                       , help    = "Lock a user's account."
                       )
    parser.add_argument( "-U", "--unlock"
                       , action  = "store_true"
                       , default = False
                       , help    = "Unock a user's account."
                       )
    parser.add_argument( "-s", "--sn"
                       , action = "store"
                       , help   = "Specify sn."
                       )
    parser.add_argument( "-g", "--given-name"
                       , action = "store"
                       , help   = "Specify given_name."
                       )

    # Get options
    namespace = parser.parse_args(options)

    # Check hash function name
    if namespace.md5:
        hash_function_name = "MD5"
    else:
        hash_function_name = "SHA-1"
    hash_password = _func.getHashedPassword(namespace.password, hash_function_name)

    # Check lock/unlock
    suspended = _func.getTrueOrFalse(namespace.lock, namespace.unlock)
    if suspended == False:
        return False

    # Get auth token
    auth_token = _func.getAuthTokenByLogin(namespace.admin_name, namespace.domain)

    # Operation
    return _func.operate( USER.updateUser
                        , namespace.user_name.lower()
                        , parser.prog
                        , namespace.result_file
                               , namespace.domain
                               , auth_token
                               , namespace.user_name.lower()    # user
                               , hash_password                  # password
                               , namespace.sn                   # sn
                               , namespace.given_name           # given name
                               , hash_function_name             # function name
                               , suspended                      # suspended
                        )