Install Poptop On FreeBSD

Step 1 - Install Poptop:
cd /usr/ports/net/poptop
make install clean

Step 2 - Create a Poptop config file: /usr/local/etc/pptpd.conf
cp -rp /usr/local/etc/pptpd.conf.sample /usr/local/etc/pptpd.conf
vi /usr/local/etc/pptpd.conf
option /etc/ppp/ppp.conf
localip 10.8.0.1
remoteip 10.8.0.10-254
pidfile /var/run/pptpd.pid
nobsdcomp
proxyarp
+chapms-v2
mppe-40
mppe-128
mppe-stateless
noipparam

Be sure to replace ¨10.8.0.1〔 with your serverˇs IP address, and ¨10.8.0.10-254〔 is the range of IP addresses you want assigned to incoming clients. In this case, I only allocated 245 addresses.

Step 3 - Add an entry to /etc/ppp/ppp.conf
vi /etc/ppp/ppp.conf
pptp:
 set timeout 0
 set log phase chat connect lcp ipcp
 set dial
 set login
 enable mssfixup
 set ifaddr 10.8.0.1 10.8.0.10-10.8.0.254 255.255.255.0
 set server /tmp/loop "" 0177
 enable chap
 enable mschapv2
 disable pap
 enable proxy
 accept dns
 set dns 10.8.0.1
 set nbns 10.8.0.1
 set device !/etc/ppp/secure

Again, be sure to replace ¨10.8.0.1〔 with your serverˇs IP address, and ¨10.8.0.10-10.8.0.254〔 is the range of IP addresses for incoming clients. Youˇll also want to set appropriate DNS servers, as well as nbns (WINS) server if needed.

Step 4 - Create a password file /etc/ppp/ppp.secret
vi /etc/ppp/ppp.secret
It should contain lines such as:
username password
Note: I have not tried this but some have said that putting ¨enable passwordauth〃 in ppp.conf will authenticate against /etc/passwd. Using a separate file gives more control, but itˇs not as convenient.
Note 2: I shouldnˇt have to remind you that since the file contains passwords, it should be mode 0600 !

Step 5 - Enable pptpd in /etc/rc.conf:
vi /etc/rc.conf
pptpd_enable="YES"

Step 6 - Start pptpd:
/usr/local/etc/rc.d/pptpd start

OpenVPN and Samba with FreeBSD, PF and Windows XP

From: http://www.ubergeek.co.uk/howtos/openvpn-freebsd-pf-windows-howto.html

OpenVPN and Samba with FreeBSD, PF and Windows XP
This howto is a quick a dirty guide to building OpenVPN on a FreeBSD box (running pf as the firewall), and then connecting a Windows XP client to it.

Last updated: 23th July 2006

Server Install
First install the port

cd /usr/ports/security/openvpn
make install clean

Now that the port is installed you can start setting stuff up.

First edit your /etc/rc.conf and add the following line:-

vi /etc/rc.conf

openvpn_enable="YES"
openvpn_if="tun"

Now create the config files, which we will place in /usr/local/etc/openvpn:-

mkdir /usr/local/etc/openvpn
mkdir /var/log/openvpn/

vi /usr/local/etc/openvpn/openvpn.conf

Place this into your config file:-

----------snip-----------
#################################################
# Sample OpenVPN 2.0 config file for            #
# multi-client server.                          #
#                                               #
# This file is for the server side              #
# of a many-clients <-> one-server              #
# OpenVPN configuration.                        #
#                                               #
# OpenVPN also supports                         #
# single-machine <-> single-machine             #
# configurations (See the Examples page         #
# on the web site for more info).               #
#                                               #
# This config should work on Windows            #
# or Linux/BSD systems.  Remember on            #
# Windows to quote pathnames and use            #
# double backslashes, e.g.:                     #
# "C:\\Program Files\\OpenVPN\\config\\foo.key" #
#                                               #
# Comments are preceded with '#' or ';'         #
#################################################

# Which local IP address should OpenVPN
# listen on? (optional)
;local a.b.c.d

# Which TCP/UDP port should OpenVPN listen on?
# If you want to run multiple OpenVPN instances
# on the same machine, use a different port
# number for each one.  You will need to
# open up this port on your firewall.
port 1194

# TCP or UDP server?
proto tcp
;proto udp

