#! /bin/bash # Shell functions to manipulate Directory Services # Copyright (C) 2007 Apple Inc. All rights reserved. DSCL=${DSCL:-"/usr/bin/dscl ."} DSSEARCH=${DSSEARCH:-"/usr/bin/dscl /Search"} DSEDITGROUP=${DSEDITGROUP:-"/usr/sbin/dseditgroup -n ."} ASROOT=${ASROOT:-sudo} # List the local users, sorted by ID. ds_list_user_ids() { $DSCL -list /Users UniqueID | awk '{print $2}' | sort -n } # Find all the known user IDs ds_search_user_ids() { $DSSEARCH -list /Users UniqueID | awk '{print $2}' | sort -n } # Find all the known user IDs ds_search_group_ids() { $DSSEARCH -list /Groups PrimaryGroupID | awk '{print $2}' | sort -n } ds_list_group_ids() { $DSCL -list /Groups PrimaryGroupID | awk '{print $2}' | sort -n } # True if the given username exists ds_user_exists() { $DSCL -list /Users/$1 > /dev/null 2>&1 } # Return the user's primary group if passed a user name. For some reason # /Search doesn't always find attributes and we need to look in /Local. ds_user_primary_group() { gid=$($DSSEARCH -read /Users/$1 PrimaryGroupID | awk '{print $2; exit}') if [ "$gid" = "" ]; then gid=$($DSCL -read /Users/$1 PrimaryGroupID | awk '{print $2; exit}') fi if [ "$gid" = "" ]; then false else echo $gid fi } ds_find_next_uid() { local highest=$(ds_list_user_ids | tail -1) echo $[$highest + 1] } ds_enable_user_for_smb() { local user="$1" local passwd="$2" # For some reason, we need to set the password both before and # after flipping the hashes. Go figure. $ASROOT $DSCL -passwd /Users/$user $passwd $ASROOT expect <