Friday, March 22, 2013

Mailbox enable a user in Office 365 using PowerShell

I was searching high and low for this all around the internet. Enable-mailbox doesn't seem to work, New-Mailbox also doesn't do it... It turns out that the solution is one that doesn't make sense at all.

Apparently all you need to do in Office 365 is to assign a license (an MsolAccountSku) to the user, and the mailbox will be automatically provisioned based on the UPN. That easy!

Here are the commands...

First, get your Account SkuID:
$sku = Get-MsolAccountSku

Then set a location for the user (else you can add a license):
Set-MsolUser -UserPrincipalName user@domain.onmicrosoft.com \
-UsageLocation "SG"

Then, add the account SkuID to the user:
Set-MsolUserLicense -UserPrincipalName \
user@domain.onmicrosoft.com -AddLicenses $sku.AccountSkuId

Then you wait as the mailbox is provisioned in the background.

Wednesday, March 20, 2013

FreeBSD 9 Authenticate to 802.1X Wired Ethernet (LAN)

I've been searching high and low for a single solution to this problem, but there seem to be no good blog/guide that answers this.

The scenario is that my workplace, NUS is slowly rolling up 802.1X authentication for wired ethernet, that's the LAN socket on the wall you connect your computer to. Yes, we now have to use our AD username and password to authenticate before we can get any sort of network connectivity after connecting to the LAN socket. Now, of course, there are guides for staff/students to get connectivity, but the guides are only for windows, mac, and (surprise!) Ubuntu. And even the Ubuntu guide is only configuring through the GUI, nothing on the actual command-line and configuration files stuff.

After spending more than half a day (spread out in a 2-3 days period) hunting high and low, plus a little bit of reading and digging through the rc.d scripts, I finally managed to get my FreeBSD box to automatically authenticate, and obtain a DHCP lease from the wall socket. Phew!

It's actually only a 2 step process. First, create a /etc/wpa_supplicant.conf
ctrl_interface=/var/run/wpa_supplicant
ctrl_interface_group=wheel
ap_scan=0
network={
 key_mgmt=IEEE8021X
 eap=PEAP
 identity="Username"
 password="secretpassword"
 eapol_flags=0
}
UPDATE: keymgmt should be key_mgmt with an underscore (ref). Thanks, Ryan Stark

Basically, the important thing you need is ap_scan=0. Also, I believe keymgmt=IEEE8021X will ensure you're not using WPA or WEP or something of those sorts. The following lines are pretty well documented. My organisation uses PEAP, as for eapol_flags, I have no idea what it does. You can try taking it out, I believe it worked for me either way. The first two lines are just to create an admin listening socket so that wpa_cli can poll it for changes, or just to query the status of the wpa_supplicant daemon. For my case, I am limiting the admin interface to members of group 'wheel' only.

Then, configure /etc/rc.conf like so:
ifconfig_bge0="WPA DHCP"
UPDATE: should be WPA instead of WAP (ref), thanks Thor Erik!

Where bge0 is your network interface. At first, I was wondering how to include the -Dwired in the rc.conf, but apparently, the rc.d/wpa_supplicant script has already catered that for wired interfaces. How neat!

Oh, by the way, if you want to test whether your configuration is right, you can run wpa_supplicant with verbose debugging as below:
wpa_supplicant -dd -Dwired -c /etc/wpa_supplicant.conf \
-i bge0
Bear in mind that if it succeeds, the daemon will be in the foreground and will not return you to shell, you will need to Ctrl-Z it, and bg it to the background if you wish to continue working.

Next up, I'd wanna get it to join AD, register its IP address in AD's built-in DDNS, disallow AD user to login, but allow AD user to access Samba file share.

Installing (and optimizing) FreeBSD 9 on SSD drive

I've setup to install FreeBSD on one of the old desktop computers lying around. It has a Pentium D and GB or so of RAM. Am planning to use it for a ZFS file server using SAMBA.

Anyway, to fully optimize the partitioning process, I opted for the "Shell" mode. These are the commands I ran:

My SSD is on /dev/ada0.

Firstly, destroy the current partition table on the disk:
gpart destroy -F /dev/ada0
Next, create a GPT disk and add the partitions. I'm using a Crucial m4 SSD, and it's said to use 2 controllers and have a block size of 1024k, so let's align it to 1024k:
gpart create -s gpt ada0
gpart add -s 64k -t freebsd-boot -a 1024k -l boot0 ada0
gpart add -s 8G -t freebsd-swap -a 1024k -l swap0 ada0
gpart add -s 20G -t freebsd-ufs -a 1024k -l root0 ada0
gpart add -s 10G -t freebsd-ufs -a 1024k -l var0 ada0
gpart add -s 4G -t freebsd-ufs -a 1024k -l tmp0 ada0 
Now, install the bootcode:
gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 1 ada0
Next, format the partitions with softupdate (no point journaling for SSD as fsck will already be fast anyway). Also, turn on TRIM (important):
newfs -U -t /dev/ada0p3
newfs -U -t /dev/ada0p4
newfs -U -t /dev/ada0p5
Now that it's all done, let's mount them properly in /mnt for the installer to continue with the installation.
mount /dev/ada0p3 /mnt
mkdir /mnt/var /mnt/tmp
mount /dev/ada0p4 /mnt/var
mount /dev/ada0p5 /mnt/tmp
Don't forget to edit fstab:
vi /tmp/bsdinstall_etc/fstab
This is how my fstab looks like:
# Device     MntPnt  FSType  Options  Dump  Pass#
/dev/ada0p2  none    swap    sw       0     0
/dev/ada0p3  /       ufs     sw       1     1
/dev/ada0p4  /var    ufs     sw       1     2
/dev/ada0p5  /tmp    ufs     sw       0     3
Finally, we can now continue with the installation:
exit