def create_user(ldap_server, user):
    old_user = find_user(ldap_server, config, user['USER_NAME'])

    if old_user is None:
        user['USER_ID'] = str(get_free_user_id(ldap_server))
        user['USER_UID'] = str(uuid.uuid4())
    else:
        user['USER_ID'] = old_user['uidNumber'][0]
        user['USER_UID'] = old_user['apple-generateduid'][0]

    group = find_group(l, config, user['USER_GROUP_NAME'])
    user['USER_GROUP_ID'] = group['gidNumber'][0]

    user['USER_PASSWORD_HASH'] = "{KERBEROS} " + user['USER_NAME']

    t = Template("../../config/plab-ldap/templates/user.ldif")
    t.replace(config)
    t.replace(user)
    insert_ldif(ldap_server, str(t))

    add_to_group(ldap_server, config, user['USER_NAME'], user['USER_GROUP_NAME'])

    # Get user and show details
    group = find_group(ldap_server, config, user['USER_GROUP_NAME'])
    user = find_user(ldap_server, config, user['USER_NAME'])

    pp = pprint.PrettyPrinter(indent = 4)

    print "Added user (" + user['uid'][0] + ") with id (" + str(user['uidNumber']) + ")"
    user['USER_ID'] = '1000'
    user['USER_UID'] = str(uuid.uuid4())
else:
    user['USER_ID'] = old_user['uidNumber'][0]
    user['USER_UID'] = old_user['apple-generateduid'][0]

group = find_group(l, config, user['USER_GROUP_NAME'])
user['USER_GROUP_ID'] = group['gidNumber'][0]

user['USER_PASSWORD_HASH'] = "{KERBEROS} " + user['USER_NAME']
 #hash_password(user['USER_PASSWORD'])

t = Template("user.ldif")
t.replace(config)
t.replace(user)
insert_ldif(l, str(t))

add_to_group(l, config, user['USER_NAME'], user['USER_GROUP_NAME'])

# Get user and show details
group = find_group(l, config, user['USER_GROUP_NAME'])
user = find_user(l, config, user['USER_NAME'])

pp = pprint.PrettyPrinter(indent = 4)

print "User added:"
pp.pprint(user)
pp.pprint(group)

l.unbind_s()