mirror of https://github.com/wolfSSL/wolfssh.git
remove duplicate code and raise permissions for chroot
parent
e1f0a67c38
commit
8a286ad727
|
@ -255,12 +255,6 @@ static WOLFSSHD_CONFIG* wolfSSHD_ConfigCopy(WOLFSSHD_CONFIG* conf)
|
|||
newConf->heap);
|
||||
}
|
||||
|
||||
if (ret == WS_SUCCESS && conf->chrootDir) {
|
||||
ret = CreateString(&newConf->chrootDir, conf->chrootDir,
|
||||
(int)WSTRLEN(conf->chrootDir),
|
||||
newConf->heap);
|
||||
}
|
||||
|
||||
if (ret == WS_SUCCESS) {
|
||||
newConf->loginTimer = conf->loginTimer;
|
||||
newConf->port = conf->port;
|
||||
|
@ -286,8 +280,14 @@ void wolfSSHD_ConfigFree(WOLFSSHD_CONFIG* conf)
|
|||
WOLFSSHD_CONFIG* next = current->next;
|
||||
heap = current->heap;
|
||||
|
||||
FreeString(¤t->authKeysFile, heap);
|
||||
FreeString(¤t->hostKeyFile, heap);
|
||||
FreeString(¤t->banner, heap);
|
||||
FreeString(¤t->chrootDir, heap);
|
||||
FreeString(¤t->ciphers, heap);
|
||||
FreeString(¤t->kekAlgos, heap);
|
||||
FreeString(¤t->hostKeyAlgos, heap);
|
||||
FreeString(¤t->listenAddress, heap);
|
||||
FreeString(¤t->authKeysFile, heap);
|
||||
FreeString(¤t->hostKeyFile, heap);
|
||||
|
||||
WFREE(current, heap, DYNTYPE_SSHD);
|
||||
current = next;
|
||||
|
@ -321,7 +321,7 @@ enum {
|
|||
OPT_INCLUDE = 16,
|
||||
OPT_CHROOT_DIR = 17,
|
||||
OPT_MATCH = 18,
|
||||
OPT_FORCE_CMD = 19,
|
||||
OPT_FORCE_CMD = 19,
|
||||
};
|
||||
enum {
|
||||
NUM_OPTIONS = 20
|
||||
|
|
|
@ -679,11 +679,22 @@ static void* HandleConnection(void* arg)
|
|||
/* check for chroot set */
|
||||
cmd = wolfSSHD_ConfigGetChroot(usrConf);
|
||||
if (cmd != NULL) {
|
||||
if (chroot(cmd) != 0) {
|
||||
wolfSSH_Log(WS_LOG_ERROR,
|
||||
"[SSHD] chroot failed to path %s", cmd);
|
||||
if (wolfSSHD_AuthRaisePermissions(conn->auth) != WS_SUCCESS) {
|
||||
wolfSSH_Log(WS_LOG_ERROR, "[SSHD] Failure to raise permissions "
|
||||
"for auth");
|
||||
ret = WS_FATAL_ERROR;
|
||||
}
|
||||
else {
|
||||
if (chroot(cmd) != 0) {
|
||||
wolfSSH_Log(WS_LOG_ERROR,
|
||||
"[SSHD] chroot failed to path %s", cmd);
|
||||
ret = WS_FATAL_ERROR;
|
||||
}
|
||||
|
||||
if (wolfSSHD_AuthReducePermissions(conn->auth) != WS_SUCCESS) {
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef WOLFSSH_SFTP
|
||||
if (ret == WS_SFTP_COMPLETE) {
|
||||
|
|
Loading…
Reference in New Issue