Open a Micrsoft DFS share in golang using smb2

705 Views Asked by At

I have a dfs share on Windows server 2012. I can open the share and read files from another system in a windows file explorer with a path like: \\dfsserver\usernamepace\Tom\go.png. However, using golang's smb2 package by https://github.com/hirochachacha/go-smb2 I get an error as

response error: The contacted server does not support the indicated part of the DFS namespace

But if I try to open the file with it's actual share path \\dfsserver\public share\Tom\go.png then the code works fine. So the problem is that I have no knowledge of the actual path during runtime and I want to be able to open the file with path provided by DFS.

Could it be the case that DFS does not work properly with smb2? or some other issues. Thanks in advance for your comments.

    func main(){
    
        // actualPath := `\\dfsserver\public share\Tom\go.png`
        // dfsPath := `\\dfsserver\usernamespace\Tom\go.png`
    
        conn, err := net.Dial("tcp", fmt.Sprintf("%s:%s", "dfsserver", "445"))
        if err != nil {
            fmt.Println(err)
        }
        defer conn.Close()
    
        dial := &smb2.Dialer{
            Initiator: &smb2.NTLMInitiator{
                User:     "user",
                Password: "password",
                Domain:  "dfsserver",
            },
        }
        session, err := dial.Dial(conn)
        if err != nil {
            fmt.Println(err)
        }
        defer session.Logoff()
    
        mountPoint, err := session.Mount("usernamespace")
        if err != nil {
            fmt.Println(err)
            os.Exit(1)
        }
    
       // error occures here, if the mountPoint was "public share" instead of "usernamespace" then no error
        remoteFile, err := mountPoint.Open(`Tom\go.png`) 
        defer remoteFile.Close()
        if err != nil {
            fmt.Println(err)
        }
    }
0

There are 0 best solutions below