# HG changeset patch # User Matt Johnston # Date 1647398604 -28800 # Node ID 75d6a9faf9199bac612d1be3df58299484a5eb84 # Parent 81991ded740f2ea3ccb9bf83bd9971c759b17124# Parent f54451afc046259a519fe12e40d3b6a1fbe9fa99 Merge pull request #151 from HansH111/pubkeyinfo diff -r 81991ded740f -r 75d6a9faf919 auth.h --- a/auth.h Tue Mar 15 15:38:46 2022 +0800 +++ b/auth.h Wed Mar 16 10:43:24 2022 +0800 @@ -125,6 +125,7 @@ char *pw_passwd; #if DROPBEAR_SVR_PUBKEY_OPTIONS_BUILT struct PubKeyOptions* pubkey_options; + char *pubkey_info; #endif }; diff -r 81991ded740f -r 75d6a9faf919 svr-authpubkey.c --- a/svr-authpubkey.c Tue Mar 15 15:38:46 2022 +0800 +++ b/svr-authpubkey.c Wed Mar 16 10:43:24 2022 +0800 @@ -261,7 +261,7 @@ const char* algo, unsigned int algolen, const unsigned char* keyblob, unsigned int keybloblen) { buffer *options_buf = NULL; - unsigned int pos, len; + unsigned int pos, len, infopos, infolen; int ret = DROPBEAR_FAILURE; if (line->len < MIN_AUTHKEYS_LINE || line->len > MAX_AUTHKEYS_LINE) { @@ -344,6 +344,11 @@ for (len = 0; line->pos < line->len; len++) { if (buf_getbyte(line) == ' ') break; } + /* findout the length of the public key info */ + infopos = line->pos; + for (infolen = 0; line->pos < line->len; infolen++) { + if (buf_getbyte(line) == ' ') break; + } buf_setpos(line, pos); buf_setlen(line, line->pos + len); @@ -351,8 +356,23 @@ ret = cmp_base64_key(keyblob, keybloblen, (const unsigned char *) algo, algolen, line, NULL); - if (ret == DROPBEAR_SUCCESS && options_buf) { - ret = svr_add_pubkey_options(options_buf, line_num, filename); + /* free pubkey_info if it is filled */ + if (ses.authstate.pubkey_info) { + m_free(ses.authstate.pubkey_info); + ses.authstate.pubkey_info = NULL; + } + if (ret == DROPBEAR_SUCCESS) { + if (options_buf) { + ret = svr_add_pubkey_options(options_buf, line_num, filename); + } + /* save the (optional) public key information */ + if (infolen) { + ses.authstate.pubkey_info = m_malloc(infolen + 1); + if (ses.authstate.pubkey_info) { + strncpy(ses.authstate.pubkey_info,(const char *) buf_getptr(line, infopos), infolen); + ses.authstate.pubkey_info[infolen]='\0'; + } + } } out: diff -r 81991ded740f -r 75d6a9faf919 svr-authpubkeyoptions.c --- a/svr-authpubkeyoptions.c Tue Mar 15 15:38:46 2022 +0800 +++ b/svr-authpubkeyoptions.c Wed Mar 16 10:43:24 2022 +0800 @@ -115,6 +115,9 @@ } m_free(ses.authstate.pubkey_options); } + if (ses.authstate.pubkey_info) { + m_free(ses.authstate.pubkey_info); + } } /* helper for svr_add_pubkey_options. returns DROPBEAR_SUCCESS if the option is matched, diff -r 81991ded740f -r 75d6a9faf919 svr-chansession.c --- a/svr-chansession.c Tue Mar 15 15:38:46 2022 +0800 +++ b/svr-chansession.c Wed Mar 16 10:43:24 2022 +0800 @@ -1030,6 +1030,9 @@ if (chansess->original_command) { addnewvar("SSH_ORIGINAL_COMMAND", chansess->original_command); } + if (ses.authstate.pubkey_info != NULL) { + addnewvar("SSH_PUBKEYINFO", ses.authstate.pubkey_info); + } /* change directory */ if (chdir(ses.authstate.pw_dir) < 0) {