# "dev tun" will create a routed IP tunnel,
# "dev tap" will create an ethernet tunnel.
# Use "dev tap0" if you are ethernet bridging
# and have precreated a tap0 virtual interface
# and bridged it with your ethernet interface.
# If you want to control access policies
# over the VPN, you must create firewall
# rules for the the TUN/TAP interface.
# On non-Windows systems, you can give
# an explicit unit number, such as tun0.
# On Windows, use "dev-node" for this.
# On most systems, the VPN will not function
# unless you partially or fully disable
# the firewall for the TUN/TAP interface.
;dev tap
dev tun

# Windows needs the TAP-Win32 adapter name
# from the Network Connections panel if you
# have more than one.  On XP SP2 or higher,
# you may need to selectively disable the
# Windows firewall for the TAP adapter.
# Non-Windows systems usually don't need this.
;dev-node MyTap

# SSL/TLS root certificate (ca), certificate
# (cert), and private key (key).  Each client
# and the server must have their own cert and
# key file.  The server and all clients will
# use the same ca file.
#
# See the "easy-rsa" directory for a series
# of scripts for generating RSA certificates
# and private keys.  Remember to use
# a unique Common Name for the server
# and each of the client certificates.
#
# Any X509 key management system can be used.
# OpenVPN can also use a PKCS #12 formatted key file
# (see "pkcs12" directive in man page).
ca /usr/local/etc/openvpn/keys/ca.crt
cert /usr/local/etc/openvpn/keys/server.crt
key /usr/local/etc/openvpn/keys/server.key  # This file should be kept secret

# Diffie hellman parameters.
# Generate your own with:
#   openssl dhparam -out dh1024.pem 1024
# Substitute 2048 for 1024 if you are using
# 2048 bit keys.
dh /usr/local/etc/openvpn/keys/dh1024.pem

# Configure server mode and supply a VPN subnet
# for OpenVPN to draw client addresses from.
# The server will take 10.8.0.1 for itself,
# the rest will be made available to clients.
# Each client will be able to reach the server
# on 10.8.0.1. Comment this line out if you are
# ethernet bridging. See the man page for more info.
server 10.8.0.0 255.255.255.0

# Maintain a record of client <-> virtual IP address
# associations in this file.  If OpenVPN goes down or
# is restarted, reconnecting clients can be assigned
# the same virtual IP address from the pool that was
# previously assigned.
ifconfig-pool-persist ipp.txt

# Configure server mode for ethernet bridging.
# You must first use your OS's bridging capability
# to bridge the TAP interface with the ethernet
# NIC interface.  Then you must manually set the
# IP/netmask on the bridge interface, here we
# assume 10.8.0.4/255.255.255.0.  Finally we
# must set aside an IP range in this subnet
# (start=10.8.0.50 end=10.8.0.100) to allocate
# to connecting clients.  Leave this line commented
# out unless you are ethernet bridging.
;server-bridge 10.8.0.4 255.255.255.0 10.8.0.50 10.8.0.100

# Push routes to the client to allow it
# to reach other private subnets behind
# the server.  Remember that these
# private subnets will also need
# to know to route the OpenVPN client
# address pool (10.8.0.0/255.255.255.0)
# back to the OpenVPN server.
;push "route 192.168.10.0 255.255.255.0"
;push "route 192.168.20.0 255.255.255.0"

# To assign specific IP addresses to specific
# clients or if a connecting client has a private
# subnet behind it that should also have VPN access,
# use the subdirectory "ccd" for client-specific
# configuration files (see man page for more info).

# EXAMPLE: Suppose the client
# having the certificate common name "Thelonious"
# also has a small subnet behind his connecting
# machine, such as 192.168.40.128/255.255.255.248.
# First, uncomment out these lines:
;client-config-dir ccd
;route 192.168.40.128 255.255.255.248
# Then create a file ccd/Thelonious with this line:
#   iroute 192.168.40.128 255.255.255.248
# This will allow Thelonious' private subnet to
# access the VPN.  This example will only work
# if you are routing, not bridging, i.e. you are
# using "dev tun" and "server" directives.

# EXAMPLE: Suppose you want to give
# Thelonious a fixed VPN IP address of 10.9.0.1.
# First uncomment out these lines:
;client-config-dir ccd
;route 10.9.0.0 255.255.255.252
# Then add this line to ccd/Thelonious:
#   ifconfig-push 10.9.0.1 10.9.0.2

# Suppose that you want to enable different
# firewall access policies for different groups
# of clients.  There are two methods:
# (1) Run multiple OpenVPN daemons, one for each
#     group, and firewall the TUN/TAP interface
#     for each group/daemon appropriately.
# (2) (Advanced) Create a script to dynamically
#     modify the firewall in response to access
#     from different clients.  See man
#     page for more info on learn-address script.
;learn-address ./script

