mirror of
https://github.com/clearml/dropbear
synced 2025-02-07 05:17:28 +00:00
Merge pull request #151 from HansH111/pubkeyinfo
This commit is contained in:
commit
355b248318
1
auth.h
1
auth.h
@ -125,6 +125,7 @@ struct AuthState {
|
|||||||
char *pw_passwd;
|
char *pw_passwd;
|
||||||
#if DROPBEAR_SVR_PUBKEY_OPTIONS_BUILT
|
#if DROPBEAR_SVR_PUBKEY_OPTIONS_BUILT
|
||||||
struct PubKeyOptions* pubkey_options;
|
struct PubKeyOptions* pubkey_options;
|
||||||
|
char *pubkey_info;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -261,7 +261,7 @@ static int checkpubkey_line(buffer* line, int line_num, const char* filename,
|
|||||||
const char* algo, unsigned int algolen,
|
const char* algo, unsigned int algolen,
|
||||||
const unsigned char* keyblob, unsigned int keybloblen) {
|
const unsigned char* keyblob, unsigned int keybloblen) {
|
||||||
buffer *options_buf = NULL;
|
buffer *options_buf = NULL;
|
||||||
unsigned int pos, len;
|
unsigned int pos, len, infopos, infolen;
|
||||||
int ret = DROPBEAR_FAILURE;
|
int ret = DROPBEAR_FAILURE;
|
||||||
|
|
||||||
if (line->len < MIN_AUTHKEYS_LINE || line->len > MAX_AUTHKEYS_LINE) {
|
if (line->len < MIN_AUTHKEYS_LINE || line->len > MAX_AUTHKEYS_LINE) {
|
||||||
@ -344,6 +344,11 @@ static int checkpubkey_line(buffer* line, int line_num, const char* filename,
|
|||||||
for (len = 0; line->pos < line->len; len++) {
|
for (len = 0; line->pos < line->len; len++) {
|
||||||
if (buf_getbyte(line) == ' ') break;
|
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_setpos(line, pos);
|
||||||
buf_setlen(line, line->pos + len);
|
buf_setlen(line, line->pos + len);
|
||||||
|
|
||||||
@ -351,8 +356,23 @@ static int checkpubkey_line(buffer* line, int line_num, const char* filename,
|
|||||||
|
|
||||||
ret = cmp_base64_key(keyblob, keybloblen, (const unsigned char *) algo, algolen, line, NULL);
|
ret = cmp_base64_key(keyblob, keybloblen, (const unsigned char *) algo, algolen, line, NULL);
|
||||||
|
|
||||||
if (ret == DROPBEAR_SUCCESS && options_buf) {
|
/* free pubkey_info if it is filled */
|
||||||
ret = svr_add_pubkey_options(options_buf, line_num, filename);
|
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:
|
out:
|
||||||
|
@ -115,6 +115,9 @@ void svr_pubkey_options_cleanup() {
|
|||||||
}
|
}
|
||||||
m_free(ses.authstate.pubkey_options);
|
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,
|
/* helper for svr_add_pubkey_options. returns DROPBEAR_SUCCESS if the option is matched,
|
||||||
|
@ -1030,6 +1030,9 @@ static void execchild(const void *user_data) {
|
|||||||
if (chansess->original_command) {
|
if (chansess->original_command) {
|
||||||
addnewvar("SSH_ORIGINAL_COMMAND", 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 */
|
/* change directory */
|
||||||
if (chdir(ses.authstate.pw_dir) < 0) {
|
if (chdir(ses.authstate.pw_dir) < 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user