diff --git a/src/driver/toks_driver_ctx.c b/src/driver/toks_driver_ctx.c index dc2730b..36f494e 100644 --- a/src/driver/toks_driver_ctx.c +++ b/src/driver/toks_driver_ctx.c @@ -174,6 +174,7 @@ int toks_get_driver_ctx( uint32_t flags, struct toks_driver_ctx ** pctx) { + int32_t status; struct toks_driver_ctx_impl * ctx; struct toks_common_ctx cctx; struct toks_split_vector sargv; @@ -432,9 +433,49 @@ int toks_get_driver_ctx( return toks_get_driver_ctx_fail(meta); } - if (cctx.drvflags & TOKS_DRIVER_MODE_CLIENT) - if (toks_client_connect(&ctx->ctx)) - return toks_get_driver_ctx_fail(meta); + if (cctx.drvflags & TOKS_DRIVER_MODE_CLIENT) { + switch ((status = toks_client_connect(&ctx->ctx))) { + case NT_STATUS_SUCCESS: + break; + + case NT_STATUS_OBJECT_NAME_NOT_FOUND: + if (flags & TOKS_DRIVER_VERBOSITY_ERRORS) + toks_dprintf(STDERR_FILENO, + "%s: error: could not connect " + "(server not running) [0x%x].", + program,status); + + return toks_get_driver_ctx_fail(meta); + + case NT_STATUS_CONNECTION_REFUSED: + case NT_STATUS_PORT_CONNECTION_REFUSED: + if (flags & TOKS_DRIVER_VERBOSITY_ERRORS) + toks_dprintf(STDERR_FILENO, + "%s: error: could not connect " + "(connection refused) [0x%x].", + program,status); + + return toks_get_driver_ctx_fail(meta); + + case NT_STATUS_ACCESS_DENIED: + if (flags & TOKS_DRIVER_VERBOSITY_ERRORS) + toks_dprintf(STDERR_FILENO, + "%s: error: could not connect " + "(access denied) [0x%x].", + program,status); + + return toks_get_driver_ctx_fail(meta); + + default: + if (flags & TOKS_DRIVER_VERBOSITY_ERRORS) + toks_dprintf(STDERR_FILENO, + "%s: error: could not connect " + "(check the system's documentation) [0x%x].", + program,status); + + return toks_get_driver_ctx_fail(meta); + } + } *pctx = &ctx->ctx; return TOKS_OK;