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']) + ")"
#
# This script sets up Kerberos on the client and joins
# the active directory domain to obtain a keytab file.
#

import sys
sys.path.append("..")

from config import config
from template import Template

import os

# Install Samba (for the net command) and Kerberos
os.system("apt-get install samba krb5-config krb5-user")

# Setup configuration
print "Installing Kerberos client configuration"

template = Template("../../config/shared/krb5.conf")
template.replace(config)
template.write("/etc/krb5.conf")

template = Template("../../config/shared/ad.conf")
template.replace(config)
template.write("/etc/ad.conf")

print "Joining system to Active Directory domain"

os.system("net ads join -s /etc/ad.conf -U " + config['AD_USERNAME'])
Пример #3
0
if old_user is None:
    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)
from config import config
from template import Template
from ldap_utils import init_ldap, insert_ldif, add_to_group, find_user, find_group

import uuid

l = init_ldap(config)

group = {}
group['GROUP_NAME'] = 'admin'
group['GROUP_ID'] = '1100'
group['GROUP_LONGNAME'] = 'Administrators'
group['GROUP_UID'] = str(uuid.uuid4())

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


group = {}
group['GROUP_NAME'] = 'user'
group['GROUP_ID'] = '1101'
group['GROUP_LONGNAME'] = 'Users'
group['GROUP_UID'] = str(uuid.uuid4())

t = Template("../../config/plab-ldap/templates/group.ldif")
t.replace(config)
t.replace(group)
insert_ldif(l, str(t))
#
# This script creates the users and groups OUs in your LDAP database.
#

import sys
sys.path.append("..")

from config import config
from template import Template
from ldap_utils import init_ldap, insert_ldif

import ldap
import base64

l = init_ldap(config)

# Build odconfig for Mac
t = Template("../../config/plab-ldap/templates/odconfig")
t.replace({'HOMEDIRECTORY': '#/Users/$uid$'})
t.replace(config)
odconfig = base64.b64encode(str(t).replace('\n', ''))

for item in ["ou=groups.ldif", "ou=users.ldif", "ou=macosx.ldif"]:
    t = Template("../../config/plab-ldap/templates/" + item)
    t.replace(config)
    t.replace({"ODCONFIG": odconfig})
    insert_ldif(l, str(t))

l.unbind_s()