🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #48457

Re: Got it! ckpasswd -f bug (INN 2.3.0)

#48457
From: Giovanni Lopedote
Date: Tue, 19 Sep 2000 23:43
103 lines
4391 bytes
(my real email address is at the end of the message)

"bill davidsen" <davidsen@tmr.com> ha scritto nel messaggio
news:8q83h1$gn2$1@newssvr02.news.prodigy.com...

>   The original code rejected data which did not contain the ':'
> character. I'm not sure that a sanity check on expected format counts as
> a "bug."

Maybe you can think different if you take a look at the whole code. Yes,
that one is a sanity check, but in the wrong place, I think. The one on
expected format is done before, at line 63. This was the whole function:

char *GetFilePass(char *name, char *file)
{
    FILE *pwfile;
    char buf[SMBUF];
    char *colon, *iter;
    int found;
    static char pass[SMBUF];

    pwfile = fopen(file, "r");
    if (!pwfile)
        return(0);
    found = 0;
    while ((!found) && fgets(buf, sizeof(buf), pwfile)) {
        buf[strlen(buf)-1] = 0; /* clean off the \n */
63->    if (!(colon = strchr(buf, ':'))) {
            fclose(pwfile);
            return(0);
        }
        *colon = 0;
        if (!strcmp(buf, name))
         found = 1;
    }
70->fclose(pwfile);
    if (!found)
        return(0);
    iter = colon+1;
75->if (!(colon = strchr(iter, ':')))
->   return(0);
->  *colon = 0;
->  strcpy(pass, iter);
    return(pass);
}

and this is the piece of code in main() that calls it:

183-> rpass = GetFilePass(uname, fname);
[...]
    if (!rpass) {
        fprintf(stderr, "ckpasswd: user %s does not exist.\n", uname);
        exit(1);
    }
    if (strcmp(rpass, crypt(pass, rpass)) == 0) {
        printf("User:%s\n", uname);
        exit(0);
    }
    fprintf(stderr, "ckpasswd: user %s password doesn't match.\n", uname);
    exit(1);
}

let's suppose we have a well-formed line in the passwords file:

foo:EncryptedPassword

and that we are checking the password of "foo". The GetFilePass function
consists of two parts: the first one (which ends at line 70) parses all the
lines of the file looking for one starting with "foo:". Then, at line 75,
iter points to what's after the colon (the 'E' in our example). At line 75,
strchr returns a null pointer as there are no other colons; this turns into
a true condition for the "if" at line 75 and then GetFilePass() exits
returning a null pointer instead of a pointer to the password. So, no matter
if the password was right or wrong, ckpasswd -f exits with "user foo does
not exist".

In my correction:

75->if (colon = strchr(iter, ':'))
->   *colon = 0;
->  strcpy(pass, iter);

the condition for the if is false and then GetFilePass returns a pointer to
the string "EncryptedPassword", as it should be; this string is then
compared (through crypt()) with the user supplied password and if it matches
the authentication is confirmed. What happen if the "if" condition at line
75 becomes true? Let's suppose now that the line was, instead:

foo:EncryptedPassword:crap

*colon=0 truncates iter to "EncryptedPassword" and then the authentication
can still be made in the right way.
If you don't want this to happen, making ckpasswd more restrictive on the
file format, you simply have to delete lines 75-77.

As I told, I was not able to get it working until I've made this correction.

Giovanni Lopedote
Bari, Italy
neuromante@gmx.net


Technical Details
Message-ID: <39c7f695@wsnews.worldshare.net>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!supernews.google.com!sn-xit-02!sn-xit-03!supernews.com!xfer13.netnews.com!netnews.com!newsin.iconnet.net!news.idt.net!attmtf.ip.att.net!attcg2!ip.att.net!wsnews.worldshare.net!212.141.254.254
References: <8q7kje$gds$1@nread1.inwind.it> <8q83h1$gn2$1@newssvr02.news.prodigy.com>

Show Full Headers
Complete Article Headers
Message-ID: <39c7f695@wsnews.worldshare.net>
Subject: Re: Got it! ckpasswd -f bug (INN 2.3.0)
Date: Wed, 20 Sep 2000 01:43:24 +0200
From: "Giovanni Lopedote" <nospamplease@gmx.net>
References: <8q7kje$gds$1@nread1.inwind.it> <8q83h1$gn2$1@newssvr02.news.prodigy.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!supernews.google.com!sn-xit-02!sn-xit-03!supernews.com!xfer13.netnews.com!netnews.com!newsin.iconnet.net!news.idt.net!attmtf.ip.att.net!attcg2!ip.att.net!wsnews.worldshare.net!212.141.254.254
Newsgroups: news.software.nntp
Lines: 102
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2919.6700
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700
NNTP-Posting-Host: 212.141.254.254
X-Original-NNTP-Posting-Host: 212.141.254.254
X-Trace: 19 Sep 2000 19:28:21 -0400, 212.141.254.254
X-Original-Trace: 19 Sep 2000 19:28:21 -0400, 212.141.254.254