Project

General

Profile

Feature #6424

Is it possible to configure FreeNAS to automatically reflect Adding user in AD and need to create a dataset for the new user.

Added by pandi raj about 6 years ago. Updated almost 6 years ago.

Status:
Closed
Priority:
Nice to have
Assignee:
Jordan Hubbard
Category:
OS
Target version:
Estimated time:
Severity:
New
Reason for Closing:
Reason for Blocked:
Needs QA:
Yes
Needs Doc:
Yes
Needs Merging:
Yes
Needs Automation:
No
Support Suite Ticket:
n/a
Hardware Configuration:

Description

Hi,
Kindly Help me, I am using FreeNas 9.2.1.8 Is it possible to configure FreeNAS to automatically reflect Adding user in AD and need to create a dataset for the new user name automatically? Or Is there any plugin?

History

#1 Updated by Jordan Hubbard about 6 years ago

  • Status changed from Unscreened to Closed
  • Priority changed from Expected to Nice to have

No. This must be done manually.

#2 Updated by John Lewis almost 6 years ago

I wrote a python script that I run via a cron job and sometimes will manually run it after creating a new user in the domain. It creates several datasets/sub-datasets with shared quotas for each user and symbolic links which are then accessed via private AFP/CIFS home shares to use with Time Machine and Windows 8 File History backups.

You'll need to modify it to your specific needs - there's a few comments that should help. DOMAIN is your NT short domain name, and "domain users" can be any domain group you want the user list to be pulled from.

usersync.py:

import os
import subprocess
import sys
sys.path.append('/usr/local/www/freenasUI/middleware')
from notifier import notifier

# Primary zpool volume: /mnt/vol/
#
# Extra datasets/folders needed before running the script: 
# (dataset) /mnt/vol/users        (type=unix, all user datasets are created here)
# (dataset) /mnt/vol/home         (type=unix, all symlinks are created here)
# (folder)  /mnt/vol/home/DOMAIN  (not a dataset, just a folder)
#
# Resulting datasets + symbolic links:
# (dataset) /mnt/vol/users/USERNAME          (type=unix,quota=X)
# (dataset) /mnt/vol/users/USERNAME/apple    (type=apple)
# (dataset) /mnt/vol/users/USERNAME/windows  (type=windows)
# (symlink) /mnt/vol/home/DOMAIN\USERNAME@ -> ../users/USERNAME/apple
# (symlink) /mnt/vol/home/DOMAIN/USERNAME@ -> ../../users/USERNAME/windows

blocked_users = ['root','administrator','krbtgt','guest','guest','tempuser']
volume = "vol" 
base_dataset = "users" 
base_home = "home" 
group_name = 'DOMAIN\\domain users'
quota = '1T'

group = str(group_name.partition('\\')[2])
domain = str(group_name.partition('\\')[0])

## call wbinfo --group-info command ##
output, error = subprocess.Popen("wbinfo --group-info '%s\\%s'" % (domain,group), stdout=subprocess.PIPE, shell=True).communicate()
for user_name in str(str(output).strip().split(":")[-1]).split(","):
    user = str(user_name.partition('\\')[2])
    if any(user in buser for buser in blocked_users):
        print "Blocked User: %s" % (user_name)
    elif str(user_name.partition('\\')[0]) != domain:
        print "Invalid Domain: %s" % (user_name)
    else:
        dataset = "%s/%s/%s" % (volume,base_dataset,user)
        path = "/mnt/%s" % dataset

        # Create base unix dataset
        props = {}
        props['quota'] = quota
        errno, errmsg = notifier().create_zfs_dataset(
                        path=dataset,
                        props=props)
        if errno == 0:
            print "New User: %s" % (user_name)
            notifier().dataset_init_unix(dataset)
            print "Base dataset successfully added: %s" % (dataset)

            # Create dataset/apple
            props = {}
            notifier().create_zfs_dataset(path=dataset+"/apple", props=props)
            notifier().dataset_init_apple(dataset+"/apple")
            notifier().mp_change_permission(path=path+"/apple", user=user_name, acl='unix')
            print "Apple dataset successfully added: %s" % (dataset+"/apple")

            # Create dataset/windows 
            props = {}
            props['aclmode'] = 'restricted'
            notifier().create_zfs_dataset(path=dataset+"/windows", props=props)
            notifier().dataset_init_windows(dataset+"/windows")
            notifier().mp_change_permission(path=path+"/windows", user=user_name, acl='windows')
            print "Windows dataset successfully added: %s" % (dataset+"/windows")

            home_path = "/mnt/%s/%s" % (volume,base_home)
            os.symlink("../%s/%s/apple" % (base_dataset,user),home_path+"/"+user_name)
            os.symlink("../../%s/%s/windows" % (base_dataset,user),home_path+"/"+domain+"/"+user)
        else:
            print "Skipped User: %s (Dataset already exists)" % (user_name)

(FYI: I am currently running FreeNAS 9.2.1.8)

Also available in: Atom PDF