#!/bin/sh
# Convert list of Windows/Samba boxes in local network to .nsmbrc format
# Args, if any passed directly to findsmb - network address and broadcast address
# $Id: smb2nsmbrc,v 1.4 2004/08/05 06:50:32 shelton Exp $

find="findsmb"			# Script to display boxes list
util="smbutil"			# Utility to convert plaintext password to hashed
outfile=".nsmbrctmp"		# Generated file name

# First, we check on presence findsmb
wfind=`whereis -b $find | awk '{print $2}'`

if [ -z $wfind ]; then
  echo FindSMB did not found in your system, please install samba package first
  exit 5
fi

# Second, we check on presence smbutil
wutil=`whereis -b $util | awk '{print $2}'`

if [ -z $wfind ]; then
  echo SMBUtil did not found in your system, please install samba package first
  exit 5
fi

# Now we ask username
echo -n "Please enter username (UPPER CASE!): "
read username

# Now we ask password and crypt by smbutil
password=`$util crypt`

# Now we detect all Windows/Samba boxes and taking their NetBIOS names
netnames=`findsmb $1 $2 | awk -f /usr/local/bin/smb2awk`

# And at least we generating temporarly file with username, password and
# sections for all detected boxes
for netname in $netnames
 do
  echo "[$netname:$username]" >> $outfile
  echo "password=$password" >> $outfile
  echo "" >> $outfile
 done
