Update code to work with samba4

Hello,

Hope everything is well.

I've managed to get this working with samba 4. As the build scripts have changed significantly in samba 4, I couldn't get the existing build scripts to work. However I found I could build it along with samba with a few small changes to samba's build scripts.

If you have any comments or suggestions, I'm happy to try to improve my attempt at this.