/* * Check a server for being alive and well. * returns 0 if the server is in shape. Returns 1 on error * * Also useable outside libsmbclient to enable external cache * to do some checks too. */ int SMBC_check_server(SMBCCTX * context, SMBCSRV * server) { time_t now; if (!cli_state_is_connected(server->cli)) { return 1; } now = time_mono(NULL); if (server->last_echo_time == (time_t)0 || now > server->last_echo_time + (server->cli->timeout/1000)) { unsigned char data[16] = {0}; NTSTATUS status = cli_echo(server->cli, 1, data_blob_const(data, sizeof(data))); if (!NT_STATUS_IS_OK(status)) { return 1; } server->last_echo_time = now; } return 0; }
const char *cli_errstr(struct cli_state *cli) { fstring cli_error_message; char *result; if (!cli->initialised) { fstrcpy(cli_error_message, "[Programmer's error] cli_errstr called on unitialized cli_stat struct!\n"); goto done; } /* Case #1: RAP error */ if (cli->rap_error) { strlcpy(cli_error_message, win_errstr(W_ERROR(cli->rap_error)), sizeof(cli_error_message)); goto done; } if (!cli_state_is_connected(cli) && NT_STATUS_IS_OK(cli->raw_status)) { return nt_errstr(NT_STATUS_CONNECTION_DISCONNECTED); } return nt_errstr(cli->raw_status); done: result = talloc_strdup(talloc_tos(), cli_error_message); SMB_ASSERT(result); return result; }
static int tstream_cli_np_destructor(struct tstream_cli_np *cli_nps) { NTSTATUS status; if (!cli_state_is_connected(cli_nps->cli)) { return 0; } /* * TODO: do not use a sync call with a destructor!!! * * This only happens, if a caller does talloc_free(), * while the everything was still ok. * * If we get an unexpected failure within a normal * operation, we already do an async cli_close_send()/_recv(). * * Once we've fixed all callers to call * tstream_disconnect_send()/_recv(), this will * never be called. */ status = cli_close(cli_nps->cli, cli_nps->fnum); if (!NT_STATUS_IS_OK(status)) { DEBUG(1, ("tstream_cli_np_destructor: cli_close " "failed on pipe %s. Error was %s\n", cli_nps->npipe, nt_errstr(status))); } /* * We can't do much on failure */ return 0; }
bool cli_is_dos_error(struct cli_state *cli) { /* A socket error is always a DOS error. */ if (!cli_state_is_connected(cli)) { return true; } return cli_is_error(cli) && NT_STATUS_IS_DOS(cli->raw_status); }
/* * Check a server for being alive and well. * returns 0 if the server is in shape. Returns 1 on error * * Also useable outside libsmbclient to enable external cache * to do some checks too. */ int SMBC_check_server(SMBCCTX * context, SMBCSRV * server) { if (!cli_state_is_connected(server->cli)) { return 1; } return 0; }
NTSTATUS cli_nt_error(struct cli_state *cli) { /* Deal with socket errors first. */ if (!cli_state_is_connected(cli)) { return NT_STATUS_CONNECTION_DISCONNECTED; } if (NT_STATUS_IS_DOS(cli->raw_status)) { int e_class = NT_STATUS_DOS_CLASS(cli->raw_status); int code = NT_STATUS_DOS_CODE(cli->raw_status); return dos_to_ntstatus(e_class, code); } return cli->raw_status; }
bool cli_is_error(struct cli_state *cli) { /* A socket error is always an error. */ if (!cli_state_is_connected(cli)) { return true; } if (NT_STATUS_IS_DOS(cli->raw_status)) { /* Return error if error class in non-zero */ uint8_t rcls = NT_STATUS_DOS_CLASS(cli->raw_status); return rcls != 0; } return NT_STATUS_IS_ERR(cli->raw_status); }
void cli_dos_error(struct cli_state *cli, uint8 *eclass, uint32 *ecode) { if (!cli_state_is_connected(cli)) { *eclass = ERRDOS; *ecode = ERRnotconnected; return; } if (!NT_STATUS_IS_DOS(cli->raw_status)) { ntstatus_to_dos(cli->raw_status, eclass, ecode); return; } *eclass = NT_STATUS_DOS_CLASS(cli->raw_status); *ecode = NT_STATUS_DOS_CODE(cli->raw_status); }