diff options
author | Matt Johnston <matt@ucc.asn.au> | 2017-05-10 00:20:21 +0800 |
---|---|---|
committer | Matt Johnston <matt@ucc.asn.au> | 2017-05-10 00:20:21 +0800 |
commit | bd3c551ce33c41fc623b38ed7bb5e3586ac3f4c5 (patch) | |
tree | 1b1f26b5b97b98a1be2e42c33dcc6441d2182488 | |
parent | 97d87da24ccad7e78533324ec0cb8436ba4955b6 (diff) | |
download | dropbear-bd3c551ce33c41fc623b38ed7bb5e3586ac3f4c5.tar.gz |
switch user when opening authorized_keys
-rw-r--r-- | svr-authpubkey.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/svr-authpubkey.c b/svr-authpubkey.c index 71c347a..c3bac82 100644 --- a/svr-authpubkey.c +++ b/svr-authpubkey.c @@ -201,6 +201,8 @@ static int checkpubkey(char* algo, unsigned int algolen, unsigned int len, pos; buffer * options_buf = NULL; int line_num; + uid_t origuid; + gid_t origgid; TRACE(("enter checkpubkey")) @@ -227,8 +229,21 @@ static int checkpubkey(char* algo, unsigned int algolen, snprintf(filename, len + 22, "%s/.ssh/authorized_keys", ses.authstate.pw_dir); - /* open the file */ + /* open the file as the authenticating user. */ + origuid = getuid(); + origgid = getgid(); + if ((setegid(ses.authstate.pw_gid)) < 0 || + (seteuid(ses.authstate.pw_uid)) < 0) { + dropbear_exit("Failed to set euid"); + } + authfile = fopen(filename, "r"); + + if ((seteuid(origuid)) < 0 || + (setegid(origgid)) < 0) { + dropbear_exit("Failed to revert euid"); + } + if (authfile == NULL) { goto out; } |