summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMatt Johnston <matt@ucc.asn.au>2017-05-10 00:20:21 +0800
committerMatt Johnston <matt@ucc.asn.au>2017-05-10 00:20:21 +0800
commit93f3c31807cc15c19640d7242883b24b374a7fde (patch)
tree079f6af4f7ae7169c1d8c0e9eeb63acde8bd2a6c
parent1df5c97144ba60eb7ae9de8b5b0ea0354a213181 (diff)
switch user when opening authorized_keys
-rw-r--r--svr-authpubkey.c17
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;
}