Module Name: src Committed By: christos Date: Fri Oct 4 18:04:06 UTC 2024
Modified Files: src/usr.bin/ftp: ruserpass.c Log Message: extract duplicate code into a function. To generate a diff of this commit: cvs rdiff -u -r1.34 -r1.35 src/usr.bin/ftp/ruserpass.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/ftp/ruserpass.c diff -u src/usr.bin/ftp/ruserpass.c:1.34 src/usr.bin/ftp/ruserpass.c:1.35 --- src/usr.bin/ftp/ruserpass.c:1.34 Thu Jul 18 23:53:13 2024 +++ src/usr.bin/ftp/ruserpass.c Fri Oct 4 14:04:06 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: ruserpass.c,v 1.34 2024/07/19 03:53:13 lukem Exp $ */ +/* $NetBSD: ruserpass.c,v 1.35 2024/10/04 18:04:06 christos Exp $ */ /* * Copyright (c) 1985, 1993, 1994 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)ruserpass.c 8.4 (Berkeley) 4/27/95"; #else -__RCSID("$NetBSD: ruserpass.c,v 1.34 2024/07/19 03:53:13 lukem Exp $"); +__RCSID("$NetBSD: ruserpass.c,v 1.35 2024/10/04 18:04:06 christos Exp $"); #endif #endif /* not lint */ @@ -79,6 +79,20 @@ static struct toktab { { NULL, 0 } }; +static int +match_host_domain(const char *host, const char *domain, const char *tokv) +{ + const char *tmp; + + if (strcasecmp(host, tokval) == 0) + return 1; + + return (tmp = strchr(host, '.')) != NULL && + strcasecmp(tmp, domain) == 0 && + strncasecmp(host, tokv, tmp - host) == 0 && + tokv[tmp - host] == '\0'; +} + int ruserpass(const char *host, char **aname, char **apass, char **aacct) { @@ -119,19 +133,9 @@ ruserpass(const char *host, char **aname * or official hostname. Also allow match of * incompletely-specified host in local domain. */ - if (strcasecmp(host, tokval) == 0) - goto match; - if (strcasecmp(hostname, tokval) == 0) - goto match; - if ((tmp = strchr(hostname, '.')) != NULL && - strcasecmp(tmp, mydomain) == 0 && - strncasecmp(hostname, tokval, tmp-hostname) == 0 && - tokval[tmp - hostname] == '\0') + if (match_host_domain(hostname, mydomain, tokval)) goto match; - if ((tmp = strchr(host, '.')) != NULL && - strcasecmp(tmp, mydomain) == 0 && - strncasecmp(host, tokval, tmp - host) == 0 && - tokval[tmp - host] == '\0') + if (match_host_domain(host, mydomain, tokval)) goto match; continue; }