mirror of
https://github.com/clearml/dropbear
synced 2025-03-13 07:08:26 +00:00
Check authorized_keys permissions as the user
This is necessary on NFS with squash root. Based on work from Chris Dragan This commit also tidies some trailing whitespace. Fixes github pull #107
This commit is contained in:
parent
6f793d42d0
commit
2f68f6693f
@ -213,7 +213,6 @@ void svr_auth_pubkey(int valid_user) {
|
||||
svr_ses.plugin_instance->auth_success(ses.plugin_session);
|
||||
}
|
||||
#endif
|
||||
|
||||
} else {
|
||||
dropbear_log(LOG_WARNING,
|
||||
"Pubkey auth bad signature for '%s' with key %s from %s",
|
||||
@ -427,23 +426,8 @@ static int checkpubkey(const char* keyalgo, unsigned int keyalgolen,
|
||||
|
||||
TRACE(("enter checkpubkey"))
|
||||
|
||||
/* check file permissions, also whether file exists */
|
||||
if (checkpubkeyperms() == DROPBEAR_FAILURE) {
|
||||
TRACE(("bad authorized_keys permissions, or file doesn't exist"))
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* we don't need to check pw and pw_dir for validity, since
|
||||
* its been done in checkpubkeyperms. */
|
||||
len = strlen(ses.authstate.pw_dir);
|
||||
/* allocate max required pathname storage,
|
||||
* = path + "/.ssh/authorized_keys" + '\0' = pathlen + 22 */
|
||||
filename = m_malloc(len + 22);
|
||||
snprintf(filename, len + 22, "%s/.ssh/authorized_keys",
|
||||
ses.authstate.pw_dir);
|
||||
|
||||
#if DROPBEAR_SVR_MULTIUSER
|
||||
/* open the file as the authenticating user. */
|
||||
/* access the file as the authenticating user. */
|
||||
origuid = getuid();
|
||||
origgid = getgid();
|
||||
if ((setegid(ses.authstate.pw_gid)) < 0 ||
|
||||
@ -451,9 +435,24 @@ static int checkpubkey(const char* keyalgo, unsigned int keyalgolen,
|
||||
dropbear_exit("Failed to set euid");
|
||||
}
|
||||
#endif
|
||||
/* check file permissions, also whether file exists */
|
||||
if (checkpubkeyperms() == DROPBEAR_FAILURE) {
|
||||
TRACE(("bad authorized_keys permissions, or file doesn't exist"))
|
||||
} else {
|
||||
/* we don't need to check pw and pw_dir for validity, since
|
||||
* its been done in checkpubkeyperms. */
|
||||
len = strlen(ses.authstate.pw_dir);
|
||||
/* allocate max required pathname storage,
|
||||
* = path + "/.ssh/authorized_keys" + '\0' = pathlen + 22 */
|
||||
filename = m_malloc(len + 22);
|
||||
snprintf(filename, len + 22, "%s/.ssh/authorized_keys",
|
||||
ses.authstate.pw_dir);
|
||||
|
||||
authfile = fopen(filename, "r");
|
||||
|
||||
authfile = fopen(filename, "r");
|
||||
if (!authfile) {
|
||||
TRACE(("checkpubkey: failed opening %s: %s", filename, strerror(errno)))
|
||||
}
|
||||
}
|
||||
#if DROPBEAR_SVR_MULTIUSER
|
||||
if ((seteuid(origuid)) < 0 ||
|
||||
(setegid(origgid)) < 0) {
|
||||
@ -485,7 +484,6 @@ static int checkpubkey(const char* keyalgo, unsigned int keyalgolen,
|
||||
}
|
||||
|
||||
/* We continue to the next line otherwise */
|
||||
|
||||
} while (1);
|
||||
|
||||
out:
|
||||
|
Loading…
Reference in New Issue
Block a user