# If enabled, this directive will configure
# all clients to redirect their default
# network gateway through the VPN, causing
# all IP traffic such as web browsing and
# and DNS lookups to go through the VPN
# (The OpenVPN server machine may need to NAT
# the TUN/TAP interface to the internet in
# order for this to work properly).
# CAVEAT: May break client's network config if
# client's local DHCP server packets get routed
# through the tunnel.  Solution: make sure
# client's local DHCP server is reachable via
# a more specific route than the default route
# of 0.0.0.0/0.0.0.0.
;push "redirect-gateway"

# Certain Windows-specific network settings
# can be pushed to clients, such as DNS
# or WINS server addresses.  CAVEAT:
# http://openvpn.net/faq.html#dhcpcaveats
push "dhcp-option DNS 10.8.0.1"
push "dhcp-option WINS 10.8.0.1"

# Uncomment this directive to allow different
# clients to be able to "see" each other.
# By default, clients will only see the server.
# To force clients to only see the server, you
# will also need to appropriately firewall the
# server's TUN/TAP interface.
client-to-client

# Uncomment this directive if multiple clients
# might connect with the same certificate/key
# files or common names.  This is recommended
# only for testing purposes.  For production use,
# each client should have its own certificate/key
# pair.
#
# IF YOU HAVE NOT GENERATED INDIVIDUAL
# CERTIFICATE/KEY PAIRS FOR EACH CLIENT,
# EACH HAVING ITS OWN UNIQUE "COMMON NAME",
# UNCOMMENT THIS LINE OUT.
duplicate-cn

# The keepalive directive causes ping-like
# messages to be sent back and forth over
# the link so that each side knows when
# the other side has gone down.
# Ping every 10 seconds, assume that remote
# peer is down if no ping received during
# a 120 second time period.
keepalive 10 120

# For extra security beyond that provided
# by SSL/TLS, create an "HMAC firewall"
# to help block DoS attacks and UDP port flooding.
#
# Generate with:
#   openvpn --genkey --secret ta.key
#
# The server and each client must have
# a copy of this key.
# The second parameter should be '0'
# on the server and '1' on the clients.
;tls-auth ta.key 0 # This file is secret

# Select a cryptographic cipher.
# This config item must be copied to
# the client config file as well.
;cipher BF-CBC        # Blowfish (default)
;cipher AES-128-CBC   # AES
;cipher DES-EDE3-CBC  # Triple-DES

# Enable compression on the VPN link.
# If you enable it here, you must also
# enable it in the client config file.
comp-lzo

# The maximum number of concurrently connected
# clients we want to allow.
;max-clients 100

# It's a good idea to reduce the OpenVPN
# daemon's privileges after initialization.
#
# You can uncomment this out on
# non-Windows systems.
user nobody
group nobody

# The persist options will try to avoid
# accessing certain resources on restart
# that may no longer be accessible because
# of the privilege downgrade.
persist-key
persist-tun

# Output a short status file showing
# current connections, truncated
# and rewritten every minute.
status /var/log/openvpn/openvpn-status.log

# By default, log messages will go to the syslog (or
# on Windows, if running as a service, they will go to
# the "\Program Files\OpenVPN\log" directory).
# Use log or log-append to override this default.
# "log" will truncate the log file on OpenVPN startup,
# while "log-append" will append to it.  Use one
# or the other (but not both).
log         /var/log/openvpn/openvpn.log
log-append  /var/log/openvpn/openvpn.log

# Set the appropriate level of log
# file verbosity.
#
# 0 is silent, except for fatal errors
# 4 is reasonable for general usage
# 5 and 6 can help to debug connection problems
# 9 is extremely verbose
verb 3

# Silence repeating messages.  At most 20
# sequential messages of the same message
# category will be output to the log.
;mute 20

----------snip-----------

Creating Certificates

cd /usr/local/share/doc/openvpn/easy-rsa

Now edit the "vars" file to set your specific details and set the environment variables you have just created and build the Certificate Authority certificates:-

NOTE: Very Important Step for FreeBSD/TCSH users
FreeBSD ships with tcsh as its native shell, at the time of writing the following scripts do not work. To get around this you must drop down to a bourne shell. To do this just type the following at a prompt:-

sh

Now you can carry on with building the certificates, once you have built them you can exit back out to tcsh.
. vars
./clean-all
./build-ca

You will have to answer a few questions on the last step, once this has been done your CA certs will be created in the keys subdirectory.

Generate certificate & key for server:-

