Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore FSDriverRequired when attempting to get DFS information for a BadNetworkName handler #196

Closed
franky920920 opened this issue Oct 25, 2022 · 11 comments · Fixed by #204

Comments

@franky920920
Copy link

Hi, the following error occurred:
Failed to authenticate with server: SpnegoError (1): SpnegoError (16): Operation not supported or available, Context: Retrieving NTLM store without NTLM_USER_FILE set to a filepath, Context: Unable to negotiate common mechanism

My code:

from smbclient import listdir, mkdir, register_session, rmdir, scandir, open_file
register_session(server=host, username=username, password=password)
with open_file(r"\\" + os.environ['fsxDns'] + "\\" + eKey, mode="w") as fd:
            fd.write(eObjBody)

Traceback:

Traceback (most recent call last):
File "/opt/python/smbprotocol/session.py", line 278, in connect
	out_token = context.step(in_token)
File "/opt/python/spnego/_negotiate.py", line 124, in step
	mech_token_in, mech_list_mic, is_spnego = self._step_spnego_input(in_token=in_token)
File "/opt/python/spnego/_negotiate.py", line 171, in _step_spnego_input
	mech_list = self._rebuild_context_list(mech_types=in_token.mech_types)
File "/opt/python/spnego/_negotiate.py", line 416, in _rebuild_context_list
	raise BadMechanismError(context_msg="Unable to negotiate common mechanism", base_error=last_err)
spnego.exceptions.BadMechanismError: SpnegoError (1): SpnegoError (16): Operation not supported or available, Context: Retrieving NTLM store without NTLM_USER_FILE set to a filepath, Context: Unable to negotiate common mechanism

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/var/task/lambda_function.py", line 57, in lambda_handler
	with open_file(r"\\" + os.environ['fsxDns'] + "\\" + eKey, mode="w") as fd:
File "/opt/python/smbclient/_os.py", line 369, in open_file
	raw_fd = file_class(path, mode=mode, share_access=share_access, desired_access=desired_access,
File "/opt/python/smbclient/_io.py", line 377, in __init__
	tree, fd_path = get_smb_tree(path, **kwargs)
File "/opt/python/smbclient/_pool.py", line 310, in get_smb_tree
	session = register_session(server, username=username, password=password, port=port, encrypt=encrypt,
File "/opt/python/smbclient/_pool.py", line 383, in register_session
	session.connect()
File "/opt/python/smbprotocol/session.py", line 280, in connect
	raise SMBAuthenticationError("Failed to authenticate with server: %s" % str(err.message))
smbprotocol.exceptions.SMBAuthenticationError: Failed to authenticate with server: SpnegoError (1): SpnegoError (16): Operation not supported or available, Context: Retrieving NTLM store without NTLM_USER_FILE set to a filepath, Context: Unable to negotiate common mechanism

Any help will be appericated. Thank you :D

@adiroiban
Copy link
Contributor

I think that adding a bit more info about your setup can help with troubleshooting this.

Is this a "simple" Windows share, do you have distributed shares... Azure Files, Samba server.

Are username and password non-empty?

Cheers

@franky920920
Copy link
Author

@adiroiban Is a share on AWS FSx for Windows Server (aka SMB share on Windows Server). User credentials are Active Directiry's credentials. Thanks

@jborean93
Copy link
Owner

This error should only occur if username/password is None or an empty string. It's trying to use NTLM but no environmental user file is present for it to use for authentication.

Can you 100% verify that username and password are set in your code?

@franky920920
Copy link
Author

@jborean93

Can you 100% verify that username and password are set in your code?

Yes, I've just print the variables out. 😄

@jborean93
Copy link
Owner

register_session(server=host, username=username, password=password)
with open_file(r"\\" + os.environ['fsxDns'] + "\\" + eKey, mode="w") as fd:
            fd.write(eObjBody)

In this example you have server=host, but the actual subsequent operation is using os.environ['fsxDns']. Are these the same? Can you omit the register_session and just do open_file(r"\\" + os.environ['fsxDns'] + "\\" + eKey, mode="w", username=username, password=password) as fd:?

@franky920920
Copy link
Author

When running open_file(r"\\" + os.environ['fsxDns'] + "\\" + eKey, mode="w", username=username, password=password) as fd: only, following error occurred:

[ERROR] FSDriverRequired: Received unexpected status from the server: A volume has been accessed for which a file system driver is required that has not yet been loaded. (3221225884) STATUS_FS_DRIVER_REQUIRED: 0xc000019c
Traceback (most recent call last):
  File "/var/task/lambda_function.py", line 59, in lambda_handler
    with open_file(r"\\" + os.environ['fsxDns'] + "\\" + eKey, mode="w", username=username, password=password) as fd:
  File "/opt/python/smbclient/_os.py", line 369, in open_file
    raw_fd = file_class(path, mode=mode, share_access=share_access, desired_access=desired_access,
  File "/opt/python/smbclient/_io.py", line 377, in __init__
    tree, fd_path = get_smb_tree(path, **kwargs)
  File "/opt/python/smbclient/_pool.py", line 327, in get_smb_tree
    referral = dfs_request(ipc_tree, "\\%s\\%s" % (path_split[0], path_split[1]))
  File "/opt/python/smbclient/_pool.py", line 209, in dfs_request
    response = tree.session.connection.receive(request)
  File "/opt/python/smbprotocol/connection.py", line 1006, in receive
    raise SMBResponseException(response)END RequestId: d3b4dc90-feb1-4518-a5d3-ff9a5b52b271

@jborean93
Copy link
Owner

Ok so we are at least past the authentication problems which is nice. The trouble here is that it's trying to do a DFS request but something is going wrong. What version of smbprotocol do you have installed?

@franky920920
Copy link
Author

smbprotocal version is 1.9.0 (latest)

@jborean93
Copy link
Owner

It seems like it is failing at https://github.com/jborean93/smbprotocol/blob/v1.9.0/smbclient/_pool.py#L327 which occurs when the initial result is BadNetworkName (share is not valid). While this particular error should be ignored and the original exception raised so it's not masked it seems like eKey is not a valid share to connect to on the host requested.

@franky920920
Copy link
Author

franky920920 commented Oct 25, 2022

ahhhh got it, I missed to add the share name in that string. Many thanks!

@jborean93
Copy link
Owner

I'm going to keep this open as a reminder to ignore FSDriverRequired in that particular bit of code. It would have hopefully made the problem clearer.

@jborean93 jborean93 reopened this Oct 25, 2022
@jborean93 jborean93 changed the title Failed to authenicate Ignore FSDriverRequired when attempting to get DFS information for a BadNetworkName handler Oct 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants