diff --git a/src/internal.c b/src/internal.c index aad54d68..c0760497 100644 --- a/src/internal.c +++ b/src/internal.c @@ -2194,6 +2194,42 @@ static int DoUserAuthRequestPublicKey(WOLFSSH* ssh, WS_UserAuthData* authData, } +static int DoGlobalRequest(WOLFSSH* ssh, + uint8_t* buf, uint32_t len, uint32_t* idx) +{ + uint32_t begin; + int ret = WS_SUCCESS; + char name[80]; + uint32_t nameSz = sizeof(name); + uint8_t wantReply = 0; + + WLOG(WS_LOG_DEBUG, "Entering DoGlobalRequest()"); + + if (ssh == NULL || buf == NULL || len == 0 || idx == NULL) + ret = WS_BAD_ARGUMENT; + + if (ret == WS_SUCCESS) { + begin = *idx; + ret = GetString(name, &nameSz, buf, len, &begin); + } + + if (ret == WS_SUCCESS) { + WLOG(WS_LOG_DEBUG, "DGR: request name = %s", name); + ret = GetBoolean(&wantReply, buf, len, &begin); + } + + if (ret == WS_SUCCESS) { + *idx += len; + + if (wantReply) + ret = SendRequestSuccess(ssh, 0); + } + + WLOG(WS_LOG_DEBUG, "Leaving DoGlobalRequest(), ret = %d", ret); + return ret; +} + + static int DoUserAuthRequest(WOLFSSH* ssh, uint8_t* buf, uint32_t len, uint32_t* idx) { @@ -2204,11 +2240,9 @@ static int DoUserAuthRequest(WOLFSSH* ssh, WLOG(WS_LOG_DEBUG, "Entering DoUserAuthRequest()"); - if (ssh == NULL || buf == NULL || len == 0 || idx == NULL) ret = WS_BAD_ARGUMENT; - if (ret == WS_SUCCESS) { begin = *idx; WMEMSET(&authData, 0, sizeof(authData)); @@ -2635,6 +2669,11 @@ static int DoPacket(WOLFSSH* ssh) ret = DoUserAuthRequest(ssh, buf + idx, payloadSz, &payloadIdx); break; + case MSGID_GLOBAL_REQUEST: + WLOG(WS_LOG_DEBUG, "Decoding MSGID_GLOBAL_REQUEST"); + ret = DoGlobalRequest(ssh, buf + idx, payloadSz, &payloadIdx); + break; + case MSGID_CHANNEL_OPEN: WLOG(WS_LOG_DEBUG, "Decoding MSGID_CHANNEL_OPEN"); ret = DoChannelOpen(ssh, buf + idx, payloadSz, &payloadIdx); @@ -4010,6 +4049,41 @@ int SendUserAuthBanner(WOLFSSH* ssh) } +int SendRequestSuccess(WOLFSSH* ssh, int success) +{ + uint8_t* output; + uint32_t idx; + int ret = WS_SUCCESS; + + WLOG(WS_LOG_DEBUG, "Entering SendRequestSuccess(), %s", + success ? "Success" : "Failure"); + + if (ssh == NULL) + ret = WS_BAD_ARGUMENT; + + if (ret == WS_SUCCESS) + ret = PreparePacket(ssh, MSG_ID_SZ); + + if (ret == WS_SUCCESS) { + output = ssh->outputBuffer.buffer; + idx = ssh->outputBuffer.length; + + output[idx++] = success ? + MSGID_REQUEST_SUCCESS : MSGID_REQUEST_FAILURE; + + ssh->outputBuffer.length = idx; + + ret = BundlePacket(ssh); + } + + if (ret == WS_SUCCESS) + ret = SendBuffered(ssh); + + WLOG(WS_LOG_DEBUG, "Leaving SendRequestSuccess(), ret = %d", ret); + return ret; +} + + int SendChannelOpenConf(WOLFSSH* ssh) { uint8_t* output; diff --git a/wolfssh/internal.h b/wolfssh/internal.h index 0655c35e..58e5b6ed 100644 --- a/wolfssh/internal.h +++ b/wolfssh/internal.h @@ -313,6 +313,7 @@ WOLFSSH_LOCAL int SendUserAuthFailure(WOLFSSH*, uint8_t); WOLFSSH_LOCAL int SendUserAuthBanner(WOLFSSH*); WOLFSSH_LOCAL int SendUserAuthPkOk(WOLFSSH*, const uint8_t*, uint32_t, const uint8_t*, uint32_t); +WOLFSSH_LOCAL int SendRequestSuccess(WOLFSSH*, int); WOLFSSH_LOCAL int SendChannelOpenConf(WOLFSSH*); WOLFSSH_LOCAL int SendChannelEof(WOLFSSH*, uint32_t); WOLFSSH_LOCAL int SendChannelClose(WOLFSSH*, uint32_t); @@ -396,6 +397,10 @@ enum WS_MessageIds { MSGID_USERAUTH_PK_OK = 60, /* Public Key OK */ MSGID_USERAUTH_PW_CHRQ = 60, /* Password Change Request */ + MSGID_GLOBAL_REQUEST = 80, + MSGID_REQUEST_SUCCESS = 81, + MSGID_REQUEST_FAILURE = 82, + MSGID_CHANNEL_OPEN = 90, MSGID_CHANNEL_OPEN_CONF = 91, MSGID_CHANNEL_WINDOW_ADJUST = 93,