./build-key-server server

Again answer the questions and the certs will be placed in the keys subdirectory.

Generate certificates & keys for 3 clients (each client will require their own certificates, if multiple clients log in with the same certs then they will be assigned the same ips and will kick each other off the network):-

Generating client certificates is very similar to the previous step. You need to ensure that all your details are the same as for the CA, apart from the common name, which needs to be different for each client. For the sake of clarity this should relate to person who is assigned this vpn certificate. All of these details can be found in keys/server.crt for the server and keys/client*.crt for the client details.

./build-key jason
./build-key test

Generate Diffie Hellman parameters

Diffie Hellman parameters must be generated for the OpenVPN server:-

./build-dh

Now link the whole keys directory to /usr/local/etc/openvpn:-

ln -s /usr/local/share/doc/openvpn/easy-rsa/keys /usr/local/etc/openvpn/keys

Now start OpenVPN:-

/usr/local/etc/rc.d/openvpn restart

Check /var/log/openvpn/openvpn.log for errors, then check that the device has been created. Mine looks like this:-

----------snip-----------
Fri Jul  7 22:49:46 2006 OpenVPN 2.0.6 i386-portbld-freebsd6.1 [SSL] [LZO] built on Jul  2 2006
Fri Jul  7 22:49:46 2006 WARNING: --ifconfig-pool-persist will not work with --duplicate-cn
Fri Jul  7 22:49:46 2006 Diffie-Hellman initialized with 1024 bit key
Fri Jul  7 22:49:46 2006 TLS-Auth MTU parms [ L:1544 D:140 EF:40 EB:0 ET:0 EL:0 ]
Fri Jul  7 22:49:46 2006 gw 202.67.155.215
Fri Jul  7 22:49:46 2006 TUN/TAP device /dev/tun0 opened
Fri Jul  7 22:49:46 2006 /sbin/ifconfig tun0 10.8.0.1 10.8.0.2 mtu 1500 netmask 255.255.255.255 up
Fri Jul  7 22:49:46 2006 /sbin/route add -net 10.8.0.0 10.8.0.2 255.255.255.0
add net 10.8.0.0: gateway 10.8.0.2
Fri Jul  7 22:49:46 2006 Data Channel MTU parms [ L:1544 D:1450 EF:44 EB:135 ET:0 EL:0 AF:3/1 ]
Fri Jul  7 22:49:46 2006 GID set to nobody
Fri Jul  7 22:49:46 2006 UID set to nobody
Fri Jul  7 22:49:46 2006 Listening for incoming TCP connection on [undef]:1194
Fri Jul  7 22:49:46 2006 TCPv4_SERVER link local (bound): [undef]:1194
Fri Jul  7 22:49:46 2006 TCPv4_SERVER link remote: [undef]
Fri Jul  7 22:49:46 2006 MULTI: multi_init called, r=256 v=256
Fri Jul  7 22:49:46 2006 IFCONFIG POOL: base=10.8.0.4 size=62
Fri Jul  7 22:49:46 2006 IFCONFIG POOL LIST
Fri Jul  7 22:49:46 2006 MULTI: TCP INIT maxclients=1024 maxevents=1028
Fri Jul  7 22:49:46 2006 Initialization Sequence Completed
Fri Jul  7 22:49:46 2006 MULTI: multi_create_instance called
Fri Jul  7 22:49:46 2006 Re-using SSL/TLS context
Fri Jul  7 22:49:46 2006 LZO compression initialized
Fri Jul  7 22:49:46 2006 Control Channel MTU parms [ L:1544 D:140 EF:40 EB:0 ET:0 EL:0 ]
Fri Jul  7 22:49:46 2006 Data Channel MTU parms [ L:1544 D:1450 EF:44 EB:135 ET:0 EL:0 AF:3/1 ]
Fri Jul  7 22:49:46 2006 Local Options hash (VER=V4): 'c0103fa8'
Fri Jul  7 22:49:46 2006 Expected Remote Options hash (VER=V4): '69109d17'
Fri Jul  7 22:49:46 2006 TCP connection established with 203.168.214.145:50548
Fri Jul  7 22:49:46 2006 TCPv4_SERVER link local: [undef]
Fri Jul  7 22:49:46 2006 TCPv4_SERVER link remote: 203.168.214.145:50548
Fri Jul  7 22:49:46 2006 203.168.214.145:50548 TLS: Initial packet from 203.168.214.145:50548, sid=ee9aa786 c46e8e35
Fri Jul  7 22:49:47 2006 203.168.214.145:50548 VERIFY OK: depth=1, /C=HK/ST=HK/L=HK/O=HOTTOP/OU=HOTTOP/CN=JASON/emailAddress=A
Email住址會使用灌水程式保護機制。你需要啟動Javascript才能觀看它
Fri Jul  7 22:49:47 2006 203.168.214.145:50548 VERIFY OK: depth=0, /C=HK/ST=HK/O=HOTTOP/OU=HOTTOP/CN=JASON/emailAddress=JASON@
JASON-TANG.COM
Fri Jul  7 22:49:47 2006 MULTI: multi_create_instance called
Fri Jul  7 22:49:47 2006 Re-using SSL/TLS context
Fri Jul  7 22:49:47 2006 LZO compression initialized
Fri Jul  7 22:49:47 2006 Control Channel MTU parms [ L:1544 D:140 EF:40 EB:0 ET:0 EL:0 ]
Fri Jul  7 22:49:47 2006 Data Channel MTU parms [ L:1544 D:1450 EF:44 EB:135 ET:0 EL:0 AF:3/1 ]
Fri Jul  7 22:49:47 2006 Local Options hash (VER=V4): 'c0103fa8'
Fri Jul  7 22:49:47 2006 Expected Remote Options hash (VER=V4): '69109d17'
Fri Jul  7 22:49:47 2006 TCP connection established with 203.168.214.145:60943
Fri Jul  7 22:49:47 2006 TCPv4_SERVER link local: [undef]
Fri Jul  7 22:49:47 2006 TCPv4_SERVER link remote: 203.168.214.145:60943
Fri Jul  7 22:49:47 2006 203.168.214.145:60943 TLS: Initial packet from 203.168.214.145:60943, sid=fc440177 9e9dd6aa
Fri Jul  7 22:49:47 2006 203.168.214.145:50548 Data Channel Encrypt: Cipher 'BF-CBC' initialized with 128 bit key
Fri Jul  7 22:49:47 2006 203.168.214.145:50548 Data Channel Encrypt: Using 160 bit message hash 'SHA1' for HMAC authentication
Fri Jul  7 22:49:47 2006 203.168.214.145:50548 Data Channel Decrypt: Cipher 'BF-CBC' initialized with 128 bit key
Fri Jul  7 22:49:47 2006 203.168.214.145:50548 Data Channel Decrypt: Using 160 bit message hash 'SHA1' for HMAC authentication
Fri Jul  7 22:49:48 2006 203.168.214.145:50548 Control Channel: TLSv1, cipher TLSv1/SSLv3 DHE-RSA-AES256-SHA, 1024 bit RSA
Fri Jul  7 22:49:48 2006 203.168.214.145:50548 [JASON] Peer Connection Initiated with 203.168.214.145:50548
Fri Jul  7 22:49:48 2006 JASON/203.168.214.145:50548 MULTI: Learn: 10.8.0.6 -> JASON/203.168.214.145:50548
Fri Jul  7 22:49:48 2006 JASON/203.168.214.145:50548 MULTI: primary virtual IP for JASON/203.168.214.145:50548: 10.8.0.6
Fri Jul  7 22:49:48 2006 203.168.214.145:60943 VERIFY OK: depth=1, /C=HK/ST=HK/L=HK/O=HOTTOP/OU=HOTTOP/CN=JASON/emailAddress=A
Email住址會使用灌水程式保護機制。你需要啟動Javascript才能觀看它
Fri Jul  7 22:49:48 2006 203.168.214.145:60943 VERIFY OK: depth=0, /C=HK/ST=HK/O=HOTTOP/OU=HOTTOP/CN=JASON/emailAddress=TEST@J
ASON-TANG.COM
Fri Jul  7 22:49:48 2006 203.168.214.145:60943 Data Channel Encrypt: Cipher 'BF-CBC' initialized with 128 bit key
Fri Jul  7 22:49:48 2006 203.168.214.145:60943 Data Channel Encrypt: Using 160 bit message hash 'SHA1' for HMAC authentication
Fri Jul  7 22:49:48 2006 203.168.214.145:60943 Data Channel Decrypt: Cipher 'BF-CBC' initialized with 128 bit key
Fri Jul  7 22:49:48 2006 203.168.214.145:60943 Data Channel Decrypt: Using 160 bit message hash 'SHA1' for HMAC authentication
Fri Jul  7 22:49:49 2006 JASON/203.168.214.145:50548 PUSH: Received control message: 'PUSH_REQUEST'
Fri Jul  7 22:49:49 2006 JASON/203.168.214.145:50548 SENT CONTROL [JASON]: 'PUSH_REPLY,dhcp-option DNS 10.8.0.1,dhcp-option WI
NS 10.8.0.1,route 10.8.0.0 255.255.255.0,ping 10,ping-restart 120,ifconfig 10.8.0.6 10.8.0.5' (status=1)
Fri Jul  7 22:49:49 2006 203.168.214.145:60943 Control Channel: TLSv1, cipher TLSv1/SSLv3 DHE-RSA-AES256-SHA, 1024 bit RSA
Fri Jul  7 22:49:49 2006 203.168.214.145:60943 [JASON] Peer Connection Initiated with 203.168.214.145:60943
Fri Jul  7 22:49:49 2006 JASON/203.168.214.145:60943 MULTI: Learn: 10.8.0.10 -> JASON/203.168.214.145:60943
Fri Jul  7 22:49:49 2006 JASON/203.168.214.145:60943 MULTI: primary virtual IP for JASON/203.168.214.145:60943: 10.8.0.10
Fri Jul  7 22:49:50 2006 JASON/203.168.214.145:60943 PUSH: Received control message: 'PUSH_REQUEST'
Fri Jul  7 22:49:50 2006 JASON/203.168.214.145:60943 SENT CONTROL [JASON]: 'PUSH_REPLY,dhcp-option DNS 10.8.0.1,dhcp-option WI
NS 10.8.0.1,route 10.8.0.0 255.255.255.0,ping 10,ping-restart 120,ifconfig 10.8.0.10 10.8.0.9' (status=1)
----------snip-----------


