반응형
dbclient 디버깅한 내용을 정리한다.
문제발생
Dbclient 를 디버깅빌드를 한후 돌려보니, 다음과 같은 에러가 발생하였다.
TRACE (89): enter buf_getline
TRACE (89): leave buf_getline: failure
TRACE (89): failed reading line: prob EOF
디버깅
소스코드를 살펴본결과.. open_known_hosts_file() 에서 제대로 된 파일을 읽어오지 못해서였다.
해당 소스코드를 보면…
static FILE* open_known_hosts_file(int * readonly)
{
FILE * hostsfile = NULL;
char * filename = NULL;
char * homedir = NULL;
homedir = getenv("HOME");
if (!homedir) {
struct passwd * pw = NULL;
pw = getpwuid(getuid());
if (pw) {
homedir = pw->pw_dir;
}
}
if (homedir) { // 중요!!!!!!
unsigned int len;
len = strlen(homedir);
filename = m_malloc(len + 18); /* "/.ssh/known_hosts" and null-terminator*/
snprintf(filename, len+18, "%s/.ssh", homedir);
/* Check that ~/.ssh exists - easiest way is just to mkdir */
if (mkdir(filename, S_IRWXU) != 0) {
if (errno != EEXIST) {
dropbear_log(LOG_INFO, "Warning: failed creating %s/.ssh: %s",
homedir, strerror(errno));
TRACE(("mkdir didn't work: %s", strerror(errno)))
goto out;
}
}
snprintf(filename, len+18, "%s/.ssh/known_hosts", homedir); // 중요!!!!!
hostsfile = fopen(filename, "a+");
if (hostsfile != NULL) {
*readonly = 0;
fseek(hostsfile, 0, SEEK_SET);
} else {
/* We mightn't have been able to open it if it was read-only */
if (errno == EACCES || errno == EROFS) {
TRACE(("trying readonly: %s", strerror(errno)))
*readonly = 1;
hostsfile = fopen(filename, "r");
}
}
//… 생략 …
즉.. 에러는 해당 폴더에 해당 파일이 없어서 나는 에러였다.
문제해결
HOME 환경변수에 맞는 .ssh/known_hosts 파일을 넣어주면 된다.
반응형