#! /usr/local/bin/python

# Copyright C 2002-2003 by Isilon Systems, Inc. All rights not expressly
# granted herein are reserved.
# Created in the United States of America.
# 
# This digital media is protected by U.S. and international copyright and
# intellectual property laws. Unless otherwise specified, all information
# and screens appearing as part of this digital medium, including
# software, services, documents, text, images, icons, and logos design;
# the selection, assembly, arrangement, and design thereof; and the code
# that enables its presentation, are the sole property of Isilon Systems,
# Inc.
# 
# Except as otherwise required by applicable law, no part of any
# copyrighted material may be reproduced, modified, translated,
# distributed, published, or transmitted by any means, electronic or
# mechanical, for any purpose, without the prior written consent of Isilon
# Systems. 
#  
# Isilon and Isilon Systems are registered trademarks of Isilon Systems,
# Inc.  Legion is a trademark of Isilon Systems, Inc.  All other
# trademarks and registered trademarks are the property of their
# respective holders.


import sys
import getpass
from isi.ui.lib.users import LegionNssUsers

try:
    done = 0

    if len(sys.argv) < 2:
        print "You must provide a username."
        sys.exit(-1)

    name = sys.argv[1]

    legion = LegionNssUsers()

    if not legion.getUserExists(name):
        print "The user "+name+" does not exist."
        sys.exit(-1)

    while not done:
        try:
            pass1 = getpass.getpass("Please enter new password for "+name+": ")
            if pass1 == '':
                continue
            pass2 = getpass.getpass("Please re-enter password for "+name+": ")

            if pass1 != pass2:
                print "\nYou did not enter the same password.\n"
                done = -1
                break
            if len(pass1) > 40:
                print "\nThe password you entered is too long.\n"
                done = -1
                break

            legion.setPassword(name, pass1)
            print "\nPassword changed.\n"
            done = 1
        except:
            done = -1
            print "\n"
except:
    done = -1

if done == 1:
    sys.exit(0)
else:
    sys.exit(-1)