Samba Server Install

cd /usr/ports/net/samba3
make install clean

Edit your /etc/rc.conf and add the following line:-

vi /etc/rc.conf

samba_enable="YES"
winbindd_enable="YES"

mkdir /home/samba
chown -R nobody:nobody /home/samba

Now Edit the config files

vi /usr/local/etc/smb.conf

----------snip-----------
# This is the main Samba configuration file. You should read the
# smb.conf(5) manual page in order to understand the options listed
# here. Samba has a huge number of configurable options (perhaps too
# many!) most of which are not shown in this example
#
# For a step to step guide on installing, configuring and using samba,
# read the Samba-HOWTO-Collection. This may be obtained from:
http://www.samba.org/samba/docs/Samba-HOWTO-Collection.pdf
#
# Many working examples of smb.conf files can be found in the
# Samba-Guide which is generated daily and can be downloaded from:
http://www.samba.org/samba/docs/Samba-Guide.pdf
#
# Any line which starts with a ; (semi-colon) or a # (hash)
# is a comment and is ignored. In this example we will use a #
# for commentry and a ; for parts of the config file that you
# may wish to enable
#
# NOTE: Whenever you modify this file you should run the command "testparm"
# to check that you have not made any basic syntactic errors.
#
#======================= Global Settings =====================================
[global]

