SW 개발

[dbclient] "failed reading line: prob EOF" 에러발생 및 해결

. . . 2017. 11. 20. 18:07
반응형
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 파일을 찾게된다.

즉.. 에러는 해당 폴더에 해당 파일이 없어서 나는 에러였다.

문제해결

HOME 환경변수에 맞는 .ssh/known_hosts 파일을 넣어주면 된다.




반응형