From nobody Thu Sep 28 15:52:39 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4RxJ076j4rz4tyKH; Thu, 28 Sep 2023 15:52:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4RxJ074gDVz4LGy; Thu, 28 Sep 2023 15:52:39 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1695916359; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=iaBoYLpHqpHO0NkD0yQtZcWOYS08mWfuTBtJOJO8ErE=; b=atXCdqiKTfhWOrP9LFVzczpVJyQY7SajI2stLBHME6JKdJtrGECE+2yFTiZveVzZAqHYhj Up/ighIrAE9VR744K7zRLp8Te/c01n50B8Vvb0C2cFcbMdrRZeC1up0zIfDO8obCz+ZLNX Tx/gLhISPd7Zsbr06X6A3Ik7tdoWzSOMKvnoel2+SG6heH6sOeD+i6PojVriPPhyCLZwpb PZgYxdHz9yTQwbtLvG8NSos8qPnVuGPg1eRmoAjtIxFb9Uvza/EM5mlEUaX+HcVoYTMAA8 maAUosqJmB5IT5B+GBbxWPhQrViVF/GJKx7jSwcuCjT/QWysudkx+khvUWn69Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1695916359; a=rsa-sha256; cv=none; b=aQlaZYV12ZgrLg2K8qdJQCql54sloJRWl2utFduMDMiyGrDq8Q33XuK8jqIjUF28Pj7Mes 26jRiE89YYU3ZthmYMLunCq9TFFtA0Nnsy6FPSmX9mbRr7nDedQdsmZAdBcQzIMqcLnz82 WTh0KhK1MKo59TBbyBs9QF7533v3bS3woCpF+MS7J1cRL4yfQ2gEoSYNe22dk1hyYufX+7 5RVcR7Px51Ax33H843IwUKS6A4mFoKf6a3Q4+LDmTPmid8g1Ed96ahXKnYj8jwR92N6XU3 xB2PgRPmxhBPp2eQ8hMGZSQYfgL8H68WwOPa74h7pS0Lgx6c8lmcXsm2baZpGg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1695916359; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=iaBoYLpHqpHO0NkD0yQtZcWOYS08mWfuTBtJOJO8ErE=; b=Cr8J6KFeCsFx5yGt0/ZnWS1JfIPy+RY6tUMejMDr7jPCubq+J1HwCUmvyoWRxLKYyuqiZZ G8OT3TlYYrUw0/TdPKg9xYtGV1/5sz46Mgyz4GzoSOmwVfLPLx6sDd3pSTmLkmJ9TYTpNP 77+KIK3Ynuis9cYXJPz9jd8zmhONoUgZPRoQzmPKAWZQv+lfgVCo9I+mAoN/A9Z8cTEzCZ 1gJLLraiHW2dIDIuzD44vOXruNXD1xKhZUAEoVB9MMhfw8jsQMVsD0i2cYtoeRKJKQHAU9 wDRV15qKZeVUJd+fepMLQ0fO4wKlk2Xzm7iiSt1loTPHadqIdIWmBiKxFJUvsA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4RxJ073fqSzD69; Thu, 28 Sep 2023 15:52:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 38SFqdLR022219; Thu, 28 Sep 2023 15:52:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 38SFqdOL022216; Thu, 28 Sep 2023 15:52:39 GMT (envelope-from git) Date: Thu, 28 Sep 2023 15:52:39 GMT Message-Id: <202309281552.38SFqdOL022216@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: f4b4a10abb26 - main - syslogd: Move selector parsing into its own function List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f4b4a10abb2688f0fef9a0cf15117b10a7f2d398 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=f4b4a10abb2688f0fef9a0cf15117b10a7f2d398 commit f4b4a10abb2688f0fef9a0cf15117b10a7f2d398 Author: Jake Freeland AuthorDate: 2023-09-01 02:50:45 +0000 Commit: Mark Johnston CommitDate: 2023-09-28 15:51:53 +0000 syslogd: Move selector parsing into its own function Clean up the cfline() function by moving selector parsing into its own function. Reviewed by: markj MFC after: 3 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D41374 --- usr.sbin/syslogd/syslogd.c | 210 ++++++++++++++++++++++----------------------- 1 file changed, 104 insertions(+), 106 deletions(-) diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c index 40c233f02d7f..6c07d60b484f 100644 --- a/usr.sbin/syslogd/syslogd.c +++ b/usr.sbin/syslogd/syslogd.c @@ -2865,6 +2865,107 @@ error: return (NULL); } +static const char * +parse_selector(const char *p, struct filed *f) +{ + int i, pri; + int pri_done = 0, pri_cmp = 0, pri_invert = 0; + char *bp, buf[LINE_MAX], ebuf[100]; + const char *q; + + /* find the end of this facility name list */ + for (q = p; *q && *q != '\t' && *q != ' ' && *q++ != '.';) + continue; + + /* get the priority comparison */ + if (*q == '!') { + pri_invert = 1; + q++; + } + while (!pri_done) { + switch (*q) { + case '<': + pri_cmp |= PRI_LT; + q++; + break; + case '=': + pri_cmp |= PRI_EQ; + q++; + break; + case '>': + pri_cmp |= PRI_GT; + q++; + break; + default: + pri_done++; + break; + } + } + + /* collect priority name */ + for (bp = buf; *q != '\0' && !strchr("\t,; ", *q); ) + *bp++ = *q++; + *bp = '\0'; + + /* skip cruft */ + while (strchr(",;", *q)) + q++; + + /* decode priority name */ + if (*buf == '*') { + pri = LOG_PRIMASK; + pri_cmp = PRI_LT | PRI_EQ | PRI_GT; + } else { + /* Ignore trailing spaces. */ + for (i = strlen(buf) - 1; i >= 0 && buf[i] == ' '; i--) + buf[i] = '\0'; + + pri = decode(buf, prioritynames); + if (pri < 0) { + errno = 0; + (void)snprintf(ebuf, sizeof ebuf, + "unknown priority name \"%s\"", buf); + logerror(ebuf); + free(f); + return (NULL); + } + } + if (!pri_cmp) + pri_cmp = UniquePriority ? PRI_EQ : (PRI_EQ | PRI_GT); + if (pri_invert) + pri_cmp ^= PRI_LT | PRI_EQ | PRI_GT; + + /* scan facilities */ + while (*p != '\0' && !strchr("\t.; ", *p)) { + for (bp = buf; *p != '\0' && !strchr("\t,;. ", *p); ) + *bp++ = *p++; + *bp = '\0'; + + if (*buf == '*') { + for (i = 0; i < LOG_NFACILITIES; i++) { + f->f_pmask[i] = pri; + f->f_pcmp[i] = pri_cmp; + } + } else { + i = decode(buf, facilitynames); + if (i < 0) { + errno = 0; + (void)snprintf(ebuf, sizeof ebuf, + "unknown facility name \"%s\"", + buf); + logerror(ebuf); + free(f); + return (NULL); + } + f->f_pmask[i >> 3] = pri; + f->f_pcmp[i >> 3] = pri_cmp; + } + while (*p == ',' || *p == ' ') + p++; + } + return (q); +} + /* * Crack a configuration file line */ @@ -2874,9 +2975,8 @@ cfline(const char *line, const char *prog, const char *host, { struct filed *f; struct addrinfo hints, *res; - int error, i, pri; + int error, i; const char *p, *q; - char *bp, buf[LINE_MAX], ebuf[100]; bool syncfile; dprintf("cfline(\"%s\", f, \"%s\", \"%s\", \"%s\")\n", line, prog, @@ -2931,110 +3031,8 @@ cfline(const char *line, const char *prog, const char *host, } /* scan through the list of selectors */ - for (p = line; *p && *p != '\t' && *p != ' ';) { - int pri_done; - int pri_cmp; - int pri_invert; - - /* find the end of this facility name list */ - for (q = p; *q && *q != '\t' && *q != ' ' && *q++ != '.'; ) - continue; - - /* get the priority comparison */ - pri_cmp = 0; - pri_done = 0; - pri_invert = 0; - if (*q == '!') { - pri_invert = 1; - q++; - } - while (!pri_done) { - switch (*q) { - case '<': - pri_cmp |= PRI_LT; - q++; - break; - case '=': - pri_cmp |= PRI_EQ; - q++; - break; - case '>': - pri_cmp |= PRI_GT; - q++; - break; - default: - pri_done++; - break; - } - } - - /* collect priority name */ - for (bp = buf; *q && !strchr("\t,; ", *q); ) - *bp++ = *q++; - *bp = '\0'; - - /* skip cruft */ - while (strchr(",;", *q)) - q++; - - /* decode priority name */ - if (*buf == '*') { - pri = LOG_PRIMASK; - pri_cmp = PRI_LT | PRI_EQ | PRI_GT; - } else { - /* Ignore trailing spaces. */ - for (i = strlen(buf) - 1; i >= 0 && buf[i] == ' '; i--) - buf[i] = '\0'; - - pri = decode(buf, prioritynames); - if (pri < 0) { - errno = 0; - (void)snprintf(ebuf, sizeof ebuf, - "unknown priority name \"%s\"", buf); - logerror(ebuf); - free(f); - return; - } - } - if (!pri_cmp) - pri_cmp = (UniquePriority) - ? (PRI_EQ) - : (PRI_EQ | PRI_GT) - ; - if (pri_invert) - pri_cmp ^= PRI_LT | PRI_EQ | PRI_GT; - - /* scan facilities */ - while (*p && !strchr("\t.; ", *p)) { - for (bp = buf; *p && !strchr("\t,;. ", *p); ) - *bp++ = *p++; - *bp = '\0'; - - if (*buf == '*') { - for (i = 0; i < LOG_NFACILITIES; i++) { - f->f_pmask[i] = pri; - f->f_pcmp[i] = pri_cmp; - } - } else { - i = decode(buf, facilitynames); - if (i < 0) { - errno = 0; - (void)snprintf(ebuf, sizeof ebuf, - "unknown facility name \"%s\"", - buf); - logerror(ebuf); - free(f); - return; - } - f->f_pmask[i >> 3] = pri; - f->f_pcmp[i >> 3] = pri_cmp; - } - while (*p == ',' || *p == ' ') - p++; - } - - p = q; - } + for (p = line; *p != '\0' && *p != '\t' && *p != ' ';) + p = parse_selector(p, f); /* skip to action part */ while (*p == '\t' || *p == ' ')