# workgroup = NT-Domain-Name or Workgroup-Name, eg: MIDEARTH
;   workgroup = MYGROUP
   workgroup = Workgroup

# server string is the equivalent of the NT Description field
   server string = Samba Server
   netbios name = samba

# Security mode. Defines in which mode Samba will operate. Possible
# values are share, user, server, domain and ads. Most people will want
# user level security. See the Samba-HOWTO-Collection for details.
;   security = user
   security = share

# This option is important for security. It allows you to restrict
# connections to machines which are on your local network. The
# following example restricts access to two C class networks and
# the "loopback" interface. For more examples of the syntax see
# the smb.conf man page
;   hosts allow = 192.168.1. 192.168.2. 127.
   hosts allow = 10.8.0. 127.0.0.1

# If you want to automatically load your printer list rather
# than setting them up individually then you'll need this
;   load printers = yes

# you may wish to override the location of the printcap file
;   printcap name = /etc/printcap

# on SystemV system setting printcap name to lpstat should allow
# you to automatically obtain a printer list from the SystemV spool
# system
;   printcap name = lpstat

# It should not be necessary to specify the print system type unless
# it is non-standard. Currently supported print systems include:
# bsd, cups, sysv, plp, lprng, aix, hpux, qnx
;   printing = cups

# Uncomment this if you want a guest account, you must add this to /etc/passwd
# otherwise the user "nobody" is used
;  guest account = pcguest

# this tells Samba to use a separate log file for each machine
# that connects
   log file = /var/log/samba/log.%m

# Put a capping on the size of the log files (in Kb).
   max log size = 5000

