Created attachment 9503 [details]
Patch fixing the issue of host unreachable error in libsmbclient
We are using libsmbclient in our application, which is contacting AD and its member file servers. In cases where the file server is down, and we are trying to access the files, the api SMBC_stat_ctx() doesn't return host unreachable (errno 113). Instead it always return ENOENT (2), which is file not found. This is creating confusion with the case where the file is actually deleted. This is the same observation with few other APIs as well which we are using like SMBC_write_ctx, SMBC_read_ctx etc.
I tried to understand the code flow and these are my understanding. Please correct me if I have misread it. Most of the APIs exposed by libsmbclient, calls cli_resolve_path() which does the actual connection to the share in the cli_cm_open(). But this error is not returned eventually to the caller of the API. Instead it sets errno as ENOENT, and returns -1. This way it is not capturing the host unreachable state of the file server.
Based on this understanding, I created a patch and with that I could get the desired result. I am attaching the patch which is working for me. Please review this change. This is based on master branch code base.