# Samba Question regarding Windows Shares

## h0mer`-

I have a simple question.

When i want to access anothers workstation shares in a windowsnetwork i will just enter "\\name_of_workstation" via the Start/Run... command and the result is a new window with all the shares listed.

Is it possible to mount exactly that directory? And whats the exact path to it?

----------

## rsa4046

 *h0mer`- wrote:*   

> I have a simple question.
> 
> When i want to access anothers workstation shares in a windowsnetwork i will just enter "\\name_of_workstation" via the Start/Run... command and the result is a new window with all the shares listed.
> 
> Is it possible to mount exactly that directory? And whats the exact path to it?

 

Assuming the Windows PC is called NETBIOS_NAME with share = ShareName, you could try:

```
$ smbclient //NETBIOS_NAME/ShareName
```

To mount NETBIOS_NAME's share ShareName, you could use smbmount (you'd have to do this as root if the mount doesn't appear in /etc/fstab)

```
# mount -t cifs //NETBIOS_NAME/ShareName <MountPoint> -o username=<name>,password=<pass>
```

----------

## h0mer`-

Thanks for your reply but that is not what i was asking for.

I am familiar with the mounting of windows shares and the syntax of samba. 

With the command "\\NETBIOS_NAME" typed into the Start/Run field, a new window opens with all the shares of the workstation i want access to. Its like the root directory of all the shares. What is the path of that directory? I mean there must be a way to mount this as it is accessible from every windows client.

NETBIOS_NAME

     |

     |--share1

     |--share2

     |--share2

I want to mount the directory from which i am able to see and access all the shares. Clear?

----------

## Rob1n

I'm pretty sure this isn't currently possible - what Windows shows isn't actually a real directory, it's just mapping the list of shares so they look that way (hence under XP you get a "Printers and Faxes" and a "Scheduled Tasks" folder, neither of which show when browsing from Win2k).  You can see this list of shares by doing "smbclient -L //NETBIOS_NAME" but I'm not aware of any Linux file browser which maps these onto a directory tree as Windows does though.

----------

## h0mer`-

Hmm, well okay then.... this makes my plan a little more complicated. Thx

----------

## zubb

I have the similar situation but I cant solve my problem

Here is the environment::

Share folders locates at server with FreeBSD.

One of the shares is accesible only with passwd

I want to mount all of them on demand as my current user (not root).

Here is a part of my fstab

```
//ADAM/vv       /home/vv/home        smbfs   credentials=/home/vv/.smbpasswd.home,user,noauto 0 0

//ADAM/exchange      /mnt/exchange        smbfs   credentials=/home/vv/.smbpasswd.exchange,user,noauto 0 0

/dev/sdb1       /mnt/usb                vfat    noauto,user
```

In the first case "smbpasswd" is filled with login & pwd, in the second it is without login & pwd

PS: I can mount the USB flash drive exactly in way I want. So guess it should work with smbfs

----------

## tarpman

 *h0mer`- wrote:*   

> I have a simple question.
> 
> When i want to access anothers workstation shares in a windowsnetwork i will just enter "\\name_of_workstation" via the Start/Run... command and the result is a new window with all the shares listed.
> 
> Is it possible to mount exactly that directory? And whats the exact path to it?

 

It is not an actual directory in the sense that you can browse it, although some Samba-aware file managers such as nautilus provide a similar feature.  To list shares from the command line, check out smbtree(1).

----------

## tarpman

 *zubb wrote:*   

> Here is the environment::
> 
> Share folders locates at server with FreeBSD.
> 
> One of the shares is accesible only with passwd
> ...

 

Hi zubb,

First of all, smbfs has been deprecated, so you should consider switching to cifs - it's on the same page as smbfs in the kernel configuration.

I don't know if smbfs supports the user option - I couldn't find it in the man page for smbmount(8).  I do know that cifs respects it, with the caveat that the mount point in question must belong to the user who wishes to mount it.  You can find more details on that in the man page for mount.cifs(8).

----------

## the_isz

Hi h0mer`- and everyone else!

I searched for the same as you did and couldn't find a satisfying solution either. So I started writing an own...

The following bash script I wrote gets the shares from a windows server, creates suitable folders for the shares and adds the shares to the /etc/fstab file.

Before executing the script, create a line in /etc/fstab starting with "#-----Samba Shares-----" (without the "). Everything following that line will be deleted by the script.

I don't take responsibility if this script harms your system! Use at your own risk.

```

#!/bin/bash

# IP of the windows machine

SERVER_IP=192.168.2.2

# TARGET_DIR is the directory you want to see the shares in and must not have a trailing "/"  

TARGET_DIR=/mnt/SAMBASRV

declare -a FOLDERS

# this command gets the shares from the server, extracts the share names and removes invalid shares (the ones

# with trailing $)

FOLDERS=( $(smbclient -g -N -L //$SERVER_IP 2>&1 | sed -e '/|/!d' -e 's/[^|]*|\([^\|]*\)|.*/\1/' -e '/\$$/d') )

# create TARGET_DIR if it doesnt exist

if [[ ! -d $TARGET_DIR ]]; then

        echo "target directory doesn't exist. trying to create..."

        mkdir -p $TARGET_DIR

        if [[ ! -d $TARGET_DIR ]]; then

                echo "could not create target directory. aborting."

                exit 1;

        fi

fi

# clean target directory

for folder in `ls $TARGET_DIR`

        do

        if [[ -d $folder ]]; then

                # check that $folder isn't currently mounted

                if [[ -z "`grep -i $TARGET_DIR/$folder`" ]]; then

                        rmdir $TARGET/$folder;

                else

                        echo "$TARGET_DIR/$folder is still mounted!"

                fi

        fi

done

# refill target directory

for folder in $(seq 0 $((${#FOLDERS[@]} -1 )))

        do

        if [[ ! -e $TARGET_DIR/${FOLDERS[$folder]} ]]; then

                mkdir $TARGET_DIR/${FOLDERS[$folder]}

        fi

done

# find special line in fstab marking the begin of the samba shares

FSTAB_LINE=`grep -nh "#-----Samba Shares-----" /etc/fstab | sed 's/\([0..9]*\):.*/\1/'`

if [[ -z $FSTAB_LINE ]]; then

        echo "special line in fstab not found! aborting operation."

        exit 1;

fi

(( FSTAB_LINE++ ))

# determine length of fstab file

FSTAB_MAX_LINE=`wc -l /etc/fstab | sed 's/\([0..9]*\) .*/\1/g'`

# delete all lines after FSTAB_LINE in /etc/fstab

if [[ $(( $FSTAB_MAX_LINE >= $FSTAB_LINE )) ]]; then

        sed -i "$FSTAB_LINE,$ d" /etc/fstab

fi

# add shares to fstab

# ToDo: convert spaces to \040

for folder in $(seq 0 $((${#FOLDERS[@]} -1 )))

        do

        echo "//$SERVER_IP/${FOLDERS[$folder]}  $TARGET_DIR/${FOLDERS[$folder]} cifs guest,noauto,users,noexec,iocharset=iso8859-1 0  0" >> /etc/fstab

done

```

One might want to setup a cron job that regularly executes this script.

Now the only problem that remains for me is that users can't mount cifs file systems if they don't own the mount points. This sucks...

Have fun with the script, I hope it helps someone.

Greetings,

Timo

----------