# Use password server option only with security = server
# The argument list may include:
#   password server = My_PDC_Name [My_BDC_Name] [My_Next_BDC_Name]
# or to auto-locate the domain controller/s
#   password server = *
;   password server = <NT-Server-Name>

# Use the realm option only with security = ads
# Specifies the Active Directory realm the host is part of
;   realm = MY_REALM

# Backend to store user information in. New installations should
# use either tdbsam or ldapsam. smbpasswd is available for backwards
# compatibility. tdbsam requires no further configuration.
;   passdb backend = tdbsam

# Using the following line enables you to customise your configuration
# on a per machine basis. The %m gets replaced with the netbios name
# of the machine that is connecting.
# Note: Consider carefully the location in the configuration file of
#       this line.  The included file is read at that point.
;   include = /usr/local/etc/smb.conf.%m

# Most people will find that this option gives better performance.
# See the chapter 'Samba performance issues' in the Samba HOWTO Collection
# and the manual pages for details.
# You may want to add the following on a Linux system:
#         SO_RCVBUF=8192 SO_SNDBUF=8192
   socket options = TCP_NODELAY

# Configure Samba to use multiple interfaces
# If you have multiple network interfaces then you must list them
# here. See the man page for details.
;   interfaces = 192.168.12.2/24 192.168.13.2/24
   interfaces = 10.8.0.1/24

# Browser Control Options:
# set local master to no if you don't want Samba to become a master
# browser on your network. Otherwise the normal election rules apply
   local master = no

# OS Level determines the precedence of this server in master browser
# elections. The default value should be reasonable
;   os level = 33

# Domain Master specifies Samba to be the Domain Master Browser. This
# allows Samba to collate browse lists between subnets. Don't use this
# if you already have a Windows NT domain controller doing this job
   domain master = yes

# Preferred Master causes Samba to force a local browser election on startup
# and gives it a slightly higher chance of winning the election
   preferred master = yes

# Enable this if you want Samba to be a domain logon server for
# Windows95 workstations.
   domain logons = yes

# if you enable domain logons then you may want a per-machine or
# per user logon script
# run a specific logon batch file per workstation (machine)
;   logon script = %m.bat
# run a specific logon batch file per username
;   logon script = %U.bat

# Where to store roving profiles (only for Win95 and WinNT)
#        %L substitutes for this servers netbios name, %U is username
#        You must uncomment the [Profiles] share below
;   logon path = \\%L\Profiles\%U

# Windows Internet Name Serving Support Section:
# WINS Support - Tells the NMBD component of Samba to enable it's WINS Server
   wins support = yes

# WINS Server - Tells the NMBD components of Samba to be a WINS Client
# Note: Samba can be either a WINS Server, or a WINS Client, but NOT both
;   wins server = w.x.y.z

# WINS Proxy - Tells Samba to answer name resolution queries on
# behalf of a non WINS capable client, for this to work there must be
# at least one WINS Server on the network. The default is NO.
   wins proxy = yes

# DNS Proxy - tells Samba whether or not to try to resolve NetBIOS names
# via DNS nslookups. The default is NO.
   dns proxy = yes

# Charset settings
;   display charset = koi8-r
;   unix charset = koi8-r
;   dos charset = cp866

# Use extended attributes to store file modes
;    store dos attributes = yes
;    map hidden = no
;    map system = no
;    map archive = no

# Use inherited ACLs for directories
;    nt acl support = yes
;    inherit acls = yes
;    map acl inherit = yes

# These scripts are used on a domain controller or stand-alone
# machine to add or delete corresponding unix accounts
;  add user script = /usr/sbin/useradd %u
;  add group script = /usr/sbin/groupadd %g
;  add machine script = /usr/sbin/adduser -n -g machines -c Machine -d /dev/null -s /bin/false %u
;  delete user script = /usr/sbin/userdel %u
;  delete user from group script = /usr/sbin/deluser %u %g
;  delete group script = /usr/sbin/groupdel %g


#============================ Share Definitions ==============================
[homes]
   comment = Home Directories for %u on %h
   browseable = no
   writable = yes
   path = /home/%u

# Un-comment the following and create the netlogon directory for Domain Logons
; [netlogon]
;   comment = Network Logon Service
;   path = /usr/local/samba/lib/netlogon
;   guest ok = yes
;   writable = no
;   share modes = no


# Un-comment the following to provide a specific roving profile share
# the default is to use the user's home directory
;[Profiles]
;    path = /usr/local/samba/profiles
;    browseable = no
;    guest ok = yes


# NOTE: If you have a BSD-style print system there is no need to
# specifically define each individual printer
;[printers]
;   comment = All Printers
;   path = /var/spool/samba
;   browseable = no
# Set public = yes to allow user 'guest account' to print
;   guest ok = no
;   writable = no
;   printable = yes

# This one is useful for people to share files
;[tmp]
;   comment = Temporary file space
;   path = /tmp
;   read only = no
;   public = yes

# A publicly accessible directory, but read only, except for people in
# the "staff" group
;[public]
;   comment = Public Stuff
;   path = /home/samba
;   public = yes
;   writable = yes
;   printable = no
;   write list = @staff

[public]
   comment = %h Shared Public Directory
   path = /home/samba
   force directory mode = 0777
   force create mode = 0777
   force group = nobody
   force user = nobody
   public = yes
   writeable = yes
   read only = no


# Other examples.
#
# A private printer, usable only by fred. Spool data will be placed in fred's
# home directory. Note that fred must have write access to the spool directory,
# wherever it is.
;[fredsprn]
;   comment = Fred's Printer
;   valid users = fred
;   path = /homes/fred
;   printer = freds_printer
;   public = no
;   writable = no
;   printable = yes

# A private directory, usable only by fred. Note that fred requires write
# access to the directory.
;[fredsdir]
;   comment = Fred's Service
;   path = /usr/somewhere/private
;   valid users = fred
;   public = no
;   writable = yes
;   printable = no

# a service which has a different directory for each machine that connects
# this allows you to tailor configurations to incoming machines. You could
# also use the %U option to tailor it by user name.
# The %m gets replaced with the machine name that is connecting.
;[pchome]
;  comment = PC Directories
;  path = /usr/pc/%m
;  public = no
;  writable = yes

# A publicly accessible directory, read/write to all users. Note that all files
# created in the directory by users will be owned by the default user, so
# any user with access can delete any other user's files. Obviously this
# directory must be writable by the default user. Another user could of course
# be specified, in which case all files would be owned by that user instead.
;[public]
;   path = /usr/somewhere/else/public
;   public = yes
;   only guest = yes
;   writable = yes
;   printable = no

# The following two entries demonstrate how to share a directory so that two
# users can place files there that will be owned by the specific users. In this
# setup, the directory should be writable by both users and should have the
# sticky bit set on it to prevent abuse. Obviously this could be extended to
# as many users as required.
;[myshare]
;   comment = Mary's and Fred's stuff
;   path = /usr/somewhere/shared
;   valid users = mary fred
;   public = no
;   writable = yes
;   printable = no
;   create mask = 0765
----------snip-----------

Now start Samba:-

/usr/local/etc/rc.d/samba.sh restart


Firewall Configuration
Now we need to alter PF to handle the VPN, below are the relevant sections of my /etc/pf.conf file:-

vi /etc/pf.conf

# VPN Interface
vpn_if="tun0"

other_services="{ 1194 }"
samba_services="{ 137, 138, 139 }"

# VPN connections inbound
pass in on $ext_if inet proto tcp from any to $ext_if port $other_services flags S/SA keep state

pass quick on $vpn_if inet proto { tcp, udp } from any to $vpn_if port $samba_services flags S/SA keep state

Now restart PF and your server will be ready for connections

Client setup
First download and install the GUI version of the client, which can be found here:-

http://www.openvpn.se

Once this is installed you will need to copy the following files from your server /usr/local/etc/openvpn/keys directory to the Windows PC C:\Program Files\Openvpn\config directory (this should be done in as secure a manner as possible, i.e. USB Stick or floppy rather than email!!!):-

ca.crt
jason.crt
jason.key

NOTE: For the next client you will need to copy the test.crt and test.key files to prevent issues later.

Create config file:-

create a jason.ovpn file in C:\Program Files\Openvpn\config and insert the following:-

----------snip-----------
client
remote www.jason-tang.com 1194
proto tcp
dev tun
comp-lzo

ca ca.crt
cert jason.crt
key jason.key

# Set log file verbosity.
verb 3
----------snip-----------

Turn off the firewall for the new Interface:-

On Windows XP, the firewall can be accessed by Control Panel -> Security Center -> Windows Firewall -> Advanced. In the Network Connection Settings control, uncheck the box corresponding to the TAP-Win32 adapter.

Now right-click the OpenVPN Icon in your Taskbar and click "connect". Once connected try pinging the remote interface and check (using tracert) that the remote network is available. Use tcpdump on the server to check traffic too:-

tcpdump -tt -i tun0

More Information:-
OpenVPN website http://www.openvpn.net